summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.hgignore21
-rw-r--r--CREDITS5
-rw-r--r--ChangeLog29
-rw-r--r--Makefile.am20
-rw-r--r--TODO29
-rwxr-xr-xautogen.sh12
-rw-r--r--automake.diff11
-rwxr-xr-xconfig.rpath133
-rw-r--r--configure.ac3647
-rw-r--r--contrib/Makefile.am153
-rw-r--r--contrib/README.contrib58
-rw-r--r--contrib/ffmpeg-distfiles588
-rwxr-xr-xcontrib/ffmpeg-universal.sh177
-rw-r--r--contrib/ffmpeg/COPYING504
-rw-r--r--contrib/ffmpeg/CREDITS47
-rw-r--r--contrib/ffmpeg/Changelog400
-rw-r--r--contrib/ffmpeg/Doxyfile1038
-rw-r--r--contrib/ffmpeg/INSTALL14
-rw-r--r--contrib/ffmpeg/MAINTAINERS254
-rw-r--r--contrib/ffmpeg/Makefile235
-rw-r--r--contrib/ffmpeg/README19
-rwxr-xr-xcontrib/ffmpeg/build_avopt9
-rwxr-xr-xcontrib/ffmpeg/clean-diff11
-rw-r--r--contrib/ffmpeg/cmdutils.c145
-rw-r--r--contrib/ffmpeg/cmdutils.h57
-rw-r--r--contrib/ffmpeg/common.mak99
-rwxr-xr-xcontrib/ffmpeg/configure2157
-rw-r--r--contrib/ffmpeg/cws2fws.c127
-rw-r--r--contrib/ffmpeg/doc/Makefile20
-rw-r--r--contrib/ffmpeg/doc/TODO91
-rw-r--r--contrib/ffmpeg/doc/avutil.txt37
-rw-r--r--contrib/ffmpeg/doc/faq.texi363
-rw-r--r--contrib/ffmpeg/doc/ffmpeg-doc.texi1656
-rw-r--r--contrib/ffmpeg/doc/ffmpeg_powerpc_performance_evaluation_howto.txt172
-rw-r--r--contrib/ffmpeg/doc/ffplay-doc.texi135
-rw-r--r--contrib/ffmpeg/doc/ffserver-doc.texi224
-rw-r--r--contrib/ffmpeg/doc/ffserver.conf349
-rw-r--r--contrib/ffmpeg/doc/hooks.texi260
-rw-r--r--contrib/ffmpeg/doc/optimization.txt167
-rw-r--r--contrib/ffmpeg/doc/snow.txt259
-rw-r--r--contrib/ffmpeg/doc/soc.txt24
-rwxr-xr-xcontrib/ffmpeg/doc/texi2pod.pl427
-rw-r--r--contrib/ffmpeg/ffinstall.nsi75
-rw-r--r--contrib/ffmpeg/ffmpeg.c3823
-rw-r--r--contrib/ffmpeg/ffplay.c2581
-rw-r--r--contrib/ffmpeg/ffserver.c4608
-rw-r--r--contrib/ffmpeg/ffserver.h28
-rw-r--r--contrib/ffmpeg/libavcodec/4xm.c749
-rw-r--r--contrib/ffmpeg/libavcodec/8bps.c236
-rw-r--r--contrib/ffmpeg/libavcodec/Makefile448
-rw-r--r--contrib/ffmpeg/libavcodec/a52dec.c259
-rw-r--r--contrib/ffmpeg/libavcodec/aasc.c175
-rw-r--r--contrib/ffmpeg/libavcodec/ac3.c287
-rw-r--r--contrib/ffmpeg/libavcodec/ac3.h171
-rw-r--r--contrib/ffmpeg/libavcodec/ac3enc.c1371
-rw-r--r--contrib/ffmpeg/libavcodec/ac3tab.h251
-rw-r--r--contrib/ffmpeg/libavcodec/adpcm.c1372
-rw-r--r--contrib/ffmpeg/libavcodec/adx.c (renamed from src/libffmpeg/libavcodec/adx.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/alac.c (renamed from src/libffmpeg/libavcodec/alac.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/allcodecs.c277
-rw-r--r--contrib/ffmpeg/libavcodec/alpha/asm.h (renamed from src/libffmpeg/libavcodec/alpha/asm.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/alpha/dsputil_alpha.c (renamed from src/libffmpeg/libavcodec/alpha/dsputil_alpha.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/alpha/dsputil_alpha_asm.S285
-rw-r--r--contrib/ffmpeg/libavcodec/alpha/motion_est_alpha.c (renamed from src/libffmpeg/libavcodec/alpha/motion_est_alpha.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/alpha/motion_est_mvi_asm.S185
-rw-r--r--contrib/ffmpeg/libavcodec/alpha/mpegvideo_alpha.c (renamed from src/libffmpeg/libavcodec/alpha/mpegvideo_alpha.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/alpha/regdef.h (renamed from src/libffmpeg/libavcodec/alpha/regdef.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/alpha/simple_idct_alpha.c308
-rw-r--r--contrib/ffmpeg/libavcodec/amr.c715
-rw-r--r--contrib/ffmpeg/libavcodec/apiexample.c454
-rw-r--r--contrib/ffmpeg/libavcodec/armv4l/dsputil_arm.c277
-rw-r--r--contrib/ffmpeg/libavcodec/armv4l/dsputil_arm_s.S (renamed from src/libffmpeg/libavcodec/armv4l/dsputil_arm_s.S)0
-rw-r--r--contrib/ffmpeg/libavcodec/armv4l/dsputil_iwmmxt.c184
-rw-r--r--contrib/ffmpeg/libavcodec/armv4l/dsputil_iwmmxt_rnd.h (renamed from src/libffmpeg/libavcodec/armv4l/dsputil_iwmmxt_rnd.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/armv4l/jrevdct_arm.S (renamed from src/libffmpeg/libavcodec/armv4l/jrevdct_arm.S)0
-rw-r--r--contrib/ffmpeg/libavcodec/armv4l/mathops.h (renamed from src/libffmpeg/libavcodec/armv4l/mathops.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/armv4l/mpegvideo_arm.c41
-rw-r--r--contrib/ffmpeg/libavcodec/armv4l/mpegvideo_armv5te.c213
-rw-r--r--contrib/ffmpeg/libavcodec/armv4l/mpegvideo_iwmmxt.c (renamed from src/libffmpeg/libavcodec/armv4l/mpegvideo_iwmmxt.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/armv4l/simple_idct_arm.S (renamed from src/libffmpeg/libavcodec/armv4l/simple_idct_arm.S)0
-rw-r--r--contrib/ffmpeg/libavcodec/armv4l/simple_idct_armv5te.S (renamed from src/libffmpeg/libavcodec/armv4l/simple_idct_armv5te.S)0
-rw-r--r--contrib/ffmpeg/libavcodec/armv4l/simple_idct_armv6.S448
-rw-r--r--contrib/ffmpeg/libavcodec/asv1.c (renamed from src/libffmpeg/libavcodec/asv1.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/audioconvert.c79
-rw-r--r--contrib/ffmpeg/libavcodec/avcodec.h3091
-rw-r--r--contrib/ffmpeg/libavcodec/avs.c (renamed from src/libffmpeg/libavcodec/avs.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/beosthread.c182
-rw-r--r--contrib/ffmpeg/libavcodec/bfin/config_bfin.h46
-rw-r--r--contrib/ffmpeg/libavcodec/bfin/dsputil_bfin.c310
-rw-r--r--contrib/ffmpeg/libavcodec/bfin/fdct_bfin.S324
-rw-r--r--contrib/ffmpeg/libavcodec/bfin/idct_bfin.S297
-rw-r--r--contrib/ffmpeg/libavcodec/bfin/pixels_bfin.S723
-rw-r--r--contrib/ffmpeg/libavcodec/bitstream.c263
-rw-r--r--contrib/ffmpeg/libavcodec/bitstream.h956
-rw-r--r--contrib/ffmpeg/libavcodec/bitstream_filter.c284
-rw-r--r--contrib/ffmpeg/libavcodec/bmp.c254
-rw-r--r--contrib/ffmpeg/libavcodec/bmp.h31
-rw-r--r--contrib/ffmpeg/libavcodec/bmpenc.c98
-rw-r--r--contrib/ffmpeg/libavcodec/bytestream.h58
-rw-r--r--contrib/ffmpeg/libavcodec/cabac.c (renamed from src/libffmpeg/libavcodec/cabac.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/cabac.h859
-rw-r--r--contrib/ffmpeg/libavcodec/cavs.c1540
-rw-r--r--contrib/ffmpeg/libavcodec/cavsdata.h (renamed from src/libffmpeg/libavcodec/cavsdata.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/cavsdsp.c546
-rw-r--r--contrib/ffmpeg/libavcodec/cinepak.c (renamed from src/libffmpeg/libavcodec/cinepak.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/cljr.c (renamed from src/libffmpeg/libavcodec/cljr.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/cook.c1147
-rw-r--r--contrib/ffmpeg/libavcodec/cookdata.h (renamed from src/libffmpeg/libavcodec/cookdata.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/cscd.c264
-rw-r--r--contrib/ffmpeg/libavcodec/cyuv.c (renamed from src/libffmpeg/libavcodec/cyuv.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/dca.c1322
-rw-r--r--contrib/ffmpeg/libavcodec/dcadata.h8454
-rw-r--r--contrib/ffmpeg/libavcodec/dcahuff.h1068
-rw-r--r--contrib/ffmpeg/libavcodec/dct-test.c565
-rw-r--r--contrib/ffmpeg/libavcodec/dnxhddata.h106
-rw-r--r--contrib/ffmpeg/libavcodec/dnxhddec.c368
-rw-r--r--contrib/ffmpeg/libavcodec/dpcm.c (renamed from src/libffmpeg/libavcodec/dpcm.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/dsicinav.c362
-rw-r--r--contrib/ffmpeg/libavcodec/dsputil.c4194
-rw-r--r--contrib/ffmpeg/libavcodec/dsputil.h762
-rw-r--r--contrib/ffmpeg/libavcodec/dtsdec.c268
-rw-r--r--contrib/ffmpeg/libavcodec/dv.c1259
-rw-r--r--contrib/ffmpeg/libavcodec/dvbsub.c445
-rw-r--r--contrib/ffmpeg/libavcodec/dvbsubdec.c1631
-rw-r--r--contrib/ffmpeg/libavcodec/dvdata.h (renamed from src/libffmpeg/libavcodec/dvdata.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/dvdsubdec.c472
-rw-r--r--contrib/ffmpeg/libavcodec/dvdsubenc.c247
-rw-r--r--contrib/ffmpeg/libavcodec/dxa.c333
-rw-r--r--contrib/ffmpeg/libavcodec/error_resilience.c1035
-rw-r--r--contrib/ffmpeg/libavcodec/eval.c466
-rw-r--r--contrib/ffmpeg/libavcodec/eval.h (renamed from src/libffmpeg/libavcodec/eval.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/faac.c136
-rw-r--r--contrib/ffmpeg/libavcodec/faad.c333
-rw-r--r--contrib/ffmpeg/libavcodec/faandct.c (renamed from src/libffmpeg/libavcodec/faandct.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/faandct.h (renamed from src/libffmpeg/libavcodec/faandct.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/fdctref.c (renamed from src/libffmpeg/libavcodec/fdctref.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/fft-test.c299
-rw-r--r--contrib/ffmpeg/libavcodec/fft.c (renamed from src/libffmpeg/libavcodec/fft.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/ffv1.c1040
-rw-r--r--contrib/ffmpeg/libavcodec/flac.c (renamed from src/libffmpeg/libavcodec/flac.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/flacenc.c1371
-rw-r--r--contrib/ffmpeg/libavcodec/flashsv.c (renamed from src/libffmpeg/libavcodec/flashsv.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/flashsvenc.c346
-rw-r--r--contrib/ffmpeg/libavcodec/flicvideo.c754
-rw-r--r--contrib/ffmpeg/libavcodec/fraps.c (renamed from src/libffmpeg/libavcodec/fraps.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/g726.c429
-rw-r--r--contrib/ffmpeg/libavcodec/gif.c350
-rw-r--r--contrib/ffmpeg/libavcodec/gifdec.c343
-rw-r--r--contrib/ffmpeg/libavcodec/golomb.c (renamed from src/libffmpeg/libavcodec/golomb.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/golomb.h (renamed from src/libffmpeg/libavcodec/golomb.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/h261.c1057
-rw-r--r--contrib/ffmpeg/libavcodec/h261data.h (renamed from src/libffmpeg/libavcodec/h261data.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/h263.c6311
-rw-r--r--contrib/ffmpeg/libavcodec/h263data.h (renamed from src/libffmpeg/libavcodec/h263data.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/h263dec.c914
-rw-r--r--contrib/ffmpeg/libavcodec/h264.c8707
-rw-r--r--contrib/ffmpeg/libavcodec/h264data.h (renamed from src/libffmpeg/libavcodec/h264data.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/h264dsp.c81
-rw-r--r--contrib/ffmpeg/libavcodec/h264enc.c107
-rw-r--r--contrib/ffmpeg/libavcodec/h264idct.c (renamed from src/libffmpeg/libavcodec/h264idct.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/huffyuv.c1390
-rw-r--r--contrib/ffmpeg/libavcodec/i386/cavsdsp_mmx.c518
-rw-r--r--contrib/ffmpeg/libavcodec/i386/cputest.c (renamed from src/libffmpeg/libavcodec/i386/cputest.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/i386/dsputil_h264_template_mmx.c305
-rw-r--r--contrib/ffmpeg/libavcodec/i386/dsputil_mmx.c3568
-rw-r--r--contrib/ffmpeg/libavcodec/i386/dsputil_mmx_avg.h (renamed from src/libffmpeg/libavcodec/i386/dsputil_mmx_avg.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/i386/dsputil_mmx_rnd.h (renamed from src/libffmpeg/libavcodec/i386/dsputil_mmx_rnd.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/i386/fdct_mmx.c (renamed from src/libffmpeg/libavcodec/i386/fdct_mmx.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/i386/fft_3dn.c (renamed from src/libffmpeg/libavcodec/i386/fft_3dn.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/i386/fft_3dn2.c (renamed from src/libffmpeg/libavcodec/i386/fft_3dn2.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/i386/fft_sse.c (renamed from src/libffmpeg/libavcodec/i386/fft_sse.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/i386/h264dsp_mmx.c1517
-rw-r--r--contrib/ffmpeg/libavcodec/i386/idct_mmx.c (renamed from src/libffmpeg/libavcodec/i386/idct_mmx.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/i386/idct_mmx_xvid.c535
-rw-r--r--contrib/ffmpeg/libavcodec/i386/mathops.h (renamed from src/libffmpeg/libavcodec/i386/mathops.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/i386/mmx.h (renamed from src/libffmpeg/libavcodec/i386/mmx.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/i386/motion_est_mmx.c (renamed from src/libffmpeg/libavcodec/i386/motion_est_mmx.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/i386/mpegvideo_mmx.c (renamed from src/libffmpeg/libavcodec/i386/mpegvideo_mmx.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/i386/mpegvideo_mmx_template.c (renamed from src/libffmpeg/libavcodec/i386/mpegvideo_mmx_template.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/i386/simple_idct_mmx.c (renamed from src/libffmpeg/libavcodec/i386/simple_idct_mmx.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/i386/snowdsp_mmx.c921
-rw-r--r--contrib/ffmpeg/libavcodec/i386/vp3dsp_mmx.c (renamed from src/libffmpeg/libavcodec/i386/vp3dsp_mmx.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/i386/vp3dsp_sse2.c (renamed from src/libffmpeg/libavcodec/i386/vp3dsp_sse2.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/idcinvideo.c (renamed from src/libffmpeg/libavcodec/idcinvideo.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/imc.c813
-rw-r--r--contrib/ffmpeg/libavcodec/imcdata.h164
-rw-r--r--contrib/ffmpeg/libavcodec/imgconvert.c2854
-rw-r--r--contrib/ffmpeg/libavcodec/imgconvert_template.h875
-rw-r--r--contrib/ffmpeg/libavcodec/imgresample.c949
-rw-r--r--contrib/ffmpeg/libavcodec/indeo2.c221
-rw-r--r--contrib/ffmpeg/libavcodec/indeo2data.h (renamed from src/libffmpeg/libavcodec/indeo2data.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/indeo3.c1149
-rw-r--r--contrib/ffmpeg/libavcodec/indeo3data.h (renamed from src/libffmpeg/libavcodec/indeo3data.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/interplayvideo.c (renamed from src/libffmpeg/libavcodec/interplayvideo.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/jfdctfst.c (renamed from src/libffmpeg/libavcodec/jfdctfst.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/jfdctint.c (renamed from src/libffmpeg/libavcodec/jfdctint.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/jpeg_ls.c860
-rw-r--r--contrib/ffmpeg/libavcodec/jrevdct.c (renamed from src/libffmpeg/libavcodec/jrevdct.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/kmvc.c416
-rw-r--r--contrib/ffmpeg/libavcodec/lcl.c (renamed from src/libffmpeg/libavcodec/lcl.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/libgsm.c145
-rw-r--r--contrib/ffmpeg/libavcodec/libtheoraenc.c280
-rw-r--r--contrib/ffmpeg/libavcodec/loco.c287
-rw-r--r--contrib/ffmpeg/libavcodec/lzw.c229
-rw-r--r--contrib/ffmpeg/libavcodec/lzw.h49
-rw-r--r--contrib/ffmpeg/libavcodec/mace.c (renamed from src/libffmpeg/libavcodec/mace.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/mathops.h (renamed from src/libffmpeg/libavcodec/mathops.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/mdct.c (renamed from src/libffmpeg/libavcodec/mdct.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/mdec.c (renamed from src/libffmpeg/libavcodec/mdec.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/mjpeg.c2651
-rw-r--r--contrib/ffmpeg/libavcodec/mlib/dsputil_mlib.c464
-rw-r--r--contrib/ffmpeg/libavcodec/mmvideo.c (renamed from src/libffmpeg/libavcodec/mmvideo.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/motion_est.c2147
-rw-r--r--contrib/ffmpeg/libavcodec/motion_est_template.c1249
-rw-r--r--contrib/ffmpeg/libavcodec/motion_test.c160
-rw-r--r--contrib/ffmpeg/libavcodec/mp3lameaudio.c221
-rw-r--r--contrib/ffmpeg/libavcodec/mpc.c355
-rw-r--r--contrib/ffmpeg/libavcodec/mpcdata.h206
-rw-r--r--contrib/ffmpeg/libavcodec/mpeg12.c3557
-rw-r--r--contrib/ffmpeg/libavcodec/mpeg12data.h474
-rw-r--r--contrib/ffmpeg/libavcodec/mpeg4data.h (renamed from src/libffmpeg/libavcodec/mpeg4data.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/mpegaudio.c799
-rw-r--r--contrib/ffmpeg/libavcodec/mpegaudio.h (renamed from src/libffmpeg/libavcodec/mpegaudio.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/mpegaudiodec.c2878
-rw-r--r--contrib/ffmpeg/libavcodec/mpegaudiodectab.h (renamed from src/libffmpeg/libavcodec/mpegaudiodectab.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/mpegaudiotab.h (renamed from src/libffmpeg/libavcodec/mpegaudiotab.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/mpegvideo.c6949
-rw-r--r--contrib/ffmpeg/libavcodec/mpegvideo.h908
-rw-r--r--contrib/ffmpeg/libavcodec/msmpeg4.c1940
-rw-r--r--contrib/ffmpeg/libavcodec/msmpeg4data.h (renamed from src/libffmpeg/libavcodec/msmpeg4data.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/msrle.c (renamed from src/libffmpeg/libavcodec/msrle.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/msvideo1.c (renamed from src/libffmpeg/libavcodec/msvideo1.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/nuv.c216
-rw-r--r--contrib/ffmpeg/libavcodec/oggvorbis.c383
-rw-r--r--contrib/ffmpeg/libavcodec/opt.c389
-rw-r--r--contrib/ffmpeg/libavcodec/opt.h85
-rw-r--r--contrib/ffmpeg/libavcodec/os2thread.c147
-rw-r--r--contrib/ffmpeg/libavcodec/parser.c834
-rw-r--r--contrib/ffmpeg/libavcodec/parser.h (renamed from src/libffmpeg/libavcodec/parser.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/pcm.c526
-rw-r--r--contrib/ffmpeg/libavcodec/png.c966
-rw-r--r--contrib/ffmpeg/libavcodec/pnm.c606
-rw-r--r--contrib/ffmpeg/libavcodec/ppc/dsputil_altivec.c (renamed from src/libffmpeg/libavcodec/ppc/dsputil_altivec.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/ppc/dsputil_altivec.h (renamed from src/libffmpeg/libavcodec/ppc/dsputil_altivec.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/ppc/dsputil_ppc.c325
-rw-r--r--contrib/ffmpeg/libavcodec/ppc/dsputil_ppc.h155
-rw-r--r--contrib/ffmpeg/libavcodec/ppc/fdct_altivec.c (renamed from src/libffmpeg/libavcodec/ppc/fdct_altivec.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/ppc/fft_altivec.c (renamed from src/libffmpeg/libavcodec/ppc/fft_altivec.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/ppc/float_altivec.c (renamed from src/libffmpeg/libavcodec/ppc/float_altivec.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/ppc/gcc_fixes.h (renamed from src/libffmpeg/libavcodec/ppc/gcc_fixes.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/ppc/gmc_altivec.c (renamed from src/libffmpeg/libavcodec/ppc/gmc_altivec.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/ppc/h264_altivec.c (renamed from src/libffmpeg/libavcodec/ppc/h264_altivec.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/ppc/h264_template_altivec.c (renamed from src/libffmpeg/libavcodec/ppc/h264_template_altivec.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/ppc/idct_altivec.c237
-rw-r--r--contrib/ffmpeg/libavcodec/ppc/mathops.h (renamed from src/libffmpeg/libavcodec/ppc/mathops.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/ppc/mpegvideo_altivec.c (renamed from src/libffmpeg/libavcodec/ppc/mpegvideo_altivec.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/ppc/mpegvideo_ppc.c (renamed from src/libffmpeg/libavcodec/ppc/mpegvideo_ppc.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/ppc/snow_altivec.c (renamed from src/libffmpeg/libavcodec/ppc/snow_altivec.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/ppc/types_altivec.h (renamed from src/libffmpeg/libavcodec/ppc/types_altivec.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/ppc/vc1dsp_altivec.c (renamed from src/libffmpeg/libavcodec/ppc/vc1dsp_altivec.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/ps2/dsputil_mmi.c163
-rw-r--r--contrib/ffmpeg/libavcodec/ps2/idct_mmi.c363
-rw-r--r--contrib/ffmpeg/libavcodec/ps2/mmi.h172
-rw-r--r--contrib/ffmpeg/libavcodec/ps2/mpegvideo_mmi.c89
-rw-r--r--contrib/ffmpeg/libavcodec/pthread.c170
-rw-r--r--contrib/ffmpeg/libavcodec/qdm2.c (renamed from src/libffmpeg/libavcodec/qdm2.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/qdm2data.h (renamed from src/libffmpeg/libavcodec/qdm2data.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/qdrw.c (renamed from src/libffmpeg/libavcodec/qdrw.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/qpeg.c323
-rw-r--r--contrib/ffmpeg/libavcodec/qtrle.c630
-rw-r--r--contrib/ffmpeg/libavcodec/ra144.c (renamed from src/libffmpeg/libavcodec/ra144.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/ra144.h (renamed from src/libffmpeg/libavcodec/ra144.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/ra288.c (renamed from src/libffmpeg/libavcodec/ra288.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/ra288.h (renamed from src/libffmpeg/libavcodec/ra288.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/rangecoder.c (renamed from src/libffmpeg/libavcodec/rangecoder.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/rangecoder.h (renamed from src/libffmpeg/libavcodec/rangecoder.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/ratecontrol.c944
-rw-r--r--contrib/ffmpeg/libavcodec/ratecontrol.h (renamed from src/libffmpeg/libavcodec/ratecontrol.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/raw.c224
-rw-r--r--contrib/ffmpeg/libavcodec/resample.c250
-rw-r--r--contrib/ffmpeg/libavcodec/resample2.c326
-rw-r--r--contrib/ffmpeg/libavcodec/rl.h42
-rw-r--r--contrib/ffmpeg/libavcodec/roqvideo.c477
-rw-r--r--contrib/ffmpeg/libavcodec/rpza.c (renamed from src/libffmpeg/libavcodec/rpza.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/rtjpeg.c (renamed from src/libffmpeg/libavcodec/rtjpeg.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/rtjpeg.h (renamed from src/libffmpeg/libavcodec/rtjpeg.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/rv10.c805
-rw-r--r--contrib/ffmpeg/libavcodec/sh4/dsputil_align.c430
-rw-r--r--contrib/ffmpeg/libavcodec/sh4/dsputil_sh4.c120
-rw-r--r--contrib/ffmpeg/libavcodec/sh4/idct_sh4.c366
-rw-r--r--contrib/ffmpeg/libavcodec/sh4/qpel.c1600
-rw-r--r--contrib/ffmpeg/libavcodec/shorten.c535
-rw-r--r--contrib/ffmpeg/libavcodec/simple_idct.c587
-rw-r--r--contrib/ffmpeg/libavcodec/simple_idct.h (renamed from src/libffmpeg/libavcodec/simple_idct.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/smacker.c717
-rw-r--r--contrib/ffmpeg/libavcodec/smc.c (renamed from src/libffmpeg/libavcodec/smc.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/snow.c4706
-rw-r--r--contrib/ffmpeg/libavcodec/snow.h176
-rw-r--r--contrib/ffmpeg/libavcodec/sonic.c981
-rw-r--r--contrib/ffmpeg/libavcodec/sp5x.h (renamed from src/libffmpeg/libavcodec/sp5x.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/sparc/dsputil_vis.c (renamed from src/libffmpeg/libavcodec/sparc/dsputil_vis.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/sparc/vis.h (renamed from src/libffmpeg/libavcodec/sparc/vis.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/svq1.c1425
-rw-r--r--contrib/ffmpeg/libavcodec/svq1_cb.h (renamed from src/libffmpeg/libavcodec/svq1_cb.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/svq1_vlc.h (renamed from src/libffmpeg/libavcodec/svq1_vlc.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/svq3.c1015
-rw-r--r--contrib/ffmpeg/libavcodec/targa.c254
-rw-r--r--contrib/ffmpeg/libavcodec/targaenc.c199
-rw-r--r--contrib/ffmpeg/libavcodec/tiertexseqv.c232
-rw-r--r--contrib/ffmpeg/libavcodec/tiff.c532
-rw-r--r--contrib/ffmpeg/libavcodec/truemotion1.c928
-rw-r--r--contrib/ffmpeg/libavcodec/truemotion1data.h (renamed from src/libffmpeg/libavcodec/truemotion1data.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/truemotion2.c892
-rw-r--r--contrib/ffmpeg/libavcodec/truespeech.c381
-rw-r--r--contrib/ffmpeg/libavcodec/truespeech_data.h (renamed from src/libffmpeg/libavcodec/truespeech_data.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/tscc.c347
-rw-r--r--contrib/ffmpeg/libavcodec/tta.c (renamed from src/libffmpeg/libavcodec/tta.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/ulti.c427
-rw-r--r--contrib/ffmpeg/libavcodec/ulti_cb.h (renamed from src/libffmpeg/libavcodec/ulti_cb.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/utils.c1340
-rw-r--r--contrib/ffmpeg/libavcodec/vc1.c4626
-rw-r--r--contrib/ffmpeg/libavcodec/vc1acdata.h (renamed from src/libffmpeg/libavcodec/vc1acdata.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/vc1data.h652
-rw-r--r--contrib/ffmpeg/libavcodec/vc1dsp.c463
-rw-r--r--contrib/ffmpeg/libavcodec/vcr1.c (renamed from src/libffmpeg/libavcodec/vcr1.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/vmdav.c572
-rw-r--r--contrib/ffmpeg/libavcodec/vmnc.c524
-rw-r--r--contrib/ffmpeg/libavcodec/vorbis.c1790
-rw-r--r--contrib/ffmpeg/libavcodec/vorbis.h (renamed from src/libffmpeg/libavcodec/vorbis.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/vorbis_data.c (renamed from src/libffmpeg/libavcodec/vorbis_data.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/vorbis_enc.c1087
-rw-r--r--contrib/ffmpeg/libavcodec/vorbis_enc_data.h498
-rw-r--r--contrib/ffmpeg/libavcodec/vp3.c2665
-rw-r--r--contrib/ffmpeg/libavcodec/vp3data.h (renamed from src/libffmpeg/libavcodec/vp3data.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/vp3dsp.c (renamed from src/libffmpeg/libavcodec/vp3dsp.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/vp5.c290
-rw-r--r--contrib/ffmpeg/libavcodec/vp56.c665
-rw-r--r--contrib/ffmpeg/libavcodec/vp56.h253
-rw-r--r--contrib/ffmpeg/libavcodec/vp56data.c (renamed from src/libffmpeg/libavcodec/vp56data.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/vp56data.h249
-rw-r--r--contrib/ffmpeg/libavcodec/vp5data.h (renamed from src/libffmpeg/libavcodec/vp5data.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/vp6.c556
-rw-r--r--contrib/ffmpeg/libavcodec/vp6data.h (renamed from src/libffmpeg/libavcodec/vp6data.h)0
-rw-r--r--contrib/ffmpeg/libavcodec/vqavideo.c (renamed from src/libffmpeg/libavcodec/vqavideo.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/w32thread.c136
-rw-r--r--contrib/ffmpeg/libavcodec/wavpack.c562
-rw-r--r--contrib/ffmpeg/libavcodec/wma.c386
-rw-r--r--contrib/ffmpeg/libavcodec/wma.h149
-rw-r--r--contrib/ffmpeg/libavcodec/wmadata.h1433
-rw-r--r--contrib/ffmpeg/libavcodec/wmadec.c912
-rw-r--r--contrib/ffmpeg/libavcodec/wmaenc.c407
-rw-r--r--contrib/ffmpeg/libavcodec/wmv2.c861
-rw-r--r--contrib/ffmpeg/libavcodec/wnv1.c (renamed from src/libffmpeg/libavcodec/wnv1.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/ws-snd1.c (renamed from src/libffmpeg/libavcodec/ws-snd1.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/x264.c300
-rw-r--r--contrib/ffmpeg/libavcodec/xan.c (renamed from src/libffmpeg/libavcodec/xan.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/xiph.c56
-rw-r--r--contrib/ffmpeg/libavcodec/xiph.h38
-rw-r--r--contrib/ffmpeg/libavcodec/xl.c (renamed from src/libffmpeg/libavcodec/xl.c)0
-rw-r--r--contrib/ffmpeg/libavcodec/xvid_internal.h32
-rw-r--r--contrib/ffmpeg/libavcodec/xvid_rc.c148
-rw-r--r--contrib/ffmpeg/libavcodec/xvidff.c768
-rw-r--r--contrib/ffmpeg/libavcodec/xvmc_render.h50
-rw-r--r--contrib/ffmpeg/libavcodec/xvmcvideo.c318
-rw-r--r--contrib/ffmpeg/libavcodec/zmbv.c691
-rw-r--r--contrib/ffmpeg/libavcodec/zmbvenc.c328
-rw-r--r--contrib/ffmpeg/libavformat/4xm.c331
-rw-r--r--contrib/ffmpeg/libavformat/Makefile179
-rw-r--r--contrib/ffmpeg/libavformat/adtsenc.c123
-rw-r--r--contrib/ffmpeg/libavformat/aiff.c444
-rw-r--r--contrib/ffmpeg/libavformat/allformats.c172
-rw-r--r--contrib/ffmpeg/libavformat/allformats.h182
-rw-r--r--contrib/ffmpeg/libavformat/amr.c201
-rw-r--r--contrib/ffmpeg/libavformat/asf-enc.c853
-rw-r--r--contrib/ffmpeg/libavformat/asf.c1037
-rw-r--r--contrib/ffmpeg/libavformat/asf.h280
-rw-r--r--contrib/ffmpeg/libavformat/au.c209
-rw-r--r--contrib/ffmpeg/libavformat/audio.c344
-rw-r--r--contrib/ffmpeg/libavformat/avformat.h888
-rw-r--r--contrib/ffmpeg/libavformat/avi.h39
-rw-r--r--contrib/ffmpeg/libavformat/avidec.c1018
-rw-r--r--contrib/ffmpeg/libavformat/avienc.c580
-rw-r--r--contrib/ffmpeg/libavformat/avio.c186
-rw-r--r--contrib/ffmpeg/libavformat/avio.h272
-rw-r--r--contrib/ffmpeg/libavformat/aviobuf.c755
-rw-r--r--contrib/ffmpeg/libavformat/avisynth.c222
-rw-r--r--contrib/ffmpeg/libavformat/avs.c227
-rw-r--r--contrib/ffmpeg/libavformat/beosaudio.cpp465
-rw-r--r--contrib/ffmpeg/libavformat/crc.c98
-rw-r--r--contrib/ffmpeg/libavformat/cutils.c275
-rw-r--r--contrib/ffmpeg/libavformat/daud.c58
-rw-r--r--contrib/ffmpeg/libavformat/dc1394.c193
-rw-r--r--contrib/ffmpeg/libavformat/dsicin.c224
-rw-r--r--contrib/ffmpeg/libavformat/dv.c451
-rw-r--r--contrib/ffmpeg/libavformat/dv.h37
-rw-r--r--contrib/ffmpeg/libavformat/dv1394.c236
-rw-r--r--contrib/ffmpeg/libavformat/dv1394.h357
-rw-r--r--contrib/ffmpeg/libavformat/dvenc.c411
-rw-r--r--contrib/ffmpeg/libavformat/dxa.c214
-rw-r--r--contrib/ffmpeg/libavformat/electronicarts.c291
-rw-r--r--contrib/ffmpeg/libavformat/ffm.c794
-rw-r--r--contrib/ffmpeg/libavformat/file.c130
-rw-r--r--contrib/ffmpeg/libavformat/flic.c223
-rw-r--r--contrib/ffmpeg/libavformat/flv.h110
-rw-r--r--contrib/ffmpeg/libavformat/flvdec.c395
-rw-r--r--contrib/ffmpeg/libavformat/flvenc.c336
-rw-r--r--contrib/ffmpeg/libavformat/framehook.c120
-rw-r--r--contrib/ffmpeg/libavformat/framehook.h52
-rw-r--r--contrib/ffmpeg/libavformat/gif.c419
-rw-r--r--contrib/ffmpeg/libavformat/gifdec.c593
-rw-r--r--contrib/ffmpeg/libavformat/grab.c860
-rw-r--r--contrib/ffmpeg/libavformat/grab_bktr.c320
-rw-r--r--contrib/ffmpeg/libavformat/gxf.c524
-rw-r--r--contrib/ffmpeg/libavformat/gxf.h34
-rw-r--r--contrib/ffmpeg/libavformat/gxfenc.c828
-rw-r--r--contrib/ffmpeg/libavformat/http.c354
-rw-r--r--contrib/ffmpeg/libavformat/idcin.c301
-rw-r--r--contrib/ffmpeg/libavformat/idroq.c291
-rw-r--r--contrib/ffmpeg/libavformat/img2.c428
-rw-r--r--contrib/ffmpeg/libavformat/ipmovie.c627
-rw-r--r--contrib/ffmpeg/libavformat/isom.c247
-rw-r--r--contrib/ffmpeg/libavformat/isom.h40
-rw-r--r--contrib/ffmpeg/libavformat/libnut.c310
-rw-r--r--contrib/ffmpeg/libavformat/matroska.c2850
-rw-r--r--contrib/ffmpeg/libavformat/mm.c212
-rw-r--r--contrib/ffmpeg/libavformat/mmf.c331
-rw-r--r--contrib/ffmpeg/libavformat/mov.c1696
-rw-r--r--contrib/ffmpeg/libavformat/movenc.c1689
-rw-r--r--contrib/ffmpeg/libavformat/mp3.c431
-rw-r--r--contrib/ffmpeg/libavformat/mpc.c231
-rw-r--r--contrib/ffmpeg/libavformat/mpeg.c1853
-rw-r--r--contrib/ffmpeg/libavformat/mpegts.c1552
-rw-r--r--contrib/ffmpeg/libavformat/mpegts.h63
-rw-r--r--contrib/ffmpeg/libavformat/mpegtsenc.c695
-rw-r--r--contrib/ffmpeg/libavformat/mpjpeg.c67
-rw-r--r--contrib/ffmpeg/libavformat/mtv.c187
-rw-r--r--contrib/ffmpeg/libavformat/mxf.c1024
-rw-r--r--contrib/ffmpeg/libavformat/network.h37
-rw-r--r--contrib/ffmpeg/libavformat/nsvdec.c765
-rw-r--r--contrib/ffmpeg/libavformat/nut.c1457
-rw-r--r--contrib/ffmpeg/libavformat/nut.h97
-rw-r--r--contrib/ffmpeg/libavformat/nutdec.c885
-rw-r--r--contrib/ffmpeg/libavformat/nuv.c241
-rw-r--r--contrib/ffmpeg/libavformat/ogg.c283
-rw-r--r--contrib/ffmpeg/libavformat/ogg2.c700
-rw-r--r--contrib/ffmpeg/libavformat/ogg2.h86
-rw-r--r--contrib/ffmpeg/libavformat/oggparseflac.c82
-rw-r--r--contrib/ffmpeg/libavformat/oggparseogm.c166
-rw-r--r--contrib/ffmpeg/libavformat/oggparsetheora.c129
-rw-r--r--contrib/ffmpeg/libavformat/oggparsevorbis.c205
-rw-r--r--contrib/ffmpeg/libavformat/os_support.c167
-rw-r--r--contrib/ffmpeg/libavformat/os_support.h111
-rw-r--r--contrib/ffmpeg/libavformat/psxstr.c364
-rw-r--r--contrib/ffmpeg/libavformat/qtpalette.h311
-rw-r--r--contrib/ffmpeg/libavformat/raw.c901
-rw-r--r--contrib/ffmpeg/libavformat/riff.c500
-rw-r--r--contrib/ffmpeg/libavformat/riff.h55
-rw-r--r--contrib/ffmpeg/libavformat/rm.c1147
-rw-r--r--contrib/ffmpeg/libavformat/rtp.c1085
-rw-r--r--contrib/ffmpeg/libavformat/rtp.h127
-rw-r--r--contrib/ffmpeg/libavformat/rtp_h264.c413
-rw-r--r--contrib/ffmpeg/libavformat/rtp_h264.h26
-rw-r--r--contrib/ffmpeg/libavformat/rtp_internal.h110
-rw-r--r--contrib/ffmpeg/libavformat/rtpproto.c295
-rw-r--r--contrib/ffmpeg/libavformat/rtsp.c1486
-rw-r--r--contrib/ffmpeg/libavformat/rtsp.h94
-rw-r--r--contrib/ffmpeg/libavformat/rtspcodes.h36
-rw-r--r--contrib/ffmpeg/libavformat/segafilm.c295
-rw-r--r--contrib/ffmpeg/libavformat/sierravmd.c302
-rw-r--r--contrib/ffmpeg/libavformat/smacker.c345
-rw-r--r--contrib/ffmpeg/libavformat/sol.c160
-rw-r--r--contrib/ffmpeg/libavformat/swf.c797
-rw-r--r--contrib/ffmpeg/libavformat/tcp.c200
-rw-r--r--contrib/ffmpeg/libavformat/thp.c170
-rw-r--r--contrib/ffmpeg/libavformat/tiertexseq.c313
-rw-r--r--contrib/ffmpeg/libavformat/tta.c150
-rw-r--r--contrib/ffmpeg/libavformat/udp.c492
-rw-r--r--contrib/ffmpeg/libavformat/utils.c2888
-rw-r--r--contrib/ffmpeg/libavformat/v4l2.c631
-rw-r--r--contrib/ffmpeg/libavformat/voc.c36
-rw-r--r--contrib/ffmpeg/libavformat/voc.h51
-rw-r--r--contrib/ffmpeg/libavformat/vocdec.c155
-rw-r--r--contrib/ffmpeg/libavformat/vocenc.c103
-rw-r--r--contrib/ffmpeg/libavformat/wav.c285
-rw-r--r--contrib/ffmpeg/libavformat/wc3movie.c394
-rw-r--r--contrib/ffmpeg/libavformat/westwood.c400
-rw-r--r--contrib/ffmpeg/libavformat/wv.c241
-rw-r--r--contrib/ffmpeg/libavformat/x11grab.c529
-rw-r--r--contrib/ffmpeg/libavformat/yuv4mpeg.c408
-rw-r--r--contrib/ffmpeg/libavutil/Makefile27
-rw-r--r--contrib/ffmpeg/libavutil/adler32.c (renamed from src/libffmpeg/libavutil/adler32.c)0
-rw-r--r--contrib/ffmpeg/libavutil/adler32.h (renamed from src/libffmpeg/libavutil/adler32.h)0
-rw-r--r--contrib/ffmpeg/libavutil/aes.c239
-rw-r--r--contrib/ffmpeg/libavutil/aes.h45
-rw-r--r--contrib/ffmpeg/libavutil/avutil.h137
-rw-r--r--contrib/ffmpeg/libavutil/base64.c230
-rw-r--r--contrib/ffmpeg/libavutil/base64.h34
-rw-r--r--contrib/ffmpeg/libavutil/bswap.h (renamed from src/libffmpeg/libavutil/bswap.h)0
-rw-r--r--contrib/ffmpeg/libavutil/common.h326
-rw-r--r--contrib/ffmpeg/libavutil/crc.c111
-rw-r--r--contrib/ffmpeg/libavutil/crc.h42
-rw-r--r--contrib/ffmpeg/libavutil/fifo.c114
-rw-r--r--contrib/ffmpeg/libavutil/fifo.h100
-rw-r--r--contrib/ffmpeg/libavutil/integer.c197
-rw-r--r--contrib/ffmpeg/libavutil/integer.h82
-rw-r--r--contrib/ffmpeg/libavutil/internal.h293
-rw-r--r--contrib/ffmpeg/libavutil/intfloat_readwrite.c97
-rw-r--r--contrib/ffmpeg/libavutil/intfloat_readwrite.h (renamed from src/libffmpeg/libavutil/intfloat_readwrite.h)0
-rw-r--r--contrib/ffmpeg/libavutil/intreadwrite.h99
-rw-r--r--contrib/ffmpeg/libavutil/lls.c (renamed from src/libffmpeg/libavutil/lls.c)0
-rw-r--r--contrib/ffmpeg/libavutil/lls.h (renamed from src/libffmpeg/libavutil/lls.h)0
-rw-r--r--contrib/ffmpeg/libavutil/log.c (renamed from src/libffmpeg/libavutil/log.c)0
-rw-r--r--contrib/ffmpeg/libavutil/log.h116
-rw-r--r--contrib/ffmpeg/libavutil/lzo.c273
-rw-r--r--contrib/ffmpeg/libavutil/lzo.h (renamed from src/libffmpeg/libavcodec/lzo.h)0
-rw-r--r--contrib/ffmpeg/libavutil/mathematics.c (renamed from src/libffmpeg/libavutil/mathematics.c)0
-rw-r--r--contrib/ffmpeg/libavutil/mathematics.h (renamed from src/libffmpeg/libavutil/mathematics.h)0
-rw-r--r--contrib/ffmpeg/libavutil/md5.c180
-rw-r--r--contrib/ffmpeg/libavutil/md5.h (renamed from src/libffmpeg/libavutil/md5.h)0
-rw-r--r--contrib/ffmpeg/libavutil/mem.c152
-rw-r--r--contrib/ffmpeg/libavutil/mem.h65
-rw-r--r--contrib/ffmpeg/libavutil/random.c104
-rw-r--r--contrib/ffmpeg/libavutil/random.h69
-rw-r--r--contrib/ffmpeg/libavutil/rational.c104
-rw-r--r--contrib/ffmpeg/libavutil/rational.h114
-rw-r--r--contrib/ffmpeg/libavutil/sha1.c160
-rw-r--r--contrib/ffmpeg/libavutil/sha1.h11
-rw-r--r--contrib/ffmpeg/libavutil/softfloat.c72
-rw-r--r--contrib/ffmpeg/libavutil/softfloat.h122
-rw-r--r--contrib/ffmpeg/libavutil/tree.c151
-rw-r--r--contrib/ffmpeg/libavutil/tree.h58
-rw-r--r--contrib/ffmpeg/libavutil/x86_cpu.h64
-rw-r--r--contrib/ffmpeg/libpostproc/Makefile24
-rw-r--r--contrib/ffmpeg/libpostproc/mangle.h47
-rw-r--r--contrib/ffmpeg/libpostproc/postprocess.c1144
-rw-r--r--contrib/ffmpeg/libpostproc/postprocess.h84
-rw-r--r--contrib/ffmpeg/libpostproc/postprocess_altivec_template.c1192
-rw-r--r--contrib/ffmpeg/libpostproc/postprocess_internal.h183
-rw-r--r--contrib/ffmpeg/libpostproc/postprocess_template.c3843
-rw-r--r--contrib/ffmpeg/libswscale/Makefile24
-rw-r--r--contrib/ffmpeg/libswscale/cs_test.c303
-rw-r--r--contrib/ffmpeg/libswscale/rgb2rgb.c665
-rw-r--r--contrib/ffmpeg/libswscale/rgb2rgb.h147
-rw-r--r--contrib/ffmpeg/libswscale/rgb2rgb_template.c2688
-rw-r--r--contrib/ffmpeg/libswscale/swscale-example.c229
-rw-r--r--contrib/ffmpeg/libswscale/swscale.c2868
-rw-r--r--contrib/ffmpeg/libswscale/swscale.h148
-rw-r--r--contrib/ffmpeg/libswscale/swscale_altivec_template.c548
-rw-r--r--contrib/ffmpeg/libswscale/swscale_internal.h224
-rw-r--r--contrib/ffmpeg/libswscale/swscale_template.c3288
-rw-r--r--contrib/ffmpeg/libswscale/yuv2rgb.c851
-rw-r--r--contrib/ffmpeg/libswscale/yuv2rgb_altivec.c963
-rw-r--r--contrib/ffmpeg/libswscale/yuv2rgb_init.c412
-rw-r--r--contrib/ffmpeg/libswscale/yuv2rgb_mlib.c86
-rw-r--r--contrib/ffmpeg/libswscale/yuv2rgb_template.c540
-rw-r--r--contrib/ffmpeg/output_example.c546
-rw-r--r--contrib/ffmpeg/pktdumper.c117
-rw-r--r--contrib/ffmpeg/qt-faststart.c311
-rw-r--r--contrib/ffmpeg/tests/Makefile114
-rw-r--r--contrib/ffmpeg/tests/audiogen.c187
-rw-r--r--contrib/ffmpeg/tests/dsptest.c178
-rw-r--r--contrib/ffmpeg/tests/ffmpeg.regression.ref198
-rw-r--r--contrib/ffmpeg/tests/ffserver.regression.ref10
-rw-r--r--contrib/ffmpeg/tests/lena.pnm109
-rw-r--r--contrib/ffmpeg/tests/libav.regression.ref113
-rwxr-xr-xcontrib/ffmpeg/tests/regression.sh722
-rw-r--r--contrib/ffmpeg/tests/rotozoom.c306
-rw-r--r--contrib/ffmpeg/tests/rotozoom.regression.ref198
-rw-r--r--contrib/ffmpeg/tests/seek_test.c91
-rwxr-xr-xcontrib/ffmpeg/tests/seek_test.sh25
-rwxr-xr-xcontrib/ffmpeg/tests/server-regression.sh54
-rw-r--r--contrib/ffmpeg/tests/test.conf307
-rw-r--r--contrib/ffmpeg/tests/tiny_psnr.c154
-rw-r--r--contrib/ffmpeg/tests/videogen.c297
-rwxr-xr-xcontrib/ffmpeg/unwrap-diff2
-rwxr-xr-xcontrib/ffmpeg/version.sh14
-rw-r--r--contrib/ffmpeg/vhook/Makefile50
-rw-r--r--contrib/ffmpeg/vhook/drawtext.c531
-rw-r--r--contrib/ffmpeg/vhook/fish.c380
-rw-r--r--contrib/ffmpeg/vhook/imlib2.c449
-rw-r--r--contrib/ffmpeg/vhook/null.c116
-rw-r--r--contrib/ffmpeg/vhook/ppm.c367
-rw-r--r--contrib/ffmpeg/vhook/watermark.c661
-rw-r--r--contrib/gsm610/Makefile.am26
-rw-r--r--contrib/gsm610/add.c (renamed from src/libxineadec/gsm610/add.c)0
-rw-r--r--contrib/gsm610/decode.c (renamed from src/libxineadec/gsm610/decode.c)0
-rw-r--r--contrib/gsm610/gsm.h (renamed from src/libxineadec/gsm610/gsm.h)0
-rw-r--r--contrib/gsm610/gsm_config.h (renamed from src/libxineadec/gsm610/gsm_config.h)0
-rw-r--r--contrib/gsm610/gsm_create.c (renamed from src/libxineadec/gsm610/gsm_create.c)0
-rw-r--r--contrib/gsm610/gsm_decode.c (renamed from src/libxineadec/gsm610/gsm_decode.c)0
-rw-r--r--contrib/gsm610/gsm_destroy.c (renamed from src/libxineadec/gsm610/gsm_destroy.c)0
-rw-r--r--contrib/gsm610/long_term.c (renamed from src/libxineadec/gsm610/long_term.c)0
-rw-r--r--contrib/gsm610/lpc.c (renamed from src/libxineadec/gsm610/lpc.c)0
-rw-r--r--contrib/gsm610/private.h (renamed from src/libxineadec/gsm610/private.h)0
-rw-r--r--contrib/gsm610/proto.h (renamed from src/libxineadec/gsm610/proto.h)0
-rw-r--r--contrib/gsm610/rpe.c (renamed from src/libxineadec/gsm610/rpe.c)0
-rw-r--r--contrib/gsm610/short_term.c (renamed from src/libxineadec/gsm610/short_term.c)0
-rw-r--r--contrib/gsm610/table.c (renamed from src/libxineadec/gsm610/table.c)0
-rw-r--r--contrib/gsm610/unproto.h (renamed from src/libxineadec/gsm610/unproto.h)0
-rw-r--r--contrib/libdca/COPYING339
-rw-r--r--contrib/libdca/Makefile.am16
-rw-r--r--contrib/libdca/bitstream.c112
-rw-r--r--contrib/libdca/bitstream.h68
-rw-r--r--contrib/libdca/dca_internal.h204
-rw-r--r--contrib/libdca/downmix.c694
-rw-r--r--contrib/libdca/include/dca.h86
-rw-r--r--contrib/libdca/include/dts.h55
-rw-r--r--contrib/libdca/parse.c1292
-rw-r--r--contrib/libdca/tables.h48
-rw-r--r--contrib/libdca/tables_adpcm.h4123
-rw-r--r--contrib/libdca/tables_fir.h2086
-rw-r--r--contrib/libdca/tables_huffman.h1072
-rw-r--r--contrib/libdca/tables_quantization.h89
-rw-r--r--contrib/libdca/tables_vq.h2076
-rw-r--r--contrib/libmad/COPYING340
-rw-r--r--contrib/libmad/D.dat607
-rw-r--r--contrib/libmad/Makefile.am44
-rw-r--r--contrib/libmad/bit.c237
-rw-r--r--contrib/libmad/bit.h47
-rw-r--r--contrib/libmad/decoder.c582
-rw-r--r--contrib/libmad/decoder.h91
-rw-r--r--contrib/libmad/fixed.c81
-rw-r--r--contrib/libmad/fixed.h499
-rw-r--r--contrib/libmad/frame.c503
-rw-r--r--contrib/libmad/frame.h118
-rw-r--r--contrib/libmad/global.h58
-rw-r--r--contrib/libmad/huffman.c3109
-rw-r--r--contrib/libmad/huffman.h66
-rw-r--r--contrib/libmad/imdct_s.dat62
-rw-r--r--contrib/libmad/layer12.c534
-rw-r--r--contrib/libmad/layer12.h31
-rw-r--r--contrib/libmad/layer3.c2698
-rw-r--r--contrib/libmad/layer3.h30
-rw-r--r--contrib/libmad/qc_table.dat77
-rw-r--r--contrib/libmad/rq_table.dat8747
-rw-r--r--contrib/libmad/sf_table.dat106
-rw-r--r--contrib/libmad/stream.c161
-rw-r--r--contrib/libmad/stream.h108
-rw-r--r--contrib/libmad/synth.c857
-rw-r--r--contrib/libmad/synth.h69
-rw-r--r--contrib/libmad/timer.c485
-rw-r--r--contrib/libmad/timer.h100
-rw-r--r--contrib/libmad/version.c91
-rw-r--r--contrib/libmad/version.h47
-rw-r--r--contrib/libmpcdec/COPYING31
-rw-r--r--contrib/libmpcdec/Makefile.am15
-rw-r--r--contrib/libmpcdec/diff_from_libmpcdec_1.2.5.patch20
-rw-r--r--contrib/libmpcdec/huffsv46.c75
-rw-r--r--contrib/libmpcdec/huffsv7.c81
-rw-r--r--contrib/libmpcdec/idtag.c83
-rw-r--r--contrib/libmpcdec/mpc_decoder.c1271
-rw-r--r--contrib/libmpcdec/mpc_reader.c96
-rw-r--r--contrib/libmpcdec/mpcdec/config_types.h50
-rw-r--r--contrib/libmpcdec/mpcdec/decoder.h124
-rw-r--r--contrib/libmpcdec/mpcdec/huffman.h58
-rw-r--r--contrib/libmpcdec/mpcdec/internal.h65
-rw-r--r--contrib/libmpcdec/mpcdec/math.h144
-rw-r--r--contrib/libmpcdec/mpcdec/mpcdec.h145
-rw-r--r--contrib/libmpcdec/mpcdec/reader.h82
-rw-r--r--contrib/libmpcdec/mpcdec/requant.h51
-rw-r--r--contrib/libmpcdec/mpcdec/streaminfo.h91
-rw-r--r--contrib/libmpcdec/requant.c120
-rw-r--r--contrib/libmpcdec/streaminfo.c281
-rw-r--r--contrib/libmpcdec/synth_filter.c440
-rw-r--r--contrib/libxdg-basedir/Makefile.am7
-rw-r--r--contrib/libxdg-basedir/basedir.c486
-rw-r--r--contrib/libxdg-basedir/basedir.h185
-rw-r--r--contrib/nosefart/Makefile.am37
-rw-r--r--contrib/nosefart/diff_to_nosefart_cvs.patch117
-rw-r--r--contrib/nosefart/dis6502.c (renamed from src/libxineadec/nosefart/dis6502.c)0
-rw-r--r--contrib/nosefart/dis6502.h (renamed from src/libxineadec/nosefart/dis6502.h)0
-rw-r--r--contrib/nosefart/fds_snd.c (renamed from src/libxineadec/nosefart/fds_snd.c)0
-rw-r--r--contrib/nosefart/fds_snd.h (renamed from src/libxineadec/nosefart/fds_snd.h)0
-rw-r--r--contrib/nosefart/fmopl.c (renamed from src/libxineadec/nosefart/fmopl.c)0
-rw-r--r--contrib/nosefart/fmopl.h (renamed from src/libxineadec/nosefart/fmopl.h)0
-rw-r--r--contrib/nosefart/log.c (renamed from src/libxineadec/nosefart/log.c)0
-rw-r--r--contrib/nosefart/log.h (renamed from src/libxineadec/nosefart/log.h)0
-rw-r--r--contrib/nosefart/memguard.c (renamed from src/libxineadec/nosefart/memguard.c)0
-rw-r--r--contrib/nosefart/memguard.h (renamed from src/libxineadec/nosefart/memguard.h)0
-rw-r--r--contrib/nosefart/mmc5_snd.c (renamed from src/libxineadec/nosefart/mmc5_snd.c)0
-rw-r--r--contrib/nosefart/mmc5_snd.h (renamed from src/libxineadec/nosefart/mmc5_snd.h)0
-rw-r--r--contrib/nosefart/nes6502.c (renamed from src/libxineadec/nosefart/nes6502.c)0
-rw-r--r--contrib/nosefart/nes6502.h (renamed from src/libxineadec/nosefart/nes6502.h)0
-rw-r--r--contrib/nosefart/nes_apu.c (renamed from src/libxineadec/nosefart/nes_apu.c)0
-rw-r--r--contrib/nosefart/nes_apu.h (renamed from src/libxineadec/nosefart/nes_apu.h)0
-rw-r--r--contrib/nosefart/nsf.c (renamed from src/libxineadec/nosefart/nsf.c)0
-rw-r--r--contrib/nosefart/nsf.h152
-rw-r--r--contrib/nosefart/osd.h94
-rw-r--r--contrib/nosefart/types.h (renamed from src/libxineadec/nosefart/types.h)0
-rw-r--r--contrib/nosefart/version.h (renamed from src/libxineadec/nosefart/version.h)0
-rw-r--r--contrib/nosefart/vrc7_snd.c (renamed from src/libxineadec/nosefart/vrc7_snd.c)0
-rw-r--r--contrib/nosefart/vrc7_snd.h (renamed from src/libxineadec/nosefart/vrc7_snd.h)0
-rw-r--r--contrib/nosefart/vrcvisnd.c (renamed from src/libxineadec/nosefart/vrcvisnd.c)0
-rw-r--r--contrib/nosefart/vrcvisnd.h (renamed from src/libxineadec/nosefart/vrcvisnd.h)0
-rw-r--r--debian/changelog7
-rw-r--r--debian/control8
-rw-r--r--debian/libxine1.install11
-rw-r--r--debian/libxine2.install11
-rw-r--r--debian/reportbug.presubj4
-rwxr-xr-xdebian/rules11
-rw-r--r--doc/Doxyfile.in1039
-rw-r--r--doc/Makefile.am2
-rw-r--r--doc/README3
-rw-r--r--doc/README.dvb6
-rw-r--r--doc/README.macosx141
-rw-r--r--doc/faq/faq.sgml11
-rw-r--r--doc/man/en/xine.53
-rw-r--r--include/Makefile.am6
-rw-r--r--include/xine.h.in42
-rw-r--r--lib/Makefile.am2
-rw-r--r--lib/os_internal.h72
-rw-r--r--lib/timedlock.c33
-rw-r--r--m4/Makefile.am37
-rw-r--r--m4/_xine.m4568
-rw-r--r--m4/aa.m4272
-rw-r--r--m4/arts.m4168
-rw-r--r--m4/attributes.m4105
-rw-r--r--m4/audio_out.m4239
-rw-r--r--m4/decoders.m4495
-rw-r--r--m4/directx.m494
-rw-r--r--m4/dl.m453
-rw-r--r--m4/dvdnav.m4187
-rw-r--r--m4/gas.m4197
-rw-r--r--m4/gettext.m4549
-rw-r--r--m4/gettext/Makefile.am32
-rw-r--r--m4/gettext/codeset.m4 (renamed from m4/codeset.m4)0
-rw-r--r--m4/gettext/gettext.m4419
-rw-r--r--m4/gettext/glibc2.m4 (renamed from m4/glibc2.m4)0
-rw-r--r--m4/gettext/glibc21.m4 (renamed from m4/glibc21.m4)0
-rw-r--r--m4/gettext/iconv.m4101
-rw-r--r--m4/gettext/intdiv0.m4 (renamed from m4/intdiv0.m4)0
-rw-r--r--m4/gettext/intmax.m4 (renamed from m4/intmax.m4)0
-rw-r--r--m4/gettext/inttypes-pri.m4 (renamed from m4/inttypes-pri.m4)0
-rw-r--r--m4/gettext/inttypes.m4 (renamed from m4/inttypes.m4)0
-rw-r--r--m4/gettext/inttypes_h.m4 (renamed from m4/inttypes_h.m4)0
-rw-r--r--m4/gettext/isc-posix.m4 (renamed from m4/isc-posix.m4)0
-rw-r--r--m4/gettext/lcmessage.m4 (renamed from m4/lcmessage.m4)0
-rw-r--r--m4/gettext/lib-ld.m4 (renamed from m4/lib-ld.m4)0
-rw-r--r--m4/gettext/lib-link.m4644
-rw-r--r--m4/gettext/lib-prefix.m4185
-rw-r--r--m4/gettext/longdouble.m4 (renamed from m4/longdouble.m4)0
-rw-r--r--m4/gettext/longlong.m4 (renamed from m4/longlong.m4)0
-rw-r--r--m4/gettext/nls.m431
-rw-r--r--m4/gettext/po.m4428
-rw-r--r--m4/gettext/printf-posix.m4 (renamed from m4/printf-posix.m4)0
-rw-r--r--m4/gettext/progtest.m4 (renamed from m4/progtest.m4)0
-rw-r--r--m4/gettext/signed.m4 (renamed from m4/signed.m4)0
-rw-r--r--m4/gettext/size_max.m4 (renamed from m4/size_max.m4)0
-rw-r--r--m4/gettext/stdint_h.m4 (renamed from m4/stdint_h.m4)0
-rw-r--r--m4/gettext/uintmax_t.m4 (renamed from m4/uintmax_t.m4)0
-rw-r--r--m4/gettext/ulonglong.m4 (renamed from m4/ulonglong.m4)0
-rw-r--r--m4/gettext/wchar_t.m4 (renamed from m4/wchar_t.m4)0
-rw-r--r--m4/gettext/wint_t.m4 (renamed from m4/wint_t.m4)0
-rw-r--r--m4/gettext/xsize.m4 (renamed from m4/xsize.m4)0
-rw-r--r--m4/iconv.m4117
-rw-r--r--m4/input.m4280
-rw-r--r--m4/ioctl_request.m452
-rw-r--r--m4/irixal.m419
-rw-r--r--m4/lib-link.m4553
-rw-r--r--m4/lib-prefix.m4153
-rw-r--r--m4/libFLAC.m427
-rw-r--r--m4/libfame.m4183
-rw-r--r--m4/libtool15.m46168
-rw-r--r--m4/macosx.m443
-rw-r--r--m4/nls.m451
-rw-r--r--m4/objc.m4253
-rw-r--r--m4/opengl.m474
-rw-r--r--m4/optimizations.m4252
-rw-r--r--m4/package.m472
-rw-r--r--m4/pkg.m46
-rw-r--r--m4/po.m4429
-rw-r--r--m4/programs.m4124
-rw-r--r--m4/pthreads.m425
-rw-r--r--m4/summary.m4364
-rw-r--r--m4/types.m4215
-rw-r--r--m4/video_out.m4519
-rw-r--r--m4/xine.m4256
-rw-r--r--m4/xv.m493
-rw-r--r--misc/Makefile.common15
-rw-r--r--misc/SlackBuild.in14
-rw-r--r--misc/build_rpms.sh.in12
-rw-r--r--misc/fonts/Makefile.am6
-rwxr-xr-x[-rw-r--r--]misc/relchk.sh.in2
-rw-r--r--misc/xine-lib.spec.in258
-rw-r--r--po/Makefile.in.in58
-rw-r--r--po/Makefile.in.in.diff30
-rw-r--r--po/POTFILES.in8
-rw-r--r--po/cs.po1228
-rw-r--r--po/de.po1228
-rw-r--r--po/es.po959
-rw-r--r--po/eu.po1003
-rw-r--r--po/fr.po899
-rw-r--r--po/it.po1237
-rw-r--r--po/libxine1.pot899
-rw-r--r--po/pl.po910
-rw-r--r--po/pt_BR.po899
-rw-r--r--po/sk.po1208
-rw-r--r--src/Makefile.am6
-rw-r--r--src/audio_out/Makefile.am105
-rwxr-xr-x[-rw-r--r--]src/audio_out/audio_directx_out.c0
-rw-r--r--src/combined/Makefile.am31
-rw-r--r--src/combined/combined_wavpack.c46
-rw-r--r--src/combined/combined_wavpack.h49
-rw-r--r--src/combined/decoder_flac.c435
-rw-r--r--src/combined/decoder_wavpack.c337
-rw-r--r--src/combined/demux_flac.h28
-rw-r--r--src/combined/demux_wavpack.c414
-rw-r--r--src/combined/flac_decoder.c426
-rw-r--r--src/combined/flac_demuxer.c (renamed from src/combined/demux_flac.c)0
-rw-r--r--src/combined/nsf_combined.c46
-rw-r--r--src/combined/nsf_decoder.c268
-rw-r--r--src/combined/nsf_demuxer.c391
-rw-r--r--src/combined/wavpack_combined.c46
-rw-r--r--src/combined/wavpack_combined.h46
-rw-r--r--src/combined/wavpack_decoder.c339
-rw-r--r--src/combined/wavpack_demuxer.c414
-rw-r--r--src/demuxers/Makefile.am54
-rw-r--r--src/demuxers/demux_film.c2
-rw-r--r--src/demuxers/demux_flac.c4
-rw-r--r--src/demuxers/demux_flv.c2
-rw-r--r--src/demuxers/demux_matroska.c11
-rw-r--r--src/demuxers/demux_mod.c14
-rw-r--r--src/demuxers/demux_mpgaudio.c2
-rw-r--r--src/demuxers/demux_nsf.c392
-rw-r--r--src/demuxers/demux_qt.c13
-rw-r--r--src/demuxers/demux_real.c4
-rw-r--r--src/demuxers/demux_ts.c4
-rw-r--r--src/demuxers/demux_tta.c10
-rw-r--r--src/demuxers/demux_wc3movie.c8
-rw-r--r--src/demuxers/group_audio.c14
-rw-r--r--src/demuxers/group_audio.h5
-rw-r--r--src/dxr3/Makefile.am39
-rw-r--r--src/input/Makefile.am100
-rw-r--r--src/input/input_cdda.c71
-rw-r--r--src/input/input_dvb.c29
-rw-r--r--src/input/input_dvd.c23
-rw-r--r--src/input/input_file.c6
-rw-r--r--src/input/input_http.c27
-rw-r--r--src/input/input_mms.c14
-rw-r--r--src/input/input_smb.c4
-rw-r--r--src/input/libdvdnav/Makefile.am6
-rw-r--r--src/input/libdvdnav/diff_against_cvs.patch33
-rw-r--r--src/input/libdvdnav/ifo_types.h22
-rw-r--r--src/input/libreal/Makefile.am19
-rw-r--r--src/input/libreal/real.c2
-rw-r--r--src/input/librtsp/Makefile.am16
-rw-r--r--src/input/vcd/Makefile.am27
-rw-r--r--src/input/vcd/libcdio/Makefile.am42
-rw-r--r--src/input/vcd/libvcd/Makefile.am69
-rw-r--r--src/input/vcd/xineplug_inp_vcd.c4
-rw-r--r--src/liba52/Makefile.am41
-rw-r--r--src/libdts/Makefile.am28
-rw-r--r--src/libdts/bitstream.c111
-rw-r--r--src/libdts/bitstream.h67
-rw-r--r--src/libdts/downmix.c691
-rw-r--r--src/libdts/dts_internal.h203
-rw-r--r--src/libdts/internal-dts.h85
-rw-r--r--src/libdts/parse.c1290
-rw-r--r--src/libdts/tables.h47
-rw-r--r--src/libdts/tables_adpcm.h4122
-rw-r--r--src/libdts/tables_fir.h2085
-rw-r--r--src/libdts/tables_huffman.h1070
-rw-r--r--src/libdts/tables_quantization.h88
-rw-r--r--src/libdts/tables_vq.h2075
-rw-r--r--src/libdts/xine_dts_decoder.c619
-rw-r--r--src/libfaad/Makefile.am102
-rw-r--r--src/libfaad/xine_faad_decoder.c11
-rw-r--r--src/libffmpeg/Makefile.am65
-rw-r--r--src/libffmpeg/diff_to_ffmpeg_cvs.txt619
-rw-r--r--src/libffmpeg/ff_audio_decoder.c136
-rw-r--r--src/libffmpeg/ff_dvaudio_decoder.c12
-rw-r--r--src/libffmpeg/ff_video_decoder.c298
-rw-r--r--src/libffmpeg/ffmpeg_decoder.c271
-rw-r--r--src/libffmpeg/ffmpeg_decoder.h8
-rw-r--r--src/libffmpeg/ffmpeg_encoder.c6
-rw-r--r--src/libffmpeg/libavcodec/4xm.c759
-rw-r--r--src/libffmpeg/libavcodec/8bps.c236
-rw-r--r--src/libffmpeg/libavcodec/Makefile.am190
-rw-r--r--src/libffmpeg/libavcodec/aasc.c176
-rw-r--r--src/libffmpeg/libavcodec/adpcm.c1370
-rw-r--r--src/libffmpeg/libavcodec/alpha/Makefile.am13
-rw-r--r--src/libffmpeg/libavcodec/alpha/dsputil_alpha_asm.S285
-rw-r--r--src/libffmpeg/libavcodec/alpha/motion_est_mvi_asm.S185
-rw-r--r--src/libffmpeg/libavcodec/alpha/simple_idct_alpha.c308
-rw-r--r--src/libffmpeg/libavcodec/armv4l/Makefile.am23
-rw-r--r--src/libffmpeg/libavcodec/armv4l/dsputil_arm.c262
-rw-r--r--src/libffmpeg/libavcodec/armv4l/dsputil_iwmmxt.c188
-rw-r--r--src/libffmpeg/libavcodec/armv4l/libavcodec_armv4l_dummy.c2
-rw-r--r--src/libffmpeg/libavcodec/armv4l/mpegvideo_arm.c36
-rw-r--r--src/libffmpeg/libavcodec/armv4l/mpegvideo_armv5te.c213
-rw-r--r--src/libffmpeg/libavcodec/avcodec.h2714
-rw-r--r--src/libffmpeg/libavcodec/bitstream.c254
-rw-r--r--src/libffmpeg/libavcodec/bitstream.h956
-rw-r--r--src/libffmpeg/libavcodec/bytestream.h89
-rw-r--r--src/libffmpeg/libavcodec/cabac.h859
-rw-r--r--src/libffmpeg/libavcodec/cavs.c1540
-rw-r--r--src/libffmpeg/libavcodec/cook.c1362
-rw-r--r--src/libffmpeg/libavcodec/cscd.c264
-rw-r--r--src/libffmpeg/libavcodec/dsputil.c4184
-rw-r--r--src/libffmpeg/libavcodec/dsputil.h759
-rw-r--r--src/libffmpeg/libavcodec/dv.c1266
-rw-r--r--src/libffmpeg/libavcodec/error_resilience.c1030
-rw-r--r--src/libffmpeg/libavcodec/eval.c466
-rw-r--r--src/libffmpeg/libavcodec/fastmemcpy.h4
-rw-r--r--src/libffmpeg/libavcodec/ffv1.c1040
-rw-r--r--src/libffmpeg/libavcodec/flicvideo.c754
-rw-r--r--src/libffmpeg/libavcodec/g726.c429
-rw-r--r--src/libffmpeg/libavcodec/h261.c1055
-rw-r--r--src/libffmpeg/libavcodec/h263.c6312
-rw-r--r--src/libffmpeg/libavcodec/h263dec.c913
-rw-r--r--src/libffmpeg/libavcodec/h264.c8653
-rw-r--r--src/libffmpeg/libavcodec/huffyuv.c1290
-rw-r--r--src/libffmpeg/libavcodec/i386/Makefile.am54
-rw-r--r--src/libffmpeg/libavcodec/i386/dsputil_h264_template_mmx.c326
-rw-r--r--src/libffmpeg/libavcodec/i386/dsputil_mmx.c3540
-rw-r--r--src/libffmpeg/libavcodec/i386/h264dsp_mmx.c1513
-rw-r--r--src/libffmpeg/libavcodec/i386/idct_mmx_xvid.c535
-rw-r--r--src/libffmpeg/libavcodec/i386/libavcodec_mmx_dummy.c2
-rw-r--r--src/libffmpeg/libavcodec/imgconvert.c2855
-rw-r--r--src/libffmpeg/libavcodec/imgconvert_template.h875
-rw-r--r--src/libffmpeg/libavcodec/imgresample.c949
-rw-r--r--src/libffmpeg/libavcodec/indeo2.c221
-rw-r--r--src/libffmpeg/libavcodec/indeo3.c1153
-rw-r--r--src/libffmpeg/libavcodec/jpeg_ls.c860
-rw-r--r--src/libffmpeg/libavcodec/kmvc.c417
-rw-r--r--src/libffmpeg/libavcodec/libpostproc/Makefile.am19
-rw-r--r--src/libffmpeg/libavcodec/libpostproc/mangle.h30
-rw-r--r--src/libffmpeg/libavcodec/libpostproc/postprocess.c1157
-rw-r--r--src/libffmpeg/libavcodec/libpostproc/postprocess.h82
-rw-r--r--src/libffmpeg/libavcodec/libpostproc/postprocess_altivec_template.c1196
-rw-r--r--src/libffmpeg/libavcodec/libpostproc/postprocess_internal.h174
-rw-r--r--src/libffmpeg/libavcodec/libpostproc/postprocess_template.c3847
-rw-r--r--src/libffmpeg/libavcodec/loco.c287
-rw-r--r--src/libffmpeg/libavcodec/lzo.c268
-rw-r--r--src/libffmpeg/libavcodec/mjpeg.c2632
-rw-r--r--src/libffmpeg/libavcodec/mlib/Makefile.am18
-rw-r--r--src/libffmpeg/libavcodec/mlib/dsputil_mlib.c466
-rw-r--r--src/libffmpeg/libavcodec/mlib/libavcodec_mlib_dummy.c2
-rw-r--r--src/libffmpeg/libavcodec/motion_est.c2149
-rw-r--r--src/libffmpeg/libavcodec/motion_est_template.c1238
-rw-r--r--src/libffmpeg/libavcodec/mpeg12.c3504
-rw-r--r--src/libffmpeg/libavcodec/mpeg12data.h469
-rw-r--r--src/libffmpeg/libavcodec/mpegaudiodec.c2879
-rw-r--r--src/libffmpeg/libavcodec/mpegvideo.c7013
-rw-r--r--src/libffmpeg/libavcodec/mpegvideo.h931
-rw-r--r--src/libffmpeg/libavcodec/msmpeg4.c1938
-rw-r--r--src/libffmpeg/libavcodec/nuv.c216
-rw-r--r--src/libffmpeg/libavcodec/opt.c381
-rw-r--r--src/libffmpeg/libavcodec/opt.h83
-rw-r--r--src/libffmpeg/libavcodec/parser.c902
-rw-r--r--src/libffmpeg/libavcodec/pcm.c548
-rw-r--r--src/libffmpeg/libavcodec/ppc/Makefile.am36
-rw-r--r--src/libffmpeg/libavcodec/ppc/dsputil_h264_altivec.c319
-rw-r--r--src/libffmpeg/libavcodec/ppc/dsputil_h264_template_altivec.c717
-rw-r--r--src/libffmpeg/libavcodec/ppc/dsputil_ppc.c325
-rw-r--r--src/libffmpeg/libavcodec/ppc/dsputil_ppc.h155
-rw-r--r--src/libffmpeg/libavcodec/ppc/idct_altivec.c237
-rw-r--r--src/libffmpeg/libavcodec/ppc/libavcodec_ppc_dummy.c2
-rw-r--r--src/libffmpeg/libavcodec/qpeg.c324
-rw-r--r--src/libffmpeg/libavcodec/qtrle.c630
-rw-r--r--src/libffmpeg/libavcodec/ratecontrol.c944
-rw-r--r--src/libffmpeg/libavcodec/raw.c210
-rw-r--r--src/libffmpeg/libavcodec/resample2.c274
-rw-r--r--src/libffmpeg/libavcodec/roqvideo.c474
-rw-r--r--src/libffmpeg/libavcodec/rv10.c803
-rw-r--r--src/libffmpeg/libavcodec/shorten.c533
-rw-r--r--src/libffmpeg/libavcodec/simple_idct.c587
-rw-r--r--src/libffmpeg/libavcodec/smacker.c723
-rw-r--r--src/libffmpeg/libavcodec/snow.c4720
-rw-r--r--src/libffmpeg/libavcodec/snow.h176
-rw-r--r--src/libffmpeg/libavcodec/sparc/Makefile.am18
-rw-r--r--src/libffmpeg/libavcodec/sparc/libavcodec_sparc_dummy.c2
-rw-r--r--src/libffmpeg/libavcodec/svq1.c1431
-rw-r--r--src/libffmpeg/libavcodec/svq3.c1015
-rw-r--r--src/libffmpeg/libavcodec/swscale.h146
-rw-r--r--src/libffmpeg/libavcodec/truemotion1.c923
-rw-r--r--src/libffmpeg/libavcodec/truemotion2.c893
-rw-r--r--src/libffmpeg/libavcodec/truespeech.c381
-rw-r--r--src/libffmpeg/libavcodec/tscc.c348
-rw-r--r--src/libffmpeg/libavcodec/ulti.c428
-rw-r--r--src/libffmpeg/libavcodec/utils.c1354
-rw-r--r--src/libffmpeg/libavcodec/vc1.c4390
-rw-r--r--src/libffmpeg/libavcodec/vc1data.h652
-rw-r--r--src/libffmpeg/libavcodec/vc1dsp.c463
-rw-r--r--src/libffmpeg/libavcodec/vmdav.c572
-rw-r--r--src/libffmpeg/libavcodec/vorbis.c1814
-rw-r--r--src/libffmpeg/libavcodec/vp3.c2657
-rw-r--r--src/libffmpeg/libavcodec/vp5.c290
-rw-r--r--src/libffmpeg/libavcodec/vp56.c665
-rw-r--r--src/libffmpeg/libavcodec/vp56.h252
-rw-r--r--src/libffmpeg/libavcodec/vp56data.h248
-rw-r--r--src/libffmpeg/libavcodec/vp6.c556
-rw-r--r--src/libffmpeg/libavcodec/wavpack.c556
-rw-r--r--src/libffmpeg/libavcodec/wmadata.h1433
-rw-r--r--src/libffmpeg/libavcodec/wmadec.c1337
-rw-r--r--src/libffmpeg/libavcodec/wmv2.c861
-rw-r--r--src/libffmpeg/libavcodec/zmbv.c692
-rw-r--r--src/libffmpeg/libavutil/Makefile.am38
-rw-r--r--src/libffmpeg/libavutil/avutil.h137
-rw-r--r--src/libffmpeg/libavutil/common.h364
-rw-r--r--src/libffmpeg/libavutil/crc.c104
-rw-r--r--src/libffmpeg/libavutil/crc.h35
-rw-r--r--src/libffmpeg/libavutil/integer.c223
-rw-r--r--src/libffmpeg/libavutil/integer.h49
-rw-r--r--src/libffmpeg/libavutil/internal.h328
-rw-r--r--src/libffmpeg/libavutil/intreadwrite.h65
-rw-r--r--src/libffmpeg/libavutil/log.h102
-rw-r--r--src/libffmpeg/libavutil/md5.c186
-rw-r--r--src/libffmpeg/libavutil/mem.c171
-rw-r--r--src/libffmpeg/libavutil/rational.c120
-rw-r--r--src/libffmpeg/libavutil/rational.h71
-rw-r--r--src/libffmpeg/libavutil/x86_cpu.h60
-rw-r--r--src/libmad/D.dat607
-rw-r--r--src/libmad/Makefile.am57
-rw-r--r--src/libmad/bit.c237
-rw-r--r--src/libmad/bit.h47
-rw-r--r--src/libmad/fixed.c81
-rw-r--r--src/libmad/fixed.h499
-rw-r--r--src/libmad/frame.c503
-rw-r--r--src/libmad/frame.h118
-rw-r--r--src/libmad/global.h58
-rw-r--r--src/libmad/huffman.c3109
-rw-r--r--src/libmad/huffman.h66
-rw-r--r--src/libmad/imdct_l_arm.S1000
-rw-r--r--src/libmad/imdct_s.dat62
-rw-r--r--src/libmad/layer12.c534
-rw-r--r--src/libmad/layer12.h31
-rw-r--r--src/libmad/layer3.c2698
-rw-r--r--src/libmad/layer3.h30
-rw-r--r--src/libmad/qc_table.dat77
-rw-r--r--src/libmad/rq_table.dat8747
-rw-r--r--src/libmad/sf_table.dat100
-rw-r--r--src/libmad/stream.c161
-rw-r--r--src/libmad/stream.h108
-rw-r--r--src/libmad/synth.c857
-rw-r--r--src/libmad/synth.h69
-rw-r--r--src/libmad/timer.c485
-rw-r--r--src/libmad/timer.h100
-rw-r--r--src/libmad/version.c91
-rw-r--r--src/libmad/version.h47
-rw-r--r--src/libmpeg2/Makefile.am12
-rw-r--r--src/libmpeg2new/Makefile.am11
-rw-r--r--src/libmpeg2new/libmpeg2/Makefile.am3
-rw-r--r--src/libmusepack/Makefile.am26
-rw-r--r--src/libmusepack/diff_against_svn.patch55
-rw-r--r--src/libmusepack/huffsv46.c268
-rw-r--r--src/libmusepack/huffsv7.c500
-rw-r--r--src/libmusepack/idtag.c83
-rw-r--r--src/libmusepack/mpc_decoder.c1349
-rw-r--r--src/libmusepack/mpc_reader.c96
-rw-r--r--src/libmusepack/musepack/Makefile.am5
-rw-r--r--src/libmusepack/musepack/config_types.h23
-rw-r--r--src/libmusepack/musepack/decoder.h114
-rw-r--r--src/libmusepack/musepack/huffman.h41
-rw-r--r--src/libmusepack/musepack/internal.h34
-rw-r--r--src/libmusepack/musepack/math.h110
-rw-r--r--src/libmusepack/musepack/musepack.h94
-rw-r--r--src/libmusepack/musepack/reader.h46
-rw-r--r--src/libmusepack/musepack/requant.h17
-rw-r--r--src/libmusepack/musepack/streaminfo.h52
-rw-r--r--src/libmusepack/requant.c152
-rw-r--r--src/libmusepack/streaminfo.c280
-rw-r--r--src/libmusepack/synth_filter.c440
-rw-r--r--src/libmusepack/xine_musepack_decoder.c471
-rw-r--r--src/libreal/Makefile.am9
-rw-r--r--src/libspucc/Makefile.am10
-rw-r--r--src/libspucmml/Makefile.am5
-rw-r--r--src/libspudec/Makefile.am31
-rw-r--r--src/libspudvb/Makefile.am5
-rw-r--r--src/libsputext/Makefile.am3
-rw-r--r--src/libsputext/xine_sputext_decoder.c2
-rw-r--r--src/libw32dll/DirectShow/Makefile.am33
-rw-r--r--src/libw32dll/Makefile.am36
-rw-r--r--src/libw32dll/dmo/Makefile.am28
-rw-r--r--src/libw32dll/wine/Makefile.am57
-rw-r--r--src/libw32dll/wine/registry.c39
-rw-r--r--src/libw32dll/wine/windef.h7
-rw-r--r--src/libxineadec/Makefile.am69
-rw-r--r--src/libxineadec/gsm610.c14
-rw-r--r--src/libxineadec/gsm610/Makefile.am25
-rw-r--r--src/libxineadec/nosefart/Makefile.am34
-rw-r--r--src/libxineadec/nosefart/diff_to_nosefart_cvs.patch75
-rw-r--r--src/libxineadec/nosefart/nsf.h150
-rw-r--r--src/libxineadec/nosefart/osd.h98
-rw-r--r--src/libxineadec/nsf.c295
-rw-r--r--src/libxineadec/xine_dts_decoder.c592
-rw-r--r--src/libxineadec/xine_lpcm_decoder.c14
-rw-r--r--src/libxineadec/xine_mad_decoder.c (renamed from src/libmad/xine_mad_decoder.c)0
-rw-r--r--src/libxineadec/xine_musepack_decoder.c477
-rw-r--r--src/libxineadec/xine_vorbis_decoder.c4
-rw-r--r--src/libxinevdec/Makefile.am14
-rw-r--r--src/libxinevdec/bitplane.c8
-rw-r--r--src/post/Makefile.am3
-rw-r--r--src/post/audio/Makefile.am5
-rw-r--r--src/post/deinterlace/Makefile.am9
-rw-r--r--src/post/deinterlace/plugins/Makefile.am48
-rw-r--r--src/post/goom/Makefile.am47
-rwxr-xr-x[-rw-r--r--]src/post/goom/gfontlib.c0
-rwxr-xr-x[-rw-r--r--]src/post/goom/gfontlib.h0
-rwxr-xr-x[-rw-r--r--]src/post/goom/gfontrle.c0
-rwxr-xr-x[-rw-r--r--]src/post/goom/mathtools.h0
-rw-r--r--src/post/goom/mmx.h4
-rwxr-xr-x[-rw-r--r--]src/post/goom/surf3d.c0
-rwxr-xr-x[-rw-r--r--]src/post/goom/surf3d.h0
-rwxr-xr-x[-rw-r--r--]src/post/goom/tentacle3d.c0
-rwxr-xr-x[-rw-r--r--]src/post/goom/tentacle3d.h0
-rwxr-xr-x[-rw-r--r--]src/post/goom/v3d.h0
-rw-r--r--src/post/mosaico/Makefile.am7
-rw-r--r--src/post/mosaico/mosaico.c2
-rw-r--r--src/post/planar/Makefile.am44
-rwxr-xr-x[-rw-r--r--]src/post/planar/pp.c0
-rw-r--r--src/post/visualizations/Makefile.am9
-rw-r--r--src/vdr/Makefile.am17
-rw-r--r--src/vdr/input_vdr.c2545
-rw-r--r--src/vdr/input_vdr.h596
-rw-r--r--src/vdr/post_vdr.c44
-rw-r--r--src/vdr/post_vdr.h72
-rw-r--r--src/vdr/post_vdr_audio.c287
-rw-r--r--src/vdr/post_vdr_video.c492
-rw-r--r--src/video_out/Makefile.am119
-rw-r--r--src/video_out/deinterlace.h2
-rw-r--r--src/video_out/libdha/Makefile.am22
-rw-r--r--src/video_out/libdha/kernelhelper/Makefile.am43
-rw-r--r--src/video_out/macosx/Makefile.am25
-rw-r--r--src/video_out/video_out_directfb.c4
-rwxr-xr-x[-rw-r--r--]src/video_out/video_out_directx.c0
-rw-r--r--src/video_out/video_out_fb.c81
-rw-r--r--src/video_out/video_out_xcbshm.c29
-rw-r--r--src/video_out/video_out_xcbxv.c62
-rw-r--r--src/video_out/video_out_xshm.c40
-rw-r--r--src/video_out/video_out_xv.c71
-rw-r--r--src/video_out/video_out_xxmc.c141
-rw-r--r--src/video_out/vidix/Makefile.am17
-rw-r--r--src/video_out/vidix/drivers/Makefile.am62
-rw-r--r--src/xine-engine/Makefile.am48
-rw-r--r--src/xine-engine/alphablend.c4
-rw-r--r--src/xine-engine/alphablend.h25
-rw-r--r--src/xine-engine/audio_out.c34
-rw-r--r--src/xine-engine/audio_out.h9
-rw-r--r--src/xine-engine/buffer.h235
-rw-r--r--src/xine-engine/buffer_types.c402
-rw-r--r--src/xine-engine/configfile.h55
-rw-r--r--src/xine-engine/load_plugins.c88
-rw-r--r--src/xine-engine/metronom.h4
-rw-r--r--src/xine-engine/osd.c173
-rw-r--r--src/xine-engine/osd.h8
-rw-r--r--src/xine-engine/plugin_catalog.h6
-rw-r--r--src/xine-engine/post.c13
-rw-r--r--src/xine-engine/post.h16
-rw-r--r--src/xine-engine/refcounter.h2
-rw-r--r--src/xine-engine/scratch.c7
-rw-r--r--src/xine-engine/video_decoder.c10
-rw-r--r--src/xine-engine/video_out.c118
-rw-r--r--src/xine-engine/video_out.h17
-rw-r--r--src/xine-engine/video_overlay.h41
-rw-r--r--src/xine-engine/vo_scale.h7
-rw-r--r--src/xine-engine/xine.c130
-rw-r--r--src/xine-engine/xine_internal.h74
-rw-r--r--src/xine-utils/Makefile.am42
-rw-r--r--src/xine-utils/attributes.h24
-rw-r--r--src/xine-utils/memcpy.c6
-rw-r--r--src/xine-utils/monitor.c11
-rw-r--r--src/xine-utils/utils.c21
-rw-r--r--src/xine-utils/xineutils.h8
-rwxr-xr-xversion.sh50
-rwxr-xr-x[-rw-r--r--]win32/README0
-rwxr-xr-x[-rw-r--r--]win32/config.h0
-rwxr-xr-x[-rw-r--r--]win32/include/sys/socket.h0
-rwxr-xr-x[-rw-r--r--]win32/xineplug_dmx_audio.dsp0
-rwxr-xr-x[-rw-r--r--]win32/xineplug_dmx_lpcm.dsp0
-rwxr-xr-x[-rw-r--r--]win32/xineplug_dmx_nsv.dsp0
-rwxr-xr-x[-rw-r--r--]win32/xineplug_dmx_pva.dsp0
-rwxr-xr-x[-rw-r--r--]win32/xineplug_dmx_real.dsp0
-rwxr-xr-x[-rw-r--r--]win32/xineplug_dmx_slave.dsp0
-rwxr-xr-x[-rw-r--r--]win32/xineplug_dmx_yuv4mpeg2.dsp0
-rwxr-xr-x[-rw-r--r--]win32/xineplug_dmx_yuv_frames.dsp0
-rwxr-xr-x[-rw-r--r--]win32/xineplug_inp_cdda.dsp0
-rwxr-xr-x[-rw-r--r--]win32/xineplug_inp_http.dsp0
-rwxr-xr-x[-rw-r--r--]win32/xineplug_inp_net.dsp0
-rwxr-xr-x[-rw-r--r--]win32/xineplug_vo_out_sdl.dsp0
1180 files changed, 326084 insertions, 186460 deletions
diff --git a/.hgignore b/.hgignore
index 32b62ae30..260a4a086 100644
--- a/.hgignore
+++ b/.hgignore
@@ -2,10 +2,17 @@ syntax: glob
*~
*.orig
+xine-lib-*.tar.gz
+xine-lib-*.tar.bz2
+
+*.o
+*.a
*.lo
*.la
-.libs/*
+*.so
+.libs
.deps/*
+.depend
Makefile
Makefile.in
@@ -34,16 +41,24 @@ build-stamp
configure-stamp
debian/files
debian/libxine-dev
-debian/libxine1
-debian/libxine1-dbg
+debian/libxine2
+debian/libxine2-dbg
debian/tmp
debian/*.debhelper
debian/*.substvars
+contrib/ffmpeg/*.pc
+contrib/ffmpeg/config.err
+contrib/ffmpeg/config.mak
+contrib/ffmpeg/doc/*.1
+contrib/ffmpeg/doc/*.html
+contrib/ffmpeg/version.h
+
doc/faq/faq.html
doc/faq/faq.txt
doc/hackersguide/*.png
doc/hackersguide/hackersguide.html
+doc/Doxyfile
include/xine.h
diff --git a/CREDITS b/CREDITS
index 79ba6f052..37aa99872 100644
--- a/CREDITS
+++ b/CREDITS
@@ -17,13 +17,14 @@ goom 2k4-0
gsm610 1.0.10 Mike Melanson
liba52 0.7.4
libcdio 0.71 [o]
-libdts 0.0.2
+libca 0.0.5
libdvdnav 0.1.10 Michael Roitzsch
libfaad cvs-2005-01-30 [GPL] Miguel Freitas
libmad 0.15.1b Miguel Freitas
libmpeg2 0.2.1 [*]
-libmusepack svn 13/01/05 James Stembridge
+libmpcdec 1.2.5
libvcd 0.7.21 [o]
+libxdg-basedir 0.1.3 Diego Pettenò
nosefart 1.92 Mike Melanson
tvtime 0.9.8.4 Miguel Freitas
wine
diff --git a/ChangeLog b/ChangeLog
index 1f439b880..f6785d60d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,32 @@
+xine-lib (1.1.90) (Unreleased)
+ * Add support for VDR.
+ * Reorder and modify public structures to reduce the holes caused by padding
+ especially on 64-bit architectures.
+ * Remove the buttons array from video_overlay, as the feature linked to that
+ was never implemented. This change reduces by 10MB the memory usage of
+ xine-lib during playback (1/3 of the memory used while playing an mp3).
+ * Use FFmpeg's own buildsystem, rather than wrapping automake around its
+ sources; this allows to enable/disable FFmpeg features easily, and allow
+ to properly support --disable-ffmpeg-(uncommon|popular)-codecs.
+ * Update libmpcdec (formerly libmusepack) to version 1.2.5 (newer than the
+ previous Subversion snapshot) and contestually move it to contrib/libmpcdec
+ to separate from xine's own code.
+ * Save plugins' cache in the defined cache home directory as per XDG Base
+ Directory Specification.
+ * Use XDG-defined cache home directory for cddb cache.
+ * Use XDG-defined cache home directory for win32codecs fake registry.
+ * Use XDG-defined data directories to look up fonts files both while using
+ FreeType2 and the standard bitmap fonts for OSD.
+ * Replace internal libdts 0.0.2 with libdca 0.0.5, and contextually move it
+ to contrib/libdca to separate from xine's own code.
+ * Add another message code to allow for auth prompts. Previously, it was
+ not possible to distinguish between 401 Authentication Requried and 403
+ Forbidden.
+ * Merge the demuxer and the decoder for NSF files in a combined plugin.
+ * Move modplug demuxing on its own plugin, this way binary distributions
+ can make it optional, as it requires quite a bit of CPU time during
+ initialisation, even for audio files that nothing have to do with modplug.
+
xine-lib (1.1.7) (unreleased)
* Support libdca (new name for libdts) by shuffling around the dts.h file.
* Add support for MDHD version 1 atom in demux_qt. [bug #1679398]
diff --git a/Makefile.am b/Makefile.am
index 0b8e0e368..548f93312 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2,11 +2,11 @@
## Process this file with automake to produce Makefile.in
##
-AUTOMAKE_OPTIONS = 1.8 no-dist-gzip dist-bzip2
+AUTOMAKE_OPTIONS = 1.9 no-dist-gzip dist-bzip2
ACLOCAL_AMFLAGS = -I m4
-SUBDIRS = doc m4 po misc include lib src win32
+SUBDIRS = doc m4 po misc include lib src win32 contrib
DEBFILES = debian/README.Debian debian/changelog debian/control \
debian/copyright debian/rules debian/compat \
@@ -48,22 +48,8 @@ pass2:
@$(MAKE) MULTIPASS_CFLAGS='$(PASS2_CFLAGS)'
-debug:
- @list='$(SUBDIRS)'; for subdir in $$list; do \
- (cd $$subdir && $(MAKE) $@) || exit;\
- done;
-
-debug-install: install-debug
-
-install-debug: debug
- @list='$(SUBDIRS)'; for subdir in $$list; do \
- (cd $$subdir && $(MAKE) $@) || exit; \
- done;
- $(MAKE) $(AM_MAKEFLAGS) install-data-hook
-
-
prune-cache:
- -rm -f config.cache
+ -rm -rf config.cache autom4te.cache
release-check:
diff --git a/TODO b/TODO
index 61fa0efe7..d7dc45ca8 100644
--- a/TODO
+++ b/TODO
@@ -1,11 +1,32 @@
+For 1.3 series
+==============
+- analyse impact of breaking xine.h down in multiple public headers, and
+ rename the xine/ directory for include files in xinecore/ (for plugins
+ only), while leaving xine/ for public include files;
+
+For 1.2 series
+==============
+- Security-Related: start using xine_xcalloc rather than xine_xmalloc when
+ the number of elements is not a build-time constant.
+- mimetype-based demuxer selection, solves the effects of shoutcast's bug;
+- Doxygen API documentation for both internal and public functions;
+- removal of (deprecated) software deinterlacers from video output plugins;
+- reduction of exported symbols by hiding (-fvisibility=hidden or attribute)
+ the internal libxine-only functions;
+- move the contributed code (not developed by xine project) in the contrib/
+ directory of the source tree;
+- reduce memory footprint (e.g. variable fifo buffer sizes...);
+- handle gracefully the runtime removal of the audio output device (being
+ it a physical removal for USB devices or a missing output on a client-server
+ design like PulseAudio, ESounD or Jack);
+- HTTPS.
+
known bugs
==========
- frame allocation problem with h264 streams using > 15 reference frames
-- our faad2 has problems with 5.1 streams. faad2 cvs is GPL incompatible.
- dvdnav time search function does not use the time table, but interpolates
only cell times
-- crash with RV10 streams
requested/planned features
@@ -50,10 +71,6 @@ optional
- helix streaming server support
- detect broken savage drivers in health check, disable Xv in that case
-- directfb video output plugin
-- reduce memory footprint (e.g. variable fifo buffer sizes...)
-- opengl video output plugin (matthias, sopra at stuttgart university)
-- irix audio output plugin (matthias)
beyond 1.0
----------
diff --git a/autogen.sh b/autogen.sh
index e228f051b..95bce9774 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -27,11 +27,11 @@
PROG=xine-lib
# Minimum value required to build
-WANT_AUTOMAKE_1_8=1 export WANT_AUTOMAKE_1_8
-WANT_AUTOMAKE=1.8 export WANT_AUTOMAKE
-AUTOMAKE_MIN=1.8.0
+export WANT_AUTOMAKE_1_9=1
+export WANT_AUTOMAKE=1.9
+AUTOMAKE_MIN=1.9.0
AUTOCONF_MIN=2.59
-LIBTOOL_MIN=1.4.0
+LIBTOOL_MIN=1.5.20
# Check how echo works in this /bin/sh
case `echo -n` in
@@ -192,7 +192,7 @@ run_automake () {
echo $_echo_n " + Running automake: $_echo_c";
- automake --gnu --add-missing --copy;
+ automake --gnu --add-missing --copy -Wno-portability;
echo "done."
}
@@ -231,7 +231,7 @@ run_aclocal () {
echo $_echo_n " + Running aclocal: $_echo_c"
- aclocal -I m4
+ aclocal -I m4 -I m4/gettext
echo "done."
}
diff --git a/automake.diff b/automake.diff
deleted file mode 100644
index ae16fcd40..000000000
--- a/automake.diff
+++ /dev/null
@@ -1,11 +0,0 @@
---- /usr/bin/automake Sat Mar 11 09:25:33 2000
-+++ automake Thu Sep 7 22:08:33 2000
-@@ -187,7 +187,7 @@ $seen_libtool = 0;
- $libtool_line = 0;
-
- # Files installed by libtoolize.
--@libtoolize_files = ('ltconfig', 'ltmain.sh', 'config.guess', 'config.sub');
-+@libtoolize_files = ('ltmain.sh', 'config.guess', 'config.sub');
-
- # TRUE if we've seen AM_MAINTAINER_MODE.
- $seen_maint_mode = 0;
diff --git a/config.rpath b/config.rpath
index 3f1bef34a..c492a93b6 100755
--- a/config.rpath
+++ b/config.rpath
@@ -2,7 +2,7 @@
# Output a system dependent set of variables, describing how to set the
# run time search path of shared libraries in an executable.
#
-# Copyright 1996-2005 Free Software Foundation, Inc.
+# Copyright 1996-2006 Free Software Foundation, Inc.
# Taken from GNU libtool, 2001
# Originally by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
#
@@ -25,7 +25,7 @@
# known workaround is to choose shorter directory names for the build
# directory and/or the installation directory.
-# All known linkers require a `.a' archive for static linking (except M$VC,
+# All known linkers require a `.a' archive for static linking (except MSVC,
# which needs '.lib').
libext=a
shrext=.so
@@ -35,7 +35,17 @@ host_cpu=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
host_vendor=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
host_os=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
-cc_basename=`echo "$CC" | sed -e 's%^.*/%%'`
+# Code taken from libtool.m4's _LT_CC_BASENAME.
+
+for cc_temp in $CC""; do
+ case $cc_temp in
+ compile | *[\\/]compile | ccache | *[\\/]ccache ) ;;
+ distcc | *[\\/]distcc | purify | *[\\/]purify ) ;;
+ \-*) ;;
+ *) break;;
+ esac
+done
+cc_basename=`echo "$cc_temp" | sed -e 's%^.*/%%'`
# Code taken from libtool.m4's AC_LIBTOOL_PROG_COMPILER_PIC.
@@ -48,7 +58,7 @@ else
wl='-Wl,'
;;
darwin*)
- case "$cc_basename" in
+ case $cc_basename in
xlc*)
wl='-Wl,'
;;
@@ -78,6 +88,13 @@ else
como)
wl='-lopt='
;;
+ *)
+ case `$CC -V 2>&1 | sed 5q` in
+ *Sun\ C*)
+ wl='-Wl,'
+ ;;
+ esac
+ ;;
esac
;;
osf3* | osf4* | osf5*)
@@ -120,6 +137,10 @@ case "$host_os" in
with_gnu_ld=no
fi
;;
+ interix*)
+ # we just hope/assume this is gcc and not c89 (= MSVC++)
+ with_gnu_ld=yes
+ ;;
openbsd*)
with_gnu_ld=no
;;
@@ -127,6 +148,12 @@ esac
ld_shlibs=yes
if test "$with_gnu_ld" = yes; then
+ # Set some defaults for GNU ld with shared library support. These
+ # are reset later if shared libraries are not supported. Putting them
+ # here allows them to be overridden if necessary.
+ # Unlike libtool, we use -rpath here, not --rpath, since the documented
+ # option of GNU ld is called -rpath, not --rpath.
+ hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
case "$host_os" in
aix3* | aix4* | aix5*)
# On AIX/PPC, the GNU linker is very broken
@@ -162,9 +189,20 @@ if test "$with_gnu_ld" = yes; then
ld_shlibs=no
fi
;;
+ interix3*)
+ hardcode_direct=no
+ hardcode_libdir_flag_spec='${wl}-rpath,$libdir'
+ ;;
+ linux*)
+ if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
+ :
+ else
+ ld_shlibs=no
+ fi
+ ;;
netbsd*)
;;
- solaris* | sysv5*)
+ solaris*)
if $LD -v 2>&1 | grep 'BFD 2\.8' > /dev/null; then
ld_shlibs=no
elif $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
@@ -173,16 +211,23 @@ if test "$with_gnu_ld" = yes; then
ld_shlibs=no
fi
;;
+ sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*)
+ case `$LD -v 2>&1` in
+ *\ [01].* | *\ 2.[0-9].* | *\ 2.1[0-5].*)
+ ld_shlibs=no
+ ;;
+ *)
+ if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
+ hardcode_libdir_flag_spec='`test -z "$SCOABSPATH" && echo ${wl}-rpath,$libdir`'
+ else
+ ld_shlibs=no
+ fi
+ ;;
+ esac
+ ;;
sunos4*)
hardcode_direct=yes
;;
- linux*)
- if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
- :
- else
- ld_shlibs=no
- fi
- ;;
*)
if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
:
@@ -191,10 +236,8 @@ if test "$with_gnu_ld" = yes; then
fi
;;
esac
- if test "$ld_shlibs" = yes; then
- # Unlike libtool, we use -rpath here, not --rpath, since the documented
- # option of GNU ld is called -rpath, not --rpath.
- hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+ if test "$ld_shlibs" = no; then
+ hardcode_libdir_flag_spec=
fi
else
case "$host_os" in
@@ -225,6 +268,7 @@ else
break
fi
done
+ ;;
esac
fi
hardcode_direct=yes
@@ -244,6 +288,7 @@ else
hardcode_libdir_flag_spec='-L$libdir'
hardcode_libdir_separator=
fi
+ ;;
esac
fi
# Begin _LT_AC_SYS_LIBPATH_AIX.
@@ -291,7 +336,7 @@ else
if test "$GCC" = yes ; then
:
else
- case "$cc_basename" in
+ case $cc_basename in
xlc*)
;;
*)
@@ -326,24 +371,25 @@ else
# but as the default location of the library.
hardcode_minus_L=yes
;;
- hpux10* | hpux11*)
+ hpux10*)
if test "$with_gnu_ld" = no; then
- case "$host_cpu" in
- hppa*64*)
- hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
- hardcode_libdir_separator=:
- hardcode_direct=no
- ;;
- ia64*)
- hardcode_libdir_flag_spec='-L$libdir'
+ hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
+ hardcode_libdir_separator=:
+ hardcode_direct=yes
+ # hardcode_minus_L: Not really in the search PATH,
+ # but as the default location of the library.
+ hardcode_minus_L=yes
+ fi
+ ;;
+ hpux11*)
+ if test "$with_gnu_ld" = no; then
+ hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
+ hardcode_libdir_separator=:
+ case $host_cpu in
+ hppa*64*|ia64*)
hardcode_direct=no
- # hardcode_minus_L: Not really in the search PATH,
- # but as the default location of the library.
- hardcode_minus_L=yes
;;
*)
- hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
- hardcode_libdir_separator=:
hardcode_direct=yes
# hardcode_minus_L: Not really in the search PATH,
# but as the default location of the library.
@@ -397,8 +443,6 @@ else
fi
hardcode_libdir_separator=:
;;
- sco3.2v5*)
- ;;
solaris*)
hardcode_libdir_flag_spec='-R$libdir'
;;
@@ -427,14 +471,11 @@ else
ld_shlibs=yes
fi
;;
- sysv4.2uw2*)
- hardcode_direct=yes
- hardcode_minus_L=no
- ;;
- sysv5OpenUNIX8* | sysv5UnixWare7* | sysv5uw[78]* | unixware7*)
+ sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[01].[10]* | unixware7*)
;;
- sysv5*)
- hardcode_libdir_flag_spec=
+ sysv5* | sco3.2v5* | sco5v6*)
+ hardcode_libdir_flag_spec='`test -z "$SCOABSPATH" && echo ${wl}-R,$libdir`'
+ hardcode_libdir_separator=':'
;;
uts4*)
hardcode_libdir_flag_spec='-L$libdir'
@@ -471,12 +512,12 @@ case "$host_os" in
;;
kfreebsd*-gnu)
;;
- freebsd*)
+ freebsd* | dragonfly*)
;;
gnu*)
;;
hpux9* | hpux10* | hpux11*)
- case "$host_cpu" in
+ case $host_cpu in
ia64*)
shrext=.so
;;
@@ -488,6 +529,8 @@ case "$host_os" in
;;
esac
;;
+ interix3*)
+ ;;
irix5* | irix6* | nonstopux*)
case "$host_os" in
irix5* | nonstopux*)
@@ -523,16 +566,16 @@ case "$host_os" in
;;
osf3* | osf4* | osf5*)
;;
- sco3.2v5*)
- ;;
solaris*)
;;
sunos4*)
;;
- sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*)
+ sysv4 | sysv4.3*)
;;
sysv4*MP*)
;;
+ sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
+ ;;
uts4*)
;;
esac
diff --git a/configure.ac b/configure.ac
index 389563fba..c7fd6968b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,183 +1,208 @@
-dnl
-dnl Configure.ac for xine
-dnl
+AC_PREREQ(2.59)
+
+m4_include([m4/objc.m4])
-AC_INIT
+dnl Note that autoconf/autoheader/automake cache using autom4te, so version.sh
+dnl will only be run if configure.ac has changed. This must be done before
+dnl AC_INIT so that XINE_VERSION_SPEC, which is an m4 macro, is available.
+m4_esyscmd([./version.sh])
+
+dnl Initialize autoconf, autoheader, and automake
+AC_INIT([xine-lib], XINE_VERSION_SPEC, [xine-bugs@lists.sourceforge.net])
+AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([src/xine-engine/xine.c])
AC_CONFIG_LIBOBJ_DIR([lib])
+AC_CONFIG_HEADERS([config.h])
+AM_MAINTAINER_MODE
-dnl
-dnl Require autoconf version 2.60
-dnl
-AC_PREREQ(2.59)
+AH_TOP([#ifndef __XINE_LIB_CONFIG_H__
+#define __XINE_LIB_CONFIG_H__ 1
+])
+AH_BOTTOM([#ifdef ASMALIGN_1SLN
+# define ASMALIGN(ZEROBITS) ".align " #ZEROBITS "\n\t"
+#else
+# define ASMALIGN(ZEROBITS) ".align 1<<" #ZEROBITS "\n\t"
+#endif
-dnl Making releases:
-dnl XINE_SUB += 1; continue with XINE_LT_* values below
-dnl
-XINE_MAJOR=1
-XINE_MINOR=1
-XINE_SUB=7
+/* include internal system specific header */
+#include "os_internal.h"
-#if test $XINE_SUB -eq 0 ; then
-# XINE_SUBPART="";
-#else
- XINE_SUBPART=".$XINE_SUB"
-#fi
-
-dnl The libtool version numbers (XINE_LT_*); Don't even think about faking this!
-dnl
-dnl immediately before every release do:
-dnl ===================================
-dnl if (the interface is totally unchanged from previous release)
-dnl XINE_LT_REVISION ++;
-dnl else { /* interfaces have been added, removed or changed */
-dnl XINE_LT_REVISION = 0;
-dnl XINE_LT_CURRENT ++;
-dnl if (any interfaces have been _added_ since last release)
-dnl XINE_LT_AGE ++;
-dnl if (any interfaces have been _removed_ or _incompatibly changed_)
-dnl XINE_LT_AGE = 0;
-dnl }
-dnl
-dnl If you want to know more about what you are doing, here are some details:
-dnl * XINE_LT_CURRENT is the current API version
-dnl * XINE_LT_REVISION is an internal revision number which is increased when the API
-dnl itself did not change
-dnl * XINE_LT_AGE is the number of previous API versions still supported by this library
-dnl * libtool has its own numbering scheme, because local library numbering schemes
-dnl are platform dependent
-dnl * in Linux, the library will be named
-dnl libname.so.(XINE_LT_CURRENT - XINE_LT_AGE).XINE_LT_AGE.XINE_LT_REVISION
-
-XINE_LT_CURRENT=18
-XINE_LT_REVISION=0
-XINE_LT_AGE=17
-
-dnl for a release tarball do "rm .cvsversion" before "make dist"
-if test -f "${srcdir-.}/.cvsversion"; then
- XINE_PRE="hg"
-else
- XINE_PRE=""
+#endif /* __XINE_LIB_CONFIG_H__ */
+])
+
+test x"$prefix" = x"NONE" && prefix="${ac_default_prefix}"
+test x"$exec_prefix" = x"NONE" && exec_prefix='${prefix}'
+
+dnl Use features of autoconf 2.61, but stay compatible with older versions.
+if test x"$datarootdir" = x""; then
+ datarootdir='${datadir}'
+ AC_SUBST(datarootdir)
+fi
+
+if test x"$docdir" = x""; then
+ docdir='${datarootdir}/doc/${PACKAGE}'
+ AC_SUBST(docdir)
fi
+if test x"$htmldir" = x""; then
+ htmldir='${docdir}'
+ AC_SUBST(htmldir)
+fi
+
+
+dnl -------------------------
+dnl Setup version information
+dnl -------------------------
+
+dnl Do not change these manually; they come from running ./version.sh when
+dnl autoconf runs. This must all be done after AC_INIT is done, but running
+dnl the version.sh script must be done before AC_INIT.
+XINE_MAJOR=XINE_VERSION_MAJOR
AC_SUBST(XINE_MAJOR)
+AC_DEFINE_UNQUOTED([XINE_MAJOR], [$XINE_MAJOR], [xine major version number])
+XINE_MINOR=XINE_VERSION_MINOR
AC_SUBST(XINE_MINOR)
+AC_DEFINE_UNQUOTED([XINE_MINOR], [$XINE_MINOR], [xine minor version number])
+XINE_SUB=XINE_VERSION_SUB
AC_SUBST(XINE_SUB)
-AC_SUBST(XINE_IFACE_AGE)
-AC_SUBST(XINE_BIN_AGE)
-
-AC_DEFINE_UNQUOTED(XINE_MAJOR, $XINE_MAJOR,[xine major version number])
-AC_DEFINE_UNQUOTED(XINE_MINOR, $XINE_MINOR,[xine minor version number])
-AC_DEFINE_UNQUOTED(XINE_SUB, $XINE_SUB, [xine sub version number])
+AC_DEFINE_UNQUOTED([XINE_SUB], [$XINE_SUB], [xine sub version number])
+XINE_LT_CURRENT=__XINE_LT_CURRENT
AC_SUBST(XINE_LT_CURRENT)
+XINE_LT_REVISION=__XINE_LT_REVISION
AC_SUBST(XINE_LT_REVISION)
+XINE_LT_AGE=__XINE_LT_AGE
AC_SUBST(XINE_LT_AGE)
-SPEC_VERSION=$XINE_MAJOR.$XINE_MINOR${XINE_SUBPART}$XINE_PRE
-TAR_NAME="xine-lib-"$SPEC_VERSION
-dnl TAR_NAME="xine-lib-"$XINE_MAJOR-$XINE_PRE
-dnl SPEC_VERSION=${XINE_MAJOR}_$XINE_PRE
+LIBNAME="libxine${XINE_MAJOR}"
+AC_SUBST(LIBNAME)
+AC_DEFINE_UNQUOTED([XINE_TEXTDOMAIN], "$LIBNAME", [catalog message text domain])
+
+dnl Always set flags to begin with -g so that debug information will be
+dnl included. In release bulids, this can be stripped out later if desired.
+dnl More importantly, it prevents autoconf from initializing the defaults to
+dnl include -O2, which is not desirable in a debug build, and it messes with
+dnl other optimizations that we'll want to be setting ourselves later.
+CFLAGS="-g $CFLAGS"
+CPPFLAGS="-D_REENTRANT -DXINE_COMPILE $CPPFLAGS"
+LDFLAGS="-g $LDFLAGS"
+OBJCFLAGS="-g $OBJCFLAGS"
+
+
+dnl ------------------------------
+dnl Build modes: debug and profile
+dnl ------------------------------
+
+AC_ARG_ENABLE([debug],
+ [AS_HELP_STRING([--enable-debug], [build with debugging code enabled])],
+ [], [enable_debug="no"])
+if test x"$enable_debug" != x"no"; then
+ CPPFLAGS="-DDEBUG $CPPFLAGS"
+else
+ CPPFLAGS="-DNDEBUG $CPPFLAGS"
+fi
+AM_CONDITIONAL([DEBUG_BUILD], [test x"$enable_debug" != x"no"])
-AC_SUBST(TAR_NAME)
-AC_SUBST(SPEC_VERSION)
+AC_ARG_ENABLE([profiling],
+ [AS_HELP_STRING([--enable-profiling], [build with profiling code enabled])],
+ [], [enable_profiling="no"])
+if test x"$enable_profiling" != x"no"; then
+ CFLAGS="-pg $CFLAGS"
+ OBJCFLAGS="-pg $OBJCFLAGS"
+ LDFLAGS="-pg $LDFLAGS"
+fi
+AM_CONDITIONAL([PROFILING_BUILD], [test x"$enable_profiling" != x"no"])
-LIBNAME=libxine$XINE_MAJOR
-AC_SUBST(LIBNAME)
-AC_DEFINE_UNQUOTED(XINE_TEXTDOMAIN, "$LIBNAME", [catalog message text domain])
+dnl --------------
+dnl Build features
+dnl --------------
-dnl
-AM_INIT_AUTOMAKE("xine-lib", $SPEC_VERSION)
-dnl AM_INIT_AUTOMAKE("xine-lib", $XINE_MAJOR-$XINE_PRE)
+AC_ARG_ENABLE([ipv6],
+ [AS_HELP_STRING([--enable-ipv6], [enable use of IPv6])],
+ [if test x"$enableval" != x"no"; then
+ AC_DEFINE([ENABLE_IPV6], 1, [Enable this when IPv6 is requested])
+ fi])
-dnl ---------------------------------------------
-dnl Made possible to build for another arch.
-dnl ---------------------------------------------
+AC_ARG_ENABLE([antialiasing],
+ [AS_HELP_STRING([--enable-antialiasing], [enable font antialiasing])],
+ [if test x"$enableval" != x"no"; then
+ AC_DEFINE([ENABLE_ANTIALIASING], 1, [Define this to 1 to enable font antialising.])
+ fi])
-AC_CANONICAL_HOST
-AC_CANONICAL_BUILD
-test "$host" == "$build" && check_athlon=yes
+dnl ----------------------------------------------
+dnl Cross compilation, Mac OS X Universal Binaries
+dnl ----------------------------------------------
-AC_CONFIG_HEADERS([config.h])
+AC_CANONICAL_BUILD
+AC_CANONICAL_HOST
+dnl check for Mac OS X universal binary support early, because certain flags
+dnl must be set prior to looking for cc/libtool, etc.
+MACOSX_UNIVERSAL_BINARIES
-dnl ---------------------------------------------
-dnl Check for programs.
-dnl ---------------------------------------------
+dnl Check to see if $host is empty. If it is, try $host_alias instead.
+dnl If $host is empty, it's because the user has run ./configure with a host
+dnl parameter unknown to config.sub. This used to be set in xv handling, but
+dnl it's also used in a bunch of other places unrelated to Xwindows support,
+dnl so if X is disabled, other things could go badly.
+host_or_hostalias="$host"
+test x"$host_or_hostalias" = x"" && host_or_hostalias="$host_alias"
-AC_PROG_CC
-AM_PROG_AS
-case "$host_os" in
- *darwin*)
- m4_ifdef([AC_PROG_OBJC],
- [AC_PROG_OBJC],
- [AC_CHECK_TOOL([OBJC], [gcc])
- AC_SUBST([OBJC])
- AC_SUBST([OBJCFLAGS])
- ])
- CPPFLAGS="$CPPFLAGS -DCONFIG_DARWIN"
- ;;
-esac
+dnl -------------------
+dnl checks for programs
+dnl -------------------
+AC_PROG_CC
AC_GNU_SOURCE
-dnl Save CFLAGS, AC_ISC_POSIX set some unwanted default CFLAGS
-saved_CFLAGS="$CFLAGS"
AC_ISC_POSIX
-AC_PATH_MAGIC
-CFLAGS="$saved_CFLAGS"
-AC_HEADER_STDC
+
+AC_PROG_OBJC
+
+CC_PROG_AS
AC_PROG_MAKE_SET
AC_PROG_EGREP
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_AWK
-AC_C_INLINE
AC_CHECK_TOOL([STRINGS], [strings], [false])
-dnl ---------------------------------------------
-dnl Libtool
-dnl ---------------------------------------------
+PKG_PROG_PKG_CONFIG
+
+dnl Check for documentation formatting tools
+AC_CHECK_PROG([SGMLTOOLS], [sgmltools], [sgmltools], [no])
+AM_CONDITIONAL([HAVE_SGMLTOOLS], [test x"$SGMLTOOLS" != x"no"])
+
+AC_CHECK_PROG([FIG2DEV], [fig2dev], [fig2dev], [no])
+AM_CONDITIONAL([HAVE_FIG2DEV], [test x"$FIG2DEV" != x"no"])
+
+dnl libtool
m4_undefine([AC_PROG_F77])
m4_defun([AC_PROG_F77],[])
-AC_LIBTOOL_DLOPEN
AC_DISABLE_STATIC
+AC_LIBTOOL_DLOPEN
AC_LIBTOOL_WIN32_DLL
+AC_PATH_MAGIC
AC_PROG_LIBTOOL
AC_PROG_LIBTOOL_SANITYCHECK
-AC_SUBST(LIBTOOL_DEPS)
-if ${CONFIG_SHELL} ./libtool --features | grep "enable static" >/dev/null; then
- STATIC="-static"
-else
- STATIC=
-fi
-AC_SUBST(STATIC)
-dnl ---------------------------------------------
-dnl Requirements for macros whose first invocations are conditional
-dnl ---------------------------------------------
-
-PKG_PROG_PKG_CONFIG
-CC_CHECK_WERROR
+dnl --------------------
+dnl checks for libraries
+dnl --------------------
-dnl ---------------------------------------------
-dnl NLS Support
-dnl ---------------------------------------------
-
-dnl ALL_LINGUAS="cs da de el en@quot en@boldquot es et fr gl id it ja ko nl nn no pl pt pt_BR ru sl sv tr zh"
AM_ICONV
AC_ARG_ENABLE([iconvtest],
- AS_HELP_STRING([--disable-iconvtest], [don't require iconv library]))
-if test "x$enable_iconvtest" != xno; then
- if test "x$am_cv_func_iconv" != xyes; then
- AC_MSG_ERROR([
+ [AS_HELP_STRING([--disable-iconvtest], [don't require iconv library])])
+if test x"$enable_iconvtest" != x"no"; then
+ if test x"$am_cv_func_iconv" != x"yes"; then
+ AC_MSG_ERROR([
****************************************************************
* iconv library not found. It's necessary for proper *
* manipulation with texts so xine requires it as default. *
@@ -186,2185 +211,768 @@ if test "x$enable_iconvtest" != xno; then
* by option --with-libiconv-prefix. *
* *
* If you don't want iconv support use the option *
-* --disable-iconvtest. *
+* --disable-iconvtest. *
****************************************************************
- ])
- fi
-fi
-
-AM_GNU_GETTEXT([external])
-AC_PROG_GMSGFMT_PLURAL
-
-AC_CHECK_FUNCS([nl_langinfo])
-
-dnl ---------------------------------------------
-dnl Checks for typedefs, structures, and compiler characteristics.
-dnl ---------------------------------------------
-
-AC_C_BIGENDIAN
-AC_C_CONST
-dnl AC_C_ALWAYS_INLINE removal allows ffmpeg to be more widely buildable
-AC_TYPE_OFF_T
-AC_TYPE_SIZE_T
-AC_CHECK_SIZEOF(long)
-dnl AC_CHECK_TYPES([ptrdiff_t])
-dnl For systems without inttypes.h would be needed extend generated replacement.
-AC_CHECK_GENERATE_INTTYPES([include])
-AM_CONDITIONAL(GENERATED_INTTYPES_H, test "x$ac_cv_header_inttypes_h" != x"yes")
-AC_CHECK_TYPE(ssize_t, :, AC_DEFINE(ssize_t, __int64, [define ssize_t to __int64 if it's missing in default includes]))
-
-dnl ---------------------------------------------
-dnl threads and OS specific stuff
-dnl ---------------------------------------------
-
-CC_PTHREAD_FLAGS(, [AC_MSG_ERROR([Pthread support is needed])])
-
-dnl
-AC_MSG_CHECKING(for recursive mutex support in pthread)
-ac_save_LIBS="$LIBS"
-LIBS="$LIBS $PTHREAD_LIBS"
-
-have_recursive_mutex=no
-AC_COMPILE_IFELSE(AC_LANG_SOURCE([#include <pthread.h>
-
-int main() {
- pthread_mutexattr_t attr;
- pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
- return 0;
-}
- ]),[
- have_recursive_mutex=yes
- ],[
- AC_MSG_ERROR(recursive mutex support is needed - please report)
- ])
-LIBS="$ac_save_LIBS"
-
-AC_MSG_RESULT($have_recursive_mutex)
-
-AC_CHECK_DECL(sysi86,[
- AC_DEFINE(HAVE_SYSI86,1,[Define this if the 'sysi86' function is declared in sys/sysi86.h])
- ],,[
-#include <sys/sysi86.h>
-])
-
-dnl ---------------------------------------------
-dnl Windows ports checks
-dnl ---------------------------------------------
-case "$host" in
- *-*-mingw* | *-*-cygwin*)
- dnl check if we are using the cygwin, mingw or cygwin with mno-cygwin mode
- dnl in which case we are actually dealing with a mingw32 compiler
- case "$host" in
- *-*-mingw32*)
- SYS=mingw32
- ;;
- *-*-cygwin*)
- AC_EGREP_CPP(pattern,
- [#ifdef WIN32
- yes
- #endif],
- SYS=mingw32, SYS=cygwin)
- ;;
- esac
-
- if test "$SYS" = "mingw32"; then
- WIN32_CPPFLAGS='-I$(top_srcdir)/win32/include'
- LIBS="-lwinmm -lwsock32 $LIBS"
- GOOM_LIBS="-liberty"
- fi
- LDFLAGS="-no-undefined $LDFLAGS"
- ;;
-esac
-AC_SUBST(GOOM_LIBS)
-AC_SUBST(WIN32_CPPFLAGS)
-AM_CONDITIONAL(WIN32, test "x$SYS" = "xmingw32")
-
-
-dnl ---------------------------------------------
-dnl dynamic linker
-dnl ---------------------------------------------
-AM_DL()
-
-
-dnl ---------------------------------------------
-dnl determine libdir name
-dnl ---------------------------------------------
-
-AC_MSG_CHECKING([libdir name])
-case $host in
-*-*-linux*)
- # Test if the compiler is 64bit
- echo 'int i;' > conftest.$ac_ext
- xine_cv_cc_64bit_output=no
- if AC_TRY_EVAL(ac_compile); then
- case `"$MAGIC_CMD" conftest.$ac_objext` in
- *"ELF 64"*)
- xine_cv_cc_64bit_output=yes
- ;;
- esac
- fi
- rm -rf conftest*
- ;;
-esac
-
-case $host_cpu:$xine_cv_cc_64bit_output in
-powerpc64:yes | s390x:yes | sparc64:yes | x86_64:yes)
- XINE_LIBNAME="lib64"
- ;;
-*:*)
- XINE_LIBNAME="lib"
- ;;
-esac
-AC_MSG_RESULT([$XINE_LIBNAME])
-
-
-dnl ---------------------------------------------
-dnl mpeg2lib and ffmpeg stuff
-dnl ---------------------------------------------
-
-AC_SUBST(LIBMPEG2_CFLAGS)
-
-AC_ARG_WITH([external-ffmpeg], AS_HELP_STRING([--with-external-ffmpeg], [use external ffmpeg library]))
-
-case "x$with_external_ffmpeg" in
- xyes)
- PKG_CHECK_MODULES([FFMPEG], [libavcodec >= 51.20.0])
- ;;
- xsoft)
- with_external_ffmpeg=yes
- PKG_CHECK_MODULES([FFMPEG], [libavcodec >= 51.20.0], [],
- [AC_MSG_RESULT(no); with_external_ffmpeg=no])
- ;;
-esac
-if test "x$with_external_ffmpeg" = "xyes"; then
- PKG_CHECK_MODULES([FFMPEG_POSTPROC], [libpostproc])
- AC_SUBST([FFMPEG_CFLAGS])
- AC_SUBST([FFMPEG_LIBS])
- AC_SUBST([FFMPEG_POSTPROC_CFLAGS])
- AC_SUBST([FFMPEG_POSTPROC_LIBS])
- AC_DEFINE([HAVE_FFMPEG], [1], [Define this if you have ffmpeg library])
-
- AC_MSG_NOTICE([
-*********************************************************************
-xine is configured with external ffmpeg.
-
-This requires the same version of ffmpeg what is included in xine and
-you should know what you do. If some problems occur, please try to
-use internal ffmpeg.
-*********************************************************************])
-else
- AC_MSG_RESULT([using included ffmpeg])
- LIBFFMPEG_CPPFLAGS="-DHAVE_AV_CONFIG_H -DRUNTIME_CPUDETECT -DXINE_MPEG_ENCODER -D_ISOC9X_SOURCE -DCONFIG_DECODERS"
- AC_CHECK_TYPES(int_fast8_t, [], [LIBFFMPEG_CPPFLAGS="$LIBFFMPEG_CPPFLAGS -DEMULATE_FAST_INT"])
- AC_SUBST([LIBFFMPEG_CPPFLAGS])
-fi
-AM_CONDITIONAL(HAVE_FFMPEG, test "x$with_external_ffmpeg" = "xyes")
-
-
-AC_ARG_ENABLE([ffmpeg_uncommon_codecs],
- AS_HELP_STRING([--disable-ffmpeg-uncommon-codecs], [don't build uncommon ffmpeg codecs]))
-
-AC_ARG_ENABLE([ffmpeg_popular_codecs],
- AS_HELP_STRING([--disable-ffmpeg-popular-codecs], [don't build popular ffmpeg codecs]))
-
-AS_MKDIR_P(src/libffmpeg)
-ffmpeg_config_h=src/libffmpeg/ffmpeg_config.h
-echo "/* Automatically generated */" > $ffmpeg_config_h
-
-dnl uncommon ffmpeg codecs
-ffmpeg_uncommon_codecs="AASC ASV1 ASV2 AVS CSCD CYUV DVVIDEO EIGHTBPS FLIC FLV FOURXM FRAPS HUFFYUV IDCIN INTERPLAY_VIDEO KMVC LOCO MMVIDEO NUV QDRAW QPEG ROQ RPZA SMACKER SMC SNOW TRUEMOTION1 TRUEMOTION2 TSCC ULTI VCR1 VMDVIDEO WNV1 XAN_WC3 XL ZMBV ALAC AMR_NB AMR_WB LIBGSM MACE3 MACE6 SHORTEN SMACKAUD TRUESPEECH TTA VMDAUDIO PCM_ALAW PCM_MULAW PCM_S8 PCM_S16BE PCM_S16LE PCM_S24BE PCM_S24DAUD PCM_S24LE PCM_S32BE PCM_S32LE PCM_U8 PCM_U16BE PCM_U16LE PCM_U24BE PCM_U24LE PCM_U32BE PCM_U32LE INTERPLAY_DPCM ROQ_DPCM SOL_DPCM VQA XAN_DPCM ADPCM_4XM ADPCM_CT ADPCM_EA ADPCM_IMA_DK3 ADPCM_IMA_DK4 ADPCM_IMA_QT ADPCM_IMA_SMJPEG ADPCM_IMA_WAV ADPCM_IMA_WS ADPCM_MS ADPCM_SBPRO_2 ADPCM_SBPRO_3 ADPCM_SBPRO_4 ADPCM_XA ADPCM_YAMAHA"
-for ucname in $ffmpeg_uncommon_codecs; do
- config_name="CONFIG_${ucname}_DECODER"
- enabled_name="ENABLE_${ucname}_DECODER"
-
- if test "x$enable_ffmpeg_uncommon_codecs" != xno; then
- echo "#define $config_name 1" >> $ffmpeg_config_h
- echo "#define $enabled_name 1" >> $ffmpeg_config_h
- else
- echo "#define $enabled_name 0" >> $ffmpeg_config_h
- fi
-done
-
-dnl popular ffmpeg codecs
-ffmpeg_popular_codecs="CINEPAK FLASHSV H261 H263 H263I H264 INDEO2 INDEO3 MJPEG MJPEGB MPEG1VIDEO MPEG2VIDEO MPEG4 MPEGVIDEO MSMPEG4V1 MSMPEG4V2 MSMPEG4V3 MSRLE MSVIDEO1 QTRLE RV10 RV20 SVQ1 SVQ3 VC1 VP3 VP5 VP6 VP6F WMV1 WMV2 WMV3 COOK DTS FLAC MP2 MP3 QDM2 RA_144 RA_288 WAVPACK WMAV1 WMAV2 ADPCM_SWF"
-
-for ucname in $ffmpeg_popular_codecs; do
- config_name="CONFIG_${ucname}_DECODER"
- enabled_name="ENABLE_${ucname}_DECODER"
-
- if test "x$enable_ffmpeg_popular_codecs" != xno; then
- echo "#define $config_name 1" >> $ffmpeg_config_h
- echo "#define $enabled_name 1" >> $ffmpeg_config_h
- else
- echo "#define $enabled_name 0" >> $ffmpeg_config_h
- fi
-done
-
-dnl disabled ffmpeg codecs
-ffmpeg_disabled_codecs="BMP CAVS CLJR DSICINVIDEO FFV1 FFVHUFF GIF MDEC MPEG_XVMC MSZH PNG RAWVIDEO SP5X TARGA TIERTEXSEQVIDEO TIFF VMNC ZLIB DSICINAUDIO IMC MP3ADU MP3ON4 MPC7 SONIC WS_SND1 ADPCM_ADX ADPCM_G726 DVBSUB DVDSUB THEORA AAC MPEG4AAC AC3 VORBIS"
-for ucname in $ffmpeg_disabled_codecs; do
- config_name="CONFIG_${ucname}_DECODER"
- enabled_name="ENABLE_${ucname}_DECODER"
-
- echo "#define $enabled_name 0" >> $ffmpeg_config_h
-done
-
-dnl disabled ffmpeg encoders
-ffmpeg_extra_encoders="H263P JPEGLS LJPEG PAM PBM PGM PGMYUV PPM SONIC_LS"
-for ucname in $ffmpeg_uncommon_codecs $ffmpeg_popular_codecs $ffmpeg_disabled_codecs $ffmpeg_extra_encoders; do
- config_name="CONFIG_${ucname}_ENCODER"
- enabled_name="ENABLE_${ucname}_ENCODER"
-
- echo "#define $enabled_name 0" >> $ffmpeg_config_h
-done
-
-dnl disabled parsers
-ffmpeg_parsers="AAC AC3 CAVSVIDEO DVBSUB DVDSUB H261 H263 H264 MJPEG MPEG4VIDEO MPEGAUDIO MPEGVIDEO PNM"
-for ucname in $ffmpeg_parsers; do
- config_name="CONFIG_${ucname}_PARSER"
- enabled_name="ENABLE_${ucname}_PARSER"
-
- echo "#define $enabled_name 0" >> $ffmpeg_config_h
-done
-
-LIBMPEG2_CFLAGS=""
-
-AC_CHECK_DECL(lrintf,[
- AC_DEFINE(HAVE_LRINTF,1,[Define this if the 'lrintf' function is declared in math.h])
- AC_DEFINE(_ISOC9X_SOURCE,1,[Define this if you are ISO C9X compliant])
- ],,[
-#define _ISOC9X_SOURCE
-#include <math.h>
])
-AC_CHECK_DECL(rintf,[
- AC_DEFINE(HAVE_RINTF,1,[Define this if the 'rintf' function is declared in math.h])
- ],,[
-#include <math.h>
-])
-
-AC_CHECK_FUNCS(memalign)
-
-AC_ARG_ENABLE([altivec],
- AS_HELP_STRING([--disable-altivec], [do not use assembly codes for Motorola 74xx CPUs]))
-
-AC_ARG_ENABLE([vis],
- AS_HELP_STRING([--disable-vis], [do not use assembly codes for Sun UltraSPARC CPUs]))
-
-AC_ARG_ENABLE([mlib],
- AS_HELP_STRING([--disable-mlib], [do not build Sun mediaLib support]))
-
-AC_ARG_ENABLE([mlib-lazyload],
- AS_HELP_STRING([--enable-mlib-lazyload], [check for Sun mediaLib at runtime]))
-
-if test "x$enable_mlib" != xno; then
- if test "x$MLIBHOME" = x; then
- mlibhome=/opt/SUNWmlib
- else
- mlibhome="$MLIBHOME"
fi
-
- AC_CHECK_LIB(mlib, mlib_VideoAddBlock_U8_S16,
- [ saved_CPPFLAGS="$CPPFLAGS"
- CPPFLAGS="$CPPFLAGS -I$mlibhome/include"
- AC_CHECK_HEADER(mlib_video.h,
- [ if test "x$enable_mlib_lazyload" = xyes; then
- if test "$GCC" = yes; then
- MLIB_LIBS="-L$mlibhome/lib -Wl,-z,lazyload,-lmlib,-z,nolazyload"
- else
- MLIB_LIBS="-L$mlibhome/lib -z lazyload -lmlib -z nolazyload"
- fi
- AC_DEFINE(MLIB_LAZYLOAD,1,[Define this if you want to load mlib lazily])
- else
- MLIB_LIBS="-L$mlibhome/lib -lmlib"
- fi
- MLIB_CFLAGS="-I$mlibhome/include"
- LIBMPEG2_CFLAGS="$LIBMPEG2_CFLAGS $MLIB_CFLAGS"
- LIBFFMPEG_CFLAGS="$LIBFFMPEG_CFLAGS $MLIB_CFLAGS"
- AC_DEFINE(HAVE_MLIB,1,[Define this if you have mlib installed])
- AC_DEFINE(LIBMPEG2_MLIB,1,[Define this if you have mlib installed])
- ac_have_mlib=yes
- ],)
- CPPFLAGS="$saved_CPPFLAGS"
- ], , -L$mlibhome/lib)
fi
-AM_CONDITIONAL(HAVE_MLIB, test "x$ac_have_mlib" = "xyes")
-AC_SUBST(MLIB_LIBS)
-AC_SUBST(MLIB_CFLAGS)
-dnl ---------------------------------------------
-dnl Checks for X11
-dnl ---------------------------------------------
+AM_GNU_GETTEXT([external])
+AC_PROG_GMSGFMT_PLURAL
-if test "x$with_x" != "xno"; then
- PKG_CHECK_MODULES([X], [x11 xext], , [
- AC_PATH_XTRA
-
- dnl Set xv_path if its not done already
- dnl we do it here before rewriting X_LIBS
- if test x$xv_path = x; then
- xv_path=`echo $X_LIBS | sed -e 's/\-L\(.*\)/\1/'`
- fi
-
- dnl ----------------------------------------------
- dnl Check for XShm support (required with X)
- dnl ----------------------------------------------
-
- if test "x$no_x" != "xyes"; then
- ac_save_CPPFLAGS="$CPPFLAGS"
- CPPFLAGS="$CPPFLAGS $X_CFLAGS"
- AC_CHECK_HEADERS([X11/extensions/XShm.h], [true],
- [AC_MSG_ERROR([XShm extension is required])])
- AC_CHECK_LIB([Xext], [main], [true],
- [AC_MSG_ERROR([libXext is required])], [$X_LIBS])
- CPPFLAGS="$ac_save_CPPFLAGS"
- X_LIBS="$X_LIBS $X_PRE_LIBS -lX11 -lXext"
- fi
- ])
+AC_CHECK_LIB([c], [dlopen], [DYNAMIC_LD_LIBS=""],
+ [AC_CHECK_LIB([dl], [dlopen], [DYNAMIC_LD_LIBS="-ldl"],
+ [AC_MSG_CHECKING(for dlopen under win32)
+ AC_LANG_PUSH([C])
+ ac_save_CPPFLAGS="$CPPFLAGS" CPPFLAGS="-I${srcdir}/win32/include $CPPFLAGS"
+ ac_save_LIBS="$LIBS" LIBS="$LIBS -lkernel32"
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stddef.h>
+ #include <dlfcn.h>]], [[dlopen(NULL, 0)]])],
+ [DYNAMIC_LD_LIBS="-lkernel32"
+ AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])])
+ CPPFLAGS="$ac_save_CPPFLAGS" LIBS="$ac_save_LIBS"
+ AC_LANG_POP([C])], [AC_MSG_ERROR([dynamic linker needed])])])
+AC_SUBST([DYNAMIC_LD_LIBS])
+
+AC_ARG_WITH([external-libxdg-basedir],
+ [AS_HELP_STRING([--with-external-libxdg-basedir], [use external copy of libxdg-basedir])])
+
+if test x"$with_external_libxdg_basedir" = x"yes"; then
+ PKG_CHECK_MODULES([XDG_BASEDIR], [libxdg-basedir >= 0.1.3])
else
- no_x="yes"
+ XDG_BASEDIR_CPPFLAGS='-I$(top_srcdir)/contrib/libxdg-basedir'
+ XDG_BASEDIR_LIBS='$(top_builddir)/contrib/libxdg-basedir/libxdg-basedir.la'
+ XDG_BASEDIR_DEPS='$(top_builddir)/contrib/libxdg-basedir/libxdg-basedir.la'
fi
-if test "x$no_x" != "xyes"; then
- AC_DEFINE(HAVE_X11,1,[Define this if you have X11R6 installed])
-fi
-AM_CONDITIONAL(HAVE_X11, [test "x$no_x" != "xyes"])
+AC_SUBST([XDG_BASEDIR_CPPFLAGS])
+AC_SUBST([XDG_BASEDIR_LIBS])
+AC_SUBST([XDG_BASEDIR_DEPS])
-
-dnl ---------------------------------------------
-dnl Locate libraries needed for X health check
-dnl ---------------------------------------------
-
-soname_script="/[[0-9]]$/! d; s%^.*/%%
-t q
-b
-:q
-q"
-x_lib_location="`ls -1 "${x_libraries:-/usr/local/lib}/libX11.so"* "${x_libraries:-/usr/lib}/libX11.so"* 2>/dev/null | sed -e \"${soname_script}\"`"
-AC_DEFINE_UNQUOTED([LIBX11_SO], "${x_lib_location:-libX11.so}", [The soname of libX11, needed for dlopen()])
-x_lib_location="`ls -1 "${x_libraries:-/usr/local/lib}/libXv.so"* "${x_libraries:-/usr/lib}/libXv.so"* 2>/dev/null | sed -e \"${soname_script}\"`"
-AC_DEFINE_UNQUOTED([LIBXV_SO], "${x_lib_location:-libXv.so}", [The soname of libXv, needed for dlopen()])
-
-
-dnl ---------------------------------------------
-dnl socket library
-dnl ---------------------------------------------
+AM_CONDITIONAL([EXTERNAL_LIBXDG_BASEDIR], [test x"$with_external_libxdg_basedir" = x"yes"])
dnl Test for socket and network support library
-NET_LIBS=""
-AC_CHECK_LIB(socket, socket, NET_LIBS="-lsocket $NET_LIBS",)
-AC_CHECK_LIB(nsl, gethostbyname, NET_LIBS="-lnsl $NET_LIBS",)
+AC_CHECK_LIB([socket], [socket], [NET_LIBS="-lsocket $NET_LIBS"])
+AC_CHECK_LIB([nsl], [gethostbyname], [NET_LIBS="-lnsl $NET_LIBS"])
+AC_CHECK_LIB([resolv], [hstrerror], [NET_LIBS="-lresolv $NET_LIBS"])
AC_SUBST(NET_LIBS)
-
-dnl ---------------------------------------------
-dnl socklen_t
-dnl ---------------------------------------------
-AC_CHECK_SOCKLEN_T
-
-
-dnl ---------------------------------------------
-dnl IPv6
-dnl ---------------------------------------------
-
-AC_ARG_ENABLE([ipv6],
- AS_HELP_STRING([--enable-ipv6], [enable use of IPv6]))
-
-if test "x$enable_ipv6" = "xyes"; then
- AC_DEFINE([ENABLE_IPV6], [1], [Enable this when IPv6 is requested])
-fi
-
-dnl ---------------------------------------------
-dnl zlib
-dnl ---------------------------------------------
-
-AC_ARG_WITH(zlib-prefix,
- AS_HELP_STRING(
- [--with-zlib-prefix=PREFIX],
- [path to zlib compression library]),
- [zlib_prefix="$withval"],
- [zlib_prefix="no"])
-
-if test "x$zlib_prefix" = "xno"; then
- ZLIB_LIBS="-lz"
-else
- ZLIB_CPPFLAGS="-I$zlib_prefix/include"
- ZLIB_LIBS="-L$zlib_prefix/lib -lz"
-fi
-
-ac_save_CPPFLAGS="$CPPFLAGS"
-ac_save_LIBS="$LIBS"
-CPPFLAGS="$CPPFLAGS $ZLIB_CPPFLAGS"
-LIBS="$LIBS $ZLIB_LIBS"
-
-AC_CHECK_LIB(z, gzsetparams,
- [AC_CHECK_HEADER(zlib.h,
- have_zlib=yes)])
-
-CPPFLAGS="$ac_save_CPPFLAGS"
-LIBS="$ac_save_LIBS"
-
-if test "x$have_zlib" != "xyes"; then
- AC_MSG_ERROR(zlib needed)
-fi
-AC_SUBST(ZLIB_CPPFLAGS)
-AC_SUBST(ZLIB_LIBS)
-
-
-dnl ---------------------------------------------
-dnl check posix timers
-dnl ---------------------------------------------
-
-AC_CHECK_LIB(rt, clock_getres,
+AC_CHECK_LIB([rt], [clock_getres],
[RT_LIBS="-lrt"
- AC_DEFINE(HAVE_POSIX_TIMERS,1,
- [Define this if you have POSIX timers.])],
- AC_MSG_RESULT([*** no POSIX timers available.]))
+ AC_DEFINE(HAVE_POSIX_TIMERS, 1, [Define this if you have POSIX timers.])],
+ [AC_MSG_RESULT([*** no POSIX timers available.])])
AC_SUBST(RT_LIBS)
-dnl ---------------------------------------------
-dnl Check for OpenGL & [GLut | GLU]
-dnl ---------------------------------------------
-
-AM_PATH_OPENGL()
+AC_CHECK_LIB([posix4], [sched_get_priority_min])
+AC_CHECK_LIB([kstat], [kstat_open],
+ [KSTAT_LIBS=-lkstat
+ AC_DEFINE([HAVE_KSTAT], 1, [Define this if you have kernel statistics available via kstat interface])])
+AC_SUBST(KSTAT_LIBS)
-dnl ---------------------------------------------
-dnl Check for platform which supports syncfb
-dnl ---------------------------------------------
-
-AC_ARG_ENABLE([syncfb],
- AS_HELP_STRING([--disable-syncfb], [do not build syncfb plugin]))
+AC_ARG_WITH([zlib-prefix],
+ [AS_HELP_STRING([--with-zlib-prefix=PREFIX], [path to zlib compression library])],
+ [if test x"$withval" != x"no"; then
+ ZLIB_CPPFLAGS="-I$withval/include"
+ ZLIB_LIBS="-L$withval/lib"
+ fi])
+
+AC_CHECK_LIB([z], [gzsetparams],
+ [ZLIB_LIBS="$ZLIB_LIBS -lz"
+ ac_save_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $ZLIB_CPPFLAGS"
+ AC_CHECK_HEADER([zlib.h], [have_zlib=yes], [have_zlib=no])
+ CPPFLAGS="$ac_save_CPPFLAGS"],
+ [have_zlib=no],
+ ["$ZLIB_LIBS"])
+
+test x"$have_zlib" != x"yes" && AC_MSG_ERROR(zlib needed)
+AC_SUBST(ZLIB_CPPFLAGS)
+AC_SUBST(ZLIB_LIBS)
-case "$host_os" in
- *linux*) ;;
- *)
- if test "x$enable_syncfb" = "xyes"; then
- AC_MSG_ERROR([You cannot build SyncFB support on non-Linux systems.])
+dnl FreeType2 (optional; disabled by default)
+AC_ARG_WITH([freetype],
+ [AS_HELP_STRING([--with-freetype], [Build with FreeType2 library])],
+ [], [with_freetype=no])
+if test x"$with_freetype" != x"no"; then
+ PKG_CHECK_MODULES([FT2], [freetype2], [have_freetype=yes], [have_freetype=no])
+ if test x"$have_freetype" = x"no"; then
+ AC_MSG_ERROR([FreeType2 support requested but FreeType2 library not found])
+ elif test x"$have_freetype" = x"yes"; then
+ AC_DEFINE([HAVE_FT2], 1, [Define this if you have freetype2 library])
fi
- enable_syncfb=no ;;
-esac
-
-AM_CONDITIONAL(HAVE_SYNCFB, test "x$enable_syncfb" != "xno")
-
-
-dnl ----------------------------------------------
-dnl Check for usable video-for-linux (v4l) support
-dnl ----------------------------------------------
-AC_ARG_ENABLE([v4l],
- AS_HELP_STRING([--disable-v4l], [do not build Video4Linux input plugin]))
-
-if test "x$enable_v4l" != "xno"; then
- AC_CHECK_HEADERS([linux/videodev.h], [have_v4l=yes], [have_v4l=no])
- AC_CHECK_HEADERS([asm/types.h])
- if test "x$enable_v4l" = "xyes" && test "x$have_v4l" = "xno"; then
- AC_MSG_ERROR([Video4Linux support requested, but prerequisite headers not found.])
- fi
-fi
-
-AM_CONDITIONAL(HAVE_V4L, [test "x$have_v4l" = "xyes"])
-
-dnl ----------------------------------------------
-dnl Check for Xv and XvMC support
-dnl ----------------------------------------------
-
-dnl With recent XFree86 or Xorg, dynamic linking is preferred!
-dnl Only dynamic linking is possible when using libtool < 1.4.0
-
-AC_ARG_WITH(xv-path, AS_HELP_STRING([--with-xv-path=path], [where libXv is installed]),
- xv_path="$withval",)
-
-AC_ARG_ENABLE([static-xv],
- AS_HELP_STRING([--enable-static-xv],[Enable this to force linking against libXv.a]))
-
-if test "x$enable_static_xv" = "xyes"; then
- xv_prefer_shared="no"
-else
- xv_prefer_shared="yes"
-fi
-
-if test "x$no_x" != "xyes"; then
- PKG_CHECK_MODULES([XV], [xv], [
- ac_have_xv="yes"
- AC_DEFINE([HAVE_XV], [1], [Define this if you have libXv installed])
- ], [AC_FIND_LIBXV])
-fi
-AM_CONDITIONAL(HAVE_XV, test "x$ac_have_xv" = "xyes")
-
-
-host_or_hostalias="$host"
-if test "$host_or_hostalias" = ""; then
- dnl user has called ./configure with a host parameter unknown to
- dnl config.sub; the canonical "$host" is empty
- dnl
- dnl Try the following switch with user's original host_alias
- dnl input instead.
- dnl
- host_or_hostalias="$host_alias"
-fi
-
-case "$host_or_hostalias" in
- hppa*)
- if test "x$ac_have_xv_static" = "xyes"; then
- echo "warning: hppa linker - disabling static libXv"
- XV_LIBS="libXv.so"
- fi
- ;;
-
- ppc-*-linux* | powerpc-*)
- ppc_arch="yes"
- ;;
-
- *)
- ;;
-esac
-AM_CONDITIONAL(PPC_ARCH, test "x$ppc_arch" = "xyes")
-
-dnl
-dnl Check if we can enable the xxmc plugin.
-dnl
-
-AC_ARG_ENABLE([xvmc],
- AS_HELP_STRING([--disable-xvmc], [Disable XxMC and XvMC outplut plugins]) )
-
-if test "x$no_x" = "x" && test "x$enable_xvmc" != "xno"; then
-
-AC_ARG_WITH(xxmc-path, AS_HELP_STRING([--with-xxmc-path=path], [where libXvMC libraries for the
- xxmc plugin are installed. Defalts to the default X library path.]),
- xxmc_path="$withval", xxmc_path="$x_libraries")
-AC_ARG_WITH(xxmc-lib, AS_HELP_STRING([--with-xxmc-lib=XXXX], [The name of the XvMC library
- libXXXX.so for the xxmc plugin.]),xxmc_stub="$withval",
- xxmc_stub="XvMCW")
-
-saved_libs="$LIBS"
-saved_CPPFLAGS="$CPPFLAGS"
-if test "x$x_includes" != "x"; then
- CPPFLAGS="$CPPFLAGS -I$x_includes"
-fi
-
-XXMC_LIBS="-L$xxmc_path -l$xxmc_stub"
-AC_MSG_CHECKING(whether to enable the xxmc plugin with vld extensions)
-AC_MSG_RESULT()
-dnl Check if vld "extended" XvMC is available
-if test "x$xxmc_stub" == "xXvMCW" && test "x$ac_have_xv" == "xyes"; then
- AC_CHECK_LIB($xxmc_stub, XvMCPutSlice,
- ac_have_xxmc="yes",
- [ac_have_xxmc="no"
- AC_MSG_RESULT([*** Could not link with -l$xxmc_stub for vld extensions.])],
- [-L$xxmc_path $X_LIBS $X_PRE_LIBS $XV_LIBS -lXext $X_EXTRA_LIBS])
-else
- if test "x$ac_have_xv" = "xyes"; then
- AC_CHECK_LIB($xxmc_stub, XvMCPutSlice,
- [ac_have_xxmc="yes"
- XXMC_LIBS="$XXMC_LIBS -lXvMC"],
- [ac_have_xxmc="no"
- AC_MSG_RESULT([*** Could not link with -l$xxmc_stub -lXvMC for vld extensions.])],
- [-L$xxmc_path -lXvMC $X_LIBS $X_PRE_LIBS $XV_LIBS -lXext $X_EXTRA_LIBS])
- else
- ac_have_xxmc="no",
- fi
-fi
-
-if test "x$ac_have_xxmc" = "xyes"; then
- AC_CHECK_HEADERS(X11/extensions/vldXvMC.h,
- [ac_have_vldxvmc_h="yes"],
- ac_have_vldxvmc="no",)
- if test "x$ac_have_vldxvmc_h" = "xyes"; then
- AC_DEFINE([HAVE_VLDXVMC], [1],
- [Define 1 if you have vldXvMC.h])
- fi
-fi
-dnl Try fallback to standard XvMC if vld failed
-if test "x$ac_have_xxmc" = "xno"; then
- if test "x$xxmc_stub" == "xXvMCW"; then
- AC_CHECK_LIB($xxmc_stub, XvMCCreateContext,
- ac_have_xxmc="yes",
- [ac_have_xxmc="no"
- AC_MSG_RESULT([*** Could not link with -l$xxmc_stub for standard XvMC.])],
- [-L$xxmc_path $X_LIBS $X_PRE_LIBS $XV_LIBS -lXext $X_EXTRA_LIBS])
- else
- if test "x$ac_have_xv" = "xyes"; then
- AC_CHECK_LIB($xxmc_stub, XvMCCreateContext,
- [ac_have_xxmc="yes"
- XXMC_LIBS="$XXMC_LIBS -lXvMC"],
- [ac_have_xxmc="no"
- AC_MSG_RESULT([*** Could not link with -lXvMC for standard XvMC.])],
- [-L$xxmc_path -lXvMC $X_LIBS $X_PRE_LIBS $XV_LIBS -lXext $X_EXTRA_LIBS])
- else
- ac_have_xxmc="no",
- fi
- fi
-fi
-if test "x$ac_have_xxmc" = "xyes"; then
- AC_CHECK_HEADERS(X11/extensions/XvMC.h,,
- ac_have_xxmc="no",)
-fi
-if test "x$ac_have_xxmc" = "xyes"; then
- AC_DEFINE(HAVE_XXMC,1,[Define this to compile the xxmc plugin.])
- if test "x$ac_have_vldxvmc_h" = "xyes"; then
- AC_MSG_RESULT([*** Enabling xxmc plugin with vld extensions.])
- else
- AC_MSG_RESULT([*** Enabling xxmc plugin for standard XvMC *only*.])
- fi
-else
- AC_MSG_RESULT([*** Disabling xxmc plugin due to above errors.])
-fi
-LIBS="$saved_libs"
-fi
-AM_CONDITIONAL(HAVE_VLDXVMC, test "x$ac_have_vldxvmc_h" = "xyes")
-AM_CONDITIONAL(HAVE_XXMC, test "x$ac_have_xxmc" = "xyes")
-AC_SUBST(XXMC_LIBS)
-
-dnl
-dnl Check if we can enable the xvmc plugin.
-dnl
-if test "x$no_x" = "x" && test "x$enable_xvmc" != "xno"; then
-
-AC_ARG_WITH(xvmc-path, AS_HELP_STRING([--with-xvmc-path=path], [where libXvMC libraries for the
- xvmc plugin are installed. Defalts to the default X library path.]),
- xvmc_path="$withval", xvmc_path="$x_libraries")
-AC_ARG_WITH(xvmc-lib, AS_HELP_STRING([--with-xvmc-lib=XXXX], [The name of the XvMC library
- libXXXX.so for the xvmc plugin.]),xvmc_stub="$withval",
- xvmc_stub="XvMCW")
-saved_libs="$LIBS"
-XVMC_LIBS="-L$xvmc_path -l$xvmc_stub"
-AC_MSG_CHECKING(whether to enable the xvmc plugin)
-AC_MSG_RESULT()
-if test "x$xvmc_stub" == "xXvMCW"; then
- AC_CHECK_LIB($xvmc_stub, XvMCCreateContext,
- ac_have_xvmc="yes",
- [ac_have_xvmc="no"
- AC_MSG_RESULT([*** Could not link with -l$xvmc_stub.])],
- [-L$xvmc_path $X_LIBS $X_PRE_LIBS $XV_LIBS -lXext $X_EXTRA_LIBS])
-else
- if test "x$ac_have_xv" = "xyes"; then
- AC_CHECK_LIB($xvmc_stub, XvMCCreateContext,
- [ac_have_xvmc="yes"
- XVMC_LIBS="$XVMC_LIBS -lXvMC"],
- [ac_have_xvmc="no"
- AC_MSG_RESULT([*** Could not link with -lXvMC.])],
- [-L$xvmc_path -lXvMC $X_LIBS $X_PRE_LIBS $XV_LIBS -lXext $X_EXTRA_LIBS])
- else
- ac_have_xvmc="no",
- fi
-fi
-if test "x$ac_have_xvmc" = "xyes"; then
- AC_CHECK_HEADERS(X11/extensions/XvMC.h,,
- ac_have_xvmc="no",)
-fi
-if test "x$ac_have_xvmc" = "xyes"; then
- AC_DEFINE(HAVE_XVMC,1,[Define this if you have an XvMC library and XvMC.h installed.])
- AC_MSG_RESULT([*** Enabling old xvmc plugin.])
-else
- AC_MSG_RESULT([*** Disabling old xvmc plugin due to above errors.])
-fi
-CPPFLAGS="$saved_CPPFLAGS"
-LIBS="$saved_libs"
-fi
-AM_CONDITIONAL(HAVE_XVMC, test "x$ac_have_xvmc" = "xyes")
-AC_SUBST(XVMC_LIBS)
-
-
-dnl ---------------------------------------------
-dnl Check for xcb
-dnl ---------------------------------------------
-AC_ARG_WITH([xcb], AS_HELP_STRING([--without-xcb], [Doesn't build XCB video out plugins]))
-
-if test "x$with_xcb" != "xno"; then
- PKG_CHECK_MODULES([XCB], [xcb-shape >= 1.0], [have_xcb="yes"], [have_xcb="no"])
-fi
-
-AC_SUBST(XCB_CFLAGS)
-AC_SUBST(XCB_LIBS)
-AM_CONDITIONAL(HAVE_XCB, test "x$have_xcb" = "xyes" )
-
-
-dnl ---------------------------------------------
-dnl Check for xcb-shm
-dnl ---------------------------------------------
-
-if test "x$have_xcb" = "xyes"; then
- PKG_CHECK_MODULES([XCBSHM], [xcb-shm], [have_xcbshm="yes"], [have_xcbshm="no"])
-fi
-
-AC_SUBST(XCBSHM_CFLAGS)
-AC_SUBST(XCBSHM_LIBS)
-AM_CONDITIONAL(HAVE_XCBSHM, test "x$have_xcbshm" = "xyes" )
-
-
-dnl ---------------------------------------------
-dnl Check for xcb-xv
-dnl ---------------------------------------------
-
-if test "x$have_xcb" = "xyes"; then
- PKG_CHECK_MODULES([XCBXV], [xcb-xv], [have_xcbxv="yes"], [have_xcbxv="no"])
-fi
-
-AC_SUBST(XCBXV_CFLAGS)
-AC_SUBST(XCBXV_LIBS)
-AM_CONDITIONAL(HAVE_XCBXV, test "x$have_xcbxv" = "xyes" )
-
-
-dnl ---------------------------------------------
-dnl Checks for Xinerama extension
-dnl ---------------------------------------------
-
-AC_ARG_ENABLE([xinerama],
- AS_HELP_STRING([--disable-xinerama], [do not build Xinerama support]))
-
-if test "x$enable_xinerama" != "xno"; then
- PKG_CHECK_MODULES([XINERAMA], [xinerama], [ac_have_xinerama=yes], [
- AC_CHECK_LIB(Xinerama, XineramaQueryExtension,
- [XINERAMA_LIBS="-lXinerama"
- ac_have_xinerama="yes"],,
- [$X_LIBS $X_PRE_LIBS -lXext $X_EXTRA_LIBS])
- ])
- if test "x$ac_have_xinerama" = "xyes"; then
- AC_DEFINE(HAVE_XINERAMA,1,[Define this if you have libXinerama installed])
- X_LIBS="${X_LIBS} ${XINERAMA_LIBS}"
- fi
-else
- ac_have_xinerama=no
-fi
-dnl AM_CONDITIONAL(HAVE_XINERAMA, test "x$ac_have_xinerama" = "xyes")
-
-
-dnl ---------------------------------------------
-dnl Checks for Ascii-Art library
-dnl ---------------------------------------------
-
-AC_ARG_ENABLE([aalib],
- AS_HELP_STRING([--disable-aalib], [do not build AALIB support]),
- [with_aalib=$enableval], [with_aalib=yes])
-
-if test "x$with_aalib" = "xyes"; then
- AM_PATH_AALIB(1.4,, AC_MSG_RESULT([*** All of AALIB dependent parts will be disabled ***]))
-else
- no_aalib=yes
-fi
-
-AM_CONDITIONAL(HAVE_AA, test "x$no_aalib" != "xyes")
-
-dnl ---------------------------------------------
-dnl Checks for Color AsCii Art library
-dnl ---------------------------------------------
-
-AC_ARG_WITH([caca],
- AS_HELP_STRING([--without-caca], [Do not build CACA support]))
-
-if test "x$with_caca" != "xno"; then
- PKG_CHECK_MODULES([CACA], [caca cucul], [have_caca="yes"], [have_caca="no"])
- if test "x$with_caca" = "xyes" && test "x$have_caca" = "xno"; then
- AC_MSG_ERROR([CACA support requested, but libcaca 0.99 not found])
- fi
-fi
-
-AM_CONDITIONAL([HAVE_CACA], [test "x$have_caca" = "xyes"])
-
-dnl ---------------------------------------------
-dnl Check solaris framebuffer device support
-dnl ---------------------------------------------
-
-AC_CHECK_HEADER(sys/fbio.h, ac_have_sunfb=yes,)
-AM_CONDITIONAL(HAVE_SUNFB, [test "x$ac_have_sunfb" = "xyes"])
-
-
-dnl ---------------------------------------------
-dnl Check for Sun DGA
-dnl ---------------------------------------------
-
-saved_LDFLAGS="$LDFLAGS"
-LDFLAGS="$LDFLAGS -L/usr/openwin/lib"
-saved_CPPFLAGS="$CPPFLAGS"
-CPPFLAGS="$CPPFLAGS -I/usr/openwin/include"
-AC_CHECK_LIB(dga, XDgaGrabDrawable, [
- AC_CHECK_HEADER(dga/dga.h, [
- SUNDGA_CFLAGS="-I/usr/openwin/include"
- SUNDGA_LIBS="-L/usr/openwin/lib -R/usr/openwin/lib -ldga"
- ac_have_sundga=yes
- ])
-])
-LDFLAGS="$saved_LDFLAGS"
-CPPFLAGS="$saved_CPPFLAGS"
-AM_CONDITIONAL(HAVE_SUNDGA, [test "x$ac_have_sundga" = "xyes"])
-AC_SUBST(SUNDGA_CFLAGS)
-AC_SUBST(SUNDGA_LIBS)
-
-
-dnl ---------------------------------------------
-dnl Check linux framebuffer device support
-dnl ---------------------------------------------
-
-AC_CHECK_HEADER(linux/fb.h,
- [AC_DEFINE(HAVE_FB,1,[Define this if you have linux framebuffer support])
- have_fb=yes],)
-AC_ARG_ENABLE(fb, AS_HELP_STRING([--disable-fb], [do not build linux framebuffer support]),
- have_fb=$enableval)
-AM_CONDITIONAL(HAVE_FB, [test "x$have_fb" = "xyes"])
-
-
-dnl ---------------------------------------------
-dnl Check whether to build Mac OS X video output driver
-dnl ---------------------------------------------
-
-AC_ARG_ENABLE(macosx_video, AS_HELP_STRING([--enable-macosx-video], [enable support for Mac OS X OpenGL video output]),
- have_macosx_video=$enableval)
-AM_CONDITIONAL(HAVE_MACOSX_VIDEO, [test "x$have_macosx_video" = "xyes"])
-
-
-dnl ---------------------------------------------
-dnl Check whether to build Mac OS X audio output driver
-dnl ---------------------------------------------
-
-AC_ARG_ENABLE(coreaudio, AS_HELP_STRING([--enable-coreaudio], [enable support for Mac OS X Coreaudio output]),
- have_coreaudio=$enableval)
-AM_CONDITIONAL(HAVE_COREAUDIO, [test "x$have_coreaudio" = "xyes"])
-
-
-dnl ---------------------------------------------
-dnl Check for DirectFB
-dnl ---------------------------------------------
-AC_ARG_ENABLE(directfb,
- AS_HELP_STRING([--enable-directfb], [enable use of DirectFB]),
- enable_directfb=$enableval,
- enable_directfb=no)
-
-if test "x$enable_directfb" = "xyes"; then
- PKG_CHECK_MODULES([DIRECTFB], [directfb >= 0.9.22], [have_directfb="yes"], [have_directfb="no"])
-fi
-
-AC_SUBST(DIRECTFB_CFLAGS)
-AC_SUBST(DIRECTFB_LIBS)
-AM_CONDITIONAL(HAVE_DIRECTFB, test "x$have_directfb" = "xyes" )
-
-
-dnl ---------------------------------------------
-dnl check for SDL
-dnl ---------------------------------------------
-
-AC_ARG_WITH([sdl],
- AS_HELP_STRING([--without-sdl], [Build without SDL video output]))
-
-if test "x$with_sdl" != "xno"; then
- PKG_CHECK_MODULES([SDL], [sdl], [have_sdl=yes], [have_sdl=no])
- if test "x$with_sdl" = "xyes" && test "x$have_sdl" = "xno"; then
- AC_MSG_ERROR([SDL support requested, but SDL not found])
- elif test "x$have_sdl" = "xyes"; then
- AC_DEFINE([HAVE_SDL], [1], [Define this if you have SDL installed])
- fi
-fi
-
-AM_CONDITIONAL([HAVE_SDL], [test "x$have_sdl" = "xyes"])
-
-AC_SUBST([SDL_CFLAGS])
-AC_SUBST([SDL_LIBS])
-
-dnl ---------------------------------------------
-dnl check for Libstk
-dnl ---------------------------------------------
-
-AC_ARG_WITH([libstk],
- AS_HELP_STRING([--with-libstk], [Build with STK surface video driver]))
-
-if test "x$with_libstk" = "xyes"; then
- PKG_CHECK_MODULES([LIBSTK], [libstk >= 0.2.0], [have_libstk=yes], [have_libstk=no])
- if test "x$with_libstk" = "xyes" && test "x$have_libstk" = "xno"; then
- AC_MSG_ERROR([libstk support requested, but libstk not found])
- fi
fi
-AM_CONDITIONAL([HAVE_STK], [test "x$have_libstk" = "xyes"])
-
-dnl ---------------------------------------------
-dnl check for pulseaudio
-dnl ---------------------------------------------
-
-AC_ARG_WITH([pulseaudio],
- AS_HELP_STRING([--without-pulseaudio], [Do not build Pulseaudio support]))
-
-if test "x$with_pulseaudio" != "xno"; then
- PKG_CHECK_MODULES([PULSEAUDIO], [libpulse], [have_pulseaudio="yes"], [have_pulseaudio="no"])
-fi
-AM_CONDITIONAL(HAVE_PULSEAUDIO, [test "x$have_pulseaudio" = x"yes"])
-
-dnl ---------------------------------------------
-dnl check for DirectX
-dnl ---------------------------------------------
-
-AM_PATH_DIRECTX()
-
-
-dnl ---------------------------------------------
-dnl dxr3 / hollywood plus card
-dnl ---------------------------------------------
-
-case "$host_or_hostalias" in
- *-linux*)
- AC_CHECK_DXR3()
- if test "x$have_libfame" = "xyes" ; then
- AC_DEFINE_UNQUOTED(HAVE_LIBFAME,1,[Define this if you have libfame mpeg encoder installed (fame.sf.net)])
- AM_PATH_LIBFAME(0.8.10,
- AC_DEFINE(HAVE_NEW_LIBFAME,1,[Define this if you have libfame 0.8.10 or above]))
+dnl fontconfig (optional; disabled by default)
+AC_ARG_WITH([fontconfig],
+ [AS_HELP_STRING([--with-fontconfig], [Build with fontconfig library])],
+ [], [with_fontconfig=no])
+if test x"$with_fontconfig" = x"yes"; then
+ if test x"$have_freetype" != x"yes"; then
+ AC_MSG_ERROR([fontconfig support requested, but FreeType2 not enabled.])
fi
- if test "x$have_librte" = "xyes" ; then
- AC_DEFINE_UNQUOTED(HAVE_LIBRTE,1,[Define this if you have librte mpeg encoder installed (zapping.sf.net)])
+ PKG_CHECK_MODULES([FONTCONFIG], [fontconfig], [have_fontconfig=yes], [have_fontconfig=no])
+ if test x"$have_fontconfig" = x"no"; then
+ AC_MSG_ERROR([fontconfig support requested but fontconfig library not found])
+ elif test x"$have_fontconfig" = x"yes"; then
+ AC_DEFINE([HAVE_FONTCONFIG], 1, [Define this if you have fontconfig library])
fi
- ;;
- *)
- have_dxr3="no"
- have_libfame="no"
- have_librte="no"
- have_encoder="no"
- ;;
-esac
-AM_CONDITIONAL(HAVE_DXR3, test "x$have_dxr3" = "xyes")
-AM_CONDITIONAL(HAVE_LIBFAME, test "x$have_libfame" = "xyes")
-AM_CONDITIONAL(HAVE_LIBRTE, test "x$have_librte" = "xyes")
-
-
-dnl ---------------------------------------------
-dnl Vidix/libdha
-dnl ---------------------------------------------
-
-AC_LINUX_PATH(/usr/src/linux)
-AC_SUBST([LINUX_INCLUDE])
-
-AC_ARG_ENABLE(vidix, AS_HELP_STRING([--disable-vidix], [do not build vidix support]),
- check_vidix=$enableval, check_vidix=yes)
-AC_ARG_ENABLE(dha-kmod, AS_HELP_STRING([--enable-dha-kmod], [build DHA kernel module]),
- enable_dha_kmod=$enableval,enable_dha_kmod=no)
-
-enable_vidix="no"
-
-AC_MSG_CHECKING(for vidix support)
-if test "x$check_vidix" = "xyes" -a "x$ac_cv_prog_AWK" != "xno"; then
- if test "x$no_x" != "xyes" -o "x$have_fb" = "xyes"; then
- case "$host_or_hostalias" in
- i?86-*-linux* | k?-*-linux* | athlon-*-linux*)
- enable_vidix="yes"
- enable_linux="yes"
- ;;
- i?86-*-freebsd* | k?-*-freebsd* | athlon-*-freebsd*)
- enable_vidix="yes"
- enable_dha_kmod="no"
- ;;
- *)
- enable_dha_kmod="no"
- enable_vidix="no"
- ;;
- esac
- fi
fi
-AC_MSG_RESULT($enable_vidix)
-AC_MSG_CHECKING(for DHA linux kernel module build)
-if test "x$enable_dha_kmod" = "xyes"; then
- AC_MSG_RESULT(yes)
-else
- AC_MSG_RESULT(no)
-fi
-AM_CONDITIONAL(HAVE_VIDIX, test "x$enable_vidix" = "xyes")
-AM_CONDITIONAL(HAVE_LINUX, test "x$enable_linux" = "xyes")
-AM_CONDITIONAL(BUILD_DHA_KMOD, test "x$enable_dha_kmod" = "xyes")
-AC_CHECK_PROG(MKNOD, mknod, mknod, no)
-AC_CHECK_PROG(DEPMOD, depmod, depmod, no, "$PATH:/sbin")
+dnl -----------------------
+dnl checks for header files
+dnl -----------------------
+AC_HEADER_STDC
-dnl ---------------------------------------------
-dnl Ogg/Vorbis libs.
-dnl ---------------------------------------------
-
-AC_ARG_WITH([vorbis],
- AS_HELP_STRING([--without-vorbis], [Build without Vorbis audio decoder]))
-
-if test "x$with_vorbis" != "xno"; then
- PKG_CHECK_MODULES([VORBIS], [ogg vorbis], [have_vorbis=yes], [have_vorbis=no])
- if test "x$with_vorbis" = "xyes" && test "x$have_vorbis" = "xno"; then
- AC_MSG_ERROR([Vorbis support requested, but libvorbis not found])
- fi
-fi
-AM_CONDITIONAL([HAVE_VORBIS], [test "x$have_vorbis" = "xyes"])
-
-AC_SUBST([VORBIS_CFLAGS])
-AC_SUBST([VORBIS_LIBS])
-
-dnl ---------------------------------------------
-dnl Ogg/Theora libs.
-dnl ---------------------------------------------
-
-AC_ARG_WITH([theora],
- AS_HELP_STRING([--without-theora], [Build without Theora video decoder]))
-
-if test "x$with_theora" != "xno"; then
- PKG_CHECK_MODULES([THEORA], [ogg theora], [have_theora=yes], [have_theora=no])
- if test "x$with_theora" = "xyes" && test "x$have_theora" = "xno"; then
- AC_MSG_ERROR([Theora support requested, but libtheora not found])
- elif test "x$have_theora" = "xyes"; then
- AC_DEFINE([HAVE_THEORA], [1], [Define this if you have theora])
- fi
-fi
-AM_CONDITIONAL([HAVE_THEORA], [test "x$have_theora" = "xyes"])
-
-AC_SUBST([THEORA_CFLAGS])
-AC_SUBST([THEORA_LIBS])
-
-dnl ---------------------------------------------
-dnl Ogg/Speex libs.
-dnl ---------------------------------------------
-AC_ARG_WITH([speex],
- AS_HELP_STRING([--without-speex], [Build without Speex audio decoder]))
-
-if test "x$with_speex" != "xno"; then
- PKG_CHECK_MODULES([SPEEX], [ogg speex], [have_speex=yes], [have_speex=no])
- if test "x$with_speex" = "xyes" && test "x$have_speex" = "xno"; then
- AC_MSG_ERROR([Speex support requested, but libspeex not found])
- elif test "x$have_speex" = "xyes"; then
- AC_DEFINE([HAVE_SPEEX], [1], [Define this if you have speex])
- fi
-fi
-AM_CONDITIONAL([HAVE_SPEEX], [test "x$have_speex" = "xyes"])
-
-AC_SUBST([SPEEX_CFLAGS])
-AC_SUBST([SPEEX_LIBS])
+AC_CHECK_HEADERS([alloca.h])
+AC_CHECK_HEADERS([assert.h byteswap.h dirent.h errno.h execinfo.h fcntl.h glob.h])
+AC_CHECK_HEADERS([libgen.h malloc.h netdb.h stdbool.h ucontext.h])
+AC_CHECK_HEADERS([sys/ioctl.h sys/mixer.h sys/mman.h sys/param.h sys/times.h sys/wait.h])
-dnl ---------------------------------------------
-dnl check for libFLAC
-dnl ---------------------------------------------
+dnl This is duplicative due to AC_HEADER_STDC, but src/input/vcd stuff needs to
+dnl have HAVE_STDIO_H defined, or it won't compile.
+AC_CHECK_HEADERS([stdio.h])
-AC_ARG_WITH([libflac],
- AS_HELP_STRING([--with-libflac], [build libFLAC-based decoder and demuxer]))
+dnl cdrom ioctls (common for dvdnav and vcd)
+case "$host_os" in
+ linux*)
+ AC_CHECK_HEADERS([linux/cdrom.h],
+ [AC_DEFINE([HAVE_LINUX_CDROM], 1, [Define 1 if you have Linux-type CD-ROM support])
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <linux/cdrom.h>]],
+ [[struct cdrom_generic_command test; int has_timeout = sizeof(test.timeout);]])],
+ [AC_DEFINE([HAVE_LINUX_CDROM_TIMEOUT], [1], [Define 1 if timeout is in cdrom_generic_command struct])])])
+ ;;
+esac
+AC_CHECK_HEADERS([sys/dvdio.h sys/cdio.h sys/scsiio.h])
-have_libflac="no"
-if test "x$with_libflac" = "xyes"; then
- AM_PATH_LIBFLAC([have_libflac="yes"])
-fi
-AM_CONDITIONAL([HAVE_LIBFLAC], [test "x$have_libflac" = "xyes"])
+dnl ----------------
+dnl checks for types
+dnl ----------------
-dnl ---------------------------------------------
-dnl External version of a52dec
-dnl ---------------------------------------------
+AC_TYPE_OFF_T
+AC_TYPE_SIZE_T
+AC_CHECK_SIZEOF([int])
+AC_CHECK_SIZEOF([long])
+AC_CHECK_GENERATE_INTTYPES([include])
+AM_CONDITIONAL([GENERATED_INTTYPES_H], [test "x$ac_cv_header_inttypes_h" != x"yes"])
+AC_CHECK_TYPE([ssize_t], [],
+ [AC_DEFINE([ssize_t], [__int64], [define ssize_t to __int64 if it's missing in default includes])])
+AC_CHECK_SOCKLEN_T
-AC_ARG_ENABLE(a52dec, AS_HELP_STRING([--disable-a52dec], [Disable support for a52dec decoding library (default: enabled)]),
- [enable_a52dec="$enableval"], [enable_a52dec="yes"])
-AC_ARG_WITH(external-a52dec, AS_HELP_STRING([--with-external-a52dec], [use external a52dec library (not recommended)]),
- [external_a52dec="$withval"], [external_a52dec="no"])
-
-have_a52="no"
-
-if test "x$enable_a52dec" = "xno"; then
- AC_MSG_RESULT([a52dec support disabled])
-elif test "x$external_a52dec" = "xyes"; then
- have_a52="yes"
- AC_CHECK_HEADERS([a52dec/a52.h a52dec/a52_internal.h],, have_a52="no",
-[
- #ifdef HAVE_SYS_TYPES_H
- # include <sys/types.h>
- #endif
- #ifdef HAVE_INTTYPES_H
- # include <inttypes.h>
- #endif
- #ifdef HAVE_STDINT_H
- # include <stdint.h>
- #endif
-
- #include <a52dec/a52.h>
+AC_CACHE_CHECK([type of request parameter for ioctl()], [ac_cv_ioctl_request], [
+ for ac_ioctl_request_type in "unsigned long" "int"; do
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/ioctl.h>
+ int ioctl(int fd, $ac_ioctl_request_type request, ...);]], [[]])],
+ [ac_cv_ioctl_request=$ac_ioctl_request_type], [])
+ done
+ if test x"$ac_cv_ioctl_request" = x""; then
+ AC_MSG_ERROR([Unable to determine the type for ioctl() request parameter])
+ fi
])
- SAVE_LIBS="$LIBS"
- AC_CHECK_LIB([a52], [a52_init],, have_a52="no", [-lm])
- LIBS="$SAVE_LIBS"
+AC_DEFINE_UNQUOTED([IOCTL_REQUEST_TYPE], [$ac_cv_ioctl_request], [Type of the request parameter for ioctl()])
- if test "x$have_a52" = "xno"; then
- AC_MSG_RESULT([*** no usable version of a52dec found, using internal copy ***])
- fi
-else
- AC_MSG_RESULT([Use included a52dec support])
-fi
-AM_CONDITIONAL(A52, test "x$enable_a52dec" = "xyes")
-AM_CONDITIONAL(EXTERNAL_A52DEC, test "x$have_a52" = "xyes")
+dnl ---------------------
+dnl checks for structures
+dnl ---------------------
-dnl ---------------------------------------------
-dnl External version of libmad
-dnl ---------------------------------------------
-
-AC_ARG_ENABLE(mad, AS_HELP_STRING([--disable-mad], [Disable support for MAD decoding library (default: enabled)]),
- [enable_libmad="$enableval"], [enable_libmad="yes"])
-AC_ARG_WITH(external-libmad, AS_HELP_STRING([--with-external-libmad], [use external libmad library (not recommended)]),
- [external_libmad="$withval"], [external_libmad="no"])
-
-have_mad="no"
-
-if test "x$enable_libmad" = "xno"; then
- AC_MSG_RESULT([libmad support disabled])
-elif test "x$external_libmad" = "xyes"; then
- PKG_CHECK_MODULES(LIBMAD, [mad], have_mad=yes, have_mad=no)
- AC_CHECK_HEADERS([mad.h])
- AC_SUBST(LIBMAD_LIBS)
- AC_SUBST(LIBMAD_CFLAGS)
- if test "x$have_mad" = "xno"; then
- AC_MSG_RESULT([*** no usable version of libmad found, using internal copy ***])
- fi
-else
- AC_MSG_RESULT([Use included libmad support])
-fi
-
-AM_CONDITIONAL(MAD, test "x$enable_libmad" = "xyes")
-AM_CONDITIONAL(EXTERNAL_LIBMAD, test "x$have_mad" = "xyes")
-
-dnl ---------------------------------------------
-dnl External libmpcdec support
-dnl ---------------------------------------------
-
-AC_ARG_ENABLE([musepack], AS_HELP_STRING([--disable-musepack], [Disable support for MusePack decoding (default: enabled)]))
-AC_ARG_WITH([external-libmpcdec], AS_HELP_STRING([--with-external-libmpcdec], [Use external libmpc library]))
-
-if test "x$enable_musepack" = "xno"; then
- AC_MSG_RESULT([musepack support disabled])
-elif test "x$with_external_libmpcdec" = "xyes"; then
- AC_CHECK_LIB([mpcdec], [mpc_decoder_decode], [have_mpcdec=yes])
- AC_CHECK_HEADERS([mpcdec/mpcdec.h], , [have_mpcdec=no])
- if test "x$have_mpcdec" != "xyes"; then
- AC_MSG_ERROR([Unable to find mpcdec])
- fi
- AC_DEFINE([HAVE_LIBMPC], [1], [Define if external libmpc is used])
-else
- AC_MSG_RESULT([Use included libmusepack])
-fi
-
-AM_CONDITIONAL([MUSEPACK], [test "x$enable_musepack" != "xno"])
-AM_CONDITIONAL([EXTERNAL_MPCDEC], [test "x$have_mpcdec" = "xyes"])
-
-dnl ---------------------------------------------
-dnl MNG libs.
-dnl ---------------------------------------------
-
-AC_ARG_ENABLE([mng],
- AS_HELP_STRING([--disable-mng], [do not build mng support]),
- [with_mng=$enableval], [with_mng=yes])
-
-if test "x$with_mng" = "xyes"; then
- AC_CHECK_LIB(mng, mng_initialize,
- [ AC_CHECK_HEADER(libmng.h,
- [ have_libmng=yes
- MNG_LIBS="-lmng" ],
- AC_MSG_RESULT([*** All libmng dependent parts will be disabled ***]))],
- AC_MSG_RESULT([*** All libmng dependent parts will be disabled ***]))
- AC_SUBST(MNG_LIBS)
-else
- have_libmng=no
-fi
-AM_CONDITIONAL(HAVE_LIBMNG, test "x$have_libmng" = "xyes")
-
-dnl ---------------------------------------------
-dnl MagickWand API of Imagemagick.
-dnl ---------------------------------------------
-
-AC_ARG_WITH([imagemagick],
- AS_HELP_STRING([--without-imagemagick], [Build without ImageMagick image decoder]))
-
-if test "x$with_imagemagick" != "xno"; then
- PKG_CHECK_MODULES([WAND], [Wand], [have_imagemagick=yes], [have_imagemagick=no])
- if test "x$with_imagemagick" = "xyes" && test "x$have_imagemagick" = "xno"; then
- AC_MSG_ERROR([ImageMagick support requested, but Wand not found])
- elif test "x$have_imagemagick" = "xyes"; then
- AC_DEFINE([HAVE_WAND], [1], [Define this if you have ImageMagick installed])
- fi
-fi
-
-AM_CONDITIONAL([HAVE_WAND], [test "x$have_imagemagick" = "xyes"])
-AC_SUBST(WAND_CFLAGS)
-AC_SUBST(WAND_LIBS)
-
-dnl ---------------------------------------------
-dnl freetype2 lib.
-dnl ---------------------------------------------
-AC_ARG_WITH([freetype],
- AS_HELP_STRING([--with-freetype], [Build with FreeType2 library]))
-
-if test "x$with_freetype" = "xyes"; then
- PKG_CHECK_MODULES([FT2], [freetype2], [have_freetype=yes], [have_freetype=no])
- if test "x$have_freetype" = "xno"; then
- AC_MSG_ERROR([FreeType2 support requested but FreeType2 library not found])
- elif test "x$have_freetype" = "xyes"; then
- AC_DEFINE([HAVE_FT2], [1], [Define this if you have freetype2 library])
- fi
-fi
-AC_SUBST([FT2_CFLAGS])
-AC_SUBST([FT2_LIBS])
+AC_CHECK_MEMBER([struct tm.tm_gmtoff],
+ [AC_DEFINE([HAVE_TM_GMTOFF], 1, [Define if struct tm has the tm_gmtoff member.])],
+ [], [#include <time.h>])
-dnl ---------------------------------------------
-dnl fontconfig
-dnl ---------------------------------------------
-AC_ARG_WITH([fontconfig],
- AS_HELP_STRING([--with-fontconfig], [Build with fontconfig library]))
-
-if test "x$with_fontconfig" = "xyes"; then
- if test "x$have_freetype" != "xyes"; then
- AC_MSG_ERROR([fontconfig support requested, but FreeType2 not enabled.])
- fi
-
- PKG_CHECK_MODULES([FONTCONFIG], [fontconfig], [have_fontconfig=yes], [have_fontconfig=no])
- if test "x$have_fontconfig" = "xno"; then
- AC_MSG_ERROR([fontconfig support requested but fontconfig library not found])
- elif test "x$have_fontconfig" = "xyes"; then
- AC_DEFINE([HAVE_FONTCONFIG], [1], [Define this if you have fontconfig library])
- fi
-fi
-AC_SUBST([FONTCONFIG_CFLAGS])
-AC_SUBST([FONTCONFIG_LIBS])
+dnl -----------------------------------
+dnl checks for compiler characteristics
+dnl -----------------------------------
-dnl ---------------------------------------------
-dnl OSS style audio interface
-dnl ---------------------------------------------
-AC_ARG_ENABLE([oss],
- AS_HELP_STRING([--disable-oss], [Do not build OSS audio output support]))
-
-if test "x$enable_oss" != "xno"; then
- AC_CHECK_HEADERS([sys/soundcard.h machine/soundcard.h soundcard.h], [break])
- AC_CHECK_DECL([SNDCTL_DSP_SETFRAGMENT], [have_ossaudio=yes], [], [
- #ifdef HAVE_SYS_SOUNDCARD_H
- # include <sys/soundcard.h>
- #endif
- #ifdef HAVE_MACHINE_SOUNDCARD_H
- # include <sys/soundcard.h>
- #endif
- #ifdef HAVE_SOUNDCARD_H
- # include <soundcard.h>
- #endif
- ])
-
- AC_IOCTL_REQUEST
+if test x"$GCC" = x"yes"; then
+ GCC_VERSION="`"$CC" -dumpversion`"
+ GCC_VERSION_MAJOR="`echo "$GCC_VERSION" | cut -d '.' -f1`"
+ GCC_VERSION_MINOR="`echo "$GCC_VERSION" | cut -d '.' -f2`"
+ GCC_VERSION_PATCHLEVEL="`echo "$GCC_VERSION" | cut -d '.' -f3`"
fi
-AM_CONDITIONAL(HAVE_OSS, test "x$have_ossaudio" = "xyes")
-
-
-dnl ---------------------------------------------
-dnl Alsa support
-dnl ---------------------------------------------
-
-AC_ARG_WITH([alsa],
- AS_HELP_STRING([--without-alsa], [Build without ALSA audio output]))
-
-if test "x$with_alsa" != "xno"; then
- PKG_CHECK_MODULES([ALSA], [alsa >= 0.9.0], [have_alsa=yes], [have_alsa=no])
- AC_SUBST([ALSA_LIBS])
- AC_SUBST([ALSA_CFLAGS])
- if test "x$have_alsa" = "xyes"; then
- AC_DEFINE([HAVE_ALSA], [1], [Define this if you have ALSA installed])
- elif test "x$with_alsa" = "xyes"; then
- AC_MSG_ERROR([ALSA support requested but not found.])
- fi
-fi
-
-AM_CONDITIONAL([HAVE_ALSA], [test "x$have_alsa" = "xyes"])
-
-dnl ---------------------------------------------
-dnl ESD support
-dnl ---------------------------------------------
+CC_CHECK_WERROR
-AC_ARG_WITH([esound],
- AS_HELP_STRING([--without-esound], [Build without ESounD audio output]))
+CC_PTHREAD_FLAGS([], [AC_MSG_ERROR([Pthread support is needed])])
+CC_PTHREAD_RECURSIVE_MUTEX([], [AC_MSG_ERROR([recursive mutex support is needed - please report])])
-if test "x$with_esound" != "xno"; then
- PKG_CHECK_MODULES([ESD], [esound], [have_esound=yes], [have_esound=no])
- if test "x$with_esound" = "xyes" && test "x$have_esound" = "xno"; then
- AC_MSG_ERROR([ESounD support requested, but libesd not found])
- elif test "x$have_esound" = "xyes"; then
- AC_DEFINE([HAVE_ESD], [1], [Define this if you have ESounD installed])
- fi
-fi
+dnl REVISIT: AC_C_ALWAYS_INLINE removal allows ffmpeg to be more widely buildable
+AC_C_BIGENDIAN
+AC_C_CONST
+AC_C_INLINE
+AC_C_RESTRICT
-AM_CONDITIONAL([HAVE_ESD], [test "x$have_esound" = "xyes"])
+dnl empty_array_size - src/input/vcd
+AC_MSG_CHECKING([how to create empty arrays])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[struct { int foo; int bar[]; } baz]])],
+ [empty_array_size=""],
+ [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[struct { int foo; int bar[0]; } baz]])],
+ [empty_array_size="0"],
+ [AC_MSG_ERROR([compiler is unable to create empty arrays])])])
-AC_SUBST([ESD_CFLAGS])
-AC_SUBST([ESD_LIBS])
+AC_DEFINE_UNQUOTED([EMPTY_ARRAY_SIZE], [$empty_array_size], [what to put between the brackets for empty arrays])
+AC_MSG_RESULT([[[$empty_array_size]]])
+dnl ISOC99_PRAGMA - src/input/vcd/libvcd
+AC_MSG_CHECKING([whether $CC supports ISOC99 _Pragma()])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[_Pragma("pack(1)")]])],
+ [ISOC99_PRAGMA=yes
+ AC_DEFINE([HAVE_ISOC99_PRAGMA], [], [Supports ISO _Pragma() macro])],
+ [ISOC99_PRAGMA=no])
+AC_MSG_RESULT([$ISOC99_PRAGMA])
-dnl ---------------------------------------------
-dnl ARTS support
-dnl ---------------------------------------------
-AC_ARG_WITH([arts],
- AS_HELP_STRING([--without-arts], [Build without ARTS audio output]),
- [with_arts=$withval], [with_arts=yes])
+dnl ASM ALIGN is power of two ?
+dnl src/post/planar
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[asm(".align 3");]])],
+ [AC_DEFINE([ASMALIGN_1SLN], [1],
+ [define if '.align n' means alignment to (1 << n) - byte boundaries])])
-if test "x$with_arts" = "xyes"; then
- AM_PATH_ARTS(0.9.5,
- AC_DEFINE(HAVE_ARTS,1,[Define this if you have ARTS (libartsc) installed]),
- AC_MSG_RESULT(*** All of ARTS dependent parts will be disabled ***))
-else
- no_arts=yes
-fi
-AM_CONDITIONAL(HAVE_ARTS, test "x$no_arts" != "xyes")
+CC_ATTRIBUTE_ALIGNED
+CC_ATTRIBUTE_PACKED([XINE_PACKED='__attribute__((packed))'],
+ [AC_MSG_WARN([Your compiler doesn't support __attribute__((packed)); xine might not work as expected.])])
+AC_DEFINE_UNQUOTED([XINE_PACKED], [$XINE_PACKED], [Mark a structure as being packed])
-dnl ---------------------------------------------
-dnl FusionSound support
-dnl ---------------------------------------------
+CC_ATTRIBUTE_MALLOC
-AC_ARG_WITH([fusionsound],
- AS_HELP_STRING([--with-fusionsound], [Build with FunsionSound audio output]),
- [with_fusionsound=$withval], [with_fusionsound=no])
+CC_ATTRIBUTE_VISIBILITY([protected],
+ [visibility_export="protected"],
+ [CC_ATTRIBUTE_VISIBILITY([default], [visibility_export="default"])])
-if test "x$with_fusionsound" = "xyes"; then
- PKG_CHECK_MODULES(FUSIONSOUND, fusionsound >= 0.9.23,
- AC_DEFINE(HAVE_FUSIONSOUND,1,[Define to 1 if you have FusionSound.]),
- AC_MSG_RESULT(*** All of FusionSound dependent parts will be disabled ***))
- AC_SUBST(FUSIONSOUND_CFLAGS)
- AC_SUBST(FUSIONSOUND_LIBS)
-else
- no_fusionsound=yes
+if test x"$visibility_export" != x""; then
+ CC_FLAG_VISIBILITY([VISIBILITY_FLAG="-fvisibility=hidden"
+ EXPORTED='__attribute__((visibility("default")))'])
fi
-AM_CONDITIONAL(HAVE_FUSIONSOUND, test "x$no_fusionsound" != "xyes")
-
-
-dnl ---------------------------------------------
-dnl JACK support
-dnl ---------------------------------------------
-
-AC_ARG_WITH([jack],
- AS_HELP_STRING([--without-jack], [Build without Jack support]))
+AC_DEFINE_UNQUOTED([EXPORTED], [$EXPORTED], [Mark a symbol as being exported if visibility is changed])
+AC_SUBST([VISIBILITY_FLAG])
-if test "x$with_jack" != "xno"; then
- PKG_CHECK_MODULES([JACK], [jack >= 0.100], [have_jack=yes], [have_jack=no])
-
- if test "x$with_jack" = "xyes" && test "x$have_jack" = "xno"; then
- AC_MSG_ERROR([Jack support requested, but Jack not found])
- fi
-fi
+CC_ATTRIBUTE_SENTINEL
+CC_ATTRIBUTE_FORMAT
+CC_ATTRIBUTE_FORMAT_ARG
-AM_CONDITIONAL([HAVE_JACK], [test "x$have_jack" = "xyes"])
+CC_CHECK_CFLAGS([-pipe], [miscflags="$miscflags -pipe"])
+dnl Set warning flags for warnings that we do not want to skip. In all cases,
+dnl these warnings should be enabled. Set these into CFLAGS and OBJCFLAGS
+dnl later after all testing is done.
-dnl ---------------------------------------------
-dnl gnome-vfs support
-dnl ---------------------------------------------
+CC_CHECK_CFLAGS([-Wall], [warnflags="$warnflags -Wall"])
-AC_ARG_ENABLE([gnomevfs],
- AS_HELP_STRING([--disable-gnomevfs], [do not build gnome-vfs support]),
- [with_gnome_vfs=$enableval], [with_gnome_vfs=yes])
-
-if test "x$with_gnome_vfs" = "xyes"; then
- PKG_CHECK_MODULES(GNOME_VFS, gnome-vfs-2.0,
- no_gnome_vfs=no,
- no_gnome_vfs=yes)
- AC_SUBST(GNOME_VFS_CFLAGS)
- AC_SUBST(GNOME_VFS_LIBS)
- if test "x$no_gnome_vfs" != "xyes"; then
- AC_DEFINE(HAVE_GNOME_VFS,1,[Define this if you have gnome-vfs installed])
- else
- AC_MSG_RESULT(*** All of the gnome-vfs dependent parts will be disabled ***)
- fi
-else
- no_gnome_vfs=yes
+CC_CHECK_CFLAGS([-Wformat=2], [wformat="-Wformat=2"],
+ [CC_CHECK_CFLAGS([-Wformat], [wformat="-Wformat"])])
+if test x"$wformat" != x""; then
+ CC_CHECK_CFLAGS([-Wno-format-zero-length], [wformat="$wformat -Wno-format-zero-length"])
fi
-AM_CONDITIONAL(HAVE_GNOME_VFS, test "x$no_gnome_vfs" != "xyes")
-
-dnl ---------------------------------------------
-dnl gdk-pixbuf support
-dnl ---------------------------------------------
+CC_CHECK_CFLAGS([-Wmissing-format-attribute], [wformat="$wformat -Wmissing-format-attribute"])
+warnflags="$warnflags $wformat"
-AC_ARG_ENABLE([gdkpixbuf],
- AS_HELP_STRING([--disable-gdkpixbuf], [do not build gdk-pixbuf support]))
-
-if test "x$enable_gdkpixbuf" != "xno"; then
- PKG_CHECK_MODULES(GDK_PIXBUF, gdk-pixbuf-2.0,
- no_gdkpixbuf=no,
- no_gdkpixbuf=yes)
- AC_SUBST(GDK_PIXBUF_CFLAGS)
- AC_SUBST(GDK_PIXBUF_LIBS)
- if test "x$no_gdkpixbuf" != "xyes"; then
- AC_DEFINE(HAVE_GDK_PIXBUF,1,[Define this if you have gdk-pixbuf installed])
- else
- AC_MSG_RESULT(*** All of the gdk-pixbuf dependent parts will be disabled ***)
- fi
-else
- no_gdkpixbuf=yes
-fi
-AM_CONDITIONAL(HAVE_GDK_PIXBUF, test "x$no_gdkpixbuf" != "xyes")
+dnl WARNING: This warning flag, if set into CFLAGS now, can break some autoconf tests.
+CC_CHECK_CFLAGS([-Werror-implicit-function-declaration], [warnflags="$warnflags -Werror-implicit-function-declaration"])
-dnl ---------------------------------------------
-dnl libsmbclient support
-dnl ---------------------------------------------
+CC_CHECK_CFLAGS([-Wstrict-aliasing=2], [warnflags="$warnflags -Wstrict-aliasing=2"],
+ [CC_CHECK_CFLAGS([-Wstrict-aliasing], [warnflags="$warnflags -Wstrict-aliasing"])])
+
+CC_CHECK_CFLAGS([-Wchar-subscripts], [warnflags="$warnflags -Wchar-subscripts"])
+CC_CHECK_CFLAGS([-Wmissing-declarations], [warnflags="$warnflags -Wmissing-declarations"])
+CC_CHECK_CFLAGS([-Wmissing-prototypes], [warnflags="$warnflags -Wmissing-prototypes"])
+
+dnl Some combinations of gcc and glibc produce useless warnings on memset when
+dnl compiling with -Wpointer-arith, so check for this first.
+AC_MSG_CHECKING([for sane -Wpointer-arith])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <string.h>]], [[int a; memset(&a, 0, sizeof(int))]])],
+ [warnflags="$warnflags -Wpointer-arith"
+ AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])])
+
+dnl FreeBSD (et al.) does not complete linking for shared objects when pthreads
+dnl are requested, as different implementations are present; to avoid problems
+dnl use -Wl,-z,defs only for those platforms not behaving this way.
+case "$host_or_hostalias" in
+ *-freebsd*) ;;
-AC_ARG_ENABLE([samba],
- AS_HELP_STRING([--disable-samba], [do not build Samba support]),
- [with_samba=$enableval], [with_samba=yes])
-
-if test "x$with_samba" = "xyes"; then
- AC_CHECK_LIB(smbclient, smbc_init,
- [ AC_CHECK_HEADER(libsmbclient.h,
- [ have_libsmbclient=yes
- LIBSMBCLIENT_LIBS="-lsmbclient" ],
- AC_MSG_RESULT([*** All libsmbclient dependent parts will be disabled ***]))],
- AC_MSG_RESULT([*** All libsmbclient dependent parts will be disabled ***]))
- AC_SUBST(LIBSMBCLIENT_LIBS)
-fi
-AM_CONDITIONAL(HAVE_LIBSMBCLIENT, test "x$have_libsmbclient" = "xyes")
+ dnl check if we are using the cygwin, mingw or cygwin with mno-cygwin mode
+ dnl in which case we are actually dealing with a mingw32 compiler
+ dnl This cannot be done until AC_PROG_EGREP and AC_PROG_CC are both done.
+ *-*-mingw* | *-*-cygwin*)
+ CC_CHECK_LDFLAGS([-Wl,-z,defs], [NOUNDEF="-Wl,-z,defs"])
+ case "$host_or_hostalias" in
+ *-*-mingw32*)
+ WIN32_SYS=mingw32
+ ;;
+ *-*-cygwin*)
+ AC_EGREP_CPP([yes],
+ [#ifdef WIN32
+ yes
+ #endif],
+ [WIN32_SYS=mingw32], [WIN32_SYS=cygwin])
+ ;;
+ esac
+
+ if test "$WIN32_SYS" = "mingw32"; then
+ WIN32_INCLUDES='-I$(top_srcdir)/win32/include'
+ LIBS="-lwinmm -lwsock32 $LIBS"
+ GOOM_LIBS="-liberty"
+ AC_SUBST(GOOM_LIBS)
+ fi
+ LDFLAGS="-no-undefined $LDFLAGS"
+ ;;
+ *)
+ CC_CHECK_LDFLAGS([-Wl,-z,defs], [NOUNDEF="-Wl,-z,defs"])
+ ;;
+esac
-dnl ---------------------------------------------
-dnl SUN style audio interface
-dnl ---------------------------------------------
+AC_SUBST(NOUNDEF)
+AM_CONDITIONAL([WIN32], [test x"$WIN32_SYS" = x"mingw32"])
-AC_MSG_CHECKING(for Sun audio support)
-have_sunaudio=no
-AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
- #include <sys/types.h>
- #include <sys/audioio.h>
- ]], [[
- audio_info_t audio_info;
- AUDIO_INITINFO(&audio_info);
- ]])],[
- have_sunaudio=yes
- ],[])
-AC_MSG_RESULT($have_sunaudio)
-AM_CONDITIONAL(HAVE_SUNAUDIO, test "x$have_sunaudio" = "xyes")
-
-if test "x$have_sunaudio" = "xyes"; then
- dnl NetBSD and OpenBSD don't have this, but check for it
- dnl rather than assuming that it doesn't happen elsewhere.
- AC_CHECK_MEMBERS([audio_info_t.output_muted])
+AC_ARG_ENABLE([altivec],
+ [AS_HELP_STRING([--disable-altivec], [do not use assembly codes for Motorola 74xx CPUs])],
+ [], [enable_altivec="yes"])
+
+dnl No optimization at all. For gcc, this is the optimization level.
+O0_CFLAGS="-O0"
+
+dnl Lowest level of optimization. For gcc, this enables:
+dnl -fdefer-pop -fdelayed-branch -fguess-branch-probability -fcprop-registers
+dnl -floop-optimize -fif-conversion -fif-conversion2 -ftree-ccp -ftree-dce
+dnl -ftree-dce -ftree-dominator-opts -ftree-dse -ftree-ter -ftree-lrs
+dnl -ftree-sra -ftree-copyrename -ftree-fre -ftree-ch -fmerge-constants
+dnl On platforms where -fomit-frame-pointer does not interfere with debugging,
+dnl it is also enabled by -O1.
+O1_CFLAGS="-O1"
+
+dnl Middle level of optimization. For gcc, this enables -O1 and:
+dnl -fthread-jumps -fcrossjumping -foptimize-sibling-calls -fcse-follow-jumps
+dnl -fcse-skip-blocks -fgcse -fgcse-lm -fexpensive-optimizations
+dnl -fstrength-reduce -frerun-cse-after-loop -frerun-loop-opt -fcaller-saves
+dnl -fforce-mem -fpeephole2 -fschedule-insns -fschedule-insns2
+dnl -fsched-interblock -fsched-spec -fregmove -fstrict-aliasing
+dnl -fdelete-null-pointer-checks -freorder-blocks -freorder-functions
+dnl -funit-at-a-time -falign-functions -falign-jumps -falign-loops
+dnl -falign-labels -ftree-pre
+dnl Note that Apple's version of gcc differs slightly, because it does not enable
+dnl -fstrict-aliasing -freorder-blocks -fsched-interblock
+O2_CFLAGS="-O2"
+
+dnl Highest level of optimization. For gcc, this enables -O2 and:
+dnl -finline-functions -funswitch-loops -fgcse-after-reload
+O3_CFLAGS="-O3"
+
+dnl gcc 3.3.5 (at least) is known to be buggy wrt optimization with
+dnl -finline-functions, so use -fno-inline-functions for gcc < 3.4.0
+if test x"$GCC" = x"yes"; then
+ if test "$GCC_VERSION_MAJOR" -lt 3; then
+ O3_CFLAGS="$O3_CFLAGS -fno-inline-functions"
+ else
+ if test "$GCC_VERSION_MAJOR" -eq 3 -a "$GCC_VERSION_MINOR" -lt 4; then
+ O3_CFLAGS="$O3_CFLAGS -fno-inline-functions"
+ fi
+ fi
fi
+CC_CHECK_CFLAGS([-ffast-math], [optflags="$optflags -ffast-math"])
+CC_CHECK_CFLAGS([-fexpensive-optimizations], [optflags="$optflags -fexpensive-optimizations"])
-dnl ---------------------------------------------
-dnl IRIX style audio interface
-dnl ---------------------------------------------
-
-AM_CHECK_IRIXAL([AC_DEFINE(HAVE_IRIXAL,1,
- [Define this if you have a usable IRIX al interface available])],
- [AC_MSG_RESULT([*** All of IRIX AL dependent parts will be disabled ***])])
-AM_CONDITIONAL(HAVE_IRIXAL, [test "x$am_cv_have_irixal" = xyes])
-
-
-dnl ---------------------------------------------
-dnl Solaris kstat kernel statistics
-dnl ---------------------------------------------
-
-AC_CHECK_LIB(kstat, kstat_open,
- [KSTAT_LIBS=-lkstat
- AC_DEFINE(HAVE_KSTAT,1,[Define this if you have kernel statistics available via kstat interface])])
-AC_SUBST(KSTAT_LIBS)
-
-
-dnl ---------------------------------------------
-dnl cdrom ioctls
-dnl ---------------------------------------------
-
-AC_CHECK_HEADERS([linux/cdrom.h sys/dvdio.h], [break])
-AC_CHECK_HEADERS([sys/cdio.h sys/scsiio.h])
-AM_CHECK_CDROM_IOCTLS(
- [AC_DEFINE(HAVE_CDROM_IOCTLS,1,[Define this if you have CDROM ioctls])],
- [AC_MSG_RESULT([*** (S)VCD support will be disabled ***])])
-AM_CONDITIONAL(HAVE_CDROM_IOCTLS, [test "x$have_cdrom_ioctls" = "xyes"])
-
-
-dnl ---------------------------------------------
-dnl check for a usable version of libdvdnav
-dnl ---------------------------------------------
-
-AC_ARG_WITH(external-dvdnav, AS_HELP_STRING([--with-external-dvdnav], [use external dvdnav library (not recommended)]),
- [external_dvdnav="$withval"], [no_dvdnav="yes"; external_dvdnav="no"])
+case "$host_or_hostalias" in
+ alphaev56-*) cpuflags="-mcpu=ev56 -mieee $cpuflags" ;;
+ alpha*) cpuflags="-mieee $cpuflags" ;;
-if test "x$external_dvdnav" = "xyes"; then
- AM_PATH_DVDNAV(0.1.9,
- AC_DEFINE(HAVE_DVDNAV,1,[Define this if you have a suitable version of libdvdnav]),
- [AC_MSG_RESULT([*** no usable version of libdvdnav found, using internal copy ***])])
-else
- AC_MSG_RESULT([Use included DVDNAV support])
-fi
+ armv4l-*-linux*)
+ cpuflags="-mcpu=strongarm1100 -ffast-math -fsigned-char $cpuflags"
+ DEFAULT_OCFLAGS='$(O2_CFLAGS)'
+ ;;
-AM_CONDITIONAL(HAVE_DVDNAV, [test "x$no_dvdnav" != "xyes"])
+ sparc*-*-linux*)
+ case "`uname -m`" in
+ sparc) cpuflags="-mcpu=supersparc -mtune=supersparc" ;;
+ sparc64) cpuflags="-mcpu=ultrasparc -mtune=ultrasparc" ;;
+ esac
+ test x"$enable_vis" != x"no" && has_vis=yes
+ AC_DEFINE([ARCH_SPARC], [], [Define this if you're running SPARC architecture])
+ ;;
+ sparc-*-solaris*)
+ if test x"$GCC" = x"yes"; then
+ case "`uname -m`" in
+ sun4c) cpuflags="-mcpu=v7 -mtune=supersparc" ;;
+ sun4m) cpuflags="-mcpu=v8 -mtune=supersparc" ;;
+ sun4u)
+ if test x"$GCC_VERSION_MAJOR" -lt 3; then
+ # -mcpu=ultrasparc triggers a GCC 2.95.x compiler bug
+ # when compiling video_out.c:
+ # gcc: Internal compiler error: program cc1 got fatal signal 11
+ # avoid -mcpu=ultrasparc with gcc 2.*
+ cpuflags="-mcpu=v8 -mtune=ultrasparc"
+ else
+ cpuflags="-mcpu=ultrasparc -mtune=ultrasparc"
+ fi
+ ;;
+ esac
+ if test "$GCC_VERSION_MAJOR" -ge 3; then
+ test x"$enable_vis" != x"no" && has_vis=yes
+ fi
+ else
+ case "`uname -m`" in
+ sun4c) cpuflags="-xarch=v7" ;;
+ sun4m) cpuflags="-xarch=v8" ;;
+ sun4u) cpuflags="-xarch=v8plusa" ;;
+ esac
+ O1_CFLAGS="-fast -xCC"
+ O2_CFLAGS="$O1_CFLAGS"
+ O3_CFLAGS="$O1_CFLAGS"
+ fi
+ AC_DEFINE([ARCH_SPARC], [], [Define this if you're running SPARC architecture])
+ ;;
-dnl ---------------------------------------------
-dnl Video CD
-dnl ---------------------------------------------
+ x86_64-*)
+ arch_x86=yes
+ AC_DEFINE([ARCH_X86_64], [], [Define this if you're running x86 architecture 64 bits])
+ ;;
-AC_ARG_ENABLE(vcd, AS_HELP_STRING([--disable-vcd], [do not compile VCD plugin]),
- enable_vcd=$enableval, enable_vcd=yes)
+ *-*-darwin*)
+ case "$host_or_hostalias" in
+ universal-*)
+ arch_ppc=yes
+ arch_x86=yes
+ ;;
+ i386-* | x86_64-*)
+ arch_x86=yes
+ AC_DEFINE([ARCH_X86_32], [], [Define this if you're running x86 architecture 32 bits])
+ ;;
+ ppc* | powerpc*)
+ arch_ppc=yes
+ dnl avoid ppc compilation crash
+ AS="$CC"
+ AC_DEFINE([ARCH_PPC], [], [Define this if you're running PowerPC architecture])
+
+ AC_CHECK_HEADER([altivec.h], [], [enable_altivec=no])
+ if test x"$enable_altivec" != x"no"; then
+ AC_DEFINE([ENABLE_ALTIVEC], [], [Define this if you want to use altivec on PowerPC CPUs])
+ cpuflags="$cpuflags -faltivec -maltivec"
+ LIBMPEG2_CFLAGS="$LIBMPEG2_CFLAGS -force_cpusubtype_ALL"
+ fi
+ ;;
+ esac
+
+ enable_impure_text=yes
+ HOST_OS_DARWIN=1
+ dnl HOST_OS_DARWIN is used by a bunch of difference stuff, including
+ dnl libdvdnav, libmpeg2, and xine itself (xine-engine, xine-utils)
+ AC_DEFINE([HOST_OS_DARWIN], 1, [Define this if built on Mac OS X/Darwin])
+ dnl CONFIG_DARWIN is used by ffmpeg, so anything that pulls ffmpeg
+ dnl headers needs to have this set.
+ AC_DEFINE([CONFIG_DARWIN], 1, [Define this if built on Mac OS X/Darwin])
+ CPPFLAGS="-D_INTL_REDIRECT_MACROS $CPPFLAGS"
+ ;;
-dnl Force build of both vcd plugins, for now.
-dnl AC_ARG_ENABLE(vcdo, AS_HELP_STRING([--disable-vcdo], [do not compile old VCD plugin]),
-dnl enable_vcdo=$enableval, enable_vcdo=yes)
-dnl
-enable_vcdo="yes"
-
-AC_ARG_WITH(internal-vcdlibs, AS_HELP_STRING([--with-internal-vcdlibs], [force using internal libcdio/libvcd/libvcdinfo]),
- [internal_vcdnav="$withval"], [internal_vcdnav="no"])
-
-if test "x$enable_vcd" = "xyes"; then
- dnl empty_array_size
- AC_MSG_CHECKING([how to create empty arrays])
-
- empty_array_size="xxx"
- AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[struct { int foo; int bar[]; } doo;]])],[empty_array_size=""],[])
-
- if test "x$empty_array_size" = "xxxx";then
- AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[struct { int foo; int bar[0]; } doo;]])],[empty_array_size="0"],[])
- fi
-
- if test "x$empty_array_size" = "xxxx"
- then
- AC_MSG_ERROR([compiler is unable to creaty empty arrays])
- else
- AC_DEFINE_UNQUOTED(EMPTY_ARRAY_SIZE, $empty_array_size,
- [what to put between the brackets for empty arrays])
- changequote(`,')
- msg="[${empty_array_size}]"
- changequote([,])
- AC_MSG_RESULT($msg)
- fi
- dnl empty_array_size
-
- if test "x$internal_vcdnav" = "xno" ; then
- PKG_CHECK_MODULES([LIBCDIO], [libcdio >= 0.71], [], [internal_vcdnav=yes])
- PKG_CHECK_MODULES([LIBVCDINFO], [libvcdinfo >= 0.7.23], [], [internal_vcdnav=yes])
- if test "x$internal_vcdnav" = "xyes"; then
- AC_MSG_RESULT([Use included libcdio/libvcdinfo support])
- fi
- fi
-
- dnl check twice, fallback is internal copy
- if test "x$internal_vcdnav" = "xno"; then
- AC_DEFINE([HAVE_VCDNAV], [1], [Define this if you use external libcdio/libvcdinfo])
- else
- AC_DEFINE_UNQUOTED(HOST_ARCH, "$host_os/$host_cpu", [host os/cpu identifier])
-
- AC_DEFINE(_DEVELOPMENT_, [], enable warnings about being development release)
- AC_HEADER_STDC
- AC_CHECK_HEADERS(sys/stat.h stdint.h glob.h inttypes.h stdbool.h)
-
- if test "x$ac_cv_header_stdint_h" != "xyes"
- then
- AC_CHECK_SIZEOF(int, 4)
- AC_CHECK_SIZEOF(long, 4)
- AC_CHECK_SIZEOF(long long, 8)
- fi
+ ppc-*-linux* | powerpc-*)
+ arch_ppc=yes
- dnl ISOC99_PRAGMA
- AC_MSG_CHECKING([whether $CC supports ISOC99 _Pragma()])
- AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[_Pragma("pack(1)")]])],[
- ISOC99_PRAGMA=yes
- AC_DEFINE(HAVE_ISOC99_PRAGMA, [], [Supports ISO _Pragma() macro])
- ],[ISOC99_PRAGMA=no])
- AC_MSG_RESULT($ISOC99_PRAGMA)
-
- dnl
- dnl bitfield order
- dnl
- AC_MSG_CHECKING([bitfield ordering in structs])
-
- dnl basic compile test for all platforms
- AC_COMPILE_IFELSE([
-int main() {
- struct { char bit_0:1, bit_12:2, bit_345:3, bit_67:2; }
-#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
- __attribute__((packed))
-#endif
- bf = { 1,1,1,1 };
- switch (0) case 0: case sizeof(bf) == 1:;
- return 0;
-}
-], [], AC_MSG_ERROR([compiler doesn't support bitfield structs]))
+ dnl avoid ppc compilation crash
+ AS="$CC"
+ AC_DEFINE([ARCH_PPC], [], [Define this if you're running PowerPC architecture])
+ AC_CHECK_HEADER([altivec.h], [], [enable_altivec=no])
+ if test x"$enable_altivec" != x"no"; then
+ AC_DEFINE([ENABLE_ALTIVEC], [], [Define this if you want to use altivec on PowerPC CPUs])
+ cpuflags="$cpuflags -maltivec"
+ fi
+ ;;
- dnl run test
- AC_RUN_IFELSE([
-int main() {
- struct { char bit_0:1, bit_12:2, bit_345:3, bit_67:2; }
-#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
- __attribute__((packed))
-#endif
- bf = { 1,1,1,1 };
- if (sizeof (bf) != 1) return 1;
- return *((unsigned char*) &bf) != 0x4b; }
-], bf_lsbf=1, [
- AC_RUN_IFELSE([
-int main() {
- struct { char bit_0:1, bit_12:2, bit_345:3, bit_67:2; }
-#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
- __attribute__((packed))
-#endif
- bf = { 1,1,1,1 };
- if (sizeof (bf) != 1) return 1;
- return *((unsigned char*) &bf) != 0xa5; }
-], bf_lsbf=0, AC_MSG_ERROR([unsupported bitfield ordering]))
- ],
- [case "$host" in
- *-*-mingw32* | *-*-cygwin*)
- bf_lsbf=1
- ;;
- *)
- AC_MSG_RESULT([unknown])
- AC_MSG_ERROR([value of bitfield test isn't known for $host
-*********************************************************************
-Value of bitfield test can't be found out for cross-compiling and we
-don't know its value for host "$host".
-
-Because it's needed for VCD plugin, disable VCD by configure option
---disable-vcd or use external VCD library.
-*********************************************************************])
- esac]
-)
-
- if test "x$cross_compiling" = "xyes"; then
- TEXT=" (guessed)"
- else
- TEXT=""
- fi
- if test "x$bf_lsbf" = "x1"; then
- AC_MSG_RESULT(LSBF${TEXT})
- AC_DEFINE(BITFIELD_LSBF, [], [compiler does lsbf in struct bitfields])
- else
- AC_MSG_RESULT(MSBF${TEXT})
- fi
+ i?86-* | k?-* | athlon-* | pentium*)
+ arch_x86=yes
+ enable_impure_text=yes
+
+ case "$host_or_hostalias" in
+ *-*-cygwin* | *-*-mingw32*)
+ CC_CHECK_CFLAGS([-fno-omit-frame-pointer], [W32_NO_OPTIMIZE="$W32_NO_OPTIMIZE -fno-omit-frame-pointer"])
+ CC_CHECK_CFLAGS([-fno-inline-functions], [W32_NO_OPTIMIZE="$W32_NO_OPTIMIZE -fno-inline-functions"])
+ CC_CHECK_CFLAGS([-fno-rename-registers], [W32_NO_OPTIMIZE="$W32_NO_OPTIMIZE -fno-rename-registers"])
+ AC_SUBST(W32_NO_OPTIMIZE)
+ case "$host_or_hostalias" in
+ *-*-cygwin*) LIBS="$LIBS @INTLLIBS@ -lkernel32" ;;
+ esac
+ ;;
+ esac
+
+ AC_DEFINE([ARCH_X86_32], [], [Define this if you're running x86 architecture 32 bits])
+
+ if test x"$GCC" = x"yes" -o x"${CC##*/}" = x"icc"; then
+ if test x"$GCC" = x"yes"; then
+ # GCC optimizations
+ CC_CHECK_CFLAGS([-mtune=i386], [sarchopt="-mtune"],
+ [CC_CHECK_CFLAGS([-mcpu=i386], [sarchopt="-mcpu"],
+ [CC_CHECK_CFLAGS([-march=i386], [sarchopt="-march"], [sarchopt="no"])])])
+ if test "$sarchopt" != "no"; then
+ case "$host_or_hostalias" in
+ i386-*) archopt_val="i386" ;;
+ i486-*) archopt_val="i486" ;;
+ i586-*) archopt_val="pentium" ;;
+ pentium-mmx-*) archopt_val="pentium-mmx" ;;
+ k6-2* | k6-3-*) archopt_val="k6-2" ;;
+ k6-*) archopt_val="k6" ;;
+ pentium3-*) archopt_val="pentium3" ;;
+ pentium4-*) archopt_val="pentium4" ;;
+
+ athlon-4-* | athlon-xp-* | althon-mp-*) archopt_val="athlon-4" ;;
+ k7-* | athlon-tbird-* | athlon-*) archopt_val="athlon" ;;
+
+ pentiumpro-* | pentium2-* | i686-*)
+ archopt_val="pentiumpro"
+ if test x"$cross_compiling" != x"yes"; then
+ if test -f /proc/cpuinfo; then
+ modelname=`cat /proc/cpuinfo | grep "model\ name\ :" | sed -e 's/ //g' | cut -d ':' -f2`
+ case "$modelname" in
+ *Athlon* | *Duron* | *K7*)
+ dnl Special check for k7 cpu CC support
+ CC_CHECK_CFLAGS([$sarchopt=athlon],
+ [archopt_val="athlon"], [archopt_val="i686"])
+ ;;
+ VIAEzra)
+ archopt_val="c3"
+ ;;
+ esac
+ fi
+ fi
+ ;;
+ esac
+ test x"$archopt_val" != x"" && cpuflags="$cpuflags $sarchopt=$archopt_val"
+ fi
+ else
+ # Intel optimizations
+ O3_CFLAGS="$O3_CFLAGS -unroll -ipo -ipo_obj"
+ fi
+ fi
+ ;;
+esac
- AC_CHECK_HEADERS([errno.h fcntl.h \
- stdbool.h stdlib.h stdint.h stdio.h string.h \
- strings.h linux/version.h sys/cdio.h sys/stat.h \
- sys/types.h ])
-
- LIBCDIO_CFLAGS='-I$(top_srcdir)/src/input/vcd/libcdio'
- LIBCDIO_LIBS='$(top_builddir)/src/input/vcd/libcdio/libcdio.la'
- LIBISO9660_LIBS='$(top_builddir)/src/input/vcd/libcdio/libiso9660.la'
- LIBVCD_CFLAGS='-I$(top_srcdir)/src/input/vcd/libvcd'
- LIBVCD_LIBS='$(top_builddir)/src/input/vcd/libvcd/libvcd.la'
- LIBVCDINFO_LIBS='$(top_builddir)/src/input/vcd/libvcd/libvcdinfo.la'
-
- case $host_os in
- darwin*)
- AC_CHECK_HEADERS(IOKit/IOKitLib.h CoreFoundation/CFBase.h,
- [have_iokit_h="yes"])
- if test "x$have_iokit_h" = "xyes" ; then
- AC_DEFINE([HAVE_DARWIN_CDROM], [1],
- [Define 1 if you have Darwin OS X-type CD-ROM support])
- fi
- ;;
- linux*)
- AC_CHECK_HEADERS(linux/version.h)
- AC_CHECK_HEADERS(linux/cdrom.h, [have_linux_cdrom_h="yes"])
- if test "x$have_linux_cdrom_h" = "xyes" ; then
- AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
-#include <linux/cdrom.h>
-struct cdrom_generic_command test;
-int has_timeout=sizeof(test.timeout);]])],
- [AC_DEFINE([HAVE_LINUX_CDROM_TIMEOUT], [1],
- [Define 1 if timeout is in cdrom_generic_command struct])],[])
- AC_DEFINE([HAVE_LINUX_CDROM], [1],
- [Define 1 if you have Linux-type CD-ROM support])
- fi
- ;;
- bsdi*)
- AC_CHECK_HEADERS(dvd.h, [have_bsdi_dvd_h="yes"])
- if test "x$have_bsdi_dvd_h" = "xyes" ; then
- AC_DEFINE([HAVE_BSDI_CDROM], [1],
- [Define 1 if you have BSDI-type CD-ROM support])
- fi
- ;;
- sunos*|sun*|solaris*)
- AC_CHECK_HEADERS(sys/cdio.h)
- AC_DEFINE([HAVE_SOLARIS_CDROM], [1],
- [Define 1 if you have Solaris CD-ROM support])
- ;;
- cygwin*)
- AC_DEFINE([CYGWIN], [1],
- [Define 1 if you are compiling using cygwin])
- AC_DEFINE([HAVE_WIN32_CDROM], [1],
- [Define 1 if you have MinGW CD-ROM support])
- LIBCDIO_LIBS="$LIBCDIO_LIBS -lwinmm"
- LIBVCD_LIBS="$LIBVCD_LIBS -lwinmm"
- ;;
- mingw*)
- AC_DEFINE([MINGW32], [1],
- [Define 1 if you are compiling using MinGW])
- AC_DEFINE([HAVE_WIN32_CDROM], [1],
- [Define 1 if you have MinGW CD-ROM support])
- ;;
- freebsd4.*)
- AC_DEFINE([HAVE_FREEBSD_CDROM], [1],
- [Define 1 if you have FreeBSD CD-ROM support])
- ;;
- *)
- AC_MSG_WARN(Don't have OS CD-reading support for ${host_os}...)
- AC_MSG_WARN(Will use generic support.)
- ;;
+AC_ARG_ENABLE([vis],
+ [AS_HELP_STRING([--disable-vis], [do not use assembly codes for Sun UltraSPARC CPUs])],
+ [], [enable_vis="yes"])
+if test "x$has_vis" = "xyes"; then
+ AC_DEFINE([ENABLE_VIS], [], [Define this if you have Sun UltraSPARC CPU])
+ case "$cpuflags" in
+ *-mcpu=*) ;;
+ *) cpuflags="$cpuflags -mcpu=v9" ;;
esac
- AC_SUBST(LINUX_CDROM_TIMEOUT)
- AC_SUBST(HAVE_BSDI_CDROM)
- AC_SUBST(HAVE_DARWIN_CDROM)
- AC_SUBST(HAVE_FREEBSD_CDROM)
- AC_SUBST(HAVE_LINUX_CDROM)
- AC_SUBST(HAVE_SOLARIS_CDROM)
- AC_SUBST(HAVE_WIN32_CDROM)
- AC_SUBST(LINUX_CDROM_TIMEOUT)
- AC_SUBST(LIBVCD_SYSDEP)
-
- AC_CHECK_FUNCS( bzero memcpy )
-
- AC_CHECK_MEMBER([struct tm.tm_gmtoff],
- [AC_DEFINE(HAVE_TM_GMTOFF, 1,
- [Define if struct tm has the tm_gmtoff member.])],
- ,
- [#include <time.h>])
- fi
fi
-
-AC_DEFINE([LIBCDIO_CONFIG_H], 1, [Get of rid system libcdio build configuration])
-AC_DEFINE([EXTERNAL_LIBCDIO_CONFIG_H], 1, [Get of rid system libcdio build configuration])
-AC_SUBST(LIBCDIO_CFLAGS)
-AC_SUBST(LIBCDIO_LIBS)
-AC_SUBST(LIBISO9660_LIBS)
-AC_SUBST(LIBVCD_CFLAGS)
-AC_SUBST(LIBVCD_LIBS)
-AC_SUBST(LIBVCDINFO_LIBS)
-AM_CONDITIONAL(HAVE_VCDNAV, [test "x$internal_vcdnav" = "xno"])
-AM_CONDITIONAL(ENABLE_VCD, [test "x$enable_vcd" = "xyes"])
-
-
-dnl ---------------------------------------------
-dnl ASF build can be optional
-dnl ---------------------------------------------
-
-AC_ARG_ENABLE([asf], AS_HELP_STRING([--disable-asf], [do not build ASF demuxer]))
-AM_CONDITIONAL(BUILD_ASF, test "x$enable_asf" != "xno")
-
-
-dnl ---------------------------------------------
-dnl FAAD build can be optional
-dnl ---------------------------------------------
-
-AC_ARG_ENABLE([faad], AS_HELP_STRING([--disable-faad], [do not build FAAD decoder]))
-AM_CONDITIONAL(BUILD_FAAD, test "x$enable_faad" != "xno")
-
-dnl ---------------------------------------------
-dnl Optional and external libdts
-dnl ---------------------------------------------
-
-AC_ARG_ENABLE(dts, AS_HELP_STRING([--disable-dts], [Disable support for DTS decoding library (default: enabled)]),
- [enable_libdts="$enableval"], [enable_libdts="yes"])
-AC_ARG_WITH(external-libdts, AS_HELP_STRING([--with-external-libdts], [use external libdts library (not recommended)]),
- [external_libdts="$withval"], [external_libdts="no"])
-
-have_dts="no"
-
-if test "x$enable_libdts" = "xno"; then
- AC_MSG_RESULT([libdts support disabled])
-elif test "x$external_libdts" = "xyes"; then
- PKG_CHECK_MODULES(LIBDTS, [libdts], have_dts=yes, have_dts=no)
- AC_CHECK_HEADERS([dts.h])
- AC_SUBST(LIBDTS_LIBS)
- AC_SUBST(LIBDTS_CFLAGS)
- if test "x$have_dts" = "xno"; then
- AC_MSG_RESULT([*** no usable version of libdts found, using internal copy ***])
- fi
+AM_CONDITIONAL([ENABLE_VIS], test x"$has_vis" = x"yes")
+
+O1_CFLAGS="$O1_CFLAGS $optflags $cpuflags"
+O2_CFLAGS="$O2_CFLAGS $optflags $cpuflags"
+O3_CFLAGS="$O3_CFLAGS $optflags $cpuflags"
+
+dnl Allow turning off/on of optimizations. By default, optimizations are
+dnl enabled if --enable-debug is not specified. Even with --enable-debug,
+dnl optimizations can be enabled by explicitly specifying --enable-optimizations
+AC_ARG_ENABLE([optimizations],
+ [AS_HELP_STRING([--disable-optimizations], [Don't try to guess what optimization to enable])],
+ [], [test x"$enable_debug" != x"no" && enable_optimizations="no"])
+AM_CONDITIONAL([DISABLE_OPTIMIZATIONS], [test x"$enable_optimizations" = x"no"])
+if test x"$enable_optimizations" = x"no"; then
+ DEFAULT_OCFLAGS='$(O0_CFLAGS)'
else
- AC_MSG_RESULT([Use included libdts support])
+ dnl For multi-pass compilation: never when cross-compiling
+ if test x"$cross_compiling" != x"yes"; then
+ if test x"$GCC" = x"yes"; then
+ CC_CHECK_CFLAGS([-fprofile-arcs], [CC_CHECK_CFLAGS([-fbranch-probabilities],
+ [PASS1_CFLAGS="-fprofile-arcs $PASS1_CFLAGS"
+ PASS2_CFLAGS="-fbranch-probabilities $PASS2_CFLAGS"])])
+ else
+ pass1flags="-prof_dir \$(PWD)/\$(top_builddir)/ -prof_genx"
+ pass2flags="-prof_dir \$(PWD)/\$(top_builddir)/ -prof_use"
+ CC_CHECK_CFLAGS(["$pass1flags"], [CC_CHECK_CFLAGS(["$pass2flags"],
+ [PASS1_CFLAGS="$pass1flags $PASS1_CFLAGS"
+ PASS2_CFLAGS="$pass2flags $PASS2_CFLAGS"])])
+ fi
+ fi
fi
+AC_SUBST(O0_CFLAGS)
+AC_SUBST(O1_CFLAGS)
+AC_SUBST(O2_CFLAGS)
+AC_SUBST(O3_CFLAGS)
-AM_CONDITIONAL(DTS, test "x$enable_libdts" = "xyes")
-AM_CONDITIONAL(EXTERNAL_LIBDTS, test "x$have_dts" = "xyes")
+AC_SUBST(PASS1_CFLAGS)
+AC_SUBST(PASS2_CFLAGS)
-dnl ---------------------------------------------
-dnl libmodplug support
-dnl ---------------------------------------------
-AC_ARG_ENABLE([modplug],
- AS_HELP_STRING([--enable-modplug], [Enable modplug support]) )
+test x"$DEFAULT_OCFLAGS" = x"" && DEFAULT_OCFLAGS='$(O3_CFLAGS)'
+AC_SUBST(DEFAULT_OCFLAGS)
-if test "x$enable_modplug" != "xno"; then
- PKG_CHECK_MODULES([LIBMODPLUG], [libmodplug >= 0.7],
- AC_DEFINE([HAVE_MODPLUG], 1, [define this if you have libmodplug installed]),
- [enable_modplug=no])
+if test x"$arch_x86" = x"yes" && test x"$enable_macosx_universal" = x"no"; then
+ AC_DEFINE([ARCH_X86], [], [Define this if you're running x86 architecture])
+ AC_DEFINE([HAVE_MMX], [], [Define this if you can compile MMX asm instructions])
fi
+AM_CONDITIONAL([ARCH_PPC], test x"$arch_ppc" = x"yes")
+AM_CONDITIONAL([ARCH_X86], test x"$arch_x86" = x"yes")
+AM_CONDITIONAL([HAVE_MMX], test x"$arch_x86" = x"yes")
+AM_CONDITIONAL([HOST_OS_DARWIN], test x"$HOST_OS_DARWIN" = x"1")
-AC_SUBST(LIBMODPLUG_CFLAGS)
-AC_SUBST(LIBMODPLUG_LIBS)
-dnl AM_CONDITIONAL(HAVE_MODPLUG, [test "x$have_modplug" = x"yes"])
-
-dnl ---------------------------------------------
-dnl Wavpack library
-dnl ---------------------------------------------
-AC_ARG_WITH([wavpack],
- AS_HELP_STRING([--with-wavpack], [Enable Wavpack decoder (requires libwavpack)]) )
-
-if test "x$with_wavpack" = "xyes"; then
- PKG_CHECK_MODULES([WAVPACK], [wavpack], [have_wavpack=yes])
+if test x"$enable_impure_text" = x"yes"; then
+ case "$host_or_hostalias" in
+ *solaris*)
+ if test "$GCC" = yes; then
+ IMPURE_TEXT_LDFLAGS="-mimpure-text"
+ else
+ IMPURE_TEXT_LDFLAGS="-z textoff"
+ fi
+ ;;
+ *darwin*)
+ IMPURE_TEXT_LDFLAGS="-Wl,-read_only_relocs,warning"
+ ;;
+ esac
fi
+AC_SUBST(IMPURE_TEXT_LDFLAGS)
-AM_CONDITIONAL([HAVE_WAVPACK], [test "x$have_wavpack" = "xyes"])
-
-
-dnl --------------------------------------------
-dnl Real binary codecs support
-dnl --------------------------------------------
-
-AC_ARG_ENABLE([real-codecs],
- AS_HELP_STRING([--disable-real-codecs], [Disable Real binary codecs support]))
-AC_ARG_WITH([real-codecs-path],
- AS_HELP_STRING([--with-real-codecs-path=dir], [Specify directory for Real binary codecs]), [
- AC_DEFINE_UNQUOTED([REAL_CODEC_PATH], ["$withval"], [Specified path for Real binary codecs])
- ])
-dnl On some systems, we cannot enable Real codecs support to begin with.
-dnl This includes Darwin, that uses Mach-O rather than ELF.
-case $host in
- *-darwin*) enable_real_codecs="no" ;;
-esac
+dnl ----------------------------
+dnl checks for library functions
+dnl ----------------------------
-if test "x$enable_real_codecs" != "xno"; then
- dnl For those that have a replacement, break at the first one found
- AC_CHECK_SYMBOLS([__environ _environ environ], [break], [need_weak_aliases=yes])
- AC_CHECK_SYMBOLS([stderr __stderrp], [break], [need_weak_aliases=yes])
+dnl NLS: src/input/mms.c src/input/vcd, xine-utils
+AC_CHECK_FUNCS([nl_langinfo])
- dnl For these there are no replacements
- AC_CHECK_SYMBOLS([___brk_addr __ctype_b])
+dnl src/libfaad
+AC_CHECK_DECL([lrintf],
+ [AC_DEFINE([HAVE_LRINTF], 1, [Define this if the 'lrintf' function is declared in math.h])
+ AC_DEFINE([_ISOC9X_SOURCE], 1, [Define this if you are ISO C9X compliant])],
+ [],
+ [#define _ISOC9X_SOURCE
+ #include <math.h>])
- if test "x$need_weak_aliases" = "xyes"; then
- CC_ATTRIBUTE_ALIAS(, [AC_MSG_ERROR([You need weak aliases support for Real codecs on your platform])])
- fi
-fi
+dnl contrib/libdca, src/video_out/vidix/drivers/mach64_vid.c
+AC_CHECK_FUNCS([memalign])
-AM_CONDITIONAL([ENABLE_REAL], [test "x$enable_real_codecs" != "xno"])
+dnl src/input/vcd/libcdio/portable.h
+AC_CHECK_FUNCS([bzero])
-dnl --------------------------------------------
-dnl mmap() support
-dnl --------------------------------------------
+dnl src/libfaad/common.h
+AC_CHECK_FUNCS([memcpy])
+dnl src/input/input_file.c
AC_ARG_ENABLE([mmap],
- AS_HELP_STRING([--enable-mmap], [Enable mmap() file loading (default: no)]))
-
-if test "x$enable_mmap" = "xyes"; then
- AC_CHECK_FUNCS([mmap])
+ AS_HELP_STRING([--enable-mmap], [Enable mmap() file loading (default: no)]))
+if test x"$enable_mmap" = x"yes"; then
+ AC_CHECK_FUNCS([mmap])
fi
-dnl ---------------------------------------------
-dnl antialising support
-dnl ---------------------------------------------
-
-AC_ARG_ENABLE([antialiasing],
- AS_HELP_STRING([--enable-antialiasing], [enable font antialiasing]))
-
-if test "x$enable_antialiasing" = "xyes"; then
- AC_DEFINE(ENABLE_ANTIALIASING,1,[Define this to 1 to enable font antialising.])
-fi
-
-dnl ---------------------------------------------
-dnl ip_mreqn
-dnl ---------------------------------------------
-
-AC_CHECK_IP_MREQN
-if test "x$have_ip_mreqn" = "xyes"; then
- AC_DEFINE(HAVE_IP_MREQN,1,[Define this if you have ip_mreqn in netinet/in.h])
-fi
-
-dnl ---------------------------------------------
-dnl restrict keyword finding (from gstreamer)
-dnl ---------------------------------------------
-restrict=""
-for restrict_keyword in restrict __restrict__ __restrict; do
- AC_MSG_CHECKING(for restrict keyword $restrict_keyword)
- AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[ void foo(char * $restrict_keyword p); ]])],[
- KEYWORD_FOUND=yes && AC_MSG_RESULT(yes) ],[
- KEYWORD_FOUND=no && AC_MSG_RESULT(no) ])
- if test "x$KEYWORD_FOUND" = xyes; then
- restrict="$restrict_keyword"
- break
- fi
-done
-if test "x$restrict" = x; then
- AC_MSG_ERROR(No restrict keyword found)
-fi
-AC_DEFINE_UNQUOTED(restrict, $restrict, [restrict keyword])
-
-dnl ---------------------------------------------
-dnl ASM ALIGN is power of two ?
-dnl Used by internal FFmpeg and Planar postprocess
-dnl ---------------------------------------------
-AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[ asm (".align 3"); ]])],
- AC_DEFINE([ASMALIGN_1SLN], [1], [define if '.align n' means alignment to (1<<n)-byte boundaries]),
- :)
-AH_BOTTOM([#ifdef ASMALIGN_1SLN
-# define ASMALIGN(ZEROBITS) ".align " #ZEROBITS "\n\t"
-#else
-# define ASMALIGN(ZEROBITS) ".align 1<<" #ZEROBITS "\n\t"
-#endif
-])
-
-dnl ---------------------------------------------
-dnl Some extra checks.
-dnl ---------------------------------------------
-
-AC_SYS_LARGEFILE
-AC_CHECK_LIB(posix4, sched_get_priority_min)
AC_CHECK_FUNCS([vsscanf sigaction sigset getpwuid_r nanosleep lstat memset readlink strchr va_copy])
-AC_CHECK_FUNCS([snprintf _snprintf], [some_snprintf="yes"; break])
-AC_CHECK_FUNCS([vsnprintf _vsnprintf], [some_vsnprintf="yes"; break])
-AC_CHECK_FUNCS([strcasecmp _stricmp], [some_strcasecmp="yes"; break])
-AC_CHECK_FUNCS([strncasecmp _strnicmp], [some_strncasecmp="yes"; break])
-if test "x$some_snprintf" != "xyes" -o \
- "x$some_vsnprintf" != "xyes" -o \
- "x$some_strcasecmp" != "xyes" -o \
- "x$some_strncasecmp" != "xyes"; then
- AC_MSG_ERROR([required function not found])
-fi
-AC_FUNC_FSEEKO
-AC_CHECK_HEADERS(assert.h byteswap.h malloc.h execinfo.h ucontext.h sys/mman.h sys/mixer.h libgen.h netdb.h dirent.h sys/times.h sys/ioctl.h sys/param.h alloca.h)
-AC_REPLACE_FUNCS(asprintf basename gettimeofday setenv strndup strpbrk strsep strtok_r timegm unsetenv)
-
-AC_LIBSOURCE(hstrerror.c)
-AC_LINK_IFELSE([#include <netdb.h>
-int main(void) {
- hstrerror(0);
-}], ac_cv_function_system_hstrerror="yes")
-AC_CHECK_LIB([resolv], [hstrerror], [
- ac_cv_function_system_hstrerror="yes"
- NET_LIBS="-lresolv $NET_LIBS"
-])
-AC_SUBST(NET_LIBS)
-if test "x$ac_cv_function_system_hstrerror" = "xyes"; then
- AC_DEFINE(HAVE_HSTRERROR, 1, [Define to 1 if you have 'hstrerror' in <netdb.h>])
-
-else
- AC_LIBOBJ(hstrerror)
-fi
-
-AC_LIBSOURCE(dirent_msvc.c)
-AC_CHECK_FUNC(opendir,
- [AC_DEFINE(HAVE_OPENDIR, 1, [Define to 1 if you have 'opendir' function])],
- [if test "x$SYS" = "xmingw32"; then
- AC_LIBOBJ(dirent_msvc)
- else
- AC_MSG_ERROR([dirent is needed (opendir, readdir, ...)])
- fi])
-
-AH_BOTTOM([/* include internal system specific header */
-#include "os_internal.h"])
+AC_CHECK_FUNCS([snprintf _snprintf], [have_required_function="yes"])
+ test x"$have_required_function" != x"yes" && AC_MSG_ERROR([required function not found])
+AC_CHECK_FUNCS([vsnprintf _vsnprintf], [have_required_function="yes"])
+ test x"$have_required_function" != x"yes" && AC_MSG_ERROR([required function not found])
+AC_CHECK_FUNCS([strcasecmp _stricmp], [have_required_function="yes"])
+ test x"$have_required_function" != x"yes" && AC_MSG_ERROR([required function not found])
+AC_CHECK_FUNCS([strncasecmp _strnicmp], [have_required_function="yes"])
+ test x"$have_required_function" != x"yes" && AC_MSG_ERROR([required function not found])
-dnl ---------------------------------------------
-dnl cflags and debug cflags
-dnl ---------------------------------------------
-
-AC_SUBST(DEBUG_CFLAGS)
-DEBUG_CFLAGS="-g -DDEBUG $CFLAGS"
-
-dnl dummy
-ASFLAGS="$ASFLAGS"
-AC_SUBST(ASFLAGS)
-
-dnl ---------------------------------------------
-dnl Check for some __attribute__ support needed
-dnl ---------------------------------------------
-
-CC_ATTRIBUTE_ALIGNED
-
-CC_ATTRIBUTE_VISIBILITY([protected], [visibility_export="protected"],
- [CC_ATTRIBUTE_VISIBILITY([default], [visibility_export="default"])]
-)
-
-if test "x$visibility_export" != "x"; then
- CC_FLAG_VISIBILITY([
- AC_DEFINE([EXPORTED], [__attribute__((visibility("default")))],
- [Mark a symbol as being exported if visibility is changed])
- VISIBILITY_FLAG="-fvisibility=hidden"
- ], [AC_DEFINE([EXPORTED], [], [Dummy mark as being exported])
- ])
-else
- AC_DEFINE([EXPORTED], [], [Dummy mark as being exported])
-fi
-
-AC_SUBST([VISIBILITY_FLAG])
-
-CC_ATTRIBUTE_SENTINEL
-CC_ATTRIBUTE_FORMAT
-CC_ATTRIBUTE_FORMAT_ARG
+AC_FUNC_FSEEKO
-AC_OPTIMIZATIONS
+AC_REPLACE_FUNCS([asprintf basename gettimeofday setenv strndup strpbrk strsep strtok_r timegm unsetenv])
+
+AC_LIBSOURCE([hstrerror.c])
+AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <netdb.h>]], [[hstrerror(0)]])],
+ [AC_DEFINE([HAVE_HSTRERROR], 1, [Define to 1 if you have 'hstrerror' in <netdb.h>])],
+ [AC_LIBOBJ([hstrerror])])
+
+AC_LIBSOURCE([dirent_msvc.c])
+AC_CHECK_FUNC([opendir],
+ [AC_DEFINE([HAVE_OPENDIR], 1, [Define to 1 if you have 'opendir' function])],
+ [if test x"$WIN32_SYS" = x"mingw32"; then
+ AC_LIBOBJ([dirent_msvc])
+ else
+ AC_MSG_ERROR([dirent is needed (opendir, readdir, ...)])
+ fi])
+
+AC_LIBSOURCE([timedlock.c])
+ac_save_LIBS="$LIBS" LIBS="$LIBS $PTHREAD_LIBS"
+AC_CHECK_FUNCS([pthread_mutex_timedlock],
+ [AC_DEFINE([HAVE_PTHREAD_MUTEX_TIMEDLOCK], 1, [Define to 1 if you have 'pthread_mutex_timedlock' in <pthread.h>])],
+ [AC_LIBOBJ([timedlock])])
+LIBS="$ac_save_LIBS"
-arch_x86="no"
-enable_armv4l="no"
-case "$host_or_hostalias" in
- i?86-* | k?-* | athlon-* | pentium*-)
- dnl enable x86 specific parts of the code
- dnl
- dnl all of this stuff needs gcc/gas; it uses gnu c compiler extensions
- dnl like the extended asm() or __attribute(__cdecl__), or other direct
- dnl mmx/sse/3dnow assembler instructions.
- dnl
- AC_DEFINE_UNQUOTED(ARCH_X86_32,,[Define this if you're running x86 architecture 32 bits])
- AC_DEFINE(FPM_INTEL,1,[Define to select libmad fixed point arithmetic implementation])
- arch_x86="yes"
- enable_impure_text="yes"
+dnl --------------------------
+dnl checks for system services
+dnl --------------------------
- case "$host_or_hostalias" in
- *-*-cygwin)
- LIBS="$LIBS @INTLLIBS@ -lkernel32"
+dnl Even as of 2.61, autoconf is not smart enough to find the X include
+dnl and library paths on Mac OS X, so seed them automatically if they're
+dnl not specified on the configure command-line.
+case "$host_os" in
+ darwin*)
+ test x"$x_includes" = x"NONE" && x_includes="/usr/X11R6/include"
+ test x"$x_libraries" = x"NONE" && x_libraries="/usr/X11R6/lib"
;;
- esac
- ;;
- x86_64-*)
- AC_DEFINE_UNQUOTED(ARCH_X86_64,,[Define this if you're running x86 architecture 64 bits])
- AC_DEFINE(FPM_64BIT,1,[Define to select libmad fixed point arithmetic implementation])
- arch_x86="yes"
- ;;
- powerpc-*-darwin*)
- dnl avoid ppc compilation crash
- AS="$CC"
- AC_DEFINE_UNQUOTED(FPM_PPC,,[Define to select libmad fixed point arithmetic implementation])
- AC_DEFINE_UNQUOTED(ARCH_PPC,,[Define this if you're running PowerPC architecture])
-
- AC_CHECK_HEADER([altivec.h], , enable_altivec=no)
-
- if test "x$enable_altivec" != xno; then
- AC_DEFINE_UNQUOTED(ENABLE_ALTIVEC,,[Define this if you want to use altivec on PowerPC CPUs])
- CFLAGS="$CFLAGS -faltivec -maltivec"
- LIBMPEG2_CFLAGS="$LIBMPEG2_CFLAGS -force_cpusubtype_ALL -faltivec -maltivec"
- fi
- ;;
- ppc-*-linux* | powerpc-*)
- dnl avoid ppc compilation crash
- AS="$CC"
- AC_DEFINE_UNQUOTED(FPM_PPC,,[Define to select libmad fixed point arithmetic implementation])
- AC_DEFINE_UNQUOTED(ARCH_PPC,,[Define this if you're running PowerPC architecture])
-
- AC_CHECK_HEADER([altivec.h], , enable_altivec=no)
-
- if test "x$enable_altivec" != xno; then
- AC_DEFINE_UNQUOTED(ENABLE_ALTIVEC,,[Define this if you have a Motorola 74xx CPU])
- CFLAGS="$CFLAGS -maltivec"
- LIBMPEG2_CFLAGS="$LIBMPEG2_CFLAGS -maltivec"
- fi
- ;;
- sparc*-*-linux*)
- if test "x$enable_vis" != xno; then
- has_vis=yes
- fi
-
- AC_DEFINE_UNQUOTED(FPM_SPARC,,[Define to select libmad fixed point arithmetic implementation])
- AC_DEFINE_UNQUOTED(ARCH_SPARC,,[Define this if you're running SPARC architecture])
- ;;
- sparc-*-solaris*)
- if test "$GCC" = yes; then
- case `$CC --version 2>/dev/null` in
- 1.*|2.*) ;;
- *)
- if test "x$enable_vis" != xno; then
- has_vis=yes
- fi
- ;;
- esac
-
- AC_DEFINE_UNQUOTED(FPM_SPARC,,[Define to select libmad fixed point arithmetic implementation])
- AC_DEFINE_UNQUOTED(ARCH_SPARC,,[Define this if you're running SPARC architecture])
- else
- AC_DEFINE_UNQUOTED(FPM_64BIT,,[Define to select libmad fixed point arithmetic implementation])
- fi
- ;;
- mips-*)
- AC_DEFINE_UNQUOTED(FPM_MIPS,,[Define to select libmad fixed point arithmetic implementation])
- ;;
- alphaev56-* | alpha* | ia64-* | hppa*-linux-*)
- AC_DEFINE_UNQUOTED(FPM_64BIT,,[Define to select libmad fixed point arithmetic implementation])
- ;;
- armv4l-*-linux*)
- AC_DEFINE_UNQUOTED(FPM_ARM,,[Define to select libmad fixed point arithmetic implementation])
- enable_armv4l="yes"
- ;;
- *)
- AC_DEFINE_UNQUOTED(FPM_DEFAULT,,[Define to select libmad fixed point arithmetic implementation])
- ;;
esac
-if test "x$has_vis" = "xyes"; then
- AC_DEFINE_UNQUOTED(ENABLE_VIS,,[Define this if you have Sun UltraSPARC CPU])
- case "$CFLAGS" in
- *-mcpu=*) ;;
- *) CFLAGS="$CFLAGS -mcpu=v9" ;;
- esac
-fi
-AM_CONDITIONAL(ENABLE_VIS, test "x$has_vis" = "xyes")
+dnl Check for Xwindows using the autoconf AC_PATH_XTRA macro, which is an
+dnl extension of AC_PATH_X that sets X_CFLAGS and X_LIBS. It will also set
+dnl X_EXTRA_LIBS and X_PRE_LIBS.
+AC_PATH_XTRA
+if test x"$no_x" != x"yes"; then
+ X_LIBS="$X_LIBS $X_PRE_LIBS -lX11 $X_EXTRA_LIBS"
+ AC_CHECK_LIB([Xext], [main],
+ [X_LIBS="$X_LIBS -lXext"], [AC_MSG_ERROR([libXext is required])],
+ [$X_LIBS])
+elif test x"$have_x" = x"no"; then
+ PKG_CHECK_MODULES([X], [x11 xext], [have_x=yes; no_x=no], [have_x=no; no_x=yes])
+fi
+
+dnl Check for XShm support (required for xine X support)
+if test x"$no_x" != x"yes"; then
+ ac_save_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $X_CFLAGS"
+ AC_CHECK_HEADERS([X11/extensions/XShm.h], [],
+ [AC_MSG_ERROR([XShm extension is required])],
+ [#include <X11/Xlib.h>])
+ CPPFLAGS="$ac_save_CPPFLAGS"
+ AC_DEFINE([HAVE_X11], 1, [Define this if you have X11R6 installed])
+fi
+AM_CONDITIONAL([HAVE_X11], [test x"$no_x" != x"yes"])
-if test "x$arch_x86" = "xyes"; then
- AC_DEFINE_UNQUOTED(ARCH_X86,,[Define this if you're running x86 architecture])
- AC_DEFINE_UNQUOTED(HAVE_MMX,,[Define this if you can compile MMX asm instructions])
-fi
-AM_CONDITIONAL(ARCH_X86, test "x$arch_x86" = "xyes")
-AM_CONDITIONAL(HAVE_MMX, test "x$arch_x86" = "xyes")
-
-case $host_os in
- darwin*)
- HOST_OS_DARWIN=1
- AC_DEFINE_UNQUOTED(HOST_OS_DARWIN, 1, [Define this if built on Mac OS X/Darwin])
- OBJCFLAGS="-D_INTL_REDIRECT_MACROS $OBJCFLAGS"
- ;;
-esac
-AM_CONDITIONAL(HOST_OS_DARWIN, test "x$HOST_OS_DARWIN" = "x1")
+dnl Locate libraries needed for X health check
+soname_script="/[[0-9]]$/! d; s%^.*/%%
+t q
+b
+:q
+q"
+x_lib_location="`ls -1 "${x_libraries:-/usr/local/lib}/libX11.$acl_cv_shlibext"* "${x_libraries:-/usr/lib}/libX11.$acl_cv_shlibext"* 2>/dev/null | sed -e \"${soname_script}\"`"
+AC_DEFINE_UNQUOTED([LIBX11_SO], "${x_lib_location:-libX11.$acl_cv_shlibext}", [The soname of libX11, needed for dlopen()])
+x_lib_location="`ls -1 "${x_libraries:-/usr/local/lib}/libXv.$acl_cv_shlibext"* "${x_libraries:-/usr/lib}/libXv.$acl_cv_shlibext"* 2>/dev/null | sed -e \"${soname_script}\"`"
+AC_DEFINE_UNQUOTED([LIBXV_SO], "${x_lib_location:-libXv.$acl_cv_shlibext}", [The soname of libXv, needed for dlopen()])
+
+dnl _FILE_OFFSET_BITS (AC_SYS_LARGEFILE; ac_cv_sys_file_offset_bits)
+dnl _LARGE_FILES (AC_SYS_LARGEFILE; ac_cv_sys_large_files)
+dnl _LARGEFILE_SOURCE (AC_FUNC_SEEKO; ac_cv_sys_largfile_source)
+dnl _LARGEFILE64_SOURCE (glibc transitional; not tested or used anywhere)
+AC_SYS_LARGEFILE
-dnl ---------------------------------------------
-dnl Set IMPURE_TEXT_LDFLAGS
-dnl ---------------------------------------------
+dnl Add macros to the compiler command line that are also in config.h for things
+dnl that do not #include config.h.
+dnl known: src/input/libreal, src/input/librtsp
+test x"$ac_cv_sys_file_offset_bits" != x"no" && CPPFLAGS="-D_FILE_OFFSET_BITS=64 $CPPFLAGS"
+test x"$ac_cv_sys_largefile_source" != x"no" && CPPFLAGS="-D_LARGEFILE_SOURCE $CPPFLAGS"
+test x"$ac_cv_sys_large_files" != x"" && test x"$ac_cv_sys_large_files" != x"no" && CPPFLAGS="-D_LARGE_FILES $CPPFLAGS"
-IMPURE_TEXT_LDFLAGS=""
-if test "x$enable_impure_text" = xyes; then
- case "$host_or_hostalias" in
- *solaris*)
- if test "$GCC" = yes; then
- IMPURE_TEXT_LDFLAGS="-mimpure-text"
- else
- IMPURE_TEXT_LDFLAGS="-z textoff"
- fi
- ;;
- *-darwin*)
- IMPURE_TEXT_LDFLAGS="-Wl,-read_only_relocs,warning"
- ;;
- esac
-fi
-AC_SUBST(IMPURE_TEXT_LDFLAGS)
-dnl ---------------------------------------------
-dnl HAVE_ARMV4L is currently used in libavcodec makefile.am
-dnl ---------------------------------------------
+dnl -------
+dnl Plugins
+dnl -------
-AM_CONDITIONAL(HAVE_ARMV4L, test "x$enable_armv4l" = "xyes")
+XINE_AUDIO_OUT_PLUGINS
+XINE_VIDEO_OUT_PLUGINS
+XINE_INPUT_PLUGINS
+XINE_DECODER_PLUGINS
dnl ---------------------------------------------
-dnl Use features of autoconf 2.61, but stay compatible
-dnl with older versions.
-dnl ---------------------------------------------
-
-if test "x$datarootdir" = "x"; then
- datarootdir='${datadir}'
- AC_SUBST(datarootdir)
-fi
-
-if test "x$docdir" = "x"; then
- docdir='${datarootdir}/doc/${PACKAGE}'
- AC_SUBST(docdir)
-fi
-
-if test "x$htmldir" = "x"; then
- htmldir='${docdir}'
- AC_SUBST(htmldir)
-fi
-
-dnl ---------------------------------------------
dnl XINE_ROOTDIR does not work if architecture independent files are
dnl installed to another place than architecture dependent files !!!
dnl ---------------------------------------------
-if test "x$prefix" = xNONE; then
- prefix="${ac_default_prefix}"
-fi
-if test "x$exec_prefix" = xNONE; then
- exec_prefix='${prefix}'
-fi
-
dnl
dnl installation directories and directories relative to prefix
dnl
@@ -2374,11 +982,11 @@ dnl use AC_SUBST for installation
dnl
makeexpand () {
- local i
- local j
- i="$1"
- while test "$i" != "$j"; do j="$i"; eval i="$j"; done
- echo "$i"
+ local i
+ local j
+ i="$1"
+ while test "$i" != "$j"; do j="$i"; eval i="$j"; done
+ echo "$i"
}
XINE_PLUGINDIR="$libdir/xine/plugins/$XINE_MAJOR.$XINE_MINOR.$XINE_SUB"
@@ -2388,36 +996,36 @@ XINE_REL_PLUGINDIR="`makeexpand "$XINE_PLUGINDIR"`"
XINE_REL_PLUGINDIR="`makeexpand "$XINE_REL_PLUGINDIR" | sed -e "s,^${prefix}/,,"`"
XINE_REL_FONTDIR="`makeexpand "$XINE_FONTDIR" | sed -e "s,^${prefix}/,,"`"
XINE_REL_LOCALEDIR="`makeexpand "$XINE_LOCALEDIR" | sed -e "s,^${prefix}/,,"`"
-if test "x$SYS" = "xmingw32" -o "x$SYS" = "xcygwin"; then
- dnl polish paths (MinGW runtime accepts both \ and / anyway)
- XINE_REL_PLUGINDIR="`echo "$XINE_REL_PLUGINDIR" | sed -e 's/\\//\\\\\\\\/g'`"
- XINE_REL_FONTDIR="`echo "$XINE_REL_FONTDIR" | sed -e 's/\\//\\\\\\\\/g'`"
- XINE_REL_LOCALEDIR="`echo "$XINE_REL_LOCALEDIR" | sed -e 's/\\//\\\\\\\\/g'`"
- dnl prefix in xine-config
- XINE_CONFIG_PREFIX="\$(cd \$(dirname \$0)/..; pwd)"
- dnl installation directories (in xine-config)
- XINE_PLUGINPATH="$XINE_CONFIG_PREFIX/$XINE_REL_PLUGINDIR"
- XINE_FONTPATH="$XINE_CONFIG_PREFIX/$XINE_REL_FONTDIR"
- XINE_LOCALEPATH="$XINE_CONFIG_PREFIX/$XINE_REL_LOCALEDIR"
- dnl runtime directories
- AC_DEFINE(XINE_PLUGINDIR,[xine_get_plugindir()],[Define this to plugins directory location])
- AC_DEFINE(XINE_FONTDIR,[xine_get_fontdir()],[Define this to osd fonts dir location])
- AC_DEFINE(XINE_LOCALEDIR,[xine_get_localedir()],[Path where catalog files will be.])
+if test "x$WIN32_SYS" = "xmingw32" -o "x$WIN32_SYS" = "xcygwin"; then
+ dnl polish paths (MinGW runtime accepts both \ and / anyway)
+ XINE_REL_PLUGINDIR="`echo "$XINE_REL_PLUGINDIR" | sed -e 's/\\//\\\\\\\\/g'`"
+ XINE_REL_FONTDIR="`echo "$XINE_REL_FONTDIR" | sed -e 's/\\//\\\\\\\\/g'`"
+ XINE_REL_LOCALEDIR="`echo "$XINE_REL_LOCALEDIR" | sed -e 's/\\//\\\\\\\\/g'`"
+ dnl prefix in xine-config
+ XINE_CONFIG_PREFIX="\$(cd \$(dirname \$0)/..; pwd)"
+ dnl installation directories (in xine-config)
+ XINE_PLUGINPATH="$XINE_CONFIG_PREFIX/$XINE_REL_PLUGINDIR"
+ XINE_FONTPATH="$XINE_CONFIG_PREFIX/$XINE_REL_FONTDIR"
+ XINE_LOCALEPATH="$XINE_CONFIG_PREFIX/$XINE_REL_LOCALEDIR"
+ dnl runtime directories
+ AC_DEFINE([XINE_PLUGINDIR], [xine_get_plugindir()], [Define this to plugins directory location])
+ AC_DEFINE([XINE_FONTDIR], [xine_get_fontdir()], [Define this to osd fonts dir location])
+ AC_DEFINE([XINE_LOCALEDIR], [xine_get_localedir()], [Path where catalog files will be.])
else
- dnl prefix in xine-config
- XINE_CONFIG_PREFIX="`makeexpand "${prefix}"`"
- dnl directories from xine-config and runtime directories
- XINE_PLUGINPATH="`makeexpand "$XINE_PLUGINDIR"`"
- XINE_FONTPATH="`makeexpand "$XINE_FONTDIR"`"
- XINE_LOCALEPATH="`makeexpand "$XINE_LOCALEDIR"`"
- dnl defining runtime directories
- AC_DEFINE_UNQUOTED(XINE_PLUGINDIR,"$XINE_PLUGINPATH",[Define this to plugins directory location])
- AC_DEFINE_UNQUOTED(XINE_FONTDIR,"$XINE_FONTPATH",[Define this to osd fonts dir location])
- AC_DEFINE_UNQUOTED(XINE_LOCALEDIR, "$XINE_LOCALEPATH",[Path where catalog files will be.])
-fi
-AC_DEFINE_UNQUOTED(XINE_REL_PLUGINDIR,"$XINE_REL_PLUGINDIR",[Define this to plugin directory relative to execution prefix])
-AC_DEFINE_UNQUOTED(XINE_REL_FONTDIR,"$XINE_REL_FONTDIR",[Define this to font directory relative to prefix])
-AC_DEFINE_UNQUOTED(XINE_REL_LOCALEDIR,"$XINE_REL_LOCALEDIR",[Define this to font directory relative to prefix])
+ dnl prefix in xine-config
+ XINE_CONFIG_PREFIX="`makeexpand "${prefix}"`"
+ dnl directories from xine-config and runtime directories
+ XINE_PLUGINPATH="`makeexpand "$XINE_PLUGINDIR"`"
+ XINE_FONTPATH="`makeexpand "$XINE_FONTDIR"`"
+ XINE_LOCALEPATH="`makeexpand "$XINE_LOCALEDIR"`"
+ dnl defining runtime directories
+ AC_DEFINE_UNQUOTED([XINE_PLUGINDIR], ["$XINE_PLUGINPATH"], [Define this to plugins directory location])
+ AC_DEFINE_UNQUOTED([XINE_FONTDIR], ["$XINE_FONTPATH"], [Define this to osd fonts dir location])
+ AC_DEFINE_UNQUOTED([XINE_LOCALEDIR], ["$XINE_LOCALEPATH"], [Path where catalog files will be.])
+fi
+AC_DEFINE_UNQUOTED([XINE_REL_PLUGINDIR], ["$XINE_REL_PLUGINDIR"], [Define this to plugin directory relative to execution prefix])
+AC_DEFINE_UNQUOTED([XINE_REL_FONTDIR], ["$XINE_REL_FONTDIR"], [Define this to font directory relative to prefix])
+AC_DEFINE_UNQUOTED([XINE_REL_LOCALEDIR], ["$XINE_REL_LOCALEDIR"], [Define this to font directory relative to prefix])
AC_SUBST(XINE_CONFIG_PREFIX)
AC_SUBST(XINE_PLUGINPATH)
AC_SUBST(XINE_FONTPATH)
@@ -2428,7 +1036,7 @@ AC_SUBST(XINE_LOCALEDIR)
dnl Where aclocal m4 files should be installed
XINE_ACFLAGS="-I `makeexpand "${datarootdir}/aclocal"`"
-AC_DEFINE_UNQUOTED(XINE_ACFLAGS, "$XINE_ACFLAGS", [Path where aclocal m4 files will be.])
+AC_DEFINE_UNQUOTED([XINE_ACFLAGS], ["$XINE_ACFLAGS"], [Path where aclocal m4 files will be.])
AC_SUBST(XINE_ACFLAGS)
dnl Where architecture independent data (e.g. logo) will/should be installed
@@ -2441,62 +1049,6 @@ AC_SUBST(XINE_SCRIPTPATH)
dnl ---------------------------------------------
-dnl Some informations about xine-lib compilation
-dnl ---------------------------------------------
-
-XINE_BUILD_CC="`$CC -v 2>&1 | tail -1 2>/dev/null`"
-XINE_BUILD_OS="`uname -s -r -m`"
-XINE_BUILD_DATE="`date \"+%a %d %b %Y %T\"`"
-AC_SUBST(XINE_BUILD_CC)
-AC_SUBST(XINE_BUILD_OS)
-AC_SUBST(XINE_BUILD_DATE)
-
-
-dnl ---------------------------------------------
-dnl For win32 libraries location, needed by libw32dll.
-dnl ---------------------------------------------
-
-AC_ARG_WITH([w32-path],
- AS_HELP_STRING([--with-w32-path=path], [location of Win32 binary codecs]),
- [w32_path="$withval"], [w32_path="/usr/lib/codecs"])
-AC_SUBST(w32_path)
-
-AC_ARG_ENABLE([w32dll],
- AS_HELP_STRING([--disable-w32dll], [Disable Win32 DLL support]),
- , [enable_w32dll=$with_gnu_as])
-
-case $host in
- *-mingw* | *-cygwin)
- enable_w32dll="no" ;;
- i?86-* | k?-* | athlon-* | pentium*-)
- if test "x$enable_w32dll" != "xno"; then
- CC_PROG_AS
- fi
- test "x$enable_w32dll" = "x" && \
- enable_w32dll="$with_gnu_as"
- ;;
- *)
- enable_w32dll="no" ;;
-esac
-
-if test "x$enable_w32dll" = "xyes" && \
- test "x$with_gnu_as" = "xno"; then
-
- AC_MSG_ERROR([You need GNU as to enable Win32 codecs support])
-fi
-
-AM_CONDITIONAL(HAVE_W32DLL, test "x$enable_w32dll" != "xno")
-
-
-dnl ---------------------------------------------
-dnl some include paths ( !!! DO NOT REMOVE !!! )
-dnl ---------------------------------------------
-
-INCLUDES='-I$(top_srcdir) -I$(top_builddir)/include -I$(top_srcdir)/include -I$(top_srcdir)/src -I$(top_builddir)/src/xine-engine -I$(top_srcdir)/src/xine-engine -I$(top_srcdir)/src/xine-utils $(INTLDIR) -I$(top_builddir)/src/input -I$(top_srcdir)/src/input $(WIN32_CPPFLAGS) -I$(top_builddir)/lib -I$(top_srcdir)/lib'
-AC_SUBST(INCLUDES)
-
-
-dnl ---------------------------------------------
dnl Get where .m4 should be installed.
dnl ---------------------------------------------
@@ -2517,89 +1069,37 @@ dnl ;;
dnl esac
dnl fi
AC_SUBST(ACLOCAL_DIR)
-AM_CONDITIONAL([INSTALL_M4],[test "x$ACLOCAL_DIR" != "x"])
+AM_CONDITIONAL([INSTALL_M4], [test x"$ACLOCAL_DIR" != x""])
-dnl ---------------------------------------------
-dnl It seems automake 1.5 don't take care about this script
-dnl ---------------------------------------------
-
-if test ! -z "$am_depcomp"; then
- DEPCOMP="depcomp"
-fi
-AC_SUBST(DEPCOMP)
-
-
-dnl ---------------------------------------------
-dnl Check for documentation formatting tool
-dnl ---------------------------------------------
-
-AC_CHECK_PROG(SGMLTOOLS, sgmltools, sgmltools, no)
-AM_CONDITIONAL([HAVE_SGMLTOOLS], [test "$SGMLTOOLS" != "no"])
-
-AC_CHECK_PROG(FIG2DEV, fig2dev, fig2dev, no)
-AM_CONDITIONAL([HAVE_FIG2DEV], [test "$FIG2DEV" != "no"])
-
-dnl ---------------------------------------------
-dnl Newest automake workaround
-dnl ---------------------------------------------
-
-AC_SUBST(mkdir_p)
-if test -n "$ac_aux_dir"; then
- case "$ac_aux_dir" in
- /*) MKINSTALLDIRS="$ac_aux_dir/install-sh -d" ;;
- *) MKINSTALLDIRS="\$(top_builddir)/$ac_aux_dir/install-sh -d" ;;
- esac
-else
- MKINSTALLDIRS="\$(top_srcdir)/install-sh -d"
-fi
-AC_SUBST(MKINSTALLDIRS)
-
dnl this is an internal function we should not use, but
dnl as long as neither autoconf nor automake offer an A[CM]_PROG_OBJC
dnl check we will have to call it
_AM_DEPENDENCIES([OBJC])
-AM_CONDITIONAL([BUILD_DMX_IMAGE], [test "x$have_imagemagick" = "xyes" -o "x$no_gdkpixbuf" != "xyes"])
-dnl Important warnings we _don't_ want to skip
-dnl Don't put these under conditional for optimisations, because these
-dnl need always to be enabled.
-CC_CHECK_CFLAGS([-Wformat=2], [wformat="-Wformat=2"],
- [CC_CHECK_CFLAGS([-Wformat], [wformat="-Wformat"])])
+dnl ---------------------------------------------
+dnl some include paths ( !!! DO NOT REMOVE !!! )
+dnl ---------------------------------------------
-test "x$wformat" != "x" && \
- CC_CHECK_CFLAGS([-Wno-format-zero-length], [wformat="$wformat -Wno-format-zero-length"])
+INCLUDES='-I$(top_srcdir) -I$(top_builddir)/include -I$(top_srcdir)/include -I$(top_srcdir)/src -I$(top_builddir)/src/xine-engine -I$(top_srcdir)/src/xine-engine -I$(top_srcdir)/src/xine-utils $(INTLDIR) -I$(top_builddir)/src/input -I$(top_srcdir)/src/input $(WIN32_INCLUDES) -I$(top_builddir)/lib -I$(top_srcdir)/lib'
+AC_SUBST(INCLUDES)
-CC_CHECK_CFLAGS([-Wmissing-format-attribute], [wformat="$wformat -Wmissing-format-attribute"])
-warnflags="$warnflags $wformat"
-dnl This *has* to stay at the end as it can break some autoconf tests.
-CC_CHECK_CFLAGS([-Werror-implicit-function-declaration], [warnflags="$warnflags -Werror-implicit-function-declaration"])
+dnl Common cflags for all platforms
+CFLAGS="$UNIVERSAL_CFLAGS \$(MULTIPASS_CFLAGS) $miscflags $warnflags $CFLAGS"
+LDFLAGS="$UNIVERSAL_LDFLAGS $LDFLAGS"
+OBJCFLAGS="$UNIVERSAL_CFLAGS $miscflags $warnflags $OBJCFLAGS"
-CC_CHECK_CFLAGS([-Wstrict-aliasing=2], [warnflags="$warnflags -Wstrict-aliasing=2"],
- [CC_CHECK_CFLAGS([-Wstrict-aliasing], [warnflags="$warnflags -Wstrict-aliasing"])])
-
-case $host in
- dnl FreeBSD (et al.) does not complete linking for shared objects when pthreads
- dnl are requested, as different implementations are present; to avoid problems
- dnl use -Wl,-z,defs only for those platform not behaving this way.
- *-freebsd*) ;;
- *)
- AC_TRY_LDFLAGS([-Wl,-z,defs], [NOUNDEF="-Wl,-z,defs"])
- ;;
-esac
-AC_SUBST([NOUNDEF])
-dnl Common cflags for all platforms
-CFLAGS="-D_REENTRANT -D_FILE_OFFSET_BITS=64 -DXINE_COMPILE \$(MULTIPASS_CFLAGS) $warnflags $CFLAGS"
-DEBUG_CFLAGS="-D_REENTRANT -D_FILE_OFFSET_BITS=64 -DXINE_COMPILE $DEBUG_CFLAGS"
+dnl Some informations about xine-lib compilation for xine-config
+XINE_BUILD_CC="`$CC -v 2>&1 | tail -1 2>/dev/null`"
+XINE_BUILD_OS="`uname -s -r -m`"
+XINE_BUILD_DATE="`date \"+%a %d %b %Y %T\"`"
+AC_SUBST(XINE_BUILD_CC)
+AC_SUBST(XINE_BUILD_OS)
+AC_SUBST(XINE_BUILD_DATE)
-if test "x$enable_debug" = "xyes"; then
- CFLAGS="$CFLAGS -DDEBUG"
-else
- CFLAGS="$CFLAGS -DNDEBUG"
-fi
dnl ---------------------------------------------
dnl Output configuration files
@@ -2612,10 +1112,19 @@ doc/man/Makefile
doc/man/en/Makefile
doc/hackersguide/Makefile
doc/faq/Makefile
+doc/Doxyfile
+contrib/Makefile
+contrib/gsm610/Makefile
+contrib/libdca/Makefile
+contrib/libmad/Makefile
+contrib/libmpcdec/Makefile
+contrib/libxdg-basedir/Makefile
+contrib/nosefart/Makefile
include/Makefile
include/xine.h
lib/Makefile
m4/Makefile
+m4/gettext/Makefile
misc/Makefile
misc/SlackBuild
misc/build_rpms.sh
@@ -2643,23 +1152,10 @@ src/input/vcd/libcdio/image/Makefile
src/input/vcd/libvcd/Makefile
src/input/vcd/libvcd/libvcd/Makefile
src/liba52/Makefile
-src/libdts/Makefile
src/libfaad/Makefile
src/libfaad/codebook/Makefile
src/libffmpeg/Makefile
-src/libffmpeg/libavcodec/Makefile
-src/libffmpeg/libavcodec/armv4l/Makefile
-src/libffmpeg/libavcodec/i386/Makefile
-src/libffmpeg/libavcodec/mlib/Makefile
-src/libffmpeg/libavcodec/alpha/Makefile
-src/libffmpeg/libavcodec/ppc/Makefile
-src/libffmpeg/libavcodec/sparc/Makefile
-src/libffmpeg/libavcodec/libpostproc/Makefile
-src/libffmpeg/libavutil/Makefile
-src/libmad/Makefile
src/libmpeg2/Makefile
-src/libmusepack/Makefile
-src/libmusepack/musepack/Makefile
src/libspudec/Makefile
src/libspucc/Makefile
src/libspucmml/Makefile
@@ -2673,8 +1169,6 @@ src/libw32dll/qtx/Makefile
src/libw32dll/qtx/qtxsdk/Makefile
src/libxinevdec/Makefile
src/libxineadec/Makefile
-src/libxineadec/gsm610/Makefile
-src/libxineadec/nosefart/Makefile
src/libreal/Makefile
src/post/Makefile
src/post/planar/Makefile
@@ -2695,6 +1189,7 @@ src/video_out/vidix/Makefile
src/video_out/vidix/drivers/Makefile
src/xine-utils/Makefile
src/xine-engine/Makefile
+src/vdr/Makefile
win32/Makefile
win32/include/Makefile])
AC_CONFIG_COMMANDS([default],[[chmod +x ./misc/SlackBuild ./misc/build_rpms.sh ./misc/relchk.sh]],[[]])
@@ -2713,442 +1208,12 @@ dnl there have no trailing slash.
dnl ---------------------------------------------
dnl Note: Brackets [] must be doubled as they are treated as m4 macro quotes.
-cat libtool | sed -e '/sys_lib_search_path_spec=/s/\/\([[ "]]\)/\1/g' > libtool.tmp
-mv -f libtool.tmp libtool
-chmod +x libtool
-
-dnl ---------------------------------------------
-dnl Some infos:
-dnl ---------------------------------------------
-
-echo "xine-lib summary:"
-echo "----------------"
-
-dnl Input
-echo " * input plugins:"
-echo " - file - net"
-echo " - stdin_fifo - rtp"
-echo " - http - mms"
-echo " - pnm - rtsp"
-echo " - dvb"
-if test "x$external_dvdnav" = "xyes"; then
- echo " - dvd (external libs)"
-else
- echo " - dvd (internal libs)"
-fi
-if test "x$have_cdrom_ioctls" = "xyes"; then
- if test "x$enable_vcd" = "xyes"; then
- if test "x$internal_vcdnav" = "xno"; then
- echo " - vcd (external libs)"
- else
- echo " - vcd (internal libs)"
- fi
- fi
- echo " - vcdo"
- echo " - cdda"
-fi
-if test "x$no_gnome_vfs" = "xno"; then
- echo " - gnome-vfs"
-fi
-if test "x$have_v4l" = "xyes"; then
- echo " - v4l"
-fi
-if test "x$have_libsmbclient" = "xyes"; then
- echo " - smbclient"
-fi
-echo ""
-
-dnl Demuxers
-echo " * demultiplexer plugins:"
-echo " - avi - mpeg"
-echo " - mpeg_block - mpeg_audio"
-echo " - mpeg_elem - mpeg_pes"
-echo " - mpeg_ts - qt/mpeg-4"
-echo " - film - roq"
-echo " - fli - smjpeg"
-echo " - idcin - wav"
-echo " - wc3 mve - voc"
-echo " - vqa - aiff"
-echo " - cdda - snd/au"
-echo " - yuv4mpeg2 - real/realaudio"
-echo " - ea wve - raw dv"
-echo " - interplay mve - psx str"
-echo " - ws aud - pva"
-echo " - vox - nsf"
-echo " - nsv - 4xm"
-echo " - FLAC - aac"
-echo " - iff - matroska"
-echo " - vmd - flv"
-if test "x$enable_asf" = "xyes"; then
- echo " - asf"
-fi
-if test "x$have_vorbis" = "xyes"; then
- echo " - ogg"
-fi
-if test "x$have_libmng" = "xyes"; then
- echo " - mng"
-fi
-if test "x$enable_modplug" != x"no"; then
- echo " - mod"
-fi
-if test "x$have_libflac" = "xyes"; then
- echo " - FLAC (with libFLAC)"
-fi
-if test "x$have_wavpack" = "xyes"; then
- echo " - WavPack"
-fi
-if test "x$enable_a52dec" = "xyes"; then
- if test "x$have_a52" = "xyes"; then
- echo " - ac3 (external library)"
- else
- echo " - ac3 (internal library)"
- fi
-fi
-echo ""
-
-dnl video decoders
-echo " * video decoder plugins:"
-echo " - MPEG 1,2 - Amiga Bitplane"
-echo " - Raw RGB - Raw YUV"
-if test "x$with_external_ffmpeg" = "xyes"; then
- echo " - ffmpeg (external library):"
+if test x"$enable_macosx_universal" = x"no"; then
+ cat libtool | sed -e '/sys_lib_search_path_spec=/s/\/\([[ "]]\)/\1/g' > libtool.tmp
else
- echo " - ffmpeg (internal library):"
-fi
-echo " - MPEG-4 (ISO, Microsoft, DivX*, XviD)"
-echo " - Creative YUV - Motion JPEG"
-echo " - Cinepak - MS Video-1"
-echo " - FLI/FLC - MS RLE"
-echo " - Id RoQ - Id Cin"
-echo " - Apple Graphics - Apple Video"
-echo " - Apple Animation - Interplay Video"
-echo " - Westwood VQA - Origin Xan"
-echo " - H.263 - Intel Indeo 3"
-echo " - SVQ1 - SVQ3"
-echo " - Real Video 1.0 - Real Video 2.0"
-echo " - 4X Video - Sierra Video"
-echo " - Asus v1/v2 - HuffYUV"
-echo " - On2 VP3 - DV"
-echo " - 8BPS - Duck TrueMotion v1"
-echo " - ATI VCR1 - Flash Video"
-echo " - ZLIB - MSZH"
-if test "x$have_dxr3" = "xyes"; then
- echo " - dxr3_video"
-fi
-if test "x$enable_w32dll" = "xyes"; then
- echo " - w32dll"
-fi
-if test "x$have_imagemagick" = "xyes"; then
- echo " - image"
-fi
-if test x"no_gdkpixbuf" != "xyes"; then
- echo " - gdk-pixbuf"
-fi
-if test "x$have_theora" = "xyes"; then
- echo " - theora"
-fi
-echo ""
-
-dnl audio decoders
-echo " * audio decoder plugins:"
-echo " - GSM 06.10"
-echo " - linear PCM - Nosefart (NSF)"
-if test "x$with_external_ffmpeg" = "xyes"; then
- echo " - ffmpeg (external library):"
-else
- echo " - ffmpeg (internal library):"
-fi
-echo " - Windows Media Audio v1/v2"
-echo " - DV - logarithmic PCM"
-echo " - 14k4 - 28k8"
-echo " - MS ADPCM - IMA ADPCM"
-echo " - XA ADPCM - Game DPCM/ADPCM"
-echo " - Mace 3:13 - Mace 6:1"
-echo " - FLAC"
-if test "x$have_libflac" = "xyes"; then
- echo " - FLAC (with libFLAC)"
-fi
-if test "x$have_vorbis" = "xyes"; then
- echo " - vorbis"
-fi
-if test "x$have_speex" = "xyes"; then
- echo " - speex"
-fi
-if test "x$enable_w32dll" = "xyes"; then
- echo " - w32dll"
-fi
-if test "x$enable_faad" = "xyes"; then
- echo " - faad"
-fi
-if test "x$enable_libmad" = "xyes"; then
- if test "x$have_mad" = "xyes"; then
- echo " - MAD (MPG 1/2/3) (external library)"
- else
- echo " - MAD (MPG 1/2/3) (internal library)"
- fi
-fi
-if test "x$enable_libdts" = "xyes"; then
- if test "x$have_dts" = "xyes"; then
- echo " - DTS (external library)"
- else
- echo " - DTS (internal library)"
- fi
-fi
-if test "x$enable_a52dec" = "xyes"; then
- if test "x$have_a52" = "xyes"; then
- echo " - A52/ra-dnet (external library)"
- else
- echo " - A52/ra-dnet (internal library)"
- fi
-fi
-if test "x$enable_musepack" != "xno"; then
- if test "x$have_mpcdec" = "xyes"; then
- echo " - MusePack (external library)"
- else
- echo " - MusePack (internal library)"
- fi
-fi
-if test "x$have_wavpack" = "xyes"; then
- echo " - WavPack"
-fi
-echo ""
-
-dnl spu decoders
-echo " * subtitle decoder plugins:"
-echo " - spu - spucc"
-echo " - spucmml - sputext"
-echo " - spudvb"
-if test "x$have_dxr3" = "xyes"; then
- echo " - dxr3_spu"
-fi
-echo ""
-
-dnl post plugins
-echo " * post effect plugins:"
-echo " * planar video effects:"
-echo " - invert - expand"
-echo " - eq - eq2"
-echo " - boxblur - denoise3d"
-echo " - unsharp - tvtime"
-echo " * SFX:"
-echo " - goom - oscope"
-echo " - fftscope - mosaico"
-echo ""
-
-dnl Video plugins
-echo " * video driver plugins:"
-if test "x$no_x" != "xyes"; then
- echo " - XShm (X11 shared memory)"
- dnl synfb
- if test "x$enable_syncfb" != "xno"; then
- echo " - SyncFB (for Matrox G200/G400 cards)"
- fi
- dnl Xv
- if test "x$ac_have_xv" = "xyes"; then
- if test "x$ac_have_xv_static" = "xyes"; then
- echo " - Xv (XVideo *static*)"
- else
- echo " - Xv (XVideo *shared*)"
- fi
- fi
- dnl XxMC
- if test "x$ac_have_xxmc" = "xyes"; then
- if test "x$ac_have_vldxvmc_h" = "xyes"; then
- echo " - XxMC (XVideo extended motion compensation)"
- else
- echo " - XxMC (XVideo motion compensation - vld extensions DISABLED)"
- fi
- fi
- dnl XvMC
- if test "x$ac_have_xvmc" = "xyes"; then
- echo " - XvMC (XVideo motion compensation)"
- fi
- if test "x$ac_have_opengl" = "xyes" -a "x$ac_have_glut" = "xyes" -o \
- x$"ac_have_opengl" = "xyes" -a "x$ac_have_glu" = "xyes"; then
- echo " - OpenGL"
- fi
- if test "x$ac_have_sunfb" = "xyes"; then
- if test "x$ac_have_sundga" = "xyes"; then
- echo " - PGX64 (for Sun XVR100/PGX64/PGX24 cards)"
- echo " - PGX32 (for Sun PGX32 cards)"
- fi
- fi
-fi
-if test "x$have_xcb" = "xyes"; then
- dnl xcb-shm
- if test "x$have_xcbshm" = "xyes"; then
- echo " - xcb-shm (X shared memory using XCB)"
- fi
- dnl xcb-xv
- if test "x$have_xcbxv" = "xyes"; then
- echo " - xcb-xv (XVideo using XCB)"
- fi
-fi
-if test "x$no_aalib" != "xyes"; then
- echo " - aa (Ascii ART)"
-fi
-if test "x$have_caca" = "xyes"; then
- echo " - caca (Color AsCii Art)"
-fi
-if test "x$have_fb" = "xyes"; then
- echo " - fb (Linux framebuffer device)"
-fi
-if test "x$have_sdl" = "xyes"; then
- echo " - sdl (Simple DirectMedia Layer)"
-fi
-if test "x$have_libstk" = "xyes"; then
- echo " - stk (Libstk Set-top Toolkit)"
-fi
-if test "x$have_directfb" = "xyes"; then
- echo " - directfb (DirectFB driver)"
-fi
-if test "x$have_dxr3" = "xyes"; then
- if test "x$have_encoder" = "xyes"; then
- echo " - dxr3 (Hollywood+ and Creative dxr3, both mpeg and non-mpeg video)"
- else
- echo " - dxr3 (Hollywood+ and Creative dxr3, mpeg video only)"
- fi
-fi
-if test "x$enable_vidix" = "xyes"; then
- echo $ECHO_N " - vidix ("
-
- if test "x$no_x" != "xyes"; then
- echo $ECHO_N "X11"
- if test "x$have_fb" = "xyes"; then
- echo $ECHO_N " and "
- fi
- fi
-
- if test "x$have_fb" = "xyes"; then
- echo $ECHO_N "framebuffer"
- fi
-
- echo $ECHO_N " support"
-
- if test "x$enable_dha_kmod" = "xyes"; then
- echo " with dhahelper)"
- else
- echo ")"
- fi
-fi
-if test "x$have_directx" = "xyes"; then
- echo " - directx (DirectX video driver)"
-fi
-if test "x$have_macosx_video" = "xyes"; then
- echo " - Mac OS X OpenGL"
-fi
-
-echo ""
-
-dnl Audio plugins
-echo " * audio driver plugins:"
-if test "x$have_ossaudio" = "xyes"; then
- echo " - oss (Open Sound System)"
-fi
-if test "x$have_alsa" = "xyes"; then
- echo " - alsa"
-fi
-if test "x$have_esound" = "xyes"; then
- echo " - esd (Enlightened Sound Daemon)"
-fi
-if test "x$no_arts" != "xyes"; then
- echo " - arts (aRts - KDE soundserver)"
-fi
-if test "x$no_fusionsound" != "xyes"; then
- echo " - fusionsound (FusionSound driver)"
-fi
-if test "x$have_sunaudio" = "xyes"; then
- echo " - sun ()"
-fi
-if test "x$am_cv_have_irixal" = xyes; then
- echo " - irixal (Irix audio library)"
-fi
-if test "x$have_directx" = "xyes"; then
- echo " - directx (DirectX audio driver)"
-fi
-if test "x$have_coreaudio" = "xyes"; then
- echo " - CoreAudio (Mac OS X audio driver)"
-fi
-if test "x$have_pulseaudio" = "xyes"; then
- echo " - pulseaudio sound server"
-fi
-if test "x$have_jack" = "xyes"; then
- echo " - Jack"
-fi
-echo "---"
-
-
-dnl ---------------------------------------------
-dnl some user warnings
-dnl ---------------------------------------------
-
-dnl some levels of variable expansion to get final install paths
-final_libdir="`eval eval eval eval echo $libdir`"
-final_bindir="`eval eval eval eval echo $bindir`"
-
-if test -r /etc/ld.so.conf && ! grep -x "$final_libdir" /etc/ld.so.conf >/dev/null ; then
- if test "$final_libdir" != "/lib" -a "$final_libdir" != "/usr/lib" ; then
- if ! echo "$LD_LIBRARY_PATH" | egrep "(:|^)$final_libdir(/?:|/?$)" >/dev/null ; then
- echo
- echo "****************************************************************"
- echo "xine-lib will be installed to $final_libdir"
- echo
- echo "This path is not mentioned among the linker search paths in your"
- echo "/etc/ld.so.conf. This means it is possible that xine-lib will"
- echo "not be found when you try to compile or run a program using it."
- echo "If this happens, you should add $final_libdir to"
- echo "the environment variable LD_LIBRARY_PATH like that:"
- echo
- echo "export LD_LIBRARY_PATH=$final_libdir:\$LD_LIBRARY_PATH"
- echo
- echo "Alternatively you can add a line \"$final_libdir\""
- echo "to your /etc/ld.so.conf."
- echo "****************************************************************"
- echo
- fi
- fi
-fi
-
-if ! echo "$PATH" | egrep "(:|^)$final_bindir(/?:|/?$)" >/dev/null ; then
- echo
- echo "****************************************************************"
- echo "xine-config will be installed to $final_bindir"
- echo
- echo "This path is not in your search path. This means it is possible"
- echo "that xine-config will not be found when you try to compile a"
- echo "program using xine-lib. This will result in build failures."
- echo "If this happens, you should add $final_bindir to"
- echo "the environment variable PATH like that:"
- echo
- echo "export PATH=$final_bindir:\$PATH"
- echo
- echo "Note that this is only needed for compilation. It is not needed"
- echo "to have xine-config in your search path at runtime. (Although"
- echo "it will not cause any harm either.)"
- echo "****************************************************************"
- echo
+ cat libtool | sed -e 's,sys_lib_search_path_spec=.*$,sys_lib_search_path_spec=\"/Developer/SDKs/MacOSX10.4u.sdk/usr/lib\",' > libtool.tmp
fi
+mv -f libtool.tmp libtool
+chmod +x libtool
-dnl warn if no X11 plugins will be built
-if test "x$no_x" = "xyes"; then
- case $host in
- *mingw*|*-cygwin) ;;
- *-darwin*) ;;
- *)
- echo
- echo "****************************************************************"
- echo "WARNING! No X11 output plugins will be built."
- echo
- echo "For some reason, the requirements for building the X11 video"
- echo "output plugins are not met. That means, that you will NOT be"
- echo "able to use the resulting xine-lib to watch videos in a window"
- echo "on any X11-based display (e.g. your desktop)."
- echo
- echo "If this is not what you want, provide the necessary X11 build"
- echo "dependencies (usually done by installing a package called"
- echo "XFree86-devel or similar) and run configure again."
- echo "****************************************************************"
- echo
- ;;
- esac
-fi
+XINE_LIB_SUMMARY
diff --git a/contrib/Makefile.am b/contrib/Makefile.am
new file mode 100644
index 000000000..6e259a4a3
--- /dev/null
+++ b/contrib/Makefile.am
@@ -0,0 +1,153 @@
+SUBDIRS = libmpcdec libxdg-basedir libdca nosefart gsm610 libmad
+
+srcdir = $(shell cd @srcdir@; pwd)
+
+ffmpeg_builder = $(srcdir)/ffmpeg-universal.sh
+
+if ENABLE_DXR3
+dxr3encoder = --enable-encoder=mpeg1video
+endif
+
+if FFMPEG_DISABLE_UNCOMMON_CODECS
+disable_uncommon_codecs = \
+ --disable-decoder=aasc --disable-decoder=asv1 --disable-decoder=asv2 --disable-decoder=avs \
+ --disable-decoder=cscd --disable-decoder=cyuv --disable-decoder=dvvideo --disable-decoder=eightbps \
+ --disable-decoder=flic --disable-decoder=flv --disable-decoder=fourxm --disable-decoder=fraps \
+ --disable-decoder=huffyuv --disable-decoder=idcin --disable-decoder=interplay_video --disable-decoder=kmvc \
+ --disable-decoder=loco --disable-decoder=mmvideo --disable-decoder=nuv --disable-decoder=qdraw \
+ --disable-decoder=qpeg --disable-decoder=roq --disable-decoder=rpza --disable-decoder=smacker \
+ --disable-decoder=smc --disable-decoder=snow --disable-decoder=truemotion1 --disable-decoder=truemotion2 \
+ --disable-decoder=tscc --disable-decoder=ulti --disable-decoder=vcr1 --disable-decoder=vmdvideo \
+ --disable-decoder=wnv1 --disable-decoder=xan_wc3 --disable-decoder=xl --disable-decoder=zmbv \
+ --disable-decoder=alac --disable-decoder=amr_nb --disable-decoder=amr_wb --disable-decoder=libgsm \
+ --disable-decoder=mace3 --disable-decoder=mace6 --disable-decoder=shorten --disable-decoder=smackaud \
+ --disable-decoder=truespeech --disable-decoder=tta --disable-decoder=vmdaudio --disable-decoder=pcm_alaw \
+ --disable-decoder=pcm_mulaw --disable-decoder=pcm_s8 --disable-decoder=pcm_s16be --disable-decoder=pcm_s16le \
+ --disable-decoder=pcm_s24be --disable-decoder=pcm_s24daud --disable-decoder=pcm_s24le --disable-decoder=pcm_s32be \
+ --disable-decoder=pcm_s32le --disable-decoder=pcm_u8 --disable-decoder=pcm_u16be --disable-decoder=pcm_u16le \
+ --disable-decoder=pcm_u24be --disable-decoder=pcm_u24le --disable-decoder=pcm_u32be --disable-decoder=pcm_u32le \
+ --disable-decoder=interplay_dpcm --disable-decoder=roq_dpcm --disable-decoder=sol_dpcm --disable-decoder=vqa \
+ --disable-decoder=xan_dpcm --disable-decoder=adpcm_4xm --disable-decoder=adpcm_ct --disable-decoder=adpcm_ea \
+ --disable-decoder=adpcm_ima_dk3 --disable-decoder=adpcm_ima_dk4 --disable-decoder=adpcm_ima_qt \
+ --disable-decoder=adpcm_ima_smjpeg --disable-decoder=adpcm_ima_wav --disable-decoder=adpcm_ima_ws \
+ --disable-decoder=adpcm_ms --disable-decoder=adpcm_sbpro_2 --disable-decoder=adpcm_sbpro_3 \
+ --disable-decoder=adpcm_sbpro_4 --disable-decoder=adpcm_xa --disable-decoder=adpcm_yamaha
+endif
+
+if FFMPEG_DISABLE_POPULAR_CODECS
+disable_popular_codecs = \
+ --disable-decoder=cinepak --disable-decoder=flashsv --disable-decoder=h261 --disable-decoder=h263 \
+ --disable-decoder=h263i --disable-decoder=h264 --disable-decoder=indeo2 --disable-decoder=indeo3 \
+ --disable-decoder=mjpeg --disable-decoder=mjpegb --disable-decoder=mpeg1video --disable-decoder=mpeg2video \
+ --disable-decoder=mpeg4 --disable-decoder=mpegvideo --disable-decoder=msmpeg4v1 --disable-decoder=msmpeg4v2 \
+ --disable-decoder=msmpeg4v3 --disable-decoder=msrle --disable-decoder=msvideo1 --disable-decoder=qtrle \
+ --disable-decoder=rv10 --disable-decoder=rv20 --disable-decoder=svq1 --disable-decoder=svq3 --disable-decoder=vc1 \
+ --disable-decoder=vp3 --disable-decoder=vp5 --disable-decoder=vp6 --disable-decoder=vp6f --disable-decoder=wmv1 \
+ --disable-decoder=wmv2 --disable-decoder=wmv3 --disable-decoder=cook --disable-decoder=dts --disable-decoder=flac \
+ --disable-decoder=mp2 --disable-decoder=mp3 --disable-decoder=qdm2 --disable-decoder=ra_144 --disable-decoder=ra_288 \
+ --disable-decoder=wavpack --disable-decoder=wmav1 --disable-decoder=wmav2 --disable-decoder=adpcm_swf
+endif
+
+configure_options =\
+ --disable-shared --enable-static --disable-demuxers --disable-muxers --disable-strip \
+ --enable-gpl --enable-pthreads --disable-ffmpeg --disable-ffserver --disable-ffplay
+
+if DEBUG_BUILD
+configure_options += --enable-debug
+else
+configure_options += --disable-debug
+endif
+if PROFILING_BUILD
+configure_options += --enable-gprof
+endif
+if DISABLE_OPTIMIZATIONS
+configure_options += --disable-opts
+endif
+if HAVE_MLIB
+configure_options += --enable-sunmlib
+endif
+
+if !HOST_OS_DARWIN
+FFMPEG_EXTRA_CFLAGS = -fPIC -DPIC
+endif
+
+disable_decoders = \
+ --disable-decoder=bmp --disable-decoder=cavs --disable-decoder=cljr --disable-decoder=dsicinvideo \
+ --disable-decoder=ffv1 --disable-decoder=ffvhuff --disable-decoder=gif --disable-decoder=mdec \
+ --disable-decoder=mpeg_xvmc --disable-decoder=mszh --disable-decoder=png --disable-decoder=rawvideo \
+ --disable-decoder=sp5x --disable-decoder=targa --disable-decoder=tiertexseqvideo --disable-decoder=tiff \
+ --disable-decoder=vmnc --disable-decoder=zlib --disable-decoder=dsicinaudio --disable-decoder=imc \
+ --disable-decoder=mp3adu --disable-decoder=mp3on4 --disable-decoder=mpc7 --disable-decoder=sonic \
+ --disable-decoder=ws_snd1 --disable-decoder=adpcm_adx --disable-decoder=adpcm_g726 --disable-decoder=dvbsub \
+ --disable-decoder=dvdsub --disable-decoder=theora --disable-decoder=aac --disable-decoder=mpeg4aac \
+ --disable-decoder=ac3 --disable-decoder=vorbis
+
+all_configure_options = \
+ $(configure_options) --make="$(MAKE)" --cc="$(CC)" \
+ --disable-encoders $(dxr3encoder) $(disable_decoders) \
+ $(disable_uncommon_codecs) $(disable_popular_codecs)
+
+ffmpeg/config.mak: ffmpeg/configure Makefile $(ffmpeg_builder)
+if MACOSX_UNIVERSAL_BINARY
+ export CFLAGS="$(VISIBILITY_FLAG)"; \
+ export FFMPEG_CONFIGURE_OPTIONS="$(all_configure_options)"; \
+ $(ffmpeg_builder) -configure "$(srcdir)/ffmpeg" $(UNIVERSAL_ARCHES)
+else
+ mkdir -p ffmpeg
+ cd ffmpeg; \
+ $(srcdir)/ffmpeg/configure $(all_configure_options) \
+ --extra-cflags="$(VISIBILITY_FLAG) $(FFMPEG_EXTRA_CFLAGS)"; \
+ cd ..
+if HOST_OS_DARWIN
+ cat ffmpeg/config.mak | sed -e '/OPTFLAGS=/s/-mdynamic-no-pic//g' > ffmpeg/config.tmp
+ mv -f ffmpeg/config.tmp ffmpeg/config.mak
+endif
+endif
+
+ffmpeg/libavutil/libavutil.a: ffmpeg/config.mak
+if MACOSX_UNIVERSAL_BINARY
+ export MAKE="$(MAKE)"; \
+ $(ffmpeg_builder) -avutil "$(srcdir)/ffmpeg" $(UNIVERSAL_ARCHES)
+else
+ $(MAKE) -C ffmpeg/libavutil libavutil.a
+endif
+
+ffmpeg/libavcodec/libavcodec.a: ffmpeg/config.mak
+if MACOSX_UNIVERSAL_BINARY
+ export MAKE="$(MAKE)"; \
+ $(ffmpeg_builder) -avcodec "$(srcdir)/ffmpeg" $(UNIVERSAL_ARCHES)
+else
+ $(MAKE) -C ffmpeg/libavcodec libavcodec.a
+endif
+
+ffmpeg/libpostproc/libpostproc.a: ffmpeg/config.mak
+if MACOSX_UNIVERSAL_BINARY
+ export MAKE="$(MAKE)"; \
+ $(ffmpeg_builder) -postproc "$(srcdir)/ffmpeg" $(UNIVERSAL_ARCHES)
+else
+ $(MAKE) -C ffmpeg/libpostproc libpostproc.a
+endif
+
+clean-local:
+if MACOSX_UNIVERSAL_BINARY
+ export MAKE="$(MAKE)"; \
+ $(ffmpeg_builder) -clean "$(srcdir)/ffmpeg" $(UNIVERSAL_ARCHES)
+else
+ -$(MAKE) -C ffmpeg clean
+endif
+
+distclean-local:
+if MACOSX_UNIVERSAL_BINARY
+ export MAKE="$(MAKE)"; \
+ $(ffmpeg_builder) -distclean "$(srcdir)/ffmpeg" $(UNIVERSAL_ARCHES)
+else
+ -$(MAKE) -C ffmpeg distclean
+endif
+
+EXTRA_DIST = README.contrib ffmpeg-distfiles
+
+dist-hook:
+ while read entry; do \
+ test -d $(srcdir)/$$entry && mkdir -p $(distdir)/$$entry; \
+ test -f $(srcdir)/$$entry && cp -p $(srcdir)/$$entry $(distdir)/$$entry; \
+ done < $(srcdir)/ffmpeg-distfiles
diff --git a/contrib/README.contrib b/contrib/README.contrib
new file mode 100644
index 000000000..6b2a58c1c
--- /dev/null
+++ b/contrib/README.contrib
@@ -0,0 +1,58 @@
+The contrib/ subdirectory for xine-lib contains the code for libraries
+that are not developed by the xine project, but are rather imported
+from other projects.
+
+These libraries are imported either because they need to be patched to
+fix bugs not yet fixed in any released version, to make it simpler for
+the users to have the library installed, or because there's no proper
+release done by that project.
+
+This README file should explain how to upgrade the code present in the
+contrib/ directory with new sources from the development project.
+
+FFmpeg
+------
+
+FFmpeg does not have proper releases at the moment, which means that
+to be safe that the correct version of FFmpeg is used by xine-lib
+users, a copy of the Subversion repository has to be imported in the
+source package.
+
+To upgrade the code coming from FFmpeg project, you have to run the
+following commands:
+
+ cd ${xine-lib-checkout}/contrib
+ rm -rf ffmpeg
+ svn export svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg
+ find ffmpeg > ffmpeg-distfiles
+
+This will take a new checkout of FFmpeg and put it in place; if there
+hasn't been functional changes in their build system, this should be
+enough (if there has been, and you don't know about them, you
+shouldn't be doing the contrib/ upgrade).
+
+After this, you need to make sure that Mercurial knows to remove the
+files that were removed by FFmpeg upstream and to add the files that
+were added by FFmpeg upstream. A way to handle this is (assuming that
+you didn't try to compile xine-lib with the updated ffmpeg yet):
+
+ cd ${xine-lib-checkout}/contrib/ffmpeg
+ hg status | egrep '^!' | cut -d ' ' -f 2 | xargs hg rm
+ hg status | egrep '^?' | cut -d ' ' -f 2 | xargs hg add
+
+This should register the file changes that happened.
+
+The ffmpeg-distfiles file is used by the make dist target to know
+which files needs to be copied over in the tarball file, so it's
+important that is always up to date.
+
+libxdg-basedir
+--------------
+
+The libxdg-basedir project is a (really) small library used to provide
+the proper access to XDG directories as described by the XDG Base
+Directory Specification (0.6 version).
+
+The library can be found at
+https://n.ethz.ch/student/nevillm/download/libxdg-basedir/ , and it's
+imported in xine-lib as it's far from commonly found on distributions.
diff --git a/contrib/ffmpeg-distfiles b/contrib/ffmpeg-distfiles
new file mode 100644
index 000000000..28735bc3c
--- /dev/null
+++ b/contrib/ffmpeg-distfiles
@@ -0,0 +1,588 @@
+ffmpeg
+ffmpeg/vhook
+ffmpeg/vhook/imlib2.c
+ffmpeg/vhook/drawtext.c
+ffmpeg/vhook/fish.c
+ffmpeg/vhook/null.c
+ffmpeg/vhook/Makefile
+ffmpeg/vhook/ppm.c
+ffmpeg/vhook/watermark.c
+ffmpeg/libavutil
+ffmpeg/libavutil/lls.h
+ffmpeg/libavutil/mathematics.c
+ffmpeg/libavutil/adler32.h
+ffmpeg/libavutil/x86_cpu.h
+ffmpeg/libavutil/integer.h
+ffmpeg/libavutil/mathematics.h
+ffmpeg/libavutil/crc.c
+ffmpeg/libavutil/avutil.h
+ffmpeg/libavutil/rational.c
+ffmpeg/libavutil/crc.h
+ffmpeg/libavutil/mem.c
+ffmpeg/libavutil/rational.h
+ffmpeg/libavutil/log.c
+ffmpeg/libavutil/internal.h
+ffmpeg/libavutil/bswap.h
+ffmpeg/libavutil/md5.c
+ffmpeg/libavutil/intfloat_readwrite.c
+ffmpeg/libavutil/log.h
+ffmpeg/libavutil/lls.c
+ffmpeg/libavutil/md5.h
+ffmpeg/libavutil/intfloat_readwrite.h
+ffmpeg/libavutil/adler32.c
+ffmpeg/libavutil/Makefile
+ffmpeg/libavutil/integer.c
+ffmpeg/libavutil/common.h
+ffmpeg/libavutil/softfloat.c
+ffmpeg/libavutil/softfloat.h
+ffmpeg/libavutil/fifo.c
+ffmpeg/libavutil/fifo.h
+ffmpeg/libavutil/tree.c
+ffmpeg/libavutil/tree.h
+ffmpeg/libavutil/intreadwrite.h
+ffmpeg/libavutil/aes.c
+ffmpeg/libavutil/aes.h
+ffmpeg/libavutil/lzo.c
+ffmpeg/libavutil/lzo.h
+ffmpeg/libavutil/random.c
+ffmpeg/libavutil/base64.c
+ffmpeg/libavutil/random.h
+ffmpeg/libavutil/base64.h
+ffmpeg/libavutil/sha1.h
+ffmpeg/libavutil/mem.h
+ffmpeg/libavutil/sha1.c
+ffmpeg/libavcodec
+ffmpeg/libavcodec/alpha
+ffmpeg/libavcodec/alpha/regdef.h
+ffmpeg/libavcodec/alpha/simple_idct_alpha.c
+ffmpeg/libavcodec/alpha/mpegvideo_alpha.c
+ffmpeg/libavcodec/alpha/asm.h
+ffmpeg/libavcodec/alpha/motion_est_alpha.c
+ffmpeg/libavcodec/alpha/dsputil_alpha.c
+ffmpeg/libavcodec/alpha/dsputil_alpha_asm.S
+ffmpeg/libavcodec/alpha/motion_est_mvi_asm.S
+ffmpeg/libavcodec/sparc
+ffmpeg/libavcodec/sparc/dsputil_vis.c
+ffmpeg/libavcodec/sparc/vis.h
+ffmpeg/libavcodec/i386
+ffmpeg/libavcodec/i386/idct_mmx_xvid.c
+ffmpeg/libavcodec/i386/mpegvideo_mmx.c
+ffmpeg/libavcodec/i386/vp3dsp_mmx.c
+ffmpeg/libavcodec/i386/motion_est_mmx.c
+ffmpeg/libavcodec/i386/fdct_mmx.c
+ffmpeg/libavcodec/i386/dsputil_h264_template_mmx.c
+ffmpeg/libavcodec/i386/idct_mmx.c
+ffmpeg/libavcodec/i386/fft_3dn2.c
+ffmpeg/libavcodec/i386/dsputil_mmx.c
+ffmpeg/libavcodec/i386/mmx.h
+ffmpeg/libavcodec/i386/dsputil_mmx_avg.h
+ffmpeg/libavcodec/i386/h264dsp_mmx.c
+ffmpeg/libavcodec/i386/vp3dsp_sse2.c
+ffmpeg/libavcodec/i386/dsputil_mmx_rnd.h
+ffmpeg/libavcodec/i386/simple_idct_mmx.c
+ffmpeg/libavcodec/i386/snowdsp_mmx.c
+ffmpeg/libavcodec/i386/fft_3dn.c
+ffmpeg/libavcodec/i386/cputest.c
+ffmpeg/libavcodec/i386/fft_sse.c
+ffmpeg/libavcodec/i386/mpegvideo_mmx_template.c
+ffmpeg/libavcodec/i386/mathops.h
+ffmpeg/libavcodec/i386/cavsdsp_mmx.c
+ffmpeg/libavcodec/ppc
+ffmpeg/libavcodec/ppc/gcc_fixes.h
+ffmpeg/libavcodec/ppc/dsputil_altivec.h
+ffmpeg/libavcodec/ppc/mpegvideo_ppc.c
+ffmpeg/libavcodec/ppc/dsputil_ppc.c
+ffmpeg/libavcodec/ppc/fft_altivec.c
+ffmpeg/libavcodec/ppc/mpegvideo_altivec.c
+ffmpeg/libavcodec/ppc/fdct_altivec.c
+ffmpeg/libavcodec/ppc/idct_altivec.c
+ffmpeg/libavcodec/ppc/dsputil_altivec.c
+ffmpeg/libavcodec/ppc/dsputil_ppc.h
+ffmpeg/libavcodec/ppc/gmc_altivec.c
+ffmpeg/libavcodec/ppc/vc1dsp_altivec.c
+ffmpeg/libavcodec/ppc/float_altivec.c
+ffmpeg/libavcodec/ppc/mathops.h
+ffmpeg/libavcodec/ppc/h264_template_altivec.c
+ffmpeg/libavcodec/ppc/h264_altivec.c
+ffmpeg/libavcodec/ppc/snow_altivec.c
+ffmpeg/libavcodec/ppc/types_altivec.h
+ffmpeg/libavcodec/ps2
+ffmpeg/libavcodec/ps2/mpegvideo_mmi.c
+ffmpeg/libavcodec/ps2/idct_mmi.c
+ffmpeg/libavcodec/ps2/dsputil_mmi.c
+ffmpeg/libavcodec/ps2/mmi.h
+ffmpeg/libavcodec/dcadata.h
+ffmpeg/libavcodec/mlib
+ffmpeg/libavcodec/mlib/dsputil_mlib.c
+ffmpeg/libavcodec/sh4
+ffmpeg/libavcodec/sh4/dsputil_align.c
+ffmpeg/libavcodec/sh4/idct_sh4.c
+ffmpeg/libavcodec/sh4/qpel.c
+ffmpeg/libavcodec/sh4/dsputil_sh4.c
+ffmpeg/libavcodec/armv4l
+ffmpeg/libavcodec/armv4l/mpegvideo_arm.c
+ffmpeg/libavcodec/armv4l/jrevdct_arm.S
+ffmpeg/libavcodec/armv4l/dsputil_iwmmxt_rnd.h
+ffmpeg/libavcodec/armv4l/dsputil_arm.c
+ffmpeg/libavcodec/armv4l/mpegvideo_iwmmxt.c
+ffmpeg/libavcodec/armv4l/dsputil_arm_s.S
+ffmpeg/libavcodec/armv4l/dsputil_iwmmxt.c
+ffmpeg/libavcodec/armv4l/simple_idct_arm.S
+ffmpeg/libavcodec/armv4l/simple_idct_armv5te.S
+ffmpeg/libavcodec/armv4l/mathops.h
+ffmpeg/libavcodec/armv4l/mpegvideo_armv5te.c
+ffmpeg/libavcodec/armv4l/simple_idct_armv6.S
+ffmpeg/libavcodec/mmvideo.c
+ffmpeg/libavcodec/dvbsubdec.c
+ffmpeg/libavcodec/msmpeg4.c
+ffmpeg/libavcodec/mjpeg.c
+ffmpeg/libavcodec/8bps.c
+ffmpeg/libavcodec/ffv1.c
+ffmpeg/libavcodec/adx.c
+ffmpeg/libavcodec/flashsv.c
+ffmpeg/libavcodec/rangecoder.h
+ffmpeg/libavcodec/vp3data.h
+ffmpeg/libavcodec/golomb.c
+ffmpeg/libavcodec/nuv.c
+ffmpeg/libavcodec/h264.c
+ffmpeg/libavcodec/vcr1.c
+ffmpeg/libavcodec/kmvc.c
+ffmpeg/libavcodec/vqavideo.c
+ffmpeg/libavcodec/golomb.h
+ffmpeg/libavcodec/zmbv.c
+ffmpeg/libavcodec/png.c
+ffmpeg/libavcodec/indeo2.c
+ffmpeg/libavcodec/simple_idct.h
+ffmpeg/libavcodec/mpegaudiodectab.h
+ffmpeg/libavcodec/apiexample.c
+ffmpeg/libavcodec/wma.c
+ffmpeg/libavcodec/roqvideo.c
+ffmpeg/libavcodec/jpeg_ls.c
+ffmpeg/libavcodec/mpeg12data.h
+ffmpeg/libavcodec/wmadata.h
+ffmpeg/libavcodec/os2thread.c
+ffmpeg/libavcodec/smacker.c
+ffmpeg/libavcodec/w32thread.c
+ffmpeg/libavcodec/truemotion1data.h
+ffmpeg/libavcodec/Makefile
+ffmpeg/libavcodec/vc1data.h
+ffmpeg/libavcodec/fft-test.c
+ffmpeg/libavcodec/avs.c
+ffmpeg/libavcodec/alac.c
+ffmpeg/libavcodec/cljr.c
+ffmpeg/libavcodec/ac3tab.h
+ffmpeg/libavcodec/cookdata.h
+ffmpeg/libavcodec/faandct.c
+ffmpeg/libavcodec/pnm.c
+ffmpeg/libavcodec/simple_idct.c
+ffmpeg/libavcodec/fft.c
+ffmpeg/libavcodec/bitstream_filter.c
+ffmpeg/libavcodec/oggvorbis.c
+ffmpeg/libavcodec/opt.c
+ffmpeg/libavcodec/flicvideo.c
+ffmpeg/libavcodec/qdm2data.h
+ffmpeg/libavcodec/mpegaudio.c
+ffmpeg/libavcodec/svq1_vlc.h
+ffmpeg/libavcodec/jrevdct.c
+ffmpeg/libavcodec/wma.h
+ffmpeg/libavcodec/cavsdsp.c
+ffmpeg/libavcodec/opt.h
+ffmpeg/libavcodec/allcodecs.c
+ffmpeg/libavcodec/resample.c
+ffmpeg/libavcodec/x264.c
+ffmpeg/libavcodec/vp3.c
+ffmpeg/libavcodec/sp5x.h
+ffmpeg/libavcodec/bmp.h
+ffmpeg/libavcodec/faandct.h
+ffmpeg/libavcodec/dv.c
+ffmpeg/libavcodec/mdec.c
+ffmpeg/libavcodec/sonic.c
+ffmpeg/libavcodec/4xm.c
+ffmpeg/libavcodec/libgsm.c
+ffmpeg/libavcodec/dsputil.h
+ffmpeg/libavcodec/idcinvideo.c
+ffmpeg/libavcodec/avcodec.h
+ffmpeg/libavcodec/qdrw.c
+ffmpeg/libavcodec/error_resilience.c
+ffmpeg/libavcodec/mpegvideo.c
+ffmpeg/libavcodec/faad.c
+ffmpeg/libavcodec/h263data.h
+ffmpeg/libavcodec/lcl.c
+ffmpeg/libavcodec/shorten.c
+ffmpeg/libavcodec/ac3.h
+ffmpeg/libavcodec/xl.c
+ffmpeg/libavcodec/rtjpeg.c
+ffmpeg/libavcodec/mpegvideo.h
+ffmpeg/libavcodec/wmv2.c
+ffmpeg/libavcodec/truemotion1.c
+ffmpeg/libavcodec/imgconvert.c
+ffmpeg/libavcodec/mdct.c
+ffmpeg/libavcodec/h261data.h
+ffmpeg/libavcodec/dvdsubdec.c
+ffmpeg/libavcodec/indeo3data.h
+ffmpeg/libavcodec/rv10.c
+ffmpeg/libavcodec/bytestream.h
+ffmpeg/libavcodec/cabac.c
+ffmpeg/libavcodec/smc.c
+ffmpeg/libavcodec/faac.c
+ffmpeg/libavcodec/xvidff.c
+ffmpeg/libavcodec/mpeg12.c
+ffmpeg/libavcodec/vc1acdata.h
+ffmpeg/libavcodec/cavsdata.h
+ffmpeg/libavcodec/raw.c
+ffmpeg/libavcodec/qpeg.c
+ffmpeg/libavcodec/vc1.c
+ffmpeg/libavcodec/h263dec.c
+ffmpeg/libavcodec/bitstream.c
+ffmpeg/libavcodec/cabac.h
+ffmpeg/libavcodec/interplayvideo.c
+ffmpeg/libavcodec/xvmcvideo.c
+ffmpeg/libavcodec/rtjpeg.h
+ffmpeg/libavcodec/jfdctfst.c
+ffmpeg/libavcodec/cook.c
+ffmpeg/libavcodec/rpza.c
+ffmpeg/libavcodec/utils.c
+ffmpeg/libavcodec/motion_est.c
+ffmpeg/libavcodec/flacenc.c
+ffmpeg/libavcodec/indeo3.c
+ffmpeg/libavcodec/wnv1.c
+ffmpeg/libavcodec/h263.c
+ffmpeg/libavcodec/imgresample.c
+ffmpeg/libavcodec/mpegaudiodec.c
+ffmpeg/libavcodec/parser.c
+ffmpeg/libavcodec/snow.c
+ffmpeg/libavcodec/truespeech_data.h
+ffmpeg/libavcodec/dct-test.c
+ffmpeg/libavcodec/ratecontrol.c
+ffmpeg/libavcodec/tta.c
+ffmpeg/libavcodec/xvid_rc.c
+ffmpeg/libavcodec/svq1.c
+ffmpeg/libavcodec/bitstream.h
+ffmpeg/libavcodec/snow.h
+ffmpeg/libavcodec/a52dec.c
+ffmpeg/libavcodec/cavs.c
+ffmpeg/libavcodec/asv1.c
+ffmpeg/libavcodec/truespeech.c
+ffmpeg/libavcodec/msmpeg4data.h
+ffmpeg/libavcodec/qdm2.c
+ffmpeg/libavcodec/fraps.c
+ffmpeg/libavcodec/svq1_cb.h
+ffmpeg/libavcodec/cscd.c
+ffmpeg/libavcodec/vorbis.c
+ffmpeg/libavcodec/bmp.c
+ffmpeg/libavcodec/dvdata.h
+ffmpeg/libavcodec/mpegaudio.h
+ffmpeg/libavcodec/flac.c
+ffmpeg/libavcodec/amr.c
+ffmpeg/libavcodec/dtsdec.c
+ffmpeg/libavcodec/dsputil.c
+ffmpeg/libavcodec/lzw.c
+ffmpeg/libavcodec/g726.c
+ffmpeg/libavcodec/bfin
+ffmpeg/libavcodec/bfin/dsputil_bfin.c
+ffmpeg/libavcodec/bfin/fdct_bfin.S
+ffmpeg/libavcodec/bfin/idct_bfin.S
+ffmpeg/libavcodec/bfin/pixels_bfin.S
+ffmpeg/libavcodec/bfin/config_bfin.h
+ffmpeg/libavcodec/ulti_cb.h
+ffmpeg/libavcodec/cinepak.c
+ffmpeg/libavcodec/xan.c
+ffmpeg/libavcodec/fdctref.c
+ffmpeg/libavcodec/eval.c
+ffmpeg/libavcodec/vmnc.c
+ffmpeg/libavcodec/qtrle.c
+ffmpeg/libavcodec/rangecoder.c
+ffmpeg/libavcodec/truemotion2.c
+ffmpeg/libavcodec/indeo2data.h
+ffmpeg/libavcodec/pcm.c
+ffmpeg/libavcodec/motion_est_template.c
+ffmpeg/libavcodec/imgconvert_template.h
+ffmpeg/libavcodec/mpegaudiotab.h
+ffmpeg/libavcodec/mp3lameaudio.c
+ffmpeg/libavcodec/h261.c
+ffmpeg/libavcodec/msrle.c
+ffmpeg/libavcodec/dpcm.c
+ffmpeg/libavcodec/cyuv.c
+ffmpeg/libavcodec/pthread.c
+ffmpeg/libavcodec/ra144.c
+ffmpeg/libavcodec/loco.c
+ffmpeg/libavcodec/huffyuv.c
+ffmpeg/libavcodec/svq3.c
+ffmpeg/libavcodec/tscc.c
+ffmpeg/libavcodec/ws-snd1.c
+ffmpeg/libavcodec/ra144.h
+ffmpeg/libavcodec/wmadec.c
+ffmpeg/libavcodec/motion_test.c
+ffmpeg/libavcodec/ra288.c
+ffmpeg/libavcodec/mace.c
+ffmpeg/libavcodec/jfdctint.c
+ffmpeg/libavcodec/aasc.c
+ffmpeg/libavcodec/ra288.h
+ffmpeg/libavcodec/mpeg4data.h
+ffmpeg/libavcodec/dvdsubenc.c
+ffmpeg/libavcodec/ulti.c
+ffmpeg/libavcodec/vmdav.c
+ffmpeg/libavcodec/vp3dsp.c
+ffmpeg/libavcodec/beosthread.c
+ffmpeg/libavcodec/h264data.h
+ffmpeg/libavcodec/adpcm.c
+ffmpeg/libavcodec/dvbsub.c
+ffmpeg/libavcodec/msvideo1.c
+ffmpeg/libavcodec/h264idct.c
+ffmpeg/libavcodec/resample2.c
+ffmpeg/libavcodec/ac3enc.c
+ffmpeg/libavcodec/vp6data.h
+ffmpeg/libavcodec/mathops.h
+ffmpeg/libavcodec/eval.h
+ffmpeg/libavcodec/vp5data.h
+ffmpeg/libavcodec/vp56data.c
+ffmpeg/libavcodec/vp56data.h
+ffmpeg/libavcodec/vp5.c
+ffmpeg/libavcodec/vorbis_enc.c
+ffmpeg/libavcodec/vp56.c
+ffmpeg/libavcodec/ratecontrol.h
+ffmpeg/libavcodec/audioconvert.c
+ffmpeg/libavcodec/vp56.h
+ffmpeg/libavcodec/vorbis.h
+ffmpeg/libavcodec/vorbis_data.c
+ffmpeg/libavcodec/vc1dsp.c
+ffmpeg/libavcodec/vp6.c
+ffmpeg/libavcodec/vorbis_enc_data.h
+ffmpeg/libavcodec/wavpack.c
+ffmpeg/libavcodec/targa.c
+ffmpeg/libavcodec/lzw.h
+ffmpeg/libavcodec/xvid_internal.h
+ffmpeg/libavcodec/imcdata.h
+ffmpeg/libavcodec/tiertexseqv.c
+ffmpeg/libavcodec/imc.c
+ffmpeg/libavcodec/tiff.c
+ffmpeg/libavcodec/dsicinav.c
+ffmpeg/libavcodec/parser.h
+ffmpeg/libavcodec/gif.c
+ffmpeg/libavcodec/gifdec.c
+ffmpeg/libavcodec/mpcdata.h
+ffmpeg/libavcodec/zmbvenc.c
+ffmpeg/libavcodec/h264dsp.c
+ffmpeg/libavcodec/h264enc.c
+ffmpeg/libavcodec/mpc.c
+ffmpeg/libavcodec/flashsvenc.c
+ffmpeg/libavcodec/xvmc_render.h
+ffmpeg/libavcodec/libtheoraenc.c
+ffmpeg/libavcodec/dca.c
+ffmpeg/libavcodec/bmpenc.c
+ffmpeg/libavcodec/dcahuff.h
+ffmpeg/libavcodec/wmaenc.c
+ffmpeg/libavcodec/targaenc.c
+ffmpeg/libavcodec/ac3.c
+ffmpeg/libavcodec/dxa.c
+ffmpeg/libavcodec/rl.h
+ffmpeg/libavcodec/dnxhddec.c
+ffmpeg/libavcodec/dnxhddata.h
+ffmpeg/libavcodec/xiph.c
+ffmpeg/libavcodec/xiph.h
+ffmpeg/libpostproc
+ffmpeg/libpostproc/postprocess_template.c
+ffmpeg/libpostproc/postprocess.c
+ffmpeg/libpostproc/postprocess_internal.h
+ffmpeg/libpostproc/postprocess_altivec_template.c
+ffmpeg/libpostproc/mangle.h
+ffmpeg/libpostproc/postprocess.h
+ffmpeg/libpostproc/Makefile
+ffmpeg/tests
+ffmpeg/tests/videogen.c
+ffmpeg/tests/rotozoom.regression.ref
+ffmpeg/tests/test.conf
+ffmpeg/tests/tiny_psnr.c
+ffmpeg/tests/dsptest.c
+ffmpeg/tests/libav.regression.ref
+ffmpeg/tests/lena.pnm
+ffmpeg/tests/regression.sh
+ffmpeg/tests/rotozoom.c
+ffmpeg/tests/audiogen.c
+ffmpeg/tests/ffserver.regression.ref
+ffmpeg/tests/Makefile
+ffmpeg/tests/server-regression.sh
+ffmpeg/tests/ffmpeg.regression.ref
+ffmpeg/tests/seek_test.sh
+ffmpeg/tests/seek_test.c
+ffmpeg/doc
+ffmpeg/doc/faq.texi
+ffmpeg/doc/ffmpeg-doc.texi
+ffmpeg/doc/optimization.txt
+ffmpeg/doc/TODO
+ffmpeg/doc/ffserver.conf
+ffmpeg/doc/texi2pod.pl
+ffmpeg/doc/ffmpeg_powerpc_performance_evaluation_howto.txt
+ffmpeg/doc/hooks.texi
+ffmpeg/doc/ffplay-doc.texi
+ffmpeg/doc/Makefile
+ffmpeg/doc/ffserver-doc.texi
+ffmpeg/doc/soc.txt
+ffmpeg/doc/snow.txt
+ffmpeg/doc/avutil.txt
+ffmpeg/libavformat
+ffmpeg/libavformat/riff.h
+ffmpeg/libavformat/img2.c
+ffmpeg/libavformat/voc.h
+ffmpeg/libavformat/dv1394.h
+ffmpeg/libavformat/rtsp.h
+ffmpeg/libavformat/utils.c
+ffmpeg/libavformat/wav.c
+ffmpeg/libavformat/cutils.c
+ffmpeg/libavformat/dvenc.c
+ffmpeg/libavformat/nut.c
+ffmpeg/libavformat/avisynth.c
+ffmpeg/libavformat/crc.c
+ffmpeg/libavformat/wv.c
+ffmpeg/libavformat/ipmovie.c
+ffmpeg/libavformat/nut.h
+ffmpeg/libavformat/ffm.c
+ffmpeg/libavformat/mtv.c
+ffmpeg/libavformat/nuv.c
+ffmpeg/libavformat/framehook.c
+ffmpeg/libavformat/os_support.c
+ffmpeg/libavformat/vocenc.c
+ffmpeg/libavformat/idroq.c
+ffmpeg/libavformat/libnut.c
+ffmpeg/libavformat/http.c
+ffmpeg/libavformat/westwood.c
+ffmpeg/libavformat/matroska.c
+ffmpeg/libavformat/vocdec.c
+ffmpeg/libavformat/adtsenc.c
+ffmpeg/libavformat/flic.c
+ffmpeg/libavformat/electronicarts.c
+ffmpeg/libavformat/rtp_h264.c
+ffmpeg/libavformat/mpjpeg.c
+ffmpeg/libavformat/flvenc.c
+ffmpeg/libavformat/os_support.h
+ffmpeg/libavformat/rtp_h264.h
+ffmpeg/libavformat/tiertexseq.c
+ffmpeg/libavformat/gxf.c
+ffmpeg/libavformat/nutdec.c
+ffmpeg/libavformat/avi.h
+ffmpeg/libavformat/network.h
+ffmpeg/libavformat/smacker.c
+ffmpeg/libavformat/flv.h
+ffmpeg/libavformat/udp.c
+ffmpeg/libavformat/x11grab.c
+ffmpeg/libavformat/gxf.h
+ffmpeg/libavformat/mpc.c
+ffmpeg/libavformat/avs.c
+ffmpeg/libavformat/daud.c
+ffmpeg/libavformat/rtpproto.c
+ffmpeg/libavformat/Makefile
+ffmpeg/libavformat/framehook.h
+ffmpeg/libavformat/oggparsevorbis.c
+ffmpeg/libavformat/rtspcodes.h
+ffmpeg/libavformat/oggparseflac.c
+ffmpeg/libavformat/mpegts.c
+ffmpeg/libavformat/mp3.c
+ffmpeg/libavformat/mpegts.h
+ffmpeg/libavformat/rtp.c
+ffmpeg/libavformat/dc1394.c
+ffmpeg/libavformat/4xm.c
+ffmpeg/libavformat/ogg.c
+ffmpeg/libavformat/qtpalette.h
+ffmpeg/libavformat/asf.c
+ffmpeg/libavformat/dv.c
+ffmpeg/libavformat/gxfenc.c
+ffmpeg/libavformat/mmf.c
+ffmpeg/libavformat/beosaudio.cpp
+ffmpeg/libavformat/rtp.h
+ffmpeg/libavformat/grab.c
+ffmpeg/libavformat/asf-enc.c
+ffmpeg/libavformat/asf.h
+ffmpeg/libavformat/dv.h
+ffmpeg/libavformat/rm.c
+ffmpeg/libavformat/file.c
+ffmpeg/libavformat/yuv4mpeg.c
+ffmpeg/libavformat/nsvdec.c
+ffmpeg/libavformat/tcp.c
+ffmpeg/libavformat/movenc.c
+ffmpeg/libavformat/mpeg.c
+ffmpeg/libavformat/raw.c
+ffmpeg/libavformat/amr.c
+ffmpeg/libavformat/sierravmd.c
+ffmpeg/libavformat/gifdec.c
+ffmpeg/libavformat/wc3movie.c
+ffmpeg/libavformat/grab_bktr.c
+ffmpeg/libavformat/sol.c
+ffmpeg/libavformat/avio.c
+ffmpeg/libavformat/ogg2.c
+ffmpeg/libavformat/swf.c
+ffmpeg/libavformat/mov.c
+ffmpeg/libavformat/avio.h
+ffmpeg/libavformat/ogg2.h
+ffmpeg/libavformat/psxstr.c
+ffmpeg/libavformat/avienc.c
+ffmpeg/libavformat/au.c
+ffmpeg/libavformat/aiff.c
+ffmpeg/libavformat/isom.c
+ffmpeg/libavformat/mxf.c
+ffmpeg/libavformat/mm.c
+ffmpeg/libavformat/avformat.h
+ffmpeg/libavformat/oggparseogm.c
+ffmpeg/libavformat/idcin.c
+ffmpeg/libavformat/oggparsetheora.c
+ffmpeg/libavformat/mpegtsenc.c
+ffmpeg/libavformat/riff.c
+ffmpeg/libavformat/segafilm.c
+ffmpeg/libavformat/v4l2.c
+ffmpeg/libavformat/tta.c
+ffmpeg/libavformat/avidec.c
+ffmpeg/libavformat/audio.c
+ffmpeg/libavformat/flvdec.c
+ffmpeg/libavformat/voc.c
+ffmpeg/libavformat/allformats.c
+ffmpeg/libavformat/gif.c
+ffmpeg/libavformat/rtsp.c
+ffmpeg/libavformat/dsicin.c
+ffmpeg/libavformat/dv1394.c
+ffmpeg/libavformat/allformats.h
+ffmpeg/libavformat/aviobuf.c
+ffmpeg/libavformat/isom.h
+ffmpeg/libavformat/rtp_internal.h
+ffmpeg/libavformat/dxa.c
+ffmpeg/libavformat/thp.c
+ffmpeg/configure
+ffmpeg/Doxyfile
+ffmpeg/ffmpeg.c
+ffmpeg/Changelog
+ffmpeg/clean-diff
+ffmpeg/pktdumper.c
+ffmpeg/output_example.c
+ffmpeg/CREDITS
+ffmpeg/version.sh
+ffmpeg/cmdutils.c
+ffmpeg/INSTALL
+ffmpeg/COPYING
+ffmpeg/build_avopt
+ffmpeg/ffinstall.nsi
+ffmpeg/cmdutils.h
+ffmpeg/Makefile
+ffmpeg/qt-faststart.c
+ffmpeg/cws2fws.c
+ffmpeg/unwrap-diff
+ffmpeg/README
+ffmpeg/common.mak
+ffmpeg/ffplay.c
+ffmpeg/ffserver.c
+ffmpeg/ffserver.h
+ffmpeg/MAINTAINERS
+ffmpeg/libswscale
+ffmpeg/libswscale/yuv2rgb.c
+ffmpeg/libswscale/swscale.c
+ffmpeg/libswscale/rgb2rgb_template.c
+ffmpeg/libswscale/swscale_internal.h
+ffmpeg/libswscale/swscale_altivec_template.c
+ffmpeg/libswscale/yuv2rgb_mlib.c
+ffmpeg/libswscale/cs_test.c
+ffmpeg/libswscale/swscale.h
+ffmpeg/libswscale/rgb2rgb.c
+ffmpeg/libswscale/yuv2rgb_altivec.c
+ffmpeg/libswscale/swscale-example.c
+ffmpeg/libswscale/yuv2rgb_template.c
+ffmpeg/libswscale/Makefile
+ffmpeg/libswscale/rgb2rgb.h
+ffmpeg/libswscale/swscale_template.c
+ffmpeg/libswscale/yuv2rgb_init.c
diff --git a/contrib/ffmpeg-universal.sh b/contrib/ffmpeg-universal.sh
new file mode 100755
index 000000000..6e27c56b8
--- /dev/null
+++ b/contrib/ffmpeg-universal.sh
@@ -0,0 +1,177 @@
+#!/bin/sh
+
+function usage {
+ echo "usage: $0 <action> <source path> <arch list>"
+ echo "where: <action> is one of:"
+ echo " -configure do initial configuration for each architecture"
+ echo " -avcodec build libavcodec.a for each architecture"
+ echo " -avutil build libavutil.a for each architecture"
+ echo " -postproc build libpostproc.a for each architecture"
+ echo " -clean clean for each architecture"
+ echo " -distclean distclean for each architecture"
+ echo ""
+ echo "Configuration must be done before any library builds. Options to be passed"
+ echo "to ffmpeg's configure command-line should be passed in the environment"
+ echo "using the FFMPEG_CONFIGURE_OPTIONS environment variable."
+ exit 1
+}
+
+function run_configure {
+ local arch=$1
+ local ffmpeg_topbuilddir="$2"
+
+ # start over from scratch
+ rm -rf "$ffmpeg_topbuilddir"
+ mkdir -p "$ffmpeg_topbuilddir"
+ pushd "$ffmpeg_topbuilddir" > /dev/null 2>&1
+
+ # The Makefile should be passing FFMPEG_CONFIGURE_OPTIONS without passing
+ # any --extra-cflags or --extra-ldflags options. Both CFLAGS and LDFLAGS
+ # should be in the environment in addition to FFMPEG_CONFIGURE_OPTIONS.
+
+ local CROSS_OPTIONS=
+ local EXTRA_CFLAGS=
+ local EXTRA_LDFLAGS=
+
+ if test $HOST_ARCH != $arch; then
+ EXTRA_CFLAGS="$CFLAGS -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch $arch"
+ EXTRA_LDFLAGS="$LDFLAGS -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch $arch"
+ if test $arch = i386; then
+ FFMPEG_ARCH=x86_32
+ else
+ FFMPEG_ARCH=$arch
+ fi
+ CROSS_OPTIONS="--cross-compile --arch=$FFMPEG_ARCH"
+ fi
+
+ echo "$SOURCE_PATH/configure" $CROSS_OPTIONS $FFMPEG_CONFIGURE_OPTIONS \
+ --extra-cflags="$EXTRA_CFLAGS" \
+ --extra-ldflags="$EXTRA_LDFLAGS"
+ "$SOURCE_PATH/configure" $CROSS_OPTIONS $FFMPEG_CONFIGURE_OPTIONS \
+ --extra-cflags="$EXTRA_CFLAGS" \
+ --extra-ldflags="$EXTRA_LDFLAGS"
+ local retval=$?
+
+ # We're building ffmpeg to put it into a shared library, but ffmpeg thinks
+ # it's building to put it into a static library or program image, so it
+ # adds -mdynamic-no-pic to its list of options as an optimization. This is
+ # fine in Tiger if later linked with -Wl,-read_only_relocs,warning, but it
+ # isn't fine on other versions of Mac OS X.
+ if test -f config.mak; then
+ cat config.mak | sed -e '/OPTFLAGS=/s/-mdynamic-no-pic//g' > config.tmp
+ mv -f config.tmp config.mak
+ fi
+
+ popd > /dev/null 2>&1
+ `exit $retval` || exit $retval
+}
+
+if test x"$*" = x""; then
+ usage
+fi
+case "$1" in
+ -configure)
+ MODE=configure
+ ;;
+ -avcodec)
+ MODE=avcodec
+ ;;
+ -avutil)
+ MODE=avutil
+ ;;
+ -postproc)
+ MODE=postproc
+ ;;
+ -clean)
+ MODE=clean
+ ;;
+ -distclean)
+ MODE=distclean
+ ;;
+ *)
+ echo "Unrecognized mode: $1"
+ usage
+ ;;
+esac
+shift
+
+if test x"$1" = x""; then
+ echo "No source path specified!"
+ usage
+fi
+if test ! -d "$1"; then
+ echo "Source path $1 does not exist!"
+ exit 1
+fi
+SOURCE_PATH="$1"
+shift
+
+TOP_BUILD_PATH="`pwd`/ffmpeg"
+if test -f "$TOP_BUILD_PATH/configure"; then
+ # Building in place. Create a temporary build directory and use that
+ # instead, but place the final output from lipo into the original
+ # build directory.
+ BUILD_PATH="$TOP_BUILD_PATH/build"
+else
+ BUILD_PATH="$TOP_BUILD_PATH"
+fi
+# This doesn't make sense for -configure, but it does for everything else.
+# The -configure mode won't ever use it anyway.
+OUTPUT_FILENAME="$BUILD_PATH/lib$MODE/lib$MODE.a"
+
+HOST_ARCH=`arch`
+UNIVERSAL_ARCHES=$*
+if test x"$UNIVERSAL_ARCHES" = x""; then
+ echo "No architecture(s) specified; using $HOST_ARCH only."
+ UNIVERSAL_ARCHES=$HOST_ARCH
+fi
+CONFIG_FILES=
+LIPO_CMDLINE="-create -output $OUTPUT_FILENAME"
+for arch in $UNIVERSAL_ARCHES; do
+ ffmpeg_topbuilddir="$BUILD_PATH/$arch"
+ LIPO_CMDLINE="$LIPO_CMDLINE -arch $arch $ffmpeg_topbuilddir/lib$MODE/lib$MODE.a"
+ case $MODE in
+ configure)
+ run_configure $arch "$ffmpeg_topbuilddir"
+ CONFIG_FILES="$CONFIG_FILES $ffmpeg_topbuilddir/config.h"
+ ;;
+ avcodec)
+ "$MAKE" -C "$ffmpeg_topbuilddir/libavcodec" libavcodec.a || exit $?
+ ;;
+ avutil)
+ "$MAKE" -C "$ffmpeg_topbuilddir/libavutil" libavutil.a || exit $?
+ ;;
+ postproc)
+ "$MAKE" -C "$ffmpeg_topbuilddir/libpostproc" libpostproc.a || exit $?
+ ;;
+ clean)
+ "$MAKE" -C "$ffmpeg_topbuilddir" clean || exit $?
+ ;;
+ distclean)
+ "$MAKE" -C "$ffmpeg_topbuilddir" distclean || exit $?
+ ;;
+ esac
+done
+
+case $MODE in
+ configure)
+ # Now that configuration is done, create config.h in the top-level
+ # ffmpeg directory. Pull out only what's needed by xine-lib, removing
+ # any possible platform conflicts
+ grep -h "define CONFIG_.*_DECODER" $CONFIG_FILES | uniq > "$BUILD_PATH/config.h"
+ touch "$BUILD_PATH/config.mak"
+ ;;
+ clean)
+ rm -f "$BUILD_PATH/libavcodec/libavcodec.a" "$BUILD_PATH/libavutil/libavutil.a" \
+ "$BUILD_PATH/libpostproc/libpostproc.a"
+ ;;
+ distclean)
+ rm -f "$BUILD_PATH/config.mak" "$BUILD_PATH/config.h"
+ rm -f "$BUILD_PATH/libavcodec/libavcodec.a" "$BUILD_PATH/libavutil/libavutil.a" \
+ "$BUILD_PATH/libpostproc/libpostproc.a"
+ ;;
+ *)
+ mkdir -p "`dirname "$OUTPUT_FILENAME"`"
+ lipo $LIPO_CMDLINE
+ ;;
+esac
diff --git a/contrib/ffmpeg/COPYING b/contrib/ffmpeg/COPYING
new file mode 100644
index 000000000..1e0991447
--- /dev/null
+++ b/contrib/ffmpeg/COPYING
@@ -0,0 +1,504 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL. It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it. You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+ When we speak of free software, we are referring to freedom of use,
+not price. Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+ To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights. These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ To protect each distributor, we want to make it very clear that
+there is no warranty for the free library. Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+ Finally, software patents pose a constant threat to the existence of
+any free program. We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder. Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+ Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License. This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License. We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+ When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library. The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom. The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+ We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License. It also provides other free software developers Less
+of an advantage over competing non-free programs. These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries. However, the Lesser license provides advantages in certain
+special circumstances.
+
+ For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard. To achieve this, non-free programs must be
+allowed to use the library. A more frequent case is that a free
+library does the same job as widely used non-free libraries. In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+ In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software. For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+ Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+ You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+ 2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+ If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+ 6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (1) uses at run time a
+ copy of the library already present on the user's computer system,
+ rather than copying library functions into the executable, and (2)
+ will operate properly with a modified version of the library, if
+ the user installs one, as long as the modified version is
+ interface-compatible with the version that the work was made with.
+
+ c) Accompany the work with a written offer, valid for at
+ least three years, to give the same user the materials
+ specified in Subsection 6a, above, for a charge no more
+ than the cost of performing this distribution.
+
+ d) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ e) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License. However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+ 9. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+ 11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded. In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation. If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission. For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this. Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+ NO WARRANTY
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Libraries
+
+ If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change. You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+ To apply these terms, attach the following notices to the library. It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the library's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
+ library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+ <signature of Ty Coon>, 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
+
+
diff --git a/contrib/ffmpeg/CREDITS b/contrib/ffmpeg/CREDITS
new file mode 100644
index 000000000..f7f086a3c
--- /dev/null
+++ b/contrib/ffmpeg/CREDITS
@@ -0,0 +1,47 @@
+This file contains the name of the people who have contributed to
+FFmpeg. The names are sorted alphabetically by last name.
+
+Michel Bardiaux
+Fabrice Bellard
+Patrice Bensoussan
+Alex Beregszaszi
+BERO
+Mario Brito
+Ronald Bultje
+Maarten Daniels
+Reimar Doeffinger
+Tim Ferguson
+Brian Foley
+Arpad Gereoffy
+Philip Gladstone
+Vladimir Gneushev
+Roine Gustafsson
+David Hammerton
+Wolfgang Hesseler
+Falk Hueffner
+Steven Johnson
+Zdenek Kabelac
+Robin Kay
+Todd Kirby
+Nick Kurshev
+Benjamin Larsson
+Loïc Le Loarer
+Daniel Maas
+Mike Melanson
+Loren Merritt
+Jeff Muizelaar
+Michael Niedermayer
+François Revol
+Peter Ross
+Måns Rullgård
+Roman Shaposhnik
+Oded Shimon
+Dieter Shirley
+Konstantin Shishkov
+Juan J. Sierralta
+Ewald Snel
+Sascha Sommer
+Leon van Stuivenberg
+Roberto Togni
+Lionel Ulmer
+Reynaldo Verdejo
diff --git a/contrib/ffmpeg/Changelog b/contrib/ffmpeg/Changelog
new file mode 100644
index 000000000..0b96efe85
--- /dev/null
+++ b/contrib/ffmpeg/Changelog
@@ -0,0 +1,400 @@
+version <next>
+- DV50 AKA DVCPRO50 encoder, decoder, muxer and demuxer
+- TechSmith Camtasia (TSCC) video decoder
+- IBM Ultimotion (ULTI) video decoder
+- Sierra Online audio file demuxer and decoder
+- Apple QuickDraw (qdrw) video decoder
+- Creative ADPCM audio decoder (16 bits as well as 8 bits schemes)
+- Electronic Arts Multimedia (WVE/UV2/etc.) file demuxer
+- Miro VideoXL (VIXL) video decoder
+- H.261 video encoder
+- QPEG video decoder
+- Nullsoft Video (NSV) file demuxer
+- Shorten audio decoder
+- LOCO video decoder
+- Apple Lossless Audio Codec (ALAC) decoder
+- Winnov WNV1 video decoder
+- Autodesk Animator Studio Codec (AASC) decoder
+- Indeo 2 video decoder
+- Fraps FPS1 video decoder
+- Snow video encoder/decoder
+- Sonic audio encoder/decoder
+- Vorbis audio encoder/decoder
+- Macromedia ADPCM decoder
+- Duck TrueMotion 2 video decoder
+- support for decoding FLX and DTA extensions in FLIC files
+- H.264 custom quantization matrices support
+- ffserver fixed, it should now be usable again
+- QDM2 audio decoder
+- Real Cooker audio decoder
+- TrueSpeech audio decoder
+- WMA2 audio decoder fixed, now all files should play correctly
+- RealAudio 14.4 and 28.8 decoders fixed
+- JPEG-LS encoder and decoder
+- CamStudio video decoder
+- build system improvements
+- tabs and trailing whitespace removed from the codebase
+- AIFF/AIFF-C audio format, encoding and decoding
+- ADTS AAC file reading and writing
+- Creative VOC file reading and writing
+- American Laser Games multimedia (*.mm) playback system
+- Zip Blocks Motion Video decoder and encoder
+- Improved Theora/VP3 decoder
+- True Audio (TTA) decoder
+- AVS demuxer and video decoder
+- Smacker demuxer and decoder
+- NuppelVideo/MythTV demuxer and RTjpeg decoder
+- KMVC decoder
+- MPEG-2 intra vlc support
+- MPEG-2 4:2:2 encoder
+- Flash Screen Video decoder
+- GXF demuxer
+- Chinese AVS decoder
+- GXF muxer
+- MXF demuxer
+- VC-1/WMV3/WMV9 video decoder
+- MacIntel support
+- AVISynth support
+- VMware video decoder
+- VP5 video decoder
+- VP6 video decoder
+- WavPack lossless audio decoder
+- Targa (.TGA) picture decoder
+- Delphine Software .cin demuxer/audio and video decoder
+- Tiertex .seq demuxer/video decoder
+- MTV demuxer
+- TIFF picture decoder
+- GIF picture decoder
+- Intel Music decoder
+- Musepack decoder
+- Flash Screen Video encoder
+- Theora encoding via libtheora
+- BMP encoder
+- WMA encoder
+- GSM-MS encoder and decoder
+- DCA decoder
+- DXA demuxer and decoder
+- DNxHD decoder
+- Gamecube movie (.THP) playback system
+- Blackfin optimizations
+
+version 0.4.9-pre1:
+
+- DV encoder, DV muxer
+- Microsoft RLE video decoder
+- Microsoft Video-1 decoder
+- Apple Animation (RLE) decoder
+- Apple Graphics (SMC) decoder
+- Apple Video (RPZA) decoder
+- Cinepak decoder
+- Sega FILM (CPK) file demuxer
+- Westwood multimedia support (VQA & AUD files)
+- Id Quake II CIN playback support
+- 8BPS video decoder
+- FLIC playback support
+- RealVideo 2.0 (RV20) decoder
+- Duck TrueMotion v1 (DUCK) video decoder
+- Sierra VMD demuxer and video decoder
+- MSZH and ZLIB decoder support
+- SVQ1 video encoder
+- AMR-WB support
+- PPC optimizations
+- rate distortion optimal cbp support
+- rate distorted optimal ac prediction for MPEG-4
+- rate distorted optimal lambda->qp support
+- AAC encoding with libfaac
+- Sunplus JPEG codec (SP5X) support
+- use Lagrange multipler instead of QP for ratecontrol
+- Theora/VP3 decoding support
+- XA and ADX ADPCM codecs
+- export MPEG-2 active display area / pan scan
+- Add support for configuring with IBM XLC
+- floating point AAN DCT
+- initial support for zygo video (not complete)
+- RGB ffv1 support
+- new audio/video parser API
+- av_log() system
+- av_read_frame() and av_seek_frame() support
+- missing last frame fixes
+- seek by mouse in ffplay
+- noise reduction of DCT coefficients
+- H.263 OBMC & 4MV support
+- H.263 alternative inter vlc support
+- H.263 loop filter
+- H.263 slice structured mode
+- interlaced DCT support for MPEG-2 encoding
+- stuffing to stay above min_bitrate
+- MB type & QP visualization
+- frame stepping for ffplay
+- interlaced motion estimation
+- alternate scantable support
+- SVCD scan offset support
+- closed GOP support
+- SSE2 FDCT
+- quantizer noise shaping
+- G.726 ADPCM audio codec
+- MS ADPCM encoding
+- multithreaded/SMP motion estimation
+- multithreaded/SMP encoding for MPEG-1/MPEG-2/MPEG-4/H.263
+- multithreaded/SMP decoding for MPEG-2
+- FLAC decoder
+- Metrowerks CodeWarrior suppport
+- H.263+ custom pcf support
+- nicer output for 'ffmpeg -formats'
+- Matroska demuxer
+- SGI image format, encoding and decoding
+- H.264 loop filter support
+- H.264 CABAC support
+- nicer looking arrows for the motion vector vissualization
+- improved VCD support
+- audio timestamp drift compensation
+- MPEG-2 YUV 422/444 support
+- polyphase kaiser windowed sinc and blackman nuttall windowed sinc audio resample
+- better image scaling
+- H.261 support
+- correctly interleave packets during encoding
+- VIS optimized motion compensation
+- intra_dc_precision>0 encoding support
+- support reuse of motion vectors/MB types/field select values of the source video
+- more accurate deblock filter
+- padding support
+- many optimizations and bugfixes
+
+version 0.4.8:
+
+- MPEG-2 video encoding (Michael)
+- Id RoQ playback subsystem (Mike Melanson and Tim Ferguson)
+- Wing Commander III Movie (.mve) file playback subsystem (Mike Melanson
+ and Mario Brito)
+- Xan DPCM audio decoder (Mario Brito)
+- Interplay MVE playback subsystem (Mike Melanson)
+- Duck DK3 and DK4 ADPCM audio decoders (Mike Melanson)
+
+version 0.4.7:
+
+- RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from mplayerhq
+ (originally from public domain player for Amiga at http://www.honeypot.net/audio)
+- current version now also compiles with older GCC (Fabrice)
+- 4X multimedia playback system including 4xm file demuxer (Mike
+ Melanson), and 4X video and audio codecs (Michael)
+- Creative YUV (CYUV) decoder (Mike Melanson)
+- FFV1 codec (our very simple lossless intra only codec, compresses much better
+ than HuffYUV) (Michael)
+- ASV1 (Asus), H.264, Intel indeo3 codecs have been added (various)
+- tiny PNG encoder and decoder, tiny GIF decoder, PAM decoder (PPM with
+ alpha support), JPEG YUV colorspace support. (Fabrice Bellard)
+- ffplay has been replaced with a newer version which uses SDL (optionally)
+ for multiplatform support (Fabrice)
+- Sorenson Version 3 codec (SVQ3) support has been added (decoding only) - donated
+ by anonymous
+- AMR format has been added (Johannes Carlsson)
+- 3GP support has been added (Johannes Carlsson)
+- VP3 codec has been added (Mike Melanson)
+- more MPEG-1/2 fixes
+- better multiplatform support, MS Visual Studio fixes (various)
+- AltiVec optimizations (Magnus Damn and others)
+- SH4 processor support has been added (BERO)
+- new public interfaces (avcodec_get_pix_fmt) (Roman Shaposhnick)
+- VOB streaming support (Brian Foley)
+- better MP3 autodetection (Andriy Rysin)
+- qpel encoding (Michael)
+- 4mv+b frames encoding finally fixed (Michael)
+- chroma ME (Michael)
+- 5 comparison functions for ME (Michael)
+- B-frame encoding speedup (Michael)
+- WMV2 codec (unfinished - Michael)
+- user specified diamond size for EPZS (Michael)
+- Playstation STR playback subsystem, still experimental (Mike and Michael)
+- ASV2 codec (Michael)
+- CLJR decoder (Alex)
+
+.. And lots more new enhancements and fixes.
+
+version 0.4.6:
+
+- completely new integer only MPEG audio layer 1/2/3 decoder rewritten
+ from scratch
+- Recoded DCT and motion vector search with gcc (no longer depends on nasm)
+- fix quantization bug in AC3 encoder
+- added PCM codecs and format. Corrected WAV/AVI/ASF PCM issues
+- added prototype ffplay program
+- added GOB header parsing on H.263/H.263+ decoder (Juanjo)
+- bug fix on MCBPC tables of H.263 (Juanjo)
+- bug fix on DC coefficients of H.263 (Juanjo)
+- added Advanced Prediction Mode on H.263/H.263+ decoder (Juanjo)
+- now we can decode H.263 streams found in QuickTime files (Juanjo)
+- now we can decode H.263 streams found in VIVO v1 files(Juanjo)
+- preliminary RTP "friendly" mode for H.263/H.263+ coding. (Juanjo)
+- added GOB header for H.263/H.263+ coding on RTP mode (Juanjo)
+- now H.263 picture size is returned on the first decoded frame (Juanjo)
+- added first regression tests
+- added MPEG-2 TS demuxer
+- new demux API for libav
+- more accurate and faster IDCT (Michael)
+- faster and entropy-controlled motion search (Michael)
+- two pass video encoding (Michael)
+- new video rate control (Michael)
+- added MSMPEG4V1, MSMPEGV2 and WMV1 support (Michael)
+- great performance improvement of video encoders and decoders (Michael)
+- new and faster bit readers and vlc parsers (Michael)
+- high quality encoding mode: tries all macroblock/VLC types (Michael)
+- added DV video decoder
+- preliminary RTP/RTSP support in ffserver and libavformat
+- H.263+ AIC decoding/encoding support (Juanjo)
+- VCD MPEG-PS mode (Juanjo)
+- PSNR stuff (Juanjo)
+- simple stats output (Juanjo)
+- 16-bit and 15-bit RGB/BGR/GBR support (Bisqwit)
+
+version 0.4.5:
+
+- some header fixes (Zdenek Kabelac <kabi@informatics.muni.cz>)
+- many MMX optimizations (Nick Kurshev <nickols_k@mail.ru>)
+- added configure system (actually a small shell script)
+- added MPEG audio layer 1/2/3 decoding using LGPL'ed mpglib by
+ Michael Hipp (temporary solution - waiting for integer only
+ decoder)
+- fixed VIDIOCSYNC interrupt
+- added Intel H.263 decoding support ('I263' AVI fourCC)
+- added Real Video 1.0 decoding (needs further testing)
+- simplified image formats again. Added PGM format (=grey
+ pgm). Renamed old PGM to PGMYUV.
+- fixed msmpeg4 slice issues (tell me if you still find problems)
+- fixed OpenDivX bugs with newer versions (added VOL header decoding)
+- added support for MPlayer interface
+- added macroblock skip optimization
+- added MJPEG decoder
+- added mmx/mmxext IDCT from libmpeg2
+- added pgmyuvpipe, ppm, and ppm_pipe formats (original patch by Celer
+ <celer@shell.scrypt.net>)
+- added pixel format conversion layer (e.g. for MJPEG or PPM)
+- added deinterlacing option
+- MPEG-1/2 fixes
+- MPEG-4 vol header fixes (Jonathan Marsden <snmjbm@pacbell.net>)
+- ARM optimizations (Lionel Ulmer <lionel.ulmer@free.fr>).
+- Windows porting of file converter
+- added MJPEG raw format (input/ouput)
+- added JPEG image format support (input/output)
+
+version 0.4.4:
+
+- fixed some std header definitions (Bjorn Lindgren
+ <bjorn.e.lindgren@telia.com>).
+- added MPEG demuxer (MPEG-1 and 2 compatible).
+- added ASF demuxer
+- added prototype RM demuxer
+- added AC3 decoding (done with libac3 by Aaron Holtzman)
+- added decoding codec parameter guessing (.e.g. for MPEG, because the
+ header does not include them)
+- fixed header generation in MPEG-1, AVI and ASF muxer: wmplayer can now
+ play them (only tested video)
+- fixed H.263 white bug
+- fixed phase rounding in img resample filter
+- add MMX code for polyphase img resample filter
+- added CPU autodetection
+- added generic title/author/copyright/comment string handling (ASF and RM
+ use them)
+- added SWF demux to extract MP3 track (not usable yet because no MP3
+ decoder)
+- added fractional frame rate support
+- codecs are no longer searched by read_header() (should fix ffserver
+ segfault)
+
+version 0.4.3:
+
+- BGR24 patch (initial patch by Jeroen Vreeken <pe1rxq@amsat.org>)
+- fixed raw yuv output
+- added motion rounding support in MPEG-4
+- fixed motion bug rounding in MSMPEG4
+- added B-frame handling in video core
+- added full MPEG-1 decoding support
+- added partial (frame only) MPEG-2 support
+- changed the FOURCC code for H.263 to "U263" to be able to see the
+ +AVI/H.263 file with the UB Video H.263+ decoder. MPlayer works with
+ this +codec ;) (JuanJo).
+- Halfpel motion estimation after MB type selection (JuanJo)
+- added pgm and .Y.U.V output format
+- suppressed 'img:' protocol. Simply use: /tmp/test%d.[pgm|Y] as input or
+ output.
+- added pgmpipe I/O format (original patch from Martin Aumueller
+ <lists@reserv.at>, but changed completely since we use a format
+ instead of a protocol)
+
+version 0.4.2:
+
+- added H.263/MPEG-4/MSMPEG4 decoding support. MPEG-4 decoding support
+ (for OpenDivX) is almost complete: 8x8 MVs and rounding are
+ missing. MSMPEG4 support is complete.
+- added prototype MPEG-1 decoder. Only I- and P-frames handled yet (it
+ can decode ffmpeg MPEGs :-)).
+- added libavcodec API documentation (see apiexample.c).
+- fixed image polyphase bug (the bottom of some images could be
+ greenish)
+- added support for non clipped motion vectors (decoding only)
+ and image sizes non-multiple of 16
+- added support for AC prediction (decoding only)
+- added file overwrite confirmation (can be disabled with -y)
+- added custom size picture to H.263 using H.263+ (Juanjo)
+
+version 0.4.1:
+
+- added MSMPEG4 (aka DivX) compatible encoder. Changed default codec
+ of AVI and ASF to DIV3.
+- added -me option to set motion estimation method
+ (default=log). suppressed redundant -hq option.
+- added options -acodec and -vcodec to force a given codec (useful for
+ AVI for example)
+- fixed -an option
+- improved dct_quantize speed
+- factorized some motion estimation code
+
+version 0.4.0:
+
+- removing grab code from ffserver and moved it to ffmpeg. Added
+ multistream support to ffmpeg.
+- added timeshifting support for live feeds (option ?date=xxx in the
+ URL)
+- added high quality image resize code with polyphase filter (need
+ mmx/see optimisation). Enable multiple image size support in ffserver.
+- added multi live feed support in ffserver
+- suppressed master feature from ffserver (it should be done with an
+ external program which opens the .ffm url and writes it to another
+ ffserver)
+- added preliminary support for video stream parsing (WAV and AVI half
+ done). Added proper support for audio/video file conversion in
+ ffmpeg.
+- added preliminary support for video file sending from ffserver
+- redesigning I/O subsystem: now using URL based input and output
+ (see avio.h)
+- added WAV format support
+- added "tty user interface" to ffmpeg to stop grabbing gracefully
+- added MMX/SSE optimizations to SAD (Sums of Absolutes Differences)
+ (Juan J. Sierralta P. a.k.a. "Juanjo" <juanjo@atmlab.utfsm.cl>)
+- added MMX DCT from mpeg2_movie 1.5 (Juanjo)
+- added new motion estimation algorithms, log and phods (Juanjo)
+- changed directories: libav for format handling, libavcodec for
+ codecs
+
+version 0.3.4:
+
+- added stereo in MPEG audio encoder
+
+version 0.3.3:
+
+- added 'high quality' mode which use motion vectors. It can be used in
+ real time at low resolution.
+- fixed rounding problems which caused quality problems at high
+ bitrates and large GOP size
+
+version 0.3.2: small fixes
+
+- ASF fixes
+- put_seek bug fix
+
+version 0.3.1: added avi/divx support
+
+- added AVI support
+- added MPEG-4 codec compatible with OpenDivX. It is based on the H.263 codec
+- added sound for flash format (not tested)
+
+version 0.3: initial public release
diff --git a/contrib/ffmpeg/Doxyfile b/contrib/ffmpeg/Doxyfile
new file mode 100644
index 000000000..9e4fdcdd0
--- /dev/null
+++ b/contrib/ffmpeg/Doxyfile
@@ -0,0 +1,1038 @@
+# Doxyfile 1.3-rc1
+
+# This file describes the settings to be used by the documentation system
+# doxygen (www.doxygen.org) for a project
+#
+# All text after a hash (#) is considered a comment and will be ignored
+# The format is:
+# TAG = value [value, ...]
+# For lists items can also be appended using:
+# TAG += value [value, ...]
+# Values that contain spaces should be placed between quotes (" ")
+
+#---------------------------------------------------------------------------
+# General configuration options
+#---------------------------------------------------------------------------
+
+# The PROJECT_NAME tag is a single word (or a sequence of words surrounded
+# by quotes) that should identify the project.
+
+PROJECT_NAME = ffmpeg
+
+# The PROJECT_NUMBER tag can be used to enter a project or revision number.
+# This could be handy for archiving the generated documentation or
+# if some version control system is used.
+
+PROJECT_NUMBER =
+
+# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
+# base path where the generated documentation will be put.
+# If a relative path is entered, it will be relative to the location
+# where doxygen was started. If left blank the current directory will be used.
+
+OUTPUT_DIRECTORY = doxy
+
+# The OUTPUT_LANGUAGE tag is used to specify the language in which all
+# documentation generated by doxygen is written. Doxygen will use this
+# information to generate all constant output in the proper language.
+# The default language is English, other supported languages are:
+# Brazilian, Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, Dutch,
+# Finnish, French, German, Greek, Hungarian, Italian, Japanese, Japanese-en
+# (Japanese with english messages), Korean, Norwegian, Polish, Portuguese,
+# Romanian, Russian, Serbian, Slovak, Slovene, Spanish, Swedish and Ukrainian.
+
+OUTPUT_LANGUAGE = English
+
+# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in
+# documentation are documented, even if no documentation was available.
+# Private class members and static file members will be hidden unless
+# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES
+
+EXTRACT_ALL = YES
+
+# If the EXTRACT_PRIVATE tag is set to YES all private members of a class
+# will be included in the documentation.
+
+EXTRACT_PRIVATE = YES
+
+# If the EXTRACT_STATIC tag is set to YES all static members of a file
+# will be included in the documentation.
+
+EXTRACT_STATIC = YES
+
+# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs)
+# defined locally in source files will be included in the documentation.
+# If set to NO only classes defined in header files are included.
+
+EXTRACT_LOCAL_CLASSES = YES
+
+# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all
+# undocumented members of documented classes, files or namespaces.
+# If set to NO (the default) these members will be included in the
+# various overviews, but no documentation section is generated.
+# This option has no effect if EXTRACT_ALL is enabled.
+
+HIDE_UNDOC_MEMBERS = NO
+
+# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all
+# undocumented classes that are normally visible in the class hierarchy.
+# If set to NO (the default) these class will be included in the various
+# overviews. This option has no effect if EXTRACT_ALL is enabled.
+
+HIDE_UNDOC_CLASSES = NO
+
+# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all
+# friend (class|struct|union) declarations.
+# If set to NO (the default) these declarations will be included in the
+# documentation.
+
+HIDE_FRIEND_COMPOUNDS = NO
+
+# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any
+# documentation blocks found inside the body of a function.
+# If set to NO (the default) these blocks will be appended to the
+# function's detailed documentation block.
+
+HIDE_IN_BODY_DOCS = NO
+
+# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will
+# include brief member descriptions after the members that are listed in
+# the file and class documentation (similar to JavaDoc).
+# Set to NO to disable this.
+
+BRIEF_MEMBER_DESC = YES
+
+# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend
+# the brief description of a member or function before the detailed description.
+# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the
+# brief descriptions will be completely suppressed.
+
+REPEAT_BRIEF = YES
+
+# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then
+# Doxygen will generate a detailed section even if there is only a brief
+# description.
+
+ALWAYS_DETAILED_SEC = NO
+
+# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all inherited
+# members of a class in the documentation of that class as if those members were
+# ordinary class members. Constructors, destructors and assignment operators of
+# the base classes will not be shown.
+
+INLINE_INHERITED_MEMB = NO
+
+# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full
+# path before files name in the file list and in the header files. If set
+# to NO the shortest path that makes the file name unique will be used.
+
+FULL_PATH_NAMES = YES
+
+# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag
+# can be used to strip a user defined part of the path. Stripping is
+# only done if one of the specified strings matches the left-hand part of
+# the path. It is allowed to use relative paths in the argument list.
+
+STRIP_FROM_PATH = .
+
+# The INTERNAL_DOCS tag determines if documentation
+# that is typed after a \internal command is included. If the tag is set
+# to NO (the default) then the documentation will be excluded.
+# Set it to YES to include the internal documentation.
+
+INTERNAL_DOCS = NO
+
+# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate
+# file names in lower case letters. If set to YES upper case letters are also
+# allowed. This is useful if you have classes or files whose names only differ
+# in case and if your file system supports case sensitive file names. Windows
+# users are adviced to set this option to NO.
+
+CASE_SENSE_NAMES = YES
+
+# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter
+# (but less readable) file names. This can be useful is your file systems
+# doesn't support long names like on DOS, Mac, or CD-ROM.
+
+SHORT_NAMES = NO
+
+# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen
+# will show members with their full class and namespace scopes in the
+# documentation. If set to YES the scope will be hidden.
+
+HIDE_SCOPE_NAMES = NO
+
+# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen
+# will generate a verbatim copy of the header file for each class for
+# which an include is specified. Set to NO to disable this.
+
+VERBATIM_HEADERS = YES
+
+# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen
+# will put list of the files that are included by a file in the documentation
+# of that file.
+
+SHOW_INCLUDE_FILES = YES
+
+# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen
+# will interpret the first line (until the first dot) of a JavaDoc-style
+# comment as the brief description. If set to NO, the JavaDoc
+# comments will behave just like the Qt-style comments (thus requiring an
+# explict @brief command for a brief description.
+
+JAVADOC_AUTOBRIEF = YES
+
+# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen
+# treat a multi-line C++ special comment block (i.e. a block of //! or ///
+# comments) as a brief description. This used to be the default behaviour.
+# The new default is to treat a multi-line C++ comment block as a detailed
+# description. Set this tag to YES if you prefer the old behaviour instead.
+
+MULTILINE_CPP_IS_BRIEF = NO
+
+# If the DETAILS_AT_TOP tag is set to YES then Doxygen
+# will output the detailed description near the top, like JavaDoc.
+# If set to NO, the detailed description appears after the member
+# documentation.
+
+DETAILS_AT_TOP = NO
+
+# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented
+# member inherits the documentation from any documented member that it
+# reimplements.
+
+INHERIT_DOCS = YES
+
+# If the INLINE_INFO tag is set to YES (the default) then a tag [inline]
+# is inserted in the documentation for inline members.
+
+INLINE_INFO = YES
+
+# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen
+# will sort the (detailed) documentation of file and class members
+# alphabetically by member name. If set to NO the members will appear in
+# declaration order.
+
+SORT_MEMBER_DOCS = YES
+
+# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC
+# tag is set to YES, then doxygen will reuse the documentation of the first
+# member in the group (if any) for the other members of the group. By default
+# all members of a group must be documented explicitly.
+
+DISTRIBUTE_GROUP_DOC = NO
+
+# The TAB_SIZE tag can be used to set the number of spaces in a tab.
+# Doxygen uses this value to replace tabs by spaces in code fragments.
+
+TAB_SIZE = 8
+
+# The GENERATE_TODOLIST tag can be used to enable (YES) or
+# disable (NO) the todo list. This list is created by putting \todo
+# commands in the documentation.
+
+GENERATE_TODOLIST = YES
+
+# The GENERATE_TESTLIST tag can be used to enable (YES) or
+# disable (NO) the test list. This list is created by putting \test
+# commands in the documentation.
+
+GENERATE_TESTLIST = YES
+
+# The GENERATE_BUGLIST tag can be used to enable (YES) or
+# disable (NO) the bug list. This list is created by putting \bug
+# commands in the documentation.
+
+GENERATE_BUGLIST = YES
+
+# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or
+# disable (NO) the deprecated list. This list is created by putting
+# \deprecated commands in the documentation.
+
+GENERATE_DEPRECATEDLIST= YES
+
+# This tag can be used to specify a number of aliases that acts
+# as commands in the documentation. An alias has the form "name=value".
+# For example adding "sideeffect=\par Side Effects:\n" will allow you to
+# put the command \sideeffect (or @sideeffect) in the documentation, which
+# will result in a user defined paragraph with heading "Side Effects:".
+# You can put \n's in the value part of an alias to insert newlines.
+
+ALIASES =
+
+# The ENABLED_SECTIONS tag can be used to enable conditional
+# documentation sections, marked by \if sectionname ... \endif.
+
+ENABLED_SECTIONS =
+
+# The MAX_INITIALIZER_LINES tag determines the maximum number of lines
+# the initial value of a variable or define consist of for it to appear in
+# the documentation. If the initializer consists of more lines than specified
+# here it will be hidden. Use a value of 0 to hide initializers completely.
+# The appearance of the initializer of individual variables and defines in the
+# documentation can be controlled using \showinitializer or \hideinitializer
+# command in the documentation regardless of this setting.
+
+MAX_INITIALIZER_LINES = 30
+
+# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources
+# only. Doxygen will then generate output that is more tailored for C.
+# For instance some of the names that are used will be different. The list
+# of all members will be omitted, etc.
+
+OPTIMIZE_OUTPUT_FOR_C = YES
+
+# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java sources
+# only. Doxygen will then generate output that is more tailored for Java.
+# For instance namespaces will be presented as packages, qualified scopes
+# will look different, etc.
+
+OPTIMIZE_OUTPUT_JAVA = NO
+
+# Set the SHOW_USED_FILES tag to NO to disable the list of files generated
+# at the bottom of the documentation of classes and structs. If set to YES the
+# list will mention the files that were used to generate the documentation.
+
+SHOW_USED_FILES = YES
+
+#---------------------------------------------------------------------------
+# configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+
+# The QUIET tag can be used to turn on/off the messages that are generated
+# by doxygen. Possible values are YES and NO. If left blank NO is used.
+
+QUIET = NO
+
+# The WARNINGS tag can be used to turn on/off the warning messages that are
+# generated by doxygen. Possible values are YES and NO. If left blank
+# NO is used.
+
+WARNINGS = YES
+
+# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings
+# for undocumented members. If EXTRACT_ALL is set to YES then this flag will
+# automatically be disabled.
+
+WARN_IF_UNDOCUMENTED = YES
+
+# The WARN_FORMAT tag determines the format of the warning messages that
+# doxygen can produce. The string should contain the $file, $line, and $text
+# tags, which will be replaced by the file and line number from which the
+# warning originated and the warning text.
+
+WARN_FORMAT = "$file:$line: $text"
+
+# The WARN_LOGFILE tag can be used to specify a file to which warning
+# and error messages should be written. If left blank the output is written
+# to stderr.
+
+WARN_LOGFILE =
+
+#---------------------------------------------------------------------------
+# configuration options related to the input files
+#---------------------------------------------------------------------------
+
+# The INPUT tag can be used to specify the files and/or directories that contain
+# documented source files. You may enter file names like "myfile.cpp" or
+# directories like "/usr/src/myproject". Separate the files or directories
+# with spaces.
+
+INPUT =
+
+# If the value of the INPUT tag contains directories, you can use the
+# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
+# and *.h) to filter out the source-files in the directories. If left
+# blank the following patterns are tested:
+# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx *.hpp
+# *.h++ *.idl *.odl
+
+FILE_PATTERNS =
+
+# The RECURSIVE tag can be used to turn specify whether or not subdirectories
+# should be searched for input files as well. Possible values are YES and NO.
+# If left blank NO is used.
+
+RECURSIVE = YES
+
+# The EXCLUDE tag can be used to specify files and/or directories that should
+# excluded from the INPUT source files. This way you can easily exclude a
+# subdirectory from a directory tree whose root is specified with the INPUT tag.
+
+EXCLUDE =
+
+# The EXCLUDE_SYMLINKS tag can be used select whether or not files or directories
+# that are symbolic links (a Unix filesystem feature) are excluded from the input.
+
+EXCLUDE_SYMLINKS = NO
+
+# If the value of the INPUT tag contains directories, you can use the
+# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
+# certain files from those directories.
+
+EXCLUDE_PATTERNS =
+
+# The EXAMPLE_PATH tag can be used to specify one or more files or
+# directories that contain example code fragments that are included (see
+# the \include command).
+
+EXAMPLE_PATH =
+
+# If the value of the EXAMPLE_PATH tag contains directories, you can use the
+# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
+# and *.h) to filter out the source-files in the directories. If left
+# blank all files are included.
+
+EXAMPLE_PATTERNS =
+
+# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be
+# searched for input files to be used with the \include or \dontinclude
+# commands irrespective of the value of the RECURSIVE tag.
+# Possible values are YES and NO. If left blank NO is used.
+
+EXAMPLE_RECURSIVE = NO
+
+# The IMAGE_PATH tag can be used to specify one or more files or
+# directories that contain image that are included in the documentation (see
+# the \image command).
+
+IMAGE_PATH =
+
+# The INPUT_FILTER tag can be used to specify a program that doxygen should
+# invoke to filter for each input file. Doxygen will invoke the filter program
+# by executing (via popen()) the command <filter> <input-file>, where <filter>
+# is the value of the INPUT_FILTER tag, and <input-file> is the name of an
+# input file. Doxygen will then use the output that the filter program writes
+# to standard output.
+
+INPUT_FILTER =
+
+# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using
+# INPUT_FILTER) will be used to filter the input files when producing source
+# files to browse (i.e. when SOURCE_BROWSER is set to YES).
+
+FILTER_SOURCE_FILES = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to source browsing
+#---------------------------------------------------------------------------
+
+# If the SOURCE_BROWSER tag is set to YES then a list of source files will
+# be generated. Documented entities will be cross-referenced with these sources.
+
+SOURCE_BROWSER = YES
+
+# Setting the INLINE_SOURCES tag to YES will include the body
+# of functions and classes directly in the documentation.
+
+INLINE_SOURCES = NO
+
+# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct
+# doxygen to hide any special comment blocks from generated source code
+# fragments. Normal C and C++ comments will always remain visible.
+
+STRIP_CODE_COMMENTS = YES
+
+# If the REFERENCED_BY_RELATION tag is set to YES (the default)
+# then for each documented function all documented
+# functions referencing it will be listed.
+
+REFERENCED_BY_RELATION = YES
+
+# If the REFERENCES_RELATION tag is set to YES (the default)
+# then for each documented function all documented entities
+# called/used by that function will be listed.
+
+REFERENCES_RELATION = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+
+# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index
+# of all compounds will be generated. Enable this if the project
+# contains a lot of classes, structs, unions or interfaces.
+
+ALPHABETICAL_INDEX = YES
+
+# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then
+# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns
+# in which this list will be split (can be a number in the range [1..20])
+
+COLS_IN_ALPHA_INDEX = 5
+
+# In case all classes in a project start with a common prefix, all
+# classes will be put under the same header in the alphabetical index.
+# The IGNORE_PREFIX tag can be used to specify one or more prefixes that
+# should be ignored while generating the index headers.
+
+IGNORE_PREFIX =
+
+#---------------------------------------------------------------------------
+# configuration options related to the HTML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_HTML tag is set to YES (the default) Doxygen will
+# generate HTML output.
+
+GENERATE_HTML = YES
+
+# The HTML_OUTPUT tag is used to specify where the HTML docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `html' will be used as the default path.
+
+HTML_OUTPUT = html
+
+# The HTML_FILE_EXTENSION tag can be used to specify the file extension for
+# each generated HTML page (for example: .htm,.php,.asp). If it is left blank
+# doxygen will generate files with .html extension.
+
+HTML_FILE_EXTENSION = .html
+
+# The HTML_HEADER tag can be used to specify a personal HTML header for
+# each generated HTML page. If it is left blank doxygen will generate a
+# standard header.
+
+HTML_HEADER =
+
+# The HTML_FOOTER tag can be used to specify a personal HTML footer for
+# each generated HTML page. If it is left blank doxygen will generate a
+# standard footer.
+
+HTML_FOOTER =
+
+# The HTML_STYLESHEET tag can be used to specify a user defined cascading
+# style sheet that is used by each HTML page. It can be used to
+# fine-tune the look of the HTML output. If the tag is left blank doxygen
+# will generate a default style sheet
+
+HTML_STYLESHEET =
+
+# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes,
+# files or namespaces will be aligned in HTML using tables. If set to
+# NO a bullet list will be used.
+
+HTML_ALIGN_MEMBERS = YES
+
+# If the GENERATE_HTMLHELP tag is set to YES, additional index files
+# will be generated that can be used as input for tools like the
+# Microsoft HTML help workshop to generate a compressed HTML help file (.chm)
+# of the generated HTML documentation.
+
+GENERATE_HTMLHELP = NO
+
+# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can
+# be used to specify the file name of the resulting .chm file. You
+# can add a path in front of the file if the result should not be
+# written to the html output dir.
+
+CHM_FILE =
+
+# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can
+# be used to specify the location (absolute path including file name) of
+# the HTML help compiler (hhc.exe). If non empty doxygen will try to run
+# the html help compiler on the generated index.hhp.
+
+HHC_LOCATION =
+
+# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag
+# controls if a separate .chi index file is generated (YES) or that
+# it should be included in the master .chm file (NO).
+
+GENERATE_CHI = NO
+
+# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag
+# controls whether a binary table of contents is generated (YES) or a
+# normal table of contents (NO) in the .chm file.
+
+BINARY_TOC = NO
+
+# The TOC_EXPAND flag can be set to YES to add extra items for group members
+# to the contents of the Html help documentation and to the tree view.
+
+TOC_EXPAND = NO
+
+# The DISABLE_INDEX tag can be used to turn on/off the condensed index at
+# top of each HTML page. The value NO (the default) enables the index and
+# the value YES disables it.
+
+DISABLE_INDEX = NO
+
+# This tag can be used to set the number of enum values (range [1..20])
+# that doxygen will group on one line in the generated HTML documentation.
+
+ENUM_VALUES_PER_LINE = 4
+
+# If the GENERATE_TREEVIEW tag is set to YES, a side panel will be
+# generated containing a tree-like index structure (just like the one that
+# is generated for HTML Help). For this to work a browser that supports
+# JavaScript and frames is required (for instance Mozilla, Netscape 4.0+,
+# or Internet explorer 4.0+). Note that for large projects the tree generation
+# can take a very long time. In such cases it is better to disable this feature.
+# Windows users are probably better off using the HTML help feature.
+
+GENERATE_TREEVIEW = NO
+
+# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be
+# used to set the initial width (in pixels) of the frame in which the tree
+# is shown.
+
+TREEVIEW_WIDTH = 250
+
+#---------------------------------------------------------------------------
+# configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will
+# generate Latex output.
+
+GENERATE_LATEX = YES
+
+# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `latex' will be used as the default path.
+
+LATEX_OUTPUT = latex
+
+# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be
+# invoked. If left blank `latex' will be used as the default command name.
+
+LATEX_CMD_NAME = latex
+
+# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to
+# generate index for LaTeX. If left blank `makeindex' will be used as the
+# default command name.
+
+MAKEINDEX_CMD_NAME = makeindex
+
+# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact
+# LaTeX documents. This may be useful for small projects and may help to
+# save some trees in general.
+
+COMPACT_LATEX = NO
+
+# The PAPER_TYPE tag can be used to set the paper type that is used
+# by the printer. Possible values are: a4, a4wide, letter, legal and
+# executive. If left blank a4wide will be used.
+
+PAPER_TYPE = a4wide
+
+# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX
+# packages that should be included in the LaTeX output.
+
+EXTRA_PACKAGES =
+
+# The LATEX_HEADER tag can be used to specify a personal LaTeX header for
+# the generated latex document. The header should contain everything until
+# the first chapter. If it is left blank doxygen will generate a
+# standard header. Notice: only use this tag if you know what you are doing!
+
+LATEX_HEADER =
+
+# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated
+# is prepared for conversion to pdf (using ps2pdf). The pdf file will
+# contain links (just like the HTML output) instead of page references
+# This makes the output suitable for online browsing using a pdf viewer.
+
+PDF_HYPERLINKS = NO
+
+# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of
+# plain latex in the generated Makefile. Set this option to YES to get a
+# higher quality PDF documentation.
+
+USE_PDFLATEX = NO
+
+# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode.
+# command to the generated LaTeX files. This will instruct LaTeX to keep
+# running if errors occur, instead of asking the user for help.
+# This option is also used when generating formulas in HTML.
+
+LATEX_BATCHMODE = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the RTF output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output
+# The RTF output is optimised for Word 97 and may not look very pretty with
+# other RTF readers or editors.
+
+GENERATE_RTF = NO
+
+# The RTF_OUTPUT tag is used to specify where the RTF docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `rtf' will be used as the default path.
+
+RTF_OUTPUT = rtf
+
+# If the COMPACT_RTF tag is set to YES Doxygen generates more compact
+# RTF documents. This may be useful for small projects and may help to
+# save some trees in general.
+
+COMPACT_RTF = NO
+
+# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated
+# will contain hyperlink fields. The RTF file will
+# contain links (just like the HTML output) instead of page references.
+# This makes the output suitable for online browsing using WORD or other
+# programs which support those fields.
+# Note: wordpad (write) and others do not support links.
+
+RTF_HYPERLINKS = NO
+
+# Load stylesheet definitions from file. Syntax is similar to doxygen's
+# config file, i.e. a series of assigments. You only have to provide
+# replacements, missing definitions are set to their default value.
+
+RTF_STYLESHEET_FILE =
+
+# Set optional variables used in the generation of an rtf document.
+# Syntax is similar to doxygen's config file.
+
+RTF_EXTENSIONS_FILE =
+
+#---------------------------------------------------------------------------
+# configuration options related to the man page output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_MAN tag is set to YES (the default) Doxygen will
+# generate man pages
+
+GENERATE_MAN = NO
+
+# The MAN_OUTPUT tag is used to specify where the man pages will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `man' will be used as the default path.
+
+MAN_OUTPUT = man
+
+# The MAN_EXTENSION tag determines the extension that is added to
+# the generated man pages (default is the subroutine's section .3)
+
+MAN_EXTENSION = .3
+
+# If the MAN_LINKS tag is set to YES and Doxygen generates man output,
+# then it will generate one additional man file for each entity
+# documented in the real man page(s). These additional files
+# only source the real man page, but without them the man command
+# would be unable to find the correct page. The default is NO.
+
+MAN_LINKS = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the XML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_XML tag is set to YES Doxygen will
+# generate an XML file that captures the structure of
+# the code including all documentation. Note that this
+# feature is still experimental and incomplete at the
+# moment.
+
+GENERATE_XML = NO
+
+# The XML_SCHEMA tag can be used to specify an XML schema,
+# which can be used by a validating XML parser to check the
+# syntax of the XML files.
+
+XML_SCHEMA =
+
+# The XML_DTD tag can be used to specify an XML DTD,
+# which can be used by a validating XML parser to check the
+# syntax of the XML files.
+
+XML_DTD =
+
+#---------------------------------------------------------------------------
+# configuration options for the AutoGen Definitions output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will
+# generate an AutoGen Definitions (see autogen.sf.net) file
+# that captures the structure of the code including all
+# documentation. Note that this feature is still experimental
+# and incomplete at the moment.
+
+GENERATE_AUTOGEN_DEF = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the Perl module output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_PERLMOD tag is set to YES Doxygen will
+# generate a Perl module file that captures the structure of
+# the code including all documentation. Note that this
+# feature is still experimental and incomplete at the
+# moment.
+
+GENERATE_PERLMOD = NO
+
+# If the PERLMOD_LATEX tag is set to YES Doxygen will generate
+# the necessary Makefile rules, Perl scripts and LaTeX code to be able
+# to generate PDF and DVI output from the Perl module output.
+
+PERLMOD_LATEX = NO
+
+# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be
+# nicely formatted so it can be parsed by a human reader. This is useful
+# if you want to understand what is going on. On the other hand, if this
+# tag is set to NO the size of the Perl module output will be much smaller
+# and Perl will parse it just the same.
+
+PERLMOD_PRETTY = YES
+
+# The names of the make variables in the generated doxyrules.make file
+# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX.
+# This is useful so different doxyrules.make files included by the same
+# Makefile don't overwrite each other's variables.
+
+PERLMOD_MAKEVAR_PREFIX =
+
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor
+#---------------------------------------------------------------------------
+
+# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will
+# evaluate all C-preprocessor directives found in the sources and include
+# files.
+
+ENABLE_PREPROCESSING = YES
+
+# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro
+# names in the source code. If set to NO (the default) only conditional
+# compilation will be performed. Macro expansion can be done in a controlled
+# way by setting EXPAND_ONLY_PREDEF to YES.
+
+MACRO_EXPANSION = YES
+
+# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES
+# then the macro expansion is limited to the macros specified with the
+# PREDEFINED and EXPAND_AS_PREDEFINED tags.
+
+EXPAND_ONLY_PREDEF = YES
+
+# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files
+# in the INCLUDE_PATH (see below) will be search if a #include is found.
+
+SEARCH_INCLUDES = YES
+
+# The INCLUDE_PATH tag can be used to specify one or more directories that
+# contain include files that are not input files but should be processed by
+# the preprocessor.
+
+INCLUDE_PATH =
+
+# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard
+# patterns (like *.h and *.hpp) to filter out the header-files in the
+# directories. If left blank, the patterns specified with FILE_PATTERNS will
+# be used.
+
+INCLUDE_FILE_PATTERNS =
+
+# The PREDEFINED tag can be used to specify one or more macro names that
+# are defined before the preprocessor is started (similar to the -D option of
+# gcc). The argument of the tag is a list of macros of the form: name
+# or name=definition (no spaces). If the definition and the = are
+# omitted =1 is assumed.
+
+PREDEFINED = __attribute__(x)="" "RENAME(x)=x ## _TMPL" "DEF(x)=x ## _TMPL" \
+ HAVE_AV_CONFIG_H HAVE_MMX HAVE_MMX2 HAVE_3DNOW \
+ ATTR_ALIGN(x)=""
+
+# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
+# this tag can be used to specify a list of macro names that should be expanded.
+# The macro definition that is found in the sources will be used.
+# Use the PREDEFINED tag if you want to use a different macro definition.
+
+#EXPAND_AS_DEFINED = FF_COMMON_FRAME
+EXPAND_AS_DEFINED = declare_idct(idct, table, idct_row_head, idct_row, idct_row_tail, idct_row_mid)
+
+# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then
+# doxygen's preprocessor will remove all function-like macros that are alone
+# on a line, have an all uppercase name, and do not end with a semicolon. Such
+# function macros are typically used for boiler-plate code, and will confuse the
+# parser if not removed.
+
+SKIP_FUNCTION_MACROS = YES
+
+#---------------------------------------------------------------------------
+# Configuration::addtions related to external references
+#---------------------------------------------------------------------------
+
+# The TAGFILES tag can be used to specify one or more tagfiles.
+
+TAGFILES =
+
+# When a file name is specified after GENERATE_TAGFILE, doxygen will create
+# a tag file that is based on the input files it reads.
+
+GENERATE_TAGFILE =
+
+# If the ALLEXTERNALS tag is set to YES all external classes will be listed
+# in the class index. If set to NO only the inherited external classes
+# will be listed.
+
+ALLEXTERNALS = NO
+
+# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed
+# in the modules index. If set to NO, only the current project's groups will
+# be listed.
+
+EXTERNAL_GROUPS = YES
+
+# The PERL_PATH should be the absolute path and name of the perl script
+# interpreter (i.e. the result of `which perl').
+
+PERL_PATH = /usr/bin/perl
+
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool
+#---------------------------------------------------------------------------
+
+# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will
+# generate a inheritance diagram (in Html, RTF and LaTeX) for classes with base or
+# super classes. Setting the tag to NO turns the diagrams off. Note that this
+# option is superceded by the HAVE_DOT option below. This is only a fallback. It is
+# recommended to install and use dot, since it yield more powerful graphs.
+
+CLASS_DIAGRAMS = YES
+
+# If set to YES, the inheritance and collaboration graphs will hide
+# inheritance and usage relations if the target is undocumented
+# or is not a class.
+
+HIDE_UNDOC_RELATIONS = YES
+
+# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is
+# available from the path. This tool is part of Graphviz, a graph visualization
+# toolkit from AT&T and Lucent Bell Labs. The other options in this section
+# have no effect if this option is set to NO (the default)
+
+HAVE_DOT = NO
+
+# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for each documented class showing the direct and
+# indirect inheritance relations. Setting this tag to YES will force the
+# the CLASS_DIAGRAMS tag to NO.
+
+CLASS_GRAPH = YES
+
+# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for each documented class showing the direct and
+# indirect implementation dependencies (inheritance, containment, and
+# class references variables) of the class with other documented classes.
+
+COLLABORATION_GRAPH = YES
+
+# If set to YES, the inheritance and collaboration graphs will show the
+# relations between templates and their instances.
+
+TEMPLATE_RELATIONS = YES
+
+# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT
+# tags are set to YES then doxygen will generate a graph for each documented
+# file showing the direct and indirect include dependencies of the file with
+# other documented files.
+
+INCLUDE_GRAPH = YES
+
+# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and
+# HAVE_DOT tags are set to YES then doxygen will generate a graph for each
+# documented header file showing the documented files that directly or
+# indirectly include this file.
+
+INCLUDED_BY_GRAPH = YES
+
+# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen
+# will graphical hierarchy of all classes instead of a textual one.
+
+GRAPHICAL_HIERARCHY = YES
+
+# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images
+# generated by dot. Possible values are png, jpg, or gif
+# If left blank png will be used.
+
+DOT_IMAGE_FORMAT = png
+
+# The tag DOT_PATH can be used to specify the path where the dot tool can be
+# found. If left blank, it is assumed the dot tool can be found on the path.
+
+DOT_PATH =
+
+# The DOTFILE_DIRS tag can be used to specify one or more directories that
+# contain dot files that are included in the documentation (see the
+# \dotfile command).
+
+DOTFILE_DIRS =
+
+# The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width
+# (in pixels) of the graphs generated by dot. If a graph becomes larger than
+# this value, doxygen will try to truncate the graph, so that it fits within
+# the specified constraint. Beware that most browsers cannot cope with very
+# large images.
+
+MAX_DOT_GRAPH_WIDTH = 1024
+
+# The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height
+# (in pixels) of the graphs generated by dot. If a graph becomes larger than
+# this value, doxygen will try to truncate the graph, so that it fits within
+# the specified constraint. Beware that most browsers cannot cope with very
+# large images.
+
+MAX_DOT_GRAPH_HEIGHT = 1024
+
+# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will
+# generate a legend page explaining the meaning of the various boxes and
+# arrows in the dot generated graphs.
+
+GENERATE_LEGEND = YES
+
+# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will
+# remove the intermedate dot files that are used to generate
+# the various graphs.
+
+DOT_CLEANUP = YES
+
+#---------------------------------------------------------------------------
+# Configuration::addtions related to the search engine
+#---------------------------------------------------------------------------
+
+# The SEARCHENGINE tag specifies whether or not a search engine should be
+# used. If set to NO the values of all tags below this one will be ignored.
+
+SEARCHENGINE = NO
+
+# The CGI_NAME tag should be the name of the CGI script that
+# starts the search engine (doxysearch) with the correct parameters.
+# A script with this name will be generated by doxygen.
+
+CGI_NAME = search.cgi
+
+# The CGI_URL tag should be the absolute URL to the directory where the
+# cgi binaries are located. See the documentation of your http daemon for
+# details.
+
+CGI_URL =
+
+# The DOC_URL tag should be the absolute URL to the directory where the
+# documentation is located. If left blank the absolute path to the
+# documentation, with file:// prepended to it, will be used.
+
+DOC_URL =
+
+# The DOC_ABSPATH tag should be the absolute path to the directory where the
+# documentation is located. If left blank the directory on the local machine
+# will be used.
+
+DOC_ABSPATH =
+
+# The BIN_ABSPATH tag must point to the directory where the doxysearch binary
+# is installed.
+
+BIN_ABSPATH = /usr/local/bin/
+
+# The EXT_DOC_PATHS tag can be used to specify one or more paths to
+# documentation generated for other projects. This allows doxysearch to search
+# the documentation for these projects as well.
+
+EXT_DOC_PATHS =
diff --git a/contrib/ffmpeg/INSTALL b/contrib/ffmpeg/INSTALL
new file mode 100644
index 000000000..a636c5367
--- /dev/null
+++ b/contrib/ffmpeg/INSTALL
@@ -0,0 +1,14 @@
+
+1) Type './configure' create the configuration (use './configure
+--help' to have the configure options).
+
+'configure' can be launched from another directory than the ffmpeg
+sources to put the objects at that place. In that case, use an
+absolute path when launching 'configure',
+e.g. /ffmpegdir/ffmpeg/configure.
+
+2) Then type 'make' to build ffmpeg. On BSD systems, type 'gmake'
+instead of 'make'. You may need to install GNU make first.
+
+3) Type 'make install' to install ffmpeg and ffserver in
+/usr/local/bin.
diff --git a/contrib/ffmpeg/MAINTAINERS b/contrib/ffmpeg/MAINTAINERS
new file mode 100644
index 000000000..beff7bb76
--- /dev/null
+++ b/contrib/ffmpeg/MAINTAINERS
@@ -0,0 +1,254 @@
+FFmpeg maintainers
+==================
+
+Below is a list of the people maintaining different parts of the
+FFmpeg code.
+
+
+Project Leader
+==============
+
+Michael Niedermayer
+ final design decisions
+
+
+Applications
+============
+
+ffmpeg:
+ ffmpeg.c Michael Niedermayer
+
+ Video Hooks:
+ vhook
+ vhook/watermark.c Marcus Engene
+ vhook/ppm.c
+ vhook/drawtext.c
+ vhook/fish.c
+ vhook/null.c
+ vhook/imlib2.c
+
+ffplay:
+ ffplay.c
+
+ffserver:
+ ffserver.c, ffserver.h Alex Beregszaszi
+
+Commandline utility code:
+ cmdutils.c, cmdutils.h
+
+QuickTime faststart:
+ qt-faststart.c Mike Melanson
+
+
+Miscellaneous Areas
+===================
+
+documentation Mike Melanson, Diego Biurrun
+website Mike Melanson, Diego Biurrun
+build system (configure,Makefiles) Diego Biurrun, Mans Rullgard
+project server Diego Biurrun, Mans Rullgard
+mailinglists Michael Niedermayer, Baptiste Coudurier
+
+
+libavutil
+=========
+
+External Interfaces:
+ libavutil/avutil.h
+Internal Interfaces:
+ libavutil/common.h
+
+Other:
+ intfloat* Michael Niedermayer
+ rational.c, rational.h Michael Niedermayer
+ mathematics.c, mathematics.h Michael Niedermayer
+ integer.c, integer.h Michael Niedermayer
+ bswap.h
+
+
+libavcodec
+==========
+
+Generic Parts:
+ External Interfaces:
+ avcodec.h Michael Niedermayer
+ utility code:
+ utils.c
+ mem.c
+ opt.c, opt.h
+ arithmetic expression evaluator:
+ eval.c Michael Niedermayer
+ audio and video frame extraction:
+ parser.c
+ bitsream reading:
+ bitstream.c, bitstream.h Michael Niedermayer
+ CABAC:
+ cabac.h, cabac.c Michael Niedermayer
+ DSP utilities:
+ dsputils.c, dsputils.h Michael Niedermayer
+ entropy coding:
+ rangecoder.c, rangecoder.h Michael Niedermayer
+ lzw.* Michael Niedermayer
+ floating point AAN DCT:
+ faandct.c, faandct.h Michael Niedermayer
+ Golomb coding:
+ golomb.c, golomb.h Michael Niedermayer
+ motion estimation:
+ motion* Michael Niedermayer
+ rate control:
+ ratecontrol.c
+ xvid_rc.c Michael Niedermayer
+ simple IDCT:
+ simple_idct.c, simple_idct.h Michael Niedermayer
+ postprocessing:
+ libpostproc/* Michael Niedermayer
+
+Codecs:
+ 4xm.c Michael Niedermayer
+ 8bps.c Roberto Togni
+ aasc.c Kostya Shishkov
+ ac3* Justin Ruggles
+ asv* Michael Niedermayer
+ bmp.c Mans Rullgard
+ cavs* Stefan Gehrer
+ cinepak.c Roberto Togni
+ cljr Alex Beregszaszi
+ cook.c, cookdata.h Benjamin Larsson
+ cscd.c Reimar Doeffinger
+ dnxhddec.c Baptiste Coudurier
+ dpcm.c Mike Melanson
+ dxa.c Kostya Shishkov
+ dv.c Roman Shaposhnik
+ ffv1.c Michael Niedermayer
+ flac.c Alex Beregszaszi
+ flacenc.c Justin Ruggles
+ flashsv* Benjamin Larsson
+ flicvideo.c Mike Melanson
+ g726.c Roman Shaposhnik
+ gifdec.c Baptiste Coudurier
+ h264* Loren Merritt, Michael Niedermayer
+ h261* Michael Niedermayer
+ h263* Michael Niedermayer
+ huffyuv.c Michael Niedermayer
+ idcinvideo.c Mike Melanson
+ imc* Benjamin Larsson
+ indeo2* Kostya Shishkov
+ interplayvideo.c Mike Melanson
+ jpeg_ls.c Kostya Shishkov
+ kmvc.c Kostya Shishkov
+ lcl.c Roberto Togni
+ libgsm.c Michel Bardiaux
+ loco.c Kostya Shishkov
+ lzo.h, lzo.c Reimar Doeffinger
+ mdec.c Michael Niedermayer
+ mjpeg.c Michael Niedermayer
+ mpc* Kostya Shishkov
+ mpeg12.c, mpeg12data.h Michael Niedermayer
+ mpegvideo.c, mpegvideo.h Michael Niedermayer
+ msmpeg4.c, msmpeg4data.h Michael Niedermayer
+ msrle.c Mike Melanson
+ msvideo1.c Mike Melanson
+ nuv.c Reimar Doeffinger
+ oggtheora.c Mans Rullgard
+ qdm2.c, qdm2data.h Roberto Togni
+ qdrw.c Kostya Shishkov
+ qpeg.c Kostya Shishkov
+ qtrle.c Mike Melanson
+ ra144.c, ra144.h, ra288.c, ra288.h Roberto Togni
+ resample2.c Michael Niedermayer
+ rpza.c Roberto Togni
+ rtjpeg.c, rtjpeg.h Reimar Doeffinger
+ rv10.c Michael Niedermayer
+ smc.c Mike Melanson
+ snow.c Michael Niedermayer, Loren Merritt
+ sonic.c Alex Beregszaszi
+ svq3.c Michael Niedermayer
+ targa.c Kostya Shishkov
+ tiff.c Kostya Shishkov
+ truemotion1* Mike Melanson
+ truemotion2* Kostya Shishkov
+ truespeech.c Kostya Shishkov
+ tscc.c Kostya Shishkov
+ ulti* Kostya Shishkov
+ vc1* Kostya Shishkov
+ vcr1.c Michael Niedermayer
+ vmnc.c Kostya Shishkov
+ vorbis_enc.c Oded Shimon
+ vp3* Mike Melanson
+ vp5 Aurelien Jacobs
+ vp6 Aurelien Jacobs
+ vqavideo.c Mike Melanson
+ wavpack.c Kostya Shishkov
+ wmv2.c Michael Niedermayer
+ wnv1.c Kostya Shishkov
+ x264.c Mans Rullgard
+ xan.c Mike Melanson
+ xl.c Kostya Shishkov
+ xvmcvideo.c Ivan Kalvachev
+ zmbv* Kostya Shishkov
+
+
+libavformat
+===========
+
+Generic parts:
+ External Interface:
+ libavformat/avformat.h
+ Utility Code:
+ libavformat/utils.c
+
+
+Muxers/Demuxers:
+ 4xm.c Mike Melanson
+ adtsenc.c Mans Rullgard
+ aiff.c Baptiste Coudurier
+ avi* Michael Niedermayer
+ crc.c Michael Niedermayer
+ daud.c Reimar Doeffinger
+ dc1394.c, dv.c Roman Shaposhnik
+ dxa.c Kostya Shishkov
+ flic.c Mike Melanson
+ flvdec.c, flvenc.c Michael Niedermayer
+ gxf.c Reimar Doeffinger
+ gxfenc.c Baptiste Coudurier
+ idcin.c Mike Melanson
+ idroq.c Mike Melanson
+ ipmovie.c Mike Melanson
+ img2.c Michael Niedermayer
+ libnut.c Oded Shimon
+ matroska.c Aurelien Jacobs
+ mov.c Michael Niedermayer, Baptiste Coudurier
+ movenc.c Michael Niedermayer, Baptiste Coudurier
+ mpc.c Kostya Shishkov
+ mpegts* Mans Rullgard
+ mtv.c Reynaldo H. Verdejo Pinochet
+ mxf.c Baptiste Coudurier
+ nsvdec.c Francois Revol
+ nut.c Michael Niedermayer
+ nuv.c Reimar Doeffinger
+ ogg2.c, ogg2.h Mans Rullgard
+ oggparsevorbis.c Mans Rullgard
+ oggparseogm.c Mans Rullgard
+ psxstr.c Mike Melanson
+ raw.c Michael Niedermayer
+ rm.c Roberto Togni
+ segafilm.c Mike Melanson
+ swf.c Baptiste Coudurier
+ v4l2.c Luca Abeni
+ voc.c Aurelien Jacobs
+ wav.c Michael Niedermayer
+ wc3movie.c Mike Melanson
+ westwood.c Mike Melanson
+ wv.c Kostya Shishkov
+
+
+Operating systems / CPU architectures
+=====================================
+
+Alpha Mans Rullgard, Falk Hueffner
+BeOS Francois Revol
+i386 Michael Niedermayer
+Mac OS X / PowerPC Romain Dolbeau
+Amiga / PowerPC Colin Ward
+Linux / PowerPC Luca Barbato
+Windows MinGW Alex Beregszaszi
diff --git a/contrib/ffmpeg/Makefile b/contrib/ffmpeg/Makefile
new file mode 100644
index 000000000..d49bb1c76
--- /dev/null
+++ b/contrib/ffmpeg/Makefile
@@ -0,0 +1,235 @@
+#
+# Main ffmpeg Makefile
+# (c) 2000-2004 Fabrice Bellard
+#
+include config.mak
+
+VPATH=$(SRC_PATH_BARE)
+
+CFLAGS=$(OPTFLAGS) -I$(BUILD_ROOT) -I$(SRC_PATH) -I$(SRC_PATH)/libavutil \
+ -I$(SRC_PATH)/libavcodec -I$(SRC_PATH)/libavformat -I$(SRC_PATH)/libswscale \
+ -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_ISOC9X_SOURCE
+LDFLAGS+= -g
+
+PROGS-$(CONFIG_FFMPEG) += ffmpeg
+PROGS-$(CONFIG_FFPLAY) += ffplay
+PROGS-$(CONFIG_FFSERVER) += ffserver
+
+PROGS = $(addsuffix $(EXESUF), $(PROGS-yes))
+PROGS_G = $(addsuffix _g$(EXESUF), $(PROGS-yes))
+MANPAGES = $(addprefix doc/, $(addsuffix .1, $(PROGS-yes)))
+
+BASENAMES=ffmpeg ffplay ffserver
+ALLPROGS=$(addsuffix $(EXESUF), $(BASENAMES))
+ALLPROGS_G=$(addsuffix _g$(EXESUF), $(BASENAMES))
+ALLMANPAGES=$(addsuffix .1, $(BASENAMES))
+
+ifeq ($(BUILD_SHARED),yes)
+DEP_LIBS=libavcodec/$(SLIBPREF)avcodec$(SLIBSUF) libavformat/$(SLIBPREF)avformat$(SLIBSUF)
+else
+DEP_LIBS=libavcodec/$(LIBPREF)avcodec$(LIBSUF) libavformat/$(LIBPREF)avformat$(LIBSUF)
+endif
+
+ifeq ($(CONFIG_VHOOK),yes)
+all: videohook
+install: install-vhook
+endif
+
+ifeq ($(BUILD_DOC),yes)
+all: documentation
+install: install-man
+endif
+
+SRCS = $(addsuffix .c, $(PROGS-yes)) cmdutils.c
+LDFLAGS := -L$(BUILD_ROOT)/libavformat -L$(BUILD_ROOT)/libavcodec -L$(BUILD_ROOT)/libavutil $(LDFLAGS)
+EXTRALIBS := -lavformat$(BUILDSUF) -lavcodec$(BUILDSUF) -lavutil$(BUILDSUF) $(EXTRALIBS)
+
+ifeq ($(CONFIG_SWSCALER),yes)
+LDFLAGS+=-L./libswscale
+EXTRALIBS+=-lswscale$(BUILDSUF)
+endif
+
+all: lib $(PROGS)
+
+lib:
+ $(MAKE) -C libavutil all
+ $(MAKE) -C libavcodec all
+ $(MAKE) -C libavformat all
+ifeq ($(CONFIG_PP),yes)
+ $(MAKE) -C libpostproc all
+endif
+ifeq ($(CONFIG_SWSCALER),yes)
+ $(MAKE) -C libswscale all
+endif
+
+ffmpeg_g$(EXESUF): ffmpeg.o cmdutils.o .libs
+ $(CC) $(LDFLAGS) -o $@ ffmpeg.o cmdutils.o $(EXTRALIBS)
+
+ffserver$(EXESUF): ffserver.o .libs
+ $(CC) $(LDFLAGS) $(FFSERVERLDFLAGS) -o $@ ffserver.o $(EXTRALIBS)
+
+ffplay_g$(EXESUF): ffplay.o cmdutils.o .libs
+ $(CC) $(LDFLAGS) -o $@ ffplay.o cmdutils.o $(EXTRALIBS) $(SDL_LIBS)
+
+%$(EXESUF): %_g$(EXESUF)
+ cp -p $< $@
+ $(STRIP) $@
+
+SVN_ENTRIES = $(SRC_PATH_BARE)/.svn/entries
+ifeq ($(wildcard $(SVN_ENTRIES)),$(SVN_ENTRIES))
+version.h: $(SVN_ENTRIES)
+endif
+
+version.h:
+ $(SRC_PATH)/version.sh $(SRC_PATH)
+
+output_example$(EXESUF): output_example.o .libs
+ $(CC) $(LDFLAGS) -o $@ output_example.o $(EXTRALIBS)
+
+qt-faststart$(EXESUF): qt-faststart.c
+ $(CC) $(CFLAGS) $< -o $@
+
+cws2fws$(EXESUF): cws2fws.c
+ $(CC) $< -o $@ -lz
+
+ffplay.o: ffplay.c
+ $(CC) $(CFLAGS) $(SDL_CFLAGS) -c -o $@ $<
+
+ffmpeg.o ffplay.o ffserver.o: version.h
+
+%.o: %.c
+ $(CC) $(CFLAGS) -c -o $@ $<
+
+videohook: .libs
+ $(MAKE) -C vhook all
+
+documentation:
+ $(MAKE) -C doc all
+
+install: install-progs install-libs install-headers
+
+ifeq ($(BUILD_SHARED),yes)
+install-progs: $(PROGS) install-libs
+else
+install-progs: $(PROGS)
+endif
+ install -d "$(bindir)"
+ install -c -m 755 $(PROGS) "$(bindir)"
+
+# Create the Windows installer.
+wininstaller: all install
+ makensis ffinstall.nsi
+
+install-man:
+ install -d "$(mandir)/man1"
+ install -m 644 $(MANPAGES) "$(mandir)/man1"
+
+install-vhook:
+ $(MAKE) -C vhook install
+
+install-libs:
+ $(MAKE) -C libavutil install-libs
+ $(MAKE) -C libavcodec install-libs
+ $(MAKE) -C libavformat install-libs
+ifeq ($(CONFIG_PP),yes)
+ $(MAKE) -C libpostproc install-libs
+endif
+ifeq ($(CONFIG_SWSCALER),yes)
+ $(MAKE) -C libswscale install-libs
+endif
+
+ifeq ($(BUILD_SHARED),yes)
+ -$(LDCONFIG)
+endif
+
+install-headers:
+ $(MAKE) -C libavutil install-headers
+ $(MAKE) -C libavcodec install-headers
+ $(MAKE) -C libavformat install-headers
+ifeq ($(CONFIG_PP),yes)
+ $(MAKE) -C libpostproc install-headers
+endif
+ $(MAKE) -C libswscale install-headers
+
+uninstall: uninstall-progs uninstall-libs uninstall-headers uninstall-man uninstall-vhook
+
+uninstall-progs:
+ rm -f $(addprefix $(bindir)/, $(ALLPROGS))
+
+uninstall-man:
+ rm -f $(addprefix $(mandir)/man1/,$(ALLMANPAGES))
+
+uninstall-vhook:
+ $(MAKE) -C vhook uninstall
+
+uninstall-libs:
+ $(MAKE) -C libavutil uninstall-libs
+ $(MAKE) -C libavcodec uninstall-libs
+ $(MAKE) -C libavformat uninstall-libs
+ $(MAKE) -C libpostproc uninstall-libs
+
+uninstall-headers:
+ $(MAKE) -C libavutil uninstall-headers
+ $(MAKE) -C libavcodec uninstall-headers
+ $(MAKE) -C libavformat uninstall-headers
+ $(MAKE) -C libpostproc uninstall-headers
+ -rmdir "$(incdir)"
+ -rmdir "$(prefix)/include/postproc"
+
+depend dep: .depend
+ $(MAKE) -C libavutil depend
+ $(MAKE) -C libavcodec depend
+ $(MAKE) -C libavformat depend
+ifeq ($(CONFIG_PP),yes)
+ $(MAKE) -C libpostproc depend
+endif
+ifeq ($(CONFIG_SWSCALER),yes)
+ $(MAKE) -C libswscale depend
+endif
+ifeq ($(CONFIG_VHOOK),yes)
+ $(MAKE) -C vhook depend
+endif
+
+.depend: $(SRCS) version.h
+ $(CC) -MM $(CFLAGS) $(SDL_CFLAGS) $(filter-out %.h,$^) 1>.depend
+
+$(DEP_LIBS): lib
+
+.libs: $(DEP_LIBS)
+ touch $@
+
+clean:
+ $(MAKE) -C libavutil clean
+ $(MAKE) -C libavcodec clean
+ $(MAKE) -C libavformat clean
+ $(MAKE) -C libpostproc clean
+ $(MAKE) -C libswscale clean
+ $(MAKE) -C tests clean
+ $(MAKE) -C vhook clean
+ $(MAKE) -C doc clean
+ rm -f *.o *.d *~ .libs gmon.out TAGS $(ALLPROGS) $(ALLPROGS_G) \
+ output_example$(EXESUF) qt-faststart$(EXESUF) cws2fws$(EXESUF)
+
+distclean: clean
+ $(MAKE) -C libavutil distclean
+ $(MAKE) -C libavcodec distclean
+ $(MAKE) -C libavformat distclean
+ $(MAKE) -C libpostproc distclean
+ $(MAKE) -C libswscale distclean
+ $(MAKE) -C tests distclean
+ $(MAKE) -C vhook distclean
+ rm -f .depend version.h config.* *.pc
+
+TAGS:
+ etags *.[ch] libavformat/*.[ch] libavcodec/*.[ch]
+
+# regression tests
+
+codectest libavtest test-server fulltest test mpeg4 mpeg: $(PROGS)
+ $(MAKE) -C tests $@
+
+.PHONY: all lib videohook documentation install* wininstaller uninstall*
+.PHONY: dep depend clean distclean TAGS
+.PHONY: codectest libavtest test-server fulltest test mpeg4 mpeg
+
+-include .depend
diff --git a/contrib/ffmpeg/README b/contrib/ffmpeg/README
new file mode 100644
index 000000000..9f905357e
--- /dev/null
+++ b/contrib/ffmpeg/README
@@ -0,0 +1,19 @@
+FFmpeg README
+-------------
+
+1) Documentation
+----------------
+
+* Read the documentation in the doc/ directory.
+
+2) Licensing
+------------
+
+* Read the file COPYING. ffmpeg and the associated libraries EXCEPT
+ libpostproc and libswscale are licensed under the GNU Lesser General
+ Public License.
+
+* libpostproc and libswscale are distributed under the GNU General Public
+ License and their compilation and use is optional in ffmpeg.
+
+Fabrice Bellard.
diff --git a/contrib/ffmpeg/build_avopt b/contrib/ffmpeg/build_avopt
new file mode 100755
index 000000000..fcf165765
--- /dev/null
+++ b/contrib/ffmpeg/build_avopt
@@ -0,0 +1,9 @@
+#!/bin/sh
+sed 's/unsigned//g' |\
+ sed 's/enum//g' |\
+ egrep '^ *(int|float|double|AVRational|char *\*) *[a-zA-Z_0-9]* *;' |\
+ sed 's/^ *\([^ ]*\)[ *]*\([^;]*\);.*$/{"\2", NULL, OFFSET(\2), FF_OPT_TYPE_\U\1, DEFAULT, \1_MIN, \1_MAX},/' |\
+ sed 's/AVRATIONAL_M/INT_M/g'|\
+ sed 's/TYPE_AVRATIONAL/TYPE_RATIONAL/g'|\
+ sed 's/FLOAT_M/FLT_M/g'|\
+ sed 's/FF_OPT_TYPE_CHAR/FF_OPT_TYPE_STRING/g'
diff --git a/contrib/ffmpeg/clean-diff b/contrib/ffmpeg/clean-diff
new file mode 100755
index 000000000..98e26a79f
--- /dev/null
+++ b/contrib/ffmpeg/clean-diff
@@ -0,0 +1,11 @@
+#!/bin/sh
+sed '/^+[^+]/!s/ /TaBBaT/g' |\
+ expand -t `seq -s , 9 8 200` |\
+ sed 's/TaBBaT/ /g' |\
+ sed '/^+[^+]/s/ * $//' |\
+ tr -d '\015' |\
+ tr '\n' '°' |\
+ sed 's/\(@@[^@]*@@°[^@]*\)/\n\1/g' |\
+ egrep -v '@@[^@]*@@°(( [^°]*°)|([+-][[:space:]]*°)|(-[[:space:]]*([^°]*)°\+[[:space:]]*\5°))*$' |\
+ tr -d '\n' |\
+ tr '°' '\n'
diff --git a/contrib/ffmpeg/cmdutils.c b/contrib/ffmpeg/cmdutils.c
new file mode 100644
index 000000000..d5095cec8
--- /dev/null
+++ b/contrib/ffmpeg/cmdutils.c
@@ -0,0 +1,145 @@
+/*
+ * Various utilities for command line tools
+ * Copyright (c) 2000-2003 Fabrice Bellard
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#define HAVE_AV_CONFIG_H
+#include "avformat.h"
+#include "common.h"
+
+#include "cmdutils.h"
+
+#undef exit
+
+void show_help_options(const OptionDef *options, const char *msg, int mask, int value)
+{
+ const OptionDef *po;
+ int first;
+
+ first = 1;
+ for(po = options; po->name != NULL; po++) {
+ char buf[64];
+ if ((po->flags & mask) == value) {
+ if (first) {
+ printf("%s", msg);
+ first = 0;
+ }
+ pstrcpy(buf, sizeof(buf), po->name);
+ if (po->flags & HAS_ARG) {
+ pstrcat(buf, sizeof(buf), " ");
+ pstrcat(buf, sizeof(buf), po->argname);
+ }
+ printf("-%-17s %s\n", buf, po->help);
+ }
+ }
+}
+
+static const OptionDef* find_option(const OptionDef *po, const char *name){
+ while (po->name != NULL) {
+ if (!strcmp(name, po->name))
+ break;
+ po++;
+ }
+ return po;
+}
+
+void parse_options(int argc, char **argv, const OptionDef *options)
+{
+ const char *opt, *arg;
+ int optindex, handleoptions=1;
+ const OptionDef *po;
+
+ /* parse options */
+ optindex = 1;
+ while (optindex < argc) {
+ opt = argv[optindex++];
+
+ if (handleoptions && opt[0] == '-' && opt[1] != '\0') {
+ if (opt[1] == '-' && opt[2] == '\0') {
+ handleoptions = 0;
+ continue;
+ }
+ po= find_option(options, opt + 1);
+ if (!po->name)
+ po= find_option(options, "default");
+ if (!po->name) {
+unknown_opt:
+ fprintf(stderr, "%s: unrecognized option '%s'\n", argv[0], opt);
+ exit(1);
+ }
+ arg = NULL;
+ if (po->flags & HAS_ARG) {
+ arg = argv[optindex++];
+ if (!arg) {
+ fprintf(stderr, "%s: missing argument for option '%s'\n", argv[0], opt);
+ exit(1);
+ }
+ }
+ if (po->flags & OPT_STRING) {
+ char *str;
+ str = av_strdup(arg);
+ *po->u.str_arg = str;
+ } else if (po->flags & OPT_BOOL) {
+ *po->u.int_arg = 1;
+ } else if (po->flags & OPT_INT) {
+ *po->u.int_arg = atoi(arg);
+ } else if (po->flags & OPT_INT64) {
+ *po->u.int64_arg = atoll(arg);
+ } else if (po->flags & OPT_FLOAT) {
+ *po->u.float_arg = atof(arg);
+ } else if (po->flags & OPT_FUNC2) {
+ if(po->u.func2_arg(opt+1, arg)<0)
+ goto unknown_opt;
+ } else {
+ po->u.func_arg(arg);
+ }
+ } else {
+ parse_arg_file(opt);
+ }
+ }
+}
+
+void print_error(const char *filename, int err)
+{
+ switch(err) {
+ case AVERROR_NUMEXPECTED:
+ fprintf(stderr, "%s: Incorrect image filename syntax.\n"
+ "Use '%%d' to specify the image number:\n"
+ " for img1.jpg, img2.jpg, ..., use 'img%%d.jpg';\n"
+ " for img001.jpg, img002.jpg, ..., use 'img%%03d.jpg'.\n",
+ filename);
+ break;
+ case AVERROR_INVALIDDATA:
+ fprintf(stderr, "%s: Error while parsing header\n", filename);
+ break;
+ case AVERROR_NOFMT:
+ fprintf(stderr, "%s: Unknown format\n", filename);
+ break;
+ case AVERROR_IO:
+ fprintf(stderr, "%s: I/O error occured\n"
+ "Usually that means that input file is truncated and/or corrupted.\n",
+ filename);
+ break;
+ case AVERROR_NOMEM:
+ fprintf(stderr, "%s: memory allocation error occured\n", filename);
+ break;
+ default:
+ fprintf(stderr, "%s: Error while opening file\n", filename);
+ break;
+ }
+}
diff --git a/contrib/ffmpeg/cmdutils.h b/contrib/ffmpeg/cmdutils.h
new file mode 100644
index 000000000..13a61c09d
--- /dev/null
+++ b/contrib/ffmpeg/cmdutils.h
@@ -0,0 +1,57 @@
+/*
+ * Various utilities for command line tools
+ * copyright (c) 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
+ */
+
+#ifndef _CMD_UTILS_H
+#define _CMD_UTILS_H
+
+typedef struct {
+ const char *name;
+ int flags;
+#define HAS_ARG 0x0001
+#define OPT_BOOL 0x0002
+#define OPT_EXPERT 0x0004
+#define OPT_STRING 0x0008
+#define OPT_VIDEO 0x0010
+#define OPT_AUDIO 0x0020
+#define OPT_GRAB 0x0040
+#define OPT_INT 0x0080
+#define OPT_FLOAT 0x0100
+#define OPT_SUBTITLE 0x0200
+#define OPT_FUNC2 0x0400
+#define OPT_INT64 0x0800
+ union {
+ void (*func_arg)(const char *); //FIXME passing error code as int return would be nicer then exit() in the func
+ int *int_arg;
+ char **str_arg;
+ float *float_arg;
+ int (*func2_arg)(const char *, const char *);
+ int64_t *int64_arg;
+ } u;
+ const char *help;
+ const char *argname;
+} OptionDef;
+
+void show_help_options(const OptionDef *options, const char *msg, int mask, int value);
+void parse_options(int argc, char **argv, const OptionDef *options);
+void parse_arg_file(const char *filename);
+void print_error(const char *filename, int err);
+
+#endif /* _CMD_UTILS_H */
diff --git a/contrib/ffmpeg/common.mak b/contrib/ffmpeg/common.mak
new file mode 100644
index 000000000..7989b9021
--- /dev/null
+++ b/contrib/ffmpeg/common.mak
@@ -0,0 +1,99 @@
+#
+# common bits used by all libraries
+#
+
+VPATH = $(SRC_PATH_BARE)/lib$(NAME)
+SRC_DIR = "$(VPATH)"
+
+CFLAGS += $(CFLAGS-yes)
+OBJS += $(OBJS-yes)
+ASM_OBJS += $(ASM_OBJS-yes)
+
+CFLAGS += -DHAVE_AV_CONFIG_H -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
+ -D_ISOC9X_SOURCE -I$(BUILD_ROOT) -I$(SRC_PATH) \
+ -I$(SRC_PATH)/libavutil $(OPTFLAGS)
+SRCS := $(OBJS:.o=.c) $(ASM_OBJS:.o=.S) $(CPPOBJS:.o=.cpp)
+OBJS := $(OBJS) $(ASM_OBJS) $(CPPOBJS)
+STATIC_OBJS := $(OBJS) $(STATIC_OBJS)
+SHARED_OBJS := $(OBJS) $(SHARED_OBJS)
+
+all: $(EXTRADEPS) $(LIB) $(SLIBNAME)
+
+$(LIB): $(STATIC_OBJS)
+ rm -f $@
+ $(AR) rc $@ $^ $(EXTRAOBJS)
+ $(RANLIB) $@
+
+$(SLIBNAME): $(SLIBNAME_WITH_MAJOR)
+ ln -sf $^ $@
+
+$(SLIBNAME_WITH_MAJOR): $(SHARED_OBJS)
+ $(CC) $(SHFLAGS) $(LDFLAGS) -o $@ $^ $(EXTRALIBS) $(EXTRAOBJS)
+ $(SLIB_EXTRA_CMD)
+
+%.o: %.c
+ $(CC) $(CFLAGS) $(LIBOBJFLAGS) -c -o $@ $<
+
+%.o: %.S
+ $(CC) $(CFLAGS) $(LIBOBJFLAGS) -c -o $@ $<
+
+%: %.o $(LIB)
+ $(CC) $(LDFLAGS) -o $@ $^ $(EXTRALIBS)
+
+depend dep: $(SRCS)
+ $(CC) -MM $(CFLAGS) $^ 1>.depend
+
+clean::
+ rm -f *.o *.d *~ *.a *.lib *.so *.so.* *.dylib *.dll \
+ *.def *.dll.a *.exp
+
+distclean: clean
+ rm -f .depend
+
+ifeq ($(BUILD_SHARED),yes)
+INSTLIBTARGETS += install-lib-shared
+endif
+ifeq ($(BUILD_STATIC),yes)
+INSTLIBTARGETS += install-lib-static
+endif
+
+install: install-libs install-headers
+
+install-libs: $(INSTLIBTARGETS)
+
+install-lib-shared: $(SLIBNAME)
+ install -d "$(shlibdir)"
+ install -m 755 $(SLIBNAME) "$(shlibdir)/$(SLIBNAME_WITH_VERSION)"
+ $(STRIP) "$(shlibdir)/$(SLIBNAME_WITH_VERSION)"
+ cd "$(shlibdir)" && \
+ ln -sf $(SLIBNAME_WITH_VERSION) $(SLIBNAME_WITH_MAJOR)
+ cd "$(shlibdir)" && \
+ ln -sf $(SLIBNAME_WITH_VERSION) $(SLIBNAME)
+ $(SLIB_INSTALL_EXTRA_CMD)
+
+install-lib-static: $(LIB)
+ install -d "$(libdir)"
+ install -m 644 $(LIB) "$(libdir)"
+ $(LIB_INSTALL_EXTRA_CMD)
+
+install-headers:
+ install -d "$(incdir)"
+ install -d "$(libdir)/pkgconfig"
+ install -m 644 $(addprefix $(SRC_DIR)/,$(HEADERS)) "$(incdir)"
+ install -m 644 $(BUILD_ROOT)/lib$(NAME).pc "$(libdir)/pkgconfig"
+
+uninstall: uninstall-libs uninstall-headers
+
+uninstall-libs:
+ -rm -f "$(shlibdir)/$(SLIBNAME_WITH_MAJOR)" \
+ "$(shlibdir)/$(SLIBNAME)" \
+ "$(shlibdir)/$(SLIBNAME_WITH_VERSION)"
+ -rm -f "$(libdir)/$(LIB)"
+
+uninstall-headers:
+ rm -f $(addprefix "$(incdir)/",$(HEADERS))
+ rm -f "$(libdir)/pkgconfig/lib$(NAME).pc"
+
+.PHONY: all depend dep clean distclean install* uninstall*
+
+-include .depend
diff --git a/contrib/ffmpeg/configure b/contrib/ffmpeg/configure
new file mode 100755
index 000000000..12f2877d2
--- /dev/null
+++ b/contrib/ffmpeg/configure
@@ -0,0 +1,2157 @@
+#!/bin/sh
+#
+# FFmpeg configure script
+#
+# Copyright (c) 2000, 2001, 2002 Fabrice Bellard
+# Copyright (c) 2005-2006 Diego Biurrun
+# Copyright (c) 2005-2006 Mans Rullgard
+#
+
+# make sure we are running under a compatible shell
+# try to make this part work with most shells
+
+try_exec(){
+ echo "Trying shell $1"
+ type "$1" >/dev/null 2>&1 && exec "$@"
+}
+
+unset foo
+(: ${foo%%bar}) 2>/dev/null
+E1="$?"
+
+(: ${foo?}) 2>/dev/null
+E2="$?"
+
+if test "$E1" != 0 || test "$E2" = 0; then
+ echo "Broken shell detected. Trying alternatives."
+ export FF_CONF_EXEC
+ if test "0$FF_CONF_EXEC" -lt 1; then
+ FF_CONF_EXEC=1
+ try_exec bash "$0" "$@"
+ fi
+ if test "0$FF_CONF_EXEC" -lt 2; then
+ FF_CONF_EXEC=2
+ try_exec ksh "$0" "$@"
+ fi
+ if test "0$FF_CONF_EXEC" -lt 3; then
+ FF_CONF_EXEC=3
+ try_exec /usr/xpg4/bin/sh "$0" "$@"
+ fi
+ echo "No compatible shell script interpreter found."
+ echo "This configure script requires a POSIX-compatible shell"
+ echo "such as bash or ksh."
+ echo "THIS IS NOT A BUG IN FFMPEG, DO NOT REPORT IT AS SUCH."
+ echo "Instead, install a working POSIX-compatible shell."
+ echo "Disabling this configure test will create a broken FFmpeg."
+ if test "$BASH_VERSION" = '2.04.0(1)-release'; then
+ echo "This bash version ($BASH_VERSION) is broken on your platform."
+ echo "Upgrade to a later version if available."
+ fi
+ exit 1
+fi
+
+show_help(){
+ echo "Usage: configure [options]"
+ echo "Options: [defaults in brackets after descriptions]"
+ echo
+ echo "Standard options:"
+ echo " --help print this message"
+ echo " --log[=FILE|yes|no] log tests and output to FILE [config.err]"
+ echo " --prefix=PREFIX install in PREFIX [$PREFIX]"
+ echo " --libdir=DIR install libs in DIR [PREFIX/lib]"
+ echo " --shlibdir=DIR install shared libs in DIR [PREFIX/lib]"
+ echo " --incdir=DIR install includes in DIR [PREFIX/include/ffmpeg]"
+ echo " --mandir=DIR install man page in DIR [PREFIX/man]"
+ echo " --enable-mingwce enable MinGW native/cross WinCE compile"
+ echo " --enable-static build static libraries [default=yes]"
+ echo " --disable-static do not build static libraries [default=no]"
+ echo " --enable-shared build shared libraries [default=no]"
+ echo " --disable-shared do not build shared libraries [default=yes]"
+ echo " --enable-gpl allow use of GPL code, the resulting libav*"
+ echo " and ffmpeg will be under GPL [default=no]"
+ echo " --enable-pp enable GPLed postprocessing support [default=no]"
+ echo " --enable-swscaler software scaler support [default=no]"
+ echo " --enable-beosthreads use BeOS threads [default=no]"
+ echo " --enable-os2threads use OS/2 threads [default=no]"
+ echo " --enable-pthreads use pthreads [default=no]"
+ echo " --enable-w32threads use Win32 threads [default=no]"
+ echo " --enable-x11grab enable X11 grabbing [default=no]"
+ echo
+ echo "External library support:"
+ echo " --enable-sunmlib use Sun medialib [default=no]"
+ echo " --enable-dc1394 enable IIDC-1394 grabbing using libdc1394"
+ echo " and libraw1394 [default=no]"
+ echo " --enable-liba52 enable GPLed liba52 support [default=no]"
+ echo " --enable-liba52bin open liba52.so.0 at runtime [default=no]"
+ echo " --enable-avisynth allow reading AVISynth script files [default=no]"
+ echo " --enable-libdts enable GPLed libdts support [default=no]"
+ echo " --enable-libfaac enable FAAC support via libfaac [default=no]"
+ echo " --enable-libfaad enable FAAD support via libfaad [default=no]"
+ echo " --enable-libfaadbin build FAAD support with runtime linking [default=no]"
+ echo " --enable-libgsm enable GSM support via libgsm [default=no]"
+ echo " --enable-libmp3lame enable MP3 encoding via libmp3lame [default=no]"
+ echo " --enable-libnut enable NUT (de)muxing via libnut,"
+ echo " native demuxer exists [default=no]"
+ echo " --enable-libogg enable Ogg muxing via libogg [default=no]"
+ echo " --enable-libtheora enable Theora encoding via libtheora [default=no]"
+ echo " --enable-libvorbis enable Vorbis en/decoding via libvorbis,"
+ echo " native implementations exist [default=no]"
+ echo " --enable-x264 enable H.264 encoding via x264 [default=no]"
+ echo " --enable-xvid enable Xvid encoding via xvidcore,"
+ echo " native MPEG-4/Xvid encoder exists [default=no]"
+ echo " --enable-amr-nb enable amr-nb floating point audio codec"
+ echo " --enable-amr-nb-fixed enable amr-nb fixed-point codec"
+ echo " --enable-amr-wb enable amr-wb floating point audio codec"
+ echo " --enable-amr-if2 enable amr-wb IF2 audio codec"
+ echo ""
+ echo "Advanced options (experts only):"
+ echo " --source-path=PATH path to source code [$source_path]"
+ echo " --cross-prefix=PREFIX use PREFIX for compilation tools [$cross_prefix]"
+ echo " --cross-compile assume a cross-compiler is used"
+ echo " --target-os=OS compiler targets OS [$targetos]"
+ echo " --cc=CC use C compiler CC [$cc]"
+ echo " --make=MAKE use specified make [$make]"
+ echo " --extra-cflags=ECFLAGS add ECFLAGS to CFLAGS [$CFLAGS]"
+ echo " --extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS [$LDFLAGS]"
+ echo " --extra-libs=ELIBS add ELIBS [$ELIBS]"
+ echo " --build-suffix=SUFFIX suffix for application specific build []"
+ echo " --arch=ARCH select architecture [$arch]"
+ echo " --cpu=CPU selects the minimum cpu required (affects"
+ echo " instruction selection, may crash on older CPUs)"
+ echo " --enable-powerpc-perf enable performance report on PPC"
+ echo " (requires enabling PMC)"
+ echo " --disable-mmx disable MMX usage"
+ echo " --disable-armv5te disable armv5te usage"
+ echo " --disable-armv6 disable armv6 usage"
+ echo " --disable-iwmmxt disable iwmmxt usage"
+ echo " --disable-altivec disable AltiVec usage"
+ echo " --disable-audio-oss disable OSS audio support [default=no]"
+ echo " --disable-audio-beos disable BeOS audio support [default=no]"
+ echo " --disable-v4l disable video4linux grabbing [default=no]"
+ echo " --disable-v4l2 disable video4linux2 grabbing [default=no]"
+ echo " --disable-bktr disable bktr video grabbing [default=no]"
+ echo " --disable-dv1394 disable DV1394 grabbing [default=no]"
+ echo " --disable-network disable network support [default=no]"
+ echo " --disable-ipv6 disable ipv6 support [default=no]"
+ echo " --disable-zlib disable zlib [default=no]"
+ echo " --disable-vhook disable video hooking support"
+ echo " --disable-debug disable debugging symbols"
+ echo " --disable-mpegaudio-hp faster (but less accurate)"
+ echo " MPEG audio decoding [default=no]"
+ echo " --disable-protocols disable I/O protocols support [default=no]"
+ echo " --disable-ffmpeg disable ffmpeg build"
+ echo " --disable-ffserver disable ffserver build"
+ echo " --disable-ffplay disable ffplay build"
+ echo " --enable-small optimize for size instead of speed"
+ echo " --enable-memalign-hack emulate memalign, interferes with memory debuggers"
+ echo " --disable-encoder=NAME disables encoder NAME"
+ echo " --enable-encoder=NAME enables encoder NAME"
+ echo " --disable-decoder=NAME disables decoder NAME"
+ echo " --enable-decoder=NAME enables decoder NAME"
+ echo " --disable-encoders disables all encoders"
+ echo " --disable-decoders disables all decoders"
+ echo " --disable-muxer=NAME disables muxer NAME"
+ echo " --enable-muxer=NAME enables muxer NAME"
+ echo " --disable-muxers disables all muxers"
+ echo " --disable-demuxer=NAME disables demuxer NAME"
+ echo " --enable-demuxer=NAME enables demuxer NAME"
+ echo " --disable-demuxers disables all demuxers"
+ echo " --enable-parser=NAME enables parser NAME"
+ echo " --disable-parser=NAME disables parser NAME"
+ echo " --disable-parsers disables all parsers"
+ echo
+ echo "Developer options (useful when working on FFmpeg itself):"
+ echo " --enable-gprof enable profiling with gprof [$gprof]"
+ echo " --disable-opts disable compiler optimizations"
+ echo " --enable-extra-warnings enable more compiler warnings"
+ echo " --disable-strip disable stripping of executables and shared libraries"
+ echo ""
+ echo "NOTE: Object files are built at the place where configure is launched."
+ exit 1
+}
+
+log(){
+ echo "$@" >>$logfile
+}
+
+log_file(){
+ log BEGIN $1
+ cat -n $1 >>$logfile
+ log END $1
+}
+
+echolog(){
+ log "$@"
+ echo "$@"
+}
+
+die(){
+ echolog "$@"
+ cat <<EOF
+If you think configure made a mistake, make sure you are using the latest
+version from SVN. If the latest version fails, report the problem to the
+ffmpeg-devel@mplayerhq.hu mailing list or IRC #ffmpeg on irc.freenode.net.
+EOF
+ if enabled logging; then
+ cat <<EOF
+Include the log file "$logfile" produced by configure as this will help
+solving the problem.
+EOF
+ else
+cat <<EOF
+Rerun configure with logging enabled (do not use --log=no), and include the
+log this produces with your report.
+EOF
+ fi
+ rm -f $TMPC $TMPO $TMPE $TMPS $TMPH
+ exit 1
+}
+
+# "tr '[a-z]' '[A-Z]'" is a workaround for Solaris tr not grokking "tr a-z A-Z"
+toupper(){
+ echo "$@" | tr '[a-z]' '[A-Z]'
+}
+
+tolower(){
+ echo "$@" | tr '[A-Z]' '[a-z]'
+}
+
+set_all(){
+ value=$1
+ shift
+ for var in $*; do
+ eval $var=$value
+ done
+}
+
+pushvar(){
+ for var in $*; do
+ eval level=\${${var}_level:=0}
+ eval ${var}_${level}="\$$var"
+ eval ${var}_level=$(($level+1))
+ done
+}
+
+popvar(){
+ for var in $*; do
+ eval level=\${${var}_level:-0}
+ test $level = 0 && continue
+ eval level=$(($level-1))
+ eval $var="\${${var}_${level}}"
+ eval ${var}_level=$level
+ eval unset ${var}_${level}
+ done
+}
+
+enable(){
+ set_all yes $*
+}
+
+disable(){
+ set_all no $*
+}
+
+enabled(){
+ eval test "x\$$1" = "xyes"
+}
+
+disabled(){
+ eval test "x\$$1" = "xno"
+}
+
+enabled_all(){
+ for opt; do
+ enabled $opt || return 1
+ done
+}
+
+disabled_all(){
+ for opt; do
+ disabled $opt || return 1
+ done
+}
+
+enabled_any(){
+ for opt; do
+ enabled $opt && return 0
+ done
+}
+
+disabled_any(){
+ for opt; do
+ disabled $opt && return 0
+ done
+}
+
+check_deps(){
+ for cfg; do
+ enabled ${cfg}_checking && die "Circular dependency for $cfg."
+ disabled ${cfg}_checking && continue
+ enable ${cfg}_checking
+
+ eval dep_all="\$${cfg}_deps"
+ eval dep_any="\$${cfg}_deps_any"
+
+ pushvar cfg dep_all dep_any
+ check_deps $dep_all $dep_any
+ popvar cfg dep_all dep_any
+
+ enabled_all $dep_all || disable $cfg
+ enabled_any $dep_any || disable $cfg
+
+ disable ${cfg}_checking
+ done
+}
+
+print_config(){
+ pfx=$1
+ header=$2
+ makefile=$3
+ shift 3
+ for cfg; do
+ if enabled $cfg; then
+ ucname="${pfx}`toupper $cfg`"
+ echo "#define ${ucname} 1" >> $header
+ echo "${ucname}=yes" >> $makefile
+ fi
+ done
+}
+
+flags_saved(){
+ (: ${SAVE_CFLAGS?}) 2>/dev/null
+}
+
+save_flags(){
+ flags_saved && return
+ SAVE_CFLAGS="$CFLAGS"
+ SAVE_LDFLAGS="$LDFLAGS"
+ SAVE_extralibs="$extralibs"
+}
+
+restore_flags(){
+ flags_saved || return
+ CFLAGS="$SAVE_CFLAGS"
+ LDFLAGS="$SAVE_LDFLAGS"
+ extralibs="$SAVE_extralibs"
+ unset SAVE_CFLAGS
+ unset SAVE_LDFLAGS
+ unset SAVE_extralibs
+}
+
+temp_cflags(){
+ save_flags
+ CFLAGS="$CFLAGS $*"
+}
+
+temp_ldflags(){
+ save_flags
+ LDFLAGS="$LDFLAGS $*"
+}
+
+temp_extralibs(){
+ save_flags
+ extralibs="$extralibs $*"
+}
+
+append(){
+ var=$1
+ shift
+ flags_saved && eval "SAVE_$var=\"\$SAVE_$var $*\""
+ eval "$var=\"\$$var $*\""
+}
+
+add_cflags(){
+ append CFLAGS "$@"
+}
+
+add_ldflags(){
+ append LDFLAGS "$@"
+}
+
+add_extralibs(){
+ append extralibs "$@"
+}
+
+check_cmd(){
+ log "$@"
+ "$@" >>$logfile 2>&1
+}
+
+check_cc(){
+ log check_cc "$@"
+ cat >$TMPC
+ log_file $TMPC
+ check_cmd $cc $CFLAGS "$@" -c -o $TMPO $TMPC
+}
+
+check_cpp(){
+ log check_cpp "$@"
+ cat >$TMPC
+ log_file $TMPC
+ check_cmd $cc $CFLAGS "$@" -E -o $TMPO $TMPC
+}
+
+check_ld(){
+ log check_ld "$@"
+ check_cc || return
+ check_cmd $cc $LDFLAGS "$@" -o $TMPE $TMPO $extralibs
+}
+
+check_cflags(){
+ log check_cflags "$@"
+ check_cc "$@" <<EOF && add_cflags "$@"
+int x;
+EOF
+}
+
+check_ldflags(){
+ log check_ldflags "$@"
+ check_ld "$@" <<EOF && add_ldflags "$@"
+int main(){
+ return 0;
+}
+EOF
+}
+
+check_header(){
+ log check_header "$@"
+ header=$1
+ shift
+ var=`echo $header | sed 's/[^A-Za-z0-9_]/_/g'`
+ disable $var
+ check_cpp "$@" <<EOF && enable $var
+#include <$header>
+int x;
+EOF
+}
+
+check_func(){
+ log check_func "$@"
+ func=$1
+ shift
+ disable $func
+ check_ld "$@" <<EOF && enable $func
+extern int $func();
+int main(){
+ $func();
+}
+EOF
+}
+
+check_func2(){
+ log check_func2 "$@"
+ headers=$1
+ func=$2
+ shift 2
+ disable $func
+ incs=""
+ for hdr in $headers; do
+ incs="$incs
+#include <$hdr>"
+ done
+ check_ld "$@" <<EOF && enable $func
+$incs
+int main(){
+ (void) $func;
+ return 0;
+}
+EOF
+}
+
+check_lib(){
+ log check_lib "$@"
+ header="$1"
+ func="$2"
+ shift 2
+ temp_extralibs "$@"
+ check_header $header && check_func $func && add_extralibs "$@"
+ err=$?
+ restore_flags
+ return $err
+}
+
+check_lib2(){
+ log check_lib2 "$@"
+ headers="$1"
+ func="$2"
+ shift 2
+ temp_extralibs "$@"
+ check_func2 "$headers" $func && add_extralibs "$@"
+ err=$?
+ restore_flags
+ return $err
+}
+
+check_exec(){
+ check_ld "$@" && { enabled cross_compile || $TMPE >>$logfile 2>&1; }
+}
+
+require(){
+ name="$1"
+ header="$2"
+ func="$3"
+ shift 3
+ check_lib $header $func "$@" || die "ERROR: $name not found"
+}
+
+require2(){
+ name="$1"
+ headers="$2"
+ func="$3"
+ shift 3
+ check_lib2 "$headers" $func "$@" || die "ERROR: $name not found"
+}
+
+check_foo_config(){
+ cfg=$1
+ pkg=$2
+ header=$3
+ func=$4
+ shift 4
+ disable $cfg
+ check_cmd ${pkg}-config --version
+ err=$?
+ if test "$err" = 0; then
+ temp_cflags `${pkg}-config --cflags`
+ temp_extralibs `${pkg}-config --libs`
+ check_lib "$@" $header $func && enable $cfg
+ fi
+ return $err
+}
+
+apply(){
+ file=$1
+ shift
+ "$@" < "$file" > "$file.tmp" && mv "$file.tmp" "$file" || rm "$file.tmp"
+}
+
+CONFIG_LIST='
+ encoders
+ decoders
+ parsers
+ muxers
+ demuxers
+ amr
+ amr_nb
+ amr_nb_fixed
+ amr_wb
+ audio_beos
+ audio_oss
+ avisynth
+ beos_netserver
+ bktr
+ dc1394
+ dv1394
+ ebp_available
+ ebx_available
+ ffmpeg
+ ffplay
+ ffserver
+ gpl
+ gprof
+ ipv6
+ liba52
+ liba52bin
+ libdts
+ libfaac
+ libfaad
+ libfaadbin
+ libgsm
+ libmp3lame
+ libnut
+ libogg
+ libtheora
+ libvorbis
+ memalign_hack
+ mpegaudio_hp
+ network
+ powerpc_perf
+ pp
+ protocols
+ swscaler
+ vhook
+ v4l
+ v4l2
+ wince
+ x11grab
+ x264
+ xvid
+ zlib
+'
+
+THREADS_LIST='
+ beosthreads
+ os2threads
+ pthreads
+ w32threads
+'
+
+HAVE_LIST="
+ $THREADS_LIST
+ altivec
+ altivec_h
+ armv5te
+ armv6
+ arpa_inet_h
+ byteswap_h
+ cmov
+ dcbzl
+ dev_bktr_ioctl_bt848_h
+ dev_bktr_ioctl_meteor_h
+ dev_ic_bt8xx_h
+ dev_video_meteor_ioctl_meteor_h
+ dev_video_bktr_ioctl_bt848_h
+ dlfcn_h
+ dlopen
+ fast_64bit
+ fast_cmov
+ freetype2
+ imlib2
+ inet_aton
+ iwmmxt
+ localtime_r
+ lrintf
+ machine_ioctl_bt848_h
+ machine_ioctl_meteor_h
+ malloc_h
+ memalign
+ mlib
+ mmi
+ mmx
+ os2
+ sdl
+ sdl_video_size
+ soundcard_h
+ sys_poll_h
+ sys_soundcard_h
+ threads
+"
+
+TARGET_LIST='
+ altivec
+ armv5te
+ armv6
+ iwmmxt
+ mmi
+ mmx
+'
+
+CMDLINE_SELECT="
+ $CONFIG_LIST
+ $TARGET_LIST
+ $THREADS_LIST
+ amr_if2
+ debug
+ extra_warnings
+ shared
+ static
+"
+
+dxa_decoder_deps="zlib"
+flashsv_decoder_deps="zlib"
+flashsv_encoder_deps="zlib"
+mpeg_xvmc_decoder_deps="xvmc"
+png_decoder_deps="zlib"
+png_encoder_deps="zlib"
+x264_encoder_deps="x264"
+xvid_encoder_deps="xvid"
+zmbv_decoder_deps="zlib"
+zmbv_encoder_deps="zlib"
+
+aac_decoder_deps="libfaad"
+mpeg4aac_decoder_deps="libfaad"
+amr_nb_decoder_deps_any="amr_nb amr_nb_fixed"
+amr_nb_encoder_deps_any="amr_nb amr_nb_fixed"
+amr_wb_decoder_deps="amr_wb"
+amr_wb_encoder_deps="amr_wb"
+dts_decoder_deps="libdts"
+faac_encoder_deps="libfaac"
+liba52_decoder_deps="liba52"
+libgsm_decoder_deps="libgsm"
+libgsm_encoder_deps="libgsm"
+libgsm_ms_decoder_deps="libgsm"
+libgsm_ms_encoder_deps="libgsm"
+libtheora_encoder_deps="libtheora"
+mp3lame_encoder_deps="libmp3lame"
+oggvorbis_decoder_deps="libvorbis"
+oggvorbis_encoder_deps="libvorbis"
+
+audio_demuxer_deps_any="audio_oss audio_beos"
+audio_muxer_deps_any="audio_oss audio_beos"
+dc1394_demuxer_deps="dc1394"
+dv1394_demuxer_deps="dv1394"
+gxf_muxer_deps="gpl"
+libnut_demuxer_deps="libnut"
+libnut_muxer_deps="libnut"
+ogg_muxer_deps="libogg"
+redir_demuxer_deps="network"
+rtp_muxer_deps="network"
+rtsp_demuxer_deps="network"
+sdp_demuxer_deps="network"
+v4l2_demuxer_deps="v4l2"
+video_grab_device_demuxer_deps_any="v4l bktr"
+x11_grab_device_demuxer_deps="x11grab"
+
+ffplay_deps="sdl"
+ffserver_deps="network protocols muxers"
+network_deps="protocols"
+
+# set temporary file name
+if test ! -z "$TMPDIR" ; then
+ TMPDIR1="${TMPDIR}"
+elif test ! -z "$TEMPDIR" ; then
+ TMPDIR1="${TEMPDIR}"
+else
+ TMPDIR1="/tmp"
+fi
+
+TMPC="${TMPDIR1}/ffmpeg-conf-${RANDOM}-$$-${RANDOM}.c"
+TMPO="${TMPDIR1}/ffmpeg-conf-${RANDOM}-$$-${RANDOM}.o"
+TMPE="${TMPDIR1}/ffmpeg-conf-${RANDOM}-$$-${RANDOM}"
+TMPS="${TMPDIR1}/ffmpeg-conf-${RANDOM}-$$-${RANDOM}.S"
+TMPH="${TMPDIR1}/ffmpeg-conf-${RANDOM}-$$-${RANDOM}.h"
+
+# default parameters
+
+logging="yes"
+logfile="config.err"
+
+# installation paths
+PREFIX="/usr/local"
+libdir='${PREFIX}/lib'
+shlibdir="$libdir"
+incdir='${PREFIX}/include/ffmpeg'
+mandir='${PREFIX}/man'
+bindir='${PREFIX}/bin'
+
+# toolchain
+cross_prefix=""
+cross_compile="no"
+cc="gcc"
+ar="ar"
+ranlib="ranlib"
+make="make"
+strip="strip"
+asmalign_pot="unknown"
+
+# machine
+arch=`uname -m`
+cpu="generic"
+powerpc_perf="no"
+mmx="default"
+cmov="no"
+fast_cmov="no"
+armv5te="default"
+armv6="default"
+iwmmxt="default"
+altivec="default"
+dcbzl="no"
+mmi="default"
+bigendian="no"
+
+# OS
+targetos=$(tolower $(uname -s))
+beos_netserver="no"
+os2="no"
+wince="no"
+
+# non-library system interfaces
+audio_beos="default"
+audio_oss="yes"
+bktr="yes"
+dv1394="yes"
+v4l2="yes"
+v4l="yes"
+
+# libraries
+amr_if2="no"
+amr_nb="no"
+amr_nb_fixed="no"
+amr_wb="no"
+avisynth="no"
+dc1394="no"
+dlfcn_h="no"
+dlopen="no"
+liba52="no"
+liba52bin="no"
+libdts="no"
+libfaac="no"
+libfaad2="no"
+libfaad="no"
+libfaadbin="no"
+libgsm="no"
+libmp3lame="no"
+libnut="no"
+libogg="no"
+libtheora="no"
+libvorbis="no"
+mlib="no"
+x11grab="no"
+x264="no"
+xvid="no"
+zlib="yes"
+
+# configurable options
+debug="yes"
+dostrip="yes"
+extra_warnings="no"
+ffmpeg="yes"
+ffplay="yes"
+ffserver="yes"
+gpl="no"
+gprof="no"
+ipv6="yes"
+shared="no"
+static="yes"
+memalign_hack="no"
+mpegaudio_hp="yes"
+network="yes"
+optimize="yes"
+pp="no"
+protocols="yes"
+swscaler="no"
+vhook="default"
+
+# threading
+beosthreads="no"
+os2threads="no"
+pthreads="no"
+w32threads="no"
+thread_type="no"
+
+# build settings
+SHFLAGS='-shared -Wl,-soname,$@'
+VHOOKSHFLAGS='$(SHFLAGS)'
+LIBOBJFLAGS=""
+FFLDFLAGS=-Wl,--warn-common
+LDLATEFLAGS='-Wl,-rpath-link,\$(BUILD_ROOT)/libavcodec -Wl,-rpath-link,\$(BUILD_ROOT)/libavformat -Wl,-rpath-link,\$(BUILD_ROOT)/libavutil'
+FFSERVERLDFLAGS=-Wl,-E
+LDCONFIG="ldconfig"
+LIBPREF="lib"
+LIBSUF=".a"
+LIB='$(LIBPREF)$(NAME)$(LIBSUF)'
+SLIBPREF="lib"
+SLIBSUF=".so"
+SLIBNAME='$(SLIBPREF)$(NAME)$(SLIBSUF)'
+SLIBNAME_WITH_VERSION='$(SLIBNAME).$(LIBVERSION)'
+SLIBNAME_WITH_MAJOR='$(SLIBNAME).$(LIBMAJOR)'
+EXESUF=""
+BUILDSUF=""
+LIB_INSTALL_EXTRA_CMD='$(RANLIB) "$(libdir)/$(LIB)"'
+
+# find source path
+source_path="`dirname \"$0\"`"
+source_path_used="yes"
+if test -z "$source_path" -o "$source_path" = "." ; then
+ source_path="`pwd`"
+ source_path_used="no"
+else
+ source_path="`cd \"$source_path\"; pwd`"
+ echo "$source_path" | grep -q '[[:blank:]]' &&
+ die "Out of tree builds are impossible with whitespace in source path."
+fi
+
+if test x"$1" = x"-h" -o x"$1" = x"--help" ; then
+ show_help
+fi
+
+FFMPEG_CONFIGURATION="$@"
+
+ENCODER_LIST=`sed -n 's/^[^#]*ENC.*, *\(.*\)).*/\1_encoder/p' "$source_path/libavcodec/allcodecs.c"`
+DECODER_LIST=`sed -n 's/^[^#]*DEC.*, *\(.*\)).*/\1_decoder/p' "$source_path/libavcodec/allcodecs.c"`
+PARSER_LIST=`sed -n 's/^[^#]*PARSER.*, *\(.*\)).*/\1_parser/p' "$source_path/libavcodec/allcodecs.c"`
+MUXER_LIST=`sed -n 's/^[^#]*_MUX.*, *\(.*\)).*/\1_muxer/p' "$source_path/libavformat/allformats.c"`
+DEMUXER_LIST=`sed -n 's/^[^#]*DEMUX.*, *\(.*\)).*/\1_demuxer/p' "$source_path/libavformat/allformats.c"`
+
+enable $ENCODER_LIST $DECODER_LIST $PARSER_LIST $MUXER_LIST $DEMUXER_LIST
+
+die_unknown(){
+ echo "Unknown option \"$1\"."
+ echo "See $0 --help for available options."
+ exit 1
+}
+
+for opt do
+ optval="${opt#*=}"
+ case "$opt" in
+ --log)
+ ;;
+ --log=*) logging="$optval"
+ ;;
+ --prefix=*) PREFIX="$optval"
+ ;;
+ --libdir=*) libdir="$optval"
+ ;;
+ --shlibdir=*) shlibdir="$optval"
+ ;;
+ --incdir=*) incdir="$optval"
+ ;;
+ --mandir=*) mandir="$optval"
+ ;;
+ --source-path=*) source_path="$optval"
+ ;;
+ --cross-prefix=*) cross_prefix="$optval"
+ ;;
+ --cross-compile) cross_compile="yes"
+ ;;
+ --target-os=*) targetos="$optval"
+ ;;
+ --cc=*) cc="$optval"
+ ;;
+ --make=*) make="$optval"
+ ;;
+ --extra-cflags=*) add_cflags "$optval"
+ ;;
+ --extra-ldflags=*) add_ldflags "$optval"
+ ;;
+ --extra-libs=*) add_extralibs "$optval"
+ ;;
+ --build-suffix=*) BUILDSUF="$optval"
+ ;;
+ --arch=*) arch="$optval"
+ ;;
+ --cpu=*) cpu="$optval"
+ ;;
+ --enable-mingwce) wince="yes"
+ ;;
+ --disable-opts) optimize="no"
+ ;;
+ --enable-small) optimize="small"
+ ;;
+ --enable-sunmlib) mlib="yes"
+ ;;
+ --disable-strip) dostrip="no"
+ ;;
+ --disable-encoders) disable $ENCODER_LIST
+ ;;
+ --disable-decoders) disable $DECODER_LIST
+ ;;
+ --disable-muxers) disable $MUXER_LIST
+ ;;
+ --disable-demuxers) disable $DEMUXER_LIST
+ ;;
+ --disable-parsers) disable $PARSER_LIST
+ ;;
+ --enable-*=*|--disable-*=*)
+ eval `echo "$opt" | sed 's/=/-/;s/--/action=/;s/-/ thing=/;s/-/ name=/'`
+ case "$thing" in
+ encoder|decoder|muxer|demuxer|parser) $action ${optval}_${thing} ;;
+ *) die_unknown "$opt" ;;
+ esac
+ ;;
+ --enable-?*|--disable-?*)
+ eval `echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g'`
+ echo "$CMDLINE_SELECT" | grep -q "^ *$option\$" || die_unknown $opt
+ $action $option
+ ;;
+ --help) show_help
+ ;;
+ *)
+ die_unknown $opt
+ ;;
+ esac
+done
+
+case "$arch" in
+ i386|i486|i586|i686|i86pc|BePC)
+ arch="x86_32"
+ ;;
+ x86_64|amd64)
+ arch="x86_32"
+ canon_arch="`$cc -dumpmachine | sed -e 's,\([^-]*\)-.*,\1,'`"
+ if [ x"$canon_arch" = x"x86_64" -o x"$canon_arch" = x"amd64" ]; then
+ if [ -z "`echo $CFLAGS | grep -- -m32`" ]; then
+ arch="x86_64"
+ enable fast_64bit
+ fi
+ fi
+ ;;
+ # armv4l is a subset of armv[567]*l
+ arm|armv[4567]*l)
+ arch="armv4l"
+ ;;
+ alpha)
+ arch="alpha"
+ enable fast_64bit
+ ;;
+ "Power Macintosh"|ppc|powerpc)
+ arch="powerpc"
+ ;;
+ ppc64)
+ arch="powerpc"
+ enable fast_64bit
+ ;;
+ mips|mipsel|IP*)
+ arch="mips"
+ ;;
+ sun4u|sparc64)
+ arch="sparc64"
+ enable fast_64bit
+ ;;
+ sparc)
+ arch="sparc"
+ ;;
+ sh4)
+ arch="sh4"
+ ;;
+ parisc)
+ arch="parisc"
+ ;;
+ parisc64)
+ arch="parisc"
+ enable fast_64bit
+ ;;
+ s390|s390x)
+ arch="s390"
+ ;;
+ m68k)
+ arch="m68k"
+ ;;
+ ia64)
+ arch="ia64"
+ enable fast_64bit
+ ;;
+ bfin)
+ arch="bfin"
+ ;;
+ *)
+ arch="unknown"
+ ;;
+esac
+
+# OS specific
+osextralibs="-lm"
+case $targetos in
+ beos|haiku|zeta)
+ PREFIX="$HOME/config"
+ # helps building libavcodec
+ add_cflags "-DPIC -fomit-frame-pointer"
+ # 3 gcc releases known for BeOS, each with ugly bugs
+ gcc_version="`$cc -v 2>&1 | grep version | cut -d ' ' -f3-`"
+ case "$gcc_version" in
+ 2.9-beos-991026*|2.9-beos-000224*) echo "R5/GG gcc"
+ mmx="no"
+ ;;
+ *20010315*) echo "BeBits gcc"
+ add_cflags "-fno-expensive-optimizations"
+ ;;
+ esac
+ LDCONFIG="echo ignoring ldconfig"
+ SHFLAGS=-nostart
+ # disable Linux things
+ dv1394="no"
+ # enable BeOS things
+ disabled audio_beos || enable_audio_beos
+ # no need for libm, but the inet stuff
+ # Check for BONE
+ # XXX: actually should check for NOT net_server
+ if (echo $BEINCLUDES|grep 'headers/be/bone' >/dev/null); then
+ osextralibs="-lbind -lsocket"
+ else
+ beos_netserver="yes"
+ osextralibs="-lnet"
+ fi ;;
+ sunos)
+ dv1394="no"
+ FFLDFLAGS=""
+ FFSERVERLDFLAGS=""
+ SHFLAGS="-shared -Wl,-h,\$@"
+ add_extralibs "-lsocket -lnsl"
+ ;;
+ netbsd)
+ dv1394="no"
+ add_extralibs "-lossaudio"
+ ;;
+ openbsd)
+ dv1394="no"
+ need_memalign="no"
+ LIBOBJFLAGS="\$(PIC)"
+ LDCONFIG="ldconfig -m \$(shlibdir)"
+ SHFLAGS='-shared'
+ SLIBNAME='$(SLIBPREF)$(NAME)$(SLIBSUF).$(LIBVERSION)'
+ SLIBNAME_WITH_VERSION='$(SLIBNAME)'
+ SLIBNAME_WITH_MAJOR='$(SLIBNAME)'
+ add_extralibs "-lossaudio"
+ ;;
+ freebsd)
+ dv1394="no"
+ need_memalign="no"
+ add_cflags "-pthread"
+ ;;
+ gnu/kfreebsd)
+ dv1394="no"
+ add_cflags "-pthread"
+ ;;
+ bsd/os)
+ dv1394="no"
+ osextralibs="-lpoll -lgnugetopt -lm"
+ strip="strip -d"
+ ;;
+ darwin)
+ dv1394="no"
+ need_memalign="no"
+ SHFLAGS="-dynamiclib -Wl,-single_module -Wl,-install_name,\$(shlibdir)/\$(SLIBNAME),-current_version,\$(SPPVERSION),-compatibility_version,\$(SPPVERSION) -Wl,-read_only_relocs,suppress"
+ VHOOKSHFLAGS='-dynamiclib -Wl,-single_module -flat_namespace -undefined suppress -Wl,-install_name,$(shlibdir)/vhook/$@'
+ osextralibs=""
+ strip="strip -x"
+ FFLDFLAGS="-Wl,-dynamic,-search_paths_first"
+ SLIBSUF=".dylib"
+ SLIBNAME_WITH_VERSION='$(SLIBPREF)$(NAME).$(LIBVERSION)$(SLIBSUF)'
+ SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(NAME).$(LIBMAJOR)$(SLIBSUF)'
+ FFSERVERLDFLAGS=-Wl,-bind_at_load
+ ;;
+ mingw32*)
+ targetos=mingw32
+ if enabled_all shared static; then
+ cat <<EOF
+You can only build one library type at once on MinGW.
+Specify --disable-static --enable-shared to only build
+the shared libraries. To build only the static libraries
+you do not need to pass additional options.
+EOF
+ exit 1
+ fi
+ dv1394="no"
+ ffserver="no"
+ network="no"
+ if enabled wince; then
+ protocols="no"
+ fi
+ SLIBPREF=""
+ SLIBSUF=".dll"
+ EXESUF=".exe"
+ SLIBNAME_WITH_VERSION='$(SLIBPREF)$(NAME)-$(LIBVERSION)$(SLIBSUF)'
+ SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(NAME)-$(LIBMAJOR)$(SLIBSUF)'
+ SLIB_EXTRA_CMD="-lib /machine:i386 /def:\$(@:${SLIBSUF}=.def)"
+ SLIB_INSTALL_EXTRA_CMD="-install -m 644 \$(SLIBNAME_WITH_MAJOR:\$(SLIBSUF)=.lib) \"\$(shlibdir)/\$(SLIBNAME_WITH_MAJOR:\$(SLIBSUF)=.lib)\""
+ SHFLAGS="-shared -Wl,--output-def,\$(@:${SLIBSUF}=.def),--out-implib,lib\$(SLIBNAME:\$(SLIBSUF)=.dll.a) -Wl,--enable-runtime-pseudo-reloc"
+ add_extralibs -lws2_32
+ ;;
+ cygwin*)
+ targetos=cygwin
+ shlibdir="$bindir"
+ dv1394="no"
+ VHOOKSHFLAGS='-shared -L$(BUILD_ROOT)/libavformat -L$(BUILD_ROOT)/libavcodec -L$(BUILD_ROOT)/libswscale -L$(BUILD_ROOT)/libavutil'
+ VHOOKLIBS='-lavformat$(BUILDSUF) -lavcodec$(BUILDSUF) -lswscale$(BUILDSUF) -lavutil$(BUILDSUF) $(EXTRALIBS)'
+ osextralibs=""
+ EXESUF=".exe"
+ SLIBPREF="cyg"
+ SLIBSUF=".dll"
+ SLIBNAME_WITH_VERSION='$(SLIBPREF)$(NAME)-$(LIBVERSION)$(SLIBSUF)'
+ SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(NAME)-$(LIBMAJOR)$(SLIBSUF)'
+ SHFLAGS='-shared -Wl,--out-implib=lib$(NAME).dll.a'
+ ;;
+ linux)
+ LDLATEFLAGS="-Wl,--as-needed $LDLATEFLAGS"
+ ;;
+ irix*)
+ targetos=irix
+ ranlib="echo ignoring ranlib"
+ ;;
+ os/2)
+ TMPE=$TMPE".exe"
+ ar="emxomfar -p128"
+ ranlib="echo ignoring ranlib"
+ strip="echo ignoring strip"
+ add_cflags "-Zomf"
+ FFLDFLAGS="-Zomf -Zstack 16384 -s"
+ SHFLAGS="-Zdll -Zomf"
+ FFSERVERLDFLAGS=""
+ LIBPREF=""
+ LIBSUF=".lib"
+ SLIBPREF=""
+ SLIBSUF=".dll"
+ EXESUF=".exe"
+ osextralibs=""
+ pkg_requires=""
+ dv1394="no"
+ ffserver="no"
+ vhook="no"
+ os2="yes"
+ ;;
+ *)
+ targetos="${targetos}-UNKNOWN"
+ ;;
+esac
+
+add_extralibs $osextralibs
+
+if ! disabled logging ; then
+ enabled logging || logfile="$logging"
+ echo "# $0 $@" >$logfile
+ set >>$logfile
+else
+ logfile=/dev/null
+fi
+
+# Combine FFLDFLAGS and the LDFLAGS environment variable.
+LDFLAGS="$FFLDFLAGS $LDFLAGS"
+
+test -n "$cross_prefix" && cross_compile=yes
+cc="${cross_prefix}${cc}"
+ar="${cross_prefix}${ar}"
+ranlib="${cross_prefix}${ranlib}"
+strip="${cross_prefix}${strip}"
+
+# Disable core dumps so that intentional execution of broken apps doesn't
+# pollute the current directory.
+ulimit -c 0
+
+# we need to build at least one lib type
+if disabled_all static shared; then
+ cat <<EOF
+At least one library type must be built.
+Specify --enable-static to build the static libraries or --enable-shared to
+build the shared libraries as well. To only build the shared libraries specify
+--disable-static in addition to --enable-shared.
+EOF
+ exit 1;
+fi
+
+if disabled libogg; then
+ enabled libtheora && die "libogg must be enabled to enable libtheora."
+ enabled libvorbis && die "libogg must be enabled to enable libvorbis."
+fi
+
+if enabled_any libfaad libfaadbin ; then
+ if check_header faad.h; then
+ check_cc << EOF
+#include <faad.h>
+#ifndef FAAD2_VERSION
+ok faad1
+#endif
+int main( void ) { return 0; }
+EOF
+ test $? = 0 && enable libfaad2
+ else
+ die "FAAD test failed."
+ fi
+fi
+
+
+if disabled gpl ; then
+ die_gpl_disabled(){
+ name=$1
+ shift
+ enabled_any $@ && die "$name is under GPL and --enable-gpl is not specified."
+ }
+ die_gpl_disabled "The Postprocessing code" pp
+ die_gpl_disabled "liba52" liba52
+ die_gpl_disabled "libxvidcore" xvid
+ die_gpl_disabled "x264" x264
+ die_gpl_disabled "libdts" libdts
+ die_gpl_disabled "FAAD2" libfaad2
+ die_gpl_disabled "The X11 grabber" x11grab
+ die_gpl_disabled "The software scaler" swscaler
+fi
+
+# compute MMX state
+if test $mmx = "default"; then
+ if test $arch = "x86_32" -o $arch = "x86_64"; then
+ mmx="yes"
+ else
+ mmx="no"
+ fi
+fi
+
+test -z "$need_memalign" && need_memalign="$mmx"
+
+#Darwin CC versions
+needmdynamicnopic="no"
+if test $targetos = darwin; then
+ if test -n "`$cc -v 2>&1 | grep xlc`"; then
+ add_cflags "-qpdf2 -qlanglvl=extc99 -qmaxmem=-1 -qarch=auto -qtune=auto"
+ else
+ gcc_version="`$cc -v 2>&1 | grep version | cut -d ' ' -f3-`"
+ case "$gcc_version" in
+ *2.95*)
+ add_cflags "-no-cpp-precomp -pipe"
+ ;;
+ *[34].*)
+ add_cflags "-no-cpp-precomp -pipe -force_cpusubtype_ALL -Wno-sign-compare"
+ if disabled shared; then
+ needmdynamicnopic="yes"
+ fi
+ ;;
+ *)
+ add_cflags "-no-cpp-precomp -pipe"
+ if disabled shared; then
+ needmdynamicnopic="yes"
+ fi
+ ;;
+ esac
+ fi
+fi
+
+disabled optimize || add_cflags -fomit-frame-pointer
+
+# Can only do AltiVec on PowerPC
+if test $altivec = "default"; then
+ if test $arch = "powerpc"; then
+ altivec="yes"
+ else
+ altivec="no"
+ fi
+fi
+
+# Add processor-specific flags
+POWERPCMODE="32bits"
+if test $cpu != "generic"; then
+ warn_altivec(){
+ $1 altivec && echo "WARNING: Tuning for $2 but AltiVec $1.";
+ }
+ case $cpu in
+ 601|ppc601|PowerPC601)
+ add_cflags "-mcpu=601"
+ warn_altivec enabled PPC601
+ ;;
+ 603*|ppc603*|PowerPC603*)
+ add_cflags "-mcpu=603"
+ warn_altivec enabled PPC603
+ ;;
+ 604*|ppc604*|PowerPC604*)
+ add_cflags "-mcpu=604"
+ warn_altivec enabled PPC604
+ ;;
+ G3|g3|75*|ppc75*|PowerPC75*)
+ add_cflags "-mcpu=750 -mpowerpc-gfxopt"
+ warn_altivec enabled PPC75x
+ ;;
+ G4|g4|745*|ppc745*|PowerPC745*)
+ add_cflags "-mcpu=7450 -mpowerpc-gfxopt"
+ warn_altivec disabled PPC745x
+ ;;
+ 74*|ppc74*|PowerPC74*)
+ add_cflags "-mcpu=7400 -mpowerpc-gfxopt"
+ warn_altivec disabled PPC74xx
+ ;;
+ G5|g5|970|ppc970|PowerPC970|power4*|Power4*)
+ add_cflags "-mcpu=970 -mpowerpc-gfxopt -mpowerpc64"
+ warn_altivec disabled PPC970
+ POWERPCMODE="64bits"
+ ;;
+ # targets that do NOT support conditional mov (cmov)
+ i[345]86|pentium|pentium-mmx|k6|k6-[23]|winchip-c6|winchip2|c3)
+ add_cflags "-march=$cpu"
+ cmov="no"
+ ;;
+ # targets that do support conditional mov (cmov)
+ i686|pentiumpro|pentium[23]|pentium-m|athlon|athlon-tbird|athlon-4|athlon-[mx]p|athlon64|k8|opteron|athlon-fx|core2)
+ add_cflags "-march=$cpu"
+ cmov="yes"
+ fast_cmov="yes"
+ ;;
+ # targets that do support conditional mov but on which it's slow
+ pentium4|prescott|nocona)
+ add_cflags "-march=$cpu"
+ cmov="yes"
+ fast_cmov="no"
+ ;;
+ sparc64)
+ add_cflags "-mcpu=v9"
+ ;;
+ bf*) #bf531 bf532 bf533 bf561 bf5xx all get this config
+ add_cflags "-mfdpic"
+ add_ldflags "-mfdpic"
+ ;;
+ *)
+ echo "WARNING: Unknown CPU \"$cpu\", ignored."
+ ;;
+ esac
+fi
+
+gnu_make(){
+ $1 --version 2>&1 | grep -q GNU
+}
+
+if ! gnu_make $make; then
+ gnu_make gmake && make=gmake || die "GNU make not found."
+fi
+
+# make sure we can execute files in $TMPDIR
+cat >$TMPE 2>>$logfile <<EOF
+#! /bin/sh
+EOF
+chmod +x $TMPE >>$logfile 2>&1
+if ! $TMPE >>$logfile 2>&1; then
+ cat <<EOF
+Unable to create and execute files in $TMPDIR1. Set the TMPDIR environment
+variable to another directory and make sure that $TMPDIR1 is not mounted
+noexec.
+EOF
+ die "Sanity test failed."
+fi
+rm $TMPE
+
+# compiler sanity check
+check_exec <<EOF
+int main(){
+ return 0;
+}
+EOF
+if test "$?" != 0; then
+ echo "$cc is unable to create an executable file."
+ if test -z "$cross_prefix" && disabled cross_compile ; then
+ echo "If $cc is a cross-compiler, use the --cross-compile option."
+ echo "Only do this if you know what cross compiling means."
+ fi
+ die "C compiler test failed."
+fi
+
+if test $arch = "x86_32" -o $arch = "x86_64"; then
+ if test "$targetos" = mingw32 -o "$targetos" = cygwin; then
+ cat <<EOF
+WARNING: The following test might cause a testapp to crash (intentionally)
+resulting in the appearance of a dialog box. Please click "Don't send" and
+ignore it.
+EOF
+ fi
+
+ # check whether EBP is available on x86
+ # As 'i' is stored on the stack, this program will crash
+ # if the base pointer is used to access it because the
+ # base pointer is cleared in the inline assembly code.
+ (check_exec) <<EOF >>$logfile 2>&1 && enable ebp_available
+int main(){
+ volatile int i=0;
+ asm volatile (
+ "xorl %%ebp, %%ebp"
+ ::: "%ebp");
+ return i;
+}
+EOF
+
+ # check wether EBX is available on x86
+ check_cc <<EOF && enable ebx_available
+int main(){
+ asm volatile ("":::"%ebx");
+}
+EOF
+fi
+
+# check for assembler specific support
+
+if test $arch = "powerpc"; then
+check_cc <<EOF && dcbzl=yes
+int main(void) {
+ register long zero = 0;
+ char data[1024];
+ asm volatile("dcbzl %0, %1" : : "b" (data), "r" (zero));
+return 0;
+}
+EOF
+fi
+
+# check for SIMD availability
+
+# AltiVec flags: The FSF version of GCC differs from the Apple version
+if test $arch = "powerpc"; then
+ if enabled altivec; then
+ if test -n "`$cc -v 2>&1 | grep version | grep Apple`"; then
+ add_cflags "-faltivec"
+ else
+ add_cflags "-maltivec -mabi=altivec"
+ fi
+ fi
+fi
+
+check_header altivec.h
+
+# check if our compiler supports Motorola AltiVec C API
+if enabled altivec; then
+ if enabled altivec_h; then
+ inc_altivec_h="#include <altivec.h>"
+ else
+ inc_altivec_h=
+ fi
+ check_cc <<EOF || altivec=no
+$inc_altivec_h
+int main(void) {
+ vector signed int v1, v2, v3;
+ v1 = vec_add(v2,v3);
+ return 0;
+}
+EOF
+fi
+
+# check armv5te instructions support
+if test $armv5te = "default" -a $arch = "armv4l"; then
+ armv5te=no
+ check_cc <<EOF && armv5te=yes
+ int main(void) {
+ __asm__ __volatile__ ("qadd r0, r0, r0");
+ }
+EOF
+fi
+
+if test $armv6 = "default" -a $arch = "armv4l"; then
+ check_cc <<EOF && armv6=yes || armv6=no
+int main(void) {
+ __asm__ __volatile__ ("sadd16 r0, r0, r0");
+}
+EOF
+fi
+
+# check iwmmxt support
+if test $iwmmxt = "default" -a $arch = "armv4l"; then
+ iwmmxt=no
+ check_cc <<EOF && iwmmxt=yes
+ int main(void) {
+ __asm__ __volatile__ ("wunpckelub wr6, wr4");
+ }
+EOF
+fi
+
+# mmi only available on mips
+if test $mmi = "default"; then
+ if test $arch = "mips"; then
+ mmi="yes"
+ else
+ mmi="no"
+ fi
+fi
+
+# check if our compiler supports mmi
+enabled mmi && check_cc <<EOF || mmi="no"
+int main(void) {
+ __asm__ ("lq \$2, 0(\$2)");
+ return 0;
+}
+EOF
+
+# ---
+# big/little-endian test
+if disabled cross_compile; then
+ check_ld <<EOF || die "endian test failed" && $TMPE && bigendian="yes"
+#include <inttypes.h>
+int main(int argc, char ** argv){
+ volatile uint32_t i=0x01234567;
+ return (*((uint8_t*)(&i))) == 0x67;
+}
+EOF
+else
+ # programs cannot be launched if cross compiling, so make a static guess
+ if test "$arch" = "powerpc" -o "$arch" = "mips" ; then
+ bigendian="yes"
+ fi
+fi
+
+# ---
+# check availability of some header files
+
+check_header malloc.h
+check_func memalign
+
+if disabled_all memalign memalign_hack && enabled need_memalign ; then
+ die "Error, no memalign() but SSE enabled, disable it or use --enable-memalign-hack."
+fi
+
+check_header byteswap.h
+
+check_header arpa/inet.h
+
+check_func inet_aton
+check_func localtime_r
+enabled zlib && check_lib zlib.h zlibVersion -lz || zlib="no"
+
+# ffserver uses poll(),
+# if it's not found we can emulate it using select().
+if enabled ffserver; then
+ check_header sys/poll.h
+fi
+
+# check for some common methods of building with pthread support
+# do this before the optional library checks as some of them require pthreads
+if enabled pthreads; then
+ if check_func pthread_create; then
+ :
+ elif check_func pthread_create -pthread; then
+ add_cflags -pthread
+ add_ldflags -pthread
+ elif check_func pthread_create -pthreads; then
+ add_cflags -pthreads
+ add_ldflags -pthreads
+ elif ! check_lib pthread.h pthread_create -lpthread; then
+ die "ERROR: can't find pthreads library"
+ fi
+fi
+
+for thread in $THREADS_LIST; do
+ if enabled $thread; then
+ if ! disabled thread_type ; then
+ die "ERROR: Only one thread type must be selected."
+ else
+ thread_type="$thread"
+ fi
+ fi
+done
+
+enabled_any amr_nb amr_nb_fixed amr_wb amr_if2 && enable amr
+enabled_all amr_nb amr_nb_fixed &&
+ die "Only one of amr_nb and amr_nb_fixed may be enabled."
+
+# these are off by default, so fail if requested and not available
+enabled liba52 && require liba52 a52dec/a52.h a52_init -la52
+enabled libdts && require libdts dts.h dts_init -ldts -lm
+enabled libgsm && require libgsm gsm.h gsm_create -lgsm
+enabled libmp3lame && require LAME lame/lame.h lame_init -lmp3lame -lm
+enabled libtheora && require libtheora theora/theora.h theora_info_init -ltheora -logg
+enabled libvorbis && require libvorbis vorbis/vorbisenc.h vorbis_info_init -lvorbis -lvorbisenc -logg
+enabled libogg && require libogg ogg/ogg.h ogg_sync_init -logg
+enabled libnut && require libnut libnut.h nut_demuxer_init -lnut
+enabled xvid && require XviD xvid.h xvid_global -lxvidcore
+enabled x264 && require x264 x264.h x264_encoder_open -lx264
+enabled dc1394 && require libdc1394 libdc1394/dc1394_control.h dc1394_create_handle -ldc1394_control -lraw1394
+enabled mlib && require mediaLib mlib_types.h mlib_VectorSub_S16_U8_Mod -lmlib
+enabled libfaac && require2 libfaac "stdint.h faac.h" faacEncGetVersion -lfaac
+enabled libfaad && require2 libfaad faad.h faacDecOpen -lfaad
+enabled avisynth && require2 vfw32 "windows.h vfw.h" AVIFileInit -lvfw32
+
+# test for lrintf in math.h
+check_exec <<EOF && lrintf=yes || lrintf=no
+#define _ISOC9X_SOURCE 1
+#include <math.h>
+int main( void ) { return (lrintf(3.999f) > 0)?0:1; }
+EOF
+
+_restrict=
+for restrict_keyword in restrict __restrict__ __restrict; do
+ check_cc <<EOF && _restrict=$restrict_keyword && break
+void foo(char * $restrict_keyword p);
+EOF
+done
+
+# dlopen/dlfcn.h probing
+
+check_header dlfcn.h
+
+if check_func dlopen; then
+ ldl=
+elif check_func dlopen -ldl; then
+ ldl=-ldl
+fi
+
+test "$vhook" = "default" && vhook="$dlopen"
+
+enabled_any vhook liba52bin libfaadbin ffserver && add_extralibs $ldl
+
+if test "$targetos" = cygwin && enabled static ; then
+ vhook="no"
+ echo
+ echo "At the moment vhooks don't work on Cygwin static builds."
+ echo "Patches welcome."
+ echo
+fi
+
+if enabled vhook; then
+ check_ldflags -rdynamic
+ check_ldflags -export-dynamic
+fi
+
+enabled audio_beos && add_extralibs "-lmedia -lbe"
+
+check_foo_config imlib2 imlib2 Imlib2.h imlib_load_font
+check_foo_config freetype2 freetype ft2build.h FT_Init_FreeType
+
+##########################################
+# SDL check
+
+sdl_too_old=no
+sdl=no
+SDL_CONFIG="${cross_prefix}sdl-config"
+if "${SDL_CONFIG}" --version >/dev/null 2>&1; then
+ sdl_cflags=`"${SDL_CONFIG}" --cflags`
+ temp_cflags $sdl_cflags
+ temp_extralibs `"${SDL_CONFIG}" --libs`
+ if check_lib SDL.h SDL_Init; then
+ _sdlversion=`"${SDL_CONFIG}" --version | sed 's/[^0-9]//g'`
+ if test "$_sdlversion" -lt 121 ; then
+ sdl_too_old=yes
+ else
+ sdl=yes
+ check_cc $sdl_cflags <<EOF && enable sdl_video_size
+#include <SDL.h>
+int main(void){
+ const SDL_VideoInfo *vi = SDL_GetVideoInfo();
+ int w = vi->current_w;
+ return 0;
+}
+EOF
+ fi
+ fi
+ restore_flags
+fi
+
+texi2html -version >/dev/null 2>&1 && enable texi2html || disable texi2html
+
+##########################################
+# IPv6 check
+
+enabled network && enabled ipv6 && check_ld <<EOF && ipv6=yes || ipv6=no
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+int main( void ) {
+ struct sockaddr_storage saddr;
+ struct ipv6_mreq mreq6;
+ getaddrinfo(0,0,0,0);
+ getnameinfo(0,0,0,0,0,0,0);
+ IN6_IS_ADDR_MULTICAST((const struct in6_addr *)0);
+}
+EOF
+
+enabled v4l && check_header linux/videodev.h || disable v4l
+enabled v4l2 && check_header linux/videodev2.h || disable v4l2
+
+# check for ioctl_meteor.h, ioctl_bt848.h and alternatives
+if enabled bktr; then
+ { check_header dev/bktr/ioctl_meteor.h &&
+ check_header dev/bktr/ioctl_bt848.h; } ||
+ { check_header machine/ioctl_meteor.h &&
+ check_header machine/ioctl_bt848.h; } ||
+ { check_header dev/video/meteor/ioctl_meteor.h &&
+ check_header dev/video/bktr/ioctl_bt848.h; } ||
+ check_header dev/ic/bt8xx.h ||
+ disable bktr
+fi
+
+enabled audio_oss &&
+ check_header sys/soundcard.h ||
+ check_header soundcard.h ||
+ disable audio_oss
+
+# Deal with the x11 frame grabber
+enabled x11grab &&
+enabled gpl &&
+enabled x11_grab_device_demuxer &&
+check_header X11/Xlib.h &&
+check_header X11/extensions/XShm.h &&
+check_func XOpenDisplay -lX11 &&
+check_func XShmCreateImage -lX11 -lXext &&
+add_extralibs -lX11 -lXext ||
+disable x11_grab_device_demuxer
+
+enabled debug && add_cflags -g
+
+# add some useful compiler flags if supported
+check_cflags -Wdeclaration-after-statement
+check_cflags -Wall
+check_cflags -Wno-switch
+check_cflags -Wdisabled-optimization
+check_cflags -Wpointer-arith
+check_cflags -Wredundant-decls
+check_cflags -Wno-pointer-sign
+enabled extra_warnings && check_cflags -Winline
+
+# add some linker flags
+check_ldflags $LDLATEFLAGS
+
+# not all compilers support -Os
+test "$optimize" = "small" && check_cflags -Os
+
+if enabled optimize; then
+ if test -n "`$cc -v 2>&1 | grep xlc`"; then
+ add_cflags "-O5"
+ add_ldflags "-O5"
+ else
+ add_cflags "-O3"
+ fi
+fi
+
+# PIC flags for shared library objects where they are needed
+if enabled shared; then
+ # LIBOBJFLAGS may have already been set in the OS configuration
+ if test -z "$LIBOBJFLAGS" ; then
+ case "$arch" in
+ x86_64|ia64|alpha|sparc*|power*) LIBOBJFLAGS="\$(PIC)" ;;
+ esac
+ fi
+fi
+
+if enabled gprof; then
+ add_cflags "-p"
+ add_ldflags "-p"
+fi
+
+VHOOKCFLAGS="-fPIC $CFLAGS"
+enabled needmdynamicnopic && add_cflags -mdynamic-no-pic
+
+# find if .align arg is power-of-two or not
+if test $asmalign_pot = "unknown"; then
+ asmalign_pot="no"
+ echo 'asm (".align 3");' | check_cc && asmalign_pot="yes"
+fi
+
+enabled_any $ENCODER_LIST && enable encoders
+enabled_any $DECODER_LIST && enable decoders
+enabled_any $MUXER_LIST && enable muxers
+enabled_any $DEMUXER_LIST && enable demuxers
+
+enabled_any $THREADS_LIST && enable threads
+
+check_deps $CONFIG_LIST $HAVE_LIST $DECODER_LIST $ENCODER_LIST $PARSER_LIST \
+ $DEMUXER_LIST $MUXER_LIST
+
+enabled libogg && append pkg_requires "ogg >= 1.1"
+enabled libtheora && append pkg_requires "theora"
+enabled libvorbis && append pkg_requires "vorbis vorbisenc"
+enabled dc1394 && append pkg_requires "libraw1394"
+
+echo "install prefix $PREFIX"
+echo "source path $source_path"
+echo "C compiler $cc"
+echo "make $make"
+echo ".align is power-of-two $asmalign_pot"
+echo "ARCH $arch ($cpu)"
+if test "$BUILDSUF" != ""; then
+ echo "build suffix $BUILDSUF"
+fi
+echo "big-endian $bigendian"
+if test $arch = "x86_32" -o $arch = "x86_64"; then
+ echo "MMX enabled $mmx"
+ echo "CMOV enabled $cmov"
+ echo "CMOV is fast $fast_cmov"
+fi
+if test $arch = "armv4l"; then
+ echo "ARMv5TE enabled $armv5te"
+ echo "ARMv6 enabled $armv6"
+ echo "IWMMXT enabled $iwmmxt"
+fi
+if test $arch = "mips"; then
+ echo "MMI enabled $mmi"
+fi
+if test $arch = "powerpc"; then
+ echo "AltiVec enabled $altivec"
+ echo "dcbzl available $dcbzl"
+fi
+echo "gprof enabled $gprof"
+echo "debug symbols $debug"
+echo "strip symbols $dostrip"
+echo "optimize $optimize"
+echo "static $static"
+echo "shared $shared"
+echo "postprocessing support $pp"
+echo "software scaler enabled $swscaler"
+echo "video hooking $vhook"
+if enabled vhook; then
+ echo "Imlib2 support $imlib2"
+ echo "FreeType support $freetype2"
+fi
+echo "network support $network"
+if enabled network; then
+ echo "IPv6 support $ipv6"
+fi
+echo "threading support $thread_type"
+echo "SDL support $sdl"
+if enabled sdl_too_old; then
+ echo "-> Your SDL version is too old - please upgrade to have FFplay/SDL support."
+fi
+echo "Sun medialib support $mlib"
+echo "AVISynth enabled $avisynth"
+echo "liba52 support $liba52"
+echo "liba52 dlopened $liba52bin"
+echo "libdts support $libdts"
+echo "libfaac enabled $libfaac"
+echo "libfaad enabled $libfaad"
+echo "faadbin enabled $libfaadbin"
+echo "libgsm enabled $libgsm"
+echo "libmp3lame enabled $libmp3lame"
+echo "libnut enabled $libnut"
+echo "libogg enabled $libogg"
+echo "libtheora enabled $libtheora"
+echo "libvorbis enabled $libvorbis"
+echo "x264 enabled $x264"
+echo "XviD enabled $xvid"
+echo "zlib enabled $zlib"
+echo "AMR-NB float support $amr_nb"
+echo "AMR-NB fixed support $amr_nb_fixed"
+echo "AMR-WB float support $amr_wb"
+echo "AMR-WB IF2 support $amr_if2"
+if disabled gpl; then
+ echo "License: LGPL"
+else
+ echo "License: GPL"
+fi
+
+echo "Creating config.mak and config.h..."
+
+echo "# Automatically generated by configure - do not modify!" > config.mak
+echo "/* Automatically generated by configure - do not modify! */" > $TMPH
+echo "#define FFMPEG_CONFIGURATION \"$FFMPEG_CONFIGURATION\"" >> $TMPH
+
+echo "PREFIX=$PREFIX" >> config.mak
+echo "prefix=\$(DESTDIR)\${PREFIX}" >> config.mak
+echo "libdir=\$(DESTDIR)$libdir" >> config.mak
+echo "shlibdir=\$(DESTDIR)$shlibdir" >> config.mak
+echo "incdir=\$(DESTDIR)$incdir" >> config.mak
+echo "bindir=\$(DESTDIR)$bindir" >> config.mak
+echo "mandir=\$(DESTDIR)$mandir" >> config.mak
+echo "MAKE=$make" >> config.mak
+echo "CC=$cc" >> config.mak
+echo "AR=$ar" >> config.mak
+echo "RANLIB=$ranlib" >> config.mak
+if enabled dostrip; then
+ echo "STRIP=$strip" >> config.mak
+else
+ echo "STRIP=echo ignoring strip" >> config.mak
+fi
+
+echo "OPTFLAGS=$CFLAGS" >> config.mak
+echo "VHOOKCFLAGS=$VHOOKCFLAGS">>config.mak
+echo "LDFLAGS=$LDFLAGS" >> config.mak
+echo "LDCONFIG=$LDCONFIG" >> config.mak
+echo "FFSERVERLDFLAGS=$FFSERVERLDFLAGS" >> config.mak
+echo "SHFLAGS=$SHFLAGS" >> config.mak
+echo "VHOOKSHFLAGS=$VHOOKSHFLAGS" >> config.mak
+echo "VHOOKLIBS=$VHOOKLIBS" >> config.mak
+echo "LIBOBJFLAGS=$LIBOBJFLAGS" >> config.mak
+echo "BUILD_STATIC=$static" >> config.mak
+echo "BUILDSUF=$BUILDSUF" >> config.mak
+echo "LIBPREF=$LIBPREF" >> config.mak
+echo "LIBSUF=\${BUILDSUF}$LIBSUF" >> config.mak
+if enabled static; then
+ echo "LIB=$LIB" >> config.mak
+else # Some Make complain if this variable does not exist.
+ echo "LIB=" >> config.mak
+fi
+echo "SLIBPREF=$SLIBPREF" >> config.mak
+echo "SLIBSUF=\${BUILDSUF}$SLIBSUF" >> config.mak
+echo "EXESUF=\${BUILDSUF}$EXESUF" >> config.mak
+
+ucarch=`toupper $arch`
+echo "TARGET_ARCH_${ucarch}=yes" >> config.mak
+echo "#define ARCH_${ucarch} 1" >> $TMPH
+
+# special cases
+case "$arch" in
+ x86_32|x86_64)
+ echo "TARGET_ARCH_X86=yes" >> config.mak
+ echo "#define ARCH_X86 1" >> $TMPH
+ ;;
+ powerpc)
+ if test "$POWERPCMODE" = "64bits"; then
+ echo "#define POWERPC_MODE_64BITS 1" >> $TMPH
+ fi
+ ;;
+ sparc64)
+ echo "TARGET_ARCH_SPARC=yes" >> config.mak
+ echo "#define ARCH_SPARC 1" >> $TMPH
+ ;;
+esac
+
+if enabled bigendian; then
+ echo "WORDS_BIGENDIAN=yes" >> config.mak
+ echo "#define WORDS_BIGENDIAN 1" >> $TMPH
+fi
+if enabled mmx; then
+ echo "#define __CPU__ 586" >> $TMPH
+fi
+
+if enabled sdl; then
+ echo "SDL_LIBS=`"${SDL_CONFIG}" --libs`" >> config.mak
+ echo "SDL_CFLAGS=`"${SDL_CONFIG}" --cflags`" >> config.mak
+fi
+if enabled texi2html; then
+ echo "BUILD_DOC=yes" >> config.mak
+fi
+
+sws_version=`grep '#define LIBSWSCALE_VERSION ' "$source_path/libswscale/swscale.h" | sed 's/[^0-9\.]//g'`
+pp_version=`grep '#define LIBPOSTPROC_VERSION ' "$source_path/libpostproc/postprocess.h" | sed 's/[^0-9\.]//g'`
+lavc_version=`grep '#define LIBAVCODEC_VERSION ' "$source_path/libavcodec/avcodec.h" | sed 's/[^0-9\.]//g'`
+lavf_version=`grep '#define LIBAVFORMAT_VERSION ' "$source_path/libavformat/avformat.h" | sed 's/[^0-9\.]//g'`
+lavu_version=`grep '#define LIBAVUTIL_VERSION ' "$source_path/libavutil/avutil.h" | sed 's/[^0-9\.]//g'`
+
+
+
+if enabled shared; then
+ echo "BUILD_SHARED=yes" >> config.mak
+ echo "PIC=-fPIC -DPIC" >> config.mak
+ echo "SPPMAJOR=${pp_version%%.*}" >> config.mak
+ echo "SPPVERSION=$pp_version" >> config.mak
+ echo "LAVCMAJOR=${lavc_version%%.*}" >> config.mak
+ echo "LAVCVERSION=$lavc_version" >> config.mak
+ echo "LAVFMAJOR=${lavf_version%%.*}" >> config.mak
+ echo "LAVFVERSION=$lavf_version" >> config.mak
+ echo "LAVUMAJOR=${lavu_version%%.*}" >> config.mak
+ echo "LAVUVERSION=$lavu_version" >> config.mak
+ echo "SWSMAJOR=${sws_version%%.*}" >> config.mak
+ echo "SWSVERSION=$sws_version" >> config.mak
+ echo "SLIBNAME=${SLIBNAME}" >> config.mak
+ echo "SLIBNAME_WITH_VERSION=${SLIBNAME_WITH_VERSION}" >> config.mak
+ echo "SLIBNAME_WITH_MAJOR=${SLIBNAME_WITH_MAJOR}" >> config.mak
+ echo "SLIB_EXTRA_CMD=${SLIB_EXTRA_CMD}" >> config.mak
+ echo "SLIB_INSTALL_EXTRA_CMD=${SLIB_INSTALL_EXTRA_CMD}" >> config.mak
+fi
+echo "LIB_INSTALL_EXTRA_CMD=${LIB_INSTALL_EXTRA_CMD}" >> config.mak
+echo "EXTRALIBS=$extralibs" >> config.mak
+
+print_config HAVE_ $TMPH config.mak $HAVE_LIST
+print_config CONFIG_ $TMPH config.mak $CONFIG_LIST
+print_config TARGET_ $TMPH config.mak $TARGET_LIST
+
+if test "$targetos" = darwin; then
+ echo "#define CONFIG_DARWIN 1" >> $TMPH
+fi
+
+echo "#define restrict $_restrict" >> $TMPH
+
+if test "$optimize" = "small"; then
+ echo "#define always_inline" >> $TMPH
+ echo "#define CONFIG_SMALL 1" >> $TMPH
+fi
+
+echo "SRC_PATH=\"$source_path\"" >> config.mak
+echo "SRC_PATH_BARE=$source_path" >> config.mak
+echo "BUILD_ROOT=\"$PWD\"" >> config.mak
+
+if enabled amr_if2; then
+ echo "AMR_CFLAGS=-DIF2=1" >> config.mak
+fi
+
+# Apparently it's not possible to portably echo a backslash.
+if enabled asmalign_pot; then
+ printf '#define ASMALIGN(ZEROBITS) ".align " #ZEROBITS "\\n\\t"\n' >> $TMPH
+else
+ printf '#define ASMALIGN(ZEROBITS) ".align 1<<" #ZEROBITS "\\n\\t"\n' >> $TMPH
+fi
+
+
+for codec in $DECODER_LIST $ENCODER_LIST $PARSER_LIST $DEMUXER_LIST $MUXER_LIST; do
+ ucname="`toupper $codec`"
+ config_name="CONFIG_$ucname"
+ enabled_name="ENABLE_$ucname"
+ if enabled $codec; then
+ echo "#define $config_name 1" >> $TMPH
+ echo "#define $enabled_name 1" >> $TMPH
+ echo "$config_name=yes" >> config.mak
+ else
+ echo "#define $enabled_name 0" >> $TMPH
+ fi
+done
+
+# Do not overwrite config.h if unchanged to avoid superfluous rebuilds.
+if ! cmp -s $TMPH config.h; then
+ mv -f $TMPH config.h
+else
+ echo "config.h is unchanged"
+fi
+
+rm -f $TMPO $TMPC $TMPE $TMPS $TMPH
+
+# build tree in object directory if source path is different from current one
+if enabled source_path_used; then
+ DIRS="\
+ doc \
+ libavformat \
+ libavcodec \
+ libavcodec/alpha \
+ libavcodec/armv4l \
+ libavcodec/bfin \
+ libavcodec/i386 \
+ libavcodec/sparc \
+ libavcodec/mlib \
+ libavcodec/ppc \
+ libavcodec/amr \
+ libavcodec/amr_float \
+ libavcodec/amrwb_float \
+ libpostproc \
+ libavutil \
+ libswscale \
+ tests \
+ vhook \
+ "
+ FILES="\
+ Makefile \
+ common.mak \
+ libavformat/Makefile \
+ libavcodec/Makefile \
+ libpostproc/Makefile \
+ libavutil/Makefile \
+ libswscale/Makefile \
+ tests/Makefile \
+ vhook/Makefile \
+ doc/Makefile \
+ doc/texi2pod.pl \
+ "
+ for dir in $DIRS ; do
+ mkdir -p $dir
+ done
+ for f in $FILES ; do
+ ln -sf "$source_path/$f" $f
+ done
+fi
+
+
+# build pkg-config files
+# FIXME: libdir and includedir are hardcoded and may differ from the real path.
+
+pkgconfig_generate(){
+name=$1
+comment=$2
+version=$3
+libs=$4
+requires=$5
+include=$6
+cat <<EOF >$name.pc
+prefix=$PREFIX
+exec_prefix=\${prefix}
+libdir=\${exec_prefix}/lib
+includedir=\${prefix}/include
+
+Name: $name
+Description: $comment
+Version: $version
+Requires: $requires
+Conflicts:
+Libs: -L\${libdir} $libs
+Cflags: -I\${includedir} -I\${includedir}/$include
+EOF
+}
+
+pkgconfig_generate_uninstalled(){
+name=$1
+shortname=${name#lib}
+comment=$2
+version=$3
+libs=$4
+requires=$5
+cat <<EOF >$name-uninstalled.pc
+prefix=
+exec_prefix=
+libdir=\${pcfiledir}/$name
+includedir=\${pcfiledir}/$name
+
+Name: $name
+Description: $comment
+Version: $version
+Requires: $requires
+Conflicts:
+Libs: \${libdir}/${LIBPREF}${shortname}${LIBSUF} $libs
+Cflags: -I\${includedir}
+EOF
+}
+
+pkgconfig_generate libavutil "FFmpeg utility library" "$lavu_version" -lavutil "" ffmpeg
+pkgconfig_generate_uninstalled libavutil "FFmpeg utility library" "$lavu_version"
+
+pkgconfig_generate libavcodec "FFmpeg codec library" "$lavc_version" "-lavcodec $extralibs" "$pkg_requires libavutil = $lavu_version" ffmpeg
+pkgconfig_generate_uninstalled libavcodec "FFmpeg codec library" "$lavc_version" "$extralibs" "$pkg_requires libavutil = $lavu_version"
+
+pkgconfig_generate libavformat "FFmpeg container format library" "$lavf_version" "-lavformat $extralibs" "$pkg_requires libavcodec = $lavc_version" ffmpeg
+pkgconfig_generate_uninstalled libavformat "FFmpeg container format library" "$lavf_version" "$extralibs" "$pkg_requires libavcodec = $lavc_version"
+
+if enabled pp; then
+ pkgconfig_generate libpostproc "FFmpeg post processing library" "$pp_version" -lpostproc "" postproc
+ pkgconfig_generate_uninstalled libpostproc "FFmpeg post processing library" "$pp_version"
+fi
+
+if enabled swscaler; then
+ pkgconfig_generate libswscale "FFmpeg image rescaling library" "$sws_version" -lswscale "libavutil = $lavu_version" ffmpeg
+ pkgconfig_generate_uninstalled libswscale "FFmpeg image rescaling library" "$sws_version" "" "libavutil = $lavu_version"
+else
+ pkgconfig_generate libswscale "FFmpeg image rescaling library" "$sws_version" "" "$pkg_requires libavcodec = $lavc_version" ffmpeg
+ pkgconfig_generate_uninstalled libswscale "FFmpeg image rescaling library" "$sws_version" "" "$pkg_requires libavcodec = $lavc_version"
+ apply libswscale.pc sed s/^Libs:.*$/Libs:/
+ apply libswscale-uninstalled.pc sed s/^Libs:.*$/Libs:/
+fi
diff --git a/contrib/ffmpeg/cws2fws.c b/contrib/ffmpeg/cws2fws.c
new file mode 100644
index 000000000..2e70c6618
--- /dev/null
+++ b/contrib/ffmpeg/cws2fws.c
@@ -0,0 +1,127 @@
+/*
+ * cws2fws by Alex Beregszaszi <alex@fsn.hu>
+ * Public domain.
+ *
+ * This utility converts compressed Macromedia Flash files to uncompressed ones.
+ *
+ */
+
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <zlib.h>
+
+#ifdef DEBUG
+#define dbgprintf printf
+#else
+#define dbgprintf
+#endif
+
+main(int argc, char *argv[])
+{
+ int fd_in, fd_out, comp_len, uncomp_len, tag, i, last_out;
+ char buf_in[1024], buf_out[65536];
+ z_stream zstream;
+ struct stat statbuf;
+
+ if (argc < 3)
+ {
+ printf("Usage: %s <infile.swf> <outfile.swf>\n", argv[0]);
+ exit(1);
+ }
+
+ fd_in = open(argv[1], O_RDONLY);
+ if (fd_in < 0)
+ {
+ perror("Error while opening: ");
+ exit(1);
+ }
+
+ fd_out = open(argv[2], O_WRONLY|O_CREAT, 00644);
+ if (fd_out < 0)
+ {
+ perror("Error while opening: ");
+ close(fd_in);
+ exit(1);
+ }
+
+ if (read(fd_in, &buf_in, 8) != 8)
+ {
+ printf("Header error\n");
+ close(fd_in);
+ close(fd_out);
+ exit(1);
+ }
+
+ if (buf_in[0] != 'C' || buf_in[1] != 'W' || buf_in[2] != 'S')
+ {
+ printf("Not a compressed flash file\n");
+ exit(1);
+ }
+
+ fstat(fd_in, &statbuf);
+ comp_len = statbuf.st_size;
+ uncomp_len = buf_in[4] | (buf_in[5] << 8) | (buf_in[6] << 16) | (buf_in[7] << 24);
+
+ printf("Compressed size: %d Uncompressed size: %d\n", comp_len-4, uncomp_len-4);
+
+ // write out modified header
+ buf_in[0] = 'F';
+ write(fd_out, &buf_in, 8);
+
+ zstream.zalloc = NULL;
+ zstream.zfree = NULL;
+ zstream.opaque = NULL;
+ inflateInit(&zstream);
+
+ for (i = 0; i < comp_len-8;)
+ {
+ int ret, len = read(fd_in, &buf_in, 1024);
+
+ dbgprintf("read %d bytes\n", len);
+
+ last_out = zstream.total_out;
+
+ zstream.next_in = &buf_in[0];
+ zstream.avail_in = len;
+ zstream.next_out = &buf_out[0];
+ zstream.avail_out = 65536;
+
+ ret = inflate(&zstream, Z_SYNC_FLUSH);
+ if (ret != Z_STREAM_END && ret != Z_OK)
+ {
+ printf("Error while decompressing: %d\n", ret);
+ inflateEnd(&zstream);
+ exit(1);
+ }
+
+ dbgprintf("a_in: %d t_in: %d a_out: %d t_out: %d -- %d out\n",
+ zstream.avail_in, zstream.total_in, zstream.avail_out, zstream.total_out,
+ zstream.total_out-last_out);
+
+ write(fd_out, &buf_out, zstream.total_out-last_out);
+
+ i += len;
+
+ if (ret == Z_STREAM_END || ret == Z_BUF_ERROR)
+ break;
+ }
+
+ if (zstream.total_out != uncomp_len-8)
+ {
+ printf("Size mismatch (%d != %d), updating header...\n",
+ zstream.total_out, uncomp_len-8);
+
+ buf_in[0] = (zstream.total_out+8) & 0xff;
+ buf_in[1] = (zstream.total_out+8 >> 8) & 0xff;
+ buf_in[2] = (zstream.total_out+8 >> 16) & 0xff;
+ buf_in[3] = (zstream.total_out+8 >> 24) & 0xff;
+
+ lseek(fd_out, 4, SEEK_SET);
+ write(fd_out, &buf_in, 4);
+ }
+
+ inflateEnd(&zstream);
+ close(fd_in);
+ close(fd_out);
+}
diff --git a/contrib/ffmpeg/doc/Makefile b/contrib/ffmpeg/doc/Makefile
new file mode 100644
index 000000000..4fc9dfb8f
--- /dev/null
+++ b/contrib/ffmpeg/doc/Makefile
@@ -0,0 +1,20 @@
+-include ../config.mak
+
+VPATH=$(SRC_PATH_BARE)/doc
+
+all: ffmpeg-doc.html faq.html ffserver-doc.html ffplay-doc.html hooks.html \
+ ffmpeg.1 ffserver.1 ffplay.1
+
+%.html: %.texi Makefile
+ texi2html -monolithic -number $<
+
+%.pod: %-doc.texi
+ ./texi2pod.pl $< $@
+
+%.1: %.pod
+ pod2man --section=1 --center=" " --release=" " $< > $@
+
+clean:
+ rm -f *.html *.pod *.1
+
+.PHONY: all clean
diff --git a/contrib/ffmpeg/doc/TODO b/contrib/ffmpeg/doc/TODO
new file mode 100644
index 000000000..996ce3177
--- /dev/null
+++ b/contrib/ffmpeg/doc/TODO
@@ -0,0 +1,91 @@
+ffmpeg TODO list:
+----------------
+
+Fabrice's TODO list: (unordered)
+-------------------
+Short term:
+
+- use AVFMTCTX_DISCARD_PKT in ffplay so that DV has a chance to work
+- add RTSP regression test (both client and server)
+- make ffserver allocate AVFormatContext
+- clean up (incompatible change, for 0.5.0):
+ * AVStream -> AVComponent
+ * AVFormatContext -> AVInputStream/AVOutputStream
+ * suppress rate_emu from AVCodecContext
+- add new float/integer audio filterting and conversion : suppress
+ CODEC_ID_PCM_xxc and use CODEC_ID_RAWAUDIO.
+- fix telecine and frame rate conversion
+
+Long term (ask me if you want to help):
+
+- commit new imgconvert API and new PIX_FMT_xxx alpha formats
+- commit new LGPL'ed float and integer-only AC3 decoder
+- add WMA integer-only decoder
+- add new MPEG4-AAC audio decoder (both integer-only and float version)
+
+Michael's TODO list: (unordered) (if anyone wanna help with sth, just ask)
+-------------------
+- optimize H264 CABAC
+- more optimizations
+- simper rate control
+
+Francois' TODO list: (unordered, without any timeframe)
+-------------------
+- test MACE decoder against the openquicktime one as suggested by A'rpi
+- BeOS audio input grabbing backend
+- BeOS video input grabbing backend
+- publish my BeOS libposix on BeBits so I can officially support ffserver :)
+- check the whole code for thread-safety (global and init stuff)
+
+Philip'a TODO list: (alphabetically ordered) (please help)
+------------------
+- Add a multi-ffm filetype so that feeds can be recorded into multiple files rather
+ than one big file.
+- Authenticated users support -- where the authentication is in the URL
+- Change ASF files so that the embedded timestamp in the frames is right rather
+ than being an offset from the start of the stream
+- Make ffm files more resilient to changes in the codec structures so that you
+ can play old ffm files.
+
+Baptiste's TODO list:
+-----------------
+- mov edit list support (AVEditList)
+- YUV 10 bit per component support "2vuy"
+- mxf muxer
+- mpeg2 non linear quantizer
+
+unassigned TODO: (unordered)
+---------------
+- use AVFrame for audio codecs too
+- rework aviobuf.c buffering strategy and fix url_fskip
+- generate optimal huffman tables for mjpeg encoding
+- fix ffserver regression tests
+- support xvids motion estimation
+- support x264s motion estimation
+- support x264s rate control
+- SNOW: non translational motion compensation
+- SNOW: more optimal quantization
+- SNOW: 4x4 block support
+- SNOW: 1/8 pel motion compensation support
+- SNOW: iterative motion estimation based on subsampled images
+- FLAC: lossy encoding (viterbi and naive scalar quantization)
+- libavfilter
+- JPEG2000 decoder & encoder
+- MPEG4 GMC encoding support
+- macroblock based pixel format (better cache locality, somewhat complex, one paper claimed it faster for high res)
+- NUT muxer
+- seeking regression test
+- regression tests for codecs which dont have an encoder (I+P frame bitstream in svn)
+- add support for using mplayers video filters to ffmpeg
+- reverse engeneer RV30/RV40
+- finish implementation of WMV2 j-picture
+- H264 encoder
+- per MB ratecontrol (so VCD and such do work better)
+- replace/rewrite libavcodec/fdctref.c
+- write a script which iteratively changes all functions between always_inline and noinline and benchmarks the result to find the best set of inlined functions
+- set up roundup bugtracker somewhere with (newBug, reproduced, analyzed, fixed, worksForMe, duplicate, wontFix, invalid, needMoreInfo, newPatch, ok, applied, rejected, needChanges, newRequest, implemented, wontImplement, invalidReq) states and a checked integer
+- convert all the non SIMD asm into small asm vs. C testcases and submit them to the gcc devels so they can improve gcc
+- generic audio mixing API
+- extract PES packetizer from PS muxer and use it for new TS muxer
+- implement automatic AVBistreamFilter activation
+- port libavformat/sgi.c (now removed) to new image format API
diff --git a/contrib/ffmpeg/doc/avutil.txt b/contrib/ffmpeg/doc/avutil.txt
new file mode 100644
index 000000000..a81e74118
--- /dev/null
+++ b/contrib/ffmpeg/doc/avutil.txt
@@ -0,0 +1,37 @@
+AVUtil
+======
+libavutil is a small lightweight library of generally useful functions.
+It is not a library for code needed by both libavcodec and libavformat.
+
+
+Overview:
+=========
+adler32.c adler32 checksum
+aes.c AES encryption and decryption
+fifo.c resizeable first in first out buffer
+intfloat_readwrite.c portable reading and writing of floating point values
+log.c "printf" with context and level
+md5.c MD5 Message-Digest Algorithm
+rational.c code to perform exact calculations with rational numbers
+tree.c generic AVL tree
+crc.c generic CRC checksumming code
+integer.c 128bit integer math
+lls.c
+mathematics.c greatest common divisor, integer sqrt, integer log2, ...
+mem.c memory allocation routines with guaranteed alignment
+softfloat.c
+
+Headers:
+bswap.h big/little/native-endian conversion code
+x86_cpu.h a few useful macros for unifying x86-64 and x86-32 code
+avutil.h
+common.h
+intreadwrite.h reading and writing of unaligned big/little/native-endian integers
+
+
+Goals:
+======
+* Modular (few interdependencies and the possibility of disabling individual parts during ./configure)
+* Small (source and object)
+* Efficient (low CPU and memory usage)
+* Useful (avoid useless features almost noone needs)
diff --git a/contrib/ffmpeg/doc/faq.texi b/contrib/ffmpeg/doc/faq.texi
new file mode 100644
index 000000000..9c41679ae
--- /dev/null
+++ b/contrib/ffmpeg/doc/faq.texi
@@ -0,0 +1,363 @@
+\input texinfo @c -*- texinfo -*-
+
+@settitle FFmpeg FAQ
+@titlepage
+@sp 7
+@center @titlefont{FFmpeg FAQ}
+@sp 3
+@end titlepage
+
+
+@chapter General Problems
+
+@section I cannot read this file although this format seems to be supported by ffmpeg.
+
+Even if ffmpeg can read the file format, it may not support all its
+codecs. Please consult the supported codec list in the ffmpeg
+documentation.
+
+@section How do I encode JPEGs to another format ?
+
+If the JPEGs are named img1.jpg, img2.jpg, img3.jpg,..., use:
+
+@example
+ ffmpeg -f image2 -i img%d.jpg /tmp/a.mpg
+@end example
+
+@samp{%d} is replaced by the image number.
+
+@file{img%03d.jpg} generates @file{img001.jpg}, @file{img002.jpg}, etc...
+
+The same system is used for the other image formats.
+
+@section How do I encode movie to single pictures ?
+
+Use:
+
+@example
+ ffmpeg -i movie.mpg movie%d.jpg
+@end example
+
+The @file{movie.mpg} used as input will be converted to
+@file{movie1.jpg}, @file{movie2.jpg}, etc...
+
+Instead of relying on file format self-recognition, you may also use
+@table @option
+@item -vcodec ppm
+@item -vcodec png
+@item -vcodec mjpeg
+@end table
+to force the encoding.
+
+Applying that to the previous example:
+@example
+ ffmpeg -i movie.mpg -f image2 -vcodec mjpeg menu%d.jpg
+@end example
+
+Beware that there is no "jpeg" codec. Use "mjpeg" instead.
+
+@section FFmpeg does not support codec XXX. Can you include a Windows DLL loader to support it ?
+
+No. FFmpeg only supports open source codecs. Windows DLLs are not
+portable, bloated and often slow.
+
+@section I get "Unsupported codec (id=86043) for input stream #0.1". What is the problem ?
+
+This is the Qcelp codec, FFmpeg has no support for that codec currently. Try mencoder/mplayer it might work.
+
+@section Why do I see a slight quality degradation with multithreaded MPEG* encoding ?
+
+For multithreaded MPEG* encoding, the encoded slices must be independent,
+otherwise thread n would practically have to wait for n-1 to finish, so it's
+quite logical that there is a small reduction of quality. This is not a bug.
+
+@section How can I read from the standard input or write to the standard output ?
+
+Use @file{-} as filename.
+
+@section Why does ffmpeg not decode audio in VOB files ?
+
+The audio is AC3 (a.k.a. A/52). AC3 decoding is an optional component in ffmpeg
+as the component that handles AC3 decoding (liba52) is currently released under
+the GPL. If you have liba52 installed on your system, enable AC3 decoding
+with @code{./configure --enable-liba52 --enable-gpl}. Take care: by
+enabling AC3, you automatically change the license of libavcodec from
+LGPL to GPL.
+
+@section Which codecs are supported by Windows ?
+
+Windows does not support standard formats like MPEG very well, unless you
+install some additional codecs
+
+The following list of video codecs should work on most Windows systems:
+@table @option
+@item msmpeg4v2
+.avi/.asf
+@item msmpeg4
+.asf only
+@item wmv1
+.asf only
+@item wmv2
+.asf only
+@item mpeg4
+only if you have some MPEG-4 codec installed like ffdshow or XviD
+@item mpeg1
+.mpg only
+@end table
+Note, ASF files often have .wmv or .wma extensions in Windows. It should also
+be mentioned that Microsoft claims a patent on the ASF format, and may sue
+or threaten users who create ASF files with non-Microsoft software. It is
+strongly advised to avoid ASF where possible.
+
+The following list of audio codecs should work on most Windows systems:
+@table @option
+@item adpcm_ima_wav
+@item adpcm_ms
+@item pcm
+@item mp3
+if some MP3 codec like LAME is installed
+@end table
+
+@section Why does the chrominance data seem to be sampled at a different time from the luminance data on bt8x8 captures on Linux?
+
+This is a well-known bug in the bt8x8 driver. For 2.4.26 there is a patch at
+(@url{http://svn.mplayerhq.hu/michael/trunk/patches/bttv-420-2.4.26.patch?view=co}). This may also
+apply cleanly to other 2.4-series kernels.
+
+@section How do I avoid the ugly aliasing artifacts in bt8x8 captures on Linux?
+
+Pass 'combfilter=1 lumafilter=1' to the bttv driver. Note though that 'combfilter=1'
+will cause somewhat too strong filtering. A fix is to apply (@url{http://svn.mplayerhq.hu/michael/trunk/patches/bttv-comb-2.4.26.patch?view=co})
+or (@url{http://svn.mplayerhq.hu/michael/trunk/patches/bttv-comb-2.6.6.patch?view=co})
+and pass 'combfilter=2'.
+
+@section I have a problem with an old version of ffmpeg; where should I report it?
+Nowhere. Upgrade to the latest release or if there is no recent release upgrade
+to Subversion HEAD. You could also try to report it. Maybe you will get lucky and
+become the first person in history to get an answer different from "upgrade
+to Subversion HEAD".
+
+@section -f jpeg doesn't work.
+
+Try '-f image2 test%d.jpg'.
+
+@section Why can I not change the framerate?
+
+Some codecs, like MPEG-1/2, only allow a small number of fixed framerates.
+Choose a different codec with the -vcodec command line option.
+
+@section ffmpeg does not work; What is wrong?
+
+Try a 'make distclean' in the ffmpeg source directory before the build. If this does not help see
+(@url{http://ffmpeg.org/bugreports.php}).
+
+@section How do I encode XviD or DivX video with ffmpeg?
+
+Both XviD and DivX (version 4+) are implementations of the ISO MPEG-4
+standard (note that there are many other coding formats that use this
+same standard). Thus, use '-vcodec mpeg4' to encode these formats. The
+default fourcc stored in an MPEG-4-coded file will be 'FMP4'. If you want
+a different fourcc, use the '-vtag' option. E.g., '-vtag xvid' will
+force the fourcc 'xvid' to be stored as the video fourcc rather than the
+default.
+
+@section How do I encode videos which play on the iPod?
+
+@table @option
+@item needed stuff
+-acodec aac -vcodec mpeg4 width<=320 height<=240
+@item working stuff
+4mv, title
+@item non-working stuff
+B-frames
+@item example command line
+ffmpeg -i input -acodec aac -ab 128kb -vcodec mpeg4 -b 1200kb -mbd 2 -flags +4mv+trell -aic 2 -cmp 2 -subcmp 2 -s 320x180 -title X output.mp4
+@end table
+
+@section How do I encode videos which play on the PSP?
+
+@table @option
+@item needed stuff
+-acodec aac -vcodec mpeg4 width*height<=76800 width%16=0 height%16=0 -ar 24000 -r 30000/1001 or 15000/1001 -f psp
+@item working stuff
+4mv, title
+@item non-working stuff
+B-frames
+@item example command line
+ffmpeg -i input -acodec aac -ab 128kb -vcodec mpeg4 -b 1200kb -ar 24000 -mbd 2 -flags +4mv+trell -aic 2 -cmp 2 -subcmp 2 -s 368x192 -r 30000/1001 -title X -f psp output.mp4
+@item needed stuff for H.264
+-acodec aac -vcodec h264 width*height<=76800 width%16=0? height%16=0? -ar 48000 -coder 1 -r 30000/1001 or 15000/1001 -f psp
+@item working stuff for H.264
+title, loop filter
+@item non-working stuff for H.264
+CAVLC
+@item example command line
+ffmpeg -i input -acodec aac -ab 128kb -vcodec h264 -b 1200kb -ar 48000 -mbd 2 -coder 1 -cmp 2 -subcmp 2 -s 368x192 -r 30000/1001 -title X -f psp -flags loop -trellis 2 -partitions parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 output.mp4
+@end table
+
+@section Which are good parameters for encoding high quality MPEG-4?
+
+'-mbd rd -flags +4mv+trell+aic -cmp 2 -subcmp 2 -g 300 -pass 1/2',
+things to try: '-bf 2', '-flags qprd', '-flags mv0', '-flags skiprd'.
+
+@section Which are good parameters for encoding high quality MPEG-1/MPEG-2?
+
+'-mbd rd -flags +trell -cmp 2 -subcmp 2 -g 100 -pass 1/2'
+but beware the '-g 100' might cause problems with some decoders.
+Things to try: '-bf 2', '-flags qprd', '-flags mv0', '-flags skiprd.
+
+@section Interlaced video looks very bad when encoded with ffmpeg, whats wrong?
+
+You should use '-flags +ilme+ildct' and maybe '-flags +alt' for interlaced
+material, and try '-top 0/1' if the result looks really messed-up.
+
+@section How can I read DirectShow files?
+
+If you have built FFmpeg with @code{./configure --enable-avisynth}
+(only possible on MinGW/Cygwin platforms),
+then you may use any file that DirectShow can read as input.
+(Be aware that this feature has been recently added,
+so you will need to help yourself in case of problems.)
+
+Just create an "input.avs" text file with this single line ...
+@example
+ DirectShowSource("C:\path to your file\yourfile.asf")
+@end example
+... and then feed that text file to FFmpeg:
+@example
+ ffmpeg -i input.avs
+@end example
+
+For ANY other help on Avisynth, please visit @url{http://www.avisynth.org/}.
+
+@section My bugreport/mail to ffmpeg-devel/user has not received any replies.
+
+Likely reasons
+@itemize
+@item We are busy and haven't had time yet to read your report or
+investigate the issue.
+@item You didn't follow bugreports.html.
+@item You didn't use Subversion HEAD.
+@item You reported a segmentation fault without gdb output.
+@item You describe a problem but not how to reproduce it.
+@item It's unclear if you use ffmpeg as command line tool or use
+libav* from another application.
+@item You speak about a video having problems on playback but
+not what you use to play it.
+@item We have no faint clue what you are talking about besides
+that it is related to FFmpeg.
+@end itemize
+
+@chapter Development
+
+@section When will the next FFmpeg version be released? / Why are FFmpeg releases so few and far between?
+
+Like most open source projects FFmpeg suffers from a certain lack of
+manpower. For this reason the developers have to prioritize the work
+they do and putting out releases is not at the top of the list, fixing
+bugs and reviewing patches takes precedence. Please don't complain or
+request more timely and/or frequent releases unless you are willing to
+help out creating them.
+
+@section Why doesn't FFmpeg support feature [xyz]?
+
+Because no one has taken on that task yet. FFmpeg development is
+driven by the tasks that are important to the individual developers.
+If there is a feature that is important to you, the best way to get
+it implemented is to undertake the task yourself.
+
+
+@section Are there examples illustrating how to use the FFmpeg libraries, particularly libavcodec and libavformat ?
+
+Yes. Read the Developers Guide of the FFmpeg documentation. Alternatively,
+examine the source code for one of the many open source projects that
+already incorporate ffmpeg at (@url{projects.php}).
+
+@section Can you support my C compiler XXX ?
+
+It depends. If your compiler is C99-compliant, then patches to support
+it are likely to be welcome if they do not pollute the source code
+with @code{#ifdef}s related to the compiler.
+
+@section Visual C++ produces many errors.
+
+Visual C++ is not compliant to the C standard and does not support
+the inline assembly used in FFmpeg.
+If you wish - for whatever weird reason - to use Visual C++ for your
+project then you can link the Visual C++ code with libav* as long as
+you compile the latter with a working C compiler. For more information, see
+the @emph{Visual C++ compatibility} section in the FFmpeg documentation.
+
+There have been efforts to make FFmpeg compatible with Visual C++ in the
+past. However, they have all been rejected as too intrusive, especially
+since MinGW does the job perfectly adequately. None of the core developers
+work with Visual C++ and thus this item is low priority. Should you find
+the silver bullet that solves this problem, feel free to shoot it at us.
+
+@section Can I use FFmpeg or libavcodec under Windows ?
+
+Yes, but the MinGW tools @emph{must} be used to compile FFmpeg. You
+can link the resulting DLLs with any other Windows program. Read the
+@emph{Native Windows Compilation} and @emph{Visual C++ compatibility}
+sections in the FFmpeg documentation to find more information.
+
+To get help and instructions for using FFmpeg under Windows, check out
+the FFmpeg Windows Help Forum at
+@url{http://arrozcru.no-ip.org/ffmpeg/}.
+
+@section Can you add automake, libtool or autoconf support ?
+
+No. These tools are too bloated and they complicate the build.
+
+@section Why not rewrite ffmpeg in object-oriented C++ ?
+
+ffmpeg is already organized in a highly modular manner and does not need to
+be rewritten in a formal object language. Further, many of the developers
+favor straight C; it works for them. For more arguments on this matter,
+read "Programming Religion" at (@url{http://www.tux.org/lkml/#s15}).
+
+@section Why are the ffmpeg programs devoid of debugging symbols ?
+
+The build process creates ffmpeg_g, ffplay_g, etc. which contain full debug
+information. Those binaries are strip'd to create ffmpeg, ffplay, etc. If
+you need the debug information, used the *_g versions.
+
+@section I do not like the LGPL, can I contribute code under the GPL instead ?
+
+Yes, as long as the code is optional and can easily and cleanly be placed
+under #ifdef CONFIG_GPL without breaking anything. So for example a new codec
+or filter would be OK under GPL while a bugfix to LGPL code would not.
+
+@section I want to compile xyz.c alone but my compiler produced many errors.
+
+Common code is in its own files in libav* and is used by the individual
+codecs. They will not work without the common parts, you have to compile
+the whole libav*. If you wish, disable some parts with configure switches.
+You can also try to hack it and remove more, but if you had problems fixing
+the compilation failure then you are probably not qualified for this.
+
+@section I have a file in memory / a API different from *open/*read/ libc how do i use it with libavformat ?
+
+You have to implement a URLProtocol, see libavformat/file.c in FFmpeg
+and libmpdemux/demux_lavf.c in MPlayer sources.
+
+@section I get "No compatible shell script interpreter found." in MSys.
+
+The standard MSys bash (2.04) is broken. You need to install 2.05 or later.
+
+@section I tried to pass RTP packets into a decoder, but it doesn't work.
+
+Of course not, you MUST strip ALL RTP headers and assemble valid packets
+first, an MP3 decoder decodes MP3 packets not bastardized MP3 packets
+encapsulated in RTP. The same applies to all decoders, this is not specific
+to ffmpeg or libavcodec.
+
+@section where can i find libav* headers for pascal/delphi
+
+see @url{http://www.iversenit.dk/dev/ffmpeg-headers/}
+
+@section where are the docs about ffv1, msmpeg4, asv1, 4xm?
+
+see @url{http://svn.mplayerhq.hu/michael/trunk/docs/}
+
+@bye
diff --git a/contrib/ffmpeg/doc/ffmpeg-doc.texi b/contrib/ffmpeg/doc/ffmpeg-doc.texi
new file mode 100644
index 000000000..e4e6430fd
--- /dev/null
+++ b/contrib/ffmpeg/doc/ffmpeg-doc.texi
@@ -0,0 +1,1656 @@
+\input texinfo @c -*- texinfo -*-
+
+@settitle FFmpeg Documentation
+@titlepage
+@sp 7
+@center @titlefont{FFmpeg Documentation}
+@sp 3
+@end titlepage
+
+
+@chapter Introduction
+
+FFmpeg is a very fast video and audio converter. It can also grab from
+a live audio/video source.
+
+The command line interface is designed to be intuitive, in the sense
+that FFmpeg tries to figure out all parameters that can possibly be
+derived automatically. You usually only have to specify the target
+bitrate you want.
+
+FFmpeg can also convert from any sample rate to any other, and resize
+video on the fly with a high quality polyphase filter.
+
+@chapter Quick Start
+
+@c man begin EXAMPLES
+@section Video and Audio grabbing
+
+FFmpeg can grab video and audio from devices given that you specify the input
+format and device.
+
+@example
+ffmpeg -f audio_device -i /dev/dsp -f video4linux2 -i /dev/video0 /tmp/out.mpg
+@end example
+
+Note that you must activate the right video source and channel before
+launching FFmpeg with any TV viewer such as xawtv
+(@url{http://bytesex.org/xawtv/}) by Gerd Knorr. You also
+have to set the audio recording levels correctly with a
+standard mixer.
+
+@section X11 grabbing
+
+FFmpeg can grab the X11 display.
+
+@example
+ffmpeg -f x11grab -i :0.0 /tmp/out.mpg
+@end example
+
+0.0 is display.screen number of your X11 server, same as
+the DISPLAY environment variable.
+
+@example
+ffmpeg -f x11grab -i :0.0+10,20 /tmp/out.mpg
+@end example
+
+0.0 is display.screen number of your X11 server, same as the DISPLAY environment
+variable. 10 is the x-offset and 20 the y-offset for the grabbing.
+
+@section Video and Audio file format conversion
+
+* FFmpeg can use any supported file format and protocol as input:
+
+Examples:
+
+* You can use YUV files as input:
+
+@example
+ffmpeg -i /tmp/test%d.Y /tmp/out.mpg
+@end example
+
+It will use the files:
+@example
+/tmp/test0.Y, /tmp/test0.U, /tmp/test0.V,
+/tmp/test1.Y, /tmp/test1.U, /tmp/test1.V, etc...
+@end example
+
+The Y files use twice the resolution of the U and V files. They are
+raw files, without header. They can be generated by all decent video
+decoders. You must specify the size of the image with the @option{-s} option
+if FFmpeg cannot guess it.
+
+* You can input from a raw YUV420P file:
+
+@example
+ffmpeg -i /tmp/test.yuv /tmp/out.avi
+@end example
+
+test.yuv is a file containing raw YUV planar data. Each frame is composed
+of the Y plane followed by the U and V planes at half vertical and
+horizontal resolution.
+
+* You can output to a raw YUV420P file:
+
+@example
+ffmpeg -i mydivx.avi hugefile.yuv
+@end example
+
+* You can set several input files and output files:
+
+@example
+ffmpeg -i /tmp/a.wav -s 640x480 -i /tmp/a.yuv /tmp/a.mpg
+@end example
+
+Converts the audio file a.wav and the raw YUV video file a.yuv
+to MPEG file a.mpg.
+
+* You can also do audio and video conversions at the same time:
+
+@example
+ffmpeg -i /tmp/a.wav -ar 22050 /tmp/a.mp2
+@end example
+
+Converts a.wav to MPEG audio at 22050Hz sample rate.
+
+* You can encode to several formats at the same time and define a
+mapping from input stream to output streams:
+
+@example
+ffmpeg -i /tmp/a.wav -ab 64k /tmp/a.mp2 -ab 128k /tmp/b.mp2 -map 0:0 -map 0:0
+@end example
+
+Converts a.wav to a.mp2 at 64 kbits and to b.mp2 at 128 kbits. '-map
+file:index' specifies which input stream is used for each output
+stream, in the order of the definition of output streams.
+
+* You can transcode decrypted VOBs
+
+@example
+ffmpeg -i snatch_1.vob -f avi -vcodec mpeg4 -b 800k -g 300 -bf 2 -acodec mp3 -ab 128k snatch.avi
+@end example
+
+This is a typical DVD ripping example; the input is a VOB file, the
+output an AVI file with MPEG-4 video and MP3 audio. Note that in this
+command we use B-frames so the MPEG-4 stream is DivX5 compatible, and
+GOP size is 300 which means one intra frame every 10 seconds for 29.97fps
+input video. Furthermore, the audio stream is MP3-encoded so you need
+to enable LAME support by passing @code{--enable-mp3lame} to configure.
+The mapping is particularly useful for DVD transcoding
+to get the desired audio language.
+
+NOTE: To see the supported input formats, use @code{ffmpeg -formats}.
+@c man end
+
+@chapter Invocation
+
+@section Syntax
+
+The generic syntax is:
+
+@example
+@c man begin SYNOPSIS
+ffmpeg [[infile options][@option{-i} @var{infile}]]... @{[outfile options] @var{outfile}@}...
+@c man end
+@end example
+@c man begin DESCRIPTION
+As a general rule, options are applied to the next specified
+file. Therefore, order is important, and you can have the same
+option on the command line multiple times. Each occurrence is
+then applied to the next input or output file.
+
+* To set the video bitrate of the output file to 64kbit/s:
+@example
+ffmpeg -i input.avi -b 64k output.avi
+@end example
+
+* To force the frame rate of the input and output file to 24 fps:
+@example
+ffmpeg -r 24 -i input.avi output.avi
+@end example
+
+* To force the frame rate of the output file to 24 fps:
+@example
+ffmpeg -i input.avi -r 24 output.avi
+@end example
+
+* To force the frame rate of input file to 1 fps and the output file to 24 fps:
+@example
+ffmpeg -r 1 -i input.avi -r 24 output.avi
+@end example
+
+The format option may be needed for raw input files.
+
+By default, FFmpeg tries to convert as losslessly as possible: It
+uses the same audio and video parameters for the outputs as the one
+specified for the inputs.
+@c man end
+
+@c man begin OPTIONS
+@section Main options
+
+@table @option
+@item -L
+Show license.
+
+@item -h
+Show help.
+
+@item -version
+Show version.
+
+@item -formats
+Show available formats, codecs, protocols, ...
+
+@item -f fmt
+Force format.
+
+@item -i filename
+input filename
+
+@item -y
+Overwrite output files.
+
+@item -t duration
+Set the recording time in seconds.
+@code{hh:mm:ss[.xxx]} syntax is also supported.
+
+@item -fs limit_size
+Set the file size limit.
+
+@item -ss position
+Seek to given time position in seconds.
+@code{hh:mm:ss[.xxx]} syntax is also supported.
+
+@item -itsoffset offset
+Set the input time offset in seconds.
+@code{[-]hh:mm:ss[.xxx]} syntax is also supported.
+This option affects all the input files that follow it.
+The offset is added to the timestamps of the input files.
+Specifying a positive offset means that the corresponding
+streams are delayed by 'offset' seconds.
+
+@item -title string
+Set the title.
+
+@item -timestamp time
+Set the timestamp.
+
+@item -author string
+Set the author.
+
+@item -copyright string
+Set the copyright.
+
+@item -comment string
+Set the comment.
+
+@item -album string
+Set the album.
+
+@item -track number
+Set the track.
+
+@item -year number
+Set the year.
+
+@item -v verbose
+Control amount of logging.
+
+@item -target type
+Specify target file type ("vcd", "svcd", "dvd", "dv", "dv50", "pal-vcd",
+"ntsc-svcd", ... ). All the format options (bitrate, codecs,
+buffer sizes) are then set automatically. You can just type:
+
+@example
+ffmpeg -i myfile.avi -target vcd /tmp/vcd.mpg
+@end example
+
+Nevertheless you can specify additional options as long as you know
+they do not conflict with the standard, as in:
+
+@example
+ffmpeg -i myfile.avi -target vcd -bf 2 /tmp/vcd.mpg
+@end example
+
+@item -dframes number
+Set the number of data frames to record.
+
+@item -scodec codec
+Force subtitle codec ('copy' to copy stream).
+
+@item -newsubtitle
+Add a new subtitle stream to the current output stream.
+
+@item -slang code
+Set the ISO 639 language code (3 letters) of the current subtitle stream.
+
+@end table
+
+@section Video Options
+
+@table @option
+@item -b bitrate
+Set the video bitrate in bit/s (default = 200 kb/s).
+@item -vframes number
+Set the number of video frames to record.
+@item -r fps
+Set frame rate (Hz value, fraction or abbreviation), (default = 25).
+@item -s size
+Set frame size. The format is @samp{wxh} (ffserver default = 160x128, ffmpeg default = same as source).
+The following abbreviations are recognized:
+@table @samp
+@item sqcif
+128x96
+@item qcif
+176x144
+@item cif
+352x288
+@item 4cif
+704x576
+@end table
+
+@item -aspect aspect
+Set aspect ratio (4:3, 16:9 or 1.3333, 1.7777).
+@item -croptop size
+Set top crop band size (in pixels).
+@item -cropbottom size
+Set bottom crop band size (in pixels).
+@item -cropleft size
+Set left crop band size (in pixels).
+@item -cropright size
+Set right crop band size (in pixels).
+@item -padtop size
+Set top pad band size (in pixels).
+@item -padbottom size
+Set bottom pad band size (in pixels).
+@item -padleft size
+Set left pad band size (in pixels).
+@item -padright size
+Set right pad band size (in pixels).
+@item -padcolor (hex color)
+Set color of padded bands. The value for padcolor is expressed
+as a six digit hexadecimal number where the first two digits
+represent red, the middle two digits green and last two digits
+blue (default = 000000 (black)).
+@item -vn
+Disable video recording.
+@item -bt tolerance
+Set video bitrate tolerance (in bit/s).
+@item -maxrate bitrate
+Set max video bitrate tolerance (in bit/s).
+@item -minrate bitrate
+Set min video bitrate tolerance (in bit/s).
+@item -bufsize size
+Set rate control buffer size (in bits).
+@item -vcodec codec
+Force video codec to @var{codec}. Use the @code{copy} special value to
+tell that the raw codec data must be copied as is.
+@item -sameq
+Use same video quality as source (implies VBR).
+
+@item -pass n
+Select the pass number (1 or 2). It is useful to do two pass
+encoding. The statistics of the video are recorded in the first
+pass and the video is generated at the exact requested bitrate
+in the second pass.
+
+@item -passlogfile file
+Set two pass logfile name to @var{file}.
+
+@item -newvideo
+Add a new video stream to the current output stream.
+
+@end table
+
+@section Advanced Video Options
+
+@table @option
+@item -pix_fmt format
+Set pixel format.
+@item -g gop_size
+Set the group of pictures size.
+@item -intra
+Use only intra frames.
+@item -vdt n
+Discard threshold.
+@item -qscale q
+Use fixed video quantizer scale (VBR).
+@item -qmin q
+minimum video quantizer scale (VBR)
+@item -qmax q
+maximum video quantizer scale (VBR)
+@item -qdiff q
+maximum difference between the quantizer scales (VBR)
+@item -qblur blur
+video quantizer scale blur (VBR)
+@item -qcomp compression
+video quantizer scale compression (VBR)
+
+@item -lmin lambda
+minimum video lagrange factor (VBR)
+@item -lmax lambda
+max video lagrange factor (VBR)
+@item -mblmin lambda
+minimum macroblock quantizer scale (VBR)
+@item -mblmax lambda
+maximum macroblock quantizer scale (VBR)
+
+These four options (lmin, lmax, mblmin, mblmax) use 'lambda' units,
+but you may use the QP2LAMBDA constant to easily convert from 'q' units:
+@example
+ffmpeg -i src.ext -lmax 21*QP2LAMBDA dst.ext
+@end example
+
+@item -rc_init_cplx complexity
+initial complexity for single pass encoding
+@item -b_qfactor factor
+qp factor between P- and B-frames
+@item -i_qfactor factor
+qp factor between P- and I-frames
+@item -b_qoffset offset
+qp offset between P- and B-frames
+@item -i_qoffset offset
+qp offset between P- and I-frames
+@item -rc_eq equation
+Set rate control equation (@pxref{FFmpeg formula
+evaluator}) (default = @code{tex^qComp}).
+@item -rc_override override
+rate control override for specific intervals
+@item -me method
+Set motion estimation method to @var{method}.
+Available methods are (from lowest to best quality):
+@table @samp
+@item zero
+Try just the (0, 0) vector.
+@item phods
+@item log
+@item x1
+@item epzs
+(default method)
+@item full
+exhaustive search (slow and marginally better than epzs)
+@end table
+
+@item -dct_algo algo
+Set DCT algorithm to @var{algo}. Available values are:
+@table @samp
+@item 0
+FF_DCT_AUTO (default)
+@item 1
+FF_DCT_FASTINT
+@item 2
+FF_DCT_INT
+@item 3
+FF_DCT_MMX
+@item 4
+FF_DCT_MLIB
+@item 5
+FF_DCT_ALTIVEC
+@end table
+
+@item -idct_algo algo
+Set IDCT algorithm to @var{algo}. Available values are:
+@table @samp
+@item 0
+FF_IDCT_AUTO (default)
+@item 1
+FF_IDCT_INT
+@item 2
+FF_IDCT_SIMPLE
+@item 3
+FF_IDCT_SIMPLEMMX
+@item 4
+FF_IDCT_LIBMPEG2MMX
+@item 5
+FF_IDCT_PS2
+@item 6
+FF_IDCT_MLIB
+@item 7
+FF_IDCT_ARM
+@item 8
+FF_IDCT_ALTIVEC
+@item 9
+FF_IDCT_SH4
+@item 10
+FF_IDCT_SIMPLEARM
+@end table
+
+@item -er n
+Set error resilience to @var{n}.
+@table @samp
+@item 1
+FF_ER_CAREFUL (default)
+@item 2
+FF_ER_COMPLIANT
+@item 3
+FF_ER_AGGRESSIVE
+@item 4
+FF_ER_VERY_AGGRESSIVE
+@end table
+
+@item -ec bit_mask
+Set error concealment to @var{bit_mask}. @var{bit_mask} is a bit mask of
+the following values:
+@table @samp
+@item 1
+FF_EC_GUESS_MVS (default = enabled)
+@item 2
+FF_EC_DEBLOCK (default = enabled)
+@end table
+
+@item -bf frames
+Use 'frames' B-frames (supported for MPEG-1, MPEG-2 and MPEG-4).
+@item -mbd mode
+macroblock decision
+@table @samp
+@item 0
+FF_MB_DECISION_SIMPLE: Use mb_cmp (cannot change it yet in FFmpeg).
+@item 1
+FF_MB_DECISION_BITS: Choose the one which needs the fewest bits.
+@item 2
+FF_MB_DECISION_RD: rate distortion
+@end table
+
+@item -4mv
+Use four motion vector by macroblock (MPEG-4 only).
+@item -part
+Use data partitioning (MPEG-4 only).
+@item -bug param
+Work around encoder bugs that are not auto-detected.
+@item -strict strictness
+How strictly to follow the standards.
+@item -aic
+Enable Advanced intra coding (h263+).
+@item -umv
+Enable Unlimited Motion Vector (h263+)
+
+@item -deinterlace
+Deinterlace pictures.
+@item -ilme
+Force interlacing support in encoder (MPEG-2 and MPEG-4 only).
+Use this option if your input file is interlaced and you want
+to keep the interlaced format for minimum losses.
+The alternative is to deinterlace the input stream with
+@option{-deinterlace}, but deinterlacing introduces losses.
+@item -psnr
+Calculate PSNR of compressed frames.
+@item -vstats
+Dump video coding statistics to @file{vstats_HHMMSS.log}.
+@item -vhook module
+Insert video processing @var{module}. @var{module} contains the module
+name and its parameters separated by spaces.
+@item -top n
+top=1/bottom=0/auto=-1 field first
+@item -dc precision
+Intra_dc_precision.
+@item -vtag fourcc/tag
+Force video tag/fourcc.
+@item -qphist
+Show QP histogram.
+@item -vbsf bitstream filter
+Bitstream filters available are "dump_extra", "remove_extra", "noise".
+@end table
+
+@section Audio Options
+
+@table @option
+@item -aframes number
+Set the number of audio frames to record.
+@item -ar freq
+Set the audio sampling frequency (default = 44100 Hz).
+@item -ab bitrate
+Set the audio bitrate in bit/s (default = 64k).
+@item -ac channels
+Set the number of audio channels (default = 1).
+@item -an
+Disable audio recording.
+@item -acodec codec
+Force audio codec to @var{codec}. Use the @code{copy} special value to
+specify that the raw codec data must be copied as is.
+@item -newaudio
+Add a new audio track to the output file. If you want to specify parameters,
+do so before @code{-newaudio} (@code{-acodec}, @code{-ab}, etc..).
+
+Mapping will be done automatically, if the number of output streams is equal to
+the number of input streams, else it will pick the first one that matches. You
+can override the mapping using @code{-map} as usual.
+
+Example:
+@example
+ffmpeg -i file.mpg -vcodec copy -acodec ac3 -ab 384k test.mpg -acodec mp2 -ab 192k -newaudio
+@end example
+@item -alang code
+Set the ISO 639 language code (3 letters) of the current audio stream.
+@end table
+
+@section Advanced Audio options:
+
+@table @option
+@item -atag fourcc/tag
+Force audio tag/fourcc.
+@item -absf bitstream filter
+Bitstream filters available are "dump_extra", "remove_extra", "noise", "mp3comp", "mp3decomp".
+@end table
+
+@section Subtitle options:
+
+@table @option
+@item -scodec codec
+Force subtitle codec ('copy' to copy stream).
+@item -newsubtitle
+Add a new subtitle stream to the current output stream.
+@item -slang code
+Set the ISO 639 language code (3 letters) of the current subtitle stream.
+@end table
+
+@section Audio/Video grab options
+
+@table @option
+@item -vc channel
+Set video grab channel (DV1394 only).
+@item -tvstd standard
+Set television standard (NTSC, PAL (SECAM)).
+@item -isync
+Synchronize read on input.
+@end table
+
+@section Advanced options
+
+@table @option
+@item -map input stream id[:input stream id]
+Set stream mapping from input streams to output streams.
+Just enumerate the input streams in the order you want them in the output.
+[input stream id] sets the (input) stream to sync against.
+@item -map_meta_data outfile:infile
+Set meta data information of outfile from infile.
+@item -debug
+Print specific debug info.
+@item -benchmark
+Add timings for benchmarking.
+@item -dump
+Dump each input packet.
+@item -hex
+When dumping packets, also dump the payload.
+@item -bitexact
+Only use bit exact algorithms (for codec testing).
+@item -ps size
+Set packet size in bits.
+@item -re
+Read input at native frame rate. Mainly used to simulate a grab device.
+@item -loop_input
+Loop over the input stream. Currently it works only for image
+streams. This option is used for automatic FFserver testing.
+@item -loop_output number_of_times
+Repeatedly loop output for formats that support looping such as animated GIF
+(0 will loop the output infinitely).
+@item -threads count
+Thread count.
+@item -vsync parameter
+Video sync method. Video will be stretched/squeezed to match the timestamps,
+it is done by duplicating and dropping frames. With -map you can select from
+which stream the timestamps should be taken. You can leave either video or
+audio unchanged and sync the remaining stream(s) to the unchanged one.
+@item -async samples_per_second
+Audio sync method. "Stretches/squeezes" the audio stream to match the timestamps,
+the parameter is the maximum samples per second by which the audio is changed.
+-async 1 is a special case where only the start of the audio stream is corrected
+without any later correction.
+@end table
+
+@node FFmpeg formula evaluator
+@section FFmpeg formula evaluator
+
+When evaluating a rate control string, FFmpeg uses an internal formula
+evaluator.
+
+The following binary operators are available: @code{+}, @code{-},
+@code{*}, @code{/}, @code{^}.
+
+The following unary operators are available: @code{+}, @code{-},
+@code{(...)}.
+
+The following functions are available:
+@table @var
+@item sinh(x)
+@item cosh(x)
+@item tanh(x)
+@item sin(x)
+@item cos(x)
+@item tan(x)
+@item exp(x)
+@item log(x)
+@item squish(x)
+@item gauss(x)
+@item abs(x)
+@item max(x, y)
+@item min(x, y)
+@item gt(x, y)
+@item lt(x, y)
+@item eq(x, y)
+@item bits2qp(bits)
+@item qp2bits(qp)
+@end table
+
+The following constants are available:
+@table @var
+@item PI
+@item E
+@item iTex
+@item pTex
+@item tex
+@item mv
+@item fCode
+@item iCount
+@item mcVar
+@item var
+@item isI
+@item isP
+@item isB
+@item avgQP
+@item qComp
+@item avgIITex
+@item avgPITex
+@item avgPPTex
+@item avgBPTex
+@item avgTex
+@end table
+
+@c man end
+
+@ignore
+
+@setfilename ffmpeg
+@settitle FFmpeg video converter
+
+@c man begin SEEALSO
+ffserver(1), ffplay(1) and the HTML documentation of @file{ffmpeg}.
+@c man end
+
+@c man begin AUTHOR
+Fabrice Bellard
+@c man end
+
+@end ignore
+
+@section Protocols
+
+The filename can be @file{-} to read from standard input or to write
+to standard output.
+
+FFmpeg also handles many protocols specified with an URL syntax.
+
+Use 'ffmpeg -formats' to see a list of the supported protocols.
+
+The protocol @code{http:} is currently used only to communicate with
+FFserver (see the FFserver documentation). When FFmpeg will be a
+video player it will also be used for streaming :-)
+
+@chapter Tips
+
+@itemize
+@item For streaming at very low bitrate application, use a low frame rate
+and a small GOP size. This is especially true for RealVideo where
+the Linux player does not seem to be very fast, so it can miss
+frames. An example is:
+
+@example
+ffmpeg -g 3 -r 3 -t 10 -b 50k -s qcif -f rv10 /tmp/b.rm
+@end example
+
+@item The parameter 'q' which is displayed while encoding is the current
+quantizer. The value 1 indicates that a very good quality could
+be achieved. The value 31 indicates the worst quality. If q=31 appears
+too often, it means that the encoder cannot compress enough to meet
+your bitrate. You must either increase the bitrate, decrease the
+frame rate or decrease the frame size.
+
+@item If your computer is not fast enough, you can speed up the
+compression at the expense of the compression ratio. You can use
+'-me zero' to speed up motion estimation, and '-intra' to disable
+motion estimation completely (you have only I-frames, which means it
+is about as good as JPEG compression).
+
+@item To have very low audio bitrates, reduce the sampling frequency
+(down to 22050 kHz for MPEG audio, 22050 or 11025 for AC3).
+
+@item To have a constant quality (but a variable bitrate), use the option
+'-qscale n' when 'n' is between 1 (excellent quality) and 31 (worst
+quality).
+
+@item When converting video files, you can use the '-sameq' option which
+uses the same quality factor in the encoder as in the decoder.
+It allows almost lossless encoding.
+
+@end itemize
+
+
+@chapter external libraries
+
+FFmpeg can be hooked up with a number of external libraries to add support
+for more formats.
+
+@section AMR
+
+AMR comes in two different flavors, WB and NB. FFmpeg can make use of the
+AMR WB (floating-point mode) and the AMR NB (both floating-point and
+fixed-point mode) reference decoders and encoders.
+
+@itemize
+
+@item For AMR WB floating-point download TS26.204 V5.1.0 from
+@url{http://www.3gpp.org/ftp/Specs/archive/26_series/26.204/26204-510.zip}
+and extract the source to @file{libavcodec/amrwb_float/}.
+
+@item For AMR NB floating-point download TS26.104 REL-5 V5.1.0 from
+@url{http://www.3gpp.org/ftp/Specs/archive/26_series/26.104/26104-510.zip}
+and extract the source to @file{libavcodec/amr_float/}.
+If you try this on Alpha, you may need to change @code{Word32} to
+@code{int} in @file{amr/typedef.h}.
+
+@item For AMR NB fixed-point download TS26.073 REL-5 V5.1.0 from
+@url{http://www.3gpp.org/ftp/Specs/archive/26_series/26.073/26073-510.zip}
+and extract the source to @file{libavcodec/amr}.
+You must also add @code{-DMMS_IO} and remove @code{-pedantic-errors}
+to/from @code{CFLAGS} in @file{libavcodec/amr/makefile}, i.e.
+``@code{CFLAGS = -Wall -I. \$(CFLAGS_\$(MODE)) -D\$(VAD) -DMMS_IO}''.
+
+@end itemize
+
+
+@chapter Supported File Formats and Codecs
+
+You can use the @code{-formats} option to have an exhaustive list.
+
+@section File Formats
+
+FFmpeg supports the following file formats through the @code{libavformat}
+library:
+
+@multitable @columnfractions .4 .1 .1 .4
+@item Supported File Format @tab Encoding @tab Decoding @tab Comments
+@item MPEG audio @tab X @tab X
+@item MPEG-1 systems @tab X @tab X
+@tab muxed audio and video
+@item MPEG-2 PS @tab X @tab X
+@tab also known as @code{VOB} file
+@item MPEG-2 TS @tab @tab X
+@tab also known as DVB Transport Stream
+@item ASF@tab X @tab X
+@item AVI@tab X @tab X
+@item WAV@tab X @tab X
+@item Macromedia Flash@tab X @tab X
+@tab Only embedded audio is decoded.
+@item FLV @tab X @tab X
+@tab Macromedia Flash video files
+@item Real Audio and Video @tab X @tab X
+@item Raw AC3 @tab X @tab X
+@item Raw MJPEG @tab X @tab X
+@item Raw MPEG video @tab X @tab X
+@item Raw PCM8/16 bits, mulaw/Alaw@tab X @tab X
+@item Raw CRI ADX audio @tab X @tab X
+@item Raw Shorten audio @tab @tab X
+@item SUN AU format @tab X @tab X
+@item NUT @tab X @tab X @tab NUT Open Container Format
+@item QuickTime @tab X @tab X
+@item MPEG-4 @tab X @tab X
+@tab MPEG-4 is a variant of QuickTime.
+@item Raw MPEG4 video @tab X @tab X
+@item DV @tab X @tab X
+@item 4xm @tab @tab X
+@tab 4X Technologies format, used in some games.
+@item Playstation STR @tab @tab X
+@item Id RoQ @tab @tab X
+@tab Used in Quake III, Jedi Knight 2, other computer games.
+@item Interplay MVE @tab @tab X
+@tab Format used in various Interplay computer games.
+@item WC3 Movie @tab @tab X
+@tab Multimedia format used in Origin's Wing Commander III computer game.
+@item Sega FILM/CPK @tab @tab X
+@tab Used in many Sega Saturn console games.
+@item Westwood Studios VQA/AUD @tab @tab X
+@tab Multimedia formats used in Westwood Studios games.
+@item Id Cinematic (.cin) @tab @tab X
+@tab Used in Quake II.
+@item FLIC format @tab @tab X
+@tab .fli/.flc files
+@item Sierra VMD @tab @tab X
+@tab Used in Sierra CD-ROM games.
+@item Sierra Online @tab @tab X
+@tab .sol files used in Sierra Online games.
+@item Matroska @tab @tab X
+@item Electronic Arts Multimedia @tab @tab X
+@tab Used in various EA games; files have extensions like WVE and UV2.
+@item Nullsoft Video (NSV) format @tab @tab X
+@item ADTS AAC audio @tab X @tab X
+@item Creative VOC @tab X @tab X @tab Created for the Sound Blaster Pro.
+@item American Laser Games MM @tab @tab X
+@tab Multimedia format used in games like Mad Dog McCree
+@item AVS @tab @tab X
+@tab Multimedia format used by the Creature Shock game.
+@item Smacker @tab @tab X
+@tab Multimedia format used by many games.
+@item GXF @tab X @tab X
+@tab General eXchange Format SMPTE 360M, used by Thomson Grass Valley playout servers.
+@item CIN @tab @tab X
+@tab Multimedia format used by Delphine Software games.
+@item MXF @tab @tab X
+@tab Material eXchange Format SMPTE 377M, used by D-Cinema, broadcast industry.
+@item SEQ @tab @tab X
+@tab Tiertex .seq files used in the DOS CDROM version of the game Flashback.
+@item DXA @tab @tab X
+@tab This format is used in non-Windows version of Feeble Files game and
+different game cutscenes repacked for use with ScummVM.
+@item THP @tab @tab X
+@tab Used on the Nintendo GameCube (video only)
+@end multitable
+
+@code{X} means that encoding (resp. decoding) is supported.
+
+@section Image Formats
+
+FFmpeg can read and write images for each frame of a video sequence. The
+following image formats are supported:
+
+@multitable @columnfractions .4 .1 .1 .4
+@item Supported Image Format @tab Encoding @tab Decoding @tab Comments
+@item PGM, PPM @tab X @tab X
+@item PAM @tab X @tab X @tab PAM is a PNM extension with alpha support.
+@item PGMYUV @tab X @tab X @tab PGM with U and V components in YUV 4:2:0
+@item JPEG @tab X @tab X @tab Progressive JPEG is not supported.
+@item .Y.U.V @tab X @tab X @tab one raw file per component
+@item animated GIF @tab X @tab X @tab Only uncompressed GIFs are generated.
+@item PNG @tab X @tab X @tab 2 bit and 4 bit/pixel not supported yet.
+@item Targa @tab @tab X @tab Targa (.TGA) image format.
+@item TIFF @tab @tab X @tab Only 24 bit/pixel images are supported.
+@item SGI @tab X @tab X @tab SGI RGB image format
+@end multitable
+
+@code{X} means that encoding (resp. decoding) is supported.
+
+@section Video Codecs
+
+@multitable @columnfractions .4 .1 .1 .4
+@item Supported Codec @tab Encoding @tab Decoding @tab Comments
+@item MPEG-1 video @tab X @tab X
+@item MPEG-2 video @tab X @tab X
+@item MPEG-4 @tab X @tab X
+@item MSMPEG4 V1 @tab X @tab X
+@item MSMPEG4 V2 @tab X @tab X
+@item MSMPEG4 V3 @tab X @tab X
+@item WMV7 @tab X @tab X
+@item WMV8 @tab X @tab X @tab not completely working
+@item WMV9 @tab @tab X @tab not completely working
+@item VC1 @tab @tab X
+@item H.261 @tab X @tab X
+@item H.263(+) @tab X @tab X @tab also known as RealVideo 1.0
+@item H.264 @tab @tab X
+@item RealVideo 1.0 @tab X @tab X
+@item RealVideo 2.0 @tab X @tab X
+@item MJPEG @tab X @tab X
+@item lossless MJPEG @tab X @tab X
+@item JPEG-LS @tab X @tab X @tab fourcc: MJLS, lossless and near-lossless is supported
+@item Apple MJPEG-B @tab @tab X
+@item Sunplus MJPEG @tab @tab X @tab fourcc: SP5X
+@item DV @tab X @tab X
+@item HuffYUV @tab X @tab X
+@item FFmpeg Video 1 @tab X @tab X @tab experimental lossless codec (fourcc: FFV1)
+@item FFmpeg Snow @tab X @tab X @tab experimental wavelet codec (fourcc: SNOW)
+@item Asus v1 @tab X @tab X @tab fourcc: ASV1
+@item Asus v2 @tab X @tab X @tab fourcc: ASV2
+@item Creative YUV @tab @tab X @tab fourcc: CYUV
+@item Sorenson Video 1 @tab X @tab X @tab fourcc: SVQ1
+@item Sorenson Video 3 @tab @tab X @tab fourcc: SVQ3
+@item On2 VP3 @tab @tab X @tab still experimental
+@item On2 VP5 @tab @tab X @tab fourcc: VP50
+@item On2 VP6 @tab @tab X @tab fourcc: VP60,VP61,VP62
+@item Theora @tab X @tab X @tab still experimental
+@item Intel Indeo 3 @tab @tab X
+@item FLV @tab X @tab X @tab Sorenson H.263 used in Flash
+@item Flash Screen Video @tab X @tab X @tab fourcc: FSV1
+@item ATI VCR1 @tab @tab X @tab fourcc: VCR1
+@item ATI VCR2 @tab @tab X @tab fourcc: VCR2
+@item Cirrus Logic AccuPak @tab @tab X @tab fourcc: CLJR
+@item 4X Video @tab @tab X @tab Used in certain computer games.
+@item Sony Playstation MDEC @tab @tab X
+@item Id RoQ @tab @tab X @tab Used in Quake III, Jedi Knight 2, other computer games.
+@item Xan/WC3 @tab @tab X @tab Used in Wing Commander III .MVE files.
+@item Interplay Video @tab @tab X @tab Used in Interplay .MVE files.
+@item Apple Animation @tab @tab X @tab fourcc: 'rle '
+@item Apple Graphics @tab @tab X @tab fourcc: 'smc '
+@item Apple Video @tab @tab X @tab fourcc: rpza
+@item Apple QuickDraw @tab @tab X @tab fourcc: qdrw
+@item Cinepak @tab @tab X
+@item Microsoft RLE @tab @tab X
+@item Microsoft Video-1 @tab @tab X
+@item Westwood VQA @tab @tab X
+@item Id Cinematic Video @tab @tab X @tab Used in Quake II.
+@item Planar RGB @tab @tab X @tab fourcc: 8BPS
+@item FLIC video @tab @tab X
+@item Duck TrueMotion v1 @tab @tab X @tab fourcc: DUCK
+@item Duck TrueMotion v2 @tab @tab X @tab fourcc: TM20
+@item VMD Video @tab @tab X @tab Used in Sierra VMD files.
+@item MSZH @tab @tab X @tab Part of LCL
+@item ZLIB @tab X @tab X @tab Part of LCL, encoder experimental
+@item TechSmith Camtasia @tab @tab X @tab fourcc: TSCC
+@item IBM Ultimotion @tab @tab X @tab fourcc: ULTI
+@item Miro VideoXL @tab @tab X @tab fourcc: VIXL
+@item QPEG @tab @tab X @tab fourccs: QPEG, Q1.0, Q1.1
+@item LOCO @tab @tab X @tab
+@item Winnov WNV1 @tab @tab X @tab
+@item Autodesk Animator Studio Codec @tab @tab X @tab fourcc: AASC
+@item Fraps FPS1 @tab @tab X @tab
+@item CamStudio @tab @tab X @tab fourcc: CSCD
+@item American Laser Games Video @tab @tab X @tab Used in games like Mad Dog McCree
+@item ZMBV @tab X @tab X @tab Encoder works only on PAL8
+@item AVS Video @tab @tab X @tab Video encoding used by the Creature Shock game.
+@item Smacker Video @tab @tab X @tab Video encoding used in Smacker.
+@item RTjpeg @tab @tab X @tab Video encoding used in NuppelVideo files.
+@item KMVC @tab @tab X @tab Codec used in Worms games.
+@item VMware Video @tab @tab X @tab Codec used in videos captured by VMware.
+@item Cin Video @tab @tab X @tab Codec used in Delphine Software games.
+@item Tiertex Seq Video @tab @tab X @tab Codec used in DOS CDROM FlashBack game.
+@item DXA Video @tab @tab X @tab Codec originally used in Feeble Files game.
+@item AVID DNxHD @tab @tab X @tab aka SMPTE VC3
+@end multitable
+
+@code{X} means that encoding (resp. decoding) is supported.
+
+@section Audio Codecs
+
+@multitable @columnfractions .4 .1 .1 .1 .7
+@item Supported Codec @tab Encoding @tab Decoding @tab Comments
+@item MPEG audio layer 2 @tab IX @tab IX
+@item MPEG audio layer 1/3 @tab IX @tab IX
+@tab MP3 encoding is supported through the external library LAME.
+@item AC3 @tab IX @tab IX
+@tab liba52 is used internally for decoding.
+@item Vorbis @tab X @tab X
+@item WMA V1/V2 @tab X @tab X
+@item AAC @tab X @tab X
+@tab Supported through the external library libfaac/libfaad.
+@item Microsoft ADPCM @tab X @tab X
+@item MS IMA ADPCM @tab X @tab X
+@item QT IMA ADPCM @tab @tab X
+@item 4X IMA ADPCM @tab @tab X
+@item G.726 ADPCM @tab X @tab X
+@item Duck DK3 IMA ADPCM @tab @tab X
+@tab Used in some Sega Saturn console games.
+@item Duck DK4 IMA ADPCM @tab @tab X
+@tab Used in some Sega Saturn console games.
+@item Westwood Studios IMA ADPCM @tab @tab X
+@tab Used in Westwood Studios games like Command and Conquer.
+@item SMJPEG IMA ADPCM @tab @tab X
+@tab Used in certain Loki game ports.
+@item CD-ROM XA ADPCM @tab @tab X
+@item CRI ADX ADPCM @tab X @tab X
+@tab Used in Sega Dreamcast games.
+@item Electronic Arts ADPCM @tab @tab X
+@tab Used in various EA titles.
+@item Creative ADPCM @tab @tab X
+@tab 16 -> 4, 8 -> 4, 8 -> 3, 8 -> 2
+@item RA144 @tab @tab X
+@tab Real 14400 bit/s codec
+@item RA288 @tab @tab X
+@tab Real 28800 bit/s codec
+@item RADnet @tab X @tab IX
+@tab Real low bitrate AC3 codec, liba52 is used for decoding.
+@item AMR-NB @tab X @tab X
+@tab Supported through an external library.
+@item AMR-WB @tab X @tab X
+@tab Supported through an external library.
+@item DV audio @tab @tab X
+@item Id RoQ DPCM @tab @tab X
+@tab Used in Quake III, Jedi Knight 2, other computer games.
+@item Interplay MVE DPCM @tab @tab X
+@tab Used in various Interplay computer games.
+@item Xan DPCM @tab @tab X
+@tab Used in Origin's Wing Commander IV AVI files.
+@item Sierra Online DPCM @tab @tab X
+@tab Used in Sierra Online game audio files.
+@item Apple MACE 3 @tab @tab X
+@item Apple MACE 6 @tab @tab X
+@item FLAC lossless audio @tab @tab X
+@item Shorten lossless audio @tab @tab X
+@item Apple lossless audio @tab @tab X
+@tab QuickTime fourcc 'alac'
+@item FFmpeg Sonic @tab X @tab X
+@tab experimental lossy/lossless codec
+@item Qdesign QDM2 @tab @tab X
+@tab there are still some distortions
+@item Real COOK @tab @tab X
+@tab All versions except 5.1 are supported
+@item DSP Group TrueSpeech @tab @tab X
+@item True Audio (TTA) @tab @tab X
+@item Smacker Audio @tab @tab X
+@item WavPack Audio @tab @tab X
+@item Cin Audio @tab @tab X
+@tab Codec used in Delphine Software games.
+@item Intel Music Coder @tab @tab X
+@item Musepack @tab @tab X
+@tab Only SV7 is supported
+@item DT$ Coherent Audio @tab @tab X
+@end multitable
+
+@code{X} means that encoding (resp. decoding) is supported.
+
+@code{I} means that an integer-only version is available, too (ensures high
+performance on systems without hardware floating point support).
+
+@chapter Platform Specific information
+
+@section BSD
+
+BSD make will not build FFmpeg, you need to install and use GNU Make
+(@file{gmake}).
+
+@section Windows
+
+To get help and instructions for using FFmpeg under Windows, check out
+the FFmpeg Windows Help Forum at
+@url{http://arrozcru.no-ip.org/ffmpeg/}.
+
+@subsection Native Windows compilation
+
+@itemize
+@item Install the current versions of MSYS and MinGW from
+@url{http://www.mingw.org/}. You can find detailed installation
+instructions in the download section and the FAQ.
+
+NOTE: Use at least bash 3.1. Older versions are known to be failing on the
+configure script.
+
+@item If you want to test the FFplay, also download
+the MinGW development library of SDL 1.2.x
+(@file{SDL-devel-1.2.x-mingw32.tar.gz}) from
+@url{http://www.libsdl.org}. Unpack it in a temporary directory, and
+unpack the archive @file{i386-mingw32msvc.tar.gz} in the MinGW tool
+directory. Edit the @file{sdl-config} script so that it gives the
+correct SDL directory when invoked.
+
+@item Extract the current version of FFmpeg.
+
+@item Start the MSYS shell (file @file{msys.bat}).
+
+@item Change to the FFmpeg directory and follow
+ the instructions of how to compile FFmpeg (file
+@file{INSTALL}). Usually, launching @file{./configure} and @file{make}
+suffices. If you have problems using SDL, verify that
+@file{sdl-config} can be launched from the MSYS command line.
+
+@item You can install FFmpeg in @file{Program Files/FFmpeg} by typing
+@file{make install}. Do not forget to copy @file{SDL.dll} to the place
+you launch @file{ffplay} from.
+
+@end itemize
+
+Notes:
+@itemize
+
+@item The target @file{make wininstaller} can be used to create a
+Nullsoft based Windows installer for FFmpeg and FFplay. @file{SDL.dll}
+must be copied to the FFmpeg directory in order to build the
+installer.
+
+@item By using @code{./configure --enable-shared} when configuring FFmpeg,
+you can build @file{avcodec.dll} and @file{avformat.dll}. With
+@code{make install} you install the FFmpeg DLLs and the associated
+headers in @file{Program Files/FFmpeg}.
+
+@item Visual C++ compatibility: If you used @code{./configure --enable-shared}
+when configuring FFmpeg, FFmpeg tries to use the Microsoft Visual
+C++ @code{lib} tool to build @code{avcodec.lib} and
+@code{avformat.lib}. With these libraries you can link your Visual C++
+code directly with the FFmpeg DLLs (see below).
+
+@end itemize
+
+@subsection Visual C++ compatibility
+
+FFmpeg will not compile under Visual C++ -- and it has too many
+dependencies on the GCC compiler to make a port viable. However,
+if you want to use the FFmpeg libraries in your own applications,
+you can still compile those applications using Visual C++. An
+important restriction to this is that you have to use the
+dynamically linked versions of the FFmpeg libraries (i.e. the
+DLLs), and you have to make sure that Visual-C++-compatible
+import libraries are created during the FFmpeg build process.
+
+This description of how to use the FFmpeg libraries with Visual C++ is
+based on Visual C++ 2005 Express Edition Beta 2. If you have a different
+version, you might have to modify the procedures slightly.
+
+Here are the step-by-step instructions for building the FFmpeg libraries
+so they can be used with Visual C++:
+
+@enumerate
+
+@item Install Visual C++ (if you have not done so already).
+
+@item Install MinGW and MSYS as described above.
+
+@item Add a call to @file{vcvars32.bat} (which sets up the environment
+variables for the Visual C++ tools) as the first line of
+@file{msys.bat}. The standard location for @file{vcvars32.bat} is
+@file{C:\Program Files\Microsoft Visual Studio 8\VC\bin\vcvars32.bat},
+and the standard location for @file{msys.bat} is
+@file{C:\msys\1.0\msys.bat}. If this corresponds to your setup, add the
+following line as the first line of @file{msys.bat}:
+
+@code{call "C:\Program Files\Microsoft Visual Studio 8\VC\bin\vcvars32.bat"}
+
+@item Start the MSYS shell (file @file{msys.bat}) and type @code{link.exe}.
+If you get a help message with the command line options of @code{link.exe},
+this means your environment variables are set up correctly, the
+Microsoft linker is on the path and will be used by FFmpeg to
+create Visual-C++-compatible import libraries.
+
+@item Extract the current version of FFmpeg and change to the FFmpeg directory.
+
+@item Type the command
+@code{./configure --enable-shared --disable-static --enable-memalign-hack}
+to configure and, if that did not produce any errors,
+type @code{make} to build FFmpeg.
+
+@item The subdirectories @file{libavformat}, @file{libavcodec}, and
+@file{libavutil} should now contain the files @file{avformat.dll},
+@file{avformat.lib}, @file{avcodec.dll}, @file{avcodec.lib},
+@file{avutil.dll}, and @file{avutil.lib}, respectively. Copy the three
+DLLs to your System32 directory (typically @file{C:\Windows\System32}).
+
+@end enumerate
+
+And here is how to use these libraries with Visual C++:
+
+@enumerate
+
+@item Create a new console application ("File / New / Project") and then
+select "Win32 Console Application". On the appropriate page of the
+Application Wizard, uncheck the "Precompiled headers" option.
+
+@item Write the source code for your application, or, for testing, just
+copy the code from an existing sample application into the source file
+that Visual C++ has already created for you. (Note that your source
+filehas to have a @code{.cpp} extension; otherwise, Visual C++ will not
+compile the FFmpeg headers correctly because in C mode, it does not
+recognize the @code{inline} keyword.) For example, you can copy
+@file{output_example.c} from the FFmpeg distribution (but you will
+have to make minor modifications so the code will compile under
+C++, see below).
+
+@item Open the "Project / Properties" dialog box. In the "Configuration"
+combo box, select "All Configurations" so that the changes you make will
+affect both debug and release builds. In the tree view on the left hand
+side, select "C/C++ / General", then edit the "Additional Include
+Directories" setting to contain the complete paths to the
+@file{libavformat}, @file{libavcodec}, and @file{libavutil}
+subdirectories of your FFmpeg directory. Note that the directories have
+to be separated using semicolons. Now select "Linker / General" from the
+tree view and edit the "Additional Library Directories" setting to
+contain the same three directories.
+
+@item Still in the "Project / Properties" dialog box, select "Linker / Input"
+from the tree view, then add the files @file{avformat.lib},
+@file{avcodec.lib}, and @file{avutil.lib} to the end of the "Additional
+Dependencies". Note that the names of the libraries have to be separated
+using spaces.
+
+@item Now, select "C/C++ / Code Generation" from the tree view. Select
+"Debug" in the "Configuration" combo box. Make sure that "Runtime
+Library" is set to "Multi-threaded Debug DLL". Then, select "Release" in
+the "Configuration" combo box and make sure that "Runtime Library" is
+set to "Multi-threaded DLL".
+
+@item Click "OK" to close the "Project / Properties" dialog box and build
+the application. Hopefully, it should compile and run cleanly. If you
+used @file{output_example.c} as your sample application, you will get a
+few compiler errors, but they are easy to fix. The first type of error
+occurs because Visual C++ does not allow an @code{int} to be converted to
+an @code{enum} without a cast. To solve the problem, insert the required
+casts (this error occurs once for a @code{CodecID} and once for a
+@code{CodecType}). The second type of error occurs because C++ requires
+the return value of @code{malloc} to be cast to the exact type of the
+pointer it is being assigned to. Visual C++ will complain that, for
+example, @code{(void *)} is being assigned to @code{(uint8_t *)} without
+an explicit cast. So insert an explicit cast in these places to silence
+the compiler. The third type of error occurs because the @code{snprintf}
+library function is called @code{_snprintf} under Visual C++. So just
+add an underscore to fix the problem. With these changes,
+@file{output_example.c} should compile under Visual C++, and the
+resulting executable should produce valid video files.
+
+@end enumerate
+
+@subsection Cross compilation for Windows with Linux
+
+You must use the MinGW cross compilation tools available at
+@url{http://www.mingw.org/}.
+
+Then configure FFmpeg with the following options:
+@example
+./configure --target-os=mingw32 --cross-prefix=i386-mingw32msvc-
+@end example
+(you can change the cross-prefix according to the prefix chosen for the
+MinGW tools).
+
+Then you can easily test FFmpeg with Wine
+(@url{http://www.winehq.com/}).
+
+@subsection Compilation under Cygwin
+
+Cygwin works very much like Unix.
+
+Just install your Cygwin with all the "Base" packages, plus the
+following "Devel" ones:
+@example
+binutils, gcc-core, make, subversion
+@end example
+
+Do not install binutils-20060709-1 (they are buggy on shared builds);
+use binutils-20050610-1 instead.
+
+Then run
+
+@example
+./configure --enable-static --disable-shared
+@end example
+
+to make a static build or
+
+@example
+./configure --enable-shared --disable-static
+@end example
+
+to build shared libraries.
+
+If you want to build FFmpeg with additional libraries, download Cygwin
+"Devel" packages for Ogg and Vorbis from any Cygwin packages repository
+and/or SDL, xvid, faac, faad2 packages from Cygwin Ports,
+(@url{http://cygwinports.dotsrc.org/}).
+
+@subsection Crosscompilation for Windows under Cygwin
+
+With Cygwin you can create Windows binaries that do not need the cygwin1.dll.
+
+Just install your Cygwin as explained before, plus these additional
+"Devel" packages:
+@example
+gcc-mingw-core, mingw-runtime, mingw-zlib
+@end example
+
+and add some special flags to your configure invocation.
+
+For a static build run
+@example
+./configure --target-os=mingw32 --enable-memalign-hack --enable-static --disable-shared --extra-cflags=-mno-cygwin --extra-libs=-mno-cygwin
+@end example
+
+and for a build with shared libraries
+@example
+./configure --target-os=mingw32 --enable-memalign-hack --enable-shared --disable-static --extra-cflags=-mno-cygwin --extra-libs=-mno-cygwin
+@end example
+
+@section BeOS
+
+The configure script should guess the configuration itself.
+Networking support is currently not finished.
+errno issues fixed by Andrew Bachmann.
+
+Old stuff:
+
+François Revol - revol at free dot fr - April 2002
+
+The configure script should guess the configuration itself,
+however I still did not test building on the net_server version of BeOS.
+
+FFserver is broken (needs poll() implementation).
+
+There are still issues with errno codes, which are negative in BeOS, and
+that FFmpeg negates when returning. This ends up turning errors into
+valid results, then crashes.
+(To be fixed)
+
+@chapter Developers Guide
+
+@section API
+@itemize @bullet
+@item libavcodec is the library containing the codecs (both encoding and
+decoding). Look at @file{libavcodec/apiexample.c} to see how to use it.
+
+@item libavformat is the library containing the file format handling (mux and
+demux code for several formats). Look at @file{ffplay.c} to use it in a
+player. See @file{output_example.c} to use it to generate audio or video
+streams.
+
+@end itemize
+
+@section Integrating libavcodec or libavformat in your program
+
+You can integrate all the source code of the libraries to link them
+statically to avoid any version problem. All you need is to provide a
+'config.mak' and a 'config.h' in the parent directory. See the defines
+generated by ./configure to understand what is needed.
+
+You can use libavcodec or libavformat in your commercial program, but
+@emph{any patch you make must be published}. The best way to proceed is
+to send your patches to the FFmpeg mailing list.
+
+@node Coding Rules
+@section Coding Rules
+
+FFmpeg is programmed in the ISO C90 language with a few additional
+features from ISO C99, namely:
+@itemize @bullet
+@item
+the @samp{inline} keyword;
+@item
+@samp{//} comments;
+@item
+designated struct initializers (@samp{struct s x = @{ .i = 17 @};})
+@item
+compound literals (@samp{x = (struct s) @{ 17, 23 @};})
+@end itemize
+
+These features are supported by all compilers we care about, so we will not
+accept patches to remove their use unless they absolutely do not impair
+clarity and performance.
+
+All code must compile with GCC 2.95 and GCC 3.3. Currently, FFmpeg also
+compiles with several other compilers, such as the Compaq ccc compiler
+or Sun Studio 9, and we would like to keep it that way unless it would
+be exceedingly involved. To ensure compatibility, please do not use any
+additional C99 features or GCC extensions. Especially watch out for:
+@itemize @bullet
+@item
+mixing statements and declarations;
+@item
+@samp{long long} (use @samp{int64_t} instead);
+@item
+@samp{__attribute__} not protected by @samp{#ifdef __GNUC__} or similar;
+@item
+GCC statement expressions (@samp{(x = (@{ int y = 4; y; @})}).
+@end itemize
+
+Indent size is 4.
+The presentation is the one specified by 'indent -i4 -kr -nut'.
+The TAB character is forbidden outside of Makefiles as is any
+form of trailing whitespace. Commits containing either will be
+rejected by the Subversion repository.
+
+Main priority in FFmpeg is simplicity and small code size (=less
+bugs).
+
+Comments: Use the JavaDoc/Doxygen
+format (see examples below) so that code documentation
+can be generated automatically. All nontrivial functions should have a comment
+above them explaining what the function does, even if it is just one sentence.
+All structures and their member variables should be documented, too.
+@example
+/**
+ * @@file mpeg.c
+ * MPEG codec.
+ * @@author ...
+ */
+
+/**
+ * Summary sentence.
+ * more text ...
+ * ...
+ */
+typedef struct Foobar@{
+ int var1; /**< var1 description */
+ int var2; ///< var2 description
+ /** var3 description */
+ int var3;
+@} Foobar;
+
+/**
+ * Summary sentence.
+ * more text ...
+ * ...
+ * @@param my_parameter description of my_parameter
+ * @@return return value description
+ */
+int myfunc(int my_parameter)
+...
+@end example
+
+fprintf and printf are forbidden in libavformat and libavcodec,
+please use av_log() instead.
+
+@section Development Policy
+
+@enumerate
+@item
+ You must not commit code which breaks FFmpeg! (Meaning unfinished but
+ enabled code which breaks compilation or compiles but does not work or
+ breaks the regression tests)
+ You can commit unfinished stuff (for testing etc), but it must be disabled
+ (#ifdef etc) by default so it does not interfere with other developers'
+ work.
+@item
+ You do not have to over-test things. If it works for you, and you think it
+ should work for others, then commit. If your code has problems
+ (portability, triggers compiler bugs, unusual environment etc) they will be
+ reported and eventually fixed.
+@item
+ Do not commit unrelated changes together, split them into self-contained
+ pieces. Also do not forget that if part B depends on part A, but A does not
+ depend on B, then A can and should be committed first and separate from B.
+ Keeping changes well split into self-contained parts makes reviewing and
+ understanding them on the commit log mailing list easier. This also helps
+ in case of debugging later on.
+ Also if you have doubts about splitting or not splitting, do not hesitate to
+ ask/disscuss it on the developer mailing list.
+@item
+ Do not change behavior of the program (renaming options etc) without
+ first discussing it on the ffmpeg-devel mailing list. Do not remove
+ functionality from the code. Just improve!
+
+ Note: Redundant code can be removed.
+@item
+ Do not commit changes to the build system (Makefiles, configure script)
+ which change behavior, defaults etc, without asking first. The same
+ applies to compiler warning fixes, trivial looking fixes and to code
+ maintained by other developers. We usually have a reason for doing things
+ the way we do. Send your changes as patches to the ffmpeg-devel mailing
+ list, and if the code maintainers say OK, you may commit. This does not
+ apply to files you wrote and/or maintain.
+@item
+ We refuse source indentation and other cosmetic changes if they are mixed
+ with functional changes, such commits will be rejected and removed. Every
+ developer has his own indentation style, you should not change it. Of course
+ if you (re)write something, you can use your own style, even though we would
+ prefer if the indentation throughout FFmpeg was consistent (Many projects
+ force a given indentation style - we do not.). If you really need to make
+ indentation changes (try to avoid this), separate them strictly from real
+ changes.
+
+ NOTE: If you had to put if()@{ .. @} over a large (> 5 lines) chunk of code,
+ then either do NOT change the indentation of the inner part within (do not
+ move it to the right)! or do so in a separate commit
+@item
+ Always fill out the commit log message. Describe in a few lines what you
+ changed and why. You can refer to mailing list postings if you fix a
+ particular bug. Comments such as "fixed!" or "Changed it." are unacceptable.
+@item
+ If you apply a patch by someone else, include the name and email address in
+ the log message. Since the ffmpeg-cvslog mailing list is publicly
+ archived you should add some SPAM protection to the email address. Send an
+ answer to ffmpeg-devel (or wherever you got the patch from) saying that
+ you applied the patch.
+@item
+ Do NOT commit to code actively maintained by others without permission.
+ Send a patch to ffmpeg-devel instead. If noone answers within a reasonable
+ timeframe (12h for build failures and security fixes, 3 days small changes,
+ 1 week for big patches) then commit your patch if you think it is OK.
+ Also note, the maintainer can simply ask for more time to review!
+@item
+ Subscribe to the ffmpeg-cvslog mailing list. The diffs of all commits
+ are sent there and reviewed by all the other developers. Bugs and possible
+ improvements or general questions regarding commits are discussed there. We
+ expect you to react if problems with your code are uncovered.
+@item
+ Update the documentation if you change behavior or add features. If you are
+ unsure how best to do this, send a patch to ffmpeg-devel, the documentation
+ maintainer(s) will review and commit your stuff.
+@item
+ Try to keep important discussions and requests (also) on the public
+ developer mailing list, so that all developers can benefit from them.
+@item
+ Never write to unallocated memory, never write over the end of arrays,
+ always check values read from some untrusted source before using them
+ as array index or other risky things.
+@item
+ Remember to check if you need to bump versions for the specific libav
+ parts (libavutil, libavcodec, libavformat) you are changing. You need
+ to change the version integer and the version string.
+ Incrementing the first component means no backward compatibility to
+ previous versions (e.g. removal of a function from the public API).
+ Incrementing the second component means backward compatible change
+ (e.g. addition of a function to the public API).
+ Incrementing the third component means a noteworthy binary compatible
+ change (e.g. encoder bug fix that matters for the decoder).
+@item
+ If you add a new codec, remember to update the changelog, add it to
+ the supported codecs table in the documentation and bump the second
+ component of the @file{libavcodec} version number appropriately. If
+ it has a fourcc, add it to @file{libavformat/avienc.c}, even if it
+ is only a decoder.
+@item
+ Do not change code to hide warnings without ensuring that the underlying
+ logic is correct and thus the warning was inappropriate.
+@end enumerate
+
+We think our rules are not too hard. If you have comments, contact us.
+
+Note, these rules are mostly borrowed from the MPlayer project.
+
+@section Submitting patches
+
+First, (@pxref{Coding Rules}) above if you did not yet.
+
+When you submit your patch, try to send a unified diff (diff '-up'
+option). I cannot read other diffs :-)
+
+Also please do not submit patches which contain several unrelated changes.
+Split them into individual self-contained patches; this makes reviewing
+them much easier.
+
+Run the regression tests before submitting a patch so that you can
+verify that there are no big problems.
+
+Patches should be posted as base64 encoded attachments (or any other
+encoding which ensures that the patch will not be trashed during
+transmission) to the ffmpeg-devel mailing list, see
+@url{http://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel}
+
+It also helps quite a bit if you tell us what the patch does (for example
+'replaces lrint by lrintf'), and why (for example '*BSD isn't C99 compliant
+and has no lrint()')
+
+@section Patch review process
+
+All patches posted to ffmpeg-devel will be reviewed, unless they contain a
+clear note that the patch is not for SVN.
+Reviews and comments will be posted as replies to the patch on the
+mailing list. The patch submitter then has to take care of every comment,
+that can be by resubmitting a changed patch or by disscussion. Resubmitted
+patches will themselves be reviewed like any other patch. If at some point
+a patch passes review with no comments then it is approved, that can for
+simple and small patches happen immediately while large patches will generally
+have to be changed and reviewed many times before they are approved.
+After a patch is approved it will be committed to the repository.
+
+We will review all submitted patches, but sometimes we are quite busy so
+especially for large patches this can take several weeks.
+
+When resubmitting patches, please do not make any significant changes
+not related to the comments received during review. Such patches will
+be rejected. Instead, submit significant changes or new features as
+separate patches.
+
+@section Regression tests
+
+Before submitting a patch (or committing to the repository), you should at least
+test that you did not break anything.
+
+The regression tests build a synthetic video stream and a synthetic
+audio stream. These are then encoded and decoded with all codecs or
+formats. The CRC (or MD5) of each generated file is recorded in a
+result file. A 'diff' is launched to compare the reference results and
+the result file.
+
+The regression tests then go on to test the FFserver code with a
+limited set of streams. It is important that this step runs correctly
+as well.
+
+Run 'make test' to test all the codecs and formats.
+
+Run 'make fulltest' to test all the codecs, formats and FFserver.
+
+[Of course, some patches may change the results of the regression tests. In
+this case, the reference results of the regression tests shall be modified
+accordingly].
+
+@bye
diff --git a/contrib/ffmpeg/doc/ffmpeg_powerpc_performance_evaluation_howto.txt b/contrib/ffmpeg/doc/ffmpeg_powerpc_performance_evaluation_howto.txt
new file mode 100644
index 000000000..2eb4ee71a
--- /dev/null
+++ b/contrib/ffmpeg/doc/ffmpeg_powerpc_performance_evaluation_howto.txt
@@ -0,0 +1,172 @@
+FFmpeg & evaluating performance on the PowerPC Architecture HOWTO
+
+(c) 2003-2004 Romain Dolbeau <romain@dolbeau.org>
+
+
+
+I - Introduction
+
+The PowerPC architecture and its SIMD extension AltiVec offer some
+interesting tools to evaluate performance and improve the code.
+This document tries to explain how to use those tools with FFmpeg.
+
+The architecture itself offers two ways to evaluate the performance of
+a given piece of code:
+
+1) The Time Base Registers (TBL)
+2) The Performance Monitor Counter Registers (PMC)
+
+The first ones are always available, always active, but they're not very
+accurate: the registers increment by one every four *bus* cycles. On
+my 667 Mhz tiBook (ppc7450), this means once every twenty *processor*
+cycles. So we won't use that.
+
+The PMC are much more useful: not only can they report cycle-accurate
+timing, but they can also be used to monitor many other parameters,
+such as the number of AltiVec stalls for every kind of instruction,
+or instruction cache misses. The downside is that not all processors
+support the PMC (all G3, all G4 and the 970 do support them), and
+they're inactive by default - you need to activate them with a
+dedicated tool. Also, the number of available PMC depends on the
+procesor: the various 604 have 2, the various 75x (aka. G3) have 4,
+and the various 74xx (aka G4) have 6.
+
+*WARNING*: The PowerPC 970 is not very well documented, and its PMC
+registers are 64 bits wide. To properly notify the code, you *must*
+tune for the 970 (using --tune=970), or the code will assume 32 bit
+registers.
+
+
+II - Enabling FFmpeg PowerPC performance support
+
+This needs to be done by hand. First, you need to configure FFmpeg as
+usual, but add the "--powerpc-perf-enable" option. For instance:
+
+#####
+./configure --prefix=/usr/local/ffmpeg-svn --cc=gcc-3.3 --tune=7450 --powerpc-perf-enable
+#####
+
+This will configure FFmpeg to install inside /usr/local/ffmpeg-svn,
+compiling with gcc-3.3 (you should try to use this one or a newer
+gcc), and tuning for the PowerPC 7450 (i.e. the newer G4; as a rule of
+thumb, those at 550Mhz and more). It will also enable the PMC.
+
+You may also edit the file "config.h" to enable the following line:
+
+#####
+// #define ALTIVEC_USE_REFERENCE_C_CODE 1
+#####
+
+If you enable this line, then the code will not make use of AltiVec,
+but will use the reference C code instead. This is useful to compare
+performance between two versions of the code.
+
+Also, the number of enabled PMC is defined in "libavcodec/ppc/dsputil_ppc.h":
+
+#####
+#define POWERPC_NUM_PMC_ENABLED 4
+#####
+
+If you have a G4 CPU, you can enable all 6 PMC. DO NOT enable more
+PMC than available on your CPU!
+
+Then, simply compile FFmpeg as usual (make && make install).
+
+
+
+III - Using FFmpeg PowerPC performance support
+
+This FFmeg can be used exactly as usual. But before exiting, FFmpeg
+will dump a per-function report that looks like this:
+
+#####
+PowerPC performance report
+ Values are from the PMC registers, and represent whatever the
+ registers are set to record.
+ Function "gmc1_altivec" (pmc1):
+ min: 231
+ max: 1339867
+ avg: 558.25 (255302)
+ Function "gmc1_altivec" (pmc2):
+ min: 93
+ max: 2164
+ avg: 267.31 (255302)
+ Function "gmc1_altivec" (pmc3):
+ min: 72
+ max: 1987
+ avg: 276.20 (255302)
+(...)
+#####
+
+In this example, PMC1 was set to record CPU cycles, PMC2 was set to
+record AltiVec Permute Stall Cycles, and PMC3 was set to record AltiVec
+Issue Stalls.
+
+The function "gmc1_altivec" was monitored 255302 times, and the
+minimum execution time was 231 processor cycles. The max and average
+aren't much use, as it's very likely the OS interrupted execution for
+reasons of its own :-(
+
+With the exact same settings and source file, but using the reference C
+code we get:
+
+#####
+PowerPC performance report
+ Values are from the PMC registers, and represent whatever the
+ registers are set to record.
+ Function "gmc1_altivec" (pmc1):
+ min: 592
+ max: 2532235
+ avg: 962.88 (255302)
+ Function "gmc1_altivec" (pmc2):
+ min: 0
+ max: 33
+ avg: 0.00 (255302)
+ Function "gmc1_altivec" (pmc3):
+ min: 0
+ max: 350
+ avg: 0.03 (255302)
+(...)
+#####
+
+592 cycles, so the fastest AltiVec execution is about 2.5x faster than
+the fastest C execution in this example. It's not perfect but it's not
+bad (well I wrote this function so I can't say otherwise :-).
+
+Once you have that kind of report, you can try to improve things by
+finding what goes wrong and fixing it; in the example above, one
+should try to diminish the number of AltiVec stalls, as this *may*
+improve performance.
+
+
+
+IV) Enabling the PMC in Mac OS X
+
+This is easy. Use "Monster" and "monster". Those tools come from
+Apple's CHUD package, and can be found hidden in the developer web
+site & FTP site. "MONster" is the graphical application, use it to
+generate a config file specifying what each register should
+monitor. Then use the command-line application "monster" to use that
+config file, and enjoy the results.
+
+Note that "MONster" can be used for many other things, but it's
+documented by Apple, it's not my subject.
+
+If you are using CHUD 4.4.2 or later, you'll notice that MONster is
+no longer available. It's been superseeded by Shark, where
+configuration of PMCs is available as a plugin.
+
+
+
+V) Enabling the PMC on Linux
+
+On linux you may use oprofile from http://oprofile.sf.net, depending on the
+version and the cpu you may need to apply a patch[1] to access a set of the
+possibile counters from the userspace application. You can always define them
+using the kernel interface /dev/oprofile/* .
+
+[1] http://dev.gentoo.org/~lu_zero/development/oprofile-g4-20060423.patch
+
+--
+Romain Dolbeau <romain@dolbeau.org>
+Luca Barbato <lu_zero@gentoo.org>
diff --git a/contrib/ffmpeg/doc/ffplay-doc.texi b/contrib/ffmpeg/doc/ffplay-doc.texi
new file mode 100644
index 000000000..1ac315662
--- /dev/null
+++ b/contrib/ffmpeg/doc/ffplay-doc.texi
@@ -0,0 +1,135 @@
+\input texinfo @c -*- texinfo -*-
+
+@settitle FFplay Documentation
+@titlepage
+@sp 7
+@center @titlefont{FFplay Documentation}
+@sp 3
+@end titlepage
+
+
+@chapter Introduction
+
+@c man begin DESCRIPTION
+FFplay is a very simple and portable media player using the FFmpeg
+libraries and the SDL library. It is mostly used as a testbed for the
+various FFmpeg APIs.
+@c man end
+
+@chapter Invocation
+
+@section Syntax
+@example
+@c man begin SYNOPSIS
+ffplay [options] @file{input_file}
+@c man end
+@end example
+
+@c man begin OPTIONS
+@section Main options
+
+@table @option
+@item -h
+show help
+@item -x width
+force displayed width
+@item -y height
+force displayed height
+@item -s size
+Set frame size (WxH or abbreviation), needed for videos which don't
+contain a header with the framesize like raw YUV.
+@item -an
+disable audio
+@item -vn
+disable video
+@item -ss pos
+seek to a given position in seconds
+@item -bytes
+seek by bytes
+@item -nodisp
+disable graphical display
+@item -f fmt
+force format
+@end table
+
+@section Advanced options
+@table @option
+@item -pix_fmt format
+set pixel format
+@item -stats
+Show the stream duration, the codec parameters, the current position in
+the stream and the audio/video synchronisation drift.
+@item -debug
+print specific debug info
+@item -bug
+work around bugs
+@item -vismv
+visualize motion vectors
+@item -fast
+non-spec-compliant optimizations
+@item -genpts
+generate pts
+@item -rtp_tcp
+Force RTP/TCP protocol usage instead of RTP/UDP. It is only meaningful
+if you are streaming with the RTSP protocol.
+@item -sync type
+Set the master clock to audio (@code{type=audio}), video
+(@code{type=video}) or external (@code{type=ext}). Default is audio. The
+master clock is used to control audio-video synchronization. Most media
+players use audio as master clock, but in some cases (streaming or high
+quality broadcast) it is necessary to change that. This option is mainly
+used for debugging purposes.
+@item -threads count
+thread count
+@end table
+
+@section While playing
+
+@table @key
+@item q, ESC
+quit
+
+@item f
+toggle full screen
+
+@item p, SPC
+pause
+
+@item a
+cycle audio channel
+
+@item v
+cycle video channel
+
+@item w
+show audio waves
+
+@item left/right
+seek backward/forward 10 seconds
+
+@item down/up
+seek backward/forward 1 minute
+
+@item mouse click
+seek to percentage in file corresponding to fraction of width
+
+@end table
+
+@c man end
+
+@ignore
+
+@setfilename ffplay
+@settitle FFplay media player
+
+@c man begin SEEALSO
+ffmpeg(1), ffserver(1) and the html documentation of @file{ffmpeg}.
+@c man end
+
+@c man begin AUTHOR
+Fabrice Bellard
+@c man end
+
+@end ignore
+
+@bye
diff --git a/contrib/ffmpeg/doc/ffserver-doc.texi b/contrib/ffmpeg/doc/ffserver-doc.texi
new file mode 100644
index 000000000..ed67bb6c0
--- /dev/null
+++ b/contrib/ffmpeg/doc/ffserver-doc.texi
@@ -0,0 +1,224 @@
+\input texinfo @c -*- texinfo -*-
+
+@settitle FFserver Documentation
+@titlepage
+@sp 7
+@center @titlefont{FFserver Documentation}
+@sp 3
+@end titlepage
+
+
+@chapter Introduction
+
+@c man begin DESCRIPTION
+FFserver is a streaming server for both audio and video. It supports
+several live feeds, streaming from files and time shifting on live feeds
+(you can seek to positions in the past on each live feed, provided you
+specify a big enough feed storage in ffserver.conf).
+
+This documentation covers only the streaming aspects of ffserver /
+ffmpeg. All questions about parameters for ffmpeg, codec questions,
+etc. are not covered here. Read @file{ffmpeg-doc.html} for more
+information.
+@c man end
+
+@chapter QuickStart
+
+[Contributed by Philip Gladstone, philip-ffserver at gladstonefamily dot net]
+
+@section What can this do?
+
+When properly configured and running, you can capture video and audio in real
+time from a suitable capture card, and stream it out over the Internet to
+either Windows Media Player or RealAudio player (with some restrictions).
+
+It can also stream from files, though that is currently broken. Very often, a
+web server can be used to serve up the files just as well.
+
+It can stream prerecorded video from .ffm files, though it is somewhat tricky
+to make it work correctly.
+
+@section What do I need?
+
+I use Linux on a 900MHz Duron with a cheapo Bt848 based TV capture card. I'm
+using stock Linux 2.4.17 with the stock drivers. [Actually that isn't true,
+I needed some special drivers for my motherboard-based sound card.]
+
+I understand that FreeBSD systems work just fine as well.
+
+@section How do I make it work?
+
+First, build the kit. It *really* helps to have installed LAME first. Then when
+you run the ffserver ./configure, make sure that you have the --enable-mp3lame
+flag turned on.
+
+LAME is important as it allows for streaming audio to Windows Media Player.
+Don't ask why the other audio types do not work.
+
+As a simple test, just run the following two command lines (assuming that you
+have a V4L video capture card):
+
+@example
+./ffserver -f doc/ffserver.conf &
+./ffmpeg http://localhost:8090/feed1.ffm
+@end example
+
+At this point you should be able to go to your Windows machine and fire up
+Windows Media Player (WMP). Go to Open URL and enter
+
+@example
+ http://<linuxbox>:8090/test.asf
+@end example
+
+You should (after a short delay) see video and hear audio.
+
+WARNING: trying to stream test1.mpg doesn't work with WMP as it tries to
+transfer the entire file before starting to play.
+The same is true of AVI files.
+
+@section What happens next?
+
+You should edit the ffserver.conf file to suit your needs (in terms of
+frame rates etc). Then install ffserver and ffmpeg, write a script to start
+them up, and off you go.
+
+@section Troubleshooting
+
+@subsection I don't hear any audio, but video is fine.
+
+Maybe you didn't install LAME, or got your ./configure statement wrong. Check
+the ffmpeg output to see if a line referring to MP3 is present. If not, then
+your configuration was incorrect. If it is, then maybe your wiring is not
+set up correctly. Maybe the sound card is not getting data from the right
+input source. Maybe you have a really awful audio interface (like I do)
+that only captures in stereo and also requires that one channel be flipped.
+If you are one of these people, then export 'AUDIO_FLIP_LEFT=1' before
+starting ffmpeg.
+
+@subsection The audio and video loose sync after a while.
+
+Yes, they do.
+
+@subsection After a long while, the video update rate goes way down in WMP.
+
+Yes, it does. Who knows why?
+
+@subsection WMP 6.4 behaves differently to WMP 7.
+
+Yes, it does. Any thoughts on this would be gratefully received. These
+differences extend to embedding WMP into a web page. [There are two
+object IDs that you can use: The old one, which does not play well, and
+the new one, which does (both tested on the same system). However,
+I suspect that the new one is not available unless you have installed WMP 7].
+
+@section What else can it do?
+
+You can replay video from .ffm files that was recorded earlier.
+However, there are a number of caveats, including the fact that the
+ffserver parameters must match the original parameters used to record the
+file. If they do not, then ffserver deletes the file before recording into it.
+(Now that I write this, it seems broken).
+
+You can fiddle with many of the codec choices and encoding parameters, and
+there are a bunch more parameters that you cannot control. Post a message
+to the mailing list if there are some 'must have' parameters. Look in
+ffserver.conf for a list of the currently available controls.
+
+It will automatically generate the ASX or RAM files that are often used
+in browsers. These files are actually redirections to the underlying ASF
+or RM file. The reason for this is that the browser often fetches the
+entire file before starting up the external viewer. The redirection files
+are very small and can be transferred quickly. [The stream itself is
+often 'infinite' and thus the browser tries to download it and never
+finishes.]
+
+@section Tips
+
+* When you connect to a live stream, most players (WMP, RA, etc) want to
+buffer a certain number of seconds of material so that they can display the
+signal continuously. However, ffserver (by default) starts sending data
+in realtime. This means that there is a pause of a few seconds while the
+buffering is being done by the player. The good news is that this can be
+cured by adding a '?buffer=5' to the end of the URL. This means that the
+stream should start 5 seconds in the past -- and so the first 5 seconds
+of the stream are sent as fast as the network will allow. It will then
+slow down to real time. This noticeably improves the startup experience.
+
+You can also add a 'Preroll 15' statement into the ffserver.conf that will
+add the 15 second prebuffering on all requests that do not otherwise
+specify a time. In addition, ffserver will skip frames until a key_frame
+is found. This further reduces the startup delay by not transferring data
+that will be discarded.
+
+* You may want to adjust the MaxBandwidth in the ffserver.conf to limit
+the amount of bandwidth consumed by live streams.
+
+@section Why does the ?buffer / Preroll stop working after a time?
+
+It turns out that (on my machine at least) the number of frames successfully
+grabbed is marginally less than the number that ought to be grabbed. This
+means that the timestamp in the encoded data stream gets behind realtime.
+This means that if you say 'Preroll 10', then when the stream gets 10
+or more seconds behind, there is no Preroll left.
+
+Fixing this requires a change in the internals of how timestamps are
+handled.
+
+@section Does the @code{?date=} stuff work.
+
+Yes (subject to the limitation outlined above). Also note that whenever you
+start ffserver, it deletes the ffm file (if any parameters have changed),
+thus wiping out what you had recorded before.
+
+The format of the @code{?date=xxxxxx} is fairly flexible. You should use one
+of the following formats (the 'T' is literal):
+
+@example
+* YYYY-MM-DDTHH:MM:SS (localtime)
+* YYYY-MM-DDTHH:MM:SSZ (UTC)
+@end example
+
+You can omit the YYYY-MM-DD, and then it refers to the current day. However
+note that @samp{?date=16:00:00} refers to 16:00 on the current day -- this
+may be in the future and so is unlikely to be useful.
+
+You use this by adding the ?date= to the end of the URL for the stream.
+For example: @samp{http://localhost:8080/test.asf?date=2002-07-26T23:05:00}.
+
+@chapter Invocation
+@section Syntax
+@example
+@c man begin SYNOPSIS
+ffserver [options]
+@c man end
+@end example
+
+@section Options
+@c man begin OPTIONS
+@table @option
+@item -L
+Print the license.
+@item -h
+Print the help.
+@item -f configfile
+Use @file{configfile} instead of @file{/etc/ffserver.conf}.
+@end table
+@c man end
+
+@ignore
+
+@setfilename ffsserver
+@settitle FFserver video server
+
+@c man begin SEEALSO
+ffmpeg(1), ffplay(1), the @file{ffmpeg/doc/ffserver.conf} example and
+the HTML documentation of @file{ffmpeg}.
+@c man end
+
+@c man begin AUTHOR
+Fabrice Bellard
+@c man end
+
+@end ignore
+
+@bye
diff --git a/contrib/ffmpeg/doc/ffserver.conf b/contrib/ffmpeg/doc/ffserver.conf
new file mode 100644
index 000000000..a3b3ff412
--- /dev/null
+++ b/contrib/ffmpeg/doc/ffserver.conf
@@ -0,0 +1,349 @@
+# Port on which the server is listening. You must select a different
+# port from your standard HTTP web server if it is running on the same
+# computer.
+Port 8090
+
+# Address on which the server is bound. Only useful if you have
+# several network interfaces.
+BindAddress 0.0.0.0
+
+# Number of simultaneous requests that can be handled. Since FFServer
+# is very fast, it is more likely that you will want to leave this high
+# and use MaxBandwidth, below.
+MaxClients 1000
+
+# This the maximum amount of kbit/sec that you are prepared to
+# consume when streaming to clients.
+MaxBandwidth 1000
+
+# Access log file (uses standard Apache log file format)
+# '-' is the standard output.
+CustomLog -
+
+# Suppress that if you want to launch ffserver as a daemon.
+NoDaemon
+
+
+##################################################################
+# Definition of the live feeds. Each live feed contains one video
+# and/or audio sequence coming from an ffmpeg encoder or another
+# ffserver. This sequence may be encoded simultaneously with several
+# codecs at several resolutions.
+
+<Feed feed1.ffm>
+
+# You must use 'ffmpeg' to send a live feed to ffserver. In this
+# example, you can type:
+#
+# ffmpeg http://localhost:8090/feed1.ffm
+
+# ffserver can also do time shifting. It means that it can stream any
+# previously recorded live stream. The request should contain:
+# "http://xxxx?date=[YYYY-MM-DDT][[HH:]MM:]SS[.m...]".You must specify
+# a path where the feed is stored on disk. You also specify the
+# maximum size of the feed, where zero means unlimited. Default:
+# File=/tmp/feed_name.ffm FileMaxSize=5M
+File /tmp/feed1.ffm
+FileMaxSize 200K
+
+# You could specify
+# ReadOnlyFile /saved/specialvideo.ffm
+# This marks the file as readonly and it will not be deleted or updated.
+
+# Specify launch in order to start ffmpeg automatically.
+# First ffmpeg must be defined with an appropriate path if needed,
+# after that options can follow, but avoid adding the http:// field
+#Launch ffmpeg
+
+# Only allow connections from localhost to the feed.
+ACL allow 127.0.0.1
+
+</Feed>
+
+
+##################################################################
+# Now you can define each stream which will be generated from the
+# original audio and video stream. Each format has a filename (here
+# 'test1.mpg'). FFServer will send this stream when answering a
+# request containing this filename.
+
+<Stream test1.mpg>
+
+# coming from live feed 'feed1'
+Feed feed1.ffm
+
+# Format of the stream : you can choose among:
+# mpeg : MPEG-1 multiplexed video and audio
+# mpegvideo : only MPEG-1 video
+# mp2 : MPEG-2 audio (use AudioCodec to select layer 2 and 3 codec)
+# ogg : Ogg format (Vorbis audio codec)
+# rm : RealNetworks-compatible stream. Multiplexed audio and video.
+# ra : RealNetworks-compatible stream. Audio only.
+# mpjpeg : Multipart JPEG (works with Netscape without any plugin)
+# jpeg : Generate a single JPEG image.
+# asf : ASF compatible streaming (Windows Media Player format).
+# swf : Macromedia Flash compatible stream
+# avi : AVI format (MPEG-4 video, MPEG audio sound)
+# master : special ffmpeg stream used to duplicate a server
+Format mpeg
+
+# Bitrate for the audio stream. Codecs usually support only a few
+# different bitrates.
+AudioBitRate 32
+
+# Number of audio channels: 1 = mono, 2 = stereo
+AudioChannels 1
+
+# Sampling frequency for audio. When using low bitrates, you should
+# lower this frequency to 22050 or 11025. The supported frequencies
+# depend on the selected audio codec.
+AudioSampleRate 44100
+
+# Bitrate for the video stream
+VideoBitRate 64
+
+# Ratecontrol buffer size
+VideoBufferSize 40
+
+# Number of frames per second
+VideoFrameRate 3
+
+# Size of the video frame: WxH (default: 160x128)
+# The following abbreviations are defined: sqcif, qcif, cif, 4cif
+VideoSize 160x128
+
+# Transmit only intra frames (useful for low bitrates, but kills frame rate).
+#VideoIntraOnly
+
+# If non-intra only, an intra frame is transmitted every VideoGopSize
+# frames. Video synchronization can only begin at an intra frame.
+VideoGopSize 12
+
+# More MPEG-4 parameters
+# VideoHighQuality
+# Video4MotionVector
+
+# Choose your codecs:
+#AudioCodec mp2
+#VideoCodec mpeg1video
+
+# Suppress audio
+#NoAudio
+
+# Suppress video
+#NoVideo
+
+#VideoQMin 3
+#VideoQMax 31
+
+# Set this to the number of seconds backwards in time to start. Note that
+# most players will buffer 5-10 seconds of video, and also you need to allow
+# for a keyframe to appear in the data stream.
+#Preroll 15
+
+# ACL:
+
+# You can allow ranges of addresses (or single addresses)
+#ACL ALLOW <first address> <last address>
+
+# You can deny ranges of addresses (or single addresses)
+#ACL DENY <first address> <last address>
+
+# You can repeat the ACL allow/deny as often as you like. It is on a per
+# stream basis. The first match defines the action. If there are no matches,
+# then the default is the inverse of the last ACL statement.
+#
+# Thus 'ACL allow localhost' only allows access from localhost.
+# 'ACL deny 1.0.0.0 1.255.255.255' would deny the whole of network 1 and
+# allow everybody else.
+
+</Stream>
+
+
+##################################################################
+# Example streams
+
+
+# Multipart JPEG
+
+#<Stream test.mjpg>
+#Feed feed1.ffm
+#Format mpjpeg
+#VideoFrameRate 2
+#VideoIntraOnly
+#NoAudio
+#Strict -1
+#</Stream>
+
+
+# Single JPEG
+
+#<Stream test.jpg>
+#Feed feed1.ffm
+#Format jpeg
+#VideoFrameRate 2
+#VideoIntraOnly
+##VideoSize 352x240
+#NoAudio
+#Strict -1
+#</Stream>
+
+
+# Flash
+
+#<Stream test.swf>
+#Feed feed1.ffm
+#Format swf
+#VideoFrameRate 2
+#VideoIntraOnly
+#NoAudio
+#</Stream>
+
+
+# ASF compatible
+
+<Stream test.asf>
+Feed feed1.ffm
+Format asf
+VideoFrameRate 15
+VideoSize 352x240
+VideoBitRate 256
+VideoBufferSize 40
+VideoGopSize 30
+AudioBitRate 64
+StartSendOnKey
+</Stream>
+
+
+# MP3 audio
+
+#<Stream test.mp3>
+#Feed feed1.ffm
+#Format mp2
+#AudioCodec mp3
+#AudioBitRate 64
+#AudioChannels 1
+#AudioSampleRate 44100
+#NoVideo
+#</Stream>
+
+
+# Ogg Vorbis audio
+
+#<Stream test.ogg>
+#Feed feed1.ffm
+#Title "Stream title"
+#AudioBitRate 64
+#AudioChannels 2
+#AudioSampleRate 44100
+#NoVideo
+#</Stream>
+
+
+# Real with audio only at 32 kbits
+
+#<Stream test.ra>
+#Feed feed1.ffm
+#Format rm
+#AudioBitRate 32
+#NoVideo
+#NoAudio
+#</Stream>
+
+
+# Real with audio and video at 64 kbits
+
+#<Stream test.rm>
+#Feed feed1.ffm
+#Format rm
+#AudioBitRate 32
+#VideoBitRate 128
+#VideoFrameRate 25
+#VideoGopSize 25
+#NoAudio
+#</Stream>
+
+
+##################################################################
+# A stream coming from a file: you only need to set the input
+# filename and optionally a new format. Supported conversions:
+# AVI -> ASF
+
+#<Stream file.rm>
+#File "/usr/local/httpd/htdocs/tlive.rm"
+#NoAudio
+#</Stream>
+
+#<Stream file.asf>
+#File "/usr/local/httpd/htdocs/test.asf"
+#NoAudio
+#Author "Me"
+#Copyright "Super MegaCorp"
+#Title "Test stream from disk"
+#Comment "Test comment"
+#</Stream>
+
+
+##################################################################
+# RTSP examples
+#
+# You can access this stream with the RTSP URL:
+# rtsp://localhost:5454/test1-rtsp.mpg
+#
+# A non-standard RTSP redirector is also created. Its URL is:
+# http://localhost:8090/test1-rtsp.rtsp
+
+#<Stream test1-rtsp.mpg>
+#Format rtp
+#File "/usr/local/httpd/htdocs/test1.mpg"
+#</Stream>
+
+
+##################################################################
+# SDP/multicast examples
+#
+# If you want to send your stream in multicast, you must set the
+# multicast address with MulticastAddress. The port and the TTL can
+# also be set.
+#
+# An SDP file is automatically generated by ffserver by adding the
+# 'sdp' extension to the stream name (here
+# http://localhost:8090/test1-sdp.sdp). You should usually give this
+# file to your player to play the stream.
+#
+# The 'NoLoop' option can be used to avoid looping when the stream is
+# terminated.
+
+#<Stream test1-sdp.mpg>
+#Format rtp
+#File "/usr/local/httpd/htdocs/test1.mpg"
+#MulticastAddress 224.124.0.1
+#MulticastPort 5000
+#MulticastTTL 16
+#NoLoop
+#</Stream>
+
+
+##################################################################
+# Special streams
+
+# Server status
+
+<Stream stat.html>
+Format status
+
+# Only allow local people to get the status
+ACL allow localhost
+ACL allow 192.168.0.0 192.168.255.255
+
+#FaviconURL http://pond1.gladstonefamily.net:8080/favicon.ico
+</Stream>
+
+
+# Redirect index.html to the appropriate site
+
+<Redirect index.html>
+URL http://www.ffmpeg.org/
+</Redirect>
+
+
diff --git a/contrib/ffmpeg/doc/hooks.texi b/contrib/ffmpeg/doc/hooks.texi
new file mode 100644
index 000000000..49504509f
--- /dev/null
+++ b/contrib/ffmpeg/doc/hooks.texi
@@ -0,0 +1,260 @@
+\input texinfo @c -*- texinfo -*-
+
+@settitle Video Hook Documentation
+@titlepage
+@sp 7
+@center @titlefont{Video Hook Documentation}
+@sp 3
+@end titlepage
+
+
+@chapter Introduction
+
+
+The video hook functionality is designed (mostly) for live video. It allows
+the video to be modified or examined between the decoder and the encoder.
+
+Any number of hook modules can be placed inline, and they are run in the
+order that they were specified on the ffmpeg command line.
+
+The video hook modules are provided for use as a base for your own modules,
+and are described below.
+
+Modules are loaded using the -vhook option to ffmpeg. The value of this parameter
+is a space separated list of arguments. The first is the module name, and the rest
+are passed as arguments to the Configure function of the module.
+
+The modules are dynamic libraries: They have different suffixes (.so, .dll, .dylib)
+depending on your platform. And your platform dictates if they need to be
+somewhere in your PATH, or in your LD_LIBRARY_PATH. Otherwise you will need to
+specify the full path of the vhook file that you are using.
+
+@section null.c
+
+This does nothing. Actually it converts the input image to RGB24 and then converts
+it back again. This is meant as a sample that you can use to test your setup.
+
+@section fish.c
+
+This implements a 'fish detector'. Essentially it converts the image into HSV
+space and tests whether more than a certain percentage of the pixels fall into
+a specific HSV cuboid. If so, then the image is saved into a file for processing
+by other bits of code.
+
+Why use HSV? It turns out that HSV cuboids represent a more compact range of
+colors than would an RGB cuboid.
+
+@section imlib2.c
+
+This module implements a text overlay for a video image. Currently it
+supports a fixed overlay or reading the text from a file. The string
+is passed through strftime() so that it is easy to imprint the date and
+time onto the image.
+
+This module depends on the external library imlib2, available on
+Sourceforge, among other places, if it is not already installed on
+your system.
+
+You may also overlay an image (even semi-transparent) like TV stations do.
+You may move either the text or the image around your video to create
+scrolling credits, for example.
+
+The font file used is looked for in a FONTPATH environment variable, and
+prepended to the point size as a command line option and can be specified
+with the full path to the font file, as in:
+@example
+-F /usr/X11R6/lib/X11/fonts/TTF/VeraBd.ttf/20
+@end example
+where 20 is the point size.
+
+Options:
+@multitable @columnfractions .2 .8
+@item @option{-c <color>} @tab The color of the text
+@item @option{-F <fontname>} @tab The font face and size
+@item @option{-t <text>} @tab The text
+@item @option{-f <filename>} @tab The filename to read text from
+@item @option{-x <expresion>} @tab x coordinate of text or image
+@item @option{-y <expresion>} @tab y coordinate of text or image
+@item @option{-i <filename>} @tab The filename to read a image from
+@end multitable
+
+Expresions are functions of these variables:
+@multitable @columnfractions .2 .8
+@item @var{N} @tab frame number (starting at zero)
+@item @var{H} @tab frame height
+@item @var{W} @tab frame width
+@item @var{h} @tab image height
+@item @var{w} @tab image width
+@item @var{X} @tab previous x coordinate of text or image
+@item @var{Y} @tab previous y coordinate of text or image
+@end multitable
+
+You may also use the constants @var{PI}, @var{E}, and the math functions available at the
+FFmpeg formula evaluator at (@url{ffmpeg-doc.html#SEC13}), except @var{bits2qp(bits)}
+and @var{qp2bits(qp)}.
+
+Usage examples:
+
+@example
+ # Remember to set the path to your fonts
+ FONTPATH="/cygdrive/c/WINDOWS/Fonts/"
+ FONTPATH="$FONTPATH:/usr/share/imlib2/data/fonts/"
+ FONTPATH="$FONTPATH:/usr/X11R6/lib/X11/fonts/TTF/"
+ export FONTPATH
+
+ # Bulb dancing in a Lissajous pattern
+ ffmpeg -i input.avi -vhook \
+ 'vhook/imlib2.dll -x W*(0.5+0.25*sin(N/47*PI))-w/2 -y H*(0.5+0.50*cos(N/97*PI))-h/2 -i /usr/share/imlib2/data/images/bulb.png' \
+ -acodec copy -sameq output.avi
+
+ # Text scrolling
+ ffmpeg -i input.avi -vhook \
+ 'vhook/imlib2.dll -c red -F Vera.ttf/20 -x 150+0.5*N -y 70+0.25*N -t Hello' \
+ -acodec copy -sameq output.avi
+
+ # Date and time stamp, security-camera style:
+ ffmpeg -r 29.97 -s 320x256 -f video4linux -i /dev/video0 \
+ -vhook 'vhook/imlib2.so -x 0 -y 0 -i black-260x20.png' \
+ -vhook 'vhook/imlib2.so -c white -F VeraBd.ttf/12 -x 0 -y 0 -t %A-%D-%T' \
+ output.avi
+
+ In this example the video is captured from the first video capture card as a
+ 320x256 AVI, and a black 260 by 20 pixel PNG image is placed in the upper
+ left corner, with the day, date and time overlaid on it in Vera Bold 12
+ point font. A simple black PNG file 260 pixels wide and 20 pixels tall
+ was created in the GIMP for this purpose.
+
+ # Scrolling credits from a text file
+ ffmpeg -i input.avi -vhook \
+ 'vhook/imlib2.so -c white -F VeraBd.ttf/16 -x 100 -y -1.0*N -f credits.txt' \
+ -sameq output.avi
+
+ In this example, the text is stored in a file, and is positioned 100
+ pixels from the left hand edge of the video. The text is scrolled from the
+ bottom up. Making the y factor positive will scroll from the top down.
+ Increasing the magnitude of the y factor makes the text scroll faster,
+ decreasing it makes it scroll slower. Hint: Blank lines containing only
+ a newline are treated as end-of-file. To create blank lines, use lines
+ that consist of space characters only.
+
+ # scrolling credits from a graphics file
+ ffmpeg -sameq -i input.avi \
+ -vhook 'vhook/imlib2.so -x 0 -y -1.0*N -i credits.png' output.avi
+
+ In this example, a transparent PNG file the same width as the video
+ (e.g. 320 pixels), but very long, (e.g. 3000 pixels), was created, and
+ text, graphics, brushstrokes, etc, were added to the image. The image
+ is then scrolled up, from the bottom of the frame.
+
+@end example
+
+@section ppm.c
+
+It's basically a launch point for a PPM pipe, so you can use any
+executable (or script) which consumes a PPM on stdin and produces a PPM
+on stdout (and flushes each frame). The Netpbm utilities are a series of
+such programs.
+
+A list of them is here:
+
+@url{http://netpbm.sourceforge.net/doc/directory.html}
+
+Usage example:
+
+@example
+ffmpeg -i input -vhook "/path/to/ppm.so some-ppm-filter args" output
+@end example
+
+@section drawtext.c
+
+This module implements a text overlay for a video image. Currently it
+supports a fixed overlay or reading the text from a file. The string
+is passed through strftime() so that it is easy to imprint the date and
+time onto the image.
+
+Features:
+@itemize @minus
+@item TrueType, Type1 and others via the FreeType2 library
+@item Font kerning (better output)
+@item Line Wrap (put the text that doesn't fit one line on the next line)
+@item Background box (currently in development)
+@item Outline
+@end itemize
+
+Options:
+@multitable @columnfractions .2 .8
+@item @option{-c <color>} @tab Foreground color of the text ('internet' way) <#RRGGBB> [default #FFFFFF]
+@item @option{-C <color>} @tab Background color of the text ('internet' way) <#RRGGBB> [default #000000]
+@item @option{-f <font-filename>} @tab font file to use
+@item @option{-t <text>} @tab text to display
+@item @option{-T <filename>} @tab file to read text from
+@item @option{-x <pos>} @tab x coordinate of the start of the text
+@item @option{-y <pos>} @tab y coordinate of the start of the text
+@end multitable
+
+Text fonts are being looked for in a FONTPATH environment variable.
+If the FONTPATH environment variable is not available, or is not checked by
+your target (i.e. Cygwin), then specify the full path to the font file as in:
+@example
+-f /usr/X11R6/lib/X11/fonts/TTF/VeraBd.ttf
+@end example
+
+Usage Example:
+@example
+ # Remember to set the path to your fonts
+ FONTPATH="/cygdrive/c/WINDOWS/Fonts/"
+ FONTPATH="$FONTPATH:/usr/share/imlib2/data/fonts/"
+ FONTPATH="$FONTPATH:/usr/X11R6/lib/X11/fonts/TTF/"
+ export FONTPATH
+
+ # Time and date display
+ ffmpeg -f video4linux2 -i /dev/video0 \
+ -vhook 'vhook/drawtext.so -f VeraBd.ttf -t %A-%D-%T' movie.mpg
+
+ This example grabs video from the first capture card and outputs it to an
+ MPEG video, and places "Weekday-dd/mm/yy-hh:mm:ss" at the top left of the
+ frame, updated every second, using the Vera Bold TrueType Font, which
+ should exist in: /usr/X11R6/lib/X11/fonts/TTF/
+@end example
+
+Check the man page for strftime() for all the various ways you can format
+the date and time.
+
+@section watermark.c
+
+Command Line options:
+@multitable @columnfractions .2 .8
+@item @option{-m [0|1]} @tab Mode (default: 0, see below)
+@item @option{-t 000000 - FFFFFF} @tab Threshold, six digit hex number
+@item @option{-f <filename>} @tab Watermark image filename, must be specified!
+@end multitable
+
+MODE 0:
+ The watermark picture works like this (assuming color intensities 0..0xFF):
+ Per color do this:
+ If mask color is 0x80, no change to the original frame.
+ If mask color is < 0x80 the absolute difference is subtracted from the
+ frame. If result < 0, result = 0.
+ If mask color is > 0x80 the absolute difference is added to the
+ frame. If result > 0xFF, result = 0xFF.
+
+ You can override the 0x80 level with the -t flag. E.g. if threshold is
+ 000000 the color value of watermark is added to the destination.
+
+ This way a mask that is visible both in light and dark pictures can be made
+ (e.g. by using a picture generated by the Gimp and the bump map tool).
+
+ An example watermark file is at:
+ @url{http://engene.se/ffmpeg_watermark.gif}
+
+MODE 1:
+ Per color do this:
+ If mask color > threshold color then the watermark pixel is used.
+
+Example usage:
+@example
+ ffmpeg -i infile -vhook '/path/watermark.so -f wm.gif' -an out.mov
+ ffmpeg -i infile -vhook '/path/watermark.so -f wm.gif -m 1 -t 222222' -an out.mov
+@end example
+
+@bye
diff --git a/contrib/ffmpeg/doc/optimization.txt b/contrib/ffmpeg/doc/optimization.txt
new file mode 100644
index 000000000..f66c69bcf
--- /dev/null
+++ b/contrib/ffmpeg/doc/optimization.txt
@@ -0,0 +1,167 @@
+optimization Tips (for libavcodec):
+
+What to optimize:
+If you plan to do non-x86 architecture specific optimizations (SIMD normally),
+then take a look in the i386/ directory, as most important functions are
+already optimized for MMX.
+
+If you want to do x86 optimizations then you can either try to finetune the
+stuff in the i386 directory or find some other functions in the C source to
+optimize, but there aren't many left.
+
+Understanding these overoptimized functions:
+As many functions tend to be a bit difficult to understand because
+of optimizations, it can be hard to optimize them further, or write
+architecture-specific versions. It is recommened to look at older
+revisions of the interesting files (for a web frontend try ViewVC at
+http://svn.mplayerhq.hu/ffmpeg/trunk/).
+Alternatively, look into the other architecture-specific versions in
+the i386/, ppc/, alpha/ subdirectories. Even if you don't exactly
+comprehend the instructions, it could help understanding the functions
+and how they can be optimized.
+
+NOTE: If you still don't understand some function, ask at our mailing list!!!
+(http://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel)
+
+
+
+WTF is that function good for ....:
+The primary purpose of that list is to avoid wasting time to optimize functions
+which are rarely used
+
+put(_no_rnd)_pixels{,_x2,_y2,_xy2}
+ Used in motion compensation (en/decoding).
+
+avg_pixels{,_x2,_y2,_xy2}
+ Used in motion compensation of B-frames.
+ These are less important than the put*pixels functions.
+
+avg_no_rnd_pixels*
+ unused
+
+pix_abs16x16{,_x2,_y2,_xy2}
+ Used in motion estimation (encoding) with SAD.
+
+pix_abs8x8{,_x2,_y2,_xy2}
+ Used in motion estimation (encoding) with SAD of MPEG-4 4MV only.
+ These are less important than the pix_abs16x16* functions.
+
+put_mspel8_mc* / wmv2_mspel8*
+ Used only in WMV2.
+ it is not recommended that you waste your time with these, as WMV2
+ is an ugly and relatively useless codec.
+
+mpeg4_qpel* / *qpel_mc*
+ Used in MPEG-4 qpel motion compensation (encoding & decoding).
+ The qpel8 functions are used only for 4mv,
+ the avg_* functions are used only for B-frames.
+ Optimizing them should have a significant impact on qpel
+ encoding & decoding.
+
+qpel{8,16}_mc??_old_c / *pixels{8,16}_l4
+ Just used to work around a bug in an old libavcodec encoder version.
+ Don't optimize them.
+
+tpel_mc_func {put,avg}_tpel_pixels_tab
+ Used only for SVQ3, so only optimize them if you need fast SVQ3 decoding.
+
+add_bytes/diff_bytes
+ For huffyuv only, optimize if you want a faster ffhuffyuv codec.
+
+get_pixels / diff_pixels
+ Used for encoding, easy.
+
+clear_blocks
+ easiest to optimize
+
+gmc
+ Used for MPEG-4 gmc.
+ Optimizing this should have a significant effect on the gmc decoding
+ speed but it's very likely impossible to write in SIMD.
+
+gmc1
+ Used for chroma blocks in MPEG-4 gmc with 1 warp point
+ (there are 4 luma & 2 chroma blocks per macroblock, so
+ only 1/3 of the gmc blocks use this, the other 2/3
+ use the normal put_pixel* code, but only if there is
+ just 1 warp point).
+ Note: DivX5 gmc always uses just 1 warp point.
+
+pix_sum
+ Used for encoding.
+
+hadamard8_diff / sse / sad == pix_norm1 / dct_sad / quant_psnr / rd / bit
+ Specific compare functions used in encoding, it depends upon the
+ command line switches which of these are used.
+ Don't waste your time with dct_sad & quant_psnr, they aren't
+ really useful.
+
+put_pixels_clamped / add_pixels_clamped
+ Used for en/decoding in the IDCT, easy.
+ Note, some optimized IDCTs have the add/put clamped code included and
+ then put_pixels_clamped / add_pixels_clamped will be unused.
+
+idct/fdct
+ idct (encoding & decoding)
+ fdct (encoding)
+ difficult to optimize
+
+dct_quantize_trellis
+ Used for encoding with trellis quantization.
+ difficult to optimize
+
+dct_quantize
+ Used for encoding.
+
+dct_unquantize_mpeg1
+ Used in MPEG-1 en/decoding.
+
+dct_unquantize_mpeg2
+ Used in MPEG-2 en/decoding.
+
+dct_unquantize_h263
+ Used in MPEG-4/H.263 en/decoding.
+
+FIXME remaining functions?
+BTW, most of these functions are in dsputil.c/.h, some are in mpegvideo.c/.h.
+
+
+
+Alignment:
+Some instructions on some architectures have strict alignment restrictions,
+for example most SSE/SSE2 instructions on x86.
+The minimum guaranteed alignment is written in the .h files, for example:
+ void (*put_pixels_clamped)(const DCTELEM *block/*align 16*/, UINT8 *pixels/*align 8*/, int line_size);
+
+
+
+Links:
+http://www.aggregate.org/MAGIC/
+
+x86-specific:
+http://developer.intel.com/design/pentium4/manuals/248966.htm
+
+The IA-32 Intel Architecture Software Developer's Manual, Volume 2:
+Instruction Set Reference
+http://developer.intel.com/design/pentium4/manuals/245471.htm
+
+http://www.agner.org/assem/
+
+AMD Athlon Processor x86 Code Optimization Guide:
+http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/22007.pdf
+
+
+ARM-specific:
+ARM Architecture Reference Manual:
+http://www.arm.com/community/academy/resources.html
+
+Instructions timings and optimization guide for ARM9E:
+http://www.arm.com/pdfs/DDI0222B_9EJS_r1p2.pdf
+
+
+GCC asm links:
+official doc but quite ugly
+http://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html
+
+a bit old (note "+" is valid for input-output, even though the next disagrees)
+http://www.cs.virginia.edu/~clc5q/gcc-inline-asm.pdf
diff --git a/contrib/ffmpeg/doc/snow.txt b/contrib/ffmpeg/doc/snow.txt
new file mode 100644
index 000000000..4b8fab75a
--- /dev/null
+++ b/contrib/ffmpeg/doc/snow.txt
@@ -0,0 +1,259 @@
+=============================================
+SNOW Video Codec Specification Draft 20070103
+=============================================
+
+
+Definitions:
+============
+
+MUST the specific part must be done to conform to this standard
+SHOULD it is recommended to be done that way, but not strictly required
+
+ilog2(x) is the rounded down logarithm of x with basis 2
+ilog2(0) = 0
+
+Type definitions:
+=================
+
+b 1-bit range coded
+u unsigned scalar value range coded
+s signed scalar value range coded
+
+
+Bitstream syntax:
+=================
+
+frame:
+ header
+ prediction
+ residual
+
+header:
+ keyframe b MID_STATE
+ if(keyframe || always_reset)
+ reset_contexts
+ if(keyframe){
+ version u header_state
+ always_reset b header_state
+ temporal_decomposition_type u header_state
+ temporal_decomposition_count u header_state
+ spatial_decomposition_count u header_state
+ colorspace_type u header_state
+ chroma_h_shift u header_state
+ chroma_v_shift u header_state
+ spatial_scalability b header_state
+ max_ref_frames-1 u header_state
+ qlogs
+ }
+
+ spatial_decomposition_type s header_state
+ qlog s header_state
+ mv_scale s header_state
+ qbias s header_state
+ block_max_depth s header_state
+
+qlogs:
+ for(plane=0; plane<2; plane++){
+ quant_table[plane][0][0] s header_state
+ for(level=0; level < spatial_decomposition_count; level++){
+ quant_table[plane][level][1]s header_state
+ quant_table[plane][level][3]s header_state
+ }
+ }
+
+reset_contexts
+ *_state[*]= MID_STATE
+
+prediction:
+ for(y=0; y<block_count_vertical; y++)
+ for(x=0; x<block_count_horizontal; x++)
+ block(0)
+
+block(level):
+ if(keyframe){
+ intra=1
+ y_diff=cb_diff=cr_diff=0
+ }else{
+ if(level!=max_block_depth){
+ s_context= 2*left->level + 2*top->level + topleft->level + topright->level
+ leaf b block_state[4 + s_context]
+ }
+ if(level==max_block_depth || leaf){
+ intra b block_state[1 + left->intra + top->intra]
+ if(intra){
+ y_diff s block_state[32]
+ cb_diff s block_state[64]
+ cr_diff s block_state[96]
+ }else{
+ ref_context= ilog2(2*left->ref) + ilog2(2*top->ref)
+ if(ref_frames > 1)
+ ref u block_state[128 + 1024 + 32*ref_context]
+ mx_context= ilog2(2*abs(left->mx - top->mx))
+ my_context= ilog2(2*abs(left->my - top->my))
+ mvx_diff s block_state[128 + 32*(mx_context + 16*!!ref)]
+ mvy_diff s block_state[128 + 32*(my_context + 16*!!ref)]
+ }
+ }else{
+ block(level+1)
+ block(level+1)
+ block(level+1)
+ block(level+1)
+ }
+ }
+
+
+residual:
+ FIXME
+
+
+
+Tag description:
+----------------
+
+version
+ 0
+ this MUST NOT change within a bitstream
+
+always_reset
+ if 1 then the range coder contexts will be reset after each frame
+
+temporal_decomposition_type
+ 0
+
+temporal_decomposition_count
+ 0
+
+spatial_decomposition_count
+ FIXME
+
+colorspace_type
+ 0
+ this MUST NOT change within a bitstream
+
+chroma_h_shift
+ log2(luma.width / chroma.width)
+ this MUST NOT change within a bitstream
+
+chroma_v_shift
+ log2(luma.height / chroma.height)
+ this MUST NOT change within a bitstream
+
+spatial_scalability
+ 0
+
+max_ref_frames
+ maximum number of reference frames
+ this MUST NOT change within a bitstream
+
+ref_frames
+ minimum of the number of available reference frames and max_ref_frames
+ for example the first frame after a key frame always has ref_frames=1
+
+spatial_decomposition_type
+ wavelet type
+ 0 is a 9/7 symmetric compact integer wavelet
+ 1 is a 5/3 symmetric compact integer wavelet
+ others are reserved
+ stored as delta from last, last is reset to 0 if always_reset || keyframe
+
+qlog
+ quality (logarthmic quantizer scale)
+ stored as delta from last, last is reset to 0 if always_reset || keyframe
+
+mv_scale
+ stored as delta from last, last is reset to 0 if always_reset || keyframe
+ FIXME check that everything works fine if this changes between frames
+
+qbias
+ dequantization bias
+ stored as delta from last, last is reset to 0 if always_reset || keyframe
+
+block_max_depth
+ maximum depth of the block tree
+ stored as delta from last, last is reset to 0 if always_reset || keyframe
+
+quant_table
+ quantiztation table
+
+Range Coder:
+============
+FIXME
+
+Neighboring Blocks:
+===================
+left and top are set to the respective blocks unless they are outside of
+the image in which case they are set to the Null block
+
+top-left is set to the top left block unless its outside of the image in
+which case it is set to the left block
+
+if this block has no larger parent block or its at the left side of its
+parent block and the top right block is not outside of the image then the
+top right block is used for top-right else the top-left block is used
+
+Null block
+y,cb,cr are 128
+level, ref, mx and my are 0
+
+
+Motion Vector Prediction:
+=========================
+1. the motion vectors of all the neighboring blocks are scaled to
+compensate for the difference of reference frames
+
+scaled_mv= (mv * (256 * (current_reference+1) / (mv.reference+1)) + 128)>>8
+
+2. the median of the scaled left, top and top-right vectors is used as
+motion vector prediction
+
+3. the used motion vector is the sum of the predictor and
+ (mvx_diff, mvy_diff)*mv_scale
+
+
+Intra DC Predicton:
+======================
+the luma and chroma values of the left block are used as predictors
+
+the used luma and chroma is the sum of the predictor and y_diff, cb_diff, cr_diff
+
+
+Motion Compensation:
+====================
+FIXME
+
+LL band prediction:
+===================
+FIXME
+
+Dequantizaton:
+==============
+FIXME
+
+Wavelet Transform:
+==================
+FIXME
+
+TODO:
+=====
+Important:
+finetune initial contexts
+spatial_decomposition_count per frame?
+flip wavelet?
+try to use the wavelet transformed predicted image (motion compensated image) as context for coding the residual coefficients
+try the MV length as context for coding the residual coefficients
+use extradata for stuff which is in the keyframes now?
+the MV median predictor is patented IIRC
+
+Not Important:
+spatial_scalability b vs u (!= 0 breaks syntax anyway so we can add a u later)
+
+
+Credits:
+========
+Michael Niedermayer
+Loren Merritt
+
+
+Copyright:
+==========
+GPL + GFDL + whatever is needed to make this a RFC
diff --git a/contrib/ffmpeg/doc/soc.txt b/contrib/ffmpeg/doc/soc.txt
new file mode 100644
index 000000000..8b4a86db8
--- /dev/null
+++ b/contrib/ffmpeg/doc/soc.txt
@@ -0,0 +1,24 @@
+Google Summer of Code and similar project guidelines
+
+Summer of Code is a project by Google in which students are paid to implement
+some nice new features for various participating open source projects ...
+
+This text is a collection of things to take care of for the next soc as
+it's a little late for this year's soc (2006).
+
+The Goal:
+Our goal in respect to soc is and must be of course exactly one thing and
+that is to improve FFmpeg, to reach this goal, code must
+* conform to the svn policy and patch submission guidelines
+* must improve FFmpeg somehow (faster, smaller, "better",
+ more codecs supported, fewer bugs, cleaner, ...)
+
+for mentors and other developers to help students to reach that goal it is
+essential that changes to their codebase are publicly visible, clean and
+easy reviewable that again leads us to:
+* use of a revision control system like svn
+* separation of cosmetic from non-cosmetic changes (this is almost entirely
+ ignored by mentors and students in soc 2006 which might lead to a suprise
+ when the code will be reviewed at the end before a possible inclusion in
+ FFmpeg, individual changes were generally not reviewable due to cosmetics).
+* frequent commits, so that comments can be provided early
diff --git a/contrib/ffmpeg/doc/texi2pod.pl b/contrib/ffmpeg/doc/texi2pod.pl
new file mode 100755
index 000000000..c414ffcc6
--- /dev/null
+++ b/contrib/ffmpeg/doc/texi2pod.pl
@@ -0,0 +1,427 @@
+#! /usr/bin/perl -w
+
+# Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
+
+# This file is part of GNU CC.
+
+# GNU CC 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, or (at your option)
+# any later version.
+
+# GNU CC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with GNU CC; see the file COPYING. If not, write to
+# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301 USA
+
+# This does trivial (and I mean _trivial_) conversion of Texinfo
+# markup to Perl POD format. It's intended to be used to extract
+# something suitable for a manpage from a Texinfo document.
+
+$output = 0;
+$skipping = 0;
+%sects = ();
+$section = "";
+@icstack = ();
+@endwstack = ();
+@skstack = ();
+@instack = ();
+$shift = "";
+%defs = ();
+$fnno = 1;
+$inf = "";
+$ibase = "";
+
+while ($_ = shift) {
+ if (/^-D(.*)$/) {
+ if ($1 ne "") {
+ $flag = $1;
+ } else {
+ $flag = shift;
+ }
+ $value = "";
+ ($flag, $value) = ($flag =~ /^([^=]+)(?:=(.+))?/);
+ die "no flag specified for -D\n"
+ unless $flag ne "";
+ die "flags may only contain letters, digits, hyphens, dashes and underscores\n"
+ unless $flag =~ /^[a-zA-Z0-9_-]+$/;
+ $defs{$flag} = $value;
+ } elsif (/^-/) {
+ usage();
+ } else {
+ $in = $_, next unless defined $in;
+ $out = $_, next unless defined $out;
+ usage();
+ }
+}
+
+if (defined $in) {
+ $inf = gensym();
+ open($inf, "<$in") or die "opening \"$in\": $!\n";
+ $ibase = $1 if $in =~ m|^(.+)/[^/]+$|;
+} else {
+ $inf = \*STDIN;
+}
+
+if (defined $out) {
+ open(STDOUT, ">$out") or die "opening \"$out\": $!\n";
+}
+
+while(defined $inf) {
+while(<$inf>) {
+ # Certain commands are discarded without further processing.
+ /^\@(?:
+ [a-z]+index # @*index: useful only in complete manual
+ |need # @need: useful only in printed manual
+ |(?:end\s+)?group # @group .. @end group: ditto
+ |page # @page: ditto
+ |node # @node: useful only in .info file
+ |(?:end\s+)?ifnottex # @ifnottex .. @end ifnottex: use contents
+ )\b/x and next;
+
+ chomp;
+
+ # Look for filename and title markers.
+ /^\@setfilename\s+([^.]+)/ and $fn = $1, next;
+ /^\@settitle\s+([^.]+)/ and $tl = postprocess($1), next;
+
+ # Identify a man title but keep only the one we are interested in.
+ /^\@c\s+man\s+title\s+([A-Za-z0-9-]+)\s+(.+)/ and do {
+ if (exists $defs{$1}) {
+ $fn = $1;
+ $tl = postprocess($2);
+ }
+ next;
+ };
+
+ # Look for blocks surrounded by @c man begin SECTION ... @c man end.
+ # This really oughta be @ifman ... @end ifman and the like, but such
+ # would require rev'ing all other Texinfo translators.
+ /^\@c\s+man\s+begin\s+([A-Z]+)\s+([A-Za-z0-9-]+)/ and do {
+ $output = 1 if exists $defs{$2};
+ $sect = $1;
+ next;
+ };
+ /^\@c\s+man\s+begin\s+([A-Z]+)/ and $sect = $1, $output = 1, next;
+ /^\@c\s+man\s+end/ and do {
+ $sects{$sect} = "" unless exists $sects{$sect};
+ $sects{$sect} .= postprocess($section);
+ $section = "";
+ $output = 0;
+ next;
+ };
+
+ # handle variables
+ /^\@set\s+([a-zA-Z0-9_-]+)\s*(.*)$/ and do {
+ $defs{$1} = $2;
+ next;
+ };
+ /^\@clear\s+([a-zA-Z0-9_-]+)/ and do {
+ delete $defs{$1};
+ next;
+ };
+
+ next unless $output;
+
+ # Discard comments. (Can't do it above, because then we'd never see
+ # @c man lines.)
+ /^\@c\b/ and next;
+
+ # End-block handler goes up here because it needs to operate even
+ # if we are skipping.
+ /^\@end\s+([a-z]+)/ and do {
+ # Ignore @end foo, where foo is not an operation which may
+ # cause us to skip, if we are presently skipping.
+ my $ended = $1;
+ next if $skipping && $ended !~ /^(?:ifset|ifclear|ignore|menu|iftex)$/;
+
+ die "\@end $ended without \@$ended at line $.\n" unless defined $endw;
+ die "\@$endw ended by \@end $ended at line $.\n" unless $ended eq $endw;
+
+ $endw = pop @endwstack;
+
+ if ($ended =~ /^(?:ifset|ifclear|ignore|menu|iftex)$/) {
+ $skipping = pop @skstack;
+ next;
+ } elsif ($ended =~ /^(?:example|smallexample|display)$/) {
+ $shift = "";
+ $_ = ""; # need a paragraph break
+ } elsif ($ended =~ /^(?:itemize|enumerate|[fv]?table)$/) {
+ $_ = "\n=back\n";
+ $ic = pop @icstack;
+ } else {
+ die "unknown command \@end $ended at line $.\n";
+ }
+ };
+
+ # We must handle commands which can cause skipping even while we
+ # are skipping, otherwise we will not process nested conditionals
+ # correctly.
+ /^\@ifset\s+([a-zA-Z0-9_-]+)/ and do {
+ push @endwstack, $endw;
+ push @skstack, $skipping;
+ $endw = "ifset";
+ $skipping = 1 unless exists $defs{$1};
+ next;
+ };
+
+ /^\@ifclear\s+([a-zA-Z0-9_-]+)/ and do {
+ push @endwstack, $endw;
+ push @skstack, $skipping;
+ $endw = "ifclear";
+ $skipping = 1 if exists $defs{$1};
+ next;
+ };
+
+ /^\@(ignore|menu|iftex)\b/ and do {
+ push @endwstack, $endw;
+ push @skstack, $skipping;
+ $endw = $1;
+ $skipping = 1;
+ next;
+ };
+
+ next if $skipping;
+
+ # Character entities. First the ones that can be replaced by raw text
+ # or discarded outright:
+ s/\@copyright\{\}/(c)/g;
+ s/\@dots\{\}/.../g;
+ s/\@enddots\{\}/..../g;
+ s/\@([.!? ])/$1/g;
+ s/\@[:-]//g;
+ s/\@bullet(?:\{\})?/*/g;
+ s/\@TeX\{\}/TeX/g;
+ s/\@pounds\{\}/\#/g;
+ s/\@minus(?:\{\})?/-/g;
+ s/\\,/,/g;
+
+ # Now the ones that have to be replaced by special escapes
+ # (which will be turned back into text by unmunge())
+ s/&/&amp;/g;
+ s/\@\{/&lbrace;/g;
+ s/\@\}/&rbrace;/g;
+ s/\@\@/&at;/g;
+
+ # Inside a verbatim block, handle @var specially.
+ if ($shift ne "") {
+ s/\@var\{([^\}]*)\}/<$1>/g;
+ }
+
+ # POD doesn't interpret E<> inside a verbatim block.
+ if ($shift eq "") {
+ s/</&lt;/g;
+ s/>/&gt;/g;
+ } else {
+ s/</&LT;/g;
+ s/>/&GT;/g;
+ }
+
+ # Single line command handlers.
+
+ /^\@include\s+(.+)$/ and do {
+ push @instack, $inf;
+ $inf = gensym();
+
+ # Try cwd and $ibase.
+ open($inf, "<" . $1)
+ or open($inf, "<" . $ibase . "/" . $1)
+ or die "cannot open $1 or $ibase/$1: $!\n";
+ next;
+ };
+
+ /^\@(?:section|unnumbered|unnumberedsec|center)\s+(.+)$/
+ and $_ = "\n=head2 $1\n";
+ /^\@subsection\s+(.+)$/
+ and $_ = "\n=head3 $1\n";
+
+ # Block command handlers:
+ /^\@itemize\s+(\@[a-z]+|\*|-)/ and do {
+ push @endwstack, $endw;
+ push @icstack, $ic;
+ $ic = $1;
+ $_ = "\n=over 4\n";
+ $endw = "itemize";
+ };
+
+ /^\@enumerate(?:\s+([a-zA-Z0-9]+))?/ and do {
+ push @endwstack, $endw;
+ push @icstack, $ic;
+ if (defined $1) {
+ $ic = $1 . ".";
+ } else {
+ $ic = "1.";
+ }
+ $_ = "\n=over 4\n";
+ $endw = "enumerate";
+ };
+
+ /^\@([fv]?table)\s+(\@[a-z]+)/ and do {
+ push @endwstack, $endw;
+ push @icstack, $ic;
+ $endw = $1;
+ $ic = $2;
+ $ic =~ s/\@(?:samp|strong|key|gcctabopt|option|env)/B/;
+ $ic =~ s/\@(?:code|kbd)/C/;
+ $ic =~ s/\@(?:dfn|var|emph|cite|i)/I/;
+ $ic =~ s/\@(?:file)/F/;
+ $_ = "\n=over 4\n";
+ };
+
+ /^\@((?:small)?example|display)/ and do {
+ push @endwstack, $endw;
+ $endw = $1;
+ $shift = "\t";
+ $_ = ""; # need a paragraph break
+ };
+
+ /^\@itemx?\s*(.+)?$/ and do {
+ if (defined $1) {
+ # Entity escapes prevent munging by the <> processing below.
+ $_ = "\n=item $ic\&LT;$1\&GT;\n";
+ } else {
+ $_ = "\n=item $ic\n";
+ $ic =~ y/A-Ya-y/B-Zb-z/;
+ $ic =~ s/(\d+)/$1 + 1/eg;
+ }
+ };
+
+ $section .= $shift.$_."\n";
+}
+# End of current file.
+close($inf);
+$inf = pop @instack;
+}
+
+die "No filename or title\n" unless defined $fn && defined $tl;
+
+$sects{NAME} = "$fn \- $tl\n";
+$sects{FOOTNOTES} .= "=back\n" if exists $sects{FOOTNOTES};
+
+for $sect (qw(NAME SYNOPSIS DESCRIPTION OPTIONS EXAMPLES ENVIRONMENT FILES
+ BUGS NOTES FOOTNOTES SEEALSO AUTHOR COPYRIGHT)) {
+ if(exists $sects{$sect}) {
+ $head = $sect;
+ $head =~ s/SEEALSO/SEE ALSO/;
+ print "=head1 $head\n\n";
+ print scalar unmunge ($sects{$sect});
+ print "\n";
+ }
+}
+
+sub usage
+{
+ die "usage: $0 [-D toggle...] [infile [outfile]]\n";
+}
+
+sub postprocess
+{
+ local $_ = $_[0];
+
+ # @value{foo} is replaced by whatever 'foo' is defined as.
+ while (m/(\@value\{([a-zA-Z0-9_-]+)\})/g) {
+ if (! exists $defs{$2}) {
+ print STDERR "Option $2 not defined\n";
+ s/\Q$1\E//;
+ } else {
+ $value = $defs{$2};
+ s/\Q$1\E/$value/;
+ }
+ }
+
+ # Formatting commands.
+ # Temporary escape for @r.
+ s/\@r\{([^\}]*)\}/R<$1>/g;
+ s/\@(?:dfn|var|emph|cite|i)\{([^\}]*)\}/I<$1>/g;
+ s/\@(?:code|kbd)\{([^\}]*)\}/C<$1>/g;
+ s/\@(?:gccoptlist|samp|strong|key|option|env|command|b)\{([^\}]*)\}/B<$1>/g;
+ s/\@sc\{([^\}]*)\}/\U$1/g;
+ s/\@file\{([^\}]*)\}/F<$1>/g;
+ s/\@w\{([^\}]*)\}/S<$1>/g;
+ s/\@(?:dmn|math)\{([^\}]*)\}/$1/g;
+
+ # Cross references are thrown away, as are @noindent and @refill.
+ # (@noindent is impossible in .pod, and @refill is unnecessary.)
+ # @* is also impossible in .pod; we discard it and any newline that
+ # follows it. Similarly, our macro @gol must be discarded.
+
+ s/\(?\@xref\{(?:[^\}]*)\}(?:[^.<]|(?:<[^<>]*>))*\.\)?//g;
+ s/\s+\(\@pxref\{(?:[^\}]*)\}\)//g;
+ s/;\s+\@pxref\{(?:[^\}]*)\}//g;
+ s/\@noindent\s*//g;
+ s/\@refill//g;
+ s/\@gol//g;
+ s/\@\*\s*\n?//g;
+
+ # @uref can take one, two, or three arguments, with different
+ # semantics each time. @url and @email are just like @uref with
+ # one argument, for our purposes.
+ s/\@(?:uref|url|email)\{([^\},]*)\}/&lt;B<$1>&gt;/g;
+ s/\@uref\{([^\},]*),([^\},]*)\}/$2 (C<$1>)/g;
+ s/\@uref\{([^\},]*),([^\},]*),([^\},]*)\}/$3/g;
+
+ # Turn B<blah I<blah> blah> into B<blah> I<blah> B<blah> to
+ # match Texinfo semantics of @emph inside @samp. Also handle @r
+ # inside bold.
+ s/&LT;/</g;
+ s/&GT;/>/g;
+ 1 while s/B<((?:[^<>]|I<[^<>]*>)*)R<([^>]*)>/B<$1>${2}B</g;
+ 1 while (s/B<([^<>]*)I<([^>]+)>/B<$1>I<$2>B</g);
+ 1 while (s/I<([^<>]*)B<([^>]+)>/I<$1>B<$2>I</g);
+ s/[BI]<>//g;
+ s/([BI])<(\s+)([^>]+)>/$2$1<$3>/g;
+ s/([BI])<([^>]+?)(\s+)>/$1<$2>$3/g;
+
+ # Extract footnotes. This has to be done after all other
+ # processing because otherwise the regexp will choke on formatting
+ # inside @footnote.
+ while (/\@footnote/g) {
+ s/\@footnote\{([^\}]+)\}/[$fnno]/;
+ add_footnote($1, $fnno);
+ $fnno++;
+ }
+
+ return $_;
+}
+
+sub unmunge
+{
+ # Replace escaped symbols with their equivalents.
+ local $_ = $_[0];
+
+ s/&lt;/E<lt>/g;
+ s/&gt;/E<gt>/g;
+ s/&lbrace;/\{/g;
+ s/&rbrace;/\}/g;
+ s/&at;/\@/g;
+ s/&amp;/&/g;
+ return $_;
+}
+
+sub add_footnote
+{
+ unless (exists $sects{FOOTNOTES}) {
+ $sects{FOOTNOTES} = "\n=over 4\n\n";
+ }
+
+ $sects{FOOTNOTES} .= "=item $fnno.\n\n"; $fnno++;
+ $sects{FOOTNOTES} .= $_[0];
+ $sects{FOOTNOTES} .= "\n\n";
+}
+
+# stolen from Symbol.pm
+{
+ my $genseq = 0;
+ sub gensym
+ {
+ my $name = "GEN" . $genseq++;
+ my $ref = \*{$name};
+ delete $::{$name};
+ return $ref;
+ }
+}
diff --git a/contrib/ffmpeg/ffinstall.nsi b/contrib/ffmpeg/ffinstall.nsi
new file mode 100644
index 000000000..f483b0174
--- /dev/null
+++ b/contrib/ffmpeg/ffinstall.nsi
@@ -0,0 +1,75 @@
+;NSIS Script For FFmpeg
+
+;Title Of Your Application
+Name "FFmpeg"
+CompletedText "FFmpeg install completed! Enjoy your meal!"
+
+; do a CRC check
+CRCCheck On
+
+; output file name
+OutFile "FFinstall.exe"
+
+; license page introduction
+LicenseText "You must agree to this license before installing."
+
+; license data
+LicenseData ".\COPYING"
+
+; the default installation directory
+InstallDir "$PROGRAMFILES\FFmpeg"
+
+;The text to prompt the user to enter a directory
+DirText "Please select the folder below"
+
+Section "Install"
+ ;Install Files
+ SetOutPath $INSTDIR
+ SetCompress Auto
+ SetOverwrite IfNewer
+ File ".\ffmpeg.exe"
+ File ".\SDL.dll"
+ File ".\ffplay.exe"
+ File ".\COPYING"
+ File ".\CREDITS"
+
+ ; documentation
+ SetOutPath $INSTDIR\doc
+ File ".\doc\faq.html"
+ File ".\doc\ffmpeg-doc.html"
+ File ".\doc\ffplay-doc.html"
+
+ ; Write the uninstall keys for Windows
+ WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\FFmpeg" "DisplayName" "FFmpeg (remove only)"
+ WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\FFmpeg" "UninstallString" "$INSTDIR\Uninst.exe"
+WriteUninstaller "Uninst.exe"
+SectionEnd
+
+Section "Shortcuts"
+ ;Add Shortcuts
+SectionEnd
+
+UninstallText "This will uninstall FFmpeg from your system"
+
+Section Uninstall
+ ; delete files
+ Delete "$INSTDIR\ffmpeg.exe"
+ Delete "$INSTDIR\SDL.dll"
+ Delete "$INSTDIR\ffplay.exe"
+ Delete "$INSTDIR\COPYING"
+ Delete "$INSTDIR\CREDITS"
+
+ ; delete documentation
+ Delete "$INSTDIR\doc\faq.html"
+ Delete "$INSTDIR\ffmpeg-doc.html"
+ Delete "$INSTDIR\doc\ffplay-doc.html"
+
+ RMDir /r $INSTDIR\doc
+
+ ; delete uninstaller and unistall registry entries
+ Delete "$INSTDIR\Uninst.exe"
+ DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE\FFmpeg"
+ DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\FFmpeg"
+ RMDir "$INSTDIR"
+SectionEnd
+
diff --git a/contrib/ffmpeg/ffmpeg.c b/contrib/ffmpeg/ffmpeg.c
new file mode 100644
index 000000000..c9bac5de6
--- /dev/null
+++ b/contrib/ffmpeg/ffmpeg.c
@@ -0,0 +1,3823 @@
+/*
+ * FFmpeg main
+ * Copyright (c) 2000-2003 Fabrice Bellard
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#define HAVE_AV_CONFIG_H
+#include <signal.h>
+#include <limits.h>
+#include "avformat.h"
+#include "swscale.h"
+#include "framehook.h"
+#include "opt.h"
+#include "fifo.h"
+
+#ifdef __MINGW32__
+#include <conio.h>
+#else
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/time.h>
+#include <termios.h>
+#include <sys/resource.h>
+#endif
+#ifdef CONFIG_OS2
+#include <sys/types.h>
+#include <sys/select.h>
+#include <stdlib.h>
+#endif
+#undef time //needed because HAVE_AV_CONFIG_H is defined on top
+#include <time.h>
+
+#include "version.h"
+#include "cmdutils.h"
+
+#undef NDEBUG
+#include <assert.h>
+
+#if !defined(INFINITY) && defined(HUGE_VAL)
+#define INFINITY HUGE_VAL
+#endif
+
+#undef exit
+
+/* select an input stream for an output stream */
+typedef struct AVStreamMap {
+ int file_index;
+ int stream_index;
+ int sync_file_index;
+ int sync_stream_index;
+} AVStreamMap;
+
+/** select an input file for an output file */
+typedef struct AVMetaDataMap {
+ int out_file;
+ int in_file;
+} AVMetaDataMap;
+
+extern const OptionDef options[];
+
+static void show_help(void);
+static void show_license(void);
+static int opt_default(const char *opt, const char *arg);
+
+#define MAX_FILES 20
+
+static AVFormatContext *input_files[MAX_FILES];
+static int64_t input_files_ts_offset[MAX_FILES];
+static int nb_input_files = 0;
+
+static AVFormatContext *output_files[MAX_FILES];
+static int nb_output_files = 0;
+
+static AVStreamMap stream_maps[MAX_FILES];
+static int nb_stream_maps;
+
+static AVMetaDataMap meta_data_maps[MAX_FILES];
+static int nb_meta_data_maps;
+
+static AVInputFormat *file_iformat;
+static AVOutputFormat *file_oformat;
+static int frame_width = 0;
+static int frame_height = 0;
+static float frame_aspect_ratio = 0;
+static enum PixelFormat frame_pix_fmt = PIX_FMT_NONE;
+static int frame_padtop = 0;
+static int frame_padbottom = 0;
+static int frame_padleft = 0;
+static int frame_padright = 0;
+static int padcolor[3] = {16,128,128}; /* default to black */
+static int frame_topBand = 0;
+static int frame_bottomBand = 0;
+static int frame_leftBand = 0;
+static int frame_rightBand = 0;
+static int max_frames[4] = {INT_MAX, INT_MAX, INT_MAX, INT_MAX};
+static int frame_rate = 25;
+static int frame_rate_base = 1;
+static float video_qscale = 0;
+static int video_qdiff = 3;
+static uint16_t *intra_matrix = NULL;
+static uint16_t *inter_matrix = NULL;
+#if 0 //experimental, (can be removed)
+static float video_rc_qsquish=1.0;
+static float video_rc_qmod_amp=0;
+static int video_rc_qmod_freq=0;
+#endif
+static char *video_rc_override_string=NULL;
+static char *video_rc_eq="tex^qComp";
+static int me_method = ME_EPZS;
+static int video_disable = 0;
+static int video_discard = 0;
+static int video_codec_id = CODEC_ID_NONE;
+static int video_codec_tag = 0;
+static int same_quality = 0;
+static int do_deinterlace = 0;
+static int strict = 0;
+static int top_field_first = -1;
+static int me_threshold = 0;
+static int intra_dc_precision = 8;
+static int loop_input = 0;
+static int loop_output = AVFMT_NOOUTPUTLOOP;
+static int qp_hist = 0;
+
+static int intra_only = 0;
+static int audio_sample_rate = 44100;
+#define QSCALE_NONE -99999
+static float audio_qscale = QSCALE_NONE;
+static int audio_disable = 0;
+static int audio_channels = 1;
+static int audio_codec_id = CODEC_ID_NONE;
+static int audio_codec_tag = 0;
+static char *audio_language = NULL;
+
+static int subtitle_codec_id = CODEC_ID_NONE;
+static char *subtitle_language = NULL;
+
+static float mux_preload= 0.5;
+static float mux_max_delay= 0.7;
+
+static int64_t recording_time = 0;
+static int64_t start_time = 0;
+static int64_t rec_timestamp = 0;
+static int64_t input_ts_offset = 0;
+static int file_overwrite = 0;
+static char *str_title = NULL;
+static char *str_author = NULL;
+static char *str_copyright = NULL;
+static char *str_comment = NULL;
+static char *str_album = NULL;
+static int do_benchmark = 0;
+static int do_hex_dump = 0;
+static int do_pkt_dump = 0;
+static int do_psnr = 0;
+static int do_vstats = 0;
+static int do_pass = 0;
+static char *pass_logfilename = NULL;
+static int audio_stream_copy = 0;
+static int video_stream_copy = 0;
+static int subtitle_stream_copy = 0;
+static int video_sync_method= 1;
+static int audio_sync_method= 0;
+static int copy_ts= 0;
+static int opt_shortest = 0; //
+static int video_global_header = 0;
+
+static int rate_emu = 0;
+
+static int video_channel = 0;
+static char *video_standard = "ntsc";
+
+static int audio_volume = 256;
+
+static int using_stdin = 0;
+static int using_vhook = 0;
+static int verbose = 1;
+static int thread_count= 1;
+static int q_pressed = 0;
+static int64_t video_size = 0;
+static int64_t audio_size = 0;
+static int64_t extra_size = 0;
+static int nb_frames_dup = 0;
+static int nb_frames_drop = 0;
+static int input_sync;
+static uint64_t limit_filesize = 0; //
+
+static int pgmyuv_compatibility_hack=0;
+static int dts_delta_threshold = 10;
+
+static int sws_flags = SWS_BICUBIC;
+
+const char **opt_names=NULL;
+int opt_name_count=0;
+AVCodecContext *avctx_opts[CODEC_TYPE_NB];
+AVFormatContext *avformat_opts;
+static int64_t timer_start = 0;
+
+static AVBitStreamFilterContext *video_bitstream_filters=NULL;
+static AVBitStreamFilterContext *audio_bitstream_filters=NULL;
+static AVBitStreamFilterContext *bitstream_filters[MAX_FILES][MAX_STREAMS];
+
+#define DEFAULT_PASS_LOGFILENAME "ffmpeg2pass"
+
+struct AVInputStream;
+
+typedef struct AVOutputStream {
+ int file_index; /* file index */
+ int index; /* stream index in the output file */
+ int source_index; /* AVInputStream index */
+ AVStream *st; /* stream in the output file */
+ int encoding_needed; /* true if encoding needed for this stream */
+ int frame_number;
+ /* input pts and corresponding output pts
+ for A/V sync */
+ //double sync_ipts; /* dts from the AVPacket of the demuxer in second units */
+ struct AVInputStream *sync_ist; /* input stream to sync against */
+ int64_t sync_opts; /* output frame counter, could be changed to some true timestamp */ //FIXME look at frame_number
+ /* video only */
+ int video_resample;
+ AVFrame pict_tmp; /* temporary image for resampling */
+ struct SwsContext *img_resample_ctx; /* for image resampling */
+ int resample_height;
+
+ int video_crop;
+ int topBand; /* cropping area sizes */
+ int leftBand;
+
+ int video_pad;
+ int padtop; /* padding area sizes */
+ int padbottom;
+ int padleft;
+ int padright;
+
+ /* audio only */
+ int audio_resample;
+ ReSampleContext *resample; /* for audio resampling */
+ AVFifoBuffer fifo; /* for compression: one audio fifo per codec */
+ FILE *logfile;
+} AVOutputStream;
+
+typedef struct AVInputStream {
+ int file_index;
+ int index;
+ AVStream *st;
+ int discard; /* true if stream data should be discarded */
+ int decoding_needed; /* true if the packets must be decoded in 'raw_fifo' */
+ int64_t sample_index; /* current sample */
+
+ int64_t start; /* time when read started */
+ unsigned long frame; /* current frame */
+ int64_t next_pts; /* synthetic pts for cases where pkt.pts
+ is not defined */
+ int64_t pts; /* current pts */
+ int is_start; /* is 1 at the start and after a discontinuity */
+} AVInputStream;
+
+typedef struct AVInputFile {
+ int eof_reached; /* true if eof reached */
+ int ist_index; /* index of first stream in ist_table */
+ int buffer_size; /* current total buffer size */
+ int nb_streams; /* nb streams we are aware of */
+} AVInputFile;
+
+#ifndef __MINGW32__
+
+/* init terminal so that we can grab keys */
+static struct termios oldtty;
+#endif
+
+static void term_exit(void)
+{
+#ifndef __MINGW32__
+ tcsetattr (0, TCSANOW, &oldtty);
+#endif
+}
+
+static volatile sig_atomic_t received_sigterm = 0;
+
+static void
+sigterm_handler(int sig)
+{
+ received_sigterm = sig;
+ term_exit();
+}
+
+static void term_init(void)
+{
+#ifndef __MINGW32__
+ struct termios tty;
+
+ tcgetattr (0, &tty);
+ oldtty = tty;
+
+ tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
+ |INLCR|IGNCR|ICRNL|IXON);
+ tty.c_oflag |= OPOST;
+ tty.c_lflag &= ~(ECHO|ECHONL|ICANON|IEXTEN);
+ tty.c_cflag &= ~(CSIZE|PARENB);
+ tty.c_cflag |= CS8;
+ tty.c_cc[VMIN] = 1;
+ tty.c_cc[VTIME] = 0;
+
+ tcsetattr (0, TCSANOW, &tty);
+ signal(SIGQUIT, sigterm_handler); /* Quit (POSIX). */
+#endif
+
+ signal(SIGINT , sigterm_handler); /* Interrupt (ANSI). */
+ signal(SIGTERM, sigterm_handler); /* Termination (ANSI). */
+ /*
+ register a function to be called at normal program termination
+ */
+ atexit(term_exit);
+#ifdef CONFIG_BEOS_NETSERVER
+ fcntl(0, F_SETFL, fcntl(0, F_GETFL) | O_NONBLOCK);
+#endif
+}
+
+/* read a key without blocking */
+static int read_key(void)
+{
+#ifdef __MINGW32__
+ if(kbhit())
+ return(getch());
+#else
+ int n = 1;
+ unsigned char ch;
+#ifndef CONFIG_BEOS_NETSERVER
+ struct timeval tv;
+ fd_set rfds;
+
+ FD_ZERO(&rfds);
+ FD_SET(0, &rfds);
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
+ n = select(1, &rfds, NULL, NULL, &tv);
+#endif
+ if (n > 0) {
+ n = read(0, &ch, 1);
+ if (n == 1)
+ return ch;
+
+ return n;
+ }
+#endif
+ return -1;
+}
+
+static int decode_interrupt_cb(void)
+{
+ return q_pressed || (q_pressed = read_key() == 'q');
+}
+
+static int read_ffserver_streams(AVFormatContext *s, const char *filename)
+{
+ int i, err;
+ AVFormatContext *ic;
+
+ err = av_open_input_file(&ic, filename, NULL, FFM_PACKET_SIZE, NULL);
+ if (err < 0)
+ return err;
+ /* copy stream format */
+ s->nb_streams = ic->nb_streams;
+ for(i=0;i<ic->nb_streams;i++) {
+ AVStream *st;
+
+ // FIXME: a more elegant solution is needed
+ st = av_mallocz(sizeof(AVStream));
+ memcpy(st, ic->streams[i], sizeof(AVStream));
+ st->codec = avcodec_alloc_context();
+ memcpy(st->codec, ic->streams[i]->codec, sizeof(AVCodecContext));
+ s->streams[i] = st;
+ }
+
+ av_close_input_file(ic);
+ return 0;
+}
+
+static double
+get_sync_ipts(const AVOutputStream *ost)
+{
+ const AVInputStream *ist = ost->sync_ist;
+ return (double)(ist->pts + input_files_ts_offset[ist->file_index] - start_time)/AV_TIME_BASE;
+}
+
+static void write_frame(AVFormatContext *s, AVPacket *pkt, AVCodecContext *avctx, AVBitStreamFilterContext *bsfc){
+ while(bsfc){
+ AVPacket new_pkt= *pkt;
+ int a= av_bitstream_filter_filter(bsfc, avctx, NULL,
+ &new_pkt.data, &new_pkt.size,
+ pkt->data, pkt->size,
+ pkt->flags & PKT_FLAG_KEY);
+ if(a){
+ av_free_packet(pkt);
+ new_pkt.destruct= av_destruct_packet;
+ }
+ *pkt= new_pkt;
+
+ bsfc= bsfc->next;
+ }
+
+ av_interleaved_write_frame(s, pkt);
+}
+
+#define MAX_AUDIO_PACKET_SIZE (128 * 1024)
+
+static void do_audio_out(AVFormatContext *s,
+ AVOutputStream *ost,
+ AVInputStream *ist,
+ unsigned char *buf, int size)
+{
+ uint8_t *buftmp;
+ static uint8_t *audio_buf = NULL;
+ static uint8_t *audio_out = NULL;
+ const int audio_out_size= 4*MAX_AUDIO_PACKET_SIZE;
+
+ int size_out, frame_bytes, ret;
+ AVCodecContext *enc= ost->st->codec;
+
+ /* SC: dynamic allocation of buffers */
+ if (!audio_buf)
+ audio_buf = av_malloc(2*MAX_AUDIO_PACKET_SIZE);
+ if (!audio_out)
+ audio_out = av_malloc(audio_out_size);
+ if (!audio_buf || !audio_out)
+ return; /* Should signal an error ! */
+
+ if(audio_sync_method){
+ double delta = get_sync_ipts(ost) * enc->sample_rate - ost->sync_opts
+ - av_fifo_size(&ost->fifo)/(ost->st->codec->channels * 2);
+ double idelta= delta*ist->st->codec->sample_rate / enc->sample_rate;
+ int byte_delta= ((int)idelta)*2*ist->st->codec->channels;
+
+ //FIXME resample delay
+ if(fabs(delta) > 50){
+ if(ist->is_start){
+ if(byte_delta < 0){
+ byte_delta= FFMAX(byte_delta, -size);
+ size += byte_delta;
+ buf -= byte_delta;
+ if(verbose > 2)
+ fprintf(stderr, "discarding %d audio samples\n", (int)-delta);
+ if(!size)
+ return;
+ ist->is_start=0;
+ }else{
+ static uint8_t *input_tmp= NULL;
+ input_tmp= av_realloc(input_tmp, byte_delta + size);
+
+ if(byte_delta + size <= MAX_AUDIO_PACKET_SIZE)
+ ist->is_start=0;
+ else
+ byte_delta= MAX_AUDIO_PACKET_SIZE - size;
+
+ memset(input_tmp, 0, byte_delta);
+ memcpy(input_tmp + byte_delta, buf, size);
+ buf= input_tmp;
+ size += byte_delta;
+ if(verbose > 2)
+ fprintf(stderr, "adding %d audio samples of silence\n", (int)delta);
+ }
+ }else if(audio_sync_method>1){
+ int comp= av_clip(delta, -audio_sync_method, audio_sync_method);
+ assert(ost->audio_resample);
+ if(verbose > 2)
+ fprintf(stderr, "compensating audio timestamp drift:%f compensation:%d in:%d\n", delta, comp, enc->sample_rate);
+// fprintf(stderr, "drift:%f len:%d opts:%"PRId64" ipts:%"PRId64" fifo:%d\n", delta, -1, ost->sync_opts, (int64_t)(get_sync_ipts(ost) * enc->sample_rate), av_fifo_size(&ost->fifo)/(ost->st->codec->channels * 2));
+ av_resample_compensate(*(struct AVResampleContext**)ost->resample, comp, enc->sample_rate);
+ }
+ }
+ }else
+ ost->sync_opts= lrintf(get_sync_ipts(ost) * enc->sample_rate)
+ - av_fifo_size(&ost->fifo)/(ost->st->codec->channels * 2); //FIXME wrong
+
+ if (ost->audio_resample) {
+ buftmp = audio_buf;
+ size_out = audio_resample(ost->resample,
+ (short *)buftmp, (short *)buf,
+ size / (ist->st->codec->channels * 2));
+ size_out = size_out * enc->channels * 2;
+ } else {
+ buftmp = buf;
+ size_out = size;
+ }
+
+ /* now encode as many frames as possible */
+ if (enc->frame_size > 1) {
+ /* output resampled raw samples */
+ av_fifo_write(&ost->fifo, buftmp, size_out);
+
+ frame_bytes = enc->frame_size * 2 * enc->channels;
+
+ while (av_fifo_read(&ost->fifo, audio_buf, frame_bytes) == 0) {
+ AVPacket pkt;
+ av_init_packet(&pkt);
+
+ ret = avcodec_encode_audio(enc, audio_out, audio_out_size,
+ (short *)audio_buf);
+ audio_size += ret;
+ pkt.stream_index= ost->index;
+ pkt.data= audio_out;
+ pkt.size= ret;
+ if(enc->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE)
+ pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base);
+ pkt.flags |= PKT_FLAG_KEY;
+ write_frame(s, &pkt, ost->st->codec, bitstream_filters[ost->file_index][pkt.stream_index]);
+
+ ost->sync_opts += enc->frame_size;
+ }
+ } else {
+ AVPacket pkt;
+ av_init_packet(&pkt);
+
+ ost->sync_opts += size_out / (2 * enc->channels);
+
+ /* output a pcm frame */
+ /* XXX: change encoding codec API to avoid this ? */
+ switch(enc->codec->id) {
+ case CODEC_ID_PCM_S32LE:
+ case CODEC_ID_PCM_S32BE:
+ case CODEC_ID_PCM_U32LE:
+ case CODEC_ID_PCM_U32BE:
+ size_out = size_out << 1;
+ 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:
+ size_out = size_out / 2 * 3;
+ break;
+ case CODEC_ID_PCM_S16LE:
+ case CODEC_ID_PCM_S16BE:
+ case CODEC_ID_PCM_U16LE:
+ case CODEC_ID_PCM_U16BE:
+ break;
+ default:
+ size_out = size_out >> 1;
+ break;
+ }
+ ret = avcodec_encode_audio(enc, audio_out, size_out,
+ (short *)buftmp);
+ audio_size += ret;
+ pkt.stream_index= ost->index;
+ pkt.data= audio_out;
+ pkt.size= ret;
+ if(enc->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE)
+ pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base);
+ pkt.flags |= PKT_FLAG_KEY;
+ write_frame(s, &pkt, ost->st->codec, bitstream_filters[ost->file_index][pkt.stream_index]);
+ }
+}
+
+static void pre_process_video_frame(AVInputStream *ist, AVPicture *picture, void **bufp)
+{
+ AVCodecContext *dec;
+ AVPicture *picture2;
+ AVPicture picture_tmp;
+ uint8_t *buf = 0;
+
+ dec = ist->st->codec;
+
+ /* deinterlace : must be done before any resize */
+ if (do_deinterlace || using_vhook) {
+ int size;
+
+ /* create temporary picture */
+ size = avpicture_get_size(dec->pix_fmt, dec->width, dec->height);
+ buf = av_malloc(size);
+ if (!buf)
+ return;
+
+ picture2 = &picture_tmp;
+ avpicture_fill(picture2, buf, dec->pix_fmt, dec->width, dec->height);
+
+ if (do_deinterlace){
+ if(avpicture_deinterlace(picture2, picture,
+ dec->pix_fmt, dec->width, dec->height) < 0) {
+ /* if error, do not deinterlace */
+ av_free(buf);
+ buf = NULL;
+ picture2 = picture;
+ }
+ } else {
+ av_picture_copy(picture2, picture, dec->pix_fmt, dec->width, dec->height);
+ }
+ } else {
+ picture2 = picture;
+ }
+
+ frame_hook_process(picture2, dec->pix_fmt, dec->width, dec->height,
+ 1000000 * ist->pts / AV_TIME_BASE);
+
+ if (picture != picture2)
+ *picture = *picture2;
+ *bufp = buf;
+}
+
+/* we begin to correct av delay at this threshold */
+#define AV_DELAY_MAX 0.100
+
+static void do_subtitle_out(AVFormatContext *s,
+ AVOutputStream *ost,
+ AVInputStream *ist,
+ AVSubtitle *sub,
+ int64_t pts)
+{
+ static uint8_t *subtitle_out = NULL;
+ int subtitle_out_max_size = 65536;
+ int subtitle_out_size, nb, i;
+ AVCodecContext *enc;
+ AVPacket pkt;
+
+ if (pts == AV_NOPTS_VALUE) {
+ fprintf(stderr, "Subtitle packets must have a pts\n");
+ return;
+ }
+
+ enc = ost->st->codec;
+
+ if (!subtitle_out) {
+ subtitle_out = av_malloc(subtitle_out_max_size);
+ }
+
+ /* Note: DVB subtitle need one packet to draw them and one other
+ packet to clear them */
+ /* XXX: signal it in the codec context ? */
+ if (enc->codec_id == CODEC_ID_DVB_SUBTITLE)
+ nb = 2;
+ else
+ nb = 1;
+
+ for(i = 0; i < nb; i++) {
+ subtitle_out_size = avcodec_encode_subtitle(enc, subtitle_out,
+ subtitle_out_max_size, sub);
+
+ av_init_packet(&pkt);
+ pkt.stream_index = ost->index;
+ pkt.data = subtitle_out;
+ pkt.size = subtitle_out_size;
+ pkt.pts = av_rescale_q(av_rescale_q(pts, ist->st->time_base, AV_TIME_BASE_Q) + input_files_ts_offset[ist->file_index], AV_TIME_BASE_Q, ost->st->time_base);
+ if (enc->codec_id == CODEC_ID_DVB_SUBTITLE) {
+ /* XXX: the pts correction is handled here. Maybe handling
+ it in the codec would be better */
+ if (i == 0)
+ pkt.pts += 90 * sub->start_display_time;
+ else
+ pkt.pts += 90 * sub->end_display_time;
+ }
+ write_frame(s, &pkt, ost->st->codec, bitstream_filters[ost->file_index][pkt.stream_index]);
+ }
+}
+
+static int bit_buffer_size= 1024*256;
+static uint8_t *bit_buffer= NULL;
+
+static void do_video_out(AVFormatContext *s,
+ AVOutputStream *ost,
+ AVInputStream *ist,
+ AVFrame *in_picture,
+ int *frame_size)
+{
+ int nb_frames, i, ret;
+ AVFrame *final_picture, *formatted_picture, *resampling_dst, *padding_src;
+ AVFrame picture_crop_temp, picture_pad_temp;
+ AVCodecContext *enc, *dec;
+
+ avcodec_get_frame_defaults(&picture_crop_temp);
+ avcodec_get_frame_defaults(&picture_pad_temp);
+
+ enc = ost->st->codec;
+ dec = ist->st->codec;
+
+ /* by default, we output a single frame */
+ nb_frames = 1;
+
+ *frame_size = 0;
+
+ if(video_sync_method){
+ double vdelta;
+ vdelta = get_sync_ipts(ost) / av_q2d(enc->time_base) - ost->sync_opts;
+ //FIXME set to 0.5 after we fix some dts/pts bugs like in avidec.c
+ if (vdelta < -1.1)
+ nb_frames = 0;
+ else if (vdelta > 1.1)
+ nb_frames = lrintf(vdelta);
+//fprintf(stderr, "vdelta:%f, ost->sync_opts:%"PRId64", ost->sync_ipts:%f nb_frames:%d\n", vdelta, ost->sync_opts, ost->sync_ipts, nb_frames);
+ if (nb_frames == 0){
+ ++nb_frames_drop;
+ if (verbose>2)
+ fprintf(stderr, "*** drop!\n");
+ }else if (nb_frames > 1) {
+ nb_frames_dup += nb_frames;
+ if (verbose>2)
+ fprintf(stderr, "*** %d dup!\n", nb_frames-1);
+ }
+ }else
+ ost->sync_opts= lrintf(get_sync_ipts(ost) / av_q2d(enc->time_base));
+
+ nb_frames= FFMIN(nb_frames, max_frames[CODEC_TYPE_VIDEO] - ost->frame_number);
+ if (nb_frames <= 0)
+ return;
+
+ if (ost->video_crop) {
+ if (av_picture_crop((AVPicture *)&picture_crop_temp, (AVPicture *)in_picture, dec->pix_fmt, ost->topBand, ost->leftBand) < 0) {
+ av_log(NULL, AV_LOG_ERROR, "error cropping picture\n");
+ return;
+ }
+ formatted_picture = &picture_crop_temp;
+ } else {
+ formatted_picture = in_picture;
+ }
+
+ final_picture = formatted_picture;
+ padding_src = formatted_picture;
+ resampling_dst = &ost->pict_tmp;
+ if (ost->video_pad) {
+ final_picture = &ost->pict_tmp;
+ if (ost->video_resample) {
+ if (av_picture_crop((AVPicture *)&picture_pad_temp, (AVPicture *)final_picture, enc->pix_fmt, ost->padtop, ost->padleft) < 0) {
+ av_log(NULL, AV_LOG_ERROR, "error padding picture\n");
+ return;
+ }
+ resampling_dst = &picture_pad_temp;
+ }
+ }
+
+ if (ost->video_resample) {
+ padding_src = NULL;
+ final_picture = &ost->pict_tmp;
+ sws_scale(ost->img_resample_ctx, formatted_picture->data, formatted_picture->linesize,
+ 0, ost->resample_height, resampling_dst->data, resampling_dst->linesize);
+ }
+
+ if (ost->video_pad) {
+ av_picture_pad((AVPicture*)final_picture, (AVPicture *)padding_src,
+ enc->height, enc->width, enc->pix_fmt,
+ ost->padtop, ost->padbottom, ost->padleft, ost->padright, padcolor);
+ }
+
+ /* duplicates frame if needed */
+ for(i=0;i<nb_frames;i++) {
+ AVPacket pkt;
+ av_init_packet(&pkt);
+ pkt.stream_index= ost->index;
+
+ if (s->oformat->flags & AVFMT_RAWPICTURE) {
+ /* raw pictures are written as AVPicture structure to
+ avoid any copies. We support temorarily the older
+ method. */
+ AVFrame* old_frame = enc->coded_frame;
+ enc->coded_frame = dec->coded_frame; //FIXME/XXX remove this hack
+ pkt.data= (uint8_t *)final_picture;
+ pkt.size= sizeof(AVPicture);
+ if(dec->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE)
+ pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base);
+ if(dec->coded_frame && dec->coded_frame->key_frame)
+ pkt.flags |= PKT_FLAG_KEY;
+
+ write_frame(s, &pkt, ost->st->codec, bitstream_filters[ost->file_index][pkt.stream_index]);
+ enc->coded_frame = old_frame;
+ } else {
+ AVFrame big_picture;
+
+ big_picture= *final_picture;
+ /* better than nothing: use input picture interlaced
+ settings */
+ big_picture.interlaced_frame = in_picture->interlaced_frame;
+ if(avctx_opts[CODEC_TYPE_VIDEO]->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME)){
+ if(top_field_first == -1)
+ big_picture.top_field_first = in_picture->top_field_first;
+ else
+ big_picture.top_field_first = top_field_first;
+ }
+
+ /* handles sameq here. This is not correct because it may
+ not be a global option */
+ if (same_quality) {
+ big_picture.quality = ist->st->quality;
+ }else
+ big_picture.quality = ost->st->quality;
+ if(!me_threshold)
+ big_picture.pict_type = 0;
+// big_picture.pts = AV_NOPTS_VALUE;
+ big_picture.pts= ost->sync_opts;
+// big_picture.pts= av_rescale(ost->sync_opts, AV_TIME_BASE*(int64_t)enc->time_base.num, enc->time_base.den);
+//av_log(NULL, AV_LOG_DEBUG, "%"PRId64" -> encoder\n", ost->sync_opts);
+ ret = avcodec_encode_video(enc,
+ bit_buffer, bit_buffer_size,
+ &big_picture);
+ if (ret == -1) {
+ fprintf(stderr, "Video encoding failed\n");
+ exit(1);
+ }
+ //enc->frame_number = enc->real_pict_num;
+ if(ret>0){
+ pkt.data= bit_buffer;
+ pkt.size= ret;
+ if(enc->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE)
+ pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base);
+/*av_log(NULL, AV_LOG_DEBUG, "encoder -> %"PRId64"/%"PRId64"\n",
+ pkt.pts != AV_NOPTS_VALUE ? av_rescale(pkt.pts, enc->time_base.den, AV_TIME_BASE*(int64_t)enc->time_base.num) : -1,
+ pkt.dts != AV_NOPTS_VALUE ? av_rescale(pkt.dts, enc->time_base.den, AV_TIME_BASE*(int64_t)enc->time_base.num) : -1);*/
+
+ if(enc->coded_frame && enc->coded_frame->key_frame)
+ pkt.flags |= PKT_FLAG_KEY;
+ write_frame(s, &pkt, ost->st->codec, bitstream_filters[ost->file_index][pkt.stream_index]);
+ *frame_size = ret;
+ //fprintf(stderr,"\nFrame: %3d %3d size: %5d type: %d",
+ // enc->frame_number-1, enc->real_pict_num, ret,
+ // enc->pict_type);
+ /* if two pass, output log */
+ if (ost->logfile && enc->stats_out) {
+ fprintf(ost->logfile, "%s", enc->stats_out);
+ }
+ }
+ }
+ ost->sync_opts++;
+ ost->frame_number++;
+ }
+}
+
+static double psnr(double d){
+ if(d==0) return INFINITY;
+ return -10.0*log(d)/log(10.0);
+}
+
+static void do_video_stats(AVFormatContext *os, AVOutputStream *ost,
+ int frame_size)
+{
+ static FILE *fvstats=NULL;
+ char filename[40];
+ time_t today2;
+ struct tm *today;
+ AVCodecContext *enc;
+ int frame_number;
+ int64_t ti;
+ double ti1, bitrate, avg_bitrate;
+
+ if (!fvstats) {
+ today2 = time(NULL);
+ today = localtime(&today2);
+ snprintf(filename, sizeof(filename), "vstats_%02d%02d%02d.log", today->tm_hour,
+ today->tm_min,
+ today->tm_sec);
+ fvstats = fopen(filename,"w");
+ if (!fvstats) {
+ perror("fopen");
+ exit(1);
+ }
+ }
+
+ ti = INT64_MAX;
+ enc = ost->st->codec;
+ if (enc->codec_type == CODEC_TYPE_VIDEO) {
+ frame_number = ost->frame_number;
+ fprintf(fvstats, "frame= %5d q= %2.1f ", frame_number, enc->coded_frame->quality/(float)FF_QP2LAMBDA);
+ if (enc->flags&CODEC_FLAG_PSNR)
+ fprintf(fvstats, "PSNR= %6.2f ", psnr(enc->coded_frame->error[0]/(enc->width*enc->height*255.0*255.0)));
+
+ fprintf(fvstats,"f_size= %6d ", frame_size);
+ /* compute pts value */
+ ti1 = ost->sync_opts * av_q2d(enc->time_base);
+ if (ti1 < 0.01)
+ ti1 = 0.01;
+
+ bitrate = (frame_size * 8) / av_q2d(enc->time_base) / 1000.0;
+ avg_bitrate = (double)(video_size * 8) / ti1 / 1000.0;
+ fprintf(fvstats, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ",
+ (double)video_size / 1024, ti1, bitrate, avg_bitrate);
+ fprintf(fvstats,"type= %c\n", av_get_pict_type_char(enc->coded_frame->pict_type));
+ }
+}
+
+static void print_report(AVFormatContext **output_files,
+ AVOutputStream **ost_table, int nb_ostreams,
+ int is_last_report)
+{
+ char buf[1024];
+ AVOutputStream *ost;
+ AVFormatContext *oc, *os;
+ int64_t total_size;
+ AVCodecContext *enc;
+ int frame_number, vid, i;
+ double bitrate, ti1, pts;
+ static int64_t last_time = -1;
+ static int qp_histogram[52];
+
+ if (!is_last_report) {
+ int64_t cur_time;
+ /* display the report every 0.5 seconds */
+ cur_time = av_gettime();
+ if (last_time == -1) {
+ last_time = cur_time;
+ return;
+ }
+ if ((cur_time - last_time) < 500000)
+ return;
+ last_time = cur_time;
+ }
+
+
+ oc = output_files[0];
+
+ total_size = url_ftell(&oc->pb);
+
+ buf[0] = '\0';
+ ti1 = 1e10;
+ vid = 0;
+ for(i=0;i<nb_ostreams;i++) {
+ ost = ost_table[i];
+ os = output_files[ost->file_index];
+ enc = ost->st->codec;
+ if (vid && enc->codec_type == CODEC_TYPE_VIDEO) {
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "q=%2.1f ",
+ enc->coded_frame->quality/(float)FF_QP2LAMBDA);
+ }
+ if (!vid && enc->codec_type == CODEC_TYPE_VIDEO) {
+ float t = (av_gettime()-timer_start) / 1000000.0;
+
+ frame_number = ost->frame_number;
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "frame=%5d fps=%3d q=%3.1f ",
+ frame_number, (t>1)?(int)(frame_number/t+0.5) : 0,
+ enc->coded_frame ? enc->coded_frame->quality/(float)FF_QP2LAMBDA : -1);
+ if(is_last_report)
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "L");
+ if(qp_hist && enc->coded_frame){
+ int j;
+ int qp= lrintf(enc->coded_frame->quality/(float)FF_QP2LAMBDA);
+ if(qp>=0 && qp<sizeof(qp_histogram)/sizeof(int))
+ qp_histogram[qp]++;
+ for(j=0; j<32; j++)
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%X", (int)lrintf(log(qp_histogram[j]+1)/log(2)));
+ }
+ if (enc->flags&CODEC_FLAG_PSNR){
+ int j;
+ double error, error_sum=0;
+ double scale, scale_sum=0;
+ char type[3]= {'Y','U','V'};
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "PSNR=");
+ for(j=0; j<3; j++){
+ if(is_last_report){
+ error= enc->error[j];
+ scale= enc->width*enc->height*255.0*255.0*frame_number;
+ }else{
+ error= enc->coded_frame->error[j];
+ scale= enc->width*enc->height*255.0*255.0;
+ }
+ if(j) scale/=4;
+ error_sum += error;
+ scale_sum += scale;
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%c:%2.2f ", type[j], psnr(error/scale));
+ }
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "*:%2.2f ", psnr(error_sum/scale_sum));
+ }
+ vid = 1;
+ }
+ /* compute min output value */
+ pts = (double)ost->st->pts.val * ost->st->time_base.num / ost->st->time_base.den;
+ if ((pts < ti1) && (pts > 0))
+ ti1 = pts;
+ }
+ if (ti1 < 0.01)
+ ti1 = 0.01;
+
+ if (verbose || is_last_report) {
+ bitrate = (double)(total_size * 8) / ti1 / 1000.0;
+
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
+ "size=%8.0fkB time=%0.1f bitrate=%6.1fkbits/s",
+ (double)total_size / 1024, ti1, bitrate);
+
+ if (verbose > 1)
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " dup=%d drop=%d",
+ nb_frames_dup, nb_frames_drop);
+
+ if (verbose >= 0)
+ fprintf(stderr, "%s \r", buf);
+
+ fflush(stderr);
+ }
+
+ if (is_last_report && verbose >= 0){
+ int64_t raw= audio_size + video_size + extra_size;
+ fprintf(stderr, "\n");
+ fprintf(stderr, "video:%1.0fkB audio:%1.0fkB global headers:%1.0fkB muxing overhead %f%%\n",
+ video_size/1024.0,
+ audio_size/1024.0,
+ extra_size/1024.0,
+ 100.0*(total_size - raw)/raw
+ );
+ }
+}
+
+/* pkt = NULL means EOF (needed to flush decoder buffers) */
+static int output_packet(AVInputStream *ist, int ist_index,
+ AVOutputStream **ost_table, int nb_ostreams,
+ const AVPacket *pkt)
+{
+ AVFormatContext *os;
+ AVOutputStream *ost;
+ uint8_t *ptr;
+ int len, ret, i;
+ uint8_t *data_buf;
+ int data_size, got_picture;
+ AVFrame picture;
+ void *buffer_to_free;
+ static unsigned int samples_size= 0;
+ static short *samples= NULL;
+ AVSubtitle subtitle, *subtitle_to_free;
+ int got_subtitle;
+
+ if(!pkt){
+ ist->pts= ist->next_pts; // needed for last packet if vsync=0
+ } else if (pkt->dts != AV_NOPTS_VALUE) { //FIXME seems redundant, as libavformat does this too
+ ist->next_pts = ist->pts = av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q);
+ } else {
+// assert(ist->pts == ist->next_pts);
+ }
+
+ if (pkt == NULL) {
+ /* EOF handling */
+ ptr = NULL;
+ len = 0;
+ goto handle_eof;
+ }
+
+ len = pkt->size;
+ ptr = pkt->data;
+ while (len > 0) {
+ handle_eof:
+ /* decode the packet if needed */
+ data_buf = NULL; /* fail safe */
+ data_size = 0;
+ subtitle_to_free = NULL;
+ if (ist->decoding_needed) {
+ switch(ist->st->codec->codec_type) {
+ case CODEC_TYPE_AUDIO:{
+ if(pkt)
+ samples= av_fast_realloc(samples, &samples_size, FFMAX(pkt->size*sizeof(*samples), AVCODEC_MAX_AUDIO_FRAME_SIZE));
+ data_size= samples_size;
+ /* XXX: could avoid copy if PCM 16 bits with same
+ endianness as CPU */
+ ret = avcodec_decode_audio2(ist->st->codec, samples, &data_size,
+ ptr, len);
+ if (ret < 0)
+ goto fail_decode;
+ ptr += ret;
+ len -= ret;
+ /* Some bug in mpeg audio decoder gives */
+ /* data_size < 0, it seems they are overflows */
+ if (data_size <= 0) {
+ /* no audio frame */
+ continue;
+ }
+ data_buf = (uint8_t *)samples;
+ ist->next_pts += ((int64_t)AV_TIME_BASE/2 * data_size) /
+ (ist->st->codec->sample_rate * ist->st->codec->channels);
+ break;}
+ case CODEC_TYPE_VIDEO:
+ data_size = (ist->st->codec->width * ist->st->codec->height * 3) / 2;
+ /* XXX: allocate picture correctly */
+ avcodec_get_frame_defaults(&picture);
+
+ ret = avcodec_decode_video(ist->st->codec,
+ &picture, &got_picture, ptr, len);
+ ist->st->quality= picture.quality;
+ if (ret < 0)
+ goto fail_decode;
+ if (!got_picture) {
+ /* no picture yet */
+ goto discard_packet;
+ }
+ if (ist->st->codec->time_base.num != 0) {
+ ist->next_pts += ((int64_t)AV_TIME_BASE *
+ ist->st->codec->time_base.num) /
+ ist->st->codec->time_base.den;
+ }
+ len = 0;
+ break;
+ case CODEC_TYPE_SUBTITLE:
+ ret = avcodec_decode_subtitle(ist->st->codec,
+ &subtitle, &got_subtitle, ptr, len);
+ if (ret < 0)
+ goto fail_decode;
+ if (!got_subtitle) {
+ goto discard_packet;
+ }
+ subtitle_to_free = &subtitle;
+ len = 0;
+ break;
+ default:
+ goto fail_decode;
+ }
+ } else {
+ switch(ist->st->codec->codec_type) {
+ case CODEC_TYPE_AUDIO:
+ ist->next_pts += ((int64_t)AV_TIME_BASE * ist->st->codec->frame_size) /
+ (ist->st->codec->sample_rate * ist->st->codec->channels);
+ break;
+ case CODEC_TYPE_VIDEO:
+ if (ist->st->codec->time_base.num != 0) {
+ ist->next_pts += ((int64_t)AV_TIME_BASE *
+ ist->st->codec->time_base.num) /
+ ist->st->codec->time_base.den;
+ }
+ break;
+ }
+ data_buf = ptr;
+ data_size = len;
+ ret = len;
+ len = 0;
+ }
+
+ buffer_to_free = NULL;
+ if (ist->st->codec->codec_type == CODEC_TYPE_VIDEO) {
+ pre_process_video_frame(ist, (AVPicture *)&picture,
+ &buffer_to_free);
+ }
+
+ // preprocess audio (volume)
+ if (ist->st->codec->codec_type == CODEC_TYPE_AUDIO) {
+ if (audio_volume != 256) {
+ short *volp;
+ volp = samples;
+ for(i=0;i<(data_size / sizeof(short));i++) {
+ int v = ((*volp) * audio_volume + 128) >> 8;
+ if (v < -32768) v = -32768;
+ if (v > 32767) v = 32767;
+ *volp++ = v;
+ }
+ }
+ }
+
+ /* frame rate emulation */
+ if (ist->st->codec->rate_emu) {
+ int64_t pts = av_rescale((int64_t) ist->frame * ist->st->codec->time_base.num, 1000000, ist->st->codec->time_base.den);
+ int64_t now = av_gettime() - ist->start;
+ if (pts > now)
+ usleep(pts - now);
+
+ ist->frame++;
+ }
+
+#if 0
+ /* mpeg PTS deordering : if it is a P or I frame, the PTS
+ is the one of the next displayed one */
+ /* XXX: add mpeg4 too ? */
+ if (ist->st->codec->codec_id == CODEC_ID_MPEG1VIDEO) {
+ if (ist->st->codec->pict_type != B_TYPE) {
+ int64_t tmp;
+ tmp = ist->last_ip_pts;
+ ist->last_ip_pts = ist->frac_pts.val;
+ ist->frac_pts.val = tmp;
+ }
+ }
+#endif
+ /* if output time reached then transcode raw format,
+ encode packets and output them */
+ if (start_time == 0 || ist->pts >= start_time)
+ for(i=0;i<nb_ostreams;i++) {
+ int frame_size;
+
+ ost = ost_table[i];
+ if (ost->source_index == ist_index) {
+ os = output_files[ost->file_index];
+
+#if 0
+ printf("%d: got pts=%0.3f %0.3f\n", i,
+ (double)pkt->pts / AV_TIME_BASE,
+ ((double)ist->pts / AV_TIME_BASE) -
+ ((double)ost->st->pts.val * ost->st->time_base.num / ost->st->time_base.den));
+#endif
+ /* set the input output pts pairs */
+ //ost->sync_ipts = (double)(ist->pts + input_files_ts_offset[ist->file_index] - start_time)/ AV_TIME_BASE;
+
+ if (ost->encoding_needed) {
+ switch(ost->st->codec->codec_type) {
+ case CODEC_TYPE_AUDIO:
+ do_audio_out(os, ost, ist, data_buf, data_size);
+ break;
+ case CODEC_TYPE_VIDEO:
+ do_video_out(os, ost, ist, &picture, &frame_size);
+ video_size += frame_size;
+ if (do_vstats && frame_size)
+ do_video_stats(os, ost, frame_size);
+ break;
+ case CODEC_TYPE_SUBTITLE:
+ do_subtitle_out(os, ost, ist, &subtitle,
+ pkt->pts);
+ break;
+ default:
+ av_abort();
+ }
+ } else {
+ AVFrame avframe; //FIXME/XXX remove this
+ AVPacket opkt;
+ av_init_packet(&opkt);
+
+ /* no reencoding needed : output the packet directly */
+ /* force the input stream PTS */
+
+ avcodec_get_frame_defaults(&avframe);
+ ost->st->codec->coded_frame= &avframe;
+ avframe.key_frame = pkt->flags & PKT_FLAG_KEY;
+
+ if(ost->st->codec->codec_type == CODEC_TYPE_AUDIO)
+ audio_size += data_size;
+ else if (ost->st->codec->codec_type == CODEC_TYPE_VIDEO) {
+ video_size += data_size;
+ ost->sync_opts++;
+ }
+
+ opkt.stream_index= ost->index;
+ if(pkt->pts != AV_NOPTS_VALUE)
+ opkt.pts= av_rescale_q(av_rescale_q(pkt->pts, ist->st->time_base, AV_TIME_BASE_Q) + input_files_ts_offset[ist->file_index], AV_TIME_BASE_Q, ost->st->time_base);
+ else
+ opkt.pts= AV_NOPTS_VALUE;
+
+ {
+ int64_t dts;
+ if (pkt->dts == AV_NOPTS_VALUE)
+ dts = ist->next_pts;
+ else
+ dts= av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q);
+ opkt.dts= av_rescale_q(dts + input_files_ts_offset[ist->file_index], AV_TIME_BASE_Q, ost->st->time_base);
+ }
+ opkt.flags= pkt->flags;
+
+ //FIXME remove the following 2 lines they shall be replaced by the bitstream filters
+ if(av_parser_change(ist->st->parser, ost->st->codec, &opkt.data, &opkt.size, data_buf, data_size, pkt->flags & PKT_FLAG_KEY))
+ opkt.destruct= av_destruct_packet;
+
+ write_frame(os, &opkt, ost->st->codec, bitstream_filters[ost->file_index][pkt->stream_index]);
+ ost->st->codec->frame_number++;
+ ost->frame_number++;
+ av_free_packet(&opkt);
+ }
+ }
+ }
+ av_free(buffer_to_free);
+ /* XXX: allocate the subtitles in the codec ? */
+ if (subtitle_to_free) {
+ if (subtitle_to_free->rects != NULL) {
+ for (i = 0; i < subtitle_to_free->num_rects; i++) {
+ av_free(subtitle_to_free->rects[i].bitmap);
+ av_free(subtitle_to_free->rects[i].rgba_palette);
+ }
+ av_freep(&subtitle_to_free->rects);
+ }
+ subtitle_to_free->num_rects = 0;
+ subtitle_to_free = NULL;
+ }
+ }
+ discard_packet:
+ if (pkt == NULL) {
+ /* EOF handling */
+
+ for(i=0;i<nb_ostreams;i++) {
+ ost = ost_table[i];
+ if (ost->source_index == ist_index) {
+ AVCodecContext *enc= ost->st->codec;
+ os = output_files[ost->file_index];
+
+ if(ost->st->codec->codec_type == CODEC_TYPE_AUDIO && enc->frame_size <=1)
+ continue;
+ if(ost->st->codec->codec_type == CODEC_TYPE_VIDEO && (os->oformat->flags & AVFMT_RAWPICTURE))
+ continue;
+
+ if (ost->encoding_needed) {
+ for(;;) {
+ AVPacket pkt;
+ int fifo_bytes;
+ av_init_packet(&pkt);
+ pkt.stream_index= ost->index;
+
+ switch(ost->st->codec->codec_type) {
+ case CODEC_TYPE_AUDIO:
+ fifo_bytes = av_fifo_size(&ost->fifo);
+ ret = 0;
+ /* encode any samples remaining in fifo */
+ if(fifo_bytes > 0 && enc->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME) {
+ int fs_tmp = enc->frame_size;
+ enc->frame_size = fifo_bytes / (2 * enc->channels);
+ if(av_fifo_read(&ost->fifo, (uint8_t *)samples, fifo_bytes) == 0) {
+ ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, samples);
+ }
+ enc->frame_size = fs_tmp;
+ }
+ if(ret <= 0) {
+ ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, NULL);
+ }
+ audio_size += ret;
+ pkt.flags |= PKT_FLAG_KEY;
+ break;
+ case CODEC_TYPE_VIDEO:
+ ret = avcodec_encode_video(enc, bit_buffer, bit_buffer_size, NULL);
+ video_size += ret;
+ if(enc->coded_frame && enc->coded_frame->key_frame)
+ pkt.flags |= PKT_FLAG_KEY;
+ if (ost->logfile && enc->stats_out) {
+ fprintf(ost->logfile, "%s", enc->stats_out);
+ }
+ break;
+ default:
+ ret=-1;
+ }
+
+ if(ret<=0)
+ break;
+ pkt.data= bit_buffer;
+ pkt.size= ret;
+ if(enc->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE)
+ pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base);
+ write_frame(os, &pkt, ost->st->codec, bitstream_filters[ost->file_index][pkt.stream_index]);
+ }
+ }
+ }
+ }
+ }
+
+ return 0;
+ fail_decode:
+ return -1;
+}
+
+
+/*
+ * The following code is the main loop of the file converter
+ */
+static int av_encode(AVFormatContext **output_files,
+ int nb_output_files,
+ AVFormatContext **input_files,
+ int nb_input_files,
+ AVStreamMap *stream_maps, int nb_stream_maps)
+{
+ int ret, i, j, k, n, nb_istreams = 0, nb_ostreams = 0;
+ AVFormatContext *is, *os;
+ AVCodecContext *codec, *icodec;
+ AVOutputStream *ost, **ost_table = NULL;
+ AVInputStream *ist, **ist_table = NULL;
+ AVInputFile *file_table;
+ int key;
+
+ file_table= (AVInputFile*) av_mallocz(nb_input_files * sizeof(AVInputFile));
+ if (!file_table)
+ goto fail;
+
+ /* input stream init */
+ j = 0;
+ for(i=0;i<nb_input_files;i++) {
+ is = input_files[i];
+ file_table[i].ist_index = j;
+ file_table[i].nb_streams = is->nb_streams;
+ j += is->nb_streams;
+ }
+ nb_istreams = j;
+
+ ist_table = av_mallocz(nb_istreams * sizeof(AVInputStream *));
+ if (!ist_table)
+ goto fail;
+
+ for(i=0;i<nb_istreams;i++) {
+ ist = av_mallocz(sizeof(AVInputStream));
+ if (!ist)
+ goto fail;
+ ist_table[i] = ist;
+ }
+ j = 0;
+ for(i=0;i<nb_input_files;i++) {
+ is = input_files[i];
+ for(k=0;k<is->nb_streams;k++) {
+ ist = ist_table[j++];
+ ist->st = is->streams[k];
+ ist->file_index = i;
+ ist->index = k;
+ ist->discard = 1; /* the stream is discarded by default
+ (changed later) */
+
+ if (ist->st->codec->rate_emu) {
+ ist->start = av_gettime();
+ ist->frame = 0;
+ }
+ }
+ }
+
+ /* output stream init */
+ nb_ostreams = 0;
+ for(i=0;i<nb_output_files;i++) {
+ os = output_files[i];
+ if (!os->nb_streams) {
+ fprintf(stderr, "Output file does not contain any stream\n");
+ exit(1);
+ }
+ nb_ostreams += os->nb_streams;
+ }
+ if (nb_stream_maps > 0 && nb_stream_maps != nb_ostreams) {
+ fprintf(stderr, "Number of stream maps must match number of output streams\n");
+ exit(1);
+ }
+
+ /* Sanity check the mapping args -- do the input files & streams exist? */
+ for(i=0;i<nb_stream_maps;i++) {
+ int fi = stream_maps[i].file_index;
+ int si = stream_maps[i].stream_index;
+
+ if (fi < 0 || fi > nb_input_files - 1 ||
+ si < 0 || si > file_table[fi].nb_streams - 1) {
+ fprintf(stderr,"Could not find input stream #%d.%d\n", fi, si);
+ exit(1);
+ }
+ fi = stream_maps[i].sync_file_index;
+ si = stream_maps[i].sync_stream_index;
+ if (fi < 0 || fi > nb_input_files - 1 ||
+ si < 0 || si > file_table[fi].nb_streams - 1) {
+ fprintf(stderr,"Could not find sync stream #%d.%d\n", fi, si);
+ exit(1);
+ }
+ }
+
+ ost_table = av_mallocz(sizeof(AVOutputStream *) * nb_ostreams);
+ if (!ost_table)
+ goto fail;
+ for(i=0;i<nb_ostreams;i++) {
+ ost = av_mallocz(sizeof(AVOutputStream));
+ if (!ost)
+ goto fail;
+ ost_table[i] = ost;
+ }
+
+ n = 0;
+ for(k=0;k<nb_output_files;k++) {
+ os = output_files[k];
+ for(i=0;i<os->nb_streams;i++) {
+ int found;
+ ost = ost_table[n++];
+ ost->file_index = k;
+ ost->index = i;
+ ost->st = os->streams[i];
+ if (nb_stream_maps > 0) {
+ ost->source_index = file_table[stream_maps[n-1].file_index].ist_index +
+ stream_maps[n-1].stream_index;
+
+ /* Sanity check that the stream types match */
+ if (ist_table[ost->source_index]->st->codec->codec_type != ost->st->codec->codec_type) {
+ fprintf(stderr, "Codec type mismatch for mapping #%d.%d -> #%d.%d\n",
+ stream_maps[n-1].file_index, stream_maps[n-1].stream_index,
+ ost->file_index, ost->index);
+ exit(1);
+ }
+
+ } else {
+ /* get corresponding input stream index : we select the first one with the right type */
+ found = 0;
+ for(j=0;j<nb_istreams;j++) {
+ ist = ist_table[j];
+ if (ist->discard &&
+ ist->st->codec->codec_type == ost->st->codec->codec_type) {
+ ost->source_index = j;
+ found = 1;
+ break;
+ }
+ }
+
+ if (!found) {
+ /* try again and reuse existing stream */
+ for(j=0;j<nb_istreams;j++) {
+ ist = ist_table[j];
+ if (ist->st->codec->codec_type == ost->st->codec->codec_type) {
+ ost->source_index = j;
+ found = 1;
+ }
+ }
+ if (!found) {
+ fprintf(stderr, "Could not find input stream matching output stream #%d.%d\n",
+ ost->file_index, ost->index);
+ exit(1);
+ }
+ }
+ }
+ ist = ist_table[ost->source_index];
+ ist->discard = 0;
+ ost->sync_ist = (nb_stream_maps > 0) ?
+ ist_table[file_table[stream_maps[n-1].sync_file_index].ist_index +
+ stream_maps[n-1].sync_stream_index] : ist;
+ }
+ }
+
+ /* for each output stream, we compute the right encoding parameters */
+ for(i=0;i<nb_ostreams;i++) {
+ ost = ost_table[i];
+ ist = ist_table[ost->source_index];
+
+ codec = ost->st->codec;
+ icodec = ist->st->codec;
+
+ if (ost->st->stream_copy) {
+ /* if stream_copy is selected, no need to decode or encode */
+ codec->codec_id = icodec->codec_id;
+ codec->codec_type = icodec->codec_type;
+ if(!codec->codec_tag) codec->codec_tag = icodec->codec_tag;
+ codec->bit_rate = icodec->bit_rate;
+ codec->extradata= icodec->extradata;
+ codec->extradata_size= icodec->extradata_size;
+ if(av_q2d(icodec->time_base) > av_q2d(ist->st->time_base) && av_q2d(ist->st->time_base) < 1.0/1000)
+ codec->time_base = icodec->time_base;
+ else
+ codec->time_base = ist->st->time_base;
+ switch(codec->codec_type) {
+ case CODEC_TYPE_AUDIO:
+ codec->sample_rate = icodec->sample_rate;
+ codec->channels = icodec->channels;
+ codec->frame_size = icodec->frame_size;
+ codec->block_align= icodec->block_align;
+ break;
+ case CODEC_TYPE_VIDEO:
+ if(using_vhook) {
+ fprintf(stderr,"-vcodec copy and -vhook are incompatible (frames are not decoded)\n");
+ exit(1);
+ }
+ codec->pix_fmt = icodec->pix_fmt;
+ codec->width = icodec->width;
+ codec->height = icodec->height;
+ codec->has_b_frames = icodec->has_b_frames;
+ break;
+ case CODEC_TYPE_SUBTITLE:
+ break;
+ default:
+ av_abort();
+ }
+ } else {
+ switch(codec->codec_type) {
+ case CODEC_TYPE_AUDIO:
+ if (av_fifo_init(&ost->fifo, 2 * MAX_AUDIO_PACKET_SIZE))
+ goto fail;
+
+ if (codec->channels == icodec->channels &&
+ codec->sample_rate == icodec->sample_rate) {
+ ost->audio_resample = 0;
+ } else {
+ if (codec->channels != icodec->channels &&
+ (icodec->codec_id == CODEC_ID_AC3 ||
+ icodec->codec_id == CODEC_ID_DTS)) {
+ /* Special case for 5:1 AC3 and DTS input */
+ /* and mono or stereo output */
+ /* Request specific number of channels */
+ icodec->channels = codec->channels;
+ if (codec->sample_rate == icodec->sample_rate)
+ ost->audio_resample = 0;
+ else {
+ ost->audio_resample = 1;
+ }
+ } else {
+ ost->audio_resample = 1;
+ }
+ }
+ if(audio_sync_method>1)
+ ost->audio_resample = 1;
+
+ if(ost->audio_resample){
+ ost->resample = audio_resample_init(codec->channels, icodec->channels,
+ codec->sample_rate, icodec->sample_rate);
+ if(!ost->resample){
+ printf("Can't resample. Aborting.\n");
+ av_abort();
+ }
+ }
+ ist->decoding_needed = 1;
+ ost->encoding_needed = 1;
+ break;
+ case CODEC_TYPE_VIDEO:
+ ost->video_crop = ((frame_leftBand + frame_rightBand + frame_topBand + frame_bottomBand) != 0);
+ ost->video_pad = ((frame_padleft + frame_padright + frame_padtop + frame_padbottom) != 0);
+ ost->video_resample = ((codec->width != icodec->width -
+ (frame_leftBand + frame_rightBand) +
+ (frame_padleft + frame_padright)) ||
+ (codec->height != icodec->height -
+ (frame_topBand + frame_bottomBand) +
+ (frame_padtop + frame_padbottom)) ||
+ (codec->pix_fmt != icodec->pix_fmt));
+ if (ost->video_crop) {
+ ost->topBand = frame_topBand;
+ ost->leftBand = frame_leftBand;
+ }
+ if (ost->video_pad) {
+ ost->padtop = frame_padtop;
+ ost->padleft = frame_padleft;
+ ost->padbottom = frame_padbottom;
+ ost->padright = frame_padright;
+ if (!ost->video_resample) {
+ avcodec_get_frame_defaults(&ost->pict_tmp);
+ if( avpicture_alloc( (AVPicture*)&ost->pict_tmp, codec->pix_fmt,
+ codec->width, codec->height ) )
+ goto fail;
+ }
+ }
+ if (ost->video_resample) {
+ avcodec_get_frame_defaults(&ost->pict_tmp);
+ if( avpicture_alloc( (AVPicture*)&ost->pict_tmp, codec->pix_fmt,
+ codec->width, codec->height ) ) {
+ fprintf(stderr, "Cannot allocate temp picture, check pix fmt\n");
+ exit(1);
+ }
+ ost->img_resample_ctx = sws_getContext(
+ icodec->width - (frame_leftBand + frame_rightBand),
+ icodec->height - (frame_topBand + frame_bottomBand),
+ icodec->pix_fmt,
+ codec->width - (frame_padleft + frame_padright),
+ codec->height - (frame_padtop + frame_padbottom),
+ codec->pix_fmt,
+ sws_flags, NULL, NULL, NULL);
+ if (ost->img_resample_ctx == NULL) {
+ fprintf(stderr, "Cannot get resampling context\n");
+ exit(1);
+ }
+ ost->resample_height = icodec->height - (frame_topBand + frame_bottomBand);
+ }
+ ost->encoding_needed = 1;
+ ist->decoding_needed = 1;
+ break;
+ case CODEC_TYPE_SUBTITLE:
+ ost->encoding_needed = 1;
+ ist->decoding_needed = 1;
+ break;
+ default:
+ av_abort();
+ break;
+ }
+ /* two pass mode */
+ if (ost->encoding_needed &&
+ (codec->flags & (CODEC_FLAG_PASS1 | CODEC_FLAG_PASS2))) {
+ char logfilename[1024];
+ FILE *f;
+ int size;
+ char *logbuffer;
+
+ snprintf(logfilename, sizeof(logfilename), "%s-%d.log",
+ pass_logfilename ?
+ pass_logfilename : DEFAULT_PASS_LOGFILENAME, i);
+ if (codec->flags & CODEC_FLAG_PASS1) {
+ f = fopen(logfilename, "w");
+ if (!f) {
+ perror(logfilename);
+ exit(1);
+ }
+ ost->logfile = f;
+ } else {
+ /* read the log file */
+ f = fopen(logfilename, "r");
+ if (!f) {
+ perror(logfilename);
+ exit(1);
+ }
+ fseek(f, 0, SEEK_END);
+ size = ftell(f);
+ fseek(f, 0, SEEK_SET);
+ logbuffer = av_malloc(size + 1);
+ if (!logbuffer) {
+ fprintf(stderr, "Could not allocate log buffer\n");
+ exit(1);
+ }
+ size = fread(logbuffer, 1, size, f);
+ fclose(f);
+ logbuffer[size] = '\0';
+ codec->stats_in = logbuffer;
+ }
+ }
+ }
+ if(codec->codec_type == CODEC_TYPE_VIDEO){
+ int size= codec->width * codec->height;
+ bit_buffer_size= FFMAX(bit_buffer_size, 4*size);
+ }
+ }
+
+ if (!bit_buffer)
+ bit_buffer = av_malloc(bit_buffer_size);
+ if (!bit_buffer)
+ goto fail;
+
+ /* dump the file output parameters - cannot be done before in case
+ of stream copy */
+ for(i=0;i<nb_output_files;i++) {
+ dump_format(output_files[i], i, output_files[i]->filename, 1);
+ }
+
+ /* dump the stream mapping */
+ if (verbose >= 0) {
+ fprintf(stderr, "Stream mapping:\n");
+ for(i=0;i<nb_ostreams;i++) {
+ ost = ost_table[i];
+ fprintf(stderr, " Stream #%d.%d -> #%d.%d",
+ ist_table[ost->source_index]->file_index,
+ ist_table[ost->source_index]->index,
+ ost->file_index,
+ ost->index);
+ if (ost->sync_ist != ist_table[ost->source_index])
+ fprintf(stderr, " [sync #%d.%d]",
+ ost->sync_ist->file_index,
+ ost->sync_ist->index);
+ fprintf(stderr, "\n");
+ }
+ }
+
+ /* open each encoder */
+ for(i=0;i<nb_ostreams;i++) {
+ ost = ost_table[i];
+ if (ost->encoding_needed) {
+ AVCodec *codec;
+ codec = avcodec_find_encoder(ost->st->codec->codec_id);
+ if (!codec) {
+ fprintf(stderr, "Unsupported codec for output stream #%d.%d\n",
+ ost->file_index, ost->index);
+ exit(1);
+ }
+ if (avcodec_open(ost->st->codec, codec) < 0) {
+ fprintf(stderr, "Error while opening codec for output stream #%d.%d - maybe incorrect parameters such as bit_rate, rate, width or height\n",
+ ost->file_index, ost->index);
+ exit(1);
+ }
+ extra_size += ost->st->codec->extradata_size;
+ }
+ }
+
+ /* open each decoder */
+ for(i=0;i<nb_istreams;i++) {
+ ist = ist_table[i];
+ if (ist->decoding_needed) {
+ AVCodec *codec;
+ codec = avcodec_find_decoder(ist->st->codec->codec_id);
+ if (!codec) {
+ fprintf(stderr, "Unsupported codec (id=%d) for input stream #%d.%d\n",
+ ist->st->codec->codec_id, ist->file_index, ist->index);
+ exit(1);
+ }
+ if (avcodec_open(ist->st->codec, codec) < 0) {
+ fprintf(stderr, "Error while opening codec for input stream #%d.%d\n",
+ ist->file_index, ist->index);
+ exit(1);
+ }
+ //if (ist->st->codec->codec_type == CODEC_TYPE_VIDEO)
+ // ist->st->codec->flags |= CODEC_FLAG_REPEAT_FIELD;
+ }
+ }
+
+ /* init pts */
+ for(i=0;i<nb_istreams;i++) {
+ ist = ist_table[i];
+ is = input_files[ist->file_index];
+ ist->pts = 0;
+ ist->next_pts = av_rescale_q(ist->st->start_time, ist->st->time_base, AV_TIME_BASE_Q);
+ if(ist->st->start_time == AV_NOPTS_VALUE)
+ ist->next_pts=0;
+ if(input_files_ts_offset[ist->file_index])
+ ist->next_pts= AV_NOPTS_VALUE;
+ ist->is_start = 1;
+ }
+
+ /* set meta data information from input file if required */
+ for (i=0;i<nb_meta_data_maps;i++) {
+ AVFormatContext *out_file;
+ AVFormatContext *in_file;
+
+ int out_file_index = meta_data_maps[i].out_file;
+ int in_file_index = meta_data_maps[i].in_file;
+ if ( out_file_index < 0 || out_file_index >= nb_output_files ) {
+ fprintf(stderr, "Invalid output file index %d map_meta_data(%d,%d)\n", out_file_index, out_file_index, in_file_index);
+ ret = AVERROR(EINVAL);
+ goto fail;
+ }
+ if ( in_file_index < 0 || in_file_index >= nb_input_files ) {
+ fprintf(stderr, "Invalid input file index %d map_meta_data(%d,%d)\n", in_file_index, out_file_index, in_file_index);
+ ret = AVERROR(EINVAL);
+ goto fail;
+ }
+
+ out_file = output_files[out_file_index];
+ in_file = input_files[in_file_index];
+
+ strcpy(out_file->title, in_file->title);
+ strcpy(out_file->author, in_file->author);
+ strcpy(out_file->copyright, in_file->copyright);
+ strcpy(out_file->comment, in_file->comment);
+ strcpy(out_file->album, in_file->album);
+ out_file->year = in_file->year;
+ out_file->track = in_file->track;
+ strcpy(out_file->genre, in_file->genre);
+ }
+
+ /* open files and write file headers */
+ for(i=0;i<nb_output_files;i++) {
+ os = output_files[i];
+ if (av_write_header(os) < 0) {
+ fprintf(stderr, "Could not write header for output file #%d (incorrect codec parameters ?)\n", i);
+ ret = AVERROR(EINVAL);
+ goto fail;
+ }
+ }
+
+ if ( !using_stdin && verbose >= 0) {
+ fprintf(stderr, "Press [q] to stop encoding\n");
+ url_set_interrupt_cb(decode_interrupt_cb);
+ }
+ term_init();
+
+ key = -1;
+ timer_start = av_gettime();
+
+ for(; received_sigterm == 0;) {
+ int file_index, ist_index;
+ AVPacket pkt;
+ double ipts_min;
+ double opts_min;
+
+ redo:
+ ipts_min= 1e100;
+ opts_min= 1e100;
+ /* if 'q' pressed, exits */
+ if (!using_stdin) {
+ if (q_pressed)
+ break;
+ /* read_key() returns 0 on EOF */
+ key = read_key();
+ if (key == 'q')
+ break;
+ }
+
+ /* select the stream that we must read now by looking at the
+ smallest output pts */
+ file_index = -1;
+ for(i=0;i<nb_ostreams;i++) {
+ double ipts, opts;
+ ost = ost_table[i];
+ os = output_files[ost->file_index];
+ ist = ist_table[ost->source_index];
+ if(ost->st->codec->codec_type == CODEC_TYPE_VIDEO)
+ opts = ost->sync_opts * av_q2d(ost->st->codec->time_base);
+ else
+ opts = ost->st->pts.val * av_q2d(ost->st->time_base);
+ ipts = (double)ist->pts;
+ if (!file_table[ist->file_index].eof_reached){
+ if(ipts < ipts_min) {
+ ipts_min = ipts;
+ if(input_sync ) file_index = ist->file_index;
+ }
+ if(opts < opts_min) {
+ opts_min = opts;
+ if(!input_sync) file_index = ist->file_index;
+ }
+ }
+ if(ost->frame_number >= max_frames[ost->st->codec->codec_type]){
+ file_index= -1;
+ break;
+ }
+ }
+ /* if none, if is finished */
+ if (file_index < 0) {
+ break;
+ }
+
+ /* finish if recording time exhausted */
+ if (recording_time > 0 && opts_min >= (recording_time / 1000000.0))
+ break;
+
+ /* finish if limit size exhausted */
+ if (limit_filesize != 0 && limit_filesize < url_ftell(&output_files[0]->pb))
+ break;
+
+ /* read a frame from it and output it in the fifo */
+ is = input_files[file_index];
+ if (av_read_frame(is, &pkt) < 0) {
+ file_table[file_index].eof_reached = 1;
+ if (opt_shortest) break; else continue; //
+ }
+
+ if (do_pkt_dump) {
+ av_pkt_dump_log(NULL, AV_LOG_DEBUG, &pkt, do_hex_dump);
+ }
+ /* the following test is needed in case new streams appear
+ dynamically in stream : we ignore them */
+ if (pkt.stream_index >= file_table[file_index].nb_streams)
+ goto discard_packet;
+ ist_index = file_table[file_index].ist_index + pkt.stream_index;
+ ist = ist_table[ist_index];
+ if (ist->discard)
+ goto discard_packet;
+
+// fprintf(stderr, "next:%"PRId64" dts:%"PRId64" off:%"PRId64" %d\n", ist->next_pts, pkt.dts, input_files_ts_offset[ist->file_index], ist->st->codec->codec_type);
+ if (pkt.dts != AV_NOPTS_VALUE && ist->next_pts != AV_NOPTS_VALUE) {
+ int64_t delta= av_rescale_q(pkt.dts, ist->st->time_base, AV_TIME_BASE_Q) - ist->next_pts;
+ if(FFABS(delta) > 1LL*dts_delta_threshold*AV_TIME_BASE && !copy_ts){
+ input_files_ts_offset[ist->file_index]-= delta;
+ if (verbose > 2)
+ fprintf(stderr, "timestamp discontinuity %"PRId64", new offset= %"PRId64"\n", delta, input_files_ts_offset[ist->file_index]);
+ for(i=0; i<file_table[file_index].nb_streams; i++){
+ int index= file_table[file_index].ist_index + i;
+ ist_table[index]->next_pts += delta;
+ ist_table[index]->is_start=1;
+ }
+ }
+ }
+
+ //fprintf(stderr,"read #%d.%d size=%d\n", ist->file_index, ist->index, pkt.size);
+ if (output_packet(ist, ist_index, ost_table, nb_ostreams, &pkt) < 0) {
+
+ if (verbose >= 0)
+ fprintf(stderr, "Error while decoding stream #%d.%d\n",
+ ist->file_index, ist->index);
+
+ av_free_packet(&pkt);
+ goto redo;
+ }
+
+ discard_packet:
+ av_free_packet(&pkt);
+
+ /* dump report by using the output first video and audio streams */
+ print_report(output_files, ost_table, nb_ostreams, 0);
+ }
+
+ /* at the end of stream, we must flush the decoder buffers */
+ for(i=0;i<nb_istreams;i++) {
+ ist = ist_table[i];
+ if (ist->decoding_needed) {
+ output_packet(ist, i, ost_table, nb_ostreams, NULL);
+ }
+ }
+
+ term_exit();
+
+ /* write the trailer if needed and close file */
+ for(i=0;i<nb_output_files;i++) {
+ os = output_files[i];
+ av_write_trailer(os);
+ }
+
+ /* dump report by using the first video and audio streams */
+ print_report(output_files, ost_table, nb_ostreams, 1);
+
+ /* close each encoder */
+ for(i=0;i<nb_ostreams;i++) {
+ ost = ost_table[i];
+ if (ost->encoding_needed) {
+ av_freep(&ost->st->codec->stats_in);
+ avcodec_close(ost->st->codec);
+ }
+ }
+
+ /* close each decoder */
+ for(i=0;i<nb_istreams;i++) {
+ ist = ist_table[i];
+ if (ist->decoding_needed) {
+ avcodec_close(ist->st->codec);
+ }
+ }
+
+ /* finished ! */
+
+ ret = 0;
+ fail1:
+ av_freep(&bit_buffer);
+ av_free(file_table);
+
+ if (ist_table) {
+ for(i=0;i<nb_istreams;i++) {
+ ist = ist_table[i];
+ av_free(ist);
+ }
+ av_free(ist_table);
+ }
+ if (ost_table) {
+ for(i=0;i<nb_ostreams;i++) {
+ ost = ost_table[i];
+ if (ost) {
+ if (ost->logfile) {
+ fclose(ost->logfile);
+ ost->logfile = NULL;
+ }
+ av_fifo_free(&ost->fifo); /* works even if fifo is not
+ initialized but set to zero */
+ av_free(ost->pict_tmp.data[0]);
+ if (ost->video_resample)
+ sws_freeContext(ost->img_resample_ctx);
+ if (ost->audio_resample)
+ audio_resample_close(ost->resample);
+ av_free(ost);
+ }
+ }
+ av_free(ost_table);
+ }
+ return ret;
+ fail:
+ ret = AVERROR(ENOMEM);
+ goto fail1;
+}
+
+#if 0
+int file_read(const char *filename)
+{
+ URLContext *h;
+ unsigned char buffer[1024];
+ int len, i;
+
+ if (url_open(&h, filename, O_RDONLY) < 0) {
+ printf("could not open '%s'\n", filename);
+ return -1;
+ }
+ for(;;) {
+ len = url_read(h, buffer, sizeof(buffer));
+ if (len <= 0)
+ break;
+ for(i=0;i<len;i++) putchar(buffer[i]);
+ }
+ url_close(h);
+ return 0;
+}
+#endif
+
+static void opt_format(const char *arg)
+{
+ /* compatibility stuff for pgmyuv */
+ if (!strcmp(arg, "pgmyuv")) {
+ pgmyuv_compatibility_hack=1;
+// opt_image_format(arg);
+ arg = "image2";
+ fprintf(stderr, "pgmyuv format is deprecated, use image2\n");
+ }
+
+ file_iformat = av_find_input_format(arg);
+ file_oformat = guess_format(arg, NULL, NULL);
+ if (!file_iformat && !file_oformat) {
+ fprintf(stderr, "Unknown input or output format: %s\n", arg);
+ exit(1);
+ }
+}
+
+static void opt_video_rc_eq(char *arg)
+{
+ video_rc_eq = arg;
+}
+
+static void opt_video_rc_override_string(char *arg)
+{
+ video_rc_override_string = arg;
+}
+
+static void opt_me_threshold(const char *arg)
+{
+ me_threshold = atoi(arg);
+}
+
+static void opt_verbose(const char *arg)
+{
+ verbose = atoi(arg);
+ av_log_level = atoi(arg);
+}
+
+static void opt_frame_rate(const char *arg)
+{
+ if (parse_frame_rate(&frame_rate, &frame_rate_base, arg) < 0) {
+ fprintf(stderr, "Incorrect frame rate\n");
+ exit(1);
+ }
+}
+
+static void opt_frame_crop_top(const char *arg)
+{
+ frame_topBand = atoi(arg);
+ if (frame_topBand < 0) {
+ fprintf(stderr, "Incorrect top crop size\n");
+ exit(1);
+ }
+ if ((frame_topBand % 2) != 0) {
+ fprintf(stderr, "Top crop size must be a multiple of 2\n");
+ exit(1);
+ }
+ if ((frame_topBand) >= frame_height){
+ fprintf(stderr, "Vertical crop dimensions are outside the range of the original image.\nRemember to crop first and scale second.\n");
+ exit(1);
+ }
+ frame_height -= frame_topBand;
+}
+
+static void opt_frame_crop_bottom(const char *arg)
+{
+ frame_bottomBand = atoi(arg);
+ if (frame_bottomBand < 0) {
+ fprintf(stderr, "Incorrect bottom crop size\n");
+ exit(1);
+ }
+ if ((frame_bottomBand % 2) != 0) {
+ fprintf(stderr, "Bottom crop size must be a multiple of 2\n");
+ exit(1);
+ }
+ if ((frame_bottomBand) >= frame_height){
+ fprintf(stderr, "Vertical crop dimensions are outside the range of the original image.\nRemember to crop first and scale second.\n");
+ exit(1);
+ }
+ frame_height -= frame_bottomBand;
+}
+
+static void opt_frame_crop_left(const char *arg)
+{
+ frame_leftBand = atoi(arg);
+ if (frame_leftBand < 0) {
+ fprintf(stderr, "Incorrect left crop size\n");
+ exit(1);
+ }
+ if ((frame_leftBand % 2) != 0) {
+ fprintf(stderr, "Left crop size must be a multiple of 2\n");
+ exit(1);
+ }
+ if ((frame_leftBand) >= frame_width){
+ fprintf(stderr, "Horizontal crop dimensions are outside the range of the original image.\nRemember to crop first and scale second.\n");
+ exit(1);
+ }
+ frame_width -= frame_leftBand;
+}
+
+static void opt_frame_crop_right(const char *arg)
+{
+ frame_rightBand = atoi(arg);
+ if (frame_rightBand < 0) {
+ fprintf(stderr, "Incorrect right crop size\n");
+ exit(1);
+ }
+ if ((frame_rightBand % 2) != 0) {
+ fprintf(stderr, "Right crop size must be a multiple of 2\n");
+ exit(1);
+ }
+ if ((frame_rightBand) >= frame_width){
+ fprintf(stderr, "Horizontal crop dimensions are outside the range of the original image.\nRemember to crop first and scale second.\n");
+ exit(1);
+ }
+ frame_width -= frame_rightBand;
+}
+
+static void opt_frame_size(const char *arg)
+{
+ if (parse_image_size(&frame_width, &frame_height, arg) < 0) {
+ fprintf(stderr, "Incorrect frame size\n");
+ exit(1);
+ }
+ if ((frame_width % 2) != 0 || (frame_height % 2) != 0) {
+ fprintf(stderr, "Frame size must be a multiple of 2\n");
+ exit(1);
+ }
+}
+
+
+#define SCALEBITS 10
+#define ONE_HALF (1 << (SCALEBITS - 1))
+#define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5))
+
+#define RGB_TO_Y(r, g, b) \
+((FIX(0.29900) * (r) + FIX(0.58700) * (g) + \
+ FIX(0.11400) * (b) + ONE_HALF) >> SCALEBITS)
+
+#define RGB_TO_U(r1, g1, b1, shift)\
+(((- FIX(0.16874) * r1 - FIX(0.33126) * g1 + \
+ FIX(0.50000) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
+
+#define RGB_TO_V(r1, g1, b1, shift)\
+(((FIX(0.50000) * r1 - FIX(0.41869) * g1 - \
+ FIX(0.08131) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
+
+static void opt_pad_color(const char *arg) {
+ /* Input is expected to be six hex digits similar to
+ how colors are expressed in html tags (but without the #) */
+ int rgb = strtol(arg, NULL, 16);
+ int r,g,b;
+
+ r = (rgb >> 16);
+ g = ((rgb >> 8) & 255);
+ b = (rgb & 255);
+
+ padcolor[0] = RGB_TO_Y(r,g,b);
+ padcolor[1] = RGB_TO_U(r,g,b,0);
+ padcolor[2] = RGB_TO_V(r,g,b,0);
+}
+
+static void opt_frame_pad_top(const char *arg)
+{
+ frame_padtop = atoi(arg);
+ if (frame_padtop < 0) {
+ fprintf(stderr, "Incorrect top pad size\n");
+ exit(1);
+ }
+ if ((frame_padtop % 2) != 0) {
+ fprintf(stderr, "Top pad size must be a multiple of 2\n");
+ exit(1);
+ }
+}
+
+static void opt_frame_pad_bottom(const char *arg)
+{
+ frame_padbottom = atoi(arg);
+ if (frame_padbottom < 0) {
+ fprintf(stderr, "Incorrect bottom pad size\n");
+ exit(1);
+ }
+ if ((frame_padbottom % 2) != 0) {
+ fprintf(stderr, "Bottom pad size must be a multiple of 2\n");
+ exit(1);
+ }
+}
+
+
+static void opt_frame_pad_left(const char *arg)
+{
+ frame_padleft = atoi(arg);
+ if (frame_padleft < 0) {
+ fprintf(stderr, "Incorrect left pad size\n");
+ exit(1);
+ }
+ if ((frame_padleft % 2) != 0) {
+ fprintf(stderr, "Left pad size must be a multiple of 2\n");
+ exit(1);
+ }
+}
+
+
+static void opt_frame_pad_right(const char *arg)
+{
+ frame_padright = atoi(arg);
+ if (frame_padright < 0) {
+ fprintf(stderr, "Incorrect right pad size\n");
+ exit(1);
+ }
+ if ((frame_padright % 2) != 0) {
+ fprintf(stderr, "Right pad size must be a multiple of 2\n");
+ exit(1);
+ }
+}
+
+
+static void opt_frame_pix_fmt(const char *arg)
+{
+ frame_pix_fmt = avcodec_get_pix_fmt(arg);
+}
+
+static void opt_frame_aspect_ratio(const char *arg)
+{
+ int x = 0, y = 0;
+ double ar = 0;
+ const char *p;
+
+ p = strchr(arg, ':');
+ if (p) {
+ x = strtol(arg, (char **)&arg, 10);
+ if (arg == p)
+ y = strtol(arg+1, (char **)&arg, 10);
+ if (x > 0 && y > 0)
+ ar = (double)x / (double)y;
+ } else
+ ar = strtod(arg, (char **)&arg);
+
+ if (!ar) {
+ fprintf(stderr, "Incorrect aspect ratio specification.\n");
+ exit(1);
+ }
+ frame_aspect_ratio = ar;
+}
+
+static void opt_qscale(const char *arg)
+{
+ video_qscale = atof(arg);
+ if (video_qscale <= 0 ||
+ video_qscale > 255) {
+ fprintf(stderr, "qscale must be > 0.0 and <= 255\n");
+ exit(1);
+ }
+}
+
+static void opt_qdiff(const char *arg)
+{
+ video_qdiff = atoi(arg);
+ if (video_qdiff < 0 ||
+ video_qdiff > 31) {
+ fprintf(stderr, "qdiff must be >= 1 and <= 31\n");
+ exit(1);
+ }
+}
+
+static void opt_strict(const char *arg)
+{
+ strict= atoi(arg);
+}
+
+static void opt_top_field_first(const char *arg)
+{
+ top_field_first= atoi(arg);
+}
+
+static void opt_thread_count(const char *arg)
+{
+ thread_count= atoi(arg);
+#if !defined(HAVE_THREADS)
+ if (verbose >= 0)
+ fprintf(stderr, "Warning: not compiled with thread support, using thread emulation\n");
+#endif
+}
+
+static void opt_audio_rate(const char *arg)
+{
+ audio_sample_rate = atoi(arg);
+}
+
+static void opt_audio_channels(const char *arg)
+{
+ audio_channels = atoi(arg);
+}
+
+static void opt_video_channel(const char *arg)
+{
+ video_channel = strtol(arg, NULL, 0);
+}
+
+static void opt_video_standard(const char *arg)
+{
+ video_standard = av_strdup(arg);
+}
+
+static void opt_codec(int *pstream_copy, int *pcodec_id,
+ int codec_type, const char *arg)
+{
+ AVCodec *p;
+
+ if (!strcmp(arg, "copy")) {
+ *pstream_copy = 1;
+ } else {
+ p = first_avcodec;
+ while (p) {
+ if (!strcmp(p->name, arg) && p->type == codec_type)
+ break;
+ p = p->next;
+ }
+ if (p == NULL) {
+ fprintf(stderr, "Unknown codec '%s'\n", arg);
+ exit(1);
+ } else {
+ *pcodec_id = p->id;
+ }
+ }
+}
+
+static void opt_audio_codec(const char *arg)
+{
+ opt_codec(&audio_stream_copy, &audio_codec_id, CODEC_TYPE_AUDIO, arg);
+}
+
+static void opt_audio_tag(const char *arg)
+{
+ char *tail;
+ audio_codec_tag= strtol(arg, &tail, 0);
+
+ if(!tail || *tail)
+ audio_codec_tag= arg[0] + (arg[1]<<8) + (arg[2]<<16) + (arg[3]<<24);
+}
+
+static void opt_video_tag(const char *arg)
+{
+ char *tail;
+ video_codec_tag= strtol(arg, &tail, 0);
+
+ if(!tail || *tail)
+ video_codec_tag= arg[0] + (arg[1]<<8) + (arg[2]<<16) + (arg[3]<<24);
+}
+
+static void add_frame_hooker(const char *arg)
+{
+ int argc = 0;
+ char *argv[64];
+ int i;
+ char *args = av_strdup(arg);
+
+ using_vhook = 1;
+
+ argv[0] = strtok(args, " ");
+ while (argc < 62 && (argv[++argc] = strtok(NULL, " "))) {
+ }
+
+ i = frame_hook_add(argc, argv);
+
+ if (i != 0) {
+ fprintf(stderr, "Failed to add video hook function: %s\n", arg);
+ exit(1);
+ }
+}
+
+const char *motion_str[] = {
+ "zero",
+ "full",
+ "log",
+ "phods",
+ "epzs",
+ "x1",
+ "hex",
+ "umh",
+ "iter",
+ NULL,
+};
+
+static void opt_motion_estimation(const char *arg)
+{
+ const char **p;
+ p = motion_str;
+ for(;;) {
+ if (!*p) {
+ fprintf(stderr, "Unknown motion estimation method '%s'\n", arg);
+ exit(1);
+ }
+ if (!strcmp(*p, arg))
+ break;
+ p++;
+ }
+ me_method = (p - motion_str) + 1;
+}
+
+static void opt_video_codec(const char *arg)
+{
+ opt_codec(&video_stream_copy, &video_codec_id, CODEC_TYPE_VIDEO, arg);
+}
+
+static void opt_subtitle_codec(const char *arg)
+{
+ opt_codec(&subtitle_stream_copy, &subtitle_codec_id, CODEC_TYPE_SUBTITLE, arg);
+}
+
+static void opt_map(const char *arg)
+{
+ AVStreamMap *m;
+ const char *p;
+
+ p = arg;
+ m = &stream_maps[nb_stream_maps++];
+
+ m->file_index = strtol(arg, (char **)&p, 0);
+ if (*p)
+ p++;
+
+ m->stream_index = strtol(p, (char **)&p, 0);
+ if (*p) {
+ p++;
+ m->sync_file_index = strtol(p, (char **)&p, 0);
+ if (*p)
+ p++;
+ m->sync_stream_index = strtol(p, (char **)&p, 0);
+ } else {
+ m->sync_file_index = m->file_index;
+ m->sync_stream_index = m->stream_index;
+ }
+}
+
+static void opt_map_meta_data(const char *arg)
+{
+ AVMetaDataMap *m;
+ const char *p;
+
+ p = arg;
+ m = &meta_data_maps[nb_meta_data_maps++];
+
+ m->out_file = strtol(arg, (char **)&p, 0);
+ if (*p)
+ p++;
+
+ m->in_file = strtol(p, (char **)&p, 0);
+}
+
+static void opt_recording_time(const char *arg)
+{
+ recording_time = parse_date(arg, 1);
+}
+
+static void opt_start_time(const char *arg)
+{
+ start_time = parse_date(arg, 1);
+}
+
+static void opt_rec_timestamp(const char *arg)
+{
+ rec_timestamp = parse_date(arg, 0) / 1000000;
+}
+
+static void opt_input_ts_offset(const char *arg)
+{
+ input_ts_offset = parse_date(arg, 1);
+}
+
+static void opt_input_file(const char *filename)
+{
+ AVFormatContext *ic;
+ AVFormatParameters params, *ap = &params;
+ int err, i, ret, rfps, rfps_base;
+ int64_t timestamp;
+
+ if (!strcmp(filename, "-"))
+ filename = "pipe:";
+
+ using_stdin |= !strncmp(filename, "pipe:", 5) ||
+ !strcmp( filename, "/dev/stdin" );
+
+ /* get default parameters from command line */
+ ic = av_alloc_format_context();
+
+ memset(ap, 0, sizeof(*ap));
+ ap->prealloced_context = 1;
+ ap->sample_rate = audio_sample_rate;
+ ap->channels = audio_channels;
+ ap->time_base.den = frame_rate;
+ ap->time_base.num = frame_rate_base;
+ ap->width = frame_width + frame_padleft + frame_padright;
+ ap->height = frame_height + frame_padtop + frame_padbottom;
+ ap->pix_fmt = frame_pix_fmt;
+ ap->channel = video_channel;
+ ap->standard = video_standard;
+ ap->video_codec_id = video_codec_id;
+ ap->audio_codec_id = audio_codec_id;
+ if(pgmyuv_compatibility_hack)
+ ap->video_codec_id= CODEC_ID_PGMYUV;
+
+ for(i=0; i<opt_name_count; i++){
+ const AVOption *opt;
+ double d= av_get_double(avformat_opts, opt_names[i], &opt);
+ if(d==d && (opt->flags&AV_OPT_FLAG_DECODING_PARAM))
+ av_set_double(ic, opt_names[i], d);
+ }
+ /* open the input file with generic libav function */
+ err = av_open_input_file(&ic, filename, file_iformat, 0, ap);
+ if (err < 0) {
+ print_error(filename, err);
+ exit(1);
+ }
+
+ ic->loop_input = loop_input;
+
+ /* If not enough info to get the stream parameters, we decode the
+ first frames to get it. (used in mpeg case for example) */
+ ret = av_find_stream_info(ic);
+ if (ret < 0 && verbose >= 0) {
+ fprintf(stderr, "%s: could not find codec parameters\n", filename);
+ exit(1);
+ }
+
+ timestamp = start_time;
+ /* add the stream start time */
+ if (ic->start_time != AV_NOPTS_VALUE)
+ timestamp += ic->start_time;
+
+ /* if seeking requested, we execute it */
+ if (start_time != 0) {
+ ret = av_seek_frame(ic, -1, timestamp, AVSEEK_FLAG_BACKWARD);
+ if (ret < 0) {
+ fprintf(stderr, "%s: could not seek to position %0.3f\n",
+ filename, (double)timestamp / AV_TIME_BASE);
+ }
+ /* reset seek info */
+ start_time = 0;
+ }
+
+ /* update the current parameters so that they match the one of the input stream */
+ for(i=0;i<ic->nb_streams;i++) {
+ int j;
+ AVCodecContext *enc = ic->streams[i]->codec;
+ if(thread_count>1)
+ avcodec_thread_init(enc, thread_count);
+ enc->thread_count= thread_count;
+ switch(enc->codec_type) {
+ case CODEC_TYPE_AUDIO:
+ for(j=0; j<opt_name_count; j++){
+ const AVOption *opt;
+ double d= av_get_double(avctx_opts[CODEC_TYPE_AUDIO], opt_names[j], &opt);
+ if(d==d && (opt->flags&AV_OPT_FLAG_AUDIO_PARAM) && (opt->flags&AV_OPT_FLAG_DECODING_PARAM))
+ av_set_double(enc, opt_names[j], d);
+ }
+ //fprintf(stderr, "\nInput Audio channels: %d", enc->channels);
+ audio_channels = enc->channels;
+ audio_sample_rate = enc->sample_rate;
+ if(audio_disable)
+ ic->streams[i]->discard= AVDISCARD_ALL;
+ break;
+ case CODEC_TYPE_VIDEO:
+ for(j=0; j<opt_name_count; j++){
+ const AVOption *opt;
+ double d= av_get_double(avctx_opts[CODEC_TYPE_VIDEO], opt_names[j], &opt);
+ if(d==d && (opt->flags&AV_OPT_FLAG_VIDEO_PARAM) && (opt->flags&AV_OPT_FLAG_DECODING_PARAM))
+ av_set_double(enc, opt_names[j], d);
+ }
+ frame_height = enc->height;
+ frame_width = enc->width;
+ frame_aspect_ratio = av_q2d(enc->sample_aspect_ratio) * enc->width / enc->height;
+ frame_pix_fmt = enc->pix_fmt;
+ rfps = ic->streams[i]->r_frame_rate.num;
+ rfps_base = ic->streams[i]->r_frame_rate.den;
+ if(enc->lowres) enc->flags |= CODEC_FLAG_EMU_EDGE;
+ if(me_threshold)
+ enc->debug |= FF_DEBUG_MV;
+
+ if (enc->time_base.den != rfps || enc->time_base.num != rfps_base) {
+
+ if (verbose >= 0)
+ fprintf(stderr,"\nSeems stream %d codec frame rate differs from container frame rate: %2.2f (%d/%d) -> %2.2f (%d/%d)\n",
+ i, (float)enc->time_base.den / enc->time_base.num, enc->time_base.den, enc->time_base.num,
+
+ (float)rfps / rfps_base, rfps, rfps_base);
+ }
+ /* update the current frame rate to match the stream frame rate */
+ frame_rate = rfps;
+ frame_rate_base = rfps_base;
+
+ enc->rate_emu = rate_emu;
+ if(video_disable)
+ ic->streams[i]->discard= AVDISCARD_ALL;
+ else if(video_discard)
+ ic->streams[i]->discard= video_discard;
+ break;
+ case CODEC_TYPE_DATA:
+ break;
+ case CODEC_TYPE_SUBTITLE:
+ break;
+ case CODEC_TYPE_UNKNOWN:
+ break;
+ default:
+ av_abort();
+ }
+ }
+
+ input_files[nb_input_files] = ic;
+ input_files_ts_offset[nb_input_files] = input_ts_offset - (copy_ts ? 0 : timestamp);
+ /* dump the file content */
+ if (verbose >= 0)
+ dump_format(ic, nb_input_files, filename, 0);
+
+ nb_input_files++;
+ file_iformat = NULL;
+ file_oformat = NULL;
+
+ video_channel = 0;
+
+ rate_emu = 0;
+}
+
+static void check_audio_video_inputs(int *has_video_ptr, int *has_audio_ptr)
+{
+ int has_video, has_audio, i, j;
+ AVFormatContext *ic;
+
+ has_video = 0;
+ has_audio = 0;
+ for(j=0;j<nb_input_files;j++) {
+ ic = input_files[j];
+ for(i=0;i<ic->nb_streams;i++) {
+ AVCodecContext *enc = ic->streams[i]->codec;
+ switch(enc->codec_type) {
+ case CODEC_TYPE_AUDIO:
+ has_audio = 1;
+ break;
+ case CODEC_TYPE_VIDEO:
+ has_video = 1;
+ break;
+ case CODEC_TYPE_DATA:
+ case CODEC_TYPE_UNKNOWN:
+ case CODEC_TYPE_SUBTITLE:
+ break;
+ default:
+ av_abort();
+ }
+ }
+ }
+ *has_video_ptr = has_video;
+ *has_audio_ptr = has_audio;
+}
+
+static void new_video_stream(AVFormatContext *oc)
+{
+ AVStream *st;
+ AVCodecContext *video_enc;
+ int codec_id;
+
+ st = av_new_stream(oc, oc->nb_streams);
+ if (!st) {
+ fprintf(stderr, "Could not alloc stream\n");
+ exit(1);
+ }
+ avcodec_get_context_defaults2(st->codec, CODEC_TYPE_VIDEO);
+ bitstream_filters[nb_output_files][oc->nb_streams - 1]= video_bitstream_filters;
+ video_bitstream_filters= NULL;
+
+ if(thread_count>1)
+ avcodec_thread_init(st->codec, thread_count);
+
+ video_enc = st->codec;
+
+ if(video_codec_tag)
+ video_enc->codec_tag= video_codec_tag;
+
+ if( (video_global_header&1)
+ || (video_global_header==0 && (oc->oformat->flags & AVFMT_GLOBALHEADER))){
+ video_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;
+ avctx_opts[CODEC_TYPE_VIDEO]->flags|= CODEC_FLAG_GLOBAL_HEADER;
+ }
+ if(video_global_header&2){
+ video_enc->flags2 |= CODEC_FLAG2_LOCAL_HEADER;
+ avctx_opts[CODEC_TYPE_VIDEO]->flags2|= CODEC_FLAG2_LOCAL_HEADER;
+ }
+
+ if (video_stream_copy) {
+ st->stream_copy = 1;
+ video_enc->codec_type = CODEC_TYPE_VIDEO;
+ } else {
+ char *p;
+ int i;
+ AVCodec *codec;
+
+ codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_VIDEO);
+ if (video_codec_id != CODEC_ID_NONE)
+ codec_id = video_codec_id;
+
+ video_enc->codec_id = codec_id;
+ codec = avcodec_find_encoder(codec_id);
+
+ for(i=0; i<opt_name_count; i++){
+ const AVOption *opt;
+ double d= av_get_double(avctx_opts[CODEC_TYPE_VIDEO], opt_names[i], &opt);
+ if(d==d && (opt->flags&AV_OPT_FLAG_VIDEO_PARAM) && (opt->flags&AV_OPT_FLAG_ENCODING_PARAM))
+ av_set_double(video_enc, opt_names[i], d);
+ }
+
+ video_enc->time_base.den = frame_rate;
+ video_enc->time_base.num = frame_rate_base;
+ if(codec && codec->supported_framerates){
+ const AVRational *p= codec->supported_framerates;
+ AVRational req= (AVRational){frame_rate, frame_rate_base};
+ const AVRational *best=NULL;
+ AVRational best_error= (AVRational){INT_MAX, 1};
+ for(; p->den!=0; p++){
+ AVRational error= av_sub_q(req, *p);
+ if(error.num <0) error.num *= -1;
+ if(av_cmp_q(error, best_error) < 0){
+ best_error= error;
+ best= p;
+ }
+ }
+ video_enc->time_base.den= best->num;
+ video_enc->time_base.num= best->den;
+ }
+
+ video_enc->width = frame_width + frame_padright + frame_padleft;
+ video_enc->height = frame_height + frame_padtop + frame_padbottom;
+ video_enc->sample_aspect_ratio = av_d2q(frame_aspect_ratio*video_enc->height/video_enc->width, 255);
+ video_enc->pix_fmt = frame_pix_fmt;
+
+ if(codec && codec->pix_fmts){
+ const enum PixelFormat *p= codec->pix_fmts;
+ for(; *p!=-1; p++){
+ if(*p == video_enc->pix_fmt)
+ break;
+ }
+ if(*p == -1)
+ video_enc->pix_fmt = codec->pix_fmts[0];
+ }
+
+ if (intra_only)
+ video_enc->gop_size = 0;
+ if (video_qscale || same_quality) {
+ video_enc->flags |= CODEC_FLAG_QSCALE;
+ video_enc->global_quality=
+ st->quality = FF_QP2LAMBDA * video_qscale;
+ }
+
+ if(intra_matrix)
+ video_enc->intra_matrix = intra_matrix;
+ if(inter_matrix)
+ video_enc->inter_matrix = inter_matrix;
+
+ video_enc->max_qdiff = video_qdiff;
+ video_enc->rc_eq = video_rc_eq;
+ video_enc->thread_count = thread_count;
+ p= video_rc_override_string;
+ for(i=0; p; i++){
+ int start, end, q;
+ int e=sscanf(p, "%d,%d,%d", &start, &end, &q);
+ if(e!=3){
+ fprintf(stderr, "error parsing rc_override\n");
+ exit(1);
+ }
+ video_enc->rc_override=
+ av_realloc(video_enc->rc_override,
+ sizeof(RcOverride)*(i+1));
+ video_enc->rc_override[i].start_frame= start;
+ video_enc->rc_override[i].end_frame = end;
+ if(q>0){
+ video_enc->rc_override[i].qscale= q;
+ video_enc->rc_override[i].quality_factor= 1.0;
+ }
+ else{
+ video_enc->rc_override[i].qscale= 0;
+ video_enc->rc_override[i].quality_factor= -q/100.0;
+ }
+ p= strchr(p, '/');
+ if(p) p++;
+ }
+ video_enc->rc_override_count=i;
+ if (!video_enc->rc_initial_buffer_occupancy)
+ video_enc->rc_initial_buffer_occupancy = video_enc->rc_buffer_size*3/4;
+ video_enc->me_threshold= me_threshold;
+ video_enc->intra_dc_precision= intra_dc_precision - 8;
+ video_enc->strict_std_compliance = strict;
+
+ if (do_psnr)
+ video_enc->flags|= CODEC_FLAG_PSNR;
+
+ video_enc->me_method = me_method;
+
+ /* two pass mode */
+ if (do_pass) {
+ if (do_pass == 1) {
+ video_enc->flags |= CODEC_FLAG_PASS1;
+ } else {
+ video_enc->flags |= CODEC_FLAG_PASS2;
+ }
+ }
+ }
+
+ /* reset some key parameters */
+ video_disable = 0;
+ video_codec_id = CODEC_ID_NONE;
+ video_stream_copy = 0;
+}
+
+static void new_audio_stream(AVFormatContext *oc)
+{
+ AVStream *st;
+ AVCodecContext *audio_enc;
+ int codec_id, i;
+
+ st = av_new_stream(oc, oc->nb_streams);
+ if (!st) {
+ fprintf(stderr, "Could not alloc stream\n");
+ exit(1);
+ }
+ avcodec_get_context_defaults2(st->codec, CODEC_TYPE_AUDIO);
+
+ bitstream_filters[nb_output_files][oc->nb_streams - 1]= audio_bitstream_filters;
+ audio_bitstream_filters= NULL;
+
+ if(thread_count>1)
+ avcodec_thread_init(st->codec, thread_count);
+
+ audio_enc = st->codec;
+ audio_enc->codec_type = CODEC_TYPE_AUDIO;
+ audio_enc->strict_std_compliance = strict;
+
+ if(audio_codec_tag)
+ audio_enc->codec_tag= audio_codec_tag;
+
+ if (oc->oformat->flags & AVFMT_GLOBALHEADER) {
+ audio_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;
+ avctx_opts[CODEC_TYPE_AUDIO]->flags|= CODEC_FLAG_GLOBAL_HEADER;
+ }
+ if (audio_stream_copy) {
+ st->stream_copy = 1;
+ audio_enc->channels = audio_channels;
+ } else {
+ codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_AUDIO);
+
+ for(i=0; i<opt_name_count; i++){
+ const AVOption *opt;
+ double d= av_get_double(avctx_opts[CODEC_TYPE_AUDIO], opt_names[i], &opt);
+ if(d==d && (opt->flags&AV_OPT_FLAG_AUDIO_PARAM) && (opt->flags&AV_OPT_FLAG_ENCODING_PARAM))
+ av_set_double(audio_enc, opt_names[i], d);
+ }
+
+ if (audio_codec_id != CODEC_ID_NONE)
+ codec_id = audio_codec_id;
+ audio_enc->codec_id = codec_id;
+
+ if (audio_qscale > QSCALE_NONE) {
+ audio_enc->flags |= CODEC_FLAG_QSCALE;
+ audio_enc->global_quality = st->quality = FF_QP2LAMBDA * audio_qscale;
+ }
+ audio_enc->thread_count = thread_count;
+ audio_enc->channels = audio_channels;
+ }
+ audio_enc->sample_rate = audio_sample_rate;
+ audio_enc->time_base= (AVRational){1, audio_sample_rate};
+ if (audio_language) {
+ pstrcpy(st->language, sizeof(st->language), audio_language);
+ av_free(audio_language);
+ audio_language = NULL;
+ }
+
+ /* reset some key parameters */
+ audio_disable = 0;
+ audio_codec_id = CODEC_ID_NONE;
+ audio_stream_copy = 0;
+}
+
+static void opt_new_subtitle_stream(void)
+{
+ AVFormatContext *oc;
+ AVStream *st;
+ AVCodecContext *subtitle_enc;
+ int i;
+
+ if (nb_output_files <= 0) {
+ fprintf(stderr, "At least one output file must be specified\n");
+ exit(1);
+ }
+ oc = output_files[nb_output_files - 1];
+
+ st = av_new_stream(oc, oc->nb_streams);
+ if (!st) {
+ fprintf(stderr, "Could not alloc stream\n");
+ exit(1);
+ }
+ avcodec_get_context_defaults2(st->codec, CODEC_TYPE_SUBTITLE);
+
+ subtitle_enc = st->codec;
+ subtitle_enc->codec_type = CODEC_TYPE_SUBTITLE;
+ if (subtitle_stream_copy) {
+ st->stream_copy = 1;
+ } else {
+ for(i=0; i<opt_name_count; i++){
+ const AVOption *opt;
+ double d= av_get_double(avctx_opts[CODEC_TYPE_SUBTITLE], opt_names[i], &opt);
+ if(d==d && (opt->flags&AV_OPT_FLAG_SUBTITLE_PARAM) && (opt->flags&AV_OPT_FLAG_ENCODING_PARAM))
+ av_set_double(subtitle_enc, opt_names[i], d);
+ }
+ subtitle_enc->codec_id = subtitle_codec_id;
+ }
+
+ if (subtitle_language) {
+ pstrcpy(st->language, sizeof(st->language), subtitle_language);
+ av_free(subtitle_language);
+ subtitle_language = NULL;
+ }
+
+ subtitle_codec_id = CODEC_ID_NONE;
+ subtitle_stream_copy = 0;
+}
+
+static void opt_new_audio_stream(void)
+{
+ AVFormatContext *oc;
+ if (nb_output_files <= 0) {
+ fprintf(stderr, "At least one output file must be specified\n");
+ exit(1);
+ }
+ oc = output_files[nb_output_files - 1];
+ new_audio_stream(oc);
+}
+
+static void opt_new_video_stream(void)
+{
+ AVFormatContext *oc;
+ if (nb_output_files <= 0) {
+ fprintf(stderr, "At least one output file must be specified\n");
+ exit(1);
+ }
+ oc = output_files[nb_output_files - 1];
+ new_video_stream(oc);
+}
+
+static void opt_output_file(const char *filename)
+{
+ AVFormatContext *oc;
+ int use_video, use_audio, input_has_video, input_has_audio, i;
+ AVFormatParameters params, *ap = &params;
+
+ if (!strcmp(filename, "-"))
+ filename = "pipe:";
+
+ oc = av_alloc_format_context();
+
+ if (!file_oformat) {
+ file_oformat = guess_format(NULL, filename, NULL);
+ if (!file_oformat) {
+ fprintf(stderr, "Unable for find a suitable output format for '%s'\n",
+ filename);
+ exit(1);
+ }
+ }
+
+ oc->oformat = file_oformat;
+ pstrcpy(oc->filename, sizeof(oc->filename), filename);
+
+ if (!strcmp(file_oformat->name, "ffm") &&
+ strstart(filename, "http:", NULL)) {
+ /* special case for files sent to ffserver: we get the stream
+ parameters from ffserver */
+ if (read_ffserver_streams(oc, filename) < 0) {
+ fprintf(stderr, "Could not read stream parameters from '%s'\n", filename);
+ exit(1);
+ }
+ } else {
+ use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_id != CODEC_ID_NONE;
+ use_audio = file_oformat->audio_codec != CODEC_ID_NONE || audio_stream_copy || audio_codec_id != CODEC_ID_NONE;
+
+ /* disable if no corresponding type found and at least one
+ input file */
+ if (nb_input_files > 0) {
+ check_audio_video_inputs(&input_has_video, &input_has_audio);
+ if (!input_has_video)
+ use_video = 0;
+ if (!input_has_audio)
+ use_audio = 0;
+ }
+
+ /* manual disable */
+ if (audio_disable) {
+ use_audio = 0;
+ }
+ if (video_disable) {
+ use_video = 0;
+ }
+
+ if (use_video) {
+ new_video_stream(oc);
+ }
+
+ if (use_audio) {
+ new_audio_stream(oc);
+ }
+
+ oc->timestamp = rec_timestamp;
+
+ if (str_title)
+ pstrcpy(oc->title, sizeof(oc->title), str_title);
+ if (str_author)
+ pstrcpy(oc->author, sizeof(oc->author), str_author);
+ if (str_copyright)
+ pstrcpy(oc->copyright, sizeof(oc->copyright), str_copyright);
+ if (str_comment)
+ pstrcpy(oc->comment, sizeof(oc->comment), str_comment);
+ if (str_album)
+ pstrcpy(oc->album, sizeof(oc->album), str_album);
+ }
+
+ output_files[nb_output_files++] = oc;
+
+ /* check filename in case of an image number is expected */
+ if (oc->oformat->flags & AVFMT_NEEDNUMBER) {
+ if (!av_filename_number_test(oc->filename)) {
+ print_error(oc->filename, AVERROR_NUMEXPECTED);
+ exit(1);
+ }
+ }
+
+ if (!(oc->oformat->flags & AVFMT_NOFILE)) {
+ /* test if it already exists to avoid loosing precious files */
+ if (!file_overwrite &&
+ (strchr(filename, ':') == NULL ||
+ strstart(filename, "file:", NULL))) {
+ if (url_exist(filename)) {
+ int c;
+
+ if ( !using_stdin ) {
+ fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename);
+ fflush(stderr);
+ c = getchar();
+ if (toupper(c) != 'Y') {
+ fprintf(stderr, "Not overwriting - exiting\n");
+ exit(1);
+ }
+ }
+ else {
+ fprintf(stderr,"File '%s' already exists. Exiting.\n", filename);
+ exit(1);
+ }
+ }
+ }
+
+ /* open the file */
+ if (url_fopen(&oc->pb, filename, URL_WRONLY) < 0) {
+ fprintf(stderr, "Could not open '%s'\n", filename);
+ exit(1);
+ }
+ }
+
+ memset(ap, 0, sizeof(*ap));
+ if (av_set_parameters(oc, ap) < 0) {
+ fprintf(stderr, "%s: Invalid encoding parameters\n",
+ oc->filename);
+ exit(1);
+ }
+
+ oc->preload= (int)(mux_preload*AV_TIME_BASE);
+ oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE);
+ oc->loop_output = loop_output;
+
+ for(i=0; i<opt_name_count; i++){
+ const AVOption *opt;
+ double d = av_get_double(avformat_opts, opt_names[i], &opt);
+ if(d==d && (opt->flags&AV_OPT_FLAG_ENCODING_PARAM))
+ av_set_double(oc, opt_names[i], d);
+ }
+
+ /* reset some options */
+ file_oformat = NULL;
+ file_iformat = NULL;
+}
+
+/* same option as mencoder */
+static void opt_pass(const char *pass_str)
+{
+ int pass;
+ pass = atoi(pass_str);
+ if (pass != 1 && pass != 2) {
+ fprintf(stderr, "pass number can be only 1 or 2\n");
+ exit(1);
+ }
+ do_pass = pass;
+}
+
+#if defined(__MINGW32__) || defined(CONFIG_OS2)
+static int64_t getutime(void)
+{
+ return av_gettime();
+}
+#else
+static int64_t getutime(void)
+{
+ struct rusage rusage;
+
+ getrusage(RUSAGE_SELF, &rusage);
+ return (rusage.ru_utime.tv_sec * 1000000LL) + rusage.ru_utime.tv_usec;
+}
+#endif
+
+#if defined(CONFIG_FFM_DEMUXER) || defined(CONFIG_FFM_MUXER)
+extern int ffm_nopts;
+#endif
+
+static void show_formats(void)
+{
+ AVInputFormat *ifmt;
+ AVOutputFormat *ofmt;
+ URLProtocol *up;
+ AVCodec *p, *p2;
+ const char **pp, *last_name;
+
+ printf("File formats:\n");
+ last_name= "000";
+ for(;;){
+ int decode=0;
+ int encode=0;
+ const char *name=NULL;
+ const char *long_name=NULL;
+
+ for(ofmt = first_oformat; ofmt != NULL; ofmt = ofmt->next) {
+ if((name == NULL || strcmp(ofmt->name, name)<0) &&
+ strcmp(ofmt->name, last_name)>0){
+ name= ofmt->name;
+ long_name= ofmt->long_name;
+ encode=1;
+ }
+ }
+ for(ifmt = first_iformat; ifmt != NULL; ifmt = ifmt->next) {
+ if((name == NULL || strcmp(ifmt->name, name)<0) &&
+ strcmp(ifmt->name, last_name)>0){
+ name= ifmt->name;
+ long_name= ifmt->long_name;
+ encode=0;
+ }
+ if(name && strcmp(ifmt->name, name)==0)
+ decode=1;
+ }
+ if(name==NULL)
+ break;
+ last_name= name;
+
+ printf(
+ " %s%s %-15s %s\n",
+ decode ? "D":" ",
+ encode ? "E":" ",
+ name,
+ long_name ? long_name:" ");
+ }
+ printf("\n");
+
+ printf("Codecs:\n");
+ last_name= "000";
+ for(;;){
+ int decode=0;
+ int encode=0;
+ int cap=0;
+ const char *type_str;
+
+ p2=NULL;
+ for(p = first_avcodec; p != NULL; p = p->next) {
+ if((p2==NULL || strcmp(p->name, p2->name)<0) &&
+ strcmp(p->name, last_name)>0){
+ p2= p;
+ decode= encode= cap=0;
+ }
+ if(p2 && strcmp(p->name, p2->name)==0){
+ if(p->decode) decode=1;
+ if(p->encode) encode=1;
+ cap |= p->capabilities;
+ }
+ }
+ if(p2==NULL)
+ break;
+ last_name= p2->name;
+
+ switch(p2->type) {
+ case CODEC_TYPE_VIDEO:
+ type_str = "V";
+ break;
+ case CODEC_TYPE_AUDIO:
+ type_str = "A";
+ break;
+ case CODEC_TYPE_SUBTITLE:
+ type_str = "S";
+ break;
+ default:
+ type_str = "?";
+ break;
+ }
+ printf(
+ " %s%s%s%s%s%s %s",
+ decode ? "D": (/*p2->decoder ? "d":*/" "),
+ encode ? "E":" ",
+ type_str,
+ cap & CODEC_CAP_DRAW_HORIZ_BAND ? "S":" ",
+ cap & CODEC_CAP_DR1 ? "D":" ",
+ cap & CODEC_CAP_TRUNCATED ? "T":" ",
+ p2->name);
+ /* if(p2->decoder && decode==0)
+ printf(" use %s for decoding", p2->decoder->name);*/
+ printf("\n");
+ }
+ printf("\n");
+
+ printf("Supported file protocols:\n");
+ for(up = first_protocol; up != NULL; up = up->next)
+ printf(" %s:", up->name);
+ printf("\n");
+
+ printf("Frame size, frame rate abbreviations:\n ntsc pal qntsc qpal sntsc spal film ntsc-film sqcif qcif cif 4cif\n");
+ printf("Motion estimation methods:\n");
+ pp = motion_str;
+ while (*pp) {
+ printf(" %s", *pp);
+ if ((pp - motion_str + 1) == ME_ZERO)
+ printf("(fastest)");
+ else if ((pp - motion_str + 1) == ME_FULL)
+ printf("(slowest)");
+ else if ((pp - motion_str + 1) == ME_EPZS)
+ printf("(default)");
+ pp++;
+ }
+ printf("\n\n");
+ printf(
+"Note, the names of encoders and decoders dont always match, so there are\n"
+"several cases where the above table shows encoder only or decoder only entries\n"
+"even though both encoding and decoding are supported for example, the h263\n"
+"decoder corresponds to the h263 and h263p encoders, for file formats its even\n"
+"worse\n");
+ exit(1);
+}
+
+static void parse_matrix_coeffs(uint16_t *dest, const char *str)
+{
+ int i;
+ const char *p = str;
+ for(i = 0;; i++) {
+ dest[i] = atoi(p);
+ if(i == 63)
+ break;
+ p = strchr(p, ',');
+ if(!p) {
+ fprintf(stderr, "Syntax error in matrix \"%s\" at coeff %d\n", str, i);
+ exit(1);
+ }
+ p++;
+ }
+}
+
+static void opt_inter_matrix(const char *arg)
+{
+ inter_matrix = av_mallocz(sizeof(uint16_t) * 64);
+ parse_matrix_coeffs(inter_matrix, arg);
+}
+
+static void opt_intra_matrix(const char *arg)
+{
+ intra_matrix = av_mallocz(sizeof(uint16_t) * 64);
+ parse_matrix_coeffs(intra_matrix, arg);
+}
+
+static void opt_target(const char *arg)
+{
+ int norm = -1;
+ static const char *const frame_rates[] = {"25", "30000/1001", "24000/1001"};
+
+ if(!strncmp(arg, "pal-", 4)) {
+ norm = 0;
+ arg += 4;
+ } else if(!strncmp(arg, "ntsc-", 5)) {
+ norm = 1;
+ arg += 5;
+ } else if(!strncmp(arg, "film-", 5)) {
+ norm = 2;
+ arg += 5;
+ } else {
+ int fr;
+ /* Calculate FR via float to avoid int overflow */
+ fr = (int)(frame_rate * 1000.0 / frame_rate_base);
+ if(fr == 25000) {
+ norm = 0;
+ } else if((fr == 29970) || (fr == 23976)) {
+ norm = 1;
+ } else {
+ /* Try to determine PAL/NTSC by peeking in the input files */
+ if(nb_input_files) {
+ int i, j;
+ for(j = 0; j < nb_input_files; j++) {
+ for(i = 0; i < input_files[j]->nb_streams; i++) {
+ AVCodecContext *c = input_files[j]->streams[i]->codec;
+ if(c->codec_type != CODEC_TYPE_VIDEO)
+ continue;
+ fr = c->time_base.den * 1000 / c->time_base.num;
+ if(fr == 25000) {
+ norm = 0;
+ break;
+ } else if((fr == 29970) || (fr == 23976)) {
+ norm = 1;
+ break;
+ }
+ }
+ if(norm >= 0)
+ break;
+ }
+ }
+ }
+ if(verbose && norm >= 0)
+ fprintf(stderr, "Assuming %s for target.\n", norm ? "NTSC" : "PAL");
+ }
+
+ if(norm < 0) {
+ fprintf(stderr, "Could not determine norm (PAL/NTSC/NTSC-Film) for target.\n");
+ fprintf(stderr, "Please prefix target with \"pal-\", \"ntsc-\" or \"film-\",\n");
+ fprintf(stderr, "or set a framerate with \"-r xxx\".\n");
+ exit(1);
+ }
+
+ if(!strcmp(arg, "vcd")) {
+
+ opt_video_codec("mpeg1video");
+ opt_audio_codec("mp2");
+ opt_format("vcd");
+
+ opt_frame_size(norm ? "352x240" : "352x288");
+ opt_frame_rate(frame_rates[norm]);
+ opt_default("gop", norm ? "18" : "15");
+
+ opt_default("b", "1150000");
+ opt_default("maxrate", "1150000");
+ opt_default("minrate", "1150000");
+ opt_default("bufsize", "327680"); // 40*1024*8;
+
+ opt_default("ab", "224000");
+ audio_sample_rate = 44100;
+ audio_channels = 2;
+
+ opt_default("packetsize", "2324");
+ opt_default("muxrate", "1411200"); // 2352 * 75 * 8;
+
+ /* We have to offset the PTS, so that it is consistent with the SCR.
+ SCR starts at 36000, but the first two packs contain only padding
+ and the first pack from the other stream, respectively, may also have
+ been written before.
+ So the real data starts at SCR 36000+3*1200. */
+ mux_preload= (36000+3*1200) / 90000.0; //0.44
+ } else if(!strcmp(arg, "svcd")) {
+
+ opt_video_codec("mpeg2video");
+ opt_audio_codec("mp2");
+ opt_format("svcd");
+
+ opt_frame_size(norm ? "480x480" : "480x576");
+ opt_frame_rate(frame_rates[norm]);
+ opt_default("gop", norm ? "18" : "15");
+
+ opt_default("b", "2040000");
+ opt_default("maxrate", "2516000");
+ opt_default("minrate", "0"); //1145000;
+ opt_default("bufsize", "1835008"); //224*1024*8;
+ opt_default("flags", "+SCAN_OFFSET");
+
+
+ opt_default("ab", "224000");
+ audio_sample_rate = 44100;
+
+ opt_default("packetsize", "2324");
+
+ } else if(!strcmp(arg, "dvd")) {
+
+ opt_video_codec("mpeg2video");
+ opt_audio_codec("ac3");
+ opt_format("dvd");
+
+ opt_frame_size(norm ? "720x480" : "720x576");
+ opt_frame_rate(frame_rates[norm]);
+ opt_default("gop", norm ? "18" : "15");
+
+ opt_default("b", "6000000");
+ opt_default("maxrate", "9000000");
+ opt_default("minrate", "0"); //1500000;
+ opt_default("bufsize", "1835008"); //224*1024*8;
+
+ opt_default("packetsize", "2048"); // from www.mpucoder.com: DVD sectors contain 2048 bytes of data, this is also the size of one pack.
+ opt_default("muxrate", "10080000"); // from mplex project: data_rate = 1260000. mux_rate = data_rate * 8
+
+ opt_default("ab", "448000");
+ audio_sample_rate = 48000;
+
+ } else if(!strncmp(arg, "dv", 2)) {
+
+ opt_format("dv");
+
+ opt_frame_size(norm ? "720x480" : "720x576");
+ opt_frame_pix_fmt(!strncmp(arg, "dv50", 4) ? "yuv422p" :
+ (norm ? "yuv411p" : "yuv420p"));
+ opt_frame_rate(frame_rates[norm]);
+
+ audio_sample_rate = 48000;
+ audio_channels = 2;
+
+ } else {
+ fprintf(stderr, "Unknown target: %s\n", arg);
+ exit(1);
+ }
+}
+
+static void opt_video_bsf(const char *arg)
+{
+ AVBitStreamFilterContext *bsfc= av_bitstream_filter_init(arg); //FIXME split name and args for filter at '='
+ AVBitStreamFilterContext **bsfp;
+
+ if(!bsfc){
+ fprintf(stderr, "Unknown bitstream filter %s\n", arg);
+ exit(1);
+ }
+
+ bsfp= &video_bitstream_filters;
+ while(*bsfp)
+ bsfp= &(*bsfp)->next;
+
+ *bsfp= bsfc;
+}
+
+//FIXME avoid audio - video code duplication
+static void opt_audio_bsf(const char *arg)
+{
+ AVBitStreamFilterContext *bsfc= av_bitstream_filter_init(arg); //FIXME split name and args for filter at '='
+ AVBitStreamFilterContext **bsfp;
+
+ if(!bsfc){
+ fprintf(stderr, "Unknown bitstream filter %s\n", arg);
+ exit(1);
+ }
+
+ bsfp= &audio_bitstream_filters;
+ while(*bsfp)
+ bsfp= &(*bsfp)->next;
+
+ *bsfp= bsfc;
+}
+
+static void show_version(void)
+{
+ /* TODO: add function interface to avutil and avformat */
+ fprintf(stderr, "ffmpeg " FFMPEG_VERSION "\n"
+ "libavutil %d\n"
+ "libavcodec %d\n"
+ "libavformat %d\n",
+ LIBAVUTIL_BUILD, avcodec_build(), LIBAVFORMAT_BUILD);
+ exit(1);
+}
+
+static int opt_default(const char *opt, const char *arg){
+ int type;
+ const AVOption *o= NULL;
+ int opt_types[]={AV_OPT_FLAG_VIDEO_PARAM, AV_OPT_FLAG_AUDIO_PARAM, 0, AV_OPT_FLAG_SUBTITLE_PARAM, 0};
+
+ for(type=0; type<CODEC_TYPE_NB; type++){
+ const AVOption *o2 = av_find_opt(avctx_opts[0], opt, NULL, opt_types[type], opt_types[type]);
+ if(o2)
+ o = av_set_string(avctx_opts[type], opt, arg);
+ }
+ if(!o)
+ o = av_set_string(avformat_opts, opt, arg);
+ if(!o){
+ if(opt[0] == 'a')
+ o = av_set_string(avctx_opts[CODEC_TYPE_AUDIO], opt+1, arg);
+ else if(opt[0] == 'v')
+ o = av_set_string(avctx_opts[CODEC_TYPE_VIDEO], opt+1, arg);
+ else if(opt[0] == 's')
+ o = av_set_string(avctx_opts[CODEC_TYPE_SUBTITLE], opt+1, arg);
+ }
+ if(!o)
+ return -1;
+
+// av_log(NULL, AV_LOG_ERROR, "%s:%s: %f 0x%0X\n", opt, arg, av_get_double(avctx_opts, opt, NULL), (int)av_get_int(avctx_opts, opt, NULL));
+
+ //FIXME we should always use avctx_opts, ... for storing options so there wont be any need to keep track of whats set over this
+ opt_names= av_realloc(opt_names, sizeof(void*)*(opt_name_count+1));
+ opt_names[opt_name_count++]= o->name;
+
+#if defined(CONFIG_FFM_DEMUXER) || defined(CONFIG_FFM_MUXER)
+ /* disable generate of real time pts in ffm (need to be supressed anyway) */
+ if(avctx_opts[0]->flags & CODEC_FLAG_BITEXACT)
+ ffm_nopts = 1;
+#endif
+
+ if(avctx_opts[0]->debug)
+ av_log_level = AV_LOG_DEBUG;
+ return 0;
+}
+
+const OptionDef options[] = {
+ /* main options */
+ { "L", 0, {(void*)show_license}, "show license" },
+ { "h", 0, {(void*)show_help}, "show help" },
+ { "version", 0, {(void*)show_version}, "show version" },
+ { "formats", 0, {(void*)show_formats}, "show available formats, codecs, protocols, ..." },
+ { "f", HAS_ARG, {(void*)opt_format}, "force format", "fmt" },
+ { "i", HAS_ARG, {(void*)opt_input_file}, "input file name", "filename" },
+ { "y", OPT_BOOL, {(void*)&file_overwrite}, "overwrite output files" },
+ { "map", HAS_ARG | OPT_EXPERT, {(void*)opt_map}, "set input stream mapping", "file:stream[:syncfile:syncstream]" },
+ { "map_meta_data", HAS_ARG | OPT_EXPERT, {(void*)opt_map_meta_data}, "set meta data information of outfile from infile", "outfile:infile" },
+ { "t", HAS_ARG, {(void*)opt_recording_time}, "set the recording time", "duration" },
+ { "fs", HAS_ARG | OPT_INT64, {(void*)&limit_filesize}, "set the limit file size in bytes", "limit_size" }, //
+ { "ss", HAS_ARG, {(void*)opt_start_time}, "set the start time offset", "time_off" },
+ { "itsoffset", HAS_ARG, {(void*)opt_input_ts_offset}, "set the input ts offset", "time_off" },
+ { "title", HAS_ARG | OPT_STRING, {(void*)&str_title}, "set the title", "string" },
+ { "timestamp", HAS_ARG, {(void*)&opt_rec_timestamp}, "set the timestamp", "time" },
+ { "author", HAS_ARG | OPT_STRING, {(void*)&str_author}, "set the author", "string" },
+ { "copyright", HAS_ARG | OPT_STRING, {(void*)&str_copyright}, "set the copyright", "string" },
+ { "comment", HAS_ARG | OPT_STRING, {(void*)&str_comment}, "set the comment", "string" },
+ { "album", HAS_ARG | OPT_STRING, {(void*)&str_album}, "set the album", "string" },
+ { "benchmark", OPT_BOOL | OPT_EXPERT, {(void*)&do_benchmark},
+ "add timings for benchmarking" },
+ { "dump", OPT_BOOL | OPT_EXPERT, {(void*)&do_pkt_dump},
+ "dump each input packet" },
+ { "hex", OPT_BOOL | OPT_EXPERT, {(void*)&do_hex_dump},
+ "when dumping packets, also dump the payload" },
+ { "re", OPT_BOOL | OPT_EXPERT, {(void*)&rate_emu}, "read input at native frame rate", "" },
+ { "loop_input", OPT_BOOL | OPT_EXPERT, {(void*)&loop_input}, "loop (current only works with images)" },
+ { "loop_output", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&loop_output}, "number of times to loop output in formats that support looping (0 loops forever)", "" },
+ { "v", HAS_ARG, {(void*)opt_verbose}, "control amount of logging", "verbose" },
+ { "target", HAS_ARG, {(void*)opt_target}, "specify target file type (\"vcd\", \"svcd\", \"dvd\", \"dv\", \"dv50\", \"pal-vcd\", \"ntsc-svcd\", ...)", "type" },
+ { "threads", HAS_ARG | OPT_EXPERT, {(void*)opt_thread_count}, "thread count", "count" },
+ { "vsync", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&video_sync_method}, "video sync method", "" },
+ { "async", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&audio_sync_method}, "audio sync method", "" },
+ { "vglobal", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&video_global_header}, "video global header storage type", "" },
+ { "copyts", OPT_BOOL | OPT_EXPERT, {(void*)&copy_ts}, "copy timestamps" },
+ { "shortest", OPT_BOOL | OPT_EXPERT, {(void*)&opt_shortest}, "finish encoding within shortest input" }, //
+ { "dts_delta_threshold", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&dts_delta_threshold}, "timestamp discontinuity delta threshold", "" },
+
+ /* video options */
+ { "vframes", OPT_INT | HAS_ARG | OPT_VIDEO, {(void*)&max_frames[CODEC_TYPE_VIDEO]}, "set the number of video frames to record", "number" },
+ { "dframes", OPT_INT | HAS_ARG, {(void*)&max_frames[CODEC_TYPE_DATA]}, "set the number of data frames to record", "number" },
+ { "r", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_rate}, "set frame rate (Hz value, fraction or abbreviation)", "rate" },
+ { "s", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_size}, "set frame size (WxH or abbreviation)", "size" },
+ { "aspect", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_aspect_ratio}, "set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)", "aspect" },
+ { "pix_fmt", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_frame_pix_fmt}, "set pixel format", "format" },
+ { "croptop", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop_top}, "set top crop band size (in pixels)", "size" },
+ { "cropbottom", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop_bottom}, "set bottom crop band size (in pixels)", "size" },
+ { "cropleft", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop_left}, "set left crop band size (in pixels)", "size" },
+ { "cropright", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop_right}, "set right crop band size (in pixels)", "size" },
+ { "padtop", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_pad_top}, "set top pad band size (in pixels)", "size" },
+ { "padbottom", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_pad_bottom}, "set bottom pad band size (in pixels)", "size" },
+ { "padleft", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_pad_left}, "set left pad band size (in pixels)", "size" },
+ { "padright", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_pad_right}, "set right pad band size (in pixels)", "size" },
+ { "padcolor", HAS_ARG | OPT_VIDEO, {(void*)opt_pad_color}, "set color of pad bands (Hex 000000 thru FFFFFF)", "color" },
+ { "intra", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&intra_only}, "use only intra frames"},
+ { "vn", OPT_BOOL | OPT_VIDEO, {(void*)&video_disable}, "disable video" },
+ { "vdt", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&video_discard}, "discard threshold", "n" },
+ { "qscale", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qscale}, "use fixed video quantizer scale (VBR)", "q" },
+ { "qdiff", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qdiff}, "max difference between the quantizer scale (VBR)", "q" },
+ { "rc_eq", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_rc_eq}, "set rate control equation", "equation" },
+ { "rc_override", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_rc_override_string}, "rate control override for specific intervals", "override" },
+ { "vcodec", HAS_ARG | OPT_VIDEO, {(void*)opt_video_codec}, "force video codec ('copy' to copy stream)", "codec" },
+ { "me", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_motion_estimation}, "set motion estimation method",
+ "method" },
+ { "me_threshold", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_me_threshold}, "motion estimaton threshold", "" },
+ { "strict", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_strict}, "how strictly to follow the standards", "strictness" },
+ { "sameq", OPT_BOOL | OPT_VIDEO, {(void*)&same_quality},
+ "use same video quality as source (implies VBR)" },
+ { "pass", HAS_ARG | OPT_VIDEO, {(void*)&opt_pass}, "select the pass number (1 or 2)", "n" },
+ { "passlogfile", HAS_ARG | OPT_STRING | OPT_VIDEO, {(void*)&pass_logfilename}, "select two pass log file name", "file" },
+ { "deinterlace", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_deinterlace},
+ "deinterlace pictures" },
+ { "psnr", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_psnr}, "calculate PSNR of compressed frames" },
+ { "vstats", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_vstats}, "dump video coding statistics to file" },
+ { "vhook", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)add_frame_hooker}, "insert video processing module", "module" },
+ { "intra_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_intra_matrix}, "specify intra matrix coeffs", "matrix" },
+ { "inter_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_inter_matrix}, "specify inter matrix coeffs", "matrix" },
+ { "top", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_top_field_first}, "top=1/bottom=0/auto=-1 field first", "" },
+ { "dc", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&intra_dc_precision}, "intra_dc_precision", "precision" },
+ { "vtag", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_tag}, "force video tag/fourcc", "fourcc/tag" },
+ { "newvideo", OPT_VIDEO, {(void*)opt_new_video_stream}, "add a new video stream to the current output stream" },
+ { "qphist", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, { (void *)&qp_hist }, "show QP histogram" },
+
+ /* audio options */
+ { "aframes", OPT_INT | HAS_ARG | OPT_AUDIO, {(void*)&max_frames[CODEC_TYPE_AUDIO]}, "set the number of audio frames to record", "number" },
+ { "aq", OPT_FLOAT | HAS_ARG | OPT_AUDIO, {(void*)&audio_qscale}, "set audio quality (codec-specific)", "quality", },
+ { "ar", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_rate}, "set audio sampling rate (in Hz)", "rate" },
+ { "ac", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_channels}, "set number of audio channels", "channels" },
+ { "an", OPT_BOOL | OPT_AUDIO, {(void*)&audio_disable}, "disable audio" },
+ { "acodec", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_codec}, "force audio codec ('copy' to copy stream)", "codec" },
+ { "atag", HAS_ARG | OPT_EXPERT | OPT_AUDIO, {(void*)opt_audio_tag}, "force audio tag/fourcc", "fourcc/tag" },
+ { "vol", OPT_INT | HAS_ARG | OPT_AUDIO, {(void*)&audio_volume}, "change audio volume (256=normal)" , "volume" }, //
+ { "newaudio", OPT_AUDIO, {(void*)opt_new_audio_stream}, "add a new audio stream to the current output stream" },
+ { "alang", HAS_ARG | OPT_STRING | OPT_AUDIO, {(void *)&audio_language}, "set the ISO 639 language code (3 letters) of the current audio stream" , "code" },
+
+ /* subtitle options */
+ { "scodec", HAS_ARG | OPT_SUBTITLE, {(void*)opt_subtitle_codec}, "force subtitle codec ('copy' to copy stream)", "codec" },
+ { "newsubtitle", OPT_SUBTITLE, {(void*)opt_new_subtitle_stream}, "add a new subtitle stream to the current output stream" },
+ { "slang", HAS_ARG | OPT_STRING | OPT_SUBTITLE, {(void *)&subtitle_language}, "set the ISO 639 language code (3 letters) of the current subtitle stream" , "code" },
+
+ /* grab options */
+ { "vc", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_GRAB, {(void*)opt_video_channel}, "set video grab channel (DV1394 only)", "channel" },
+ { "tvstd", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_GRAB, {(void*)opt_video_standard}, "set television standard (NTSC, PAL (SECAM))", "standard" },
+ { "isync", OPT_BOOL | OPT_EXPERT | OPT_GRAB, {(void*)&input_sync}, "sync read on input", "" },
+
+ /* muxer options */
+ { "muxdelay", OPT_FLOAT | HAS_ARG | OPT_EXPERT, {(void*)&mux_max_delay}, "set the maximum demux-decode delay", "seconds" },
+ { "muxpreload", OPT_FLOAT | HAS_ARG | OPT_EXPERT, {(void*)&mux_preload}, "set the initial demux-decode delay", "seconds" },
+
+ { "absf", HAS_ARG | OPT_AUDIO | OPT_EXPERT, {(void*)opt_audio_bsf}, "", "bitstream filter" },
+ { "vbsf", HAS_ARG | OPT_VIDEO | OPT_EXPERT, {(void*)opt_video_bsf}, "", "bitstream filter" },
+
+ { "default", OPT_FUNC2 | HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {(void*)opt_default}, "generic catch all option", "" },
+ { NULL, },
+};
+
+static void show_banner(void)
+{
+ fprintf(stderr, "FFmpeg version " FFMPEG_VERSION ", Copyright (c) 2000-2007 Fabrice Bellard, et al.\n");
+ fprintf(stderr, " configuration: " FFMPEG_CONFIGURATION "\n");
+ fprintf(stderr, " libavutil version: " AV_STRINGIFY(LIBAVUTIL_VERSION) "\n");
+ fprintf(stderr, " libavcodec version: " AV_STRINGIFY(LIBAVCODEC_VERSION) "\n");
+ fprintf(stderr, " libavformat version: " AV_STRINGIFY(LIBAVFORMAT_VERSION) "\n");
+ fprintf(stderr, " built on " __DATE__ " " __TIME__);
+#ifdef __GNUC__
+ fprintf(stderr, ", gcc: " __VERSION__ "\n");
+#else
+ fprintf(stderr, ", using a non-gcc compiler\n");
+#endif
+}
+
+static void show_license(void)
+{
+ show_banner();
+#ifdef CONFIG_GPL
+ printf(
+ "FFmpeg is free software; you can redistribute it and/or modify\n"
+ "it under the terms of the GNU General Public License as published by\n"
+ "the Free Software Foundation; either version 2 of the License, or\n"
+ "(at your option) any later version.\n"
+ "\n"
+ "FFmpeg is distributed in the hope that it will be useful,\n"
+ "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
+ "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
+ "GNU General Public License for more details.\n"
+ "\n"
+ "You should have received a copy of the GNU General Public License\n"
+ "along with FFmpeg; if not, write to the Free Software\n"
+ "Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n"
+ );
+#else
+ printf(
+ "FFmpeg is free software; you can redistribute it and/or\n"
+ "modify it under the terms of the GNU Lesser General Public\n"
+ "License as published by the Free Software Foundation; either\n"
+ "version 2.1 of the License, or (at your option) any later version.\n"
+ "\n"
+ "FFmpeg is distributed in the hope that it will be useful,\n"
+ "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
+ "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
+ "Lesser General Public License for more details.\n"
+ "\n"
+ "You should have received a copy of the GNU Lesser General Public\n"
+ "License along with FFmpeg; if not, write to the Free Software\n"
+ "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n"
+ );
+#endif
+ exit(1);
+}
+
+static void show_help(void)
+{
+ show_banner();
+ printf("usage: ffmpeg [[infile options] -i infile]... {[outfile options] outfile}...\n"
+ "Hyper fast Audio and Video encoder\n");
+ printf("\n");
+ show_help_options(options, "Main options:\n",
+ OPT_EXPERT | OPT_AUDIO | OPT_VIDEO, 0);
+ show_help_options(options, "\nVideo options:\n",
+ OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB,
+ OPT_VIDEO);
+ show_help_options(options, "\nAdvanced Video options:\n",
+ OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB,
+ OPT_VIDEO | OPT_EXPERT);
+ show_help_options(options, "\nAudio options:\n",
+ OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB,
+ OPT_AUDIO);
+ show_help_options(options, "\nAdvanced Audio options:\n",
+ OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB,
+ OPT_AUDIO | OPT_EXPERT);
+ show_help_options(options, "\nSubtitle options:\n",
+ OPT_SUBTITLE | OPT_GRAB,
+ OPT_SUBTITLE);
+ show_help_options(options, "\nAudio/Video grab options:\n",
+ OPT_GRAB,
+ OPT_GRAB);
+ show_help_options(options, "\nAdvanced options:\n",
+ OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB,
+ OPT_EXPERT);
+ av_opt_show(avctx_opts[0], NULL);
+ av_opt_show(avformat_opts, NULL);
+
+ exit(1);
+}
+
+void parse_arg_file(const char *filename)
+{
+ opt_output_file(filename);
+}
+
+int main(int argc, char **argv)
+{
+ int i;
+ int64_t ti;
+
+ av_register_all();
+
+ for(i=0; i<CODEC_TYPE_NB; i++){
+ avctx_opts[i]= avcodec_alloc_context2(i);
+ }
+ avformat_opts = av_alloc_format_context();
+
+ if (argc <= 1)
+ show_help();
+ else
+ show_banner();
+
+ /* parse options */
+ parse_options(argc, argv, options);
+
+ /* file converter / grab */
+ if (nb_output_files <= 0) {
+ fprintf(stderr, "Must supply at least one output file\n");
+ exit(1);
+ }
+
+ if (nb_input_files == 0) {
+ fprintf(stderr, "Must supply at least one input file\n");
+ exit(1);
+ }
+
+ ti = getutime();
+ av_encode(output_files, nb_output_files, input_files, nb_input_files,
+ stream_maps, nb_stream_maps);
+ ti = getutime() - ti;
+ if (do_benchmark) {
+ printf("bench: utime=%0.3fs\n", ti / 1000000.0);
+ }
+
+ /* close files */
+ for(i=0;i<nb_output_files;i++) {
+ /* maybe av_close_output_file ??? */
+ AVFormatContext *s = output_files[i];
+ int j;
+ if (!(s->oformat->flags & AVFMT_NOFILE))
+ url_fclose(&s->pb);
+ for(j=0;j<s->nb_streams;j++) {
+ av_free(s->streams[j]->codec);
+ av_free(s->streams[j]);
+ }
+ av_free(s);
+ }
+ for(i=0;i<nb_input_files;i++)
+ av_close_input_file(input_files[i]);
+
+ av_free_static();
+
+ av_free(intra_matrix);
+ av_free(inter_matrix);
+ av_free(opt_names);
+
+#ifdef CONFIG_POWERPC_PERF
+ extern void powerpc_display_perf_report(void);
+ powerpc_display_perf_report();
+#endif /* CONFIG_POWERPC_PERF */
+
+ if (received_sigterm) {
+ fprintf(stderr,
+ "Received signal %d: terminating.\n",
+ (int) received_sigterm);
+ exit (255);
+ }
+
+ exit(0); /* not all OS-es handle main() return value */
+ return 0;
+}
diff --git a/contrib/ffmpeg/ffplay.c b/contrib/ffmpeg/ffplay.c
new file mode 100644
index 000000000..ebe31cd9b
--- /dev/null
+++ b/contrib/ffmpeg/ffplay.c
@@ -0,0 +1,2581 @@
+/*
+ * FFplay : Simple Media Player based on the ffmpeg libraries
+ * Copyright (c) 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
+ */
+#define HAVE_AV_CONFIG_H
+#include "avformat.h"
+#include "swscale.h"
+
+#include "version.h"
+#include "cmdutils.h"
+
+#include <SDL.h>
+#include <SDL_thread.h>
+
+#ifdef __MINGW32__
+#undef main /* We don't want SDL to override our main() */
+#endif
+
+#ifdef CONFIG_OS2
+#define INCL_DOS
+ #include <os2.h>
+ #include <stdio.h>
+
+ void MorphToPM()
+ {
+ PPIB pib;
+ PTIB tib;
+
+ DosGetInfoBlocks(&tib, &pib);
+
+ // Change flag from VIO to PM:
+ if (pib->pib_ultype==2) pib->pib_ultype = 3;
+ }
+#endif
+
+#undef exit
+
+//#define DEBUG_SYNC
+
+#define MAX_VIDEOQ_SIZE (5 * 256 * 1024)
+#define MAX_AUDIOQ_SIZE (5 * 16 * 1024)
+#define MAX_SUBTITLEQ_SIZE (5 * 16 * 1024)
+
+/* SDL audio buffer size, in samples. Should be small to have precise
+ A/V sync as SDL does not have hardware buffer fullness info. */
+#define SDL_AUDIO_BUFFER_SIZE 1024
+
+/* no AV sync correction is done if below the AV sync threshold */
+#define AV_SYNC_THRESHOLD 0.01
+/* no AV correction is done if too big error */
+#define AV_NOSYNC_THRESHOLD 10.0
+
+/* maximum audio speed change to get correct sync */
+#define SAMPLE_CORRECTION_PERCENT_MAX 10
+
+/* we use about AUDIO_DIFF_AVG_NB A-V differences to make the average */
+#define AUDIO_DIFF_AVG_NB 20
+
+/* NOTE: the size must be big enough to compensate the hardware audio buffersize size */
+#define SAMPLE_ARRAY_SIZE (2*65536)
+
+static int sws_flags = SWS_BICUBIC;
+
+typedef struct PacketQueue {
+ AVPacketList *first_pkt, *last_pkt;
+ int nb_packets;
+ int size;
+ int abort_request;
+ SDL_mutex *mutex;
+ SDL_cond *cond;
+} PacketQueue;
+
+#define VIDEO_PICTURE_QUEUE_SIZE 1
+#define SUBPICTURE_QUEUE_SIZE 4
+
+typedef struct VideoPicture {
+ double pts; ///<presentation time stamp for this picture
+ SDL_Overlay *bmp;
+ int width, height; /* source height & width */
+ int allocated;
+} VideoPicture;
+
+typedef struct SubPicture {
+ double pts; /* presentation time stamp for this picture */
+ AVSubtitle sub;
+} SubPicture;
+
+enum {
+ AV_SYNC_AUDIO_MASTER, /* default choice */
+ AV_SYNC_VIDEO_MASTER,
+ AV_SYNC_EXTERNAL_CLOCK, /* synchronize to an external clock */
+};
+
+typedef struct VideoState {
+ SDL_Thread *parse_tid;
+ SDL_Thread *video_tid;
+ AVInputFormat *iformat;
+ int no_background;
+ int abort_request;
+ int paused;
+ int last_paused;
+ int seek_req;
+ int seek_flags;
+ int64_t seek_pos;
+ AVFormatContext *ic;
+ int dtg_active_format;
+
+ int audio_stream;
+
+ int av_sync_type;
+ double external_clock; /* external clock base */
+ int64_t external_clock_time;
+
+ double audio_clock;
+ double audio_diff_cum; /* used for AV difference average computation */
+ double audio_diff_avg_coef;
+ double audio_diff_threshold;
+ int audio_diff_avg_count;
+ AVStream *audio_st;
+ PacketQueue audioq;
+ int audio_hw_buf_size;
+ /* samples output by the codec. we reserve more space for avsync
+ compensation */
+ DECLARE_ALIGNED(16,uint8_t,audio_buf[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2]);
+ unsigned int audio_buf_size; /* in bytes */
+ int audio_buf_index; /* in bytes */
+ AVPacket audio_pkt;
+ uint8_t *audio_pkt_data;
+ int audio_pkt_size;
+
+ int show_audio; /* if true, display audio samples */
+ int16_t sample_array[SAMPLE_ARRAY_SIZE];
+ int sample_array_index;
+ int last_i_start;
+
+ SDL_Thread *subtitle_tid;
+ int subtitle_stream;
+ int subtitle_stream_changed;
+ AVStream *subtitle_st;
+ PacketQueue subtitleq;
+ SubPicture subpq[SUBPICTURE_QUEUE_SIZE];
+ int subpq_size, subpq_rindex, subpq_windex;
+ SDL_mutex *subpq_mutex;
+ SDL_cond *subpq_cond;
+
+ double frame_timer;
+ double frame_last_pts;
+ double frame_last_delay;
+ double video_clock; ///<pts of last decoded frame / predicted pts of next decoded frame
+ int video_stream;
+ AVStream *video_st;
+ PacketQueue videoq;
+ double video_current_pts; ///<current displayed pts (different from video_clock if frame fifos are used)
+ int64_t video_current_pts_time; ///<time (av_gettime) at which we updated video_current_pts - used to have running video pts
+ VideoPicture pictq[VIDEO_PICTURE_QUEUE_SIZE];
+ int pictq_size, pictq_rindex, pictq_windex;
+ SDL_mutex *pictq_mutex;
+ SDL_cond *pictq_cond;
+
+ // QETimer *video_timer;
+ char filename[1024];
+ int width, height, xleft, ytop;
+} VideoState;
+
+void show_help(void);
+static int audio_write_get_buf_size(VideoState *is);
+
+/* options specified by the user */
+static AVInputFormat *file_iformat;
+static const char *input_filename;
+static int fs_screen_width;
+static int fs_screen_height;
+static int screen_width = 0;
+static int screen_height = 0;
+static int frame_width = 0;
+static int frame_height = 0;
+static enum PixelFormat frame_pix_fmt = PIX_FMT_NONE;
+static int audio_disable;
+static int video_disable;
+static int wanted_audio_stream= 0;
+static int seek_by_bytes;
+static int display_disable;
+static int show_status;
+static int av_sync_type = AV_SYNC_AUDIO_MASTER;
+static int64_t start_time = AV_NOPTS_VALUE;
+static int debug = 0;
+static int debug_mv = 0;
+static int step = 0;
+static int thread_count = 1;
+static int workaround_bugs = 1;
+static int fast = 0;
+static int genpts = 0;
+static int lowres = 0;
+static int idct = FF_IDCT_AUTO;
+static enum AVDiscard skip_frame= AVDISCARD_DEFAULT;
+static enum AVDiscard skip_idct= AVDISCARD_DEFAULT;
+static enum AVDiscard skip_loop_filter= AVDISCARD_DEFAULT;
+static int error_resilience = FF_ER_CAREFUL;
+static int error_concealment = 3;
+static int decoder_reorder_pts= 0;
+
+/* current context */
+static int is_full_screen;
+static VideoState *cur_stream;
+static int64_t audio_callback_time;
+
+AVPacket flush_pkt;
+
+#define FF_ALLOC_EVENT (SDL_USEREVENT)
+#define FF_REFRESH_EVENT (SDL_USEREVENT + 1)
+#define FF_QUIT_EVENT (SDL_USEREVENT + 2)
+
+SDL_Surface *screen;
+
+/* packet queue handling */
+static void packet_queue_init(PacketQueue *q)
+{
+ memset(q, 0, sizeof(PacketQueue));
+ q->mutex = SDL_CreateMutex();
+ q->cond = SDL_CreateCond();
+}
+
+static void packet_queue_flush(PacketQueue *q)
+{
+ AVPacketList *pkt, *pkt1;
+
+ SDL_LockMutex(q->mutex);
+ for(pkt = q->first_pkt; pkt != NULL; pkt = pkt1) {
+ pkt1 = pkt->next;
+ av_free_packet(&pkt->pkt);
+ av_freep(&pkt);
+ }
+ q->last_pkt = NULL;
+ q->first_pkt = NULL;
+ q->nb_packets = 0;
+ q->size = 0;
+ SDL_UnlockMutex(q->mutex);
+}
+
+static void packet_queue_end(PacketQueue *q)
+{
+ packet_queue_flush(q);
+ SDL_DestroyMutex(q->mutex);
+ SDL_DestroyCond(q->cond);
+}
+
+static int packet_queue_put(PacketQueue *q, AVPacket *pkt)
+{
+ AVPacketList *pkt1;
+
+ /* duplicate the packet */
+ if (pkt!=&flush_pkt && av_dup_packet(pkt) < 0)
+ return -1;
+
+ pkt1 = av_malloc(sizeof(AVPacketList));
+ if (!pkt1)
+ return -1;
+ pkt1->pkt = *pkt;
+ pkt1->next = NULL;
+
+
+ SDL_LockMutex(q->mutex);
+
+ if (!q->last_pkt)
+
+ q->first_pkt = pkt1;
+ else
+ q->last_pkt->next = pkt1;
+ q->last_pkt = pkt1;
+ q->nb_packets++;
+ q->size += pkt1->pkt.size;
+ /* XXX: should duplicate packet data in DV case */
+ SDL_CondSignal(q->cond);
+
+ SDL_UnlockMutex(q->mutex);
+ return 0;
+}
+
+static void packet_queue_abort(PacketQueue *q)
+{
+ SDL_LockMutex(q->mutex);
+
+ q->abort_request = 1;
+
+ SDL_CondSignal(q->cond);
+
+ SDL_UnlockMutex(q->mutex);
+}
+
+/* return < 0 if aborted, 0 if no packet and > 0 if packet. */
+static int packet_queue_get(PacketQueue *q, AVPacket *pkt, int block)
+{
+ AVPacketList *pkt1;
+ int ret;
+
+ SDL_LockMutex(q->mutex);
+
+ for(;;) {
+ if (q->abort_request) {
+ ret = -1;
+ break;
+ }
+
+ pkt1 = q->first_pkt;
+ if (pkt1) {
+ q->first_pkt = pkt1->next;
+ if (!q->first_pkt)
+ q->last_pkt = NULL;
+ q->nb_packets--;
+ q->size -= pkt1->pkt.size;
+ *pkt = pkt1->pkt;
+ av_free(pkt1);
+ ret = 1;
+ break;
+ } else if (!block) {
+ ret = 0;
+ break;
+ } else {
+ SDL_CondWait(q->cond, q->mutex);
+ }
+ }
+ SDL_UnlockMutex(q->mutex);
+ return ret;
+}
+
+static inline void fill_rectangle(SDL_Surface *screen,
+ int x, int y, int w, int h, int color)
+{
+ SDL_Rect rect;
+ rect.x = x;
+ rect.y = y;
+ rect.w = w;
+ rect.h = h;
+ SDL_FillRect(screen, &rect, color);
+}
+
+#if 0
+/* draw only the border of a rectangle */
+void fill_border(VideoState *s, int x, int y, int w, int h, int color)
+{
+ int w1, w2, h1, h2;
+
+ /* fill the background */
+ w1 = x;
+ if (w1 < 0)
+ w1 = 0;
+ w2 = s->width - (x + w);
+ if (w2 < 0)
+ w2 = 0;
+ h1 = y;
+ if (h1 < 0)
+ h1 = 0;
+ h2 = s->height - (y + h);
+ if (h2 < 0)
+ h2 = 0;
+ fill_rectangle(screen,
+ s->xleft, s->ytop,
+ w1, s->height,
+ color);
+ fill_rectangle(screen,
+ s->xleft + s->width - w2, s->ytop,
+ w2, s->height,
+ color);
+ fill_rectangle(screen,
+ s->xleft + w1, s->ytop,
+ s->width - w1 - w2, h1,
+ color);
+ fill_rectangle(screen,
+ s->xleft + w1, s->ytop + s->height - h2,
+ s->width - w1 - w2, h2,
+ color);
+}
+#endif
+
+
+
+#define SCALEBITS 10
+#define ONE_HALF (1 << (SCALEBITS - 1))
+#define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5))
+
+#define RGB_TO_Y_CCIR(r, g, b) \
+((FIX(0.29900*219.0/255.0) * (r) + FIX(0.58700*219.0/255.0) * (g) + \
+ FIX(0.11400*219.0/255.0) * (b) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS)
+
+#define RGB_TO_U_CCIR(r1, g1, b1, shift)\
+(((- FIX(0.16874*224.0/255.0) * r1 - FIX(0.33126*224.0/255.0) * g1 + \
+ FIX(0.50000*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
+
+#define RGB_TO_V_CCIR(r1, g1, b1, shift)\
+(((FIX(0.50000*224.0/255.0) * r1 - FIX(0.41869*224.0/255.0) * g1 - \
+ FIX(0.08131*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
+
+#define ALPHA_BLEND(a, oldp, newp, s)\
+((((oldp << s) * (255 - (a))) + (newp * (a))) / (255 << s))
+
+#define RGBA_IN(r, g, b, a, s)\
+{\
+ unsigned int v = ((const uint32_t *)(s))[0];\
+ a = (v >> 24) & 0xff;\
+ r = (v >> 16) & 0xff;\
+ g = (v >> 8) & 0xff;\
+ b = v & 0xff;\
+}
+
+#define YUVA_IN(y, u, v, a, s, pal)\
+{\
+ unsigned int val = ((const uint32_t *)(pal))[*(const uint8_t*)s];\
+ a = (val >> 24) & 0xff;\
+ y = (val >> 16) & 0xff;\
+ u = (val >> 8) & 0xff;\
+ v = val & 0xff;\
+}
+
+#define YUVA_OUT(d, y, u, v, a)\
+{\
+ ((uint32_t *)(d))[0] = (a << 24) | (y << 16) | (u << 8) | v;\
+}
+
+
+#define BPP 1
+
+static void blend_subrect(AVPicture *dst, const AVSubtitleRect *rect)
+{
+ int wrap, wrap3, width2, skip2;
+ int y, u, v, a, u1, v1, a1, w, h;
+ uint8_t *lum, *cb, *cr;
+ const uint8_t *p;
+ const uint32_t *pal;
+
+ lum = dst->data[0] + rect->y * dst->linesize[0];
+ cb = dst->data[1] + (rect->y >> 1) * dst->linesize[1];
+ cr = dst->data[2] + (rect->y >> 1) * dst->linesize[2];
+
+ width2 = (rect->w + 1) >> 1;
+ skip2 = rect->x >> 1;
+ wrap = dst->linesize[0];
+ wrap3 = rect->linesize;
+ p = rect->bitmap;
+ pal = rect->rgba_palette; /* Now in YCrCb! */
+
+ if (rect->y & 1) {
+ lum += rect->x;
+ cb += skip2;
+ cr += skip2;
+
+ if (rect->x & 1) {
+ YUVA_IN(y, u, v, a, p, pal);
+ lum[0] = ALPHA_BLEND(a, lum[0], y, 0);
+ cb[0] = ALPHA_BLEND(a >> 2, cb[0], u, 0);
+ cr[0] = ALPHA_BLEND(a >> 2, cr[0], v, 0);
+ cb++;
+ cr++;
+ lum++;
+ p += BPP;
+ }
+ for(w = rect->w - (rect->x & 1); w >= 2; w -= 2) {
+ YUVA_IN(y, u, v, a, p, pal);
+ u1 = u;
+ v1 = v;
+ a1 = a;
+ lum[0] = ALPHA_BLEND(a, lum[0], y, 0);
+
+ YUVA_IN(y, u, v, a, p + BPP, pal);
+ u1 += u;
+ v1 += v;
+ a1 += a;
+ lum[1] = ALPHA_BLEND(a, lum[1], y, 0);
+ cb[0] = ALPHA_BLEND(a1 >> 2, cb[0], u1, 1);
+ cr[0] = ALPHA_BLEND(a1 >> 2, cr[0], v1, 1);
+ cb++;
+ cr++;
+ p += 2 * BPP;
+ lum += 2;
+ }
+ if (w) {
+ YUVA_IN(y, u, v, a, p, pal);
+ lum[0] = ALPHA_BLEND(a, lum[0], y, 0);
+ cb[0] = ALPHA_BLEND(a >> 2, cb[0], u, 0);
+ cr[0] = ALPHA_BLEND(a >> 2, cr[0], v, 0);
+ }
+ p += wrap3 + (wrap3 - rect->w * BPP);
+ lum += wrap + (wrap - rect->w - rect->x);
+ cb += dst->linesize[1] - width2 - skip2;
+ cr += dst->linesize[2] - width2 - skip2;
+ }
+ for(h = rect->h - (rect->y & 1); h >= 2; h -= 2) {
+ lum += rect->x;
+ cb += skip2;
+ cr += skip2;
+
+ if (rect->x & 1) {
+ YUVA_IN(y, u, v, a, p, pal);
+ u1 = u;
+ v1 = v;
+ a1 = a;
+ lum[0] = ALPHA_BLEND(a, lum[0], y, 0);
+ p += wrap3;
+ lum += wrap;
+ YUVA_IN(y, u, v, a, p, pal);
+ u1 += u;
+ v1 += v;
+ a1 += a;
+ lum[0] = ALPHA_BLEND(a, lum[0], y, 0);
+ cb[0] = ALPHA_BLEND(a1 >> 2, cb[0], u1, 1);
+ cr[0] = ALPHA_BLEND(a1 >> 2, cr[0], v1, 1);
+ cb++;
+ cr++;
+ p += -wrap3 + BPP;
+ lum += -wrap + 1;
+ }
+ for(w = rect->w - (rect->x & 1); w >= 2; w -= 2) {
+ YUVA_IN(y, u, v, a, p, pal);
+ u1 = u;
+ v1 = v;
+ a1 = a;
+ lum[0] = ALPHA_BLEND(a, lum[0], y, 0);
+
+ YUVA_IN(y, u, v, a, p, pal);
+ u1 += u;
+ v1 += v;
+ a1 += a;
+ lum[1] = ALPHA_BLEND(a, lum[1], y, 0);
+ p += wrap3;
+ lum += wrap;
+
+ YUVA_IN(y, u, v, a, p, pal);
+ u1 += u;
+ v1 += v;
+ a1 += a;
+ lum[0] = ALPHA_BLEND(a, lum[0], y, 0);
+
+ YUVA_IN(y, u, v, a, p, pal);
+ u1 += u;
+ v1 += v;
+ a1 += a;
+ lum[1] = ALPHA_BLEND(a, lum[1], y, 0);
+
+ cb[0] = ALPHA_BLEND(a1 >> 2, cb[0], u1, 2);
+ cr[0] = ALPHA_BLEND(a1 >> 2, cr[0], v1, 2);
+
+ cb++;
+ cr++;
+ p += -wrap3 + 2 * BPP;
+ lum += -wrap + 2;
+ }
+ if (w) {
+ YUVA_IN(y, u, v, a, p, pal);
+ u1 = u;
+ v1 = v;
+ a1 = a;
+ lum[0] = ALPHA_BLEND(a, lum[0], y, 0);
+ p += wrap3;
+ lum += wrap;
+ YUVA_IN(y, u, v, a, p, pal);
+ u1 += u;
+ v1 += v;
+ a1 += a;
+ lum[0] = ALPHA_BLEND(a, lum[0], y, 0);
+ cb[0] = ALPHA_BLEND(a1 >> 2, cb[0], u1, 1);
+ cr[0] = ALPHA_BLEND(a1 >> 2, cr[0], v1, 1);
+ cb++;
+ cr++;
+ p += -wrap3 + BPP;
+ lum += -wrap + 1;
+ }
+ p += wrap3 + (wrap3 - rect->w * BPP);
+ lum += wrap + (wrap - rect->w - rect->x);
+ cb += dst->linesize[1] - width2 - skip2;
+ cr += dst->linesize[2] - width2 - skip2;
+ }
+ /* handle odd height */
+ if (h) {
+ lum += rect->x;
+ cb += skip2;
+ cr += skip2;
+
+ if (rect->x & 1) {
+ YUVA_IN(y, u, v, a, p, pal);
+ lum[0] = ALPHA_BLEND(a, lum[0], y, 0);
+ cb[0] = ALPHA_BLEND(a >> 2, cb[0], u, 0);
+ cr[0] = ALPHA_BLEND(a >> 2, cr[0], v, 0);
+ cb++;
+ cr++;
+ lum++;
+ p += BPP;
+ }
+ for(w = rect->w - (rect->x & 1); w >= 2; w -= 2) {
+ YUVA_IN(y, u, v, a, p, pal);
+ u1 = u;
+ v1 = v;
+ a1 = a;
+ lum[0] = ALPHA_BLEND(a, lum[0], y, 0);
+
+ YUVA_IN(y, u, v, a, p + BPP, pal);
+ u1 += u;
+ v1 += v;
+ a1 += a;
+ lum[1] = ALPHA_BLEND(a, lum[1], y, 0);
+ cb[0] = ALPHA_BLEND(a1 >> 2, cb[0], u, 1);
+ cr[0] = ALPHA_BLEND(a1 >> 2, cr[0], v, 1);
+ cb++;
+ cr++;
+ p += 2 * BPP;
+ lum += 2;
+ }
+ if (w) {
+ YUVA_IN(y, u, v, a, p, pal);
+ lum[0] = ALPHA_BLEND(a, lum[0], y, 0);
+ cb[0] = ALPHA_BLEND(a >> 2, cb[0], u, 0);
+ cr[0] = ALPHA_BLEND(a >> 2, cr[0], v, 0);
+ }
+ }
+}
+
+static void free_subpicture(SubPicture *sp)
+{
+ int i;
+
+ for (i = 0; i < sp->sub.num_rects; i++)
+ {
+ av_free(sp->sub.rects[i].bitmap);
+ av_free(sp->sub.rects[i].rgba_palette);
+ }
+
+ av_free(sp->sub.rects);
+
+ memset(&sp->sub, 0, sizeof(AVSubtitle));
+}
+
+static void video_image_display(VideoState *is)
+{
+ VideoPicture *vp;
+ SubPicture *sp;
+ AVPicture pict;
+ float aspect_ratio;
+ int width, height, x, y;
+ SDL_Rect rect;
+ int i;
+
+ vp = &is->pictq[is->pictq_rindex];
+ if (vp->bmp) {
+ /* XXX: use variable in the frame */
+ if (is->video_st->codec->sample_aspect_ratio.num == 0)
+ aspect_ratio = 0;
+ else
+ aspect_ratio = av_q2d(is->video_st->codec->sample_aspect_ratio)
+ * is->video_st->codec->width / is->video_st->codec->height;;
+ if (aspect_ratio <= 0.0)
+ aspect_ratio = (float)is->video_st->codec->width /
+ (float)is->video_st->codec->height;
+ /* if an active format is indicated, then it overrides the
+ mpeg format */
+#if 0
+ if (is->video_st->codec->dtg_active_format != is->dtg_active_format) {
+ is->dtg_active_format = is->video_st->codec->dtg_active_format;
+ printf("dtg_active_format=%d\n", is->dtg_active_format);
+ }
+#endif
+#if 0
+ switch(is->video_st->codec->dtg_active_format) {
+ case FF_DTG_AFD_SAME:
+ default:
+ /* nothing to do */
+ break;
+ case FF_DTG_AFD_4_3:
+ aspect_ratio = 4.0 / 3.0;
+ break;
+ case FF_DTG_AFD_16_9:
+ aspect_ratio = 16.0 / 9.0;
+ break;
+ case FF_DTG_AFD_14_9:
+ aspect_ratio = 14.0 / 9.0;
+ break;
+ case FF_DTG_AFD_4_3_SP_14_9:
+ aspect_ratio = 14.0 / 9.0;
+ break;
+ case FF_DTG_AFD_16_9_SP_14_9:
+ aspect_ratio = 14.0 / 9.0;
+ break;
+ case FF_DTG_AFD_SP_4_3:
+ aspect_ratio = 4.0 / 3.0;
+ break;
+ }
+#endif
+
+ if (is->subtitle_st)
+ {
+ if (is->subpq_size > 0)
+ {
+ sp = &is->subpq[is->subpq_rindex];
+
+ if (vp->pts >= sp->pts + ((float) sp->sub.start_display_time / 1000))
+ {
+ SDL_LockYUVOverlay (vp->bmp);
+
+ pict.data[0] = vp->bmp->pixels[0];
+ pict.data[1] = vp->bmp->pixels[2];
+ pict.data[2] = vp->bmp->pixels[1];
+
+ pict.linesize[0] = vp->bmp->pitches[0];
+ pict.linesize[1] = vp->bmp->pitches[2];
+ pict.linesize[2] = vp->bmp->pitches[1];
+
+ for (i = 0; i < sp->sub.num_rects; i++)
+ blend_subrect(&pict, &sp->sub.rects[i]);
+
+ SDL_UnlockYUVOverlay (vp->bmp);
+ }
+ }
+ }
+
+
+ /* XXX: we suppose the screen has a 1.0 pixel ratio */
+ height = is->height;
+ width = ((int)rint(height * aspect_ratio)) & -3;
+ if (width > is->width) {
+ width = is->width;
+ height = ((int)rint(width / aspect_ratio)) & -3;
+ }
+ x = (is->width - width) / 2;
+ y = (is->height - height) / 2;
+ if (!is->no_background) {
+ /* fill the background */
+ // fill_border(is, x, y, width, height, QERGB(0x00, 0x00, 0x00));
+ } else {
+ is->no_background = 0;
+ }
+ rect.x = is->xleft + x;
+ rect.y = is->ytop + y;
+ rect.w = width;
+ rect.h = height;
+ SDL_DisplayYUVOverlay(vp->bmp, &rect);
+ } else {
+#if 0
+ fill_rectangle(screen,
+ is->xleft, is->ytop, is->width, is->height,
+ QERGB(0x00, 0x00, 0x00));
+#endif
+ }
+}
+
+static inline int compute_mod(int a, int b)
+{
+ a = a % b;
+ if (a >= 0)
+ return a;
+ else
+ return a + b;
+}
+
+static void video_audio_display(VideoState *s)
+{
+ int i, i_start, x, y1, y, ys, delay, n, nb_display_channels;
+ int ch, channels, h, h2, bgcolor, fgcolor;
+ int16_t time_diff;
+
+ /* compute display index : center on currently output samples */
+ channels = s->audio_st->codec->channels;
+ nb_display_channels = channels;
+ if (!s->paused) {
+ n = 2 * channels;
+ delay = audio_write_get_buf_size(s);
+ delay /= n;
+
+ /* to be more precise, we take into account the time spent since
+ the last buffer computation */
+ if (audio_callback_time) {
+ time_diff = av_gettime() - audio_callback_time;
+ delay += (time_diff * s->audio_st->codec->sample_rate) / 1000000;
+ }
+
+ delay -= s->width / 2;
+ if (delay < s->width)
+ delay = s->width;
+
+ i_start= x = compute_mod(s->sample_array_index - delay * channels, SAMPLE_ARRAY_SIZE);
+
+ h= INT_MIN;
+ for(i=0; i<1000; i+=channels){
+ int idx= (SAMPLE_ARRAY_SIZE + x - i) % SAMPLE_ARRAY_SIZE;
+ int a= s->sample_array[idx];
+ int b= s->sample_array[(idx + 4*channels)%SAMPLE_ARRAY_SIZE];
+ int c= s->sample_array[(idx + 5*channels)%SAMPLE_ARRAY_SIZE];
+ int d= s->sample_array[(idx + 9*channels)%SAMPLE_ARRAY_SIZE];
+ int score= a-d;
+ if(h<score && (b^c)<0){
+ h= score;
+ i_start= idx;
+ }
+ }
+
+ s->last_i_start = i_start;
+ } else {
+ i_start = s->last_i_start;
+ }
+
+ bgcolor = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00);
+ fill_rectangle(screen,
+ s->xleft, s->ytop, s->width, s->height,
+ bgcolor);
+
+ fgcolor = SDL_MapRGB(screen->format, 0xff, 0xff, 0xff);
+
+ /* total height for one channel */
+ h = s->height / nb_display_channels;
+ /* graph height / 2 */
+ h2 = (h * 9) / 20;
+ for(ch = 0;ch < nb_display_channels; ch++) {
+ i = i_start + ch;
+ y1 = s->ytop + ch * h + (h / 2); /* position of center line */
+ for(x = 0; x < s->width; x++) {
+ y = (s->sample_array[i] * h2) >> 15;
+ if (y < 0) {
+ y = -y;
+ ys = y1 - y;
+ } else {
+ ys = y1;
+ }
+ fill_rectangle(screen,
+ s->xleft + x, ys, 1, y,
+ fgcolor);
+ i += channels;
+ if (i >= SAMPLE_ARRAY_SIZE)
+ i -= SAMPLE_ARRAY_SIZE;
+ }
+ }
+
+ fgcolor = SDL_MapRGB(screen->format, 0x00, 0x00, 0xff);
+
+ for(ch = 1;ch < nb_display_channels; ch++) {
+ y = s->ytop + ch * h;
+ fill_rectangle(screen,
+ s->xleft, y, s->width, 1,
+ fgcolor);
+ }
+ SDL_UpdateRect(screen, s->xleft, s->ytop, s->width, s->height);
+}
+
+static int video_open(VideoState *is){
+ int flags = SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_HWACCEL;
+ int w,h;
+
+ if(is_full_screen) flags |= SDL_FULLSCREEN;
+ else flags |= SDL_RESIZABLE;
+
+ if (is_full_screen && fs_screen_width) {
+ w = fs_screen_width;
+ h = fs_screen_height;
+ } else if(!is_full_screen && screen_width){
+ w = screen_width;
+ h = screen_height;
+ }else if (is->video_st && is->video_st->codec->width){
+ w = is->video_st->codec->width;
+ h = is->video_st->codec->height;
+ } else {
+ w = 640;
+ h = 480;
+ }
+#ifndef CONFIG_DARWIN
+ screen = SDL_SetVideoMode(w, h, 0, flags);
+#else
+ /* setting bits_per_pixel = 0 or 32 causes blank video on OS X */
+ screen = SDL_SetVideoMode(w, h, 24, flags);
+#endif
+ if (!screen) {
+ fprintf(stderr, "SDL: could not set video mode - exiting\n");
+ return -1;
+ }
+ SDL_WM_SetCaption("FFplay", "FFplay");
+
+ is->width = screen->w;
+ is->height = screen->h;
+
+ return 0;
+}
+
+/* display the current picture, if any */
+static void video_display(VideoState *is)
+{
+ if(!screen)
+ video_open(cur_stream);
+ if (is->audio_st && is->show_audio)
+ video_audio_display(is);
+ else if (is->video_st)
+ video_image_display(is);
+}
+
+static Uint32 sdl_refresh_timer_cb(Uint32 interval, void *opaque)
+{
+ SDL_Event event;
+ event.type = FF_REFRESH_EVENT;
+ event.user.data1 = opaque;
+ SDL_PushEvent(&event);
+ return 0; /* 0 means stop timer */
+}
+
+/* schedule a video refresh in 'delay' ms */
+static void schedule_refresh(VideoState *is, int delay)
+{
+ SDL_AddTimer(delay, sdl_refresh_timer_cb, is);
+}
+
+/* get the current audio clock value */
+static double get_audio_clock(VideoState *is)
+{
+ double pts;
+ int hw_buf_size, bytes_per_sec;
+ pts = is->audio_clock;
+ hw_buf_size = audio_write_get_buf_size(is);
+ bytes_per_sec = 0;
+ if (is->audio_st) {
+ bytes_per_sec = is->audio_st->codec->sample_rate *
+ 2 * is->audio_st->codec->channels;
+ }
+ if (bytes_per_sec)
+ pts -= (double)hw_buf_size / bytes_per_sec;
+ return pts;
+}
+
+/* get the current video clock value */
+static double get_video_clock(VideoState *is)
+{
+ double delta;
+ if (is->paused) {
+ delta = 0;
+ } else {
+ delta = (av_gettime() - is->video_current_pts_time) / 1000000.0;
+ }
+ return is->video_current_pts + delta;
+}
+
+/* get the current external clock value */
+static double get_external_clock(VideoState *is)
+{
+ int64_t ti;
+ ti = av_gettime();
+ return is->external_clock + ((ti - is->external_clock_time) * 1e-6);
+}
+
+/* get the current master clock value */
+static double get_master_clock(VideoState *is)
+{
+ double val;
+
+ if (is->av_sync_type == AV_SYNC_VIDEO_MASTER) {
+ if (is->video_st)
+ val = get_video_clock(is);
+ else
+ val = get_audio_clock(is);
+ } else if (is->av_sync_type == AV_SYNC_AUDIO_MASTER) {
+ if (is->audio_st)
+ val = get_audio_clock(is);
+ else
+ val = get_video_clock(is);
+ } else {
+ val = get_external_clock(is);
+ }
+ return val;
+}
+
+/* seek in the stream */
+static void stream_seek(VideoState *is, int64_t pos, int rel)
+{
+ if (!is->seek_req) {
+ is->seek_pos = pos;
+ is->seek_flags = rel < 0 ? AVSEEK_FLAG_BACKWARD : 0;
+ if (seek_by_bytes)
+ is->seek_flags |= AVSEEK_FLAG_BYTE;
+ is->seek_req = 1;
+ }
+}
+
+/* pause or resume the video */
+static void stream_pause(VideoState *is)
+{
+ is->paused = !is->paused;
+ if (!is->paused) {
+ is->video_current_pts = get_video_clock(is);
+ is->frame_timer += (av_gettime() - is->video_current_pts_time) / 1000000.0;
+ }
+}
+
+/* called to display each frame */
+static void video_refresh_timer(void *opaque)
+{
+ VideoState *is = opaque;
+ VideoPicture *vp;
+ double actual_delay, delay, sync_threshold, ref_clock, diff;
+
+ SubPicture *sp, *sp2;
+
+ if (is->video_st) {
+ if (is->pictq_size == 0) {
+ /* if no picture, need to wait */
+ schedule_refresh(is, 1);
+ } else {
+ /* dequeue the picture */
+ vp = &is->pictq[is->pictq_rindex];
+
+ /* update current video pts */
+ is->video_current_pts = vp->pts;
+ is->video_current_pts_time = av_gettime();
+
+ /* compute nominal delay */
+ delay = vp->pts - is->frame_last_pts;
+ if (delay <= 0 || delay >= 1.0) {
+ /* if incorrect delay, use previous one */
+ delay = is->frame_last_delay;
+ }
+ is->frame_last_delay = delay;
+ is->frame_last_pts = vp->pts;
+
+ /* update delay to follow master synchronisation source */
+ if (((is->av_sync_type == AV_SYNC_AUDIO_MASTER && is->audio_st) ||
+ is->av_sync_type == AV_SYNC_EXTERNAL_CLOCK)) {
+ /* if video is slave, we try to correct big delays by
+ duplicating or deleting a frame */
+ ref_clock = get_master_clock(is);
+ diff = vp->pts - ref_clock;
+
+ /* skip or repeat frame. We take into account the
+ delay to compute the threshold. I still don't know
+ if it is the best guess */
+ sync_threshold = AV_SYNC_THRESHOLD;
+ if (delay > sync_threshold)
+ sync_threshold = delay;
+ if (fabs(diff) < AV_NOSYNC_THRESHOLD) {
+ if (diff <= -sync_threshold)
+ delay = 0;
+ else if (diff >= sync_threshold)
+ delay = 2 * delay;
+ }
+ }
+
+ is->frame_timer += delay;
+ /* compute the REAL delay (we need to do that to avoid
+ long term errors */
+ actual_delay = is->frame_timer - (av_gettime() / 1000000.0);
+ if (actual_delay < 0.010) {
+ /* XXX: should skip picture */
+ actual_delay = 0.010;
+ }
+ /* launch timer for next picture */
+ schedule_refresh(is, (int)(actual_delay * 1000 + 0.5));
+
+#if defined(DEBUG_SYNC)
+ printf("video: delay=%0.3f actual_delay=%0.3f pts=%0.3f A-V=%f\n",
+ delay, actual_delay, vp->pts, -diff);
+#endif
+
+ if(is->subtitle_st) {
+ if (is->subtitle_stream_changed) {
+ SDL_LockMutex(is->subpq_mutex);
+
+ while (is->subpq_size) {
+ free_subpicture(&is->subpq[is->subpq_rindex]);
+
+ /* update queue size and signal for next picture */
+ if (++is->subpq_rindex == SUBPICTURE_QUEUE_SIZE)
+ is->subpq_rindex = 0;
+
+ is->subpq_size--;
+ }
+ is->subtitle_stream_changed = 0;
+
+ SDL_CondSignal(is->subpq_cond);
+ SDL_UnlockMutex(is->subpq_mutex);
+ } else {
+ if (is->subpq_size > 0) {
+ sp = &is->subpq[is->subpq_rindex];
+
+ if (is->subpq_size > 1)
+ sp2 = &is->subpq[(is->subpq_rindex + 1) % SUBPICTURE_QUEUE_SIZE];
+ else
+ sp2 = NULL;
+
+ if ((is->video_current_pts > (sp->pts + ((float) sp->sub.end_display_time / 1000)))
+ || (sp2 && is->video_current_pts > (sp2->pts + ((float) sp2->sub.start_display_time / 1000))))
+ {
+ free_subpicture(sp);
+
+ /* update queue size and signal for next picture */
+ if (++is->subpq_rindex == SUBPICTURE_QUEUE_SIZE)
+ is->subpq_rindex = 0;
+
+ SDL_LockMutex(is->subpq_mutex);
+ is->subpq_size--;
+ SDL_CondSignal(is->subpq_cond);
+ SDL_UnlockMutex(is->subpq_mutex);
+ }
+ }
+ }
+ }
+
+ /* display picture */
+ video_display(is);
+
+ /* update queue size and signal for next picture */
+ if (++is->pictq_rindex == VIDEO_PICTURE_QUEUE_SIZE)
+ is->pictq_rindex = 0;
+
+ SDL_LockMutex(is->pictq_mutex);
+ is->pictq_size--;
+ SDL_CondSignal(is->pictq_cond);
+ SDL_UnlockMutex(is->pictq_mutex);
+ }
+ } else if (is->audio_st) {
+ /* draw the next audio frame */
+
+ schedule_refresh(is, 40);
+
+ /* if only audio stream, then display the audio bars (better
+ than nothing, just to test the implementation */
+
+ /* display picture */
+ video_display(is);
+ } else {
+ schedule_refresh(is, 100);
+ }
+ if (show_status) {
+ static int64_t last_time;
+ int64_t cur_time;
+ int aqsize, vqsize, sqsize;
+ double av_diff;
+
+ cur_time = av_gettime();
+ if (!last_time || (cur_time - last_time) >= 500 * 1000) {
+ aqsize = 0;
+ vqsize = 0;
+ sqsize = 0;
+ if (is->audio_st)
+ aqsize = is->audioq.size;
+ if (is->video_st)
+ vqsize = is->videoq.size;
+ if (is->subtitle_st)
+ sqsize = is->subtitleq.size;
+ av_diff = 0;
+ if (is->audio_st && is->video_st)
+ av_diff = get_audio_clock(is) - get_video_clock(is);
+ printf("%7.2f A-V:%7.3f aq=%5dKB vq=%5dKB sq=%5dB \r",
+ get_master_clock(is), av_diff, aqsize / 1024, vqsize / 1024, sqsize);
+ fflush(stdout);
+ last_time = cur_time;
+ }
+ }
+}
+
+/* allocate a picture (needs to do that in main thread to avoid
+ potential locking problems */
+static void alloc_picture(void *opaque)
+{
+ VideoState *is = opaque;
+ VideoPicture *vp;
+
+ vp = &is->pictq[is->pictq_windex];
+
+ if (vp->bmp)
+ SDL_FreeYUVOverlay(vp->bmp);
+
+#if 0
+ /* XXX: use generic function */
+ /* XXX: disable overlay if no hardware acceleration or if RGB format */
+ switch(is->video_st->codec->pix_fmt) {
+ case PIX_FMT_YUV420P:
+ case PIX_FMT_YUV422P:
+ case PIX_FMT_YUV444P:
+ case PIX_FMT_YUYV422:
+ case PIX_FMT_YUV410P:
+ case PIX_FMT_YUV411P:
+ is_yuv = 1;
+ break;
+ default:
+ is_yuv = 0;
+ break;
+ }
+#endif
+ vp->bmp = SDL_CreateYUVOverlay(is->video_st->codec->width,
+ is->video_st->codec->height,
+ SDL_YV12_OVERLAY,
+ screen);
+ vp->width = is->video_st->codec->width;
+ vp->height = is->video_st->codec->height;
+
+ SDL_LockMutex(is->pictq_mutex);
+ vp->allocated = 1;
+ SDL_CondSignal(is->pictq_cond);
+ SDL_UnlockMutex(is->pictq_mutex);
+}
+
+/**
+ *
+ * @param pts the dts of the pkt / pts of the frame and guessed if not known
+ */
+static int queue_picture(VideoState *is, AVFrame *src_frame, double pts)
+{
+ VideoPicture *vp;
+ int dst_pix_fmt;
+ AVPicture pict;
+ static struct SwsContext *img_convert_ctx;
+
+ /* wait until we have space to put a new picture */
+ SDL_LockMutex(is->pictq_mutex);
+ while (is->pictq_size >= VIDEO_PICTURE_QUEUE_SIZE &&
+ !is->videoq.abort_request) {
+ SDL_CondWait(is->pictq_cond, is->pictq_mutex);
+ }
+ SDL_UnlockMutex(is->pictq_mutex);
+
+ if (is->videoq.abort_request)
+ return -1;
+
+ vp = &is->pictq[is->pictq_windex];
+
+ /* alloc or resize hardware picture buffer */
+ if (!vp->bmp ||
+ vp->width != is->video_st->codec->width ||
+ vp->height != is->video_st->codec->height) {
+ SDL_Event event;
+
+ vp->allocated = 0;
+
+ /* the allocation must be done in the main thread to avoid
+ locking problems */
+ event.type = FF_ALLOC_EVENT;
+ event.user.data1 = is;
+ SDL_PushEvent(&event);
+
+ /* wait until the picture is allocated */
+ SDL_LockMutex(is->pictq_mutex);
+ while (!vp->allocated && !is->videoq.abort_request) {
+ SDL_CondWait(is->pictq_cond, is->pictq_mutex);
+ }
+ SDL_UnlockMutex(is->pictq_mutex);
+
+ if (is->videoq.abort_request)
+ return -1;
+ }
+
+ /* if the frame is not skipped, then display it */
+ if (vp->bmp) {
+ /* get a pointer on the bitmap */
+ SDL_LockYUVOverlay (vp->bmp);
+
+ dst_pix_fmt = PIX_FMT_YUV420P;
+ pict.data[0] = vp->bmp->pixels[0];
+ pict.data[1] = vp->bmp->pixels[2];
+ pict.data[2] = vp->bmp->pixels[1];
+
+ pict.linesize[0] = vp->bmp->pitches[0];
+ pict.linesize[1] = vp->bmp->pitches[2];
+ pict.linesize[2] = vp->bmp->pitches[1];
+ if (img_convert_ctx == NULL) {
+ img_convert_ctx = sws_getContext(is->video_st->codec->width,
+ is->video_st->codec->height, is->video_st->codec->pix_fmt,
+ is->video_st->codec->width, is->video_st->codec->height,
+ dst_pix_fmt, sws_flags, NULL, NULL, NULL);
+ if (img_convert_ctx == NULL) {
+ fprintf(stderr, "Cannot initialize the conversion context\n");
+ exit(1);
+ }
+ }
+ sws_scale(img_convert_ctx, src_frame->data, src_frame->linesize,
+ 0, is->video_st->codec->height, pict.data, pict.linesize);
+ /* update the bitmap content */
+ SDL_UnlockYUVOverlay(vp->bmp);
+
+ vp->pts = pts;
+
+ /* now we can update the picture count */
+ if (++is->pictq_windex == VIDEO_PICTURE_QUEUE_SIZE)
+ is->pictq_windex = 0;
+ SDL_LockMutex(is->pictq_mutex);
+ is->pictq_size++;
+ SDL_UnlockMutex(is->pictq_mutex);
+ }
+ return 0;
+}
+
+/**
+ * compute the exact PTS for the picture if it is omitted in the stream
+ * @param pts1 the dts of the pkt / pts of the frame
+ */
+static int output_picture2(VideoState *is, AVFrame *src_frame, double pts1)
+{
+ double frame_delay, pts;
+
+ pts = pts1;
+
+ if (pts != 0) {
+ /* update video clock with pts, if present */
+ is->video_clock = pts;
+ } else {
+ pts = is->video_clock;
+ }
+ /* update video clock for next frame */
+ frame_delay = av_q2d(is->video_st->codec->time_base);
+ /* for MPEG2, the frame can be repeated, so we update the
+ clock accordingly */
+ frame_delay += src_frame->repeat_pict * (frame_delay * 0.5);
+ is->video_clock += frame_delay;
+
+#if defined(DEBUG_SYNC) && 0
+ {
+ int ftype;
+ if (src_frame->pict_type == FF_B_TYPE)
+ ftype = 'B';
+ else if (src_frame->pict_type == FF_I_TYPE)
+ ftype = 'I';
+ else
+ ftype = 'P';
+ printf("frame_type=%c clock=%0.3f pts=%0.3f\n",
+ ftype, pts, pts1);
+ }
+#endif
+ return queue_picture(is, src_frame, pts);
+}
+
+static uint64_t global_video_pkt_pts= AV_NOPTS_VALUE;
+
+static int my_get_buffer(struct AVCodecContext *c, AVFrame *pic){
+ int ret= avcodec_default_get_buffer(c, pic);
+ uint64_t *pts= av_malloc(sizeof(uint64_t));
+ *pts= global_video_pkt_pts;
+ pic->opaque= pts;
+ return ret;
+}
+
+static void my_release_buffer(struct AVCodecContext *c, AVFrame *pic){
+ if(pic) av_freep(&pic->opaque);
+ avcodec_default_release_buffer(c, pic);
+}
+
+static int video_thread(void *arg)
+{
+ VideoState *is = arg;
+ AVPacket pkt1, *pkt = &pkt1;
+ int len1, got_picture;
+ AVFrame *frame= avcodec_alloc_frame();
+ double pts;
+
+ for(;;) {
+ while (is->paused && !is->videoq.abort_request) {
+ SDL_Delay(10);
+ }
+ if (packet_queue_get(&is->videoq, pkt, 1) < 0)
+ break;
+
+ if(pkt->data == flush_pkt.data){
+ avcodec_flush_buffers(is->video_st->codec);
+ continue;
+ }
+
+ /* NOTE: ipts is the PTS of the _first_ picture beginning in
+ this packet, if any */
+ global_video_pkt_pts= pkt->pts;
+ len1 = avcodec_decode_video(is->video_st->codec,
+ frame, &got_picture,
+ pkt->data, pkt->size);
+
+ if( (decoder_reorder_pts || pkt->dts == AV_NOPTS_VALUE)
+ && frame->opaque && *(uint64_t*)frame->opaque != AV_NOPTS_VALUE)
+ pts= *(uint64_t*)frame->opaque;
+ else if(pkt->dts != AV_NOPTS_VALUE)
+ pts= pkt->dts;
+ else
+ pts= 0;
+ pts *= av_q2d(is->video_st->time_base);
+
+// if (len1 < 0)
+// break;
+ if (got_picture) {
+ if (output_picture2(is, frame, pts) < 0)
+ goto the_end;
+ }
+ av_free_packet(pkt);
+ if (step)
+ if (cur_stream)
+ stream_pause(cur_stream);
+ }
+ the_end:
+ av_free(frame);
+ return 0;
+}
+
+static int subtitle_thread(void *arg)
+{
+ VideoState *is = arg;
+ SubPicture *sp;
+ AVPacket pkt1, *pkt = &pkt1;
+ int len1, got_subtitle;
+ double pts;
+ int i, j;
+ int r, g, b, y, u, v, a;
+
+ for(;;) {
+ while (is->paused && !is->subtitleq.abort_request) {
+ SDL_Delay(10);
+ }
+ if (packet_queue_get(&is->subtitleq, pkt, 1) < 0)
+ break;
+
+ if(pkt->data == flush_pkt.data){
+ avcodec_flush_buffers(is->subtitle_st->codec);
+ continue;
+ }
+ SDL_LockMutex(is->subpq_mutex);
+ while (is->subpq_size >= SUBPICTURE_QUEUE_SIZE &&
+ !is->subtitleq.abort_request) {
+ SDL_CondWait(is->subpq_cond, is->subpq_mutex);
+ }
+ SDL_UnlockMutex(is->subpq_mutex);
+
+ if (is->subtitleq.abort_request)
+ goto the_end;
+
+ sp = &is->subpq[is->subpq_windex];
+
+ /* NOTE: ipts is the PTS of the _first_ picture beginning in
+ this packet, if any */
+ pts = 0;
+ if (pkt->pts != AV_NOPTS_VALUE)
+ pts = av_q2d(is->subtitle_st->time_base)*pkt->pts;
+
+ len1 = avcodec_decode_subtitle(is->subtitle_st->codec,
+ &sp->sub, &got_subtitle,
+ pkt->data, pkt->size);
+// if (len1 < 0)
+// break;
+ if (got_subtitle && sp->sub.format == 0) {
+ sp->pts = pts;
+
+ for (i = 0; i < sp->sub.num_rects; i++)
+ {
+ for (j = 0; j < sp->sub.rects[i].nb_colors; j++)
+ {
+ RGBA_IN(r, g, b, a, sp->sub.rects[i].rgba_palette + j);
+ y = RGB_TO_Y_CCIR(r, g, b);
+ u = RGB_TO_U_CCIR(r, g, b, 0);
+ v = RGB_TO_V_CCIR(r, g, b, 0);
+ YUVA_OUT(sp->sub.rects[i].rgba_palette + j, y, u, v, a);
+ }
+ }
+
+ /* now we can update the picture count */
+ if (++is->subpq_windex == SUBPICTURE_QUEUE_SIZE)
+ is->subpq_windex = 0;
+ SDL_LockMutex(is->subpq_mutex);
+ is->subpq_size++;
+ SDL_UnlockMutex(is->subpq_mutex);
+ }
+ av_free_packet(pkt);
+// if (step)
+// if (cur_stream)
+// stream_pause(cur_stream);
+ }
+ the_end:
+ return 0;
+}
+
+/* copy samples for viewing in editor window */
+static void update_sample_display(VideoState *is, short *samples, int samples_size)
+{
+ int size, len, channels;
+
+ channels = is->audio_st->codec->channels;
+
+ size = samples_size / sizeof(short);
+ while (size > 0) {
+ len = SAMPLE_ARRAY_SIZE - is->sample_array_index;
+ if (len > size)
+ len = size;
+ memcpy(is->sample_array + is->sample_array_index, samples, len * sizeof(short));
+ samples += len;
+ is->sample_array_index += len;
+ if (is->sample_array_index >= SAMPLE_ARRAY_SIZE)
+ is->sample_array_index = 0;
+ size -= len;
+ }
+}
+
+/* return the new audio buffer size (samples can be added or deleted
+ to get better sync if video or external master clock) */
+static int synchronize_audio(VideoState *is, short *samples,
+ int samples_size1, double pts)
+{
+ int n, samples_size;
+ double ref_clock;
+
+ n = 2 * is->audio_st->codec->channels;
+ samples_size = samples_size1;
+
+ /* if not master, then we try to remove or add samples to correct the clock */
+ if (((is->av_sync_type == AV_SYNC_VIDEO_MASTER && is->video_st) ||
+ is->av_sync_type == AV_SYNC_EXTERNAL_CLOCK)) {
+ double diff, avg_diff;
+ int wanted_size, min_size, max_size, nb_samples;
+
+ ref_clock = get_master_clock(is);
+ diff = get_audio_clock(is) - ref_clock;
+
+ if (diff < AV_NOSYNC_THRESHOLD) {
+ is->audio_diff_cum = diff + is->audio_diff_avg_coef * is->audio_diff_cum;
+ if (is->audio_diff_avg_count < AUDIO_DIFF_AVG_NB) {
+ /* not enough measures to have a correct estimate */
+ is->audio_diff_avg_count++;
+ } else {
+ /* estimate the A-V difference */
+ avg_diff = is->audio_diff_cum * (1.0 - is->audio_diff_avg_coef);
+
+ if (fabs(avg_diff) >= is->audio_diff_threshold) {
+ wanted_size = samples_size + ((int)(diff * is->audio_st->codec->sample_rate) * n);
+ nb_samples = samples_size / n;
+
+ min_size = ((nb_samples * (100 - SAMPLE_CORRECTION_PERCENT_MAX)) / 100) * n;
+ max_size = ((nb_samples * (100 + SAMPLE_CORRECTION_PERCENT_MAX)) / 100) * n;
+ if (wanted_size < min_size)
+ wanted_size = min_size;
+ else if (wanted_size > max_size)
+ wanted_size = max_size;
+
+ /* add or remove samples to correction the synchro */
+ if (wanted_size < samples_size) {
+ /* remove samples */
+ samples_size = wanted_size;
+ } else if (wanted_size > samples_size) {
+ uint8_t *samples_end, *q;
+ int nb;
+
+ /* add samples */
+ nb = (samples_size - wanted_size);
+ samples_end = (uint8_t *)samples + samples_size - n;
+ q = samples_end + n;
+ while (nb > 0) {
+ memcpy(q, samples_end, n);
+ q += n;
+ nb -= n;
+ }
+ samples_size = wanted_size;
+ }
+ }
+#if 0
+ printf("diff=%f adiff=%f sample_diff=%d apts=%0.3f vpts=%0.3f %f\n",
+ diff, avg_diff, samples_size - samples_size1,
+ is->audio_clock, is->video_clock, is->audio_diff_threshold);
+#endif
+ }
+ } else {
+ /* too big difference : may be initial PTS errors, so
+ reset A-V filter */
+ is->audio_diff_avg_count = 0;
+ is->audio_diff_cum = 0;
+ }
+ }
+
+ return samples_size;
+}
+
+/* decode one audio frame and returns its uncompressed size */
+static int audio_decode_frame(VideoState *is, uint8_t *audio_buf, int buf_size, double *pts_ptr)
+{
+ AVPacket *pkt = &is->audio_pkt;
+ int n, len1, data_size;
+ double pts;
+
+ for(;;) {
+ /* NOTE: the audio packet can contain several frames */
+ while (is->audio_pkt_size > 0) {
+ data_size = buf_size;
+ len1 = avcodec_decode_audio2(is->audio_st->codec,
+ (int16_t *)audio_buf, &data_size,
+ is->audio_pkt_data, is->audio_pkt_size);
+ if (len1 < 0) {
+ /* if error, we skip the frame */
+ is->audio_pkt_size = 0;
+ break;
+ }
+
+ is->audio_pkt_data += len1;
+ is->audio_pkt_size -= len1;
+ if (data_size <= 0)
+ continue;
+ /* if no pts, then compute it */
+ pts = is->audio_clock;
+ *pts_ptr = pts;
+ n = 2 * is->audio_st->codec->channels;
+ is->audio_clock += (double)data_size /
+ (double)(n * is->audio_st->codec->sample_rate);
+#if defined(DEBUG_SYNC)
+ {
+ static double last_clock;
+ printf("audio: delay=%0.3f clock=%0.3f pts=%0.3f\n",
+ is->audio_clock - last_clock,
+ is->audio_clock, pts);
+ last_clock = is->audio_clock;
+ }
+#endif
+ return data_size;
+ }
+
+ /* free the current packet */
+ if (pkt->data)
+ av_free_packet(pkt);
+
+ if (is->paused || is->audioq.abort_request) {
+ return -1;
+ }
+
+ /* read next packet */
+ if (packet_queue_get(&is->audioq, pkt, 1) < 0)
+ return -1;
+ if(pkt->data == flush_pkt.data){
+ avcodec_flush_buffers(is->audio_st->codec);
+ continue;
+ }
+
+ is->audio_pkt_data = pkt->data;
+ is->audio_pkt_size = pkt->size;
+
+ /* if update the audio clock with the pts */
+ if (pkt->pts != AV_NOPTS_VALUE) {
+ is->audio_clock = av_q2d(is->audio_st->time_base)*pkt->pts;
+ }
+ }
+}
+
+/* get the current audio output buffer size, in samples. With SDL, we
+ cannot have a precise information */
+static int audio_write_get_buf_size(VideoState *is)
+{
+ return is->audio_buf_size - is->audio_buf_index;
+}
+
+
+/* prepare a new audio buffer */
+void sdl_audio_callback(void *opaque, Uint8 *stream, int len)
+{
+ VideoState *is = opaque;
+ int audio_size, len1;
+ double pts;
+
+ audio_callback_time = av_gettime();
+
+ while (len > 0) {
+ if (is->audio_buf_index >= is->audio_buf_size) {
+ audio_size = audio_decode_frame(is, is->audio_buf, sizeof(is->audio_buf), &pts);
+ if (audio_size < 0) {
+ /* if error, just output silence */
+ is->audio_buf_size = 1024;
+ memset(is->audio_buf, 0, is->audio_buf_size);
+ } else {
+ if (is->show_audio)
+ update_sample_display(is, (int16_t *)is->audio_buf, audio_size);
+ audio_size = synchronize_audio(is, (int16_t *)is->audio_buf, audio_size,
+ pts);
+ is->audio_buf_size = audio_size;
+ }
+ is->audio_buf_index = 0;
+ }
+ len1 = is->audio_buf_size - is->audio_buf_index;
+ if (len1 > len)
+ len1 = len;
+ memcpy(stream, (uint8_t *)is->audio_buf + is->audio_buf_index, len1);
+ len -= len1;
+ stream += len1;
+ is->audio_buf_index += len1;
+ }
+}
+
+/* open a given stream. Return 0 if OK */
+static int stream_component_open(VideoState *is, int stream_index)
+{
+ AVFormatContext *ic = is->ic;
+ AVCodecContext *enc;
+ AVCodec *codec;
+ SDL_AudioSpec wanted_spec, spec;
+
+ if (stream_index < 0 || stream_index >= ic->nb_streams)
+ return -1;
+ enc = ic->streams[stream_index]->codec;
+
+ /* prepare audio output */
+ if (enc->codec_type == CODEC_TYPE_AUDIO) {
+ wanted_spec.freq = enc->sample_rate;
+ wanted_spec.format = AUDIO_S16SYS;
+ /* hack for AC3. XXX: suppress that */
+ if (enc->channels > 2)
+ enc->channels = 2;
+ wanted_spec.channels = enc->channels;
+ wanted_spec.silence = 0;
+ wanted_spec.samples = SDL_AUDIO_BUFFER_SIZE;
+ wanted_spec.callback = sdl_audio_callback;
+ wanted_spec.userdata = is;
+ if (SDL_OpenAudio(&wanted_spec, &spec) < 0) {
+ fprintf(stderr, "SDL_OpenAudio: %s\n", SDL_GetError());
+ return -1;
+ }
+ is->audio_hw_buf_size = spec.size;
+ }
+
+ codec = avcodec_find_decoder(enc->codec_id);
+ enc->debug_mv = debug_mv;
+ enc->debug = debug;
+ enc->workaround_bugs = workaround_bugs;
+ enc->lowres = lowres;
+ if(lowres) enc->flags |= CODEC_FLAG_EMU_EDGE;
+ enc->idct_algo= idct;
+ if(fast) enc->flags2 |= CODEC_FLAG2_FAST;
+ enc->skip_frame= skip_frame;
+ enc->skip_idct= skip_idct;
+ enc->skip_loop_filter= skip_loop_filter;
+ enc->error_resilience= error_resilience;
+ enc->error_concealment= error_concealment;
+ if (!codec ||
+ avcodec_open(enc, codec) < 0)
+ return -1;
+ if(thread_count>1)
+ avcodec_thread_init(enc, thread_count);
+ enc->thread_count= thread_count;
+ switch(enc->codec_type) {
+ case CODEC_TYPE_AUDIO:
+ is->audio_stream = stream_index;
+ is->audio_st = ic->streams[stream_index];
+ is->audio_buf_size = 0;
+ is->audio_buf_index = 0;
+
+ /* init averaging filter */
+ is->audio_diff_avg_coef = exp(log(0.01) / AUDIO_DIFF_AVG_NB);
+ is->audio_diff_avg_count = 0;
+ /* since we do not have a precise anough audio fifo fullness,
+ we correct audio sync only if larger than this threshold */
+ is->audio_diff_threshold = 2.0 * SDL_AUDIO_BUFFER_SIZE / enc->sample_rate;
+
+ memset(&is->audio_pkt, 0, sizeof(is->audio_pkt));
+ packet_queue_init(&is->audioq);
+ SDL_PauseAudio(0);
+ break;
+ case CODEC_TYPE_VIDEO:
+ is->video_stream = stream_index;
+ is->video_st = ic->streams[stream_index];
+
+ is->frame_last_delay = 40e-3;
+ is->frame_timer = (double)av_gettime() / 1000000.0;
+ is->video_current_pts_time = av_gettime();
+
+ packet_queue_init(&is->videoq);
+ is->video_tid = SDL_CreateThread(video_thread, is);
+
+ enc-> get_buffer= my_get_buffer;
+ enc->release_buffer= my_release_buffer;
+ break;
+ case CODEC_TYPE_SUBTITLE:
+ is->subtitle_stream = stream_index;
+ is->subtitle_st = ic->streams[stream_index];
+ packet_queue_init(&is->subtitleq);
+
+ is->subtitle_tid = SDL_CreateThread(subtitle_thread, is);
+ break;
+ default:
+ break;
+ }
+ return 0;
+}
+
+static void stream_component_close(VideoState *is, int stream_index)
+{
+ AVFormatContext *ic = is->ic;
+ AVCodecContext *enc;
+
+ if (stream_index < 0 || stream_index >= ic->nb_streams)
+ return;
+ enc = ic->streams[stream_index]->codec;
+
+ switch(enc->codec_type) {
+ case CODEC_TYPE_AUDIO:
+ packet_queue_abort(&is->audioq);
+
+ SDL_CloseAudio();
+
+ packet_queue_end(&is->audioq);
+ break;
+ case CODEC_TYPE_VIDEO:
+ packet_queue_abort(&is->videoq);
+
+ /* note: we also signal this mutex to make sure we deblock the
+ video thread in all cases */
+ SDL_LockMutex(is->pictq_mutex);
+ SDL_CondSignal(is->pictq_cond);
+ SDL_UnlockMutex(is->pictq_mutex);
+
+ SDL_WaitThread(is->video_tid, NULL);
+
+ packet_queue_end(&is->videoq);
+ break;
+ case CODEC_TYPE_SUBTITLE:
+ packet_queue_abort(&is->subtitleq);
+
+ /* note: we also signal this mutex to make sure we deblock the
+ video thread in all cases */
+ SDL_LockMutex(is->subpq_mutex);
+ is->subtitle_stream_changed = 1;
+
+ SDL_CondSignal(is->subpq_cond);
+ SDL_UnlockMutex(is->subpq_mutex);
+
+ SDL_WaitThread(is->subtitle_tid, NULL);
+
+ packet_queue_end(&is->subtitleq);
+ break;
+ default:
+ break;
+ }
+
+ avcodec_close(enc);
+ switch(enc->codec_type) {
+ case CODEC_TYPE_AUDIO:
+ is->audio_st = NULL;
+ is->audio_stream = -1;
+ break;
+ case CODEC_TYPE_VIDEO:
+ is->video_st = NULL;
+ is->video_stream = -1;
+ break;
+ case CODEC_TYPE_SUBTITLE:
+ is->subtitle_st = NULL;
+ is->subtitle_stream = -1;
+ break;
+ default:
+ break;
+ }
+}
+
+static void dump_stream_info(const AVFormatContext *s)
+{
+ if (s->track != 0)
+ fprintf(stderr, "Track: %d\n", s->track);
+ if (s->title[0] != '\0')
+ fprintf(stderr, "Title: %s\n", s->title);
+ if (s->author[0] != '\0')
+ fprintf(stderr, "Author: %s\n", s->author);
+ if (s->copyright[0] != '\0')
+ fprintf(stderr, "Copyright: %s\n", s->copyright);
+ if (s->comment[0] != '\0')
+ fprintf(stderr, "Comment: %s\n", s->comment);
+ if (s->album[0] != '\0')
+ fprintf(stderr, "Album: %s\n", s->album);
+ if (s->year != 0)
+ fprintf(stderr, "Year: %d\n", s->year);
+ if (s->genre[0] != '\0')
+ fprintf(stderr, "Genre: %s\n", s->genre);
+}
+
+/* since we have only one decoding thread, we can use a global
+ variable instead of a thread local variable */
+static VideoState *global_video_state;
+
+static int decode_interrupt_cb(void)
+{
+ return (global_video_state && global_video_state->abort_request);
+}
+
+/* this thread gets the stream from the disk or the network */
+static int decode_thread(void *arg)
+{
+ VideoState *is = arg;
+ AVFormatContext *ic;
+ int err, i, ret, video_index, audio_index, use_play;
+ AVPacket pkt1, *pkt = &pkt1;
+ AVFormatParameters params, *ap = &params;
+
+ video_index = -1;
+ audio_index = -1;
+ is->video_stream = -1;
+ is->audio_stream = -1;
+ is->subtitle_stream = -1;
+
+ global_video_state = is;
+ url_set_interrupt_cb(decode_interrupt_cb);
+
+ memset(ap, 0, sizeof(*ap));
+ ap->initial_pause = 1; /* we force a pause when starting an RTSP
+ stream */
+
+ ap->width = frame_width;
+ ap->height= frame_height;
+ ap->time_base= (AVRational){1, 25};
+ ap->pix_fmt = frame_pix_fmt;
+
+ err = av_open_input_file(&ic, is->filename, is->iformat, 0, ap);
+ if (err < 0) {
+ print_error(is->filename, err);
+ ret = -1;
+ goto fail;
+ }
+ is->ic = ic;
+#ifdef CONFIG_NETWORK
+ use_play = (ic->iformat == &rtsp_demuxer);
+#else
+ use_play = 0;
+#endif
+
+ if(genpts)
+ ic->flags |= AVFMT_FLAG_GENPTS;
+
+ if (!use_play) {
+ err = av_find_stream_info(ic);
+ if (err < 0) {
+ fprintf(stderr, "%s: could not find codec parameters\n", is->filename);
+ ret = -1;
+ goto fail;
+ }
+ ic->pb.eof_reached= 0; //FIXME hack, ffplay maybe shouldnt use url_feof() to test for the end
+ }
+
+ /* if seeking requested, we execute it */
+ if (start_time != AV_NOPTS_VALUE) {
+ int64_t timestamp;
+
+ timestamp = start_time;
+ /* add the stream start time */
+ if (ic->start_time != AV_NOPTS_VALUE)
+ timestamp += ic->start_time;
+ ret = av_seek_frame(ic, -1, timestamp, AVSEEK_FLAG_BACKWARD);
+ if (ret < 0) {
+ fprintf(stderr, "%s: could not seek to position %0.3f\n",
+ is->filename, (double)timestamp / AV_TIME_BASE);
+ }
+ }
+
+ /* now we can begin to play (RTSP stream only) */
+ av_read_play(ic);
+
+ if (use_play) {
+ err = av_find_stream_info(ic);
+ if (err < 0) {
+ fprintf(stderr, "%s: could not find codec parameters\n", is->filename);
+ ret = -1;
+ goto fail;
+ }
+ }
+
+ for(i = 0; i < ic->nb_streams; i++) {
+ AVCodecContext *enc = ic->streams[i]->codec;
+ switch(enc->codec_type) {
+ case CODEC_TYPE_AUDIO:
+ if ((audio_index < 0 || wanted_audio_stream-- > 0) && !audio_disable)
+ audio_index = i;
+ break;
+ case CODEC_TYPE_VIDEO:
+ if (video_index < 0 && !video_disable)
+ video_index = i;
+ break;
+ default:
+ break;
+ }
+ }
+ if (show_status) {
+ dump_format(ic, 0, is->filename, 0);
+ dump_stream_info(ic);
+ }
+
+ /* open the streams */
+ if (audio_index >= 0) {
+ stream_component_open(is, audio_index);
+ }
+
+ if (video_index >= 0) {
+ stream_component_open(is, video_index);
+ } else {
+ if (!display_disable)
+ is->show_audio = 1;
+ }
+
+ if (is->video_stream < 0 && is->audio_stream < 0) {
+ fprintf(stderr, "%s: could not open codecs\n", is->filename);
+ ret = -1;
+ goto fail;
+ }
+
+ for(;;) {
+ if (is->abort_request)
+ break;
+#ifdef CONFIG_NETWORK
+ if (is->paused != is->last_paused) {
+ is->last_paused = is->paused;
+ if (is->paused)
+ av_read_pause(ic);
+ else
+ av_read_play(ic);
+ }
+ if (is->paused && ic->iformat == &rtsp_demuxer) {
+ /* wait 10 ms to avoid trying to get another packet */
+ /* XXX: horrible */
+ SDL_Delay(10);
+ continue;
+ }
+#endif
+ if (is->seek_req) {
+ int stream_index= -1;
+ int64_t seek_target= is->seek_pos;
+
+ if (is-> video_stream >= 0) stream_index= is-> video_stream;
+ else if(is-> audio_stream >= 0) stream_index= is-> audio_stream;
+ else if(is->subtitle_stream >= 0) stream_index= is->subtitle_stream;
+
+ if(stream_index>=0){
+ seek_target= av_rescale_q(seek_target, AV_TIME_BASE_Q, ic->streams[stream_index]->time_base);
+ }
+
+ ret = av_seek_frame(is->ic, stream_index, seek_target, is->seek_flags);
+ if (ret < 0) {
+ fprintf(stderr, "%s: error while seeking\n", is->ic->filename);
+ }else{
+ if (is->audio_stream >= 0) {
+ packet_queue_flush(&is->audioq);
+ packet_queue_put(&is->audioq, &flush_pkt);
+ }
+ if (is->subtitle_stream >= 0) {
+ packet_queue_flush(&is->subtitleq);
+ packet_queue_put(&is->subtitleq, &flush_pkt);
+ }
+ if (is->video_stream >= 0) {
+ packet_queue_flush(&is->videoq);
+ packet_queue_put(&is->videoq, &flush_pkt);
+ }
+ }
+ is->seek_req = 0;
+ }
+
+ /* if the queue are full, no need to read more */
+ if (is->audioq.size > MAX_AUDIOQ_SIZE ||
+ is->videoq.size > MAX_VIDEOQ_SIZE ||
+ is->subtitleq.size > MAX_SUBTITLEQ_SIZE ||
+ url_feof(&ic->pb)) {
+ /* wait 10 ms */
+ SDL_Delay(10);
+ continue;
+ }
+ ret = av_read_frame(ic, pkt);
+ if (ret < 0) {
+ if (url_ferror(&ic->pb) == 0) {
+ SDL_Delay(100); /* wait for user event */
+ continue;
+ } else
+ break;
+ }
+ if (pkt->stream_index == is->audio_stream) {
+ packet_queue_put(&is->audioq, pkt);
+ } else if (pkt->stream_index == is->video_stream) {
+ packet_queue_put(&is->videoq, pkt);
+ } else if (pkt->stream_index == is->subtitle_stream) {
+ packet_queue_put(&is->subtitleq, pkt);
+ } else {
+ av_free_packet(pkt);
+ }
+ }
+ /* wait until the end */
+ while (!is->abort_request) {
+ SDL_Delay(100);
+ }
+
+ ret = 0;
+ fail:
+ /* disable interrupting */
+ global_video_state = NULL;
+
+ /* close each stream */
+ if (is->audio_stream >= 0)
+ stream_component_close(is, is->audio_stream);
+ if (is->video_stream >= 0)
+ stream_component_close(is, is->video_stream);
+ if (is->subtitle_stream >= 0)
+ stream_component_close(is, is->subtitle_stream);
+ if (is->ic) {
+ av_close_input_file(is->ic);
+ is->ic = NULL; /* safety */
+ }
+ url_set_interrupt_cb(NULL);
+
+ if (ret != 0) {
+ SDL_Event event;
+
+ event.type = FF_QUIT_EVENT;
+ event.user.data1 = is;
+ SDL_PushEvent(&event);
+ }
+ return 0;
+}
+
+static VideoState *stream_open(const char *filename, AVInputFormat *iformat)
+{
+ VideoState *is;
+
+ is = av_mallocz(sizeof(VideoState));
+ if (!is)
+ return NULL;
+ pstrcpy(is->filename, sizeof(is->filename), filename);
+ is->iformat = iformat;
+ is->ytop = 0;
+ is->xleft = 0;
+
+ /* start video display */
+ is->pictq_mutex = SDL_CreateMutex();
+ is->pictq_cond = SDL_CreateCond();
+
+ is->subpq_mutex = SDL_CreateMutex();
+ is->subpq_cond = SDL_CreateCond();
+
+ /* add the refresh timer to draw the picture */
+ schedule_refresh(is, 40);
+
+ is->av_sync_type = av_sync_type;
+ is->parse_tid = SDL_CreateThread(decode_thread, is);
+ if (!is->parse_tid) {
+ av_free(is);
+ return NULL;
+ }
+ return is;
+}
+
+static void stream_close(VideoState *is)
+{
+ VideoPicture *vp;
+ int i;
+ /* XXX: use a special url_shutdown call to abort parse cleanly */
+ is->abort_request = 1;
+ SDL_WaitThread(is->parse_tid, NULL);
+
+ /* free all pictures */
+ for(i=0;i<VIDEO_PICTURE_QUEUE_SIZE; i++) {
+ vp = &is->pictq[i];
+ if (vp->bmp) {
+ SDL_FreeYUVOverlay(vp->bmp);
+ vp->bmp = NULL;
+ }
+ }
+ SDL_DestroyMutex(is->pictq_mutex);
+ SDL_DestroyCond(is->pictq_cond);
+ SDL_DestroyMutex(is->subpq_mutex);
+ SDL_DestroyCond(is->subpq_cond);
+}
+
+static void stream_cycle_channel(VideoState *is, int codec_type)
+{
+ AVFormatContext *ic = is->ic;
+ int start_index, stream_index;
+ AVStream *st;
+
+ if (codec_type == CODEC_TYPE_VIDEO)
+ start_index = is->video_stream;
+ else if (codec_type == CODEC_TYPE_AUDIO)
+ start_index = is->audio_stream;
+ else
+ start_index = is->subtitle_stream;
+ if (start_index < (codec_type == CODEC_TYPE_SUBTITLE ? -1 : 0))
+ return;
+ stream_index = start_index;
+ for(;;) {
+ if (++stream_index >= is->ic->nb_streams)
+ {
+ if (codec_type == CODEC_TYPE_SUBTITLE)
+ {
+ stream_index = -1;
+ goto the_end;
+ } else
+ stream_index = 0;
+ }
+ if (stream_index == start_index)
+ return;
+ st = ic->streams[stream_index];
+ if (st->codec->codec_type == codec_type) {
+ /* check that parameters are OK */
+ switch(codec_type) {
+ case CODEC_TYPE_AUDIO:
+ if (st->codec->sample_rate != 0 &&
+ st->codec->channels != 0)
+ goto the_end;
+ break;
+ case CODEC_TYPE_VIDEO:
+ case CODEC_TYPE_SUBTITLE:
+ goto the_end;
+ default:
+ break;
+ }
+ }
+ }
+ the_end:
+ stream_component_close(is, start_index);
+ stream_component_open(is, stream_index);
+}
+
+
+static void toggle_full_screen(void)
+{
+ is_full_screen = !is_full_screen;
+ if (!fs_screen_width) {
+ /* use default SDL method */
+// SDL_WM_ToggleFullScreen(screen);
+ }
+ video_open(cur_stream);
+}
+
+static void toggle_pause(void)
+{
+ if (cur_stream)
+ stream_pause(cur_stream);
+ step = 0;
+}
+
+static void step_to_next_frame(void)
+{
+ if (cur_stream) {
+ if (cur_stream->paused)
+ cur_stream->paused=0;
+ cur_stream->video_current_pts = get_video_clock(cur_stream);
+ }
+ step = 1;
+}
+
+static void do_exit(void)
+{
+ if (cur_stream) {
+ stream_close(cur_stream);
+ cur_stream = NULL;
+ }
+ if (show_status)
+ printf("\n");
+ SDL_Quit();
+ exit(0);
+}
+
+static void toggle_audio_display(void)
+{
+ if (cur_stream) {
+ cur_stream->show_audio = !cur_stream->show_audio;
+ }
+}
+
+/* handle an event sent by the GUI */
+static void event_loop(void)
+{
+ SDL_Event event;
+ double incr, pos, frac;
+
+ for(;;) {
+ SDL_WaitEvent(&event);
+ switch(event.type) {
+ case SDL_KEYDOWN:
+ switch(event.key.keysym.sym) {
+ case SDLK_ESCAPE:
+ case SDLK_q:
+ do_exit();
+ break;
+ case SDLK_f:
+ toggle_full_screen();
+ break;
+ case SDLK_p:
+ case SDLK_SPACE:
+ toggle_pause();
+ break;
+ case SDLK_s: //S: Step to next frame
+ step_to_next_frame();
+ break;
+ case SDLK_a:
+ if (cur_stream)
+ stream_cycle_channel(cur_stream, CODEC_TYPE_AUDIO);
+ break;
+ case SDLK_v:
+ if (cur_stream)
+ stream_cycle_channel(cur_stream, CODEC_TYPE_VIDEO);
+ break;
+ case SDLK_t:
+ if (cur_stream)
+ stream_cycle_channel(cur_stream, CODEC_TYPE_SUBTITLE);
+ break;
+ case SDLK_w:
+ toggle_audio_display();
+ break;
+ case SDLK_LEFT:
+ incr = -10.0;
+ goto do_seek;
+ case SDLK_RIGHT:
+ incr = 10.0;
+ goto do_seek;
+ case SDLK_UP:
+ incr = 60.0;
+ goto do_seek;
+ case SDLK_DOWN:
+ incr = -60.0;
+ do_seek:
+ if (cur_stream) {
+ if (seek_by_bytes) {
+ pos = url_ftell(&cur_stream->ic->pb);
+ if (cur_stream->ic->bit_rate)
+ incr *= cur_stream->ic->bit_rate / 60.0;
+ else
+ incr *= 180000.0;
+ pos += incr;
+ stream_seek(cur_stream, pos, incr);
+ } else {
+ pos = get_master_clock(cur_stream);
+ pos += incr;
+ stream_seek(cur_stream, (int64_t)(pos * AV_TIME_BASE), incr);
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ break;
+ case SDL_MOUSEBUTTONDOWN:
+ if (cur_stream) {
+ int ns, hh, mm, ss;
+ int tns, thh, tmm, tss;
+ tns = cur_stream->ic->duration/1000000LL;
+ thh = tns/3600;
+ tmm = (tns%3600)/60;
+ tss = (tns%60);
+ frac = (double)event.button.x/(double)cur_stream->width;
+ ns = frac*tns;
+ hh = ns/3600;
+ mm = (ns%3600)/60;
+ ss = (ns%60);
+ fprintf(stderr, "Seek to %2.0f%% (%2d:%02d:%02d) of total duration (%2d:%02d:%02d) \n", frac*100,
+ hh, mm, ss, thh, tmm, tss);
+ stream_seek(cur_stream, (int64_t)(cur_stream->ic->start_time+frac*cur_stream->ic->duration), 0);
+ }
+ break;
+ case SDL_VIDEORESIZE:
+ if (cur_stream) {
+ screen = SDL_SetVideoMode(event.resize.w, event.resize.h, 0,
+ SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_HWACCEL);
+ screen_width = cur_stream->width = event.resize.w;
+ screen_height= cur_stream->height= event.resize.h;
+ }
+ break;
+ case SDL_QUIT:
+ case FF_QUIT_EVENT:
+ do_exit();
+ break;
+ case FF_ALLOC_EVENT:
+ video_open(event.user.data1);
+ alloc_picture(event.user.data1);
+ break;
+ case FF_REFRESH_EVENT:
+ video_refresh_timer(event.user.data1);
+ break;
+ default:
+ break;
+ }
+ }
+}
+
+static void opt_frame_size(const char *arg)
+{
+ if (parse_image_size(&frame_width, &frame_height, arg) < 0) {
+ fprintf(stderr, "Incorrect frame size\n");
+ exit(1);
+ }
+ if ((frame_width % 2) != 0 || (frame_height % 2) != 0) {
+ fprintf(stderr, "Frame size must be a multiple of 2\n");
+ exit(1);
+ }
+}
+
+void opt_width(const char *arg)
+{
+ screen_width = atoi(arg);
+ if(screen_width<=0){
+ fprintf(stderr, "invalid width\n");
+ exit(1);
+ }
+}
+
+void opt_height(const char *arg)
+{
+ screen_height = atoi(arg);
+ if(screen_height<=0){
+ fprintf(stderr, "invalid height\n");
+ exit(1);
+ }
+}
+
+static void opt_format(const char *arg)
+{
+ file_iformat = av_find_input_format(arg);
+ if (!file_iformat) {
+ fprintf(stderr, "Unknown input format: %s\n", arg);
+ exit(1);
+ }
+}
+
+static void opt_frame_pix_fmt(const char *arg)
+{
+ frame_pix_fmt = avcodec_get_pix_fmt(arg);
+}
+
+#ifdef CONFIG_NETWORK
+void opt_rtp_tcp(void)
+{
+ /* only tcp protocol */
+ rtsp_default_protocols = (1 << RTSP_PROTOCOL_RTP_TCP);
+}
+#endif
+
+void opt_sync(const char *arg)
+{
+ if (!strcmp(arg, "audio"))
+ av_sync_type = AV_SYNC_AUDIO_MASTER;
+ else if (!strcmp(arg, "video"))
+ av_sync_type = AV_SYNC_VIDEO_MASTER;
+ else if (!strcmp(arg, "ext"))
+ av_sync_type = AV_SYNC_EXTERNAL_CLOCK;
+ else
+ show_help();
+}
+
+void opt_seek(const char *arg)
+{
+ start_time = parse_date(arg, 1);
+}
+
+static void opt_debug(const char *arg)
+{
+ av_log_level = 99;
+ debug = atoi(arg);
+}
+
+static void opt_vismv(const char *arg)
+{
+ debug_mv = atoi(arg);
+}
+
+static void opt_thread_count(const char *arg)
+{
+ thread_count= atoi(arg);
+#if !defined(HAVE_THREADS)
+ fprintf(stderr, "Warning: not compiled with thread support, using thread emulation\n");
+#endif
+}
+
+const OptionDef options[] = {
+ { "h", 0, {(void*)show_help}, "show help" },
+ { "x", HAS_ARG, {(void*)opt_width}, "force displayed width", "width" },
+ { "y", HAS_ARG, {(void*)opt_height}, "force displayed height", "height" },
+ { "s", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_size}, "set frame size (WxH or abbreviation)", "size" },
+ { "fs", OPT_BOOL, {(void*)&is_full_screen}, "force full screen" },
+ { "an", OPT_BOOL, {(void*)&audio_disable}, "disable audio" },
+ { "vn", OPT_BOOL, {(void*)&video_disable}, "disable video" },
+ { "ast", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&wanted_audio_stream}, "", "" },
+ { "ss", HAS_ARG, {(void*)&opt_seek}, "seek to a given position in seconds", "pos" },
+ { "bytes", OPT_BOOL, {(void*)&seek_by_bytes}, "seek by bytes" },
+ { "nodisp", OPT_BOOL, {(void*)&display_disable}, "disable graphical display" },
+ { "f", HAS_ARG, {(void*)opt_format}, "force format", "fmt" },
+ { "pix_fmt", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_frame_pix_fmt}, "set pixel format", "format" },
+ { "stats", OPT_BOOL | OPT_EXPERT, {(void*)&show_status}, "show status", "" },
+ { "debug", HAS_ARG | OPT_EXPERT, {(void*)opt_debug}, "print specific debug info", "" },
+ { "bug", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&workaround_bugs}, "workaround bugs", "" },
+ { "vismv", HAS_ARG | OPT_EXPERT, {(void*)opt_vismv}, "visualize motion vectors", "" },
+ { "fast", OPT_BOOL | OPT_EXPERT, {(void*)&fast}, "non spec compliant optimizations", "" },
+ { "genpts", OPT_BOOL | OPT_EXPERT, {(void*)&genpts}, "generate pts", "" },
+ { "drp", OPT_BOOL |OPT_EXPERT, {(void*)&decoder_reorder_pts}, "let decoder reorder pts", ""},
+ { "lowres", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&lowres}, "", "" },
+ { "skiploop", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&skip_loop_filter}, "", "" },
+ { "skipframe", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&skip_frame}, "", "" },
+ { "skipidct", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&skip_idct}, "", "" },
+ { "idct", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&idct}, "set idct algo", "algo" },
+ { "er", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&error_resilience}, "set error detection threshold (0-4)", "threshold" },
+ { "ec", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&error_concealment}, "set error concealment options", "bit_mask" },
+#ifdef CONFIG_NETWORK
+ { "rtp_tcp", OPT_EXPERT, {(void*)&opt_rtp_tcp}, "force RTP/TCP protocol usage", "" },
+#endif
+ { "sync", HAS_ARG | OPT_EXPERT, {(void*)opt_sync}, "set audio-video sync. type (type=audio/video/ext)", "type" },
+ { "threads", HAS_ARG | OPT_EXPERT, {(void*)opt_thread_count}, "thread count", "count" },
+ { NULL, },
+};
+
+void show_help(void)
+{
+ printf("ffplay version " FFMPEG_VERSION ", Copyright (c) 2003-2006 Fabrice Bellard, et al.\n"
+ "usage: ffplay [options] input_file\n"
+ "Simple media player\n");
+ printf("\n");
+ show_help_options(options, "Main options:\n",
+ OPT_EXPERT, 0);
+ show_help_options(options, "\nAdvanced options:\n",
+ OPT_EXPERT, OPT_EXPERT);
+ printf("\nWhile playing:\n"
+ "q, ESC quit\n"
+ "f toggle full screen\n"
+ "p, SPC pause\n"
+ "a cycle audio channel\n"
+ "v cycle video channel\n"
+ "t cycle subtitle channel\n"
+ "w show audio waves\n"
+ "left/right seek backward/forward 10 seconds\n"
+ "down/up seek backward/forward 1 minute\n"
+ "mouse click seek to percentage in file corresponding to fraction of width\n"
+ );
+ exit(1);
+}
+
+void parse_arg_file(const char *filename)
+{
+ if (!strcmp(filename, "-"))
+ filename = "pipe:";
+ input_filename = filename;
+}
+
+/* Called from the main */
+int main(int argc, char **argv)
+{
+ int flags;
+
+ /* register all codecs, demux and protocols */
+ av_register_all();
+
+ #ifdef CONFIG_OS2
+ MorphToPM(); // Morph the VIO application to a PM one to be able to use Win* functions
+
+ // Make stdout and stderr unbuffered
+ setbuf( stdout, NULL );
+ setbuf( stderr, NULL );
+ #endif
+
+ parse_options(argc, argv, options);
+
+ if (!input_filename)
+ show_help();
+
+ if (display_disable) {
+ video_disable = 1;
+ }
+ flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER;
+#if !defined(__MINGW32__) && !defined(CONFIG_DARWIN)
+ flags |= SDL_INIT_EVENTTHREAD; /* Not supported on win32 or darwin */
+#endif
+ if (SDL_Init (flags)) {
+ fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError());
+ exit(1);
+ }
+
+ if (!display_disable) {
+#ifdef HAVE_SDL_VIDEO_SIZE
+ const SDL_VideoInfo *vi = SDL_GetVideoInfo();
+ fs_screen_width = vi->current_w;
+ fs_screen_height = vi->current_h;
+#endif
+ }
+
+ SDL_EventState(SDL_ACTIVEEVENT, SDL_IGNORE);
+ SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
+ SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE);
+ SDL_EventState(SDL_USEREVENT, SDL_IGNORE);
+
+ av_init_packet(&flush_pkt);
+ flush_pkt.data= "FLUSH";
+
+ cur_stream = stream_open(input_filename, file_iformat);
+
+ event_loop();
+
+ /* never returns */
+
+ return 0;
+}
diff --git a/contrib/ffmpeg/ffserver.c b/contrib/ffmpeg/ffserver.c
new file mode 100644
index 000000000..063ac5a02
--- /dev/null
+++ b/contrib/ffmpeg/ffserver.c
@@ -0,0 +1,4608 @@
+/*
+ * Multiple format streaming server
+ * Copyright (c) 2000, 2001, 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
+ */
+#define HAVE_AV_CONFIG_H
+#include "avformat.h"
+
+#include <stdarg.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#ifdef HAVE_SYS_POLL_H
+#include <sys/poll.h>
+#endif
+#include <errno.h>
+#include <sys/time.h>
+#undef time //needed because HAVE_AV_CONFIG_H is defined on top
+#include <time.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/wait.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <signal.h>
+#ifdef HAVE_DLFCN_H
+#include <dlfcn.h>
+#endif
+
+#include "version.h"
+#include "ffserver.h"
+#include "random.h"
+
+#undef exit
+
+/* maximum number of simultaneous HTTP connections */
+#define HTTP_MAX_CONNECTIONS 2000
+
+enum HTTPState {
+ HTTPSTATE_WAIT_REQUEST,
+ HTTPSTATE_SEND_HEADER,
+ HTTPSTATE_SEND_DATA_HEADER,
+ HTTPSTATE_SEND_DATA, /* sending TCP or UDP data */
+ HTTPSTATE_SEND_DATA_TRAILER,
+ HTTPSTATE_RECEIVE_DATA,
+ HTTPSTATE_WAIT_FEED, /* wait for data from the feed */
+ HTTPSTATE_READY,
+
+ RTSPSTATE_WAIT_REQUEST,
+ RTSPSTATE_SEND_REPLY,
+ RTSPSTATE_SEND_PACKET,
+};
+
+const char *http_state[] = {
+ "HTTP_WAIT_REQUEST",
+ "HTTP_SEND_HEADER",
+
+ "SEND_DATA_HEADER",
+ "SEND_DATA",
+ "SEND_DATA_TRAILER",
+ "RECEIVE_DATA",
+ "WAIT_FEED",
+ "READY",
+
+ "RTSP_WAIT_REQUEST",
+ "RTSP_SEND_REPLY",
+ "RTSP_SEND_PACKET",
+};
+
+#define IOBUFFER_INIT_SIZE 8192
+
+/* timeouts are in ms */
+#define HTTP_REQUEST_TIMEOUT (15 * 1000)
+#define RTSP_REQUEST_TIMEOUT (3600 * 24 * 1000)
+
+#define SYNC_TIMEOUT (10 * 1000)
+
+typedef struct {
+ int64_t count1, count2;
+ int64_t time1, time2;
+} DataRateData;
+
+/* context associated with one connection */
+typedef struct HTTPContext {
+ enum HTTPState state;
+ int fd; /* socket file descriptor */
+ struct sockaddr_in from_addr; /* origin */
+ struct pollfd *poll_entry; /* used when polling */
+ int64_t timeout;
+ uint8_t *buffer_ptr, *buffer_end;
+ int http_error;
+ int post;
+ struct HTTPContext *next;
+ int got_key_frame; /* stream 0 => 1, stream 1 => 2, stream 2=> 4 */
+ int64_t data_count;
+ /* feed input */
+ int feed_fd;
+ /* input format handling */
+ AVFormatContext *fmt_in;
+ int64_t start_time; /* In milliseconds - this wraps fairly often */
+ int64_t first_pts; /* initial pts value */
+ int64_t cur_pts; /* current pts value from the stream in us */
+ int64_t cur_frame_duration; /* duration of the current frame in us */
+ int cur_frame_bytes; /* output frame size, needed to compute
+ the time at which we send each
+ packet */
+ int pts_stream_index; /* stream we choose as clock reference */
+ int64_t cur_clock; /* current clock reference value in us */
+ /* output format handling */
+ struct FFStream *stream;
+ /* -1 is invalid stream */
+ int feed_streams[MAX_STREAMS]; /* index of streams in the feed */
+ int switch_feed_streams[MAX_STREAMS]; /* index of streams in the feed */
+ int switch_pending;
+ AVFormatContext fmt_ctx; /* instance of FFStream for one user */
+ int last_packet_sent; /* true if last data packet was sent */
+ int suppress_log;
+ DataRateData datarate;
+ int wmp_client_id;
+ char protocol[16];
+ char method[16];
+ char url[128];
+ int buffer_size;
+ uint8_t *buffer;
+ int is_packetized; /* if true, the stream is packetized */
+ int packet_stream_index; /* current stream for output in state machine */
+
+ /* RTSP state specific */
+ uint8_t *pb_buffer; /* XXX: use that in all the code */
+ ByteIOContext *pb;
+ int seq; /* RTSP sequence number */
+
+ /* RTP state specific */
+ enum RTSPProtocol rtp_protocol;
+ char session_id[32]; /* session id */
+ AVFormatContext *rtp_ctx[MAX_STREAMS];
+
+ /* RTP/UDP specific */
+ URLContext *rtp_handles[MAX_STREAMS];
+
+ /* RTP/TCP specific */
+ struct HTTPContext *rtsp_c;
+ uint8_t *packet_buffer, *packet_buffer_ptr, *packet_buffer_end;
+} HTTPContext;
+
+static AVFrame dummy_frame;
+
+/* each generated stream is described here */
+enum StreamType {
+ STREAM_TYPE_LIVE,
+ STREAM_TYPE_STATUS,
+ STREAM_TYPE_REDIRECT,
+};
+
+enum IPAddressAction {
+ IP_ALLOW = 1,
+ IP_DENY,
+};
+
+typedef struct IPAddressACL {
+ struct IPAddressACL *next;
+ enum IPAddressAction action;
+ /* These are in host order */
+ struct in_addr first;
+ struct in_addr last;
+} IPAddressACL;
+
+/* description of each stream of the ffserver.conf file */
+typedef struct FFStream {
+ enum StreamType stream_type;
+ char filename[1024]; /* stream filename */
+ struct FFStream *feed; /* feed we are using (can be null if
+ coming from file) */
+ AVFormatParameters *ap_in; /* input parameters */
+ AVInputFormat *ifmt; /* if non NULL, force input format */
+ AVOutputFormat *fmt;
+ IPAddressACL *acl;
+ int nb_streams;
+ int prebuffer; /* Number of millseconds early to start */
+ int64_t max_time; /* Number of milliseconds to run */
+ int send_on_key;
+ AVStream *streams[MAX_STREAMS];
+ int feed_streams[MAX_STREAMS]; /* index of streams in the feed */
+ char feed_filename[1024]; /* file name of the feed storage, or
+ input file name for a stream */
+ char author[512];
+ char title[512];
+ char copyright[512];
+ char comment[512];
+ pid_t pid; /* Of ffmpeg process */
+ time_t pid_start; /* Of ffmpeg process */
+ char **child_argv;
+ struct FFStream *next;
+ int bandwidth; /* bandwidth, in kbits/s */
+ /* RTSP options */
+ char *rtsp_option;
+ /* multicast specific */
+ int is_multicast;
+ struct in_addr multicast_ip;
+ int multicast_port; /* first port used for multicast */
+ int multicast_ttl;
+ int loop; /* if true, send the stream in loops (only meaningful if file) */
+
+ /* feed specific */
+ int feed_opened; /* true if someone is writing to the feed */
+ int is_feed; /* true if it is a feed */
+ int readonly; /* True if writing is prohibited to the file */
+ int conns_served;
+ int64_t bytes_served;
+ int64_t feed_max_size; /* maximum storage size, zero means unlimited */
+ int64_t feed_write_index; /* current write position in feed (it wraps round) */
+ int64_t feed_size; /* current size of feed */
+ struct FFStream *next_feed;
+} FFStream;
+
+typedef struct FeedData {
+ long long data_count;
+ float avg_frame_size; /* frame size averraged over last frames with exponential mean */
+} FeedData;
+
+struct sockaddr_in my_http_addr;
+struct sockaddr_in my_rtsp_addr;
+
+static char logfilename[1024];
+static HTTPContext *first_http_ctx;
+static FFStream *first_feed; /* contains only feeds */
+static FFStream *first_stream; /* contains all streams, including feeds */
+
+static void new_connection(int server_fd, int is_rtsp);
+static void close_connection(HTTPContext *c);
+
+/* HTTP handling */
+static int handle_connection(HTTPContext *c);
+static int http_parse_request(HTTPContext *c);
+static int http_send_data(HTTPContext *c);
+static void compute_stats(HTTPContext *c);
+static int open_input_stream(HTTPContext *c, const char *info);
+static int http_start_receive_data(HTTPContext *c);
+static int http_receive_data(HTTPContext *c);
+
+/* RTSP handling */
+static int rtsp_parse_request(HTTPContext *c);
+static void rtsp_cmd_describe(HTTPContext *c, const char *url);
+static void rtsp_cmd_options(HTTPContext *c, const char *url);
+static void rtsp_cmd_setup(HTTPContext *c, const char *url, RTSPHeader *h);
+static void rtsp_cmd_play(HTTPContext *c, const char *url, RTSPHeader *h);
+static void rtsp_cmd_pause(HTTPContext *c, const char *url, RTSPHeader *h);
+static void rtsp_cmd_teardown(HTTPContext *c, const char *url, RTSPHeader *h);
+
+/* SDP handling */
+static int prepare_sdp_description(FFStream *stream, uint8_t **pbuffer,
+ struct in_addr my_ip);
+
+/* RTP handling */
+static HTTPContext *rtp_new_connection(struct sockaddr_in *from_addr,
+ FFStream *stream, const char *session_id,
+ enum RTSPProtocol rtp_protocol);
+static int rtp_new_av_stream(HTTPContext *c,
+ int stream_index, struct sockaddr_in *dest_addr,
+ HTTPContext *rtsp_c);
+
+static const char *my_program_name;
+static const char *my_program_dir;
+
+static int ffserver_debug;
+static int ffserver_daemon;
+static int no_launch;
+static int need_to_start_children;
+
+static int nb_max_connections;
+static int nb_connections;
+
+static int max_bandwidth;
+static int current_bandwidth;
+
+static int64_t cur_time; // Making this global saves on passing it around everywhere
+
+static AVRandomState random_state;
+
+static FILE *logfile = NULL;
+
+static void __attribute__ ((format (printf, 1, 2))) http_log(const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+
+ if (logfile) {
+ vfprintf(logfile, fmt, ap);
+ fflush(logfile);
+ }
+ va_end(ap);
+}
+
+static char *ctime1(char *buf2)
+{
+ time_t ti;
+ char *p;
+
+ ti = time(NULL);
+ p = ctime(&ti);
+ strcpy(buf2, p);
+ p = buf2 + strlen(p) - 1;
+ if (*p == '\n')
+ *p = '\0';
+ return buf2;
+}
+
+static void log_connection(HTTPContext *c)
+{
+ char buf2[32];
+
+ if (c->suppress_log)
+ return;
+
+ http_log("%s - - [%s] \"%s %s %s\" %d %"PRId64"\n",
+ inet_ntoa(c->from_addr.sin_addr),
+ ctime1(buf2), c->method, c->url,
+ c->protocol, (c->http_error ? c->http_error : 200), c->data_count);
+}
+
+static void update_datarate(DataRateData *drd, int64_t count)
+{
+ if (!drd->time1 && !drd->count1) {
+ drd->time1 = drd->time2 = cur_time;
+ drd->count1 = drd->count2 = count;
+ } else {
+ if (cur_time - drd->time2 > 5000) {
+ drd->time1 = drd->time2;
+ drd->count1 = drd->count2;
+ drd->time2 = cur_time;
+ drd->count2 = count;
+ }
+ }
+}
+
+/* In bytes per second */
+static int compute_datarate(DataRateData *drd, int64_t count)
+{
+ if (cur_time == drd->time1)
+ return 0;
+
+ return ((count - drd->count1) * 1000) / (cur_time - drd->time1);
+}
+
+
+static void start_children(FFStream *feed)
+{
+ if (no_launch)
+ return;
+
+ for (; feed; feed = feed->next) {
+ if (feed->child_argv && !feed->pid) {
+ feed->pid_start = time(0);
+
+ feed->pid = fork();
+
+ if (feed->pid < 0) {
+ fprintf(stderr, "Unable to create children\n");
+ exit(1);
+ }
+ if (!feed->pid) {
+ /* In child */
+ char pathname[1024];
+ char *slash;
+ int i;
+
+ for (i = 3; i < 256; i++) {
+ close(i);
+ }
+
+ if (!ffserver_debug) {
+ i = open("/dev/null", O_RDWR);
+ if (i)
+ dup2(i, 0);
+ dup2(i, 1);
+ dup2(i, 2);
+ if (i)
+ close(i);
+ }
+
+ pstrcpy(pathname, sizeof(pathname), my_program_name);
+
+ slash = strrchr(pathname, '/');
+ if (!slash) {
+ slash = pathname;
+ } else {
+ slash++;
+ }
+ strcpy(slash, "ffmpeg");
+
+ /* This is needed to make relative pathnames work */
+ chdir(my_program_dir);
+
+ signal(SIGPIPE, SIG_DFL);
+
+ execvp(pathname, feed->child_argv);
+
+ _exit(1);
+ }
+ }
+ }
+}
+
+/* open a listening socket */
+static int socket_open_listen(struct sockaddr_in *my_addr)
+{
+ int server_fd, tmp;
+
+ server_fd = socket(AF_INET,SOCK_STREAM,0);
+ if (server_fd < 0) {
+ perror ("socket");
+ return -1;
+ }
+
+ tmp = 1;
+ setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &tmp, sizeof(tmp));
+
+ if (bind (server_fd, (struct sockaddr *) my_addr, sizeof (*my_addr)) < 0) {
+ char bindmsg[32];
+ snprintf(bindmsg, sizeof(bindmsg), "bind(port %d)", ntohs(my_addr->sin_port));
+ perror (bindmsg);
+ closesocket(server_fd);
+ return -1;
+ }
+
+ if (listen (server_fd, 5) < 0) {
+ perror ("listen");
+ closesocket(server_fd);
+ return -1;
+ }
+ fcntl(server_fd, F_SETFL, O_NONBLOCK);
+
+ return server_fd;
+}
+
+/* start all multicast streams */
+static void start_multicast(void)
+{
+ FFStream *stream;
+ char session_id[32];
+ HTTPContext *rtp_c;
+ struct sockaddr_in dest_addr;
+ int default_port, stream_index;
+
+ default_port = 6000;
+ for(stream = first_stream; stream != NULL; stream = stream->next) {
+ if (stream->is_multicast) {
+ /* open the RTP connection */
+ snprintf(session_id, sizeof(session_id), "%08x%08x",
+ av_random(&random_state), av_random(&random_state));
+
+ /* choose a port if none given */
+ if (stream->multicast_port == 0) {
+ stream->multicast_port = default_port;
+ default_port += 100;
+ }
+
+ dest_addr.sin_family = AF_INET;
+ dest_addr.sin_addr = stream->multicast_ip;
+ dest_addr.sin_port = htons(stream->multicast_port);
+
+ rtp_c = rtp_new_connection(&dest_addr, stream, session_id,
+ RTSP_PROTOCOL_RTP_UDP_MULTICAST);
+ if (!rtp_c) {
+ continue;
+ }
+ if (open_input_stream(rtp_c, "") < 0) {
+ fprintf(stderr, "Could not open input stream for stream '%s'\n",
+ stream->filename);
+ continue;
+ }
+
+ /* open each RTP stream */
+ for(stream_index = 0; stream_index < stream->nb_streams;
+ stream_index++) {
+ dest_addr.sin_port = htons(stream->multicast_port +
+ 2 * stream_index);
+ if (rtp_new_av_stream(rtp_c, stream_index, &dest_addr, NULL) < 0) {
+ fprintf(stderr, "Could not open output stream '%s/streamid=%d'\n",
+ stream->filename, stream_index);
+ exit(1);
+ }
+ }
+
+ /* change state to send data */
+ rtp_c->state = HTTPSTATE_SEND_DATA;
+ }
+ }
+}
+
+/* main loop of the http server */
+static int http_server(void)
+{
+ int server_fd, ret, rtsp_server_fd, delay, delay1;
+ struct pollfd poll_table[HTTP_MAX_CONNECTIONS + 2], *poll_entry;
+ HTTPContext *c, *c_next;
+
+ server_fd = socket_open_listen(&my_http_addr);
+ if (server_fd < 0)
+ return -1;
+
+ rtsp_server_fd = socket_open_listen(&my_rtsp_addr);
+ if (rtsp_server_fd < 0)
+ return -1;
+
+ http_log("ffserver started.\n");
+
+ start_children(first_feed);
+
+ first_http_ctx = NULL;
+ nb_connections = 0;
+
+ start_multicast();
+
+ for(;;) {
+ poll_entry = poll_table;
+ poll_entry->fd = server_fd;
+ poll_entry->events = POLLIN;
+ poll_entry++;
+
+ poll_entry->fd = rtsp_server_fd;
+ poll_entry->events = POLLIN;
+ poll_entry++;
+
+ /* wait for events on each HTTP handle */
+ c = first_http_ctx;
+ delay = 1000;
+ while (c != NULL) {
+ int fd;
+ fd = c->fd;
+ switch(c->state) {
+ case HTTPSTATE_SEND_HEADER:
+ case RTSPSTATE_SEND_REPLY:
+ case RTSPSTATE_SEND_PACKET:
+ c->poll_entry = poll_entry;
+ poll_entry->fd = fd;
+ poll_entry->events = POLLOUT;
+ poll_entry++;
+ break;
+ case HTTPSTATE_SEND_DATA_HEADER:
+ case HTTPSTATE_SEND_DATA:
+ case HTTPSTATE_SEND_DATA_TRAILER:
+ if (!c->is_packetized) {
+ /* for TCP, we output as much as we can (may need to put a limit) */
+ c->poll_entry = poll_entry;
+ poll_entry->fd = fd;
+ poll_entry->events = POLLOUT;
+ poll_entry++;
+ } else {
+ /* when ffserver is doing the timing, we work by
+ looking at which packet need to be sent every
+ 10 ms */
+ delay1 = 10; /* one tick wait XXX: 10 ms assumed */
+ if (delay1 < delay)
+ delay = delay1;
+ }
+ break;
+ case HTTPSTATE_WAIT_REQUEST:
+ case HTTPSTATE_RECEIVE_DATA:
+ case HTTPSTATE_WAIT_FEED:
+ case RTSPSTATE_WAIT_REQUEST:
+ /* need to catch errors */
+ c->poll_entry = poll_entry;
+ poll_entry->fd = fd;
+ poll_entry->events = POLLIN;/* Maybe this will work */
+ poll_entry++;
+ break;
+ default:
+ c->poll_entry = NULL;
+ break;
+ }
+ c = c->next;
+ }
+
+ /* wait for an event on one connection. We poll at least every
+ second to handle timeouts */
+ do {
+ ret = poll(poll_table, poll_entry - poll_table, delay);
+ if (ret < 0 && errno != EAGAIN && errno != EINTR)
+ return -1;
+ } while (ret <= 0);
+
+ cur_time = av_gettime() / 1000;
+
+ if (need_to_start_children) {
+ need_to_start_children = 0;
+ start_children(first_feed);
+ }
+
+ /* now handle the events */
+ for(c = first_http_ctx; c != NULL; c = c_next) {
+ c_next = c->next;
+ if (handle_connection(c) < 0) {
+ /* close and free the connection */
+ log_connection(c);
+ close_connection(c);
+ }
+ }
+
+ poll_entry = poll_table;
+ /* new HTTP connection request ? */
+ if (poll_entry->revents & POLLIN) {
+ new_connection(server_fd, 0);
+ }
+ poll_entry++;
+ /* new RTSP connection request ? */
+ if (poll_entry->revents & POLLIN) {
+ new_connection(rtsp_server_fd, 1);
+ }
+ }
+}
+
+/* start waiting for a new HTTP/RTSP request */
+static void start_wait_request(HTTPContext *c, int is_rtsp)
+{
+ c->buffer_ptr = c->buffer;
+ c->buffer_end = c->buffer + c->buffer_size - 1; /* leave room for '\0' */
+
+ if (is_rtsp) {
+ c->timeout = cur_time + RTSP_REQUEST_TIMEOUT;
+ c->state = RTSPSTATE_WAIT_REQUEST;
+ } else {
+ c->timeout = cur_time + HTTP_REQUEST_TIMEOUT;
+ c->state = HTTPSTATE_WAIT_REQUEST;
+ }
+}
+
+static void new_connection(int server_fd, int is_rtsp)
+{
+ struct sockaddr_in from_addr;
+ int fd, len;
+ HTTPContext *c = NULL;
+
+ len = sizeof(from_addr);
+ fd = accept(server_fd, (struct sockaddr *)&from_addr,
+ &len);
+ if (fd < 0)
+ return;
+ fcntl(fd, F_SETFL, O_NONBLOCK);
+
+ /* XXX: should output a warning page when coming
+ close to the connection limit */
+ if (nb_connections >= nb_max_connections)
+ goto fail;
+
+ /* add a new connection */
+ c = av_mallocz(sizeof(HTTPContext));
+ if (!c)
+ goto fail;
+
+ c->fd = fd;
+ c->poll_entry = NULL;
+ c->from_addr = from_addr;
+ c->buffer_size = IOBUFFER_INIT_SIZE;
+ c->buffer = av_malloc(c->buffer_size);
+ if (!c->buffer)
+ goto fail;
+
+ c->next = first_http_ctx;
+ first_http_ctx = c;
+ nb_connections++;
+
+ start_wait_request(c, is_rtsp);
+
+ return;
+
+ fail:
+ if (c) {
+ av_free(c->buffer);
+ av_free(c);
+ }
+ closesocket(fd);
+}
+
+static void close_connection(HTTPContext *c)
+{
+ HTTPContext **cp, *c1;
+ int i, nb_streams;
+ AVFormatContext *ctx;
+ URLContext *h;
+ AVStream *st;
+
+ /* remove connection from list */
+ cp = &first_http_ctx;
+ while ((*cp) != NULL) {
+ c1 = *cp;
+ if (c1 == c) {
+ *cp = c->next;
+ } else {
+ cp = &c1->next;
+ }
+ }
+
+ /* remove references, if any (XXX: do it faster) */
+ for(c1 = first_http_ctx; c1 != NULL; c1 = c1->next) {
+ if (c1->rtsp_c == c)
+ c1->rtsp_c = NULL;
+ }
+
+ /* remove connection associated resources */
+ if (c->fd >= 0)
+ closesocket(c->fd);
+ if (c->fmt_in) {
+ /* close each frame parser */
+ for(i=0;i<c->fmt_in->nb_streams;i++) {
+ st = c->fmt_in->streams[i];
+ if (st->codec->codec) {
+ avcodec_close(st->codec);
+ }
+ }
+ av_close_input_file(c->fmt_in);
+ }
+
+ /* free RTP output streams if any */
+ nb_streams = 0;
+ if (c->stream)
+ nb_streams = c->stream->nb_streams;
+
+ for(i=0;i<nb_streams;i++) {
+ ctx = c->rtp_ctx[i];
+ if (ctx) {
+ av_write_trailer(ctx);
+ av_free(ctx);
+ }
+ h = c->rtp_handles[i];
+ if (h) {
+ url_close(h);
+ }
+ }
+
+ ctx = &c->fmt_ctx;
+
+ if (!c->last_packet_sent) {
+ if (ctx->oformat) {
+ /* prepare header */
+ if (url_open_dyn_buf(&ctx->pb) >= 0) {
+ av_write_trailer(ctx);
+ url_close_dyn_buf(&ctx->pb, &c->pb_buffer);
+ }
+ }
+ }
+
+ for(i=0; i<ctx->nb_streams; i++)
+ av_free(ctx->streams[i]) ;
+
+ if (c->stream && !c->post && c->stream->stream_type == STREAM_TYPE_LIVE)
+ current_bandwidth -= c->stream->bandwidth;
+
+ /* signal that there is no feed if we are the feeder socket */
+ if (c->state == HTTPSTATE_RECEIVE_DATA && c->stream) {
+ c->stream->feed_opened = 0;
+ close(c->feed_fd);
+ }
+
+ av_freep(&c->pb_buffer);
+ av_freep(&c->packet_buffer);
+ av_free(c->buffer);
+ av_free(c);
+ nb_connections--;
+}
+
+static int handle_connection(HTTPContext *c)
+{
+ int len, ret;
+
+ switch(c->state) {
+ case HTTPSTATE_WAIT_REQUEST:
+ case RTSPSTATE_WAIT_REQUEST:
+ /* timeout ? */
+ if ((c->timeout - cur_time) < 0)
+ return -1;
+ if (c->poll_entry->revents & (POLLERR | POLLHUP))
+ return -1;
+
+ /* no need to read if no events */
+ if (!(c->poll_entry->revents & POLLIN))
+ return 0;
+ /* read the data */
+ read_loop:
+ len = recv(c->fd, c->buffer_ptr, 1, 0);
+ if (len < 0) {
+ if (errno != EAGAIN && errno != EINTR)
+ return -1;
+ } else if (len == 0) {
+ return -1;
+ } else {
+ /* search for end of request. */
+ uint8_t *ptr;
+ c->buffer_ptr += len;
+ ptr = c->buffer_ptr;
+ if ((ptr >= c->buffer + 2 && !memcmp(ptr-2, "\n\n", 2)) ||
+ (ptr >= c->buffer + 4 && !memcmp(ptr-4, "\r\n\r\n", 4))) {
+ /* request found : parse it and reply */
+ if (c->state == HTTPSTATE_WAIT_REQUEST) {
+ ret = http_parse_request(c);
+ } else {
+ ret = rtsp_parse_request(c);
+ }
+ if (ret < 0)
+ return -1;
+ } else if (ptr >= c->buffer_end) {
+ /* request too long: cannot do anything */
+ return -1;
+ } else goto read_loop;
+ }
+ break;
+
+ case HTTPSTATE_SEND_HEADER:
+ if (c->poll_entry->revents & (POLLERR | POLLHUP))
+ return -1;
+
+ /* no need to write if no events */
+ if (!(c->poll_entry->revents & POLLOUT))
+ return 0;
+ len = send(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr, 0);
+ if (len < 0) {
+ if (errno != EAGAIN && errno != EINTR) {
+ /* error : close connection */
+ av_freep(&c->pb_buffer);
+ return -1;
+ }
+ } else {
+ c->buffer_ptr += len;
+ if (c->stream)
+ c->stream->bytes_served += len;
+ c->data_count += len;
+ if (c->buffer_ptr >= c->buffer_end) {
+ av_freep(&c->pb_buffer);
+ /* if error, exit */
+ if (c->http_error) {
+ return -1;
+ }
+ /* all the buffer was sent : synchronize to the incoming stream */
+ c->state = HTTPSTATE_SEND_DATA_HEADER;
+ c->buffer_ptr = c->buffer_end = c->buffer;
+ }
+ }
+ break;
+
+ case HTTPSTATE_SEND_DATA:
+ case HTTPSTATE_SEND_DATA_HEADER:
+ case HTTPSTATE_SEND_DATA_TRAILER:
+ /* for packetized output, we consider we can always write (the
+ input streams sets the speed). It may be better to verify
+ that we do not rely too much on the kernel queues */
+ if (!c->is_packetized) {
+ if (c->poll_entry->revents & (POLLERR | POLLHUP))
+ return -1;
+
+ /* no need to read if no events */
+ if (!(c->poll_entry->revents & POLLOUT))
+ return 0;
+ }
+ if (http_send_data(c) < 0)
+ return -1;
+ /* close connection if trailer sent */
+ if (c->state == HTTPSTATE_SEND_DATA_TRAILER)
+ return -1;
+ break;
+ case HTTPSTATE_RECEIVE_DATA:
+ /* no need to read if no events */
+ if (c->poll_entry->revents & (POLLERR | POLLHUP))
+ return -1;
+ if (!(c->poll_entry->revents & POLLIN))
+ return 0;
+ if (http_receive_data(c) < 0)
+ return -1;
+ break;
+ case HTTPSTATE_WAIT_FEED:
+ /* no need to read if no events */
+ if (c->poll_entry->revents & (POLLIN | POLLERR | POLLHUP))
+ return -1;
+
+ /* nothing to do, we'll be waken up by incoming feed packets */
+ break;
+
+ case RTSPSTATE_SEND_REPLY:
+ if (c->poll_entry->revents & (POLLERR | POLLHUP)) {
+ av_freep(&c->pb_buffer);
+ return -1;
+ }
+ /* no need to write if no events */
+ if (!(c->poll_entry->revents & POLLOUT))
+ return 0;
+ len = send(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr, 0);
+ if (len < 0) {
+ if (errno != EAGAIN && errno != EINTR) {
+ /* error : close connection */
+ av_freep(&c->pb_buffer);
+ return -1;
+ }
+ } else {
+ c->buffer_ptr += len;
+ c->data_count += len;
+ if (c->buffer_ptr >= c->buffer_end) {
+ /* all the buffer was sent : wait for a new request */
+ av_freep(&c->pb_buffer);
+ start_wait_request(c, 1);
+ }
+ }
+ break;
+ case RTSPSTATE_SEND_PACKET:
+ if (c->poll_entry->revents & (POLLERR | POLLHUP)) {
+ av_freep(&c->packet_buffer);
+ return -1;
+ }
+ /* no need to write if no events */
+ if (!(c->poll_entry->revents & POLLOUT))
+ return 0;
+ len = send(c->fd, c->packet_buffer_ptr,
+ c->packet_buffer_end - c->packet_buffer_ptr, 0);
+ if (len < 0) {
+ if (errno != EAGAIN && errno != EINTR) {
+ /* error : close connection */
+ av_freep(&c->packet_buffer);
+ return -1;
+ }
+ } else {
+ c->packet_buffer_ptr += len;
+ if (c->packet_buffer_ptr >= c->packet_buffer_end) {
+ /* all the buffer was sent : wait for a new request */
+ av_freep(&c->packet_buffer);
+ c->state = RTSPSTATE_WAIT_REQUEST;
+ }
+ }
+ break;
+ case HTTPSTATE_READY:
+ /* nothing to do */
+ break;
+ default:
+ return -1;
+ }
+ return 0;
+}
+
+static int extract_rates(char *rates, int ratelen, const char *request)
+{
+ const char *p;
+
+ for (p = request; *p && *p != '\r' && *p != '\n'; ) {
+ if (strncasecmp(p, "Pragma:", 7) == 0) {
+ const char *q = p + 7;
+
+ while (*q && *q != '\n' && isspace(*q))
+ q++;
+
+ if (strncasecmp(q, "stream-switch-entry=", 20) == 0) {
+ int stream_no;
+ int rate_no;
+
+ q += 20;
+
+ memset(rates, 0xff, ratelen);
+
+ while (1) {
+ while (*q && *q != '\n' && *q != ':')
+ q++;
+
+ if (sscanf(q, ":%d:%d", &stream_no, &rate_no) != 2) {
+ break;
+ }
+ stream_no--;
+ if (stream_no < ratelen && stream_no >= 0) {
+ rates[stream_no] = rate_no;
+ }
+
+ while (*q && *q != '\n' && !isspace(*q))
+ q++;
+ }
+
+ return 1;
+ }
+ }
+ p = strchr(p, '\n');
+ if (!p)
+ break;
+
+ p++;
+ }
+
+ return 0;
+}
+
+static int find_stream_in_feed(FFStream *feed, AVCodecContext *codec, int bit_rate)
+{
+ int i;
+ int best_bitrate = 100000000;
+ int best = -1;
+
+ for (i = 0; i < feed->nb_streams; i++) {
+ AVCodecContext *feed_codec = feed->streams[i]->codec;
+
+ if (feed_codec->codec_id != codec->codec_id ||
+ feed_codec->sample_rate != codec->sample_rate ||
+ feed_codec->width != codec->width ||
+ feed_codec->height != codec->height) {
+ continue;
+ }
+
+ /* Potential stream */
+
+ /* We want the fastest stream less than bit_rate, or the slowest
+ * faster than bit_rate
+ */
+
+ if (feed_codec->bit_rate <= bit_rate) {
+ if (best_bitrate > bit_rate || feed_codec->bit_rate > best_bitrate) {
+ best_bitrate = feed_codec->bit_rate;
+ best = i;
+ }
+ } else {
+ if (feed_codec->bit_rate < best_bitrate) {
+ best_bitrate = feed_codec->bit_rate;
+ best = i;
+ }
+ }
+ }
+
+ return best;
+}
+
+static int modify_current_stream(HTTPContext *c, char *rates)
+{
+ int i;
+ FFStream *req = c->stream;
+ int action_required = 0;
+
+ /* Not much we can do for a feed */
+ if (!req->feed)
+ return 0;
+
+ for (i = 0; i < req->nb_streams; i++) {
+ AVCodecContext *codec = req->streams[i]->codec;
+
+ switch(rates[i]) {
+ case 0:
+ c->switch_feed_streams[i] = req->feed_streams[i];
+ break;
+ case 1:
+ c->switch_feed_streams[i] = find_stream_in_feed(req->feed, codec, codec->bit_rate / 2);
+ break;
+ case 2:
+ /* Wants off or slow */
+ c->switch_feed_streams[i] = find_stream_in_feed(req->feed, codec, codec->bit_rate / 4);
+#ifdef WANTS_OFF
+ /* This doesn't work well when it turns off the only stream! */
+ c->switch_feed_streams[i] = -2;
+ c->feed_streams[i] = -2;
+#endif
+ break;
+ }
+
+ if (c->switch_feed_streams[i] >= 0 && c->switch_feed_streams[i] != c->feed_streams[i])
+ action_required = 1;
+ }
+
+ return action_required;
+}
+
+
+static void do_switch_stream(HTTPContext *c, int i)
+{
+ if (c->switch_feed_streams[i] >= 0) {
+#ifdef PHILIP
+ c->feed_streams[i] = c->switch_feed_streams[i];
+#endif
+
+ /* Now update the stream */
+ }
+ c->switch_feed_streams[i] = -1;
+}
+
+/* XXX: factorize in utils.c ? */
+/* XXX: take care with different space meaning */
+static void skip_spaces(const char **pp)
+{
+ const char *p;
+ p = *pp;
+ while (*p == ' ' || *p == '\t')
+ p++;
+ *pp = p;
+}
+
+static void get_word(char *buf, int buf_size, const char **pp)
+{
+ const char *p;
+ char *q;
+
+ p = *pp;
+ skip_spaces(&p);
+ q = buf;
+ while (!isspace(*p) && *p != '\0') {
+ if ((q - buf) < buf_size - 1)
+ *q++ = *p;
+ p++;
+ }
+ if (buf_size > 0)
+ *q = '\0';
+ *pp = p;
+}
+
+static int validate_acl(FFStream *stream, HTTPContext *c)
+{
+ enum IPAddressAction last_action = IP_DENY;
+ IPAddressACL *acl;
+ struct in_addr *src = &c->from_addr.sin_addr;
+ unsigned long src_addr = ntohl(src->s_addr);
+
+ for (acl = stream->acl; acl; acl = acl->next) {
+ if (src_addr >= acl->first.s_addr && src_addr <= acl->last.s_addr) {
+ return (acl->action == IP_ALLOW) ? 1 : 0;
+ }
+ last_action = acl->action;
+ }
+
+ /* Nothing matched, so return not the last action */
+ return (last_action == IP_DENY) ? 1 : 0;
+}
+
+/* compute the real filename of a file by matching it without its
+ extensions to all the stream filenames */
+static void compute_real_filename(char *filename, int max_size)
+{
+ char file1[1024];
+ char file2[1024];
+ char *p;
+ FFStream *stream;
+
+ /* compute filename by matching without the file extensions */
+ pstrcpy(file1, sizeof(file1), filename);
+ p = strrchr(file1, '.');
+ if (p)
+ *p = '\0';
+ for(stream = first_stream; stream != NULL; stream = stream->next) {
+ pstrcpy(file2, sizeof(file2), stream->filename);
+ p = strrchr(file2, '.');
+ if (p)
+ *p = '\0';
+ if (!strcmp(file1, file2)) {
+ pstrcpy(filename, max_size, stream->filename);
+ break;
+ }
+ }
+}
+
+enum RedirType {
+ REDIR_NONE,
+ REDIR_ASX,
+ REDIR_RAM,
+ REDIR_ASF,
+ REDIR_RTSP,
+ REDIR_SDP,
+};
+
+/* parse http request and prepare header */
+static int http_parse_request(HTTPContext *c)
+{
+ char *p;
+ enum RedirType redir_type;
+ char cmd[32];
+ char info[1024], filename[1024];
+ char url[1024], *q;
+ char protocol[32];
+ char msg[1024];
+ const char *mime_type;
+ FFStream *stream;
+ int i;
+ char ratebuf[32];
+ char *useragent = 0;
+
+ p = c->buffer;
+ get_word(cmd, sizeof(cmd), (const char **)&p);
+ pstrcpy(c->method, sizeof(c->method), cmd);
+
+ if (!strcmp(cmd, "GET"))
+ c->post = 0;
+ else if (!strcmp(cmd, "POST"))
+ c->post = 1;
+ else
+ return -1;
+
+ get_word(url, sizeof(url), (const char **)&p);
+ pstrcpy(c->url, sizeof(c->url), url);
+
+ get_word(protocol, sizeof(protocol), (const char **)&p);
+ if (strcmp(protocol, "HTTP/1.0") && strcmp(protocol, "HTTP/1.1"))
+ return -1;
+
+ pstrcpy(c->protocol, sizeof(c->protocol), protocol);
+
+ if (ffserver_debug)
+ http_log("New connection: %s %s\n", cmd, url);
+
+ /* find the filename and the optional info string in the request */
+ p = strchr(url, '?');
+ if (p) {
+ pstrcpy(info, sizeof(info), p);
+ *p = '\0';
+ } else {
+ info[0] = '\0';
+ }
+
+ pstrcpy(filename, sizeof(filename)-1, url + ((*url == '/') ? 1 : 0));
+
+ for (p = c->buffer; *p && *p != '\r' && *p != '\n'; ) {
+ if (strncasecmp(p, "User-Agent:", 11) == 0) {
+ useragent = p + 11;
+ if (*useragent && *useragent != '\n' && isspace(*useragent))
+ useragent++;
+ break;
+ }
+ p = strchr(p, '\n');
+ if (!p)
+ break;
+
+ p++;
+ }
+
+ redir_type = REDIR_NONE;
+ if (match_ext(filename, "asx")) {
+ redir_type = REDIR_ASX;
+ filename[strlen(filename)-1] = 'f';
+ } else if (match_ext(filename, "asf") &&
+ (!useragent || strncasecmp(useragent, "NSPlayer", 8) != 0)) {
+ /* if this isn't WMP or lookalike, return the redirector file */
+ redir_type = REDIR_ASF;
+ } else if (match_ext(filename, "rpm,ram")) {
+ redir_type = REDIR_RAM;
+ strcpy(filename + strlen(filename)-2, "m");
+ } else if (match_ext(filename, "rtsp")) {
+ redir_type = REDIR_RTSP;
+ compute_real_filename(filename, sizeof(filename) - 1);
+ } else if (match_ext(filename, "sdp")) {
+ redir_type = REDIR_SDP;
+ compute_real_filename(filename, sizeof(filename) - 1);
+ }
+
+ // "redirect" / request to index.html
+ if (!strlen(filename))
+ pstrcpy(filename, sizeof(filename) - 1, "index.html");
+
+ stream = first_stream;
+ while (stream != NULL) {
+ if (!strcmp(stream->filename, filename) && validate_acl(stream, c))
+ break;
+ stream = stream->next;
+ }
+ if (stream == NULL) {
+ snprintf(msg, sizeof(msg), "File '%s' not found", url);
+ goto send_error;
+ }
+
+ c->stream = stream;
+ memcpy(c->feed_streams, stream->feed_streams, sizeof(c->feed_streams));
+ memset(c->switch_feed_streams, -1, sizeof(c->switch_feed_streams));
+
+ if (stream->stream_type == STREAM_TYPE_REDIRECT) {
+ c->http_error = 301;
+ q = c->buffer;
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "HTTP/1.0 301 Moved\r\n");
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Location: %s\r\n", stream->feed_filename);
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Content-type: text/html\r\n");
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "\r\n");
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "<html><head><title>Moved</title></head><body>\r\n");
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "You should be <a href=\"%s\">redirected</a>.\r\n", stream->feed_filename);
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "</body></html>\r\n");
+
+ /* prepare output buffer */
+ c->buffer_ptr = c->buffer;
+ c->buffer_end = q;
+ c->state = HTTPSTATE_SEND_HEADER;
+ return 0;
+ }
+
+ /* If this is WMP, get the rate information */
+ if (extract_rates(ratebuf, sizeof(ratebuf), c->buffer)) {
+ if (modify_current_stream(c, ratebuf)) {
+ for (i = 0; i < sizeof(c->feed_streams) / sizeof(c->feed_streams[0]); i++) {
+ if (c->switch_feed_streams[i] >= 0)
+ do_switch_stream(c, i);
+ }
+ }
+ }
+
+ /* If already streaming this feed, dont let start an another feeder */
+ if (stream->feed_opened) {
+ snprintf(msg, sizeof(msg), "This feed is already being received.");
+ goto send_error;
+ }
+
+ if (c->post == 0 && stream->stream_type == STREAM_TYPE_LIVE) {
+ current_bandwidth += stream->bandwidth;
+ }
+
+ if (c->post == 0 && max_bandwidth < current_bandwidth) {
+ c->http_error = 200;
+ q = c->buffer;
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "HTTP/1.0 200 Server too busy\r\n");
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Content-type: text/html\r\n");
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "\r\n");
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "<html><head><title>Too busy</title></head><body>\r\n");
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "<p>The server is too busy to serve your request at this time.</p>\r\n");
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "<p>The bandwidth being served (including your stream) is %dkbit/sec, and this exceeds the limit of %dkbit/sec.</p>\r\n",
+ current_bandwidth, max_bandwidth);
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "</body></html>\r\n");
+
+ /* prepare output buffer */
+ c->buffer_ptr = c->buffer;
+ c->buffer_end = q;
+ c->state = HTTPSTATE_SEND_HEADER;
+ return 0;
+ }
+
+ if (redir_type != REDIR_NONE) {
+ char *hostinfo = 0;
+
+ for (p = c->buffer; *p && *p != '\r' && *p != '\n'; ) {
+ if (strncasecmp(p, "Host:", 5) == 0) {
+ hostinfo = p + 5;
+ break;
+ }
+ p = strchr(p, '\n');
+ if (!p)
+ break;
+
+ p++;
+ }
+
+ if (hostinfo) {
+ char *eoh;
+ char hostbuf[260];
+
+ while (isspace(*hostinfo))
+ hostinfo++;
+
+ eoh = strchr(hostinfo, '\n');
+ if (eoh) {
+ if (eoh[-1] == '\r')
+ eoh--;
+
+ if (eoh - hostinfo < sizeof(hostbuf) - 1) {
+ memcpy(hostbuf, hostinfo, eoh - hostinfo);
+ hostbuf[eoh - hostinfo] = 0;
+
+ c->http_error = 200;
+ q = c->buffer;
+ switch(redir_type) {
+ case REDIR_ASX:
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "HTTP/1.0 200 ASX Follows\r\n");
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Content-type: video/x-ms-asf\r\n");
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "\r\n");
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "<ASX Version=\"3\">\r\n");
+ //q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "<!-- Autogenerated by ffserver -->\r\n");
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "<ENTRY><REF HREF=\"http://%s/%s%s\"/></ENTRY>\r\n",
+ hostbuf, filename, info);
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "</ASX>\r\n");
+ break;
+ case REDIR_RAM:
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "HTTP/1.0 200 RAM Follows\r\n");
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Content-type: audio/x-pn-realaudio\r\n");
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "\r\n");
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "# Autogenerated by ffserver\r\n");
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "http://%s/%s%s\r\n",
+ hostbuf, filename, info);
+ break;
+ case REDIR_ASF:
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "HTTP/1.0 200 ASF Redirect follows\r\n");
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Content-type: video/x-ms-asf\r\n");
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "\r\n");
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "[Reference]\r\n");
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Ref1=http://%s/%s%s\r\n",
+ hostbuf, filename, info);
+ break;
+ case REDIR_RTSP:
+ {
+ char hostname[256], *p;
+ /* extract only hostname */
+ pstrcpy(hostname, sizeof(hostname), hostbuf);
+ p = strrchr(hostname, ':');
+ if (p)
+ *p = '\0';
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "HTTP/1.0 200 RTSP Redirect follows\r\n");
+ /* XXX: incorrect mime type ? */
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Content-type: application/x-rtsp\r\n");
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "\r\n");
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "rtsp://%s:%d/%s\r\n",
+ hostname, ntohs(my_rtsp_addr.sin_port),
+ filename);
+ }
+ break;
+ case REDIR_SDP:
+ {
+ uint8_t *sdp_data;
+ int sdp_data_size, len;
+ struct sockaddr_in my_addr;
+
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "HTTP/1.0 200 OK\r\n");
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Content-type: application/sdp\r\n");
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "\r\n");
+
+ len = sizeof(my_addr);
+ getsockname(c->fd, (struct sockaddr *)&my_addr, &len);
+
+ /* XXX: should use a dynamic buffer */
+ sdp_data_size = prepare_sdp_description(stream,
+ &sdp_data,
+ my_addr.sin_addr);
+ if (sdp_data_size > 0) {
+ memcpy(q, sdp_data, sdp_data_size);
+ q += sdp_data_size;
+ *q = '\0';
+ av_free(sdp_data);
+ }
+ }
+ break;
+ default:
+ av_abort();
+ break;
+ }
+
+ /* prepare output buffer */
+ c->buffer_ptr = c->buffer;
+ c->buffer_end = q;
+ c->state = HTTPSTATE_SEND_HEADER;
+ return 0;
+ }
+ }
+ }
+
+ snprintf(msg, sizeof(msg), "ASX/RAM file not handled");
+ goto send_error;
+ }
+
+ stream->conns_served++;
+
+ /* XXX: add there authenticate and IP match */
+
+ if (c->post) {
+ /* if post, it means a feed is being sent */
+ if (!stream->is_feed) {
+ /* However it might be a status report from WMP! Lets log the data
+ * as it might come in handy one day
+ */
+ char *logline = 0;
+ int client_id = 0;
+
+ for (p = c->buffer; *p && *p != '\r' && *p != '\n'; ) {
+ if (strncasecmp(p, "Pragma: log-line=", 17) == 0) {
+ logline = p;
+ break;
+ }
+ if (strncasecmp(p, "Pragma: client-id=", 18) == 0) {
+ client_id = strtol(p + 18, 0, 10);
+ }
+ p = strchr(p, '\n');
+ if (!p)
+ break;
+
+ p++;
+ }
+
+ if (logline) {
+ char *eol = strchr(logline, '\n');
+
+ logline += 17;
+
+ if (eol) {
+ if (eol[-1] == '\r')
+ eol--;
+ http_log("%.*s\n", (int) (eol - logline), logline);
+ c->suppress_log = 1;
+ }
+ }
+
+#ifdef DEBUG_WMP
+ http_log("\nGot request:\n%s\n", c->buffer);
+#endif
+
+ if (client_id && extract_rates(ratebuf, sizeof(ratebuf), c->buffer)) {
+ HTTPContext *wmpc;
+
+ /* Now we have to find the client_id */
+ for (wmpc = first_http_ctx; wmpc; wmpc = wmpc->next) {
+ if (wmpc->wmp_client_id == client_id)
+ break;
+ }
+
+ if (wmpc) {
+ if (modify_current_stream(wmpc, ratebuf)) {
+ wmpc->switch_pending = 1;
+ }
+ }
+ }
+
+ snprintf(msg, sizeof(msg), "POST command not handled");
+ c->stream = 0;
+ goto send_error;
+ }
+ if (http_start_receive_data(c) < 0) {
+ snprintf(msg, sizeof(msg), "could not open feed");
+ goto send_error;
+ }
+ c->http_error = 0;
+ c->state = HTTPSTATE_RECEIVE_DATA;
+ return 0;
+ }
+
+#ifdef DEBUG_WMP
+ if (strcmp(stream->filename + strlen(stream->filename) - 4, ".asf") == 0) {
+ http_log("\nGot request:\n%s\n", c->buffer);
+ }
+#endif
+
+ if (c->stream->stream_type == STREAM_TYPE_STATUS)
+ goto send_stats;
+
+ /* open input stream */
+ if (open_input_stream(c, info) < 0) {
+ snprintf(msg, sizeof(msg), "Input stream corresponding to '%s' not found", url);
+ goto send_error;
+ }
+
+ /* prepare http header */
+ q = c->buffer;
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "HTTP/1.0 200 OK\r\n");
+ mime_type = c->stream->fmt->mime_type;
+ if (!mime_type)
+ mime_type = "application/x-octet-stream";
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Pragma: no-cache\r\n");
+
+ /* for asf, we need extra headers */
+ if (!strcmp(c->stream->fmt->name,"asf_stream")) {
+ /* Need to allocate a client id */
+
+ c->wmp_client_id = av_random(&random_state) & 0x7fffffff;
+
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Server: Cougar 4.1.0.3923\r\nCache-Control: no-cache\r\nPragma: client-id=%d\r\nPragma: features=\"broadcast\"\r\n", c->wmp_client_id);
+ }
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Content-Type: %s\r\n", mime_type);
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "\r\n");
+
+ /* prepare output buffer */
+ c->http_error = 0;
+ c->buffer_ptr = c->buffer;
+ c->buffer_end = q;
+ c->state = HTTPSTATE_SEND_HEADER;
+ return 0;
+ send_error:
+ c->http_error = 404;
+ q = c->buffer;
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "HTTP/1.0 404 Not Found\r\n");
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Content-type: %s\r\n", "text/html");
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "\r\n");
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "<HTML>\n");
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "<HEAD><TITLE>404 Not Found</TITLE></HEAD>\n");
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "<BODY>%s</BODY>\n", msg);
+ q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "</HTML>\n");
+
+ /* prepare output buffer */
+ c->buffer_ptr = c->buffer;
+ c->buffer_end = q;
+ c->state = HTTPSTATE_SEND_HEADER;
+ return 0;
+ send_stats:
+ compute_stats(c);
+ c->http_error = 200; /* horrible : we use this value to avoid
+ going to the send data state */
+ c->state = HTTPSTATE_SEND_HEADER;
+ return 0;
+}
+
+static void fmt_bytecount(ByteIOContext *pb, int64_t count)
+{
+ static const char *suffix = " kMGTP";
+ const char *s;
+
+ for (s = suffix; count >= 100000 && s[1]; count /= 1000, s++) {
+ }
+
+ url_fprintf(pb, "%"PRId64"%c", count, *s);
+}
+
+static void compute_stats(HTTPContext *c)
+{
+ HTTPContext *c1;
+ FFStream *stream;
+ char *p;
+ time_t ti;
+ int i, len;
+ ByteIOContext pb1, *pb = &pb1;
+
+ if (url_open_dyn_buf(pb) < 0) {
+ /* XXX: return an error ? */
+ c->buffer_ptr = c->buffer;
+ c->buffer_end = c->buffer;
+ return;
+ }
+
+ url_fprintf(pb, "HTTP/1.0 200 OK\r\n");
+ url_fprintf(pb, "Content-type: %s\r\n", "text/html");
+ url_fprintf(pb, "Pragma: no-cache\r\n");
+ url_fprintf(pb, "\r\n");
+
+ url_fprintf(pb, "<HEAD><TITLE>FFServer Status</TITLE>\n");
+ if (c->stream->feed_filename) {
+ url_fprintf(pb, "<link rel=\"shortcut icon\" href=\"%s\">\n", c->stream->feed_filename);
+ }
+ url_fprintf(pb, "</HEAD>\n<BODY>");
+ url_fprintf(pb, "<H1>FFServer Status</H1>\n");
+ /* format status */
+ url_fprintf(pb, "<H2>Available Streams</H2>\n");
+ url_fprintf(pb, "<TABLE cellspacing=0 cellpadding=4>\n");
+ url_fprintf(pb, "<TR><Th valign=top>Path<th align=left>Served<br>Conns<Th><br>bytes<Th valign=top>Format<Th>Bit rate<br>kbits/s<Th align=left>Video<br>kbits/s<th><br>Codec<Th align=left>Audio<br>kbits/s<th><br>Codec<Th align=left valign=top>Feed\n");
+ stream = first_stream;
+ while (stream != NULL) {
+ char sfilename[1024];
+ char *eosf;
+
+ if (stream->feed != stream) {
+ pstrcpy(sfilename, sizeof(sfilename) - 10, stream->filename);
+ eosf = sfilename + strlen(sfilename);
+ if (eosf - sfilename >= 4) {
+ if (strcmp(eosf - 4, ".asf") == 0) {
+ strcpy(eosf - 4, ".asx");
+ } else if (strcmp(eosf - 3, ".rm") == 0) {
+ strcpy(eosf - 3, ".ram");
+ } else if (stream->fmt == &rtp_muxer) {
+ /* generate a sample RTSP director if
+ unicast. Generate an SDP redirector if
+ multicast */
+ eosf = strrchr(sfilename, '.');
+ if (!eosf)
+ eosf = sfilename + strlen(sfilename);
+ if (stream->is_multicast)
+ strcpy(eosf, ".sdp");
+ else
+ strcpy(eosf, ".rtsp");
+ }
+ }
+
+ url_fprintf(pb, "<TR><TD><A HREF=\"/%s\">%s</A> ",
+ sfilename, stream->filename);
+ url_fprintf(pb, "<td align=right> %d <td align=right> ",
+ stream->conns_served);
+ fmt_bytecount(pb, stream->bytes_served);
+ switch(stream->stream_type) {
+ case STREAM_TYPE_LIVE:
+ {
+ int audio_bit_rate = 0;
+ int video_bit_rate = 0;
+ const char *audio_codec_name = "";
+ const char *video_codec_name = "";
+ const char *audio_codec_name_extra = "";
+ const char *video_codec_name_extra = "";
+
+ for(i=0;i<stream->nb_streams;i++) {
+ AVStream *st = stream->streams[i];
+ AVCodec *codec = avcodec_find_encoder(st->codec->codec_id);
+ switch(st->codec->codec_type) {
+ case CODEC_TYPE_AUDIO:
+ audio_bit_rate += st->codec->bit_rate;
+ if (codec) {
+ if (*audio_codec_name)
+ audio_codec_name_extra = "...";
+ audio_codec_name = codec->name;
+ }
+ break;
+ case CODEC_TYPE_VIDEO:
+ video_bit_rate += st->codec->bit_rate;
+ if (codec) {
+ if (*video_codec_name)
+ video_codec_name_extra = "...";
+ video_codec_name = codec->name;
+ }
+ break;
+ case CODEC_TYPE_DATA:
+ video_bit_rate += st->codec->bit_rate;
+ break;
+ default:
+ av_abort();
+ }
+ }
+ url_fprintf(pb, "<TD align=center> %s <TD align=right> %d <TD align=right> %d <TD> %s %s <TD align=right> %d <TD> %s %s",
+ stream->fmt->name,
+ stream->bandwidth,
+ video_bit_rate / 1000, video_codec_name, video_codec_name_extra,
+ audio_bit_rate / 1000, audio_codec_name, audio_codec_name_extra);
+ if (stream->feed) {
+ url_fprintf(pb, "<TD>%s", stream->feed->filename);
+ } else {
+ url_fprintf(pb, "<TD>%s", stream->feed_filename);
+ }
+ url_fprintf(pb, "\n");
+ }
+ break;
+ default:
+ url_fprintf(pb, "<TD align=center> - <TD align=right> - <TD align=right> - <td><td align=right> - <TD>\n");
+ break;
+ }
+ }
+ stream = stream->next;
+ }
+ url_fprintf(pb, "</TABLE>\n");
+
+ stream = first_stream;
+ while (stream != NULL) {
+ if (stream->feed == stream) {
+ url_fprintf(pb, "<h2>Feed %s</h2>", stream->filename);
+ if (stream->pid) {
+ url_fprintf(pb, "Running as pid %d.\n", stream->pid);
+
+#if defined(linux) && !defined(CONFIG_NOCUTILS)
+ {
+ FILE *pid_stat;
+ char ps_cmd[64];
+
+ /* This is somewhat linux specific I guess */
+ snprintf(ps_cmd, sizeof(ps_cmd),
+ "ps -o \"%%cpu,cputime\" --no-headers %d",
+ stream->pid);
+
+ pid_stat = popen(ps_cmd, "r");
+ if (pid_stat) {
+ char cpuperc[10];
+ char cpuused[64];
+
+ if (fscanf(pid_stat, "%10s %64s", cpuperc,
+ cpuused) == 2) {
+ url_fprintf(pb, "Currently using %s%% of the cpu. Total time used %s.\n",
+ cpuperc, cpuused);
+ }
+ fclose(pid_stat);
+ }
+ }
+#endif
+
+ url_fprintf(pb, "<p>");
+ }
+ url_fprintf(pb, "<table cellspacing=0 cellpadding=4><tr><th>Stream<th>type<th>kbits/s<th align=left>codec<th align=left>Parameters\n");
+
+ for (i = 0; i < stream->nb_streams; i++) {
+ AVStream *st = stream->streams[i];
+ AVCodec *codec = avcodec_find_encoder(st->codec->codec_id);
+ const char *type = "unknown";
+ char parameters[64];
+
+ parameters[0] = 0;
+
+ switch(st->codec->codec_type) {
+ case CODEC_TYPE_AUDIO:
+ type = "audio";
+ snprintf(parameters, sizeof(parameters), "%d channel(s), %d Hz", st->codec->channels, st->codec->sample_rate);
+ break;
+ case CODEC_TYPE_VIDEO:
+ type = "video";
+ snprintf(parameters, sizeof(parameters), "%dx%d, q=%d-%d, fps=%d", st->codec->width, st->codec->height,
+ st->codec->qmin, st->codec->qmax, st->codec->time_base.den / st->codec->time_base.num);
+ break;
+ default:
+ av_abort();
+ }
+ url_fprintf(pb, "<tr><td align=right>%d<td>%s<td align=right>%d<td>%s<td>%s\n",
+ i, type, st->codec->bit_rate/1000, codec ? codec->name : "", parameters);
+ }
+ url_fprintf(pb, "</table>\n");
+
+ }
+ stream = stream->next;
+ }
+
+#if 0
+ {
+ float avg;
+ AVCodecContext *enc;
+ char buf[1024];
+
+ /* feed status */
+ stream = first_feed;
+ while (stream != NULL) {
+ url_fprintf(pb, "<H1>Feed '%s'</H1>\n", stream->filename);
+ url_fprintf(pb, "<TABLE>\n");
+ url_fprintf(pb, "<TR><TD>Parameters<TD>Frame count<TD>Size<TD>Avg bitrate (kbits/s)\n");
+ for(i=0;i<stream->nb_streams;i++) {
+ AVStream *st = stream->streams[i];
+ FeedData *fdata = st->priv_data;
+ enc = st->codec;
+
+ avcodec_string(buf, sizeof(buf), enc);
+ avg = fdata->avg_frame_size * (float)enc->rate * 8.0;
+ if (enc->codec->type == CODEC_TYPE_AUDIO && enc->frame_size > 0)
+ avg /= enc->frame_size;
+ url_fprintf(pb, "<TR><TD>%s <TD> %d <TD> %"PRId64" <TD> %0.1f\n",
+ buf, enc->frame_number, fdata->data_count, avg / 1000.0);
+ }
+ url_fprintf(pb, "</TABLE>\n");
+ stream = stream->next_feed;
+ }
+ }
+#endif
+
+ /* connection status */
+ url_fprintf(pb, "<H2>Connection Status</H2>\n");
+
+ url_fprintf(pb, "Number of connections: %d / %d<BR>\n",
+ nb_connections, nb_max_connections);
+
+ url_fprintf(pb, "Bandwidth in use: %dk / %dk<BR>\n",
+ current_bandwidth, max_bandwidth);
+
+ url_fprintf(pb, "<TABLE>\n");
+ url_fprintf(pb, "<TR><th>#<th>File<th>IP<th>Proto<th>State<th>Target bits/sec<th>Actual bits/sec<th>Bytes transferred\n");
+ c1 = first_http_ctx;
+ i = 0;
+ while (c1 != NULL) {
+ int bitrate;
+ int j;
+
+ bitrate = 0;
+ if (c1->stream) {
+ for (j = 0; j < c1->stream->nb_streams; j++) {
+ if (!c1->stream->feed) {
+ bitrate += c1->stream->streams[j]->codec->bit_rate;
+ } else {
+ if (c1->feed_streams[j] >= 0) {
+ bitrate += c1->stream->feed->streams[c1->feed_streams[j]]->codec->bit_rate;
+ }
+ }
+ }
+ }
+
+ i++;
+ p = inet_ntoa(c1->from_addr.sin_addr);
+ url_fprintf(pb, "<TR><TD><B>%d</B><TD>%s%s<TD>%s<TD>%s<TD>%s<td align=right>",
+ i,
+ c1->stream ? c1->stream->filename : "",
+ c1->state == HTTPSTATE_RECEIVE_DATA ? "(input)" : "",
+ p,
+ c1->protocol,
+ http_state[c1->state]);
+ fmt_bytecount(pb, bitrate);
+ url_fprintf(pb, "<td align=right>");
+ fmt_bytecount(pb, compute_datarate(&c1->datarate, c1->data_count) * 8);
+ url_fprintf(pb, "<td align=right>");
+ fmt_bytecount(pb, c1->data_count);
+ url_fprintf(pb, "\n");
+ c1 = c1->next;
+ }
+ url_fprintf(pb, "</TABLE>\n");
+
+ /* date */
+ ti = time(NULL);
+ p = ctime(&ti);
+ url_fprintf(pb, "<HR size=1 noshade>Generated at %s", p);
+ url_fprintf(pb, "</BODY>\n</HTML>\n");
+
+ len = url_close_dyn_buf(pb, &c->pb_buffer);
+ c->buffer_ptr = c->pb_buffer;
+ c->buffer_end = c->pb_buffer + len;
+}
+
+/* check if the parser needs to be opened for stream i */
+static void open_parser(AVFormatContext *s, int i)
+{
+ AVStream *st = s->streams[i];
+ AVCodec *codec;
+
+ if (!st->codec->codec) {
+ codec = avcodec_find_decoder(st->codec->codec_id);
+ if (codec && (codec->capabilities & CODEC_CAP_PARSE_ONLY)) {
+ st->codec->parse_only = 1;
+ if (avcodec_open(st->codec, codec) < 0) {
+ st->codec->parse_only = 0;
+ }
+ }
+ }
+}
+
+static int open_input_stream(HTTPContext *c, const char *info)
+{
+ char buf[128];
+ char input_filename[1024];
+ AVFormatContext *s;
+ int buf_size, i;
+ int64_t stream_pos;
+
+ /* find file name */
+ if (c->stream->feed) {
+ strcpy(input_filename, c->stream->feed->feed_filename);
+ buf_size = FFM_PACKET_SIZE;
+ /* compute position (absolute time) */
+ if (find_info_tag(buf, sizeof(buf), "date", info)) {
+ stream_pos = parse_date(buf, 0);
+ } else if (find_info_tag(buf, sizeof(buf), "buffer", info)) {
+ int prebuffer = strtol(buf, 0, 10);
+ stream_pos = av_gettime() - prebuffer * (int64_t)1000000;
+ } else {
+ stream_pos = av_gettime() - c->stream->prebuffer * (int64_t)1000;
+ }
+ } else {
+ strcpy(input_filename, c->stream->feed_filename);
+ buf_size = 0;
+ /* compute position (relative time) */
+ if (find_info_tag(buf, sizeof(buf), "date", info)) {
+ stream_pos = parse_date(buf, 1);
+ } else {
+ stream_pos = 0;
+ }
+ }
+ if (input_filename[0] == '\0')
+ return -1;
+
+#if 0
+ { time_t when = stream_pos / 1000000;
+ http_log("Stream pos = %"PRId64", time=%s", stream_pos, ctime(&when));
+ }
+#endif
+
+ /* open stream */
+ if (av_open_input_file(&s, input_filename, c->stream->ifmt,
+ buf_size, c->stream->ap_in) < 0) {
+ http_log("%s not found", input_filename);
+ return -1;
+ }
+ c->fmt_in = s;
+
+ /* open each parser */
+ for(i=0;i<s->nb_streams;i++)
+ open_parser(s, i);
+
+ /* choose stream as clock source (we favorize video stream if
+ present) for packet sending */
+ c->pts_stream_index = 0;
+ for(i=0;i<c->stream->nb_streams;i++) {
+ if (c->pts_stream_index == 0 &&
+ c->stream->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO) {
+ c->pts_stream_index = i;
+ }
+ }
+
+#if 1
+ if (c->fmt_in->iformat->read_seek) {
+ c->fmt_in->iformat->read_seek(c->fmt_in, 0, stream_pos, 0);
+ }
+#endif
+ /* set the start time (needed for maxtime and RTP packet timing) */
+ c->start_time = cur_time;
+ c->first_pts = AV_NOPTS_VALUE;
+ return 0;
+}
+
+/* return the server clock (in us) */
+static int64_t get_server_clock(HTTPContext *c)
+{
+ /* compute current pts value from system time */
+ return (cur_time - c->start_time) * 1000;
+}
+
+/* return the estimated time at which the current packet must be sent
+ (in us) */
+static int64_t get_packet_send_clock(HTTPContext *c)
+{
+ int bytes_left, bytes_sent, frame_bytes;
+
+ frame_bytes = c->cur_frame_bytes;
+ if (frame_bytes <= 0) {
+ return c->cur_pts;
+ } else {
+ bytes_left = c->buffer_end - c->buffer_ptr;
+ bytes_sent = frame_bytes - bytes_left;
+ return c->cur_pts + (c->cur_frame_duration * bytes_sent) / frame_bytes;
+ }
+}
+
+
+static int http_prepare_data(HTTPContext *c)
+{
+ int i, len, ret;
+ AVFormatContext *ctx;
+
+ av_freep(&c->pb_buffer);
+ switch(c->state) {
+ case HTTPSTATE_SEND_DATA_HEADER:
+ memset(&c->fmt_ctx, 0, sizeof(c->fmt_ctx));
+ pstrcpy(c->fmt_ctx.author, sizeof(c->fmt_ctx.author),
+ c->stream->author);
+ pstrcpy(c->fmt_ctx.comment, sizeof(c->fmt_ctx.comment),
+ c->stream->comment);
+ pstrcpy(c->fmt_ctx.copyright, sizeof(c->fmt_ctx.copyright),
+ c->stream->copyright);
+ pstrcpy(c->fmt_ctx.title, sizeof(c->fmt_ctx.title),
+ c->stream->title);
+
+ /* open output stream by using specified codecs */
+ c->fmt_ctx.oformat = c->stream->fmt;
+ c->fmt_ctx.nb_streams = c->stream->nb_streams;
+ for(i=0;i<c->fmt_ctx.nb_streams;i++) {
+ AVStream *st;
+ AVStream *src;
+ st = av_mallocz(sizeof(AVStream));
+ st->codec= avcodec_alloc_context();
+ c->fmt_ctx.streams[i] = st;
+ /* if file or feed, then just take streams from FFStream struct */
+ if (!c->stream->feed ||
+ c->stream->feed == c->stream)
+ src = c->stream->streams[i];
+ else
+ src = c->stream->feed->streams[c->stream->feed_streams[i]];
+
+ *st = *src;
+ st->priv_data = 0;
+ st->codec->frame_number = 0; /* XXX: should be done in
+ AVStream, not in codec */
+ /* I'm pretty sure that this is not correct...
+ * However, without it, we crash
+ */
+ st->codec->coded_frame = &dummy_frame;
+ }
+ c->got_key_frame = 0;
+
+ /* prepare header and save header data in a stream */
+ if (url_open_dyn_buf(&c->fmt_ctx.pb) < 0) {
+ /* XXX: potential leak */
+ return -1;
+ }
+ c->fmt_ctx.pb.is_streamed = 1;
+
+ av_set_parameters(&c->fmt_ctx, NULL);
+ if (av_write_header(&c->fmt_ctx) < 0)
+ return -1;
+
+ len = url_close_dyn_buf(&c->fmt_ctx.pb, &c->pb_buffer);
+ c->buffer_ptr = c->pb_buffer;
+ c->buffer_end = c->pb_buffer + len;
+
+ c->state = HTTPSTATE_SEND_DATA;
+ c->last_packet_sent = 0;
+ break;
+ case HTTPSTATE_SEND_DATA:
+ /* find a new packet */
+ {
+ AVPacket pkt;
+
+ /* read a packet from the input stream */
+ if (c->stream->feed) {
+ ffm_set_write_index(c->fmt_in,
+ c->stream->feed->feed_write_index,
+ c->stream->feed->feed_size);
+ }
+
+ if (c->stream->max_time &&
+ c->stream->max_time + c->start_time - cur_time < 0) {
+ /* We have timed out */
+ c->state = HTTPSTATE_SEND_DATA_TRAILER;
+ } else {
+ redo:
+ if (av_read_frame(c->fmt_in, &pkt) < 0) {
+ if (c->stream->feed && c->stream->feed->feed_opened) {
+ /* if coming from feed, it means we reached the end of the
+ ffm file, so must wait for more data */
+ c->state = HTTPSTATE_WAIT_FEED;
+ return 1; /* state changed */
+ } else {
+ if (c->stream->loop) {
+ av_close_input_file(c->fmt_in);
+ c->fmt_in = NULL;
+ if (open_input_stream(c, "") < 0)
+ goto no_loop;
+ goto redo;
+ } else {
+ no_loop:
+ /* must send trailer now because eof or error */
+ c->state = HTTPSTATE_SEND_DATA_TRAILER;
+ }
+ }
+ } else {
+ /* update first pts if needed */
+ if (c->first_pts == AV_NOPTS_VALUE) {
+ c->first_pts = av_rescale_q(pkt.dts, c->fmt_in->streams[pkt.stream_index]->time_base, AV_TIME_BASE_Q);
+ c->start_time = cur_time;
+ }
+ /* send it to the appropriate stream */
+ if (c->stream->feed) {
+ /* if coming from a feed, select the right stream */
+ if (c->switch_pending) {
+ c->switch_pending = 0;
+ for(i=0;i<c->stream->nb_streams;i++) {
+ if (c->switch_feed_streams[i] == pkt.stream_index) {
+ if (pkt.flags & PKT_FLAG_KEY) {
+ do_switch_stream(c, i);
+ }
+ }
+ if (c->switch_feed_streams[i] >= 0) {
+ c->switch_pending = 1;
+ }
+ }
+ }
+ for(i=0;i<c->stream->nb_streams;i++) {
+ if (c->feed_streams[i] == pkt.stream_index) {
+ pkt.stream_index = i;
+ if (pkt.flags & PKT_FLAG_KEY) {
+ c->got_key_frame |= 1 << i;
+ }
+ /* See if we have all the key frames, then
+ * we start to send. This logic is not quite
+ * right, but it works for the case of a
+ * single video stream with one or more
+ * audio streams (for which every frame is
+ * typically a key frame).
+ */
+ if (!c->stream->send_on_key ||
+ ((c->got_key_frame + 1) >> c->stream->nb_streams)) {
+ goto send_it;
+ }
+ }
+ }
+ } else {
+ AVCodecContext *codec;
+
+ send_it:
+ /* specific handling for RTP: we use several
+ output stream (one for each RTP
+ connection). XXX: need more abstract handling */
+ if (c->is_packetized) {
+ AVStream *st;
+ /* compute send time and duration */
+ st = c->fmt_in->streams[pkt.stream_index];
+ c->cur_pts = av_rescale_q(pkt.dts, st->time_base, AV_TIME_BASE_Q);
+ if (st->start_time != AV_NOPTS_VALUE)
+ c->cur_pts -= av_rescale_q(st->start_time, st->time_base, AV_TIME_BASE_Q);
+ c->cur_frame_duration = av_rescale_q(pkt.duration, st->time_base, AV_TIME_BASE_Q);
+#if 0
+ printf("index=%d pts=%0.3f duration=%0.6f\n",
+ pkt.stream_index,
+ (double)c->cur_pts /
+ AV_TIME_BASE,
+ (double)c->cur_frame_duration /
+ AV_TIME_BASE);
+#endif
+ /* find RTP context */
+ c->packet_stream_index = pkt.stream_index;
+ ctx = c->rtp_ctx[c->packet_stream_index];
+ if(!ctx) {
+ av_free_packet(&pkt);
+ break;
+ }
+ codec = ctx->streams[0]->codec;
+ /* only one stream per RTP connection */
+ pkt.stream_index = 0;
+ } else {
+ ctx = &c->fmt_ctx;
+ /* Fudge here */
+ codec = ctx->streams[pkt.stream_index]->codec;
+ }
+
+ codec->coded_frame->key_frame = ((pkt.flags & PKT_FLAG_KEY) != 0);
+ if (c->is_packetized) {
+ int max_packet_size;
+ if (c->rtp_protocol == RTSP_PROTOCOL_RTP_TCP)
+ max_packet_size = RTSP_TCP_MAX_PACKET_SIZE;
+ else
+ max_packet_size = url_get_max_packet_size(c->rtp_handles[c->packet_stream_index]);
+ ret = url_open_dyn_packet_buf(&ctx->pb, max_packet_size);
+ } else {
+ ret = url_open_dyn_buf(&ctx->pb);
+ }
+ if (ret < 0) {
+ /* XXX: potential leak */
+ return -1;
+ }
+ if (pkt.dts != AV_NOPTS_VALUE)
+ pkt.dts = av_rescale_q(pkt.dts,
+ c->fmt_in->streams[pkt.stream_index]->time_base,
+ ctx->streams[pkt.stream_index]->time_base);
+ if (pkt.pts != AV_NOPTS_VALUE)
+ pkt.pts = av_rescale_q(pkt.pts,
+ c->fmt_in->streams[pkt.stream_index]->time_base,
+ ctx->streams[pkt.stream_index]->time_base);
+ if (av_write_frame(ctx, &pkt)) {
+ c->state = HTTPSTATE_SEND_DATA_TRAILER;
+ }
+
+ len = url_close_dyn_buf(&ctx->pb, &c->pb_buffer);
+ c->cur_frame_bytes = len;
+ c->buffer_ptr = c->pb_buffer;
+ c->buffer_end = c->pb_buffer + len;
+
+ codec->frame_number++;
+ if (len == 0)
+ goto redo;
+ }
+ av_free_packet(&pkt);
+ }
+ }
+ }
+ break;
+ default:
+ case HTTPSTATE_SEND_DATA_TRAILER:
+ /* last packet test ? */
+ if (c->last_packet_sent || c->is_packetized)
+ return -1;
+ ctx = &c->fmt_ctx;
+ /* prepare header */
+ if (url_open_dyn_buf(&ctx->pb) < 0) {
+ /* XXX: potential leak */
+ return -1;
+ }
+ av_write_trailer(ctx);
+ len = url_close_dyn_buf(&ctx->pb, &c->pb_buffer);
+ c->buffer_ptr = c->pb_buffer;
+ c->buffer_end = c->pb_buffer + len;
+
+ c->last_packet_sent = 1;
+ break;
+ }
+ return 0;
+}
+
+/* should convert the format at the same time */
+/* send data starting at c->buffer_ptr to the output connection
+ (either UDP or TCP connection) */
+static int http_send_data(HTTPContext *c)
+{
+ int len, ret;
+
+ for(;;) {
+ if (c->buffer_ptr >= c->buffer_end) {
+ ret = http_prepare_data(c);
+ if (ret < 0)
+ return -1;
+ else if (ret != 0) {
+ /* state change requested */
+ break;
+ }
+ } else {
+ if (c->is_packetized) {
+ /* RTP data output */
+ len = c->buffer_end - c->buffer_ptr;
+ if (len < 4) {
+ /* fail safe - should never happen */
+ fail1:
+ c->buffer_ptr = c->buffer_end;
+ return 0;
+ }
+ len = (c->buffer_ptr[0] << 24) |
+ (c->buffer_ptr[1] << 16) |
+ (c->buffer_ptr[2] << 8) |
+ (c->buffer_ptr[3]);
+ if (len > (c->buffer_end - c->buffer_ptr))
+ goto fail1;
+ if ((get_packet_send_clock(c) - get_server_clock(c)) > 0) {
+ /* nothing to send yet: we can wait */
+ return 0;
+ }
+
+ c->data_count += len;
+ update_datarate(&c->datarate, c->data_count);
+ if (c->stream)
+ c->stream->bytes_served += len;
+
+ if (c->rtp_protocol == RTSP_PROTOCOL_RTP_TCP) {
+ /* RTP packets are sent inside the RTSP TCP connection */
+ ByteIOContext pb1, *pb = &pb1;
+ int interleaved_index, size;
+ uint8_t header[4];
+ HTTPContext *rtsp_c;
+
+ rtsp_c = c->rtsp_c;
+ /* if no RTSP connection left, error */
+ if (!rtsp_c)
+ return -1;
+ /* if already sending something, then wait. */
+ if (rtsp_c->state != RTSPSTATE_WAIT_REQUEST) {
+ break;
+ }
+ if (url_open_dyn_buf(pb) < 0)
+ goto fail1;
+ interleaved_index = c->packet_stream_index * 2;
+ /* RTCP packets are sent at odd indexes */
+ if (c->buffer_ptr[1] == 200)
+ interleaved_index++;
+ /* write RTSP TCP header */
+ header[0] = '$';
+ header[1] = interleaved_index;
+ header[2] = len >> 8;
+ header[3] = len;
+ put_buffer(pb, header, 4);
+ /* write RTP packet data */
+ c->buffer_ptr += 4;
+ put_buffer(pb, c->buffer_ptr, len);
+ size = url_close_dyn_buf(pb, &c->packet_buffer);
+ /* prepare asynchronous TCP sending */
+ rtsp_c->packet_buffer_ptr = c->packet_buffer;
+ rtsp_c->packet_buffer_end = c->packet_buffer + size;
+ c->buffer_ptr += len;
+
+ /* send everything we can NOW */
+ len = send(rtsp_c->fd, rtsp_c->packet_buffer_ptr,
+ rtsp_c->packet_buffer_end - rtsp_c->packet_buffer_ptr, 0);
+ if (len > 0) {
+ rtsp_c->packet_buffer_ptr += len;
+ }
+ if (rtsp_c->packet_buffer_ptr < rtsp_c->packet_buffer_end) {
+ /* if we could not send all the data, we will
+ send it later, so a new state is needed to
+ "lock" the RTSP TCP connection */
+ rtsp_c->state = RTSPSTATE_SEND_PACKET;
+ break;
+ } else {
+ /* all data has been sent */
+ av_freep(&c->packet_buffer);
+ }
+ } else {
+ /* send RTP packet directly in UDP */
+ c->buffer_ptr += 4;
+ url_write(c->rtp_handles[c->packet_stream_index],
+ c->buffer_ptr, len);
+ c->buffer_ptr += len;
+ /* here we continue as we can send several packets per 10 ms slot */
+ }
+ } else {
+ /* TCP data output */
+ len = send(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr, 0);
+ if (len < 0) {
+ if (errno != EAGAIN && errno != EINTR) {
+ /* error : close connection */
+ return -1;
+ } else {
+ return 0;
+ }
+ } else {
+ c->buffer_ptr += len;
+ }
+ c->data_count += len;
+ update_datarate(&c->datarate, c->data_count);
+ if (c->stream)
+ c->stream->bytes_served += len;
+ break;
+ }
+ }
+ } /* for(;;) */
+ return 0;
+}
+
+static int http_start_receive_data(HTTPContext *c)
+{
+ int fd;
+
+ if (c->stream->feed_opened)
+ return -1;
+
+ /* Don't permit writing to this one */
+ if (c->stream->readonly)
+ return -1;
+
+ /* open feed */
+ fd = open(c->stream->feed_filename, O_RDWR);
+ if (fd < 0)
+ return -1;
+ c->feed_fd = fd;
+
+ c->stream->feed_write_index = ffm_read_write_index(fd);
+ c->stream->feed_size = lseek(fd, 0, SEEK_END);
+ lseek(fd, 0, SEEK_SET);
+
+ /* init buffer input */
+ c->buffer_ptr = c->buffer;
+ c->buffer_end = c->buffer + FFM_PACKET_SIZE;
+ c->stream->feed_opened = 1;
+ return 0;
+}
+
+static int http_receive_data(HTTPContext *c)
+{
+ HTTPContext *c1;
+
+ if (c->buffer_end > c->buffer_ptr) {
+ int len;
+
+ len = recv(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr, 0);
+ if (len < 0) {
+ if (errno != EAGAIN && errno != EINTR) {
+ /* error : close connection */
+ goto fail;
+ }
+ } else if (len == 0) {
+ /* end of connection : close it */
+ goto fail;
+ } else {
+ c->buffer_ptr += len;
+ c->data_count += len;
+ update_datarate(&c->datarate, c->data_count);
+ }
+ }
+
+ if (c->buffer_ptr - c->buffer >= 2 && c->data_count > FFM_PACKET_SIZE) {
+ if (c->buffer[0] != 'f' ||
+ c->buffer[1] != 'm') {
+ http_log("Feed stream has become desynchronized -- disconnecting\n");
+ goto fail;
+ }
+ }
+
+ if (c->buffer_ptr >= c->buffer_end) {
+ FFStream *feed = c->stream;
+ /* a packet has been received : write it in the store, except
+ if header */
+ if (c->data_count > FFM_PACKET_SIZE) {
+
+ // printf("writing pos=0x%"PRIx64" size=0x%"PRIx64"\n", feed->feed_write_index, feed->feed_size);
+ /* XXX: use llseek or url_seek */
+ lseek(c->feed_fd, feed->feed_write_index, SEEK_SET);
+ write(c->feed_fd, c->buffer, FFM_PACKET_SIZE);
+
+ feed->feed_write_index += FFM_PACKET_SIZE;
+ /* update file size */
+ if (feed->feed_write_index > c->stream->feed_size)
+ feed->feed_size = feed->feed_write_index;
+
+ /* handle wrap around if max file size reached */
+ if (c->stream->feed_max_size && feed->feed_write_index >= c->stream->feed_max_size)
+ feed->feed_write_index = FFM_PACKET_SIZE;
+
+ /* write index */
+ ffm_write_write_index(c->feed_fd, feed->feed_write_index);
+
+ /* wake up any waiting connections */
+ for(c1 = first_http_ctx; c1 != NULL; c1 = c1->next) {
+ if (c1->state == HTTPSTATE_WAIT_FEED &&
+ c1->stream->feed == c->stream->feed) {
+ c1->state = HTTPSTATE_SEND_DATA;
+ }
+ }
+ } else {
+ /* We have a header in our hands that contains useful data */
+ AVFormatContext s;
+ AVInputFormat *fmt_in;
+ ByteIOContext *pb = &s.pb;
+ int i;
+
+ memset(&s, 0, sizeof(s));
+
+ url_open_buf(pb, c->buffer, c->buffer_end - c->buffer, URL_RDONLY);
+ pb->buf_end = c->buffer_end; /* ?? */
+ pb->is_streamed = 1;
+
+ /* use feed output format name to find corresponding input format */
+ fmt_in = av_find_input_format(feed->fmt->name);
+ if (!fmt_in)
+ goto fail;
+
+ if (fmt_in->priv_data_size > 0) {
+ s.priv_data = av_mallocz(fmt_in->priv_data_size);
+ if (!s.priv_data)
+ goto fail;
+ } else
+ s.priv_data = NULL;
+
+ if (fmt_in->read_header(&s, 0) < 0) {
+ av_freep(&s.priv_data);
+ goto fail;
+ }
+
+ /* Now we have the actual streams */
+ if (s.nb_streams != feed->nb_streams) {
+ av_freep(&s.priv_data);
+ goto fail;
+ }
+ for (i = 0; i < s.nb_streams; i++) {
+ memcpy(feed->streams[i]->codec,
+ s.streams[i]->codec, sizeof(AVCodecContext));
+ }
+ av_freep(&s.priv_data);
+ }
+ c->buffer_ptr = c->buffer;
+ }
+
+ return 0;
+ fail:
+ c->stream->feed_opened = 0;
+ close(c->feed_fd);
+ return -1;
+}
+
+/********************************************************************/
+/* RTSP handling */
+
+static void rtsp_reply_header(HTTPContext *c, enum RTSPStatusCode error_number)
+{
+ const char *str;
+ time_t ti;
+ char *p;
+ char buf2[32];
+
+ switch(error_number) {
+#define DEF(n, c, s) case c: str = s; break;
+#include "rtspcodes.h"
+#undef DEF
+ default:
+ str = "Unknown Error";
+ break;
+ }
+
+ url_fprintf(c->pb, "RTSP/1.0 %d %s\r\n", error_number, str);
+ url_fprintf(c->pb, "CSeq: %d\r\n", c->seq);
+
+ /* output GMT time */
+ ti = time(NULL);
+ p = ctime(&ti);
+ strcpy(buf2, p);
+ p = buf2 + strlen(p) - 1;
+ if (*p == '\n')
+ *p = '\0';
+ url_fprintf(c->pb, "Date: %s GMT\r\n", buf2);
+}
+
+static void rtsp_reply_error(HTTPContext *c, enum RTSPStatusCode error_number)
+{
+ rtsp_reply_header(c, error_number);
+ url_fprintf(c->pb, "\r\n");
+}
+
+static int rtsp_parse_request(HTTPContext *c)
+{
+ const char *p, *p1, *p2;
+ char cmd[32];
+ char url[1024];
+ char protocol[32];
+ char line[1024];
+ ByteIOContext pb1;
+ int len;
+ RTSPHeader header1, *header = &header1;
+
+ c->buffer_ptr[0] = '\0';
+ p = c->buffer;
+
+ get_word(cmd, sizeof(cmd), &p);
+ get_word(url, sizeof(url), &p);
+ get_word(protocol, sizeof(protocol), &p);
+
+ pstrcpy(c->method, sizeof(c->method), cmd);
+ pstrcpy(c->url, sizeof(c->url), url);
+ pstrcpy(c->protocol, sizeof(c->protocol), protocol);
+
+ c->pb = &pb1;
+ if (url_open_dyn_buf(c->pb) < 0) {
+ /* XXX: cannot do more */
+ c->pb = NULL; /* safety */
+ return -1;
+ }
+
+ /* check version name */
+ if (strcmp(protocol, "RTSP/1.0") != 0) {
+ rtsp_reply_error(c, RTSP_STATUS_VERSION);
+ goto the_end;
+ }
+
+ /* parse each header line */
+ memset(header, 0, sizeof(RTSPHeader));
+ /* skip to next line */
+ while (*p != '\n' && *p != '\0')
+ p++;
+ if (*p == '\n')
+ p++;
+ while (*p != '\0') {
+ p1 = strchr(p, '\n');
+ if (!p1)
+ break;
+ p2 = p1;
+ if (p2 > p && p2[-1] == '\r')
+ p2--;
+ /* skip empty line */
+ if (p2 == p)
+ break;
+ len = p2 - p;
+ if (len > sizeof(line) - 1)
+ len = sizeof(line) - 1;
+ memcpy(line, p, len);
+ line[len] = '\0';
+ rtsp_parse_line(header, line);
+ p = p1 + 1;
+ }
+
+ /* handle sequence number */
+ c->seq = header->seq;
+
+ if (!strcmp(cmd, "DESCRIBE")) {
+ rtsp_cmd_describe(c, url);
+ } else if (!strcmp(cmd, "OPTIONS")) {
+ rtsp_cmd_options(c, url);
+ } else if (!strcmp(cmd, "SETUP")) {
+ rtsp_cmd_setup(c, url, header);
+ } else if (!strcmp(cmd, "PLAY")) {
+ rtsp_cmd_play(c, url, header);
+ } else if (!strcmp(cmd, "PAUSE")) {
+ rtsp_cmd_pause(c, url, header);
+ } else if (!strcmp(cmd, "TEARDOWN")) {
+ rtsp_cmd_teardown(c, url, header);
+ } else {
+ rtsp_reply_error(c, RTSP_STATUS_METHOD);
+ }
+ the_end:
+ len = url_close_dyn_buf(c->pb, &c->pb_buffer);
+ c->pb = NULL; /* safety */
+ if (len < 0) {
+ /* XXX: cannot do more */
+ return -1;
+ }
+ c->buffer_ptr = c->pb_buffer;
+ c->buffer_end = c->pb_buffer + len;
+ c->state = RTSPSTATE_SEND_REPLY;
+ return 0;
+}
+
+/* XXX: move that to rtsp.c, but would need to replace FFStream by
+ AVFormatContext */
+static int prepare_sdp_description(FFStream *stream, uint8_t **pbuffer,
+ struct in_addr my_ip)
+{
+ ByteIOContext pb1, *pb = &pb1;
+ int i, payload_type, port, private_payload_type, j;
+ const char *ipstr, *title, *mediatype;
+ AVStream *st;
+
+ if (url_open_dyn_buf(pb) < 0)
+ return -1;
+
+ /* general media info */
+
+ url_fprintf(pb, "v=0\n");
+ ipstr = inet_ntoa(my_ip);
+ url_fprintf(pb, "o=- 0 0 IN IP4 %s\n", ipstr);
+ title = stream->title;
+ if (title[0] == '\0')
+ title = "No Title";
+ url_fprintf(pb, "s=%s\n", title);
+ if (stream->comment[0] != '\0')
+ url_fprintf(pb, "i=%s\n", stream->comment);
+ if (stream->is_multicast) {
+ url_fprintf(pb, "c=IN IP4 %s\n", inet_ntoa(stream->multicast_ip));
+ }
+ /* for each stream, we output the necessary info */
+ private_payload_type = RTP_PT_PRIVATE;
+ for(i = 0; i < stream->nb_streams; i++) {
+ st = stream->streams[i];
+ if (st->codec->codec_id == CODEC_ID_MPEG2TS) {
+ mediatype = "video";
+ } else {
+ switch(st->codec->codec_type) {
+ case CODEC_TYPE_AUDIO:
+ mediatype = "audio";
+ break;
+ case CODEC_TYPE_VIDEO:
+ mediatype = "video";
+ break;
+ default:
+ mediatype = "application";
+ break;
+ }
+ }
+ /* NOTE: the port indication is not correct in case of
+ unicast. It is not an issue because RTSP gives it */
+ payload_type = rtp_get_payload_type(st->codec);
+ if (payload_type < 0)
+ payload_type = private_payload_type++;
+ if (stream->is_multicast) {
+ port = stream->multicast_port + 2 * i;
+ } else {
+ port = 0;
+ }
+ url_fprintf(pb, "m=%s %d RTP/AVP %d\n",
+ mediatype, port, payload_type);
+ if (payload_type >= RTP_PT_PRIVATE) {
+ /* for private payload type, we need to give more info */
+ switch(st->codec->codec_id) {
+ case CODEC_ID_MPEG4:
+ {
+ uint8_t *data;
+ url_fprintf(pb, "a=rtpmap:%d MP4V-ES/%d\n",
+ payload_type, 90000);
+ /* we must also add the mpeg4 header */
+ data = st->codec->extradata;
+ if (data) {
+ url_fprintf(pb, "a=fmtp:%d config=", payload_type);
+ for(j=0;j<st->codec->extradata_size;j++) {
+ url_fprintf(pb, "%02x", data[j]);
+ }
+ url_fprintf(pb, "\n");
+ }
+ }
+ break;
+ default:
+ /* XXX: add other codecs ? */
+ goto fail;
+ }
+ }
+ url_fprintf(pb, "a=control:streamid=%d\n", i);
+ }
+ return url_close_dyn_buf(pb, pbuffer);
+ fail:
+ url_close_dyn_buf(pb, pbuffer);
+ av_free(*pbuffer);
+ return -1;
+}
+
+static void rtsp_cmd_options(HTTPContext *c, const char *url)
+{
+// rtsp_reply_header(c, RTSP_STATUS_OK);
+ url_fprintf(c->pb, "RTSP/1.0 %d %s\r\n", RTSP_STATUS_OK, "OK");
+ url_fprintf(c->pb, "CSeq: %d\r\n", c->seq);
+ url_fprintf(c->pb, "Public: %s\r\n", "OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE");
+ url_fprintf(c->pb, "\r\n");
+}
+
+static void rtsp_cmd_describe(HTTPContext *c, const char *url)
+{
+ FFStream *stream;
+ char path1[1024];
+ const char *path;
+ uint8_t *content;
+ int content_length, len;
+ struct sockaddr_in my_addr;
+
+ /* find which url is asked */
+ url_split(NULL, 0, NULL, 0, NULL, 0, NULL, path1, sizeof(path1), url);
+ path = path1;
+ if (*path == '/')
+ path++;
+
+ for(stream = first_stream; stream != NULL; stream = stream->next) {
+ if (!stream->is_feed && stream->fmt == &rtp_muxer &&
+ !strcmp(path, stream->filename)) {
+ goto found;
+ }
+ }
+ /* no stream found */
+ rtsp_reply_error(c, RTSP_STATUS_SERVICE); /* XXX: right error ? */
+ return;
+
+ found:
+ /* prepare the media description in sdp format */
+
+ /* get the host IP */
+ len = sizeof(my_addr);
+ getsockname(c->fd, (struct sockaddr *)&my_addr, &len);
+ content_length = prepare_sdp_description(stream, &content, my_addr.sin_addr);
+ if (content_length < 0) {
+ rtsp_reply_error(c, RTSP_STATUS_INTERNAL);
+ return;
+ }
+ rtsp_reply_header(c, RTSP_STATUS_OK);
+ url_fprintf(c->pb, "Content-Type: application/sdp\r\n");
+ url_fprintf(c->pb, "Content-Length: %d\r\n", content_length);
+ url_fprintf(c->pb, "\r\n");
+ put_buffer(c->pb, content, content_length);
+}
+
+static HTTPContext *find_rtp_session(const char *session_id)
+{
+ HTTPContext *c;
+
+ if (session_id[0] == '\0')
+ return NULL;
+
+ for(c = first_http_ctx; c != NULL; c = c->next) {
+ if (!strcmp(c->session_id, session_id))
+ return c;
+ }
+ return NULL;
+}
+
+static RTSPTransportField *find_transport(RTSPHeader *h, enum RTSPProtocol protocol)
+{
+ RTSPTransportField *th;
+ int i;
+
+ for(i=0;i<h->nb_transports;i++) {
+ th = &h->transports[i];
+ if (th->protocol == protocol)
+ return th;
+ }
+ return NULL;
+}
+
+static void rtsp_cmd_setup(HTTPContext *c, const char *url,
+ RTSPHeader *h)
+{
+ FFStream *stream;
+ int stream_index, port;
+ char buf[1024];
+ char path1[1024];
+ const char *path;
+ HTTPContext *rtp_c;
+ RTSPTransportField *th;
+ struct sockaddr_in dest_addr;
+ RTSPActionServerSetup setup;
+
+ /* find which url is asked */
+ url_split(NULL, 0, NULL, 0, NULL, 0, NULL, path1, sizeof(path1), url);
+ path = path1;
+ if (*path == '/')
+ path++;
+
+ /* now check each stream */
+ for(stream = first_stream; stream != NULL; stream = stream->next) {
+ if (!stream->is_feed && stream->fmt == &rtp_muxer) {
+ /* accept aggregate filenames only if single stream */
+ if (!strcmp(path, stream->filename)) {
+ if (stream->nb_streams != 1) {
+ rtsp_reply_error(c, RTSP_STATUS_AGGREGATE);
+ return;
+ }
+ stream_index = 0;
+ goto found;
+ }
+
+ for(stream_index = 0; stream_index < stream->nb_streams;
+ stream_index++) {
+ snprintf(buf, sizeof(buf), "%s/streamid=%d",
+ stream->filename, stream_index);
+ if (!strcmp(path, buf))
+ goto found;
+ }
+ }
+ }
+ /* no stream found */
+ rtsp_reply_error(c, RTSP_STATUS_SERVICE); /* XXX: right error ? */
+ return;
+ found:
+
+ /* generate session id if needed */
+ if (h->session_id[0] == '\0') {
+ snprintf(h->session_id, sizeof(h->session_id), "%08x%08x",
+ av_random(&random_state), av_random(&random_state));
+ }
+
+ /* find rtp session, and create it if none found */
+ rtp_c = find_rtp_session(h->session_id);
+ if (!rtp_c) {
+ /* always prefer UDP */
+ th = find_transport(h, RTSP_PROTOCOL_RTP_UDP);
+ if (!th) {
+ th = find_transport(h, RTSP_PROTOCOL_RTP_TCP);
+ if (!th) {
+ rtsp_reply_error(c, RTSP_STATUS_TRANSPORT);
+ return;
+ }
+ }
+
+ rtp_c = rtp_new_connection(&c->from_addr, stream, h->session_id,
+ th->protocol);
+ if (!rtp_c) {
+ rtsp_reply_error(c, RTSP_STATUS_BANDWIDTH);
+ return;
+ }
+
+ /* open input stream */
+ if (open_input_stream(rtp_c, "") < 0) {
+ rtsp_reply_error(c, RTSP_STATUS_INTERNAL);
+ return;
+ }
+ }
+
+ /* test if stream is OK (test needed because several SETUP needs
+ to be done for a given file) */
+ if (rtp_c->stream != stream) {
+ rtsp_reply_error(c, RTSP_STATUS_SERVICE);
+ return;
+ }
+
+ /* test if stream is already set up */
+ if (rtp_c->rtp_ctx[stream_index]) {
+ rtsp_reply_error(c, RTSP_STATUS_STATE);
+ return;
+ }
+
+ /* check transport */
+ th = find_transport(h, rtp_c->rtp_protocol);
+ if (!th || (th->protocol == RTSP_PROTOCOL_RTP_UDP &&
+ th->client_port_min <= 0)) {
+ rtsp_reply_error(c, RTSP_STATUS_TRANSPORT);
+ return;
+ }
+
+ /* setup default options */
+ setup.transport_option[0] = '\0';
+ dest_addr = rtp_c->from_addr;
+ dest_addr.sin_port = htons(th->client_port_min);
+
+ /* add transport option if needed */
+ if (ff_rtsp_callback) {
+ setup.ipaddr = ntohl(dest_addr.sin_addr.s_addr);
+ if (ff_rtsp_callback(RTSP_ACTION_SERVER_SETUP, rtp_c->session_id,
+ (char *)&setup, sizeof(setup),
+ stream->rtsp_option) < 0) {
+ rtsp_reply_error(c, RTSP_STATUS_TRANSPORT);
+ return;
+ }
+ dest_addr.sin_addr.s_addr = htonl(setup.ipaddr);
+ }
+
+ /* setup stream */
+ if (rtp_new_av_stream(rtp_c, stream_index, &dest_addr, c) < 0) {
+ rtsp_reply_error(c, RTSP_STATUS_TRANSPORT);
+ return;
+ }
+
+ /* now everything is OK, so we can send the connection parameters */
+ rtsp_reply_header(c, RTSP_STATUS_OK);
+ /* session ID */
+ url_fprintf(c->pb, "Session: %s\r\n", rtp_c->session_id);
+
+ switch(rtp_c->rtp_protocol) {
+ case RTSP_PROTOCOL_RTP_UDP:
+ port = rtp_get_local_port(rtp_c->rtp_handles[stream_index]);
+ url_fprintf(c->pb, "Transport: RTP/AVP/UDP;unicast;"
+ "client_port=%d-%d;server_port=%d-%d",
+ th->client_port_min, th->client_port_min + 1,
+ port, port + 1);
+ break;
+ case RTSP_PROTOCOL_RTP_TCP:
+ url_fprintf(c->pb, "Transport: RTP/AVP/TCP;interleaved=%d-%d",
+ stream_index * 2, stream_index * 2 + 1);
+ break;
+ default:
+ break;
+ }
+ if (setup.transport_option[0] != '\0') {
+ url_fprintf(c->pb, ";%s", setup.transport_option);
+ }
+ url_fprintf(c->pb, "\r\n");
+
+
+ url_fprintf(c->pb, "\r\n");
+}
+
+
+/* find an rtp connection by using the session ID. Check consistency
+ with filename */
+static HTTPContext *find_rtp_session_with_url(const char *url,
+ const char *session_id)
+{
+ HTTPContext *rtp_c;
+ char path1[1024];
+ const char *path;
+ char buf[1024];
+ int s;
+
+ rtp_c = find_rtp_session(session_id);
+ if (!rtp_c)
+ return NULL;
+
+ /* find which url is asked */
+ url_split(NULL, 0, NULL, 0, NULL, 0, NULL, path1, sizeof(path1), url);
+ path = path1;
+ if (*path == '/')
+ path++;
+ if(!strcmp(path, rtp_c->stream->filename)) return rtp_c;
+ for(s=0; s<rtp_c->stream->nb_streams; ++s) {
+ snprintf(buf, sizeof(buf), "%s/streamid=%d",
+ rtp_c->stream->filename, s);
+ if(!strncmp(path, buf, sizeof(buf))) {
+ // XXX: Should we reply with RTSP_STATUS_ONLY_AGGREGATE if nb_streams>1?
+ return rtp_c;
+ }
+ }
+ return NULL;
+}
+
+static void rtsp_cmd_play(HTTPContext *c, const char *url, RTSPHeader *h)
+{
+ HTTPContext *rtp_c;
+
+ rtp_c = find_rtp_session_with_url(url, h->session_id);
+ if (!rtp_c) {
+ rtsp_reply_error(c, RTSP_STATUS_SESSION);
+ return;
+ }
+
+ if (rtp_c->state != HTTPSTATE_SEND_DATA &&
+ rtp_c->state != HTTPSTATE_WAIT_FEED &&
+ rtp_c->state != HTTPSTATE_READY) {
+ rtsp_reply_error(c, RTSP_STATUS_STATE);
+ return;
+ }
+
+#if 0
+ /* XXX: seek in stream */
+ if (h->range_start != AV_NOPTS_VALUE) {
+ printf("range_start=%0.3f\n", (double)h->range_start / AV_TIME_BASE);
+ av_seek_frame(rtp_c->fmt_in, -1, h->range_start);
+ }
+#endif
+
+ rtp_c->state = HTTPSTATE_SEND_DATA;
+
+ /* now everything is OK, so we can send the connection parameters */
+ rtsp_reply_header(c, RTSP_STATUS_OK);
+ /* session ID */
+ url_fprintf(c->pb, "Session: %s\r\n", rtp_c->session_id);
+ url_fprintf(c->pb, "\r\n");
+}
+
+static void rtsp_cmd_pause(HTTPContext *c, const char *url, RTSPHeader *h)
+{
+ HTTPContext *rtp_c;
+
+ rtp_c = find_rtp_session_with_url(url, h->session_id);
+ if (!rtp_c) {
+ rtsp_reply_error(c, RTSP_STATUS_SESSION);
+ return;
+ }
+
+ if (rtp_c->state != HTTPSTATE_SEND_DATA &&
+ rtp_c->state != HTTPSTATE_WAIT_FEED) {
+ rtsp_reply_error(c, RTSP_STATUS_STATE);
+ return;
+ }
+
+ rtp_c->state = HTTPSTATE_READY;
+ rtp_c->first_pts = AV_NOPTS_VALUE;
+ /* now everything is OK, so we can send the connection parameters */
+ rtsp_reply_header(c, RTSP_STATUS_OK);
+ /* session ID */
+ url_fprintf(c->pb, "Session: %s\r\n", rtp_c->session_id);
+ url_fprintf(c->pb, "\r\n");
+}
+
+static void rtsp_cmd_teardown(HTTPContext *c, const char *url, RTSPHeader *h)
+{
+ HTTPContext *rtp_c;
+
+ rtp_c = find_rtp_session_with_url(url, h->session_id);
+ if (!rtp_c) {
+ rtsp_reply_error(c, RTSP_STATUS_SESSION);
+ return;
+ }
+
+ /* abort the session */
+ close_connection(rtp_c);
+
+ if (ff_rtsp_callback) {
+ ff_rtsp_callback(RTSP_ACTION_SERVER_TEARDOWN, rtp_c->session_id,
+ NULL, 0,
+ rtp_c->stream->rtsp_option);
+ }
+
+ /* now everything is OK, so we can send the connection parameters */
+ rtsp_reply_header(c, RTSP_STATUS_OK);
+ /* session ID */
+ url_fprintf(c->pb, "Session: %s\r\n", rtp_c->session_id);
+ url_fprintf(c->pb, "\r\n");
+}
+
+
+/********************************************************************/
+/* RTP handling */
+
+static HTTPContext *rtp_new_connection(struct sockaddr_in *from_addr,
+ FFStream *stream, const char *session_id,
+ enum RTSPProtocol rtp_protocol)
+{
+ HTTPContext *c = NULL;
+ const char *proto_str;
+
+ /* XXX: should output a warning page when coming
+ close to the connection limit */
+ if (nb_connections >= nb_max_connections)
+ goto fail;
+
+ /* add a new connection */
+ c = av_mallocz(sizeof(HTTPContext));
+ if (!c)
+ goto fail;
+
+ c->fd = -1;
+ c->poll_entry = NULL;
+ c->from_addr = *from_addr;
+ c->buffer_size = IOBUFFER_INIT_SIZE;
+ c->buffer = av_malloc(c->buffer_size);
+ if (!c->buffer)
+ goto fail;
+ nb_connections++;
+ c->stream = stream;
+ pstrcpy(c->session_id, sizeof(c->session_id), session_id);
+ c->state = HTTPSTATE_READY;
+ c->is_packetized = 1;
+ c->rtp_protocol = rtp_protocol;
+
+ /* protocol is shown in statistics */
+ switch(c->rtp_protocol) {
+ case RTSP_PROTOCOL_RTP_UDP_MULTICAST:
+ proto_str = "MCAST";
+ break;
+ case RTSP_PROTOCOL_RTP_UDP:
+ proto_str = "UDP";
+ break;
+ case RTSP_PROTOCOL_RTP_TCP:
+ proto_str = "TCP";
+ break;
+ default:
+ proto_str = "???";
+ break;
+ }
+ pstrcpy(c->protocol, sizeof(c->protocol), "RTP/");
+ pstrcat(c->protocol, sizeof(c->protocol), proto_str);
+
+ current_bandwidth += stream->bandwidth;
+
+ c->next = first_http_ctx;
+ first_http_ctx = c;
+ return c;
+
+ fail:
+ if (c) {
+ av_free(c->buffer);
+ av_free(c);
+ }
+ return NULL;
+}
+
+/* add a new RTP stream in an RTP connection (used in RTSP SETUP
+ command). If RTP/TCP protocol is used, TCP connection 'rtsp_c' is
+ used. */
+static int rtp_new_av_stream(HTTPContext *c,
+ int stream_index, struct sockaddr_in *dest_addr,
+ HTTPContext *rtsp_c)
+{
+ AVFormatContext *ctx;
+ AVStream *st;
+ char *ipaddr;
+ URLContext *h;
+ uint8_t *dummy_buf;
+ char buf2[32];
+ int max_packet_size;
+
+ /* now we can open the relevant output stream */
+ ctx = av_alloc_format_context();
+ if (!ctx)
+ return -1;
+ ctx->oformat = &rtp_muxer;
+
+ st = av_mallocz(sizeof(AVStream));
+ if (!st)
+ goto fail;
+ st->codec= avcodec_alloc_context();
+ ctx->nb_streams = 1;
+ ctx->streams[0] = st;
+
+ if (!c->stream->feed ||
+ c->stream->feed == c->stream) {
+ memcpy(st, c->stream->streams[stream_index], sizeof(AVStream));
+ } else {
+ memcpy(st,
+ c->stream->feed->streams[c->stream->feed_streams[stream_index]],
+ sizeof(AVStream));
+ }
+
+ /* build destination RTP address */
+ ipaddr = inet_ntoa(dest_addr->sin_addr);
+
+ switch(c->rtp_protocol) {
+ case RTSP_PROTOCOL_RTP_UDP:
+ case RTSP_PROTOCOL_RTP_UDP_MULTICAST:
+ /* RTP/UDP case */
+
+ /* XXX: also pass as parameter to function ? */
+ if (c->stream->is_multicast) {
+ int ttl;
+ ttl = c->stream->multicast_ttl;
+ if (!ttl)
+ ttl = 16;
+ snprintf(ctx->filename, sizeof(ctx->filename),
+ "rtp://%s:%d?multicast=1&ttl=%d",
+ ipaddr, ntohs(dest_addr->sin_port), ttl);
+ } else {
+ snprintf(ctx->filename, sizeof(ctx->filename),
+ "rtp://%s:%d", ipaddr, ntohs(dest_addr->sin_port));
+ }
+
+ if (url_open(&h, ctx->filename, URL_WRONLY) < 0)
+ goto fail;
+ c->rtp_handles[stream_index] = h;
+ max_packet_size = url_get_max_packet_size(h);
+ break;
+ case RTSP_PROTOCOL_RTP_TCP:
+ /* RTP/TCP case */
+ c->rtsp_c = rtsp_c;
+ max_packet_size = RTSP_TCP_MAX_PACKET_SIZE;
+ break;
+ default:
+ goto fail;
+ }
+
+ http_log("%s:%d - - [%s] \"PLAY %s/streamid=%d %s\"\n",
+ ipaddr, ntohs(dest_addr->sin_port),
+ ctime1(buf2),
+ c->stream->filename, stream_index, c->protocol);
+
+ /* normally, no packets should be output here, but the packet size may be checked */
+ if (url_open_dyn_packet_buf(&ctx->pb, max_packet_size) < 0) {
+ /* XXX: close stream */
+ goto fail;
+ }
+ av_set_parameters(ctx, NULL);
+ if (av_write_header(ctx) < 0) {
+ fail:
+ if (h)
+ url_close(h);
+ av_free(ctx);
+ return -1;
+ }
+ url_close_dyn_buf(&ctx->pb, &dummy_buf);
+ av_free(dummy_buf);
+
+ c->rtp_ctx[stream_index] = ctx;
+ return 0;
+}
+
+/********************************************************************/
+/* ffserver initialization */
+
+static AVStream *add_av_stream1(FFStream *stream, AVCodecContext *codec)
+{
+ AVStream *fst;
+
+ fst = av_mallocz(sizeof(AVStream));
+ if (!fst)
+ return NULL;
+ fst->codec= avcodec_alloc_context();
+ fst->priv_data = av_mallocz(sizeof(FeedData));
+ memcpy(fst->codec, codec, sizeof(AVCodecContext));
+ fst->codec->coded_frame = &dummy_frame;
+ fst->index = stream->nb_streams;
+ av_set_pts_info(fst, 33, 1, 90000);
+ stream->streams[stream->nb_streams++] = fst;
+ return fst;
+}
+
+/* return the stream number in the feed */
+static int add_av_stream(FFStream *feed, AVStream *st)
+{
+ AVStream *fst;
+ AVCodecContext *av, *av1;
+ int i;
+
+ av = st->codec;
+ for(i=0;i<feed->nb_streams;i++) {
+ st = feed->streams[i];
+ av1 = st->codec;
+ if (av1->codec_id == av->codec_id &&
+ av1->codec_type == av->codec_type &&
+ av1->bit_rate == av->bit_rate) {
+
+ switch(av->codec_type) {
+ case CODEC_TYPE_AUDIO:
+ if (av1->channels == av->channels &&
+ av1->sample_rate == av->sample_rate)
+ goto found;
+ break;
+ case CODEC_TYPE_VIDEO:
+ if (av1->width == av->width &&
+ av1->height == av->height &&
+ av1->time_base.den == av->time_base.den &&
+ av1->time_base.num == av->time_base.num &&
+ av1->gop_size == av->gop_size)
+ goto found;
+ break;
+ default:
+ av_abort();
+ }
+ }
+ }
+
+ fst = add_av_stream1(feed, av);
+ if (!fst)
+ return -1;
+ return feed->nb_streams - 1;
+ found:
+ return i;
+}
+
+static void remove_stream(FFStream *stream)
+{
+ FFStream **ps;
+ ps = &first_stream;
+ while (*ps != NULL) {
+ if (*ps == stream) {
+ *ps = (*ps)->next;
+ } else {
+ ps = &(*ps)->next;
+ }
+ }
+}
+
+/* specific mpeg4 handling : we extract the raw parameters */
+static void extract_mpeg4_header(AVFormatContext *infile)
+{
+ int mpeg4_count, i, size;
+ AVPacket pkt;
+ AVStream *st;
+ const uint8_t *p;
+
+ mpeg4_count = 0;
+ for(i=0;i<infile->nb_streams;i++) {
+ st = infile->streams[i];
+ if (st->codec->codec_id == CODEC_ID_MPEG4 &&
+ st->codec->extradata_size == 0) {
+ mpeg4_count++;
+ }
+ }
+ if (!mpeg4_count)
+ return;
+
+ printf("MPEG4 without extra data: trying to find header in %s\n", infile->filename);
+ while (mpeg4_count > 0) {
+ if (av_read_packet(infile, &pkt) < 0)
+ break;
+ st = infile->streams[pkt.stream_index];
+ if (st->codec->codec_id == CODEC_ID_MPEG4 &&
+ st->codec->extradata_size == 0) {
+ av_freep(&st->codec->extradata);
+ /* fill extradata with the header */
+ /* XXX: we make hard suppositions here ! */
+ p = pkt.data;
+ while (p < pkt.data + pkt.size - 4) {
+ /* stop when vop header is found */
+ if (p[0] == 0x00 && p[1] == 0x00 &&
+ p[2] == 0x01 && p[3] == 0xb6) {
+ size = p - pkt.data;
+ // av_hex_dump_log(infile, AV_LOG_DEBUG, pkt.data, size);
+ st->codec->extradata = av_malloc(size);
+ st->codec->extradata_size = size;
+ memcpy(st->codec->extradata, pkt.data, size);
+ break;
+ }
+ p++;
+ }
+ mpeg4_count--;
+ }
+ av_free_packet(&pkt);
+ }
+}
+
+/* compute the needed AVStream for each file */
+static void build_file_streams(void)
+{
+ FFStream *stream, *stream_next;
+ AVFormatContext *infile;
+ int i;
+
+ /* gather all streams */
+ for(stream = first_stream; stream != NULL; stream = stream_next) {
+ stream_next = stream->next;
+ if (stream->stream_type == STREAM_TYPE_LIVE &&
+ !stream->feed) {
+ /* the stream comes from a file */
+ /* try to open the file */
+ /* open stream */
+ stream->ap_in = av_mallocz(sizeof(AVFormatParameters));
+ if (stream->fmt == &rtp_muxer) {
+ /* specific case : if transport stream output to RTP,
+ we use a raw transport stream reader */
+ stream->ap_in->mpeg2ts_raw = 1;
+ stream->ap_in->mpeg2ts_compute_pcr = 1;
+ }
+
+ if (av_open_input_file(&infile, stream->feed_filename,
+ stream->ifmt, 0, stream->ap_in) < 0) {
+ http_log("%s not found", stream->feed_filename);
+ /* remove stream (no need to spend more time on it) */
+ fail:
+ remove_stream(stream);
+ } else {
+ /* find all the AVStreams inside and reference them in
+ 'stream' */
+ if (av_find_stream_info(infile) < 0) {
+ http_log("Could not find codec parameters from '%s'",
+ stream->feed_filename);
+ av_close_input_file(infile);
+ goto fail;
+ }
+ extract_mpeg4_header(infile);
+
+ for(i=0;i<infile->nb_streams;i++) {
+ add_av_stream1(stream, infile->streams[i]->codec);
+ }
+ av_close_input_file(infile);
+ }
+ }
+ }
+}
+
+/* compute the needed AVStream for each feed */
+static void build_feed_streams(void)
+{
+ FFStream *stream, *feed;
+ int i;
+
+ /* gather all streams */
+ for(stream = first_stream; stream != NULL; stream = stream->next) {
+ feed = stream->feed;
+ if (feed) {
+ if (!stream->is_feed) {
+ /* we handle a stream coming from a feed */
+ for(i=0;i<stream->nb_streams;i++) {
+ stream->feed_streams[i] = add_av_stream(feed, stream->streams[i]);
+ }
+ }
+ }
+ }
+
+ /* gather all streams */
+ for(stream = first_stream; stream != NULL; stream = stream->next) {
+ feed = stream->feed;
+ if (feed) {
+ if (stream->is_feed) {
+ for(i=0;i<stream->nb_streams;i++) {
+ stream->feed_streams[i] = i;
+ }
+ }
+ }
+ }
+
+ /* create feed files if needed */
+ for(feed = first_feed; feed != NULL; feed = feed->next_feed) {
+ int fd;
+
+ if (url_exist(feed->feed_filename)) {
+ /* See if it matches */
+ AVFormatContext *s;
+ int matches = 0;
+
+ if (av_open_input_file(&s, feed->feed_filename, NULL, FFM_PACKET_SIZE, NULL) >= 0) {
+ /* Now see if it matches */
+ if (s->nb_streams == feed->nb_streams) {
+ matches = 1;
+ for(i=0;i<s->nb_streams;i++) {
+ AVStream *sf, *ss;
+ sf = feed->streams[i];
+ ss = s->streams[i];
+
+ if (sf->index != ss->index ||
+ sf->id != ss->id) {
+ printf("Index & Id do not match for stream %d (%s)\n",
+ i, feed->feed_filename);
+ matches = 0;
+ } else {
+ AVCodecContext *ccf, *ccs;
+
+ ccf = sf->codec;
+ ccs = ss->codec;
+#define CHECK_CODEC(x) (ccf->x != ccs->x)
+
+ if (CHECK_CODEC(codec) || CHECK_CODEC(codec_type)) {
+ printf("Codecs do not match for stream %d\n", i);
+ matches = 0;
+ } else if (CHECK_CODEC(bit_rate) || CHECK_CODEC(flags)) {
+ printf("Codec bitrates do not match for stream %d\n", i);
+ matches = 0;
+ } else if (ccf->codec_type == CODEC_TYPE_VIDEO) {
+ if (CHECK_CODEC(time_base.den) ||
+ CHECK_CODEC(time_base.num) ||
+ CHECK_CODEC(width) ||
+ CHECK_CODEC(height)) {
+ printf("Codec width, height and framerate do not match for stream %d\n", i);
+ matches = 0;
+ }
+ } else if (ccf->codec_type == CODEC_TYPE_AUDIO) {
+ if (CHECK_CODEC(sample_rate) ||
+ CHECK_CODEC(channels) ||
+ CHECK_CODEC(frame_size)) {
+ printf("Codec sample_rate, channels, frame_size do not match for stream %d\n", i);
+ matches = 0;
+ }
+ } else {
+ printf("Unknown codec type\n");
+ matches = 0;
+ }
+ }
+ if (!matches) {
+ break;
+ }
+ }
+ } else {
+ printf("Deleting feed file '%s' as stream counts differ (%d != %d)\n",
+ feed->feed_filename, s->nb_streams, feed->nb_streams);
+ }
+
+ av_close_input_file(s);
+ } else {
+ printf("Deleting feed file '%s' as it appears to be corrupt\n",
+ feed->feed_filename);
+ }
+ if (!matches) {
+ if (feed->readonly) {
+ printf("Unable to delete feed file '%s' as it is marked readonly\n",
+ feed->feed_filename);
+ exit(1);
+ }
+ unlink(feed->feed_filename);
+ }
+ }
+ if (!url_exist(feed->feed_filename)) {
+ AVFormatContext s1, *s = &s1;
+
+ if (feed->readonly) {
+ printf("Unable to create feed file '%s' as it is marked readonly\n",
+ feed->feed_filename);
+ exit(1);
+ }
+
+ /* only write the header of the ffm file */
+ if (url_fopen(&s->pb, feed->feed_filename, URL_WRONLY) < 0) {
+ fprintf(stderr, "Could not open output feed file '%s'\n",
+ feed->feed_filename);
+ exit(1);
+ }
+ s->oformat = feed->fmt;
+ s->nb_streams = feed->nb_streams;
+ for(i=0;i<s->nb_streams;i++) {
+ AVStream *st;
+ st = feed->streams[i];
+ s->streams[i] = st;
+ }
+ av_set_parameters(s, NULL);
+ if (av_write_header(s) < 0) {
+ fprintf(stderr, "Container doesn't supports the required parameters\n");
+ exit(1);
+ }
+ /* XXX: need better api */
+ av_freep(&s->priv_data);
+ url_fclose(&s->pb);
+ }
+ /* get feed size and write index */
+ fd = open(feed->feed_filename, O_RDONLY);
+ if (fd < 0) {
+ fprintf(stderr, "Could not open output feed file '%s'\n",
+ feed->feed_filename);
+ exit(1);
+ }
+
+ feed->feed_write_index = ffm_read_write_index(fd);
+ feed->feed_size = lseek(fd, 0, SEEK_END);
+ /* ensure that we do not wrap before the end of file */
+ if (feed->feed_max_size && feed->feed_max_size < feed->feed_size)
+ feed->feed_max_size = feed->feed_size;
+
+ close(fd);
+ }
+}
+
+/* compute the bandwidth used by each stream */
+static void compute_bandwidth(void)
+{
+ int bandwidth, i;
+ FFStream *stream;
+
+ for(stream = first_stream; stream != NULL; stream = stream->next) {
+ bandwidth = 0;
+ for(i=0;i<stream->nb_streams;i++) {
+ AVStream *st = stream->streams[i];
+ switch(st->codec->codec_type) {
+ case CODEC_TYPE_AUDIO:
+ case CODEC_TYPE_VIDEO:
+ bandwidth += st->codec->bit_rate;
+ break;
+ default:
+ break;
+ }
+ }
+ stream->bandwidth = (bandwidth + 999) / 1000;
+ }
+}
+
+static void get_arg(char *buf, int buf_size, const char **pp)
+{
+ const char *p;
+ char *q;
+ int quote;
+
+ p = *pp;
+ while (isspace(*p)) p++;
+ q = buf;
+ quote = 0;
+ if (*p == '\"' || *p == '\'')
+ quote = *p++;
+ for(;;) {
+ if (quote) {
+ if (*p == quote)
+ break;
+ } else {
+ if (isspace(*p))
+ break;
+ }
+ if (*p == '\0')
+ break;
+ if ((q - buf) < buf_size - 1)
+ *q++ = *p;
+ p++;
+ }
+ *q = '\0';
+ if (quote && *p == quote)
+ p++;
+ *pp = p;
+}
+
+/* add a codec and set the default parameters */
+static void add_codec(FFStream *stream, AVCodecContext *av)
+{
+ AVStream *st;
+
+ /* compute default parameters */
+ switch(av->codec_type) {
+ case CODEC_TYPE_AUDIO:
+ if (av->bit_rate == 0)
+ av->bit_rate = 64000;
+ if (av->sample_rate == 0)
+ av->sample_rate = 22050;
+ if (av->channels == 0)
+ av->channels = 1;
+ break;
+ case CODEC_TYPE_VIDEO:
+ if (av->bit_rate == 0)
+ av->bit_rate = 64000;
+ if (av->time_base.num == 0){
+ av->time_base.den = 5;
+ av->time_base.num = 1;
+ }
+ if (av->width == 0 || av->height == 0) {
+ av->width = 160;
+ av->height = 128;
+ }
+ /* Bitrate tolerance is less for streaming */
+ if (av->bit_rate_tolerance == 0)
+ av->bit_rate_tolerance = av->bit_rate / 4;
+ if (av->qmin == 0)
+ av->qmin = 3;
+ if (av->qmax == 0)
+ av->qmax = 31;
+ if (av->max_qdiff == 0)
+ av->max_qdiff = 3;
+ av->qcompress = 0.5;
+ av->qblur = 0.5;
+
+ if (!av->nsse_weight)
+ av->nsse_weight = 8;
+
+ av->frame_skip_cmp = FF_CMP_DCTMAX;
+ av->me_method = ME_EPZS;
+ av->rc_buffer_aggressivity = 1.0;
+
+ if (!av->rc_eq)
+ av->rc_eq = "tex^qComp";
+ if (!av->i_quant_factor)
+ av->i_quant_factor = -0.8;
+ if (!av->b_quant_factor)
+ av->b_quant_factor = 1.25;
+ if (!av->b_quant_offset)
+ av->b_quant_offset = 1.25;
+ if (!av->rc_max_rate)
+ av->rc_max_rate = av->bit_rate * 2;
+
+ if (av->rc_max_rate && !av->rc_buffer_size) {
+ av->rc_buffer_size = av->rc_max_rate;
+ }
+
+
+ break;
+ default:
+ av_abort();
+ }
+
+ st = av_mallocz(sizeof(AVStream));
+ if (!st)
+ return;
+ st->codec = avcodec_alloc_context();
+ stream->streams[stream->nb_streams++] = st;
+ memcpy(st->codec, av, sizeof(AVCodecContext));
+}
+
+static int opt_audio_codec(const char *arg)
+{
+ AVCodec *p;
+
+ p = first_avcodec;
+ while (p) {
+ if (!strcmp(p->name, arg) && p->type == CODEC_TYPE_AUDIO)
+ break;
+ p = p->next;
+ }
+ if (p == NULL) {
+ return CODEC_ID_NONE;
+ }
+
+ return p->id;
+}
+
+static int opt_video_codec(const char *arg)
+{
+ AVCodec *p;
+
+ p = first_avcodec;
+ while (p) {
+ if (!strcmp(p->name, arg) && p->type == CODEC_TYPE_VIDEO)
+ break;
+ p = p->next;
+ }
+ if (p == NULL) {
+ return CODEC_ID_NONE;
+ }
+
+ return p->id;
+}
+
+/* simplistic plugin support */
+
+#ifdef HAVE_DLOPEN
+static void load_module(const char *filename)
+{
+ void *dll;
+ void (*init_func)(void);
+ dll = dlopen(filename, RTLD_NOW);
+ if (!dll) {
+ fprintf(stderr, "Could not load module '%s' - %s\n",
+ filename, dlerror());
+ return;
+ }
+
+ init_func = dlsym(dll, "ffserver_module_init");
+ if (!init_func) {
+ fprintf(stderr,
+ "%s: init function 'ffserver_module_init()' not found\n",
+ filename);
+ dlclose(dll);
+ }
+
+ init_func();
+}
+#endif
+
+static int parse_ffconfig(const char *filename)
+{
+ FILE *f;
+ char line[1024];
+ char cmd[64];
+ char arg[1024];
+ const char *p;
+ int val, errors, line_num;
+ FFStream **last_stream, *stream, *redirect;
+ FFStream **last_feed, *feed;
+ AVCodecContext audio_enc, video_enc;
+ int audio_id, video_id;
+
+ f = fopen(filename, "r");
+ if (!f) {
+ perror(filename);
+ return -1;
+ }
+
+ errors = 0;
+ line_num = 0;
+ first_stream = NULL;
+ last_stream = &first_stream;
+ first_feed = NULL;
+ last_feed = &first_feed;
+ stream = NULL;
+ feed = NULL;
+ redirect = NULL;
+ audio_id = CODEC_ID_NONE;
+ video_id = CODEC_ID_NONE;
+ for(;;) {
+ if (fgets(line, sizeof(line), f) == NULL)
+ break;
+ line_num++;
+ p = line;
+ while (isspace(*p))
+ p++;
+ if (*p == '\0' || *p == '#')
+ continue;
+
+ get_arg(cmd, sizeof(cmd), &p);
+
+ if (!strcasecmp(cmd, "Port")) {
+ get_arg(arg, sizeof(arg), &p);
+ my_http_addr.sin_port = htons (atoi(arg));
+ } else if (!strcasecmp(cmd, "BindAddress")) {
+ get_arg(arg, sizeof(arg), &p);
+ if (!inet_aton(arg, &my_http_addr.sin_addr)) {
+ fprintf(stderr, "%s:%d: Invalid IP address: %s\n",
+ filename, line_num, arg);
+ errors++;
+ }
+ } else if (!strcasecmp(cmd, "NoDaemon")) {
+ ffserver_daemon = 0;
+ } else if (!strcasecmp(cmd, "RTSPPort")) {
+ get_arg(arg, sizeof(arg), &p);
+ my_rtsp_addr.sin_port = htons (atoi(arg));
+ } else if (!strcasecmp(cmd, "RTSPBindAddress")) {
+ get_arg(arg, sizeof(arg), &p);
+ if (!inet_aton(arg, &my_rtsp_addr.sin_addr)) {
+ fprintf(stderr, "%s:%d: Invalid IP address: %s\n",
+ filename, line_num, arg);
+ errors++;
+ }
+ } else if (!strcasecmp(cmd, "MaxClients")) {
+ get_arg(arg, sizeof(arg), &p);
+ val = atoi(arg);
+ if (val < 1 || val > HTTP_MAX_CONNECTIONS) {
+ fprintf(stderr, "%s:%d: Invalid MaxClients: %s\n",
+ filename, line_num, arg);
+ errors++;
+ } else {
+ nb_max_connections = val;
+ }
+ } else if (!strcasecmp(cmd, "MaxBandwidth")) {
+ get_arg(arg, sizeof(arg), &p);
+ val = atoi(arg);
+ if (val < 10 || val > 100000) {
+ fprintf(stderr, "%s:%d: Invalid MaxBandwidth: %s\n",
+ filename, line_num, arg);
+ errors++;
+ } else {
+ max_bandwidth = val;
+ }
+ } else if (!strcasecmp(cmd, "CustomLog")) {
+ get_arg(logfilename, sizeof(logfilename), &p);
+ } else if (!strcasecmp(cmd, "<Feed")) {
+ /*********************************************/
+ /* Feed related options */
+ char *q;
+ if (stream || feed) {
+ fprintf(stderr, "%s:%d: Already in a tag\n",
+ filename, line_num);
+ } else {
+ feed = av_mallocz(sizeof(FFStream));
+ /* add in stream list */
+ *last_stream = feed;
+ last_stream = &feed->next;
+ /* add in feed list */
+ *last_feed = feed;
+ last_feed = &feed->next_feed;
+
+ get_arg(feed->filename, sizeof(feed->filename), &p);
+ q = strrchr(feed->filename, '>');
+ if (*q)
+ *q = '\0';
+ feed->fmt = guess_format("ffm", NULL, NULL);
+ /* defaut feed file */
+ snprintf(feed->feed_filename, sizeof(feed->feed_filename),
+ "/tmp/%s.ffm", feed->filename);
+ feed->feed_max_size = 5 * 1024 * 1024;
+ feed->is_feed = 1;
+ feed->feed = feed; /* self feeding :-) */
+ }
+ } else if (!strcasecmp(cmd, "Launch")) {
+ if (feed) {
+ int i;
+
+ feed->child_argv = (char **) av_mallocz(64 * sizeof(char *));
+
+ for (i = 0; i < 62; i++) {
+ char argbuf[256];
+
+ get_arg(argbuf, sizeof(argbuf), &p);
+ if (!argbuf[0])
+ break;
+
+ feed->child_argv[i] = av_malloc(strlen(argbuf) + 1);
+ strcpy(feed->child_argv[i], argbuf);
+ }
+
+ feed->child_argv[i] = av_malloc(30 + strlen(feed->filename));
+
+ snprintf(feed->child_argv[i], 30+strlen(feed->filename),
+ "http://%s:%d/%s",
+ (my_http_addr.sin_addr.s_addr == INADDR_ANY) ? "127.0.0.1" :
+ inet_ntoa(my_http_addr.sin_addr),
+ ntohs(my_http_addr.sin_port), feed->filename);
+
+ if (ffserver_debug)
+ {
+ int j;
+ fprintf(stdout, "Launch commandline: ");
+ for (j = 0; j <= i; j++)
+ fprintf(stdout, "%s ", feed->child_argv[j]);
+ fprintf(stdout, "\n");
+ }
+ }
+ } else if (!strcasecmp(cmd, "ReadOnlyFile")) {
+ if (feed) {
+ get_arg(feed->feed_filename, sizeof(feed->feed_filename), &p);
+ feed->readonly = 1;
+ } else if (stream) {
+ get_arg(stream->feed_filename, sizeof(stream->feed_filename), &p);
+ }
+ } else if (!strcasecmp(cmd, "File")) {
+ if (feed) {
+ get_arg(feed->feed_filename, sizeof(feed->feed_filename), &p);
+ } else if (stream) {
+ get_arg(stream->feed_filename, sizeof(stream->feed_filename), &p);
+ }
+ } else if (!strcasecmp(cmd, "FileMaxSize")) {
+ if (feed) {
+ const char *p1;
+ double fsize;
+
+ get_arg(arg, sizeof(arg), &p);
+ p1 = arg;
+ fsize = strtod(p1, (char **)&p1);
+ switch(toupper(*p1)) {
+ case 'K':
+ fsize *= 1024;
+ break;
+ case 'M':
+ fsize *= 1024 * 1024;
+ break;
+ case 'G':
+ fsize *= 1024 * 1024 * 1024;
+ break;
+ }
+ feed->feed_max_size = (int64_t)fsize;
+ }
+ } else if (!strcasecmp(cmd, "</Feed>")) {
+ if (!feed) {
+ fprintf(stderr, "%s:%d: No corresponding <Feed> for </Feed>\n",
+ filename, line_num);
+ errors++;
+#if 0
+ } else {
+ /* Make sure that we start out clean */
+ if (unlink(feed->feed_filename) < 0
+ && errno != ENOENT) {
+ fprintf(stderr, "%s:%d: Unable to clean old feed file '%s': %s\n",
+ filename, line_num, feed->feed_filename, strerror(errno));
+ errors++;
+ }
+#endif
+ }
+ feed = NULL;
+ } else if (!strcasecmp(cmd, "<Stream")) {
+ /*********************************************/
+ /* Stream related options */
+ char *q;
+ if (stream || feed) {
+ fprintf(stderr, "%s:%d: Already in a tag\n",
+ filename, line_num);
+ } else {
+ stream = av_mallocz(sizeof(FFStream));
+ *last_stream = stream;
+ last_stream = &stream->next;
+
+ get_arg(stream->filename, sizeof(stream->filename), &p);
+ q = strrchr(stream->filename, '>');
+ if (*q)
+ *q = '\0';
+ stream->fmt = guess_stream_format(NULL, stream->filename, NULL);
+ memset(&audio_enc, 0, sizeof(AVCodecContext));
+ memset(&video_enc, 0, sizeof(AVCodecContext));
+ audio_id = CODEC_ID_NONE;
+ video_id = CODEC_ID_NONE;
+ if (stream->fmt) {
+ audio_id = stream->fmt->audio_codec;
+ video_id = stream->fmt->video_codec;
+ }
+ }
+ } else if (!strcasecmp(cmd, "Feed")) {
+ get_arg(arg, sizeof(arg), &p);
+ if (stream) {
+ FFStream *sfeed;
+
+ sfeed = first_feed;
+ while (sfeed != NULL) {
+ if (!strcmp(sfeed->filename, arg))
+ break;
+ sfeed = sfeed->next_feed;
+ }
+ if (!sfeed) {
+ fprintf(stderr, "%s:%d: feed '%s' not defined\n",
+ filename, line_num, arg);
+ } else {
+ stream->feed = sfeed;
+ }
+ }
+ } else if (!strcasecmp(cmd, "Format")) {
+ get_arg(arg, sizeof(arg), &p);
+ if (!strcmp(arg, "status")) {
+ stream->stream_type = STREAM_TYPE_STATUS;
+ stream->fmt = NULL;
+ } else {
+ stream->stream_type = STREAM_TYPE_LIVE;
+ /* jpeg cannot be used here, so use single frame jpeg */
+ if (!strcmp(arg, "jpeg"))
+ strcpy(arg, "mjpeg");
+ stream->fmt = guess_stream_format(arg, NULL, NULL);
+ if (!stream->fmt) {
+ fprintf(stderr, "%s:%d: Unknown Format: %s\n",
+ filename, line_num, arg);
+ errors++;
+ }
+ }
+ if (stream->fmt) {
+ audio_id = stream->fmt->audio_codec;
+ video_id = stream->fmt->video_codec;
+ }
+ } else if (!strcasecmp(cmd, "InputFormat")) {
+ stream->ifmt = av_find_input_format(arg);
+ if (!stream->ifmt) {
+ fprintf(stderr, "%s:%d: Unknown input format: %s\n",
+ filename, line_num, arg);
+ }
+ } else if (!strcasecmp(cmd, "FaviconURL")) {
+ if (stream && stream->stream_type == STREAM_TYPE_STATUS) {
+ get_arg(stream->feed_filename, sizeof(stream->feed_filename), &p);
+ } else {
+ fprintf(stderr, "%s:%d: FaviconURL only permitted for status streams\n",
+ filename, line_num);
+ errors++;
+ }
+ } else if (!strcasecmp(cmd, "Author")) {
+ if (stream) {
+ get_arg(stream->author, sizeof(stream->author), &p);
+ }
+ } else if (!strcasecmp(cmd, "Comment")) {
+ if (stream) {
+ get_arg(stream->comment, sizeof(stream->comment), &p);
+ }
+ } else if (!strcasecmp(cmd, "Copyright")) {
+ if (stream) {
+ get_arg(stream->copyright, sizeof(stream->copyright), &p);
+ }
+ } else if (!strcasecmp(cmd, "Title")) {
+ if (stream) {
+ get_arg(stream->title, sizeof(stream->title), &p);
+ }
+ } else if (!strcasecmp(cmd, "Preroll")) {
+ get_arg(arg, sizeof(arg), &p);
+ if (stream) {
+ stream->prebuffer = atof(arg) * 1000;
+ }
+ } else if (!strcasecmp(cmd, "StartSendOnKey")) {
+ if (stream) {
+ stream->send_on_key = 1;
+ }
+ } else if (!strcasecmp(cmd, "AudioCodec")) {
+ get_arg(arg, sizeof(arg), &p);
+ audio_id = opt_audio_codec(arg);
+ if (audio_id == CODEC_ID_NONE) {
+ fprintf(stderr, "%s:%d: Unknown AudioCodec: %s\n",
+ filename, line_num, arg);
+ errors++;
+ }
+ } else if (!strcasecmp(cmd, "VideoCodec")) {
+ get_arg(arg, sizeof(arg), &p);
+ video_id = opt_video_codec(arg);
+ if (video_id == CODEC_ID_NONE) {
+ fprintf(stderr, "%s:%d: Unknown VideoCodec: %s\n",
+ filename, line_num, arg);
+ errors++;
+ }
+ } else if (!strcasecmp(cmd, "MaxTime")) {
+ get_arg(arg, sizeof(arg), &p);
+ if (stream) {
+ stream->max_time = atof(arg) * 1000;
+ }
+ } else if (!strcasecmp(cmd, "AudioBitRate")) {
+ get_arg(arg, sizeof(arg), &p);
+ if (stream) {
+ audio_enc.bit_rate = atoi(arg) * 1000;
+ }
+ } else if (!strcasecmp(cmd, "AudioChannels")) {
+ get_arg(arg, sizeof(arg), &p);
+ if (stream) {
+ audio_enc.channels = atoi(arg);
+ }
+ } else if (!strcasecmp(cmd, "AudioSampleRate")) {
+ get_arg(arg, sizeof(arg), &p);
+ if (stream) {
+ audio_enc.sample_rate = atoi(arg);
+ }
+ } else if (!strcasecmp(cmd, "AudioQuality")) {
+ get_arg(arg, sizeof(arg), &p);
+ if (stream) {
+// audio_enc.quality = atof(arg) * 1000;
+ }
+ } else if (!strcasecmp(cmd, "VideoBitRateRange")) {
+ if (stream) {
+ int minrate, maxrate;
+
+ get_arg(arg, sizeof(arg), &p);
+
+ if (sscanf(arg, "%d-%d", &minrate, &maxrate) == 2) {
+ video_enc.rc_min_rate = minrate * 1000;
+ video_enc.rc_max_rate = maxrate * 1000;
+ } else {
+ fprintf(stderr, "%s:%d: Incorrect format for VideoBitRateRange -- should be <min>-<max>: %s\n",
+ filename, line_num, arg);
+ errors++;
+ }
+ }
+ } else if (!strcasecmp(cmd, "Debug")) {
+ if (stream) {
+ get_arg(arg, sizeof(arg), &p);
+ video_enc.debug = strtol(arg,0,0);
+ }
+ } else if (!strcasecmp(cmd, "Strict")) {
+ if (stream) {
+ get_arg(arg, sizeof(arg), &p);
+ video_enc.strict_std_compliance = atoi(arg);
+ }
+ } else if (!strcasecmp(cmd, "VideoBufferSize")) {
+ if (stream) {
+ get_arg(arg, sizeof(arg), &p);
+ video_enc.rc_buffer_size = atoi(arg) * 8*1024;
+ }
+ } else if (!strcasecmp(cmd, "VideoBitRateTolerance")) {
+ if (stream) {
+ get_arg(arg, sizeof(arg), &p);
+ video_enc.bit_rate_tolerance = atoi(arg) * 1000;
+ }
+ } else if (!strcasecmp(cmd, "VideoBitRate")) {
+ get_arg(arg, sizeof(arg), &p);
+ if (stream) {
+ video_enc.bit_rate = atoi(arg) * 1000;
+ }
+ } else if (!strcasecmp(cmd, "VideoSize")) {
+ get_arg(arg, sizeof(arg), &p);
+ if (stream) {
+ parse_image_size(&video_enc.width, &video_enc.height, arg);
+ if ((video_enc.width % 16) != 0 ||
+ (video_enc.height % 16) != 0) {
+ fprintf(stderr, "%s:%d: Image size must be a multiple of 16\n",
+ filename, line_num);
+ errors++;
+ }
+ }
+ } else if (!strcasecmp(cmd, "VideoFrameRate")) {
+ get_arg(arg, sizeof(arg), &p);
+ if (stream) {
+ video_enc.time_base.num= DEFAULT_FRAME_RATE_BASE;
+ video_enc.time_base.den = (int)(strtod(arg, NULL) * video_enc.time_base.num);
+ }
+ } else if (!strcasecmp(cmd, "VideoGopSize")) {
+ get_arg(arg, sizeof(arg), &p);
+ if (stream) {
+ video_enc.gop_size = atoi(arg);
+ }
+ } else if (!strcasecmp(cmd, "VideoIntraOnly")) {
+ if (stream) {
+ video_enc.gop_size = 1;
+ }
+ } else if (!strcasecmp(cmd, "VideoHighQuality")) {
+ if (stream) {
+ video_enc.mb_decision = FF_MB_DECISION_BITS;
+ }
+ } else if (!strcasecmp(cmd, "Video4MotionVector")) {
+ if (stream) {
+ video_enc.mb_decision = FF_MB_DECISION_BITS; //FIXME remove
+ video_enc.flags |= CODEC_FLAG_4MV;
+ }
+ } else if (!strcasecmp(cmd, "VideoTag")) {
+ get_arg(arg, sizeof(arg), &p);
+ if ((strlen(arg) == 4) && stream) {
+ video_enc.codec_tag = ff_get_fourcc(arg);
+ }
+ } else if (!strcasecmp(cmd, "BitExact")) {
+ if (stream) {
+ video_enc.flags |= CODEC_FLAG_BITEXACT;
+ }
+ } else if (!strcasecmp(cmd, "DctFastint")) {
+ if (stream) {
+ video_enc.dct_algo = FF_DCT_FASTINT;
+ }
+ } else if (!strcasecmp(cmd, "IdctSimple")) {
+ if (stream) {
+ video_enc.idct_algo = FF_IDCT_SIMPLE;
+ }
+ } else if (!strcasecmp(cmd, "Qscale")) {
+ get_arg(arg, sizeof(arg), &p);
+ if (stream) {
+ video_enc.flags |= CODEC_FLAG_QSCALE;
+ video_enc.global_quality = FF_QP2LAMBDA * atoi(arg);
+ }
+ } else if (!strcasecmp(cmd, "VideoQDiff")) {
+ get_arg(arg, sizeof(arg), &p);
+ if (stream) {
+ video_enc.max_qdiff = atoi(arg);
+ if (video_enc.max_qdiff < 1 || video_enc.max_qdiff > 31) {
+ fprintf(stderr, "%s:%d: VideoQDiff out of range\n",
+ filename, line_num);
+ errors++;
+ }
+ }
+ } else if (!strcasecmp(cmd, "VideoQMax")) {
+ get_arg(arg, sizeof(arg), &p);
+ if (stream) {
+ video_enc.qmax = atoi(arg);
+ if (video_enc.qmax < 1 || video_enc.qmax > 31) {
+ fprintf(stderr, "%s:%d: VideoQMax out of range\n",
+ filename, line_num);
+ errors++;
+ }
+ }
+ } else if (!strcasecmp(cmd, "VideoQMin")) {
+ get_arg(arg, sizeof(arg), &p);
+ if (stream) {
+ video_enc.qmin = atoi(arg);
+ if (video_enc.qmin < 1 || video_enc.qmin > 31) {
+ fprintf(stderr, "%s:%d: VideoQMin out of range\n",
+ filename, line_num);
+ errors++;
+ }
+ }
+ } else if (!strcasecmp(cmd, "LumaElim")) {
+ get_arg(arg, sizeof(arg), &p);
+ if (stream) {
+ video_enc.luma_elim_threshold = atoi(arg);
+ }
+ } else if (!strcasecmp(cmd, "ChromaElim")) {
+ get_arg(arg, sizeof(arg), &p);
+ if (stream) {
+ video_enc.chroma_elim_threshold = atoi(arg);
+ }
+ } else if (!strcasecmp(cmd, "LumiMask")) {
+ get_arg(arg, sizeof(arg), &p);
+ if (stream) {
+ video_enc.lumi_masking = atof(arg);
+ }
+ } else if (!strcasecmp(cmd, "DarkMask")) {
+ get_arg(arg, sizeof(arg), &p);
+ if (stream) {
+ video_enc.dark_masking = atof(arg);
+ }
+ } else if (!strcasecmp(cmd, "NoVideo")) {
+ video_id = CODEC_ID_NONE;
+ } else if (!strcasecmp(cmd, "NoAudio")) {
+ audio_id = CODEC_ID_NONE;
+ } else if (!strcasecmp(cmd, "ACL")) {
+ IPAddressACL acl;
+ struct hostent *he;
+
+ get_arg(arg, sizeof(arg), &p);
+ if (strcasecmp(arg, "allow") == 0) {
+ acl.action = IP_ALLOW;
+ } else if (strcasecmp(arg, "deny") == 0) {
+ acl.action = IP_DENY;
+ } else {
+ fprintf(stderr, "%s:%d: ACL action '%s' is not ALLOW or DENY\n",
+ filename, line_num, arg);
+ errors++;
+ }
+
+ get_arg(arg, sizeof(arg), &p);
+
+ he = gethostbyname(arg);
+ if (!he) {
+ fprintf(stderr, "%s:%d: ACL refers to invalid host or ip address '%s'\n",
+ filename, line_num, arg);
+ errors++;
+ } else {
+ /* Only take the first */
+ acl.first.s_addr = ntohl(((struct in_addr *) he->h_addr_list[0])->s_addr);
+ acl.last = acl.first;
+ }
+
+ get_arg(arg, sizeof(arg), &p);
+
+ if (arg[0]) {
+ he = gethostbyname(arg);
+ if (!he) {
+ fprintf(stderr, "%s:%d: ACL refers to invalid host or ip address '%s'\n",
+ filename, line_num, arg);
+ errors++;
+ } else {
+ /* Only take the first */
+ acl.last.s_addr = ntohl(((struct in_addr *) he->h_addr_list[0])->s_addr);
+ }
+ }
+
+ if (!errors) {
+ IPAddressACL *nacl = (IPAddressACL *) av_mallocz(sizeof(*nacl));
+ IPAddressACL **naclp = 0;
+
+ acl.next = 0;
+ *nacl = acl;
+
+ if (stream) {
+ naclp = &stream->acl;
+ } else if (feed) {
+ naclp = &feed->acl;
+ } else {
+ fprintf(stderr, "%s:%d: ACL found not in <stream> or <feed>\n",
+ filename, line_num);
+ errors++;
+ }
+
+ if (naclp) {
+ while (*naclp)
+ naclp = &(*naclp)->next;
+
+ *naclp = nacl;
+ }
+ }
+ } else if (!strcasecmp(cmd, "RTSPOption")) {
+ get_arg(arg, sizeof(arg), &p);
+ if (stream) {
+ av_freep(&stream->rtsp_option);
+ stream->rtsp_option = av_strdup(arg);
+ }
+ } else if (!strcasecmp(cmd, "MulticastAddress")) {
+ get_arg(arg, sizeof(arg), &p);
+ if (stream) {
+ if (!inet_aton(arg, &stream->multicast_ip)) {
+ fprintf(stderr, "%s:%d: Invalid IP address: %s\n",
+ filename, line_num, arg);
+ errors++;
+ }
+ stream->is_multicast = 1;
+ stream->loop = 1; /* default is looping */
+ }
+ } else if (!strcasecmp(cmd, "MulticastPort")) {
+ get_arg(arg, sizeof(arg), &p);
+ if (stream) {
+ stream->multicast_port = atoi(arg);
+ }
+ } else if (!strcasecmp(cmd, "MulticastTTL")) {
+ get_arg(arg, sizeof(arg), &p);
+ if (stream) {
+ stream->multicast_ttl = atoi(arg);
+ }
+ } else if (!strcasecmp(cmd, "NoLoop")) {
+ if (stream) {
+ stream->loop = 0;
+ }
+ } else if (!strcasecmp(cmd, "</Stream>")) {
+ if (!stream) {
+ fprintf(stderr, "%s:%d: No corresponding <Stream> for </Stream>\n",
+ filename, line_num);
+ errors++;
+ }
+ if (stream->feed && stream->fmt && strcmp(stream->fmt->name, "ffm") != 0) {
+ if (audio_id != CODEC_ID_NONE) {
+ audio_enc.codec_type = CODEC_TYPE_AUDIO;
+ audio_enc.codec_id = audio_id;
+ add_codec(stream, &audio_enc);
+ }
+ if (video_id != CODEC_ID_NONE) {
+ video_enc.codec_type = CODEC_TYPE_VIDEO;
+ video_enc.codec_id = video_id;
+ add_codec(stream, &video_enc);
+ }
+ }
+ stream = NULL;
+ } else if (!strcasecmp(cmd, "<Redirect")) {
+ /*********************************************/
+ char *q;
+ if (stream || feed || redirect) {
+ fprintf(stderr, "%s:%d: Already in a tag\n",
+ filename, line_num);
+ errors++;
+ } else {
+ redirect = av_mallocz(sizeof(FFStream));
+ *last_stream = redirect;
+ last_stream = &redirect->next;
+
+ get_arg(redirect->filename, sizeof(redirect->filename), &p);
+ q = strrchr(redirect->filename, '>');
+ if (*q)
+ *q = '\0';
+ redirect->stream_type = STREAM_TYPE_REDIRECT;
+ }
+ } else if (!strcasecmp(cmd, "URL")) {
+ if (redirect) {
+ get_arg(redirect->feed_filename, sizeof(redirect->feed_filename), &p);
+ }
+ } else if (!strcasecmp(cmd, "</Redirect>")) {
+ if (!redirect) {
+ fprintf(stderr, "%s:%d: No corresponding <Redirect> for </Redirect>\n",
+ filename, line_num);
+ errors++;
+ }
+ if (!redirect->feed_filename[0]) {
+ fprintf(stderr, "%s:%d: No URL found for <Redirect>\n",
+ filename, line_num);
+ errors++;
+ }
+ redirect = NULL;
+ } else if (!strcasecmp(cmd, "LoadModule")) {
+ get_arg(arg, sizeof(arg), &p);
+#ifdef HAVE_DLOPEN
+ load_module(arg);
+#else
+ fprintf(stderr, "%s:%d: Module support not compiled into this version: '%s'\n",
+ filename, line_num, arg);
+ errors++;
+#endif
+ } else {
+ fprintf(stderr, "%s:%d: Incorrect keyword: '%s'\n",
+ filename, line_num, cmd);
+ errors++;
+ }
+ }
+
+ fclose(f);
+ if (errors)
+ return -1;
+ else
+ return 0;
+}
+
+static void show_banner(void)
+{
+ printf("ffserver version " FFMPEG_VERSION ", Copyright (c) 2000-2006 Fabrice Bellard, et al.\n");
+}
+
+static void show_help(void)
+{
+ show_banner();
+ printf("usage: ffserver [-L] [-h] [-f configfile]\n"
+ "Hyper fast multi format Audio/Video streaming server\n"
+ "\n"
+ "-L : print the LICENSE\n"
+ "-h : this help\n"
+ "-f configfile : use configfile instead of /etc/ffserver.conf\n"
+ );
+}
+
+static void show_license(void)
+{
+ show_banner();
+ printf(
+ "FFmpeg is free software; you can redistribute it and/or\n"
+ "modify it under the terms of the GNU Lesser General Public\n"
+ "License as published by the Free Software Foundation; either\n"
+ "version 2.1 of the License, or (at your option) any later version.\n"
+ "\n"
+ "FFmpeg is distributed in the hope that it will be useful,\n"
+ "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
+ "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
+ "Lesser General Public License for more details.\n"
+ "\n"
+ "You should have received a copy of the GNU Lesser General Public\n"
+ "License along with FFmpeg; if not, write to the Free Software\n"
+ "Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n"
+ );
+}
+
+static void handle_child_exit(int sig)
+{
+ pid_t pid;
+ int status;
+
+ while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
+ FFStream *feed;
+
+ for (feed = first_feed; feed; feed = feed->next) {
+ if (feed->pid == pid) {
+ int uptime = time(0) - feed->pid_start;
+
+ feed->pid = 0;
+ fprintf(stderr, "%s: Pid %d exited with status %d after %d seconds\n", feed->filename, pid, status, uptime);
+
+ if (uptime < 30) {
+ /* Turn off any more restarts */
+ feed->child_argv = 0;
+ }
+ }
+ }
+ }
+
+ need_to_start_children = 1;
+}
+
+int main(int argc, char **argv)
+{
+ const char *config_filename;
+ int c;
+ struct sigaction sigact;
+
+ av_register_all();
+
+ config_filename = "/etc/ffserver.conf";
+
+ my_program_name = argv[0];
+ my_program_dir = getcwd(0, 0);
+ ffserver_daemon = 1;
+
+ for(;;) {
+ c = getopt(argc, argv, "ndLh?f:");
+ if (c == -1)
+ break;
+ switch(c) {
+ case 'L':
+ show_license();
+ exit(1);
+ case '?':
+ case 'h':
+ show_help();
+ exit(1);
+ case 'n':
+ no_launch = 1;
+ break;
+ case 'd':
+ ffserver_debug = 1;
+ ffserver_daemon = 0;
+ break;
+ case 'f':
+ config_filename = optarg;
+ break;
+ default:
+ exit(2);
+ }
+ }
+
+ putenv("http_proxy"); /* Kill the http_proxy */
+
+ av_init_random(av_gettime() + (getpid() << 16), &random_state);
+
+ /* address on which the server will handle HTTP connections */
+ my_http_addr.sin_family = AF_INET;
+ my_http_addr.sin_port = htons (8080);
+ my_http_addr.sin_addr.s_addr = htonl (INADDR_ANY);
+
+ /* address on which the server will handle RTSP connections */
+ my_rtsp_addr.sin_family = AF_INET;
+ my_rtsp_addr.sin_port = htons (5454);
+ my_rtsp_addr.sin_addr.s_addr = htonl (INADDR_ANY);
+
+ nb_max_connections = 5;
+ max_bandwidth = 1000;
+ first_stream = NULL;
+ logfilename[0] = '\0';
+
+ memset(&sigact, 0, sizeof(sigact));
+ sigact.sa_handler = handle_child_exit;
+ sigact.sa_flags = SA_NOCLDSTOP | SA_RESTART;
+ sigaction(SIGCHLD, &sigact, 0);
+
+ if (parse_ffconfig(config_filename) < 0) {
+ fprintf(stderr, "Incorrect config file - exiting.\n");
+ exit(1);
+ }
+
+ build_file_streams();
+
+ build_feed_streams();
+
+ compute_bandwidth();
+
+ /* put the process in background and detach it from its TTY */
+ if (ffserver_daemon) {
+ int pid;
+
+ pid = fork();
+ if (pid < 0) {
+ perror("fork");
+ exit(1);
+ } else if (pid > 0) {
+ /* parent : exit */
+ exit(0);
+ } else {
+ /* child */
+ setsid();
+ chdir("/");
+ close(0);
+ open("/dev/null", O_RDWR);
+ if (strcmp(logfilename, "-") != 0) {
+ close(1);
+ dup(0);
+ }
+ close(2);
+ dup(0);
+ }
+ }
+
+ /* signal init */
+ signal(SIGPIPE, SIG_IGN);
+
+ /* open log file if needed */
+ if (logfilename[0] != '\0') {
+ if (!strcmp(logfilename, "-"))
+ logfile = stdout;
+ else
+ logfile = fopen(logfilename, "w");
+ }
+
+ if (http_server() < 0) {
+ fprintf(stderr, "Could not start server\n");
+ exit(1);
+ }
+
+ return 0;
+}
diff --git a/contrib/ffmpeg/ffserver.h b/contrib/ffmpeg/ffserver.h
new file mode 100644
index 000000000..a1b95e84a
--- /dev/null
+++ b/contrib/ffmpeg/ffserver.h
@@ -0,0 +1,28 @@
+/*
+ * Multiple format streaming server
+ * 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
+ */
+#ifndef FFSERVER_H
+#define FFSERVER_H
+
+/* interface between ffserver and modules */
+
+void ffserver_module_init(void);
+
+#endif
diff --git a/contrib/ffmpeg/libavcodec/4xm.c b/contrib/ffmpeg/libavcodec/4xm.c
new file mode 100644
index 000000000..6889dbc4b
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/4xm.c
@@ -0,0 +1,749 @@
+/*
+ * 4XM codec
+ * 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 4xm.c
+ * 4XM codec.
+ */
+
+#include "avcodec.h"
+#include "dsputil.h"
+#include "mpegvideo.h"
+
+//#undef NDEBUG
+//#include <assert.h>
+
+#define BLOCK_TYPE_VLC_BITS 5
+#define ACDC_VLC_BITS 9
+
+#define CFRAME_BUFFER_COUNT 100
+
+static const uint8_t block_type_tab[4][8][2]={
+ { //{8,4,2}x{8,4,2}
+ { 0,1}, { 2,2}, { 6,3}, {14,4}, {30,5}, {31,5}, { 0,0}
+ },{ //{8,4}x1
+ { 0,1}, { 0,0}, { 2,2}, { 6,3}, {14,4}, {15,4}, { 0,0}
+ },{ //1x{8,4}
+ { 0,1}, { 2,2}, { 0,0}, { 6,3}, {14,4}, {15,4}, { 0,0}
+ },{ //1x2, 2x1
+ { 0,1}, { 0,0}, { 0,0}, { 2,2}, { 6,3}, {14,4}, {15,4}
+ }
+};
+
+static const uint8_t size2index[4][4]={
+ {-1, 3, 1, 1},
+ { 3, 0, 0, 0},
+ { 2, 0, 0, 0},
+ { 2, 0, 0, 0},
+};
+
+static const int8_t mv[256][2]={
+{ 0, 0},{ 0, -1},{ -1, 0},{ 1, 0},{ 0, 1},{ -1, -1},{ 1, -1},{ -1, 1},
+{ 1, 1},{ 0, -2},{ -2, 0},{ 2, 0},{ 0, 2},{ -1, -2},{ 1, -2},{ -2, -1},
+{ 2, -1},{ -2, 1},{ 2, 1},{ -1, 2},{ 1, 2},{ -2, -2},{ 2, -2},{ -2, 2},
+{ 2, 2},{ 0, -3},{ -3, 0},{ 3, 0},{ 0, 3},{ -1, -3},{ 1, -3},{ -3, -1},
+{ 3, -1},{ -3, 1},{ 3, 1},{ -1, 3},{ 1, 3},{ -2, -3},{ 2, -3},{ -3, -2},
+{ 3, -2},{ -3, 2},{ 3, 2},{ -2, 3},{ 2, 3},{ 0, -4},{ -4, 0},{ 4, 0},
+{ 0, 4},{ -1, -4},{ 1, -4},{ -4, -1},{ 4, -1},{ 4, 1},{ -1, 4},{ 1, 4},
+{ -3, -3},{ -3, 3},{ 3, 3},{ -2, -4},{ -4, -2},{ 4, -2},{ -4, 2},{ -2, 4},
+{ 2, 4},{ -3, -4},{ 3, -4},{ 4, -3},{ -5, 0},{ -4, 3},{ -3, 4},{ 3, 4},
+{ -1, -5},{ -5, -1},{ -5, 1},{ -1, 5},{ -2, -5},{ 2, -5},{ 5, -2},{ 5, 2},
+{ -4, -4},{ -4, 4},{ -3, -5},{ -5, -3},{ -5, 3},{ 3, 5},{ -6, 0},{ 0, 6},
+{ -6, -1},{ -6, 1},{ 1, 6},{ 2, -6},{ -6, 2},{ 2, 6},{ -5, -4},{ 5, 4},
+{ 4, 5},{ -6, -3},{ 6, 3},{ -7, 0},{ -1, -7},{ 5, -5},{ -7, 1},{ -1, 7},
+{ 4, -6},{ 6, 4},{ -2, -7},{ -7, 2},{ -3, -7},{ 7, -3},{ 3, 7},{ 6, -5},
+{ 0, -8},{ -1, -8},{ -7, -4},{ -8, 1},{ 4, 7},{ 2, -8},{ -2, 8},{ 6, 6},
+{ -8, 3},{ 5, -7},{ -5, 7},{ 8, -4},{ 0, -9},{ -9, -1},{ 1, 9},{ 7, -6},
+{ -7, 6},{ -5, -8},{ -5, 8},{ -9, 3},{ 9, -4},{ 7, -7},{ 8, -6},{ 6, 8},
+{ 10, 1},{-10, 2},{ 9, -5},{ 10, -3},{ -8, -7},{-10, -4},{ 6, -9},{-11, 0},
+{ 11, 1},{-11, -2},{ -2, 11},{ 7, -9},{ -7, 9},{ 10, 6},{ -4, 11},{ 8, -9},
+{ 8, 9},{ 5, 11},{ 7,-10},{ 12, -3},{ 11, 6},{ -9, -9},{ 8, 10},{ 5, 12},
+{-11, 7},{ 13, 2},{ 6,-12},{ 10, 9},{-11, 8},{ -7, 12},{ 0, 14},{ 14, -2},
+{ -9, 11},{ -6, 13},{-14, -4},{ -5,-14},{ 5, 14},{-15, -1},{-14, -6},{ 3,-15},
+{ 11,-11},{ -7, 14},{ -5, 15},{ 8,-14},{ 15, 6},{ 3, 16},{ 7,-15},{-16, 5},
+{ 0, 17},{-16, -6},{-10, 14},{-16, 7},{ 12, 13},{-16, 8},{-17, 6},{-18, 3},
+{ -7, 17},{ 15, 11},{ 16, 10},{ 2,-19},{ 3,-19},{-11,-16},{-18, 8},{-19, -6},
+{ 2,-20},{-17,-11},{-10,-18},{ 8, 19},{-21, -1},{-20, 7},{ -4, 21},{ 21, 5},
+{ 15, 16},{ 2,-22},{-10,-20},{-22, 5},{ 20,-11},{ -7,-22},{-12, 20},{ 23, -5},
+{ 13,-20},{ 24, -2},{-15, 19},{-11, 22},{ 16, 19},{ 23,-10},{-18,-18},{ -9,-24},
+{ 24,-10},{ -3, 26},{-23, 13},{-18,-20},{ 17, 21},{ -4, 27},{ 27, 6},{ 1,-28},
+{-11, 26},{-17,-23},{ 7, 28},{ 11,-27},{ 29, 5},{-23,-19},{-28,-11},{-21, 22},
+{-30, 7},{-17, 26},{-27, 16},{ 13, 29},{ 19,-26},{ 10,-31},{-14,-30},{ 20,-27},
+{-29, 18},{-16,-31},{-28,-22},{ 21,-30},{-25, 28},{ 26,-29},{ 25,-32},{-32,-32}
+};
+
+// this is simply the scaled down elementwise product of the standard jpeg quantizer table and the AAN premul table
+static const uint8_t dequant_table[64]={
+ 16, 15, 13, 19, 24, 31, 28, 17,
+ 17, 23, 25, 31, 36, 63, 45, 21,
+ 18, 24, 27, 37, 52, 59, 49, 20,
+ 16, 28, 34, 40, 60, 80, 51, 20,
+ 18, 31, 48, 66, 68, 86, 56, 21,
+ 19, 38, 56, 59, 64, 64, 48, 20,
+ 27, 48, 55, 55, 56, 51, 35, 15,
+ 20, 35, 34, 32, 31, 22, 15, 8,
+};
+
+static VLC block_type_vlc[4];
+
+
+typedef struct CFrameBuffer{
+ unsigned int allocated_size;
+ unsigned int size;
+ int id;
+ uint8_t *data;
+}CFrameBuffer;
+
+typedef struct FourXContext{
+ AVCodecContext *avctx;
+ DSPContext dsp;
+ AVFrame current_picture, last_picture;
+ GetBitContext pre_gb; ///< ac/dc prefix
+ GetBitContext gb;
+ uint8_t *bytestream;
+ uint16_t *wordstream;
+ int mv[256];
+ VLC pre_vlc;
+ int last_dc;
+ DECLARE_ALIGNED_8(DCTELEM, block[6][64]);
+ uint8_t *bitstream_buffer;
+ unsigned int bitstream_buffer_size;
+ CFrameBuffer cfrm[CFRAME_BUFFER_COUNT];
+} FourXContext;
+
+
+#define FIX_1_082392200 70936
+#define FIX_1_414213562 92682
+#define FIX_1_847759065 121095
+#define FIX_2_613125930 171254
+
+#define MULTIPLY(var,const) (((var)*(const)) >> 16)
+
+static void idct(DCTELEM block[64]){
+ int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
+ int tmp10, tmp11, tmp12, tmp13;
+ int z5, z10, z11, z12, z13;
+ int i;
+ int temp[64];
+
+ for(i=0; i<8; i++){
+ tmp10 = block[8*0 + i] + block[8*4 + i];
+ tmp11 = block[8*0 + i] - block[8*4 + i];
+
+ tmp13 = block[8*2 + i] + block[8*6 + i];
+ tmp12 = MULTIPLY(block[8*2 + i] - block[8*6 + i], FIX_1_414213562) - tmp13;
+
+ tmp0 = tmp10 + tmp13;
+ tmp3 = tmp10 - tmp13;
+ tmp1 = tmp11 + tmp12;
+ tmp2 = tmp11 - tmp12;
+
+ z13 = block[8*5 + i] + block[8*3 + i];
+ z10 = block[8*5 + i] - block[8*3 + i];
+ z11 = block[8*1 + i] + block[8*7 + i];
+ z12 = block[8*1 + i] - block[8*7 + i];
+
+ tmp7 = z11 + z13;
+ tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562);
+
+ z5 = MULTIPLY(z10 + z12, FIX_1_847759065);
+ tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5;
+ tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5;
+
+ tmp6 = tmp12 - tmp7;
+ tmp5 = tmp11 - tmp6;
+ tmp4 = tmp10 + tmp5;
+
+ temp[8*0 + i] = tmp0 + tmp7;
+ temp[8*7 + i] = tmp0 - tmp7;
+ temp[8*1 + i] = tmp1 + tmp6;
+ temp[8*6 + i] = tmp1 - tmp6;
+ temp[8*2 + i] = tmp2 + tmp5;
+ temp[8*5 + i] = tmp2 - tmp5;
+ temp[8*4 + i] = tmp3 + tmp4;
+ temp[8*3 + i] = tmp3 - tmp4;
+ }
+
+ for(i=0; i<8*8; i+=8){
+ tmp10 = temp[0 + i] + temp[4 + i];
+ tmp11 = temp[0 + i] - temp[4 + i];
+
+ tmp13 = temp[2 + i] + temp[6 + i];
+ tmp12 = MULTIPLY(temp[2 + i] - temp[6 + i], FIX_1_414213562) - tmp13;
+
+ tmp0 = tmp10 + tmp13;
+ tmp3 = tmp10 - tmp13;
+ tmp1 = tmp11 + tmp12;
+ tmp2 = tmp11 - tmp12;
+
+ z13 = temp[5 + i] + temp[3 + i];
+ z10 = temp[5 + i] - temp[3 + i];
+ z11 = temp[1 + i] + temp[7 + i];
+ z12 = temp[1 + i] - temp[7 + i];
+
+ tmp7 = z11 + z13;
+ tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562);
+
+ z5 = MULTIPLY(z10 + z12, FIX_1_847759065);
+ tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5;
+ tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5;
+
+ tmp6 = tmp12 - tmp7;
+ tmp5 = tmp11 - tmp6;
+ tmp4 = tmp10 + tmp5;
+
+ block[0 + i] = (tmp0 + tmp7)>>6;
+ block[7 + i] = (tmp0 - tmp7)>>6;
+ block[1 + i] = (tmp1 + tmp6)>>6;
+ block[6 + i] = (tmp1 - tmp6)>>6;
+ block[2 + i] = (tmp2 + tmp5)>>6;
+ block[5 + i] = (tmp2 - tmp5)>>6;
+ block[4 + i] = (tmp3 + tmp4)>>6;
+ block[3 + i] = (tmp3 - tmp4)>>6;
+ }
+}
+
+static void init_vlcs(FourXContext *f){
+ int i;
+
+ for(i=0; i<4; i++){
+ init_vlc(&block_type_vlc[i], BLOCK_TYPE_VLC_BITS, 7,
+ &block_type_tab[i][0][1], 2, 1,
+ &block_type_tab[i][0][0], 2, 1, 1);
+ }
+}
+
+static void init_mv(FourXContext *f){
+ int i;
+
+ for(i=0; i<256; i++){
+ f->mv[i] = mv[i][0] + mv[i][1]*f->current_picture.linesize[0]/2;
+ }
+}
+
+static inline void mcdc(uint16_t *dst, uint16_t *src, int log2w, int h, int stride, int scale, int dc){
+ int i;
+ dc*= 0x10001;
+
+ switch(log2w){
+ case 0:
+ for(i=0; i<h; i++){
+ dst[0] = scale*src[0] + dc;
+ if(scale) src += stride;
+ dst += stride;
+ }
+ break;
+ case 1:
+ for(i=0; i<h; i++){
+ ((uint32_t*)dst)[0] = scale*((uint32_t*)src)[0] + dc;
+ if(scale) src += stride;
+ dst += stride;
+ }
+ break;
+ case 2:
+ for(i=0; i<h; i++){
+ ((uint32_t*)dst)[0] = scale*((uint32_t*)src)[0] + dc;
+ ((uint32_t*)dst)[1] = scale*((uint32_t*)src)[1] + dc;
+ if(scale) src += stride;
+ dst += stride;
+ }
+ break;
+ case 3:
+ for(i=0; i<h; i++){
+ ((uint32_t*)dst)[0] = scale*((uint32_t*)src)[0] + dc;
+ ((uint32_t*)dst)[1] = scale*((uint32_t*)src)[1] + dc;
+ ((uint32_t*)dst)[2] = scale*((uint32_t*)src)[2] + dc;
+ ((uint32_t*)dst)[3] = scale*((uint32_t*)src)[3] + dc;
+ if(scale) src += stride;
+ dst += stride;
+ }
+ break;
+ default: assert(0);
+ }
+}
+
+static void decode_p_block(FourXContext *f, uint16_t *dst, uint16_t *src, int log2w, int log2h, int stride){
+ const int index= size2index[log2h][log2w];
+ const int h= 1<<log2h;
+ int code= get_vlc2(&f->gb, block_type_vlc[index].table, BLOCK_TYPE_VLC_BITS, 1);
+
+ assert(code>=0 && code<=6);
+
+ if(code == 0){
+ src += f->mv[ *f->bytestream++ ];
+ mcdc(dst, src, log2w, h, stride, 1, 0);
+ }else if(code == 1){
+ log2h--;
+ decode_p_block(f, dst , src , log2w, log2h, stride);
+ decode_p_block(f, dst + (stride<<log2h), src + (stride<<log2h), log2w, log2h, stride);
+ }else if(code == 2){
+ log2w--;
+ decode_p_block(f, dst , src , log2w, log2h, stride);
+ decode_p_block(f, dst + (1<<log2w), src + (1<<log2w), log2w, log2h, stride);
+ }else if(code == 4){
+ src += f->mv[ *f->bytestream++ ];
+ mcdc(dst, src, log2w, h, stride, 1, le2me_16(*f->wordstream++));
+ }else if(code == 5){
+ mcdc(dst, src, log2w, h, stride, 0, le2me_16(*f->wordstream++));
+ }else if(code == 6){
+ if(log2w){
+ dst[0] = le2me_16(*f->wordstream++);
+ dst[1] = le2me_16(*f->wordstream++);
+ }else{
+ dst[0 ] = le2me_16(*f->wordstream++);
+ dst[stride] = le2me_16(*f->wordstream++);
+ }
+ }
+}
+
+static int get32(void *p){
+ return le2me_32(*(uint32_t*)p);
+}
+
+static int decode_p_frame(FourXContext *f, uint8_t *buf, int length){
+ int x, y;
+ const int width= f->avctx->width;
+ const int height= f->avctx->height;
+ uint16_t *src= (uint16_t*)f->last_picture.data[0];
+ uint16_t *dst= (uint16_t*)f->current_picture.data[0];
+ const int stride= f->current_picture.linesize[0]>>1;
+ const unsigned int bitstream_size= get32(buf+8);
+ const unsigned int bytestream_size= get32(buf+16);
+ const unsigned int wordstream_size= get32(buf+12);
+
+ if(bitstream_size+ bytestream_size+ wordstream_size + 20 != length
+ || bitstream_size > (1<<26)
+ || bytestream_size > (1<<26)
+ || wordstream_size > (1<<26)
+ ){
+ av_log(f->avctx, AV_LOG_ERROR, "lengths %d %d %d %d\n", bitstream_size, bytestream_size, wordstream_size,
+ bitstream_size+ bytestream_size+ wordstream_size - length);
+ return -1;
+ }
+
+ f->bitstream_buffer= av_fast_realloc(f->bitstream_buffer, &f->bitstream_buffer_size, bitstream_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ f->dsp.bswap_buf((uint32_t*)f->bitstream_buffer, (uint32_t*)(buf + 20), bitstream_size/4);
+ init_get_bits(&f->gb, f->bitstream_buffer, 8*bitstream_size);
+
+ f->wordstream= (uint16_t*)(buf + 20 + bitstream_size);
+ f->bytestream= buf + 20 + bitstream_size + wordstream_size;
+
+ init_mv(f);
+
+ for(y=0; y<height; y+=8){
+ for(x=0; x<width; x+=8){
+ decode_p_block(f, dst + x, src + x, 3, 3, stride);
+ }
+ src += 8*stride;
+ dst += 8*stride;
+ }
+
+ if(bitstream_size != (get_bits_count(&f->gb)+31)/32*4)
+ av_log(f->avctx, AV_LOG_ERROR, " %d %td %td bytes left\n",
+ bitstream_size - (get_bits_count(&f->gb)+31)/32*4,
+ bytestream_size - (f->bytestream - (buf + 20 + bitstream_size + wordstream_size)),
+ wordstream_size - (((uint8_t*)f->wordstream) - (buf + 20 + bitstream_size))
+ );
+
+ return 0;
+}
+
+/**
+ * decode block and dequantize.
+ * Note this is allmost identical to mjpeg
+ */
+static int decode_i_block(FourXContext *f, DCTELEM *block){
+ int code, i, j, level, val;
+
+ /* DC coef */
+ val = get_vlc2(&f->pre_gb, f->pre_vlc.table, ACDC_VLC_BITS, 3);
+ if (val>>4){
+ av_log(f->avctx, AV_LOG_ERROR, "error dc run != 0\n");
+ }
+
+ if(val)
+ val = get_xbits(&f->gb, val);
+
+ val = val * dequant_table[0] + f->last_dc;
+ f->last_dc =
+ block[0] = val;
+ /* AC coefs */
+ i = 1;
+ for(;;) {
+ code = get_vlc2(&f->pre_gb, f->pre_vlc.table, ACDC_VLC_BITS, 3);
+
+ /* EOB */
+ if (code == 0)
+ break;
+ if (code == 0xf0) {
+ i += 16;
+ } else {
+ level = get_xbits(&f->gb, code & 0xf);
+ i += code >> 4;
+ if (i >= 64) {
+ av_log(f->avctx, AV_LOG_ERROR, "run %d oveflow\n", i);
+ return 0;
+ }
+
+ j= ff_zigzag_direct[i];
+ block[j] = level * dequant_table[j];
+ i++;
+ if (i >= 64)
+ break;
+ }
+ }
+
+ return 0;
+}
+
+static inline void idct_put(FourXContext *f, int x, int y){
+ DCTELEM (*block)[64]= f->block;
+ int stride= f->current_picture.linesize[0]>>1;
+ int i;
+ uint16_t *dst = ((uint16_t*)f->current_picture.data[0]) + y * stride + x;
+
+ for(i=0; i<4; i++){
+ block[i][0] += 0x80*8*8;
+ idct(block[i]);
+ }
+
+ if(!(f->avctx->flags&CODEC_FLAG_GRAY)){
+ for(i=4; i<6; i++) idct(block[i]);
+ }
+
+/* Note transform is:
+y= ( 1b + 4g + 2r)/14
+cb=( 3b - 2g - 1r)/14
+cr=(-1b - 4g + 5r)/14
+*/
+ for(y=0; y<8; y++){
+ for(x=0; x<8; x++){
+ DCTELEM *temp= block[(x>>2) + 2*(y>>2)] + 2*(x&3) + 2*8*(y&3); //FIXME optimize
+ int cb= block[4][x + 8*y];
+ int cr= block[5][x + 8*y];
+ int cg= (cb + cr)>>1;
+ int y;
+
+ cb+=cb;
+
+ y = temp[0];
+ dst[0 ]= ((y+cb)>>3) + (((y-cg)&0xFC)<<3) + (((y+cr)&0xF8)<<8);
+ y = temp[1];
+ dst[1 ]= ((y+cb)>>3) + (((y-cg)&0xFC)<<3) + (((y+cr)&0xF8)<<8);
+ y = temp[8];
+ dst[ stride]= ((y+cb)>>3) + (((y-cg)&0xFC)<<3) + (((y+cr)&0xF8)<<8);
+ y = temp[9];
+ dst[1+stride]= ((y+cb)>>3) + (((y-cg)&0xFC)<<3) + (((y+cr)&0xF8)<<8);
+ dst += 2;
+ }
+ dst += 2*stride - 2*8;
+ }
+}
+
+static int decode_i_mb(FourXContext *f){
+ int i;
+
+ f->dsp.clear_blocks(f->block[0]);
+
+ for(i=0; i<6; i++){
+ if(decode_i_block(f, f->block[i]) < 0)
+ return -1;
+ }
+
+ return 0;
+}
+
+static uint8_t *read_huffman_tables(FourXContext *f, uint8_t * const buf){
+ int frequency[512];
+ uint8_t flag[512];
+ int up[512];
+ uint8_t len_tab[257];
+ int bits_tab[257];
+ int start, end;
+ uint8_t *ptr= buf;
+ int j;
+
+ memset(frequency, 0, sizeof(frequency));
+ memset(up, -1, sizeof(up));
+
+ start= *ptr++;
+ end= *ptr++;
+ for(;;){
+ int i;
+
+ for(i=start; i<=end; i++){
+ frequency[i]= *ptr++;
+ }
+ start= *ptr++;
+ if(start==0) break;
+
+ end= *ptr++;
+ }
+ frequency[256]=1;
+
+ while((ptr - buf)&3) ptr++; // 4byte align
+
+ for(j=257; j<512; j++){
+ int min_freq[2]= {256*256, 256*256};
+ int smallest[2]= {0, 0};
+ int i;
+ for(i=0; i<j; i++){
+ if(frequency[i] == 0) continue;
+ if(frequency[i] < min_freq[1]){
+ if(frequency[i] < min_freq[0]){
+ min_freq[1]= min_freq[0]; smallest[1]= smallest[0];
+ min_freq[0]= frequency[i];smallest[0]= i;
+ }else{
+ min_freq[1]= frequency[i];smallest[1]= i;
+ }
+ }
+ }
+ if(min_freq[1] == 256*256) break;
+
+ frequency[j]= min_freq[0] + min_freq[1];
+ flag[ smallest[0] ]= 0;
+ flag[ smallest[1] ]= 1;
+ up[ smallest[0] ]=
+ up[ smallest[1] ]= j;
+ frequency[ smallest[0] ]= frequency[ smallest[1] ]= 0;
+ }
+
+ for(j=0; j<257; j++){
+ int node;
+ int len=0;
+ int bits=0;
+
+ for(node= j; up[node] != -1; node= up[node]){
+ bits += flag[node]<<len;
+ len++;
+ if(len > 31) av_log(f->avctx, AV_LOG_ERROR, "vlc length overflow\n"); //can this happen at all ?
+ }
+
+ bits_tab[j]= bits;
+ len_tab[j]= len;
+ }
+
+ init_vlc(&f->pre_vlc, ACDC_VLC_BITS, 257,
+ len_tab , 1, 1,
+ bits_tab, 4, 4, 0);
+
+ return ptr;
+}
+
+static int decode_i_frame(FourXContext *f, uint8_t *buf, int length){
+ int x, y;
+ const int width= f->avctx->width;
+ const int height= f->avctx->height;
+ uint16_t *dst= (uint16_t*)f->current_picture.data[0];
+ const int stride= f->current_picture.linesize[0]>>1;
+ const unsigned int bitstream_size= get32(buf);
+ const int token_count __attribute__((unused)) = get32(buf + bitstream_size + 8);
+ unsigned int prestream_size= 4*get32(buf + bitstream_size + 4);
+ uint8_t *prestream= buf + bitstream_size + 12;
+
+ if(prestream_size + bitstream_size + 12 != length
+ || bitstream_size > (1<<26)
+ || prestream_size > (1<<26)){
+ av_log(f->avctx, AV_LOG_ERROR, "size mismatch %d %d %d\n", prestream_size, bitstream_size, length);
+ return -1;
+ }
+
+ prestream= read_huffman_tables(f, prestream);
+
+ init_get_bits(&f->gb, buf + 4, 8*bitstream_size);
+
+ prestream_size= length + buf - prestream;
+
+ f->bitstream_buffer= av_fast_realloc(f->bitstream_buffer, &f->bitstream_buffer_size, prestream_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ f->dsp.bswap_buf((uint32_t*)f->bitstream_buffer, (uint32_t*)prestream, prestream_size/4);
+ init_get_bits(&f->pre_gb, f->bitstream_buffer, 8*prestream_size);
+
+ f->last_dc= 0*128*8*8;
+
+ for(y=0; y<height; y+=16){
+ for(x=0; x<width; x+=16){
+ if(decode_i_mb(f) < 0)
+ return -1;
+
+ idct_put(f, x, y);
+ }
+ dst += 16*stride;
+ }
+
+ if(get_vlc2(&f->pre_gb, f->pre_vlc.table, ACDC_VLC_BITS, 3) != 256)
+ av_log(f->avctx, AV_LOG_ERROR, "end mismatch\n");
+
+ return 0;
+}
+
+static int decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ FourXContext * const f = avctx->priv_data;
+ AVFrame *picture = data;
+ AVFrame *p, temp;
+ int i, frame_4cc, frame_size;
+
+ frame_4cc= get32(buf);
+ if(buf_size != get32(buf+4)+8 || buf_size < 20){
+ av_log(f->avctx, AV_LOG_ERROR, "size mismatch %d %d\n", buf_size, get32(buf+4));
+ }
+
+ if(frame_4cc == ff_get_fourcc("cfrm")){
+ int free_index=-1;
+ const int data_size= buf_size - 20;
+ const int id= get32(buf+12);
+ const int whole_size= get32(buf+16);
+ CFrameBuffer *cfrm;
+
+ for(i=0; i<CFRAME_BUFFER_COUNT; i++){
+ if(f->cfrm[i].id && f->cfrm[i].id < avctx->frame_number)
+ av_log(f->avctx, AV_LOG_ERROR, "lost c frame %d\n", f->cfrm[i].id);
+ }
+
+ for(i=0; i<CFRAME_BUFFER_COUNT; i++){
+ if(f->cfrm[i].id == id) break;
+ if(f->cfrm[i].size == 0 ) free_index= i;
+ }
+
+ if(i>=CFRAME_BUFFER_COUNT){
+ i= free_index;
+ f->cfrm[i].id= id;
+ }
+ cfrm= &f->cfrm[i];
+
+ cfrm->data= av_fast_realloc(cfrm->data, &cfrm->allocated_size, cfrm->size + data_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ if(!cfrm->data){ //explicit check needed as memcpy below might not catch a NULL
+ av_log(f->avctx, AV_LOG_ERROR, "realloc falure");
+ return -1;
+ }
+
+ memcpy(cfrm->data + cfrm->size, buf+20, data_size);
+ cfrm->size += data_size;
+
+ if(cfrm->size >= whole_size){
+ buf= cfrm->data;
+ frame_size= cfrm->size;
+
+ if(id != avctx->frame_number){
+ av_log(f->avctx, AV_LOG_ERROR, "cframe id mismatch %d %d\n", id, avctx->frame_number);
+ }
+
+ cfrm->size= cfrm->id= 0;
+ frame_4cc= ff_get_fourcc("pfrm");
+ }else
+ return buf_size;
+ }else{
+ buf= buf + 12;
+ frame_size= buf_size - 12;
+ }
+
+ temp= f->current_picture;
+ f->current_picture= f->last_picture;
+ f->last_picture= temp;
+
+ p= &f->current_picture;
+ avctx->coded_frame= p;
+
+ avctx->flags |= CODEC_FLAG_EMU_EDGE; // alternatively we would have to use our own buffer management
+
+ if(p->data[0])
+ avctx->release_buffer(avctx, p);
+
+ p->reference= 1;
+ if(avctx->get_buffer(avctx, p) < 0){
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ return -1;
+ }
+
+ if(frame_4cc == ff_get_fourcc("ifrm")){
+ p->pict_type= I_TYPE;
+ if(decode_i_frame(f, buf, frame_size) < 0)
+ return -1;
+ }else if(frame_4cc == ff_get_fourcc("pfrm")){
+ p->pict_type= P_TYPE;
+ if(decode_p_frame(f, buf, frame_size) < 0)
+ return -1;
+ }else if(frame_4cc == ff_get_fourcc("snd_")){
+ av_log(avctx, AV_LOG_ERROR, "ignoring snd_ chunk length:%d\n", buf_size);
+ }else{
+ av_log(avctx, AV_LOG_ERROR, "ignoring unknown chunk length:%d\n", buf_size);
+ }
+
+ p->key_frame= p->pict_type == I_TYPE;
+
+ *picture= *p;
+ *data_size = sizeof(AVPicture);
+
+ emms_c();
+
+ return buf_size;
+}
+
+
+static void common_init(AVCodecContext *avctx){
+ FourXContext * const f = avctx->priv_data;
+
+ dsputil_init(&f->dsp, avctx);
+
+ f->avctx= avctx;
+}
+
+static int decode_init(AVCodecContext *avctx){
+ FourXContext * const f = avctx->priv_data;
+
+ common_init(avctx);
+ init_vlcs(f);
+
+ avctx->pix_fmt= PIX_FMT_RGB565;
+
+ return 0;
+}
+
+
+static int decode_end(AVCodecContext *avctx){
+ FourXContext * const f = avctx->priv_data;
+ int i;
+
+ av_freep(&f->bitstream_buffer);
+ f->bitstream_buffer_size=0;
+ for(i=0; i<CFRAME_BUFFER_COUNT; i++){
+ av_freep(&f->cfrm[i].data);
+ f->cfrm[i].allocated_size= 0;
+ }
+ free_vlc(&f->pre_vlc);
+
+ return 0;
+}
+
+AVCodec fourxm_decoder = {
+ "4xm",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_4XM,
+ sizeof(FourXContext),
+ decode_init,
+ NULL,
+ decode_end,
+ decode_frame,
+ /*CODEC_CAP_DR1,*/
+};
+
diff --git a/contrib/ffmpeg/libavcodec/8bps.c b/contrib/ffmpeg/libavcodec/8bps.c
new file mode 100644
index 000000000..3d4eb05b3
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/8bps.c
@@ -0,0 +1,236 @@
+/*
+ * Quicktime Planar RGB (8BPS) Video Decoder
+ * Copyright (C) 2003 Roberto Togni
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 8bps.c
+ * QT 8BPS Video Decoder by Roberto Togni <rtogni at bresciaonline dot it>
+ * For more information about the 8BPS format, visit:
+ * http://www.pcisys.net/~melanson/codecs/
+ *
+ * Supports: PAL8 (RGB 8bpp, paletted)
+ * : BGR24 (RGB 24bpp) (can also output it as RGB32)
+ * : RGB32 (RGB 32bpp, 4th plane is probably alpha and it's ignored)
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "common.h"
+#include "avcodec.h"
+
+
+static const enum PixelFormat pixfmt_rgb24[] = {PIX_FMT_BGR24, PIX_FMT_RGB32, -1};
+
+/*
+ * Decoder context
+ */
+typedef struct EightBpsContext {
+
+ AVCodecContext *avctx;
+ AVFrame pic;
+
+ unsigned char planes;
+ unsigned char planemap[4];
+} EightBpsContext;
+
+
+/*
+ *
+ * Decode a frame
+ *
+ */
+static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size)
+{
+ EightBpsContext * const c = (EightBpsContext *)avctx->priv_data;
+ unsigned char *encoded = (unsigned char *)buf;
+ unsigned char *pixptr, *pixptr_end;
+ unsigned int height = avctx->height; // Real image height
+ unsigned int dlen, p, row;
+ unsigned char *lp, *dp;
+ unsigned char count;
+ unsigned int px_inc;
+ unsigned int planes = c->planes;
+ unsigned char *planemap = c->planemap;
+
+ if(c->pic.data[0])
+ avctx->release_buffer(avctx, &c->pic);
+
+ c->pic.reference = 0;
+ c->pic.buffer_hints = FF_BUFFER_HINTS_VALID;
+ if(avctx->get_buffer(avctx, &c->pic) < 0){
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ return -1;
+ }
+
+ /* Set data pointer after line lengths */
+ dp = encoded + planes * (height << 1);
+
+ /* Ignore alpha plane, don't know what to do with it */
+ if (planes == 4)
+ planes--;
+
+ px_inc = planes + (avctx->pix_fmt == PIX_FMT_RGB32);
+
+ for (p = 0; p < planes; p++) {
+ /* Lines length pointer for this plane */
+ lp = encoded + p * (height << 1);
+
+ /* Decode a plane */
+ for(row = 0; row < height; row++) {
+ pixptr = c->pic.data[0] + row * c->pic.linesize[0] + planemap[p];
+ pixptr_end = pixptr + c->pic.linesize[0];
+ dlen = be2me_16(*(unsigned short *)(lp+row*2));
+ /* Decode a row of this plane */
+ while(dlen > 0) {
+ if(dp + 1 >= buf+buf_size) return -1;
+ if ((count = *dp++) <= 127) {
+ count++;
+ dlen -= count + 1;
+ if (pixptr + count * px_inc > pixptr_end)
+ break;
+ if(dp + count > buf+buf_size) return -1;
+ while(count--) {
+ *pixptr = *dp++;
+ pixptr += px_inc;
+ }
+ } else {
+ count = 257 - count;
+ if (pixptr + count * px_inc > pixptr_end)
+ break;
+ while(count--) {
+ *pixptr = *dp;
+ pixptr += px_inc;
+ }
+ dp++;
+ dlen -= 2;
+ }
+ }
+ }
+ }
+
+ if (avctx->palctrl) {
+ memcpy (c->pic.data[1], avctx->palctrl->palette, AVPALETTE_SIZE);
+ if (avctx->palctrl->palette_changed) {
+ c->pic.palette_has_changed = 1;
+ avctx->palctrl->palette_changed = 0;
+ } else
+ c->pic.palette_has_changed = 0;
+ }
+
+ *data_size = sizeof(AVFrame);
+ *(AVFrame*)data = c->pic;
+
+ /* always report that the buffer was completely consumed */
+ return buf_size;
+}
+
+
+/*
+ *
+ * Init 8BPS decoder
+ *
+ */
+static int decode_init(AVCodecContext *avctx)
+{
+ EightBpsContext * const c = (EightBpsContext *)avctx->priv_data;
+
+ c->avctx = avctx;
+ avctx->has_b_frames = 0;
+
+ c->pic.data[0] = NULL;
+
+ if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) {
+ return 1;
+ }
+
+ switch (avctx->bits_per_sample) {
+ case 8:
+ avctx->pix_fmt = PIX_FMT_PAL8;
+ c->planes = 1;
+ c->planemap[0] = 0; // 1st plane is palette indexes
+ if (avctx->palctrl == NULL) {
+ av_log(avctx, AV_LOG_ERROR, "Error: PAL8 format but no palette from demuxer.\n");
+ return -1;
+ }
+ break;
+ case 24:
+ avctx->pix_fmt = avctx->get_format(avctx, pixfmt_rgb24);
+ c->planes = 3;
+ c->planemap[0] = 2; // 1st plane is red
+ c->planemap[1] = 1; // 2nd plane is green
+ c->planemap[2] = 0; // 3rd plane is blue
+ break;
+ case 32:
+ avctx->pix_fmt = PIX_FMT_RGB32;
+ c->planes = 4;
+#ifdef WORDS_BIGENDIAN
+ c->planemap[0] = 1; // 1st plane is red
+ c->planemap[1] = 2; // 2nd plane is green
+ c->planemap[2] = 3; // 3rd plane is blue
+ c->planemap[3] = 0; // 4th plane is alpha???
+#else
+ c->planemap[0] = 2; // 1st plane is red
+ c->planemap[1] = 1; // 2nd plane is green
+ c->planemap[2] = 0; // 3rd plane is blue
+ c->planemap[3] = 3; // 4th plane is alpha???
+#endif
+ break;
+ default:
+ av_log(avctx, AV_LOG_ERROR, "Error: Unsupported color depth: %u.\n", avctx->bits_per_sample);
+ return -1;
+ }
+
+ return 0;
+}
+
+
+
+
+/*
+ *
+ * Uninit 8BPS decoder
+ *
+ */
+static int decode_end(AVCodecContext *avctx)
+{
+ EightBpsContext * const c = (EightBpsContext *)avctx->priv_data;
+
+ if (c->pic.data[0])
+ avctx->release_buffer(avctx, &c->pic);
+
+ return 0;
+}
+
+
+
+AVCodec eightbps_decoder = {
+ "8bps",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_8BPS,
+ sizeof(EightBpsContext),
+ decode_init,
+ NULL,
+ decode_end,
+ decode_frame,
+ CODEC_CAP_DR1,
+};
diff --git a/contrib/ffmpeg/libavcodec/Makefile b/contrib/ffmpeg/libavcodec/Makefile
new file mode 100644
index 000000000..9ec6b96f1
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/Makefile
@@ -0,0 +1,448 @@
+#
+# libavcodec Makefile
+# (c) 2000-2005 Fabrice Bellard
+#
+include ../config.mak
+
+CFLAGS+=-I$(SRC_PATH)/libswscale $(AMR_CFLAGS)
+
+OBJS= bitstream.o \
+ utils.o \
+ allcodecs.o \
+ mpegvideo.o \
+ jrevdct.o \
+ jfdctfst.o \
+ jfdctint.o\
+ mjpeg.o \
+ resample.o \
+ resample2.o \
+ dsputil.o \
+ motion_est.o \
+ imgconvert.o \
+ mpeg12.o \
+ mpegaudiodec.o \
+ simple_idct.o \
+ ratecontrol.o \
+ eval.o \
+ error_resilience.o \
+ fft.o \
+ mdct.o \
+ raw.o \
+ golomb.o \
+ cabac.o\
+ faandct.o \
+ parser.o \
+ vp3dsp.o \
+ h264idct.o \
+ rangecoder.o \
+ pnm.o \
+ h263.o \
+ msmpeg4.o \
+ h263dec.o \
+ opt.o \
+ bitstream_filter.o \
+ audioconvert.o \
+
+
+HEADERS = avcodec.h opt.h
+
+OBJS-$(CONFIG_AASC_DECODER) += aasc.o
+OBJS-$(CONFIG_AC3_ENCODER) += ac3enc.o ac3.o
+OBJS-$(CONFIG_ALAC_DECODER) += alac.o
+OBJS-$(CONFIG_ASV1_DECODER) += asv1.o
+OBJS-$(CONFIG_ASV1_ENCODER) += asv1.o
+OBJS-$(CONFIG_ASV2_DECODER) += asv1.o
+OBJS-$(CONFIG_ASV2_ENCODER) += asv1.o
+OBJS-$(CONFIG_AVS_DECODER) += avs.o
+OBJS-$(CONFIG_BMP_DECODER) += bmp.o
+OBJS-$(CONFIG_BMP_ENCODER) += bmpenc.o
+OBJS-$(CONFIG_CAVS_DECODER) += cavs.o cavsdsp.o
+OBJS-$(CONFIG_CINEPAK_DECODER) += cinepak.o
+OBJS-$(CONFIG_CLJR_DECODER) += cljr.o
+OBJS-$(CONFIG_CLJR_ENCODER) += cljr.o
+OBJS-$(CONFIG_COOK_DECODER) += cook.o
+OBJS-$(CONFIG_CSCD_DECODER) += cscd.o
+OBJS-$(CONFIG_CYUV_DECODER) += cyuv.o
+OBJS-$(CONFIG_DCA_DECODER) += dca.o
+OBJS-$(CONFIG_DNXHD_DECODER) += dnxhddec.o
+OBJS-$(CONFIG_DSICINVIDEO_DECODER) += dsicinav.o
+OBJS-$(CONFIG_DSICINAUDIO_DECODER) += dsicinav.o
+OBJS-$(CONFIG_DVBSUB_DECODER) += dvbsubdec.o
+OBJS-$(CONFIG_DVBSUB_ENCODER) += dvbsub.o
+OBJS-$(CONFIG_DVDSUB_DECODER) += dvdsubdec.o
+OBJS-$(CONFIG_DVDSUB_ENCODER) += dvdsubenc.o
+OBJS-$(CONFIG_DVVIDEO_DECODER) += dv.o
+OBJS-$(CONFIG_DVVIDEO_ENCODER) += dv.o
+OBJS-$(CONFIG_DXA_DECODER) += dxa.o
+OBJS-$(CONFIG_EIGHTBPS_DECODER) += 8bps.o
+OBJS-$(CONFIG_FFV1_DECODER) += ffv1.o
+OBJS-$(CONFIG_FFV1_ENCODER) += ffv1.o
+OBJS-$(CONFIG_FFVHUFF_DECODER) += huffyuv.o
+OBJS-$(CONFIG_FFVHUFF_ENCODER) += huffyuv.o
+OBJS-$(CONFIG_FLAC_DECODER) += flac.o
+OBJS-$(CONFIG_FLAC_ENCODER) += flacenc.o
+OBJS-$(CONFIG_FLASHSV_DECODER) += flashsv.o
+OBJS-$(CONFIG_FLASHSV_ENCODER) += flashsvenc.o
+OBJS-$(CONFIG_FLIC_DECODER) += flicvideo.o
+OBJS-$(CONFIG_FOURXM_DECODER) += 4xm.o
+OBJS-$(CONFIG_FRAPS_DECODER) += fraps.o
+OBJS-$(CONFIG_GIF_DECODER) += gifdec.o lzw.o
+OBJS-$(CONFIG_GIF_ENCODER) += gif.o
+OBJS-$(CONFIG_H261_DECODER) += h261.o
+OBJS-$(CONFIG_H261_ENCODER) += h261.o
+OBJS-$(CONFIG_H264_DECODER) += h264.o
+OBJS-$(CONFIG_H264_ENCODER) += h264enc.o h264dsp.o
+OBJS-$(CONFIG_HUFFYUV_DECODER) += huffyuv.o
+OBJS-$(CONFIG_HUFFYUV_ENCODER) += huffyuv.o
+OBJS-$(CONFIG_IDCIN_DECODER) += idcinvideo.o
+OBJS-$(CONFIG_IMC_DECODER) += imc.o
+OBJS-$(CONFIG_INDEO2_DECODER) += indeo2.o
+OBJS-$(CONFIG_INDEO3_DECODER) += indeo3.o
+OBJS-$(CONFIG_INTERPLAY_VIDEO_DECODER) += interplayvideo.o
+OBJS-$(CONFIG_INTERPLAY_DPCM_DECODER) += dpcm.o
+OBJS-$(CONFIG_KMVC_DECODER) += kmvc.o
+OBJS-$(CONFIG_LOCO_DECODER) += loco.o
+OBJS-$(CONFIG_MACE3_DECODER) += mace.o
+OBJS-$(CONFIG_MACE6_DECODER) += mace.o
+OBJS-$(CONFIG_MMVIDEO_DECODER) += mmvideo.o
+OBJS-$(CONFIG_MP2_ENCODER) += mpegaudio.o
+OBJS-$(CONFIG_MPC7_DECODER) += mpc.o
+OBJS-$(CONFIG_MSRLE_DECODER) += msrle.o
+OBJS-$(CONFIG_MSVIDEO1_DECODER) += msvideo1.o
+OBJS-$(CONFIG_MSZH_DECODER) += lcl.o
+OBJS-$(CONFIG_NUV_DECODER) += nuv.o rtjpeg.o
+OBJS-$(CONFIG_PNG_DECODER) += png.o
+OBJS-$(CONFIG_PNG_ENCODER) += png.o
+OBJS-$(CONFIG_QDM2_DECODER) += qdm2.o
+OBJS-$(CONFIG_QDRAW_DECODER) += qdrw.o
+OBJS-$(CONFIG_QPEG_DECODER) += qpeg.o
+OBJS-$(CONFIG_QTRLE_DECODER) += qtrle.o
+OBJS-$(CONFIG_RA_144_DECODER) += ra144.o
+OBJS-$(CONFIG_RA_288_DECODER) += ra288.o
+OBJS-$(CONFIG_ROQ_DECODER) += roqvideo.o
+OBJS-$(CONFIG_ROQ_DPCM_DECODER) += dpcm.o
+OBJS-$(CONFIG_RPZA_DECODER) += rpza.o
+OBJS-$(CONFIG_RV10_DECODER) += rv10.o
+OBJS-$(CONFIG_RV10_ENCODER) += rv10.o
+OBJS-$(CONFIG_RV20_DECODER) += rv10.o
+OBJS-$(CONFIG_RV20_ENCODER) += rv10.o
+OBJS-$(CONFIG_SHORTEN_DECODER) += shorten.o
+OBJS-$(CONFIG_SMACKAUD_DECODER) += smacker.o
+OBJS-$(CONFIG_SMACKER_DECODER) += smacker.o
+OBJS-$(CONFIG_SMC_DECODER) += smc.o
+OBJS-$(CONFIG_SNOW_DECODER) += snow.o
+OBJS-$(CONFIG_SNOW_ENCODER) += snow.o
+OBJS-$(CONFIG_SOL_DPCM_DECODER) += dpcm.o
+OBJS-$(CONFIG_SONIC_DECODER) += sonic.o
+OBJS-$(CONFIG_SONIC_ENCODER) += sonic.o
+OBJS-$(CONFIG_SONIC_LS_DECODER) += sonic.o
+OBJS-$(CONFIG_SVQ1_DECODER) += svq1.o
+OBJS-$(CONFIG_SVQ1_ENCODER) += svq1.o
+OBJS-$(CONFIG_SVQ3_DECODER) += h264.o
+OBJS-$(CONFIG_TARGA_DECODER) += targa.o
+OBJS-$(CONFIG_TARGA_ENCODER) += targaenc.o
+OBJS-$(CONFIG_THEORA_DECODER) += vp3.o xiph.o
+OBJS-$(CONFIG_TIERTEXSEQVIDEO_DECODER) += tiertexseqv.o
+OBJS-$(CONFIG_TIFF_DECODER) += tiff.o lzw.o
+OBJS-$(CONFIG_TRUEMOTION1_DECODER) += truemotion1.o
+OBJS-$(CONFIG_TRUEMOTION2_DECODER) += truemotion2.o
+OBJS-$(CONFIG_TRUESPEECH_DECODER) += truespeech.o
+OBJS-$(CONFIG_TSCC_DECODER) += tscc.o
+OBJS-$(CONFIG_TTA_DECODER) += tta.o
+OBJS-$(CONFIG_ULTI_DECODER) += ulti.o
+OBJS-$(CONFIG_VC1_DECODER) += vc1.o vc1dsp.o
+OBJS-$(CONFIG_VCR1_DECODER) += vcr1.o
+OBJS-$(CONFIG_VCR1_ENCODER) += vcr1.o
+OBJS-$(CONFIG_VMDAUDIO_DECODER) += vmdav.o
+OBJS-$(CONFIG_VMDVIDEO_DECODER) += vmdav.o
+OBJS-$(CONFIG_VMNC_DECODER) += vmnc.o
+OBJS-$(CONFIG_VORBIS_DECODER) += vorbis.o vorbis_data.o xiph.o
+OBJS-$(CONFIG_VORBIS_ENCODER) += vorbis_enc.o vorbis.o vorbis_data.o
+OBJS-$(CONFIG_VP3_DECODER) += vp3.o
+OBJS-$(CONFIG_VP5_DECODER) += vp5.o vp56.o vp56data.o
+OBJS-$(CONFIG_VP6_DECODER) += vp6.o vp56.o vp56data.o
+OBJS-$(CONFIG_VQA_DECODER) += vqavideo.o
+OBJS-$(CONFIG_WAVPACK_DECODER) += wavpack.o
+OBJS-$(CONFIG_WMAV1_DECODER) += wmadec.o wma.o
+OBJS-$(CONFIG_WMAV2_DECODER) += wmadec.o wma.o
+OBJS-$(CONFIG_WMAV1_ENCODER) += wmaenc.o wma.o
+OBJS-$(CONFIG_WMAV2_ENCODER) += wmaenc.o wma.o
+OBJS-$(CONFIG_WMV3_DECODER) += vc1.o vc1dsp.o
+OBJS-$(CONFIG_WNV1_DECODER) += wnv1.o
+OBJS-$(CONFIG_WS_SND1_DECODER) += ws-snd1.o
+OBJS-$(CONFIG_XAN_DPCM_DECODER) += dpcm.o
+OBJS-$(CONFIG_XAN_WC3_DECODER) += xan.o
+OBJS-$(CONFIG_XAN_WC4_DECODER) += xan.o
+OBJS-$(CONFIG_XL_DECODER) += xl.o
+OBJS-$(CONFIG_ZLIB_DECODER) += lcl.o
+OBJS-$(CONFIG_ZLIB_ENCODER) += lcl.o
+OBJS-$(CONFIG_ZMBV_DECODER) += zmbv.o
+OBJS-$(CONFIG_ZMBV_ENCODER) += zmbvenc.o
+
+OBJS-$(CONFIG_PCM_S32LE_DECODER) += pcm.o
+OBJS-$(CONFIG_PCM_S32LE_ENCODER) += pcm.o
+OBJS-$(CONFIG_PCM_S32BE_DECODER) += pcm.o
+OBJS-$(CONFIG_PCM_S32BE_ENCODER) += pcm.o
+OBJS-$(CONFIG_PCM_U32LE_DECODER) += pcm.o
+OBJS-$(CONFIG_PCM_U32LE_ENCODER) += pcm.o
+OBJS-$(CONFIG_PCM_U32BE_DECODER) += pcm.o
+OBJS-$(CONFIG_PCM_U32BE_ENCODER) += pcm.o
+OBJS-$(CONFIG_PCM_S24LE_DECODER) += pcm.o
+OBJS-$(CONFIG_PCM_S24LE_ENCODER) += pcm.o
+OBJS-$(CONFIG_PCM_S24BE_DECODER) += pcm.o
+OBJS-$(CONFIG_PCM_S24BE_ENCODER) += pcm.o
+OBJS-$(CONFIG_PCM_U24LE_DECODER) += pcm.o
+OBJS-$(CONFIG_PCM_U24LE_ENCODER) += pcm.o
+OBJS-$(CONFIG_PCM_U24BE_DECODER) += pcm.o
+OBJS-$(CONFIG_PCM_U24BE_ENCODER) += pcm.o
+OBJS-$(CONFIG_PCM_S24DAUD_DECODER) += pcm.o
+OBJS-$(CONFIG_PCM_S24DAUD_ENCODER) += pcm.o
+OBJS-$(CONFIG_PCM_S16LE_DECODER) += pcm.o
+OBJS-$(CONFIG_PCM_S16LE_ENCODER) += pcm.o
+OBJS-$(CONFIG_PCM_S16BE_DECODER) += pcm.o
+OBJS-$(CONFIG_PCM_S16BE_ENCODER) += pcm.o
+OBJS-$(CONFIG_PCM_U16LE_DECODER) += pcm.o
+OBJS-$(CONFIG_PCM_U16LE_ENCODER) += pcm.o
+OBJS-$(CONFIG_PCM_U16BE_DECODER) += pcm.o
+OBJS-$(CONFIG_PCM_U16BE_ENCODER) += pcm.o
+OBJS-$(CONFIG_PCM_S8_DECODER) += pcm.o
+OBJS-$(CONFIG_PCM_S8_ENCODER) += pcm.o
+OBJS-$(CONFIG_PCM_U8_DECODER) += pcm.o
+OBJS-$(CONFIG_PCM_U8_ENCODER) += pcm.o
+OBJS-$(CONFIG_PCM_ALAW_DECODER) += pcm.o
+OBJS-$(CONFIG_PCM_ALAW_ENCODER) += pcm.o
+OBJS-$(CONFIG_PCM_MULAW_DECODER) += pcm.o
+OBJS-$(CONFIG_PCM_MULAW_ENCODER) += pcm.o
+
+OBJS-$(CONFIG_ADPCM_4XM_DECODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_4XM_ENCODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_ADX_DECODER) += adx.o
+OBJS-$(CONFIG_ADPCM_ADX_ENCODER) += adx.o
+OBJS-$(CONFIG_ADPCM_CT_DECODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_CT_ENCODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_EA_DECODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_EA_ENCODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_G726_DECODER) += g726.o
+OBJS-$(CONFIG_ADPCM_G726_ENCODER) += g726.o
+OBJS-$(CONFIG_ADPCM_IMA_DK3_DECODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_IMA_DK3_ENCODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_IMA_DK4_DECODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_IMA_DK4_ENCODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_IMA_QT_DECODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_IMA_QT_ENCODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_IMA_SMJPEG_DECODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_IMA_SMJPEG_ENCODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_IMA_WAV_DECODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_IMA_WAV_ENCODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_IMA_WS_DECODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_IMA_WS_ENCODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_MS_DECODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_MS_ENCODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_SBPRO_2_DECODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_SBPRO_2_ENCODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_SBPRO_3_DECODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_SBPRO_3_ENCODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_SBPRO_4_DECODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_SBPRO_4_ENCODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_SWF_DECODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_SWF_ENCODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_XA_DECODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_XA_ENCODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_YAMAHA_DECODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_YAMAHA_ENCODER) += adpcm.o
+
+# external codec libraries
+OBJS-$(CONFIG_LIBA52) += a52dec.o
+OBJS-$(CONFIG_LIBDTS) += dtsdec.o
+OBJS-$(CONFIG_LIBFAAC) += faac.o
+OBJS-$(CONFIG_LIBFAAD) += faad.o
+OBJS-$(CONFIG_LIBGSM) += libgsm.o
+OBJS-$(CONFIG_LIBMP3LAME) += mp3lameaudio.o
+OBJS-$(CONFIG_LIBTHEORA) += libtheoraenc.o
+OBJS-$(CONFIG_LIBVORBIS) += oggvorbis.o
+OBJS-$(CONFIG_X264) += x264.o
+OBJS-$(CONFIG_XVID) += xvidff.o xvid_rc.o
+
+OBJS-$(CONFIG_AMR) += amr.o
+OBJS-$(CONFIG_AMR_NB) += amr_float/sp_dec.o \
+ amr_float/sp_enc.o \
+ amr_float/interf_dec.o \
+ amr_float/interf_enc.o
+
+ifeq ($(CONFIG_AMR_NB_FIXED),yes)
+EXTRAOBJS += amr/*.o
+EXTRADEPS=amrlibs
+endif
+
+OBJS-$(CONFIG_AMR_WB) += amrwb_float/dec_acelp.o \
+ amrwb_float/dec_dtx.o \
+ amrwb_float/dec_gain.o \
+ amrwb_float/dec_if.o \
+ amrwb_float/dec_lpc.o \
+ amrwb_float/dec_main.o \
+ amrwb_float/dec_rom.o \
+ amrwb_float/dec_util.o \
+ amrwb_float/enc_acelp.o \
+ amrwb_float/enc_dtx.o \
+ amrwb_float/enc_gain.o \
+ amrwb_float/enc_if.o \
+ amrwb_float/enc_lpc.o \
+ amrwb_float/enc_main.o \
+ amrwb_float/enc_rom.o \
+ amrwb_float/enc_util.o \
+ amrwb_float/if_rom.o
+
+OBJS-$(CONFIG_AAC_PARSER) += parser.o
+OBJS-$(CONFIG_AC3_PARSER) += parser.o ac3.o
+OBJS-$(CONFIG_CAVSVIDEO_PARSER) += cavs.o parser.o
+OBJS-$(CONFIG_DVBSUB_PARSER) += dvbsubdec.o
+OBJS-$(CONFIG_DVDSUB_PARSER) += dvdsubdec.o
+OBJS-$(CONFIG_H261_PARSER) += h261.o
+OBJS-$(CONFIG_H263_PARSER) += h263dec.o
+OBJS-$(CONFIG_H264_PARSER) += h264.o
+OBJS-$(CONFIG_MJPEG_PARSER) += mjpeg.o
+OBJS-$(CONFIG_MPEG4VIDEO_PARSER) += parser.o
+OBJS-$(CONFIG_MPEGAUDIO_PARSER) += parser.o
+OBJS-$(CONFIG_MPEGVIDEO_PARSER) += parser.o
+OBJS-$(CONFIG_PNM_PARSER) += pnm.o
+
+OBJS-$(HAVE_PTHREADS) += pthread.o
+OBJS-$(HAVE_W32THREADS) += w32thread.o
+OBJS-$(HAVE_OS2THREADS) += os2thread.o
+OBJS-$(HAVE_BEOSTHREADS) += beosthread.o
+
+OBJS-$(HAVE_XVMC_ACCEL) += xvmcvideo.o
+
+ifneq ($(CONFIG_SWSCALER),yes)
+OBJS += imgresample.o
+endif
+
+# processor-specific code
+ifeq ($(TARGET_MMX),yes)
+OBJS += i386/fdct_mmx.o \
+ i386/cputest.o \
+ i386/dsputil_mmx.o \
+ i386/mpegvideo_mmx.o \
+ i386/motion_est_mmx.o \
+ i386/simple_idct_mmx.o \
+ i386/idct_mmx_xvid.o \
+ i386/fft_sse.o \
+ i386/vp3dsp_mmx.o \
+ i386/vp3dsp_sse2.o \
+ i386/fft_3dn.o \
+ i386/fft_3dn2.o \
+
+OBJS-$(CONFIG_GPL) += i386/idct_mmx.o
+OBJS-$(CONFIG_CAVS_DECODER) += i386/cavsdsp_mmx.o
+OBJS-$(CONFIG_SNOW_DECODER) += i386/snowdsp_mmx.o
+endif
+
+ASM_OBJS-$(TARGET_ARCH_ARMV4L) += armv4l/jrevdct_arm.o \
+ armv4l/simple_idct_arm.o \
+ armv4l/dsputil_arm_s.o \
+
+OBJS-$(TARGET_ARCH_ARMV4L) += armv4l/dsputil_arm.o \
+ armv4l/mpegvideo_arm.o \
+
+OBJS-$(TARGET_IWMMXT) += armv4l/dsputil_iwmmxt.o \
+ armv4l/mpegvideo_iwmmxt.o \
+
+ASM_OBJS-$(TARGET_ARMV5TE) += armv4l/simple_idct_armv5te.o \
+ armv4l/mpegvideo_armv5te.o \
+
+ASM_OBJS-$(HAVE_ARMV6) += armv4l/simple_idct_armv6.o
+
+OBJS-$(TARGET_ARCH_SPARC) += sparc/dsputil_vis.o \
+
+sparc/dsputil_vis.o: CFLAGS += -mcpu=ultrasparc -mtune=ultrasparc
+
+OBJS-$(HAVE_MLIB) += mlib/dsputil_mlib.o \
+
+OBJS-$(TARGET_ARCH_ALPHA) += alpha/dsputil_alpha.o \
+ alpha/mpegvideo_alpha.o \
+ alpha/simple_idct_alpha.o \
+ alpha/motion_est_alpha.o \
+
+ASM_OBJS-$(TARGET_ARCH_ALPHA) += alpha/dsputil_alpha_asm.o \
+ alpha/motion_est_mvi_asm.o \
+
+OBJS-$(TARGET_ARCH_POWERPC) += ppc/dsputil_ppc.o \
+ ppc/mpegvideo_ppc.o \
+
+OBJS-$(TARGET_MMI) += ps2/dsputil_mmi.o \
+ ps2/idct_mmi.o \
+ ps2/mpegvideo_mmi.o \
+
+OBJS-$(TARGET_ARCH_SH4) += sh4/idct_sh4.o \
+ sh4/dsputil_sh4.o \
+ sh4/dsputil_align.o \
+
+OBJS-$(TARGET_ALTIVEC) += ppc/dsputil_altivec.o \
+ ppc/mpegvideo_altivec.o \
+ ppc/idct_altivec.o \
+ ppc/fft_altivec.o \
+ ppc/gmc_altivec.o \
+ ppc/fdct_altivec.o \
+ ppc/float_altivec.o \
+
+ifeq ($(TARGET_ALTIVEC),yes)
+OBJS-$(CONFIG_H264_DECODER) += ppc/h264_altivec.o
+OBJS-$(CONFIG_SNOW_DECODER) += ppc/snow_altivec.o
+OBJS-$(CONFIG_VC1_DECODER) += ppc/vc1dsp_altivec.o
+OBJS-$(CONFIG_WMV3_DECODER) += ppc/vc1dsp_altivec.o
+endif
+
+OBJS-$(TARGET_ARCH_BFIN) += bfin/dsputil_bfin.o \
+
+ASM_OBJS-$(TARGET_ARCH_BFIN) += bfin/pixels_bfin.o \
+ bfin/idct_bfin.o \
+ bfin/fdct_bfin.o \
+
+EXTRALIBS := -L$(BUILD_ROOT)/libavutil -lavutil$(BUILDSUF) $(EXTRALIBS)
+
+NAME=avcodec
+LIBVERSION=$(LAVCVERSION)
+LIBMAJOR=$(LAVCMAJOR)
+
+TESTS= imgresample-test fft-test dct-test
+ifeq ($(TARGET_ARCH_X86),yes)
+TESTS+= cpuid_test motion-test
+endif
+
+include ../common.mak
+
+amrlibs:
+ $(MAKE) -C amr spclib fipoplib
+
+tests: apiexample $(TESTS)
+
+clean::
+ rm -f \
+ i386/*.o i386/*~ \
+ armv4l/*.o armv4l/*~ \
+ mlib/*.o mlib/*~ \
+ alpha/*.o alpha/*~ \
+ ppc/*.o ppc/*~ \
+ ps2/*.o ps2/*~ \
+ sh4/*.o sh4/*~ \
+ sparc/*.o sparc/*~ \
+ amr_float/*.o \
+ apiexample $(TESTS)
+ -$(MAKE) -C amr clean
+ -$(MAKE) -C amrwb_float -f makefile.gcc clean
+
+apiexample: apiexample.o $(LIB)
+
+cpuid_test: i386/cputest.c
+ $(CC) $(CFLAGS) -D__TEST__ -o $@ $<
+
+imgresample-test: imgresample.c $(LIB)
+ $(CC) $(CFLAGS) -DTEST -o $@ $^ $(EXTRALIBS)
+
+dct-test: dct-test.o fdctref.o $(LIB)
+
+motion-test: motion_test.o $(LIB)
+
+fft-test: fft-test.o $(LIB)
+
+.PHONY: amrlibs tests
diff --git a/contrib/ffmpeg/libavcodec/a52dec.c b/contrib/ffmpeg/libavcodec/a52dec.c
new file mode 100644
index 000000000..c2da2283d
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/a52dec.c
@@ -0,0 +1,259 @@
+/*
+ * A52 decoder using liba52
+ * Copyright (c) 2001 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 a52dec.c
+ * A52 decoder using liba52
+ */
+
+#include "avcodec.h"
+#include <a52dec/a52.h>
+
+#ifdef CONFIG_LIBA52BIN
+#include <dlfcn.h>
+static const char* liba52name = "liba52.so.0";
+#endif
+
+/**
+ * liba52 - Copyright (C) Aaron Holtzman
+ * released under the GPL license.
+ */
+typedef struct AC3DecodeState {
+ uint8_t inbuf[4096]; /* input buffer */
+ uint8_t *inbuf_ptr;
+ int frame_size;
+ int flags;
+ int channels;
+ a52_state_t* state;
+ sample_t* samples;
+
+ /*
+ * virtual method table
+ *
+ * using this function table so the liba52 doesn't
+ * have to be really linked together with ffmpeg
+ * and might be linked in runtime - this allows binary
+ * distribution of ffmpeg library which doens't depend
+ * on liba52 library - but if user has it installed
+ * it will be used - user might install such library
+ * separately
+ */
+ void* handle;
+ a52_state_t* (*a52_init)(uint32_t mm_accel);
+ sample_t* (*a52_samples)(a52_state_t * state);
+ int (*a52_syncinfo)(uint8_t * buf, int * flags,
+ int * sample_rate, int * bit_rate);
+ int (*a52_frame)(a52_state_t * state, uint8_t * buf, int * flags,
+ sample_t * level, sample_t bias);
+ void (*a52_dynrng)(a52_state_t * state,
+ sample_t (* call) (sample_t, void *), void * data);
+ int (*a52_block)(a52_state_t * state);
+ void (*a52_free)(a52_state_t * state);
+
+} AC3DecodeState;
+
+#ifdef CONFIG_LIBA52BIN
+static void* dlsymm(void* handle, const char* symbol)
+{
+ void* f = dlsym(handle, symbol);
+ if (!f)
+ av_log( NULL, AV_LOG_ERROR, "A52 Decoder - function '%s' can't be resolved\n", symbol);
+ return f;
+}
+#endif
+
+static int a52_decode_init(AVCodecContext *avctx)
+{
+ AC3DecodeState *s = avctx->priv_data;
+
+#ifdef CONFIG_LIBA52BIN
+ s->handle = dlopen(liba52name, RTLD_LAZY);
+ if (!s->handle)
+ {
+ av_log( avctx, AV_LOG_ERROR, "A52 library %s could not be opened! \n%s\n", liba52name, dlerror());
+ return -1;
+ }
+ s->a52_init = (a52_state_t* (*)(uint32_t)) dlsymm(s->handle, "a52_init");
+ s->a52_samples = (sample_t* (*)(a52_state_t*)) dlsymm(s->handle, "a52_samples");
+ s->a52_syncinfo = (int (*)(uint8_t*, int*, int*, int*)) dlsymm(s->handle, "a52_syncinfo");
+ s->a52_frame = (int (*)(a52_state_t*, uint8_t*, int*, sample_t*, sample_t)) dlsymm(s->handle, "a52_frame");
+ s->a52_block = (int (*)(a52_state_t*)) dlsymm(s->handle, "a52_block");
+ s->a52_free = (void (*)(a52_state_t*)) dlsymm(s->handle, "a52_free");
+ if (!s->a52_init || !s->a52_samples || !s->a52_syncinfo
+ || !s->a52_frame || !s->a52_block || !s->a52_free)
+ {
+ dlclose(s->handle);
+ return -1;
+ }
+#else
+ s->handle = 0;
+ s->a52_init = a52_init;
+ s->a52_samples = a52_samples;
+ s->a52_syncinfo = a52_syncinfo;
+ s->a52_frame = a52_frame;
+ s->a52_block = a52_block;
+ s->a52_free = a52_free;
+#endif
+ s->state = s->a52_init(0); /* later use CPU flags */
+ s->samples = s->a52_samples(s->state);
+ s->inbuf_ptr = s->inbuf;
+ s->frame_size = 0;
+
+ return 0;
+}
+
+/**** the following two functions comes from a52dec */
+static inline int blah (int32_t i)
+{
+ if (i > 0x43c07fff)
+ return 32767;
+ else if (i < 0x43bf8000)
+ return -32768;
+ return i - 0x43c00000;
+}
+
+static inline void float_to_int (float * _f, int16_t * s16, int nchannels)
+{
+ int i, j, c;
+ int32_t * f = (int32_t *) _f; // XXX assumes IEEE float format
+
+ j = 0;
+ nchannels *= 256;
+ for (i = 0; i < 256; i++) {
+ for (c = 0; c < nchannels; c += 256)
+ s16[j++] = blah (f[i + c]);
+ }
+}
+
+/**** end */
+
+#define HEADER_SIZE 7
+
+static int a52_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ AC3DecodeState *s = avctx->priv_data;
+ uint8_t *buf_ptr;
+ int flags, i, len;
+ int sample_rate, bit_rate;
+ short *out_samples = data;
+ float level;
+ static const int ac3_channels[8] = {
+ 2, 1, 2, 3, 3, 4, 4, 5
+ };
+
+ *data_size= 0;
+
+ buf_ptr = buf;
+ while (buf_size > 0) {
+ len = s->inbuf_ptr - s->inbuf;
+ if (s->frame_size == 0) {
+ /* no header seen : find one. We need at least 7 bytes to parse it */
+ len = HEADER_SIZE - len;
+ if (len > buf_size)
+ len = buf_size;
+ memcpy(s->inbuf_ptr, buf_ptr, len);
+ buf_ptr += len;
+ s->inbuf_ptr += len;
+ buf_size -= len;
+ if ((s->inbuf_ptr - s->inbuf) == HEADER_SIZE) {
+ len = s->a52_syncinfo(s->inbuf, &s->flags, &sample_rate, &bit_rate);
+ if (len == 0) {
+ /* no sync found : move by one byte (inefficient, but simple!) */
+ memcpy(s->inbuf, s->inbuf + 1, HEADER_SIZE - 1);
+ s->inbuf_ptr--;
+ } else {
+ s->frame_size = len;
+ /* update codec info */
+ avctx->sample_rate = sample_rate;
+ s->channels = ac3_channels[s->flags & 7];
+ if (s->flags & A52_LFE)
+ s->channels++;
+ if (avctx->channels == 0)
+ /* No specific number of channel requested */
+ avctx->channels = s->channels;
+ else if (s->channels < avctx->channels) {
+ av_log(avctx, AV_LOG_ERROR, "ac3dec: AC3 Source channels are less than specified: output to %d channels.. (frmsize: %d)\n", s->channels, len);
+ avctx->channels = s->channels;
+ }
+ avctx->bit_rate = bit_rate;
+ }
+ }
+ } else if (len < s->frame_size) {
+ len = s->frame_size - len;
+ if (len > buf_size)
+ len = buf_size;
+
+ memcpy(s->inbuf_ptr, buf_ptr, len);
+ buf_ptr += len;
+ s->inbuf_ptr += len;
+ buf_size -= len;
+ } else {
+ flags = s->flags;
+ if (avctx->channels == 1)
+ flags = A52_MONO;
+ else if (avctx->channels == 2)
+ flags = A52_STEREO;
+ else
+ flags |= A52_ADJUST_LEVEL;
+ level = 1;
+ if (s->a52_frame(s->state, s->inbuf, &flags, &level, 384)) {
+ fail:
+ av_log(avctx, AV_LOG_ERROR, "Error decoding frame\n");
+ s->inbuf_ptr = s->inbuf;
+ s->frame_size = 0;
+ continue;
+ }
+ for (i = 0; i < 6; i++) {
+ if (s->a52_block(s->state))
+ goto fail;
+ float_to_int(s->samples, out_samples + i * 256 * avctx->channels, avctx->channels);
+ }
+ s->inbuf_ptr = s->inbuf;
+ s->frame_size = 0;
+ *data_size = 6 * avctx->channels * 256 * sizeof(int16_t);
+ break;
+ }
+ }
+ return buf_ptr - buf;
+}
+
+static int a52_decode_end(AVCodecContext *avctx)
+{
+ AC3DecodeState *s = avctx->priv_data;
+ s->a52_free(s->state);
+#ifdef CONFIG_LIBA52BIN
+ dlclose(s->handle);
+#endif
+ return 0;
+}
+
+AVCodec liba52_decoder = {
+ "ac3",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_AC3,
+ sizeof(AC3DecodeState),
+ a52_decode_init,
+ NULL,
+ a52_decode_end,
+ a52_decode_frame,
+};
diff --git a/contrib/ffmpeg/libavcodec/aasc.c b/contrib/ffmpeg/libavcodec/aasc.c
new file mode 100644
index 000000000..8f26fae87
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/aasc.c
@@ -0,0 +1,175 @@
+/*
+ * Autodesc RLE Decoder
+ * Copyright (C) 2005 the ffmpeg project
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file aasc.c
+ * Autodesc RLE Video Decoder by Konstantin Shishkov
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "common.h"
+#include "avcodec.h"
+#include "dsputil.h"
+
+typedef struct AascContext {
+ AVCodecContext *avctx;
+ AVFrame frame;
+} AascContext;
+
+#define FETCH_NEXT_STREAM_BYTE() \
+ if (stream_ptr >= buf_size) \
+ { \
+ av_log(s->avctx, AV_LOG_ERROR, " AASC: stream ptr just went out of bounds (fetch)\n"); \
+ break; \
+ } \
+ stream_byte = buf[stream_ptr++];
+
+static int aasc_decode_init(AVCodecContext *avctx)
+{
+ AascContext *s = (AascContext *)avctx->priv_data;
+
+ s->avctx = avctx;
+
+ avctx->pix_fmt = PIX_FMT_BGR24;
+ s->frame.data[0] = NULL;
+
+ return 0;
+}
+
+static int aasc_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ AascContext *s = (AascContext *)avctx->priv_data;
+ int stream_ptr = 4;
+ unsigned char rle_code;
+ unsigned char stream_byte;
+ int pixel_ptr = 0;
+ int row_dec, row_ptr;
+ int frame_size;
+ int i;
+
+ s->frame.reference = 1;
+ s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
+ if (avctx->reget_buffer(avctx, &s->frame)) {
+ av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
+ return -1;
+ }
+
+ row_dec = s->frame.linesize[0];
+ row_ptr = (s->avctx->height - 1) * row_dec;
+ frame_size = row_dec * s->avctx->height;
+
+ while (row_ptr >= 0) {
+ FETCH_NEXT_STREAM_BYTE();
+ rle_code = stream_byte;
+ if (rle_code == 0) {
+ /* fetch the next byte to see how to handle escape code */
+ FETCH_NEXT_STREAM_BYTE();
+ if (stream_byte == 0) {
+ /* line is done, goto the next one */
+ row_ptr -= row_dec;
+ pixel_ptr = 0;
+ } else if (stream_byte == 1) {
+ /* decode is done */
+ break;
+ } else if (stream_byte == 2) {
+ /* reposition frame decode coordinates */
+ FETCH_NEXT_STREAM_BYTE();
+ pixel_ptr += stream_byte;
+ FETCH_NEXT_STREAM_BYTE();
+ row_ptr -= stream_byte * row_dec;
+ } else {
+ /* copy pixels from encoded stream */
+ if ((pixel_ptr + stream_byte > avctx->width * 3) ||
+ (row_ptr < 0)) {
+ av_log(s->avctx, AV_LOG_ERROR, " AASC: frame ptr just went out of bounds (copy1)\n");
+ break;
+ }
+
+ rle_code = stream_byte;
+ if (stream_ptr + rle_code > buf_size) {
+ av_log(s->avctx, AV_LOG_ERROR, " AASC: stream ptr just went out of bounds (copy2)\n");
+ break;
+ }
+
+ for (i = 0; i < rle_code; i++) {
+ FETCH_NEXT_STREAM_BYTE();
+ s->frame.data[0][row_ptr + pixel_ptr] = stream_byte;
+ pixel_ptr++;
+ }
+ if (rle_code & 1)
+ stream_ptr++;
+ }
+ } else {
+ /* decode a run of data */
+ if ((pixel_ptr + rle_code > avctx->width * 3) ||
+ (row_ptr < 0)) {
+ av_log(s->avctx, AV_LOG_ERROR, " AASC: frame ptr just went out of bounds (run1)\n");
+ break;
+ }
+
+ FETCH_NEXT_STREAM_BYTE();
+
+ while(rle_code--) {
+ s->frame.data[0][row_ptr + pixel_ptr] = stream_byte;
+ pixel_ptr++;
+ }
+ }
+ }
+
+ /* one last sanity check on the way out */
+ if (stream_ptr < buf_size)
+ av_log(s->avctx, AV_LOG_ERROR, " AASC: ended frame decode with bytes left over (%d < %d)\n",
+ stream_ptr, buf_size);
+
+ *data_size = sizeof(AVFrame);
+ *(AVFrame*)data = s->frame;
+
+ /* report that the buffer was completely consumed */
+ return buf_size;
+}
+
+static int aasc_decode_end(AVCodecContext *avctx)
+{
+ AascContext *s = (AascContext *)avctx->priv_data;
+
+ /* release the last frame */
+ if (s->frame.data[0])
+ avctx->release_buffer(avctx, &s->frame);
+
+ return 0;
+}
+
+AVCodec aasc_decoder = {
+ "aasc",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_AASC,
+ sizeof(AascContext),
+ aasc_decode_init,
+ NULL,
+ aasc_decode_end,
+ aasc_decode_frame,
+ CODEC_CAP_DR1,
+};
diff --git a/contrib/ffmpeg/libavcodec/ac3.c b/contrib/ffmpeg/libavcodec/ac3.c
new file mode 100644
index 000000000..3749d02f0
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/ac3.c
@@ -0,0 +1,287 @@
+/*
+ * Common code between AC3 encoder and decoder
+ * Copyright (c) 2000 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 ac3.c
+ * Common code between AC3 encoder and decoder.
+ */
+
+#include "avcodec.h"
+#include "ac3.h"
+#include "ac3tab.h"
+#include "bitstream.h"
+
+static inline int calc_lowcomp1(int a, int b0, int b1, int c)
+{
+ if ((b0 + 256) == b1) {
+ a = c;
+ } else if (b0 > b1) {
+ a = FFMAX(a - 64, 0);
+ }
+ return a;
+}
+
+static inline int calc_lowcomp(int a, int b0, int b1, int bin)
+{
+ if (bin < 7) {
+ return calc_lowcomp1(a, b0, b1, 384);
+ } else if (bin < 20) {
+ return calc_lowcomp1(a, b0, b1, 320);
+ } else {
+ return FFMAX(a - 128, 0);
+ }
+}
+
+void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd,
+ int16_t *bndpsd)
+{
+ int bin, i, j, k, end1, v;
+
+ /* exponent mapping to PSD */
+ for(bin=start;bin<end;bin++) {
+ psd[bin]=(3072 - (exp[bin] << 7));
+ }
+
+ /* PSD integration */
+ j=start;
+ k=masktab[start];
+ do {
+ v=psd[j];
+ j++;
+ end1 = FFMIN(bndtab[k+1], end);
+ for(i=j;i<end1;i++) {
+ /* logadd */
+ int adr = FFMIN(FFABS(v - psd[j]) >> 1, 255);
+ v = FFMAX(v, psd[j]) + latab[adr];
+ j++;
+ }
+ bndpsd[k]=v;
+ k++;
+ } while (end > bndtab[k]);
+}
+
+void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *bndpsd,
+ int start, int end, int fgain, int is_lfe,
+ int deltbae, int deltnseg, uint8_t *deltoffst,
+ uint8_t *deltlen, uint8_t *deltba,
+ int16_t *mask)
+{
+ int16_t excite[50]; /* excitation */
+ int bin, k;
+ int bndstrt, bndend, begin, end1, tmp;
+ int lowcomp, fastleak, slowleak;
+
+ /* excitation function */
+ bndstrt = masktab[start];
+ bndend = masktab[end-1] + 1;
+
+ if (bndstrt == 0) {
+ lowcomp = 0;
+ lowcomp = calc_lowcomp1(lowcomp, bndpsd[0], bndpsd[1], 384);
+ excite[0] = bndpsd[0] - fgain - lowcomp;
+ lowcomp = calc_lowcomp1(lowcomp, bndpsd[1], bndpsd[2], 384);
+ excite[1] = bndpsd[1] - fgain - lowcomp;
+ begin = 7;
+ for (bin = 2; bin < 7; bin++) {
+ if (!(is_lfe && bin == 6))
+ lowcomp = calc_lowcomp1(lowcomp, bndpsd[bin], bndpsd[bin+1], 384);
+ fastleak = bndpsd[bin] - fgain;
+ slowleak = bndpsd[bin] - s->sgain;
+ excite[bin] = fastleak - lowcomp;
+ if (!(is_lfe && bin == 6)) {
+ if (bndpsd[bin] <= bndpsd[bin+1]) {
+ begin = bin + 1;
+ break;
+ }
+ }
+ }
+
+ end1=bndend;
+ if (end1 > 22) end1=22;
+
+ for (bin = begin; bin < end1; bin++) {
+ if (!(is_lfe && bin == 6))
+ lowcomp = calc_lowcomp(lowcomp, bndpsd[bin], bndpsd[bin+1], bin);
+
+ fastleak = FFMAX(fastleak - s->fdecay, bndpsd[bin] - fgain);
+ slowleak = FFMAX(slowleak - s->sdecay, bndpsd[bin] - s->sgain);
+ excite[bin] = FFMAX(fastleak - lowcomp, slowleak);
+ }
+ begin = 22;
+ } else {
+ /* coupling channel */
+ begin = bndstrt;
+
+ fastleak = (s->cplfleak << 8) + 768;
+ slowleak = (s->cplsleak << 8) + 768;
+ }
+
+ for (bin = begin; bin < bndend; bin++) {
+ fastleak = FFMAX(fastleak - s->fdecay, bndpsd[bin] - fgain);
+ slowleak = FFMAX(slowleak - s->sdecay, bndpsd[bin] - s->sgain);
+ excite[bin] = FFMAX(fastleak, slowleak);
+ }
+
+ /* compute masking curve */
+
+ for (bin = bndstrt; bin < bndend; bin++) {
+ tmp = s->dbknee - bndpsd[bin];
+ if (tmp > 0) {
+ excite[bin] += tmp >> 2;
+ }
+ mask[bin] = FFMAX(hth[bin >> s->halfratecod][s->fscod], excite[bin]);
+ }
+
+ /* delta bit allocation */
+
+ if (deltbae == 0 || deltbae == 1) {
+ int band, seg, delta;
+ band = 0;
+ for (seg = 0; seg < deltnseg; seg++) {
+ band += deltoffst[seg];
+ if (deltba[seg] >= 4) {
+ delta = (deltba[seg] - 3) << 7;
+ } else {
+ delta = (deltba[seg] - 4) << 7;
+ }
+ for (k = 0; k < deltlen[seg]; k++) {
+ mask[band] += delta;
+ band++;
+ }
+ }
+ }
+}
+
+void ff_ac3_bit_alloc_calc_bap(int16_t *mask, int16_t *psd, int start, int end,
+ int snroffset, int floor, uint8_t *bap)
+{
+ int i, j, k, end1, v, address;
+
+ /* special case, if snroffset is -960, set all bap's to zero */
+ if(snroffset == -960) {
+ memset(bap, 0, 256);
+ return;
+ }
+
+ i = start;
+ j = masktab[start];
+ do {
+ v = (FFMAX(mask[j] - snroffset - floor, 0) & 0x1FE0) + floor;
+ end1 = FFMIN(bndtab[j] + bndsz[j], end);
+ for (k = i; k < end1; k++) {
+ address = av_clip((psd[i] - v) >> 5, 0, 63);
+ bap[i] = baptab[address];
+ i++;
+ }
+ } while (end > bndtab[j++]);
+}
+
+/* AC3 bit allocation. The algorithm is the one described in the AC3
+ spec. */
+void ac3_parametric_bit_allocation(AC3BitAllocParameters *s, uint8_t *bap,
+ int8_t *exp, int start, int end,
+ int snroffset, int fgain, int is_lfe,
+ int deltbae,int deltnseg,
+ uint8_t *deltoffst, uint8_t *deltlen,
+ uint8_t *deltba)
+{
+ int16_t psd[256]; /* scaled exponents */
+ int16_t bndpsd[50]; /* interpolated exponents */
+ int16_t mask[50]; /* masking value */
+
+ ff_ac3_bit_alloc_calc_psd(exp, start, end, psd, bndpsd);
+
+ ff_ac3_bit_alloc_calc_mask(s, bndpsd, start, end, fgain, is_lfe,
+ deltbae, deltnseg, deltoffst, deltlen, deltba,
+ mask);
+
+ ff_ac3_bit_alloc_calc_bap(mask, psd, start, end, snroffset, s->floor, bap);
+}
+
+/**
+ * Initializes some tables.
+ * note: This function must remain thread safe because it is called by the
+ * AVParser init code.
+ */
+void ac3_common_init(void)
+{
+ int i, j, k, l, v;
+ /* compute bndtab and masktab from bandsz */
+ k = 0;
+ l = 0;
+ for(i=0;i<50;i++) {
+ bndtab[i] = l;
+ v = bndsz[i];
+ for(j=0;j<v;j++) masktab[k++]=i;
+ l += v;
+ }
+ bndtab[50] = l;
+}
+
+int ff_ac3_parse_header(const uint8_t buf[7], AC3HeaderInfo *hdr)
+{
+ GetBitContext gbc;
+
+ memset(hdr, 0, sizeof(*hdr));
+
+ init_get_bits(&gbc, buf, 54);
+
+ hdr->sync_word = get_bits(&gbc, 16);
+ if(hdr->sync_word != 0x0B77)
+ return -1;
+
+ /* read ahead to bsid to make sure this is AC-3, not E-AC-3 */
+ hdr->bsid = show_bits_long(&gbc, 29) & 0x1F;
+ if(hdr->bsid > 10)
+ return -2;
+
+ hdr->crc1 = get_bits(&gbc, 16);
+ hdr->fscod = get_bits(&gbc, 2);
+ if(hdr->fscod == 3)
+ return -3;
+
+ hdr->frmsizecod = get_bits(&gbc, 6);
+ if(hdr->frmsizecod > 37)
+ return -4;
+
+ skip_bits(&gbc, 5); // skip bsid, already got it
+
+ hdr->bsmod = get_bits(&gbc, 3);
+ hdr->acmod = get_bits(&gbc, 3);
+ if((hdr->acmod & 1) && hdr->acmod != 1) {
+ hdr->cmixlev = get_bits(&gbc, 2);
+ }
+ if(hdr->acmod & 4) {
+ hdr->surmixlev = get_bits(&gbc, 2);
+ }
+ if(hdr->acmod == 2) {
+ hdr->dsurmod = get_bits(&gbc, 2);
+ }
+ hdr->lfeon = get_bits1(&gbc);
+
+ hdr->halfratecod = FFMAX(hdr->bsid, 8) - 8;
+ hdr->sample_rate = ff_ac3_freqs[hdr->fscod] >> hdr->halfratecod;
+ hdr->bit_rate = (ff_ac3_bitratetab[hdr->frmsizecod>>1] * 1000) >> hdr->halfratecod;
+ hdr->channels = ff_ac3_channels[hdr->acmod] + hdr->lfeon;
+ hdr->frame_size = ff_ac3_frame_sizes[hdr->frmsizecod][hdr->fscod] * 2;
+
+ return 0;
+}
diff --git a/contrib/ffmpeg/libavcodec/ac3.h b/contrib/ffmpeg/libavcodec/ac3.h
new file mode 100644
index 000000000..ae53a80c3
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/ac3.h
@@ -0,0 +1,171 @@
+/*
+ * Common code between AC3 encoder and decoder
+ * Copyright (c) 2000, 2001, 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 ac3.h
+ * Common code between AC3 encoder and decoder.
+ */
+
+#define AC3_MAX_CODED_FRAME_SIZE 3840 /* in bytes */
+#define AC3_MAX_CHANNELS 6 /* including LFE channel */
+
+#define NB_BLOCKS 6 /* number of PCM blocks inside an AC3 frame */
+#define AC3_FRAME_SIZE (NB_BLOCKS * 256)
+
+/* exponent encoding strategy */
+#define EXP_REUSE 0
+#define EXP_NEW 1
+
+#define EXP_D15 1
+#define EXP_D25 2
+#define EXP_D45 3
+
+typedef struct AC3BitAllocParameters {
+ int fscod; /* frequency */
+ int halfratecod;
+ int sgain, sdecay, fdecay, dbknee, floor;
+ int cplfleak, cplsleak;
+} AC3BitAllocParameters;
+
+/**
+ * @struct AC3HeaderInfo
+ * Coded AC-3 header values up to the lfeon element, plus derived values.
+ */
+typedef struct {
+ /** @defgroup coded Coded elements
+ * @{
+ */
+ uint16_t sync_word;
+ uint16_t crc1;
+ uint8_t fscod;
+ uint8_t frmsizecod;
+ uint8_t bsid;
+ uint8_t bsmod;
+ uint8_t acmod;
+ uint8_t cmixlev;
+ uint8_t surmixlev;
+ uint8_t dsurmod;
+ uint8_t lfeon;
+ /** @} */
+
+ /** @defgroup derived Derived values
+ * @{
+ */
+ uint8_t halfratecod;
+ uint16_t sample_rate;
+ uint32_t bit_rate;
+ uint8_t channels;
+ uint16_t frame_size;
+ /** @} */
+} AC3HeaderInfo;
+
+/**
+ * Parses AC-3 frame header.
+ * Parses the header up to the lfeon element, which is the first 52 or 54 bits
+ * depending on the audio coding mode.
+ * @param buf[in] Array containing the first 7 bytes of the frame.
+ * @param hdr[out] Pointer to struct where header info is written.
+ * @return Returns 0 on success, -1 if there is a sync word mismatch,
+ * -2 if the bsid (version) element is invalid, -3 if the fscod (sample rate)
+ * element is invalid, or -4 if the frmsizecod (bit rate) element is invalid.
+ */
+int ff_ac3_parse_header(const uint8_t buf[7], AC3HeaderInfo *hdr);
+
+extern const uint16_t ff_ac3_frame_sizes[38][3];
+extern const uint8_t ff_ac3_channels[8];
+extern const uint16_t ff_ac3_freqs[3];
+extern const uint16_t ff_ac3_bitratetab[19];
+extern const int16_t ff_ac3_window[256];
+extern const uint8_t ff_sdecaytab[4];
+extern const uint8_t ff_fdecaytab[4];
+extern const uint16_t ff_sgaintab[4];
+extern const uint16_t ff_dbkneetab[4];
+extern const int16_t ff_floortab[8];
+extern const uint16_t ff_fgaintab[8];
+
+void ac3_common_init(void);
+
+/**
+ * Calculates the log power-spectral density of the input signal.
+ * This gives a rough estimate of signal power in the frequency domain by using
+ * the spectral envelope (exponents). The psd is also separately grouped
+ * into critical bands for use in the calculating the masking curve.
+ * 128 units in psd = -6 dB. The dbknee parameter in AC3BitAllocParameters
+ * determines the reference level.
+ *
+ * @param[in] exp frequency coefficient exponents
+ * @param[in] start starting bin location
+ * @param[in] end ending bin location
+ * @param[out] psd signal power for each frequency bin
+ * @param[out] bndpsd signal power for each critical band
+ */
+void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd,
+ int16_t *bndpsd);
+
+/**
+ * Calculates the masking curve.
+ * First, the excitation is calculated using parameters in \p s and the signal
+ * power in each critical band. The excitation is compared with a predefined
+ * hearing threshold table to produce the masking curve. If delta bit
+ * allocation information is provided, it is used for adjusting the masking
+ * curve, usually to give a closer match to a better psychoacoustic model.
+ *
+ * @param[in] s adjustable bit allocation parameters
+ * @param[in] bndpsd signal power for each critical band
+ * @param[in] start starting bin location
+ * @param[in] end ending bin location
+ * @param[in] fgain fast gain (estimated signal-to-mask ratio)
+ * @param[in] is_lfe whether or not the channel being processed is the LFE
+ * @param[in] deltbae delta bit allocation exists (none, reuse, or new)
+ * @param[in] deltnseg number of delta segments
+ * @param[in] deltoffst location offsets for each segment
+ * @param[in] deltlen length of each segment
+ * @param[in] deltba delta bit allocation for each segment
+ * @param[out] mask calculated masking curve
+ */
+void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *bndpsd,
+ int start, int end, int fgain, int is_lfe,
+ int deltbae, int deltnseg, uint8_t *deltoffst,
+ uint8_t *deltlen, uint8_t *deltba,
+ int16_t *mask);
+
+/**
+ * Calculates bit allocation pointers.
+ * The SNR is the difference between the masking curve and the signal. AC-3
+ * uses this value for each frequency bin to allocate bits. The \p snroffset
+ * parameter is a global adjustment to the SNR for all bins.
+ *
+ * @param[in] mask masking curve
+ * @param[in] psd signal power for each frequency bin
+ * @param[in] start starting bin location
+ * @param[in] end ending bin location
+ * @param[in] snroffset SNR adjustment
+ * @param[in] floor noise floor
+ * @param[out] bap bit allocation pointers
+ */
+void ff_ac3_bit_alloc_calc_bap(int16_t *mask, int16_t *psd, int start, int end,
+ int snroffset, int floor, uint8_t *bap);
+
+void ac3_parametric_bit_allocation(AC3BitAllocParameters *s, uint8_t *bap,
+ int8_t *exp, int start, int end,
+ int snroffset, int fgain, int is_lfe,
+ int deltbae,int deltnseg,
+ uint8_t *deltoffst, uint8_t *deltlen, uint8_t *deltba);
diff --git a/contrib/ffmpeg/libavcodec/ac3enc.c b/contrib/ffmpeg/libavcodec/ac3enc.c
new file mode 100644
index 000000000..5161b61e4
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/ac3enc.c
@@ -0,0 +1,1371 @@
+/*
+ * The simplest AC3 encoder
+ * Copyright (c) 2000 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 ac3enc.c
+ * The simplest AC3 encoder.
+ */
+//#define DEBUG
+//#define DEBUG_BITALLOC
+#include "avcodec.h"
+#include "bitstream.h"
+#include "crc.h"
+#include "ac3.h"
+
+typedef struct AC3EncodeContext {
+ PutBitContext pb;
+ int nb_channels;
+ int nb_all_channels;
+ int lfe_channel;
+ int bit_rate;
+ unsigned int sample_rate;
+ unsigned int bsid;
+ unsigned int frame_size_min; /* minimum frame size in case rounding is necessary */
+ unsigned int frame_size; /* current frame size in words */
+ unsigned int bits_written;
+ unsigned int samples_written;
+ int halfratecod;
+ unsigned int frmsizecod;
+ unsigned int fscod; /* frequency */
+ unsigned int acmod;
+ int lfe;
+ unsigned int bsmod;
+ short last_samples[AC3_MAX_CHANNELS][256];
+ unsigned int chbwcod[AC3_MAX_CHANNELS];
+ int nb_coefs[AC3_MAX_CHANNELS];
+
+ /* bitrate allocation control */
+ int sgaincod, sdecaycod, fdecaycod, dbkneecod, floorcod;
+ AC3BitAllocParameters bit_alloc;
+ int csnroffst;
+ int fgaincod[AC3_MAX_CHANNELS];
+ int fsnroffst[AC3_MAX_CHANNELS];
+ /* mantissa encoding */
+ int mant1_cnt, mant2_cnt, mant4_cnt;
+} AC3EncodeContext;
+
+static int16_t costab[64];
+static int16_t sintab[64];
+static int16_t fft_rev[512];
+static int16_t xcos1[128];
+static int16_t xsin1[128];
+
+#define MDCT_NBITS 9
+#define N (1 << MDCT_NBITS)
+
+/* new exponents are sent if their Norm 1 exceed this number */
+#define EXP_DIFF_THRESHOLD 1000
+
+static void fft_init(int ln);
+
+static inline int16_t fix15(float a)
+{
+ int v;
+ v = (int)(a * (float)(1 << 15));
+ if (v < -32767)
+ v = -32767;
+ else if (v > 32767)
+ v = 32767;
+ return v;
+}
+
+typedef struct IComplex {
+ short re,im;
+} IComplex;
+
+static void fft_init(int ln)
+{
+ int i, j, m, n;
+ float alpha;
+
+ n = 1 << ln;
+
+ for(i=0;i<(n/2);i++) {
+ alpha = 2 * M_PI * (float)i / (float)n;
+ costab[i] = fix15(cos(alpha));
+ sintab[i] = fix15(sin(alpha));
+ }
+
+ for(i=0;i<n;i++) {
+ m=0;
+ for(j=0;j<ln;j++) {
+ m |= ((i >> j) & 1) << (ln-j-1);
+ }
+ fft_rev[i]=m;
+ }
+}
+
+/* butter fly op */
+#define BF(pre, pim, qre, qim, pre1, pim1, qre1, qim1) \
+{\
+ int ax, ay, bx, by;\
+ bx=pre1;\
+ by=pim1;\
+ ax=qre1;\
+ ay=qim1;\
+ pre = (bx + ax) >> 1;\
+ pim = (by + ay) >> 1;\
+ qre = (bx - ax) >> 1;\
+ qim = (by - ay) >> 1;\
+}
+
+#define MUL16(a,b) ((a) * (b))
+
+#define CMUL(pre, pim, are, aim, bre, bim) \
+{\
+ pre = (MUL16(are, bre) - MUL16(aim, bim)) >> 15;\
+ pim = (MUL16(are, bim) + MUL16(bre, aim)) >> 15;\
+}
+
+
+/* do a 2^n point complex fft on 2^ln points. */
+static void fft(IComplex *z, int ln)
+{
+ int j, l, np, np2;
+ int nblocks, nloops;
+ register IComplex *p,*q;
+ int tmp_re, tmp_im;
+
+ np = 1 << ln;
+
+ /* reverse */
+ for(j=0;j<np;j++) {
+ int k;
+ IComplex tmp;
+ k = fft_rev[j];
+ if (k < j) {
+ tmp = z[k];
+ z[k] = z[j];
+ z[j] = tmp;
+ }
+ }
+
+ /* pass 0 */
+
+ p=&z[0];
+ j=(np >> 1);
+ do {
+ BF(p[0].re, p[0].im, p[1].re, p[1].im,
+ p[0].re, p[0].im, p[1].re, p[1].im);
+ p+=2;
+ } while (--j != 0);
+
+ /* pass 1 */
+
+ p=&z[0];
+ j=np >> 2;
+ do {
+ BF(p[0].re, p[0].im, p[2].re, p[2].im,
+ p[0].re, p[0].im, p[2].re, p[2].im);
+ BF(p[1].re, p[1].im, p[3].re, p[3].im,
+ p[1].re, p[1].im, p[3].im, -p[3].re);
+ p+=4;
+ } while (--j != 0);
+
+ /* pass 2 .. ln-1 */
+
+ nblocks = np >> 3;
+ nloops = 1 << 2;
+ np2 = np >> 1;
+ do {
+ p = z;
+ q = z + nloops;
+ for (j = 0; j < nblocks; ++j) {
+
+ BF(p->re, p->im, q->re, q->im,
+ p->re, p->im, q->re, q->im);
+
+ p++;
+ q++;
+ for(l = nblocks; l < np2; l += nblocks) {
+ CMUL(tmp_re, tmp_im, costab[l], -sintab[l], q->re, q->im);
+ BF(p->re, p->im, q->re, q->im,
+ p->re, p->im, tmp_re, tmp_im);
+ p++;
+ q++;
+ }
+ p += nloops;
+ q += nloops;
+ }
+ nblocks = nblocks >> 1;
+ nloops = nloops << 1;
+ } while (nblocks != 0);
+}
+
+/* do a 512 point mdct */
+static void mdct512(int32_t *out, int16_t *in)
+{
+ int i, re, im, re1, im1;
+ int16_t rot[N];
+ IComplex x[N/4];
+
+ /* shift to simplify computations */
+ for(i=0;i<N/4;i++)
+ rot[i] = -in[i + 3*N/4];
+ for(i=N/4;i<N;i++)
+ rot[i] = in[i - N/4];
+
+ /* pre rotation */
+ for(i=0;i<N/4;i++) {
+ re = ((int)rot[2*i] - (int)rot[N-1-2*i]) >> 1;
+ im = -((int)rot[N/2+2*i] - (int)rot[N/2-1-2*i]) >> 1;
+ CMUL(x[i].re, x[i].im, re, im, -xcos1[i], xsin1[i]);
+ }
+
+ fft(x, MDCT_NBITS - 2);
+
+ /* post rotation */
+ for(i=0;i<N/4;i++) {
+ re = x[i].re;
+ im = x[i].im;
+ CMUL(re1, im1, re, im, xsin1[i], xcos1[i]);
+ out[2*i] = im1;
+ out[N/2-1-2*i] = re1;
+ }
+}
+
+/* XXX: use another norm ? */
+static int calc_exp_diff(uint8_t *exp1, uint8_t *exp2, int n)
+{
+ int sum, i;
+ sum = 0;
+ for(i=0;i<n;i++) {
+ sum += abs(exp1[i] - exp2[i]);
+ }
+ return sum;
+}
+
+static void compute_exp_strategy(uint8_t exp_strategy[NB_BLOCKS][AC3_MAX_CHANNELS],
+ uint8_t exp[NB_BLOCKS][AC3_MAX_CHANNELS][N/2],
+ int ch, int is_lfe)
+{
+ int i, j;
+ int exp_diff;
+
+ /* estimate if the exponent variation & decide if they should be
+ reused in the next frame */
+ exp_strategy[0][ch] = EXP_NEW;
+ for(i=1;i<NB_BLOCKS;i++) {
+ exp_diff = calc_exp_diff(exp[i][ch], exp[i-1][ch], N/2);
+#ifdef DEBUG
+ av_log(NULL, AV_LOG_DEBUG, "exp_diff=%d\n", exp_diff);
+#endif
+ if (exp_diff > EXP_DIFF_THRESHOLD)
+ exp_strategy[i][ch] = EXP_NEW;
+ else
+ exp_strategy[i][ch] = EXP_REUSE;
+ }
+ if (is_lfe)
+ return;
+
+ /* now select the encoding strategy type : if exponents are often
+ recoded, we use a coarse encoding */
+ i = 0;
+ while (i < NB_BLOCKS) {
+ j = i + 1;
+ while (j < NB_BLOCKS && exp_strategy[j][ch] == EXP_REUSE)
+ j++;
+ switch(j - i) {
+ case 1:
+ exp_strategy[i][ch] = EXP_D45;
+ break;
+ case 2:
+ case 3:
+ exp_strategy[i][ch] = EXP_D25;
+ break;
+ default:
+ exp_strategy[i][ch] = EXP_D15;
+ break;
+ }
+ i = j;
+ }
+}
+
+/* set exp[i] to min(exp[i], exp1[i]) */
+static void exponent_min(uint8_t exp[N/2], uint8_t exp1[N/2], int n)
+{
+ int i;
+
+ for(i=0;i<n;i++) {
+ if (exp1[i] < exp[i])
+ exp[i] = exp1[i];
+ }
+}
+
+/* update the exponents so that they are the ones the decoder will
+ decode. Return the number of bits used to code the exponents */
+static int encode_exp(uint8_t encoded_exp[N/2],
+ uint8_t exp[N/2],
+ int nb_exps,
+ int exp_strategy)
+{
+ int group_size, nb_groups, i, j, k, exp_min;
+ uint8_t exp1[N/2];
+
+ switch(exp_strategy) {
+ case EXP_D15:
+ group_size = 1;
+ break;
+ case EXP_D25:
+ group_size = 2;
+ break;
+ default:
+ case EXP_D45:
+ group_size = 4;
+ break;
+ }
+ nb_groups = ((nb_exps + (group_size * 3) - 4) / (3 * group_size)) * 3;
+
+ /* for each group, compute the minimum exponent */
+ exp1[0] = exp[0]; /* DC exponent is handled separately */
+ k = 1;
+ for(i=1;i<=nb_groups;i++) {
+ exp_min = exp[k];
+ assert(exp_min >= 0 && exp_min <= 24);
+ for(j=1;j<group_size;j++) {
+ if (exp[k+j] < exp_min)
+ exp_min = exp[k+j];
+ }
+ exp1[i] = exp_min;
+ k += group_size;
+ }
+
+ /* constraint for DC exponent */
+ if (exp1[0] > 15)
+ exp1[0] = 15;
+
+ /* Decrease the delta between each groups to within 2
+ * so that they can be differentially encoded */
+ for (i=1;i<=nb_groups;i++)
+ exp1[i] = FFMIN(exp1[i], exp1[i-1] + 2);
+ for (i=nb_groups-1;i>=0;i--)
+ exp1[i] = FFMIN(exp1[i], exp1[i+1] + 2);
+
+ /* now we have the exponent values the decoder will see */
+ encoded_exp[0] = exp1[0];
+ k = 1;
+ for(i=1;i<=nb_groups;i++) {
+ for(j=0;j<group_size;j++) {
+ encoded_exp[k+j] = exp1[i];
+ }
+ k += group_size;
+ }
+
+#if defined(DEBUG)
+ av_log(NULL, AV_LOG_DEBUG, "exponents: strategy=%d\n", exp_strategy);
+ for(i=0;i<=nb_groups * group_size;i++) {
+ av_log(NULL, AV_LOG_DEBUG, "%d ", encoded_exp[i]);
+ }
+ av_log(NULL, AV_LOG_DEBUG, "\n");
+#endif
+
+ return 4 + (nb_groups / 3) * 7;
+}
+
+/* return the size in bits taken by the mantissa */
+static int compute_mantissa_size(AC3EncodeContext *s, uint8_t *m, int nb_coefs)
+{
+ int bits, mant, i;
+
+ bits = 0;
+ for(i=0;i<nb_coefs;i++) {
+ mant = m[i];
+ switch(mant) {
+ case 0:
+ /* nothing */
+ break;
+ case 1:
+ /* 3 mantissa in 5 bits */
+ if (s->mant1_cnt == 0)
+ bits += 5;
+ if (++s->mant1_cnt == 3)
+ s->mant1_cnt = 0;
+ break;
+ case 2:
+ /* 3 mantissa in 7 bits */
+ if (s->mant2_cnt == 0)
+ bits += 7;
+ if (++s->mant2_cnt == 3)
+ s->mant2_cnt = 0;
+ break;
+ case 3:
+ bits += 3;
+ break;
+ case 4:
+ /* 2 mantissa in 7 bits */
+ if (s->mant4_cnt == 0)
+ bits += 7;
+ if (++s->mant4_cnt == 2)
+ s->mant4_cnt = 0;
+ break;
+ case 14:
+ bits += 14;
+ break;
+ case 15:
+ bits += 16;
+ break;
+ default:
+ bits += mant - 1;
+ break;
+ }
+ }
+ return bits;
+}
+
+
+static void bit_alloc_masking(AC3EncodeContext *s,
+ uint8_t encoded_exp[NB_BLOCKS][AC3_MAX_CHANNELS][N/2],
+ uint8_t exp_strategy[NB_BLOCKS][AC3_MAX_CHANNELS],
+ int16_t psd[NB_BLOCKS][AC3_MAX_CHANNELS][N/2],
+ int16_t mask[NB_BLOCKS][AC3_MAX_CHANNELS][50])
+{
+ int blk, ch;
+ int16_t bndpsd[NB_BLOCKS][AC3_MAX_CHANNELS][50];
+
+ for(blk=0; blk<NB_BLOCKS; blk++) {
+ for(ch=0;ch<s->nb_all_channels;ch++) {
+ if(exp_strategy[blk][ch] == EXP_REUSE) {
+ memcpy(psd[blk][ch], psd[blk-1][ch], (N/2)*sizeof(int16_t));
+ memcpy(mask[blk][ch], mask[blk-1][ch], 50*sizeof(int16_t));
+ } else {
+ ff_ac3_bit_alloc_calc_psd(encoded_exp[blk][ch], 0,
+ s->nb_coefs[ch],
+ psd[blk][ch], bndpsd[blk][ch]);
+ ff_ac3_bit_alloc_calc_mask(&s->bit_alloc, bndpsd[blk][ch],
+ 0, s->nb_coefs[ch],
+ ff_fgaintab[s->fgaincod[ch]],
+ ch == s->lfe_channel,
+ 2, 0, NULL, NULL, NULL,
+ mask[blk][ch]);
+ }
+ }
+ }
+}
+
+static int bit_alloc(AC3EncodeContext *s,
+ int16_t mask[NB_BLOCKS][AC3_MAX_CHANNELS][50],
+ int16_t psd[NB_BLOCKS][AC3_MAX_CHANNELS][N/2],
+ uint8_t bap[NB_BLOCKS][AC3_MAX_CHANNELS][N/2],
+ int frame_bits, int csnroffst, int fsnroffst)
+{
+ int i, ch;
+ int snroffset;
+
+ snroffset = (((csnroffst - 15) << 4) + fsnroffst) << 2;
+
+ /* compute size */
+ for(i=0;i<NB_BLOCKS;i++) {
+ s->mant1_cnt = 0;
+ s->mant2_cnt = 0;
+ s->mant4_cnt = 0;
+ for(ch=0;ch<s->nb_all_channels;ch++) {
+ ff_ac3_bit_alloc_calc_bap(mask[i][ch], psd[i][ch], 0,
+ s->nb_coefs[ch], snroffset,
+ s->bit_alloc.floor, bap[i][ch]);
+ frame_bits += compute_mantissa_size(s, bap[i][ch],
+ s->nb_coefs[ch]);
+ }
+ }
+#if 0
+ printf("csnr=%d fsnr=%d frame_bits=%d diff=%d\n",
+ csnroffst, fsnroffst, frame_bits,
+ 16 * s->frame_size - ((frame_bits + 7) & ~7));
+#endif
+ return 16 * s->frame_size - frame_bits;
+}
+
+#define SNR_INC1 4
+
+static int compute_bit_allocation(AC3EncodeContext *s,
+ uint8_t bap[NB_BLOCKS][AC3_MAX_CHANNELS][N/2],
+ uint8_t encoded_exp[NB_BLOCKS][AC3_MAX_CHANNELS][N/2],
+ uint8_t exp_strategy[NB_BLOCKS][AC3_MAX_CHANNELS],
+ int frame_bits)
+{
+ int i, ch;
+ int csnroffst, fsnroffst;
+ uint8_t bap1[NB_BLOCKS][AC3_MAX_CHANNELS][N/2];
+ int16_t psd[NB_BLOCKS][AC3_MAX_CHANNELS][N/2];
+ int16_t mask[NB_BLOCKS][AC3_MAX_CHANNELS][50];
+ static int frame_bits_inc[8] = { 0, 0, 2, 2, 2, 4, 2, 4 };
+
+ /* init default parameters */
+ s->sdecaycod = 2;
+ s->fdecaycod = 1;
+ s->sgaincod = 1;
+ s->dbkneecod = 2;
+ s->floorcod = 4;
+ for(ch=0;ch<s->nb_all_channels;ch++)
+ s->fgaincod[ch] = 4;
+
+ /* compute real values */
+ s->bit_alloc.fscod = s->fscod;
+ s->bit_alloc.halfratecod = s->halfratecod;
+ s->bit_alloc.sdecay = ff_sdecaytab[s->sdecaycod] >> s->halfratecod;
+ s->bit_alloc.fdecay = ff_fdecaytab[s->fdecaycod] >> s->halfratecod;
+ s->bit_alloc.sgain = ff_sgaintab[s->sgaincod];
+ s->bit_alloc.dbknee = ff_dbkneetab[s->dbkneecod];
+ s->bit_alloc.floor = ff_floortab[s->floorcod];
+
+ /* header size */
+ frame_bits += 65;
+ // if (s->acmod == 2)
+ // frame_bits += 2;
+ frame_bits += frame_bits_inc[s->acmod];
+
+ /* audio blocks */
+ for(i=0;i<NB_BLOCKS;i++) {
+ frame_bits += s->nb_channels * 2 + 2; /* blksw * c, dithflag * c, dynrnge, cplstre */
+ if (s->acmod == 2) {
+ frame_bits++; /* rematstr */
+ if(i==0) frame_bits += 4;
+ }
+ frame_bits += 2 * s->nb_channels; /* chexpstr[2] * c */
+ if (s->lfe)
+ frame_bits++; /* lfeexpstr */
+ for(ch=0;ch<s->nb_channels;ch++) {
+ if (exp_strategy[i][ch] != EXP_REUSE)
+ frame_bits += 6 + 2; /* chbwcod[6], gainrng[2] */
+ }
+ frame_bits++; /* baie */
+ frame_bits++; /* snr */
+ frame_bits += 2; /* delta / skip */
+ }
+ frame_bits++; /* cplinu for block 0 */
+ /* bit alloc info */
+ /* sdcycod[2], fdcycod[2], sgaincod[2], dbpbcod[2], floorcod[3] */
+ /* csnroffset[6] */
+ /* (fsnoffset[4] + fgaincod[4]) * c */
+ frame_bits += 2*4 + 3 + 6 + s->nb_all_channels * (4 + 3);
+
+ /* auxdatae, crcrsv */
+ frame_bits += 2;
+
+ /* CRC */
+ frame_bits += 16;
+
+ /* calculate psd and masking curve before doing bit allocation */
+ bit_alloc_masking(s, encoded_exp, exp_strategy, psd, mask);
+
+ /* now the big work begins : do the bit allocation. Modify the snr
+ offset until we can pack everything in the requested frame size */
+
+ csnroffst = s->csnroffst;
+ while (csnroffst >= 0 &&
+ bit_alloc(s, mask, psd, bap, frame_bits, csnroffst, 0) < 0)
+ csnroffst -= SNR_INC1;
+ if (csnroffst < 0) {
+ av_log(NULL, AV_LOG_ERROR, "Bit allocation failed, try increasing the bitrate, -ab 384 for example!\n");
+ return -1;
+ }
+ while ((csnroffst + SNR_INC1) <= 63 &&
+ bit_alloc(s, mask, psd, bap1, frame_bits,
+ csnroffst + SNR_INC1, 0) >= 0) {
+ csnroffst += SNR_INC1;
+ memcpy(bap, bap1, sizeof(bap1));
+ }
+ while ((csnroffst + 1) <= 63 &&
+ bit_alloc(s, mask, psd, bap1, frame_bits, csnroffst + 1, 0) >= 0) {
+ csnroffst++;
+ memcpy(bap, bap1, sizeof(bap1));
+ }
+
+ fsnroffst = 0;
+ while ((fsnroffst + SNR_INC1) <= 15 &&
+ bit_alloc(s, mask, psd, bap1, frame_bits,
+ csnroffst, fsnroffst + SNR_INC1) >= 0) {
+ fsnroffst += SNR_INC1;
+ memcpy(bap, bap1, sizeof(bap1));
+ }
+ while ((fsnroffst + 1) <= 15 &&
+ bit_alloc(s, mask, psd, bap1, frame_bits,
+ csnroffst, fsnroffst + 1) >= 0) {
+ fsnroffst++;
+ memcpy(bap, bap1, sizeof(bap1));
+ }
+
+ s->csnroffst = csnroffst;
+ for(ch=0;ch<s->nb_all_channels;ch++)
+ s->fsnroffst[ch] = fsnroffst;
+#if defined(DEBUG_BITALLOC)
+ {
+ int j;
+
+ for(i=0;i<6;i++) {
+ for(ch=0;ch<s->nb_all_channels;ch++) {
+ printf("Block #%d Ch%d:\n", i, ch);
+ printf("bap=");
+ for(j=0;j<s->nb_coefs[ch];j++) {
+ printf("%d ",bap[i][ch][j]);
+ }
+ printf("\n");
+ }
+ }
+ }
+#endif
+ return 0;
+}
+
+static int AC3_encode_init(AVCodecContext *avctx)
+{
+ int freq = avctx->sample_rate;
+ int bitrate = avctx->bit_rate;
+ int channels = avctx->channels;
+ AC3EncodeContext *s = avctx->priv_data;
+ int i, j, ch;
+ float alpha;
+ static const uint8_t acmod_defs[6] = {
+ 0x01, /* C */
+ 0x02, /* L R */
+ 0x03, /* L C R */
+ 0x06, /* L R SL SR */
+ 0x07, /* L C R SL SR */
+ 0x07, /* L C R SL SR (+LFE) */
+ };
+
+ avctx->frame_size = AC3_FRAME_SIZE;
+
+ ac3_common_init();
+
+ /* number of channels */
+ if (channels < 1 || channels > 6)
+ return -1;
+ s->acmod = acmod_defs[channels - 1];
+ s->lfe = (channels == 6) ? 1 : 0;
+ s->nb_all_channels = channels;
+ s->nb_channels = channels > 5 ? 5 : channels;
+ s->lfe_channel = s->lfe ? 5 : -1;
+
+ /* frequency */
+ for(i=0;i<3;i++) {
+ for(j=0;j<3;j++)
+ if ((ff_ac3_freqs[j] >> i) == freq)
+ goto found;
+ }
+ return -1;
+ found:
+ s->sample_rate = freq;
+ s->halfratecod = i;
+ s->fscod = j;
+ s->bsid = 8 + s->halfratecod;
+ s->bsmod = 0; /* complete main audio service */
+
+ /* bitrate & frame size */
+ bitrate /= 1000;
+ for(i=0;i<19;i++) {
+ if ((ff_ac3_bitratetab[i] >> s->halfratecod) == bitrate)
+ break;
+ }
+ if (i == 19)
+ return -1;
+ s->bit_rate = bitrate;
+ s->frmsizecod = i << 1;
+ s->frame_size_min = ff_ac3_frame_sizes[s->frmsizecod][s->fscod];
+ s->bits_written = 0;
+ s->samples_written = 0;
+ s->frame_size = s->frame_size_min;
+
+ /* bit allocation init */
+ for(ch=0;ch<s->nb_channels;ch++) {
+ /* bandwidth for each channel */
+ /* XXX: should compute the bandwidth according to the frame
+ size, so that we avoid anoying high freq artefacts */
+ s->chbwcod[ch] = 50; /* sample bandwidth as mpeg audio layer 2 table 0 */
+ s->nb_coefs[ch] = ((s->chbwcod[ch] + 12) * 3) + 37;
+ }
+ if (s->lfe) {
+ s->nb_coefs[s->lfe_channel] = 7; /* fixed */
+ }
+ /* initial snr offset */
+ s->csnroffst = 40;
+
+ /* mdct init */
+ fft_init(MDCT_NBITS - 2);
+ for(i=0;i<N/4;i++) {
+ alpha = 2 * M_PI * (i + 1.0 / 8.0) / (float)N;
+ xcos1[i] = fix15(-cos(alpha));
+ xsin1[i] = fix15(-sin(alpha));
+ }
+
+ avctx->coded_frame= avcodec_alloc_frame();
+ avctx->coded_frame->key_frame= 1;
+
+ return 0;
+}
+
+/* output the AC3 frame header */
+static void output_frame_header(AC3EncodeContext *s, unsigned char *frame)
+{
+ init_put_bits(&s->pb, frame, AC3_MAX_CODED_FRAME_SIZE);
+
+ put_bits(&s->pb, 16, 0x0b77); /* frame header */
+ put_bits(&s->pb, 16, 0); /* crc1: will be filled later */
+ put_bits(&s->pb, 2, s->fscod);
+ put_bits(&s->pb, 6, s->frmsizecod + (s->frame_size - s->frame_size_min));
+ put_bits(&s->pb, 5, s->bsid);
+ put_bits(&s->pb, 3, s->bsmod);
+ put_bits(&s->pb, 3, s->acmod);
+ if ((s->acmod & 0x01) && s->acmod != 0x01)
+ put_bits(&s->pb, 2, 1); /* XXX -4.5 dB */
+ if (s->acmod & 0x04)
+ put_bits(&s->pb, 2, 1); /* XXX -6 dB */
+ if (s->acmod == 0x02)
+ put_bits(&s->pb, 2, 0); /* surround not indicated */
+ put_bits(&s->pb, 1, s->lfe); /* LFE */
+ put_bits(&s->pb, 5, 31); /* dialog norm: -31 db */
+ put_bits(&s->pb, 1, 0); /* no compression control word */
+ put_bits(&s->pb, 1, 0); /* no lang code */
+ put_bits(&s->pb, 1, 0); /* no audio production info */
+ put_bits(&s->pb, 1, 0); /* no copyright */
+ put_bits(&s->pb, 1, 1); /* original bitstream */
+ put_bits(&s->pb, 1, 0); /* no time code 1 */
+ put_bits(&s->pb, 1, 0); /* no time code 2 */
+ put_bits(&s->pb, 1, 0); /* no addtional bit stream info */
+}
+
+/* symetric quantization on 'levels' levels */
+static inline int sym_quant(int c, int e, int levels)
+{
+ int v;
+
+ if (c >= 0) {
+ v = (levels * (c << e)) >> 24;
+ v = (v + 1) >> 1;
+ v = (levels >> 1) + v;
+ } else {
+ v = (levels * ((-c) << e)) >> 24;
+ v = (v + 1) >> 1;
+ v = (levels >> 1) - v;
+ }
+ assert (v >= 0 && v < levels);
+ return v;
+}
+
+/* asymetric quantization on 2^qbits levels */
+static inline int asym_quant(int c, int e, int qbits)
+{
+ int lshift, m, v;
+
+ lshift = e + qbits - 24;
+ if (lshift >= 0)
+ v = c << lshift;
+ else
+ v = c >> (-lshift);
+ /* rounding */
+ v = (v + 1) >> 1;
+ m = (1 << (qbits-1));
+ if (v >= m)
+ v = m - 1;
+ assert(v >= -m);
+ return v & ((1 << qbits)-1);
+}
+
+/* Output one audio block. There are NB_BLOCKS audio blocks in one AC3
+ frame */
+static void output_audio_block(AC3EncodeContext *s,
+ uint8_t exp_strategy[AC3_MAX_CHANNELS],
+ uint8_t encoded_exp[AC3_MAX_CHANNELS][N/2],
+ uint8_t bap[AC3_MAX_CHANNELS][N/2],
+ int32_t mdct_coefs[AC3_MAX_CHANNELS][N/2],
+ int8_t global_exp[AC3_MAX_CHANNELS],
+ int block_num)
+{
+ int ch, nb_groups, group_size, i, baie, rbnd;
+ uint8_t *p;
+ uint16_t qmant[AC3_MAX_CHANNELS][N/2];
+ int exp0, exp1;
+ int mant1_cnt, mant2_cnt, mant4_cnt;
+ uint16_t *qmant1_ptr, *qmant2_ptr, *qmant4_ptr;
+ int delta0, delta1, delta2;
+
+ for(ch=0;ch<s->nb_channels;ch++)
+ put_bits(&s->pb, 1, 0); /* 512 point MDCT */
+ for(ch=0;ch<s->nb_channels;ch++)
+ put_bits(&s->pb, 1, 1); /* no dither */
+ put_bits(&s->pb, 1, 0); /* no dynamic range */
+ if (block_num == 0) {
+ /* for block 0, even if no coupling, we must say it. This is a
+ waste of bit :-) */
+ put_bits(&s->pb, 1, 1); /* coupling strategy present */
+ put_bits(&s->pb, 1, 0); /* no coupling strategy */
+ } else {
+ put_bits(&s->pb, 1, 0); /* no new coupling strategy */
+ }
+
+ if (s->acmod == 2)
+ {
+ if(block_num==0)
+ {
+ /* first block must define rematrixing (rematstr) */
+ put_bits(&s->pb, 1, 1);
+
+ /* dummy rematrixing rematflg(1:4)=0 */
+ for (rbnd=0;rbnd<4;rbnd++)
+ put_bits(&s->pb, 1, 0);
+ }
+ else
+ {
+ /* no matrixing (but should be used in the future) */
+ put_bits(&s->pb, 1, 0);
+ }
+ }
+
+#if defined(DEBUG)
+ {
+ static int count = 0;
+ av_log(NULL, AV_LOG_DEBUG, "Block #%d (%d)\n", block_num, count++);
+ }
+#endif
+ /* exponent strategy */
+ for(ch=0;ch<s->nb_channels;ch++) {
+ put_bits(&s->pb, 2, exp_strategy[ch]);
+ }
+
+ if (s->lfe) {
+ put_bits(&s->pb, 1, exp_strategy[s->lfe_channel]);
+ }
+
+ for(ch=0;ch<s->nb_channels;ch++) {
+ if (exp_strategy[ch] != EXP_REUSE)
+ put_bits(&s->pb, 6, s->chbwcod[ch]);
+ }
+
+ /* exponents */
+ for (ch = 0; ch < s->nb_all_channels; ch++) {
+ switch(exp_strategy[ch]) {
+ case EXP_REUSE:
+ continue;
+ case EXP_D15:
+ group_size = 1;
+ break;
+ case EXP_D25:
+ group_size = 2;
+ break;
+ default:
+ case EXP_D45:
+ group_size = 4;
+ break;
+ }
+ nb_groups = (s->nb_coefs[ch] + (group_size * 3) - 4) / (3 * group_size);
+ p = encoded_exp[ch];
+
+ /* first exponent */
+ exp1 = *p++;
+ put_bits(&s->pb, 4, exp1);
+
+ /* next ones are delta encoded */
+ for(i=0;i<nb_groups;i++) {
+ /* merge three delta in one code */
+ exp0 = exp1;
+ exp1 = p[0];
+ p += group_size;
+ delta0 = exp1 - exp0 + 2;
+
+ exp0 = exp1;
+ exp1 = p[0];
+ p += group_size;
+ delta1 = exp1 - exp0 + 2;
+
+ exp0 = exp1;
+ exp1 = p[0];
+ p += group_size;
+ delta2 = exp1 - exp0 + 2;
+
+ put_bits(&s->pb, 7, ((delta0 * 5 + delta1) * 5) + delta2);
+ }
+
+ if (ch != s->lfe_channel)
+ put_bits(&s->pb, 2, 0); /* no gain range info */
+ }
+
+ /* bit allocation info */
+ baie = (block_num == 0);
+ put_bits(&s->pb, 1, baie);
+ if (baie) {
+ put_bits(&s->pb, 2, s->sdecaycod);
+ put_bits(&s->pb, 2, s->fdecaycod);
+ put_bits(&s->pb, 2, s->sgaincod);
+ put_bits(&s->pb, 2, s->dbkneecod);
+ put_bits(&s->pb, 3, s->floorcod);
+ }
+
+ /* snr offset */
+ put_bits(&s->pb, 1, baie); /* always present with bai */
+ if (baie) {
+ put_bits(&s->pb, 6, s->csnroffst);
+ for(ch=0;ch<s->nb_all_channels;ch++) {
+ put_bits(&s->pb, 4, s->fsnroffst[ch]);
+ put_bits(&s->pb, 3, s->fgaincod[ch]);
+ }
+ }
+
+ put_bits(&s->pb, 1, 0); /* no delta bit allocation */
+ put_bits(&s->pb, 1, 0); /* no data to skip */
+
+ /* mantissa encoding : we use two passes to handle the grouping. A
+ one pass method may be faster, but it would necessitate to
+ modify the output stream. */
+
+ /* first pass: quantize */
+ mant1_cnt = mant2_cnt = mant4_cnt = 0;
+ qmant1_ptr = qmant2_ptr = qmant4_ptr = NULL;
+
+ for (ch = 0; ch < s->nb_all_channels; ch++) {
+ int b, c, e, v;
+
+ for(i=0;i<s->nb_coefs[ch];i++) {
+ c = mdct_coefs[ch][i];
+ e = encoded_exp[ch][i] - global_exp[ch];
+ b = bap[ch][i];
+ switch(b) {
+ case 0:
+ v = 0;
+ break;
+ case 1:
+ v = sym_quant(c, e, 3);
+ switch(mant1_cnt) {
+ case 0:
+ qmant1_ptr = &qmant[ch][i];
+ v = 9 * v;
+ mant1_cnt = 1;
+ break;
+ case 1:
+ *qmant1_ptr += 3 * v;
+ mant1_cnt = 2;
+ v = 128;
+ break;
+ default:
+ *qmant1_ptr += v;
+ mant1_cnt = 0;
+ v = 128;
+ break;
+ }
+ break;
+ case 2:
+ v = sym_quant(c, e, 5);
+ switch(mant2_cnt) {
+ case 0:
+ qmant2_ptr = &qmant[ch][i];
+ v = 25 * v;
+ mant2_cnt = 1;
+ break;
+ case 1:
+ *qmant2_ptr += 5 * v;
+ mant2_cnt = 2;
+ v = 128;
+ break;
+ default:
+ *qmant2_ptr += v;
+ mant2_cnt = 0;
+ v = 128;
+ break;
+ }
+ break;
+ case 3:
+ v = sym_quant(c, e, 7);
+ break;
+ case 4:
+ v = sym_quant(c, e, 11);
+ switch(mant4_cnt) {
+ case 0:
+ qmant4_ptr = &qmant[ch][i];
+ v = 11 * v;
+ mant4_cnt = 1;
+ break;
+ default:
+ *qmant4_ptr += v;
+ mant4_cnt = 0;
+ v = 128;
+ break;
+ }
+ break;
+ case 5:
+ v = sym_quant(c, e, 15);
+ break;
+ case 14:
+ v = asym_quant(c, e, 14);
+ break;
+ case 15:
+ v = asym_quant(c, e, 16);
+ break;
+ default:
+ v = asym_quant(c, e, b - 1);
+ break;
+ }
+ qmant[ch][i] = v;
+ }
+ }
+
+ /* second pass : output the values */
+ for (ch = 0; ch < s->nb_all_channels; ch++) {
+ int b, q;
+
+ for(i=0;i<s->nb_coefs[ch];i++) {
+ q = qmant[ch][i];
+ b = bap[ch][i];
+ switch(b) {
+ case 0:
+ break;
+ case 1:
+ if (q != 128)
+ put_bits(&s->pb, 5, q);
+ break;
+ case 2:
+ if (q != 128)
+ put_bits(&s->pb, 7, q);
+ break;
+ case 3:
+ put_bits(&s->pb, 3, q);
+ break;
+ case 4:
+ if (q != 128)
+ put_bits(&s->pb, 7, q);
+ break;
+ case 14:
+ put_bits(&s->pb, 14, q);
+ break;
+ case 15:
+ put_bits(&s->pb, 16, q);
+ break;
+ default:
+ put_bits(&s->pb, b - 1, q);
+ break;
+ }
+ }
+ }
+}
+
+#define CRC16_POLY ((1 << 0) | (1 << 2) | (1 << 15) | (1 << 16))
+
+static unsigned int mul_poly(unsigned int a, unsigned int b, unsigned int poly)
+{
+ unsigned int c;
+
+ c = 0;
+ while (a) {
+ if (a & 1)
+ c ^= b;
+ a = a >> 1;
+ b = b << 1;
+ if (b & (1 << 16))
+ b ^= poly;
+ }
+ return c;
+}
+
+static unsigned int pow_poly(unsigned int a, unsigned int n, unsigned int poly)
+{
+ unsigned int r;
+ r = 1;
+ while (n) {
+ if (n & 1)
+ r = mul_poly(r, a, poly);
+ a = mul_poly(a, a, poly);
+ n >>= 1;
+ }
+ return r;
+}
+
+
+/* compute log2(max(abs(tab[]))) */
+static int log2_tab(int16_t *tab, int n)
+{
+ int i, v;
+
+ v = 0;
+ for(i=0;i<n;i++) {
+ v |= abs(tab[i]);
+ }
+ return av_log2(v);
+}
+
+static void lshift_tab(int16_t *tab, int n, int lshift)
+{
+ int i;
+
+ if (lshift > 0) {
+ for(i=0;i<n;i++) {
+ tab[i] <<= lshift;
+ }
+ } else if (lshift < 0) {
+ lshift = -lshift;
+ for(i=0;i<n;i++) {
+ tab[i] >>= lshift;
+ }
+ }
+}
+
+/* fill the end of the frame and compute the two crcs */
+static int output_frame_end(AC3EncodeContext *s)
+{
+ int frame_size, frame_size_58, n, crc1, crc2, crc_inv;
+ uint8_t *frame;
+
+ frame_size = s->frame_size; /* frame size in words */
+ /* align to 8 bits */
+ flush_put_bits(&s->pb);
+ /* add zero bytes to reach the frame size */
+ frame = s->pb.buf;
+ n = 2 * s->frame_size - (pbBufPtr(&s->pb) - frame) - 2;
+ assert(n >= 0);
+ if(n>0)
+ memset(pbBufPtr(&s->pb), 0, n);
+
+ /* Now we must compute both crcs : this is not so easy for crc1
+ because it is at the beginning of the data... */
+ frame_size_58 = (frame_size >> 1) + (frame_size >> 3);
+ crc1 = bswap_16(av_crc(av_crc8005, 0, frame + 4, 2 * frame_size_58 - 4));
+ /* XXX: could precompute crc_inv */
+ crc_inv = pow_poly((CRC16_POLY >> 1), (16 * frame_size_58) - 16, CRC16_POLY);
+ crc1 = mul_poly(crc_inv, crc1, CRC16_POLY);
+ frame[2] = crc1 >> 8;
+ frame[3] = crc1;
+
+ crc2 = bswap_16(av_crc(av_crc8005, 0, frame + 2 * frame_size_58, (frame_size - frame_size_58) * 2 - 2));
+ frame[2*frame_size - 2] = crc2 >> 8;
+ frame[2*frame_size - 1] = crc2;
+
+ // printf("n=%d frame_size=%d\n", n, frame_size);
+ return frame_size * 2;
+}
+
+static int AC3_encode_frame(AVCodecContext *avctx,
+ unsigned char *frame, int buf_size, void *data)
+{
+ AC3EncodeContext *s = avctx->priv_data;
+ int16_t *samples = data;
+ int i, j, k, v, ch;
+ int16_t input_samples[N];
+ int32_t mdct_coef[NB_BLOCKS][AC3_MAX_CHANNELS][N/2];
+ uint8_t exp[NB_BLOCKS][AC3_MAX_CHANNELS][N/2];
+ uint8_t exp_strategy[NB_BLOCKS][AC3_MAX_CHANNELS];
+ uint8_t encoded_exp[NB_BLOCKS][AC3_MAX_CHANNELS][N/2];
+ uint8_t bap[NB_BLOCKS][AC3_MAX_CHANNELS][N/2];
+ int8_t exp_samples[NB_BLOCKS][AC3_MAX_CHANNELS];
+ int frame_bits;
+
+ frame_bits = 0;
+ for(ch=0;ch<s->nb_all_channels;ch++) {
+ /* fixed mdct to the six sub blocks & exponent computation */
+ for(i=0;i<NB_BLOCKS;i++) {
+ int16_t *sptr;
+ int sinc;
+
+ /* compute input samples */
+ memcpy(input_samples, s->last_samples[ch], N/2 * sizeof(int16_t));
+ sinc = s->nb_all_channels;
+ sptr = samples + (sinc * (N/2) * i) + ch;
+ for(j=0;j<N/2;j++) {
+ v = *sptr;
+ input_samples[j + N/2] = v;
+ s->last_samples[ch][j] = v;
+ sptr += sinc;
+ }
+
+ /* apply the MDCT window */
+ for(j=0;j<N/2;j++) {
+ input_samples[j] = MUL16(input_samples[j],
+ ff_ac3_window[j]) >> 15;
+ input_samples[N-j-1] = MUL16(input_samples[N-j-1],
+ ff_ac3_window[j]) >> 15;
+ }
+
+ /* Normalize the samples to use the maximum available
+ precision */
+ v = 14 - log2_tab(input_samples, N);
+ if (v < 0)
+ v = 0;
+ exp_samples[i][ch] = v - 9;
+ lshift_tab(input_samples, N, v);
+
+ /* do the MDCT */
+ mdct512(mdct_coef[i][ch], input_samples);
+
+ /* compute "exponents". We take into account the
+ normalization there */
+ for(j=0;j<N/2;j++) {
+ int e;
+ v = abs(mdct_coef[i][ch][j]);
+ if (v == 0)
+ e = 24;
+ else {
+ e = 23 - av_log2(v) + exp_samples[i][ch];
+ if (e >= 24) {
+ e = 24;
+ mdct_coef[i][ch][j] = 0;
+ }
+ }
+ exp[i][ch][j] = e;
+ }
+ }
+
+ compute_exp_strategy(exp_strategy, exp, ch, ch == s->lfe_channel);
+
+ /* compute the exponents as the decoder will see them. The
+ EXP_REUSE case must be handled carefully : we select the
+ min of the exponents */
+ i = 0;
+ while (i < NB_BLOCKS) {
+ j = i + 1;
+ while (j < NB_BLOCKS && exp_strategy[j][ch] == EXP_REUSE) {
+ exponent_min(exp[i][ch], exp[j][ch], s->nb_coefs[ch]);
+ j++;
+ }
+ frame_bits += encode_exp(encoded_exp[i][ch],
+ exp[i][ch], s->nb_coefs[ch],
+ exp_strategy[i][ch]);
+ /* copy encoded exponents for reuse case */
+ for(k=i+1;k<j;k++) {
+ memcpy(encoded_exp[k][ch], encoded_exp[i][ch],
+ s->nb_coefs[ch] * sizeof(uint8_t));
+ }
+ i = j;
+ }
+ }
+
+ /* adjust for fractional frame sizes */
+ while(s->bits_written >= s->bit_rate*1000 && s->samples_written >= s->sample_rate) {
+ s->bits_written -= s->bit_rate*1000;
+ s->samples_written -= s->sample_rate;
+ }
+ s->frame_size = s->frame_size_min + (s->bits_written * s->sample_rate < s->samples_written * s->bit_rate*1000);
+ s->bits_written += s->frame_size * 16;
+ s->samples_written += AC3_FRAME_SIZE;
+
+ compute_bit_allocation(s, bap, encoded_exp, exp_strategy, frame_bits);
+ /* everything is known... let's output the frame */
+ output_frame_header(s, frame);
+
+ for(i=0;i<NB_BLOCKS;i++) {
+ output_audio_block(s, exp_strategy[i], encoded_exp[i],
+ bap[i], mdct_coef[i], exp_samples[i], i);
+ }
+ return output_frame_end(s);
+}
+
+static int AC3_encode_close(AVCodecContext *avctx)
+{
+ av_freep(&avctx->coded_frame);
+ return 0;
+}
+
+#if 0
+/*************************************************************************/
+/* TEST */
+
+#define FN (N/4)
+
+void fft_test(void)
+{
+ IComplex in[FN], in1[FN];
+ int k, n, i;
+ float sum_re, sum_im, a;
+
+ /* FFT test */
+
+ for(i=0;i<FN;i++) {
+ in[i].re = random() % 65535 - 32767;
+ in[i].im = random() % 65535 - 32767;
+ in1[i] = in[i];
+ }
+ fft(in, 7);
+
+ /* do it by hand */
+ for(k=0;k<FN;k++) {
+ sum_re = 0;
+ sum_im = 0;
+ for(n=0;n<FN;n++) {
+ a = -2 * M_PI * (n * k) / FN;
+ sum_re += in1[n].re * cos(a) - in1[n].im * sin(a);
+ sum_im += in1[n].re * sin(a) + in1[n].im * cos(a);
+ }
+ printf("%3d: %6d,%6d %6.0f,%6.0f\n",
+ k, in[k].re, in[k].im, sum_re / FN, sum_im / FN);
+ }
+}
+
+void mdct_test(void)
+{
+ int16_t input[N];
+ int32_t output[N/2];
+ float input1[N];
+ float output1[N/2];
+ float s, a, err, e, emax;
+ int i, k, n;
+
+ for(i=0;i<N;i++) {
+ input[i] = (random() % 65535 - 32767) * 9 / 10;
+ input1[i] = input[i];
+ }
+
+ mdct512(output, input);
+
+ /* do it by hand */
+ for(k=0;k<N/2;k++) {
+ s = 0;
+ for(n=0;n<N;n++) {
+ a = (2*M_PI*(2*n+1+N/2)*(2*k+1) / (4 * N));
+ s += input1[n] * cos(a);
+ }
+ output1[k] = -2 * s / N;
+ }
+
+ err = 0;
+ emax = 0;
+ for(i=0;i<N/2;i++) {
+ printf("%3d: %7d %7.0f\n", i, output[i], output1[i]);
+ e = output[i] - output1[i];
+ if (e > emax)
+ emax = e;
+ err += e * e;
+ }
+ printf("err2=%f emax=%f\n", err / (N/2), emax);
+}
+
+void test_ac3(void)
+{
+ AC3EncodeContext ctx;
+ unsigned char frame[AC3_MAX_CODED_FRAME_SIZE];
+ short samples[AC3_FRAME_SIZE];
+ int ret, i;
+
+ AC3_encode_init(&ctx, 44100, 64000, 1);
+
+ fft_test();
+ mdct_test();
+
+ for(i=0;i<AC3_FRAME_SIZE;i++)
+ samples[i] = (int)(sin(2*M_PI*i*1000.0/44100) * 10000);
+ ret = AC3_encode_frame(&ctx, frame, samples);
+ printf("ret=%d\n", ret);
+}
+#endif
+
+AVCodec ac3_encoder = {
+ "ac3",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_AC3,
+ sizeof(AC3EncodeContext),
+ AC3_encode_init,
+ AC3_encode_frame,
+ AC3_encode_close,
+ NULL,
+};
diff --git a/contrib/ffmpeg/libavcodec/ac3tab.h b/contrib/ffmpeg/libavcodec/ac3tab.h
new file mode 100644
index 000000000..b549c5ba9
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/ac3tab.h
@@ -0,0 +1,251 @@
+/*
+ * AC3 tables
+ * copyright (c) 2001 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 ac3tab.h
+ * tables taken directly from AC3 spec.
+ */
+
+/**
+ * Possible frame sizes.
+ * from ATSC A/52 Table 5.18 Frame Size Code Table.
+ */
+const uint16_t ff_ac3_frame_sizes[38][3] = {
+ { 64, 69, 96 },
+ { 64, 70, 96 },
+ { 80, 87, 120 },
+ { 80, 88, 120 },
+ { 96, 104, 144 },
+ { 96, 105, 144 },
+ { 112, 121, 168 },
+ { 112, 122, 168 },
+ { 128, 139, 192 },
+ { 128, 140, 192 },
+ { 160, 174, 240 },
+ { 160, 175, 240 },
+ { 192, 208, 288 },
+ { 192, 209, 288 },
+ { 224, 243, 336 },
+ { 224, 244, 336 },
+ { 256, 278, 384 },
+ { 256, 279, 384 },
+ { 320, 348, 480 },
+ { 320, 349, 480 },
+ { 384, 417, 576 },
+ { 384, 418, 576 },
+ { 448, 487, 672 },
+ { 448, 488, 672 },
+ { 512, 557, 768 },
+ { 512, 558, 768 },
+ { 640, 696, 960 },
+ { 640, 697, 960 },
+ { 768, 835, 1152 },
+ { 768, 836, 1152 },
+ { 896, 975, 1344 },
+ { 896, 976, 1344 },
+ { 1024, 1114, 1536 },
+ { 1024, 1115, 1536 },
+ { 1152, 1253, 1728 },
+ { 1152, 1254, 1728 },
+ { 1280, 1393, 1920 },
+ { 1280, 1394, 1920 },
+};
+
+/**
+ * Maps audio coding mode (acmod) to number of full-bandwidth channels.
+ * from ATSC A/52 Table 5.8 Audio Coding Mode
+ */
+const uint8_t ff_ac3_channels[8] = {
+ 2, 1, 2, 3, 3, 4, 4, 5
+};
+
+/* possible frequencies */
+const uint16_t ff_ac3_freqs[3] = { 48000, 44100, 32000 };
+
+/* possible bitrates */
+const uint16_t ff_ac3_bitratetab[19] = {
+ 32, 40, 48, 56, 64, 80, 96, 112, 128,
+ 160, 192, 224, 256, 320, 384, 448, 512, 576, 640
+};
+
+/* AC3 MDCT window */
+
+/* MDCT window */
+const int16_t ff_ac3_window[256] = {
+ 4, 7, 12, 16, 21, 28, 34, 42,
+ 51, 61, 72, 84, 97, 111, 127, 145,
+ 164, 184, 207, 231, 257, 285, 315, 347,
+ 382, 419, 458, 500, 544, 591, 641, 694,
+ 750, 810, 872, 937, 1007, 1079, 1155, 1235,
+ 1318, 1406, 1497, 1593, 1692, 1796, 1903, 2016,
+ 2132, 2253, 2379, 2509, 2644, 2783, 2927, 3076,
+ 3230, 3389, 3552, 3721, 3894, 4072, 4255, 4444,
+ 4637, 4835, 5038, 5246, 5459, 5677, 5899, 6127,
+ 6359, 6596, 6837, 7083, 7334, 7589, 7848, 8112,
+ 8380, 8652, 8927, 9207, 9491, 9778,10069,10363,
+10660,10960,11264,11570,11879,12190,12504,12820,
+13138,13458,13780,14103,14427,14753,15079,15407,
+15735,16063,16392,16720,17049,17377,17705,18032,
+18358,18683,19007,19330,19651,19970,20287,20602,
+20914,21225,21532,21837,22139,22438,22733,23025,
+23314,23599,23880,24157,24430,24699,24964,25225,
+25481,25732,25979,26221,26459,26691,26919,27142,
+27359,27572,27780,27983,28180,28373,28560,28742,
+28919,29091,29258,29420,29577,29729,29876,30018,
+30155,30288,30415,30538,30657,30771,30880,30985,
+31086,31182,31274,31363,31447,31528,31605,31678,
+31747,31814,31877,31936,31993,32046,32097,32145,
+32190,32232,32272,32310,32345,32378,32409,32438,
+32465,32490,32513,32535,32556,32574,32592,32608,
+32623,32636,32649,32661,32671,32681,32690,32698,
+32705,32712,32718,32724,32729,32733,32737,32741,
+32744,32747,32750,32752,32754,32756,32757,32759,
+32760,32761,32762,32763,32764,32764,32765,32765,
+32766,32766,32766,32766,32767,32767,32767,32767,
+32767,32767,32767,32767,32767,32767,32767,32767,
+32767,32767,32767,32767,32767,32767,32767,32767,
+};
+
+static uint8_t masktab[253];
+
+static const uint8_t latab[260]= {
+0x0040,0x003f,0x003e,0x003d,0x003c,0x003b,0x003a,0x0039,0x0038,0x0037,
+0x0036,0x0035,0x0034,0x0034,0x0033,0x0032,0x0031,0x0030,0x002f,0x002f,
+0x002e,0x002d,0x002c,0x002c,0x002b,0x002a,0x0029,0x0029,0x0028,0x0027,
+0x0026,0x0026,0x0025,0x0024,0x0024,0x0023,0x0023,0x0022,0x0021,0x0021,
+0x0020,0x0020,0x001f,0x001e,0x001e,0x001d,0x001d,0x001c,0x001c,0x001b,
+0x001b,0x001a,0x001a,0x0019,0x0019,0x0018,0x0018,0x0017,0x0017,0x0016,
+0x0016,0x0015,0x0015,0x0015,0x0014,0x0014,0x0013,0x0013,0x0013,0x0012,
+0x0012,0x0012,0x0011,0x0011,0x0011,0x0010,0x0010,0x0010,0x000f,0x000f,
+0x000f,0x000e,0x000e,0x000e,0x000d,0x000d,0x000d,0x000d,0x000c,0x000c,
+0x000c,0x000c,0x000b,0x000b,0x000b,0x000b,0x000a,0x000a,0x000a,0x000a,
+0x000a,0x0009,0x0009,0x0009,0x0009,0x0009,0x0008,0x0008,0x0008,0x0008,
+0x0008,0x0008,0x0007,0x0007,0x0007,0x0007,0x0007,0x0007,0x0006,0x0006,
+0x0006,0x0006,0x0006,0x0006,0x0006,0x0006,0x0005,0x0005,0x0005,0x0005,
+0x0005,0x0005,0x0005,0x0005,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,
+0x0004,0x0004,0x0004,0x0004,0x0004,0x0003,0x0003,0x0003,0x0003,0x0003,
+0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0002,
+0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,
+0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0001,0x0001,
+0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,
+0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,
+0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,
+0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
+0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
+0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
+0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
+0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
+};
+
+static const uint16_t hth[50][3]= {
+{ 0x04d0,0x04f0,0x0580 },
+{ 0x04d0,0x04f0,0x0580 },
+{ 0x0440,0x0460,0x04b0 },
+{ 0x0400,0x0410,0x0450 },
+{ 0x03e0,0x03e0,0x0420 },
+{ 0x03c0,0x03d0,0x03f0 },
+{ 0x03b0,0x03c0,0x03e0 },
+{ 0x03b0,0x03b0,0x03d0 },
+{ 0x03a0,0x03b0,0x03c0 },
+{ 0x03a0,0x03a0,0x03b0 },
+{ 0x03a0,0x03a0,0x03b0 },
+{ 0x03a0,0x03a0,0x03b0 },
+{ 0x03a0,0x03a0,0x03a0 },
+{ 0x0390,0x03a0,0x03a0 },
+{ 0x0390,0x0390,0x03a0 },
+{ 0x0390,0x0390,0x03a0 },
+{ 0x0380,0x0390,0x03a0 },
+{ 0x0380,0x0380,0x03a0 },
+{ 0x0370,0x0380,0x03a0 },
+{ 0x0370,0x0380,0x03a0 },
+{ 0x0360,0x0370,0x0390 },
+{ 0x0360,0x0370,0x0390 },
+{ 0x0350,0x0360,0x0390 },
+{ 0x0350,0x0360,0x0390 },
+{ 0x0340,0x0350,0x0380 },
+{ 0x0340,0x0350,0x0380 },
+{ 0x0330,0x0340,0x0380 },
+{ 0x0320,0x0340,0x0370 },
+{ 0x0310,0x0320,0x0360 },
+{ 0x0300,0x0310,0x0350 },
+{ 0x02f0,0x0300,0x0340 },
+{ 0x02f0,0x02f0,0x0330 },
+{ 0x02f0,0x02f0,0x0320 },
+{ 0x02f0,0x02f0,0x0310 },
+{ 0x0300,0x02f0,0x0300 },
+{ 0x0310,0x0300,0x02f0 },
+{ 0x0340,0x0320,0x02f0 },
+{ 0x0390,0x0350,0x02f0 },
+{ 0x03e0,0x0390,0x0300 },
+{ 0x0420,0x03e0,0x0310 },
+{ 0x0460,0x0420,0x0330 },
+{ 0x0490,0x0450,0x0350 },
+{ 0x04a0,0x04a0,0x03c0 },
+{ 0x0460,0x0490,0x0410 },
+{ 0x0440,0x0460,0x0470 },
+{ 0x0440,0x0440,0x04a0 },
+{ 0x0520,0x0480,0x0460 },
+{ 0x0800,0x0630,0x0440 },
+{ 0x0840,0x0840,0x0450 },
+{ 0x0840,0x0840,0x04e0 },
+};
+
+static const uint8_t baptab[64]= {
+ 0, 1, 1, 1, 1, 1, 2, 2, 3, 3,
+ 3, 4, 4, 5, 5, 6, 6, 6, 6, 7,
+ 7, 7, 7, 8, 8, 8, 8, 9, 9, 9,
+ 9, 10, 10, 10, 10, 11, 11, 11, 11, 12,
+ 12, 12, 12, 13, 13, 13, 13, 14, 14, 14,
+ 14, 14, 14, 14, 14, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15,
+};
+
+const uint8_t ff_sdecaytab[4]={
+ 0x0f, 0x11, 0x13, 0x15,
+};
+
+const uint8_t ff_fdecaytab[4]={
+ 0x3f, 0x53, 0x67, 0x7b,
+};
+
+const uint16_t ff_sgaintab[4]= {
+ 0x540, 0x4d8, 0x478, 0x410,
+};
+
+const uint16_t ff_dbkneetab[4]= {
+ 0x000, 0x700, 0x900, 0xb00,
+};
+
+const int16_t ff_floortab[8]= {
+ 0x2f0, 0x2b0, 0x270, 0x230, 0x1f0, 0x170, 0x0f0, 0xf800,
+};
+
+const uint16_t ff_fgaintab[8]= {
+ 0x080, 0x100, 0x180, 0x200, 0x280, 0x300, 0x380, 0x400,
+};
+
+static const uint8_t bndsz[50]={
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3,
+ 3, 6, 6, 6, 6, 6, 6, 12, 12, 12, 12, 24, 24, 24, 24, 24
+};
+
+static uint8_t bndtab[51];
diff --git a/contrib/ffmpeg/libavcodec/adpcm.c b/contrib/ffmpeg/libavcodec/adpcm.c
new file mode 100644
index 000000000..8800c3a20
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/adpcm.c
@@ -0,0 +1,1372 @@
+/*
+ * ADPCM codecs
+ * Copyright (c) 2001-2003 The ffmpeg Project
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include "avcodec.h"
+#include "bitstream.h"
+
+/**
+ * @file adpcm.c
+ * ADPCM codecs.
+ * First version by Francois Revol (revol@free.fr)
+ * Fringe ADPCM codecs (e.g., DK3, DK4, Westwood)
+ * by Mike Melanson (melanson@pcisys.net)
+ * CD-ROM XA ADPCM codec by BERO
+ * EA ADPCM decoder by Robin Kay (komadori@myrealbox.com)
+ *
+ * Features and limitations:
+ *
+ * Reference documents:
+ * http://www.pcisys.net/~melanson/codecs/simpleaudio.html
+ * http://www.geocities.com/SiliconValley/8682/aud3.txt
+ * http://openquicktime.sourceforge.net/plugins.htm
+ * XAnim sources (xa_codec.c) http://www.rasnaimaging.com/people/lapus/download.html
+ * http://www.cs.ucla.edu/~leec/mediabench/applications.html
+ * SoX source code http://home.sprynet.com/~cbagwell/sox.html
+ *
+ * CD-ROM XA:
+ * http://ku-www.ss.titech.ac.jp/~yatsushi/xaadpcm.html
+ * vagpack & depack http://homepages.compuserve.de/bITmASTER32/psx-index.html
+ * readstr http://www.geocities.co.jp/Playtown/2004/
+ */
+
+#define BLKSIZE 1024
+
+#define CLAMP_TO_SHORT(value) \
+if (value > 32767) \
+ value = 32767; \
+else if (value < -32768) \
+ value = -32768; \
+
+/* step_table[] and index_table[] are from the ADPCM reference source */
+/* This is the index table: */
+static const int index_table[16] = {
+ -1, -1, -1, -1, 2, 4, 6, 8,
+ -1, -1, -1, -1, 2, 4, 6, 8,
+};
+
+/**
+ * This is the step table. Note that many programs use slight deviations from
+ * this table, but such deviations are negligible:
+ */
+static const int step_table[89] = {
+ 7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
+ 19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
+ 50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
+ 130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
+ 337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
+ 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
+ 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
+ 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
+ 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
+};
+
+/* These are for MS-ADPCM */
+/* AdaptationTable[], AdaptCoeff1[], and AdaptCoeff2[] are from libsndfile */
+static const int AdaptationTable[] = {
+ 230, 230, 230, 230, 307, 409, 512, 614,
+ 768, 614, 512, 409, 307, 230, 230, 230
+};
+
+static const int AdaptCoeff1[] = {
+ 256, 512, 0, 192, 240, 460, 392
+};
+
+static const int AdaptCoeff2[] = {
+ 0, -256, 0, 64, 0, -208, -232
+};
+
+/* These are for CD-ROM XA ADPCM */
+static const int xa_adpcm_table[5][2] = {
+ { 0, 0 },
+ { 60, 0 },
+ { 115, -52 },
+ { 98, -55 },
+ { 122, -60 }
+};
+
+static const int ea_adpcm_table[] = {
+ 0, 240, 460, 392, 0, 0, -208, -220, 0, 1,
+ 3, 4, 7, 8, 10, 11, 0, -1, -3, -4
+};
+
+static const int ct_adpcm_table[8] = {
+ 0x00E6, 0x00E6, 0x00E6, 0x00E6,
+ 0x0133, 0x0199, 0x0200, 0x0266
+};
+
+// padded to zero where table size is less then 16
+static const int swf_index_tables[4][16] = {
+ /*2*/ { -1, 2 },
+ /*3*/ { -1, -1, 2, 4 },
+ /*4*/ { -1, -1, -1, -1, 2, 4, 6, 8 },
+ /*5*/ { -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16 }
+};
+
+static const int yamaha_indexscale[] = {
+ 230, 230, 230, 230, 307, 409, 512, 614,
+ 230, 230, 230, 230, 307, 409, 512, 614
+};
+
+static const int yamaha_difflookup[] = {
+ 1, 3, 5, 7, 9, 11, 13, 15,
+ -1, -3, -5, -7, -9, -11, -13, -15
+};
+
+/* end of tables */
+
+typedef struct ADPCMChannelStatus {
+ int predictor;
+ short int step_index;
+ int step;
+ /* for encoding */
+ int prev_sample;
+
+ /* MS version */
+ short sample1;
+ short sample2;
+ int coeff1;
+ int coeff2;
+ int idelta;
+} ADPCMChannelStatus;
+
+typedef struct ADPCMContext {
+ int channel; /* for stereo MOVs, decode left, then decode right, then tell it's decoded */
+ ADPCMChannelStatus status[2];
+ short sample_buffer[32]; /* hold left samples while waiting for right samples */
+} ADPCMContext;
+
+/* XXX: implement encoding */
+
+#ifdef CONFIG_ENCODERS
+static int adpcm_encode_init(AVCodecContext *avctx)
+{
+ if (avctx->channels > 2)
+ return -1; /* only stereo or mono =) */
+ switch(avctx->codec->id) {
+ case CODEC_ID_ADPCM_IMA_QT:
+ av_log(avctx, AV_LOG_ERROR, "ADPCM: codec adpcm_ima_qt unsupported for encoding !\n");
+ avctx->frame_size = 64; /* XXX: can multiple of avctx->channels * 64 (left and right blocks are interleaved) */
+ return -1;
+ break;
+ case CODEC_ID_ADPCM_IMA_WAV:
+ avctx->frame_size = (BLKSIZE - 4 * avctx->channels) * 8 / (4 * avctx->channels) + 1; /* each 16 bits sample gives one nibble */
+ /* and we have 4 bytes per channel overhead */
+ avctx->block_align = BLKSIZE;
+ /* seems frame_size isn't taken into account... have to buffer the samples :-( */
+ break;
+ case CODEC_ID_ADPCM_MS:
+ avctx->frame_size = (BLKSIZE - 7 * avctx->channels) * 2 / avctx->channels + 2; /* each 16 bits sample gives one nibble */
+ /* and we have 7 bytes per channel overhead */
+ avctx->block_align = BLKSIZE;
+ break;
+ case CODEC_ID_ADPCM_YAMAHA:
+ avctx->frame_size = BLKSIZE * avctx->channels;
+ avctx->block_align = BLKSIZE;
+ break;
+ default:
+ return -1;
+ break;
+ }
+
+ avctx->coded_frame= avcodec_alloc_frame();
+ avctx->coded_frame->key_frame= 1;
+
+ return 0;
+}
+
+static int adpcm_encode_close(AVCodecContext *avctx)
+{
+ av_freep(&avctx->coded_frame);
+
+ return 0;
+}
+
+
+static inline unsigned char adpcm_ima_compress_sample(ADPCMChannelStatus *c, short sample)
+{
+ int delta = sample - c->prev_sample;
+ int nibble = FFMIN(7, abs(delta)*4/step_table[c->step_index]) + (delta<0)*8;
+ c->prev_sample = c->prev_sample + ((step_table[c->step_index] * yamaha_difflookup[nibble]) / 8);
+ CLAMP_TO_SHORT(c->prev_sample);
+ c->step_index = av_clip(c->step_index + index_table[nibble], 0, 88);
+ return nibble;
+}
+
+static inline unsigned char adpcm_ms_compress_sample(ADPCMChannelStatus *c, short sample)
+{
+ int predictor, nibble, bias;
+
+ predictor = (((c->sample1) * (c->coeff1)) + ((c->sample2) * (c->coeff2))) / 256;
+
+ nibble= sample - predictor;
+ if(nibble>=0) bias= c->idelta/2;
+ else bias=-c->idelta/2;
+
+ nibble= (nibble + bias) / c->idelta;
+ nibble= av_clip(nibble, -8, 7)&0x0F;
+
+ predictor += (signed)((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->idelta;
+ CLAMP_TO_SHORT(predictor);
+
+ c->sample2 = c->sample1;
+ c->sample1 = predictor;
+
+ c->idelta = (AdaptationTable[(int)nibble] * c->idelta) >> 8;
+ if (c->idelta < 16) c->idelta = 16;
+
+ return nibble;
+}
+
+static inline unsigned char adpcm_yamaha_compress_sample(ADPCMChannelStatus *c, short sample)
+{
+ int nibble, delta;
+
+ if(!c->step) {
+ c->predictor = 0;
+ c->step = 127;
+ }
+
+ delta = sample - c->predictor;
+
+ nibble = FFMIN(7, abs(delta)*4/c->step) + (delta<0)*8;
+
+ c->predictor = c->predictor + ((c->step * yamaha_difflookup[nibble]) / 8);
+ CLAMP_TO_SHORT(c->predictor);
+ c->step = (c->step * yamaha_indexscale[nibble]) >> 8;
+ c->step = av_clip(c->step, 127, 24567);
+
+ return nibble;
+}
+
+typedef struct TrellisPath {
+ int nibble;
+ int prev;
+} TrellisPath;
+
+typedef struct TrellisNode {
+ uint32_t ssd;
+ int path;
+ int sample1;
+ int sample2;
+ int step;
+} TrellisNode;
+
+static void adpcm_compress_trellis(AVCodecContext *avctx, const short *samples,
+ uint8_t *dst, ADPCMChannelStatus *c, int n)
+{
+#define FREEZE_INTERVAL 128
+ //FIXME 6% faster if frontier is a compile-time constant
+ const int frontier = 1 << avctx->trellis;
+ const int stride = avctx->channels;
+ const int version = avctx->codec->id;
+ const int max_paths = frontier*FREEZE_INTERVAL;
+ TrellisPath paths[max_paths], *p;
+ TrellisNode node_buf[2][frontier];
+ TrellisNode *nodep_buf[2][frontier];
+ TrellisNode **nodes = nodep_buf[0]; // nodes[] is always sorted by .ssd
+ TrellisNode **nodes_next = nodep_buf[1];
+ int pathn = 0, froze = -1, i, j, k;
+
+ assert(!(max_paths&(max_paths-1)));
+
+ memset(nodep_buf, 0, sizeof(nodep_buf));
+ nodes[0] = &node_buf[1][0];
+ nodes[0]->ssd = 0;
+ nodes[0]->path = 0;
+ nodes[0]->step = c->step_index;
+ nodes[0]->sample1 = c->sample1;
+ nodes[0]->sample2 = c->sample2;
+ if(version == CODEC_ID_ADPCM_IMA_WAV)
+ nodes[0]->sample1 = c->prev_sample;
+ if(version == CODEC_ID_ADPCM_MS)
+ nodes[0]->step = c->idelta;
+ if(version == CODEC_ID_ADPCM_YAMAHA) {
+ if(c->step == 0) {
+ nodes[0]->step = 127;
+ nodes[0]->sample1 = 0;
+ } else {
+ nodes[0]->step = c->step;
+ nodes[0]->sample1 = c->predictor;
+ }
+ }
+
+ for(i=0; i<n; i++) {
+ TrellisNode *t = node_buf[i&1];
+ TrellisNode **u;
+ int sample = samples[i*stride];
+ memset(nodes_next, 0, frontier*sizeof(TrellisNode*));
+ for(j=0; j<frontier && nodes[j]; j++) {
+ // higher j have higher ssd already, so they're unlikely to use a suboptimal next sample too
+ const int range = (j < frontier/2) ? 1 : 0;
+ const int step = nodes[j]->step;
+ int nidx;
+ if(version == CODEC_ID_ADPCM_MS) {
+ const int predictor = ((nodes[j]->sample1 * c->coeff1) + (nodes[j]->sample2 * c->coeff2)) / 256;
+ const int div = (sample - predictor) / step;
+ const int nmin = av_clip(div-range, -8, 6);
+ const int nmax = av_clip(div+range, -7, 7);
+ for(nidx=nmin; nidx<=nmax; nidx++) {
+ const int nibble = nidx & 0xf;
+ int dec_sample = predictor + nidx * step;
+#define STORE_NODE(NAME, STEP_INDEX)\
+ int d;\
+ uint32_t ssd;\
+ CLAMP_TO_SHORT(dec_sample);\
+ d = sample - dec_sample;\
+ ssd = nodes[j]->ssd + d*d;\
+ if(nodes_next[frontier-1] && ssd >= nodes_next[frontier-1]->ssd)\
+ continue;\
+ /* Collapse any two states with the same previous sample value. \
+ * One could also distinguish states by step and by 2nd to last
+ * sample, but the effects of that are negligible. */\
+ for(k=0; k<frontier && nodes_next[k]; k++) {\
+ if(dec_sample == nodes_next[k]->sample1) {\
+ assert(ssd >= nodes_next[k]->ssd);\
+ goto next_##NAME;\
+ }\
+ }\
+ for(k=0; k<frontier; k++) {\
+ if(!nodes_next[k] || ssd < nodes_next[k]->ssd) {\
+ TrellisNode *u = nodes_next[frontier-1];\
+ if(!u) {\
+ assert(pathn < max_paths);\
+ u = t++;\
+ u->path = pathn++;\
+ }\
+ u->ssd = ssd;\
+ u->step = STEP_INDEX;\
+ u->sample2 = nodes[j]->sample1;\
+ u->sample1 = dec_sample;\
+ paths[u->path].nibble = nibble;\
+ paths[u->path].prev = nodes[j]->path;\
+ memmove(&nodes_next[k+1], &nodes_next[k], (frontier-k-1)*sizeof(TrellisNode*));\
+ nodes_next[k] = u;\
+ break;\
+ }\
+ }\
+ next_##NAME:;
+ STORE_NODE(ms, FFMAX(16, (AdaptationTable[nibble] * step) >> 8));
+ }
+ } else if(version == CODEC_ID_ADPCM_IMA_WAV) {
+#define LOOP_NODES(NAME, STEP_TABLE, STEP_INDEX)\
+ const int predictor = nodes[j]->sample1;\
+ const int div = (sample - predictor) * 4 / STEP_TABLE;\
+ int nmin = av_clip(div-range, -7, 6);\
+ int nmax = av_clip(div+range, -6, 7);\
+ if(nmin<=0) nmin--; /* distinguish -0 from +0 */\
+ if(nmax<0) nmax--;\
+ for(nidx=nmin; nidx<=nmax; nidx++) {\
+ const int nibble = nidx<0 ? 7-nidx : nidx;\
+ int dec_sample = predictor + (STEP_TABLE * yamaha_difflookup[nibble]) / 8;\
+ STORE_NODE(NAME, STEP_INDEX);\
+ }
+ LOOP_NODES(ima, step_table[step], av_clip(step + index_table[nibble], 0, 88));
+ } else { //CODEC_ID_ADPCM_YAMAHA
+ LOOP_NODES(yamaha, step, av_clip((step * yamaha_indexscale[nibble]) >> 8, 127, 24567));
+#undef LOOP_NODES
+#undef STORE_NODE
+ }
+ }
+
+ u = nodes;
+ nodes = nodes_next;
+ nodes_next = u;
+
+ // prevent overflow
+ if(nodes[0]->ssd > (1<<28)) {
+ for(j=1; j<frontier && nodes[j]; j++)
+ nodes[j]->ssd -= nodes[0]->ssd;
+ nodes[0]->ssd = 0;
+ }
+
+ // merge old paths to save memory
+ if(i == froze + FREEZE_INTERVAL) {
+ p = &paths[nodes[0]->path];
+ for(k=i; k>froze; k--) {
+ dst[k] = p->nibble;
+ p = &paths[p->prev];
+ }
+ froze = i;
+ pathn = 0;
+ // other nodes might use paths that don't coincide with the frozen one.
+ // checking which nodes do so is too slow, so just kill them all.
+ // this also slightly improves quality, but I don't know why.
+ memset(nodes+1, 0, (frontier-1)*sizeof(TrellisNode*));
+ }
+ }
+
+ p = &paths[nodes[0]->path];
+ for(i=n-1; i>froze; i--) {
+ dst[i] = p->nibble;
+ p = &paths[p->prev];
+ }
+
+ c->predictor = nodes[0]->sample1;
+ c->sample1 = nodes[0]->sample1;
+ c->sample2 = nodes[0]->sample2;
+ c->step_index = nodes[0]->step;
+ c->step = nodes[0]->step;
+ c->idelta = nodes[0]->step;
+}
+
+static int adpcm_encode_frame(AVCodecContext *avctx,
+ unsigned char *frame, int buf_size, void *data)
+{
+ int n, i, st;
+ short *samples;
+ unsigned char *dst;
+ ADPCMContext *c = avctx->priv_data;
+
+ dst = frame;
+ samples = (short *)data;
+ st= avctx->channels == 2;
+/* n = (BLKSIZE - 4 * avctx->channels) / (2 * 8 * avctx->channels); */
+
+ switch(avctx->codec->id) {
+ case CODEC_ID_ADPCM_IMA_QT: /* XXX: can't test until we get .mov writer */
+ break;
+ case CODEC_ID_ADPCM_IMA_WAV:
+ n = avctx->frame_size / 8;
+ c->status[0].prev_sample = (signed short)samples[0]; /* XXX */
+/* c->status[0].step_index = 0; *//* XXX: not sure how to init the state machine */
+ *dst++ = (c->status[0].prev_sample) & 0xFF; /* little endian */
+ *dst++ = (c->status[0].prev_sample >> 8) & 0xFF;
+ *dst++ = (unsigned char)c->status[0].step_index;
+ *dst++ = 0; /* unknown */
+ samples++;
+ if (avctx->channels == 2) {
+ c->status[1].prev_sample = (signed short)samples[1];
+/* c->status[1].step_index = 0; */
+ *dst++ = (c->status[1].prev_sample) & 0xFF;
+ *dst++ = (c->status[1].prev_sample >> 8) & 0xFF;
+ *dst++ = (unsigned char)c->status[1].step_index;
+ *dst++ = 0;
+ samples++;
+ }
+
+ /* stereo: 4 bytes (8 samples) for left, 4 bytes for right, 4 bytes left, ... */
+ if(avctx->trellis > 0) {
+ uint8_t buf[2][n*8];
+ adpcm_compress_trellis(avctx, samples, buf[0], &c->status[0], n*8);
+ if(avctx->channels == 2)
+ adpcm_compress_trellis(avctx, samples+1, buf[1], &c->status[1], n*8);
+ for(i=0; i<n; i++) {
+ *dst++ = buf[0][8*i+0] | (buf[0][8*i+1] << 4);
+ *dst++ = buf[0][8*i+2] | (buf[0][8*i+3] << 4);
+ *dst++ = buf[0][8*i+4] | (buf[0][8*i+5] << 4);
+ *dst++ = buf[0][8*i+6] | (buf[0][8*i+7] << 4);
+ if (avctx->channels == 2) {
+ *dst++ = buf[1][8*i+0] | (buf[1][8*i+1] << 4);
+ *dst++ = buf[1][8*i+2] | (buf[1][8*i+3] << 4);
+ *dst++ = buf[1][8*i+4] | (buf[1][8*i+5] << 4);
+ *dst++ = buf[1][8*i+6] | (buf[1][8*i+7] << 4);
+ }
+ }
+ } else
+ for (; n>0; n--) {
+ *dst = adpcm_ima_compress_sample(&c->status[0], samples[0]) & 0x0F;
+ *dst |= (adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels]) << 4) & 0xF0;
+ dst++;
+ *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 2]) & 0x0F;
+ *dst |= (adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 3]) << 4) & 0xF0;
+ dst++;
+ *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 4]) & 0x0F;
+ *dst |= (adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 5]) << 4) & 0xF0;
+ dst++;
+ *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 6]) & 0x0F;
+ *dst |= (adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 7]) << 4) & 0xF0;
+ dst++;
+ /* right channel */
+ if (avctx->channels == 2) {
+ *dst = adpcm_ima_compress_sample(&c->status[1], samples[1]);
+ *dst |= adpcm_ima_compress_sample(&c->status[1], samples[3]) << 4;
+ dst++;
+ *dst = adpcm_ima_compress_sample(&c->status[1], samples[5]);
+ *dst |= adpcm_ima_compress_sample(&c->status[1], samples[7]) << 4;
+ dst++;
+ *dst = adpcm_ima_compress_sample(&c->status[1], samples[9]);
+ *dst |= adpcm_ima_compress_sample(&c->status[1], samples[11]) << 4;
+ dst++;
+ *dst = adpcm_ima_compress_sample(&c->status[1], samples[13]);
+ *dst |= adpcm_ima_compress_sample(&c->status[1], samples[15]) << 4;
+ dst++;
+ }
+ samples += 8 * avctx->channels;
+ }
+ break;
+ case CODEC_ID_ADPCM_MS:
+ for(i=0; i<avctx->channels; i++){
+ int predictor=0;
+
+ *dst++ = predictor;
+ c->status[i].coeff1 = AdaptCoeff1[predictor];
+ c->status[i].coeff2 = AdaptCoeff2[predictor];
+ }
+ for(i=0; i<avctx->channels; i++){
+ if (c->status[i].idelta < 16)
+ c->status[i].idelta = 16;
+
+ *dst++ = c->status[i].idelta & 0xFF;
+ *dst++ = c->status[i].idelta >> 8;
+ }
+ for(i=0; i<avctx->channels; i++){
+ c->status[i].sample1= *samples++;
+
+ *dst++ = c->status[i].sample1 & 0xFF;
+ *dst++ = c->status[i].sample1 >> 8;
+ }
+ for(i=0; i<avctx->channels; i++){
+ c->status[i].sample2= *samples++;
+
+ *dst++ = c->status[i].sample2 & 0xFF;
+ *dst++ = c->status[i].sample2 >> 8;
+ }
+
+ if(avctx->trellis > 0) {
+ int n = avctx->block_align - 7*avctx->channels;
+ uint8_t buf[2][n];
+ if(avctx->channels == 1) {
+ n *= 2;
+ adpcm_compress_trellis(avctx, samples, buf[0], &c->status[0], n);
+ for(i=0; i<n; i+=2)
+ *dst++ = (buf[0][i] << 4) | buf[0][i+1];
+ } else {
+ adpcm_compress_trellis(avctx, samples, buf[0], &c->status[0], n);
+ adpcm_compress_trellis(avctx, samples+1, buf[1], &c->status[1], n);
+ for(i=0; i<n; i++)
+ *dst++ = (buf[0][i] << 4) | buf[1][i];
+ }
+ } else
+ for(i=7*avctx->channels; i<avctx->block_align; i++) {
+ int nibble;
+ nibble = adpcm_ms_compress_sample(&c->status[ 0], *samples++)<<4;
+ nibble|= adpcm_ms_compress_sample(&c->status[st], *samples++);
+ *dst++ = nibble;
+ }
+ break;
+ case CODEC_ID_ADPCM_YAMAHA:
+ n = avctx->frame_size / 2;
+ if(avctx->trellis > 0) {
+ uint8_t buf[2][n*2];
+ n *= 2;
+ if(avctx->channels == 1) {
+ adpcm_compress_trellis(avctx, samples, buf[0], &c->status[0], n);
+ for(i=0; i<n; i+=2)
+ *dst++ = buf[0][i] | (buf[0][i+1] << 4);
+ } else {
+ adpcm_compress_trellis(avctx, samples, buf[0], &c->status[0], n);
+ adpcm_compress_trellis(avctx, samples+1, buf[1], &c->status[1], n);
+ for(i=0; i<n; i++)
+ *dst++ = buf[0][i] | (buf[1][i] << 4);
+ }
+ } else
+ for (; n>0; n--) {
+ for(i = 0; i < avctx->channels; i++) {
+ int nibble;
+ nibble = adpcm_yamaha_compress_sample(&c->status[i], samples[i]);
+ nibble |= adpcm_yamaha_compress_sample(&c->status[i], samples[i+avctx->channels]) << 4;
+ *dst++ = nibble;
+ }
+ samples += 2 * avctx->channels;
+ }
+ break;
+ default:
+ return -1;
+ }
+ return dst - frame;
+}
+#endif //CONFIG_ENCODERS
+
+static int adpcm_decode_init(AVCodecContext * avctx)
+{
+ ADPCMContext *c = avctx->priv_data;
+
+ if(avctx->channels > 2U){
+ return -1;
+ }
+
+ c->channel = 0;
+ c->status[0].predictor = c->status[1].predictor = 0;
+ c->status[0].step_index = c->status[1].step_index = 0;
+ c->status[0].step = c->status[1].step = 0;
+
+ switch(avctx->codec->id) {
+ case CODEC_ID_ADPCM_CT:
+ c->status[0].step = c->status[1].step = 511;
+ break;
+ default:
+ break;
+ }
+ return 0;
+}
+
+static inline short adpcm_ima_expand_nibble(ADPCMChannelStatus *c, char nibble, int shift)
+{
+ int step_index;
+ int predictor;
+ int sign, delta, diff, step;
+
+ step = step_table[c->step_index];
+ step_index = c->step_index + index_table[(unsigned)nibble];
+ if (step_index < 0) step_index = 0;
+ else if (step_index > 88) step_index = 88;
+
+ sign = nibble & 8;
+ delta = nibble & 7;
+ /* perform direct multiplication instead of series of jumps proposed by
+ * the reference ADPCM implementation since modern CPUs can do the mults
+ * quickly enough */
+ diff = ((2 * delta + 1) * step) >> shift;
+ predictor = c->predictor;
+ if (sign) predictor -= diff;
+ else predictor += diff;
+
+ CLAMP_TO_SHORT(predictor);
+ c->predictor = predictor;
+ c->step_index = step_index;
+
+ return (short)predictor;
+}
+
+static inline short adpcm_ms_expand_nibble(ADPCMChannelStatus *c, char nibble)
+{
+ int predictor;
+
+ predictor = (((c->sample1) * (c->coeff1)) + ((c->sample2) * (c->coeff2))) / 256;
+ predictor += (signed)((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->idelta;
+ CLAMP_TO_SHORT(predictor);
+
+ c->sample2 = c->sample1;
+ c->sample1 = predictor;
+ c->idelta = (AdaptationTable[(int)nibble] * c->idelta) >> 8;
+ if (c->idelta < 16) c->idelta = 16;
+
+ return (short)predictor;
+}
+
+static inline short adpcm_ct_expand_nibble(ADPCMChannelStatus *c, char nibble)
+{
+ int predictor;
+ int sign, delta, diff;
+ int new_step;
+
+ sign = nibble & 8;
+ delta = nibble & 7;
+ /* perform direct multiplication instead of series of jumps proposed by
+ * the reference ADPCM implementation since modern CPUs can do the mults
+ * quickly enough */
+ diff = ((2 * delta + 1) * c->step) >> 3;
+ predictor = c->predictor;
+ /* predictor update is not so trivial: predictor is multiplied on 254/256 before updating */
+ if(sign)
+ predictor = ((predictor * 254) >> 8) - diff;
+ else
+ predictor = ((predictor * 254) >> 8) + diff;
+ /* calculate new step and clamp it to range 511..32767 */
+ new_step = (ct_adpcm_table[nibble & 7] * c->step) >> 8;
+ c->step = new_step;
+ if(c->step < 511)
+ c->step = 511;
+ if(c->step > 32767)
+ c->step = 32767;
+
+ CLAMP_TO_SHORT(predictor);
+ c->predictor = predictor;
+ return (short)predictor;
+}
+
+static inline short adpcm_sbpro_expand_nibble(ADPCMChannelStatus *c, char nibble, int size, int shift)
+{
+ int sign, delta, diff;
+
+ sign = nibble & (1<<(size-1));
+ delta = nibble & ((1<<(size-1))-1);
+ diff = delta << (7 + c->step + shift);
+
+ if (sign)
+ c->predictor -= diff;
+ else
+ c->predictor += diff;
+
+ /* clamp result */
+ if (c->predictor > 16256)
+ c->predictor = 16256;
+ else if (c->predictor < -16384)
+ c->predictor = -16384;
+
+ /* calculate new step */
+ if (delta >= (2*size - 3) && c->step < 3)
+ c->step++;
+ else if (delta == 0 && c->step > 0)
+ c->step--;
+
+ return (short) c->predictor;
+}
+
+static inline short adpcm_yamaha_expand_nibble(ADPCMChannelStatus *c, unsigned char nibble)
+{
+ if(!c->step) {
+ c->predictor = 0;
+ c->step = 127;
+ }
+
+ c->predictor += (c->step * yamaha_difflookup[nibble]) / 8;
+ CLAMP_TO_SHORT(c->predictor);
+ c->step = (c->step * yamaha_indexscale[nibble]) >> 8;
+ c->step = av_clip(c->step, 127, 24567);
+ return c->predictor;
+}
+
+static void xa_decode(short *out, const unsigned char *in,
+ ADPCMChannelStatus *left, ADPCMChannelStatus *right, int inc)
+{
+ int i, j;
+ int shift,filter,f0,f1;
+ int s_1,s_2;
+ int d,s,t;
+
+ for(i=0;i<4;i++) {
+
+ shift = 12 - (in[4+i*2] & 15);
+ filter = in[4+i*2] >> 4;
+ f0 = xa_adpcm_table[filter][0];
+ f1 = xa_adpcm_table[filter][1];
+
+ s_1 = left->sample1;
+ s_2 = left->sample2;
+
+ for(j=0;j<28;j++) {
+ d = in[16+i+j*4];
+
+ t = (signed char)(d<<4)>>4;
+ s = ( t<<shift ) + ((s_1*f0 + s_2*f1+32)>>6);
+ CLAMP_TO_SHORT(s);
+ *out = s;
+ out += inc;
+ s_2 = s_1;
+ s_1 = s;
+ }
+
+ if (inc==2) { /* stereo */
+ left->sample1 = s_1;
+ left->sample2 = s_2;
+ s_1 = right->sample1;
+ s_2 = right->sample2;
+ out = out + 1 - 28*2;
+ }
+
+ shift = 12 - (in[5+i*2] & 15);
+ filter = in[5+i*2] >> 4;
+
+ f0 = xa_adpcm_table[filter][0];
+ f1 = xa_adpcm_table[filter][1];
+
+ for(j=0;j<28;j++) {
+ d = in[16+i+j*4];
+
+ t = (signed char)d >> 4;
+ s = ( t<<shift ) + ((s_1*f0 + s_2*f1+32)>>6);
+ CLAMP_TO_SHORT(s);
+ *out = s;
+ out += inc;
+ s_2 = s_1;
+ s_1 = s;
+ }
+
+ if (inc==2) { /* stereo */
+ right->sample1 = s_1;
+ right->sample2 = s_2;
+ out -= 1;
+ } else {
+ left->sample1 = s_1;
+ left->sample2 = s_2;
+ }
+ }
+}
+
+
+/* DK3 ADPCM support macro */
+#define DK3_GET_NEXT_NIBBLE() \
+ if (decode_top_nibble_next) \
+ { \
+ nibble = (last_byte >> 4) & 0x0F; \
+ decode_top_nibble_next = 0; \
+ } \
+ else \
+ { \
+ last_byte = *src++; \
+ if (src >= buf + buf_size) break; \
+ nibble = last_byte & 0x0F; \
+ decode_top_nibble_next = 1; \
+ }
+
+static int adpcm_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ ADPCMContext *c = avctx->priv_data;
+ ADPCMChannelStatus *cs;
+ int n, m, channel, i;
+ int block_predictor[2];
+ short *samples;
+ short *samples_end;
+ uint8_t *src;
+ int st; /* stereo */
+
+ /* DK3 ADPCM accounting variables */
+ unsigned char last_byte = 0;
+ unsigned char nibble;
+ int decode_top_nibble_next = 0;
+ int diff_channel;
+
+ /* EA ADPCM state variables */
+ uint32_t samples_in_chunk;
+ int32_t previous_left_sample, previous_right_sample;
+ int32_t current_left_sample, current_right_sample;
+ int32_t next_left_sample, next_right_sample;
+ int32_t coeff1l, coeff2l, coeff1r, coeff2r;
+ uint8_t shift_left, shift_right;
+ int count1, count2;
+
+ if (!buf_size)
+ return 0;
+
+ //should protect all 4bit ADPCM variants
+ //8 is needed for CODEC_ID_ADPCM_IMA_WAV with 2 channels
+ //
+ if(*data_size/4 < buf_size + 8)
+ return -1;
+
+ samples = data;
+ samples_end= samples + *data_size/2;
+ *data_size= 0;
+ src = buf;
+
+ st = avctx->channels == 2 ? 1 : 0;
+
+ switch(avctx->codec->id) {
+ case CODEC_ID_ADPCM_IMA_QT:
+ n = (buf_size - 2);/* >> 2*avctx->channels;*/
+ channel = c->channel;
+ cs = &(c->status[channel]);
+ /* (pppppp) (piiiiiii) */
+
+ /* Bits 15-7 are the _top_ 9 bits of the 16-bit initial predictor value */
+ cs->predictor = (*src++) << 8;
+ cs->predictor |= (*src & 0x80);
+ cs->predictor &= 0xFF80;
+
+ /* sign extension */
+ if(cs->predictor & 0x8000)
+ cs->predictor -= 0x10000;
+
+ CLAMP_TO_SHORT(cs->predictor);
+
+ cs->step_index = (*src++) & 0x7F;
+
+ if (cs->step_index > 88){
+ av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n", cs->step_index);
+ cs->step_index = 88;
+ }
+
+ cs->step = step_table[cs->step_index];
+
+ if (st && channel)
+ samples++;
+
+ for(m=32; n>0 && m>0; n--, m--) { /* in QuickTime, IMA is encoded by chuncks of 34 bytes (=64 samples) */
+ *samples = adpcm_ima_expand_nibble(cs, src[0] & 0x0F, 3);
+ samples += avctx->channels;
+ *samples = adpcm_ima_expand_nibble(cs, (src[0] >> 4) & 0x0F, 3);
+ samples += avctx->channels;
+ src ++;
+ }
+
+ if(st) { /* handle stereo interlacing */
+ c->channel = (channel + 1) % 2; /* we get one packet for left, then one for right data */
+ if(channel == 1) { /* wait for the other packet before outputing anything */
+ return src - buf;
+ }
+ }
+ break;
+ case CODEC_ID_ADPCM_IMA_WAV:
+ if (avctx->block_align != 0 && buf_size > avctx->block_align)
+ buf_size = avctx->block_align;
+
+// samples_per_block= (block_align-4*chanels)*8 / (bits_per_sample * chanels) + 1;
+
+ for(i=0; i<avctx->channels; i++){
+ cs = &(c->status[i]);
+ cs->predictor = (int16_t)(src[0] + (src[1]<<8));
+ src+=2;
+
+ // XXX: is this correct ??: *samples++ = cs->predictor;
+
+ cs->step_index = *src++;
+ if (cs->step_index > 88){
+ av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n", cs->step_index);
+ cs->step_index = 88;
+ }
+ if (*src++) av_log(avctx, AV_LOG_ERROR, "unused byte should be null but is %d!!\n", src[-1]); /* unused */
+ }
+
+ while(src < buf + buf_size){
+ for(m=0; m<4; m++){
+ for(i=0; i<=st; i++)
+ *samples++ = adpcm_ima_expand_nibble(&c->status[i], src[4*i] & 0x0F, 3);
+ for(i=0; i<=st; i++)
+ *samples++ = adpcm_ima_expand_nibble(&c->status[i], src[4*i] >> 4 , 3);
+ src++;
+ }
+ src += 4*st;
+ }
+ break;
+ case CODEC_ID_ADPCM_4XM:
+ cs = &(c->status[0]);
+ c->status[0].predictor= (int16_t)(src[0] + (src[1]<<8)); src+=2;
+ if(st){
+ c->status[1].predictor= (int16_t)(src[0] + (src[1]<<8)); src+=2;
+ }
+ c->status[0].step_index= (int16_t)(src[0] + (src[1]<<8)); src+=2;
+ if(st){
+ c->status[1].step_index= (int16_t)(src[0] + (src[1]<<8)); src+=2;
+ }
+ if (cs->step_index < 0) cs->step_index = 0;
+ if (cs->step_index > 88) cs->step_index = 88;
+
+ m= (buf_size - (src - buf))>>st;
+ for(i=0; i<m; i++) {
+ *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[i] & 0x0F, 4);
+ if (st)
+ *samples++ = adpcm_ima_expand_nibble(&c->status[1], src[i+m] & 0x0F, 4);
+ *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[i] >> 4, 4);
+ if (st)
+ *samples++ = adpcm_ima_expand_nibble(&c->status[1], src[i+m] >> 4, 4);
+ }
+
+ src += m<<st;
+
+ break;
+ case CODEC_ID_ADPCM_MS:
+ if (avctx->block_align != 0 && buf_size > avctx->block_align)
+ buf_size = avctx->block_align;
+ n = buf_size - 7 * avctx->channels;
+ if (n < 0)
+ return -1;
+ block_predictor[0] = av_clip(*src++, 0, 7);
+ block_predictor[1] = 0;
+ if (st)
+ block_predictor[1] = av_clip(*src++, 0, 7);
+ c->status[0].idelta = (int16_t)((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
+ src+=2;
+ if (st){
+ c->status[1].idelta = (int16_t)((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
+ src+=2;
+ }
+ c->status[0].coeff1 = AdaptCoeff1[block_predictor[0]];
+ c->status[0].coeff2 = AdaptCoeff2[block_predictor[0]];
+ c->status[1].coeff1 = AdaptCoeff1[block_predictor[1]];
+ c->status[1].coeff2 = AdaptCoeff2[block_predictor[1]];
+
+ c->status[0].sample1 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
+ src+=2;
+ if (st) c->status[1].sample1 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
+ if (st) src+=2;
+ c->status[0].sample2 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
+ src+=2;
+ if (st) c->status[1].sample2 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
+ if (st) src+=2;
+
+ *samples++ = c->status[0].sample1;
+ if (st) *samples++ = c->status[1].sample1;
+ *samples++ = c->status[0].sample2;
+ if (st) *samples++ = c->status[1].sample2;
+ for(;n>0;n--) {
+ *samples++ = adpcm_ms_expand_nibble(&c->status[0], (src[0] >> 4) & 0x0F);
+ *samples++ = adpcm_ms_expand_nibble(&c->status[st], src[0] & 0x0F);
+ src ++;
+ }
+ break;
+ case CODEC_ID_ADPCM_IMA_DK4:
+ if (avctx->block_align != 0 && buf_size > avctx->block_align)
+ buf_size = avctx->block_align;
+
+ c->status[0].predictor = (int16_t)(src[0] | (src[1] << 8));
+ c->status[0].step_index = src[2];
+ src += 4;
+ *samples++ = c->status[0].predictor;
+ if (st) {
+ c->status[1].predictor = (int16_t)(src[0] | (src[1] << 8));
+ c->status[1].step_index = src[2];
+ src += 4;
+ *samples++ = c->status[1].predictor;
+ }
+ while (src < buf + buf_size) {
+
+ /* take care of the top nibble (always left or mono channel) */
+ *samples++ = adpcm_ima_expand_nibble(&c->status[0],
+ (src[0] >> 4) & 0x0F, 3);
+
+ /* take care of the bottom nibble, which is right sample for
+ * stereo, or another mono sample */
+ if (st)
+ *samples++ = adpcm_ima_expand_nibble(&c->status[1],
+ src[0] & 0x0F, 3);
+ else
+ *samples++ = adpcm_ima_expand_nibble(&c->status[0],
+ src[0] & 0x0F, 3);
+
+ src++;
+ }
+ break;
+ case CODEC_ID_ADPCM_IMA_DK3:
+ if (avctx->block_align != 0 && buf_size > avctx->block_align)
+ buf_size = avctx->block_align;
+
+ if(buf_size + 16 > (samples_end - samples)*3/8)
+ return -1;
+
+ c->status[0].predictor = (int16_t)(src[10] | (src[11] << 8));
+ c->status[1].predictor = (int16_t)(src[12] | (src[13] << 8));
+ c->status[0].step_index = src[14];
+ c->status[1].step_index = src[15];
+ /* sign extend the predictors */
+ src += 16;
+ diff_channel = c->status[1].predictor;
+
+ /* the DK3_GET_NEXT_NIBBLE macro issues the break statement when
+ * the buffer is consumed */
+ while (1) {
+
+ /* for this algorithm, c->status[0] is the sum channel and
+ * c->status[1] is the diff channel */
+
+ /* process the first predictor of the sum channel */
+ DK3_GET_NEXT_NIBBLE();
+ adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
+
+ /* process the diff channel predictor */
+ DK3_GET_NEXT_NIBBLE();
+ adpcm_ima_expand_nibble(&c->status[1], nibble, 3);
+
+ /* process the first pair of stereo PCM samples */
+ diff_channel = (diff_channel + c->status[1].predictor) / 2;
+ *samples++ = c->status[0].predictor + c->status[1].predictor;
+ *samples++ = c->status[0].predictor - c->status[1].predictor;
+
+ /* process the second predictor of the sum channel */
+ DK3_GET_NEXT_NIBBLE();
+ adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
+
+ /* process the second pair of stereo PCM samples */
+ diff_channel = (diff_channel + c->status[1].predictor) / 2;
+ *samples++ = c->status[0].predictor + c->status[1].predictor;
+ *samples++ = c->status[0].predictor - c->status[1].predictor;
+ }
+ break;
+ case CODEC_ID_ADPCM_IMA_WS:
+ /* no per-block initialization; just start decoding the data */
+ while (src < buf + buf_size) {
+
+ if (st) {
+ *samples++ = adpcm_ima_expand_nibble(&c->status[0],
+ (src[0] >> 4) & 0x0F, 3);
+ *samples++ = adpcm_ima_expand_nibble(&c->status[1],
+ src[0] & 0x0F, 3);
+ } else {
+ *samples++ = adpcm_ima_expand_nibble(&c->status[0],
+ (src[0] >> 4) & 0x0F, 3);
+ *samples++ = adpcm_ima_expand_nibble(&c->status[0],
+ src[0] & 0x0F, 3);
+ }
+
+ src++;
+ }
+ break;
+ case CODEC_ID_ADPCM_XA:
+ c->status[0].sample1 = c->status[0].sample2 =
+ c->status[1].sample1 = c->status[1].sample2 = 0;
+ while (buf_size >= 128) {
+ xa_decode(samples, src, &c->status[0], &c->status[1],
+ avctx->channels);
+ src += 128;
+ samples += 28 * 8;
+ buf_size -= 128;
+ }
+ break;
+ case CODEC_ID_ADPCM_EA:
+ samples_in_chunk = AV_RL32(src);
+ if (samples_in_chunk >= ((buf_size - 12) * 2)) {
+ src += buf_size;
+ break;
+ }
+ src += 4;
+ current_left_sample = (int16_t)AV_RL16(src);
+ src += 2;
+ previous_left_sample = (int16_t)AV_RL16(src);
+ src += 2;
+ current_right_sample = (int16_t)AV_RL16(src);
+ src += 2;
+ previous_right_sample = (int16_t)AV_RL16(src);
+ src += 2;
+
+ for (count1 = 0; count1 < samples_in_chunk/28;count1++) {
+ coeff1l = ea_adpcm_table[(*src >> 4) & 0x0F];
+ coeff2l = ea_adpcm_table[((*src >> 4) & 0x0F) + 4];
+ coeff1r = ea_adpcm_table[*src & 0x0F];
+ coeff2r = ea_adpcm_table[(*src & 0x0F) + 4];
+ src++;
+
+ shift_left = ((*src >> 4) & 0x0F) + 8;
+ shift_right = (*src & 0x0F) + 8;
+ src++;
+
+ for (count2 = 0; count2 < 28; count2++) {
+ next_left_sample = (((*src & 0xF0) << 24) >> shift_left);
+ next_right_sample = (((*src & 0x0F) << 28) >> shift_right);
+ src++;
+
+ next_left_sample = (next_left_sample +
+ (current_left_sample * coeff1l) +
+ (previous_left_sample * coeff2l) + 0x80) >> 8;
+ next_right_sample = (next_right_sample +
+ (current_right_sample * coeff1r) +
+ (previous_right_sample * coeff2r) + 0x80) >> 8;
+ CLAMP_TO_SHORT(next_left_sample);
+ CLAMP_TO_SHORT(next_right_sample);
+
+ previous_left_sample = current_left_sample;
+ current_left_sample = next_left_sample;
+ previous_right_sample = current_right_sample;
+ current_right_sample = next_right_sample;
+ *samples++ = (unsigned short)current_left_sample;
+ *samples++ = (unsigned short)current_right_sample;
+ }
+ }
+ break;
+ case CODEC_ID_ADPCM_IMA_SMJPEG:
+ c->status[0].predictor = *src;
+ src += 2;
+ c->status[0].step_index = *src++;
+ src++; /* skip another byte before getting to the meat */
+ while (src < buf + buf_size) {
+ *samples++ = adpcm_ima_expand_nibble(&c->status[0],
+ *src & 0x0F, 3);
+ *samples++ = adpcm_ima_expand_nibble(&c->status[0],
+ (*src >> 4) & 0x0F, 3);
+ src++;
+ }
+ break;
+ case CODEC_ID_ADPCM_CT:
+ while (src < buf + buf_size) {
+ if (st) {
+ *samples++ = adpcm_ct_expand_nibble(&c->status[0],
+ (src[0] >> 4) & 0x0F);
+ *samples++ = adpcm_ct_expand_nibble(&c->status[1],
+ src[0] & 0x0F);
+ } else {
+ *samples++ = adpcm_ct_expand_nibble(&c->status[0],
+ (src[0] >> 4) & 0x0F);
+ *samples++ = adpcm_ct_expand_nibble(&c->status[0],
+ src[0] & 0x0F);
+ }
+ src++;
+ }
+ break;
+ case CODEC_ID_ADPCM_SBPRO_4:
+ case CODEC_ID_ADPCM_SBPRO_3:
+ case CODEC_ID_ADPCM_SBPRO_2:
+ if (!c->status[0].step_index) {
+ /* the first byte is a raw sample */
+ *samples++ = 128 * (*src++ - 0x80);
+ if (st)
+ *samples++ = 128 * (*src++ - 0x80);
+ c->status[0].step_index = 1;
+ }
+ if (avctx->codec->id == CODEC_ID_ADPCM_SBPRO_4) {
+ while (src < buf + buf_size) {
+ *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
+ (src[0] >> 4) & 0x0F, 4, 0);
+ *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
+ src[0] & 0x0F, 4, 0);
+ src++;
+ }
+ } else if (avctx->codec->id == CODEC_ID_ADPCM_SBPRO_3) {
+ while (src < buf + buf_size && samples + 2 < samples_end) {
+ *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
+ (src[0] >> 5) & 0x07, 3, 0);
+ *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
+ (src[0] >> 2) & 0x07, 3, 0);
+ *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
+ src[0] & 0x03, 2, 0);
+ src++;
+ }
+ } else {
+ while (src < buf + buf_size && samples + 3 < samples_end) {
+ *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
+ (src[0] >> 6) & 0x03, 2, 2);
+ *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
+ (src[0] >> 4) & 0x03, 2, 2);
+ *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
+ (src[0] >> 2) & 0x03, 2, 2);
+ *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
+ src[0] & 0x03, 2, 2);
+ src++;
+ }
+ }
+ break;
+ case CODEC_ID_ADPCM_SWF:
+ {
+ GetBitContext gb;
+ const int *table;
+ int k0, signmask, nb_bits;
+ int size = buf_size*8;
+
+ init_get_bits(&gb, buf, size);
+
+ //read bits & inital values
+ nb_bits = get_bits(&gb, 2)+2;
+ //av_log(NULL,AV_LOG_INFO,"nb_bits: %d\n", nb_bits);
+ table = swf_index_tables[nb_bits-2];
+ k0 = 1 << (nb_bits-2);
+ signmask = 1 << (nb_bits-1);
+
+ for (i = 0; i < avctx->channels; i++) {
+ *samples++ = c->status[i].predictor = get_sbits(&gb, 16);
+ c->status[i].step_index = get_bits(&gb, 6);
+ }
+
+ while (get_bits_count(&gb) < size)
+ {
+ int i;
+
+ for (i = 0; i < avctx->channels; i++) {
+ // similar to IMA adpcm
+ int delta = get_bits(&gb, nb_bits);
+ int step = step_table[c->status[i].step_index];
+ long vpdiff = 0; // vpdiff = (delta+0.5)*step/4
+ int k = k0;
+
+ do {
+ if (delta & k)
+ vpdiff += step;
+ step >>= 1;
+ k >>= 1;
+ } while(k);
+ vpdiff += step;
+
+ if (delta & signmask)
+ c->status[i].predictor -= vpdiff;
+ else
+ c->status[i].predictor += vpdiff;
+
+ c->status[i].step_index += table[delta & (~signmask)];
+
+ c->status[i].step_index = av_clip(c->status[i].step_index, 0, 88);
+ c->status[i].predictor = av_clip(c->status[i].predictor, -32768, 32767);
+
+ *samples++ = c->status[i].predictor;
+ if (samples >= samples_end) {
+ av_log(avctx, AV_LOG_ERROR, "allocated output buffer is too small\n");
+ return -1;
+ }
+ }
+ }
+ src += buf_size;
+ break;
+ }
+ case CODEC_ID_ADPCM_YAMAHA:
+ while (src < buf + buf_size) {
+ if (st) {
+ *samples++ = adpcm_yamaha_expand_nibble(&c->status[0],
+ src[0] & 0x0F);
+ *samples++ = adpcm_yamaha_expand_nibble(&c->status[1],
+ (src[0] >> 4) & 0x0F);
+ } else {
+ *samples++ = adpcm_yamaha_expand_nibble(&c->status[0],
+ src[0] & 0x0F);
+ *samples++ = adpcm_yamaha_expand_nibble(&c->status[0],
+ (src[0] >> 4) & 0x0F);
+ }
+ src++;
+ }
+ break;
+ default:
+ return -1;
+ }
+ *data_size = (uint8_t *)samples - (uint8_t *)data;
+ return src - buf;
+}
+
+
+
+#ifdef CONFIG_ENCODERS
+#define ADPCM_ENCODER(id,name) \
+AVCodec name ## _encoder = { \
+ #name, \
+ CODEC_TYPE_AUDIO, \
+ id, \
+ sizeof(ADPCMContext), \
+ adpcm_encode_init, \
+ adpcm_encode_frame, \
+ adpcm_encode_close, \
+ NULL, \
+};
+#else
+#define ADPCM_ENCODER(id,name)
+#endif
+
+#ifdef CONFIG_DECODERS
+#define ADPCM_DECODER(id,name) \
+AVCodec name ## _decoder = { \
+ #name, \
+ CODEC_TYPE_AUDIO, \
+ id, \
+ sizeof(ADPCMContext), \
+ adpcm_decode_init, \
+ NULL, \
+ NULL, \
+ adpcm_decode_frame, \
+};
+#else
+#define ADPCM_DECODER(id,name)
+#endif
+
+#define ADPCM_CODEC(id, name) \
+ADPCM_ENCODER(id,name) ADPCM_DECODER(id,name)
+
+ADPCM_CODEC(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt);
+ADPCM_CODEC(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav);
+ADPCM_CODEC(CODEC_ID_ADPCM_IMA_DK3, adpcm_ima_dk3);
+ADPCM_CODEC(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4);
+ADPCM_CODEC(CODEC_ID_ADPCM_IMA_WS, adpcm_ima_ws);
+ADPCM_CODEC(CODEC_ID_ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg);
+ADPCM_CODEC(CODEC_ID_ADPCM_MS, adpcm_ms);
+ADPCM_CODEC(CODEC_ID_ADPCM_4XM, adpcm_4xm);
+ADPCM_CODEC(CODEC_ID_ADPCM_XA, adpcm_xa);
+ADPCM_CODEC(CODEC_ID_ADPCM_EA, adpcm_ea);
+ADPCM_CODEC(CODEC_ID_ADPCM_CT, adpcm_ct);
+ADPCM_CODEC(CODEC_ID_ADPCM_SWF, adpcm_swf);
+ADPCM_CODEC(CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha);
+ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_4, adpcm_sbpro_4);
+ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_3, adpcm_sbpro_3);
+ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_2, adpcm_sbpro_2);
+
+#undef ADPCM_CODEC
diff --git a/src/libffmpeg/libavcodec/adx.c b/contrib/ffmpeg/libavcodec/adx.c
index b449c9124..b449c9124 100644
--- a/src/libffmpeg/libavcodec/adx.c
+++ b/contrib/ffmpeg/libavcodec/adx.c
diff --git a/src/libffmpeg/libavcodec/alac.c b/contrib/ffmpeg/libavcodec/alac.c
index cc87c81e5..cc87c81e5 100644
--- a/src/libffmpeg/libavcodec/alac.c
+++ b/contrib/ffmpeg/libavcodec/alac.c
diff --git a/contrib/ffmpeg/libavcodec/allcodecs.c b/contrib/ffmpeg/libavcodec/allcodecs.c
new file mode 100644
index 000000000..b247cbe34
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/allcodecs.c
@@ -0,0 +1,277 @@
+/*
+ * Provides registration of all codecs, parsers and bitstream filters for libavcodec.
+ * 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 allcodecs.c
+ * Provides registration of all codecs, parsers and bitstream filters for libavcodec.
+ */
+
+#include "avcodec.h"
+
+#define REGISTER_ENCODER(X,x) \
+ if(ENABLE_##X##_ENCODER) register_avcodec(&x##_encoder)
+#define REGISTER_DECODER(X,x) \
+ if(ENABLE_##X##_DECODER) register_avcodec(&x##_decoder)
+#define REGISTER_ENCDEC(X,x) REGISTER_ENCODER(X,x); REGISTER_DECODER(X,x)
+
+#define REGISTER_PARSER(X,x) \
+ if(ENABLE_##X##_PARSER) av_register_codec_parser(&x##_parser)
+
+/**
+ * Register all the codecs, parsers and bitstream filters which were enabled at
+ * configuration time. If you do not call this function you can select exactly
+ * which formats you want to support, by using the individual registration
+ * functions.
+ *
+ * @see register_avcodec
+ * @see av_register_codec_parser
+ * @see av_register_bitstream_filter
+ */
+void avcodec_register_all(void)
+{
+ static int inited = 0;
+
+ if (inited != 0)
+ return;
+ inited = 1;
+
+ /* video codecs */
+ REGISTER_DECODER(AASC, aasc);
+ REGISTER_ENCDEC (ASV1, asv1);
+ REGISTER_ENCDEC (ASV2, asv2);
+ REGISTER_DECODER(AVS, avs);
+ REGISTER_ENCDEC (BMP, bmp);
+ REGISTER_DECODER(CAVS, cavs);
+ REGISTER_DECODER(CINEPAK, cinepak);
+ REGISTER_DECODER(CLJR, cljr);
+ REGISTER_DECODER(CSCD, cscd);
+ REGISTER_DECODER(CYUV, cyuv);
+ REGISTER_DECODER(DCA, dca);
+ REGISTER_DECODER(DNXHD, dnxhd);
+ REGISTER_DECODER(DSICINVIDEO, dsicinvideo);
+ REGISTER_ENCDEC (DVVIDEO, dvvideo);
+ REGISTER_DECODER(DXA, dxa);
+ REGISTER_DECODER(EIGHTBPS, eightbps);
+ REGISTER_ENCDEC (FFV1, ffv1);
+ REGISTER_ENCDEC (FFVHUFF, ffvhuff);
+ REGISTER_ENCDEC (FLASHSV, flashsv);
+ REGISTER_DECODER(FLIC, flic);
+ REGISTER_ENCDEC (FLV, flv);
+ REGISTER_DECODER(FOURXM, fourxm);
+ REGISTER_DECODER(FRAPS, fraps);
+ REGISTER_ENCDEC (GIF, gif);
+ REGISTER_ENCDEC (H261, h261);
+ REGISTER_ENCDEC (H263, h263);
+ REGISTER_DECODER(H263I, h263i);
+ REGISTER_ENCODER(H263P, h263p);
+ REGISTER_DECODER(H264, h264);
+ REGISTER_ENCDEC (HUFFYUV, huffyuv);
+ REGISTER_DECODER(IDCIN, idcin);
+ REGISTER_DECODER(INDEO2, indeo2);
+ REGISTER_DECODER(INDEO3, indeo3);
+ REGISTER_DECODER(INTERPLAY_VIDEO, interplay_video);
+ REGISTER_ENCODER(JPEGLS, jpegls);
+ REGISTER_DECODER(KMVC, kmvc);
+ REGISTER_ENCODER(LJPEG, ljpeg);
+ REGISTER_DECODER(LOCO, loco);
+ REGISTER_DECODER(MDEC, mdec);
+ REGISTER_ENCDEC (MJPEG, mjpeg);
+ REGISTER_DECODER(MJPEGB, mjpegb);
+ REGISTER_DECODER(MMVIDEO, mmvideo);
+ REGISTER_DECODER(MPEG_XVMC, mpeg_xvmc);
+ REGISTER_ENCDEC (MPEG1VIDEO, mpeg1video);
+ REGISTER_ENCDEC (MPEG2VIDEO, mpeg2video);
+ REGISTER_ENCDEC (MPEG4, mpeg4);
+ REGISTER_DECODER(MPEGVIDEO, mpegvideo);
+ REGISTER_ENCDEC (MSMPEG4V1, msmpeg4v1);
+ REGISTER_ENCDEC (MSMPEG4V2, msmpeg4v2);
+ REGISTER_ENCDEC (MSMPEG4V3, msmpeg4v3);
+ REGISTER_DECODER(MSRLE, msrle);
+ REGISTER_DECODER(MSVIDEO1, msvideo1);
+ REGISTER_DECODER(MSZH, mszh);
+ REGISTER_DECODER(NUV, nuv);
+ REGISTER_ENCODER(PAM, pam);
+ REGISTER_ENCODER(PBM, pbm);
+ REGISTER_ENCODER(PGM, pgm);
+ REGISTER_ENCODER(PGMYUV, pgmyuv);
+ REGISTER_ENCDEC (PNG, png);
+ REGISTER_ENCODER(PPM, ppm);
+ REGISTER_DECODER(QDRAW, qdraw);
+ REGISTER_DECODER(QPEG, qpeg);
+ REGISTER_DECODER(QTRLE, qtrle);
+ REGISTER_ENCDEC (RAWVIDEO, rawvideo);
+ REGISTER_DECODER(ROQ, roq);
+ REGISTER_DECODER(RPZA, rpza);
+ REGISTER_ENCDEC (RV10, rv10);
+ REGISTER_ENCDEC (RV20, rv20);
+ REGISTER_DECODER(SMACKER, smacker);
+ REGISTER_DECODER(SMC, smc);
+ REGISTER_ENCDEC (SNOW, snow);
+ REGISTER_DECODER(SP5X, sp5x);
+ REGISTER_ENCDEC (SVQ1, svq1);
+ REGISTER_DECODER(SVQ3, svq3);
+ REGISTER_ENCDEC (TARGA, targa);
+ REGISTER_DECODER(THEORA, theora);
+ REGISTER_DECODER(THP, thp);
+ REGISTER_DECODER(TIERTEXSEQVIDEO, tiertexseqvideo);
+ REGISTER_DECODER(TIFF, tiff);
+ REGISTER_DECODER(TRUEMOTION1, truemotion1);
+ REGISTER_DECODER(TRUEMOTION2, truemotion2);
+ REGISTER_DECODER(TSCC, tscc);
+ REGISTER_DECODER(ULTI, ulti);
+ REGISTER_DECODER(VC1, vc1);
+ REGISTER_DECODER(VCR1, vcr1);
+ REGISTER_DECODER(VMDVIDEO, vmdvideo);
+ REGISTER_DECODER(VMNC, vmnc);
+ REGISTER_DECODER(VP3, vp3);
+ REGISTER_DECODER(VP5, vp5);
+ REGISTER_DECODER(VP6, vp6);
+ REGISTER_DECODER(VP6F, vp6f);
+ REGISTER_DECODER(VQA, vqa);
+ REGISTER_ENCDEC (WMV1, wmv1);
+ REGISTER_ENCDEC (WMV2, wmv2);
+ REGISTER_DECODER(WMV3, wmv3);
+ REGISTER_DECODER(WNV1, wnv1);
+ REGISTER_ENCODER(X264, x264);
+ REGISTER_DECODER(XAN_WC3, xan_wc3);
+ REGISTER_DECODER(XL, xl);
+ REGISTER_ENCODER(XVID, xvid);
+ REGISTER_ENCDEC (ZLIB, zlib);
+ REGISTER_ENCDEC (ZMBV, zmbv);
+
+ /* audio codecs */
+ REGISTER_DECODER(AAC, aac);
+ REGISTER_DECODER(MPEG4AAC, mpeg4aac);
+ REGISTER_ENCODER(AC3, ac3);
+ REGISTER_DECODER(ALAC, alac);
+ REGISTER_ENCDEC (AMR_NB, amr_nb);
+ REGISTER_ENCDEC (AMR_WB, amr_wb);
+ REGISTER_DECODER(COOK, cook);
+ REGISTER_DECODER(DSICINAUDIO, dsicinaudio);
+ REGISTER_DECODER(DTS, dts);
+ REGISTER_ENCODER(FAAC, faac);
+ REGISTER_ENCDEC (FLAC, flac);
+ REGISTER_DECODER(IMC, imc);
+ REGISTER_DECODER(LIBA52, liba52);
+ REGISTER_ENCDEC (LIBGSM, libgsm);
+ REGISTER_ENCDEC (LIBGSM_MS, libgsm_ms);
+ REGISTER_ENCODER(LIBTHEORA, libtheora);
+ REGISTER_DECODER(MACE3, mace3);
+ REGISTER_DECODER(MACE6, mace6);
+ REGISTER_ENCDEC (MP2, mp2);
+ REGISTER_DECODER(MP3, mp3);
+ REGISTER_DECODER(MP3ADU, mp3adu);
+ REGISTER_ENCODER(MP3LAME, mp3lame);
+ REGISTER_DECODER(MP3ON4, mp3on4);
+ REGISTER_DECODER(MPC7, mpc7);
+ if (!ENABLE_VORBIS_ENCODER) REGISTER_ENCODER(OGGVORBIS, oggvorbis);
+ if (!ENABLE_VORBIS_DECODER) REGISTER_DECODER(OGGVORBIS, oggvorbis);
+ REGISTER_DECODER(QDM2, qdm2);
+ REGISTER_DECODER(RA_144, ra_144);
+ REGISTER_DECODER(RA_288, ra_288);
+ REGISTER_DECODER(SHORTEN, shorten);
+ REGISTER_DECODER(SMACKAUD, smackaud);
+ REGISTER_ENCDEC (SONIC, sonic);
+ REGISTER_ENCODER(SONIC_LS, sonic_ls);
+ REGISTER_DECODER(TRUESPEECH, truespeech);
+ REGISTER_DECODER(TTA, tta);
+ REGISTER_DECODER(VMDAUDIO, vmdaudio);
+ REGISTER_ENCDEC (VORBIS, vorbis);
+ REGISTER_DECODER(WAVPACK, wavpack);
+ REGISTER_ENCDEC(WMAV1, wmav1);
+ REGISTER_ENCDEC(WMAV2, wmav2);
+ REGISTER_DECODER(WS_SND1, ws_snd1);
+
+ /* pcm codecs */
+ REGISTER_ENCDEC (PCM_ALAW, pcm_alaw);
+ REGISTER_ENCDEC (PCM_MULAW, pcm_mulaw);
+ REGISTER_ENCDEC (PCM_S8, pcm_s8);
+ REGISTER_ENCDEC (PCM_S16BE, pcm_s16be);
+ REGISTER_ENCDEC (PCM_S16LE, pcm_s16le);
+ REGISTER_ENCDEC (PCM_S24BE, pcm_s24be);
+ REGISTER_ENCDEC (PCM_S24DAUD, pcm_s24daud);
+ REGISTER_ENCDEC (PCM_S24LE, pcm_s24le);
+ REGISTER_ENCDEC (PCM_S32BE, pcm_s32be);
+ REGISTER_ENCDEC (PCM_S32LE, pcm_s32le);
+ REGISTER_ENCDEC (PCM_U8, pcm_u8);
+ REGISTER_ENCDEC (PCM_U16BE, pcm_u16be);
+ REGISTER_ENCDEC (PCM_U16LE, pcm_u16le);
+ REGISTER_ENCDEC (PCM_U24BE, pcm_u24be);
+ REGISTER_ENCDEC (PCM_U24LE, pcm_u24le);
+ REGISTER_ENCDEC (PCM_U32BE, pcm_u32be);
+ REGISTER_ENCDEC (PCM_U32LE, pcm_u32le);
+
+ /* dpcm codecs */
+ REGISTER_DECODER(INTERPLAY_DPCM, interplay_dpcm);
+ REGISTER_DECODER(ROQ_DPCM, roq_dpcm);
+ REGISTER_DECODER(SOL_DPCM, sol_dpcm);
+ REGISTER_DECODER(XAN_DPCM, xan_dpcm);
+
+ /* adpcm codecs */
+ REGISTER_ENCDEC (ADPCM_4XM, adpcm_4xm);
+ REGISTER_ENCDEC (ADPCM_ADX, adpcm_adx);
+ REGISTER_ENCDEC (ADPCM_CT, adpcm_ct);
+ REGISTER_ENCDEC (ADPCM_EA, adpcm_ea);
+ REGISTER_ENCDEC (ADPCM_G726, adpcm_g726);
+ REGISTER_ENCDEC (ADPCM_IMA_DK3, adpcm_ima_dk3);
+ REGISTER_ENCDEC (ADPCM_IMA_DK4, adpcm_ima_dk4);
+ REGISTER_ENCDEC (ADPCM_IMA_QT, adpcm_ima_qt);
+ REGISTER_ENCDEC (ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg);
+ REGISTER_ENCDEC (ADPCM_IMA_WAV, adpcm_ima_wav);
+ REGISTER_ENCDEC (ADPCM_IMA_WS, adpcm_ima_ws);
+ REGISTER_ENCDEC (ADPCM_MS, adpcm_ms);
+ REGISTER_ENCDEC (ADPCM_SBPRO_2, adpcm_sbpro_2);
+ REGISTER_ENCDEC (ADPCM_SBPRO_3, adpcm_sbpro_3);
+ REGISTER_ENCDEC (ADPCM_SBPRO_4, adpcm_sbpro_4);
+ REGISTER_ENCDEC (ADPCM_SWF, adpcm_swf);
+ REGISTER_ENCDEC (ADPCM_XA, adpcm_xa);
+ REGISTER_ENCDEC (ADPCM_YAMAHA, adpcm_yamaha);
+
+ /* subtitles */
+ REGISTER_ENCDEC (DVBSUB, dvbsub);
+ REGISTER_ENCDEC (DVDSUB, dvdsub);
+
+ /* parsers */
+ REGISTER_PARSER (AAC, aac);
+ REGISTER_PARSER (AC3, ac3);
+ REGISTER_PARSER (CAVSVIDEO, cavsvideo);
+ REGISTER_PARSER (DCA, dca);
+ REGISTER_PARSER (DVBSUB, dvbsub);
+ REGISTER_PARSER (DVDSUB, dvdsub);
+ REGISTER_PARSER (H261, h261);
+ REGISTER_PARSER (H263, h263);
+ REGISTER_PARSER (H264, h264);
+ REGISTER_PARSER (MJPEG, mjpeg);
+ REGISTER_PARSER (MPEG4VIDEO, mpeg4video);
+ REGISTER_PARSER (MPEGAUDIO, mpegaudio);
+ REGISTER_PARSER (MPEGVIDEO, mpegvideo);
+ REGISTER_PARSER (PNM, pnm);
+ REGISTER_PARSER (VC1, vc1);
+
+ av_register_bitstream_filter(&dump_extradata_bsf);
+ av_register_bitstream_filter(&remove_extradata_bsf);
+ av_register_bitstream_filter(&noise_bsf);
+ av_register_bitstream_filter(&mp3_header_compress_bsf);
+ av_register_bitstream_filter(&mp3_header_decompress_bsf);
+ av_register_bitstream_filter(&mjpega_dump_header_bsf);
+ av_register_bitstream_filter(&imx_dump_header_bsf);
+}
+
diff --git a/src/libffmpeg/libavcodec/alpha/asm.h b/contrib/ffmpeg/libavcodec/alpha/asm.h
index c0ddde528..c0ddde528 100644
--- a/src/libffmpeg/libavcodec/alpha/asm.h
+++ b/contrib/ffmpeg/libavcodec/alpha/asm.h
diff --git a/src/libffmpeg/libavcodec/alpha/dsputil_alpha.c b/contrib/ffmpeg/libavcodec/alpha/dsputil_alpha.c
index c98d6f7ff..c98d6f7ff 100644
--- a/src/libffmpeg/libavcodec/alpha/dsputil_alpha.c
+++ b/contrib/ffmpeg/libavcodec/alpha/dsputil_alpha.c
diff --git a/contrib/ffmpeg/libavcodec/alpha/dsputil_alpha_asm.S b/contrib/ffmpeg/libavcodec/alpha/dsputil_alpha_asm.S
new file mode 100644
index 000000000..dbdf279ba
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/alpha/dsputil_alpha_asm.S
@@ -0,0 +1,285 @@
+/*
+ * Alpha optimized DSP utils
+ * Copyright (c) 2002 Falk Hueffner <falk@debian.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*
+ * These functions are scheduled for pca56. They should work
+ * reasonably on ev6, though.
+ */
+
+#include "regdef.h"
+
+/* Some nicer register names. */
+#define ta t10
+#define tb t11
+#define tc t12
+#define td AT
+/* Danger: these overlap with the argument list and the return value */
+#define te a5
+#define tf a4
+#define tg a3
+#define th v0
+
+ .set noat
+ .set noreorder
+ .arch pca56
+ .text
+
+/************************************************************************
+ * void put_pixels_axp_asm(uint8_t *block, const uint8_t *pixels,
+ * int line_size, int h)
+ */
+ .align 6
+ .globl put_pixels_axp_asm
+ .ent put_pixels_axp_asm
+put_pixels_axp_asm:
+ .frame sp, 0, ra
+ .prologue 0
+
+#ifdef CONFIG_GPROF
+ lda AT, _mcount
+ jsr AT, (AT), _mcount
+#endif
+
+ and a1, 7, t0
+ beq t0, $aligned
+
+ .align 4
+$unaligned:
+ ldq_u t0, 0(a1)
+ ldq_u t1, 8(a1)
+ addq a1, a2, a1
+ nop
+
+ ldq_u t2, 0(a1)
+ ldq_u t3, 8(a1)
+ addq a1, a2, a1
+ nop
+
+ ldq_u t4, 0(a1)
+ ldq_u t5, 8(a1)
+ addq a1, a2, a1
+ nop
+
+ ldq_u t6, 0(a1)
+ ldq_u t7, 8(a1)
+ extql t0, a1, t0
+ addq a1, a2, a1
+
+ extqh t1, a1, t1
+ addq a0, a2, t8
+ extql t2, a1, t2
+ addq t8, a2, t9
+
+ extqh t3, a1, t3
+ addq t9, a2, ta
+ extql t4, a1, t4
+ or t0, t1, t0
+
+ extqh t5, a1, t5
+ or t2, t3, t2
+ extql t6, a1, t6
+ or t4, t5, t4
+
+ extqh t7, a1, t7
+ or t6, t7, t6
+ stq t0, 0(a0)
+ stq t2, 0(t8)
+
+ stq t4, 0(t9)
+ subq a3, 4, a3
+ stq t6, 0(ta)
+ addq ta, a2, a0
+
+ bne a3, $unaligned
+ ret
+
+ .align 4
+$aligned:
+ ldq t0, 0(a1)
+ addq a1, a2, a1
+ ldq t1, 0(a1)
+ addq a1, a2, a1
+
+ ldq t2, 0(a1)
+ addq a1, a2, a1
+ ldq t3, 0(a1)
+
+ addq a0, a2, t4
+ addq a1, a2, a1
+ addq t4, a2, t5
+ subq a3, 4, a3
+
+ stq t0, 0(a0)
+ addq t5, a2, t6
+ stq t1, 0(t4)
+ addq t6, a2, a0
+
+ stq t2, 0(t5)
+ stq t3, 0(t6)
+
+ bne a3, $aligned
+ ret
+ .end put_pixels_axp_asm
+
+/************************************************************************
+ * void put_pixels_clamped_mvi_asm(const DCTELEM *block, uint8_t *pixels,
+ * int line_size)
+ */
+ .align 6
+ .globl put_pixels_clamped_mvi_asm
+ .ent put_pixels_clamped_mvi_asm
+put_pixels_clamped_mvi_asm:
+ .frame sp, 0, ra
+ .prologue 0
+
+#ifdef CONFIG_GPROF
+ lda AT, _mcount
+ jsr AT, (AT), _mcount
+#endif
+
+ lda t8, -1
+ lda t9, 8 # loop counter
+ zap t8, 0xaa, t8 # 00ff00ff00ff00ff
+
+ .align 4
+1: ldq t0, 0(a0)
+ ldq t1, 8(a0)
+ ldq t2, 16(a0)
+ ldq t3, 24(a0)
+
+ maxsw4 t0, zero, t0
+ subq t9, 2, t9
+ maxsw4 t1, zero, t1
+ lda a0, 32(a0)
+
+ maxsw4 t2, zero, t2
+ addq a1, a2, ta
+ maxsw4 t3, zero, t3
+ minsw4 t0, t8, t0
+
+ minsw4 t1, t8, t1
+ minsw4 t2, t8, t2
+ minsw4 t3, t8, t3
+ pkwb t0, t0
+
+ pkwb t1, t1
+ pkwb t2, t2
+ pkwb t3, t3
+ stl t0, 0(a1)
+
+ stl t1, 4(a1)
+ addq ta, a2, a1
+ stl t2, 0(ta)
+ stl t3, 4(ta)
+
+ bne t9, 1b
+ ret
+ .end put_pixels_clamped_mvi_asm
+
+/************************************************************************
+ * void add_pixels_clamped_mvi_asm(const DCTELEM *block, uint8_t *pixels,
+ * int line_size)
+ */
+ .align 6
+ .globl add_pixels_clamped_mvi_asm
+ .ent add_pixels_clamped_mvi_asm
+add_pixels_clamped_mvi_asm:
+ .frame sp, 0, ra
+ .prologue 0
+
+#ifdef CONFIG_GPROF
+ lda AT, _mcount
+ jsr AT, (AT), _mcount
+#endif
+
+ lda t1, -1
+ lda th, 8
+ zap t1, 0x33, tg
+ nop
+
+ srl tg, 1, t0
+ xor tg, t0, tg # 0x8000800080008000
+ zap t1, 0xaa, tf # 0x00ff00ff00ff00ff
+
+ .align 4
+1: ldl t1, 0(a1) # pix0 (try to hit cache line soon)
+ ldl t4, 4(a1) # pix1
+ addq a1, a2, te # pixels += line_size
+ ldq t0, 0(a0) # shorts0
+
+ ldl t7, 0(te) # pix2 (try to hit cache line soon)
+ ldl ta, 4(te) # pix3
+ ldq t3, 8(a0) # shorts1
+ ldq t6, 16(a0) # shorts2
+
+ ldq t9, 24(a0) # shorts3
+ unpkbw t1, t1 # 0 0 (quarter/op no.)
+ and t0, tg, t2 # 0 1
+ unpkbw t4, t4 # 1 0
+
+ bic t0, tg, t0 # 0 2
+ unpkbw t7, t7 # 2 0
+ and t3, tg, t5 # 1 1
+ addq t0, t1, t0 # 0 3
+
+ xor t0, t2, t0 # 0 4
+ unpkbw ta, ta # 3 0
+ and t6, tg, t8 # 2 1
+ maxsw4 t0, zero, t0 # 0 5
+
+ bic t3, tg, t3 # 1 2
+ bic t6, tg, t6 # 2 2
+ minsw4 t0, tf, t0 # 0 6
+ addq t3, t4, t3 # 1 3
+
+ pkwb t0, t0 # 0 7
+ xor t3, t5, t3 # 1 4
+ maxsw4 t3, zero, t3 # 1 5
+ addq t6, t7, t6 # 2 3
+
+ xor t6, t8, t6 # 2 4
+ and t9, tg, tb # 3 1
+ minsw4 t3, tf, t3 # 1 6
+ bic t9, tg, t9 # 3 2
+
+ maxsw4 t6, zero, t6 # 2 5
+ addq t9, ta, t9 # 3 3
+ stl t0, 0(a1) # 0 8
+ minsw4 t6, tf, t6 # 2 6
+
+ xor t9, tb, t9 # 3 4
+ maxsw4 t9, zero, t9 # 3 5
+ lda a0, 32(a0) # block += 16;
+ pkwb t3, t3 # 1 7
+
+ minsw4 t9, tf, t9 # 3 6
+ subq th, 2, th
+ pkwb t6, t6 # 2 7
+ pkwb t9, t9 # 3 7
+
+ stl t3, 4(a1) # 1 8
+ addq te, a2, a1 # pixels += line_size
+ stl t6, 0(te) # 2 8
+ stl t9, 4(te) # 3 8
+
+ bne th, 1b
+ ret
+ .end add_pixels_clamped_mvi_asm
diff --git a/src/libffmpeg/libavcodec/alpha/motion_est_alpha.c b/contrib/ffmpeg/libavcodec/alpha/motion_est_alpha.c
index 337ffb38e..337ffb38e 100644
--- a/src/libffmpeg/libavcodec/alpha/motion_est_alpha.c
+++ b/contrib/ffmpeg/libavcodec/alpha/motion_est_alpha.c
diff --git a/contrib/ffmpeg/libavcodec/alpha/motion_est_mvi_asm.S b/contrib/ffmpeg/libavcodec/alpha/motion_est_mvi_asm.S
new file mode 100644
index 000000000..cdf40b1f3
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/alpha/motion_est_mvi_asm.S
@@ -0,0 +1,185 @@
+/*
+ * Alpha optimized DSP utils
+ * Copyright (c) 2002 Falk Hueffner <falk@debian.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "regdef.h"
+
+/* Some nicer register names. */
+#define ta t10
+#define tb t11
+#define tc t12
+#define td AT
+/* Danger: these overlap with the argument list and the return value */
+#define te a5
+#define tf a4
+#define tg a3
+#define th v0
+
+ .set noat
+ .set noreorder
+ .arch pca56
+ .text
+
+/*****************************************************************************
+ * int pix_abs16x16_mvi_asm(uint8_t *pix1, uint8_t *pix2, int line_size)
+ *
+ * This code is written with a pca56 in mind. For ev6, one should
+ * really take the increased latency of 3 cycles for MVI instructions
+ * into account.
+ *
+ * It is important to keep the loading and first use of a register as
+ * far apart as possible, because if a register is accessed before it
+ * has been fetched from memory, the CPU will stall.
+ */
+ .align 4
+ .globl pix_abs16x16_mvi_asm
+ .ent pix_abs16x16_mvi_asm
+pix_abs16x16_mvi_asm:
+ .frame sp, 0, ra, 0
+ .prologue 0
+
+#ifdef CONFIG_GPROF
+ lda AT, _mcount
+ jsr AT, (AT), _mcount
+#endif
+
+ and a1, 7, t0
+ clr v0
+ lda a3, 16
+ beq t0, $aligned
+ .align 4
+$unaligned:
+ /* Registers:
+ line 0:
+ t0: left_u -> left lo -> left
+ t1: mid
+ t2: right_u -> right hi -> right
+ t3: ref left
+ t4: ref right
+ line 1:
+ t5: left_u -> left lo -> left
+ t6: mid
+ t7: right_u -> right hi -> right
+ t8: ref left
+ t9: ref right
+ temp:
+ ta: left hi
+ tb: right lo
+ tc: error left
+ td: error right */
+
+ /* load line 0 */
+ ldq_u t0, 0(a1) # left_u
+ ldq_u t1, 8(a1) # mid
+ ldq_u t2, 16(a1) # right_u
+ ldq t3, 0(a0) # ref left
+ ldq t4, 8(a0) # ref right
+ addq a0, a2, a0 # pix1
+ addq a1, a2, a1 # pix2
+ /* load line 1 */
+ ldq_u t5, 0(a1) # left_u
+ ldq_u t6, 8(a1) # mid
+ ldq_u t7, 16(a1) # right_u
+ ldq t8, 0(a0) # ref left
+ ldq t9, 8(a0) # ref right
+ addq a0, a2, a0 # pix1
+ addq a1, a2, a1 # pix2
+ /* calc line 0 */
+ extql t0, a1, t0 # left lo
+ extqh t1, a1, ta # left hi
+ extql t1, a1, tb # right lo
+ or t0, ta, t0 # left
+ extqh t2, a1, t2 # right hi
+ perr t3, t0, tc # error left
+ or t2, tb, t2 # right
+ perr t4, t2, td # error right
+ addq v0, tc, v0 # add error left
+ addq v0, td, v0 # add error left
+ /* calc line 1 */
+ extql t5, a1, t5 # left lo
+ extqh t6, a1, ta # left hi
+ extql t6, a1, tb # right lo
+ or t5, ta, t5 # left
+ extqh t7, a1, t7 # right hi
+ perr t8, t5, tc # error left
+ or t7, tb, t7 # right
+ perr t9, t7, td # error right
+ addq v0, tc, v0 # add error left
+ addq v0, td, v0 # add error left
+ /* loop */
+ subq a3, 2, a3 # h -= 2
+ bne a3, $unaligned
+ ret
+
+ .align 4
+$aligned:
+ /* load line 0 */
+ ldq t0, 0(a1) # left
+ ldq t1, 8(a1) # right
+ addq a1, a2, a1 # pix2
+ ldq t2, 0(a0) # ref left
+ ldq t3, 8(a0) # ref right
+ addq a0, a2, a0 # pix1
+ /* load line 1 */
+ ldq t4, 0(a1) # left
+ ldq t5, 8(a1) # right
+ addq a1, a2, a1 # pix2
+ ldq t6, 0(a0) # ref left
+ ldq t7, 8(a0) # ref right
+ addq a0, a2, a0 # pix1
+ /* load line 2 */
+ ldq t8, 0(a1) # left
+ ldq t9, 8(a1) # right
+ addq a1, a2, a1 # pix2
+ ldq ta, 0(a0) # ref left
+ ldq tb, 8(a0) # ref right
+ addq a0, a2, a0 # pix1
+ /* load line 3 */
+ ldq tc, 0(a1) # left
+ ldq td, 8(a1) # right
+ addq a1, a2, a1 # pix2
+ ldq te, 0(a0) # ref left
+ ldq tf, 8(a0) # ref right
+ /* calc line 0 */
+ perr t0, t2, t0 # error left
+ addq a0, a2, a0 # pix1
+ perr t1, t3, t1 # error right
+ addq v0, t0, v0 # add error left
+ /* calc line 1 */
+ perr t4, t6, t0 # error left
+ addq v0, t1, v0 # add error right
+ perr t5, t7, t1 # error right
+ addq v0, t0, v0 # add error left
+ /* calc line 2 */
+ perr t8, ta, t0 # error left
+ addq v0, t1, v0 # add error right
+ perr t9, tb, t1 # error right
+ addq v0, t0, v0 # add error left
+ /* calc line 3 */
+ perr tc, te, t0 # error left
+ addq v0, t1, v0 # add error right
+ perr td, tf, t1 # error right
+ addq v0, t0, v0 # add error left
+ addq v0, t1, v0 # add error right
+ /* loop */
+ subq a3, 4, a3 # h -= 4
+ bne a3, $aligned
+ ret
+ .end pix_abs16x16_mvi_asm
diff --git a/src/libffmpeg/libavcodec/alpha/mpegvideo_alpha.c b/contrib/ffmpeg/libavcodec/alpha/mpegvideo_alpha.c
index 8ad264b06..8ad264b06 100644
--- a/src/libffmpeg/libavcodec/alpha/mpegvideo_alpha.c
+++ b/contrib/ffmpeg/libavcodec/alpha/mpegvideo_alpha.c
diff --git a/src/libffmpeg/libavcodec/alpha/regdef.h b/contrib/ffmpeg/libavcodec/alpha/regdef.h
index 01e263bac..01e263bac 100644
--- a/src/libffmpeg/libavcodec/alpha/regdef.h
+++ b/contrib/ffmpeg/libavcodec/alpha/regdef.h
diff --git a/contrib/ffmpeg/libavcodec/alpha/simple_idct_alpha.c b/contrib/ffmpeg/libavcodec/alpha/simple_idct_alpha.c
new file mode 100644
index 000000000..adadd3ab0
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/alpha/simple_idct_alpha.c
@@ -0,0 +1,308 @@
+/*
+ * Simple IDCT (Alpha optimized)
+ *
+ * Copyright (c) 2001 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * based upon some outcommented c code from mpeg2dec (idct_mmx.c
+ * written by Aaron Holtzman <aholtzma@ess.engr.uvic.ca>)
+ *
+ * Alpha optimiziations by Måns Rullgård <mru@users.sourceforge.net>
+ * and Falk Hueffner <falk@debian.org>
+ */
+
+#include "asm.h"
+#include "../dsputil.h"
+
+extern void (*put_pixels_clamped_axp_p)(const DCTELEM *block, uint8_t *pixels,
+ int line_size);
+extern void (*add_pixels_clamped_axp_p)(const DCTELEM *block, uint8_t *pixels,
+ int line_size);
+
+// cos(i * M_PI / 16) * sqrt(2) * (1 << 14)
+// W4 is actually exactly 16384, but using 16383 works around
+// accumulating rounding errors for some encoders
+#define W1 ((int_fast32_t) 22725)
+#define W2 ((int_fast32_t) 21407)
+#define W3 ((int_fast32_t) 19266)
+#define W4 ((int_fast32_t) 16383)
+#define W5 ((int_fast32_t) 12873)
+#define W6 ((int_fast32_t) 8867)
+#define W7 ((int_fast32_t) 4520)
+#define ROW_SHIFT 11
+#define COL_SHIFT 20
+
+/* 0: all entries 0, 1: only first entry nonzero, 2: otherwise */
+static inline int idct_row(DCTELEM *row)
+{
+ int_fast32_t a0, a1, a2, a3, b0, b1, b2, b3, t;
+ uint64_t l, r, t2;
+ l = ldq(row);
+ r = ldq(row + 4);
+
+ if (l == 0 && r == 0)
+ return 0;
+
+ a0 = W4 * sextw(l) + (1 << (ROW_SHIFT - 1));
+
+ if (((l & ~0xffffUL) | r) == 0) {
+ a0 >>= ROW_SHIFT;
+ t2 = (uint16_t) a0;
+ t2 |= t2 << 16;
+ t2 |= t2 << 32;
+
+ stq(t2, row);
+ stq(t2, row + 4);
+ return 1;
+ }
+
+ a1 = a0;
+ a2 = a0;
+ a3 = a0;
+
+ t = extwl(l, 4); /* row[2] */
+ if (t != 0) {
+ t = sextw(t);
+ a0 += W2 * t;
+ a1 += W6 * t;
+ a2 -= W6 * t;
+ a3 -= W2 * t;
+ }
+
+ t = extwl(r, 0); /* row[4] */
+ if (t != 0) {
+ t = sextw(t);
+ a0 += W4 * t;
+ a1 -= W4 * t;
+ a2 -= W4 * t;
+ a3 += W4 * t;
+ }
+
+ t = extwl(r, 4); /* row[6] */
+ if (t != 0) {
+ t = sextw(t);
+ a0 += W6 * t;
+ a1 -= W2 * t;
+ a2 += W2 * t;
+ a3 -= W6 * t;
+ }
+
+ t = extwl(l, 2); /* row[1] */
+ if (t != 0) {
+ t = sextw(t);
+ b0 = W1 * t;
+ b1 = W3 * t;
+ b2 = W5 * t;
+ b3 = W7 * t;
+ } else {
+ b0 = 0;
+ b1 = 0;
+ b2 = 0;
+ b3 = 0;
+ }
+
+ t = extwl(l, 6); /* row[3] */
+ if (t) {
+ t = sextw(t);
+ b0 += W3 * t;
+ b1 -= W7 * t;
+ b2 -= W1 * t;
+ b3 -= W5 * t;
+ }
+
+
+ t = extwl(r, 2); /* row[5] */
+ if (t) {
+ t = sextw(t);
+ b0 += W5 * t;
+ b1 -= W1 * t;
+ b2 += W7 * t;
+ b3 += W3 * t;
+ }
+
+ t = extwl(r, 6); /* row[7] */
+ if (t) {
+ t = sextw(t);
+ b0 += W7 * t;
+ b1 -= W5 * t;
+ b2 += W3 * t;
+ b3 -= W1 * t;
+ }
+
+ row[0] = (a0 + b0) >> ROW_SHIFT;
+ row[1] = (a1 + b1) >> ROW_SHIFT;
+ row[2] = (a2 + b2) >> ROW_SHIFT;
+ row[3] = (a3 + b3) >> ROW_SHIFT;
+ row[4] = (a3 - b3) >> ROW_SHIFT;
+ row[5] = (a2 - b2) >> ROW_SHIFT;
+ row[6] = (a1 - b1) >> ROW_SHIFT;
+ row[7] = (a0 - b0) >> ROW_SHIFT;
+
+ return 2;
+}
+
+static inline void idct_col(DCTELEM *col)
+{
+ int_fast32_t a0, a1, a2, a3, b0, b1, b2, b3;
+
+ col[0] += (1 << (COL_SHIFT - 1)) / W4;
+
+ a0 = W4 * col[8 * 0];
+ a1 = W4 * col[8 * 0];
+ a2 = W4 * col[8 * 0];
+ a3 = W4 * col[8 * 0];
+
+ if (col[8 * 2]) {
+ a0 += W2 * col[8 * 2];
+ a1 += W6 * col[8 * 2];
+ a2 -= W6 * col[8 * 2];
+ a3 -= W2 * col[8 * 2];
+ }
+
+ if (col[8 * 4]) {
+ a0 += W4 * col[8 * 4];
+ a1 -= W4 * col[8 * 4];
+ a2 -= W4 * col[8 * 4];
+ a3 += W4 * col[8 * 4];
+ }
+
+ if (col[8 * 6]) {
+ a0 += W6 * col[8 * 6];
+ a1 -= W2 * col[8 * 6];
+ a2 += W2 * col[8 * 6];
+ a3 -= W6 * col[8 * 6];
+ }
+
+ if (col[8 * 1]) {
+ b0 = W1 * col[8 * 1];
+ b1 = W3 * col[8 * 1];
+ b2 = W5 * col[8 * 1];
+ b3 = W7 * col[8 * 1];
+ } else {
+ b0 = 0;
+ b1 = 0;
+ b2 = 0;
+ b3 = 0;
+ }
+
+ if (col[8 * 3]) {
+ b0 += W3 * col[8 * 3];
+ b1 -= W7 * col[8 * 3];
+ b2 -= W1 * col[8 * 3];
+ b3 -= W5 * col[8 * 3];
+ }
+
+ if (col[8 * 5]) {
+ b0 += W5 * col[8 * 5];
+ b1 -= W1 * col[8 * 5];
+ b2 += W7 * col[8 * 5];
+ b3 += W3 * col[8 * 5];
+ }
+
+ if (col[8 * 7]) {
+ b0 += W7 * col[8 * 7];
+ b1 -= W5 * col[8 * 7];
+ b2 += W3 * col[8 * 7];
+ b3 -= W1 * col[8 * 7];
+ }
+
+ col[8 * 0] = (a0 + b0) >> COL_SHIFT;
+ col[8 * 7] = (a0 - b0) >> COL_SHIFT;
+ col[8 * 1] = (a1 + b1) >> COL_SHIFT;
+ col[8 * 6] = (a1 - b1) >> COL_SHIFT;
+ col[8 * 2] = (a2 + b2) >> COL_SHIFT;
+ col[8 * 5] = (a2 - b2) >> COL_SHIFT;
+ col[8 * 3] = (a3 + b3) >> COL_SHIFT;
+ col[8 * 4] = (a3 - b3) >> COL_SHIFT;
+}
+
+/* If all rows but the first one are zero after row transformation,
+ all rows will be identical after column transformation. */
+static inline void idct_col2(DCTELEM *col)
+{
+ int i;
+ uint64_t l, r;
+
+ for (i = 0; i < 8; ++i) {
+ int_fast32_t a0 = col[i] + (1 << (COL_SHIFT - 1)) / W4;
+
+ a0 *= W4;
+ col[i] = a0 >> COL_SHIFT;
+ }
+
+ l = ldq(col + 0 * 4); r = ldq(col + 1 * 4);
+ stq(l, col + 2 * 4); stq(r, col + 3 * 4);
+ stq(l, col + 4 * 4); stq(r, col + 5 * 4);
+ stq(l, col + 6 * 4); stq(r, col + 7 * 4);
+ stq(l, col + 8 * 4); stq(r, col + 9 * 4);
+ stq(l, col + 10 * 4); stq(r, col + 11 * 4);
+ stq(l, col + 12 * 4); stq(r, col + 13 * 4);
+ stq(l, col + 14 * 4); stq(r, col + 15 * 4);
+}
+
+void simple_idct_axp(DCTELEM *block)
+{
+
+ int i;
+ int rowsZero = 1; /* all rows except row 0 zero */
+ int rowsConstant = 1; /* all rows consist of a constant value */
+
+ for (i = 0; i < 8; i++) {
+ int sparseness = idct_row(block + 8 * i);
+
+ if (i > 0 && sparseness > 0)
+ rowsZero = 0;
+ if (sparseness == 2)
+ rowsConstant = 0;
+ }
+
+ if (rowsZero) {
+ idct_col2(block);
+ } else if (rowsConstant) {
+ idct_col(block);
+ for (i = 0; i < 8; i += 2) {
+ uint64_t v = (uint16_t) block[0];
+ uint64_t w = (uint16_t) block[8];
+
+ v |= v << 16;
+ w |= w << 16;
+ v |= v << 32;
+ w |= w << 32;
+ stq(v, block + 0 * 4);
+ stq(v, block + 1 * 4);
+ stq(w, block + 2 * 4);
+ stq(w, block + 3 * 4);
+ block += 4 * 4;
+ }
+ } else {
+ for (i = 0; i < 8; i++)
+ idct_col(block + i);
+ }
+}
+
+void simple_idct_put_axp(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ simple_idct_axp(block);
+ put_pixels_clamped_axp_p(block, dest, line_size);
+}
+
+void simple_idct_add_axp(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ simple_idct_axp(block);
+ add_pixels_clamped_axp_p(block, dest, line_size);
+}
diff --git a/contrib/ffmpeg/libavcodec/amr.c b/contrib/ffmpeg/libavcodec/amr.c
new file mode 100644
index 000000000..6a8193f0b
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/amr.c
@@ -0,0 +1,715 @@
+/*
+ * AMR Audio decoder stub
+ * Copyright (c) 2003 the ffmpeg project
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+ /** @file
+ * Adaptive Multi-Rate (AMR) Audio decoder stub.
+ *
+ * This code implements both an AMR-NarrowBand (AMR-NB) and an AMR-WideBand
+ * (AMR-WB) audio encoder/decoder through external reference code from
+ * http://www.3gpp.org/. The license of the code from 3gpp is unclear so you
+ * have to download the code separately. Two versions exists: One fixed-point
+ * and one with floats. For some reason the float-encoder is significant faster
+ * at least on a P4 1.5GHz (0.9s instead of 9.9s on a 30s audio clip at MR102).
+ * Both float and fixed point are supported for AMR-NB, but only float for
+ * AMR-WB.
+ *
+ * \section AMR-NB
+ *
+ * \subsection Float
+ * The float version (default) can be downloaded from:
+ * http://www.3gpp.org/ftp/Specs/archive/26_series/26.104/26104-610.zip
+ * Extract the source into \c "ffmpeg/libavcodec/amr_float".
+ *
+ * \subsection Fixed-point
+ * The fixed-point (TS26.073) can be downloaded from:
+ * http://www.3gpp.org/ftp/Specs/archive/26_series/26.073/26073-510.zip.
+ * Extract the source into \c "ffmpeg/libavcodec/amr".
+ * To use the fixed version run \c "./configure" with \c "--enable-amr_nb-fixed".
+ *
+ * \subsection Specification
+ * The specification for AMR-NB can be found in TS 26.071
+ * (http://www.3gpp.org/ftp/Specs/html-info/26071.htm) and some other
+ * info at http://www.3gpp.org/ftp/Specs/html-info/26-series.htm.
+ *
+ * \section AMR-WB
+ * \subsection Float
+ * The reference code can be downloaded from:
+ * http://www.3gpp.org/ftp/Specs/archive/26_series/26.204/26204-600.zip
+ * It should be extracted to \c "ffmpeg/libavcodec/amrwb_float". Enable it with
+ * \c "--enable-amr_wb".
+ *
+ * \subsection Fixed-point
+ * If someone wants to use the fixed point version it can be downloaded from:
+ * http://www.3gpp.org/ftp/Specs/archive/26_series/26.173/26173-571.zip.
+ *
+ * \subsection Specification
+ * The specification for AMR-WB can be found in TS 26.171
+ * (http://www.3gpp.org/ftp/Specs/html-info/26171.htm) and some other
+ * info at http://www.3gpp.org/ftp/Specs/html-info/26-series.htm.
+ *
+ */
+
+#include "avcodec.h"
+
+#ifdef CONFIG_AMR_NB_FIXED
+
+#define MMS_IO
+
+#include "amr/sp_dec.h"
+#include "amr/d_homing.h"
+#include "amr/typedef.h"
+#include "amr/sp_enc.h"
+#include "amr/sid_sync.h"
+#include "amr/e_homing.h"
+
+#else
+#include "amr_float/interf_dec.h"
+#include "amr_float/interf_enc.h"
+#endif
+
+/* Common code for fixed and float version*/
+typedef struct AMR_bitrates
+{
+ int rate;
+ enum Mode mode;
+} AMR_bitrates;
+
+/* Match desired bitrate */
+static int getBitrateMode(int bitrate)
+{
+ /* make the correspondance between bitrate and mode */
+ AMR_bitrates rates[]={ {4750,MR475},
+ {5150,MR515},
+ {5900,MR59},
+ {6700,MR67},
+ {7400,MR74},
+ {7950,MR795},
+ {10200,MR102},
+ {12200,MR122},
+ };
+ int i;
+
+ for(i=0;i<8;i++)
+ {
+ if(rates[i].rate==bitrate)
+ {
+ return(rates[i].mode);
+ }
+ }
+ /* no bitrate matching, return an error */
+ return -1;
+}
+
+static void amr_decode_fix_avctx(AVCodecContext * avctx)
+{
+ const int is_amr_wb = 1 + (avctx->codec_id == CODEC_ID_AMR_WB);
+
+ if(avctx->sample_rate == 0)
+ {
+ avctx->sample_rate = 8000 * is_amr_wb;
+ }
+
+ if(avctx->channels == 0)
+ {
+ avctx->channels = 1;
+ }
+
+ avctx->frame_size = 160 * is_amr_wb;
+}
+
+#ifdef CONFIG_AMR_NB_FIXED
+/* fixed point version*/
+/* frame size in serial bitstream file (frame type + serial stream + flags) */
+#define SERIAL_FRAMESIZE (1+MAX_SERIAL_SIZE+5)
+
+typedef struct AMRContext {
+ int frameCount;
+ Speech_Decode_FrameState *speech_decoder_state;
+ enum RXFrameType rx_type;
+ enum Mode mode;
+ Word16 reset_flag;
+ Word16 reset_flag_old;
+
+ int enc_bitrate;
+ Speech_Encode_FrameState *enstate;
+ sid_syncState *sidstate;
+ enum TXFrameType tx_frametype;
+} AMRContext;
+
+static int amr_nb_decode_init(AVCodecContext * avctx)
+{
+ AMRContext *s = avctx->priv_data;
+
+ s->frameCount=0;
+ s->speech_decoder_state=NULL;
+ s->rx_type = (enum RXFrameType)0;
+ s->mode= (enum Mode)0;
+ s->reset_flag=0;
+ s->reset_flag_old=1;
+
+ if(Speech_Decode_Frame_init(&s->speech_decoder_state, "Decoder"))
+ {
+ av_log(avctx, AV_LOG_ERROR, "Speech_Decode_Frame_init error\n");
+ return -1;
+ }
+
+ amr_decode_fix_avctx(avctx);
+
+ if(avctx->channels > 1)
+ {
+ av_log(avctx, AV_LOG_ERROR, "amr_nb: multichannel decoding not supported\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+static int amr_nb_encode_init(AVCodecContext * avctx)
+{
+ AMRContext *s = avctx->priv_data;
+
+ s->frameCount=0;
+ s->speech_decoder_state=NULL;
+ s->rx_type = (enum RXFrameType)0;
+ s->mode= (enum Mode)0;
+ s->reset_flag=0;
+ s->reset_flag_old=1;
+
+ if(avctx->sample_rate!=8000)
+ {
+ av_log(avctx, AV_LOG_ERROR, "Only 8000Hz sample rate supported\n");
+ return -1;
+ }
+
+ if(avctx->channels!=1)
+ {
+ av_log(avctx, AV_LOG_ERROR, "Only mono supported\n");
+ return -1;
+ }
+
+ avctx->frame_size=160;
+ avctx->coded_frame= avcodec_alloc_frame();
+
+ if(Speech_Encode_Frame_init(&s->enstate, 0, "encoder") || sid_sync_init (&s->sidstate))
+ {
+ av_log(avctx, AV_LOG_ERROR, "Speech_Encode_Frame_init error\n");
+ return -1;
+ }
+
+ if((s->enc_bitrate=getBitrateMode(avctx->bit_rate))<0)
+ {
+ av_log(avctx, AV_LOG_ERROR, "bitrate not supported\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+static int amr_nb_encode_close(AVCodecContext * avctx)
+{
+ AMRContext *s = avctx->priv_data;
+
+ Speech_Encode_Frame_exit(&s->enstate);
+ sid_sync_exit (&s->sidstate);
+ av_freep(&avctx->coded_frame);
+ return 0;
+}
+
+static int amr_nb_decode_close(AVCodecContext * avctx)
+{
+ AMRContext *s = avctx->priv_data;
+
+ Speech_Decode_Frame_exit(&s->speech_decoder_state);
+ return 0;
+}
+
+static int amr_nb_decode_frame(AVCodecContext * avctx,
+ void *data, int *data_size,
+ uint8_t * buf, int buf_size)
+{
+ AMRContext *s = avctx->priv_data;
+ uint8_t*amrData=buf;
+ int offset=0;
+ UWord8 toc, q, ft;
+ Word16 serial[SERIAL_FRAMESIZE]; /* coded bits */
+ Word16 *synth;
+ UWord8 *packed_bits;
+ static Word16 packed_size[16] = {12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0};
+ int i;
+
+ //printf("amr_decode_frame data_size=%i buf=0x%X buf_size=%d frameCount=%d!!\n",*data_size,buf,buf_size,s->frameCount);
+
+ synth=data;
+
+// while(offset<buf_size)
+ {
+ toc=amrData[offset];
+ /* read rest of the frame based on ToC byte */
+ q = (toc >> 2) & 0x01;
+ ft = (toc >> 3) & 0x0F;
+
+ //printf("offset=%d, packet_size=%d amrData= 0x%X %X %X %X\n",offset,packed_size[ft],amrData[offset],amrData[offset+1],amrData[offset+2],amrData[offset+3]);
+
+ offset++;
+
+ packed_bits=amrData+offset;
+
+ offset+=packed_size[ft];
+
+ //Unsort and unpack bits
+ s->rx_type = UnpackBits(q, ft, packed_bits, &s->mode, &serial[1]);
+
+ //We have a new frame
+ s->frameCount++;
+
+ if (s->rx_type == RX_NO_DATA)
+ {
+ s->mode = s->speech_decoder_state->prev_mode;
+ }
+ else {
+ s->speech_decoder_state->prev_mode = s->mode;
+ }
+
+ /* if homed: check if this frame is another homing frame */
+ if (s->reset_flag_old == 1)
+ {
+ /* only check until end of first subframe */
+ s->reset_flag = decoder_homing_frame_test_first(&serial[1], s->mode);
+ }
+ /* produce encoder homing frame if homed & input=decoder homing frame */
+ if ((s->reset_flag != 0) && (s->reset_flag_old != 0))
+ {
+ for (i = 0; i < L_FRAME; i++)
+ {
+ synth[i] = EHF_MASK;
+ }
+ }
+ else
+ {
+ /* decode frame */
+ Speech_Decode_Frame(s->speech_decoder_state, s->mode, &serial[1], s->rx_type, synth);
+ }
+
+ //Each AMR-frame results in 160 16-bit samples
+ *data_size+=160*2;
+ synth+=160;
+
+ /* if not homed: check whether current frame is a homing frame */
+ if (s->reset_flag_old == 0)
+ {
+ /* check whole frame */
+ s->reset_flag = decoder_homing_frame_test(&serial[1], s->mode);
+ }
+ /* reset decoder if current frame is a homing frame */
+ if (s->reset_flag != 0)
+ {
+ Speech_Decode_Frame_reset(s->speech_decoder_state);
+ }
+ s->reset_flag_old = s->reset_flag;
+
+ }
+ return offset;
+}
+
+
+static int amr_nb_encode_frame(AVCodecContext *avctx,
+ unsigned char *frame/*out*/, int buf_size, void *data/*in*/)
+{
+ short serial_data[250] = {0};
+ AMRContext *s = avctx->priv_data;
+ int written;
+
+ s->reset_flag = encoder_homing_frame_test(data);
+
+ Speech_Encode_Frame(s->enstate, s->enc_bitrate, data, &serial_data[1], &s->mode);
+
+ /* add frame type and mode */
+ sid_sync (s->sidstate, s->mode, &s->tx_frametype);
+
+ written = PackBits(s->mode, s->enc_bitrate, s->tx_frametype, &serial_data[1], frame);
+
+ if (s->reset_flag != 0)
+ {
+ Speech_Encode_Frame_reset(s->enstate);
+ sid_sync_reset(s->sidstate);
+ }
+ return written;
+}
+
+
+#elif defined(CONFIG_AMR_NB) /* Float point version*/
+
+typedef struct AMRContext {
+ int frameCount;
+ void * decState;
+ int *enstate;
+ int enc_bitrate;
+} AMRContext;
+
+static int amr_nb_decode_init(AVCodecContext * avctx)
+{
+ AMRContext *s = avctx->priv_data;
+
+ s->frameCount=0;
+ s->decState=Decoder_Interface_init();
+ if(!s->decState)
+ {
+ av_log(avctx, AV_LOG_ERROR, "Decoder_Interface_init error\r\n");
+ return -1;
+ }
+
+ amr_decode_fix_avctx(avctx);
+
+ if(avctx->channels > 1)
+ {
+ av_log(avctx, AV_LOG_ERROR, "amr_nb: multichannel decoding not supported\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+static int amr_nb_encode_init(AVCodecContext * avctx)
+{
+ AMRContext *s = avctx->priv_data;
+
+ s->frameCount=0;
+
+ if(avctx->sample_rate!=8000)
+ {
+ av_log(avctx, AV_LOG_ERROR, "Only 8000Hz sample rate supported\n");
+ return -1;
+ }
+
+ if(avctx->channels!=1)
+ {
+ av_log(avctx, AV_LOG_ERROR, "Only mono supported\n");
+ return -1;
+ }
+
+ avctx->frame_size=160;
+ avctx->coded_frame= avcodec_alloc_frame();
+
+ s->enstate=Encoder_Interface_init(0);
+ if(!s->enstate)
+ {
+ av_log(avctx, AV_LOG_ERROR, "Encoder_Interface_init error\n");
+ return -1;
+ }
+
+ if((s->enc_bitrate=getBitrateMode(avctx->bit_rate))<0)
+ {
+ av_log(avctx, AV_LOG_ERROR, "bitrate not supported\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+static int amr_nb_decode_close(AVCodecContext * avctx)
+{
+ AMRContext *s = avctx->priv_data;
+
+ Decoder_Interface_exit(s->decState);
+ return 0;
+}
+
+static int amr_nb_encode_close(AVCodecContext * avctx)
+{
+ AMRContext *s = avctx->priv_data;
+
+ Encoder_Interface_exit(s->enstate);
+ av_freep(&avctx->coded_frame);
+ return 0;
+}
+
+static int amr_nb_decode_frame(AVCodecContext * avctx,
+ void *data, int *data_size,
+ uint8_t * buf, int buf_size)
+{
+ AMRContext *s = avctx->priv_data;
+ uint8_t*amrData=buf;
+ static short block_size[16]={ 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0 };
+ enum Mode dec_mode;
+ int packet_size;
+
+ /* av_log(NULL,AV_LOG_DEBUG,"amr_decode_frame buf=%p buf_size=%d frameCount=%d!!\n",buf,buf_size,s->frameCount); */
+
+ dec_mode = (buf[0] >> 3) & 0x000F;
+ packet_size = block_size[dec_mode]+1;
+
+ if(packet_size > buf_size) {
+ av_log(avctx, AV_LOG_ERROR, "amr frame too short (%u, should be %u)\n", buf_size, packet_size);
+ return -1;
+ }
+
+ s->frameCount++;
+ /* av_log(NULL,AV_LOG_DEBUG,"packet_size=%d amrData= 0x%X %X %X %X\n",packet_size,amrData[0],amrData[1],amrData[2],amrData[3]); */
+ /* call decoder */
+ Decoder_Interface_Decode(s->decState, amrData, data, 0);
+ *data_size=160*2;
+
+ return packet_size;
+}
+
+static int amr_nb_encode_frame(AVCodecContext *avctx,
+ unsigned char *frame/*out*/, int buf_size, void *data/*in*/)
+{
+ AMRContext *s = avctx->priv_data;
+ int written;
+
+ if((s->enc_bitrate=getBitrateMode(avctx->bit_rate))<0)
+ {
+ av_log(avctx, AV_LOG_ERROR, "bitrate not supported\n");
+ return -1;
+ }
+
+ written = Encoder_Interface_Encode(s->enstate,
+ s->enc_bitrate,
+ data,
+ frame,
+ 0);
+ /* av_log(NULL,AV_LOG_DEBUG,"amr_nb_encode_frame encoded %u bytes, bitrate %u, first byte was %#02x\n",written, s->enc_bitrate, frame[0] ); */
+
+ return written;
+}
+
+#endif
+
+#if defined(CONFIG_AMR_NB) || defined(CONFIG_AMR_NB_FIXED)
+
+AVCodec amr_nb_decoder =
+{
+ "amr_nb",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_AMR_NB,
+ sizeof(AMRContext),
+ amr_nb_decode_init,
+ NULL,
+ amr_nb_decode_close,
+ amr_nb_decode_frame,
+};
+
+AVCodec amr_nb_encoder =
+{
+ "amr_nb",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_AMR_NB,
+ sizeof(AMRContext),
+ amr_nb_encode_init,
+ amr_nb_encode_frame,
+ amr_nb_encode_close,
+ NULL,
+};
+
+#endif
+
+/* -----------AMR wideband ------------*/
+#ifdef CONFIG_AMR_WB
+
+#ifdef _TYPEDEF_H
+//To avoid duplicate typedefs from typdef in amr-nb
+#define typedef_h
+#endif
+
+#include "amrwb_float/enc_if.h"
+#include "amrwb_float/dec_if.h"
+
+/* Common code for fixed and float version*/
+typedef struct AMRWB_bitrates
+{
+ int rate;
+ int mode;
+} AMRWB_bitrates;
+
+static int getWBBitrateMode(int bitrate)
+{
+ /* make the correspondance between bitrate and mode */
+ AMRWB_bitrates rates[]={ {6600,0},
+ {8850,1},
+ {12650,2},
+ {14250,3},
+ {15850,4},
+ {18250,5},
+ {19850,6},
+ {23050,7},
+ {23850,8},
+ };
+ int i;
+
+ for(i=0;i<9;i++)
+ {
+ if(rates[i].rate==bitrate)
+ {
+ return(rates[i].mode);
+ }
+ }
+ /* no bitrate matching, return an error */
+ return -1;
+}
+
+
+typedef struct AMRWBContext {
+ int frameCount;
+ void *state;
+ int mode;
+ Word16 allow_dtx;
+} AMRWBContext;
+
+static int amr_wb_encode_init(AVCodecContext * avctx)
+{
+ AMRWBContext *s = avctx->priv_data;
+
+ s->frameCount=0;
+
+ if(avctx->sample_rate!=16000)
+ {
+ av_log(avctx, AV_LOG_ERROR, "Only 16000Hz sample rate supported\n");
+ return -1;
+ }
+
+ if(avctx->channels!=1)
+ {
+ av_log(avctx, AV_LOG_ERROR, "Only mono supported\n");
+ return -1;
+ }
+
+ if((s->mode=getWBBitrateMode(avctx->bit_rate))<0)
+ {
+ av_log(avctx, AV_LOG_ERROR, "bitrate not supported\n");
+ return -1;
+ }
+
+ avctx->frame_size=320;
+ avctx->coded_frame= avcodec_alloc_frame();
+
+ s->state = E_IF_init();
+ s->allow_dtx=0;
+
+ return 0;
+}
+
+static int amr_wb_encode_close(AVCodecContext * avctx)
+{
+ AMRWBContext *s = avctx->priv_data;
+
+ E_IF_exit(s->state);
+ av_freep(&avctx->coded_frame);
+ s->frameCount++;
+ return 0;
+}
+
+static int amr_wb_encode_frame(AVCodecContext *avctx,
+ unsigned char *frame/*out*/, int buf_size, void *data/*in*/)
+{
+ AMRWBContext *s = avctx->priv_data;
+ int size;
+
+ if((s->mode=getWBBitrateMode(avctx->bit_rate))<0)
+ {
+ av_log(avctx, AV_LOG_ERROR, "bitrate not supported\n");
+ return -1;
+ }
+ size = E_IF_encode(s->state, s->mode, data, frame, s->allow_dtx);
+ return size;
+}
+
+static int amr_wb_decode_init(AVCodecContext * avctx)
+{
+ AMRWBContext *s = avctx->priv_data;
+
+ s->frameCount=0;
+ s->state = D_IF_init();
+
+ amr_decode_fix_avctx(avctx);
+
+ if(avctx->channels > 1)
+ {
+ av_log(avctx, AV_LOG_ERROR, "amr_wb: multichannel decoding not supported\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+extern const UWord8 block_size[];
+
+static int amr_wb_decode_frame(AVCodecContext * avctx,
+ void *data, int *data_size,
+ uint8_t * buf, int buf_size)
+{
+ AMRWBContext *s = avctx->priv_data;
+ uint8_t*amrData=buf;
+ int mode;
+ int packet_size;
+
+ if(buf_size==0) {
+ /* nothing to do */
+ return 0;
+ }
+
+ mode = (amrData[0] >> 3) & 0x000F;
+ packet_size = block_size[mode];
+
+ if(packet_size > buf_size) {
+ av_log(avctx, AV_LOG_ERROR, "amr frame too short (%u, should be %u)\n", buf_size, packet_size+1);
+ return -1;
+ }
+
+ s->frameCount++;
+ D_IF_decode( s->state, amrData, data, _good_frame);
+ *data_size=320*2;
+ return packet_size;
+}
+
+static int amr_wb_decode_close(AVCodecContext * avctx)
+{
+ AMRWBContext *s = avctx->priv_data;
+
+ D_IF_exit(s->state);
+ return 0;
+}
+
+AVCodec amr_wb_decoder =
+{
+ "amr_wb",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_AMR_WB,
+ sizeof(AMRWBContext),
+ amr_wb_decode_init,
+ NULL,
+ amr_wb_decode_close,
+ amr_wb_decode_frame,
+};
+
+AVCodec amr_wb_encoder =
+{
+ "amr_wb",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_AMR_WB,
+ sizeof(AMRWBContext),
+ amr_wb_encode_init,
+ amr_wb_encode_frame,
+ amr_wb_encode_close,
+ NULL,
+};
+
+#endif //CONFIG_AMR_WB
diff --git a/contrib/ffmpeg/libavcodec/apiexample.c b/contrib/ffmpeg/libavcodec/apiexample.c
new file mode 100644
index 000000000..151637bd2
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/apiexample.c
@@ -0,0 +1,454 @@
+/*
+ * copyright (c) 2001 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 apiexample.c
+ * avcodec API use example.
+ *
+ * Note that this library only handles codecs (mpeg, mpeg4, etc...),
+ * not file formats (avi, vob, etc...). See library 'libavformat' for the
+ * format handling
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+
+#define PI 3.14159265358979323846
+
+#ifdef HAVE_AV_CONFIG_H
+#undef HAVE_AV_CONFIG_H
+#endif
+
+#include "avcodec.h"
+
+#define INBUF_SIZE 4096
+
+/*
+ * Audio encoding example
+ */
+void audio_encode_example(const char *filename)
+{
+ AVCodec *codec;
+ AVCodecContext *c= NULL;
+ int frame_size, i, j, out_size, outbuf_size;
+ FILE *f;
+ short *samples;
+ float t, tincr;
+ uint8_t *outbuf;
+
+ printf("Audio encoding\n");
+
+ /* find the MP2 encoder */
+ codec = avcodec_find_encoder(CODEC_ID_MP2);
+ if (!codec) {
+ fprintf(stderr, "codec not found\n");
+ exit(1);
+ }
+
+ c= avcodec_alloc_context();
+
+ /* put sample parameters */
+ c->bit_rate = 64000;
+ c->sample_rate = 44100;
+ c->channels = 2;
+
+ /* open it */
+ if (avcodec_open(c, codec) < 0) {
+ fprintf(stderr, "could not open codec\n");
+ exit(1);
+ }
+
+ /* the codec gives us the frame size, in samples */
+ frame_size = c->frame_size;
+ samples = malloc(frame_size * 2 * c->channels);
+ outbuf_size = 10000;
+ outbuf = malloc(outbuf_size);
+
+ f = fopen(filename, "wb");
+ if (!f) {
+ fprintf(stderr, "could not open %s\n", filename);
+ exit(1);
+ }
+
+ /* encode a single tone sound */
+ t = 0;
+ tincr = 2 * PI * 440.0 / c->sample_rate;
+ for(i=0;i<200;i++) {
+ for(j=0;j<frame_size;j++) {
+ samples[2*j] = (int)(sin(t) * 10000);
+ samples[2*j+1] = samples[2*j];
+ t += tincr;
+ }
+ /* encode the samples */
+ out_size = avcodec_encode_audio(c, outbuf, outbuf_size, samples);
+ fwrite(outbuf, 1, out_size, f);
+ }
+ fclose(f);
+ free(outbuf);
+ free(samples);
+
+ avcodec_close(c);
+ av_free(c);
+}
+
+/*
+ * Audio decoding.
+ */
+void audio_decode_example(const char *outfilename, const char *filename)
+{
+ AVCodec *codec;
+ AVCodecContext *c= NULL;
+ int out_size, size, len;
+ FILE *f, *outfile;
+ uint8_t *outbuf;
+ uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE], *inbuf_ptr;
+
+ printf("Audio decoding\n");
+
+ /* find the mpeg audio decoder */
+ codec = avcodec_find_decoder(CODEC_ID_MP2);
+ if (!codec) {
+ fprintf(stderr, "codec not found\n");
+ exit(1);
+ }
+
+ c= avcodec_alloc_context();
+
+ /* open it */
+ if (avcodec_open(c, codec) < 0) {
+ fprintf(stderr, "could not open codec\n");
+ exit(1);
+ }
+
+ outbuf = malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE);
+
+ f = fopen(filename, "rb");
+ if (!f) {
+ fprintf(stderr, "could not open %s\n", filename);
+ exit(1);
+ }
+ outfile = fopen(outfilename, "wb");
+ if (!outfile) {
+ av_free(c);
+ exit(1);
+ }
+
+ /* decode until eof */
+ inbuf_ptr = inbuf;
+ for(;;) {
+ size = fread(inbuf, 1, INBUF_SIZE, f);
+ if (size == 0)
+ break;
+
+ inbuf_ptr = inbuf;
+ while (size > 0) {
+ len = avcodec_decode_audio(c, (short *)outbuf, &out_size,
+ inbuf_ptr, size);
+ 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);
+ }
+ size -= len;
+ inbuf_ptr += len;
+ }
+ }
+
+ fclose(outfile);
+ fclose(f);
+ free(outbuf);
+
+ avcodec_close(c);
+ av_free(c);
+}
+
+/*
+ * Video encoding example
+ */
+void video_encode_example(const char *filename)
+{
+ AVCodec *codec;
+ AVCodecContext *c= NULL;
+ int i, out_size, size, x, y, outbuf_size;
+ FILE *f;
+ AVFrame *picture;
+ uint8_t *outbuf, *picture_buf;
+
+ printf("Video encoding\n");
+
+ /* find the mpeg1 video encoder */
+ codec = avcodec_find_encoder(CODEC_ID_MPEG1VIDEO);
+ if (!codec) {
+ fprintf(stderr, "codec not found\n");
+ exit(1);
+ }
+
+ c= avcodec_alloc_context();
+ picture= avcodec_alloc_frame();
+
+ /* put sample parameters */
+ c->bit_rate = 400000;
+ /* resolution must be a multiple of two */
+ c->width = 352;
+ c->height = 288;
+ /* frames per second */
+ c->time_base= (AVRational){1,25};
+ c->gop_size = 10; /* emit one intra frame every ten frames */
+ c->max_b_frames=1;
+ c->pix_fmt = PIX_FMT_YUV420P;
+
+ /* open it */
+ if (avcodec_open(c, codec) < 0) {
+ fprintf(stderr, "could not open codec\n");
+ exit(1);
+ }
+
+ f = fopen(filename, "wb");
+ if (!f) {
+ fprintf(stderr, "could not open %s\n", filename);
+ exit(1);
+ }
+
+ /* alloc image and output buffer */
+ outbuf_size = 100000;
+ outbuf = malloc(outbuf_size);
+ size = c->width * c->height;
+ picture_buf = malloc((size * 3) / 2); /* size for YUV 420 */
+
+ picture->data[0] = picture_buf;
+ picture->data[1] = picture->data[0] + size;
+ picture->data[2] = picture->data[1] + size / 4;
+ picture->linesize[0] = c->width;
+ picture->linesize[1] = c->width / 2;
+ picture->linesize[2] = c->width / 2;
+
+ /* encode 1 second of video */
+ for(i=0;i<25;i++) {
+ fflush(stdout);
+ /* prepare a dummy image */
+ /* Y */
+ for(y=0;y<c->height;y++) {
+ for(x=0;x<c->width;x++) {
+ picture->data[0][y * picture->linesize[0] + x] = x + y + i * 3;
+ }
+ }
+
+ /* Cb and Cr */
+ for(y=0;y<c->height/2;y++) {
+ for(x=0;x<c->width/2;x++) {
+ picture->data[1][y * picture->linesize[1] + x] = 128 + y + i * 2;
+ picture->data[2][y * picture->linesize[2] + x] = 64 + x + i * 5;
+ }
+ }
+
+ /* encode the image */
+ out_size = avcodec_encode_video(c, outbuf, outbuf_size, picture);
+ printf("encoding frame %3d (size=%5d)\n", i, out_size);
+ fwrite(outbuf, 1, out_size, f);
+ }
+
+ /* get the delayed frames */
+ for(; out_size; i++) {
+ fflush(stdout);
+
+ out_size = avcodec_encode_video(c, outbuf, outbuf_size, NULL);
+ printf("write frame %3d (size=%5d)\n", i, out_size);
+ fwrite(outbuf, 1, out_size, f);
+ }
+
+ /* add sequence end code to have a real mpeg file */
+ outbuf[0] = 0x00;
+ outbuf[1] = 0x00;
+ outbuf[2] = 0x01;
+ outbuf[3] = 0xb7;
+ fwrite(outbuf, 1, 4, f);
+ fclose(f);
+ free(picture_buf);
+ free(outbuf);
+
+ avcodec_close(c);
+ av_free(c);
+ av_free(picture);
+ printf("\n");
+}
+
+/*
+ * Video decoding example
+ */
+
+void pgm_save(unsigned char *buf,int wrap, int xsize,int ysize,char *filename)
+{
+ FILE *f;
+ int i;
+
+ f=fopen(filename,"w");
+ fprintf(f,"P5\n%d %d\n%d\n",xsize,ysize,255);
+ for(i=0;i<ysize;i++)
+ fwrite(buf + i * wrap,1,xsize,f);
+ fclose(f);
+}
+
+void video_decode_example(const char *outfilename, const char *filename)
+{
+ AVCodec *codec;
+ AVCodecContext *c= NULL;
+ int frame, size, got_picture, len;
+ FILE *f;
+ AVFrame *picture;
+ uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE], *inbuf_ptr;
+ char buf[1024];
+
+ /* set end of buffer to 0 (this ensures that no overreading happens for damaged mpeg streams) */
+ memset(inbuf + INBUF_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+
+ printf("Video decoding\n");
+
+ /* find the mpeg1 video decoder */
+ codec = avcodec_find_decoder(CODEC_ID_MPEG1VIDEO);
+ if (!codec) {
+ fprintf(stderr, "codec not found\n");
+ exit(1);
+ }
+
+ c= avcodec_alloc_context();
+ picture= avcodec_alloc_frame();
+
+ if(codec->capabilities&CODEC_CAP_TRUNCATED)
+ c->flags|= CODEC_FLAG_TRUNCATED; /* we dont send complete frames */
+
+ /* for some codecs, such as msmpeg4 and mpeg4, width and height
+ MUST be initialized there because these info are not available
+ in the bitstream */
+
+ /* open it */
+ if (avcodec_open(c, codec) < 0) {
+ fprintf(stderr, "could not open codec\n");
+ exit(1);
+ }
+
+ /* the codec gives us the frame size, in samples */
+
+ f = fopen(filename, "rb");
+ if (!f) {
+ fprintf(stderr, "could not open %s\n", filename);
+ exit(1);
+ }
+
+ frame = 0;
+ for(;;) {
+ size = fread(inbuf, 1, INBUF_SIZE, f);
+ if (size == 0)
+ break;
+
+ /* NOTE1: some codecs are stream based (mpegvideo, mpegaudio)
+ and this is the only method to use them because you cannot
+ know the compressed data size before analysing it.
+
+ BUT some other codecs (msmpeg4, mpeg4) are inherently frame
+ based, so you must call them with all the data for one
+ frame exactly. You must also initialize 'width' and
+ 'height' before initializing them. */
+
+ /* NOTE2: some codecs allow the raw parameters (frame size,
+ sample rate) to be changed at any frame. We handle this, so
+ you should also take care of it */
+
+ /* here, we use a stream based decoder (mpeg1video), so we
+ feed decoder and see if it could decode a frame */
+ inbuf_ptr = inbuf;
+ while (size > 0) {
+ len = avcodec_decode_video(c, picture, &got_picture,
+ inbuf_ptr, size);
+ if (len < 0) {
+ fprintf(stderr, "Error while decoding frame %d\n", frame);
+ exit(1);
+ }
+ if (got_picture) {
+ printf("saving frame %3d\n", frame);
+ fflush(stdout);
+
+ /* the picture is allocated by the decoder. no need to
+ free it */
+ snprintf(buf, sizeof(buf), outfilename, frame);
+ pgm_save(picture->data[0], picture->linesize[0],
+ c->width, c->height, buf);
+ frame++;
+ }
+ size -= len;
+ inbuf_ptr += len;
+ }
+ }
+
+ /* some codecs, such as MPEG, transmit the I and P frame with a
+ latency of one frame. You must do the following to have a
+ chance to get the last frame of the video */
+ len = avcodec_decode_video(c, picture, &got_picture,
+ NULL, 0);
+ if (got_picture) {
+ printf("saving last frame %3d\n", frame);
+ fflush(stdout);
+
+ /* the picture is allocated by the decoder. no need to
+ free it */
+ snprintf(buf, sizeof(buf), outfilename, frame);
+ pgm_save(picture->data[0], picture->linesize[0],
+ c->width, c->height, buf);
+ frame++;
+ }
+
+ fclose(f);
+
+ avcodec_close(c);
+ av_free(c);
+ av_free(picture);
+ printf("\n");
+}
+
+int main(int argc, char **argv)
+{
+ const char *filename;
+
+ /* must be called before using avcodec lib */
+ avcodec_init();
+
+ /* register all the codecs (you can also register only the codec
+ you wish to have smaller code */
+ avcodec_register_all();
+
+ if (argc <= 1) {
+ audio_encode_example("/tmp/test.mp2");
+ audio_decode_example("/tmp/test.sw", "/tmp/test.mp2");
+
+ video_encode_example("/tmp/test.mpg");
+ filename = "/tmp/test.mpg";
+ } else {
+ filename = argv[1];
+ }
+
+ // audio_decode_example("/tmp/test.sw", filename);
+ video_decode_example("/tmp/test%d.pgm", filename);
+
+ return 0;
+}
diff --git a/contrib/ffmpeg/libavcodec/armv4l/dsputil_arm.c b/contrib/ffmpeg/libavcodec/armv4l/dsputil_arm.c
new file mode 100644
index 000000000..61b5fdacc
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/armv4l/dsputil_arm.c
@@ -0,0 +1,277 @@
+/*
+ * ARMv4L optimized DSP utils
+ * Copyright (c) 2001 Lionel Ulmer.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 "../dsputil.h"
+#ifdef HAVE_IPP
+#include "ipp.h"
+#endif
+
+extern void dsputil_init_iwmmxt(DSPContext* c, AVCodecContext *avctx);
+
+extern void j_rev_dct_ARM(DCTELEM *data);
+extern void simple_idct_ARM(DCTELEM *data);
+
+extern void simple_idct_armv5te(DCTELEM *data);
+extern void simple_idct_put_armv5te(uint8_t *dest, int line_size,
+ DCTELEM *data);
+extern void simple_idct_add_armv5te(uint8_t *dest, int line_size,
+ DCTELEM *data);
+
+extern void ff_simple_idct_armv6(DCTELEM *data);
+extern void ff_simple_idct_put_armv6(uint8_t *dest, int line_size,
+ DCTELEM *data);
+extern void ff_simple_idct_add_armv6(uint8_t *dest, int line_size,
+ DCTELEM *data);
+
+/* XXX: local hack */
+static void (*ff_put_pixels_clamped)(const DCTELEM *block, uint8_t *pixels, int line_size);
+static void (*ff_add_pixels_clamped)(const DCTELEM *block, uint8_t *pixels, int line_size);
+
+void put_pixels8_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h);
+void put_pixels8_x2_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h);
+void put_pixels8_y2_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h);
+void put_pixels8_xy2_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h);
+
+void put_no_rnd_pixels8_x2_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h);
+void put_no_rnd_pixels8_y2_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h);
+void put_no_rnd_pixels8_xy2_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h);
+
+void put_pixels16_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h);
+
+CALL_2X_PIXELS(put_pixels16_x2_arm , put_pixels8_x2_arm , 8)
+CALL_2X_PIXELS(put_pixels16_y2_arm , put_pixels8_y2_arm , 8)
+CALL_2X_PIXELS(put_pixels16_xy2_arm, put_pixels8_xy2_arm, 8)
+CALL_2X_PIXELS(put_no_rnd_pixels16_x2_arm , put_no_rnd_pixels8_x2_arm , 8)
+CALL_2X_PIXELS(put_no_rnd_pixels16_y2_arm , put_no_rnd_pixels8_y2_arm , 8)
+CALL_2X_PIXELS(put_no_rnd_pixels16_xy2_arm, put_no_rnd_pixels8_xy2_arm, 8)
+
+static void add_pixels_clamped_ARM(short *block, unsigned char *dest, int line_size)
+{
+ asm volatile (
+ "mov r10, #8 \n\t"
+
+ "1: \n\t"
+
+ /* load dest */
+ "ldr r4, [%1] \n\t"
+ /* block[0] and block[1]*/
+ "ldrsh r5, [%0] \n\t"
+ "ldrsh r7, [%0, #2] \n\t"
+ "and r6, r4, #0xFF \n\t"
+ "and r8, r4, #0xFF00 \n\t"
+ "add r6, r5, r6 \n\t"
+ "add r8, r7, r8, lsr #8 \n\t"
+ "mvn r5, r5 \n\t"
+ "mvn r7, r7 \n\t"
+ "tst r6, #0x100 \n\t"
+ "movne r6, r5, lsr #24 \n\t"
+ "tst r8, #0x100 \n\t"
+ "movne r8, r7, lsr #24 \n\t"
+ "mov r9, r6 \n\t"
+ "ldrsh r5, [%0, #4] \n\t" /* moved form [A] */
+ "orr r9, r9, r8, lsl #8 \n\t"
+ /* block[2] and block[3] */
+ /* [A] */
+ "ldrsh r7, [%0, #6] \n\t"
+ "and r6, r4, #0xFF0000 \n\t"
+ "and r8, r4, #0xFF000000 \n\t"
+ "add r6, r5, r6, lsr #16 \n\t"
+ "add r8, r7, r8, lsr #24 \n\t"
+ "mvn r5, r5 \n\t"
+ "mvn r7, r7 \n\t"
+ "tst r6, #0x100 \n\t"
+ "movne r6, r5, lsr #24 \n\t"
+ "tst r8, #0x100 \n\t"
+ "movne r8, r7, lsr #24 \n\t"
+ "orr r9, r9, r6, lsl #16 \n\t"
+ "ldr r4, [%1, #4] \n\t" /* moved form [B] */
+ "orr r9, r9, r8, lsl #24 \n\t"
+ /* store dest */
+ "ldrsh r5, [%0, #8] \n\t" /* moved form [C] */
+ "str r9, [%1] \n\t"
+
+ /* load dest */
+ /* [B] */
+ /* block[4] and block[5] */
+ /* [C] */
+ "ldrsh r7, [%0, #10] \n\t"
+ "and r6, r4, #0xFF \n\t"
+ "and r8, r4, #0xFF00 \n\t"
+ "add r6, r5, r6 \n\t"
+ "add r8, r7, r8, lsr #8 \n\t"
+ "mvn r5, r5 \n\t"
+ "mvn r7, r7 \n\t"
+ "tst r6, #0x100 \n\t"
+ "movne r6, r5, lsr #24 \n\t"
+ "tst r8, #0x100 \n\t"
+ "movne r8, r7, lsr #24 \n\t"
+ "mov r9, r6 \n\t"
+ "ldrsh r5, [%0, #12] \n\t" /* moved from [D] */
+ "orr r9, r9, r8, lsl #8 \n\t"
+ /* block[6] and block[7] */
+ /* [D] */
+ "ldrsh r7, [%0, #14] \n\t"
+ "and r6, r4, #0xFF0000 \n\t"
+ "and r8, r4, #0xFF000000 \n\t"
+ "add r6, r5, r6, lsr #16 \n\t"
+ "add r8, r7, r8, lsr #24 \n\t"
+ "mvn r5, r5 \n\t"
+ "mvn r7, r7 \n\t"
+ "tst r6, #0x100 \n\t"
+ "movne r6, r5, lsr #24 \n\t"
+ "tst r8, #0x100 \n\t"
+ "movne r8, r7, lsr #24 \n\t"
+ "orr r9, r9, r6, lsl #16 \n\t"
+ "add %0, %0, #16 \n\t" /* moved from [E] */
+ "orr r9, r9, r8, lsl #24 \n\t"
+ "subs r10, r10, #1 \n\t" /* moved from [F] */
+ /* store dest */
+ "str r9, [%1, #4] \n\t"
+
+ /* [E] */
+ /* [F] */
+ "add %1, %1, %2 \n\t"
+ "bne 1b \n\t"
+ : "+r"(block),
+ "+r"(dest)
+ : "r"(line_size)
+ : "r4", "r5", "r6", "r7", "r8", "r9", "r10", "cc", "memory" );
+}
+
+/* XXX: those functions should be suppressed ASAP when all IDCTs are
+ converted */
+static void j_rev_dct_ARM_put(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ j_rev_dct_ARM (block);
+ ff_put_pixels_clamped(block, dest, line_size);
+}
+static void j_rev_dct_ARM_add(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ j_rev_dct_ARM (block);
+ ff_add_pixels_clamped(block, dest, line_size);
+}
+static void simple_idct_ARM_put(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ simple_idct_ARM (block);
+ ff_put_pixels_clamped(block, dest, line_size);
+}
+static void simple_idct_ARM_add(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ simple_idct_ARM (block);
+ ff_add_pixels_clamped(block, dest, line_size);
+}
+
+#ifdef HAVE_IPP
+static void simple_idct_ipp(DCTELEM *block)
+{
+ ippiDCT8x8Inv_Video_16s_C1I(block);
+}
+static void simple_idct_ipp_put(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ ippiDCT8x8Inv_Video_16s8u_C1R(block, dest, line_size);
+}
+
+void add_pixels_clamped_iwmmxt(const DCTELEM *block, uint8_t *pixels, int line_size);
+
+static void simple_idct_ipp_add(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ ippiDCT8x8Inv_Video_16s_C1I(block);
+#ifdef HAVE_IWMMXT
+ add_pixels_clamped_iwmmxt(block, dest, line_size);
+#else
+ add_pixels_clamped_ARM(block, dest, line_size);
+#endif
+}
+#endif
+
+void dsputil_init_armv4l(DSPContext* c, AVCodecContext *avctx)
+{
+ int idct_algo= avctx->idct_algo;
+
+ ff_put_pixels_clamped = c->put_pixels_clamped;
+ ff_add_pixels_clamped = c->add_pixels_clamped;
+
+ if(idct_algo == FF_IDCT_AUTO){
+#if defined(HAVE_IPP)
+ idct_algo = FF_IDCT_IPP;
+#elif defined(HAVE_ARMV6)
+ idct_algo = FF_IDCT_SIMPLEARMV6;
+#elif defined(HAVE_ARMV5TE)
+ idct_algo = FF_IDCT_SIMPLEARMV5TE;
+#else
+ idct_algo = FF_IDCT_ARM;
+#endif
+ }
+
+ if(idct_algo==FF_IDCT_ARM){
+ c->idct_put= j_rev_dct_ARM_put;
+ c->idct_add= j_rev_dct_ARM_add;
+ c->idct = j_rev_dct_ARM;
+ c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;/* FF_NO_IDCT_PERM */
+ } else if (idct_algo==FF_IDCT_SIMPLEARM){
+ c->idct_put= simple_idct_ARM_put;
+ c->idct_add= simple_idct_ARM_add;
+ c->idct = simple_idct_ARM;
+ c->idct_permutation_type= FF_NO_IDCT_PERM;
+#ifdef HAVE_ARMV6
+ } else if (idct_algo==FF_IDCT_SIMPLEARMV6){
+ c->idct_put= ff_simple_idct_put_armv6;
+ c->idct_add= ff_simple_idct_add_armv6;
+ c->idct = ff_simple_idct_armv6;
+ c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
+#endif
+#ifdef HAVE_ARMV5TE
+ } else if (idct_algo==FF_IDCT_SIMPLEARMV5TE){
+ c->idct_put= simple_idct_put_armv5te;
+ c->idct_add= simple_idct_add_armv5te;
+ c->idct = simple_idct_armv5te;
+ c->idct_permutation_type = FF_NO_IDCT_PERM;
+#endif
+#ifdef HAVE_IPP
+ } else if (idct_algo==FF_IDCT_IPP){
+ c->idct_put= simple_idct_ipp_put;
+ c->idct_add= simple_idct_ipp_add;
+ c->idct = simple_idct_ipp;
+ c->idct_permutation_type= FF_NO_IDCT_PERM;
+#endif
+ }
+
+/* c->put_pixels_tab[0][0] = put_pixels16_arm; */ // NG!
+ c->put_pixels_tab[0][1] = put_pixels16_x2_arm; //OK!
+ c->put_pixels_tab[0][2] = put_pixels16_y2_arm; //OK!
+/* c->put_pixels_tab[0][3] = put_pixels16_xy2_arm; /\* NG *\/ */
+/* c->put_no_rnd_pixels_tab[0][0] = put_pixels16_arm; */
+ c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_arm; // OK
+ c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_arm; //OK
+/* c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy2_arm; //NG */
+ c->put_pixels_tab[1][0] = put_pixels8_arm; //OK
+ c->put_pixels_tab[1][1] = put_pixels8_x2_arm; //OK
+/* c->put_pixels_tab[1][2] = put_pixels8_y2_arm; //NG */
+/* c->put_pixels_tab[1][3] = put_pixels8_xy2_arm; //NG */
+ c->put_no_rnd_pixels_tab[1][0] = put_pixels8_arm;//OK
+ c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_arm; //OK
+ c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_arm; //OK
+/* c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels8_xy2_arm;//NG */
+
+#ifdef HAVE_IWMMXT
+ dsputil_init_iwmmxt(c, avctx);
+#endif
+}
diff --git a/src/libffmpeg/libavcodec/armv4l/dsputil_arm_s.S b/contrib/ffmpeg/libavcodec/armv4l/dsputil_arm_s.S
index 2a3ee9c50..2a3ee9c50 100644
--- a/src/libffmpeg/libavcodec/armv4l/dsputil_arm_s.S
+++ b/contrib/ffmpeg/libavcodec/armv4l/dsputil_arm_s.S
diff --git a/contrib/ffmpeg/libavcodec/armv4l/dsputil_iwmmxt.c b/contrib/ffmpeg/libavcodec/armv4l/dsputil_iwmmxt.c
new file mode 100644
index 000000000..7536100ee
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/armv4l/dsputil_iwmmxt.c
@@ -0,0 +1,184 @@
+/*
+ * iWMMXt optimized DSP utils
+ * Copyright (c) 2004 AGAWA Koji
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 "../dsputil.h"
+
+#define DEF(x, y) x ## _no_rnd_ ## y ##_iwmmxt
+#define SET_RND(regd) __asm__ __volatile__ ("mov r12, #1 \n\t tbcsth " #regd ", r12":::"r12");
+#define WAVG2B "wavg2b"
+#include "dsputil_iwmmxt_rnd.h"
+#undef DEF
+#undef SET_RND
+#undef WAVG2B
+
+#define DEF(x, y) x ## _ ## y ##_iwmmxt
+#define SET_RND(regd) __asm__ __volatile__ ("mov r12, #2 \n\t tbcsth " #regd ", r12":::"r12");
+#define WAVG2B "wavg2br"
+#include "dsputil_iwmmxt_rnd.h"
+#undef DEF
+#undef SET_RND
+#undef WAVG2BR
+
+// need scheduling
+#define OP(AVG) \
+ asm volatile ( \
+ /* alignment */ \
+ "and r12, %[pixels], #7 \n\t" \
+ "bic %[pixels], %[pixels], #7 \n\t" \
+ "tmcr wcgr1, r12 \n\t" \
+ \
+ "wldrd wr0, [%[pixels]] \n\t" \
+ "wldrd wr1, [%[pixels], #8] \n\t" \
+ "add %[pixels], %[pixels], %[line_size] \n\t" \
+ "walignr1 wr4, wr0, wr1 \n\t" \
+ \
+ "1: \n\t" \
+ \
+ "wldrd wr2, [%[pixels]] \n\t" \
+ "wldrd wr3, [%[pixels], #8] \n\t" \
+ "add %[pixels], %[pixels], %[line_size] \n\t" \
+ "pld [%[pixels]] \n\t" \
+ "walignr1 wr5, wr2, wr3 \n\t" \
+ AVG " wr6, wr4, wr5 \n\t" \
+ "wstrd wr6, [%[block]] \n\t" \
+ "add %[block], %[block], %[line_size] \n\t" \
+ \
+ "wldrd wr0, [%[pixels]] \n\t" \
+ "wldrd wr1, [%[pixels], #8] \n\t" \
+ "add %[pixels], %[pixels], %[line_size] \n\t" \
+ "walignr1 wr4, wr0, wr1 \n\t" \
+ "pld [%[pixels]] \n\t" \
+ AVG " wr6, wr4, wr5 \n\t" \
+ "wstrd wr6, [%[block]] \n\t" \
+ "add %[block], %[block], %[line_size] \n\t" \
+ \
+ "subs %[h], %[h], #2 \n\t" \
+ "bne 1b \n\t" \
+ : [block]"+r"(block), [pixels]"+r"(pixels), [h]"+r"(h) \
+ : [line_size]"r"(line_size) \
+ : "memory", "r12");
+void put_pixels8_y2_iwmmxt(uint8_t *block, const uint8_t *pixels, const int line_size, int h)
+{
+ OP("wavg2br");
+}
+void put_no_rnd_pixels8_y2_iwmmxt(uint8_t *block, const uint8_t *pixels, const int line_size, int h)
+{
+ OP("wavg2b");
+}
+#undef OP
+
+void add_pixels_clamped_iwmmxt(const DCTELEM *block, uint8_t *pixels, int line_size)
+{
+ uint8_t *pixels2 = pixels + line_size;
+
+ __asm__ __volatile__ (
+ "mov r12, #4 \n\t"
+ "1: \n\t"
+ "pld [%[pixels], %[line_size2]] \n\t"
+ "pld [%[pixels2], %[line_size2]] \n\t"
+ "wldrd wr4, [%[pixels]] \n\t"
+ "wldrd wr5, [%[pixels2]] \n\t"
+ "pld [%[block], #32] \n\t"
+ "wunpckelub wr6, wr4 \n\t"
+ "wldrd wr0, [%[block]] \n\t"
+ "wunpckehub wr7, wr4 \n\t"
+ "wldrd wr1, [%[block], #8] \n\t"
+ "wunpckelub wr8, wr5 \n\t"
+ "wldrd wr2, [%[block], #16] \n\t"
+ "wunpckehub wr9, wr5 \n\t"
+ "wldrd wr3, [%[block], #24] \n\t"
+ "add %[block], %[block], #32 \n\t"
+ "waddhss wr10, wr0, wr6 \n\t"
+ "waddhss wr11, wr1, wr7 \n\t"
+ "waddhss wr12, wr2, wr8 \n\t"
+ "waddhss wr13, wr3, wr9 \n\t"
+ "wpackhus wr14, wr10, wr11 \n\t"
+ "wpackhus wr15, wr12, wr13 \n\t"
+ "wstrd wr14, [%[pixels]] \n\t"
+ "add %[pixels], %[pixels], %[line_size2] \n\t"
+ "subs r12, r12, #1 \n\t"
+ "wstrd wr15, [%[pixels2]] \n\t"
+ "add %[pixels2], %[pixels2], %[line_size2] \n\t"
+ "bne 1b \n\t"
+ : [block]"+r"(block), [pixels]"+r"(pixels), [pixels2]"+r"(pixels2)
+ : [line_size2]"r"(line_size << 1)
+ : "cc", "memory", "r12");
+}
+
+static void nop(uint8_t *block, const uint8_t *pixels, int line_size, int h)
+{
+ return;
+}
+
+/* A run time test is not simple. If this file is compiled in
+ * then we should install the functions
+ */
+int mm_flags = MM_IWMMXT; /* multimedia extension flags */
+
+void dsputil_init_iwmmxt(DSPContext* c, AVCodecContext *avctx)
+{
+ if (avctx->dsp_mask) {
+ if (avctx->dsp_mask & FF_MM_FORCE)
+ mm_flags |= (avctx->dsp_mask & 0xffff);
+ else
+ mm_flags &= ~(avctx->dsp_mask & 0xffff);
+ }
+
+ if (!(mm_flags & MM_IWMMXT)) return;
+
+ c->add_pixels_clamped = add_pixels_clamped_iwmmxt;
+
+ c->put_pixels_tab[0][0] = put_pixels16_iwmmxt;
+ c->put_pixels_tab[0][1] = put_pixels16_x2_iwmmxt;
+ c->put_pixels_tab[0][2] = put_pixels16_y2_iwmmxt;
+ c->put_pixels_tab[0][3] = put_pixels16_xy2_iwmmxt;
+ c->put_no_rnd_pixels_tab[0][0] = put_pixels16_iwmmxt;
+ c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_iwmmxt;
+ c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_iwmmxt;
+ c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy2_iwmmxt;
+
+ c->put_pixels_tab[1][0] = put_pixels8_iwmmxt;
+ c->put_pixels_tab[1][1] = put_pixels8_x2_iwmmxt;
+ c->put_pixels_tab[1][2] = put_pixels8_y2_iwmmxt;
+ c->put_pixels_tab[1][3] = put_pixels8_xy2_iwmmxt;
+ c->put_no_rnd_pixels_tab[1][0] = put_pixels8_iwmmxt;
+ c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_iwmmxt;
+ c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_iwmmxt;
+ c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels8_xy2_iwmmxt;
+
+ c->avg_pixels_tab[0][0] = avg_pixels16_iwmmxt;
+ c->avg_pixels_tab[0][1] = avg_pixels16_x2_iwmmxt;
+ c->avg_pixels_tab[0][2] = avg_pixels16_y2_iwmmxt;
+ c->avg_pixels_tab[0][3] = avg_pixels16_xy2_iwmmxt;
+ c->avg_no_rnd_pixels_tab[0][0] = avg_pixels16_iwmmxt;
+ c->avg_no_rnd_pixels_tab[0][1] = avg_no_rnd_pixels16_x2_iwmmxt;
+ c->avg_no_rnd_pixels_tab[0][2] = avg_no_rnd_pixels16_y2_iwmmxt;
+ c->avg_no_rnd_pixels_tab[0][3] = avg_no_rnd_pixels16_xy2_iwmmxt;
+
+ c->avg_pixels_tab[1][0] = avg_pixels8_iwmmxt;
+ c->avg_pixels_tab[1][1] = avg_pixels8_x2_iwmmxt;
+ c->avg_pixels_tab[1][2] = avg_pixels8_y2_iwmmxt;
+ c->avg_pixels_tab[1][3] = avg_pixels8_xy2_iwmmxt;
+ c->avg_no_rnd_pixels_tab[1][0] = avg_no_rnd_pixels8_iwmmxt;
+ c->avg_no_rnd_pixels_tab[1][1] = avg_no_rnd_pixels8_x2_iwmmxt;
+ c->avg_no_rnd_pixels_tab[1][2] = avg_no_rnd_pixels8_y2_iwmmxt;
+ c->avg_no_rnd_pixels_tab[1][3] = avg_no_rnd_pixels8_xy2_iwmmxt;
+}
diff --git a/src/libffmpeg/libavcodec/armv4l/dsputil_iwmmxt_rnd.h b/contrib/ffmpeg/libavcodec/armv4l/dsputil_iwmmxt_rnd.h
index 51ba61c47..51ba61c47 100644
--- a/src/libffmpeg/libavcodec/armv4l/dsputil_iwmmxt_rnd.h
+++ b/contrib/ffmpeg/libavcodec/armv4l/dsputil_iwmmxt_rnd.h
diff --git a/src/libffmpeg/libavcodec/armv4l/jrevdct_arm.S b/contrib/ffmpeg/libavcodec/armv4l/jrevdct_arm.S
index 294ea4750..294ea4750 100644
--- a/src/libffmpeg/libavcodec/armv4l/jrevdct_arm.S
+++ b/contrib/ffmpeg/libavcodec/armv4l/jrevdct_arm.S
diff --git a/src/libffmpeg/libavcodec/armv4l/mathops.h b/contrib/ffmpeg/libavcodec/armv4l/mathops.h
index 7ddd0ec6e..7ddd0ec6e 100644
--- a/src/libffmpeg/libavcodec/armv4l/mathops.h
+++ b/contrib/ffmpeg/libavcodec/armv4l/mathops.h
diff --git a/contrib/ffmpeg/libavcodec/armv4l/mpegvideo_arm.c b/contrib/ffmpeg/libavcodec/armv4l/mpegvideo_arm.c
new file mode 100644
index 000000000..22d40d8bc
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/armv4l/mpegvideo_arm.c
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2002 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 "../dsputil.h"
+#include "../mpegvideo.h"
+#include "../avcodec.h"
+
+extern void MPV_common_init_iwmmxt(MpegEncContext *s);
+extern void MPV_common_init_armv5te(MpegEncContext *s);
+
+void MPV_common_init_armv4l(MpegEncContext *s)
+{
+ /* IWMMXT support is a superset of armv5te, so
+ * allow optimised functions for armv5te unless
+ * a better iwmmxt function exists
+ */
+#ifdef HAVE_ARMV5TE
+ MPV_common_init_armv5te(s);
+#endif
+#ifdef HAVE_IWMMXT
+ MPV_common_init_iwmmxt(s);
+#endif
+}
diff --git a/contrib/ffmpeg/libavcodec/armv4l/mpegvideo_armv5te.c b/contrib/ffmpeg/libavcodec/armv4l/mpegvideo_armv5te.c
new file mode 100644
index 000000000..5e83c8a43
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/armv4l/mpegvideo_armv5te.c
@@ -0,0 +1,213 @@
+/*
+ * Optimization of some functions from mpegvideo.c for armv5te
+ * Copyright (c) 2007 Siarhei Siamashka <ssvb@users.sourceforge.net>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*
+ * Some useful links for those who may be interested in optimizing code for ARM.
+ * ARM Architecture Reference Manual: http://www.arm.com/community/academy/resources.html
+ * Instructions timings and optimization guide for ARM9E: http://www.arm.com/pdfs/DDI0222B_9EJS_r1p2.pdf
+ */
+
+#include "../dsputil.h"
+#include "../mpegvideo.h"
+#include "../avcodec.h"
+
+
+#ifdef ENABLE_ARM_TESTS
+/**
+ * h263 dequantizer supplementary function, it is performance critical and needs to
+ * have optimized implementations for each architecture. Is also used as a reference
+ * implementation in regression tests
+ */
+static inline void dct_unquantize_h263_helper_c(DCTELEM *block, int qmul, int qadd, int count)
+{
+ int i, level;
+ for (i = 0; i < count; i++) {
+ level = block[i];
+ if (level) {
+ if (level < 0) {
+ level = level * qmul - qadd;
+ } else {
+ level = level * qmul + qadd;
+ }
+ block[i] = level;
+ }
+ }
+}
+#endif
+
+/* GCC 3.1 or higher is required to support symbolic names in assembly code */
+#if (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))
+
+/**
+ * Special optimized version of dct_unquantize_h263_helper_c, it requires the block
+ * to be at least 8 bytes aligned, and may process more elements than requested.
+ * But it is guaranteed to never process more than 64 elements provided that
+ * xxcount argument is <= 64, so it is safe. This macro is optimized for a common
+ * distribution of values for nCoeffs (they are mostly multiple of 8 plus one or
+ * two extra elements). So this macro processes data as 8 elements per loop iteration
+ * and contains optional 2 elements processing in the end.
+ *
+ * Inner loop should take 6 cycles per element on arm926ej-s (Nokia 770)
+ */
+#define dct_unquantize_h263_special_helper_armv5te(xxblock, xxqmul, xxqadd, xxcount) \
+({ DCTELEM *xblock = xxblock; \
+ int xqmul = xxqmul, xqadd = xxqadd, xcount = xxcount, xtmp; \
+ int xdata1, xdata2; \
+__asm__ __volatile__( \
+ "subs %[count], %[count], #2 \n\t" \
+ "ble 2f \n\t" \
+ "ldrd r4, [%[block], #0] \n\t" \
+ "1: \n\t" \
+ "ldrd r6, [%[block], #8] \n\t" \
+\
+ "rsbs %[data1], %[zero], r4, asr #16 \n\t" \
+ "addgt %[data1], %[qadd], #0 \n\t" \
+ "rsblt %[data1], %[qadd], #0 \n\t" \
+ "smlatbne %[data1], r4, %[qmul], %[data1] \n\t" \
+\
+ "rsbs %[data2], %[zero], r5, asr #16 \n\t" \
+ "addgt %[data2], %[qadd], #0 \n\t" \
+ "rsblt %[data2], %[qadd], #0 \n\t" \
+ "smlatbne %[data2], r5, %[qmul], %[data2] \n\t" \
+\
+ "rsbs %[tmp], %[zero], r4, asl #16 \n\t" \
+ "addgt %[tmp], %[qadd], #0 \n\t" \
+ "rsblt %[tmp], %[qadd], #0 \n\t" \
+ "smlabbne r4, r4, %[qmul], %[tmp] \n\t" \
+\
+ "rsbs %[tmp], %[zero], r5, asl #16 \n\t" \
+ "addgt %[tmp], %[qadd], #0 \n\t" \
+ "rsblt %[tmp], %[qadd], #0 \n\t" \
+ "smlabbne r5, r5, %[qmul], %[tmp] \n\t" \
+\
+ "strh r4, [%[block]], #2 \n\t" \
+ "strh %[data1], [%[block]], #2 \n\t" \
+ "strh r5, [%[block]], #2 \n\t" \
+ "strh %[data2], [%[block]], #2 \n\t" \
+\
+ "rsbs %[data1], %[zero], r6, asr #16 \n\t" \
+ "addgt %[data1], %[qadd], #0 \n\t" \
+ "rsblt %[data1], %[qadd], #0 \n\t" \
+ "smlatbne %[data1], r6, %[qmul], %[data1] \n\t" \
+\
+ "rsbs %[data2], %[zero], r7, asr #16 \n\t" \
+ "addgt %[data2], %[qadd], #0 \n\t" \
+ "rsblt %[data2], %[qadd], #0 \n\t" \
+ "smlatbne %[data2], r7, %[qmul], %[data2] \n\t" \
+\
+ "rsbs %[tmp], %[zero], r6, asl #16 \n\t" \
+ "addgt %[tmp], %[qadd], #0 \n\t" \
+ "rsblt %[tmp], %[qadd], #0 \n\t" \
+ "smlabbne r6, r6, %[qmul], %[tmp] \n\t" \
+\
+ "rsbs %[tmp], %[zero], r7, asl #16 \n\t" \
+ "addgt %[tmp], %[qadd], #0 \n\t" \
+ "rsblt %[tmp], %[qadd], #0 \n\t" \
+ "smlabbne r7, r7, %[qmul], %[tmp] \n\t" \
+\
+ "strh r6, [%[block]], #2 \n\t" \
+ "strh %[data1], [%[block]], #2 \n\t" \
+ "strh r7, [%[block]], #2 \n\t" \
+ "strh %[data2], [%[block]], #2 \n\t" \
+\
+ "subs %[count], %[count], #8 \n\t" \
+ "ldrgtd r4, [%[block], #0] \n\t" /* load data early to avoid load/use pipeline stall */ \
+ "bgt 1b \n\t" \
+\
+ "adds %[count], %[count], #2 \n\t" \
+ "ble 3f \n\t" \
+ "2: \n\t" \
+ "ldrsh %[data1], [%[block], #0] \n\t" \
+ "ldrsh %[data2], [%[block], #2] \n\t" \
+ "mov %[tmp], %[qadd] \n\t" \
+ "cmp %[data1], #0 \n\t" \
+ "rsblt %[tmp], %[qadd], #0 \n\t" \
+ "smlabbne %[data1], %[data1], %[qmul], %[tmp] \n\t" \
+ "mov %[tmp], %[qadd] \n\t" \
+ "cmp %[data2], #0 \n\t" \
+ "rsblt %[tmp], %[qadd], #0 \n\t" \
+ "smlabbne %[data2], %[data2], %[qmul], %[tmp] \n\t" \
+ "strh %[data1], [%[block]], #2 \n\t" \
+ "strh %[data2], [%[block]], #2 \n\t" \
+ "3: \n\t" \
+ : [block] "+&r" (xblock), [count] "+&r" (xcount), [tmp] "=&r" (xtmp), \
+ [data1] "=&r" (xdata1), [data2] "=&r" (xdata2) \
+ : [qmul] "r" (xqmul), [qadd] "r" (xqadd), [zero] "r" (0) \
+ : "r4", "r5", "r6", "r7", "cc", "memory" \
+); \
+})
+
+static void dct_unquantize_h263_intra_armv5te(MpegEncContext *s,
+ DCTELEM *block, int n, int qscale)
+{
+ int i, level, qmul, qadd;
+ int nCoeffs;
+
+ assert(s->block_last_index[n]>=0);
+
+ qmul = qscale << 1;
+
+ if (!s->h263_aic) {
+ if (n < 4)
+ level = block[0] * s->y_dc_scale;
+ else
+ level = block[0] * s->c_dc_scale;
+ qadd = (qscale - 1) | 1;
+ }else{
+ qadd = 0;
+ level = block[0];
+ }
+ if(s->ac_pred)
+ nCoeffs=63;
+ else
+ nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];
+
+ dct_unquantize_h263_special_helper_armv5te(block, qmul, qadd, nCoeffs + 1);
+ block[0] = level;
+}
+
+static void dct_unquantize_h263_inter_armv5te(MpegEncContext *s,
+ DCTELEM *block, int n, int qscale)
+{
+ int i, level, qmul, qadd;
+ int nCoeffs;
+
+ assert(s->block_last_index[n]>=0);
+
+ qadd = (qscale - 1) | 1;
+ qmul = qscale << 1;
+
+ nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];
+
+ dct_unquantize_h263_special_helper_armv5te(block, qmul, qadd, nCoeffs + 1);
+}
+
+#define HAVE_DCT_UNQUANTIZE_H263_ARMV5TE_OPTIMIZED
+
+#endif
+
+void MPV_common_init_armv5te(MpegEncContext *s)
+{
+#ifdef HAVE_DCT_UNQUANTIZE_H263_ARMV5TE_OPTIMIZED
+ s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_armv5te;
+ s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_armv5te;
+#endif
+}
diff --git a/src/libffmpeg/libavcodec/armv4l/mpegvideo_iwmmxt.c b/contrib/ffmpeg/libavcodec/armv4l/mpegvideo_iwmmxt.c
index 1336ac5f8..1336ac5f8 100644
--- a/src/libffmpeg/libavcodec/armv4l/mpegvideo_iwmmxt.c
+++ b/contrib/ffmpeg/libavcodec/armv4l/mpegvideo_iwmmxt.c
diff --git a/src/libffmpeg/libavcodec/armv4l/simple_idct_arm.S b/contrib/ffmpeg/libavcodec/armv4l/simple_idct_arm.S
index b5a20f6da..b5a20f6da 100644
--- a/src/libffmpeg/libavcodec/armv4l/simple_idct_arm.S
+++ b/contrib/ffmpeg/libavcodec/armv4l/simple_idct_arm.S
diff --git a/src/libffmpeg/libavcodec/armv4l/simple_idct_armv5te.S b/contrib/ffmpeg/libavcodec/armv4l/simple_idct_armv5te.S
index 28bee0643..28bee0643 100644
--- a/src/libffmpeg/libavcodec/armv4l/simple_idct_armv5te.S
+++ b/contrib/ffmpeg/libavcodec/armv4l/simple_idct_armv5te.S
diff --git a/contrib/ffmpeg/libavcodec/armv4l/simple_idct_armv6.S b/contrib/ffmpeg/libavcodec/armv4l/simple_idct_armv6.S
new file mode 100644
index 000000000..401e1910d
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/armv4l/simple_idct_armv6.S
@@ -0,0 +1,448 @@
+/*
+ * Simple IDCT
+ *
+ * Copyright (c) 2001 Michael Niedermayer <michaelni@gmx.at>
+ * Copyright (c) 2007 Mans Rullgard <mru@inprovide.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#define W1 22725 /* cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 */
+#define W2 21407 /* cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 */
+#define W3 19266 /* cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 */
+#define W4 16383 /* cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 */
+#define W5 12873 /* cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 */
+#define W6 8867 /* cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 */
+#define W7 4520 /* cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 */
+#define ROW_SHIFT 11
+#define COL_SHIFT 20
+
+#define W13 (W1 | (W3 << 16))
+#define W26 (W2 | (W6 << 16))
+#define W42 (W4 | (W2 << 16))
+#define W42n (-W4&0xffff | (-W2 << 16))
+#define W46 (W4 | (W6 << 16))
+#define W57 (W5 | (W7 << 16))
+
+ .text
+ .align
+w13: .long W13
+w26: .long W26
+w42: .long W42
+w42n: .long W42n
+w46: .long W46
+w57: .long W57
+
+/*
+ Compute partial IDCT of single row.
+ shift = left-shift amount
+ a1 = source address
+ a3 = row[2,0] <= 2 cycles
+ a4 = row[3,1]
+ ip = w42 <= 2 cycles
+
+ Output in registers v1--v8
+*/
+ .macro idct_row shift
+ ldr lr, [pc, #(w46-.-8)] /* lr = W4 | (W6 << 16) */
+ mov a2, #(1<<(\shift-1))
+ smlad v1, a3, ip, a2
+ smlsd v4, a3, ip, a2
+ ldr ip, [pc, #(w13-.-8)] /* ip = W1 | (W3 << 16) */
+ ldr v7, [pc, #(w57-.-8)] /* v7 = W5 | (W7 << 16) */
+ smlad v2, a3, lr, a2
+ smlsd v3, a3, lr, a2
+
+ smuad v5, a4, ip /* v5 = B0 = W1*row[1] + W3*row[3] */
+ smusdx fp, a4, v7 /* fp = B3 = W7*row[1] - W5*row[3] */
+ ldr lr, [a1, #12] /* lr = row[7,5] */
+ pkhtb a3, ip, v7, asr #16 /* a4 = W7 | (W3 << 16) */
+ pkhbt a2, ip, v7, lsl #16 /* a2 = W1 | (W5 << 16) */
+ smusdx v6, a3, a4 /* v6 = -B1 = W7*row[3] - W3*row[1] */
+ smlad v5, lr, v7, v5 /* B0 += W5*row[5] + W7*row[7] */
+ smusdx v7, a4, a2 /* v7 = B2 = W5*row[1] - W1*row[3] */
+
+ ldr a4, [pc, #(w42n-.-8)] /* a4 = -W4 | (-W2 << 16) */
+ smlad v7, lr, a3, v7 /* B2 += W7*row[5] + W3*row[7] */
+ ldr a3, [a1, #4] /* a3 = row[6,4] */
+ smlsdx fp, lr, ip, fp /* B3 += W3*row[5] - W1*row[7] */
+ ldr ip, [pc, #(w46-.-8)] /* ip = W4 | (W6 << 16) */
+ smlad v6, lr, a2, v6 /* B1 -= W1*row[5] + W5*row[7] */
+
+ smlad v2, a3, a4, v2 /* A1 += -W4*row[4] - W2*row[6] */
+ smlsd v3, a3, a4, v3 /* A2 += -W4*row[4] + W2*row[6] */
+ smlad v1, a3, ip, v1 /* A0 += W4*row[4] + W6*row[6] */
+ smlsd v4, a3, ip, v4 /* A3 += W4*row[4] - W6*row[6] */
+ .endm
+
+/*
+ Compute partial IDCT of half row.
+ shift = left-shift amount
+ a3 = row[2,0]
+ a4 = row[3,1]
+ ip = w42
+
+ Output in registers v1--v8
+*/
+ .macro idct_row4 shift
+ ldr lr, [pc, #(w46-.-8)] /* lr = W4 | (W6 << 16) */
+ ldr v7, [pc, #(w57-.-8)] /* v7 = W5 | (W7 << 16) */
+ mov a2, #(1<<(\shift-1))
+ smlad v1, a3, ip, a2
+ smlsd v4, a3, ip, a2
+ ldr ip, [pc, #(w13-.-8)] /* ip = W1 | (W3 << 16) */
+ smlad v2, a3, lr, a2
+ smlsd v3, a3, lr, a2
+ smusdx fp, a4, v7 /* fp = B3 = W7*row[1] - W5*row[3] */
+ smuad v5, a4, ip /* v5 = B0 = W1*row[1] + W3*row[3] */
+ pkhtb a3, ip, v7, asr #16 /* a4 = W7 | (W3 << 16) */
+ pkhbt a2, ip, v7, lsl #16 /* a2 = W1 | (W5 << 16) */
+ smusdx v6, a3, a4 /* v6 = -B1 = W7*row[3] - W3*row[1] */
+ smusdx v7, a4, a2 /* v7 = B2 = W5*row[1] - W1*row[3] */
+ .endm
+
+/*
+ Compute final part of IDCT single row without shift.
+ Input in registers v1--v8
+ Output in registers ip, v1--v3, lr, v5--v7
+*/
+ .macro idct_finish
+ add ip, v1, v5 /* a2 = A0 + B0 */
+ sub lr, v1, v5 /* a3 = A0 - B0 */
+ sub v1, v2, v6 /* a3 = A1 + B1 */
+ add v5, v2, v6 /* a3 = A1 - B1 */
+ add v2, v3, v7 /* a2 = A2 + B2 */
+ sub v6, v3, v7 /* a2 = A2 - B2 */
+ add v3, v4, fp /* a3 = A3 + B3 */
+ sub v7, v4, fp /* a3 = A3 - B3 */
+ .endm
+
+/*
+ Compute final part of IDCT single row.
+ shift = right-shift amount
+ Input/output in registers v1--v8
+*/
+ .macro idct_finish_shift shift
+ add a4, v1, v5 /* a4 = A0 + B0 */
+ sub a3, v1, v5 /* a3 = A0 - B0 */
+ mov v1, a4, asr #\shift
+ mov v5, a3, asr #\shift
+
+ sub a4, v2, v6 /* a4 = A1 + B1 */
+ add a3, v2, v6 /* a3 = A1 - B1 */
+ mov v2, a4, asr #\shift
+ mov v6, a3, asr #\shift
+
+ add a4, v3, v7 /* a4 = A2 + B2 */
+ sub a3, v3, v7 /* a3 = A2 - B2 */
+ mov v3, a4, asr #\shift
+ mov v7, a3, asr #\shift
+
+ add a4, v4, fp /* a4 = A3 + B3 */
+ sub a3, v4, fp /* a3 = A3 - B3 */
+ mov v4, a4, asr #\shift
+ mov fp, a3, asr #\shift
+ .endm
+
+/*
+ Compute final part of IDCT single row, saturating results at 8 bits.
+ shift = right-shift amount
+ Input/output in registers v1--v8
+*/
+ .macro idct_finish_shift_sat shift
+ add a4, v1, v5 /* a4 = A0 + B0 */
+ sub ip, v1, v5 /* ip = A0 - B0 */
+ usat v1, #8, a4, asr #\shift
+ usat v5, #8, ip, asr #\shift
+
+ sub a4, v2, v6 /* a4 = A1 + B1 */
+ add ip, v2, v6 /* ip = A1 - B1 */
+ usat v2, #8, a4, asr #\shift
+ usat v6, #8, ip, asr #\shift
+
+ add a4, v3, v7 /* a4 = A2 + B2 */
+ sub ip, v3, v7 /* ip = A2 - B2 */
+ usat v3, #8, a4, asr #\shift
+ usat v7, #8, ip, asr #\shift
+
+ add a4, v4, fp /* a4 = A3 + B3 */
+ sub ip, v4, fp /* ip = A3 - B3 */
+ usat v4, #8, a4, asr #\shift
+ usat fp, #8, ip, asr #\shift
+ .endm
+
+/*
+ Compute IDCT of single row, storing as column.
+ a1 = source
+ a2 = dest
+*/
+ .align
+ .func idct_row_armv6
+idct_row_armv6:
+ str lr, [sp, #-4]!
+
+ ldr lr, [a1, #12] /* lr = row[7,5] */
+ ldr ip, [a1, #4] /* ip = row[6,4] */
+ ldr a4, [a1, #8] /* a4 = row[3,1] */
+ ldr a3, [a1] /* a3 = row[2,0] */
+ orrs lr, lr, ip
+ cmpeq lr, a4
+ cmpeq lr, a3, lsr #16
+ beq 1f
+ str a2, [sp, #-4]!
+ ldr ip, [pc, #(w42-.-8)] /* ip = W4 | (W2 << 16) */
+ cmp lr, #0
+ beq 2f
+
+ idct_row ROW_SHIFT
+ b 3f
+
+2: idct_row4 ROW_SHIFT
+
+3: ldr a2, [sp], #4
+ idct_finish_shift ROW_SHIFT
+
+ strh v1, [a2]
+ strh v2, [a2, #(16*2)]
+ strh v3, [a2, #(16*4)]
+ strh v4, [a2, #(16*6)]
+ strh fp, [a2, #(16*1)]
+ strh v7, [a2, #(16*3)]
+ strh v6, [a2, #(16*5)]
+ strh v5, [a2, #(16*7)]
+
+ ldr pc, [sp], #4
+
+1: mov a3, a3, lsl #3
+ strh a3, [a2]
+ strh a3, [a2, #(16*2)]
+ strh a3, [a2, #(16*4)]
+ strh a3, [a2, #(16*6)]
+ strh a3, [a2, #(16*1)]
+ strh a3, [a2, #(16*3)]
+ strh a3, [a2, #(16*5)]
+ strh a3, [a2, #(16*7)]
+ ldr pc, [sp], #4
+ .endfunc
+
+/*
+ Compute IDCT of single column, read as row.
+ a1 = source
+ a2 = dest
+*/
+ .align
+ .func idct_col_armv6
+idct_col_armv6:
+ stmfd sp!, {a2, lr}
+
+ ldr a3, [a1] /* a3 = row[2,0] */
+ ldr ip, [pc, #(w42-.-8)] /* ip = W4 | (W2 << 16) */
+ ldr a4, [a1, #8] /* a4 = row[3,1] */
+ idct_row COL_SHIFT
+ ldr a2, [sp], #4
+ idct_finish_shift COL_SHIFT
+
+ strh v1, [a2]
+ strh v2, [a2, #(16*1)]
+ strh v3, [a2, #(16*2)]
+ strh v4, [a2, #(16*3)]
+ strh fp, [a2, #(16*4)]
+ strh v7, [a2, #(16*5)]
+ strh v6, [a2, #(16*6)]
+ strh v5, [a2, #(16*7)]
+
+ ldr pc, [sp], #4
+ .endfunc
+
+/*
+ Compute IDCT of single column, read as row, store saturated 8-bit.
+ a1 = source
+ a2 = dest
+ a3 = line size
+*/
+ .align
+ .func idct_col_put_armv6
+idct_col_put_armv6:
+ stmfd sp!, {a2, a3, lr}
+
+ ldr a3, [a1] /* a3 = row[2,0] */
+ ldr ip, [pc, #(w42-.-8)] /* ip = W4 | (W2 << 16) */
+ ldr a4, [a1, #8] /* a4 = row[3,1] */
+ idct_row COL_SHIFT
+ ldmfd sp!, {a2, a3}
+ idct_finish_shift_sat COL_SHIFT
+
+ strb v1, [a2], a3
+ strb v2, [a2], a3
+ strb v3, [a2], a3
+ strb v4, [a2], a3
+ strb fp, [a2], a3
+ strb v7, [a2], a3
+ strb v6, [a2], a3
+ strb v5, [a2], a3
+
+ sub a2, a2, a3, lsl #3
+
+ ldr pc, [sp], #4
+ .endfunc
+
+/*
+ Compute IDCT of single column, read as row, add/store saturated 8-bit.
+ a1 = source
+ a2 = dest
+ a3 = line size
+*/
+ .align
+ .func idct_col_add_armv6
+idct_col_add_armv6:
+ stmfd sp!, {a2, a3, lr}
+
+ ldr a3, [a1] /* a3 = row[2,0] */
+ ldr ip, [pc, #(w42-.-8)] /* ip = W4 | (W2 << 16) */
+ ldr a4, [a1, #8] /* a4 = row[3,1] */
+ idct_row COL_SHIFT
+ ldmfd sp!, {a2, a3}
+ idct_finish
+
+ ldrb a4, [a2]
+ ldrb v4, [a2, a3]
+ ldrb fp, [a2, a3, lsl #2]
+ add ip, a4, ip, asr #COL_SHIFT
+ usat ip, #8, ip
+ add v1, v4, v1, asr #COL_SHIFT
+ strb ip, [a2], a3
+ ldrb ip, [a2, a3]
+ usat v1, #8, v1
+ ldrb fp, [a2, a3, lsl #2]
+ add v2, ip, v2, asr #COL_SHIFT
+ usat v2, #8, v2
+ strb v1, [a2], a3
+ ldrb a4, [a2, a3]
+ ldrb ip, [a2, a3, lsl #2]
+ strb v2, [a2], a3
+ ldrb v4, [a2, a3]
+ ldrb v1, [a2, a3, lsl #2]
+ add v3, a4, v3, asr #COL_SHIFT
+ usat v3, #8, v3
+ add v7, v4, v7, asr #COL_SHIFT
+ usat v7, #8, v7
+ add v6, fp, v6, asr #COL_SHIFT
+ usat v6, #8, v6
+ add v5, ip, v5, asr #COL_SHIFT
+ usat v5, #8, v5
+ add lr, v1, lr, asr #COL_SHIFT
+ usat lr, #8, lr
+ strb v3, [a2], a3
+ strb v7, [a2], a3
+ strb v6, [a2], a3
+ strb v5, [a2], a3
+ strb lr, [a2], a3
+
+ sub a2, a2, a3, lsl #3
+
+ ldr pc, [sp], #4
+ .endfunc
+
+/*
+ Compute 8 IDCT row transforms.
+ func = IDCT row->col function
+ width = width of columns in bytes
+*/
+ .macro idct_rows func width
+ bl \func
+ add a1, a1, #(16*2)
+ add a2, a2, #\width
+ bl \func
+ add a1, a1, #(16*2)
+ add a2, a2, #\width
+ bl \func
+ add a1, a1, #(16*2)
+ add a2, a2, #\width
+ bl \func
+ sub a1, a1, #(16*5)
+ add a2, a2, #\width
+ bl \func
+ add a1, a1, #(16*2)
+ add a2, a2, #\width
+ bl \func
+ add a1, a1, #(16*2)
+ add a2, a2, #\width
+ bl \func
+ add a1, a1, #(16*2)
+ add a2, a2, #\width
+ bl \func
+
+ sub a1, a1, #(16*7)
+ .endm
+
+ .align
+ .global ff_simple_idct_armv6
+ .func ff_simple_idct_armv6
+/* void ff_simple_idct_armv6(DCTELEM *data); */
+ff_simple_idct_armv6:
+ stmfd sp!, {v1, v2, v3, v4, v5, v6, v7, fp, lr}
+ sub sp, sp, #128
+
+ mov a2, sp
+ idct_rows idct_row_armv6, 2
+ mov a2, a1
+ mov a1, sp
+ idct_rows idct_col_armv6, 2
+
+ add sp, sp, #128
+ ldmfd sp!, {v1, v2, v3, v4, v5, v6, v7, fp, pc}
+ .endfunc
+
+ .align
+ .global ff_simple_idct_add_armv6
+ .func ff_simple_idct_add_armv6
+/* ff_simple_idct_add_armv6(uint8_t *dest, int line_size, DCTELEM *data); */
+ff_simple_idct_add_armv6:
+ stmfd sp!, {a1, a2, v1, v2, v3, v4, v5, v6, v7, fp, lr}
+ sub sp, sp, #128
+
+ mov a1, a3
+ mov a2, sp
+ idct_rows idct_row_armv6, 2
+ mov a1, sp
+ ldr a2, [sp, #128]
+ ldr a3, [sp, #(128+4)]
+ idct_rows idct_col_add_armv6, 1
+
+ add sp, sp, #(128+8)
+ ldmfd sp!, {v1, v2, v3, v4, v5, v6, v7, fp, pc}
+ .endfunc
+
+ .align
+ .global ff_simple_idct_put_armv6
+ .func ff_simple_idct_put_armv6
+/* ff_simple_idct_put_armv6(uint8_t *dest, int line_size, DCTELEM *data); */
+ff_simple_idct_put_armv6:
+ stmfd sp!, {a1, a2, v1, v2, v3, v4, v5, v6, v7, fp, lr}
+ sub sp, sp, #128
+
+ mov a1, a3
+ mov a2, sp
+ idct_rows idct_row_armv6, 2
+ mov a1, sp
+ ldr a2, [sp, #128]
+ ldr a3, [sp, #(128+4)]
+ idct_rows idct_col_put_armv6, 1
+
+ add sp, sp, #(128+8)
+ ldmfd sp!, {v1, v2, v3, v4, v5, v6, v7, fp, pc}
+ .endfunc
diff --git a/src/libffmpeg/libavcodec/asv1.c b/contrib/ffmpeg/libavcodec/asv1.c
index ec6bbb9ba..ec6bbb9ba 100644
--- a/src/libffmpeg/libavcodec/asv1.c
+++ b/contrib/ffmpeg/libavcodec/asv1.c
diff --git a/contrib/ffmpeg/libavcodec/audioconvert.c b/contrib/ffmpeg/libavcodec/audioconvert.c
new file mode 100644
index 000000000..e6291ac6d
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/audioconvert.c
@@ -0,0 +1,79 @@
+/*
+ * audio conversion
+ * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * @file audioconvert.c
+ * audio conversion
+ * @author Michael Niedermayer <michaelni@gmx.at>
+ */
+
+#include "avcodec.h"
+
+int av_audio_convert(void *maybe_dspcontext_or_something_av_convert_specific,
+ void *out[6], int out_stride[6], enum SampleFormat out_fmt,
+ void * in[6], int in_stride[6], enum SampleFormat in_fmt, int len){
+ int ch;
+ const int isize= FFMIN( in_fmt+1, 4);
+ const int osize= FFMIN(out_fmt+1, 4);
+ const int fmt_pair= out_fmt + 5*in_fmt;
+
+ //FIXME optimize common cases
+
+ for(ch=0; ch<6; ch++){
+ const int is= in_stride[ch] * isize;
+ const int os= out_stride[ch] * osize;
+ uint8_t *pi= in[ch];
+ uint8_t *po= out[ch];
+ uint8_t *end= po + os;
+ if(!out[ch])
+ continue;
+
+#define CONV(ofmt, otype, ifmt, expr)\
+if(fmt_pair == ofmt + 5*ifmt){\
+ do{\
+ *(otype*)po = expr; pi += is; po += os;\
+ }while(po < end);\
+}
+
+//FIXME put things below under ifdefs so we dont waste space for cases no codec will need
+//FIXME rounding and cliping ?
+
+ CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_U8 , *(uint8_t*)pi)
+ else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_U8 , (*(uint8_t*)pi - 0x80)<<8)
+ else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_U8 , (*(uint8_t*)pi - 0x80)<<24)
+ else CONV(SAMPLE_FMT_FLT, float , SAMPLE_FMT_U8 , (*(uint8_t*)pi - 0x80)*(1.0 / (1<<7)))
+ else CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_S16, (*(int16_t*)pi>>8) + 0x80)
+ else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_S16, *(int16_t*)pi)
+ else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_S16, *(int16_t*)pi<<16)
+ else CONV(SAMPLE_FMT_FLT, float , SAMPLE_FMT_S16, *(int16_t*)pi*(1.0 / (1<<15)))
+ else CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_S32, (*(int32_t*)pi>>24) + 0x80)
+ else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_S32, *(int32_t*)pi>>16)
+ else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_S32, *(int32_t*)pi)
+ else CONV(SAMPLE_FMT_FLT, float , SAMPLE_FMT_S32, *(int32_t*)pi*(1.0 / (1<<31)))
+ else CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_FLT, lrintf(*(float*)pi * (1<<7)) + 0x80)
+ else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_FLT, lrintf(*(float*)pi * (1<<15)))
+ else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_FLT, lrintf(*(float*)pi * (1<<31)))
+ else CONV(SAMPLE_FMT_FLT, float , SAMPLE_FMT_FLT, *(float*)pi)
+ else return -1;
+ }
+ return 0;
+}
diff --git a/contrib/ffmpeg/libavcodec/avcodec.h b/contrib/ffmpeg/libavcodec/avcodec.h
new file mode 100644
index 000000000..1d8427a9d
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/avcodec.h
@@ -0,0 +1,3091 @@
+/*
+ * copyright (c) 2001 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 St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_H
+#define AVCODEC_H
+
+/**
+ * @file avcodec.h
+ * external api header.
+ */
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "avutil.h"
+#include <sys/types.h> /* size_t */
+
+#define AV_STRINGIFY(s) AV_TOSTRING(s)
+#define AV_TOSTRING(s) #s
+
+#define LIBAVCODEC_VERSION_INT ((51<<16)+(40<<8)+2)
+#define LIBAVCODEC_VERSION 51.40.2
+#define LIBAVCODEC_BUILD LIBAVCODEC_VERSION_INT
+
+#define LIBAVCODEC_IDENT "Lavc" AV_STRINGIFY(LIBAVCODEC_VERSION)
+
+#define AV_NOPTS_VALUE INT64_C(0x8000000000000000)
+#define AV_TIME_BASE 1000000
+#define AV_TIME_BASE_Q (AVRational){1, AV_TIME_BASE}
+
+/**
+ *
+ * if you add a codec id to this list add it so that
+ * 1. no value of a existing codec id changes (that would break ABI)
+ * 2. closest to similar codecs
+ */
+enum CodecID {
+ CODEC_ID_NONE,
+ CODEC_ID_MPEG1VIDEO,
+ CODEC_ID_MPEG2VIDEO, /* prefered ID for MPEG Video 1 or 2 decoding */
+ CODEC_ID_MPEG2VIDEO_XVMC,
+ CODEC_ID_H261,
+ CODEC_ID_H263,
+ CODEC_ID_RV10,
+ CODEC_ID_RV20,
+ CODEC_ID_MJPEG,
+ CODEC_ID_MJPEGB,
+ CODEC_ID_LJPEG,
+ CODEC_ID_SP5X,
+ CODEC_ID_JPEGLS,
+ CODEC_ID_MPEG4,
+ CODEC_ID_RAWVIDEO,
+ CODEC_ID_MSMPEG4V1,
+ CODEC_ID_MSMPEG4V2,
+ CODEC_ID_MSMPEG4V3,
+ CODEC_ID_WMV1,
+ CODEC_ID_WMV2,
+ CODEC_ID_H263P,
+ CODEC_ID_H263I,
+ CODEC_ID_FLV1,
+ CODEC_ID_SVQ1,
+ CODEC_ID_SVQ3,
+ CODEC_ID_DVVIDEO,
+ CODEC_ID_HUFFYUV,
+ CODEC_ID_CYUV,
+ CODEC_ID_H264,
+ CODEC_ID_INDEO3,
+ CODEC_ID_VP3,
+ CODEC_ID_THEORA,
+ CODEC_ID_ASV1,
+ CODEC_ID_ASV2,
+ CODEC_ID_FFV1,
+ CODEC_ID_4XM,
+ CODEC_ID_VCR1,
+ CODEC_ID_CLJR,
+ CODEC_ID_MDEC,
+ CODEC_ID_ROQ,
+ CODEC_ID_INTERPLAY_VIDEO,
+ CODEC_ID_XAN_WC3,
+ CODEC_ID_XAN_WC4,
+ CODEC_ID_RPZA,
+ CODEC_ID_CINEPAK,
+ CODEC_ID_WS_VQA,
+ CODEC_ID_MSRLE,
+ CODEC_ID_MSVIDEO1,
+ CODEC_ID_IDCIN,
+ CODEC_ID_8BPS,
+ CODEC_ID_SMC,
+ CODEC_ID_FLIC,
+ CODEC_ID_TRUEMOTION1,
+ CODEC_ID_VMDVIDEO,
+ CODEC_ID_MSZH,
+ CODEC_ID_ZLIB,
+ CODEC_ID_QTRLE,
+ CODEC_ID_SNOW,
+ CODEC_ID_TSCC,
+ CODEC_ID_ULTI,
+ CODEC_ID_QDRAW,
+ CODEC_ID_VIXL,
+ CODEC_ID_QPEG,
+ CODEC_ID_XVID,
+ CODEC_ID_PNG,
+ CODEC_ID_PPM,
+ CODEC_ID_PBM,
+ CODEC_ID_PGM,
+ CODEC_ID_PGMYUV,
+ CODEC_ID_PAM,
+ CODEC_ID_FFVHUFF,
+ CODEC_ID_RV30,
+ CODEC_ID_RV40,
+ CODEC_ID_VC1,
+ CODEC_ID_WMV3,
+ CODEC_ID_LOCO,
+ CODEC_ID_WNV1,
+ CODEC_ID_AASC,
+ CODEC_ID_INDEO2,
+ CODEC_ID_FRAPS,
+ CODEC_ID_TRUEMOTION2,
+ CODEC_ID_BMP,
+ CODEC_ID_CSCD,
+ CODEC_ID_MMVIDEO,
+ CODEC_ID_ZMBV,
+ CODEC_ID_AVS,
+ CODEC_ID_SMACKVIDEO,
+ CODEC_ID_NUV,
+ CODEC_ID_KMVC,
+ CODEC_ID_FLASHSV,
+ CODEC_ID_CAVS,
+ CODEC_ID_JPEG2000,
+ CODEC_ID_VMNC,
+ CODEC_ID_VP5,
+ CODEC_ID_VP6,
+ CODEC_ID_VP6F,
+ CODEC_ID_TARGA,
+ CODEC_ID_DSICINVIDEO,
+ CODEC_ID_TIERTEXSEQVIDEO,
+ CODEC_ID_TIFF,
+ CODEC_ID_GIF,
+ CODEC_ID_FFH264,
+ CODEC_ID_DXA,
+ CODEC_ID_DNXHD,
+ CODEC_ID_THP,
+
+ /* various pcm "codecs" */
+ CODEC_ID_PCM_S16LE= 0x10000,
+ CODEC_ID_PCM_S16BE,
+ CODEC_ID_PCM_U16LE,
+ CODEC_ID_PCM_U16BE,
+ CODEC_ID_PCM_S8,
+ CODEC_ID_PCM_U8,
+ CODEC_ID_PCM_MULAW,
+ CODEC_ID_PCM_ALAW,
+ CODEC_ID_PCM_S32LE,
+ CODEC_ID_PCM_S32BE,
+ CODEC_ID_PCM_U32LE,
+ CODEC_ID_PCM_U32BE,
+ CODEC_ID_PCM_S24LE,
+ CODEC_ID_PCM_S24BE,
+ CODEC_ID_PCM_U24LE,
+ CODEC_ID_PCM_U24BE,
+ CODEC_ID_PCM_S24DAUD,
+
+ /* various adpcm codecs */
+ CODEC_ID_ADPCM_IMA_QT= 0x11000,
+ CODEC_ID_ADPCM_IMA_WAV,
+ CODEC_ID_ADPCM_IMA_DK3,
+ CODEC_ID_ADPCM_IMA_DK4,
+ CODEC_ID_ADPCM_IMA_WS,
+ CODEC_ID_ADPCM_IMA_SMJPEG,
+ CODEC_ID_ADPCM_MS,
+ CODEC_ID_ADPCM_4XM,
+ CODEC_ID_ADPCM_XA,
+ CODEC_ID_ADPCM_ADX,
+ CODEC_ID_ADPCM_EA,
+ CODEC_ID_ADPCM_G726,
+ CODEC_ID_ADPCM_CT,
+ CODEC_ID_ADPCM_SWF,
+ CODEC_ID_ADPCM_YAMAHA,
+ CODEC_ID_ADPCM_SBPRO_4,
+ CODEC_ID_ADPCM_SBPRO_3,
+ CODEC_ID_ADPCM_SBPRO_2,
+
+ /* AMR */
+ CODEC_ID_AMR_NB= 0x12000,
+ CODEC_ID_AMR_WB,
+
+ /* RealAudio codecs*/
+ CODEC_ID_RA_144= 0x13000,
+ CODEC_ID_RA_288,
+
+ /* various DPCM codecs */
+ CODEC_ID_ROQ_DPCM= 0x14000,
+ CODEC_ID_INTERPLAY_DPCM,
+ CODEC_ID_XAN_DPCM,
+ CODEC_ID_SOL_DPCM,
+
+ CODEC_ID_MP2= 0x15000,
+ CODEC_ID_MP3, /* prefered ID for MPEG Audio layer 1, 2 or3 decoding */
+ CODEC_ID_AAC,
+#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
+ CODEC_ID_MPEG4AAC,
+#endif
+ CODEC_ID_AC3,
+ CODEC_ID_DTS,
+ CODEC_ID_VORBIS,
+ CODEC_ID_DVAUDIO,
+ CODEC_ID_WMAV1,
+ CODEC_ID_WMAV2,
+ CODEC_ID_MACE3,
+ CODEC_ID_MACE6,
+ CODEC_ID_VMDAUDIO,
+ CODEC_ID_SONIC,
+ CODEC_ID_SONIC_LS,
+ CODEC_ID_FLAC,
+ CODEC_ID_MP3ADU,
+ CODEC_ID_MP3ON4,
+ CODEC_ID_SHORTEN,
+ CODEC_ID_ALAC,
+ CODEC_ID_WESTWOOD_SND1,
+ CODEC_ID_GSM, /* As in Berlin toast format */
+ CODEC_ID_QDM2,
+ CODEC_ID_COOK,
+ CODEC_ID_TRUESPEECH,
+ CODEC_ID_TTA,
+ CODEC_ID_SMACKAUDIO,
+ CODEC_ID_QCELP,
+ CODEC_ID_WAVPACK,
+ CODEC_ID_DSICINAUDIO,
+ CODEC_ID_IMC,
+ CODEC_ID_MUSEPACK7,
+ CODEC_ID_MLP,
+ CODEC_ID_GSM_MS, /* As found in WAV */
+
+ /* subtitle codecs */
+ CODEC_ID_DVD_SUBTITLE= 0x17000,
+ CODEC_ID_DVB_SUBTITLE,
+
+ CODEC_ID_MPEG2TS= 0x20000, /* _FAKE_ codec to indicate a raw MPEG2 transport
+ stream (only used by libavformat) */
+};
+
+#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
+/* CODEC_ID_MP3LAME is absolete */
+#define CODEC_ID_MP3LAME CODEC_ID_MP3
+#define CODEC_ID_MPEG4AAC CODEC_ID_AAC
+#endif
+
+enum CodecType {
+ CODEC_TYPE_UNKNOWN = -1,
+ CODEC_TYPE_VIDEO,
+ CODEC_TYPE_AUDIO,
+ CODEC_TYPE_DATA,
+ CODEC_TYPE_SUBTITLE,
+ CODEC_TYPE_NB
+};
+
+/* currently unused, may be used if 24/32 bits samples ever supported */
+/* all in native endian */
+enum SampleFormat {
+ SAMPLE_FMT_NONE = -1,
+ SAMPLE_FMT_U8, ///< unsigned 8 bits
+ SAMPLE_FMT_S16, ///< signed 16 bits
+ SAMPLE_FMT_S24, ///< signed 24 bits
+ SAMPLE_FMT_S32, ///< signed 32 bits
+ SAMPLE_FMT_FLT, ///< float
+};
+
+/* in bytes */
+#define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000 // 1 second of 48khz 32bit audio
+
+/**
+ * Required number of additionally allocated bytes at the end of the input bitstream for decoding.
+ * this is mainly needed because some optimized bitstream readers read
+ * 32 or 64 bit at once and could read over the end<br>
+ * Note, if the first 23 bits of the additional bytes are not 0 then damaged
+ * MPEG bitstreams could cause overread and segfault
+ */
+#define FF_INPUT_BUFFER_PADDING_SIZE 8
+
+/**
+ * minimum encoding buffer size.
+ * used to avoid some checks during header writing
+ */
+#define FF_MIN_BUFFER_SIZE 16384
+
+/* motion estimation type, EPZS by default */
+enum Motion_Est_ID {
+ ME_ZERO = 1,
+ ME_FULL,
+ ME_LOG,
+ ME_PHODS,
+ ME_EPZS,
+ ME_X1,
+ ME_HEX,
+ ME_UMH,
+ ME_ITER,
+};
+
+enum AVDiscard{
+//we leave some space between them for extensions (drop some keyframes for intra only or drop just some bidir frames)
+ AVDISCARD_NONE =-16, ///< discard nothing
+ AVDISCARD_DEFAULT= 0, ///< discard useless packets like 0 size packets in avi
+ AVDISCARD_NONREF = 8, ///< discard all non reference
+ AVDISCARD_BIDIR = 16, ///< discard all bidirectional frames
+ AVDISCARD_NONKEY = 32, ///< discard all frames except keyframes
+ AVDISCARD_ALL = 48, ///< discard all
+};
+
+typedef struct RcOverride{
+ int start_frame;
+ int end_frame;
+ int qscale; // if this is 0 then quality_factor will be used instead
+ float quality_factor;
+} RcOverride;
+
+#define FF_MAX_B_FRAMES 16
+
+/* encoding support
+ these flags can be passed in AVCodecContext.flags before initing
+ Note: not everything is supported yet.
+*/
+
+#define CODEC_FLAG_QSCALE 0x0002 ///< use fixed qscale
+#define CODEC_FLAG_4MV 0x0004 ///< 4 MV per MB allowed / Advanced prediction for H263
+#define CODEC_FLAG_QPEL 0x0010 ///< use qpel MC
+#define CODEC_FLAG_GMC 0x0020 ///< use GMC
+#define CODEC_FLAG_MV0 0x0040 ///< always try a MB with MV=<0,0>
+#define CODEC_FLAG_PART 0x0080 ///< use data partitioning
+/* parent program guarantees that the input for b-frame containing streams is not written to
+ for at least s->max_b_frames+1 frames, if this is not set than the input will be copied */
+#define CODEC_FLAG_INPUT_PRESERVED 0x0100
+#define CODEC_FLAG_PASS1 0x0200 ///< use internal 2pass ratecontrol in first pass mode
+#define CODEC_FLAG_PASS2 0x0400 ///< use internal 2pass ratecontrol in second pass mode
+#define CODEC_FLAG_EXTERN_HUFF 0x1000 ///< use external huffman table (for mjpeg)
+#define CODEC_FLAG_GRAY 0x2000 ///< only decode/encode grayscale
+#define CODEC_FLAG_EMU_EDGE 0x4000///< don't draw edges
+#define CODEC_FLAG_PSNR 0x8000 ///< error[?] variables will be set during encoding
+#define CODEC_FLAG_TRUNCATED 0x00010000 /** input bitstream might be truncated at a random location instead
+ of only at frame boundaries */
+#define CODEC_FLAG_NORMALIZE_AQP 0x00020000 ///< normalize adaptive quantization
+#define CODEC_FLAG_INTERLACED_DCT 0x00040000 ///< use interlaced dct
+#define CODEC_FLAG_LOW_DELAY 0x00080000 ///< force low delay
+#define CODEC_FLAG_ALT_SCAN 0x00100000 ///< use alternate scan
+#define CODEC_FLAG_TRELLIS_QUANT 0x00200000 ///< use trellis quantization
+#define CODEC_FLAG_GLOBAL_HEADER 0x00400000 ///< place global headers in extradata instead of every keyframe
+#define CODEC_FLAG_BITEXACT 0x00800000 ///< use only bitexact stuff (except (i)dct)
+/* Fx : Flag for h263+ extra options */
+#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
+#define CODEC_FLAG_H263P_AIC 0x01000000 ///< H263 Advanced intra coding / MPEG4 AC prediction (remove this)
+#endif
+#define CODEC_FLAG_AC_PRED 0x01000000 ///< H263 Advanced intra coding / MPEG4 AC prediction
+#define CODEC_FLAG_H263P_UMV 0x02000000 ///< Unlimited motion vector
+#define CODEC_FLAG_CBP_RD 0x04000000 ///< use rate distortion optimization for cbp
+#define CODEC_FLAG_QP_RD 0x08000000 ///< use rate distortion optimization for qp selectioon
+#define CODEC_FLAG_H263P_AIV 0x00000008 ///< H263 Alternative inter vlc
+#define CODEC_FLAG_OBMC 0x00000001 ///< OBMC
+#define CODEC_FLAG_LOOP_FILTER 0x00000800 ///< loop filter
+#define CODEC_FLAG_H263P_SLICE_STRUCT 0x10000000
+#define CODEC_FLAG_INTERLACED_ME 0x20000000 ///< interlaced motion estimation
+#define CODEC_FLAG_SVCD_SCAN_OFFSET 0x40000000 ///< will reserve space for SVCD scan offset user data
+#define CODEC_FLAG_CLOSED_GOP ((int)0x80000000)
+#define CODEC_FLAG2_FAST 0x00000001 ///< allow non spec compliant speedup tricks
+#define CODEC_FLAG2_STRICT_GOP 0x00000002 ///< strictly enforce GOP size
+#define CODEC_FLAG2_NO_OUTPUT 0x00000004 ///< skip bitstream encoding
+#define CODEC_FLAG2_LOCAL_HEADER 0x00000008 ///< place global headers at every keyframe instead of in extradata
+#define CODEC_FLAG2_BPYRAMID 0x00000010 ///< H.264 allow b-frames to be used as references
+#define CODEC_FLAG2_WPRED 0x00000020 ///< H.264 weighted biprediction for b-frames
+#define CODEC_FLAG2_MIXED_REFS 0x00000040 ///< H.264 one reference per partition, as opposed to one reference per macroblock
+#define CODEC_FLAG2_8X8DCT 0x00000080 ///< H.264 high profile 8x8 transform
+#define CODEC_FLAG2_FASTPSKIP 0x00000100 ///< H.264 fast pskip
+#define CODEC_FLAG2_AUD 0x00000200 ///< H.264 access unit delimiters
+#define CODEC_FLAG2_BRDO 0x00000400 ///< b-frame rate-distortion optimization
+#define CODEC_FLAG2_INTRA_VLC 0x00000800 ///< use MPEG-2 intra VLC table
+#define CODEC_FLAG2_MEMC_ONLY 0x00001000 ///< only do ME/MC (I frames -> ref, P frame -> ME+MC)
+#define CODEC_FLAG2_DROP_FRAME_TIMECODE 0x00002000 ///< timecode is in drop frame format
+#define CODEC_FLAG2_SKIP_RD 0x00004000 ///< RD optimal MB level residual skiping
+#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 non linear quantizer
+
+/* Unsupported options :
+ * Syntax Arithmetic coding (SAC)
+ * Reference Picture Selection
+ * Independent Segment Decoding */
+/* /Fx */
+/* codec capabilities */
+
+#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
+ */
+#define CODEC_CAP_DR1 0x0002
+/* if 'parse_only' field is true, then avcodec_parse_frame() can be
+ used */
+#define CODEC_CAP_PARSE_ONLY 0x0004
+#define CODEC_CAP_TRUNCATED 0x0008
+/* codec can export data for HW decoding (XvMC) */
+#define CODEC_CAP_HWACCEL 0x0010
+/**
+ * codec has a non zero delay and needs to be feeded with NULL at the end to get the delayed data.
+ * if this is not set, the codec is guaranteed to never be feeded with NULL data
+ */
+#define CODEC_CAP_DELAY 0x0020
+/**
+ * Codec can be fed a final frame with a smaller size.
+ * This can be used to prevent truncation of the last audio samples.
+ */
+#define CODEC_CAP_SMALL_LAST_FRAME 0x0040
+
+//the following defines may change, don't expect compatibility if you use them
+#define MB_TYPE_INTRA4x4 0x0001
+#define MB_TYPE_INTRA16x16 0x0002 //FIXME h264 specific
+#define MB_TYPE_INTRA_PCM 0x0004 //FIXME h264 specific
+#define MB_TYPE_16x16 0x0008
+#define MB_TYPE_16x8 0x0010
+#define MB_TYPE_8x16 0x0020
+#define MB_TYPE_8x8 0x0040
+#define MB_TYPE_INTERLACED 0x0080
+#define MB_TYPE_DIRECT2 0x0100 //FIXME
+#define MB_TYPE_ACPRED 0x0200
+#define MB_TYPE_GMC 0x0400
+#define MB_TYPE_SKIP 0x0800
+#define MB_TYPE_P0L0 0x1000
+#define MB_TYPE_P1L0 0x2000
+#define MB_TYPE_P0L1 0x4000
+#define MB_TYPE_P1L1 0x8000
+#define MB_TYPE_L0 (MB_TYPE_P0L0 | MB_TYPE_P1L0)
+#define MB_TYPE_L1 (MB_TYPE_P0L1 | MB_TYPE_P1L1)
+#define MB_TYPE_L0L1 (MB_TYPE_L0 | MB_TYPE_L1)
+#define MB_TYPE_QUANT 0x00010000
+#define MB_TYPE_CBP 0x00020000
+//Note bits 24-31 are reserved for codec specific use (h264 ref0, mpeg1 0mv, ...)
+
+/**
+ * Pan Scan area.
+ * this specifies the area which should be displayed. Note there may be multiple such areas for one frame
+ */
+typedef struct AVPanScan{
+ /**
+ * id.
+ * - encoding: set by user.
+ * - decoding: set by lavc
+ */
+ int id;
+
+ /**
+ * width and height in 1/16 pel
+ * - encoding: set by user.
+ * - decoding: set by lavc
+ */
+ int width;
+ int height;
+
+ /**
+ * position of the top left corner in 1/16 pel for up to 3 fields/frames.
+ * - encoding: set by user.
+ * - decoding: set by lavc
+ */
+ int16_t position[3][2];
+}AVPanScan;
+
+#define FF_COMMON_FRAME \
+ /**\
+ * pointer to the picture planes.\
+ * this might be different from the first allocated byte\
+ * - encoding: \
+ * - decoding: \
+ */\
+ uint8_t *data[4];\
+ int linesize[4];\
+ /**\
+ * pointer to the first allocated byte of the picture. can be used in get_buffer/release_buffer\
+ * this isn't used by lavc unless the default get/release_buffer() is used\
+ * - encoding: \
+ * - decoding: \
+ */\
+ uint8_t *base[4];\
+ /**\
+ * 1 -> keyframe, 0-> not\
+ * - encoding: set by lavc\
+ * - decoding: set by lavc\
+ */\
+ int key_frame;\
+\
+ /**\
+ * picture type of the frame, see ?_TYPE below.\
+ * - encoding: set by lavc for coded_picture (and set by user for input)\
+ * - decoding: set by lavc\
+ */\
+ int pict_type;\
+\
+ /**\
+ * presentation timestamp in time_base units (time when frame should be shown to user)\
+ * if AV_NOPTS_VALUE then frame_rate = 1/time_base will be assumed\
+ * - encoding: MUST be set by user\
+ * - decoding: set by lavc\
+ */\
+ int64_t pts;\
+\
+ /**\
+ * picture number in bitstream order.\
+ * - encoding: set by\
+ * - decoding: set by lavc\
+ */\
+ int coded_picture_number;\
+ /**\
+ * picture number in display order.\
+ * - encoding: set by\
+ * - decoding: set by lavc\
+ */\
+ int display_picture_number;\
+\
+ /**\
+ * quality (between 1 (good) and FF_LAMBDA_MAX (bad)) \
+ * - encoding: set by lavc for coded_picture (and set by user for input)\
+ * - decoding: set by lavc\
+ */\
+ int quality; \
+\
+ /**\
+ * buffer age (1->was last buffer and dint change, 2->..., ...).\
+ * set to INT_MAX if the buffer has not been used yet \
+ * - encoding: unused\
+ * - decoding: MUST be set by get_buffer()\
+ */\
+ int age;\
+\
+ /**\
+ * is this picture used as reference\
+ * - encoding: unused\
+ * - decoding: set by lavc (before get_buffer() call))\
+ */\
+ int reference;\
+\
+ /**\
+ * QP table\
+ * - encoding: unused\
+ * - decoding: set by lavc\
+ */\
+ int8_t *qscale_table;\
+ /**\
+ * QP store stride\
+ * - encoding: unused\
+ * - decoding: set by lavc\
+ */\
+ int qstride;\
+\
+ /**\
+ * mbskip_table[mb]>=1 if MB didnt change\
+ * stride= mb_width = (width+15)>>4\
+ * - encoding: unused\
+ * - decoding: set by lavc\
+ */\
+ uint8_t *mbskip_table;\
+\
+ /**\
+ * Motion vector table.\
+ * @code\
+ * example:\
+ * int mv_sample_log2= 4 - motion_subsample_log2;\
+ * int mb_width= (width+15)>>4;\
+ * int mv_stride= (mb_width << mv_sample_log2) + 1;\
+ * motion_val[direction][x + y*mv_stride][0->mv_x, 1->mv_y];\
+ * @endcode\
+ * - encoding: set by user\
+ * - decoding: set by lavc\
+ */\
+ int16_t (*motion_val[2])[2];\
+\
+ /**\
+ * Macroblock type table\
+ * mb_type_base + mb_width + 2\
+ * - encoding: set by user\
+ * - decoding: set by lavc\
+ */\
+ uint32_t *mb_type;\
+\
+ /**\
+ * log2 of the size of the block which a single vector in motion_val represents: \
+ * (4->16x16, 3->8x8, 2-> 4x4, 1-> 2x2)\
+ * - encoding: unused\
+ * - decoding: set by lavc\
+ */\
+ uint8_t motion_subsample_log2;\
+\
+ /**\
+ * for some private data of the user\
+ * - encoding: unused\
+ * - decoding: set by user\
+ */\
+ void *opaque;\
+\
+ /**\
+ * error\
+ * - encoding: set by lavc if flags&CODEC_FLAG_PSNR\
+ * - decoding: unused\
+ */\
+ uint64_t error[4];\
+\
+ /**\
+ * type of the buffer (to keep track of who has to dealloc data[*])\
+ * - encoding: set by the one who allocs it\
+ * - decoding: set by the one who allocs it\
+ * Note: user allocated (direct rendering) & internal buffers can not coexist currently\
+ */\
+ int type;\
+ \
+ /**\
+ * when decoding, this signal how much the picture must be delayed.\
+ * extra_delay = repeat_pict / (2*fps)\
+ * - encoding: unused\
+ * - decoding: set by lavc\
+ */\
+ int repeat_pict;\
+ \
+ /**\
+ * \
+ */\
+ int qscale_type;\
+ \
+ /**\
+ * The content of the picture is interlaced.\
+ * - encoding: set by user\
+ * - decoding: set by lavc (default 0)\
+ */\
+ int interlaced_frame;\
+ \
+ /**\
+ * if the content is interlaced, is top field displayed first.\
+ * - encoding: set by user\
+ * - decoding: set by lavc\
+ */\
+ int top_field_first;\
+ \
+ /**\
+ * Pan scan.\
+ * - encoding: set by user\
+ * - decoding: set by lavc\
+ */\
+ AVPanScan *pan_scan;\
+ \
+ /**\
+ * tell user application that palette has changed from previous frame.\
+ * - encoding: ??? (no palette-enabled encoder yet)\
+ * - decoding: set by lavc (default 0)\
+ */\
+ int palette_has_changed;\
+ \
+ /**\
+ * Codec suggestion on buffer type if != 0\
+ * - encoding: unused\
+ * - decoding: set by lavc (before get_buffer() call))\
+ */\
+ int buffer_hints;\
+\
+ /**\
+ * DCT coeffitients\
+ * - encoding: unused\
+ * - decoding: set by lavc\
+ */\
+ short *dct_coeff;\
+\
+ /**\
+ * Motion referece frame index\
+ * - encoding: set by user\
+ * - decoding: set by lavc\
+ */\
+ int8_t *ref_index[2];
+
+#define FF_QSCALE_TYPE_MPEG1 0
+#define FF_QSCALE_TYPE_MPEG2 1
+#define FF_QSCALE_TYPE_H264 2
+
+#define FF_BUFFER_TYPE_INTERNAL 1
+#define FF_BUFFER_TYPE_USER 2 ///< Direct rendering buffers (image is (de)allocated by user)
+#define FF_BUFFER_TYPE_SHARED 4 ///< buffer from somewhere else, don't dealloc image (data/base), all other tables are not shared
+#define FF_BUFFER_TYPE_COPY 8 ///< just a (modified) copy of some other buffer, don't dealloc anything
+
+
+#define FF_I_TYPE 1 // Intra
+#define FF_P_TYPE 2 // Predicted
+#define FF_B_TYPE 3 // Bi-dir predicted
+#define FF_S_TYPE 4 // S(GMC)-VOP MPEG4
+#define FF_SI_TYPE 5
+#define FF_SP_TYPE 6
+
+#define FF_BUFFER_HINTS_VALID 0x01 // Buffer hints value is meaningful (if 0 ignore)
+#define FF_BUFFER_HINTS_READABLE 0x02 // Codec will read from buffer
+#define FF_BUFFER_HINTS_PRESERVE 0x04 // User must not alter buffer content
+#define FF_BUFFER_HINTS_REUSABLE 0x08 // Codec will reuse the buffer (update)
+
+/**
+ * Audio Video Frame.
+ */
+typedef struct AVFrame {
+ FF_COMMON_FRAME
+} AVFrame;
+
+#define DEFAULT_FRAME_RATE_BASE 1001000
+
+/**
+ * main external api structure.
+ */
+typedef struct AVCodecContext {
+ /**
+ * Info on struct for av_log
+ * - set by avcodec_alloc_context
+ */
+ AVClass *av_class;
+ /**
+ * the average bitrate.
+ * - encoding: set by user. unused for constant quantizer encoding
+ * - decoding: set by lavc. 0 or some bitrate if this info is available in the stream
+ */
+ int bit_rate;
+
+ /**
+ * number of bits the bitstream is allowed to diverge from the reference.
+ * the reference can be CBR (for CBR pass1) or VBR (for pass2)
+ * - encoding: set by user. unused for constant quantizer encoding
+ * - decoding: unused
+ */
+ int bit_rate_tolerance;
+
+ /**
+ * CODEC_FLAG_*.
+ * - encoding: set by user.
+ * - decoding: set by user.
+ */
+ int flags;
+
+ /**
+ * some codecs needs additionnal format info. It is stored here
+ * if any muxer uses this then ALL demuxers/parsers AND encoders for the specific codec MUST set it correctly
+ * too otherwise stream copy breaks
+ * in general use of this field by muxers is not recommanded
+ * - encoding: set by lavc.
+ * - decoding: set by lavc. (FIXME is this ok?)
+ */
+ int sub_id;
+
+ /**
+ * motion estimation algorithm used for video coding.
+ * 1 (zero), 2 (full), 3 (log), 4 (phods), 5 (epzs), 6 (x1), 7 (hex),
+ * 8 (umh), 9 (iter) [7, 8 are x264 specific, 9 is snow specific]
+ * - encoding: MUST be set by user.
+ * - decoding: unused
+ */
+ int me_method;
+
+ /**
+ * some codecs need / can use extra-data like huffman tables.
+ * mjpeg: huffman tables
+ * rv10: additional flags
+ * mpeg4: global headers (they can be in the bitstream or here)
+ * the allocated memory should be FF_INPUT_BUFFER_PADDING_SIZE bytes larger
+ * then extradata_size to avoid prolems if its read with the bitstream reader
+ * the bytewise contents of extradata must not depend on the architecture or cpu endianness
+ * - encoding: set/allocated/freed by lavc.
+ * - decoding: set/allocated/freed by user.
+ */
+ uint8_t *extradata;
+ int extradata_size;
+
+ /**
+ * this is the fundamental unit of time (in seconds) in terms
+ * of which frame timestamps are represented. for fixed-fps content,
+ * timebase should be 1/framerate and timestamp increments should be
+ * identically 1.
+ * - encoding: MUST be set by user
+ * - decoding: set by lavc.
+ */
+ AVRational time_base;
+
+ /* video only */
+ /**
+ * picture width / height.
+ * - encoding: MUST be set by user.
+ * - decoding: set by lavc.
+ * Note, for compatibility its possible to set this instead of
+ * coded_width/height before decoding
+ */
+ int width, height;
+
+#define FF_ASPECT_EXTENDED 15
+
+ /**
+ * the number of pictures in a group of pitures, or 0 for intra_only.
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int gop_size;
+
+ /**
+ * pixel format, see PIX_FMT_xxx.
+ * - encoding: set by user.
+ * - decoding: set by lavc.
+ */
+ enum PixelFormat pix_fmt;
+
+ /**
+ * Frame rate emulation. If not zero lower layer (i.e. format handler)
+ * has to read frames at native frame rate.
+ * - encoding: set by user.
+ * - decoding: unused.
+ */
+ int rate_emu;
+
+ /**
+ * if non NULL, 'draw_horiz_band' is called by the libavcodec
+ * decoder to draw an horizontal band. It improve cache usage. Not
+ * all codecs can do that. You must check the codec capabilities
+ * before
+ * - encoding: unused
+ * - decoding: set by user.
+ * @param height the height of the slice
+ * @param y the y position of the slice
+ * @param type 1->top field, 2->bottom field, 3->frame
+ * @param offset offset into the AVFrame.data from which the slice should be read
+ */
+ void (*draw_horiz_band)(struct AVCodecContext *s,
+ const AVFrame *src, int offset[4],
+ int y, int type, int height);
+
+ /* audio only */
+ int sample_rate; ///< samples per sec
+ int channels;
+
+ /**
+ * audio sample format.
+ * - encoding: set by user.
+ * - decoding: set by lavc.
+ */
+ enum SampleFormat sample_fmt; ///< sample format, currenly unused
+
+ /* the following data should not be initialized */
+ /**
+ * samples per packet. initialized when calling 'init'
+ */
+ int frame_size;
+ int frame_number; ///< audio or video frame number
+ int real_pict_num; ///< returns the real picture number of previous encoded frame
+
+ /**
+ * number of frames the decoded output will be delayed relative to
+ * the encoded input.
+ * - encoding: set by lavc.
+ * - decoding: unused
+ */
+ int delay;
+
+ /* - encoding parameters */
+ float qcompress; ///< amount of qscale change between easy & hard scenes (0.0-1.0)
+ float qblur; ///< amount of qscale smoothing over time (0.0-1.0)
+
+ /**
+ * minimum quantizer.
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int qmin;
+
+ /**
+ * maximum quantizer.
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int qmax;
+
+ /**
+ * maximum quantizer difference between frames.
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int max_qdiff;
+
+ /**
+ * maximum number of b frames between non b frames.
+ * note: the output will be delayed by max_b_frames+1 relative to the input
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int max_b_frames;
+
+ /**
+ * qscale factor between ip and b frames.
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ float b_quant_factor;
+
+ /** obsolete FIXME remove */
+ int rc_strategy;
+#define FF_RC_STRATEGY_XVID 1
+
+ int b_frame_strategy;
+
+ /**
+ * hurry up amount.
+ * - encoding: unused
+ * - decoding: set by user. 1-> skip b frames, 2-> skip idct/dequant too, 5-> skip everything except header
+ * @deprecated Deprecated in favor of skip_idct and skip_frame.
+ */
+ int hurry_up;
+
+ struct AVCodec *codec;
+
+ void *priv_data;
+
+#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
+ /* unused, FIXME remove*/
+ int rtp_mode;
+#endif
+
+ int rtp_payload_size; /* The size of the RTP payload: the coder will */
+ /* do it's best to deliver a chunk with size */
+ /* below rtp_payload_size, the chunk will start */
+ /* with a start code on some codecs like H.263 */
+ /* This doesn't take account of any particular */
+ /* headers inside the transmited RTP payload */
+
+
+ /* The RTP callback: This function is called */
+ /* every time the encoder has a packet to send */
+ /* Depends on the encoder if the data starts */
+ /* with a Start Code (it should) H.263 does. */
+ /* mb_nb contains the number of macroblocks */
+ /* encoded in the RTP payload */
+ void (*rtp_callback)(struct AVCodecContext *avctx, void *data, int size, int mb_nb);
+
+ /* statistics, used for 2-pass encoding */
+ int mv_bits;
+ int header_bits;
+ int i_tex_bits;
+ int p_tex_bits;
+ int i_count;
+ int p_count;
+ int skip_count;
+ int misc_bits;
+
+ /**
+ * number of bits used for the previously encoded frame.
+ * - encoding: set by lavc
+ * - decoding: unused
+ */
+ int frame_bits;
+
+ /**
+ * private data of the user, can be used to carry app specific stuff.
+ * - encoding: set by user
+ * - decoding: set by user
+ */
+ void *opaque;
+
+ char codec_name[32];
+ enum CodecType codec_type; /* see CODEC_TYPE_xxx */
+ enum CodecID codec_id; /* see CODEC_ID_xxx */
+
+ /**
+ * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
+ * this is used to workaround some encoder bugs
+ * a demuxer should set this to what is stored in the field used to identify the codec
+ * if there are mutiple such fields in a container then the demuxer should choose the one
+ * which maximizes the information about the used codec
+ * if the codec tag field in a container is larger then 32bit then the demxuer should
+ * remap the longer id to 32bit with a table or other structure alternatively a new
+ * extra_codec_tag + size could be added but for this a clear advantage must be demonstrated
+ * first
+ * - encoding: set by user, if not then the default based on codec_id will be used
+ * - decoding: set by user, will be converted to upper case by lavc during init
+ */
+ unsigned int codec_tag;
+
+ /**
+ * workaround bugs in encoders which sometimes cannot be detected automatically.
+ * - encoding: set by user
+ * - decoding: set by user
+ */
+ int workaround_bugs;
+#define FF_BUG_AUTODETECT 1 ///< autodetection
+#define FF_BUG_OLD_MSMPEG4 2
+#define FF_BUG_XVID_ILACE 4
+#define FF_BUG_UMP4 8
+#define FF_BUG_NO_PADDING 16
+#define FF_BUG_AMV 32
+#define FF_BUG_AC_VLC 0 ///< will be removed, libavcodec can now handle these non compliant files by default
+#define FF_BUG_QPEL_CHROMA 64
+#define FF_BUG_STD_QPEL 128
+#define FF_BUG_QPEL_CHROMA2 256
+#define FF_BUG_DIRECT_BLOCKSIZE 512
+#define FF_BUG_EDGE 1024
+#define FF_BUG_HPEL_CHROMA 2048
+#define FF_BUG_DC_CLIP 4096
+#define FF_BUG_MS 8192 ///< workaround various bugs in microsofts broken decoders
+//#define FF_BUG_FAKE_SCALABILITY 16 //autodetection should work 100%
+
+ /**
+ * luma single coeff elimination threshold.
+ * - encoding: set by user
+ * - decoding: unused
+ */
+ int luma_elim_threshold;
+
+ /**
+ * chroma single coeff elimination threshold.
+ * - encoding: set by user
+ * - decoding: unused
+ */
+ int chroma_elim_threshold;
+
+ /**
+ * strictly follow the std (MPEG4, ...).
+ * - encoding: set by user
+ * - decoding: unused
+ */
+ int strict_std_compliance;
+#define FF_COMPLIANCE_VERY_STRICT 2 ///< strictly conform to a older more strict version of the spec or reference software
+#define FF_COMPLIANCE_STRICT 1 ///< strictly conform to all the things in the spec no matter what consequences
+#define FF_COMPLIANCE_NORMAL 0
+#define FF_COMPLIANCE_INOFFICIAL -1 ///< allow inofficial extensions
+#define FF_COMPLIANCE_EXPERIMENTAL -2 ///< allow non standarized experimental things
+
+ /**
+ * qscale offset between ip and b frames.
+ * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset)
+ * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset)
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ float b_quant_offset;
+
+ /**
+ * error resilience higher values will detect more errors but may missdetect
+ * some more or less valid parts as errors.
+ * - encoding: unused
+ * - decoding: set by user
+ */
+ int error_resilience;
+#define FF_ER_CAREFUL 1
+#define FF_ER_COMPLIANT 2
+#define FF_ER_AGGRESSIVE 3
+#define FF_ER_VERY_AGGRESSIVE 4
+
+ /**
+ * 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 lavc
+ * avcodec_align_dimensions() should be used to find the required width and
+ * height, as they normally need to be rounded up to the next multiple of 16
+ * - encoding: unused
+ * - decoding: set by lavc, user can override
+ */
+ int (*get_buffer)(struct AVCodecContext *c, AVFrame *pic);
+
+ /**
+ * called to release buffers which where allocated with get_buffer.
+ * a released buffer can be reused in get_buffer()
+ * pic.data[*] must be set to NULL
+ * - encoding: unused
+ * - decoding: set by lavc, user can override
+ */
+ void (*release_buffer)(struct AVCodecContext *c, AVFrame *pic);
+
+ /**
+ * if 1 the stream has a 1 frame delay during decoding.
+ * - encoding: set by lavc
+ * - decoding: set by lavc
+ */
+ int has_b_frames;
+
+ /**
+ * number of bytes per packet if constant and known or 0
+ * used by some WAV based audio codecs
+ */
+ int block_align;
+
+ int parse_only; /* - decoding only: if true, only parsing is done
+ (function avcodec_parse_frame()). The frame
+ data is returned. Only MPEG codecs support this now. */
+
+ /**
+ * 0-> h263 quant 1-> mpeg quant.
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int mpeg_quant;
+
+ /**
+ * pass1 encoding statistics output buffer.
+ * - encoding: set by lavc
+ * - decoding: unused
+ */
+ char *stats_out;
+
+ /**
+ * pass2 encoding statistics input buffer.
+ * concatenated stuff from stats_out of pass1 should be placed here
+ * - encoding: allocated/set/freed by user
+ * - decoding: unused
+ */
+ char *stats_in;
+
+ /**
+ * ratecontrol qmin qmax limiting method.
+ * 0-> clipping, 1-> use a nice continous function to limit qscale wthin qmin/qmax
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ float rc_qsquish;
+
+ float rc_qmod_amp;
+ int rc_qmod_freq;
+
+ /**
+ * ratecontrol override, see RcOverride.
+ * - encoding: allocated/set/freed by user.
+ * - decoding: unused
+ */
+ RcOverride *rc_override;
+ int rc_override_count;
+
+ /**
+ * rate control equation.
+ * - encoding: set by user
+ * - decoding: unused
+ */
+ char *rc_eq;
+
+ /**
+ * maximum bitrate.
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int rc_max_rate;
+
+ /**
+ * minimum bitrate.
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int rc_min_rate;
+
+ /**
+ * decoder bitstream buffer size.
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int rc_buffer_size;
+ float rc_buffer_aggressivity;
+
+ /**
+ * qscale factor between p and i frames.
+ * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset)
+ * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset)
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ float i_quant_factor;
+
+ /**
+ * qscale offset between p and i frames.
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ float i_quant_offset;
+
+ /**
+ * initial complexity for pass1 ratecontrol.
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ float rc_initial_cplx;
+
+ /**
+ * dct algorithm, see FF_DCT_* below.
+ * - encoding: set by user
+ * - decoding: unused
+ */
+ int dct_algo;
+#define FF_DCT_AUTO 0
+#define FF_DCT_FASTINT 1
+#define FF_DCT_INT 2
+#define FF_DCT_MMX 3
+#define FF_DCT_MLIB 4
+#define FF_DCT_ALTIVEC 5
+#define FF_DCT_FAAN 6
+
+ /**
+ * luminance masking (0-> disabled).
+ * - encoding: set by user
+ * - decoding: unused
+ */
+ float lumi_masking;
+
+ /**
+ * temporary complexity masking (0-> disabled).
+ * - encoding: set by user
+ * - decoding: unused
+ */
+ float temporal_cplx_masking;
+
+ /**
+ * spatial complexity masking (0-> disabled).
+ * - encoding: set by user
+ * - decoding: unused
+ */
+ float spatial_cplx_masking;
+
+ /**
+ * p block masking (0-> disabled).
+ * - encoding: set by user
+ * - decoding: unused
+ */
+ float p_masking;
+
+ /**
+ * darkness masking (0-> disabled).
+ * - encoding: set by user
+ * - decoding: unused
+ */
+ float dark_masking;
+
+
+ /* for binary compatibility */
+ int unused;
+
+ /**
+ * idct algorithm, see FF_IDCT_* below.
+ * - encoding: set by user
+ * - decoding: set by user
+ */
+ int idct_algo;
+#define FF_IDCT_AUTO 0
+#define FF_IDCT_INT 1
+#define FF_IDCT_SIMPLE 2
+#define FF_IDCT_SIMPLEMMX 3
+#define FF_IDCT_LIBMPEG2MMX 4
+#define FF_IDCT_PS2 5
+#define FF_IDCT_MLIB 6
+#define FF_IDCT_ARM 7
+#define FF_IDCT_ALTIVEC 8
+#define FF_IDCT_SH4 9
+#define FF_IDCT_SIMPLEARM 10
+#define FF_IDCT_H264 11
+#define FF_IDCT_VP3 12
+#define FF_IDCT_IPP 13
+#define FF_IDCT_XVIDMMX 14
+#define FF_IDCT_CAVS 15
+#define FF_IDCT_SIMPLEARMV5TE 16
+#define FF_IDCT_SIMPLEARMV6 17
+
+ /**
+ * slice count.
+ * - encoding: set by lavc
+ * - decoding: set by user (or 0)
+ */
+ int slice_count;
+ /**
+ * slice offsets in the frame in bytes.
+ * - encoding: set/allocated by lavc
+ * - decoding: set/allocated by user (or NULL)
+ */
+ int *slice_offset;
+
+ /**
+ * error concealment flags.
+ * - encoding: unused
+ * - decoding: set by user
+ */
+ int error_concealment;
+#define FF_EC_GUESS_MVS 1
+#define FF_EC_DEBLOCK 2
+
+ /**
+ * dsp_mask could be add used to disable unwanted CPU features
+ * CPU features (i.e. MMX, SSE. ...)
+ *
+ * with FORCE flag you may instead enable given CPU features
+ * (Dangerous: usable in case of misdetection, improper usage however will
+ * result into program crash)
+ */
+ unsigned dsp_mask;
+#define FF_MM_FORCE 0x80000000 /* force usage of selected flags (OR) */
+ /* lower 16 bits - CPU features */
+#ifdef HAVE_MMX
+#define FF_MM_MMX 0x0001 /* standard MMX */
+#define FF_MM_3DNOW 0x0004 /* AMD 3DNOW */
+#define FF_MM_MMXEXT 0x0002 /* SSE integer functions or AMD MMX ext */
+#define FF_MM_SSE 0x0008 /* SSE functions */
+#define FF_MM_SSE2 0x0010 /* PIV SSE2 functions */
+#define FF_MM_3DNOWEXT 0x0020 /* AMD 3DNowExt */
+#endif /* HAVE_MMX */
+#ifdef HAVE_IWMMXT
+#define FF_MM_IWMMXT 0x0100 /* XScale IWMMXT */
+#endif /* HAVE_IWMMXT */
+
+ /**
+ * bits per sample/pixel from the demuxer (needed for huffyuv).
+ * - encoding: set by lavc
+ * - decoding: set by user
+ */
+ int bits_per_sample;
+
+ /**
+ * prediction method (needed for huffyuv).
+ * - encoding: set by user
+ * - decoding: unused
+ */
+ int prediction_method;
+#define FF_PRED_LEFT 0
+#define FF_PRED_PLANE 1
+#define FF_PRED_MEDIAN 2
+
+ /**
+ * sample aspect ratio (0 if unknown).
+ * numerator and denominator must be relative prime and smaller then 256 for some video standards
+ * - encoding: set by user.
+ * - decoding: set by lavc.
+ */
+ AVRational sample_aspect_ratio;
+
+ /**
+ * the picture in the bitstream.
+ * - encoding: set by lavc
+ * - decoding: set by lavc
+ */
+ AVFrame *coded_frame;
+
+ /**
+ * debug.
+ * - encoding: set by user.
+ * - decoding: set by user.
+ */
+ int debug;
+#define FF_DEBUG_PICT_INFO 1
+#define FF_DEBUG_RC 2
+#define FF_DEBUG_BITSTREAM 4
+#define FF_DEBUG_MB_TYPE 8
+#define FF_DEBUG_QP 16
+#define FF_DEBUG_MV 32
+#define FF_DEBUG_DCT_COEFF 0x00000040
+#define FF_DEBUG_SKIP 0x00000080
+#define FF_DEBUG_STARTCODE 0x00000100
+#define FF_DEBUG_PTS 0x00000200
+#define FF_DEBUG_ER 0x00000400
+#define FF_DEBUG_MMCO 0x00000800
+#define FF_DEBUG_BUGS 0x00001000
+#define FF_DEBUG_VIS_QP 0x00002000
+#define FF_DEBUG_VIS_MB_TYPE 0x00004000
+
+ /**
+ * debug.
+ * - encoding: set by user.
+ * - decoding: set by user.
+ */
+ int debug_mv;
+#define FF_DEBUG_VIS_MV_P_FOR 0x00000001 //visualize forward predicted MVs of P frames
+#define FF_DEBUG_VIS_MV_B_FOR 0x00000002 //visualize forward predicted MVs of B frames
+#define FF_DEBUG_VIS_MV_B_BACK 0x00000004 //visualize backward predicted MVs of B frames
+
+ /**
+ * error.
+ * - encoding: set by lavc if flags&CODEC_FLAG_PSNR
+ * - decoding: unused
+ */
+ uint64_t error[4];
+
+ /**
+ * minimum MB quantizer.
+ * - encoding: unused
+ * - decoding: unused
+ */
+ int mb_qmin;
+
+ /**
+ * maximum MB quantizer.
+ * - encoding: unused
+ * - decoding: unused
+ */
+ int mb_qmax;
+
+ /**
+ * motion estimation compare function.
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int me_cmp;
+ /**
+ * subpixel motion estimation compare function.
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int me_sub_cmp;
+ /**
+ * macroblock compare function (not supported yet).
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int mb_cmp;
+ /**
+ * interlaced dct compare function
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int ildct_cmp;
+#define FF_CMP_SAD 0
+#define FF_CMP_SSE 1
+#define FF_CMP_SATD 2
+#define FF_CMP_DCT 3
+#define FF_CMP_PSNR 4
+#define FF_CMP_BIT 5
+#define FF_CMP_RD 6
+#define FF_CMP_ZERO 7
+#define FF_CMP_VSAD 8
+#define FF_CMP_VSSE 9
+#define FF_CMP_NSSE 10
+#define FF_CMP_W53 11
+#define FF_CMP_W97 12
+#define FF_CMP_DCTMAX 13
+#define FF_CMP_DCT264 14
+#define FF_CMP_CHROMA 256
+
+ /**
+ * ME diamond size & shape.
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int dia_size;
+
+ /**
+ * amount of previous MV predictors (2a+1 x 2a+1 square).
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int last_predictor_count;
+
+ /**
+ * pre pass for motion estimation.
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int pre_me;
+
+ /**
+ * motion estimation pre pass compare function.
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int me_pre_cmp;
+
+ /**
+ * ME pre pass diamond size & shape.
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int pre_dia_size;
+
+ /**
+ * subpel ME quality.
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int me_subpel_quality;
+
+ /**
+ * callback to negotiate the pixelFormat.
+ * @param fmt is the list of formats which are supported by the codec,
+ * its terminated by -1 as 0 is a valid format, the formats are ordered by quality
+ * the first is allways the native one
+ * @return the choosen format
+ * - encoding: unused
+ * - decoding: set by user, if not set then the native format will always be choosen
+ */
+ enum PixelFormat (*get_format)(struct AVCodecContext *s, const enum PixelFormat * fmt);
+
+ /**
+ * DTG active format information (additionnal aspect ratio
+ * information only used in DVB MPEG2 transport streams). 0 if
+ * not set.
+ *
+ * - encoding: unused.
+ * - decoding: set by decoder
+ */
+ int dtg_active_format;
+#define FF_DTG_AFD_SAME 8
+#define FF_DTG_AFD_4_3 9
+#define FF_DTG_AFD_16_9 10
+#define FF_DTG_AFD_14_9 11
+#define FF_DTG_AFD_4_3_SP_14_9 13
+#define FF_DTG_AFD_16_9_SP_14_9 14
+#define FF_DTG_AFD_SP_4_3 15
+
+ /**
+ * Maximum motion estimation search range in subpel units.
+ * if 0 then no limit
+ *
+ * - encoding: set by user.
+ * - decoding: unused.
+ */
+ int me_range;
+
+ /**
+ * intra quantizer bias.
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int intra_quant_bias;
+#define FF_DEFAULT_QUANT_BIAS 999999
+
+ /**
+ * inter quantizer bias.
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int inter_quant_bias;
+
+ /**
+ * color table ID.
+ * - encoding: unused.
+ * - decoding: which clrtable should be used for 8bit RGB images
+ * table have to be stored somewhere FIXME
+ */
+ int color_table_id;
+
+ /**
+ * internal_buffer count.
+ * Don't touch, used by lavc default_get_buffer()
+ */
+ int internal_buffer_count;
+
+ /**
+ * internal_buffers.
+ * Don't touch, used by lavc default_get_buffer()
+ */
+ void *internal_buffer;
+
+#define FF_LAMBDA_SHIFT 7
+#define FF_LAMBDA_SCALE (1<<FF_LAMBDA_SHIFT)
+#define FF_QP2LAMBDA 118 ///< factor to convert from H.263 QP to lambda
+#define FF_LAMBDA_MAX (256*128-1)
+
+#define FF_QUALITY_SCALE FF_LAMBDA_SCALE //FIXME maybe remove
+ /**
+ * global quality for codecs which cannot change it per frame.
+ * this should be proportional to MPEG1/2/4 qscale.
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int global_quality;
+
+#define FF_CODER_TYPE_VLC 0
+#define FF_CODER_TYPE_AC 1
+ /**
+ * coder type
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int coder_type;
+
+ /**
+ * context model
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int context_model;
+#if 0
+ /**
+ *
+ * - encoding: unused
+ * - decoding: set by user.
+ */
+ uint8_t * (*realloc)(struct AVCodecContext *s, uint8_t *buf, int buf_size);
+#endif
+
+ /**
+ * slice flags
+ * - encoding: unused
+ * - decoding: set by user.
+ */
+ int slice_flags;
+#define SLICE_FLAG_CODED_ORDER 0x0001 ///< draw_horiz_band() is called in coded order instead of display
+#define SLICE_FLAG_ALLOW_FIELD 0x0002 ///< allow draw_horiz_band() with field slices (MPEG2 field pics)
+#define SLICE_FLAG_ALLOW_PLANE 0x0004 ///< allow draw_horiz_band() with 1 component at a time (SVQ1)
+
+ /**
+ * XVideo Motion Acceleration
+ * - encoding: forbidden
+ * - decoding: set by decoder
+ */
+ int xvmc_acceleration;
+
+ /**
+ * macroblock decision mode
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int mb_decision;
+#define FF_MB_DECISION_SIMPLE 0 ///< uses mb_cmp
+#define FF_MB_DECISION_BITS 1 ///< chooses the one which needs the fewest bits
+#define FF_MB_DECISION_RD 2 ///< rate distoration
+
+ /**
+ * custom intra quantization matrix
+ * - encoding: set by user, can be NULL
+ * - decoding: set by lavc
+ */
+ uint16_t *intra_matrix;
+
+ /**
+ * custom inter quantization matrix
+ * - encoding: set by user, can be NULL
+ * - decoding: set by lavc
+ */
+ uint16_t *inter_matrix;
+
+ /**
+ * fourcc from the AVI stream header (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
+ * this is used to workaround some encoder bugs
+ * - encoding: unused
+ * - decoding: set by user, will be converted to upper case by lavc during init
+ */
+ unsigned int stream_codec_tag;
+
+ /**
+ * scene change detection threshold.
+ * 0 is default, larger means fewer detected scene changes
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int scenechange_threshold;
+
+ /**
+ * minimum lagrange multipler
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int lmin;
+
+ /**
+ * maximum lagrange multipler
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int lmax;
+
+ /**
+ * Palette control structure
+ * - encoding: ??? (no palette-enabled encoder yet)
+ * - decoding: set by user.
+ */
+ struct AVPaletteControl *palctrl;
+
+ /**
+ * noise reduction strength
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int noise_reduction;
+
+ /**
+ * called at the beginning of a frame to get cr buffer for it.
+ * buffer type (size, hints) must be the same. lavc won't check it.
+ * lavc will pass previous buffer in pic, function should return
+ * same buffer or new buffer with old frame "painted" into it.
+ * if pic.data[0] == NULL must behave like get_buffer().
+ * - encoding: unused
+ * - decoding: set by lavc, user can override
+ */
+ int (*reget_buffer)(struct AVCodecContext *c, AVFrame *pic);
+
+ /**
+ * number of bits which should be loaded into the rc buffer before decoding starts
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int rc_initial_buffer_occupancy;
+
+ /**
+ *
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int inter_threshold;
+
+ /**
+ * CODEC_FLAG2_*.
+ * - encoding: set by user.
+ * - decoding: set by user.
+ */
+ int flags2;
+
+ /**
+ * simulates errors in the bitstream to test error concealment.
+ * - encoding: set by user.
+ * - decoding: unused.
+ */
+ int error_rate;
+
+ /**
+ * MP3 antialias algorithm, see FF_AA_* below.
+ * - encoding: unused
+ * - decoding: set by user
+ */
+ int antialias_algo;
+#define FF_AA_AUTO 0
+#define FF_AA_FASTINT 1 //not implemented yet
+#define FF_AA_INT 2
+#define FF_AA_FLOAT 3
+ /**
+ * Quantizer noise shaping.
+ * - encoding: set by user
+ * - decoding: unused
+ */
+ int quantizer_noise_shaping;
+
+ /**
+ * Thread count.
+ * is used to decide how many independent tasks should be passed to execute()
+ * - encoding: set by user
+ * - decoding: set by user
+ */
+ int thread_count;
+
+ /**
+ * 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
+ * @param count the number of things to execute
+ * - encoding: set by lavc, user can override
+ * - decoding: set by lavc, user can override
+ */
+ int (*execute)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg), void **arg2, int *ret, int count);
+
+ /**
+ * Thread opaque.
+ * can be used by execute() to store some per AVCodecContext stuff.
+ * - encoding: set by execute()
+ * - decoding: set by execute()
+ */
+ void *thread_opaque;
+
+ /**
+ * Motion estimation threshold. under which no motion estimation is
+ * performed, but instead the user specified motion vectors are used
+ *
+ * - encoding: set by user
+ * - decoding: unused
+ */
+ int me_threshold;
+
+ /**
+ * Macroblock threshold. under which the user specified macroblock types will be used
+ * - encoding: set by user
+ * - decoding: unused
+ */
+ int mb_threshold;
+
+ /**
+ * precision of the intra dc coefficient - 8.
+ * - encoding: set by user
+ * - decoding: unused
+ */
+ int intra_dc_precision;
+
+ /**
+ * noise vs. sse weight for the nsse comparsion function.
+ * - encoding: set by user
+ * - decoding: unused
+ */
+ int nsse_weight;
+
+ /**
+ * number of macroblock rows at the top which are skipped.
+ * - encoding: unused
+ * - decoding: set by user
+ */
+ int skip_top;
+
+ /**
+ * number of macroblock rows at the bottom which are skipped.
+ * - encoding: unused
+ * - decoding: set by user
+ */
+ int skip_bottom;
+
+ /**
+ * profile
+ * - encoding: set by user
+ * - decoding: set by lavc
+ */
+ int profile;
+#define FF_PROFILE_UNKNOWN -99
+
+ /**
+ * level
+ * - encoding: set by user
+ * - decoding: set by lavc
+ */
+ int level;
+#define FF_LEVEL_UNKNOWN -99
+
+ /**
+ * low resolution decoding. 1-> 1/2 size, 2->1/4 size
+ * - encoding: unused
+ * - decoding: set by user
+ */
+ int lowres;
+
+ /**
+ * bitsream width / height. may be different from width/height if lowres
+ * or other things are used
+ * - encoding: unused
+ * - decoding: set by user before init if known, codec should override / dynamically change if needed
+ */
+ int coded_width, coded_height;
+
+ /**
+ * frame skip threshold
+ * - encoding: set by user
+ * - decoding: unused
+ */
+ int frame_skip_threshold;
+
+ /**
+ * frame skip factor
+ * - encoding: set by user
+ * - decoding: unused
+ */
+ int frame_skip_factor;
+
+ /**
+ * frame skip exponent
+ * - encoding: set by user
+ * - decoding: unused
+ */
+ int frame_skip_exp;
+
+ /**
+ * frame skip comparission function
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int frame_skip_cmp;
+
+ /**
+ * border processing masking. raises the quantizer for mbs on the borders
+ * of the picture.
+ * - encoding: set by user
+ * - decoding: unused
+ */
+ float border_masking;
+
+ /**
+ * minimum MB lagrange multipler.
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int mb_lmin;
+
+ /**
+ * maximum MB lagrange multipler.
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int mb_lmax;
+
+ /**
+ *
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int me_penalty_compensation;
+
+ /**
+ *
+ * - encoding: unused
+ * - decoding: set by user.
+ */
+ enum AVDiscard skip_loop_filter;
+
+ /**
+ *
+ * - encoding: unused
+ * - decoding: set by user.
+ */
+ enum AVDiscard skip_idct;
+
+ /**
+ *
+ * - encoding: unused
+ * - decoding: set by user.
+ */
+ enum AVDiscard skip_frame;
+
+ /**
+ *
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int bidir_refine;
+
+ /**
+ *
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int brd_scale;
+
+ /**
+ * constant rate factor - quality-based VBR - values ~correspond to qps
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ float crf;
+
+ /**
+ * constant quantization parameter rate control method
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int cqp;
+
+ /**
+ * minimum gop size
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int keyint_min;
+
+ /**
+ * number of reference frames
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int refs;
+
+ /**
+ * chroma qp offset from luma
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int chromaoffset;
+
+ /**
+ * influences how often b-frames are used
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int bframebias;
+
+ /**
+ * trellis RD quantization
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int trellis;
+
+ /**
+ * reduce fluctuations in qp (before curve compression)
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ float complexityblur;
+
+ /**
+ * in-loop deblocking filter alphac0 parameter
+ * alpha is in the range -6...6
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int deblockalpha;
+
+ /**
+ * in-loop deblocking filter beta parameter
+ * beta is in the range -6...6
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int deblockbeta;
+
+ /**
+ * macroblock subpartition sizes to consider - p8x8, p4x4, b8x8, i8x8, i4x4
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int partitions;
+#define X264_PART_I4X4 0x001 /* Analyse i4x4 */
+#define X264_PART_I8X8 0x002 /* Analyse i8x8 (requires 8x8 transform) */
+#define X264_PART_P8X8 0x010 /* Analyse p16x8, p8x16 and p8x8 */
+#define X264_PART_P4X4 0x020 /* Analyse p8x4, p4x8, p4x4 */
+#define X264_PART_B8X8 0x100 /* Analyse b16x8, b8x16 and b8x8 */
+
+ /**
+ * direct mv prediction mode - 0 (none), 1 (spatial), 2 (temporal)
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int directpred;
+
+ /**
+ * audio cutoff bandwidth (0 means "automatic") . Currently used only by FAAC
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int cutoff;
+
+ /**
+ * multiplied by qscale for each frame and added to scene_change_score
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int scenechange_factor;
+
+ /**
+ *
+ * note: value depends upon the compare functin used for fullpel ME
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int mv0_threshold;
+
+ /**
+ * adjusts sensitivity of b_frame_strategy 1
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int b_sensitivity;
+
+ /**
+ * - encoding: set by user.
+ * - decoding: unused
+ */
+ int compression_level;
+#define FF_COMPRESSION_DEFAULT -1
+
+ /**
+ * sets whether to use LPC mode - used by FLAC encoder
+ * - encoding: set by user.
+ * - decoding: unused.
+ */
+ int use_lpc;
+
+ /**
+ * LPC coefficient precision - used by FLAC encoder
+ * - encoding: set by user.
+ * - decoding: unused.
+ */
+ int lpc_coeff_precision;
+
+ /**
+ * - encoding: set by user.
+ * - decoding: unused.
+ */
+ int min_prediction_order;
+
+ /**
+ * - encoding: set by user.
+ * - decoding: unused.
+ */
+ int max_prediction_order;
+
+ /**
+ * search method for selecting prediction order
+ * - encoding: set by user.
+ * - decoding: unused.
+ */
+ int prediction_order_method;
+
+ /**
+ * - encoding: set by user.
+ * - decoding: unused.
+ */
+ int min_partition_order;
+
+ /**
+ * - encoding: set by user.
+ * - decoding: unused.
+ */
+ int max_partition_order;
+
+ /**
+ * GOP timecode frame start number, in non drop frame format
+ * - encoding: set by user.
+ * - decoding: unused.
+ */
+ int64_t timecode_frame_start;
+} AVCodecContext;
+
+/**
+ * AVCodec.
+ */
+typedef struct AVCodec {
+ const char *name;
+ enum CodecType type;
+ enum CodecID id;
+ int priv_data_size;
+ int (*init)(AVCodecContext *);
+ int (*encode)(AVCodecContext *, uint8_t *buf, int buf_size, void *data);
+ int (*close)(AVCodecContext *);
+ int (*decode)(AVCodecContext *, void *outdata, int *outdata_size,
+ uint8_t *buf, int buf_size);
+ int capabilities;
+ struct AVCodec *next;
+ void (*flush)(AVCodecContext *);
+ const AVRational *supported_framerates; ///array of supported framerates, or NULL if any, array is terminated by {0,0}
+ const enum PixelFormat *pix_fmts; ///array of supported pixel formats, or NULL if unknown, array is terminanted by -1
+} AVCodec;
+
+/**
+ * four components are given, that's all.
+ * the last component is alpha
+ */
+typedef struct AVPicture {
+ uint8_t *data[4];
+ int linesize[4]; ///< number of bytes per line
+} AVPicture;
+
+/**
+ * AVPaletteControl
+ * This structure defines a method for communicating palette changes
+ * between and demuxer and a decoder.
+ * this is totally broken, palette changes should be sent as AVPackets
+ */
+#define AVPALETTE_SIZE 1024
+#define AVPALETTE_COUNT 256
+typedef struct AVPaletteControl {
+
+ /* demuxer sets this to 1 to indicate the palette has changed;
+ * decoder resets to 0 */
+ int palette_changed;
+
+ /* 4-byte ARGB palette entries, stored in native byte order; note that
+ * the individual palette components should be on a 8-bit scale; if
+ * the palette data comes from a IBM VGA native format, the component
+ * data is probably 6 bits in size and needs to be scaled */
+ unsigned int palette[AVPALETTE_COUNT];
+
+} AVPaletteControl attribute_deprecated;
+
+typedef struct AVSubtitleRect {
+ uint16_t x;
+ uint16_t y;
+ uint16_t w;
+ uint16_t h;
+ uint16_t nb_colors;
+ int linesize;
+ uint32_t *rgba_palette;
+ uint8_t *bitmap;
+} AVSubtitleRect;
+
+typedef struct AVSubtitle {
+ uint16_t format; /* 0 = graphics */
+ uint32_t start_display_time; /* relative to packet pts, in ms */
+ uint32_t end_display_time; /* relative to packet pts, in ms */
+ uint32_t num_rects;
+ AVSubtitleRect *rects;
+} AVSubtitle;
+
+extern AVCodec ac3_encoder;
+extern AVCodec amr_nb_encoder;
+extern AVCodec amr_wb_encoder;
+extern AVCodec asv1_encoder;
+extern AVCodec asv2_encoder;
+extern AVCodec bmp_encoder;
+extern AVCodec dvvideo_encoder;
+extern AVCodec faac_encoder;
+extern AVCodec ffv1_encoder;
+extern AVCodec ffvhuff_encoder;
+extern AVCodec flac_encoder;
+extern AVCodec flashsv_encoder;
+extern AVCodec flv_encoder;
+extern AVCodec gif_encoder;
+extern AVCodec h261_encoder;
+extern AVCodec h263_encoder;
+extern AVCodec h263p_encoder;
+extern AVCodec h264_encoder;
+extern AVCodec huffyuv_encoder;
+extern AVCodec jpegls_encoder;
+extern AVCodec libgsm_encoder;
+extern AVCodec libgsm_ms_encoder;
+extern AVCodec libtheora_encoder;
+extern AVCodec ljpeg_encoder;
+extern AVCodec mdec_encoder;
+extern AVCodec mjpeg_encoder;
+extern AVCodec mp2_encoder;
+extern AVCodec mp3lame_encoder;
+extern AVCodec mpeg1video_encoder;
+extern AVCodec mpeg2video_encoder;
+extern AVCodec mpeg4_encoder;
+extern AVCodec msmpeg4v1_encoder;
+extern AVCodec msmpeg4v2_encoder;
+extern AVCodec msmpeg4v3_encoder;
+extern AVCodec oggvorbis_encoder;
+extern AVCodec pam_encoder;
+extern AVCodec pbm_encoder;
+extern AVCodec pgm_encoder;
+extern AVCodec pgmyuv_encoder;
+extern AVCodec png_encoder;
+extern AVCodec ppm_encoder;
+extern AVCodec rv10_encoder;
+extern AVCodec rv20_encoder;
+extern AVCodec snow_encoder;
+extern AVCodec sonic_encoder;
+extern AVCodec sonic_ls_encoder;
+extern AVCodec svq1_encoder;
+extern AVCodec targa_encoder;
+extern AVCodec vcr1_encoder;
+extern AVCodec vorbis_encoder;
+extern AVCodec wmav1_encoder;
+extern AVCodec wmav2_encoder;
+extern AVCodec wmv1_encoder;
+extern AVCodec wmv2_encoder;
+extern AVCodec x264_encoder;
+extern AVCodec xvid_encoder;
+extern AVCodec zlib_encoder;
+extern AVCodec zmbv_encoder;
+
+extern AVCodec aac_decoder;
+extern AVCodec aasc_decoder;
+extern AVCodec alac_decoder;
+extern AVCodec amr_nb_decoder;
+extern AVCodec amr_wb_decoder;
+extern AVCodec asv1_decoder;
+extern AVCodec asv2_decoder;
+extern AVCodec avs_decoder;
+extern AVCodec bmp_decoder;
+extern AVCodec cavs_decoder;
+extern AVCodec cinepak_decoder;
+extern AVCodec cljr_decoder;
+extern AVCodec cook_decoder;
+extern AVCodec cscd_decoder;
+extern AVCodec cyuv_decoder;
+extern AVCodec dca_decoder;
+extern AVCodec dnxhd_decoder;
+extern AVCodec dsicinaudio_decoder;
+extern AVCodec dsicinvideo_decoder;
+extern AVCodec dvvideo_decoder;
+extern AVCodec dxa_decoder;
+extern AVCodec eightbps_decoder;
+extern AVCodec ffv1_decoder;
+extern AVCodec ffvhuff_decoder;
+extern AVCodec flac_decoder;
+extern AVCodec flashsv_decoder;
+extern AVCodec flic_decoder;
+extern AVCodec flv_decoder;
+extern AVCodec fourxm_decoder;
+extern AVCodec fraps_decoder;
+extern AVCodec gif_decoder;
+extern AVCodec h261_decoder;
+extern AVCodec h263_decoder;
+extern AVCodec h263i_decoder;
+extern AVCodec h264_decoder;
+extern AVCodec huffyuv_decoder;
+extern AVCodec idcin_decoder;
+extern AVCodec imc_decoder;
+extern AVCodec indeo2_decoder;
+extern AVCodec indeo3_decoder;
+extern AVCodec interplay_dpcm_decoder;
+extern AVCodec interplay_video_decoder;
+extern AVCodec kmvc_decoder;
+extern AVCodec libgsm_decoder;
+extern AVCodec libgsm_ms_decoder;
+extern AVCodec loco_decoder;
+extern AVCodec mace3_decoder;
+extern AVCodec mace6_decoder;
+extern AVCodec mdec_decoder;
+extern AVCodec mjpeg_decoder;
+extern AVCodec mjpegb_decoder;
+extern AVCodec mmvideo_decoder;
+extern AVCodec mp2_decoder;
+extern AVCodec mp3_decoder;
+extern AVCodec mp3adu_decoder;
+extern AVCodec mp3on4_decoder;
+extern AVCodec mpc7_decoder;
+extern AVCodec mpeg1video_decoder;
+extern AVCodec mpeg2video_decoder;
+extern AVCodec mpeg4_decoder;
+extern AVCodec mpeg4aac_decoder;
+extern AVCodec mpeg_xvmc_decoder;
+extern AVCodec mpegvideo_decoder;
+extern AVCodec msmpeg4v1_decoder;
+extern AVCodec msmpeg4v2_decoder;
+extern AVCodec msmpeg4v3_decoder;
+extern AVCodec msrle_decoder;
+extern AVCodec msvideo1_decoder;
+extern AVCodec mszh_decoder;
+extern AVCodec nuv_decoder;
+extern AVCodec oggvorbis_decoder;
+extern AVCodec png_decoder;
+extern AVCodec qdm2_decoder;
+extern AVCodec qdraw_decoder;
+extern AVCodec qpeg_decoder;
+extern AVCodec qtrle_decoder;
+extern AVCodec ra_144_decoder;
+extern AVCodec ra_288_decoder;
+extern AVCodec roq_decoder;
+extern AVCodec roq_dpcm_decoder;
+extern AVCodec rpza_decoder;
+extern AVCodec rv10_decoder;
+extern AVCodec rv20_decoder;
+extern AVCodec rv30_decoder;
+extern AVCodec rv40_decoder;
+extern AVCodec shorten_decoder;
+extern AVCodec smackaud_decoder;
+extern AVCodec smacker_decoder;
+extern AVCodec smc_decoder;
+extern AVCodec snow_decoder;
+extern AVCodec sol_dpcm_decoder;
+extern AVCodec sonic_decoder;
+extern AVCodec sp5x_decoder;
+extern AVCodec svq1_decoder;
+extern AVCodec svq3_decoder;
+extern AVCodec targa_decoder;
+extern AVCodec theora_decoder;
+extern AVCodec thp_decoder;
+extern AVCodec tiertexseqvideo_decoder;
+extern AVCodec tiff_decoder;
+extern AVCodec truemotion1_decoder;
+extern AVCodec truemotion2_decoder;
+extern AVCodec truespeech_decoder;
+extern AVCodec tscc_decoder;
+extern AVCodec tta_decoder;
+extern AVCodec ulti_decoder;
+extern AVCodec vc1_decoder;
+extern AVCodec vcr1_decoder;
+extern AVCodec vmdaudio_decoder;
+extern AVCodec vmdvideo_decoder;
+extern AVCodec vmnc_decoder;
+extern AVCodec vorbis_decoder;
+extern AVCodec vp3_decoder;
+extern AVCodec vp5_decoder;
+extern AVCodec vp6_decoder;
+extern AVCodec vp6f_decoder;
+extern AVCodec vqa_decoder;
+extern AVCodec wavpack_decoder;
+extern AVCodec wmav1_decoder;
+extern AVCodec wmav2_decoder;
+extern AVCodec wmv1_decoder;
+extern AVCodec wmv2_decoder;
+extern AVCodec wmv3_decoder;
+extern AVCodec wnv1_decoder;
+extern AVCodec ws_snd1_decoder;
+extern AVCodec xan_dpcm_decoder;
+extern AVCodec xan_wc3_decoder;
+extern AVCodec xl_decoder;
+extern AVCodec zlib_decoder;
+extern AVCodec zmbv_decoder;
+
+/* pcm codecs */
+#define PCM_CODEC(id, name) \
+extern AVCodec name ## _decoder; \
+extern AVCodec name ## _encoder
+
+PCM_CODEC(CODEC_ID_PCM_ALAW, pcm_alaw);
+PCM_CODEC(CODEC_ID_PCM_MULAW, pcm_mulaw);
+PCM_CODEC(CODEC_ID_PCM_S8, pcm_s8);
+PCM_CODEC(CODEC_ID_PCM_S16BE, pcm_s16be);
+PCM_CODEC(CODEC_ID_PCM_S16LE, pcm_s16le);
+PCM_CODEC(CODEC_ID_PCM_S24BE, pcm_s24be);
+PCM_CODEC(CODEC_ID_PCM_S24DAUD, pcm_s24daud);
+PCM_CODEC(CODEC_ID_PCM_S24LE, pcm_s24le);
+PCM_CODEC(CODEC_ID_PCM_S32BE, pcm_s32be);
+PCM_CODEC(CODEC_ID_PCM_S32LE, pcm_s32le);
+PCM_CODEC(CODEC_ID_PCM_U8, pcm_u8);
+PCM_CODEC(CODEC_ID_PCM_U16BE, pcm_u16be);
+PCM_CODEC(CODEC_ID_PCM_U16LE, pcm_u16le);
+PCM_CODEC(CODEC_ID_PCM_U24BE, pcm_u24be);
+PCM_CODEC(CODEC_ID_PCM_U24LE, pcm_u24le);
+PCM_CODEC(CODEC_ID_PCM_U32BE, pcm_u32be);
+PCM_CODEC(CODEC_ID_PCM_U32LE, pcm_u32le);
+
+/* adpcm codecs */
+
+PCM_CODEC(CODEC_ID_ADPCM_4XM, adpcm_4xm);
+PCM_CODEC(CODEC_ID_ADPCM_ADX, adpcm_adx);
+PCM_CODEC(CODEC_ID_ADPCM_CT, adpcm_ct);
+PCM_CODEC(CODEC_ID_ADPCM_EA, adpcm_ea);
+PCM_CODEC(CODEC_ID_ADPCM_G726, adpcm_g726);
+PCM_CODEC(CODEC_ID_ADPCM_IMA_DK3, adpcm_ima_dk3);
+PCM_CODEC(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4);
+PCM_CODEC(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt);
+PCM_CODEC(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav);
+PCM_CODEC(CODEC_ID_ADPCM_IMA_WS, adpcm_ima_ws);
+PCM_CODEC(CODEC_ID_ADPCM_MS, adpcm_ms);
+PCM_CODEC(CODEC_ID_ADPCM_SBPRO_2, adpcm_sbpro_2);
+PCM_CODEC(CODEC_ID_ADPCM_SBPRO_3, adpcm_sbpro_3);
+PCM_CODEC(CODEC_ID_ADPCM_SBPRO_4, adpcm_sbpro_4);
+PCM_CODEC(CODEC_ID_ADPCM_SMJPEG, adpcm_ima_smjpeg);
+PCM_CODEC(CODEC_ID_ADPCM_SWF, adpcm_swf);
+PCM_CODEC(CODEC_ID_ADPCM_XA, adpcm_xa);
+PCM_CODEC(CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha);
+
+#undef PCM_CODEC
+
+/* dummy raw video codec */
+extern AVCodec rawvideo_decoder;
+extern AVCodec rawvideo_encoder;
+
+/* the following codecs use external GPL libs */
+extern AVCodec dts_decoder;
+extern AVCodec liba52_decoder;
+
+/* subtitles */
+extern AVCodec dvbsub_decoder;
+extern AVCodec dvbsub_encoder;
+extern AVCodec dvdsub_decoder;
+extern AVCodec dvdsub_encoder;
+
+/* resample.c */
+
+struct ReSampleContext;
+struct AVResampleContext;
+
+typedef struct ReSampleContext ReSampleContext;
+
+ReSampleContext *audio_resample_init(int output_channels, int input_channels,
+ int output_rate, int input_rate);
+int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
+void audio_resample_close(ReSampleContext *s);
+
+struct AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_length, int log2_phase_count, int linear, double cutoff);
+int av_resample(struct AVResampleContext *c, short *dst, short *src, int *consumed, int src_size, int dst_size, int update_ctx);
+void av_resample_compensate(struct AVResampleContext *c, int sample_delta, int compensation_distance);
+void av_resample_close(struct AVResampleContext *c);
+
+#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
+/* YUV420 format is assumed ! */
+
+struct ImgReSampleContext attribute_deprecated;
+
+typedef struct ImgReSampleContext ImgReSampleContext attribute_deprecated;
+
+attribute_deprecated ImgReSampleContext *img_resample_init(int output_width, int output_height,
+ int input_width, int input_height);
+
+attribute_deprecated ImgReSampleContext *img_resample_full_init(int owidth, int oheight,
+ int iwidth, int iheight,
+ int topBand, int bottomBand,
+ int leftBand, int rightBand,
+ int padtop, int padbottom,
+ int padleft, int padright);
+
+
+attribute_deprecated void img_resample(ImgReSampleContext *s,
+ AVPicture *output, const AVPicture *input);
+
+attribute_deprecated void img_resample_close(ImgReSampleContext *s);
+
+#endif
+
+/**
+ * Allocate memory for a picture. Call avpicture_free to free it.
+ *
+ * @param picture the picture to be filled in.
+ * @param pix_fmt the format of the picture.
+ * @param width the width of the picture.
+ * @param height the height of the picture.
+ * @return Zero if successful, a negative value if not.
+ */
+int avpicture_alloc(AVPicture *picture, int pix_fmt, int width, int height);
+
+/**
+ * Free a picture previously allocated by avpicture_alloc().
+ *
+ * @param picture The AVPicture to be freed.
+ */
+void avpicture_free(AVPicture *picture);
+
+/**
+ * Fill in AVPicture's fields.
+ * The fields of the given AVPicture are filled in by using the 'ptr' address
+ * which points to the image data buffer. Depending on the specified picture
+ * format, one or multiple image data pointers and line sizes will be set.
+ * If a planar format is specified, several pointers will be set pointing to
+ * the different picture planes and the line sizes of the different planes
+ * will be stored in the lines_sizes array.
+ *
+ * @param picture AVPicture who's fields are to be filled in
+ * @param ptr Buffer which will contain or contains the actual image data
+ * @param pix_fmt The format in which the picture data is stored
+ * @param width The width of the image in pixels
+ * @param height The height of the image in pixels
+ * @return Size of the image data in bytes.
+ */
+int avpicture_fill(AVPicture *picture, uint8_t *ptr,
+ int pix_fmt, int width, int height);
+int avpicture_layout(const AVPicture* src, int pix_fmt, int width, int height,
+ unsigned char *dest, int dest_size);
+
+/**
+ * Calculate the size in bytes that a picture of the given width and height
+ * would occupy if stored in the given picture format.
+ *
+ * @param pix_fmt The given picture format
+ * @param width The width of the image
+ * @param height The height of the image
+ * @return Image data size in bytes
+ */
+int avpicture_get_size(int pix_fmt, int width, int height);
+void avcodec_get_chroma_sub_sample(int pix_fmt, int *h_shift, int *v_shift);
+const char *avcodec_get_pix_fmt_name(int pix_fmt);
+void avcodec_set_dimensions(AVCodecContext *s, int width, int height);
+enum PixelFormat avcodec_get_pix_fmt(const char* name);
+unsigned int avcodec_pix_fmt_to_codec_tag(enum PixelFormat p);
+
+#define FF_LOSS_RESOLUTION 0x0001 /**< loss due to resolution change */
+#define FF_LOSS_DEPTH 0x0002 /**< loss due to color depth change */
+#define FF_LOSS_COLORSPACE 0x0004 /**< loss due to color space conversion */
+#define FF_LOSS_ALPHA 0x0008 /**< loss of alpha bits */
+#define FF_LOSS_COLORQUANT 0x0010 /**< loss due to color quantization */
+#define FF_LOSS_CHROMA 0x0020 /**< loss of chroma (e.g. RGB to gray conversion) */
+
+/**
+ * Computes what kind of losses will occur when converting from one specific
+ * pixel format to another.
+ * When converting from one pixel format to another, information loss may occur.
+ * For example, when converting from RGB24 to GRAY, the color information will
+ * be lost. Similarly, other losses occur when converting from some formats to
+ * other formats. These losses can involve loss of chroma, but also loss of
+ * resolution, loss of color depth, loss due to the color space conversion, loss
+ * of the alpha bits or loss due to color quantization.
+ * avcodec_get_fix_fmt_loss() informs you on the various types of losses which
+ * will occur when converting from one pixel format to another.
+ *
+ * @param[in] dst_pix_fmt Destination pixel format.
+ * @param[in] src_pix_fmt Source pixel format.
+ * @param[in] has_alpha Whether the source pixel format alpha channel is used.
+ * @return Combination of flags informing you what kind of losses will occur.
+ */
+int avcodec_get_pix_fmt_loss(int dst_pix_fmt, int src_pix_fmt,
+ int has_alpha);
+
+/**
+ * Finds the best pixel format to convert to given a certain source pixel
+ * format. When converting from one pixel format to another, information loss
+ * may occur. For example, when converting from RGB24 to GRAY, the color
+ * information will be lost. Similarly, other losses occur when converting from
+ * some formats to other formats. avcodec_find_best_pix_fmt() searches which of
+ * the given pixel formats should be used to undergo the least amount of losses.
+ * The pixel formats from which it choses one, are determined by the
+ * \p pix_fmt_mask parameter.
+ *
+ * @code
+ * src_pix_fmt = PIX_FMT_YUV420P;
+ * pix_fmt_mask = (1 << PIX_FMT_YUV422P) || (1 << PIX_FMT_RGB24);
+ * dst_pix_fmt = avcodec_find_best_pix_fmt(pix_fmt_mask, src_pix_fmt, alpha, &loss);
+ * @endcode
+ *
+ * @param[in] pix_fmt_mask Bitmask determining which pixel format to choose from.
+ * @param[in] src_pix_fmt Source pixel format.
+ * @param[in] has_alpha Whether the source pixel format alpha channel is used.
+ * @param[out] loss_ptr Combination of flags informing you what kind of losses will occur.
+ * @return The best pixel format to convert to or -1 if none was found.
+ */
+int avcodec_find_best_pix_fmt(int pix_fmt_mask, int src_pix_fmt,
+ int has_alpha, int *loss_ptr);
+
+#define FF_ALPHA_TRANSP 0x0001 /* image has some totally transparent pixels */
+#define FF_ALPHA_SEMI_TRANSP 0x0002 /* image has some transparent pixels */
+
+/**
+ * Tell if an image really has transparent alpha values.
+ * @return ored mask of FF_ALPHA_xxx constants
+ */
+int img_get_alpha_info(const AVPicture *src,
+ int pix_fmt, int width, int height);
+
+#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
+/* convert among pixel formats */
+attribute_deprecated int img_convert(AVPicture *dst, int dst_pix_fmt,
+ const AVPicture *src, int pix_fmt,
+ int width, int height);
+#endif
+
+/* deinterlace a picture */
+/* deinterlace - if not supported return -1 */
+int avpicture_deinterlace(AVPicture *dst, const AVPicture *src,
+ int pix_fmt, int width, int height);
+
+/* external high level API */
+
+extern AVCodec *first_avcodec;
+
+/* returns LIBAVCODEC_VERSION_INT constant */
+unsigned avcodec_version(void);
+/* returns LIBAVCODEC_BUILD constant */
+unsigned avcodec_build(void);
+
+/**
+ * Initializes libavcodec.
+ *
+ * @warning This function \e must be called before any other libavcodec
+ * function.
+ */
+void avcodec_init(void);
+
+void register_avcodec(AVCodec *format);
+
+/**
+ * Finds an encoder with a matching codec ID.
+ *
+ * @param id CodecID of the requested encoder.
+ * @return An encoder if one was found, NULL otherwise.
+ */
+AVCodec *avcodec_find_encoder(enum CodecID id);
+
+/**
+ * Finds an encoder with the specified name.
+ *
+ * @param name Name of the requested encoder.
+ * @return An encoder if one was found, NULL otherwise.
+ */
+AVCodec *avcodec_find_encoder_by_name(const char *name);
+
+/**
+ * Finds a decoder with a matching codec ID.
+ *
+ * @param id CodecID of the requested decoder.
+ * @return A decoder if one was found, NULL otherwise.
+ */
+AVCodec *avcodec_find_decoder(enum CodecID id);
+
+/**
+ * Finds an decoder with the specified name.
+ *
+ * @param name Name of the requested decoder.
+ * @return A decoder if one was found, NULL otherwise.
+ */
+AVCodec *avcodec_find_decoder_by_name(const char *name);
+void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
+
+/**
+ * Sets the fields of the given AVCodecContext to default values.
+ *
+ * @param s The AVCodecContext of which the fields should be set to default values.
+ */
+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);
+
+/**
+ * Allocates an AVCodecContext and sets its fields to default values. The
+ * resulting struct can be deallocated by simply calling av_free().
+ *
+ * @return An AVCodecContext filled with default values or NULL on failure.
+ * @see avcodec_get_context_defaults
+ */
+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);
+
+/**
+ * Sets the fields of the given AVFrame to default values.
+ *
+ * @param pic The AVFrame of which the fields should be set to default values.
+ */
+void avcodec_get_frame_defaults(AVFrame *pic);
+
+/**
+ * Allocates an AVFrame and sets its fields to default values. The resulting
+ * struct can be deallocated by simply calling av_free().
+ *
+ * @return An AVFrame filled with default values or NULL on failure.
+ * @see avcodec_get_frame_defaults
+ */
+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);
+void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height);
+
+/**
+ * Checks if the given dimension of a picture is valid, meaning that all
+ * bytes of the picture can be addressed with a signed int.
+ *
+ * @param[in] w Width of the picture.
+ * @param[in] h Height of the picture.
+ * @return Zero if valid, a negative value if invalid.
+ */
+int avcodec_check_dimensions(void *av_log_ctx, unsigned int w, unsigned int h);
+enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat * fmt);
+
+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 avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count);
+//FIXME func typedef
+
+/**
+ * Initializes the AVCodecContext to use the given AVCodec. Prior to using this
+ * function the context has to be allocated.
+ *
+ * The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(),
+ * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for
+ * retrieving a codec.
+ *
+ * @warning This function is not thread save!
+ *
+ * @code
+ * codec = avcodec_find_decoder(CODEC_ID_H264);
+ * if (!codec)
+ * exit(1);
+ *
+ * context = avcodec_alloc_context();
+ *
+ * if (avcodec_open(context, codec) < 0)
+ * exit(1);
+ * @endcode
+ *
+ * @param avctx The context which will be setup to use the given codec.
+ * @param codec The codec to use within the context.
+ * @return Zero on success, a negative value on error.
+ * @see avcodec_alloc_context, avcodec_find_decoder, avcodec_find_encoder
+ */
+int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
+
+/**
+ * @deprecated Use avcodec_decode_audio2() instead.
+ */
+attribute_deprecated int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples,
+ int *frame_size_ptr,
+ uint8_t *buf, int buf_size);
+
+/**
+ * Decodes an audio frame from \p buf into \p samples.
+ * The avcodec_decode_audio2() function decodes a frame of audio from the input
+ * buffer \p buf of size \p buf_size. To decode it, it makes use of the
+ * audiocodec which was coupled with \p avctx using avcodec_open(). The
+ * resulting decoded frame is stored in output buffer \p samples. If no frame
+ * could be decompressed, \p frame_size_ptr is zero. Otherwise, it is the
+ * decompressed frame size in \e bytes.
+ *
+ * @warning You \e must set \p frame_size_ptr to the allocated size of the
+ * output buffer before calling avcodec_decode_audio2().
+ *
+ * @warning The input buffer must be \c FF_INPUT_BUFFER_PADDING_SIZE larger than
+ * the actual read bytes because some optimized bitstream readers read 32 or 64
+ * bits at once and could read over the end.
+ *
+ * @warning The end of the input buffer \p buf should be set to 0 to ensure that
+ * no overreading happens for damaged MPEG streams.
+ *
+ * @note You might have to align the input buffer \p buf and output buffer \p
+ * samples. The alignment requirements depend on the CPU: on some CPUs it isn't
+ * necessary at all, on others it won't work at all if not aligned and on others
+ * it will work but it will have an impact on performance. In practice, the
+ * bitstream should have 4 byte alignment at minimum and all sample data should
+ * be 16 byte aligned unless the CPU doesn't need it (AltiVec and SSE do). If
+ * the linesize is not a multiple of 16 then there's no sense in aligning the
+ * start of the buffer to 16.
+ *
+ * @param avctx The codec context.
+ * @param[out] samples The output buffer.
+ * @param[in,out] frame_size_ptr The output buffer size in bytes.
+ * @param[in] buf The input buffer.
+ * @param[in] buf_size The input buffer size in bytes.
+ * @return On error a negative value is returned, otherwise the number of bytes
+ * used or zero if no frame could be decompressed.
+ */
+int avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples,
+ int *frame_size_ptr,
+ uint8_t *buf, int buf_size);
+
+/**
+ * Decodes a video frame from \p buf into \p picture.
+ * The avcodec_decode_video() function decodes a frame of video from the input
+ * buffer \p buf of size \p buf_size. To decode it, it makes use of the
+ * videocodec which was coupled with \p avctx using avcodec_open(). The
+ * resulting decoded frame is stored in \p picture.
+ *
+ * @warning The input buffer must be \c FF_INPUT_BUFFER_PADDING_SIZE larger than
+ * the actual read bytes because some optimized bitstream readers read 32 or 64
+ * bits at once and could read over the end.
+ *
+ * @warning The end of the input buffer \p buf should be set to 0 to ensure that
+ * no overreading happens for damaged MPEG streams.
+ *
+ * @note You might have to align the input buffer \p buf and output buffer \p
+ * samples. The alignment requirements depend on the CPU: on some CPUs it isn't
+ * necessary at all, on others it won't work at all if not aligned and on others
+ * it will work but it will have an impact on performance. In practice, the
+ * bitstream should have 4 byte alignment at minimum and all sample data should
+ * be 16 byte aligned unless the CPU doesn't need it (AltiVec and SSE do). If
+ * the linesize is not a multiple of 16 then there's no sense in aligning the
+ * start of the buffer to 16.
+ *
+ * @param avctx The codec context.
+ * @param[out] picture The AVFrame in which the decoded video frame will be stored.
+ * @param[in] buf The input buffer.
+ * @param[in] buf_size The size of the input buffer in bytes.
+ * @param[in,out] got_picture_ptr Zero if no frame could be decompressed, otherwise, it is non zero.
+ * @return On error a negative value is returned, otherwise the number of bytes
+ * used or zero if no frame could be decompressed.
+ */
+int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
+ int *got_picture_ptr,
+ uint8_t *buf, int buf_size);
+
+/* decode a subtitle message. return -1 if error, otherwise return the
+ *number of bytes used. If no subtitle could be decompressed,
+ *got_sub_ptr is zero. Otherwise, the subtitle is stored in *sub. */
+int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub,
+ int *got_sub_ptr,
+ const uint8_t *buf, int buf_size);
+int avcodec_parse_frame(AVCodecContext *avctx, uint8_t **pdata,
+ int *data_size_ptr,
+ uint8_t *buf, int buf_size);
+
+/**
+ * Encodes an audio frame from \p samples into \p buf.
+ * The avcodec_encode_audio() function encodes a frame of audio from the input
+ * buffer \p samples. To encode it, it makes use of the audiocodec which was
+ * coupled with \p avctx using avcodec_open(). The resulting encoded frame is
+ * stored in output buffer \p buf.
+ *
+ * @note The output buffer should be at least \c FF_MIN_BUFFER_SIZE bytes large.
+ *
+ * @param avctx The codec context.
+ * @param[out] buf The output buffer.
+ * @param[in] buf_size The output buffer size.
+ * @param[in] samples The input buffer containing the samples.
+ * @return On error a negative value is returned, on succes zero or the number
+ * of bytes used from the input buffer.
+ */
+int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
+ const short *samples);
+
+/**
+ * Encodes a video frame from \p pict into \p buf.
+ * The avcodec_encode_video() function encodes a frame of video from the input
+ * \p pict. To encode it, it makes use of the videocodec which was coupled with
+ * \p avctx using avcodec_open(). The resulting encoded bytes representing the
+ * frame are stored in the output buffer \p buf. The input picture should be
+ * stored using a specific format, namely \c avctx.pix_fmt.
+ *
+ * @param avctx The codec context.
+ * @param[out] buf The output buffer for the bitstream of encoded frame.
+ * @param[in] buf_size The size of the outputbuffer in bytes.
+ * @param[in] pict The input picture to encode.
+ * @return On error a negative value is returned, on success zero or the number
+ * of bytes used from the input buffer.
+ */
+int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
+ const AVFrame *pict);
+int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
+ const AVSubtitle *sub);
+
+int avcodec_close(AVCodecContext *avctx);
+
+void avcodec_register_all(void);
+
+/**
+ * Flush buffers, should be called when seeking or when switching to a different stream.
+ */
+void avcodec_flush_buffers(AVCodecContext *avctx);
+
+void avcodec_default_free_buffers(AVCodecContext *s);
+
+/* misc useful functions */
+
+/**
+ * Returns a single letter to describe the given picture type \p pict_type.
+ *
+ * @param[in] pict_type The picture type.
+ * @return A single character representing the picture type.
+ */
+char av_get_pict_type_char(int pict_type);
+
+/**
+ * Returns codec bits per sample.
+ *
+ * @param[in] codec_id The codec.
+ * @return Number of bits per sample or zero if unknown for the given codec.
+ */
+int av_get_bits_per_sample(enum CodecID codec_id);
+
+/* frame parsing */
+typedef struct AVCodecParserContext {
+ void *priv_data;
+ struct AVCodecParser *parser;
+ int64_t frame_offset; /* offset of the current frame */
+ int64_t cur_offset; /* current offset
+ (incremented by each av_parser_parse()) */
+ int64_t last_frame_offset; /* offset of the last frame */
+ /* video info */
+ int pict_type; /* XXX: put it back in AVCodecContext */
+ int repeat_pict; /* XXX: put it back in AVCodecContext */
+ int64_t pts; /* pts of the current frame */
+ int64_t dts; /* dts of the current frame */
+
+ /* private data */
+ int64_t last_pts;
+ int64_t last_dts;
+ int fetch_timestamp;
+
+#define AV_PARSER_PTS_NB 4
+ int cur_frame_start_index;
+ int64_t cur_frame_offset[AV_PARSER_PTS_NB];
+ int64_t cur_frame_pts[AV_PARSER_PTS_NB];
+ int64_t cur_frame_dts[AV_PARSER_PTS_NB];
+
+ int flags;
+#define PARSER_FLAG_COMPLETE_FRAMES 0x0001
+} AVCodecParserContext;
+
+typedef struct AVCodecParser {
+ int codec_ids[5]; /* several codec IDs are permitted */
+ int priv_data_size;
+ int (*parser_init)(AVCodecParserContext *s);
+ int (*parser_parse)(AVCodecParserContext *s,
+ AVCodecContext *avctx,
+ uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size);
+ void (*parser_close)(AVCodecParserContext *s);
+ int (*split)(AVCodecContext *avctx, const uint8_t *buf, int buf_size);
+ struct AVCodecParser *next;
+} AVCodecParser;
+
+extern AVCodecParser *av_first_parser;
+
+void av_register_codec_parser(AVCodecParser *parser);
+AVCodecParserContext *av_parser_init(int codec_id);
+int av_parser_parse(AVCodecParserContext *s,
+ AVCodecContext *avctx,
+ uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size,
+ int64_t pts, int64_t dts);
+int av_parser_change(AVCodecParserContext *s,
+ AVCodecContext *avctx,
+ uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size, int keyframe);
+void av_parser_close(AVCodecParserContext *s);
+
+extern AVCodecParser aac_parser;
+extern AVCodecParser ac3_parser;
+extern AVCodecParser cavsvideo_parser;
+extern AVCodecParser dca_parser;
+extern AVCodecParser dvbsub_parser;
+extern AVCodecParser dvdsub_parser;
+extern AVCodecParser h261_parser;
+extern AVCodecParser h263_parser;
+extern AVCodecParser h264_parser;
+extern AVCodecParser mjpeg_parser;
+extern AVCodecParser mpeg4video_parser;
+extern AVCodecParser mpegaudio_parser;
+extern AVCodecParser mpegvideo_parser;
+extern AVCodecParser pnm_parser;
+extern AVCodecParser vc1_parser;
+
+
+typedef struct AVBitStreamFilterContext {
+ void *priv_data;
+ struct AVBitStreamFilter *filter;
+ AVCodecParserContext *parser;
+ struct AVBitStreamFilterContext *next;
+} AVBitStreamFilterContext;
+
+
+typedef struct AVBitStreamFilter {
+ const char *name;
+ int priv_data_size;
+ int (*filter)(AVBitStreamFilterContext *bsfc,
+ AVCodecContext *avctx, const char *args,
+ uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size, int keyframe);
+ struct AVBitStreamFilter *next;
+} AVBitStreamFilter;
+
+extern AVBitStreamFilter *av_first_bitstream_filter;
+
+void av_register_bitstream_filter(AVBitStreamFilter *bsf);
+AVBitStreamFilterContext *av_bitstream_filter_init(const char *name);
+int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc,
+ AVCodecContext *avctx, const char *args,
+ uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size, int keyframe);
+void av_bitstream_filter_close(AVBitStreamFilterContext *bsf);
+
+extern AVBitStreamFilter dump_extradata_bsf;
+extern AVBitStreamFilter remove_extradata_bsf;
+extern AVBitStreamFilter noise_bsf;
+extern AVBitStreamFilter mp3_header_compress_bsf;
+extern AVBitStreamFilter mp3_header_decompress_bsf;
+extern AVBitStreamFilter mjpega_dump_header_bsf;
+extern AVBitStreamFilter imx_dump_header_bsf;
+
+
+/* memory */
+
+/**
+ * Reallocates the given block if it is not large enough, otherwise it
+ * does nothing.
+ *
+ * @see av_realloc
+ */
+void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size);
+
+/* for static data only */
+
+/**
+ * Frees all static arrays and reset their pointers to 0.
+ * Call this function to release all statically allocated tables.
+ */
+attribute_deprecated void av_free_static(void);
+
+/**
+ * Allocation of static arrays.
+ *
+ * @warning Do not use for normal allocation.
+ *
+ * @param[in] size The amount of memory you need in bytes.
+ * @return Block of memory of the requested size.
+ */
+attribute_deprecated void *av_mallocz_static(unsigned int size);
+
+/**
+ * Copy image 'src' to 'dst'.
+ */
+void av_picture_copy(AVPicture *dst, const AVPicture *src,
+ int pix_fmt, int width, int height);
+
+/**
+ * Crop image top and left side
+ */
+int av_picture_crop(AVPicture *dst, const AVPicture *src,
+ int pix_fmt, int top_band, int left_band);
+
+/**
+ * Pad image
+ */
+int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width, int pix_fmt,
+ int padtop, int padbottom, int padleft, int padright, int *color);
+
+#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
+attribute_deprecated void img_copy(AVPicture *dst, const AVPicture *src,
+ int pix_fmt, int width, int height);
+
+attribute_deprecated int img_crop(AVPicture *dst, const AVPicture *src,
+ int pix_fmt, int top_band, int left_band);
+
+attribute_deprecated int img_pad(AVPicture *dst, const AVPicture *src, int height, int width, int pix_fmt,
+ int padtop, int padbottom, int padleft, int padright, int *color);
+#endif
+
+extern unsigned int av_xiphlacing(unsigned char *s, unsigned int v);
+
+/* 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 */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* AVCODEC_H */
diff --git a/src/libffmpeg/libavcodec/avs.c b/contrib/ffmpeg/libavcodec/avs.c
index ebfa8adb7..ebfa8adb7 100644
--- a/src/libffmpeg/libavcodec/avs.c
+++ b/contrib/ffmpeg/libavcodec/avs.c
diff --git a/contrib/ffmpeg/libavcodec/beosthread.c b/contrib/ffmpeg/libavcodec/beosthread.c
new file mode 100644
index 000000000..3d059912b
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/beosthread.c
@@ -0,0 +1,182 @@
+/*
+ * Copyright (c) 2004 François Revol <revol@free.fr>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 DEBUG
+
+#include "avcodec.h"
+#include "common.h"
+
+#include <OS.h>
+
+typedef struct ThreadContext{
+ AVCodecContext *avctx;
+ thread_id thread;
+ sem_id work_sem;
+ sem_id done_sem;
+ int (*func)(AVCodecContext *c, void *arg);
+ void *arg;
+ int ret;
+}ThreadContext;
+
+// it's odd Be never patented that :D
+struct benaphore {
+ vint32 atom;
+ sem_id sem;
+};
+static inline int lock_ben(struct benaphore *ben)
+{
+ if (atomic_add(&ben->atom, 1) > 0)
+ return acquire_sem(ben->sem);
+ return B_OK;
+}
+static inline int unlock_ben(struct benaphore *ben)
+{
+ if (atomic_add(&ben->atom, -1) > 1)
+ return release_sem(ben->sem);
+ return B_OK;
+}
+
+static struct benaphore av_thread_lib_ben;
+
+static int32 ff_thread_func(void *v){
+ ThreadContext *c= v;
+
+ for(;;){
+//printf("thread_func %X enter wait\n", (int)v); fflush(stdout);
+ acquire_sem(c->work_sem);
+//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);
+ else
+ return 0;
+//printf("thread_func %X signal complete\n", (int)v); fflush(stdout);
+ release_sem(c->done_sem);
+ }
+
+ return B_OK;
+}
+
+/**
+ * free what has been allocated by avcodec_thread_init().
+ * must be called after decoding has finished, especially dont call while avcodec_thread_execute() is running
+ */
+void avcodec_thread_free(AVCodecContext *s){
+ ThreadContext *c= s->thread_opaque;
+ int i;
+ int32 ret;
+
+ for(i=0; i<s->thread_count; i++){
+
+ c[i].func= NULL;
+ release_sem(c[i].work_sem);
+ wait_for_thread(c[i].thread, &ret);
+ if(c[i].work_sem > B_OK) delete_sem(c[i].work_sem);
+ if(c[i].done_sem > B_OK) delete_sem(c[i].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){
+ ThreadContext *c= s->thread_opaque;
+ int i;
+
+ 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; i<count; i++){
+ c[i].arg= arg[i];
+ c[i].func= func;
+ c[i].ret= 12345;
+
+ release_sem(c[i].work_sem);
+ }
+ for(i=0; i<count; i++){
+ acquire_sem(c[i].done_sem);
+
+ c[i].func= NULL;
+ if(ret) ret[i]= c[i].ret;
+ }
+ return 0;
+}
+
+int avcodec_thread_init(AVCodecContext *s, int thread_count){
+ int i;
+ ThreadContext *c;
+
+ s->thread_count= thread_count;
+
+ assert(!s->thread_opaque);
+ c= av_mallocz(sizeof(ThreadContext)*thread_count);
+ s->thread_opaque= c;
+
+ for(i=0; i<thread_count; i++){
+//printf("init semaphors %d\n", i); fflush(stdout);
+ c[i].avctx= s;
+
+ if((c[i].work_sem = create_sem(0, "ff work sem")) < B_OK)
+ goto fail;
+ if((c[i].done_sem = create_sem(0, "ff done sem")) < B_OK)
+ goto fail;
+
+//printf("create thread %d\n", i); fflush(stdout);
+ c[i].thread = spawn_thread(ff_thread_func, "libavcodec thread", B_LOW_PRIORITY, &c[i] );
+ if( c[i].thread < B_OK ) goto fail;
+ resume_thread(c[i].thread );
+ }
+//printf("init done\n"); fflush(stdout);
+
+ s->execute= avcodec_thread_execute;
+
+ return 0;
+fail:
+ avcodec_thread_free(s);
+ return -1;
+}
+
+/* provide a mean to serialize calls to avcodec_*() for thread safety. */
+
+int avcodec_thread_lock_lib(void)
+{
+ return lock_ben(&av_thread_lib_ben);
+}
+
+int avcodec_thread_unlock_lib(void)
+{
+ return unlock_ben(&av_thread_lib_ben);
+}
+
+/* our versions of _init and _fini (which are called by those actually from crt.o) */
+
+void initialize_after(void)
+{
+ av_thread_lib_ben.atom = 0;
+ av_thread_lib_ben.sem = create_sem(0, "libavcodec benaphore");
+}
+
+void uninitialize_before(void)
+{
+ delete_sem(av_thread_lib_ben.sem);
+}
+
+
+
diff --git a/contrib/ffmpeg/libavcodec/bfin/config_bfin.h b/contrib/ffmpeg/libavcodec/bfin/config_bfin.h
new file mode 100644
index 000000000..1f5080900
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/bfin/config_bfin.h
@@ -0,0 +1,46 @@
+/*
+ * config_bfin.h
+ *
+ * Copyright (C) 2007 Marc Hoffman <marc.hoffman@analog.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+/*
+ low level assembler interface wrapper
+
+DEFUN(put_pixels_clamped,mL1,
+ (DCTELEM *block, uint8_t *dest, int line_size)):
+
+ body
+
+ rts;
+*/
+#ifndef DEFUN
+
+#ifndef mL1
+#define mL1 .l1.text
+#endif
+#define mL3 .text
+
+#define DEFUN(fname,where,interface) \
+ .section where; \
+ .global _ff_bfin_ ## fname ; \
+ .align 8; \
+ _ff_bfin_ ## fname
+
+#endif
+
diff --git a/contrib/ffmpeg/libavcodec/bfin/dsputil_bfin.c b/contrib/ffmpeg/libavcodec/bfin/dsputil_bfin.c
new file mode 100644
index 000000000..b4d549fb7
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/bfin/dsputil_bfin.c
@@ -0,0 +1,310 @@
+/*
+ * BlackFin DSPUTILS
+ *
+ * Copyright (C) 2007 Marc Hoffman <marc.hoffman@analog.com>
+ * Copyright (c) 2006 Michael Benjamin <michael.benjamin@analog.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <unistd.h>
+#include <bits/bfin_sram.h>
+#include "../avcodec.h"
+#include "../dsputil.h"
+
+#define USE_L1CODE
+
+#ifdef USE_L1CODE
+#define L1CODE __attribute__ ((l1_text))
+#else
+#define L1CODE
+#endif
+int off;
+
+
+extern void ff_bfin_idct (DCTELEM *block) L1CODE;
+extern void ff_bfin_fdct (DCTELEM *block) L1CODE;
+extern void ff_bfin_add_pixels_clamped (DCTELEM *block, uint8_t *dest, int line_size) L1CODE;
+extern void ff_bfin_put_pixels_clamped (DCTELEM *block, uint8_t *dest, int line_size) L1CODE;
+extern void ff_bfin_diff_pixels (DCTELEM *block, uint8_t *s1, uint8_t *s2, int stride) L1CODE;
+extern void ff_bfin_get_pixels (DCTELEM *restrict block, const uint8_t *pixels, int line_size) L1CODE;
+extern int ff_bfin_pix_norm1 (uint8_t * pix, int line_size) L1CODE;
+extern int ff_bfin_z_sad8x8 (uint8_t *blk1, uint8_t *blk2, int dsz, int line_size, int h) L1CODE;
+extern int ff_bfin_z_sad16x16 (uint8_t *blk1, uint8_t *blk2, int dsz, int line_size, int h) L1CODE;
+
+extern void ff_bfin_z_put_pixels16_xy2 (uint8_t *block, const uint8_t *s0, int dest_size, int line_size, int h) L1CODE;
+extern void ff_bfin_z_put_pixels8_xy2 (uint8_t *block, const uint8_t *s0, int dest_size, int line_size, int h) L1CODE;
+extern void ff_bfin_put_pixels16_xy2_nornd (uint8_t *block, const uint8_t *s0, int line_size, int h) L1CODE;
+extern void ff_bfin_put_pixels8_xy2_nornd (uint8_t *block, const uint8_t *s0, int line_size, int h) L1CODE;
+
+
+extern int ff_bfin_pix_sum (uint8_t *p, int stride) L1CODE;
+
+extern void ff_bfin_put_pixels8uc (uint8_t *block, const uint8_t *s0, const uint8_t *s1, int dest_size, int line_size, int h) L1CODE;
+extern void ff_bfin_put_pixels16uc (uint8_t *block, const uint8_t *s0, const uint8_t *s1, int dest_size, int line_size, int h) L1CODE;
+extern void ff_bfin_put_pixels8uc_nornd (uint8_t *block, const uint8_t *s0, const uint8_t *s1, int line_size, int h) L1CODE;
+extern void ff_bfin_put_pixels16uc_nornd (uint8_t *block, const uint8_t *s0, const uint8_t *s1, int line_size, int h) L1CODE;
+
+extern int ff_bfin_sse4 (void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) L1CODE;
+extern int ff_bfin_sse8 (void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) L1CODE;
+extern int ff_bfin_sse16 (void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) L1CODE;
+
+
+#if 0
+void pblk (uint8_t *p, int w, int h, int s)
+{
+ int i,j;
+ av_log (0,0,"0x%08x:\n", p);
+ for (i = 0;i<h;i++) {
+ for (j=0;j<w;j++)
+ av_log (0,0,"%3d ", p[j]);
+ p+=s;
+ av_log (0,0,"\n");
+ }
+ av_log (0,0,"\n");
+}
+#endif
+
+static void bfin_idct_add (uint8_t *dest, int line_size, DCTELEM *block)
+{
+ ff_bfin_idct (block);
+ ff_bfin_add_pixels_clamped (block, dest, line_size);
+}
+
+static void bfin_idct_put (uint8_t *dest, int line_size, DCTELEM *block)
+{
+ ff_bfin_idct (block);
+ ff_bfin_put_pixels_clamped (block, dest, line_size);
+}
+
+
+static void bfin_clear_blocks (DCTELEM *blocks)
+{
+ // This is just a simple memset.
+ //
+ asm("P0=192; "
+ "I0=%0; "
+ "R0=0; "
+ "LSETUP(clear_blocks_blkfn_lab,clear_blocks_blkfn_lab)LC0=P0;"
+ "clear_blocks_blkfn_lab:"
+ "[I0++]=R0;"
+ ::"a" (blocks):"P0","I0","R0");
+}
+
+
+
+static void bfin_put_pixels8 (uint8_t *block, const uint8_t *pixels, int line_size, int h)
+{
+ ff_bfin_put_pixels8uc (block, pixels, pixels, line_size, line_size, h);
+}
+
+static void bfin_put_pixels8_x2(uint8_t *block, const uint8_t *pixels, int line_size, int h)
+{
+ ff_bfin_put_pixels8uc (block, pixels, pixels+1, line_size, line_size, h);
+}
+
+static void bfin_put_pixels8_y2 (uint8_t *block, const uint8_t *pixels, int line_size, int h)
+{
+ ff_bfin_put_pixels8uc (block, pixels, pixels+line_size, line_size, line_size, h);
+}
+
+static void bfin_put_pixels8_xy2 (uint8_t *block, const uint8_t *s0, int line_size, int h)
+{
+ ff_bfin_z_put_pixels8_xy2 (block,s0,line_size, line_size, h);
+}
+
+static void bfin_put_pixels16 (uint8_t *block, const uint8_t *pixels, int line_size, int h)
+{
+ ff_bfin_put_pixels16uc (block, pixels, pixels, line_size, line_size, h);
+}
+
+static void bfin_put_pixels16_x2 (uint8_t *block, const uint8_t *pixels, int line_size, int h)
+{
+ ff_bfin_put_pixels16uc (block, pixels, pixels+1, line_size, line_size, h);
+}
+
+static void bfin_put_pixels16_y2 (uint8_t *block, const uint8_t *pixels, int line_size, int h)
+{
+ ff_bfin_put_pixels16uc (block, pixels, pixels+line_size, line_size, line_size, h);
+}
+
+static void bfin_put_pixels16_xy2 (uint8_t *block, const uint8_t *s0, int line_size, int h)
+{
+ ff_bfin_z_put_pixels16_xy2 (block,s0,line_size, line_size, h);
+}
+
+void bfin_put_pixels8_nornd (uint8_t *block, const uint8_t *pixels, int line_size, int h)
+{
+ ff_bfin_put_pixels8uc_nornd (block, pixels, pixels, line_size, h);
+}
+
+static void bfin_put_pixels8_x2_nornd (uint8_t *block, const uint8_t *pixels, int line_size, int h)
+{
+ ff_bfin_put_pixels8uc_nornd (block, pixels, pixels+1, line_size, h);
+}
+
+static void bfin_put_pixels8_y2_nornd (uint8_t *block, const uint8_t *pixels, int line_size, int h)
+{
+ ff_bfin_put_pixels8uc_nornd (block, pixels, pixels+line_size, line_size, h);
+}
+
+
+void bfin_put_pixels16_nornd (uint8_t *block, const uint8_t *pixels, int line_size, int h)
+{
+ ff_bfin_put_pixels16uc_nornd (block, pixels, pixels, line_size, h);
+}
+
+static void bfin_put_pixels16_x2_nornd (uint8_t *block, const uint8_t *pixels, int line_size, int h)
+{
+ ff_bfin_put_pixels16uc_nornd (block, pixels, pixels+1, line_size, h);
+}
+
+static void bfin_put_pixels16_y2_nornd (uint8_t *block, const uint8_t *pixels, int line_size, int h)
+{
+ ff_bfin_put_pixels16uc_nornd (block, pixels, pixels+line_size, line_size, h);
+}
+
+static int bfin_pix_abs16 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
+{
+ return ff_bfin_z_sad16x16 (blk1,blk2,line_size,line_size,h);
+}
+
+static uint8_t vtmp_blk[256] __attribute__((l1_data_B));
+
+static int bfin_pix_abs16_x2 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
+{
+ ff_bfin_put_pixels16uc (vtmp_blk, blk2, blk2+1, 16, line_size, h);
+ return ff_bfin_z_sad16x16 (blk1, vtmp_blk, line_size, 16, h);
+}
+
+static int bfin_pix_abs16_y2 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
+{
+ ff_bfin_put_pixels16uc (vtmp_blk, blk2, blk2+line_size, 16, line_size, h);
+ return ff_bfin_z_sad16x16 (blk1, vtmp_blk, line_size, 16, h);
+}
+
+static int bfin_pix_abs16_xy2 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
+{
+ ff_bfin_z_put_pixels16_xy2 (vtmp_blk, blk2, 16, line_size, h);
+ return ff_bfin_z_sad16x16 (blk1, vtmp_blk, line_size, 16, h);
+}
+
+static int bfin_pix_abs8 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
+{
+ return ff_bfin_z_sad8x8 (blk1,blk2,line_size,line_size, h);
+}
+
+static int bfin_pix_abs8_x2 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
+{
+ ff_bfin_put_pixels8uc (vtmp_blk, blk2, blk2+1, 8, line_size, h);
+ return ff_bfin_z_sad8x8 (blk1, vtmp_blk, line_size, 8, h);
+}
+
+static int bfin_pix_abs8_y2 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
+{
+ ff_bfin_put_pixels8uc (vtmp_blk, blk2, blk2+line_size, 8, line_size, h);
+ return ff_bfin_z_sad8x8 (blk1, vtmp_blk, line_size, 8, h);
+}
+
+static int bfin_pix_abs8_xy2 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
+{
+ ff_bfin_z_put_pixels8_xy2 (vtmp_blk, blk2, 8, line_size, h);
+ return ff_bfin_z_sad8x8 (blk1, vtmp_blk, line_size, 8, h);
+}
+
+
+/*
+ decoder optimization
+ start on 2/11 100 frames of 352x240@25 compiled with no optimization -g debugging
+ 9.824s ~ 2.44x off
+ 6.360s ~ 1.58x off with -O2
+ 5.740s ~ 1.43x off with idcts
+
+ 2.64s 2/20 same sman.mp4 decode only
+
+*/
+
+void dsputil_init_bfin( DSPContext* c, AVCodecContext *avctx )
+{
+ c->get_pixels = ff_bfin_get_pixels;
+ c->diff_pixels = ff_bfin_diff_pixels;
+ c->put_pixels_clamped = ff_bfin_put_pixels_clamped;
+ c->add_pixels_clamped = ff_bfin_add_pixels_clamped;
+
+ c->clear_blocks = bfin_clear_blocks;
+ c->pix_sum = ff_bfin_pix_sum;
+ c->pix_norm1 = ff_bfin_pix_norm1;
+
+ c->sad[0] = bfin_pix_abs16;
+ c->sad[1] = bfin_pix_abs8;
+
+ /* TODO [0] 16 [1] 8 */
+ c->pix_abs[0][0] = bfin_pix_abs16;
+ c->pix_abs[0][1] = bfin_pix_abs16_x2;
+ c->pix_abs[0][2] = bfin_pix_abs16_y2;
+ c->pix_abs[0][3] = bfin_pix_abs16_xy2;
+
+ c->pix_abs[1][0] = bfin_pix_abs8;
+ c->pix_abs[1][1] = bfin_pix_abs8_x2;
+ c->pix_abs[1][2] = bfin_pix_abs8_y2;
+ c->pix_abs[1][3] = bfin_pix_abs8_xy2;
+
+
+ c->sse[0] = ff_bfin_sse16;
+ c->sse[1] = ff_bfin_sse8;
+ c->sse[2] = ff_bfin_sse4;
+
+
+ /**
+ * Halfpel motion compensation with rounding (a+b+1)>>1.
+ * This is an array[4][4] of motion compensation functions for 4
+ * horizontal blocksizes (8,16) and the 4 halfpel positions
+ * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
+ * @param block destination where the result is stored
+ * @param pixels source
+ * @param line_size number of bytes in a horizontal line of block
+ * @param h height
+ */
+
+ c->put_pixels_tab[0][0] = bfin_put_pixels16;
+ c->put_pixels_tab[0][1] = bfin_put_pixels16_x2;
+ c->put_pixels_tab[0][2] = bfin_put_pixels16_y2;
+ c->put_pixels_tab[0][3] = bfin_put_pixels16_xy2;
+
+ c->put_pixels_tab[1][0] = bfin_put_pixels8;
+ c->put_pixels_tab[1][1] = bfin_put_pixels8_x2;
+ c->put_pixels_tab[1][2] = bfin_put_pixels8_y2;
+ c->put_pixels_tab[1][3] = bfin_put_pixels8_xy2;
+
+ c->put_no_rnd_pixels_tab[1][0] = bfin_put_pixels8_nornd;
+ c->put_no_rnd_pixels_tab[1][1] = bfin_put_pixels8_x2_nornd;
+ c->put_no_rnd_pixels_tab[1][2] = bfin_put_pixels8_y2_nornd;
+ c->put_no_rnd_pixels_tab[1][3] = ff_bfin_put_pixels8_xy2_nornd;
+
+ c->put_no_rnd_pixels_tab[0][0] = bfin_put_pixels16_nornd;
+ c->put_no_rnd_pixels_tab[0][1] = bfin_put_pixels16_x2_nornd;
+ c->put_no_rnd_pixels_tab[0][2] = bfin_put_pixels16_y2_nornd;
+ c->put_no_rnd_pixels_tab[0][3] = ff_bfin_put_pixels16_xy2_nornd;
+
+ c->fdct = ff_bfin_fdct;
+ c->idct = ff_bfin_idct;
+ c->idct_add = bfin_idct_add;
+ c->idct_put = bfin_idct_put;
+}
+
+
+
diff --git a/contrib/ffmpeg/libavcodec/bfin/fdct_bfin.S b/contrib/ffmpeg/libavcodec/bfin/fdct_bfin.S
new file mode 100644
index 000000000..8230673e8
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/bfin/fdct_bfin.S
@@ -0,0 +1,324 @@
+/*
+ * fdct BlackFin
+ *
+ * Copyright (C) 2007 Marc Hoffman <marc.hoffman@analog.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+/*
+ void ff_bfin_fdct (DCTELEM *buf);
+
+ This implementation works only for 8x8 input. The range of input
+ must be -256 to 255 i.e. 8bit input represented in a 16bit data
+ word. The original data must be sign extended into the 16bit data
+ words.
+
+
+ Chen factorization of
+
+ 8
+ X(m) = sum (x(n) * cos ((2n+1)*m*pi/16))
+ n=0
+
+ C4
+ 0 --*-------------*0+7---*-----*0+3-------*-*-------------------> 0
+ \ / \ / X S4,S4
+ 1 --*-\---------/-*1+6---*-\-/-*1+2-------*-*-------------------> 4
+ \ / \ -C4 C3
+ 2 --*---\-----/---*2+5---*-/-\-*1-2---------------*-*-----------> 2
+ \ / / \ X S3,-S3
+ 3 --*-----\-/-----*3+4---*-----*0-3---------------*-*-----------> 6
+ / C7 C3
+ 4 --*-----/-\-----*3-4------------*-*4+5--*-----*---------------> 1
+ / \ -C4 X \ /S7 C3
+ 5 --*---/-----\---*2-5---*-*------*=*4-5----\-/------*-*--------> 5
+ / \ X S4,S4 / X S3,-S3
+ 6 --*-/---------\-*1-6---*-*------*=*7-6----/-\------*-*--------> 3
+ / \ C4 X / \-S7 C3
+ --*-------------*0-7------------*-*7+6--*-----*---------------> 7
+ C7
+
+Notation
+ Cn = cos(n*pi/8) used throughout the code.
+
+
+ Registers used:
+ R0, R1, R2, R3, R4, R5, R6,R7, P0, P1, P2, P3, P4, P5, A0, A1.
+ Other registers used:
+ I0, I1, I2, I3, B0, B2, B3, M0, M1, L3 registers and LC0.
+
+ Input - r0 - pointer to start of DCTELEM *block
+
+ Output - The DCT output coefficients in the DCTELEM *block
+
+ Register constraint:
+ This code is called from jpeg_encode.
+ R6, R5, R4 if modified should be stored and restored.
+
+
+ Performance: (Timer version 0.6.33)
+ Code Size : 240 Bytes.
+ Memory Required :
+ Input Matrix : 8 * 8 * 2 Bytes.
+ Coefficients : 16 Bytes
+ Temporary matrix: 8 * 8 * 2 Bytes.
+ Cycle Count :26+{18+8*(14+2S)}*2 where S -> Stalls
+ (7.45 c/pel)
+ -----------------------------------------
+ | Size | Forward DCT | Inverse DCT |
+ -----------------------------------------
+ | 8x8 | 284 Cycles | 311 Cycles |
+ -----------------------------------------
+
+Ck = int16(cos(k/16*pi)*32767+.5)/2
+#define C4 23170
+#define C3 13623
+#define C6 6270
+#define C7 3196
+
+Sk = int16(sin(k/16*pi)*32767+.5)/2
+#define S4 11585
+#define S3 9102
+#define S6 15137
+#define S7 16069
+
+the coefficients are ordered as follows:
+short dct_coef[]
+ C4,S4,
+ C6,S6,
+ C7,S7,
+ S3,C3,
+
+-----------------------------------------------------------
+FFMPEG conformance testing results
+-----------------------------------------------------------
+dct-test: modified with the following
+ dct_error("BFINfdct", 0, ff_bfin_fdct, fdct, test);
+produces the following output:
+
+root:/u/ffmpeg/bhead/libavcodec> ./dct-test
+ffmpeg DCT/IDCT test
+
+ 2 -131 -6 -48 -36 33 -83 24
+ 34 52 -24 -15 5 92 57 143
+ -67 -43 -1 74 -16 5 -71 32
+ -78 106 92 -34 -38 81 20 -18
+ 7 -62 40 2 -15 90 -62 -83
+ -83 1 -104 -13 43 -19 7 11
+ -63 31 12 -29 83 72 21 10
+ -17 -63 -15 73 50 -91 159 -14
+DCT BFINfdct: err_inf=2 err2=0.16425938 syserr=0.00795000 maxout=2098 blockSumErr=27
+DCT BFINfdct: 92.1 kdct/s
+root:/u/ffmpeg/bhead/libavcodec>
+
+*/
+
+#include "config_bfin.h"
+
+.section .l1.data.B,"aw",@progbits
+.align 4;
+dct_coeff:
+.short 0x5a82, 0x2d41, 0x187e, 0x3b21, 0x0c7c, 0x3ec5, 0x238e, 0x3537;
+
+.section .l1.data.A,"aw",@progbits
+.align 4
+vtmp: .space 128
+
+DEFUN(fdct,mL1,
+ (DCTELEM *block)):
+ [--SP] = (R7:4, P5:3); // Push the registers onto the stack.
+
+ b0 = r0;
+ r0 = [P3+dct_coeff@GOT17M4];
+ b3 = r0;
+ r0 = [P3+vtmp@GOT17M4];
+ b2 = r0;
+
+ L3 = 16; // L3 is set to 16 to make the coefficient
+ // array Circular.
+
+
+//----------------------------------------------------------------------------
+
+/*
+ * I0, I1, and I2 registers are used to read the input data. I3 register is used
+ * to read the coefficients. P0 and P1 registers are used for writing the output
+ * data.
+ */
+ M0 = 12 (X); // All these initializations are used in the
+ M1 = 16 (X); // modification of address offsets.
+
+ M2 = 128 (X);
+
+ P2 = 16;
+ P3 = 32 (X);
+ P4 = -110 (X);
+ P5 = -62 (X);
+ P0 = 2(X);
+
+
+ // Prescale the input to get the correct precision.
+ i0=b0;
+ i1=b0;
+
+ lsetup (.0, .1) LC0 = P3;
+ r0=[i0++];
+.0: r1=r0<<3 (v) || r0=[i0++] ;
+.1: [i1++]=r1;
+
+ /*
+ * B0 points to the "in" buffer.
+ * B2 points to "temp" buffer in the first iteration.
+ */
+
+ lsetup (.2, .3) LC0 = P0;
+.2:
+ I0 = B0; // I0 points to Input Element (0, 0).
+ I1 = B0; // Element 1 and 0 is read in R0.
+ I1 += M0 || R0 = [I0++]; // I1 points to Input Element (0, 6).
+ I2 = I1; // Element 6 is read into R3.H.
+ I2 -= 4 || R3.H = W[I1++]; // I2 points to Input Element (0, 4).
+
+ I3 = B3; // I3 points to Coefficients.
+ P0 = B2; // P0 points to temporary array Element
+ // (0, 0).
+ P1 = B2; // P1 points to temporary array.
+ R7 = [P1++P2] || R2 = [I2++]; // P1 points to temporary array
+ // Element (1, 0).
+ // R7 is a dummy read. X4,X5
+ // are read into R2.
+ R3.L = W[I1--]; // X7 is read into R3.L.
+ R1.H = W[I0++]; // X2 is read into R1.H.
+
+
+ /*
+ * X0 = (X0 + X7) / 2.
+ * X1 = (X1 + X6) / 2.
+ * X6 = (X1 - X6) / 2.
+ * X7 = (X0 - X7) / 2.
+ * It reads the data 3 in R1.L.
+ */
+
+ R0 = R0 +|+ R3, R3 = R0 -|- R3 || R1.L = W[I0++] || NOP;
+
+ /*
+ * X2 = (X2 + X5) / 2.
+ * X3 = (X3 + X4) / 2.
+ * X4 = (X3 - X4) / 2.
+ * X5 = (X2 - X5) / 2.
+ * R7 = C4 = cos(4*pi/16)
+ */
+
+ R1 = R1 +|+ R2, R2 = R1 -|- R2 (CO) || NOP || R7 = [I3++];
+
+ /*
+ * At the end of stage 1 R0 has (1,0), R1 has (2,3), R2 has (4, 5) and
+ * R3 has (6,7).
+ * Where the notation (x, y) represents uper/lower half pairs.
+ */
+
+ /*
+ * X0 = X0 + X3.
+ * X1 = X1 + X2.
+ * X2 = X1 - X2.
+ * X3 = X0 - X3.
+ */
+ R0 = R0 +|+ R1, R1 = R0 -|- R1;
+
+ lsetup (.row0, .row1) LC1 = P2 >> 1; // 1d dct, loops 8x
+.row0:
+
+ /*
+ * This is part 2 computation continued.....
+ * A1 = X6 * cos(pi/4)
+ * A0 = X6 * cos(pi/4)
+ * A1 = A1 - X5 * cos(pi/4)
+ * A0 = A0 + X5 * cos(pi/4).
+ * The instruction W[I0] = R3.L is used for packing it to R2.L.
+ */
+
+ A1=R3.H*R7.l, A0=R3.H*R7.l || I1+=M1 || W[I0] = R3.L;
+ R4.H=(A1-=R2.L*R7.l), R4.L=(A0+=R2.L*R7.l) || I2+=M0 || NOP;
+
+ /* R0 = (X1,X0) R1 = (X2,X3) R4 = (X5, X6). */
+
+ /*
+ * A1 = X0 * cos(pi/4)
+ * A0 = X0 * cos(pi/4)
+ * A1 = A1 - X1 * cos(pi/4)
+ * A0 = A0 + X1 * cos(pi/4)
+ * R7 = (C2,C6)
+ */
+ A1=R0.L*R7.h, A0=R0.L*R7.h || NOP || R3.H=W[I1++];
+ R5.H=(A1-=R0.H*R7.h),R5.L=(A0+=R0.H*R7.h) || R7=[I3++] || NOP;
+
+ /*
+ * A1 = X2 * cos(3pi/8)
+ * A0 = X3 * cos(3pi/8)
+ * A1 = A1 + X3 * cos(pi/8)
+ * A0 = A0 - X2 * cos(pi/8)
+ * R3 = cos(pi/4)
+ * R7 = (cos(7pi/8),cos(pi/8))
+ * X4 = X4 + X5.
+ * X5 = X4 - X5.
+ * X6 = X7 - X6.
+ * X7 = X7 + X6.
+ */
+ A1=R1.H*R7.L, A0=R1.L*R7.L || W[P0++P3]=R5.L || R2.L=W[I0];
+ R2=R2+|+R4, R4=R2-|-R4 || I0+=4 || R3.L=W[I1--];
+ R6.H=(A1+=R1.L*R7.H),R6.L=(A0 -= R1.H * R7.H) || I0+=4 || R7=[I3++];
+
+ /* R2 = (X4, X7) R4 = (X5,X6) R5 = (X1, X0) R6 = (X2,X3). */
+
+ /*
+ * A1 = X4 * cos(7pi/16)
+ * A0 = X7 * cos(7pi/16)
+ * A1 = A1 + X7 * cos(pi/16)
+ * A0 = A0 - X4 * cos(pi/16)
+ */
+
+ A1=R2.H*R7.L, A0=R2.L*R7.L || W[P0++P3]=R6.H || R0=[I0++];
+ R2.H=(A1+=R2.L*R7.H),R2.L=(A0-=R2.H*R7.H) || W[P0++P3]=R5.H || R7=[I3++];
+
+ /*
+ * A1 = X5 * cos(3pi/16)
+ * A0 = X6 * cos(3pi/16)
+ * A1 = A1 + X6 * cos(5pi/16)
+ * A0 = A0 - X5 * cos(5pi/16)
+ * The output values are written.
+ */
+
+ A1=R4.H*R7.H, A0=R4.L*R7.H || W[P0++P2]=R6.L || R1.H=W[I0++];
+ R4.H=(A1+=R4.L*R7.L),R4.L=(A0-=R4.H*R7.L) || W[P0++P4]=R2.L || R1.L=W[I0++];
+
+
+ /* Beginning of next stage, **pipelined** + drain and store the
+ rest of the column store. */
+
+ R0=R0+|+R3,R3=R0-|-R3 || W[P1++P3]=R2.H || R2=[I2++];
+ R1=R1+|+R2,R2=R1-|-R2 (CO) || W[P1++P3]=R4.L || R7=[I3++];
+.row1: R0=R0+|+R1,R1=R0-|-R1 || W[P1++P5]=R4.H || NOP;
+
+ // Exchange input with output.
+ B1 = B0;
+ B0 = B2;
+.3: B2 = B1;
+
+ L3=0;
+ (r7:4,p5:3) = [sp++];
+ RTS;
+
diff --git a/contrib/ffmpeg/libavcodec/bfin/idct_bfin.S b/contrib/ffmpeg/libavcodec/bfin/idct_bfin.S
new file mode 100644
index 000000000..f6904c189
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/bfin/idct_bfin.S
@@ -0,0 +1,297 @@
+/*
+ * idct BlackFin
+ *
+ * Copyright (C) 2007 Marc Hoffman <marc.hoffman@analog.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+/*
+ This blackfin DSP code implements an 8x8 inverse type II DCT.
+
+Prototype : void ff_bfin_idct(DCTELEM *in)
+
+Registers Used : A0, A1, R0-R7, I0-I3, B0, B2, B3, M0-M2, L0-L3, P0-P5, LC0.
+
+Performance :
+ Code Size : 498 Bytes.
+ Cycle Count : 417 Cycles
+
+
+-----------------------------------------------------------
+FFMPEG conformance testing results
+-----------------------------------------------------------
+
+dct-test: modified with the following
+ dct_error("BFINidct", 1, ff_bfin_idct, idct, test);
+produces the following output
+
+root:/u/ffmpeg/bhead/libavcodec> ./dct-test -i
+ffmpeg DCT/IDCT test
+
+ 8 15 -2 21 24 17 0 10
+ 2 -10 -5 -5 -3 7 -14 -3
+ 2 -13 -10 -19 18 -6 6 -2
+ 9 4 16 -3 9 12 10 15
+ 15 -9 -2 10 1 16 0 -15
+ -15 5 7 3 13 0 13 20
+ -6 -15 24 9 -18 1 9 -22
+ -8 25 23 2 -7 0 30 13
+IDCT BFINidct: err_inf=1 err2=0.01002344 syserr=0.00150000 maxout=266 blockSumErr=64
+IDCT BFINidct: 88.3 kdct/s
+
+*/
+
+#include "config_bfin.h"
+
+.section .l1.data.B,"aw",@progbits
+
+.align 4;
+coefs:
+.short 0x5a82; // C4
+.short 0x5a82; // C4
+.short 0x30FC; //cos(3pi/8) C6
+.short 0x7642; //cos(pi/8) C2
+.short 0x18F9; //cos(7pi/16)
+.short 0x7D8A; //cos(pi/16)
+.short 0x471D; //cos(5pi/16)
+.short 0x6A6E; //cos(3pi/16)
+.short 0x18F9; //cos(7pi/16)
+.short 0x7D8A; //cos(pi/16)
+
+.section .l1.data.A
+
+vtmp: .space 256
+
+#define TMP0 FP-8
+#define TMP1 FP-12
+#define TMP2 FP-16
+
+
+DEFUN(idct,mL1,
+ (DCTELEM *block)):
+
+/********************** Function Prologue *********************************/
+ link 16;
+ [--SP] = (R7:4, P5:3); // Push the registers onto the stack.
+ B0 = R0; // Pointer to Input matrix
+ R1 = [P3+coefs@GOT17M4]; // Pointer to Coefficients
+ R2 = [P3+vtmp@GOT17M4]; // Pointer to Temporary matrix
+ B3 = R1;
+ B2 = R2;
+ L3 = 20; // L3 is used for making the coefficient array
+ // circular.
+ // MUST BE RESTORED TO ZERO at function exit.
+ M1 = 16 (X); // All these registers are initialized for
+ M3 = 8(X); // modifying address offsets.
+
+ I0 = B0; // I0 points to Input Element (0, 0).
+ I2 = B0; // I2 points to Input Element (0, 0).
+ I2 += M3 || R0.H = W[I0];
+ // Element 0 is read into R0.H
+ I1 = I2; // I1 points to input Element (0, 6).
+ I1 += 4 || R0.L = W[I2++];
+ // I2 points to input Element (0, 4).
+ // Element 4 is read into R0.L.
+ P2 = 8 (X);
+ P3 = 32 (X);
+ P4 = -32 (X);
+ P5 = 98 (X);
+ R7 = 0x8000(Z);
+ I3 = B3; // I3 points to Coefficients
+ P0 = B2; // P0 points to array Element (0, 0) of temp
+ P1 = B2;
+ R7 = [I3++] || [TMP2]=R7; // Coefficient C4 is read into R7.H and R7.L.
+ MNOP;
+ NOP;
+
+ /*
+ * A1 = Y0 * cos(pi/4)
+ * A0 = Y0 * cos(pi/4)
+ * A1 = A1 + Y4 * cos(pi/4)
+ * A0 = A0 - Y4 * cos(pi/4)
+ * load:
+ * R1=(Y2,Y6)
+ * R7=(C2,C6)
+ * res:
+ * R3=Y0, R2=Y4
+ */
+ A1=R7.H*R0.H, A0=R7.H*R0.H (IS) || I0+= 4 || R1.L=W[I1++];
+ R3=(A1+=R7.H*R0.L), R2=(A0-=R7.H*R0.L) (IS) || R1.H=W[I0--] || R7=[I3++];
+
+ LSETUP (.0, .1) LC0 = P2; // perform 8 1d idcts
+
+ P2 = 112 (X);
+ P1 = P1 + P2; // P1 points to element (7, 0) of temp buffer.
+ P2 = -94(X);
+
+.0:
+ /*
+ * A1 = Y2 * cos(3pi/8)
+ * A0 = Y2 * cos(pi/8)
+ * A1 = A1 - Y6 * cos(pi/8)
+ * A0 = A0 + Y6 * cos(3pi/8)
+ * R5 = (Y1,Y7)
+ * R7 = (C1,C7)
+ * res:
+ * R1=Y2, R0=Y6
+ */
+ A1=R7.L*R1.H, A0=R7.H*R1.H (IS) || I0+=4 || R5.H=W[I0];
+ R1=(A1-=R7.H*R1.L), R0=(A0+=R7.L*R1.L) (IS) || R5.L=W[I1--] || R7=[I3++];
+ /*
+ * Y0 = Y0 + Y6.
+ * Y4 = Y4 + Y2.
+ * Y2 = Y4 - Y2.
+ * Y6 = Y0 - Y6.
+ * R3 is saved
+ * R6.l=Y3
+ * note: R3: Y0, R2: Y4, R1: Y2, R0: Y6
+ */
+ R3=R3+R0, R0=R3-R0;
+ R2=R2+R1, R1=R2-R1 || [TMP0]=R3 || R6.L=W[I0--];
+ /*
+ * Compute the odd portion (1,3,5,7) even is done.
+ *
+ * Y1 = C7 * Y1 - C1 * Y7 + C3 * Y5 - C5 * Y3.
+ * Y7 = C1 * Y1 + C7 * Y7 + C5 * Y5 + C3 * Y3.
+ * Y5 = C5 * Y1 + C3 * Y7 + C7 * Y5 - C1 * Y3.
+ * Y3 = C3 * Y1 - C5 * Y7 - C1 * Y5 - C7 * Y3.
+ */
+ // R5=(Y1,Y7) R6=(Y5,Y3) // R7=(C1,C7)
+ A1 =R7.L*R5.H, A0 =R7.H*R5.H (IS) || [TMP1]=R2 || R6.H=W[I2--];
+ A1-=R7.H*R5.L, A0+=R7.L*R5.L (IS) || I0-=4 || R7=[I3++];
+ A1+=R7.H*R6.H, A0+=R7.L*R6.H (IS) || I0+=M1; // R7=(C3,C5)
+ R3 =(A1-=R7.L*R6.L), R2 =(A0+=R7.H*R6.L) (IS);
+ A1 =R7.L*R5.H, A0 =R7.H*R5.H (IS) || R4=[TMP0];
+ A1+=R7.H*R5.L, A0-=R7.L*R5.L (IS) || I1+=M1 || R7=[I3++]; // R7=(C1,C7)
+ A1+=R7.L*R6.H, A0-=R7.H*R6.H (IS);
+ R7 =(A1-=R7.H*R6.L), R6 =(A0-=R7.L*R6.L) (IS) || I2+=M1;
+ // R3=Y1, R2=Y7, R7=Y5, R6=Y3
+
+ /* Transpose write column. */
+ R5.H=R4+R2 (RND12); // Y0=Y0+Y7
+ R5.L=R4-R2 (RND12) || R4 = [TMP1]; // Y7=Y7-Y0
+ R2.H=R1+R7 (RND12) || W[P0++P3]=R5.H; // Y2=Y2+Y5 st Y0
+ R2.L=R1-R7 (RND12) || W[P1++P4]=R5.L || R7=[I3++]; // Y5=Y2-Y5 st Y7
+ R5.H=R0-R3 (RND12) || W[P0++P3]=R2.H || R1.L=W[I1++]; // Y1=Y6-Y1 st Y2
+ R5.L=R0+R3 (RND12) || W[P1++P4]=R2.L || R0.H=W[I0++]; // Y6=Y6+Y1 st Y5
+ R3.H=R4-R6 (RND12) || W[P0++P3]=R5.H || R0.L=W[I2++]; // Y3=Y3-Y4 st Y1
+ R3.L=R4+R6 (RND12) || W[P1++P4]=R5.L || R1.H=W[I0++]; // Y4=Y3+Y4 st Y6
+
+ /* pipeline loop start, + drain Y3, Y4 */
+ A1=R7.H*R0.H, A0=R7.H*R0.H (IS) || W[P0++P2]= R3.H || R1.H = W[I0--];
+.1: R3=(A1+=R7.H*R0.L), R2=(A0-=R7.H*R0.L) (IS) || W[P1++P5]= R3.L || R7 = [I3++];
+
+
+
+ I0 = B2; // I0 points to Input Element (0, 0)
+ I2 = B2; // I2 points to Input Element (0, 0)
+ I2 += M3 || R0.H = W[I0];
+ // Y0 is read in R0.H
+ I1 = I2; // I1 points to input Element (0, 6)
+ I1 += 4 || R0.L = W[I2++];
+ // I2 points to input Element (0, 4)
+ // Y4 is read in R0.L
+ P2 = 8 (X);
+ I3 = B3; // I3 points to Coefficients
+ P0 = B0; // P0 points to array Element (0, 0) for writing
+ // output
+ P1 = B0;
+ R7 = [I3++]; // R7.H = C4 and R7.L = C4
+ NOP;
+
+ /*
+ * A1 = Y0 * cos(pi/4)
+ * A0 = Y0 * cos(pi/4)
+ * A1 = A1 + Y4 * cos(pi/4)
+ * A0 = A0 - Y4 * cos(pi/4)
+ * load:
+ * R1=(Y2,Y6)
+ * R7=(C2,C6)
+ * res:
+ * R3=Y0, R2=Y4
+ */
+ A1=R7.H*R0.H, A0=R7.H*R0.H (IS) || I0+=4 || R1.L=W[I1++];
+ R3=(A1+=R7.H*R0.L), R2=(A0-=R7.H*R0.L) (IS) || R1.H=W[I0--] || R7=[I3++];
+
+ LSETUP (.2, .3) LC0 = P2; // peform 8 1d idcts
+ P2 = 112 (X);
+ P1 = P1 + P2;
+ P2 = -94(X);
+
+.2:
+ /*
+ * A1 = Y2 * cos(3pi/8)
+ * A0 = Y2 * cos(pi/8)
+ * A1 = A1 - Y6 * cos(pi/8)
+ * A0 = A0 + Y6 * cos(3pi/8)
+ * R5 = (Y1,Y7)
+ * R7 = (C1,C7)
+ * res:
+ * R1=Y2, R0=Y6
+ */
+ A1=R7.L*R1.H, A0=R7.H*R1.H (IS) || I0+=4 || R5.H=W[I0];
+ R1=(A1-=R7.H*R1.L), R0=(A0+=R7.L*R1.L) (IS) || R5.L=W[I1--] || R7=[I3++];
+ /*
+ * Y0 = Y0 + Y6.
+ * Y4 = Y4 + Y2.
+ * Y2 = Y4 - Y2.
+ * Y6 = Y0 - Y6.
+ * R3 is saved
+ * R6.l=Y3
+ * note: R3: Y0, R2: Y4, R1: Y2, R0: Y6
+ */
+ R3=R3+R0, R0=R3-R0;
+ R2=R2+R1, R1=R2-R1 || [TMP0]=R3 || R6.L=W[I0--];
+ /*
+ * Compute the odd portion (1,3,5,7) even is done.
+ *
+ * Y1 = C7 * Y1 - C1 * Y7 + C3 * Y5 - C5 * Y3.
+ * Y7 = C1 * Y1 + C7 * Y7 + C5 * Y5 + C3 * Y3.
+ * Y5 = C5 * Y1 + C3 * Y7 + C7 * Y5 - C1 * Y3.
+ * Y3 = C3 * Y1 - C5 * Y7 - C1 * Y5 - C7 * Y3.
+ */
+ // R5=(Y1,Y7) R6=(Y5,Y3) // R7=(C1,C7)
+ A1 =R7.L*R5.H, A0 =R7.H*R5.H (IS) || [TMP1]=R2 || R6.H=W[I2--];
+ A1-=R7.H*R5.L, A0+=R7.L*R5.L (IS) || I0-=4 || R7=[I3++];
+ A1+=R7.H*R6.H, A0+=R7.L*R6.H (IS) || I0+=M1; // R7=(C3,C5)
+ R3 =(A1-=R7.L*R6.L), R2 =(A0+=R7.H*R6.L) (IS);
+ A1 =R7.L*R5.H, A0 =R7.H*R5.H (IS) || R4=[TMP0];
+ A1+=R7.H*R5.L, A0-=R7.L*R5.L (IS) || I1+=M1 || R7=[I3++]; // R7=(C1,C7)
+ A1+=R7.L*R6.H, A0-=R7.H*R6.H (IS);
+ R7 =(A1-=R7.H*R6.L), R6 =(A0-=R7.L*R6.L) (IS) || I2+=M1;
+ // R3=Y1, R2=Y7, R7=Y5, R6=Y3
+
+ /* Transpose write column. */
+ R5.H=R4+R2 (RND20); // Y0=Y0+Y7
+ R5.L=R4-R2 (RND20) || R4 = [TMP1]; // Y7=Y7-Y0
+ R2.H=R1+R7 (RND20) || W[P0++P3]=R5.H; // Y2=Y2+Y5 st Y0
+ R2.L=R1-R7 (RND20) || W[P1++P4]=R5.L || R7=[I3++]; // Y5=Y2-Y5 st Y7
+ R5.H=R0-R3 (RND20) || W[P0++P3]=R2.H || R1.L=W[I1++]; // Y1=Y6-Y1 st Y2
+ R5.L=R0+R3 (RND20) || W[P1++P4]=R2.L || R0.H=W[I0++]; // Y6=Y6+Y1 st Y5
+ R3.H=R4-R6 (RND20) || W[P0++P3]=R5.H || R0.L=W[I2++]; // Y3=Y3-Y4 st Y1
+ R3.L=R4+R6 (RND20) || W[P1++P4]=R5.L || R1.H=W[I0++]; // Y4=Y3+Y4 st Y6
+
+ /* pipeline loop start, + drain Y3, Y4 */
+ A1=R7.H*R0.H, A0=R7.H*R0.H (IS) || W[P0++P2]= R3.H || R1.H = W[I0--];
+.3: R3=(A1+=R7.H*R0.L), R2=(A0-=R7.H*R0.L) (IS) || W[P1++P5]= R3.L || R7 = [I3++];
+
+ L3 = 0;
+ (R7:4,P5:3)=[SP++];
+ unlink;
+ RTS;
+
+
diff --git a/contrib/ffmpeg/libavcodec/bfin/pixels_bfin.S b/contrib/ffmpeg/libavcodec/bfin/pixels_bfin.S
new file mode 100644
index 000000000..2968fcff6
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/bfin/pixels_bfin.S
@@ -0,0 +1,723 @@
+/*
+ * Blackfin Pixel Operations
+ * Copyright (C) 2007 Marc Hoffman <marc.hoffman@analog.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include "config_bfin.h"
+
+DEFUN(put_pixels_clamped,mL1,
+ (DCTELEM *block, uint8_t *dest, int line_size)):
+ [--SP] = (R7:4);
+ R4 = 0;
+ R5.l = 0x00ff;
+ R5.h = 0x00ff;
+ I0 = R0; // block
+ I1 = R1; // dest
+ R2 += -4; // line_size
+ M1 = R2;
+ P0 = 8;
+ R0 = [I0++];
+ R1 = [I0++];
+ R2 = MAX(R0, R4) (V);
+ LSETUP (ppc$0,ppc$1) LC0=P0;
+ppc$0: R2 = MIN(R2, R5) (V);
+ R3 = MAX(R1, R4) (V);
+ R3 = MIN(R3, R5) (V) || R0 = [I0++];
+ R6 = BYTEPACK (R2,R3) || R1 = [I0++];
+ R2 = MAX(R0, R4) (V) || [I1++] = R6;
+ R2 = MIN(R2, R5) (V);
+ R3 = MAX(R1, R4) (V);
+ R3 = MIN(R3, R5) (V) || R0 = [I0++];
+ R6 = BYTEPACK (R2,R3) || R1 = [I0++];
+ppc$1: R2 = Max(R0, R4) (V) || [I1++M1] = R6;
+
+ (R7:4) = [SP++];
+ RTS;
+
+DEFUN(add_pixels_clamped,mL1,
+ (DCTELEM *block, uint8_t *dest, int line_size)):
+ [-- SP] = (R7:4);
+ R4 = 0;
+ I0 = 0;
+ R2 += -4; // line_size
+ M0 = R2;
+ I1 = R1; // dest
+ I3 = R0; // block
+ I2 = R1; // dest
+ P0 = 8;
+ M3 = 2;
+ R0 = [I3++] || R2 = [I1];
+ R2 = R2 << 8 || R0.H = W[I3--] || R3 = [I1++];
+ R3 = R3 >> 8 || R1.L = W[I3] || I3 += 4;
+ R6 = BYTEOP3P(R1:0, R3:2) (LO) || R1.H = W[I3++] || R2 = [I1];
+
+ LSETUP(apc$2,apc$3) LC1 = P0;
+apc$2: R7 = BYTEOP3P(R1:0, R3:2) (HI, R) || R0 = [I3++] || R3 = [I1++M0];
+ R2 = R2 << 8 || R0.H = W[I3--];
+ R3 = R3 >> 8 || R1.L = W[I3] || I3 += 4;
+ R6 = R6 + R7 (S) || R1.H = W[I3];
+ R6 = BYTEOP3P(R1:0, R3:2) (LO) || I3+=M3 || [I2++]=R6;
+ R7 = BYTEOP3P(R1:0, R3:2) (HI, R) || R0 = [I3++] || R2 = [I1];
+ R2 = R2 << 8 || R0.H = W[I3--] || R3 = [I1++];
+ R3 = R3 >> 8 || R1.L = W[I3] || I3 += 4;
+ R6 = R6 + R7 (S) || R1.H = W[I3++];
+apc$3: R6 = BYTEOP3P(R1:0, R3:2) (LO) || [I2++M0] = R6 || R2 = [I1];
+
+ (R7:4) = [SP++];
+ RTS;
+
+
+/*
+ motion compensation
+ primitives
+
+ * Halfpel motion compensation with rounding (a+b+1)>>1.
+ * This is an array[4][4] of motion compensation funcions for 4
+ * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
+ * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
+ * @param block destination where the result is stored
+ * @param pixels source
+ * @param line_size number of bytes in a horizontal line of block
+ * @param h height
+
+*/
+
+DEFUN(put_pixels8uc,mL1,
+ (uint8_t *block, const uint8_t *s0, const uint8_t *s1,
+ int dest_size, int line_size, int h)):
+ i3=r0; // dest
+ i0=r1; // src0
+ i1=r2; // src1
+ r0=[sp+12]; // dest_size
+ r2=[sp+16]; // line_size
+ p0=[sp+20]; // h
+ [--sp] = (r7:6);
+ r0+=-4;
+ m3=r0;
+ r2+=-8;
+ m0=r2;
+ LSETUP(pp8$0,pp8$1) LC0=P0;
+ DISALGNEXCPT || R0 = [I0++] || R2 =[I1++];
+
+pp8$0: DISALGNEXCPT || R1 = [I0++] || R3 =[I1++];
+ R6 = BYTEOP1P(R1:0,R3:2) || R0 = [I0++M0]|| R2 =[I1++M0];
+ R7 = BYTEOP1P(R1:0,R3:2)(R) || R0 = [I0++] || [I3++] = R6 ;
+pp8$1: DISALGNEXCPT || R2 = [I1++] || [I3++M3] = R7;
+
+ (r7:6) = [sp++];
+ RTS;
+
+DEFUN(put_pixels16uc,mL1,
+ (uint8_t *block, const uint8_t *s0, const uint8_t *s1,
+ int dest_size, int line_size, int h)):
+ link 0;
+ [--sp] = (r7:6);
+ i3=r0; // dest
+ i0=r1; // src0
+ i1=r2; // src1
+ r0=[fp+20]; // dest_size
+ r2=[fp+24]; // line_size
+ p0=[fp+28]; // h
+
+
+ r0+=-12;
+ m3=r0; // line_size
+ r2+=-16;
+ m0=r2;
+
+ LSETUP(pp16$0,pp16$1) LC0=P0;
+ DISALGNEXCPT || R0 = [I0++] || R2 =[I1++];
+
+pp16$0: DISALGNEXCPT || R1 = [I0++] || R3 =[I1++];
+ R6 = BYTEOP1P(R1:0,R3:2) || R0 = [I0++] || R2 =[I1++];
+ R7 = BYTEOP1P(R1:0,R3:2)(R) || R1 = [I0++] || R3 =[I1++];
+ [I3++] = R6;
+ R6 = BYTEOP1P(R1:0,R3:2) || R0 = [I0++M0] || R2 =[I1++M0];
+ R7 = BYTEOP1P(R1:0,R3:2)(R) || R0 = [I0++] || [I3++] = R7 ;
+ [I3++] = R6;
+pp16$1: DISALGNEXCPT || R2 = [I1++] || [I3++M3] = R7;
+
+ (r7:6) = [sp++];
+ unlink;
+ RTS;
+
+
+
+
+
+
+DEFUN(put_pixels8uc_nornd,mL1,
+ (uint8_t *block, const uint8_t *s0, const uint8_t *s1,
+ int line_size, int h)):
+ i3=r0; // dest
+ i0=r1; // src0
+ i1=r2; // src1
+ r2=[sp+12]; // line_size
+ p0=[sp+16]; // h
+ [--sp] = (r7:6);
+ r2+=-4;
+ m3=r2;
+ r2+=-4;
+ m0=r2;
+ LSETUP(pp8$2,pp8$3) LC0=P0;
+ DISALGNEXCPT || R0 = [I0++] || R2 =[I1++];
+
+pp8$2: DISALGNEXCPT || R1 = [I0++] || R3 =[I1++];
+ R6 = BYTEOP1P(R1:0,R3:2)(T) || R0 = [I0++M0]|| R2 =[I1++M0];
+ R7 = BYTEOP1P(R1:0,R3:2)(T,R) || R0 = [I0++] || [I3++] = R6 ;
+pp8$3: DISALGNEXCPT || R2 = [I1++] || [I3++M3] = R7;
+
+ (r7:6) = [sp++];
+ RTS;
+
+DEFUN(put_pixels16uc_nornd,mL1,
+ (uint8_t *block, const uint8_t *s0, const uint8_t *s1,
+ int line_size, int h)):
+ i3=r0; // dest
+ i0=r1; // src0
+ i1=r2; // src1
+ r2=[sp+12]; // line_size
+ p0=[sp+16]; // h
+
+ [--sp] = (r7:6);
+ r2+=-12;
+ m3=r2; // line_size
+ r2+=-4;
+ m0=r2;
+
+ LSETUP(pp16$2,pp16$3) LC0=P0;
+ DISALGNEXCPT || R0 = [I0++] || R2 =[I1++];
+
+pp16$2:
+ DISALGNEXCPT || R1 = [I0++] || R3 =[I1++];
+ R6 = BYTEOP1P(R1:0,R3:2)(T) || R0 = [I0++] || R2 =[I1++];
+ R7 = BYTEOP1P(R1:0,R3:2)(T,R) || R1 = [I0++] || R3 =[I1++];
+ [I3++] = R6;
+
+ R6 = BYTEOP1P(R1:0,R3:2)(T) || R0 = [I0++M0] || R2 =[I1++M0];
+ R7 = BYTEOP1P(R1:0,R3:2)(T,R) || R0 = [I0++] || [I3++] = R7 ;
+ [I3++] = R6;
+pp16$3: DISALGNEXCPT || R2 = [I1++] || [I3++M3] = R7;
+
+ (r7:6) = [sp++];
+
+ RTS;
+
+DEFUN(z_put_pixels16_xy2,mL1,
+ (uint8_t *block, const uint8_t *s0,
+ int dest_size, int line_size, int h)):
+ link 0;
+ [--sp] = (r7:4);
+ i3=r0; // dest
+ i0=r1; // src0--> pixels
+ i1=r1; // src1--> pixels + line_size
+ r2+=-12;
+ m2=r2; // m2=dest_width-4
+ r2=[fp+20];
+ m3=r2; // line_size
+ p0=[fp+24]; // h
+ r2+=-16;
+ i1+=m3; /* src1 + line_size */
+ m0=r2; /* line-size - 20 */
+
+ B0 = I0;
+ B1 = I1;
+ B3 = I3;
+
+ DISALGNEXCPT || R0 = [I0++] || R2 =[I1++];
+
+ LSETUP(LS$16E,LE$16E) LC0=P0;
+LS$16E: DISALGNEXCPT || R1 = [I0++] || R3 =[I1++];
+ R4 = BYTEOP2P (R3:2,R1:0) (RNDL) || R0 = [I0++] || R2 =[I1++];
+ R5 = BYTEOP2P (R3:2,R1:0) (RNDL,R) || R1 = [I0++] || [I3++] = R4 ;
+ DISALGNEXCPT || R3 = [I1++] || [I3++] = R5;
+ R4 = BYTEOP2P (R3:2,R1:0) (RNDL) || R0 = [I0++M0]|| R2 = [I1++M0];
+ R5 = BYTEOP2P (R3:2,R1:0) (RNDL,R) || R0 = [I0++] || [I3++] = R4 ;
+LE$16E: DISALGNEXCPT || R2 = [I1++] || [I3++M2] = R5;
+
+ M1 = 1;
+ I3 = B3;
+ I1 = B1;
+ I0 = B0;
+
+ I0 += M1;
+ I1 += M1;
+
+ DISALGNEXCPT || R0 = [I0++] || R2 =[I1++];
+ LSETUP(LS$16O,LE$16O) LC0=P0;
+LS$16O: DISALGNEXCPT || R1 = [I0++] || R3 =[I1++];
+ R4 = BYTEOP2P (R3:2,R1:0) (RNDH) || R0 = [I0++] || R2 =[I1++];
+ R5 = BYTEOP2P (R3:2,R1:0) (RNDH,R) || R1 = [I0++] || R6 =[I3++];
+ R4 = R4 +|+ R6 || R7 = [I3--];
+ R5 = R5 +|+ R7 || [I3++] = R4;
+ DISALGNEXCPT || R3 =[I1++] || [I3++] = R5;
+ R4 = BYTEOP2P (R3:2,R1:0) (RNDH) || R0 = [I0++M0]|| R2 = [I1++M0];
+ R5 = BYTEOP2P (R3:2,R1:0) (RNDH,R) || R0 = [I0++] || R6 = [I3++];
+ R4 = R4 +|+ R6 || R7 = [I3--];
+ R5 = R5 +|+ R7 || [I3++] = R4;
+LE$16O: DISALGNEXCPT || R2 = [I1++] || [I3++M2] = R5;
+
+ (r7:4) = [sp++];
+ unlink;
+ rts;
+
+DEFUN(put_pixels16_xy2_nornd,mL1,
+ (uint8_t *block, const uint8_t *s0,
+ int line_size, int h)):
+ link 0;
+ [--sp] = (r7:4);
+ i3=r0; // dest
+ i0=r1; // src0--> pixels
+ i1=r1; // src1--> pixels + line_size
+ m3=r2;
+ r2+=-12;
+ m2=r2;
+ r2+=-4;
+ i1+=m3; /* src1 + line_size */
+ m0=r2; /* line-size - 20 */
+ p0=[fp+20]; // h
+
+ B0=I0;
+ B1=I1;
+ B3=I3;
+
+ DISALGNEXCPT || R0 = [I0++] || R2 =[I1++];
+
+ LSETUP(LS$16ET,LE$16ET) LC0=P0;
+LS$16ET:DISALGNEXCPT || R1 = [I0++] || R3 =[I1++];
+ R4 = BYTEOP2P (R3:2,R1:0) (TL) || R0 = [I0++] || R2 =[I1++];
+ R5 = BYTEOP2P (R3:2,R1:0) (TL,R) || R1 = [I0++] || [I3++] = R4 ;
+ DISALGNEXCPT || R3 = [I1++] || [I3++] = R5;
+ R4 = BYTEOP2P (R3:2,R1:0) (TL) || R0 = [I0++M0]|| R2 = [I1++M0];
+ R5 = BYTEOP2P (R3:2,R1:0) (TL,R) || R0 = [I0++] || [I3++] = R4 ;
+LE$16ET:DISALGNEXCPT || R2 = [I1++] || [I3++M2] = R5;
+
+ M1 = 1;
+ I3=B3;
+ I1=B1;
+ I0=B0;
+
+ I0 += M1;
+ I1 += M1;
+
+ DISALGNEXCPT || R0 = [I0++] || R2 =[I1++];
+ LSETUP(LS$16OT,LE$16OT) LC0=P0;
+LS$16OT:DISALGNEXCPT || R1 = [I0++] || R3 =[I1++];
+ R4 = BYTEOP2P (R3:2,R1:0) (TH) || R0 = [I0++] || R2 =[I1++];
+ R5 = BYTEOP2P (R3:2,R1:0) (TH,R) || R1 = [I0++] || R6 =[I3++];
+ R4 = R4 +|+ R6 || R7 = [I3--];
+ R5 = R5 +|+ R7 || [I3++] = R4;
+ DISALGNEXCPT || R3 =[I1++] || [I3++] = R5;
+ R4 = BYTEOP2P (R3:2,R1:0) (TH) || R0 = [I0++M0]|| R2 = [I1++M0];
+ R5 = BYTEOP2P (R3:2,R1:0) (TH,R) || R0 = [I0++] || R6 = [I3++];
+ R4 = R4 +|+ R6 || R7 = [I3--];
+ R5 = R5 +|+ R7 || [I3++] = R4;
+LE$16OT:DISALGNEXCPT || R2 = [I1++] || [I3++M2] = R5;
+
+ (r7:4) = [sp++];
+ unlink;
+ rts;
+
+DEFUN(z_put_pixels8_xy2,mL1,
+ (uint8_t *block, const uint8_t *s0,
+ int dest_size, int line_size, int h)):
+ link 0;
+ [--sp] = (r7:4);
+ i3=r0; // dest
+ i0=r1; // src0--> pixels
+ i1=r1; // src1--> pixels + line_size
+ r2+=-4;
+ m2=r2; // m2=dest_width-4
+ r2=[fp+20];
+ m3=r2; // line_size
+ p0=[fp+24]; // h
+ r2+=-8;
+ i1+=m3; /* src1 + line_size */
+ m0=r2; /* line-size - 20 */
+
+ b0 = I0;
+ b1 = I1;
+ b3 = I3;
+
+ LSETUP(LS$8E,LE$8E) LC0=P0;
+ DISALGNEXCPT || R0 = [I0++] || R2 =[I1++];
+LS$8E: DISALGNEXCPT || R1 = [I0++] || R3 =[I1++];
+ R4 = BYTEOP2P (R3:2,R1:0) (RNDL) || R0 = [I0++M0] || R2 =[I1++M0];
+ R5 = BYTEOP2P (R3:2,R1:0) (RNDL,R) || R0 = [I0++] || [I3++] = R4 ;
+LE$8E: DISALGNEXCPT || R2 = [I1++] || [I3++M2] = R5;
+
+ M1 = 1;
+ I3 = b3;
+ I1 = b1;
+ I0 = b0;
+
+ I0 += M1;
+ I1 += M1;
+
+ LSETUP(LS$8O,LE$8O) LC0=P0;
+ DISALGNEXCPT || R0 = [I0++] || R2 =[I1++];
+LS$8O: DISALGNEXCPT || R1 = [I0++] || R3 =[I1++];
+ R4 = BYTEOP2P (R3:2,R1:0) (RNDH) || R0 = [I0++M0] || R2 =[I1++M0];
+ R5 = BYTEOP2P (R3:2,R1:0) (RNDH,R) || R0 = [I0++] || R6 =[I3++];
+ R4 = R4 +|+ R6 || R7 = [I3--];
+ R5 = R5 +|+ R7 || [I3++] = R4;
+LE$8O: DISALGNEXCPT || R2 =[I1++] || [I3++M2] = R5;
+
+ (r7:4) = [sp++];
+ unlink;
+ rts;
+
+DEFUN(put_pixels8_xy2_nornd,mL1,
+ (uint8_t *block, const uint8_t *s0, int line_size, int h)):
+ link 0;
+ [--sp] = (r7:4);
+ i3=r0; // dest
+ i0=r1; // src0--> pixels
+ i1=r1; // src1--> pixels + line_size
+ m3=r2;
+ r2+=-4;
+ m2=r2;
+ r2+=-4;
+ i1+=m3; /* src1 + line_size */
+ m0=r2; /* line-size - 20 */
+ p0=[fp+20]; // h
+
+
+ b0 = I0;
+ b1 = I1;
+ b3 = I3;
+
+ LSETUP(LS$8ET,LE$8ET) LC0=P0;
+ DISALGNEXCPT || R0 = [I0++] || R2 =[I1++];
+
+LS$8ET: DISALGNEXCPT || R1 = [I0++] || R3 = [I1++];
+ R4 = BYTEOP2P (R3:2,R1:0) (TL) || R0 = [I0++M0] || R2 = [I1++M0];
+ R5 = BYTEOP2P (R3:2,R1:0) (TL,R) || R0 = [I0++] || [I3++] = R4 ;
+LE$8ET: DISALGNEXCPT || R2 = [I1++] || [I3++M2] = R5;
+
+ M1 = 1;
+ I3 = b3;
+ I1 = b1;
+ I0 = b0;
+
+ I0 += M1;
+ I1 += M1;
+
+ LSETUP(LS$8OT,LE$8OT) LC0=P0;
+ DISALGNEXCPT || R0 = [I0++] || R2 = [I1++];
+
+LS$8OT: DISALGNEXCPT || R1 = [I0++] || R3 = [I1++];
+ R4 = BYTEOP2P (R3:2,R1:0) (TH) || R0 = [I0++M0] || R2 = [I1++M0];
+ R5 = BYTEOP2P (R3:2,R1:0) (TH,R) || R0 = [I0++] || R6 = [I3++];
+ R4 = R4 +|+ R6 || R7 = [I3--];
+ R5 = R5 +|+ R7 || [I3++] = R4;
+LE$8OT: DISALGNEXCPT || R2 =[I1++] || [I3++M2] = R5;
+
+ (r7:4) = [sp++];
+ unlink;
+ rts;
+
+DEFUN(diff_pixels,mL1,
+ (DCTELEM *block, uint8_t *s1, uint8_t *s2, int stride)):
+ link 0;
+ [--sp] = (r7:4);
+ p0=8;
+ i3=r0; // block
+ i0=r1; // s1
+ i1=r2; // s2
+ r2=[fp+20]; // stride
+ r2+=-8;
+ m0=r2;
+
+
+ LSETUP(.LS0,.LE0) LC0=P0;
+ DISALGNEXCPT || R0 = [I0++] || R2 =[I1++];
+
+.LS0: DISALGNEXCPT || R1 = [I0++] || R3 = [I1++];
+ (R5,R4) = BYTEOP16M (R1:0,R3:2) || R0 = [I0++M0] || R2 = [I1++M0];
+ (R7,R6) = BYTEOP16M (R1:0,R3:2) (R)|| R0 = [I0++] || [I3++] = R4;
+ DISALGNEXCPT || R2 = [I1++] || [I3++] = R5;
+ [i3++]=r6;
+.LE0: [i3++]=r7;
+
+ (r7:4) = [sp++];
+ unlink;
+ rts;
+
+/*
+ for (i = 0; i < 16; i++) {
+ for (j = 0; j < 16; j++) {
+ sum += pix[j];
+ }
+ pix += line_size;
+ }
+*/
+DEFUN(pix_sum,mL1,
+ (uint8_t *p, int stride)):
+ link 0;
+ [--sp] = (r7:4);
+ p0=8;
+ i0=r0; // s1
+ i1=r0;
+ m1=r1;
+ r1=r1+r1;
+ r1+=-16; // stride
+ m0=r1;
+ i1+=m1;
+
+ r6=0;
+
+ LSETUP(LS$PS,LE$PS) LC0=P0;
+ DISALGNEXCPT || R0 = [I0++] || R2 =[I1++];
+
+LS$PS: DISALGNEXCPT || R1 = [I0++] || R3 = [I1++];
+ (R5,R4) = BYTEOP16P (R3:2,R1:0) || R0 = [I0++] || R2 = [I1++];
+ r6=r6+|+r5;
+ r6=r6+|+r4;
+ (R5,R4) = BYTEOP16P (R3:2,R1:0) (R)|| R1 = [I0++] || R3 = [I1++];
+ r6=r6+|+r5;
+ r6=r6+|+r4;
+ (R5,R4) = BYTEOP16P (R3:2,R1:0) || R0 = [I0++m0] || R2 = [I1++m0];
+ r6=r6+|+r5;
+ r6=r6+|+r4;
+ (R5,R4) = BYTEOP16P (R3:2,R1:0) (R)|| R0 = [I0++] || R2 = [I1++];
+ r6=r6+|+r5;
+LE$PS: r6=r6+|+r4;
+ r0.l=r6.l+r6.h;
+ r0.h=0;
+
+ (r7:4) = [sp++];
+ unlink;
+ rts;
+
+
+DEFUN(get_pixels,mL1,
+ (DCTELEM *restrict block, const uint8_t *pixels, int line_size)):
+ [--sp] = (r7:4);
+ i3=r0; // dest
+ i0=r1; // src0
+ p0=8;
+ r2+=-8;
+ m0=r2;
+ LSETUP(gp8$0,gp8$1) LC0=P0;
+
+ DISALGNEXCPT || R0 = [I0++];
+ DISALGNEXCPT || R1 = [I0++];
+
+gp8$0: (R7,R6) = byteunpack R1:0 || R0 = [I0++M0];
+ (R5,R4) = byteunpack R1:0 (R) || R0 = [I0++] || [I3++]=R6;
+ DISALGNEXCPT || R1 = [I0++] || [I3++]=R7;
+ [I3++]=R4;
+gp8$1: [I3++]=R5
+
+
+ (r7:4) = [sp++];
+ RTS;
+
+
+/* sad = sad16x16 (ubyte *mb, ubyte *refwin, srcwidth, refwinwidth, h) */
+/* 91 cycles */
+DEFUN(z_sad16x16,mL1,
+ (uint8_t *blk1, uint8_t *blk2, int dsz, int line_size, int h)):
+ link 0;
+ I0 = R0;
+ I1 = R1;
+
+ A1 = A0 = 0;
+ R0 = [sp+20]; // rwidth
+ P2 = [sp+24]; // height
+ R3 = 16;
+ R0 = R0 - R3;
+ R3 = R2 - R3;
+ M1 = R0;
+ M0 = R3;
+
+ DISALGNEXCPT || R0 = [I0++] || R2 = [I1++];
+ LSETUP (s$16, e$16) LC0=P2;
+s$16: DISALGNEXCPT || R1 = [I0++] || R3 = [I1++];
+ SAA (R1:0,R3:2) || R0 = [I0++] || R2 = [I1++];
+ SAA (R1:0,R3:2) (R) || R1 = [I0++] || R3 = [I1++];
+ SAA (R1:0,R3:2) || R0 = [I0++M0] || R2 = [I1++M1];
+e$16: SAA (R1:0,R3:2) (R) || R0 = [I0++] || R2 = [I1++];
+
+ R3=A1.L+A1.H, R2=A0.L+A0.H ;
+ R0 = R2 + R3 ;
+ unlink;
+ RTS;
+
+/* sad = sad8x8 (ubyte *mb, ubyte *refwin, int srcwidth, int refwinwidth, int h) */
+/* 36 cycles */
+DEFUN(z_sad8x8,mL1,
+ (uint8_t *blk1, uint8_t *blk2, int dsz, int line_size, int h)):
+ I0 = R0;
+ I1 = R1;
+
+ A1 = A0 = 0;
+ r0 = [sp+12]; // rwidth
+ P2 = [sp+16]; //height
+ R3 = 8;
+ R0 = R0 - R3;
+ R3 = R2 - R3;
+ M0 = R3;
+ M1 = R0;
+
+ LSETUP (s$8, e$8) LC0=P2;
+ DISALGNEXCPT || R0 = [I0++] || R2 = [I1++];
+ DISALGNEXCPT || R1 = [I0++] || R3 = [I1++];
+s$8: SAA (R1:0,R3:2) || R0 = [I0++M0] || R2 = [I1++M1];
+ SAA (R1:0,R3:2) (R) || R0 = [I0++] || R2 = [I1++];
+e$8: DISALGNEXCPT || R1 = [I0++] || R3 = [I1++];
+
+ R3=A1.L+A1.H, R2=A0.L+A0.H ;
+ R0 = R2 + R3 ;
+ RTS;
+
+DEFUN(pix_norm1,mL1,
+ (uint8_t * pix, int line_size)):
+ [--SP]=(R7:4,P5:3);
+
+ // Fetch the input arguments.
+ P1 = R0; // pix
+ P0 = R1; // line_size
+ P5 = 16; // loop ctr.
+ P0 -= P5;
+ M0 = P0; // M0 = line_size-16;
+ // Now for the real work.
+ A1 = A0 = 0;
+ lsetup(_pix_norm1_blkfn_loopStart, _pix_norm1_blkfn_loopEnd) LC1 = P5;
+ I0 = P1;
+ DISALGNEXCPT || r0 = [i0++];
+
+_pix_norm1_blkfn_loopStart:
+ // following unpacks pix1[0..15] pix1+line_size[0..15]
+ DISALGNEXCPT || r1 = [i0++];
+
+ (r5, r4) = byteunpack r1:0 || r0 = [i0++];
+ a1 += r5.h * r5.h, a0 += r5.l * r5.l (is);
+ a1 += r4.h * r4.h, a0 += r4.l * r4.l (is);
+ (r5, r4) = byteunpack r1:0(r) || r1 = [i0++];
+ a1 += r5.h * r5.h, a0 += r5.l * r5.l (is);
+ a1 += r4.h * r4.h, a0 += r4.l * r4.l (is);
+ (r5, r4) = byteunpack r1:0 || r0 = [i0++M0];
+ a1 += r5.h * r5.h, a0 += r5.l * r5.l (is);
+ a1 += r4.h * r4.h, a0 += r4.l * r4.l (is);
+ (r5, r4) = byteunpack r1:0(r) || r0 = [i0++];
+ a1 += r5.h * r5.h, a0 += r5.l * r5.l (is);
+_pix_norm1_blkfn_loopEnd:
+ a1 += r4.h * r4.h, a0 += r4.l * r4.l (is);
+
+
+// Clean up at the end:
+ R2 = A0, R3 = A1;
+ R0 = R2 + R3 (S);
+
+ (R7:4,P5:3)=[SP++];
+
+ RTS;
+
+DEFUN(sse4,mL1,
+ (void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)):
+ link 0;
+ [--sp] = (r7:6);
+ p0=[fp+24]; // h
+ i0=r1; // pix1
+ i1=r2; // pix2
+ r2=[fp+20]; // line_size
+ r2+=-4;
+ m0=r2;
+
+ a0=a1=0;
+ LSETUP(.S40,.E40) LC0=P0;
+ DISALGNEXCPT || R0 = [I0++] || R2 =[I1++];
+
+.S40: DISALGNEXCPT || R1 = [I0++M0] || R3 = [I1++M0];
+ (R7,R6) = BYTEOP16M (R1:0,R3:2);
+ a0 += r7.l * r7.l, a1 += r7.h * r7.h (is);
+.E40: a0 += r6.l * r6.l, a1 += r6.h * r6.h (is);
+ a0 += a1;
+ r0 = a0;
+
+ (r7:6) = [sp++];
+ unlink;
+ rts;
+
+DEFUN(sse8,mL1,
+ (void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)):
+ link 0;
+ [--sp] = (r7:6);
+ p0=[fp+24]; // h
+ i0=r1; // pix1
+ i1=r2; // pix2
+ r2=[fp+20]; // line_size
+ r2+=-8;
+ m0=r2;
+
+ a0=a1=0;
+ LSETUP(.S80,.E80) LC0=P0;
+ DISALGNEXCPT || R0 = [I0++] || R2 =[I1++];
+
+.S80: DISALGNEXCPT || R1 = [I0++] || R3 = [I1++];
+ (R7,R6) = BYTEOP16M (R1:0,R3:2) || R0 = [I0++M0] || R2 = [I1++M0];
+ a0 += r7.l * r7.l, a1 += r7.h * r7.h (is);
+ a0 += r6.l * r6.l, a1 += r6.h * r6.h (is);
+ (R7,R6) = BYTEOP16M (R1:0,R3:2) (R)|| R0 = [I0++] || R2 = [I1++];
+ a0 += r7.l * r7.l, a1 += r7.h * r7.h (is);
+.E80: a0 += r6.l * r6.l, a1 += r6.h * r6.h (is);
+ a0 += a1;
+ r0 = a0;
+
+ (r7:6) = [sp++];
+ unlink;
+ rts;
+
+DEFUN(sse16,mL1,
+ (void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)):
+ link 0;
+ [--sp] = (r7:6);
+ p0=[fp+24]; // h
+ i0=r1; // pix1
+ i1=r2; // pix2
+ r2=[fp+20]; // line_size
+ r2+=-16;
+ m0=r2;
+
+ a0=a1=0;
+ DISALGNEXCPT || R0 = [I0++] || R2 =[I1++];
+ LSETUP(.S160,.E160) LC0=P0;
+
+.S160: DISALGNEXCPT || R1 = [I0++] || R3 = [I1++];
+ (R7,R6) = BYTEOP16M (R1:0,R3:2) || R0 = [I0++] || R2 = [I1++];
+ a0 += r7.l * r7.l, a1 += r7.h * r7.h (is);
+ a0 += r6.l * r6.l, a1 += r6.h * r6.h (is);
+ (R7,R6) = BYTEOP16M (R1:0,R3:2) (R)|| R1 = [I0++] || R3 = [I1++];
+ a0 += r7.l * r7.l, a1 += r7.h * r7.h (is);
+ a0 += r6.l * r6.l, a1 += r6.h * r6.h (is);
+ (R7,R6) = BYTEOP16M (R1:0,R3:2) || R0 = [I0++M0] || R2 = [I1++M0];
+ a0 += r7.l * r7.l, a1 += r7.h * r7.h (is);
+ a0 += r6.l * r6.l, a1 += r6.h * r6.h (is);
+ (R7,R6) = BYTEOP16M (R1:0,R3:2) (R)|| R0 = [I0++] || R2 = [I1++];
+ a0 += r7.l * r7.l, a1 += r7.h * r7.h (is);
+.E160: a0 += r6.l * r6.l, a1 += r6.h * r6.h (is);
+ a0 += a1;
+ r0 = a0;
+
+ (r7:6) = [sp++];
+ unlink;
+ rts;
+
+
diff --git a/contrib/ffmpeg/libavcodec/bitstream.c b/contrib/ffmpeg/libavcodec/bitstream.c
new file mode 100644
index 000000000..a0c239798
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/bitstream.c
@@ -0,0 +1,263 @@
+/*
+ * Common bit i/o utils
+ * Copyright (c) 2000, 2001 Fabrice Bellard.
+ * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * alternative bitstream reader & writer by Michael Niedermayer <michaelni@gmx.at>
+ */
+
+/**
+ * @file bitstream.c
+ * bitstream api.
+ */
+
+#include "avcodec.h"
+#include "bitstream.h"
+
+/**
+ * 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.
+ */
+attribute_deprecated void *ff_realloc_static(void *ptr, unsigned int size);
+
+void align_put_bits(PutBitContext *s)
+{
+#ifdef ALT_BITSTREAM_WRITER
+ put_bits(s,( - s->index) & 7,0);
+#else
+ put_bits(s,s->bit_left & 7,0);
+#endif
+}
+
+void ff_put_string(PutBitContext * pbc, char *s, int put_zero)
+{
+ while(*s){
+ put_bits(pbc, 8, *s);
+ s++;
+ }
+ if(put_zero)
+ put_bits(pbc, 8, 0);
+}
+
+/* VLC decoding */
+
+//#define DEBUG_VLC
+
+#define GET_DATA(v, table, i, wrap, size) \
+{\
+ const uint8_t *ptr = (const uint8_t *)table + i * wrap;\
+ switch(size) {\
+ case 1:\
+ v = *(const uint8_t *)ptr;\
+ break;\
+ case 2:\
+ v = *(const uint16_t *)ptr;\
+ break;\
+ default:\
+ v = *(const uint32_t *)ptr;\
+ break;\
+ }\
+}
+
+
+static int alloc_table(VLC *vlc, int size, int use_static)
+{
+ int index;
+ index = vlc->table_size;
+ vlc->table_size += size;
+ if (vlc->table_size > vlc->table_allocated) {
+ 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);
+ 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,
+ uint32_t code_prefix, int n_prefix, int flags)
+{
+ int i, j, k, n, table_size, table_index, nb, n1, index, code_prefix2;
+ 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);
+#ifdef DEBUG_VLC
+ printf("new table index=%d size=%d code_prefix=%x n=%d\n",
+ table_index, table_size, code_prefix, n_prefix);
+#endif
+ if (table_index < 0)
+ return -1;
+ table = &vlc->table[table_index];
+
+ for(i=0;i<table_size;i++) {
+ table[i][1] = 0; //bits
+ table[i][0] = -1; //codes
+ }
+
+ /* first pass: map codes and compute auxillary table sizes */
+ for(i=0;i<nb_codes;i++) {
+ GET_DATA(n, bits, i, bits_wrap, bits_size);
+ GET_DATA(code, codes, i, codes_wrap, codes_size);
+ /* we accept tables with holes */
+ if (n <= 0)
+ continue;
+#if defined(DEBUG_VLC) && 0
+ printf("i=%d n=%d code=0x%x\n", i, n, code);
+#endif
+ /* if code matches the prefix, it is in the table */
+ n -= n_prefix;
+ if(flags & INIT_VLC_LE)
+ code_prefix2= code & (n_prefix>=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<nb;k++) {
+ if(flags & INIT_VLC_LE)
+ j = (code >> n_prefix) + (k<<n);
+#ifdef DEBUG_VLC
+ 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] = i; //code
+ j++;
+ }
+ } else {
+ n -= table_nb_bits;
+ j = (code >> ((flags & INIT_VLC_LE) ? n_prefix : n)) & ((1 << table_nb_bits) - 1);
+#ifdef DEBUG_VLC
+ printf("%4x: n=%d (subtable)\n",
+ j, n);
+#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_size;i++) {
+ n = table[i][1]; //bits
+ if (n < 0) {
+ n = -n;
+ if (n > 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,
+ (flags & INIT_VLC_LE) ? (code_prefix | (i << n_prefix)) : ((code_prefix << table_nb_bits) | i),
+ n_prefix + table_nb_bits, flags);
+ if (index < 0)
+ return -1;
+ /* note: realloc has been done, so reload tables */
+ table = &vlc->table[table_index];
+ table[i][0] = index; //code
+ }
+ }
+ return table_index;
+}
+
+
+/* Build VLC decoding tables suitable for use with get_vlc().
+
+ 'nb_bits' set thee decoding table size (2^nb_bits) entries. The
+ bigger it is, the faster is the decoding. But it should not be too
+ big to save memory and L1 cache. '9' is a good compromise.
+
+ 'nb_codes' : number of vlcs codes
+
+ 'bits' : table which gives the size (in bits) of each vlc code.
+
+ 'codes' : table which gives the bit pattern of of each vlc code.
+
+ 'xxx_wrap' : give the number of bytes between each entry of the
+ 'bits' or 'codes' tables.
+
+ 'xxx_size' : gives the number of bytes of each entry of the 'bits'
+ or 'codes' tables.
+
+ 'wrap' and 'size' allows to use any memory configuration and types
+ (byte/word/long) to store the 'bits' and 'codes' tables.
+
+ 'use_static' should be set to 1 for tables, which should be freed
+ with av_free_static(), 0 if free_vlc() will be used.
+*/
+int init_vlc(VLC *vlc, int nb_bits, int nb_codes,
+ const void *bits, int bits_wrap, int bits_size,
+ const void *codes, int codes_wrap, int codes_size,
+ int flags)
+{
+ vlc->bits = nb_bits;
+ if(!(flags & INIT_VLC_USE_STATIC)) {
+ 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
+ printf("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,
+ 0, 0, flags) < 0) {
+ av_free(vlc->table);
+ return -1;
+ }
+ return 0;
+}
+
+
+void free_vlc(VLC *vlc)
+{
+ av_free(vlc->table);
+}
+
diff --git a/contrib/ffmpeg/libavcodec/bitstream.h b/contrib/ffmpeg/libavcodec/bitstream.h
new file mode 100644
index 000000000..18842702c
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/bitstream.h
@@ -0,0 +1,956 @@
+/*
+ * copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file bitstream.h
+ * bitstream api header.
+ */
+
+#ifndef BITSTREAM_H
+#define BITSTREAM_H
+
+#include "log.h"
+
+#if defined(ALT_BITSTREAM_READER_LE) && !defined(ALT_BITSTREAM_READER)
+#define ALT_BITSTREAM_READER
+#endif
+
+//#define ALT_BITSTREAM_WRITER
+//#define ALIGNED_BITSTREAM_WRITER
+#if !defined(LIBMPEG2_BITSTREAM_READER) && !defined(A32_BITSTREAM_READER) && !defined(ALT_BITSTREAM_READER)
+# ifdef ARCH_ARMV4L
+# define A32_BITSTREAM_READER
+# else
+#define ALT_BITSTREAM_READER
+//#define LIBMPEG2_BITSTREAM_READER
+//#define A32_BITSTREAM_READER
+# endif
+#endif
+#define LIBMPEG2_BITSTREAM_READER_HACK //add BERO
+
+extern const uint8_t ff_reverse[256];
+
+#if defined(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 output */
+
+/* buf and buf_end must be present and used by every alternative writer. */
+typedef struct PutBitContext {
+#ifdef ALT_BITSTREAM_WRITER
+ uint8_t *buf, *buf_end;
+ int index;
+#else
+ uint32_t bit_buf;
+ int bit_left;
+ uint8_t *buf, *buf_ptr, *buf_end;
+#endif
+} PutBitContext;
+
+static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
+{
+ if(buffer_size < 0) {
+ buffer_size = 0;
+ buffer = NULL;
+ }
+
+ s->buf = buffer;
+ s->buf_end = s->buf + buffer_size;
+#ifdef ALT_BITSTREAM_WRITER
+ s->index=0;
+ ((uint32_t*)(s->buf))[0]=0;
+// memset(buffer, 0, buffer_size);
+#else
+ s->buf_ptr = s->buf;
+ s->bit_left=32;
+ s->bit_buf=0;
+#endif
+}
+
+/* return the number of bits output */
+static inline int put_bits_count(PutBitContext *s)
+{
+#ifdef ALT_BITSTREAM_WRITER
+ return s->index;
+#else
+ return (s->buf_ptr - s->buf) * 8 + 32 - s->bit_left;
+#endif
+}
+
+/* pad the end of the output stream with zeros */
+static inline void flush_put_bits(PutBitContext *s)
+{
+#ifdef ALT_BITSTREAM_WRITER
+ align_put_bits(s);
+#else
+ s->bit_buf<<= s->bit_left;
+ while (s->bit_left < 32) {
+ /* XXX: should test end of buffer */
+ *s->buf_ptr++=s->bit_buf >> 24;
+ s->bit_buf<<=8;
+ s->bit_left+=8;
+ }
+ s->bit_left=32;
+ s->bit_buf=0;
+#endif
+}
+
+void align_put_bits(PutBitContext *s);
+void ff_put_string(PutBitContext * pbc, char *s, int put_zero);
+
+/* bit input */
+/* buffer, buffer_end and size_in_bits must be present and used by every reader */
+typedef struct GetBitContext {
+ const uint8_t *buffer, *buffer_end;
+#ifdef ALT_BITSTREAM_READER
+ int index;
+#elif defined LIBMPEG2_BITSTREAM_READER
+ uint8_t *buffer_ptr;
+ uint32_t cache;
+ int bit_count;
+#elif defined A32_BITSTREAM_READER
+ uint32_t *buffer_ptr;
+ uint32_t cache0;
+ uint32_t cache1;
+ int bit_count;
+#endif
+ int size_in_bits;
+} GetBitContext;
+
+#define VLC_TYPE int16_t
+
+typedef struct VLC {
+ int bits;
+ VLC_TYPE (*table)[2]; ///< code, bits
+ int table_size, table_allocated;
+} VLC;
+
+typedef struct RL_VLC_ELEM {
+ int16_t level;
+ int8_t len;
+ uint8_t run;
+} RL_VLC_ELEM;
+
+#if defined(ARCH_SPARC) || defined(ARCH_ARMV4L) || defined(ARCH_MIPS)
+#define UNALIGNED_STORES_ARE_BAD
+#endif
+
+/* used to avoid missaligned exceptions on some archs (alpha, ...) */
+#if defined(ARCH_X86)
+# define unaligned16(a) (*(const uint16_t*)(a))
+# define unaligned32(a) (*(const uint32_t*)(a))
+# define unaligned64(a) (*(const uint64_t*)(a))
+#else
+# ifdef __GNUC__
+# define unaligned(x) \
+static inline uint##x##_t unaligned##x(const void *v) { \
+ struct Unaligned { \
+ uint##x##_t i; \
+ } __attribute__((packed)); \
+ \
+ return ((const struct Unaligned *) v)->i; \
+}
+# elif defined(__DECC)
+# define unaligned(x) \
+static inline uint##x##_t unaligned##x(const void *v) { \
+ return *(const __unaligned uint##x##_t *) v; \
+}
+# else
+# define unaligned(x) \
+static inline uint##x##_t unaligned##x(const void *v) { \
+ return *(const uint##x##_t *) v; \
+}
+# endif
+unaligned(16)
+unaligned(32)
+unaligned(64)
+#undef unaligned
+#endif /* defined(ARCH_X86) */
+
+#ifndef ALT_BITSTREAM_WRITER
+static inline void put_bits(PutBitContext *s, int n, unsigned int value)
+{
+ unsigned int bit_buf;
+ int bit_left;
+
+ // printf("put_bits=%d %x\n", n, value);
+ assert(n == 32 || value < (1U << n));
+
+ bit_buf = s->bit_buf;
+ bit_left = s->bit_left;
+
+ // printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf);
+ /* XXX: optimize */
+ if (n < bit_left) {
+ bit_buf = (bit_buf<<n) | value;
+ bit_left-=n;
+ } else {
+ bit_buf<<=bit_left;
+ bit_buf |= value >> (n - bit_left);
+#ifdef UNALIGNED_STORES_ARE_BAD
+ if (3 & (intptr_t) s->buf_ptr) {
+ s->buf_ptr[0] = bit_buf >> 24;
+ s->buf_ptr[1] = bit_buf >> 16;
+ s->buf_ptr[2] = bit_buf >> 8;
+ s->buf_ptr[3] = bit_buf ;
+ } else
+#endif
+ *(uint32_t *)s->buf_ptr = be2me_32(bit_buf);
+ //printf("bitbuf = %08x\n", bit_buf);
+ s->buf_ptr+=4;
+ bit_left+=32 - n;
+ bit_buf = value;
+ }
+
+ s->bit_buf = bit_buf;
+ s->bit_left = bit_left;
+}
+#endif
+
+
+#ifdef ALT_BITSTREAM_WRITER
+static inline void put_bits(PutBitContext *s, int n, unsigned int value)
+{
+# ifdef ALIGNED_BITSTREAM_WRITER
+# if defined(ARCH_X86)
+ asm volatile(
+ "movl %0, %%ecx \n\t"
+ "xorl %%eax, %%eax \n\t"
+ "shrdl %%cl, %1, %%eax \n\t"
+ "shrl %%cl, %1 \n\t"
+ "movl %0, %%ecx \n\t"
+ "shrl $3, %%ecx \n\t"
+ "andl $0xFFFFFFFC, %%ecx \n\t"
+ "bswapl %1 \n\t"
+ "orl %1, (%2, %%ecx) \n\t"
+ "bswapl %%eax \n\t"
+ "addl %3, %0 \n\t"
+ "movl %%eax, 4(%2, %%ecx) \n\t"
+ : "=&r" (s->index), "=&r" (value)
+ : "r" (s->buf), "r" (n), "0" (s->index), "1" (value<<(-n))
+ : "%eax", "%ecx"
+ );
+# else
+ int index= s->index;
+ uint32_t *ptr= ((uint32_t *)s->buf)+(index>>5);
+
+ value<<= 32-n;
+
+ ptr[0] |= be2me_32(value>>(index&31));
+ ptr[1] = be2me_32(value<<(32-(index&31)));
+//if(n>24) printf("%d %d\n", n, value);
+ index+= n;
+ s->index= index;
+# endif
+# else //ALIGNED_BITSTREAM_WRITER
+# if defined(ARCH_X86)
+ asm volatile(
+ "movl $7, %%ecx \n\t"
+ "andl %0, %%ecx \n\t"
+ "addl %3, %%ecx \n\t"
+ "negl %%ecx \n\t"
+ "shll %%cl, %1 \n\t"
+ "bswapl %1 \n\t"
+ "movl %0, %%ecx \n\t"
+ "shrl $3, %%ecx \n\t"
+ "orl %1, (%%ecx, %2) \n\t"
+ "addl %3, %0 \n\t"
+ "movl $0, 4(%%ecx, %2) \n\t"
+ : "=&r" (s->index), "=&r" (value)
+ : "r" (s->buf), "r" (n), "0" (s->index), "1" (value)
+ : "%ecx"
+ );
+# else
+ int index= s->index;
+ uint32_t *ptr= (uint32_t*)(((uint8_t *)s->buf)+(index>>3));
+
+ ptr[0] |= be2me_32(value<<(32-n-(index&7) ));
+ ptr[1] = 0;
+//if(n>24) printf("%d %d\n", n, value);
+ index+= n;
+ s->index= index;
+# endif
+# endif //!ALIGNED_BITSTREAM_WRITER
+}
+#endif
+
+
+static inline uint8_t* pbBufPtr(PutBitContext *s)
+{
+#ifdef ALT_BITSTREAM_WRITER
+ return s->buf + (s->index>>3);
+#else
+ return s->buf_ptr;
+#endif
+}
+
+/**
+ *
+ * PutBitContext must be flushed & aligned to a byte boundary before calling this.
+ */
+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
+ s->index += n<<3;
+#else
+ assert(s->bit_left==32);
+ s->buf_ptr += n;
+#endif
+}
+
+/**
+ * skips the given number of bits.
+ * must only be used if the actual values in the bitstream dont matter
+ */
+static inline void skip_put_bits(PutBitContext *s, int n){
+#ifdef ALT_BITSTREAM_WRITER
+ s->index += n;
+#else
+ s->bit_left -= n;
+ s->buf_ptr-= s->bit_left>>5;
+ s->bit_left &= 31;
+#endif
+}
+
+/**
+ * Changes the end of the buffer.
+ */
+static inline void set_put_bits_buffer_size(PutBitContext *s, int size){
+ s->buf_end= s->buf + size;
+}
+
+/* Bitstream reader API docs:
+name
+ abritary name which is used as prefix for the internal variables
+
+gb
+ getbitcontext
+
+OPEN_READER(name, gb)
+ loads gb into local variables
+
+CLOSE_READER(name, gb)
+ stores local vars in gb
+
+UPDATE_CACHE(name, gb)
+ refills the internal cache from the bitstream
+ after this call at least MIN_CACHE_BITS will be available,
+
+GET_CACHE(name, gb)
+ will output the contents of the internal cache, next bit is MSB of 32 or 64 bit (FIXME 64bit)
+
+SHOW_UBITS(name, gb, num)
+ will return the next num bits
+
+SHOW_SBITS(name, gb, num)
+ will return the next num bits and do sign extension
+
+SKIP_BITS(name, gb, num)
+ will skip over the next num bits
+ note, this is equivalent to SKIP_CACHE; SKIP_COUNTER
+
+SKIP_CACHE(name, gb, num)
+ will remove the next num bits from the cache (note SKIP_COUNTER MUST be called before UPDATE_CACHE / CLOSE_READER)
+
+SKIP_COUNTER(name, gb, num)
+ will increment the internal bit counter (see SKIP_CACHE & SKIP_BITS)
+
+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
+
+for examples see get_bits, show_bits, skip_bits, get_vlc
+*/
+
+static inline int unaligned32_be(const void *v)
+{
+#ifdef CONFIG_ALIGN
+ const uint8_t *p=v;
+ return (((p[0]<<8) | p[1])<<16) | (p[2]<<8) | (p[3]);
+#else
+ return be2me_32( unaligned32(v)); //original
+#endif
+}
+
+static inline int unaligned32_le(const void *v)
+{
+#ifdef CONFIG_ALIGN
+ const uint8_t *p=v;
+ return (((p[3]<<8) | p[2])<<16) | (p[1]<<8) | (p[0]);
+#else
+ return le2me_32( unaligned32(v)); //original
+#endif
+}
+
+#ifdef ALT_BITSTREAM_READER
+# define MIN_CACHE_BITS 25
+
+# define OPEN_READER(name, gb)\
+ int name##_index= (gb)->index;\
+ int name##_cache= 0;\
+
+# define CLOSE_READER(name, gb)\
+ (gb)->index= name##_index;\
+
+# ifdef ALT_BITSTREAM_READER_LE
+# define UPDATE_CACHE(name, gb)\
+ name##_cache= unaligned32_le( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) >> (name##_index&0x07);\
+
+# define SKIP_CACHE(name, gb, num)\
+ name##_cache >>= (num);
+# else
+# define UPDATE_CACHE(name, gb)\
+ name##_cache= unaligned32_be( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) << (name##_index&0x07);\
+
+# define SKIP_CACHE(name, gb, num)\
+ name##_cache <<= (num);
+# endif
+
+// FIXME name?
+# define SKIP_COUNTER(name, gb, num)\
+ name##_index += (num);\
+
+# define SKIP_BITS(name, gb, num)\
+ {\
+ SKIP_CACHE(name, gb, num)\
+ SKIP_COUNTER(name, gb, num)\
+ }\
+
+# define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num)
+# define LAST_SKIP_CACHE(name, gb, num) ;
+
+# ifdef ALT_BITSTREAM_READER_LE
+# define SHOW_UBITS(name, gb, num)\
+ ((name##_cache) & (NEG_USR32(0xffffffff,num)))
+
+# define SHOW_SBITS(name, gb, num)\
+ NEG_SSR32((name##_cache)<<(32-(num)), num)
+# else
+# define SHOW_UBITS(name, gb, num)\
+ NEG_USR32(name##_cache, num)
+
+# define SHOW_SBITS(name, gb, num)\
+ NEG_SSR32(name##_cache, num)
+# endif
+
+# define GET_CACHE(name, gb)\
+ ((uint32_t)name##_cache)
+
+static inline int get_bits_count(GetBitContext *s){
+ return s->index;
+}
+
+static inline void skip_bits_long(GetBitContext *s, int n){
+ s->index += n;
+}
+
+#elif defined LIBMPEG2_BITSTREAM_READER
+//libmpeg2 like reader
+
+# define MIN_CACHE_BITS 17
+
+# define OPEN_READER(name, gb)\
+ int name##_bit_count=(gb)->bit_count;\
+ int name##_cache= (gb)->cache;\
+ uint8_t * name##_buffer_ptr=(gb)->buffer_ptr;\
+
+# define CLOSE_READER(name, gb)\
+ (gb)->bit_count= name##_bit_count;\
+ (gb)->cache= name##_cache;\
+ (gb)->buffer_ptr= name##_buffer_ptr;\
+
+#ifdef LIBMPEG2_BITSTREAM_READER_HACK
+
+# define UPDATE_CACHE(name, gb)\
+ if(name##_bit_count >= 0){\
+ name##_cache+= (int)be2me_16(*(uint16_t*)name##_buffer_ptr) << name##_bit_count;\
+ name##_buffer_ptr += 2;\
+ name##_bit_count-= 16;\
+ }\
+
+#else
+
+# define UPDATE_CACHE(name, gb)\
+ if(name##_bit_count >= 0){\
+ name##_cache+= ((name##_buffer_ptr[0]<<8) + name##_buffer_ptr[1]) << name##_bit_count;\
+ name##_buffer_ptr+=2;\
+ name##_bit_count-= 16;\
+ }\
+
+#endif
+
+# define SKIP_CACHE(name, gb, num)\
+ name##_cache <<= (num);\
+
+# define SKIP_COUNTER(name, gb, num)\
+ name##_bit_count += (num);\
+
+# define SKIP_BITS(name, gb, num)\
+ {\
+ SKIP_CACHE(name, gb, num)\
+ SKIP_COUNTER(name, gb, num)\
+ }\
+
+# define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num)
+# define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num)
+
+# define SHOW_UBITS(name, gb, num)\
+ NEG_USR32(name##_cache, num)
+
+# define SHOW_SBITS(name, gb, num)\
+ NEG_SSR32(name##_cache, num)
+
+# define GET_CACHE(name, gb)\
+ ((uint32_t)name##_cache)
+
+static inline int get_bits_count(GetBitContext *s){
+ return (s->buffer_ptr - s->buffer)*8 - 16 + s->bit_count;
+}
+
+static inline void skip_bits_long(GetBitContext *s, int n){
+ OPEN_READER(re, s)
+ re_bit_count += n;
+ re_buffer_ptr += 2*(re_bit_count>>4);
+ re_bit_count &= 15;
+ re_cache = ((re_buffer_ptr[-2]<<8) + re_buffer_ptr[-1]) << (16+re_bit_count);
+ UPDATE_CACHE(re, s)
+ CLOSE_READER(re, s)
+}
+
+#elif defined A32_BITSTREAM_READER
+
+# define MIN_CACHE_BITS 32
+
+# define OPEN_READER(name, gb)\
+ int name##_bit_count=(gb)->bit_count;\
+ uint32_t name##_cache0= (gb)->cache0;\
+ uint32_t name##_cache1= (gb)->cache1;\
+ uint32_t * name##_buffer_ptr=(gb)->buffer_ptr;\
+
+# define CLOSE_READER(name, gb)\
+ (gb)->bit_count= name##_bit_count;\
+ (gb)->cache0= name##_cache0;\
+ (gb)->cache1= name##_cache1;\
+ (gb)->buffer_ptr= name##_buffer_ptr;\
+
+# define UPDATE_CACHE(name, gb)\
+ if(name##_bit_count > 0){\
+ const uint32_t next= be2me_32( *name##_buffer_ptr );\
+ name##_cache0 |= NEG_USR32(next,name##_bit_count);\
+ name##_cache1 |= next<<name##_bit_count;\
+ name##_buffer_ptr++;\
+ name##_bit_count-= 32;\
+ }\
+
+#if defined(ARCH_X86)
+# define SKIP_CACHE(name, gb, num)\
+ asm(\
+ "shldl %2, %1, %0 \n\t"\
+ "shll %2, %1 \n\t"\
+ : "+r" (name##_cache0), "+r" (name##_cache1)\
+ : "Ic" ((uint8_t)(num))\
+ );
+#else
+# define SKIP_CACHE(name, gb, num)\
+ name##_cache0 <<= (num);\
+ name##_cache0 |= NEG_USR32(name##_cache1,num);\
+ name##_cache1 <<= (num);
+#endif
+
+# define SKIP_COUNTER(name, gb, num)\
+ name##_bit_count += (num);\
+
+# define SKIP_BITS(name, gb, num)\
+ {\
+ SKIP_CACHE(name, gb, num)\
+ SKIP_COUNTER(name, gb, num)\
+ }\
+
+# define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num)
+# define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num)
+
+# define SHOW_UBITS(name, gb, num)\
+ NEG_USR32(name##_cache0, num)
+
+# define SHOW_SBITS(name, gb, num)\
+ NEG_SSR32(name##_cache0, num)
+
+# define GET_CACHE(name, gb)\
+ (name##_cache0)
+
+static inline int get_bits_count(GetBitContext *s){
+ return ((uint8_t*)s->buffer_ptr - s->buffer)*8 - 32 + s->bit_count;
+}
+
+static inline void skip_bits_long(GetBitContext *s, int n){
+ OPEN_READER(re, s)
+ re_bit_count += n;
+ re_buffer_ptr += re_bit_count>>5;
+ re_bit_count &= 31;
+ re_cache0 = be2me_32( re_buffer_ptr[-1] ) << re_bit_count;
+ re_cache1 = 0;
+ UPDATE_CACHE(re, s)
+ CLOSE_READER(re, s)
+}
+
+#endif
+
+/**
+ * read mpeg1 dc style vlc (sign bit + mantisse with no MSB).
+ * if MSB not set it is negative
+ * @param n length in bits
+ * @author BERO
+ */
+static inline int get_xbits(GetBitContext *s, int n){
+ register int sign;
+ register int32_t cache;
+ OPEN_READER(re, s)
+ UPDATE_CACHE(re, s)
+ cache = GET_CACHE(re,s);
+ sign=(~cache)>>31;
+ LAST_SKIP_BITS(re, s, n)
+ CLOSE_READER(re, s)
+ return (NEG_USR32(sign ^ cache, n) ^ sign) - sign;
+}
+
+static inline int get_sbits(GetBitContext *s, int n){
+ register int tmp;
+ OPEN_READER(re, s)
+ UPDATE_CACHE(re, s)
+ tmp= SHOW_SBITS(re, s, n);
+ LAST_SKIP_BITS(re, s, n)
+ CLOSE_READER(re, s)
+ return tmp;
+}
+
+/**
+ * reads 1-17 bits.
+ * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't
+ */
+static inline unsigned int get_bits(GetBitContext *s, int n){
+ register int tmp;
+ OPEN_READER(re, s)
+ UPDATE_CACHE(re, s)
+ tmp= SHOW_UBITS(re, s, n);
+ LAST_SKIP_BITS(re, s, n)
+ CLOSE_READER(re, s)
+ return tmp;
+}
+
+/**
+ * shows 1-17 bits.
+ * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't
+ */
+static inline unsigned int show_bits(GetBitContext *s, int n){
+ register int tmp;
+ OPEN_READER(re, s)
+ UPDATE_CACHE(re, s)
+ tmp= SHOW_UBITS(re, s, n);
+// CLOSE_READER(re, s)
+ return tmp;
+}
+
+static inline void skip_bits(GetBitContext *s, int n){
+ //Note gcc seems to optimize this to s->index+=n for the ALT_READER :))
+ OPEN_READER(re, s)
+ UPDATE_CACHE(re, s)
+ LAST_SKIP_BITS(re, s, n)
+ CLOSE_READER(re, s)
+}
+
+static inline unsigned int get_bits1(GetBitContext *s){
+#ifdef ALT_BITSTREAM_READER
+ int index= s->index;
+ uint8_t result= s->buffer[ index>>3 ];
+#ifdef ALT_BITSTREAM_READER_LE
+ result>>= (index&0x07);
+ result&= 1;
+#else
+ result<<= (index&0x07);
+ result>>= 8 - 1;
+#endif
+ index++;
+ s->index= index;
+
+ return result;
+#else
+ return get_bits(s, 1);
+#endif
+}
+
+static inline unsigned int show_bits1(GetBitContext *s){
+ return show_bits(s, 1);
+}
+
+static inline void skip_bits1(GetBitContext *s){
+ skip_bits(s, 1);
+}
+
+/**
+ * reads 0-32 bits.
+ */
+static inline unsigned int get_bits_long(GetBitContext *s, int n){
+ if(n<=17) return get_bits(s, n);
+ else{
+#ifdef ALT_BITSTREAM_READER_LE
+ int ret= get_bits(s, 16);
+ return ret | (get_bits(s, n-16) << 16);
+#else
+ int ret= get_bits(s, 16) << (n-16);
+ return ret | get_bits(s, n-16);
+#endif
+ }
+}
+
+/**
+ * shows 0-32 bits.
+ */
+static inline unsigned int show_bits_long(GetBitContext *s, int n){
+ if(n<=17) return show_bits(s, n);
+ else{
+ GetBitContext gb= *s;
+ int ret= get_bits_long(s, n);
+ *s= gb;
+ return ret;
+ }
+}
+
+static inline int check_marker(GetBitContext *s, const char *msg)
+{
+ int bit= get_bits1(s);
+ if(!bit)
+ av_log(NULL, AV_LOG_INFO, "Marker bit missing %s\n", msg);
+
+ return bit;
+}
+
+/**
+ * init GetBitContext.
+ * @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
+ */
+static inline void init_get_bits(GetBitContext *s,
+ const uint8_t *buffer, int bit_size)
+{
+ int buffer_size= (bit_size+7)>>3;
+ if(buffer_size < 0 || bit_size < 0) {
+ buffer_size = bit_size = 0;
+ buffer = NULL;
+ }
+
+ s->buffer= buffer;
+ s->size_in_bits= bit_size;
+ s->buffer_end= buffer + buffer_size;
+#ifdef ALT_BITSTREAM_READER
+ s->index=0;
+#elif defined LIBMPEG2_BITSTREAM_READER
+ s->buffer_ptr = (uint8_t*)((intptr_t)buffer&(~1));
+ s->bit_count = 16 + 8*((intptr_t)buffer&1);
+ skip_bits_long(s, 0);
+#elif defined A32_BITSTREAM_READER
+ s->buffer_ptr = (uint32_t*)((intptr_t)buffer&(~3));
+ s->bit_count = 32 + 8*((intptr_t)buffer&3);
+ skip_bits_long(s, 0);
+#endif
+}
+
+static inline void align_get_bits(GetBitContext *s)
+{
+ int n= (-get_bits_count(s)) & 7;
+ if(n) skip_bits(s, n);
+}
+
+int init_vlc(VLC *vlc, int nb_bits, int nb_codes,
+ const void *bits, int bits_wrap, int bits_size,
+ const void *codes, int codes_wrap, int codes_size,
+ int flags);
+#define INIT_VLC_USE_STATIC 1
+#define INIT_VLC_LE 2
+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
+ */
+#define GET_VLC(code, name, gb, table, bits, max_depth)\
+{\
+ int n, index, nb_bits;\
+\
+ index= SHOW_UBITS(name, gb, bits);\
+ code = table[index][0];\
+ n = table[index][1];\
+\
+ if(max_depth > 1 && n < 0){\
+ LAST_SKIP_BITS(name, gb, bits)\
+ UPDATE_CACHE(name, gb)\
+\
+ nb_bits = -n;\
+\
+ index= SHOW_UBITS(name, gb, nb_bits) + code;\
+ code = table[index][0];\
+ n = table[index][1];\
+ if(max_depth > 2 && n < 0){\
+ LAST_SKIP_BITS(name, gb, nb_bits)\
+ UPDATE_CACHE(name, gb)\
+\
+ nb_bits = -n;\
+\
+ index= SHOW_UBITS(name, gb, nb_bits) + code;\
+ code = table[index][0];\
+ n = table[index][1];\
+ }\
+ }\
+ SKIP_BITS(name, gb, n)\
+}
+
+#define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)\
+{\
+ int n, index, nb_bits;\
+\
+ index= SHOW_UBITS(name, gb, bits);\
+ level = table[index].level;\
+ n = table[index].len;\
+\
+ if(max_depth > 1 && n < 0){\
+ SKIP_BITS(name, gb, bits)\
+ if(need_update){\
+ UPDATE_CACHE(name, gb)\
+ }\
+\
+ nb_bits = -n;\
+\
+ index= SHOW_UBITS(name, gb, nb_bits) + level;\
+ level = table[index].level;\
+ n = table[index].len;\
+ }\
+ run= table[index].run;\
+ SKIP_BITS(name, gb, n)\
+}
+
+
+/**
+ * parses a vlc code, faster then get_vlc()
+ * @param bits is the number of bits which will be read at once, must be
+ * identical to nb_bits in init_vlc()
+ * @param max_depth is the number of times bits bits must be readed to completly
+ * read the longest vlc code
+ * = (max_vlc_length + bits - 1) / bits
+ */
+static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2],
+ int bits, int max_depth)
+{
+ int code;
+
+ OPEN_READER(re, s)
+ UPDATE_CACHE(re, s)
+
+ GET_VLC(code, re, s, table, bits, max_depth)
+
+ CLOSE_READER(re, s)
+ return code;
+}
+
+//#define TRACE
+
+#ifdef TRACE
+static inline void print_bin(int bits, int n){
+ int i;
+
+ for(i=n-1; i>=0; i--){
+ av_log(NULL, AV_LOG_DEBUG, "%d", (bits>>i)&1);
+ }
+ for(i=n; i<24; i++)
+ av_log(NULL, AV_LOG_DEBUG, " ");
+}
+
+static inline int get_bits_trace(GetBitContext *s, int n, char *file, const char *func, int line){
+ int r= get_bits(s, n);
+
+ print_bin(r, n);
+ av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d bit @%5d in %s %s:%d\n", r, n, r, get_bits_count(s)-n, file, func, line);
+ return r;
+}
+static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2], int bits, int max_depth, char *file, const char *func, int line){
+ int show= show_bits(s, 24);
+ int pos= get_bits_count(s);
+ int r= get_vlc2(s, table, bits, max_depth);
+ int len= get_bits_count(s) - pos;
+ int bits2= show>>(24-len);
+
+ print_bin(bits2, len);
+
+ av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d vlc @%5d in %s %s:%d\n", bits2, len, r, pos, file, func, line);
+ return r;
+}
+static inline int get_xbits_trace(GetBitContext *s, int n, char *file, const char *func, int line){
+ int show= show_bits(s, n);
+ int r= get_xbits(s, n);
+
+ print_bin(show, n);
+ av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d xbt @%5d in %s %s:%d\n", show, n, r, get_bits_count(s)-n, file, func, line);
+ return r;
+}
+
+#define get_bits(s, n) get_bits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__)
+#define get_bits1(s) get_bits_trace(s, 1, __FILE__, __PRETTY_FUNCTION__, __LINE__)
+#define get_xbits(s, n) get_xbits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__)
+#define get_vlc(s, vlc) get_vlc_trace(s, (vlc)->table, (vlc)->bits, 3, __FILE__, __PRETTY_FUNCTION__, __LINE__)
+#define get_vlc2(s, tab, bits, max) get_vlc_trace(s, tab, bits, max, __FILE__, __PRETTY_FUNCTION__, __LINE__)
+
+#define tprintf(p, ...) av_log(p, AV_LOG_DEBUG, __VA_ARGS__)
+
+#else //TRACE
+#define tprintf(p, ...) {}
+#endif
+
+static inline int decode012(GetBitContext *gb){
+ int n;
+ n = get_bits1(gb);
+ if (n == 0)
+ return 0;
+ else
+ return get_bits1(gb) + 1;
+}
+
+#endif /* BITSTREAM_H */
diff --git a/contrib/ffmpeg/libavcodec/bitstream_filter.c b/contrib/ffmpeg/libavcodec/bitstream_filter.c
new file mode 100644
index 000000000..89fc4e175
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/bitstream_filter.c
@@ -0,0 +1,284 @@
+/*
+ * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avcodec.h"
+#include "mpegaudio.h"
+
+AVBitStreamFilter *first_bitstream_filter= NULL;
+
+void av_register_bitstream_filter(AVBitStreamFilter *bsf){
+ bsf->next = first_bitstream_filter;
+ first_bitstream_filter= bsf;
+}
+
+AVBitStreamFilterContext *av_bitstream_filter_init(const char *name){
+ AVBitStreamFilter *bsf= first_bitstream_filter;
+
+ while(bsf){
+ if(!strcmp(name, bsf->name)){
+ AVBitStreamFilterContext *bsfc= av_mallocz(sizeof(AVBitStreamFilterContext));
+ bsfc->filter= bsf;
+ bsfc->priv_data= av_mallocz(bsf->priv_data_size);
+ return bsfc;
+ }
+ bsf= bsf->next;
+ }
+ return NULL;
+}
+
+void av_bitstream_filter_close(AVBitStreamFilterContext *bsfc){
+ av_freep(&bsfc->priv_data);
+ av_parser_close(bsfc->parser);
+ av_free(bsfc);
+}
+
+int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc,
+ AVCodecContext *avctx, const char *args,
+ uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size, int keyframe){
+ *poutbuf= (uint8_t *) buf;
+ *poutbuf_size= buf_size;
+ return bsfc->filter->filter(bsfc, avctx, args, poutbuf, poutbuf_size, buf, buf_size, keyframe);
+}
+
+static int dump_extradata(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
+ uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size, int keyframe){
+ int cmd= args ? *args : 0;
+ /* cast to avoid warning about discarding qualifiers */
+ if(avctx->extradata){
+ if( (keyframe && (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER) && cmd=='a')
+ ||(keyframe && (cmd=='k' || !cmd))
+ ||(cmd=='e')
+ /*||(? && (s->flags & PARSER_FLAG_DUMP_EXTRADATA_AT_BEGIN)*/){
+ int size= buf_size + avctx->extradata_size;
+ *poutbuf_size= size;
+ *poutbuf= av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
+
+ memcpy(*poutbuf, avctx->extradata, avctx->extradata_size);
+ memcpy((*poutbuf) + avctx->extradata_size, buf, buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ return 1;
+ }
+ }
+ return 0;
+}
+
+static int remove_extradata(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
+ uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size, int keyframe){
+ int cmd= args ? *args : 0;
+ AVCodecParserContext *s;
+
+ if(!bsfc->parser){
+ bsfc->parser= av_parser_init(avctx->codec_id);
+ }
+ s= bsfc->parser;
+
+ if(s && s->parser->split){
+ if( (((avctx->flags & CODEC_FLAG_GLOBAL_HEADER) || (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER)) && cmd=='a')
+ ||(!keyframe && cmd=='k')
+ ||(cmd=='e' || !cmd)
+ ){
+ int i= s->parser->split(avctx, buf, buf_size);
+ buf += i;
+ buf_size -= i;
+ }
+ }
+ *poutbuf= (uint8_t *) buf;
+ *poutbuf_size= buf_size;
+
+ return 0;
+}
+
+static int noise(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
+ uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size, int keyframe){
+ int amount= args ? atoi(args) : 10000;
+ unsigned int *state= bsfc->priv_data;
+ int i;
+
+ *poutbuf= av_malloc(buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
+
+ memcpy(*poutbuf, buf, buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ for(i=0; i<buf_size; i++){
+ (*state) += (*poutbuf)[i] + 1;
+ if(*state % amount == 0)
+ (*poutbuf)[i] = *state;
+ }
+ return 1;
+}
+
+#define MP3_MASK 0xFFFE0CCF
+
+static int mp3_header_compress(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
+ uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size, int keyframe){
+ uint32_t header, extraheader;
+ int mode_extension, header_size;
+
+ if(avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){
+ av_log(avctx, AV_LOG_ERROR, "not standards compliant\n");
+ return -1;
+ }
+
+ header = AV_RB32(buf);
+ mode_extension= (header>>4)&3;
+
+ if(ff_mpa_check_header(header) < 0 || (header&0x60000) != 0x20000){
+output_unchanged:
+ *poutbuf= (uint8_t *) buf;
+ *poutbuf_size= buf_size;
+
+ av_log(avctx, AV_LOG_INFO, "cannot compress %08X\n", header);
+ return 0;
+ }
+
+ if(avctx->extradata_size == 0){
+ avctx->extradata_size=15;
+ avctx->extradata= av_malloc(avctx->extradata_size);
+ strcpy(avctx->extradata, "FFCMP3 0.0");
+ memcpy(avctx->extradata+11, buf, 4);
+ }
+ if(avctx->extradata_size != 15){
+ av_log(avctx, AV_LOG_ERROR, "Extradata invalid\n");
+ return -1;
+ }
+ extraheader = AV_RB32(avctx->extradata+11);
+ if((extraheader&MP3_MASK) != (header&MP3_MASK))
+ goto output_unchanged;
+
+ header_size= (header&0x10000) ? 4 : 6;
+
+ *poutbuf_size= buf_size - header_size;
+ *poutbuf= av_malloc(buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ memcpy(*poutbuf, buf + header_size, buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE);
+
+ if(avctx->channels==2){
+ if((header & (3<<19)) != 3<<19){
+ (*poutbuf)[1] &= 0x3F;
+ (*poutbuf)[1] |= mode_extension<<6;
+ FFSWAP(int, (*poutbuf)[1], (*poutbuf)[2]);
+ }else{
+ (*poutbuf)[1] &= 0x8F;
+ (*poutbuf)[1] |= mode_extension<<4;
+ }
+ }
+
+ return 1;
+}
+
+static int mp3_header_decompress(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
+ uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size, int keyframe){
+ uint32_t header;
+ int sample_rate= avctx->sample_rate;
+ int sample_rate_index=0;
+ int lsf, mpeg25, bitrate_index, frame_size;
+
+ header = AV_RB32(buf);
+ if(ff_mpa_check_header(header) >= 0){
+ *poutbuf= (uint8_t *) buf;
+ *poutbuf_size= buf_size;
+
+ return 0;
+ }
+
+ if(avctx->extradata_size != 15 || strcmp(avctx->extradata, "FFCMP3 0.0")){
+ av_log(avctx, AV_LOG_ERROR, "Extradata invalid %d\n", avctx->extradata_size);
+ return -1;
+ }
+
+ header= AV_RB32(avctx->extradata+11) & MP3_MASK;
+
+ lsf = sample_rate < (24000+32000)/2;
+ mpeg25 = sample_rate < (12000+16000)/2;
+ sample_rate_index= (header>>10)&3;
+ sample_rate= mpa_freq_tab[sample_rate_index] >> (lsf + mpeg25); //in case sample rate is a little off
+
+ for(bitrate_index=2; bitrate_index<30; bitrate_index++){
+ frame_size = mpa_bitrate_tab[lsf][2][bitrate_index>>1];
+ frame_size = (frame_size * 144000) / (sample_rate << lsf) + (bitrate_index&1);
+ if(frame_size == buf_size + 4)
+ break;
+ if(frame_size == buf_size + 6)
+ break;
+ }
+ if(bitrate_index == 30){
+ av_log(avctx, AV_LOG_ERROR, "couldnt find bitrate_index\n");
+ return -1;
+ }
+
+ header |= (bitrate_index&1)<<9;
+ header |= (bitrate_index>>1)<<12;
+ header |= (frame_size == buf_size + 4)<<16; //FIXME actually set a correct crc instead of 0
+
+ *poutbuf_size= frame_size;
+ *poutbuf= av_malloc(frame_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ memcpy(*poutbuf + frame_size - buf_size, buf, buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
+
+ if(avctx->channels==2){
+ uint8_t *p= *poutbuf + frame_size - buf_size;
+ if(lsf){
+ FFSWAP(int, p[1], p[2]);
+ header |= (p[1] & 0xC0)>>2;
+ p[1] &= 0x3F;
+ }else{
+ header |= p[1] & 0x30;
+ p[1] &= 0xCF;
+ }
+ }
+
+ (*poutbuf)[0]= header>>24;
+ (*poutbuf)[1]= header>>16;
+ (*poutbuf)[2]= header>> 8;
+ (*poutbuf)[3]= header ;
+
+ return 1;
+}
+
+AVBitStreamFilter dump_extradata_bsf={
+ "dump_extra",
+ 0,
+ dump_extradata,
+};
+
+AVBitStreamFilter remove_extradata_bsf={
+ "remove_extra",
+ 0,
+ remove_extradata,
+};
+
+AVBitStreamFilter noise_bsf={
+ "noise",
+ sizeof(int),
+ noise,
+};
+
+AVBitStreamFilter mp3_header_compress_bsf={
+ "mp3comp",
+ 0,
+ mp3_header_compress,
+};
+
+AVBitStreamFilter mp3_header_decompress_bsf={
+ "mp3decomp",
+ 0,
+ mp3_header_decompress,
+};
diff --git a/contrib/ffmpeg/libavcodec/bmp.c b/contrib/ffmpeg/libavcodec/bmp.c
new file mode 100644
index 000000000..d1cfdce6d
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/bmp.c
@@ -0,0 +1,254 @@
+/*
+ * BMP image format decoder
+ * Copyright (c) 2005 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 "avcodec.h"
+#include "bytestream.h"
+#include "bmp.h"
+
+static int bmp_decode_init(AVCodecContext *avctx){
+ BMPContext *s = avctx->priv_data;
+
+ avcodec_get_frame_defaults((AVFrame*)&s->picture);
+ avctx->coded_frame = (AVFrame*)&s->picture;
+
+ return 0;
+}
+
+static int bmp_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ BMPContext *s = avctx->priv_data;
+ AVFrame *picture = data;
+ AVFrame *p = &s->picture;
+ unsigned int fsize, hsize;
+ int width, height;
+ unsigned int depth;
+ BiCompression comp;
+ unsigned int ihsize;
+ int i, j, n, linesize;
+ uint32_t rgb[3];
+ uint8_t *ptr;
+ int dsize;
+ uint8_t *buf0 = buf;
+
+ if(buf_size < 14){
+ av_log(avctx, AV_LOG_ERROR, "buf size too small (%d)\n", buf_size);
+ return -1;
+ }
+
+ if(bytestream_get_byte(&buf) != 'B' ||
+ bytestream_get_byte(&buf) != 'M') {
+ av_log(avctx, AV_LOG_ERROR, "bad magic number\n");
+ return -1;
+ }
+
+ fsize = bytestream_get_le32(&buf);
+ if(buf_size < fsize){
+ av_log(avctx, AV_LOG_ERROR, "not enough data (%d < %d)\n",
+ buf_size, fsize);
+ return -1;
+ }
+
+ buf += 2; /* reserved1 */
+ buf += 2; /* reserved2 */
+
+ hsize = bytestream_get_le32(&buf); /* header size */
+ if(fsize <= hsize){
+ av_log(avctx, AV_LOG_ERROR, "not enough data (%d < %d)\n",
+ fsize, hsize);
+ return -1;
+ }
+
+ ihsize = bytestream_get_le32(&buf); /* more header size */
+ if(ihsize + 14 > hsize){
+ av_log(avctx, AV_LOG_ERROR, "invalid header size %d\n", hsize);
+ return -1;
+ }
+
+ width = bytestream_get_le32(&buf);
+ height = bytestream_get_le32(&buf);
+
+ if(bytestream_get_le16(&buf) != 1){ /* planes */
+ av_log(avctx, AV_LOG_ERROR, "invalid BMP header\n");
+ return -1;
+ }
+
+ depth = bytestream_get_le16(&buf);
+
+ if(ihsize > 16)
+ comp = bytestream_get_le32(&buf);
+ else
+ comp = BMP_RGB;
+
+ if(comp != BMP_RGB && comp != BMP_BITFIELDS){
+ av_log(avctx, AV_LOG_ERROR, "BMP coding %d not supported\n", comp);
+ return -1;
+ }
+
+ if(comp == BMP_BITFIELDS){
+ buf += 20;
+ rgb[0] = bytestream_get_le32(&buf);
+ rgb[1] = bytestream_get_le32(&buf);
+ rgb[2] = bytestream_get_le32(&buf);
+ }
+
+ avctx->codec_id = CODEC_ID_BMP;
+ avctx->width = width;
+ avctx->height = height > 0? height: -height;
+
+ avctx->pix_fmt = PIX_FMT_NONE;
+
+ switch(depth){
+ case 32:
+ if(comp == BMP_BITFIELDS){
+ rgb[0] = (rgb[0] >> 15) & 3;
+ rgb[1] = (rgb[1] >> 15) & 3;
+ rgb[2] = (rgb[2] >> 15) & 3;
+
+ if(rgb[0] + rgb[1] + rgb[2] != 3 ||
+ rgb[0] == rgb[1] || rgb[0] == rgb[2] || rgb[1] == rgb[2]){
+ break;
+ }
+ } else {
+ rgb[0] = 2;
+ rgb[1] = 1;
+ rgb[2] = 0;
+ }
+
+ avctx->pix_fmt = PIX_FMT_BGR24;
+ break;
+ case 24:
+ avctx->pix_fmt = PIX_FMT_BGR24;
+ break;
+ case 16:
+ if(comp == BMP_RGB)
+ avctx->pix_fmt = PIX_FMT_RGB555;
+ break;
+ default:
+ av_log(avctx, AV_LOG_ERROR, "depth %d not supported\n", depth);
+ return -1;
+ }
+
+ if(avctx->pix_fmt == PIX_FMT_NONE){
+ av_log(avctx, AV_LOG_ERROR, "unsupported pixel format\n");
+ 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;
+
+ buf = buf0 + hsize;
+ dsize = buf_size - hsize;
+
+ /* Line size in file multiple of 4 */
+ n = (avctx->width * (depth / 8) + 3) & ~3;
+
+ if(n * avctx->height > dsize){
+ av_log(avctx, AV_LOG_ERROR, "not enough data (%d < %d)\n",
+ dsize, n * avctx->height);
+ return -1;
+ }
+
+ if(height > 0){
+ ptr = p->data[0] + (avctx->height - 1) * p->linesize[0];
+ linesize = -p->linesize[0];
+ } else {
+ ptr = p->data[0];
+ linesize = p->linesize[0];
+ }
+
+ switch(depth){
+ case 24:
+ for(i = 0; i < avctx->height; i++){
+ memcpy(ptr, buf, avctx->width*(depth>>3));
+ buf += n;
+ ptr += linesize;
+ }
+ break;
+ case 16:
+ for(i = 0; i < avctx->height; i++){
+ uint16_t *src = (uint16_t *) buf;
+ uint16_t *dst = (uint16_t *) ptr;
+
+ for(j = 0; j < avctx->width; j++)
+ *dst++ = le2me_16(*src++);
+
+ buf += n;
+ ptr += linesize;
+ }
+ break;
+ case 32:
+ for(i = 0; i < avctx->height; i++){
+ uint8_t *src = buf;
+ uint8_t *dst = ptr;
+
+ for(j = 0; j < avctx->width; j++){
+ dst[0] = src[rgb[2]];
+ dst[1] = src[rgb[1]];
+ dst[2] = src[rgb[0]];
+ dst += 3;
+ src += 4;
+ }
+
+ buf += n;
+ ptr += linesize;
+ }
+ break;
+ default:
+ av_log(avctx, AV_LOG_ERROR, "BMP decoder is broken\n");
+ return -1;
+ }
+
+ *picture = s->picture;
+ *data_size = sizeof(AVPicture);
+
+ return buf_size;
+}
+
+static int bmp_decode_end(AVCodecContext *avctx)
+{
+ BMPContext* c = avctx->priv_data;
+
+ if (c->picture.data[0])
+ avctx->release_buffer(avctx, &c->picture);
+
+ return 0;
+}
+
+AVCodec bmp_decoder = {
+ "bmp",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_BMP,
+ sizeof(BMPContext),
+ bmp_decode_init,
+ NULL,
+ bmp_decode_end,
+ bmp_decode_frame
+};
diff --git a/contrib/ffmpeg/libavcodec/bmp.h b/contrib/ffmpeg/libavcodec/bmp.h
new file mode 100644
index 000000000..cf6ace845
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/bmp.h
@@ -0,0 +1,31 @@
+/*
+ * internals for BMP codecs
+ * Copyright (c) 2005 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
+ */
+
+typedef struct BMPContext {
+ AVFrame picture;
+} BMPContext;
+
+typedef enum {
+ BMP_RGB =0,
+ BMP_RLE8 =1,
+ BMP_RLE4 =2,
+ BMP_BITFIELDS =3,
+} BiCompression;
diff --git a/contrib/ffmpeg/libavcodec/bmpenc.c b/contrib/ffmpeg/libavcodec/bmpenc.c
new file mode 100644
index 000000000..351038504
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/bmpenc.c
@@ -0,0 +1,98 @@
+/*
+ * BMP image format encoder
+ * Copyright (c) 2006, 2007 Michel Bardiaux
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 "bmp.h"
+
+static int bmp_encode_init(AVCodecContext *avctx){
+ BMPContext *s = avctx->priv_data;
+
+ avcodec_get_frame_defaults((AVFrame*)&s->picture);
+ avctx->coded_frame = (AVFrame*)&s->picture;
+
+ return 0;
+}
+
+static int bmp_encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
+ BMPContext *s = avctx->priv_data;
+ AVFrame *pict = data;
+ AVFrame * const p= (AVFrame*)&s->picture;
+ int n_bytes_image, n_bytes_per_row, n_bytes, i, n, hsize;
+ uint8_t *ptr;
+ unsigned char* buf0 = buf;
+ *p = *pict;
+ p->pict_type= FF_I_TYPE;
+ p->key_frame= 1;
+ n_bytes_per_row = (avctx->width*3 + 3) & ~3;
+ n_bytes_image = avctx->height*n_bytes_per_row;
+
+ // STRUCTURE.field refer to the MSVC documentation for BITMAPFILEHEADER
+ // and related pages.
+#define SIZE_BITMAPFILEHEADER 14
+#define SIZE_BITMAPINFOHEADER 40
+ hsize = SIZE_BITMAPFILEHEADER + SIZE_BITMAPINFOHEADER;
+ n_bytes = n_bytes_image + hsize;
+ if(n_bytes>buf_size) {
+ av_log(avctx, AV_LOG_ERROR, "buf size too small (need %d, got %d)\n", n_bytes, buf_size);
+ return -1;
+ }
+ bytestream_put_byte(&buf, 'B'); // BITMAPFILEHEADER.bfType
+ bytestream_put_byte(&buf, 'M'); // do.
+ bytestream_put_le32(&buf, n_bytes); // BITMAPFILEHEADER.bfSize
+ bytestream_put_le16(&buf, 0); // BITMAPFILEHEADER.bfReserved1
+ bytestream_put_le16(&buf, 0); // BITMAPFILEHEADER.bfReserved2
+ bytestream_put_le32(&buf, hsize); // BITMAPFILEHEADER.bfOffBits
+ bytestream_put_le32(&buf, SIZE_BITMAPINFOHEADER); // BITMAPINFOHEADER.biSize
+ bytestream_put_le32(&buf, avctx->width); // BITMAPINFOHEADER.biWidth
+ bytestream_put_le32(&buf, avctx->height); // BITMAPINFOHEADER.biHeight
+ bytestream_put_le16(&buf, 1); // BITMAPINFOHEADER.biPlanes
+ bytestream_put_le16(&buf, 24); // BITMAPINFOHEADER.biBitCount
+ bytestream_put_le32(&buf, BMP_RGB); // BITMAPINFOHEADER.biCompression
+ bytestream_put_le32(&buf, n_bytes_image); // BITMAPINFOHEADER.biSizeImage
+ bytestream_put_le32(&buf, 0); // BITMAPINFOHEADER.biXPelsPerMeter
+ bytestream_put_le32(&buf, 0); // BITMAPINFOHEADER.biYPelsPerMeter
+ bytestream_put_le32(&buf, 0); // BITMAPINFOHEADER.biClrUsed
+ bytestream_put_le32(&buf, 0); // BITMAPINFOHEADER.biClrImportant
+ // BMP files are bottom-to-top so we start from the end...
+ ptr = p->data[0] + (avctx->height - 1) * p->linesize[0];
+ buf = buf0 + hsize;
+ for(i = 0; i < avctx->height; i++) {
+ n = 3*avctx->width;
+ memcpy(buf, ptr, n);
+ buf += n;
+ memset(buf, 0, n_bytes_per_row-n);
+ buf += n_bytes_per_row-n;
+ ptr -= p->linesize[0]; // ... and go back
+ }
+ return n_bytes;
+}
+
+AVCodec bmp_encoder = {
+ "bmp",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_BMP,
+ sizeof(BMPContext),
+ bmp_encode_init,
+ bmp_encode_frame,
+ NULL, //encode_end,
+ .pix_fmts= (enum PixelFormat[]){PIX_FMT_BGR24, -1},
+};
diff --git a/contrib/ffmpeg/libavcodec/bytestream.h b/contrib/ffmpeg/libavcodec/bytestream.h
new file mode 100644
index 000000000..d1e9f82ed
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/bytestream.h
@@ -0,0 +1,58 @@
+/*
+ * Bytestream functions
+ * copyright (c) 2006 Baptiste Coudurier <baptiste.coudurier@free.fr>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef FFMPEG_BYTESTREAM_H
+#define FFMPEG_BYTESTREAM_H
+
+#define DEF(name, bytes, read, write)\
+static av_always_inline unsigned int bytestream_get_ ## name(uint8_t **b){\
+ (*b) += bytes;\
+ return read(*b - bytes);\
+}\
+static av_always_inline void bytestream_put_ ##name(uint8_t **b, const unsigned int value){\
+ write(*b, value);\
+ (*b) += bytes;\
+};
+
+DEF(le32, 4, AV_RL32, AV_WL32)
+DEF(le24, 3, AV_RL24, AV_WL24)
+DEF(le16, 2, AV_RL16, AV_WL16)
+DEF(be32, 4, AV_RB32, AV_WB32)
+DEF(be24, 3, AV_RB24, AV_WB24)
+DEF(be16, 2, AV_RB16, AV_WB16)
+DEF(byte, 1, AV_RB8 , AV_WB8 )
+
+#undef DEF
+
+static av_always_inline unsigned int bytestream_get_buffer(uint8_t **b, uint8_t *dst, unsigned int size)
+{
+ memcpy(dst, *b, size);
+ (*b) += size;
+ return size;
+}
+
+static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
+{
+ memcpy(*b, src, size);
+ (*b) += size;
+}
+
+#endif /* FFMPEG_BYTESTREAM_H */
diff --git a/src/libffmpeg/libavcodec/cabac.c b/contrib/ffmpeg/libavcodec/cabac.c
index c6da6292a..c6da6292a 100644
--- a/src/libffmpeg/libavcodec/cabac.c
+++ b/contrib/ffmpeg/libavcodec/cabac.c
diff --git a/contrib/ffmpeg/libavcodec/cabac.h b/contrib/ffmpeg/libavcodec/cabac.h
new file mode 100644
index 000000000..147d25ffa
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/cabac.h
@@ -0,0 +1,859 @@
+/*
+ * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder
+ * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * @file cabac.h
+ * Context Adaptive Binary Arithmetic Coder.
+ */
+
+
+//#undef NDEBUG
+#include <assert.h>
+#ifdef ARCH_X86
+#include "x86_cpu.h"
+#endif
+
+#define CABAC_BITS 16
+#define CABAC_MASK ((1<<CABAC_BITS)-1)
+#define BRANCHLESS_CABAC_DECODER 1
+//#define ARCH_X86_DISABLED 1
+
+typedef struct CABACContext{
+ int low;
+ int range;
+ int outstanding_count;
+#ifdef STRICT_LIMITS
+ int symCount;
+#endif
+ const uint8_t *bytestream_start;
+ const uint8_t *bytestream;
+ const uint8_t *bytestream_end;
+ PutBitContext pb;
+}CABACContext;
+
+extern uint8_t ff_h264_mlps_state[4*64];
+extern uint8_t ff_h264_lps_range[4*2*64]; ///< rangeTabLPS
+extern uint8_t ff_h264_mps_state[2*64]; ///< transIdxMPS
+extern uint8_t ff_h264_lps_state[2*64]; ///< transIdxLPS
+extern const uint8_t ff_h264_norm_shift[512];
+
+
+void ff_init_cabac_encoder(CABACContext *c, uint8_t *buf, int buf_size);
+void ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size);
+void ff_init_cabac_states(CABACContext *c);
+
+
+static inline void put_cabac_bit(CABACContext *c, int b){
+ put_bits(&c->pb, 1, b);
+ for(;c->outstanding_count; c->outstanding_count--){
+ put_bits(&c->pb, 1, 1-b);
+ }
+}
+
+static inline void renorm_cabac_encoder(CABACContext *c){
+ while(c->range < 0x100){
+ //FIXME optimize
+ if(c->low<0x100){
+ put_cabac_bit(c, 0);
+ }else if(c->low<0x200){
+ c->outstanding_count++;
+ c->low -= 0x100;
+ }else{
+ put_cabac_bit(c, 1);
+ c->low -= 0x200;
+ }
+
+ c->range+= c->range;
+ c->low += c->low;
+ }
+}
+
+static void put_cabac(CABACContext *c, uint8_t * const state, int bit){
+ int RangeLPS= ff_h264_lps_range[2*(c->range&0xC0) + *state];
+
+ if(bit == ((*state)&1)){
+ c->range -= RangeLPS;
+ *state= ff_h264_mps_state[*state];
+ }else{
+ c->low += c->range - RangeLPS;
+ c->range = RangeLPS;
+ *state= ff_h264_lps_state[*state];
+ }
+
+ renorm_cabac_encoder(c);
+
+#ifdef STRICT_LIMITS
+ c->symCount++;
+#endif
+}
+
+static void put_cabac_static(CABACContext *c, int RangeLPS, int bit){
+ assert(c->range > RangeLPS);
+
+ if(!bit){
+ c->range -= RangeLPS;
+ }else{
+ c->low += c->range - RangeLPS;
+ c->range = RangeLPS;
+ }
+
+ renorm_cabac_encoder(c);
+
+#ifdef STRICT_LIMITS
+ c->symCount++;
+#endif
+}
+
+/**
+ * @param bit 0 -> write zero bit, !=0 write one bit
+ */
+static void put_cabac_bypass(CABACContext *c, int bit){
+ c->low += c->low;
+
+ if(bit){
+ c->low += c->range;
+ }
+//FIXME optimize
+ if(c->low<0x200){
+ put_cabac_bit(c, 0);
+ }else if(c->low<0x400){
+ c->outstanding_count++;
+ c->low -= 0x200;
+ }else{
+ put_cabac_bit(c, 1);
+ c->low -= 0x400;
+ }
+
+#ifdef STRICT_LIMITS
+ c->symCount++;
+#endif
+}
+
+/**
+ *
+ * @return the number of bytes written
+ */
+static int put_cabac_terminate(CABACContext *c, int bit){
+ c->range -= 2;
+
+ if(!bit){
+ renorm_cabac_encoder(c);
+ }else{
+ c->low += c->range;
+ c->range= 2;
+
+ renorm_cabac_encoder(c);
+
+ assert(c->low <= 0x1FF);
+ put_cabac_bit(c, c->low>>9);
+ put_bits(&c->pb, 2, ((c->low>>7)&3)|1);
+
+ flush_put_bits(&c->pb); //FIXME FIXME FIXME XXX wrong
+ }
+
+#ifdef STRICT_LIMITS
+ c->symCount++;
+#endif
+
+ return (put_bits_count(&c->pb)+7)>>3;
+}
+
+/**
+ * put (truncated) unary binarization.
+ */
+static void put_cabac_u(CABACContext *c, uint8_t * state, int v, int max, int max_index, int truncated){
+ int i;
+
+ assert(v <= max);
+
+#if 1
+ for(i=0; i<v; i++){
+ put_cabac(c, state, 1);
+ if(i < max_index) state++;
+ }
+ if(truncated==0 || v<max)
+ put_cabac(c, state, 0);
+#else
+ if(v <= max_index){
+ for(i=0; i<v; i++){
+ put_cabac(c, state+i, 1);
+ }
+ if(truncated==0 || v<max)
+ put_cabac(c, state+i, 0);
+ }else{
+ for(i=0; i<=max_index; i++){
+ put_cabac(c, state+i, 1);
+ }
+ for(; i<v; i++){
+ put_cabac(c, state+max_index, 1);
+ }
+ if(truncated==0 || v<max)
+ put_cabac(c, state+max_index, 0);
+ }
+#endif
+}
+
+/**
+ * put unary exp golomb k-th order binarization.
+ */
+static void put_cabac_ueg(CABACContext *c, uint8_t * state, int v, int max, int is_signed, int k, int max_index){
+ int i;
+
+ if(v==0)
+ put_cabac(c, state, 0);
+ else{
+ const int sign= v < 0;
+
+ if(is_signed) v= FFABS(v);
+
+ if(v<max){
+ for(i=0; i<v; i++){
+ put_cabac(c, state, 1);
+ if(i < max_index) state++;
+ }
+
+ put_cabac(c, state, 0);
+ }else{
+ int m= 1<<k;
+
+ for(i=0; i<max; i++){
+ put_cabac(c, state, 1);
+ if(i < max_index) state++;
+ }
+
+ v -= max;
+ while(v >= m){ //FIXME optimize
+ put_cabac_bypass(c, 1);
+ v-= m;
+ m+= m;
+ }
+ put_cabac_bypass(c, 0);
+ while(m>>=1){
+ put_cabac_bypass(c, v&m);
+ }
+ }
+
+ if(is_signed)
+ put_cabac_bypass(c, sign);
+ }
+}
+
+static void refill(CABACContext *c){
+#if CABAC_BITS == 16
+ c->low+= (c->bytestream[0]<<9) + (c->bytestream[1]<<1);
+#else
+ c->low+= c->bytestream[0]<<1;
+#endif
+ c->low -= CABAC_MASK;
+ c->bytestream+= CABAC_BITS/8;
+}
+
+static void refill2(CABACContext *c){
+ int i, x;
+
+ x= c->low ^ (c->low-1);
+ i= 7 - ff_h264_norm_shift[x>>(CABAC_BITS-1)];
+
+ x= -CABAC_MASK;
+
+#if CABAC_BITS == 16
+ x+= (c->bytestream[0]<<9) + (c->bytestream[1]<<1);
+#else
+ x+= c->bytestream[0]<<1;
+#endif
+
+ c->low += x<<i;
+ c->bytestream+= CABAC_BITS/8;
+}
+
+static inline void renorm_cabac_decoder(CABACContext *c){
+ while(c->range < 0x100){
+ c->range+= c->range;
+ c->low+= c->low;
+ if(!(c->low & CABAC_MASK))
+ refill(c);
+ }
+}
+
+static inline void renorm_cabac_decoder_once(CABACContext *c){
+#ifdef ARCH_X86_DISABLED
+ int temp;
+#if 0
+ //P3:683 athlon:475
+ asm(
+ "lea -0x100(%0), %2 \n\t"
+ "shr $31, %2 \n\t" //FIXME 31->63 for x86-64
+ "shl %%cl, %0 \n\t"
+ "shl %%cl, %1 \n\t"
+ : "+r"(c->range), "+r"(c->low), "+c"(temp)
+ );
+#elif 0
+ //P3:680 athlon:474
+ asm(
+ "cmp $0x100, %0 \n\t"
+ "setb %%cl \n\t" //FIXME 31->63 for x86-64
+ "shl %%cl, %0 \n\t"
+ "shl %%cl, %1 \n\t"
+ : "+r"(c->range), "+r"(c->low), "+c"(temp)
+ );
+#elif 1
+ int temp2;
+ //P3:665 athlon:517
+ asm(
+ "lea -0x100(%0), %%eax \n\t"
+ "cdq \n\t"
+ "mov %0, %%eax \n\t"
+ "and %%edx, %0 \n\t"
+ "and %1, %%edx \n\t"
+ "add %%eax, %0 \n\t"
+ "add %%edx, %1 \n\t"
+ : "+r"(c->range), "+r"(c->low), "+a"(temp), "+d"(temp2)
+ );
+#elif 0
+ int temp2;
+ //P3:673 athlon:509
+ asm(
+ "cmp $0x100, %0 \n\t"
+ "sbb %%edx, %%edx \n\t"
+ "mov %0, %%eax \n\t"
+ "and %%edx, %0 \n\t"
+ "and %1, %%edx \n\t"
+ "add %%eax, %0 \n\t"
+ "add %%edx, %1 \n\t"
+ : "+r"(c->range), "+r"(c->low), "+a"(temp), "+d"(temp2)
+ );
+#else
+ int temp2;
+ //P3:677 athlon:511
+ asm(
+ "cmp $0x100, %0 \n\t"
+ "lea (%0, %0), %%eax \n\t"
+ "lea (%1, %1), %%edx \n\t"
+ "cmovb %%eax, %0 \n\t"
+ "cmovb %%edx, %1 \n\t"
+ : "+r"(c->range), "+r"(c->low), "+a"(temp), "+d"(temp2)
+ );
+#endif
+#else
+ //P3:675 athlon:476
+ int shift= (uint32_t)(c->range - 0x100)>>31;
+ c->range<<= shift;
+ c->low <<= shift;
+#endif
+ if(!(c->low & CABAC_MASK))
+ refill(c);
+}
+
+static int av_always_inline get_cabac_inline(CABACContext *c, uint8_t * const state){
+ //FIXME gcc generates duplicate load/stores for c->low and c->range
+#define LOW "0"
+#define RANGE "4"
+#ifdef ARCH_X86_64
+#define BYTESTART "16"
+#define BYTE "24"
+#define BYTEEND "32"
+#else
+#define BYTESTART "12"
+#define BYTE "16"
+#define BYTEEND "20"
+#endif
+#if defined(ARCH_X86) && defined(CONFIG_7REGS) && defined(CONFIG_EBX_AVAILABLE) && !( defined(ARCH_X86_64) && defined(PIC) )
+ int bit;
+
+#ifndef BRANCHLESS_CABAC_DECODER
+ asm volatile(
+ "movzbl (%1), %0 \n\t"
+ "movl "RANGE "(%2), %%ebx \n\t"
+ "movl "RANGE "(%2), %%edx \n\t"
+ "andl $0xC0, %%ebx \n\t"
+ "movzbl "MANGLE(ff_h264_lps_range)"(%0, %%ebx, 2), %%esi\n\t"
+ "movl "LOW "(%2), %%ebx \n\t"
+//eax:state ebx:low, edx:range, esi:RangeLPS
+ "subl %%esi, %%edx \n\t"
+ "movl %%edx, %%ecx \n\t"
+ "shll $17, %%ecx \n\t"
+ "cmpl %%ecx, %%ebx \n\t"
+ " ja 1f \n\t"
+
+#if 1
+ //athlon:4067 P3:4110
+ "lea -0x100(%%edx), %%ecx \n\t"
+ "shr $31, %%ecx \n\t"
+ "shl %%cl, %%edx \n\t"
+ "shl %%cl, %%ebx \n\t"
+#else
+ //athlon:4057 P3:4130
+ "cmp $0x100, %%edx \n\t" //FIXME avoidable
+ "setb %%cl \n\t"
+ "shl %%cl, %%edx \n\t"
+ "shl %%cl, %%ebx \n\t"
+#endif
+ "movzbl "MANGLE(ff_h264_mps_state)"(%0), %%ecx \n\t"
+ "movb %%cl, (%1) \n\t"
+//eax:state ebx:low, edx:range, esi:RangeLPS
+ "test %%bx, %%bx \n\t"
+ " jnz 2f \n\t"
+ "mov "BYTE "(%2), %%"REG_S" \n\t"
+ "subl $0xFFFF, %%ebx \n\t"
+ "movzwl (%%"REG_S"), %%ecx \n\t"
+ "bswap %%ecx \n\t"
+ "shrl $15, %%ecx \n\t"
+ "add $2, %%"REG_S" \n\t"
+ "addl %%ecx, %%ebx \n\t"
+ "mov %%"REG_S", "BYTE "(%2) \n\t"
+ "jmp 2f \n\t"
+ "1: \n\t"
+//eax:state ebx:low, edx:range, esi:RangeLPS
+ "subl %%ecx, %%ebx \n\t"
+ "movl %%esi, %%edx \n\t"
+ "movzbl " MANGLE(ff_h264_norm_shift) "(%%esi), %%ecx \n\t"
+ "shll %%cl, %%ebx \n\t"
+ "shll %%cl, %%edx \n\t"
+ "movzbl "MANGLE(ff_h264_lps_state)"(%0), %%ecx \n\t"
+ "movb %%cl, (%1) \n\t"
+ "add $1, %0 \n\t"
+ "test %%bx, %%bx \n\t"
+ " jnz 2f \n\t"
+
+ "mov "BYTE "(%2), %%"REG_c" \n\t"
+ "movzwl (%%"REG_c"), %%esi \n\t"
+ "bswap %%esi \n\t"
+ "shrl $15, %%esi \n\t"
+ "subl $0xFFFF, %%esi \n\t"
+ "add $2, %%"REG_c" \n\t"
+ "mov %%"REG_c", "BYTE "(%2) \n\t"
+
+ "leal -1(%%ebx), %%ecx \n\t"
+ "xorl %%ebx, %%ecx \n\t"
+ "shrl $15, %%ecx \n\t"
+ "movzbl " MANGLE(ff_h264_norm_shift) "(%%ecx), %%ecx \n\t"
+ "neg %%ecx \n\t"
+ "add $7, %%ecx \n\t"
+
+ "shll %%cl , %%esi \n\t"
+ "addl %%esi, %%ebx \n\t"
+ "2: \n\t"
+ "movl %%edx, "RANGE "(%2) \n\t"
+ "movl %%ebx, "LOW "(%2) \n\t"
+ :"=&a"(bit) //FIXME this is fragile gcc either runs out of registers or misscompiles it (for example if "+a"(bit) or "+m"(*state) is used
+ :"r"(state), "r"(c)
+ : "%"REG_c, "%ebx", "%edx", "%"REG_S, "memory"
+ );
+ bit&=1;
+#else /* BRANCHLESS_CABAC_DECODER */
+
+
+#if defined HAVE_FAST_CMOV
+#define BRANCHLESS_GET_CABAC_UPDATE(ret, cabac, statep, low, lowword, range, tmp, tmpbyte)\
+ "mov "tmp" , %%ecx \n\t"\
+ "shl $17 , "tmp" \n\t"\
+ "cmp "low" , "tmp" \n\t"\
+ "cmova %%ecx , "range" \n\t"\
+ "sbb %%ecx , %%ecx \n\t"\
+ "and %%ecx , "tmp" \n\t"\
+ "sub "tmp" , "low" \n\t"\
+ "xor %%ecx , "ret" \n\t"
+#else /* HAVE_FAST_CMOV */
+#define BRANCHLESS_GET_CABAC_UPDATE(ret, cabac, statep, low, lowword, range, tmp, tmpbyte)\
+ "mov "tmp" , %%ecx \n\t"\
+ "shl $17 , "tmp" \n\t"\
+ "sub "low" , "tmp" \n\t"\
+ "sar $31 , "tmp" \n\t" /*lps_mask*/\
+ "sub %%ecx , "range" \n\t" /*RangeLPS - range*/\
+ "and "tmp" , "range" \n\t" /*(RangeLPS - range)&lps_mask*/\
+ "add %%ecx , "range" \n\t" /*new range*/\
+ "shl $17 , %%ecx \n\t"\
+ "and "tmp" , %%ecx \n\t"\
+ "sub %%ecx , "low" \n\t"\
+ "xor "tmp" , "ret" \n\t"
+#endif /* HAVE_FAST_CMOV */
+
+
+#define BRANCHLESS_GET_CABAC(ret, cabac, statep, low, lowword, range, tmp, tmpbyte)\
+ "movzbl "statep" , "ret" \n\t"\
+ "mov "range" , "tmp" \n\t"\
+ "and $0xC0 , "range" \n\t"\
+ "movzbl "MANGLE(ff_h264_lps_range)"("ret", "range", 2), "range" \n\t"\
+ "sub "range" , "tmp" \n\t"\
+ BRANCHLESS_GET_CABAC_UPDATE(ret, cabac, statep, low, lowword, range, tmp, tmpbyte)\
+ "movzbl " MANGLE(ff_h264_norm_shift) "("range"), %%ecx \n\t"\
+ "shl %%cl , "range" \n\t"\
+ "movzbl "MANGLE(ff_h264_mlps_state)"+128("ret"), "tmp" \n\t"\
+ "mov "tmpbyte" , "statep" \n\t"\
+ "shl %%cl , "low" \n\t"\
+ "test "lowword" , "lowword" \n\t"\
+ " jnz 1f \n\t"\
+ "mov "BYTE"("cabac"), %%"REG_c" \n\t"\
+ "movzwl (%%"REG_c") , "tmp" \n\t"\
+ "bswap "tmp" \n\t"\
+ "shr $15 , "tmp" \n\t"\
+ "sub $0xFFFF , "tmp" \n\t"\
+ "add $2 , %%"REG_c" \n\t"\
+ "mov %%"REG_c" , "BYTE "("cabac") \n\t"\
+ "lea -1("low") , %%ecx \n\t"\
+ "xor "low" , %%ecx \n\t"\
+ "shr $15 , %%ecx \n\t"\
+ "movzbl " MANGLE(ff_h264_norm_shift) "(%%ecx), %%ecx \n\t"\
+ "neg %%ecx \n\t"\
+ "add $7 , %%ecx \n\t"\
+ "shl %%cl , "tmp" \n\t"\
+ "add "tmp" , "low" \n\t"\
+ "1: \n\t"
+
+ asm volatile(
+ "movl "RANGE "(%2), %%esi \n\t"
+ "movl "LOW "(%2), %%ebx \n\t"
+ BRANCHLESS_GET_CABAC("%0", "%2", "(%1)", "%%ebx", "%%bx", "%%esi", "%%edx", "%%dl")
+ "movl %%esi, "RANGE "(%2) \n\t"
+ "movl %%ebx, "LOW "(%2) \n\t"
+
+ :"=&a"(bit)
+ :"r"(state), "r"(c)
+ : "%"REG_c, "%ebx", "%edx", "%esi", "memory"
+ );
+ bit&=1;
+#endif /* BRANCHLESS_CABAC_DECODER */
+#else /* defined(ARCH_X86) && !(defined(PIC) && defined(__GNUC__)) */
+ int s = *state;
+ int RangeLPS= ff_h264_lps_range[2*(c->range&0xC0) + s];
+ int bit, lps_mask attribute_unused;
+
+ c->range -= RangeLPS;
+#ifndef BRANCHLESS_CABAC_DECODER
+ if(c->low < (c->range<<(CABAC_BITS+1))){
+ bit= s&1;
+ *state= ff_h264_mps_state[s];
+ renorm_cabac_decoder_once(c);
+ }else{
+ bit= ff_h264_norm_shift[RangeLPS];
+ c->low -= (c->range<<(CABAC_BITS+1));
+ *state= ff_h264_lps_state[s];
+ c->range = RangeLPS<<bit;
+ c->low <<= bit;
+ bit= (s&1)^1;
+
+ if(!(c->low & CABAC_MASK)){
+ refill2(c);
+ }
+ }
+#else /* BRANCHLESS_CABAC_DECODER */
+ lps_mask= ((c->range<<(CABAC_BITS+1)) - c->low)>>31;
+
+ c->low -= (c->range<<(CABAC_BITS+1)) & lps_mask;
+ c->range += (RangeLPS - c->range) & lps_mask;
+
+ s^=lps_mask;
+ *state= (ff_h264_mlps_state+128)[s];
+ bit= s&1;
+
+ lps_mask= ff_h264_norm_shift[c->range];
+ c->range<<= lps_mask;
+ c->low <<= lps_mask;
+ if(!(c->low & CABAC_MASK))
+ refill2(c);
+#endif /* BRANCHLESS_CABAC_DECODER */
+#endif /* defined(ARCH_X86) && !(defined(PIC) && defined(__GNUC__)) */
+ return bit;
+}
+
+static int av_noinline get_cabac_noinline(CABACContext *c, uint8_t * const state){
+ return get_cabac_inline(c,state);
+}
+
+static int get_cabac(CABACContext *c, uint8_t * const state){
+ return get_cabac_inline(c,state);
+}
+
+static int get_cabac_bypass(CABACContext *c){
+#if 0 //not faster
+ int bit;
+ asm volatile(
+ "movl "RANGE "(%1), %%ebx \n\t"
+ "movl "LOW "(%1), %%eax \n\t"
+ "shl $17, %%ebx \n\t"
+ "add %%eax, %%eax \n\t"
+ "sub %%ebx, %%eax \n\t"
+ "cdq \n\t"
+ "and %%edx, %%ebx \n\t"
+ "add %%ebx, %%eax \n\t"
+ "test %%ax, %%ax \n\t"
+ " jnz 1f \n\t"
+ "movl "BYTE "(%1), %%"REG_b" \n\t"
+ "subl $0xFFFF, %%eax \n\t"
+ "movzwl (%%"REG_b"), %%ecx \n\t"
+ "bswap %%ecx \n\t"
+ "shrl $15, %%ecx \n\t"
+ "addl $2, %%"REG_b" \n\t"
+ "addl %%ecx, %%eax \n\t"
+ "movl %%"REG_b", "BYTE "(%1) \n\t"
+ "1: \n\t"
+ "movl %%eax, "LOW "(%1) \n\t"
+
+ :"=&d"(bit)
+ :"r"(c)
+ : "%eax", "%"REG_b, "%ecx", "memory"
+ );
+ return bit+1;
+#else
+ int range;
+ c->low += c->low;
+
+ if(!(c->low & CABAC_MASK))
+ refill(c);
+
+ range= c->range<<(CABAC_BITS+1);
+ if(c->low < range){
+ return 0;
+ }else{
+ c->low -= range;
+ return 1;
+ }
+#endif
+}
+
+
+static av_always_inline int get_cabac_bypass_sign(CABACContext *c, int val){
+#if defined(ARCH_X86) && !(defined(PIC) && defined(__GNUC__))
+ asm volatile(
+ "movl "RANGE "(%1), %%ebx \n\t"
+ "movl "LOW "(%1), %%eax \n\t"
+ "shl $17, %%ebx \n\t"
+ "add %%eax, %%eax \n\t"
+ "sub %%ebx, %%eax \n\t"
+ "cdq \n\t"
+ "and %%edx, %%ebx \n\t"
+ "add %%ebx, %%eax \n\t"
+ "xor %%edx, %%ecx \n\t"
+ "sub %%edx, %%ecx \n\t"
+ "test %%ax, %%ax \n\t"
+ " jnz 1f \n\t"
+ "mov "BYTE "(%1), %%"REG_b" \n\t"
+ "subl $0xFFFF, %%eax \n\t"
+ "movzwl (%%"REG_b"), %%edx \n\t"
+ "bswap %%edx \n\t"
+ "shrl $15, %%edx \n\t"
+ "add $2, %%"REG_b" \n\t"
+ "addl %%edx, %%eax \n\t"
+ "mov %%"REG_b", "BYTE "(%1) \n\t"
+ "1: \n\t"
+ "movl %%eax, "LOW "(%1) \n\t"
+
+ :"+c"(val)
+ :"r"(c)
+ : "%eax", "%"REG_b, "%edx", "memory"
+ );
+ return val;
+#else
+ int range, mask;
+ c->low += c->low;
+
+ if(!(c->low & CABAC_MASK))
+ refill(c);
+
+ range= c->range<<(CABAC_BITS+1);
+ c->low -= range;
+ mask= c->low >> 31;
+ range &= mask;
+ c->low += range;
+ return (val^mask)-mask;
+#endif
+}
+
+//FIXME the x86 code from this file should be moved into i386/h264 or cabac something.c/h (note ill kill you if you move my code away from under my fingers before iam finished with it!)
+//FIXME use some macros to avoid duplicatin get_cabac (cant be done yet as that would make optimization work hard)
+#if defined(ARCH_X86) && defined(CONFIG_7REGS) && defined(CONFIG_EBX_AVAILABLE) && !( defined(ARCH_X86_64) && defined(PIC) )
+static int decode_significance_x86(CABACContext *c, int max_coeff, uint8_t *significant_coeff_ctx_base, int *index){
+ void *end= significant_coeff_ctx_base + max_coeff - 1;
+ int minusstart= -(int)significant_coeff_ctx_base;
+ int minusindex= 4-(int)index;
+ int coeff_count;
+ asm volatile(
+ "movl "RANGE "(%3), %%esi \n\t"
+ "movl "LOW "(%3), %%ebx \n\t"
+
+ "2: \n\t"
+
+ BRANCHLESS_GET_CABAC("%%edx", "%3", "(%1)", "%%ebx", "%%bx", "%%esi", "%%eax", "%%al")
+
+ "test $1, %%edx \n\t"
+ " jz 3f \n\t"
+
+ BRANCHLESS_GET_CABAC("%%edx", "%3", "61(%1)", "%%ebx", "%%bx", "%%esi", "%%eax", "%%al")
+
+ "mov %2, %%"REG_a" \n\t"
+ "movl %4, %%ecx \n\t"
+ "add %1, %%"REG_c" \n\t"
+ "movl %%ecx, (%%"REG_a") \n\t"
+
+ "test $1, %%edx \n\t"
+ " jnz 4f \n\t"
+
+ "add $4, %%"REG_a" \n\t"
+ "mov %%"REG_a", %2 \n\t"
+
+ "3: \n\t"
+ "add $1, %1 \n\t"
+ "cmp %5, %1 \n\t"
+ " jb 2b \n\t"
+ "mov %2, %%"REG_a" \n\t"
+ "movl %4, %%ecx \n\t"
+ "add %1, %%"REG_c" \n\t"
+ "movl %%ecx, (%%"REG_a") \n\t"
+ "4: \n\t"
+ "add %6, %%eax \n\t"
+ "shr $2, %%eax \n\t"
+
+ "movl %%esi, "RANGE "(%3) \n\t"
+ "movl %%ebx, "LOW "(%3) \n\t"
+ :"=&a"(coeff_count), "+r"(significant_coeff_ctx_base), "+m"(index)\
+ :"r"(c), "m"(minusstart), "m"(end), "m"(minusindex)\
+ : "%"REG_c, "%ebx", "%edx", "%esi", "memory"\
+ );
+ return coeff_count;
+}
+
+static int decode_significance_8x8_x86(CABACContext *c, uint8_t *significant_coeff_ctx_base, int *index, uint8_t *sig_off){
+ int minusindex= 4-(int)index;
+ int coeff_count;
+ long last=0;
+ asm volatile(
+ "movl "RANGE "(%3), %%esi \n\t"
+ "movl "LOW "(%3), %%ebx \n\t"
+
+ "mov %1, %%"REG_D" \n\t"
+ "2: \n\t"
+
+ "mov %6, %%"REG_a" \n\t"
+ "movzbl (%%"REG_a", %%"REG_D"), %%edi \n\t"
+ "add %5, %%"REG_D" \n\t"
+
+ BRANCHLESS_GET_CABAC("%%edx", "%3", "(%%"REG_D")", "%%ebx", "%%bx", "%%esi", "%%eax", "%%al")
+
+ "mov %1, %%edi \n\t"
+ "test $1, %%edx \n\t"
+ " jz 3f \n\t"
+
+ "movzbl "MANGLE(last_coeff_flag_offset_8x8)"(%%edi), %%edi\n\t"
+ "add %5, %%"REG_D" \n\t"
+
+ BRANCHLESS_GET_CABAC("%%edx", "%3", "15(%%"REG_D")", "%%ebx", "%%bx", "%%esi", "%%eax", "%%al")
+
+ "mov %2, %%"REG_a" \n\t"
+ "mov %1, %%edi \n\t"
+ "movl %%edi, (%%"REG_a") \n\t"
+
+ "test $1, %%edx \n\t"
+ " jnz 4f \n\t"
+
+ "add $4, %%"REG_a" \n\t"
+ "mov %%"REG_a", %2 \n\t"
+
+ "3: \n\t"
+ "addl $1, %%edi \n\t"
+ "mov %%edi, %1 \n\t"
+ "cmpl $63, %%edi \n\t"
+ " jb 2b \n\t"
+ "mov %2, %%"REG_a" \n\t"
+ "movl %%edi, (%%"REG_a") \n\t"
+ "4: \n\t"
+ "addl %4, %%eax \n\t"
+ "shr $2, %%eax \n\t"
+
+ "movl %%esi, "RANGE "(%3) \n\t"
+ "movl %%ebx, "LOW "(%3) \n\t"
+ :"=&a"(coeff_count),"+m"(last), "+m"(index)\
+ :"r"(c), "m"(minusindex), "m"(significant_coeff_ctx_base), "m"(sig_off)\
+ : "%"REG_c, "%ebx", "%edx", "%esi", "%"REG_D, "memory"\
+ );
+ return coeff_count;
+}
+#endif /* defined(ARCH_X86) && !(defined(PIC) && defined(__GNUC__)) */
+
+/**
+ *
+ * @return the number of bytes read or 0 if no end
+ */
+static int get_cabac_terminate(CABACContext *c){
+ c->range -= 2;
+ if(c->low < c->range<<(CABAC_BITS+1)){
+ renorm_cabac_decoder_once(c);
+ return 0;
+ }else{
+ return c->bytestream - c->bytestream_start;
+ }
+}
+
+/**
+ * get (truncated) unnary binarization.
+ */
+static int get_cabac_u(CABACContext *c, uint8_t * state, int max, int max_index, int truncated){
+ int i;
+
+ for(i=0; i<max; i++){
+ if(get_cabac(c, state)==0)
+ return i;
+
+ if(i< max_index) state++;
+ }
+
+ return truncated ? max : -1;
+}
+
+/**
+ * get unary exp golomb k-th order binarization.
+ */
+static int get_cabac_ueg(CABACContext *c, uint8_t * state, int max, int is_signed, int k, int max_index){
+ int i, v;
+ int m= 1<<k;
+
+ if(get_cabac(c, state)==0)
+ return 0;
+
+ if(0 < max_index) state++;
+
+ for(i=1; i<max; i++){
+ if(get_cabac(c, state)==0){
+ if(is_signed && get_cabac_bypass(c)){
+ return -i;
+ }else
+ return i;
+ }
+
+ if(i < max_index) state++;
+ }
+
+ while(get_cabac_bypass(c)){
+ i+= m;
+ m+= m;
+ }
+
+ v=0;
+ while(m>>=1){
+ v+= v + get_cabac_bypass(c);
+ }
+ i += v;
+
+ if(is_signed && get_cabac_bypass(c)){
+ return -i;
+ }else
+ return i;
+}
diff --git a/contrib/ffmpeg/libavcodec/cavs.c b/contrib/ffmpeg/libavcodec/cavs.c
new file mode 100644
index 000000000..4672635d7
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/cavs.c
@@ -0,0 +1,1540 @@
+/*
+ * Chinese AVS video (AVS1-P2, JiZhun profile) decoder.
+ * Copyright (c) 2006 Stefan Gehrer <stefan.gehrer@gmx.de>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have 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 cavs.c
+ * Chinese AVS video (AVS1-P2, JiZhun profile) decoder
+ * @author Stefan Gehrer <stefan.gehrer@gmx.de>
+ */
+
+#include "avcodec.h"
+#include "bitstream.h"
+#include "golomb.h"
+#include "mpegvideo.h"
+#include "cavsdata.h"
+
+#ifdef CONFIG_CAVS_DECODER
+typedef struct {
+ MpegEncContext s;
+ Picture picture; ///< currently decoded frame
+ Picture DPB[2]; ///< reference frames
+ int dist[2]; ///< temporal distances from current frame to ref frames
+ int profile, level;
+ int aspect_ratio;
+ int mb_width, mb_height;
+ int pic_type;
+ int progressive;
+ int pic_structure;
+ int skip_mode_flag; ///< select between skip_count or one skip_flag per MB
+ int loop_filter_disable;
+ int alpha_offset, beta_offset;
+ int ref_flag;
+ int mbx, mby; ///< macroblock coordinates
+ int flags; ///< availability flags of neighbouring macroblocks
+ int stc; ///< last start code
+ uint8_t *cy, *cu, *cv; ///< current MB sample pointers
+ int left_qp;
+ uint8_t *top_qp;
+
+ /** mv motion vector cache
+ 0: D3 B2 B3 C2
+ 4: A1 X0 X1 -
+ 8: A3 X2 X3 -
+
+ X are the vectors in the current macroblock (5,6,9,10)
+ A is the macroblock to the left (4,8)
+ B is the macroblock to the top (1,2)
+ C is the macroblock to the top-right (3)
+ D is the macroblock to the top-left (0)
+
+ the same is repeated for backward motion vectors */
+ vector_t mv[2*4*3];
+ vector_t *top_mv[2];
+ vector_t *col_mv;
+
+ /** luma pred mode cache
+ 0: -- B2 B3
+ 3: A1 X0 X1
+ 6: A3 X2 X3 */
+ int pred_mode_Y[3*3];
+ int *top_pred_Y;
+ int l_stride, c_stride;
+ int luma_scan[4];
+ int qp;
+ int qp_fixed;
+ int cbp;
+ ScanTable scantable;
+
+ /** intra prediction is done with un-deblocked samples
+ they are saved here before deblocking the MB */
+ uint8_t *top_border_y, *top_border_u, *top_border_v;
+ uint8_t left_border_y[26], left_border_u[10], left_border_v[10];
+ uint8_t intern_border_y[26];
+ uint8_t topleft_border_y, topleft_border_u, topleft_border_v;
+
+ void (*intra_pred_l[8])(uint8_t *d,uint8_t *top,uint8_t *left,int stride);
+ void (*intra_pred_c[7])(uint8_t *d,uint8_t *top,uint8_t *left,int stride);
+ uint8_t *col_type_base;
+ uint8_t *col_type;
+
+ /* scaling factors for MV prediction */
+ int sym_factor; ///< for scaling in symmetrical B block
+ int direct_den[2]; ///< for scaling in direct B block
+ int scale_den[2]; ///< for scaling neighbouring MVs
+
+ int got_keyframe;
+ DCTELEM *block;
+} AVSContext;
+
+/*****************************************************************************
+ *
+ * in-loop deblocking filter
+ *
+ ****************************************************************************/
+
+static inline int get_bs(vector_t *mvP, vector_t *mvQ, int b) {
+ if((mvP->ref == REF_INTRA) || (mvQ->ref == REF_INTRA))
+ return 2;
+ if( (abs(mvP->x - mvQ->x) >= 4) || (abs(mvP->y - mvQ->y) >= 4) )
+ return 1;
+ if(b){
+ mvP += MV_BWD_OFFS;
+ mvQ += MV_BWD_OFFS;
+ if( (abs(mvP->x - mvQ->x) >= 4) || (abs(mvP->y - mvQ->y) >= 4) )
+ return 1;
+ }else{
+ if(mvP->ref != mvQ->ref)
+ return 1;
+ }
+ return 0;
+}
+
+#define SET_PARAMS \
+ alpha = alpha_tab[av_clip(qp_avg + h->alpha_offset,0,63)]; \
+ beta = beta_tab[av_clip(qp_avg + h->beta_offset, 0,63)]; \
+ tc = tc_tab[av_clip(qp_avg + h->alpha_offset,0,63)];
+
+/**
+ * in-loop deblocking filter for a single macroblock
+ *
+ * boundary strength (bs) mapping:
+ *
+ * --4---5--
+ * 0 2 |
+ * | 6 | 7 |
+ * 1 3 |
+ * ---------
+ *
+ */
+static void filter_mb(AVSContext *h, enum mb_t mb_type) {
+ DECLARE_ALIGNED_8(uint8_t, bs[8]);
+ int qp_avg, alpha, beta, tc;
+ int i;
+
+ /* save un-deblocked lines */
+ h->topleft_border_y = h->top_border_y[h->mbx*16+15];
+ h->topleft_border_u = h->top_border_u[h->mbx*10+8];
+ h->topleft_border_v = h->top_border_v[h->mbx*10+8];
+ memcpy(&h->top_border_y[h->mbx*16], h->cy + 15* h->l_stride,16);
+ memcpy(&h->top_border_u[h->mbx*10+1], h->cu + 7* h->c_stride,8);
+ memcpy(&h->top_border_v[h->mbx*10+1], h->cv + 7* h->c_stride,8);
+ for(i=0;i<8;i++) {
+ h->left_border_y[i*2+1] = *(h->cy + 15 + (i*2+0)*h->l_stride);
+ h->left_border_y[i*2+2] = *(h->cy + 15 + (i*2+1)*h->l_stride);
+ h->left_border_u[i+1] = *(h->cu + 7 + i*h->c_stride);
+ h->left_border_v[i+1] = *(h->cv + 7 + i*h->c_stride);
+ }
+ if(!h->loop_filter_disable) {
+ /* determine bs */
+ if(mb_type == I_8X8)
+ *((uint64_t *)bs) = 0x0202020202020202ULL;
+ else{
+ *((uint64_t *)bs) = 0;
+ if(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);
+ }
+ if(partition_flags[mb_type] & SPLITH){
+ bs[6] = get_bs(&h->mv[MV_FWD_X0], &h->mv[MV_FWD_X2], mb_type > P_8X8);
+ bs[7] = get_bs(&h->mv[MV_FWD_X1], &h->mv[MV_FWD_X3], mb_type > P_8X8);
+ }
+ bs[0] = get_bs(&h->mv[MV_FWD_A1], &h->mv[MV_FWD_X0], mb_type > P_8X8);
+ bs[1] = get_bs(&h->mv[MV_FWD_A3], &h->mv[MV_FWD_X2], mb_type > P_8X8);
+ 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(h->flags & A_AVAIL) {
+ qp_avg = (h->qp + h->left_qp + 1) >> 1;
+ SET_PARAMS;
+ h->s.dsp.cavs_filter_lv(h->cy,h->l_stride,alpha,beta,tc,bs[0],bs[1]);
+ h->s.dsp.cavs_filter_cv(h->cu,h->c_stride,alpha,beta,tc,bs[0],bs[1]);
+ h->s.dsp.cavs_filter_cv(h->cv,h->c_stride,alpha,beta,tc,bs[0],bs[1]);
+ }
+ qp_avg = h->qp;
+ SET_PARAMS;
+ h->s.dsp.cavs_filter_lv(h->cy + 8,h->l_stride,alpha,beta,tc,bs[2],bs[3]);
+ h->s.dsp.cavs_filter_lh(h->cy + 8*h->l_stride,h->l_stride,alpha,beta,tc,
+ bs[6],bs[7]);
+
+ if(h->flags & B_AVAIL) {
+ qp_avg = (h->qp + h->top_qp[h->mbx] + 1) >> 1;
+ SET_PARAMS;
+ h->s.dsp.cavs_filter_lh(h->cy,h->l_stride,alpha,beta,tc,bs[4],bs[5]);
+ h->s.dsp.cavs_filter_ch(h->cu,h->c_stride,alpha,beta,tc,bs[4],bs[5]);
+ h->s.dsp.cavs_filter_ch(h->cv,h->c_stride,alpha,beta,tc,bs[4],bs[5]);
+ }
+ }
+ }
+ h->left_qp = h->qp;
+ h->top_qp[h->mbx] = h->qp;
+}
+
+#undef SET_PARAMS
+
+/*****************************************************************************
+ *
+ * spatial intra prediction
+ *
+ ****************************************************************************/
+
+static inline void load_intra_pred_luma(AVSContext *h, uint8_t *top,
+ uint8_t **left, int block) {
+ int i;
+
+ switch(block) {
+ case 0:
+ *left = h->left_border_y;
+ h->left_border_y[0] = h->left_border_y[1];
+ memset(&h->left_border_y[17],h->left_border_y[16],9);
+ memcpy(&top[1],&h->top_border_y[h->mbx*16],16);
+ top[17] = top[16];
+ top[0] = top[1];
+ if((h->flags & A_AVAIL) && (h->flags & B_AVAIL))
+ h->left_border_y[0] = top[0] = h->topleft_border_y;
+ break;
+ case 1:
+ *left = h->intern_border_y;
+ for(i=0;i<8;i++)
+ h->intern_border_y[i+1] = *(h->cy + 7 + i*h->l_stride);
+ memset(&h->intern_border_y[9],h->intern_border_y[8],9);
+ h->intern_border_y[0] = h->intern_border_y[1];
+ memcpy(&top[1],&h->top_border_y[h->mbx*16+8],8);
+ if(h->flags & C_AVAIL)
+ memcpy(&top[9],&h->top_border_y[(h->mbx + 1)*16],8);
+ else
+ memset(&top[9],top[8],9);
+ top[17] = top[16];
+ top[0] = top[1];
+ if(h->flags & B_AVAIL)
+ h->intern_border_y[0] = top[0] = h->top_border_y[h->mbx*16+7];
+ break;
+ case 2:
+ *left = &h->left_border_y[8];
+ memcpy(&top[1],h->cy + 7*h->l_stride,16);
+ top[17] = top[16];
+ top[0] = top[1];
+ if(h->flags & A_AVAIL)
+ top[0] = h->left_border_y[8];
+ break;
+ case 3:
+ *left = &h->intern_border_y[8];
+ for(i=0;i<8;i++)
+ h->intern_border_y[i+9] = *(h->cy + 7 + (i+8)*h->l_stride);
+ memset(&h->intern_border_y[17],h->intern_border_y[16],9);
+ memcpy(&top[0],h->cy + 7 + 7*h->l_stride,9);
+ memset(&top[9],top[8],9);
+ break;
+ }
+}
+
+static void intra_pred_vert(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
+ int y;
+ uint64_t a = unaligned64(&top[1]);
+ for(y=0;y<8;y++) {
+ *((uint64_t *)(d+y*stride)) = a;
+ }
+}
+
+static void intra_pred_horiz(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
+ int y;
+ uint64_t a;
+ for(y=0;y<8;y++) {
+ a = left[y+1] * 0x0101010101010101ULL;
+ *((uint64_t *)(d+y*stride)) = a;
+ }
+}
+
+static void intra_pred_dc_128(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
+ int y;
+ uint64_t a = 0x8080808080808080ULL;
+ for(y=0;y<8;y++)
+ *((uint64_t *)(d+y*stride)) = a;
+}
+
+static void intra_pred_plane(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
+ int x,y,ia;
+ int ih = 0;
+ int iv = 0;
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+
+ for(x=0; x<4; x++) {
+ ih += (x+1)*(top[5+x]-top[3-x]);
+ iv += (x+1)*(left[5+x]-left[3-x]);
+ }
+ ia = (top[8]+left[8])<<4;
+ ih = (17*ih+16)>>5;
+ iv = (17*iv+16)>>5;
+ for(y=0; y<8; y++)
+ for(x=0; x<8; x++)
+ d[y*stride+x] = cm[(ia+(x-3)*ih+(y-3)*iv+16)>>5];
+}
+
+#define LOWPASS(ARRAY,INDEX) \
+ (( ARRAY[(INDEX)-1] + 2*ARRAY[(INDEX)] + ARRAY[(INDEX)+1] + 2) >> 2)
+
+static void intra_pred_lp(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
+ int x,y;
+ for(y=0; y<8; y++)
+ for(x=0; x<8; x++)
+ d[y*stride+x] = (LOWPASS(top,x+1) + LOWPASS(left,y+1)) >> 1;
+}
+
+static void intra_pred_down_left(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
+ int x,y;
+ for(y=0; y<8; y++)
+ for(x=0; x<8; x++)
+ d[y*stride+x] = (LOWPASS(top,x+y+2) + LOWPASS(left,x+y+2)) >> 1;
+}
+
+static void intra_pred_down_right(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
+ int x,y;
+ for(y=0; y<8; y++)
+ for(x=0; x<8; x++)
+ if(x==y)
+ d[y*stride+x] = (left[1]+2*top[0]+top[1]+2)>>2;
+ else if(x>y)
+ d[y*stride+x] = LOWPASS(top,x-y);
+ else
+ d[y*stride+x] = LOWPASS(left,y-x);
+}
+
+static void intra_pred_lp_left(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
+ int x,y;
+ for(y=0; y<8; y++)
+ for(x=0; x<8; x++)
+ d[y*stride+x] = LOWPASS(left,y+1);
+}
+
+static void intra_pred_lp_top(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
+ int x,y;
+ for(y=0; y<8; y++)
+ for(x=0; x<8; x++)
+ d[y*stride+x] = LOWPASS(top,x+1);
+}
+
+#undef LOWPASS
+
+static inline void modify_pred(const int_fast8_t *mod_table, int *mode) {
+ *mode = mod_table[*mode];
+ if(*mode < 0) {
+ av_log(NULL, AV_LOG_ERROR, "Illegal intra prediction mode\n");
+ *mode = 0;
+ }
+}
+
+/*****************************************************************************
+ *
+ * motion compensation
+ *
+ ****************************************************************************/
+
+static inline void mc_dir_part(AVSContext *h,Picture *pic,int square,
+ int chroma_height,int delta,int list,uint8_t *dest_y,
+ uint8_t *dest_cb,uint8_t *dest_cr,int src_x_offset,
+ int src_y_offset,qpel_mc_func *qpix_op,
+ h264_chroma_mc_func chroma_op,vector_t *mv){
+ MpegEncContext * const s = &h->s;
+ const int mx= mv->x + src_x_offset*8;
+ const int my= mv->y + src_y_offset*8;
+ const int luma_xy= (mx&3) + ((my&3)<<2);
+ uint8_t * src_y = pic->data[0] + (mx>>2) + (my>>2)*h->l_stride;
+ uint8_t * src_cb= pic->data[1] + (mx>>3) + (my>>3)*h->c_stride;
+ uint8_t * src_cr= pic->data[2] + (mx>>3) + (my>>3)*h->c_stride;
+ int extra_width= 0; //(s->flags&CODEC_FLAG_EMU_EDGE) ? 0 : 16;
+ int extra_height= extra_width;
+ int emu=0;
+ const int full_mx= mx>>2;
+ const int full_my= my>>2;
+ const int pic_width = 16*h->mb_width;
+ const int pic_height = 16*h->mb_height;
+
+ if(!pic->data[0])
+ return;
+ if(mx&7) extra_width -= 3;
+ if(my&7) extra_height -= 3;
+
+ if( full_mx < 0-extra_width
+ || full_my < 0-extra_height
+ || full_mx + 16/*FIXME*/ > pic_width + extra_width
+ || full_my + 16/*FIXME*/ > pic_height + extra_height){
+ ff_emulated_edge_mc(s->edge_emu_buffer, src_y - 2 - 2*h->l_stride, h->l_stride,
+ 16+5, 16+5/*FIXME*/, full_mx-2, full_my-2, pic_width, pic_height);
+ src_y= s->edge_emu_buffer + 2 + 2*h->l_stride;
+ emu=1;
+ }
+
+ qpix_op[luma_xy](dest_y, src_y, h->l_stride); //FIXME try variable height perhaps?
+ if(!square){
+ qpix_op[luma_xy](dest_y + delta, src_y + delta, h->l_stride);
+ }
+
+ if(emu){
+ ff_emulated_edge_mc(s->edge_emu_buffer, src_cb, h->c_stride,
+ 9, 9/*FIXME*/, (mx>>3), (my>>3), pic_width>>1, pic_height>>1);
+ src_cb= s->edge_emu_buffer;
+ }
+ chroma_op(dest_cb, src_cb, h->c_stride, chroma_height, mx&7, my&7);
+
+ if(emu){
+ ff_emulated_edge_mc(s->edge_emu_buffer, src_cr, h->c_stride,
+ 9, 9/*FIXME*/, (mx>>3), (my>>3), pic_width>>1, pic_height>>1);
+ src_cr= s->edge_emu_buffer;
+ }
+ chroma_op(dest_cr, src_cr, h->c_stride, chroma_height, mx&7, my&7);
+}
+
+static inline void mc_part_std(AVSContext *h,int square,int chroma_height,int delta,
+ uint8_t *dest_y,uint8_t *dest_cb,uint8_t *dest_cr,
+ int x_offset, int y_offset,qpel_mc_func *qpix_put,
+ h264_chroma_mc_func chroma_put,qpel_mc_func *qpix_avg,
+ h264_chroma_mc_func chroma_avg, vector_t *mv){
+ qpel_mc_func *qpix_op= qpix_put;
+ h264_chroma_mc_func chroma_op= chroma_put;
+
+ dest_y += 2*x_offset + 2*y_offset*h->l_stride;
+ dest_cb += x_offset + y_offset*h->c_stride;
+ dest_cr += x_offset + y_offset*h->c_stride;
+ x_offset += 8*h->mbx;
+ y_offset += 8*h->mby;
+
+ if(mv->ref >= 0){
+ Picture *ref= &h->DPB[mv->ref];
+ mc_dir_part(h, ref, square, chroma_height, delta, 0,
+ dest_y, dest_cb, dest_cr, x_offset, y_offset,
+ qpix_op, chroma_op, mv);
+
+ qpix_op= qpix_avg;
+ chroma_op= chroma_avg;
+ }
+
+ if((mv+MV_BWD_OFFS)->ref >= 0){
+ Picture *ref= &h->DPB[0];
+ mc_dir_part(h, ref, square, chroma_height, delta, 1,
+ dest_y, dest_cb, dest_cr, x_offset, y_offset,
+ qpix_op, chroma_op, mv+MV_BWD_OFFS);
+ }
+}
+
+static void inter_pred(AVSContext *h, enum mb_t mb_type) {
+ if(partition_flags[mb_type] == 0){ // 16x16
+ mc_part_std(h, 1, 8, 0, h->cy, h->cu, h->cv, 0, 0,
+ h->s.dsp.put_cavs_qpel_pixels_tab[0],
+ h->s.dsp.put_h264_chroma_pixels_tab[0],
+ h->s.dsp.avg_cavs_qpel_pixels_tab[0],
+ h->s.dsp.avg_h264_chroma_pixels_tab[0],&h->mv[MV_FWD_X0]);
+ }else{
+ mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 0, 0,
+ h->s.dsp.put_cavs_qpel_pixels_tab[1],
+ h->s.dsp.put_h264_chroma_pixels_tab[1],
+ h->s.dsp.avg_cavs_qpel_pixels_tab[1],
+ h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X0]);
+ mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 4, 0,
+ h->s.dsp.put_cavs_qpel_pixels_tab[1],
+ h->s.dsp.put_h264_chroma_pixels_tab[1],
+ h->s.dsp.avg_cavs_qpel_pixels_tab[1],
+ h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X1]);
+ mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 0, 4,
+ h->s.dsp.put_cavs_qpel_pixels_tab[1],
+ h->s.dsp.put_h264_chroma_pixels_tab[1],
+ h->s.dsp.avg_cavs_qpel_pixels_tab[1],
+ h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X2]);
+ mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 4, 4,
+ h->s.dsp.put_cavs_qpel_pixels_tab[1],
+ h->s.dsp.put_h264_chroma_pixels_tab[1],
+ h->s.dsp.avg_cavs_qpel_pixels_tab[1],
+ h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X3]);
+ }
+ /* set intra prediction modes to default values */
+ 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;
+}
+
+/*****************************************************************************
+ *
+ * motion vector prediction
+ *
+ ****************************************************************************/
+
+static inline void set_mvs(vector_t *mv, enum block_t size) {
+ switch(size) {
+ case BLK_16X16:
+ mv[MV_STRIDE ] = mv[0];
+ mv[MV_STRIDE+1] = mv[0];
+ case BLK_16X8:
+ mv[1] = mv[0];
+ break;
+ case BLK_8X16:
+ mv[MV_STRIDE] = mv[0];
+ break;
+ }
+}
+
+static inline void store_mvs(AVSContext *h) {
+ h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + 0] = h->mv[MV_FWD_X0];
+ h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + 1] = h->mv[MV_FWD_X1];
+ h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + 2] = h->mv[MV_FWD_X2];
+ h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + 3] = h->mv[MV_FWD_X3];
+}
+
+static inline void scale_mv(AVSContext *h, int *d_x, int *d_y, vector_t *src, int distp) {
+ int den = h->scale_den[src->ref];
+
+ *d_x = (src->x*distp*den + 256 + (src->x>>31)) >> 9;
+ *d_y = (src->y*distp*den + 256 + (src->y>>31)) >> 9;
+}
+
+static inline void mv_pred_median(AVSContext *h, vector_t *mvP, vector_t *mvA, vector_t *mvB, vector_t *mvC) {
+ int ax, ay, bx, by, cx, cy;
+ int len_ab, len_bc, len_ca, len_mid;
+
+ /* scale candidates according to their temporal span */
+ scale_mv(h, &ax, &ay, mvA, mvP->dist);
+ scale_mv(h, &bx, &by, mvB, mvP->dist);
+ scale_mv(h, &cx, &cy, mvC, mvP->dist);
+ /* find the geometrical median of the three candidates */
+ len_ab = abs(ax - bx) + abs(ay - by);
+ len_bc = abs(bx - cx) + abs(by - cy);
+ len_ca = abs(cx - ax) + abs(cy - ay);
+ len_mid = mid_pred(len_ab, len_bc, len_ca);
+ if(len_mid == len_ab) {
+ mvP->x = cx;
+ mvP->y = cy;
+ } else if(len_mid == len_bc) {
+ mvP->x = ax;
+ mvP->y = ay;
+ } else {
+ mvP->x = bx;
+ mvP->y = by;
+ }
+}
+
+static inline void mv_pred_direct(AVSContext *h, vector_t *pmv_fw,
+ vector_t *col_mv) {
+ vector_t *pmv_bw = pmv_fw + MV_BWD_OFFS;
+ int den = h->direct_den[col_mv->ref];
+ int m = col_mv->x >> 31;
+
+ pmv_fw->dist = h->dist[1];
+ pmv_bw->dist = h->dist[0];
+ pmv_fw->ref = 1;
+ pmv_bw->ref = 0;
+ /* scale the co-located motion vector according to its temporal span */
+ pmv_fw->x = (((den+(den*col_mv->x*pmv_fw->dist^m)-m-1)>>14)^m)-m;
+ pmv_bw->x = m-(((den+(den*col_mv->x*pmv_bw->dist^m)-m-1)>>14)^m);
+ m = col_mv->y >> 31;
+ pmv_fw->y = (((den+(den*col_mv->y*pmv_fw->dist^m)-m-1)>>14)^m)-m;
+ pmv_bw->y = m-(((den+(den*col_mv->y*pmv_bw->dist^m)-m-1)>>14)^m);
+}
+
+static inline void mv_pred_sym(AVSContext *h, vector_t *src, enum block_t size) {
+ vector_t *dst = src + MV_BWD_OFFS;
+
+ /* backward mv is the scaled and negated forward mv */
+ dst->x = -((src->x * h->sym_factor + 256) >> 9);
+ dst->y = -((src->y * h->sym_factor + 256) >> 9);
+ dst->ref = 0;
+ dst->dist = h->dist[0];
+ set_mvs(dst, size);
+}
+
+static void mv_pred(AVSContext *h, enum mv_loc_t nP, enum mv_loc_t nC,
+ enum mv_pred_t mode, enum block_t size, int ref) {
+ vector_t *mvP = &h->mv[nP];
+ vector_t *mvA = &h->mv[nP-1];
+ vector_t *mvB = &h->mv[nP-4];
+ vector_t *mvC = &h->mv[nC];
+ const vector_t *mvP2 = NULL;
+
+ mvP->ref = ref;
+ mvP->dist = h->dist[mvP->ref];
+ if(mvC->ref == NOT_AVAIL)
+ mvC = &h->mv[nP-5]; // set to top-left (mvD)
+ if((mode == MV_PRED_PSKIP) &&
+ ((mvA->ref == NOT_AVAIL) || (mvB->ref == NOT_AVAIL) ||
+ ((mvA->x | mvA->y | mvA->ref) == 0) ||
+ ((mvB->x | mvB->y | mvB->ref) == 0) )) {
+ mvP2 = &un_mv;
+ /* if there is only one suitable candidate, take it */
+ } else if((mvA->ref >= 0) && (mvB->ref < 0) && (mvC->ref < 0)) {
+ mvP2= mvA;
+ } else if((mvA->ref < 0) && (mvB->ref >= 0) && (mvC->ref < 0)) {
+ mvP2= mvB;
+ } else if((mvA->ref < 0) && (mvB->ref < 0) && (mvC->ref >= 0)) {
+ mvP2= mvC;
+ } else if(mode == MV_PRED_LEFT && mvA->ref == ref){
+ mvP2= mvA;
+ } else if(mode == MV_PRED_TOP && mvB->ref == ref){
+ mvP2= mvB;
+ } else if(mode == MV_PRED_TOPRIGHT && mvC->ref == ref){
+ mvP2= mvC;
+ }
+ if(mvP2){
+ mvP->x = mvP2->x;
+ mvP->y = mvP2->y;
+ }else
+ mv_pred_median(h, mvP, mvA, mvB, mvC);
+
+ if(mode < MV_PRED_PSKIP) {
+ mvP->x += get_se_golomb(&h->s.gb);
+ mvP->y += get_se_golomb(&h->s.gb);
+ }
+ set_mvs(mvP,size);
+}
+
+/*****************************************************************************
+ *
+ * residual data decoding
+ *
+ ****************************************************************************/
+
+/** kth-order exponential golomb code */
+static inline int get_ue_code(GetBitContext *gb, int order) {
+ if(order) {
+ int ret = get_ue_golomb(gb) << order;
+ return ret + get_bits(gb,order);
+ }
+ return get_ue_golomb(gb);
+}
+
+/**
+ * decode coefficients from one 8x8 block, dequantize, inverse transform
+ * and add them to sample block
+ * @param r pointer to 2D VLC table
+ * @param esc_golomb_order escape codes are k-golomb with this order k
+ * @param qp quantizer
+ * @param dst location of sample block
+ * @param stride line stride in frame buffer
+ */
+static int decode_residual_block(AVSContext *h, GetBitContext *gb,
+ const residual_vlc_t *r, int esc_golomb_order,
+ int qp, uint8_t *dst, int stride) {
+ int i,pos = -1;
+ int level_code, esc_code, level, run, mask;
+ int level_buf[64];
+ int run_buf[64];
+ int dqm = dequant_mul[qp];
+ int dqs = dequant_shift[qp];
+ int dqa = 1 << (dqs - 1);
+ const uint8_t *scantab = h->scantable.permutated;
+ DCTELEM *block = h->block;
+
+ for(i=0;i<65;i++) {
+ level_code = get_ue_code(gb,r->golomb_order);
+ if(level_code >= ESCAPE_CODE) {
+ run = ((level_code - ESCAPE_CODE) >> 1) + 1;
+ esc_code = get_ue_code(gb,esc_golomb_order);
+ level = esc_code + (run > r->max_run ? 1 : r->level_add[run]);
+ while(level > r->inc_limit)
+ r++;
+ mask = -(level_code & 1);
+ level = (level^mask) - mask;
+ } else {
+ level = r->rltab[level_code][0];
+ if(!level) //end of block signal
+ break;
+ run = r->rltab[level_code][1];
+ r += r->rltab[level_code][2];
+ }
+ level_buf[i] = level;
+ run_buf[i] = run;
+ }
+ /* inverse scan and dequantization */
+ while(--i >= 0){
+ pos += run_buf[i];
+ if(pos > 63) {
+ av_log(h->s.avctx, AV_LOG_ERROR,
+ "position out of block bounds at pic %d MB(%d,%d)\n",
+ h->picture.poc, h->mbx, h->mby);
+ return -1;
+ }
+ block[scantab[pos]] = (level_buf[i]*dqm + dqa) >> dqs;
+ }
+ h->s.dsp.cavs_idct8_add(dst,block,stride);
+ return 0;
+}
+
+
+static inline void decode_residual_chroma(AVSContext *h) {
+ if(h->cbp & (1<<4))
+ decode_residual_block(h,&h->s.gb,chroma_2dvlc,0, chroma_qp[h->qp],
+ h->cu,h->c_stride);
+ if(h->cbp & (1<<5))
+ decode_residual_block(h,&h->s.gb,chroma_2dvlc,0, chroma_qp[h->qp],
+ h->cv,h->c_stride);
+}
+
+static inline int decode_residual_inter(AVSContext *h) {
+ int block;
+
+ /* get coded block pattern */
+ int cbp= get_ue_golomb(&h->s.gb);
+ if(cbp > 63){
+ av_log(h->s.avctx, AV_LOG_ERROR, "illegal inter cbp\n");
+ return -1;
+ }
+ h->cbp = cbp_tab[cbp][1];
+
+ /* get quantizer */
+ if(h->cbp && !h->qp_fixed)
+ h->qp = (h->qp + get_se_golomb(&h->s.gb)) & 63;
+ for(block=0;block<4;block++)
+ if(h->cbp & (1<<block))
+ decode_residual_block(h,&h->s.gb,inter_2dvlc,0,h->qp,
+ h->cy + h->luma_scan[block], h->l_stride);
+ decode_residual_chroma(h);
+
+ return 0;
+}
+
+/*****************************************************************************
+ *
+ * macroblock level
+ *
+ ****************************************************************************/
+
+/**
+ * initialise predictors for motion vectors and intra prediction
+ */
+static inline void init_mb(AVSContext *h) {
+ int i;
+
+ /* copy predictors from top line (MB B and C) into cache */
+ for(i=0;i<3;i++) {
+ h->mv[MV_FWD_B2+i] = h->top_mv[0][h->mbx*2+i];
+ h->mv[MV_BWD_B2+i] = h->top_mv[1][h->mbx*2+i];
+ }
+ h->pred_mode_Y[1] = h->top_pred_Y[h->mbx*2+0];
+ h->pred_mode_Y[2] = h->top_pred_Y[h->mbx*2+1];
+ /* clear top predictors if MB B is not available */
+ if(!(h->flags & B_AVAIL)) {
+ h->mv[MV_FWD_B2] = un_mv;
+ h->mv[MV_FWD_B3] = un_mv;
+ h->mv[MV_BWD_B2] = un_mv;
+ h->mv[MV_BWD_B3] = un_mv;
+ h->pred_mode_Y[1] = h->pred_mode_Y[2] = NOT_AVAIL;
+ h->flags &= ~(C_AVAIL|D_AVAIL);
+ } else if(h->mbx) {
+ h->flags |= D_AVAIL;
+ }
+ if(h->mbx == h->mb_width-1) //MB C not available
+ h->flags &= ~C_AVAIL;
+ /* clear top-right predictors if MB C is not available */
+ if(!(h->flags & C_AVAIL)) {
+ h->mv[MV_FWD_C2] = un_mv;
+ h->mv[MV_BWD_C2] = un_mv;
+ }
+ /* clear top-left predictors if MB D is not available */
+ if(!(h->flags & D_AVAIL)) {
+ h->mv[MV_FWD_D3] = un_mv;
+ h->mv[MV_BWD_D3] = un_mv;
+ }
+ /* set pointer for co-located macroblock type */
+ h->col_type = &h->col_type_base[h->mby*h->mb_width + h->mbx];
+}
+
+static inline void check_for_slice(AVSContext *h);
+
+/**
+ * save predictors for later macroblocks and increase
+ * macroblock address
+ * @returns 0 if end of frame is reached, 1 otherwise
+ */
+static inline int next_mb(AVSContext *h) {
+ int i;
+
+ h->flags |= A_AVAIL;
+ h->cy += 16;
+ h->cu += 8;
+ h->cv += 8;
+ /* copy mvs as predictors to the left */
+ for(i=0;i<=20;i+=4)
+ h->mv[i] = h->mv[i+2];
+ /* copy bottom mvs from cache to top line */
+ h->top_mv[0][h->mbx*2+0] = h->mv[MV_FWD_X2];
+ h->top_mv[0][h->mbx*2+1] = h->mv[MV_FWD_X3];
+ h->top_mv[1][h->mbx*2+0] = h->mv[MV_BWD_X2];
+ h->top_mv[1][h->mbx*2+1] = h->mv[MV_BWD_X3];
+ /* next MB address */
+ h->mbx++;
+ if(h->mbx == h->mb_width) { //new mb line
+ h->flags = B_AVAIL|C_AVAIL;
+ /* clear left pred_modes */
+ h->pred_mode_Y[3] = h->pred_mode_Y[6] = NOT_AVAIL;
+ /* clear left mv predictors */
+ for(i=0;i<=20;i+=4)
+ h->mv[i] = un_mv;
+ h->mbx = 0;
+ h->mby++;
+ /* re-calculate sample pointers */
+ h->cy = h->picture.data[0] + h->mby*16*h->l_stride;
+ h->cu = h->picture.data[1] + h->mby*8*h->c_stride;
+ h->cv = h->picture.data[2] + h->mby*8*h->c_stride;
+ if(h->mby == h->mb_height) { //frame end
+ return 0;
+ } else {
+ //check_for_slice(h);
+ }
+ }
+ return 1;
+}
+
+static int decode_mb_i(AVSContext *h, int cbp_code) {
+ GetBitContext *gb = &h->s.gb;
+ int block, pred_mode_uv;
+ uint8_t top[18];
+ uint8_t *left = NULL;
+ uint8_t *d;
+
+ init_mb(h);
+
+ /* get intra prediction modes from stream */
+ for(block=0;block<4;block++) {
+ int nA,nB,predpred;
+ int pos = scan3x3[block];
+
+ nA = h->pred_mode_Y[pos-1];
+ nB = h->pred_mode_Y[pos-3];
+ predpred = FFMIN(nA,nB);
+ if(predpred == NOT_AVAIL) // if either is not available
+ predpred = INTRA_L_LP;
+ if(!get_bits1(gb)){
+ int rem_mode= get_bits(gb, 2);
+ predpred = rem_mode + (rem_mode >= predpred);
+ }
+ h->pred_mode_Y[pos] = predpred;
+ }
+ pred_mode_uv = get_ue_golomb(gb);
+ if(pred_mode_uv > 6) {
+ av_log(h->s.avctx, AV_LOG_ERROR, "illegal intra chroma pred mode\n");
+ return -1;
+ }
+
+ /* save pred modes before they get modified */
+ h->pred_mode_Y[3] = h->pred_mode_Y[5];
+ h->pred_mode_Y[6] = h->pred_mode_Y[8];
+ h->top_pred_Y[h->mbx*2+0] = h->pred_mode_Y[7];
+ h->top_pred_Y[h->mbx*2+1] = h->pred_mode_Y[8];
+
+ /* modify pred modes according to availability of neighbour samples */
+ if(!(h->flags & A_AVAIL)) {
+ modify_pred(left_modifier_l, &h->pred_mode_Y[4] );
+ modify_pred(left_modifier_l, &h->pred_mode_Y[7] );
+ modify_pred(left_modifier_c, &pred_mode_uv );
+ }
+ if(!(h->flags & B_AVAIL)) {
+ modify_pred(top_modifier_l, &h->pred_mode_Y[4] );
+ modify_pred(top_modifier_l, &h->pred_mode_Y[5] );
+ modify_pred(top_modifier_c, &pred_mode_uv );
+ }
+
+ /* get coded block pattern */
+ if(h->pic_type == FF_I_TYPE)
+ cbp_code = get_ue_golomb(gb);
+ if(cbp_code > 63){
+ av_log(h->s.avctx, AV_LOG_ERROR, "illegal intra cbp\n");
+ return -1;
+ }
+ h->cbp = cbp_tab[cbp_code][0];
+ if(h->cbp && !h->qp_fixed)
+ h->qp = (h->qp + get_se_golomb(gb)) & 63; //qp_delta
+
+ /* luma intra prediction interleaved with residual decode/transform/add */
+ for(block=0;block<4;block++) {
+ d = h->cy + h->luma_scan[block];
+ load_intra_pred_luma(h, top, &left, block);
+ h->intra_pred_l[h->pred_mode_Y[scan3x3[block]]]
+ (d, top, left, h->l_stride);
+ if(h->cbp & (1<<block))
+ decode_residual_block(h,gb,intra_2dvlc,1,h->qp,d,h->l_stride);
+ }
+
+ /* chroma intra prediction */
+ /* extend borders by one pixel */
+ h->left_border_u[9] = h->left_border_u[8];
+ h->left_border_v[9] = h->left_border_v[8];
+ h->top_border_u[h->mbx*10+9] = h->top_border_u[h->mbx*10+8];
+ h->top_border_v[h->mbx*10+9] = h->top_border_v[h->mbx*10+8];
+ if(h->mbx && h->mby) {
+ h->top_border_u[h->mbx*10] = h->left_border_u[0] = h->topleft_border_u;
+ h->top_border_v[h->mbx*10] = h->left_border_v[0] = h->topleft_border_v;
+ } else {
+ h->left_border_u[0] = h->left_border_u[1];
+ h->left_border_v[0] = h->left_border_v[1];
+ h->top_border_u[h->mbx*10] = h->top_border_u[h->mbx*10+1];
+ h->top_border_v[h->mbx*10] = h->top_border_v[h->mbx*10+1];
+ }
+ h->intra_pred_c[pred_mode_uv](h->cu, &h->top_border_u[h->mbx*10],
+ h->left_border_u, h->c_stride);
+ h->intra_pred_c[pred_mode_uv](h->cv, &h->top_border_v[h->mbx*10],
+ h->left_border_v, h->c_stride);
+
+ decode_residual_chroma(h);
+ filter_mb(h,I_8X8);
+
+ /* mark motion vectors as intra */
+ h->mv[MV_FWD_X0] = intra_mv;
+ set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);
+ h->mv[MV_BWD_X0] = intra_mv;
+ set_mvs(&h->mv[MV_BWD_X0], BLK_16X16);
+ if(h->pic_type != FF_B_TYPE)
+ *h->col_type = I_8X8;
+
+ return 0;
+}
+
+static void decode_mb_p(AVSContext *h, enum mb_t mb_type) {
+ GetBitContext *gb = &h->s.gb;
+ int ref[4];
+
+ init_mb(h);
+ switch(mb_type) {
+ case P_SKIP:
+ mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_PSKIP, BLK_16X16, 0);
+ break;
+ case P_16X16:
+ ref[0] = h->ref_flag ? 0 : get_bits1(gb);
+ mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_MEDIAN, BLK_16X16,ref[0]);
+ break;
+ case P_16X8:
+ ref[0] = h->ref_flag ? 0 : get_bits1(gb);
+ ref[2] = h->ref_flag ? 0 : get_bits1(gb);
+ mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_TOP, BLK_16X8, ref[0]);
+ mv_pred(h, MV_FWD_X2, MV_FWD_A1, MV_PRED_LEFT, BLK_16X8, ref[2]);
+ break;
+ case P_8X16:
+ ref[0] = h->ref_flag ? 0 : get_bits1(gb);
+ ref[1] = h->ref_flag ? 0 : get_bits1(gb);
+ mv_pred(h, MV_FWD_X0, MV_FWD_B3, MV_PRED_LEFT, BLK_8X16, ref[0]);
+ mv_pred(h, MV_FWD_X1, MV_FWD_C2, MV_PRED_TOPRIGHT, BLK_8X16, ref[1]);
+ break;
+ case P_8X8:
+ ref[0] = h->ref_flag ? 0 : get_bits1(gb);
+ ref[1] = h->ref_flag ? 0 : get_bits1(gb);
+ ref[2] = h->ref_flag ? 0 : get_bits1(gb);
+ ref[3] = h->ref_flag ? 0 : get_bits1(gb);
+ mv_pred(h, MV_FWD_X0, MV_FWD_B3, MV_PRED_MEDIAN, BLK_8X8, ref[0]);
+ mv_pred(h, MV_FWD_X1, MV_FWD_C2, MV_PRED_MEDIAN, BLK_8X8, ref[1]);
+ mv_pred(h, MV_FWD_X2, MV_FWD_X1, MV_PRED_MEDIAN, BLK_8X8, ref[2]);
+ mv_pred(h, MV_FWD_X3, MV_FWD_X0, MV_PRED_MEDIAN, BLK_8X8, ref[3]);
+ }
+ inter_pred(h, mb_type);
+ store_mvs(h);
+ if(mb_type != P_SKIP)
+ decode_residual_inter(h);
+ filter_mb(h,mb_type);
+ *h->col_type = mb_type;
+}
+
+static void decode_mb_b(AVSContext *h, enum mb_t mb_type) {
+ int block;
+ enum sub_mb_t sub_type[4];
+ int flags;
+
+ init_mb(h);
+
+ /* reset all MVs */
+ h->mv[MV_FWD_X0] = dir_mv;
+ set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);
+ h->mv[MV_BWD_X0] = dir_mv;
+ set_mvs(&h->mv[MV_BWD_X0], BLK_16X16);
+ switch(mb_type) {
+ case B_SKIP:
+ case B_DIRECT:
+ if(!(*h->col_type)) {
+ /* intra MB at co-location, do in-plane prediction */
+ mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_BSKIP, BLK_16X16, 1);
+ mv_pred(h, MV_BWD_X0, MV_BWD_C2, MV_PRED_BSKIP, BLK_16X16, 0);
+ } else
+ /* direct prediction from co-located P MB, block-wise */
+ for(block=0;block<4;block++)
+ mv_pred_direct(h,&h->mv[mv_scan[block]],
+ &h->col_mv[(h->mby*h->mb_width+h->mbx)*4 + block]);
+ break;
+ case B_FWD_16X16:
+ mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_MEDIAN, BLK_16X16, 1);
+ break;
+ case B_SYM_16X16:
+ mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_MEDIAN, BLK_16X16, 1);
+ mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_16X16);
+ break;
+ case B_BWD_16X16:
+ mv_pred(h, MV_BWD_X0, MV_BWD_C2, MV_PRED_MEDIAN, BLK_16X16, 0);
+ break;
+ case B_8X8:
+ for(block=0;block<4;block++)
+ sub_type[block] = get_bits(&h->s.gb,2);
+ for(block=0;block<4;block++) {
+ switch(sub_type[block]) {
+ case B_SUB_DIRECT:
+ if(!(*h->col_type)) {
+ /* intra MB at co-location, do in-plane prediction */
+ mv_pred(h, mv_scan[block], mv_scan[block]-3,
+ MV_PRED_BSKIP, BLK_8X8, 1);
+ mv_pred(h, mv_scan[block]+MV_BWD_OFFS,
+ mv_scan[block]-3+MV_BWD_OFFS,
+ MV_PRED_BSKIP, BLK_8X8, 0);
+ } else
+ mv_pred_direct(h,&h->mv[mv_scan[block]],
+ &h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + block]);
+ break;
+ case B_SUB_FWD:
+ mv_pred(h, mv_scan[block], mv_scan[block]-3,
+ MV_PRED_MEDIAN, BLK_8X8, 1);
+ break;
+ case B_SUB_SYM:
+ mv_pred(h, mv_scan[block], mv_scan[block]-3,
+ MV_PRED_MEDIAN, BLK_8X8, 1);
+ mv_pred_sym(h, &h->mv[mv_scan[block]], BLK_8X8);
+ break;
+ }
+ }
+ for(block=0;block<4;block++) {
+ if(sub_type[block] == B_SUB_BWD)
+ mv_pred(h, mv_scan[block]+MV_BWD_OFFS,
+ mv_scan[block]+MV_BWD_OFFS-3,
+ MV_PRED_MEDIAN, BLK_8X8, 0);
+ }
+ break;
+ default:
+ assert((mb_type > B_SYM_16X16) && (mb_type < B_8X8));
+ flags = partition_flags[mb_type];
+ if(mb_type & 1) { /* 16x8 macroblock types */
+ if(flags & FWD0)
+ mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_TOP, BLK_16X8, 1);
+ if(flags & SYM0)
+ mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_16X8);
+ if(flags & FWD1)
+ mv_pred(h, MV_FWD_X2, MV_FWD_A1, MV_PRED_LEFT, BLK_16X8, 1);
+ if(flags & SYM1)
+ mv_pred_sym(h, &h->mv[MV_FWD_X2], BLK_16X8);
+ if(flags & BWD0)
+ mv_pred(h, MV_BWD_X0, MV_BWD_C2, MV_PRED_TOP, BLK_16X8, 0);
+ if(flags & BWD1)
+ mv_pred(h, MV_BWD_X2, MV_BWD_A1, MV_PRED_LEFT, BLK_16X8, 0);
+ } else { /* 8x16 macroblock types */
+ if(flags & FWD0)
+ mv_pred(h, MV_FWD_X0, MV_FWD_B3, MV_PRED_LEFT, BLK_8X16, 1);
+ if(flags & SYM0)
+ mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_8X16);
+ if(flags & FWD1)
+ mv_pred(h, MV_FWD_X1, MV_FWD_C2, MV_PRED_TOPRIGHT,BLK_8X16, 1);
+ if(flags & SYM1)
+ mv_pred_sym(h, &h->mv[MV_FWD_X1], BLK_8X16);
+ if(flags & BWD0)
+ mv_pred(h, MV_BWD_X0, MV_BWD_B3, MV_PRED_LEFT, BLK_8X16, 0);
+ if(flags & BWD1)
+ mv_pred(h, MV_BWD_X1, MV_BWD_C2, MV_PRED_TOPRIGHT,BLK_8X16, 0);
+ }
+ }
+ inter_pred(h, mb_type);
+ if(mb_type != B_SKIP)
+ decode_residual_inter(h);
+ filter_mb(h,mb_type);
+}
+
+/*****************************************************************************
+ *
+ * slice level
+ *
+ ****************************************************************************/
+
+static inline int decode_slice_header(AVSContext *h, GetBitContext *gb) {
+ if(h->stc > 0xAF)
+ av_log(h->s.avctx, AV_LOG_ERROR, "unexpected start code 0x%02x\n", h->stc);
+ h->mby = h->stc;
+ if((h->mby == 0) && (!h->qp_fixed)){
+ h->qp_fixed = get_bits1(gb);
+ h->qp = get_bits(gb,6);
+ }
+ /* inter frame or second slice can have weighting params */
+ if((h->pic_type != FF_I_TYPE) || (!h->pic_structure && h->mby >= h->mb_width/2))
+ if(get_bits1(gb)) { //slice_weighting_flag
+ av_log(h->s.avctx, AV_LOG_ERROR,
+ "weighted prediction not yet supported\n");
+ }
+ return 0;
+}
+
+static inline void check_for_slice(AVSContext *h) {
+ GetBitContext *gb = &h->s.gb;
+ int align;
+ align = (-get_bits_count(gb)) & 7;
+ if((show_bits_long(gb,24+align) & 0xFFFFFF) == 0x000001) {
+ get_bits_long(gb,24+align);
+ h->stc = get_bits(gb,8);
+ decode_slice_header(h,gb);
+ }
+}
+
+/*****************************************************************************
+ *
+ * frame level
+ *
+ ****************************************************************************/
+
+static void init_pic(AVSContext *h) {
+ int i;
+
+ /* clear some predictors */
+ for(i=0;i<=20;i+=4)
+ h->mv[i] = un_mv;
+ h->mv[MV_BWD_X0] = dir_mv;
+ set_mvs(&h->mv[MV_BWD_X0], BLK_16X16);
+ h->mv[MV_FWD_X0] = dir_mv;
+ set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);
+ h->pred_mode_Y[3] = h->pred_mode_Y[6] = NOT_AVAIL;
+ h->cy = h->picture.data[0];
+ h->cu = h->picture.data[1];
+ h->cv = h->picture.data[2];
+ h->l_stride = h->picture.linesize[0];
+ h->c_stride = h->picture.linesize[1];
+ h->luma_scan[2] = 8*h->l_stride;
+ h->luma_scan[3] = 8*h->l_stride+8;
+ h->mbx = h->mby = 0;
+ h->flags = 0;
+}
+
+static int decode_pic(AVSContext *h) {
+ MpegEncContext *s = &h->s;
+ int skip_count;
+ enum mb_t mb_type;
+
+ if (!s->context_initialized) {
+ s->avctx->idct_algo = FF_IDCT_CAVS;
+ if (MPV_common_init(s) < 0)
+ return -1;
+ ff_init_scantable(s->dsp.idct_permutation,&h->scantable,ff_zigzag_direct);
+ }
+ get_bits(&s->gb,16);//bbv_dwlay
+ if(h->stc == PIC_PB_START_CODE) {
+ h->pic_type = get_bits(&s->gb,2) + FF_I_TYPE;
+ if(h->pic_type > FF_B_TYPE) {
+ av_log(s->avctx, AV_LOG_ERROR, "illegal picture type\n");
+ return -1;
+ }
+ /* make sure we have the reference frames we need */
+ if(!h->DPB[0].data[0] ||
+ (!h->DPB[1].data[0] && h->pic_type == FF_B_TYPE))
+ return -1;
+ } else {
+ h->pic_type = FF_I_TYPE;
+ if(get_bits1(&s->gb))
+ get_bits(&s->gb,16);//time_code
+ }
+ /* release last B frame */
+ if(h->picture.data[0])
+ s->avctx->release_buffer(s->avctx, (AVFrame *)&h->picture);
+
+ s->avctx->get_buffer(s->avctx, (AVFrame *)&h->picture);
+ init_pic(h);
+ h->picture.poc = get_bits(&s->gb,8)*2;
+
+ /* get temporal distances and MV scaling factors */
+ if(h->pic_type != FF_B_TYPE) {
+ h->dist[0] = (h->picture.poc - h->DPB[0].poc + 512) % 512;
+ } else {
+ h->dist[0] = (h->DPB[0].poc - h->picture.poc + 512) % 512;
+ }
+ h->dist[1] = (h->picture.poc - h->DPB[1].poc + 512) % 512;
+ h->scale_den[0] = h->dist[0] ? 512/h->dist[0] : 0;
+ h->scale_den[1] = h->dist[1] ? 512/h->dist[1] : 0;
+ if(h->pic_type == FF_B_TYPE) {
+ h->sym_factor = h->dist[0]*h->scale_den[1];
+ } else {
+ h->direct_den[0] = h->dist[0] ? 16384/h->dist[0] : 0;
+ h->direct_den[1] = h->dist[1] ? 16384/h->dist[1] : 0;
+ }
+
+ if(s->low_delay)
+ get_ue_golomb(&s->gb); //bbv_check_times
+ h->progressive = get_bits1(&s->gb);
+ if(h->progressive)
+ h->pic_structure = 1;
+ else if(!(h->pic_structure = get_bits1(&s->gb) && (h->stc == PIC_PB_START_CODE)) )
+ get_bits1(&s->gb); //advanced_pred_mode_disable
+ skip_bits1(&s->gb); //top_field_first
+ skip_bits1(&s->gb); //repeat_first_field
+ h->qp_fixed = get_bits1(&s->gb);
+ h->qp = get_bits(&s->gb,6);
+ if(h->pic_type == FF_I_TYPE) {
+ if(!h->progressive && !h->pic_structure)
+ skip_bits1(&s->gb);//what is this?
+ skip_bits(&s->gb,4); //reserved bits
+ } else {
+ if(!(h->pic_type == FF_B_TYPE && h->pic_structure == 1))
+ h->ref_flag = get_bits1(&s->gb);
+ skip_bits(&s->gb,4); //reserved bits
+ h->skip_mode_flag = get_bits1(&s->gb);
+ }
+ h->loop_filter_disable = get_bits1(&s->gb);
+ if(!h->loop_filter_disable && get_bits1(&s->gb)) {
+ h->alpha_offset = get_se_golomb(&s->gb);
+ h->beta_offset = get_se_golomb(&s->gb);
+ } else {
+ h->alpha_offset = h->beta_offset = 0;
+ }
+ check_for_slice(h);
+ if(h->pic_type == FF_I_TYPE) {
+ do {
+ decode_mb_i(h, 0);
+ } while(next_mb(h));
+ } else if(h->pic_type == FF_P_TYPE) {
+ do {
+ if(h->skip_mode_flag) {
+ skip_count = get_ue_golomb(&s->gb);
+ while(skip_count--) {
+ decode_mb_p(h,P_SKIP);
+ if(!next_mb(h))
+ goto done;
+ }
+ mb_type = get_ue_golomb(&s->gb) + P_16X16;
+ } else
+ mb_type = get_ue_golomb(&s->gb) + P_SKIP;
+ if(mb_type > P_8X8) {
+ decode_mb_i(h, mb_type - P_8X8 - 1);
+ } else
+ decode_mb_p(h,mb_type);
+ } while(next_mb(h));
+ } else { /* FF_B_TYPE */
+ do {
+ if(h->skip_mode_flag) {
+ skip_count = get_ue_golomb(&s->gb);
+ while(skip_count--) {
+ decode_mb_b(h,B_SKIP);
+ if(!next_mb(h))
+ goto done;
+ }
+ mb_type = get_ue_golomb(&s->gb) + B_DIRECT;
+ } else
+ mb_type = get_ue_golomb(&s->gb) + B_SKIP;
+ if(mb_type > B_8X8) {
+ decode_mb_i(h, mb_type - B_8X8 - 1);
+ } else
+ decode_mb_b(h,mb_type);
+ } while(next_mb(h));
+ }
+ done:
+ if(h->pic_type != FF_B_TYPE) {
+ if(h->DPB[1].data[0])
+ s->avctx->release_buffer(s->avctx, (AVFrame *)&h->DPB[1]);
+ memcpy(&h->DPB[1], &h->DPB[0], sizeof(Picture));
+ memcpy(&h->DPB[0], &h->picture, sizeof(Picture));
+ memset(&h->picture,0,sizeof(Picture));
+ }
+ return 0;
+}
+
+/*****************************************************************************
+ *
+ * headers and interface
+ *
+ ****************************************************************************/
+
+/**
+ * some predictions require data from the top-neighbouring macroblock.
+ * this data has to be stored for one complete row of macroblocks
+ * and this storage space is allocated here
+ */
+static void init_top_lines(AVSContext *h) {
+ /* alloc top line of predictors */
+ h->top_qp = av_malloc( h->mb_width);
+ h->top_mv[0] = av_malloc((h->mb_width*2+1)*sizeof(vector_t));
+ h->top_mv[1] = av_malloc((h->mb_width*2+1)*sizeof(vector_t));
+ h->top_pred_Y = av_malloc( h->mb_width*2*sizeof(*h->top_pred_Y));
+ h->top_border_y = av_malloc((h->mb_width+1)*16);
+ h->top_border_u = av_malloc((h->mb_width)*10);
+ h->top_border_v = av_malloc((h->mb_width)*10);
+
+ /* alloc space for co-located MVs and types */
+ h->col_mv = av_malloc( h->mb_width*h->mb_height*4*sizeof(vector_t));
+ h->col_type_base = av_malloc(h->mb_width*h->mb_height);
+ h->block = av_mallocz(64*sizeof(DCTELEM));
+}
+
+static int decode_seq_header(AVSContext *h) {
+ MpegEncContext *s = &h->s;
+ extern const AVRational ff_frame_rate_tab[];
+ int frame_rate_code;
+
+ h->profile = get_bits(&s->gb,8);
+ h->level = get_bits(&s->gb,8);
+ skip_bits1(&s->gb); //progressive sequence
+ s->width = get_bits(&s->gb,14);
+ s->height = get_bits(&s->gb,14);
+ skip_bits(&s->gb,2); //chroma format
+ skip_bits(&s->gb,3); //sample_precision
+ h->aspect_ratio = get_bits(&s->gb,4);
+ frame_rate_code = get_bits(&s->gb,4);
+ skip_bits(&s->gb,18);//bit_rate_lower
+ skip_bits1(&s->gb); //marker_bit
+ skip_bits(&s->gb,12);//bit_rate_upper
+ s->low_delay = get_bits1(&s->gb);
+ h->mb_width = (s->width + 15) >> 4;
+ h->mb_height = (s->height + 15) >> 4;
+ h->s.avctx->time_base.den = ff_frame_rate_tab[frame_rate_code].num;
+ h->s.avctx->time_base.num = ff_frame_rate_tab[frame_rate_code].den;
+ h->s.avctx->width = s->width;
+ h->s.avctx->height = s->height;
+ if(!h->top_qp)
+ init_top_lines(h);
+ return 0;
+}
+
+static void cavs_flush(AVCodecContext * avctx) {
+ AVSContext *h = avctx->priv_data;
+ h->got_keyframe = 0;
+}
+
+static int cavs_decode_frame(AVCodecContext * avctx,void *data, int *data_size,
+ uint8_t * buf, int buf_size) {
+ AVSContext *h = avctx->priv_data;
+ MpegEncContext *s = &h->s;
+ int input_size;
+ const uint8_t *buf_end;
+ const uint8_t *buf_ptr;
+ AVFrame *picture = data;
+ uint32_t stc;
+
+ s->avctx = avctx;
+
+ if (buf_size == 0) {
+ if(!s->low_delay && h->DPB[0].data[0]) {
+ *data_size = sizeof(AVPicture);
+ *picture = *(AVFrame *) &h->DPB[0];
+ }
+ return 0;
+ }
+
+ buf_ptr = buf;
+ buf_end = buf + buf_size;
+ for(;;) {
+ buf_ptr = ff_find_start_code(buf_ptr,buf_end, &stc);
+ if(stc & 0xFFFFFE00)
+ return FFMAX(0, buf_ptr - buf - s->parse_context.last_index);
+ input_size = (buf_end - buf_ptr)*8;
+ switch(stc) {
+ case SEQ_START_CODE:
+ init_get_bits(&s->gb, buf_ptr, input_size);
+ decode_seq_header(h);
+ break;
+ case PIC_I_START_CODE:
+ if(!h->got_keyframe) {
+ if(h->DPB[0].data[0])
+ avctx->release_buffer(avctx, (AVFrame *)&h->DPB[0]);
+ if(h->DPB[1].data[0])
+ avctx->release_buffer(avctx, (AVFrame *)&h->DPB[1]);
+ h->got_keyframe = 1;
+ }
+ case PIC_PB_START_CODE:
+ *data_size = 0;
+ if(!h->got_keyframe)
+ break;
+ init_get_bits(&s->gb, buf_ptr, input_size);
+ h->stc = stc;
+ if(decode_pic(h))
+ break;
+ *data_size = sizeof(AVPicture);
+ if(h->pic_type != FF_B_TYPE) {
+ if(h->DPB[1].data[0]) {
+ *picture = *(AVFrame *) &h->DPB[1];
+ } else {
+ *data_size = 0;
+ }
+ } else
+ *picture = *(AVFrame *) &h->picture;
+ break;
+ case EXT_START_CODE:
+ //mpeg_decode_extension(avctx,buf_ptr, input_size);
+ break;
+ case USER_START_CODE:
+ //mpeg_decode_user_data(avctx,buf_ptr, input_size);
+ break;
+ default:
+ if (stc >= SLICE_MIN_START_CODE &&
+ stc <= SLICE_MAX_START_CODE) {
+ init_get_bits(&s->gb, buf_ptr, input_size);
+ decode_slice_header(h, &s->gb);
+ }
+ break;
+ }
+ }
+}
+
+static int cavs_decode_init(AVCodecContext * avctx) {
+ AVSContext *h = avctx->priv_data;
+ MpegEncContext * const s = &h->s;
+
+ MPV_decode_defaults(s);
+ s->avctx = avctx;
+
+ avctx->pix_fmt= PIX_FMT_YUV420P;
+
+ h->luma_scan[0] = 0;
+ h->luma_scan[1] = 8;
+ h->intra_pred_l[ INTRA_L_VERT] = intra_pred_vert;
+ h->intra_pred_l[ INTRA_L_HORIZ] = intra_pred_horiz;
+ h->intra_pred_l[ INTRA_L_LP] = intra_pred_lp;
+ h->intra_pred_l[ INTRA_L_DOWN_LEFT] = intra_pred_down_left;
+ h->intra_pred_l[INTRA_L_DOWN_RIGHT] = intra_pred_down_right;
+ h->intra_pred_l[ INTRA_L_LP_LEFT] = intra_pred_lp_left;
+ h->intra_pred_l[ INTRA_L_LP_TOP] = intra_pred_lp_top;
+ h->intra_pred_l[ INTRA_L_DC_128] = intra_pred_dc_128;
+ h->intra_pred_c[ INTRA_C_LP] = intra_pred_lp;
+ h->intra_pred_c[ INTRA_C_HORIZ] = intra_pred_horiz;
+ h->intra_pred_c[ INTRA_C_VERT] = intra_pred_vert;
+ h->intra_pred_c[ INTRA_C_PLANE] = intra_pred_plane;
+ h->intra_pred_c[ INTRA_C_LP_LEFT] = intra_pred_lp_left;
+ h->intra_pred_c[ INTRA_C_LP_TOP] = intra_pred_lp_top;
+ h->intra_pred_c[ INTRA_C_DC_128] = intra_pred_dc_128;
+ h->mv[ 7] = un_mv;
+ h->mv[19] = un_mv;
+ return 0;
+}
+
+static int cavs_decode_end(AVCodecContext * avctx) {
+ AVSContext *h = avctx->priv_data;
+
+ av_free(h->top_qp);
+ av_free(h->top_mv[0]);
+ av_free(h->top_mv[1]);
+ av_free(h->top_pred_Y);
+ av_free(h->top_border_y);
+ av_free(h->top_border_u);
+ av_free(h->top_border_v);
+ av_free(h->col_mv);
+ av_free(h->col_type_base);
+ av_free(h->block);
+ return 0;
+}
+
+AVCodec cavs_decoder = {
+ "cavs",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_CAVS,
+ sizeof(AVSContext),
+ cavs_decode_init,
+ NULL,
+ cavs_decode_end,
+ cavs_decode_frame,
+ CODEC_CAP_DR1 | CODEC_CAP_DELAY,
+ .flush= cavs_flush,
+};
+#endif /* CONFIG_CAVS_DECODER */
+
+#ifdef CONFIG_CAVSVIDEO_PARSER
+/**
+ * finds the end of the current frame in the bitstream.
+ * @return the position of the first byte of the next frame, or -1
+ */
+static int cavs_find_frame_end(ParseContext *pc, const uint8_t *buf,
+ int buf_size) {
+ int pic_found, i;
+ uint32_t state;
+
+ pic_found= pc->frame_start_found;
+ state= pc->state;
+
+ i=0;
+ if(!pic_found){
+ for(i=0; i<buf_size; i++){
+ state= (state<<8) | buf[i];
+ if(state == PIC_I_START_CODE || state == PIC_PB_START_CODE){
+ i++;
+ pic_found=1;
+ break;
+ }
+ }
+ }
+
+ if(pic_found){
+ /* EOF considered as end of frame */
+ if (buf_size == 0)
+ return 0;
+ for(; i<buf_size; i++){
+ state= (state<<8) | buf[i];
+ if((state&0xFFFFFF00) == 0x100){
+ if(state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE){
+ pc->frame_start_found=0;
+ pc->state=-1;
+ return i-3;
+ }
+ }
+ }
+ }
+ pc->frame_start_found= pic_found;
+ pc->state= state;
+ return END_NOT_FOUND;
+}
+
+static int cavsvideo_parse(AVCodecParserContext *s,
+ AVCodecContext *avctx,
+ uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size)
+{
+ ParseContext *pc = s->priv_data;
+ int next;
+
+ if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){
+ next= buf_size;
+ }else{
+ next= cavs_find_frame_end(pc, buf, buf_size);
+
+ if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
+ *poutbuf = NULL;
+ *poutbuf_size = 0;
+ return buf_size;
+ }
+ }
+ *poutbuf = (uint8_t *)buf;
+ *poutbuf_size = buf_size;
+ return next;
+}
+
+AVCodecParser cavsvideo_parser = {
+ { CODEC_ID_CAVS },
+ sizeof(ParseContext1),
+ NULL,
+ cavsvideo_parse,
+ ff_parse1_close,
+ ff_mpeg4video_split,
+};
+#endif /* CONFIG_CAVSVIDEO_PARSER */
diff --git a/src/libffmpeg/libavcodec/cavsdata.h b/contrib/ffmpeg/libavcodec/cavsdata.h
index d76985136..d76985136 100644
--- a/src/libffmpeg/libavcodec/cavsdata.h
+++ b/contrib/ffmpeg/libavcodec/cavsdata.h
diff --git a/contrib/ffmpeg/libavcodec/cavsdsp.c b/contrib/ffmpeg/libavcodec/cavsdsp.c
new file mode 100644
index 000000000..55ecaae0a
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/cavsdsp.c
@@ -0,0 +1,546 @@
+/*
+ * Chinese AVS video (AVS1-P2, JiZhun profile) decoder.
+ *
+ * DSP functions
+ *
+ * Copyright (c) 2006 Stefan Gehrer <stefan.gehrer@gmx.de>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have 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
+ */
+
+#include <stdio.h>
+#include "dsputil.h"
+
+/*****************************************************************************
+ *
+ * in-loop deblocking filter
+ *
+ ****************************************************************************/
+
+#define P2 p0_p[-3*stride]
+#define P1 p0_p[-2*stride]
+#define P0 p0_p[-1*stride]
+#define Q0 p0_p[ 0*stride]
+#define Q1 p0_p[ 1*stride]
+#define Q2 p0_p[ 2*stride]
+
+static inline void loop_filter_l2(uint8_t *p0_p,int stride,int alpha, int beta) {
+ int p0 = P0;
+ int q0 = Q0;
+
+ if(abs(p0-q0)<alpha && abs(P1-p0)<beta && abs(Q1-q0)<beta) {
+ int s = p0 + q0 + 2;
+ alpha = (alpha>>2) + 2;
+ if(abs(P2-p0) < beta && abs(p0-q0) < alpha) {
+ P0 = (P1 + p0 + s) >> 2;
+ P1 = (2*P1 + s) >> 2;
+ } else
+ P0 = (2*P1 + s) >> 2;
+ if(abs(Q2-q0) < beta && abs(q0-p0) < alpha) {
+ Q0 = (Q1 + q0 + s) >> 2;
+ Q1 = (2*Q1 + s) >> 2;
+ } else
+ Q0 = (2*Q1 + s) >> 2;
+ }
+}
+
+static inline void loop_filter_l1(uint8_t *p0_p, int stride, int alpha, int beta, int tc) {
+ int p0 = P0;
+ int q0 = Q0;
+
+ if(abs(p0-q0)<alpha && abs(P1-p0)<beta && abs(Q1-q0)<beta) {
+ int delta = av_clip(((q0-p0)*3+P1-Q1+4)>>3,-tc, tc);
+ P0 = av_clip_uint8(p0+delta);
+ Q0 = av_clip_uint8(q0-delta);
+ if(abs(P2-p0)<beta) {
+ delta = av_clip(((P0-P1)*3+P2-Q0+4)>>3, -tc, tc);
+ P1 = av_clip_uint8(P1+delta);
+ }
+ if(abs(Q2-q0)<beta) {
+ delta = av_clip(((Q1-Q0)*3+P0-Q2+4)>>3, -tc, tc);
+ Q1 = av_clip_uint8(Q1-delta);
+ }
+ }
+}
+
+static inline void loop_filter_c2(uint8_t *p0_p,int stride,int alpha, int beta) {
+ int p0 = P0;
+ int q0 = Q0;
+
+ if(abs(p0-q0)<alpha && abs(P1-p0)<beta && abs(Q1-q0)<beta) {
+ int s = p0 + q0 + 2;
+ alpha = (alpha>>2) + 2;
+ if(abs(P2-p0) < beta && abs(p0-q0) < alpha) {
+ P0 = (P1 + p0 + s) >> 2;
+ } else
+ P0 = (2*P1 + s) >> 2;
+ if(abs(Q2-q0) < beta && abs(q0-p0) < alpha) {
+ Q0 = (Q1 + q0 + s) >> 2;
+ } else
+ Q0 = (2*Q1 + s) >> 2;
+ }
+}
+
+static inline void loop_filter_c1(uint8_t *p0_p,int stride,int alpha, int beta,
+ int tc) {
+ if(abs(P0-Q0)<alpha && abs(P1-P0)<beta && abs(Q1-Q0)<beta) {
+ int delta = av_clip(((Q0-P0)*3+P1-Q1+4)>>3, -tc, tc);
+ P0 = av_clip_uint8(P0+delta);
+ Q0 = av_clip_uint8(Q0-delta);
+ }
+}
+
+#undef P0
+#undef P1
+#undef P2
+#undef Q0
+#undef Q1
+#undef Q2
+
+static void cavs_filter_lv_c(uint8_t *d, int stride, int alpha, int beta, int tc,
+ int bs1, int bs2) {
+ int i;
+ if(bs1==2)
+ for(i=0;i<16;i++)
+ loop_filter_l2(d + i*stride,1,alpha,beta);
+ else {
+ if(bs1)
+ for(i=0;i<8;i++)
+ loop_filter_l1(d + i*stride,1,alpha,beta,tc);
+ if (bs2)
+ for(i=8;i<16;i++)
+ loop_filter_l1(d + i*stride,1,alpha,beta,tc);
+ }
+}
+
+static void cavs_filter_lh_c(uint8_t *d, int stride, int alpha, int beta, int tc,
+ int bs1, int bs2) {
+ int i;
+ if(bs1==2)
+ for(i=0;i<16;i++)
+ loop_filter_l2(d + i,stride,alpha,beta);
+ else {
+ if(bs1)
+ for(i=0;i<8;i++)
+ loop_filter_l1(d + i,stride,alpha,beta,tc);
+ if (bs2)
+ for(i=8;i<16;i++)
+ loop_filter_l1(d + i,stride,alpha,beta,tc);
+ }
+}
+
+static void cavs_filter_cv_c(uint8_t *d, int stride, int alpha, int beta, int tc,
+ int bs1, int bs2) {
+ int i;
+ if(bs1==2)
+ for(i=0;i<8;i++)
+ loop_filter_c2(d + i*stride,1,alpha,beta);
+ else {
+ if(bs1)
+ for(i=0;i<4;i++)
+ loop_filter_c1(d + i*stride,1,alpha,beta,tc);
+ if (bs2)
+ for(i=4;i<8;i++)
+ loop_filter_c1(d + i*stride,1,alpha,beta,tc);
+ }
+}
+
+static void cavs_filter_ch_c(uint8_t *d, int stride, int alpha, int beta, int tc,
+ int bs1, int bs2) {
+ int i;
+ if(bs1==2)
+ for(i=0;i<8;i++)
+ loop_filter_c2(d + i,stride,alpha,beta);
+ else {
+ if(bs1)
+ for(i=0;i<4;i++)
+ loop_filter_c1(d + i,stride,alpha,beta,tc);
+ if (bs2)
+ for(i=4;i<8;i++)
+ loop_filter_c1(d + i,stride,alpha,beta,tc);
+ }
+}
+
+/*****************************************************************************
+ *
+ * inverse transform
+ *
+ ****************************************************************************/
+
+static void cavs_idct8_add_c(uint8_t *dst, DCTELEM *block, int stride) {
+ int i;
+ DCTELEM (*src)[8] = (DCTELEM(*)[8])block;
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+
+ src[0][0] += 8;
+
+ for( i = 0; i < 8; i++ ) {
+ const int a0 = 3*src[i][1] - (src[i][7]<<1);
+ const int a1 = 3*src[i][3] + (src[i][5]<<1);
+ const int a2 = (src[i][3]<<1) - 3*src[i][5];
+ const int a3 = (src[i][1]<<1) + 3*src[i][7];
+
+ const int b4 = ((a0 + a1 + a3)<<1) + a1;
+ const int b5 = ((a0 - a1 + a2)<<1) + a0;
+ const int b6 = ((a3 - a2 - a1)<<1) + a3;
+ const int b7 = ((a0 - a2 - a3)<<1) - a2;
+
+ const int a7 = (src[i][2]<<2) - 10*src[i][6];
+ const int a6 = (src[i][6]<<2) + 10*src[i][2];
+ const int a5 = ((src[i][0] - src[i][4]) << 3) + 4;
+ const int a4 = ((src[i][0] + src[i][4]) << 3) + 4;
+
+ const int b0 = a4 + a6;
+ const int b1 = a5 + a7;
+ const int b2 = a5 - a7;
+ const int b3 = a4 - a6;
+
+ src[i][0] = (b0 + b4) >> 3;
+ src[i][1] = (b1 + b5) >> 3;
+ src[i][2] = (b2 + b6) >> 3;
+ src[i][3] = (b3 + b7) >> 3;
+ src[i][4] = (b3 - b7) >> 3;
+ src[i][5] = (b2 - b6) >> 3;
+ src[i][6] = (b1 - b5) >> 3;
+ src[i][7] = (b0 - b4) >> 3;
+ }
+ for( i = 0; i < 8; i++ ) {
+ const int a0 = 3*src[1][i] - (src[7][i]<<1);
+ const int a1 = 3*src[3][i] + (src[5][i]<<1);
+ const int a2 = (src[3][i]<<1) - 3*src[5][i];
+ const int a3 = (src[1][i]<<1) + 3*src[7][i];
+
+ const int b4 = ((a0 + a1 + a3)<<1) + a1;
+ const int b5 = ((a0 - a1 + a2)<<1) + a0;
+ const int b6 = ((a3 - a2 - a1)<<1) + a3;
+ const int b7 = ((a0 - a2 - a3)<<1) - a2;
+
+ const int a7 = (src[2][i]<<2) - 10*src[6][i];
+ const int a6 = (src[6][i]<<2) + 10*src[2][i];
+ const int a5 = (src[0][i] - src[4][i]) << 3;
+ const int a4 = (src[0][i] + src[4][i]) << 3;
+
+ const int b0 = a4 + a6;
+ const int b1 = a5 + a7;
+ const int b2 = a5 - a7;
+ const int b3 = a4 - a6;
+
+ dst[i + 0*stride] = cm[ dst[i + 0*stride] + ((b0 + b4) >> 7)];
+ dst[i + 1*stride] = cm[ dst[i + 1*stride] + ((b1 + b5) >> 7)];
+ dst[i + 2*stride] = cm[ dst[i + 2*stride] + ((b2 + b6) >> 7)];
+ dst[i + 3*stride] = cm[ dst[i + 3*stride] + ((b3 + b7) >> 7)];
+ dst[i + 4*stride] = cm[ dst[i + 4*stride] + ((b3 - b7) >> 7)];
+ dst[i + 5*stride] = cm[ dst[i + 5*stride] + ((b2 - b6) >> 7)];
+ dst[i + 6*stride] = cm[ dst[i + 6*stride] + ((b1 - b5) >> 7)];
+ dst[i + 7*stride] = cm[ dst[i + 7*stride] + ((b0 - b4) >> 7)];
+ }
+ memset(block,0,64*sizeof(DCTELEM));
+}
+
+/*****************************************************************************
+ *
+ * motion compensation
+ *
+ ****************************************************************************/
+
+#define CAVS_SUBPIX(OPNAME, OP, NAME, A, B, C, D, E, F) \
+static void OPNAME ## cavs_filt8_h_ ## NAME(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ const int h=8;\
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
+ int i;\
+ for(i=0; i<h; i++)\
+ {\
+ OP(dst[0], A*src[-2] + B*src[-1] + C*src[0] + D*src[1] + E*src[2] + F*src[3]);\
+ OP(dst[1], A*src[-1] + B*src[ 0] + C*src[1] + D*src[2] + E*src[3] + F*src[4]);\
+ OP(dst[2], A*src[ 0] + B*src[ 1] + C*src[2] + D*src[3] + E*src[4] + F*src[5]);\
+ OP(dst[3], A*src[ 1] + B*src[ 2] + C*src[3] + D*src[4] + E*src[5] + F*src[6]);\
+ OP(dst[4], A*src[ 2] + B*src[ 3] + C*src[4] + D*src[5] + E*src[6] + F*src[7]);\
+ OP(dst[5], A*src[ 3] + B*src[ 4] + C*src[5] + D*src[6] + E*src[7] + F*src[8]);\
+ OP(dst[6], A*src[ 4] + B*src[ 5] + C*src[6] + D*src[7] + E*src[8] + F*src[9]);\
+ OP(dst[7], A*src[ 5] + B*src[ 6] + C*src[7] + D*src[8] + E*src[9] + F*src[10]);\
+ dst+=dstStride;\
+ src+=srcStride;\
+ }\
+}\
+\
+static void OPNAME ## cavs_filt8_v_ ## NAME(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ const int w=8;\
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
+ int i;\
+ for(i=0; i<w; i++)\
+ {\
+ const int srcB= src[-2*srcStride];\
+ const int srcA= src[-1*srcStride];\
+ const int src0= src[0 *srcStride];\
+ const int src1= src[1 *srcStride];\
+ const int src2= src[2 *srcStride];\
+ const int src3= src[3 *srcStride];\
+ const int src4= src[4 *srcStride];\
+ const int src5= src[5 *srcStride];\
+ const int src6= src[6 *srcStride];\
+ const int src7= src[7 *srcStride];\
+ const int src8= src[8 *srcStride];\
+ const int src9= src[9 *srcStride];\
+ const int src10= src[10 *srcStride];\
+ OP(dst[0*dstStride], A*srcB + B*srcA + C*src0 + D*src1 + E*src2 + F*src3);\
+ OP(dst[1*dstStride], A*srcA + B*src0 + C*src1 + D*src2 + E*src3 + F*src4);\
+ OP(dst[2*dstStride], A*src0 + B*src1 + C*src2 + D*src3 + E*src4 + F*src5);\
+ OP(dst[3*dstStride], A*src1 + B*src2 + C*src3 + D*src4 + E*src5 + F*src6);\
+ OP(dst[4*dstStride], A*src2 + B*src3 + C*src4 + D*src5 + E*src6 + F*src7);\
+ OP(dst[5*dstStride], A*src3 + B*src4 + C*src5 + D*src6 + E*src7 + F*src8);\
+ OP(dst[6*dstStride], A*src4 + B*src5 + C*src6 + D*src7 + E*src8 + F*src9);\
+ OP(dst[7*dstStride], A*src5 + B*src6 + C*src7 + D*src8 + E*src9 + F*src10);\
+ dst++;\
+ src++;\
+ }\
+}\
+\
+static void OPNAME ## cavs_filt16_v_ ## NAME(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ OPNAME ## cavs_filt8_v_ ## NAME(dst , src , dstStride, srcStride);\
+ OPNAME ## cavs_filt8_v_ ## NAME(dst+8, src+8, dstStride, srcStride);\
+ src += 8*srcStride;\
+ dst += 8*dstStride;\
+ OPNAME ## cavs_filt8_v_ ## NAME(dst , src , dstStride, srcStride);\
+ OPNAME ## cavs_filt8_v_ ## NAME(dst+8, src+8, dstStride, srcStride);\
+}\
+\
+static void OPNAME ## cavs_filt16_h_ ## NAME(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ OPNAME ## cavs_filt8_h_ ## NAME(dst , src , dstStride, srcStride);\
+ OPNAME ## cavs_filt8_h_ ## NAME(dst+8, src+8, dstStride, srcStride);\
+ src += 8*srcStride;\
+ dst += 8*dstStride;\
+ OPNAME ## cavs_filt8_h_ ## NAME(dst , src , dstStride, srcStride);\
+ OPNAME ## cavs_filt8_h_ ## NAME(dst+8, src+8, dstStride, srcStride);\
+}\
+
+#define CAVS_SUBPIX_HV(OPNAME, OP, NAME, AH, BH, CH, DH, EH, FH, AV, BV, CV, DV, EV, FV, FULL) \
+static void OPNAME ## cavs_filt8_hv_ ## NAME(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int srcStride){\
+ int16_t temp[8*(8+5)];\
+ int16_t *tmp = temp;\
+ const int h=8;\
+ const int w=8;\
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
+ int i;\
+ src1 -= 2*srcStride;\
+ for(i=0; i<h+5; i++)\
+ {\
+ tmp[0]= AH*src1[-2] + BH*src1[-1] + CH*src1[0] + DH*src1[1] + EH*src1[2] + FH*src1[3];\
+ tmp[1]= AH*src1[-1] + BH*src1[ 0] + CH*src1[1] + DH*src1[2] + EH*src1[3] + FH*src1[4];\
+ tmp[2]= AH*src1[ 0] + BH*src1[ 1] + CH*src1[2] + DH*src1[3] + EH*src1[4] + FH*src1[5];\
+ tmp[3]= AH*src1[ 1] + BH*src1[ 2] + CH*src1[3] + DH*src1[4] + EH*src1[5] + FH*src1[6];\
+ tmp[4]= AH*src1[ 2] + BH*src1[ 3] + CH*src1[4] + DH*src1[5] + EH*src1[6] + FH*src1[7];\
+ tmp[5]= AH*src1[ 3] + BH*src1[ 4] + CH*src1[5] + DH*src1[6] + EH*src1[7] + FH*src1[8];\
+ tmp[6]= AH*src1[ 4] + BH*src1[ 5] + CH*src1[6] + DH*src1[7] + EH*src1[8] + FH*src1[9];\
+ tmp[7]= AH*src1[ 5] + BH*src1[ 6] + CH*src1[7] + DH*src1[8] + EH*src1[9] + FH*src1[10];\
+ tmp+=8;\
+ src1+=srcStride;\
+ }\
+ if(FULL) {\
+ tmp = temp+8*2; \
+ for(i=0; i<w; i++) \
+ { \
+ const int tmpB= tmp[-2*8]; \
+ const int tmpA= tmp[-1*8]; \
+ const int tmp0= tmp[0 *8]; \
+ const int tmp1= tmp[1 *8]; \
+ const int tmp2= tmp[2 *8]; \
+ const int tmp3= tmp[3 *8]; \
+ const int tmp4= tmp[4 *8]; \
+ const int tmp5= tmp[5 *8]; \
+ const int tmp6= tmp[6 *8]; \
+ const int tmp7= tmp[7 *8]; \
+ const int tmp8= tmp[8 *8]; \
+ const int tmp9= tmp[9 *8]; \
+ const int tmp10=tmp[10*8]; \
+ OP(dst[0*dstStride], AV*tmpB + BV*tmpA + CV*tmp0 + DV*tmp1 + EV*tmp2 + FV*tmp3 + 64*src2[0*srcStride]); \
+ OP(dst[1*dstStride], AV*tmpA + BV*tmp0 + CV*tmp1 + DV*tmp2 + EV*tmp3 + FV*tmp4 + 64*src2[1*srcStride]); \
+ OP(dst[2*dstStride], AV*tmp0 + BV*tmp1 + CV*tmp2 + DV*tmp3 + EV*tmp4 + FV*tmp5 + 64*src2[2*srcStride]); \
+ OP(dst[3*dstStride], AV*tmp1 + BV*tmp2 + CV*tmp3 + DV*tmp4 + EV*tmp5 + FV*tmp6 + 64*src2[3*srcStride]); \
+ OP(dst[4*dstStride], AV*tmp2 + BV*tmp3 + CV*tmp4 + DV*tmp5 + EV*tmp6 + FV*tmp7 + 64*src2[4*srcStride]); \
+ OP(dst[5*dstStride], AV*tmp3 + BV*tmp4 + CV*tmp5 + DV*tmp6 + EV*tmp7 + FV*tmp8 + 64*src2[5*srcStride]); \
+ OP(dst[6*dstStride], AV*tmp4 + BV*tmp5 + CV*tmp6 + DV*tmp7 + EV*tmp8 + FV*tmp9 + 64*src2[6*srcStride]); \
+ OP(dst[7*dstStride], AV*tmp5 + BV*tmp6 + CV*tmp7 + DV*tmp8 + EV*tmp9 + FV*tmp10 + 64*src2[7*srcStride]); \
+ dst++; \
+ tmp++; \
+ src2++; \
+ } \
+ } else {\
+ tmp = temp+8*2; \
+ for(i=0; i<w; i++) \
+ { \
+ const int tmpB= tmp[-2*8]; \
+ const int tmpA= tmp[-1*8]; \
+ const int tmp0= tmp[0 *8]; \
+ const int tmp1= tmp[1 *8]; \
+ const int tmp2= tmp[2 *8]; \
+ const int tmp3= tmp[3 *8]; \
+ const int tmp4= tmp[4 *8]; \
+ const int tmp5= tmp[5 *8]; \
+ const int tmp6= tmp[6 *8]; \
+ const int tmp7= tmp[7 *8]; \
+ const int tmp8= tmp[8 *8]; \
+ const int tmp9= tmp[9 *8]; \
+ const int tmp10=tmp[10*8]; \
+ OP(dst[0*dstStride], AV*tmpB + BV*tmpA + CV*tmp0 + DV*tmp1 + EV*tmp2 + FV*tmp3); \
+ OP(dst[1*dstStride], AV*tmpA + BV*tmp0 + CV*tmp1 + DV*tmp2 + EV*tmp3 + FV*tmp4); \
+ OP(dst[2*dstStride], AV*tmp0 + BV*tmp1 + CV*tmp2 + DV*tmp3 + EV*tmp4 + FV*tmp5); \
+ OP(dst[3*dstStride], AV*tmp1 + BV*tmp2 + CV*tmp3 + DV*tmp4 + EV*tmp5 + FV*tmp6); \
+ OP(dst[4*dstStride], AV*tmp2 + BV*tmp3 + CV*tmp4 + DV*tmp5 + EV*tmp6 + FV*tmp7); \
+ OP(dst[5*dstStride], AV*tmp3 + BV*tmp4 + CV*tmp5 + DV*tmp6 + EV*tmp7 + FV*tmp8); \
+ OP(dst[6*dstStride], AV*tmp4 + BV*tmp5 + CV*tmp6 + DV*tmp7 + EV*tmp8 + FV*tmp9); \
+ OP(dst[7*dstStride], AV*tmp5 + BV*tmp6 + CV*tmp7 + DV*tmp8 + EV*tmp9 + FV*tmp10); \
+ dst++; \
+ tmp++; \
+ } \
+ }\
+}\
+\
+static void OPNAME ## cavs_filt16_hv_ ## NAME(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int srcStride){ \
+ OPNAME ## cavs_filt8_hv_ ## NAME(dst , src1, src2 , dstStride, srcStride); \
+ OPNAME ## cavs_filt8_hv_ ## NAME(dst+8, src1+8, src2+8, dstStride, srcStride); \
+ src1 += 8*srcStride;\
+ src2 += 8*srcStride;\
+ dst += 8*dstStride;\
+ OPNAME ## cavs_filt8_hv_ ## NAME(dst , src1, src2 , dstStride, srcStride); \
+ OPNAME ## cavs_filt8_hv_ ## NAME(dst+8, src1+8, src2+8, dstStride, srcStride); \
+}\
+
+#define CAVS_MC(OPNAME, SIZE) \
+static void ff_ ## OPNAME ## cavs_qpel ## SIZE ## _mc10_c(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## cavs_filt ## SIZE ## _h_qpel_l(dst, src, stride, stride);\
+}\
+\
+static void ff_ ## OPNAME ## cavs_qpel ## SIZE ## _mc20_c(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## cavs_filt ## SIZE ## _h_hpel(dst, src, stride, stride);\
+}\
+\
+static void ff_ ## OPNAME ## cavs_qpel ## SIZE ## _mc30_c(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## cavs_filt ## SIZE ## _h_qpel_r(dst, src, stride, stride);\
+}\
+\
+static void ff_ ## OPNAME ## cavs_qpel ## SIZE ## _mc01_c(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## cavs_filt ## SIZE ## _v_qpel_l(dst, src, stride, stride);\
+}\
+\
+static void ff_ ## OPNAME ## cavs_qpel ## SIZE ## _mc02_c(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## cavs_filt ## SIZE ## _v_hpel(dst, src, stride, stride);\
+}\
+\
+static void ff_ ## OPNAME ## cavs_qpel ## SIZE ## _mc03_c(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## cavs_filt ## SIZE ## _v_qpel_r(dst, src, stride, stride);\
+}\
+\
+static void ff_ ## OPNAME ## cavs_qpel ## SIZE ## _mc22_c(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## cavs_filt ## SIZE ## _hv_jj(dst, src, NULL, stride, stride); \
+}\
+\
+static void ff_ ## OPNAME ## cavs_qpel ## SIZE ## _mc11_c(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## cavs_filt ## SIZE ## _hv_egpr(dst, src, src, stride, stride); \
+}\
+\
+static void ff_ ## OPNAME ## cavs_qpel ## SIZE ## _mc13_c(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## cavs_filt ## SIZE ## _hv_egpr(dst, src, src+stride, stride, stride); \
+}\
+\
+static void ff_ ## OPNAME ## cavs_qpel ## SIZE ## _mc31_c(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## cavs_filt ## SIZE ## _hv_egpr(dst, src, src+1, stride, stride); \
+}\
+\
+static void ff_ ## OPNAME ## cavs_qpel ## SIZE ## _mc33_c(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## cavs_filt ## SIZE ## _hv_egpr(dst, src, src+stride+1,stride, stride); \
+}\
+\
+static void ff_ ## OPNAME ## cavs_qpel ## SIZE ## _mc21_c(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## cavs_filt ## SIZE ## _hv_ff(dst, src, src+stride+1,stride, stride); \
+}\
+\
+static void ff_ ## OPNAME ## cavs_qpel ## SIZE ## _mc12_c(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## cavs_filt ## SIZE ## _hv_ii(dst, src, src+stride+1,stride, stride); \
+}\
+\
+static void ff_ ## OPNAME ## cavs_qpel ## SIZE ## _mc32_c(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## cavs_filt ## SIZE ## _hv_kk(dst, src, src+stride+1,stride, stride); \
+}\
+\
+static void ff_ ## OPNAME ## cavs_qpel ## SIZE ## _mc23_c(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## cavs_filt ## SIZE ## _hv_qq(dst, src, src+stride+1,stride, stride); \
+}\
+
+#define op_put1(a, b) a = cm[((b)+4)>>3]
+#define op_put2(a, b) a = cm[((b)+64)>>7]
+#define op_put3(a, b) a = cm[((b)+32)>>6]
+#define op_put4(a, b) a = cm[((b)+512)>>10]
+#define op_avg1(a, b) a = ((a)+cm[((b)+4)>>3] +1)>>1
+#define op_avg2(a, b) a = ((a)+cm[((b)+64)>>7] +1)>>1
+#define op_avg3(a, b) a = ((a)+cm[((b)+32)>>6] +1)>>1
+#define op_avg4(a, b) a = ((a)+cm[((b)+512)>>10]+1)>>1
+CAVS_SUBPIX(put_ , op_put1, hpel, 0, -1, 5, 5, -1, 0)
+CAVS_SUBPIX(put_ , op_put2, qpel_l, -1, -2, 96, 42, -7, 0)
+CAVS_SUBPIX(put_ , op_put2, qpel_r, 0, -7, 42, 96, -2, -1)
+CAVS_SUBPIX_HV(put_, op_put3, jj, 0, -1, 5, 5, -1, 0, 0, -1, 5, 5, -1, 0, 0)
+CAVS_SUBPIX_HV(put_, op_put4, ff, 0, -1, 5, 5, -1, 0, -1, -2, 96, 42, -7, 0, 0)
+CAVS_SUBPIX_HV(put_, op_put4, ii, -1, -2, 96, 42, -7, 0, 0, -1, 5, 5, -1, 0, 0)
+CAVS_SUBPIX_HV(put_, op_put4, kk, 0, -7, 42, 96, -2, -1, 0, -1, 5, 5, -1, 0, 0)
+CAVS_SUBPIX_HV(put_, op_put4, qq, 0, -1, 5, 5, -1, 0, 0, -7, 42, 96, -2,-1, 0)
+CAVS_SUBPIX_HV(put_, op_put2, egpr, 0, -1, 5, 5, -1, 0, 0, -1, 5, 5, -1, 0, 1)
+CAVS_SUBPIX(avg_ , op_avg1, hpel, 0, -1, 5, 5, -1, 0)
+CAVS_SUBPIX(avg_ , op_avg2, qpel_l, -1, -2, 96, 42, -7, 0)
+CAVS_SUBPIX(avg_ , op_avg2, qpel_r, 0, -7, 42, 96, -2, -1)
+CAVS_SUBPIX_HV(avg_, op_avg3, jj, 0, -1, 5, 5, -1, 0, 0, -1, 5, 5, -1, 0, 0)
+CAVS_SUBPIX_HV(avg_, op_avg4, ff, 0, -1, 5, 5, -1, 0, -1, -2, 96, 42, -7, 0, 0)
+CAVS_SUBPIX_HV(avg_, op_avg4, ii, -1, -2, 96, 42, -7, 0, 0, -1, 5, 5, -1, 0, 0)
+CAVS_SUBPIX_HV(avg_, op_avg4, kk, 0, -7, 42, 96, -2, -1, 0, -1, 5, 5, -1, 0, 0)
+CAVS_SUBPIX_HV(avg_, op_avg4, qq, 0, -1, 5, 5, -1, 0, 0, -7, 42, 96, -2,-1, 0)
+CAVS_SUBPIX_HV(avg_, op_avg2, egpr, 0, -1, 5, 5, -1, 0, 0, -1, 5, 5, -1, 0, 1)
+CAVS_MC(put_, 8)
+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) {
+#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; \
+ c->PFX ## _pixels_tab[IDX][ 2] = ff_ ## PFX ## NUM ## _mc20_c; \
+ c->PFX ## _pixels_tab[IDX][ 3] = ff_ ## PFX ## NUM ## _mc30_c; \
+ c->PFX ## _pixels_tab[IDX][ 4] = ff_ ## PFX ## NUM ## _mc01_c; \
+ c->PFX ## _pixels_tab[IDX][ 5] = ff_ ## PFX ## NUM ## _mc11_c; \
+ c->PFX ## _pixels_tab[IDX][ 6] = ff_ ## PFX ## NUM ## _mc21_c; \
+ c->PFX ## _pixels_tab[IDX][ 7] = ff_ ## PFX ## NUM ## _mc31_c; \
+ c->PFX ## _pixels_tab[IDX][ 8] = ff_ ## PFX ## NUM ## _mc02_c; \
+ c->PFX ## _pixels_tab[IDX][ 9] = ff_ ## PFX ## NUM ## _mc12_c; \
+ c->PFX ## _pixels_tab[IDX][10] = ff_ ## PFX ## NUM ## _mc22_c; \
+ c->PFX ## _pixels_tab[IDX][11] = ff_ ## PFX ## NUM ## _mc32_c; \
+ c->PFX ## _pixels_tab[IDX][12] = ff_ ## PFX ## NUM ## _mc03_c; \
+ c->PFX ## _pixels_tab[IDX][13] = ff_ ## PFX ## NUM ## _mc13_c; \
+ c->PFX ## _pixels_tab[IDX][14] = ff_ ## PFX ## NUM ## _mc23_c; \
+ c->PFX ## _pixels_tab[IDX][15] = ff_ ## PFX ## NUM ## _mc33_c
+ dspfunc(put_cavs_qpel, 0, 16);
+ dspfunc(put_cavs_qpel, 1, 8);
+ dspfunc(avg_cavs_qpel, 0, 16);
+ dspfunc(avg_cavs_qpel, 1, 8);
+ c->cavs_filter_lv = cavs_filter_lv_c;
+ c->cavs_filter_lh = cavs_filter_lh_c;
+ c->cavs_filter_cv = cavs_filter_cv_c;
+ c->cavs_filter_ch = cavs_filter_ch_c;
+ c->cavs_idct8_add = cavs_idct8_add_c;
+}
diff --git a/src/libffmpeg/libavcodec/cinepak.c b/contrib/ffmpeg/libavcodec/cinepak.c
index db0519b5d..db0519b5d 100644
--- a/src/libffmpeg/libavcodec/cinepak.c
+++ b/contrib/ffmpeg/libavcodec/cinepak.c
diff --git a/src/libffmpeg/libavcodec/cljr.c b/contrib/ffmpeg/libavcodec/cljr.c
index 44810f5cf..44810f5cf 100644
--- a/src/libffmpeg/libavcodec/cljr.c
+++ b/contrib/ffmpeg/libavcodec/cljr.c
diff --git a/contrib/ffmpeg/libavcodec/cook.c b/contrib/ffmpeg/libavcodec/cook.c
new file mode 100644
index 000000000..32b1081cc
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/cook.c
@@ -0,0 +1,1147 @@
+/*
+ * COOK compatible decoder
+ * Copyright (c) 2003 Sascha Sommer
+ * Copyright (c) 2005 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 cook.c
+ * Cook compatible decoder.
+ * This decoder handles RealNetworks, RealAudio G2 data.
+ * Cook is identified by the codec name cook in RM files.
+ *
+ * To use this decoder, a calling application must supply the extradata
+ * bytes provided from the RM container; 8+ bytes for mono streams and
+ * 16+ for stereo streams (maybe more).
+ *
+ * Codec technicalities (all this assume a buffer length of 1024):
+ * Cook works with several different techniques to achieve its compression.
+ * In the timedomain the buffer is divided into 8 pieces and quantized. If
+ * two neighboring pieces have different quantization index a smooth
+ * quantization curve is used to get a smooth overlap between the different
+ * pieces.
+ * To get to the transformdomain Cook uses a modulated lapped transform.
+ * The transform domain has 50 subbands with 20 elements each. This
+ * means only a maximum of 50*20=1000 coefficients are used out of the 1024
+ * available.
+ */
+
+#include <math.h>
+#include <stddef.h>
+#include <stdio.h>
+
+#include "avcodec.h"
+#include "bitstream.h"
+#include "dsputil.h"
+#include "common.h"
+#include "bytestream.h"
+#include "random.h"
+
+#include "cookdata.h"
+
+/* the different Cook versions */
+#define MONO 0x1000001
+#define STEREO 0x1000002
+#define JOINT_STEREO 0x1000003
+#define MC_COOK 0x2000000 //multichannel Cook, not supported
+
+#define SUBBAND_SIZE 20
+//#define COOKDEBUG
+
+typedef struct {
+ int *now;
+ int *previous;
+} cook_gains;
+
+typedef struct {
+ GetBitContext gb;
+ /* stream data */
+ int nb_channels;
+ int joint_stereo;
+ int bit_rate;
+ int sample_rate;
+ int samples_per_channel;
+ int samples_per_frame;
+ int subbands;
+ int log2_numvector_size;
+ int numvector_size; //1 << log2_numvector_size;
+ int js_subband_start;
+ int total_subbands;
+ int num_vectors;
+ int bits_per_subpacket;
+ int cookversion;
+ /* states */
+ AVRandomState random_state;
+
+ /* transform data */
+ MDCTContext mdct_ctx;
+ DECLARE_ALIGNED_16(FFTSample, mdct_tmp[1024]); /* temporary storage for imlt */
+ float* mlt_window;
+
+ /* gain buffers */
+ cook_gains gains1;
+ cook_gains gains2;
+ int gain_1[9];
+ int gain_2[9];
+ int gain_3[9];
+ int gain_4[9];
+
+ /* VLC data */
+ int js_vlc_bits;
+ VLC envelope_quant_index[13];
+ VLC sqvh[7]; //scalar quantization
+ VLC ccpl; //channel coupling
+
+ /* generatable tables and related variables */
+ int gain_size_factor;
+ float gain_table[23];
+ float pow2tab[127];
+ float rootpow2tab[127];
+
+ /* data buffers */
+
+ uint8_t* decoded_bytes_buffer;
+ DECLARE_ALIGNED_16(float,mono_mdct_output[2048]);
+ float mono_previous_buffer1[1024];
+ float mono_previous_buffer2[1024];
+ float decode_buffer_1[1024];
+ float decode_buffer_2[1024];
+} COOKContext;
+
+/* debug functions */
+
+#ifdef COOKDEBUG
+static void dump_float_table(float* table, int size, int delimiter) {
+ int i=0;
+ av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i);
+ for (i=0 ; i<size ; i++) {
+ av_log(NULL, AV_LOG_ERROR, "%5.1f, ", table[i]);
+ if ((i+1)%delimiter == 0) av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i+1);
+ }
+}
+
+static void dump_int_table(int* table, int size, int delimiter) {
+ int i=0;
+ av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i);
+ for (i=0 ; i<size ; i++) {
+ av_log(NULL, AV_LOG_ERROR, "%d, ", table[i]);
+ if ((i+1)%delimiter == 0) av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i+1);
+ }
+}
+
+static void dump_short_table(short* table, int size, int delimiter) {
+ int i=0;
+ av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i);
+ for (i=0 ; i<size ; i++) {
+ av_log(NULL, AV_LOG_ERROR, "%d, ", table[i]);
+ if ((i+1)%delimiter == 0) av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i+1);
+ }
+}
+
+#endif
+
+/*************** init functions ***************/
+
+/* table generator */
+static void init_pow2table(COOKContext *q){
+ int i;
+ q->pow2tab[63] = 1.0;
+ for (i=1 ; i<64 ; i++){
+ q->pow2tab[63+i]=(float)((uint64_t)1<<i);
+ q->pow2tab[63-i]=1.0/(float)((uint64_t)1<<i);
+ }
+}
+
+/* table generator */
+static void init_rootpow2table(COOKContext *q){
+ int i;
+ q->rootpow2tab[63] = 1.0;
+ for (i=1 ; i<64 ; i++){
+ q->rootpow2tab[63+i]=sqrt((float)((uint64_t)1<<i));
+ q->rootpow2tab[63-i]=sqrt(1.0/(float)((uint64_t)1<<i));
+ }
+}
+
+/* table generator */
+static void init_gain_table(COOKContext *q) {
+ int i;
+ q->gain_size_factor = q->samples_per_channel/8;
+ for (i=0 ; i<23 ; i++) {
+ q->gain_table[i] = pow((double)q->pow2tab[i+52] ,
+ (1.0/(double)q->gain_size_factor));
+ }
+}
+
+
+static int init_cook_vlc_tables(COOKContext *q) {
+ int i, result;
+
+ result = 0;
+ for (i=0 ; i<13 ; i++) {
+ result &= init_vlc (&q->envelope_quant_index[i], 9, 24,
+ envelope_quant_index_huffbits[i], 1, 1,
+ envelope_quant_index_huffcodes[i], 2, 2, 0);
+ }
+ av_log(NULL,AV_LOG_DEBUG,"sqvh VLC init\n");
+ for (i=0 ; i<7 ; i++) {
+ result &= init_vlc (&q->sqvh[i], vhvlcsize_tab[i], vhsize_tab[i],
+ cvh_huffbits[i], 1, 1,
+ cvh_huffcodes[i], 2, 2, 0);
+ }
+
+ if (q->nb_channels==2 && q->joint_stereo==1){
+ result &= init_vlc (&q->ccpl, 6, (1<<q->js_vlc_bits)-1,
+ ccpl_huffbits[q->js_vlc_bits-2], 1, 1,
+ ccpl_huffcodes[q->js_vlc_bits-2], 2, 2, 0);
+ av_log(NULL,AV_LOG_DEBUG,"Joint-stereo VLC used.\n");
+ }
+
+ av_log(NULL,AV_LOG_DEBUG,"VLC tables initialized.\n");
+ return result;
+}
+
+static int init_cook_mlt(COOKContext *q) {
+ int j;
+ float alpha;
+ int mlt_size = q->samples_per_channel;
+
+ if ((q->mlt_window = av_malloc(sizeof(float)*mlt_size)) == 0)
+ return -1;
+
+ /* Initialize the MLT window: simple sine window. */
+ alpha = M_PI / (2.0 * (float)mlt_size);
+ for(j=0 ; j<mlt_size ; j++)
+ q->mlt_window[j] = sin((j + 0.5) * alpha) * sqrt(2.0 / q->samples_per_channel);
+
+ /* Initialize the MDCT. */
+ if (ff_mdct_init(&q->mdct_ctx, av_log2(mlt_size)+1, 1)) {
+ av_free(q->mlt_window);
+ return -1;
+ }
+ av_log(NULL,AV_LOG_DEBUG,"MDCT initialized, order = %d.\n",
+ av_log2(mlt_size)+1);
+
+ return 0;
+}
+
+/*************** init functions end ***********/
+
+/**
+ * Cook indata decoding, every 32 bits are XORed with 0x37c511f2.
+ * Why? No idea, some checksum/error detection method maybe.
+ *
+ * Out buffer size: extra bytes are needed to cope with
+ * padding/missalignment.
+ * Subpackets passed to the decoder can contain two, consecutive
+ * half-subpackets, of identical but arbitrary size.
+ * 1234 1234 1234 1234 extraA extraB
+ * Case 1: AAAA BBBB 0 0
+ * Case 2: AAAA ABBB BB-- 3 3
+ * Case 3: AAAA AABB BBBB 2 2
+ * Case 4: AAAA AAAB BBBB BB-- 1 5
+ *
+ * Nice way to waste CPU cycles.
+ *
+ * @param inbuffer pointer to byte array of indata
+ * @param out pointer to byte array of outdata
+ * @param bytes number of bytes
+ */
+#define DECODE_BYTES_PAD1(bytes) (3 - ((bytes)+3) % 4)
+#define DECODE_BYTES_PAD2(bytes) ((bytes) % 4 + DECODE_BYTES_PAD1(2 * (bytes)))
+
+static inline int decode_bytes(uint8_t* inbuffer, uint8_t* out, int bytes){
+ int i, off;
+ uint32_t c;
+ uint32_t* buf;
+ uint32_t* obuf = (uint32_t*) out;
+ /* FIXME: 64 bit platforms would be able to do 64 bits at a time.
+ * I'm too lazy though, should be something like
+ * for(i=0 ; i<bitamount/64 ; i++)
+ * (int64_t)out[i] = 0x37c511f237c511f2^be2me_64(int64_t)in[i]);
+ * Buffer alignment needs to be checked. */
+
+ off = (int)((long)inbuffer & 3);
+ buf = (uint32_t*) (inbuffer - off);
+ c = be2me_32((0x37c511f2 >> (off*8)) | (0x37c511f2 << (32-(off*8))));
+ bytes += 3 + off;
+ for (i = 0; i < bytes/4; i++)
+ obuf[i] = c ^ buf[i];
+
+ return off;
+}
+
+/**
+ * Cook uninit
+ */
+
+static int cook_decode_close(AVCodecContext *avctx)
+{
+ int i;
+ COOKContext *q = avctx->priv_data;
+ av_log(avctx,AV_LOG_DEBUG, "Deallocating memory.\n");
+
+ /* Free allocated memory buffers. */
+ av_free(q->mlt_window);
+ av_free(q->decoded_bytes_buffer);
+
+ /* Free the transform. */
+ ff_mdct_end(&q->mdct_ctx);
+
+ /* Free the VLC tables. */
+ for (i=0 ; i<13 ; i++) {
+ free_vlc(&q->envelope_quant_index[i]);
+ }
+ for (i=0 ; i<7 ; i++) {
+ free_vlc(&q->sqvh[i]);
+ }
+ if(q->nb_channels==2 && q->joint_stereo==1 ){
+ free_vlc(&q->ccpl);
+ }
+
+ av_log(NULL,AV_LOG_DEBUG,"Memory deallocated.\n");
+
+ return 0;
+}
+
+/**
+ * Fill the gain array for the timedomain quantization.
+ *
+ * @param q pointer to the COOKContext
+ * @param gaininfo[9] array of gain indices
+ */
+
+static void decode_gain_info(GetBitContext *gb, int *gaininfo)
+{
+ int i, n;
+
+ while (get_bits1(gb)) {}
+ n = get_bits_count(gb) - 1; //amount of elements*2 to update
+
+ i = 0;
+ while (n--) {
+ int index = get_bits(gb, 3);
+ int gain = get_bits1(gb) ? get_bits(gb, 4) - 7 : -1;
+
+ while (i <= index) gaininfo[i++] = gain;
+ }
+ while (i <= 8) gaininfo[i++] = 0;
+}
+
+/**
+ * Create the quant index table needed for the envelope.
+ *
+ * @param q pointer to the COOKContext
+ * @param quant_index_table pointer to the array
+ */
+
+static void decode_envelope(COOKContext *q, int* quant_index_table) {
+ int i,j, vlc_index;
+ int bitbias;
+
+ bitbias = get_bits_count(&q->gb);
+ quant_index_table[0]= get_bits(&q->gb,6) - 6; //This is used later in categorize
+
+ for (i=1 ; i < q->total_subbands ; i++){
+ vlc_index=i;
+ if (i >= q->js_subband_start * 2) {
+ vlc_index-=q->js_subband_start;
+ } else {
+ vlc_index/=2;
+ if(vlc_index < 1) vlc_index = 1;
+ }
+ if (vlc_index>13) vlc_index = 13; //the VLC tables >13 are identical to No. 13
+
+ j = get_vlc2(&q->gb, q->envelope_quant_index[vlc_index-1].table,
+ q->envelope_quant_index[vlc_index-1].bits,2);
+ quant_index_table[i] = quant_index_table[i-1] + j - 12; //differential encoding
+ }
+}
+
+/**
+ * Calculate the category and category_index vector.
+ *
+ * @param q pointer to the COOKContext
+ * @param quant_index_table pointer to the array
+ * @param category pointer to the category array
+ * @param category_index pointer to the category_index array
+ */
+
+static void categorize(COOKContext *q, int* quant_index_table,
+ int* category, int* category_index){
+ int exp_idx, bias, tmpbias, bits_left, num_bits, index, v, i, j;
+ int exp_index2[102];
+ int exp_index1[102];
+
+ int tmp_categorize_array1[128];
+ int tmp_categorize_array1_idx=0;
+ int tmp_categorize_array2[128];
+ int tmp_categorize_array2_idx=0;
+ int category_index_size=0;
+
+ bits_left = q->bits_per_subpacket - get_bits_count(&q->gb);
+
+ if(bits_left > q->samples_per_channel) {
+ bits_left = q->samples_per_channel +
+ ((bits_left - q->samples_per_channel)*5)/8;
+ //av_log(NULL, AV_LOG_ERROR, "bits_left = %d\n",bits_left);
+ }
+
+ memset(&exp_index1,0,102*sizeof(int));
+ memset(&exp_index2,0,102*sizeof(int));
+ memset(&tmp_categorize_array1,0,128*sizeof(int));
+ memset(&tmp_categorize_array2,0,128*sizeof(int));
+
+ bias=-32;
+
+ /* Estimate bias. */
+ for (i=32 ; i>0 ; i=i/2){
+ num_bits = 0;
+ index = 0;
+ for (j=q->total_subbands ; j>0 ; j--){
+ exp_idx = (i - quant_index_table[index] + bias) / 2;
+ if (exp_idx<0){
+ exp_idx=0;
+ } else if(exp_idx >7) {
+ exp_idx=7;
+ }
+ index++;
+ num_bits+=expbits_tab[exp_idx];
+ }
+ if(num_bits >= bits_left - 32){
+ bias+=i;
+ }
+ }
+
+ /* Calculate total number of bits. */
+ num_bits=0;
+ for (i=0 ; i<q->total_subbands ; i++) {
+ exp_idx = (bias - quant_index_table[i]) / 2;
+ if (exp_idx<0) {
+ exp_idx=0;
+ } else if(exp_idx >7) {
+ exp_idx=7;
+ }
+ num_bits += expbits_tab[exp_idx];
+ exp_index1[i] = exp_idx;
+ exp_index2[i] = exp_idx;
+ }
+ tmpbias = bias = num_bits;
+
+ for (j = 1 ; j < q->numvector_size ; j++) {
+ if (tmpbias + bias > 2*bits_left) { /* ---> */
+ int max = -999999;
+ index=-1;
+ for (i=0 ; i<q->total_subbands ; i++){
+ if (exp_index1[i] < 7) {
+ v = (-2*exp_index1[i]) - quant_index_table[i] - 32;
+ if ( v >= max) {
+ max = v;
+ index = i;
+ }
+ }
+ }
+ if(index==-1)break;
+ tmp_categorize_array1[tmp_categorize_array1_idx++] = index;
+ tmpbias -= expbits_tab[exp_index1[index]] -
+ expbits_tab[exp_index1[index]+1];
+ ++exp_index1[index];
+ } else { /* <--- */
+ int min = 999999;
+ index=-1;
+ for (i=0 ; i<q->total_subbands ; i++){
+ if(exp_index2[i] > 0){
+ v = (-2*exp_index2[i])-quant_index_table[i];
+ if ( v < min) {
+ min = v;
+ index = i;
+ }
+ }
+ }
+ if(index == -1)break;
+ tmp_categorize_array2[tmp_categorize_array2_idx++] = index;
+ tmpbias -= expbits_tab[exp_index2[index]] -
+ expbits_tab[exp_index2[index]-1];
+ --exp_index2[index];
+ }
+ }
+
+ for(i=0 ; i<q->total_subbands ; i++)
+ category[i] = exp_index2[i];
+
+ /* Concatenate the two arrays. */
+ for(i=tmp_categorize_array2_idx-1 ; i >= 0; i--)
+ category_index[category_index_size++] = tmp_categorize_array2[i];
+
+ for(i=0;i<tmp_categorize_array1_idx;i++)
+ category_index[category_index_size++ ] = tmp_categorize_array1[i];
+
+ /* FIXME: mc_sich_ra8_20.rm triggers this, not sure with what we
+ should fill the remaining bytes. */
+ for(i=category_index_size;i<q->numvector_size;i++)
+ category_index[i]=0;
+
+}
+
+
+/**
+ * Expand the category vector.
+ *
+ * @param q pointer to the COOKContext
+ * @param category pointer to the category array
+ * @param category_index pointer to the category_index array
+ */
+
+static void inline expand_category(COOKContext *q, int* category,
+ int* category_index){
+ int i;
+ for(i=0 ; i<q->num_vectors ; i++){
+ ++category[category_index[i]];
+ }
+}
+
+/**
+ * The real requantization of the mltcoefs
+ *
+ * @param q pointer to the COOKContext
+ * @param index index
+ * @param quant_index quantisation index
+ * @param subband_coef_index array of indexes to quant_centroid_tab
+ * @param subband_coef_sign signs of coefficients
+ * @param mlt_p pointer into the mlt buffer
+ */
+
+static void scalar_dequant(COOKContext *q, int index, int quant_index,
+ int* subband_coef_index, int* subband_coef_sign,
+ float* mlt_p){
+ int i;
+ float f1;
+
+ for(i=0 ; i<SUBBAND_SIZE ; i++) {
+ if (subband_coef_index[i]) {
+ f1 = quant_centroid_tab[index][subband_coef_index[i]];
+ if (subband_coef_sign[i]) f1 = -f1;
+ } else {
+ /* noise coding if subband_coef_index[i] == 0 */
+ f1 = dither_tab[index];
+ if (av_random(&q->random_state) < 0x80000000) f1 = -f1;
+ }
+ mlt_p[i] = f1 * q->rootpow2tab[quant_index+63];
+ }
+}
+/**
+ * Unpack the subband_coef_index and subband_coef_sign vectors.
+ *
+ * @param q pointer to the COOKContext
+ * @param category pointer to the category array
+ * @param subband_coef_index array of indexes to quant_centroid_tab
+ * @param subband_coef_sign signs of coefficients
+ */
+
+static int unpack_SQVH(COOKContext *q, int category, int* subband_coef_index,
+ int* subband_coef_sign) {
+ int i,j;
+ int vlc, vd ,tmp, result;
+ int ub;
+ int cb;
+
+ vd = vd_tab[category];
+ result = 0;
+ for(i=0 ; i<vpr_tab[category] ; i++){
+ ub = get_bits_count(&q->gb);
+ vlc = get_vlc2(&q->gb, q->sqvh[category].table, q->sqvh[category].bits, 3);
+ cb = get_bits_count(&q->gb);
+ if (q->bits_per_subpacket < get_bits_count(&q->gb)){
+ vlc = 0;
+ result = 1;
+ }
+ for(j=vd-1 ; j>=0 ; j--){
+ tmp = (vlc * invradix_tab[category])/0x100000;
+ subband_coef_index[vd*i+j] = vlc - tmp * (kmax_tab[category]+1);
+ vlc = tmp;
+ }
+ for(j=0 ; j<vd ; j++){
+ if (subband_coef_index[i*vd + j]) {
+ if(get_bits_count(&q->gb) < q->bits_per_subpacket){
+ subband_coef_sign[i*vd+j] = get_bits1(&q->gb);
+ } else {
+ result=1;
+ subband_coef_sign[i*vd+j]=0;
+ }
+ } else {
+ subband_coef_sign[i*vd+j]=0;
+ }
+ }
+ }
+ return result;
+}
+
+
+/**
+ * Fill the mlt_buffer with mlt coefficients.
+ *
+ * @param q pointer to the COOKContext
+ * @param category pointer to the category array
+ * @param quant_index_table pointer to the array
+ * @param mlt_buffer pointer to mlt coefficients
+ */
+
+
+static void decode_vectors(COOKContext* q, int* category,
+ int *quant_index_table, float* mlt_buffer){
+ /* A zero in this table means that the subband coefficient is
+ random noise coded. */
+ int subband_coef_index[SUBBAND_SIZE];
+ /* A zero in this table means that the subband coefficient is a
+ positive multiplicator. */
+ int subband_coef_sign[SUBBAND_SIZE];
+ int band, j;
+ int index=0;
+
+ for(band=0 ; band<q->total_subbands ; band++){
+ index = category[band];
+ if(category[band] < 7){
+ if(unpack_SQVH(q, category[band], subband_coef_index, subband_coef_sign)){
+ index=7;
+ for(j=0 ; j<q->total_subbands ; j++) category[band+j]=7;
+ }
+ }
+ if(index==7) {
+ memset(subband_coef_index, 0, sizeof(subband_coef_index));
+ memset(subband_coef_sign, 0, sizeof(subband_coef_sign));
+ }
+ scalar_dequant(q, index, quant_index_table[band],
+ subband_coef_index, subband_coef_sign,
+ &mlt_buffer[band * 20]);
+ }
+
+ if(q->total_subbands*SUBBAND_SIZE >= q->samples_per_channel){
+ return;
+ } /* FIXME: should this be removed, or moved into loop above? */
+}
+
+
+/**
+ * function for decoding mono data
+ *
+ * @param q pointer to the COOKContext
+ * @param mlt_buffer1 pointer to left channel mlt coefficients
+ * @param mlt_buffer2 pointer to right channel mlt coefficients
+ */
+
+static void mono_decode(COOKContext *q, float* mlt_buffer) {
+
+ int category_index[128];
+ int quant_index_table[102];
+ int category[128];
+
+ memset(&category, 0, 128*sizeof(int));
+ memset(&category_index, 0, 128*sizeof(int));
+
+ decode_envelope(q, quant_index_table);
+ q->num_vectors = get_bits(&q->gb,q->log2_numvector_size);
+ categorize(q, quant_index_table, category, category_index);
+ expand_category(q, category, category_index);
+ decode_vectors(q, category, quant_index_table, mlt_buffer);
+}
+
+
+/**
+ * the actual requantization of the timedomain samples
+ *
+ * @param q pointer to the COOKContext
+ * @param buffer pointer to the timedomain buffer
+ * @param gain_index index for the block multiplier
+ * @param gain_index_next index for the next block multiplier
+ */
+
+static void interpolate(COOKContext *q, float* buffer,
+ int gain_index, int gain_index_next){
+ int i;
+ float fc1, fc2;
+ fc1 = q->pow2tab[gain_index+63];
+
+ if(gain_index == gain_index_next){ //static gain
+ for(i=0 ; i<q->gain_size_factor ; i++){
+ buffer[i]*=fc1;
+ }
+ return;
+ } else { //smooth gain
+ fc2 = q->gain_table[11 + (gain_index_next-gain_index)];
+ for(i=0 ; i<q->gain_size_factor ; i++){
+ buffer[i]*=fc1;
+ fc1*=fc2;
+ }
+ return;
+ }
+}
+
+
+/**
+ * The modulated lapped transform, this takes transform coefficients
+ * and transforms them into timedomain samples.
+ * Apply transform window, overlap buffers, apply gain profile
+ * and buffer management.
+ *
+ * @param q pointer to the COOKContext
+ * @param inbuffer pointer to the mltcoefficients
+ * @param gains_ptr current and previous gains
+ * @param previous_buffer pointer to the previous buffer to be used for overlapping
+ */
+
+static void imlt_gain(COOKContext *q, float *inbuffer,
+ cook_gains *gains_ptr, float* previous_buffer)
+{
+ const float fc = q->pow2tab[gains_ptr->previous[0] + 63];
+ float *buffer0 = q->mono_mdct_output;
+ float *buffer1 = q->mono_mdct_output + q->samples_per_channel;
+ int i;
+
+ /* Inverse modified discrete cosine transform */
+ q->mdct_ctx.fft.imdct_calc(&q->mdct_ctx, q->mono_mdct_output,
+ inbuffer, q->mdct_tmp);
+
+ /* The weird thing here, is that the two halves of the time domain
+ * buffer are swapped. Also, the newest data, that we save away for
+ * next frame, has the wrong sign. Hence the subtraction below.
+ * Almost sounds like a complex conjugate/reverse data/FFT effect.
+ */
+
+ /* Apply window and overlap */
+ for(i = 0; i < q->samples_per_channel; i++){
+ buffer1[i] = buffer1[i] * fc * q->mlt_window[i] -
+ previous_buffer[i] * q->mlt_window[q->samples_per_channel - 1 - i];
+ }
+
+ /* Apply gain profile */
+ for (i = 0; i < 8; i++) {
+ if (gains_ptr->now[i] || gains_ptr->now[i + 1])
+ interpolate(q, &buffer1[q->gain_size_factor * i],
+ gains_ptr->now[i], gains_ptr->now[i + 1]);
+ }
+
+ /* Save away the current to be previous block. */
+ memcpy(previous_buffer, buffer0, sizeof(float)*q->samples_per_channel);
+}
+
+
+/**
+ * function for getting the jointstereo coupling information
+ *
+ * @param q pointer to the COOKContext
+ * @param decouple_tab decoupling array
+ *
+ */
+
+static void decouple_info(COOKContext *q, int* decouple_tab){
+ int length, i;
+
+ if(get_bits1(&q->gb)) {
+ if(cplband[q->js_subband_start] > cplband[q->subbands-1]) return;
+
+ length = cplband[q->subbands-1] - cplband[q->js_subband_start] + 1;
+ for (i=0 ; i<length ; i++) {
+ decouple_tab[cplband[q->js_subband_start] + i] = get_vlc2(&q->gb, q->ccpl.table, q->ccpl.bits, 2);
+ }
+ return;
+ }
+
+ if(cplband[q->js_subband_start] > cplband[q->subbands-1]) return;
+
+ length = cplband[q->subbands-1] - cplband[q->js_subband_start] + 1;
+ for (i=0 ; i<length ; i++) {
+ decouple_tab[cplband[q->js_subband_start] + i] = get_bits(&q->gb, q->js_vlc_bits);
+ }
+ return;
+}
+
+
+/**
+ * function for decoding joint stereo data
+ *
+ * @param q pointer to the COOKContext
+ * @param mlt_buffer1 pointer to left channel mlt coefficients
+ * @param mlt_buffer2 pointer to right channel mlt coefficients
+ */
+
+static void joint_decode(COOKContext *q, float* mlt_buffer1,
+ float* mlt_buffer2) {
+ int i,j;
+ int decouple_tab[SUBBAND_SIZE];
+ float decode_buffer[1060];
+ int idx, cpl_tmp,tmp_idx;
+ float f1,f2;
+ float* cplscale;
+
+ memset(decouple_tab, 0, sizeof(decouple_tab));
+ memset(decode_buffer, 0, sizeof(decode_buffer));
+
+ /* Make sure the buffers are zeroed out. */
+ memset(mlt_buffer1,0, 1024*sizeof(float));
+ memset(mlt_buffer2,0, 1024*sizeof(float));
+ decouple_info(q, decouple_tab);
+ mono_decode(q, decode_buffer);
+
+ /* The two channels are stored interleaved in decode_buffer. */
+ for (i=0 ; i<q->js_subband_start ; i++) {
+ for (j=0 ; j<SUBBAND_SIZE ; j++) {
+ mlt_buffer1[i*20+j] = decode_buffer[i*40+j];
+ mlt_buffer2[i*20+j] = decode_buffer[i*40+20+j];
+ }
+ }
+
+ /* When we reach js_subband_start (the higher frequencies)
+ the coefficients are stored in a coupling scheme. */
+ idx = (1 << q->js_vlc_bits) - 1;
+ for (i=q->js_subband_start ; i<q->subbands ; i++) {
+ cpl_tmp = cplband[i];
+ idx -=decouple_tab[cpl_tmp];
+ cplscale = (float*)cplscales[q->js_vlc_bits-2]; //choose decoupler table
+ f1 = cplscale[decouple_tab[cpl_tmp]];
+ f2 = cplscale[idx-1];
+ for (j=0 ; j<SUBBAND_SIZE ; j++) {
+ tmp_idx = ((q->js_subband_start + i)*20)+j;
+ mlt_buffer1[20*i + j] = f1 * decode_buffer[tmp_idx];
+ mlt_buffer2[20*i + j] = f2 * decode_buffer[tmp_idx];
+ }
+ idx = (1 << q->js_vlc_bits) - 1;
+ }
+}
+
+/**
+ * First part of subpacket decoding:
+ * decode raw stream bytes and read gain info.
+ *
+ * @param q pointer to the COOKContext
+ * @param inbuffer pointer to raw stream data
+ * @param gain_ptr array of current/prev gain pointers
+ */
+
+static inline void
+decode_bytes_and_gain(COOKContext *q, uint8_t *inbuffer,
+ cook_gains *gains_ptr)
+{
+ int offset;
+
+ offset = decode_bytes(inbuffer, q->decoded_bytes_buffer,
+ q->bits_per_subpacket/8);
+ init_get_bits(&q->gb, q->decoded_bytes_buffer + offset,
+ q->bits_per_subpacket);
+ decode_gain_info(&q->gb, gains_ptr->now);
+
+ /* Swap current and previous gains */
+ FFSWAP(int *, gains_ptr->now, gains_ptr->previous);
+}
+
+/**
+ * Final part of subpacket decoding:
+ * Apply modulated lapped transform, gain compensation,
+ * clip and convert to integer.
+ *
+ * @param q pointer to the COOKContext
+ * @param decode_buffer pointer to the mlt coefficients
+ * @param gain_ptr array of current/prev gain pointers
+ * @param previous_buffer pointer to the previous buffer to be used for overlapping
+ * @param out pointer to the output buffer
+ * @param chan 0: left or single channel, 1: right channel
+ */
+
+static inline void
+mlt_compensate_output(COOKContext *q, float *decode_buffer,
+ cook_gains *gains, float *previous_buffer,
+ int16_t *out, int chan)
+{
+ float *output = q->mono_mdct_output + q->samples_per_channel;
+ int j;
+
+ imlt_gain(q, decode_buffer, gains, previous_buffer);
+
+ /* Clip and convert floats to 16 bits.
+ */
+ for (j = 0; j < q->samples_per_channel; j++) {
+ out[chan + q->nb_channels * j] =
+ av_clip(lrintf(output[j]), -32768, 32767);
+ }
+}
+
+
+/**
+ * Cook subpacket decoding. This function returns one decoded subpacket,
+ * usually 1024 samples per channel.
+ *
+ * @param q pointer to the COOKContext
+ * @param inbuffer pointer to the inbuffer
+ * @param sub_packet_size subpacket size
+ * @param outbuffer pointer to the outbuffer
+ */
+
+
+static int decode_subpacket(COOKContext *q, uint8_t *inbuffer,
+ int sub_packet_size, int16_t *outbuffer) {
+ /* packet dump */
+// for (i=0 ; i<sub_packet_size ; i++) {
+// av_log(NULL, AV_LOG_ERROR, "%02x", inbuffer[i]);
+// }
+// av_log(NULL, AV_LOG_ERROR, "\n");
+
+ decode_bytes_and_gain(q, inbuffer, &q->gains1);
+
+ if (q->joint_stereo) {
+ joint_decode(q, q->decode_buffer_1, q->decode_buffer_2);
+ } else {
+ mono_decode(q, q->decode_buffer_1);
+
+ if (q->nb_channels == 2) {
+ decode_bytes_and_gain(q, inbuffer + sub_packet_size/2, &q->gains2);
+ mono_decode(q, q->decode_buffer_2);
+ }
+ }
+
+ mlt_compensate_output(q, q->decode_buffer_1, &q->gains1,
+ q->mono_previous_buffer1, outbuffer, 0);
+
+ if (q->nb_channels == 2) {
+ if (q->joint_stereo) {
+ mlt_compensate_output(q, q->decode_buffer_2, &q->gains1,
+ q->mono_previous_buffer2, outbuffer, 1);
+ } else {
+ mlt_compensate_output(q, q->decode_buffer_2, &q->gains2,
+ q->mono_previous_buffer2, outbuffer, 1);
+ }
+ }
+ return q->samples_per_frame * sizeof(int16_t);
+}
+
+
+/**
+ * Cook frame decoding
+ *
+ * @param avctx pointer to the AVCodecContext
+ */
+
+static int cook_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size) {
+ COOKContext *q = avctx->priv_data;
+
+ if (buf_size < avctx->block_align)
+ return buf_size;
+
+ *data_size = decode_subpacket(q, buf, avctx->block_align, data);
+
+ /* Discard the first two frames: no valid audio. */
+ if (avctx->frame_number < 2) *data_size = 0;
+
+ return avctx->block_align;
+}
+
+#ifdef COOKDEBUG
+static void dump_cook_context(COOKContext *q)
+{
+ //int i=0;
+#define PRINT(a,b) av_log(NULL,AV_LOG_ERROR," %s = %d\n", a, b);
+ av_log(NULL,AV_LOG_ERROR,"COOKextradata\n");
+ av_log(NULL,AV_LOG_ERROR,"cookversion=%x\n",q->cookversion);
+ if (q->cookversion > STEREO) {
+ PRINT("js_subband_start",q->js_subband_start);
+ PRINT("js_vlc_bits",q->js_vlc_bits);
+ }
+ av_log(NULL,AV_LOG_ERROR,"COOKContext\n");
+ PRINT("nb_channels",q->nb_channels);
+ PRINT("bit_rate",q->bit_rate);
+ PRINT("sample_rate",q->sample_rate);
+ PRINT("samples_per_channel",q->samples_per_channel);
+ PRINT("samples_per_frame",q->samples_per_frame);
+ PRINT("subbands",q->subbands);
+ PRINT("random_state",q->random_state);
+ PRINT("js_subband_start",q->js_subband_start);
+ PRINT("log2_numvector_size",q->log2_numvector_size);
+ PRINT("numvector_size",q->numvector_size);
+ PRINT("total_subbands",q->total_subbands);
+}
+#endif
+
+/**
+ * Cook initialization
+ *
+ * @param avctx pointer to the AVCodecContext
+ */
+
+static int cook_decode_init(AVCodecContext *avctx)
+{
+ COOKContext *q = avctx->priv_data;
+ uint8_t *edata_ptr = avctx->extradata;
+
+ /* Take care of the codec specific extradata. */
+ if (avctx->extradata_size <= 0) {
+ av_log(avctx,AV_LOG_ERROR,"Necessary extradata missing!\n");
+ return -1;
+ } else {
+ /* 8 for mono, 16 for stereo, ? for multichannel
+ Swap to right endianness so we don't need to care later on. */
+ av_log(avctx,AV_LOG_DEBUG,"codecdata_length=%d\n",avctx->extradata_size);
+ if (avctx->extradata_size >= 8){
+ q->cookversion = bytestream_get_be32(&edata_ptr);
+ q->samples_per_frame = bytestream_get_be16(&edata_ptr);
+ q->subbands = bytestream_get_be16(&edata_ptr);
+ }
+ if (avctx->extradata_size >= 16){
+ bytestream_get_be32(&edata_ptr); //Unknown unused
+ q->js_subband_start = bytestream_get_be16(&edata_ptr);
+ q->js_vlc_bits = bytestream_get_be16(&edata_ptr);
+ }
+ }
+
+ /* Take data from the AVCodecContext (RM container). */
+ q->sample_rate = avctx->sample_rate;
+ q->nb_channels = avctx->channels;
+ q->bit_rate = avctx->bit_rate;
+
+ /* Initialize RNG. */
+ av_init_random(1, &q->random_state);
+
+ /* Initialize extradata related variables. */
+ q->samples_per_channel = q->samples_per_frame / q->nb_channels;
+ q->bits_per_subpacket = avctx->block_align * 8;
+
+ /* Initialize default data states. */
+ q->log2_numvector_size = 5;
+ q->total_subbands = q->subbands;
+
+ /* Initialize version-dependent variables */
+ av_log(NULL,AV_LOG_DEBUG,"q->cookversion=%x\n",q->cookversion);
+ q->joint_stereo = 0;
+ switch (q->cookversion) {
+ case MONO:
+ if (q->nb_channels != 1) {
+ av_log(avctx,AV_LOG_ERROR,"Container channels != 1, report sample!\n");
+ return -1;
+ }
+ av_log(avctx,AV_LOG_DEBUG,"MONO\n");
+ break;
+ case STEREO:
+ if (q->nb_channels != 1) {
+ q->bits_per_subpacket = q->bits_per_subpacket/2;
+ }
+ av_log(avctx,AV_LOG_DEBUG,"STEREO\n");
+ break;
+ case JOINT_STEREO:
+ if (q->nb_channels != 2) {
+ av_log(avctx,AV_LOG_ERROR,"Container channels != 2, report sample!\n");
+ return -1;
+ }
+ av_log(avctx,AV_LOG_DEBUG,"JOINT_STEREO\n");
+ if (avctx->extradata_size >= 16){
+ q->total_subbands = q->subbands + q->js_subband_start;
+ q->joint_stereo = 1;
+ }
+ if (q->samples_per_channel > 256) {
+ q->log2_numvector_size = 6;
+ }
+ if (q->samples_per_channel > 512) {
+ q->log2_numvector_size = 7;
+ }
+ break;
+ case MC_COOK:
+ av_log(avctx,AV_LOG_ERROR,"MC_COOK not supported!\n");
+ return -1;
+ break;
+ default:
+ av_log(avctx,AV_LOG_ERROR,"Unknown Cook version, report sample!\n");
+ return -1;
+ break;
+ }
+
+ /* Initialize variable relations */
+ q->numvector_size = (1 << q->log2_numvector_size);
+
+ /* Generate tables */
+ init_rootpow2table(q);
+ init_pow2table(q);
+ init_gain_table(q);
+
+ if (init_cook_vlc_tables(q) != 0)
+ return -1;
+
+
+ if(avctx->block_align >= UINT_MAX/2)
+ return -1;
+
+ /* Pad the databuffer with:
+ DECODE_BYTES_PAD1 or DECODE_BYTES_PAD2 for decode_bytes(),
+ FF_INPUT_BUFFER_PADDING_SIZE, for the bitstreamreader. */
+ if (q->nb_channels==2 && q->joint_stereo==0) {
+ q->decoded_bytes_buffer =
+ av_mallocz(avctx->block_align/2
+ + DECODE_BYTES_PAD2(avctx->block_align/2)
+ + FF_INPUT_BUFFER_PADDING_SIZE);
+ } else {
+ q->decoded_bytes_buffer =
+ av_mallocz(avctx->block_align
+ + DECODE_BYTES_PAD1(avctx->block_align)
+ + FF_INPUT_BUFFER_PADDING_SIZE);
+ }
+ if (q->decoded_bytes_buffer == NULL)
+ return -1;
+
+ q->gains1.now = q->gain_1;
+ q->gains1.previous = q->gain_2;
+ q->gains2.now = q->gain_3;
+ q->gains2.previous = q->gain_4;
+
+ /* Initialize transform. */
+ if ( init_cook_mlt(q) != 0 )
+ return -1;
+
+ /* Try to catch some obviously faulty streams, othervise it might be exploitable */
+ if (q->total_subbands > 53) {
+ av_log(avctx,AV_LOG_ERROR,"total_subbands > 53, report sample!\n");
+ return -1;
+ }
+ if (q->subbands > 50) {
+ av_log(avctx,AV_LOG_ERROR,"subbands > 50, report sample!\n");
+ return -1;
+ }
+ if ((q->samples_per_channel == 256) || (q->samples_per_channel == 512) || (q->samples_per_channel == 1024)) {
+ } else {
+ av_log(avctx,AV_LOG_ERROR,"unknown amount of samples_per_channel = %d, report sample!\n",q->samples_per_channel);
+ return -1;
+ }
+ if ((q->js_vlc_bits > 6) || (q->js_vlc_bits < 0)) {
+ av_log(avctx,AV_LOG_ERROR,"q->js_vlc_bits = %d, only >= 0 and <= 6 allowed!\n",q->js_vlc_bits);
+ return -1;
+ }
+
+#ifdef COOKDEBUG
+ dump_cook_context(q);
+#endif
+ return 0;
+}
+
+
+AVCodec cook_decoder =
+{
+ .name = "cook",
+ .type = CODEC_TYPE_AUDIO,
+ .id = CODEC_ID_COOK,
+ .priv_data_size = sizeof(COOKContext),
+ .init = cook_decode_init,
+ .close = cook_decode_close,
+ .decode = cook_decode_frame,
+};
diff --git a/src/libffmpeg/libavcodec/cookdata.h b/contrib/ffmpeg/libavcodec/cookdata.h
index 395c9a7dd..395c9a7dd 100644
--- a/src/libffmpeg/libavcodec/cookdata.h
+++ b/contrib/ffmpeg/libavcodec/cookdata.h
diff --git a/contrib/ffmpeg/libavcodec/cscd.c b/contrib/ffmpeg/libavcodec/cscd.c
new file mode 100644
index 000000000..2e7d05c40
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/cscd.c
@@ -0,0 +1,264 @@
+/*
+ * CamStudio decoder
+ * Copyright (c) 2006 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 <stdio.h>
+#include <stdlib.h>
+
+#include "common.h"
+#include "avcodec.h"
+
+#ifdef CONFIG_ZLIB
+#include <zlib.h>
+#endif
+#include "lzo.h"
+
+typedef struct {
+ AVFrame pic;
+ int linelen, height, bpp;
+ unsigned int decomp_size;
+ unsigned char* decomp_buf;
+} CamStudioContext;
+
+static void copy_frame_default(AVFrame *f, uint8_t *src,
+ int linelen, int height) {
+ int i;
+ uint8_t *dst = f->data[0];
+ dst += (height - 1) * f->linesize[0];
+ for (i = height; i; i--) {
+ memcpy(dst, src, linelen);
+ src += linelen;
+ dst -= f->linesize[0];
+ }
+}
+
+static void add_frame_default(AVFrame *f, uint8_t *src,
+ int linelen, int height) {
+ int i, j;
+ uint8_t *dst = f->data[0];
+ dst += (height - 1) * f->linesize[0];
+ for (i = height; i; i--) {
+ for (j = linelen; j; j--)
+ *dst++ += *src++;
+ dst -= f->linesize[0] + linelen;
+ }
+}
+
+#ifndef WORDS_BIGENDIAN
+#define copy_frame_16 copy_frame_default
+#define copy_frame_32 copy_frame_default
+#define add_frame_16 add_frame_default
+#define add_frame_32 add_frame_default
+#else
+static void copy_frame_16(AVFrame *f, uint8_t *src,
+ int linelen, int height) {
+ int i, j;
+ uint8_t *dst = f->data[0];
+ dst += (height - 1) * f->linesize[0];
+ for (i = height; i; i--) {
+ for (j = linelen / 2; j; j--) {
+ dst[0] = src[1];
+ dst[1] = src[0];
+ src += 2;
+ dst += 2;
+ }
+ dst -= f->linesize[0] + linelen;
+ }
+}
+
+static void copy_frame_32(AVFrame *f, uint8_t *src,
+ int linelen, int height) {
+ int i, j;
+ uint8_t *dst = f->data[0];
+ dst += (height - 1) * f->linesize[0];
+ for (i = height; i; i--) {
+ for (j = linelen / 4; j; j--) {
+ dst[0] = src[3];
+ dst[1] = src[2];
+ dst[2] = src[1];
+ dst[3] = src[0];
+ src += 4;
+ dst += 4;
+ }
+ dst -= f->linesize[0] + linelen;
+ }
+}
+
+static void add_frame_16(AVFrame *f, uint8_t *src,
+ int linelen, int height) {
+ int i, j;
+ uint8_t *dst = f->data[0];
+ dst += (height - 1) * f->linesize[0];
+ for (i = height; i; i--) {
+ for (j = linelen / 2; j; j--) {
+ dst[0] += src[1];
+ dst[1] += src[0];
+ src += 2;
+ dst += 2;
+ }
+ dst -= f->linesize[0] + linelen;
+ }
+}
+
+static void add_frame_32(AVFrame *f, uint8_t *src,
+ int linelen, int height) {
+ int i, j;
+ uint8_t *dst = f->data[0];
+ dst += (height - 1) * f->linesize[0];
+ for (i = height; i; i--) {
+ for (j = linelen / 4; j; j--) {
+ dst[0] += src[3];
+ dst[1] += src[2];
+ dst[2] += src[1];
+ dst[3] += src[0];
+ src += 4;
+ dst += 4;
+ }
+ dst -= f->linesize[0] + linelen;
+ }
+}
+#endif
+
+static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
+ uint8_t *buf, int buf_size) {
+ CamStudioContext *c = (CamStudioContext *)avctx->priv_data;
+ AVFrame *picture = data;
+
+ if (buf_size < 2) {
+ av_log(avctx, AV_LOG_ERROR, "coded frame too small\n");
+ return -1;
+ }
+
+ if (c->pic.data[0])
+ avctx->release_buffer(avctx, &c->pic);
+ c->pic.reference = 1;
+ c->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_READABLE |
+ FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
+ if (avctx->get_buffer(avctx, &c->pic) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ return -1;
+ }
+
+ // decompress data
+ switch ((buf[0] >> 1) & 7) {
+ case 0: { // lzo compression
+ int outlen = c->decomp_size, inlen = buf_size - 2;
+ if (lzo1x_decode(c->decomp_buf, &outlen, &buf[2], &inlen))
+ av_log(avctx, AV_LOG_ERROR, "error during lzo decompression\n");
+ break;
+ }
+ case 1: { // zlib compression
+#ifdef CONFIG_ZLIB
+ unsigned long dlen = c->decomp_size;
+ if (uncompress(c->decomp_buf, &dlen, &buf[2], buf_size - 2) != Z_OK)
+ av_log(avctx, AV_LOG_ERROR, "error during zlib decompression\n");
+ break;
+#else
+ av_log(avctx, AV_LOG_ERROR, "compiled without zlib support\n");
+ return -1;
+#endif
+ }
+ default:
+ av_log(avctx, AV_LOG_ERROR, "unknown compression\n");
+ return -1;
+ }
+
+ // flip upside down, add difference frame
+ if (buf[0] & 1) { // keyframe
+ c->pic.pict_type = FF_I_TYPE;
+ c->pic.key_frame = 1;
+ switch (c->bpp) {
+ case 16:
+ copy_frame_16(&c->pic, c->decomp_buf, c->linelen, c->height);
+ break;
+ case 32:
+ copy_frame_32(&c->pic, c->decomp_buf, c->linelen, c->height);
+ break;
+ default:
+ copy_frame_default(&c->pic, c->decomp_buf, c->linelen, c->height);
+ }
+ } else {
+ c->pic.pict_type = FF_P_TYPE;
+ c->pic.key_frame = 0;
+ switch (c->bpp) {
+ case 16:
+ add_frame_16(&c->pic, c->decomp_buf, c->linelen, c->height);
+ break;
+ case 32:
+ add_frame_32(&c->pic, c->decomp_buf, c->linelen, c->height);
+ break;
+ default:
+ add_frame_default(&c->pic, c->decomp_buf, c->linelen, c->height);
+ }
+ }
+
+ *picture = c->pic;
+ *data_size = sizeof(AVFrame);
+ return buf_size;
+}
+
+static int decode_init(AVCodecContext *avctx) {
+ CamStudioContext *c = (CamStudioContext *)avctx->priv_data;
+ if (avcodec_check_dimensions(avctx, avctx->height, avctx->width) < 0) {
+ return 1;
+ }
+ avctx->has_b_frames = 0;
+ switch (avctx->bits_per_sample) {
+ case 16: avctx->pix_fmt = PIX_FMT_RGB555; break;
+ case 24: avctx->pix_fmt = PIX_FMT_BGR24; break;
+ case 32: avctx->pix_fmt = PIX_FMT_RGB32; break;
+ default:
+ av_log(avctx, AV_LOG_ERROR,
+ "CamStudio codec error: invalid depth %i bpp\n",
+ avctx->bits_per_sample);
+ return 1;
+ }
+ c->bpp = avctx->bits_per_sample;
+ c->pic.data[0] = NULL;
+ c->linelen = avctx->width * avctx->bits_per_sample / 8;
+ c->height = avctx->height;
+ c->decomp_size = c->height * c->linelen;
+ c->decomp_buf = av_malloc(c->decomp_size + LZO_OUTPUT_PADDING);
+ if (!c->decomp_buf) {
+ av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
+ return 1;
+ }
+ return 0;
+}
+
+static int decode_end(AVCodecContext *avctx) {
+ CamStudioContext *c = (CamStudioContext *)avctx->priv_data;
+ av_freep(&c->decomp_buf);
+ if (c->pic.data[0])
+ avctx->release_buffer(avctx, &c->pic);
+ return 0;
+}
+
+AVCodec cscd_decoder = {
+ "camstudio",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_CSCD,
+ sizeof(CamStudioContext),
+ decode_init,
+ NULL,
+ decode_end,
+ decode_frame,
+ CODEC_CAP_DR1,
+};
+
diff --git a/src/libffmpeg/libavcodec/cyuv.c b/contrib/ffmpeg/libavcodec/cyuv.c
index 101f2bd85..101f2bd85 100644
--- a/src/libffmpeg/libavcodec/cyuv.c
+++ b/contrib/ffmpeg/libavcodec/cyuv.c
diff --git a/contrib/ffmpeg/libavcodec/dca.c b/contrib/ffmpeg/libavcodec/dca.c
new file mode 100644
index 000000000..a57dcdc44
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/dca.c
@@ -0,0 +1,1322 @@
+/*
+ * DCA compatible decoder
+ * Copyright (C) 2004 Gildas Bazin
+ * Copyright (C) 2004 Benjamin Zores
+ * Copyright (C) 2006 Benjamin Larsson
+ * Copyright (C) 2007 Konstantin Shishkov
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file dca.c
+ */
+
+#include <math.h>
+#include <stddef.h>
+#include <stdio.h>
+
+#include "avcodec.h"
+#include "dsputil.h"
+#include "bitstream.h"
+#include "dcadata.h"
+#include "dcahuff.h"
+#include "parser.h"
+
+/** DCA syncwords, also used for bitstream type detection */
+//@{
+#define DCA_MARKER_RAW_BE 0x7FFE8001
+#define DCA_MARKER_RAW_LE 0xFE7F0180
+#define DCA_MARKER_14B_BE 0x1FFFE800
+#define DCA_MARKER_14B_LE 0xFF1F00E8
+//@}
+
+//#define TRACE
+
+#define DCA_PRIM_CHANNELS_MAX (5)
+#define DCA_SUBBANDS (32)
+#define DCA_ABITS_MAX (32) /* Should be 28 */
+#define DCA_SUBSUBFAMES_MAX (4)
+#define DCA_LFE_MAX (3)
+
+enum DCAMode {
+ DCA_MONO = 0,
+ DCA_CHANNEL,
+ DCA_STEREO,
+ DCA_STEREO_SUMDIFF,
+ DCA_STEREO_TOTAL,
+ DCA_3F,
+ DCA_2F1R,
+ DCA_3F1R,
+ DCA_2F2R,
+ DCA_3F2R,
+ DCA_4F2R
+};
+
+#define DCA_DOLBY 101 /* FIXME */
+
+#define DCA_CHANNEL_BITS 6
+#define DCA_CHANNEL_MASK 0x3F
+
+#define DCA_LFE 0x80
+
+#define HEADER_SIZE 14
+#define CONVERT_BIAS 384
+
+#define DCA_MAX_FRAME_SIZE 16383
+
+/** Bit allocation */
+typedef struct {
+ int offset; ///< code values offset
+ int maxbits[8]; ///< max bits in VLC
+ int wrap; ///< wrap for get_vlc2()
+ VLC vlc[8]; ///< actual codes
+} BitAlloc;
+
+static BitAlloc dca_bitalloc_index; ///< indexes for samples VLC select
+static BitAlloc dca_tmode; ///< transition mode VLCs
+static BitAlloc dca_scalefactor; ///< scalefactor VLCs
+static BitAlloc dca_smpl_bitalloc[11]; ///< samples VLCs
+
+/** Pre-calculated cosine modulation coefs for the QMF */
+static float cos_mod[544];
+
+static int av_always_inline get_bitalloc(GetBitContext *gb, BitAlloc *ba, int idx)
+{
+ return get_vlc2(gb, ba->vlc[idx].table, ba->vlc[idx].bits, ba->wrap) + ba->offset;
+}
+
+typedef struct {
+ AVCodecContext *avctx;
+ /* Frame header */
+ int frame_type; ///< type of the current frame
+ int samples_deficit; ///< deficit sample count
+ int crc_present; ///< crc is present in the bitstream
+ int sample_blocks; ///< number of PCM sample blocks
+ int frame_size; ///< primary frame byte size
+ int amode; ///< audio channels arrangement
+ int sample_rate; ///< audio sampling rate
+ int bit_rate; ///< transmission bit rate
+
+ int downmix; ///< embedded downmix enabled
+ int dynrange; ///< embedded dynamic range flag
+ int timestamp; ///< embedded time stamp flag
+ int aux_data; ///< auxiliary data flag
+ int hdcd; ///< source material is mastered in HDCD
+ int ext_descr; ///< extension audio descriptor flag
+ int ext_coding; ///< extended coding flag
+ int aspf; ///< audio sync word insertion flag
+ int lfe; ///< low frequency effects flag
+ int predictor_history; ///< predictor history flag
+ int header_crc; ///< header crc check bytes
+ int multirate_inter; ///< multirate interpolator switch
+ int version; ///< encoder software revision
+ int copy_history; ///< copy history
+ int source_pcm_res; ///< source pcm resolution
+ int front_sum; ///< front sum/difference flag
+ int surround_sum; ///< surround sum/difference flag
+ int dialog_norm; ///< dialog normalisation parameter
+
+ /* Primary audio coding header */
+ int subframes; ///< number of subframes
+ int prim_channels; ///< number of primary audio channels
+ int subband_activity[DCA_PRIM_CHANNELS_MAX]; ///< subband activity count
+ int vq_start_subband[DCA_PRIM_CHANNELS_MAX]; ///< high frequency vq start subband
+ int joint_intensity[DCA_PRIM_CHANNELS_MAX]; ///< joint intensity coding index
+ int transient_huffman[DCA_PRIM_CHANNELS_MAX]; ///< transient mode code book
+ int scalefactor_huffman[DCA_PRIM_CHANNELS_MAX]; ///< scale factor code book
+ int bitalloc_huffman[DCA_PRIM_CHANNELS_MAX]; ///< bit allocation quantizer select
+ int quant_index_huffman[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX]; ///< quantization index codebook select
+ float scalefactor_adj[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX]; ///< scale factor adjustment
+
+ /* Primary audio coding side information */
+ int subsubframes; ///< number of subsubframes
+ int partial_samples; ///< partial subsubframe samples count
+ int prediction_mode[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< prediction mode (ADPCM used or not)
+ int prediction_vq[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< prediction VQ coefs
+ int bitalloc[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< bit allocation index
+ int transition_mode[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< transition mode (transients)
+ int scale_factor[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][2]; ///< scale factors (2 if transient)
+ int joint_huff[DCA_PRIM_CHANNELS_MAX]; ///< joint subband scale factors codebook
+ int joint_scale_factor[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< joint subband scale factors
+ int downmix_coef[DCA_PRIM_CHANNELS_MAX][2]; ///< stereo downmix coefficients
+ int dynrange_coef; ///< dynamic range coefficient
+
+ int high_freq_vq[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< VQ encoded high frequency subbands
+
+ float lfe_data[2 * DCA_SUBSUBFAMES_MAX * DCA_LFE_MAX *
+ 2 /*history */ ]; ///< Low frequency effect data
+ int lfe_scale_factor;
+
+ /* Subband samples history (for ADPCM) */
+ float subband_samples_hist[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][4];
+ float subband_fir_hist[DCA_PRIM_CHANNELS_MAX][512];
+ float subband_fir_noidea[DCA_PRIM_CHANNELS_MAX][64];
+
+ int output; ///< type of output
+ int bias; ///< output bias
+
+ DECLARE_ALIGNED_16(float, samples[1536]); /* 6 * 256 = 1536, might only need 5 */
+ DECLARE_ALIGNED_16(int16_t, tsamples[1536]);
+
+ uint8_t dca_buffer[DCA_MAX_FRAME_SIZE];
+ int dca_buffer_size; ///< how much data is in the dca_buffer
+
+ GetBitContext gb;
+ /* Current position in DCA frame */
+ int current_subframe;
+ int current_subsubframe;
+
+ int debug_flag; ///< used for suppressing repeated error messages output
+ DSPContext dsp;
+} DCAContext;
+
+static void dca_init_vlcs()
+{
+ static int vlcs_inited = 0;
+ int i, j;
+
+ if (vlcs_inited)
+ return;
+
+ dca_bitalloc_index.offset = 1;
+ dca_bitalloc_index.wrap = 1;
+ for (i = 0; i < 5; i++)
+ init_vlc(&dca_bitalloc_index.vlc[i], bitalloc_12_vlc_bits[i], 12,
+ bitalloc_12_bits[i], 1, 1,
+ bitalloc_12_codes[i], 2, 2, 1);
+ dca_scalefactor.offset = -64;
+ dca_scalefactor.wrap = 2;
+ for (i = 0; i < 5; i++)
+ init_vlc(&dca_scalefactor.vlc[i], SCALES_VLC_BITS, 129,
+ scales_bits[i], 1, 1,
+ scales_codes[i], 2, 2, 1);
+ dca_tmode.offset = 0;
+ dca_tmode.wrap = 1;
+ for (i = 0; i < 4; i++)
+ init_vlc(&dca_tmode.vlc[i], tmode_vlc_bits[i], 4,
+ tmode_bits[i], 1, 1,
+ tmode_codes[i], 2, 2, 1);
+
+ for(i = 0; i < 10; i++)
+ for(j = 0; j < 7; j++){
+ if(!bitalloc_codes[i][j]) break;
+ dca_smpl_bitalloc[i+1].offset = bitalloc_offsets[i];
+ dca_smpl_bitalloc[i+1].wrap = 1 + (j > 4);
+ init_vlc(&dca_smpl_bitalloc[i+1].vlc[j], bitalloc_maxbits[i][j],
+ bitalloc_sizes[i],
+ bitalloc_bits[i][j], 1, 1,
+ bitalloc_codes[i][j], 2, 2, 1);
+ }
+ vlcs_inited = 1;
+}
+
+static inline void get_array(GetBitContext *gb, int *dst, int len, int bits)
+{
+ while(len--)
+ *dst++ = get_bits(gb, bits);
+}
+
+static int dca_parse_frame_header(DCAContext * s)
+{
+ int i, j;
+ static const float adj_table[4] = { 1.0, 1.1250, 1.2500, 1.4375 };
+ static const int bitlen[11] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 };
+ static const int thr[11] = { 0, 1, 3, 3, 3, 3, 7, 7, 7, 7, 7 };
+
+ s->bias = CONVERT_BIAS;
+
+ init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8);
+
+ /* Sync code */
+ get_bits(&s->gb, 32);
+
+ /* Frame header */
+ s->frame_type = get_bits(&s->gb, 1);
+ s->samples_deficit = get_bits(&s->gb, 5) + 1;
+ s->crc_present = get_bits(&s->gb, 1);
+ s->sample_blocks = get_bits(&s->gb, 7) + 1;
+ s->frame_size = get_bits(&s->gb, 14) + 1;
+ if (s->frame_size < 95)
+ return -1;
+ s->amode = get_bits(&s->gb, 6);
+ s->sample_rate = dca_sample_rates[get_bits(&s->gb, 4)];
+ if (!s->sample_rate)
+ return -1;
+ s->bit_rate = dca_bit_rates[get_bits(&s->gb, 5)];
+ if (!s->bit_rate)
+ return -1;
+
+ s->downmix = get_bits(&s->gb, 1);
+ s->dynrange = get_bits(&s->gb, 1);
+ s->timestamp = get_bits(&s->gb, 1);
+ s->aux_data = get_bits(&s->gb, 1);
+ s->hdcd = get_bits(&s->gb, 1);
+ s->ext_descr = get_bits(&s->gb, 3);
+ s->ext_coding = get_bits(&s->gb, 1);
+ s->aspf = get_bits(&s->gb, 1);
+ s->lfe = get_bits(&s->gb, 2);
+ s->predictor_history = get_bits(&s->gb, 1);
+
+ /* TODO: check CRC */
+ if (s->crc_present)
+ s->header_crc = get_bits(&s->gb, 16);
+
+ s->multirate_inter = get_bits(&s->gb, 1);
+ s->version = get_bits(&s->gb, 4);
+ s->copy_history = get_bits(&s->gb, 2);
+ s->source_pcm_res = get_bits(&s->gb, 3);
+ s->front_sum = get_bits(&s->gb, 1);
+ s->surround_sum = get_bits(&s->gb, 1);
+ s->dialog_norm = get_bits(&s->gb, 4);
+
+ /* FIXME: channels mixing levels */
+ s->output = DCA_STEREO;
+
+#ifdef TRACE
+ av_log(s->avctx, AV_LOG_DEBUG, "frame type: %i\n", s->frame_type);
+ av_log(s->avctx, AV_LOG_DEBUG, "samples deficit: %i\n", s->samples_deficit);
+ av_log(s->avctx, AV_LOG_DEBUG, "crc present: %i\n", s->crc_present);
+ av_log(s->avctx, AV_LOG_DEBUG, "sample blocks: %i (%i samples)\n",
+ s->sample_blocks, s->sample_blocks * 32);
+ av_log(s->avctx, AV_LOG_DEBUG, "frame size: %i bytes\n", s->frame_size);
+ av_log(s->avctx, AV_LOG_DEBUG, "amode: %i (%i channels)\n",
+ s->amode, dca_channels[s->amode]);
+ av_log(s->avctx, AV_LOG_DEBUG, "sample rate: %i (%i Hz)\n",
+ s->sample_rate, dca_sample_rates[s->sample_rate]);
+ av_log(s->avctx, AV_LOG_DEBUG, "bit rate: %i (%i bits/s)\n",
+ s->bit_rate, dca_bit_rates[s->bit_rate]);
+ av_log(s->avctx, AV_LOG_DEBUG, "downmix: %i\n", s->downmix);
+ av_log(s->avctx, AV_LOG_DEBUG, "dynrange: %i\n", s->dynrange);
+ av_log(s->avctx, AV_LOG_DEBUG, "timestamp: %i\n", s->timestamp);
+ av_log(s->avctx, AV_LOG_DEBUG, "aux_data: %i\n", s->aux_data);
+ av_log(s->avctx, AV_LOG_DEBUG, "hdcd: %i\n", s->hdcd);
+ av_log(s->avctx, AV_LOG_DEBUG, "ext descr: %i\n", s->ext_descr);
+ av_log(s->avctx, AV_LOG_DEBUG, "ext coding: %i\n", s->ext_coding);
+ av_log(s->avctx, AV_LOG_DEBUG, "aspf: %i\n", s->aspf);
+ av_log(s->avctx, AV_LOG_DEBUG, "lfe: %i\n", s->lfe);
+ av_log(s->avctx, AV_LOG_DEBUG, "predictor history: %i\n",
+ s->predictor_history);
+ av_log(s->avctx, AV_LOG_DEBUG, "header crc: %i\n", s->header_crc);
+ av_log(s->avctx, AV_LOG_DEBUG, "multirate inter: %i\n",
+ s->multirate_inter);
+ av_log(s->avctx, AV_LOG_DEBUG, "version number: %i\n", s->version);
+ av_log(s->avctx, AV_LOG_DEBUG, "copy history: %i\n", s->copy_history);
+ av_log(s->avctx, AV_LOG_DEBUG,
+ "source pcm resolution: %i (%i bits/sample)\n",
+ s->source_pcm_res, dca_bits_per_sample[s->source_pcm_res]);
+ av_log(s->avctx, AV_LOG_DEBUG, "front sum: %i\n", s->front_sum);
+ av_log(s->avctx, AV_LOG_DEBUG, "surround sum: %i\n", s->surround_sum);
+ av_log(s->avctx, AV_LOG_DEBUG, "dialog norm: %i\n", s->dialog_norm);
+ av_log(s->avctx, AV_LOG_DEBUG, "\n");
+#endif
+
+ /* Primary audio coding header */
+ s->subframes = get_bits(&s->gb, 4) + 1;
+ s->prim_channels = get_bits(&s->gb, 3) + 1;
+
+
+ for (i = 0; i < s->prim_channels; i++) {
+ s->subband_activity[i] = get_bits(&s->gb, 5) + 2;
+ if (s->subband_activity[i] > DCA_SUBBANDS)
+ s->subband_activity[i] = DCA_SUBBANDS;
+ }
+ for (i = 0; i < s->prim_channels; i++) {
+ s->vq_start_subband[i] = get_bits(&s->gb, 5) + 1;
+ if (s->vq_start_subband[i] > DCA_SUBBANDS)
+ s->vq_start_subband[i] = DCA_SUBBANDS;
+ }
+ get_array(&s->gb, s->joint_intensity, s->prim_channels, 3);
+ get_array(&s->gb, s->transient_huffman, s->prim_channels, 2);
+ get_array(&s->gb, s->scalefactor_huffman, s->prim_channels, 3);
+ get_array(&s->gb, s->bitalloc_huffman, s->prim_channels, 3);
+
+ /* Get codebooks quantization indexes */
+ memset(s->quant_index_huffman, 0, sizeof(s->quant_index_huffman));
+ for (j = 1; j < 11; j++)
+ for (i = 0; i < s->prim_channels; i++)
+ s->quant_index_huffman[i][j] = get_bits(&s->gb, bitlen[j]);
+
+ /* Get scale factor adjustment */
+ for (j = 0; j < 11; j++)
+ for (i = 0; i < s->prim_channels; i++)
+ s->scalefactor_adj[i][j] = 1;
+
+ for (j = 1; j < 11; j++)
+ for (i = 0; i < s->prim_channels; i++)
+ if (s->quant_index_huffman[i][j] < thr[j])
+ s->scalefactor_adj[i][j] = adj_table[get_bits(&s->gb, 2)];
+
+ if (s->crc_present) {
+ /* Audio header CRC check */
+ get_bits(&s->gb, 16);
+ }
+
+ s->current_subframe = 0;
+ s->current_subsubframe = 0;
+
+#ifdef TRACE
+ av_log(s->avctx, AV_LOG_DEBUG, "subframes: %i\n", s->subframes);
+ av_log(s->avctx, AV_LOG_DEBUG, "prim channels: %i\n", s->prim_channels);
+ for(i = 0; i < s->prim_channels; i++){
+ av_log(s->avctx, AV_LOG_DEBUG, "subband activity: %i\n", s->subband_activity[i]);
+ av_log(s->avctx, AV_LOG_DEBUG, "vq start subband: %i\n", s->vq_start_subband[i]);
+ av_log(s->avctx, AV_LOG_DEBUG, "joint intensity: %i\n", s->joint_intensity[i]);
+ av_log(s->avctx, AV_LOG_DEBUG, "transient mode codebook: %i\n", s->transient_huffman[i]);
+ av_log(s->avctx, AV_LOG_DEBUG, "scale factor codebook: %i\n", s->scalefactor_huffman[i]);
+ av_log(s->avctx, AV_LOG_DEBUG, "bit allocation quantizer: %i\n", s->bitalloc_huffman[i]);
+ av_log(s->avctx, AV_LOG_DEBUG, "quant index huff:");
+ for (j = 0; j < 11; j++)
+ av_log(s->avctx, AV_LOG_DEBUG, " %i",
+ s->quant_index_huffman[i][j]);
+ av_log(s->avctx, AV_LOG_DEBUG, "\n");
+ av_log(s->avctx, AV_LOG_DEBUG, "scalefac adj:");
+ for (j = 0; j < 11; j++)
+ av_log(s->avctx, AV_LOG_DEBUG, " %1.3f", s->scalefactor_adj[i][j]);
+ av_log(s->avctx, AV_LOG_DEBUG, "\n");
+ }
+#endif
+
+ return 0;
+}
+
+
+static inline int get_scale(GetBitContext *gb, int level, int index, int value)
+{
+ if (level < 5) {
+ /* huffman encoded */
+ value += get_bitalloc(gb, &dca_scalefactor, index);
+ } else if(level < 8)
+ value = get_bits(gb, level + 1);
+ return value;
+}
+
+static int dca_subframe_header(DCAContext * s)
+{
+ /* Primary audio coding side information */
+ int j, k;
+
+ s->subsubframes = get_bits(&s->gb, 2) + 1;
+ s->partial_samples = get_bits(&s->gb, 3);
+ for (j = 0; j < s->prim_channels; j++) {
+ for (k = 0; k < s->subband_activity[j]; k++)
+ s->prediction_mode[j][k] = get_bits(&s->gb, 1);
+ }
+
+ /* Get prediction codebook */
+ for (j = 0; j < s->prim_channels; j++) {
+ for (k = 0; k < s->subband_activity[j]; k++) {
+ if (s->prediction_mode[j][k] > 0) {
+ /* (Prediction coefficient VQ address) */
+ s->prediction_vq[j][k] = get_bits(&s->gb, 12);
+ }
+ }
+ }
+
+ /* Bit allocation index */
+ for (j = 0; j < s->prim_channels; j++) {
+ for (k = 0; k < s->vq_start_subband[j]; k++) {
+ if (s->bitalloc_huffman[j] == 6)
+ s->bitalloc[j][k] = get_bits(&s->gb, 5);
+ else if (s->bitalloc_huffman[j] == 5)
+ s->bitalloc[j][k] = get_bits(&s->gb, 4);
+ else {
+ s->bitalloc[j][k] =
+ get_bitalloc(&s->gb, &dca_bitalloc_index, j);
+ }
+
+ if (s->bitalloc[j][k] > 26) {
+// av_log(s->avctx,AV_LOG_DEBUG,"bitalloc index [%i][%i] too big (%i)\n",
+// j, k, s->bitalloc[j][k]);
+ return -1;
+ }
+ }
+ }
+
+ /* Transition mode */
+ for (j = 0; j < s->prim_channels; j++) {
+ for (k = 0; k < s->subband_activity[j]; k++) {
+ s->transition_mode[j][k] = 0;
+ if (s->subsubframes > 1 &&
+ k < s->vq_start_subband[j] && s->bitalloc[j][k] > 0) {
+ s->transition_mode[j][k] =
+ get_bitalloc(&s->gb, &dca_tmode, s->transient_huffman[j]);
+ }
+ }
+ }
+
+ for (j = 0; j < s->prim_channels; j++) {
+ uint32_t *scale_table;
+ int scale_sum;
+
+ memset(s->scale_factor[j], 0, s->subband_activity[j] * sizeof(s->scale_factor[0][0][0]) * 2);
+
+ if (s->scalefactor_huffman[j] == 6)
+ scale_table = (uint32_t *) scale_factor_quant7;
+ else
+ scale_table = (uint32_t *) scale_factor_quant6;
+
+ /* When huffman coded, only the difference is encoded */
+ scale_sum = 0;
+
+ for (k = 0; k < s->subband_activity[j]; k++) {
+ if (k >= s->vq_start_subband[j] || s->bitalloc[j][k] > 0) {
+ scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], j, scale_sum);
+ s->scale_factor[j][k][0] = scale_table[scale_sum];
+ }
+
+ if (k < s->vq_start_subband[j] && s->transition_mode[j][k]) {
+ /* Get second scale factor */
+ scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], j, scale_sum);
+ s->scale_factor[j][k][1] = scale_table[scale_sum];
+ }
+ }
+ }
+
+ /* Joint subband scale factor codebook select */
+ for (j = 0; j < s->prim_channels; j++) {
+ /* Transmitted only if joint subband coding enabled */
+ if (s->joint_intensity[j] > 0)
+ s->joint_huff[j] = get_bits(&s->gb, 3);
+ }
+
+ /* Scale factors for joint subband coding */
+ for (j = 0; j < s->prim_channels; j++) {
+ int source_channel;
+
+ /* Transmitted only if joint subband coding enabled */
+ if (s->joint_intensity[j] > 0) {
+ int scale = 0;
+ source_channel = s->joint_intensity[j] - 1;
+
+ /* When huffman coded, only the difference is encoded
+ * (is this valid as well for joint scales ???) */
+
+ for (k = s->subband_activity[j]; k < s->subband_activity[source_channel]; k++) {
+ scale = get_scale(&s->gb, s->joint_huff[j], j, 0);
+ scale += 64; /* bias */
+ s->joint_scale_factor[j][k] = scale; /*joint_scale_table[scale]; */
+ }
+
+ if (!s->debug_flag & 0x02) {
+ av_log(s->avctx, AV_LOG_DEBUG,
+ "Joint stereo coding not supported\n");
+ s->debug_flag |= 0x02;
+ }
+ }
+ }
+
+ /* Stereo downmix coefficients */
+ if (s->prim_channels > 2 && s->downmix) {
+ for (j = 0; j < s->prim_channels; j++) {
+ s->downmix_coef[j][0] = get_bits(&s->gb, 7);
+ s->downmix_coef[j][1] = get_bits(&s->gb, 7);
+ }
+ }
+
+ /* Dynamic range coefficient */
+ if (s->dynrange)
+ s->dynrange_coef = get_bits(&s->gb, 8);
+
+ /* Side information CRC check word */
+ if (s->crc_present) {
+ get_bits(&s->gb, 16);
+ }
+
+ /*
+ * Primary audio data arrays
+ */
+
+ /* VQ encoded high frequency subbands */
+ for (j = 0; j < s->prim_channels; j++)
+ for (k = s->vq_start_subband[j]; k < s->subband_activity[j]; k++)
+ /* 1 vector -> 32 samples */
+ s->high_freq_vq[j][k] = get_bits(&s->gb, 10);
+
+ /* Low frequency effect data */
+ if (s->lfe) {
+ /* LFE samples */
+ int lfe_samples = 2 * s->lfe * s->subsubframes;
+ float lfe_scale;
+
+ for (j = lfe_samples; j < lfe_samples * 2; j++) {
+ /* Signed 8 bits int */
+ s->lfe_data[j] = get_sbits(&s->gb, 8);
+ }
+
+ /* Scale factor index */
+ s->lfe_scale_factor = scale_factor_quant7[get_bits(&s->gb, 8)];
+
+ /* Quantization step size * scale factor */
+ lfe_scale = 0.035 * s->lfe_scale_factor;
+
+ for (j = lfe_samples; j < lfe_samples * 2; j++)
+ s->lfe_data[j] *= lfe_scale;
+ }
+
+#ifdef TRACE
+ av_log(s->avctx, AV_LOG_DEBUG, "subsubframes: %i\n", s->subsubframes);
+ av_log(s->avctx, AV_LOG_DEBUG, "partial samples: %i\n",
+ s->partial_samples);
+ for (j = 0; j < s->prim_channels; j++) {
+ av_log(s->avctx, AV_LOG_DEBUG, "prediction mode:");
+ for (k = 0; k < s->subband_activity[j]; k++)
+ av_log(s->avctx, AV_LOG_DEBUG, " %i", s->prediction_mode[j][k]);
+ av_log(s->avctx, AV_LOG_DEBUG, "\n");
+ }
+ for (j = 0; j < s->prim_channels; j++) {
+ for (k = 0; k < s->subband_activity[j]; k++)
+ av_log(s->avctx, AV_LOG_DEBUG,
+ "prediction coefs: %f, %f, %f, %f\n",
+ (float) adpcm_vb[s->prediction_vq[j][k]][0] / 8192,
+ (float) adpcm_vb[s->prediction_vq[j][k]][1] / 8192,
+ (float) adpcm_vb[s->prediction_vq[j][k]][2] / 8192,
+ (float) adpcm_vb[s->prediction_vq[j][k]][3] / 8192);
+ }
+ for (j = 0; j < s->prim_channels; j++) {
+ av_log(s->avctx, AV_LOG_DEBUG, "bitalloc index: ");
+ for (k = 0; k < s->vq_start_subband[j]; k++)
+ av_log(s->avctx, AV_LOG_DEBUG, "%2.2i ", s->bitalloc[j][k]);
+ av_log(s->avctx, AV_LOG_DEBUG, "\n");
+ }
+ for (j = 0; j < s->prim_channels; j++) {
+ av_log(s->avctx, AV_LOG_DEBUG, "Transition mode:");
+ for (k = 0; k < s->subband_activity[j]; k++)
+ av_log(s->avctx, AV_LOG_DEBUG, " %i", s->transition_mode[j][k]);
+ av_log(s->avctx, AV_LOG_DEBUG, "\n");
+ }
+ for (j = 0; j < s->prim_channels; j++) {
+ av_log(s->avctx, AV_LOG_DEBUG, "Scale factor:");
+ for (k = 0; k < s->subband_activity[j]; k++) {
+ if (k >= s->vq_start_subband[j] || s->bitalloc[j][k] > 0)
+ av_log(s->avctx, AV_LOG_DEBUG, " %i", s->scale_factor[j][k][0]);
+ if (k < s->vq_start_subband[j] && s->transition_mode[j][k])
+ av_log(s->avctx, AV_LOG_DEBUG, " %i(t)", s->scale_factor[j][k][1]);
+ }
+ av_log(s->avctx, AV_LOG_DEBUG, "\n");
+ }
+ for (j = 0; j < s->prim_channels; j++) {
+ if (s->joint_intensity[j] > 0) {
+ av_log(s->avctx, AV_LOG_DEBUG, "Joint scale factor index:\n");
+ for (k = s->subband_activity[j]; k < s->subband_activity[source_channel]; k++)
+ av_log(s->avctx, AV_LOG_DEBUG, " %i", s->joint_scale_factor[j][k]);
+ av_log(s->avctx, AV_LOG_DEBUG, "\n");
+ }
+ }
+ if (s->prim_channels > 2 && s->downmix) {
+ av_log(s->avctx, AV_LOG_DEBUG, "Downmix coeffs:\n");
+ for (j = 0; j < s->prim_channels; j++) {
+ av_log(s->avctx, AV_LOG_DEBUG, "Channel 0,%d = %f\n", j, dca_downmix_coeffs[s->downmix_coef[j][0]]);
+ av_log(s->avctx, AV_LOG_DEBUG, "Channel 1,%d = %f\n", j, dca_downmix_coeffs[s->downmix_coef[j][1]]);
+ }
+ av_log(s->avctx, AV_LOG_DEBUG, "\n");
+ }
+ for (j = 0; j < s->prim_channels; j++)
+ for (k = s->vq_start_subband[j]; k < s->subband_activity[j]; k++)
+ av_log(s->avctx, AV_LOG_DEBUG, "VQ index: %i\n", s->high_freq_vq[j][k]);
+ if(s->lfe){
+ av_log(s->avctx, AV_LOG_DEBUG, "LFE samples:\n");
+ for (j = lfe_samples; j < lfe_samples * 2; j++)
+ av_log(s->avctx, AV_LOG_DEBUG, " %f", s->lfe_data[j]);
+ av_log(s->avctx, AV_LOG_DEBUG, "\n");
+ }
+#endif
+
+ return 0;
+}
+
+static void qmf_32_subbands(DCAContext * s, int chans,
+ float samples_in[32][8], float *samples_out,
+ float scale, float bias)
+{
+ float *prCoeff;
+ int i, j, k;
+ float praXin[33], *raXin = &praXin[1];
+
+ float *subband_fir_hist = s->subband_fir_hist[chans];
+ float *subband_fir_hist2 = s->subband_fir_noidea[chans];
+
+ int chindex = 0, subindex;
+
+ praXin[0] = 0.0;
+
+ /* Select filter */
+ if (!s->multirate_inter) /* Non-perfect reconstruction */
+ prCoeff = (float *) fir_32bands_nonperfect;
+ else /* Perfect reconstruction */
+ prCoeff = (float *) fir_32bands_perfect;
+
+ /* Reconstructed channel sample index */
+ for (subindex = 0; subindex < 8; subindex++) {
+ float t1, t2, sum[16], diff[16];
+
+ /* Load in one sample from each subband and clear inactive subbands */
+ for (i = 0; i < s->subband_activity[chans]; i++)
+ raXin[i] = samples_in[i][subindex];
+ for (; i < 32; i++)
+ raXin[i] = 0.0;
+
+ /* Multiply by cosine modulation coefficients and
+ * create temporary arrays SUM and DIFF */
+ for (j = 0, k = 0; k < 16; k++) {
+ t1 = 0.0;
+ t2 = 0.0;
+ for (i = 0; i < 16; i++, j++){
+ t1 += (raXin[2 * i] + raXin[2 * i + 1]) * cos_mod[j];
+ t2 += (raXin[2 * i] + raXin[2 * i - 1]) * cos_mod[j + 256];
+ }
+ sum[k] = t1 + t2;
+ diff[k] = t1 - t2;
+ }
+
+ j = 512;
+ /* Store history */
+ for (k = 0; k < 16; k++)
+ subband_fir_hist[k] = cos_mod[j++] * sum[k];
+ for (k = 0; k < 16; k++)
+ subband_fir_hist[32-k-1] = cos_mod[j++] * diff[k];
+
+ /* Multiply by filter coefficients */
+ for (k = 31, i = 0; i < 32; i++, k--)
+ for (j = 0; j < 512; j += 64){
+ subband_fir_hist2[i] += prCoeff[i+j] * ( subband_fir_hist[i+j] - subband_fir_hist[j+k]);
+ subband_fir_hist2[i+32] += prCoeff[i+j+32]*(-subband_fir_hist[i+j] - subband_fir_hist[j+k]);
+ }
+
+ /* Create 32 PCM output samples */
+ for (i = 0; i < 32; i++)
+ samples_out[chindex++] = subband_fir_hist2[i] * scale + bias;
+
+ /* Update working arrays */
+ memmove(&subband_fir_hist[32], &subband_fir_hist[0], (512 - 32) * sizeof(float));
+ memmove(&subband_fir_hist2[0], &subband_fir_hist2[32], 32 * sizeof(float));
+ memset(&subband_fir_hist2[32], 0, 32 * sizeof(float));
+ }
+}
+
+static void lfe_interpolation_fir(int decimation_select,
+ int num_deci_sample, float *samples_in,
+ float *samples_out, float scale,
+ float bias)
+{
+ /* samples_in: An array holding decimated samples.
+ * Samples in current subframe starts from samples_in[0],
+ * while samples_in[-1], samples_in[-2], ..., stores samples
+ * from last subframe as history.
+ *
+ * samples_out: An array holding interpolated samples
+ */
+
+ int decifactor, k, j;
+ const float *prCoeff;
+
+ int interp_index = 0; /* Index to the interpolated samples */
+ int deciindex;
+
+ /* Select decimation filter */
+ if (decimation_select == 1) {
+ decifactor = 128;
+ prCoeff = lfe_fir_128;
+ } else {
+ decifactor = 64;
+ 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;
+ }
+ }
+}
+
+/* downmixing routines */
+#define MIX_REAR1(samples, si1) \
+ samples[i] += samples[si1]; \
+ samples[i+256] += samples[si1];
+
+#define MIX_REAR2(samples, si1, si2) \
+ samples[i] += samples[si1]; \
+ samples[i+256] += samples[si2];
+
+#define MIX_FRONT3(samples) \
+ t = samples[i]; \
+ samples[i] += samples[i+256]; \
+ samples[i+256] = samples[i+512] + t;
+
+#define DOWNMIX_TO_STEREO(op1, op2) \
+ for(i = 0; i < 256; i++){ \
+ op1 \
+ op2 \
+ }
+
+static void dca_downmix(float *samples, int srcfmt)
+{
+ int i;
+ float t;
+
+ switch (srcfmt) {
+ case DCA_MONO:
+ case DCA_CHANNEL:
+ case DCA_STEREO_TOTAL:
+ case DCA_STEREO_SUMDIFF:
+ case DCA_4F2R:
+ av_log(NULL, 0, "Not implemented!\n");
+ break;
+ case DCA_STEREO:
+ break;
+ case DCA_3F:
+ DOWNMIX_TO_STEREO(MIX_FRONT3(samples),);
+ break;
+ case DCA_2F1R:
+ DOWNMIX_TO_STEREO(MIX_REAR1(samples, i + 512),);
+ break;
+ case DCA_3F1R:
+ DOWNMIX_TO_STEREO(MIX_FRONT3(samples),
+ MIX_REAR1(samples, i + 768));
+ break;
+ case DCA_2F2R:
+ DOWNMIX_TO_STEREO(MIX_REAR2(samples, i + 512, i + 768),);
+ break;
+ case DCA_3F2R:
+ DOWNMIX_TO_STEREO(MIX_FRONT3(samples),
+ MIX_REAR2(samples, i + 768, i + 1024));
+ break;
+ }
+}
+
+
+/* Very compact version of the block code decoder that does not use table
+ * look-up but is slightly slower */
+static int decode_blockcode(int code, int levels, int *values)
+{
+ int i;
+ int offset = (levels - 1) >> 1;
+
+ for (i = 0; i < 4; i++) {
+ values[i] = (code % levels) - offset;
+ code /= levels;
+ }
+
+ if (code == 0)
+ return 0;
+ else {
+ av_log(NULL, AV_LOG_ERROR, "ERROR: block code look-up failed\n");
+ return -1;
+ }
+}
+
+static const uint8_t abits_sizes[7] = { 7, 10, 12, 13, 15, 17, 19 };
+static const uint8_t abits_levels[7] = { 3, 5, 7, 9, 13, 17, 25 };
+
+static int dca_subsubframe(DCAContext * s)
+{
+ int k, l;
+ int subsubframe = s->current_subsubframe;
+
+ float *quant_step_table;
+
+ /* FIXME */
+ float subband_samples[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][8];
+
+ /*
+ * Audio data
+ */
+
+ /* Select quantization step size table */
+ if (s->bit_rate == 0x1f)
+ quant_step_table = (float *) lossless_quant_d;
+ else
+ quant_step_table = (float *) lossy_quant_d;
+
+ for (k = 0; k < s->prim_channels; k++) {
+ for (l = 0; l < s->vq_start_subband[k]; l++) {
+ int m;
+
+ /* Select the mid-tread linear quantizer */
+ int abits = s->bitalloc[k][l];
+
+ float quant_step_size = quant_step_table[abits];
+ float rscale;
+
+ /*
+ * Determine quantization index code book and its type
+ */
+
+ /* Select quantization index code book */
+ int sel = s->quant_index_huffman[k][abits];
+
+ /*
+ * Extract bits from the bit stream
+ */
+ 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];
+
+ 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]);
+ for (m = 0; m < 8; m++)
+ subband_samples[k][l][m] = block[m];
+ }else{
+ /* no coding */
+ for (m = 0; m < 8; m++)
+ subband_samples[k][l][m] = get_sbits(&s->gb, abits - 3);
+ }
+ }else{
+ /* Huffman coded */
+ for (m = 0; m < 8; m++)
+ subband_samples[k][l][m] = get_bitalloc(&s->gb, &dca_smpl_bitalloc[abits], sel);
+ }
+
+ /* 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
+ */
+ if (s->prediction_mode[k][l]) {
+ int n;
+ for (m = 0; m < 8; m++) {
+ for (n = 1; n <= 4; n++)
+ if (m >= n)
+ subband_samples[k][l][m] +=
+ (adpcm_vb[s->prediction_vq[k][l]][n - 1] *
+ subband_samples[k][l][m - n] / 8192);
+ else if (s->predictor_history)
+ subband_samples[k][l][m] +=
+ (adpcm_vb[s->prediction_vq[k][l]][n - 1] *
+ s->subband_samples_hist[k][l][m - n +
+ 4] / 8192);
+ }
+ }
+ }
+
+ /*
+ * Decode VQ encoded high frequencies
+ */
+ for (l = s->vq_start_subband[k]; l < s->subband_activity[k]; l++) {
+ /* 1 vector -> 32 samples but we only need the 8 samples
+ * for this subsubframe. */
+ int m;
+
+ if (!s->debug_flag & 0x01) {
+ av_log(s->avctx, AV_LOG_DEBUG, "Stream with high frequencies VQ coding\n");
+ s->debug_flag |= 0x01;
+ }
+
+ for (m = 0; m < 8; m++) {
+ subband_samples[k][l][m] =
+ high_freq_vq[s->high_freq_vq[k][l]][subsubframe * 8 +
+ m]
+ * (float) s->scale_factor[k][l][0] / 16.0;
+ }
+ }
+ }
+
+ /* Check for DSYNC after subsubframe */
+ if (s->aspf || subsubframe == s->subsubframes - 1) {
+ if (0xFFFF == get_bits(&s->gb, 16)) { /* 0xFFFF */
+#ifdef TRACE
+ av_log(s->avctx, AV_LOG_DEBUG, "Got subframe DSYNC\n");
+#endif
+ } else {
+ av_log(s->avctx, AV_LOG_ERROR, "Didn't get subframe DSYNC\n");
+ }
+ }
+
+ /* Backup predictor history for adpcm */
+ for (k = 0; k < s->prim_channels; k++)
+ for (l = 0; l < s->vq_start_subband[k]; l++)
+ memcpy(s->subband_samples_hist[k][l], &subband_samples[k][l][4],
+ 4 * sizeof(subband_samples[0][0][0]));
+
+ /* 32 subbands QMF */
+ for (k = 0; k < s->prim_channels; k++) {
+/* static float pcm_to_double[8] =
+ {32768.0, 32768.0, 524288.0, 524288.0, 0, 8388608.0, 8388608.0};*/
+ qmf_32_subbands(s, k, subband_samples[k], &s->samples[256 * k],
+ 2.0 / 3 /*pcm_to_double[s->source_pcm_res] */ ,
+ 0 /*s->bias */ );
+ }
+
+ /* Down mixing */
+
+ if (s->prim_channels > dca_channels[s->output & DCA_CHANNEL_MASK]) {
+ dca_downmix(s->samples, s->amode);
+ }
+
+ /* Generate LFE samples for this subsubframe FIXME!!! */
+ if (s->output & DCA_LFE) {
+ int lfe_samples = 2 * s->lfe * s->subsubframes;
+ int i_channels = dca_channels[s->output & DCA_CHANNEL_MASK];
+
+ lfe_interpolation_fir(s->lfe, 2 * s->lfe,
+ s->lfe_data + lfe_samples +
+ 2 * s->lfe * subsubframe,
+ &s->samples[256 * i_channels],
+ 8388608.0, s->bias);
+ /* Outputs 20bits pcm samples */
+ }
+
+ return 0;
+}
+
+
+static int dca_subframe_footer(DCAContext * s)
+{
+ int aux_data_count = 0, i;
+ int lfe_samples;
+
+ /*
+ * Unpack optional information
+ */
+
+ if (s->timestamp)
+ get_bits(&s->gb, 32);
+
+ if (s->aux_data)
+ aux_data_count = get_bits(&s->gb, 6);
+
+ for (i = 0; i < aux_data_count; i++)
+ get_bits(&s->gb, 8);
+
+ if (s->crc_present && (s->downmix || s->dynrange))
+ get_bits(&s->gb, 16);
+
+ lfe_samples = 2 * s->lfe * s->subsubframes;
+ for (i = 0; i < lfe_samples; i++) {
+ s->lfe_data[i] = s->lfe_data[i + lfe_samples];
+ }
+
+ return 0;
+}
+
+/**
+ * Decode a dca frame block
+ *
+ * @param s pointer to the DCAContext
+ */
+
+static int dca_decode_block(DCAContext * s)
+{
+
+ /* Sanity check */
+ if (s->current_subframe >= s->subframes) {
+ av_log(s->avctx, AV_LOG_DEBUG, "check failed: %i>%i",
+ s->current_subframe, s->subframes);
+ return -1;
+ }
+
+ if (!s->current_subsubframe) {
+#ifdef TRACE
+ av_log(s->avctx, AV_LOG_DEBUG, "DSYNC dca_subframe_header\n");
+#endif
+ /* Read subframe header */
+ if (dca_subframe_header(s))
+ return -1;
+ }
+
+ /* Read subsubframe */
+#ifdef TRACE
+ av_log(s->avctx, AV_LOG_DEBUG, "DSYNC dca_subsubframe\n");
+#endif
+ if (dca_subsubframe(s))
+ return -1;
+
+ /* Update state */
+ s->current_subsubframe++;
+ if (s->current_subsubframe >= s->subsubframes) {
+ s->current_subsubframe = 0;
+ s->current_subframe++;
+ }
+ if (s->current_subframe >= s->subframes) {
+#ifdef TRACE
+ av_log(s->avctx, AV_LOG_DEBUG, "DSYNC dca_subframe_footer\n");
+#endif
+ /* Read subframe footer */
+ if (dca_subframe_footer(s))
+ return -1;
+ }
+
+ return 0;
+}
+
+/**
+ * Convert bitstream to one representation based on sync marker
+ */
+static int dca_convert_bitstream(uint8_t * src, int src_size, uint8_t * dst,
+ int max_size)
+{
+ uint32_t mrk;
+ int i, tmp;
+ uint16_t *ssrc = (uint16_t *) src, *sdst = (uint16_t *) dst;
+ PutBitContext pb;
+
+ mrk = AV_RB32(src);
+ switch (mrk) {
+ case DCA_MARKER_RAW_BE:
+ memcpy(dst, src, FFMIN(src_size, max_size));
+ return FFMIN(src_size, max_size);
+ case DCA_MARKER_RAW_LE:
+ for (i = 0; i < (FFMIN(src_size, max_size) + 1) >> 1; i++)
+ *sdst++ = bswap_16(*ssrc++);
+ return FFMIN(src_size, max_size);
+ case DCA_MARKER_14B_BE:
+ case DCA_MARKER_14B_LE:
+ init_put_bits(&pb, dst, max_size);
+ for (i = 0; i < (src_size + 1) >> 1; i++, src += 2) {
+ tmp = ((mrk == DCA_MARKER_14B_BE) ? AV_RB16(src) : AV_RL16(src)) & 0x3FFF;
+ put_bits(&pb, 14, tmp);
+ }
+ flush_put_bits(&pb);
+ return (put_bits_count(&pb) + 7) >> 3;
+ default:
+ return -1;
+ }
+}
+
+/**
+ * Main frame decoding function
+ * FIXME add arguments
+ */
+static int dca_decode_frame(AVCodecContext * avctx,
+ void *data, int *data_size,
+ uint8_t * buf, int buf_size)
+{
+
+ int i, j, k;
+ int16_t *samples = data;
+ DCAContext *s = avctx->priv_data;
+ int channels;
+
+
+ s->dca_buffer_size = dca_convert_bitstream(buf, buf_size, s->dca_buffer, DCA_MAX_FRAME_SIZE);
+ if (s->dca_buffer_size == -1) {
+ av_log(avctx, AV_LOG_ERROR, "Not a DCA frame\n");
+ return -1;
+ }
+
+ init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8);
+ if (dca_parse_frame_header(s) < 0) {
+ //seems like the frame is corrupt, try with the next one
+ return buf_size;
+ }
+ //set AVCodec values with parsed data
+ avctx->sample_rate = s->sample_rate;
+ avctx->channels = 2; //FIXME
+ avctx->bit_rate = s->bit_rate;
+
+ channels = dca_channels[s->output];
+ if(*data_size < (s->sample_blocks / 8) * 256 * sizeof(int16_t) * channels)
+ return -1;
+ *data_size = 0;
+ for (i = 0; i < (s->sample_blocks / 8); i++) {
+ dca_decode_block(s);
+ s->dsp.float_to_int16(s->tsamples, s->samples, 256 * channels);
+ /* interleave samples */
+ for (j = 0; j < 256; j++) {
+ for (k = 0; k < channels; k++)
+ samples[k] = s->tsamples[j + k * 256];
+ samples += channels;
+ }
+ *data_size += 256 * sizeof(int16_t) * channels;
+ }
+
+ return buf_size;
+}
+
+
+
+/**
+ * Build the cosine modulation tables for the QMF
+ *
+ * @param s pointer to the DCAContext
+ */
+
+static void pre_calc_cosmod(DCAContext * s)
+{
+ int i, j, k;
+ static int cosmod_inited = 0;
+
+ if(cosmod_inited) return;
+ for (j = 0, k = 0; k < 16; k++)
+ for (i = 0; i < 16; i++)
+ cos_mod[j++] = cos((2 * i + 1) * (2 * k + 1) * M_PI / 64);
+
+ for (k = 0; k < 16; k++)
+ for (i = 0; i < 16; i++)
+ cos_mod[j++] = cos((i) * (2 * k + 1) * M_PI / 32);
+
+ for (k = 0; k < 16; k++)
+ cos_mod[j++] = 0.25 / (2 * cos((2 * k + 1) * M_PI / 128));
+
+ for (k = 0; k < 16; k++)
+ cos_mod[j++] = -0.25 / (2.0 * sin((2 * k + 1) * M_PI / 128));
+
+ cosmod_inited = 1;
+}
+
+
+/**
+ * DCA initialization
+ *
+ * @param avctx pointer to the AVCodecContext
+ */
+
+static int dca_decode_init(AVCodecContext * avctx)
+{
+ DCAContext *s = avctx->priv_data;
+
+ s->avctx = avctx;
+ dca_init_vlcs();
+ pre_calc_cosmod(s);
+
+ dsputil_init(&s->dsp, avctx);
+ return 0;
+}
+
+
+AVCodec dca_decoder = {
+ .name = "dca",
+ .type = CODEC_TYPE_AUDIO,
+ .id = CODEC_ID_DTS,
+ .priv_data_size = sizeof(DCAContext),
+ .init = dca_decode_init,
+ .decode = dca_decode_frame,
+};
+
+#ifdef CONFIG_DCA_PARSER
+
+typedef struct DCAParseContext {
+ ParseContext pc;
+ uint32_t lastmarker;
+} DCAParseContext;
+
+#define IS_MARKER(state, i, buf, buf_size) \
+ ((state == DCA_MARKER_14B_LE && (i < buf_size-2) && (buf[i+1] & 0xF0) == 0xF0 && buf[i+2] == 0x07) \
+ || (state == DCA_MARKER_14B_BE && (i < buf_size-2) && buf[i+1] == 0x07 && (buf[i+2] & 0xF0) == 0xF0) \
+ || state == DCA_MARKER_RAW_LE || state == DCA_MARKER_RAW_BE)
+
+/**
+ * finds the end of the current frame in the bitstream.
+ * @return the position of the first byte of the next frame, or -1
+ */
+static int dca_find_frame_end(DCAParseContext * pc1, const uint8_t * buf,
+ int buf_size)
+{
+ int start_found, i;
+ uint32_t state;
+ ParseContext *pc = &pc1->pc;
+
+ start_found = pc->frame_start_found;
+ state = pc->state;
+
+ i = 0;
+ if (!start_found) {
+ for (i = 0; i < buf_size; i++) {
+ state = (state << 8) | buf[i];
+ if (IS_MARKER(state, i, buf, buf_size)) {
+ if (pc1->lastmarker && state == pc1->lastmarker) {
+ start_found = 1;
+ break;
+ } else if (!pc1->lastmarker) {
+ start_found = 1;
+ pc1->lastmarker = state;
+ break;
+ }
+ }
+ }
+ }
+ if (start_found) {
+ for (; i < buf_size; i++) {
+ state = (state << 8) | buf[i];
+ if (state == pc1->lastmarker && IS_MARKER(state, i, buf, buf_size)) {
+ pc->frame_start_found = 0;
+ pc->state = -1;
+ return i - 3;
+ }
+ }
+ }
+ pc->frame_start_found = start_found;
+ pc->state = state;
+ return END_NOT_FOUND;
+}
+
+static int dca_parse_init(AVCodecParserContext * s)
+{
+ DCAParseContext *pc1 = s->priv_data;
+
+ pc1->lastmarker = 0;
+ return 0;
+}
+
+static int dca_parse(AVCodecParserContext * s,
+ AVCodecContext * avctx,
+ uint8_t ** poutbuf, int *poutbuf_size,
+ const uint8_t * buf, int buf_size)
+{
+ DCAParseContext *pc1 = s->priv_data;
+ ParseContext *pc = &pc1->pc;
+ int next;
+
+ if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
+ next = buf_size;
+ } else {
+ next = dca_find_frame_end(pc1, buf, buf_size);
+
+ if (ff_combine_frame(pc, next, (uint8_t **) & buf, &buf_size) < 0) {
+ *poutbuf = NULL;
+ *poutbuf_size = 0;
+ return buf_size;
+ }
+ }
+ *poutbuf = (uint8_t *) buf;
+ *poutbuf_size = buf_size;
+ return next;
+}
+
+AVCodecParser dca_parser = {
+ {CODEC_ID_DTS},
+ sizeof(DCAParseContext),
+ dca_parse_init,
+ dca_parse,
+ ff_parse_close,
+};
+#endif /* CONFIG_DCA_PARSER */
diff --git a/contrib/ffmpeg/libavcodec/dcadata.h b/contrib/ffmpeg/libavcodec/dcadata.h
new file mode 100644
index 000000000..c9f2ca747
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/dcadata.h
@@ -0,0 +1,8454 @@
+/*
+ * DCA compatible decoder data
+ * Copyright (C) 2004 Gildas Bazin
+ * Copyright (c) 2006 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 dcadata.c
+ */
+
+/* Generic tables */
+
+static const uint32_t dca_sample_rates[16] =
+{
+ 0, 8000, 16000, 32000, 0, 0, 11025, 22050, 44100, 0, 0,
+ 12000, 24000, 48000, 96000, 192000
+};
+
+static const uint32_t dca_bit_rates[32] =
+{
+ 32000, 56000, 64000, 96000, 112000, 128000,
+ 192000, 224000, 256000, 320000, 384000,
+ 448000, 512000, 576000, 640000, 768000,
+ 896000, 1024000, 1152000, 1280000, 1344000,
+ 1408000, 1411200, 1472000, 1536000, 1920000,
+ 2048000, 3072000, 3840000, 1/*open*/, 2/*variable*/, 3/*lossless*/
+};
+
+static const uint8_t dca_channels[16] =
+{
+ 1, 2, 2, 2, 2, 3, 3, 4, 4, 5, 6, 6, 6, 7, 8, 8
+};
+
+static const uint8_t dca_bits_per_sample[7] =
+{
+ 16, 16, 20, 20, 0, 24, 24
+};
+
+
+/* Adpcm data */
+
+/* 16bits signed fractional Q13 binary codes */
+static const int16_t adpcm_vb[4096][4] =
+{
+ { 9928, -2618, -1093, -1263 },
+ { 11077, -2876, -1747, -308 },
+ { 10503, -1082, -1426, -1167 },
+ { 9337, -2403, -1495, 274 },
+ { 10698, -2529, -532, -1122 },
+ { 10368, -3974, -1264, -750 },
+ { 10070, -3667, 346, 863 },
+ { 10278, -3093, 311, -576 },
+ { 9894, -1330, -1428, -860 },
+ { 10544, -1923, -1058, -971 },
+ { 10996, -1632, -841, -1404 },
+ { 11832, -3465, 1658, -1990 },
+ { 10852, -688, -2658, -499 },
+ { 10546, -1749, -147, -1733 },
+ { 10801, -1004, -708, -1453 },
+ { 10588, -441, -2113, -952 },
+ { 10141, -3331, -582, -1432 },
+ { 9608, -2590, 383, 258 },
+ { 11422, -3265, 229, -1544 },
+ { 10460, -1338, -713, -1568 },
+ { 10306, -1721, -1660, -603 },
+ { 9580, -1812, -1235, -1061 },
+ { 11471, -2285, -1617, -607 },
+ { 10081, -2225, -1408, -868 },
+ { 10715, -2624, -1367, -704 },
+ { 10616, -1871, -2770, -35 },
+ { 9352, -2340, -1024, -1566 },
+ { 11065, -1458, -1926, -735 },
+ { 11334, -2056, -1041, -1144 },
+ { 9825, -2048, -794, -1536 },
+ { 11850, -2695, -1123, -867 },
+ { 10654, -2226, -1891, -373 },
+ { 10024, -1557, -808, -1069 },
+ { 11142, -1266, -3238, 128 },
+ { 11729, -3282, -514, -1011 },
+ { 11402, -2094, -2335, -189 },
+ { 10195, -3658, 181, -1875 },
+ { 11431, -2626, -404, -1377 },
+ { 11001, -3868, -619, -1077 },
+ { 10894, -2559, 274, -1758 },
+ { 9633, -1482, -2253, -773 },
+ { 11245, -3321, 830, -1972 },
+ { 9768, -2701, -199, -1859 },
+ { 10500, -2042, 525, -2043 },
+ { 11669, -4069, 293, -1468 },
+ { 9192, -1991, -583, -61 },
+ { 10057, -3220, -2015, -473 },
+ { 9497, -2315, -2490, -467 },
+ { 10455, -3069, -1194, -1007 },
+ { 9994, -1936, -60, -1225 },
+ { 9295, -2156, -1761, -1134 },
+ { 10085, -3748, -1026, 197 },
+ { 9334, -2360, 804, -351 },
+ { 11561, -2553, 1352, -2313 },
+ { 12837, -3998, 1195, -1958 },
+ { 10114, -1100, -2414, -394 },
+ { 9341, -2530, 315, 755 },
+ { 10131, -3164, 1411, -674 },
+ { 9535, -905, -1551, 579 },
+ { 11717, -1519, -3051, 91 },
+ { 9824, -2911, -2775, 192 },
+ { 9662, -2934, -561, 1450 },
+ { 11085, -3392, -1298, -659 },
+ { 8955, -2102, -1899, 703 },
+ { 8607, -1742, -4348, 814 },
+ { 7640, -2063, -3617, 52 },
+ { 7074, -826, -4325, 4375 },
+ { 7714, 584, -4238, 1927 },
+ { 6355, -952, -4912, 3127 },
+ { 7069, -660, -6413, 4087 },
+ { 8313, -132, -2964, -876 },
+ { 6952, -1422, -3962, -24 },
+ { 9299, -734, -3088, -263 },
+ { 9484, -574, -4513, 466 },
+ { 7246, -91, -3735, -704 },
+ { 8325, -1417, -3090, -530 },
+ { 6469, -1226, -4757, 829 },
+ { 6652, -368, -5682, 1393 },
+ { 7971, -1278, -2284, 1205 },
+ { 7229, -699, -3556, 1840 },
+ { 7994, 1284, -2729, 732 },
+ { 9005, -698, -4522, 2189 },
+ { 6963, 197, -2727, 380 },
+ { 8527, 135, -3991, -213 },
+ { 8840, 934, -3014, -567 },
+ { 10125, 418, -3284, -371 },
+ { 6367, 361, -2318, 2554 },
+ { 7892, 172, -5247, 4673 },
+ { 6674, 387, -5424, 4398 },
+ { 6240, 684, -4047, 1219 },
+ { 11170, -794, -5081, 1195 },
+ { 11765, -648, -6265, 2052 },
+ { 10845, -775, -3837, 366 },
+ { 12496, -689, -8260, 3562 },
+ { 7893, -1166, -4972, 988 },
+ { 8592, 1052, -5986, 3087 },
+ { 7277, 1874, -5685, 3579 },
+ { 6900, 2016, -4809, 3491 },
+ { 8530, -2405, -3250, 1986 },
+ { 9426, 494, -7067, 5038 },
+ { 10285, 564, -8210, 5370 },
+ { 8749, -2207, -3980, 2852 },
+ { 9653, -2686, -4300, 1400 },
+ { 9770, -2286, -5663, 4233 },
+ { 8490, -4, -7048, 4496 },
+ { 7697, -1209, -5328, 3183 },
+ { 6451, 801, -4324, -554 },
+ { 7387, 1806, -5265, 545 },
+ { 7450, -2302, -4445, 1418 },
+ { 8817, -1370, -5827, 2168 },
+ { 10324, -2406, -5629, 2579 },
+ { 8863, -2578, -3537, 467 },
+ { 6901, -1624, -3169, 3392 },
+ { 7846, 156, -6948, 3381 },
+ { 7928, -1115, -5972, 4816 },
+ { 6089, -599, -4368, -320 },
+ { 7833, 1246, -3960, -621 },
+ { 8931, 2521, -6768, 2052 },
+ { 8900, 1944, -4126, 40 },
+ { 7661, -34, -2855, 2480 },
+ { 5873, 474, -3262, 3712 },
+ { 7535, -234, -4699, 216 },
+ { 5856, 143, -5142, 73 },
+ { 8944, -106, -5874, 3663 },
+ { 7134, 426, -5879, 2895 },
+ { 10199, 1011, -4762, 369 },
+ { 8454, 264, -5971, 1291 },
+ { 7822, -2449, -4333, 4540 },
+ { 6200, -2758, -2632, 1497 },
+ { 6070, -4315, -2699, 414 },
+ { 7047, -3739, -3210, 1060 },
+ { 5675, -3801, -2717, -407 },
+ { 4789, -4063, -2628, -744 },
+ { 4023, -3366, -3133, -726 },
+ { 4296, -2407, -3381, -513 },
+ { 4388, -2931, -2820, 1512 },
+ { 4559, -4233, -1941, 1976 },
+ { 6702, -3208, -1755, 1680 },
+ { 4416, -3521, -1052, 2984 },
+ { 7154, -4266, -1203, 3732 },
+ { 3625, -4242, -3244, 1395 },
+ { 6518, -2856, -1304, 2887 },
+ { 6170, -1949, -3014, 3973 },
+ { 5189, -2451, -4020, 3477 },
+ { 6218, -2988, -1921, 3844 },
+ { 4827, -3688, -1928, 3343 },
+ { 6668, -3991, -2805, 3095 },
+ { 5297, -3115, -3684, 2390 },
+ { 5354, -4614, -2662, 1504 },
+ { 4196, -3091, -4147, 1135 },
+ { 3540, -2893, -4007, 100 },
+ { 5569, -1602, -4007, 1909 },
+ { 4341, -2091, -4272, 252 },
+ { 5559, -2878, -3832, 498 },
+ { 4548, -4479, -2898, -27 },
+ { 5176, -2494, -4635, 1476 },
+ { 3294, -3485, -3738, 716 },
+ { 4920, -1229, -4195, -365 },
+ { 3257, -3518, -3349, 2862 },
+ { 5286, -1948, -3485, -778 },
+ { 6502, -3051, -152, 2854 },
+ { 5864, -4192, -1076, 3451 },
+ { 4656, -3122, -3448, 179 },
+ { 5907, -754, -1596, 3116 },
+ { 7229, -3680, -1590, 2892 },
+ { 5107, -3888, -3364, 806 },
+ { 6764, -2635, -3450, 134 },
+ { 5258, -2827, -2844, -1052 },
+ { 5798, -1725, -4305, 205 },
+ { 5404, -1213, -3362, 449 },
+ { 6224, -2738, -3046, -581 },
+ { 4223, -2438, -2725, 3745 },
+ { 4751, -3411, -2123, 116 },
+ { 3868, -3000, -3954, 2297 },
+ { 6819, -2899, -4277, 2825 },
+ { 4207, -4754, -2808, 865 },
+ { 4804, -1494, -1997, 4688 },
+ { 5282, -2213, -548, 3559 },
+ { 5580, -1912, -566, 4370 },
+ { 6168, -2857, -672, 4053 },
+ { 6583, -4515, -2850, 1670 },
+ { 6511, -3093, -3988, 1421 },
+ { 4646, -1790, -1443, 3650 },
+ { 5915, -924, -2020, 896 },
+ { 7814, -4181, -3152, 2007 },
+ { 6190, -2238, -4817, 2279 },
+ { 4737, -4034, -3288, 1835 },
+ { 8161, -3633, -3423, 3137 },
+ { 7415, -2351, -2088, 4290 },
+ { 4106, -2517, -62, 2905 },
+ { 4909, -3145, -614, 4112 },
+ { 4938, -3281, -397, 1100 },
+ { -173, 919, 1589, -5363 },
+ { -13, 796, -295, -6655 },
+ { -1860, -829, 1141, -4555 },
+ { 2298, -838, -664, -5005 },
+ { -884, -1097, 2074, -4613 },
+ { -101, 281, 2846, -4535 },
+ { 1166, 453, 2429, -5910 },
+ { 879, -664, 2370, -5452 },
+ { 1415, -370, -1699, -4727 },
+ { -1413, 1277, -669, -6649 },
+ { 2133, 304, -968, -4624 },
+ { 380, 586, -2087, -4892 },
+ { 1336, 275, -82, -5789 },
+ { -2459, 1057, -34, -5416 },
+ { 2278, -1758, 866, -5653 },
+ { 1945, -2295, -149, -5302 },
+ { 1287, -3525, 996, -5255 },
+ { 2297, 803, 1177, -6067 },
+ { 187, -180, -619, -6202 },
+ { -793, -2537, 1554, -5057 },
+ { -2703, -204, -629, -5853 },
+ { -1007, -146, 313, -5582 },
+ { 830, 357, 869, -6363 },
+ { -228, -575, -3177, -4433 },
+ { -1001, -1553, -142, -5708 },
+ { -1644, 1683, 1721, -4533 },
+ { 893, 1924, -15, -5791 },
+ { 2195, 2061, -262, -5471 },
+ { 3031, 270, 311, -5096 },
+ { 1912, 1638, -1523, -4677 },
+ { -3142, -55, 253, -4914 },
+ { 356, -1680, 343, -6123 },
+ { -2241, -1734, -976, -5939 },
+ { -2196, -2893, 547, -4938 },
+ { -1245, 126, -1916, -5419 },
+ { -249, -3755, -1422, -5594 },
+ { 575, -2683, -1926, -4566 },
+ { -762, 1885, 192, -5880 },
+ { -811, -2562, -1068, -6013 },
+ { -2264, -3086, -976, -4775 },
+ { 70, -1215, 2880, -4410 },
+ { 714, -3760, 2916, -4691 },
+ { -244, -3404, 1740, -4493 },
+ { 684, -5137, -328, -5608 },
+ { -529, -3825, -1786, -4535 },
+ { -713, -4743, -1118, -5546 },
+ { 2718, -3788, 1798, -5708 },
+ { -1639, -3679, -1564, -6095 },
+ { 1693, -2642, -1389, -4539 },
+ { 505, -1573, -1651, -4878 },
+ { -835, -2256, -1941, -5352 },
+ { 1464, -411, 1993, -6441 },
+ { 493, -3184, -145, -6148 },
+ { -1413, 499, -1617, -6479 },
+ { -294, 1722, -1419, -5725 },
+ { -2937, -1528, -175, -4624 },
+ { -594, -5911, -56, -6146 },
+ { -300, -4275, 1156, -5947 },
+ { 552, -2643, 2669, -3959 },
+ { 905, -4158, 1789, -5809 },
+ { 1336, -2009, 2108, -5903 },
+ { 1555, -3600, 1110, -6759 },
+ { -1294, -3464, 77, -6084 },
+ { -1139, -4006, -1270, -4181 },
+ { -5094, -3296, 1092, -2847 },
+ { -5503, -2883, 1984, -2067 },
+ { -4671, -4218, -1417, -4132 },
+ { -3763, -3818, 1262, -3082 },
+ { -5132, -3430, 2928, -728 },
+ { -5957, -2877, 1251, -2446 },
+ { -4425, -2319, -212, -4276 },
+ { -6201, -1993, 1774, -2182 },
+ { -5500, -3836, 2201, -1396 },
+ { -6934, -2334, 2366, -1293 },
+ { -6124, -4140, 1337, -1977 },
+ { -6553, -4186, 1756, -1325 },
+ { -5126, -1258, 744, -3656 },
+ { -5167, -1390, 1581, -2895 },
+ { -4525, -3398, 2429, -1865 },
+ { -4076, -3183, 2027, -2510 },
+ { -6191, -3274, 1838, -1814 },
+ { -4454, -2753, 2723, -1185 },
+ { -6655, -4797, 251, -2595 },
+ { -6332, -2232, 1832, 217 },
+ { -5869, -1698, 134, 340 },
+ { -6614, -1045, 2126, -1932 },
+ { -4859, -2107, 2010, -2435 },
+ { -6274, -1622, 2808, -1374 },
+ { -3119, -3209, 521, -3988 },
+ { -5676, -2082, -420, -2711 },
+ { -7073, -3623, 696, -2343 },
+ { -5986, -4224, 572, -2454 },
+ { -4340, -4521, 882, -2771 },
+ { -6178, -1933, 535, -1444 },
+ { -4923, -4163, 1744, -2066 },
+ { -6410, -1519, 1058, -2683 },
+ { -5077, -1185, 856, -2216 },
+ { -7091, -2444, 687, -2597 },
+ { -5284, -2165, 3239, -993 },
+ { -4763, -1497, 197, -3179 },
+ { -4128, -4958, -396, -3578 },
+ { -5054, -3878, -647, -2672 },
+ { -7005, -3348, 1679, -1579 },
+ { -5767, -1017, 2582, -1915 },
+ { -7069, -2787, 1331, -2070 },
+ { -5532, -2296, 706, -2950 },
+ { -5059, -3543, -821, -3637 },
+ { -6639, -1835, 1016, -696 },
+ { -5611, -5220, -694, -3371 },
+ { -5994, -2803, 2933, -729 },
+ { -5948, -619, 1596, -2676 },
+ { -5486, -4419, 153, -3265 },
+ { -4329, -3440, 1646, -1439 },
+ { -4083, -3978, 177, -3569 },
+ { -4289, -2599, 1224, -3075 },
+ { -5707, -3253, 1912, -759 },
+ { -6606, -3437, 2562, -571 },
+ { -5254, -2444, 769, -352 },
+ { -6545, -3154, 582, -1103 },
+ { -5328, -2241, 2566, -1775 },
+ { -7216, -1936, 1538, -1983 },
+ { -3730, -2451, 426, -3869 },
+ { -5110, -1385, 2031, -1169 },
+ { -6470, -2715, 269, -3123 },
+ { -5806, -2480, -97, -3832 },
+ { -3683, -4916, -490, -4330 },
+ { -6341, -2083, -669, -115 },
+ { -4913, -4079, -837, -4673 },
+ { -3274, -2497, 2334, -2652 },
+ { -1286, -1731, 2550, -3756 },
+ { -3375, -877, 926, -3977 },
+ { -2525, -2079, 2879, -2625 },
+ { -5308, -504, 3111, -1607 },
+ { -4904, 460, 4093, -1232 },
+ { -1993, 1616, 4656, -1913 },
+ { -3481, -1176, 3119, -2236 },
+ { -4132, -1502, 2339, -2545 },
+ { -2542, 1151, 3569, -2550 },
+ { -4381, 430, 3147, -2082 },
+ { -3888, 867, 3899, -1657 },
+ { -2861, 1290, 4202, -1979 },
+ { -3893, -253, 2363, -2764 },
+ { -1705, 688, 3827, -2923 },
+ { -2223, 2312, 3700, -3148 },
+ { -1986, -720, 5021, -795 },
+ { -3177, 242, 1952, -3352 },
+ { -1854, 1509, 2528, -3815 },
+ { -3173, 97, 5019, -706 },
+ { -2689, -145, 1375, -3915 },
+ { -4838, -385, 2488, -2427 },
+ { -4557, -355, 1603, -3060 },
+ { -3522, 1832, 3292, -2674 },
+ { -3769, 780, 2378, -2704 },
+ { -4323, -1932, 3414, -1169 },
+ { -2740, 1158, 2729, -3273 },
+ { -3647, 210, 1464, -2892 },
+ { -2342, -2097, 1513, -3727 },
+ { -4422, -1242, 3130, -1833 },
+ { -1308, -1039, 4290, -1875 },
+ { -1754, -2535, 3298, -2314 },
+ { -4102, -186, 4037, -1094 },
+ { -1008, 1570, 3290, 171 },
+ { -3322, -2621, 2791, -1536 },
+ { -2539, -2597, 3442, -1672 },
+ { -3411, -2015, 3670, -1174 },
+ { -2097, 730, 5581, -1399 },
+ { -1510, -74, 4820, -2004 },
+ { -4086, -868, 4425, -771 },
+ { -956, -986, 3640, -2925 },
+ { -2087, -1250, 3464, -2458 },
+ { -3308, -2411, 1334, -3667 },
+ { -2264, -389, 4004, -1854 },
+ { -680, 239, 4058, -3388 },
+ { -1357, 30, 2993, -3658 },
+ { -3601, -552, 1177, -1136 },
+ { -2641, 442, 4374, -1625 },
+ { -2525, 770, 1640, -3895 },
+ { -3172, -891, 3893, -1608 },
+ { -2996, 13, 3277, -2414 },
+ { -899, 1055, 4470, -2501 },
+ { -422, -584, 3475, -3787 },
+ { -1978, -593, 2566, -3415 },
+ { -3150, -1280, 2362, -3047 },
+ { -3592, 224, 1026, -3932 },
+ { -4840, -1189, 3633, -879 },
+ { -3952, -2255, 2916, -1826 },
+ { -1695, 28, 1810, -349 },
+ { -745, -2484, 3308, -3293 },
+ { -1016, 1563, 5365, -1823 },
+ { -2172, -1787, 4266, -1287 },
+ { -1241, -1951, 3982, -2413 },
+ { -2009, -2639, 2330, -3480 },
+ { 5105, -1618, -2588, -2015 },
+ { 6497, -1523, -3218, -910 },
+ { 6526, -2305, -2029, -1790 },
+ { 5289, -99, -3436, -400 },
+ { 5781, -1623, -1577, -2617 },
+ { 5259, -670, -3125, -1700 },
+ { 6343, -1256, -331, -3222 },
+ { 7967, -678, -2195, -1462 },
+ { 6119, -695, -2988, -1538 },
+ { 6108, 494, -3359, -1548 },
+ { 5067, 969, -2328, -2707 },
+ { 7595, -435, -1497, -2056 },
+ { 6929, -719, -2420, -1665 },
+ { 5190, 584, -2982, -2103 },
+ { 6106, -444, -1411, -2739 },
+ { 5584, 289, -1804, -2803 },
+ { 5276, 227, -1180, -3361 },
+ { 7544, -1525, -1834, -1725 },
+ { 5986, -1470, -2606, -1701 },
+ { 5096, -765, -1712, -3006 },
+ { 5423, -149, -3933, -1157 },
+ { 7651, 26, -2445, -1507 },
+ { 4745, -464, -1735, -2362 },
+ { 5352, -1011, -1094, -1999 },
+ { 6300, -672, -542, -1950 },
+ { 6675, -1020, -1318, -1059 },
+ { 7218, -2036, -603, -2462 },
+ { 7755, -1514, -2430, -1229 },
+ { 5041, 449, -1056, -2405 },
+ { 6710, -2277, -1344, -2284 },
+ { 6824, -1347, -2254, 251 },
+ { 6068, -1857, -983, -1316 },
+ { 5603, -2177, -2730, -1477 },
+ { 5838, -1059, -3604, -970 },
+ { 5076, -789, -335, -2413 },
+ { 6191, -1634, -2000, -2129 },
+ { 5092, -1292, -2543, -1034 },
+ { 5305, 435, -1710, -1850 },
+ { 6140, 561, -2176, -2380 },
+ { 6752, 348, -2496, -1890 },
+ { 6405, 273, -1098, -2778 },
+ { 6942, -1340, -496, -1381 },
+ { 5238, -687, -2454, -2349 },
+ { 6959, -882, -1833, -2061 },
+ { 6292, -253, -2125, -2199 },
+ { 5838, -574, -759, -3215 },
+ { 6954, -1484, -640, -2771 },
+ { 7498, -1706, -1210, -2154 },
+ { 6772, -1003, -1235, -2532 },
+ { 6014, 228, -2154, -1108 },
+ { 6943, -2178, -2644, -1122 },
+ { 7262, -763, -3056, -1090 },
+ { 6273, -1478, -1072, 177 },
+ { 4734, 425, -2912, 357 },
+ { 7129, 168, -1537, -2327 },
+ { 7204, -434, -746, -2660 },
+ { 6879, 57, -3087, -1310 },
+ { 4623, -610, -718, -3459 },
+ { 6565, -543, -1998, -339 },
+ { 4752, -277, -2066, -1405 },
+ { 7435, -1416, -1904, -505 },
+ { 4076, 150, -1222, -3556 },
+ { 7082, -28, -1456, -1174 },
+ { 5941, -446, -1326, -1158 },
+ { 3870, -1648, -2474, -2589 },
+ { 858, 37, -3387, -3721 },
+ { 3557, -1503, -1664, -3383 },
+ { 3336, -1972, -3079, -2216 },
+ { 3186, 60, -4185, -863 },
+ { 3456, -773, -3066, -2457 },
+ { 4131, -913, -2060, -2601 },
+ { 4431, -691, -4114, -972 },
+ { 3461, -334, -3680, -1751 },
+ { 2006, -459, -2214, -3827 },
+ { 1322, 32, -2816, -3203 },
+ { 4425, -1897, -2791, -1946 },
+ { 4504, 23, -3421, -1909 },
+ { 3090, -885, -2366, -3264 },
+ { 3209, -2363, -3730, -834 },
+ { 3312, -1471, -3641, -1579 },
+ { 4184, -1669, -3323, -1248 },
+ { 2190, -931, -3302, -2944 },
+ { 2947, -229, -4791, -1195 },
+ { 2020, -1626, -2700, -3125 },
+ { 2214, -326, -4352, -1683 },
+ { 3286, -2619, -2412, -2458 },
+ { 1000, -2571, -4129, -2158 },
+ { 2496, -2627, -3611, -1433 },
+ { 2043, -2191, -2167, -3827 },
+ { 2571, -2544, -1915, -3222 },
+ { 2022, -1501, -3856, -2165 },
+ { 2685, -1180, -1461, -4038 },
+ { 1610, -2313, -4391, -1173 },
+ { 2340, -2490, -4215, -516 },
+ { 1742, -2615, -3632, -2146 },
+ { 523, -1293, -4246, -2442 },
+ { 3725, -2723, -3014, -1576 },
+ { 3554, -1381, -4200, -824 },
+ { 1291, -1594, -4777, -1430 },
+ { 1452, 515, -2960, -3830 },
+ { 4264, -894, -3305, -1826 },
+ { 2606, -1452, -4522, -966 },
+ { 1196, -830, -4807, -1816 },
+ { 1054, -775, -2616, -4071 },
+ { 4206, 415, -4344, -1132 },
+ { 3044, 491, -4126, -1934 },
+ { 988, -901, -3353, -3443 },
+ { 1729, -3063, -2267, -3370 },
+ { 3915, 912, -2989, -2387 },
+ { 3781, 300, -2457, -3050 },
+ { 2712, 924, -1350, -1206 },
+ { 4230, 405, -2343, 665 },
+ { 1878, -873, -225, -29 },
+ { 3510, 56, -1334, -3420 },
+ { 2850, 1447, -2651, -3150 },
+ { 1510, -706, -4125, -2483 },
+ { 3115, 793, -1692, -3894 },
+ { 2667, 213, -2973, -2786 },
+ { 1184, -2384, -3051, -3173 },
+ { 2139, 796, -2079, -3697 },
+ { 1464, -1483, -3726, -2754 },
+ { 2407, -1148, -3915, -1569 },
+ { 2612, -1779, -3217, -2271 },
+ { 2406, -2870, -2937, -2496 },
+ { 2140, 126, -3646, -2758 },
+ { 2952, -1036, 268, -1423 },
+ { 93, -1931, -3841, -3535 },
+ { 389, -2953, -3383, -3343 },
+ { 8652, -5511, -1662, 565 },
+ { 7427, -2791, -2535, -842 },
+ { 8541, -4253, -1407, -988 },
+ { 8018, -3203, -2998, 105 },
+ { 7231, -3926, -958, 1308 },
+ { 7331, -3690, -363, 2586 },
+ { 6803, -3646, -2226, -903 },
+ { 8163, -2811, -477, -2235 },
+ { 9356, -3818, -1685, -684 },
+ { 8466, -2854, -302, -698 },
+ { 8458, -3224, 517, 279 },
+ { 8074, -2619, -1326, 2596 },
+ { 8779, -2761, -2527, -441 },
+ { 6533, -2887, -899, -696 },
+ { 7394, -2305, -1642, -120 },
+ { 8281, -3780, -22, 1305 },
+ { 9158, -4413, -779, 901 },
+ { 9031, -5240, -1109, 1678 },
+ { 8717, -3650, 410, -1075 },
+ { 7317, -3197, -818, -2264 },
+ { 7934, -2385, -1214, -1886 },
+ { 8256, -4441, -291, -587 },
+ { 7358, -3395, 1090, -270 },
+ { 9446, -4910, -1343, -473 },
+ { 8187, -4726, -808, 1166 },
+ { 7504, -3845, -47, 267 },
+ { 8029, -2146, -1283, -383 },
+ { 7461, -2705, -853, 783 },
+ { 9367, -3636, -645, -354 },
+ { 8955, -3473, -308, -1947 },
+ { 8676, -2683, -2099, 1485 },
+ { 7481, -3003, -871, -444 },
+ { 8015, -2839, -1673, 1175 },
+ { 6947, -4643, -1527, -1047 },
+ { 7622, -2575, -137, -960 },
+ { 9388, -4279, -707, -1322 },
+ { 8382, -5259, -1283, -565 },
+ { 6856, -4138, -1030, 630 },
+ { 8659, -2571, -1124, -1666 },
+ { 8763, -3807, -537, 2543 },
+ { 8049, -3578, -2186, -604 },
+ { 8272, -2351, -1985, -1214 },
+ { 6855, -3796, -1527, -1631 },
+ { 7178, -2896, -1600, -1756 },
+ { 7040, -2888, -89, -1586 },
+ { 6261, -3403, -264, 998 },
+ { 7756, -4699, -1543, -834 },
+ { 7682, -4622, -758, -1721 },
+ { 8839, -4232, -2932, 1959 },
+ { 9363, -4679, -1956, 39 },
+ { 7883, -3616, -1414, -1432 },
+ { 8828, -3188, -1356, -1312 },
+ { 7746, -3987, -121, -2424 },
+ { 9262, -3256, -693, 818 },
+ { 7670, -3420, -148, 3504 },
+ { 7344, -3183, 608, 1595 },
+ { 8976, -4139, -1848, 1304 },
+ { 6708, -4131, 33, -852 },
+ { 7840, -4429, -2275, 79 },
+ { 8980, -3858, -2838, 453 },
+ { 7815, -4604, -2563, 944 },
+ { 8372, -4422, -1783, 3071 },
+ { 8623, -5128, -1754, 2888 },
+ { 7462, -3281, 889, 920 },
+ { 8416, -59, -1320, -1825 },
+ { 7928, -1488, -414, -2499 },
+ { 8110, -977, -1047, -2042 },
+ { 8278, -687, -1597, -1550 },
+ { 7988, -174, -977, -2106 },
+ { 8609, -1547, -1628, -1527 },
+ { 9000, -1798, -946, -1761 },
+ { 8954, -872, -1404, -1594 },
+ { 8939, 466, -748, -1212 },
+ { 9549, -329, -177, -1360 },
+ { 9411, -18, -1126, -1568 },
+ { 8859, -782, -488, -1338 },
+ { 8955, -218, -43, -1209 },
+ { 9131, -69, -453, -1001 },
+ { 9069, -1519, -1091, -1199 },
+ { 9247, -1309, -566, -1146 },
+ { 8528, -1617, -287, -1313 },
+ { 7763, -745, -149, -2040 },
+ { 8294, -343, 257, -2633 },
+ { 10149, -893, -552, -1649 },
+ { 9398, -915, 218, -2042 },
+ { 9703, -1194, -675, -1592 },
+ { 9586, -700, -427, -1710 },
+ { 8930, 497, -1445, -1218 },
+ { 9285, -1323, -163, -1552 },
+ { 8431, -1289, -985, -1404 },
+ { 8965, -655, 653, -1483 },
+ { 9542, -1001, -951, -1128 },
+ { 9205, -647, -37, -882 },
+ { 8603, -56, 514, -1793 },
+ { 9300, -12, -1324, -567 },
+ { 8773, 238, -184, -1456 },
+ { 9941, -1306, -69, -1792 },
+ { 9360, 279, -376, -1919 },
+ { 9180, -285, 95, -2170 },
+ { 9922, -501, -970, -1570 },
+ { 8341, -1493, -856, -2092 },
+ { 8780, -981, -850, -1014 },
+ { 9721, -548, -1504, -1094 },
+ { 9973, -1493, 482, -2105 },
+ { 8707, -333, -1027, -1087 },
+ { 9098, -469, -315, -1723 },
+ { 8879, -1050, -661, -2020 },
+ { 8857, 602, -866, -1918 },
+ { 8945, -1025, -2154, -1071 },
+ { 8484, -1930, -468, -2179 },
+ { 9177, -1903, -224, -2112 },
+ { 8652, -137, -2097, -1214 },
+ { 9063, -973, -1405, -772 },
+ { 9328, -456, 662, -2469 },
+ { 10101, -697, 127, -2113 },
+ { 9685, 811, -2359, -1024 },
+ { 8586, -94, -460, -1982 },
+ { 7924, -141, -509, -2513 },
+ { 7773, -669, -107, -2835 },
+ { 8636, -1064, -46, -2409 },
+ { 9748, 596, -1815, -1349 },
+ { 8924, 304, 547, -2614 },
+ { 9442, 746, -1153, -1679 },
+ { 9454, -278, -529, -1976 },
+ { 8488, 561, -32, -2160 },
+ { 10083, -63, -1544, -1364 },
+ { 9390, -1278, 568, -1131 },
+ { 9740, -49, -2253, -910 },
+ { 3636, -2391, -1115, -3614 },
+ { 6014, -3204, -1902, -1808 },
+ { 5787, -3497, -1116, -2590 },
+ { 4365, -3046, -1632, -2668 },
+ { 4733, -2192, -2029, -2468 },
+ { 5412, -2753, -1633, -2464 },
+ { 4455, -3375, -767, -3399 },
+ { 4456, -1644, -983, -2841 },
+ { 4039, -2523, 38, -3967 },
+ { 3406, -2662, 72, -4757 },
+ { 4279, -2005, 1055, -4399 },
+ { 4321, -1377, -860, -3786 },
+ { 3743, -5739, -651, -3047 },
+ { 3528, -5510, 361, -4060 },
+ { 6496, -4886, -136, -2689 },
+ { 4513, -5254, 551, -4010 },
+ { 6557, -3413, -92, -3063 },
+ { 4186, -2059, 187, 47 },
+ { 6210, -4117, -1256, -1985 },
+ { 6038, -4343, 351, -2124 },
+ { 4305, -4780, -2077, -1897 },
+ { 4480, -3815, -2228, -1533 },
+ { 5582, -3689, 1221, -3429 },
+ { 5532, -4874, 1195, -2765 },
+ { 6518, -2853, -905, -2568 },
+ { 5467, -2192, 470, -4115 },
+ { 4139, -1577, 240, -3493 },
+ { 5281, -1926, -729, -3340 },
+ { 5214, -2870, 1359, -4289 },
+ { 3046, -3510, -1536, -3214 },
+ { 5433, -2881, -1230, -1184 },
+ { 4861, -3932, -1071, -2791 },
+ { 5693, -4234, -1906, -1502 },
+ { 4004, -3935, -1804, -2383 },
+ { 3728, -3792, 681, -4773 },
+ { 3621, -3030, -1951, -2598 },
+ { 5133, -3903, 44, -3700 },
+ { 3561, -3451, 1183, -5301 },
+ { 5026, -2762, -2341, -1780 },
+ { 5841, -2492, -467, -3210 },
+ { 5591, -1791, 497, -2472 },
+ { 5054, -3898, -1822, -2097 },
+ { 5813, -2792, 83, -1469 },
+ { 4432, -4497, 1670, -5193 },
+ { 5338, -4653, -1109, -2200 },
+ { 3239, -4401, -648, -3655 },
+ { 2147, -3598, -1200, -4242 },
+ { 4417, -2271, -1552, -3210 },
+ { 6494, -4360, 852, -3565 },
+ { 2393, -6358, -856, -4524 },
+ { 4959, -4196, -847, -1403 },
+ { 4924, -5438, -226, -3026 },
+ { 4254, -5303, -1306, -2424 },
+ { 4121, -3126, -2334, -1981 },
+ { 3437, -4443, -1464, -2953 },
+ { 3203, -3459, -529, -4339 },
+ { 5896, -5945, 543, -3246 },
+ { 1987, -4733, -220, -4863 },
+ { 4358, -4431, -514, -3081 },
+ { 4583, -2416, -492, -2287 },
+ { 2943, -5035, 419, -4927 },
+ { 5358, -5129, 987, -4309 },
+ { 4460, -3392, 1752, -5634 },
+ { 3415, -4633, 1507, -5945 },
+ { 811, -4692, -445, 2333 },
+ { 1009, -5613, -1857, 1360 },
+ { 1338, -2712, -2720, 3036 },
+ { 1002, -3754, -2582, 2344 },
+ { 750, -4608, -2334, 714 },
+ { 2043, -3207, -2822, 2173 },
+ { -140, -4654, -2953, 357 },
+ { -54, -4026, -2376, 2695 },
+ { 1858, -5022, -717, 2287 },
+ { 2064, -3894, -722, 3255 },
+ { 2727, -4558, -332, 2603 },
+ { 1810, -5378, 283, 1826 },
+ { 3935, -4326, 762, 3383 },
+ { -767, -4697, -2510, 1922 },
+ { 2146, -4312, -3090, 1641 },
+ { 54, -5881, -2114, 921 },
+ { 1992, -5766, -640, 1574 },
+ { 1200, -5371, -1114, 1828 },
+ { 2973, -5337, 34, 2266 },
+ { 1531, -5018, -2817, 1192 },
+ { 3078, -4570, 117, 1990 },
+ { 924, -4286, -1388, 2713 },
+ { 142, -5058, -2848, 1487 },
+ { -106, -6180, -881, 842 },
+ { 673, -5433, -229, 1596 },
+ { 783, -5710, -2784, 562 },
+ { 1935, -5729, -2009, 856 },
+ { -410, -3375, -3326, 2734 },
+ { 234, -3000, -2628, 3260 },
+ { 733, -3405, -3806, 1589 },
+ { 771, -4285, -3544, 1314 },
+ { 1192, -3563, -3960, 2178 },
+ { 206, -5555, -1250, 1546 },
+ { -130, -3815, -1210, 3041 },
+ { 646, -3940, -393, 2992 },
+ { -184, -4931, -1767, 1925 },
+ { 2746, -5120, -2275, 1464 },
+ { 2440, -3731, -3352, 2729 },
+ { -490, -4942, -3779, 997 },
+ { 68, -2636, -4167, 3778 },
+ { 48, -3986, -4118, 2106 },
+ { -978, -5486, -1336, 1390 },
+ { 1126, -5297, -855, 640 },
+ { -472, -3975, -3622, 1557 },
+ { 2456, -5344, -1523, 1648 },
+ { -774, -5652, -2417, 1147 },
+ { 995, -6122, -812, 1132 },
+ { 3282, -4571, -1763, 2175 },
+ { 3655, -3862, -676, 3568 },
+ { 3038, -3647, -1672, 3381 },
+ { 2595, -2964, -2772, 3263 },
+ { 4176, -3353, -1148, 4354 },
+ { 1603, -3442, -1500, 3444 },
+ { 828, -6226, -1783, 678 },
+ { 1421, -3333, -3080, 3403 },
+ { 1121, -4727, -1924, 1984 },
+ { -186, -5083, -682, 1796 },
+ { 819, -2778, -3488, 530 },
+ { 421, -2873, -3832, 2596 },
+ { 2164, -4263, -1605, 2282 },
+ { 585, -4437, -682, -491 },
+ { -644, -4452, -1157, 2325 },
+ { 1991, -4299, 210, 2834 },
+ { 2135, -3632, -2113, 665 },
+ { -7482, -2724, -2662, -1380 },
+ { -6983, -2166, -3756, -3509 },
+ { -7085, -1439, -2397, -3112 },
+ { -7760, -3049, -3319, -2822 },
+ { -8413, -2760, -4406, -3298 },
+ { -5995, -3943, -1260, -3750 },
+ { -7879, -1554, -3464, -2606 },
+ { -6314, -2034, -3878, -1681 },
+ { -8849, -2084, -1399, -1231 },
+ { -7153, -2602, -1384, -817 },
+ { -8041, -2571, -407, -2785 },
+ { -7246, -2233, -1578, 260 },
+ { -7336, -3883, -4061, -1342 },
+ { -7619, -3908, -2342, 382 },
+ { -8684, -3724, -1662, -727 },
+ { -7850, -2922, -1770, -3449 },
+ { -6766, -2034, -1293, -1988 },
+ { -6895, -2116, -968, -3744 },
+ { -7136, -5147, -2618, -2809 },
+ { -8224, -3724, -2519, -1589 },
+ { -6711, -2750, -3021, -219 },
+ { -8059, -1638, -1102, -3175 },
+ { -8710, -4839, -3963, -3143 },
+ { -9363, -4965, -3257, -1002 },
+ { -6099, -1751, -3157, -395 },
+ { -6453, -3216, -4597, -483 },
+ { -7879, -5477, -839, -2638 },
+ { -7202, -4038, -526, -2856 },
+ { -8022, -1228, -1910, -1646 },
+ { -9117, -1393, -1582, -2535 },
+ { -9095, -2693, -636, -2605 },
+ { -9076, -2580, -3481, -2519 },
+ { -8327, -4859, -2422, 83 },
+ { -8368, -2129, -2324, -2173 },
+ { -8554, -4563, -3842, -2007 },
+ { -10462, -4261, -1934, -2084 },
+ { -9717, -3187, -2294, -1896 },
+ { -9625, -3889, -3020, -3224 },
+ { -9857, -4955, -4239, -2184 },
+ { -9752, -2351, -2277, -3129 },
+ { -7219, -1302, -2639, -1603 },
+ { -7477, -4360, -3718, -559 },
+ { -5680, -2033, -2326, -3078 },
+ { -10190, -5548, -4643, -3601 },
+ { -9431, -4121, -879, -2479 },
+ { -8365, -5450, -2020, -1439 },
+ { -6289, -5178, -1605, -3845 },
+ { -8319, -3866, -687, -2792 },
+ { -8131, -1031, -3608, -3947 },
+ { -10510, -2560, -1199, -2082 },
+ { -11015, -3640, -2748, -3041 },
+ { -8762, -5022, -5231, -1162 },
+ { -10153, -2715, -4648, -4859 },
+ { -7930, -5205, -1900, -3600 },
+ { -9561, -3548, -4812, -3722 },
+ { -7663, -4709, -1180, -1475 },
+ { -9073, -5707, -1815, -2980 },
+ { -8602, -2363, -2675, -3770 },
+ { -9967, -5614, -3575, -3838 },
+ { -8324, -1005, -2131, -3254 },
+ { -10331, -5737, -2550, -2940 },
+ { -8234, -3354, -3361, -4479 },
+ { -8140, -1951, -4526, -4545 },
+ { -6679, -2662, -2284, -4182 },
+ { -1122, -1514, -6427, -212 },
+ { 54, -1660, -5424, -1404 },
+ { 254, -2778, -5222, 846 },
+ { -267, -1661, -6577, 814 },
+ { -305, -2021, -5759, 1484 },
+ { -1791, -2446, -6867, -86 },
+ { -2929, -3158, -6603, -1799 },
+ { -1391, -3189, -5557, -1053 },
+ { -1602, -884, -6767, -1213 },
+ { -361, -318, -6219, -44 },
+ { -4078, -2635, -5523, -433 },
+ { -956, 478, -4382, 1470 },
+ { -3300, -2462, -6021, -2721 },
+ { 708, -2434, -5085, -540 },
+ { -2435, -3607, -5647, -2110 },
+ { -491, -1134, -4681, -2886 },
+ { 87, -3435, -4641, -1194 },
+ { -586, -2927, -4784, 366 },
+ { -1394, -2326, -6021, 350 },
+ { 97, -2519, -4678, -2120 },
+ { -1547, -1907, -5069, -2993 },
+ { 268, -3724, -4719, 127 },
+ { -827, -1190, -5912, 1144 },
+ { -3959, -2322, -6898, -1974 },
+ { -2728, -2228, -6426, -562 },
+ { -456, -666, -5785, -1609 },
+ { 531, -1096, -5731, -656 },
+ { -3569, -688, -3915, 110 },
+ { -4752, -1725, -4393, -377 },
+ { -3210, -3315, -6960, -840 },
+ { -688, -3416, -4971, 1221 },
+ { -1833, 77, -6491, -2434 },
+ { -239, -255, -6850, -886 },
+ { -2112, -1490, -6291, -2689 },
+ { -1544, -4579, -5198, -1261 },
+ { -2771, -4014, -5520, 683 },
+ { -1635, -2829, -5512, 1214 },
+ { -958, -2582, -4823, 2360 },
+ { -2077, -4566, -4642, 365 },
+ { -3112, -4214, -5960, -823 },
+ { -2467, -2510, -4858, 1467 },
+ { -1561, -3399, -5822, 211 },
+ { -775, -1081, -4424, 2636 },
+ { -1263, 25, -6378, -1392 },
+ { -3476, -366, -5417, -1393 },
+ { -3176, -1476, -4149, 1466 },
+ { -2479, 518, -4448, -257 },
+ { -2992, 158, -4660, -1279 },
+ { -1320, -3872, -4479, 1147 },
+ { -1475, -312, -5318, 539 },
+ { -3527, -1679, -5860, -1681 },
+ { -3397, -3438, -5593, 1866 },
+ { -4089, -2439, -4763, 1275 },
+ { -748, -4513, -4687, -48 },
+ { -2166, -4531, -4691, -2856 },
+ { -2385, -853, -6035, -627 },
+ { -1194, -4091, -4472, -1963 },
+ { -682, -3234, -4084, -3033 },
+ { -3255, -5015, -5328, -12 },
+ { -2313, -3436, -4601, -155 },
+ { -2792, -1038, -6947, -2019 },
+ { -1244, -1526, -5771, -1882 },
+ { -4679, -3731, -5506, 283 },
+ { -3062, -66, -3558, -758 },
+ { -4895, -1187, 4751, 3728 },
+ { -7600, -2752, 3320, 4613 },
+ { -5703, -2975, 3944, 2659 },
+ { -4972, -1257, -246, 2952 },
+ { -4221, -2487, 1702, 4295 },
+ { -2900, -1529, 2458, 4935 },
+ { -5061, 407, 2416, 4050 },
+ { -6931, -3478, 2761, 2213 },
+ { -6037, -3921, 3192, 1866 },
+ { -6113, -811, 2407, 3782 },
+ { -5878, -1716, 1207, 3478 },
+ { -5953, -2853, 2207, 2712 },
+ { -6807, -3223, 2749, 3595 },
+ { -3272, -3157, 1389, 3788 },
+ { -5368, -1904, 1980, 5077 },
+ { -7235, -1398, 3075, 4548 },
+ { -4765, -3487, 2755, 2796 },
+ { -7658, -4435, 2694, 2582 },
+ { -6997, -4282, 456, 3832 },
+ { -5563, -3115, -63, 3713 },
+ { -4244, -4220, 1450, 2767 },
+ { -3801, -2194, 190, 4303 },
+ { -5458, -4119, 1958, 2274 },
+ { -7300, -3469, 3514, 3193 },
+ { -4594, -2067, 775, 4752 },
+ { -3389, -1654, 1464, 5412 },
+ { -4845, -3483, 964, 3437 },
+ { -6007, -2818, 1666, 4659 },
+ { -8709, -5007, 1757, 3287 },
+ { -5833, -4389, 1025, 3171 },
+ { -5788, -1780, 3944, 3661 },
+ { -4430, -920, 1938, 4753 },
+ { -7066, -1857, 4591, 4538 },
+ { -3549, -513, 1427, 5317 },
+ { -7517, -1220, 2883, 3049 },
+ { -7605, -2687, 1874, 2735 },
+ { -8718, -4035, 2676, 3730 },
+ { -7990, -3907, 1185, 2607 },
+ { -6058, -1744, 3349, 5157 },
+ { -5954, 565, 3161, 3250 },
+ { -6478, -612, 1930, 2271 },
+ { -6535, -1445, -2, 1618 },
+ { -8963, -4151, 1192, 4044 },
+ { -7227, -3570, 1600, 4234 },
+ { -4674, 79, 595, 3015 },
+ { -3974, 430, 2727, 5137 },
+ { -5299, 9, 3714, 4779 },
+ { -6779, -2699, -8, 2436 },
+ { -7016, -1145, 1293, 2310 },
+ { -6955, -3312, 1534, 1801 },
+ { -4025, 740, 1850, 4054 },
+ { -9589, -3460, 4154, 5270 },
+ { -4404, -1181, 4298, 5173 },
+ { -7356, -4583, -18, 2644 },
+ { -6516, -1235, 4439, 6234 },
+ { -3453, -301, 4344, 4464 },
+ { -4643, 1530, 3315, 4340 },
+ { -4575, -2557, 3754, 3682 },
+ { -3643, -3501, 2051, 2997 },
+ { -5412, -2475, 2301, 1579 },
+ { -5846, 259, 1360, 2348 },
+ { -5258, -1358, 1050, 838 },
+ { -5542, -219, 6377, 5750 },
+ { -5713, -2952, 922, 899 },
+ { -2049, -1135, 5206, 1033 },
+ { -1693, -1886, 4835, -106 },
+ { -2344, -3504, 4232, -13 },
+ { -2475, -2334, 5043, 1126 },
+ { -787, -2549, 3880, 2138 },
+ { -3159, -2341, 4830, 2887 },
+ { -1780, -1009, 6240, 2061 },
+ { -4327, -3363, 2818, 886 },
+ { -3376, -2743, 4104, 207 },
+ { -3250, -4640, 2718, 1498 },
+ { -382, -1075, 4382, 3460 },
+ { -2416, -4168, 3530, 816 },
+ { -1756, -2708, 4861, 622 },
+ { -1879, -2097, 5156, 2889 },
+ { -2496, -2418, 3722, 2671 },
+ { -2717, -3252, 3341, 1944 },
+ { -4063, -4091, 3306, 267 },
+ { -3549, -3808, 3747, 842 },
+ { -2635, 546, 5794, 1894 },
+ { -1857, -1121, 4383, 3964 },
+ { -2226, -2166, 3489, 3678 },
+ { -3492, -660, 5323, 1063 },
+ { -3033, -3130, 4382, 1828 },
+ { -2703, -625, 6369, 2851 },
+ { -1656, -2842, 4584, -528 },
+ { -4781, -2622, 4390, 2097 },
+ { -413, -2045, 5081, 3035 },
+ { -3810, -2662, 4532, 1095 },
+ { -3144, -1858, 5215, 1880 },
+ { -3562, -1795, 4928, 670 },
+ { -4800, -1509, 5189, 1859 },
+ { -1085, -3832, 4169, 900 },
+ { -1969, -3270, 2857, 2878 },
+ { -4267, -4140, 3176, 1805 },
+ { -5145, -3727, 3524, 1168 },
+ { -1346, -1876, 5501, 1748 },
+ { -4998, -2945, 3699, 338 },
+ { -3458, -3096, 3406, -635 },
+ { -1751, -3209, 3508, 395 },
+ { -2507, 170, 5987, 705 },
+ { -3756, -1072, 5647, 3536 },
+ { -2870, -1439, 5026, 3212 },
+ { -3913, -3225, 3669, 2144 },
+ { -3739, 226, 5747, 764 },
+ { -2052, -820, 5266, 3093 },
+ { -3214, -3820, 2409, 2391 },
+ { -4398, -2588, 3501, -218 },
+ { -4484, -1763, 4180, -198 },
+ { -3368, -1525, 4362, -134 },
+ { -2407, 224, 4905, 3533 },
+ { -1369, -2937, 4728, 1788 },
+ { -4848, -1707, 4159, 851 },
+ { -3454, -1749, 4281, 3230 },
+ { -1990, -3853, 3487, 1735 },
+ { -3117, 92, 6155, 4075 },
+ { -2676, -2472, 4078, -589 },
+ { -1547, -2012, 2626, 1835 },
+ { -4275, -588, 4824, 725 },
+ { -601, -2249, 3736, 3548 },
+ { -4060, -61, 5333, 3097 },
+ { -4303, 7, 6551, 3054 },
+ { -5003, -1029, 5786, 3319 },
+ { -2810, -728, 5392, 199 },
+ { -1232, -200, 5228, 3121 },
+ { 2621, 165, -6255, 298 },
+ { 3669, 537, -6844, 1564 },
+ { 1598, -1190, -6235, 2523 },
+ { 2164, -32, -6894, 1383 },
+ { 853, -1597, -6069, 1449 },
+ { 1377, -1661, -5266, 108 },
+ { 2660, 48, -5172, -517 },
+ { 1903, -391, -5677, 1010 },
+ { 3792, 206, -5274, -11 },
+ { 1239, 2776, -2929, 2721 },
+ { 4071, 149, -7259, 3125 },
+ { 1436, -480, -6156, -196 },
+ { 1373, -1960, -5005, 3122 },
+ { 3413, -1271, -5176, 3283 },
+ { 3060, -68, -6495, 2238 },
+ { 2700, -2075, -4681, 91 },
+ { 2928, -1728, -5168, 1858 },
+ { 4424, 828, -4471, 88 },
+ { 2672, -2604, -4038, 2753 },
+ { 5223, -123, -6749, 2295 },
+ { 4237, -420, -5538, 1353 },
+ { 4744, -1281, -4097, 4708 },
+ { 1103, -2764, -4751, 2024 },
+ { 3747, -1913, -3911, 3960 },
+ { 2470, -1416, -5542, 615 },
+ { 4847, -1354, -5334, 1733 },
+ { 5336, 88, -7593, 4007 },
+ { 2388, -2880, -4807, 1037 },
+ { 4495, 1391, -5685, -139 },
+ { 5253, 1637, -6450, 1533 },
+ { 1199, 795, -5515, 1261 },
+ { 1397, -1259, -4252, 3838 },
+ { 746, 70, -6640, 604 },
+ { 1584, 166, -4972, 3072 },
+ { 380, -999, -5397, 2267 },
+ { 2974, 1707, -3242, 5360 },
+ { 5202, -403, -5453, 2832 },
+ { 3718, -1731, -4760, 714 },
+ { 4150, -975, -4792, 61 },
+ { 2925, -818, -4841, 15 },
+ { 5301, 577, -4006, 3259 },
+ { 5265, 1986, -5679, 3028 },
+ { 3752, 1928, -4509, 3729 },
+ { 3278, 1925, -6370, 1247 },
+ { 5107, 1721, -4853, 3127 },
+ { 3279, 2982, -2515, 4005 },
+ { 4622, 668, -6204, 759 },
+ { 6034, 317, -5763, 4818 },
+ { -558, 57, -3785, 2817 },
+ { 4476, 1616, -3965, 4536 },
+ { 5953, 2056, -8215, 2715 },
+ { 4387, 2613, -7463, 868 },
+ { 5834, 1088, -4736, 4924 },
+ { 6473, -856, -6991, 4172 },
+ { 4959, -293, -5162, 76 },
+ { 2731, -843, -6119, 3847 },
+ { 3245, 1202, -6833, 616 },
+ { 2553, 1383, -3829, 3859 },
+ { 4332, 2099, -3480, 3622 },
+ { 2110, 2683, -2728, 3990 },
+ { 876, 1167, -3290, 3466 },
+ { 3991, 1709, -2410, 4077 },
+ { 5105, 939, -2584, 3256 },
+ { 4719, 688, -1566, 3040 },
+ { -3632, 4335, 1266, -3303 },
+ { -4956, 3207, 1312, -2806 },
+ { -4669, 2627, 2663, -2435 },
+ { -4282, 3708, 2303, -3038 },
+ { -4536, 2297, -175, -3350 },
+ { -5234, 2503, -139, -880 },
+ { -3978, 1512, 1092, -3619 },
+ { -4519, 4649, 1363, -2455 },
+ { -5118, 3132, 1961, -1577 },
+ { -5196, 3379, -182, -1378 },
+ { -6420, 4486, 2397, -1993 },
+ { -5030, 5046, 1292, -1118 },
+ { -4559, 2573, -927, -1406 },
+ { -3501, 3730, 691, -4930 },
+ { -4364, 2758, 1007, -3909 },
+ { -4026, 2839, -1559, -2340 },
+ { -5037, 4053, 836, -1571 },
+ { -4727, 5136, 1110, -3588 },
+ { -5245, 2799, -999, -2164 },
+ { -4954, 1501, 422, -3963 },
+ { -5994, 2726, 1462, -2833 },
+ { -5621, 5159, 2038, -2512 },
+ { -4991, 2291, 1917, -3151 },
+ { -5469, 4382, -148, -2978 },
+ { -5858, 1983, 807, -2720 },
+ { -4709, 3556, 952, -467 },
+ { -2489, 2362, 1714, -4230 },
+ { -4717, 5004, -1180, -3672 },
+ { -5914, 3653, 1359, -1317 },
+ { -5506, 2995, 780, -1059 },
+ { -5287, 3945, 2480, -2293 },
+ { -3849, 4358, 322, -1770 },
+ { -3911, 3570, 252, -3185 },
+ { -3660, 5128, 158, -3719 },
+ { -4599, 3277, -503, -2727 },
+ { -3673, 3760, -1252, -3339 },
+ { -5161, 2337, 388, -1943 },
+ { -3529, 2216, 2156, -3080 },
+ { -4309, 4331, 1808, -1460 },
+ { -4782, 3820, 480, -2504 },
+ { -4166, 3544, -378, -1567 },
+ { -5572, 2466, -418, -2909 },
+ { -6096, 2930, 119, -1878 },
+ { -5963, 3554, 1011, -2233 },
+ { -6433, 4335, 935, -2930 },
+ { -5004, 3314, -1352, -3430 },
+ { -6042, 3463, -1008, -3940 },
+ { -4671, 2214, -640, -5040 },
+ { -2795, 3759, 1412, -3803 },
+ { -3647, 4436, 729, -515 },
+ { -3594, 1033, 56, -4148 },
+ { -2908, 3027, 2889, -3485 },
+ { -3338, 2234, 313, -4285 },
+ { -3825, 4497, -561, -2634 },
+ { -6167, 3012, -48, -3149 },
+ { -4828, 3515, -969, -4475 },
+ { -5789, 2757, -539, -4173 },
+ { -2452, 3067, 564, -4249 },
+ { -4921, 1358, 1331, -2889 },
+ { -3127, 4239, -1045, -1523 },
+ { -4780, 2326, -1118, -3446 },
+ { -3908, 5546, 152, -2622 },
+ { -6972, 2976, 337, -2809 },
+ { -4839, 4613, -35, -4077 },
+ { -1408, 4822, -1149, -4997 },
+ { -981, 4979, -912, -6304 },
+ { -2098, 5689, -888, -2878 },
+ { -3343, 4814, -657, -4434 },
+ { -2461, 3601, -967, -4869 },
+ { -2652, 3944, 87, -5520 },
+ { -1104, 6076, 174, -6407 },
+ { 355, 5370, -1721, -5869 },
+ { 1242, 4497, -1107, -5091 },
+ { -89, 4002, -1491, -5182 },
+ { 1059, 5693, -1591, -4905 },
+ { 1323, 4682, -2078, -4768 },
+ { 818, 3996, -549, -5468 },
+ { -287, 4529, 929, -5543 },
+ { -919, 5519, -2791, -2844 },
+ { -1407, 5679, -3289, -3974 },
+ { -189, 6530, -3547, -4002 },
+ { -900, 7039, -3371, -4855 },
+ { -2983, 7211, -363, -4835 },
+ { -814, 6503, -104, -5106 },
+ { -2386, 6896, 809, -4919 },
+ { 845, 4492, 352, -6621 },
+ { -1998, 7237, -1646, -4231 },
+ { -3380, 6251, 471, -4577 },
+ { -1908, 7059, 84, -5726 },
+ { -340, 6346, -803, -6265 },
+ { -2279, 5834, -47, -4633 },
+ { -1532, 5286, -1748, -1901 },
+ { -2757, 6188, -453, -3415 },
+ { -1255, 6405, -2043, -6357 },
+ { 918, 5581, -121, -5667 },
+ { 1840, 5336, -821, -5034 },
+ { -2475, 4992, -1825, -3104 },
+ { -2413, 5606, -1789, -4298 },
+ { 132, 5128, -2389, -4442 },
+ { 223, 6400, -2653, -4742 },
+ { -673, 5012, 680, -4582 },
+ { -1657, 6624, -349, -3596 },
+ { -755, 6289, -1860, -3978 },
+ { -572, 6894, -1946, -5207 },
+ { -1141, 4756, -2665, -5586 },
+ { -1073, 4269, -431, -4030 },
+ { 186, 5761, 916, -5868 },
+ { -1907, 4836, 1017, -5106 },
+ { -963, 3363, -1248, -6348 },
+ { -3262, 4774, -1818, -5858 },
+ { 847, 3812, -2538, -4302 },
+ { -1223, 5903, 1360, -5479 },
+ { -1094, 6923, -1244, -2381 },
+ { 267, 6276, -709, -2846 },
+ { -157, 5840, 1124, -4266 },
+ { 889, 3206, -910, -5305 },
+ { -1736, 3344, 582, -4838 },
+ { -2357, 5676, -2695, -6277 },
+ { -1916, 6901, -986, -5397 },
+ { -3062, 6028, -695, -5687 },
+ { 1836, 3566, -1357, -5226 },
+ { -2176, 4938, 646, -3872 },
+ { -2199, 3055, -208, -6124 },
+ { -236, 3032, -821, -5325 },
+ { -3989, 7277, -565, -3899 },
+ { -595, 4362, 74, -5975 },
+ { 684, 5874, -841, -4424 },
+ { -2731, 6305, -2389, -5465 },
+ { -5775, 1325, -56, -2528 },
+ { -7029, -534, -1890, -3278 },
+ { -5798, -15, -2734, -2210 },
+ { -5504, -1198, -353, -3659 },
+ { -5079, 960, -894, -4336 },
+ { -6073, -36, -133, -3014 },
+ { -5782, -259, -1025, -3986 },
+ { -6843, 1262, -807, -1639 },
+ { -5263, -918, -3290, -579 },
+ { -4840, 461, -2158, -533 },
+ { -6014, -50, -620, 504 },
+ { -5843, 241, -1359, -282 },
+ { -5898, 577, 769, -3271 },
+ { -6833, -946, -466, -3347 },
+ { -6026, 1459, -512, -729 },
+ { -7361, 747, -388, -1110 },
+ { -6391, 2142, -1160, -2513 },
+ { -6995, 304, 498, -2673 },
+ { -6757, 679, -386, -433 },
+ { -5222, 1688, -1093, -1032 },
+ { -5019, 575, 184, -3627 },
+ { -4237, 628, -3507, -1243 },
+ { -7479, -456, -1722, -1486 },
+ { -6464, 713, -1273, -1153 },
+ { -6255, 1682, -606, -3607 },
+ { -7033, 1497, -71, -1955 },
+ { -6694, 1556, -1721, -3214 },
+ { -6114, -356, 813, -2575 },
+ { -5308, 632, -1851, -1636 },
+ { -5742, -911, -1733, 383 },
+ { -6083, -387, -2313, -879 },
+ { -6535, -530, -1505, -2083 },
+ { -4896, 1223, -2750, -1816 },
+ { -6392, -463, -3247, -2093 },
+ { -5373, 1264, -2706, -3042 },
+ { -3894, -1390, -1020, -891 },
+ { -6179, 1168, -1966, -1922 },
+ { -5162, 1668, -1617, -1916 },
+ { -6453, 920, -1169, -2432 },
+ { -6130, 2005, -536, -1519 },
+ { -6552, -98, -518, -1938 },
+ { -7528, 355, -1101, -1772 },
+ { -5745, 610, -247, -1360 },
+ { -7003, 177, -2064, -1958 },
+ { -6956, -570, -2220, -4225 },
+ { -7830, 791, -1394, -2774 },
+ { -7634, 480, -3171, -4224 },
+ { -7913, 1154, -350, -2381 },
+ { -5063, 1704, -1804, -2977 },
+ { -4887, -524, -2703, 188 },
+ { -5551, 406, -1620, -3063 },
+ { -7109, 1342, 381, -3021 },
+ { -6846, 631, -458, -3398 },
+ { -4606, -605, 11, -3930 },
+ { -8134, -225, -1738, -2648 },
+ { -7043, 402, -2734, -3059 },
+ { -7417, 1825, -2545, -4389 },
+ { -6971, -236, -1031, -665 },
+ { -5752, 2111, -1632, -3808 },
+ { -7660, -78, -624, -3135 },
+ { -6358, 619, -1951, -3911 },
+ { -8134, 408, -1935, -3695 },
+ { -6335, 1911, -2368, -4505 },
+ { -7116, 2163, -344, -2753 },
+ { 2357, 4488, 2220, -5682 },
+ { 1385, 3206, 2300, -5305 },
+ { 1419, 2557, 5203, -3516 },
+ { 262, 4315, 3920, -1847 },
+ { 3316, 3187, 1612, -5609 },
+ { 1729, 2350, 1673, -6068 },
+ { 1603, 6126, 1467, -2839 },
+ { -1339, 3316, 3691, -3530 },
+ { -563, 4618, 3180, -4548 },
+ { 463, 4624, 3111, -5614 },
+ { 1246, 5455, 3356, -5720 },
+ { 480, 2149, 5422, -2893 },
+ { 1768, 4827, 913, -5579 },
+ { -149, 5381, 4366, -3297 },
+ { 985, 3672, 2644, -92 },
+ { -258, 2911, 5817, -2213 },
+ { 3428, 3289, 3351, -3541 },
+ { -666, 3295, 4727, -2869 },
+ { 35, 6641, 4160, -4052 },
+ { 623, 6787, 3156, -4560 },
+ { 2654, 4360, 4676, -4632 },
+ { 1386, 5246, 4834, -4497 },
+ { 3488, 4574, 3856, -5946 },
+ { 383, 4481, 4168, -4110 },
+ { 1753, 3652, 4288, -3326 },
+ { 1344, 4905, 2508, -4660 },
+ { 1580, 4106, 3104, -2224 },
+ { 2027, 5038, 1683, -1554 },
+ { 446, 3699, 5872, -3013 },
+ { 4637, 4087, 3578, -5018 },
+ { 2629, 3560, 5331, -4900 },
+ { 1527, 6674, 2523, -4131 },
+ { -1437, 2804, 2528, -4464 },
+ { -229, 3355, 2016, -5537 },
+ { 3666, 3418, 4374, -4581 },
+ { 1192, 3799, 923, -6596 },
+ { 2040, 2956, 448, -5322 },
+ { 2468, 5768, 4029, -5869 },
+ { 3438, 6516, 3529, -6667 },
+ { 2737, 5495, 680, -5535 },
+ { 3896, 5727, 1801, -4958 },
+ { 4988, 4957, 3592, -6518 },
+ { -542, 4416, 5794, -2787 },
+ { 4136, 4354, 2064, -4696 },
+ { 3067, 5936, 1207, -3396 },
+ { 2789, 4966, 2405, -3854 },
+ { 1731, 3270, 3251, -1063 },
+ { 1767, 5537, 2084, -2349 },
+ { 465, 3116, 4532, -837 },
+ { 1499, 2627, 4610, -2212 },
+ { 122, 3095, 3642, -3552 },
+ { 2542, 2866, 2705, -6402 },
+ { 3134, 4323, 698, -4785 },
+ { 731, 1859, 3112, -5242 },
+ { 2553, 2980, 3241, -4846 },
+ { 1329, 5310, 1607, -6624 },
+ { 2468, 1858, 3476, -1034 },
+ { -172, 4996, 2000, -5562 },
+ { 2621, 4220, 1574, -3386 },
+ { -333, 1832, 3362, -4117 },
+ { 2169, 6762, 3065, -6225 },
+ { 2844, 5528, 3223, -4765 },
+ { 526, 5175, 1644, -4267 },
+ { 2922, 4426, 2414, -2610 },
+ { 452, 1399, -4516, -2636 },
+ { 2872, 1720, -4667, -1435 },
+ { 1279, 702, -5424, -1984 },
+ { 2187, 870, -5021, -1341 },
+ { 583, -144, -4628, -2464 },
+ { 3, 2237, -5284, -2827 },
+ { -19, 1005, -5460, -1819 },
+ { 2897, 2084, -5885, -515 },
+ { -400, 3370, -5527, -2947 },
+ { 1505, 2593, -5518, -1802 },
+ { 1341, 4534, -5094, -1899 },
+ { 3241, 3670, -5493, -1252 },
+ { -1287, 921, -5994, -1675 },
+ { 627, 408, -6652, -364 },
+ { -260, 1127, -4849, -3247 },
+ { 371, 3400, -5976, -2285 },
+ { 1533, 1566, -6373, -610 },
+ { 2462, 4274, -6184, -1254 },
+ { 1782, 3363, -6222, -1381 },
+ { 572, 4650, -5673, -2754 },
+ { 2674, 3414, -4460, -2154 },
+ { 3614, 3820, -6883, -398 },
+ { 1136, -1, -5511, -1112 },
+ { -1773, 1137, -5647, -2377 },
+ { -753, 2104, -6085, -2565 },
+ { -204, 3025, -4731, -1418 },
+ { -1486, 1438, -4380, -216 },
+ { 302, 858, -5786, -264 },
+ { 3486, 1495, -5234, -783 },
+ { 888, 2327, -3423, -3720 },
+ { -259, 772, -6596, -1311 },
+ { -1197, 2073, -5174, -1826 },
+ { 1500, 3470, -4462, -2645 },
+ { 3072, 1960, -3277, -2264 },
+ { 1841, 952, -4324, -2340 },
+ { 1994, 2200, -3940, -2923 },
+ { -1782, 1699, -4667, -1075 },
+ { -1464, 2906, -3468, -375 },
+ { 366, 2380, -3747, 1467 },
+ { -545, 1645, -4619, 376 },
+ { 1724, 2350, -2374, -3512 },
+ { 3184, 2628, -2996, -3275 },
+ { 734, 2010, -6239, -1479 },
+ { 524, 3756, -4496, -3263 },
+ { 1492, 3570, -3494, -3600 },
+ { -932, 618, -5389, -2894 },
+ { -133, 2161, -4083, -3267 },
+ { 786, 774, -3279, -3731 },
+ { 1078, 803, -3843, -3007 },
+ { -332, 3405, -3347, 40 },
+ { -17, 6, -4005, -3690 },
+ { -189, 4372, -4488, -2561 },
+ { -450, 3846, -3790, -1370 },
+ { 362, 2212, -5272, -15 },
+ { -1529, 791, -6802, -2296 },
+ { 2145, 4241, -4474, 376 },
+ { 1813, 2426, -2932, -2726 },
+ { -542, 4557, -3140, -1080 },
+ { 1192, 3784, -4371, -20 },
+ { 2784, 5188, -6399, -1394 },
+ { 431, 4561, -3673, -1398 },
+ { 1382, 3096, -4083, 1253 },
+ { 1209, 4224, -2930, 1500 },
+ { 2798, 2684, -6676, -606 },
+ { -2396, 1510, -5381, -2713 },
+ { -2625, 2542, -4032, -2880 },
+ { -1231, 3967, -4098, -2886 },
+ { -1393, 2374, -3862, -4525 },
+ { -2495, 1665, -1637, -5445 },
+ { -3854, 1759, -1750, -4944 },
+ { -2373, 1668, -2856, -6251 },
+ { -2668, 1981, -886, -4557 },
+ { -2927, 4427, -3451, -6172 },
+ { -1925, 2596, -4696, -2527 },
+ { -3202, 2847, -3928, -5896 },
+ { -3332, 1665, -5025, -3412 },
+ { -3212, 3115, -4155, -4062 },
+ { -1013, 3205, -5133, -3751 },
+ { -2022, 4595, -3947, -5611 },
+ { -3556, 1755, -3715, -2300 },
+ { -1784, 4114, -2723, -1773 },
+ { -3586, 4081, -2733, -4942 },
+ { -1608, 3685, -4154, -4573 },
+ { -3368, 4042, -4452, -6227 },
+ { -1407, 3881, -5729, -3719 },
+ { -2751, 3281, -5077, -4999 },
+ { -3791, 2410, -4906, -5288 },
+ { -730, 2303, -4217, -3755 },
+ { -1812, 2311, -5492, -3709 },
+ { -610, 4336, -3915, -3783 },
+ { -2841, 4337, -4278, -4430 },
+ { -1662, 4666, -4661, -3964 },
+ { -589, 5209, -4923, -3682 },
+ { -4155, 2234, -4076, -4218 },
+ { -3951, 2770, -2665, -2805 },
+ { -2302, 3228, -3717, -1908 },
+ { -3129, 4373, -2264, -2851 },
+ { -447, 1363, -3578, -4323 },
+ { -2648, 4237, -3159, -3071 },
+ { -4072, 3241, -3541, -4605 },
+ { -4507, 3458, -2339, -3838 },
+ { -1646, 997, -4926, -3970 },
+ { -3025, 1614, -3940, -1242 },
+ { -1337, 1756, -3163, -5529 },
+ { -3203, 1865, -3282, -4354 },
+ { -1646, 2118, -2203, -6018 },
+ { 174, 1871, -2707, -4639 },
+ { -2607, 1485, -4778, -4750 },
+ { -2199, 3991, -3134, -4879 },
+ { -2962, 3323, -2816, -2419 },
+ { -5286, 2495, -4548, -5395 },
+ { -2810, 3710, -2274, -4211 },
+ { -330, 3006, -2993, -4678 },
+ { -1187, 2411, -2743, -5196 },
+ { -664, 4033, -3101, -5641 },
+ { -1458, 3602, -2816, -5371 },
+ { -4116, 4923, -3321, -5630 },
+ { -4165, 2528, -2592, -4798 },
+ { -2759, 3080, -2333, -5719 },
+ { -5157, 3011, -5526, -6348 },
+ { -3095, 2126, -5881, -4234 },
+ { -4377, 3849, -3600, -6099 },
+ { -1994, 4947, -5235, -4753 },
+ { -1067, 600, -3258, -5133 },
+ { -4992, 3302, -2208, -5051 },
+ { -3377, 2981, -1655, -4815 },
+ { -3325, 2446, -1787, -6116 },
+ { -2341, 2737, -3240, -6347 },
+ { -2258, -3732, 3710, -1235 },
+ { -1558, -3849, 2694, -3012 },
+ { -599, -4837, 3050, -2951 },
+ { -2246, -5433, 2798, -1910 },
+ { -2255, -4989, 3260, 270 },
+ { -3026, -5353, 2693, -1036 },
+ { -1151, -6097, 1097, -3782 },
+ { -3391, -6012, 2130, -1303 },
+ { -2850, -4422, 3375, -480 },
+ { -1138, -3779, 1491, -4162 },
+ { -551, -3892, 3787, -2082 },
+ { -3221, -3676, 3144, -1202 },
+ { -3023, -5196, 2650, 605 },
+ { -1756, -5729, 2646, 321 },
+ { -2693, -4409, 494, -4797 },
+ { -1913, -4573, 3372, -1730 },
+ { -1277, -3604, 4061, -993 },
+ { -420, -4993, 1351, -4796 },
+ { -3052, -5333, 1435, -1242 },
+ { -602, -5034, 3869, -1141 },
+ { -2436, -4680, 1665, -3019 },
+ { -2657, -3658, 1459, -3391 },
+ { -1220, -6246, 2749, -525 },
+ { -3838, -4844, 2265, -1735 },
+ { -1247, -5679, 3356, -1417 },
+ { -917, -5448, 3342, 105 },
+ { -1756, -6839, 2276, -2350 },
+ { -412, -5206, 1764, -3539 },
+ { -1439, -6915, 1442, -3750 },
+ { -1381, -4439, 3863, -282 },
+ { -3482, -4953, 2726, -336 },
+ { -1376, -5931, 1714, -1987 },
+ { -1716, -4405, 2608, 105 },
+ { -1590, -5191, 2652, -2704 },
+ { -2149, -6442, 2453, -1263 },
+ { -3426, -3832, 2334, -1829 },
+ { -2747, -5948, 2362, -173 },
+ { -2435, -3267, 2966, -1710 },
+ { -3979, -4282, 2705, -775 },
+ { -356, -4238, 2544, -4343 },
+ { -1363, -6471, 2817, -1836 },
+ { -2878, -5117, 218, -3149 },
+ { -3539, -5196, 1710, -2356 },
+ { -2888, -4537, 2746, -1701 },
+ { -1870, -4439, 1496, -4121 },
+ { -1486, -3388, 3349, -2145 },
+ { -3333, -4138, 1467, -2876 },
+ { -345, -5340, 1012, -1190 },
+ { -1672, -4992, 2289, -1029 },
+ { -2146, -5528, 3038, -635 },
+ { -316, -3656, 3426, -3152 },
+ { -2695, -5812, 2336, -2050 },
+ { -2067, -6052, 737, -3258 },
+ { -2664, -4205, -350, -1266 },
+ { -617, -5406, 80, -4853 },
+ { -2418, -3825, 1853, -1326 },
+ { -1961, -4339, 583, -4315 },
+ { -1495, -5141, -133, -5205 },
+ { -3208, -6440, 1691, -2069 },
+ { -2632, -3633, 2325, -2761 },
+ { -2624, -5670, 1252, -3676 },
+ { -3687, -5608, 687, -2833 },
+ { -3320, -5707, 16, -3877 },
+ { -2738, -6112, 84, -5135 },
+ { 2277, -5661, 3076, 843 },
+ { 1555, -5769, 2821, -5236 },
+ { 536, -6381, 603, -4910 },
+ { 734, -4609, 3314, -4092 },
+ { 1836, -4547, 3267, -4322 },
+ { -13, -5976, 3752, -1607 },
+ { 1423, -6318, 2336, 398 },
+ { 365, -7779, 1498, -534 },
+ { 2104, -8366, 2946, -1345 },
+ { 143, -5545, 1898, -3756 },
+ { 655, -6852, 1430, 148 },
+ { 4, -6653, 2397, -59 },
+ { 2346, -5996, 4562, -934 },
+ { 1229, -7104, 2963, -598 },
+ { -528, -7048, 2887, -1790 },
+ { 1451, -6857, 3900, -1637 },
+ { 554, -6018, 3336, 9 },
+ { 3278, -5758, 4034, 129 },
+ { 3541, -7145, 4905, -1575 },
+ { 2339, -6907, 3464, -301 },
+ { 2775, -7301, 1667, -3894 },
+ { 539, -7887, 991, -4156 },
+ { 2115, -7421, 3131, -3075 },
+ { 2803, -8546, 2564, -5836 },
+ { 2869, -5833, 1620, -4561 },
+ { 2591, -7281, 3215, -4719 },
+ { -1228, -8477, 706, -4782 },
+ { 1967, -5243, 4813, -1940 },
+ { 701, -7010, 2273, -3893 },
+ { 915, -8470, 1918, -5620 },
+ { -94, -6715, 156, -3873 },
+ { 1074, -5607, 4389, -1017 },
+ { 2739, -6551, 1227, -3521 },
+ { 725, -7835, 2701, -1291 },
+ { -493, -7475, 2263, -1075 },
+ { -412, -6508, 2984, -744 },
+ { 665, -5451, 3725, -2692 },
+ { 1499, -8129, 3564, -2072 },
+ { 2870, -6333, 4487, -2108 },
+ { 706, -5007, 3911, -152 },
+ { -482, -8660, 1483, -2900 },
+ { 2481, -6596, 2518, -1715 },
+ { 1403, -6414, 1398, -5387 },
+ { 652, -6267, 583, -5942 },
+ { 694, -7540, 646, -6272 },
+ { 2275, -7614, 256, -5015 },
+ { 1416, -9727, 1900, -3153 },
+ { 2760, -6433, 3875, -3771 },
+ { 2325, -11196, 2182, -5155 },
+ { 1223, -11061, 1377, -5097 },
+ { 108, -10603, 307, -4952 },
+ { -118, -8268, 1650, -1572 },
+ { 1839, -7943, 1755, -612 },
+ { 2501, -9056, 981, -2969 },
+ { 2902, -8476, 1491, -5780 },
+ { 1995, -11175, 1585, -3643 },
+ { 696, -8212, 828, -2474 },
+ { 1526, -8649, 1380, -1210 },
+ { 461, -7253, 3222, -2229 },
+ { 2966, -8641, 4121, -3271 },
+ { 833, -6039, 2361, -1086 },
+ { 3565, -7312, 1980, -5427 },
+ { 2850, -8671, 3760, -1846 },
+ { 2643, -7281, 2163, -173 },
+ { 3463, -3706, -3132, -923 },
+ { 1315, -3825, -3443, 2 },
+ { 2594, -4083, -3815, 670 },
+ { 1826, -4291, -2741, -155 },
+ { 868, -3749, -4175, -298 },
+ { 2008, -4237, -3897, -517 },
+ { 1242, -3493, -4335, -1335 },
+ { -88, -4142, -3390, -1529 },
+ { 2176, -3488, -3822, -975 },
+ { 1706, -5188, -3415, -637 },
+ { 2717, -6159, -2333, -882 },
+ { 1276, -3978, -4361, 537 },
+ { 2471, -5556, -2866, -208 },
+ { 799, -4673, -4086, 56 },
+ { 1901, -4786, -3533, 270 },
+ { 3036, -3902, -3606, -333 },
+ { 2249, -3317, -4319, -144 },
+ { 2594, -4207, -2105, -2930 },
+ { 4008, -4774, -2626, -902 },
+ { 1038, -3659, -3496, -2454 },
+ { 2725, -3597, -3298, -1535 },
+ { 1662, -5803, -2813, 175 },
+ { 705, -3757, -3441, -1484 },
+ { 1860, -5987, -2821, -886 },
+ { 3786, -4918, -2199, -1929 },
+ { 3683, -4235, -2547, -1287 },
+ { 2531, -4896, -2956, -1593 },
+ { 1005, -5585, -3324, -180 },
+ { 1625, -5229, -1756, -3642 },
+ { 1494, -5041, -2989, -2685 },
+ { 2718, -4655, -3224, -867 },
+ { 2374, -6640, -1745, -2975 },
+ { 2133, -6436, -2477, -1499 },
+ { 1833, -4418, -3523, -1512 },
+ { 1128, -4910, -2658, -1106 },
+ { 689, -4777, -2831, -2085 },
+ { 3593, -5280, -2627, -315 },
+ { 3264, -3771, -2673, -1861 },
+ { 3202, -5602, -2409, 402 },
+ { 552, -4618, -2221, -3002 },
+ { 3095, -5356, -2666, -1083 },
+ { 3401, -4609, -3146, 45 },
+ { 3051, -4662, -2192, -2232 },
+ { 2798, -5552, -2462, -1941 },
+ { 2354, -5815, -2223, -2619 },
+ { 192, -3708, -2807, -2658 },
+ { 1886, -4226, -1862, -3529 },
+ { 2526, -3976, -2819, -2332 },
+ { 1577, -3870, -2711, -2806 },
+ { 1288, -5588, -3382, -1403 },
+ { 2711, -5399, -1564, -3253 },
+ { 1459, -5492, -2222, -322 },
+ { 2823, -5091, -2886, 776 },
+ { 3559, -5821, -2109, -1360 },
+ { 1587, -6331, -2760, -1909 },
+ { 2139, -5213, -2874, -2120 },
+ { 1318, -4337, -3695, -2098 },
+ { 821, -4471, -1849, -565 },
+ { 3329, -4782, -1725, -89 },
+ { 582, -4914, -4105, -1119 },
+ { 417, -4144, -4072, -2529 },
+ { -199, -3803, -2765, -4042 },
+ { 2731, -4283, -2143, 1 },
+ { 2911, -6187, -1951, -2116 },
+ { 1573, -6094, -493, -2838 },
+ { 2081, -6927, -864, -3211 },
+ { 1058, -7826, 79, -364 },
+ { 3147, -5570, -684, -978 },
+ { 3572, -5856, 1060, 1824 },
+ { 1143, -6702, -1478, 338 },
+ { 2341, -7220, -88, 260 },
+ { 3639, -6861, 668, 815 },
+ { 2227, -6268, -1706, 446 },
+ { 3390, -6082, -353, 1302 },
+ { 1123, -7556, -1237, -430 },
+ { 1729, -7742, 729, -218 },
+ { 1457, -6774, 587, 579 },
+ { 505, -6919, -569, 371 },
+ { 1106, -7245, 78, 158 },
+ { 2755, -6745, -1122, 338 },
+ { 3069, -6040, -1415, 986 },
+ { 2174, -7064, -1430, -283 },
+ { 1390, -8626, -446, -3031 },
+ { 3534, -6890, -431, 547 },
+ { 2267, -9618, 475, -2994 },
+ { 3672, -7673, 75, -115 },
+ { 2131, -7560, -1206, -750 },
+ { 2972, -7477, -685, -262 },
+ { 1604, -6637, -672, 699 },
+ { 1666, -7577, -577, -240 },
+ { 1591, -6554, -2158, -94 },
+ { 2348, -6286, -353, 1123 },
+ { 2017, -8810, -412, -1805 },
+ { 2892, -6713, -1765, -554 },
+ { 2500, -6828, -1995, -1197 },
+ { 3877, -6639, -224, -1655 },
+ { 2392, -7872, -91, -333 },
+ { 3562, -7370, -532, -2836 },
+ { 2552, -7614, 164, -1805 },
+ { 990, -6104, 218, 438 },
+ { 910, -7861, 312, -1195 },
+ { 1472, -6327, 372, -640 },
+ { 1576, -7143, -1983, -843 },
+ { 422, -7625, -457, -278 },
+ { 1797, -8532, 405, -1011 },
+ { 1088, -7396, -238, -2277 },
+ { 3209, -6753, -1431, -2072 },
+ { 2617, -6839, 100, -2573 },
+ { 2575, -8573, -387, -3188 },
+ { 3618, -6971, -1190, -321 },
+ { 2205, -7361, -1695, -2008 },
+ { 2985, -6297, 1464, 1179 },
+ { 2804, -7310, 1053, 338 },
+ { 1362, -6074, -1163, -840 },
+ { 3336, -6325, -1794, 21 },
+ { 2836, -8109, 818, -329 },
+ { 2791, -5879, 560, 1546 },
+ { 2392, -6064, 135, 100 },
+ { 1838, -6194, 596, 1085 },
+ { 1926, -7515, -414, -4901 },
+ { 3225, -7298, -1202, -1189 },
+ { 3960, -7558, -659, -719 },
+ { 3442, -6647, -1692, -1095 },
+ { 3381, -6441, 262, -886 },
+ { 1431, -8150, -1186, -1406 },
+ { 340, -8498, -150, -899 },
+ { 3004, -8149, -260, -953 },
+ { 2749, -6611, 563, 873 },
+ { -6647, -1325, -4517, -4691 },
+ { -6005, -1657, -4089, -3797 },
+ { -3157, 588, -5213, -3068 },
+ { -3311, -1425, -6329, -3726 },
+ { -5866, -819, -3857, -2744 },
+ { -5001, -1799, -1075, -4621 },
+ { -5330, -2650, -2672, -4664 },
+ { -4930, -539, -2363, -4010 },
+ { -2984, 10, -3863, -5749 },
+ { -1055, -2106, -3713, -4267 },
+ { -5476, -502, -4279, -6504 },
+ { -5231, -1543, -5018, -6425 },
+ { -5134, -363, -3165, -5109 },
+ { -3953, -771, -4107, -6393 },
+ { -2159, -563, -3652, -5342 },
+ { -3888, -2321, -919, -5057 },
+ { -1236, -597, -4235, -4193 },
+ { -4053, 675, -3083, -6174 },
+ { -2793, -1089, -5396, -3460 },
+ { -3000, -44, -2209, -6575 },
+ { -3336, -1531, -4313, -5160 },
+ { -2127, 128, -4851, -3692 },
+ { -3321, 136, -2067, -5660 },
+ { -5215, 1404, -4374, -4356 },
+ { -2747, 400, -6340, -3691 },
+ { -3926, -599, -5361, -5006 },
+ { -2875, -2592, -5143, -4092 },
+ { -4991, -1958, -5322, -4891 },
+ { -4965, -1318, -6652, -5333 },
+ { -4920, -1691, -3388, -5561 },
+ { -3644, -3354, -2688, -5982 },
+ { -5076, -919, -4563, -2984 },
+ { -6114, 250, -3884, -3915 },
+ { -4014, 744, -3973, -1924 },
+ { -5543, -1041, -5557, -3847 },
+ { -4711, -1352, -5649, -2603 },
+ { -3362, 775, -5305, -4879 },
+ { -5001, 107, -3554, -2888 },
+ { -6258, -1651, -6356, -6566 },
+ { -4529, 407, -5003, -3865 },
+ { -5154, 550, -5278, -5465 },
+ { -4195, -467, -1894, -3129 },
+ { -5022, 1127, -3349, -3314 },
+ { -6075, 1250, -4313, -5641 },
+ { -2677, -2283, -2312, -5903 },
+ { -4113, 193, -1195, -4833 },
+ { -3940, -1048, -1389, -5079 },
+ { -3703, 917, -4043, -4451 },
+ { -3366, -4231, -1534, -5488 },
+ { -3326, -3583, -2091, -4903 },
+ { -5144, 1254, -2532, -4949 },
+ { -5982, -870, -2545, -4555 },
+ { -3925, -157, -5367, -2281 },
+ { -6419, -746, -5668, -4371 },
+ { -5787, 518, -7096, -5805 },
+ { -4258, 954, -6453, -4321 },
+ { -4771, -695, -4158, -1639 },
+ { -7078, -760, -5195, -5877 },
+ { -7348, 83, -4101, -4586 },
+ { -2430, 184, -2874, -1679 },
+ { -2284, -3943, -2924, -5034 },
+ { -1804, -1785, -3002, -4710 },
+ { -4399, -2772, -1815, -4637 },
+ { -6340, -2626, -2824, -5191 },
+ { -4998, -5168, -3480, 1905 },
+ { -3958, -5492, -1599, 1579 },
+ { -2471, -3755, -276, 3182 },
+ { -3033, -5779, -1063, 1554 },
+ { -2936, -4829, -1290, 2386 },
+ { -1835, -5073, -3051, 1299 },
+ { -1724, -3771, -3935, 2324 },
+ { -5070, -2550, -3692, 768 },
+ { -4326, -5333, -297, 1878 },
+ { -3472, -5619, -3094, 992 },
+ { -3027, -4384, -3038, 2265 },
+ { -3201, -5332, 67, 2200 },
+ { -1681, -4373, -1947, 2461 },
+ { -3221, -3329, -4238, 2564 },
+ { -1262, -2968, -2915, 3227 },
+ { -3419, -1878, -3373, 2110 },
+ { -2244, -5583, -2012, 1288 },
+ { -1971, -5266, -990, 1812 },
+ { -2975, -2778, -452, 4063 },
+ { -2198, -1165, -3298, 2965 },
+ { -4782, -4894, -4767, 664 },
+ { -6002, -3950, -2806, 2025 },
+ { -3142, -3162, -2859, 3295 },
+ { -3262, -3340, -4123, 1596 },
+ { -4014, -3918, -1955, 3361 },
+ { -1700, -3463, -1346, 3449 },
+ { -4245, -4445, -4743, 1644 },
+ { -4180, -3969, -401, 3281 },
+ { -2782, -5240, -4117, 1156 },
+ { -5744, -4040, -1439, 3470 },
+ { -5063, -4663, -323, 3172 },
+ { -4531, -3319, -844, 3988 },
+ { -6226, -5125, -2064, 2976 },
+ { -3115, -3267, -1531, 3898 },
+ { -4628, -4421, -2864, 2808 },
+ { -4559, -2989, -3442, 2024 },
+ { -1775, -4487, -656, 2477 },
+ { -2664, -1865, -1884, 4081 },
+ { -1828, -2575, -3894, 3378 },
+ { -6441, -3677, -2025, 1677 },
+ { -4141, -2156, -1191, 3474 },
+ { -4802, -1623, -1727, 2160 },
+ { -5474, -2745, -1475, 2498 },
+ { -3664, -1056, -1975, 2491 },
+ { -4672, -3062, -2235, 2933 },
+ { -4205, -5960, -2849, 1517 },
+ { -4995, -5708, -1739, 1805 },
+ { -4892, -6080, -4793, 872 },
+ { -4270, -4172, -4263, 2185 },
+ { -4687, -1470, -2905, 1023 },
+ { -6446, -5017, -3919, 1000 },
+ { -6046, -5538, -3943, 2006 },
+ { -6028, -3750, -3953, 771 },
+ { -5959, -4582, -5024, 824 },
+ { -5818, -2576, -2249, 1326 },
+ { -5659, -5345, -1119, 2500 },
+ { -3346, -4155, 606, 2749 },
+ { -5680, -4827, -2501, 1838 },
+ { -6193, -2543, -1295, 840 },
+ { -6871, -4925, -3512, 1801 },
+ { -5605, -1788, -1895, 779 },
+ { -3922, -5712, -4644, 510 },
+ { -4745, -3869, -4533, 99 },
+ { -2984, -4907, -399, 1497 },
+ { 1847, -478, 3061, -5812 },
+ { 4450, -1116, 3609, -6570 },
+ { 3139, 99, 3007, -5532 },
+ { 2590, -3782, 3138, -4770 },
+ { 1881, 1204, 5778, -3404 },
+ { 3631, 2060, 5566, -5038 },
+ { 3461, 1961, 5167, -3800 },
+ { 2947, 273, 4536, -4389 },
+ { 4453, -1730, 5788, -4370 },
+ { 4032, 1805, 2666, -4534 },
+ { 3487, -944, 2313, -6028 },
+ { 1313, 34, 4210, -4067 },
+ { 5632, -1502, 5825, -5855 },
+ { 7736, -547, 4879, -5476 },
+ { 4906, -1512, 4760, -5760 },
+ { 3843, 447, 1091, -4958 },
+ { 2982, -1135, 5442, -4386 },
+ { 3579, 271, 3031, -6770 },
+ { 3932, -211, 4688, -5507 },
+ { 4411, 1720, 2387, -5584 },
+ { 5379, -479, 4575, -6280 },
+ { 3613, -362, 2012, -4885 },
+ { 3744, -2013, 4493, -5073 },
+ { 5693, 109, 4379, -3362 },
+ { 5475, -621, 5317, -3985 },
+ { 6411, -673, 5708, -4752 },
+ { 4933, -796, 7262, -4290 },
+ { 2804, 444, 6276, -3655 },
+ { 4120, -517, 6078, -4531 },
+ { 5119, 841, 3486, -3910 },
+ { 4738, 1539, 3525, -2970 },
+ { 5086, 370, 5895, -5640 },
+ { 4235, 2716, 4589, -5044 },
+ { 3691, 682, 6199, -4700 },
+ { 6111, -570, 6271, -6528 },
+ { 2611, 1277, 3756, -4802 },
+ { 4395, 970, 3807, -5879 },
+ { 5225, 2299, 3242, -4333 },
+ { 5144, 1778, 4946, -5545 },
+ { 2989, -3016, 3247, -5495 },
+ { 2983, 920, 2071, -6059 },
+ { 5270, -903, 4434, -2350 },
+ { 6415, -585, 3970, -3554 },
+ { 3866, -197, 5216, -2884 },
+ { 3767, -1298, 6702, -3315 },
+ { 6299, 2620, 5284, -6824 },
+ { 6654, 646, 3653, -4927 },
+ { 4770, 3047, 5160, -6287 },
+ { 5364, 434, 2919, -5207 },
+ { 2998, 1344, 4801, -2456 },
+ { 3896, 1013, 3773, -1864 },
+ { 2115, 655, 2999, -6344 },
+ { 5170, -981, 2849, -4464 },
+ { 2735, -2159, 2717, -5776 },
+ { 2430, -1952, 4392, -4559 },
+ { 6143, -1180, 3659, -4746 },
+ { 4978, -1483, 1726, -4875 },
+ { 3486, -2383, 3306, -4301 },
+ { 1434, -1372, 4171, -4770 },
+ { 3354, -2627, 1525, -5093 },
+ { 6790, 2386, 3995, -5909 },
+ { 1475, -2674, 3451, -4204 },
+ { 1999, -3494, 3693, -5556 },
+ { 4764, -2848, 2856, -5589 },
+ { -3677, 5131, 2827, -2934 },
+ { -2844, 7078, 2852, -3580 },
+ { -3902, 6434, 4118, -1911 },
+ { -1769, 7530, 3492, -3541 },
+ { -1937, 5679, -447, -1127 },
+ { -2456, 4680, 4196, -2407 },
+ { -2778, 8241, 1698, -4288 },
+ { -2876, 6104, 5182, -2387 },
+ { -2802, 7341, 4463, -2938 },
+ { -1025, 6267, 4752, -3201 },
+ { -2349, 5413, 2041, -3794 },
+ { -2252, 8225, 2856, -4269 },
+ { -1465, 4967, 4976, -2500 },
+ { -636, 7565, 3517, -4233 },
+ { -1905, 5618, 3904, -2942 },
+ { -302, 6816, 3343, -3316 },
+ { -2210, 4156, 2817, -3511 },
+ { -717, 6568, 1863, -2951 },
+ { -3873, 5682, 2164, -575 },
+ { -2878, 5835, 440, -2597 },
+ { -3228, 7701, 2610, -2514 },
+ { -3608, 8888, 3377, -2468 },
+ { -2582, 9717, 2519, -3126 },
+ { -5238, 6202, 2866, -2831 },
+ { -3428, 7370, 3056, -335 },
+ { -1681, 8836, 1210, -2010 },
+ { -3276, 6724, 1156, -3930 },
+ { -894, 8149, 827, -1258 },
+ { -2965, 8631, 2549, -1320 },
+ { -3961, 6902, 3581, 55 },
+ { -1894, 7745, 1750, -841 },
+ { -821, 6844, 850, -676 },
+ { -608, 6948, -4, -1376 },
+ { 615, 6524, 1089, -1147 },
+ { -2972, 5668, 1091, -489 },
+ { -157, 4649, 2904, -413 },
+ { 673, 5121, 1498, -66 },
+ { -390, 5902, 1611, -245 },
+ { -2349, 5478, 4772, -1320 },
+ { 88, 6798, 1972, -1859 },
+ { -1213, 5120, 2991, 200 },
+ { -2347, 6040, 2839, 376 },
+ { -578, 5976, 3364, -1796 },
+ { -1391, 5872, 3002, -965 },
+ { -564, 4496, 3946, -1186 },
+ { -2299, 6386, 3135, -2176 },
+ { -2131, 5641, 2011, 1223 },
+ { -772, 5807, 1124, 895 },
+ { -2837, 6758, 2297, -740 },
+ { -3091, 6298, 1415, -2126 },
+ { -4197, 6036, 1843, -3022 },
+ { -41, 6459, 92, 344 },
+ { -2241, 6860, 2095, -4396 },
+ { -1931, 7088, 2117, -2135 },
+ { -2375, 4422, 1688, -3169 },
+ { -1742, 6674, 1538, -119 },
+ { -4818, 7749, 4192, -1577 },
+ { -2004, 5672, 193, -430 },
+ { -3825, 6042, 2128, -1898 },
+ { -1108, 8033, 2119, -3013 },
+ { -2370, 5453, 1721, 266 },
+ { -1570, 7134, 614, -2638 },
+ { -1519, 8752, 3503, -4330 },
+ { -2050, 3845, 2907, -1126 },
+ { 5085, 4412, -335, -1923 },
+ { 3618, 1423, -613, -4012 },
+ { 4481, 3729, 589, -4631 },
+ { 4270, 3216, -1763, -3168 },
+ { 4241, 1796, -1701, -2796 },
+ { 4787, 2338, -487, -3639 },
+ { 2915, 3429, -621, -4753 },
+ { 5175, 1660, -1265, -3223 },
+ { 4280, 4057, -684, -4079 },
+ { 4980, 4419, -1455, -2719 },
+ { 5436, 2464, 387, -4197 },
+ { 4507, 4018, 1121, -3314 },
+ { 6020, 2401, -413, -3201 },
+ { 4200, 3789, -333, -2813 },
+ { 5229, 2493, -1194, -1878 },
+ { 5851, 2695, -492, -2292 },
+ { 5743, 3288, -697, -1221 },
+ { 5692, 2612, 979, -2227 },
+ { 5085, 2067, 1046, -1214 },
+ { 3163, 2240, -2098, -3435 },
+ { 5228, 1898, 145, -2397 },
+ { 5860, 3976, -418, -2872 },
+ { 6008, 3399, 1027, -3506 },
+ { 4126, 2035, 1865, -893 },
+ { 5375, 3596, 511, -2362 },
+ { 1937, 1493, -852, -122 },
+ { 3473, 4849, 547, -2603 },
+ { 4631, 2977, 1141, -1768 },
+ { 6149, 3050, -71, -1886 },
+ { 4069, 4353, -289, -1429 },
+ { 2884, 1225, -1388, 365 },
+ { 5485, 2518, -235, -571 },
+ { 1216, 4375, 1443, 398 },
+ { 4988, 3106, 107, -1435 },
+ { 4511, 2801, 307, -444 },
+ { 3235, 4386, 327, -676 },
+ { 2055, 3708, 1657, -305 },
+ { 5839, 2374, 290, -1385 },
+ { 5110, 3305, 1936, -4206 },
+ { 6416, 2920, 338, -2736 },
+ { 3350, 2824, -1269, -3881 },
+ { 4840, 1815, 464, 186 },
+ { 2399, 3332, 238, 1238 },
+ { 3516, 1363, 1582, 688 },
+ { 3582, 1874, 154, -4770 },
+ { 3261, 2878, 886, 283 },
+ { 3877, 2658, -327, 884 },
+ { 4151, 3436, 2173, -2923 },
+ { 3592, 3674, 1281, -1295 },
+ { 4561, 3730, -1114, -1747 },
+ { 4595, 3625, -558, -575 },
+ { 2577, 2348, 2267, 120 },
+ { 5242, 3299, 32, -3412 },
+ { 4264, 3637, 709, -2320 },
+ { 6556, 3570, -838, -2472 },
+ { 5745, 4014, -940, -1973 },
+ { 5629, 4475, 477, -3328 },
+ { 5269, 3199, 1682, -3085 },
+ { 4432, 2416, 1145, -3299 },
+ { 4465, 2505, 2162, -2186 },
+ { 4643, 4941, -88, -2885 },
+ { 4568, 5231, 552, -3915 },
+ { 5667, 3075, -1406, -2963 },
+ { 5418, 5259, -771, -2818 },
+ { -256, -7875, 511, -471 },
+ { -1813, -7971, -424, -396 },
+ { -306, -7006, 862, 282 },
+ { -2306, -6422, -1440, 508 },
+ { -245, -6787, 375, -100 },
+ { -1309, -6065, -20, 779 },
+ { -1656, -6047, -641, 1307 },
+ { -1496, -6522, 964, 726 },
+ { -2291, -6588, -202, 795 },
+ { -762, -7522, 1454, -558 },
+ { -2270, -7004, -834, -580 },
+ { -1139, -7078, 259, 362 },
+ { -2535, -7568, -1040, 49 },
+ { -3786, -7280, 934, -476 },
+ { -3336, -6368, 606, 1056 },
+ { -3602, -6924, 52, 714 },
+ { -2278, -6550, 1674, 204 },
+ { -2855, -5765, 930, 1530 },
+ { -2889, -7325, -215, 305 },
+ { -2749, -6080, -237, 1452 },
+ { -985, -6667, 1577, 400 },
+ { -2036, -6083, 380, 1267 },
+ { -2077, -7460, 380, -30 },
+ { -1775, -7175, 1540, -386 },
+ { -3065, -6927, 989, 168 },
+ { -2836, -7602, 117, -3392 },
+ { -1058, -6396, 593, -3078 },
+ { -844, -6062, 999, -236 },
+ { -3261, -6951, 1491, -720 },
+ { -2186, -8484, 75, -1287 },
+ { -2882, -7756, 456, -510 },
+ { -1800, -6879, 960, -1183 },
+ { -2554, -7241, 1614, -1474 },
+ { -2608, -5305, 392, 851 },
+ { -2973, -6562, -859, 858 },
+ { -2640, -5989, 1031, -416 },
+ { -977, -8366, 705, -1434 },
+ { -1213, -7409, -77, -1390 },
+ { -1335, -6657, 2125, -123 },
+ { -2544, -6862, 1852, -737 },
+ { -3235, -6422, 1752, -103 },
+ { -1300, -7557, 939, -348 },
+ { -3476, -7579, 202, -109 },
+ { -2482, -6572, 753, 619 },
+ { -2554, -8136, -648, -429 },
+ { -1012, -7870, -3, -421 },
+ { -3604, -6247, 32, -3102 },
+ { -1486, -7271, 2013, -1021 },
+ { -578, -6799, -523, 405 },
+ { -2841, -5948, 1644, 911 },
+ { -2411, -7473, 1084, -484 },
+ { -2238, -6033, 294, -1059 },
+ { -3459, -6470, -201, -790 },
+ { -2027, -6009, 1833, 805 },
+ { -1433, -8047, 1531, -1754 },
+ { -3258, -7884, 763, -1422 },
+ { -1544, -6928, -729, 478 },
+ { -2314, -8415, 74, -3757 },
+ { -3201, -5684, 95, -2214 },
+ { -2423, -8694, 725, -3631 },
+ { -3545, -7071, 1162, -1798 },
+ { -294, -9662, 403, -2274 },
+ { -2290, -5460, 1196, 402 },
+ { -1603, -6713, 903, -2363 },
+ { 4121, 2491, -3142, -2482 },
+ { 4500, 3305, -3671, -1567 },
+ { 5973, 3172, -1348, -534 },
+ { 4830, 3379, -1549, 643 },
+ { 5214, 3938, -2641, -2302 },
+ { 4639, 4826, -5532, -847 },
+ { 5639, 2731, -2170, -963 },
+ { 6084, 3487, -3525, -1346 },
+ { 5971, 3154, -2190, -2316 },
+ { 5618, 4865, -6927, 116 },
+ { 5345, 3568, -7391, 709 },
+ { 5429, 5078, -3811, -1524 },
+ { 6960, 2037, -3515, -1096 },
+ { 7092, 2531, -4557, -588 },
+ { 6061, 4247, -5651, -478 },
+ { 4595, 3684, -4907, -827 },
+ { 7497, 3213, -3048, -424 },
+ { 5996, 2137, -3098, -1745 },
+ { 6198, 5199, -2223, -2274 },
+ { 6888, 2851, -2768, -1675 },
+ { 6114, 4210, -2316, -954 },
+ { 7127, 4242, -3041, -1408 },
+ { 6126, 3668, -1517, -1427 },
+ { 6245, 6129, -4225, -1186 },
+ { 6816, 3213, -2101, -964 },
+ { 5345, 5276, -2643, -847 },
+ { 6592, 4665, -4338, 484 },
+ { 6746, 3751, -3443, 124 },
+ { 5453, 1980, -2738, 2606 },
+ { 4662, 2179, -4226, -1059 },
+ { 5571, 3208, -3554, 174 },
+ { 5256, 4447, -1815, -1481 },
+ { 5400, 2570, -1210, 235 },
+ { 7056, 2549, -2674, 318 },
+ { 4574, 4340, -2892, -130 },
+ { 6203, 4587, -3273, -305 },
+ { 5103, 1925, -2715, -2137 },
+ { 3905, 4296, -1700, 247 },
+ { 4421, 4605, -3299, 811 },
+ { 5671, 1273, -3870, -924 },
+ { 5486, 1805, -4901, 133 },
+ { 6437, 2578, -1828, -106 },
+ { 5530, 5253, -5058, 1223 },
+ { 4816, 2025, -1215, 1443 },
+ { 3457, 3525, -2456, 3217 },
+ { 3316, 2595, -1108, 2459 },
+ { 3068, 3810, -2207, 1926 },
+ { 6351, 5436, -6470, 600 },
+ { 6324, 4240, -5365, 2416 },
+ { 4851, 4774, -4075, 1878 },
+ { 4900, 3679, -5198, 1078 },
+ { 8347, 3633, -4565, -171 },
+ { 5244, 5718, -3853, 173 },
+ { 3960, 3492, -2939, 2105 },
+ { 6070, 3473, -2351, 161 },
+ { 8228, 3034, -3360, -901 },
+ { 7006, 3985, -1940, -1926 },
+ { 7123, 4681, -4301, -878 },
+ { 5122, 4097, -1851, -449 },
+ { 6200, 2060, -2251, 1049 },
+ { 7106, 3844, -7209, 2625 },
+ { 7108, 3370, -6734, 533 },
+ { 6859, 2849, -3992, 1360 },
+ { 5458, 2278, -3253, 1131 },
+ { -1072, -2109, 4783, -1073 },
+ { -319, -2604, 4257, -2418 },
+ { 2466, 1300, 3476, -314 },
+ { 2847, -1502, 5296, -141 },
+ { 1667, -1273, 5559, -2725 },
+ { 2877, -3402, 6434, 204 },
+ { 53, -2637, 5275, -1181 },
+ { 1091, -2215, 5803, -1549 },
+ { 2397, -922, 4327, 1182 },
+ { 219, -3747, 4647, -1564 },
+ { -29, -2705, 4812, 1277 },
+ { 1499, -2608, 5648, 1407 },
+ { 2139, -2399, 4202, 2791 },
+ { -426, -2064, 5528, 151 },
+ { 2560, -2803, 6179, -2806 },
+ { 4537, -2479, 3797, 1095 },
+ { 888, -3357, 5341, -415 },
+ { 4460, -1814, 5388, -1227 },
+ { 3920, -3268, 6364, -703 },
+ { 3343, -4698, 4410, 784 },
+ { 309, -1897, 6306, 1223 },
+ { 958, -3318, 4254, -3167 },
+ { -99, 1596, 6018, -1983 },
+ { -429, -853, 6407, 878 },
+ { 1170, -1322, 6290, -417 },
+ { 2288, -505, 6303, -1999 },
+ { 3312, -1674, 6749, -2494 },
+ { -415, -3401, 4721, -371 },
+ { -189, -1210, 4844, -2002 },
+ { 888, -4142, 4377, 130 },
+ { 2469, -4381, 5398, -2492 },
+ { 2879, -2912, 5094, -2598 },
+ { -717, -617, 5650, -685 },
+ { 1470, -3863, 5352, -1684 },
+ { 3935, -96, 3823, -730 },
+ { 3769, -430, 3168, 694 },
+ { 2556, 385, 3539, 512 },
+ { 77, -1415, 5111, 2655 },
+ { 2724, -2158, 6715, -822 },
+ { 1832, 1001, 5385, -1900 },
+ { 900, 2198, 4464, -559 },
+ { 441, 69, 5921, -1743 },
+ { -1161, 738, 6732, -308 },
+ { 257, 2035, 4091, 736 },
+ { 1607, 1288, 4355, -23 },
+ { -13, 1316, 4180, 1672 },
+ { 1511, 1336, 3057, 1435 },
+ { 2189, -3813, 4530, 939 },
+ { 3632, -706, 2646, 1375 },
+ { 4266, -3761, 4241, 1077 },
+ { 3101, -427, 5273, -1202 },
+ { 2293, 276, 4810, -313 },
+ { 3430, -1851, 3101, 2045 },
+ { 3453, -2979, 5142, 942 },
+ { 1683, -3281, 4802, 2002 },
+ { 3954, -4715, 5611, 578 },
+ { 1272, -155, 5085, 454 },
+ { 128, -194, 5095, 1409 },
+ { 820, 880, 5797, -2658 },
+ { -1095, 656, 5774, 1095 },
+ { 813, -1669, 4320, -3251 },
+ { -119, 518, 6372, -651 },
+ { 2922, -4299, 6115, -877 },
+ { 4205, -4273, 4004, 2642 },
+ { -1211, -3892, 224, 3127 },
+ { -34, -4371, 1321, 2318 },
+ { 77, -6326, 1201, 828 },
+ { 3995, -3775, 1958, 3233 },
+ { 178, -3301, 1985, 3318 },
+ { 2330, -3801, 1033, 3195 },
+ { 1413, -5536, 826, 1709 },
+ { 2468, -3499, 3653, 3631 },
+ { 741, -4617, 1723, 2008 },
+ { 1246, -3043, 2978, 3949 },
+ { -343, -4308, 2258, 2189 },
+ { -682, -4640, 454, 2272 },
+ { 1236, -4829, 2491, 1642 },
+ { -512, -3766, 1182, 3052 },
+ { 119, -3939, 3712, 971 },
+ { -1145, -4624, 1360, 2281 },
+ { 101, -4746, 2866, 1255 },
+ { -1500, -5455, 539, 1637 },
+ { -969, -5909, 1414, 1128 },
+ { -1261, -4939, -231, 2022 },
+ { -226, -5345, 1207, 705 },
+ { 2712, -5109, 3205, 1866 },
+ { -476, -5913, 273, 1208 },
+ { -2039, -4464, 624, 2545 },
+ { -2351, -3930, 2019, 2673 },
+ { -2675, -4849, 1522, 1990 },
+ { -1524, -3461, 1446, 3204 },
+ { 477, -5314, 1710, 1577 },
+ { 656, -3729, 2346, 2511 },
+ { 550, -5917, 1975, 1040 },
+ { 1728, -4704, 3067, 1058 },
+ { -9, -5247, 506, 1760 },
+ { -574, -5135, 1675, 1672 },
+ { 2129, -3781, 3444, 2313 },
+ { 1144, -4439, 2214, 2529 },
+ { 1292, -4160, 3185, 1833 },
+ { 2445, -3262, 2534, 3227 },
+ { 2266, -4401, 2023, 2400 },
+ { -587, -3602, 3408, 2067 },
+ { -885, -4951, 3228, 1174 },
+ { -728, -2711, 2807, 3552 },
+ { 1019, -3043, 3195, 2954 },
+ { 1888, -4615, 1140, 2454 },
+ { 660, -5616, 754, 800 },
+ { -1975, -5371, 1649, 1585 },
+ { -1544, -5436, 2422, 1081 },
+ { -422, -5882, 2390, 750 },
+ { 1336, -5557, 2441, 1230 },
+ { 136, -4001, 267, 2854 },
+ { -522, -3289, 2226, 2728 },
+ { -971, -4580, 2471, 708 },
+ { 704, -5306, 3300, 1001 },
+ { 325, -3464, 3555, 2398 },
+ { 794, -3686, 848, 3169 },
+ { 660, -3017, 4584, 3242 },
+ { -1486, -3978, 2170, 1644 },
+ { -1615, -4650, 2688, 1844 },
+ { 750, -4578, 538, 2239 },
+ { 1668, -5849, 1455, 1031 },
+ { 3486, -4681, 2030, 2183 },
+ { 2642, -5429, 1696, 1761 },
+ { 4491, -4502, 3538, 2767 },
+ { 3545, -4528, 3514, 2982 },
+ { 3269, -3676, 2758, 3966 },
+ { 5572, 1146, 209, -3379 },
+ { 7459, 1053, 593, -1896 },
+ { 4480, 200, -310, -4259 },
+ { 5577, -939, 242, -3992 },
+ { 8142, 442, 1257, -3083 },
+ { 5442, 1261, 1424, -3236 },
+ { 6260, -183, 3125, -2532 },
+ { 7179, 889, 1618, -2548 },
+ { 6416, 932, 2379, -2487 },
+ { 7094, 2560, 961, -3392 },
+ { 7322, 463, 2732, -3735 },
+ { 6632, 1577, 1912, -3272 },
+ { 6312, 1349, 3028, -3460 },
+ { 6105, 386, 1213, -977 },
+ { 5478, 1158, 1114, -486 },
+ { 6493, 410, 1686, -2180 },
+ { 6378, 1881, 1333, -2240 },
+ { 5711, 812, 1958, -1300 },
+ { 6844, 877, 730, -1189 },
+ { 6824, -245, 2249, -2000 },
+ { 7515, 1521, 1251, -3058 },
+ { 6697, 1051, 1300, -1749 },
+ { 6476, 1425, 811, -2773 },
+ { 7350, 465, -76, -2849 },
+ { 6975, 2095, 567, -2492 },
+ { 4691, 1736, 2660, -2289 },
+ { 7837, 1456, 340, -2767 },
+ { 7930, 507, 838, -2074 },
+ { 6106, 1502, 766, -1110 },
+ { 4891, -659, 835, -3954 },
+ { 7250, 141, 1369, -1523 },
+ { 7651, 67, 1651, -2298 },
+ { 7364, -305, 601, -3132 },
+ { 7179, 193, 2491, -2871 },
+ { 6504, -272, 2167, -1322 },
+ { 4456, 983, 2300, -421 },
+ { 4817, 457, 1695, 371 },
+ { 6914, 555, 850, -3159 },
+ { 5904, 1030, 202, -1959 },
+ { 6258, 880, 2233, -4503 },
+ { 6029, 10, 2130, -3600 },
+ { 6449, 985, 1129, -3963 },
+ { 6616, -18, -111, -3285 },
+ { 4496, 775, 817, -4276 },
+ { 6134, 2338, 1470, -2973 },
+ { 6911, 152, 430, -1946 },
+ { 4053, 991, 3218, -1193 },
+ { 5435, 1285, 3124, -2412 },
+ { 5507, 1836, 1935, -1988 },
+ { 5240, 689, 2189, -2670 },
+ { 6638, 1719, 606, -1799 },
+ { 5556, -180, 129, -2595 },
+ { 5644, 1918, 1281, -4316 },
+ { 6410, 1088, -282, -3117 },
+ { 6503, 1841, 312, -3514 },
+ { 6947, 20, 1358, -3886 },
+ { 5464, 2109, 2398, -3194 },
+ { 5616, -407, 2140, -498 },
+ { 6121, 2707, 2379, -4096 },
+ { 7303, 1846, 2266, -4095 },
+ { 5444, 470, 2718, -1553 },
+ { 5817, -645, 3285, -1349 },
+ { 5625, 1427, 1103, -1991 },
+ { 6041, -806, 1196, -2943 },
+ { 3050, -5722, 4070, -5460 },
+ { 3420, -4386, 4078, -5155 },
+ { 6020, -3982, 7268, -2689 },
+ { 7502, -4317, 7894, -3973 },
+ { 4156, -3558, 5247, -4316 },
+ { 4725, -4401, 7290, -1540 },
+ { 6688, -5122, 8216, -3210 },
+ { 9176, -6576, 9276, -4963 },
+ { 8706, -5708, 7987, -4621 },
+ { 7060, -3535, 6532, -3308 },
+ { 5600, -2719, 5363, -1568 },
+ { 4661, -2803, 6263, -4716 },
+ { 3673, -3636, 6147, -3433 },
+ { 5305, -2585, 6073, -2638 },
+ { 7614, -1962, 6079, -5266 },
+ { 6760, -3366, 7382, -4322 },
+ { 6385, -3883, 4797, -1353 },
+ { 8182, -5120, 4298, -4641 },
+ { 9130, -6198, 4975, -3063 },
+ { 7421, -5436, 5576, -3713 },
+ { 3483, -4898, 5443, -2745 },
+ { 4907, -5643, 6390, -4105 },
+ { 8119, -7008, 7992, -6764 },
+ { 6528, -6122, 6967, -5590 },
+ { 5890, -4190, 6624, -5688 },
+ { 6815, -7934, 7275, -5456 },
+ { 5434, -4306, 5169, -5378 },
+ { 4364, -6436, 5376, -2604 },
+ { 8152, -3404, 5913, -5048 },
+ { 7983, -4863, 4262, -2461 },
+ { 8023, -6188, 6238, -5062 },
+ { 6753, -3692, 3935, -3723 },
+ { 6826, -4760, 3284, -4051 },
+ { 7224, -7423, 4492, -3875 },
+ { 6904, -2590, 6587, -6248 },
+ { 6106, -1944, 7345, -5506 },
+ { 4956, -2990, 7808, -3146 },
+ { 6908, -6885, 5949, -1288 },
+ { 7162, -6058, 3419, -3401 },
+ { 7015, -7080, 6907, -3018 },
+ { 6971, -6832, 5646, -3273 },
+ { 8014, -5546, 5471, -1544 },
+ { 6792, -2220, 5105, -2879 },
+ { 8494, -3974, 4408, -3999 },
+ { 9591, -4866, 6027, -4558 },
+ { 5264, -5161, 6101, -738 },
+ { 5803, -6141, 5197, -5231 },
+ { 4657, -6822, 3232, -5189 },
+ { 4791, -5135, 3809, -4665 },
+ { 6108, -5103, 2379, -3873 },
+ { 4680, -3909, 3234, -5093 },
+ { 5802, -3853, 3795, -4984 },
+ { 4360, -7483, 4802, -3877 },
+ { 5429, -7517, 5911, -3717 },
+ { 6866, -2280, 4880, -4634 },
+ { 10131, -4628, 4414, -4092 },
+ { 10811, -5189, 7746, -5337 },
+ { 5663, -8941, 5287, -5680 },
+ { 8023, -5991, 7403, -2796 },
+ { 9669, -6919, 6525, -4932 },
+ { 7275, -3796, 4962, -2547 },
+ { 8848, -4806, 5677, -3080 },
+ { 8128, -4308, 7749, -6569 },
+ { 4032, -5196, 2282, -6239 },
+ { 6593, 700, -229, 304 },
+ { 8260, 539, -66, -1259 },
+ { 6605, 176, -814, -109 },
+ { 8057, 0, -1, -136 },
+ { 7382, -38, -484, -1129 },
+ { 8373, -929, 682, -454 },
+ { 7674, 690, -1278, 546 },
+ { 7326, -517, 406, -1283 },
+ { 7612, -1715, -1167, 1175 },
+ { 8590, 441, -782, -710 },
+ { 8572, -1202, -291, 260 },
+ { 7308, -147, -1785, 414 },
+ { 6787, -353, -672, 934 },
+ { 5177, -133, 179, 82 },
+ { 4161, -34, 447, 1497 },
+ { 5997, -902, 1533, -121 },
+ { 5727, -871, -1370, 945 },
+ { 8386, -252, 293, -823 },
+ { 6573, -1354, 682, 616 },
+ { 7650, -2096, 725, 457 },
+ { 8122, 78, 636, -1400 },
+ { 8421, 428, -1620, 131 },
+ { 7341, -1292, -717, 186 },
+ { 7998, -49, -720, 266 },
+ { 5987, -351, 669, 844 },
+ { 7314, -1620, 250, -603 },
+ { 7219, -1562, -572, 1994 },
+ { 8682, -358, -290, -388 },
+ { 5810, 155, -178, 1199 },
+ { 7246, -12, 1042, -786 },
+ { 7357, -923, 1468, -475 },
+ { 7801, 621, -212, -724 },
+ { 5346, -514, 1210, 1356 },
+ { 8459, 36, -127, -779 },
+ { 6878, -2429, 854, 1750 },
+ { 7280, -1401, -1353, 2845 },
+ { 7579, -2148, -1463, 2087 },
+ { 6637, 946, -872, 750 },
+ { 4807, -1100, 1289, 2602 },
+ { 4495, 219, 1551, 1128 },
+ { 7639, 506, 446, -1107 },
+ { 6359, 188, 1009, -115 },
+ { 6641, -1820, 1655, 723 },
+ { 5394, -2382, 1604, 2542 },
+ { 6021, -2644, 2396, 1407 },
+ { 4698, 882, 245, 1525 },
+ { 8103, 573, -798, -349 },
+ { 8045, -519, 997, -1092 },
+ { 7571, -122, 227, -338 },
+ { 5347, -1200, 630, 1718 },
+ { 7070, 790, 218, -544 },
+ { 7440, 728, -527, -20 },
+ { 6402, -355, 197, -736 },
+ { 4031, 771, 866, 1895 },
+ { 6009, 896, 445, -31 },
+ { 5160, 1098, -856, 1784 },
+ { 7980, -886, -1293, 1396 },
+ { 6318, -1361, 2423, 252 },
+ { 7547, -699, 133, 506 },
+ { 8562, -2344, 940, 264 },
+ { 5890, 1187, -1425, 2194 },
+ { 6558, -645, -1311, 2621 },
+ { 4634, -1671, 2075, 1623 },
+ { 5614, 105, -816, 2376 },
+ { 6646, 1558, -1365, 630 },
+ { 6998, 1150, -2117, -990 },
+ { 6555, 2311, -1093, -1783 },
+ { 6682, 1430, -2391, -1940 },
+ { 7861, 1555, -2977, -1188 },
+ { 6745, 1723, -459, -2085 },
+ { 7504, 1229, -1666, -2060 },
+ { 7937, 671, -2128, -1529 },
+ { 7139, 991, -735, -2632 },
+ { 6867, 1592, -1303, -2324 },
+ { 6401, 2230, -1732, -2508 },
+ { 7201, 2184, -2169, -1988 },
+ { 6636, 2190, -995, -2840 },
+ { 7620, 2306, -2089, -651 },
+ { 7584, 1875, -1438, -631 },
+ { 9214, 1561, -2464, -1139 },
+ { 6154, 1318, -1237, -2917 },
+ { 7917, 2847, -1797, -1599 },
+ { 8309, 2029, -2555, -465 },
+ { 8204, 1282, -584, -2405 },
+ { 8440, 1035, -1147, -1137 },
+ { 7107, 1858, -60, -1568 },
+ { 6781, 2912, -873, -1463 },
+ { 7603, 1316, -319, -1249 },
+ { 7833, 1335, -78, -1849 },
+ { 7930, 1141, -1016, -695 },
+ { 7883, 1610, -1017, -1314 },
+ { 8069, 1409, -1811, -196 },
+ { 8319, 1031, -582, -1590 },
+ { 5948, 1537, -2153, -2373 },
+ { 8684, 1171, -1871, -850 },
+ { 8357, 2484, -2411, -1292 },
+ { 6516, 2092, -193, -1167 },
+ { 6112, 1697, 22, -525 },
+ { 7161, 703, -602, -1879 },
+ { 6047, 2351, -807, -219 },
+ { 8072, 1854, -1817, -1553 },
+ { 6956, 1304, 76, -1011 },
+ { 6607, 1481, -544, -162 },
+ { 6958, 2541, -265, -1938 },
+ { 6416, 2514, -777, -850 },
+ { 7272, 2110, -899, -1171 },
+ { 7741, 2153, -283, -2614 },
+ { 6482, 2041, -1758, -1221 },
+ { 6762, 940, -1862, -2281 },
+ { 5610, 1194, -1691, -1561 },
+ { 7833, 2164, -823, -1952 },
+ { 5460, 1438, -848, 1189 },
+ { 6011, 1377, -771, -1557 },
+ { 7679, 544, -1134, -2214 },
+ { 7209, 1292, -2714, -1564 },
+ { 5567, 1200, -404, -169 },
+ { 5853, 1461, -1465, -518 },
+ { 6782, 689, -844, -860 },
+ { 7330, 1337, -1152, -71 },
+ { 7189, 1506, -653, -685 },
+ { 6860, 2116, -1403, -240 },
+ { 8804, 1516, -1391, -1760 },
+ { 7210, 2689, -1498, -989 },
+ { 7030, 3022, -1441, -2083 },
+ { 5649, 1836, -407, 525 },
+ { 7451, 3099, -717, -2464 },
+ { 7384, 1656, -2007, 398 },
+ { 6504, 707, -1919, -134 },
+ { -1851, 3639, -2279, -695 },
+ { -4037, 1644, -77, 1329 },
+ { -4025, 1960, -1565, -567 },
+ { -3430, 2495, -795, 368 },
+ { -4771, 2480, 993, 756 },
+ { -3431, 2058, -2539, -971 },
+ { -3802, 3418, 380, 217 },
+ { -3074, 3350, -1652, -1056 },
+ { -3705, 326, -1650, 1535 },
+ { -3122, 1281, -1192, 1607 },
+ { -4601, 1367, -968, 53 },
+ { -3808, 958, 44, 2560 },
+ { -2079, 2530, -1485, 1166 },
+ { -3707, 343, -2889, 180 },
+ { -5249, 1431, -31, 688 },
+ { -4990, 125, -704, 1270 },
+ { -2771, 1334, -2446, 746 },
+ { -2292, 994, -1527, 2630 },
+ { -1261, 3070, -2519, 268 },
+ { -2544, 3890, -1057, -552 },
+ { -4421, 255, -1980, 530 },
+ { -2951, 454, -13, 3643 },
+ { -2262, 1815, -370, 2880 },
+ { -2383, 3657, -649, 576 },
+ { -3541, -161, -1389, 2550 },
+ { -4241, 1575, 1325, 2561 },
+ { -2767, 4037, 1221, 1578 },
+ { -3748, 2697, 1148, 1801 },
+ { -4686, 2385, -220, 0 },
+ { -1531, 1645, -2751, 1327 },
+ { -45, 4032, -799, 2298 },
+ { -2915, 2280, 709, 2495 },
+ { -1199, 3278, -406, 2346 },
+ { -2471, 116, -2706, 2060 },
+ { -2440, 2173, -2894, -344 },
+ { -3375, 2287, 1781, 3226 },
+ { -2153, 3568, 1827, 2918 },
+ { -862, 2267, -1626, 2527 },
+ { -2698, 1135, 301, 4239 },
+ { -2364, 2123, 1010, 3710 },
+ { -2447, 3281, -81, 1408 },
+ { -2660, 4735, 472, 258 },
+ { -1053, 3097, 2682, 2398 },
+ { -3366, -1037, -1152, -868 },
+ { -643, 4242, 2212, 1259 },
+ { 971, 3991, 934, 643 },
+ { -1617, 2002, 2139, 2195 },
+ { -4897, 972, 784, 1719 },
+ { -1275, 2992, 1039, 3821 },
+ { -392, 4973, -209, 1821 },
+ { -1028, 4718, -1479, -137 },
+ { 50, 3914, 553, 2210 },
+ { 678, 4364, 359, 1303 },
+ { -582, 4911, 514, 1671 },
+ { 1276, 3914, -1252, 2934 },
+ { -1496, 3984, 857, 2330 },
+ { 772, 4744, -655, 2332 },
+ { -799, 5283, -439, 624 },
+ { 1341, 2937, 650, 2027 },
+ { -1739, 4892, 1275, 1702 },
+ { -892, 2596, -151, 3951 },
+ { -3532, 1090, 1292, 32 },
+ { 321, 3146, 2647, 1475 },
+ { 264, 4199, -1591, 1317 },
+ { -452, -2357, 2266, 4192 },
+ { 3022, -1033, -2389, 5678 },
+ { -1162, -1342, 3543, 4990 },
+ { -474, -1477, -1223, 5016 },
+ { -699, -2857, 900, 3835 },
+ { -461, -2255, -117, 4626 },
+ { 1204, -2062, -1211, 4403 },
+ { 2192, -3035, -337, 3966 },
+ { 108, -831, 279, 5643 },
+ { 1457, -620, -2908, 5276 },
+ { -2527, -78, 1085, 5460 },
+ { -1978, -1918, -949, 4733 },
+ { 32, 367, -1904, 5166 },
+ { 1890, -1665, 440, 4752 },
+ { -518, -348, 2816, 4891 },
+ { 3695, -2490, -1374, 4603 },
+ { 246, -1965, 3549, 3969 },
+ { 1100, -3111, 656, 3737 },
+ { -1379, 870, -414, 4575 },
+ { 628, -357, -1227, 6179 },
+ { -1129, -1318, -2457, 4576 },
+ { -425, -98, -73, 6336 },
+ { 367, -887, 2990, 4207 },
+ { 2091, -1251, 2444, 3557 },
+ { -1759, -1610, 2046, 5273 },
+ { 3210, 1414, -20, 2616 },
+ { 3303, -2636, 1005, 4237 },
+ { -327, -3107, -640, 3687 },
+ { -197, 764, 572, 5486 },
+ { 646, -767, 1388, 5464 },
+ { 104, 2742, -228, 3907 },
+ { -236, 1829, -579, 4585 },
+ { -2150, -474, -1525, 4006 },
+ { -23, -2632, -2400, 3892 },
+ { -12, -1739, -2910, 4867 },
+ { -2310, -368, -102, 4583 },
+ { -1991, -2061, 533, 4531 },
+ { 3884, -1446, -153, 4393 },
+ { 1568, 14, -289, 5268 },
+ { -1376, -253, -2797, 3417 },
+ { 3193, -2577, 2475, 3566 },
+ { 3418, 617, 1350, 1857 },
+ { 3792, -24, -272, 3370 },
+ { 153, 1159, 2906, 2877 },
+ { 511, 2162, 1548, 2741 },
+ { 262, 819, -2791, 3734 },
+ { 4232, -2015, 1486, 3477 },
+ { 2943, -1110, -1014, 5480 },
+ { 2842, 369, 703, 3476 },
+ { 3011, 1634, -933, 3553 },
+ { 4412, -1548, -942, 5021 },
+ { -1405, 593, 2372, 5267 },
+ { 2093, 2129, 896, 2365 },
+ { 4845, -1980, 0, 3823 },
+ { -2140, 81, 3278, 5637 },
+ { 1484, 2665, -324, 3653 },
+ { 10, 192, 1620, 5291 },
+ { 2152, 738, -2269, 5000 },
+ { 2102, 2748, -1652, 4707 },
+ { 2855, -2131, -387, 5188 },
+ { 1173, 676, 1338, 3277 },
+ { 2340, -2329, -2064, 4095 },
+ { 861, -2024, 1296, 5055 },
+ { 2189, 3225, -695, 2626 },
+ { 6196, -7079, 1943, -822 },
+ { 4547, -4813, 3261, 1856 },
+ { 4243, -6904, 3443, 448 },
+ { 4581, -7503, 946, 506 },
+ { 6626, -7754, 3427, 470 },
+ { 3407, -9088, 3269, -1496 },
+ { 4079, -6464, 2304, 777 },
+ { 5621, -9336, 2684, -768 },
+ { 5351, -6464, 5238, -214 },
+ { 5961, -8007, 1724, -3091 },
+ { 4213, -8067, 603, -246 },
+ { 7208, -7403, 3168, -1738 },
+ { 6098, -7700, 329, -1379 },
+ { 6525, -6735, 4248, -1072 },
+ { 6073, -6241, 2167, -2378 },
+ { 4609, -9218, 3051, -1033 },
+ { 6813, -7283, 1581, -1897 },
+ { 6126, -6275, 2789, 681 },
+ { 4423, -6538, 1621, -1692 },
+ { 6272, -8298, 3167, -1855 },
+ { 6172, -8558, 4498, -1169 },
+ { 4844, -8588, 1647, -366 },
+ { 6209, -8807, 1581, -369 },
+ { 5389, -8059, 550, -192 },
+ { 6654, -9775, 2504, -1063 },
+ { 7103, -7998, 806, 530 },
+ { 5662, -6736, 1565, -3620 },
+ { 4165, -9564, 4191, -2131 },
+ { 4526, -7181, 576, -2875 },
+ { 4633, -8623, 2807, -4742 },
+ { 3709, -7794, 1815, 34 },
+ { 3634, -8622, 2313, -826 },
+ { 6991, -8447, 2063, -3198 },
+ { 7757, -9486, 2255, -558 },
+ { 4149, -7778, 4728, -1696 },
+ { 5767, -7427, 1113, 707 },
+ { 4592, -6261, 2329, 1864 },
+ { 3159, -10498, 1677, -4273 },
+ { 3534, -9010, 2437, -3565 },
+ { 4479, -10821, 2715, -4942 },
+ { 3207, -9805, 3054, -3886 },
+ { 4627, -8189, 3018, -2354 },
+ { 5527, -10566, 3244, -2749 },
+ { 4346, -10127, 3335, -3084 },
+ { 6132, -10085, 3316, -1308 },
+ { 5629, -9704, 2178, -3058 },
+ { 3603, -8538, 1246, -624 },
+ { 3737, -8488, 395, -3167 },
+ { 5465, -11414, 2810, -4640 },
+ { 5306, -7745, 2721, -3988 },
+ { 7000, -9111, 1695, -1409 },
+ { 6663, -7741, 2466, -4079 },
+ { 4083, -7175, 1836, -4831 },
+ { 3613, -9926, 1342, -3455 },
+ { 6588, -8033, 457, -258 },
+ { 4720, -8102, 17, -1209 },
+ { 7414, -8709, 1294, -344 },
+ { 5437, -10030, 4043, -1704 },
+ { 4862, -9281, 1558, -1431 },
+ { 6800, -6403, 5113, 862 },
+ { 4623, -8242, 2667, -228 },
+ { 5919, -5083, 3348, 2135 },
+ { 5985, -8889, 2733, -5105 },
+ { 5029, -5767, 4407, 719 },
+ { 354, -6158, -838, -3001 },
+ { 351, -5943, -2104, -1534 },
+ { -633, -7190, -25, -4798 },
+ { -1595, -7235, -3812, -1400 },
+ { 103, -6197, -2933, -78 },
+ { -1722, -5020, -3441, -4333 },
+ { -1963, -5644, -4365, -270 },
+ { -846, -5743, -3477, 196 },
+ { -191, -5348, -4054, -469 },
+ { -2515, -7754, -3495, -818 },
+ { -2090, -6710, -2701, 117 },
+ { -546, -7036, -1398, 163 },
+ { -278, -7091, -2662, -536 },
+ { -622, -7962, -2731, -1464 },
+ { -1555, -8118, -3612, -2057 },
+ { -1094, -6280, -2314, 505 },
+ { -2556, -8538, -4024, -2247 },
+ { 109, -7134, -3107, -1823 },
+ { -900, -6954, -3340, -717 },
+ { -605, -7113, -3656, -2154 },
+ { 837, -6263, -3211, -2177 },
+ { -417, -5810, -3871, -1469 },
+ { -1318, -5649, -4207, -3198 },
+ { 413, -6765, -2082, -33 },
+ { -3101, -6450, -4362, -766 },
+ { 755, -6489, -2967, -846 },
+ { 1117, -7106, -2452, -1352 },
+ { -1202, -8387, -3072, -2897 },
+ { -365, -4894, -3561, -2937 },
+ { -2372, -8776, -265, -4441 },
+ { -1224, -8678, -896, -5074 },
+ { -755, -10096, -600, -6623 },
+ { 300, -8206, -225, -4568 },
+ { -1176, -6824, -2633, -3527 },
+ { -2006, -5443, -1526, -5849 },
+ { -1115, -5540, -2363, -4785 },
+ { 1059, -6812, -2543, -2654 },
+ { -1976, -6861, -3062, -5508 },
+ { -379, -5328, -2321, -3624 },
+ { -2108, -5860, -4518, -1915 },
+ { -379, -7885, -1329, -594 },
+ { 774, -5389, -581, -5213 },
+ { -2601, -5083, -1849, -4921 },
+ { -176, -5580, 74, -5075 },
+ { -204, -6780, -190, -6232 },
+ { 418, -7594, -1987, -820 },
+ { -1873, -8529, -2926, -1609 },
+ { 1340, -6362, -919, -4975 },
+ { 577, -7990, -2044, -1873 },
+ { -2572, -7413, -1745, -2224 },
+ { -2037, -7030, -1461, -7138 },
+ { -2559, -8756, -2039, -5836 },
+ { -2079, -6764, -1209, -5669 },
+ { -1613, -7801, -2006, -685 },
+ { -1865, -6583, -722, -3529 },
+ { -589, -6358, -1377, -1003 },
+ { -540, -7514, -1331, -3542 },
+ { 419, -6192, -1677, -4927 },
+ { -2786, -8763, -2966, -5065 },
+ { -2172, -8411, -1726, -4675 },
+ { -3382, -9833, -3497, -5722 },
+ { -2433, -10169, -2077, -5775 },
+ { -424, -9451, -1096, -3658 },
+ { -537, -8522, -910, -1897 },
+ { -5550, 2807, 1683, -693 },
+ { -6395, 635, 3573, -1246 },
+ { -7544, 2280, 2140, 44 },
+ { -8751, 1136, 2951, -794 },
+ { -5605, 2709, 2052, 916 },
+ { -7650, 654, 869, 135 },
+ { -6939, 967, 1409, 870 },
+ { -7834, 2123, 3310, 974 },
+ { -6935, 2818, 1274, -1678 },
+ { -5605, 2233, 1013, 471 },
+ { -7095, 1849, 1648, 198 },
+ { -6636, 1634, 712, -37 },
+ { -7279, 978, 296, -315 },
+ { -7664, 3504, 3292, -216 },
+ { -7836, 1209, 1221, -257 },
+ { -7913, 2201, 1765, -1529 },
+ { -7077, 3783, 2632, -1407 },
+ { -5565, 1645, 1410, -622 },
+ { -6494, 2879, 1181, -759 },
+ { -7073, 3137, 3010, 550 },
+ { -7249, 1839, 847, -805 },
+ { -6630, 2197, 282, -1096 },
+ { -8836, 1573, 1988, -1090 },
+ { -7809, 1274, 836, -1198 },
+ { -7895, 2970, 3511, -1097 },
+ { -6960, 1664, 1356, -2442 },
+ { -6582, 2866, 2273, 307 },
+ { -7221, 821, 2851, -1435 },
+ { -6015, 1703, 2001, -2367 },
+ { -8082, 1034, 2103, 239 },
+ { -5952, 1912, 301, -465 },
+ { -6099, 841, 379, 567 },
+ { -6343, 50, 494, 658 },
+ { -6586, 983, 591, -893 },
+ { -5500, 869, 2187, -2479 },
+ { -6482, 60, 1545, -979 },
+ { -6705, 515, 1974, -53 },
+ { -6460, 1755, 1325, -1275 },
+ { -6093, 2617, 2465, -623 },
+ { -7330, 2161, 594, -2115 },
+ { -7324, 762, 1593, -2004 },
+ { -6385, 679, 1510, -2514 },
+ { -6159, 241, 2976, -1631 },
+ { -8583, 3030, 4045, -162 },
+ { -6299, 66, 2209, -2103 },
+ { -5428, 1279, 3267, -1846 },
+ { -6438, 1335, 2728, -1631 },
+ { -8012, 1070, 2428, -1151 },
+ { -6201, 2781, 2349, -1918 },
+ { -5918, 1139, 3121, -148 },
+ { -6314, 2481, 3137, -1808 },
+ { -7180, 1722, 2435, -1602 },
+ { -6750, 1829, 3763, -1145 },
+ { -6713, 1777, 2221, 1212 },
+ { -7479, 1835, 3627, -479 },
+ { -7299, 10, 2406, -1593 },
+ { -8249, 3129, 996, -2870 },
+ { -8374, 1534, 1333, -1882 },
+ { -7507, 3353, 1598, -2299 },
+ { -7379, 2701, 2326, -1167 },
+ { -8440, 2276, 2796, -542 },
+ { -10348, 1527, 2649, -1165 },
+ { -8184, 3614, 2574, -1738 },
+ { -5539, 1574, 1733, 1138 },
+ { 9404, -7652, 67, 79 },
+ { 8654, -3972, 1358, -60 },
+ { 8617, -4794, 117, 2318 },
+ { 7886, -4505, 1784, 1200 },
+ { 8636, -6125, 3879, -1003 },
+ { 9654, -6836, 1816, 205 },
+ { 9374, -6553, 913, 1875 },
+ { 8020, -6150, 1134, 2390 },
+ { 7786, -4970, 2078, -1857 },
+ { 8691, -6119, 711, 708 },
+ { 9039, -5568, 2944, -1902 },
+ { 9955, -5048, 1433, -601 },
+ { 8089, -6927, 3093, -2846 },
+ { 8487, -7024, 2415, 19 },
+ { 9388, -5287, 3577, -2655 },
+ { 8591, -7371, 2300, -996 },
+ { 9104, -4763, 1453, -2558 },
+ { 7615, -5457, 596, 164 },
+ { 9860, -7047, 3433, -614 },
+ { 8756, -4404, 2235, -964 },
+ { 9462, -4660, 299, -1822 },
+ { 10119, -5550, 2689, -1273 },
+ { 10915, -7471, 2705, -1007 },
+ { 11433, -7090, 1410, -1198 },
+ { 9882, -7431, 2965, -1895 },
+ { 7628, -5219, 769, -2661 },
+ { 8169, -5318, 2262, 70 },
+ { 8846, -6320, 1939, -754 },
+ { 7147, -5593, 1248, -971 },
+ { 10652, -5485, 935, 137 },
+ { 7778, -6533, 2564, -1932 },
+ { 8878, -5173, 1214, -361 },
+ { 9828, -4943, 282, 510 },
+ { 10042, -6134, 3895, -1914 },
+ { 7965, -6630, 3566, -433 },
+ { 8573, -4502, 3574, -1209 },
+ { 8398, -4801, 1031, -1347 },
+ { 10136, -7772, 2612, 1547 },
+ { 9890, -7280, 1768, -1083 },
+ { 8407, -6585, -706, -58 },
+ { 7976, -7582, 229, -131 },
+ { 10481, -8866, 1166, -147 },
+ { 10914, -4342, 3189, -2412 },
+ { 10440, -5198, -104, -1109 },
+ { 11227, -6530, 2381, -2449 },
+ { 8487, -8064, 1086, 230 },
+ { 9975, -6123, -857, -134 },
+ { 8339, -6498, 1232, -2337 },
+ { 11042, -4506, 1119, -2098 },
+ { 12563, -5592, 1837, -2062 },
+ { 11801, -5590, 632, -1296 },
+ { 10152, -5617, 1511, -1917 },
+ { 7800, -6473, 51, -1337 },
+ { 7941, -5560, 2438, -3270 },
+ { 6554, -3834, 2100, 1476 },
+ { 9065, -5520, -226, -1120 },
+ { 10794, -7120, -243, 122 },
+ { 10429, -6968, 272, -806 },
+ { 8942, -8914, 1442, -392 },
+ { 9969, -5051, 2033, -2953 },
+ { 7275, -4152, 3058, -64 },
+ { 11127, -5488, 4589, -3227 },
+ { 9626, -6666, 2739, -2958 },
+ { 6943, -5362, 4470, 1008 },
+ { -7456, -967, 2936, -1002 },
+ { -8622, -333, 6962, 2606 },
+ { -7486, -3392, 3668, 1287 },
+ { -8053, -827, 5148, 1097 },
+ { -6610, 454, 4952, 96 },
+ { -7701, -1982, 3161, -468 },
+ { -7307, -1132, 4071, -36 },
+ { -8125, -271, 5199, 3862 },
+ { -9182, -1950, 2813, 1878 },
+ { -9855, -952, 4794, 3010 },
+ { -7241, 1431, 4202, 2468 },
+ { -9646, 157, 4766, 1046 },
+ { -9371, 1230, 6009, 2958 },
+ { -11514, -64, 8630, 5248 },
+ { -6766, 565, 2766, 2140 },
+ { -8426, -9, 2852, 1271 },
+ { -11291, -1113, 5087, 2937 },
+ { -8297, 2092, 4495, 1264 },
+ { -9983, 735, 3809, -51 },
+ { -9048, -1000, 3191, -308 },
+ { -7331, -1987, 2655, 1391 },
+ { -7144, -21, 4333, 2161 },
+ { -6032, -1540, 3543, 896 },
+ { -7987, -1036, 1985, 1529 },
+ { -9264, 2004, 5194, 290 },
+ { -11308, -840, 5754, 1654 },
+ { -9130, -2398, 4292, 2973 },
+ { -6248, 838, 3563, 1223 },
+ { -6819, -2760, 3511, 119 },
+ { -7213, -2006, 4364, 762 },
+ { -5431, -1047, 4533, 166 },
+ { -7098, -641, 2021, 639 },
+ { -8628, -2249, 3588, 399 },
+ { -6352, -1498, 3560, -648 },
+ { -7033, -2190, 4870, 2562 },
+ { -7405, -46, 3772, -581 },
+ { -6104, 796, 5143, 1965 },
+ { -5787, 943, 5784, 3030 },
+ { -8367, 1465, 7192, 4097 },
+ { -8259, 789, 5694, 1963 },
+ { -10614, -1899, 5748, 2645 },
+ { -8258, -805, 3698, 2275 },
+ { -6877, -972, 6431, 3160 },
+ { -6483, 363, 7018, 3129 },
+ { -6283, -1358, 5191, 1524 },
+ { -8853, -3157, 4119, 1741 },
+ { -6086, -267, 3883, -835 },
+ { -7254, 1032, 6613, 4017 },
+ { -11470, -3350, 4649, 3426 },
+ { -6743, 481, 6148, 1239 },
+ { -5394, -166, 5309, 3165 },
+ { -7958, 1068, 4268, -240 },
+ { -10520, 2256, 7916, 2828 },
+ { -5132, -4, 5739, 1176 },
+ { -8643, 120, 3255, -629 },
+ { -9631, 1974, 8870, 4362 },
+ { -10663, -1221, 3733, 589 },
+ { -8224, -1843, 5806, 2655 },
+ { -8282, 1255, 8647, 3478 },
+ { -12311, -1505, 9043, 6256 },
+ { -11312, -856, 7136, 4681 },
+ { -11944, -722, 7941, 3309 },
+ { -7868, -463, 6846, 4196 },
+ { -8679, -241, 7410, 5347 },
+ { 6759, -4680, -508, 1220 },
+ { 5176, -6111, 944, 121 },
+ { 6843, -5667, -1368, -533 },
+ { 5616, -5884, -1471, -695 },
+ { 6030, -5089, -1808, -940 },
+ { 7444, -5463, -52, 1881 },
+ { 4207, -6079, -506, 1571 },
+ { 6785, -4410, -649, 3084 },
+ { 4838, -5214, 2026, 2998 },
+ { 4201, -5790, 645, 1811 },
+ { 6930, -5129, -1940, 1698 },
+ { 6332, -4627, 692, 3027 },
+ { 6285, -4314, -106, 3644 },
+ { 6255, -5450, -1975, 742 },
+ { 4199, -4676, -459, 1796 },
+ { 5592, -5500, 1345, 1300 },
+ { 4358, -5556, -2236, 114 },
+ { 4620, -5875, -1563, 888 },
+ { 4892, -7550, -327, -419 },
+ { 4734, -7085, 7, 613 },
+ { 3883, -5562, -1969, 1080 },
+ { 5610, -4990, -204, 834 },
+ { 4117, -6482, -1271, 341 },
+ { 6585, -5107, 892, 1169 },
+ { 6632, -3683, 302, 3002 },
+ { 6326, -5351, -983, -1250 },
+ { 4382, -7192, -730, -158 },
+ { 5227, -6540, -451, 1123 },
+ { 5468, -6472, -870, -1471 },
+ { 5191, -6402, -1365, -127 },
+ { 7407, -6317, -973, -336 },
+ { 4611, -6530, -820, -1980 },
+ { 4963, -5159, -2050, -966 },
+ { 4414, -5691, -211, -998 },
+ { 5954, -5873, 750, -1749 },
+ { 4394, -4796, -1268, 254 },
+ { 7161, -6214, -1010, 689 },
+ { 4965, -3598, 2372, 1711 },
+ { 6248, -6180, 981, 864 },
+ { 6473, -5336, 525, -600 },
+ { 4591, -6864, -1131, -900 },
+ { 6314, -6440, -1021, -375 },
+ { 5838, -6209, -1199, 944 },
+ { 5308, -5283, -2100, 1267 },
+ { 4342, -5860, -1637, -1356 },
+ { 5680, -4388, -1227, -104 },
+ { 4900, -4098, 1449, 4046 },
+ { 4677, -4284, -106, 3190 },
+ { 7574, -6173, -848, 1859 },
+ { 6493, -7207, -131, 726 },
+ { 5513, -5261, -2117, 4 },
+ { 6191, -7352, -193, -505 },
+ { 5885, -4333, 324, -134 },
+ { 6162, -6081, -312, -2044 },
+ { 4216, -6200, -1810, -572 },
+ { 5652, -7035, -696, -197 },
+ { 7131, -7189, -366, -60 },
+ { 5032, -4803, -1514, 2832 },
+ { 7386, -4610, -606, 3489 },
+ { 4211, -5031, 1221, 3047 },
+ { 4050, -4653, 1584, 1469 },
+ { 6852, -5302, -1861, 206 },
+ { 7736, -4816, -1794, 3359 },
+ { 6290, -3439, 1522, 2454 },
+ { 1768, 5990, -5560, -2594 },
+ { 3903, 5326, -1530, -1501 },
+ { 2472, 3738, -2117, -4240 },
+ { 3260, 5448, -904, -4733 },
+ { 1435, 7297, -3676, -4102 },
+ { 4096, 5951, -656, -3312 },
+ { 2178, 6009, -3146, -3724 },
+ { 3787, 5493, -5473, -1633 },
+ { 2998, 7286, -3334, -3571 },
+ { 2894, 6576, -4708, -2804 },
+ { 830, 6163, -4286, -3348 },
+ { 4755, 5569, -1730, -2739 },
+ { 4604, 6065, -3562, -2605 },
+ { 2749, 5141, -3986, -2775 },
+ { 3942, 4875, -2143, -3340 },
+ { 2819, 8517, -2004, -2724 },
+ { 2146, 6298, -689, -3093 },
+ { 5196, 6504, -3393, -1475 },
+ { 1851, 8386, -1748, -1420 },
+ { 3474, 8572, -3534, -2688 },
+ { 4503, 7560, -3561, -2245 },
+ { 4433, 6219, -2393, -1575 },
+ { 3506, 7248, -2275, -1977 },
+ { 3490, 7409, -3147, -604 },
+ { 4214, 6447, -3520, 516 },
+ { 619, 7034, -829, -1705 },
+ { 1732, 7395, -356, -2208 },
+ { 1226, 5204, -3294, -3732 },
+ { 2027, 5619, -1813, -4146 },
+ { 3078, 5877, 47, -2651 },
+ { 1654, 5458, 424, -682 },
+ { 3163, 5464, -2026, -270 },
+ { 2884, 5375, -685, -530 },
+ { 2950, 7286, -35, -2967 },
+ { 1986, 5066, -597, 482 },
+ { 3459, 4308, -3845, -2333 },
+ { 3155, 7037, -1346, -4345 },
+ { 2193, 6696, -717, -1319 },
+ { 3677, 5089, -3892, -487 },
+ { 2186, 5136, -4186, -1492 },
+ { 773, 5796, -917, 817 },
+ { 2489, 6546, -3570, -2117 },
+ { 1223, 6469, -1362, -33 },
+ { 271, 6061, -1466, -1725 },
+ { 2540, 5171, -1847, 1032 },
+ { 2548, 5251, -2697, 1677 },
+ { 771, 7600, -768, -632 },
+ { 4710, 6647, -4736, -1275 },
+ { 1369, 5917, -2971, -1056 },
+ { 163, 5239, -3499, -2275 },
+ { 2104, 4285, -3211, -3286 },
+ { 1107, 7411, -1972, -1671 },
+ { 2196, 7262, -2310, -1926 },
+ { -244, 6439, -1745, -839 },
+ { 3293, 3832, -2890, -3000 },
+ { 419, 6443, -379, -407 },
+ { 3077, 4930, -1156, -2869 },
+ { 2131, 5874, -2330, 224 },
+ { 690, 6538, -2212, -2841 },
+ { 1602, 4421, -2515, 1542 },
+ { 3318, 9373, -3032, -3477 },
+ { 5646, 7462, -5153, -1463 },
+ { 4139, 7137, -1539, -3321 },
+ { 3481, 9077, -1645, -3653 },
+ { -7747, 375, -106, -543 },
+ { -8587, -1379, -586, -461 },
+ { -10146, -892, 2094, 694 },
+ { -8103, 382, 504, -325 },
+ { -8548, -92, 94, -656 },
+ { -7460, 38, 152, 388 },
+ { -8266, -271, -459, -883 },
+ { -7935, -664, -1026, -802 },
+ { -8341, -109, 853, 161 },
+ { -8802, -1355, 1099, 630 },
+ { -8957, -6, 1108, -669 },
+ { -7260, -1520, -43, -407 },
+ { -7555, -174, 668, -2562 },
+ { -9014, -126, 227, -1191 },
+ { -8184, 769, 290, -1375 },
+ { -9476, 55, 962, -1528 },
+ { -8679, 541, 755, -1030 },
+ { -9842, -1626, 838, -1588 },
+ { -8513, -702, 788, -1998 },
+ { -10101, -1558, -366, -1841 },
+ { -8135, 78, 1479, -1813 },
+ { -9128, -454, 313, -1786 },
+ { -7554, -1084, 831, -2442 },
+ { -7576, -701, 2068, -1665 },
+ { -7791, -1481, 1587, -1808 },
+ { -6701, -596, -97, 802 },
+ { -7418, -15, 684, -963 },
+ { -7127, -477, -139, -426 },
+ { -8097, -110, -36, -264 },
+ { -7620, -1922, -590, -101 },
+ { -7647, -1201, 279, 660 },
+ { -7856, -1974, 758, -2271 },
+ { -8496, -167, 2232, -1143 },
+ { -8506, -1359, 624, -740 },
+ { -7274, -1052, 1062, -139 },
+ { -7800, -217, 91, -1794 },
+ { -7030, -1694, -955, 615 },
+ { -9020, -1864, 101, -2182 },
+ { -9400, -740, 598, -667 },
+ { -8448, -1184, 2024, -1272 },
+ { -8812, -570, -897, -2384 },
+ { -10559, -1286, 538, -1536 },
+ { -8728, -888, -1089, -1397 },
+ { -7080, -1185, 636, -1252 },
+ { -9880, 233, 2344, -782 },
+ { -7952, -1326, -378, -1947 },
+ { -7207, -378, 1408, -2237 },
+ { -8467, -1545, 902, -1987 },
+ { -9163, -1474, 924, -1739 },
+ { -8159, -992, -77, -2744 },
+ { -8343, 148, -423, -1573 },
+ { -9105, -649, -254, -1214 },
+ { -8939, 456, 281, -1905 },
+ { -8837, 179, -394, -2634 },
+ { -9145, 757, 1547, -1319 },
+ { -9775, -723, 441, -1680 },
+ { -8910, -686, 1529, -1525 },
+ { -9492, -1134, 2064, -938 },
+ { -6111, -943, 677, -31 },
+ { -7411, -613, -814, 46 },
+ { -9479, -922, -430, -2061 },
+ { -11298, -1268, 1318, -1117 },
+ { -8190, 832, 671, -2214 },
+ { -10453, -550, 1672, -886 },
+ { 1044, 9353, -1651, -5423 },
+ { 1034, 8149, -455, -6166 },
+ { 761, 8293, -3214, -4838 },
+ { 938, 8077, 164, -5130 },
+ { 1295, 8673, 2582, -5490 },
+ { -314, 7973, -2395, -5231 },
+ { -507, 9012, -2497, -5775 },
+ { 2396, 8314, -1022, -4673 },
+ { -1516, 8501, 1950, -4969 },
+ { -308, 7401, 1549, -4866 },
+ { -112, 8340, 3003, -4920 },
+ { -50, 9315, 1371, -5666 },
+ { -659, 9449, 2496, -5547 },
+ { 2573, 9148, -2270, -4783 },
+ { 830, 7104, -438, -3907 },
+ { 522, 10672, -677, -6483 },
+ { -1190, 10108, -510, -6518 },
+ { -427, 8271, -579, -6315 },
+ { 1602, 8113, -1927, -4418 },
+ { -2266, 8180, 448, -5190 },
+ { -1633, 8816, -226, -5771 },
+ { 759, 9481, -105, -5813 },
+ { 2254, 6679, -466, -5662 },
+ { -88, 6946, 895, -5958 },
+ { -1705, 10009, 1394, -5574 },
+ { 748, 7943, 540, -6692 },
+ { 1411, 7009, 232, -6145 },
+ { 697, 7290, -1221, -5342 },
+ { -1764, 10580, 1944, -3981 },
+ { -1334, 9124, 1195, -3903 },
+ { -905, 10067, 635, -5039 },
+ { 664, 10680, 49, -4625 },
+ { 1374, 9536, -777, -3591 },
+ { 252, 9698, -597, -2931 },
+ { 824, 9164, -1014, -2144 },
+ { 2438, 10569, -2289, -4424 },
+ { 2101, 7102, 507, -3614 },
+ { 294, 8051, -432, -1518 },
+ { -665, 10337, 547, -2852 },
+ { 1168, 11989, -492, -5427 },
+ { 1344, 6416, 302, -5061 },
+ { -1727, 12264, 1507, -4543 },
+ { 674, 10889, -902, -3605 },
+ { -582, 9504, 300, -3618 },
+ { 641, 7654, 689, -2109 },
+ { 2065, 9243, 508, -4367 },
+ { 1055, 8373, 688, -3144 },
+ { -641, 8185, 986, -3307 },
+ { 1120, 7426, 1785, -3757 },
+ { 1660, 8070, -593, -3104 },
+ { 2002, 9467, -1722, -3475 },
+ { 2361, 8368, 100, -3709 },
+ { -772, 7845, -613, -4988 },
+ { 1485, 7430, 1896, -6127 },
+ { -432, 7823, -947, -2882 },
+ { 313, 11122, -760, -4871 },
+ { 412, 8412, -283, -4231 },
+ { 1585, 10402, -1884, -3267 },
+ { 321, 6952, 773, -3016 },
+ { -105, 9014, 121, -2249 },
+ { 1585, 10313, -977, -4812 },
+ { 1619, 11869, 1306, -6876 },
+ { -1168, 8886, -81, -2500 },
+ { -395, 10886, 733, -6490 },
+ { -4949, 4274, 3992, -1054 },
+ { -4241, 5299, 4262, -1584 },
+ { -2710, 3862, 4552, -1673 },
+ { -4608, 2472, 3672, -1715 },
+ { -2843, 2816, 4003, -2326 },
+ { -5229, 2964, 5636, 90 },
+ { -4924, 3442, 5015, -1096 },
+ { -1281, 3313, 5537, -2066 },
+ { -3808, 1939, 4351, -919 },
+ { -1915, 2585, 4939, -1614 },
+ { -3470, 1843, 5562, -682 },
+ { -3800, 870, 5827, 144 },
+ { -4985, 1452, 4728, -709 },
+ { -3745, 2750, 7220, 259 },
+ { -1875, 1900, 6514, -826 },
+ { -4329, 1574, 7192, 1304 },
+ { -5408, 1444, 6208, 631 },
+ { -3327, 5312, 5707, -1541 },
+ { -6966, 3334, 4034, 1028 },
+ { -7484, 4245, 4218, -212 },
+ { -6567, 5839, 4539, -512 },
+ { -5715, 5935, 3747, -1186 },
+ { -6410, 4881, 3356, -1610 },
+ { -5146, 2590, 2850, 2172 },
+ { -5196, 4095, 2569, -373 },
+ { -5043, 6025, 4318, 692 },
+ { -5525, 4884, 3513, 370 },
+ { -6804, 7533, 5812, -488 },
+ { -5657, 2480, 4061, 1234 },
+ { -3155, 1472, 6071, 1188 },
+ { -3427, 5217, 3442, 858 },
+ { -4698, 3013, 5517, 2586 },
+ { -4449, 2226, 5418, 3580 },
+ { -6395, 3547, 5487, 2028 },
+ { -3500, 5019, 4787, 1 },
+ { -4038, 2578, 3073, 3151 },
+ { -2750, 1955, 4469, 3856 },
+ { -5696, 1659, 6118, 2469 },
+ { -4350, 1241, 6840, 3126 },
+ { -5565, 5058, 5196, 1314 },
+ { -1642, 4190, 3948, 607 },
+ { -1233, 4108, 4850, -640 },
+ { -997, 3428, 3239, 1378 },
+ { -6488, 2741, 6926, 2792 },
+ { -4188, 3763, 4235, 2018 },
+ { -3210, 3224, 5646, 1427 },
+ { -5526, 6909, 5070, -627 },
+ { -2815, 3994, 3425, 1903 },
+ { -2163, 2734, 5423, 145 },
+ { -4149, 4247, 2355, 734 },
+ { -410, 2521, 4138, -16 },
+ { -2411, 2385, 4927, 2105 },
+ { -6077, 3591, 3114, 594 },
+ { -4186, 4834, 5926, -1004 },
+ { -7315, 3369, 5966, 448 },
+ { -7042, 5721, 5771, 238 },
+ { -4466, 3907, 3535, -1751 },
+ { -2116, 3970, 6163, -1392 },
+ { -7239, 2143, 8407, 3630 },
+ { -5431, 4486, 6486, -42 },
+ { -1874, 1617, 6333, 519 },
+ { -6478, 2629, 4634, -505 },
+ { -7784, 2342, 7216, 1365 },
+ { -1154, 1432, 4831, 1544 },
+ { -4964, -5801, 1797, 506 },
+ { -4436, -6905, 1059, -1237 },
+ { -5400, -6886, 884, -290 },
+ { -6259, -7103, 523, -227 },
+ { -4819, -6450, 1412, -450 },
+ { -4056, -6213, 1725, -943 },
+ { -5642, -6091, 1357, 605 },
+ { -4196, -5678, 2187, -173 },
+ { -4726, -5126, 2470, 321 },
+ { -6642, -5091, 1507, -1005 },
+ { -5304, -5250, 1944, 1579 },
+ { -7179, -5520, 1468, -425 },
+ { -6033, -4895, 1876, -955 },
+ { -6595, -5143, 2207, 1291 },
+ { -4224, -4943, 1846, 1792 },
+ { -7128, -6950, 539, 724 },
+ { -4369, -4901, 2590, 1103 },
+ { -7413, -5696, 1712, 1440 },
+ { -5885, -6821, 418, 871 },
+ { -6828, -5599, 710, -1563 },
+ { -6123, -5817, 1358, 1631 },
+ { -5291, -5622, 578, 2138 },
+ { -7171, -6004, 347, 2208 },
+ { -6083, -5251, 2132, 425 },
+ { -4329, -5721, 407, -2993 },
+ { -5326, -5056, 1119, -1837 },
+ { -5485, -5856, 185, -2389 },
+ { -6529, -5178, 403, -697 },
+ { -6719, -4412, 2726, 871 },
+ { -5126, -5629, 1835, -771 },
+ { -5622, -4361, 2973, 858 },
+ { -5282, -5895, 45, -335 },
+ { -4357, -5656, 1696, -1558 },
+ { -7139, -6659, 627, -409 },
+ { -4415, -6328, 35, 1306 },
+ { -7639, -6110, 1134, 197 },
+ { -3626, -5592, 2019, 901 },
+ { -3547, -5064, 1176, 1738 },
+ { -5075, -3899, 2087, 266 },
+ { -4086, -6311, 1479, 360 },
+ { -6210, -5220, -199, -1477 },
+ { -3910, -5063, 1356, -15 },
+ { -7616, -4977, 461, 2401 },
+ { -6118, -6131, 1258, -563 },
+ { -6127, -4968, 1286, -27 },
+ { -4121, -5852, 1113, 1476 },
+ { -5157, -4881, 1162, -662 },
+ { -4637, -5031, 1179, 709 },
+ { -5509, -5452, -397, 1224 },
+ { -4597, -6861, 646, 467 },
+ { -6247, -4043, 468, 278 },
+ { -5336, -6465, 874, -1472 },
+ { -6998, -6346, 78, -1798 },
+ { -4915, -4530, 2756, -203 },
+ { -6048, -4373, 1468, 1052 },
+ { -4273, -7100, 942, -323 },
+ { -6552, -4287, 2351, 69 },
+ { -6954, -4613, 722, 1521 },
+ { -4201, -5361, 763, -1562 },
+ { -6881, -5596, -748, 669 },
+ { -6695, -3547, -34, 1299 },
+ { -3981, -5728, 84, 111 },
+ { -4663, -4809, 2173, -1031 },
+ { -6599, -6077, 1303, 256 },
+ { -7596, -4265, -5791, -4140 },
+ { -6610, -2758, -5288, -3936 },
+ { -5880, -3865, -6563, -3088 },
+ { -7228, -5510, -7677, -3912 },
+ { -8854, -6553, -8318, -5361 },
+ { -9362, -5249, -6413, -4319 },
+ { -4418, -3110, -6368, -4358 },
+ { -5544, -4203, -6863, -5013 },
+ { -3056, -4316, -5567, -3181 },
+ { -3078, -5999, -5051, -2657 },
+ { -5884, -6292, -5756, -4013 },
+ { -4825, -4549, -5535, -4053 },
+ { -4443, -6126, -5316, -1368 },
+ { -3972, -6341, -6098, -2686 },
+ { -5751, -2781, -5398, -6230 },
+ { -4466, -6135, -5570, -3679 },
+ { -4291, -5992, -3564, -5189 },
+ { -7189, -4429, -7279, -6082 },
+ { -5076, -4433, -2748, -5366 },
+ { -6225, -2825, -6833, -5663 },
+ { -2989, -4792, -3960, -4492 },
+ { -7836, -7773, -7722, -5741 },
+ { -6559, -5703, -5844, -5589 },
+ { -7612, -5438, -4136, -3774 },
+ { -4218, -4176, -6591, -2333 },
+ { -4837, -5063, -6581, 322 },
+ { -6590, -5990, -2980, -3847 },
+ { -5558, -2971, -5489, -1932 },
+ { -7001, -5323, -4975, -1697 },
+ { -4694, -2688, -6904, -3044 },
+ { -8511, -5379, -5767, -2549 },
+ { -7548, -5412, -6522, -2572 },
+ { -6597, -4973, -6423, -1274 },
+ { -6415, -4022, -5168, -1072 },
+ { -5528, -5530, -7218, -2345 },
+ { -4845, -4805, -5943, -1227 },
+ { -6049, -7150, -6744, -2161 },
+ { -9061, -7299, -8542, -4375 },
+ { -5010, -5546, -5416, -82 },
+ { -4135, -4205, -5109, -3373 },
+ { -3311, -5869, -4007, -5061 },
+ { -5993, -6472, -3962, -4718 },
+ { -2966, -5832, -2821, -6305 },
+ { -4851, -5152, -2067, -3930 },
+ { -3620, -4441, -3362, -5836 },
+ { -4469, -5221, -4534, -5592 },
+ { -4022, -6335, -4321, -6107 },
+ { -4899, -4503, -3084, -3725 },
+ { -4490, -8276, -4620, -6236 },
+ { -6591, -4342, -7365, -4063 },
+ { -6498, -5057, -5553, 485 },
+ { -6060, -2714, -7093, -4144 },
+ { -6199, -7774, -7094, -4057 },
+ { -7536, -6424, -6415, -4265 },
+ { -7439, -2454, -6348, -4827 },
+ { -5333, -7565, -4417, -4639 },
+ { -4353, -7103, -4197, -2689 },
+ { -5229, -6549, -5129, -6804 },
+ { -6129, -7701, -5236, -4836 },
+ { -6797, -3983, -3884, -4406 },
+ { -6624, -4467, -4745, -5052 },
+ { -3324, -7596, -2720, -6553 },
+ { -5473, -6284, -1704, -4511 },
+ { -4131, -7263, -3180, -5196 },
+ { -7116, -5565, -3469, 685 },
+ { -6002, -6021, -3858, 576 },
+ { -3144, -8203, -1291, -434 },
+ { -6096, -7027, -4004, 1353 },
+ { -3943, -7709, -2344, -36 },
+ { -4510, -6767, -2642, 631 },
+ { -3657, -11541, -2570, -3984 },
+ { -5959, -8854, -1333, -867 },
+ { -6699, -8866, -1606, -344 },
+ { -3836, -7961, -2334, -2028 },
+ { -3430, -8045, -3037, -672 },
+ { -3868, -9184, -3635, -1819 },
+ { -4258, -9060, -2621, -1008 },
+ { -3595, -8693, -2022, -752 },
+ { -4573, -8048, -3166, -2622 },
+ { -4852, -7903, -1405, 256 },
+ { -4591, -7057, -1560, 965 },
+ { -6963, -7655, -980, 808 },
+ { -5179, -6641, -3356, 1196 },
+ { -7102, -6941, -2798, 2123 },
+ { -6867, -5834, -3320, -770 },
+ { -5977, -7369, -2500, -778 },
+ { -6160, -6400, -934, -2543 },
+ { -6741, -7608, -355, -1289 },
+ { -6856, -6466, -1433, -1643 },
+ { -4786, -6292, -4970, 376 },
+ { -5407, -8866, -2255, -400 },
+ { -3814, -6506, -1387, -3620 },
+ { -4998, -6137, -1200, -4092 },
+ { -5123, -9557, -2849, -1306 },
+ { -4259, -6444, -4395, -338 },
+ { -5221, -6810, -883, 1225 },
+ { -6137, -6215, -2165, 554 },
+ { -3895, -6557, -3176, -1829 },
+ { -3886, -8188, -87, -954 },
+ { -7243, -6707, -2216, -316 },
+ { -5592, -7606, 85, -432 },
+ { -3957, -7945, -504, -144 },
+ { -4617, -7624, 218, -312 },
+ { -4797, -8737, -844, -1051 },
+ { -4478, -8516, -1401, -454 },
+ { -4557, -7058, -302, -2332 },
+ { -6623, -7736, -271, -50 },
+ { -3157, -7532, -1111, -2207 },
+ { -3590, -7300, -1271, 517 },
+ { -4442, -7306, -507, 590 },
+ { -6458, -7524, -2807, 666 },
+ { -4991, -8466, -3363, -785 },
+ { -7474, -7541, -1056, -1839 },
+ { -7501, -8316, -938, -180 },
+ { -5329, -7739, -579, -2341 },
+ { -4549, -7063, -176, -3539 },
+ { -5191, -8612, -1504, -4250 },
+ { -3083, -7058, -2251, 32 },
+ { -4003, -7043, -1093, -791 },
+ { -5523, -8093, -678, -114 },
+ { -3022, -10265, -2070, -3109 },
+ { -3905, -6274, -182, -3652 },
+ { -3269, -9217, -551, -2650 },
+ { -3138, -9314, -1726, -1704 },
+ { -4420, -10339, -1744, -3459 },
+ { -4163, -8609, -2298, -4113 },
+ { -5566, -6505, -1241, -463 },
+ { -3130, -9746, -2352, -4884 },
+ { -7825, -3439, 1451, -1468 },
+ { -8451, -3318, 2360, -435 },
+ { -8462, -4130, 1438, -1024 },
+ { -9425, -4564, 1328, -689 },
+ { -11014, -3202, 2278, 2080 },
+ { -8269, -2761, -146, -440 },
+ { -7497, -2618, -166, 413 },
+ { -8250, -3060, 522, -2133 },
+ { -8365, -5366, 1347, -451 },
+ { -8589, -3979, 2943, 714 },
+ { -8111, -2572, 1272, -1748 },
+ { -7830, -5193, 605, -1484 },
+ { -8119, -4736, 2141, 256 },
+ { -7724, -4769, 1463, -812 },
+ { -7363, -3911, 2540, 4 },
+ { -7974, -3397, 2363, 1366 },
+ { -7359, -4204, 1752, -958 },
+ { -7622, -3505, 660, 916 },
+ { -9934, -3665, 3165, 828 },
+ { -8721, -4162, 62, 1718 },
+ { -9433, -4768, 2722, 1234 },
+ { -7960, -4496, 138, 1528 },
+ { -8198, -3454, -443, 631 },
+ { -7756, -2246, 655, 1137 },
+ { -8841, -3145, 1113, 829 },
+ { -7817, -3298, 1251, 230 },
+ { -9413, -2733, 323, -1862 },
+ { -9408, -4168, 1270, 1549 },
+ { -9037, -3892, -942, 283 },
+ { -8255, -3849, 1301, 1762 },
+ { -9057, -3987, -41, -682 },
+ { -9441, -4187, 2019, -111 },
+ { -9740, -3178, 1602, -871 },
+ { -8344, -2474, 1461, 1506 },
+ { -9752, -2925, 1996, 1243 },
+ { -9199, -3796, 180, 537 },
+ { -9060, -2405, 1140, -1562 },
+ { -9348, -2376, 309, -162 },
+ { -10786, -3182, -5, -1500 },
+ { -8142, -4540, -434, -826 },
+ { -7528, -2341, 1104, -73 },
+ { -9360, -2658, 3062, 56 },
+ { -8267, -2335, 2000, -1193 },
+ { -12169, -3154, 1287, -640 },
+ { -11398, -2120, 946, -1163 },
+ { -8940, -4559, 328, -1696 },
+ { -11025, -4213, 2813, 840 },
+ { -9224, -3581, 2224, 2039 },
+ { -8943, -3337, 1248, -1298 },
+ { -7900, -4042, 485, -2080 },
+ { -9221, -1947, 2191, -880 },
+ { -10762, -1800, 2516, -324 },
+ { -10095, -2238, 981, -1335 },
+ { -11908, -2808, 3255, 645 },
+ { -10640, -4105, 1283, -595 },
+ { -7663, -2863, 2467, -797 },
+ { -10712, -3854, 3710, 1538 },
+ { -10823, -2893, 1408, -801 },
+ { -9874, -3832, 256, -1638 },
+ { -10394, -3391, 2315, -94 },
+ { -11525, -4079, 4153, 2122 },
+ { -9546, -2088, 1541, 481 },
+ { -8731, -2433, 1042, 2160 },
+ { -7852, -3977, -1370, 1677 },
+ { 7072, -3420, 1398, -1741 },
+ { 6180, -1976, 1280, -3557 },
+ { 7692, -1793, 2844, -1700 },
+ { 8363, -1773, 3104, -2679 },
+ { 9213, -3266, 3756, -3542 },
+ { 9650, -2644, 1426, -1318 },
+ { 7712, -2796, 3686, -1975 },
+ { 7316, -3517, 2821, -622 },
+ { 7434, -2594, 2305, -2264 },
+ { 7237, -1797, 255, -3114 },
+ { 8663, -1983, 1338, -3056 },
+ { 6616, -952, 4059, -2652 },
+ { 8823, -1327, 1362, -1356 },
+ { 9938, -1722, 1287, -2362 },
+ { 7207, -1057, 1913, -1315 },
+ { 7508, -1585, 870, -1982 },
+ { 8217, -3680, 1417, -3170 },
+ { 8329, -2541, 1684, -585 },
+ { 8062, -2335, 252, -2800 },
+ { 8204, -4108, 3097, -2569 },
+ { 7701, -3367, 576, -3008 },
+ { 7350, -786, 2414, -2129 },
+ { 6948, -2568, 1607, -225 },
+ { 7684, -2387, 1308, -3449 },
+ { 8306, -3458, 2394, -1454 },
+ { 8438, -2781, 1043, -1362 },
+ { 9175, -2076, 2144, -1987 },
+ { 8347, -2709, 3489, -4301 },
+ { 5696, -2377, 2870, 851 },
+ { 8825, -1243, 2219, -2603 },
+ { 8801, -1614, 584, -2513 },
+ { 8413, -384, 1421, -2244 },
+ { 9228, -3050, 3279, -2164 },
+ { 6342, -2698, 3547, -107 },
+ { 10053, -2476, 2837, -3168 },
+ { 7439, -604, 3177, -3991 },
+ { 7749, -1064, 4329, -4855 },
+ { 8655, -2177, 2252, -3519 },
+ { 8490, -228, 1958, -3233 },
+ { 10513, -2968, 1911, -2340 },
+ { 8146, -862, 1884, -1723 },
+ { 7788, -666, 3004, -2891 },
+ { 7785, -1620, 4133, -3417 },
+ { 10262, -3731, 3455, -2971 },
+ { 8570, -905, 4519, -4649 },
+ { 9129, -2562, 463, -2465 },
+ { 9451, -3587, 1904, -3056 },
+ { 6549, -2236, 3010, -4523 },
+ { 7175, -2684, 2967, -3458 },
+ { 9872, -3278, 1054, -2472 },
+ { 9153, -931, 1217, -2565 },
+ { 8789, -3469, 753, -2568 },
+ { 6683, -3791, 1797, -3968 },
+ { 6801, -1977, 2311, -452 },
+ { 6336, -1572, 2612, -3264 },
+ { 7996, -1008, 730, -2964 },
+ { 7521, -1059, 1573, -3694 },
+ { 8148, -3973, 2600, -3572 },
+ { 7765, -1532, 2528, -3856 },
+ { 7404, -3918, 4472, -143 },
+ { 8894, -1398, 3299, -3685 },
+ { 5768, -2041, 1487, -637 },
+ { 5131, -2865, 2463, -811 },
+ { 6439, -1568, 3500, -1550 },
+ { -8878, -6798, -5319, -1452 },
+ { -6332, -9713, -3112, -990 },
+ { -8444, -6316, -3694, -687 },
+ { -6123, -10840, -3637, -4358 },
+ { -4784, -9580, -4577, -2581 },
+ { -6108, -10515, -4859, -2524 },
+ { -7605, -7518, -2327, -2797 },
+ { -9662, -8775, -2467, -2010 },
+ { -6494, -7523, -4715, -118 },
+ { -8290, -8982, -1672, -317 },
+ { -8798, -11051, -3888, -1426 },
+ { -6273, -6623, -6791, -142 },
+ { -8313, -7668, -2141, -1275 },
+ { -6453, -8412, -3589, -4102 },
+ { -6747, -7750, -5690, -2498 },
+ { -7814, -6693, -3174, -2446 },
+ { -10383, -10130, -3931, -2364 },
+ { -10606, -8467, -5539, -2772 },
+ { -9475, -6671, -3305, -2271 },
+ { -8982, -9457, -5635, -4005 },
+ { -10111, -7965, -6515, -4180 },
+ { -7301, -6479, -5364, 720 },
+ { -9543, -8999, -7921, -912 },
+ { -9534, -8562, -3469, -384 },
+ { -7601, -10344, -3205, -1127 },
+ { -8088, -8620, -4954, -2888 },
+ { -8202, -8406, -7038, -3775 },
+ { -7312, -8324, -3334, -1775 },
+ { -8566, -9262, -8071, -4174 },
+ { -7068, -11300, -5573, -2907 },
+ { -8295, -8952, -4366, -1544 },
+ { -11104, -10210, -2285, -384 },
+ { -5213, -7520, -5008, -1339 },
+ { -5889, -7940, -5987, -1385 },
+ { -10816, -8201, -4153, -1485 },
+ { -10277, -8919, -6315, -1652 },
+ { -5888, -10320, -3821, -1733 },
+ { -10497, -7181, -6083, -3032 },
+ { -7721, -9724, -6591, -5336 },
+ { -5688, -7894, -3486, -2552 },
+ { -10014, -10500, -3247, -820 },
+ { -6301, -8765, -4506, -2923 },
+ { -8261, -7847, -6213, -1552 },
+ { -10212, -7481, -8113, -3954 },
+ { -6938, -10874, -6074, -4703 },
+ { -7183, -10968, -4446, -1773 },
+ { -7120, -9193, -1966, -2509 },
+ { -6234, -9263, -2313, -4284 },
+ { -8503, -9857, -2429, -608 },
+ { -9372, -7844, -8391, -2120 },
+ { -7951, -7157, -6535, -11 },
+ { -7256, -9473, -2172, -660 },
+ { -10063, -9612, -2515, -15 },
+ { -6684, -9134, -6109, -4206 },
+ { -8204, -11932, -5220, -2306 },
+ { -9710, -6706, -4115, -3275 },
+ { -6855, -7078, -2409, -4447 },
+ { -7344, -7673, -4479, -4116 },
+ { -8851, -6842, -4927, -2948 },
+ { -8927, -10452, -5633, -2194 },
+ { -8627, -9002, -7176, -1575 },
+ { -8209, -9722, -7021, -3324 },
+ { -3770, -10249, -3623, -4816 },
+ { -8183, -7465, -4090, 646 },
+ { -8163, -7149, 200, 498 },
+ { -8289, -6266, 686, -206 },
+ { -10030, -6241, -1032, -1864 },
+ { -8793, -8327, -773, -169 },
+ { -9149, -6215, 969, -15 },
+ { -8303, -5859, -7, 2006 },
+ { -9682, -7283, 255, 1322 },
+ { -9293, -7227, 71, -231 },
+ { -8525, -6215, 287, -837 },
+ { -10477, -5379, 1159, 1449 },
+ { -10726, -7856, -130, 102 },
+ { -8694, -7461, -1210, 690 },
+ { -9367, -5324, 1103, 3170 },
+ { -10686, -8055, -831, 1633 },
+ { -9201, -6873, -2704, 2258 },
+ { -8421, -5358, -1405, 226 },
+ { -9066, -5830, -307, -1571 },
+ { -11150, -7381, -2746, -900 },
+ { -9978, -5925, -2006, -437 },
+ { -9464, -4741, -273, 1061 },
+ { -10543, -6684, -1113, 1660 },
+ { -10073, -5576, 1083, -269 },
+ { -8826, -5763, 1600, 1486 },
+ { -10445, -9071, -1253, -64 },
+ { -12085, -5799, 2, 769 },
+ { -12939, -6663, 1650, 1437 },
+ { -10932, -6434, -1252, -649 },
+ { -11650, -7826, -2053, 710 },
+ { -12122, -6733, -1889, -731 },
+ { -9093, -6095, -2463, -842 },
+ { -10977, -4364, 469, 420 },
+ { -11488, -6908, -521, 893 },
+ { -9669, -5478, -842, 337 },
+ { -10606, -5203, -632, -1361 },
+ { -10198, -6284, 1662, 1277 },
+ { -10135, -5292, 2435, 3493 },
+ { -11027, -6561, 655, 56 },
+ { -10977, -5030, 1127, -358 },
+ { -12766, -3986, 1348, -335 },
+ { -14244, -7731, 264, 317 },
+ { -15124, -10309, -508, 1447 },
+ { -12821, -8638, -608, 137 },
+ { -13076, -8693, -2852, -431 },
+ { -11156, -5546, -2252, -1600 },
+ { -8692, -7366, -819, -1223 },
+ { -12507, -9816, -1714, -121 },
+ { -10712, -6666, 544, 3349 },
+ { -12462, -5890, -2491, -2318 },
+ { -12468, -7226, 437, 232 },
+ { -11300, -5226, 2068, 687 },
+ { -11994, -8320, -626, 2728 },
+ { -12222, -5476, 1142, 18 },
+ { -10277, -8122, -2418, 2003 },
+ { -13418, -6115, -3563, -2802 },
+ { -14759, -9834, -1243, 21 },
+ { -13699, -5665, 1525, 507 },
+ { -16269, -9476, -701, 163 },
+ { -12677, -5437, -247, -1019 },
+ { -11827, -4295, -181, -1243 },
+ { -12847, -4496, 2984, 1123 },
+ { -13860, -7915, -1166, -547 },
+ { -12276, -8145, -2290, -1527 },
+ { -11417, -4830, 2983, 1854 },
+ { -11793, -6002, 1163, 1940 },
+ { 11443, -4920, -3235, 3151 },
+ { 11300, -6616, -1506, 1175 },
+ { 9198, -4628, -2060, 2390 },
+ { 10532, -4027, -643, 912 },
+ { 9902, -3573, -1606, 1327 },
+ { 9653, -3536, -2240, 1869 },
+ { 9948, -5171, -423, 2662 },
+ { 12316, -4004, -1989, 281 },
+ { 12125, -4800, -1265, -163 },
+ { 10650, -2617, -2337, 1462 },
+ { 9909, -4968, -2376, 916 },
+ { 12944, -4647, -1958, 460 },
+ { 12988, -5283, -1141, 41 },
+ { 12321, -2915, -3621, 1025 },
+ { 11449, -2894, -2728, 351 },
+ { 12087, -3041, -2002, -32 },
+ { 11558, -4031, -1343, -399 },
+ { 12983, -3740, -3516, 1245 },
+ { 12099, -2515, -2752, 225 },
+ { 12515, -3465, -2701, 550 },
+ { 14683, -5022, -5272, 2996 },
+ { 12260, -3383, -1215, -528 },
+ { 13810, -5422, -2443, 1166 },
+ { 13421, -5378, -1886, 721 },
+ { 12961, -4259, -2594, 796 },
+ { 12266, -2104, -4768, 1591 },
+ { 13523, -4710, -3045, 1342 },
+ { 12437, -2099, -5610, 2117 },
+ { 11850, -2183, -3497, 661 },
+ { 12275, -3936, -597, -697 },
+ { 12459, -5253, -517, -544 },
+ { 12835, -4094, -1322, -168 },
+ { 14360, -5677, -3305, 1859 },
+ { 13905, -4552, -4309, 2117 },
+ { 11559, -3412, -1847, -81 },
+ { 13379, -3167, -5764, 2746 },
+ { 11910, -1634, -4342, 1052 },
+ { 12662, -4742, 71, -974 },
+ { 13057, -3254, -4424, 1705 },
+ { 15046, -5706, -4851, 3019 },
+ { 14162, -4142, -5514, 2843 },
+ { 12764, -1845, -6684, 2888 },
+ { 13714, -2374, -7838, 3857 },
+ { 13295, -1663, -8293, 4073 },
+ { 10032, -4152, -3403, 1421 },
+ { 10942, -5386, -2222, 950 },
+ { 10532, -6385, -1750, 1925 },
+ { 10273, -5972, -1534, 643 },
+ { 10605, -4782, -1695, 27 },
+ { 10988, -5153, -1123, -341 },
+ { 11629, -5884, -1060, 48 },
+ { 10441, -4045, -2431, 311 },
+ { 10788, -3595, -4171, 1807 },
+ { 12110, -5686, -2127, 976 },
+ { 11746, -4773, -2639, 891 },
+ { 11541, -5299, -3031, 1732 },
+ { 11416, -2559, -5359, 2198 },
+ { 11583, -5376, -704, 677 },
+ { 10416, -3214, -3516, 872 },
+ { 9651, -5435, -1618, 3255 },
+ { 9973, -5133, -996, 3923 },
+ { 11707, -4643, -430, -796 },
+ { 10994, -2709, -3587, 2302 },
+ { 10716, -5118, -645, 270 },
+ { 14100, -10314, 1095, 1531 },
+ { 12944, -8049, 1105, -741 },
+ { 13276, -7035, -511, 274 },
+ { 14008, -7254, -283, 139 },
+ { 11594, -6536, -91, 1671 },
+ { 11732, -8645, 746, 15 },
+ { 14613, -7085, -1578, 1183 },
+ { 13083, -6224, -750, -4 },
+ { 13988, -6256, -1592, 820 },
+ { 14678, -8683, 441, 126 },
+ { 15571, -8872, -521, 1139 },
+ { 15642, -9533, 341, 697 },
+ { 15960, -9586, -168, 1121 },
+ { 15464, -10239, 1433, -1 },
+ { 14934, -7887, -1046, 1080 },
+ { 15252, -7630, -1899, 1628 },
+ { 15485, -8384, -1234, 1484 },
+ { 15962, -8638, -1815, 1931 },
+ { 16501, -10664, 398, 1167 },
+ { 16146, -10145, 411, 918 },
+ { 14573, -7475, -697, 601 },
+ { 14302, -7996, 28, 257 },
+ { 14769, -6792, -2286, 1574 },
+ { 14144, -6137, -2169, 1257 },
+ { 14770, -6271, -3111, 1933 },
+ { 14110, -8312, 1083, -531 },
+ { 15235, -6991, -2993, 2174 },
+ { 13222, -5805, 547, -891 },
+ { 14796, -8762, 1254, -246 },
+ { 16040, -9181, -1005, 1551 },
+ { 16487, -10086, -373, 1420 },
+ { 15077, -9479, 966, 51 },
+ { 13026, -6468, 932, -1080 },
+ { 12703, -6152, -33, -573 },
+ { 15641, -6810, -4128, 2874 },
+ { 13282, -7673, 1583, -1283 },
+ { 12373, -7150, 1512, -917 },
+ { 12992, -7751, -678, 783 },
+ { 10907, -6858, -313, 2597 },
+ { 13026, -8963, 125, 2152 },
+ { 12770, -9946, 1957, -505 },
+ { 12482, -6849, -1268, 833 },
+ { 13790, -6181, -138, -279 },
+ { 12709, -8382, 2044, 227 },
+ { 12244, -6630, 203, -457 },
+ { 14209, -6816, -1032, 632 },
+ { 15134, -8267, -288, 640 },
+ { 13619, -6157, -1090, 356 },
+ { 14044, -7413, 725, -484 },
+ { 12958, -7753, 2585, -1980 },
+ { 13188, -8396, 2306, -1558 },
+ { 14379, -9980, 2132, -688 },
+ { 14275, -9857, 1162, 179 },
+ { 13690, -8648, 1621, -889 },
+ { 11770, -6829, -746, 278 },
+ { 12732, -8202, 286, 90 },
+ { 13630, -10146, 1867, -207 },
+ { 12072, -8740, 1299, -645 },
+ { 12852, -9492, 1226, 62 },
+ { 11792, -7382, -54, -116 },
+ { 13779, -9014, 487, 351 },
+ { 11951, -7729, 121, 834 },
+ { 11970, -9781, 2276, -4 },
+ { 12680, -7984, 2787, -787 },
+ { 13300, -14488, 6408, -1927 },
+ { 13635, -15355, 9153, -3073 },
+ { 12804, -13566, 5517, -1625 },
+ { 16624, -10854, 1690, 28 },
+ { 20387, -18532, 6162, -261 },
+ { 16515, -12642, 3392, -519 },
+ { 15800, -11095, 2151, -202 },
+ { 16824, -11790, 1651, 599 },
+ { 17604, -13213, 2563, 538 },
+ { 17892, -14177, 3562, 147 },
+ { 16987, -11399, 869, 1052 },
+ { 17003, -12456, 2442, 265 },
+ { 21657, -21806, 9198, -1250 },
+ { 16825, -13341, 3980, -686 },
+ { 17525, -12714, 1887, 805 },
+ { 16419, -11034, 1216, 617 },
+ { 20931, -19939, 7469, -684 },
+ { 18452, -15390, 4573, -191 },
+ { 14778, -10077, 2841, -1209 },
+ { 17402, -13319, 3042, 160 },
+ { 19365, -17922, 7087, -1061 },
+ { 16298, -11941, 2810, -351 },
+ { 19087, -16176, 4775, -84 },
+ { 17666, -12289, 938, 1224 },
+ { 18581, -15894, 5132, -430 },
+ { 19823, -16717, 4142, 545 },
+ { 19960, -19423, 8400, -1492 },
+ { 18973, -16817, 5906, -594 },
+ { 19079, -15431, 3528, 503 },
+ { 16667, -12485, 4467, -1302 },
+ { 19791, -17797, 6196, -529 },
+ { 20005, -17606, 5354, -20 },
+ { 20123, -18599, 6886, -728 },
+ { 19068, -14805, 2394, 1105 },
+ { 14443, -13723, 5631, -2029 },
+ { 14730, -14231, 5631, -1450 },
+ { 16089, -15959, 7271, -2029 },
+ { 13473, -11200, 3236, -924 },
+ { 14413, -10902, 2347, -267 },
+ { 17666, -18662, 11381, -3496 },
+ { 14749, -11042, 3305, -275 },
+ { 15304, -10486, 1869, -240 },
+ { 14809, -12126, 3369, -616 },
+ { 16896, -16561, 7307, -1845 },
+ { 15782, -14336, 5380, -1264 },
+ { 16395, -15520, 6415, -1588 },
+ { 13681, -11114, 2584, -320 },
+ { 14244, -12326, 4480, -1632 },
+ { 15247, -13119, 4265, -898 },
+ { 13987, -12091, 3469, -597 },
+ { 13941, -12770, 4240, -839 },
+ { 13771, -13627, 5252, -1384 },
+ { 15010, -16074, 7592, -2249 },
+ { 15852, -17226, 8619, -2655 },
+ { 18921, -16916, 6875, -1501 },
+ { 14909, -11678, 2768, -295 },
+ { 18988, -18353, 8424, -2070 },
+ { 15457, -15080, 6218, -1513 },
+ { 14916, -15512, 6949, -1883 },
+ { 18108, -14702, 4681, -701 },
+ { 17600, -15733, 5616, -775 },
+ { 14070, -13683, 6472, -2626 },
+ { 13832, -11914, 5201, -2232 },
+ { 18846, -19009, 9192, -1961 },
+ { -11981, -10994, -6324, -2264 },
+ { -10976, -9047, -6546, -3828 },
+ { -11288, -10532, -7014, -4191 },
+ { -10139, -10189, -7799, -2688 },
+ { -10555, -9988, -9181, -2040 },
+ { -11596, -11339, -10022, -2707 },
+ { -13400, -13395, -11306, -4206 },
+ { -9774, -12281, -7466, -4133 },
+ { -10842, -13125, -8777, -4956 },
+ { -11964, -15082, -9779, -5095 },
+ { -9382, -10188, -9053, -4927 },
+ { -11562, -11296, -3651, -985 },
+ { -9287, -10083, -7918, -4069 },
+ { -12821, -16556, -11410, -6195 },
+ { -12628, -8959, -4521, -1113 },
+ { -13845, -11581, -3649, -681 },
+ { -12685, -10269, -5483, -1275 },
+ { -14988, -12874, -5107, -1189 },
+ { -13761, -11367, -6202, -1804 },
+ { -13225, -11249, -7820, -3354 },
+ { -14809, -11992, -3202, -312 },
+ { -15620, -15519, -10210, -3433 },
+ { -12954, -10200, -3139, -611 },
+ { -11536, -9981, -5284, -923 },
+ { -13034, -12417, -4612, -1098 },
+ { -16911, -15505, -6123, -1352 },
+ { -17396, -17685, -8330, -2171 },
+ { -14120, -10764, -2265, -99 },
+ { -12598, -7367, -5406, -3530 },
+ { -14143, -12793, -10909, -5226 },
+ { -14692, -16871, -11626, -5554 },
+ { -12581, -11197, -9194, -3837 },
+ { -16752, -16726, -9746, -2808 },
+ { -10600, -10358, -6560, -1227 },
+ { -14573, -13312, -8957, -3393 },
+ { -10172, -8463, -8579, -3387 },
+ { -11418, -12421, -5522, -1842 },
+ { -11855, -14204, -6669, -2625 },
+ { -13308, -8191, -3941, -2194 },
+ { -10007, -12266, -5022, -1811 },
+ { -13532, -15771, -9497, -3175 },
+ { -11760, -11148, -10339, -5529 },
+ { -12149, -12763, -11198, -3697 },
+ { -12029, -12119, -8555, -1792 },
+ { -16995, -19957, -11447, -3471 },
+ { -13144, -14504, -9988, -3191 },
+ { -9938, -11064, -6139, -3162 },
+ { -8873, -11550, -8294, -6550 },
+ { -9303, -13010, -6150, -2711 },
+ { -15463, -10469, -1766, -170 },
+ { -15985, -11693, -3007, -650 },
+ { -17142, -10671, -1434, 47 },
+ { -16063, -13858, -4817, -1058 },
+ { -19446, -19599, -9594, -2464 },
+ { -20076, -18744, -8313, -1889 },
+ { -15047, -16085, -7590, -2250 },
+ { -13481, -16195, -8552, -2998 },
+ { -13829, -14869, -6704, -1932 },
+ { -16357, -18484, -9802, -2959 },
+ { -10551, -8393, -9303, -5070 },
+ { -11345, -9156, -5641, -3107 },
+ { -13217, -13449, -9270, -4541 },
+ { -11988, -13732, -9995, -6374 },
+ { -11007, -9519, -5168, -4107 },
+ { 9930, -7858, 8061, -4375 },
+ { 8274, -7867, 5992, -2096 },
+ { 9692, -9675, 7621, -3670 },
+ { 9589, -8110, 6509, -3010 },
+ { 12617, -11976, 10122, -5360 },
+ { 11867, -8895, 7948, -5323 },
+ { 10388, -10482, 9234, -4324 },
+ { 8188, -8220, 7810, -2737 },
+ { 10407, -8787, 4806, -1930 },
+ { 10348, -8845, 9233, -6614 },
+ { 9422, -7091, 4820, -2878 },
+ { 9758, -9796, 5584, -2256 },
+ { 10188, -7994, 5347, -3343 },
+ { 11133, -7455, 4015, -2306 },
+ { 10676, -10744, 6093, -2629 },
+ { 11522, -12184, 7848, -3375 },
+ { 8805, -9883, 5317, -3071 },
+ { 9498, -9654, 6555, -3592 },
+ { 10488, -8008, 4066, -1252 },
+ { 11261, -8930, 6068, -2738 },
+ { 12180, -10397, 5027, -1531 },
+ { 9138, -8531, 3601, -1959 },
+ { 8107, -8380, 4970, -2061 },
+ { 9737, -13248, 6438, -2617 },
+ { 11178, -10423, 2622, -522 },
+ { 9572, -12372, 5199, -2019 },
+ { 12057, -12144, 4147, -1099 },
+ { 9047, -9925, 2516, -665 },
+ { 10790, -8030, 5882, -4386 },
+ { 7199, -8426, 6337, -2841 },
+ { 7778, -8285, 3529, -3442 },
+ { 7559, -10569, 3484, -1332 },
+ { 9404, -8115, 7484, -5541 },
+ { 7792, -11976, 5546, -2573 },
+ { 9313, -10264, 7661, -5195 },
+ { 6701, -10725, 4370, -1784 },
+ { 4918, -11361, 4507, -4527 },
+ { 5147, -12305, 3978, -5556 },
+ { 6525, -9899, 4481, -3129 },
+ { 7538, -12855, 6060, -4826 },
+ { 8659, -12111, 7159, -4430 },
+ { 8440, -11304, 4547, -1747 },
+ { 9216, -10918, 3507, -1195 },
+ { 6165, -9254, 4771, -4677 },
+ { 9163, -11019, 5637, -4935 },
+ { 13441, -11509, 6676, -2434 },
+ { 7912, -9398, 6663, -4048 },
+ { 11723, -13745, 8131, -4148 },
+ { 6065, -10257, 5005, -6327 },
+ { 11618, -12417, 5336, -1894 },
+ { 8891, -13924, 8407, -6131 },
+ { 9622, -12563, 7908, -5109 },
+ { 11479, -10315, 8349, -3991 },
+ { 11676, -14103, 6611, -2330 },
+ { 11951, -8953, 3829, -1550 },
+ { 10486, -8044, 10493, -5920 },
+ { 11801, -10769, 9763, -5305 },
+ { 6109, -8676, 5827, -1346 },
+ { 7030, -9611, 5624, -5761 },
+ { 12808, -12886, 8683, -4148 },
+ { 13213, -10464, 6381, -3189 },
+ { 11796, -13681, 10703, -6075 },
+ { 9639, -7949, 9625, -3944 },
+ { 8538, -6997, 5309, 453 }
+};
+
+/* quantization tables */
+
+static const uint32_t scale_factor_quant6[64] = {
+ 1, 2, 2, 3, 3, 4, 6, 7,
+ 10, 12, 16, 20, 26, 34, 44, 56,
+ 72, 93, 120, 155, 200, 257, 331, 427,
+ 550, 708, 912, 1175, 1514, 1950, 2512, 3236,
+ 4169, 5370, 6918, 8913, 11482, 14791, 19055, 24547,
+ 31623, 40738, 52481, 67608, 87096, 112202, 144544, 186209,
+ 239883, 309030, 398107, 512861, 660693, 851138, 1096478, 1412538,
+ 1819701, 2344229, 3019952, 3890451, 5011872, 6456542, 8317638, 0
+};
+
+static const uint32_t scale_factor_quant7[128] = {
+ 1, 1, 2, 2, 2, 2, 3, 3,
+ 3, 4, 4, 5, 6, 7, 7, 8,
+ 10, 11, 12, 14, 16, 18, 20, 23,
+ 26, 30, 34, 38, 44, 50, 56, 64,
+ 72, 82, 93, 106, 120, 136, 155, 176,
+ 200, 226, 257, 292, 331, 376, 427, 484,
+ 550, 624, 708, 804, 912, 1035, 1175, 1334,
+ 1514, 1718, 1950, 2213, 2512, 2851, 3236, 3673,
+ 4169, 4732, 5370, 6095, 6918, 7852, 8913, 10116,
+ 11482, 13032, 14791, 16788, 19055, 21627, 24547, 27861,
+ 31623, 35892, 40738, 46238, 52481, 59566, 67608, 76736,
+ 87096, 98855, 112202, 127350, 144544, 164059, 186209, 211349,
+ 239883, 272270, 309030, 350752, 398107, 451856, 512861, 582103,
+ 660693, 749894, 851138, 966051, 1096478, 1244515, 1412538, 1603245,
+ 1819701, 2065380, 2344229, 2660725, 3019952, 3427678, 3890451, 4415704,
+ 5011872, 5688529, 6456542, 7328245, 8317638, 0, 0, 0
+};
+
+/* 20bits unsigned fractional binary codes */
+static const uint32_t lossy_quant[32] = {
+ 0, 6710886, 4194304, 3355443, 2474639, 2097152, 1761608, 1426063,
+ 796918, 461373, 251658, 146801, 79692, 46137, 27263, 16777,
+ 10486, 5872, 3355, 1887, 1258, 713, 336, 168,
+ 84, 42, 21, 0, 0, 0, 0, 0
+};
+
+static const float lossy_quant_d[32] = {
+ 0, 1.6, 1.0, 0.8, 0.59, 0.50, 0.42, 0.34,
+ 0.19, 0.11, 0.06, 0.035, 0.019, 0.011, 0.0065, 0.0040,
+ 0.0025, 0.0014, 0.0008, 0.00045, 0.00030, 0.00017, 0.00008, 0.00004,
+ 0.00002, 0.00001, 0.000005, 0, 0, 0, 0, 0
+};
+
+/* 20bits unsigned fractional binary codes */
+static const uint32_t lossless_quant[32] = {
+ 0, 4194304, 2097152, 1384120, 1048576, 696254, 524288, 348127,
+ 262144, 131072, 65431, 33026, 16450, 8208, 4100, 2049,
+ 1024, 512, 256, 128, 64, 32, 16, 8,
+ 4, 2, 1, 0, 0, 0, 0, 0
+};
+
+static const float lossless_quant_d[32] = {
+ 0, 1.0, 0.5, 0.33, 0.25, 0.166, 0.125,
+ 0.083, 0.0625, 0.03125, 0.0156, 7.874E-3, 3.922E-3, 1.957E-3,
+ 9.775E-4, 4.885E-4, 2.442E-4, 1.221E-4, 6.104E-5, 3.052E-5, 1.526E-5,
+ 7.629E-6, 3.815E-6, 1.907E-6, 9.537E-7, 4.768E-7, 2.384E-7, 0,
+ 0, 0, 0, 0
+};
+
+
+/* Vector quantization tables */
+
+static const int8_t high_freq_vq[1024][32] =
+{
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ { -4, -2, 2, 1, -16, -10, 1, 3, 1, 0, 6, 1, -3, 7, 1, -22,
+ 2, -4, -3, 11, 14, 6, -1, 1, -13, 29, -28, 10, 10, -8, 0, -9 },
+ { -8, 8, -7, 10, -3, -12, -5, -8, 1, -2, 9, -2, -5, -18, 1, 9,
+ -8, -8, 3, 41, 7, -9, -9, 22, -42, -29, 14, -18, -14, -32, 1, -15 },
+ { -16, 8, 15, 16, -16, 5, 2, 7, -6, -16, -7, 1, 1, -3, -2, 0,
+ 8, 20, -26, -11, 2, -17, 0, -3, -34, -37, 10, 44, -2, 22, 2, -4 },
+ { 7, 14, 5, 6, 15, -1, 3, -3, -9, -23, -5, -14, 8, -1, -14, -6,
+ -5, -8, 54, 31, -6, 18, 2, -19, -2, -11, -30, -6, -19, 2, -2, -14 },
+ { 1, 2, -2, -1, -3, -3, 1, -5, 1, -3, -4, -8, 5, -4, 0, 1,
+ 3, 7, -5, -4, -3, -12, 3, -2, -3, 12, -53, -51, 6, -1, 6, 8 },
+ { 0, -1, 5, 1, -6, -8, 7, 5, -18, -4, -1, 1, 0, -3, -3, -14,
+ -1, -6, 0, -14, -1, -1, 5, -3, -11, 1, -20, 10, 2, 19, -2, -2 },
+ { 2, 4, 3, 0, 5, 0, 3, 1, -2, 0, -6, -3, -4, -5, -3, -3,
+ -7, 0, -34, 4, -43, 17, 0, -53, -13, -7, 24, 14, 5, -18, 9, -20 },
+ { 1, 0, -3, 2, 3, -5, -2, 7, -21, 5, -25, 23, 11, -28, 2, 1,
+ -11, 9, 13, -6, -12, 5, 7, 2, 4, -11, -6, -1, 8, 0, 1, -2 },
+ { 2, -4, -6, -4, 0, -5, -29, 13, -6, -22, -3, -43, 12, -41, 5, 24,
+ 18, -9, -36, -6, 4, -7, -4, 13, 4, -15, -1, -5, 1, 2, -5, 4 },
+ { 0, -1, 13, -6, -5, 1, 0, -3, 1, -5, 19, -22, 31, -27, 4, -15,
+ -6, 15, 9, -13, 1, -9, 10, -17, 4, -1, -1, 4, 2, 0, -3, -5 },
+ { -7, 3, -8, 13, 19, -12, 8, -19, -3, -2, -24, 31, 14, 0, 7, -13,
+ -18, 0, 3, 6, 13, -2, 1, -12, -21, 9, -2, 30, 21, -14, 2, -14 },
+ { -3, -7, 8, -1, -2, -9, 6, 1, -7, 7, 13, 3, -1, -10, 30, 4,
+ -10, 12, 5, 6, -13, -7, -4, -2, -2, 7, -3, -6, 3, 4, 1, 2 },
+ { -8, 9, 2, -3, -5, 2, 0, 9, 3, 7, -4, -16, -13, 3, 23, -27,
+ 18, 46, -38, 6, 4, 43, -1, 0, 8, -7, -4, -1, 11, -7, 6, -3 },
+ { 1, 1, 18, -8, -6, 0, 3, 4, 22, -3, -4, -2, -4, -11, 40, -7,
+ -3, -13, -14, -7, -10, 14, 7, 5, -14, 11, -5, 7, 21, -2, 9, -3 },
+ { 0, 0, -2, 4, -2, 0, 2, 0, -1, 2, -1, 0, 0, 2, 2, 2,
+ -1, 1, -3, -1, -15, -2, -63, -27, -21, -47, -14, 1, -14, 10, 0, 2 },
+ { 1, 0, -4, 0, -3, -9, 4, 2, 6, -6, 0, -5, 11, -7, -15, 6,
+ -7, -6, 3, 7, -15, -5, 23, -13, -6, 12, -8, 9, 2, -3, 3, 4 },
+ { 6, 0, 3, 0, -2, -4, 2, 1, 1, -1, 1, -2, -1, -4, -22, -15,
+ -46, -66, 10, 20, 2, -17, 12, -6, 1, -2, -2, 0, 1, -5, 1, 2 },
+ { -1, 0, 0, 1, 0, -4, 0, 1, -10, -3, -8, 5, 7, -11, 2, -11,
+ 29, -25, 11, 10, 0, -1, 5, -7, -2, -5, -2, 4, 4, -3, 5, -2 },
+ { 1, -1, -1, -3, -2, 1, -8, -3, 2, -2, 4, -5, -1, -7, -2, 1,
+ -14, -7, 3, -30, -15, -14, 3, -4, -1, 3, -13, -1, -3, 1, 2, 3 },
+ { -1, -2, -3, 2, 2, -3, 3, 1, -3, 2, 0, -4, 6, 5, -5, 10,
+ -57, 3, 22, -50, 1, -2, -5, -6, -1, 5, 1, 2, 2, 1, -2, 2 },
+ { 2, 0, -1, -7, 2, 1, 3, 2, 0, 4, 3, -2, 3, -3, 4, -4,
+ 24, -35, -3, 38, -6, -5, 15, 20, 3, 16, -7, -5, 0, -4, -5, 0 },
+ { 0, 1, 0, 0, 0, -1, -1, 1, 1, -1, 1, -2, 0, 0, 0, 0,
+ 0, -1, -2, -1, -5, -2, -43, -3, 46, -52, -10, 7, -8, 11, -2, -1 },
+ { 0, 0, -1, 0, -1, 2, -41, 33, -44, -48, -15, -26, -9, 6, 3, 3,
+ -3, 2, 2, 2, 2, -1, -1, -2, 1, 3, 0, 0, 5, 2, 3, 1 },
+ { -4, 1, 6, 1, -6, -1, -2, 1, -14, -4, 0, -5, -2, 2, -2, 0,
+ -6, 1, 0, 8, -21, 32, -3, -36, -6, -2, -1, -7, 3, 0, 1, -6 },
+ { -3, -2, 3, 0, 2, 2, 8, -4, -4, 6, 2, 1, 3, -6, 4, 3,
+ 13, 0, -12, -1, 25, -20, -2, -23, -15, 7, -3, -11, -3, 6, -1, 0 },
+ { 0, 0, -3, -1, 0, 0, -2, -1, -2, -2, 1, -1, 0, 0, 10, 3,
+ -2, 3, 3, -7, -6, -5, 0, -4, -60, -16, -6, 38, 5, 6, -5, 0 },
+ { 0, 1, 0, 0, 0, 0, 0, 0, 1, -1, -1, 0, 1, 0, 0, 1,
+ 0, 0, -1, 0, -8, 2, -9, 10, 40, 31, -56, -21, 4, 20, -4, 7 },
+ { -2, -2, 0, 4, -3, -1, 7, 3, 1, 3, -8, 0, 3, 1, 2, 5,
+ 1, -2, 14, 5, 4, 5, 5, 5, -5, 9, -66, 0, -20, -2, -8, 4 },
+ { -2, -1, 4, -1, -8, -2, -4, -1, -3, -3, 2, -7, -3, 5, 7, -2,
+ 45, 31, -17, -16, -2, -2, -1, -22, 1, -1, -3, 3, 5, -3, 5, -1 },
+ { -4, 0, 7, 5, 8, 7, 2, 9, -9, -9, -7, -11, -3, -8, 17, -4,
+ 34, 32, 18, 22, 1, 2, 1, -7, -5, 6, -1, 6, 4, 10, -2, -7 },
+ { 6, 0, 14, 9, 6, -1, -2, -3, 4, -6, -8, 4, 7, -1, 28, 38,
+ 15, -1, 16, -11, 5, 8, 4, -10, 3, -10, -17, 5, 3, 3, 3, 1 },
+ { 1, 1, 2, -1, 2, 1, 0, 0, -1, 0, 0, -2, 1, -3, 0, 1,
+ 2, -2, -4, -2, 0, -1, 1, -3, 1, 1, 1, -1, 8, 8, 66, 33 },
+ { -5, 2, -3, -7, 2, -8, -4, 10, 17, -18, -7, 4, -4, -7, -6, -6,
+ -5, 5, -12, 2, 0, 6, 8, -2, 1, 4, -11, 2, 1, 8, 31, 19 },
+ { 6, 9, 16, -6, -6, -1, -2, -3, -11, -2, 7, 7, 17, 3, 4, 10,
+ 2, 5, -13, 8, 7, 1, 4, 5, 7, 6, 7, -8, 9, -8, 33, 6 },
+ { 3, -1, 1, 0, -7, -5, 0, 14, -7, 1, -7, 1, 2, -4, 7, 10,
+ -16, 12, 1, -6, 3, 8, -1, 10, -13, -6, -12, -23, 12, -3, 30, 14 },
+ { -2, -15, 0, 8, 3, -19, 5, -3, 2, 3, 13, 7, 14, -3, -10, 0,
+ 8, 5, -6, -16, -8, -8, 14, 2, -1, 1, -9, -11, 11, -5, 27, 9 },
+ { -8, 6, -4, 4, -4, -1, 5, 4, 1, -7, -5, -4, -15, 1, 9, 0,
+ 8, 4, 1, -17, 11, -2, -19, -1, -6, -8, 3, -12, 3, -17, 33, -10 },
+ { -3, -1, 2, 7, 7, -2, 9, 8, -18, -1, -13, -10, -3, -3, 11, 8,
+ -2, -12, -8, 1, 4, 9, 14, 10, -3, 0, 2, 1, -2, 3, 31, 10 },
+ { -3, -10, 8, -1, -5, -11, 7, -5, 3, 6, 1, 4, -16, 10, 5, -4,
+ -2, -10, -1, 13, 6, -5, -7, 12, 7, -3, -17, 1, 12, -4, 29, 8 },
+ { 1, 2, 5, 2, -6, -7, 0, -1, 6, -1, 10, 6, -4, 5, 2, 2,
+ -2, -8, -6, -11, 14, -13, 27, 3, -2, -12, 5, -16, 2, -26, 20, 15 },
+ { -1, -3, -5, -3, -3, 6, -1, 3, -5, 1, 7, 2, 1, 0, -1, -1,
+ 0, -1, 9, 7, -6, -3, 4, -5, -4, 8, -8, -25, -8, -4, 34, 23 },
+ { -1, -2, 1, 1, -1, -2, -1, 1, -1, 0, 0, 0, 0, -2, -1, 1,
+ 0, 2, 1, -1, 4, 0, 0, 1, -1, 0, 5, 3, 12, -9, 68, -16 },
+ { 10, 0, -8, 14, -6, 1, -12, 0, 0, -3, -5, -11, -6, 12, 9, -10,
+ -3, 5, 0, 7, 11, 2, 4, -3, -8, -3, 7, 4, 3, -3, 34, 4 },
+ { -12, 13, -5, 7, -11, -2, -1, 1, -4, -14, -21, 3, -3, -3, -4, -7,
+ -9, -4, 3, -17, -2, -13, 10, -2, 12, -4, 0, -9, 1, -5, 31, 10 },
+ { -10, 6, 5, 6, 4, -7, 10, 0, -28, -3, 0, -11, -1, -5, 16, -10,
+ -16, 7, 20, 2, -4, 2, -5, 0, 15, 6, 5, -10, 7, -9, 20, 4 },
+ { 1, -7, -2, -7, 4, -3, -2, -7, -1, -14, 6, -16, 4, -5, -4, -6,
+ -5, 0, -2, 2, -6, 9, -5, 4, -18, 8, -10, 8, 15, 0, 32, 1 },
+ { -5, 7, -3, 7, 15, -4, 0, -16, 9, 5, -5, 5, 4, -3, -12, -9,
+ -18, 10, 2, 2, -3, 7, 3, -1, 6, -9, -10, 3, 15, -4, 35, -7 },
+ { -1, -10, 2, 2, -4, -2, 10, 2, -1, 2, -2, 1, -1, -14, -11, 3,
+ -8, 5, -8, -2, 6, -1, -7, 1, 7, 5, 7, 8, 30, -4, 30, 14 },
+ { 2, -2, 1, 2, 3, -8, 3, 0, -2, 0, -9, 2, 1, 4, -6, -1,
+ -2, 5, 0, 1, -2, 12, 6, -3, 9, -3, 4, -12, 21, -39, 24, -2 },
+ { 3, 5, 1, -2, -2, -2, -3, 6, -8, -2, -11, -8, -1, 4, 2, 2,
+ -4, -10, 12, -5, -11, 1, -15, -34, -11, -7, -11, -1, 7, -14, 38, -1 },
+ { -4, 4, 8, 9, 8, 1, -5, -9, 4, -2, 15, -4, 11, -15, 20, -1,
+ -1, -3, 4, -9, -2, -2, -2, 8, 6, 12, -5, 0, 11, -12, 27, -4 },
+ { 0, 8, -4, 3, -11, 6, -11, 2, 3, 0, 5, -8, -7, -6, -9, -21,
+ 4, -11, -1, -16, -7, 16, -3, 7, -7, 4, -5, 0, 11, -7, 31, 3 },
+ { 1, 3, 4, 11, -11, -2, -3, -6, 6, 5, 0, 3, -9, -6, 4, -4,
+ 0, 4, -8, 13, -6, -13, -1, -5, -1, 4, 0, 0, 9, -22, 24, 18 },
+ { -7, 3, 10, -13, -6, 6, -6, 6, 22, 1, 0, -14, 2, 3, 7, -1,
+ 8, 20, -1, 5, -4, 13, 9, -9, -9, 6, 0, -4, 0, -8, 31, -4 },
+ { -3, -4, 0, 1, 7, 3, -7, 0, 5, -2, 1, 3, 3, 1, -5, -2,
+ 5, 2, -11, 4, 0, -1, 12, 0, -3, -13, 15, 8, -6, -27, 34, 0 },
+ { -3, -3, 10, -4, 2, -1, -3, 0, -1, -1, -4, 2, 6, -2, 12, 1,
+ 3, -6, -7, -6, -5, 4, -19, -6, -8, -34, -4, -8, 10, -7, 23, 10 },
+ { -7, 0, -1, -6, 8, 4, -4, 2, -5, -8, -7, -9, -8, 5, 9, 7,
+ -6, 1, -12, -12, -1, -16, 5, 0, 16, 3, -7, -8, 27, -4, 23, 15 },
+ { -8, 4, 8, 5, 6, 11, -3, 5, 3, -1, -11, 6, -5, 0, 2, -6,
+ -3, -6, 4, -1, 5, -5, -12, -6, 7, -5, 9, 3, 6, -7, 29, 1 },
+ { 1, 3, -2, -2, -6, -2, 1, 6, -6, -3, 1, 2, 3, 4, 1, 5,
+ -1, 0, 4, 2, 11, 6, 2, -3, 13, -9, -19, 18, -15, -10, 36, 21 },
+ { -3, -3, 2, -1, -7, 6, -4, 1, -3, -1, -2, 2, 3, -7, -3, 0,
+ -2, 0, -2, 6, -19, 3, -8, 2, -6, 7, -1, 0, 29, -6, 28, -10 },
+ { -5, 1, -3, -7, -12, -4, 1, 1, -1, 13, -10, -1, -9, -5, -13, 6,
+ 13, 3, -4, 2, 3, 11, 2, 6, -25, -16, -6, 0, 14, -1, 27, 16 },
+ { -6, -1, -7, -5, -2, -5, -5, -1, 9, 1, 0, 3, -8, -12, -6, 5,
+ -6, 5, 3, -9, 1, 4, -7, -10, -9, -7, -17, -5, -15, -23, 25, 3 },
+ { -8, -2, 9, -3, -4, 3, -1, 8, -7, -7, -5, -4, -2, 9, 4, -1,
+ -7, -4, -5, -16, 3, -6, 18, -13, -9, 16, -15, 8, 15, -10, 24, 5 },
+ { 1, -38, 2, 34, 9, 10, 11, 2, 2, -6, 3, 2, -2, 5, 4, -7,
+ -1, 1, 4, 0, 3, 1, -8, -1, -6, 5, 4, 2, -4, 5, 2, -1 },
+ { 1, -22, 15, 18, -2, 10, -16, -9, -8, -11, 8, 4, 0, 7, -14, -5,
+ -1, -7, 12, 17, 9, 5, -7, -4, -12, -6, 7, 0, 7, 2, -2, 1 },
+ { -11, -29, 7, 10, 19, -1, -8, -9, 7, 1, 9, 6, 8, -7, -14, 8,
+ -3, -11, -13, 0, -7, -23, -2, -8, 12, 9, 2, 14, 19, 1, -1, 5 },
+ { -24, -27, -11, 36, 2, 6, -3, 4, -6, 8, 0, 12, -1, -4, -6, 3,
+ 4, -1, 2, -3, -2, 3, 2, -1, -2, -4, 0, -1, -2, 7, 2, 3 },
+ { -9, -24, 11, 13, -10, -12, 12, -2, 7, 4, 8, 13, -3, -3, 2, 9,
+ -3, -4, 4, 13, 5, 13, -6, -3, 1, 15, 7, -3, 0, 19, -2, -9 },
+ { -8, -15, 7, 14, -4, -5, 2, -18, -19, -2, 2, 17, 16, 6, -10, 10,
+ -9, 14, -1, -5, -1, -6, -7, 2, 9, 11, 13, 6, -5, -12, 3, 2 },
+ { -10, -37, 13, 1, 3, -14, 0, -20, 4, -3, 8, 2, -2, -3, -9, -5,
+ -3, -17, -1, 13, -11, 2, -6, 4, 4, 0, 3, 1, -9, -4, -5, -4 },
+ { -2, -22, -5, 46, -8, 5, 9, -11, 8, 7, 7, -1, -1, -2, -7, 2,
+ -3, 3, -1, -2, 7, 0, 2, -1, 1, -2, -2, -3, 6, 0, -4, -6 },
+ { -16, -27, 15, 16, -4, 14, -7, -26, 2, -2, 6, 5, -3, 11, 0, 2,
+ 3, 9, -7, -1, 2, -4, -4, -1, 6, 10, 1, 1, -3, -2, 3, 0 },
+ { -3, -22, 10, 26, 1, 2, -3, 3, 17, -3, -7, 9, 1, -21, -4, 5,
+ 3, 0, -7, -6, 3, 3, -8, -7, -9, 3, 7, 1, -8, 12, 6, -7 },
+ { -9, -25, 3, 18, 9, -6, -11, 0, -5, -12, 9, -8, -7, -6, -6, 22,
+ 2, -6, -3, 15, 3, 2, -2, 9, 14, -10, -7, 15, 13, 6, -2, 11 },
+ { 5, -20, -5, 28, 11, 10, -4, -4, 0, -7, 3, 5, 2, -5, -8, 2,
+ 6, 10, 9, -9, -18, 3, 14, 1, 3, -3, -1, -6, 7, 7, 2, -1 },
+ { -8, -30, 7, 12, 10, 8, 7, -13, -16, 0, 1, -1, -6, -11, -15, 4,
+ 1, -2, 10, -15, 1, 11, -2, 8, 9, -7, -7, 9, -5, 2, 7, -18 },
+ { -10, -32, 10, 11, 3, -1, 3, -5, 5, 2, 14, -6, 3, 1, 5, -15,
+ -11, 6, 20, 4, 0, -12, -7, 3, 1, -1, 10, 6, -1, -9, -4, -1 },
+ { 1, -25, -14, 12, -11, 9, 9, -16, -24, -17, 22, -9, 11, -30, -3, -4,
+ 6, -7, 9, 2, -1, -5, -6, 2, -1, -1, 10, 1, -3, 3, 4, 8 },
+ { -14, -26, -6, 9, 8, 17, -11, -24, -7, -4, -8, -2, 10, 2, 2, -1,
+ 2, 13, 12, -7, 4, -6, -10, 6, 6, -13, -11, -7, -16, 0, -2, 5 },
+ { -4, -30, -13, 12, 16, -6, 12, -16, -13, 5, 15, -2, -2, -10, -7, 7,
+ 11, -1, -4, -2, -4, 7, 4, -8, 1, 3, 0, 11, 3, -2, -5, 4 },
+ { -4, -21, 20, 22, 2, 20, -8, 1, -12, -5, -9, 4, -10, -17, -3, -8,
+ -3, 3, -12, 1, -3, 0, 7, 4, 7, 7, -3, 7, 5, 3, 1, -5 },
+ { -12, -20, 2, 29, 11, -6, 9, -7, -6, -4, 0, 6, 17, -13, -2, -10,
+ -17, -1, -18, 2, 0, 14, -6, 1, 0, 3, 2, -10, 1, -5, -2, 5 },
+ { 16, -37, -1, 26, -2, -14, 1, -5, -14, 2, 2, 3, 6, 1, 1, 4,
+ 0, -1, 0, -2, -2, 4, 9, -6, 0, -2, 10, -7, -2, 4, 1, 0 },
+ { -9, -24, -12, 5, 5, 3, -17, -14, 4, 3, 2, -4, 10, -22, -8, -3,
+ 6, 1, 12, -8, 4, 1, 9, -1, 18, -3, 6, 5, 3, -5, 9, -5 },
+ { -14, -33, -2, 20, -13, -10, 2, -7, -1, 11, -9, -8, 18, -3, 1, 8,
+ 0, -2, 10, 7, -2, -13, 9, -3, -4, 5, -2, -2, -1, -5, 1, -7 },
+ { -10, -23, 8, 14, 1, 7, 1, -3, -7, 4, 1, 1, 8, -7, 15, -14,
+ 13, 14, 2, 5, -13, -5, -8, -1, 6, 3, 6, 9, 6, 15, 14, 5 },
+ { -13, -25, -10, 13, -17, -24, -7, -13, -6, -10, -8, 2, 0, -13, -10, -4,
+ -8, 4, -9, 9, -4, 4, -3, -3, 3, 3, -5, -9, 1, -2, 11, 2 },
+ { -12, -23, 1, 18, -11, -2, 5, 9, -5, 5, 14, -9, -3, -2, -6, 2,
+ -2, 11, -13, 1, -3, 11, -9, -4, -2, -6, 8, 10, 1, 4, 2, 1 },
+ { -5, -18, 16, 22, 2, 0, 8, -6, -9, -7, 10, -16, 23, 10, -11, -1,
+ 7, 2, 7, 2, 1, -5, 6, 1, 0, -4, 9, 2, -3, 1, 0, -4 },
+ { -3, -26, 14, 11, 2, -9, 17, -2, -1, -5, -16, -9, -5, 10, -13, 1,
+ 6, 12, 10, 11, 0, 0, -3, -14, 6, -2, 0, 4, -5, -1, -7, -1 },
+ { -10, -33, 1, 8, 11, -5, 1, -6, 7, 4, 5, 6, 1, -2, -10, -5,
+ -6, 12, -11, 5, -10, 4, 12, -1, -1, -3, 4, -1, 9, 0, 16, -17 },
+ { -14, -37, 7, 7, -2, 5, -8, -11, 2, -13, 4, -19, 1, 8, 8, 4,
+ -9, 2, -4, 3, 12, 2, 4, -4, -8, 8, 1, 4, 8, -1, 6, -2 },
+ { -6, -30, 18, 17, 1, -22, -3, 4, -7, -10, 7, 0, -8, 8, -1, 4,
+ 2, 8, 6, -2, 2, 7, 4, 4, 3, -6, 2, 1, -3, 1, -1, -5 },
+ { -17, -18, -3, 22, -8, 1, 9, -2, -17, 20, -5, -5, -12, -5, 4, -5,
+ -9, 8, -2, 16, -3, 0, 19, -8, 8, 1, 2, -4, 0, 11, 0, -3 },
+ { -9, -23, 3, 10, 4, 4, -3, -2, -2, -2, 1, -22, 11, 0, -2, 5,
+ -2, 14, -9, -11, -4, 7, 5, 32, 1, -3, -7, 0, 21, -9, 7, -6 },
+ { 0, 0, 0, 2, -1, 1, 0, 1, 3, 0, 0, 1, 0, 1, 0, 1,
+ -3, 0, -1, -2, 0, -1, -1, -3, -1, 1, -4, 1, -1, -5, -69, -19 },
+ { -3, -5, -8, -12, 4, -3, -19, -11, -5, 0, -14, 7, 18, -6, 7, 22,
+ 8, 14, 15, 10, 3, -1, -3, 5, -1, 7, -7, 1, -6, 3, -26, -11 },
+ { -1, -6, 4, -4, -5, -16, 0, -6, -3, 11, 1, 0, 9, 5, 16, 3,
+ -4, -33, -4, 4, -7, 0, 1, 6, -11, -2, -13, -2, -18, 20, -25, -16 },
+ { 4, 0, -1, 0, -5, 1, 0, 2, 0, 11, -10, 4, -10, 7, 16, 2,
+ 16, 15, 2, -1, 2, 9, 2, 8, -3, -5, -2, 0, -3, 0, -33, -2 },
+ { -3, -15, 10, 10, -9, -1, 7, 3, 5, -5, -8, -8, -3, 15, -9, 4,
+ 12, 13, -13, -14, 10, -6, 9, 22, -27, 23, -1, 5, -24, 2, -30, 5 },
+ { 0, -2, 7, -5, -5, 3, 5, 3, -3, -5, 2, 1, -4, 3, -3, -1,
+ 1, -2, 10, 22, -3, -4, -2, -2, -7, 3, 8, 1, 14, 4, -37, 9 },
+ { -3, -4, -1, 1, -4, 0, 6, 2, 6, -7, -10, -10, -1, -4, 11, -3,
+ 7, -6, 4, -12, -1, 5, 1, -7, 10, -6, 17, -4, 8, 3, -40, 13 },
+ { 2, 12, 4, -7, 14, -3, 16, -2, 18, 2, 13, 5, 5, 1, 11, -1,
+ 0, 9, 2, -6, -1, 2, -6, 2, -5, 3, 5, 1, -1, 1, -32, -7 },
+ { -16, 11, 7, -4, 2, -5, -9, 9, 11, 11, 15, -13, -11, 11, 9, 4,
+ 3, -8, -10, 12, 12, 0, 0, -16, -9, 13, 2, 9, 4, -13, -33, 3 },
+ { 6, 4, 5, 4, 3, -1, 5, 6, 4, 2, -11, -1, -15, -11, -1, 1,
+ 11, -3, -2, 24, -4, -6, -25, -10, -15, -8, 0, 0, -5, 4, -30, 2 },
+ { 10, -3, -6, 1, -9, -5, 6, 9, -10, -3, 8, -1, 4, -1, 11, -11,
+ 3, 9, 11, -3, 6, -17, 5, -8, -33, 9, -13, 19, -2, 9, -25, 2 },
+ { 0, 0, -1, -3, 0, -2, 1, 0, 0, 2, 1, 0, -2, 0, -1, 2,
+ 0, -1, 4, -1, 2, -3, 4, -2, 3, 3, 1, 0, -15, 12, -63, 27 },
+ { -2, 14, 9, -1, 3, 0, 1, 1, -19, 15, 3, 4, 0, -10, 1, -5,
+ 3, 0, -5, -10, 2, -16, -4, 8, -12, -6, 7, -5, -10, -1, -33, -4 },
+ { 0, 3, 1, 3, 1, 2, 4, 4, 9, -6, -8, -5, 1, -12, 3, 8,
+ -10, 6, -1, 1, 13, -5, -5, 2, -4, 13, -18, -10, -7, -9, -33, 10 },
+ { -6, -3, -12, 5, -1, 11, -6, 0, -2, 1, 2, -7, 3, 1, 3, -2,
+ 1, 8, -10, 7, -1, -3, 3, 0, 13, 1, 6, 7, -16, -7, -39, 8 },
+ { -6, -1, 11, 6, -3, 8, 3, -5, 3, 0, -5, -2, -6, -3, -4, 2,
+ -3, 13, -11, 1, 7, 5, 19, -5, -3, -15, -1, 7, -1, 6, -33, 8 },
+ { -7, 3, -4, -3, -4, 1, 6, -5, -5, 6, -8, -1, -7, 4, -1, -6,
+ -2, 1, 7, 0, 1, 1, -5, 2, -2, 0, -13, -2, -31, -14, -39, -12 },
+ { -10, 9, 0, -3, 1, -1, -1, 0, 1, -5, -1, -4, -2, 5, 2, -7,
+ 18, -8, -2, -19, -7, -7, -12, -14, -11, -1, -9, -13, -7, -12, -31, -9 },
+ { -3, -16, 10, 9, 1, -10, -12, 2, -2, 2, 7, -3, -3, 1, -4, -5,
+ -9, 5, 7, 3, -1, 4, -11, -8, 4, 13, -10, 13, 10, -4, -36, 1 },
+ { -7, -12, 4, -20, -7, -7, 2, 11, -1, -2, 3, -12, 1, 0, -6, -7,
+ 6, 4, 13, 3, -3, 4, 3, -6, -12, 5, -5, -22, -13, -8, -37, -6 },
+ { -7, 5, 3, 5, 7, 9, -14, -3, 10, 17, -1, 1, -12, 5, -6, 0,
+ -4, -9, 0, -11, -14, 3, 13, 6, -25, -8, -12, 4, -10, 18, -30, -1 },
+ { -10, 6, -10, 6, 6, 1, -10, 0, -7, 5, -2, 17, -18, -4, 0, -3,
+ -16, -6, -3, -8, 5, 1, -4, 6, -7, 16, 6, 10, -1, 0, -32, -11 },
+ { -1, 9, 9, -5, 4, 9, 6, 9, -4, -2, 7, 11, 4, 2, -5, -4,
+ -6, 0, 2, -3, -1, 5, 10, 0, 12, -10, -18, -3, -1, 14, -33, 2 },
+ { 4, -8, -18, -4, -5, -11, 4, -10, -4, 9, 13, -12, 1, -6, 1, 2,
+ 4, -9, 8, 3, -6, 21, 13, -1, -2, 1, -2, 6, -7, 0, -30, 1 },
+ { 6, -1, 2, -3, -1, -4, 6, -4, 0, 4, 2, 2, -9, 2, 6, 3,
+ -2, 4, -1, 9, -6, 0, 7, -8, 5, 19, -2, 9, -5, 2, -33, -8 },
+ { 2, 1, 12, -5, -8, 8, 3, -2, -4, 1, -2, 5, -4, -9, -8, -8,
+ 7, -11, -4, 6, -10, 7, -1, -1, -2, -1, 16, 32, -7, 20, -33, -6 },
+ { -18, 2, 6, 13, 9, 9, -1, 3, -17, 24, -2, -6, 28, 8, -2, 6,
+ 3, -10, -34, -16, -13, -4, -15, -11, -12, -3, -10, 4, -8, 4, -31, -4 },
+ { -11, 0, 18, 2, -16, -9, -13, -2, -2, -12, -3, -22, 30, 0, 8, 3,
+ 9, -4, -16, 1, 0, -11, 15, -2, -4, 6, -5, 6, 1, 2, -25, -12 },
+ { 14, -1, 5, 7, 3, -15, -8, 1, 5, -2, 12, 13, 11, -25, 3, 1,
+ 0, -2, -4, -16, -23, 0, -5, -17, 7, 5, -9, 6, -5, 2, -32, -7 },
+ { 3, -1, 6, 14, 2, -12, -9, -9, 4, 7, 4, 6, 5, -8, 4, 2,
+ 4, 5, -2, 8, 8, -6, 0, 10, -20, -1, 3, -1, 8, 23, -33, -5 },
+ { -3, 11, -6, 3, -4, 5, 7, 3, 4, 5, -2, 3, -1, 30, 6, 1,
+ 8, -6, 0, 0, -9, 6, -9, 4, 2, 9, -6, 1, -12, 0, -34, 18 },
+ { -17, 13, 0, 1, 9, -4, -11, 0, 7, 0, -10, -4, -1, 6, -6, 4,
+ 1, 6, -9, 3, -5, -6, -11, 2, -4, 14, 23, -3, 2, 5, -30, 12 },
+ { -14, 5, -27, 2, 0, 7, 1, 4, 30, 8, 7, 5, 1, -1, 0, 5,
+ 8, -10, 48, -11, 12, 33, 6, 8, -15, 20, -2, -5, 32, 5, -19, 10 },
+ { -16, -4, -12, -7, -2, 0, 8, -6, -20, -18, 16, -3, 0, 31, -2, 11,
+ 2, -9, 49, -19, -12, -23, 10, 26, 16, -2, 4, -21, -14, 13, -11, -9 },
+ { -5, -9, -1, 3, -5, -21, 2, 10, 0, 0, 10, -21, -7, 7, -26, -9,
+ 22, 32, 58, 11, -3, 11, -5, -8, -13, 6, -5, -9, 1, 10, 14, -8 },
+ { 7, 7, 10, 3, -2, -1, -11, -11, -6, -43, -3, 14, -19, -18, 19, 18,
+ -32, 10, 45, -6, 6, 21, -20, -12, 2, 4, 6, 6, -4, 3, 3, 1 },
+ { 21, 22, -3, -2, -11, -6, -1, -2, 8, 8, 32, -21, 7, 28, -4, -6,
+ -3, -2, 50, 2, 2, 27, -5, -8, 12, 7, -5, -1, -4, -17, 27, 6 },
+ { 13, 7, 2, -6, -12, 2, -10, -5, -17, 11, 4, 17, -12, -2, 5, -17,
+ 37, -16, 48, -14, -18, 29, 8, 24, 11, -5, -9, 11, -1, 1, -13, -3 },
+ { 1, 1, -1, 2, 0, 0, 0, -1, 1, -1, 7, 2, -3, 3, 0, 6,
+ 2, 10, 54, -25, 7, 54, -5, -6, -1, -15, 9, 13, -24, -15, -12, 3 },
+ { 21, 5, 8, 3, -3, -4, -2, -4, 3, -11, -5, -8, 9, 16, 8, -9,
+ -10, -3, 46, -46, 2, 1, -10, 10, 17, 11, -20, -36, 10, 14, 0, -5 },
+ { 7, -13, -6, -9, -24, 45, 2, 8, 8, 0, 17, 20, 12, -24, 1, -7,
+ -15, -3, 46, -13, -2, 20, 1, -13, -11, -13, 2, 15, 1, 10, -1, 3 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -2, -1,
+ -16, -9, 31, -69, -34, 26, 7, 17, -1, -6, -1, 0, 0, 0, 0, 0 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -4,
+ -5, -20, 18, -82, 22, 3, -7, 9, 4, 6, 2, -4, -1, 0, -2, 2 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 4, -1,
+ 15, -5, 62, -36, 4, 52, -7, 5, 0, 6, 1, 2, 1, 1, -1, 0 },
+ { 3, -19, 19, -20, 13, -4, -11, 8, 8, -16, 10, 1, -14, 30, 1, -33,
+ 10, -11, 45, -30, 3, -4, -3, -13, 7, 12, 3, -22, 3, -2, -4, -2 },
+ { -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 1,
+ 11, 8, 70, 48, -10, 21, 4, 9, -9, -9, -4, -6, 0, -1, 0, 0 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0,
+ 2, -1, 80, 2, -15, -36, -10, -5, -2, 8, -2, 2, 0, 0, 0, 0 },
+ { 10, 8, -8, -8, -24, 12, -1, 0, 20, 9, -1, -2, 2, -2, 12, -10,
+ -2, -13, 35, -43, 44, 15, -10, -25, 4, 10, -3, -5, -5, 7, -1, 3 },
+ { 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, -2, -1,
+ -18, 9, 49, -72, 7, -8, 7, -5, 2, 3, 2, -2, 1, -2, -3, 1 },
+ { -1, 4, -3, 10, 19, 4, 3, 20, 6, -24, 6, 9, 8, 15, 18, 18,
+ -36, 19, 57, -11, 4, -3, 8, 7, 2, -3, -2, -9, -15, -2, 12, -4 },
+ { 20, 3, 11, -9, -4, 22, 42, -25, 1, 5, -10, -19, 0, 9, -16, 5,
+ 2, 10, 44, -29, 17, -3, -9, -2, -1, 8, 14, -7, -1, 16, -5, 1 },
+ { -7, 16, -11, 12, 6, 33, -15, 14, -23, 2, -26, 8, 2, 10, 0, -5,
+ 8, -8, 38, -38, -4, 5, 5, 5, 1, 22, -15, 7, 6, 0, 4, 28 },
+ { -1, -12, 2, 10, -2, 0, 7, 17, 12, 22, -4, 10, 25, 29, 5, 18,
+ 4, 1, 27, -39, 31, 17, 2, 2, 22, -23, 13, 16, 1, -7, -4, -5 },
+ { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -2, 0, -14, 0,
+ -7, -11, 49, -22, -4, 19, 17, -39, 4, -29, 10, 2, 36, -4, 23, -1 },
+ { -2, -2, -2, -2, 1, 15, -5, -7, -16, -8, -19, 16, -3, -20, 36, -9,
+ -3, 20, 39, -20, 0, 2, 27, -16, 10, 10, -14, -22, -16, -3, 13, -8 },
+ { 5, -9, 6, -25, 7, 37, 13, -10, -5, 3, -5, 7, 18, -22, -7, 9,
+ -5, -4, 50, -11, -4, -5, -5, 8, -4, -2, -4, -27, 14, 20, 7, -9 },
+ { 0, -14, -10, -27, -14, -17, -6, 26, 10, 2, 14, -12, -5, 0, 8, 9,
+ 0, -28, 55, -7, -12, -7, 4, -10, 10, 7, -12, 11, 3, 5, 9, -8 },
+ { 2, 23, 4, -2, -1, -20, -2, 14, 10, -9, -9, -24, 10, 0, 11, -12,
+ 12, 11, 49, -25, -2, 29, 7, -13, 21, -10, 11, -17, 3, 1, -8, 5 },
+ { 3, 0, -14, -6, 18, -2, 17, -9, -19, 9, -5, 9, 14, 6, 19, -3,
+ 27, 1, 41, -21, 20, -15, 33, 0, 26, 14, 7, 10, 3, 20, -3, -12 },
+ { -1, 16, 15, -8, 3, -8, -8, 21, -5, -16, -29, 4, 1, -6, -4, -28,
+ 2, 31, 37, -26, -2, 13, 24, 8, -9, -6, -29, 10, 7, 2, 7, 8 },
+ { -10, -10, 11, 13, -32, 2, 16, 9, 14, 23, -15, -13, 24, 13, 4, -27,
+ 14, 12, 31, -18, 17, 23, -2, -7, -14, 9, -17, -6, -10, 20, 9, 6 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0,
+ 5, 1, 89, 8, 10, -6, 2, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, -1,
+ 4, -7, 64, -50, 7, 37, 2, 5, 0, 0, 0, 0, 0, 0, 0, 0 },
+ { -2, 5, 3, -4, -4, -3, 2, -3, 3, -3, 5, 4, 1, -6, -1, 1,
+ 6, -2, 50, -35, -7, 43, 7, -7, -5, -26, 24, 21, 3, -15, 5, 6 },
+ { -8, 21, -19, 33, -8, 22, -11, 17, 3, 0, 0, -2, 1, -3, 6, -1,
+ 10, -8, 4, -11, -4, -5, 0, 8, -4, 3, 1, -4, 4, 2, 8, 4 },
+ { -7, 5, -20, 9, -22, 3, -14, 1, 6, 13, 23, -2, -4, -7, 2, 0,
+ 11, 4, 6, 3, -7, -11, -7, 4, 5, 5, -12, 8, 2, 4, 7, -3 },
+ { -7, 6, -4, 20, -20, 16, -2, 7, 6, 16, 11, 12, -7, -7, 5, 3,
+ -9, -4, 1, 2, 5, 2, 1, -9, -2, -17, -4, 6, -10, 7, -7, -6 },
+ { -9, 18, -17, 12, -24, 1, -1, 4, 14, 9, 4, 3, 2, 8, -12, -14,
+ 4, -8, -4, 7, 7, 6, -1, 13, -9, -4, -1, 1, 0, -4, 15, 8 },
+ { -25, 2, -11, 6, -5, 24, -28, -5, 8, 12, -2, 6, 8, -3, 8, -9,
+ -1, -5, -1, -5, 6, -1, -1, -1, -4, 8, -12, -2, -13, 7, 2, 1 },
+ { -14, 14, -18, 20, -10, 12, -2, 9, 1, 0, 12, -2, 15, -10, 26, -17,
+ 16, -11, 10, -10, 9, -2, 4, -8, 2, -3, 4, 4, 2, -3, -5, 1 },
+ { -18, 12, -18, 21, -6, 12, -6, 13, -25, 18, 1, 11, -9, -5, 0, 10,
+ -5, 3, -3, 8, -9, 7, 4, 2, -9, 0, 5, 0, 2, -3, 9, -8 },
+ { -4, 16, 1, 18, -30, 9, 1, 6, -8, 13, 13, -12, -6, -1, 13, 7,
+ 6, 2, -15, -3, 5, 5, 1, -6, 1, -5, 0, 2, -16, 0, 3, -4 },
+ { -21, 1, -2, 6, -43, 18, -1, 5, -1, 4, 6, -2, -1, -3, -1, -3,
+ 0, 1, 2, -9, 0, -1, 0, -2, 0, -1, -1, -2, 6, 0, 1, -2 },
+ { -23, 10, 4, 7, -32, -11, -18, 2, -2, -7, -6, -3, -3, -12, 19, 3,
+ -5, -6, 16, -6, 16, 2, 16, 16, 8, -2, 13, 8, -15, -11, 2, 10 },
+ { -8, 2, -13, 2, -29, 24, -20, 19, 1, 10, -4, 10, 1, 2, -9, 11,
+ -1, -2, 9, -5, 19, -7, 16, -9, -2, -18, 11, 1, 1, 0, 7, -3 },
+ { -6, 3, 4, 13, -26, 10, -10, 28, -7, 28, 1, 7, 0, -14, 5, 7,
+ 4, -4, 3, -2, 3, 3, -11, 7, 6, 4, 0, -1, 2, -1, -3, 2 },
+ { -6, 16, -31, 13, -10, 17, -6, 4, -14, 4, 4, -1, -10, 12, -5, 1,
+ -14, 15, 0, -8, 1, -5, 3, 3, 9, -5, 7, -20, 7, 4, 11, -5 },
+ { -19, 3, -17, 14, -12, 16, -22, 18, 14, 8, -2, 4, 10, 12, -14, 4,
+ -3, 2, 3, 7, -7, 7, -6, 2, -2, -4, -5, 0, -5, -2, 2, 1 },
+ { -9, -7, -11, 24, -36, -9, -11, 5, 7, -12, -13, 18, -2, 20, 1, -4,
+ -1, -10, 15, -6, 14, 1, 0, 2, 1, 2, -9, -16, -11, 7, 13, 0 },
+ { -24, 24, -18, 18, -22, 14, -11, 13, -12, 11, -10, 11, -7, 11, -5, -4,
+ -1, 1, 5, 2, 3, -1, 1, -5, 7, -4, 5, -6, 8, -7, 8, -6 },
+ { -6, 18, -22, 22, 5, 11, -1, 6, 19, 22, 8, 4, -8, 20, -2, 15,
+ -6, -18, 0, -33, -9, -12, -1, 6, 5, 2, 5, 5, -5, -17, -3, -3 },
+ { 1, 11, -16, 9, -18, 11, -4, 18, 20, 26, -10, 8, 1, -11, 8, -4,
+ 0, 7, 3, 5, 2, 2, 10, -2, -4, 4, -4, -2, 1, -4, -5, -1 },
+ { -10, 6, -1, 18, -17, 27, -3, 10, -2, 12, -7, -9, 1, 1, -1, 7,
+ -12, -1, -7, -6, -1, 8, 3, -15, 8, 9, 3, -7, 4, -1, 1, -1 },
+ { -14, 6, -16, 22, 2, 5, 0, 5, -18, 11, 6, -3, 22, -20, -9, -3,
+ 6, -6, -7, -15, 1, 15, -8, 11, 8, -3, -8, 1, -8, 2, 6, -2 },
+ { -21, 5, -19, 19, -7, 4, -7, 0, -8, 6, 12, 5, -3, -22, -13, -6,
+ -1, -3, -2, -14, 6, -3, 1, -8, -7, -5, -6, 11, -3, -10, -5, 2 },
+ { -1, 9, -12, 15, -6, 6, -19, 14, -9, 11, 3, 12, -17, -3, 8, -4,
+ -3, -4, 1, -5, 4, 5, -7, -15, -7, 15, -6, -5, 1, -5, -3, 1 },
+ { -12, 20, -15, 20, -14, 3, -14, 9, -6, 33, -13, 6, -2, 8, -6, 7,
+ -5, -6, -3, -3, 0, 8, -3, -3, 1, -2, 2, 2, 6, -5, -5, -2 },
+ { -7, 12, -18, 12, -18, 10, -4, 8, 2, 4, 8, 9, 0, 3, -8, 3,
+ 6, -12, -4, 1, 25, -5, -9, 6, -7, 0, -9, -7, 3, -5, -4, -4 },
+ { -18, 12, -10, 11, -22, 0, -15, 5, -2, 2, -3, 6, -4, -4, -3, -15,
+ -2, -3, 21, 6, -12, -11, 19, 3, 3, -14, 7, 0, -11, -22, -10, 0 },
+ { -15, 2, -30, 15, -17, 13, -16, 8, -7, 10, -8, 2, 11, 3, 10, -7,
+ 7, -22, 12, -10, 3, -12, 6, -10, 12, -10, 7, -8, 5, 2, 9, 1 },
+ { -9, 11, -14, 6, -10, 21, 5, 12, -5, 5, 7, 21, 6, 2, -2, -1,
+ -1, 4, 2, -20, -18, -1, -14, 3, -1, 4, -7, 10, 1, 11, 4, -4 },
+ { -22, 8, -30, 13, -21, -4, 4, -1, 12, 9, -2, -3, 2, -6, 4, -13,
+ -2, 8, 8, 1, -7, 3, -4, -5, -1, -7, -2, 8, 8, 7, 8, 0 },
+ { -6, -4, -35, 16, -13, 15, -11, 14, -7, 9, -1, 11, 7, 0, 13, 10,
+ -1, 8, 1, 1, -2, 8, -1, 2, 2, 3, -10, -1, 7, -13, -3, -7 },
+ { -15, 7, -16, 14, -18, 17, -6, 14, 3, 4, 7, -3, 10, -22, 5, -15,
+ 4, -4, -11, 15, -15, 11, -11, 20, 1, 0, 2, 1, 11, -3, 11, -7 },
+ { -12, 3, 5, 16, -37, -1, 15, 15, -15, 10, 3, -10, 1, 15, 7, -15,
+ -13, 8, 9, -3, 2, 12, -8, 2, -5, 0, -3, 4, 5, -9, -4, 5 },
+ { -16, 26, -4, 14, -22, 26, 6, -3, -8, 4, 21, 6, 16, -4, -11, 7,
+ -10, 3, 3, 7, -4, 2, -9, 8, -2, 2, 5, -2, -4, -2, 7, -1 },
+ { -7, -10, 4, 3, 2, -4, -12, -10, -4, -5, 16, 19, -16, 1, 2, -9,
+ -10, 0, 9, 7, -8, 3, 12, 8, -6, -11, -13, -1, -3, -20, 6, -5 },
+ { -14, -17, 3, -5, 14, -12, -12, 8, -6, -25, 21, 21, 10, -8, -12, 4,
+ 10, -4, 3, -9, 11, 9, 0, 4, 2, -15, 1, -14, 4, 1, 0, -4 },
+ { -4, -9, -3, -1, 6, 3, -6, 6, -10, -4, 14, 8, 2, -3, -12, -19,
+ 0, 11, -20, 1, 6, -2, -27, -6, 10, -17, -14, -17, -9, 8, -8, 3 },
+ { -12, -13, 16, -4, -2, 12, -7, -11, 2, -13, 3, 7, -16, -18, -1, -12,
+ -2, 1, -12, -9, -2, -6, 2, 9, -22, -3, -4, -14, -7, 7, -1, 2 },
+ { -7, -8, -8, 15, 15, 18, 15, 16, -4, -37, 11, 15, -12, -1, -3, 3,
+ 6, 6, 0, -5, -3, -5, 9, 1, 1, -11, -1, -8, -6, 2, 3, 0 },
+ { -6, 7, -5, -12, 13, 10, -18, -4, -3, -21, 6, 16, -15, -7, -12, -9,
+ 1, -12, -1, 10, -2, -1, -3, 4, -4, 1, -16, -1, 12, -9, 5, 9 },
+ { -14, -5, 9, 3, 4, 26, -28, 3, -6, -24, 4, 5, 3, 13, 5, -1,
+ 3, -1, 3, 1, 1, -5, 3, 0, -7, -8, -7, -3, 3, -5, 4, 0 },
+ { -4, 2, -10, -6, 25, 26, -6, 10, -6, -8, 15, 11, -6, -3, 2, -7,
+ 5, 14, 9, -1, 0, -12, 4, -4, -10, 1, -3, 3, -2, -2, -6, -1 },
+ { -10, 8, -15, -10, 19, 17, -8, 0, -3, -7, 7, 5, -13, -1, 7, -7,
+ 1, 13, -12, -13, 17, -12, 1, 26, -18, -3, -5, -6, 4, 5, 8, 1 },
+ { 2, -5, 3, 0, 0, 0, 2, -3, -2, -5, 7, 13, -4, 9, 0, -5,
+ 4, -1, -11, -8, -4, 0, -13, 2, -47, -23, -8, -11, -4, 4, -2, -3 },
+ { -18, -4, 4, 5, -1, 17, -12, -8, 1, -12, 7, 20, -12, 3, -2, -11,
+ 16, 12, -6, 1, -13, -16, -6, -3, -3, -5, 4, -12, -5, -9, 10, 1 },
+ { -11, 0, 4, 7, 7, 8, 3, -1, 3, -19, 32, 8, -19, -8, 2, 4,
+ -12, 15, -16, 3, 1, 9, -2, 1, -2, 8, 5, 6, -4, -1, 11, -8 },
+ { 3, -1, 4, -2, 14, 32, -9, -23, -10, -12, 22, 15, -1, -2, 10, 0,
+ 4, 6, -8, 4, -15, -2, -1, -4, 0, -8, 4, 1, -8, 3, 4, 1 },
+ { -17, -12, 6, -8, 16, 13, -20, -8, -1, -16, 10, 21, -19, 11, -9, -5,
+ 7, 18, -6, 7, -7, -18, 13, 2, -2, 8, -12, -9, 2, 4, -5, 16 },
+ { 4, 0, 17, -11, 12, 7, -12, 5, -1, -25, 30, -8, -7, -6, -4, -7,
+ 9, 8, 7, 3, 3, -16, 8, 0, -2, -2, -18, -3, -4, -5, 1, 4 },
+ { -3, -6, 6, -16, 17, 6, -3, 2, -9, -17, 12, 11, 11, 2, -20, 8,
+ 1, 1, 0, 2, -2, -6, -21, -13, -9, -15, -1, -8, -6, -8, 0, -2 },
+ { -11, -7, 6, -9, 3, 6, 8, 16, 4, -5, 23, 26, -10, -3, 4, 0,
+ 2, 2, -4, 4, -2, -12, 12, 10, -11, 0, -10, -16, 3, 0, 0, -10 },
+ { -5, -16, 10, -6, 27, 13, -3, 4, -2, -13, 15, 5, 2, 5, 3, -4,
+ 13, 12, -11, -7, 0, 1, 11, 12, 2, 13, -15, -8, 9, -2, 3, 8 },
+ { -5, -8, 4, 3, 9, 3, -11, 10, 14, -25, 14, 8, -2, 5, -12, -21,
+ 2, 10, -7, 2, -3, 2, 0, 2, -1, -3, -5, -6, -1, -16, 2, 8 },
+ { -1, 5, 1, -11, 5, 9, -7, 8, -13, -12, 4, 12, -4, 1, -1, -1,
+ 27, 29, 10, 15, 2, -6, -3, 4, -21, 10, -9, -11, -6, -1, -9, -3 },
+ { -6, -3, -1, -6, 11, -5, 0, -2, -5, -31, 11, 3, -1, 5, -3, 4,
+ 5, 7, -10, 5, -10, -13, 4, 12, -15, -2, 2, -7, 1, -9, -3, -10 },
+ { -3, -7, 17, -8, -5, 36, 8, -7, -8, -20, 12, 8, 1, -1, 3, 0,
+ 1, 4, -10, 3, 1, 4, -2, -3, -2, -3, -10, 4, -1, -7, 3, 2 },
+ { -13, -3, -5, 9, 22, 6, -23, 3, -10, -7, 17, 17, 18, -14, -8, -8,
+ 2, 4, -8, 2, -3, -8, 6, 4, -1, 7, 0, 0, -3, 0, -12, -3 },
+ { -3, -10, -15, -3, 9, 3, -23, -9, -13, -18, 12, 13, -2, 0, 1, 8,
+ -1, 2, -7, -12, -5, 14, 2, 1, -22, 6, -10, -8, -9, 28, -7, -14 },
+ { -3, 1, 2, -1, 13, 7, -2, -7, 1, -3, 6, 9, -3, -2, 4, -2,
+ 2, 1, -10, -2, -2, -22, -2, -7, -10, -5, -11, -27, -12, -16, 4, -7 },
+ { 2, -6, -3, 1, 8, 0, -2, 12, -3, -4, 58, 15, -10, -4, -2, 2,
+ -2, 0, -2, -6, 2, 4, -1, 1, -4, 1, -1, -5, -4, -3, 3, 1 },
+ { 10, -1, 0, 5, 21, 7, -14, 6, -3, -16, 15, 17, -16, 13, 3, -6,
+ -4, 6, -12, -5, 1, -4, -7, -8, 2, 3, -6, 6, -1, -8, 5, 4 },
+ { -6, -2, -8, -11, 15, 10, 0, 8, -6, -15, 33, 8, -2, 18, -15, -11,
+ 5, -1, 0, 15, -15, -4, -4, -1, 10, 7, -13, 4, -4, 0, 8, 3 },
+ { -7, -2, 0, -2, 0, -2, -4, -5, -14, -16, 12, 38, 7, 12, 6, -4,
+ 0, -1, 0, 3, -2, -6, 0, 2, -9, 1, 0, -1, 0, -2, 4, 1 },
+ { -8, -4, 18, 1, 14, 5, -12, -3, 20, -17, 5, 19, -11, -8, 11, -3,
+ 3, 9, -7, -8, 9, -17, 2, 15, -10, -11, 5, -5, 7, 15, -6, -2 },
+ { -7, 2, 38, 5, 19, 16, -5, 4, -13, -20, 0, 4, -4, 6, 4, 2,
+ -7, 6, -8, -2, -5, -7, 6, 3, -4, -3, -2, -3, 7, -6, -4, 0 },
+ { -11, -12, 8, -15, -3, 14, -7, -22, -11, 2, 22, 14, -19, 2, -19, -6,
+ 1, 3, -18, 14, 2, -6, -2, -8, -3, -6, 5, -7, -8, -4, 1, 1 },
+ { 8, 7, 25, -21, 12, -6, -5, -4, -10, 6, 0, 10, 1, -12, 18, -5,
+ -15, 4, 1, 14, -1, 5, 8, -7, 1, -7, -3, 9, 10, 1, -1, 0 },
+ { 9, 10, 32, -15, 8, 2, 11, -7, -18, -8, 2, -6, -9, -16, -3, 3,
+ -1, 3, 1, -5, 4, -2, 1, -8, 0, -6, -3, -11, 1, 5, 0, 0 },
+ { 14, 0, 23, -25, 22, 3, 7, 10, 0, -2, 7, 8, 0, 10, 0, 0,
+ 3, 2, 3, -10, 0, 10, 0, -7, 0, 10, -1, -5, -7, 1, -1, 2 },
+ { 12, 0, 25, -18, -5, -4, 13, -10, 3, -6, 7, 21, 0, -16, 3, -10,
+ -6, 5, -7, -3, 2, 5, 3, -6, 4, 9, -8, 12, -2, 3, 2, 4 },
+ { 31, 15, 27, -20, 10, -7, 15, -10, 9, -8, 4, -5, 3, -3, 5, 6,
+ 11, -2, -12, -2, 6, -2, 1, 2, -1, -1, 1, 1, 3, 1, 1, 2 },
+ { 12, -4, 13, -23, 12, -6, 2, 4, -3, 13, 6, -7, 5, -19, -7, 18,
+ 1, -7, 7, 1, 16, -7, 3, 0, 3, 0, -12, 8, -11, 9, 4, 7 },
+ { 29, 1, 3, -22, -5, 6, 0, 12, -14, 11, 1, 6, -3, 4, 6, -2,
+ 4, -13, 12, 1, 1, 3, -11, 9, -10, -1, -7, 16, -11, -1, 3, 9 },
+ { 4, 4, 36, -23, -5, -8, -15, 1, -6, 3, 13, -1, -5, -7, 4, 9,
+ 2, -11, -3, 5, 1, 3, -6, -1, -4, -4, -2, 2, 3, -1, -5, -2 },
+ { 19, 10, 6, -17, 2, -4, -2, -4, -3, 13, 2, 2, -13, -7, -3, -11,
+ 9, -6, 1, -9, -5, 4, -5, -9, -18, -7, -11, 9, 4, -11, 8, 4 },
+ { 16, -3, 9, -16, 18, -2, -12, -16, -11, 11, -18, 16, -13, 6, 2, 8,
+ 3, 8, -4, -16, 10, -11, -1, -3, -8, 5, -9, -4, 9, -4, 0, -3 },
+ { 14, 15, 3, -23, -5, 7, -8, -6, 2, 17, 2, 12, -8, -12, 13, -1,
+ -9, 3, 1, 1, 19, 15, 4, -1, 1, 2, -3, 2, -3, 1, 5, 3 },
+ { 32, 5, -10, -47, -5, -1, 4, 11, -7, 0, 2, -2, 1, -7, 6, -4,
+ 6, 2, -4, -2, 2, -2, 0, -4, 1, -6, -5, 2, -2, -1, -3, -4 },
+ { 20, 8, 10, -21, -7, -9, -16, 12, 1, 4, 6, -5, 9, -11, -7, 4,
+ -11, 28, -3, 2, 4, -6, 10, -8, -5, -5, -9, 9, -2, -1, 6, -5 },
+ { 38, 3, 23, -25, -6, -18, 3, -10, -8, 6, -10, 1, -10, 2, 2, 0,
+ -7, 2, -4, 5, -1, 8, -3, 0, 3, 3, -1, 1, 0, -4, -4, 0 },
+ { 20, 5, 16, -22, 24, -18, 2, -12, -14, -7, -3, 10, 2, 7, -10, 2,
+ -8, 1, 8, -1, 4, 1, 4, -2, 5, -9, -18, -8, -13, 5, -11, 10 },
+ { 14, 8, -12, -16, 9, -11, -3, -6, -25, -7, 6, 5, -7, -16, 10, 2,
+ -7, -1, -9, -3, 16, 4, 3, 3, -3, -3, -15, 13, -3, 4, 13, -7 },
+ { 16, -9, 19, -23, 7, -19, -3, -5, -15, 11, -21, 21, -16, 18, -1, 6,
+ 10, -10, 18, -14, 16, -15, 6, -5, -9, 5, -17, 13, -10, 13, 0, 10 },
+ { 8, -4, 4, -24, 8, -21, -18, 9, -11, 4, -6, 17, 5, -9, -2, -2,
+ 2, 15, -2, -3, -2, 1, 7, -13, 15, -10, -8, -11, 3, 3, -1, -1 },
+ { 14, 17, 6, -32, 5, -17, -2, 0, 15, -1, -5, 16, 1, -5, -2, 9,
+ -3, 8, 4, -2, -2, -4, -3, 1, 0, 7, -3, 4, -5, 0, -7, 2 },
+ { 24, 6, 22, -12, 8, 3, -14, 4, -7, 8, 6, 5, 6, 1, 6, -12,
+ 15, 10, 4, 11, 9, 6, -7, -4, 10, -9, 2, -1, -5, 11, 15, 3 },
+ { 17, 12, 3, -23, 5, -1, -2, 1, -9, -1, -3, 1, 8, 1, -5, 17,
+ 11, 0, -2, -11, 7, 4, 0, -27, -7, 1, 2, -8, 9, 7, 5, 3 },
+ { 12, 10, 12, -10, -4, 5, -1, 2, -24, 5, -8, 2, 6, -17, 19, 5,
+ 12, -2, 16, -7, -6, -14, 4, 1, -3, 13, -16, 5, -1, 4, 1, 1 },
+ { 31, 9, 11, -17, 10, -3, -7, 7, 1, 2, 2, 4, -3, -1, 11, 4,
+ -5, -8, 1, 4, 15, -6, -28, 1, 8, 3, -6, 5, 17, -2, 2, -4 },
+ { 11, 19, 16, -26, 0, -7, -7, 2, -13, -15, -12, 9, -3, 27, 8, 4,
+ -6, 1, 4, -6, 11, -1, -6, -7, -3, 0, -6, 4, -6, -7, -3, -1 },
+ { 10, 18, 16, -32, 19, -9, -4, -3, -7, 8, 8, -3, -11, -2, -6, -16,
+ 13, 13, -6, -1, 10, -2, -2, -9, 0, -3, 9, 4, 11, -2, -6, 6 },
+ { 9, 4, 19, -33, 4, 7, -12, 36, -3, -1, 8, -2, 2, -8, -9, -4,
+ -8, 0, 1, -1, 0, -4, -4, 3, 0, 3, 6, 0, -6, 2, 0, -2 },
+ { 25, 7, 15, -12, 2, -24, -1, 24, -4, 4, 9, 0, -2, -9, 4, 6,
+ 3, 13, -3, 1, 5, -1, -3, -5, -1, 7, -2, 3, 4, 4, 1, 0 },
+ { 19, 6, 8, -20, 9, -9, 5, -4, -13, 7, 11, -3, 5, -13, -9, 6,
+ -11, -1, 0, 4, 11, 26, 3, 6, -7, 12, 6, -3, 1, -9, 7, 1 },
+ { 15, 6, 19, -23, -3, -9, 3, 16, -6, -4, 6, -5, -10, 1, 16, -14,
+ 2, 0, 2, -13, -3, 8, -6, 3, 1, 1, 2, -5, 12, -4, -8, -3 },
+ { 14, 4, 16, -20, 1, 12, 0, 6, -3, 9, 4, 16, 10, -16, 5, 7,
+ 5, -4, -4, -18, -3, -11, -4, 4, -7, 3, 13, 7, 3, 3, 2, -7 },
+ { 22, 3, -1, -30, 18, -3, -9, 9, -2, 11, -16, -2, -14, 12, 0, 4,
+ -5, 4, -1, 3, -20, 12, 4, -10, -2, -2, -12, -12, 10, 6, 11, -3 },
+ { 15, 7, 2, -21, 5, 4, 9, -9, -33, 7, 7, 3, -6, -14, -8, 10,
+ 12, 0, 2, -1, 5, 4, -2, 0, -7, 0, 2, 4, 0, 1, -3, 8 },
+ { -7, 0, 12, 3, 0, -6, 8, -4, 0, 2, 14, -15, 2, -7, -31, -3,
+ 14, 0, 14, -15, -1, -4, -15, 10, 1, -3, 1, 2, 5, 2, -8, 1 },
+ { -2, 5, 1, 0, -3, 3, 3, -6, -1, 2, -4, 1, -19, 0, -11, 18,
+ 11, 10, 21, 5, 6, 2, 10, 3, -6, 0, -2, 13, 5, -1, -2, 9 },
+ { -9, 1, -5, 0, 0, -15, 8, 4, 8, 3, 8, 12, -13, -2, -39, -2,
+ 4, -4, 5, -3, -4, 3, -3, 3, 10, 5, 3, 2, -3, 5, -2, 8 },
+ { -9, 6, 6, -8, 12, -12, 23, -18, 4, -15, -5, 2, -20, 13, -7, 7,
+ 7, -12, 14, -12, 6, 1, 1, -3, -8, 9, 0, 1, -7, 3, 7, -6 },
+ { -18, 13, 4, 3, -10, -30, -10, -6, -14, 1, -7, -4, -35, 5, -25, 11,
+ 9, 8, 19, -4, -7, -3, -18, -8, 1, 5, 10, -4, -14, -9, 3, -4 },
+ { -6, -1, 4, -9, -9, 4, 20, 0, 0, 3, 11, 7, -16, -17, -20, 11,
+ -6, -14, 1, 4, 19, 2, -8, 6, -15, 3, 6, -5, -14, 3, 7, 2 },
+ { 1, 6, -2, -8, -5, -3, 3, -8, 21, 1, 3, 16, -14, -2, -9, -4,
+ 13, -2, 18, 14, 14, 19, -13, 5, -10, 2, -3, 3, 5, 5, 1, -1 },
+ { -1, -5, -6, -2, -11, -7, 5, -4, 5, -1, 0, 3, -3, 2, -19, 18,
+ 16, 4, 14, -22, -2, -11, -22, 1, -1, 11, 1, 2, 11, -10, 7, -12 },
+ { 1, 4, 5, -1, -9, -5, 1, 12, 5, 6, 12, 9, -24, 23, 1, 20,
+ 14, -11, 13, 5, -2, -2, 5, 6, 2, 1, -9, 6, 10, 5, -4, 11 },
+ { -1, -1, 1, 7, -3, -4, 8, -16, 15, -1, -7, 9, -22, -11, -11, 10,
+ 16, 9, -2, 4, 13, 10, 6, 16, 4, 7, 1, -8, -7, -14, -7, 4 },
+ { 1, 3, -6, 0, 15, -9, -4, 0, 4, 6, 12, 9, -6, -5, -22, 17,
+ 7, -11, 15, -5, 1, 3, -19, 0, -15, -3, 16, 5, 5, -7, -11, 12 },
+ { -2, -1, 13, 2, 4, -24, 37, -5, -2, -6, 12, 7, -2, -23, -4, 9,
+ 2, -3, 3, 2, 3, 3, -14, 11, 0, -4, -2, -2, 3, 10, -10, 4 },
+ { 2, 9, 8, -6, -28, 14, 28, -11, 18, -11, 0, 2, -2, 4, -12, 3,
+ 6, 0, 7, -7, -6, 2, 5, -1, -1, -1, 5, 2, 3, 0, -3, 9 },
+ { -7, 14, 5, -10, -3, 7, 4, -5, 7, -8, -7, 4, -12, 14, -16, 25,
+ 3, 0, 1, -5, 12, -10, 0, -10, 0, 12, 12, 17, 12, 10, -1, 0 },
+ { -4, -2, 5, -2, -17, -3, 5, -5, 7, -17, 1, 5, -4, 4, -20, 0,
+ 11, -15, 13, -8, 10, 1, 1, 5, -12, 9, -8, 0, 6, -1, -11, 4 },
+ { -3, 12, 13, -15, -7, -7, 0, 5, 33, 3, 3, -6, -13, -7, -15, 10,
+ 3, 3, 3, -5, 2, 7, -1, 0, -12, 2, 11, -6, -9, 0, 5, 11 },
+ { -8, 5, 10, -7, -14, -4, 13, 0, 18, -3, -6, 7, 1, -6, 0, 21,
+ 8, -7, 10, -8, -3, 17, -9, 0, -5, 1, 4, 8, -3, 11, -5, 0 },
+ { -8, 8, -3, -8, 8, -11, 16, -16, 17, 0, 8, 16, -17, 10, -16, 10,
+ -8, 6, 11, 0, 10, 7, 4, 5, 7, -5, -5, -6, -7, -5, -1, 16 },
+ { -6, 0, 6, 1, -8, -8, 8, -7, -5, -10, -11, 8, -19, 6, -7, 13,
+ 5, -3, 4, -8, 7, -1, -18, 9, 0, -5, 6, 26, 3, 8, 2, 4 },
+ { -2, -2, 23, -2, -20, 2, 7, -7, -6, -15, 3, 9, -19, -2, -10, 7,
+ -2, 7, 9, 11, 0, 4, -4, 6, 9, -2, 4, -3, 4, 3, 2, 8 },
+ { -6, 12, 10, -10, -7, 4, 17, 11, -6, 1, 12, 11, -18, 8, -12, 4,
+ 1, 13, 6, -13, 23, 9, -5, 8, -2, -5, 1, 3, 0, -2, -4, 4 },
+ { 7, 1, 7, -17, -8, 8, -1, -7, 5, -6, 4, -3, -16, 9, -24, 18,
+ -3, 10, 13, -11, -6, -11, -4, 10, 0, 11, 8, 2, 6, -5, -11, 4 },
+ { -4, 1, -5, -10, 0, -3, 9, -2, 4, -1, 1, 5, -41, -10, -7, 4,
+ -3, 3, 1, 0, -12, 4, -3, 0, 2, -1, -2, -5, 3, 2, -7, 5 },
+ { -2, 1, 4, 4, -3, -6, 1, 0, 12, -5, 11, 0, -17, -3, -1, 11,
+ 4, 1, 27, -12, 0, -14, 2, -15, -3, -9, 0, -7, -3, 15, -8, 6 },
+ { -6, 4, 9, 2, 4, 3, 7, -10, 28, 1, -2, 48, 7, 0, -10, 10,
+ 1, -9, 2, -1, 0, 3, -5, 5, -4, -2, 7, 7, 1, 3, 2, 5 },
+ { -3, 3, -1, 3, -9, 0, -1, 3, 2, -6, 39, -14, -12, 5, -19, 21,
+ 7, -6, 4, -1, -4, 0, -4, 1, 0, -9, 1, 10, 0, -2, 0, 7 },
+ { 4, 2, -29, 12, 5, -3, 16, -6, 15, -13, -4, -1, -13, 22, -16, 17,
+ 16, 4, 9, -4, 4, -6, -4, 11, -8, 7, 8, 4, 3, -3, -7, -13 },
+ { 0, 3, 3, -6, -4, 0, 9, 0, 5, 0, 10, 10, 4, -13, -12, 16,
+ 23, -4, -12, -6, -4, 20, 2, 0, -4, 23, 1, 8, 11, -4, -5, 15 },
+ { -6, 4, -15, -9, -1, -19, 12, -30, -17, -4, 1, -13, -13, 4, -3, 26,
+ 5, -25, 11, -14, -6, -13, 0, -7, 9, 2, 8, -1, -8, 1, -8, 13 },
+ { 1, 6, 1, -4, -4, 1, 2, 0, -3, 2, 10, 6, -6, -2, -11, 4,
+ 32, 15, 15, -47, -8, 3, -12, 4, -5, 4, -1, 0, -5, 5, 1, -7 },
+ { 2, -1, 0, 0, -1, -6, 0, -6, 4, -4, 5, 9, -5, 1, -3, 51,
+ 4, -5, 4, -14, -1, -4, -3, 1, -4, -1, 0, 2, -8, 0, 1, 2 },
+ { 0, 4, -2, -7, -2, -9, 6, -8, 11, -3, -6, 3, -11, -8, -12, 8,
+ 11, 5, 19, 3, -24, 19, -14, 11, -5, -18, -8, -12, -5, -4, -1, 4 },
+ { 16, 9, 10, 14, -18, -2, -18, -27, 10, -5, 12, 14, 4, 0, -2, -6,
+ -12, -7, -1, 3, 4, 7, 11, 10, 5, -5, -7, -16, -3, -6, 6, 9 },
+ { 7, 15, -9, 10, -19, 4, -5, -37, -2, -4, 8, 2, 4, -1, 1, 9,
+ -5, -5, -12, 1, -1, -8, 3, -3, 4, 6, 9, 3, 3, -1, 2, 4 },
+ { 13, 17, 3, 9, -7, -7, -15, -17, -8, -13, -4, -8, 19, 2, 16, 25,
+ 7, 15, 2, 16, -5, -6, -10, -9, -7, -6, -2, -7, 7, 2, 4, 5 },
+ { 24, 7, 9, 8, -13, -2, 0, -4, 1, -13, 3, 6, 7, 10, -4, 15,
+ 5, 7, -4, 5, -5, 3, 13, -7, 5, 15, -11, -2, 7, 5, 8, 6 },
+ { 17, 6, -15, 23, -2, -1, -6, -2, 0, -4, 11, -3, 12, 15, 6, -8,
+ -15, 10, -9, 7, -1, -11, 2, -8, -4, 3, 4, -10, 4, 4, 11, 1 },
+ { 21, 12, -3, 6, -8, 8, -11, -8, -5, -5, 3, 7, -1, -5, 12, 15,
+ -10, -11, 3, 15, 8, 4, 2, -15, 0, 14, 1, -8, -1, 3, 10, -7 },
+ { 16, 12, 5, 13, -6, 15, -23, 0, -17, -9, 0, 4, -9, 13, 6, 18,
+ 0, 0, -4, -1, 0, 14, 5, -1, 8, -4, -8, -6, 5, -2, -2, 0 },
+ { 14, 16, -1, 12, -15, -9, -6, -20, 4, 6, 8, 9, 3, 1, -9, -4,
+ -1, -11, 9, 11, -12, 1, -14, -7, 2, -8, 11, 9, -4, 10, 4, -16 },
+ { 13, 10, 3, 7, 0, -8, -33, -6, 4, -4, 19, -2, 14, 6, 5, 7,
+ 6, -3, -1, -10, -10, -9, 4, -3, 5, 9, 2, 2, 10, 9, -2, -3 },
+ { 11, 10, 25, 18, -1, -6, -21, -21, -11, -16, 6, 5, 14, 4, 8, 7,
+ 0, -10, -7, -9, -5, -4, 3, -1, 1, 6, -1, 6, -2, 2, -3, -9 },
+ { 15, 9, 5, 22, -17, 15, -9, 7, 7, -9, 13, 9, 10, -1, 8, -3,
+ -2, 6, 1, 17, 8, -14, 7, -3, 12, 9, 1, 0, 1, -5, 17, -18 },
+ { 25, 19, -17, 12, -4, -10, 1, -13, -19, -7, -3, 9, 6, -2, 3, 1,
+ 4, -2, -11, -14, -1, -7, -5, -9, 7, -1, -3, 4, -5, 1, 0, -1 },
+ { 20, 8, -3, -10, -24, 3, -6, -2, 0, -12, 14, 6, 7, 11, 4, 7,
+ -12, -5, -8, -10, 5, -1, -4, 4, 16, 7, -14, 6, -1, -2, -7, -11 },
+ { 16, 18, 17, 1, -15, -6, -5, -3, -1, -19, 8, -2, 2, 8, 12, -19,
+ -12, 8, 0, -3, -1, -1, 4, -14, 9, -1, -12, -1, -7, 10, -3, 5 },
+ { 18, 12, -7, 7, 0, -3, -13, 0, -1, -4, 9, -2, 6, -1, 0, 1,
+ 15, -21, 1, -8, 25, -19, 13, -9, 2, 12, 5, -7, -3, -1, -3, 1 },
+ { 13, 16, -4, 9, -2, 2, -1, -19, -7, -4, 18, -6, 14, 18, -5, 4,
+ -6, -3, -19, -14, -1, -12, 10, 6, 7, 17, -12, -13, -10, -4, 5, 4 },
+ { 27, 17, 4, 14, -9, -2, -4, -8, 0, -6, 14, -11, -7, 2, -3, -3,
+ -2, -3, -13, 12, 16, 1, -5, -9, -10, -11, -2, 3, -7, 5, 11, -7 },
+ { 7, 17, -16, -2, -14, -28, -7, -8, 15, -10, 7, 15, 8, 17, 13, -1,
+ 4, -7, -12, -11, 0, 0, 2, 3, -3, 7, -6, 6, 1, -16, 1, -2 },
+ { 23, 11, -9, 15, -23, -4, -6, -4, 2, -9, -7, 9, -8, 3, -13, -4,
+ 8, 18, -6, -2, 1, -5, 6, -14, -5, -2, -6, -5, -3, -2, 4, -5 },
+ { 12, 13, 18, 18, -35, 2, 7, -17, 3, -11, 6, 9, -3, -2, 10, -4,
+ 3, 3, -2, -7, 0, 2, -4, 0, -4, 0, -6, 5, 10, 4, -3, -1 },
+ { 19, 11, 1, 20, -14, 4, -9, -13, -2, 11, 0, 17, -1, -1, -1, -1,
+ -5, -8, 0, 5, -1, -8, 5, -1, 3, 2, -12, 21, -2, -24, 5, 7 },
+ { 15, 15, -15, 17, -14, -22, 3, -4, -11, -3, -7, 1, 18, 10, 1, 10,
+ -6, -3, 8, 2, -7, 0, -2, 1, 1, 2, -9, -2, 1, 2, -3, 4 },
+ { 45, 13, 8, 17, -5, 2, -16, 2, 8, -2, 8, -15, 4, 5, -1, 7,
+ -6, -2, -6, 2, -3, 0, 0, -9, -1, 7, 2, 3, -3, -3, -1, 5 },
+ { 1, 18, -8, 18, -12, -10, 3, 4, -22, -12, 20, 8, -3, 9, 2, 10,
+ -10, -3, 9, 3, 6, -3, 10, -1, -3, 2, -2, 4, 2, 3, -3, -18 },
+ { 9, 10, -5, 9, -35, -21, -18, -16, -1, -12, -6, -7, -15, -19, 12, 4,
+ 4, 9, -7, 2, 14, 1, 4, 0, -1, 6, -7, 2, 1, 1, -4, 4 },
+ { 31, 8, -17, 35, -8, 1, -5, -6, -7, -6, 10, -2, -3, 6, 9, 3,
+ -6, -2, 3, 3, 5, -3, 0, 6, 0, 1, -5, -3, -2, -4, -1, 0 },
+ { 18, 4, -8, 7, -8, -15, -1, -16, 12, 18, 3, 19, 2, 4, 8, 8,
+ 0, -5, -8, -12, 10, -5, 0, 1, 0, 4, -3, 16, 11, 11, -2, -6 },
+ { 27, 15, -17, -10, -23, -22, -1, -14, -4, -7, 20, -2, -7, 6, 15, -5,
+ 32, 4, 9, -11, -3, -8, 11, -4, -1, -4, -8, -6, -4, -5, -2, -7 },
+ { 22, 4, -7, 2, -15, -11, -17, -10, 2, 0, 15, 11, 7, 12, -8, 6,
+ -10, -18, -6, -12, 7, 3, 22, 3, -7, 14, -5, -2, -13, -7, -1, -7 },
+ { 18, 13, 9, 24, -4, -19, -9, -11, 13, 8, 2, 4, -1, 8, 14, 10,
+ -12, 0, 0, 5, 10, 5, 4, -1, 5, 1, -1, 11, 2, -4, 0, -9 },
+ { 15, 19, -5, 1, -4, -10, -8, -27, 6, 8, 5, 10, 4, 11, 5, -5,
+ -11, 0, -11, -14, -4, -9, -8, -8, 6, -9, 4, -5, -1, 1, 5, -4 },
+ { 18, 1, -13, 14, -14, 9, -15, -7, 12, 1, 13, -4, -20, 12, 10, 12,
+ -12, 7, 1, -13, 10, -6, 5, -3, 4, 8, 10, -13, -3, -6, 9, -3 },
+ { 19, -14, 5, -8, -6, 2, -5, 5, -3, -1, -28, 11, 18, -6, -4, -2,
+ 11, 14, -43, -42, 9, 2, 20, -23, 6, 32, 0, 5, 0, 6, 9, 5 },
+ { 8, 11, -14, -1, 7, 12, -7, 2, -16, 2, 10, -3, -1, -7, -7, -1,
+ 1, -10, -60, -23, -18, 42, -13, 9, 18, -11, 0, 1, 0, 2, -5, 1 },
+ { -5, -1, 2, 0, 3, -3, 3, -2, -6, 0, -3, -3, 7, 2, 0, -2,
+ -2, 3, -34, -15, 37, 47, 10, 20, 9, 1, 3, -21, -25, -33, -14, 8 },
+ { 5, 6, 2, -2, -2, -2, 6, 5, -5, 7, -3, 1, -5, -13, 9, 3,
+ -17, -19, -2, -79, -12, -7, -8, -6, -2, -2, -1, -1, -7, -13, 6, -1 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1,
+ 0, 3, 4, -87, 6, -11, 16, -9, -1, 8, 0, 5, 0, 1, 2, 1 },
+ { -5, 6, 2, -24, 5, -9, -7, 0, 7, 3, -3, 16, -14, -16, 0, 18,
+ 15, -9, -14, -28, -17, 53, 14, -6, -28, -1, -3, -10, -7, -14, 19, -15 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -3, 0,
+ -13, 0, -53, 3, -22, 63, 19, 16, 1, -11, 0, -3, 0, -3, 0, 1 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1,
+ -1, -6, -43, -43, -2, 65, -13, -4, 9, 1, 1, 2, 1, 0, 0, 1 },
+ { 0, 1, 0, 0, -1, 0, 1, 1, 0, 0, 1, 2, -1, -1, -3, -1,
+ -23, 1, -61, -55, 3, -28, -6, -4, -4, 8, 2, 1, 1, -1, 0, 0 },
+ { 0, 1, -1, 1, -1, 0, -1, 0, 1, -1, 0, 1, -1, 0, -9, -4,
+ -48, -19, -52, -46, 11, -12, 5, -14, 0, -10, 0, 0, -1, -2, -1, 0 },
+ { 0, -3, -1, -4, 2, -1, -7, 3, 1, 3, -1, 1, -3, 0, -7, 0,
+ 3, -7, -61, -51, -4, -21, -16, -21, -11, 14, -7, 8, 3, -5, 1, 2 },
+ { 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, -1, 9, -3,
+ 56, -11, -6, -67, -1, 13, 0, 7, 1, -9, -1, -1, 0, 0, 1, 0 },
+ { 14, 9, -2, 14, -10, -10, 9, -5, 1, -8, -23, 30, 8, -7, 23, 8,
+ 2, 10, -1, -27, -17, 57, 22, 4, -5, 2, -12, -6, 2, -7, -4, -9 },
+ { 1, 5, 12, -2, -2, -3, 2, -3, 6, 0, 4, -2, -8, -6, 0, 16,
+ -15, 29, -55, -29, -24, 29, 3, 10, 6, 13, 10, -5, 21, 11, -14, 5 },
+ { 4, 2, 26, -6, 10, 11, -23, -10, -27, -20, 3, -24, -11, -10, -13, 25,
+ -10, 5, -9, -36, -7, 43, 3, -13, 6, 13, -2, 0, 1, 3, -3, -4 },
+ { -1, 0, -1, 0, 0, 0, 0, -1, 1, 0, -1, 0, 0, 0, -1, 1,
+ -12, 12, -26, -64, -15, 29, 37, -7, -3, -12, -5, 14, 8, -8, -10, -2 },
+ { 19, -4, -11, -16, 8, 14, 5, 19, 3, 22, -11, -21, -1, -6, -11, 11,
+ 10, -24, -23, -40, -8, 20, 17, 5, 13, -6, 3, 14, -20, -8, 3, 28 },
+ { 2, -12, 10, -14, -18, 26, -22, 4, -2, 5, -21, 8, 3, 1, 19, 0,
+ -12, 24, -14, -40, 15, 29, -15, 6, 15, 1, -19, 2, 4, 7, -12, -3 },
+ { 0, 17, 13, 7, -5, -11, 2, -19, 3, 38, -21, -3, -6, -4, 7, 1,
+ 1, -5, -40, -10, -2, 35, 8, 8, -10, -8, -9, 33, 4, 4, 0, -2 },
+ { -2, -12, 7, 29, -24, 2, 16, -1, -7, 16, 10, -2, -2, -2, 13, -2,
+ -37, 15, -22, -40, -11, 33, 10, -1, 8, 10, 6, 8, 9, 0, -12, 2 },
+ { 15, -8, -9, -2, 7, -17, 7, 19, 14, 4, 12, 27, 11, 10, 4, 11,
+ -15, 14, -13, -48, 5, 18, 0, -9, -36, -11, 2, 4, 5, 5, -15, -12 },
+ { -12, 0, 3, 4, 7, -5, 5, -14, -24, -18, -6, -15, -8, -20, 1, -7,
+ -33, -28, -40, -38, -18, -10, -5, 17, -12, 4, 3, -5, 5, -13, 4, -7 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1,
+ -3, -9, -49, -60, -5, 45, -1, 6, 0, 0, 0, 0, 0, 0, 0, 0 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1,
+ -3, -9, -49, -60, -5, 45, -1, 6, 0, 0, 0, 0, 0, 0, 0, 0 },
+ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0,
+ 3, -2, 9, -29, -11, 55, 8, 32, -36, -13, -7, 37, 4, 11, 0, 3 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 4, -1, -39, -4, -30, 63, 28, -17, -6, 10, 7, -14, -9, 11, 9, 7 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
+ 13, -2, -50, -32, 22, 51, 4, 7, 6, 11, -20, -13, 9, -5, 21, -4 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1,
+ -3, -9, -49, -60, -5, 45, -1, 6, 0, 0, 0, 0, 0, 0, 0, 0 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1,
+ -3, -9, -49, -60, -5, 45, -1, 6, 0, 0, 0, 0, 0, 0, 0, 0 },
+ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0,
+ 3, -2, 9, -29, -11, 55, 8, 32, -36, -13, -7, 37, 4, 11, 0, 3 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 4, -1, -39, -4, -30, 63, 28, -17, -6, 10, 7, -14, -9, 11, 9, 7 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
+ 13, -2, -50, -32, 22, 51, 4, 7, 6, 11, -20, -13, 9, -5, 21, -4 },
+ { -8, 2, 1, 22, -31, -6, -25, -3, -3, 1, -15, -11, -2, -3, 4, -13,
+ -9, 15, -18, 37, -7, -37, 12, -13, -11, -25, -10, -11, -22, 7, 16, 7 },
+ { 14, 10, 4, -10, -1, -5, -7, -3, 16, 13, -5, -15, 5, 11, -1, 8,
+ -27, 7, -12, 49, 17, -22, 9, -2, -9, -1, 2, -15, -1, 41, -18, -17 },
+ { -4, -9, -15, -3, 3, 4, 4, 2, 7, -3, -7, -8, -5, 17, -19, -7,
+ 36, -9, -38, 17, 1, -48, 11, -18, -13, -2, -8, 4, -10, -5, 21, 11 },
+ { 15, -13, 4, 2, 1, -5, -2, 1, -10, 7, -1, 3, -6, 0, 11, -11,
+ 8, 20, -17, 51, -17, -41, 2, 15, 4, 8, -2, 16, -32, -1, 17, 6 },
+ { -8, 8, -18, -5, 4, 6, -3, 8, 0, -4, 2, 0, -1, -4, 5, 8,
+ 30, 30, -8, 70, 2, 8, 2, 0, 7, 1, 13, -1, -6, -7, -11, 2 },
+ { -8, -7, 9, -10, -13, 6, -11, -14, 13, 25, -26, 5, 2, -5, -5, 5,
+ -8, 4, 0, 33, 12, -38, -4, 6, 13, 6, 25, 34, -1, 25, -19, -5 },
+ { 18, 3, -17, 4, -8, 7, 20, 1, -1, 5, -5, -2, -8, 8, -35, 15,
+ 24, 43, -5, 51, 5, -12, -3, 1, -2, 3, -3, -3, -9, 8, -9, 2 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+ 2, 10, 24, 76, -2, -22, 11, -1, 4, 33, 4, 1, -1, 1, 2, 0 },
+ { 0, -1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 2, 0,
+ 24, 13, 32, 70, 26, 5, -21, -9, -6, -15, 2, -2, 2, 4, 1, 1 },
+ { 5, -4, -11, 4, -4, 22, 10, -2, 13, -11, -4, -21, -17, 0, -7, 4,
+ 10, -34, 11, 52, 2, -46, -5, 0, 0, -1, 2, 4, -9, 1, 1, -7 },
+ { 0, 1, 1, 0, -1, 0, 1, 0, 1, 1, 0, 1, 0, 0, -3, 1,
+ -8, 9, -1, 64, -13, -61, -3, 3, -5, 10, 1, 3, -1, -1, -1, -1 },
+ { 0, 1, 0, -1, 0, -1, 0, 0, 1, 0, 0, 0, 1, 1, 2, 1,
+ 10, -2, -31, 79, -10, 27, 0, -1, 3, 8, 1, 1, 0, -1, 0, -1 },
+ { 3, 12, 10, 26, -19, 10, -9, 6, -4, -15, 10, 3, -16, 6, 11, -19,
+ 3, 10, 18, 44, 5, -30, 5, -9, 21, 4, 20, 10, 14, -25, 8, -17 },
+ { 0, 0, 0, 1, -1, 0, -1, 0, 1, 0, 1, 1, 0, 0, -6, -2,
+ 8, -8, 13, 69, 26, -19, -25, -17, 16, 6, -12, 22, 2, -6, 9, 5 },
+ { 0, -1, 0, 1, 0, -1, -1, 0, 0, 1, -2, 1, 0, 0, -4, -1,
+ -34, -15, -33, 56, 9, -42, 9, 10, 6, 9, -8, -11, 0, -6, 15, 5 },
+ { 10, 2, -14, -3, -15, -35, -1, 7, -18, 14, 8, -1, -15, -26, 6, -15,
+ -18, 22, 9, 33, 0, -32, -9, 3, -11, 7, 4, -1, 5, 30, 9, 1 },
+ { 4, 15, 0, 6, -5, -11, 9, 6, 6, 6, 14, 2, -1, 10, -24, -25,
+ -2, -4, -1, 37, 2, -29, 14, -9, 22, 17, -2, 33, 10, -25, 11, -11 },
+ { 0, 5, 2, 18, -12, 21, 22, 33, -7, 21, -9, -7, 7, -15, -7, 16,
+ 7, 0, -14, 44, 10, -25, 5, -4, 15, -8, 10, -4, 5, 9, -1, 16 },
+ { 3, 13, 12, 12, 8, 25, -23, 8, -22, -3, -18, -8, 15, 12, 9, 19,
+ 0, 0, -9, 49, -27, -15, -9, -15, 12, -8, -16, -7, 13, 5, 13, 2 },
+ { 12, -6, 7, -2, 20, -9, -14, 12, 13, -5, -17, 22, -8, -4, 2, 7,
+ -13, -2, -15, 43, -5, -30, 27, 4, 10, -27, 5, 27, -10, -10, -18, 0 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+ -1, 10, -18, 70, -2, -52, -1, -7, 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, 10, -18, 70, -2, -52, -1, -7, 0, 0, 0, 0, 0, 0, 0, 0 },
+ { 15, -13, -20, 16, 2, 13, 5, -11, -8, -5, -3, 2, 24, -23, 30, -7,
+ 11, 30, -15, 43, 5, -15, 15, -3, -14, 1, -23, 8, 3, 9, 4, -11 },
+ { 0, -1, 0, 1, 0, -1, -1, 0, 0, 1, -2, 1, 0, 0, -4, -1,
+ -34, -15, -33, 56, 9, -42, 9, 10, 6, 9, -8, -11, 0, -6, 15, 5 },
+ { 10, 2, -14, -3, -15, -35, -1, 7, -18, 14, 8, -1, -15, -26, 6, -15,
+ -18, 22, 9, 33, 0, -32, -9, 3, -11, 7, 4, -1, 5, 30, 9, 1 },
+ { 4, 15, 0, 6, -5, -11, 9, 6, 6, 6, 14, 2, -1, 10, -24, -25,
+ -2, -4, -1, 37, 2, -29, 14, -9, 22, 17, -2, 33, 10, -25, 11, -11 },
+ { 0, 5, 2, 18, -12, 21, 22, 33, -7, 21, -9, -7, 7, -15, -7, 16,
+ 7, 0, -14, 44, 10, -25, 5, -4, 15, -8, 10, -4, 5, 9, -1, 16 },
+ { 3, 13, 12, 12, 8, 25, -23, 8, -22, -3, -18, -8, 15, 12, 9, 19,
+ 0, 0, -9, 49, -27, -15, -9, -15, 12, -8, -16, -7, 13, 5, 13, 2 },
+ { 12, -6, 7, -2, 20, -9, -14, 12, 13, -5, -17, 22, -8, -4, 2, 7,
+ -13, -2, -15, 43, -5, -30, 27, 4, 10, -27, 5, 27, -10, -10, -18, 0 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+ -1, 10, -18, 70, -2, -52, -1, -7, 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, 10, -18, 70, -2, -52, -1, -7, 0, 0, 0, 0, 0, 0, 0, 0 },
+ { 15, -13, -20, 16, 2, 13, 5, -11, -8, -5, -3, 2, 24, -23, 30, -7,
+ 11, 30, -15, 43, 5, -15, 15, -3, -14, 1, -23, 8, 3, 9, 4, -11 },
+ { 16, -18, 7, -4, 31, -15, -9, -13, 20, -12, -6, 0, 12, -6, -2, 4,
+ 3, -3, -1, 0, 1, 3, 3, -2, 1, 6, 4, 0, -3, 2, -5, 1 },
+ { 38, -5, -13, -4, 8, -15, 11, 1, 2, -4, -1, 9, 13, 4, -12, -7,
+ 0, -2, 7, 2, -6, -2, -3, -2, 3, -4, 6, 15, 1, 1, -11, -2 },
+ { 47, -22, 9, -26, 3, -5, 2, -7, 4, -2, 2, -2, 3, 0, 3, -4,
+ 3, -3, 2, -3, 7, -3, -1, 1, 1, -5, 5, 0, 2, -5, -3, -2 },
+ { 14, -16, 2, -6, 7, -2, -7, -4, -4, -7, 14, -3, 7, -19, -14, -17,
+ -29, 6, 26, 16, -5, 13, -4, -1, 21, 14, 1, 3, -6, 0, -7, -1 },
+ { 29, -11, 5, -3, 4, 11, 4, -10, 1, -22, -3, -10, 5, 4, 2, 8,
+ -2, -7, -12, -12, -8, -3, -18, -2, -9, -5, -1, -3, 2, -14, -14, 7 },
+ { 28, -12, 5, 3, 9, -7, 0, -2, 2, 1, 4, 0, -7, -3, -2, 4,
+ 4, 14, 8, -1, -4, 14, -7, 17, -2, -2, -9, 2, 19, -7, 9, -8 },
+ { 31, -18, -22, 8, 15, -5, -10, -15, 1, 10, 6, 7, 6, -8, 2, -1,
+ 12, -3, 3, -1, 1, 5, -6, -4, 0, 1, 7, -10, -2, 4, -3, -4 },
+ { 53, -30, -4, 12, 2, 3, -3, -3, 0, 1, 6, 5, -5, -4, -7, 1,
+ 0, 2, 1, 3, 1, 5, 0, 2, 2, -1, 0, 4, 2, 0, -2, 0 },
+ { 27, -18, -3, -2, 4, -8, 3, -2, -11, 2, 10, -8, -8, -4, 0, -2,
+ 8, 0, 9, 0, -16, 11, 1, -6, 13, -3, -10, -13, -15, 25, 1, 0 },
+ { 35, -5, -1, -8, 23, 11, -14, -3, 2, -2, 8, -6, 17, -2, 7, 0,
+ -2, 10, -17, 13, -2, -2, 11, 11, -14, 2, -2, -3, -8, -1, -12, -5 },
+ { 29, -9, 7, 3, 2, -10, 0, 3, 9, 0, -3, 5, 1, -10, 10, -5,
+ 3, 6, -20, -9, -6, -4, 1, 0, 12, 17, -8, 9, 3, -1, -9, 0 },
+ { 15, -16, 18, -19, 16, -15, 17, -18, 13, -16, 17, -14, 15, -9, 13, -17,
+ 9, -7, 4, -5, 3, -4, -3, 0, -6, 7, -9, 7, -2, 7, -9, 9 },
+ { 21, -10, 7, -2, 12, -7, 13, -17, 11, -2, 20, 3, 5, -11, -6, -6,
+ -15, 0, -9, 5, -11, 7, -1, 7, 8, -10, -9, 3, -5, 9, -8, -2 },
+ { 23, -22, 15, -5, 16, -4, -3, -12, 9, 3, -1, -2, -8, 2, -2, -16,
+ 3, 4, -2, -6, -7, 12, -8, 2, -14, 2, -7, 11, -2, 6, -4, -1 },
+ { 34, -17, -4, 8, 4, -6, 1, 8, 4, 16, 3, 6, 12, -1, -1, -15,
+ 6, 4, -7, -6, 6, 0, 2, 1, -2, 2, 3, 3, -3, -2, 8, -6 },
+ { 18, -18, 2, -2, 10, 1, 18, -23, -3, -10, 0, 4, 20, -19, -3, -4,
+ 2, 8, 6, 1, -3, 1, 1, 3, 5, -1, -11, 3, -7, 5, -1, 1 },
+ { 15, -14, 2, 3, 10, -8, 12, -13, 13, -15, 6, -8, -4, -10, 14, -9,
+ 24, 2, -7, -18, 13, -11, 8, 14, -6, -2, 3, -1, -4, 7, -7, -4 },
+ { 20, -12, 13, 5, -1, -10, 15, -6, 8, -1, -3, -10, 17, 0, -6, -19,
+ 2, -1, 8, -3, -16, 0, -3, 2, -2, 0, 8, -9, 0, 1, -10, -9 },
+ { 32, 0, -9, -5, -1, 5, 13, -11, 8, 3, 11, -11, 0, -8, -2, -14,
+ 7, 10, 6, -5, 1, 10, 2, 12, -10, 4, 4, 6, 4, 0, -7, -10 },
+ { 16, -14, 10, -7, 11, -11, 11, -11, 18, -13, 8, -15, 16, -11, 13, -9,
+ 8, -7, 12, -11, 7, -6, 3, -5, 9, -5, 4, -1, 7, -4, 8, -3 },
+ { 24, -27, -1, 5, 8, -5, 12, 7, 4, -3, 3, -1, -9, -11, -13, -5,
+ 10, 0, -13, 7, 1, -5, 4, -9, 7, -3, 13, 2, -5, -3, -17, -2 },
+ { 23, -19, 15, 1, -10, -18, -12, -6, 8, -3, 12, 0, -12, -10, -4, -4,
+ 8, -10, 4, 2, -2, -8, 13, -3, -2, -6, 2, -3, 5, -2, 2, 11 },
+ { 25, -12, 4, 2, 24, -3, 3, -6, 14, 11, 0, -21, -3, -3, 1, -8,
+ 7, 0, 0, 3, 3, -6, -7, 6, 2, 1, -4, 5, -1, 10, -2, 9 },
+ { 24, -8, -6, 7, 16, -12, 13, -1, 11, -21, 2, -6, 3, -12, 0, 9,
+ 4, 11, -7, 1, 4, 1, -8, 3, 3, -6, 3, 3, 0, -8, 8, 4 },
+ { 25, -21, 13, 14, 13, -18, 4, -3, 0, -5, -4, 5, -3, 0, 4, 12,
+ 7, 3, 5, -5, 2, -2, 3, -10, 2, -9, -15, 6, 1, 7, -5, 1 },
+ { 23, -16, -2, 10, 4, -1, 3, 1, 32, 3, -5, -2, 9, 10, -1, -4,
+ -6, 2, 9, -1, 14, 12, -6, -1, -17, -2, -4, -9, -7, -6, -8, 3 },
+ { 50, -8, 5, 2, -11, 10, 0, 0, 6, -3, 7, 0, -3, -2, -3, 0,
+ 6, -4, 2, -5, -9, 0, 3, 10, 1, -7, -2, -3, -6, -9, 1, -2 },
+ { 28, -17, 0, -2, 2, -9, 1, 5, -4, -1, 0, 0, 19, -27, 5, -12,
+ 7, -14, -3, -6, 10, -2, -4, -2, 4, -5, -2, -7, 1, 7, -9, 4 },
+ { 22, -19, -6, -6, 3, -22, 3, 5, 20, -8, -14, -5, 1, 1, 20, 2,
+ 16, 6, 3, 14, 4, 3, 5, 1, 5, -7, -10, -6, 3, -6, 1, -14 },
+ { 29, -14, -8, 13, 8, -10, -6, 4, 4, -6, 5, -7, 1, 12, 14, 11,
+ -7, 1, 2, -9, -11, -9, 0, 4, -1, 7, 10, 4, 4, 20, -1, -11 },
+ { 18, -9, 4, 1, 7, -29, 12, 1, -1, -9, -2, -1, -2, 2, 9, -8,
+ -13, 5, 4, -13, -4, 2, -5, -7, -6, 14, -10, -34, -3, 1, -3, -13 },
+ { 38, -9, 24, 8, 11, 4, -6, -11, -2, -12, 1, 1, -11, -8, -5, -2,
+ -15, -8, 8, 0, 1, -7, 5, 4, -1, 8, -2, 11, -3, -1, -5, -5 },
+ { -20, 11, -4, 24, -11, 1, 15, 4, 0, -28, -10, -1, 10, 10, -6, 5,
+ -6, 2, 7, -2, 1, -2, -6, -3, -7, 1, 2, 12, -1, 7, 0, -2 },
+ { -9, 10, -23, 27, -4, -17, 20, -6, 14, -17, 5, -1, 5, -9, -7, 5,
+ -6, 4, -2, 9, 0, 8, 0, 1, -3, -3, -5, -8, 5, -2, -2, 12 },
+ { -10, 19, 4, 9, 1, -16, 17, -2, 9, -29, -16, -11, -4, 7, -5, 4,
+ -1, -3, 3, 2, 3, -4, 5, -12, -2, 6, 5, -4, 4, 1, 4, 10 },
+ { -20, 10, -24, 14, -5, 11, 9, 0, 16, -20, 10, -5, -6, -6, -1, 2,
+ -4, 5, -16, 8, -2, 5, 5, -11, 9, -11, 4, -11, -1, -1, 4, 3 },
+ { -9, 11, 3, 19, 24, 4, 5, -14, 30, -17, -4, -2, -17, 7, 2, 3,
+ 1, 3, -7, -4, 2, -3, 1, 4, -1, -1, 3, -12, -2, 3, -3, 10 },
+ { -19, 18, 11, 19, 19, 19, 10, 4, 13, 6, 5, 4, 8, 3, -2, 12,
+ -6, -2, 7, -6, 15, 12, 16, 16, 18, -3, -4, -20, 0, 10, -9, -3 },
+ { -21, 9, 20, 12, 0, -3, 5, -9, 15, -13, 5, -5, -6, 24, 2, 9,
+ -5, 2, -7, 2, 5, 7, -5, 2, 15, 3, 1, -1, -4, -2, 7, 0 },
+ { -18, 16, 13, 15, 2, -10, 14, -11, 4, -11, 5, 12, 12, 20, 8, 30,
+ 2, 11, -9, 7, 0, -3, -16, -5, -6, 5, -4, -21, 0, 5, 6, 1 },
+ { -26, 8, -13, 9, 6, -10, 2, -11, 7, -4, 6, -19, -11, -6, -12, 16,
+ 0, 5, -7, 8, 5, 6, 17, -9, 10, -10, 5, -3, -11, 2, 4, 10 },
+ { -11, 17, -3, 22, -5, 18, 3, 1, 4, -5, 14, -27, 5, -7, -4, -5,
+ -10, 11, 1, 15, 1, 1, -6, -5, 10, -22, -7, -7, -15, 13, -4, 5 },
+ { -17, 14, -7, 13, 3, 0, 13, -6, 9, -14, -22, -1, 1, 19, 14, -3,
+ 4, -13, -13, 2, -4, 8, -2, -2, 13, -12, 13, -12, -7, -5, -3, 6 },
+ { -17, 17, -1, 33, 6, 3, 9, -16, 3, -14, -8, 6, -17, 8, 3, 13,
+ 8, -6, 3, 1, -2, 0, -2, 8, 4, 9, 13, -10, 4, -17, 0, -6 },
+ { -20, 7, 7, 21, 1, -3, 7, -3, -2, -12, 9, -7, 2, -3, 14, 1,
+ -1, -7, 12, -10, 5, -20, 11, -2, 0, -24, -17, 6, 6, -4, 3, -1 },
+ { -8, 10, 6, 7, -1, -6, 28, -6, 10, -33, 1, -20, 0, -12, 10, 1,
+ -6, 8, -3, -1, -10, 8, 5, 0, 10, -2, 8, 16, -5, -3, -7, 4 },
+ { -17, 13, 3, 15, 1, -5, 27, -5, 6, -6, 12, 2, -4, 8, -1, -3,
+ -2, 12, -15, 3, 4, 1, 2, -9, 0, -16, -21, 2, -4, 16, -7, 4 },
+ { -15, 20, 8, 17, 5, -14, 15, -11, 21, -11, 13, -13, 2, -15, -13, 1,
+ -5, 5, 2, 10, -9, 4, -1, 3, 2, -4, 13, -5, 1, -4, 5, -3 },
+ { -21, 8, 2, 16, -1, 2, 15, -16, 13, -12, -12, -7, -8, 2, -7, 11,
+ -8, 5, 2, -7, 16, -4, 1, -7, 3, -15, 6, -5, -8, 2, -8, 5 },
+ { -15, 17, -6, 3, -3, 3, 9, -7, 14, -23, 11, 1, -1, 4, 7, 6,
+ -1, -14, 7, 6, -8, 5, 1, -15, 10, -9, 2, -3, -1, 4, -10, -4 },
+ { -10, 18, 3, 11, 1, 4, 14, -14, 7, -4, 15, -10, 10, -11, 10, -4,
+ 5, -14, 10, 4, 15, -12, 15, -13, 20, -15, 14, -15, 8, -11, 4, -6 },
+ { -7, 23, 2, 20, 7, 8, 19, -5, 9, -16, -8, -17, -5, 1, 5, -6,
+ -8, 1, -6, -4, 10, 6, 6, 2, -11, -4, 0, 2, 4, 7, 9, -4 },
+ { -15, 20, -5, 22, 11, -8, 9, -5, 10, -13, -8, 8, 2, -2, -3, 7,
+ 6, 10, 1, 2, -5, -9, 1, 10, 16, -22, -7, 0, 7, 7, 6, 1 },
+ { -26, 19, -5, 3, 5, 25, 18, -5, 9, -14, -8, -6, -2, -6, 2, 3,
+ -8, -2, -7, 7, -3, 7, 3, 4, -8, 0, 1, -8, -4, -2, -2, 1 },
+ { -20, 14, -10, 6, -3, 7, 8, -32, -2, -7, -2, -10, 16, -12, -9, 15,
+ -2, -5, -6, 2, -7, 5, 9, 1, 6, -7, -1, 0, -2, -4, -7, 3 },
+ { -14, 16, 4, 11, -8, 1, 23, -4, 17, -13, -10, 1, 12, 9, 12, -4,
+ 7, -1, -1, 5, -8, -6, 3, 3, -6, -3, -18, 0, 18, 20, 4, -2 },
+ { -33, 19, -10, 30, 15, 2, -3, -1, -4, -14, 7, -7, -1, 7, -8, 9,
+ -1, -3, -5, 2, 2, 4, 0, 5, 0, 0, 2, 3, 3, -3, -3, 4 },
+ { -6, 20, 0, 5, 17, -10, 18, -17, 9, -16, 4, -13, -6, 2, -14, 14,
+ -28, 9, -12, 25, -4, 7, 7, -8, 6, -6, -2, -10, 2, -11, -1, 2 },
+ { -12, 14, 12, 52, -3, 5, -5, 4, 8, -13, 2, -5, -4, 2, -2, -1,
+ -2, 3, 3, 5, 2, 3, 0, 1, -5, 2, -4, -3, 1, -5, -2, 0 },
+ { -13, 6, 9, 24, 0, 8, 14, -15, 18, -9, -11, -8, 3, 15, -2, -4,
+ -9, 4, -3, 12, 14, -13, 11, -4, 2, -4, 0, -6, -6, -6, -14, -1 },
+ { -10, 28, 3, 12, 9, 3, 11, -28, 6, -11, -7, 4, 0, 7, 8, -9,
+ 0, -6, 0, -16, 4, 7, 4, 4, 7, 3, 4, -7, 0, -3, -10, 6 },
+ { -11, 14, -2, 19, -1, -1, 7, 9, -2, -27, 10, -14, 15, -4, 12, -4,
+ 2, -2, -6, 12, -6, 0, -5, -4, -5, 1, 3, -11, 5, -9, 3, -8 },
+ { -18, 7, 13, 16, -4, 3, 9, -10, 10, -10, -3, -22, -4, -12, 3, -16,
+ 0, -3, -16, 8, -11, 1, 10, -7, 15, 3, 0, -1, -13, 8, 1, 6 },
+ { -20, 10, -10, 10, 8, -1, 6, 0, 16, -12, 9, -10, -1, -5, -4, -13,
+ 13, 16, -8, 12, -2, 14, 18, 13, 0, -16, 2, -5, -5, -5, -4, 3 },
+ { -14, 5, -7, -17, 5, -13, 23, 20, -4, -1, 1, -6, 13, 5, -1, 4,
+ -14, -2, -7, 8, 3, 2, 2, -7, 2, -1, 4, 7, 3, -9, -1, -5 },
+ { -19, 3, -24, -28, -9, -7, 19, 3, 2, 19, 7, 5, -13, 8, -15, -17,
+ 3, -11, 4, 13, 3, 2, -1, -3, -4, -4, 2, 0, -5, -6, 6, 2 },
+ { -17, 18, -30, -20, -2, -3, 1, 15, -1, -11, 6, -4, 11, 11, -4, -5,
+ -10, 0, 0, 1, 3, -7, 8, 2, 5, 1, 5, -5, 1, 6, 4, 1 },
+ { -6, 1, -30, -25, -1, -8, -2, -9, -17, 16, 3, -1, -2, -9, -6, -7,
+ -3, 12, 6, -4, -10, 0, 10, -8, -6, -5, -3, -11, -4, 0, -1, -3 },
+ { -1, -1, -34, -28, 1, -10, 2, 9, 4, 16, 2, 6, 14, 17, 0, 7,
+ -4, 4, 4, 4, 0, 1, -1, -5, 8, 1, -4, 1, -9, -2, 5, 6 },
+ { -11, 14, 1, -31, -7, -24, 9, 7, 6, 5, -13, 1, -1, 3, 4, -1,
+ -2, -8, -6, 3, 5, -4, -6, 7, -2, 5, 3, 3, 0, 0, -5, 2 },
+ { -25, 8, -11, -18, 1, -4, 8, -3, -4, 15, 6, -5, 8, 2, 3, 4,
+ -4, 5, 6, 8, -7, 6, 1, -11, -15, -13, 9, -4, -14, 10, 12, 7 },
+ { -20, 11, -15, -25, 3, 4, 18, 13, -4, -5, -9, -1, -5, -2, -2, -7,
+ 16, 5, -4, -5, -7, -2, -3, -9, 11, -2, 0, -7, -17, -6, -11, 6 },
+ { -11, 18, -5, -20, -15, -3, 9, 11, -20, 12, 5, 5, 11, -3, 7, 1,
+ 10, -6, -3, -3, 3, 3, 14, -7, 10, -17, 9, -11, -2, -6, 7, -12 },
+ { -20, 8, -14, -17, -9, -13, -3, 0, -27, -14, -3, -14, 4, 3, 6, -6,
+ 7, 4, 23, 9, 11, 9, 3, -4, 9, 2, 4, -1, -6, 1, -8, -11 },
+ { -9, 14, 2, -37, -7, 13, 6, -11, -6, 9, 18, -11, -6, 2, 12, 4,
+ -1, 3, 1, -2, -2, 1, -9, -4, -2, -3, 3, 5, -6, 0, -2, -8 },
+ { -29, 8, -1, -13, -2, 8, 23, 2, -10, 7, 13, -6, -5, 11, 13, 0,
+ -10, -13, 11, -12, -10, 6, 4, 6, 4, 3, 6, -5, -9, -2, -1, 3 },
+ { -18, 6, -10, -55, -4, -11, -2, 0, 1, -3, -9, -6, 3, -2, -1, 6,
+ 3, -1, 3, 1, -4, -7, -2, 6, 3, -2, -1, -3, -2, 0, 4, 1 },
+ { -14, 5, 3, -21, -8, -16, -4, -2, -11, 27, 15, -20, 3, 0, 1, 1,
+ 2, -5, -5, 4, 1, -9, 5, -3, 3, 0, -4, -2, -11, -4, -3, 7 },
+ { -17, -1, -9, -17, -8, -18, 12, -13, -9, 13, -3, 3, 3, -3, 1, -2,
+ 0, 16, -9, 6, 12, 9, 5, 11, 2, -15, 1, -4, -16, 7, -4, -12 },
+ { -18, 8, -6, -11, -8, -7, 13, 7, 1, 6, 8, -1, 21, -4, 14, 15,
+ 18, -4, -3, 15, 0, 9, 4, 7, 3, -1, 9, -2, 0, 7, -8, 2 },
+ { -10, 7, -18, -29, 3, 12, 12, 9, 11, 4, -1, -15, 1, -1, 8, -2,
+ -2, 10, -15, -1, 0, 6, 12, -6, -1, 10, -6, -3, -11, -4, 9, -6 },
+ { -14, 14, -9, -21, -12, -2, -1, -7, -5, -10, 5, -8, 0, 6, 9, -11,
+ 11, -3, -5, 3, 8, 15, -2, -4, -22, 4, -6, 12, 2, 13, 6, -7 },
+ { -12, 11, -5, -29, -25, 4, 12, -13, -11, -7, 4, 2, 2, -5, 5, 8,
+ 7, -5, -5, 6, 3, -10, 1, -6, 6, -6, -5, -1, -2, -4, 7, 6 },
+ { -15, 11, -5, -16, 0, -13, 26, -23, -6, -3, 5, -2, -2, 21, -6, -3,
+ -5, -1, 6, -1, 0, -13, 2, -3, -9, -1, -4, -3, 5, -4, 12, -16 },
+ { -9, 9, -1, -17, -3, -6, 12, 6, -18, -2, 11, -14, -6, 3, 14, -12,
+ -11, -5, 14, 2, 5, -8, -4, -11, 2, -5, 16, 6, -7, -4, 8, 13 },
+ { -13, 5, 3, -28, -14, 0, 6, 23, 5, 4, -1, -17, 1, -3, 0, 0,
+ 5, 4, 0, -18, 14, 10, 4, 2, 5, -2, 4, -3, 2, 0, 2, 0 },
+ { -15, 4, -13, -16, -3, -12, -2, 2, 7, 10, 9, 3, 11, 4, 23, 14,
+ 9, 16, 4, 1, -12, -3, 4, -7, -15, -7, -10, -14, -6, -8, -1, -6 },
+ { -7, 10, -5, -10, -3, -13, 16, -1, -12, 7, -3, -12, 2, 13, 13, 2,
+ 17, 15, -13, 1, -5, -2, 3, -1, 1, -3, 6, -3, -12, -16, 7, -7 },
+ { -11, -5, -12, -30, -6, -22, 1, 4, -6, -3, 12, 6, 7, 0, 16, 6,
+ -2, 0, -22, -2, -9, 2, -13, 8, 6, -8, 4, -7, -1, -6, 4, 6 },
+ { -14, 5, 1, -27, -4, 2, 1, 14, -11, -7, -8, -4, 1, 8, 0, -6,
+ -13, 11, -12, -7, -5, 1, 10, 7, 3, -2, 0, 6, -8, 2, 10, -1 },
+ { -10, 10, -25, -13, -20, -4, 19, 3, 13, 5, 5, 7, -8, 2, 4, 2,
+ 3, -1, -1, -9, 14, 10, 9, 14, 3, 3, -6, 0, -5, 4, 1, -1 },
+ { -9, 15, -18, -17, 4, -11, 6, 7, -12, 8, -1, -11, 2, 3, 7, 16,
+ -3, -9, 7, -12, 23, 0, 6, 7, -14, -9, 8, 1, -2, 6, -2, -1 },
+ { -6, 9, -16, -26, -14, -11, 9, -6, 5, -2, 13, 17, 21, 7, 18, -19,
+ 6, -23, -2, -15, -2, 2, -10, -8, 2, 1, -2, 4, -3, -4, -5, -4 },
+ { 0, 6, -5, -28, -17, -32, 2, -10, 11, 3, -5, 9, 10, 3, 11, 11,
+ -3, 12, -2, 2, 4, -6, 9, -4, -4, -4, -4, -9, 2, 0, 2, 4 },
+ { 0, -8, -18, -34, -9, -7, -4, -11, 10, 15, 11, -1, -8, 15, 6, -13,
+ 9, 2, -4, -12, 0, -1, 19, 12, 6, 5, 0, -3, -10, -12, 3, -5 },
+ { -10, 6, -9, -17, -12, -11, 9, -6, 11, 11, 18, -7, 0, 16, 4, 2,
+ -6, 3, -12, -1, 0, 1, -5, -22, -2, -12, 0, 6, 17, 5, 5, 6 },
+ { 12, -5, 7, 1, -5, -2, -1, 2, 2, -4, -3, -3, -3, -2, -29, 11,
+ 5, -13, -73, 24, 12, 4, -14, -10, 5, 1, 0, -11, -7, -7, 7, 3 },
+ { 10, -3, -1, -3, 4, -11, -5, -2, -8, 7, 9, 2, -8, -6, 6, 7,
+ 21, 17, -54, 47, -14, -10, 14, 19, 13, 21, -4, 3, 1, 2, -4, 2 },
+ { -12, 4, -16, -12, 5, -9, -4, 19, -7, -22, -22, -17, 3, 0, -6, 8,
+ 23, -4, -55, -28, 2, -26, 2, 1, 4, 0, -13, 6, 0, 10, -7, -11 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -1,
+ 35, -1, -67, -35, -24, -24, -6, 2, 2, -2, 1, 3, 2, 0, -1, 1 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 5, 0,
+ 41, -4, -73, -15, 18, 4, 17, 8, -1, -16, -1, -2, 1, 0, 0, 0 },
+ { -4, -4, 4, 6, -1, 2, -16, -10, -15, -10, 21, -2, -6, -2, 14, -7,
+ 10, -5, -55, 34, -12, 11, -13, -2, 2, 28, -26, 0, 7, 4, 21, -7 },
+ { 2, 1, 15, -22, 10, -3, 14, -6, -2, 15, -2, -7, 20, 6, -15, -7,
+ 23, 10, -60, 8, -4, 29, -22, 2, -13, 9, -10, 12, -1, -3, 4, 7 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -1, -2, 11, -5,
+ -21, -11, -60, -27, -17, -39, 6, 36, 0, -8, 2, 2, 0, 0, -2, 3 },
+ { 2, -5, 9, -17, -1, 2, -3, -6, 8, 12, 7, -6, -33, -11, -14, -40,
+ 10, 36, -46, 0, -19, 5, 0, -10, 3, 12, -6, -8, 6, -12, -7, 1 },
+ { 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, -1, 0, 1, 0, -2, 0,
+ 4, -2, -87, -3, -2, 2, -2, 20, 2, 6, -1, 6, 0, 0, 2, -1 },
+ { 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, -1, 0, 0, 1,
+ 1, 7, -76, 41, -7, -24, 0, -6, 3, 6, 0, -2, -1, 1, 0, 0 },
+ { 0, -3, 4, 2, 3, 2, 2, 0, 3, -1, 4, 0, -1, 4, -2, -4,
+ -32, -11, -64, -29, -9, -43, 2, -11, -1, -7, 0, -4, -2, -2, -2, 2 },
+ { 10, -20, 3, -3, 13, 13, 0, -4, 2, 7, -8, 7, -2, 2, -20, -20,
+ -19, 3, -47, -18, -16, -6, -15, -42, -17, 14, -6, 8, 12, -10, 11, -12 },
+ { -3, -2, -2, -1, -1, 4, -3, -1, -6, -2, 3, 2, -3, 6, -1, -9,
+ 10, 13, -68, -9, 26, 3, 5, 3, -21, 10, -15, 21, -22, 19, 11, -14 },
+ { 1, 5, 18, -19, -29, -13, -2, 18, -10, 20, 2, 10, -10, 11, 1, 8,
+ -16, -17, -41, 10, -14, -25, 0, -14, -19, 17, 7, -12, 14, -11, 14, 5 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -1, -43, 5,
+ 6, -12, -48, 19, 8, -38, -8, -3, 22, -21, -10, 15, 20, -9, -5, 8 },
+ { 0, 0, 0, 0, -1, 1, -1, 0, 0, 0, 0, 0, 0, 0, 6, -3,
+ 22, -14, -71, -24, -2, -33, 23, 7, -8, 7, -3, 2, -4, 1, -8, -2 },
+ { 1, 0, -1, 2, 0, -2, 0, 0, -1, 0, 4, 0, 26, -1, 10, -11,
+ -17, -32, -58, 14, -14, -11, -2, 15, 2, -8, 12, 10, -9, 13, -33, -14 },
+ { 15, -17, -19, 7, -8, -15, -32, -22, 7, 12, 18, 0, 0, -15, -4, 16,
+ 37, -2, -46, 11, 2, -8, -10, -8, 14, 9, -4, 5, 7, -17, 4, 3 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, 0,
+ -5, 3, -85, 23, -9, -17, -2, -2, 0, 0, 0, 0, 0, 0, 0, 0 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, 0,
+ -5, 3, -85, 23, -9, -17, -2, -2, 0, 0, 0, 0, 0, 0, 0, 0 },
+ { 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, -1, 0, 0, 1,
+ 1, 7, -76, 41, -7, -24, 0, -6, 3, 6, 0, -2, -1, 1, 0, 0 },
+ { 0, -3, 4, 2, 3, 2, 2, 0, 3, -1, 4, 0, -1, 4, -2, -4,
+ -32, -11, -64, -29, -9, -43, 2, -11, -1, -7, 0, -4, -2, -2, -2, 2 },
+ { 10, -20, 3, -3, 13, 13, 0, -4, 2, 7, -8, 7, -2, 2, -20, -20,
+ -19, 3, -47, -18, -16, -6, -15, -42, -17, 14, -6, 8, 12, -10, 11, -12 },
+ { -3, -2, -2, -1, -1, 4, -3, -1, -6, -2, 3, 2, -3, 6, -1, -9,
+ 10, 13, -68, -9, 26, 3, 5, 3, -21, 10, -15, 21, -22, 19, 11, -14 },
+ { 1, 5, 18, -19, -29, -13, -2, 18, -10, 20, 2, 10, -10, 11, 1, 8,
+ -16, -17, -41, 10, -14, -25, 0, -14, -19, 17, 7, -12, 14, -11, 14, 5 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -1, -43, 5,
+ 6, -12, -48, 19, 8, -38, -8, -3, 22, -21, -10, 15, 20, -9, -5, 8 },
+ { 0, 0, 0, 0, -1, 1, -1, 0, 0, 0, 0, 0, 0, 0, 6, -3,
+ 22, -14, -71, -24, -2, -33, 23, 7, -8, 7, -3, 2, -4, 1, -8, -2 },
+ { 1, 0, -1, 2, 0, -2, 0, 0, -1, 0, 4, 0, 26, -1, 10, -11,
+ -17, -32, -58, 14, -14, -11, -2, 15, 2, -8, 12, 10, -9, 13, -33, -14 },
+ { 15, -17, -19, 7, -8, -15, -32, -22, 7, 12, 18, 0, 0, -15, -4, 16,
+ 37, -2, -46, 11, 2, -8, -10, -8, 14, 9, -4, 5, 7, -17, 4, 3 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, 0,
+ -5, 3, -85, 23, -9, -17, -2, -2, 0, 0, 0, 0, 0, 0, 0, 0 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, 0,
+ -5, 3, -85, 23, -9, -17, -2, -2, 0, 0, 0, 0, 0, 0, 0, 0 },
+ { 16, 65, -2, -2, 4, 3, 0, -7, 3, 1, 3, 1, 0, 5, 1, -5,
+ 0, 2, -1, 3, 0, 0, -1, -2, 6, 0, -2, 0, 0, -1, 1, 1 },
+ { 5, 37, -4, 8, -4, -1, 9, 17, 6, -7, 5, -1, 11, 6, -4, 7,
+ -2, 4, 1, -3, 11, 3, 3, -9, 6, 0, -2, -4, -5, 4, -12, -11 },
+ { 15, 24, -14, 2, 6, 17, 26, 5, 8, 11, -9, -7, -6, -8, 3, -5,
+ 9, 10, -3, 10, 0, 1, 4, -9, 4, 9, 3, 0, 4, 0, -5, 3 },
+ { 9, 36, -9, -8, 7, 7, 4, 3, -1, -16, -2, 7, -5, -6, 6, 12,
+ -11, -12, 9, -1, -3, -9, 12, 6, -6, 2, 2, 5, 0, 5, 6, -6 },
+ { 25, 39, -5, 24, 3, 10, 3, -6, 13, -8, 3, -7, 2, -10, -5, 2,
+ -2, 3, 5, -2, 1, 5, -2, 3, -4, 1, -5, -4, 0, 1, -2, 0 },
+ { 16, 27, -1, 0, -14, 6, 4, -5, 7, -2, -6, 0, -3, -5, 2, -1,
+ -1, -19, 5, -8, 0, 11, 12, 5, 0, 3, 10, 6, -14, 14, -13, -15 },
+ { 12, 23, -14, 2, 1, 4, -3, 16, 7, -8, 2, -8, 8, 6, -8, -7,
+ -3, 0, 2, 8, -13, 7, 13, -6, -4, 6, -13, -16, 14, 11, -7, 5 },
+ { 16, 28, -7, -1, 6, -3, 9, 0, -7, 3, 0, 3, -12, 20, 8, 9,
+ 8, 23, 8, -13, -2, 4, 9, 3, -5, 13, 5, -2, 12, 14, 5, -1 },
+ { 19, 37, 19, 5, 7, 5, 10, 5, 19, 10, 14, 0, 2, 5, 1, -4,
+ -4, 2, 2, -5, -2, -1, 2, -6, -4, -4, -5, -3, 2, -2, -2, -2 },
+ { 24, 21, 1, -11, -10, 17, -14, 14, 6, -1, -6, -1, 0, -13, -1, -12,
+ -2, -5, 6, -4, -12, 14, 5, -2, -8, -8, 15, -7, -30, -12, 4, 0 },
+ { 11, 26, -3, 3, 5, -1, -2, 3, -2, 10, 15, -4, 10, -28, 10, -17,
+ -8, 1, 2, -7, -1, -6, -15, -1, 4, 5, -7, 9, 0, -5, -4, 4 },
+ { 18, 32, 1, 2, -7, 4, 15, 2, -9, -2, 12, -11, 7, 11, 13, 2,
+ 0, 5, 9, -10, 16, 3, -3, 5, -9, -23, 2, -2, -1, 5, 2, 11 },
+ { 35, 24, -20, 2, 4, -1, 5, 14, -10, -9, 8, -7, 0, 5, -7, -7,
+ 11, 1, 5, 3, 2, 0, -2, 3, 0, 1, 4, 0, -2, -8, 0, -4 },
+ { 9, 35, -1, 2, -1, -19, -3, 12, -1, 8, 8, -13, -1, -2, 2, 5,
+ -8, -1, 13, -2, 11, 1, 0, -10, 0, -3, -7, 2, 1, -12, 3, 12 },
+ { 20, 27, -12, -12, 7, 4, -1, -13, -1, -9, 2, 13, -11, 5, 7, -9,
+ 9, 1, 1, 8, -9, 0, -6, 7, 4, 2, -2, 7, 3, -2, 1, -9 },
+ { 8, 37, -20, -5, 0, -21, 10, -8, 3, 19, -9, 7, -3, -8, 10, -2,
+ 0, 5, 6, -4, -2, -1, 0, -7, 6, 1, 0, 4, -5, 6, -8, 2 },
+ { 8, 27, 1, -3, -5, 1, 6, 0, 15, 2, 17, -1, 3, -17, 10, 5,
+ 5, -6, -6, 6, -10, 18, -5, 0, 0, 13, 7, 10, -5, -6, -2, -4 },
+ { 14, 29, -20, -4, -3, 1, -5, -1, 2, 12, -10, -3, 4, -18, 4, 14,
+ -4, -1, -9, 15, -2, 2, -5, -3, 2, 9, -2, -14, -3, 4, -4, -7 },
+ { 23, 23, -23, -11, 27, 4, 4, -1, 7, 0, -5, 9, 2, -11, 3, 7,
+ -2, -5, 2, -7, -7, 13, -3, -6, 2, 3, 3, -4, -1, -8, 5, -2 },
+ { 16, 26, -6, 8, -9, -1, -2, -1, -8, 4, -2, 0, -12, 9, -1, 0,
+ -17, -9, 30, -5, -15, -16, -13, 0, 10, -11, -7, -3, -1, 0, -11, -2 },
+ { 12, 32, -4, -5, 10, 19, -10, 4, -12, 5, -6, 9, -12, -6, -6, -8,
+ 4, 1, 3, 0, 8, 0, -3, -4, -7, -4, 10, 8, 6, 5, -1, 4 },
+ { 46, 42, -3, -14, -2, -6, 6, -2, -5, -1, -3, -3, 1, -1, 3, 1,
+ 1, 4, -1, 2, 3, 1, -2, 6, 0, -1, -2, 4, -2, -1, 2, 2 },
+ { 9, 33, -13, 4, -11, 3, -8, 22, 12, -2, 4, 0, -16, 5, 4, -1,
+ 7, -6, -9, 1, 7, 5, 0, -5, 5, -1, 10, 3, -2, -1, 3, -2 },
+ { 9, 30, 6, -3, 6, 1, -7, 5, 11, 14, 7, 1, 0, 2, 2, -1,
+ 8, 7, -6, -13, -10, -2, 1, -6, 10, 7, 6, 5, -2, -5, -1, -16 },
+ { 9, 28, -11, -10, 9, -10, 15, 8, 4, 9, -4, -7, 0, -5, 9, 8,
+ -7, 2, -15, -23, 4, -4, 4, 16, -8, -3, 0, -8, 14, 5, -3, 15 },
+ { 17, 26, -5, -5, -1, -8, 20, 18, -7, -2, 4, -7, -8, -5, -4, 16,
+ 0, 0, -7, -2, -13, -5, -2, 3, 12, 1, 3, -5, 2, 2, 0, -1 },
+ { 11, 37, 7, -23, 6, -1, 15, 13, 4, -9, 7, 5, 3, -3, -5, -8,
+ -2, 3, -5, -1, -8, 7, 2, 13, 1, 3, 0, -3, -1, 2, 0, -2 },
+ { 21, 33, 7, 20, 21, -10, 6, -5, -5, -6, -9, 2, 10, 0, 8, -4,
+ 10, 2, -2, -2, 0, -10, -6, -2, 0, -5, 3, -11, 3, -9, -3, 1 },
+ { 6, 30, -15, -8, 16, 1, 4, 6, 4, 5, 8, -3, 8, -9, -1, -6,
+ 8, 2, -2, 4, -2, 5, 11, -21, 3, -10, 16, -11, 24, 10, 14, -6 },
+ { 15, 36, -3, -9, -20, 12, 0, -7, -18, -4, -8, -9, 9, -7, -3, -1,
+ 2, 7, -5, -8, 6, 2, 2, -1, 7, 1, 1, -3, 3, -4, -8, 1 },
+ { 16, 34, 21, 3, -9, 10, 7, 9, -7, 1, -4, -9, -4, -5, -5, 3,
+ 3, -19, 1, 5, 4, -2, -6, -5, -10, -11, -8, -2, 2, -5, -8, -7 },
+ { 28, 29, -3, 18, -2, 0, -6, 12, -2, 10, -11, -4, -13, -12, -6, -4,
+ 0, 4, -1, -8, 6, 4, 12, 11, 10, 10, -3, -6, 1, 2, 1, 7 },
+ { 3, 8, 22, -8, 3, 36, -8, -1, 9, 6, -13, -14, 8, -1, 1, 2,
+ -2, -8, 0, 3, 1, 2, -1, 5, -1, -8, 0, -2, 2, 2, -1, 1 },
+ { 0, 6, 0, 0, 4, 13, -7, -16, -6, 15, -14, -21, -9, -10, -10, -6,
+ -21, 5, 4, 2, 12, 4, 12, 11, -4, -6, -6, -10, -7, -18, 1, 4 },
+ { -1, 3, 10, 1, -1, 15, 4, -7, -16, 3, 0, -22, 10, 2, -3, -2,
+ 13, 5, -8, 16, -5, 4, 0, -11, -10, -22, 0, -4, -17, 5, 2, 1 },
+ { 12, 8, -4, -9, 14, 40, -21, 0, 1, -15, -10, -12, 12, 6, -10, 2,
+ 8, 6, -12, -10, -11, 1, 0, -11, 2, 1, 13, 0, 6, 3, 8, 4 },
+ { -10, 3, 5, -4, -3, 3, 0, -9, 2, 8, -22, -23, 17, 8, -17, -3,
+ 14, -8, -4, 1, -8, 3, 0, 5, -1, -3, -2, -4, 1, -10, 0, -2 },
+ { 0, -1, 5, -7, 4, 12, -2, 0, -7, 2, -16, -15, 12, 21, -7, -4,
+ 7, -7, -11, -15, -7, -9, -5, -8, 0, -6, 8, -3, -8, 22, -7, -9 },
+ { 7, 19, 4, -9, 24, 22, 2, -6, 8, 13, -14, -20, -4, 11, 8, -4,
+ -1, 2, 0, -7, 5, -17, -3, 3, -6, 5, 3, 4, -5, -7, -3, 14 },
+ { -2, 6, 2, 8, -2, 5, -4, -2, -10, 3, -45, -30, -3, -3, -12, -4,
+ -3, -3, -1, 9, -6, -6, 5, -4, 0, 5, -1, -2, -1, 0, -6, -1 },
+ { -3, 14, -16, -10, 10, 0, -2, -40, -9, 12, 2, -19, 15, -4, 4, 3,
+ 3, -4, 7, 1, -4, -5, 0, 4, -1, 0, -9, -2, -4, -1, -2, 0 },
+ { 7, 16, 2, -7, 8, 2, 0, 1, 5, 21, -10, -26, 7, 2, -9, -7,
+ -3, -16, 8, 5, 5, -6, 10, 4, -14, -6, 5, 3, -2, -2, -4, 1 },
+ { -9, 14, -1, 3, 3, 11, 1, -5, -3, 13, -16, -18, 20, 6, -5, 0,
+ -3, 2, 8, 4, -19, -9, 12, 0, -8, 2, 2, 1, 6, 13, -7, -11 },
+ { 2, 5, 16, -4, 19, 15, 4, 0, -11, 7, -10, -10, -16, 18, -11, -12,
+ -9, -4, 7, -4, -4, -17, 1, 1, -8, -3, -3, 5, -2, -6, -11, -5 },
+ { 2, 12, 0, -9, -10, 14, 6, 2, -3, 2, -12, -28, 12, 1, -1, 2,
+ 0, -3, -4, 7, 16, 5, -7, 8, -4, -3, -1, 3, -12, 4, -17, -5 },
+ { -4, 7, 11, 6, 1, 14, -4, -6, 5, 5, -6, -24, 23, -9, -15, 13,
+ -7, -9, -15, 10, -1, 8, -5, 1, 12, 6, 2, 0, 4, -2, 9, -10 },
+ { 1, 5, 11, 3, 6, 12, -3, 8, -21, 5, -7, -20, 12, -2, -9, -3,
+ 17, -7, -8, -9, -14, 3, -13, 18, -8, 9, 2, -8, 4, -8, -5, -2 },
+ { -3, -3, -1, 5, -2, 15, 3, 2, 1, -8, 1, -39, -6, 13, -13, 0,
+ -2, -5, -6, -3, 0, -5, -2, 15, -9, 5, -3, -6, -2, 7, 0, -13 },
+ { 2, 8, 5, -12, -13, 22, 8, -16, 11, 5, -2, -32, -2, -4, 11, 5,
+ 5, -6, 1, 3, 1, 5, 3, 6, -5, 4, 4, -8, 8, 4, 1, 3 },
+ { 13, 9, 5, -4, 9, 18, -11, 2, -1, 15, -10, -19, -2, 14, 0, -10,
+ 1, 1, -18, 3, 2, -6, -8, 20, 7, -8, 16, 9, 9, -13, -3, -2 },
+ { -13, 11, 11, -9, -10, 13, -3, -18, 2, 10, 5, -21, 6, 15, -11, -21,
+ 3, 14, 0, -12, 9, -1, -2, -4, 3, -3, -9, -8, -5, -2, -8, 2 },
+ { 3, 3, 11, 4, 0, 13, 1, -8, 10, 13, -6, -26, 2, 12, -3, -5,
+ 12, -2, 1, 8, -7, -17, -19, 5, 10, 7, -3, 2, -3, 0, 5, 0 },
+ { 5, 0, 3, -3, -9, 5, -15, -5, -5, 17, -5, -31, 0, 13, 13, 5,
+ -1, -6, -14, 7, -8, 9, -14, -2, -16, -4, -4, -6, 6, -6, -10, 6 },
+ { 13, 3, 1, 7, -3, 4, -1, -2, -1, 4, -8, -32, -1, -4, 0, 3,
+ -10, 7, 10, -10, 4, -1, 6, 2, -16, -9, 4, 3, 13, -23, -3, -4 },
+ { 4, 11, -4, -9, 4, 11, -12, -12, -12, 6, 1, -28, -3, 14, 18, -2,
+ -12, 7, 15, -3, -5, -7, -3, 2, -6, 4, 4, -2, -5, -3, 2, -13 },
+ { 8, 7, -7, 0, 13, 7, -8, -7, 8, 36, -10, -22, 3, 23, -3, -10,
+ -3, 11, 1, -7, 3, 3, -1, -7, -4, 2, 3, 2, 5, 3, -4, -1 },
+ { -1, 1, 13, 1, -6, -1, -6, -9, -18, 17, -5, -37, -1, -1, -6, -4,
+ 1, -6, -15, 2, 17, -9, 0, -3, 0, 4, 0, -5, 0, 4, 1, -5 },
+ { 0, 14, 5, 0, -7, 2, -6, 17, -6, -9, 7, -16, -5, 23, -14, -13,
+ 8, -15, 11, 10, -11, -13, -33, -5, -2, 1, 6, 8, 0, -13, -9, 5 },
+ { 11, 7, -2, -8, 9, 11, 25, -14, 7, 3, -1, -33, 14, 8, -6, -19,
+ 3, 3, 2, -1, -3, -1, -2, -10, -3, 1, 2, 1, 4, 2, -3, 4 },
+ { -2, 8, 4, -2, 9, 13, -4, -2, -15, -3, 19, -37, 9, 25, -9, 2,
+ -5, -2, -2, -4, 4, 2, 2, 0, 3, 3, 3, 5, -2, -3, -4, -3 },
+ { 10, 13, -1, -15, 4, 6, -18, -4, 25, 1, -23, -17, 15, 13, -8, -8,
+ 7, 4, -5, 3, 6, 9, -7, 6, 0, -5, 8, 0, -6, -1, -2, -2 },
+ { 1, 3, 9, -5, 27, 15, -9, -31, -1, 23, -2, -9, 1, 8, -1, -7,
+ -2, -8, -4, -4, -2, -1, 3, 5, 0, 0, -1, 1, -7, 7, -3, -3 },
+ { -8, 7, 3, -6, 8, 3, -11, -2, 36, 14, 1, -30, 6, 10, -12, -6,
+ -6, -2, -4, -3, -5, 0, 9, 4, -5, -5, -8, 12, 4, -3, 1, -8 },
+ { -2, 9, 33, 0, 12, -3, -7, -4, -4, -1, 6, -25, 11, -6, -9, -11,
+ -2, -4, -2, 6, -1, -3, -6, 15, -6, 3, 10, -4, 1, 0, 5, 8 },
+ { -22, -21, -9, -19, -5, -7, -12, -15, -8, 9, -19, 14, -7, -4, 5, -8,
+ -2, 7, 1, -3, 4, -4, 6, 11, 2, 6, -3, -5, 2, -2, 0, -3 },
+ { -32, -13, 3, -24, 3, -8, 4, 1, -10, 14, -15, 0, 4, 6, -1, 6,
+ 7, -1, 6, 4, -3, -17, 1, 4, -6, -1, 1, 0, 3, 3, -7, -4 },
+ { -32, -11, 7, -8, -12, 13, -5, -22, -4, 12, -16, 2, 0, 4, 0, 1,
+ 0, 6, -5, -8, 2, 6, 5, 0, -3, -6, 5, 6, 5, 5, 13, -4 },
+ { -44, -33, 6, -4, 2, 0, -9, 10, 3, 4, 7, 0, -1, 7, 5, 1,
+ 1, -3, 1, 6, -1, 0, 2, 3, -4, 0, 0, 1, 0, -1, -2, -1 },
+ { -30, -18, -24, -8, 5, 0, -2, 14, 7, 0, 1, 12, 6, 4, -9, 7,
+ 5, 7, -11, -5, 1, -8, -1, 2, 2, -9, 7, -1, 7, 5, 6, 6 },
+ { -22, -20, -13, -9, 20, -3, 10, -8, 6, -4, 2, -7, 10, 8, 0, -1,
+ 2, -3, 6, -19, 2, 4, 3, 3, -7, 2, -1, -6, 1, 1, 6, -2 },
+ { -27, -8, -1, 3, -1, -11, 24, 4, -1, 1, -8, 8, 5, -11, 15, -3,
+ -15, -1, -1, -13, -1, 1, -5, 5, 2, 3, -9, 0, 4, 3, -7, 6 },
+ { -33, -16, -1, -8, 10, -23, 6, 13, -1, -3, -9, 0, 5, -7, -5, -12,
+ -2, 3, 3, 6, -2, -3, 2, -3, 9, -6, -3, -2, 0, 5, -3, -4 },
+ { -22, -17, 11, -3, 3, 1, -1, -5, 17, 2, -15, -2, 10, -9, 6, 14,
+ -16, -12, 20, -1, -7, 6, -3, -12, 1, 10, -10, -1, 7, -3, -1, 10 },
+ { -28, -13, 1, -3, -1, -1, 0, 3, 3, 5, 1, 10, -10, -3, 7, 2,
+ 4, 19, -1, -1, 10, 5, -8, 1, 11, -15, -4, -3, -5, 4, -13, 3 },
+ { -22, -13, 42, -20, 5, -13, 7, -11, 1, 1, -1, 1, 6, 3, 6, -11,
+ 3, 3, -2, 0, -4, 4, -3, -1, -5, 2, 0, 0, -9, -1, 4, 4 },
+ { -26, -15, -2, -6, -4, -2, 16, 8, 21, 8, 1, -3, -10, 7, -8, -12,
+ -5, 12, -9, 3, -2, -3, 18, 1, -12, -15, -4, 5, -3, 0, 12, 7 },
+ { -26, -16, 5, 6, 14, -3, 15, 6, 1, -7, -13, 16, -15, 5, 11, -2,
+ 9, -7, -4, -2, 0, 0, -2, 7, -8, -6, -5, 2, 7, -3, 2, 12 },
+ { -31, -17, -8, -30, 4, 14, 6, -6, 6, -11, 0, 3, -4, 0, 0, -4,
+ 0, -4, 1, 4, 3, 4, 0, -5, 3, 2, 2, 0, 2, 1, 3, 5 },
+ { -61, -10, 4, 10, 4, 7, 0, -3, 0, 1, 0, -3, 0, 1, 0, -2,
+ -1, 1, 2, -2, 4, -3, 1, 1, -1, 1, -2, -4, -4, 4, 0, 0 },
+ { -28, -13, -8, -4, 3, -3, 2, 1, 11, 14, 3, 9, 1, 13, 3, 5,
+ -3, -2, -2, -12, -14, -9, -11, -15, -12, -5, -4, -12, 3, -3, 0, -5 },
+ { -41, 0, 12, -24, 13, 4, 5, 16, -5, -4, 0, 0, 13, -4, 1, -9,
+ 9, -6, -1, 6, -2, 5, 2, 9, 6, -9, -8, 8, -2, -3, -6, -4 },
+ { -26, -19, -2, -15, 4, -14, 6, 0, 26, 20, 8, 9, 9, 3, -4, -5,
+ -8, 1, 0, -1, 5, 9, 3, 4, 4, 7, 1, 3, -2, -2, -10, 0 },
+ { -29, -18, 9, -4, 1, -5, -14, -12, 5, -10, -5, 4, -5, 0, -1, -1,
+ 4, -5, 7, -16, -11, 2, 7, -15, 2, -4, 6, -4, -6, 7, -3, 7 },
+ { -27, -16, 9, -14, 3, -8, 9, 0, 7, -4, -3, -7, 0, -10, -1, 2,
+ 1, -2, 15, -10, 14, 7, 6, 17, 3, -4, 3, -10, 8, -8, 3, 11 },
+ { -21, -20, -8, -8, 4, 5, -3, -2, 0, -5, 14, -10, 11, -4, 13, 0,
+ 5, -11, 19, -18, 18, 3, -5, -3, -4, -8, 11, -10, 10, 3, 4, -9 },
+ { -35, -15, 13, -12, 4, 0, -2, -4, -12, -3, -8, -24, -7, 1, 7, 8,
+ -3, 0, -2, -1, 3, -2, -2, -6, 8, 1, 0, 1, -6, -1, 2, -6 },
+ { -19, -14, 13, -10, 9, -1, 1, 3, -12, 5, -16, 7, 13, 9, 4, -4,
+ 6, -5, 4, 9, -3, 17, -4, 12, -11, -6, -5, -6, 13, 2, 7, -9 },
+ { -34, -8, -4, 1, 2, -1, 3, 6, -20, -11, 8, -1, 4, 2, -9, 4,
+ -4, -5, 16, 10, -4, 14, -13, 1, -6, 0, 2, -10, 0, -3, -3, 7 },
+ { -36, -10, -8, -3, 2, -2, 14, -4, -1, -7, -4, 10, -1, -3, 15, -11,
+ 0, 2, 3, -1, 4, 0, 8, -1, 0, 18, -11, -5, 15, -5, 13, -12 },
+ { -22, -13, 14, -20, 15, 25, 16, 10, 8, -2, -10, -5, -1, -8, 11, 8,
+ -1, -2, -4, 1, 2, -1, -7, 0, 0, 0, -3, 0, 2, -1, 0, 2 },
+ { -31, -22, 7, 6, -2, 5, -20, 14, -6, 7, 0, 14, 3, -7, 3, -6,
+ -2, 1, -3, -5, 1, -10, 1, -24, 6, -2, 3, -7, 1, -7, 8, 7 },
+ { -25, -20, -3, -9, 10, 6, 12, 7, 5, 4, -3, 6, -1, -5, -6, -8,
+ 3, 5, 6, 5, -10, 10, -4, -15, -15, -2, -9, 2, 18, 1, 8, 12 },
+ { -24, -19, -2, -4, -7, 11, 6, 9, 16, 2, -7, 18, 6, -7, 6, 6,
+ -2, -9, 3, 12, -2, 3, -1, 6, 7, 8, 0, 8, -11, 8, 4, 2 },
+ { -26, -20, -12, -12, -2, -3, 1, -5, -1, -2, 0, 3, 7, 9, -2, 2,
+ 9, 22, 13, 4, -4, -1, -2, -14, 5, 15, -8, -5, -7, -11, -14, -6 },
+ { -21, -18, -1, -4, 0, 3, 7, -2, 10, 8, -8, -1, 15, 1, -9, 3,
+ 1, 3, -5, -2, 2, 4, 0, -1, 10, 2, -19, -8, 8, 30, -7, 8 },
+ { -25, -6, 26, 4, -8, 4, -2, 21, 5, -4, -16, 5, 13, 4, -10, -1,
+ -6, -2, 2, -10, -13, 1, 3, -3, -6, -8, 2, 11, 1, -7, 0, 5 },
+ { 0, -1, -2, 19, -12, -48, -6, 11, 8, -2, -4, -2, -7, 5, -3, 2,
+ -2, -1, -1, -7, 0, -3, -3, -4, -4, 4, 1, 3, -3, -1, -2, -5 },
+ { -11, -8, -28, 18, 16, -24, -8, 19, 4, 8, -12, 9, -4, -2, 4, -7,
+ 6, 2, 3, 3, -4, 0, 1, -6, -4, -2, 2, 6, 0, -3, 1, -16 },
+ { -9, -5, -26, 7, -3, -37, -16, -2, 2, -7, 4, -13, 0, -4, -6, -5,
+ -6, -4, 0, 3, 4, -3, -4, -4, 4, -3, 9, -4, -2, 2, 7, -4 },
+ { 2, 9, -18, 7, 29, -24, -1, 7, 14, 10, 3, -3, -2, -5, 6, -10,
+ -6, -3, -8, 0, 5, 1, 4, 3, -12, 2, 6, 1, 3, 4, 1, -3 },
+ { -20, 2, 8, 20, -9, -24, -4, 18, 3, 11, -1, -11, 6, 9, -1, -3,
+ 1, -1, -15, 3, 15, 9, 3, 2, -13, 2, -8, 8, 1, -1, 1, -8 },
+ { -12, 5, -11, 6, 19, -26, -17, -6, 4, 14, 6, -8, 9, 5, -6, -5,
+ 2, -1, 20, 1, -11, -10, -18, 20, -7, 0, -3, 4, 2, 0, 10, 4 },
+ { -15, 1, -2, 13, -8, -21, -22, 4, 4, 3, 3, -7, -31, 4, -10, -14,
+ 0, 8, 4, 5, 8, 11, 2, -8, 6, 7, 0, -2, 6, 8, 8, 7 },
+ { -13, -10, -9, 12, 19, -16, -3, -2, 9, 2, 11, -29, -1, 9, 4, -3,
+ 1, -10, -10, 16, 1, 7, -7, -6, -4, -1, -5, 3, 6, 0, 3, 1 },
+ { -17, -1, -5, 19, 12, -9, -21, -5, 2, 12, -7, -7, -3, 8, 7, -2,
+ 6, -9, -9, 1, -4, 1, 1, 3, -14, 2, -8, 0, 10, 1, -12, -6 },
+ { -13, -5, 8, 15, 0, -20, -2, 20, 8, -8, 8, -19, 12, 10, 2, -11,
+ 0, 12, 1, -11, 0, -11, -15, 5, -11, 2, 4, -4, -11, 5, -4, -5 },
+ { 3, -11, -7, 8, 0, -17, -26, 15, 19, -7, 10, -9, -5, -5, 14, -25,
+ 0, -8, 2, -9, -3, 9, 1, -6, 4, -4, 3, -9, -1, 6, 2, 2 },
+ { -12, 5, 5, 9, 14, -18, -19, 4, 2, 16, 14, -21, -15, -9, -1, 16,
+ 12, -11, -10, -5, -7, 4, 15, -8, -5, -1, 1, 14, 13, -7, -1, -4 },
+ { -10, -5, -1, 8, 7, -23, -10, 14, 6, 11, 10, -16, -3, 16, 6, 0,
+ 0, 9, 6, -2, -7, 1, 22, 5, 3, -8, 0, 3, -2, -10, 3, 0 },
+ { -2, -14, 2, 16, 15, -17, -17, 6, 19, 4, -10, -15, -1, 15, 11, -14,
+ -8, 5, 8, 8, -2, -8, -11, 10, 10, -8, -14, 2, 13, 4, -2, -12 },
+ { -10, 3, 6, 4, 19, -23, -19, 1, 4, -9, -30, 3, -6, 18, 0, 2,
+ 0, -11, 0, 3, 7, -2, 8, 5, 2, -3, 6, -9, 1, -4, 7, -6 },
+ { 9, 5, -2, 21, 20, -33, -13, 7, -10, 8, 8, -15, -6, -4, 1, 5,
+ 3, 7, -2, -9, -1, 4, -6, 1, 0, 9, -1, -5, 2, 1, -3, 3 },
+ { -9, -3, 3, 15, -3, -30, -7, -7, -25, 6, 2, -6, 1, 19, 1, -12,
+ 1, -8, -13, 9, 13, 1, 8, 2, 5, 15, -2, 3, -9, 0, -4, 4 },
+ { -6, -12, -17, 25, 22, -13, -10, 9, 2, 11, -7, -16, 4, 6, 1, 0,
+ 0, 18, -4, -5, 4, -2, -1, -5, 0, -4, 6, 1, 6, -1, 7, 0 },
+ { -1, 0, -10, 8, 8, -27, 0, -2, 29, 16, -2, -4, 9, -1, 2, 0,
+ 6, 10, 6, 4, 2, -7, 9, -18, 3, 3, 3, -10, 17, 10, 9, -6 },
+ { -3, -12, -6, 11, 20, -32, 5, 21, 3, -4, -9, 2, -10, 1, 7, -4,
+ 5, 0, 0, -1, -8, -9, -7, 4, -10, 5, 0, 2, -5, 4, 9, 1 },
+ { -5, -1, -5, 1, 2, -19, -13, 1, 6, 12, 2, -16, -17, 11, 10, 13,
+ 16, -12, -11, 3, -6, 0, 6, 4, -3, 1, 8, 2, 5, -11, 3, -14 },
+ { -19, 5, 10, 11, 2, -23, -9, 16, -2, 7, 0, -11, -7, 10, 6, -7,
+ 26, -15, -4, 8, 6, -4, 7, -9, -15, 1, 8, -4, 4, 2, -12, 16 },
+ { -11, 1, 11, -4, 1, -31, -13, -1, 8, 5, 4, -2, 0, 13, 7, -17,
+ 7, -10, -6, 1, 4, -1, 2, -9, -4, 9, 3, 3, -4, -5, 3, 4 },
+ { -3, 1, 10, -1, 0, -15, -22, 4, 40, -11, -4, -3, -14, 9, 11, -1,
+ 9, -1, -6, 6, 3, -6, 0, 0, -12, 7, -2, 0, 9, 3, 1, 3 },
+ { -1, -1, -1, 14, 8, -24, -14, -8, 5, 8, 5, -12, -17, 8, 2, 7,
+ 10, -8, 0, 4, -6, -6, -10, 8, 4, -12, 3, -9, -12, 5, 4, -3 },
+ { -5, 1, -11, 8, 9, -24, 0, 2, 2, 14, -12, -13, 1, 6, 7, 0,
+ 7, -6, 9, 26, 11, -14, 8, 10, 1, 9, 0, 11, -2, 6, 2, -10 },
+ { -13, 1, 4, 34, 19, -17, -15, 0, 3, -2, -7, -1, 0, -3, -3, -1,
+ 1, -1, -10, 8, 5, 0, -8, 4, -17, 9, -2, 0, 0, 6, 2, -3 },
+ { -6, -4, 1, 2, 2, -14, -29, 0, 9, 34, -3, -5, -14, 6, -10, -9,
+ -5, -1, 0, 3, 3, 0, 1, -1, -2, -1, -1, -3, -3, -4, 3, -3 },
+ { -4, 6, 3, 14, 14, -8, -29, 31, 11, 14, -4, -5, -6, 10, 6, -9,
+ -1, -11, -7, 1, 7, 4, 1, -6, 4, 0, 10, -7, -5, -1, 2, 4 },
+ { -4, -4, -2, 14, 6, -32, -6, -14, 14, -5, -11, 10, -18, -4, 6, -8,
+ 9, 5, -4, 1, -4, 5, -2, -9, 3, 5, 2, -10, -6, -17, 3, 17 },
+ { -16, 9, 21, 19, 4, -20, -17, 14, 9, 15, -6, -17, -1, 1, 6, -3,
+ 1, 1, 8, -3, -6, 6, 9, 4, 9, -9, -5, 1, -1, 0, -1, 2 },
+ { -7, -5, 3, 19, 1, -20, -9, 14, 21, -7, -18, -9, 26, -7, -17, -7,
+ 12, 6, 0, -9, -6, 14, 9, -9, -8, 4, 15, -7, -9, -1, 9, 1 },
+ { -20, 30, -6, 11, 24, -4, 0, -6, -2, 8, -4, 12, -8, -17, 0, 5,
+ -4, 1, -1, 3, -3, 5, 3, 3, 7, -2, -3, -2, 4, 0, 0, -1 },
+ { -35, 17, 6, 1, -9, -1, -16, 3, -20, -13, 8, 7, -4, -7, -4, -20,
+ 7, 12, -5, 5, -5, -11, 12, -1, 15, -9, -6, 16, -4, -9, -13, 4 },
+ { -21, 36, -19, 9, 0, -7, -8, 9, -4, -3, 3, 0, 7, -8, -2, -2,
+ -11, 13, -1, 5, -3, 7, 2, 3, -1, -2, -5, 1, -1, -2, -5, -3 },
+ { -12, 33, -4, 1, -12, -9, 0, -13, -1, 2, -8, 4, -10, 6, -16, -7,
+ -1, -4, -10, 15, -1, 0, -5, -8, 5, 5, -3, 0, 2, -7, 1, -7 },
+ { -14, 32, 5, -7, -15, 3, -5, 8, 14, 5, 9, 13, 3, 18, -3, 7,
+ 4, -10, -10, 10, -1, 2, 0, -2, -11, 5, -3, -4, 2, 2, 7, 4 },
+ { -14, 34, 1, 20, -1, -12, 0, -3, -7, -4, 7, 18, 9, -3, 14, -7,
+ -9, -20, -7, -4, -13, 12, 1, 12, 5, -6, 2, -4, 0, -15, 1, 3 },
+ { -21, 23, 7, -8, 3, -13, -3, 0, -6, -2, -7, 6, -12, 9, -6, -2,
+ -2, -4, -1, 6, 9, 5, -9, 15, 0, 8, -8, 7, 6, -15, 3, -5 },
+ { -27, 32, -1, -4, -2, 4, -10, 12, -3, 8, 13, 7, 0, -15, 4, -2,
+ 3, 5, 7, -4, 9, -12, -1, -2, -1, -4, 0, -4, 2, -5, 6, -6 },
+ { -17, 29, 15, 0, -1, -4, -10, 13, 12, -1, -8, -10, -10, 4, 7, -2,
+ 6, -5, -13, 19, 6, 1, -7, 2, -9, -2, 12, -4, -8, -3, 2, 4 },
+ { -38, 27, 16, -15, -6, 3, -7, -4, 0, -1, 6, -2, -3, -6, 6, -6,
+ -3, 0, 2, 0, -4, 6, 1, -1, 0, 4, -1, 3, 4, 1, -2, 5 },
+ { -33, 40, -4, 2, 1, 0, 0, -10, -14, 0, -7, 4, -1, 3, -2, 5,
+ 7, 6, -1, 4, 1, 3, 1, -7, 1, -4, 5, 7, 0, 4, 3, -4 },
+ { -20, 25, 12, -4, 16, -4, 2, 2, -14, -2, -3, 29, -1, 1, 3, 1,
+ 9, -5, 2, -8, -3, 1, -7, -2, -7, 1, 0, 4, 16, -2, -1, -1 },
+ { -10, 30, 17, 3, -5, -2, 0, -5, -22, 4, 5, 5, -3, -18, -6, 10,
+ -5, -7, 2, 8, 7, -7, -11, -2, 0, -3, 3, 2, 11, -4, 4, -4 },
+ { -11, 30, 11, 4, -3, -8, 1, -2, 4, 18, 3, 1, -1, 0, -8, -4,
+ -3, 10, 13, 14, 5, -5, 1, 1, -10, 2, 15, 4, 9, -1, -5, -3 },
+ { -17, 32, 18, -18, -3, -5, 6, 10, 1, -15, -5, 9, 8, -12, -10, -6,
+ 11, 9, -5, -8, -7, 10, 5, -10, -14, -4, -3, 1, 9, -11, 2, 1 },
+ { -13, 28, -11, -1, 2, -16, -2, 7, -24, 0, 3, 6, 3, -1, -8, -7,
+ -12, 2, 2, -20, 10, 4, 0, -13, -2, -2, 1, 8, -14, 0, 4, 1 },
+ { -14, 23, 12, 8, 8, -26, 2, -4, -14, 13, -14, 15, 3, -9, -1, -13,
+ -10, -2, -10, 6, -16, 12, 8, 0, 9, -10, -7, -4, -4, 7, -8, 8 },
+ { -20, 45, 10, -14, 4, 16, 8, -9, 1, -8, 10, 5, -7, -2, 2, -5,
+ -1, 0, -5, 4, -6, -2, 4, 1, 3, 4, -4, 2, -2, -2, 5, 1 },
+ { -20, 26, -4, 1, 7, 4, -8, 1, -5, -13, 2, 13, -7, -3, 6, -6,
+ 22, 0, 5, 11, -4, -11, 8, -9, 2, -2, -4, -2, 2, -13, -4, -8 },
+ { -28, 18, 17, 3, -8, -23, -16, -6, 5, -10, 14, 10, 5, -1, -8, 4,
+ -2, 13, -3, -2, 3, 4, 3, -2, -3, -4, 0, 1, 3, 4, 0, 4 },
+ { -12, 32, -6, -16, 18, 12, -16, 0, 7, 13, -4, 5, -8, -1, -3, 4,
+ 6, -2, -1, -13, 4, -1, 3, 12, -3, -10, 1, 6, 8, -11, -2, 4 },
+ { -18, 26, 2, 5, 0, -9, -17, 14, 5, 1, 7, -3, -8, -3, 11, 7,
+ -5, -12, -8, 7, 0, -7, 2, -12, -9, 13, -11, 9, 6, -11, -5, 11 },
+ { -24, 22, -15, -9, 8, 1, -7, -12, -9, 3, 11, 15, 14, -11, 12, -15,
+ -5, 7, -2, 0, -8, 3, 3, -1, 2, 11, -11, 14, -6, 13, 1, -6 },
+ { -20, 28, 18, -4, -6, -5, 12, 14, 2, 10, -13, -6, -8, -6, -13, -1,
+ -26, 22, -3, -14, 6, 0, 10, -15, -13, -9, 6, -7, 1, -5, -4, -1 },
+ { -19, 26, -8, -3, -14, -6, -9, -4, -8, 15, -8, 3, -12, -4, -2, -7,
+ -5, 3, 13, -3, -4, -25, 4, -1, 5, -12, -1, -13, 5, 2, 0, 6 },
+ { -18, 43, 14, -8, 1, -23, -2, -2, 1, 3, -7, 0, 0, 8, -1, -3,
+ -5, 1, 5, 2, 0, -2, -2, -2, 1, -1, -1, -7, 0, 3, -3, 9 },
+ { -11, 30, 10, -14, 3, 1, 10, -11, 1, -7, -4, 14, 2, 1, -9, 1,
+ -11, -2, -7, 5, -11, 1, 3, 14, 1, -16, -8, 3, -5, 7, -4, 4 },
+ { -18, 24, 6, 3, 8, 7, -22, -7, -7, 3, -8, 4, 23, 9, 3, -1,
+ 3, 6, 7, -1, -7, 6, 4, 1, -3, 1, -6, -1, 2, -7, 3, 3 },
+ { -15, 38, -7, -1, -11, 2, -17, -24, 24, 8, 7, -4, -5, 2, 2, -7,
+ 1, 4, 0, -9, 5, 0, -1, 1, -1, -5, -6, 3, 0, 7, 8, -3 },
+ { -14, 22, 1, -5, 9, -12, -9, -5, -6, 5, 7, 8, -1, -4, -9, -3,
+ -33, -16, -9, -1, 12, -11, 17, -7, -3, -1, -7, 3, 2, -3, 16, -4 },
+ { -14, 20, 6, 4, -10, -4, -4, -4, 1, -7, 2, 6, 8, -12, 4, 1,
+ -1, 12, 10, 3, -14, -10, -3, 18, -2, 33, -5, -17, 17, -5, 9, 7 },
+ { -12, 23, 13, 0, -11, -8, -11, 12, -5, -9, -16, 11, 6, 4, 12, -5,
+ 5, -13, 7, -12, -3, 1, 2, 12, 1, -4, -1, 5, 4, 11, -12, -3 },
+ { 15, 2, 14, 7, 1, 2, 1, 12, 10, 23, 4, 6, -20, -10, 4, 26,
+ -6, 13, 4, 3, 2, -11, 5, -7, -10, 4, 9, 1, 10, -4, 11, 4 },
+ { 17, 15, 31, 17, 18, 16, 11, 24, 2, 4, 2, 3, -8, -3, 7, -3,
+ -5, -7, -2, -6, -4, -5, -4, -1, -4, -2, -5, -6, 2, -1, 4, -2 },
+ { 16, 8, 15, 14, 3, 7, 21, 9, 8, 15, 21, 6, 8, 12, 5, -5,
+ 7, -3, 10, 2, -3, 8, 6, 0, 5, 5, 6, -3, 2, 4, 0, -5 },
+ { 5, -4, 6, 12, 6, 13, 24, 17, -5, 17, -1, -6, -7, -10, -8, -18,
+ 3, -2, 2, 7, -15, -11, 12, -3, -2, -2, -4, -7, 2, 0, 5, 5 },
+ { 10, -6, 8, 11, 12, 20, 22, -11, -3, 15, -3, 15, -2, -2, 0, 2,
+ 5, -8, 4, -5, -9, -4, -1, 2, -1, -3, 1, 3, 13, -1, 9, 7 },
+ { -5, 8, 5, 11, 14, -5, 14, -9, 2, 35, 8, 15, 1, -2, 2, -2,
+ 4, -9, -3, -14, -12, -2, -2, -4, -2, -8, -3, 1, -6, 3, 10, 0 },
+ { 16, 0, -6, 15, -3, 4, 4, 3, 3, 20, 5, -4, 10, 9, -9, -3,
+ -10, -2, -7, 11, -11, -10, 17, -1, 3, -15, 2, 9, -15, -10, 16, 10 },
+ { 14, 4, -7, 19, 3, 0, 19, 8, 16, 34, -9, 6, -13, -1, 6, 5,
+ -1, -2, 4, 3, 2, 1, 1, -1, 0, -7, 2, -1, 1, 0, 6, -1 },
+ { 1, 6, 9, 13, 9, 10, 15, 16, 10, 18, 13, 17, 3, -1, -7, 2,
+ -15, -11, -10, -4, -13, -6, -17, -13, -6, -14, 1, -10, 6, 4, -1, -1 },
+ { 13, 1, 7, 10, 14, 13, -7, 5, 5, 28, 14, 14, -2, 2, 3, -3,
+ -13, -4, 10, -9, 19, -4, -3, 4, -5, -5, 0, 5, -5, 0, 3, -4 },
+ { 1, 0, 6, 22, 9, 18, 18, -3, 5, 10, 12, -2, 1, -3, -8, -12,
+ 9, -10, -7, 1, -1, 19, 0, 2, -8, -11, -10, 9, 6, 11, 0, 3 },
+ { 10, 11, 19, 44, 0, 14, 1, -7, 6, 22, 2, -1, 9, 2, 0, -4,
+ 4, 0, -6, -6, 3, 0, 0, -2, 2, -5, 1, -2, 0, 1, 1, 1 },
+ { 5, 7, 0, 32, 30, 26, 5, 4, -7, -3, 15, -6, 3, -10, 7, 6,
+ -8, -7, 2, -13, -5, -1, -3, 7, 3, -2, -8, 0, 6, 4, 5, 0 },
+ { 9, 8, -2, 4, 2, 11, 4, 29, -5, 14, 8, -5, -14, 8, 0, 9,
+ 8, -10, 5, -15, -6, -9, 9, -1, 18, -16, 9, -21, -3, -13, -2, 8 },
+ { 25, 7, -9, 23, 20, 18, 6, 16, -9, 8, 8, -5, 11, 13, -8, 7,
+ 4, 10, -2, -1, -7, -9, -7, -9, -4, 1, 1, -5, -10, 8, 4, -5 },
+ { 9, 2, 16, 14, -5, 14, 1, 0, -21, 17, -1, 9, 12, -3, -3, 4,
+ -4, 14, 10, 3, 0, -10, 7, 4, 4, -11, 2, 4, -1, -3, 9, -1 },
+ { 17, 8, 11, 26, 15, -3, 14, -1, 12, 9, 10, -8, 8, -18, -11, -3,
+ -14, -7, 7, -3, -3, -4, 1, -7, -3, 2, -3, 16, 10, 0, 9, 6 },
+ { 9, 8, 3, 8, 18, 14, 11, 1, 10, 6, 1, -4, -16, -2, 14, -2,
+ 1, 8, 12, 14, 3, -3, 8, 8, 12, -15, 3, -3, 3, -2, 14, 10 },
+ { 22, -3, -11, 13, -7, 11, 4, 11, 3, 14, 0, -6, -2, -9, 4, 2,
+ -2, 0, -5, -27, -10, 3, -1, 5, 8, -24, -3, -11, -3, 2, 11, -1 },
+ { 19, 2, 8, 36, 5, -6, 3, 15, -3, -4, -5, 14, -10, 1, -12, -10,
+ -3, -4, 3, -2, 1, -8, 4, 3, 5, -3, 0, 4, 8, -2, 8, 4 },
+ { 8, 14, 15, 9, -4, 10, 5, 11, 9, 10, 8, 9, -15, 15, 6, -8,
+ -10, -13, 5, -8, -20, -13, -6, -11, -1, -3, -6, -4, -1, 0, 13, 15 },
+ { -2, -1, 9, 12, 2, 2, 13, 3, -23, 33, 15, 2, -4, -1, 3, 8,
+ 8, 6, 6, -7, 8, 6, 9, -1, 3, -8, 0, -4, 1, -8, 11, -1 },
+ { 6, 5, -6, 16, 2, -3, 31, 21, -9, 12, 0, -1, -4, 1, -12, 3,
+ -13, -18, 2, -11, -9, 2, -8, -6, 11, -3, -1, 0, -1, 0, 13, 5 },
+ { 5, -1, 2, 0, 25, 5, 10, 16, -5, 21, 14, 12, 13, 2, -5, 5,
+ 5, -3, -2, -14, 0, -12, 7, 11, -1, -7, 19, -1, -1, -1, 8, -1 },
+ { 10, 7, 3, 11, 0, 8, 22, 3, 3, 19, -4, 12, 15, 9, 5, 15,
+ 2, 1, 2, -10, -10, 0, 2, -1, 0, 1, -12, -1, 21, 16, 9, -7 },
+ { 11, -4, -5, 24, -7, 11, 20, 11, -15, 18, 5, -13, -15, 0, -5, 9,
+ 1, 0, -1, -9, 4, -8, 6, -8, 1, -2, -7, 20, 9, 3, 9, 3 },
+ { 20, 0, -12, -6, 9, 31, 9, 12, 8, 27, 15, 7, -16, 5, -3, -7,
+ -1, -9, -2, -7, -3, 4, -8, -3, 3, -6, -2, -2, -3, -6, -1, 2 },
+ { 6, -6, 48, 8, -3, 19, 12, 11, -7, 2, 3, 0, -1, 1, 8, -4,
+ 4, -6, 0, -4, -4, -3, 3, 6, 3, -13, -8, 5, -3, -7, 8, 5 },
+ { 7, -2, 6, 11, 12, 2, 14, 4, -5, 12, 2, 9, 4, 2, 0, -1,
+ 2, 0, -15, -9, -16, -2, 8, -17, -5, -22, -19, -5, -1, -10, 1, -2 },
+ { 11, -9, 3, 12, 6, 6, 1, 17, -6, 19, 14, 7, -7, -1, -1, -9,
+ 9, -11, -17, 0, -6, 16, 0, 1, 9, -24, 3, 3, -9, -3, 3, -2 },
+ { 9, 0, 1, 8, 1, 7, 2, -5, -3, 8, -1, 7, 2, 6, -3, -6,
+ 5, -2, 6, -2, -4, -3, 0, -3, 13, -50, 1, -2, 2, 4, 4, 3 },
+ { 7, 0, 26, 21, -4, 2, 17, 8, 7, 11, -7, 1, -1, -15, -1, -15,
+ -11, -4, -17, -4, 1, -7, 3, 6, 3, -9, 2, 3, 6, 10, 6, 12 },
+ { 1, -2, 2, -1, -10, -4, 6, -3, -5, -2, -8, 2, 2, 2, 8, 0,
+ 1, 1, 6, 0, 11, 13, 3, 4, 0, -12, 11, -5, 19, 20, 2, 5 },
+ { 5, 3, -13, -2, 1, -12, 11, -7, -12, 7, 10, 0, 7, 0, -2, 4,
+ -6, -9, -11, -12, -23, 12, 10, -3, 0, 6, 19, -1, 24, 18, 9, 12 },
+ { 6, -3, 2, 5, 2, 2, -2, -5, -8, -11, -4, 3, -8, -4, 5, -3,
+ -16, -4, 3, -12, -4, 3, 32, 7, 2, 8, 32, -18, -1, 12, 1, 7 },
+ { 0, -8, -1, 0, -8, 7, -8, -1, -1, 4, -12, -1, 3, 0, 1, -18,
+ 8, 8, -14, -10, -11, 19, 9, 5, -7, 6, 8, -4, 26, 12, -1, 6 },
+ { 3, 5, -14, 7, 14, 8, 20, -13, -16, -10, -2, 17, -7, 4, -8, -9,
+ 14, -5, 3, -4, -12, 7, 14, -10, -19, -20, 35, 8, 13, 14, -2, 9 },
+ { -2, -4, -1, 1, -3, 0, -1, 1, 2, 2, 6, 0, 0, 4, 5, -2,
+ 3, 3, 3, -2, -7, -3, -3, -1, 6, -2, 29, 22, 13, 34, 0, 14 },
+ { -3, -9, 3, 1, 5, -4, 2, 0, 7, -9, 0, 2, -5, -3, 0, 6,
+ -1, -1, -1, 2, 2, 4, 8, 7, 20, -6, 7, 16, 33, 20, 6, -1 },
+ { -11, 1, -3, -3, -11, 3, -9, -25, -1, -16, 4, -8, 15, 1, -2, 7,
+ 8, 23, 2, 18, -13, 16, 3, -7, 6, 3, 16, -8, 12, 16, 3, 4 },
+ { 0, 5, 5, -5, 1, -1, 2, -3, -2, 1, -13, 2, 2, 10, 6, 7,
+ 18, 18, 7, 9, 8, 9, 21, 14, 7, 12, 15, 14, 15, 12, 11, 5 },
+ { 1, -5, 11, -2, 17, 8, 3, 0, -1, 6, 11, -7, 6, 6, 7, 5,
+ -15, 14, 1, 11, 4, 10, 12, 1, 2, 4, 30, 1, 11, 1, 6, 13 },
+ { 2, 4, 3, -7, 5, 8, -11, 7, -5, 9, -10, 6, 8, -10, -3, 10,
+ 1, -29, -4, -26, 5, -8, 13, 4, 3, 6, 35, 1, 3, 6, 3, 0 },
+ { -2, 1, 0, 0, -1, -3, -7, -3, -9, -3, -1, -6, 3, 4, 4, 0,
+ 5, -1, -2, -2, -1, -4, -10, 8, 0, -6, 10, -4, 46, 12, 2, 28 },
+ { 4, -1, 4, 1, 0, 4, -2, -2, -2, -1, 2, -4, 1, 5, 0, -3,
+ 1, 1, -2, 0, 1, -2, -1, -1, 3, -6, 35, -11, 13, 53, -3, -1 },
+ { -5, -2, 0, -13, -16, 5, -12, -11, 1, -30, 3, -18, -24, -8, -5, -19,
+ 1, -3, -8, 7, -7, -8, 15, -19, 4, 10, 30, 24, 6, 1, -9, 10 },
+ { -4, 8, -7, -4, -6, 12, -1, -9, -4, 2, -9, 3, 2, -2, 4, 2,
+ 22, 9, 4, -5, 0, 5, -2, -9, -3, 1, 18, -12, 18, 16, 4, 16 },
+ { -5, -8, -3, -5, -3, 6, -7, -3, -2, -5, -3, 1, 2, 2, 4, -6,
+ 10, 3, 12, -3, 20, 0, 27, -4, 16, 5, 18, -3, 23, 4, 12, 11 },
+ { 0, 1, 0, 1, -2, 1, 2, 1, -1, 0, -2, 2, -2, -4, 1, -2,
+ -2, -1, -5, -2, 0, 0, -2, 2, 9, 7, 63, 5, 12, -1, 1, 0 },
+ { 4, -3, -7, -5, -11, -5, -12, -10, -10, -12, -15, -12, -14, -14, 1, 1,
+ 10, -10, 16, 6, 2, 9, 11, 9, 9, 8, 12, -1, 13, 12, 6, 3 },
+ { 7, -3, -2, 4, 6, -8, 2, -3, -12, -5, -9, -8, -10, 15, -2, -4,
+ 8, 9, 7, -13, -18, 34, -5, 7, 12, 22, 16, -11, 13, 25, -15, -11 },
+ { -3, -2, 0, -4, 1, 0, -3, -13, -7, 13, 12, -7, -10, 13, 19, 6,
+ 16, 15, -12, -15, -3, 34, 1, 5, 1, -9, 11, 21, 8, 17, -5, -6 },
+ { 3, -5, 0, -4, 0, 4, -11, 4, -7, -3, -1, -8, 3, -2, 2, 1,
+ 11, 5, 6, 14, -3, 2, -4, -7, 0, 31, 15, -2, 24, 11, 5, 4 },
+ { -1, -4, -9, 5, -8, -18, -4, -9, -20, -18, 7, -14, -16, 3, 8, -3,
+ 29, 11, -13, -13, 7, 1, 17, 6, 6, 21, 11, 1, 14, -8, 2, 5 },
+ { -3, 8, -10, -6, 12, 2, 1, 3, 3, 3, 3, -6, -8, -14, 15, -5,
+ 16, 4, 16, 0, 7, -1, 0, 16, 2, 1, 22, 4, 19, 13, -11, 1 },
+ { 2, -3, 10, 20, -4, -1, -8, 5, -8, -9, -6, -2, -4, -7, 8, -10,
+ 0, 8, -6, 1, -8, 14, 13, 5, 17, -6, 26, -1, 7, -1, 0, 12 },
+ { -4, -7, -31, -2, -7, -1, 5, -5, -5, -12, 4, -7, -6, 3, 15, -2,
+ 5, -2, 7, -1, 10, 7, 8, -1, 14, 20, 14, 9, 16, 16, 8, 24 },
+ { -7, 0, -3, -6, 1, 3, -13, -6, -4, -4, -5, -9, -1, -10, -4, -8,
+ 2, 0, -1, 1, 24, 24, 21, 31, 5, 2, 11, 12, 7, 4, 3, 6 },
+ { -3, -5, 6, -4, -3, -1, 2, -1, -2, 1, 0, -8, -1, 2, 0, -4,
+ 6, 22, -1, -5, 8, 12, -1, -2, 28, 27, 20, -27, 14, 1, 2, -3 },
+ { 1, -5, -2, -2, 6, -2, 9, 1, -2, -5, 3, 4, 11, 5, 2, 8,
+ -3, -1, 1, -2, -3, -5, 5, 8, 49, 12, 8, -3, 9, 20, 12, 17 },
+ { -6, 0, 1, 7, 0, 9, -2, -4, 8, 0, -2, -10, 0, 7, 21, -1,
+ 0, 1, 17, -7, -5, 2, 4, 16, -2, 17, 14, -20, 15, 14, 4, 15 },
+ { 0, 3, -4, 9, -4, 0, 6, 4, -6, -6, -5, -7, 2, -9, -10, -2,
+ -5, 0, -3, -21, 9, 14, -11, 13, 29, 2, 25, 4, 22, -1, 2, -3 },
+ { 2, 12, -11, 2, 16, 9, -4, 7, 1, -10, -15, 11, -4, 3, -2, 4,
+ 4, -5, -10, 1, 4, 19, -15, 6, -4, -2, 30, -7, 11, 21, -12, 5 },
+ { -2, -3, -2, 4, -1, -5, -3, -7, -5, 1, 0, -6, 1, -6, 7, 0,
+ 8, -7, -3, -2, 2, 14, 2, -3, -26, -1, 26, 22, 32, 1, -2, 6 },
+ { 1, -38, -1, -20, -2, -3, -6, -4, 2, 2, 7, 0, 3, 5, 3, 10,
+ 6, 1, -3, -5, 7, 5, -5, -4, 8, 3, 1, -14, -1, -9, -5, -4 },
+ { -5, -26, -7, -19, -10, -5, -11, 5, -11, -25, -8, -14, -9, -16, -8, -6,
+ -17, -14, -1, -1, 6, 2, 2, 2, 3, 0, 2, 8, -8, 3, 0, -3 },
+ { 17, -49, -3, -23, -1, 11, 7, 3, 4, -4, 0, 0, -1, 4, 2, 4,
+ -2, -4, 2, -2, -1, -2, 2, 0, 0, -1, 0, 0, 1, 2, 0, 0 },
+ { 4, -34, -6, -9, 1, 21, -7, 3, -2, -1, -3, 18, 2, -16, 7, -3,
+ 8, 7, -5, 7, 2, 4, 8, -6, -7, -2, -5, -1, 4, 1, 2, -4 },
+ { 5, -29, 13, -2, -14, 3, 1, 18, -15, 4, -8, 8, -10, 8, 2, 1,
+ -8, 15, 3, -10, -4, -4, -2, 0, -3, -4, 2, -3, -4, -3, 12, -6 },
+ { 13, -20, 3, -18, -17, 4, -14, 13, 28, 11, -8, -6, 16, 6, 0, 10,
+ 3, 4, -9, 13, 5, -7, 12, -5, 0, -7, 5, 1, 3, 3, 2, 1 },
+ { 3, -27, -5, -11, -21, -11, -12, 0, -5, 7, -22, 1, 3, 5, 0, -5,
+ 8, 7, 1, -5, -7, 2, -5, 4, 1, 3, -8, -2, 0, 4, -2, 6 },
+ { 31, -45, 0, -1, -12, 1, 2, -6, 4, 3, -1, 3, 3, 0, 5, 3,
+ -5, 12, 4, 6, 2, 1, -2, 1, 3, 2, 5, 2, 2, 2, 3, -1 },
+ { 9, -45, 6, 5, -1, -17, -2, 18, -3, 2, 0, 1, 0, -1, 10, 8,
+ -7, -2, -5, -8, 6, -1, 0, 4, 6, -3, 12, -1, -2, 0, 5, -7 },
+ { 3, -26, -2, -12, -12, 2, -10, 16, -3, 12, 4, 5, 11, 8, -16, -17,
+ -2, -3, -3, 2, 5, -9, 13, 1, 10, 11, 3, 5, -2, 2, 2, -7 },
+ { 8, -26, 32, -7, -5, 22, 2, 14, -10, -8, -7, 3, 3, 7, 0, -5,
+ 0, -1, -3, 0, 8, 4, -5, -7, 6, -1, 4, 8, 1, 1, 7, -6 },
+ { 4, -31, 2, -14, 2, 0, 1, 8, -6, -1, 17, -3, 13, -6, 5, -10,
+ -2, -10, -2, -10, -3, 7, 1, 5, -8, 8, -14, -3, -15, 7, -10, -6 },
+ { 16, -27, 13, -4, -23, 7, -9, 6, -7, 5, 4, 2, -1, -3, 23, -18,
+ 7, 0, -3, 4, -3, 9, -6, -2, -1, 8, -6, 2, 6, -3, 2, -2 },
+ { -1, -35, -2, -8, 11, -1, -7, -3, -2, 11, 7, 6, -6, -10, 9, 6,
+ -3, -5, -6, -3, 9, 16, -16, -9, -20, 12, 3, 5, -3, 1, -9, 4 },
+ { 2, -24, 1, -12, -16, 5, -4, 3, -4, -1, -11, -11, -8, -14, 14, 10,
+ -8, 20, 8, -3, -11, 1, 1, -4, -4, -7, -3, 15, 2, -6, -2, 7 },
+ { 9, -21, 2, -19, -7, -5, -8, 25, 3, 17, 5, -3, 9, -12, 8, 2,
+ -4, 3, 3, 1, 11, -9, -4, -3, 4, 3, -22, 6, 4, 6, 11, -5 },
+ { 16, -23, 13, -17, -21, -12, 5, 9, -20, 7, 6, -6, 0, 2, -9, 6,
+ -6, -13, -7, -1, 5, -3, 5, -7, -10, 1, 0, 8, -9, 11, 0, -8 },
+ { 10, -26, -9, -7, -19, -4, 6, 16, -7, 5, -4, 4, 8, 0, 4, -1,
+ 6, -7, 1, -8, -11, 10, -14, 0, -16, 6, -3, 5, -1, 14, 12, 1 },
+ { 8, -27, 12, -14, -1, -1, -19, 10, -11, 21, -14, 9, -8, -3, 8, -1,
+ 12, -13, 3, -4, -2, 0, -9, 0, -7, 2, -3, 12, 1, -3, 3, 1 },
+ { 18, -20, -14, -14, -16, -3, -24, 6, -17, 2, -3, -11, 2, -3, 12, 10,
+ 10, 1, 10, 7, 8, 5, 5, 4, -1, 7, 2, 2, 0, 4, 7, 0 },
+ { 0, -30, 9, -16, -18, 15, 12, -3, 4, -4, -5, -11, -4, -12, -10, 0,
+ 2, -2, -4, -1, 2, 0, -1, -6, 2, -3, 4, -5, 7, 3, 5, 7 },
+ { 25, -24, -1, -6, -9, 6, -13, -2, 3, 15, -3, 11, 4, -8, -11, 2,
+ 0, -9, -2, 7, 4, 8, 5, -8, 5, 6, -1, -11, -15, -5, 0, 11 },
+ { 0, -34, -7, -11, -7, 9, -3, 19, 4, -8, 3, -11, 11, -3, -9, 12,
+ 9, 9, 2, 1, -7, 1, -3, 0, -6, -2, -1, 3, 0, -7, -2, -5 },
+ { 6, -34, -4, -5, -3, -9, 2, 9, -1, 9, -5, -3, -26, -12, 8, -6,
+ -7, 11, -8, 4, 4, 1, -1, 0, 8, 9, -4, 7, -1, 1, -3, -1 },
+ { 3, -30, 5, 6, -10, 3, -7, 6, 3, 3, -26, -19, -3, 1, 7, 5,
+ -4, -5, 6, 10, 13, -10, 4, -7, -4, 5, -3, 9, -6, 3, 9, 5 },
+ { 4, -24, 9, -19, 2, -4, -5, 8, -3, 2, 0, -15, -1, 9, -4, 22,
+ 6, 9, 3, 7, 11, -9, 0, -3, 4, 5, -5, 10, -8, 5, -7, -3 },
+ { 8, -27, 7, -3, -1, 2, -9, 13, 7, 12, -4, -6, -6, 5, 0, 7,
+ 5, 1, 15, -3, -4, 0, -5, -2, 7, -5, -7, 1, -2, 13, -8, 13 },
+ { 17, -22, -15, -11, -8, 16, -14, 18, 2, -1, 14, -7, 14, -6, -6, -7,
+ -8, 17, 6, 4, 4, -7, -5, -9, -14, -6, -1, 9, -3, 1, 6, -5 },
+ { 25, -30, 2, -12, -13, 18, -18, 16, 8, -3, 10, -8, -3, -1, -6, 3,
+ -5, -7, 4, 6, 7, 1, 1, -11, -5, 6, 2, -4, 9, -1, -5, -2 },
+ { 7, -23, 7, -15, -1, -3, -1, 0, -10, 12, 2, 5, -4, 0, 4, 6,
+ -1, 5, -9, -1, -1, -7, 1, 17, 9, -17, -16, 8, 4, -14, 11, 14 },
+ { 0, -31, 7, -13, 3, -11, -7, 6, 1, -11, 8, -7, 15, -3, 16, -11,
+ -1, -15, 16, -3, 5, 0, -2, -2, -6, 11, 5, 6, 5, -5, 6, 3 },
+ { 13, -24, -2, -20, -10, 7, -3, -1, 15, 2, 6, -5, -7, -10, -20, 1,
+ -4, 14, 8, -2, 3, -13, -3, 1, -4, 1, -3, 2, 8, -7, 16, -4 },
+ { 1, -2, -2, -3, -4, -7, 0, 3, 6, 7, 3, 2, 1, -2, -1, 0,
+ -6, 4, 2, -4, -3, -4, 5, 9, 5, 0, -3, -3, -4, -7, -31, -50 },
+ { -1, -3, 7, 2, -1, 2, 4, 6, 0, 10, -2, 0, -20, -6, -3, 9,
+ -20, -22, -1, -1, 15, 9, -12, 10, -13, -20, 12, 3, 5, 6, -7, -26 },
+ { 0, 4, -2, -14, -12, 6, -13, 11, -10, 3, 22, 6, 16, -2, -5, 1,
+ -3, -11, 0, -7, 5, -5, 0, 1, -1, -6, 8, 8, 10, 9, -5, -27 },
+ { -5, 10, -2, 7, 9, -9, 5, -9, 5, 4, -15, 14, 1, 3, -10, 5,
+ 0, -2, 7, 3, -13, 6, 9, -6, 5, -14, -17, -1, 11, 14, -2, -26 },
+ { 0, 6, -3, 0, -8, 6, 0, 1, 4, -8, 2, -5, 4, 7, 15, 11,
+ 9, 19, -2, 14, -8, 7, -1, 3, -3, -3, -10, -2, 12, -2, -12, -29 },
+ { -12, -5, 0, -3, -2, 6, 3, -3, 2, -2, 1, 11, 2, -7, 5, 1,
+ 2, -2, -14, 0, -1, -5, 3, 8, -28, -26, 6, -6, 3, 8, -10, -27 },
+ { -1, -3, 6, 2, 4, 15, 1, 0, 2, -2, -2, 13, 3, 6, 0, 6,
+ -1, -4, -1, -5, 8, -1, 5, -5, -15, 11, -8, -5, 14, -6, -14, -29 },
+ { -5, -6, 0, 1, 0, 6, -3, 2, -5, -1, 5, -3, 2, -10, 3, 4,
+ 3, 0, 13, -3, -1, 4, -4, -6, 2, 9, 8, 2, -3, 28, -11, -31 },
+ { 1, -4, -10, -9, -4, -3, -15, -6, 1, 5, -3, -6, 5, -6, -22, 27,
+ -13, 5, 3, -7, -4, 20, -7, -12, -1, -24, -4, -13, -8, -11, -15, -21 },
+ { -6, -4, 19, -6, 2, 11, -6, 1, -3, -10, 9, -9, 12, -10, 2, 1,
+ -9, 1, 15, 7, -5, 5, -29, -35, 4, -30, 9, 9, 19, 17, 2, -17 },
+ { -3, 3, -3, 1, 2, 5, -1, 5, -2, -3, 1, -3, -8, 3, -4, -2,
+ -4, -1, 12, 0, 2, -8, -6, -4, 16, -1, -14, -2, 25, -6, -15, -36 },
+ { 0, -1, 3, -4, -4, -1, 7, -4, 8, 0, 10, 9, -4, 1, 10, -1,
+ -3, -13, -5, -4, -1, -4, 8, 11, 14, -7, -5, 16, 12, 13, -1, -28 },
+ { 1, -2, 2, -3, -8, 10, 4, 9, 12, 3, 5, 0, 8, -3, -6, 2,
+ 16, -11, 11, 0, 1, 6, 1, 18, -10, -16, -1, -4, 5, -14, -15, -20 },
+ { 1, -12, 5, 4, -7, 8, -1, -17, -2, -9, -14, -11, 6, -9, 5, -4,
+ 3, -2, 7, 18, -5, 5, 6, -1, -11, -2, -10, -3, 8, -3, -2, -32 },
+ { -12, 5, 20, -5, -6, -11, -6, -6, -13, 4, -6, 19, -8, 2, 3, -9,
+ -4, -4, -1, 9, -1, 21, -1, 7, 15, -10, -1, -3, 9, -3, 2, -24 },
+ { 0, -3, 2, -6, 4, -1, -9, -2, -1, -3, 6, -1, -5, -6, -5, -8,
+ 0, -2, -6, 9, -4, 3, 2, -13, 1, -7, 23, -13, 4, -3, -15, -33 },
+ { -7, 2, -15, 11, -10, 14, 0, -11, 3, -1, 12, -4, -4, 9, 11, -13,
+ -13, -3, -14, 1, 3, 6, -5, 8, 0, 5, 5, -10, 4, 5, -6, -30 },
+ { -6, 4, 0, -5, 4, 1, -1, -1, 3, 6, 5, -2, -5, 0, -2, 5,
+ -4, -2, -4, -2, 4, 7, -7, -1, 1, -4, -3, -19, 37, 12, 10, -40 },
+ { -7, 2, -7, -12, 17, 11, -7, 2, 2, 3, 1, -1, 3, 4, -2, -5,
+ 9, -9, 6, 4, 9, 12, 11, -5, 2, -1, 0, 9, 5, -7, -2, -24 },
+ { -7, 6, 1, 3, 1, 0, 6, 0, 4, -12, -2, -2, 1, -9, 10, -2,
+ 11, -1, 21, -12, 15, -5, 10, -5, 5, -5, 14, -6, 5, -7, -3, -29 },
+ { -2, 0, -5, -2, -3, 1, -3, 0, 4, 2, 3, 0, 2, -2, 7, -2,
+ 3, -5, 2, -1, 6, -4, 0, -3, 8, -11, 19, -8, 22, -34, 13, -35 },
+ { -1, -3, -1, 9, 11, -3, -3, -1, 7, 18, 11, -5, 2, -12, -11, 18,
+ 9, -5, 1, -6, -9, 12, 1, -3, -3, -9, -14, 9, 9, 8, -6, -26 },
+ { 0, 5, -5, -1, -1, -2, 4, 6, 8, 2, -1, -2, 5, 1, -5, -4,
+ 1, 1, 18, 1, 7, -10, 3, -2, 12, -1, -15, 9, 12, -14, 13, -38 },
+ { 3, 0, -8, -1, 0, 8, -9, -3, -8, 16, 3, 16, -5, -9, 0, -1,
+ -7, -1, -4, 13, 7, 0, 1, 2, -1, -16, 0, -2, 1, 8, -8, -28 },
+ { 7, 9, -5, -3, -2, 2, 0, 3, 11, -6, -4, -2, -2, -5, 28, -18,
+ -6, 2, 15, -10, -15, -10, -2, 0, -2, -2, 4, -3, 7, 11, 5, -30 },
+ { 9, 0, -7, -1, -4, -7, 2, 2, 9, -2, 2, 3, -8, -6, -6, 3,
+ -10, 4, 10, 5, 21, -4, 14, -18, 1, 3, -10, -2, 6, 14, -8, -26 },
+ { -14, -1, 2, 3, -3, 7, 1, -22, -1, -1, 0, 1, 12, -14, 3, -5,
+ 0, 10, -3, 1, -5, 12, -3, 10, -8, -22, -11, -13, -7, -10, -13, -25 },
+ { -2, -5, -4, -4, -9, -18, 9, -3, -5, 17, 13, 5, 6, 11, 3, 8,
+ 20, 4, 2, 9, 8, 5, 6, 1, 7, -7, -6, -2, -7, 0, -17, -23 },
+ { -5, -5, 2, 0, 6, 2, -2, 2, -3, 4, 4, 0, -5, -2, -4, 6,
+ 8, 10, -1, 1, -5, 5, -14, -2, -11, 8, 6, 25, 7, -1, 0, -43 },
+ { -4, 0, 4, -2, 7, 0, 3, 17, 5, 2, -5, 1, 21, 3, -2, -10,
+ -16, -9, 7, -12, 9, -8, 2, 5, -5, -10, -2, -11, -5, -1, -9, -30 },
+ { -2, 3, 1, -4, -1, 0, 8, 1, 12, 4, -1, -1, 3, -17, 13, 9,
+ 0, 7, -6, -5, 9, 1, 5, 4, -10, -18, 0, 14, 11, -4, -16, -28 },
+ { -1, 0, 2, -1, 4, 1, -1, 1, -1, -2, -1, -2, 3, 0, 0, -1,
+ -1, 1, 2, -2, 3, 3, -2, 4, -2, -1, -6, 1, -1, -1, 6, -70 },
+ { 7, 3, -11, -1, 12, -4, -14, 4, 4, -4, 4, -2, 2, -12, -4, 15,
+ -17, -4, -3, 6, 8, -5, 22, -22, 5, -11, 15, -4, 4, -1, -21, -1 },
+ { 10, -2, -13, 11, 4, 14, 4, 9, 8, 8, 19, 15, 14, 15, 5, 10,
+ 8, 15, -5, 4, 14, -8, 1, 1, 2, 1, -1, -3, 21, 8, -29, 13 },
+ { -6, 0, -6, 6, -1, 2, 8, -4, -5, 4, -4, -5, 0, -2, -4, 0,
+ 9, -2, 1, -2, 26, -19, 21, -10, 4, 1, -8, 5, 22, -10, -13, 15 },
+ { 11, -5, 1, 0, 6, 3, 7, -2, -2, -3, -5, -1, -2, -6, 1, 1,
+ -8, -5, -13, 13, -2, -3, -1, -9, -28, 4, 2, -11, 18, -20, -24, 9 },
+ { 7, 4, -3, 6, 6, -6, -7, -5, -7, -4, -4, 0, -7, -5, -6, -5,
+ 2, -13, -12, 2, 0, 5, 18, 15, -13, -7, 13, -20, 16, -10, -19, 6 },
+ { 5, -8, -1, 5, 10, 2, -1, -10, -11, 23, 8, -5, -8, 4, -5, -4,
+ -5, -5, -11, -8, 5, 1, 7, -9, -9, -6, 12, 14, 17, -12, -22, 3 },
+ { -5, -8, -3, 3, 12, -1, 0, -4, -5, 1, 1, 6, 1, 5, -5, 7,
+ -2, 7, 1, 6, 6, 2, 0, -5, 17, -4, -5, -24, 13, -20, -27, 14 },
+ { -1, 2, -3, 1, -3, 1, -3, 0, -2, 3, -2, 1, 2, -1, -2, -1,
+ -2, -5, 5, -2, 0, -7, 1, -6, 8, 8, 11, -5, 24, -43, -13, 2 },
+ { -2, 4, 7, -3, -4, 4, 13, -4, 0, 0, -2, 9, 0, -3, -6, 1,
+ -7, 1, -1, 10, 0, 5, -1, -24, 25, -15, 7, 2, 22, -10, -21, 0 },
+ { -5, 2, 6, -2, 13, 3, 5, -12, -11, 16, 6, 10, -5, 0, -3, 6,
+ 5, -5, -5, 10, 12, 10, 11, -7, 8, -14, 2, -15, 13, -14, -8, -3 },
+ { 5, 6, -7, -5, 5, 2, 9, 5, 0, -1, -4, 2, 8, 0, 3, 5,
+ -12, 3, -3, -6, 2, -1, -5, 14, 11, -20, -21, -25, 24, -1, -10, 6 },
+ { -5, 5, -2, 9, 4, -4, -1, -6, 11, -6, 5, 0, 2, -3, 6, -1,
+ -17, -18, -4, -13, 9, -1, 9, -7, -4, -8, 2, -3, 12, -31, -18, 5 },
+ { -7, -11, 6, -8, 4, -3, -12, 0, -1, -6, -3, 0, 5, 9, 7, 2,
+ 1, -8, -6, 8, 2, -5, 7, -1, 16, -10, 16, -12, 18, -1, -25, -12 },
+ { 3, -12, 1, 2, -2, -18, -8, -15, -10, -9, 2, -7, 11, -11, 2, -1,
+ -1, -1, -9, -6, 3, -14, -2, -1, 2, -13, -7, -9, 19, -5, -17, 2 },
+ { 7, 1, -8, 7, 17, -13, -10, 5, 7, 1, -6, 4, 9, -4, 0, 3,
+ 8, 1, -14, -9, 4, 7, -9, 0, 6, -5, -12, -2, 25, -2, -19, 1 },
+ { 7, -3, 6, -3, 1, 6, -7, 0, 10, 0, 4, -5, -17, -4, 4, -1,
+ 0, -3, -7, 19, 24, -1, 21, 8, 10, 9, 8, -1, 23, -2, -18, -2 },
+ { 3, -3, 0, 5, 8, -2, -9, 2, 9, 6, 19, 8, 2, 6, -9, -2,
+ -4, -3, -8, 7, -7, -8, 5, 4, 26, -6, 7, 18, 24, 0, -13, 4 },
+ { 0, -13, -11, -1, 3, -9, 5, 4, -7, 3, 0, 2, -1, 4, -5, 2,
+ 9, -2, -11, 15, 1, -21, 1, -1, 0, 4, -14, -4, 24, -16, -13, 1 },
+ { 1, -9, -8, 0, 0, -4, 11, -1, 14, 16, 0, 17, -2, -9, -12, 0,
+ -1, -14, -9, -14, 0, -2, 19, 4, 6, 4, 4, -11, 8, -17, -19, -5 },
+ { -3, 1, 2, 12, -4, -18, -1, -4, -7, 14, -3, 2, 0, -7, -8, 12,
+ -5, -9, 14, 12, -9, -2, 4, -6, 4, 18, -1, -25, 22, 2, -23, -5 },
+ { -2, 0, 0, 0, 1, 3, 5, -1, 5, -2, -2, 2, -3, 0, 1, 2,
+ 0, -1, 2, -1, -9, -6, -7, -4, -2, 4, -7, -5, 64, -3, -25, 4 },
+ { 12, -2, -3, 0, 8, -9, 13, -7, 6, -3, -12, 12, 15, -9, -4, 2,
+ 9, -4, -12, 3, 14, 1, 7, -15, 15, 0, -6, -12, 0, -3, -20, 6 },
+ { 2, -1, -4, 5, 9, 6, -7, 2, -2, -7, -2, 0, -1, -18, -4, -6,
+ -15, -5, 11, 5, -10, -1, 2, 7, 12, -19, -7, 8, 21, -4, -15, 4 },
+ { 4, 2, 5, 5, -5, 1, 3, 2, -8, 13, 0, -5, -2, -14, -11, 6,
+ 2, 17, 8, -13, 26, -2, 5, -15, -4, -14, 12, -9, 13, -21, -23, -4 },
+ { 2, -3, -2, -3, 3, -2, 6, 9, -9, 13, 4, 2, 12, -3, -3, 1,
+ -17, -22, -3, 4, 3, -2, 1, -9, 1, -6, 11, -13, 14, 0, -15, 6 },
+ { -16, -4, 17, -2, -20, -11, 11, 10, 5, -8, 16, 2, -17, -14, 11, 11,
+ -6, -11, -7, 12, 12, -10, -6, 5, 8, -4, -2, -5, 28, 3, -13, 4 },
+ { 0, -3, 3, -7, 6, 8, -12, 20, -19, 18, -11, 10, -5, 0, -9, 11,
+ 3, 0, -2, 9, -7, -5, 18, 3, -2, -16, 1, 6, 12, -7, -16, 1 },
+ { 4, 1, 5, -5, 15, 2, -8, 3, 5, -11, 15, -3, 8, -8, -1, 7,
+ 4, 7, -2, 6, -9, 5, 12, 2, 33, -2, -6, -18, 4, 0, -18, 11 },
+ { 3, -1, 1, -1, 0, 1, 4, -1, -5, 0, 1, 0, 4, 2, -1, 4,
+ -3, 2, 0, -2, 4, 6, -1, 6, 42, 19, -4, -37, 19, 1, -15, -4 },
+ { 2, 0, -5, 0, 10, 0, 0, -5, 3, 0, 0, -3, -3, 0, 2, -4,
+ -10, 2, -6, 4, 4, 1, 27, -7, 17, -34, 5, -9, 15, -16, -7, -5 },
+ { -2, 7, 7, -2, 9, -2, -15, 11, 11, 7, 5, 1, 15, 1, -9, 31,
+ 2, -15, 2, 4, 3, 4, -1, -8, 2, -7, 6, -17, 11, -14, -11, 2 },
+ { 1, 1, -11, 9, 9, -6, -14, -11, -10, 8, -3, 11, 16, -9, -8, -13,
+ -8, 9, 0, 6, 6, -2, 13, -8, -2, 3, 13, -3, 10, -6, -17, 4 },
+ { 14, 5, 4, -6, -12, 10, -7, 8, 21, -8, -30, 15, -2, 1, 11, -9,
+ -5, 1, 0, -1, -1, -6, -2, 3, -5, 7, 9, 5, -5, 2, 0, 1 },
+ { -1, 2, 20, -17, -15, 3, 3, 7, 11, -17, -13, -6, -3, 18, 17, -15,
+ -4, -4, -5, 22, 14, -14, -2, -10, -7, 11, 8, -7, -3, 0, -7, 11 },
+ { 7, -11, -7, -8, -14, 22, 5, 2, 6, 13, -12, -2, 10, 3, 0, -21,
+ -4, 20, 3, 10, 21, -10, -12, 8, 11, 2, -5, 2, 1, 3, -1, 15 },
+ { -1, -2, -1, -2, -13, 8, -4, 0, 7, -2, -17, 8, 18, 5, 3, 8,
+ -8, -2, 3, -4, 14, -18, -13, 14, 15, -13, -1, -2, 4, 11, 1, 12 },
+ { 13, -6, -4, -16, -17, 16, 21, -2, 5, -11, -9, 19, 21, -17, -3, -17,
+ 3, 12, 8, -12, -6, 1, -7, 9, 9, -7, -5, -1, -3, 5, -6, -4 },
+ { 11, 5, 12, -20, -6, 10, 4, 12, 8, -5, -10, 15, 13, 14, 10, -15,
+ -13, 1, 6, 14, 15, -17, -13, 4, -5, 10, 7, -6, -8, -3, -4, 12 },
+ { 25, -1, 7, -5, -7, 11, 1, 17, 13, -15, -14, -4, 5, 3, 8, -3,
+ -2, 2, 0, 6, 16, -12, -6, -4, 4, -3, 7, -10, -3, -7, -13, 7 },
+ { -8, 10, -3, -13, 5, 2, 4, 9, 9, -17, -13, 2, 11, 1, 6, -4,
+ 8, -10, 4, 1, 19, -15, -4, 12, 31, 7, -5, -17, -4, 9, -2, 7 },
+ { 14, -6, -6, -6, -14, 13, 17, -5, 4, -14, -9, 7, 7, -9, 3, -16,
+ -15, 11, 11, 6, 4, -11, -19, 3, 5, 8, 13, -14, -14, 3, -4, 12 },
+ { -2, -4, 10, -4, -7, -1, 27, 5, 2, -16, -18, 4, 12, -2, -3, -2,
+ -1, 1, -8, -12, 3, -4, 8, 15, 2, 4, 9, -13, -14, 9, -7, 5 },
+ { 4, 2, -10, -5, -7, 2, 1, 4, -1, -6, -15, 6, 1, 10, 5, -10,
+ -9, -1, 13, -3, 5, -21, -11, 8, 8, 5, 27, -21, -18, -5, -1, 15 },
+ { 11, 1, -16, -8, -11, 0, 5, -8, -12, -13, -17, 22, 4, -6, -1, -18,
+ -10, 0, 19, 2, -2, -8, -7, -3, 2, -2, -9, -17, -5, 4, 4, 10 },
+ { 8, -6, -19, -5, -4, 12, 14, 15, 10, -9, -1, -9, 19, 12, 0, -1,
+ 2, 4, 7, 9, 16, -16, -14, 9, -4, 3, 1, 0, -2, 10, -1, -1 },
+ { 12, -8, 12, -9, 0, 25, 7, 9, 2, -31, -9, -4, 15, 4, -5, 1,
+ -10, 11, 8, 10, 0, -6, 5, 11, -1, -6, 4, -10, -9, 6, 4, 5 },
+ { 14, 6, -17, -2, 17, 12, -9, 2, 0, -25, -14, 5, 20, 14, 8, -20,
+ 5, 2, -2, -3, 9, -13, -3, -1, -6, 3, 7, -6, 0, 2, 3, 1 },
+ { 8, 4, -15, -3, 10, 18, -4, 13, 8, -22, -10, 9, 19, -15, 7, -5,
+ -13, 12, -4, 9, 2, -9, -6, 0, 2, 1, -9, -6, 6, 1, -1, 11 },
+ { 4, 1, 4, -5, -10, 18, 7, 2, -4, -9, -11, 0, 32, -7, 4, -16,
+ -1, 0, 6, 3, 6, -3, -14, 16, 9, -2, 7, -1, 0, -5, 5, -3 },
+ { -3, 2, 3, -8, -6, 4, 6, 2, 4, -12, -15, 2, 8, 8, 9, -3,
+ -18, 6, 34, 11, 12, -15, -1, 2, 9, 2, -4, -4, 2, 4, 2, -3 },
+ { 18, -6, -12, -8, -1, 15, 20, -4, -1, -11, -5, 6, 6, -11, -15, -7,
+ 3, 7, 10, 2, 8, -10, -5, 8, 15, -5, 5, -17, -13, 13, 11, 7 },
+ { 8, -4, -6, -1, -14, -3, 6, -2, 1, -5, -1, 10, 10, -15, 5, 0,
+ -10, -4, -3, 7, -4, -19, -15, 27, 11, 18, 3, -19, -2, 6, 0, 12 },
+ { 12, 0, -5, 0, 4, -5, 1, 5, 10, -7, -11, 21, 29, 1, -2, 1,
+ -4, -11, -1, 13, 11, -20, -1, 4, 4, 4, -5, 6, -13, -2, 11, 9 },
+ { 2, -7, -7, -3, -10, -1, 20, 12, 1, -19, -19, -1, 5, 4, -7, -25,
+ 14, 1, -3, 2, 12, -4, -3, -3, -2, 6, 1, 0, 3, 2, 5, -1 },
+ { 12, -8, 3, -12, -10, 10, 13, 0, 23, -14, -18, 10, 0, 15, 3, -12,
+ -3, -5, 5, -4, 2, -14, -10, 8, 2, 9, -1, -11, -3, 5, 13, 2 },
+ { 9, -6, 7, -7, -30, 17, 6, 13, 1, -14, 0, -1, 6, -9, 8, 3,
+ -4, 0, -1, -7, -5, -13, -19, -3, -4, 4, -6, -2, -13, 1, -2, 3 },
+ { 10, 1, 3, -18, -26, 17, 4, -16, 4, -3, -13, -4, -6, -11, -4, -21,
+ 7, 8, 2, 5, 13, -6, 1, 5, 8, 7, 9, -6, -6, 1, -1, 2 },
+ { -3, -1, 0, -2, -2, 0, -1, 3, 4, -14, -8, -9, 13, 2, 50, -23,
+ -8, 8, 7, 11, 16, 3, -7, 0, -2, 6, 5, -1, 1, -2, 4, 3 },
+ { 1, 3, 1, 1, -6, 3, 6, 6, 2, -2, -3, 10, 2, -8, -5, -5,
+ 5, 4, 4, -2, 10, -8, -40, -1, 21, 8, 3, -4, -1, 13, 4, 7 },
+ { 2, 0, -4, -8, 5, 2, 7, -5, 5, -8, -4, -1, 12, 2, 12, -13,
+ -9, 0, 1, -12, 9, -43, 1, -5, 12, 1, 3, 6, 1, -1, 3, -2 },
+ { 6, -2, -1, 1, 0, 4, 8, 14, 4, -7, -23, -5, 23, -17, -6, -15,
+ -8, 7, 10, -1, 7, -16, 4, -6, 2, 3, -3, -3, -1, 8, -1, 4 },
+ { 10, 4, -4, 1, 7, -3, 2, 11, 4, -6, -3, 8, 5, 4, 1, -45,
+ -6, -4, 4, 2, 1, -14, -10, 1, 1, 6, 2, -8, -1, -3, 3, 3 },
+ { 1, -1, 2, -3, -8, 9, 3, 3, -2, -5, -8, 8, 7, -7, -4, -6,
+ 5, -9, 11, -2, 46, -5, -1, 9, -2, 0, 3, -5, -3, -5, 7, 0 },
+ { -4, 1, -2, -1, -11, 11, 8, -3, -2, -10, 0, 4, 9, 9, -17, -17,
+ -34, -4, -5, -7, -3, -12, -3, 11, 18, 3, -2, -5, -18, -5, -3, 6 },
+ { 7, -5, -3, 1, -4, -3, -5, -1, 2, 5, -2, 3, -10, 12, -18, -5,
+ -10, 12, -9, 4, -6, 2, 0, 16, -17, 15, 14, -12, -10, -2, -9, -1 },
+ { 4, -5, -3, -5, -3, -1, 7, 18, -7, 12, 3, 5, -8, -4, -20, 1,
+ -25, 1, -8, 13, -10, 8, -19, -1, -8, 10, 6, -9, -1, 0, 12, 4 },
+ { -4, 5, 0, -1, 2, 5, -8, -2, -6, 4, -8, 9, 3, 2, -7, 4,
+ -25, 13, -23, 10, 14, 15, -11, 3, -18, 4, 16, -4, 1, -10, -10, 3 },
+ { 5, -3, -1, -3, 4, 1, -3, -4, -5, 1, -12, 14, -7, 11, -15, 6,
+ -6, 24, -4, 13, -1, 15, -13, 8, 3, 7, -5, 2, 2, 0, 3, -7 },
+ { -3, 1, 0, 8, 6, -1, 6, 5, -5, -2, -12, 4, 0, -2, -3, 5,
+ -6, 0, -8, 9, -10, 4, -28, 12, -20, 11, -13, 7, -18, 1, -11, 1 },
+ { 1, -4, -15, 5, 0, -13, -5, 13, -11, 4, -4, -5, 5, -14, -16, 0,
+ -14, 5, -20, 12, 10, -7, -5, 6, 6, 22, 6, -4, -2, 3, 8, 11 },
+ { 13, -11, -2, 16, 16, -7, 0, 20, -7, -1, 0, 5, -9, 12, -2, -5,
+ -22, 5, -10, 12, -6, 11, 9, 21, -8, 15, 4, 0, -8, -4, -4, 10 },
+ { 18, -4, -13, 0, 1, -15, -1, -3, 2, 10, -1, 6, 1, -4, -20, -5,
+ -8, 6, -8, 17, -5, 5, -10, 8, -22, 6, -5, -2, 8, -17, 8, 2 },
+ { 1, -2, -9, 6, -31, -8, -8, 8, 0, 5, -9, -4, 2, 3, -12, 11,
+ -18, 10, -5, 3, -11, 13, -6, 11, -3, 12, -7, 3, -9, -1, 2, 11 },
+ { -9, -6, 21, -8, -15, 4, -11, 12, -11, 17, -1, 2, -6, 0, -15, 13,
+ -12, 19, 0, 2, -6, -3, -9, 10, 3, 17, -2, 5, -10, -3, 0, 1 },
+ { 4, -6, 5, -10, 1, -5, 1, 0, 0, 0, 2, 7, -2, 2, -2, 0,
+ -4, 3, -4, 1, -12, 6, -49, 16, -10, 13, 0, -2, 8, 6, 1, 8 },
+ { 5, -8, -7, 9, 13, -5, 7, 0, 10, 11, -4, -3, -1, 13, -14, 6,
+ -15, -6, -14, 16, 15, 1, -18, -4, -20, 20, -7, -1, -9, -2, -10, 10 },
+ { -12, 4, 0, 10, 0, 3, 8, 4, -27, -1, -2, 19, -4, 2, -13, 3,
+ 1, 9, -12, 1, -22, 19, -5, 4, -9, 12, 2, -9, -8, 11, -3, 7 },
+ { 4, -5, 11, -6, 17, -17, 5, -4, -2, -6, 1, -5, 2, 4, -14, 6,
+ -20, 19, -20, 12, -21, 5, -14, 13, -2, 11, 4, -3, 0, -10, -4, -2 },
+ { -2, -1, -3, 8, -9, -7, -22, -3, -24, 13, -2, 10, -15, 5, -9, 4,
+ -7, 0, -5, 15, -8, 11, -13, 6, -4, 19, -8, 12, -4, 6, 9, 7 },
+ { 2, -3, 2, -1, 0, 3, 1, 2, 1, -4, -2, -3, 1, 5, -12, 6,
+ -16, 14, -23, 10, -14, 17, -15, 16, -2, 9, -25, 9, -10, 16, 4, 9 },
+ { -3, 7, -8, -3, 2, 2, -4, -8, -9, 10, 3, -11, 25, -10, -28, 27,
+ -9, 7, -13, 9, -2, 4, -12, -8, -14, 6, 7, -10, 3, 3, -3, 5 },
+ { -8, -3, 1, -10, 8, -3, -9, -4, 13, 7, 2, 4, -10, 4, 3, 7,
+ -18, 2, -22, 15, 4, 20, -7, 5, -6, 13, -1, 4, -7, -6, 6, 13 },
+ { -2, 3, 0, 2, -4, -2, 0, 0, 1, 2, -2, -5, 0, 1, -4, 0,
+ -2, -3, 1, 2, -1, 2, -8, -1, -24, 68, -3, 8, 3, 3, -1, -1 },
+ { -15, -2, -9, -7, -1, 8, -14, 8, 3, 6, 0, -1, -8, 8, -23, 2,
+ -14, 17, -15, 8, -4, 7, -18, 0, -8, -3, -1, -4, -10, 4, -1, 4 },
+ { 8, 0, 2, -7, 0, 5, 1, 3, -11, 4, -8, 14, 3, 20, 1, 26,
+ -11, 13, -13, 20, -2, 0, -8, 2, -6, 6, -1, 9, 3, -6, -3, 10 },
+ { 5, 0, -1, -7, 10, 1, -3, 5, 4, 7, -5, -1, -3, -1, 12, -3,
+ -15, 7, -9, 22, -19, 8, -9, 4, -23, 13, -14, 6, -6, -14, -4, 7 },
+ { 14, -5, -8, -10, 25, 3, -23, -7, -28, 0, -1, -9, 4, 1, -13, 20,
+ -8, 10, -16, 8, 12, -13, -21, 5, -13, 11, -2, 1, 12, -7, 2, -10 },
+ { -5, -4, 9, 5, -6, 35, -7, 8, 15, 2, -1, -9, -6, 2, -18, 7,
+ -15, 6, -3, 2, 8, 12, -30, 7, -4, 20, 2, 6, 13, -6, -4, 0 },
+ { 1, 8, -9, 9, -5, 12, -9, 16, -9, 16, -17, 14, -13, 15, -18, 14,
+ -15, 17, -12, 14, -13, 7, -16, 13, -9, 5, -11, 10, -9, 6, -12, 13 },
+ { -10, -4, 5, 3, 1, 6, 8, -14, -5, 15, 7, 4, 8, 7, -22, 8,
+ -7, -8, -15, 26, 1, 13, -3, 17, -5, 9, -2, 4, -6, 3, -8, 9 },
+ { 8, -3, 2, 3, 3, 1, -2, -1, -11, 8, -4, 0, -6, -5, -1, 13,
+ -37, 9, 1, -6, -10, -2, -10, 11, 8, 13, -3, -2, -6, 8, -4, 13 },
+ { 3, 2, -3, -4, -4, 7, -8, 9, -8, 9, -20, 12, -19, 15, -18, 17,
+ -15, 7, -1, 20, -11, 6, -6, 3, 1, 9, 2, -14, -2, -2, 2, 1 },
+ { -7, 1, -1, -3, -6, 4, 4, -3, 3, -1, 5, -4, 3, 2, -1, 9,
+ -59, 5, -4, 30, 3, 3, -2, -3, -1, 2, 2, 1, -1, -1, -2, 1 },
+ { 0, -3, 2, 0, -1, -8, 0, 2, -3, 4, -4, 1, 10, 6, -6, 8,
+ -7, 4, 10, 11, -41, 27, -20, 3, -3, 8, 1, 11, -5, -8, 0, 4 },
+ { 5, 1, 4, -2, 1, 2, -1, 6, -7, 2, 11, 4, 0, 0, -8, 7,
+ -10, 0, 0, 8, 2, 10, -1, 1, -2, 44, -2, -21, -12, -3, -1, 2 },
+ { -4, 4, -2, -2, 6, -8, 2, 1, -10, 14, 8, 6, 5, 1, -2, 4,
+ -13, 4, 2, 5, 10, -2, -21, 32, -3, 18, 9, -6, -9, -9, 10, 2 },
+ { 9, -16, -6, -2, 1, 4, 22, 2, -2, 1, -3, -2, -9, 3, 16, 19,
+ -24, -6, -6, -5, -8, -7, 8, -7, -1, -12, 5, -3, 0, 4, 2, -3 },
+ { 10, 3, -16, -4, -1, 13, 4, 4, 1, -3, 1, -6, -14, 18, 3, 8,
+ -8, -28, -16, 4, 4, 2, 12, 7, 9, -4, -4, 5, -1, -1, 2, 2 },
+ { -5, -13, -22, -3, -8, 21, -2, -9, 21, -4, -9, 5, -8, 15, 5, 1,
+ -5, -9, -7, -2, -5, -5, -1, -5, -5, -5, 3, 10, -4, 0, -7, -2 },
+ { 5, -10, -18, 2, 20, 4, 13, -10, 8, -15, -11, -3, -1, 16, 10, 9,
+ -8, 6, 7, -5, 6, 11, 5, 17, -4, 7, -11, 5, -3, -6, 2, 1 },
+ { 3, -5, -19, 1, 1, -3, -2, -25, -11, -17, 0, -13, -4, 10, 10, 2,
+ -5, 4, 0, 3, -3, -5, -10, -2, 13, -22, 0, 3, -11, -5, 7, -1 },
+ { 12, -14, -29, 6, -1, 10, 7, -17, -12, 14, 3, 9, -9, 9, 7, 6,
+ -3, -13, 0, 5, 3, -1, -6, -1, 0, 2, 4, -12, -5, -1, 2, 11 },
+ { 12, -15, -7, -2, -12, 17, 20, -16, -2, -12, -6, 15, -6, 12, 11, 9,
+ 7, -6, 7, -4, -19, 6, 2, 2, 3, -11, -10, -4, -5, -3, 3, 2 },
+ { 11, -22, -6, 0, 8, 18, 3, -11, -4, -7, -15, -17, -12, 6, 16, 4,
+ -9, 4, -5, 3, 6, -16, 10, -7, -7, -3, 5, 0, 1, -15, -4, 5 },
+ { 12, -22, -16, 5, -6, 8, 12, -4, -9, -17, -11, 3, 5, 8, -17, 0,
+ 11, -4, -13, -6, 2, -1, -1, 3, 3, -11, -12, -1, 1, 1, 12, -2 },
+ { 8, -10, -33, -5, -3, -6, 1, -7, -8, -4, -6, -1, 5, -4, -6, -12,
+ -16, -8, 11, 8, -14, 7, 12, 11, 4, -14, -3, 6, -7, -5, -3, 3 },
+ { 0, -8, -7, 2, -4, 24, 2, -9, -11, -3, -7, 11, -12, 17, 1, -1,
+ 3, -5, -7, 12, 4, 11, 0, 3, 2, -18, -3, 4, 7, -6, 3, 15 },
+ { 10, -15, -16, -2, -4, -9, 7, -15, -6, 2, -16, 13, -8, 7, 19, -21,
+ -4, -12, -9, -3, -3, 6, 11, -3, -1, -19, 3, -7, -9, -4, 3, -6 },
+ { -5, -10, -21, 0, -3, -7, 18, -21, 15, -5, -12, -4, -13, 2, 6, -9,
+ -9, -11, -4, 13, -3, 6, 4, -1, 7, -9, -4, 9, 5, 2, 6, 3 },
+ { 15, -1, -27, -2, 10, 3, 7, -8, 9, -2, 7, 1, -2, -5, 18, 9,
+ -11, -17, -2, 7, -9, 11, 10, 0, -8, 6, -16, -3, 2, -7, 3, 11 },
+ { 4, -9, -39, 19, 6, -13, 13, -5, -5, -15, -2, 9, 0, 4, 14, 6,
+ -10, -4, -5, 2, -4, -2, 5, -11, 3, 3, -2, -2, -7, 9, 7, -10 },
+ { 5, -11, -8, 10, -2, 12, 16, 0, 12, -2, -6, 8, 14, 8, 7, 1,
+ 18, -30, 4, 10, -4, -6, 2, -11, 9, -10, -8, 5, 0, 0, -7, 6 },
+ { -1, -16, -10, 11, 0, 13, 12, -4, -4, -5, -21, 12, 4, 13, 14, -7,
+ 6, -16, -13, 8, 2, 9, 15, -12, 1, -9, -22, 10, -9, 9, 9, -7 },
+ { 4, -12, -27, 1, -2, 11, 15, 3, 14, -14, -9, 0, -9, 16, 22, 10,
+ 16, -10, 5, -5, -9, 1, 1, 6, 6, -4, 2, -17, -5, -6, -15, -1 },
+ { 7, -12, -17, 1, -9, 5, 20, -7, 3, 23, -8, -8, -8, -1, 13, 17,
+ -7, -13, 4, -4, 7, 14, 8, 11, -3, -3, 4, 0, 4, 6, -1, -9 },
+ { 7, -15, -15, -4, 10, 12, 3, -13, 6, 14, 9, -8, -15, 14, 23, -5,
+ -10, -5, 1, 15, -10, -7, 1, 9, 4, -13, -10, 10, 7, -3, 2, 3 },
+ { 4, -10, -14, 0, 3, 4, 0, -9, -3, -4, -11, 2, -17, 8, 2, 15,
+ 6, -12, -12, 15, -5, 17, 18, 3, -3, -3, -4, -6, -8, 13, 4, 10 },
+ { -2, -18, -26, 10, -4, 10, 13, 4, -4, -16, -7, -17, -3, 5, -4, 2,
+ -15, -10, -1, -8, -7, -3, 2, 2, 8, -10, -7, 2, 2, -4, 4, -1 },
+ { 4, -19, -5, -1, -1, -6, 2, -8, 10, -16, -28, -6, 8, -1, 11, 28,
+ 2, -10, -4, 6, -6, 6, 11, 15, -4, -2, 7, 3, 7, -7, 4, 1 },
+ { -3, -6, -10, -5, 13, 18, 10, -15, -5, -3, -13, 5, 1, 2, 18, -5,
+ -10, -10, -7, 4, 2, 1, 5, 4, 2, 5, 4, 8, -9, -17, 7, 7 },
+ { 20, -12, -2, -4, 5, 14, 7, -11, -1, -16, -6, -4, -11, 17, 14, 0,
+ -8, -10, -8, 10, 3, 5, 10, -16, 3, -8, -14, 10, 3, 9, 0, 3 },
+ { 12, -10, -36, 0, 7, 15, 2, -16, 2, -1, 0, -1, 5, 4, 5, -3,
+ 1, -10, 5, -1, -15, -3, -12, 12, 2, 5, -1, 5, 6, -3, -2, 2 },
+ { 17, -15, -31, 23, -4, 15, -2, -3, 6, -7, -5, 1, -12, 4, 6, 8,
+ -10, 8, 3, 5, -4, 1, 5, 3, -1, -4, -3, 1, 10, -4, -2, -2 },
+ { 6, -18, -5, 12, 10, 12, 14, -11, 15, 2, -9, -6, -5, -2, -9, 4,
+ -5, -28, -4, 14, 0, -16, 9, 14, -1, 3, -4, -4, 2, 1, 0, 4 },
+ { -5, -14, -31, 8, 16, 7, 13, -13, 5, 6, -16, 10, -5, 2, -2, 2,
+ 14, -5, 8, -5, 7, -16, 6, -13, -5, 0, -5, 8, -3, -1, 4, 3 },
+ { 1, -2, -1, 0, 6, 5, 2, -4, -3, -1, 0, 1, 4, 2, 43, 28,
+ -12, -35, -2, -2, -7, -1, 0, 2, -1, -2, -2, 1, -4, 0, -2, 3 },
+ { 2, -9, -22, 12, 3, 3, -7, -4, -19, -22, -14, -4, -1, 21, 9, -3,
+ -15, -16, -13, 1, -11, 4, -9, 1, -7, -1, -1, 0, -2, 9, -13, -3 },
+ { -1, -3, -23, 0, 2, 12, 3, -9, -4, 7, 3, 9, -10, 1, 27, 28,
+ 0, 9, -15, -2, -2, 1, 6, 8, -8, 7, -3, 20, 0, 0, -1, -6 },
+ { -1, 11, 8, -2, 1, 5, -6, -1, 4, 2, -4, 0, -1, -5, 4, -6,
+ -10, -12, 19, 1, -7, 9, -8, -9, -16, -11, -2, 12, 14, 4, 4, 34 },
+ { 17, 7, -6, 1, 4, -10, -5, 4, -11, 3, -18, 4, 14, -13, -3, 1,
+ 0, 0, -11, 0, 7, -17, -4, 4, -11, -6, -8, 18, 0, 0, 0, 26 },
+ { -6, -7, -1, -1, 11, -8, 1, 3, 2, 11, -6, -6, 10, -3, 1, -3,
+ 7, 4, -12, -8, 0, -9, 8, -22, -5, 0, -6, 22, -2, 11, -13, 24 },
+ { -3, 4, 0, 3, 9, 10, -1, 3, -9, -12, 1, -5, 18, 0, -3, 8,
+ 25, 15, -8, 2, 2, -2, 4, 8, 9, -1, -5, 10, -3, 1, -1, 23 },
+ { -5, 2, -9, -1, -3, 0, 3, -1, -10, -4, 0, -13, 16, 9, -1, -14,
+ 2, 6, -2, -6, -5, -2, -7, 7, 5, 3, 11, -2, -14, 0, -9, 30 },
+ { 4, 6, 6, 5, -3, -1, 4, 5, 10, 0, 5, -4, 7, -11, 14, 14,
+ 7, 34, -9, 0, -10, 22, -7, -1, 7, -9, 2, -8, 0, -7, -5, 29 },
+ { -4, 3, -1, -4, -3, 5, 1, -4, 0, 2, 4, 2, 1, -1, -10, 1,
+ 6, -6, -4, 1, 4, -3, -3, -5, 0, 3, 7, -12, 0, -2, -10, 55 },
+ { 5, 9, -1, 0, 4, 9, -21, -9, 4, 2, 6, -7, 11, -7, 1, -5,
+ 0, -4, 2, -3, -13, -8, 0, -9, -4, 2, 16, -2, -15, -7, -11, 31 },
+ { 8, 2, -1, 0, 3, -5, -5, 5, 1, -1, -9, 1, 0, -6, -2, -1,
+ 5, 2, 0, 0, 12, 20, -19, 1, 8, -12, -11, 0, 6, -5, 2, 31 },
+ { -1, -1, -2, 1, -1, 3, -9, -5, 8, -2, 5, -1, 0, -2, 4, -2,
+ -3, -12, 0, -2, 3, 0, 9, 4, -1, 21, -8, 3, -4, 9, -6, 30 },
+ { -4, 0, -7, 17, 10, -12, -2, -10, -12, -3, 10, 0, 11, -4, -13, -3,
+ 5, 6, 10, 7, -8, 0, -7, -13, 1, 0, -2, 7, -12, 4, -3, 24 },
+ { -13, 9, 4, -2, 2, -4, -14, -1, -3, -5, -10, 4, 13, -2, 5, 13,
+ 8, 3, -2, 1, 5, -6, 7, -18, -10, 1, -1, 5, 4, 1, 0, 25 },
+ { -5, -1, 18, 12, 8, 8, -16, -1, 1, 1, 1, -4, -5, 3, 3, 4,
+ 4, -11, -12, -16, -6, 2, 12, -13, 0, 9, 7, 9, -9, 0, -10, 24 },
+ { -4, 1, -3, 0, 2, -4, 4, 1, 5, 0, -3, 2, -3, -2, 2, -1,
+ 1, 4, -1, -2, -2, 1, -1, -1, -4, -1, -4, -2, -6, 6, 12, 69 },
+ { 8, 5, 11, 0, -15, -4, 13, 6, 0, -4, 9, 1, -5, -3, 15, 0,
+ 1, 6, -5, 0, 1, 6, 5, 8, 0, 7, 1, -1, -4, -11, -9, 41 },
+ { -4, -9, 32, -6, 0, 7, -4, 6, -6, 1, -6, -2, 4, -8, -5, -3,
+ -16, -1, -2, -6, 1, 15, 0, 21, 3, -3, -4, 3, -12, 16, 2, 27 },
+ { -6, -5, 1, -9, -5, 3, 7, -3, 5, 5, 14, 13, 20, -7, -1, 12,
+ -1, 10, -11, -11, -7, -4, -14, 7, -14, 13, 22, 18, -1, 0, 14, 28 },
+ { -8, 3, -2, 0, 5, 6, -1, -4, 1, 3, -7, 3, 1, -15, 4, -9,
+ 22, -10, -9, -4, 1, 8, -4, 9, -15, 2, -6, -4, -16, 12, -10, 23 },
+ { 0, 0, 2, 0, -1, 3, -3, -1, 3, -5, 7, 1, 5, -5, -8, 1,
+ 13, -15, -5, -7, 12, -6, -2, 3, 10, -5, -8, 17, -5, -11, -14, 23 },
+ { -7, -4, 6, -4, 5, -6, -5, 2, -4, 11, 9, -4, 2, -2, -4, 6,
+ 15, 3, -3, 18, -15, -2, -6, 3, 3, -20, 17, 11, -4, 2, 3, 29 },
+ { 6, 1, -6, 2, 3, 0, 0, -3, 3, 3, -1, 3, -4, -6, -6, -7,
+ -3, -2, -7, -2, -4, 5, 3, -5, -20, -13, -4, 10, -14, -29, 14, 37 },
+ { 3, 4, 3, -6, -4, 5, 0, 3, 2, 3, 0, -2, 4, 0, -3, -5,
+ -4, 4, -4, 4, 4, 3, 1, -4, -4, -9, -14, 20, -30, 3, -18, 33 },
+ { 0, 2, 5, -2, -4, -2, -1, 2, -6, -3, -2, -2, 2, -5, -1, 4,
+ 3, 2, -3, 0, -1, -1, -10, -7, 2, -4, -18, 2, -37, -1, 12, 40 },
+ { -7, 2, -1, 0, -2, 4, -8, 1, -4, 12, 7, 4, 15, -7, 1, -9,
+ 18, 0, 12, -17, -3, -1, 0, 0, 0, 2, -6, 0, -4, -3, -1, 26 },
+ { -6, 4, 8, -5, -6, -2, 2, -1, 1, -1, -15, 8, 7, -1, -17, -4,
+ 1, 5, 6, -11, -6, 14, 17, -5, -15, 11, 8, 0, -3, -15, -6, 28 },
+ { -1, 0, 0, 0, 1, 0, -1, 0, 1, 3, 2, -2, 3, -1, -1, 2,
+ 2, -1, -1, -7, 1, 2, -9, 0, -1, -4, -18, 7, -10, 49, -13, 32 },
+ { -1, -3, 4, 1, 2, -5, 1, -7, -1, 5, -9, 4, 4, 25, 1, -1,
+ 2, -5, 2, -7, 17, -2, 10, -5, 0, 2, -15, 3, -9, 7, -9, 30 },
+ { -5, -1, 0, 2, 1, -1, 2, 5, -33, 3, -5, 14, 11, 7, 5, -3,
+ 2, -8, -4, -2, -7, -6, 4, -8, -1, -8, 2, -2, -8, -1, -4, 27 },
+ { -1, 0, -1, -2, 1, -1, -2, -1, 2, 0, 1, 2, 2, 4, 1, 3,
+ 4, 2, 1, -7, -4, 1, -3, -4, -35, -25, 17, 10, -3, -26, -7, 32 },
+ { -5, 1, 6, -2, 6, 6, -9, 3, -1, -4, 5, -4, -2, -2, -9, 2,
+ -5, 2, 2, 4, 3, 5, -5, -16, -31, -12, -11, 2, -19, 20, -2, 21 },
+ { -5, 2, 7, -7, -7, 5, -7, 2, 0, 0, -4, 3, -1, 0, -1, -2,
+ 0, -3, 5, -11, -8, -3, -7, -7, 28, -11, -7, 0, -16, -11, -4, 29 },
+ { 2, 1, -3, -2, -1, 3, 4, 0, 1, 0, -1, -5, 4, -5, -12, 2,
+ -2, -5, -22, -2, -1, 11, 8, -7, -12, 0, -34, 6, -5, 11, -8, 19 },
+ { -1, -3, 5, 11, 18, -2, -2, -5, -2, 4, -1, 8, 5, -6, 1, -1,
+ 2, 8, 4, -5, -8, -2, 5, -18, 7, 12, 7, 19, -18, 2, -6, -13 },
+ { 9, 0, 0, 5, 4, 3, -6, 4, 1, -4, 5, -1, -4, 8, 8, 6,
+ -8, -6, 0, 6, -3, 3, 5, -3, 17, 31, 16, 10, -13, 0, -9, -19 },
+ { 12, -10, 2, -2, -2, -1, -3, 6, -12, -5, -2, 14, -16, 4, 12, 12,
+ 17, 4, 7, -16, 7, -6, 11, 7, 7, 2, -25, 23, -24, 5, -7, -9 },
+ { 10, 4, 13, 10, 10, 3, -6, 3, 3, 2, -1, -6, 8, 4, 10, 0,
+ 1, 2, -4, 2, -3, -8, 0, -1, 9, 9, -10, -3, -29, 1, -1, -27 },
+ { 2, 2, 0, 7, 9, -2, -10, -1, -1, 1, -9, -5, 8, 4, 1, 2,
+ -10, 1, 13, 12, -3, 15, -9, 2, -7, 1, -10, 23, -20, -18, -9, -15 },
+ { -3, -5, -1, 8, 0, -5, -1, 4, 7, -1, -7, 2, -8, -5, 11, 7,
+ -6, 3, -3, -9, 7, 9, -22, 1, 6, -4, 14, 27, -25, -14, 3, -5 },
+ { 1, 3, 8, 4, 7, 6, 12, -17, -15, 1, -8, -10, 7, -14, -8, 6,
+ -2, -2, -11, -11, -7, 13, -2, -2, 4, 5, -5, 13, -23, -6, -17, -8 },
+ { -5, 4, -14, -5, -4, -5, 6, 5, -8, -5, -2, -11, -7, -12, 3, -11,
+ 2, -6, 4, -10, -5, -7, 14, 5, 23, 11, 7, 12, -16, -6, -4, -16 },
+ { 5, 6, 2, 5, -2, -5, -5, -6, -5, -19, -13, -1, -3, -13, 5, 0,
+ 6, -2, -2, -6, -7, -7, -1, -9, 4, 14, 17, -12, -27, 3, 0, -1 },
+ { 7, -1, 9, -10, 8, 2, -7, -2, 5, 2, -3, -7, 3, 0, 6, 4,
+ 12, 5, 11, 14, -13, -1, 8, 1, 13, 9, 12, 12, -18, -14, -11, -16 },
+ { -7, -5, -6, -5, 0, -1, -3, 2, 2, 1, 4, 9, 2, 3, 5, -2,
+ 2, 1, 8, 0, 3, 0, -2, 2, 1, 7, 29, 0, -36, -5, -9, -21 },
+ { 14, -6, -9, 0, -1, -8, -8, -11, 2, 2, -9, -12, 12, -4, 5, 3,
+ -5, -9, 11, -1, -3, 12, -21, -3, 12, 5, 3, 11, -18, -15, 1, -2 },
+ { -1, 3, -9, -3, 7, -7, -18, 2, 4, 12, -10, 2, 8, -3, -14, 13,
+ 17, -5, 5, -9, 13, -3, -7, -18, 17, -2, 5, 7, -20, -3, -6, -11 },
+ { -3, 3, 3, -1, 1, -6, -5, 1, 5, -3, -14, -6, -5, -8, 14, -6,
+ 7, -1, 5, 1, 15, -1, -7, -4, 6, -11, 9, -2, -37, 16, -7, -3 },
+ { -1, 0, 6, 1, -3, -9, 0, 11, -8, 2, -2, 0, 5, 2, 12, -10,
+ 10, 13, 2, 7, -6, 2, -10, -10, 21, -5, 5, 5, -12, -23, 3, -14 },
+ { 6, 0, -2, 1, 0, 1, 0, -4, 1, 1, 8, -2, 2, -5, -2, 1,
+ 8, -4, -1, -1, 4, -1, 2, 6, 32, 1, -5, -20, -40, -4, -18, -14 },
+ { 2, 2, -7, -2, 4, 4, -1, 2, 0, -2, -4, -7, 3, 5, 0, -5,
+ 1, 2, -6, 4, -1, -2, -1, -15, 8, 3, 9, 46, -7, -18, 6, -11 },
+ { 5, 5, 16, 21, 3, -11, -4, 11, -12, 2, 4, -12, -1, 11, 8, 1,
+ -4, 11, -11, -21, 1, 1, -11, 3, 13, 1, 5, 12, -25, 1, -3, -2 },
+ { 1, 6, -7, 4, 2, 3, 1, -5, 8, 9, -15, 3, -3, -14, 17, 4,
+ -8, 14, -2, -8, -4, 5, 8, -7, 8, 9, 7, 6, -29, -17, 8, 4 },
+ { -7, -7, 4, 0, 13, 1, 0, 4, 4, -16, -10, -7, 5, 9, -15, -10,
+ -10, 8, -4, -1, -11, -1, -10, -15, 3, 3, 14, 10, -19, 2, -18, -12 },
+ { -4, 0, 2, 0, 5, -2, -9, 0, 4, -4, 2, -1, -2, 2, -4, 9,
+ 2, -6, -4, -2, -1, -3, -3, -1, 2, 5, -1, 11, -24, -44, -9, -15 },
+ { -1, -10, 6, 21, 11, 15, -7, 10, -14, -9, -8, -8, 4, 6, 19, 1,
+ -6, 1, -5, -17, -8, -10, 9, 5, 11, 18, -1, 10, -16, -7, -9, -8 },
+ { 3, -5, 0, 0, -2, -2, -6, 4, -4, 1, -1, 0, 7, -3, 4, -4,
+ -7, 7, 17, -20, 6, 4, 1, -6, -12, 31, 13, 19, -14, -10, -7, -2 },
+ { -2, 6, -10, 3, 9, 6, -14, 15, 2, -5, 2, -11, 9, -8, 4, 6,
+ 20, -15, -3, -3, -1, 32, -21, 6, 1, 9, 11, 17, -19, 6, -1, -3 },
+ { 8, 10, -2, 0, -8, -16, 7, 7, 6, 10, 4, -14, 7, -6, 21, -7,
+ 10, 5, 5, 0, -7, 2, -6, 0, -7, 11, -9, 15, -20, -7, -11, 2 },
+ { 0, -7, 5, 2, 0, -3, -6, -4, -2, -1, -4, -5, -13, -1, 27, -9,
+ -6, -11, -7, 1, 11, -4, -4, -14, -2, 11, 6, 10, -19, -6, -15, 2 },
+ { 0, 7, -1, 2, -7, -15, -2, -3, 13, -5, -5, 12, 3, 0, 5, -5,
+ -22, 2, 7, 22, 13, 0, -1, 2, 3, 2, -7, 7, -27, -4, -4, -12 },
+ { 11, 1, -16, 6, -15, 1, 3, 2, 0, 2, -3, 2, 5, -2, -5, 9,
+ 5, -3, 3, -2, -11, 3, 9, 6, 9, 3, -1, 12, -41, 8, -6, 9 },
+ { 3, -7, 3, 2, 5, 5, 0, -1, 1, 3, -5, -2, -13, 7, -1, -2,
+ -2, -6, 4, -6, 0, 2, -2, 2, 4, 1, -4, 1, -47, -21, 7, -6 },
+ { 3, 16, -7, 13, -4, -2, 10, -3, -1, 18, -13, 7, -13, -4, 8, 4,
+ 8, 9, -5, 13, 8, -5, 3, -6, 7, 18, -8, 10, -25, -3, -12, -12 },
+ { 1, -1, -1, 0, 2, 5, -5, -3, 0, -5, -1, 0, -4, -8, -2, 3,
+ 2, -2, -17, -6, -4, 1, 33, -6, -20, -6, 8, 31, -26, -8, -1, -4 },
+ { 3, -3, -3, 5, -3, -2, 1, 7, 0, 3, 6, 3, 6, -2, 9, 15,
+ -10, -3, -15, -5, -3, -4, -6, -30, 17, -8, -2, 2, -20, 0, -8, -2 },
+ { -2, -1, -1, -1, 3, -5, -2, -3, 4, -2, 0, 5, 8, -3, 1, -4,
+ 1, 1, -3, 4, 4, -14, 3, 11, -5, 3, -3, 7, -3, 13, 23, -16 },
+ { 2, -6, 1, -3, 5, 0, -6, -11, -7, -4, -1, 2, -7, -1, -1, 7,
+ 1, -2, 6, 12, -6, 8, -13, 17, 25, -23, -19, -7, -12, 9, 16, -17 },
+ { 9, 4, 4, 4, -3, -1, 6, -2, -3, 0, 13, -4, -7, 14, 1, -7,
+ 0, -5, 3, -19, -3, 5, 3, 9, -1, 9, -13, 13, -17, 4, 21, -26 },
+ { 0, -5, 0, 0, -4, -5, 2, -6, -4, 5, -7, 10, 0, 2, 0, -2,
+ -2, 0, 4, -6, 7, -2, 6, 5, -5, 2, -12, 1, -29, 29, 27, 12 },
+ { 9, -10, -22, 6, -1, -1, 9, -14, -12, -2, 1, -1, 10, -11, -16, 0,
+ 3, 11, 13, -14, -9, -2, -1, 6, 4, -14, 0, -10, -2, 16, 17, -11 },
+ { 2, 0, -1, -2, 4, 3, -6, -2, 1, -1, 1, 3, -4, 1, 3, -4,
+ -1, -1, 4, -1, 1, 0, 1, 6, -5, -7, 2, 1, -47, -3, 50, -17 },
+ { 8, -4, -11, -7, 11, 11, 14, -7, 12, -7, 6, 2, 13, -6, -3, -2,
+ -14, 6, 6, 6, 0, 2, -1, 5, -20, 2, -1, 4, -5, 6, 21, -11 },
+ { -2, -9, 3, 0, -6, 7, 8, -8, 1, -3, 4, 1, 5, -2, -3, -7,
+ 4, 7, -12, -9, -2, 10, -6, 13, 6, 5, 20, 2, -15, 9, 28, -7 },
+ { 0, -5, -6, -6, -6, 1, -6, 6, -2, 4, 8, -3, 12, -1, -4, -2,
+ 6, 16, -14, 9, -14, -2, -8, -27, -3, 18, -1, -7, -3, 8, 23, -23 },
+ { 1, 4, -9, -1, -5, 10, -2, 1, -11, 1, -9, 4, 7, 14, -9, -2,
+ -3, 2, -5, -1, -6, -10, -7, 11, 20, 2, 3, -19, 3, 15, 30, -9 },
+ { 7, 2, -14, -4, 0, -2, 5, 2, 5, -2, 8, -3, -7, 6, 6, -11,
+ -14, 1, 10, -1, -7, -8, 1, 10, 3, -6, -15, -12, -17, 4, 30, -6 },
+ { 4, 2, 1, -2, 3, 0, 1, 0, 2, 0, 1, 6, -7, 0, 3, 4,
+ 4, -4, -2, -5, -2, 2, -1, -2, 0, -2, -11, -7, -3, 42, 24, -14 },
+ { 4, 1, 3, 2, 0, -2, -3, -2, 2, -1, 4, 11, -2, 2, 3, -4,
+ -5, 9, 2, -4, -9, 5, 8, -1, -7, 1, 24, -13, -28, 20, 15, -22 },
+ { -3, 7, 6, 3, -2, -5, -10, -2, -2, -1, -6, -6, -2, -14, -16, -6,
+ -5, 0, 18, 0, 9, 1, 7, -13, -5, -6, -9, 11, -15, 9, 22, -11 },
+ { 9, -2, 6, 5, 2, 9, -10, 1, 1, 5, -4, 12, 2, 2, -10, -7,
+ -4, -6, 7, 9, 6, 15, 6, 6, -10, 10, 5, -13, -5, 6, 24, -12 },
+ { 1, 3, -3, -3, 8, 1, -6, 2, -5, -3, 7, 2, 14, 6, 9, -6,
+ -5, -4, 27, 7, -3, 8, -6, 3, -8, 8, 22, -5, -6, -2, 22, -17 },
+ { -2, -2, 3, 10, 9, 9, 12, -15, -1, -11, -13, 3, -2, 1, -3, -11,
+ 7, 9, 16, -3, -10, -5, -5, 1, 8, -3, 9, 9, -5, 3, 31, -12 },
+ { 7, -5, 10, -4, -8, 2, 16, -2, 10, 10, -3, -2, 3, -8, -3, 3,
+ -13, -6, 15, 20, -9, -3, -12, 1, -2, -16, 8, 8, -1, 16, 22, -5 },
+ { 5, -3, -15, -2, 12, -8, 8, -5, 2, -8, 20, -18, 14, -4, 3, 3,
+ 7, -13, -16, 1, -10, 7, 16, 7, 4, -14, -4, -5, -9, 8, 23, -6 },
+ { 5, -4, -5, -4, 1, 8, 4, -7, -5, 8, 10, 6, -6, -10, -2, 6,
+ 9, -17, -14, 11, 12, -3, -13, -7, 2, 18, 3, -25, -16, 18, 22, -5 },
+ { 5, 6, -7, -20, -4, 2, 8, 4, -24, -4, 1, 4, -5, -2, 1, -10,
+ -2, 9, 3, -4, -3, -4, -4, -4, 10, 10, 3, 0, -6, 25, 21, -11 },
+ { 0, 7, -1, 14, -6, -4, -10, 5, 4, 4, 4, -5, 3, 4, -1, -7,
+ 8, -19, 0, 6, 2, 3, -18, -3, -6, 2, 8, 14, -26, 22, 27, -13 },
+ { -2, -6, 7, -5, 12, -7, 8, -1, 3, -2, 4, 1, 8, -2, 0, 14,
+ 6, -5, 6, -4, -7, 7, -21, 8, 1, 8, -9, -4, -3, 11, 25, -13 },
+ { 4, 4, -1, -6, 4, 9, -8, 1, -3, -10, -2, 0, 15, -9, -16, 11,
+ 1, 1, 6, 3, -9, -5, 16, 26, 1, -14, 1, -3, -14, 7, 15, -9 },
+ { -12, -2, -9, -13, 2, 6, 14, 0, 1, 0, -1, -13, 0, 10, -1, 6,
+ 9, -7, 8, 8, 19, 6, -1, 9, 10, -4, 1, -7, -22, -2, 29, -7 },
+ { 2, 4, 13, -12, -8, -4, -5, 13, 12, -5, -3, -3, -4, 1, -1, 10,
+ 15, -6, -1, -11, -30, 4, 15, -1, 9, -7, 0, -2, -7, 10, 25, -16 },
+ { 7, -15, -7, -7, -1, -5, -5, -11, -20, 10, 3, -10, -3, 5, 20, -4,
+ 0, -2, -2, 17, 2, 0, -3, 3, 6, 5, -1, -12, -3, 15, 22, -16 },
+ { 4, -1, 3, 4, -5, 0, -1, -5, -24, -29, 4, -9, 1, -3, 0, 0,
+ 0, -4, 7, -4, -4, -4, 3, 1, -6, 5, -3, -5, -10, 3, 25, -10 },
+ { -2, -1, -1, 4, 4, -1, 2, 0, -4, -4, 2, -1, -3, -1, -2, -2,
+ 1, -3, -5, -1, 2, -3, -4, -4, -3, 5, -9, 1, -11, 7, 46, -46 },
+ { 0, -9, 3, 4, 4, 3, -5, -6, 5, -4, 4, -2, 1, 7, -4, -10,
+ 13, 1, 3, -6, 4, -4, 7, 2, -19, -25, -3, -16, -12, 16, 20, -1 },
+ { 18, 6, 4, -12, 0, -14, 9, -6, -1, -4, -5, 2, 1, 12, 4, 2,
+ 7, 0, 2, 5, -11, -5, -2, 2, -4, 10, 0, -9, -7, 9, 25, -8 },
+ { 5, 0, -6, 5, 6, 3, 3, -10, -5, 1, -1, 4, 3, -11, -8, 5,
+ 4, -5, 5, -5, -7, -5, 11, 5, 20, -8, -16, 21, -4, 27, 23, -5 }
+};
+
+
+/* FIR filter coefficients, they can be cut on half and maybe use float instead of double*/
+
+static const float fir_32bands_perfect[] =
+{
++1.135985195E-010,
+-6.022448247E-007,
++9.742954035E-007,
++7.018770981E-011,
+-6.628192182E-007,
++1.085227950E-006,
+-1.608403011E-008,
+-6.982898526E-007,
++1.162929266E-006,
+-5.083275667E-008,
+-7.020648809E-007,
++1.194632091E-006,
+-1.543309907E-007,
+-6.767839409E-007,
++1.179182050E-006,
+-3.961981463E-007,
+-6.262345096E-007,
++1.033426656E-006,
+-7.342250683E-007,
+-5.564140224E-007,
++9.451737242E-007,
+-3.970030775E-007,
++7.003467317E-007,
++1.975324267E-006,
+-4.741137047E-007,
++8.419976893E-007,
++1.190443072E-006,
++5.234479659E-007,
++6.402664354E-008,
+-1.470520488E-006,
++2.014677420E-007,
+-3.246264413E-008,
+-1.853591357E-006,
++7.834767501E-008,
+-3.809887872E-008,
++7.198007665E-007,
++8.434094667E-008,
++3.086857760E-006,
+-6.702406963E-010,
++6.437721822E-008,
++6.084746474E-006,
+-1.613285505E-009,
++1.189317118E-006,
++9.561075785E-006,
+-2.682709610E-009,
++2.497214155E-006,
++1.309637537E-005,
+-3.399493131E-009,
++3.617151151E-006,
++2.263354872E-005,
++1.314406006E-008,
++3.157242645E-006,
++2.847247197E-005,
++7.506701927E-009,
++2.319611212E-006,
++3.415624451E-005,
++2.788728892E-008,
++7.869333785E-006,
++3.946387005E-005,
++1.444918922E-007,
++9.826449968E-006,
++4.425736552E-005,
++3.132386439E-007,
++1.177108606E-005,
++4.839275425E-005,
++1.399798180E-006,
++1.379448349E-005,
++5.176846025E-005,
++2.032118118E-006,
++1.571428584E-005,
++5.429694284E-005,
++2.715013807E-006,
++1.743183020E-005,
++5.595519906E-005,
++3.453840463E-006,
++1.884208177E-005,
++4.916387297E-006,
++4.195037945E-006,
++1.987093310E-005,
++9.299508747E-006,
++4.896494374E-006,
++2.042970118E-005,
++1.356193479E-005,
++5.516381407E-006,
+-3.144468428E-005,
++1.751866148E-005,
++6.015239251E-006,
+-3.334947178E-005,
++2.093936746E-005,
++6.361419310E-006,
+-3.460439257E-005,
++2.362549276E-005,
++8.006985809E-006,
+-3.515914432E-005,
++2.537086584E-005,
++8.087732567E-006,
+-3.495384954E-005,
++2.618136386E-005,
++7.941360309E-006,
+-3.397853652E-005,
++2.554462844E-005,
++7.568834008E-006,
+-3.225446198E-005,
++3.018750249E-005,
++6.986399967E-006,
+-2.978993689E-005,
++2.570833203E-005,
++6.225028756E-006,
+-2.677291741E-005,
++1.985177369E-005,
++5.315936960E-006,
+-1.806914770E-005,
++1.191342653E-005,
++4.429412002E-006,
+-1.776598037E-005,
++2.525620175E-006,
++3.332600045E-006,
+-1.661818715E-005,
+-1.521241393E-005,
++8.427224429E-007,
+-1.207003334E-005,
+-1.617751332E-005,
++4.341498823E-007,
+-6.993315310E-006,
++1.992636317E-005,
++9.458596395E-008,
+-5.633860383E-007,
++1.774702469E-005,
++2.975164826E-008,
+-9.984935332E-007,
++4.624524081E-005,
++5.610509834E-005,
+-5.729619297E-004,
++4.244441516E-004,
++6.568001118E-005,
+-6.358824321E-004,
++2.206075296E-004,
++7.513730816E-005,
+-7.021900383E-004,
+-2.719412748E-007,
++8.413690375E-005,
+-7.698345580E-004,
+-2.382978710E-004,
++8.757545584E-005,
+-8.385353722E-004,
+-4.935106263E-004,
++9.517164290E-005,
+-9.078957955E-004,
+-7.658848190E-004,
++1.020687996E-004,
+-9.775133803E-004,
+-1.055365428E-003,
++1.084438481E-004,
+-1.046945457E-003,
+-1.361547387E-003,
++1.140582463E-004,
+-1.115717343E-003,
+-1.684492454E-003,
++1.187910311E-004,
+-1.183370827E-003,
+-2.023874084E-003,
++1.224978914E-004,
+-1.252829796E-003,
+-2.379294252E-003,
++1.250260248E-004,
+-1.316190348E-003,
+-2.750317100E-003,
++1.262027217E-004,
+-1.376571832E-003,
+-3.136433195E-003,
++1.226499153E-004,
+-1.433344092E-003,
+-3.537061159E-003,
++1.213575742E-004,
+-1.485876855E-003,
+-3.951539751E-003,
++1.180980107E-004,
+-1.533520175E-003,
+-4.379155114E-003,
++1.126275165E-004,
+-1.575609902E-003,
+-4.819062538E-003,
++1.047207043E-004,
+-1.611457788E-003,
+-5.270531867E-003,
++9.417100227E-005,
+-1.640390139E-003,
+-5.732392892E-003,
++8.078388782E-005,
+-1.661288203E-003,
+-6.203945260E-003,
++6.447290798E-005,
+-1.674512983E-003,
+-6.683901884E-003,
++4.491530854E-005,
+-1.678415807E-003,
+-7.170005701E-003,
++2.470704203E-005,
+-1.672798418E-003,
+-7.664063945E-003,
+-1.714242217E-006,
+-1.656501088E-003,
+-8.162760176E-003,
+-3.193307566E-005,
+-1.633993932E-003,
+-8.665001951E-003,
+-6.541742187E-005,
+-1.593449386E-003,
+-9.170533158E-003,
+-1.024175072E-004,
++1.542080659E-003,
+-9.676489048E-003,
+-1.312203676E-004,
++1.479332102E-003,
+-1.018219907E-002,
+-1.774113771E-004,
++1.395521569E-003,
+-1.068630442E-002,
+-2.233728592E-004,
++1.303116791E-003,
+-1.118756086E-002,
+-2.682086197E-004,
++1.196175464E-003,
+-1.168460958E-002,
+-3.347633174E-004,
++1.073757303E-003,
+-1.217562053E-002,
+-3.906481725E-004,
++9.358961834E-004,
+-1.265939046E-002,
+-4.490280990E-004,
++7.817269652E-004,
+-1.313448418E-002,
+-5.099929986E-004,
++6.114174030E-004,
+-1.359948888E-002,
+-1.405300573E-002,
++1.572482102E-002,
++4.935106263E-004,
+-1.449365262E-002,
++1.533095632E-002,
++2.382978710E-004,
+-1.492007636E-002,
++1.492007636E-002,
++2.719412748E-007,
+-1.533095632E-002,
++1.449365262E-002,
+-2.206075296E-004,
+-1.572482102E-002,
++1.405300573E-002,
+-4.244441516E-004,
+-1.610082202E-002,
++1.359948888E-002,
+-6.114174030E-004,
+-1.645756140E-002,
++1.313448418E-002,
+-7.817269652E-004,
+-1.679391414E-002,
++1.265939046E-002,
+-9.358961834E-004,
+-1.710879989E-002,
++1.217562053E-002,
+-1.073757303E-003,
+-1.740120351E-002,
++1.168460958E-002,
+-1.196175464E-003,
+-1.767017506E-002,
++1.118756086E-002,
+-1.303116791E-003,
+-1.791484281E-002,
++1.068630442E-002,
+-1.395521569E-003,
+-1.813439466E-002,
++1.018219907E-002,
+-1.479332102E-003,
+-1.832821220E-002,
++9.676489048E-003,
+-1.542080659E-003,
+-1.849545911E-002,
++9.170533158E-003,
++1.593449386E-003,
+-1.863567345E-002,
++8.665001951E-003,
++1.633993932E-003,
+-1.874836907E-002,
++8.162760176E-003,
++1.656501088E-003,
+-1.883326657E-002,
++7.664063945E-003,
++1.672798418E-003,
+-1.889026538E-002,
++7.170005701E-003,
++1.678415807E-003,
+-1.891860925E-002,
++6.683901884E-003,
++1.674512983E-003,
++1.891860925E-002,
++6.203945260E-003,
++1.661288203E-003,
++1.889026538E-002,
++5.732392892E-003,
++1.640390139E-003,
++1.883326657E-002,
++5.270531867E-003,
++1.611457788E-003,
++1.874836907E-002,
++4.819062538E-003,
++1.575609902E-003,
++1.863567345E-002,
++4.379155114E-003,
++1.533520175E-003,
++1.849545911E-002,
++3.951539751E-003,
++1.485876855E-003,
++1.832821220E-002,
++3.537061159E-003,
++1.433344092E-003,
++1.813439466E-002,
++3.136433195E-003,
++1.376571832E-003,
++1.791484281E-002,
++2.750317100E-003,
++1.316190348E-003,
++1.767017506E-002,
++2.379294252E-003,
++1.252829796E-003,
++1.740120351E-002,
++2.023874084E-003,
++1.183370827E-003,
++1.710879989E-002,
++1.684492454E-003,
++1.115717343E-003,
++1.679391414E-002,
++1.361547387E-003,
++1.046945457E-003,
++1.645756140E-002,
++1.055365428E-003,
++9.775133803E-004,
++1.610082202E-002,
++7.658848190E-004,
++9.078957955E-004,
++8.385353722E-004,
+-8.757545584E-005,
+-6.084746474E-006,
++7.698345580E-004,
+-8.413690375E-005,
+-3.086857760E-006,
++7.021900383E-004,
+-7.513730816E-005,
+-7.198007665E-007,
++6.358824321E-004,
+-6.568001118E-005,
++1.853591357E-006,
++5.729619297E-004,
+-5.610509834E-005,
++1.470520488E-006,
++5.099929986E-004,
+-4.624524081E-005,
++9.984935332E-007,
++4.490280990E-004,
+-1.774702469E-005,
++5.633860383E-007,
++3.906481725E-004,
+-1.992636317E-005,
++6.993315310E-006,
++3.347633174E-004,
++1.617751332E-005,
++1.207003334E-005,
++2.682086197E-004,
++1.521241393E-005,
++1.661818715E-005,
++2.233728592E-004,
+-2.525620175E-006,
++1.776598037E-005,
++1.774113771E-004,
+-1.191342653E-005,
++1.806914770E-005,
++1.312203676E-004,
+-1.985177369E-005,
++2.677291741E-005,
++1.024175072E-004,
+-2.570833203E-005,
++2.978993689E-005,
++6.541742187E-005,
+-3.018750249E-005,
++3.225446198E-005,
++3.193307566E-005,
+-2.554462844E-005,
++3.397853652E-005,
++1.714242217E-006,
+-2.618136386E-005,
++3.495384954E-005,
+-2.470704203E-005,
+-2.537086584E-005,
++3.515914432E-005,
+-4.491530854E-005,
+-2.362549276E-005,
++3.460439257E-005,
+-6.447290798E-005,
+-2.093936746E-005,
++3.334947178E-005,
+-8.078388782E-005,
+-1.751866148E-005,
++3.144468428E-005,
+-9.417100227E-005,
+-1.356193479E-005,
+-2.042970118E-005,
+-1.047207043E-004,
+-9.299508747E-006,
+-1.987093310E-005,
+-1.126275165E-004,
+-4.916387297E-006,
+-1.884208177E-005,
+-1.180980107E-004,
+-5.595519906E-005,
+-1.743183020E-005,
+-1.213575742E-004,
+-5.429694284E-005,
+-1.571428584E-005,
+-1.226499153E-004,
+-5.176846025E-005,
+-1.379448349E-005,
+-1.262027217E-004,
+-4.839275425E-005,
+-1.177108606E-005,
+-1.250260248E-004,
+-4.425736552E-005,
+-9.826449968E-006,
+-1.224978914E-004,
+-3.946387005E-005,
+-7.869333785E-006,
+-1.187910311E-004,
+-3.415624451E-005,
+-2.319611212E-006,
+-1.140582463E-004,
+-2.847247197E-005,
+-3.157242645E-006,
+-1.084438481E-004,
+-2.263354872E-005,
+-3.617151151E-006,
+-1.020687996E-004,
+-1.309637537E-005,
+-2.497214155E-006,
+-9.517164290E-005,
+-9.561075785E-006,
+-1.189317118E-006,
+-6.437721822E-008,
+-4.195037945E-006,
+-1.194632091E-006,
+-8.434094667E-008,
+-3.453840463E-006,
+-1.162929266E-006,
++3.809887872E-008,
+-2.715013807E-006,
+-1.085227950E-006,
++3.246264413E-008,
+-2.032118118E-006,
+-9.742954035E-007,
+-6.402664354E-008,
+-1.399798180E-006,
+-8.419976893E-007,
+-2.975164826E-008,
+-3.132386439E-007,
+-7.003467317E-007,
+-9.458596395E-008,
+-1.444918922E-007,
++5.564140224E-007,
+-4.341498823E-007,
+-2.788728892E-008,
++6.262345096E-007,
+-8.427224429E-007,
+-7.506701927E-009,
++6.767839409E-007,
+-3.332600045E-006,
+-1.314406006E-008,
++7.020648809E-007,
+-4.429412002E-006,
++3.399493131E-009,
++6.982898526E-007,
+-5.315936960E-006,
++2.682709610E-009,
++6.628192182E-007,
+-6.225028756E-006,
++1.613285505E-009,
++6.022448247E-007,
+-6.986399967E-006,
++6.702406963E-010,
++4.741137047E-007,
+-7.568834008E-006,
+-7.834767501E-008,
++3.970030775E-007,
+-7.941360309E-006,
+-2.014677420E-007,
++7.342250683E-007,
+-8.087732567E-006,
+-5.234479659E-007,
++3.961981463E-007,
+-8.006985809E-006,
+-1.190443072E-006,
++1.543309907E-007,
+-6.361419310E-006,
+-1.975324267E-006,
++5.083275667E-008,
+-6.015239251E-006,
+-9.451737242E-007,
++1.608403011E-008,
+-5.516381407E-006,
+-1.033426656E-006,
+-7.018770981E-011,
+-4.896494374E-006,
+-1.179182050E-006,
+-1.135985195E-010
+};
+
+static const float fir_32bands_nonperfect[] =
+{
+-1.390191784E-007,
+-1.693738625E-007,
+-2.030677564E-007,
+-2.404238444E-007,
+-2.818143514E-007,
+-3.276689142E-007,
+-3.784752209E-007,
+-4.347855338E-007,
+-4.972276315E-007,
+-5.665120852E-007,
+-6.434325428E-007,
+-7.288739425E-007,
+-8.238164355E-007,
+-9.293416952E-007,
+-1.046637067E-006,
+-1.176999604E-006,
+-1.321840614E-006,
+-1.482681114E-006,
+-1.661159786E-006,
+-1.859034001E-006,
+-2.078171747E-006,
+-2.320550948E-006,
+-2.588257530E-006,
+-2.883470643E-006,
+-3.208459020E-006,
+-3.565570978E-006,
+-3.957220997E-006,
+-4.385879038E-006,
+-4.854050530E-006,
+-5.364252502E-006,
+-5.918994248E-006,
+-6.520755960E-006,
+-7.171964626E-006,
+-7.874960829E-006,
+-8.631964192E-006,
+-9.445050637E-006,
+-1.031611009E-005,
+-1.124680875E-005,
+-1.223855270E-005,
+-1.329243969E-005,
+-1.440921824E-005,
+-1.558924305E-005,
+-1.683242772E-005,
+-1.813820381E-005,
+-1.950545993E-005,
+-2.093250441E-005,
+-2.241701623E-005,
+-2.395598858E-005,
+-2.554569073E-005,
+-2.718161704E-005,
+-2.885844333E-005,
+-3.056998685E-005,
+-3.230916263E-005,
+-3.406793985E-005,
+-3.583733633E-005,
+-3.760734762E-005,
+-3.936696885E-005,
+-4.110412556E-005,
+-4.280570283E-005,
+-4.445751256E-005,
+-4.604430433E-005,
+-4.754976908E-005,
+-4.895655002E-005,
+-5.024627535E-005,
++5.139957648E-005,
++5.239612074E-005,
++5.321469871E-005,
++5.383323878E-005,
++5.422891263E-005,
++5.437819709E-005,
++5.425697600E-005,
++5.384063843E-005,
++5.310418419E-005,
++5.202236207E-005,
++5.056979353E-005,
++4.872112549E-005,
++4.645117951E-005,
++4.373511547E-005,
++4.054862075E-005,
++3.686808850E-005,
++3.267079956E-005,
++2.793515523E-005,
++2.264085742E-005,
++1.676913780E-005,
++1.030297699E-005,
++3.227306706E-006,
+-4.470633485E-006,
+-1.280130618E-005,
+-2.177240640E-005,
+-3.138873581E-005,
+-4.165195787E-005,
+-5.256036457E-005,
+-6.410864444E-005,
+-7.628766616E-005,
+-8.908427117E-005,
+-1.024810626E-004,
+-1.164562127E-004,
+-1.309833024E-004,
+-1.460311323E-004,
+-1.615635992E-004,
+-1.775395358E-004,
+-1.939126523E-004,
+-2.106313768E-004,
+-2.276388550E-004,
+-2.448728774E-004,
+-2.622658503E-004,
+-2.797449124E-004,
+-2.972317743E-004,
+-3.146430245E-004,
+-3.318900708E-004,
+-3.488793736E-004,
+-3.655125911E-004,
+-3.816867538E-004,
+-3.972945851E-004,
+-4.122247046E-004,
+-4.263620067E-004,
+-4.395879805E-004,
+-4.517810594E-004,
+-4.628172028E-004,
+-4.725702747E-004,
+-4.809123348E-004,
+-4.877146275E-004,
+-4.928477574E-004,
+-4.961824161E-004,
+-4.975944757E-004,
+-4.969481961E-004,
+-4.941228544E-004,
+-4.889960401E-004,
++4.814492422E-004,
++4.713678791E-004,
++4.586426076E-004,
++4.431701091E-004,
++4.248536134E-004,
++4.036037717E-004,
++3.793396754E-004,
++3.519894381E-004,
++3.214911267E-004,
++2.877934603E-004,
++2.508567995E-004,
++2.106537577E-004,
++1.671699720E-004,
++1.204049113E-004,
++7.037253090E-005,
++1.710198012E-005,
+-3.936182839E-005,
+-9.895755647E-005,
+-1.616069785E-004,
+-2.272142592E-004,
+-2.956659591E-004,
+-3.668301215E-004,
+-4.405563814E-004,
+-5.166754709E-004,
+-5.949990009E-004,
+-6.753197522E-004,
+-7.574109477E-004,
+-8.410271257E-004,
+-9.259034996E-004,
+-1.011756598E-003,
+-1.098284614E-003,
+-1.185167348E-003,
+-1.272067428E-003,
+-1.358630019E-003,
+-1.444484224E-003,
+-1.529243193E-003,
+-1.612505526E-003,
+-1.693855622E-003,
+-1.772865304E-003,
+-1.849094522E-003,
+-1.922092517E-003,
+-1.991399564E-003,
+-2.056547208E-003,
+-2.117061289E-003,
+-2.172462177E-003,
+-2.222266514E-003,
+-2.265989315E-003,
+-2.303145360E-003,
+-2.333251061E-003,
+-2.355825622E-003,
+-2.370394068E-003,
+-2.376487479E-003,
+-2.373647178E-003,
+-2.361423569E-003,
+-2.339380793E-003,
+-2.307097195E-003,
+-2.264167881E-003,
+-2.210205887E-003,
+-2.144844970E-003,
+-2.067740774E-003,
+-1.978572691E-003,
+-1.877046190E-003,
+-1.762894331E-003,
+-1.635878929E-003,
++1.495792647E-003,
++1.342460280E-003,
++1.175740734E-003,
++9.955273708E-004,
++8.017504588E-004,
++5.943773431E-004,
++3.734139318E-004,
++1.389056415E-004,
+-1.090620208E-004,
+-3.703625989E-004,
+-6.448282511E-004,
+-9.322494152E-004,
+-1.232374110E-003,
+-1.544908970E-003,
+-1.869517611E-003,
+-2.205822384E-003,
+-2.553403843E-003,
+-2.911801683E-003,
+-3.280514618E-003,
+-3.659002949E-003,
+-4.046686925E-003,
+-4.442950245E-003,
+-4.847140983E-003,
+-5.258570891E-003,
+-5.676518660E-003,
+-6.100233644E-003,
+-6.528933067E-003,
+-6.961807609E-003,
+-7.398022339E-003,
+-7.836719044E-003,
+-8.277016692E-003,
+-8.718019351E-003,
+-9.158811532E-003,
+-9.598465636E-003,
+-1.003604382E-002,
+-1.047059800E-002,
+-1.090117730E-002,
+-1.132682897E-002,
+-1.174659748E-002,
+-1.215953380E-002,
+-1.256469358E-002,
+-1.296114177E-002,
+-1.334795821E-002,
+-1.372423489E-002,
+-1.408908330E-002,
+-1.444163360E-002,
+-1.478104480E-002,
+-1.510649733E-002,
+-1.541720331E-002,
+-1.571240649E-002,
+-1.599138230E-002,
+-1.625344716E-002,
+-1.649795473E-002,
+-1.672429405E-002,
+-1.693190821E-002,
+-1.712027565E-002,
+-1.728892699E-002,
+-1.743743755E-002,
+-1.756543480E-002,
+-1.767260395E-002,
+-1.775865816E-002,
+-1.782339066E-002,
+-1.786663756E-002,
+-1.788828894E-002,
++1.788828894E-002,
++1.786663756E-002,
++1.782339066E-002,
++1.775865816E-002,
++1.767260395E-002,
++1.756543480E-002,
++1.743743755E-002,
++1.728892699E-002,
++1.712027565E-002,
++1.693190821E-002,
++1.672429405E-002,
++1.649795473E-002,
++1.625344716E-002,
++1.599138230E-002,
++1.571240649E-002,
++1.541720331E-002,
++1.510649733E-002,
++1.478104480E-002,
++1.444163360E-002,
++1.408908330E-002,
++1.372423489E-002,
++1.334795821E-002,
++1.296114177E-002,
++1.256469358E-002,
++1.215953380E-002,
++1.174659748E-002,
++1.132682897E-002,
++1.090117730E-002,
++1.047059800E-002,
++1.003604382E-002,
++9.598465636E-003,
++9.158811532E-003,
++8.718019351E-003,
++8.277016692E-003,
++7.836719044E-003,
++7.398022339E-003,
++6.961807609E-003,
++6.528933067E-003,
++6.100233644E-003,
++5.676518660E-003,
++5.258570891E-003,
++4.847140983E-003,
++4.442950245E-003,
++4.046686925E-003,
++3.659002949E-003,
++3.280514618E-003,
++2.911801683E-003,
++2.553403843E-003,
++2.205822384E-003,
++1.869517611E-003,
++1.544908970E-003,
++1.232374110E-003,
++9.322494152E-004,
++6.448282511E-004,
++3.703625989E-004,
++1.090620208E-004,
+-1.389056415E-004,
+-3.734139318E-004,
+-5.943773431E-004,
+-8.017504588E-004,
+-9.955273708E-004,
+-1.175740734E-003,
+-1.342460280E-003,
+-1.495792647E-003,
++1.635878929E-003,
++1.762894331E-003,
++1.877046190E-003,
++1.978572691E-003,
++2.067740774E-003,
++2.144844970E-003,
++2.210205887E-003,
++2.264167881E-003,
++2.307097195E-003,
++2.339380793E-003,
++2.361423569E-003,
++2.373647178E-003,
++2.376487479E-003,
++2.370394068E-003,
++2.355825622E-003,
++2.333251061E-003,
++2.303145360E-003,
++2.265989315E-003,
++2.222266514E-003,
++2.172462177E-003,
++2.117061289E-003,
++2.056547208E-003,
++1.991399564E-003,
++1.922092517E-003,
++1.849094522E-003,
++1.772865304E-003,
++1.693855622E-003,
++1.612505526E-003,
++1.529243193E-003,
++1.444484224E-003,
++1.358630019E-003,
++1.272067428E-003,
++1.185167348E-003,
++1.098284614E-003,
++1.011756598E-003,
++9.259034996E-004,
++8.410271257E-004,
++7.574109477E-004,
++6.753197522E-004,
++5.949990009E-004,
++5.166754709E-004,
++4.405563814E-004,
++3.668301215E-004,
++2.956659591E-004,
++2.272142592E-004,
++1.616069785E-004,
++9.895755647E-005,
++3.936182839E-005,
+-1.710198012E-005,
+-7.037253090E-005,
+-1.204049113E-004,
+-1.671699720E-004,
+-2.106537577E-004,
+-2.508567995E-004,
+-2.877934603E-004,
+-3.214911267E-004,
+-3.519894381E-004,
+-3.793396754E-004,
+-4.036037717E-004,
+-4.248536134E-004,
+-4.431701091E-004,
+-4.586426076E-004,
+-4.713678791E-004,
+-4.814492422E-004,
++4.889960401E-004,
++4.941228544E-004,
++4.969481961E-004,
++4.975944757E-004,
++4.961824161E-004,
++4.928477574E-004,
++4.877146275E-004,
++4.809123348E-004,
++4.725702747E-004,
++4.628172028E-004,
++4.517810594E-004,
++4.395879805E-004,
++4.263620067E-004,
++4.122247046E-004,
++3.972945851E-004,
++3.816867538E-004,
++3.655125911E-004,
++3.488793736E-004,
++3.318900708E-004,
++3.146430245E-004,
++2.972317743E-004,
++2.797449124E-004,
++2.622658503E-004,
++2.448728774E-004,
++2.276388550E-004,
++2.106313768E-004,
++1.939126523E-004,
++1.775395358E-004,
++1.615635992E-004,
++1.460311323E-004,
++1.309833024E-004,
++1.164562127E-004,
++1.024810626E-004,
++8.908427117E-005,
++7.628766616E-005,
++6.410864444E-005,
++5.256036457E-005,
++4.165195787E-005,
++3.138873581E-005,
++2.177240640E-005,
++1.280130618E-005,
++4.470633485E-006,
+-3.227306706E-006,
+-1.030297699E-005,
+-1.676913780E-005,
+-2.264085742E-005,
+-2.793515523E-005,
+-3.267079956E-005,
+-3.686808850E-005,
+-4.054862075E-005,
+-4.373511547E-005,
+-4.645117951E-005,
+-4.872112549E-005,
+-5.056979353E-005,
+-5.202236207E-005,
+-5.310418419E-005,
+-5.384063843E-005,
+-5.425697600E-005,
+-5.437819709E-005,
+-5.422891263E-005,
+-5.383323878E-005,
+-5.321469871E-005,
+-5.239612074E-005,
+-5.139957648E-005,
++5.024627535E-005,
++4.895655002E-005,
++4.754976908E-005,
++4.604430433E-005,
++4.445751256E-005,
++4.280570283E-005,
++4.110412556E-005,
++3.936696885E-005,
++3.760734762E-005,
++3.583733633E-005,
++3.406793985E-005,
++3.230916263E-005,
++3.056998685E-005,
++2.885844333E-005,
++2.718161704E-005,
++2.554569073E-005,
++2.395598858E-005,
++2.241701623E-005,
++2.093250441E-005,
++1.950545993E-005,
++1.813820381E-005,
++1.683242772E-005,
++1.558924305E-005,
++1.440921824E-005,
++1.329243969E-005,
++1.223855270E-005,
++1.124680875E-005,
++1.031611009E-005,
++9.445050637E-006,
++8.631964192E-006,
++7.874960829E-006,
++7.171964626E-006,
++6.520755960E-006,
++5.918994248E-006,
++5.364252502E-006,
++4.854050530E-006,
++4.385879038E-006,
++3.957220997E-006,
++3.565570978E-006,
++3.208459020E-006,
++2.883470643E-006,
++2.588257530E-006,
++2.320550948E-006,
++2.078171747E-006,
++1.859034001E-006,
++1.661159786E-006,
++1.482681114E-006,
++1.321840614E-006,
++1.176999604E-006,
++1.046637067E-006,
++9.293416952E-007,
++8.238164355E-007,
++7.288739425E-007,
++6.434325428E-007,
++5.665120852E-007,
++4.972276315E-007,
++4.347855338E-007,
++3.784752209E-007,
++3.276689142E-007,
++2.818143514E-007,
++2.404238444E-007,
++2.030677564E-007,
++1.693738625E-007,
++1.390191784E-007
+};
+
+//FIXME the coeffs are symetric
+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
+};
+
+//FIXME the coeffs are symetric
+
+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
+};
+
+/* 10^-(dB/20), with dB beeing a list of dB values rangeing from 0 to -72 */
+/* do a 20*log10(dca_downmix_coeffs) to reconvert the values */
+
+static const float dca_downmix_coeffs[65] = {
+ 1.000000000000000, 0.988553094656939, 0.971627951577106, 0.944060876285923, 0.917275935389780, 0.891250938133746,
+ 0.865964323360065, 0.841395141645195, 0.817523037943650, 0.794328234724281, 0.771791515585012, 0.749894209332456,
+ 0.728618174513228, 0.707945784384138, 0.687859912308808, 0.668343917568615, 0.649381631576211, 0.630957344480193,
+ 0.613055792149821, 0.595662143529010, 0.578761988349121, 0.562341325190349, 0.546386549881854, 0.530884444230988,
+ 0.515822165072306, 0.501187233627272, 0.446683592150963, 0.398107170553497, 0.354813389233575, 0.316227766016838,
+ 0.281838293126445, 0.251188643150958, 0.223872113856834, 0.199526231496888, 0.177827941003892, 0.158489319246111,
+ 0.141253754462275, 0.125892541179417, 0.112201845430196, 0.100000000000000, 0.089125093813374, 0.079432823472428,
+ 0.070794578438414, 0.063095734448019, 0.053088444423099, 0.044668359215096, 0.037583740428844, 0.031622776601684,
+ 0.026607250597988, 0.022387211385683, 0.018836490894898, 0.015848931924611, 0.013335214321633, 0.011220184543020,
+ 0.009440608762859, 0.007943282347243, 0.005623413251903, 0.003981071705535, 0.002818382931264, 0.001995262314969,
+ 0.001412537544623, 0.001000000000000, 0.000501187233627, 0.000251188643151, 0.000000000000000,
+};
+
+/* downmix coeffs
+
+ TABLE 9
+______________________________________
+Down-mix coefficients for 8-channel source
+audio (5 + 3 format)
+ lt
+ cen- rt lt ctr rt
+lt ter ctr center
+ rt srd srd srd
+______________________________________
+1 0.71 0.74 1.0 0.71 0.71 0.58 0.58 0.58
+2 left 1.0 0.89 0.71 0.46 0.71 0.50
+ rt 0.45 0.71 0.89 1.0 0.50 0.71
+3 lt 1.0 0.89 0.71 0.45
+ rt 0.45 0.71 0.89 1.0
+ srd 0.71 0.71 0.71
+4 lt 1.0 0.89 0.71 0.45
+ rt 0.45 0.71 0.89 1.0
+ lt srd 1.0 0.71
+ rt srd 0.71 0.71
+4 lt 1.0 0.5
+ ctr 0.87 1.0 0.87
+ rt 0.5 1.0
+ srd 0.71 0.71 0.71
+5 lt 1.0 0.5
+ ctr 0.87 1.0 0.87
+ rt 0.5 1.0
+ lt srd 1.0 0.71
+ rt srd 0.71 1.0
+6 lt 1.0 0.5
+ lt ctr 0.87 0.71
+ rt ctr 0.71 0.87
+ rt 0.5 1.0
+ lt srd 1.0 0.71
+ rt srd 0.71 1.0
+6 lt 1.0 0.5
+ ctr 0.86 1.0 0.86
+ rt 0.5 1.0
+ lt srd 1.0
+ ctr srd 1.0
+ rt srd 1.0
+7 lt 1.0
+ lt ctr 1.0
+ ctr 1.0
+ rt ctr 1.0
+ rt 1.0
+ lt srd 1.0 0.71
+ rt srd 0.71 1.0
+7 lt 1.0 0.5
+ lt ctr 0.87 0.71
+ rt ctr 0.71 0.87
+ rt 0.5 1.0
+ lt srd 1.0
+ ctr srd 1.0
+ rt srd 1.0
+8 lt 1.0 0.5
+ lt ctr 0.87 0.71
+ rt ctr 0.71 0.87
+ rt 0.5 1.0
+ lt 1 srd 0.87 0.35
+ lt 2 srd 0.5 0.61
+ rt 2 srd 0.61 0.50
+ rt 2 srd 0.35 0.87
+
+ Generation of Lt Rt
+
+In the case when the playback system has analog or digital surround multi-channel capability, a down matrix from 5, 4, or 3 channel to Lt Rt may be desirable. In the case when the number of decoded audio channels exceeds 5, 4 or 3 respectively a first stage down mix to 5, 4 or 3 chs should be used as described above.
+
+The down matrixing equations for 5-channel source audio to a two-channel Lt Rt playback system are given by:
+
+Left left+0.7*center-0.7*(lt surround+rt surround)
+
+Right=right+0.7*center+0.7*(lt surround+rt surround)
+
+Embedded mixing to 2-channel
+
+One concern arising from the proliferation of multi-channel audio systems is that most home systems presently have only two channel playback capability. To accommodate this a fixed 2-channel down matrix processes is commonly used following the multi-channel decoding stage. However, for music only applications the image quality etc. of the down matrixed signal may not match that of an equivalent stereo recording found on CD.
+
+The concept of embedded mixing is to allow the producer to dynamically specify the matrixing coefficients within the audio frame itself. In this way the stereo down mix at the decoder may be better matched to a 2-channel playback environment.
+
+CHS*2, 7-bit down mix indexes (MCOEFFS) are transmitted along with the multi-channel audio once in every frame. The indexes are converted to attenuation factors using a 7 bit LUT. The 2-ch down mix equations are as follows,
+
+Left Ch=sum (MCOEFF[n]*Ch[n]) for n=1, CHS
+
+Right Ch sum (MCOEFF[n+CHS]*Ch[n]) for n=1, CHS
+
+where Ch(n) represents the subband samples in the (n)th audio channel.
+
+
+*/
diff --git a/contrib/ffmpeg/libavcodec/dcahuff.h b/contrib/ffmpeg/libavcodec/dcahuff.h
new file mode 100644
index 000000000..8a78aee7e
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/dcahuff.h
@@ -0,0 +1,1068 @@
+/*
+ * DCA compatible decoder - huffman tables
+ * Copyright (C) 2004 Gildas Bazin
+ * Copyright (C) 2007 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
+ */
+
+#define TMODE_COUNT 4
+static const uint8_t tmode_vlc_bits[TMODE_COUNT] = { 3, 3, 3, 2 };
+static const uint16_t tmode_codes[TMODE_COUNT][4] = {
+ { 0x0000, 0x0002, 0x0006, 0x0007 },
+ { 0x0002, 0x0006, 0x0007, 0x0000 },
+ { 0x0006, 0x0007, 0x0000, 0x0002 },
+ { 0x0000, 0x0001, 0x0002, 0x0003 }
+};
+static const uint8_t tmode_bits[TMODE_COUNT][4] = {
+ { 1, 2, 3, 3 },
+ { 2, 3, 3, 1 },
+ { 3, 3, 1, 2 },
+ { 2, 2, 2, 2 }
+};
+
+
+#define BITALLOC_12_COUNT 5
+#define BITALLOC_12_VLC_BITS 9
+static const uint8_t bitalloc_12_vlc_bits[BITALLOC_12_COUNT] = {
+ 9, 7, 7, 9, 9
+};
+static const uint16_t bitalloc_12_codes[BITALLOC_12_COUNT][12] = {
+ {
+ 0x0000, 0x0002, 0x0006, 0x000E, 0x001E, 0x003E, 0x00FF, 0x00FE,
+ 0x01FB, 0x01FA, 0x01F9, 0x01F8,
+ },
+ {
+ 0x0001, 0x0000, 0x0002, 0x000F, 0x000C, 0x001D, 0x0039, 0x0038,
+ 0x0037, 0x0036, 0x0035, 0x0034,
+ },
+ {
+ 0x0000, 0x0007, 0x0005, 0x0004, 0x0002, 0x000D, 0x000C, 0x0006,
+ 0x000F, 0x001D, 0x0039, 0x0038,
+ },
+ {
+ 0x0003, 0x0002, 0x0000, 0x0002, 0x0006, 0x000E, 0x001E, 0x003E,
+ 0x007E, 0x00FE, 0x01FF, 0x01FE,
+ },
+ {
+ 0x0001, 0x0000, 0x0002, 0x0006, 0x000E, 0x003F, 0x003D, 0x007C,
+ 0x0079, 0x0078, 0x00FB, 0x00FA,
+ }
+};
+static const uint8_t bitalloc_12_bits[BITALLOC_12_COUNT][12] = {
+ { 1, 2, 3, 4, 5, 6, 8, 8, 9, 9, 9, 9 },
+ { 1, 2, 3, 5, 5, 6, 7, 7, 7, 7, 7, 7 },
+ { 2, 3, 3, 3, 3, 4, 4, 4, 5, 6, 7, 7 },
+ { 2, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10 },
+ { 1, 2, 3, 4, 5, 7, 7, 8, 8, 8, 9, 9 }
+};
+
+
+#define SCALES_COUNT 5
+#define SCALES_VLC_BITS 9
+static const uint16_t scales_codes[SCALES_COUNT][129] = {
+ {
+ 0x3AB0, 0x3AB2, 0x3AB4, 0x3AB6, 0x3AB8, 0x3ABA, 0x3ABC, 0x3ABE,
+ 0x3AC0, 0x3AC2, 0x3AC4, 0x3AC6, 0x3AC8, 0x3ACA, 0x3ACC, 0x3ACE,
+ 0x3AD0, 0x3AD2, 0x3AD4, 0x3AD6, 0x3AD8, 0x3ADA, 0x3ADC, 0x3ADE,
+ 0x3AE0, 0x3AE2, 0x3AE4, 0x3AE6, 0x3AE8, 0x3AEA, 0x3AEC, 0x3AEE,
+ 0x3AF0, 0x3AF2, 0x3AF4, 0x3AF6, 0x3AF8, 0x3AFA, 0x3AFC, 0x3AFE,
+ 0x0540, 0x0542, 0x0544, 0x0546, 0x0548, 0x054A, 0x054C, 0x054E,
+ 0x0558, 0x055E, 0x02AD, 0x0154, 0x0754, 0x03A8, 0x0056, 0x0028,
+ 0x00E8, 0x004A, 0x000B, 0x003B, 0x0013, 0x0003, 0x000F, 0x0005,
+ 0x0001, 0x0006, 0x0000, 0x0008, 0x001C, 0x0004, 0x0024, 0x004B,
+ 0x00E9, 0x0029, 0x0057, 0x03A9, 0x0755, 0x0155, 0x02AE, 0x055F,
+ 0x0559, 0x054F, 0x054D, 0x054B, 0x0549, 0x0547, 0x0545, 0x0543,
+ 0x0541, 0x3AFF, 0x3AFD, 0x3AFB, 0x3AF9, 0x3AF7, 0x3AF5, 0x3AF3,
+ 0x3AF1, 0x3AEF, 0x3AED, 0x3AEB, 0x3AE9, 0x3AE7, 0x3AE5, 0x3AE3,
+ 0x3AE1, 0x3ADF, 0x3ADD, 0x3ADB, 0x3AD9, 0x3AD7, 0x3AD5, 0x3AD3,
+ 0x3AD1, 0x3ACF, 0x3ACD, 0x3ACB, 0x3AC9, 0x3AC7, 0x3AC5, 0x3AC3,
+ 0x3AC1, 0x3ABF, 0x3ABD, 0x3ABB, 0x3AB9, 0x3AB7, 0x3AB5, 0x3AB3,
+ 0x3AB1,
+ },
+ {
+ 0x0F60, 0x0F62, 0x0F64, 0x0F66, 0x0F68, 0x0F6A, 0x0F6C, 0x0F6E,
+ 0x0F70, 0x0F72, 0x0F74, 0x0F76, 0x0F78, 0x0F7A, 0x0F7C, 0x0F7E,
+ 0x0F80, 0x0F82, 0x0F84, 0x0F86, 0x0F88, 0x0F8A, 0x0F8C, 0x0F8E,
+ 0x0F90, 0x0F92, 0x0F94, 0x0F96, 0x0F98, 0x0F9A, 0x0F9C, 0x0F9E,
+ 0x0FA0, 0x0FA2, 0x0FA4, 0x0FA6, 0x0FA8, 0x0FAA, 0x0FAC, 0x0FAE,
+ 0x0FB0, 0x0FB2, 0x0FB4, 0x0FB6, 0x0FB8, 0x0FBA, 0x0FBC, 0x0FBE,
+ 0x07A0, 0x07A2, 0x03D2, 0x01EA, 0x00FC, 0x007F, 0x001C, 0x000C,
+ 0x0004, 0x0034, 0x0010, 0x001B, 0x0009, 0x000B, 0x000E, 0x0001,
+ 0x0003, 0x0002, 0x000F, 0x000C, 0x000A, 0x0000, 0x0011, 0x0035,
+ 0x0005, 0x000D, 0x001D, 0x003C, 0x00FD, 0x01EB, 0x03D3, 0x07A3,
+ 0x07A1, 0x0FBF, 0x0FBD, 0x0FBB, 0x0FB9, 0x0FB7, 0x0FB5, 0x0FB3,
+ 0x0FB1, 0x0FAF, 0x0FAD, 0x0FAB, 0x0FA9, 0x0FA7, 0x0FA5, 0x0FA3,
+ 0x0FA1, 0x0F9F, 0x0F9D, 0x0F9B, 0x0F99, 0x0F97, 0x0F95, 0x0F93,
+ 0x0F91, 0x0F8F, 0x0F8D, 0x0F8B, 0x0F89, 0x0F87, 0x0F85, 0x0F83,
+ 0x0F81, 0x0F7F, 0x0F7D, 0x0F7B, 0x0F79, 0x0F77, 0x0F75, 0x0F73,
+ 0x0F71, 0x0F6F, 0x0F6D, 0x0F6B, 0x0F69, 0x0F67, 0x0F65, 0x0F63,
+ 0x0F61,
+ },
+ {
+ 0x51D0, 0x51D2, 0x51D4, 0x51D6, 0x51D8, 0x51DA, 0x51DC, 0x51DE,
+ 0x51E0, 0x51E2, 0x51E4, 0x51E6, 0x51E8, 0x51EA, 0x51EC, 0x51EE,
+ 0x51F0, 0x51F2, 0x51F4, 0x51F6, 0x51F8, 0x51FA, 0x51FC, 0x51FE,
+ 0x70C0, 0x70C2, 0x70C4, 0x70C6, 0x70C8, 0x70CA, 0x70CC, 0x70CE,
+ 0x70EC, 0x10EA, 0x3868, 0x3877, 0x0876, 0x1C35, 0x0434, 0x0A34,
+ 0x0E1B, 0x021B, 0x051B, 0x070F, 0x010F, 0x0380, 0x0080, 0x0140,
+ 0x01C1, 0x0041, 0x00A1, 0x00E2, 0x0022, 0x0052, 0x0072, 0x0012,
+ 0x002A, 0x003A, 0x000A, 0x0016, 0x001E, 0x0006, 0x000C, 0x0000,
+ 0x0004, 0x0001, 0x000D, 0x0007, 0x001F, 0x0017, 0x000B, 0x003B,
+ 0x002B, 0x0013, 0x0073, 0x0053, 0x0023, 0x00E3, 0x00A2, 0x0042,
+ 0x01C2, 0x0141, 0x0081, 0x0381, 0x028C, 0x010C, 0x051C, 0x021C,
+ 0x0E1C, 0x0A35, 0x0435, 0x1C3A, 0x0877, 0x0874, 0x3869, 0x10EB,
+ 0x70ED, 0x70CF, 0x70CD, 0x70CB, 0x70C9, 0x70C7, 0x70C5, 0x70C3,
+ 0x70C1, 0x51FF, 0x51FD, 0x51FB, 0x51F9, 0x51F7, 0x51F5, 0x51F3,
+ 0x51F1, 0x51EF, 0x51ED, 0x51EB, 0x51E9, 0x51E7, 0x51E5, 0x51E3,
+ 0x51E1, 0x51DF, 0x51DD, 0x51DB, 0x51D9, 0x51D7, 0x51D5, 0x51D3,
+ 0x51D1,
+ },
+ {
+ 0x6F64, 0x6F66, 0x6F68, 0x6F6A, 0x6F6C, 0x6F6E, 0x6F70, 0x6F72,
+ 0x6F74, 0x6F76, 0x6F78, 0x6F7A, 0x6F7C, 0x6F7E, 0x6F80, 0x6F82,
+ 0x6F84, 0x6F86, 0x6F88, 0x6F8A, 0x6F8C, 0x6F8E, 0x6F90, 0x6F92,
+ 0x6F94, 0x6F96, 0x6F98, 0x6F9A, 0x6F9C, 0x6F9E, 0x6FA0, 0x6FA2,
+ 0x6FA4, 0x6FA6, 0x6FA8, 0x6FAA, 0x6FAC, 0x6FAE, 0x6FB0, 0x6FB2,
+ 0x6FB4, 0x6FB6, 0x17B4, 0x37DC, 0x0BDB, 0x1BEF, 0x05EE, 0x0DF8,
+ 0x02F8, 0x06FD, 0x017D, 0x037F, 0x00BF, 0x0040, 0x00C0, 0x0021,
+ 0x0061, 0x0011, 0x0031, 0x0009, 0x0019, 0x0006, 0x000E, 0x0004,
+ 0x0000, 0x0005, 0x000F, 0x0007, 0x001A, 0x000A, 0x0036, 0x0016,
+ 0x006E, 0x002E, 0x00C1, 0x0041, 0x01BC, 0x00BC, 0x037A, 0x017A,
+ 0x02F9, 0x0DF9, 0x05EF, 0x05EC, 0x1BD8, 0x37DD, 0x17B5, 0x6FB7,
+ 0x6FB5, 0x6FB3, 0x6FB1, 0x6FAF, 0x6FAD, 0x6FAB, 0x6FA9, 0x6FA7,
+ 0x6FA5, 0x6FA3, 0x6FA1, 0x6F9F, 0x6F9D, 0x6F9B, 0x6F99, 0x6F97,
+ 0x6F95, 0x6F93, 0x6F91, 0x6F8F, 0x6F8D, 0x6F8B, 0x6F89, 0x6F87,
+ 0x6F85, 0x6F83, 0x6F81, 0x6F7F, 0x6F7D, 0x6F7B, 0x6F79, 0x6F77,
+ 0x6F75, 0x6F73, 0x6F71, 0x6F6F, 0x6F6D, 0x6F6B, 0x6F69, 0x6F67,
+ 0x6F65,
+ },
+ {
+ 0xDF54, 0xDF56, 0xDFC8, 0xDFCA, 0xDFCC, 0xDFCE, 0xDFD0, 0xDFD2,
+ 0xDFD4, 0xDFD6, 0xDFD8, 0xDFDA, 0xDFDC, 0xDFDE, 0xDFE0, 0xDFE2,
+ 0x0FE8, 0x2FEA, 0x6FA8, 0x6FF6, 0x07F5, 0x07F7, 0x37D2, 0x37F9,
+ 0x03F8, 0x0BF8, 0x0BFB, 0x1BEB, 0x01FA, 0x05FA, 0x09FA, 0x0DFA,
+ 0x0DFF, 0x00FF, 0x02FF, 0x06FB, 0x007C, 0x017C, 0x027C, 0x027F,
+ 0x003C, 0x00BC, 0x013C, 0x01BC, 0x001C, 0x005C, 0x009C, 0x00DC,
+ 0x000C, 0x002C, 0x004C, 0x006C, 0x0004, 0x0014, 0x0024, 0x0034,
+ 0x0000, 0x0008, 0x0010, 0x0018, 0x001E, 0x0002, 0x0006, 0x000A,
+ 0x000E, 0x000B, 0x0007, 0x0003, 0x001F, 0x0019, 0x0011, 0x0009,
+ 0x0001, 0x0035, 0x0025, 0x0015, 0x0005, 0x006D, 0x004D, 0x002D,
+ 0x000D, 0x00DD, 0x009D, 0x005D, 0x001D, 0x01BD, 0x013D, 0x00BD,
+ 0x003D, 0x037C, 0x027D, 0x017D, 0x007D, 0x06FC, 0x04FC, 0x02FC,
+ 0x00FC, 0x0DFB, 0x09FB, 0x05FB, 0x01FB, 0x1BF8, 0x1BE8, 0x0BF9,
+ 0x03F9, 0x37FA, 0x37D3, 0x17F4, 0x07F6, 0x6FF7, 0x6FA9, 0x2FEB,
+ 0x0FE9, 0xDFE3, 0xDFE1, 0xDFDF, 0xDFDD, 0xDFDB, 0xDFD9, 0xDFD7,
+ 0xDFD5, 0xDFD3, 0xDFD1, 0xDFCF, 0xDFCD, 0xDFCB, 0xDFC9, 0xDF57,
+ 0xDF55,
+ }
+};
+
+static const uint8_t scales_bits[SCALES_COUNT][129] = {
+ {
+ 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14,
+ 13, 13, 13, 13, 13, 13, 13, 13,
+ 13, 13, 12, 11, 11, 10, 9, 8,
+ 8, 7, 6, 6, 5, 4, 4, 3,
+ 2, 3, 3, 4, 5, 5, 6, 7,
+ 8, 8, 9, 10, 11, 11, 12, 13,
+ 13, 13, 13, 13, 13, 13, 13, 13,
+ 13, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14,
+ 14,
+ },
+ {
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 14, 14, 13, 12, 11, 10, 8, 7,
+ 6, 6, 5, 5, 4, 4, 4, 3,
+ 3, 3, 4, 4, 4, 4, 5, 6,
+ 6, 7, 8, 9, 11, 12, 13, 14,
+ 14, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15,
+ },
+ {
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 14, 14, 14, 13, 13, 12, 12,
+ 12, 11, 11, 11, 10, 10, 9, 9,
+ 9, 8, 8, 8, 7, 7, 7, 6,
+ 6, 6, 5, 5, 5, 4, 4, 3,
+ 3, 3, 4, 4, 5, 5, 5, 6,
+ 6, 6, 7, 7, 7, 8, 8, 8,
+ 9, 9, 9, 10, 10, 10, 11, 11,
+ 12, 12, 12, 13, 13, 13, 14, 14,
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15,
+ },
+ {
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 14, 14, 13, 13, 12, 12,
+ 11, 11, 10, 10, 9, 8, 8, 7,
+ 7, 6, 6, 5, 5, 4, 4, 3,
+ 2, 3, 4, 4, 5, 5, 6, 6,
+ 7, 7, 8, 8, 9, 9, 10, 10,
+ 11, 12, 12, 12, 13, 14, 14, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15,
+ },
+ {
+ 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16,
+ 15, 15, 15, 15, 14, 14, 14, 14,
+ 13, 13, 13, 13, 12, 12, 12, 12,
+ 12, 11, 11, 11, 10, 10, 10, 10,
+ 9, 9, 9, 9, 8, 8, 8, 8,
+ 7, 7, 7, 7, 6, 6, 6, 6,
+ 5, 5, 5, 5, 5, 4, 4, 4,
+ 4, 4, 4, 4, 5, 5, 5, 5,
+ 5, 6, 6, 6, 6, 7, 7, 7,
+ 7, 8, 8, 8, 8, 9, 9, 9,
+ 9, 10, 10, 10, 10, 11, 11, 11,
+ 11, 12, 12, 12, 12, 13, 13, 13,
+ 13, 14, 14, 14, 14, 15, 15, 15,
+ 15, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16,
+ 16,
+ }
+};
+
+static const uint16_t bitalloc_3_codes[3] =
+{
+ 0x0003, 0x0000, 0x0002,
+};
+static const uint8_t bitalloc_3_bits[3] =
+{
+ 2, 1, 2,
+};
+
+static const uint16_t bitalloc_5_codes_a[5] =
+{
+ 0x000F, 0x0006, 0x0000, 0x0002, 0x000E,
+};
+static const uint16_t bitalloc_5_codes_b[5] =
+{
+ 0x0007, 0x0001, 0x0002, 0x0000, 0x0006,
+};
+static const uint16_t bitalloc_5_codes_c[5] =
+{
+ 0x0007, 0x0005, 0x0000, 0x0004, 0x0006,
+};
+static const uint8_t bitalloc_5_bits_a[5] =
+{
+ 4, 3, 1, 2, 4,
+};
+static const uint8_t bitalloc_5_bits_b[5] =
+{
+ 3, 2, 2, 2, 3,
+};
+static const uint8_t bitalloc_5_bits_c[5] =
+{
+ 3, 3, 1, 3, 3,
+};
+
+static const uint16_t bitalloc_7_codes_a[7] =
+{
+ 0x001E, 0x000E, 0x0005, 0x0000, 0x0006, 0x0004, 0x001F,
+};
+static const uint16_t bitalloc_7_codes_b[7] =
+{
+ 0x0014, 0x000B, 0x0000, 0x0003, 0x0001, 0x0004, 0x0015,
+};
+static const uint16_t bitalloc_7_codes_c[7] =
+{
+ 0x0000, 0x0002, 0x0001, 0x0003, 0x0002, 0x0003, 0x0001,
+};
+static const uint8_t bitalloc_7_bits_a[7] =
+{
+ 5, 4, 3, 1, 3, 3, 5,
+};
+static const uint8_t bitalloc_7_bits_b[7] =
+{
+ 5, 4, 2, 2, 2, 3, 5,
+};
+static const uint8_t bitalloc_7_bits_c[7] =
+{
+ 4, 4, 2, 2, 2, 4, 4,
+};
+
+static const uint16_t bitalloc_9_codes_a[9] =
+{
+ 0x0030, 0x0019, 0x0009, 0x0005, 0x0000, 0x0007, 0x000D, 0x0008,
+ 0x0031,
+};
+static const uint16_t bitalloc_9_codes_b[9] =
+{
+ 0x0018, 0x001A, 0x0002, 0x0007, 0x0002, 0x0000, 0x0003, 0x001B,
+ 0x0019,
+};
+static const uint16_t bitalloc_9_codes_c[9] =
+{
+ 0x001C, 0x000F, 0x0002, 0x0007, 0x0002, 0x0000, 0x0006, 0x0006,
+ 0x001D,
+};
+static const uint8_t bitalloc_9_bits_a[9] =
+{
+ 6, 5, 4, 3, 1, 3, 4, 4, 6,
+};
+static const uint8_t bitalloc_9_bits_b[9] =
+{
+ 5, 5, 3, 3, 2, 2, 3, 5, 5,
+};
+static const uint8_t bitalloc_9_bits_c[9] =
+{
+ 6, 5, 3, 3, 2, 2, 3, 4, 6,
+};
+
+static const uint16_t bitalloc_13_codes_a[13] =
+{
+ 0x0070, 0x002E, 0x0039, 0x001D, 0x000C, 0x000F, 0x0000, 0x0004,
+ 0x000D, 0x000A, 0x0016, 0x002F, 0x0071,
+};
+static const uint16_t bitalloc_13_codes_b[13] =
+{
+ 0x0038, 0x0010, 0x001D, 0x0007, 0x000F, 0x0005, 0x0000, 0x0006,
+ 0x0002, 0x0009, 0x0006, 0x0011, 0x0039,
+};
+static const uint16_t bitalloc_13_codes_c[13] =
+{
+ 0x0004, 0x001A, 0x0003, 0x000E, 0x0000, 0x0003, 0x0005, 0x0004,
+ 0x0002, 0x000F, 0x000C, 0x001B, 0x0005,
+};
+static const uint8_t bitalloc_13_bits_a[13] =
+{
+ 7, 6, 6, 5, 4, 4, 1, 3, 4, 4, 5, 6, 7,
+};
+static const uint8_t bitalloc_13_bits_b[13] =
+{
+ 6, 5, 5, 4, 4, 3, 2, 3, 3, 4, 4, 5, 6,
+};
+static const uint8_t bitalloc_13_bits_c[13] =
+{
+ 5, 5, 4, 4, 3, 3, 3, 3, 3, 4, 4, 5, 5,
+};
+
+static const uint16_t bitalloc_17_codes_a[17] =
+{
+ 0x0154, 0x00AB, 0x002B, 0x000B, 0x0003, 0x000A, 0x0001, 0x0006,
+ 0x0001, 0x0007, 0x0004, 0x000B, 0x0000, 0x0004, 0x0014, 0x0054,
+ 0x0155,
+};
+static const uint16_t bitalloc_17_codes_b[17] =
+{
+ 0x007C, 0x003F, 0x0019, 0x000D, 0x001C, 0x0008, 0x000F, 0x0005,
+ 0x0000, 0x0006, 0x0002, 0x0009, 0x001D, 0x000E, 0x001E, 0x0018,
+ 0x007D,
+};
+static const uint16_t bitalloc_17_codes_c[17] =
+{
+ 0x002C, 0x0017, 0x0005, 0x001C, 0x0003, 0x000A, 0x000F, 0x0003,
+ 0x0006, 0x0004, 0x0000, 0x000B, 0x0004, 0x001D, 0x000A, 0x0004,
+ 0x002D,
+};
+static const uint16_t bitalloc_17_codes_d[17] =
+{
+ 0x0100, 0x0102, 0x0082, 0x0042, 0x0022, 0x0012, 0x000A, 0x0006,
+ 0x0000, 0x0007, 0x000B, 0x0013, 0x0023, 0x0043, 0x0083, 0x0103,
+ 0x0101,
+};
+static const uint16_t bitalloc_17_codes_e[17] =
+{
+ 0x00E8, 0x00F6, 0x0075, 0x0034, 0x003B, 0x001B, 0x001F, 0x0004,
+ 0x0000, 0x0005, 0x000C, 0x001C, 0x003C, 0x0035, 0x007A, 0x00F7,
+ 0x00E9,
+};
+static const uint16_t bitalloc_17_codes_f[17] =
+{
+ 0x0004, 0x0003, 0x001E, 0x0001, 0x0001, 0x000E, 0x0001, 0x0004,
+ 0x0006, 0x0005, 0x0002, 0x000F, 0x0006, 0x000E, 0x001F, 0x0000,
+ 0x0005,
+};
+static const uint16_t bitalloc_17_codes_g[17] =
+{
+ 0x0060, 0x007E, 0x0031, 0x0019, 0x000D, 0x0004, 0x0000, 0x0006,
+ 0x0002, 0x0007, 0x0001, 0x0005, 0x000E, 0x001E, 0x003E, 0x007F,
+ 0x0061,
+};
+static const uint8_t bitalloc_17_bits_a[17] =
+{
+ 12, 11, 9, 7, 5, 4, 3, 3, 2, 3, 3, 4, 4, 6, 8, 10,
+ 12,
+};
+static const uint8_t bitalloc_17_bits_b[17] =
+{
+ 8, 7, 6, 5, 5, 4, 4, 3, 2, 3, 3, 4, 5, 5, 6, 6,
+ 8,
+};
+static const uint8_t bitalloc_17_bits_c[17] =
+{
+ 7, 6, 5, 5, 4, 4, 4, 3, 3, 3, 3, 4, 4, 5, 5, 5,
+ 7,
+};
+static const uint8_t bitalloc_17_bits_d[17] =
+{
+ 9, 9, 8, 7, 6, 5, 4, 3, 1, 3, 4, 5, 6, 7, 8, 9,
+ 9,
+};
+static const uint8_t bitalloc_17_bits_e[17] =
+{
+ 8, 8, 7, 6, 6, 5, 5, 3, 1, 3, 4, 5, 6, 6, 7, 8,
+ 8,
+};
+static const uint8_t bitalloc_17_bits_f[17] =
+{
+ 8, 7, 6, 5, 4, 4, 3, 3, 3, 3, 3, 4, 4, 5, 6, 6,
+ 8,
+};
+static const uint8_t bitalloc_17_bits_g[17] =
+{
+ 8, 8, 7, 6, 5, 4, 3, 3, 2, 3, 3, 4, 5, 6, 7, 8,
+ 8,
+};
+
+static const uint16_t bitalloc_25_codes_a[25] =
+{
+ 0x2854, 0x142B, 0x050B, 0x0143, 0x00A2, 0x0052, 0x002E, 0x0015,
+ 0x0004, 0x000E, 0x0000, 0x0003, 0x0006, 0x0004, 0x0001, 0x000F,
+ 0x0005, 0x0016, 0x002F, 0x0053, 0x00A3, 0x00A0, 0x0284, 0x0A14,
+ 0x2855,
+};
+static const uint16_t bitalloc_25_codes_b[25] =
+{
+ 0x001C, 0x000F, 0x0005, 0x0000, 0x0030, 0x0036, 0x000E, 0x0019,
+ 0x0001, 0x0008, 0x000E, 0x0001, 0x0005, 0x0002, 0x000F, 0x0009,
+ 0x0006, 0x001A, 0x000F, 0x0037, 0x0031, 0x0001, 0x0006, 0x0004,
+ 0x001D,
+};
+static const uint16_t bitalloc_25_codes_c[25] =
+{
+ 0x004C, 0x0027, 0x006D, 0x0028, 0x0037, 0x000E, 0x0015, 0x0000,
+ 0x0005, 0x0008, 0x000B, 0x000E, 0x0001, 0x000F, 0x000C, 0x0009,
+ 0x0006, 0x0001, 0x001A, 0x000F, 0x0008, 0x0029, 0x0012, 0x006C,
+ 0x004D,
+};
+static const uint16_t bitalloc_25_codes_d[25] =
+{
+ 0x0780, 0x0782, 0x03C2, 0x01E2, 0x00FE, 0x0079, 0x003D, 0x001C,
+ 0x000C, 0x0004, 0x0000, 0x0006, 0x0002, 0x0007, 0x0001, 0x0005,
+ 0x000D, 0x001D, 0x003E, 0x007E, 0x00FF, 0x01E3, 0x03C3, 0x0783,
+ 0x0781,
+};
+static const uint16_t bitalloc_25_codes_e[25] =
+{
+ 0x003C, 0x0092, 0x0018, 0x001F, 0x004E, 0x000D, 0x0025, 0x0004,
+ 0x0010, 0x0000, 0x000A, 0x0002, 0x0003, 0x0003, 0x000B, 0x0001,
+ 0x0011, 0x0005, 0x0026, 0x000E, 0x004F, 0x0048, 0x0019, 0x0093,
+ 0x003D,
+};
+static const uint16_t bitalloc_25_codes_f[25] =
+{
+ 0x0324, 0x0193, 0x00CE, 0x0065, 0x0024, 0x000C, 0x0013, 0x0004,
+ 0x0007, 0x000A, 0x000D, 0x000F, 0x0001, 0x0000, 0x000E, 0x000B,
+ 0x0008, 0x0005, 0x0018, 0x000D, 0x0025, 0x0066, 0x00CF, 0x00C8,
+ 0x0325,
+};
+static const uint16_t bitalloc_25_codes_g[25] =
+{
+ 0x03A8, 0x03AE, 0x01D5, 0x0094, 0x0014, 0x004B, 0x000B, 0x003B,
+ 0x0013, 0x0003, 0x000F, 0x0005, 0x0001, 0x0006, 0x0000, 0x0008,
+ 0x001C, 0x0004, 0x0024, 0x0074, 0x0015, 0x0095, 0x01D6, 0x03AF,
+ 0x03A9,
+};
+static const uint8_t bitalloc_25_bits_a[25] =
+{
+ 14, 13, 11, 9, 8, 7, 6, 5, 4, 4, 3, 3, 3, 3, 3, 4,
+ 4, 5, 6, 7, 8, 8, 10, 12, 14,
+};
+static const uint8_t bitalloc_25_bits_b[25] =
+{
+ 9, 8, 7, 6, 6, 6, 5, 5, 4, 4, 4, 3, 3, 3, 4, 4,
+ 4, 5, 5, 6, 6, 6, 7, 7, 9,
+};
+static const uint8_t bitalloc_25_bits_c[25] =
+{
+ 8, 7, 7, 6, 6, 5, 5, 4, 4, 4, 4, 4, 3, 4, 4, 4,
+ 4, 4, 5, 5, 5, 6, 6, 7, 8,
+};
+static const uint8_t bitalloc_25_bits_d[25] =
+{
+ 12, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 3, 2, 3, 3, 4,
+ 5, 6, 7, 8, 9, 10, 11, 12, 12,
+};
+static const uint8_t bitalloc_25_bits_e[25] =
+{
+ 8, 8, 7, 7, 7, 6, 6, 5, 5, 4, 4, 3, 2, 3, 4, 4,
+ 5, 5, 6, 6, 7, 7, 7, 8, 8,
+};
+static const uint8_t bitalloc_25_bits_f[25] =
+{
+ 10, 9, 8, 7, 6, 5, 5, 4, 4, 4, 4, 4, 3, 3, 4, 4,
+ 4, 4, 5, 5, 6, 7, 8, 8, 10,
+};
+static const uint8_t bitalloc_25_bits_g[25] =
+{
+ 10, 10, 9, 8, 7, 7, 6, 6, 5, 4, 4, 3, 2, 3, 3, 4,
+ 5, 5, 6, 7, 7, 8, 9, 10, 10,
+};
+
+static const uint16_t bitalloc_33_codes_a[33] =
+{
+ 0x1580, 0x1582, 0x0AC2, 0x0562, 0x02B2, 0x015E, 0x00AD, 0x0054,
+ 0x001C, 0x003C, 0x000F, 0x001F, 0x0008, 0x000B, 0x000D, 0x0000,
+ 0x0002, 0x0001, 0x000E, 0x000C, 0x0009, 0x0006, 0x0014, 0x003D,
+ 0x001D, 0x0055, 0x00AE, 0x015F, 0x02B3, 0x0563, 0x0AC3, 0x1583,
+ 0x1581,
+};
+static const uint16_t bitalloc_33_codes_b[33] =
+{
+ 0x030C, 0x0187, 0x006D, 0x0028, 0x0037, 0x0066, 0x0015, 0x0031,
+ 0x0000, 0x000B, 0x0012, 0x001A, 0x0001, 0x0007, 0x000A, 0x000E,
+ 0x0001, 0x000F, 0x000B, 0x0008, 0x0004, 0x001B, 0x0013, 0x000C,
+ 0x0001, 0x0032, 0x001A, 0x0067, 0x0060, 0x0029, 0x00C2, 0x006C,
+ 0x030D,
+};
+static const uint16_t bitalloc_33_codes_c[33] =
+{
+ 0x00CC, 0x0067, 0x0005, 0x0070, 0x0003, 0x001A, 0x0039, 0x003F,
+ 0x000A, 0x0012, 0x0018, 0x001D, 0x0001, 0x0003, 0x0007, 0x000A,
+ 0x000D, 0x000B, 0x0008, 0x0004, 0x0002, 0x001E, 0x0019, 0x0013,
+ 0x000B, 0x0000, 0x003E, 0x001B, 0x0018, 0x0071, 0x0032, 0x0004,
+ 0x00CD,
+};
+static const uint16_t bitalloc_33_codes_d[33] =
+{
+ 0x3AF8, 0x3AFA, 0x1D7E, 0x0EBC, 0x075C, 0x03AC, 0x01D4, 0x0094,
+ 0x0014, 0x004B, 0x000B, 0x003B, 0x0013, 0x0003, 0x000F, 0x0005,
+ 0x0001, 0x0006, 0x0000, 0x0008, 0x001C, 0x0004, 0x0024, 0x0074,
+ 0x0015, 0x0095, 0x01D5, 0x03AD, 0x075D, 0x0EBD, 0x1D7F, 0x3AFB,
+ 0x3AF9,
+};
+static const uint16_t bitalloc_33_codes_e[33] =
+{
+ 0x01C8, 0x01E6, 0x0064, 0x00E2, 0x00E5, 0x0030, 0x0033, 0x0073,
+ 0x007A, 0x001A, 0x003A, 0x0002, 0x001A, 0x001F, 0x0007, 0x0001,
+ 0x0002, 0x0002, 0x000C, 0x0000, 0x001B, 0x0003, 0x003B, 0x001B,
+ 0x007B, 0x0078, 0x0070, 0x0031, 0x00F2, 0x00E3, 0x0065, 0x01E7,
+ 0x01C9,
+};
+static const uint16_t bitalloc_33_codes_f[33] =
+{
+ 0x0724, 0x0393, 0x01CE, 0x00E5, 0x002C, 0x0008, 0x0017, 0x003E,
+ 0x0005, 0x0014, 0x001D, 0x0000, 0x0003, 0x0006, 0x0008, 0x000B,
+ 0x000D, 0x000C, 0x0009, 0x0007, 0x0004, 0x0001, 0x001E, 0x0015,
+ 0x000A, 0x003F, 0x0038, 0x0009, 0x002D, 0x00E6, 0x01CF, 0x01C8,
+ 0x0725,
+};
+static const uint16_t bitalloc_33_codes_g[33] =
+{
+ 0x0284, 0x0042, 0x0140, 0x0143, 0x003E, 0x00BE, 0x0011, 0x0051,
+ 0x0009, 0x0029, 0x0005, 0x0015, 0x0000, 0x0008, 0x000E, 0x0002,
+ 0x0006, 0x0003, 0x000F, 0x0009, 0x0001, 0x0016, 0x0006, 0x002E,
+ 0x000E, 0x005E, 0x001E, 0x00BF, 0x003F, 0x0020, 0x0141, 0x0043,
+ 0x0285,
+};
+static const uint8_t bitalloc_33_bits_a[33] =
+{
+ 13, 13, 12, 11, 10, 9, 8, 7, 6, 6, 5, 5, 4, 4, 4, 3,
+ 3, 3, 4, 4, 4, 4, 5, 6, 6, 7, 8, 9, 10, 11, 12, 13,
+ 13,
+};
+static const uint8_t bitalloc_33_bits_b[33] =
+{
+ 10, 9, 8, 7, 7, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4,
+ 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8,
+ 10,
+};
+static const uint8_t bitalloc_33_bits_c[33] =
+{
+ 9, 8, 7, 7, 6, 6, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 7, 7, 7,
+ 9,
+};
+static const uint8_t bitalloc_33_bits_d[33] =
+{
+ 14, 14, 13, 12, 11, 10, 9, 8, 7, 7, 6, 6, 5, 4, 4, 3,
+ 2, 3, 3, 4, 5, 5, 6, 7, 7, 8, 9, 10, 11, 12, 13, 14,
+ 14,
+};
+static const uint8_t bitalloc_33_bits_e[33] =
+{
+ 9, 9, 8, 8, 8, 7, 7, 7, 7, 6, 6, 5, 5, 5, 4, 3,
+ 2, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9,
+ 9,
+};
+static const uint8_t bitalloc_33_bits_f[33] =
+{
+ 11, 10, 9, 8, 7, 6, 6, 6, 5, 5, 5, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 8, 9, 9,
+ 11,
+};
+static const uint8_t bitalloc_33_bits_g[33] =
+{
+ 10, 9, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 4, 3,
+ 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 8, 9, 9,
+ 10,
+};
+
+static const uint16_t bitalloc_65_codes_a[65] =
+{
+ 0x9E5C, 0x9E5E, 0x4F2C, 0x2794, 0x13C4, 0x1E44, 0x09E3, 0x0F23,
+ 0x04F3, 0x0792, 0x027E, 0x03CE, 0x013D, 0x01E5, 0x009C, 0x00CC,
+ 0x0040, 0x0058, 0x0067, 0x001E, 0x0021, 0x002D, 0x003D, 0x0007,
+ 0x0011, 0x0014, 0x0017, 0x001A, 0x001C, 0x001F, 0x0001, 0x0004,
+ 0x0006, 0x0005, 0x0002, 0x0000, 0x001D, 0x001B, 0x0018, 0x0015,
+ 0x0012, 0x000E, 0x0006, 0x0032, 0x0026, 0x001F, 0x0078, 0x0059,
+ 0x0041, 0x00CD, 0x009D, 0x01E6, 0x013E, 0x03CF, 0x027F, 0x0793,
+ 0x0790, 0x04F0, 0x09E4, 0x1E45, 0x13C5, 0x2795, 0x4F2D, 0x9E5F,
+ 0x9E5D,
+};
+static const uint16_t bitalloc_65_codes_b[65] =
+{
+ 0x0A8C, 0x0547, 0x01B5, 0x0008, 0x00DB, 0x0152, 0x0005, 0x000B,
+ 0x008E, 0x00AE, 0x00E4, 0x0003, 0x0037, 0x0039, 0x0055, 0x006C,
+ 0x0073, 0x0003, 0x0015, 0x001D, 0x0028, 0x0030, 0x0037, 0x003E,
+ 0x0006, 0x000B, 0x000F, 0x0012, 0x0016, 0x0019, 0x001D, 0x0001,
+ 0x0004, 0x0002, 0x001E, 0x001A, 0x0017, 0x0013, 0x0010, 0x000C,
+ 0x0007, 0x003F, 0x0038, 0x0031, 0x0029, 0x0022, 0x001A, 0x0014,
+ 0x0000, 0x006D, 0x0056, 0x0046, 0x0038, 0x0004, 0x00E5, 0x00AF,
+ 0x008F, 0x006C, 0x000A, 0x0153, 0x0150, 0x0009, 0x02A2, 0x01B4,
+ 0x0A8D,
+};
+static const uint16_t bitalloc_65_codes_c[65] =
+{
+ 0x045C, 0x022F, 0x03F5, 0x01BC, 0x01FB, 0x0059, 0x00D0, 0x00DF,
+ 0x000A, 0x002D, 0x002F, 0x0052, 0x0069, 0x0078, 0x007F, 0x000A,
+ 0x0010, 0x001C, 0x0023, 0x002A, 0x0035, 0x003A, 0x003D, 0x0000,
+ 0x0003, 0x0006, 0x0009, 0x000C, 0x000F, 0x0012, 0x0016, 0x0018,
+ 0x001C, 0x0019, 0x0017, 0x0013, 0x0010, 0x000D, 0x000A, 0x0007,
+ 0x0004, 0x0001, 0x003E, 0x003B, 0x0036, 0x002B, 0x0028, 0x001D,
+ 0x0011, 0x000B, 0x0004, 0x0079, 0x006E, 0x0053, 0x0044, 0x002E,
+ 0x000B, 0x00FC, 0x00D1, 0x008A, 0x0058, 0x01BD, 0x0116, 0x03F4,
+ 0x045D,
+};
+static const uint16_t bitalloc_65_codes_d[65] =
+{
+ 0x70B0, 0x70B2, 0x70B4, 0x2852, 0x385B, 0x142E, 0x1C2E, 0x0A15,
+ 0x0E14, 0x0214, 0x0704, 0x0104, 0x010B, 0x0383, 0x0083, 0x0143,
+ 0x01C3, 0x0043, 0x00A2, 0x00E2, 0x0022, 0x0052, 0x0072, 0x0012,
+ 0x002A, 0x003A, 0x000A, 0x0016, 0x001E, 0x0006, 0x000C, 0x0000,
+ 0x0004, 0x0001, 0x000D, 0x0007, 0x001F, 0x0017, 0x000B, 0x003B,
+ 0x002B, 0x0013, 0x0073, 0x0053, 0x0023, 0x00E3, 0x00A3, 0x00A0,
+ 0x0040, 0x01C0, 0x0084, 0x0384, 0x0284, 0x0105, 0x0705, 0x0215,
+ 0x0E15, 0x0A16, 0x1C2F, 0x142F, 0x1428, 0x2853, 0x70B5, 0x70B3,
+ 0x70B1,
+};
+static const uint16_t bitalloc_65_codes_e[65] =
+{
+ 0x032C, 0x0332, 0x0378, 0x037E, 0x008C, 0x014A, 0x0188, 0x0197,
+ 0x019E, 0x01BD, 0x0044, 0x0047, 0x00AA, 0x00C5, 0x00CD, 0x00DC,
+ 0x001C, 0x002C, 0x0053, 0x0063, 0x0068, 0x0008, 0x000F, 0x0017,
+ 0x002B, 0x0035, 0x0005, 0x0009, 0x0016, 0x001C, 0x0006, 0x000F,
+ 0x0004, 0x0000, 0x0007, 0x001D, 0x0017, 0x000A, 0x0006, 0x0036,
+ 0x0030, 0x0028, 0x0010, 0x0009, 0x0069, 0x0064, 0x0054, 0x002D,
+ 0x001D, 0x00DD, 0x00CE, 0x00CA, 0x00AB, 0x00A4, 0x0045, 0x01BE,
+ 0x019F, 0x0198, 0x0189, 0x014B, 0x008D, 0x037F, 0x0379, 0x0333,
+ 0x032D,
+};
+static const uint16_t bitalloc_65_codes_f[65] =
+{
+ 0x0FE0, 0x0FE2, 0x0FE8, 0x0FEA, 0x0FEC, 0x0FEE, 0x0FF0, 0x0FF2,
+ 0x0FF4, 0x2FF2, 0x07F2, 0x07FB, 0x03F6, 0x0BFA, 0x0BFD, 0x01FF,
+ 0x05FF, 0x02FC, 0x007C, 0x017C, 0x003C, 0x00BC, 0x001C, 0x005C,
+ 0x000C, 0x002C, 0x0004, 0x0014, 0x0000, 0x0008, 0x000E, 0x0002,
+ 0x0006, 0x0003, 0x000F, 0x0009, 0x0001, 0x0015, 0x0005, 0x002D,
+ 0x000D, 0x005D, 0x001D, 0x00BD, 0x003D, 0x017D, 0x007D, 0x02FD,
+ 0x00FC, 0x05FC, 0x01FA, 0x0BFB, 0x03F7, 0x17F8, 0x07F3, 0x2FF3,
+ 0x0FF5, 0x0FF3, 0x0FF1, 0x0FEF, 0x0FED, 0x0FEB, 0x0FE9, 0x0FE3,
+ 0x0FE1,
+};
+static const uint16_t bitalloc_65_codes_g[65] =
+{
+ 0x010C, 0x038A, 0x0608, 0x0786, 0x0084, 0x0087, 0x0302, 0x0305,
+ 0x0040, 0x00E0, 0x00E3, 0x0183, 0x001E, 0x005E, 0x009E, 0x00DE,
+ 0x00F1, 0x0011, 0x0039, 0x0061, 0x0079, 0x0009, 0x001D, 0x0031,
+ 0x003D, 0x0005, 0x000F, 0x0019, 0x001F, 0x0003, 0x0006, 0x000A,
+ 0x000E, 0x000B, 0x0008, 0x0004, 0x0000, 0x001A, 0x0012, 0x000A,
+ 0x0002, 0x0036, 0x0026, 0x0016, 0x0006, 0x006E, 0x004E, 0x002E,
+ 0x000E, 0x00DF, 0x009F, 0x005F, 0x001F, 0x01E0, 0x0180, 0x00E1,
+ 0x0041, 0x03C2, 0x0303, 0x01C4, 0x0085, 0x0787, 0x0609, 0x038B,
+ 0x010D,
+};
+static const uint8_t bitalloc_65_bits_a[65] =
+{
+ 16, 16, 15, 14, 13, 13, 12, 12, 11, 11, 10, 10, 9, 9, 8, 8,
+ 7, 7, 7, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 4,
+ 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 7, 7,
+ 7, 8, 8, 9, 9, 10, 10, 11, 11, 11, 12, 13, 13, 14, 15, 16,
+ 16,
+};
+static const uint8_t bitalloc_65_bits_b[65] =
+{
+ 12, 11, 10, 9, 9, 9, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7,
+ 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4,
+ 4, 4, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
+ 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 10, 10,
+ 12,
+};
+static const uint8_t bitalloc_65_bits_c[65] =
+{
+ 11, 10, 10, 9, 9, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 6,
+ 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 10,
+ 11,
+};
+static const uint8_t bitalloc_65_bits_d[65] =
+{
+ 15, 15, 15, 14, 14, 13, 13, 12, 12, 11, 11, 10, 10, 10, 9, 9,
+ 9, 8, 8, 8, 7, 7, 7, 6, 6, 6, 5, 5, 5, 4, 4, 3,
+ 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8,
+ 8, 9, 9, 10, 10, 10, 11, 11, 12, 12, 13, 13, 13, 14, 15, 15,
+ 15,
+};
+static const uint8_t bitalloc_65_bits_e[65] =
+{
+ 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8,
+ 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 5, 5, 5, 5, 4, 4,
+ 3, 3, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7,
+ 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10,
+ 10,
+};
+static const uint8_t bitalloc_65_bits_f[65] =
+{
+ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13, 12, 12, 12, 11,
+ 11, 10, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 4, 3,
+ 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10,
+ 10, 11, 11, 12, 12, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14,
+ 14,
+};
+static const uint8_t bitalloc_65_bits_g[65] =
+{
+ 11, 11, 11, 11, 10, 10, 10, 10, 9, 9, 9, 9, 8, 8, 8, 8,
+ 8, 7, 7, 7, 7, 6, 6, 6, 6, 5, 5, 5, 5, 4, 4, 4,
+ 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7,
+ 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11,
+ 11,
+};
+
+static const uint16_t bitalloc_129_codes_a[129] =
+{
+ 0x0660, 0x0666, 0x06EC, 0x0722, 0x0760, 0x076E, 0x004C, 0x004E,
+ 0x00F4, 0x010A, 0x0148, 0x0156, 0x01D4, 0x01F2, 0x0331, 0x0370,
+ 0x0377, 0x0396, 0x03B1, 0x0024, 0x0064, 0x007B, 0x008A, 0x00A5,
+ 0x00D4, 0x00EB, 0x00FA, 0x019A, 0x01B9, 0x01C9, 0x01D9, 0x0010,
+ 0x0030, 0x0033, 0x0043, 0x0053, 0x006B, 0x007A, 0x00CA, 0x00D2,
+ 0x00DE, 0x00E6, 0x00F6, 0x000E, 0x001F, 0x0023, 0x002B, 0x003B,
+ 0x003F, 0x0067, 0x0070, 0x0077, 0x0005, 0x000D, 0x0012, 0x001B,
+ 0x002C, 0x0035, 0x003A, 0x0004, 0x000B, 0x0017, 0x001F, 0x0009,
+ 0x0008, 0x000A, 0x0000, 0x0018, 0x000C, 0x0005, 0x003C, 0x0036,
+ 0x002D, 0x001C, 0x0013, 0x000E, 0x0006, 0x007A, 0x0071, 0x0068,
+ 0x0064, 0x003C, 0x0034, 0x0028, 0x0020, 0x000F, 0x00F7, 0x00E7,
+ 0x00DF, 0x00D3, 0x00CB, 0x007B, 0x0074, 0x0054, 0x0044, 0x003C,
+ 0x0031, 0x0011, 0x01DA, 0x01CA, 0x01BA, 0x019B, 0x00FB, 0x00F8,
+ 0x00D5, 0x00AA, 0x008B, 0x0084, 0x0065, 0x0025, 0x03B6, 0x0397,
+ 0x0390, 0x0371, 0x0332, 0x01F3, 0x01D5, 0x0157, 0x0149, 0x010B,
+ 0x00F5, 0x004F, 0x004D, 0x076F, 0x0761, 0x0723, 0x06ED, 0x0667,
+ 0x0661,
+};
+static const uint16_t bitalloc_129_codes_b[129] =
+{
+ 0x29DC, 0x14EF, 0x0455, 0x0E9C, 0x022B, 0x0489, 0x0740, 0x074F,
+ 0x0172, 0x0245, 0x0247, 0x030A, 0x03A1, 0x001C, 0x008B, 0x00D6,
+ 0x010C, 0x0148, 0x014F, 0x0186, 0x01D1, 0x0008, 0x000F, 0x0046,
+ 0x005D, 0x0078, 0x0087, 0x0096, 0x00A5, 0x00BC, 0x00D8, 0x00DE,
+ 0x00F6, 0x0005, 0x0014, 0x0024, 0x002F, 0x003A, 0x003D, 0x0049,
+ 0x0050, 0x0058, 0x005F, 0x0066, 0x006D, 0x0075, 0x007C, 0x0004,
+ 0x000B, 0x0013, 0x0018, 0x001B, 0x001F, 0x0022, 0x0026, 0x002A,
+ 0x002D, 0x0031, 0x0034, 0x0038, 0x003B, 0x003F, 0x0003, 0x0006,
+ 0x000A, 0x0007, 0x0004, 0x0000, 0x003C, 0x0039, 0x0035, 0x0032,
+ 0x002E, 0x002B, 0x0027, 0x0023, 0x0020, 0x001C, 0x0019, 0x0016,
+ 0x0010, 0x0005, 0x007D, 0x007A, 0x006E, 0x0067, 0x0060, 0x0059,
+ 0x0051, 0x004A, 0x0042, 0x003B, 0x0034, 0x0025, 0x0015, 0x0006,
+ 0x00F7, 0x00DF, 0x00D9, 0x00BD, 0x00A6, 0x0097, 0x0090, 0x0079,
+ 0x006A, 0x0047, 0x0044, 0x0009, 0x01D2, 0x0187, 0x0184, 0x0149,
+ 0x010D, 0x00D7, 0x00B8, 0x001D, 0x03A6, 0x030B, 0x029C, 0x0246,
+ 0x0173, 0x0114, 0x0741, 0x053A, 0x0488, 0x0E9D, 0x0A76, 0x0454,
+ 0x29DD,
+};
+static const uint16_t bitalloc_129_codes_c[129] =
+{
+ 0x0E5C, 0x072F, 0x001D, 0x0724, 0x000F, 0x010D, 0x0324, 0x0393,
+ 0x03E9, 0x0080, 0x0087, 0x00FA, 0x0164, 0x0193, 0x01DE, 0x01F5,
+ 0x0010, 0x002A, 0x0041, 0x0064, 0x0073, 0x008E, 0x00A4, 0x00B3,
+ 0x00D6, 0x00E5, 0x00F4, 0x00FB, 0x0002, 0x0009, 0x0013, 0x001E,
+ 0x0026, 0x002C, 0x0033, 0x003F, 0x0041, 0x004C, 0x0053, 0x005E,
+ 0x0065, 0x0070, 0x0073, 0x0078, 0x007B, 0x007E, 0x0002, 0x0005,
+ 0x0007, 0x000B, 0x000D, 0x0011, 0x0014, 0x0017, 0x001A, 0x001D,
+ 0x0021, 0x0024, 0x0027, 0x002A, 0x002D, 0x0030, 0x0033, 0x0036,
+ 0x003A, 0x0037, 0x0034, 0x0031, 0x002E, 0x002B, 0x0028, 0x0025,
+ 0x0022, 0x001E, 0x001B, 0x0018, 0x0015, 0x0012, 0x000E, 0x000C,
+ 0x0008, 0x0006, 0x0003, 0x007F, 0x007C, 0x0079, 0x0076, 0x0071,
+ 0x006A, 0x005F, 0x0058, 0x004D, 0x0046, 0x0040, 0x0038, 0x002D,
+ 0x0027, 0x001F, 0x0014, 0x0012, 0x0003, 0x0000, 0x00F5, 0x00EE,
+ 0x00D7, 0x00C8, 0x00A5, 0x008F, 0x007C, 0x0065, 0x0042, 0x002B,
+ 0x0011, 0x0002, 0x01DF, 0x01C8, 0x0165, 0x00FB, 0x00E4, 0x0081,
+ 0x0006, 0x03E8, 0x0325, 0x01CA, 0x010C, 0x0725, 0x0396, 0x001C,
+ 0x0E5D,
+};
+static const uint16_t bitalloc_129_codes_d[129] =
+{
+ 0xA598, 0xA59A, 0xA59C, 0xA59E, 0xC598, 0xE586, 0x3ACC, 0x52CA,
+ 0x62CD, 0x0D48, 0x1D67, 0x2978, 0x3167, 0x3966, 0x06A5, 0x0EBC,
+ 0x14BD, 0x1CB1, 0x0350, 0x0353, 0x075F, 0x0A5F, 0x0C5E, 0x0E5E,
+ 0x01AE, 0x03AD, 0x052D, 0x062D, 0x072D, 0x00D5, 0x01D4, 0x0294,
+ 0x0314, 0x0394, 0x0014, 0x0094, 0x0114, 0x0174, 0x01B4, 0x01F4,
+ 0x000B, 0x004B, 0x008B, 0x00BB, 0x00DB, 0x00FB, 0x001B, 0x003B,
+ 0x0053, 0x0063, 0x0073, 0x0003, 0x0013, 0x0023, 0x002F, 0x0037,
+ 0x003F, 0x0007, 0x000F, 0x0015, 0x0019, 0x001D, 0x0001, 0x0005,
+ 0x0009, 0x0006, 0x0002, 0x001E, 0x001A, 0x0016, 0x0010, 0x0008,
+ 0x0000, 0x0038, 0x0030, 0x0028, 0x001C, 0x000C, 0x007C, 0x006C,
+ 0x005C, 0x0044, 0x0024, 0x0004, 0x00E4, 0x00C4, 0x00A4, 0x0074,
+ 0x0034, 0x01F5, 0x01B5, 0x0175, 0x0115, 0x0095, 0x0015, 0x0395,
+ 0x0315, 0x0295, 0x01D5, 0x00D6, 0x072E, 0x062E, 0x052E, 0x03AE,
+ 0x01AF, 0x0E5F, 0x0C5F, 0x0C58, 0x0A58, 0x0758, 0x0351, 0x1CB2,
+ 0x18B2, 0x0EBD, 0x0EB2, 0x3967, 0x3960, 0x2979, 0x2964, 0x0D49,
+ 0x72C2, 0x52CB, 0x3ACD, 0xE587, 0xC599, 0xA59F, 0xA59D, 0xA59B,
+ 0xA599,
+};
+static const uint16_t bitalloc_129_codes_e[129] =
+{
+ 0xA13C, 0xC720, 0xA13F, 0xA13E, 0xA13D, 0xE722, 0x5090, 0x6393,
+ 0x7392, 0x2849, 0x31CE, 0x39CE, 0x1425, 0x18E5, 0x1CE5, 0x0844,
+ 0x0A1C, 0x0C7C, 0x036C, 0x0423, 0x050F, 0x063F, 0x01B7, 0x0216,
+ 0x0285, 0x031D, 0x039D, 0x0109, 0x0140, 0x0180, 0x01C8, 0x01CF,
+ 0x007A, 0x008A, 0x00A2, 0x00C1, 0x00E5, 0x0014, 0x0037, 0x0043,
+ 0x004E, 0x0056, 0x0061, 0x006C, 0x007C, 0x000B, 0x001C, 0x001F,
+ 0x0023, 0x0025, 0x0029, 0x002C, 0x002E, 0x0032, 0x0034, 0x0037,
+ 0x003A, 0x003C, 0x003F, 0x0001, 0x0003, 0x0006, 0x0008, 0x000A,
+ 0x000C, 0x000B, 0x0009, 0x0007, 0x0004, 0x0002, 0x0000, 0x003D,
+ 0x003B, 0x0038, 0x0035, 0x0033, 0x002F, 0x002D, 0x002A, 0x0026,
+ 0x0024, 0x0020, 0x001D, 0x001A, 0x007D, 0x006D, 0x0062, 0x0057,
+ 0x004F, 0x0044, 0x003C, 0x0015, 0x00E6, 0x00C6, 0x00A3, 0x008B,
+ 0x007B, 0x006C, 0x01C9, 0x0181, 0x0141, 0x010A, 0x00DA, 0x031E,
+ 0x0286, 0x0217, 0x0210, 0x0738, 0x0638, 0x0508, 0x036D, 0x0C7D,
+ 0x0A1D, 0x0845, 0x1CE6, 0x18E6, 0x1426, 0x39CF, 0x31CF, 0x284E,
+ 0x7393, 0x7390, 0x5091, 0xE723, 0xC724, 0xC725, 0xC722, 0xC723,
+ 0xC721,
+};
+static const uint16_t bitalloc_129_codes_f[129] =
+{
+ 0x762C, 0x3B17, 0x1555, 0x0608, 0x0AAB, 0x0FF2, 0x0305, 0x0307,
+ 0x0763, 0x0046, 0x010C, 0x01BC, 0x02AB, 0x03B6, 0x03FD, 0x0080,
+ 0x0087, 0x00DF, 0x0156, 0x01D9, 0x01F8, 0x01FF, 0x002A, 0x0041,
+ 0x0061, 0x0094, 0x00D4, 0x00EA, 0x00F2, 0x00FD, 0x0009, 0x000B,
+ 0x001A, 0x0026, 0x0031, 0x0040, 0x004B, 0x006B, 0x0073, 0x0077,
+ 0x007A, 0x007C, 0x0000, 0x0002, 0x0006, 0x0008, 0x000B, 0x000E,
+ 0x0011, 0x0014, 0x0016, 0x0019, 0x001C, 0x001E, 0x0021, 0x0023,
+ 0x0026, 0x0028, 0x002B, 0x002D, 0x002F, 0x0031, 0x0033, 0x0036,
+ 0x0038, 0x0037, 0x0034, 0x0032, 0x0030, 0x002E, 0x002C, 0x0029,
+ 0x0027, 0x0024, 0x0022, 0x001F, 0x001D, 0x001A, 0x0017, 0x0015,
+ 0x0012, 0x000F, 0x000C, 0x0009, 0x0007, 0x0003, 0x0001, 0x007D,
+ 0x007B, 0x0078, 0x0074, 0x0072, 0x0054, 0x0041, 0x0036, 0x0027,
+ 0x001B, 0x0014, 0x000A, 0x00FE, 0x00F3, 0x00EB, 0x00D5, 0x0095,
+ 0x006E, 0x0042, 0x002B, 0x0010, 0x01F9, 0x01DA, 0x0157, 0x0154,
+ 0x00C0, 0x0081, 0x0022, 0x03B7, 0x03B0, 0x01BD, 0x010D, 0x0047,
+ 0x07F8, 0x0554, 0x0306, 0x0FF3, 0x0EC4, 0x0609, 0x1D8A, 0x1554,
+ 0x762D,
+};
+static const uint16_t bitalloc_129_codes_g[129] =
+{
+ 0x1E20, 0x1E5E, 0x031C, 0x051A, 0x0718, 0x0916, 0x0B14, 0x0D12,
+ 0x0F11, 0x0090, 0x018F, 0x028E, 0x038D, 0x048C, 0x058B, 0x068A,
+ 0x0789, 0x0049, 0x00C8, 0x0148, 0x01C7, 0x0247, 0x02C6, 0x0346,
+ 0x03C5, 0x0025, 0x0065, 0x00A5, 0x00E4, 0x0124, 0x0164, 0x01A4,
+ 0x01E3, 0x0013, 0x0033, 0x0053, 0x0073, 0x0093, 0x00B3, 0x00D3,
+ 0x00F3, 0x000A, 0x001A, 0x002A, 0x003A, 0x004A, 0x005A, 0x006A,
+ 0x007A, 0x0006, 0x000E, 0x0016, 0x001E, 0x0026, 0x002E, 0x0036,
+ 0x003E, 0x0004, 0x0008, 0x000C, 0x0010, 0x0014, 0x0018, 0x001C,
+ 0x0000, 0x001D, 0x0019, 0x0015, 0x0011, 0x000D, 0x0009, 0x0005,
+ 0x003F, 0x0037, 0x002F, 0x0027, 0x001F, 0x0017, 0x000F, 0x0007,
+ 0x007B, 0x006B, 0x005B, 0x004B, 0x003B, 0x002B, 0x001B, 0x000B,
+ 0x0008, 0x00F0, 0x00D0, 0x00B0, 0x0090, 0x0070, 0x0050, 0x0030,
+ 0x01E4, 0x01A5, 0x0165, 0x0125, 0x00E5, 0x00E2, 0x00A2, 0x0062,
+ 0x03CA, 0x0347, 0x02C7, 0x02C4, 0x0244, 0x0149, 0x00C9, 0x00C6,
+ 0x0796, 0x068B, 0x0688, 0x048D, 0x048A, 0x028F, 0x028C, 0x0091,
+ 0x0F2E, 0x0D13, 0x0B15, 0x0917, 0x0719, 0x051B, 0x031D, 0x1E5F,
+ 0x1E21,
+};
+static const uint8_t bitalloc_129_bits_a[129] =
+{
+ 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8,
+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 4,
+ 4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+ 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11,
+ 11,
+};
+static const uint8_t bitalloc_129_bits_b[129] =
+{
+ 14, 13, 12, 12, 11, 11, 11, 11, 10, 10, 10, 10, 10, 9, 9, 9,
+ 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+ 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5,
+ 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
+ 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 11, 11, 11, 12, 12, 12,
+ 14,
+};
+static const uint8_t bitalloc_129_bits_c[129] =
+{
+ 13, 12, 11, 11, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9,
+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+ 8, 8, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11,
+ 13,
+};
+static const uint8_t bitalloc_129_bits_d[129] =
+{
+ 16, 16, 16, 16, 16, 16, 15, 15, 15, 14, 14, 14, 14, 14, 13, 13,
+ 13, 13, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 10, 10, 10,
+ 10, 10, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 7, 7,
+ 7, 7, 7, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 4, 4,
+ 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7,
+ 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10,
+ 10, 10, 10, 10, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 13,
+ 13, 13, 13, 14, 14, 14, 14, 14, 15, 15, 15, 16, 16, 16, 16, 16,
+ 16,
+};
+static const uint8_t bitalloc_129_bits_e[129] =
+{
+ 16, 16, 16, 16, 16, 16, 15, 15, 15, 14, 14, 14, 13, 13, 13, 12,
+ 12, 12, 11, 11, 11, 11, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9,
+ 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
+ 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12,
+ 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 16, 16, 16, 16, 16,
+ 16,
+};
+static const uint8_t bitalloc_129_bits_f[129] =
+{
+ 15, 14, 13, 12, 12, 12, 11, 11, 11, 10, 10, 10, 10, 10, 10, 9,
+ 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
+ 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13,
+ 15,
+};
+static const uint8_t bitalloc_129_bits_g[129] =
+{
+ 13, 13, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11,
+ 11, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9,
+ 9, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7,
+ 7, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5,
+ 4, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
+ 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
+ 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 13,
+ 13,
+};
+
+static const uint8_t bitalloc_sizes[10] = { 3, 5, 7, 9, 13, 17, 25, 33, 65, 129 };
+
+static const uint8_t bitalloc_offsets[10] =
+ { -1, -2, -3, -4, -6, -8, -12, -16, -32, -64 };
+
+static const uint8_t bitalloc_maxbits[10][7] = {
+ { 2 },
+ { 4, 3, 3 },
+ { 5, 5, 4 },
+ { 6, 5, 6 },
+ { 7, 6, 5 },
+ { 9, 8, 7, 9, 8, 8, 8 },
+ { 9, 9, 8, 9, 8, 9, 9 },
+ { 9, 9, 9, 9, 9, 9, 9 },
+ { 9, 9, 9, 9, 9, 9, 9 },
+ { 9, 9, 9, 9, 9, 9, 9 }
+};
+
+static const uint16_t* bitalloc_codes[10][8] = {
+ { bitalloc_3_codes, NULL },
+ { bitalloc_5_codes_a, bitalloc_5_codes_b, bitalloc_5_codes_c, NULL },
+ { bitalloc_7_codes_a, bitalloc_7_codes_b, bitalloc_7_codes_c, NULL },
+ { bitalloc_9_codes_a, bitalloc_9_codes_b, bitalloc_9_codes_c, NULL },
+ { bitalloc_13_codes_a, bitalloc_13_codes_b, bitalloc_13_codes_c, NULL },
+ { bitalloc_17_codes_a, bitalloc_17_codes_b, bitalloc_17_codes_c, bitalloc_17_codes_d,
+ bitalloc_17_codes_e, bitalloc_17_codes_f, bitalloc_17_codes_g, NULL },
+ { bitalloc_25_codes_a, bitalloc_25_codes_b, bitalloc_25_codes_c, bitalloc_25_codes_d,
+ bitalloc_25_codes_e, bitalloc_25_codes_f, bitalloc_25_codes_g, NULL },
+ { bitalloc_33_codes_a, bitalloc_33_codes_b, bitalloc_33_codes_c, bitalloc_33_codes_d,
+ bitalloc_33_codes_e, bitalloc_33_codes_f, bitalloc_33_codes_g, NULL },
+ { bitalloc_65_codes_a, bitalloc_65_codes_b, bitalloc_65_codes_c, bitalloc_65_codes_d,
+ bitalloc_65_codes_e, bitalloc_65_codes_f, bitalloc_65_codes_g, NULL },
+ { bitalloc_129_codes_a, bitalloc_129_codes_b, bitalloc_129_codes_c, bitalloc_129_codes_d,
+ bitalloc_129_codes_e, bitalloc_129_codes_f, bitalloc_129_codes_g, NULL }
+};
+
+static const uint8_t* bitalloc_bits[10][8] = {
+ { bitalloc_3_bits, NULL },
+ { bitalloc_5_bits_a, bitalloc_5_bits_b, bitalloc_5_bits_c, NULL },
+ { bitalloc_7_bits_a, bitalloc_7_bits_b, bitalloc_7_bits_c, NULL },
+ { bitalloc_9_bits_a, bitalloc_9_bits_b, bitalloc_9_bits_c, NULL },
+ { bitalloc_13_bits_a, bitalloc_13_bits_b, bitalloc_13_bits_c, NULL },
+ { bitalloc_17_bits_a, bitalloc_17_bits_b, bitalloc_17_bits_c, bitalloc_17_bits_d,
+ bitalloc_17_bits_e, bitalloc_17_bits_f, bitalloc_17_bits_g, NULL },
+ { bitalloc_25_bits_a, bitalloc_25_bits_b, bitalloc_25_bits_c, bitalloc_25_bits_d,
+ bitalloc_25_bits_e, bitalloc_25_bits_f, bitalloc_25_bits_g, NULL },
+ { bitalloc_33_bits_a, bitalloc_33_bits_b, bitalloc_33_bits_c, bitalloc_33_bits_d,
+ bitalloc_33_bits_e, bitalloc_33_bits_f, bitalloc_33_bits_g, NULL },
+ { bitalloc_65_bits_a, bitalloc_65_bits_b, bitalloc_65_bits_c, bitalloc_65_bits_d,
+ bitalloc_65_bits_e, bitalloc_65_bits_f, bitalloc_65_bits_g, NULL },
+ { bitalloc_129_bits_a, bitalloc_129_bits_b, bitalloc_129_bits_c, bitalloc_129_bits_d,
+ bitalloc_129_bits_e, bitalloc_129_bits_f, bitalloc_129_bits_g, NULL }
+};
diff --git a/contrib/ffmpeg/libavcodec/dct-test.c b/contrib/ffmpeg/libavcodec/dct-test.c
new file mode 100644
index 000000000..7cd866832
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/dct-test.c
@@ -0,0 +1,565 @@
+/*
+ * (c) 2001 Fabrice Bellard
+ * 2007 Marc Hoffman <marc.hoffman@analog.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file dct-test.c
+ * DCT test. (c) 2001 Fabrice Bellard.
+ * Started from sample code by Juan J. Sierralta P.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/time.h>
+#include <unistd.h>
+
+#include "dsputil.h"
+
+#include "simple_idct.h"
+#include "faandct.h"
+
+#ifndef MAX
+#define MAX(a, b) (((a) > (b)) ? (a) : (b))
+#endif
+
+#undef printf
+
+void *fast_memcpy(void *a, const void *b, size_t c){return memcpy(a,b,c);};
+
+/* reference fdct/idct */
+extern void fdct(DCTELEM *block);
+extern void idct(DCTELEM *block);
+extern void ff_idct_xvid_mmx(DCTELEM *block);
+extern void ff_idct_xvid_mmx2(DCTELEM *block);
+extern void init_fdct();
+
+extern void j_rev_dct(DCTELEM *data);
+extern void ff_mmx_idct(DCTELEM *data);
+extern void ff_mmxext_idct(DCTELEM *data);
+
+extern void odivx_idct_c (short *block);
+
+// BFIN
+extern void ff_bfin_idct (DCTELEM *block) ;
+extern void ff_bfin_fdct (DCTELEM *block) ;
+
+// ALTIVEC
+extern void fdct_altivec (DCTELEM *block);
+//extern void idct_altivec (DCTELEM *block);?? no routine
+
+
+struct algo {
+ char *name;
+ enum { FDCT, IDCT } is_idct;
+ void (* func) (DCTELEM *block);
+ void (* ref) (DCTELEM *block);
+ enum formattag { NO_PERM,MMX_PERM, MMX_SIMPLE_PERM, SCALE_PERM } format;
+};
+
+#ifndef FAAN_POSTSCALE
+#define FAAN_SCALE SCALE_PERM
+#else
+#define FAAN_SCALE NO_PERM
+#endif
+
+#define DCT_ERROR(name,is_idct,func,ref,form) {name,is_idct,func,ref,form}
+
+
+struct algo algos[] = {
+ DCT_ERROR( "REF-DBL", 0, fdct, fdct, NO_PERM),
+ DCT_ERROR("IJG-AAN-INT", 0, fdct_ifast, fdct, SCALE_PERM),
+ DCT_ERROR("IJG-LLM-INT", 0, ff_jpeg_fdct_islow, fdct, NO_PERM),
+ DCT_ERROR("REF-DBL", 1, idct, idct, NO_PERM),
+ DCT_ERROR("INT", 1, j_rev_dct, idct, MMX_PERM),
+ DCT_ERROR("SIMPLE-C", 1, simple_idct, idct, NO_PERM),
+
+#ifdef ARCH_X86
+ DCT_ERROR("MMX", 0, ff_fdct_mmx, fdct, NO_PERM),
+ DCT_ERROR("MMX2", 0, ff_fdct_mmx2, fdct, NO_PERM),
+ DCT_ERROR("FAAN", 0, ff_faandct, fdct, FAAN_SCALE),
+
+ DCT_ERROR("LIBMPEG2-MMX", 1, ff_mmx_idct, idct, MMX_PERM),
+ DCT_ERROR("LIBMPEG2-MMXEXT", 1, ff_mmxext_idct, idct, MMX_PERM),
+ DCT_ERROR("SIMPLE-MMX", 1, ff_simple_idct_mmx, idct, MMX_SIMPLE_PERM),
+ DCT_ERROR("XVID-MMX", 1, ff_idct_xvid_mmx, idct, NO_PERM),
+ DCT_ERROR("XVID-MMX2", 1, ff_idct_xvid_mmx2, idct, NO_PERM),
+#endif
+
+#ifdef HAVE_ALTIVEC
+ DCT_ERROR("altivecfdct", 0, fdct_altivec, fdct, NO_PERM),
+#endif
+
+#ifdef ARCH_BFIN
+ DCT_ERROR("BFINfdct", 0, ff_bfin_fdct, fdct, NO_PERM),
+ DCT_ERROR("BFINidct", 1, ff_bfin_idct, idct, NO_PERM),
+#endif
+
+ { 0 }
+};
+
+#define AANSCALE_BITS 12
+static const unsigned short aanscales[64] = {
+ /* precomputed values scaled up by 14 bits */
+ 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
+ 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
+ 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
+ 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
+ 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
+ 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
+ 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
+ 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
+};
+
+uint8_t cropTbl[256 + 2 * MAX_NEG_CROP];
+
+int64_t gettime(void)
+{
+ struct timeval tv;
+ gettimeofday(&tv,NULL);
+ return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
+}
+
+#define NB_ITS 20000
+#define NB_ITS_SPEED 50000
+
+static short idct_mmx_perm[64];
+
+static short idct_simple_mmx_perm[64]={
+ 0x00, 0x08, 0x04, 0x09, 0x01, 0x0C, 0x05, 0x0D,
+ 0x10, 0x18, 0x14, 0x19, 0x11, 0x1C, 0x15, 0x1D,
+ 0x20, 0x28, 0x24, 0x29, 0x21, 0x2C, 0x25, 0x2D,
+ 0x12, 0x1A, 0x16, 0x1B, 0x13, 0x1E, 0x17, 0x1F,
+ 0x02, 0x0A, 0x06, 0x0B, 0x03, 0x0E, 0x07, 0x0F,
+ 0x30, 0x38, 0x34, 0x39, 0x31, 0x3C, 0x35, 0x3D,
+ 0x22, 0x2A, 0x26, 0x2B, 0x23, 0x2E, 0x27, 0x2F,
+ 0x32, 0x3A, 0x36, 0x3B, 0x33, 0x3E, 0x37, 0x3F,
+};
+
+void idct_mmx_init(void)
+{
+ int i;
+
+ /* the mmx/mmxext idct uses a reordered input, so we patch scan tables */
+ for (i = 0; i < 64; i++) {
+ idct_mmx_perm[i] = (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2);
+// idct_simple_mmx_perm[i] = simple_block_permute_op(i);
+ }
+}
+
+static DCTELEM block[64] __attribute__ ((aligned (8)));
+static DCTELEM block1[64] __attribute__ ((aligned (8)));
+static DCTELEM block_org[64] __attribute__ ((aligned (8)));
+
+void dct_error(const char *name, int is_idct,
+ void (*fdct_func)(DCTELEM *block),
+ void (*fdct_ref)(DCTELEM *block), int form, int test)
+{
+ int it, i, scale;
+ int err_inf, v;
+ int64_t err2, ti, ti1, it1;
+ int64_t sysErr[64], sysErrMax=0;
+ int maxout=0;
+ int blockSumErrMax=0, blockSumErr;
+
+ srandom(0);
+
+ err_inf = 0;
+ err2 = 0;
+ for(i=0; i<64; i++) sysErr[i]=0;
+ for(it=0;it<NB_ITS;it++) {
+ for(i=0;i<64;i++)
+ block1[i] = 0;
+ switch(test){
+ case 0:
+ for(i=0;i<64;i++)
+ block1[i] = (random() % 512) -256;
+ if (is_idct){
+ fdct(block1);
+
+ for(i=0;i<64;i++)
+ block1[i]>>=3;
+ }
+ break;
+ case 1:{
+ int num= (random()%10)+1;
+ for(i=0;i<num;i++)
+ block1[random()%64] = (random() % 512) -256;
+ }break;
+ case 2:
+ block1[0]= (random()%4096)-2048;
+ block1[63]= (block1[0]&1)^1;
+ break;
+ }
+
+#if 0 // simulate mismatch control
+{ int sum=0;
+ for(i=0;i<64;i++)
+ sum+=block1[i];
+
+ if((sum&1)==0) block1[63]^=1;
+}
+#endif
+
+ for(i=0; i<64; i++)
+ block_org[i]= block1[i];
+
+ if (form == MMX_PERM) {
+ for(i=0;i<64;i++)
+ block[idct_mmx_perm[i]] = block1[i];
+ } else if (form == MMX_SIMPLE_PERM) {
+ for(i=0;i<64;i++)
+ block[idct_simple_mmx_perm[i]] = block1[i];
+
+ } else {
+ for(i=0; i<64; i++)
+ block[i]= block1[i];
+ }
+#if 0 // simulate mismatch control for tested IDCT but not the ref
+{ int sum=0;
+ for(i=0;i<64;i++)
+ sum+=block[i];
+
+ if((sum&1)==0) block[63]^=1;
+}
+#endif
+
+ fdct_func(block);
+ emms_c(); /* for ff_mmx_idct */
+
+ if (form == SCALE_PERM) {
+ for(i=0; i<64; i++) {
+ scale = 8*(1 << (AANSCALE_BITS + 11)) / aanscales[i];
+ block[i] = (block[i] * scale /*+ (1<<(AANSCALE_BITS-1))*/) >> AANSCALE_BITS;
+ }
+ }
+
+ fdct_ref(block1);
+
+ blockSumErr=0;
+ for(i=0;i<64;i++) {
+ v = abs(block[i] - block1[i]);
+ if (v > err_inf)
+ err_inf = v;
+ err2 += v * v;
+ sysErr[i] += block[i] - block1[i];
+ blockSumErr += v;
+ if( abs(block[i])>maxout) maxout=abs(block[i]);
+ }
+ if(blockSumErrMax < blockSumErr) blockSumErrMax= blockSumErr;
+#if 0 // print different matrix pairs
+ if(blockSumErr){
+ printf("\n");
+ for(i=0; i<64; i++){
+ if((i&7)==0) printf("\n");
+ printf("%4d ", block_org[i]);
+ }
+ for(i=0; i<64; i++){
+ if((i&7)==0) printf("\n");
+ printf("%4d ", block[i] - block1[i]);
+ }
+ }
+#endif
+ }
+ for(i=0; i<64; i++) sysErrMax= MAX(sysErrMax, FFABS(sysErr[i]));
+
+#if 1 // dump systematic errors
+ for(i=0; i<64; i++){
+ if(i%8==0) printf("\n");
+ printf("%5d ", (int)sysErr[i]);
+ }
+ printf("\n");
+#endif
+
+ printf("%s %s: err_inf=%d err2=%0.8f syserr=%0.8f maxout=%d blockSumErr=%d\n",
+ is_idct ? "IDCT" : "DCT",
+ name, err_inf, (double)err2 / NB_ITS / 64.0, (double)sysErrMax / NB_ITS, maxout, blockSumErrMax);
+#if 1 //Speed test
+ /* speed test */
+ for(i=0;i<64;i++)
+ block1[i] = 0;
+ switch(test){
+ case 0:
+ for(i=0;i<64;i++)
+ block1[i] = (random() % 512) -256;
+ if (is_idct){
+ fdct(block1);
+
+ for(i=0;i<64;i++)
+ block1[i]>>=3;
+ }
+ break;
+ case 1:{
+ case 2:
+ block1[0] = (random() % 512) -256;
+ block1[1] = (random() % 512) -256;
+ block1[2] = (random() % 512) -256;
+ block1[3] = (random() % 512) -256;
+ }break;
+ }
+
+ if (form == MMX_PERM) {
+ for(i=0;i<64;i++)
+ block[idct_mmx_perm[i]] = block1[i];
+ } else if(form == MMX_SIMPLE_PERM) {
+ for(i=0;i<64;i++)
+ block[idct_simple_mmx_perm[i]] = block1[i];
+ } else {
+ for(i=0; i<64; i++)
+ block[i]= block1[i];
+ }
+
+ ti = gettime();
+ it1 = 0;
+ do {
+ for(it=0;it<NB_ITS_SPEED;it++) {
+ for(i=0; i<64; i++)
+ block[i]= block1[i];
+// memcpy(block, block1, sizeof(DCTELEM) * 64);
+// dont memcpy especially not fastmemcpy because it does movntq !!!
+ fdct_func(block);
+ }
+ it1 += NB_ITS_SPEED;
+ ti1 = gettime() - ti;
+ } while (ti1 < 1000000);
+ emms_c();
+
+ printf("%s %s: %0.1f kdct/s\n",
+ is_idct ? "IDCT" : "DCT",
+ name, (double)it1 * 1000.0 / (double)ti1);
+#endif
+}
+
+static uint8_t img_dest[64] __attribute__ ((aligned (8)));
+static uint8_t img_dest1[64] __attribute__ ((aligned (8)));
+
+void idct248_ref(uint8_t *dest, int linesize, int16_t *block)
+{
+ static int init;
+ static double c8[8][8];
+ static double c4[4][4];
+ double block1[64], block2[64], block3[64];
+ double s, sum, v;
+ int i, j, k;
+
+ if (!init) {
+ init = 1;
+
+ for(i=0;i<8;i++) {
+ sum = 0;
+ for(j=0;j<8;j++) {
+ s = (i==0) ? sqrt(1.0/8.0) : sqrt(1.0/4.0);
+ c8[i][j] = s * cos(M_PI * i * (j + 0.5) / 8.0);
+ sum += c8[i][j] * c8[i][j];
+ }
+ }
+
+ for(i=0;i<4;i++) {
+ sum = 0;
+ for(j=0;j<4;j++) {
+ s = (i==0) ? sqrt(1.0/4.0) : sqrt(1.0/2.0);
+ c4[i][j] = s * cos(M_PI * i * (j + 0.5) / 4.0);
+ sum += c4[i][j] * c4[i][j];
+ }
+ }
+ }
+
+ /* butterfly */
+ s = 0.5 * sqrt(2.0);
+ for(i=0;i<4;i++) {
+ for(j=0;j<8;j++) {
+ block1[8*(2*i)+j] = (block[8*(2*i)+j] + block[8*(2*i+1)+j]) * s;
+ block1[8*(2*i+1)+j] = (block[8*(2*i)+j] - block[8*(2*i+1)+j]) * s;
+ }
+ }
+
+ /* idct8 on lines */
+ for(i=0;i<8;i++) {
+ for(j=0;j<8;j++) {
+ sum = 0;
+ for(k=0;k<8;k++)
+ sum += c8[k][j] * block1[8*i+k];
+ block2[8*i+j] = sum;
+ }
+ }
+
+ /* idct4 */
+ for(i=0;i<8;i++) {
+ for(j=0;j<4;j++) {
+ /* top */
+ sum = 0;
+ for(k=0;k<4;k++)
+ sum += c4[k][j] * block2[8*(2*k)+i];
+ block3[8*(2*j)+i] = sum;
+
+ /* bottom */
+ sum = 0;
+ for(k=0;k<4;k++)
+ sum += c4[k][j] * block2[8*(2*k+1)+i];
+ block3[8*(2*j+1)+i] = sum;
+ }
+ }
+
+ /* clamp and store the result */
+ for(i=0;i<8;i++) {
+ for(j=0;j<8;j++) {
+ v = block3[8*i+j];
+ if (v < 0)
+ v = 0;
+ else if (v > 255)
+ v = 255;
+ dest[i * linesize + j] = (int)rint(v);
+ }
+ }
+}
+
+void idct248_error(const char *name,
+ void (*idct248_put)(uint8_t *dest, int line_size, int16_t *block))
+{
+ int it, i, it1, ti, ti1, err_max, v;
+
+ srandom(0);
+
+ /* just one test to see if code is correct (precision is less
+ important here) */
+ err_max = 0;
+ for(it=0;it<NB_ITS;it++) {
+
+ /* XXX: use forward transform to generate values */
+ for(i=0;i<64;i++)
+ block1[i] = (random() % 256) - 128;
+ block1[0] += 1024;
+
+ for(i=0; i<64; i++)
+ block[i]= block1[i];
+ idct248_ref(img_dest1, 8, block);
+
+ for(i=0; i<64; i++)
+ block[i]= block1[i];
+ idct248_put(img_dest, 8, block);
+
+ for(i=0;i<64;i++) {
+ v = abs((int)img_dest[i] - (int)img_dest1[i]);
+ if (v == 255)
+ printf("%d %d\n", img_dest[i], img_dest1[i]);
+ if (v > err_max)
+ err_max = v;
+ }
+#if 0
+ printf("ref=\n");
+ for(i=0;i<8;i++) {
+ int j;
+ for(j=0;j<8;j++) {
+ printf(" %3d", img_dest1[i*8+j]);
+ }
+ printf("\n");
+ }
+
+ printf("out=\n");
+ for(i=0;i<8;i++) {
+ int j;
+ for(j=0;j<8;j++) {
+ printf(" %3d", img_dest[i*8+j]);
+ }
+ printf("\n");
+ }
+#endif
+ }
+ printf("%s %s: err_inf=%d\n",
+ 1 ? "IDCT248" : "DCT248",
+ name, err_max);
+
+ ti = gettime();
+ it1 = 0;
+ do {
+ for(it=0;it<NB_ITS_SPEED;it++) {
+ for(i=0; i<64; i++)
+ block[i]= block1[i];
+// memcpy(block, block1, sizeof(DCTELEM) * 64);
+// dont memcpy especially not fastmemcpy because it does movntq !!!
+ idct248_put(img_dest, 8, block);
+ }
+ it1 += NB_ITS_SPEED;
+ ti1 = gettime() - ti;
+ } while (ti1 < 1000000);
+ emms_c();
+
+ printf("%s %s: %0.1f kdct/s\n",
+ 1 ? "IDCT248" : "DCT248",
+ name, (double)it1 * 1000.0 / (double)ti1);
+}
+
+void help(void)
+{
+ printf("dct-test [-i] [<test-number>]\n"
+ "test-number 0 -> test with random matrixes\n"
+ " 1 -> test with random sparse matrixes\n"
+ " 2 -> do 3. test from mpeg4 std\n"
+ "-i test IDCT implementations\n"
+ "-4 test IDCT248 implementations\n");
+}
+
+int main(int argc, char **argv)
+{
+ int test_idct = 0, test_248_dct = 0;
+ int c,i;
+ int test=1;
+
+ init_fdct();
+ idct_mmx_init();
+
+ for(i=0;i<256;i++) cropTbl[i + MAX_NEG_CROP] = i;
+ for(i=0;i<MAX_NEG_CROP;i++) {
+ cropTbl[i] = 0;
+ cropTbl[i + MAX_NEG_CROP + 256] = 255;
+ }
+
+ for(;;) {
+ c = getopt(argc, argv, "ih4");
+ if (c == -1)
+ break;
+ switch(c) {
+ case 'i':
+ test_idct = 1;
+ break;
+ case '4':
+ test_248_dct = 1;
+ break;
+ default :
+ case 'h':
+ help();
+ return 0;
+ }
+ }
+
+ if(optind <argc) test= atoi(argv[optind]);
+
+ printf("ffmpeg DCT/IDCT test\n");
+
+ if (test_248_dct) {
+ idct248_error("SIMPLE-C", simple_idct248_put);
+ } else {
+ for (i=0;algos[i].name;i++)
+ if (algos[i].is_idct == test_idct) {
+ dct_error (algos[i].name, algos[i].is_idct, algos[i].func, algos[i].ref, algos[i].format, test);
+ }
+ }
+ return 0;
+}
diff --git a/contrib/ffmpeg/libavcodec/dnxhddata.h b/contrib/ffmpeg/libavcodec/dnxhddata.h
new file mode 100644
index 000000000..5d5aa528b
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/dnxhddata.h
@@ -0,0 +1,106 @@
+/*
+ * VC3/DNxHD decoder.
+ * Copyright (c) 2007 SmartJog S.A., Baptiste Coudurier <baptiste dot coudurier at smartjog dot com>.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+static const uint8_t dnxhd_1238_luma_weigth[] = {
+ 0, 32, 32, 33, 34, 33, 33, 33,
+ 33, 33, 33, 33, 33, 35, 37, 37,
+ 36, 36, 35, 36, 38, 38, 36, 35,
+ 36, 37, 38, 41, 42, 41, 39, 38,
+ 38, 38, 39, 41, 42, 41, 39, 39,
+ 40, 41, 43, 44, 44, 44, 44, 44,
+ 45, 47, 47, 47, 49, 50, 51, 51,
+ 51, 53, 55, 57, 58, 59, 57, 57,
+};
+
+static const uint8_t dnxhd_1238_chroma_weigth[] = {
+ 0, 32, 35, 35, 35, 34, 34, 35,
+ 39, 43, 45, 45, 41, 39, 40, 41,
+ 42, 44, 48, 55, 59, 63, 65, 59,
+ 53, 52, 52, 55, 61, 62, 58, 58,
+ 63, 66, 66, 65, 70, 74, 70, 66,
+ 65, 68, 75, 77, 74, 74, 77, 76,
+ 73, 73, 73, 73, 76, 80, 89, 90,
+ 82, 77, 80, 86, 84, 82, 82, 82,
+};
+
+/* FIXME permute */
+static const uint8_t dnxhd_1243_luma_weigth[] = {
+ 0,32,35,35,38,40,44,45,
+ 32,33,35,35,39,42,44,45,
+ 33,35,34,37,41,42,45,45,
+ 35,35,37,40,41,44,45,48,
+ 35,37,38,40,43,45,47,48,
+ 36,36,38,40,45,47,48,47,
+ 35,36,38,41,45,46,47,48,
+ 36,37,39,41,44,45,47,47,
+};
+
+/* FIXME permute */
+static const uint8_t dnxhd_1243_chroma_weigth[] = {
+ 0,32,37,39,41,42,45,45,
+ 36,36,39,41,43,45,46,45,
+ 37,41,41,43,45,44,45,46,
+ 43,42,43,46,44,45,46,48,
+ 43,44,47,45,44,46,47,49,
+ 44,46,44,45,45,47,48,47,
+ 44,42,46,44,45,46,47,48,
+ 41,43,45,44,45,46,47,47,
+};
+
+static const uint8_t dnxhd_1238_dc_codes[12] = {
+ 0, 12, 13, 1, 2, 3, 4, 5, 14, 30, 62, 63,
+};
+
+static const uint8_t dnxhd_1238_dc_bits[12] = {
+ 3, 4, 4, 3, 3, 3, 3, 3, 4, 5, 6, 6,
+};
+
+static const uint16_t dnxhd_1238_ac_codes[257] = {
+ 0, 1, 4, 10, 11, 24, 25, 26, 54, 55, 56, 57, 116, 117, 118, 119, 240, 241, 242, 243, 244, 245, 492, 493, 494, 495, 496, 497, 498, 499, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026, 2027, 4056, 4057, 4058, 4059, 4060, 4061, 4062, 4063, 4064, 4065, 4066, 4067, 4068, 4069, 8140, 8141, 8142, 8143, 8144, 8145, 8146, 8147, 8148, 8149, 8150, 8151, 8152, 8153, 8154, 8155, 8156, 16314, 16315, 16316, 16317, 16318, 16319, 16320, 16321, 16322, 16323, 16324, 16325, 16326, 16327, 16328, 16329, 16330, 16331, 16332, 16333, 16334, 16335, 16336, 16337, 16338, 32678, 32679, 32680, 32681, 32682, 32683, 32684, 32685, 32686, 32687, 32688, 32689, 32690, 32691, 32692, 32693, 32694, 32695, 32696, 32697, 32698, 32699, 32700, 32701, 32702, 32703, 32704, 32705, 65412, 65413, 65414, 65415, 65416, 65417, 65418, 65419, 65420, 65421, 65422, 65423, 65424, 65425, 65426, 65427, 65428, 65429, 65430, 65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438, 65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446, 65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454, 65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462, 65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470, 65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478, 65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486, 65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494, 65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502, 65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510, 65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518, 65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526, 65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534, 65535,
+};
+
+static const uint8_t dnxhd_1238_ac_bits[257] = {
+ 2, 2, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+};
+
+static const uint8_t dnxhd_1238_ac_level[257] = {
+ 1, 1, 2, 3, 0, 4, 5, 2, 6, 7, 8, 3, 9, 10, 11, 4, 12, 13, 14, 15, 16, 5, 17, 18, 19, 20, 21, 22, 6, 7, 23, 24, 25, 26, 27, 28, 29, 8, 9, 30, 31, 32, 33, 34, 35, 36, 37, 10, 11, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 12, 13, 14, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 15, 16, 17, 18, 62, 63, 64, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 19, 20, 21, 22, 23, 24, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 40, 25, 26, 27, 28, 29, 30, 38, 39, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
+}; /* 0 is EOB */
+
+static const uint8_t dnxhd_1238_ac_run_flag[257] = {
+ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+};
+
+static const uint8_t dnxhd_1238_ac_index_flag[257] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+};
+
+static const uint16_t dnxhd_1238_run_codes[62] = {
+ 0, 4, 10, 11, 24, 25, 26, 27, 56, 57, 58, 59, 120, 242, 486, 487, 488, 489, 980, 981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994, 995, 996, 997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023,
+};
+
+static const uint8_t dnxhd_1238_run_bits[62] = {
+ 1, 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+};
+
+static const uint8_t dnxhd_1238_run[62] = {
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 20, 21, 17, 18, 19, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
+};
diff --git a/contrib/ffmpeg/libavcodec/dnxhddec.c b/contrib/ffmpeg/libavcodec/dnxhddec.c
new file mode 100644
index 000000000..224439c47
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/dnxhddec.c
@@ -0,0 +1,368 @@
+/*
+ * VC3/DNxHD decoder.
+ * Copyright (c) 2007 SmartJog S.A., Baptiste Coudurier <baptiste dot coudurier at smartjog dot com>.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+//#define TRACE
+//#define DEBUG
+
+#include "avcodec.h"
+#include "bitstream.h"
+#include "dnxhddata.h"
+#include "dsputil.h"
+#include "mpegvideo.h"
+
+typedef struct {
+ int cid;
+ unsigned int width, height;
+ int interlaced;
+ unsigned int frame_size;
+ int index_bits;
+ int bit_depth;
+ const uint8_t *luma_weigth, *chroma_weigth;
+ const uint8_t *dc_codes, *dc_bits;
+ const uint16_t *ac_codes;
+ const uint8_t *ac_bits, *ac_level;
+ const uint8_t *ac_run_flag, *ac_index_flag;
+ const uint16_t *run_codes;
+ const uint8_t *run_bits, *run;
+} CIDEntry;
+
+typedef struct {
+ AVCodecContext *avctx;
+ AVFrame picture;
+ GetBitContext gb;
+ int cid; ///< compression id
+ unsigned int width, height;
+ unsigned int mb_width, mb_height;
+ uint32_t mb_scan_index[68]; /* max for 1080p */
+ int cur_field; ///< current interlaced field
+ int index_bits; ///< length of index value
+ VLC ac_vlc, dc_vlc, run_vlc;
+ const uint8_t *ac_level, *run;
+ const uint8_t *ac_run_flag, *ac_index_flag;
+ const uint8_t *luma_weigth, *chroma_weigth;
+ int last_dc[3];
+ DSPContext dsp;
+ DECLARE_ALIGNED_16(DCTELEM, blocks[8][64]);
+ DECLARE_ALIGNED_8(ScanTable, scantable);
+ const CIDEntry *cid_table;
+} DNXHDContext;
+
+static const CIDEntry cid_table[] = {
+ { 1238, 1920, 1080, 0, 917504, 4, 8,
+ dnxhd_1238_luma_weigth, dnxhd_1238_chroma_weigth,
+ dnxhd_1238_dc_codes, dnxhd_1238_dc_bits,
+ dnxhd_1238_ac_codes, dnxhd_1238_ac_bits, dnxhd_1238_ac_level,
+ dnxhd_1238_ac_run_flag, dnxhd_1238_ac_index_flag,
+ dnxhd_1238_run_codes, dnxhd_1238_run_bits, dnxhd_1238_run },
+/* { 1243, 1920, 1080, 1, 917504, 4, 8, */
+/* dnxhd_1243_luma_weigth, dnxhd_1243_chroma_weigth, */
+/* dnxhd_1238_dc_codes, dnxhd_1238_dc_bits, */
+/* dnxhd_1238_ac_codes, dnxhd_1238_ac_bits, dnxhd_1238_ac_level, */
+/* dnxhd_1238_ac_run_flag, dnxhd_1238_ac_index_flag, */
+/* dnxhd_1238_run_codes, dnxhd_1238_run_bits, dnxhd_1238_run }, */
+};
+
+static int dnxhd_get_cid_table(int cid)
+{
+ int i;
+ for (i = 0; i < sizeof(cid_table)/sizeof(CIDEntry); i++)
+ if (cid_table[i].cid == cid)
+ return i;
+ return -1;
+}
+
+#define DNXHD_VLC_BITS 9
+#define DNXHD_DC_VLC_BITS 6
+
+static int dnxhd_decode_init(AVCodecContext *avctx)
+{
+ DNXHDContext *ctx = avctx->priv_data;
+
+ ctx->avctx = avctx;
+ dsputil_init(&ctx->dsp, avctx);
+ avctx->coded_frame = &ctx->picture;
+ ctx->picture.type = FF_I_TYPE;
+ return 0;
+}
+
+static int dnxhd_init_vlc(DNXHDContext *ctx, int cid)
+{
+ if (!ctx->cid_table) {
+ int index;
+
+ if ((index = dnxhd_get_cid_table(cid)) < 0) {
+ av_log(ctx->avctx, AV_LOG_ERROR, "unsupported cid %d\n", cid);
+ return -1;
+ }
+ ctx->cid_table = &cid_table[index];
+ init_vlc(&ctx->ac_vlc, DNXHD_VLC_BITS, 257,
+ cid_table->ac_bits, 1, 1,
+ cid_table->ac_codes, 2, 2, 0);
+ init_vlc(&ctx->dc_vlc, DNXHD_DC_VLC_BITS, 12,
+ cid_table->dc_bits, 1, 1,
+ cid_table->dc_codes, 1, 1, 0);
+ init_vlc(&ctx->run_vlc, DNXHD_VLC_BITS, 62,
+ cid_table->run_bits, 1, 1,
+ cid_table->run_codes, 2, 2, 0);
+
+ ctx->run = cid_table->run;
+ ctx->ac_level = cid_table->ac_level;
+ ctx->ac_run_flag = cid_table->ac_run_flag;
+ ctx->ac_index_flag = cid_table->ac_index_flag;
+ ctx->luma_weigth = cid_table->luma_weigth;
+ ctx->chroma_weigth = cid_table->chroma_weigth;
+
+ ctx->index_bits = cid_table->index_bits;
+
+ ff_init_scantable(ctx->dsp.idct_permutation, &ctx->scantable, ff_zigzag_direct);
+ }
+ return 0;
+}
+
+static int dnxhd_decode_header(DNXHDContext *ctx, uint8_t *buf, int buf_size)
+{
+ static const uint8_t header_prefix[] = { 0x00, 0x00, 0x02, 0x80, 0x01 };
+ int i;
+
+ if (buf_size < 0x280)
+ return -1;
+
+ if (memcmp(buf, header_prefix, 5)) {
+ av_log(ctx->avctx, AV_LOG_ERROR, "error in header\n");
+ return -1;
+ }
+ if (buf[5] & 2) {/* interlaced FIXME top or bottom */
+ ctx->picture.interlaced_frame = 1;
+ av_log(ctx->avctx, AV_LOG_DEBUG, "interlaced %d\n", buf[5] & 3);
+ }
+
+ ctx->height = AV_RB16(buf + 0x18);
+ ctx->width = AV_RB16(buf + 0x1a);
+
+ dprintf(ctx->avctx, "width %d, heigth %d\n", ctx->width, ctx->height);
+
+ if (buf[0x21] & 0x80) {
+ av_log(ctx->avctx, AV_LOG_ERROR, "10 bit per component\n");
+ return -1;
+ }
+
+ ctx->cid = AV_RB32(buf + 0x28);
+ dprintf(ctx->avctx, "compression id %d\n", ctx->cid);
+
+ if (dnxhd_init_vlc(ctx, ctx->cid) < 0)
+ return -1;
+
+ if (buf_size < ctx->cid_table->frame_size) {
+ av_log(ctx->avctx, AV_LOG_ERROR, "incorrect frame size\n");
+ return -1;
+ }
+
+ 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");
+ 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]);
+ if (buf_size < ctx->mb_scan_index[i] + 0x280) {
+ av_log(ctx->avctx, AV_LOG_ERROR, "invalid mb scan index\n");
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+static int dnxhd_decode_dc(DNXHDContext *ctx)
+{
+ int len;
+
+ len = get_vlc2(&ctx->gb, ctx->dc_vlc.table, DNXHD_DC_VLC_BITS, 1);
+ return len ? get_xbits(&ctx->gb, len) : 0;
+}
+
+static void dnxhd_decode_dct_block(DNXHDContext *ctx, DCTELEM *block, int n, int qscale)
+{
+ int i, j, index, index2;
+ int level, component, sign;
+ const uint8_t *weigth_matrix;
+
+ if (n&2) {
+ component = 1 + (n&1);
+ weigth_matrix = ctx->chroma_weigth;
+ } else {
+ component = 0;
+ weigth_matrix = ctx->luma_weigth;
+ }
+
+ ctx->last_dc[component] += dnxhd_decode_dc(ctx);
+ block[0] = ctx->last_dc[component];
+ //av_log(ctx->avctx, AV_LOG_DEBUG, "dc %d\n", block[0]);
+ for (i = 1; ; i++) {
+ index = get_vlc2(&ctx->gb, ctx->ac_vlc.table, DNXHD_VLC_BITS, 2);
+ //av_log(ctx->avctx, AV_LOG_DEBUG, "index %d\n", index);
+ level = ctx->ac_level[index];
+ if (!level) { /* EOB */
+ //av_log(ctx->avctx, AV_LOG_DEBUG, "EOB\n");
+ return;
+ }
+ sign = get_sbits(&ctx->gb, 1);
+
+ if (ctx->ac_index_flag[index]) {
+ level += get_bits(&ctx->gb, ctx->index_bits)<<6;
+ }
+
+ if (ctx->ac_run_flag[index]) {
+ index2 = get_vlc2(&ctx->gb, ctx->run_vlc.table, DNXHD_VLC_BITS, 2);
+ i += ctx->run[index2];
+ }
+
+ j = ctx->scantable.permutated[i];
+ //av_log(ctx->avctx, AV_LOG_DEBUG, "j %d\n", j);
+ //av_log(ctx->avctx, AV_LOG_DEBUG, "level %d, weigth %d\n", level, weigth_matrix[i]);
+ level = (2*level+1) * qscale * weigth_matrix[i];
+ if (weigth_matrix[i] != 32) // FIXME 10bit
+ level += 32;
+ level >>= 6;
+ level = (level^sign) - sign;
+
+ if (i > 63) {
+ av_log(ctx->avctx, AV_LOG_ERROR, "ac tex damaged %d, %d\n", n, i);
+ return;
+ }
+
+ //av_log(NULL, AV_LOG_DEBUG, "i %d, j %d, end level %d\n", i, j, level);
+ block[j] = level;
+ }
+}
+
+static int dnxhd_decode_macroblock(DNXHDContext *ctx, int x, int y)
+{
+ int dct_linesize_luma = ctx->picture.linesize[0];
+ int dct_linesize_chroma = ctx->picture.linesize[1];
+ uint8_t *dest_y, *dest_u, *dest_v;
+ int dct_offset;
+ int qscale, i;
+
+ ctx->dsp.clear_blocks(ctx->blocks[0]);
+ ctx->dsp.clear_blocks(ctx->blocks[2]); // FIXME change clear blocks to take block amount
+
+ qscale = get_bits(&ctx->gb, 11);
+ skip_bits1(&ctx->gb);
+ //av_log(ctx->avctx, AV_LOG_DEBUG, "qscale %d\n", qscale);
+
+ for (i = 0; i < 8; i++) {
+ dnxhd_decode_dct_block(ctx, ctx->blocks[i], i, qscale);
+ }
+ dest_y = ctx->picture.data[0] + ((y * dct_linesize_luma) << 4) + (x << 4);
+ dest_u = ctx->picture.data[1] + ((y * dct_linesize_chroma) << 4) + (x << 3);
+ dest_v = ctx->picture.data[2] + ((y * dct_linesize_chroma) << 4) + (x << 3);
+
+ dct_offset = dct_linesize_luma << 3;
+ ctx->dsp.idct_put(dest_y, dct_linesize_luma, ctx->blocks[0]);
+ ctx->dsp.idct_put(dest_y + 8, dct_linesize_luma, ctx->blocks[1]);
+ ctx->dsp.idct_put(dest_y + dct_offset, dct_linesize_luma, ctx->blocks[4]);
+ ctx->dsp.idct_put(dest_y + dct_offset + 8, dct_linesize_luma, ctx->blocks[5]);
+
+ if (!(ctx->avctx->flags & CODEC_FLAG_GRAY)) {
+ dct_offset = dct_linesize_chroma << 3;
+ ctx->dsp.idct_put(dest_u, dct_linesize_chroma, ctx->blocks[2]);
+ ctx->dsp.idct_put(dest_v, dct_linesize_chroma, ctx->blocks[3]);
+ ctx->dsp.idct_put(dest_u + dct_offset, dct_linesize_chroma, ctx->blocks[6]);
+ ctx->dsp.idct_put(dest_v + dct_offset, dct_linesize_chroma, ctx->blocks[7]);
+ }
+
+ return 0;
+}
+
+static int dnxhd_decode_macroblocks(DNXHDContext *ctx, uint8_t *buf, int buf_size)
+{
+ int x, y;
+ for (y = 0; y < ctx->mb_height; y++) {
+ memset(ctx->last_dc, 4, sizeof(ctx->last_dc)); // 4 for levels +128
+ init_get_bits(&ctx->gb, buf + ctx->mb_scan_index[y], (buf_size - ctx->mb_scan_index[y]) << 3);
+ for (x = 0; x < ctx->mb_width; x++) {
+ //START_TIMER;
+ dnxhd_decode_macroblock(ctx, x, y);
+ //STOP_TIMER("decode macroblock");
+ }
+ }
+ return 0;
+}
+
+static int dnxhd_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ DNXHDContext *ctx = avctx->priv_data;
+ AVFrame *picture = data;
+
+ dprintf(avctx, "frame size %d\n", buf_size);
+
+ if (dnxhd_decode_header(ctx, buf, buf_size) < 0)
+ return -1;
+
+ avctx->pix_fmt = PIX_FMT_YUV422P;
+ if (avcodec_check_dimensions(avctx, ctx->width, ctx->height))
+ return -1;
+ avcodec_set_dimensions(avctx, ctx->width, ctx->height);
+
+ if (ctx->picture.data[0])
+ avctx->release_buffer(avctx, &ctx->picture);
+ if (avctx->get_buffer(avctx, &ctx->picture) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ return -1;
+ }
+
+ dnxhd_decode_macroblocks(ctx, buf + 0x280, buf_size - 0x280);
+
+ *picture = ctx->picture;
+ *data_size = sizeof(AVPicture);
+ return buf_size;
+}
+
+static int dnxhd_decode_close(AVCodecContext *avctx)
+{
+ DNXHDContext *ctx = avctx->priv_data;
+
+ if(ctx->picture.data[0])
+ avctx->release_buffer(avctx, &ctx->picture);
+ free_vlc(&ctx->ac_vlc);
+ free_vlc(&ctx->dc_vlc);
+ free_vlc(&ctx->run_vlc);
+ return 0;
+}
+
+AVCodec dnxhd_decoder = {
+ "dnxhd",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_DNXHD,
+ sizeof(DNXHDContext),
+ dnxhd_decode_init,
+ NULL,
+ dnxhd_decode_close,
+ dnxhd_decode_frame,
+ CODEC_CAP_DR1,
+};
diff --git a/src/libffmpeg/libavcodec/dpcm.c b/contrib/ffmpeg/libavcodec/dpcm.c
index 6243881de..6243881de 100644
--- a/src/libffmpeg/libavcodec/dpcm.c
+++ b/contrib/ffmpeg/libavcodec/dpcm.c
diff --git a/contrib/ffmpeg/libavcodec/dsicinav.c b/contrib/ffmpeg/libavcodec/dsicinav.c
new file mode 100644
index 000000000..c7c3f5627
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/dsicinav.c
@@ -0,0 +1,362 @@
+/*
+ * Delphine Software International CIN Audio/Video Decoders
+ * Copyright (c) 2006 Gregory Montoir (cyx@users.sourceforge.net)
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 dsicinav.c
+ * Delphine Software International CIN audio/video decoders
+ */
+
+#include "avcodec.h"
+#include "common.h"
+
+
+typedef enum CinVideoBitmapIndex {
+ CIN_CUR_BMP = 0, /* current */
+ CIN_PRE_BMP = 1, /* previous */
+ CIN_INT_BMP = 2 /* intermediate */
+} CinVideoBitmapIndex;
+
+typedef struct CinVideoContext {
+ AVCodecContext *avctx;
+ AVFrame frame;
+ unsigned int bitmap_size;
+ uint32_t palette[256];
+ uint8_t *bitmap_table[3];
+} CinVideoContext;
+
+typedef struct CinAudioContext {
+ AVCodecContext *avctx;
+ int initial_decode_frame;
+ int delta;
+} CinAudioContext;
+
+
+/* table defining a geometric sequence with multiplier = 32767 ^ (1 / 128) */
+static const int16_t cinaudio_delta16_table[256] = {
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, -30210, -27853, -25680, -23677, -21829,
+ -20126, -18556, -17108, -15774, -14543, -13408, -12362, -11398,
+ -10508, -9689, -8933, -8236, -7593, -7001, -6455, -5951,
+ -5487, -5059, -4664, -4300, -3964, -3655, -3370, -3107,
+ -2865, -2641, -2435, -2245, -2070, -1908, -1759, -1622,
+ -1495, -1379, -1271, -1172, -1080, -996, -918, -847,
+ -781, -720, -663, -612, -564, -520, -479, -442,
+ -407, -376, -346, -319, -294, -271, -250, -230,
+ -212, -196, -181, -166, -153, -141, -130, -120,
+ -111, -102, -94, -87, -80, -74, -68, -62,
+ -58, -53, -49, -45, -41, -38, -35, -32,
+ -30, -27, -25, -23, -21, -20, -18, -17,
+ -15, -14, -13, -12, -11, -10, -9, -8,
+ -7, -6, -5, -4, -3, -2, -1, 0,
+ 0, 1, 2, 3, 4, 5, 6, 7,
+ 8, 9, 10, 11, 12, 13, 14, 15,
+ 17, 18, 20, 21, 23, 25, 27, 30,
+ 32, 35, 38, 41, 45, 49, 53, 58,
+ 62, 68, 74, 80, 87, 94, 102, 111,
+ 120, 130, 141, 153, 166, 181, 196, 212,
+ 230, 250, 271, 294, 319, 346, 376, 407,
+ 442, 479, 520, 564, 612, 663, 720, 781,
+ 847, 918, 996, 1080, 1172, 1271, 1379, 1495,
+ 1622, 1759, 1908, 2070, 2245, 2435, 2641, 2865,
+ 3107, 3370, 3655, 3964, 4300, 4664, 5059, 5487,
+ 5951, 6455, 7001, 7593, 8236, 8933, 9689, 10508,
+ 11398, 12362, 13408, 14543, 15774, 17108, 18556, 20126,
+ 21829, 23677, 25680, 27853, 30210, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+
+static int cinvideo_decode_init(AVCodecContext *avctx)
+{
+ CinVideoContext *cin = (CinVideoContext *)avctx->priv_data;
+ unsigned int i;
+
+ cin->avctx = avctx;
+ avctx->pix_fmt = PIX_FMT_PAL8;
+ avctx->has_b_frames = 0;
+
+ cin->frame.data[0] = NULL;
+
+ cin->bitmap_size = avctx->width * avctx->height;
+ for (i = 0; i < 3; ++i) {
+ cin->bitmap_table[i] = av_mallocz(cin->bitmap_size);
+ if (!cin->bitmap_table[i])
+ av_log(avctx, AV_LOG_ERROR, "Can't allocate bitmap buffers.\n");
+ }
+
+ return 0;
+}
+
+static void cin_apply_delta_data(const unsigned char *src, unsigned char *dst, int size)
+{
+ while (size--)
+ *dst++ += *src++;
+}
+
+static int cin_decode_huffman(const unsigned char *src, int src_size, unsigned char *dst, int dst_size)
+{
+ int b, huff_code = 0;
+ unsigned char huff_code_table[15];
+ unsigned char *dst_cur = dst;
+ unsigned char *dst_end = dst + dst_size;
+ const unsigned char *src_end = src + src_size;
+
+ memcpy(huff_code_table, src, 15); src += 15; src_size -= 15;
+
+ while (src < src_end) {
+ huff_code = *src++;
+ if ((huff_code >> 4) == 15) {
+ b = huff_code << 4;
+ huff_code = *src++;
+ *dst_cur++ = b | (huff_code >> 4);
+ } else
+ *dst_cur++ = huff_code_table[huff_code >> 4];
+ if (dst_cur >= dst_end)
+ break;
+
+ huff_code &= 15;
+ if (huff_code == 15) {
+ *dst_cur++ = *src++;
+ } else
+ *dst_cur++ = huff_code_table[huff_code];
+ if (dst_cur >= dst_end)
+ break;
+ }
+
+ return dst_cur - dst;
+}
+
+static void cin_decode_lzss(const unsigned char *src, int src_size, unsigned char *dst, int dst_size)
+{
+ uint16_t cmd;
+ int i, sz, offset, code;
+ unsigned char *dst_end = dst + dst_size;
+ const unsigned char *src_end = src + src_size;
+
+ while (src < src_end && dst < dst_end) {
+ code = *src++;
+ for (i = 0; i < 8 && src < src_end && dst < dst_end; ++i) {
+ if (code & (1 << i)) {
+ *dst++ = *src++;
+ } else {
+ cmd = AV_RL16(src); src += 2;
+ offset = cmd >> 4;
+ sz = (cmd & 0xF) + 2;
+ /* don't use memcpy/memmove here as the decoding routine (ab)uses */
+ /* buffer overlappings to repeat bytes in the destination */
+ sz = FFMIN(sz, dst_end - dst);
+ while (sz--) {
+ *dst = *(dst - offset - 1);
+ ++dst;
+ }
+ }
+ }
+ }
+}
+
+static void cin_decode_rle(const unsigned char *src, int src_size, unsigned char *dst, int dst_size)
+{
+ int len, code;
+ unsigned char *dst_end = dst + dst_size;
+ const unsigned char *src_end = src + src_size;
+
+ while (src < src_end && dst < dst_end) {
+ code = *src++;
+ if (code & 0x80) {
+ len = code - 0x7F;
+ memset(dst, *src++, FFMIN(len, dst_end - dst));
+ } else {
+ len = code + 1;
+ memcpy(dst, src, FFMIN(len, dst_end - dst));
+ src += len;
+ }
+ dst += len;
+ }
+}
+
+static int cinvideo_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ CinVideoContext *cin = (CinVideoContext *)avctx->priv_data;
+ int i, y, palette_type, palette_colors_count, bitmap_frame_type, bitmap_frame_size;
+
+ cin->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
+ if (avctx->reget_buffer(avctx, &cin->frame)) {
+ av_log(cin->avctx, AV_LOG_ERROR, "delphinecinvideo: reget_buffer() failed to allocate a frame\n");
+ return -1;
+ }
+
+ palette_type = buf[0];
+ palette_colors_count = buf[1] | (buf[2] << 8);
+ bitmap_frame_type = buf[3];
+ buf += 4;
+
+ bitmap_frame_size = buf_size - 4;
+
+ /* handle palette */
+ if (palette_type == 0) {
+ for (i = 0; i < palette_colors_count; ++i) {
+ cin->palette[i] = (buf[2] << 16) | (buf[1] << 8) | buf[0];
+ buf += 3;
+ bitmap_frame_size -= 3;
+ }
+ } else {
+ for (i = 0; i < palette_colors_count; ++i) {
+ cin->palette[buf[0]] = (buf[3] << 16) | (buf[2] << 8) | buf[1];
+ buf += 4;
+ bitmap_frame_size -= 4;
+ }
+ }
+ memcpy(cin->frame.data[1], cin->palette, sizeof(cin->palette));
+ cin->frame.palette_has_changed = 1;
+
+ /* note: the decoding routines below assumes that surface.width = surface.pitch */
+ switch (bitmap_frame_type) {
+ case 9:
+ cin_decode_rle(buf, bitmap_frame_size,
+ cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);
+ break;
+ case 34:
+ cin_decode_rle(buf, bitmap_frame_size,
+ cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);
+ cin_apply_delta_data(cin->bitmap_table[CIN_PRE_BMP],
+ cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);
+ break;
+ case 35:
+ cin_decode_huffman(buf, bitmap_frame_size,
+ cin->bitmap_table[CIN_INT_BMP], cin->bitmap_size);
+ cin_decode_rle(cin->bitmap_table[CIN_INT_BMP], bitmap_frame_size,
+ cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);
+ break;
+ case 36:
+ bitmap_frame_size = cin_decode_huffman(buf, bitmap_frame_size,
+ cin->bitmap_table[CIN_INT_BMP], cin->bitmap_size);
+ cin_decode_rle(cin->bitmap_table[CIN_INT_BMP], bitmap_frame_size,
+ cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);
+ cin_apply_delta_data(cin->bitmap_table[CIN_PRE_BMP],
+ cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);
+ break;
+ case 37:
+ cin_decode_huffman(buf, bitmap_frame_size,
+ cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);
+ break;
+ case 38:
+ cin_decode_lzss(buf, bitmap_frame_size,
+ cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);
+ break;
+ case 39:
+ cin_decode_lzss(buf, bitmap_frame_size,
+ cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);
+ cin_apply_delta_data(cin->bitmap_table[CIN_PRE_BMP],
+ cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);
+ break;
+ }
+
+ for (y = 0; y < cin->avctx->height; ++y)
+ memcpy(cin->frame.data[0] + (cin->avctx->height - 1 - y) * cin->frame.linesize[0],
+ cin->bitmap_table[CIN_CUR_BMP] + y * cin->avctx->width,
+ cin->avctx->width);
+
+ FFSWAP(uint8_t *, cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_table[CIN_PRE_BMP]);
+
+ *data_size = sizeof(AVFrame);
+ *(AVFrame *)data = cin->frame;
+
+ return buf_size;
+}
+
+static int cinvideo_decode_end(AVCodecContext *avctx)
+{
+ CinVideoContext *cin = (CinVideoContext *)avctx->priv_data;
+ int i;
+
+ if (cin->frame.data[0])
+ avctx->release_buffer(avctx, &cin->frame);
+
+ for (i = 0; i < 3; ++i)
+ av_free(cin->bitmap_table[i]);
+
+ return 0;
+}
+
+static int cinaudio_decode_init(AVCodecContext *avctx)
+{
+ CinAudioContext *cin = (CinAudioContext *)avctx->priv_data;
+
+ cin->avctx = avctx;
+ cin->initial_decode_frame = 1;
+ cin->delta = 0;
+
+ return 0;
+}
+
+static int cinaudio_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ CinAudioContext *cin = (CinAudioContext *)avctx->priv_data;
+ uint8_t *src = buf;
+ int16_t *samples = (int16_t *)data;
+
+ if (cin->initial_decode_frame) {
+ cin->initial_decode_frame = 0;
+ cin->delta = (int16_t)AV_RL16(src); src += 2;
+ *samples++ = cin->delta;
+ buf_size -= 2;
+ }
+ while (buf_size > 0) {
+ cin->delta += cinaudio_delta16_table[*src++];
+ cin->delta = av_clip(cin->delta, -32768, 32767);
+ *samples++ = cin->delta;
+ --buf_size;
+ }
+
+ *data_size = (uint8_t *)samples - (uint8_t *)data;
+
+ return src - buf;
+}
+
+
+AVCodec dsicinvideo_decoder = {
+ "dsicinvideo",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_DSICINVIDEO,
+ sizeof(CinVideoContext),
+ cinvideo_decode_init,
+ NULL,
+ cinvideo_decode_end,
+ cinvideo_decode_frame,
+ CODEC_CAP_DR1,
+};
+
+AVCodec dsicinaudio_decoder = {
+ "dsicinaudio",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_DSICINAUDIO,
+ sizeof(CinAudioContext),
+ cinaudio_decode_init,
+ NULL,
+ NULL,
+ cinaudio_decode_frame,
+};
diff --git a/contrib/ffmpeg/libavcodec/dsputil.c b/contrib/ffmpeg/libavcodec/dsputil.c
new file mode 100644
index 000000000..3f5e845e7
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/dsputil.c
@@ -0,0 +1,4194 @@
+/*
+ * DSP utils
+ * Copyright (c) 2000, 2001 Fabrice Bellard.
+ * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * gmc & q-pel & 32/64 bit based MC by Michael Niedermayer <michaelni@gmx.at>
+ */
+
+/**
+ * @file dsputil.c
+ * DSP utils
+ */
+
+#include "avcodec.h"
+#include "dsputil.h"
+#include "mpegvideo.h"
+#include "simple_idct.h"
+#include "faandct.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);
+
+uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP] = {0, };
+uint32_t ff_squareTbl[512] = {0, };
+
+const uint8_t ff_zigzag_direct[64] = {
+ 0, 1, 8, 16, 9, 2, 3, 10,
+ 17, 24, 32, 25, 18, 11, 4, 5,
+ 12, 19, 26, 33, 40, 48, 41, 34,
+ 27, 20, 13, 6, 7, 14, 21, 28,
+ 35, 42, 49, 56, 57, 50, 43, 36,
+ 29, 22, 15, 23, 30, 37, 44, 51,
+ 58, 59, 52, 45, 38, 31, 39, 46,
+ 53, 60, 61, 54, 47, 55, 62, 63
+};
+
+/* Specific zigzag scan for 248 idct. NOTE that unlike the
+ specification, we interleave the fields */
+const uint8_t ff_zigzag248_direct[64] = {
+ 0, 8, 1, 9, 16, 24, 2, 10,
+ 17, 25, 32, 40, 48, 56, 33, 41,
+ 18, 26, 3, 11, 4, 12, 19, 27,
+ 34, 42, 49, 57, 50, 58, 35, 43,
+ 20, 28, 5, 13, 6, 14, 21, 29,
+ 36, 44, 51, 59, 52, 60, 37, 45,
+ 22, 30, 7, 15, 23, 31, 38, 46,
+ 53, 61, 54, 62, 39, 47, 55, 63,
+};
+
+/* not permutated inverse zigzag_direct + 1 for MMX quantizer */
+DECLARE_ALIGNED_8(uint16_t, inv_zigzag_direct16[64]) = {0, };
+
+const uint8_t ff_alternate_horizontal_scan[64] = {
+ 0, 1, 2, 3, 8, 9, 16, 17,
+ 10, 11, 4, 5, 6, 7, 15, 14,
+ 13, 12, 19, 18, 24, 25, 32, 33,
+ 26, 27, 20, 21, 22, 23, 28, 29,
+ 30, 31, 34, 35, 40, 41, 48, 49,
+ 42, 43, 36, 37, 38, 39, 44, 45,
+ 46, 47, 50, 51, 56, 57, 58, 59,
+ 52, 53, 54, 55, 60, 61, 62, 63,
+};
+
+const uint8_t ff_alternate_vertical_scan[64] = {
+ 0, 8, 16, 24, 1, 9, 2, 10,
+ 17, 25, 32, 40, 48, 56, 57, 49,
+ 41, 33, 26, 18, 3, 11, 4, 12,
+ 19, 27, 34, 42, 50, 58, 35, 43,
+ 51, 59, 20, 28, 5, 13, 6, 14,
+ 21, 29, 36, 44, 52, 60, 37, 45,
+ 53, 61, 22, 30, 7, 15, 23, 31,
+ 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]={
+ 0, 4294967295U,2147483648U,1431655766, 1073741824, 858993460, 715827883, 613566757,
+ 536870912, 477218589, 429496730, 390451573, 357913942, 330382100, 306783379, 286331154,
+ 268435456, 252645136, 238609295, 226050911, 214748365, 204522253, 195225787, 186737709,
+ 178956971, 171798692, 165191050, 159072863, 153391690, 148102321, 143165577, 138547333,
+ 134217728, 130150525, 126322568, 122713352, 119304648, 116080198, 113025456, 110127367,
+ 107374183, 104755300, 102261127, 99882961, 97612894, 95443718, 93368855, 91382283,
+ 89478486, 87652394, 85899346, 84215046, 82595525, 81037119, 79536432, 78090315,
+ 76695845, 75350304, 74051161, 72796056, 71582789, 70409300, 69273667, 68174085,
+ 67108864, 66076420, 65075263, 64103990, 63161284, 62245903, 61356676, 60492498,
+ 59652324, 58835169, 58040099, 57266231, 56512728, 55778797, 55063684, 54366675,
+ 53687092, 53024288, 52377650, 51746594, 51130564, 50529028, 49941481, 49367441,
+ 48806447, 48258060, 47721859, 47197443, 46684428, 46182445, 45691142, 45210183,
+ 44739243, 44278014, 43826197, 43383509, 42949673, 42524429, 42107523, 41698712,
+ 41297763, 40904451, 40518560, 40139882, 39768216, 39403370, 39045158, 38693400,
+ 38347923, 38008561, 37675152, 37347542, 37025581, 36709123, 36398028, 36092163,
+ 35791395, 35495598, 35204650, 34918434, 34636834, 34359739, 34087043, 33818641,
+ 33554432, 33294321, 33038210, 32786010, 32537632, 32292988, 32051995, 31814573,
+ 31580642, 31350127, 31122952, 30899046, 30678338, 30460761, 30246249, 30034737,
+ 29826162, 29620465, 29417585, 29217465, 29020050, 28825284, 28633116, 28443493,
+ 28256364, 28071682, 27889399, 27709467, 27531842, 27356480, 27183338, 27012373,
+ 26843546, 26676816, 26512144, 26349493, 26188825, 26030105, 25873297, 25718368,
+ 25565282, 25414008, 25264514, 25116768, 24970741, 24826401, 24683721, 24542671,
+ 24403224, 24265352, 24129030, 23994231, 23860930, 23729102, 23598722, 23469767,
+ 23342214, 23216040, 23091223, 22967740, 22845571, 22724695, 22605092, 22486740,
+ 22369622, 22253717, 22139007, 22025474, 21913099, 21801865, 21691755, 21582751,
+ 21474837, 21367997, 21262215, 21157475, 21053762, 20951060, 20849356, 20748635,
+ 20648882, 20550083, 20452226, 20355296, 20259280, 20164166, 20069941, 19976593,
+ 19884108, 19792477, 19701685, 19611723, 19522579, 19434242, 19346700, 19259944,
+ 19173962, 19088744, 19004281, 18920561, 18837576, 18755316, 18673771, 18592933,
+ 18512791, 18433337, 18354562, 18276457, 18199014, 18122225, 18046082, 17970575,
+ 17895698, 17821442, 17747799, 17674763, 17602325, 17530479, 17459217, 17388532,
+ 17318417, 17248865, 17179870, 17111424, 17043522, 16976156, 16909321, 16843010,
+};
+
+/* Input permutation for the simple_idct_mmx */
+static const uint8_t simple_mmx_permutation[64]={
+ 0x00, 0x08, 0x04, 0x09, 0x01, 0x0C, 0x05, 0x0D,
+ 0x10, 0x18, 0x14, 0x19, 0x11, 0x1C, 0x15, 0x1D,
+ 0x20, 0x28, 0x24, 0x29, 0x21, 0x2C, 0x25, 0x2D,
+ 0x12, 0x1A, 0x16, 0x1B, 0x13, 0x1E, 0x17, 0x1F,
+ 0x02, 0x0A, 0x06, 0x0B, 0x03, 0x0E, 0x07, 0x0F,
+ 0x30, 0x38, 0x34, 0x39, 0x31, 0x3C, 0x35, 0x3D,
+ 0x22, 0x2A, 0x26, 0x2B, 0x23, 0x2E, 0x27, 0x2F,
+ 0x32, 0x3A, 0x36, 0x3B, 0x33, 0x3E, 0x37, 0x3F,
+};
+
+static int pix_sum_c(uint8_t * pix, int line_size)
+{
+ int s, i, j;
+
+ s = 0;
+ for (i = 0; i < 16; i++) {
+ for (j = 0; j < 16; j += 8) {
+ s += pix[0];
+ s += pix[1];
+ s += pix[2];
+ s += pix[3];
+ s += pix[4];
+ s += pix[5];
+ s += pix[6];
+ s += pix[7];
+ pix += 8;
+ }
+ pix += line_size - 16;
+ }
+ return s;
+}
+
+static int pix_norm1_c(uint8_t * pix, int line_size)
+{
+ int s, i, j;
+ uint32_t *sq = ff_squareTbl + 256;
+
+ s = 0;
+ for (i = 0; i < 16; i++) {
+ for (j = 0; j < 16; j += 8) {
+#if 0
+ s += sq[pix[0]];
+ s += sq[pix[1]];
+ s += sq[pix[2]];
+ s += sq[pix[3]];
+ s += sq[pix[4]];
+ s += sq[pix[5]];
+ s += sq[pix[6]];
+ s += sq[pix[7]];
+#else
+#if LONG_MAX > 2147483647
+ register uint64_t x=*(uint64_t*)pix;
+ s += sq[x&0xff];
+ s += sq[(x>>8)&0xff];
+ s += sq[(x>>16)&0xff];
+ s += sq[(x>>24)&0xff];
+ s += sq[(x>>32)&0xff];
+ s += sq[(x>>40)&0xff];
+ s += sq[(x>>48)&0xff];
+ s += sq[(x>>56)&0xff];
+#else
+ register uint32_t x=*(uint32_t*)pix;
+ s += sq[x&0xff];
+ s += sq[(x>>8)&0xff];
+ s += sq[(x>>16)&0xff];
+ s += sq[(x>>24)&0xff];
+ x=*(uint32_t*)(pix+4);
+ s += sq[x&0xff];
+ s += sq[(x>>8)&0xff];
+ s += sq[(x>>16)&0xff];
+ s += sq[(x>>24)&0xff];
+#endif
+#endif
+ pix += 8;
+ }
+ pix += line_size - 16;
+ }
+ return s;
+}
+
+static void bswap_buf(uint32_t *dst, uint32_t *src, int w){
+ int i;
+
+ for(i=0; i+8<=w; i+=8){
+ dst[i+0]= bswap_32(src[i+0]);
+ dst[i+1]= bswap_32(src[i+1]);
+ dst[i+2]= bswap_32(src[i+2]);
+ dst[i+3]= bswap_32(src[i+3]);
+ dst[i+4]= bswap_32(src[i+4]);
+ dst[i+5]= bswap_32(src[i+5]);
+ dst[i+6]= bswap_32(src[i+6]);
+ dst[i+7]= bswap_32(src[i+7]);
+ }
+ for(;i<w; i++){
+ dst[i+0]= bswap_32(src[i+0]);
+ }
+}
+
+static int sse4_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h)
+{
+ int s, i;
+ uint32_t *sq = ff_squareTbl + 256;
+
+ s = 0;
+ for (i = 0; i < h; i++) {
+ s += sq[pix1[0] - pix2[0]];
+ s += sq[pix1[1] - pix2[1]];
+ s += sq[pix1[2] - pix2[2]];
+ s += sq[pix1[3] - pix2[3]];
+ pix1 += line_size;
+ pix2 += line_size;
+ }
+ return s;
+}
+
+static int sse8_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h)
+{
+ int s, i;
+ uint32_t *sq = ff_squareTbl + 256;
+
+ s = 0;
+ for (i = 0; i < h; i++) {
+ s += sq[pix1[0] - pix2[0]];
+ s += sq[pix1[1] - pix2[1]];
+ s += sq[pix1[2] - pix2[2]];
+ s += sq[pix1[3] - pix2[3]];
+ s += sq[pix1[4] - pix2[4]];
+ s += sq[pix1[5] - pix2[5]];
+ s += sq[pix1[6] - pix2[6]];
+ s += sq[pix1[7] - pix2[7]];
+ pix1 += line_size;
+ pix2 += line_size;
+ }
+ return s;
+}
+
+static int sse16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
+{
+ int s, i;
+ uint32_t *sq = ff_squareTbl + 256;
+
+ s = 0;
+ for (i = 0; i < h; i++) {
+ s += sq[pix1[ 0] - pix2[ 0]];
+ s += sq[pix1[ 1] - pix2[ 1]];
+ s += sq[pix1[ 2] - pix2[ 2]];
+ s += sq[pix1[ 3] - pix2[ 3]];
+ s += sq[pix1[ 4] - pix2[ 4]];
+ s += sq[pix1[ 5] - pix2[ 5]];
+ s += sq[pix1[ 6] - pix2[ 6]];
+ s += sq[pix1[ 7] - pix2[ 7]];
+ s += sq[pix1[ 8] - pix2[ 8]];
+ s += sq[pix1[ 9] - pix2[ 9]];
+ s += sq[pix1[10] - pix2[10]];
+ s += sq[pix1[11] - pix2[11]];
+ s += sq[pix1[12] - pix2[12]];
+ s += sq[pix1[13] - pix2[13]];
+ s += sq[pix1[14] - pix2[14]];
+ s += sq[pix1[15] - pix2[15]];
+
+ pix1 += line_size;
+ pix2 += line_size;
+ }
+ return s;
+}
+
+
+#ifdef 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++){
+ for(ori= level ? 1 : 0; ori<4; ori++){
+ int size= w>>(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<size; i++){
+ for(j=0; j<size; j++){
+ int v= tmp[sx + sy + i*stride + j] * scale[type][dec_count-3][level][ori];
+ s += FFABS(v);
+ }
+ }
+ }
+ }
+ assert(s>=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
+
+static void get_pixels_c(DCTELEM *restrict block, const uint8_t *pixels, int line_size)
+{
+ int i;
+
+ /* read the pixels */
+ for(i=0;i<8;i++) {
+ block[0] = pixels[0];
+ block[1] = pixels[1];
+ block[2] = pixels[2];
+ block[3] = pixels[3];
+ block[4] = pixels[4];
+ block[5] = pixels[5];
+ block[6] = pixels[6];
+ block[7] = pixels[7];
+ pixels += line_size;
+ block += 8;
+ }
+}
+
+static void diff_pixels_c(DCTELEM *restrict block, const uint8_t *s1,
+ const uint8_t *s2, int stride){
+ int i;
+
+ /* read the pixels */
+ for(i=0;i<8;i++) {
+ block[0] = s1[0] - s2[0];
+ block[1] = s1[1] - s2[1];
+ block[2] = s1[2] - s2[2];
+ block[3] = s1[3] - s2[3];
+ block[4] = s1[4] - s2[4];
+ block[5] = s1[5] - s2[5];
+ block[6] = s1[6] - s2[6];
+ block[7] = s1[7] - s2[7];
+ s1 += stride;
+ s2 += stride;
+ block += 8;
+ }
+}
+
+
+static void put_pixels_clamped_c(const DCTELEM *block, uint8_t *restrict pixels,
+ int line_size)
+{
+ int i;
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+
+ /* read the pixels */
+ for(i=0;i<8;i++) {
+ pixels[0] = cm[block[0]];
+ pixels[1] = cm[block[1]];
+ pixels[2] = cm[block[2]];
+ pixels[3] = cm[block[3]];
+ pixels[4] = cm[block[4]];
+ pixels[5] = cm[block[5]];
+ pixels[6] = cm[block[6]];
+ pixels[7] = cm[block[7]];
+
+ pixels += line_size;
+ block += 8;
+ }
+}
+
+static void put_pixels_clamped4_c(const DCTELEM *block, uint8_t *restrict pixels,
+ int line_size)
+{
+ int i;
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+
+ /* read the pixels */
+ for(i=0;i<4;i++) {
+ pixels[0] = cm[block[0]];
+ pixels[1] = cm[block[1]];
+ pixels[2] = cm[block[2]];
+ pixels[3] = cm[block[3]];
+
+ pixels += line_size;
+ block += 8;
+ }
+}
+
+static void put_pixels_clamped2_c(const DCTELEM *block, uint8_t *restrict pixels,
+ int line_size)
+{
+ int i;
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+
+ /* read the pixels */
+ for(i=0;i<2;i++) {
+ pixels[0] = cm[block[0]];
+ pixels[1] = cm[block[1]];
+
+ pixels += line_size;
+ block += 8;
+ }
+}
+
+static void put_signed_pixels_clamped_c(const DCTELEM *block,
+ uint8_t *restrict pixels,
+ int line_size)
+{
+ int i, j;
+
+ for (i = 0; i < 8; i++) {
+ for (j = 0; j < 8; j++) {
+ if (*block < -128)
+ *pixels = 0;
+ else if (*block > 127)
+ *pixels = 255;
+ else
+ *pixels = (uint8_t)(*block + 128);
+ block++;
+ pixels++;
+ }
+ pixels += (line_size - 8);
+ }
+}
+
+static void add_pixels_clamped_c(const DCTELEM *block, uint8_t *restrict pixels,
+ int line_size)
+{
+ int i;
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+
+ /* read the pixels */
+ for(i=0;i<8;i++) {
+ pixels[0] = cm[pixels[0] + block[0]];
+ pixels[1] = cm[pixels[1] + block[1]];
+ pixels[2] = cm[pixels[2] + block[2]];
+ pixels[3] = cm[pixels[3] + block[3]];
+ pixels[4] = cm[pixels[4] + block[4]];
+ pixels[5] = cm[pixels[5] + block[5]];
+ pixels[6] = cm[pixels[6] + block[6]];
+ pixels[7] = cm[pixels[7] + block[7]];
+ pixels += line_size;
+ block += 8;
+ }
+}
+
+static void add_pixels_clamped4_c(const DCTELEM *block, uint8_t *restrict pixels,
+ int line_size)
+{
+ int i;
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+
+ /* read the pixels */
+ for(i=0;i<4;i++) {
+ pixels[0] = cm[pixels[0] + block[0]];
+ pixels[1] = cm[pixels[1] + block[1]];
+ pixels[2] = cm[pixels[2] + block[2]];
+ pixels[3] = cm[pixels[3] + block[3]];
+ pixels += line_size;
+ block += 8;
+ }
+}
+
+static void add_pixels_clamped2_c(const DCTELEM *block, uint8_t *restrict pixels,
+ int line_size)
+{
+ int i;
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+
+ /* read the pixels */
+ for(i=0;i<2;i++) {
+ pixels[0] = cm[pixels[0] + block[0]];
+ pixels[1] = cm[pixels[1] + block[1]];
+ pixels += line_size;
+ block += 8;
+ }
+}
+
+static void add_pixels8_c(uint8_t *restrict pixels, DCTELEM *block, int line_size)
+{
+ int i;
+ 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_pixels4_c(uint8_t *restrict pixels, DCTELEM *block, int line_size)
+{
+ int i;
+ for(i=0;i<4;i++) {
+ pixels[0] += block[0];
+ pixels[1] += block[1];
+ pixels[2] += block[2];
+ pixels[3] += block[3];
+ pixels += line_size;
+ block += 4;
+ }
+}
+
+#if 0
+
+#define PIXOP2(OPNAME, OP) \
+static void OPNAME ## _pixels(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
+{\
+ int i;\
+ for(i=0; i<h; i++){\
+ OP(*((uint64_t*)block), LD64(pixels));\
+ pixels+=line_size;\
+ block +=line_size;\
+ }\
+}\
+\
+static void OPNAME ## _no_rnd_pixels_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
+{\
+ int i;\
+ for(i=0; i<h; i++){\
+ const uint64_t a= LD64(pixels );\
+ const uint64_t b= LD64(pixels+1);\
+ OP(*((uint64_t*)block), (a&b) + (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
+ pixels+=line_size;\
+ block +=line_size;\
+ }\
+}\
+\
+static void OPNAME ## _pixels_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
+{\
+ int i;\
+ for(i=0; i<h; i++){\
+ const uint64_t a= LD64(pixels );\
+ const uint64_t b= LD64(pixels+1);\
+ OP(*((uint64_t*)block), (a|b) - (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
+ pixels+=line_size;\
+ block +=line_size;\
+ }\
+}\
+\
+static void OPNAME ## _no_rnd_pixels_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
+{\
+ int i;\
+ for(i=0; i<h; i++){\
+ const uint64_t a= LD64(pixels );\
+ const uint64_t b= LD64(pixels+line_size);\
+ OP(*((uint64_t*)block), (a&b) + (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
+ pixels+=line_size;\
+ block +=line_size;\
+ }\
+}\
+\
+static void OPNAME ## _pixels_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
+{\
+ int i;\
+ for(i=0; i<h; i++){\
+ const uint64_t a= LD64(pixels );\
+ const uint64_t b= LD64(pixels+line_size);\
+ OP(*((uint64_t*)block), (a|b) - (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
+ pixels+=line_size;\
+ block +=line_size;\
+ }\
+}\
+\
+static void OPNAME ## _pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
+{\
+ int i;\
+ const uint64_t a= LD64(pixels );\
+ const uint64_t b= LD64(pixels+1);\
+ uint64_t l0= (a&0x0303030303030303ULL)\
+ + (b&0x0303030303030303ULL)\
+ + 0x0202020202020202ULL;\
+ uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
+ + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
+ uint64_t l1,h1;\
+\
+ pixels+=line_size;\
+ for(i=0; i<h; i+=2){\
+ uint64_t a= LD64(pixels );\
+ uint64_t b= LD64(pixels+1);\
+ l1= (a&0x0303030303030303ULL)\
+ + (b&0x0303030303030303ULL);\
+ h1= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
+ + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
+ OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
+ pixels+=line_size;\
+ block +=line_size;\
+ a= LD64(pixels );\
+ b= LD64(pixels+1);\
+ l0= (a&0x0303030303030303ULL)\
+ + (b&0x0303030303030303ULL)\
+ + 0x0202020202020202ULL;\
+ h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
+ + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
+ OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
+ pixels+=line_size;\
+ block +=line_size;\
+ }\
+}\
+\
+static void OPNAME ## _no_rnd_pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
+{\
+ int i;\
+ const uint64_t a= LD64(pixels );\
+ const uint64_t b= LD64(pixels+1);\
+ uint64_t l0= (a&0x0303030303030303ULL)\
+ + (b&0x0303030303030303ULL)\
+ + 0x0101010101010101ULL;\
+ uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
+ + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
+ uint64_t l1,h1;\
+\
+ pixels+=line_size;\
+ for(i=0; i<h; i+=2){\
+ uint64_t a= LD64(pixels );\
+ uint64_t b= LD64(pixels+1);\
+ l1= (a&0x0303030303030303ULL)\
+ + (b&0x0303030303030303ULL);\
+ h1= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
+ + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
+ OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
+ pixels+=line_size;\
+ block +=line_size;\
+ a= LD64(pixels );\
+ b= LD64(pixels+1);\
+ l0= (a&0x0303030303030303ULL)\
+ + (b&0x0303030303030303ULL)\
+ + 0x0101010101010101ULL;\
+ h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
+ + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
+ OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
+ pixels+=line_size;\
+ block +=line_size;\
+ }\
+}\
+\
+CALL_2X_PIXELS(OPNAME ## _pixels16_c , OPNAME ## _pixels_c , 8)\
+CALL_2X_PIXELS(OPNAME ## _pixels16_x2_c , OPNAME ## _pixels_x2_c , 8)\
+CALL_2X_PIXELS(OPNAME ## _pixels16_y2_c , OPNAME ## _pixels_y2_c , 8)\
+CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_c, OPNAME ## _pixels_xy2_c, 8)\
+CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2_c , OPNAME ## _no_rnd_pixels_x2_c , 8)\
+CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2_c , OPNAME ## _no_rnd_pixels_y2_c , 8)\
+CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_c, OPNAME ## _no_rnd_pixels_xy2_c, 8)
+
+#define op_avg(a, b) a = ( ((a)|(b)) - ((((a)^(b))&0xFEFEFEFEFEFEFEFEULL)>>1) )
+#else // 64 bit variant
+
+#define PIXOP2(OPNAME, OP) \
+static void OPNAME ## _pixels2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
+ int i;\
+ for(i=0; i<h; i++){\
+ OP(*((uint16_t*)(block )), LD16(pixels ));\
+ pixels+=line_size;\
+ block +=line_size;\
+ }\
+}\
+static void OPNAME ## _pixels4_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
+ int i;\
+ for(i=0; i<h; i++){\
+ OP(*((uint32_t*)(block )), LD32(pixels ));\
+ pixels+=line_size;\
+ block +=line_size;\
+ }\
+}\
+static void OPNAME ## _pixels8_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
+ int i;\
+ for(i=0; i<h; i++){\
+ OP(*((uint32_t*)(block )), LD32(pixels ));\
+ OP(*((uint32_t*)(block+4)), LD32(pixels+4));\
+ pixels+=line_size;\
+ block +=line_size;\
+ }\
+}\
+static inline void OPNAME ## _no_rnd_pixels8_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
+ OPNAME ## _pixels8_c(block, pixels, line_size, h);\
+}\
+\
+static inline void OPNAME ## _no_rnd_pixels8_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
+ int src_stride1, int src_stride2, int h){\
+ int i;\
+ for(i=0; i<h; i++){\
+ uint32_t a,b;\
+ a= LD32(&src1[i*src_stride1 ]);\
+ b= LD32(&src2[i*src_stride2 ]);\
+ OP(*((uint32_t*)&dst[i*dst_stride ]), no_rnd_avg32(a, b));\
+ a= LD32(&src1[i*src_stride1+4]);\
+ b= LD32(&src2[i*src_stride2+4]);\
+ OP(*((uint32_t*)&dst[i*dst_stride+4]), no_rnd_avg32(a, b));\
+ }\
+}\
+\
+static inline void OPNAME ## _pixels8_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
+ int src_stride1, int src_stride2, int h){\
+ int i;\
+ for(i=0; i<h; i++){\
+ uint32_t a,b;\
+ a= LD32(&src1[i*src_stride1 ]);\
+ b= LD32(&src2[i*src_stride2 ]);\
+ OP(*((uint32_t*)&dst[i*dst_stride ]), rnd_avg32(a, b));\
+ a= LD32(&src1[i*src_stride1+4]);\
+ b= LD32(&src2[i*src_stride2+4]);\
+ OP(*((uint32_t*)&dst[i*dst_stride+4]), rnd_avg32(a, b));\
+ }\
+}\
+\
+static inline void OPNAME ## _pixels4_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
+ int src_stride1, int src_stride2, int h){\
+ int i;\
+ for(i=0; i<h; i++){\
+ uint32_t a,b;\
+ a= LD32(&src1[i*src_stride1 ]);\
+ b= LD32(&src2[i*src_stride2 ]);\
+ OP(*((uint32_t*)&dst[i*dst_stride ]), rnd_avg32(a, b));\
+ }\
+}\
+\
+static inline void OPNAME ## _pixels2_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
+ int src_stride1, int src_stride2, int h){\
+ int i;\
+ for(i=0; i<h; i++){\
+ uint32_t a,b;\
+ a= LD16(&src1[i*src_stride1 ]);\
+ b= LD16(&src2[i*src_stride2 ]);\
+ OP(*((uint16_t*)&dst[i*dst_stride ]), rnd_avg32(a, b));\
+ }\
+}\
+\
+static inline void OPNAME ## _pixels16_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
+ int src_stride1, int src_stride2, int h){\
+ OPNAME ## _pixels8_l2(dst , src1 , src2 , dst_stride, src_stride1, src_stride2, h);\
+ OPNAME ## _pixels8_l2(dst+8, src1+8, src2+8, dst_stride, src_stride1, src_stride2, h);\
+}\
+\
+static inline void OPNAME ## _no_rnd_pixels16_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
+ int src_stride1, int src_stride2, int h){\
+ OPNAME ## _no_rnd_pixels8_l2(dst , src1 , src2 , dst_stride, src_stride1, src_stride2, h);\
+ OPNAME ## _no_rnd_pixels8_l2(dst+8, src1+8, src2+8, dst_stride, src_stride1, src_stride2, h);\
+}\
+\
+static inline void OPNAME ## _no_rnd_pixels8_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
+ OPNAME ## _no_rnd_pixels8_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
+}\
+\
+static inline void OPNAME ## _pixels8_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
+ OPNAME ## _pixels8_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
+}\
+\
+static inline void OPNAME ## _no_rnd_pixels8_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
+ OPNAME ## _no_rnd_pixels8_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
+}\
+\
+static inline void OPNAME ## _pixels8_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
+ OPNAME ## _pixels8_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
+}\
+\
+static inline void OPNAME ## _pixels8_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
+ int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
+ int i;\
+ for(i=0; i<h; i++){\
+ uint32_t a, b, c, d, l0, l1, h0, h1;\
+ a= LD32(&src1[i*src_stride1]);\
+ b= LD32(&src2[i*src_stride2]);\
+ c= LD32(&src3[i*src_stride3]);\
+ d= LD32(&src4[i*src_stride4]);\
+ l0= (a&0x03030303UL)\
+ + (b&0x03030303UL)\
+ + 0x02020202UL;\
+ h0= ((a&0xFCFCFCFCUL)>>2)\
+ + ((b&0xFCFCFCFCUL)>>2);\
+ l1= (c&0x03030303UL)\
+ + (d&0x03030303UL);\
+ h1= ((c&0xFCFCFCFCUL)>>2)\
+ + ((d&0xFCFCFCFCUL)>>2);\
+ OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
+ a= LD32(&src1[i*src_stride1+4]);\
+ b= LD32(&src2[i*src_stride2+4]);\
+ c= LD32(&src3[i*src_stride3+4]);\
+ d= LD32(&src4[i*src_stride4+4]);\
+ l0= (a&0x03030303UL)\
+ + (b&0x03030303UL)\
+ + 0x02020202UL;\
+ h0= ((a&0xFCFCFCFCUL)>>2)\
+ + ((b&0xFCFCFCFCUL)>>2);\
+ l1= (c&0x03030303UL)\
+ + (d&0x03030303UL);\
+ h1= ((c&0xFCFCFCFCUL)>>2)\
+ + ((d&0xFCFCFCFCUL)>>2);\
+ OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
+ }\
+}\
+\
+static inline void OPNAME ## _pixels4_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
+ OPNAME ## _pixels4_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
+}\
+\
+static inline void OPNAME ## _pixels4_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
+ OPNAME ## _pixels4_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
+}\
+\
+static inline void OPNAME ## _pixels2_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
+ OPNAME ## _pixels2_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
+}\
+\
+static inline void OPNAME ## _pixels2_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
+ OPNAME ## _pixels2_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
+}\
+\
+static inline void OPNAME ## _no_rnd_pixels8_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
+ int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
+ int i;\
+ for(i=0; i<h; i++){\
+ uint32_t a, b, c, d, l0, l1, h0, h1;\
+ a= LD32(&src1[i*src_stride1]);\
+ b= LD32(&src2[i*src_stride2]);\
+ c= LD32(&src3[i*src_stride3]);\
+ d= LD32(&src4[i*src_stride4]);\
+ l0= (a&0x03030303UL)\
+ + (b&0x03030303UL)\
+ + 0x01010101UL;\
+ h0= ((a&0xFCFCFCFCUL)>>2)\
+ + ((b&0xFCFCFCFCUL)>>2);\
+ l1= (c&0x03030303UL)\
+ + (d&0x03030303UL);\
+ h1= ((c&0xFCFCFCFCUL)>>2)\
+ + ((d&0xFCFCFCFCUL)>>2);\
+ OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
+ a= LD32(&src1[i*src_stride1+4]);\
+ b= LD32(&src2[i*src_stride2+4]);\
+ c= LD32(&src3[i*src_stride3+4]);\
+ d= LD32(&src4[i*src_stride4+4]);\
+ l0= (a&0x03030303UL)\
+ + (b&0x03030303UL)\
+ + 0x01010101UL;\
+ h0= ((a&0xFCFCFCFCUL)>>2)\
+ + ((b&0xFCFCFCFCUL)>>2);\
+ l1= (c&0x03030303UL)\
+ + (d&0x03030303UL);\
+ h1= ((c&0xFCFCFCFCUL)>>2)\
+ + ((d&0xFCFCFCFCUL)>>2);\
+ OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
+ }\
+}\
+static inline void OPNAME ## _pixels16_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
+ int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
+ OPNAME ## _pixels8_l4(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
+ OPNAME ## _pixels8_l4(dst+8, src1+8, src2+8, src3+8, src4+8, dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
+}\
+static inline void OPNAME ## _no_rnd_pixels16_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
+ int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
+ OPNAME ## _no_rnd_pixels8_l4(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
+ OPNAME ## _no_rnd_pixels8_l4(dst+8, src1+8, src2+8, src3+8, src4+8, dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
+}\
+\
+static inline void OPNAME ## _pixels2_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
+{\
+ int i, a0, b0, a1, b1;\
+ a0= pixels[0];\
+ b0= pixels[1] + 2;\
+ a0 += b0;\
+ b0 += pixels[2];\
+\
+ pixels+=line_size;\
+ for(i=0; i<h; i+=2){\
+ a1= pixels[0];\
+ b1= pixels[1];\
+ a1 += b1;\
+ b1 += pixels[2];\
+\
+ block[0]= (a1+a0)>>2; /* FIXME non put */\
+ block[1]= (b1+b0)>>2;\
+\
+ pixels+=line_size;\
+ block +=line_size;\
+\
+ a0= pixels[0];\
+ b0= pixels[1] + 2;\
+ a0 += b0;\
+ b0 += pixels[2];\
+\
+ block[0]= (a1+a0)>>2;\
+ block[1]= (b1+b0)>>2;\
+ pixels+=line_size;\
+ block +=line_size;\
+ }\
+}\
+\
+static inline void OPNAME ## _pixels4_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
+{\
+ int i;\
+ const uint32_t a= LD32(pixels );\
+ const uint32_t b= LD32(pixels+1);\
+ uint32_t l0= (a&0x03030303UL)\
+ + (b&0x03030303UL)\
+ + 0x02020202UL;\
+ uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
+ + ((b&0xFCFCFCFCUL)>>2);\
+ uint32_t l1,h1;\
+\
+ pixels+=line_size;\
+ for(i=0; i<h; i+=2){\
+ uint32_t a= LD32(pixels );\
+ uint32_t b= LD32(pixels+1);\
+ l1= (a&0x03030303UL)\
+ + (b&0x03030303UL);\
+ h1= ((a&0xFCFCFCFCUL)>>2)\
+ + ((b&0xFCFCFCFCUL)>>2);\
+ OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
+ pixels+=line_size;\
+ block +=line_size;\
+ a= LD32(pixels );\
+ b= LD32(pixels+1);\
+ l0= (a&0x03030303UL)\
+ + (b&0x03030303UL)\
+ + 0x02020202UL;\
+ h0= ((a&0xFCFCFCFCUL)>>2)\
+ + ((b&0xFCFCFCFCUL)>>2);\
+ OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
+ pixels+=line_size;\
+ block +=line_size;\
+ }\
+}\
+\
+static inline void OPNAME ## _pixels8_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
+{\
+ int j;\
+ for(j=0; j<2; j++){\
+ int i;\
+ const uint32_t a= LD32(pixels );\
+ const uint32_t b= LD32(pixels+1);\
+ uint32_t l0= (a&0x03030303UL)\
+ + (b&0x03030303UL)\
+ + 0x02020202UL;\
+ uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
+ + ((b&0xFCFCFCFCUL)>>2);\
+ uint32_t l1,h1;\
+\
+ pixels+=line_size;\
+ for(i=0; i<h; i+=2){\
+ uint32_t a= LD32(pixels );\
+ uint32_t b= LD32(pixels+1);\
+ l1= (a&0x03030303UL)\
+ + (b&0x03030303UL);\
+ h1= ((a&0xFCFCFCFCUL)>>2)\
+ + ((b&0xFCFCFCFCUL)>>2);\
+ OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
+ pixels+=line_size;\
+ block +=line_size;\
+ a= LD32(pixels );\
+ b= LD32(pixels+1);\
+ l0= (a&0x03030303UL)\
+ + (b&0x03030303UL)\
+ + 0x02020202UL;\
+ h0= ((a&0xFCFCFCFCUL)>>2)\
+ + ((b&0xFCFCFCFCUL)>>2);\
+ OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
+ pixels+=line_size;\
+ block +=line_size;\
+ }\
+ pixels+=4-line_size*(h+1);\
+ block +=4-line_size*h;\
+ }\
+}\
+\
+static inline void OPNAME ## _no_rnd_pixels8_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
+{\
+ int j;\
+ for(j=0; j<2; j++){\
+ int i;\
+ const uint32_t a= LD32(pixels );\
+ const uint32_t b= LD32(pixels+1);\
+ uint32_t l0= (a&0x03030303UL)\
+ + (b&0x03030303UL)\
+ + 0x01010101UL;\
+ uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
+ + ((b&0xFCFCFCFCUL)>>2);\
+ uint32_t l1,h1;\
+\
+ pixels+=line_size;\
+ for(i=0; i<h; i+=2){\
+ uint32_t a= LD32(pixels );\
+ uint32_t b= LD32(pixels+1);\
+ l1= (a&0x03030303UL)\
+ + (b&0x03030303UL);\
+ h1= ((a&0xFCFCFCFCUL)>>2)\
+ + ((b&0xFCFCFCFCUL)>>2);\
+ OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
+ pixels+=line_size;\
+ block +=line_size;\
+ a= LD32(pixels );\
+ b= LD32(pixels+1);\
+ l0= (a&0x03030303UL)\
+ + (b&0x03030303UL)\
+ + 0x01010101UL;\
+ h0= ((a&0xFCFCFCFCUL)>>2)\
+ + ((b&0xFCFCFCFCUL)>>2);\
+ OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
+ pixels+=line_size;\
+ block +=line_size;\
+ }\
+ pixels+=4-line_size*(h+1);\
+ block +=4-line_size*h;\
+ }\
+}\
+\
+CALL_2X_PIXELS(OPNAME ## _pixels16_c , OPNAME ## _pixels8_c , 8)\
+CALL_2X_PIXELS(OPNAME ## _pixels16_x2_c , OPNAME ## _pixels8_x2_c , 8)\
+CALL_2X_PIXELS(OPNAME ## _pixels16_y2_c , OPNAME ## _pixels8_y2_c , 8)\
+CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_c, OPNAME ## _pixels8_xy2_c, 8)\
+CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_c , OPNAME ## _pixels8_c , 8)\
+CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2_c , OPNAME ## _no_rnd_pixels8_x2_c , 8)\
+CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2_c , OPNAME ## _no_rnd_pixels8_y2_c , 8)\
+CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_c, OPNAME ## _no_rnd_pixels8_xy2_c, 8)\
+
+#define op_avg(a, b) a = rnd_avg32(a, b)
+#endif
+#define op_put(a, b) a = b
+
+PIXOP2(avg, op_avg)
+PIXOP2(put, op_put)
+#undef op_avg
+#undef op_put
+
+#define avg2(a,b) ((a+b+1)>>1)
+#define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
+
+static void put_no_rnd_pixels16_l2_c(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h){
+ put_no_rnd_pixels16_l2(dst, a, b, stride, stride, stride, h);
+}
+
+static void put_no_rnd_pixels8_l2_c(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h){
+ put_no_rnd_pixels8_l2(dst, a, b, stride, stride, stride, h);
+}
+
+static void gmc1_c(uint8_t *dst, uint8_t *src, int stride, int h, int x16, int y16, int rounder)
+{
+ const int A=(16-x16)*(16-y16);
+ const int B=( x16)*(16-y16);
+ const int C=(16-x16)*( y16);
+ const int D=( x16)*( y16);
+ int i;
+
+ for(i=0; i<h; i++)
+ {
+ dst[0]= (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + rounder)>>8;
+ dst[1]= (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + rounder)>>8;
+ dst[2]= (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + rounder)>>8;
+ dst[3]= (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + rounder)>>8;
+ dst[4]= (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + rounder)>>8;
+ dst[5]= (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + rounder)>>8;
+ dst[6]= (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + rounder)>>8;
+ dst[7]= (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + rounder)>>8;
+ dst+= stride;
+ src+= stride;
+ }
+}
+
+void ff_gmc_c(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)
+{
+ int y, vx, vy;
+ const int s= 1<<shift;
+
+ width--;
+ height--;
+
+ for(y=0; y<h; y++){
+ int x;
+
+ vx= ox;
+ vy= oy;
+ for(x=0; x<8; x++){ //XXX FIXME optimize
+ int src_x, src_y, frac_x, frac_y, index;
+
+ src_x= vx>>16;
+ src_y= vy>>16;
+ frac_x= src_x&(s-1);
+ frac_y= src_y&(s-1);
+ src_x>>=shift;
+ src_y>>=shift;
+
+ if((unsigned)src_x < width){
+ if((unsigned)src_y < height){
+ index= src_x + src_y*stride;
+ dst[y*stride + x]= ( ( src[index ]*(s-frac_x)
+ + src[index +1]* frac_x )*(s-frac_y)
+ + ( src[index+stride ]*(s-frac_x)
+ + src[index+stride+1]* frac_x )* frac_y
+ + r)>>(shift*2);
+ }else{
+ index= src_x + av_clip(src_y, 0, height)*stride;
+ dst[y*stride + x]= ( ( src[index ]*(s-frac_x)
+ + src[index +1]* frac_x )*s
+ + r)>>(shift*2);
+ }
+ }else{
+ if((unsigned)src_y < height){
+ index= av_clip(src_x, 0, width) + src_y*stride;
+ dst[y*stride + x]= ( ( src[index ]*(s-frac_y)
+ + src[index+stride ]* frac_y )*s
+ + r)>>(shift*2);
+ }else{
+ index= av_clip(src_x, 0, width) + av_clip(src_y, 0, height)*stride;
+ dst[y*stride + x]= src[index ];
+ }
+ }
+
+ vx+= dxx;
+ vy+= dyx;
+ }
+ ox += dxy;
+ oy += dyy;
+ }
+}
+
+static inline void put_tpel_pixels_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+ switch(width){
+ case 2: put_pixels2_c (dst, src, stride, height); break;
+ case 4: put_pixels4_c (dst, src, stride, height); break;
+ case 8: put_pixels8_c (dst, src, stride, height); break;
+ case 16:put_pixels16_c(dst, src, stride, height); break;
+ }
+}
+
+static inline void put_tpel_pixels_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+ int i,j;
+ for (i=0; i < height; i++) {
+ for (j=0; j < width; j++) {
+ dst[j] = (683*(2*src[j] + src[j+1] + 1)) >> 11;
+ }
+ src += stride;
+ dst += stride;
+ }
+}
+
+static inline void put_tpel_pixels_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+ int i,j;
+ for (i=0; i < height; i++) {
+ for (j=0; j < width; j++) {
+ dst[j] = (683*(src[j] + 2*src[j+1] + 1)) >> 11;
+ }
+ src += stride;
+ dst += stride;
+ }
+}
+
+static inline void put_tpel_pixels_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+ int i,j;
+ for (i=0; i < height; i++) {
+ for (j=0; j < width; j++) {
+ dst[j] = (683*(2*src[j] + src[j+stride] + 1)) >> 11;
+ }
+ src += stride;
+ dst += stride;
+ }
+}
+
+static inline void put_tpel_pixels_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+ int i,j;
+ for (i=0; i < height; i++) {
+ for (j=0; j < width; j++) {
+ dst[j] = (2731*(4*src[j] + 3*src[j+1] + 3*src[j+stride] + 2*src[j+stride+1] + 6)) >> 15;
+ }
+ src += stride;
+ dst += stride;
+ }
+}
+
+static inline void put_tpel_pixels_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+ int i,j;
+ for (i=0; i < height; i++) {
+ for (j=0; j < width; j++) {
+ dst[j] = (2731*(3*src[j] + 2*src[j+1] + 4*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15;
+ }
+ src += stride;
+ dst += stride;
+ }
+}
+
+static inline void put_tpel_pixels_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+ int i,j;
+ for (i=0; i < height; i++) {
+ for (j=0; j < width; j++) {
+ dst[j] = (683*(src[j] + 2*src[j+stride] + 1)) >> 11;
+ }
+ src += stride;
+ dst += stride;
+ }
+}
+
+static inline void put_tpel_pixels_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+ int i,j;
+ for (i=0; i < height; i++) {
+ for (j=0; j < width; j++) {
+ dst[j] = (2731*(3*src[j] + 4*src[j+1] + 2*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15;
+ }
+ src += stride;
+ dst += stride;
+ }
+}
+
+static inline void put_tpel_pixels_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+ int i,j;
+ for (i=0; i < height; i++) {
+ for (j=0; j < width; j++) {
+ dst[j] = (2731*(2*src[j] + 3*src[j+1] + 3*src[j+stride] + 4*src[j+stride+1] + 6)) >> 15;
+ }
+ src += stride;
+ dst += stride;
+ }
+}
+
+static inline void avg_tpel_pixels_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+ switch(width){
+ case 2: avg_pixels2_c (dst, src, stride, height); break;
+ case 4: avg_pixels4_c (dst, src, stride, height); break;
+ case 8: avg_pixels8_c (dst, src, stride, height); break;
+ case 16:avg_pixels16_c(dst, src, stride, height); break;
+ }
+}
+
+static inline void avg_tpel_pixels_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+ int i,j;
+ for (i=0; i < height; i++) {
+ for (j=0; j < width; j++) {
+ dst[j] = (dst[j] + ((683*(2*src[j] + src[j+1] + 1)) >> 11) + 1) >> 1;
+ }
+ src += stride;
+ dst += stride;
+ }
+}
+
+static inline void avg_tpel_pixels_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+ int i,j;
+ for (i=0; i < height; i++) {
+ for (j=0; j < width; j++) {
+ dst[j] = (dst[j] + ((683*(src[j] + 2*src[j+1] + 1)) >> 11) + 1) >> 1;
+ }
+ src += stride;
+ dst += stride;
+ }
+}
+
+static inline void avg_tpel_pixels_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+ int i,j;
+ for (i=0; i < height; i++) {
+ for (j=0; j < width; j++) {
+ dst[j] = (dst[j] + ((683*(2*src[j] + src[j+stride] + 1)) >> 11) + 1) >> 1;
+ }
+ src += stride;
+ dst += stride;
+ }
+}
+
+static inline void avg_tpel_pixels_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+ int i,j;
+ for (i=0; i < height; i++) {
+ for (j=0; j < width; j++) {
+ dst[j] = (dst[j] + ((2731*(4*src[j] + 3*src[j+1] + 3*src[j+stride] + 2*src[j+stride+1] + 6)) >> 15) + 1) >> 1;
+ }
+ src += stride;
+ dst += stride;
+ }
+}
+
+static inline void avg_tpel_pixels_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+ int i,j;
+ for (i=0; i < height; i++) {
+ for (j=0; j < width; j++) {
+ dst[j] = (dst[j] + ((2731*(3*src[j] + 2*src[j+1] + 4*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15) + 1) >> 1;
+ }
+ src += stride;
+ dst += stride;
+ }
+}
+
+static inline void avg_tpel_pixels_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+ int i,j;
+ for (i=0; i < height; i++) {
+ for (j=0; j < width; j++) {
+ dst[j] = (dst[j] + ((683*(src[j] + 2*src[j+stride] + 1)) >> 11) + 1) >> 1;
+ }
+ src += stride;
+ dst += stride;
+ }
+}
+
+static inline void avg_tpel_pixels_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+ int i,j;
+ for (i=0; i < height; i++) {
+ for (j=0; j < width; j++) {
+ dst[j] = (dst[j] + ((2731*(3*src[j] + 4*src[j+1] + 2*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15) + 1) >> 1;
+ }
+ src += stride;
+ dst += stride;
+ }
+}
+
+static inline void avg_tpel_pixels_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
+ int i,j;
+ for (i=0; i < height; i++) {
+ for (j=0; j < width; j++) {
+ dst[j] = (dst[j] + ((2731*(2*src[j] + 3*src[j+1] + 3*src[j+stride] + 4*src[j+stride+1] + 6)) >> 15) + 1) >> 1;
+ }
+ src += stride;
+ dst += stride;
+ }
+}
+#if 0
+#define TPEL_WIDTH(width)\
+static void put_tpel_pixels ## width ## _mc00_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
+ void put_tpel_pixels_mc00_c(dst, src, stride, width, height);}\
+static void put_tpel_pixels ## width ## _mc10_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
+ void put_tpel_pixels_mc10_c(dst, src, stride, width, height);}\
+static void put_tpel_pixels ## width ## _mc20_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
+ void put_tpel_pixels_mc20_c(dst, src, stride, width, height);}\
+static void put_tpel_pixels ## width ## _mc01_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
+ void put_tpel_pixels_mc01_c(dst, src, stride, width, height);}\
+static void put_tpel_pixels ## width ## _mc11_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
+ void put_tpel_pixels_mc11_c(dst, src, stride, width, height);}\
+static void put_tpel_pixels ## width ## _mc21_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
+ void put_tpel_pixels_mc21_c(dst, src, stride, width, height);}\
+static void put_tpel_pixels ## width ## _mc02_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
+ void put_tpel_pixels_mc02_c(dst, src, stride, width, height);}\
+static void put_tpel_pixels ## width ## _mc12_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
+ void put_tpel_pixels_mc12_c(dst, src, stride, width, height);}\
+static void put_tpel_pixels ## width ## _mc22_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
+ void put_tpel_pixels_mc22_c(dst, src, stride, width, height);}
+#endif
+
+#define H264_CHROMA_MC(OPNAME, OP)\
+static void OPNAME ## h264_chroma_mc2_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
+ const int A=(8-x)*(8-y);\
+ const int B=( x)*(8-y);\
+ const int C=(8-x)*( y);\
+ const int D=( x)*( y);\
+ int i;\
+ \
+ assert(x<8 && y<8 && x>=0 && y>=0);\
+\
+ for(i=0; i<h; i++)\
+ {\
+ OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
+ OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
+ dst+= stride;\
+ src+= stride;\
+ }\
+}\
+\
+static void OPNAME ## h264_chroma_mc4_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
+ const int A=(8-x)*(8-y);\
+ const int B=( x)*(8-y);\
+ const int C=(8-x)*( y);\
+ const int D=( x)*( y);\
+ int i;\
+ \
+ assert(x<8 && y<8 && x>=0 && y>=0);\
+\
+ for(i=0; i<h; i++)\
+ {\
+ OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
+ OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
+ OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\
+ OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\
+ dst+= stride;\
+ src+= stride;\
+ }\
+}\
+\
+static void OPNAME ## h264_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
+ const int A=(8-x)*(8-y);\
+ const int B=( x)*(8-y);\
+ const int C=(8-x)*( y);\
+ const int D=( x)*( y);\
+ int i;\
+ \
+ assert(x<8 && y<8 && x>=0 && y>=0);\
+\
+ for(i=0; i<h; i++)\
+ {\
+ OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
+ OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
+ OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\
+ OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\
+ OP(dst[4], (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5]));\
+ OP(dst[5], (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6]));\
+ OP(dst[6], (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7]));\
+ OP(dst[7], (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8]));\
+ dst+= stride;\
+ src+= stride;\
+ }\
+}
+
+#define op_avg(a, b) a = (((a)+(((b) + 32)>>6)+1)>>1)
+#define op_put(a, b) a = (((b) + 32)>>6)
+
+H264_CHROMA_MC(put_ , op_put)
+H264_CHROMA_MC(avg_ , op_avg)
+#undef op_avg
+#undef op_put
+
+static void put_no_rnd_h264_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){
+ const int A=(8-x)*(8-y);
+ const int B=( x)*(8-y);
+ const int C=(8-x)*( y);
+ const int D=( x)*( y);
+ int i;
+
+ assert(x<8 && y<8 && x>=0 && y>=0);
+
+ for(i=0; i<h; i++)
+ {
+ dst[0] = (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + 32 - 4) >> 6;
+ dst[1] = (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6;
+ dst[2] = (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6;
+ dst[3] = (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6;
+ dst[4] = (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + 32 - 4) >> 6;
+ dst[5] = (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + 32 - 4) >> 6;
+ dst[6] = (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + 32 - 4) >> 6;
+ dst[7] = (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + 32 - 4) >> 6;
+ dst+= stride;
+ src+= stride;
+ }
+}
+
+#define QPEL_MC(r, OPNAME, RND, OP) \
+static void OPNAME ## mpeg4_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
+ int i;\
+ for(i=0; i<h; i++)\
+ {\
+ OP(dst[0], (src[0]+src[1])*20 - (src[0]+src[2])*6 + (src[1]+src[3])*3 - (src[2]+src[4]));\
+ OP(dst[1], (src[1]+src[2])*20 - (src[0]+src[3])*6 + (src[0]+src[4])*3 - (src[1]+src[5]));\
+ OP(dst[2], (src[2]+src[3])*20 - (src[1]+src[4])*6 + (src[0]+src[5])*3 - (src[0]+src[6]));\
+ OP(dst[3], (src[3]+src[4])*20 - (src[2]+src[5])*6 + (src[1]+src[6])*3 - (src[0]+src[7]));\
+ OP(dst[4], (src[4]+src[5])*20 - (src[3]+src[6])*6 + (src[2]+src[7])*3 - (src[1]+src[8]));\
+ OP(dst[5], (src[5]+src[6])*20 - (src[4]+src[7])*6 + (src[3]+src[8])*3 - (src[2]+src[8]));\
+ OP(dst[6], (src[6]+src[7])*20 - (src[5]+src[8])*6 + (src[4]+src[8])*3 - (src[3]+src[7]));\
+ OP(dst[7], (src[7]+src[8])*20 - (src[6]+src[8])*6 + (src[5]+src[7])*3 - (src[4]+src[6]));\
+ dst+=dstStride;\
+ src+=srcStride;\
+ }\
+}\
+\
+static void OPNAME ## mpeg4_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ const int w=8;\
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
+ int i;\
+ for(i=0; i<w; i++)\
+ {\
+ const int src0= src[0*srcStride];\
+ const int src1= src[1*srcStride];\
+ const int src2= src[2*srcStride];\
+ const int src3= src[3*srcStride];\
+ const int src4= src[4*srcStride];\
+ const int src5= src[5*srcStride];\
+ const int src6= src[6*srcStride];\
+ const int src7= src[7*srcStride];\
+ const int src8= src[8*srcStride];\
+ OP(dst[0*dstStride], (src0+src1)*20 - (src0+src2)*6 + (src1+src3)*3 - (src2+src4));\
+ OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*6 + (src0+src4)*3 - (src1+src5));\
+ OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*6 + (src0+src5)*3 - (src0+src6));\
+ OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*6 + (src1+src6)*3 - (src0+src7));\
+ OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*6 + (src2+src7)*3 - (src1+src8));\
+ OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*6 + (src3+src8)*3 - (src2+src8));\
+ OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*6 + (src4+src8)*3 - (src3+src7));\
+ OP(dst[7*dstStride], (src7+src8)*20 - (src6+src8)*6 + (src5+src7)*3 - (src4+src6));\
+ dst++;\
+ src++;\
+ }\
+}\
+\
+static void OPNAME ## mpeg4_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
+ int i;\
+ \
+ for(i=0; i<h; i++)\
+ {\
+ OP(dst[ 0], (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]));\
+ OP(dst[ 1], (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]));\
+ OP(dst[ 2], (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]));\
+ OP(dst[ 3], (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]));\
+ OP(dst[ 4], (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]));\
+ OP(dst[ 5], (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]));\
+ OP(dst[ 6], (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]));\
+ OP(dst[ 7], (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]));\
+ OP(dst[ 8], (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]));\
+ OP(dst[ 9], (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]));\
+ OP(dst[10], (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]));\
+ OP(dst[11], (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]));\
+ OP(dst[12], (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]));\
+ OP(dst[13], (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]));\
+ OP(dst[14], (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]));\
+ OP(dst[15], (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]));\
+ dst+=dstStride;\
+ src+=srcStride;\
+ }\
+}\
+\
+static void OPNAME ## mpeg4_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
+ int i;\
+ const int w=16;\
+ for(i=0; i<w; i++)\
+ {\
+ const int src0= src[0*srcStride];\
+ const int src1= src[1*srcStride];\
+ const int src2= src[2*srcStride];\
+ const int src3= src[3*srcStride];\
+ const int src4= src[4*srcStride];\
+ const int src5= src[5*srcStride];\
+ const int src6= src[6*srcStride];\
+ const int src7= src[7*srcStride];\
+ const int src8= src[8*srcStride];\
+ const int src9= src[9*srcStride];\
+ const int src10= src[10*srcStride];\
+ const int src11= src[11*srcStride];\
+ const int src12= src[12*srcStride];\
+ const int src13= src[13*srcStride];\
+ const int src14= src[14*srcStride];\
+ const int src15= src[15*srcStride];\
+ const int src16= src[16*srcStride];\
+ OP(dst[ 0*dstStride], (src0 +src1 )*20 - (src0 +src2 )*6 + (src1 +src3 )*3 - (src2 +src4 ));\
+ OP(dst[ 1*dstStride], (src1 +src2 )*20 - (src0 +src3 )*6 + (src0 +src4 )*3 - (src1 +src5 ));\
+ OP(dst[ 2*dstStride], (src2 +src3 )*20 - (src1 +src4 )*6 + (src0 +src5 )*3 - (src0 +src6 ));\
+ OP(dst[ 3*dstStride], (src3 +src4 )*20 - (src2 +src5 )*6 + (src1 +src6 )*3 - (src0 +src7 ));\
+ OP(dst[ 4*dstStride], (src4 +src5 )*20 - (src3 +src6 )*6 + (src2 +src7 )*3 - (src1 +src8 ));\
+ OP(dst[ 5*dstStride], (src5 +src6 )*20 - (src4 +src7 )*6 + (src3 +src8 )*3 - (src2 +src9 ));\
+ OP(dst[ 6*dstStride], (src6 +src7 )*20 - (src5 +src8 )*6 + (src4 +src9 )*3 - (src3 +src10));\
+ OP(dst[ 7*dstStride], (src7 +src8 )*20 - (src6 +src9 )*6 + (src5 +src10)*3 - (src4 +src11));\
+ OP(dst[ 8*dstStride], (src8 +src9 )*20 - (src7 +src10)*6 + (src6 +src11)*3 - (src5 +src12));\
+ OP(dst[ 9*dstStride], (src9 +src10)*20 - (src8 +src11)*6 + (src7 +src12)*3 - (src6 +src13));\
+ OP(dst[10*dstStride], (src10+src11)*20 - (src9 +src12)*6 + (src8 +src13)*3 - (src7 +src14));\
+ OP(dst[11*dstStride], (src11+src12)*20 - (src10+src13)*6 + (src9 +src14)*3 - (src8 +src15));\
+ OP(dst[12*dstStride], (src12+src13)*20 - (src11+src14)*6 + (src10+src15)*3 - (src9 +src16));\
+ OP(dst[13*dstStride], (src13+src14)*20 - (src12+src15)*6 + (src11+src16)*3 - (src10+src16));\
+ OP(dst[14*dstStride], (src14+src15)*20 - (src13+src16)*6 + (src12+src16)*3 - (src11+src15));\
+ OP(dst[15*dstStride], (src15+src16)*20 - (src14+src16)*6 + (src13+src15)*3 - (src12+src14));\
+ dst++;\
+ src++;\
+ }\
+}\
+\
+static void OPNAME ## qpel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## pixels8_c(dst, src, stride, 8);\
+}\
+\
+static void OPNAME ## qpel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t half[64];\
+ put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
+ OPNAME ## pixels8_l2(dst, src, half, stride, stride, 8, 8);\
+}\
+\
+static void OPNAME ## qpel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## mpeg4_qpel8_h_lowpass(dst, src, stride, stride, 8);\
+}\
+\
+static void OPNAME ## qpel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t half[64];\
+ put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
+ OPNAME ## pixels8_l2(dst, src+1, half, stride, stride, 8, 8);\
+}\
+\
+static void OPNAME ## qpel8_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[16*9];\
+ uint8_t half[64];\
+ copy_block9(full, src, 16, stride, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
+ OPNAME ## pixels8_l2(dst, full, half, stride, 16, 8, 8);\
+}\
+\
+static void OPNAME ## qpel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[16*9];\
+ copy_block9(full, src, 16, stride, 9);\
+ OPNAME ## mpeg4_qpel8_v_lowpass(dst, full, stride, 16);\
+}\
+\
+static void OPNAME ## qpel8_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[16*9];\
+ uint8_t half[64];\
+ copy_block9(full, src, 16, stride, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
+ OPNAME ## pixels8_l2(dst, full+16, half, stride, 16, 8, 8);\
+}\
+void ff_ ## OPNAME ## qpel8_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[16*9];\
+ uint8_t halfH[72];\
+ uint8_t halfV[64];\
+ uint8_t halfHV[64];\
+ copy_block9(full, src, 16, stride, 9);\
+ put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+ OPNAME ## pixels8_l4(dst, full, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
+}\
+static void OPNAME ## qpel8_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[16*9];\
+ uint8_t halfH[72];\
+ uint8_t halfHV[64];\
+ copy_block9(full, src, 16, stride, 9);\
+ put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+ put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+ OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
+}\
+void ff_ ## OPNAME ## qpel8_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[16*9];\
+ uint8_t halfH[72];\
+ uint8_t halfV[64];\
+ uint8_t halfHV[64];\
+ copy_block9(full, src, 16, stride, 9);\
+ put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+ OPNAME ## pixels8_l4(dst, full+1, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
+}\
+static void OPNAME ## qpel8_mc31_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[16*9];\
+ uint8_t halfH[72];\
+ uint8_t halfHV[64];\
+ copy_block9(full, src, 16, stride, 9);\
+ put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+ put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+ OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
+}\
+void ff_ ## OPNAME ## qpel8_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[16*9];\
+ uint8_t halfH[72];\
+ uint8_t halfV[64];\
+ uint8_t halfHV[64];\
+ copy_block9(full, src, 16, stride, 9);\
+ put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+ OPNAME ## pixels8_l4(dst, full+16, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
+}\
+static void OPNAME ## qpel8_mc13_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[16*9];\
+ uint8_t halfH[72];\
+ uint8_t halfHV[64];\
+ copy_block9(full, src, 16, stride, 9);\
+ put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+ put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+ OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
+}\
+void ff_ ## OPNAME ## qpel8_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[16*9];\
+ uint8_t halfH[72];\
+ uint8_t halfV[64];\
+ uint8_t halfHV[64];\
+ copy_block9(full, src, 16, stride, 9);\
+ put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full , 8, 16, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+ OPNAME ## pixels8_l4(dst, full+17, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
+}\
+static void OPNAME ## qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[16*9];\
+ uint8_t halfH[72];\
+ uint8_t halfHV[64];\
+ copy_block9(full, src, 16, stride, 9);\
+ put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+ put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+ OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
+}\
+static void OPNAME ## qpel8_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t halfH[72];\
+ uint8_t halfHV[64];\
+ put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+ OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
+}\
+static void OPNAME ## qpel8_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t halfH[72];\
+ uint8_t halfHV[64];\
+ put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+ OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
+}\
+void ff_ ## OPNAME ## qpel8_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[16*9];\
+ uint8_t halfH[72];\
+ uint8_t halfV[64];\
+ uint8_t halfHV[64];\
+ copy_block9(full, src, 16, stride, 9);\
+ put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+ OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\
+}\
+static void OPNAME ## qpel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[16*9];\
+ uint8_t halfH[72];\
+ copy_block9(full, src, 16, stride, 9);\
+ put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+ put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
+ OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
+}\
+void ff_ ## OPNAME ## qpel8_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[16*9];\
+ uint8_t halfH[72];\
+ uint8_t halfV[64];\
+ uint8_t halfHV[64];\
+ copy_block9(full, src, 16, stride, 9);\
+ put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+ OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\
+}\
+static void OPNAME ## qpel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[16*9];\
+ uint8_t halfH[72];\
+ copy_block9(full, src, 16, stride, 9);\
+ put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+ put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
+ OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
+}\
+static void OPNAME ## qpel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t halfH[72];\
+ put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
+ OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
+}\
+static void OPNAME ## qpel16_mc00_c (uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## pixels16_c(dst, src, stride, 16);\
+}\
+\
+static void OPNAME ## qpel16_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t half[256];\
+ put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
+ OPNAME ## pixels16_l2(dst, src, half, stride, stride, 16, 16);\
+}\
+\
+static void OPNAME ## qpel16_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## mpeg4_qpel16_h_lowpass(dst, src, stride, stride, 16);\
+}\
+\
+static void OPNAME ## qpel16_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t half[256];\
+ put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
+ OPNAME ## pixels16_l2(dst, src+1, half, stride, stride, 16, 16);\
+}\
+\
+static void OPNAME ## qpel16_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[24*17];\
+ uint8_t half[256];\
+ copy_block17(full, src, 24, stride, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
+ OPNAME ## pixels16_l2(dst, full, half, stride, 24, 16, 16);\
+}\
+\
+static void OPNAME ## qpel16_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[24*17];\
+ copy_block17(full, src, 24, stride, 17);\
+ OPNAME ## mpeg4_qpel16_v_lowpass(dst, full, stride, 24);\
+}\
+\
+static void OPNAME ## qpel16_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[24*17];\
+ uint8_t half[256];\
+ copy_block17(full, src, 24, stride, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
+ OPNAME ## pixels16_l2(dst, full+24, half, stride, 24, 16, 16);\
+}\
+void ff_ ## OPNAME ## qpel16_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[24*17];\
+ uint8_t halfH[272];\
+ uint8_t halfV[256];\
+ uint8_t halfHV[256];\
+ copy_block17(full, src, 24, stride, 17);\
+ put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+ OPNAME ## pixels16_l4(dst, full, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
+}\
+static void OPNAME ## qpel16_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[24*17];\
+ uint8_t halfH[272];\
+ uint8_t halfHV[256];\
+ copy_block17(full, src, 24, stride, 17);\
+ put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+ put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+ OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
+}\
+void ff_ ## OPNAME ## qpel16_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[24*17];\
+ uint8_t halfH[272];\
+ uint8_t halfV[256];\
+ uint8_t halfHV[256];\
+ copy_block17(full, src, 24, stride, 17);\
+ put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+ OPNAME ## pixels16_l4(dst, full+1, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
+}\
+static void OPNAME ## qpel16_mc31_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[24*17];\
+ uint8_t halfH[272];\
+ uint8_t halfHV[256];\
+ copy_block17(full, src, 24, stride, 17);\
+ put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+ put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+ OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
+}\
+void ff_ ## OPNAME ## qpel16_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[24*17];\
+ uint8_t halfH[272];\
+ uint8_t halfV[256];\
+ uint8_t halfHV[256];\
+ copy_block17(full, src, 24, stride, 17);\
+ put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+ OPNAME ## pixels16_l4(dst, full+24, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
+}\
+static void OPNAME ## qpel16_mc13_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[24*17];\
+ uint8_t halfH[272];\
+ uint8_t halfHV[256];\
+ copy_block17(full, src, 24, stride, 17);\
+ put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+ put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+ OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
+}\
+void ff_ ## OPNAME ## qpel16_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[24*17];\
+ uint8_t halfH[272];\
+ uint8_t halfV[256];\
+ uint8_t halfHV[256];\
+ copy_block17(full, src, 24, stride, 17);\
+ put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full , 16, 24, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+ OPNAME ## pixels16_l4(dst, full+25, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
+}\
+static void OPNAME ## qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[24*17];\
+ uint8_t halfH[272];\
+ uint8_t halfHV[256];\
+ copy_block17(full, src, 24, stride, 17);\
+ put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+ put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+ OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
+}\
+static void OPNAME ## qpel16_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t halfH[272];\
+ uint8_t halfHV[256];\
+ put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+ OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
+}\
+static void OPNAME ## qpel16_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t halfH[272];\
+ uint8_t halfHV[256];\
+ put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+ OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
+}\
+void ff_ ## OPNAME ## qpel16_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[24*17];\
+ uint8_t halfH[272];\
+ uint8_t halfV[256];\
+ uint8_t halfHV[256];\
+ copy_block17(full, src, 24, stride, 17);\
+ put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+ OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\
+}\
+static void OPNAME ## qpel16_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[24*17];\
+ uint8_t halfH[272];\
+ copy_block17(full, src, 24, stride, 17);\
+ put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+ put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
+ OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
+}\
+void ff_ ## OPNAME ## qpel16_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[24*17];\
+ uint8_t halfH[272];\
+ uint8_t halfV[256];\
+ uint8_t halfHV[256];\
+ copy_block17(full, src, 24, stride, 17);\
+ put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+ OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\
+}\
+static void OPNAME ## qpel16_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[24*17];\
+ uint8_t halfH[272];\
+ copy_block17(full, src, 24, stride, 17);\
+ put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+ put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
+ OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
+}\
+static void OPNAME ## qpel16_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t halfH[272];\
+ put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
+ OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
+}
+
+#define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
+#define op_avg_no_rnd(a, b) a = (((a)+cm[((b) + 15)>>5])>>1)
+#define op_put(a, b) a = cm[((b) + 16)>>5]
+#define op_put_no_rnd(a, b) a = cm[((b) + 15)>>5]
+
+QPEL_MC(0, put_ , _ , op_put)
+QPEL_MC(1, put_no_rnd_, _no_rnd_, op_put_no_rnd)
+QPEL_MC(0, avg_ , _ , op_avg)
+//QPEL_MC(1, avg_no_rnd , _ , op_avg)
+#undef op_avg
+#undef op_avg_no_rnd
+#undef op_put
+#undef op_put_no_rnd
+
+#if 1
+#define H264_LOWPASS(OPNAME, OP, OP2) \
+static void OPNAME ## h264_qpel2_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ const int h=2;\
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
+ int i;\
+ for(i=0; i<h; i++)\
+ {\
+ OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\
+ OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]));\
+ dst+=dstStride;\
+ src+=srcStride;\
+ }\
+}\
+\
+static void OPNAME ## h264_qpel2_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ const int w=2;\
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
+ int i;\
+ for(i=0; i<w; i++)\
+ {\
+ const int srcB= src[-2*srcStride];\
+ const int srcA= src[-1*srcStride];\
+ const int src0= src[0 *srcStride];\
+ const int src1= src[1 *srcStride];\
+ const int src2= src[2 *srcStride];\
+ const int src3= src[3 *srcStride];\
+ const int src4= src[4 *srcStride];\
+ OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
+ OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
+ dst++;\
+ src++;\
+ }\
+}\
+\
+static void OPNAME ## h264_qpel2_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
+ const int h=2;\
+ const int w=2;\
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
+ int i;\
+ src -= 2*srcStride;\
+ for(i=0; i<h+5; i++)\
+ {\
+ tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]);\
+ tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]);\
+ tmp+=tmpStride;\
+ src+=srcStride;\
+ }\
+ tmp -= tmpStride*(h+5-2);\
+ for(i=0; i<w; i++)\
+ {\
+ const int tmpB= tmp[-2*tmpStride];\
+ const int tmpA= tmp[-1*tmpStride];\
+ const int tmp0= tmp[0 *tmpStride];\
+ const int tmp1= tmp[1 *tmpStride];\
+ const int tmp2= tmp[2 *tmpStride];\
+ const int tmp3= tmp[3 *tmpStride];\
+ const int tmp4= tmp[4 *tmpStride];\
+ OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
+ OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
+ dst++;\
+ tmp++;\
+ }\
+}\
+static void OPNAME ## h264_qpel4_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ const int h=4;\
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
+ int i;\
+ for(i=0; i<h; i++)\
+ {\
+ OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\
+ OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]));\
+ OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]));\
+ OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]));\
+ dst+=dstStride;\
+ src+=srcStride;\
+ }\
+}\
+\
+static void OPNAME ## h264_qpel4_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ const int w=4;\
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
+ int i;\
+ for(i=0; i<w; i++)\
+ {\
+ const int srcB= src[-2*srcStride];\
+ const int srcA= src[-1*srcStride];\
+ const int src0= src[0 *srcStride];\
+ const int src1= src[1 *srcStride];\
+ const int src2= src[2 *srcStride];\
+ const int src3= src[3 *srcStride];\
+ const int src4= src[4 *srcStride];\
+ const int src5= src[5 *srcStride];\
+ const int src6= src[6 *srcStride];\
+ OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
+ OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
+ OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
+ OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
+ dst++;\
+ src++;\
+ }\
+}\
+\
+static void OPNAME ## h264_qpel4_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
+ const int h=4;\
+ const int w=4;\
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
+ int i;\
+ src -= 2*srcStride;\
+ for(i=0; i<h+5; i++)\
+ {\
+ tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]);\
+ tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]);\
+ tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]);\
+ tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]);\
+ tmp+=tmpStride;\
+ src+=srcStride;\
+ }\
+ tmp -= tmpStride*(h+5-2);\
+ for(i=0; i<w; i++)\
+ {\
+ const int tmpB= tmp[-2*tmpStride];\
+ const int tmpA= tmp[-1*tmpStride];\
+ const int tmp0= tmp[0 *tmpStride];\
+ const int tmp1= tmp[1 *tmpStride];\
+ const int tmp2= tmp[2 *tmpStride];\
+ const int tmp3= tmp[3 *tmpStride];\
+ const int tmp4= tmp[4 *tmpStride];\
+ const int tmp5= tmp[5 *tmpStride];\
+ const int tmp6= tmp[6 *tmpStride];\
+ OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
+ OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
+ OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
+ OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
+ dst++;\
+ tmp++;\
+ }\
+}\
+\
+static void OPNAME ## h264_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ const int h=8;\
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
+ int i;\
+ for(i=0; i<h; i++)\
+ {\
+ OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]));\
+ OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]));\
+ OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]));\
+ OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]));\
+ OP(dst[4], (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]));\
+ OP(dst[5], (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]));\
+ OP(dst[6], (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]));\
+ OP(dst[7], (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]));\
+ dst+=dstStride;\
+ src+=srcStride;\
+ }\
+}\
+\
+static void OPNAME ## h264_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ const int w=8;\
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
+ int i;\
+ for(i=0; i<w; i++)\
+ {\
+ const int srcB= src[-2*srcStride];\
+ const int srcA= src[-1*srcStride];\
+ const int src0= src[0 *srcStride];\
+ const int src1= src[1 *srcStride];\
+ const int src2= src[2 *srcStride];\
+ const int src3= src[3 *srcStride];\
+ const int src4= src[4 *srcStride];\
+ const int src5= src[5 *srcStride];\
+ const int src6= src[6 *srcStride];\
+ const int src7= src[7 *srcStride];\
+ const int src8= src[8 *srcStride];\
+ const int src9= src[9 *srcStride];\
+ const int src10=src[10*srcStride];\
+ OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
+ OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
+ OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
+ OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
+ OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*5 + (src2+src7));\
+ OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*5 + (src3+src8));\
+ OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*5 + (src4+src9));\
+ OP(dst[7*dstStride], (src7+src8)*20 - (src6+src9)*5 + (src5+src10));\
+ dst++;\
+ src++;\
+ }\
+}\
+\
+static void OPNAME ## h264_qpel8_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
+ const int h=8;\
+ const int w=8;\
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
+ int i;\
+ src -= 2*srcStride;\
+ for(i=0; i<h+5; i++)\
+ {\
+ tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]);\
+ tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]);\
+ tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]);\
+ tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]);\
+ tmp[4]= (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]);\
+ tmp[5]= (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]);\
+ tmp[6]= (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]);\
+ tmp[7]= (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]);\
+ tmp+=tmpStride;\
+ src+=srcStride;\
+ }\
+ tmp -= tmpStride*(h+5-2);\
+ for(i=0; i<w; i++)\
+ {\
+ const int tmpB= tmp[-2*tmpStride];\
+ const int tmpA= tmp[-1*tmpStride];\
+ const int tmp0= tmp[0 *tmpStride];\
+ const int tmp1= tmp[1 *tmpStride];\
+ const int tmp2= tmp[2 *tmpStride];\
+ const int tmp3= tmp[3 *tmpStride];\
+ const int tmp4= tmp[4 *tmpStride];\
+ const int tmp5= tmp[5 *tmpStride];\
+ const int tmp6= tmp[6 *tmpStride];\
+ const int tmp7= tmp[7 *tmpStride];\
+ const int tmp8= tmp[8 *tmpStride];\
+ const int tmp9= tmp[9 *tmpStride];\
+ const int tmp10=tmp[10*tmpStride];\
+ OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
+ OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
+ OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
+ OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
+ OP2(dst[4*dstStride], (tmp4+tmp5)*20 - (tmp3+tmp6)*5 + (tmp2+tmp7));\
+ OP2(dst[5*dstStride], (tmp5+tmp6)*20 - (tmp4+tmp7)*5 + (tmp3+tmp8));\
+ OP2(dst[6*dstStride], (tmp6+tmp7)*20 - (tmp5+tmp8)*5 + (tmp4+tmp9));\
+ OP2(dst[7*dstStride], (tmp7+tmp8)*20 - (tmp6+tmp9)*5 + (tmp5+tmp10));\
+ dst++;\
+ tmp++;\
+ }\
+}\
+\
+static void OPNAME ## h264_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ OPNAME ## h264_qpel8_v_lowpass(dst , src , dstStride, srcStride);\
+ OPNAME ## h264_qpel8_v_lowpass(dst+8, src+8, dstStride, srcStride);\
+ src += 8*srcStride;\
+ dst += 8*dstStride;\
+ OPNAME ## h264_qpel8_v_lowpass(dst , src , dstStride, srcStride);\
+ OPNAME ## h264_qpel8_v_lowpass(dst+8, src+8, dstStride, srcStride);\
+}\
+\
+static void OPNAME ## h264_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ OPNAME ## h264_qpel8_h_lowpass(dst , src , dstStride, srcStride);\
+ OPNAME ## h264_qpel8_h_lowpass(dst+8, src+8, dstStride, srcStride);\
+ src += 8*srcStride;\
+ dst += 8*dstStride;\
+ OPNAME ## h264_qpel8_h_lowpass(dst , src , dstStride, srcStride);\
+ OPNAME ## h264_qpel8_h_lowpass(dst+8, src+8, dstStride, srcStride);\
+}\
+\
+static void OPNAME ## h264_qpel16_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
+ OPNAME ## h264_qpel8_hv_lowpass(dst , tmp , src , dstStride, tmpStride, srcStride);\
+ OPNAME ## h264_qpel8_hv_lowpass(dst+8, tmp+8, src+8, dstStride, tmpStride, srcStride);\
+ src += 8*srcStride;\
+ dst += 8*dstStride;\
+ OPNAME ## h264_qpel8_hv_lowpass(dst , tmp , src , dstStride, tmpStride, srcStride);\
+ OPNAME ## h264_qpel8_hv_lowpass(dst+8, tmp+8, src+8, dstStride, tmpStride, srcStride);\
+}\
+
+#define H264_MC(OPNAME, SIZE) \
+static void OPNAME ## h264_qpel ## SIZE ## _mc00_c (uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## pixels ## SIZE ## _c(dst, src, stride, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc10_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t half[SIZE*SIZE];\
+ put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\
+ OPNAME ## pixels ## SIZE ## _l2(dst, src, half, stride, stride, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc20_c(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## h264_qpel ## SIZE ## _h_lowpass(dst, src, stride, stride);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc30_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t half[SIZE*SIZE];\
+ put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\
+ OPNAME ## pixels ## SIZE ## _l2(dst, src+1, half, stride, stride, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc01_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[SIZE*(SIZE+5)];\
+ uint8_t * const full_mid= full + SIZE*2;\
+ uint8_t half[SIZE*SIZE];\
+ copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
+ put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\
+ OPNAME ## pixels ## SIZE ## _l2(dst, full_mid, half, stride, SIZE, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc02_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[SIZE*(SIZE+5)];\
+ uint8_t * const full_mid= full + SIZE*2;\
+ copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
+ OPNAME ## h264_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc03_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[SIZE*(SIZE+5)];\
+ uint8_t * const full_mid= full + SIZE*2;\
+ uint8_t half[SIZE*SIZE];\
+ copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
+ put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\
+ OPNAME ## pixels ## SIZE ## _l2(dst, full_mid+SIZE, half, stride, SIZE, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc11_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[SIZE*(SIZE+5)];\
+ uint8_t * const full_mid= full + SIZE*2;\
+ uint8_t halfH[SIZE*SIZE];\
+ uint8_t halfV[SIZE*SIZE];\
+ put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
+ copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
+ put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
+ OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc31_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[SIZE*(SIZE+5)];\
+ uint8_t * const full_mid= full + SIZE*2;\
+ uint8_t halfH[SIZE*SIZE];\
+ uint8_t halfV[SIZE*SIZE];\
+ put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
+ copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
+ put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
+ OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc13_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[SIZE*(SIZE+5)];\
+ uint8_t * const full_mid= full + SIZE*2;\
+ uint8_t halfH[SIZE*SIZE];\
+ uint8_t halfV[SIZE*SIZE];\
+ put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
+ copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
+ put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
+ OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc33_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[SIZE*(SIZE+5)];\
+ uint8_t * const full_mid= full + SIZE*2;\
+ uint8_t halfH[SIZE*SIZE];\
+ uint8_t halfV[SIZE*SIZE];\
+ put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
+ copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
+ put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
+ OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc22_c(uint8_t *dst, uint8_t *src, int stride){\
+ int16_t tmp[SIZE*(SIZE+5)];\
+ OPNAME ## h264_qpel ## SIZE ## _hv_lowpass(dst, tmp, src, stride, SIZE, stride);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc21_c(uint8_t *dst, uint8_t *src, int stride){\
+ int16_t tmp[SIZE*(SIZE+5)];\
+ uint8_t halfH[SIZE*SIZE];\
+ uint8_t halfHV[SIZE*SIZE];\
+ put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
+ put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
+ OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc23_c(uint8_t *dst, uint8_t *src, int stride){\
+ int16_t tmp[SIZE*(SIZE+5)];\
+ uint8_t halfH[SIZE*SIZE];\
+ uint8_t halfHV[SIZE*SIZE];\
+ put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
+ put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
+ OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc12_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[SIZE*(SIZE+5)];\
+ uint8_t * const full_mid= full + SIZE*2;\
+ int16_t tmp[SIZE*(SIZE+5)];\
+ uint8_t halfV[SIZE*SIZE];\
+ uint8_t halfHV[SIZE*SIZE];\
+ copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
+ put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
+ put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
+ OPNAME ## pixels ## SIZE ## _l2(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc32_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[SIZE*(SIZE+5)];\
+ uint8_t * const full_mid= full + SIZE*2;\
+ int16_t tmp[SIZE*(SIZE+5)];\
+ uint8_t halfV[SIZE*SIZE];\
+ uint8_t halfHV[SIZE*SIZE];\
+ copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
+ put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
+ put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
+ OPNAME ## pixels ## SIZE ## _l2(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\
+}\
+
+#define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
+//#define op_avg2(a, b) a = (((a)*w1+cm[((b) + 16)>>5]*w2 + o + 64)>>7)
+#define op_put(a, b) a = cm[((b) + 16)>>5]
+#define op2_avg(a, b) a = (((a)+cm[((b) + 512)>>10]+1)>>1)
+#define op2_put(a, b) a = cm[((b) + 512)>>10]
+
+H264_LOWPASS(put_ , op_put, op2_put)
+H264_LOWPASS(avg_ , op_avg, op2_avg)
+H264_MC(put_, 2)
+H264_MC(put_, 4)
+H264_MC(put_, 8)
+H264_MC(put_, 16)
+H264_MC(avg_, 4)
+H264_MC(avg_, 8)
+H264_MC(avg_, 16)
+
+#undef op_avg
+#undef op_put
+#undef op2_avg
+#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<H; y++, block += stride){ \
+ op_scale1(0); \
+ op_scale1(1); \
+ if(W==2) continue; \
+ op_scale1(2); \
+ op_scale1(3); \
+ if(W==4) continue; \
+ op_scale1(4); \
+ op_scale1(5); \
+ op_scale1(6); \
+ op_scale1(7); \
+ if(W==8) continue; \
+ op_scale1(8); \
+ op_scale1(9); \
+ op_scale1(10); \
+ op_scale1(11); \
+ op_scale1(12); \
+ op_scale1(13); \
+ op_scale1(14); \
+ op_scale1(15); \
+ } \
+} \
+static void biweight_h264_pixels ## W ## x ## H ## _c(uint8_t *dst, uint8_t *src, int stride, int log2_denom, int weightd, int weights, int offset){ \
+ int y; \
+ offset = ((offset + 1) | 1) << log2_denom; \
+ for(y=0; y<H; y++, dst += stride, src += stride){ \
+ op_scale2(0); \
+ op_scale2(1); \
+ if(W==2) continue; \
+ op_scale2(2); \
+ op_scale2(3); \
+ if(W==4) continue; \
+ op_scale2(4); \
+ op_scale2(5); \
+ op_scale2(6); \
+ op_scale2(7); \
+ if(W==8) continue; \
+ op_scale2(8); \
+ op_scale2(9); \
+ op_scale2(10); \
+ op_scale2(11); \
+ op_scale2(12); \
+ op_scale2(13); \
+ op_scale2(14); \
+ op_scale2(15); \
+ } \
+}
+
+H264_WEIGHT(16,16)
+H264_WEIGHT(16,8)
+H264_WEIGHT(8,16)
+H264_WEIGHT(8,8)
+H264_WEIGHT(8,4)
+H264_WEIGHT(4,8)
+H264_WEIGHT(4,4)
+H264_WEIGHT(4,2)
+H264_WEIGHT(2,4)
+H264_WEIGHT(2,2)
+
+#undef op_scale1
+#undef op_scale2
+#undef H264_WEIGHT
+
+static void wmv2_mspel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+ int i;
+
+ for(i=0; i<h; i++){
+ dst[0]= cm[(9*(src[0] + src[1]) - (src[-1] + src[2]) + 8)>>4];
+ dst[1]= cm[(9*(src[1] + src[2]) - (src[ 0] + src[3]) + 8)>>4];
+ dst[2]= cm[(9*(src[2] + src[3]) - (src[ 1] + src[4]) + 8)>>4];
+ dst[3]= cm[(9*(src[3] + src[4]) - (src[ 2] + src[5]) + 8)>>4];
+ dst[4]= cm[(9*(src[4] + src[5]) - (src[ 3] + src[6]) + 8)>>4];
+ dst[5]= cm[(9*(src[5] + src[6]) - (src[ 4] + src[7]) + 8)>>4];
+ dst[6]= cm[(9*(src[6] + src[7]) - (src[ 5] + src[8]) + 8)>>4];
+ dst[7]= cm[(9*(src[7] + src[8]) - (src[ 6] + src[9]) + 8)>>4];
+ dst+=dstStride;
+ src+=srcStride;
+ }
+}
+
+#ifdef CONFIG_CAVS_DECODER
+/* AVS specific */
+void ff_cavsdsp_init(DSPContext* c, AVCodecContext *avctx);
+
+void ff_put_cavs_qpel8_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
+ put_pixels8_c(dst, src, stride, 8);
+}
+void ff_avg_cavs_qpel8_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
+ avg_pixels8_c(dst, src, stride, 8);
+}
+void ff_put_cavs_qpel16_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
+ put_pixels16_c(dst, src, stride, 16);
+}
+void ff_avg_cavs_qpel16_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
+ avg_pixels16_c(dst, src, stride, 16);
+}
+#endif /* CONFIG_CAVS_DECODER */
+
+#if defined(CONFIG_VC1_DECODER) || defined(CONFIG_WMV3_DECODER)
+/* VC-1 specific */
+void ff_vc1dsp_init(DSPContext* c, AVCodecContext *avctx);
+
+void ff_put_vc1_mspel_mc00_c(uint8_t *dst, uint8_t *src, int stride, int rnd) {
+ put_pixels8_c(dst, src, stride, 8);
+}
+#endif /* CONFIG_VC1_DECODER||CONFIG_WMV3_DECODER */
+
+#if defined(CONFIG_H264_ENCODER)
+/* H264 specific */
+void ff_h264dsp_init(DSPContext* c, AVCodecContext *avctx);
+#endif /* CONFIG_H264_ENCODER */
+
+static void wmv2_mspel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int w){
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+ int i;
+
+ for(i=0; i<w; i++){
+ const int src_1= src[ -srcStride];
+ const int src0 = src[0 ];
+ const int src1 = src[ srcStride];
+ const int src2 = src[2*srcStride];
+ const int src3 = src[3*srcStride];
+ const int src4 = src[4*srcStride];
+ const int src5 = src[5*srcStride];
+ const int src6 = src[6*srcStride];
+ const int src7 = src[7*srcStride];
+ const int src8 = src[8*srcStride];
+ const int src9 = src[9*srcStride];
+ dst[0*dstStride]= cm[(9*(src0 + src1) - (src_1 + src2) + 8)>>4];
+ dst[1*dstStride]= cm[(9*(src1 + src2) - (src0 + src3) + 8)>>4];
+ dst[2*dstStride]= cm[(9*(src2 + src3) - (src1 + src4) + 8)>>4];
+ dst[3*dstStride]= cm[(9*(src3 + src4) - (src2 + src5) + 8)>>4];
+ dst[4*dstStride]= cm[(9*(src4 + src5) - (src3 + src6) + 8)>>4];
+ dst[5*dstStride]= cm[(9*(src5 + src6) - (src4 + src7) + 8)>>4];
+ dst[6*dstStride]= cm[(9*(src6 + src7) - (src5 + src8) + 8)>>4];
+ dst[7*dstStride]= cm[(9*(src7 + src8) - (src6 + src9) + 8)>>4];
+ src++;
+ dst++;
+ }
+}
+
+static void put_mspel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){
+ put_pixels8_c(dst, src, stride, 8);
+}
+
+static void put_mspel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){
+ uint8_t half[64];
+ wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
+ put_pixels8_l2(dst, src, half, stride, stride, 8, 8);
+}
+
+static void put_mspel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){
+ wmv2_mspel8_h_lowpass(dst, src, stride, stride, 8);
+}
+
+static void put_mspel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){
+ uint8_t half[64];
+ wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
+ put_pixels8_l2(dst, src+1, half, stride, stride, 8, 8);
+}
+
+static void put_mspel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){
+ wmv2_mspel8_v_lowpass(dst, src, stride, stride, 8);
+}
+
+static void put_mspel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){
+ uint8_t halfH[88];
+ uint8_t halfV[64];
+ uint8_t halfHV[64];
+ wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
+ wmv2_mspel8_v_lowpass(halfV, src, 8, stride, 8);
+ wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
+ put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);
+}
+static void put_mspel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){
+ uint8_t halfH[88];
+ uint8_t halfV[64];
+ uint8_t halfHV[64];
+ wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
+ wmv2_mspel8_v_lowpass(halfV, src+1, 8, stride, 8);
+ wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
+ put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);
+}
+static void put_mspel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){
+ uint8_t halfH[88];
+ wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
+ wmv2_mspel8_v_lowpass(dst, halfH+8, stride, 8, 8);
+}
+
+static void h263_v_loop_filter_c(uint8_t *src, int stride, int qscale){
+ int x;
+ const int strength= ff_h263_loop_filter_strength[qscale];
+
+ for(x=0; x<8; x++){
+ int d1, d2, ad1;
+ int p0= src[x-2*stride];
+ int p1= src[x-1*stride];
+ int p2= src[x+0*stride];
+ int p3= src[x+1*stride];
+ int d = (p0 - p3 + 4*(p2 - p1)) / 8;
+
+ if (d<-2*strength) d1= 0;
+ else if(d<- strength) d1=-2*strength - d;
+ else if(d< strength) d1= d;
+ else if(d< 2*strength) d1= 2*strength - d;
+ else d1= 0;
+
+ p1 += d1;
+ p2 -= d1;
+ if(p1&256) p1= ~(p1>>31);
+ if(p2&256) p2= ~(p2>>31);
+
+ src[x-1*stride] = p1;
+ src[x+0*stride] = p2;
+
+ ad1= FFABS(d1)>>1;
+
+ d2= av_clip((p0-p3)/4, -ad1, ad1);
+
+ src[x-2*stride] = p0 - d2;
+ src[x+ stride] = p3 + d2;
+ }
+}
+
+static void h263_h_loop_filter_c(uint8_t *src, int stride, int qscale){
+ int y;
+ const int strength= ff_h263_loop_filter_strength[qscale];
+
+ for(y=0; y<8; y++){
+ int d1, d2, ad1;
+ int p0= src[y*stride-2];
+ int p1= src[y*stride-1];
+ int p2= src[y*stride+0];
+ int p3= src[y*stride+1];
+ int d = (p0 - p3 + 4*(p2 - p1)) / 8;
+
+ if (d<-2*strength) d1= 0;
+ else if(d<- strength) d1=-2*strength - d;
+ else if(d< strength) d1= d;
+ else if(d< 2*strength) d1= 2*strength - d;
+ else d1= 0;
+
+ p1 += d1;
+ p2 -= d1;
+ if(p1&256) p1= ~(p1>>31);
+ if(p2&256) p2= ~(p2>>31);
+
+ src[y*stride-1] = p1;
+ src[y*stride+0] = p2;
+
+ ad1= FFABS(d1)>>1;
+
+ d2= av_clip((p0-p3)/4, -ad1, ad1);
+
+ src[y*stride-2] = p0 - d2;
+ src[y*stride+1] = p3 + d2;
+ }
+}
+
+static void h261_loop_filter_c(uint8_t *src, int stride){
+ int x,y,xy,yz;
+ int temp[64];
+
+ for(x=0; x<8; x++){
+ temp[x ] = 4*src[x ];
+ temp[x + 7*8] = 4*src[x + 7*stride];
+ }
+ for(y=1; y<7; y++){
+ for(x=0; x<8; x++){
+ xy = y * stride + x;
+ yz = y * 8 + x;
+ temp[yz] = src[xy - stride] + 2*src[xy] + src[xy + stride];
+ }
+ }
+
+ for(y=0; y<8; y++){
+ src[ y*stride] = (temp[ y*8] + 2)>>2;
+ src[7+y*stride] = (temp[7+y*8] + 2)>>2;
+ for(x=1; x<7; x++){
+ xy = y * stride + x;
+ yz = y * 8 + x;
+ src[xy] = (temp[yz-1] + 2*temp[yz] + temp[yz+1] + 8)>>4;
+ }
+ }
+}
+
+static inline void h264_loop_filter_luma_c(uint8_t *pix, int xstride, int ystride, int alpha, int beta, int8_t *tc0)
+{
+ int i, d;
+ for( i = 0; i < 4; i++ ) {
+ if( tc0[i] < 0 ) {
+ pix += 4*ystride;
+ continue;
+ }
+ for( d = 0; d < 4; d++ ) {
+ const int p0 = pix[-1*xstride];
+ const int p1 = pix[-2*xstride];
+ const int p2 = pix[-3*xstride];
+ const int q0 = pix[0];
+ 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 ) {
+
+ int tc = tc0[i];
+ int i_delta;
+
+ if( FFABS( p2 - p0 ) < beta ) {
+ pix[-2*xstride] = p1 + av_clip( (( p2 + ( ( p0 + q0 + 1 ) >> 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_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;
+
+ s = 0;
+ for(i=0;i<h;i++) {
+ s += abs(pix1[0] - pix2[0]);
+ s += abs(pix1[1] - pix2[1]);
+ s += abs(pix1[2] - pix2[2]);
+ s += abs(pix1[3] - pix2[3]);
+ s += abs(pix1[4] - pix2[4]);
+ s += abs(pix1[5] - pix2[5]);
+ s += abs(pix1[6] - pix2[6]);
+ s += abs(pix1[7] - pix2[7]);
+ s += abs(pix1[8] - pix2[8]);
+ s += abs(pix1[9] - pix2[9]);
+ s += abs(pix1[10] - pix2[10]);
+ s += abs(pix1[11] - pix2[11]);
+ s += abs(pix1[12] - pix2[12]);
+ s += abs(pix1[13] - pix2[13]);
+ s += abs(pix1[14] - pix2[14]);
+ s += abs(pix1[15] - pix2[15]);
+ pix1 += line_size;
+ pix2 += line_size;
+ }
+ return s;
+}
+
+static int pix_abs16_x2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
+{
+ int s, i;
+
+ s = 0;
+ for(i=0;i<h;i++) {
+ s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
+ s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
+ s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
+ s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
+ s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
+ s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
+ s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
+ s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
+ s += abs(pix1[8] - avg2(pix2[8], pix2[9]));
+ s += abs(pix1[9] - avg2(pix2[9], pix2[10]));
+ s += abs(pix1[10] - avg2(pix2[10], pix2[11]));
+ s += abs(pix1[11] - avg2(pix2[11], pix2[12]));
+ s += abs(pix1[12] - avg2(pix2[12], pix2[13]));
+ s += abs(pix1[13] - avg2(pix2[13], pix2[14]));
+ s += abs(pix1[14] - avg2(pix2[14], pix2[15]));
+ s += abs(pix1[15] - avg2(pix2[15], pix2[16]));
+ pix1 += line_size;
+ pix2 += line_size;
+ }
+ return s;
+}
+
+static int pix_abs16_y2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
+{
+ int s, i;
+ uint8_t *pix3 = pix2 + line_size;
+
+ s = 0;
+ for(i=0;i<h;i++) {
+ s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
+ s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
+ s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
+ s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
+ s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
+ s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
+ s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
+ s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
+ s += abs(pix1[8] - avg2(pix2[8], pix3[8]));
+ s += abs(pix1[9] - avg2(pix2[9], pix3[9]));
+ s += abs(pix1[10] - avg2(pix2[10], pix3[10]));
+ s += abs(pix1[11] - avg2(pix2[11], pix3[11]));
+ s += abs(pix1[12] - avg2(pix2[12], pix3[12]));
+ s += abs(pix1[13] - avg2(pix2[13], pix3[13]));
+ s += abs(pix1[14] - avg2(pix2[14], pix3[14]));
+ s += abs(pix1[15] - avg2(pix2[15], pix3[15]));
+ pix1 += line_size;
+ pix2 += line_size;
+ pix3 += line_size;
+ }
+ return s;
+}
+
+static int pix_abs16_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
+{
+ int s, i;
+ uint8_t *pix3 = pix2 + line_size;
+
+ s = 0;
+ for(i=0;i<h;i++) {
+ s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
+ s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
+ s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
+ s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
+ s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
+ s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
+ s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
+ s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
+ s += abs(pix1[8] - avg4(pix2[8], pix2[9], pix3[8], pix3[9]));
+ s += abs(pix1[9] - avg4(pix2[9], pix2[10], pix3[9], pix3[10]));
+ s += abs(pix1[10] - avg4(pix2[10], pix2[11], pix3[10], pix3[11]));
+ s += abs(pix1[11] - avg4(pix2[11], pix2[12], pix3[11], pix3[12]));
+ s += abs(pix1[12] - avg4(pix2[12], pix2[13], pix3[12], pix3[13]));
+ s += abs(pix1[13] - avg4(pix2[13], pix2[14], pix3[13], pix3[14]));
+ s += abs(pix1[14] - avg4(pix2[14], pix2[15], pix3[14], pix3[15]));
+ s += abs(pix1[15] - avg4(pix2[15], pix2[16], pix3[15], pix3[16]));
+ pix1 += line_size;
+ pix2 += line_size;
+ pix3 += line_size;
+ }
+ return s;
+}
+
+static inline int pix_abs8_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
+{
+ int s, i;
+
+ s = 0;
+ for(i=0;i<h;i++) {
+ s += abs(pix1[0] - pix2[0]);
+ s += abs(pix1[1] - pix2[1]);
+ s += abs(pix1[2] - pix2[2]);
+ s += abs(pix1[3] - pix2[3]);
+ s += abs(pix1[4] - pix2[4]);
+ s += abs(pix1[5] - pix2[5]);
+ s += abs(pix1[6] - pix2[6]);
+ s += abs(pix1[7] - pix2[7]);
+ pix1 += line_size;
+ pix2 += line_size;
+ }
+ return s;
+}
+
+static int pix_abs8_x2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
+{
+ int s, i;
+
+ s = 0;
+ for(i=0;i<h;i++) {
+ s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
+ s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
+ s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
+ s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
+ s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
+ s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
+ s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
+ s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
+ pix1 += line_size;
+ pix2 += line_size;
+ }
+ return s;
+}
+
+static int pix_abs8_y2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
+{
+ int s, i;
+ uint8_t *pix3 = pix2 + line_size;
+
+ s = 0;
+ for(i=0;i<h;i++) {
+ s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
+ s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
+ s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
+ s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
+ s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
+ s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
+ s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
+ s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
+ pix1 += line_size;
+ pix2 += line_size;
+ pix3 += line_size;
+ }
+ return s;
+}
+
+static int pix_abs8_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
+{
+ int s, i;
+ uint8_t *pix3 = pix2 + line_size;
+
+ s = 0;
+ for(i=0;i<h;i++) {
+ s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
+ s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
+ s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
+ s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
+ s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
+ s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
+ s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
+ s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
+ pix1 += line_size;
+ pix2 += line_size;
+ pix3 += line_size;
+ }
+ return s;
+}
+
+static int nsse16_c(void *v, uint8_t *s1, uint8_t *s2, int stride, int h){
+ MpegEncContext *c = v;
+ int score1=0;
+ int score2=0;
+ int x,y;
+
+ for(y=0; y<h; y++){
+ for(x=0; x<16; x++){
+ score1+= (s1[x ] - s2[x ])*(s1[x ] - s2[x ]);
+ }
+ if(y+1<h){
+ for(x=0; x<15; x++){
+ score2+= FFABS( s1[x ] - s1[x +stride]
+ - s1[x+1] + s1[x+1+stride])
+ -FFABS( s2[x ] - s2[x +stride]
+ - s2[x+1] + s2[x+1+stride]);
+ }
+ }
+ s1+= stride;
+ s2+= stride;
+ }
+
+ if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight;
+ else return score1 + FFABS(score2)*8;
+}
+
+static int nsse8_c(void *v, uint8_t *s1, uint8_t *s2, int stride, int h){
+ MpegEncContext *c = v;
+ int score1=0;
+ int score2=0;
+ int x,y;
+
+ for(y=0; y<h; y++){
+ for(x=0; x<8; x++){
+ score1+= (s1[x ] - s2[x ])*(s1[x ] - s2[x ]);
+ }
+ if(y+1<h){
+ for(x=0; x<7; x++){
+ score2+= FFABS( s1[x ] - s1[x +stride]
+ - s1[x+1] + s1[x+1+stride])
+ -FFABS( s2[x ] - s2[x +stride]
+ - s2[x+1] + s2[x+1+stride]);
+ }
+ }
+ s1+= stride;
+ s2+= stride;
+ }
+
+ if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight;
+ else return score1 + FFABS(score2)*8;
+}
+
+static int try_8x8basis_c(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale){
+ int i;
+ unsigned int sum=0;
+
+ for(i=0; i<8*8; i++){
+ int b= rem[i] + ((basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT));
+ int w= weight[i];
+ b>>= RECON_SHIFT;
+ assert(-512<b && b<512);
+
+ sum += (w*b)*(w*b)>>4;
+ }
+ return sum>>2;
+}
+
+static void add_8x8basis_c(int16_t rem[64], int16_t basis[64], int scale){
+ int i;
+
+ for(i=0; i<8*8; i++){
+ rem[i] += (basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT);
+ }
+}
+
+/**
+ * permutes an 8x8 block.
+ * @param block the block which will be permuted according to the given permutation vector
+ * @param permutation the permutation vector
+ * @param last the last non zero coefficient in scantable order, used to speed the permutation up
+ * @param scantable the used scantable, this is only used to speed the permutation up, the block is not
+ * (inverse) permutated to scantable order!
+ */
+void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last)
+{
+ int i;
+ DCTELEM temp[64];
+
+ if(last<=0) return;
+ //if(permutation[1]==1) return; //FIXME its ok but not clean and might fail for some perms
+
+ for(i=0; i<=last; i++){
+ const int j= scantable[i];
+ temp[j]= block[j];
+ block[j]=0;
+ }
+
+ for(i=0; i<=last; i++){
+ const int j= scantable[i];
+ const int perm_j= permutation[j];
+ block[perm_j]= temp[j];
+ }
+}
+
+static int zero_cmp(void *s, uint8_t *a, uint8_t *b, int stride, int h){
+ return 0;
+}
+
+void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type){
+ int i;
+
+ memset(cmp, 0, sizeof(void*)*5);
+
+ for(i=0; i<5; i++){
+ switch(type&0xFF){
+ case FF_CMP_SAD:
+ cmp[i]= c->sad[i];
+ break;
+ case FF_CMP_SATD:
+ cmp[i]= c->hadamard8_diff[i];
+ break;
+ case FF_CMP_SSE:
+ cmp[i]= c->sse[i];
+ break;
+ case FF_CMP_DCT:
+ cmp[i]= c->dct_sad[i];
+ break;
+ case FF_CMP_DCT264:
+ cmp[i]= c->dct264_sad[i];
+ break;
+ case FF_CMP_DCTMAX:
+ cmp[i]= c->dct_max[i];
+ break;
+ case FF_CMP_PSNR:
+ cmp[i]= c->quant_psnr[i];
+ break;
+ case FF_CMP_BIT:
+ cmp[i]= c->bit[i];
+ break;
+ case FF_CMP_RD:
+ cmp[i]= c->rd[i];
+ break;
+ case FF_CMP_VSAD:
+ cmp[i]= c->vsad[i];
+ break;
+ case FF_CMP_VSSE:
+ cmp[i]= c->vsse[i];
+ break;
+ case FF_CMP_ZERO:
+ cmp[i]= zero_cmp;
+ break;
+ case FF_CMP_NSSE:
+ cmp[i]= c->nsse[i];
+ break;
+#ifdef CONFIG_SNOW_ENCODER
+ case FF_CMP_W53:
+ cmp[i]= c->w53[i];
+ break;
+ case FF_CMP_W97:
+ cmp[i]= c->w97[i];
+ break;
+#endif
+ default:
+ av_log(NULL, AV_LOG_ERROR,"internal error in cmp function selection\n");
+ }
+ }
+}
+
+/**
+ * memset(blocks, 0, sizeof(DCTELEM)*6*64)
+ */
+static void clear_blocks_c(DCTELEM *blocks)
+{
+ memset(blocks, 0, sizeof(DCTELEM)*6*64);
+}
+
+static void add_bytes_c(uint8_t *dst, uint8_t *src, int w){
+ int i;
+ for(i=0; i+7<w; i+=8){
+ dst[i+0] += src[i+0];
+ dst[i+1] += src[i+1];
+ dst[i+2] += src[i+2];
+ dst[i+3] += src[i+3];
+ dst[i+4] += src[i+4];
+ dst[i+5] += src[i+5];
+ dst[i+6] += src[i+6];
+ dst[i+7] += src[i+7];
+ }
+ for(; i<w; i++)
+ dst[i+0] += src[i+0];
+}
+
+static void diff_bytes_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
+ int i;
+ for(i=0; i+7<w; i+=8){
+ dst[i+0] = src1[i+0]-src2[i+0];
+ dst[i+1] = src1[i+1]-src2[i+1];
+ dst[i+2] = src1[i+2]-src2[i+2];
+ dst[i+3] = src1[i+3]-src2[i+3];
+ dst[i+4] = src1[i+4]-src2[i+4];
+ dst[i+5] = src1[i+5]-src2[i+5];
+ dst[i+6] = src1[i+6]-src2[i+6];
+ dst[i+7] = src1[i+7]-src2[i+7];
+ }
+ for(; i<w; i++)
+ dst[i+0] = src1[i+0]-src2[i+0];
+}
+
+static void sub_hfyu_median_prediction_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w, int *left, int *left_top){
+ int i;
+ uint8_t l, lt;
+
+ l= *left;
+ lt= *left_top;
+
+ for(i=0; i<w; i++){
+ const int pred= mid_pred(l, src1[i], (l + src1[i] - lt)&0xFF);
+ lt= src1[i];
+ l= src2[i];
+ dst[i]= l - pred;
+ }
+
+ *left= l;
+ *left_top= lt;
+}
+
+#define BUTTERFLY2(o1,o2,i1,i2) \
+o1= (i1)+(i2);\
+o2= (i1)-(i2);
+
+#define BUTTERFLY1(x,y) \
+{\
+ int a,b;\
+ a= x;\
+ b= y;\
+ x= a+b;\
+ y= a-b;\
+}
+
+#define BUTTERFLYA(x,y) (FFABS((x)+(y)) + FFABS((x)-(y)))
+
+static int hadamard8_diff8x8_c(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h){
+ int i;
+ int temp[64];
+ int sum=0;
+
+ assert(h==8);
+
+ for(i=0; i<8; i++){
+ //FIXME try pointer walks
+ BUTTERFLY2(temp[8*i+0], temp[8*i+1], src[stride*i+0]-dst[stride*i+0],src[stride*i+1]-dst[stride*i+1]);
+ BUTTERFLY2(temp[8*i+2], temp[8*i+3], src[stride*i+2]-dst[stride*i+2],src[stride*i+3]-dst[stride*i+3]);
+ BUTTERFLY2(temp[8*i+4], temp[8*i+5], src[stride*i+4]-dst[stride*i+4],src[stride*i+5]-dst[stride*i+5]);
+ BUTTERFLY2(temp[8*i+6], temp[8*i+7], src[stride*i+6]-dst[stride*i+6],src[stride*i+7]-dst[stride*i+7]);
+
+ BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
+ BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
+ BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
+ BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
+
+ BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
+ BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
+ BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
+ BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
+ }
+
+ for(i=0; i<8; i++){
+ BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
+ BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
+ BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
+ BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
+
+ BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
+ BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
+ BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
+ BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
+
+ sum +=
+ BUTTERFLYA(temp[8*0+i], temp[8*4+i])
+ +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
+ +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
+ +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
+ }
+#if 0
+static int maxi=0;
+if(sum>maxi){
+ maxi=sum;
+ printf("MAX:%d\n", maxi);
+}
+#endif
+ return sum;
+}
+
+static int hadamard8_intra8x8_c(/*MpegEncContext*/ void *s, uint8_t *src, uint8_t *dummy, int stride, int h){
+ int i;
+ int temp[64];
+ int sum=0;
+
+ assert(h==8);
+
+ for(i=0; i<8; i++){
+ //FIXME try pointer walks
+ BUTTERFLY2(temp[8*i+0], temp[8*i+1], src[stride*i+0],src[stride*i+1]);
+ BUTTERFLY2(temp[8*i+2], temp[8*i+3], src[stride*i+2],src[stride*i+3]);
+ BUTTERFLY2(temp[8*i+4], temp[8*i+5], src[stride*i+4],src[stride*i+5]);
+ BUTTERFLY2(temp[8*i+6], temp[8*i+7], src[stride*i+6],src[stride*i+7]);
+
+ BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
+ BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
+ BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
+ BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
+
+ BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
+ BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
+ BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
+ BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
+ }
+
+ for(i=0; i<8; i++){
+ BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
+ BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
+ BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
+ BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
+
+ BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
+ BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
+ BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
+ BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
+
+ sum +=
+ BUTTERFLYA(temp[8*0+i], temp[8*4+i])
+ +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
+ +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
+ +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
+ }
+
+ sum -= FFABS(temp[8*0] + temp[8*4]); // -mean
+
+ return sum;
+}
+
+static int dct_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
+ MpegEncContext * const s= (MpegEncContext *)c;
+ DECLARE_ALIGNED_8(uint64_t, aligned_temp[sizeof(DCTELEM)*64/8]);
+ DCTELEM * const temp= (DCTELEM*)aligned_temp;
+ int sum=0, i;
+
+ assert(h==8);
+
+ s->dsp.diff_pixels(temp, src1, src2, stride);
+ s->dsp.fdct(temp);
+
+ for(i=0; i<64; i++)
+ sum+= FFABS(temp[i]);
+
+ return sum;
+}
+
+#ifdef CONFIG_GPL
+#define DCT8_1D {\
+ const int s07 = SRC(0) + SRC(7);\
+ const int s16 = SRC(1) + SRC(6);\
+ const int s25 = SRC(2) + SRC(5);\
+ const int s34 = SRC(3) + SRC(4);\
+ const int a0 = s07 + s34;\
+ const int a1 = s16 + s25;\
+ const int a2 = s07 - s34;\
+ const int a3 = s16 - s25;\
+ const int d07 = SRC(0) - SRC(7);\
+ const int d16 = SRC(1) - SRC(6);\
+ const int d25 = SRC(2) - SRC(5);\
+ const int d34 = SRC(3) - SRC(4);\
+ const int a4 = d16 + d25 + (d07 + (d07>>1));\
+ const int a5 = d07 - d34 - (d25 + (d25>>1));\
+ const int a6 = d07 + d34 - (d16 + (d16>>1));\
+ const int a7 = d16 - d25 + (d34 + (d34>>1));\
+ DST(0, a0 + a1 ) ;\
+ DST(1, a4 + (a7>>2)) ;\
+ DST(2, a2 + (a3>>1)) ;\
+ DST(3, a5 + (a6>>2)) ;\
+ DST(4, a0 - a1 ) ;\
+ DST(5, a6 - (a5>>2)) ;\
+ DST(6, (a2>>1) - a3 ) ;\
+ DST(7, (a4>>2) - a7 ) ;\
+}
+
+static int dct264_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
+ MpegEncContext * const s= (MpegEncContext *)c;
+ int16_t dct[8][8];
+ int i;
+ int sum=0;
+
+ s->dsp.diff_pixels(dct, src1, src2, stride);
+
+#define SRC(x) dct[i][x]
+#define DST(x,v) dct[i][x]= v
+ for( i = 0; i < 8; i++ )
+ DCT8_1D
+#undef SRC
+#undef DST
+
+#define SRC(x) dct[x][i]
+#define DST(x,v) sum += FFABS(v)
+ for( i = 0; i < 8; i++ )
+ DCT8_1D
+#undef SRC
+#undef DST
+ return sum;
+}
+#endif
+
+static int dct_max8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
+ MpegEncContext * const s= (MpegEncContext *)c;
+ DECLARE_ALIGNED_8(uint64_t, aligned_temp[sizeof(DCTELEM)*64/8]);
+ DCTELEM * const temp= (DCTELEM*)aligned_temp;
+ int sum=0, i;
+
+ assert(h==8);
+
+ s->dsp.diff_pixels(temp, src1, src2, stride);
+ s->dsp.fdct(temp);
+
+ for(i=0; i<64; i++)
+ sum= FFMAX(sum, FFABS(temp[i]));
+
+ return sum;
+}
+
+static int quant_psnr8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
+ MpegEncContext * const s= (MpegEncContext *)c;
+ DECLARE_ALIGNED_8 (uint64_t, aligned_temp[sizeof(DCTELEM)*64*2/8]);
+ DCTELEM * const temp= (DCTELEM*)aligned_temp;
+ DCTELEM * const bak = ((DCTELEM*)aligned_temp)+64;
+ int sum=0, i;
+
+ assert(h==8);
+ s->mb_intra=0;
+
+ s->dsp.diff_pixels(temp, src1, src2, stride);
+
+ memcpy(bak, temp, 64*sizeof(DCTELEM));
+
+ s->block_last_index[0/*FIXME*/]= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
+ s->dct_unquantize_inter(s, temp, 0, s->qscale);
+ simple_idct(temp); //FIXME
+
+ for(i=0; i<64; i++)
+ sum+= (temp[i]-bak[i])*(temp[i]-bak[i]);
+
+ return sum;
+}
+
+static int rd8x8_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]);
+ DECLARE_ALIGNED_8 (uint64_t, aligned_bak[stride]);
+ DCTELEM * const temp= (DCTELEM*)aligned_temp;
+ uint8_t * const bak= (uint8_t*)aligned_bak;
+ int i, last, run, bits, level, distoration, start_i;
+ const int esc_length= s->ac_esc_length;
+ uint8_t * length;
+ uint8_t * last_length;
+
+ assert(h==8);
+
+ for(i=0; i<8; i++){
+ ((uint32_t*)(bak + i*stride))[0]= ((uint32_t*)(src2 + i*stride))[0];
+ ((uint32_t*)(bak + i*stride))[1]= ((uint32_t*)(src2 + i*stride))[1];
+ }
+
+ s->dsp.diff_pixels(temp, src1, src2, stride);
+
+ s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
+
+ bits=0;
+
+ if (s->mb_intra) {
+ start_i = 1;
+ length = s->intra_ac_vlc_length;
+ last_length= s->intra_ac_vlc_last_length;
+ bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma
+ } else {
+ start_i = 0;
+ length = s->inter_ac_vlc_length;
+ last_length= s->inter_ac_vlc_last_length;
+ }
+
+ if(last>=start_i){
+ run=0;
+ for(i=start_i; i<last; i++){
+ int j= scantable[i];
+ level= temp[j];
+
+ if(level){
+ level+=64;
+ if((level&(~127)) == 0){
+ bits+= length[UNI_AC_ENC_INDEX(run, level)];
+ }else
+ bits+= esc_length;
+ run=0;
+ }else
+ run++;
+ }
+ i= scantable[last];
+
+ level= temp[i] + 64;
+
+ assert(level - 64);
+
+ if((level&(~127)) == 0){
+ bits+= last_length[UNI_AC_ENC_INDEX(run, level)];
+ }else
+ bits+= esc_length;
+
+ }
+
+ if(last>=0){
+ if(s->mb_intra)
+ s->dct_unquantize_intra(s, temp, 0, s->qscale);
+ else
+ s->dct_unquantize_inter(s, temp, 0, s->qscale);
+ }
+
+ s->dsp.idct_add(bak, stride, temp);
+
+ distoration= s->dsp.sse[1](NULL, bak, src1, stride, 8);
+
+ return distoration + ((bits*s->qscale*s->qscale*109 + 64)>>7);
+}
+
+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;
+ int i, last, run, bits, level, start_i;
+ const int esc_length= s->ac_esc_length;
+ uint8_t * length;
+ uint8_t * last_length;
+
+ assert(h==8);
+
+ s->dsp.diff_pixels(temp, src1, src2, stride);
+
+ s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
+
+ bits=0;
+
+ if (s->mb_intra) {
+ start_i = 1;
+ length = s->intra_ac_vlc_length;
+ last_length= s->intra_ac_vlc_last_length;
+ bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma
+ } else {
+ start_i = 0;
+ length = s->inter_ac_vlc_length;
+ last_length= s->inter_ac_vlc_last_length;
+ }
+
+ if(last>=start_i){
+ run=0;
+ for(i=start_i; i<last; i++){
+ int j= scantable[i];
+ level= temp[j];
+
+ if(level){
+ level+=64;
+ if((level&(~127)) == 0){
+ bits+= length[UNI_AC_ENC_INDEX(run, level)];
+ }else
+ bits+= esc_length;
+ run=0;
+ }else
+ run++;
+ }
+ i= scantable[last];
+
+ level= temp[i] + 64;
+
+ assert(level - 64);
+
+ if((level&(~127)) == 0){
+ bits+= last_length[UNI_AC_ENC_INDEX(run, level)];
+ }else
+ bits+= esc_length;
+ }
+
+ return bits;
+}
+
+static int vsad_intra16_c(/*MpegEncContext*/ void *c, uint8_t *s, uint8_t *dummy, int stride, int h){
+ int score=0;
+ int x,y;
+
+ for(y=1; y<h; y++){
+ for(x=0; x<16; x+=4){
+ score+= FFABS(s[x ] - s[x +stride]) + FFABS(s[x+1] - s[x+1+stride])
+ +FFABS(s[x+2] - s[x+2+stride]) + FFABS(s[x+3] - s[x+3+stride]);
+ }
+ s+= stride;
+ }
+
+ return score;
+}
+
+static int vsad16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){
+ int score=0;
+ int x,y;
+
+ for(y=1; y<h; y++){
+ for(x=0; x<16; x++){
+ score+= FFABS(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]);
+ }
+ s1+= stride;
+ s2+= stride;
+ }
+
+ return score;
+}
+
+#define SQ(a) ((a)*(a))
+static int vsse_intra16_c(/*MpegEncContext*/ void *c, uint8_t *s, uint8_t *dummy, int stride, int h){
+ int score=0;
+ int x,y;
+
+ for(y=1; y<h; y++){
+ for(x=0; x<16; x+=4){
+ score+= SQ(s[x ] - s[x +stride]) + SQ(s[x+1] - s[x+1+stride])
+ +SQ(s[x+2] - s[x+2+stride]) + SQ(s[x+3] - s[x+3+stride]);
+ }
+ s+= stride;
+ }
+
+ return score;
+}
+
+static int vsse16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){
+ int score=0;
+ int x,y;
+
+ for(y=1; y<h; y++){
+ for(x=0; x<16; x++){
+ score+= SQ(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]);
+ }
+ s1+= stride;
+ s2+= stride;
+ }
+
+ return score;
+}
+
+static int ssd_int8_vs_int16_c(int8_t *pix1, int16_t *pix2, int size){
+ int score=0;
+ int i;
+ for(i=0; i<size; i++)
+ score += (pix1[i]-pix2[i])*(pix1[i]-pix2[i]);
+ return score;
+}
+
+WARPER8_16_SQ(hadamard8_diff8x8_c, hadamard8_diff16_c)
+WARPER8_16_SQ(hadamard8_intra8x8_c, hadamard8_intra16_c)
+WARPER8_16_SQ(dct_sad8x8_c, dct_sad16_c)
+#ifdef CONFIG_GPL
+WARPER8_16_SQ(dct264_sad8x8_c, dct264_sad16_c)
+#endif
+WARPER8_16_SQ(dct_max8x8_c, dct_max16_c)
+WARPER8_16_SQ(quant_psnr8x8_c, quant_psnr16_c)
+WARPER8_16_SQ(rd8x8_c, rd16_c)
+WARPER8_16_SQ(bit8x8_c, bit16_c)
+
+static void vector_fmul_c(float *dst, const float *src, int len){
+ int i;
+ for(i=0; i<len; i++)
+ dst[i] *= src[i];
+}
+
+static void vector_fmul_reverse_c(float *dst, const float *src0, const float *src1, int len){
+ int i;
+ src1 += len-1;
+ for(i=0; i<len; i++)
+ 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){
+ int i;
+ for(i=0; i<len; i++)
+ dst[i*step] = src0[i] * src1[i] + src2[i] + src3;
+}
+
+void ff_float_to_int16_c(int16_t *dst, const float *src, int len){
+ int i;
+ for(i=0; i<len; i++) {
+ int_fast32_t tmp = ((int32_t*)src)[i];
+ if(tmp & 0xf0000){
+ tmp = (0x43c0ffff - tmp)>>31;
+ // is this faster on some gcc/cpu combinations?
+// if(tmp > 0x43c0ffff) tmp = 0xFFFF;
+// else tmp = 0;
+ }
+ dst[i] = tmp - 0x8000;
+ }
+}
+
+/* XXX: those functions should be suppressed ASAP when all IDCTs are
+ converted */
+static void ff_jref_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ j_rev_dct (block);
+ put_pixels_clamped_c(block, dest, line_size);
+}
+static void ff_jref_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ j_rev_dct (block);
+ add_pixels_clamped_c(block, dest, line_size);
+}
+
+static void ff_jref_idct4_put(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ j_rev_dct4 (block);
+ put_pixels_clamped4_c(block, dest, line_size);
+}
+static void ff_jref_idct4_add(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ j_rev_dct4 (block);
+ add_pixels_clamped4_c(block, dest, line_size);
+}
+
+static void ff_jref_idct2_put(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ j_rev_dct2 (block);
+ put_pixels_clamped2_c(block, dest, line_size);
+}
+static void ff_jref_idct2_add(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ j_rev_dct2 (block);
+ add_pixels_clamped2_c(block, dest, line_size);
+}
+
+static void ff_jref_idct1_put(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+
+ dest[0] = cm[(block[0] + 4)>>3];
+}
+static void ff_jref_idct1_add(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+
+ dest[0] = cm[dest[0] + ((block[0] + 4)>>3)];
+}
+
+static void just_return() { return; }
+
+/* init static data */
+void dsputil_static_init(void)
+{
+ int i;
+
+ for(i=0;i<256;i++) ff_cropTbl[i + MAX_NEG_CROP] = i;
+ for(i=0;i<MAX_NEG_CROP;i++) {
+ ff_cropTbl[i] = 0;
+ ff_cropTbl[i + MAX_NEG_CROP + 256] = 255;
+ }
+
+ for(i=0;i<512;i++) {
+ ff_squareTbl[i] = (i - 256) * (i - 256);
+ }
+
+ for(i=0; i<64; i++) inv_zigzag_direct16[ff_zigzag_direct[i]]= i+1;
+}
+
+int ff_check_alignment(void){
+ static int did_fail=0;
+ DECLARE_ALIGNED_16(int, aligned);
+
+ if((int)&aligned & 15){
+ if(!did_fail){
+#if defined(HAVE_MMX) || defined(HAVE_ALTIVEC)
+ av_log(NULL, AV_LOG_ERROR,
+ "Compiler did not align stack variables. Libavcodec has been miscompiled\n"
+ "and may be very slow or crash. This is not a bug in libavcodec,\n"
+ "but in the compiler. Do not report crashes to FFmpeg developers.\n");
+#endif
+ did_fail=1;
+ }
+ return -1;
+ }
+ return 0;
+}
+
+void dsputil_init(DSPContext* c, AVCodecContext *avctx)
+{
+ int i;
+
+ ff_check_alignment();
+
+#ifdef CONFIG_ENCODERS
+ if(avctx->dct_algo==FF_DCT_FASTINT) {
+ c->fdct = fdct_ifast;
+ c->fdct248 = fdct_ifast248;
+ }
+ else if(avctx->dct_algo==FF_DCT_FAAN) {
+ c->fdct = ff_faandct;
+ c->fdct248 = ff_faandct248;
+ }
+ else {
+ c->fdct = ff_jpeg_fdct_islow; //slow/accurate/default
+ c->fdct248 = ff_fdct248_islow;
+ }
+#endif //CONFIG_ENCODERS
+
+ if(avctx->lowres==1){
+ if(avctx->idct_algo==FF_IDCT_INT || avctx->idct_algo==FF_IDCT_AUTO){
+ c->idct_put= ff_jref_idct4_put;
+ c->idct_add= ff_jref_idct4_add;
+ }else{
+ c->idct_put= ff_h264_lowres_idct_put_c;
+ c->idct_add= ff_h264_lowres_idct_add_c;
+ }
+ c->idct = j_rev_dct4;
+ c->idct_permutation_type= FF_NO_IDCT_PERM;
+ }else if(avctx->lowres==2){
+ c->idct_put= ff_jref_idct2_put;
+ c->idct_add= ff_jref_idct2_add;
+ c->idct = j_rev_dct2;
+ c->idct_permutation_type= FF_NO_IDCT_PERM;
+ }else if(avctx->lowres==3){
+ c->idct_put= ff_jref_idct1_put;
+ c->idct_add= ff_jref_idct1_add;
+ c->idct = j_rev_dct1;
+ c->idct_permutation_type= FF_NO_IDCT_PERM;
+ }else{
+ if(avctx->idct_algo==FF_IDCT_INT){
+ c->idct_put= ff_jref_idct_put;
+ c->idct_add= ff_jref_idct_add;
+ c->idct = j_rev_dct;
+ c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
+ }else if(avctx->idct_algo==FF_IDCT_VP3){
+ c->idct_put= ff_vp3_idct_put_c;
+ c->idct_add= ff_vp3_idct_add_c;
+ c->idct = ff_vp3_idct_c;
+ c->idct_permutation_type= FF_NO_IDCT_PERM;
+ }else{ //accurate/default
+ c->idct_put= simple_idct_put;
+ c->idct_add= simple_idct_add;
+ c->idct = simple_idct;
+ c->idct_permutation_type= FF_NO_IDCT_PERM;
+ }
+ }
+
+ 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->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->add_pixels_clamped = add_pixels_clamped_c;
+ c->add_pixels8 = add_pixels8_c;
+ c->add_pixels4 = add_pixels4_c;
+ c->gmc1 = gmc1_c;
+ c->gmc = ff_gmc_c;
+ c->clear_blocks = clear_blocks_c;
+ c->pix_sum = pix_sum_c;
+ c->pix_norm1 = pix_norm1_c;
+
+ /* TODO [0] 16 [1] 8 */
+ c->pix_abs[0][0] = pix_abs16_c;
+ c->pix_abs[0][1] = pix_abs16_x2_c;
+ c->pix_abs[0][2] = pix_abs16_y2_c;
+ c->pix_abs[0][3] = pix_abs16_xy2_c;
+ c->pix_abs[1][0] = pix_abs8_c;
+ c->pix_abs[1][1] = pix_abs8_x2_c;
+ c->pix_abs[1][2] = pix_abs8_y2_c;
+ c->pix_abs[1][3] = pix_abs8_xy2_c;
+
+#define dspfunc(PFX, IDX, NUM) \
+ c->PFX ## _pixels_tab[IDX][0] = PFX ## _pixels ## NUM ## _c; \
+ c->PFX ## _pixels_tab[IDX][1] = PFX ## _pixels ## NUM ## _x2_c; \
+ c->PFX ## _pixels_tab[IDX][2] = PFX ## _pixels ## NUM ## _y2_c; \
+ c->PFX ## _pixels_tab[IDX][3] = PFX ## _pixels ## NUM ## _xy2_c
+
+ dspfunc(put, 0, 16);
+ dspfunc(put_no_rnd, 0, 16);
+ dspfunc(put, 1, 8);
+ dspfunc(put_no_rnd, 1, 8);
+ dspfunc(put, 2, 4);
+ dspfunc(put, 3, 2);
+
+ dspfunc(avg, 0, 16);
+ dspfunc(avg_no_rnd, 0, 16);
+ dspfunc(avg, 1, 8);
+ dspfunc(avg_no_rnd, 1, 8);
+ dspfunc(avg, 2, 4);
+ dspfunc(avg, 3, 2);
+#undef dspfunc
+
+ c->put_no_rnd_pixels_l2[0]= put_no_rnd_pixels16_l2_c;
+ c->put_no_rnd_pixels_l2[1]= put_no_rnd_pixels8_l2_c;
+
+ c->put_tpel_pixels_tab[ 0] = put_tpel_pixels_mc00_c;
+ c->put_tpel_pixels_tab[ 1] = put_tpel_pixels_mc10_c;
+ c->put_tpel_pixels_tab[ 2] = put_tpel_pixels_mc20_c;
+ c->put_tpel_pixels_tab[ 4] = put_tpel_pixels_mc01_c;
+ c->put_tpel_pixels_tab[ 5] = put_tpel_pixels_mc11_c;
+ c->put_tpel_pixels_tab[ 6] = put_tpel_pixels_mc21_c;
+ c->put_tpel_pixels_tab[ 8] = put_tpel_pixels_mc02_c;
+ c->put_tpel_pixels_tab[ 9] = put_tpel_pixels_mc12_c;
+ c->put_tpel_pixels_tab[10] = put_tpel_pixels_mc22_c;
+
+ c->avg_tpel_pixels_tab[ 0] = avg_tpel_pixels_mc00_c;
+ c->avg_tpel_pixels_tab[ 1] = avg_tpel_pixels_mc10_c;
+ c->avg_tpel_pixels_tab[ 2] = avg_tpel_pixels_mc20_c;
+ c->avg_tpel_pixels_tab[ 4] = avg_tpel_pixels_mc01_c;
+ c->avg_tpel_pixels_tab[ 5] = avg_tpel_pixels_mc11_c;
+ c->avg_tpel_pixels_tab[ 6] = avg_tpel_pixels_mc21_c;
+ c->avg_tpel_pixels_tab[ 8] = avg_tpel_pixels_mc02_c;
+ c->avg_tpel_pixels_tab[ 9] = avg_tpel_pixels_mc12_c;
+ c->avg_tpel_pixels_tab[10] = avg_tpel_pixels_mc22_c;
+
+#define dspfunc(PFX, IDX, NUM) \
+ c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_c; \
+ c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_c; \
+ c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_c; \
+ c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_c; \
+ c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_c; \
+ c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_c; \
+ c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_c; \
+ c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_c; \
+ c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_c; \
+ c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_c; \
+ c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_c; \
+ c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_c; \
+ c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_c; \
+ c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_c; \
+ c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_c; \
+ c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_c
+
+ dspfunc(put_qpel, 0, 16);
+ dspfunc(put_no_rnd_qpel, 0, 16);
+
+ dspfunc(avg_qpel, 0, 16);
+ /* dspfunc(avg_no_rnd_qpel, 0, 16); */
+
+ dspfunc(put_qpel, 1, 8);
+ dspfunc(put_no_rnd_qpel, 1, 8);
+
+ dspfunc(avg_qpel, 1, 8);
+ /* dspfunc(avg_no_rnd_qpel, 1, 8); */
+
+ dspfunc(put_h264_qpel, 0, 16);
+ dspfunc(put_h264_qpel, 1, 8);
+ dspfunc(put_h264_qpel, 2, 4);
+ dspfunc(put_h264_qpel, 3, 2);
+ dspfunc(avg_h264_qpel, 0, 16);
+ dspfunc(avg_h264_qpel, 1, 8);
+ dspfunc(avg_h264_qpel, 2, 4);
+
+#undef dspfunc
+ c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_c;
+ c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_c;
+ c->put_h264_chroma_pixels_tab[2]= put_h264_chroma_mc2_c;
+ c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_c;
+ c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_c;
+ c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_c;
+ c->put_no_rnd_h264_chroma_pixels_tab[0]= put_no_rnd_h264_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;
+
+#ifdef CONFIG_CAVS_DECODER
+ ff_cavsdsp_init(c,avctx);
+#endif
+#if defined(CONFIG_VC1_DECODER) || defined(CONFIG_WMV3_DECODER)
+ ff_vc1dsp_init(c,avctx);
+#endif
+#if defined(CONFIG_H264_ENCODER)
+ ff_h264dsp_init(c,avctx);
+#endif
+
+ c->put_mspel_pixels_tab[0]= put_mspel8_mc00_c;
+ c->put_mspel_pixels_tab[1]= put_mspel8_mc10_c;
+ c->put_mspel_pixels_tab[2]= put_mspel8_mc20_c;
+ c->put_mspel_pixels_tab[3]= put_mspel8_mc30_c;
+ c->put_mspel_pixels_tab[4]= put_mspel8_mc02_c;
+ c->put_mspel_pixels_tab[5]= put_mspel8_mc12_c;
+ c->put_mspel_pixels_tab[6]= put_mspel8_mc22_c;
+ c->put_mspel_pixels_tab[7]= put_mspel8_mc32_c;
+
+#define SET_CMP_FUNC(name) \
+ c->name[0]= name ## 16_c;\
+ c->name[1]= name ## 8x8_c;
+
+ SET_CMP_FUNC(hadamard8_diff)
+ c->hadamard8_diff[4]= hadamard8_intra16_c;
+ SET_CMP_FUNC(dct_sad)
+ SET_CMP_FUNC(dct_max)
+#ifdef CONFIG_GPL
+ SET_CMP_FUNC(dct264_sad)
+#endif
+ c->sad[0]= pix_abs16_c;
+ c->sad[1]= pix_abs8_c;
+ c->sse[0]= sse16_c;
+ c->sse[1]= sse8_c;
+ c->sse[2]= sse4_c;
+ SET_CMP_FUNC(quant_psnr)
+ SET_CMP_FUNC(rd)
+ SET_CMP_FUNC(bit)
+ c->vsad[0]= vsad16_c;
+ c->vsad[4]= vsad_intra16_c;
+ c->vsse[0]= vsse16_c;
+ c->vsse[4]= vsse_intra16_c;
+ c->nsse[0]= nsse16_c;
+ c->nsse[1]= nsse8_c;
+#ifdef 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;
+#endif
+
+ c->ssd_int8_vs_int16 = ssd_int8_vs_int16_c;
+
+ c->add_bytes= add_bytes_c;
+ c->diff_bytes= diff_bytes_c;
+ c->sub_hfyu_median_prediction= sub_hfyu_median_prediction_c;
+ c->bswap_buf= bswap_buf;
+
+ 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_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;
+
+ c->h263_h_loop_filter= h263_h_loop_filter_c;
+ c->h263_v_loop_filter= h263_v_loop_filter_c;
+
+ c->h261_loop_filter= h261_loop_filter_c;
+
+ c->try_8x8basis= try_8x8basis_c;
+ c->add_8x8basis= add_8x8basis_c;
+
+#ifdef 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
+
+#ifdef CONFIG_VORBIS_DECODER
+ c->vorbis_inverse_coupling = vorbis_inverse_coupling;
+#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->float_to_int16 = ff_float_to_int16_c;
+
+ c->shrink[0]= ff_img_copy_plane;
+ c->shrink[1]= ff_shrink22;
+ c->shrink[2]= ff_shrink44;
+ c->shrink[3]= ff_shrink88;
+
+ c->prefetch= just_return;
+
+ memset(c->put_2tap_qpel_pixels_tab, 0, sizeof(c->put_2tap_qpel_pixels_tab));
+ memset(c->avg_2tap_qpel_pixels_tab, 0, sizeof(c->avg_2tap_qpel_pixels_tab));
+
+#ifdef HAVE_MMX
+ dsputil_init_mmx(c, avctx);
+#endif
+#ifdef ARCH_ARMV4L
+ dsputil_init_armv4l(c, avctx);
+#endif
+#ifdef HAVE_MLIB
+ dsputil_init_mlib(c, avctx);
+#endif
+#ifdef ARCH_SPARC
+ dsputil_init_vis(c,avctx);
+#endif
+#ifdef ARCH_ALPHA
+ dsputil_init_alpha(c, avctx);
+#endif
+#ifdef ARCH_POWERPC
+ dsputil_init_ppc(c, avctx);
+#endif
+#ifdef HAVE_MMI
+ dsputil_init_mmi(c, avctx);
+#endif
+#ifdef ARCH_SH4
+ dsputil_init_sh4(c,avctx);
+#endif
+#ifdef ARCH_BFIN
+ dsputil_init_bfin(c,avctx);
+#endif
+
+ for(i=0; i<64; i++){
+ if(!c->put_2tap_qpel_pixels_tab[0][i])
+ c->put_2tap_qpel_pixels_tab[0][i]= c->put_h264_qpel_pixels_tab[0][i];
+ if(!c->avg_2tap_qpel_pixels_tab[0][i])
+ c->avg_2tap_qpel_pixels_tab[0][i]= c->avg_h264_qpel_pixels_tab[0][i];
+ }
+
+ switch(c->idct_permutation_type){
+ case FF_NO_IDCT_PERM:
+ for(i=0; i<64; i++)
+ c->idct_permutation[i]= i;
+ break;
+ case FF_LIBMPEG2_IDCT_PERM:
+ for(i=0; i<64; i++)
+ c->idct_permutation[i]= (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2);
+ break;
+ case FF_SIMPLE_IDCT_PERM:
+ for(i=0; i<64; i++)
+ c->idct_permutation[i]= simple_mmx_permutation[i];
+ break;
+ case FF_TRANSPOSE_IDCT_PERM:
+ for(i=0; i<64; i++)
+ c->idct_permutation[i]= ((i&7)<<3) | (i>>3);
+ break;
+ case FF_PARTTRANS_IDCT_PERM:
+ for(i=0; i<64; i++)
+ c->idct_permutation[i]= (i&0x24) | ((i&3)<<3) | ((i>>3)&3);
+ break;
+ default:
+ av_log(avctx, AV_LOG_ERROR, "Internal error, IDCT permutation not set\n");
+ }
+}
+
diff --git a/contrib/ffmpeg/libavcodec/dsputil.h b/contrib/ffmpeg/libavcodec/dsputil.h
new file mode 100644
index 000000000..800669ea7
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/dsputil.h
@@ -0,0 +1,762 @@
+/*
+ * DSP utils
+ * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
+ * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file dsputil.h
+ * 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
+ */
+
+#ifndef DSPUTIL_H
+#define DSPUTIL_H
+
+#include "common.h"
+#include "avcodec.h"
+
+
+//#define DEBUG
+/* dct code */
+typedef short DCTELEM;
+typedef int DWTELEM;
+
+void fdct_ifast (DCTELEM *data);
+void fdct_ifast248 (DCTELEM *data);
+void ff_jpeg_fdct_islow (DCTELEM *data);
+void ff_fdct248_islow (DCTELEM *data);
+
+void j_rev_dct (DCTELEM *data);
+void j_rev_dct4 (DCTELEM *data);
+void j_rev_dct2 (DCTELEM *data);
+void j_rev_dct1 (DCTELEM *data);
+
+void ff_fdct_mmx(DCTELEM *block);
+void ff_fdct_mmx2(DCTELEM *block);
+void ff_fdct_sse2(DCTELEM *block);
+
+void ff_h264_idct8_add_c(uint8_t *dst, DCTELEM *block, int stride);
+void ff_h264_idct_add_c(uint8_t *dst, DCTELEM *block, int stride);
+void ff_h264_idct8_dc_add_c(uint8_t *dst, DCTELEM *block, int stride);
+void ff_h264_idct_dc_add_c(uint8_t *dst, DCTELEM *block, int stride);
+void ff_h264_lowres_idct_add_c(uint8_t *dst, int stride, DCTELEM *block);
+void ff_h264_lowres_idct_put_c(uint8_t *dst, int stride, DCTELEM *block);
+
+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_float_to_int16_c(int16_t *dst, const float *src, int len);
+
+/* encoding scans */
+extern const uint8_t ff_alternate_horizontal_scan[64];
+extern const uint8_t ff_alternate_vertical_scan[64];
+extern const uint8_t ff_zigzag_direct[64];
+extern const uint8_t ff_zigzag248_direct[64];
+
+/* pixel operations */
+#define MAX_NEG_CROP 1024
+
+/* temporary */
+extern uint32_t ff_squareTbl[512];
+extern uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP];
+
+/* VP3 DSP functions */
+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*/);
+
+/* 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);
+void ff_shrink44(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
+void ff_shrink88(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
+
+void ff_gmc_c(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);
+
+/* minimum alignment rules ;)
+if u notice errors in the align stuff, need more alignment for some asm code for some cpu
+or need to use a function with less aligned data then send a mail to the ffmpeg-dev list, ...
+
+!warning these alignments might not match reallity, (missing attribute((align)) stuff somewhere possible)
+i (michael) didnt check them, these are just the alignents which i think could be reached easily ...
+
+!future video codecs might need functions with less strict alignment
+*/
+
+/*
+void get_pixels_c(DCTELEM *block, const uint8_t *pixels, int line_size);
+void diff_pixels_c(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, int stride);
+void put_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size);
+void add_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size);
+void clear_blocks_c(DCTELEM *blocks);
+*/
+
+/* add and put pixel (decoding) */
+// blocksizes for op_pixels_func are 8x4,8x8 16x8 16x16
+//h for op_pixels_func is limited to {width/2, width} but never larger than 16 and never smaller then 4
+typedef void (*op_pixels_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, int line_size, int h);
+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);
+
+#define DEF_OLD_QPEL(name)\
+void ff_put_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
+void ff_put_no_rnd_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
+void ff_avg_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);
+
+DEF_OLD_QPEL(qpel16_mc11_old_c)
+DEF_OLD_QPEL(qpel16_mc31_old_c)
+DEF_OLD_QPEL(qpel16_mc12_old_c)
+DEF_OLD_QPEL(qpel16_mc32_old_c)
+DEF_OLD_QPEL(qpel16_mc13_old_c)
+DEF_OLD_QPEL(qpel16_mc33_old_c)
+DEF_OLD_QPEL(qpel8_mc11_old_c)
+DEF_OLD_QPEL(qpel8_mc31_old_c)
+DEF_OLD_QPEL(qpel8_mc12_old_c)
+DEF_OLD_QPEL(qpel8_mc32_old_c)
+DEF_OLD_QPEL(qpel8_mc13_old_c)
+DEF_OLD_QPEL(qpel8_mc33_old_c)
+
+#define CALL_2X_PIXELS(a, b, n)\
+static void a(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
+ b(block , pixels , line_size, h);\
+ b(block+n, pixels+n, line_size, h);\
+}
+
+/* motion estimation */
+// h is limited to {width/2, width, 2*width} but never larger than 16 and never smaller then 2
+// allthough currently h<4 is not used as functions with width <8 are not used and neither 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;
+
+/**
+ * DSPContext.
+ */
+typedef struct DSPContext {
+ /* pixel ops : interface with DCT */
+ void (*get_pixels)(DCTELEM *block/*align 16*/, const uint8_t *pixels/*align 8*/, int line_size);
+ void (*diff_pixels)(DCTELEM *block/*align 16*/, const uint8_t *s1/*align 8*/, const uint8_t *s2/*align 8*/, int stride);
+ void (*put_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
+ void (*put_signed_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
+ void (*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);
+ /**
+ * translational global motion compensation.
+ */
+ void (*gmc1)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x16, int y16, int rounder);
+ /**
+ * global motion compensation.
+ */
+ void (*gmc )(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int ox, int oy,
+ int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height);
+ void (*clear_blocks)(DCTELEM *blocks/*align 16*/);
+ int (*pix_sum)(uint8_t * pix, int line_size);
+ int (*pix_norm1)(uint8_t * pix, int line_size);
+// 16x16 8x8 4x4 2x2 16x8 8x4 4x2 8x16 4x8 2x4
+
+ me_cmp_func sad[5]; /* identical to pix_absAxA except additional void * */
+ me_cmp_func sse[5];
+ me_cmp_func hadamard8_diff[5];
+ me_cmp_func dct_sad[5];
+ me_cmp_func quant_psnr[5];
+ me_cmp_func bit[5];
+ me_cmp_func rd[5];
+ me_cmp_func vsad[5];
+ me_cmp_func vsse[5];
+ me_cmp_func nsse[5];
+ me_cmp_func w53[5];
+ me_cmp_func w97[5];
+ me_cmp_func dct_max[5];
+ me_cmp_func dct264_sad[5];
+
+ me_cmp_func me_pre_cmp[5];
+ me_cmp_func me_cmp[5];
+ me_cmp_func me_sub_cmp[5];
+ me_cmp_func mb_cmp[5];
+ me_cmp_func ildct_cmp[5]; //only width 16 used
+ me_cmp_func frame_skip_cmp[5]; //only width 8 used
+
+ int (*ssd_int8_vs_int16)(int8_t *pix1, int16_t *pix2, int size);
+
+ /**
+ * Halfpel motion compensation with rounding (a+b+1)>>1.
+ * this is an array[4][4] of motion compensation functions for 4
+ * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
+ * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
+ * @param block destination where the result is stored
+ * @param pixels source
+ * @param line_size number of bytes in a horizontal line of block
+ * @param h height
+ */
+ op_pixels_func put_pixels_tab[4][4];
+
+ /**
+ * Halfpel motion compensation with rounding (a+b+1)>>1.
+ * This is an array[4][4] of motion compensation functions for 4
+ * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
+ * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
+ * @param block destination into which the result is averaged (a+b+1)>>1
+ * @param pixels source
+ * @param line_size number of bytes in a horizontal line of block
+ * @param h height
+ */
+ op_pixels_func avg_pixels_tab[4][4];
+
+ /**
+ * Halfpel motion compensation with no rounding (a+b)>>1.
+ * this is an array[2][4] of motion compensation functions for 2
+ * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
+ * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
+ * @param block destination where the result is stored
+ * @param pixels source
+ * @param line_size number of bytes in a horizontal line of block
+ * @param h height
+ */
+ op_pixels_func put_no_rnd_pixels_tab[4][4];
+
+ /**
+ * Halfpel motion compensation with no rounding (a+b)>>1.
+ * this is an array[2][4] of motion compensation functions for 2
+ * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
+ * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
+ * @param block destination into which the result is averaged (a+b)>>1
+ * @param pixels source
+ * @param line_size number of bytes in a horizontal line of block
+ * @param h height
+ */
+ op_pixels_func avg_no_rnd_pixels_tab[4][4];
+
+ void (*put_no_rnd_pixels_l2[2])(uint8_t *block/*align width (8 or 16)*/, const uint8_t *a/*align 1*/, const uint8_t *b/*align 1*/, int line_size, int h);
+
+ /**
+ * Thirdpel motion compensation with rounding (a+b+1)>>1.
+ * this is an array[12] of motion compensation functions for the 9 thirdpe
+ * positions<br>
+ * *pixels_tab[ xthirdpel + 4*ythirdpel ]
+ * @param block destination where the result is stored
+ * @param pixels source
+ * @param line_size number of bytes in a horizontal line of block
+ * @param h height
+ */
+ tpel_mc_func put_tpel_pixels_tab[11]; //FIXME individual func ptr per width?
+ tpel_mc_func avg_tpel_pixels_tab[11]; //FIXME individual func ptr per width?
+
+ qpel_mc_func put_qpel_pixels_tab[2][16];
+ qpel_mc_func avg_qpel_pixels_tab[2][16];
+ qpel_mc_func put_no_rnd_qpel_pixels_tab[2][16];
+ qpel_mc_func avg_no_rnd_qpel_pixels_tab[2][16];
+ qpel_mc_func put_mspel_pixels_tab[8];
+
+ /**
+ * h264 Chroma MC
+ */
+ h264_chroma_mc_func put_h264_chroma_pixels_tab[3];
+ /* This is really one func used in VC-1 decoding */
+ h264_chroma_mc_func put_no_rnd_h264_chroma_pixels_tab[3];
+ h264_chroma_mc_func avg_h264_chroma_pixels_tab[3];
+
+ qpel_mc_func put_h264_qpel_pixels_tab[4][16];
+ qpel_mc_func avg_h264_qpel_pixels_tab[4][16];
+
+ 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];
+ void (*cavs_filter_lv)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
+ void (*cavs_filter_lh)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
+ void (*cavs_filter_cv)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
+ void (*cavs_filter_ch)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
+ void (*cavs_idct8_add)(uint8_t *dst, DCTELEM *block, int stride);
+
+ me_cmp_func pix_abs[2][4];
+
+ /* huffyuv specific */
+ void (*add_bytes)(uint8_t *dst/*align 16*/, uint8_t *src/*align 16*/, int w);
+ void (*diff_bytes)(uint8_t *dst/*align 16*/, uint8_t *src1/*align 16*/, uint8_t *src2/*align 1*/,int w);
+ /**
+ * subtract huffyuv's variant of median prediction
+ * 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 (*bswap_buf)(uint32_t *dst, uint32_t *src, int w);
+
+ void (*h264_v_loop_filter_luma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0);
+ void (*h264_h_loop_filter_luma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0);
+ void (*h264_v_loop_filter_chroma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0);
+ void (*h264_h_loop_filter_chroma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0);
+ void (*h264_v_loop_filter_chroma_intra)(uint8_t *pix, int stride, int alpha, int beta);
+ void (*h264_h_loop_filter_chroma_intra)(uint8_t *pix, 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);
+
+ void (*h263_v_loop_filter)(uint8_t *src, int stride, int qscale);
+ void (*h263_h_loop_filter)(uint8_t *src, int stride, int qscale);
+
+ void (*h261_loop_filter)(uint8_t *src, int stride);
+
+ /* assume len is a multiple of 4, and arrays are 16-byte aligned */
+ void (*vorbis_inverse_coupling)(float *mag, float *ang, int blocksize);
+ /* 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);
+
+ /* 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 */
+ void (*float_to_int16)(int16_t *dst, const float *src, int len);
+
+ /* (I)DCT */
+ void (*fdct)(DCTELEM *block/* align 16*/);
+ void (*fdct248)(DCTELEM *block/* align 16*/);
+
+ /* IDCT really*/
+ void (*idct)(DCTELEM *block/* align 16*/);
+
+ /**
+ * block -> idct -> clip to unsigned 8 bit -> dest.
+ * (-1392, 0, 0, ...) -> idct -> (-174, -174, ...) -> put -> (0, 0, ...)
+ * @param line_size size in bytes of a horizotal line of dest
+ */
+ void (*idct_put)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
+
+ /**
+ * block -> idct -> add dest -> clip to unsigned 8 bit -> dest.
+ * @param line_size size in bytes of a horizotal line of dest
+ */
+ void (*idct_add)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
+
+ /**
+ * idct input permutation.
+ * several optimized IDCTs need a permutated input (relative to the normal order of the reference
+ * IDCT)
+ * this permutation must be performed before the idct_put/add, note, normally this can be merged
+ * with the zigzag/alternate scan<br>
+ * an example to avoid confusion:
+ * - (->decode coeffs -> zigzag reorder -> dequant -> reference idct ->...)
+ * - (x -> referece dct -> reference idct -> x)
+ * - (x -> referece dct -> simple_mmx_perm = idct_permutation -> simple_idct_mmx -> x)
+ * - (->decode coeffs -> zigzag reorder -> simple_mmx_perm -> dequant -> simple_idct_mmx ->...)
+ */
+ uint8_t idct_permutation[64];
+ int idct_permutation_type;
+#define FF_NO_IDCT_PERM 1
+#define FF_LIBMPEG2_IDCT_PERM 2
+#define FF_SIMPLE_IDCT_PERM 3
+#define FF_TRANSPOSE_IDCT_PERM 4
+#define FF_PARTTRANS_IDCT_PERM 5
+
+ int (*try_8x8basis)(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale);
+ void (*add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale);
+#define BASIS_SHIFT 16
+#define RECON_SHIFT 6
+
+ /* h264 functions */
+ void (*h264_idct_add)(uint8_t *dst, DCTELEM *block, int stride);
+ void (*h264_idct8_add)(uint8_t *dst, DCTELEM *block, int stride);
+ void (*h264_idct_dc_add)(uint8_t *dst, DCTELEM *block, int stride);
+ void (*h264_idct8_dc_add)(uint8_t *dst, DCTELEM *block, int stride);
+ void (*h264_dct)(DCTELEM block[4][4]);
+
+ /* snow wavelet */
+ void (*vertical_compose97i)(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWTELEM *b3, DWTELEM *b4, DWTELEM *b5, int width);
+ void (*horizontal_compose97i)(DWTELEM *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);
+
+ /* vc1 functions */
+ void (*vc1_inv_trans_8x8)(DCTELEM *b);
+ void (*vc1_inv_trans_8x4)(DCTELEM *b, int n);
+ void (*vc1_inv_trans_4x8)(DCTELEM *b, int n);
+ void (*vc1_inv_trans_4x4)(DCTELEM *b, int n);
+ void (*vc1_v_overlap)(uint8_t* src, int stride);
+ void (*vc1_h_overlap)(uint8_t* src, int stride);
+ /* put 8x8 block with bicubic interpolation and quarterpel precision
+ * last argument is actually round value instead of height
+ */
+ op_pixels_func put_vc1_mspel_pixels_tab[16];
+} DSPContext;
+
+void dsputil_static_init(void);
+void dsputil_init(DSPContext* p, AVCodecContext *avctx);
+
+int ff_check_alignment(void);
+
+/**
+ * permute block according to permuatation.
+ * @param last last non zero element in scantable order
+ */
+void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last);
+
+void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type);
+
+#define BYTE_VEC32(c) ((c)*0x01010101UL)
+
+static inline uint32_t rnd_avg32(uint32_t a, uint32_t b)
+{
+ return (a | b) - (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
+}
+
+static inline uint32_t no_rnd_avg32(uint32_t a, uint32_t b)
+{
+ return (a & b) + (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
+}
+
+static inline int get_penalty_factor(int lambda, int lambda2, int type){
+ switch(type&0xFF){
+ default:
+ case FF_CMP_SAD:
+ return lambda>>FF_LAMBDA_SHIFT;
+ case FF_CMP_DCT:
+ return (3*lambda)>>(FF_LAMBDA_SHIFT+1);
+ case FF_CMP_W53:
+ return (4*lambda)>>(FF_LAMBDA_SHIFT);
+ case FF_CMP_W97:
+ return (2*lambda)>>(FF_LAMBDA_SHIFT);
+ case FF_CMP_SATD:
+ case FF_CMP_DCT264:
+ return (2*lambda)>>FF_LAMBDA_SHIFT;
+ case FF_CMP_RD:
+ case FF_CMP_PSNR:
+ case FF_CMP_SSE:
+ case FF_CMP_NSSE:
+ return lambda2>>FF_LAMBDA_SHIFT;
+ case FF_CMP_BIT:
+ return 1;
+ }
+}
+
+/**
+ * Empty mmx state.
+ * this must be called between any dsp function and float/double code.
+ * for example sin(); dsp->idct_put(); emms_c(); cos()
+ */
+#define emms_c()
+
+/* should be defined by architectures supporting
+ one or more MultiMedia extension */
+int mm_support(void);
+
+#ifdef __GNUC__
+ #define DECLARE_ALIGNED_16(t,v) t v __attribute__ ((aligned (16)))
+#else
+ #define DECLARE_ALIGNED_16(t,v) __declspec(align(16)) t v
+#endif
+
+#if defined(HAVE_MMX)
+
+#undef emms_c
+
+#define MM_MMX 0x0001 /* standard MMX */
+#define MM_3DNOW 0x0004 /* AMD 3DNOW */
+#define MM_MMXEXT 0x0002 /* SSE integer functions or AMD MMX ext */
+#define MM_SSE 0x0008 /* SSE functions */
+#define MM_SSE2 0x0010 /* PIV SSE2 functions */
+#define MM_3DNOWEXT 0x0020 /* AMD 3DNowExt */
+#define MM_SSE3 0x0040 /* Prescott SSE3 functions */
+#define MM_SSSE3 0x0080 /* Conroe SSSE3 functions */
+
+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");
+}
+
+
+#define emms_c() \
+{\
+ if (mm_flags & MM_MMX)\
+ emms();\
+}
+
+#ifdef __GNUC__
+ #define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8)))
+#else
+ #define DECLARE_ALIGNED_8(t,v) __declspec(align(8)) t v
+#endif
+
+#define STRIDE_ALIGN 8
+
+void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx);
+void dsputil_init_pix_mmx(DSPContext* c, AVCodecContext *avctx);
+
+#elif defined(ARCH_ARMV4L)
+
+/* This is to use 4 bytes read to the IDCT pointers for some 'zero'
+ line optimizations */
+#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (4)))
+#define STRIDE_ALIGN 4
+
+#define MM_IWMMXT 0x0100 /* XScale IWMMXT */
+
+extern int mm_flags;
+
+void dsputil_init_armv4l(DSPContext* c, AVCodecContext *avctx);
+
+#elif defined(HAVE_MLIB)
+
+/* SPARC/VIS IDCT needs 8-byte aligned DCT blocks */
+#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8)))
+#define STRIDE_ALIGN 8
+
+void dsputil_init_mlib(DSPContext* c, AVCodecContext *avctx);
+
+#elif defined(ARCH_SPARC)
+
+/* SPARC/VIS IDCT needs 8-byte aligned DCT blocks */
+#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8)))
+#define STRIDE_ALIGN 8
+void dsputil_init_vis(DSPContext* c, AVCodecContext *avctx);
+
+#elif defined(ARCH_ALPHA)
+
+#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8)))
+#define STRIDE_ALIGN 8
+
+void dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx);
+
+#elif defined(ARCH_POWERPC)
+
+#define MM_ALTIVEC 0x0001 /* standard AltiVec */
+
+extern int mm_flags;
+
+#if defined(HAVE_ALTIVEC) && !defined(CONFIG_DARWIN)
+#define pixel altivec_pixel
+#include <altivec.h>
+#undef pixel
+#endif
+
+#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (16)))
+#define STRIDE_ALIGN 16
+
+void dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx);
+
+#elif defined(HAVE_MMI)
+
+#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (16)))
+#define STRIDE_ALIGN 16
+
+void dsputil_init_mmi(DSPContext* c, AVCodecContext *avctx);
+
+#elif defined(ARCH_SH4)
+
+#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8)))
+#define STRIDE_ALIGN 8
+
+void dsputil_init_sh4(DSPContext* c, AVCodecContext *avctx);
+
+#elif defined(ARCH_BFIN)
+
+#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8)))
+#define STRIDE_ALIGN 8
+
+void dsputil_init_bfin(DSPContext* c, AVCodecContext *avctx);
+
+#else
+
+#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8)))
+#define STRIDE_ALIGN 8
+
+#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 */
+ void (*fft_calc)(struct FFTContext *s, FFTComplex *z);
+ void (*imdct_calc)(struct MDCTContext *s, FFTSample *output,
+ const FFTSample *input, FFTSample *tmp);
+} FFTContext;
+
+int ff_fft_init(FFTContext *s, int nbits, int inverse);
+void ff_fft_permute(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);
+
+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;
+
+int ff_mdct_init(MDCTContext *s, int nbits, int inverse);
+void ff_imdct_calc(MDCTContext *s, FFTSample *output,
+ const FFTSample *input, FFTSample *tmp);
+void ff_imdct_calc_3dn2(MDCTContext *s, FFTSample *output,
+ const FFTSample *input, FFTSample *tmp);
+void ff_imdct_calc_sse(MDCTContext *s, FFTSample *output,
+ const FFTSample *input, FFTSample *tmp);
+void ff_mdct_calc(MDCTContext *s, FFTSample *out,
+ const FFTSample *input, FFTSample *tmp);
+void ff_mdct_end(MDCTContext *s);
+
+#define WARPER8_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)\
+ +name8(s, dst+8 , src+8 , stride, h);\
+}
+
+#define WARPER8_16_SQ(name8, name16)\
+static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\
+ int score=0;\
+ score +=name8(s, dst , src , stride, 8);\
+ score +=name8(s, dst+8 , src+8 , stride, 8);\
+ if(h==16){\
+ dst += 8*stride;\
+ src += 8*stride;\
+ score +=name8(s, dst , src , stride, 8);\
+ score +=name8(s, dst+8 , src+8 , stride, 8);\
+ }\
+ return score;\
+}
+
+
+static inline void copy_block2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
+{
+ int i;
+ for(i=0; i<h; i++)
+ {
+ ST16(dst , LD16(src ));
+ dst+=dstStride;
+ src+=srcStride;
+ }
+}
+
+static inline void copy_block4(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
+{
+ int i;
+ for(i=0; i<h; i++)
+ {
+ ST32(dst , LD32(src ));
+ dst+=dstStride;
+ src+=srcStride;
+ }
+}
+
+static inline void copy_block8(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
+{
+ int i;
+ for(i=0; i<h; i++)
+ {
+ ST32(dst , LD32(src ));
+ ST32(dst+4 , LD32(src+4 ));
+ dst+=dstStride;
+ src+=srcStride;
+ }
+}
+
+static inline void copy_block9(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
+{
+ int i;
+ for(i=0; i<h; i++)
+ {
+ ST32(dst , LD32(src ));
+ ST32(dst+4 , LD32(src+4 ));
+ dst[8]= src[8];
+ dst+=dstStride;
+ src+=srcStride;
+ }
+}
+
+static inline void copy_block16(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
+{
+ int i;
+ for(i=0; i<h; i++)
+ {
+ ST32(dst , LD32(src ));
+ ST32(dst+4 , LD32(src+4 ));
+ ST32(dst+8 , LD32(src+8 ));
+ ST32(dst+12, LD32(src+12));
+ dst+=dstStride;
+ src+=srcStride;
+ }
+}
+
+static inline void copy_block17(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
+{
+ int i;
+ for(i=0; i<h; i++)
+ {
+ ST32(dst , LD32(src ));
+ ST32(dst+4 , LD32(src+4 ));
+ ST32(dst+8 , LD32(src+8 ));
+ ST32(dst+12, LD32(src+12));
+ dst[16]= src[16];
+ dst+=dstStride;
+ src+=srcStride;
+ }
+}
+
+#endif
diff --git a/contrib/ffmpeg/libavcodec/dtsdec.c b/contrib/ffmpeg/libavcodec/dtsdec.c
new file mode 100644
index 000000000..6763572dd
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/dtsdec.c
@@ -0,0 +1,268 @@
+/*
+ * dtsdec.c : free DTS Coherent Acoustics stream decoder.
+ * Copyright (C) 2004 Benjamin Zores <ben@geexbox.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avcodec.h"
+#include <dts.h>
+
+#include <stdlib.h>
+#include <string.h>
+
+#define BUFFER_SIZE 18726
+#define HEADER_SIZE 14
+
+#define CONVERT_LEVEL 1
+#define CONVERT_BIAS 0
+
+typedef struct DTSContext {
+ dts_state_t *state;
+ uint8_t buf[BUFFER_SIZE];
+ uint8_t *bufptr;
+ uint8_t *bufpos;
+} DTSContext;
+
+static inline int16_t
+convert(sample_t s)
+{
+ return s * 0x7fff;
+}
+
+static void
+convert2s16_multi(sample_t *f, int16_t *s16, int flags)
+{
+ int i;
+
+ switch(flags & (DTS_CHANNEL_MASK | DTS_LFE)){
+ case DTS_MONO:
+ for(i = 0; i < 256; i++){
+ s16[5*i] = s16[5*i+1] = s16[5*i+2] = s16[5*i+3] = 0;
+ s16[5*i+4] = convert(f[i]);
+ }
+ case DTS_CHANNEL:
+ case DTS_STEREO:
+ case DTS_DOLBY:
+ for(i = 0; i < 256; i++){
+ s16[2*i] = convert(f[i]);
+ s16[2*i+1] = convert(f[i+256]);
+ }
+ case DTS_3F:
+ for(i = 0; i < 256; i++){
+ s16[5*i] = convert(f[i+256]);
+ s16[5*i+1] = convert(f[i+512]);
+ s16[5*i+2] = s16[5*i+3] = 0;
+ s16[5*i+4] = convert(f[i]);
+ }
+ case DTS_2F2R:
+ for(i = 0; i < 256; i++){
+ s16[4*i] = convert(f[i]);
+ s16[4*i+1] = convert(f[i+256]);
+ s16[4*i+2] = convert(f[i+512]);
+ s16[4*i+3] = convert(f[i+768]);
+ }
+ case DTS_3F2R:
+ for(i = 0; i < 256; i++){
+ s16[5*i] = convert(f[i+256]);
+ s16[5*i+1] = convert(f[i+512]);
+ s16[5*i+2] = convert(f[i+768]);
+ s16[5*i+3] = convert(f[i+1024]);
+ s16[5*i+4] = convert(f[i]);
+ }
+ case DTS_MONO | DTS_LFE:
+ for(i = 0; i < 256; i++){
+ s16[6*i] = s16[6*i+1] = s16[6*i+2] = s16[6*i+3] = 0;
+ s16[6*i+4] = convert(f[i]);
+ s16[6*i+5] = convert(f[i+256]);
+ }
+ case DTS_CHANNEL | DTS_LFE:
+ case DTS_STEREO | DTS_LFE:
+ case DTS_DOLBY | DTS_LFE:
+ for(i = 0; i < 256; i++){
+ s16[6*i] = convert(f[i]);
+ s16[6*i+1] = convert(f[i+256]);
+ s16[6*i+2] = s16[6*i+3] = s16[6*i+4] = 0;
+ s16[6*i+5] = convert(f[i+512]);
+ }
+ case DTS_3F | DTS_LFE:
+ for(i = 0; i < 256; i++){
+ s16[6*i] = convert(f[i+256]);
+ s16[6*i+1] = convert(f[i+512]);
+ s16[6*i+2] = s16[6*i+3] = 0;
+ s16[6*i+4] = convert(f[i]);
+ s16[6*i+5] = convert(f[i+768]);
+ }
+ case DTS_2F2R | DTS_LFE:
+ for(i = 0; i < 256; i++){
+ s16[6*i] = convert(f[i]);
+ s16[6*i+1] = convert(f[i+256]);
+ s16[6*i+2] = convert(f[i+512]);
+ s16[6*i+3] = convert(f[i+768]);
+ s16[6*i+4] = 0;
+ s16[6*i+5] = convert(f[i+1024]);
+ }
+ case DTS_3F2R | DTS_LFE:
+ for(i = 0; i < 256; i++){
+ s16[6*i] = convert(f[i+256]);
+ s16[6*i+1] = convert(f[i+512]);
+ s16[6*i+2] = convert(f[i+768]);
+ s16[6*i+3] = convert(f[i+1024]);
+ s16[6*i+4] = convert(f[i]);
+ s16[6*i+5] = convert(f[i+1280]);
+ }
+ }
+}
+
+static int
+channels_multi(int flags)
+{
+ switch(flags & (DTS_CHANNEL_MASK | DTS_LFE)){
+ case DTS_CHANNEL:
+ case DTS_STEREO:
+ case DTS_DOLBY:
+ return 2;
+ case DTS_2F2R:
+ return 4;
+ case DTS_MONO:
+ case DTS_3F:
+ case DTS_3F2R:
+ return 5;
+ case DTS_MONO | DTS_LFE:
+ case DTS_CHANNEL | DTS_LFE:
+ case DTS_STEREO | DTS_LFE:
+ case DTS_DOLBY | DTS_LFE:
+ case DTS_3F | DTS_LFE:
+ case DTS_2F2R | DTS_LFE:
+ case DTS_3F2R | DTS_LFE:
+ return 6;
+ }
+
+ return -1;
+}
+
+static int
+dts_decode_frame(AVCodecContext * avctx, void *data, int *data_size,
+ uint8_t * buff, int buff_size)
+{
+ DTSContext *s = avctx->priv_data;
+ uint8_t *start = buff;
+ uint8_t *end = buff + buff_size;
+ int16_t *out_samples = data;
+ int sample_rate;
+ int frame_length;
+ int flags;
+ int bit_rate;
+ int len;
+ level_t level;
+ sample_t bias;
+ int nblocks;
+ int i;
+
+ *data_size = 0;
+
+ while(1) {
+ int length;
+
+ len = end - start;
+ if(!len)
+ break;
+ if(len > s->bufpos - s->bufptr)
+ len = s->bufpos - s->bufptr;
+ memcpy(s->bufptr, start, len);
+ s->bufptr += len;
+ start += len;
+ if(s->bufptr != s->bufpos)
+ return start - buff;
+ if(s->bufpos != s->buf + HEADER_SIZE)
+ break;
+
+ length = dts_syncinfo(s->state, s->buf, &flags, &sample_rate,
+ &bit_rate, &frame_length);
+ if(!length) {
+ av_log(NULL, AV_LOG_INFO, "skip\n");
+ for(s->bufptr = s->buf; s->bufptr < s->buf + HEADER_SIZE - 1; s->bufptr++)
+ s->bufptr[0] = s->bufptr[1];
+ continue;
+ }
+ s->bufpos = s->buf + length;
+ }
+
+ level = CONVERT_LEVEL;
+ bias = CONVERT_BIAS;
+
+ flags |= DTS_ADJUST_LEVEL;
+ if(dts_frame(s->state, s->buf, &flags, &level, bias)) {
+ av_log(avctx, AV_LOG_ERROR, "dts_frame() failed\n");
+ goto end;
+ }
+
+ avctx->sample_rate = sample_rate;
+ avctx->channels = channels_multi(flags);
+ avctx->bit_rate = bit_rate;
+
+ nblocks = dts_blocks_num(s->state);
+
+ for(i = 0; i < nblocks; i++) {
+ if(dts_block(s->state)) {
+ av_log(avctx, AV_LOG_ERROR, "dts_block() failed\n");
+ goto end;
+ }
+
+ convert2s16_multi(dts_samples(s->state), out_samples, flags);
+
+ out_samples += 256 * avctx->channels;
+ *data_size += 256 * sizeof(int16_t) * avctx->channels;
+ }
+
+end:
+ s->bufptr = s->buf;
+ s->bufpos = s->buf + HEADER_SIZE;
+ return start - buff;
+}
+
+static int
+dts_decode_init(AVCodecContext * avctx)
+{
+ DTSContext *s = avctx->priv_data;
+ s->bufptr = s->buf;
+ s->bufpos = s->buf + HEADER_SIZE;
+ s->state = dts_init(0);
+ if(s->state == NULL)
+ return -1;
+
+ return 0;
+}
+
+static int
+dts_decode_end(AVCodecContext * avctx)
+{
+ DTSContext *s = avctx->priv_data;
+ dts_free(s->state);
+ return 0;
+}
+
+AVCodec dts_decoder = {
+ "dts",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_DTS,
+ sizeof(DTSContext),
+ dts_decode_init,
+ NULL,
+ dts_decode_end,
+ dts_decode_frame,
+};
diff --git a/contrib/ffmpeg/libavcodec/dv.c b/contrib/ffmpeg/libavcodec/dv.c
new file mode 100644
index 000000000..19615b431
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/dv.c
@@ -0,0 +1,1259 @@
+/*
+ * DV decoder
+ * Copyright (c) 2002 Fabrice Bellard.
+ * Copyright (c) 2004 Roman Shaposhnik.
+ *
+ * DV encoder
+ * Copyright (c) 2003 Roman Shaposhnik.
+ *
+ * 50 Mbps (DVCPRO50) support
+ * Copyright (c) 2006 Daniel Maas <dmaas@maasdigital.com>
+ *
+ * Many thanks to Dan Dennedy <dan@dennedy.org> for providing wealth
+ * of DV technical info.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 dv.c
+ * DV codec.
+ */
+#define ALT_BITSTREAM_READER
+#include "avcodec.h"
+#include "dsputil.h"
+#include "mpegvideo.h"
+#include "simple_idct.h"
+#include "dvdata.h"
+
+//#undef NDEBUG
+//#include <assert.h>
+
+typedef struct DVVideoContext {
+ const DVprofile* sys;
+ AVFrame picture;
+ AVCodecContext *avctx;
+ uint8_t *buf;
+
+ uint8_t dv_zigzag[2][64];
+ uint8_t dv_idct_shift[2][2][22][64];
+
+ void (*get_pixels)(DCTELEM *block, const uint8_t *pixels, int line_size);
+ void (*fdct[2])(DCTELEM *block);
+ void (*idct_put[2])(uint8_t *dest, int line_size, DCTELEM *block);
+} DVVideoContext;
+
+/* MultiThreading - dv_anchor applies to entire DV codec, not just the avcontext */
+/* one element is needed for each video segment in a DV frame */
+/* at most there are 2 DIF channels * 12 DIF sequences * 27 video segments (PAL 50Mbps) */
+#define DV_ANCHOR_SIZE (2*12*27)
+
+static void* dv_anchor[DV_ANCHOR_SIZE];
+
+#define TEX_VLC_BITS 9
+
+#ifdef DV_CODEC_TINY_TARGET
+#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 void dv_build_unquantize_tables(DVVideoContext *s, uint8_t* perm)
+{
+ int i, q, j;
+
+ /* NOTE: max left shift is 6 */
+ for(q = 0; q < 22; q++) {
+ /* 88DCT */
+ for(i = 1; i < 64; i++) {
+ /* 88 table */
+ j = perm[i];
+ s->dv_idct_shift[0][0][q][j] =
+ dv_quant_shifts[q][dv_88_areas[i]] + 1;
+ s->dv_idct_shift[1][0][q][j] = s->dv_idct_shift[0][0][q][j] + 1;
+ }
+
+ /* 248DCT */
+ for(i = 1; i < 64; i++) {
+ /* 248 table */
+ s->dv_idct_shift[0][1][q][i] =
+ dv_quant_shifts[q][dv_248_areas[i]] + 1;
+ s->dv_idct_shift[1][1][q][i] = s->dv_idct_shift[0][1][q][i] + 1;
+ }
+ }
+}
+
+static int dvvideo_init(AVCodecContext *avctx)
+{
+ DVVideoContext *s = avctx->priv_data;
+ DSPContext dsp;
+ static int done=0;
+ int i, j;
+
+ if (!done) {
+ VLC dv_vlc;
+ uint16_t new_dv_vlc_bits[NB_DV_VLC*2];
+ uint8_t new_dv_vlc_len[NB_DV_VLC*2];
+ uint8_t new_dv_vlc_run[NB_DV_VLC*2];
+ int16_t new_dv_vlc_level[NB_DV_VLC*2];
+
+ done = 1;
+
+ /* dv_anchor lets each thread know its Id */
+ for (i=0; i<DV_ANCHOR_SIZE; i++)
+ dv_anchor[i] = (void*)(size_t)i;
+
+ /* it's faster to include sign bit in a generic VLC parsing scheme */
+ for (i=0, j=0; i<NB_DV_VLC; i++, j++) {
+ new_dv_vlc_bits[j] = dv_vlc_bits[i];
+ new_dv_vlc_len[j] = dv_vlc_len[i];
+ new_dv_vlc_run[j] = dv_vlc_run[i];
+ new_dv_vlc_level[j] = dv_vlc_level[i];
+
+ if (dv_vlc_level[i]) {
+ new_dv_vlc_bits[j] <<= 1;
+ new_dv_vlc_len[j]++;
+
+ j++;
+ new_dv_vlc_bits[j] = (dv_vlc_bits[i] << 1) | 1;
+ new_dv_vlc_len[j] = dv_vlc_len[i] + 1;
+ new_dv_vlc_run[j] = dv_vlc_run[i];
+ new_dv_vlc_level[j] = -dv_vlc_level[i];
+ }
+ }
+
+ /* NOTE: as a trick, we use the fact the no codes are unused
+ to accelerate the parsing of partial codes */
+ init_vlc(&dv_vlc, TEX_VLC_BITS, j,
+ new_dv_vlc_len, 1, 1, new_dv_vlc_bits, 2, 2, 0);
+ assert(dv_vlc.table_size == 1184);
+
+ for(i = 0; i < dv_vlc.table_size; i++){
+ int code= dv_vlc.table[i][0];
+ int len = dv_vlc.table[i][1];
+ int level, run;
+
+ if(len<0){ //more bits needed
+ run= 0;
+ level= code;
+ } else {
+ run= new_dv_vlc_run[code] + 1;
+ level= new_dv_vlc_level[code];
+ }
+ dv_rl_vlc[i].len = len;
+ dv_rl_vlc[i].level = level;
+ dv_rl_vlc[i].run = run;
+ }
+ free_vlc(&dv_vlc);
+
+ for (i = 0; i < NB_DV_VLC - 1; i++) {
+ if (dv_vlc_run[i] >= DV_VLC_MAP_RUN_SIZE)
+ continue;
+#ifdef DV_CODEC_TINY_TARGET
+ 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++) {
+#ifdef DV_CODEC_TINY_TARGET
+ 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
+ }
+ }
+
+ /* Generic DSP setup */
+ dsputil_init(&dsp, avctx);
+ s->get_pixels = dsp.get_pixels;
+
+ /* 88DCT setup */
+ s->fdct[0] = dsp.fdct;
+ s->idct_put[0] = dsp.idct_put;
+ for (i=0; i<64; i++)
+ s->dv_zigzag[0][i] = dsp.idct_permutation[ff_zigzag_direct[i]];
+
+ /* 248DCT setup */
+ s->fdct[1] = dsp.fdct248;
+ s->idct_put[1] = simple_idct248_put; // FIXME: need to add it to DSP
+ if(avctx->lowres){
+ for (i=0; i<64; i++){
+ int j= ff_zigzag248_direct[i];
+ s->dv_zigzag[1][i] = dsp.idct_permutation[(j&7) + (j&8)*4 + (j&48)/2];
+ }
+ }else
+ memcpy(s->dv_zigzag[1], ff_zigzag248_direct, 64);
+
+ /* XXX: do it only for constant case */
+ dv_build_unquantize_tables(s, dsp.idct_permutation);
+
+ avctx->coded_frame = &s->picture;
+ s->avctx= avctx;
+
+ return 0;
+}
+
+// #define VLC_DEBUG
+// #define printf(...) av_log(NULL, AV_LOG_ERROR, __VA_ARGS__)
+
+typedef struct BlockInfo {
+ const uint8_t *shift_table;
+ const uint8_t *scan_table;
+ const int *iweight_table;
+ uint8_t pos; /* position in block */
+ uint8_t dct_mode;
+ uint8_t partial_bit_count;
+ uint16_t partial_bit_buffer;
+ int shift_offset;
+} BlockInfo;
+
+/* block size in bits */
+static const uint16_t block_sizes[6] = {
+ 112, 112, 112, 112, 80, 80
+};
+/* bit budget for AC only in 5 MBs */
+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 get_bits_size(GetBitContext *s)
+{
+ return s->size_in_bits;
+}
+
+static inline int put_bits_left(PutBitContext* s)
+{
+ return (s->buf_end - s->buf) * 8 - put_bits_count(s);
+}
+
+/* decode ac coefs */
+static void dv_decode_ac(GetBitContext *gb, BlockInfo *mb, DCTELEM *block)
+{
+ int last_index = get_bits_size(gb);
+ const uint8_t *scan_table = mb->scan_table;
+ const uint8_t *shift_table = mb->shift_table;
+ const int *iweight_table = mb->iweight_table;
+ int pos = mb->pos;
+ int partial_bit_count = mb->partial_bit_count;
+ int level, pos1, run, vlc_len, index;
+
+ OPEN_READER(re, gb);
+ UPDATE_CACHE(re, gb);
+
+ /* if we must parse a partial vlc, we do it here */
+ if (partial_bit_count > 0) {
+ re_cache = ((unsigned)re_cache >> partial_bit_count) |
+ (mb->partial_bit_buffer << (sizeof(re_cache)*8 - partial_bit_count));
+ re_index -= partial_bit_count;
+ mb->partial_bit_count = 0;
+ }
+
+ /* get the AC coefficients until last_index is reached */
+ for(;;) {
+#ifdef VLC_DEBUG
+ printf("%2d: bits=%04x index=%d\n", pos, SHOW_UBITS(re, gb, 16), re_index);
+#endif
+ /* our own optimized GET_RL_VLC */
+ index = NEG_USR32(re_cache, TEX_VLC_BITS);
+ vlc_len = dv_rl_vlc[index].len;
+ if (vlc_len < 0) {
+ index = NEG_USR32((unsigned)re_cache << TEX_VLC_BITS, -vlc_len) + dv_rl_vlc[index].level;
+ vlc_len = TEX_VLC_BITS - vlc_len;
+ }
+ level = dv_rl_vlc[index].level;
+ run = dv_rl_vlc[index].run;
+
+ /* gotta check if we're still within gb boundaries */
+ if (re_index + vlc_len > last_index) {
+ /* should be < 16 bits otherwise a codeword could have been parsed */
+ mb->partial_bit_count = last_index - re_index;
+ mb->partial_bit_buffer = NEG_USR32(re_cache, mb->partial_bit_count);
+ re_index = last_index;
+ break;
+ }
+ re_index += vlc_len;
+
+#ifdef VLC_DEBUG
+ printf("run=%d level=%d\n", run, level);
+#endif
+ pos += run;
+ if (pos >= 64)
+ break;
+
+ pos1 = scan_table[pos];
+ level <<= shift_table[pos1];
+
+ /* unweigh, round, and shift down */
+ level = (level*iweight_table[pos] + (1 << (dv_iweight_bits-1))) >> dv_iweight_bits;
+
+ block[pos1] = level;
+
+ UPDATE_CACHE(re, gb);
+ }
+ CLOSE_READER(re, gb);
+ mb->pos = pos;
+}
+
+static inline void bit_copy(PutBitContext *pb, GetBitContext *gb)
+{
+ int bits_left = get_bits_left(gb);
+ while (bits_left >= MIN_CACHE_BITS) {
+ put_bits(pb, MIN_CACHE_BITS, get_bits(gb, MIN_CACHE_BITS));
+ bits_left -= MIN_CACHE_BITS;
+ }
+ if (bits_left > 0) {
+ put_bits(pb, bits_left, get_bits(gb, bits_left));
+ }
+}
+
+/* mb_x and mb_y are in units of 8 pixels */
+static inline void dv_decode_video_segment(DVVideoContext *s,
+ uint8_t *buf_ptr1,
+ const uint16_t *mb_pos_ptr)
+{
+ int quant, dc, dct_mode, class1, j;
+ int mb_index, mb_x, mb_y, v, last_index;
+ DCTELEM *block, *block1;
+ int c_offset;
+ uint8_t *y_ptr;
+ void (*idct_put)(uint8_t *dest, int line_size, DCTELEM *block);
+ uint8_t *buf_ptr;
+ PutBitContext pb, vs_pb;
+ GetBitContext gb;
+ BlockInfo mb_data[5 * 6], *mb, *mb1;
+ DECLARE_ALIGNED_8(DCTELEM, sblock[5*6][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 */
+ const int log2_blocksize= 3-s->avctx->lowres;
+
+ assert((((int)mb_bit_buffer)&7)==0);
+ assert((((int)vs_bit_buffer)&7)==0);
+
+ memset(sblock, 0, sizeof(sblock));
+
+ /* pass 1 : read DC and AC coefficients in blocks */
+ buf_ptr = buf_ptr1;
+ block1 = &sblock[0][0];
+ mb1 = mb_data;
+ init_put_bits(&vs_pb, vs_bit_buffer, 5 * 80);
+ for(mb_index = 0; mb_index < 5; mb_index++, mb1 += 6, block1 += 6 * 64) {
+ /* skip header */
+ quant = buf_ptr[3] & 0x0f;
+ buf_ptr += 4;
+ init_put_bits(&pb, mb_bit_buffer, 80);
+ mb = mb1;
+ block = block1;
+ for(j = 0;j < 6; j++) {
+ last_index = block_sizes[j];
+ init_get_bits(&gb, buf_ptr, last_index);
+
+ /* get the dc */
+ dc = get_sbits(&gb, 9);
+ dct_mode = get_bits1(&gb);
+ mb->dct_mode = dct_mode;
+ mb->scan_table = s->dv_zigzag[dct_mode];
+ mb->iweight_table = dct_mode ? dv_iweight_248 : dv_iweight_88;
+ class1 = get_bits(&gb, 2);
+ mb->shift_table = s->dv_idct_shift[class1 == 3][dct_mode]
+ [quant + dv_quant_offset[class1]];
+ dc = dc << 2;
+ /* convert to unsigned because 128 is not added in the
+ standard IDCT */
+ dc += 1024;
+ block[0] = dc;
+ buf_ptr += last_index >> 3;
+ mb->pos = 0;
+ mb->partial_bit_count = 0;
+
+#ifdef VLC_DEBUG
+ printf("MB block: %d, %d ", mb_index, j);
+#endif
+ dv_decode_ac(&gb, mb, block);
+
+ /* write the remaining bits in a new buffer only if the
+ block is finished */
+ if (mb->pos >= 64)
+ bit_copy(&pb, &gb);
+
+ block += 64;
+ mb++;
+ }
+
+ /* pass 2 : we can do it just after */
+#ifdef VLC_DEBUG
+ printf("***pass 2 size=%d MB#=%d\n", put_bits_count(&pb), mb_index);
+#endif
+ block = block1;
+ mb = mb1;
+ init_get_bits(&gb, mb_bit_buffer, put_bits_count(&pb));
+ flush_put_bits(&pb);
+ for(j = 0;j < 6; j++, block += 64, mb++) {
+ if (mb->pos < 64 && get_bits_left(&gb) > 0) {
+ dv_decode_ac(&gb, mb, block);
+ /* if still not finished, no need to parse other blocks */
+ if (mb->pos < 64)
+ break;
+ }
+ }
+ /* all blocks are finished, so the extra bytes can be used at
+ the video segment level */
+ if (j >= 6)
+ bit_copy(&vs_pb, &gb);
+ }
+
+ /* we need a pass other the whole video segment */
+#ifdef VLC_DEBUG
+ printf("***pass 3 size=%d\n", put_bits_count(&vs_pb));
+#endif
+ block = &sblock[0][0];
+ mb = mb_data;
+ init_get_bits(&gb, vs_bit_buffer, put_bits_count(&vs_pb));
+ flush_put_bits(&vs_pb);
+ for(mb_index = 0; mb_index < 5; mb_index++) {
+ for(j = 0;j < 6; j++) {
+ if (mb->pos < 64) {
+#ifdef VLC_DEBUG
+ printf("start %d:%d\n", mb_index, j);
+#endif
+ 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);
+ block += 64;
+ mb++;
+ }
+ }
+
+ /* compute idct and place blocks */
+ block = &sblock[0][0];
+ mb = mb_data;
+ for(mb_index = 0; mb_index < 5; mb_index++) {
+ v = *mb_pos_ptr++;
+ mb_x = v & 0xff;
+ mb_y = v >> 8;
+ if (s->sys->pix_fmt == PIX_FMT_YUV422P) {
+ y_ptr = s->picture.data[0] + ((mb_y * s->picture.linesize[0] + (mb_x>>1))<<log2_blocksize);
+ c_offset = ((mb_y * s->picture.linesize[1] + (mb_x >> 2))<<log2_blocksize);
+ } else { /* 4:1:1 or 4:2:0 */
+ y_ptr = s->picture.data[0] + ((mb_y * s->picture.linesize[0] + mb_x)<<log2_blocksize);
+ if (s->sys->pix_fmt == PIX_FMT_YUV411P)
+ c_offset = ((mb_y * s->picture.linesize[1] + (mb_x >> 2))<<log2_blocksize);
+ else /* 4:2:0 */
+ c_offset = (((mb_y >> 1) * s->picture.linesize[1] + (mb_x >> 1))<<log2_blocksize);
+ }
+ for(j = 0;j < 6; j++) {
+ idct_put = s->idct_put[mb->dct_mode && log2_blocksize==3];
+ if (s->sys->pix_fmt == PIX_FMT_YUV422P) { /* 4:2:2 */
+ if (j == 0 || j == 2) {
+ /* Y0 Y1 */
+ idct_put(y_ptr + ((j >> 1)<<log2_blocksize),
+ s->picture.linesize[0], block);
+ } else if(j > 3) {
+ /* Cr Cb */
+ idct_put(s->picture.data[6 - j] + c_offset,
+ s->picture.linesize[6 - j], block);
+ }
+ /* note: j=1 and j=3 are "dummy" blocks in 4:2:2 */
+ } else { /* 4:1:1 or 4:2:0 */
+ if (j < 4) {
+ if (s->sys->pix_fmt == PIX_FMT_YUV411P && mb_x < (704 / 8)) {
+ /* NOTE: at end of line, the macroblock is handled as 420 */
+ idct_put(y_ptr + (j<<log2_blocksize), s->picture.linesize[0], block);
+ } else {
+ idct_put(y_ptr + (((j & 1) + (j >> 1) * s->picture.linesize[0])<<log2_blocksize),
+ s->picture.linesize[0], block);
+ }
+ } else {
+ if (s->sys->pix_fmt == PIX_FMT_YUV411P && mb_x >= (704 / 8)) {
+ uint64_t aligned_pixels[64/8];
+ uint8_t *pixels= (uint8_t*)aligned_pixels;
+ uint8_t *c_ptr, *c_ptr1, *ptr, *ptr1;
+ int x, y, linesize;
+ /* NOTE: at end of line, the macroblock is handled as 420 */
+ idct_put(pixels, 8, block);
+ linesize = s->picture.linesize[6 - j];
+ c_ptr = s->picture.data[6 - j] + c_offset;
+ ptr = pixels;
+ for(y = 0;y < (1<<log2_blocksize); y++) {
+ ptr1= ptr + (1<<(log2_blocksize-1));
+ c_ptr1 = c_ptr + (linesize<<log2_blocksize);
+ for(x=0; x < (1<<(log2_blocksize-1)); x++){
+ c_ptr[x]= ptr[x]; c_ptr1[x]= ptr1[x];
+ }
+ c_ptr += linesize;
+ ptr += 8;
+ }
+ } else {
+ /* don't ask me why they inverted Cb and Cr ! */
+ idct_put(s->picture.data[6 - j] + c_offset,
+ s->picture.linesize[6 - j], block);
+ }
+ }
+ }
+ block += 64;
+ mb++;
+ }
+ }
+}
+
+#ifdef DV_CODEC_TINY_TARGET
+/* Converts run and level (where level != 0) pair into vlc, returning bit size */
+static av_always_inline int dv_rl2vlc(int run, int level, int sign, uint32_t* vlc)
+{
+ int size;
+ if (run < DV_VLC_MAP_RUN_SIZE && level < DV_VLC_MAP_LEV_SIZE) {
+ *vlc = dv_vlc_map[run][level].vlc | sign;
+ size = dv_vlc_map[run][level].size;
+ }
+ else {
+ if (level < DV_VLC_MAP_LEV_SIZE) {
+ *vlc = dv_vlc_map[0][level].vlc | sign;
+ size = dv_vlc_map[0][level].size;
+ } else {
+ *vlc = 0xfe00 | (level << 1) | sign;
+ size = 16;
+ }
+ if (run) {
+ *vlc |= ((run < 16) ? dv_vlc_map[run-1][0].vlc :
+ (0x1f80 | (run - 1))) << size;
+ size += (run < 16) ? dv_vlc_map[run-1][0].size : 13;
+ }
+ }
+
+ return size;
+}
+
+static av_always_inline int dv_rl2vlc_size(int run, int level)
+{
+ int size;
+
+ if (run < DV_VLC_MAP_RUN_SIZE && level < DV_VLC_MAP_LEV_SIZE) {
+ size = dv_vlc_map[run][level].size;
+ }
+ else {
+ size = (level < DV_VLC_MAP_LEV_SIZE) ? dv_vlc_map[0][level].size : 16;
+ if (run) {
+ size += (run < 16) ? dv_vlc_map[run-1][0].size : 13;
+ }
+ }
+ return size;
+}
+#else
+static av_always_inline int dv_rl2vlc(int run, int l, int sign, uint32_t* vlc)
+{
+ *vlc = dv_vlc_map[run][l].vlc | sign;
+ return dv_vlc_map[run][l].size;
+}
+
+static av_always_inline int dv_rl2vlc_size(int run, int l)
+{
+ return dv_vlc_map[run][l].size;
+}
+#endif
+
+typedef struct EncBlockInfo {
+ int area_q[4];
+ int bit_size[4];
+ int prev[5];
+ int cur_ac;
+ int cno;
+ int dct_mode;
+ DCTELEM mb[64];
+ uint8_t next[64];
+ uint8_t sign[64];
+ uint8_t partial_bit_count;
+ uint32_t partial_bit_buffer; /* we can't use uint16_t here */
+} EncBlockInfo;
+
+static av_always_inline PutBitContext* dv_encode_ac(EncBlockInfo* bi, PutBitContext* pb_pool,
+ PutBitContext* pb_end)
+{
+ int prev;
+ int bits_left;
+ PutBitContext* pb = pb_pool;
+ int size = bi->partial_bit_count;
+ uint32_t vlc = bi->partial_bit_buffer;
+
+ bi->partial_bit_count = bi->partial_bit_buffer = 0;
+ for(;;){
+ /* Find suitable storage space */
+ for (; size > (bits_left = put_bits_left(pb)); pb++) {
+ if (bits_left) {
+ size -= bits_left;
+ put_bits(pb, bits_left, vlc >> size);
+ vlc = vlc & ((1<<size)-1);
+ }
+ if (pb + 1 >= pb_end) {
+ bi->partial_bit_count = size;
+ bi->partial_bit_buffer = vlc;
+ return pb;
+ }
+ }
+
+ /* Store VLC */
+ put_bits(pb, size, vlc);
+
+ if(bi->cur_ac>=64)
+ break;
+
+ /* Construct the next VLC */
+ prev= bi->cur_ac;
+ bi->cur_ac = bi->next[prev];
+ if(bi->cur_ac < 64){
+ size = dv_rl2vlc(bi->cur_ac - prev - 1, bi->mb[bi->cur_ac], bi->sign[bi->cur_ac], &vlc);
+ } else {
+ size = 4; vlc = 6; /* End Of Block stamp */
+ }
+ }
+ return pb;
+}
+
+static av_always_inline void dv_set_class_number(DCTELEM* blk, EncBlockInfo* bi,
+ const uint8_t* zigzag_scan, const int *weight, int bias)
+{
+ int i, area;
+ /* We offer two different methods for class number assignment: the
+ method suggested in SMPTE 314M Table 22, and an improved
+ method. The SMPTE method is very conservative; it assigns class
+ 3 (i.e. severe quantization) to any block where the largest AC
+ component is greater than 36. ffmpeg's DV encoder tracks AC bit
+ consumption precisely, so there is no need to bias most blocks
+ towards strongly lossy compression. Instead, we assign class 2
+ to most blocks, and use class 3 only when strictly necessary
+ (for blocks whose largest AC component exceeds 255). */
+
+#if 0 /* SMPTE spec method */
+ static const int classes[] = {12, 24, 36, 0xffff};
+#else /* improved ffmpeg method */
+ static const int classes[] = {-1, -1, 255, 0xffff};
+#endif
+ int max=classes[0];
+ int prev=0;
+
+ bi->mb[0] = blk[0];
+
+ for (area = 0; area < 4; area++) {
+ bi->prev[area] = prev;
+ bi->bit_size[area] = 1; // 4 areas 4 bits for EOB :)
+ for (i=mb_area_start[area]; i<mb_area_start[area+1]; i++) {
+ int level = blk[zigzag_scan[i]];
+
+ if (level+15 > 30U) {
+ bi->sign[i] = (level>>31)&1;
+ /* weigh it and and shift down into range, adding for rounding */
+ /* the extra division by a factor of 2^4 reverses the 8x expansion of the DCT
+ AND the 2x doubling of the weights */
+ level = (FFABS(level) * weight[i] + (1<<(dv_weight_bits+3))) >> (dv_weight_bits+4);
+ bi->mb[i] = level;
+ if(level>max) max= level;
+ bi->bit_size[area] += dv_rl2vlc_size(i - prev - 1, level);
+ bi->next[prev]= i;
+ prev= i;
+ }
+ }
+ }
+ bi->next[prev]= i;
+ for(bi->cno = 0; max > classes[bi->cno]; bi->cno++);
+
+ bi->cno += bias;
+
+ if (bi->cno >= 3) {
+ bi->cno = 3;
+ prev=0;
+ i= bi->next[prev];
+ for (area = 0; area < 4; area++) {
+ bi->prev[area] = prev;
+ bi->bit_size[area] = 1; // 4 areas 4 bits for EOB :)
+ for (; i<mb_area_start[area+1]; i= bi->next[i]) {
+ bi->mb[i] >>=1;
+
+ if (bi->mb[i]) {
+ bi->bit_size[area] += dv_rl2vlc_size(i - prev - 1, bi->mb[i]);
+ bi->next[prev]= i;
+ prev= i;
+ }
+ }
+ }
+ bi->next[prev]= i;
+ }
+}
+
+//FIXME replace this by dsputil
+#define SC(x, y) ((s[x] - s[y]) ^ ((s[x] - s[y]) >> 7))
+static av_always_inline int dv_guess_dct_mode(DCTELEM *blk) {
+ DCTELEM *s;
+ int score88 = 0;
+ int score248 = 0;
+ int i;
+
+ /* Compute 8-8 score (small values give a better chance for 8-8 DCT) */
+ s = blk;
+ for(i=0; i<7; i++) {
+ score88 += SC(0, 8) + SC(1, 9) + SC(2, 10) + SC(3, 11) +
+ SC(4, 12) + SC(5,13) + SC(6, 14) + SC(7, 15);
+ s += 8;
+ }
+ /* Compute 2-4-8 score (small values give a better chance for 2-4-8 DCT) */
+ s = blk;
+ for(i=0; i<6; i++) {
+ score248 += SC(0, 16) + SC(1,17) + SC(2, 18) + SC(3, 19) +
+ SC(4, 20) + SC(5,21) + SC(6, 22) + SC(7, 23);
+ s += 8;
+ }
+
+ return (score88 - score248 > -10);
+}
+
+static inline void dv_guess_qnos(EncBlockInfo* blks, int* qnos)
+{
+ int size[5];
+ int i, j, k, a, prev, a2;
+ EncBlockInfo* b;
+
+ size[0] = size[1] = size[2] = size[3] = size[4] = 1<<24;
+ do {
+ b = blks;
+ for (i=0; i<5; i++) {
+ if (!qnos[i])
+ continue;
+
+ qnos[i]--;
+ size[i] = 0;
+ for (j=0; j<6; j++, b++) {
+ for (a=0; a<4; a++) {
+ if (b->area_q[a] != dv_quant_shifts[qnos[i] + dv_quant_offset[b->cno]][a]) {
+ b->bit_size[a] = 1; // 4 areas 4 bits for EOB :)
+ b->area_q[a]++;
+ prev= b->prev[a];
+ assert(b->next[prev] >= mb_area_start[a+1] || b->mb[prev]);
+ for (k= b->next[prev] ; k<mb_area_start[a+1]; k= b->next[k]) {
+ b->mb[k] >>= 1;
+ if (b->mb[k]) {
+ b->bit_size[a] += dv_rl2vlc_size(k - prev - 1, b->mb[k]);
+ prev= k;
+ } else {
+ if(b->next[k] >= mb_area_start[a+1] && b->next[k]<64){
+ for(a2=a+1; b->next[k] >= mb_area_start[a2+1]; a2++)
+ b->prev[a2] = prev;
+ assert(a2<4);
+ assert(b->mb[b->next[k]]);
+ b->bit_size[a2] += dv_rl2vlc_size(b->next[k] - prev - 1, b->mb[b->next[k]])
+ -dv_rl2vlc_size(b->next[k] - k - 1, b->mb[b->next[k]]);
+ assert(b->prev[a2]==k && (a2+1 >= 4 || b->prev[a2+1]!=k));
+ b->prev[a2] = prev;
+ }
+ b->next[prev] = b->next[k];
+ }
+ }
+ b->prev[a+1]= prev;
+ }
+ size[i] += b->bit_size[a];
+ }
+ }
+ if(vs_total_ac_bits >= size[0] + size[1] + size[2] + size[3] + size[4])
+ return;
+ }
+ } while (qnos[0]|qnos[1]|qnos[2]|qnos[3]|qnos[4]);
+
+
+ for(a=2; a==2 || vs_total_ac_bits < size[0]; a+=a){
+ b = blks;
+ size[0] = 5*6*4; //EOB
+ for (j=0; j<6*5; j++, b++) {
+ prev= b->prev[0];
+ for (k= b->next[prev]; k<64; k= b->next[k]) {
+ if(b->mb[k] < a && b->mb[k] > -a){
+ b->next[prev] = b->next[k];
+ }else{
+ size[0] += dv_rl2vlc_size(k - prev - 1, b->mb[k]);
+ prev= k;
+ }
+ }
+ }
+ }
+}
+
+static inline void dv_encode_video_segment(DVVideoContext *s,
+ uint8_t *dif,
+ const uint16_t *mb_pos_ptr)
+{
+ int mb_index, i, j, v;
+ int mb_x, mb_y, c_offset, linesize;
+ uint8_t* y_ptr;
+ uint8_t* data;
+ uint8_t* ptr;
+ int do_edge_wrap;
+ DECLARE_ALIGNED_16(DCTELEM, block[64]);
+ EncBlockInfo enc_blks[5*6];
+ PutBitContext pbs[5*6];
+ PutBitContext* pb;
+ EncBlockInfo* enc_blk;
+ int vs_bit_size = 0;
+ int qnos[5];
+
+ assert((((int)block) & 15) == 0);
+
+ enc_blk = &enc_blks[0];
+ pb = &pbs[0];
+ for(mb_index = 0; mb_index < 5; mb_index++) {
+ v = *mb_pos_ptr++;
+ mb_x = v & 0xff;
+ mb_y = v >> 8;
+ if (s->sys->pix_fmt == PIX_FMT_YUV422P) {
+ y_ptr = s->picture.data[0] + (mb_y * s->picture.linesize[0] * 8) + (mb_x * 4);
+ } else { /* 4:1:1 */
+ y_ptr = s->picture.data[0] + (mb_y * s->picture.linesize[0] * 8) + (mb_x * 8);
+ }
+ if (s->sys->pix_fmt == PIX_FMT_YUV420P) {
+ c_offset = (((mb_y >> 1) * s->picture.linesize[1] * 8) + ((mb_x >> 1) * 8));
+ } else { /* 4:2:2 or 4:1:1 */
+ c_offset = ((mb_y * s->picture.linesize[1] * 8) + ((mb_x >> 2) * 8));
+ }
+ do_edge_wrap = 0;
+ qnos[mb_index] = 15; /* No quantization */
+ ptr = dif + mb_index*80 + 4;
+ for(j = 0;j < 6; j++) {
+ int dummy = 0;
+ if (s->sys->pix_fmt == PIX_FMT_YUV422P) { /* 4:2:2 */
+ if (j == 0 || j == 2) {
+ /* Y0 Y1 */
+ data = y_ptr + ((j>>1) * 8);
+ linesize = s->picture.linesize[0];
+ } else if (j > 3) {
+ /* Cr Cb */
+ data = s->picture.data[6 - j] + c_offset;
+ linesize = s->picture.linesize[6 - j];
+ } else {
+ /* j=1 and j=3 are "dummy" blocks, used for AC data only */
+ data = 0;
+ linesize = 0;
+ dummy = 1;
+ }
+ } else { /* 4:1:1 or 4:2:0 */
+ if (j < 4) { /* Four Y blocks */
+ /* NOTE: at end of line, the macroblock is handled as 420 */
+ if (s->sys->pix_fmt == PIX_FMT_YUV411P && mb_x < (704 / 8)) {
+ data = y_ptr + (j * 8);
+ } else {
+ data = y_ptr + ((j & 1) * 8) + ((j >> 1) * 8 * s->picture.linesize[0]);
+ }
+ linesize = s->picture.linesize[0];
+ } else { /* Cr and Cb blocks */
+ /* don't ask Fabrice why they inverted Cb and Cr ! */
+ data = s->picture.data[6 - j] + c_offset;
+ linesize = s->picture.linesize[6 - j];
+ if (s->sys->pix_fmt == PIX_FMT_YUV411P && mb_x >= (704 / 8))
+ do_edge_wrap = 1;
+ }
+ }
+
+ /* Everything is set up -- now just copy data -> DCT block */
+ if (do_edge_wrap) { /* Edge wrap copy: 4x16 -> 8x8 */
+ uint8_t* d;
+ DCTELEM *b = block;
+ for (i=0;i<8;i++) {
+ d = data + 8 * linesize;
+ b[0] = data[0]; b[1] = data[1]; b[2] = data[2]; b[3] = data[3];
+ b[4] = d[0]; b[5] = d[1]; b[6] = d[2]; b[7] = d[3];
+ data += linesize;
+ b += 8;
+ }
+ } else { /* Simple copy: 8x8 -> 8x8 */
+ if (!dummy)
+ s->get_pixels(block, data, linesize);
+ }
+
+ if(s->avctx->flags & CODEC_FLAG_INTERLACED_DCT)
+ enc_blk->dct_mode = dv_guess_dct_mode(block);
+ else
+ enc_blk->dct_mode = 0;
+ enc_blk->area_q[0] = enc_blk->area_q[1] = enc_blk->area_q[2] = enc_blk->area_q[3] = 0;
+ enc_blk->partial_bit_count = 0;
+ enc_blk->partial_bit_buffer = 0;
+ enc_blk->cur_ac = 0;
+
+ if (dummy) {
+ /* 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(block, 0, sizeof(block));
+ } else {
+ s->fdct[enc_blk->dct_mode](block);
+ }
+
+ dv_set_class_number(block, enc_blk,
+ enc_blk->dct_mode ? ff_zigzag248_direct : ff_zigzag_direct,
+ enc_blk->dct_mode ? dv_weight_248 : dv_weight_88,
+ j/4);
+
+ init_put_bits(pb, ptr, block_sizes[j]/8);
+ put_bits(pb, 9, (uint16_t)(((enc_blk->mb[0] >> 3) - 1024 + 2) >> 2));
+ put_bits(pb, 1, enc_blk->dct_mode);
+ put_bits(pb, 2, enc_blk->cno);
+
+ vs_bit_size += enc_blk->bit_size[0] + enc_blk->bit_size[1] +
+ enc_blk->bit_size[2] + enc_blk->bit_size[3];
+ ++enc_blk;
+ ++pb;
+ ptr += block_sizes[j]/8;
+ }
+ }
+
+ if (vs_total_ac_bits < vs_bit_size)
+ dv_guess_qnos(&enc_blks[0], &qnos[0]);
+
+ for (i=0; i<5; i++) {
+ dif[i*80 + 3] = qnos[i];
+ }
+
+ /* First pass over individual cells only */
+ for (j=0; j<5*6; j++)
+ dv_encode_ac(&enc_blks[j], &pbs[j], &pbs[j+1]);
+
+ /* Second pass over each MB space */
+ for (j=0; j<5*6; j+=6) {
+ pb= &pbs[j];
+ for (i=0; i<6; i++) {
+ if (enc_blks[i+j].partial_bit_count)
+ pb=dv_encode_ac(&enc_blks[i+j], pb, &pbs[j+6]);
+ }
+ }
+
+ /* Third and final pass over the whole vides segment space */
+ pb= &pbs[0];
+ for (j=0; j<5*6; j++) {
+ if (enc_blks[j].partial_bit_count)
+ pb=dv_encode_ac(&enc_blks[j], pb, &pbs[6*5]);
+ if (enc_blks[j].partial_bit_count)
+ av_log(NULL, AV_LOG_ERROR, "ac bitstream overflow\n");
+ }
+
+ for (j=0; j<5*6; j++)
+ flush_put_bits(&pbs[j]);
+}
+
+static int dv_decode_mt(AVCodecContext *avctx, void* sl)
+{
+ DVVideoContext *s = avctx->priv_data;
+ int slice = (size_t)sl;
+
+ /* which DIF channel is this? */
+ int chan = slice / (s->sys->difseg_size * 27);
+
+ /* slice within the DIF channel */
+ int chan_slice = slice % (s->sys->difseg_size * 27);
+
+ /* byte offset of this channel's data */
+ int chan_offset = chan * s->sys->difseg_size * 150 * 80;
+
+ dv_decode_video_segment(s, &s->buf[((chan_slice/27)*6+(chan_slice/3)+chan_slice*5+7)*80 + chan_offset],
+ &s->sys->video_place[slice*5]);
+ return 0;
+}
+
+#ifdef CONFIG_ENCODERS
+static int dv_encode_mt(AVCodecContext *avctx, void* sl)
+{
+ DVVideoContext *s = avctx->priv_data;
+ int slice = (size_t)sl;
+
+ /* which DIF channel is this? */
+ int chan = slice / (s->sys->difseg_size * 27);
+
+ /* slice within the DIF channel */
+ int chan_slice = slice % (s->sys->difseg_size * 27);
+
+ /* byte offset of this channel's data */
+ int chan_offset = chan * s->sys->difseg_size * 150 * 80;
+
+ dv_encode_video_segment(s, &s->buf[((chan_slice/27)*6+(chan_slice/3)+chan_slice*5+7)*80 + chan_offset],
+ &s->sys->video_place[slice*5]);
+ return 0;
+}
+#endif
+
+#ifdef CONFIG_DECODERS
+/* NOTE: exactly one frame must be given (120000 bytes for NTSC,
+ 144000 bytes for PAL - or twice those for 50Mbps) */
+static int dvvideo_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ DVVideoContext *s = avctx->priv_data;
+
+ s->sys = dv_frame_profile(buf);
+ if (!s->sys || buf_size < s->sys->frame_size)
+ return -1; /* NOTE: we only accept several full frames */
+
+ if(s->picture.data[0])
+ avctx->release_buffer(avctx, &s->picture);
+
+ s->picture.reference = 0;
+ s->picture.key_frame = 1;
+ s->picture.pict_type = FF_I_TYPE;
+ avctx->pix_fmt = s->sys->pix_fmt;
+ avcodec_set_dimensions(avctx, s->sys->width, s->sys->height);
+ if(avctx->get_buffer(avctx, &s->picture) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ return -1;
+ }
+ s->picture.interlaced_frame = 1;
+ s->picture.top_field_first = 0;
+
+ s->buf = buf;
+ avctx->execute(avctx, dv_decode_mt, (void**)&dv_anchor[0], NULL,
+ s->sys->n_difchan * s->sys->difseg_size * 27);
+
+ emms_c();
+
+ /* return image */
+ *data_size = sizeof(AVFrame);
+ *(AVFrame*)data= s->picture;
+
+ return s->sys->frame_size;
+}
+#endif
+
+
+static inline int dv_write_pack(enum dv_pack_type pack_id, DVVideoContext *c, uint8_t* buf)
+{
+ /*
+ * Here's what SMPTE314M says about these two:
+ * (page 6) APTn, AP1n, AP2n, AP3n: These data shall be identical
+ * as track application IDs (APTn = 001, AP1n =
+ * 001, AP2n = 001, AP3n = 001), if the source signal
+ * comes from a digital VCR. If the signal source is
+ * unknown, all bits for these data shall be set to 1.
+ * (page 12) STYPE: STYPE defines a signal type of video signal
+ * 00000b = 4:1:1 compression
+ * 00100b = 4:2:2 compression
+ * XXXXXX = Reserved
+ * Now, I've got two problems with these statements:
+ * 1. it looks like APT == 111b should be a safe bet, but it isn't.
+ * It seems that for PAL as defined in IEC 61834 we have to set
+ * APT to 000 and for SMPTE314M to 001.
+ * 2. It is not at all clear what STYPE is used for 4:2:0 PAL
+ * compression scheme (if any).
+ */
+ int apt = (c->sys->pix_fmt == PIX_FMT_YUV420P ? 0 : 1);
+ int stype = (c->sys->pix_fmt == PIX_FMT_YUV422P ? 4 : 0);
+
+ uint8_t aspect = 0;
+ if((int)(av_q2d(c->avctx->sample_aspect_ratio) * c->avctx->width / c->avctx->height * 10) == 17) /* 16:9 */
+ aspect = 0x02;
+
+ buf[0] = (uint8_t)pack_id;
+ switch (pack_id) {
+ case dv_header525: /* I can't imagine why these two weren't defined as real */
+ case dv_header625: /* packs in SMPTE314M -- they definitely look like ones */
+ buf[1] = 0xf8 | /* reserved -- always 1 */
+ (apt & 0x07); /* APT: Track application ID */
+ buf[2] = (0 << 7) | /* TF1: audio data is 0 - valid; 1 - invalid */
+ (0x0f << 3) | /* reserved -- always 1 */
+ (apt & 0x07); /* AP1: Audio application ID */
+ buf[3] = (0 << 7) | /* TF2: video data is 0 - valid; 1 - invalid */
+ (0x0f << 3) | /* reserved -- always 1 */
+ (apt & 0x07); /* AP2: Video application ID */
+ buf[4] = (0 << 7) | /* TF3: subcode(SSYB) is 0 - valid; 1 - invalid */
+ (0x0f << 3) | /* reserved -- always 1 */
+ (apt & 0x07); /* AP3: Subcode application ID */
+ break;
+ case dv_video_source:
+ buf[1] = 0xff; /* reserved -- always 1 */
+ buf[2] = (1 << 7) | /* B/W: 0 - b/w, 1 - color */
+ (1 << 6) | /* following CLF is valid - 0, invalid - 1 */
+ (3 << 4) | /* CLF: color frames id (see ITU-R BT.470-4) */
+ 0xf; /* reserved -- always 1 */
+ buf[3] = (3 << 6) | /* reserved -- always 1 */
+ (c->sys->dsf << 5) | /* system: 60fields/50fields */
+ stype; /* signal type video compression */
+ buf[4] = 0xff; /* VISC: 0xff -- no information */
+ break;
+ case dv_video_control:
+ buf[1] = (0 << 6) | /* Copy generation management (CGMS) 0 -- free */
+ 0x3f; /* reserved -- always 1 */
+ buf[2] = 0xc8 | /* reserved -- always b11001xxx */
+ aspect;
+ buf[3] = (1 << 7) | /* Frame/field flag 1 -- frame, 0 -- field */
+ (1 << 6) | /* First/second field flag 0 -- field 2, 1 -- field 1 */
+ (1 << 5) | /* Frame change flag 0 -- same picture as before, 1 -- different */
+ (1 << 4) | /* 1 - interlaced, 0 - noninterlaced */
+ 0xc; /* reserved -- always b1100 */
+ buf[4] = 0xff; /* reserved -- always 1 */
+ break;
+ default:
+ buf[1] = buf[2] = buf[3] = buf[4] = 0xff;
+ }
+ return 5;
+}
+
+static void dv_format_frame(DVVideoContext* c, uint8_t* buf)
+{
+ int chan, i, j, k;
+
+ for (chan = 0; chan < c->sys->n_difchan; chan++) {
+ for (i = 0; i < c->sys->difseg_size; i++) {
+ memset(buf, 0xff, 80 * 6); /* First 6 DIF blocks are for control data */
+
+ /* DV header: 1DIF */
+ buf += dv_write_dif_id(dv_sect_header, chan, i, 0, buf);
+ buf += dv_write_pack((c->sys->dsf ? dv_header625 : dv_header525), c, buf);
+ buf += 72; /* unused bytes */
+
+ /* DV subcode: 2DIFs */
+ for (j = 0; j < 2; j++) {
+ buf += dv_write_dif_id(dv_sect_subcode, chan, i, j, buf);
+ for (k = 0; k < 6; k++)
+ buf += dv_write_ssyb_id(k, (i < c->sys->difseg_size/2), buf) + 5;
+ buf += 29; /* unused bytes */
+ }
+
+ /* DV VAUX: 3DIFS */
+ for (j = 0; j < 3; j++) {
+ buf += dv_write_dif_id(dv_sect_vaux, chan, i, j, buf);
+ buf += dv_write_pack(dv_video_source, c, buf);
+ buf += dv_write_pack(dv_video_control, c, buf);
+ buf += 7*5;
+ buf += dv_write_pack(dv_video_source, c, buf);
+ buf += dv_write_pack(dv_video_control, c, buf);
+ buf += 4*5 + 2; /* unused bytes */
+ }
+
+ /* DV Audio/Video: 135 Video DIFs + 9 Audio DIFs */
+ for (j = 0; j < 135; j++) {
+ if (j%15 == 0) {
+ memset(buf, 0xff, 80);
+ buf += dv_write_dif_id(dv_sect_audio, chan, i, j/15, buf);
+ buf += 77; /* audio control & shuffled PCM audio */
+ }
+ buf += dv_write_dif_id(dv_sect_video, chan, i, j, buf);
+ buf += 77; /* 1 video macro block: 1 bytes control
+ 4 * 14 bytes Y 8x8 data
+ 10 bytes Cr 8x8 data
+ 10 bytes Cb 8x8 data */
+ }
+ }
+ }
+}
+
+
+#ifdef CONFIG_ENCODERS
+static int dvvideo_encode_frame(AVCodecContext *c, uint8_t *buf, int buf_size,
+ void *data)
+{
+ DVVideoContext *s = c->priv_data;
+
+ s->sys = dv_codec_profile(c);
+ if (!s->sys)
+ return -1;
+ if(buf_size < s->sys->frame_size)
+ return -1;
+
+ c->pix_fmt = s->sys->pix_fmt;
+ s->picture = *((AVFrame *)data);
+ s->picture.key_frame = 1;
+ s->picture.pict_type = FF_I_TYPE;
+
+ s->buf = buf;
+ c->execute(c, dv_encode_mt, (void**)&dv_anchor[0], NULL,
+ s->sys->n_difchan * s->sys->difseg_size * 27);
+
+ emms_c();
+
+ dv_format_frame(s, buf);
+
+ return s->sys->frame_size;
+}
+#endif
+
+static int dvvideo_close(AVCodecContext *c)
+{
+ DVVideoContext *s = c->priv_data;
+
+ if(s->picture.data[0])
+ c->release_buffer(c, &s->picture);
+
+ return 0;
+}
+
+
+#ifdef CONFIG_DVVIDEO_ENCODER
+AVCodec dvvideo_encoder = {
+ "dvvideo",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_DVVIDEO,
+ sizeof(DVVideoContext),
+ dvvideo_init,
+ dvvideo_encode_frame,
+ .pix_fmts = (enum PixelFormat[]) {PIX_FMT_YUV411P, PIX_FMT_YUV422P, PIX_FMT_YUV420P, -1},
+};
+#endif // CONFIG_DVVIDEO_ENCODER
+
+#ifdef CONFIG_DVVIDEO_DECODER
+AVCodec dvvideo_decoder = {
+ "dvvideo",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_DVVIDEO,
+ sizeof(DVVideoContext),
+ dvvideo_init,
+ NULL,
+ dvvideo_close,
+ dvvideo_decode_frame,
+ CODEC_CAP_DR1,
+ NULL
+};
+#endif
diff --git a/contrib/ffmpeg/libavcodec/dvbsub.c b/contrib/ffmpeg/libavcodec/dvbsub.c
new file mode 100644
index 000000000..44ba19d86
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/dvbsub.c
@@ -0,0 +1,445 @@
+/*
+ * DVB subtitle encoding for ffmpeg
+ * Copyright (c) 2005 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"
+
+typedef struct DVBSubtitleContext {
+ int hide_state;
+ int object_version;
+} DVBSubtitleContext;
+
+#define PUTBITS2(val)\
+{\
+ bitbuf |= (val) << bitcnt;\
+ bitcnt -= 2;\
+ if (bitcnt < 0) {\
+ bitcnt = 6;\
+ *q++ = bitbuf;\
+ bitbuf = 0;\
+ }\
+}
+
+static void dvb_encode_rle2(uint8_t **pq,
+ const uint8_t *bitmap, int linesize,
+ int w, int h)
+{
+ uint8_t *q;
+ unsigned int bitbuf;
+ int bitcnt;
+ int x, y, len, x1, v, color;
+
+ q = *pq;
+
+ for(y = 0; y < h; y++) {
+ *q++ = 0x10;
+ bitbuf = 0;
+ bitcnt = 6;
+
+ x = 0;
+ while (x < w) {
+ x1 = x;
+ color = bitmap[x1++];
+ while (x1 < w && bitmap[x1] == color)
+ x1++;
+ len = x1 - x;
+ if (color == 0 && len == 2) {
+ PUTBITS2(0);
+ PUTBITS2(0);
+ PUTBITS2(1);
+ } else if (len >= 3 && len <= 10) {
+ v = len - 3;
+ PUTBITS2(0);
+ PUTBITS2((v >> 2) | 2);
+ PUTBITS2(v & 3);
+ PUTBITS2(color);
+ } else if (len >= 12 && len <= 27) {
+ v = len - 12;
+ PUTBITS2(0);
+ PUTBITS2(0);
+ PUTBITS2(2);
+ PUTBITS2(v >> 2);
+ PUTBITS2(v & 3);
+ PUTBITS2(color);
+ } else if (len >= 29) {
+ /* length = 29 ... 284 */
+ if (len > 284)
+ len = 284;
+ v = len - 29;
+ PUTBITS2(0);
+ PUTBITS2(0);
+ PUTBITS2(3);
+ PUTBITS2((v >> 6));
+ PUTBITS2((v >> 4) & 3);
+ PUTBITS2((v >> 2) & 3);
+ PUTBITS2(v & 3);
+ PUTBITS2(color);
+ } else {
+ PUTBITS2(color);
+ if (color == 0) {
+ PUTBITS2(1);
+ }
+ len = 1;
+ }
+ x += len;
+ }
+ /* end of line */
+ PUTBITS2(0);
+ PUTBITS2(0);
+ PUTBITS2(0);
+ if (bitcnt != 6) {
+ *q++ = bitbuf;
+ }
+ *q++ = 0xf0;
+ bitmap += linesize;
+ }
+ *pq = q;
+}
+
+#define PUTBITS4(val)\
+{\
+ bitbuf |= (val) << bitcnt;\
+ bitcnt -= 4;\
+ if (bitcnt < 0) {\
+ bitcnt = 4;\
+ *q++ = bitbuf;\
+ bitbuf = 0;\
+ }\
+}
+
+/* some DVB decoders only implement 4 bits/pixel */
+static void dvb_encode_rle4(uint8_t **pq,
+ const uint8_t *bitmap, int linesize,
+ int w, int h)
+{
+ uint8_t *q;
+ unsigned int bitbuf;
+ int bitcnt;
+ int x, y, len, x1, v, color;
+
+ q = *pq;
+
+ for(y = 0; y < h; y++) {
+ *q++ = 0x11;
+ bitbuf = 0;
+ bitcnt = 4;
+
+ x = 0;
+ while (x < w) {
+ x1 = x;
+ color = bitmap[x1++];
+ while (x1 < w && bitmap[x1] == color)
+ x1++;
+ len = x1 - x;
+ if (color == 0 && len == 2) {
+ PUTBITS4(0);
+ PUTBITS4(0xd);
+ } else if (color == 0 && (len >= 3 && len <= 9)) {
+ PUTBITS4(0);
+ PUTBITS4(len - 2);
+ } else if (len >= 4 && len <= 7) {
+ PUTBITS4(0);
+ PUTBITS4(8 + len - 4);
+ PUTBITS4(color);
+ } else if (len >= 9 && len <= 24) {
+ PUTBITS4(0);
+ PUTBITS4(0xe);
+ PUTBITS4(len - 9);
+ PUTBITS4(color);
+ } else if (len >= 25) {
+ if (len > 280)
+ len = 280;
+ v = len - 25;
+ PUTBITS4(0);
+ PUTBITS4(0xf);
+ PUTBITS4(v >> 4);
+ PUTBITS4(v & 0xf);
+ PUTBITS4(color);
+ } else {
+ PUTBITS4(color);
+ if (color == 0) {
+ PUTBITS4(0xc);
+ }
+ len = 1;
+ }
+ x += len;
+ }
+ /* end of line */
+ PUTBITS4(0);
+ PUTBITS4(0);
+ if (bitcnt != 4) {
+ *q++ = bitbuf;
+ }
+ *q++ = 0xf0;
+ bitmap += linesize;
+ }
+ *pq = q;
+}
+
+#define SCALEBITS 10
+#define ONE_HALF (1 << (SCALEBITS - 1))
+#define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5))
+
+#define RGB_TO_Y_CCIR(r, g, b) \
+((FIX(0.29900*219.0/255.0) * (r) + FIX(0.58700*219.0/255.0) * (g) + \
+ FIX(0.11400*219.0/255.0) * (b) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS)
+
+#define RGB_TO_U_CCIR(r1, g1, b1, shift)\
+(((- FIX(0.16874*224.0/255.0) * r1 - FIX(0.33126*224.0/255.0) * g1 + \
+ FIX(0.50000*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
+
+#define RGB_TO_V_CCIR(r1, g1, b1, shift)\
+(((FIX(0.50000*224.0/255.0) * r1 - FIX(0.41869*224.0/255.0) * g1 - \
+ FIX(0.08131*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
+
+static inline void putbe16(uint8_t **pq, uint16_t v)
+{
+ uint8_t *q;
+ q = *pq;
+ *q++ = v >> 8;
+ *q++ = v;
+ *pq = q;
+}
+
+static int encode_dvb_subtitles(DVBSubtitleContext *s,
+ uint8_t *outbuf, AVSubtitle *h)
+{
+ uint8_t *q, *pseg_len;
+ int page_id, region_id, clut_id, object_id, i, bpp_index, page_state;
+
+
+ q = outbuf;
+
+ page_id = 1;
+
+ if (h->num_rects == 0 || h->rects == NULL)
+ return -1;
+
+ *q++ = 0x00; /* subtitle_stream_id */
+
+ /* page composition segment */
+
+ *q++ = 0x0f; /* sync_byte */
+ *q++ = 0x10; /* segment_type */
+ putbe16(&q, page_id);
+ pseg_len = q;
+ q += 2; /* segment length */
+ *q++ = 30; /* page_timeout (seconds) */
+ if (s->hide_state)
+ page_state = 0; /* normal case */
+ else
+ page_state = 2; /* mode change */
+ /* page_version = 0 + page_state */
+ *q++ = s->object_version | (page_state << 2) | 3;
+
+ for (region_id = 0; region_id < h->num_rects; region_id++) {
+ *q++ = region_id;
+ *q++ = 0xff; /* reserved */
+ putbe16(&q, h->rects[region_id].x); /* left pos */
+ putbe16(&q, h->rects[region_id].y); /* top pos */
+ }
+
+ putbe16(&pseg_len, q - pseg_len - 2);
+
+ if (!s->hide_state) {
+ for (clut_id = 0; clut_id < h->num_rects; clut_id++) {
+
+ /* CLUT segment */
+
+ if (h->rects[clut_id].nb_colors <= 4) {
+ /* 2 bpp, some decoders do not support it correctly */
+ bpp_index = 0;
+ } else if (h->rects[clut_id].nb_colors <= 16) {
+ /* 4 bpp, standard encoding */
+ bpp_index = 1;
+ } else {
+ return -1;
+ }
+
+ *q++ = 0x0f; /* sync byte */
+ *q++ = 0x12; /* CLUT definition segment */
+ putbe16(&q, page_id);
+ pseg_len = q;
+ q += 2; /* segment length */
+ *q++ = clut_id;
+ *q++ = (0 << 4) | 0xf; /* version = 0 */
+
+ for(i = 0; i < h->rects[clut_id].nb_colors; i++) {
+ *q++ = i; /* clut_entry_id */
+ *q++ = (1 << (7 - bpp_index)) | (0xf << 1) | 1; /* 2 bits/pixel full range */
+ {
+ int a, r, g, b;
+ a = (h->rects[clut_id].rgba_palette[i] >> 24) & 0xff;
+ r = (h->rects[clut_id].rgba_palette[i] >> 16) & 0xff;
+ g = (h->rects[clut_id].rgba_palette[i] >> 8) & 0xff;
+ b = (h->rects[clut_id].rgba_palette[i] >> 0) & 0xff;
+
+ *q++ = RGB_TO_Y_CCIR(r, g, b);
+ *q++ = RGB_TO_V_CCIR(r, g, b, 0);
+ *q++ = RGB_TO_U_CCIR(r, g, b, 0);
+ *q++ = 255 - a;
+ }
+ }
+
+ putbe16(&pseg_len, q - pseg_len - 2);
+ }
+ }
+
+ for (region_id = 0; region_id < h->num_rects; region_id++) {
+
+ /* region composition segment */
+
+ if (h->rects[region_id].nb_colors <= 4) {
+ /* 2 bpp, some decoders do not support it correctly */
+ bpp_index = 0;
+ } else if (h->rects[region_id].nb_colors <= 16) {
+ /* 4 bpp, standard encoding */
+ bpp_index = 1;
+ } else {
+ return -1;
+ }
+
+ *q++ = 0x0f; /* sync_byte */
+ *q++ = 0x11; /* segment_type */
+ putbe16(&q, page_id);
+ pseg_len = q;
+ q += 2; /* segment length */
+ *q++ = region_id;
+ *q++ = (s->object_version << 4) | (0 << 3) | 0x07; /* version , no fill */
+ putbe16(&q, h->rects[region_id].w); /* region width */
+ putbe16(&q, h->rects[region_id].h); /* region height */
+ *q++ = ((1 + bpp_index) << 5) | ((1 + bpp_index) << 2) | 0x03;
+ *q++ = region_id; /* clut_id == region_id */
+ *q++ = 0; /* 8 bit fill colors */
+ *q++ = 0x03; /* 4 bit and 2 bit fill colors */
+
+ if (!s->hide_state) {
+ putbe16(&q, region_id); /* object_id == region_id */
+ *q++ = (0 << 6) | (0 << 4);
+ *q++ = 0;
+ *q++ = 0xf0;
+ *q++ = 0;
+ }
+
+ putbe16(&pseg_len, q - pseg_len - 2);
+ }
+
+ if (!s->hide_state) {
+
+ for (object_id = 0; object_id < h->num_rects; object_id++) {
+ /* Object Data segment */
+
+ if (h->rects[object_id].nb_colors <= 4) {
+ /* 2 bpp, some decoders do not support it correctly */
+ bpp_index = 0;
+ } else if (h->rects[object_id].nb_colors <= 16) {
+ /* 4 bpp, standard encoding */
+ bpp_index = 1;
+ } else {
+ return -1;
+ }
+
+ *q++ = 0x0f; /* sync byte */
+ *q++ = 0x13;
+ putbe16(&q, page_id);
+ pseg_len = q;
+ q += 2; /* segment length */
+
+ putbe16(&q, object_id);
+ *q++ = (s->object_version << 4) | (0 << 2) | (0 << 1) | 1; /* version = 0,
+ onject_coding_method,
+ non_modifying_color_flag */
+ {
+ uint8_t *ptop_field_len, *pbottom_field_len, *top_ptr, *bottom_ptr;
+ void (*dvb_encode_rle)(uint8_t **pq,
+ const uint8_t *bitmap, int linesize,
+ int w, int h);
+ ptop_field_len = q;
+ q += 2;
+ pbottom_field_len = q;
+ q += 2;
+
+ if (bpp_index == 0)
+ dvb_encode_rle = dvb_encode_rle2;
+ else
+ dvb_encode_rle = dvb_encode_rle4;
+
+ top_ptr = q;
+ dvb_encode_rle(&q, h->rects[object_id].bitmap, h->rects[object_id].w * 2,
+ h->rects[object_id].w, h->rects[object_id].h >> 1);
+ bottom_ptr = q;
+ dvb_encode_rle(&q, h->rects[object_id].bitmap + h->rects[object_id].w,
+ h->rects[object_id].w * 2, h->rects[object_id].w,
+ h->rects[object_id].h >> 1);
+
+ putbe16(&ptop_field_len, bottom_ptr - top_ptr);
+ putbe16(&pbottom_field_len, q - bottom_ptr);
+ }
+
+ putbe16(&pseg_len, q - pseg_len - 2);
+ }
+ }
+
+ /* end of display set segment */
+
+ *q++ = 0x0f; /* sync_byte */
+ *q++ = 0x80; /* segment_type */
+ putbe16(&q, page_id);
+ pseg_len = q;
+ q += 2; /* segment length */
+
+ putbe16(&pseg_len, q - pseg_len - 2);
+
+ *q++ = 0xff; /* end of PES data */
+
+ s->object_version = (s->object_version + 1) & 0xf;
+ s->hide_state = !s->hide_state;
+ return q - outbuf;
+}
+
+static int dvbsub_init_decoder(AVCodecContext *avctx)
+{
+ return 0;
+}
+
+static int dvbsub_close_decoder(AVCodecContext *avctx)
+{
+ return 0;
+}
+
+static int dvbsub_encode(AVCodecContext *avctx,
+ unsigned char *buf, int buf_size, void *data)
+{
+ DVBSubtitleContext *s = avctx->priv_data;
+ AVSubtitle *sub = data;
+ int ret;
+
+ ret = encode_dvb_subtitles(s, buf, sub);
+ return ret;
+}
+
+AVCodec dvbsub_encoder = {
+ "dvbsub",
+ CODEC_TYPE_SUBTITLE,
+ CODEC_ID_DVB_SUBTITLE,
+ sizeof(DVBSubtitleContext),
+ dvbsub_init_decoder,
+ dvbsub_encode,
+ dvbsub_close_decoder,
+};
diff --git a/contrib/ffmpeg/libavcodec/dvbsubdec.c b/contrib/ffmpeg/libavcodec/dvbsubdec.c
new file mode 100644
index 000000000..08ef6213e
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/dvbsubdec.c
@@ -0,0 +1,1631 @@
+/*
+ * DVB subtitle decoding for ffmpeg
+ * Copyright (c) 2005 Ian Caulfield.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 "bitstream.h"
+
+//#define DEBUG
+//#define DEBUG_PACKET_CONTENTS
+//#define DEBUG_SAVE_IMAGES
+
+#define DVBSUB_PAGE_SEGMENT 0x10
+#define DVBSUB_REGION_SEGMENT 0x11
+#define DVBSUB_CLUT_SEGMENT 0x12
+#define DVBSUB_OBJECT_SEGMENT 0x13
+#define DVBSUB_DISPLAY_SEGMENT 0x80
+
+#define cm (ff_cropTbl + MAX_NEG_CROP)
+
+#ifdef DEBUG_SAVE_IMAGES
+#undef fprintf
+#if 0
+static void png_save(const char *filename, uint8_t *bitmap, int w, int h,
+ uint32_t *rgba_palette)
+{
+ int x, y, v;
+ FILE *f;
+ char fname[40], fname2[40];
+ char command[1024];
+
+ snprintf(fname, 40, "%s.ppm", filename);
+
+ f = fopen(fname, "w");
+ if (!f) {
+ perror(fname);
+ exit(1);
+ }
+ fprintf(f, "P6\n"
+ "%d %d\n"
+ "%d\n",
+ w, h, 255);
+ for(y = 0; y < h; y++) {
+ for(x = 0; x < w; x++) {
+ v = rgba_palette[bitmap[y * w + x]];
+ putc((v >> 16) & 0xff, f);
+ putc((v >> 8) & 0xff, f);
+ putc((v >> 0) & 0xff, f);
+ }
+ }
+ fclose(f);
+
+
+ snprintf(fname2, 40, "%s-a.pgm", filename);
+
+ f = fopen(fname2, "w");
+ if (!f) {
+ perror(fname2);
+ exit(1);
+ }
+ fprintf(f, "P5\n"
+ "%d %d\n"
+ "%d\n",
+ w, h, 255);
+ for(y = 0; y < h; y++) {
+ for(x = 0; x < w; x++) {
+ v = rgba_palette[bitmap[y * w + x]];
+ putc((v >> 24) & 0xff, f);
+ }
+ }
+ fclose(f);
+
+ snprintf(command, 1024, "pnmtopng -alpha %s %s > %s.png 2> /dev/null", fname2, fname, filename);
+ system(command);
+
+ snprintf(command, 1024, "rm %s %s", fname, fname2);
+ system(command);
+}
+#endif
+
+static void png_save2(const char *filename, uint32_t *bitmap, int w, int h)
+{
+ int x, y, v;
+ FILE *f;
+ char fname[40], fname2[40];
+ char command[1024];
+
+ snprintf(fname, 40, "%s.ppm", filename);
+
+ f = fopen(fname, "w");
+ if (!f) {
+ perror(fname);
+ exit(1);
+ }
+ fprintf(f, "P6\n"
+ "%d %d\n"
+ "%d\n",
+ w, h, 255);
+ for(y = 0; y < h; y++) {
+ for(x = 0; x < w; x++) {
+ v = bitmap[y * w + x];
+ putc((v >> 16) & 0xff, f);
+ putc((v >> 8) & 0xff, f);
+ putc((v >> 0) & 0xff, f);
+ }
+ }
+ fclose(f);
+
+
+ snprintf(fname2, 40, "%s-a.pgm", filename);
+
+ f = fopen(fname2, "w");
+ if (!f) {
+ perror(fname2);
+ exit(1);
+ }
+ fprintf(f, "P5\n"
+ "%d %d\n"
+ "%d\n",
+ w, h, 255);
+ for(y = 0; y < h; y++) {
+ for(x = 0; x < w; x++) {
+ v = bitmap[y * w + x];
+ putc((v >> 24) & 0xff, f);
+ }
+ }
+ fclose(f);
+
+ snprintf(command, 1024, "pnmtopng -alpha %s %s > %s.png 2> /dev/null", fname2, fname, filename);
+ system(command);
+
+ snprintf(command, 1024, "rm %s %s", fname, fname2);
+ system(command);
+}
+#endif
+
+#define RGBA(r,g,b,a) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
+
+typedef struct DVBSubCLUT {
+ int id;
+
+ uint32_t clut4[4];
+ uint32_t clut16[16];
+ uint32_t clut256[256];
+
+ struct DVBSubCLUT *next;
+} DVBSubCLUT;
+
+static DVBSubCLUT default_clut;
+
+typedef struct DVBSubObjectDisplay {
+ int object_id;
+ int region_id;
+
+ int x_pos;
+ int y_pos;
+
+ int fgcolour;
+ int bgcolour;
+
+ struct DVBSubObjectDisplay *region_list_next;
+ struct DVBSubObjectDisplay *object_list_next;
+} DVBSubObjectDisplay;
+
+typedef struct DVBSubObject {
+ int id;
+
+ int type;
+
+ DVBSubObjectDisplay *display_list;
+
+ struct DVBSubObject *next;
+} DVBSubObject;
+
+typedef struct DVBSubRegionDisplay {
+ int region_id;
+
+ int x_pos;
+ int y_pos;
+
+ struct DVBSubRegionDisplay *next;
+} DVBSubRegionDisplay;
+
+typedef struct DVBSubRegion {
+ int id;
+
+ int width;
+ int height;
+ int depth;
+
+ int clut;
+ int bgcolour;
+
+ uint8_t *pbuf;
+ int buf_size;
+
+ DVBSubObjectDisplay *display_list;
+
+ struct DVBSubRegion *next;
+} DVBSubRegion;
+
+typedef struct DVBSubContext {
+ int composition_id;
+ int ancillary_id;
+
+ int time_out;
+ DVBSubRegion *region_list;
+ DVBSubCLUT *clut_list;
+ DVBSubObject *object_list;
+
+ int display_list_size;
+ DVBSubRegionDisplay *display_list;
+} DVBSubContext;
+
+
+static DVBSubObject* get_object(DVBSubContext *ctx, int object_id)
+{
+ DVBSubObject *ptr = ctx->object_list;
+
+ while (ptr != NULL && ptr->id != object_id) {
+ ptr = ptr->next;
+ }
+
+ return ptr;
+}
+
+static DVBSubCLUT* get_clut(DVBSubContext *ctx, int clut_id)
+{
+ DVBSubCLUT *ptr = ctx->clut_list;
+
+ while (ptr != NULL && ptr->id != clut_id) {
+ ptr = ptr->next;
+ }
+
+ return ptr;
+}
+
+static DVBSubRegion* get_region(DVBSubContext *ctx, int region_id)
+{
+ DVBSubRegion *ptr = ctx->region_list;
+
+ while (ptr != NULL && ptr->id != region_id) {
+ ptr = ptr->next;
+ }
+
+ return ptr;
+}
+
+static void delete_region_display_list(DVBSubContext *ctx, DVBSubRegion *region)
+{
+ DVBSubObject *object, *obj2, **obj2_ptr;
+ DVBSubObjectDisplay *display, *obj_disp, **obj_disp_ptr;
+
+ while (region->display_list != NULL) {
+ display = region->display_list;
+
+ object = get_object(ctx, display->object_id);
+
+ if (object != NULL) {
+ obj_disp = object->display_list;
+ obj_disp_ptr = &object->display_list;
+
+ while (obj_disp != NULL && obj_disp != display) {
+ obj_disp_ptr = &obj_disp->object_list_next;
+ obj_disp = obj_disp->object_list_next;
+ }
+
+ if (obj_disp) {
+ *obj_disp_ptr = obj_disp->object_list_next;
+
+ if (object->display_list == NULL) {
+ obj2 = ctx->object_list;
+ obj2_ptr = &ctx->object_list;
+
+ while (obj2 != NULL && obj2 != object) {
+ obj2_ptr = &obj2->next;
+ obj2 = obj2->next;
+ }
+
+ *obj2_ptr = obj2->next;
+
+ av_free(obj2);
+ }
+ }
+ }
+
+ region->display_list = display->region_list_next;
+
+ av_free(display);
+ }
+
+}
+
+static void delete_state(DVBSubContext *ctx)
+{
+ DVBSubRegion *region;
+ DVBSubCLUT *clut;
+
+ while (ctx->region_list != NULL)
+ {
+ region = ctx->region_list;
+
+ ctx->region_list = region->next;
+
+ delete_region_display_list(ctx, region);
+ if (region->pbuf != NULL)
+ av_free(region->pbuf);
+
+ av_free(region);
+ }
+
+ while (ctx->clut_list != NULL)
+ {
+ clut = ctx->clut_list;
+
+ ctx->clut_list = clut->next;
+
+ av_free(clut);
+ }
+
+ /* Should already be null */
+ if (ctx->object_list != NULL)
+ av_log(0, AV_LOG_ERROR, "Memory deallocation error!\n");
+}
+
+static int dvbsub_init_decoder(AVCodecContext *avctx)
+{
+ int i, r, g, b, a = 0;
+ DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data;
+
+ memset(avctx->priv_data, 0, sizeof(DVBSubContext));
+
+ ctx->composition_id = avctx->sub_id & 0xffff;
+ ctx->ancillary_id = avctx->sub_id >> 16;
+
+ default_clut.id = -1;
+ default_clut.next = NULL;
+
+ default_clut.clut4[0] = RGBA( 0, 0, 0, 0);
+ default_clut.clut4[1] = RGBA(255, 255, 255, 255);
+ default_clut.clut4[2] = RGBA( 0, 0, 0, 255);
+ default_clut.clut4[3] = RGBA(127, 127, 127, 255);
+
+ default_clut.clut16[0] = RGBA( 0, 0, 0, 0);
+ for (i = 1; i < 16; i++) {
+ if (i < 8) {
+ r = (i & 1) ? 255 : 0;
+ g = (i & 2) ? 255 : 0;
+ b = (i & 4) ? 255 : 0;
+ } else {
+ r = (i & 1) ? 127 : 0;
+ g = (i & 2) ? 127 : 0;
+ b = (i & 4) ? 127 : 0;
+ }
+ default_clut.clut16[i] = RGBA(r, g, b, 255);
+ }
+
+ default_clut.clut256[0] = RGBA( 0, 0, 0, 0);
+ for (i = 1; i < 256; i++) {
+ if (i < 8) {
+ r = (i & 1) ? 255 : 0;
+ g = (i & 2) ? 255 : 0;
+ b = (i & 4) ? 255 : 0;
+ a = 63;
+ } else {
+ switch (i & 0x88) {
+ case 0x00:
+ r = ((i & 1) ? 85 : 0) + ((i & 0x10) ? 170 : 0);
+ g = ((i & 2) ? 85 : 0) + ((i & 0x20) ? 170 : 0);
+ b = ((i & 4) ? 85 : 0) + ((i & 0x40) ? 170 : 0);
+ a = 255;
+ break;
+ case 0x08:
+ r = ((i & 1) ? 85 : 0) + ((i & 0x10) ? 170 : 0);
+ g = ((i & 2) ? 85 : 0) + ((i & 0x20) ? 170 : 0);
+ b = ((i & 4) ? 85 : 0) + ((i & 0x40) ? 170 : 0);
+ a = 127;
+ break;
+ case 0x80:
+ r = 127 + ((i & 1) ? 43 : 0) + ((i & 0x10) ? 85 : 0);
+ g = 127 + ((i & 2) ? 43 : 0) + ((i & 0x20) ? 85 : 0);
+ b = 127 + ((i & 4) ? 43 : 0) + ((i & 0x40) ? 85 : 0);
+ a = 255;
+ break;
+ case 0x88:
+ r = ((i & 1) ? 43 : 0) + ((i & 0x10) ? 85 : 0);
+ g = ((i & 2) ? 43 : 0) + ((i & 0x20) ? 85 : 0);
+ b = ((i & 4) ? 43 : 0) + ((i & 0x40) ? 85 : 0);
+ a = 255;
+ break;
+ }
+ }
+ default_clut.clut256[i] = RGBA(r, g, b, a);
+ }
+
+ return 0;
+}
+
+static int dvbsub_close_decoder(AVCodecContext *avctx)
+{
+ DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data;
+ DVBSubRegionDisplay *display;
+
+ delete_state(ctx);
+
+ while (ctx->display_list != NULL)
+ {
+ display = ctx->display_list;
+ ctx->display_list = display->next;
+
+ av_free(display);
+ }
+
+ return 0;
+}
+
+static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len,
+ uint8_t **srcbuf, int buf_size,
+ int non_mod, uint8_t *map_table)
+{
+ GetBitContext gb;
+
+ int bits;
+ int run_length;
+ int pixels_read = 0;
+
+ init_get_bits(&gb, *srcbuf, buf_size << 8);
+
+ while (get_bits_count(&gb) < (buf_size << 8) && pixels_read < dbuf_len) {
+ bits = get_bits(&gb, 2);
+
+ if (bits != 0) {
+ if (non_mod != 1 || bits != 1) {
+ if (map_table != NULL)
+ *destbuf++ = map_table[bits];
+ else
+ *destbuf++ = bits;
+ }
+ pixels_read++;
+ } else {
+ bits = get_bits(&gb, 1);
+ if (bits == 1) {
+ run_length = get_bits(&gb, 3) + 3;
+ bits = get_bits(&gb, 2);
+
+ if (non_mod == 1 && bits == 1)
+ pixels_read += run_length;
+ else {
+ if (map_table != NULL)
+ bits = map_table[bits];
+ while (run_length-- > 0 && pixels_read < dbuf_len) {
+ *destbuf++ = bits;
+ pixels_read++;
+ }
+ }
+ } else {
+ bits = get_bits(&gb, 1);
+ if (bits == 0) {
+ bits = get_bits(&gb, 2);
+ if (bits == 2) {
+ run_length = get_bits(&gb, 4) + 12;
+ bits = get_bits(&gb, 2);
+
+ if (non_mod == 1 && bits == 1)
+ pixels_read += run_length;
+ else {
+ if (map_table != NULL)
+ bits = map_table[bits];
+ while (run_length-- > 0 && pixels_read < dbuf_len) {
+ *destbuf++ = bits;
+ pixels_read++;
+ }
+ }
+ } else if (bits == 3) {
+ run_length = get_bits(&gb, 8) + 29;
+ bits = get_bits(&gb, 2);
+
+ if (non_mod == 1 && bits == 1)
+ pixels_read += run_length;
+ else {
+ if (map_table != NULL)
+ bits = map_table[bits];
+ while (run_length-- > 0 && pixels_read < dbuf_len) {
+ *destbuf++ = bits;
+ pixels_read++;
+ }
+ }
+ } else if (bits == 1) {
+ pixels_read += 2;
+ if (map_table != NULL)
+ bits = map_table[0];
+ else
+ bits = 0;
+ if (pixels_read <= dbuf_len) {
+ *destbuf++ = bits;
+ *destbuf++ = bits;
+ }
+ } else {
+ (*srcbuf) += (get_bits_count(&gb) + 7) >> 3;
+ return pixels_read;
+ }
+ } else {
+ if (map_table != NULL)
+ bits = map_table[0];
+ else
+ bits = 0;
+ *destbuf++ = bits;
+ pixels_read++;
+ }
+ }
+ }
+ }
+
+ if (get_bits(&gb, 6) != 0)
+ av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n");
+
+ (*srcbuf) += (get_bits_count(&gb) + 7) >> 3;
+
+ return pixels_read;
+}
+
+static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len,
+ uint8_t **srcbuf, int buf_size,
+ int non_mod, uint8_t *map_table)
+{
+ GetBitContext gb;
+
+ int bits;
+ int run_length;
+ int pixels_read = 0;
+
+ init_get_bits(&gb, *srcbuf, buf_size << 8);
+
+ while (get_bits_count(&gb) < (buf_size << 8) && pixels_read < dbuf_len) {
+ bits = get_bits(&gb, 4);
+
+ if (bits != 0) {
+ if (non_mod != 1 || bits != 1) {
+ if (map_table != NULL)
+ *destbuf++ = map_table[bits];
+ else
+ *destbuf++ = bits;
+ }
+ pixels_read++;
+ } else {
+ bits = get_bits(&gb, 1);
+ if (bits == 0) {
+ run_length = get_bits(&gb, 3);
+
+ if (run_length == 0) {
+ (*srcbuf) += (get_bits_count(&gb) + 7) >> 3;
+ return pixels_read;
+ }
+
+ run_length += 2;
+
+ if (map_table != NULL)
+ bits = map_table[0];
+ else
+ bits = 0;
+
+ while (run_length-- > 0 && pixels_read < dbuf_len) {
+ *destbuf++ = bits;
+ pixels_read++;
+ }
+ } else {
+ bits = get_bits(&gb, 1);
+ if (bits == 0) {
+ run_length = get_bits(&gb, 2) + 4;
+ bits = get_bits(&gb, 4);
+
+ if (non_mod == 1 && bits == 1)
+ pixels_read += run_length;
+ else {
+ if (map_table != NULL)
+ bits = map_table[bits];
+ while (run_length-- > 0 && pixels_read < dbuf_len) {
+ *destbuf++ = bits;
+ pixels_read++;
+ }
+ }
+ } else {
+ bits = get_bits(&gb, 2);
+ if (bits == 2) {
+ run_length = get_bits(&gb, 4) + 9;
+ bits = get_bits(&gb, 4);
+
+ if (non_mod == 1 && bits == 1)
+ pixels_read += run_length;
+ else {
+ if (map_table != NULL)
+ bits = map_table[bits];
+ while (run_length-- > 0 && pixels_read < dbuf_len) {
+ *destbuf++ = bits;
+ pixels_read++;
+ }
+ }
+ } else if (bits == 3) {
+ run_length = get_bits(&gb, 8) + 25;
+ bits = get_bits(&gb, 4);
+
+ if (non_mod == 1 && bits == 1)
+ pixels_read += run_length;
+ else {
+ if (map_table != NULL)
+ bits = map_table[bits];
+ while (run_length-- > 0 && pixels_read < dbuf_len) {
+ *destbuf++ = bits;
+ pixels_read++;
+ }
+ }
+ } else if (bits == 1) {
+ pixels_read += 2;
+ if (map_table != NULL)
+ bits = map_table[0];
+ else
+ bits = 0;
+ if (pixels_read <= dbuf_len) {
+ *destbuf++ = bits;
+ *destbuf++ = bits;
+ }
+ } else {
+ if (map_table != NULL)
+ bits = map_table[0];
+ else
+ bits = 0;
+ *destbuf++ = bits;
+ pixels_read ++;
+ }
+ }
+ }
+ }
+ }
+
+ if (get_bits(&gb, 8) != 0)
+ av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n");
+
+ (*srcbuf) += (get_bits_count(&gb) + 7) >> 3;
+
+ return pixels_read;
+}
+
+static int dvbsub_read_8bit_string(uint8_t *destbuf, int dbuf_len,
+ uint8_t **srcbuf, int buf_size,
+ int non_mod, uint8_t *map_table)
+{
+ uint8_t *sbuf_end = (*srcbuf) + buf_size;
+ int bits;
+ int run_length;
+ int pixels_read = 0;
+
+ while (*srcbuf < sbuf_end && pixels_read < dbuf_len) {
+ bits = *(*srcbuf)++;
+
+ if (bits != 0) {
+ if (non_mod != 1 || bits != 1) {
+ if (map_table != NULL)
+ *destbuf++ = map_table[bits];
+ else
+ *destbuf++ = bits;
+ }
+ pixels_read++;
+ } else {
+ bits = *(*srcbuf)++;
+ run_length = bits & 0x7f;
+ if ((bits & 0x80) == 0) {
+ if (run_length == 0) {
+ return pixels_read;
+ }
+
+ if (map_table != NULL)
+ bits = map_table[0];
+ else
+ bits = 0;
+ while (run_length-- > 0 && pixels_read < dbuf_len) {
+ *destbuf++ = bits;
+ pixels_read++;
+ }
+ } else {
+ bits = *(*srcbuf)++;
+
+ if (non_mod == 1 && bits == 1)
+ pixels_read += run_length;
+ if (map_table != NULL)
+ bits = map_table[bits];
+ else while (run_length-- > 0 && pixels_read < dbuf_len) {
+ *destbuf++ = bits;
+ pixels_read++;
+ }
+ }
+ }
+ }
+
+ if (*(*srcbuf)++ != 0)
+ av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n");
+
+ return pixels_read;
+}
+
+
+
+static void dvbsub_parse_pixel_data_block(AVCodecContext *avctx, DVBSubObjectDisplay *display,
+ uint8_t *buf, int buf_size, int top_bottom, int non_mod)
+{
+ DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data;
+
+ DVBSubRegion *region = get_region(ctx, display->region_id);
+ uint8_t *buf_end = buf + buf_size;
+ uint8_t *pbuf;
+ int x_pos, y_pos;
+ int i;
+
+ uint8_t map2to4[] = { 0x0, 0x7, 0x8, 0xf};
+ uint8_t map2to8[] = {0x00, 0x77, 0x88, 0xff};
+ uint8_t map4to8[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
+ 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};
+ uint8_t *map_table;
+
+#ifdef DEBUG
+ av_log(avctx, AV_LOG_INFO, "DVB pixel block size %d, %s field:\n", buf_size,
+ top_bottom ? "bottom" : "top");
+#endif
+
+#ifdef DEBUG_PACKET_CONTENTS
+ for (i = 0; i < buf_size; i++)
+ {
+ if (i % 16 == 0)
+ av_log(avctx, AV_LOG_INFO, "0x%08p: ", buf+i);
+
+ av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]);
+ if (i % 16 == 15)
+ av_log(avctx, AV_LOG_INFO, "\n");
+ }
+
+ if (i % 16 != 0)
+ av_log(avctx, AV_LOG_INFO, "\n");
+
+#endif
+
+ if (region == 0)
+ return;
+
+ pbuf = region->pbuf;
+
+ x_pos = display->x_pos;
+ y_pos = display->y_pos;
+
+ if ((y_pos & 1) != top_bottom)
+ y_pos++;
+
+ while (buf < buf_end) {
+ if (x_pos > region->width || y_pos > region->height) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid object location!\n");
+ return;
+ }
+
+ switch (*buf++) {
+ case 0x10:
+ if (region->depth == 8)
+ map_table = map2to8;
+ else if (region->depth == 4)
+ map_table = map2to4;
+ else
+ map_table = NULL;
+
+ x_pos += dvbsub_read_2bit_string(pbuf + (y_pos * region->width) + x_pos,
+ region->width - x_pos, &buf, buf_size,
+ non_mod, map_table);
+ break;
+ case 0x11:
+ if (region->depth < 4) {
+ av_log(avctx, AV_LOG_ERROR, "4-bit pixel string in %d-bit region!\n", region->depth);
+ return;
+ }
+
+ if (region->depth == 8)
+ map_table = map4to8;
+ else
+ map_table = NULL;
+
+ x_pos += dvbsub_read_4bit_string(pbuf + (y_pos * region->width) + x_pos,
+ region->width - x_pos, &buf, buf_size,
+ non_mod, map_table);
+ break;
+ case 0x12:
+ if (region->depth < 8) {
+ av_log(avctx, AV_LOG_ERROR, "8-bit pixel string in %d-bit region!\n", region->depth);
+ return;
+ }
+
+ x_pos += dvbsub_read_8bit_string(pbuf + (y_pos * region->width) + x_pos,
+ region->width - x_pos, &buf, buf_size,
+ non_mod, NULL);
+ break;
+
+ case 0x20:
+ map2to4[0] = (*buf) >> 4;
+ map2to4[1] = (*buf++) & 0xf;
+ map2to4[2] = (*buf) >> 4;
+ map2to4[3] = (*buf++) & 0xf;
+ break;
+ case 0x21:
+ for (i = 0; i < 4; i++)
+ map2to8[i] = *buf++;
+ break;
+ case 0x22:
+ for (i = 0; i < 16; i++)
+ map4to8[i] = *buf++;
+ break;
+
+ case 0xf0:
+ x_pos = display->x_pos;
+ y_pos += 2;
+ break;
+ default:
+ av_log(avctx, AV_LOG_INFO, "Unknown/unsupported pixel block 0x%x\n", *(buf-1));
+ }
+ }
+
+}
+
+static void dvbsub_parse_object_segment(AVCodecContext *avctx,
+ uint8_t *buf, int buf_size)
+{
+ DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data;
+
+ uint8_t *buf_end = buf + buf_size;
+ uint8_t *block;
+ int object_id;
+ DVBSubObject *object;
+ DVBSubObjectDisplay *display;
+ int top_field_len, bottom_field_len;
+
+ int coding_method, non_modifying_colour;
+
+ object_id = AV_RB16(buf);
+ buf += 2;
+
+ object = get_object(ctx, object_id);
+
+ if (!object)
+ return;
+
+ coding_method = ((*buf) >> 2) & 3;
+ non_modifying_colour = ((*buf++) >> 1) & 1;
+
+ if (coding_method == 0) {
+ top_field_len = AV_RB16(buf);
+ buf += 2;
+ bottom_field_len = AV_RB16(buf);
+ buf += 2;
+
+ if (buf + top_field_len + bottom_field_len > buf_end) {
+ av_log(avctx, AV_LOG_ERROR, "Field data size too large\n");
+ return;
+ }
+
+ for (display = object->display_list; display != 0; display = display->object_list_next) {
+ block = buf;
+
+ dvbsub_parse_pixel_data_block(avctx, display, block, top_field_len, 0,
+ non_modifying_colour);
+
+ if (bottom_field_len > 0)
+ block = buf + top_field_len;
+ else
+ bottom_field_len = top_field_len;
+
+ dvbsub_parse_pixel_data_block(avctx, display, block, bottom_field_len, 1,
+ non_modifying_colour);
+ }
+
+/* } else if (coding_method == 1) {*/
+
+ } else {
+ av_log(avctx, AV_LOG_ERROR, "Unknown object coding %d\n", coding_method);
+ }
+
+}
+
+#define SCALEBITS 10
+#define ONE_HALF (1 << (SCALEBITS - 1))
+#define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5))
+
+#define YUV_TO_RGB1_CCIR(cb1, cr1)\
+{\
+ cb = (cb1) - 128;\
+ cr = (cr1) - 128;\
+ r_add = FIX(1.40200*255.0/224.0) * cr + ONE_HALF;\
+ g_add = - FIX(0.34414*255.0/224.0) * cb - FIX(0.71414*255.0/224.0) * cr + \
+ ONE_HALF;\
+ b_add = FIX(1.77200*255.0/224.0) * cb + ONE_HALF;\
+}
+
+#define YUV_TO_RGB2_CCIR(r, g, b, y1)\
+{\
+ y = ((y1) - 16) * FIX(255.0/219.0);\
+ r = cm[(y + r_add) >> SCALEBITS];\
+ g = cm[(y + g_add) >> SCALEBITS];\
+ b = cm[(y + b_add) >> SCALEBITS];\
+}
+
+
+static void dvbsub_parse_clut_segment(AVCodecContext *avctx,
+ uint8_t *buf, int buf_size)
+{
+ DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data;
+
+ uint8_t *buf_end = buf + buf_size;
+ int clut_id;
+ DVBSubCLUT *clut;
+ int entry_id, depth , full_range;
+ int y, cr, cb, alpha;
+ int r, g, b, r_add, g_add, b_add;
+
+#ifdef DEBUG_PACKET_CONTENTS
+ int i;
+
+ av_log(avctx, AV_LOG_INFO, "DVB clut 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 % 16 != 0)
+ av_log(avctx, AV_LOG_INFO, "\n");
+
+#endif
+
+ clut_id = *buf++;
+ buf += 1;
+
+ clut = get_clut(ctx, clut_id);
+
+ if (clut == NULL) {
+ clut = av_malloc(sizeof(DVBSubCLUT));
+
+ memcpy(clut, &default_clut, sizeof(DVBSubCLUT));
+
+ clut->id = clut_id;
+
+ clut->next = ctx->clut_list;
+ ctx->clut_list = clut;
+ }
+
+ while (buf + 4 < buf_end)
+ {
+ entry_id = *buf++;
+
+ depth = (*buf) & 0xe0;
+
+ if (depth == 0) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid clut depth 0x%x!\n", *buf);
+ return;
+ }
+
+ full_range = (*buf++) & 1;
+
+ if (full_range) {
+ y = *buf++;
+ cr = *buf++;
+ cb = *buf++;
+ alpha = *buf++;
+ } else {
+ y = buf[0] & 0xfc;
+ cr = (((buf[0] & 3) << 2) | ((buf[1] >> 6) & 3)) << 4;
+ cb = (buf[1] << 2) & 0xf0;
+ alpha = (buf[1] << 6) & 0xc0;
+
+ buf += 2;
+ }
+
+ if (y == 0)
+ alpha = 0xff;
+
+ YUV_TO_RGB1_CCIR(cb, cr);
+ YUV_TO_RGB2_CCIR(r, g, b, y);
+
+#ifdef DEBUG
+ av_log(avctx, AV_LOG_INFO, "clut %d := (%d,%d,%d,%d)\n", entry_id, r, g, b, alpha);
+#endif
+
+ if (depth & 0x80)
+ clut->clut4[entry_id] = RGBA(r,g,b,255 - alpha);
+ if (depth & 0x40)
+ clut->clut16[entry_id] = RGBA(r,g,b,255 - alpha);
+ if (depth & 0x20)
+ clut->clut256[entry_id] = RGBA(r,g,b,255 - alpha);
+ }
+}
+
+
+static void dvbsub_parse_region_segment(AVCodecContext *avctx,
+ uint8_t *buf, int buf_size)
+{
+ DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data;
+
+ uint8_t *buf_end = buf + buf_size;
+ int region_id, object_id;
+ DVBSubRegion *region;
+ DVBSubObject *object;
+ DVBSubObjectDisplay *display;
+ int fill;
+
+ if (buf_size < 10)
+ return;
+
+ region_id = *buf++;
+
+ region = get_region(ctx, region_id);
+
+ if (region == NULL)
+ {
+ region = av_mallocz(sizeof(DVBSubRegion));
+
+ region->id = region_id;
+
+ region->next = ctx->region_list;
+ ctx->region_list = region;
+ }
+
+ fill = ((*buf++) >> 3) & 1;
+
+ region->width = AV_RB16(buf);
+ buf += 2;
+ region->height = AV_RB16(buf);
+ buf += 2;
+
+ if (region->width * region->height != region->buf_size) {
+ if (region->pbuf != 0)
+ av_free(region->pbuf);
+
+ region->buf_size = region->width * region->height;
+
+ region->pbuf = av_malloc(region->buf_size);
+
+ fill = 1;
+ }
+
+ region->depth = 1 << (((*buf++) >> 2) & 7);
+ region->clut = *buf++;
+
+ if (region->depth == 8)
+ region->bgcolour = *buf++;
+ else {
+ buf += 1;
+
+ if (region->depth == 4)
+ region->bgcolour = (((*buf++) >> 4) & 15);
+ else
+ region->bgcolour = (((*buf++) >> 2) & 3);
+ }
+
+#ifdef DEBUG
+ av_log(avctx, AV_LOG_INFO, "Region %d, (%dx%d)\n", region_id, region->width, region->height);
+#endif
+
+ if (fill) {
+ memset(region->pbuf, region->bgcolour, region->buf_size);
+#ifdef DEBUG
+ av_log(avctx, AV_LOG_INFO, "Fill region (%d)\n", region->bgcolour);
+#endif
+ }
+
+ delete_region_display_list(ctx, region);
+
+ while (buf + 5 < buf_end) {
+ object_id = AV_RB16(buf);
+ buf += 2;
+
+ object = get_object(ctx, object_id);
+
+ if (object == NULL) {
+ object = av_mallocz(sizeof(DVBSubObject));
+
+ object->id = object_id;
+ object->next = ctx->object_list;
+ ctx->object_list = object;
+ }
+
+ object->type = (*buf) >> 6;
+
+ display = av_mallocz(sizeof(DVBSubObjectDisplay));
+
+ display->object_id = object_id;
+ display->region_id = region_id;
+
+ display->x_pos = AV_RB16(buf) & 0xfff;
+ buf += 2;
+ display->y_pos = AV_RB16(buf) & 0xfff;
+ buf += 2;
+
+ if ((object->type == 1 || object->type == 2) && buf+1 < buf_end) {
+ display->fgcolour = *buf++;
+ display->bgcolour = *buf++;
+ }
+
+ display->region_list_next = region->display_list;
+ region->display_list = display;
+
+ display->object_list_next = object->display_list;
+ object->display_list = display;
+ }
+}
+
+static void dvbsub_parse_page_segment(AVCodecContext *avctx,
+ uint8_t *buf, int buf_size)
+{
+ DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data;
+ DVBSubRegionDisplay *display;
+ DVBSubRegionDisplay *tmp_display_list, **tmp_ptr;
+
+ uint8_t *buf_end = buf + buf_size;
+ int region_id;
+ int page_state;
+
+ if (buf_size < 1)
+ return;
+
+ ctx->time_out = *buf++;
+ page_state = ((*buf++) >> 2) & 3;
+
+#ifdef DEBUG
+ av_log(avctx, AV_LOG_INFO, "Page time out %ds, state %d\n", ctx->time_out, page_state);
+#endif
+
+ if (page_state == 2)
+ {
+ delete_state(ctx);
+ }
+
+ tmp_display_list = ctx->display_list;
+ ctx->display_list = NULL;
+ ctx->display_list_size = 0;
+
+ while (buf + 5 < buf_end) {
+ region_id = *buf++;
+ buf += 1;
+
+ display = tmp_display_list;
+ tmp_ptr = &tmp_display_list;
+
+ while (display != NULL && display->region_id != region_id) {
+ tmp_ptr = &display->next;
+ display = display->next;
+ }
+
+ if (display == NULL)
+ display = av_mallocz(sizeof(DVBSubRegionDisplay));
+
+ display->region_id = region_id;
+
+ display->x_pos = AV_RB16(buf);
+ buf += 2;
+ display->y_pos = AV_RB16(buf);
+ buf += 2;
+
+ *tmp_ptr = display->next;
+
+ display->next = ctx->display_list;
+ ctx->display_list = display;
+ ctx->display_list_size++;
+
+#ifdef DEBUG
+ av_log(avctx, AV_LOG_INFO, "Region %d, (%d,%d)\n", region_id, display->x_pos, display->y_pos);
+#endif
+ }
+
+ while (tmp_display_list != 0) {
+ display = tmp_display_list;
+
+ tmp_display_list = display->next;
+
+ av_free(display);
+ }
+
+}
+
+
+#ifdef DEBUG_SAVE_IMAGES
+static void save_display_set(DVBSubContext *ctx)
+{
+ DVBSubRegion *region;
+ DVBSubRegionDisplay *display;
+ DVBSubCLUT *clut;
+ uint32_t *clut_table;
+ int x_pos, y_pos, width, height;
+ int x, y, y_off, x_off;
+ uint32_t *pbuf;
+ char filename[32];
+ static int fileno_index = 0;
+
+ x_pos = -1;
+ y_pos = -1;
+ width = 0;
+ height = 0;
+
+ for (display = ctx->display_list; display != NULL; display = display->next) {
+ region = get_region(ctx, display->region_id);
+
+ if (x_pos == -1) {
+ x_pos = display->x_pos;
+ y_pos = display->y_pos;
+ width = region->width;
+ height = region->height;
+ } else {
+ if (display->x_pos < x_pos) {
+ width += (x_pos - display->x_pos);
+ x_pos = display->x_pos;
+ }
+
+ if (display->y_pos < y_pos) {
+ height += (y_pos - display->y_pos);
+ y_pos = display->y_pos;
+ }
+
+ if (display->x_pos + region->width > x_pos + width) {
+ width = display->x_pos + region->width - x_pos;
+ }
+
+ if (display->y_pos + region->height > y_pos + height) {
+ height = display->y_pos + region->height - y_pos;
+ }
+ }
+ }
+
+ if (x_pos >= 0) {
+
+ pbuf = av_malloc(width * height * 4);
+
+ for (display = ctx->display_list; display != NULL; display = display->next) {
+ region = get_region(ctx, display->region_id);
+
+ x_off = display->x_pos - x_pos;
+ y_off = display->y_pos - y_pos;
+
+ clut = get_clut(ctx, region->clut);
+
+ if (clut == 0)
+ clut = &default_clut;
+
+ switch (region->depth) {
+ case 2:
+ clut_table = clut->clut4;
+ break;
+ case 8:
+ clut_table = clut->clut256;
+ break;
+ case 4:
+ default:
+ clut_table = clut->clut16;
+ break;
+ }
+
+ for (y = 0; y < region->height; y++) {
+ for (x = 0; x < region->width; x++) {
+ pbuf[((y + y_off) * width) + x_off + x] =
+ clut_table[region->pbuf[y * region->width + x]];
+ }
+ }
+
+ }
+
+ snprintf(filename, 32, "dvbs.%d", fileno_index);
+
+ png_save2(filename, pbuf, width, height);
+
+ av_free(pbuf);
+ }
+
+ fileno_index++;
+}
+#endif
+
+static int dvbsub_display_end_segment(AVCodecContext *avctx, uint8_t *buf,
+ int buf_size, AVSubtitle *sub)
+{
+ DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data;
+
+ DVBSubRegion *region;
+ DVBSubRegionDisplay *display;
+ AVSubtitleRect *rect;
+ DVBSubCLUT *clut;
+ uint32_t *clut_table;
+ int i;
+
+ sub->rects = NULL;
+ sub->start_display_time = 0;
+ sub->end_display_time = ctx->time_out * 1000;
+ sub->format = 0;
+
+ sub->num_rects = ctx->display_list_size;
+
+ if (sub->num_rects > 0)
+ sub->rects = av_mallocz(sizeof(AVSubtitleRect) * sub->num_rects);
+
+ i = 0;
+
+ for (display = ctx->display_list; display != NULL; display = display->next) {
+ region = get_region(ctx, display->region_id);
+ rect = &sub->rects[i];
+
+ if (region == NULL)
+ continue;
+
+ rect->x = display->x_pos;
+ rect->y = display->y_pos;
+ rect->w = region->width;
+ rect->h = region->height;
+ rect->nb_colors = 16;
+ rect->linesize = region->width;
+
+ clut = get_clut(ctx, region->clut);
+
+ if (clut == NULL)
+ clut = &default_clut;
+
+ switch (region->depth) {
+ case 2:
+ clut_table = clut->clut4;
+ break;
+ case 8:
+ clut_table = clut->clut256;
+ break;
+ case 4:
+ default:
+ clut_table = clut->clut16;
+ break;
+ }
+
+ rect->rgba_palette = av_malloc((1 << region->depth) * sizeof(uint32_t));
+ memcpy(rect->rgba_palette, clut_table, (1 << region->depth) * sizeof(uint32_t));
+
+ rect->bitmap = av_malloc(region->buf_size);
+ memcpy(rect->bitmap, region->pbuf, region->buf_size);
+
+ i++;
+ }
+
+ sub->num_rects = i;
+
+#ifdef DEBUG_SAVE_IMAGES
+ save_display_set(ctx);
+#endif
+
+ return 1;
+}
+
+static int dvbsub_decode(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data;
+ AVSubtitle *sub = (AVSubtitle*) data;
+ uint8_t *p, *p_end;
+ int segment_type;
+ int page_id;
+ int segment_length;
+
+#ifdef DEBUG_PACKET_CONTENTS
+ int i;
+
+ av_log(avctx, AV_LOG_INFO, "DVB 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 % 16 != 0)
+ av_log(avctx, AV_LOG_INFO, "\n");
+
+#endif
+
+ if (buf_size <= 2)
+ return -1;
+
+ p = buf;
+ p_end = buf + buf_size;
+
+ while (p < p_end && *p == 0x0f)
+ {
+ p += 1;
+ segment_type = *p++;
+ page_id = AV_RB16(p);
+ p += 2;
+ segment_length = AV_RB16(p);
+ p += 2;
+
+ if (page_id == ctx->composition_id || page_id == ctx->ancillary_id) {
+ switch (segment_type) {
+ case DVBSUB_PAGE_SEGMENT:
+ dvbsub_parse_page_segment(avctx, p, segment_length);
+ break;
+ case DVBSUB_REGION_SEGMENT:
+ dvbsub_parse_region_segment(avctx, p, segment_length);
+ break;
+ case DVBSUB_CLUT_SEGMENT:
+ dvbsub_parse_clut_segment(avctx, p, segment_length);
+ break;
+ case DVBSUB_OBJECT_SEGMENT:
+ dvbsub_parse_object_segment(avctx, p, segment_length);
+ break;
+ case DVBSUB_DISPLAY_SEGMENT:
+ *data_size = dvbsub_display_end_segment(avctx, p, segment_length, sub);
+ break;
+ default:
+#ifdef DEBUG
+ av_log(avctx, AV_LOG_INFO, "Subtitling segment type 0x%x, page id %d, length %d\n",
+ segment_type, page_id, segment_length);
+#endif
+ break;
+ }
+ }
+
+ p += segment_length;
+ }
+
+ if (p != p_end)
+ {
+#ifdef DEBUG
+ av_log(avctx, AV_LOG_INFO, "Junk at end of packet\n");
+#endif
+ return -1;
+ }
+
+ return buf_size;
+}
+
+
+AVCodec dvbsub_decoder = {
+ "dvbsub",
+ CODEC_TYPE_SUBTITLE,
+ CODEC_ID_DVB_SUBTITLE,
+ sizeof(DVBSubContext),
+ dvbsub_init_decoder,
+ NULL,
+ dvbsub_close_decoder,
+ dvbsub_decode,
+};
+
+/* Parser (mostly) copied from dvdsub.c */
+
+#define PARSE_BUF_SIZE (65536)
+
+
+/* parser definition */
+typedef struct DVBSubParseContext {
+ uint8_t *packet_buf;
+ int packet_start;
+ int packet_index;
+ int in_packet;
+} DVBSubParseContext;
+
+static int dvbsub_parse_init(AVCodecParserContext *s)
+{
+ DVBSubParseContext *pc = s->priv_data;
+ pc->packet_buf = av_malloc(PARSE_BUF_SIZE);
+
+ return 0;
+}
+
+static int dvbsub_parse(AVCodecParserContext *s,
+ AVCodecContext *avctx,
+ uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size)
+{
+ DVBSubParseContext *pc = s->priv_data;
+ uint8_t *p, *p_end;
+ int len, buf_pos = 0;
+
+#ifdef DEBUG
+ av_log(avctx, AV_LOG_INFO, "DVB parse packet pts=%"PRIx64", lpts=%"PRIx64", cpts=%"PRIx64":\n",
+ s->pts, s->last_pts, s->cur_frame_pts[s->cur_frame_start_index]);
+#endif
+
+#ifdef DEBUG_PACKET_CONTENTS
+ int i;
+
+ 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 % 16 != 0)
+ av_log(avctx, AV_LOG_INFO, "\n");
+
+#endif
+
+ *poutbuf = NULL;
+ *poutbuf_size = 0;
+
+ s->fetch_timestamp = 1;
+
+ if (s->last_pts != s->pts && s->last_pts != AV_NOPTS_VALUE) /* Start of a new packet */
+ {
+ if (pc->packet_index != pc->packet_start)
+ {
+#ifdef DEBUG
+ av_log(avctx, AV_LOG_INFO, "Discarding %d bytes\n",
+ pc->packet_index - pc->packet_start);
+#endif
+ }
+
+ pc->packet_start = 0;
+ pc->packet_index = 0;
+
+ if (buf_size < 2 || buf[0] != 0x20 || buf[1] != 0x00) {
+#ifdef DEBUG
+ av_log(avctx, AV_LOG_INFO, "Bad packet header\n");
+#endif
+ return -1;
+ }
+
+ buf_pos = 2;
+
+ pc->in_packet = 1;
+ } else {
+ if (pc->packet_start != 0)
+ {
+ if (pc->packet_index != pc->packet_start)
+ {
+ memmove(pc->packet_buf, pc->packet_buf + pc->packet_start,
+ pc->packet_index - pc->packet_start);
+
+ pc->packet_index -= pc->packet_start;
+ pc->packet_start = 0;
+ } else {
+ pc->packet_start = 0;
+ pc->packet_index = 0;
+ }
+ }
+ }
+
+ if (buf_size - buf_pos + pc->packet_index > PARSE_BUF_SIZE)
+ return -1;
+
+/* if not currently in a packet, discard data */
+ if (pc->in_packet == 0)
+ return buf_size;
+
+ memcpy(pc->packet_buf + pc->packet_index, buf + buf_pos, buf_size - buf_pos);
+ pc->packet_index += buf_size - buf_pos;
+
+ p = pc->packet_buf;
+ p_end = pc->packet_buf + pc->packet_index;
+
+ while (p < p_end)
+ {
+ if (*p == 0x0f)
+ {
+ if (p + 6 <= p_end)
+ {
+ len = AV_RB16(p + 4);
+
+ if (p + len + 6 <= p_end)
+ {
+ *poutbuf_size += len + 6;
+
+ p += len + 6;
+ } else
+ break;
+ } else
+ break;
+ } else if (*p == 0xff) {
+ if (p + 1 < p_end)
+ {
+#ifdef DEBUG
+ av_log(avctx, AV_LOG_INFO, "Junk at end of packet\n");
+#endif
+ }
+ pc->packet_index = p - pc->packet_buf;
+ pc->in_packet = 0;
+ break;
+ } else {
+ av_log(avctx, AV_LOG_ERROR, "Junk in packet\n");
+
+ pc->packet_index = p - pc->packet_buf;
+ pc->in_packet = 0;
+ break;
+ }
+ }
+
+ if (*poutbuf_size > 0)
+ {
+ *poutbuf = pc->packet_buf;
+ pc->packet_start = *poutbuf_size;
+ }
+
+ if (s->last_pts == AV_NOPTS_VALUE)
+ s->last_pts = s->pts;
+
+ return buf_size;
+}
+
+static void dvbsub_parse_close(AVCodecParserContext *s)
+{
+ DVBSubParseContext *pc = s->priv_data;
+ av_freep(&pc->packet_buf);
+}
+
+AVCodecParser dvbsub_parser = {
+ { CODEC_ID_DVB_SUBTITLE },
+ sizeof(DVBSubParseContext),
+ dvbsub_parse_init,
+ dvbsub_parse,
+ dvbsub_parse_close,
+};
diff --git a/src/libffmpeg/libavcodec/dvdata.h b/contrib/ffmpeg/libavcodec/dvdata.h
index e688ffbb0..e688ffbb0 100644
--- a/src/libffmpeg/libavcodec/dvdata.h
+++ b/contrib/ffmpeg/libavcodec/dvdata.h
diff --git a/contrib/ffmpeg/libavcodec/dvdsubdec.c b/contrib/ffmpeg/libavcodec/dvdsubdec.c
new file mode 100644
index 000000000..3a93a6076
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/dvdsubdec.c
@@ -0,0 +1,472 @@
+/*
+ * DVD subtitle decoding for ffmpeg
+ * Copyright (c) 2005 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"
+
+//#define DEBUG
+
+static int dvdsub_init_decoder(AVCodecContext *avctx)
+{
+ return 0;
+}
+
+static int get_nibble(const uint8_t *buf, int nibble_offset)
+{
+ return (buf[nibble_offset >> 1] >> ((1 - (nibble_offset & 1)) << 2)) & 0xf;
+}
+
+static int decode_rle(uint8_t *bitmap, int linesize, int w, int h,
+ const uint8_t *buf, int nibble_offset, int buf_size)
+{
+ unsigned int v;
+ int x, y, len, color, nibble_end;
+ uint8_t *d;
+
+ nibble_end = buf_size * 2;
+ x = 0;
+ y = 0;
+ d = bitmap;
+ for(;;) {
+ if (nibble_offset >= nibble_end)
+ return -1;
+ v = get_nibble(buf, nibble_offset++);
+ if (v < 0x4) {
+ v = (v << 4) | get_nibble(buf, nibble_offset++);
+ if (v < 0x10) {
+ v = (v << 4) | get_nibble(buf, nibble_offset++);
+ if (v < 0x040) {
+ v = (v << 4) | get_nibble(buf, nibble_offset++);
+ if (v < 4) {
+ v |= (w - x) << 2;
+ }
+ }
+ }
+ }
+ len = v >> 2;
+ if (len > (w - x))
+ len = (w - x);
+ color = v & 0x03;
+ memset(d + x, color, len);
+ x += len;
+ if (x >= w) {
+ y++;
+ if (y >= h)
+ break;
+ d += linesize;
+ x = 0;
+ /* byte align */
+ nibble_offset += (nibble_offset & 1);
+ }
+ }
+ return 0;
+}
+
+static void guess_palette(uint32_t *rgba_palette,
+ uint8_t *palette,
+ uint8_t *alpha,
+ uint32_t subtitle_color)
+{
+ uint8_t color_used[16];
+ int nb_opaque_colors, i, level, j, r, g, b;
+
+ for(i = 0; i < 4; i++)
+ rgba_palette[i] = 0;
+
+ memset(color_used, 0, 16);
+ nb_opaque_colors = 0;
+ for(i = 0; i < 4; i++) {
+ if (alpha[i] != 0 && !color_used[palette[i]]) {
+ color_used[palette[i]] = 1;
+ nb_opaque_colors++;
+ }
+ }
+
+ if (nb_opaque_colors == 0)
+ return;
+
+ j = nb_opaque_colors;
+ memset(color_used, 0, 16);
+ for(i = 0; i < 4; i++) {
+ if (alpha[i] != 0) {
+ if (!color_used[palette[i]]) {
+ level = (0xff * j) / nb_opaque_colors;
+ r = (((subtitle_color >> 16) & 0xff) * level) >> 8;
+ g = (((subtitle_color >> 8) & 0xff) * level) >> 8;
+ b = (((subtitle_color >> 0) & 0xff) * level) >> 8;
+ rgba_palette[i] = b | (g << 8) | (r << 16) | ((alpha[i] * 17) << 24);
+ color_used[palette[i]] = (i + 1);
+ j--;
+ } else {
+ rgba_palette[i] = (rgba_palette[color_used[palette[i]] - 1] & 0x00ffffff) |
+ ((alpha[i] * 17) << 24);
+ }
+ }
+ }
+}
+
+static int decode_dvd_subtitles(AVSubtitle *sub_header,
+ const uint8_t *buf, int buf_size)
+{
+ int cmd_pos, pos, cmd, x1, y1, x2, y2, offset1, offset2, next_cmd_pos;
+ uint8_t palette[4], alpha[4];
+ int date;
+ int i;
+ int is_menu = 0;
+
+ if (buf_size < 4)
+ return -1;
+ sub_header->rects = NULL;
+ sub_header->num_rects = 0;
+ sub_header->start_display_time = 0;
+ sub_header->end_display_time = 0;
+
+ cmd_pos = AV_RB16(buf + 2);
+ while ((cmd_pos + 4) < buf_size) {
+ date = AV_RB16(buf + cmd_pos);
+ next_cmd_pos = AV_RB16(buf + cmd_pos + 2);
+#ifdef DEBUG
+ av_log(NULL, AV_LOG_INFO, "cmd_pos=0x%04x next=0x%04x date=%d\n",
+ cmd_pos, next_cmd_pos, date);
+#endif
+ pos = cmd_pos + 4;
+ offset1 = -1;
+ offset2 = -1;
+ x1 = y1 = x2 = y2 = 0;
+ while (pos < buf_size) {
+ cmd = buf[pos++];
+#ifdef DEBUG
+ av_log(NULL, AV_LOG_INFO, "cmd=%02x\n", cmd);
+#endif
+ switch(cmd) {
+ case 0x00:
+ /* menu subpicture */
+ is_menu = 1;
+ break;
+ case 0x01:
+ /* set start date */
+ sub_header->start_display_time = (date << 10) / 90;
+ break;
+ case 0x02:
+ /* set end date */
+ sub_header->end_display_time = (date << 10) / 90;
+ break;
+ case 0x03:
+ /* set palette */
+ if ((buf_size - pos) < 2)
+ goto fail;
+ palette[3] = buf[pos] >> 4;
+ palette[2] = buf[pos] & 0x0f;
+ palette[1] = buf[pos + 1] >> 4;
+ palette[0] = buf[pos + 1] & 0x0f;
+ pos += 2;
+ break;
+ case 0x04:
+ /* set alpha */
+ if ((buf_size - pos) < 2)
+ goto fail;
+ alpha[3] = buf[pos] >> 4;
+ alpha[2] = buf[pos] & 0x0f;
+ alpha[1] = buf[pos + 1] >> 4;
+ alpha[0] = buf[pos + 1] & 0x0f;
+ pos += 2;
+#ifdef DEBUG
+ av_log(NULL, AV_LOG_INFO, "alpha=%x%x%x%x\n", alpha[0],alpha[1],alpha[2],alpha[3]);
+#endif
+ break;
+ case 0x05:
+ if ((buf_size - pos) < 6)
+ goto fail;
+ x1 = (buf[pos] << 4) | (buf[pos + 1] >> 4);
+ x2 = ((buf[pos + 1] & 0x0f) << 8) | buf[pos + 2];
+ y1 = (buf[pos + 3] << 4) | (buf[pos + 4] >> 4);
+ y2 = ((buf[pos + 4] & 0x0f) << 8) | buf[pos + 5];
+#ifdef DEBUG
+ av_log(NULL, AV_LOG_INFO, "x1=%d x2=%d y1=%d y2=%d\n",
+ x1, x2, y1, y2);
+#endif
+ pos += 6;
+ break;
+ case 0x06:
+ if ((buf_size - pos) < 4)
+ goto fail;
+ offset1 = AV_RB16(buf + pos);
+ offset2 = AV_RB16(buf + pos + 2);
+#ifdef DEBUG
+ av_log(NULL, AV_LOG_INFO, "offset1=0x%04x offset2=0x%04x\n", offset1, offset2);
+#endif
+ pos += 4;
+ break;
+ case 0xff:
+ default:
+ goto the_end;
+ }
+ }
+ the_end:
+ if (offset1 >= 0) {
+ int w, h;
+ uint8_t *bitmap;
+
+ /* decode the bitmap */
+ w = x2 - x1 + 1;
+ if (w < 0)
+ w = 0;
+ h = y2 - y1;
+ if (h < 0)
+ h = 0;
+ if (w > 0 && h > 0) {
+ if (sub_header->rects != NULL) {
+ for (i = 0; i < sub_header->num_rects; i++) {
+ av_free(sub_header->rects[i].bitmap);
+ av_free(sub_header->rects[i].rgba_palette);
+ }
+ av_freep(&sub_header->rects);
+ sub_header->num_rects = 0;
+ }
+
+ bitmap = av_malloc(w * h);
+ sub_header->rects = av_mallocz(sizeof(AVSubtitleRect));
+ sub_header->num_rects = 1;
+ sub_header->rects[0].rgba_palette = av_malloc(4 * 4);
+ decode_rle(bitmap, w * 2, w, (h + 1) / 2,
+ buf, offset1 * 2, buf_size);
+ decode_rle(bitmap + w, w * 2, w, h / 2,
+ buf, offset2 * 2, buf_size);
+ guess_palette(sub_header->rects[0].rgba_palette,
+ palette, alpha, 0xffff00);
+ sub_header->rects[0].x = x1;
+ sub_header->rects[0].y = y1;
+ sub_header->rects[0].w = w;
+ sub_header->rects[0].h = h;
+ sub_header->rects[0].nb_colors = 4;
+ sub_header->rects[0].linesize = w;
+ sub_header->rects[0].bitmap = bitmap;
+ }
+ }
+ if (next_cmd_pos == cmd_pos)
+ break;
+ cmd_pos = next_cmd_pos;
+ }
+ if (sub_header->num_rects > 0)
+ return is_menu;
+ fail:
+ return -1;
+}
+
+static int is_transp(const uint8_t *buf, int pitch, int n,
+ const uint8_t *transp_color)
+{
+ int i;
+ for(i = 0; i < n; i++) {
+ if (!transp_color[*buf])
+ return 0;
+ buf += pitch;
+ }
+ return 1;
+}
+
+/* return 0 if empty rectangle, 1 if non empty */
+static int find_smallest_bounding_rectangle(AVSubtitle *s)
+{
+ uint8_t transp_color[256];
+ int y1, y2, x1, x2, y, w, h, i;
+ uint8_t *bitmap;
+
+ if (s->num_rects == 0 || s->rects == NULL || s->rects[0].w <= 0 || s->rects[0].h <= 0)
+ return 0;
+
+ memset(transp_color, 0, 256);
+ for(i = 0; i < s->rects[0].nb_colors; i++) {
+ if ((s->rects[0].rgba_palette[i] >> 24) == 0)
+ transp_color[i] = 1;
+ }
+ y1 = 0;
+ while (y1 < s->rects[0].h && is_transp(s->rects[0].bitmap + y1 * s->rects[0].linesize,
+ 1, s->rects[0].w, transp_color))
+ y1++;
+ if (y1 == s->rects[0].h) {
+ av_freep(&s->rects[0].bitmap);
+ s->rects[0].w = s->rects[0].h = 0;
+ return 0;
+ }
+
+ y2 = s->rects[0].h - 1;
+ while (y2 > 0 && is_transp(s->rects[0].bitmap + y2 * s->rects[0].linesize, 1,
+ s->rects[0].w, transp_color))
+ y2--;
+ x1 = 0;
+ while (x1 < (s->rects[0].w - 1) && is_transp(s->rects[0].bitmap + x1, s->rects[0].linesize,
+ s->rects[0].h, transp_color))
+ x1++;
+ x2 = s->rects[0].w - 1;
+ while (x2 > 0 && is_transp(s->rects[0].bitmap + x2, s->rects[0].linesize, s->rects[0].h,
+ transp_color))
+ x2--;
+ w = x2 - x1 + 1;
+ h = y2 - y1 + 1;
+ bitmap = av_malloc(w * h);
+ if (!bitmap)
+ return 1;
+ for(y = 0; y < h; y++) {
+ memcpy(bitmap + w * y, s->rects[0].bitmap + x1 + (y1 + y) * s->rects[0].linesize, w);
+ }
+ av_freep(&s->rects[0].bitmap);
+ s->rects[0].bitmap = bitmap;
+ s->rects[0].linesize = w;
+ s->rects[0].w = w;
+ s->rects[0].h = h;
+ s->rects[0].x += x1;
+ s->rects[0].y += y1;
+ return 1;
+}
+
+static int dvdsub_close_decoder(AVCodecContext *avctx)
+{
+ return 0;
+}
+
+#ifdef DEBUG
+#undef fprintf
+static void ppm_save(const char *filename, uint8_t *bitmap, int w, int h,
+ uint32_t *rgba_palette)
+{
+ int x, y, v;
+ FILE *f;
+
+ f = fopen(filename, "w");
+ if (!f) {
+ perror(filename);
+ exit(1);
+ }
+ fprintf(f, "P6\n"
+ "%d %d\n"
+ "%d\n",
+ w, h, 255);
+ for(y = 0; y < h; y++) {
+ for(x = 0; x < w; x++) {
+ v = rgba_palette[bitmap[y * w + x]];
+ putc((v >> 16) & 0xff, f);
+ putc((v >> 8) & 0xff, f);
+ putc((v >> 0) & 0xff, f);
+ }
+ }
+ fclose(f);
+}
+#endif
+
+static int dvdsub_decode(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ AVSubtitle *sub = (void *)data;
+ int is_menu;
+
+ is_menu = decode_dvd_subtitles(sub, buf, buf_size);
+
+ if (is_menu < 0) {
+ no_subtitle:
+ *data_size = 0;
+
+ return buf_size;
+ }
+ if (!is_menu && find_smallest_bounding_rectangle(sub) == 0)
+ goto no_subtitle;
+
+#if defined(DEBUG)
+ av_log(NULL, AV_LOG_INFO, "start=%d ms end =%d ms\n",
+ sub->start_display_time,
+ sub->end_display_time);
+ ppm_save("/tmp/a.ppm", sub->rects[0].bitmap,
+ sub->rects[0].w, sub->rects[0].h, sub->rects[0].rgba_palette);
+#endif
+
+ *data_size = 1;
+ return buf_size;
+}
+
+AVCodec dvdsub_decoder = {
+ "dvdsub",
+ CODEC_TYPE_SUBTITLE,
+ CODEC_ID_DVD_SUBTITLE,
+ 0,
+ dvdsub_init_decoder,
+ NULL,
+ dvdsub_close_decoder,
+ dvdsub_decode,
+};
+
+/* parser definition */
+typedef struct DVDSubParseContext {
+ uint8_t *packet;
+ int packet_len;
+ int packet_index;
+} DVDSubParseContext;
+
+static int dvdsub_parse_init(AVCodecParserContext *s)
+{
+ return 0;
+}
+
+static int dvdsub_parse(AVCodecParserContext *s,
+ AVCodecContext *avctx,
+ uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size)
+{
+ DVDSubParseContext *pc = s->priv_data;
+
+ if (pc->packet_index == 0) {
+ if (buf_size < 2)
+ return 0;
+ pc->packet_len = AV_RB16(buf);
+ av_freep(&pc->packet);
+ pc->packet = av_malloc(pc->packet_len);
+ }
+ if (pc->packet) {
+ if (pc->packet_index + buf_size <= pc->packet_len) {
+ memcpy(pc->packet + pc->packet_index, buf, buf_size);
+ pc->packet_index += buf_size;
+ if (pc->packet_index >= pc->packet_len) {
+ *poutbuf = pc->packet;
+ *poutbuf_size = pc->packet_len;
+ pc->packet_index = 0;
+ return buf_size;
+ }
+ } else {
+ /* erroneous size */
+ pc->packet_index = 0;
+ }
+ }
+ *poutbuf = NULL;
+ *poutbuf_size = 0;
+ return buf_size;
+}
+
+static void dvdsub_parse_close(AVCodecParserContext *s)
+{
+ DVDSubParseContext *pc = s->priv_data;
+ av_freep(&pc->packet);
+}
+
+AVCodecParser dvdsub_parser = {
+ { CODEC_ID_DVD_SUBTITLE },
+ sizeof(DVDSubParseContext),
+ dvdsub_parse_init,
+ dvdsub_parse,
+ dvdsub_parse_close,
+};
diff --git a/contrib/ffmpeg/libavcodec/dvdsubenc.c b/contrib/ffmpeg/libavcodec/dvdsubenc.c
new file mode 100644
index 000000000..fac29acc2
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/dvdsubenc.c
@@ -0,0 +1,247 @@
+/*
+ * DVD subtitle encoding for ffmpeg
+ * Copyright (c) 2005 Wolfram Gloger.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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"
+
+#undef NDEBUG
+#include <assert.h>
+
+// ncnt is the nibble counter
+#define PUTNIBBLE(val)\
+do {\
+ if (ncnt++ & 1)\
+ *q++ = bitbuf | ((val) & 0x0f);\
+ else\
+ bitbuf = (val) << 4;\
+} while(0)
+
+static void dvd_encode_rle(uint8_t **pq,
+ const uint8_t *bitmap, int linesize,
+ int w, int h,
+ const int cmap[256])
+{
+ uint8_t *q;
+ unsigned int bitbuf = 0;
+ int ncnt;
+ int x, y, len, color;
+
+ q = *pq;
+
+ for (y = 0; y < h; ++y) {
+ ncnt = 0;
+ for(x = 0; x < w; x += len) {
+ color = bitmap[x];
+ for (len=1; x+len < w; ++len)
+ if (bitmap[x+len] != color)
+ break;
+ color = cmap[color];
+ assert(color < 4);
+ if (len < 0x04) {
+ PUTNIBBLE((len << 2)|color);
+ } else if (len < 0x10) {
+ PUTNIBBLE(len >> 2);
+ PUTNIBBLE((len << 2)|color);
+ } else if (len < 0x40) {
+ PUTNIBBLE(0);
+ PUTNIBBLE(len >> 2);
+ PUTNIBBLE((len << 2)|color);
+ } else if (x+len == w) {
+ PUTNIBBLE(0);
+ PUTNIBBLE(0);
+ PUTNIBBLE(0);
+ PUTNIBBLE(color);
+ } else {
+ if (len > 0xff)
+ len = 0xff;
+ PUTNIBBLE(0);
+ PUTNIBBLE(len >> 6);
+ PUTNIBBLE(len >> 2);
+ PUTNIBBLE((len << 2)|color);
+ }
+ }
+ /* end of line */
+ if (ncnt & 1)
+ PUTNIBBLE(0);
+ bitmap += linesize;
+ }
+
+ *pq = q;
+}
+
+static inline void putbe16(uint8_t **pq, uint16_t v)
+{
+ uint8_t *q = *pq;
+ *q++ = v >> 8;
+ *q++ = v;
+ *pq = q;
+}
+
+static int encode_dvd_subtitles(uint8_t *outbuf, int outbuf_size,
+ const AVSubtitle *h)
+{
+ uint8_t *q, *qq;
+ int object_id;
+ int offset1[20], offset2[20];
+ int i, imax, color, alpha, rects = h->num_rects;
+ unsigned long hmax;
+ unsigned long hist[256];
+ int cmap[256];
+
+ if (rects == 0 || h->rects == NULL)
+ return -1;
+ if (rects > 20)
+ rects = 20;
+
+ // analyze bitmaps, compress to 4 colors
+ for (i=0; i<256; ++i) {
+ hist[i] = 0;
+ cmap[i] = 0;
+ }
+ for (object_id = 0; object_id < rects; object_id++)
+ for (i=0; i<h->rects[object_id].w*h->rects[object_id].h; ++i) {
+ color = h->rects[object_id].bitmap[i];
+ // only count non-transparent pixels
+ alpha = h->rects[object_id].rgba_palette[color] >> 24;
+ hist[color] += alpha;
+ }
+ for (color=3;; --color) {
+ hmax = 0;
+ imax = 0;
+ for (i=0; i<256; ++i)
+ if (hist[i] > hmax) {
+ imax = i;
+ hmax = hist[i];
+ }
+ if (hmax == 0)
+ break;
+ if (color == 0)
+ color = 3;
+ av_log(NULL, AV_LOG_DEBUG, "dvd_subtitle hist[%d]=%ld -> col %d\n",
+ imax, hist[imax], color);
+ cmap[imax] = color;
+ hist[imax] = 0;
+ }
+
+
+ // encode data block
+ q = outbuf + 4;
+ for (object_id = 0; object_id < rects; object_id++) {
+ offset1[object_id] = q - outbuf;
+ // worst case memory requirement: 1 nibble per pixel..
+ if ((q - outbuf) + h->rects[object_id].w*h->rects[object_id].h/2
+ + 17*rects + 21 > outbuf_size) {
+ av_log(NULL, AV_LOG_ERROR, "dvd_subtitle too big\n");
+ return -1;
+ }
+ dvd_encode_rle(&q, h->rects[object_id].bitmap,
+ h->rects[object_id].w*2,
+ h->rects[object_id].w, h->rects[object_id].h >> 1,
+ cmap);
+ offset2[object_id] = q - outbuf;
+ dvd_encode_rle(&q, h->rects[object_id].bitmap + h->rects[object_id].w,
+ h->rects[object_id].w*2,
+ h->rects[object_id].w, h->rects[object_id].h >> 1,
+ cmap);
+ }
+
+ // set data packet size
+ qq = outbuf + 2;
+ putbe16(&qq, q - outbuf);
+
+ // send start display command
+ putbe16(&q, (h->start_display_time*90) >> 10);
+ putbe16(&q, (q - outbuf) /*- 2 */ + 8 + 12*rects + 2);
+ *q++ = 0x03; // palette - 4 nibbles
+ *q++ = 0x03; *q++ = 0x7f;
+ *q++ = 0x04; // alpha - 4 nibbles
+ *q++ = 0xf0; *q++ = 0x00;
+ //*q++ = 0x0f; *q++ = 0xff;
+
+ // XXX not sure if more than one rect can really be encoded..
+ // 12 bytes per rect
+ for (object_id = 0; object_id < rects; object_id++) {
+ int x2 = h->rects[object_id].x + h->rects[object_id].w - 1;
+ int y2 = h->rects[object_id].y + h->rects[object_id].h - 1;
+
+ *q++ = 0x05;
+ // x1 x2 -> 6 nibbles
+ *q++ = h->rects[object_id].x >> 4;
+ *q++ = (h->rects[object_id].x << 4) | ((x2 >> 8) & 0xf);
+ *q++ = x2;
+ // y1 y2 -> 6 nibbles
+ *q++ = h->rects[object_id].y >> 4;
+ *q++ = (h->rects[object_id].y << 4) | ((y2 >> 8) & 0xf);
+ *q++ = y2;
+
+ *q++ = 0x06;
+ // offset1, offset2
+ putbe16(&q, offset1[object_id]);
+ putbe16(&q, offset2[object_id]);
+ }
+ *q++ = 0x01; // start command
+ *q++ = 0xff; // terminating command
+
+ // send stop display command last
+ putbe16(&q, (h->end_display_time*90) >> 10);
+ putbe16(&q, (q - outbuf) - 2 /*+ 4*/);
+ *q++ = 0x02; // set end
+ *q++ = 0xff; // terminating command
+
+ qq = outbuf;
+ putbe16(&qq, q - outbuf);
+
+ av_log(NULL, AV_LOG_DEBUG, "subtitle_packet size=%td\n", q - outbuf);
+ return q - outbuf;
+}
+
+static int dvdsub_init_encoder(AVCodecContext *avctx)
+{
+ return 0;
+}
+
+static int dvdsub_close_encoder(AVCodecContext *avctx)
+{
+ return 0;
+}
+
+static int dvdsub_encode(AVCodecContext *avctx,
+ unsigned char *buf, int buf_size, void *data)
+{
+ //DVDSubtitleContext *s = avctx->priv_data;
+ AVSubtitle *sub = data;
+ int ret;
+
+ ret = encode_dvd_subtitles(buf, buf_size, sub);
+ return ret;
+}
+
+AVCodec dvdsub_encoder = {
+ "dvdsub",
+ CODEC_TYPE_SUBTITLE,
+ CODEC_ID_DVD_SUBTITLE,
+ 0,
+ dvdsub_init_encoder,
+ dvdsub_encode,
+ dvdsub_close_encoder,
+};
+
+/* Local Variables: */
+/* c-basic-offset:4 */
+/* End: */
diff --git a/contrib/ffmpeg/libavcodec/dxa.c b/contrib/ffmpeg/libavcodec/dxa.c
new file mode 100644
index 000000000..fc201ccb4
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/dxa.c
@@ -0,0 +1,333 @@
+/*
+ * Feeble Files/ScummVM DXA decoder
+ * Copyright (c) 2007 Konstantin Shishkov
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * @file dxa.c
+ * DXA Video decoder
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "common.h"
+#include "avcodec.h"
+
+#include <zlib.h>
+
+/*
+ * Decoder context
+ */
+typedef struct DxaDecContext {
+ AVCodecContext *avctx;
+ AVFrame pic, prev;
+
+ int dsize;
+ uint8_t *decomp_buf;
+ uint32_t pal[256];
+} DxaDecContext;
+
+static const int shift1[6] = { 0, 8, 8, 8, 4, 4 };
+static const int shift2[6] = { 0, 0, 8, 4, 0, 4 };
+
+static int decode_13(AVCodecContext *avctx, DxaDecContext *c, uint8_t* dst, uint8_t *src, uint8_t *ref)
+{
+ uint8_t *code, *data, *mv, *msk, *tmp, *tmp2;
+ int i, j, k;
+ int type, x, y, d, d2;
+ int stride = c->pic.linesize[0];
+ uint32_t mask;
+
+ code = src + 12;
+ data = code + ((avctx->width * avctx->height) >> 4);
+ mv = data + AV_RB32(src + 0);
+ msk = mv + AV_RB32(src + 4);
+
+ for(j = 0; j < avctx->height; j += 4){
+ for(i = 0; i < avctx->width; i += 4){
+ tmp = dst + i;
+ tmp2 = ref + i;
+ type = *code++;
+ switch(type){
+ case 4: // motion compensation
+ x = (*mv) >> 4; if(x & 8) x = 8 - x;
+ y = (*mv++) & 0xF; if(y & 8) y = 8 - y;
+ tmp2 += x + y*stride;
+ case 0: // skip
+ case 5: // skip in method 12
+ for(y = 0; y < 4; y++){
+ memcpy(tmp, tmp2, 4);
+ tmp += stride;
+ tmp2 += stride;
+ }
+ break;
+ case 1: // masked change
+ case 10: // masked change with only half of pixels changed
+ case 11: // cases 10-15 are for method 12 only
+ case 12:
+ case 13:
+ case 14:
+ case 15:
+ if(type == 1){
+ mask = AV_RB16(msk);
+ msk += 2;
+ }else{
+ type -= 10;
+ mask = ((msk[0] & 0xF0) << shift1[type]) | ((msk[0] & 0xF) << shift2[type]);
+ msk++;
+ }
+ for(y = 0; y < 4; y++){
+ for(x = 0; x < 4; x++){
+ tmp[x] = (mask & 0x8000) ? *data++ : tmp2[x];
+ mask <<= 1;
+ }
+ tmp += stride;
+ tmp2 += stride;
+ }
+ break;
+ case 2: // fill block
+ for(y = 0; y < 4; y++){
+ memset(tmp, data[0], 4);
+ tmp += stride;
+ }
+ data++;
+ break;
+ case 3: // raw block
+ for(y = 0; y < 4; y++){
+ memcpy(tmp, data, 4);
+ data += 4;
+ tmp += stride;
+ }
+ break;
+ case 8: // subblocks - method 13 only
+ mask = *msk++;
+ for(k = 0; k < 4; k++){
+ d = ((k & 1) << 1) + ((k & 2) * stride);
+ d2 = ((k & 1) << 1) + ((k & 2) * stride);
+ tmp2 = ref + i + d2;
+ switch(mask & 0xC0){
+ case 0x80: // motion compensation
+ x = (*mv) >> 4; if(x & 8) x = 8 - x;
+ y = (*mv++) & 0xF; if(y & 8) y = 8 - y;
+ tmp2 += x + y*stride;
+ case 0x00: // skip
+ tmp[d + 0 ] = tmp2[0];
+ tmp[d + 1 ] = tmp2[1];
+ tmp[d + 0 + stride] = tmp2[0 + stride];
+ tmp[d + 1 + stride] = tmp2[1 + stride];
+ break;
+ case 0x40: // fill
+ tmp[d + 0 ] = data[0];
+ tmp[d + 1 ] = data[0];
+ tmp[d + 0 + stride] = data[0];
+ tmp[d + 1 + stride] = data[0];
+ data++;
+ break;
+ case 0xC0: // raw
+ tmp[d + 0 ] = *data++;
+ tmp[d + 1 ] = *data++;
+ tmp[d + 0 + stride] = *data++;
+ tmp[d + 1 + stride] = *data++;
+ break;
+ }
+ mask <<= 2;
+ }
+ break;
+ case 32: // vector quantization - 2 colors
+ mask = AV_RB16(msk);
+ msk += 2;
+ for(y = 0; y < 4; y++){
+ for(x = 0; x < 4; x++){
+ tmp[x] = data[mask & 1];
+ mask >>= 1;
+ }
+ tmp += stride;
+ tmp2 += stride;
+ }
+ data += 2;
+ break;
+ case 33: // vector quantization - 3 or 4 colors
+ case 34:
+ mask = AV_RB32(msk);
+ msk += 4;
+ for(y = 0; y < 4; y++){
+ for(x = 0; x < 4; x++){
+ tmp[x] = data[mask & 3];
+ mask >>= 2;
+ }
+ tmp += stride;
+ tmp2 += stride;
+ }
+ data += type - 30;
+ break;
+ default:
+ av_log(avctx, AV_LOG_ERROR, "Unknown opcode %d\n", type);
+ return -1;
+ }
+ }
+ dst += stride * 4;
+ ref += stride * 4;
+ }
+ return 0;
+}
+
+static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size)
+{
+ DxaDecContext * const c = (DxaDecContext *)avctx->priv_data;
+ uint8_t *outptr, *srcptr, *tmpptr;
+ unsigned long dsize;
+ int i, j, compr;
+ int stride;
+ int orig_buf_size = buf_size;
+ int pc = 0;
+
+ /* make the palette available on the way out */
+ if(buf[0]=='C' && buf[1]=='M' && buf[2]=='A' && buf[3]=='P'){
+ int r, g, b;
+
+ buf += 4;
+ for(i = 0; i < 256; i++){
+ r = *buf++;
+ g = *buf++;
+ b = *buf++;
+ c->pal[i] = (r << 16) | (g << 8) | b;
+ }
+ pc = 1;
+ buf_size -= 768+4;
+ }
+
+ if(avctx->get_buffer(avctx, &c->pic) < 0){
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ return -1;
+ }
+ memcpy(c->pic.data[1], c->pal, AVPALETTE_SIZE);
+ c->pic.palette_has_changed = pc;
+
+ outptr = c->pic.data[0];
+ srcptr = c->decomp_buf;
+ tmpptr = c->prev.data[0];
+ stride = c->pic.linesize[0];
+
+ if(buf[0]=='N' && buf[1]=='U' && buf[2]=='L' && buf[3]=='L')
+ compr = -1;
+ else
+ compr = buf[4];
+
+ dsize = c->dsize;
+ if((compr != 4 && compr != -1) && uncompress(c->decomp_buf, &dsize, buf + 9, buf_size - 9) != Z_OK){
+ av_log(avctx, AV_LOG_ERROR, "Uncompress failed!\n");
+ return -1;
+ }
+ switch(compr){
+ case -1:
+ c->pic.key_frame = 0;
+ c->pic.pict_type = FF_P_TYPE;
+ if(c->prev.data[0])
+ memcpy(c->pic.data[0], c->prev.data[0], c->pic.linesize[0] * avctx->height);
+ else{ // Should happen only when first frame is 'NULL'
+ memset(c->pic.data[0], 0, c->pic.linesize[0] * avctx->height);
+ c->pic.key_frame = 1;
+ c->pic.pict_type = FF_I_TYPE;
+ }
+ break;
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ c->pic.key_frame = !(compr & 1);
+ c->pic.pict_type = (compr & 1) ? FF_P_TYPE : FF_I_TYPE;
+ for(j = 0; j < avctx->height; j++){
+ if(compr & 1){
+ for(i = 0; i < avctx->width; i++)
+ outptr[i] = srcptr[i] ^ tmpptr[i];
+ tmpptr += stride;
+ }else
+ memcpy(outptr, srcptr, avctx->width);
+ outptr += stride;
+ srcptr += avctx->width;
+ }
+ break;
+ case 12: // ScummVM coding
+ case 13:
+ c->pic.key_frame = 0;
+ c->pic.pict_type = FF_P_TYPE;
+ decode_13(avctx, c, c->pic.data[0], srcptr, c->prev.data[0]);
+ break;
+ default:
+ av_log(avctx, AV_LOG_ERROR, "Unknown/unsupported compression type %d\n", buf[4]);
+ return -1;
+ }
+
+ FFSWAP(AVFrame, c->pic, c->prev);
+ if(c->pic.data[0])
+ avctx->release_buffer(avctx, &c->pic);
+
+ *data_size = sizeof(AVFrame);
+ *(AVFrame*)data = c->prev;
+
+ /* always report that the buffer was completely consumed */
+ return orig_buf_size;
+}
+
+static int decode_init(AVCodecContext *avctx)
+{
+ DxaDecContext * const c = (DxaDecContext *)avctx->priv_data;
+
+ 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");
+ return -1;
+ }
+
+ return 0;
+}
+
+static int decode_end(AVCodecContext *avctx)
+{
+ DxaDecContext * const c = (DxaDecContext *)avctx->priv_data;
+
+ av_freep(&c->decomp_buf);
+ if(c->prev.data[0])
+ avctx->release_buffer(avctx, &c->prev);
+ if(c->pic.data[0])
+ avctx->release_buffer(avctx, &c->pic);
+
+ return 0;
+}
+
+AVCodec dxa_decoder = {
+ "dxa",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_DXA,
+ sizeof(DxaDecContext),
+ decode_init,
+ NULL,
+ decode_end,
+ decode_frame
+};
+
diff --git a/contrib/ffmpeg/libavcodec/error_resilience.c b/contrib/ffmpeg/libavcodec/error_resilience.c
new file mode 100644
index 000000000..175ccf73a
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/error_resilience.c
@@ -0,0 +1,1035 @@
+/*
+ * Error resilience / concealment
+ *
+ * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file error_resilience.c
+ * Error resilience / concealment.
+ */
+
+#include <limits.h>
+
+#include "avcodec.h"
+#include "dsputil.h"
+#include "mpegvideo.h"
+#include "common.h"
+
+static void decode_mb(MpegEncContext *s){
+ 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;
+
+ MPV_decode_mb(s, s->block);
+}
+
+/**
+ * replaces the current MB with a flat dc only version.
+ */
+static void put_dc(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int mb_x, int mb_y)
+{
+ int dc, dcu, dcv, y, i;
+ for(i=0; i<4; i++){
+ dc= s->dc_val[0][mb_x*2 + (i&1) + (mb_y*2 + (i>>1))*s->b8_stride];
+ if(dc<0) dc=0;
+ else if(dc>2040) dc=2040;
+ for(y=0; y<8; y++){
+ int x;
+ for(x=0; x<8; x++){
+ dest_y[x + (i&1)*8 + (y + (i>>1)*8)*s->linesize]= dc/8;
+ }
+ }
+ }
+ dcu = s->dc_val[1][mb_x + mb_y*s->mb_stride];
+ dcv = s->dc_val[2][mb_x + mb_y*s->mb_stride];
+ if (dcu<0 ) dcu=0;
+ else if(dcu>2040) dcu=2040;
+ if (dcv<0 ) dcv=0;
+ else if(dcv>2040) dcv=2040;
+ for(y=0; y<8; y++){
+ int x;
+ for(x=0; x<8; x++){
+ dest_cb[x + y*(s->uvlinesize)]= dcu/8;
+ dest_cr[x + y*(s->uvlinesize)]= dcv/8;
+ }
+ }
+}
+
+static void filter181(int16_t *data, int width, int height, int stride){
+ int x,y;
+
+ /* horizontal filter */
+ for(y=1; y<height-1; y++){
+ int prev_dc= data[0 + y*stride];
+
+ for(x=1; x<width-1; x++){
+ int dc;
+
+ dc= - prev_dc
+ + data[x + y*stride]*8
+ - data[x + 1 + y*stride];
+ dc= (dc*10923 + 32768)>>16;
+ prev_dc= data[x + y*stride];
+ data[x + y*stride]= dc;
+ }
+ }
+
+ /* vertical filter */
+ for(x=1; x<width-1; x++){
+ int prev_dc= data[x];
+
+ for(y=1; y<height-1; y++){
+ int dc;
+
+ dc= - prev_dc
+ + data[x + y *stride]*8
+ - data[x + (y+1)*stride];
+ dc= (dc*10923 + 32768)>>16;
+ prev_dc= data[x + y*stride];
+ data[x + y*stride]= dc;
+ }
+ }
+}
+
+/**
+ * guess the dc of blocks which dont have a undamaged dc
+ * @param w width in 8 pixel blocks
+ * @param h height in 8 pixel blocks
+ */
+static void guess_dc(MpegEncContext *s, int16_t *dc, int w, int h, int stride, int is_luma){
+ int b_x, b_y;
+
+ for(b_y=0; b_y<h; b_y++){
+ for(b_x=0; b_x<w; b_x++){
+ int color[4]={1024,1024,1024,1024};
+ int distance[4]={9999,9999,9999,9999};
+ int mb_index, error, j;
+ int64_t guess, weight_sum;
+
+ mb_index= (b_x>>is_luma) + (b_y>>is_luma)*s->mb_stride;
+
+ error= s->error_status_table[mb_index];
+
+ if(IS_INTER(s->current_picture.mb_type[mb_index])) continue; //inter
+ if(!(error&DC_ERROR)) continue; //dc-ok
+
+ /* right block */
+ for(j=b_x+1; j<w; j++){
+ int mb_index_j= (j>>is_luma) + (b_y>>is_luma)*s->mb_stride;
+ int error_j= s->error_status_table[mb_index_j];
+ int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
+ if(intra_j==0 || !(error_j&DC_ERROR)){
+ color[0]= dc[j + b_y*stride];
+ distance[0]= j-b_x;
+ break;
+ }
+ }
+
+ /* left block */
+ for(j=b_x-1; j>=0; j--){
+ int mb_index_j= (j>>is_luma) + (b_y>>is_luma)*s->mb_stride;
+ int error_j= s->error_status_table[mb_index_j];
+ int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
+ if(intra_j==0 || !(error_j&DC_ERROR)){
+ color[1]= dc[j + b_y*stride];
+ distance[1]= b_x-j;
+ break;
+ }
+ }
+
+ /* bottom block */
+ for(j=b_y+1; j<h; j++){
+ int mb_index_j= (b_x>>is_luma) + (j>>is_luma)*s->mb_stride;
+ int error_j= s->error_status_table[mb_index_j];
+ int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
+ if(intra_j==0 || !(error_j&DC_ERROR)){
+ color[2]= dc[b_x + j*stride];
+ distance[2]= j-b_y;
+ break;
+ }
+ }
+
+ /* top block */
+ for(j=b_y-1; j>=0; j--){
+ int mb_index_j= (b_x>>is_luma) + (j>>is_luma)*s->mb_stride;
+ int error_j= s->error_status_table[mb_index_j];
+ int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
+ if(intra_j==0 || !(error_j&DC_ERROR)){
+ color[3]= dc[b_x + j*stride];
+ distance[3]= b_y-j;
+ break;
+ }
+ }
+
+ weight_sum=0;
+ guess=0;
+ for(j=0; j<4; j++){
+ int64_t weight= 256*256*256*16/distance[j];
+ guess+= weight*(int64_t)color[j];
+ weight_sum+= weight;
+ }
+ guess= (guess + weight_sum/2) / weight_sum;
+
+ dc[b_x + b_y*stride]= guess;
+ }
+ }
+}
+
+/**
+ * simple horizontal deblocking filter used for error resilience
+ * @param w width in 8 pixel blocks
+ * @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;
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+
+ for(b_y=0; b_y<h; b_y++){
+ for(b_x=0; b_x<w-1; b_x++){
+ int y;
+ int left_status = s->error_status_table[( b_x >>is_luma) + (b_y>>is_luma)*s->mb_stride];
+ int right_status= s->error_status_table[((b_x+1)>>is_luma) + (b_y>>is_luma)*s->mb_stride];
+ int left_intra= IS_INTRA(s->current_picture.mb_type [( b_x >>is_luma) + (b_y>>is_luma)*s->mb_stride]);
+ int right_intra= IS_INTRA(s->current_picture.mb_type [((b_x+1)>>is_luma) + (b_y>>is_luma)*s->mb_stride]);
+ int left_damage = left_status&(DC_ERROR|AC_ERROR|MV_ERROR);
+ int right_damage= right_status&(DC_ERROR|AC_ERROR|MV_ERROR);
+ int offset= b_x*8 + b_y*stride*8;
+ int16_t *left_mv= s->current_picture.motion_val[0][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))];
+
+ if(!(left_damage||right_damage)) continue; // both undamaged
+
+ if( (!left_intra) && (!right_intra)
+ && FFABS(left_mv[0]-right_mv[0]) + FFABS(left_mv[1]+right_mv[1]) < 2) continue;
+
+ for(y=0; y<8; y++){
+ int a,b,c,d;
+
+ a= dst[offset + 7 + y*stride] - dst[offset + 6 + y*stride];
+ b= dst[offset + 8 + y*stride] - dst[offset + 7 + y*stride];
+ c= dst[offset + 9 + y*stride] - dst[offset + 8 + y*stride];
+
+ d= FFABS(b) - ((FFABS(a) + FFABS(c) + 1)>>1);
+ d= FFMAX(d, 0);
+ if(b<0) d= -d;
+
+ if(d==0) continue;
+
+ if(!(left_damage && right_damage))
+ d= d*16/9;
+
+ if(left_damage){
+ dst[offset + 7 + y*stride] = cm[dst[offset + 7 + y*stride] + ((d*7)>>4)];
+ dst[offset + 6 + y*stride] = cm[dst[offset + 6 + y*stride] + ((d*5)>>4)];
+ dst[offset + 5 + y*stride] = cm[dst[offset + 5 + y*stride] + ((d*3)>>4)];
+ dst[offset + 4 + y*stride] = cm[dst[offset + 4 + y*stride] + ((d*1)>>4)];
+ }
+ if(right_damage){
+ dst[offset + 8 + y*stride] = cm[dst[offset + 8 + y*stride] - ((d*7)>>4)];
+ dst[offset + 9 + y*stride] = cm[dst[offset + 9 + y*stride] - ((d*5)>>4)];
+ dst[offset + 10+ y*stride] = cm[dst[offset +10 + y*stride] - ((d*3)>>4)];
+ dst[offset + 11+ y*stride] = cm[dst[offset +11 + y*stride] - ((d*1)>>4)];
+ }
+ }
+ }
+ }
+}
+
+/**
+ * simple vertical deblocking filter used for error resilience
+ * @param w width in 8 pixel blocks
+ * @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;
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+
+ for(b_y=0; b_y<h-1; b_y++){
+ for(b_x=0; b_x<w; b_x++){
+ int x;
+ int top_status = s->error_status_table[(b_x>>is_luma) + ( b_y >>is_luma)*s->mb_stride];
+ int bottom_status= s->error_status_table[(b_x>>is_luma) + ((b_y+1)>>is_luma)*s->mb_stride];
+ int top_intra= IS_INTRA(s->current_picture.mb_type [(b_x>>is_luma) + ( b_y >>is_luma)*s->mb_stride]);
+ int bottom_intra= IS_INTRA(s->current_picture.mb_type [(b_x>>is_luma) + ((b_y+1)>>is_luma)*s->mb_stride]);
+ int top_damage = top_status&(DC_ERROR|AC_ERROR|MV_ERROR);
+ int bottom_damage= bottom_status&(DC_ERROR|AC_ERROR|MV_ERROR);
+ int offset= b_x*8 + b_y*stride*8;
+ int16_t *top_mv= s->current_picture.motion_val[0][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))];
+
+ if(!(top_damage||bottom_damage)) continue; // both undamaged
+
+ if( (!top_intra) && (!bottom_intra)
+ && FFABS(top_mv[0]-bottom_mv[0]) + FFABS(top_mv[1]+bottom_mv[1]) < 2) continue;
+
+ for(x=0; x<8; x++){
+ int a,b,c,d;
+
+ a= dst[offset + x + 7*stride] - dst[offset + x + 6*stride];
+ b= dst[offset + x + 8*stride] - dst[offset + x + 7*stride];
+ c= dst[offset + x + 9*stride] - dst[offset + x + 8*stride];
+
+ d= FFABS(b) - ((FFABS(a) + FFABS(c)+1)>>1);
+ d= FFMAX(d, 0);
+ if(b<0) d= -d;
+
+ if(d==0) continue;
+
+ if(!(top_damage && bottom_damage))
+ d= d*16/9;
+
+ if(top_damage){
+ dst[offset + x + 7*stride] = cm[dst[offset + x + 7*stride] + ((d*7)>>4)];
+ dst[offset + x + 6*stride] = cm[dst[offset + x + 6*stride] + ((d*5)>>4)];
+ dst[offset + x + 5*stride] = cm[dst[offset + x + 5*stride] + ((d*3)>>4)];
+ dst[offset + x + 4*stride] = cm[dst[offset + x + 4*stride] + ((d*1)>>4)];
+ }
+ if(bottom_damage){
+ dst[offset + x + 8*stride] = cm[dst[offset + x + 8*stride] - ((d*7)>>4)];
+ dst[offset + x + 9*stride] = cm[dst[offset + x + 9*stride] - ((d*5)>>4)];
+ dst[offset + x + 10*stride] = cm[dst[offset + x + 10*stride] - ((d*3)>>4)];
+ dst[offset + x + 11*stride] = cm[dst[offset + x + 11*stride] - ((d*1)>>4)];
+ }
+ }
+ }
+ }
+}
+
+static void guess_mv(MpegEncContext *s){
+ uint8_t fixed[s->mb_stride * s->mb_height];
+#define MV_FROZEN 3
+#define MV_CHANGED 2
+#define MV_UNCHANGED 1
+ const int mb_stride = s->mb_stride;
+ const int mb_width = s->mb_width;
+ const int mb_height= s->mb_height;
+ int i, depth, num_avail;
+ int mb_x, mb_y;
+
+ num_avail=0;
+ for(i=0; i<s->mb_num; i++){
+ const int mb_xy= s->mb_index2xy[ i ];
+ int f=0;
+ int error= s->error_status_table[mb_xy];
+
+ if(IS_INTRA(s->current_picture.mb_type[mb_xy])) f=MV_FROZEN; //intra //FIXME check
+ if(!(error&MV_ERROR)) f=MV_FROZEN; //inter with undamaged MV
+
+ fixed[mb_xy]= f;
+ if(f==MV_FROZEN)
+ num_avail++;
+ }
+
+ if((!(s->avctx->error_concealment&FF_EC_GUESS_MVS)) || num_avail <= mb_width/2){
+ for(mb_y=0; mb_y<s->mb_height; mb_y++){
+ for(mb_x=0; mb_x<s->mb_width; mb_x++){
+ const int mb_xy= mb_x + mb_y*s->mb_stride;
+
+ if(IS_INTRA(s->current_picture.mb_type[mb_xy])) continue;
+ if(!(s->error_status_table[mb_xy]&MV_ERROR)) continue;
+
+ s->mv_dir = MV_DIR_FORWARD;
+ s->mb_intra=0;
+ s->mv_type = MV_TYPE_16X16;
+ s->mb_skipped=0;
+
+ s->dsp.clear_blocks(s->block[0]);
+
+ s->mb_x= mb_x;
+ s->mb_y= mb_y;
+ s->mv[0][0][0]= 0;
+ s->mv[0][0][1]= 0;
+ decode_mb(s);
+ }
+ }
+ return;
+ }
+
+ for(depth=0;; depth++){
+ int changed, pass, none_left;
+
+ none_left=1;
+ changed=1;
+ for(pass=0; (changed || pass<2) && pass<10; pass++){
+ int mb_x, mb_y;
+int score_sum=0;
+
+ changed=0;
+ for(mb_y=0; mb_y<s->mb_height; mb_y++){
+ for(mb_x=0; mb_x<s->mb_width; mb_x++){
+ const int mb_xy= mb_x + mb_y*s->mb_stride;
+ int mv_predictor[8][2]={{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;
+ int prev_x= s->current_picture.motion_val[0][mot_index][0];
+ int prev_y= s->current_picture.motion_val[0][mot_index][1];
+
+ if((mb_x^mb_y^pass)&1) continue;
+
+ if(fixed[mb_xy]==MV_FROZEN) continue;
+ assert(!IS_INTRA(s->current_picture.mb_type[mb_xy]));
+ assert(s->last_picture_ptr && s->last_picture_ptr->data[0]);
+
+ j=0;
+ if(mb_x>0 && fixed[mb_xy-1 ]==MV_FROZEN) j=1;
+ if(mb_x+1<mb_width && fixed[mb_xy+1 ]==MV_FROZEN) j=1;
+ if(mb_y>0 && fixed[mb_xy-mb_stride]==MV_FROZEN) j=1;
+ if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]==MV_FROZEN) j=1;
+ if(j==0) continue;
+
+ j=0;
+ if(mb_x>0 && fixed[mb_xy-1 ]==MV_CHANGED) j=1;
+ if(mb_x+1<mb_width && fixed[mb_xy+1 ]==MV_CHANGED) j=1;
+ if(mb_y>0 && fixed[mb_xy-mb_stride]==MV_CHANGED) j=1;
+ if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]==MV_CHANGED) j=1;
+ if(j==0 && pass>1) continue;
+
+ 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];
+ pred_count++;
+ }
+ if(mb_x+1<mb_width && fixed[mb_xy+1]){
+ mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index + 2][0];
+ mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + 2][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];
+ pred_count++;
+ }
+ if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]){
+ mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index + mot_stride*2][0];
+ mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + mot_stride*2][1];
+ 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;
+
+ for(j=0; j<pred_count; j++){
+ sum_x+= mv_predictor[j][0];
+ sum_y+= mv_predictor[j][1];
+ }
+
+ /* mean */
+ mv_predictor[pred_count][0] = sum_x/j;
+ mv_predictor[pred_count][1] = sum_y/j;
+
+ /* median */
+ if(pred_count>=3){
+ min_y= min_x= 99999;
+ max_y= max_x=-99999;
+ }else{
+ min_x=min_y=max_x=max_y=0;
+ }
+ for(j=0; j<pred_count; j++){
+ max_x= FFMAX(max_x, mv_predictor[j][0]);
+ max_y= FFMAX(max_y, mv_predictor[j][1]);
+ min_x= FFMIN(min_x, mv_predictor[j][0]);
+ min_y= FFMIN(min_y, mv_predictor[j][1]);
+ }
+ mv_predictor[pred_count+1][0] = sum_x - max_x - min_x;
+ mv_predictor[pred_count+1][1] = sum_y - max_y - min_y;
+
+ if(pred_count==4){
+ mv_predictor[pred_count+1][0] /= 2;
+ mv_predictor[pred_count+1][1] /= 2;
+ }
+ pred_count+=2;
+ }
+
+ /* zero MV */
+ pred_count++;
+
+ /* last MV */
+ mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index][0];
+ mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index][1];
+ pred_count++;
+
+ s->mv_dir = MV_DIR_FORWARD;
+ s->mb_intra=0;
+ s->mv_type = MV_TYPE_16X16;
+ s->mb_skipped=0;
+
+ s->dsp.clear_blocks(s->block[0]);
+
+ s->mb_x= mb_x;
+ s->mb_y= mb_y;
+
+ for(j=0; j<pred_count; j++){
+ int score=0;
+ uint8_t *src= s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
+
+ 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(mb_x>0 && fixed[mb_xy-1]){
+ int k;
+ for(k=0; k<16; k++)
+ score += FFABS(src[k*s->linesize-1 ]-src[k*s->linesize ]);
+ }
+ if(mb_x+1<mb_width && fixed[mb_xy+1]){
+ int k;
+ for(k=0; k<16; k++)
+ score += FFABS(src[k*s->linesize+15]-src[k*s->linesize+16]);
+ }
+ if(mb_y>0 && fixed[mb_xy-mb_stride]){
+ int k;
+ for(k=0; k<16; k++)
+ score += FFABS(src[k-s->linesize ]-src[k ]);
+ }
+ if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]){
+ int k;
+ for(k=0; k<16; k++)
+ score += FFABS(src[k+s->linesize*15]-src[k+s->linesize*16]);
+ }
+
+ if(score <= best_score){ // <= will favor the last MV
+ best_score= score;
+ best_pred= j;
+ }
+ }
+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];
+
+ decode_mb(s);
+
+
+ if(s->mv[0][0][0] != prev_x || s->mv[0][0][1] != prev_y){
+ fixed[mb_xy]=MV_CHANGED;
+ changed++;
+ }else
+ fixed[mb_xy]=MV_UNCHANGED;
+ }
+ }
+
+// printf(".%d/%d", changed, score_sum); fflush(stdout);
+ }
+
+ if(none_left)
+ return;
+
+ for(i=0; i<s->mb_num; i++){
+ int mb_xy= s->mb_index2xy[i];
+ if(fixed[mb_xy])
+ fixed[mb_xy]=MV_FROZEN;
+ }
+// printf(":"); fflush(stdout);
+ }
+}
+
+static int is_intra_more_likely(MpegEncContext *s){
+ int is_intra_likely, i, j, undamaged_count, skip_amount, mb_x, mb_y;
+
+ if(s->last_picture_ptr==NULL) return 1; //no previous frame available -> use spatial prediction
+
+ undamaged_count=0;
+ for(i=0; i<s->mb_num; i++){
+ const int mb_xy= s->mb_index2xy[i];
+ const int error= s->error_status_table[mb_xy];
+ if(!((error&DC_ERROR) && (error&MV_ERROR)))
+ undamaged_count++;
+ }
+
+ if(undamaged_count < 5) return 0; //allmost all MBs damaged -> use temporal prediction
+
+ skip_amount= FFMAX(undamaged_count/50, 1); //check only upto 50 MBs
+ is_intra_likely=0;
+
+ j=0;
+ for(mb_y= 0; mb_y<s->mb_height-1; mb_y++){
+ for(mb_x= 0; mb_x<s->mb_width; mb_x++){
+ int error;
+ const int mb_xy= mb_x + mb_y*s->mb_stride;
+
+ error= s->error_status_table[mb_xy];
+ if((error&DC_ERROR) && (error&MV_ERROR))
+ continue; //skip damaged
+
+ j++;
+ if((j%skip_amount) != 0) continue; //skip a few to speed things up
+
+ if(s->pict_type==I_TYPE){
+ uint8_t *mb_ptr = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
+ uint8_t *last_mb_ptr= s->last_picture.data [0] + mb_x*16 + mb_y*16*s->linesize;
+
+ is_intra_likely += s->dsp.sad[0](NULL, last_mb_ptr, mb_ptr , s->linesize, 16);
+ is_intra_likely -= s->dsp.sad[0](NULL, last_mb_ptr, last_mb_ptr+s->linesize*16, s->linesize, 16);
+ }else{
+ if(IS_INTRA(s->current_picture.mb_type[mb_xy]))
+ is_intra_likely++;
+ else
+ is_intra_likely--;
+ }
+ }
+ }
+//printf("is_intra_likely: %d type:%d\n", is_intra_likely, s->pict_type);
+ return is_intra_likely > 0;
+}
+
+void ff_er_frame_start(MpegEncContext *s){
+ if(!s->error_resilience) return;
+
+ memset(s->error_status_table, MV_ERROR|AC_ERROR|DC_ERROR|VP_START|AC_END|DC_END|MV_END, s->mb_stride*s->mb_height*sizeof(uint8_t));
+ s->error_count= 3*s->mb_num;
+}
+
+/**
+ * adds a slice.
+ * @param endx x component of the last macroblock, can be -1 for the last of the previous line
+ * @param status the status at the end (MV_END, AC_ERROR, ...), it is assumed that no earlier end or
+ * error of the same type occured
+ */
+void ff_er_add_slice(MpegEncContext *s, int startx, int starty, int endx, int endy, int status){
+ const int start_i= av_clip(startx + starty * s->mb_width , 0, s->mb_num-1);
+ const int end_i = av_clip(endx + endy * s->mb_width , 0, s->mb_num);
+ const int start_xy= s->mb_index2xy[start_i];
+ const int end_xy = s->mb_index2xy[end_i];
+ int mask= -1;
+
+ if(start_i > end_i || start_xy > end_xy){
+ av_log(s->avctx, AV_LOG_ERROR, "internal error, slice end before start\n");
+ return;
+ }
+
+ if(!s->error_resilience) return;
+
+ mask &= ~VP_START;
+ if(status & (AC_ERROR|AC_END)){
+ mask &= ~(AC_ERROR|AC_END);
+ s->error_count -= end_i - start_i + 1;
+ }
+ if(status & (DC_ERROR|DC_END)){
+ mask &= ~(DC_ERROR|DC_END);
+ s->error_count -= end_i - start_i + 1;
+ }
+ if(status & (MV_ERROR|MV_END)){
+ mask &= ~(MV_ERROR|MV_END);
+ s->error_count -= end_i - start_i + 1;
+ }
+
+ if(status & (AC_ERROR|DC_ERROR|MV_ERROR)) s->error_count= INT_MAX;
+
+ if(mask == ~0x7F){
+ memset(&s->error_status_table[start_xy], 0, (end_xy - start_xy) * sizeof(uint8_t));
+ }else{
+ int i;
+ for(i=start_xy; i<end_xy; i++){
+ s->error_status_table[ i ] &= mask;
+ }
+ }
+
+ if(end_i == s->mb_num)
+ s->error_count= INT_MAX;
+ else{
+ s->error_status_table[end_xy] &= mask;
+ s->error_status_table[end_xy] |= status;
+ }
+
+ s->error_status_table[start_xy] |= VP_START;
+
+ if(start_xy > 0 && s->avctx->thread_count <= 1 && s->avctx->skip_top*s->mb_width < start_i){
+ int prev_status= s->error_status_table[ s->mb_index2xy[start_i - 1] ];
+
+ prev_status &= ~ VP_START;
+ if(prev_status != (MV_END|DC_END|AC_END)) s->error_count= INT_MAX;
+ }
+}
+
+void ff_er_frame_end(MpegEncContext *s){
+ int i, mb_x, mb_y, error, error_type, dc_error, mv_error, ac_error;
+ int distance;
+ int threshold_part[4]= {100,100,100};
+ int threshold= 50;
+ int is_intra_likely;
+ int size = s->b8_stride * 2 * s->mb_height;
+ Picture *pic= s->current_picture_ptr;
+
+ if(!s->error_resilience || s->error_count==0 ||
+ 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->motion_val_base[i]= av_mallocz((size+4) * 2 * sizeof(uint16_t));
+ pic->motion_val[i]= pic->motion_val_base[i]+4;
+ }
+ pic->motion_subsample_log2= 3;
+ 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_y<s->mb_height; mb_y++){
+ for(mb_x=0; mb_x<s->mb_width; mb_x++){
+ int status= s->error_status_table[mb_x + mb_y*s->mb_stride];
+
+ av_log(s->avctx, AV_LOG_DEBUG, "%2X ", status);
+ }
+ av_log(s->avctx, AV_LOG_DEBUG, "\n");
+ }
+ }
+
+#if 1
+ /* handle overlapping slices */
+ for(error_type=1; error_type<=3; error_type++){
+ int end_ok=0;
+
+ for(i=s->mb_num-1; i>=0; i--){
+ const int mb_xy= s->mb_index2xy[i];
+ int error= s->error_status_table[mb_xy];
+
+ if(error&(1<<error_type))
+ end_ok=1;
+ if(error&(8<<error_type))
+ end_ok=1;
+
+ if(!end_ok)
+ s->error_status_table[mb_xy]|= 1<<error_type;
+
+ if(error&VP_START)
+ end_ok=0;
+ }
+ }
+#endif
+#if 1
+ /* handle slices with partitions of different length */
+ if(s->partitioned_frame){
+ int end_ok=0;
+
+ for(i=s->mb_num-1; i>=0; i--){
+ const int mb_xy= s->mb_index2xy[i];
+ int error= s->error_status_table[mb_xy];
+
+ if(error&AC_END)
+ end_ok=0;
+ if((error&MV_END) || (error&DC_END) || (error&AC_ERROR))
+ end_ok=1;
+
+ if(!end_ok)
+ s->error_status_table[mb_xy]|= AC_ERROR;
+
+ if(error&VP_START)
+ end_ok=0;
+ }
+ }
+#endif
+ /* handle missing slices */
+ if(s->error_resilience>=4){
+ int end_ok=1;
+
+ for(i=s->mb_num-2; i>=s->mb_width+100; i--){ //FIXME +100 hack
+ const int mb_xy= s->mb_index2xy[i];
+ int error1= s->error_status_table[mb_xy ];
+ int error2= s->error_status_table[s->mb_index2xy[i+1]];
+
+ if(error1&VP_START)
+ end_ok=1;
+
+ if( error2==(VP_START|DC_ERROR|AC_ERROR|MV_ERROR|AC_END|DC_END|MV_END)
+ && error1!=(VP_START|DC_ERROR|AC_ERROR|MV_ERROR|AC_END|DC_END|MV_END)
+ && ((error1&AC_END) || (error1&DC_END) || (error1&MV_END))){ //end & uninited
+ end_ok=0;
+ }
+
+ if(!end_ok)
+ s->error_status_table[mb_xy]|= DC_ERROR|AC_ERROR|MV_ERROR;
+ }
+ }
+
+#if 1
+ /* backward mark errors */
+ distance=9999999;
+ for(error_type=1; error_type<=3; error_type++){
+ for(i=s->mb_num-1; i>=0; i--){
+ const int mb_xy= s->mb_index2xy[i];
+ int error= s->error_status_table[mb_xy];
+
+ if(!s->mbskip_table[mb_xy]) //FIXME partition specific
+ distance++;
+ if(error&(1<<error_type))
+ distance= 0;
+
+ if(s->partitioned_frame){
+ if(distance < threshold_part[error_type-1])
+ s->error_status_table[mb_xy]|= 1<<error_type;
+ }else{
+ if(distance < threshold)
+ s->error_status_table[mb_xy]|= 1<<error_type;
+ }
+
+ if(error&VP_START)
+ distance= 9999999;
+ }
+ }
+#endif
+
+ /* forward mark errors */
+ error=0;
+ for(i=0; i<s->mb_num; i++){
+ const int mb_xy= s->mb_index2xy[i];
+ int old_error= s->error_status_table[mb_xy];
+
+ if(old_error&VP_START)
+ error= old_error& (DC_ERROR|AC_ERROR|MV_ERROR);
+ else{
+ error|= old_error& (DC_ERROR|AC_ERROR|MV_ERROR);
+ s->error_status_table[mb_xy]|= error;
+ }
+ }
+#if 1
+ /* handle not partitioned case */
+ if(!s->partitioned_frame){
+ for(i=0; i<s->mb_num; i++){
+ const int mb_xy= s->mb_index2xy[i];
+ error= s->error_status_table[mb_xy];
+ if(error&(AC_ERROR|DC_ERROR|MV_ERROR))
+ error|= AC_ERROR|DC_ERROR|MV_ERROR;
+ s->error_status_table[mb_xy]= error;
+ }
+ }
+#endif
+
+ dc_error= ac_error= mv_error=0;
+ for(i=0; i<s->mb_num; i++){
+ const int mb_xy= s->mb_index2xy[i];
+ error= s->error_status_table[mb_xy];
+ if(error&DC_ERROR) dc_error ++;
+ if(error&AC_ERROR) ac_error ++;
+ if(error&MV_ERROR) mv_error ++;
+ }
+ av_log(s->avctx, AV_LOG_INFO, "concealing %d DC, %d AC, %d MV errors\n", dc_error, ac_error, mv_error);
+
+ is_intra_likely= is_intra_more_likely(s);
+
+ /* set unknown mb-type to most likely */
+ for(i=0; i<s->mb_num; i++){
+ const int mb_xy= s->mb_index2xy[i];
+ error= s->error_status_table[mb_xy];
+ if(!((error&DC_ERROR) && (error&MV_ERROR)))
+ continue;
+
+ if(is_intra_likely)
+ s->current_picture.mb_type[mb_xy]= MB_TYPE_INTRA4x4;
+ else
+ s->current_picture.mb_type[mb_xy]= MB_TYPE_16x16 | MB_TYPE_L0;
+ }
+
+ /* handle inter blocks with damaged AC */
+ for(mb_y=0; mb_y<s->mb_height; mb_y++){
+ for(mb_x=0; mb_x<s->mb_width; mb_x++){
+ const int mb_xy= mb_x + mb_y * s->mb_stride;
+ const int mb_type= s->current_picture.mb_type[mb_xy];
+ error= s->error_status_table[mb_xy];
+
+ if(IS_INTRA(mb_type)) continue; //intra
+ if(error&MV_ERROR) continue; //inter with damaged MV
+ if(!(error&AC_ERROR)) continue; //undamaged inter
+
+ s->mv_dir = MV_DIR_FORWARD;
+ s->mb_intra=0;
+ s->mb_skipped=0;
+ if(IS_8X8(mb_type)){
+ int mb_index= mb_x*2 + mb_y*2*s->b8_stride;
+ int j;
+ s->mv_type = MV_TYPE_8X8;
+ for(j=0; j<4; j++){
+ s->mv[0][j][0] = s->current_picture.motion_val[0][ mb_index + (j&1) + (j>>1)*s->b8_stride ][0];
+ s->mv[0][j][1] = s->current_picture.motion_val[0][ mb_index + (j&1) + (j>>1)*s->b8_stride ][1];
+ }
+ }else{
+ s->mv_type = MV_TYPE_16X16;
+ s->mv[0][0][0] = s->current_picture.motion_val[0][ mb_x*2 + mb_y*2*s->b8_stride ][0];
+ s->mv[0][0][1] = s->current_picture.motion_val[0][ mb_x*2 + mb_y*2*s->b8_stride ][1];
+ }
+
+ s->dsp.clear_blocks(s->block[0]);
+
+ s->mb_x= mb_x;
+ s->mb_y= mb_y;
+ decode_mb(s);
+ }
+ }
+
+ /* guess MVs */
+ if(s->pict_type==B_TYPE){
+ for(mb_y=0; mb_y<s->mb_height; mb_y++){
+ for(mb_x=0; mb_x<s->mb_width; mb_x++){
+ int xy= mb_x*2 + mb_y*2*s->b8_stride;
+ const int mb_xy= mb_x + mb_y * s->mb_stride;
+ const int mb_type= s->current_picture.mb_type[mb_xy];
+ error= s->error_status_table[mb_xy];
+
+ if(IS_INTRA(mb_type)) continue;
+ if(!(error&MV_ERROR)) continue; //inter with undamaged MV
+ if(!(error&AC_ERROR)) continue; //undamaged inter
+
+ s->mv_dir = MV_DIR_FORWARD|MV_DIR_BACKWARD;
+ s->mb_intra=0;
+ s->mv_type = MV_TYPE_16X16;
+ s->mb_skipped=0;
+
+ if(s->pp_time){
+ int time_pp= s->pp_time;
+ int time_pb= s->pb_time;
+
+ s->mv[0][0][0] = s->next_picture.motion_val[0][xy][0]*time_pb/time_pp;
+ s->mv[0][0][1] = s->next_picture.motion_val[0][xy][1]*time_pb/time_pp;
+ s->mv[1][0][0] = s->next_picture.motion_val[0][xy][0]*(time_pb - time_pp)/time_pp;
+ s->mv[1][0][1] = s->next_picture.motion_val[0][xy][1]*(time_pb - time_pp)/time_pp;
+ }else{
+ 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->dsp.clear_blocks(s->block[0]);
+ s->mb_x= mb_x;
+ s->mb_y= mb_y;
+ decode_mb(s);
+ }
+ }
+ }else
+ guess_mv(s);
+
+#ifdef HAVE_XVMC
+ /* the filters below are not XvMC compatible, skip them */
+ if(s->avctx->xvmc_acceleration) goto ec_clean;
+#endif
+ /* fill DC for inter blocks */
+ for(mb_y=0; mb_y<s->mb_height; mb_y++){
+ for(mb_x=0; mb_x<s->mb_width; mb_x++){
+ int dc, dcu, dcv, y, n;
+ int16_t *dc_ptr;
+ uint8_t *dest_y, *dest_cb, *dest_cr;
+ const int mb_xy= mb_x + mb_y * s->mb_stride;
+ const int mb_type= s->current_picture.mb_type[mb_xy];
+
+ error= s->error_status_table[mb_xy];
+
+ if(IS_INTRA(mb_type) && s->partitioned_frame) continue;
+// if(error&MV_ERROR) continue; //inter data damaged FIXME is this good?
+
+ dest_y = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
+ dest_cb= s->current_picture.data[1] + mb_x*8 + mb_y*8 *s->uvlinesize;
+ dest_cr= s->current_picture.data[2] + mb_x*8 + mb_y*8 *s->uvlinesize;
+
+ dc_ptr= &s->dc_val[0][mb_x*2 + mb_y*2*s->b8_stride];
+ for(n=0; n<4; n++){
+ dc=0;
+ for(y=0; y<8; y++){
+ int x;
+ for(x=0; x<8; x++){
+ dc+= dest_y[x + (n&1)*8 + (y + (n>>1)*8)*s->linesize];
+ }
+ }
+ dc_ptr[(n&1) + (n>>1)*s->b8_stride]= (dc+4)>>3;
+ }
+
+ dcu=dcv=0;
+ for(y=0; y<8; y++){
+ int x;
+ for(x=0; x<8; x++){
+ dcu+=dest_cb[x + y*(s->uvlinesize)];
+ dcv+=dest_cr[x + y*(s->uvlinesize)];
+ }
+ }
+ s->dc_val[1][mb_x + mb_y*s->mb_stride]= (dcu+4)>>3;
+ s->dc_val[2][mb_x + mb_y*s->mb_stride]= (dcv+4)>>3;
+ }
+ }
+#if 1
+ /* guess DC for damaged blocks */
+ guess_dc(s, s->dc_val[0], s->mb_width*2, s->mb_height*2, s->b8_stride, 1);
+ guess_dc(s, s->dc_val[1], s->mb_width , s->mb_height , s->mb_stride, 0);
+ guess_dc(s, s->dc_val[2], s->mb_width , s->mb_height , s->mb_stride, 0);
+#endif
+ /* filter luma DC */
+ filter181(s->dc_val[0], s->mb_width*2, s->mb_height*2, s->b8_stride);
+
+#if 1
+ /* render DC only intra */
+ for(mb_y=0; mb_y<s->mb_height; mb_y++){
+ for(mb_x=0; mb_x<s->mb_width; mb_x++){
+ uint8_t *dest_y, *dest_cb, *dest_cr;
+ const int mb_xy= mb_x + mb_y * s->mb_stride;
+ const int mb_type= s->current_picture.mb_type[mb_xy];
+
+ error= s->error_status_table[mb_xy];
+
+ if(IS_INTER(mb_type)) continue;
+ if(!(error&AC_ERROR)) continue; //undamaged
+
+ dest_y = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
+ dest_cb= s->current_picture.data[1] + mb_x*8 + mb_y*8 *s->uvlinesize;
+ dest_cr= s->current_picture.data[2] + mb_x*8 + mb_y*8 *s->uvlinesize;
+
+ put_dc(s, dest_y, dest_cb, dest_cr, mb_x, mb_y);
+ }
+ }
+#endif
+
+ if(s->avctx->error_concealment&FF_EC_DEBLOCK){
+ /* filter horizontal block boundaries */
+ h_block_filter(s, s->current_picture.data[0], s->mb_width*2, s->mb_height*2, s->linesize , 1);
+ h_block_filter(s, s->current_picture.data[1], s->mb_width , s->mb_height , s->uvlinesize, 0);
+ h_block_filter(s, s->current_picture.data[2], s->mb_width , s->mb_height , s->uvlinesize, 0);
+
+ /* filter vertical block boundaries */
+ v_block_filter(s, s->current_picture.data[0], s->mb_width*2, s->mb_height*2, s->linesize , 1);
+ v_block_filter(s, s->current_picture.data[1], s->mb_width , s->mb_height , s->uvlinesize, 0);
+ v_block_filter(s, s->current_picture.data[2], s->mb_width , s->mb_height , s->uvlinesize, 0);
+ }
+
+#ifdef HAVE_XVMC
+ec_clean:
+#endif
+ /* clean a few tables */
+ for(i=0; i<s->mb_num; i++){
+ const int mb_xy= s->mb_index2xy[i];
+ int error= s->error_status_table[mb_xy];
+
+ if(s->pict_type!=B_TYPE && (error&(DC_ERROR|MV_ERROR|AC_ERROR))){
+ s->mbskip_table[mb_xy]=0;
+ }
+ s->mbintra_table[mb_xy]=1;
+ }
+}
diff --git a/contrib/ffmpeg/libavcodec/eval.c b/contrib/ffmpeg/libavcodec/eval.c
new file mode 100644
index 000000000..877de3552
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/eval.c
@@ -0,0 +1,466 @@
+/*
+ * simple arithmetic expression evaluator
+ *
+ * Copyright (c) 2002-2006 Michael Niedermayer <michaelni@gmx.at>
+ * Copyright (c) 2006 Oded Shimon <ods15@ods15.dyndns.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * @file eval.c
+ * simple arithmetic expression evaluator.
+ *
+ * see http://joe.hotchkiss.com/programming/eval/eval.html
+ */
+
+#include "avcodec.h"
+#include "mpegvideo.h"
+#include "eval.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+#ifndef NAN
+ #define NAN 0.0/0.0
+#endif
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
+typedef struct Parser{
+ int stack_index;
+ char *s;
+ double *const_value;
+ const char **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
+ char **func2_name; // NULL terminated
+ void *opaque;
+ char **error;
+#define VARS 10
+ double var[VARS];
+} Parser;
+
+static int8_t si_prefixes['z' - 'E' + 1]={
+ ['y'-'E']= -24,
+ ['z'-'E']= -21,
+ ['a'-'E']= -18,
+ ['f'-'E']= -15,
+ ['p'-'E']= -12,
+ ['n'-'E']= - 9,
+ ['u'-'E']= - 6,
+ ['m'-'E']= - 3,
+ ['c'-'E']= - 2,
+ ['d'-'E']= - 1,
+ ['h'-'E']= 2,
+ ['k'-'E']= 3,
+ ['K'-'E']= 3,
+ ['M'-'E']= 6,
+ ['G'-'E']= 9,
+ ['T'-'E']= 12,
+ ['P'-'E']= 15,
+ ['E'-'E']= 18,
+ ['Z'-'E']= 21,
+ ['Y'-'E']= 24,
+};
+
+/** strtod() function extended with 'k', 'M', 'G', 'ki', 'Mi', 'Gi' and 'B'
+ * postfixes. This allows using f.e. kB, MiB, G and B as a postfix. This
+ * function assumes that the unit of numbers is bits not bytes.
+ */
+static double av_strtod(const char *name, char **tail) {
+ double d;
+ char *next;
+ d = strtod(name, &next);
+ /* if parsing succeeded, check for and interpret postfixes */
+ if (next!=name) {
+
+ if(*next >= 'E' && *next <= 'z'){
+ int e= si_prefixes[*next - 'E'];
+ if(e){
+ if(next[1] == 'i'){
+ d*= pow( 2, e/0.3);
+ next+=2;
+ }else{
+ d*= pow(10, e);
+ next++;
+ }
+ }
+ }
+
+ if(*next=='B') {
+ d*=8;
+ next++;
+ }
+ }
+ /* if requested, fill in tail with the position after the last parsed
+ character */
+ if (tail)
+ *tail = next;
+ return d;
+}
+
+static int strmatch(const char *s, const char *prefix){
+ int i;
+ for(i=0; prefix[i]; i++){
+ if(prefix[i] != s[i]) return 0;
+ }
+ return 1;
+}
+
+struct ff_expr_s {
+ enum {
+ e_value, e_const, e_func0, e_func1, e_func2,
+ e_squish, e_gauss, e_ld,
+ e_mod, e_max, e_min, e_eq, e_gt, e_gte,
+ e_pow, e_mul, e_div, e_add,
+ e_last, e_st, e_while,
+ } type;
+ double value; // is sign in other types
+ union {
+ int const_index;
+ double (*func0)(double);
+ double (*func1)(void *, double);
+ double (*func2)(void *, double, double);
+ } a;
+ AVEvalExpr * param[2];
+};
+
+static double eval_expr(Parser * p, AVEvalExpr * e) {
+ switch (e->type) {
+ case e_value: return e->value;
+ case e_const: return e->value * p->const_value[e->a.const_index];
+ case e_func0: return e->value * e->a.func0(eval_expr(p, e->param[0]));
+ case e_func1: return e->value * e->a.func1(p->opaque, eval_expr(p, e->param[0]));
+ case e_func2: return e->value * e->a.func2(p->opaque, eval_expr(p, e->param[0]), eval_expr(p, e->param[1]));
+ case e_squish: return 1/(1+exp(4*eval_expr(p, e->param[0])));
+ case e_gauss: { double d = eval_expr(p, e->param[0]); return exp(-d*d/2)/sqrt(2*M_PI); }
+ case e_ld: return e->value * p->var[av_clip(eval_expr(p, e->param[0]), 0, VARS-1)];
+ case e_while: {
+ double d = NAN;
+ while(eval_expr(p, e->param[0]))
+ d=eval_expr(p, e->param[1]);
+ return d;
+ }
+ default: {
+ double d = eval_expr(p, e->param[0]);
+ double d2 = eval_expr(p, e->param[1]);
+ switch (e->type) {
+ case e_mod: return e->value * (d - floor(d/d2)*d2);
+ case e_max: return e->value * (d > d2 ? d : d2);
+ case e_min: return e->value * (d < d2 ? d : d2);
+ case e_eq: return e->value * (d == d2 ? 1.0 : 0.0);
+ case e_gt: return e->value * (d > d2 ? 1.0 : 0.0);
+ case e_gte: return e->value * (d >= d2 ? 1.0 : 0.0);
+ case e_pow: return e->value * pow(d, d2);
+ case e_mul: return e->value * (d * d2);
+ case e_div: return e->value * (d / d2);
+ case e_add: return e->value * (d + d2);
+ case e_last:return e->value * d2;
+ case e_st : return e->value * (p->var[av_clip(d, 0, VARS-1)]= d2);
+ }
+ }
+ }
+ return NAN;
+}
+
+static AVEvalExpr * parse_expr(Parser *p);
+
+void ff_eval_free(AVEvalExpr * e) {
+ if (!e) return;
+ ff_eval_free(e->param[0]);
+ ff_eval_free(e->param[1]);
+ av_freep(&e);
+}
+
+static AVEvalExpr * parse_primary(Parser *p) {
+ AVEvalExpr * d = av_mallocz(sizeof(AVEvalExpr));
+ char *next= p->s;
+ int i;
+
+ /* number */
+ d->value = av_strtod(p->s, &next);
+ if(next != p->s){
+ d->type = e_value;
+ p->s= next;
+ return d;
+ }
+ d->value = 1;
+
+ /* named constants */
+ for(i=0; p->const_name && p->const_name[i]; i++){
+ if(strmatch(p->s, p->const_name[i])){
+ p->s+= strlen(p->const_name[i]);
+ d->type = e_const;
+ d->a.const_index = i;
+ return d;
+ }
+ }
+
+ p->s= strchr(p->s, '(');
+ if(p->s==NULL){
+ *p->error = "missing (";
+ p->s= next;
+ ff_eval_free(d);
+ return NULL;
+ }
+ p->s++; // "("
+ if (*next == '(') { // special case do-nothing
+ av_freep(&d);
+ d = parse_expr(p);
+ if(p->s[0] != ')'){
+ *p->error = "missing )";
+ ff_eval_free(d);
+ return NULL;
+ }
+ p->s++; // ")"
+ return d;
+ }
+ d->param[0] = parse_expr(p);
+ if(p->s[0]== ','){
+ p->s++; // ","
+ d->param[1] = parse_expr(p);
+ }
+ if(p->s[0] != ')'){
+ *p->error = "missing )";
+ ff_eval_free(d);
+ return NULL;
+ }
+ p->s++; // ")"
+
+ d->type = e_func0;
+ if( strmatch(next, "sinh" ) ) d->a.func0 = sinh;
+ else if( strmatch(next, "cosh" ) ) d->a.func0 = cosh;
+ else if( strmatch(next, "tanh" ) ) d->a.func0 = tanh;
+ else if( strmatch(next, "sin" ) ) d->a.func0 = sin;
+ else if( strmatch(next, "cos" ) ) d->a.func0 = cos;
+ else if( strmatch(next, "tan" ) ) d->a.func0 = tan;
+ else if( strmatch(next, "atan" ) ) d->a.func0 = atan;
+ else if( strmatch(next, "asin" ) ) d->a.func0 = asin;
+ else if( strmatch(next, "acos" ) ) d->a.func0 = acos;
+ else if( strmatch(next, "exp" ) ) d->a.func0 = exp;
+ else if( strmatch(next, "log" ) ) d->a.func0 = log;
+ else if( strmatch(next, "abs" ) ) d->a.func0 = fabs;
+ else if( strmatch(next, "squish") ) d->type = e_squish;
+ else if( strmatch(next, "gauss" ) ) d->type = e_gauss;
+ else if( strmatch(next, "mod" ) ) d->type = e_mod;
+ else if( strmatch(next, "max" ) ) d->type = e_max;
+ else if( strmatch(next, "min" ) ) d->type = e_min;
+ 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, "ld" ) ) d->type = e_ld;
+ else if( strmatch(next, "st" ) ) d->type = e_st;
+ else if( strmatch(next, "while" ) ) d->type = e_while;
+ else {
+ for(i=0; p->func1_name && p->func1_name[i]; i++){
+ if(strmatch(next, p->func1_name[i])){
+ d->a.func1 = p->func1[i];
+ d->type = e_func1;
+ return d;
+ }
+ }
+
+ for(i=0; p->func2_name && p->func2_name[i]; i++){
+ if(strmatch(next, p->func2_name[i])){
+ d->a.func2 = p->func2[i];
+ d->type = e_func2;
+ return d;
+ }
+ }
+
+ *p->error = "unknown function";
+ ff_eval_free(d);
+ return NULL;
+ }
+
+ return d;
+}
+
+static AVEvalExpr * new_eval_expr(int type, int value, AVEvalExpr *p0, AVEvalExpr *p1){
+ AVEvalExpr * e = av_mallocz(sizeof(AVEvalExpr));
+ e->type =type ;
+ e->value =value ;
+ e->param[0] =p0 ;
+ e->param[1] =p1 ;
+ return e;
+}
+
+static AVEvalExpr * 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){
+ int sign, sign2;
+ AVEvalExpr * 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->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);
+ 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));
+ }
+ return e;
+}
+
+static AVEvalExpr * parse_subexpr(Parser *p) {
+ AVEvalExpr * e = parse_term(p);
+ while(*p->s == '+' || *p->s == '-') {
+ e= new_eval_expr(e_add, 1, e, parse_term(p));
+ };
+
+ return e;
+}
+
+static AVEvalExpr * parse_expr(Parser *p) {
+ AVEvalExpr * e;
+
+ if(p->stack_index <= 0) //protect against stack overflows
+ return NULL;
+ p->stack_index--;
+
+ e = parse_subexpr(p);
+
+ while(*p->s == ';') {
+ p->s++;
+ e= new_eval_expr(e_last, 1, e, parse_subexpr(p));
+ };
+
+ p->stack_index++;
+
+ return e;
+}
+
+static int verify_expr(AVEvalExpr * e) {
+ if (!e) return 0;
+ switch (e->type) {
+ case e_value:
+ case e_const: return 1;
+ case e_func0:
+ case e_func1:
+ case e_squish:
+ case e_ld:
+ case e_gauss: return verify_expr(e->param[0]);
+ default: return verify_expr(e->param[0]) && verify_expr(e->param[1]);
+ }
+}
+
+AVEvalExpr * ff_parse(char *s, const char **const_name,
+ double (**func1)(void *, double), const char **func1_name,
+ double (**func2)(void *, double, double), char **func2_name,
+ char **error){
+ Parser p;
+ AVEvalExpr * e;
+ char w[strlen(s) + 1], * wp = w;
+
+ while (*s)
+ if (!isspace(*s++)) *wp++ = s[-1];
+ *wp++ = 0;
+
+ p.stack_index=100;
+ p.s= w;
+ p.const_name = const_name;
+ p.func1 = func1;
+ p.func1_name = func1_name;
+ p.func2 = func2;
+ p.func2_name = func2_name;
+ p.error= error;
+
+ e = parse_expr(&p);
+ if (!verify_expr(e)) {
+ ff_eval_free(e);
+ return NULL;
+ }
+ return e;
+}
+
+double ff_parse_eval(AVEvalExpr * e, double *const_value, void *opaque) {
+ Parser p;
+
+ p.const_value= const_value;
+ p.opaque = opaque;
+ return eval_expr(&p, e);
+}
+
+double ff_eval2(char *s, double *const_value, const char **const_name,
+ double (**func1)(void *, double), const char **func1_name,
+ double (**func2)(void *, double, double), char **func2_name,
+ void *opaque, char **error){
+ AVEvalExpr * e = ff_parse(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);
+ return d;
+}
+
+#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
+attribute_deprecated double ff_eval(char *s, double *const_value, const char **const_name,
+ double (**func1)(void *, double), const char **func1_name,
+ double (**func2)(void *, double, double), char **func2_name,
+ void *opaque){
+ char *error=NULL;
+ double ret;
+ ret = ff_eval2(s, const_value, const_name, func1, func1_name, func2, func2_name, opaque, &error);
+ if (error)
+ av_log(NULL, AV_LOG_ERROR, "Error evaluating \"%s\": %s\n", s, error);
+ return ret;
+}
+#endif
+
+#ifdef TEST
+#undef printf
+static double const_values[]={
+ M_PI,
+ M_E,
+ 0
+};
+static const char *const_names[]={
+ "PI",
+ "E",
+ 0
+};
+main(){
+ int i;
+ printf("%f == 12.7\n", ff_eval("1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", const_values, const_names, NULL, NULL, NULL, NULL, NULL));
+ printf("%f == 0.931322575\n", ff_eval("80G/80Gi", const_values, const_names, NULL, NULL, NULL, NULL, NULL));
+
+ for(i=0; i<1050; i++){
+ START_TIMER
+ ff_eval("1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", const_values, const_names, NULL, NULL, NULL, NULL, NULL);
+ STOP_TIMER("ff_eval")
+ }
+}
+#endif
diff --git a/src/libffmpeg/libavcodec/eval.h b/contrib/ffmpeg/libavcodec/eval.h
index b52199cf4..b52199cf4 100644
--- a/src/libffmpeg/libavcodec/eval.h
+++ b/contrib/ffmpeg/libavcodec/eval.h
diff --git a/contrib/ffmpeg/libavcodec/faac.c b/contrib/ffmpeg/libavcodec/faac.c
new file mode 100644
index 000000000..9ff9f5ed0
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/faac.c
@@ -0,0 +1,136 @@
+/*
+ * Interface to libfaac for aac encoding
+ * Copyright (c) 2002 Gildas Bazin <gbazin@netcourrier.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file faacaudio.c
+ * Interface to libfaac for aac encoding.
+ */
+
+#include "avcodec.h"
+#include <faac.h>
+
+typedef struct FaacAudioContext {
+ faacEncHandle faac_handle;
+} FaacAudioContext;
+
+static int Faac_encode_init(AVCodecContext *avctx)
+{
+ FaacAudioContext *s = avctx->priv_data;
+ faacEncConfigurationPtr faac_cfg;
+ unsigned long samples_input, max_bytes_output;
+
+ /* number of channels */
+ if (avctx->channels < 1 || avctx->channels > 6)
+ return -1;
+
+ s->faac_handle = faacEncOpen(avctx->sample_rate,
+ avctx->channels,
+ &samples_input, &max_bytes_output);
+
+ /* check faac version */
+ faac_cfg = faacEncGetCurrentConfiguration(s->faac_handle);
+ if (faac_cfg->version != FAAC_CFG_VERSION) {
+ av_log(avctx, AV_LOG_ERROR, "wrong libfaac version (compiled for: %d, using %d)\n", FAAC_CFG_VERSION, faac_cfg->version);
+ faacEncClose(s->faac_handle);
+ return -1;
+ }
+
+ /* put the options in the configuration struct */
+ faac_cfg->aacObjectType = LOW;
+ faac_cfg->mpegVersion = MPEG4;
+ faac_cfg->useTns = 0;
+ faac_cfg->allowMidside = 1;
+ faac_cfg->bitRate = avctx->bit_rate / avctx->channels;
+ faac_cfg->bandWidth = avctx->cutoff;
+ if(avctx->flags & CODEC_FLAG_QSCALE) {
+ faac_cfg->bitRate = 0;
+ faac_cfg->quantqual = avctx->global_quality / FF_QP2LAMBDA;
+ }
+ faac_cfg->outputFormat = 1;
+ faac_cfg->inputFormat = FAAC_INPUT_16BIT;
+
+ avctx->frame_size = samples_input / avctx->channels;
+
+ avctx->coded_frame= avcodec_alloc_frame();
+ avctx->coded_frame->key_frame= 1;
+
+ /* Set decoder specific info */
+ avctx->extradata_size = 0;
+ if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) {
+
+ unsigned char *buffer = NULL;
+ unsigned long decoder_specific_info_size;
+
+ if (!faacEncGetDecoderSpecificInfo(s->faac_handle, &buffer,
+ &decoder_specific_info_size)) {
+ avctx->extradata = av_malloc(decoder_specific_info_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ avctx->extradata_size = decoder_specific_info_size;
+ memcpy(avctx->extradata, buffer, avctx->extradata_size);
+ faac_cfg->outputFormat = 0;
+ }
+#undef free
+ free(buffer);
+#define free please_use_av_free
+ }
+
+ if (!faacEncSetConfiguration(s->faac_handle, faac_cfg)) {
+ av_log(avctx, AV_LOG_ERROR, "libfaac doesn't support this output format!\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+static int Faac_encode_frame(AVCodecContext *avctx,
+ unsigned char *frame, int buf_size, void *data)
+{
+ FaacAudioContext *s = avctx->priv_data;
+ int bytes_written;
+
+ bytes_written = faacEncEncode(s->faac_handle,
+ data,
+ avctx->frame_size * avctx->channels,
+ frame,
+ buf_size);
+
+ return bytes_written;
+}
+
+static int Faac_encode_close(AVCodecContext *avctx)
+{
+ FaacAudioContext *s = avctx->priv_data;
+
+ av_freep(&avctx->coded_frame);
+ av_freep(&avctx->extradata);
+
+ faacEncClose(s->faac_handle);
+ return 0;
+}
+
+AVCodec faac_encoder = {
+ "aac",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_AAC,
+ sizeof(FaacAudioContext),
+ Faac_encode_init,
+ Faac_encode_frame,
+ Faac_encode_close
+};
diff --git a/contrib/ffmpeg/libavcodec/faad.c b/contrib/ffmpeg/libavcodec/faad.c
new file mode 100644
index 000000000..01cbd40e7
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/faad.c
@@ -0,0 +1,333 @@
+/*
+ * Faad decoder
+ * Copyright (c) 2003 Zdenek Kabelac.
+ * Copyright (c) 2004 Thomas Raivio.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 faad.c
+ * AAC decoder.
+ *
+ * still a bit unfinished - but it plays something
+ */
+
+#include "avcodec.h"
+#include "faad.h"
+
+#ifndef FAADAPI
+#define FAADAPI
+#endif
+
+/*
+ * when CONFIG_LIBFAADBIN is defined the libfaad will be opened at runtime
+ */
+//#undef CONFIG_LIBFAADBIN
+//#define CONFIG_LIBFAADBIN
+
+#ifdef CONFIG_LIBFAADBIN
+#include <dlfcn.h>
+static const char* libfaadname = "libfaad.so.0";
+#else
+#define dlopen(a)
+#define dlclose(a)
+#endif
+
+typedef struct {
+ void* handle; /* dlopen handle */
+ void* faac_handle; /* FAAD library handle */
+ int sample_size;
+ int init;
+
+ /* faad calls */
+ faacDecHandle FAADAPI (*faacDecOpen)(void);
+ faacDecConfigurationPtr FAADAPI (*faacDecGetCurrentConfiguration)(faacDecHandle hDecoder);
+#ifndef FAAD2_VERSION
+ int FAADAPI (*faacDecSetConfiguration)(faacDecHandle hDecoder,
+ faacDecConfigurationPtr config);
+ int FAADAPI (*faacDecInit)(faacDecHandle hDecoder,
+ unsigned char *buffer,
+ unsigned long *samplerate,
+ unsigned long *channels);
+ int FAADAPI (*faacDecInit2)(faacDecHandle hDecoder, unsigned char *pBuffer,
+ unsigned long SizeOfDecoderSpecificInfo,
+ unsigned long *samplerate, unsigned long *channels);
+ int FAADAPI (*faacDecDecode)(faacDecHandle hDecoder,
+ unsigned char *buffer,
+ unsigned long *bytesconsumed,
+ short *sample_buffer,
+ unsigned long *samples);
+#else
+ unsigned char FAADAPI (*faacDecSetConfiguration)(faacDecHandle hDecoder,
+ faacDecConfigurationPtr config);
+ long FAADAPI (*faacDecInit)(faacDecHandle hDecoder,
+ unsigned char *buffer,
+ unsigned long buffer_size,
+ unsigned long *samplerate,
+ unsigned char *channels);
+ char FAADAPI (*faacDecInit2)(faacDecHandle hDecoder, unsigned char *pBuffer,
+ unsigned long SizeOfDecoderSpecificInfo,
+ unsigned long *samplerate, unsigned char *channels);
+ void *FAADAPI (*faacDecDecode)(faacDecHandle hDecoder,
+ faacDecFrameInfo *hInfo,
+ unsigned char *buffer,
+ unsigned long buffer_size);
+ char* FAADAPI (*faacDecGetErrorMessage)(unsigned char errcode);
+#endif
+
+ void FAADAPI (*faacDecClose)(faacDecHandle hDecoder);
+
+
+} FAACContext;
+
+static const unsigned long faac_srates[] =
+{
+ 96000, 88200, 64000, 48000, 44100, 32000,
+ 24000, 22050, 16000, 12000, 11025, 8000
+};
+
+static int faac_init_mp4(AVCodecContext *avctx)
+{
+ FAACContext *s = (FAACContext *) avctx->priv_data;
+ unsigned long samplerate;
+#ifndef FAAD2_VERSION
+ unsigned long channels;
+#else
+ unsigned char channels;
+#endif
+ int r = 0;
+
+ if (avctx->extradata){
+ r = s->faacDecInit2(s->faac_handle, (uint8_t*) avctx->extradata,
+ avctx->extradata_size,
+ &samplerate, &channels);
+ if (r < 0){
+ av_log(avctx, AV_LOG_ERROR,
+ "faacDecInit2 failed r:%d sr:%ld ch:%ld s:%d\n",
+ r, samplerate, (long)channels, avctx->extradata_size);
+ } else {
+ avctx->sample_rate = samplerate;
+ avctx->channels = channels;
+ s->init = 1;
+ }
+ }
+
+ return r;
+}
+
+static int faac_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ FAACContext *s = (FAACContext *) avctx->priv_data;
+#ifndef FAAD2_VERSION
+ unsigned long bytesconsumed;
+ short *sample_buffer = NULL;
+ unsigned long samples;
+ int out;
+#else
+ faacDecFrameInfo frame_info;
+ void *out;
+#endif
+ if(buf_size == 0)
+ return 0;
+#ifndef FAAD2_VERSION
+ out = s->faacDecDecode(s->faac_handle,
+ (unsigned char*)buf,
+ &bytesconsumed,
+ data,
+ &samples);
+ samples *= s->sample_size;
+ if (data_size)
+ *data_size = samples;
+ return (buf_size < (int)bytesconsumed)
+ ? buf_size : (int)bytesconsumed;
+#else
+
+ if(!s->init){
+ unsigned long srate;
+ 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: %s\n",
+ s->faacDecGetErrorMessage(frame_info.error));
+ return -1;
+ }
+ avctx->sample_rate = srate;
+ avctx->channels = channels;
+ s->init = 1;
+ }
+
+ 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",
+ s->faacDecGetErrorMessage(frame_info.error));
+ return -1;
+ }
+
+ frame_info.samples *= s->sample_size;
+ memcpy(data, out, frame_info.samples); // CHECKME - can we cheat this one
+
+ if (data_size)
+ *data_size = frame_info.samples;
+
+ return (buf_size < (int)frame_info.bytesconsumed)
+ ? buf_size : (int)frame_info.bytesconsumed;
+#endif
+}
+
+static int faac_decode_end(AVCodecContext *avctx)
+{
+ FAACContext *s = (FAACContext *) avctx->priv_data;
+
+ s->faacDecClose(s->faac_handle);
+
+ dlclose(s->handle);
+ return 0;
+}
+
+static int faac_decode_init(AVCodecContext *avctx)
+{
+ FAACContext *s = (FAACContext *) avctx->priv_data;
+ faacDecConfigurationPtr faac_cfg;
+
+#ifdef CONFIG_LIBFAADBIN
+ const char* err = 0;
+
+ s->handle = dlopen(libfaadname, RTLD_LAZY);
+ if (!s->handle)
+ {
+ av_log(avctx, AV_LOG_ERROR, "FAAD library: %s could not be opened! \n%s\n",
+ libfaadname, dlerror());
+ return -1;
+ }
+#define dfaac(a, b) \
+ do { static const char* n = "faacDec" #a; \
+ if ((s->faacDec ## a = b dlsym( s->handle, n )) == NULL) { err = n; break; } } while(0)
+ for(;;) {
+#else /* !CONFIG_LIBFAADBIN */
+#define dfaac(a, b) s->faacDec ## a = faacDec ## a
+#endif /* CONFIG_LIBFAADBIN */
+
+ // resolve all needed function calls
+ dfaac(Open, (faacDecHandle FAADAPI (*)(void)));
+ dfaac(Close, (void FAADAPI (*)(faacDecHandle hDecoder)));
+ dfaac(GetCurrentConfiguration, (faacDecConfigurationPtr
+ FAADAPI (*)(faacDecHandle)));
+#ifndef FAAD2_VERSION
+ dfaac(SetConfiguration, (int FAADAPI (*)(faacDecHandle,
+ faacDecConfigurationPtr)));
+
+ dfaac(Init, (int FAADAPI (*)(faacDecHandle, unsigned char*,
+ unsigned long*, unsigned long*)));
+ dfaac(Init2, (int FAADAPI (*)(faacDecHandle, unsigned char*,
+ unsigned long, unsigned long*,
+ unsigned long*)));
+ dfaac(Decode, (int FAADAPI (*)(faacDecHandle, unsigned char*,
+ unsigned long*, short*, unsigned long*)));
+#else
+ dfaac(SetConfiguration, (unsigned char FAADAPI (*)(faacDecHandle,
+ faacDecConfigurationPtr)));
+ dfaac(Init, (long FAADAPI (*)(faacDecHandle, unsigned char*,
+ unsigned long, unsigned long*, unsigned char*)));
+ dfaac(Init2, (char FAADAPI (*)(faacDecHandle, unsigned char*,
+ unsigned long, unsigned long*,
+ unsigned char*)));
+ dfaac(Decode, (void *FAADAPI (*)(faacDecHandle, faacDecFrameInfo*,
+ unsigned char*, unsigned long)));
+ dfaac(GetErrorMessage, (char* FAADAPI (*)(unsigned char)));
+#endif
+#undef dfacc
+
+#ifdef CONFIG_LIBFAADBIN
+ break;
+ }
+ if (err) {
+ dlclose(s->handle);
+ av_log(avctx, AV_LOG_ERROR, "FAAD library: cannot resolve %s in %s!\n",
+ err, libfaadname);
+ return -1;
+ }
+#endif
+
+ s->faac_handle = s->faacDecOpen();
+ if (!s->faac_handle) {
+ av_log(avctx, AV_LOG_ERROR, "FAAD library: cannot create handler!\n");
+ faac_decode_end(avctx);
+ return -1;
+ }
+
+
+ faac_cfg = s->faacDecGetCurrentConfiguration(s->faac_handle);
+
+ if (faac_cfg) {
+ switch (avctx->bits_per_sample) {
+ case 8: av_log(avctx, AV_LOG_ERROR, "FAADlib unsupported bps %d\n", avctx->bits_per_sample); break;
+ default:
+ case 16:
+#ifdef FAAD2_VERSION
+ faac_cfg->outputFormat = FAAD_FMT_16BIT;
+#endif
+ s->sample_size = 2;
+ break;
+ case 24:
+#ifdef FAAD2_VERSION
+ faac_cfg->outputFormat = FAAD_FMT_24BIT;
+#endif
+ s->sample_size = 3;
+ break;
+ case 32:
+#ifdef FAAD2_VERSION
+ faac_cfg->outputFormat = FAAD_FMT_32BIT;
+#endif
+ s->sample_size = 4;
+ break;
+ }
+
+ faac_cfg->defSampleRate = (!avctx->sample_rate) ? 44100 : avctx->sample_rate;
+ faac_cfg->defObjectType = LC;
+ }
+
+ s->faacDecSetConfiguration(s->faac_handle, faac_cfg);
+
+ faac_init_mp4(avctx);
+
+ return 0;
+}
+
+#define AAC_CODEC(id, name) \
+AVCodec name ## _decoder = { \
+ #name, \
+ CODEC_TYPE_AUDIO, \
+ id, \
+ sizeof(FAACContext), \
+ faac_decode_init, \
+ NULL, \
+ faac_decode_end, \
+ faac_decode_frame, \
+}
+
+// FIXME - raw AAC files - maybe just one entry will be enough
+AAC_CODEC(CODEC_ID_AAC, aac);
+#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
+// If it's mp4 file - usually embeded into Qt Mov
+AAC_CODEC(CODEC_ID_MPEG4AAC, mpeg4aac);
+#endif
+
+#undef AAC_CODEC
diff --git a/src/libffmpeg/libavcodec/faandct.c b/contrib/ffmpeg/libavcodec/faandct.c
index 6f73ee5e9..6f73ee5e9 100644
--- a/src/libffmpeg/libavcodec/faandct.c
+++ b/contrib/ffmpeg/libavcodec/faandct.c
diff --git a/src/libffmpeg/libavcodec/faandct.h b/contrib/ffmpeg/libavcodec/faandct.h
index 77dd41dae..77dd41dae 100644
--- a/src/libffmpeg/libavcodec/faandct.h
+++ b/contrib/ffmpeg/libavcodec/faandct.h
diff --git a/src/libffmpeg/libavcodec/fdctref.c b/contrib/ffmpeg/libavcodec/fdctref.c
index 5eff36849..5eff36849 100644
--- a/src/libffmpeg/libavcodec/fdctref.c
+++ b/contrib/ffmpeg/libavcodec/fdctref.c
diff --git a/contrib/ffmpeg/libavcodec/fft-test.c b/contrib/ffmpeg/libavcodec/fft-test.c
new file mode 100644
index 000000000..d2497383d
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/fft-test.c
@@ -0,0 +1,299 @@
+/*
+ * (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 fft-test.c
+ * FFT and MDCT tests.
+ */
+
+#include "dsputil.h"
+#include <math.h>
+#include <unistd.h>
+#include <sys/time.h>
+
+#undef exit
+
+int mm_flags;
+
+/* reference fft */
+
+#define MUL16(a,b) ((a) * (b))
+
+#define CMAC(pre, pim, are, aim, bre, bim) \
+{\
+ pre += (MUL16(are, bre) - MUL16(aim, bim));\
+ pim += (MUL16(are, bim) + MUL16(bre, aim));\
+}
+
+FFTComplex *exptab;
+
+void fft_ref_init(int nbits, int inverse)
+{
+ int n, i;
+ float c1, s1, alpha;
+
+ n = 1 << nbits;
+ exptab = av_malloc((n / 2) * sizeof(FFTComplex));
+
+ for(i=0;i<(n/2);i++) {
+ alpha = 2 * M_PI * (float)i / (float)n;
+ c1 = cos(alpha);
+ s1 = sin(alpha);
+ if (!inverse)
+ s1 = -s1;
+ exptab[i].re = c1;
+ exptab[i].im = s1;
+ }
+}
+
+void fft_ref(FFTComplex *tabr, FFTComplex *tab, int nbits)
+{
+ int n, i, j, k, n2;
+ float tmp_re, tmp_im, s, c;
+ FFTComplex *q;
+
+ n = 1 << nbits;
+ n2 = n >> 1;
+ for(i=0;i<n;i++) {
+ tmp_re = 0;
+ tmp_im = 0;
+ q = tab;
+ for(j=0;j<n;j++) {
+ k = (i * j) & (n - 1);
+ if (k >= n2) {
+ c = -exptab[k - n2].re;
+ s = -exptab[k - n2].im;
+ } else {
+ c = exptab[k].re;
+ s = exptab[k].im;
+ }
+ CMAC(tmp_re, tmp_im, c, s, q->re, q->im);
+ q++;
+ }
+ tabr[i].re = tmp_re;
+ tabr[i].im = tmp_im;
+ }
+}
+
+void imdct_ref(float *out, float *in, int n)
+{
+ int k, i, a;
+ float sum, f;
+
+ for(i=0;i<n;i++) {
+ sum = 0;
+ for(k=0;k<n/2;k++) {
+ a = (2 * i + 1 + (n / 2)) * (2 * k + 1);
+ f = cos(M_PI * a / (double)(2 * n));
+ sum += f * in[k];
+ }
+ out[i] = -sum;
+ }
+}
+
+/* NOTE: no normalisation by 1 / N is done */
+void mdct_ref(float *output, float *input, int n)
+{
+ int k, i;
+ float a, s;
+
+ /* do it by hand */
+ for(k=0;k<n/2;k++) {
+ s = 0;
+ for(i=0;i<n;i++) {
+ a = (2*M_PI*(2*i+1+n/2)*(2*k+1) / (4 * n));
+ s += input[i] * cos(a);
+ }
+ output[k] = s;
+ }
+}
+
+
+float frandom(void)
+{
+ return (float)((random() & 0xffff) - 32768) / 32768.0;
+}
+
+int64_t gettime(void)
+{
+ struct timeval tv;
+ gettimeofday(&tv,NULL);
+ return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
+}
+
+void check_diff(float *tab1, float *tab2, int n)
+{
+ int i;
+
+ for(i=0;i<n;i++) {
+ if (fabsf(tab1[i] - tab2[i]) >= 1e-3) {
+ av_log(NULL, AV_LOG_ERROR, "ERROR %d: %f %f\n",
+ i, tab1[i], tab2[i]);
+ }
+ }
+}
+
+
+void help(void)
+{
+ av_log(NULL, AV_LOG_INFO,"usage: fft-test [-h] [-s] [-i] [-n b]\n"
+ "-h print this help\n"
+ "-s speed test\n"
+ "-m (I)MDCT test\n"
+ "-i inverse transform test\n"
+ "-n b set the transform size to 2^b\n"
+ );
+ exit(1);
+}
+
+
+
+int main(int argc, char **argv)
+{
+ FFTComplex *tab, *tab1, *tab_ref;
+ FFTSample *tabtmp, *tab2;
+ int it, i, c;
+ int do_speed = 0;
+ int do_mdct = 0;
+ int do_inverse = 0;
+ FFTContext s1, *s = &s1;
+ MDCTContext m1, *m = &m1;
+ int fft_nbits, fft_size;
+
+ mm_flags = 0;
+ fft_nbits = 9;
+ for(;;) {
+ c = getopt(argc, argv, "hsimn:");
+ if (c == -1)
+ break;
+ switch(c) {
+ case 'h':
+ help();
+ break;
+ case 's':
+ do_speed = 1;
+ break;
+ case 'i':
+ do_inverse = 1;
+ break;
+ case 'm':
+ do_mdct = 1;
+ break;
+ case 'n':
+ fft_nbits = atoi(optarg);
+ break;
+ }
+ }
+
+ fft_size = 1 << fft_nbits;
+ tab = av_malloc(fft_size * sizeof(FFTComplex));
+ tab1 = av_malloc(fft_size * sizeof(FFTComplex));
+ tab_ref = av_malloc(fft_size * sizeof(FFTComplex));
+ tabtmp = av_malloc(fft_size / 2 * sizeof(FFTSample));
+ tab2 = av_malloc(fft_size * sizeof(FFTSample));
+
+ if (do_mdct) {
+ 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);
+ } else {
+ 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);
+ }
+ av_log(NULL, AV_LOG_INFO," %d test\n", fft_size);
+
+ /* generate random data */
+
+ for(i=0;i<fft_size;i++) {
+ tab1[i].re = frandom();
+ tab1[i].im = frandom();
+ }
+
+ /* checking result */
+ av_log(NULL, AV_LOG_INFO,"Checking...\n");
+
+ if (do_mdct) {
+ if (do_inverse) {
+ imdct_ref((float *)tab_ref, (float *)tab1, fft_size);
+ ff_imdct_calc(m, tab2, (float *)tab1, tabtmp);
+ check_diff((float *)tab_ref, tab2, fft_size);
+ } else {
+ mdct_ref((float *)tab_ref, (float *)tab1, fft_size);
+
+ ff_mdct_calc(m, tab2, (float *)tab1, tabtmp);
+
+ check_diff((float *)tab_ref, tab2, fft_size / 2);
+ }
+ } else {
+ memcpy(tab, tab1, fft_size * sizeof(FFTComplex));
+ ff_fft_permute(s, tab);
+ ff_fft_calc(s, tab);
+
+ fft_ref(tab_ref, tab1, fft_nbits);
+ check_diff((float *)tab_ref, (float *)tab, fft_size * 2);
+ }
+
+ /* do a speed test */
+
+ if (do_speed) {
+ int64_t time_start, duration;
+ int nb_its;
+
+ av_log(NULL, AV_LOG_INFO,"Speed test...\n");
+ /* we measure during about 1 seconds */
+ nb_its = 1;
+ for(;;) {
+ time_start = gettime();
+ for(it=0;it<nb_its;it++) {
+ if (do_mdct) {
+ if (do_inverse) {
+ ff_imdct_calc(m, (float *)tab, (float *)tab1, tabtmp);
+ } else {
+ ff_mdct_calc(m, (float *)tab, (float *)tab1, tabtmp);
+ }
+ } else {
+ memcpy(tab, tab1, fft_size * sizeof(FFTComplex));
+ ff_fft_calc(s, tab);
+ }
+ }
+ duration = gettime() - time_start;
+ if (duration >= 1000000)
+ break;
+ nb_its *= 2;
+ }
+ av_log(NULL, AV_LOG_INFO,"time: %0.1f us/transform [total time=%0.2f s its=%d]\n",
+ (double)duration / nb_its,
+ (double)duration / 1000000.0,
+ nb_its);
+ }
+
+ if (do_mdct) {
+ ff_mdct_end(m);
+ } else {
+ ff_fft_end(s);
+ }
+ return 0;
+}
diff --git a/src/libffmpeg/libavcodec/fft.c b/contrib/ffmpeg/libavcodec/fft.c
index 62a6a5576..62a6a5576 100644
--- a/src/libffmpeg/libavcodec/fft.c
+++ b/contrib/ffmpeg/libavcodec/fft.c
diff --git a/contrib/ffmpeg/libavcodec/ffv1.c b/contrib/ffmpeg/libavcodec/ffv1.c
new file mode 100644
index 000000000..45f408c87
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/ffv1.c
@@ -0,0 +1,1040 @@
+/*
+ * FFV1 codec for libavcodec
+ *
+ * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * @file ffv1.c
+ * FF Video Codec 1 (an experimental lossless codec)
+ */
+
+#include "common.h"
+#include "bitstream.h"
+#include "avcodec.h"
+#include "dsputil.h"
+#include "rangecoder.h"
+#include "golomb.h"
+
+#define MAX_PLANES 4
+#define CONTEXT_SIZE 32
+
+static const int8_t quant3[256]={
+ 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 0,
+};
+static const int8_t quant5[256]={
+ 0, 1, 1, 1, 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,-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,-1,-1,-1,
+};
+static const int8_t quant7[256]={
+ 0, 1, 1, 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, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,
+-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,
+-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,
+-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,
+-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,
+-3,-3,-3,-3,-3,-3,-3,-3,-3,-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,-1,-1,
+};
+static const int8_t quant9[256]={
+ 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 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,-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,-3,-3,-3,-3,
+-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-2,-2,-2,-2,-1,-1,
+};
+static const int8_t quant11[256]={
+ 0, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
+-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
+-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
+-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
+-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
+-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-4,-4,
+-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,
+-4,-4,-4,-4,-4,-3,-3,-3,-3,-3,-3,-3,-2,-2,-2,-1,
+};
+static const int8_t quant13[256]={
+ 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,
+-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,
+-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,
+-6,-6,-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,-5,
+-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
+-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
+-4,-4,-4,-4,-4,-4,-4,-4,-4,-3,-3,-3,-3,-2,-2,-1,
+};
+
+static const uint8_t log2_run[32]={
+ 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3,
+ 4, 4, 5, 5, 6, 6, 7, 7,
+ 8, 9,10,11,12,13,14,15,
+};
+
+typedef struct VlcState{
+ int16_t drift;
+ uint16_t error_sum;
+ int8_t bias;
+ uint8_t count;
+} VlcState;
+
+typedef struct PlaneContext{
+ int context_count;
+ uint8_t (*state)[CONTEXT_SIZE];
+ VlcState *vlc_state;
+ uint8_t interlace_bit_state[2];
+} PlaneContext;
+
+typedef struct FFV1Context{
+ AVCodecContext *avctx;
+ RangeCoder c;
+ GetBitContext gb;
+ PutBitContext pb;
+ int version;
+ int width, height;
+ int chroma_h_shift, chroma_v_shift;
+ int flags;
+ int picture_number;
+ AVFrame picture;
+ int plane_count;
+ int ac; ///< 1-> CABAC 0-> golomb rice
+ PlaneContext plane[MAX_PLANES];
+ int16_t quant_table[5][256];
+ int run_index;
+ int colorspace;
+
+ DSPContext dsp;
+}FFV1Context;
+
+static av_always_inline int fold(int diff, int bits){
+ if(bits==8)
+ diff= (int8_t)diff;
+ else{
+ diff+= 1<<(bits-1);
+ diff&=(1<<bits)-1;
+ diff-= 1<<(bits-1);
+ }
+
+ return diff;
+}
+
+static inline int predict(int_fast16_t *src, int_fast16_t *last){
+ const int LT= last[-1];
+ const int T= last[ 0];
+ const int L = src[-1];
+
+ return mid_pred(L, L + T - LT, T);
+}
+
+static inline int get_context(FFV1Context *f, int_fast16_t *src, int_fast16_t *last, int_fast16_t *last2){
+ const int LT= last[-1];
+ const int T= last[ 0];
+ const int RT= last[ 1];
+ const int L = src[-1];
+
+ if(f->quant_table[3][127]){
+ const int TT= last2[0];
+ const int LL= src[-2];
+ return f->quant_table[0][(L-LT) & 0xFF] + f->quant_table[1][(LT-T) & 0xFF] + f->quant_table[2][(T-RT) & 0xFF]
+ +f->quant_table[3][(LL-L) & 0xFF] + f->quant_table[4][(TT-T) & 0xFF];
+ }else
+ return f->quant_table[0][(L-LT) & 0xFF] + f->quant_table[1][(LT-T) & 0xFF] + f->quant_table[2][(T-RT) & 0xFF];
+}
+
+static inline void put_symbol(RangeCoder *c, uint8_t *state, int v, int is_signed){
+ int i;
+
+ if(v){
+ const int a= FFABS(v);
+ const int e= av_log2(a);
+ put_rac(c, state+0, 0);
+
+ assert(e<=9);
+
+ for(i=0; i<e; i++){
+ put_rac(c, state+1+i, 1); //1..10
+ }
+ put_rac(c, state+1+i, 0);
+
+ for(i=e-1; i>=0; i--){
+ put_rac(c, state+22+i, (a>>i)&1); //22..31
+ }
+
+ if(is_signed)
+ put_rac(c, state+11 + e, v < 0); //11..21
+ }else{
+ put_rac(c, state+0, 1);
+ }
+}
+
+static inline int get_symbol(RangeCoder *c, uint8_t *state, int is_signed){
+ if(get_rac(c, state+0))
+ return 0;
+ else{
+ int i, e, a;
+ e= 0;
+ while(get_rac(c, state+1 + e)){ //1..10
+ e++;
+ }
+ assert(e<=9);
+
+ a= 1;
+ for(i=e-1; i>=0; i--){
+ a += a + get_rac(c, state+22 + i); //22..31
+ }
+
+ if(is_signed && get_rac(c, state+11 + e)) //11..21
+ return -a;
+ else
+ return a;
+ }
+}
+
+static inline void update_vlc_state(VlcState * const state, const int v){
+ int drift= state->drift;
+ int count= state->count;
+ state->error_sum += FFABS(v);
+ drift += v;
+
+ if(count == 128){ //FIXME variable
+ count >>= 1;
+ drift >>= 1;
+ state->error_sum >>= 1;
+ }
+ count++;
+
+ if(drift <= -count){
+ if(state->bias > -128) state->bias--;
+
+ drift += count;
+ if(drift <= -count)
+ drift= -count + 1;
+ }else if(drift > 0){
+ if(state->bias < 127) state->bias++;
+
+ drift -= count;
+ if(drift > 0)
+ drift= 0;
+ }
+
+ state->drift= drift;
+ state->count= count;
+}
+
+static inline void put_vlc_symbol(PutBitContext *pb, VlcState * const state, int v, int bits){
+ int i, k, code;
+//printf("final: %d ", v);
+ v = fold(v - state->bias, bits);
+
+ i= state->count;
+ k=0;
+ while(i < state->error_sum){ //FIXME optimize
+ k++;
+ i += i;
+ }
+
+ assert(k<=8);
+
+#if 0 // JPEG LS
+ if(k==0 && 2*state->drift <= - state->count) code= v ^ (-1);
+ else code= v;
+#else
+ code= v ^ ((2*state->drift + state->count)>>31);
+#endif
+
+//printf("v:%d/%d bias:%d error:%d drift:%d count:%d k:%d\n", v, code, state->bias, state->error_sum, state->drift, state->count, k);
+ set_sr_golomb(pb, code, k, 12, bits);
+
+ update_vlc_state(state, v);
+}
+
+static inline int get_vlc_symbol(GetBitContext *gb, VlcState * const state, int bits){
+ int k, i, v, ret;
+
+ i= state->count;
+ k=0;
+ while(i < state->error_sum){ //FIXME optimize
+ k++;
+ i += i;
+ }
+
+ assert(k<=8);
+
+ v= get_sr_golomb(gb, k, 12, bits);
+//printf("v:%d bias:%d error:%d drift:%d count:%d k:%d", v, state->bias, state->error_sum, state->drift, state->count, k);
+
+#if 0 // JPEG LS
+ if(k==0 && 2*state->drift <= - state->count) v ^= (-1);
+#else
+ v ^= ((2*state->drift + state->count)>>31);
+#endif
+
+ ret= fold(v + state->bias, bits);
+
+ update_vlc_state(state, v);
+//printf("final: %d\n", ret);
+ return ret;
+}
+
+#ifdef CONFIG_ENCODERS
+static inline int encode_line(FFV1Context *s, int w, int_fast16_t *sample[2], int plane_index, int bits){
+ PlaneContext * const p= &s->plane[plane_index];
+ RangeCoder * const c= &s->c;
+ int x;
+ int run_index= s->run_index;
+ int run_count=0;
+ int run_mode=0;
+
+ if(s->ac){
+ if(c->bytestream_end - c->bytestream < w*20){
+ av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
+ return -1;
+ }
+ }else{
+ if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < w*4){
+ av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
+ return -1;
+ }
+ }
+
+ for(x=0; x<w; x++){
+ int diff, context;
+
+ context= get_context(s, sample[0]+x, sample[1]+x, sample[2]+x);
+ diff= sample[0][x] - predict(sample[0]+x, sample[1]+x);
+
+ if(context < 0){
+ context = -context;
+ diff= -diff;
+ }
+
+ diff= fold(diff, bits);
+
+ if(s->ac){
+ put_symbol(c, p->state[context], diff, 1);
+ }else{
+ if(context == 0) run_mode=1;
+
+ if(run_mode){
+
+ if(diff){
+ while(run_count >= 1<<log2_run[run_index]){
+ run_count -= 1<<log2_run[run_index];
+ run_index++;
+ put_bits(&s->pb, 1, 1);
+ }
+
+ put_bits(&s->pb, 1 + log2_run[run_index], run_count);
+ if(run_index) run_index--;
+ run_count=0;
+ run_mode=0;
+ if(diff>0) diff--;
+ }else{
+ run_count++;
+ }
+ }
+
+// printf("count:%d index:%d, mode:%d, x:%d y:%d pos:%d\n", run_count, run_index, run_mode, x, y, (int)put_bits_count(&s->pb));
+
+ if(run_mode == 0)
+ put_vlc_symbol(&s->pb, &p->vlc_state[context], diff, bits);
+ }
+ }
+ if(run_mode){
+ while(run_count >= 1<<log2_run[run_index]){
+ run_count -= 1<<log2_run[run_index];
+ run_index++;
+ put_bits(&s->pb, 1, 1);
+ }
+
+ if(run_count)
+ put_bits(&s->pb, 1, 1);
+ }
+ s->run_index= run_index;
+
+ return 0;
+}
+
+static void encode_plane(FFV1Context *s, uint8_t *src, int w, int h, int stride, int plane_index){
+ int x,y,i;
+ const int ring_size= s->avctx->context_model ? 3 : 2;
+ int_fast16_t sample_buffer[ring_size][w+6], *sample[ring_size];
+ s->run_index=0;
+
+ memset(sample_buffer, 0, sizeof(sample_buffer));
+
+ for(y=0; y<h; y++){
+ for(i=0; i<ring_size; i++)
+ sample[i]= sample_buffer[(h+i-y)%ring_size]+3;
+
+ sample[0][-1]= sample[1][0 ];
+ sample[1][ w]= sample[1][w-1];
+//{START_TIMER
+ for(x=0; x<w; x++){
+ sample[0][x]= src[x + stride*y];
+ }
+ encode_line(s, w, sample, plane_index, 8);
+//STOP_TIMER("encode line")}
+ }
+}
+
+static void encode_rgb_frame(FFV1Context *s, uint32_t *src, int w, int h, int stride){
+ int x, y, p, i;
+ const int ring_size= s->avctx->context_model ? 3 : 2;
+ int_fast16_t sample_buffer[3][ring_size][w+6], *sample[3][ring_size];
+ s->run_index=0;
+
+ memset(sample_buffer, 0, sizeof(sample_buffer));
+
+ for(y=0; y<h; y++){
+ for(i=0; i<ring_size; i++)
+ for(p=0; p<3; p++)
+ sample[p][i]= sample_buffer[p][(h+i-y)%ring_size]+3;
+
+ for(x=0; x<w; x++){
+ int v= src[x + stride*y];
+ int b= v&0xFF;
+ int g= (v>>8)&0xFF;
+ int r= (v>>16)&0xFF;
+
+ b -= g;
+ r -= g;
+ g += (b + r)>>2;
+ b += 0x100;
+ r += 0x100;
+
+// assert(g>=0 && b>=0 && r>=0);
+// assert(g<256 && b<512 && r<512);
+ sample[0][0][x]= g;
+ sample[1][0][x]= b;
+ sample[2][0][x]= r;
+ }
+ for(p=0; p<3; p++){
+ sample[p][0][-1]= sample[p][1][0 ];
+ sample[p][1][ w]= sample[p][1][w-1];
+ encode_line(s, w, sample[p], FFMIN(p, 1), 9);
+ }
+ }
+}
+
+static void write_quant_table(RangeCoder *c, int16_t *quant_table){
+ int last=0;
+ int i;
+ uint8_t state[CONTEXT_SIZE];
+ memset(state, 128, sizeof(state));
+
+ for(i=1; i<128 ; i++){
+ if(quant_table[i] != quant_table[i-1]){
+ put_symbol(c, state, i-last-1, 0);
+ last= i;
+ }
+ }
+ put_symbol(c, state, i-last-1, 0);
+}
+
+static void write_header(FFV1Context *f){
+ uint8_t state[CONTEXT_SIZE];
+ int i;
+ RangeCoder * const c= &f->c;
+
+ 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->colorspace, 0); //YUV cs type
+ put_rac(c, state, 1); //chroma planes
+ put_symbol(c, state, f->chroma_h_shift, 0);
+ put_symbol(c, state, f->chroma_v_shift, 0);
+ put_rac(c, state, 0); //no transparency plane
+
+ for(i=0; i<5; i++)
+ write_quant_table(c, f->quant_table[i]);
+}
+#endif /* CONFIG_ENCODERS */
+
+static int common_init(AVCodecContext *avctx){
+ FFV1Context *s = avctx->priv_data;
+ int width, height;
+
+ s->avctx= avctx;
+ s->flags= avctx->flags;
+
+ dsputil_init(&s->dsp, avctx);
+
+ width= s->width= avctx->width;
+ height= s->height= avctx->height;
+
+ assert(width && height);
+
+ return 0;
+}
+
+#ifdef CONFIG_ENCODERS
+static int encode_init(AVCodecContext *avctx)
+{
+ FFV1Context *s = avctx->priv_data;
+ int i;
+
+ common_init(avctx);
+
+ s->version=0;
+ s->ac= avctx->coder_type;
+
+ s->plane_count=2;
+ for(i=0; i<256; i++){
+ s->quant_table[0][i]= quant11[i];
+ s->quant_table[1][i]= 11*quant11[i];
+ if(avctx->context_model==0){
+ s->quant_table[2][i]= 11*11*quant11[i];
+ s->quant_table[3][i]=
+ s->quant_table[4][i]=0;
+ }else{
+ s->quant_table[2][i]= 11*11*quant5 [i];
+ s->quant_table[3][i]= 5*11*11*quant5 [i];
+ s->quant_table[4][i]= 5*5*11*11*quant5 [i];
+ }
+ }
+
+ for(i=0; i<s->plane_count; i++){
+ PlaneContext * const p= &s->plane[i];
+
+ if(avctx->context_model==0){
+ p->context_count= (11*11*11+1)/2;
+ }else{
+ p->context_count= (11*11*5*5*5+1)/2;
+ }
+
+ if(s->ac){
+ if(!p->state) p->state= av_malloc(CONTEXT_SIZE*p->context_count*sizeof(uint8_t));
+ }else{
+ if(!p->vlc_state) p->vlc_state= av_malloc(p->context_count*sizeof(VlcState));
+ }
+ }
+
+ avctx->coded_frame= &s->picture;
+ switch(avctx->pix_fmt){
+ case PIX_FMT_YUV444P:
+ case PIX_FMT_YUV422P:
+ case PIX_FMT_YUV420P:
+ case PIX_FMT_YUV411P:
+ case PIX_FMT_YUV410P:
+ s->colorspace= 0;
+ break;
+ case PIX_FMT_RGB32:
+ s->colorspace= 1;
+ break;
+ default:
+ av_log(avctx, AV_LOG_ERROR, "format not supported\n");
+ return -1;
+ }
+ avcodec_get_chroma_sub_sample(avctx->pix_fmt, &s->chroma_h_shift, &s->chroma_v_shift);
+
+ s->picture_number=0;
+
+ return 0;
+}
+#endif /* CONFIG_ENCODERS */
+
+
+static void clear_state(FFV1Context *f){
+ int i, j;
+
+ for(i=0; i<f->plane_count; i++){
+ PlaneContext *p= &f->plane[i];
+
+ p->interlace_bit_state[0]= 128;
+ p->interlace_bit_state[1]= 128;
+
+ for(j=0; j<p->context_count; j++){
+ if(f->ac){
+ memset(p->state[j], 128, sizeof(uint8_t)*CONTEXT_SIZE);
+ }else{
+ p->vlc_state[j].drift= 0;
+ p->vlc_state[j].error_sum= 4; //FFMAX((RANGE + 32)/64, 2);
+ p->vlc_state[j].bias= 0;
+ p->vlc_state[j].count= 1;
+ }
+ }
+ }
+}
+
+#ifdef CONFIG_ENCODERS
+static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
+ FFV1Context *f = avctx->priv_data;
+ RangeCoder * const c= &f->c;
+ AVFrame *pict = data;
+ const int width= f->width;
+ const int height= f->height;
+ AVFrame * const p= &f->picture;
+ int used_count= 0;
+ 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;
+ p->pict_type= FF_I_TYPE;
+
+ if(avctx->gop_size==0 || f->picture_number % avctx->gop_size == 0){
+ put_rac(c, &keystate, 1);
+ p->key_frame= 1;
+ write_header(f);
+ clear_state(f);
+ }else{
+ put_rac(c, &keystate, 0);
+ p->key_frame= 0;
+ }
+
+ if(!f->ac){
+ used_count += ff_rac_terminate(c);
+//printf("pos=%d\n", used_count);
+ init_put_bits(&f->pb, buf + used_count, buf_size - used_count);
+ }
+
+ if(f->colorspace==0){
+ const int chroma_width = -((-width )>>f->chroma_h_shift);
+ const int chroma_height= -((-height)>>f->chroma_v_shift);
+
+ encode_plane(f, p->data[0], width, height, p->linesize[0], 0);
+
+ encode_plane(f, p->data[1], chroma_width, chroma_height, p->linesize[1], 1);
+ encode_plane(f, p->data[2], chroma_width, chroma_height, p->linesize[2], 1);
+ }else{
+ encode_rgb_frame(f, (uint32_t*)(p->data[0]), width, height, p->linesize[0]/4);
+ }
+ emms_c();
+
+ f->picture_number++;
+
+ if(f->ac){
+ return ff_rac_terminate(c);
+ }else{
+ flush_put_bits(&f->pb); //nicer padding FIXME
+ return used_count + (put_bits_count(&f->pb)+7)/8;
+ }
+}
+#endif /* CONFIG_ENCODERS */
+
+static int common_end(AVCodecContext *avctx){
+ FFV1Context *s = avctx->priv_data;
+ int i;
+
+ for(i=0; i<s->plane_count; i++){
+ PlaneContext *p= &s->plane[i];
+
+ av_freep(&p->state);
+ }
+
+ return 0;
+}
+
+static inline void decode_line(FFV1Context *s, int w, int_fast16_t *sample[2], int plane_index, int bits){
+ PlaneContext * const p= &s->plane[plane_index];
+ RangeCoder * const c= &s->c;
+ int x;
+ int run_count=0;
+ int run_mode=0;
+ int run_index= s->run_index;
+
+ for(x=0; x<w; x++){
+ int diff, context, sign;
+
+ context= get_context(s, sample[1] + x, sample[0] + x, sample[1] + x);
+ if(context < 0){
+ context= -context;
+ sign=1;
+ }else
+ sign=0;
+
+
+ if(s->ac){
+ diff= get_symbol(c, p->state[context], 1);
+ }else{
+ if(context == 0 && run_mode==0) run_mode=1;
+
+ if(run_mode){
+ if(run_count==0 && run_mode==1){
+ if(get_bits1(&s->gb)){
+ run_count = 1<<log2_run[run_index];
+ if(x + run_count <= w) run_index++;
+ }else{
+ if(log2_run[run_index]) run_count = get_bits(&s->gb, log2_run[run_index]);
+ else run_count=0;
+ if(run_index) run_index--;
+ run_mode=2;
+ }
+ }
+ run_count--;
+ if(run_count < 0){
+ run_mode=0;
+ run_count=0;
+ diff= get_vlc_symbol(&s->gb, &p->vlc_state[context], bits);
+ if(diff>=0) diff++;
+ }else
+ diff=0;
+ }else
+ diff= get_vlc_symbol(&s->gb, &p->vlc_state[context], bits);
+
+// printf("count:%d index:%d, mode:%d, x:%d y:%d pos:%d\n", run_count, run_index, run_mode, x, y, get_bits_count(&s->gb));
+ }
+
+ if(sign) diff= -diff;
+
+ sample[1][x]= (predict(sample[1] + x, sample[0] + x) + diff) & ((1<<bits)-1);
+ }
+ s->run_index= run_index;
+}
+
+static void decode_plane(FFV1Context *s, uint8_t *src, int w, int h, int stride, int plane_index){
+ int x, y;
+ int_fast16_t sample_buffer[2][w+6];
+ int_fast16_t *sample[2]= {sample_buffer[0]+3, sample_buffer[1]+3};
+
+ s->run_index=0;
+
+ memset(sample_buffer, 0, sizeof(sample_buffer));
+
+ for(y=0; y<h; y++){
+ int_fast16_t *temp= sample[0]; //FIXME try a normal buffer
+
+ sample[0]= sample[1];
+ sample[1]= temp;
+
+ sample[1][-1]= sample[0][0 ];
+ sample[0][ w]= sample[0][w-1];
+
+//{START_TIMER
+ decode_line(s, w, sample, plane_index, 8);
+ for(x=0; x<w; x++){
+ src[x + stride*y]= sample[1][x];
+ }
+//STOP_TIMER("decode-line")}
+ }
+}
+
+static void decode_rgb_frame(FFV1Context *s, uint32_t *src, int w, int h, int stride){
+ int x, y, p;
+ int_fast16_t sample_buffer[3][2][w+6];
+ int_fast16_t *sample[3][2]= {
+ {sample_buffer[0][0]+3, sample_buffer[0][1]+3},
+ {sample_buffer[1][0]+3, sample_buffer[1][1]+3},
+ {sample_buffer[2][0]+3, sample_buffer[2][1]+3}};
+
+ s->run_index=0;
+
+ memset(sample_buffer, 0, sizeof(sample_buffer));
+
+ for(y=0; y<h; y++){
+ for(p=0; p<3; p++){
+ int_fast16_t *temp= sample[p][0]; //FIXME try a normal buffer
+
+ sample[p][0]= sample[p][1];
+ sample[p][1]= temp;
+
+ sample[p][1][-1]= sample[p][0][0 ];
+ sample[p][0][ w]= sample[p][0][w-1];
+ decode_line(s, w, sample[p], FFMIN(p, 1), 9);
+ }
+ for(x=0; x<w; x++){
+ int g= sample[0][1][x];
+ int b= sample[1][1][x];
+ int r= sample[2][1][x];
+
+// assert(g>=0 && b>=0 && r>=0);
+// assert(g<256 && b<512 && r<512);
+
+ b -= 0x100;
+ r -= 0x100;
+ g -= (b + r)>>2;
+ b += g;
+ r += g;
+
+ src[x + stride*y]= b + (g<<8) + (r<<16);
+ }
+ }
+}
+
+static int read_quant_table(RangeCoder *c, int16_t *quant_table, int scale){
+ int v;
+ int i=0;
+ uint8_t state[CONTEXT_SIZE];
+
+ memset(state, 128, sizeof(state));
+
+ for(v=0; i<128 ; v++){
+ int len= get_symbol(c, state, 0) + 1;
+
+ if(len + i > 128) return -1;
+
+ while(len--){
+ quant_table[i] = scale*v;
+ i++;
+//printf("%2d ",v);
+//if(i%16==0) printf("\n");
+ }
+ }
+
+ for(i=1; i<128; i++){
+ quant_table[256-i]= -quant_table[i];
+ }
+ quant_table[128]= -quant_table[127];
+
+ return 2*v - 1;
+}
+
+static int read_header(FFV1Context *f){
+ uint8_t state[CONTEXT_SIZE];
+ int i, context_count;
+ RangeCoder * const c= &f->c;
+
+ memset(state, 128, sizeof(state));
+
+ f->version= get_symbol(c, state, 0);
+ f->ac= f->avctx->coder_type= get_symbol(c, state, 0);
+ f->colorspace= get_symbol(c, state, 0); //YUV cs type
+ get_rac(c, state); //no chroma = false
+ f->chroma_h_shift= get_symbol(c, state, 0);
+ f->chroma_v_shift= get_symbol(c, state, 0);
+ get_rac(c, state); //transparency plane
+ f->plane_count= 2;
+
+ if(f->colorspace==0){
+ switch(16*f->chroma_h_shift + f->chroma_v_shift){
+ case 0x00: f->avctx->pix_fmt= PIX_FMT_YUV444P; break;
+ case 0x10: f->avctx->pix_fmt= PIX_FMT_YUV422P; break;
+ case 0x11: f->avctx->pix_fmt= PIX_FMT_YUV420P; break;
+ case 0x20: f->avctx->pix_fmt= PIX_FMT_YUV411P; break;
+ case 0x22: f->avctx->pix_fmt= PIX_FMT_YUV410P; break;
+ default:
+ av_log(f->avctx, AV_LOG_ERROR, "format not supported\n");
+ return -1;
+ }
+ }else if(f->colorspace==1){
+ if(f->chroma_h_shift || f->chroma_v_shift){
+ av_log(f->avctx, AV_LOG_ERROR, "chroma subsampling not supported in this colorspace\n");
+ return -1;
+ }
+ f->avctx->pix_fmt= PIX_FMT_RGB32;
+ }else{
+ av_log(f->avctx, AV_LOG_ERROR, "colorspace not supported\n");
+ return -1;
+ }
+
+//printf("%d %d %d\n", f->chroma_h_shift, f->chroma_v_shift,f->avctx->pix_fmt);
+
+ context_count=1;
+ for(i=0; i<5; i++){
+ context_count*= read_quant_table(c, f->quant_table[i], context_count);
+ if(context_count < 0 || context_count > 32768){
+ av_log(f->avctx, AV_LOG_ERROR, "read_quant_table error\n");
+ return -1;
+ }
+ }
+ context_count= (context_count+1)/2;
+
+ for(i=0; i<f->plane_count; i++){
+ PlaneContext * const p= &f->plane[i];
+
+ p->context_count= context_count;
+
+ if(f->ac){
+ if(!p->state) p->state= av_malloc(CONTEXT_SIZE*p->context_count*sizeof(uint8_t));
+ }else{
+ if(!p->vlc_state) p->vlc_state= av_malloc(p->context_count*sizeof(VlcState));
+ }
+ }
+
+ return 0;
+}
+
+static int decode_init(AVCodecContext *avctx)
+{
+// FFV1Context *s = avctx->priv_data;
+
+ common_init(avctx);
+
+ return 0;
+}
+
+static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size){
+ FFV1Context *f = avctx->priv_data;
+ RangeCoder * const c= &f->c;
+ const int width= f->width;
+ const int height= f->height;
+ AVFrame * const p= &f->picture;
+ int bytes_read;
+ uint8_t keystate= 128;
+
+ AVFrame *picture = data;
+
+ ff_init_range_decoder(c, buf, buf_size);
+ ff_build_rac_states(c, 0.05*(1LL<<32), 256-8);
+
+
+ p->pict_type= FF_I_TYPE; //FIXME I vs. P
+ if(get_rac(c, &keystate)){
+ p->key_frame= 1;
+ if(read_header(f) < 0)
+ return -1;
+ clear_state(f);
+ }else{
+ p->key_frame= 0;
+ }
+ if(!f->plane[0].state && !f->plane[0].vlc_state)
+ return -1;
+
+ p->reference= 0;
+ if(avctx->get_buffer(avctx, p) < 0){
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ return -1;
+ }
+
+ if(avctx->debug&FF_DEBUG_PICT_INFO)
+ av_log(avctx, AV_LOG_ERROR, "keyframe:%d coder:%d\n", p->key_frame, f->ac);
+
+ if(!f->ac){
+ bytes_read = c->bytestream - c->bytestream_start - 1;
+ if(bytes_read ==0) av_log(avctx, AV_LOG_ERROR, "error at end of AC stream\n"); //FIXME
+//printf("pos=%d\n", bytes_read);
+ init_get_bits(&f->gb, buf + bytes_read, buf_size - bytes_read);
+ } else {
+ bytes_read = 0; /* avoid warning */
+ }
+
+ if(f->colorspace==0){
+ const int chroma_width = -((-width )>>f->chroma_h_shift);
+ const int chroma_height= -((-height)>>f->chroma_v_shift);
+ decode_plane(f, p->data[0], width, height, p->linesize[0], 0);
+
+ decode_plane(f, p->data[1], chroma_width, chroma_height, p->linesize[1], 1);
+ decode_plane(f, p->data[2], chroma_width, chroma_height, p->linesize[2], 1);
+ }else{
+ decode_rgb_frame(f, (uint32_t*)p->data[0], width, height, p->linesize[0]/4);
+ }
+
+ emms_c();
+
+ f->picture_number++;
+
+ *picture= *p;
+
+ avctx->release_buffer(avctx, p); //FIXME
+
+ *data_size = sizeof(AVFrame);
+
+ if(f->ac){
+ bytes_read= c->bytestream - c->bytestream_start - 1;
+ if(bytes_read ==0) av_log(f->avctx, AV_LOG_ERROR, "error at end of frame\n");
+ }else{
+ bytes_read+= (get_bits_count(&f->gb)+7)/8;
+ }
+
+ return bytes_read;
+}
+
+AVCodec ffv1_decoder = {
+ "ffv1",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_FFV1,
+ sizeof(FFV1Context),
+ decode_init,
+ NULL,
+ common_end,
+ decode_frame,
+ CODEC_CAP_DR1 /*| CODEC_CAP_DRAW_HORIZ_BAND*/,
+ NULL
+};
+
+#ifdef CONFIG_ENCODERS
+AVCodec ffv1_encoder = {
+ "ffv1",
+ CODEC_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, -1},
+};
+#endif
diff --git a/src/libffmpeg/libavcodec/flac.c b/contrib/ffmpeg/libavcodec/flac.c
index 1016ed47f..1016ed47f 100644
--- a/src/libffmpeg/libavcodec/flac.c
+++ b/contrib/ffmpeg/libavcodec/flac.c
diff --git a/contrib/ffmpeg/libavcodec/flacenc.c b/contrib/ffmpeg/libavcodec/flacenc.c
new file mode 100644
index 000000000..9dd6c7eb8
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/flacenc.c
@@ -0,0 +1,1371 @@
+/**
+ * FLAC audio encoder
+ * Copyright (c) 2006 Justin Ruggles <jruggle@earthlink.net>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 "bitstream.h"
+#include "crc.h"
+#include "golomb.h"
+#include "lls.h"
+
+#define FLAC_MAX_CH 8
+#define FLAC_MIN_BLOCKSIZE 16
+#define FLAC_MAX_BLOCKSIZE 65535
+
+#define FLAC_SUBFRAME_CONSTANT 0
+#define FLAC_SUBFRAME_VERBATIM 1
+#define FLAC_SUBFRAME_FIXED 8
+#define FLAC_SUBFRAME_LPC 32
+
+#define FLAC_CHMODE_NOT_STEREO 0
+#define FLAC_CHMODE_LEFT_RIGHT 1
+#define FLAC_CHMODE_LEFT_SIDE 8
+#define FLAC_CHMODE_RIGHT_SIDE 9
+#define FLAC_CHMODE_MID_SIDE 10
+
+#define ORDER_METHOD_EST 0
+#define ORDER_METHOD_2LEVEL 1
+#define ORDER_METHOD_4LEVEL 2
+#define ORDER_METHOD_8LEVEL 3
+#define ORDER_METHOD_SEARCH 4
+#define ORDER_METHOD_LOG 5
+
+#define FLAC_STREAMINFO_SIZE 34
+
+#define MIN_LPC_ORDER 1
+#define MAX_LPC_ORDER 32
+#define MAX_FIXED_ORDER 4
+#define MAX_PARTITION_ORDER 8
+#define MAX_PARTITIONS (1 << MAX_PARTITION_ORDER)
+#define MAX_LPC_PRECISION 15
+#define MAX_LPC_SHIFT 15
+#define MAX_RICE_PARAM 14
+
+typedef struct CompressionOptions {
+ int compression_level;
+ int block_time_ms;
+ int use_lpc;
+ int lpc_coeff_precision;
+ int min_prediction_order;
+ int max_prediction_order;
+ int prediction_order_method;
+ int min_partition_order;
+ int max_partition_order;
+} CompressionOptions;
+
+typedef struct RiceContext {
+ int porder;
+ int params[MAX_PARTITIONS];
+} RiceContext;
+
+typedef struct FlacSubframe {
+ int type;
+ int type_code;
+ int obits;
+ int order;
+ int32_t coefs[MAX_LPC_ORDER];
+ int shift;
+ RiceContext rc;
+ int32_t samples[FLAC_MAX_BLOCKSIZE];
+ int32_t residual[FLAC_MAX_BLOCKSIZE];
+} FlacSubframe;
+
+typedef struct FlacFrame {
+ FlacSubframe subframes[FLAC_MAX_CH];
+ int blocksize;
+ int bs_code[2];
+ uint8_t crc8;
+ int ch_mode;
+} FlacFrame;
+
+typedef struct FlacEncodeContext {
+ PutBitContext pb;
+ int channels;
+ int ch_code;
+ int samplerate;
+ int sr_code[2];
+ int blocksize;
+ int max_framesize;
+ uint32_t frame_count;
+ FlacFrame frame;
+ CompressionOptions options;
+ AVCodecContext *avctx;
+} FlacEncodeContext;
+
+static const int flac_samplerates[16] = {
+ 0, 0, 0, 0,
+ 8000, 16000, 22050, 24000, 32000, 44100, 48000, 96000,
+ 0, 0, 0, 0
+};
+
+static const int flac_blocksizes[16] = {
+ 0,
+ 192,
+ 576, 1152, 2304, 4608,
+ 0, 0,
+ 256, 512, 1024, 2048, 4096, 8192, 16384, 32768
+};
+
+/**
+ * Writes streaminfo metadata block to byte array
+ */
+static void write_streaminfo(FlacEncodeContext *s, uint8_t *header)
+{
+ PutBitContext pb;
+
+ memset(header, 0, FLAC_STREAMINFO_SIZE);
+ init_put_bits(&pb, header, FLAC_STREAMINFO_SIZE);
+
+ /* streaminfo metadata block */
+ put_bits(&pb, 16, s->blocksize);
+ put_bits(&pb, 16, s->blocksize);
+ put_bits(&pb, 24, 0);
+ put_bits(&pb, 24, s->max_framesize);
+ put_bits(&pb, 20, s->samplerate);
+ put_bits(&pb, 3, s->channels-1);
+ put_bits(&pb, 5, 15); /* bits per sample - 1 */
+ flush_put_bits(&pb);
+ /* total samples = 0 */
+ /* MD5 signature = 0 */
+}
+
+/**
+ * Sets blocksize based on samplerate
+ * Chooses the closest predefined blocksize >= BLOCK_TIME_MS milliseconds
+ */
+static int select_blocksize(int samplerate, int block_time_ms)
+{
+ int i;
+ int target;
+ int blocksize;
+
+ assert(samplerate > 0);
+ blocksize = flac_blocksizes[1];
+ target = (samplerate * block_time_ms) / 1000;
+ for(i=0; i<16; i++) {
+ if(target >= flac_blocksizes[i] && flac_blocksizes[i] > blocksize) {
+ blocksize = flac_blocksizes[i];
+ }
+ }
+ return blocksize;
+}
+
+static int flac_encode_init(AVCodecContext *avctx)
+{
+ int freq = avctx->sample_rate;
+ int channels = avctx->channels;
+ FlacEncodeContext *s = avctx->priv_data;
+ int i, level;
+ uint8_t *streaminfo;
+
+ s->avctx = avctx;
+
+ if(avctx->sample_fmt != SAMPLE_FMT_S16) {
+ return -1;
+ }
+
+ if(channels < 1 || channels > FLAC_MAX_CH) {
+ return -1;
+ }
+ s->channels = channels;
+ s->ch_code = s->channels-1;
+
+ /* find samplerate in table */
+ if(freq < 1)
+ return -1;
+ for(i=4; i<12; i++) {
+ if(freq == flac_samplerates[i]) {
+ s->samplerate = flac_samplerates[i];
+ s->sr_code[0] = i;
+ s->sr_code[1] = 0;
+ break;
+ }
+ }
+ /* if not in table, samplerate is non-standard */
+ if(i == 12) {
+ if(freq % 1000 == 0 && freq < 255000) {
+ s->sr_code[0] = 12;
+ s->sr_code[1] = freq / 1000;
+ } else if(freq % 10 == 0 && freq < 655350) {
+ s->sr_code[0] = 14;
+ s->sr_code[1] = freq / 10;
+ } else if(freq < 65535) {
+ s->sr_code[0] = 13;
+ s->sr_code[1] = freq;
+ } else {
+ return -1;
+ }
+ s->samplerate = freq;
+ }
+
+ /* set compression option defaults based on avctx->compression_level */
+ if(avctx->compression_level < 0) {
+ s->options.compression_level = 5;
+ } else {
+ s->options.compression_level = avctx->compression_level;
+ }
+ av_log(avctx, AV_LOG_DEBUG, " compression: %d\n", s->options.compression_level);
+
+ level= s->options.compression_level;
+ if(level > 12) {
+ av_log(avctx, AV_LOG_ERROR, "invalid compression level: %d\n",
+ s->options.compression_level);
+ return -1;
+ }
+
+ s->options.block_time_ms = ((int[]){ 27, 27, 27,105,105,105,105,105,105,105,105,105,105})[level];
+ s->options.use_lpc = ((int[]){ 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1})[level];
+ s->options.min_prediction_order= ((int[]){ 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1})[level];
+ s->options.max_prediction_order= ((int[]){ 3, 4, 4, 6, 8, 8, 8, 8, 12, 12, 12, 32, 32})[level];
+ s->options.prediction_order_method = ((int[]){ ORDER_METHOD_EST, ORDER_METHOD_EST, ORDER_METHOD_EST,
+ ORDER_METHOD_EST, ORDER_METHOD_EST, ORDER_METHOD_EST,
+ ORDER_METHOD_4LEVEL, ORDER_METHOD_LOG, ORDER_METHOD_4LEVEL,
+ ORDER_METHOD_LOG, ORDER_METHOD_SEARCH, ORDER_METHOD_LOG,
+ ORDER_METHOD_SEARCH})[level];
+ s->options.min_partition_order = ((int[]){ 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})[level];
+ s->options.max_partition_order = ((int[]){ 2, 2, 3, 3, 3, 8, 8, 8, 8, 8, 8, 8, 8})[level];
+
+ /* set compression option overrides from AVCodecContext */
+ if(avctx->use_lpc >= 0) {
+ s->options.use_lpc = av_clip(avctx->use_lpc, 0, 11);
+ }
+ if(s->options.use_lpc == 1)
+ av_log(avctx, AV_LOG_DEBUG, " use lpc: Levinson-Durbin recursion with Welch window\n");
+ else if(s->options.use_lpc > 1)
+ av_log(avctx, AV_LOG_DEBUG, " use lpc: Cholesky factorization\n");
+
+ if(avctx->min_prediction_order >= 0) {
+ if(s->options.use_lpc) {
+ if(avctx->min_prediction_order < MIN_LPC_ORDER ||
+ avctx->min_prediction_order > MAX_LPC_ORDER) {
+ av_log(avctx, AV_LOG_ERROR, "invalid min prediction order: %d\n",
+ avctx->min_prediction_order);
+ return -1;
+ }
+ } else {
+ if(avctx->min_prediction_order > MAX_FIXED_ORDER) {
+ av_log(avctx, AV_LOG_ERROR, "invalid min prediction order: %d\n",
+ avctx->min_prediction_order);
+ return -1;
+ }
+ }
+ s->options.min_prediction_order = avctx->min_prediction_order;
+ }
+ if(avctx->max_prediction_order >= 0) {
+ if(s->options.use_lpc) {
+ if(avctx->max_prediction_order < MIN_LPC_ORDER ||
+ avctx->max_prediction_order > MAX_LPC_ORDER) {
+ av_log(avctx, AV_LOG_ERROR, "invalid max prediction order: %d\n",
+ avctx->max_prediction_order);
+ return -1;
+ }
+ } else {
+ if(avctx->max_prediction_order > MAX_FIXED_ORDER) {
+ av_log(avctx, AV_LOG_ERROR, "invalid max prediction order: %d\n",
+ avctx->max_prediction_order);
+ return -1;
+ }
+ }
+ s->options.max_prediction_order = avctx->max_prediction_order;
+ }
+ if(s->options.max_prediction_order < s->options.min_prediction_order) {
+ av_log(avctx, AV_LOG_ERROR, "invalid prediction orders: min=%d max=%d\n",
+ s->options.min_prediction_order, s->options.max_prediction_order);
+ return -1;
+ }
+ av_log(avctx, AV_LOG_DEBUG, " prediction order: %d, %d\n",
+ s->options.min_prediction_order, s->options.max_prediction_order);
+
+ if(avctx->prediction_order_method >= 0) {
+ if(avctx->prediction_order_method > ORDER_METHOD_LOG) {
+ av_log(avctx, AV_LOG_ERROR, "invalid prediction order method: %d\n",
+ avctx->prediction_order_method);
+ return -1;
+ }
+ s->options.prediction_order_method = avctx->prediction_order_method;
+ }
+ switch(s->options.prediction_order_method) {
+ case ORDER_METHOD_EST: av_log(avctx, AV_LOG_DEBUG, " order method: %s\n",
+ "estimate"); break;
+ case ORDER_METHOD_2LEVEL: av_log(avctx, AV_LOG_DEBUG, " order method: %s\n",
+ "2-level"); break;
+ case ORDER_METHOD_4LEVEL: av_log(avctx, AV_LOG_DEBUG, " order method: %s\n",
+ "4-level"); break;
+ case ORDER_METHOD_8LEVEL: av_log(avctx, AV_LOG_DEBUG, " order method: %s\n",
+ "8-level"); break;
+ case ORDER_METHOD_SEARCH: av_log(avctx, AV_LOG_DEBUG, " order method: %s\n",
+ "full search"); break;
+ case ORDER_METHOD_LOG: av_log(avctx, AV_LOG_DEBUG, " order method: %s\n",
+ "log search"); break;
+ }
+
+ if(avctx->min_partition_order >= 0) {
+ if(avctx->min_partition_order > MAX_PARTITION_ORDER) {
+ av_log(avctx, AV_LOG_ERROR, "invalid min partition order: %d\n",
+ avctx->min_partition_order);
+ return -1;
+ }
+ s->options.min_partition_order = avctx->min_partition_order;
+ }
+ if(avctx->max_partition_order >= 0) {
+ if(avctx->max_partition_order > MAX_PARTITION_ORDER) {
+ av_log(avctx, AV_LOG_ERROR, "invalid max partition order: %d\n",
+ avctx->max_partition_order);
+ return -1;
+ }
+ s->options.max_partition_order = avctx->max_partition_order;
+ }
+ if(s->options.max_partition_order < s->options.min_partition_order) {
+ av_log(avctx, AV_LOG_ERROR, "invalid partition orders: min=%d max=%d\n",
+ s->options.min_partition_order, s->options.max_partition_order);
+ return -1;
+ }
+ av_log(avctx, AV_LOG_DEBUG, " partition order: %d, %d\n",
+ s->options.min_partition_order, s->options.max_partition_order);
+
+ if(avctx->frame_size > 0) {
+ if(avctx->frame_size < FLAC_MIN_BLOCKSIZE ||
+ avctx->frame_size > FLAC_MAX_BLOCKSIZE) {
+ av_log(avctx, AV_LOG_ERROR, "invalid block size: %d\n",
+ avctx->frame_size);
+ return -1;
+ }
+ s->blocksize = avctx->frame_size;
+ } else {
+ s->blocksize = select_blocksize(s->samplerate, s->options.block_time_ms);
+ avctx->frame_size = s->blocksize;
+ }
+ av_log(avctx, AV_LOG_DEBUG, " block size: %d\n", s->blocksize);
+
+ /* set LPC precision */
+ if(avctx->lpc_coeff_precision > 0) {
+ if(avctx->lpc_coeff_precision > MAX_LPC_PRECISION) {
+ av_log(avctx, AV_LOG_ERROR, "invalid lpc coeff precision: %d\n",
+ avctx->lpc_coeff_precision);
+ return -1;
+ }
+ s->options.lpc_coeff_precision = avctx->lpc_coeff_precision;
+ } else {
+ /* select LPC precision based on block size */
+ if( s->blocksize <= 192) s->options.lpc_coeff_precision = 7;
+ else if(s->blocksize <= 384) s->options.lpc_coeff_precision = 8;
+ else if(s->blocksize <= 576) s->options.lpc_coeff_precision = 9;
+ else if(s->blocksize <= 1152) s->options.lpc_coeff_precision = 10;
+ else if(s->blocksize <= 2304) s->options.lpc_coeff_precision = 11;
+ else if(s->blocksize <= 4608) s->options.lpc_coeff_precision = 12;
+ else if(s->blocksize <= 8192) s->options.lpc_coeff_precision = 13;
+ else if(s->blocksize <= 16384) s->options.lpc_coeff_precision = 14;
+ else s->options.lpc_coeff_precision = 15;
+ }
+ av_log(avctx, AV_LOG_DEBUG, " lpc precision: %d\n",
+ s->options.lpc_coeff_precision);
+
+ /* set maximum encoded frame size in verbatim mode */
+ if(s->channels == 2) {
+ s->max_framesize = 14 + ((s->blocksize * 33 + 7) >> 3);
+ } else {
+ s->max_framesize = 14 + (s->blocksize * s->channels * 2);
+ }
+
+ streaminfo = av_malloc(FLAC_STREAMINFO_SIZE);
+ write_streaminfo(s, streaminfo);
+ avctx->extradata = streaminfo;
+ avctx->extradata_size = FLAC_STREAMINFO_SIZE;
+
+ s->frame_count = 0;
+
+ avctx->coded_frame = avcodec_alloc_frame();
+ avctx->coded_frame->key_frame = 1;
+
+ return 0;
+}
+
+static void init_frame(FlacEncodeContext *s)
+{
+ int i, ch;
+ FlacFrame *frame;
+
+ frame = &s->frame;
+
+ for(i=0; i<16; i++) {
+ if(s->blocksize == flac_blocksizes[i]) {
+ frame->blocksize = flac_blocksizes[i];
+ frame->bs_code[0] = i;
+ frame->bs_code[1] = 0;
+ break;
+ }
+ }
+ if(i == 16) {
+ frame->blocksize = s->blocksize;
+ if(frame->blocksize <= 256) {
+ frame->bs_code[0] = 6;
+ frame->bs_code[1] = frame->blocksize-1;
+ } else {
+ frame->bs_code[0] = 7;
+ frame->bs_code[1] = frame->blocksize-1;
+ }
+ }
+
+ for(ch=0; ch<s->channels; ch++) {
+ frame->subframes[ch].obits = 16;
+ }
+}
+
+/**
+ * Copy channel-interleaved input samples into separate subframes
+ */
+static void copy_samples(FlacEncodeContext *s, int16_t *samples)
+{
+ int i, j, ch;
+ FlacFrame *frame;
+
+ frame = &s->frame;
+ for(i=0,j=0; i<frame->blocksize; i++) {
+ for(ch=0; ch<s->channels; ch++,j++) {
+ frame->subframes[ch].samples[i] = samples[j];
+ }
+ }
+}
+
+
+#define rice_encode_count(sum, n, k) (((n)*((k)+1))+((sum-(n>>1))>>(k)))
+
+static int find_optimal_param(uint32_t sum, int n)
+{
+ int k, k_opt;
+ uint32_t nbits[MAX_RICE_PARAM+1];
+
+ k_opt = 0;
+ nbits[0] = UINT32_MAX;
+ for(k=0; k<=MAX_RICE_PARAM; k++) {
+ nbits[k] = rice_encode_count(sum, n, k);
+ if(nbits[k] < nbits[k_opt]) {
+ k_opt = k;
+ }
+ }
+ return k_opt;
+}
+
+static uint32_t calc_optimal_rice_params(RiceContext *rc, int porder,
+ uint32_t *sums, int n, int pred_order)
+{
+ int i;
+ int k, cnt, part;
+ uint32_t all_bits;
+
+ part = (1 << porder);
+ all_bits = 0;
+
+ cnt = (n >> porder) - pred_order;
+ for(i=0; i<part; i++) {
+ if(i == 1) cnt = (n >> porder);
+ k = find_optimal_param(sums[i], cnt);
+ rc->params[i] = k;
+ all_bits += rice_encode_count(sums[i], cnt, k);
+ }
+ all_bits += (4 * part);
+
+ rc->porder = porder;
+
+ return all_bits;
+}
+
+static void calc_sums(int pmin, int pmax, uint32_t *data, int n, int pred_order,
+ uint32_t sums[][MAX_PARTITIONS])
+{
+ int i, j;
+ int parts;
+ uint32_t *res, *res_end;
+
+ /* sums for highest level */
+ parts = (1 << pmax);
+ res = &data[pred_order];
+ res_end = &data[n >> pmax];
+ for(i=0; i<parts; i++) {
+ sums[pmax][i] = 0;
+ while(res < res_end){
+ sums[pmax][i] += *(res++);
+ }
+ res_end+= n >> pmax;
+ }
+ /* sums for lower levels */
+ for(i=pmax-1; i>=pmin; i--) {
+ parts = (1 << i);
+ for(j=0; j<parts; j++) {
+ sums[i][j] = sums[i+1][2*j] + sums[i+1][2*j+1];
+ }
+ }
+}
+
+static uint32_t calc_rice_params(RiceContext *rc, int pmin, int pmax,
+ int32_t *data, int n, int pred_order)
+{
+ int i;
+ uint32_t bits[MAX_PARTITION_ORDER+1];
+ int opt_porder;
+ RiceContext tmp_rc;
+ uint32_t *udata;
+ uint32_t sums[MAX_PARTITION_ORDER+1][MAX_PARTITIONS];
+
+ assert(pmin >= 0 && pmin <= MAX_PARTITION_ORDER);
+ assert(pmax >= 0 && pmax <= MAX_PARTITION_ORDER);
+ assert(pmin <= pmax);
+
+ udata = av_malloc(n * sizeof(uint32_t));
+ for(i=0; i<n; i++) {
+ udata[i] = (2*data[i]) ^ (data[i]>>31);
+ }
+
+ calc_sums(pmin, pmax, udata, n, pred_order, sums);
+
+ opt_porder = pmin;
+ bits[pmin] = UINT32_MAX;
+ for(i=pmin; i<=pmax; i++) {
+ bits[i] = calc_optimal_rice_params(&tmp_rc, i, sums[i], n, pred_order);
+ if(bits[i] <= bits[opt_porder]) {
+ opt_porder = i;
+ *rc= tmp_rc;
+ }
+ }
+
+ av_freep(&udata);
+ return bits[opt_porder];
+}
+
+static int get_max_p_order(int max_porder, int n, int order)
+{
+ int porder = FFMIN(max_porder, av_log2(n^(n-1)));
+ if(order > 0)
+ porder = FFMIN(porder, av_log2(n/order));
+ return porder;
+}
+
+static uint32_t calc_rice_params_fixed(RiceContext *rc, int pmin, int pmax,
+ int32_t *data, int n, int pred_order,
+ int bps)
+{
+ uint32_t bits;
+ pmin = get_max_p_order(pmin, n, pred_order);
+ pmax = get_max_p_order(pmax, n, pred_order);
+ bits = pred_order*bps + 6;
+ bits += calc_rice_params(rc, pmin, pmax, data, n, pred_order);
+ return bits;
+}
+
+static uint32_t calc_rice_params_lpc(RiceContext *rc, int pmin, int pmax,
+ int32_t *data, int n, int pred_order,
+ int bps, int precision)
+{
+ uint32_t bits;
+ pmin = get_max_p_order(pmin, n, pred_order);
+ pmax = get_max_p_order(pmax, n, pred_order);
+ bits = pred_order*bps + 4 + 5 + pred_order*precision + 6;
+ bits += calc_rice_params(rc, pmin, pmax, data, n, pred_order);
+ 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;
+
+ n2 = (len >> 1);
+ c = 2.0 / (len - 1.0);
+ for(i=0; i<n2; i++) {
+ w = c - i - 1.0;
+ w = 1.0 - (w * w);
+ w_data[i] = data[i] * w;
+ w_data[len-1-i] = data[len-1-i] * w;
+ }
+}
+
+/**
+ * Calculates autocorrelation data from audio samples
+ * A Welch window function is applied before calculation.
+ */
+static void compute_autocorr(const int32_t *data, int len, int lag,
+ double *autoc)
+{
+ int i, lag_ptr;
+ double tmp[len + lag];
+ double *data1= tmp + lag;
+
+ apply_welch_window(data, len, data1);
+
+ for(i=0; i<lag; i++){
+ autoc[i] = 1.0;
+ data1[i-lag]= 0.0;
+ }
+
+ for(i=0; i<len; i++){
+ for(lag_ptr= i-lag; lag_ptr<=i; lag_ptr++){
+ autoc[i-lag_ptr] += data1[i] * data1[lag_ptr];
+ }
+ }
+}
+
+/**
+ * Levinson-Durbin recursion.
+ * Produces LPC coefficients from autocorrelation data.
+ */
+static void compute_lpc_coefs(const double *autoc, int max_order,
+ double lpc[][MAX_LPC_ORDER], double *ref)
+{
+ int i, j, i2;
+ double r, err, tmp;
+ double lpc_tmp[MAX_LPC_ORDER];
+
+ for(i=0; i<max_order; i++) lpc_tmp[i] = 0;
+ err = autoc[0];
+
+ for(i=0; i<max_order; i++) {
+ r = -autoc[i+1];
+ for(j=0; j<i; j++) {
+ r -= lpc_tmp[j] * autoc[i-j];
+ }
+ r /= err;
+ ref[i] = fabs(r);
+
+ err *= 1.0 - (r * r);
+
+ i2 = (i >> 1);
+ lpc_tmp[i] = r;
+ for(j=0; j<i2; j++) {
+ tmp = lpc_tmp[j];
+ lpc_tmp[j] += r * lpc_tmp[i-1-j];
+ lpc_tmp[i-1-j] += r * tmp;
+ }
+ if(i & 1) {
+ lpc_tmp[j] += lpc_tmp[j] * r;
+ }
+
+ for(j=0; j<=i; j++) {
+ lpc[i][j] = -lpc_tmp[j];
+ }
+ }
+}
+
+/**
+ * Quantize LPC coefficients
+ */
+static void quantize_lpc_coefs(double *lpc_in, int order, int precision,
+ int32_t *lpc_out, int *shift)
+{
+ int i;
+ double cmax, error;
+ int32_t qmax;
+ int sh;
+
+ /* define maximum levels */
+ qmax = (1 << (precision - 1)) - 1;
+
+ /* find maximum coefficient value */
+ cmax = 0.0;
+ for(i=0; i<order; i++) {
+ cmax= FFMAX(cmax, fabs(lpc_in[i]));
+ }
+
+ /* if maximum value quantizes to zero, return all zeros */
+ if(cmax * (1 << MAX_LPC_SHIFT) < 1.0) {
+ *shift = 0;
+ memset(lpc_out, 0, sizeof(int32_t) * order);
+ return;
+ }
+
+ /* calculate level shift which scales max coeff to available bits */
+ sh = MAX_LPC_SHIFT;
+ while((cmax * (1 << sh) > qmax) && (sh > 0)) {
+ sh--;
+ }
+
+ /* since negative shift values are unsupported in decoder, scale down
+ coefficients instead */
+ if(sh == 0 && cmax > qmax) {
+ double scale = ((double)qmax) / cmax;
+ for(i=0; i<order; i++) {
+ lpc_in[i] *= scale;
+ }
+ }
+
+ /* output quantized coefficients and level shift */
+ error=0;
+ for(i=0; i<order; i++) {
+ error += lpc_in[i] * (1 << sh);
+ lpc_out[i] = av_clip(lrintf(error), -qmax, qmax);
+ error -= lpc_out[i];
+ }
+ *shift = sh;
+}
+
+static int estimate_best_order(double *ref, int max_order)
+{
+ int i, est;
+
+ est = 1;
+ for(i=max_order-1; i>=0; i--) {
+ if(ref[i] > 0.10) {
+ est = i+1;
+ break;
+ }
+ }
+ return est;
+}
+
+/**
+ * Calculate LPC coefficients for multiple orders
+ */
+static int lpc_calc_coefs(const int32_t *samples, int blocksize, int max_order,
+ int precision, int32_t coefs[][MAX_LPC_ORDER],
+ int *shift, int use_lpc, int omethod)
+{
+ double autoc[MAX_LPC_ORDER+1];
+ double ref[MAX_LPC_ORDER];
+ double lpc[MAX_LPC_ORDER][MAX_LPC_ORDER];
+ int i, j, pass;
+ int opt_order;
+
+ assert(max_order >= MIN_LPC_ORDER && max_order <= MAX_LPC_ORDER);
+
+ if(use_lpc == 1){
+ compute_autocorr(samples, blocksize, max_order+1, autoc);
+
+ compute_lpc_coefs(autoc, max_order, lpc, ref);
+ }else{
+ LLSModel m[2];
+ double var[MAX_LPC_ORDER+1], eval, weight;
+
+ for(pass=0; pass<use_lpc-1; pass++){
+ av_init_lls(&m[pass&1], max_order);
+
+ weight=0;
+ for(i=max_order; i<blocksize; i++){
+ for(j=0; j<=max_order; j++)
+ var[j]= samples[i-j];
+
+ if(pass){
+ eval= av_evaluate_lls(&m[(pass-1)&1], var+1, max_order-1);
+ eval= (512>>pass) + fabs(eval - var[0]);
+ for(j=0; j<=max_order; j++)
+ var[j]/= sqrt(eval);
+ weight += 1/eval;
+ }else
+ weight++;
+
+ av_update_lls(&m[pass&1], var, 1.0);
+ }
+ av_solve_lls(&m[pass&1], 0.001, 0);
+ }
+
+ for(i=0; i<max_order; i++){
+ for(j=0; j<max_order; j++)
+ lpc[i][j]= m[(pass-1)&1].coeff[i][j];
+ ref[i]= sqrt(m[(pass-1)&1].variance[i] / weight) * (blocksize - max_order) / 4000;
+ }
+ for(i=max_order-1; i>0; i--)
+ ref[i] = ref[i-1] - ref[i];
+ }
+ opt_order = max_order;
+
+ if(omethod == ORDER_METHOD_EST) {
+ opt_order = estimate_best_order(ref, max_order);
+ i = opt_order-1;
+ quantize_lpc_coefs(lpc[i], i+1, precision, coefs[i], &shift[i]);
+ } else {
+ for(i=0; i<max_order; i++) {
+ quantize_lpc_coefs(lpc[i], i+1, precision, coefs[i], &shift[i]);
+ }
+ }
+
+ return opt_order;
+}
+
+
+static void encode_residual_verbatim(int32_t *res, int32_t *smp, int n)
+{
+ assert(n > 0);
+ memcpy(res, smp, n * sizeof(int32_t));
+}
+
+static void encode_residual_fixed(int32_t *res, const int32_t *smp, int n,
+ int order)
+{
+ int i;
+
+ for(i=0; i<order; i++) {
+ res[i] = smp[i];
+ }
+
+ if(order==0){
+ for(i=order; i<n; i++)
+ res[i]= smp[i];
+ }else if(order==1){
+ for(i=order; i<n; i++)
+ res[i]= smp[i] - smp[i-1];
+ }else if(order==2){
+ for(i=order; i<n; i++)
+ res[i]= smp[i] - 2*smp[i-1] + smp[i-2];
+ }else if(order==3){
+ for(i=order; i<n; i++)
+ res[i]= smp[i] - 3*smp[i-1] + 3*smp[i-2] - smp[i-3];
+ }else{
+ for(i=order; i<n; i++)
+ res[i]= smp[i] - 4*smp[i-1] + 6*smp[i-2] - 4*smp[i-3] + smp[i-4];
+ }
+}
+
+static void encode_residual_lpc(int32_t *res, const int32_t *smp, int n,
+ int order, const int32_t *coefs, int shift)
+{
+ int i, j;
+ int32_t pred;
+
+ for(i=0; i<order; i++) {
+ res[i] = smp[i];
+ }
+ for(i=order; i<n; i++) {
+ pred = 0;
+ for(j=0; j<order; j++) {
+ pred += coefs[j] * smp[i-j-1];
+ }
+ res[i] = smp[i] - (pred >> shift);
+ }
+}
+
+static int encode_residual(FlacEncodeContext *ctx, int ch)
+{
+ int i, n;
+ int min_order, max_order, opt_order, precision, omethod;
+ int min_porder, max_porder;
+ FlacFrame *frame;
+ FlacSubframe *sub;
+ int32_t coefs[MAX_LPC_ORDER][MAX_LPC_ORDER];
+ int shift[MAX_LPC_ORDER];
+ int32_t *res, *smp;
+
+ frame = &ctx->frame;
+ sub = &frame->subframes[ch];
+ res = sub->residual;
+ smp = sub->samples;
+ n = frame->blocksize;
+
+ /* CONSTANT */
+ for(i=1; i<n; i++) {
+ if(smp[i] != smp[0]) break;
+ }
+ if(i == n) {
+ sub->type = sub->type_code = FLAC_SUBFRAME_CONSTANT;
+ res[0] = smp[0];
+ return sub->obits;
+ }
+
+ /* VERBATIM */
+ if(n < 5) {
+ sub->type = sub->type_code = FLAC_SUBFRAME_VERBATIM;
+ encode_residual_verbatim(res, smp, n);
+ return sub->obits * n;
+ }
+
+ min_order = ctx->options.min_prediction_order;
+ max_order = ctx->options.max_prediction_order;
+ min_porder = ctx->options.min_partition_order;
+ max_porder = ctx->options.max_partition_order;
+ precision = ctx->options.lpc_coeff_precision;
+ omethod = ctx->options.prediction_order_method;
+
+ /* FIXED */
+ if(!ctx->options.use_lpc || max_order == 0 || (n <= max_order)) {
+ uint32_t bits[MAX_FIXED_ORDER+1];
+ if(max_order > MAX_FIXED_ORDER) max_order = MAX_FIXED_ORDER;
+ opt_order = 0;
+ bits[0] = UINT32_MAX;
+ for(i=min_order; i<=max_order; i++) {
+ encode_residual_fixed(res, smp, n, i);
+ bits[i] = calc_rice_params_fixed(&sub->rc, min_porder, max_porder, res,
+ n, i, sub->obits);
+ if(bits[i] < bits[opt_order]) {
+ opt_order = i;
+ }
+ }
+ sub->order = opt_order;
+ sub->type = FLAC_SUBFRAME_FIXED;
+ sub->type_code = sub->type | sub->order;
+ if(sub->order != max_order) {
+ encode_residual_fixed(res, smp, n, sub->order);
+ return calc_rice_params_fixed(&sub->rc, min_porder, max_porder, res, n,
+ sub->order, sub->obits);
+ }
+ return bits[sub->order];
+ }
+
+ /* LPC */
+ opt_order = lpc_calc_coefs(smp, n, max_order, precision, coefs, shift, ctx->options.use_lpc, omethod);
+
+ if(omethod == ORDER_METHOD_2LEVEL ||
+ omethod == ORDER_METHOD_4LEVEL ||
+ omethod == ORDER_METHOD_8LEVEL) {
+ int levels = 1 << omethod;
+ uint32_t bits[levels];
+ int order;
+ int opt_index = levels-1;
+ opt_order = max_order-1;
+ bits[opt_index] = UINT32_MAX;
+ for(i=levels-1; i>=0; i--) {
+ order = min_order + (((max_order-min_order+1) * (i+1)) / levels)-1;
+ if(order < 0) order = 0;
+ encode_residual_lpc(res, smp, n, order+1, coefs[order], shift[order]);
+ bits[i] = calc_rice_params_lpc(&sub->rc, min_porder, max_porder,
+ res, n, order+1, sub->obits, precision);
+ if(bits[i] < bits[opt_index]) {
+ opt_index = i;
+ opt_order = order;
+ }
+ }
+ opt_order++;
+ } else if(omethod == ORDER_METHOD_SEARCH) {
+ // brute-force optimal order search
+ uint32_t bits[MAX_LPC_ORDER];
+ opt_order = 0;
+ bits[0] = UINT32_MAX;
+ for(i=min_order-1; i<max_order; i++) {
+ encode_residual_lpc(res, smp, n, i+1, coefs[i], shift[i]);
+ bits[i] = calc_rice_params_lpc(&sub->rc, min_porder, max_porder,
+ res, n, i+1, sub->obits, precision);
+ if(bits[i] < bits[opt_order]) {
+ opt_order = i;
+ }
+ }
+ opt_order++;
+ } else if(omethod == ORDER_METHOD_LOG) {
+ uint32_t bits[MAX_LPC_ORDER];
+ int step;
+
+ opt_order= min_order - 1 + (max_order-min_order)/3;
+ memset(bits, -1, sizeof(bits));
+
+ for(step=16 ;step; step>>=1){
+ int last= opt_order;
+ for(i=last-step; i<=last+step; i+= step){
+ if(i<min_order-1 || i>=max_order || bits[i] < UINT32_MAX)
+ continue;
+ encode_residual_lpc(res, smp, n, i+1, coefs[i], shift[i]);
+ bits[i] = calc_rice_params_lpc(&sub->rc, min_porder, max_porder,
+ res, n, i+1, sub->obits, precision);
+ if(bits[i] < bits[opt_order])
+ opt_order= i;
+ }
+ }
+ opt_order++;
+ }
+
+ sub->order = opt_order;
+ sub->type = FLAC_SUBFRAME_LPC;
+ sub->type_code = sub->type | (sub->order-1);
+ sub->shift = shift[sub->order-1];
+ for(i=0; i<sub->order; i++) {
+ sub->coefs[i] = coefs[sub->order-1][i];
+ }
+ encode_residual_lpc(res, smp, n, sub->order, sub->coefs, sub->shift);
+ return calc_rice_params_lpc(&sub->rc, min_porder, max_porder, res, n, sub->order,
+ sub->obits, precision);
+}
+
+static int encode_residual_v(FlacEncodeContext *ctx, int ch)
+{
+ int i, n;
+ FlacFrame *frame;
+ FlacSubframe *sub;
+ int32_t *res, *smp;
+
+ frame = &ctx->frame;
+ sub = &frame->subframes[ch];
+ res = sub->residual;
+ smp = sub->samples;
+ n = frame->blocksize;
+
+ /* CONSTANT */
+ for(i=1; i<n; i++) {
+ if(smp[i] != smp[0]) break;
+ }
+ if(i == n) {
+ sub->type = sub->type_code = FLAC_SUBFRAME_CONSTANT;
+ res[0] = smp[0];
+ return sub->obits;
+ }
+
+ /* VERBATIM */
+ sub->type = sub->type_code = FLAC_SUBFRAME_VERBATIM;
+ encode_residual_verbatim(res, smp, n);
+ return sub->obits * n;
+}
+
+static int estimate_stereo_mode(int32_t *left_ch, int32_t *right_ch, int n)
+{
+ int i, best;
+ int32_t lt, rt;
+ uint64_t sum[4];
+ uint64_t score[4];
+ int k;
+
+ /* calculate sum of 2nd order residual for each channel */
+ sum[0] = sum[1] = sum[2] = sum[3] = 0;
+ for(i=2; i<n; i++) {
+ lt = left_ch[i] - 2*left_ch[i-1] + left_ch[i-2];
+ rt = right_ch[i] - 2*right_ch[i-1] + right_ch[i-2];
+ sum[2] += FFABS((lt + rt) >> 1);
+ sum[3] += FFABS(lt - rt);
+ sum[0] += FFABS(lt);
+ sum[1] += FFABS(rt);
+ }
+ /* estimate bit counts */
+ for(i=0; i<4; i++) {
+ k = find_optimal_param(2*sum[i], n);
+ sum[i] = rice_encode_count(2*sum[i], n, k);
+ }
+
+ /* calculate score for each mode */
+ score[0] = sum[0] + sum[1];
+ score[1] = sum[0] + sum[3];
+ score[2] = sum[1] + sum[3];
+ score[3] = sum[2] + sum[3];
+
+ /* return mode with lowest score */
+ best = 0;
+ for(i=1; i<4; i++) {
+ if(score[i] < score[best]) {
+ best = i;
+ }
+ }
+ if(best == 0) {
+ return FLAC_CHMODE_LEFT_RIGHT;
+ } else if(best == 1) {
+ return FLAC_CHMODE_LEFT_SIDE;
+ } else if(best == 2) {
+ return FLAC_CHMODE_RIGHT_SIDE;
+ } else {
+ return FLAC_CHMODE_MID_SIDE;
+ }
+}
+
+/**
+ * Perform stereo channel decorrelation
+ */
+static void channel_decorrelation(FlacEncodeContext *ctx)
+{
+ FlacFrame *frame;
+ int32_t *left, *right;
+ int i, n;
+
+ frame = &ctx->frame;
+ n = frame->blocksize;
+ left = frame->subframes[0].samples;
+ right = frame->subframes[1].samples;
+
+ if(ctx->channels != 2) {
+ frame->ch_mode = FLAC_CHMODE_NOT_STEREO;
+ return;
+ }
+
+ frame->ch_mode = estimate_stereo_mode(left, right, n);
+
+ /* perform decorrelation and adjust bits-per-sample */
+ if(frame->ch_mode == FLAC_CHMODE_LEFT_RIGHT) {
+ return;
+ }
+ if(frame->ch_mode == FLAC_CHMODE_MID_SIDE) {
+ int32_t tmp;
+ for(i=0; i<n; i++) {
+ tmp = left[i];
+ left[i] = (tmp + right[i]) >> 1;
+ right[i] = tmp - right[i];
+ }
+ frame->subframes[1].obits++;
+ } else if(frame->ch_mode == FLAC_CHMODE_LEFT_SIDE) {
+ for(i=0; i<n; i++) {
+ right[i] = left[i] - right[i];
+ }
+ frame->subframes[1].obits++;
+ } else {
+ for(i=0; i<n; i++) {
+ left[i] -= right[i];
+ }
+ frame->subframes[0].obits++;
+ }
+}
+
+static void put_sbits(PutBitContext *pb, int bits, int32_t val)
+{
+ assert(bits >= 0 && bits <= 31);
+
+ put_bits(pb, bits, val & ((1<<bits)-1));
+}
+
+static void write_utf8(PutBitContext *pb, uint32_t val)
+{
+ uint8_t tmp;
+ PUT_UTF8(val, tmp, put_bits(pb, 8, tmp);)
+}
+
+static void output_frame_header(FlacEncodeContext *s)
+{
+ FlacFrame *frame;
+ int crc;
+
+ frame = &s->frame;
+
+ put_bits(&s->pb, 16, 0xFFF8);
+ put_bits(&s->pb, 4, frame->bs_code[0]);
+ put_bits(&s->pb, 4, s->sr_code[0]);
+ if(frame->ch_mode == FLAC_CHMODE_NOT_STEREO) {
+ put_bits(&s->pb, 4, s->ch_code);
+ } else {
+ put_bits(&s->pb, 4, frame->ch_mode);
+ }
+ put_bits(&s->pb, 3, 4); /* bits-per-sample code */
+ put_bits(&s->pb, 1, 0);
+ write_utf8(&s->pb, s->frame_count);
+ if(frame->bs_code[0] == 6) {
+ put_bits(&s->pb, 8, frame->bs_code[1]);
+ } else if(frame->bs_code[0] == 7) {
+ put_bits(&s->pb, 16, frame->bs_code[1]);
+ }
+ if(s->sr_code[0] == 12) {
+ put_bits(&s->pb, 8, s->sr_code[1]);
+ } else if(s->sr_code[0] > 12) {
+ put_bits(&s->pb, 16, s->sr_code[1]);
+ }
+ flush_put_bits(&s->pb);
+ crc = av_crc(av_crc07, 0, s->pb.buf, put_bits_count(&s->pb)>>3);
+ put_bits(&s->pb, 8, crc);
+}
+
+static void output_subframe_constant(FlacEncodeContext *s, int ch)
+{
+ FlacSubframe *sub;
+ int32_t res;
+
+ sub = &s->frame.subframes[ch];
+ res = sub->residual[0];
+ put_sbits(&s->pb, sub->obits, res);
+}
+
+static void output_subframe_verbatim(FlacEncodeContext *s, int ch)
+{
+ int i;
+ FlacFrame *frame;
+ FlacSubframe *sub;
+ int32_t res;
+
+ frame = &s->frame;
+ sub = &frame->subframes[ch];
+
+ for(i=0; i<frame->blocksize; i++) {
+ res = sub->residual[i];
+ put_sbits(&s->pb, sub->obits, res);
+ }
+}
+
+static void output_residual(FlacEncodeContext *ctx, int ch)
+{
+ int i, j, p, n, parts;
+ int k, porder, psize, res_cnt;
+ FlacFrame *frame;
+ FlacSubframe *sub;
+ int32_t *res;
+
+ frame = &ctx->frame;
+ sub = &frame->subframes[ch];
+ res = sub->residual;
+ n = frame->blocksize;
+
+ /* rice-encoded block */
+ put_bits(&ctx->pb, 2, 0);
+
+ /* partition order */
+ porder = sub->rc.porder;
+ psize = n >> porder;
+ parts = (1 << porder);
+ put_bits(&ctx->pb, 4, porder);
+ res_cnt = psize - sub->order;
+
+ /* residual */
+ j = sub->order;
+ for(p=0; p<parts; p++) {
+ k = sub->rc.params[p];
+ put_bits(&ctx->pb, 4, k);
+ if(p == 1) res_cnt = psize;
+ for(i=0; i<res_cnt && j<n; i++, j++) {
+ set_sr_golomb_flac(&ctx->pb, res[j], k, INT32_MAX, 0);
+ }
+ }
+}
+
+static void output_subframe_fixed(FlacEncodeContext *ctx, int ch)
+{
+ int i;
+ FlacFrame *frame;
+ FlacSubframe *sub;
+
+ frame = &ctx->frame;
+ sub = &frame->subframes[ch];
+
+ /* warm-up samples */
+ for(i=0; i<sub->order; i++) {
+ put_sbits(&ctx->pb, sub->obits, sub->residual[i]);
+ }
+
+ /* residual */
+ output_residual(ctx, ch);
+}
+
+static void output_subframe_lpc(FlacEncodeContext *ctx, int ch)
+{
+ int i, cbits;
+ FlacFrame *frame;
+ FlacSubframe *sub;
+
+ frame = &ctx->frame;
+ sub = &frame->subframes[ch];
+
+ /* warm-up samples */
+ for(i=0; i<sub->order; i++) {
+ put_sbits(&ctx->pb, sub->obits, sub->residual[i]);
+ }
+
+ /* LPC coefficients */
+ cbits = ctx->options.lpc_coeff_precision;
+ put_bits(&ctx->pb, 4, cbits-1);
+ put_sbits(&ctx->pb, 5, sub->shift);
+ for(i=0; i<sub->order; i++) {
+ put_sbits(&ctx->pb, cbits, sub->coefs[i]);
+ }
+
+ /* residual */
+ output_residual(ctx, ch);
+}
+
+static void output_subframes(FlacEncodeContext *s)
+{
+ FlacFrame *frame;
+ FlacSubframe *sub;
+ int ch;
+
+ frame = &s->frame;
+
+ for(ch=0; ch<s->channels; ch++) {
+ sub = &frame->subframes[ch];
+
+ /* subframe header */
+ put_bits(&s->pb, 1, 0);
+ put_bits(&s->pb, 6, sub->type_code);
+ put_bits(&s->pb, 1, 0); /* no wasted bits */
+
+ /* subframe */
+ if(sub->type == FLAC_SUBFRAME_CONSTANT) {
+ output_subframe_constant(s, ch);
+ } else if(sub->type == FLAC_SUBFRAME_VERBATIM) {
+ output_subframe_verbatim(s, ch);
+ } else if(sub->type == FLAC_SUBFRAME_FIXED) {
+ output_subframe_fixed(s, ch);
+ } else if(sub->type == FLAC_SUBFRAME_LPC) {
+ output_subframe_lpc(s, ch);
+ }
+ }
+}
+
+static void output_frame_footer(FlacEncodeContext *s)
+{
+ int crc;
+ flush_put_bits(&s->pb);
+ crc = bswap_16(av_crc(av_crc8005, 0, s->pb.buf, put_bits_count(&s->pb)>>3));
+ put_bits(&s->pb, 16, crc);
+ flush_put_bits(&s->pb);
+}
+
+static int flac_encode_frame(AVCodecContext *avctx, uint8_t *frame,
+ int buf_size, void *data)
+{
+ int ch;
+ FlacEncodeContext *s;
+ int16_t *samples = data;
+ int out_bytes;
+
+ s = avctx->priv_data;
+
+ s->blocksize = avctx->frame_size;
+ init_frame(s);
+
+ copy_samples(s, samples);
+
+ channel_decorrelation(s);
+
+ for(ch=0; ch<s->channels; ch++) {
+ encode_residual(s, ch);
+ }
+ init_put_bits(&s->pb, frame, buf_size);
+ output_frame_header(s);
+ output_subframes(s);
+ output_frame_footer(s);
+ out_bytes = put_bits_count(&s->pb) >> 3;
+
+ if(out_bytes > s->max_framesize || out_bytes >= buf_size) {
+ /* frame too large. use verbatim mode */
+ for(ch=0; ch<s->channels; ch++) {
+ encode_residual_v(s, ch);
+ }
+ init_put_bits(&s->pb, frame, buf_size);
+ output_frame_header(s);
+ output_subframes(s);
+ output_frame_footer(s);
+ out_bytes = put_bits_count(&s->pb) >> 3;
+
+ if(out_bytes > s->max_framesize || out_bytes >= buf_size) {
+ /* still too large. must be an error. */
+ av_log(avctx, AV_LOG_ERROR, "error encoding frame\n");
+ return -1;
+ }
+ }
+
+ s->frame_count++;
+ return out_bytes;
+}
+
+static int flac_encode_close(AVCodecContext *avctx)
+{
+ av_freep(&avctx->extradata);
+ avctx->extradata_size = 0;
+ av_freep(&avctx->coded_frame);
+ return 0;
+}
+
+AVCodec flac_encoder = {
+ "flac",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_FLAC,
+ sizeof(FlacEncodeContext),
+ flac_encode_init,
+ flac_encode_frame,
+ flac_encode_close,
+ NULL,
+ .capabilities = CODEC_CAP_SMALL_LAST_FRAME,
+};
diff --git a/src/libffmpeg/libavcodec/flashsv.c b/contrib/ffmpeg/libavcodec/flashsv.c
index 9e4aa951a..9e4aa951a 100644
--- a/src/libffmpeg/libavcodec/flashsv.c
+++ b/contrib/ffmpeg/libavcodec/flashsv.c
diff --git a/contrib/ffmpeg/libavcodec/flashsvenc.c b/contrib/ffmpeg/libavcodec/flashsvenc.c
new file mode 100644
index 000000000..cbf488328
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/flashsvenc.c
@@ -0,0 +1,346 @@
+/*
+ * Flash Screen Video encoder
+ * Copyright (C) 2004 Alex Beregszaszi
+ * Copyright (C) 2006 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
+ */
+
+/* Encoding development sponsored by http://fh-campuswien.ac.at */
+
+/**
+ * @file flashsvenc.c
+ * Flash Screen Video encoder
+ * @author Alex Beregszaszi
+ * @author Benjamin Larsson
+ */
+
+/* Bitstream description
+ * The picture is divided into blocks that are zlib-compressed.
+ *
+ * The decoder is fed complete frames, the frameheader contains:
+ * 4bits of block width
+ * 12bits of frame width
+ * 4bits of block height
+ * 12bits of frame height
+ *
+ * Directly after the header are the compressed blocks. The blocks
+ * have their compressed size represented with 16bits in the beginig.
+ * If the size = 0 then the block is unchanged from the previous frame.
+ * All blocks are decompressed until the buffer is consumed.
+ *
+ * Encoding ideas, a basic encoder would just use a fixed block size.
+ * Block sizes can be multipels of 16, from 16 to 256. The blocks don't
+ * have to be quadratic. A brute force search with a set of different
+ * block sizes should give a better result than to just use a fixed size.
+ */
+
+/* TODO:
+ * Don't reencode the frame in brute force mode if the frame is a dupe. Speed up.
+ * Make the difference check faster.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <zlib.h>
+
+#include "common.h"
+#include "avcodec.h"
+#include "bitstream.h"
+#include "bytestream.h"
+
+
+typedef struct FlashSVContext {
+ AVCodecContext *avctx;
+ uint8_t *previous_frame;
+ AVFrame frame;
+ int image_width, image_height;
+ int block_width, block_height;
+ uint8_t* tmpblock;
+ uint8_t* encbuffer;
+ int block_size;
+ z_stream zstream;
+ int last_key_frame;
+} FlashSVContext;
+
+static int copy_region_enc(uint8_t *sptr, uint8_t *dptr,
+ int dx, int dy, int h, int w, int stride, uint8_t *pfptr) {
+ int i,j;
+ uint8_t *nsptr;
+ uint8_t *npfptr;
+ int diff = 0;
+
+ for (i = dx+h; i > dx; i--) {
+ nsptr = sptr+(i*stride)+dy*3;
+ npfptr = pfptr+(i*stride)+dy*3;
+ for (j=0 ; j<w*3 ; j++) {
+ diff |=npfptr[j]^nsptr[j];
+ dptr[j] = nsptr[j];
+ }
+ dptr += w*3;
+ }
+ if (diff)
+ return 1;
+ return 0;
+}
+
+static int flashsv_encode_init(AVCodecContext *avctx)
+{
+ FlashSVContext *s = (FlashSVContext *)avctx->priv_data;
+
+ s->avctx = avctx;
+
+ if ((avctx->width > 4095) || (avctx->height > 4095)) {
+ av_log(avctx, AV_LOG_ERROR, "Input dimensions too large, input must be max 4096x4096 !\n");
+ 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));
+/*
+ s->zstream.zalloc = NULL; //av_malloc;
+ s->zstream.zfree = NULL; //av_free;
+ s->zstream.opaque = NULL;
+ zret = deflateInit(&(s->zstream), 9);
+ if (zret != Z_OK) {
+ av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
+ return -1;
+ }
+*/
+
+ s->last_key_frame=0;
+
+ s->image_width = avctx->width;
+ s->image_height = avctx->height;
+
+ s->tmpblock = av_mallocz(3*256*256);
+ s->encbuffer = av_mallocz(s->image_width*s->image_height*3);
+
+ if (!s->tmpblock || !s->encbuffer) {
+ av_log(avctx, AV_LOG_ERROR, "Memory allocation failed.\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+
+static int encode_bitstream(FlashSVContext *s, AVFrame *p, uint8_t *buf, int buf_size,
+ int block_width, int block_height, uint8_t *previous_frame, int* I_frame) {
+
+ PutBitContext pb;
+ int h_blocks, v_blocks, h_part, v_part, i, j;
+ int buf_pos, res;
+ int pred_blocks = 0;
+
+ init_put_bits(&pb, buf, buf_size*8);
+
+ put_bits(&pb, 4, (block_width/16)-1);
+ put_bits(&pb, 12, s->image_width);
+ put_bits(&pb, 4, (block_height/16)-1);
+ put_bits(&pb, 12, s->image_height);
+ flush_put_bits(&pb);
+ buf_pos=4;
+
+ h_blocks = s->image_width / block_width;
+ h_part = s->image_width % block_width;
+ v_blocks = s->image_height / block_height;
+ v_part = s->image_height % block_height;
+
+ /* loop over all block columns */
+ for (j = 0; j < v_blocks + (v_part?1:0); j++)
+ {
+
+ int hp = j*block_height; // horiz position in frame
+ int hs = (j<v_blocks)?block_height:v_part; // size of block
+
+ /* loop over all block rows */
+ for (i = 0; i < h_blocks + (h_part?1:0); i++)
+ {
+ int wp = i*block_width; // vert position in frame
+ int ws = (i<h_blocks)?block_width:h_part; // size of block
+ int ret=Z_OK;
+ uint8_t *ptr;
+
+ ptr = buf+buf_pos;
+
+ //copy the block to the temp buffer before compression (if it differs from the previous frame's block)
+ res = copy_region_enc(p->data[0], s->tmpblock, s->image_height-(hp+hs+1), wp, hs, ws, p->linesize[0], previous_frame);
+
+ if (res || *I_frame) {
+ unsigned long zsize;
+ zsize = 3*block_width*block_height;
+ ret = compress2(ptr+2, &zsize, s->tmpblock, 3*ws*hs, 9);
+
+
+ //ret = deflateReset(&(s->zstream));
+ if (ret != Z_OK)
+ av_log(s->avctx, AV_LOG_ERROR, "error while compressing block %dx%d\n", i, j);
+ /*
+ s->zstream.next_in = s->tmpblock;
+ s->zstream.avail_in = 3*ws*hs;
+ s->zstream.total_in = 0;
+
+ s->zstream.next_out = ptr+2;
+ s->zstream.avail_out = buf_size-buf_pos-2;
+ s->zstream.total_out = 0;
+
+ ret = deflate(&(s->zstream), Z_FINISH);
+ if ((ret != Z_OK) && (ret != Z_STREAM_END))
+ av_log(s->avctx, AV_LOG_ERROR, "error while compressing block %dx%d\n", i, j);
+
+ size = s->zstream.total_out;
+ //av_log(avctx, AV_LOG_INFO, "compressed blocks: %d\n", size);
+ */
+ bytestream_put_be16(&ptr,(unsigned int)zsize);
+ buf_pos += zsize+2;
+ //av_log(avctx, AV_LOG_ERROR, "buf_pos = %d\n", buf_pos);
+ } else {
+ pred_blocks++;
+ bytestream_put_be16(&ptr,0);
+ buf_pos += 2;
+ }
+ }
+ }
+
+ if (pred_blocks)
+ *I_frame = 0;
+ else
+ *I_frame = 1;
+
+ return buf_pos;
+}
+
+
+static int flashsv_encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_size, void *data)
+{
+ FlashSVContext * const s = (FlashSVContext *)avctx->priv_data;
+ AVFrame *pict = data;
+ AVFrame * const p = &s->frame;
+ int res;
+ int I_frame = 0;
+ int opt_w, opt_h;
+
+ *p = *pict;
+
+ /* First frame needs to be a keyframe */
+ if (avctx->frame_number == 0) {
+ s->previous_frame = av_mallocz(p->linesize[0]*s->image_height);
+ if (!s->previous_frame) {
+ av_log(avctx, AV_LOG_ERROR, "Memory allocation failed.\n");
+ return -1;
+ }
+ I_frame = 1;
+ }
+
+ /* Check the placement of keyframes */
+ if (avctx->gop_size > 0) {
+ if (avctx->frame_number >= s->last_key_frame + avctx->gop_size) {
+ I_frame = 1;
+ }
+ }
+
+#if 0
+ int w, h;
+ int optim_sizes[16][16];
+ int smallest_size;
+ //Try all possible combinations and store the encoded frame sizes
+ for (w=1 ; w<17 ; w++) {
+ for (h=1 ; h<17 ; h++) {
+ optim_sizes[w-1][h-1] = encode_bitstream(s, p, s->encbuffer, s->image_width*s->image_height*4, w*16, h*16, s->previous_frame);
+ //av_log(avctx, AV_LOG_ERROR, "[%d][%d]size = %d\n",w,h,optim_sizes[w-1][h-1]);
+ }
+ }
+
+ //Search for the smallest framesize and encode the frame with those parameters
+ smallest_size=optim_sizes[0][0];
+ opt_w = 0;
+ opt_h = 0;
+ for (w=0 ; w<16 ; w++) {
+ for (h=0 ; h<16 ; h++) {
+ if (optim_sizes[w][h] < smallest_size) {
+ smallest_size = optim_sizes[w][h];
+ opt_w = w;
+ opt_h = h;
+ }
+ }
+ }
+ res = encode_bitstream(s, p, buf, buf_size, (opt_w+1)*16, (opt_h+1)*16, s->previous_frame);
+ av_log(avctx, AV_LOG_ERROR, "[%d][%d]optimal size = %d, res = %d|\n", opt_w, opt_h, smallest_size, res);
+
+ if (buf_size < res)
+ av_log(avctx, AV_LOG_ERROR, "buf_size %d < res %d\n", buf_size, res);
+
+#else
+ opt_w=1;
+ opt_h=1;
+
+ if (buf_size < s->image_width*s->image_height*3) {
+ //Conservative upper bound check for compressed data
+ av_log(avctx, AV_LOG_ERROR, "buf_size %d < %d\n", buf_size, s->image_width*s->image_height*3);
+ return -1;
+ }
+
+ res = encode_bitstream(s, p, buf, buf_size, opt_w*16, opt_h*16, s->previous_frame, &I_frame);
+#endif
+ //save the current frame
+ memcpy(s->previous_frame, p->data[0], s->image_height*p->linesize[0]);
+
+ //mark the frame type so the muxer can mux it correctly
+ if (I_frame) {
+ p->pict_type = FF_I_TYPE;
+ p->key_frame = 1;
+ s->last_key_frame = avctx->frame_number;
+ av_log(avctx, AV_LOG_DEBUG, "Inserting key frame at frame %d\n",avctx->frame_number);
+ } else {
+ p->pict_type = FF_P_TYPE;
+ p->key_frame = 0;
+ }
+
+ avctx->coded_frame = p;
+
+ return res;
+}
+
+static int flashsv_encode_end(AVCodecContext *avctx)
+{
+ FlashSVContext *s = (FlashSVContext *)avctx->priv_data;
+
+ deflateEnd(&(s->zstream));
+
+ av_free(s->encbuffer);
+ av_free(s->previous_frame);
+ av_free(s->tmpblock);
+
+ return 0;
+}
+
+AVCodec flashsv_encoder = {
+ "flashsv",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_FLASHSV,
+ sizeof(FlashSVContext),
+ flashsv_encode_init,
+ flashsv_encode_frame,
+ flashsv_encode_end,
+ .pix_fmts = (enum PixelFormat[]){PIX_FMT_BGR24, -1},
+};
+
diff --git a/contrib/ffmpeg/libavcodec/flicvideo.c b/contrib/ffmpeg/libavcodec/flicvideo.c
new file mode 100644
index 000000000..b60e0b1c2
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/flicvideo.c
@@ -0,0 +1,754 @@
+/*
+ * FLI/FLC Animation Video Decoder
+ * Copyright (C) 2003, 2004 the ffmpeg project
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * @file flic.c
+ * 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
+ * variations, visit:
+ * http://www.compuphase.com/flic.htm
+ *
+ * This decoder outputs PAL8/RGB555/RGB565 and maybe one day RGB24
+ * colorspace data, depending on the FLC. To use this decoder, be
+ * sure that your demuxer sends the FLI file header to the decoder via
+ * the extradata chunk in AVCodecContext. The chunk should be 128 bytes
+ * large. The only exception is for FLI files from the game "Magic Carpet",
+ * in which the header is only 12 bytes.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "common.h"
+#include "avcodec.h"
+#include "bswap.h"
+
+#define FLI_256_COLOR 4
+#define FLI_DELTA 7
+#define FLI_COLOR 11
+#define FLI_LC 12
+#define FLI_BLACK 13
+#define FLI_BRUN 15
+#define FLI_COPY 16
+#define FLI_MINI 18
+#define FLI_DTA_BRUN 25
+#define FLI_DTA_COPY 26
+#define FLI_DTA_LC 27
+
+#define FLI_TYPE_CODE (0xAF11)
+#define FLC_FLX_TYPE_CODE (0xAF12)
+#define FLC_DTA_TYPE_CODE (0xAF44) /* Marks an "Extended FLC" comes from Dave's Targa Animator (DTA) */
+#define FLC_MAGIC_CARPET_SYNTHETIC_TYPE_CODE (0xAF13)
+
+#define CHECK_PIXEL_PTR(n) \
+ if (pixel_ptr + n > pixel_limit) { \
+ av_log (s->avctx, AV_LOG_INFO, "Problem: pixel_ptr >= pixel_limit (%d >= %d)\n", \
+ pixel_ptr + n, pixel_limit); \
+ return -1; \
+ } \
+
+typedef struct FlicDecodeContext {
+ AVCodecContext *avctx;
+ AVFrame frame;
+
+ unsigned int palette[256];
+ int new_palette;
+ int fli_type; /* either 0xAF11 or 0xAF12, affects palette resolution */
+} FlicDecodeContext;
+
+static int flic_decode_init(AVCodecContext *avctx)
+{
+ FlicDecodeContext *s = (FlicDecodeContext *)avctx->priv_data;
+ unsigned char *fli_header = (unsigned char *)avctx->extradata;
+ int depth;
+
+ s->avctx = avctx;
+ avctx->has_b_frames = 0;
+
+ s->fli_type = AV_RL16(&fli_header[4]); /* Might be overridden if a Magic Carpet FLC */
+ depth = AV_RL16(&fli_header[12]);
+
+ if (depth == 0) {
+ depth = 8; /* Some FLC generators set depth to zero, when they mean 8Bpp. Fix up here */
+ }
+
+ if (s->avctx->extradata_size == 12) {
+ /* special case for magic carpet FLIs */
+ s->fli_type = FLC_MAGIC_CARPET_SYNTHETIC_TYPE_CODE;
+ } else if (s->avctx->extradata_size != 128) {
+ av_log(avctx, AV_LOG_ERROR, "Expected extradata of 12 or 128 bytes\n");
+ return -1;
+ }
+
+ if ((s->fli_type == FLC_FLX_TYPE_CODE) && (depth == 16)) {
+ depth = 15; /* Original Autodesk FLX's say the depth is 16Bpp when it is really 15Bpp */
+ }
+
+ switch (depth) {
+ case 8 : avctx->pix_fmt = PIX_FMT_PAL8; break;
+ case 15 : avctx->pix_fmt = PIX_FMT_RGB555; break;
+ case 16 : avctx->pix_fmt = PIX_FMT_RGB565; break;
+ case 24 : avctx->pix_fmt = PIX_FMT_BGR24; /* Supposedly BGR, but havent any files to test with */
+ av_log(avctx, AV_LOG_ERROR, "24Bpp FLC/FLX is unsupported due to no test files.\n");
+ return -1;
+ break;
+ default :
+ av_log(avctx, AV_LOG_ERROR, "Unknown FLC/FLX depth of %d Bpp is unsupported.\n",depth);
+ return -1;
+ }
+
+ s->frame.data[0] = NULL;
+ s->new_palette = 0;
+
+ return 0;
+}
+
+static int flic_decode_frame_8BPP(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ FlicDecodeContext *s = (FlicDecodeContext *)avctx->priv_data;
+
+ int stream_ptr = 0;
+ int stream_ptr_after_color_chunk;
+ int pixel_ptr;
+ int palette_ptr;
+ unsigned char palette_idx1;
+ unsigned char palette_idx2;
+
+ unsigned int frame_size;
+ int num_chunks;
+
+ unsigned int chunk_size;
+ int chunk_type;
+
+ int i, j;
+
+ int color_packets;
+ int color_changes;
+ int color_shift;
+ unsigned char r, g, b;
+
+ int lines;
+ int compressed_lines;
+ int starting_line;
+ signed short line_packets;
+ int y_ptr;
+ int byte_run;
+ int pixel_skip;
+ int pixel_countdown;
+ unsigned char *pixels;
+ int pixel_limit;
+
+ s->frame.reference = 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;
+ }
+
+ pixels = s->frame.data[0];
+ pixel_limit = s->avctx->height * s->frame.linesize[0];
+
+ frame_size = AV_RL32(&buf[stream_ptr]);
+ stream_ptr += 6; /* skip the magic number */
+ num_chunks = AV_RL16(&buf[stream_ptr]);
+ stream_ptr += 10; /* skip padding */
+
+ frame_size -= 16;
+
+ /* iterate through the chunks */
+ while ((frame_size > 0) && (num_chunks > 0)) {
+ chunk_size = AV_RL32(&buf[stream_ptr]);
+ stream_ptr += 4;
+ chunk_type = AV_RL16(&buf[stream_ptr]);
+ stream_ptr += 2;
+
+ switch (chunk_type) {
+ case FLI_256_COLOR:
+ case FLI_COLOR:
+ stream_ptr_after_color_chunk = stream_ptr + chunk_size - 6;
+
+ /* check special case: If this file is from the Magic Carpet
+ * game and uses 6-bit colors even though it reports 256-color
+ * chunks in a 0xAF12-type file (fli_type is set to 0xAF13 during
+ * initialization) */
+ if ((chunk_type == FLI_256_COLOR) && (s->fli_type != FLC_MAGIC_CARPET_SYNTHETIC_TYPE_CODE))
+ color_shift = 0;
+ else
+ color_shift = 2;
+ /* set up the palette */
+ color_packets = AV_RL16(&buf[stream_ptr]);
+ stream_ptr += 2;
+ palette_ptr = 0;
+ for (i = 0; i < color_packets; i++) {
+ /* first byte is how many colors to skip */
+ palette_ptr += buf[stream_ptr++];
+
+ /* next byte indicates how many entries to change */
+ color_changes = buf[stream_ptr++];
+
+ /* if there are 0 color changes, there are actually 256 */
+ if (color_changes == 0)
+ color_changes = 256;
+
+ for (j = 0; j < color_changes; j++) {
+ unsigned int entry;
+
+ /* wrap around, for good measure */
+ if ((unsigned)palette_ptr >= 256)
+ palette_ptr = 0;
+
+ r = buf[stream_ptr++] << color_shift;
+ g = buf[stream_ptr++] << color_shift;
+ b = buf[stream_ptr++] << color_shift;
+ entry = (r << 16) | (g << 8) | b;
+ if (s->palette[palette_ptr] != entry)
+ s->new_palette = 1;
+ s->palette[palette_ptr++] = entry;
+ }
+ }
+
+ /* color chunks sometimes have weird 16-bit alignment issues;
+ * therefore, take the hardline approach and set the stream_ptr
+ * to the value calculated w.r.t. the size specified by the color
+ * chunk header */
+ stream_ptr = stream_ptr_after_color_chunk;
+
+ break;
+
+ case FLI_DELTA:
+ y_ptr = 0;
+ compressed_lines = AV_RL16(&buf[stream_ptr]);
+ stream_ptr += 2;
+ while (compressed_lines > 0) {
+ line_packets = AV_RL16(&buf[stream_ptr]);
+ stream_ptr += 2;
+ if ((line_packets & 0xC000) == 0xC000) {
+ // line skip opcode
+ line_packets = -line_packets;
+ y_ptr += line_packets * s->frame.linesize[0];
+ } else if ((line_packets & 0xC000) == 0x4000) {
+ av_log(avctx, AV_LOG_ERROR, "Undefined opcode (%x) in DELTA_FLI\n", line_packets);
+ } else if ((line_packets & 0xC000) == 0x8000) {
+ // "last byte" opcode
+ pixels[y_ptr + s->frame.linesize[0] - 1] = line_packets & 0xff;
+ } else {
+ compressed_lines--;
+ pixel_ptr = y_ptr;
+ pixel_countdown = s->avctx->width;
+ for (i = 0; i < line_packets; i++) {
+ /* account for the skip bytes */
+ pixel_skip = buf[stream_ptr++];
+ pixel_ptr += pixel_skip;
+ pixel_countdown -= pixel_skip;
+ byte_run = (signed char)(buf[stream_ptr++]);
+ if (byte_run < 0) {
+ byte_run = -byte_run;
+ palette_idx1 = buf[stream_ptr++];
+ palette_idx2 = buf[stream_ptr++];
+ CHECK_PIXEL_PTR(byte_run);
+ for (j = 0; j < byte_run; j++, pixel_countdown -= 2) {
+ pixels[pixel_ptr++] = palette_idx1;
+ pixels[pixel_ptr++] = palette_idx2;
+ }
+ } else {
+ CHECK_PIXEL_PTR(byte_run * 2);
+ for (j = 0; j < byte_run * 2; j++, pixel_countdown--) {
+ palette_idx1 = buf[stream_ptr++];
+ pixels[pixel_ptr++] = palette_idx1;
+ }
+ }
+ }
+
+ y_ptr += s->frame.linesize[0];
+ }
+ }
+ break;
+
+ case FLI_LC:
+ /* line compressed */
+ starting_line = AV_RL16(&buf[stream_ptr]);
+ stream_ptr += 2;
+ y_ptr = 0;
+ y_ptr += starting_line * s->frame.linesize[0];
+
+ compressed_lines = AV_RL16(&buf[stream_ptr]);
+ stream_ptr += 2;
+ while (compressed_lines > 0) {
+ pixel_ptr = y_ptr;
+ pixel_countdown = s->avctx->width;
+ line_packets = buf[stream_ptr++];
+ if (line_packets > 0) {
+ for (i = 0; i < line_packets; i++) {
+ /* account for the skip bytes */
+ pixel_skip = buf[stream_ptr++];
+ pixel_ptr += pixel_skip;
+ pixel_countdown -= pixel_skip;
+ byte_run = (signed char)(buf[stream_ptr++]);
+ if (byte_run > 0) {
+ CHECK_PIXEL_PTR(byte_run);
+ for (j = 0; j < byte_run; j++, pixel_countdown--) {
+ palette_idx1 = buf[stream_ptr++];
+ pixels[pixel_ptr++] = palette_idx1;
+ }
+ } else if (byte_run < 0) {
+ byte_run = -byte_run;
+ palette_idx1 = buf[stream_ptr++];
+ CHECK_PIXEL_PTR(byte_run);
+ for (j = 0; j < byte_run; j++, pixel_countdown--) {
+ pixels[pixel_ptr++] = palette_idx1;
+ }
+ }
+ }
+ }
+
+ y_ptr += s->frame.linesize[0];
+ compressed_lines--;
+ }
+ break;
+
+ case FLI_BLACK:
+ /* set the whole frame to color 0 (which is usually black) */
+ memset(pixels, 0,
+ s->frame.linesize[0] * s->avctx->height);
+ break;
+
+ case FLI_BRUN:
+ /* Byte run compression: This chunk type only occurs in the first
+ * FLI frame and it will update the entire frame. */
+ y_ptr = 0;
+ for (lines = 0; lines < s->avctx->height; lines++) {
+ pixel_ptr = y_ptr;
+ /* disregard the line packets; instead, iterate through all
+ * pixels on a row */
+ stream_ptr++;
+ pixel_countdown = s->avctx->width;
+ while (pixel_countdown > 0) {
+ byte_run = (signed char)(buf[stream_ptr++]);
+ if (byte_run > 0) {
+ palette_idx1 = buf[stream_ptr++];
+ CHECK_PIXEL_PTR(byte_run);
+ for (j = 0; j < byte_run; j++) {
+ pixels[pixel_ptr++] = palette_idx1;
+ pixel_countdown--;
+ if (pixel_countdown < 0)
+ av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d) at line %d\n",
+ pixel_countdown, lines);
+ }
+ } else { /* copy bytes if byte_run < 0 */
+ byte_run = -byte_run;
+ CHECK_PIXEL_PTR(byte_run);
+ for (j = 0; j < byte_run; j++) {
+ palette_idx1 = buf[stream_ptr++];
+ pixels[pixel_ptr++] = palette_idx1;
+ pixel_countdown--;
+ if (pixel_countdown < 0)
+ av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d) at line %d\n",
+ pixel_countdown, lines);
+ }
+ }
+ }
+
+ y_ptr += s->frame.linesize[0];
+ }
+ break;
+
+ case FLI_COPY:
+ /* copy the chunk (uncompressed frame) */
+ if (chunk_size - 6 > s->avctx->width * s->avctx->height) {
+ av_log(avctx, AV_LOG_ERROR, "In chunk FLI_COPY : source data (%d bytes) " \
+ "bigger than image, skipping chunk\n", chunk_size - 6);
+ stream_ptr += chunk_size - 6;
+ } else {
+ for (y_ptr = 0; y_ptr < s->frame.linesize[0] * s->avctx->height;
+ y_ptr += s->frame.linesize[0]) {
+ memcpy(&pixels[y_ptr], &buf[stream_ptr],
+ s->avctx->width);
+ stream_ptr += s->avctx->width;
+ }
+ }
+ break;
+
+ case FLI_MINI:
+ /* some sort of a thumbnail? disregard this chunk... */
+ stream_ptr += chunk_size - 6;
+ break;
+
+ default:
+ av_log(avctx, AV_LOG_ERROR, "Unrecognized chunk type: %d\n", chunk_type);
+ break;
+ }
+
+ frame_size -= chunk_size;
+ num_chunks--;
+ }
+
+ /* by the end of the chunk, the stream ptr should equal the frame
+ * size (minus 1, possibly); if it doesn't, issue a warning */
+ if ((stream_ptr != buf_size) && (stream_ptr != buf_size - 1))
+ av_log(avctx, AV_LOG_ERROR, "Processed FLI chunk where chunk size = %d " \
+ "and final chunk ptr = %d\n", buf_size, stream_ptr);
+
+ /* make the palette available on the way out */
+ memcpy(s->frame.data[1], s->palette, AVPALETTE_SIZE);
+ if (s->new_palette) {
+ s->frame.palette_has_changed = 1;
+ s->new_palette = 0;
+ }
+
+ *data_size=sizeof(AVFrame);
+ *(AVFrame*)data = s->frame;
+
+ return buf_size;
+}
+
+static int flic_decode_frame_15_16BPP(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ /* Note, the only difference between the 15Bpp and 16Bpp */
+ /* Format is the pixel format, the packets are processed the same. */
+ FlicDecodeContext *s = (FlicDecodeContext *)avctx->priv_data;
+
+ int stream_ptr = 0;
+ int pixel_ptr;
+ unsigned char palette_idx1;
+
+ unsigned int frame_size;
+ int num_chunks;
+
+ unsigned int chunk_size;
+ int chunk_type;
+
+ int i, j;
+
+ int lines;
+ int compressed_lines;
+ signed short line_packets;
+ int y_ptr;
+ int byte_run;
+ int pixel_skip;
+ int pixel_countdown;
+ unsigned char *pixels;
+ int pixel;
+ int pixel_limit;
+
+ s->frame.reference = 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;
+ }
+
+ pixels = s->frame.data[0];
+ pixel_limit = s->avctx->height * s->frame.linesize[0];
+
+ frame_size = AV_RL32(&buf[stream_ptr]);
+ stream_ptr += 6; /* skip the magic number */
+ num_chunks = AV_RL16(&buf[stream_ptr]);
+ stream_ptr += 10; /* skip padding */
+
+ frame_size -= 16;
+
+ /* iterate through the chunks */
+ while ((frame_size > 0) && (num_chunks > 0)) {
+ chunk_size = AV_RL32(&buf[stream_ptr]);
+ stream_ptr += 4;
+ chunk_type = AV_RL16(&buf[stream_ptr]);
+ stream_ptr += 2;
+
+ switch (chunk_type) {
+ case FLI_256_COLOR:
+ case FLI_COLOR:
+ /* For some reason, it seems that non-paletised flics do include one of these */
+ /* chunks in their first frame. Why i do not know, it seems rather extraneous */
+/* av_log(avctx, AV_LOG_ERROR, "Unexpected Palette chunk %d in non-paletised FLC\n",chunk_type);*/
+ stream_ptr = stream_ptr + chunk_size - 6;
+ break;
+
+ case FLI_DELTA:
+ case FLI_DTA_LC:
+ y_ptr = 0;
+ compressed_lines = AV_RL16(&buf[stream_ptr]);
+ stream_ptr += 2;
+ while (compressed_lines > 0) {
+ line_packets = AV_RL16(&buf[stream_ptr]);
+ stream_ptr += 2;
+ if (line_packets < 0) {
+ line_packets = -line_packets;
+ y_ptr += line_packets * s->frame.linesize[0];
+ } else {
+ compressed_lines--;
+ pixel_ptr = y_ptr;
+ pixel_countdown = s->avctx->width;
+ for (i = 0; i < line_packets; i++) {
+ /* account for the skip bytes */
+ pixel_skip = buf[stream_ptr++];
+ pixel_ptr += (pixel_skip*2); /* Pixel is 2 bytes wide */
+ pixel_countdown -= pixel_skip;
+ byte_run = (signed char)(buf[stream_ptr++]);
+ if (byte_run < 0) {
+ byte_run = -byte_run;
+ pixel = AV_RL16(&buf[stream_ptr]);
+ stream_ptr += 2;
+ CHECK_PIXEL_PTR(byte_run);
+ for (j = 0; j < byte_run; j++, pixel_countdown -= 2) {
+ *((signed short*)(&pixels[pixel_ptr])) = pixel;
+ pixel_ptr += 2;
+ }
+ } else {
+ CHECK_PIXEL_PTR(byte_run);
+ for (j = 0; j < byte_run; j++, pixel_countdown--) {
+ *((signed short*)(&pixels[pixel_ptr])) = AV_RL16(&buf[stream_ptr]);
+ stream_ptr += 2;
+ pixel_ptr += 2;
+ }
+ }
+ }
+
+ y_ptr += s->frame.linesize[0];
+ }
+ }
+ break;
+
+ case FLI_LC:
+ av_log(avctx, AV_LOG_ERROR, "Unexpected FLI_LC chunk in non-paletised FLC\n");
+ stream_ptr = stream_ptr + chunk_size - 6;
+ break;
+
+ case FLI_BLACK:
+ /* set the whole frame to 0x0000 which is black in both 15Bpp and 16Bpp modes. */
+ memset(pixels, 0x0000,
+ s->frame.linesize[0] * s->avctx->height);
+ break;
+
+ case FLI_BRUN:
+ y_ptr = 0;
+ for (lines = 0; lines < s->avctx->height; lines++) {
+ pixel_ptr = y_ptr;
+ /* disregard the line packets; instead, iterate through all
+ * pixels on a row */
+ stream_ptr++;
+ pixel_countdown = (s->avctx->width * 2);
+
+ while (pixel_countdown > 0) {
+ byte_run = (signed char)(buf[stream_ptr++]);
+ if (byte_run > 0) {
+ palette_idx1 = buf[stream_ptr++];
+ CHECK_PIXEL_PTR(byte_run);
+ for (j = 0; j < byte_run; j++) {
+ pixels[pixel_ptr++] = palette_idx1;
+ pixel_countdown--;
+ if (pixel_countdown < 0)
+ av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d) (linea%d)\n",
+ pixel_countdown, lines);
+ }
+ } else { /* copy bytes if byte_run < 0 */
+ byte_run = -byte_run;
+ CHECK_PIXEL_PTR(byte_run);
+ for (j = 0; j < byte_run; j++) {
+ palette_idx1 = buf[stream_ptr++];
+ pixels[pixel_ptr++] = palette_idx1;
+ pixel_countdown--;
+ if (pixel_countdown < 0)
+ av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d) at line %d\n",
+ pixel_countdown, lines);
+ }
+ }
+ }
+
+ /* Now FLX is strange, in that it is "byte" as opposed to "pixel" run length compressed.
+ * This doesnt give us any good oportunity to perform word endian conversion
+ * during decompression. So if its requried (ie, this isnt a LE target, we do
+ * a second pass over the line here, swapping the bytes.
+ */
+ pixel = 0xFF00;
+ if (0xFF00 != AV_RL16(&pixel)) /* Check if its not an LE Target */
+ {
+ pixel_ptr = y_ptr;
+ pixel_countdown = s->avctx->width;
+ while (pixel_countdown > 0) {
+ *((signed short*)(&pixels[pixel_ptr])) = AV_RL16(&buf[pixel_ptr]);
+ pixel_ptr += 2;
+ }
+ }
+ y_ptr += s->frame.linesize[0];
+ }
+ break;
+
+ case FLI_DTA_BRUN:
+ y_ptr = 0;
+ for (lines = 0; lines < s->avctx->height; lines++) {
+ pixel_ptr = y_ptr;
+ /* disregard the line packets; instead, iterate through all
+ * pixels on a row */
+ stream_ptr++;
+ pixel_countdown = s->avctx->width; /* Width is in pixels, not bytes */
+
+ while (pixel_countdown > 0) {
+ byte_run = (signed char)(buf[stream_ptr++]);
+ if (byte_run > 0) {
+ pixel = AV_RL16(&buf[stream_ptr]);
+ stream_ptr += 2;
+ CHECK_PIXEL_PTR(byte_run);
+ for (j = 0; j < byte_run; j++) {
+ *((signed short*)(&pixels[pixel_ptr])) = pixel;
+ pixel_ptr += 2;
+ pixel_countdown--;
+ if (pixel_countdown < 0)
+ av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d)\n",
+ pixel_countdown);
+ }
+ } else { /* copy pixels if byte_run < 0 */
+ byte_run = -byte_run;
+ CHECK_PIXEL_PTR(byte_run);
+ for (j = 0; j < byte_run; j++) {
+ *((signed short*)(&pixels[pixel_ptr])) = AV_RL16(&buf[stream_ptr]);
+ stream_ptr += 2;
+ pixel_ptr += 2;
+ pixel_countdown--;
+ if (pixel_countdown < 0)
+ av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d)\n",
+ pixel_countdown);
+ }
+ }
+ }
+
+ y_ptr += s->frame.linesize[0];
+ }
+ break;
+
+ case FLI_COPY:
+ case FLI_DTA_COPY:
+ /* copy the chunk (uncompressed frame) */
+ if (chunk_size - 6 > (unsigned int)(s->avctx->width * s->avctx->height)*2) {
+ av_log(avctx, AV_LOG_ERROR, "In chunk FLI_COPY : source data (%d bytes) " \
+ "bigger than image, skipping chunk\n", chunk_size - 6);
+ stream_ptr += chunk_size - 6;
+ } else {
+
+ for (y_ptr = 0; y_ptr < s->frame.linesize[0] * s->avctx->height;
+ y_ptr += s->frame.linesize[0]) {
+
+ pixel_countdown = s->avctx->width;
+ pixel_ptr = 0;
+ while (pixel_countdown > 0) {
+ *((signed short*)(&pixels[y_ptr + pixel_ptr])) = AV_RL16(&buf[stream_ptr+pixel_ptr]);
+ pixel_ptr += 2;
+ pixel_countdown--;
+ }
+ stream_ptr += s->avctx->width*2;
+ }
+ }
+ break;
+
+ case FLI_MINI:
+ /* some sort of a thumbnail? disregard this chunk... */
+ stream_ptr += chunk_size - 6;
+ break;
+
+ default:
+ av_log(avctx, AV_LOG_ERROR, "Unrecognized chunk type: %d\n", chunk_type);
+ break;
+ }
+
+ frame_size -= chunk_size;
+ num_chunks--;
+ }
+
+ /* by the end of the chunk, the stream ptr should equal the frame
+ * size (minus 1, possibly); if it doesn't, issue a warning */
+ if ((stream_ptr != buf_size) && (stream_ptr != buf_size - 1))
+ av_log(avctx, AV_LOG_ERROR, "Processed FLI chunk where chunk size = %d " \
+ "and final chunk ptr = %d\n", buf_size, stream_ptr);
+
+
+ *data_size=sizeof(AVFrame);
+ *(AVFrame*)data = s->frame;
+
+ return buf_size;
+}
+
+static int flic_decode_frame_24BPP(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ av_log(avctx, AV_LOG_ERROR, "24Bpp FLC Unsupported due to lack of test files.\n");
+ return -1;
+}
+
+static int flic_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ if (avctx->pix_fmt == PIX_FMT_PAL8) {
+ return flic_decode_frame_8BPP(avctx, data, data_size,
+ buf, buf_size);
+ }
+ else if ((avctx->pix_fmt == PIX_FMT_RGB555) ||
+ (avctx->pix_fmt == PIX_FMT_RGB565)) {
+ return flic_decode_frame_15_16BPP(avctx, data, data_size,
+ buf, buf_size);
+ }
+ else if (avctx->pix_fmt == PIX_FMT_BGR24) {
+ return flic_decode_frame_24BPP(avctx, data, data_size,
+ buf, buf_size);
+ }
+
+ /* Shouldnt get here, ever as the pix_fmt is processed */
+ /* in flic_decode_init and the above if should deal with */
+ /* the finite set of possibilites allowable by here. */
+ /* but in case we do, just error out. */
+ av_log(avctx, AV_LOG_ERROR, "Unknown Format of FLC. My Science cant explain how this happened\n");
+ return -1;
+}
+
+
+static int flic_decode_end(AVCodecContext *avctx)
+{
+ FlicDecodeContext *s = avctx->priv_data;
+
+ if (s->frame.data[0])
+ avctx->release_buffer(avctx, &s->frame);
+
+ return 0;
+}
+
+AVCodec flic_decoder = {
+ "flic",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_FLIC,
+ sizeof(FlicDecodeContext),
+ flic_decode_init,
+ NULL,
+ flic_decode_end,
+ flic_decode_frame,
+ CODEC_CAP_DR1,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
diff --git a/src/libffmpeg/libavcodec/fraps.c b/contrib/ffmpeg/libavcodec/fraps.c
index 0a4567d05..0a4567d05 100644
--- a/src/libffmpeg/libavcodec/fraps.c
+++ b/contrib/ffmpeg/libavcodec/fraps.c
diff --git a/contrib/ffmpeg/libavcodec/g726.c b/contrib/ffmpeg/libavcodec/g726.c
new file mode 100644
index 000000000..07af33122
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/g726.c
@@ -0,0 +1,429 @@
+/*
+ * G.726 ADPCM audio codec
+ * Copyright (c) 2004 Roman Shaposhnik.
+ *
+ * This is a very straightforward rendition of the G.726
+ * Section 4 "Computational Details".
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 <limits.h>
+#include "avcodec.h"
+#include "common.h"
+#include "bitstream.h"
+
+/**
+ * G.726 11bit float.
+ * G.726 Standard uses rather odd 11bit floating point arithmentic for
+ * numerous occasions. It's a mistery to me why they did it this way
+ * instead of simply using 32bit integer arithmetic.
+ */
+typedef struct Float11 {
+ int sign; /**< 1bit sign */
+ int exp; /**< 4bit exponent */
+ int mant; /**< 6bit mantissa */
+} Float11;
+
+static inline Float11* i2f(int16_t i, Float11* f)
+{
+ f->sign = (i < 0);
+ if (f->sign)
+ i = -i;
+ f->exp = av_log2_16bit(i) + !!i;
+ f->mant = i? (i<<6) >> f->exp : 1<<5;
+ return f;
+}
+
+static inline int16_t mult(Float11* f1, Float11* f2)
+{
+ int res, exp;
+
+ exp = f1->exp + f2->exp;
+ res = (((f1->mant * f2->mant) + 0x30) >> 4) << 7;
+ res = exp > 26 ? res << (exp - 26) : res >> (26 - exp);
+ return (f1->sign ^ f2->sign) ? -res : res;
+}
+
+static inline int sgn(int value)
+{
+ return (value < 0) ? -1 : 1;
+}
+
+typedef struct G726Tables {
+ int bits; /**< bits per sample */
+ int* quant; /**< quantization table */
+ int* iquant; /**< inverse quantization table */
+ int* W; /**< special table #1 ;-) */
+ int* F; /**< special table #2 */
+} G726Tables;
+
+typedef struct G726Context {
+ G726Tables* tbls; /**< static tables needed for computation */
+
+ Float11 sr[2]; /**< prev. reconstructed samples */
+ Float11 dq[6]; /**< prev. difference */
+ int a[2]; /**< second order predictor coeffs */
+ int b[6]; /**< sixth order predictor coeffs */
+ int pk[2]; /**< signs of prev. 2 sez + dq */
+
+ int ap; /**< scale factor control */
+ int yu; /**< fast scale factor */
+ int yl; /**< slow scale factor */
+ int dms; /**< short average magnitude of F[i] */
+ int dml; /**< long average magnitude of F[i] */
+ int td; /**< tone detect */
+
+ int se; /**< estimated signal for the next iteration */
+ int sez; /**< estimated second order prediction */
+ int y; /**< quantizer scaling factor for the next iteration */
+} G726Context;
+
+static int quant_tbl16[] = /**< 16kbit/s 2bits per sample */
+ { 260, INT_MAX };
+static int iquant_tbl16[] =
+ { 116, 365, 365, 116 };
+static int W_tbl16[] =
+ { -22, 439, 439, -22 };
+static int F_tbl16[] =
+ { 0, 7, 7, 0 };
+
+static int quant_tbl24[] = /**< 24kbit/s 3bits per sample */
+ { 7, 217, 330, INT_MAX };
+static int iquant_tbl24[] =
+ { INT_MIN, 135, 273, 373, 373, 273, 135, INT_MIN };
+static int W_tbl24[] =
+ { -4, 30, 137, 582, 582, 137, 30, -4 };
+static int F_tbl24[] =
+ { 0, 1, 2, 7, 7, 2, 1, 0 };
+
+static int quant_tbl32[] = /**< 32kbit/s 4bits per sample */
+ { -125, 79, 177, 245, 299, 348, 399, INT_MAX };
+static int iquant_tbl32[] =
+ { INT_MIN, 4, 135, 213, 273, 323, 373, 425,
+ 425, 373, 323, 273, 213, 135, 4, INT_MIN };
+static int W_tbl32[] =
+ { -12, 18, 41, 64, 112, 198, 355, 1122,
+ 1122, 355, 198, 112, 64, 41, 18, -12};
+static int F_tbl32[] =
+ { 0, 0, 0, 1, 1, 1, 3, 7, 7, 3, 1, 1, 1, 0, 0, 0 };
+
+static int quant_tbl40[] = /**< 40kbit/s 5bits per sample */
+ { -122, -16, 67, 138, 197, 249, 297, 338,
+ 377, 412, 444, 474, 501, 527, 552, INT_MAX };
+static int iquant_tbl40[] =
+ { INT_MIN, -66, 28, 104, 169, 224, 274, 318,
+ 358, 395, 429, 459, 488, 514, 539, 566,
+ 566, 539, 514, 488, 459, 429, 395, 358,
+ 318, 274, 224, 169, 104, 28, -66, INT_MIN };
+static int W_tbl40[] =
+ { 14, 14, 24, 39, 40, 41, 58, 100,
+ 141, 179, 219, 280, 358, 440, 529, 696,
+ 696, 529, 440, 358, 280, 219, 179, 141,
+ 100, 58, 41, 40, 39, 24, 14, 14 };
+static int F_tbl40[] =
+ { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 6,
+ 6, 6, 5, 4, 3, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
+
+static G726Tables G726Tables_pool[] =
+ {{ 2, quant_tbl16, iquant_tbl16, W_tbl16, F_tbl16 },
+ { 3, quant_tbl24, iquant_tbl24, W_tbl24, F_tbl24 },
+ { 4, quant_tbl32, iquant_tbl32, W_tbl32, F_tbl32 },
+ { 5, quant_tbl40, iquant_tbl40, W_tbl40, F_tbl40 }};
+
+
+/**
+ * Para 4.2.2 page 18: Adaptive quantizer.
+ */
+static inline uint8_t quant(G726Context* c, int d)
+{
+ int sign, exp, i, dln;
+
+ sign = i = 0;
+ if (d < 0) {
+ sign = 1;
+ d = -d;
+ }
+ exp = av_log2_16bit(d);
+ dln = ((exp<<7) + (((d<<7)>>exp)&0x7f)) - (c->y>>2);
+
+ while (c->tbls->quant[i] < INT_MAX && c->tbls->quant[i] < dln)
+ ++i;
+
+ if (sign)
+ i = ~i;
+ if (c->tbls->bits != 2 && i == 0) /* I'm not sure this is a good idea */
+ i = 0xff;
+
+ return i;
+}
+
+/**
+ * Para 4.2.3 page 22: Inverse adaptive quantizer.
+ */
+static inline int16_t inverse_quant(G726Context* c, int i)
+{
+ int dql, dex, dqt;
+
+ dql = c->tbls->iquant[i] + (c->y >> 2);
+ dex = (dql>>7) & 0xf; /* 4bit exponent */
+ dqt = (1<<7) + (dql & 0x7f); /* log2 -> linear */
+ return (dql < 0) ? 0 : ((dqt<<7) >> (14-dex));
+}
+
+static inline int16_t g726_iterate(G726Context* c, int16_t I)
+{
+ int dq, re_signal, pk0, fa1, i, tr, ylint, ylfrac, thr2, al, dq0;
+ Float11 f;
+
+ dq = inverse_quant(c, I);
+ if (I >> (c->tbls->bits - 1)) /* get the sign */
+ dq = -dq;
+ re_signal = c->se + dq;
+
+ /* Transition detect */
+ ylint = (c->yl >> 15);
+ ylfrac = (c->yl >> 10) & 0x1f;
+ thr2 = (ylint > 9) ? 0x1f << 10 : (0x20 + ylfrac) << ylint;
+ if (c->td == 1 && abs(dq) > ((thr2+(thr2>>1))>>1))
+ tr = 1;
+ else
+ tr = 0;
+
+ /* Update second order predictor coefficient A2 and A1 */
+ pk0 = (c->sez + dq) ? sgn(c->sez + dq) : 0;
+ dq0 = dq ? sgn(dq) : 0;
+ if (tr) {
+ c->a[0] = 0;
+ c->a[1] = 0;
+ for (i=0; i<6; i++)
+ c->b[i] = 0;
+ } else {
+ /* This is a bit crazy, but it really is +255 not +256 */
+ fa1 = av_clip((-c->a[0]*c->pk[0]*pk0)>>5, -256, 255);
+
+ c->a[1] += 128*pk0*c->pk[1] + fa1 - (c->a[1]>>7);
+ c->a[1] = av_clip(c->a[1], -12288, 12288);
+ c->a[0] += 64*3*pk0*c->pk[0] - (c->a[0] >> 8);
+ c->a[0] = av_clip(c->a[0], -(15360 - c->a[1]), 15360 - c->a[1]);
+
+ for (i=0; i<6; i++)
+ c->b[i] += 128*dq0*sgn(-c->dq[i].sign) - (c->b[i]>>8);
+ }
+
+ /* Update Dq and Sr and Pk */
+ c->pk[1] = c->pk[0];
+ c->pk[0] = pk0 ? pk0 : 1;
+ c->sr[1] = c->sr[0];
+ i2f(re_signal, &c->sr[0]);
+ for (i=5; i>0; i--)
+ c->dq[i] = c->dq[i-1];
+ i2f(dq, &c->dq[0]);
+ c->dq[0].sign = I >> (c->tbls->bits - 1); /* Isn't it crazy ?!?! */
+
+ /* Update tone detect [I'm not sure 'tr == 0' is really needed] */
+ c->td = (tr == 0 && c->a[1] < -11776);
+
+ /* Update Ap */
+ c->dms += ((c->tbls->F[I]<<9) - c->dms) >> 5;
+ c->dml += ((c->tbls->F[I]<<11) - c->dml) >> 7;
+ if (tr)
+ c->ap = 256;
+ else if (c->y > 1535 && !c->td && (abs((c->dms << 2) - c->dml) < (c->dml >> 3)))
+ c->ap += (-c->ap) >> 4;
+ else
+ c->ap += (0x200 - c->ap) >> 4;
+
+ /* Update Yu and Yl */
+ c->yu = av_clip(c->y + (((c->tbls->W[I] << 5) - c->y) >> 5), 544, 5120);
+ c->yl += c->yu + ((-c->yl)>>6);
+
+ /* Next iteration for Y */
+ al = (c->ap >= 256) ? 1<<6 : c->ap >> 2;
+ c->y = (c->yl + (c->yu - (c->yl>>6))*al) >> 6;
+
+ /* Next iteration for SE and SEZ */
+ c->se = 0;
+ for (i=0; i<6; i++)
+ c->se += mult(i2f(c->b[i] >> 2, &f), &c->dq[i]);
+ c->sez = c->se >> 1;
+ for (i=0; i<2; i++)
+ c->se += mult(i2f(c->a[i] >> 2, &f), &c->sr[i]);
+ c->se >>= 1;
+
+ return av_clip(re_signal << 2, -0xffff, 0xffff);
+}
+
+static int g726_reset(G726Context* c, int bit_rate)
+{
+ int i;
+
+ c->tbls = &G726Tables_pool[bit_rate/8000 - 2];
+ for (i=0; i<2; i++) {
+ i2f(0, &c->sr[i]);
+ c->a[i] = 0;
+ c->pk[i] = 1;
+ }
+ for (i=0; i<6; i++) {
+ i2f(0, &c->dq[i]);
+ c->b[i] = 0;
+ }
+ c->ap = 0;
+ c->dms = 0;
+ c->dml = 0;
+ c->yu = 544;
+ c->yl = 34816;
+ c->td = 0;
+
+ c->se = 0;
+ c->sez = 0;
+ c->y = 544;
+
+ return 0;
+}
+
+static int16_t g726_decode(G726Context* c, int16_t i)
+{
+ return g726_iterate(c, i);
+}
+
+#ifdef CONFIG_ENCODERS
+static int16_t g726_encode(G726Context* c, int16_t sig)
+{
+ uint8_t i;
+
+ i = quant(c, sig/4 - c->se) & ((1<<c->tbls->bits) - 1);
+ g726_iterate(c, i);
+ return i;
+}
+#endif
+
+/* Interfacing to the libavcodec */
+
+typedef struct AVG726Context {
+ G726Context c;
+ int bits_left;
+ int bit_buffer;
+ int code_size;
+} AVG726Context;
+
+static int g726_init(AVCodecContext * avctx)
+{
+ AVG726Context* c = (AVG726Context*)avctx->priv_data;
+
+ if (avctx->channels != 1 ||
+ (avctx->bit_rate != 16000 && avctx->bit_rate != 24000 &&
+ avctx->bit_rate != 32000 && avctx->bit_rate != 40000)) {
+ av_log(avctx, AV_LOG_ERROR, "G726: unsupported audio format\n");
+ return -1;
+ }
+ if (avctx->sample_rate != 8000 && avctx->strict_std_compliance>FF_COMPLIANCE_INOFFICIAL) {
+ av_log(avctx, AV_LOG_ERROR, "G726: unsupported audio format\n");
+ return -1;
+ }
+ g726_reset(&c->c, avctx->bit_rate);
+ c->code_size = c->c.tbls->bits;
+ c->bit_buffer = 0;
+ c->bits_left = 0;
+
+ avctx->coded_frame = avcodec_alloc_frame();
+ if (!avctx->coded_frame)
+ return AVERROR(ENOMEM);
+ avctx->coded_frame->key_frame = 1;
+
+ return 0;
+}
+
+static int g726_close(AVCodecContext *avctx)
+{
+ av_freep(&avctx->coded_frame);
+ return 0;
+}
+
+#ifdef CONFIG_ENCODERS
+static int g726_encode_frame(AVCodecContext *avctx,
+ uint8_t *dst, int buf_size, void *data)
+{
+ AVG726Context *c = avctx->priv_data;
+ short *samples = data;
+ PutBitContext pb;
+
+ init_put_bits(&pb, dst, 1024*1024);
+
+ for (; buf_size; buf_size--)
+ put_bits(&pb, c->code_size, g726_encode(&c->c, *samples++));
+
+ flush_put_bits(&pb);
+
+ return put_bits_count(&pb)>>3;
+}
+#endif
+
+static int g726_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ AVG726Context *c = avctx->priv_data;
+ short *samples = data;
+ uint8_t code;
+ uint8_t mask;
+ GetBitContext gb;
+
+ if (!buf_size)
+ goto out;
+
+ mask = (1<<c->code_size) - 1;
+ init_get_bits(&gb, buf, buf_size * 8);
+ if (c->bits_left) {
+ int s = c->code_size - c->bits_left;;
+ code = (c->bit_buffer << s) | get_bits(&gb, s);
+ *samples++ = g726_decode(&c->c, code & mask);
+ }
+
+ while (get_bits_count(&gb) + c->code_size <= buf_size*8)
+ *samples++ = g726_decode(&c->c, get_bits(&gb, c->code_size) & mask);
+
+ c->bits_left = buf_size*8 - get_bits_count(&gb);
+ c->bit_buffer = get_bits(&gb, c->bits_left);
+
+out:
+ *data_size = (uint8_t*)samples - (uint8_t*)data;
+ return buf_size;
+}
+
+#ifdef CONFIG_ENCODERS
+AVCodec adpcm_g726_encoder = {
+ "g726",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_ADPCM_G726,
+ sizeof(AVG726Context),
+ g726_init,
+ g726_encode_frame,
+ g726_close,
+ NULL,
+};
+#endif //CONFIG_ENCODERS
+
+AVCodec adpcm_g726_decoder = {
+ "g726",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_ADPCM_G726,
+ sizeof(AVG726Context),
+ g726_init,
+ NULL,
+ g726_close,
+ g726_decode_frame,
+};
diff --git a/contrib/ffmpeg/libavcodec/gif.c b/contrib/ffmpeg/libavcodec/gif.c
new file mode 100644
index 000000000..f67ab52c2
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/gif.c
@@ -0,0 +1,350 @@
+/*
+ * GIF encoder.
+ * Copyright (c) 2000 Fabrice Bellard.
+ * Copyright (c) 2002 Francois Revol.
+ * Copyright (c) 2006 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
+ */
+
+/*
+ * First version by Francois Revol revol@free.fr
+ *
+ * Features and limitations:
+ * - currently no compression is performed,
+ * in fact the size of the data is 9/8 the size of the image in 8bpp
+ * - uses only a global standard palette
+ * - tested with IE 5.0, Opera for BeOS, NetPositive (BeOS), and Mozilla (BeOS).
+ *
+ * Reference documents:
+ * http://www.goice.co.jp/member/mo/formats/gif.html
+ * http://astronomy.swin.edu.au/pbourke/dataformats/gif/
+ * http://www.dcs.ed.ac.uk/home/mxr/gfx/2d/GIF89a.txt
+ *
+ * this url claims to have an LZW algorithm not covered by Unisys patent:
+ * http://www.msg.net/utility/whirlgif/gifencod.html
+ * could help reduce the size of the files _a lot_...
+ * some sites mentions an RLE type compression also.
+ */
+
+#include "avcodec.h"
+#include "bytestream.h"
+#include "bitstream.h"
+
+/* bitstream minipacket size */
+#define GIF_CHUNKS 100
+
+/* slows down the decoding (and some browsers don't like it) */
+/* update on the 'some browsers don't like it issue from above: this was probably due to missing 'Data Sub-block Terminator' (byte 19) in the app_header */
+#define GIF_ADD_APP_HEADER // required to enable looping of animated gif
+
+typedef struct {
+ unsigned char r;
+ unsigned char g;
+ unsigned char b;
+} rgb_triplet;
+
+/* we use the standard 216 color palette */
+
+/* this script was used to create the palette:
+ * for r in 00 33 66 99 cc ff; do for g in 00 33 66 99 cc ff; do echo -n " "; for b in 00 33 66 99 cc ff; do
+ * echo -n "{ 0x$r, 0x$g, 0x$b }, "; done; echo ""; done; done
+ */
+
+static const rgb_triplet gif_clut[216] = {
+ { 0x00, 0x00, 0x00 }, { 0x00, 0x00, 0x33 }, { 0x00, 0x00, 0x66 }, { 0x00, 0x00, 0x99 }, { 0x00, 0x00, 0xcc }, { 0x00, 0x00, 0xff },
+ { 0x00, 0x33, 0x00 }, { 0x00, 0x33, 0x33 }, { 0x00, 0x33, 0x66 }, { 0x00, 0x33, 0x99 }, { 0x00, 0x33, 0xcc }, { 0x00, 0x33, 0xff },
+ { 0x00, 0x66, 0x00 }, { 0x00, 0x66, 0x33 }, { 0x00, 0x66, 0x66 }, { 0x00, 0x66, 0x99 }, { 0x00, 0x66, 0xcc }, { 0x00, 0x66, 0xff },
+ { 0x00, 0x99, 0x00 }, { 0x00, 0x99, 0x33 }, { 0x00, 0x99, 0x66 }, { 0x00, 0x99, 0x99 }, { 0x00, 0x99, 0xcc }, { 0x00, 0x99, 0xff },
+ { 0x00, 0xcc, 0x00 }, { 0x00, 0xcc, 0x33 }, { 0x00, 0xcc, 0x66 }, { 0x00, 0xcc, 0x99 }, { 0x00, 0xcc, 0xcc }, { 0x00, 0xcc, 0xff },
+ { 0x00, 0xff, 0x00 }, { 0x00, 0xff, 0x33 }, { 0x00, 0xff, 0x66 }, { 0x00, 0xff, 0x99 }, { 0x00, 0xff, 0xcc }, { 0x00, 0xff, 0xff },
+ { 0x33, 0x00, 0x00 }, { 0x33, 0x00, 0x33 }, { 0x33, 0x00, 0x66 }, { 0x33, 0x00, 0x99 }, { 0x33, 0x00, 0xcc }, { 0x33, 0x00, 0xff },
+ { 0x33, 0x33, 0x00 }, { 0x33, 0x33, 0x33 }, { 0x33, 0x33, 0x66 }, { 0x33, 0x33, 0x99 }, { 0x33, 0x33, 0xcc }, { 0x33, 0x33, 0xff },
+ { 0x33, 0x66, 0x00 }, { 0x33, 0x66, 0x33 }, { 0x33, 0x66, 0x66 }, { 0x33, 0x66, 0x99 }, { 0x33, 0x66, 0xcc }, { 0x33, 0x66, 0xff },
+ { 0x33, 0x99, 0x00 }, { 0x33, 0x99, 0x33 }, { 0x33, 0x99, 0x66 }, { 0x33, 0x99, 0x99 }, { 0x33, 0x99, 0xcc }, { 0x33, 0x99, 0xff },
+ { 0x33, 0xcc, 0x00 }, { 0x33, 0xcc, 0x33 }, { 0x33, 0xcc, 0x66 }, { 0x33, 0xcc, 0x99 }, { 0x33, 0xcc, 0xcc }, { 0x33, 0xcc, 0xff },
+ { 0x33, 0xff, 0x00 }, { 0x33, 0xff, 0x33 }, { 0x33, 0xff, 0x66 }, { 0x33, 0xff, 0x99 }, { 0x33, 0xff, 0xcc }, { 0x33, 0xff, 0xff },
+ { 0x66, 0x00, 0x00 }, { 0x66, 0x00, 0x33 }, { 0x66, 0x00, 0x66 }, { 0x66, 0x00, 0x99 }, { 0x66, 0x00, 0xcc }, { 0x66, 0x00, 0xff },
+ { 0x66, 0x33, 0x00 }, { 0x66, 0x33, 0x33 }, { 0x66, 0x33, 0x66 }, { 0x66, 0x33, 0x99 }, { 0x66, 0x33, 0xcc }, { 0x66, 0x33, 0xff },
+ { 0x66, 0x66, 0x00 }, { 0x66, 0x66, 0x33 }, { 0x66, 0x66, 0x66 }, { 0x66, 0x66, 0x99 }, { 0x66, 0x66, 0xcc }, { 0x66, 0x66, 0xff },
+ { 0x66, 0x99, 0x00 }, { 0x66, 0x99, 0x33 }, { 0x66, 0x99, 0x66 }, { 0x66, 0x99, 0x99 }, { 0x66, 0x99, 0xcc }, { 0x66, 0x99, 0xff },
+ { 0x66, 0xcc, 0x00 }, { 0x66, 0xcc, 0x33 }, { 0x66, 0xcc, 0x66 }, { 0x66, 0xcc, 0x99 }, { 0x66, 0xcc, 0xcc }, { 0x66, 0xcc, 0xff },
+ { 0x66, 0xff, 0x00 }, { 0x66, 0xff, 0x33 }, { 0x66, 0xff, 0x66 }, { 0x66, 0xff, 0x99 }, { 0x66, 0xff, 0xcc }, { 0x66, 0xff, 0xff },
+ { 0x99, 0x00, 0x00 }, { 0x99, 0x00, 0x33 }, { 0x99, 0x00, 0x66 }, { 0x99, 0x00, 0x99 }, { 0x99, 0x00, 0xcc }, { 0x99, 0x00, 0xff },
+ { 0x99, 0x33, 0x00 }, { 0x99, 0x33, 0x33 }, { 0x99, 0x33, 0x66 }, { 0x99, 0x33, 0x99 }, { 0x99, 0x33, 0xcc }, { 0x99, 0x33, 0xff },
+ { 0x99, 0x66, 0x00 }, { 0x99, 0x66, 0x33 }, { 0x99, 0x66, 0x66 }, { 0x99, 0x66, 0x99 }, { 0x99, 0x66, 0xcc }, { 0x99, 0x66, 0xff },
+ { 0x99, 0x99, 0x00 }, { 0x99, 0x99, 0x33 }, { 0x99, 0x99, 0x66 }, { 0x99, 0x99, 0x99 }, { 0x99, 0x99, 0xcc }, { 0x99, 0x99, 0xff },
+ { 0x99, 0xcc, 0x00 }, { 0x99, 0xcc, 0x33 }, { 0x99, 0xcc, 0x66 }, { 0x99, 0xcc, 0x99 }, { 0x99, 0xcc, 0xcc }, { 0x99, 0xcc, 0xff },
+ { 0x99, 0xff, 0x00 }, { 0x99, 0xff, 0x33 }, { 0x99, 0xff, 0x66 }, { 0x99, 0xff, 0x99 }, { 0x99, 0xff, 0xcc }, { 0x99, 0xff, 0xff },
+ { 0xcc, 0x00, 0x00 }, { 0xcc, 0x00, 0x33 }, { 0xcc, 0x00, 0x66 }, { 0xcc, 0x00, 0x99 }, { 0xcc, 0x00, 0xcc }, { 0xcc, 0x00, 0xff },
+ { 0xcc, 0x33, 0x00 }, { 0xcc, 0x33, 0x33 }, { 0xcc, 0x33, 0x66 }, { 0xcc, 0x33, 0x99 }, { 0xcc, 0x33, 0xcc }, { 0xcc, 0x33, 0xff },
+ { 0xcc, 0x66, 0x00 }, { 0xcc, 0x66, 0x33 }, { 0xcc, 0x66, 0x66 }, { 0xcc, 0x66, 0x99 }, { 0xcc, 0x66, 0xcc }, { 0xcc, 0x66, 0xff },
+ { 0xcc, 0x99, 0x00 }, { 0xcc, 0x99, 0x33 }, { 0xcc, 0x99, 0x66 }, { 0xcc, 0x99, 0x99 }, { 0xcc, 0x99, 0xcc }, { 0xcc, 0x99, 0xff },
+ { 0xcc, 0xcc, 0x00 }, { 0xcc, 0xcc, 0x33 }, { 0xcc, 0xcc, 0x66 }, { 0xcc, 0xcc, 0x99 }, { 0xcc, 0xcc, 0xcc }, { 0xcc, 0xcc, 0xff },
+ { 0xcc, 0xff, 0x00 }, { 0xcc, 0xff, 0x33 }, { 0xcc, 0xff, 0x66 }, { 0xcc, 0xff, 0x99 }, { 0xcc, 0xff, 0xcc }, { 0xcc, 0xff, 0xff },
+ { 0xff, 0x00, 0x00 }, { 0xff, 0x00, 0x33 }, { 0xff, 0x00, 0x66 }, { 0xff, 0x00, 0x99 }, { 0xff, 0x00, 0xcc }, { 0xff, 0x00, 0xff },
+ { 0xff, 0x33, 0x00 }, { 0xff, 0x33, 0x33 }, { 0xff, 0x33, 0x66 }, { 0xff, 0x33, 0x99 }, { 0xff, 0x33, 0xcc }, { 0xff, 0x33, 0xff },
+ { 0xff, 0x66, 0x00 }, { 0xff, 0x66, 0x33 }, { 0xff, 0x66, 0x66 }, { 0xff, 0x66, 0x99 }, { 0xff, 0x66, 0xcc }, { 0xff, 0x66, 0xff },
+ { 0xff, 0x99, 0x00 }, { 0xff, 0x99, 0x33 }, { 0xff, 0x99, 0x66 }, { 0xff, 0x99, 0x99 }, { 0xff, 0x99, 0xcc }, { 0xff, 0x99, 0xff },
+ { 0xff, 0xcc, 0x00 }, { 0xff, 0xcc, 0x33 }, { 0xff, 0xcc, 0x66 }, { 0xff, 0xcc, 0x99 }, { 0xff, 0xcc, 0xcc }, { 0xff, 0xcc, 0xff },
+ { 0xff, 0xff, 0x00 }, { 0xff, 0xff, 0x33 }, { 0xff, 0xff, 0x66 }, { 0xff, 0xff, 0x99 }, { 0xff, 0xff, 0xcc }, { 0xff, 0xff, 0xff },
+};
+
+/* The GIF format uses reversed order for bitstreams... */
+/* at least they don't use PDP_ENDIAN :) */
+/* so we 'extend' PutBitContext. hmmm, OOP :) */
+/* seems this thing changed slightly since I wrote it... */
+
+#ifdef ALT_BITSTREAM_WRITER
+# error no ALT_BITSTREAM_WRITER support for now
+#endif
+
+static void gif_put_bits_rev(PutBitContext *s, int n, unsigned int value)
+{
+ unsigned int bit_buf;
+ int bit_cnt;
+
+ // printf("put_bits=%d %x\n", n, value);
+ assert(n == 32 || value < (1U << n));
+
+ bit_buf = s->bit_buf;
+ bit_cnt = 32 - s->bit_left; /* XXX:lazyness... was = s->bit_cnt; */
+
+ // printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf);
+ /* XXX: optimize */
+ if (n < (32-bit_cnt)) {
+ bit_buf |= value << (bit_cnt);
+ bit_cnt+=n;
+ } else {
+ bit_buf |= value << (bit_cnt);
+
+ *s->buf_ptr = bit_buf & 0xff;
+ s->buf_ptr[1] = (bit_buf >> 8) & 0xff;
+ s->buf_ptr[2] = (bit_buf >> 16) & 0xff;
+ s->buf_ptr[3] = (bit_buf >> 24) & 0xff;
+
+ //printf("bitbuf = %08x\n", bit_buf);
+ s->buf_ptr+=4;
+ if (s->buf_ptr >= s->buf_end)
+ puts("bit buffer overflow !!"); // should never happen ! who got rid of the callback ???
+// flush_buffer_rev(s);
+ bit_cnt=bit_cnt + n - 32;
+ if (bit_cnt == 0) {
+ bit_buf = 0;
+ } else {
+ bit_buf = value >> (n - bit_cnt);
+ }
+ }
+
+ s->bit_buf = bit_buf;
+ s->bit_left = 32 - bit_cnt;
+}
+
+/* pad the end of the output stream with zeros */
+static void gif_flush_put_bits_rev(PutBitContext *s)
+{
+ while (s->bit_left < 32) {
+ /* XXX: should test end of buffer */
+ *s->buf_ptr++=s->bit_buf & 0xff;
+ s->bit_buf>>=8;
+ s->bit_left+=8;
+ }
+// flush_buffer_rev(s);
+ s->bit_left=32;
+ s->bit_buf=0;
+}
+
+/* !RevPutBitContext */
+
+/* GIF header */
+static int gif_image_write_header(uint8_t **bytestream,
+ int width, int height, int loop_count,
+ 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_byte(bytestream, 0xf7); /* flags: global clut, 256 entries */
+ bytestream_put_byte(bytestream, 0x1f); /* background color index */
+ bytestream_put_byte(bytestream, 0); /* aspect ratio */
+
+ /* the global palette */
+ if (!palette) {
+ bytestream_put_buffer(bytestream, (const unsigned char *)gif_clut, 216*3);
+ for(i=0;i<((256-216)*3);i++)
+ bytestream_put_byte(bytestream, 0);
+ } else {
+ for(i=0;i<256;i++) {
+ v = palette[i];
+ bytestream_put_byte(bytestream, (v >> 16) & 0xff);
+ bytestream_put_byte(bytestream, (v >> 8) & 0xff);
+ bytestream_put_byte(bytestream, (v) & 0xff);
+ }
+ }
+
+ /* update: this is the 'NETSCAPE EXTENSION' that allows for looped animated gif
+ see http://members.aol.com/royalef/gifabout.htm#net-extension
+
+ byte 1 : 33 (hex 0x21) GIF Extension code
+ byte 2 : 255 (hex 0xFF) Application Extension Label
+ byte 3 : 11 (hex (0x0B) Length of Application Block
+ (eleven bytes of data to follow)
+ bytes 4 to 11 : "NETSCAPE"
+ bytes 12 to 14 : "2.0"
+ byte 15 : 3 (hex 0x03) Length of Data Sub-Block
+ (three bytes of data to follow)
+ byte 16 : 1 (hex 0x01)
+ bytes 17 to 18 : 0 to 65535, an unsigned integer in
+ lo-hi byte format. This indicate the
+ number of iterations the loop should
+ be executed.
+ bytes 19 : 0 (hex 0x00) a Data Sub-block Terminator
+ */
+
+ /* application extension header */
+#ifdef GIF_ADD_APP_HEADER
+ if (loop_count >= 0 && loop_count <= 65535) {
+ bytestream_put_byte(bytestream, 0x21);
+ bytestream_put_byte(bytestream, 0xff);
+ bytestream_put_byte(bytestream, 0x0b);
+ bytestream_put_buffer(bytestream, "NETSCAPE2.0", 11); // bytes 4 to 14
+ bytestream_put_byte(bytestream, 0x03); // byte 15
+ bytestream_put_byte(bytestream, 0x01); // byte 16
+ bytestream_put_le16(bytestream, (uint16_t)loop_count);
+ bytestream_put_byte(bytestream, 0x00); // byte 19
+ }
+#endif
+ return 0;
+}
+
+/* this is maybe slow, but allows for extensions */
+static inline unsigned char gif_clut_index(uint8_t r, uint8_t g, uint8_t b)
+{
+ return ((((r)/47)%6)*6*6+(((g)/47)%6)*6+(((b)/47)%6));
+}
+
+
+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)
+{
+ PutBitContext p;
+ uint8_t buffer[200]; /* 100 * 9 / 8 = 113 */
+ int i, left, w, v;
+ 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_byte(bytestream, 0x00); /* flags */
+ /* no local clut */
+
+ bytestream_put_byte(bytestream, 0x08);
+
+ left= width * height;
+
+ 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) {
+
+ gif_put_bits_rev(&p, 9, 0x0100); /* clear code */
+
+ for(i=(left<GIF_CHUNKS)?left:GIF_CHUNKS;i;i--) {
+ if (pix_fmt == PIX_FMT_RGB24) {
+ v = gif_clut_index(ptr[0], ptr[1], ptr[2]);
+ ptr+=3;
+ } else {
+ v = *ptr++;
+ }
+ gif_put_bits_rev(&p, 9, v);
+ if (--w == 0) {
+ w = width;
+ buf += linesize;
+ ptr = buf;
+ }
+ }
+
+ if(left<=GIF_CHUNKS) {
+ gif_put_bits_rev(&p, 9, 0x101); /* end of stream */
+ gif_flush_put_bits_rev(&p);
+ }
+ if(pbBufPtr(&p) - p.buf > 0) {
+ bytestream_put_byte(bytestream, pbBufPtr(&p) - p.buf); /* byte count of the packet */
+ bytestream_put_buffer(bytestream, p.buf, pbBufPtr(&p) - p.buf); /* the actual buffer */
+ p.buf_ptr = p.buf; /* dequeue the bytes off the bitstream */
+ }
+ left-=GIF_CHUNKS;
+ }
+ bytestream_put_byte(bytestream, 0x00); /* end of image block */
+ bytestream_put_byte(bytestream, 0x3b);
+ return 0;
+}
+
+typedef struct {
+ int64_t time, file_time;
+ uint8_t buffer[100]; /* data chunks */
+ AVFrame picture;
+} GIFContext;
+
+static int gif_encode_init(AVCodecContext *avctx)
+{
+ GIFContext *s = avctx->priv_data;
+
+ avctx->coded_frame = &s->picture;
+ return 0;
+}
+
+/* better than nothing gif encoder */
+static int gif_encode_frame(AVCodecContext *avctx, unsigned char *outbuf, int buf_size, void *data)
+{
+ GIFContext *s = avctx->priv_data;
+ AVFrame *pict = data;
+ AVFrame *const p = (AVFrame *)&s->picture;
+ uint8_t *outbuf_ptr = outbuf;
+
+ *p = *pict;
+ p->pict_type = FF_I_TYPE;
+ p->key_frame = 1;
+ gif_image_write_header(&outbuf_ptr, avctx->width, avctx->height, -1, (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);
+ return outbuf_ptr - outbuf;
+}
+
+AVCodec gif_encoder = {
+ "gif",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_GIF,
+ sizeof(GIFContext),
+ gif_encode_init,
+ gif_encode_frame,
+ NULL, //encode_end,
+ .pix_fmts= (enum PixelFormat[]){PIX_FMT_PAL8, -1},
+};
diff --git a/contrib/ffmpeg/libavcodec/gifdec.c b/contrib/ffmpeg/libavcodec/gifdec.c
new file mode 100644
index 000000000..3e8a3e6bc
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/gifdec.c
@@ -0,0 +1,343 @@
+/*
+ * GIF decoder
+ * Copyright (c) 2003 Fabrice Bellard.
+ * Copyright (c) 2006 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
+ */
+
+//#define DEBUG
+
+#include "avcodec.h"
+#include "bytestream.h"
+#include "lzw.h"
+
+#define GCE_DISPOSAL_NONE 0
+#define GCE_DISPOSAL_INPLACE 1
+#define GCE_DISPOSAL_BACKGROUND 2
+#define GCE_DISPOSAL_RESTORE 3
+
+typedef struct GifState {
+ AVFrame picture;
+ int screen_width;
+ int screen_height;
+ int bits_per_pixel;
+ int background_color_index;
+ int transparent_color_index;
+ int color_resolution;
+ uint32_t *image_palette;
+
+ /* after the frame is displayed, the disposal method is used */
+ int gce_disposal;
+ /* delay during which the frame is shown */
+ int gce_delay;
+
+ /* LZW compatible decoder */
+ uint8_t *bytestream;
+ uint8_t *bytestream_end;
+ LZWState *lzw;
+
+ /* aux buffers */
+ uint8_t global_palette[256 * 3];
+ uint8_t local_palette[256 * 3];
+
+ AVCodecContext* avctx;
+} GifState;
+
+static const uint8_t gif87a_sig[6] = "GIF87a";
+static const uint8_t gif89a_sig[6] = "GIF89a";
+
+static int gif_read_image(GifState *s)
+{
+ int left, top, width, height, bits_per_pixel, code_size, flags;
+ int is_interleaved, has_local_palette, y, pass, y1, linesize, n, i;
+ uint8_t *ptr, *spal, *palette, *ptr1;
+
+ left = bytestream_get_le16(&s->bytestream);
+ top = bytestream_get_le16(&s->bytestream);
+ width = bytestream_get_le16(&s->bytestream);
+ height = bytestream_get_le16(&s->bytestream);
+ flags = bytestream_get_byte(&s->bytestream);
+ is_interleaved = flags & 0x40;
+ has_local_palette = flags & 0x80;
+ bits_per_pixel = (flags & 0x07) + 1;
+#ifdef DEBUG
+ dprintf(s->avctx, "gif: image x=%d y=%d w=%d h=%d\n", left, top, width, height);
+#endif
+
+ if (has_local_palette) {
+ bytestream_get_buffer(&s->bytestream, s->local_palette, 3 * (1 << bits_per_pixel));
+ palette = s->local_palette;
+ } else {
+ palette = s->global_palette;
+ bits_per_pixel = s->bits_per_pixel;
+ }
+
+ /* verify that all the image is inside the screen dimensions */
+ if (left + width > s->screen_width ||
+ top + height > s->screen_height)
+ return AVERROR(EINVAL);
+
+ /* build the palette */
+ n = (1 << bits_per_pixel);
+ spal = palette;
+ for(i = 0; i < n; i++) {
+ s->image_palette[i] = (0xff << 24) |
+ (spal[0] << 16) | (spal[1] << 8) | (spal[2]);
+ spal += 3;
+ }
+ for(; i < 256; i++)
+ s->image_palette[i] = (0xff << 24);
+ /* handle transparency */
+ if (s->transparent_color_index >= 0)
+ s->image_palette[s->transparent_color_index] = 0;
+
+ /* now get the image data */
+ code_size = bytestream_get_byte(&s->bytestream);
+ ff_lzw_decode_init(s->lzw, code_size, s->bytestream,
+ s->bytestream_end - s->bytestream, FF_LZW_GIF);
+
+ /* read all the image */
+ linesize = s->picture.linesize[0];
+ ptr1 = s->picture.data[0] + top * linesize + left;
+ ptr = ptr1;
+ pass = 0;
+ y1 = 0;
+ for (y = 0; y < height; y++) {
+ ff_lzw_decode(s->lzw, ptr, width);
+ if (is_interleaved) {
+ switch(pass) {
+ default:
+ case 0:
+ case 1:
+ y1 += 8;
+ ptr += linesize * 8;
+ if (y1 >= height) {
+ y1 = 4;
+ if (pass == 0)
+ ptr = ptr1 + linesize * 4;
+ else
+ ptr = ptr1 + linesize * 2;
+ pass++;
+ }
+ break;
+ case 2:
+ y1 += 4;
+ ptr += linesize * 4;
+ if (y1 >= height) {
+ y1 = 1;
+ ptr = ptr1 + linesize;
+ pass++;
+ }
+ break;
+ case 3:
+ y1 += 2;
+ ptr += linesize * 2;
+ break;
+ }
+ } else {
+ ptr += linesize;
+ }
+ }
+ /* read the garbage data until end marker is found */
+ ff_lzw_decode_tail(s->lzw);
+ s->bytestream = ff_lzw_cur_ptr(s->lzw);
+ return 0;
+}
+
+static int gif_read_extension(GifState *s)
+{
+ int ext_code, ext_len, i, gce_flags, gce_transparent_index;
+
+ /* extension */
+ ext_code = bytestream_get_byte(&s->bytestream);
+ ext_len = bytestream_get_byte(&s->bytestream);
+#ifdef DEBUG
+ dprintf(s->avctx, "gif: ext_code=0x%x len=%d\n", ext_code, ext_len);
+#endif
+ switch(ext_code) {
+ case 0xf9:
+ if (ext_len != 4)
+ goto discard_ext;
+ s->transparent_color_index = -1;
+ gce_flags = bytestream_get_byte(&s->bytestream);
+ s->gce_delay = bytestream_get_le16(&s->bytestream);
+ gce_transparent_index = bytestream_get_byte(&s->bytestream);
+ if (gce_flags & 0x01)
+ s->transparent_color_index = gce_transparent_index;
+ else
+ s->transparent_color_index = -1;
+ s->gce_disposal = (gce_flags >> 2) & 0x7;
+#ifdef DEBUG
+ dprintf(s->avctx, "gif: gce_flags=%x delay=%d tcolor=%d disposal=%d\n",
+ gce_flags, s->gce_delay,
+ s->transparent_color_index, s->gce_disposal);
+#endif
+ ext_len = bytestream_get_byte(&s->bytestream);
+ break;
+ }
+
+ /* NOTE: many extension blocks can come after */
+ discard_ext:
+ while (ext_len != 0) {
+ for (i = 0; i < ext_len; i++)
+ bytestream_get_byte(&s->bytestream);
+ ext_len = bytestream_get_byte(&s->bytestream);
+#ifdef DEBUG
+ dprintf(s->avctx, "gif: ext_len1=%d\n", ext_len);
+#endif
+ }
+ return 0;
+}
+
+static int gif_read_header1(GifState *s)
+{
+ uint8_t sig[6];
+ int v, n;
+ int has_global_palette;
+
+ if (s->bytestream_end < s->bytestream + 13)
+ return -1;
+
+ /* read gif signature */
+ bytestream_get_buffer(&s->bytestream, sig, 6);
+ if (memcmp(sig, gif87a_sig, 6) != 0 &&
+ memcmp(sig, gif89a_sig, 6) != 0)
+ return -1;
+
+ /* read screen header */
+ s->transparent_color_index = -1;
+ s->screen_width = bytestream_get_le16(&s->bytestream);
+ s->screen_height = bytestream_get_le16(&s->bytestream);
+ if( (unsigned)s->screen_width > 32767
+ || (unsigned)s->screen_height > 32767){
+ av_log(NULL, AV_LOG_ERROR, "picture size too large\n");
+ return -1;
+ }
+
+ v = bytestream_get_byte(&s->bytestream);
+ s->color_resolution = ((v & 0x70) >> 4) + 1;
+ has_global_palette = (v & 0x80);
+ s->bits_per_pixel = (v & 0x07) + 1;
+ s->background_color_index = bytestream_get_byte(&s->bytestream);
+ bytestream_get_byte(&s->bytestream); /* ignored */
+#ifdef DEBUG
+ dprintf(s->avctx, "gif: screen_w=%d screen_h=%d bpp=%d global_palette=%d\n",
+ s->screen_width, s->screen_height, s->bits_per_pixel,
+ has_global_palette);
+#endif
+ if (has_global_palette) {
+ n = 1 << s->bits_per_pixel;
+ if (s->bytestream_end < s->bytestream + n * 3)
+ return -1;
+ bytestream_get_buffer(&s->bytestream, s->global_palette, n * 3);
+ }
+ return 0;
+}
+
+static int gif_parse_next_image(GifState *s)
+{
+ while (s->bytestream < s->bytestream_end) {
+ int code = bytestream_get_byte(&s->bytestream);
+#ifdef DEBUG
+ dprintf(s->avctx, "gif: code=%02x '%c'\n", code, code);
+#endif
+ switch (code) {
+ case ',':
+ if (gif_read_image(s) < 0)
+ return -1;
+ return 0;
+ case ';':
+ /* end of image */
+ return -1;
+ case '!':
+ if (gif_read_extension(s) < 0)
+ return -1;
+ break;
+ default:
+ /* error or errneous EOF */
+ return -1;
+ }
+ }
+ return -1;
+}
+
+static int gif_decode_init(AVCodecContext *avctx)
+{
+ GifState *s = avctx->priv_data;
+
+ s->avctx = avctx;
+
+ avcodec_get_frame_defaults(&s->picture);
+ avctx->coded_frame= &s->picture;
+ s->picture.data[0] = NULL;
+ ff_lzw_decode_open(&s->lzw);
+ return 0;
+}
+
+static int gif_decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size)
+{
+ GifState *s = avctx->priv_data;
+ AVFrame *picture = data;
+ int ret;
+
+ s->bytestream = buf;
+ s->bytestream_end = buf + buf_size;
+ if (gif_read_header1(s) < 0)
+ return -1;
+
+ avctx->pix_fmt = PIX_FMT_PAL8;
+ if (avcodec_check_dimensions(avctx, s->screen_width, s->screen_height))
+ return -1;
+ avcodec_set_dimensions(avctx, s->screen_width, s->screen_height);
+
+ if (s->picture.data[0])
+ avctx->release_buffer(avctx, &s->picture);
+ if (avctx->get_buffer(avctx, &s->picture) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ return -1;
+ }
+ s->image_palette = (uint32_t *)s->picture.data[1];
+ ret = gif_parse_next_image(s);
+ if (ret < 0)
+ return ret;
+
+ *picture = s->picture;
+ *data_size = sizeof(AVPicture);
+ return s->bytestream - buf;
+}
+
+static int gif_decode_close(AVCodecContext *avctx)
+{
+ GifState *s = avctx->priv_data;
+
+ ff_lzw_decode_close(&s->lzw);
+ if(s->picture.data[0])
+ avctx->release_buffer(avctx, &s->picture);
+ return 0;
+}
+
+AVCodec gif_decoder = {
+ "gif",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_GIF,
+ sizeof(GifState),
+ gif_decode_init,
+ NULL,
+ gif_decode_close,
+ gif_decode_frame,
+};
diff --git a/src/libffmpeg/libavcodec/golomb.c b/contrib/ffmpeg/libavcodec/golomb.c
index 50df4fc40..50df4fc40 100644
--- a/src/libffmpeg/libavcodec/golomb.c
+++ b/contrib/ffmpeg/libavcodec/golomb.c
diff --git a/src/libffmpeg/libavcodec/golomb.h b/contrib/ffmpeg/libavcodec/golomb.h
index 9bf7aec46..9bf7aec46 100644
--- a/src/libffmpeg/libavcodec/golomb.h
+++ b/contrib/ffmpeg/libavcodec/golomb.h
diff --git a/contrib/ffmpeg/libavcodec/h261.c b/contrib/ffmpeg/libavcodec/h261.c
new file mode 100644
index 000000000..83f3136e3
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/h261.c
@@ -0,0 +1,1057 @@
+/*
+ * H261 decoder
+ * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
+ * Copyright (c) 2004 Maarten Daniels
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 h261.c
+ * h261codec.
+ */
+
+#include "common.h"
+#include "dsputil.h"
+#include "avcodec.h"
+#include "mpegvideo.h"
+#include "h261data.h"
+
+
+#define H261_MBA_VLC_BITS 9
+#define H261_MTYPE_VLC_BITS 6
+#define H261_MV_VLC_BITS 7
+#define H261_CBP_VLC_BITS 9
+#define TCOEFF_VLC_BITS 9
+
+#define MBA_STUFFING 33
+#define MBA_STARTCODE 34
+#define IS_FIL(a) ((a)&MB_TYPE_H261_FIL)
+
+/**
+ * H261Context
+ */
+typedef struct H261Context{
+ MpegEncContext s;
+
+ int current_mba;
+ int previous_mba;
+ int mba_diff;
+ int mtype;
+ int current_mv_x;
+ int current_mv_y;
+ int gob_number;
+ int gob_start_code_skipped; // 1 if gob start code is already read before gob header is read
+}H261Context;
+
+static uint8_t static_rl_table_store[2][2*MAX_RUN + MAX_LEVEL + 3];
+
+void ff_h261_loop_filter(MpegEncContext *s){
+ H261Context * h= (H261Context*)s;
+ const int linesize = s->linesize;
+ const int uvlinesize= s->uvlinesize;
+ uint8_t *dest_y = s->dest[0];
+ uint8_t *dest_cb= s->dest[1];
+ uint8_t *dest_cr= s->dest[2];
+
+ if(!(IS_FIL (h->mtype)))
+ return;
+
+ s->dsp.h261_loop_filter(dest_y , linesize);
+ s->dsp.h261_loop_filter(dest_y + 8, linesize);
+ s->dsp.h261_loop_filter(dest_y + 8 * linesize , linesize);
+ s->dsp.h261_loop_filter(dest_y + 8 * linesize + 8, linesize);
+ s->dsp.h261_loop_filter(dest_cb, uvlinesize);
+ s->dsp.h261_loop_filter(dest_cr, uvlinesize);
+}
+
+int ff_h261_get_picture_format(int width, int height){
+ // QCIF
+ if (width == 176 && height == 144)
+ return 0;
+ // CIF
+ else if (width == 352 && height == 288)
+ return 1;
+ // ERROR
+ else
+ return -1;
+}
+
+static void h261_encode_block(H261Context * h, DCTELEM * block,
+ int n);
+static int h261_decode_block(H261Context *h, DCTELEM *block,
+ int n, int coded);
+
+void ff_h261_encode_picture_header(MpegEncContext * s, int picture_number){
+ H261Context * h = (H261Context *) s;
+ int format, temp_ref;
+
+ align_put_bits(&s->pb);
+
+ /* Update the pointer to last GOB */
+ s->ptr_lastgob = pbBufPtr(&s->pb);
+
+ put_bits(&s->pb, 20, 0x10); /* PSC */
+
+ temp_ref= s->picture_number * (int64_t)30000 * s->avctx->time_base.num /
+ (1001 * (int64_t)s->avctx->time_base.den); //FIXME maybe this should use a timestamp
+ put_bits(&s->pb, 5, temp_ref & 0x1f); /* TemporalReference */
+
+ 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_h261_get_picture_format(s->width, s->height);
+
+ put_bits(&s->pb, 1, format); /* 0 == QCIF, 1 == CIF */
+
+ put_bits(&s->pb, 1, 0); /* still image mode */
+ put_bits(&s->pb, 1, 0); /* reserved */
+
+ put_bits(&s->pb, 1, 0); /* no PEI */
+ if(format == 0)
+ h->gob_number = -1;
+ else
+ h->gob_number = 0;
+ h->current_mba = 0;
+}
+
+/**
+ * Encodes a group of blocks header.
+ */
+static void h261_encode_gob_header(MpegEncContext * s, int mb_line){
+ H261Context * h = (H261Context *)s;
+ if(ff_h261_get_picture_format(s->width, s->height) == 0){
+ h->gob_number+=2; // QCIF
+ }
+ else{
+ h->gob_number++; // CIF
+ }
+ put_bits(&s->pb, 16, 1); /* GBSC */
+ put_bits(&s->pb, 4, h->gob_number); /* GN */
+ put_bits(&s->pb, 5, s->qscale); /* GQUANT */
+ put_bits(&s->pb, 1, 0); /* no GEI */
+ h->current_mba = 0;
+ h->previous_mba = 0;
+ h->current_mv_x=0;
+ h->current_mv_y=0;
+}
+
+void ff_h261_reorder_mb_index(MpegEncContext* s){
+ int index= s->mb_x + s->mb_y*s->mb_width;
+
+ if(index % 33 == 0)
+ h261_encode_gob_header(s,0);
+
+ /* for CIF the GOB's are fragmented in the middle of a scanline
+ that's why we need to adjust the x and y index of the macroblocks */
+ if(ff_h261_get_picture_format(s->width,s->height) == 1){ // CIF
+ s->mb_x = index % 11 ; index /= 11;
+ s->mb_y = index % 3 ; index /= 3;
+ s->mb_x+= 11*(index % 2); index /= 2;
+ s->mb_y+= 3*index;
+
+ ff_init_block_index(s);
+ ff_update_block_index(s);
+ }
+}
+
+static void h261_encode_motion(H261Context * h, int val){
+ MpegEncContext * const s = &h->s;
+ int sign, code;
+ if(val==0){
+ code = 0;
+ put_bits(&s->pb,h261_mv_tab[code][1],h261_mv_tab[code][0]);
+ }
+ else{
+ if(val > 15)
+ val -=32;
+ if(val < -16)
+ val+=32;
+ sign = val < 0;
+ code = sign ? -val : val;
+ put_bits(&s->pb,h261_mv_tab[code][1],h261_mv_tab[code][0]);
+ put_bits(&s->pb,1,sign);
+ }
+}
+
+static inline int get_cbp(MpegEncContext * s,
+ DCTELEM block[6][64])
+{
+ int i, cbp;
+ cbp= 0;
+ for (i = 0; i < 6; i++) {
+ if (s->block_last_index[i] >= 0)
+ cbp |= 1 << (5 - i);
+ }
+ return cbp;
+}
+void ff_h261_encode_mb(MpegEncContext * s,
+ DCTELEM block[6][64],
+ int motion_x, int motion_y)
+{
+ H261Context * h = (H261Context *)s;
+ int mvd, mv_diff_x, mv_diff_y, i, cbp;
+ cbp = 63; // avoid warning
+ mvd = 0;
+
+ h->current_mba++;
+ h->mtype = 0;
+
+ if (!s->mb_intra){
+ /* compute cbp */
+ cbp= get_cbp(s, block);
+
+ /* mvd indicates if this block is motion compensated */
+ mvd = motion_x | motion_y;
+
+ if((cbp | mvd | s->dquant ) == 0) {
+ /* skip macroblock */
+ s->skip_count++;
+ h->current_mv_x=0;
+ h->current_mv_y=0;
+ return;
+ }
+ }
+
+ /* MB is not skipped, encode MBA */
+ put_bits(&s->pb, h261_mba_bits[(h->current_mba-h->previous_mba)-1], h261_mba_code[(h->current_mba-h->previous_mba)-1]);
+
+ /* calculate MTYPE */
+ if(!s->mb_intra){
+ h->mtype++;
+
+ if(mvd || s->loop_filter)
+ h->mtype+=3;
+ if(s->loop_filter)
+ h->mtype+=3;
+ if(cbp || s->dquant)
+ h->mtype++;
+ assert(h->mtype > 1);
+ }
+
+ if(s->dquant)
+ h->mtype++;
+
+ put_bits(&s->pb, h261_mtype_bits[h->mtype], h261_mtype_code[h->mtype]);
+
+ h->mtype = h261_mtype_map[h->mtype];
+
+ if(IS_QUANT(h->mtype)){
+ ff_set_qscale(s,s->qscale+s->dquant);
+ put_bits(&s->pb, 5, s->qscale);
+ }
+
+ if(IS_16X16(h->mtype)){
+ mv_diff_x = (motion_x >> 1) - h->current_mv_x;
+ mv_diff_y = (motion_y >> 1) - h->current_mv_y;
+ h->current_mv_x = (motion_x >> 1);
+ h->current_mv_y = (motion_y >> 1);
+ h261_encode_motion(h,mv_diff_x);
+ h261_encode_motion(h,mv_diff_y);
+ }
+
+ h->previous_mba = h->current_mba;
+
+ if(HAS_CBP(h->mtype)){
+ assert(cbp>0);
+ put_bits(&s->pb,h261_cbp_tab[cbp-1][1],h261_cbp_tab[cbp-1][0]);
+ }
+ for(i=0; i<6; i++) {
+ /* encode each block */
+ h261_encode_block(h, block[i], i);
+ }
+
+ if ( ( h->current_mba == 11 ) || ( h->current_mba == 22 ) || ( h->current_mba == 33 ) || ( !IS_16X16 ( h->mtype ) )){
+ h->current_mv_x=0;
+ h->current_mv_y=0;
+ }
+}
+
+void ff_h261_encode_init(MpegEncContext *s){
+ static int done = 0;
+
+ if (!done) {
+ done = 1;
+ init_rl(&h261_rl_tcoeff, static_rl_table_store);
+ }
+
+ 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 h261_encode_block(H261Context * h, DCTELEM * block, int n){
+ MpegEncContext * const s = &h->s;
+ int level, run, last, i, j, last_index, last_non_zero, sign, slevel, code;
+ RLTable *rl;
+
+ rl = &h261_rl_tcoeff;
+ if (s->mb_intra) {
+ /* 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)
+ put_bits(&s->pb, 8, 0xff);
+ else
+ put_bits(&s->pb, 8, level);
+ i = 1;
+ } else if((block[0]==1 || block[0] == -1) && (s->block_last_index[n] > -1)){
+ //special case
+ put_bits(&s->pb,2,block[0]>0 ? 2 : 3 );
+ i = 1;
+ } else {
+ i = 0;
+ }
+
+ /* 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, 0 /*no last in H.261, EOB is used*/, run, level);
+ if(run==0 && level < 16)
+ code+=1;
+ put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
+ if (code == rl->n) {
+ put_bits(&s->pb, 6, run);
+ assert(slevel != 0);
+ assert(level <= 127);
+ put_bits(&s->pb, 8, slevel & 0xff);
+ } else {
+ put_bits(&s->pb, 1, sign);
+ }
+ last_non_zero = i;
+ }
+ }
+ if(last_index > -1){
+ put_bits(&s->pb, rl->table_vlc[0][1], rl->table_vlc[0][0]);// END OF BLOCK
+ }
+}
+
+/***********************************************/
+/* decoding */
+
+static VLC h261_mba_vlc;
+static VLC h261_mtype_vlc;
+static VLC h261_mv_vlc;
+static VLC h261_cbp_vlc;
+
+static void h261_decode_init_vlc(H261Context *h){
+ static int done = 0;
+
+ if(!done){
+ done = 1;
+ init_vlc(&h261_mba_vlc, H261_MBA_VLC_BITS, 35,
+ h261_mba_bits, 1, 1,
+ h261_mba_code, 1, 1, 1);
+ init_vlc(&h261_mtype_vlc, H261_MTYPE_VLC_BITS, 10,
+ h261_mtype_bits, 1, 1,
+ h261_mtype_code, 1, 1, 1);
+ init_vlc(&h261_mv_vlc, H261_MV_VLC_BITS, 17,
+ &h261_mv_tab[0][1], 2, 1,
+ &h261_mv_tab[0][0], 2, 1, 1);
+ init_vlc(&h261_cbp_vlc, H261_CBP_VLC_BITS, 63,
+ &h261_cbp_tab[0][1], 2, 1,
+ &h261_cbp_tab[0][0], 2, 1, 1);
+ init_rl(&h261_rl_tcoeff, static_rl_table_store);
+ init_vlc_rl(&h261_rl_tcoeff, 1);
+ }
+}
+
+static int h261_decode_init(AVCodecContext *avctx){
+ H261Context *h= avctx->priv_data;
+ MpegEncContext * const s = &h->s;
+
+ // set defaults
+ MPV_decode_defaults(s);
+ s->avctx = avctx;
+
+ s->width = s->avctx->coded_width;
+ s->height = s->avctx->coded_height;
+ s->codec_id = s->avctx->codec->id;
+
+ s->out_format = FMT_H261;
+ s->low_delay= 1;
+ avctx->pix_fmt= PIX_FMT_YUV420P;
+
+ s->codec_id= avctx->codec->id;
+
+ h261_decode_init_vlc(h);
+
+ h->gob_start_code_skipped = 0;
+
+ return 0;
+}
+
+/**
+ * decodes the group of blocks header or slice header.
+ * @return <0 if an error occured
+ */
+static int h261_decode_gob_header(H261Context *h){
+ unsigned int val;
+ MpegEncContext * const s = &h->s;
+
+ if ( !h->gob_start_code_skipped ){
+ /* Check for GOB Start Code */
+ val = show_bits(&s->gb, 15);
+ if(val)
+ return -1;
+
+ /* We have a GBSC */
+ skip_bits(&s->gb, 16);
+ }
+
+ h->gob_start_code_skipped = 0;
+
+ h->gob_number = get_bits(&s->gb, 4); /* GN */
+ s->qscale = get_bits(&s->gb, 5); /* GQUANT */
+
+ /* Check if gob_number is valid */
+ if (s->mb_height==18){ //cif
+ if ((h->gob_number<=0) || (h->gob_number>12))
+ return -1;
+ }
+ else{ //qcif
+ if ((h->gob_number!=1) && (h->gob_number!=3) && (h->gob_number!=5))
+ return -1;
+ }
+
+ /* GEI */
+ while (get_bits1(&s->gb) != 0) {
+ skip_bits(&s->gb, 8);
+ }
+
+ if(s->qscale==0)
+ return -1;
+
+ // For the first transmitted macroblock in a GOB, MBA is the absolute address. For
+ // subsequent macroblocks, MBA is the difference between the absolute addresses of
+ // the macroblock and the last transmitted macroblock.
+ h->current_mba = 0;
+ h->mba_diff = 0;
+
+ return 0;
+}
+
+/**
+ * decodes the group of blocks / video packet header.
+ * @return <0 if no resync found
+ */
+static int ff_h261_resync(H261Context *h){
+ MpegEncContext * const s = &h->s;
+ int left, ret;
+
+ if ( h->gob_start_code_skipped ){
+ ret= h261_decode_gob_header(h);
+ if(ret>=0)
+ return 0;
+ }
+ else{
+ if(show_bits(&s->gb, 15)==0){
+ ret= h261_decode_gob_header(h);
+ if(ret>=0)
+ return 0;
+ }
+ //ok, its not where its 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>15+1+4+5; left-=8){
+ if(show_bits(&s->gb, 15)==0){
+ GetBitContext bak= s->gb;
+
+ ret= h261_decode_gob_header(h);
+ if(ret>=0)
+ return 0;
+
+ s->gb= bak;
+ }
+ skip_bits(&s->gb, 8);
+ }
+ }
+
+ return -1;
+}
+
+/**
+ * decodes skipped macroblocks
+ * @return 0
+ */
+static int h261_decode_mb_skipped(H261Context *h, int mba1, int mba2 )
+{
+ MpegEncContext * const s = &h->s;
+ int i;
+
+ s->mb_intra = 0;
+
+ for(i=mba1; i<mba2; i++){
+ int j, xy;
+
+ s->mb_x= ((h->gob_number-1) % 2) * 11 + i % 11;
+ s->mb_y= ((h->gob_number-1) / 2) * 3 + i / 11;
+ xy = s->mb_x + s->mb_y * s->mb_stride;
+ ff_init_block_index(s);
+ ff_update_block_index(s);
+
+ for(j=0;j<6;j++)
+ s->block_last_index[j] = -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 = 1;
+ h->mtype &= ~MB_TYPE_H261_FIL;
+
+ MPV_decode_mb(s, s->block);
+ }
+
+ return 0;
+}
+
+static int decode_mv_component(GetBitContext *gb, int v){
+ int mv_diff = get_vlc2(gb, h261_mv_vlc.table, H261_MV_VLC_BITS, 2);
+
+ /* check if mv_diff is valid */
+ if ( mv_diff < 0 )
+ return v;
+
+ mv_diff = mvmap[mv_diff];
+
+ if(mv_diff && !get_bits1(gb))
+ mv_diff= -mv_diff;
+
+ v += mv_diff;
+ if (v <=-16) v+= 32;
+ else if(v >= 16) v-= 32;
+
+ return v;
+}
+
+static int h261_decode_mb(H261Context *h){
+ MpegEncContext * const s = &h->s;
+ int i, cbp, xy;
+
+ cbp = 63;
+ // Read mba
+ do{
+ h->mba_diff = get_vlc2(&s->gb, h261_mba_vlc.table, H261_MBA_VLC_BITS, 2);
+
+ /* Check for slice end */
+ /* NOTE: GOB can be empty (no MB data) or exist only of MBA_stuffing */
+ if (h->mba_diff == MBA_STARTCODE){ // start code
+ h->gob_start_code_skipped = 1;
+ return SLICE_END;
+ }
+ }
+ while( h->mba_diff == MBA_STUFFING ); // stuffing
+
+ if ( h->mba_diff < 0 ){
+ if ( get_bits_count(&s->gb) + 7 >= s->gb.size_in_bits )
+ return SLICE_END;
+
+ av_log(s->avctx, AV_LOG_ERROR, "illegal mba at %d %d\n", s->mb_x, s->mb_y);
+ return SLICE_ERROR;
+ }
+
+ h->mba_diff += 1;
+ h->current_mba += h->mba_diff;
+
+ if ( h->current_mba > MBA_STUFFING )
+ return SLICE_ERROR;
+
+ s->mb_x= ((h->gob_number-1) % 2) * 11 + ((h->current_mba-1) % 11);
+ s->mb_y= ((h->gob_number-1) / 2) * 3 + ((h->current_mba-1) / 11);
+ xy = s->mb_x + s->mb_y * s->mb_stride;
+ ff_init_block_index(s);
+ ff_update_block_index(s);
+
+ // Read mtype
+ h->mtype = get_vlc2(&s->gb, h261_mtype_vlc.table, H261_MTYPE_VLC_BITS, 2);
+ h->mtype = h261_mtype_map[h->mtype];
+
+ // Read mquant
+ if ( IS_QUANT ( h->mtype ) ){
+ ff_set_qscale(s, get_bits(&s->gb, 5));
+ }
+
+ s->mb_intra = IS_INTRA4x4(h->mtype);
+
+ // Read mv
+ if ( IS_16X16 ( h->mtype ) ){
+ // Motion vector data is included for all MC macroblocks. MVD is obtained from the macroblock vector by subtracting the
+ // vector of the preceding macroblock. For this calculation the vector of the preceding macroblock is regarded as zero in the
+ // following three situations:
+ // 1) evaluating MVD for macroblocks 1, 12 and 23;
+ // 2) evaluating MVD for macroblocks in which MBA does not represent a difference of 1;
+ // 3) MTYPE of the previous macroblock was not MC.
+ if ( ( h->current_mba == 1 ) || ( h->current_mba == 12 ) || ( h->current_mba == 23 ) ||
+ ( h->mba_diff != 1))
+ {
+ h->current_mv_x = 0;
+ h->current_mv_y = 0;
+ }
+
+ h->current_mv_x= decode_mv_component(&s->gb, h->current_mv_x);
+ h->current_mv_y= decode_mv_component(&s->gb, h->current_mv_y);
+ }else{
+ h->current_mv_x = 0;
+ h->current_mv_y = 0;
+ }
+
+ // Read cbp
+ if ( HAS_CBP( h->mtype ) ){
+ cbp = get_vlc2(&s->gb, h261_cbp_vlc.table, H261_CBP_VLC_BITS, 2) + 1;
+ }
+
+ if(s->mb_intra){
+ s->current_picture.mb_type[xy]= MB_TYPE_INTRA;
+ goto intra;
+ }
+
+ //set motion vectors
+ s->mv_dir = MV_DIR_FORWARD;
+ s->mv_type = MV_TYPE_16X16;
+ s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0;
+ s->mv[0][0][0] = h->current_mv_x * 2;//gets divided by 2 in motion compensation
+ s->mv[0][0][1] = h->current_mv_y * 2;
+
+intra:
+ /* decode each block */
+ if(s->mb_intra || HAS_CBP(h->mtype)){
+ s->dsp.clear_blocks(s->block[0]);
+ for (i = 0; i < 6; i++) {
+ if (h261_decode_block(h, s->block[i], i, cbp&32) < 0){
+ return SLICE_ERROR;
+ }
+ cbp+=cbp;
+ }
+ }else{
+ for (i = 0; i < 6; i++)
+ s->block_last_index[i]= -1;
+ }
+
+ MPV_decode_mb(s, s->block);
+
+ return SLICE_OK;
+}
+
+/**
+ * decodes a macroblock
+ * @return <0 if an error occured
+ */
+static int h261_decode_block(H261Context * h, DCTELEM * block,
+ int n, int coded)
+{
+ MpegEncContext * const s = &h->s;
+ int code, level, i, j, run;
+ RLTable *rl = &h261_rl_tcoeff;
+ const uint8_t *scan_table;
+
+ // For the variable length encoding there are two code tables, one being used for
+ // the first transmitted LEVEL in INTER, INTER+MC and INTER+MC+FIL blocks, the second
+ // for all other LEVELs except the first one in INTRA blocks which is fixed length
+ // coded with 8 bits.
+ // NOTE: the two code tables only differ in one VLC so we handle that manually.
+ scan_table = s->intra_scantable.permutated;
+ if (s->mb_intra){
+ /* DC coef */
+ level = get_bits(&s->gb, 8);
+ // 0 (00000000b) and -128 (10000000b) are FORBIDDEN
+ 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);
+ return -1;
+ }
+ // The code 1000 0000 is not used, the reconstruction level of 1024 being coded as 1111 1111.
+ if (level == 255)
+ level = 128;
+ block[0] = level;
+ i = 1;
+ }else if(coded){
+ // Run Level Code
+ // EOB Not possible for first level when cbp is available (that's why the table is different)
+ // 0 1 1s
+ // * * 0*
+ int check = show_bits(&s->gb, 2);
+ i = 0;
+ if ( check & 0x2 ){
+ skip_bits(&s->gb, 2);
+ block[0] = ( check & 0x1 ) ? -1 : 1;
+ i = 1;
+ }
+ }else{
+ i = 0;
+ }
+ if(!coded){
+ s->block_last_index[n] = i - 1;
+ return 0;
+ }
+ for(;;){
+ code = get_vlc2(&s->gb, rl->vlc.table, TCOEFF_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 */
+ // The remaining combinations of (run, level) are encoded with a 20-bit word consisting of 6 bits escape, 6 bits run and 8 bits level.
+ run = get_bits(&s->gb, 6);
+ level = get_sbits(&s->gb, 8);
+ }else if(code == 0){
+ break;
+ }else{
+ run = rl->table_run[code];
+ level = rl->table_level[code];
+ if (get_bits1(&s->gb))
+ level = -level;
+ }
+ i += run;
+ if (i >= 64){
+ av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d\n", s->mb_x, s->mb_y);
+ return -1;
+ }
+ j = scan_table[i];
+ block[j] = level;
+ i++;
+ }
+ s->block_last_index[n] = i-1;
+ return 0;
+}
+
+/**
+ * decodes the H261 picture header.
+ * @return <0 if no startcode found
+ */
+static int h261_decode_picture_header(H261Context *h){
+ MpegEncContext * const s = &h->s;
+ int format, i;
+ uint32_t startcode= 0;
+
+ for(i= s->gb.size_in_bits - get_bits_count(&s->gb); i>24; i-=1){
+ startcode = ((startcode << 1) | get_bits(&s->gb, 1)) & 0x000FFFFF;
+
+ if(startcode == 0x10)
+ break;
+ }
+
+ if (startcode != 0x10){
+ av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
+ return -1;
+ }
+
+ /* temporal reference */
+ i= get_bits(&s->gb, 5); /* picture timestamp */
+ if(i < (s->picture_number&31))
+ i += 32;
+ s->picture_number = (s->picture_number&~31) + i;
+
+ s->avctx->time_base= (AVRational){1001, 30000};
+ s->current_picture.pts= s->picture_number;
+
+
+ /* PTYPE starts here */
+ skip_bits1(&s->gb); /* split screen off */
+ skip_bits1(&s->gb); /* camera off */
+ skip_bits1(&s->gb); /* freeze picture release off */
+
+ format = get_bits1(&s->gb);
+
+ //only 2 formats possible
+ if (format == 0){//QCIF
+ s->width = 176;
+ s->height = 144;
+ s->mb_width = 11;
+ s->mb_height = 9;
+ }else{//CIF
+ s->width = 352;
+ s->height = 288;
+ s->mb_width = 22;
+ s->mb_height = 18;
+ }
+
+ s->mb_num = s->mb_width * s->mb_height;
+
+ skip_bits1(&s->gb); /* still image mode off */
+ skip_bits1(&s->gb); /* Reserved */
+
+ /* PEI */
+ while (get_bits1(&s->gb) != 0){
+ skip_bits(&s->gb, 8);
+ }
+
+ // h261 has no I-FRAMES, but if we pass I_TYPE for the first frame, the codec crashes if it does
+ // not contain all I-blocks (e.g. when a packet is lost)
+ s->pict_type = P_TYPE;
+
+ h->gob_number = 0;
+ return 0;
+}
+
+static int h261_decode_gob(H261Context *h){
+ MpegEncContext * const s = &h->s;
+
+ ff_set_qscale(s, s->qscale);
+
+ /* decode mb's */
+ while(h->current_mba <= MBA_STUFFING)
+ {
+ int ret;
+ /* DCT & quantize */
+ ret= h261_decode_mb(h);
+ if(ret<0){
+ if(ret==SLICE_END){
+ h261_decode_mb_skipped(h, h->current_mba, 33);
+ return 0;
+ }
+ av_log(s->avctx, AV_LOG_ERROR, "Error at MB: %d\n", s->mb_x + s->mb_y*s->mb_stride);
+ return -1;
+ }
+
+ h261_decode_mb_skipped(h, h->current_mba-h->mba_diff, h->current_mba-1);
+ }
+
+ return -1;
+}
+
+#ifdef CONFIG_H261_PARSER
+static int h261_find_frame_end(ParseContext *pc, AVCodecContext* avctx, const uint8_t *buf, int buf_size){
+ int vop_found, i, j;
+ uint32_t state;
+
+ vop_found= pc->frame_start_found;
+ state= pc->state;
+
+ for(i=0; i<buf_size && !vop_found; i++){
+ state= (state<<8) | buf[i];
+ for(j=0; j<8; j++){
+ if(((state>>j)&0xFFFFF) == 0x00010){
+ vop_found=1;
+ break;
+ }
+ }
+ }
+ if(vop_found){
+ for(; i<buf_size; i++){
+ state= (state<<8) | buf[i];
+ for(j=0; j<8; j++){
+ if(((state>>j)&0xFFFFF) == 0x00010){
+ pc->frame_start_found=0;
+ pc->state= state>>(2*8);
+ return i-1;
+ }
+ }
+ }
+ }
+
+ pc->frame_start_found= vop_found;
+ pc->state= state;
+ return END_NOT_FOUND;
+}
+
+static int h261_parse(AVCodecParserContext *s,
+ AVCodecContext *avctx,
+ uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size)
+{
+ ParseContext *pc = s->priv_data;
+ int next;
+
+ next= h261_find_frame_end(pc,avctx, buf, buf_size);
+ if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
+ *poutbuf = NULL;
+ *poutbuf_size = 0;
+ return buf_size;
+ }
+ *poutbuf = (uint8_t *)buf;
+ *poutbuf_size = buf_size;
+ return next;
+}
+#endif
+
+/**
+ * returns the number of bytes consumed for building the current frame
+ */
+static int get_consumed_bytes(MpegEncContext *s, int buf_size){
+ int pos= get_bits_count(&s->gb)>>3;
+ if(pos==0) pos=1; //avoid infinite loops (i doubt thats needed but ...)
+ if(pos+10>buf_size) pos=buf_size; // oops ;)
+
+ return pos;
+}
+
+static int h261_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ H261Context *h= avctx->priv_data;
+ MpegEncContext *s = &h->s;
+ int ret;
+ AVFrame *pict = data;
+
+#ifdef DEBUG
+ av_log(avctx, AV_LOG_DEBUG, "*****frame %d size=%d\n", avctx->frame_number, buf_size);
+ av_log(avctx, AV_LOG_DEBUG, "bytes=%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]);
+#endif
+ s->flags= avctx->flags;
+ s->flags2= avctx->flags2;
+
+ h->gob_start_code_skipped=0;
+
+retry:
+
+ init_get_bits(&s->gb, buf, buf_size*8);
+
+ if(!s->context_initialized){
+ if (MPV_common_init(s) < 0) //we need the idct permutaton for reading a custom matrix
+ return -1;
+ }
+
+ //we need to set current_picture_ptr before reading the header, otherwise we cant store anyting im there
+ if(s->current_picture_ptr==NULL || s->current_picture_ptr->data[0]){
+ int i= ff_find_unused_picture(s, 0);
+ s->current_picture_ptr= &s->picture[i];
+ }
+
+ ret = h261_decode_picture_header(h);
+
+ /* skip if the header was thrashed */
+ if (ret < 0){
+ av_log(s->avctx, AV_LOG_ERROR, "header damaged\n");
+ return -1;
+ }
+
+ if (s->width != avctx->coded_width || s->height != avctx->coded_height){
+ ParseContext pc= s->parse_context; //FIXME move these demuxng hack to avformat
+ s->parse_context.buffer=0;
+ MPV_common_end(s);
+ s->parse_context= pc;
+ }
+ if (!s->context_initialized) {
+ avcodec_set_dimensions(avctx, s->width, s->height);
+
+ goto retry;
+ }
+
+ // for hurry_up==5
+ s->current_picture.pict_type= s->pict_type;
+ s->current_picture.key_frame= s->pict_type == I_TYPE;
+
+ /* skip everything if we are in a hurry>=5 */
+ if(avctx->hurry_up>=5) return get_consumed_bytes(s, buf_size);
+ if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==B_TYPE)
+ ||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=I_TYPE)
+ || avctx->skip_frame >= AVDISCARD_ALL)
+ return get_consumed_bytes(s, buf_size);
+
+ if(MPV_frame_start(s, avctx) < 0)
+ return -1;
+
+ ff_er_frame_start(s);
+
+ /* decode each macroblock */
+ s->mb_x=0;
+ s->mb_y=0;
+
+ while(h->gob_number < (s->mb_height==18 ? 12 : 5)){
+ if(ff_h261_resync(h)<0)
+ break;
+ h261_decode_gob(h);
+ }
+ MPV_frame_end(s);
+
+assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type);
+assert(s->current_picture.pict_type == s->pict_type);
+ *pict= *(AVFrame*)s->current_picture_ptr;
+ ff_print_debug_info(s, pict);
+
+ *data_size = sizeof(AVFrame);
+
+ return get_consumed_bytes(s, buf_size);
+}
+
+static int h261_decode_end(AVCodecContext *avctx)
+{
+ H261Context *h= avctx->priv_data;
+ MpegEncContext *s = &h->s;
+
+ MPV_common_end(s);
+ return 0;
+}
+
+#ifdef CONFIG_ENCODERS
+AVCodec h261_encoder = {
+ "h261",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_H261,
+ sizeof(H261Context),
+ MPV_encode_init,
+ MPV_encode_picture,
+ MPV_encode_end,
+ .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1},
+};
+#endif
+
+AVCodec h261_decoder = {
+ "h261",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_H261,
+ sizeof(H261Context),
+ h261_decode_init,
+ NULL,
+ h261_decode_end,
+ h261_decode_frame,
+ CODEC_CAP_DR1,
+};
+
+#ifdef CONFIG_H261_PARSER
+AVCodecParser h261_parser = {
+ { CODEC_ID_H261 },
+ sizeof(ParseContext),
+ NULL,
+ h261_parse,
+ ff_parse_close,
+};
+#endif
diff --git a/src/libffmpeg/libavcodec/h261data.h b/contrib/ffmpeg/libavcodec/h261data.h
index 2a93b73e3..2a93b73e3 100644
--- a/src/libffmpeg/libavcodec/h261data.h
+++ b/contrib/ffmpeg/libavcodec/h261data.h
diff --git a/contrib/ffmpeg/libavcodec/h263.c b/contrib/ffmpeg/libavcodec/h263.c
new file mode 100644
index 000000000..4db89e970
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/h263.c
@@ -0,0 +1,6311 @@
+/*
+ * H263/MPEG4 backend for ffmpeg encoder and decoder
+ * Copyright (c) 2000,2001 Fabrice Bellard.
+ * H263+ support.
+ * Copyright (c) 2001 Juan J. Sierralta P.
+ * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * ac prediction encoding, b-frame support, error resilience, optimizations,
+ * qpel decoding, gmc decoding, interlaced decoding,
+ * by Michael Niedermayer <michaelni@gmx.at>
+ */
+
+/**
+ * @file h263.c
+ * h263/mpeg4 codec.
+ */
+
+//#define DEBUG
+#include <limits.h>
+
+#include "common.h"
+#include "dsputil.h"
+#include "avcodec.h"
+#include "mpegvideo.h"
+#include "h263data.h"
+#include "mpeg4data.h"
+
+//#undef NDEBUG
+//#include <assert.h>
+
+#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
+
+#ifdef CONFIG_ENCODERS
+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);
+#endif
+
+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);
+#ifdef CONFIG_ENCODERS
+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);
+#endif //CONFIG_ENCODERS
+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);
+
+#ifdef 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 == ff_get_fourcc("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;
+}
+
+#ifdef 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 == 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(1, div, 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 = pbBufPtr(&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_bits(&s->pb, 8, temp_ref & 0xff); /* 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 == 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 == 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_bits(&s->pb, 2, (temp_ref>>8)&3);
+ }
+
+ /* 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 == 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 == 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(j<block_last_index) rate+= s->intra_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;
+ level-= 64;
+
+ 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; i<s->mb_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; i<s->mb_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; i<s->mb_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== 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; i<s->mb_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; i<s->mb_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; i<s->mb_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)(sizeof(s->direct_scale_mv[0])/sizeof(int16_t)))
+#define tab_bias (tab_size/2)
+
+void ff_mpeg4_init_direct_mv(MpegEncContext *s){
+ int i;
+ for(i=0; i<tab_size; i++){
+ s->direct_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= s->pp_time;
+ uint16_t time_pb= s->pb_time;
+ 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;
+ //FIXME a lot of that is only needed for !low_delay
+ const int wrap = s->b8_stride;
+ const int xy = s->block_index[0];
+
+ s->current_picture.mbskip_table[mb_xy]= s->mb_skipped;
+
+ if(s->mv_type != MV_TYPE_8X8){
+ int motion_x, motion_y;
+ if (s->mb_intra) {
+ motion_x = 0;
+ motion_y = 0;
+ } else if (s->mv_type == MV_TYPE_16X16) {
+ motion_x = s->mv[0][0][0];
+ motion_y = s->mv[0][0][1];
+ } else /*if (s->mv_type == MV_TYPE_FIELD)*/ {
+ int i;
+ motion_x = s->mv[0][0][0] + s->mv[0][1][0];
+ motion_y = s->mv[0][0][1] + s->mv[0][1][1];
+ motion_x = (motion_x>>1) | (motion_x&1);
+ for(i=0; i<2; i++){
+ 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];
+ }
+
+ /* no update if 8X8 because it has been done during parsing */
+ s->current_picture.motion_val[0][xy][0] = motion_x;
+ s->current_picture.motion_val[0][xy][1] = motion_y;
+ s->current_picture.motion_val[0][xy + 1][0] = motion_x;
+ s->current_picture.motion_val[0][xy + 1][1] = motion_y;
+ s->current_picture.motion_val[0][xy + wrap][0] = motion_x;
+ s->current_picture.motion_val[0][xy + wrap][1] = motion_y;
+ s->current_picture.motion_val[0][xy + 1 + wrap][0] = motion_x;
+ s->current_picture.motion_val[0][xy + 1 + wrap][1] = motion_y;
+ }
+
+ if(s->encoding){ //FIXME encoding MUST be cleaned up
+ if (s->mv_type == MV_TYPE_8X8)
+ s->current_picture.mb_type[mb_xy]= MB_TYPE_L0 | MB_TYPE_8x8;
+ else if(s->mb_intra)
+ s->current_picture.mb_type[mb_xy]= MB_TYPE_INTRA;
+ else
+ s->current_picture.mb_type[mb_xy]= MB_TYPE_L0 | MB_TYPE_16x16;
+ }
+}
+
+#ifdef 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)>>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;
+ memset(s->block[i], 0, sizeof(DCTELEM)*64);
+ }
+ }
+ }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;
+ memset(s->block[i], 0, sizeof(DCTELEM)*64);
+ }
+ }
+ }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);
+ }
+ }
+ }
+}
+
+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!=B_TYPE ? &s->tex_pb : &s->pb;
+ PutBitContext * const dc_pb = s->data_partitioning && s->pict_type!=I_TYPE ? &s->pb2 : &s->pb;
+ const int interleaved_stats= (s->flags&CODEC_FLAG_PASS1) && !s->data_partitioning ? 1 : 0;
+ const int dquant_code[5]= {1,0,9,2,3};
+
+ // printf("**mb x=%d y=%d\n", s->mb_x, s->mb_y);
+ if (!s->mb_intra) {
+ int i, cbp;
+
+ if(s->pict_type==B_TYPE){
+ static const int mb_type_table[8]= {-1, 2, 3, 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==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; i<s->max_b_frames; i++){
+ uint8_t *b_pic;
+ int diff;
+ Picture *pic= s->reordered_input_picture[i+1];
+
+ if(pic==NULL || pic->pict_type!=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++;
+ }
+ } 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 == 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);
+ }
+}
+
+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);
+ const int dquant_code[5]= {1,0,9,2,3};
+
+ //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 == 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;
+ const int uvlinesize= s->uvlinesize;
+ const int xy = s->mb_y * s->mb_stride + s->mb_x;
+ uint8_t *dest_y = s->dest[0];
+ uint8_t *dest_cb= s->dest[1];
+ uint8_t *dest_cr= s->dest[2];
+
+// if(s->pict_type==B_TYPE && !s->readable) return;
+
+ /*
+ Diag Top
+ Left Center
+ */
+ if(!IS_SKIP(s->current_picture.mb_type[xy])){
+ qp_c= s->qscale;
+ s->dsp.h263_v_loop_filter(dest_y+8*linesize , linesize, qp_c);
+ s->dsp.h263_v_loop_filter(dest_y+8*linesize+8, linesize, qp_c);
+ }else
+ qp_c= 0;
+
+ if(s->mb_y){
+ int qp_dt, qp_t, qp_tc;
+
+ if(IS_SKIP(s->current_picture.mb_type[xy-s->mb_stride]))
+ qp_t=0;
+ else
+ qp_t= s->current_picture.qscale_table[xy-s->mb_stride];
+
+ if(qp_c)
+ qp_tc= qp_c;
+ else
+ qp_tc= qp_t;
+
+ if(qp_tc){
+ const int chroma_qp= s->chroma_qscale_table[qp_tc];
+ s->dsp.h263_v_loop_filter(dest_y , linesize, qp_tc);
+ s->dsp.h263_v_loop_filter(dest_y+8, linesize, qp_tc);
+
+ s->dsp.h263_v_loop_filter(dest_cb , uvlinesize, chroma_qp);
+ s->dsp.h263_v_loop_filter(dest_cr , uvlinesize, chroma_qp);
+ }
+
+ if(qp_t)
+ s->dsp.h263_h_loop_filter(dest_y-8*linesize+8 , linesize, qp_t);
+
+ if(s->mb_x){
+ if(qp_t || IS_SKIP(s->current_picture.mb_type[xy-1-s->mb_stride]))
+ qp_dt= qp_t;
+ else
+ qp_dt= s->current_picture.qscale_table[xy-1-s->mb_stride];
+
+ if(qp_dt){
+ const int chroma_qp= s->chroma_qscale_table[qp_dt];
+ s->dsp.h263_h_loop_filter(dest_y -8*linesize , linesize, qp_dt);
+ s->dsp.h263_h_loop_filter(dest_cb-8*uvlinesize, uvlinesize, chroma_qp);
+ s->dsp.h263_h_loop_filter(dest_cr-8*uvlinesize, uvlinesize, chroma_qp);
+ }
+ }
+ }
+
+ if(qp_c){
+ s->dsp.h263_h_loop_filter(dest_y +8, linesize, qp_c);
+ if(s->mb_y + 1 == s->mb_height)
+ s->dsp.h263_h_loop_filter(dest_y+8*linesize+8, linesize, qp_c);
+ }
+
+ if(s->mb_x){
+ int qp_lc;
+ if(qp_c || IS_SKIP(s->current_picture.mb_type[xy-1]))
+ qp_lc= qp_c;
+ else
+ qp_lc= s->current_picture.qscale_table[xy-1];
+
+ if(qp_lc){
+ s->dsp.h263_h_loop_filter(dest_y, linesize, qp_lc);
+ if(s->mb_y + 1 == s->mb_height){
+ const int chroma_qp= s->chroma_qscale_table[qp_lc];
+ s->dsp.h263_h_loop_filter(dest_y +8* linesize, linesize, qp_lc);
+ s->dsp.h263_h_loop_filter(dest_cb , uvlinesize, chroma_qp);
+ s->dsp.h263_h_loop_filter(dest_cr , uvlinesize, chroma_qp);
+ }
+ }
+ }
+}
+
+#ifdef CONFIG_ENCODERS
+static int h263_pred_dc(MpegEncContext * s, int n, int16_t **dc_val_ptr)
+{
+ int x, y, wrap, a, c, pred_dc, scale;
+ 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];
+ scale = s->y_dc_scale;
+ } else {
+ x = s->mb_x;
+ y = s->mb_y;
+ wrap = s->mb_stride;
+ dc_val = s->dc_val[n - 4 + 1];
+ scale = s->c_dc_scale;
+ }
+ /* 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;
+ }
+ pred_dc = 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 */
+ //pred_dc = (pred_dc + (scale >> 1)) / scale;
+ *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)
+{
+ int x, y, wrap, a, c, pred_dc, scale, i;
+ int16_t *dc_val, *ac_val, *ac_val1;
+
+ /* find prediction */
+ if (n < 4) {
+ x = 2 * s->mb_x + (n & 1);
+ y = 2 * s->mb_y + (n>> 1);
+ wrap = s->b8_stride;
+ dc_val = s->dc_val[0];
+ ac_val = s->ac_val[0][0];
+ scale = s->y_dc_scale;
+ } else {
+ x = s->mb_x;
+ y = s->mb_y;
+ wrap = s->mb_stride;
+ dc_val = s->dc_val[n - 4 + 1];
+ ac_val = s->ac_val[n - 4 + 1][0];
+ scale = s->c_dc_scale;
+ }
+
+ ac_val += ((y) * wrap + (x)) * 16;
+ ac_val1 = ac_val;
+
+ /* 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;
+ }
+
+ if (s->ac_pred) {
+ pred_dc = 1024;
+ if (s->h263_aic_dir) {
+ /* left prediction */
+ if (a != 1024) {
+ ac_val -= 16;
+ for(i=1;i<8;i++) {
+ block[s->dsp.idct_permutation[i<<3]] += ac_val[i];
+ }
+ pred_dc = a;
+ }
+ } else {
+ /* top prediction */
+ if (c != 1024) {
+ ac_val -= 16 * wrap;
+ for(i=1;i<8;i++) {
+ block[s->dsp.idct_permutation[i ]] += ac_val[i + 8];
+ }
+ pred_dc = c;
+ }
+ }
+ } else {
+ /* 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 */
+ block[0]=block[0]*scale + pred_dc;
+
+ if (block[0] < 0)
+ block[0] = 0;
+ else
+ block[0] |= 1;
+
+ /* Update AC/DC tables */
+ dc_val[(x) + (y) * wrap] = block[0];
+
+ /* 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 ]];
+}
+
+int16_t *h263_pred_motion(MpegEncContext * s, int block, int dir,
+ int *px, int *py)
+{
+ int wrap;
+ int16_t *A, *B, *C, (*mot_val)[2];
+ static const int off[4]= {2, 1, 1, -1};
+
+ wrap = s->b8_stride;
+ mot_val = s->current_picture.motion_val[dir] + s->block_index[block];
+
+ A = mot_val[ - 1];
+ /* special case for first (slice) line */
+ if (s->first_slice_line && block<3) {
+ // we can't just change some MVs to simulate that as we need them for the B frames (and ME)
+ // and if we ever support non rectangular objects than we need to do a few ifs here anyway :(
+ if(block==0){ //most common case
+ if(s->mb_x == s->resync_mb_x){ //rare
+ *px= *py = 0;
+ }else if(s->mb_x + 1 == s->resync_mb_x && s->h263_pred){ //rare
+ C = mot_val[off[block] - wrap];
+ if(s->mb_x==0){
+ *px = C[0];
+ *py = C[1];
+ }else{
+ *px = mid_pred(A[0], 0, C[0]);
+ *py = mid_pred(A[1], 0, C[1]);
+ }
+ }else{
+ *px = A[0];
+ *py = A[1];
+ }
+ }else if(block==1){
+ if(s->mb_x + 1 == s->resync_mb_x && s->h263_pred){ //rare
+ C = mot_val[off[block] - wrap];
+ *px = mid_pred(A[0], 0, C[0]);
+ *py = mid_pred(A[1], 0, C[1]);
+ }else{
+ *px = A[0];
+ *py = A[1];
+ }
+ }else{ /* block==2*/
+ B = mot_val[ - wrap];
+ C = mot_val[off[block] - wrap];
+ if(s->mb_x == s->resync_mb_x) //rare
+ A[0]=A[1]=0;
+
+ *px = mid_pred(A[0], B[0], C[0]);
+ *py = mid_pred(A[1], B[1], C[1]);
+ }
+ } else {
+ B = mot_val[ - wrap];
+ C = mot_val[off[block] - wrap];
+ *px = mid_pred(A[0], B[0], C[0]);
+ *py = mid_pred(A[1], B[1], C[1]);
+ }
+ return *mot_val;
+}
+
+#ifdef 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)>>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, range, code;
+
+ bit_size = f_code - 1;
+ range = 1 << bit_size;
+
+ 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<<f_code); mv<(16<<f_code); mv++){
+ fcode_tab[mv+MAX_MV]= f_code;
+ }
+ }
+
+ for(mv=0; mv<MAX_MV*2+1; mv++){
+ umv_fcode_tab[mv]= 1;
+ }
+}
+#endif
+
+#ifdef CONFIG_ENCODERS
+
+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= 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;
+
+ }
+}
+
+#endif //CONFIG_ENCODERS
+
+#ifdef CONFIG_ENCODERS
+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_bits(&s->pb, 8, slevel & 0xff);
+ else{
+ put_bits(&s->pb, 8, 128);
+ put_bits(&s->pb, 5, slevel & 0x1f);
+ put_bits(&s->pb, 6, (slevel>>5)&0x3f);
+ }
+ }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_bits(&s->pb, 7, slevel & 0x7f);
+ } else {
+ /* 11-bit level */
+ put_bits(&s->pb, 1, 1);
+ put_bits(&s->pb, 1, last);
+ put_bits(&s->pb, 6, run);
+
+ put_bits(&s->pb, 11, slevel & 0x7ff);
+ }
+ }
+ } else {
+ put_bits(&s->pb, 1, sign);
+ }
+ last_non_zero = i;
+ }
+ }
+}
+#endif
+
+#ifdef CONFIG_ENCODERS
+
+/***************************************************/
+/**
+ * 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<<length)-1);
+}
+
+/* must be called before writing the header */
+void ff_set_mpeg4_time(MpegEncContext * s, int picture_number){
+ int time_div, time_mod;
+
+ assert(s->current_picture_ptr->pts != AV_NOPTS_VALUE);
+ s->time= s->current_picture_ptr->pts*s->avctx->time_base.num;
+
+ time_div= s->time/s->avctx->time_base.den;
+ time_mod= s->time%s->avctx->time_base.den;
+
+ if(s->pict_type==B_TYPE){
+ s->pb_time= s->pp_time - (s->last_non_b_time - s->time);
+ assert(s->pb_time > 0 && s->pb_time < s->pp_time);
+ ff_mpeg4_init_direct_mv(s);
+ }else{
+ s->last_time_base= s->time_base;
+ s->time_base= time_div;
+ s->pp_time= s->time - s->last_non_b_time;
+ s->last_non_b_time= s->time;
+ assert(picture_number==0 || s->pp_time > 0);
+ }
+}
+
+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(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==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!=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 == P_TYPE
+ || (s->pict_type == 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 != I_TYPE)
+ put_bits(&s->pb, 3, s->f_code); /* fcode_for */
+ if (s->pict_type == B_TYPE)
+ put_bits(&s->pb, 3, s->b_code); /* fcode_back */
+ // printf("****frame %d\n", picture_number);
+}
+
+#endif //CONFIG_ENCODERS
+
+/**
+ * set qscale and update qscale dependent variables.
+ */
+void ff_set_qscale(MpegEncContext * s, int qscale)
+{
+ if (qscale < 1)
+ qscale = 1;
+ else if (qscale > 31)
+ qscale = 31;
+
+ s->qscale = qscale;
+ s->chroma_qscale= s->chroma_qscale_table[qscale];
+
+ s->y_dc_scale= s->y_dc_scale_table[ qscale ];
+ s->c_dc_scale= s->c_dc_scale_table[ s->chroma_qscale ];
+}
+
+/**
+ * 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_resilience>=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 ]];
+
+}
+
+#ifdef 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_bits(ac_pb, 12, slevel & 0xfff);
+ 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;
+ const RLTable *rl;
+ 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;
+ rl = &rl_intra;
+ len_tab = uni_mpeg4_intra_rl_len;
+ } else {
+ if(last_index<0) return 0;
+ i = 0;
+ rl = &rl_inter;
+ 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;
+
+void init_vlc_rl(RLTable *rl, int use_static)
+{
+ int i, q;
+
+ /* Return if static table is already initialized */
+ if(use_static && rl->rl_vlc[0])
+ return;
+
+ init_vlc(&rl->vlc, 9, rl->n + 1,
+ &rl->table_vlc[0][1], 4, 2,
+ &rl->table_vlc[0][0], 4, 2, use_static);
+
+
+ for(q=0; q<32; q++){
+ int qmul= q*2;
+ int qadd= (q-1)|1;
+
+ if(q==0){
+ qmul=1;
+ qadd=0;
+ }
+ if(use_static)
+ rl->rl_vlc[q]= av_mallocz_static(rl->vlc.table_size*sizeof(RL_VLC_ELEM));
+ else
+ rl->rl_vlc[q]= av_malloc(rl->vlc.table_size*sizeof(RL_VLC_ELEM));
+ for(i=0; i<rl->vlc.table_size; i++){
+ int code= rl->vlc.table[i][0];
+ int len = rl->vlc.table[i][1];
+ int level, run;
+
+ if(len==0){ // illegal code
+ run= 66;
+ level= MAX_LEVEL;
+ }else if(len<0){ //more bits needed
+ run= 0;
+ level= code;
+ }else{
+ if(code==rl->n){ //esc
+ run= 66;
+ level= 0;
+ }else{
+ run= rl->table_run [code] + 1;
+ level= rl->table_level[code] * qmul + qadd;
+ if(code >= rl->last) run+=192;
+ }
+ }
+ rl->rl_vlc[q][i].len= len;
+ rl->rl_vlc[q][i].level= level;
+ rl->rl_vlc[q][i].run= run;
+ }
+ }
+}
+
+/* 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(&intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 9,
+ intra_MCBPC_bits, 1, 1,
+ intra_MCBPC_code, 1, 1, 1);
+ init_vlc(&inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 28,
+ inter_MCBPC_bits, 1, 1,
+ inter_MCBPC_code, 1, 1, 1);
+ init_vlc(&cbpy_vlc, CBPY_VLC_BITS, 16,
+ &cbpy_tab[0][1], 2, 1,
+ &cbpy_tab[0][0], 2, 1, 1);
+ init_vlc(&mv_vlc, MV_VLC_BITS, 33,
+ &mvtab[0][1], 2, 1,
+ &mvtab[0][0], 2, 1, 1);
+ 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, 1);
+ init_vlc_rl(&rl_intra, 1);
+ init_vlc_rl(&rvlc_rl_inter, 1);
+ init_vlc_rl(&rvlc_rl_intra, 1);
+ init_vlc_rl(&rl_intra_aic, 1);
+ init_vlc(&dc_lum, DC_VLC_BITS, 10 /* 13 */,
+ &DCtab_lum[0][1], 2, 1,
+ &DCtab_lum[0][0], 2, 1, 1);
+ init_vlc(&dc_chrom, DC_VLC_BITS, 10 /* 13 */,
+ &DCtab_chrom[0][1], 2, 1,
+ &DCtab_chrom[0][0], 2, 1, 1);
+ init_vlc(&sprite_trajectory, SPRITE_TRAJ_VLC_BITS, 15,
+ &sprite_trajectory_tab[0][1], 4, 2,
+ &sprite_trajectory_tab[0][0], 4, 2, 1);
+ init_vlc(&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, 1);
+ init_vlc(&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, 1);
+ init_vlc(&cbpc_b_vlc, CBPC_B_VLC_BITS, 4,
+ &cbpc_b_tab[0][1], 2, 1,
+ &cbpc_b_tab[0][0], 2, 1, 1);
+ }
+}
+
+/**
+ * Get the GOB height based on picture height.
+ */
+int ff_h263_get_gob_height(MpegEncContext *s){
+ if (s->height <= 400)
+ return 1;
+ else if (s->height <= 800)
+ return 2;
+ 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 occured
+ */
+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;i<n;i++)
+ tab[i] = val;
+}
+
+#ifdef CONFIG_ENCODERS
+
+void ff_mpeg4_init_partitions(MpegEncContext *s)
+{
+ uint8_t *start= pbBufPtr(&s->pb);
+ uint8_t *end= s->pb.buf_end;
+ int size= end - start;
+ int pb_size = (((long)start + size/3)&(~3)) - (long)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==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 I_TYPE:
+ return 16;
+ case P_TYPE:
+ case S_TYPE:
+ return s->f_code+15;
+ case B_TYPE:
+ return FFMAX(FFMAX(s->f_code, s->b_code)+15, 17);
+ default:
+ return -1;
+ }
+}
+
+#ifdef 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==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 == 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 allready 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 == 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 != 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 == 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;
+}
+
+/**
+ * decodes the group of blocks / video packet header.
+ * @return <0 if no resync found
+ */
+int ff_h263_resync(MpegEncContext *s){
+ int left, ret;
+
+ if(s->codec_id==CODEC_ID_MPEG4){
+ skip_bits1(&s->gb);
+ align_get_bits(&s->gb);
+ }
+
+ if(show_bits(&s->gb, 16)==0){
+ 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 0;
+ }
+ //ok, it's not where its 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;
+
+ 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 0;
+
+ 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]<<s->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 occured
+ */
+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_y<s->mb_height; s->mb_y++){
+ ff_init_block_index(s);
+ for(; s->mb_x<s->mb_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==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==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==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 occured
+ */
+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_x<s->mb_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==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==I_TYPE ? (DC_ERROR|MV_ERROR) : MV_ERROR;
+ const int part_a_end = s->pict_type==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==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==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==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 occured
+ */
+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 == P_TYPE || s->pict_type==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==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 == 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);
+}
+
+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;
+
+ assert(!s->h263_pred);
+
+ if (s->pict_type == 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;
+
+ 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;
+ }
+ }
+
+ /* 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->obmc){
+ if(s->pict_type == P_TYPE && s->mb_x+1<s->mb_width && s->mb_num_left != 1)
+ preview_obmc(s);
+ }
+ } else if(s->pict_type==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;
+
+ /* decode each block */
+ for (i = 0; i < 6; i++) {
+ if (h263_decode_block(s, block[i], i, cbp&32) < 0)
+ return -1;
+ cbp+=cbp;
+ }
+ } 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;
+
+ 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);
+ }
+
+ /* decode each block */
+ for (i = 0; i < 6; i++) {
+ if (h263_decode_block(s, block[i], i, cbp&32) < 0)
+ return -1;
+ cbp+=cbp;
+ }
+ }
+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 == P_TYPE || s->pict_type==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==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==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==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==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)>>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);
+#ifdef DEBUG
+ av_log( s->avctx, AV_LOG_DEBUG,"H.263+ UMV Motion = %d\n", code);
+#endif
+ 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){
+#ifdef CONFIG_RV10_DECODER
+ if (s->rv10_version == 3 && s->pict_type == 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_resilience >= 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 its supposed to work ...
+ rl = &rl_intra_aic;
+ i = 0;
+ s->gb= gb;
+ memset(block, 0, sizeof(DCTELEM)*64);
+ 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_resilience>=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 occured
+ */
+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]<<n)&32;
+ }else{
+ level = mpeg4_decode_dc(s, n, &dc_pred_dir);
+ if (level < 0)
+ return -1;
+ }
+ block[0] = level;
+ i = 0;
+ }else{
+ i = -1;
+ ff_mpeg4_pred_dc(s, n, 0, &dc_pred_dir, 0);
+ }
+ if (!coded)
+ goto not_coded;
+
+ if(rvlc){
+ rl = &rvlc_rl_intra;
+ rl_vlc = rvlc_rl_intra.rl_vlc[0];
+ }else{
+ rl = &rl_intra;
+ rl_vlc = rl_intra.rl_vlc[0];
+ }
+ if (s->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_resilience >= 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_resilience > 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_resilience > 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 = 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;
+
+ if (get_bits1(&s->gb) != 0) {
+ av_log(s->avctx, AV_LOG_ERROR, "H263 PB frame not supported\n");
+ return -1; /* not PB frame */
+ }
+ 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_bits(&s->gb, 1); /* 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= I_TYPE;break;
+ case 1: s->pict_type= P_TYPE;break;
+ case 3: s->pict_type= B_TYPE;break;
+ case 7: s->pict_type= 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= ff_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;
+
+ /* 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){
+ 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 1
+ if (s->pict_type == I_TYPE && s->codec_tag == ff_get_fourcc("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<<s->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; i<s->num_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);
+ d[i][0]= x;
+ d[i][1]= y;
+ }
+
+ while((1<<alpha)<w) alpha++;
+ while((1<<beta )<h) beta++; // there seems to be a typo in the mpeg4 std for the definition of w' and h'
+ w2= 1<<alpha;
+ h2= 1<<beta;
+
+// Note, the 4th point isn't used for GMC
+ if(s->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<<s->sprite_shift[0]
+ && s->sprite_delta[0][1] == 0
+ && s->sprite_delta[1][0] == 0
+ && s->sprite_delta[1][1] == a<<s->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!=1){
+ 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 == ff_get_fourcc("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);
+ 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)) av_log(s->avctx, AV_LOG_ERROR, "Complexity estimation not supported\n");
+
+ 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.
+ * allso inits 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';
+ }
+
+ /* 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) + I_TYPE; /* pict type: I = 0 , P = 1 */
+ if(s->pict_type==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!=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!=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 == P_TYPE
+ || (s->pict_type == 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 != 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) {
+ 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 == 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 != 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 == 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\n",
+ s->qscale, s->f_code, s->b_code,
+ s->pict_type == I_TYPE ? "I" : (s->pict_type == P_TYPE ? "P" : (s->pict_type == 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);
+ }
+
+ if(!s->scalability){
+ if (s->shape!=RECT_SHAPE && s->pict_type!=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 == ff_get_fourcc("WV1F") && show_bits(gb, 24) == 0x575630){
+ skip_bits(gb, 24);
+ if(get_bits(gb, 8) == 0xF0)
+ return decode_vop_header(s, gb);
+ }
+
+ 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){
+ return decode_vop_header(s, gb);
+ }
+
+ align_get_bits(gb);
+ startcode = 0xff;
+ }
+}
+
+/* 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 = 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 */
+ }
+ if (get_bits1(&s->gb) != 0) {
+ s->obmc= 1;
+ av_log(s->avctx, AV_LOG_ERROR, "Advanced Prediction Mode not supported\n");
+// return -1; /* advanced prediction mode: off */
+ }
+ if (get_bits1(&s->gb) != 0) {
+ av_log(s->avctx, AV_LOG_ERROR, "PB frame mode no supported\n");
+ return -1; /* PB frame mode */
+ }
+
+ /* skip unknown header garbage */
+ skip_bits(&s->gb, 41);
+
+ s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
+ skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
+
+ /* 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;
+
+ 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 = I_TYPE + get_bits(&s->gb, 2);
+ s->dropable= s->pict_type > P_TYPE;
+ if (s->dropable)
+ s->pict_type = 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/libffmpeg/libavcodec/h263data.h b/contrib/ffmpeg/libavcodec/h263data.h
index 5eddc3b54..5eddc3b54 100644
--- a/src/libffmpeg/libavcodec/h263data.h
+++ b/contrib/ffmpeg/libavcodec/h263data.h
diff --git a/contrib/ffmpeg/libavcodec/h263dec.c b/contrib/ffmpeg/libavcodec/h263dec.c
new file mode 100644
index 000000000..b385f84cd
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/h263dec.c
@@ -0,0 +1,914 @@
+/*
+ * H.263 decoder
+ * Copyright (c) 2001 Fabrice Bellard.
+ * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file h263dec.c
+ * H.263 decoder.
+ */
+
+#include "avcodec.h"
+#include "dsputil.h"
+#include "mpegvideo.h"
+
+//#define DEBUG
+//#define PRINT_FRAME_TIME
+
+int ff_h263_decode_init(AVCodecContext *avctx)
+{
+ MpegEncContext *s = avctx->priv_data;
+
+ s->avctx = avctx;
+ s->out_format = FMT_H263;
+
+ s->width = avctx->coded_width;
+ s->height = avctx->coded_height;
+ s->workaround_bugs= avctx->workaround_bugs;
+
+ // set defaults
+ MPV_decode_defaults(s);
+ s->quant_precision=5;
+ s->decode_mb= ff_h263_decode_mb;
+ s->low_delay= 1;
+ avctx->pix_fmt= PIX_FMT_YUV420P;
+ s->unrestricted_mv= 1;
+
+ /* select sub codec */
+ switch(avctx->codec->id) {
+ case CODEC_ID_H263:
+ s->unrestricted_mv= 0;
+ 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
+ break;
+ case CODEC_ID_MSMPEG4V1:
+ s->h263_msmpeg4 = 1;
+ s->h263_pred = 1;
+ s->msmpeg4_version=1;
+ break;
+ case CODEC_ID_MSMPEG4V2:
+ s->h263_msmpeg4 = 1;
+ s->h263_pred = 1;
+ s->msmpeg4_version=2;
+ break;
+ case CODEC_ID_MSMPEG4V3:
+ s->h263_msmpeg4 = 1;
+ s->h263_pred = 1;
+ s->msmpeg4_version=3;
+ break;
+ case CODEC_ID_WMV1:
+ s->h263_msmpeg4 = 1;
+ s->h263_pred = 1;
+ s->msmpeg4_version=4;
+ break;
+ case CODEC_ID_WMV2:
+ s->h263_msmpeg4 = 1;
+ s->h263_pred = 1;
+ s->msmpeg4_version=5;
+ break;
+ case CODEC_ID_VC1:
+ case CODEC_ID_WMV3:
+ s->h263_msmpeg4 = 1;
+ s->h263_pred = 1;
+ s->msmpeg4_version=6;
+ break;
+ case CODEC_ID_H263I:
+ break;
+ case CODEC_ID_FLV1:
+ s->h263_flv = 1;
+ break;
+ default:
+ return -1;
+ }
+ s->codec_id= avctx->codec->id;
+
+ /* for h263, we allocate the images after having read the header */
+ if (avctx->codec->id != CODEC_ID_H263 && avctx->codec->id != CODEC_ID_MPEG4)
+ if (MPV_common_init(s) < 0)
+ return -1;
+
+ if (s->h263_msmpeg4)
+ ff_msmpeg4_decode_init(s);
+ else
+ h263_decode_init_vlc(s);
+
+ return 0;
+}
+
+int ff_h263_decode_end(AVCodecContext *avctx)
+{
+ MpegEncContext *s = avctx->priv_data;
+
+ MPV_common_end(s);
+ return 0;
+}
+
+/**
+ * returns the number of bytes consumed for building the current frame
+ */
+static int get_consumed_bytes(MpegEncContext *s, int buf_size){
+ int pos= (get_bits_count(&s->gb)+7)>>3;
+
+ if(s->divx_packed){
+ //we would have to scan through the whole buf to handle the weird reordering ...
+ return buf_size;
+ }else if(s->flags&CODEC_FLAG_TRUNCATED){
+ pos -= s->parse_context.last_index;
+ if(pos<0) pos=0; // padding is not really read so this might be -1
+ return pos;
+ }else{
+ if(pos==0) pos=1; //avoid infinite loops (i doubt thats needed but ...)
+ if(pos+10>buf_size) pos=buf_size; // oops ;)
+
+ return pos;
+ }
+}
+
+static int decode_slice(MpegEncContext *s){
+ const int part_mask= s->partitioned_frame ? (AC_END|AC_ERROR) : 0x7F;
+ const int mb_size= 16>>s->avctx->lowres;
+ s->last_resync_gb= s->gb;
+ s->first_slice_line= 1;
+
+ s->resync_mb_x= s->mb_x;
+ s->resync_mb_y= s->mb_y;
+
+ ff_set_qscale(s, s->qscale);
+
+ if(s->partitioned_frame){
+ const int qscale= s->qscale;
+
+ if(s->codec_id==CODEC_ID_MPEG4){
+ if(ff_mpeg4_decode_partitions(s) < 0)
+ return -1;
+ }
+
+ /* restore variables which were modified */
+ s->first_slice_line=1;
+ s->mb_x= s->resync_mb_x;
+ s->mb_y= s->resync_mb_y;
+ ff_set_qscale(s, qscale);
+ }
+
+ for(; s->mb_y < s->mb_height; s->mb_y++) {
+ /* per-row end of slice checks */
+ if(s->msmpeg4_version){
+ if(s->resync_mb_y + s->slice_height == s->mb_y){
+ 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);
+
+ return 0;
+ }
+ }
+
+ if(s->msmpeg4_version==1){
+ s->last_dc[0]=
+ s->last_dc[1]=
+ s->last_dc[2]= 128;
+ }
+
+ ff_init_block_index(s);
+ for(; s->mb_x < s->mb_width; s->mb_x++) {
+ int ret;
+
+ ff_update_block_index(s);
+
+ if(s->resync_mb_x == s->mb_x && s->resync_mb_y+1 == s->mb_y){
+ s->first_slice_line=0;
+ }
+
+ /* DCT & quantize */
+
+ s->mv_dir = MV_DIR_FORWARD;
+ s->mv_type = MV_TYPE_16X16;
+// s->mb_skipped = 0;
+//printf("%d %d %06X\n", ret, get_bits_count(&s->gb), show_bits(&s->gb, 24));
+ ret= s->decode_mb(s, s->block);
+
+ if (s->pict_type!=B_TYPE)
+ ff_h263_update_motion_val(s);
+
+ if(ret<0){
+ const int xy= s->mb_x + s->mb_y*s->mb_stride;
+ if(ret==SLICE_END){
+ MPV_decode_mb(s, s->block);
+ if(s->loop_filter)
+ ff_h263_loop_filter(s);
+
+//printf("%d %d %d %06X\n", s->mb_x, s->mb_y, s->gb.size*8 - get_bits_count(&s->gb), show_bits(&s->gb, 24));
+ 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);
+
+ s->padding_bug_score--;
+
+ if(++s->mb_x >= s->mb_width){
+ s->mb_x=0;
+ ff_draw_horiz_band(s, s->mb_y*mb_size, mb_size);
+ s->mb_y++;
+ }
+ return 0;
+ }else if(ret==SLICE_NOEND){
+ av_log(s->avctx, AV_LOG_ERROR, "Slice mismatch at MB: %d\n", xy);
+ 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 -1;
+ }
+ av_log(s->avctx, AV_LOG_ERROR, "Error at MB: %d\n", xy);
+ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);
+
+ return -1;
+ }
+
+ MPV_decode_mb(s, s->block);
+ if(s->loop_filter)
+ ff_h263_loop_filter(s);
+ }
+
+ ff_draw_horiz_band(s, s->mb_y*mb_size, mb_size);
+
+ s->mb_x= 0;
+ }
+
+ assert(s->mb_x==0 && s->mb_y==s->mb_height);
+
+ /* 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
+// && !s->resync_marker
+ && !s->data_partitioning){
+
+ const int bits_count= get_bits_count(&s->gb);
+ const int bits_left = s->gb.size_in_bits - bits_count;
+
+ if(bits_left==0){
+ s->padding_bug_score+=16;
+ } else if(bits_left != 1){
+ int v= show_bits(&s->gb, 8);
+ v|= 0x7F >> (7-(bits_count&7));
+
+ if(v==0x7F && bits_left<=8)
+ s->padding_bug_score--;
+ else if(v==0x7F && ((get_bits_count(&s->gb)+8)&8) && bits_left<=16)
+ s->padding_bug_score+= 4;
+ else
+ s->padding_bug_score++;
+ }
+ }
+
+ if(s->workaround_bugs&FF_BUG_AUTODETECT){
+ if(s->padding_bug_score > -2 && !s->data_partitioning /*&& (s->divx_version || !s->resync_marker)*/)
+ s->workaround_bugs |= FF_BUG_NO_PADDING;
+ else
+ s->workaround_bugs &= ~FF_BUG_NO_PADDING;
+ }
+
+ // 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 max_extra=7;
+
+ /* no markers in M$ crap */
+ if(s->msmpeg4_version && s->pict_type==I_TYPE)
+ max_extra+= 17;
+
+ /* buggy padding but the frame should still end approximately at the bitstream end */
+ if((s->workaround_bugs&FF_BUG_NO_PADDING) && s->error_resilience>=3)
+ max_extra+= 48;
+ else if((s->workaround_bugs&FF_BUG_NO_PADDING))
+ max_extra+= 256*256*256*64;
+
+ if(left>max_extra){
+ av_log(s->avctx, AV_LOG_ERROR, "discarding %d junk bits at end, next would be %X\n", left, show_bits(&s->gb, 24));
+ }
+ else if(left<0){
+ av_log(s->avctx, AV_LOG_ERROR, "overreading %d bits\n", -left);
+ }else
+ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, AC_END|DC_END|MV_END);
+
+ return 0;
+ }
+
+ 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),
+ 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);
+
+ return -1;
+}
+
+/**
+ * finds the end of the current frame in the bitstream.
+ * @return the position of the first byte of the next frame, or -1
+ */
+int ff_mpeg4_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size){
+ int vop_found, i;
+ uint32_t state;
+
+ vop_found= pc->frame_start_found;
+ state= pc->state;
+
+ i=0;
+ if(!vop_found){
+ for(i=0; i<buf_size; i++){
+ state= (state<<8) | buf[i];
+ if(state == 0x1B6){
+ i++;
+ vop_found=1;
+ break;
+ }
+ }
+ }
+
+ if(vop_found){
+ /* EOF considered as end of frame */
+ if (buf_size == 0)
+ return 0;
+ for(; i<buf_size; i++){
+ state= (state<<8) | buf[i];
+ if((state&0xFFFFFF00) == 0x100){
+ pc->frame_start_found=0;
+ pc->state=-1;
+ return i-3;
+ }
+ }
+ }
+ pc->frame_start_found= vop_found;
+ pc->state= state;
+ return END_NOT_FOUND;
+}
+
+static int h263_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size){
+ int vop_found, i;
+ uint32_t state;
+
+ vop_found= pc->frame_start_found;
+ state= pc->state;
+
+ i=0;
+ if(!vop_found){
+ for(i=0; i<buf_size; i++){
+ state= (state<<8) | buf[i];
+ if(state>>(32-22) == 0x20){
+ i++;
+ vop_found=1;
+ break;
+ }
+ }
+ }
+
+ if(vop_found){
+ for(; i<buf_size; i++){
+ state= (state<<8) | buf[i];
+ if(state>>(32-22) == 0x20){
+ pc->frame_start_found=0;
+ pc->state=-1;
+ return i-3;
+ }
+ }
+ }
+ pc->frame_start_found= vop_found;
+ pc->state= state;
+
+ return END_NOT_FOUND;
+}
+
+#ifdef CONFIG_H263_PARSER
+static int h263_parse(AVCodecParserContext *s,
+ AVCodecContext *avctx,
+ uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size)
+{
+ ParseContext *pc = s->priv_data;
+ int next;
+
+ next= h263_find_frame_end(pc, buf, buf_size);
+
+ if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
+ *poutbuf = NULL;
+ *poutbuf_size = 0;
+ return buf_size;
+ }
+
+ *poutbuf = (uint8_t *)buf;
+ *poutbuf_size = buf_size;
+ return next;
+}
+#endif
+
+int ff_h263_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ MpegEncContext *s = avctx->priv_data;
+ int ret;
+ AVFrame *pict = data;
+
+#ifdef PRINT_FRAME_TIME
+uint64_t time= rdtsc();
+#endif
+#ifdef DEBUG
+ av_log(avctx, AV_LOG_DEBUG, "*****frame %d size=%d\n", avctx->frame_number, buf_size);
+ if(buf_size>0)
+ av_log(avctx, AV_LOG_DEBUG, "bytes=%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]);
+#endif
+ s->flags= avctx->flags;
+ s->flags2= avctx->flags2;
+
+ /* no supplementary picture */
+ if (buf_size == 0) {
+ /* special case for last picture */
+ if (s->low_delay==0 && s->next_picture_ptr) {
+ *pict= *(AVFrame*)s->next_picture_ptr;
+ s->next_picture_ptr= NULL;
+
+ *data_size = sizeof(AVFrame);
+ }
+
+ return 0;
+ }
+
+ if(s->flags&CODEC_FLAG_TRUNCATED){
+ int next;
+
+ if(s->codec_id==CODEC_ID_MPEG4){
+ next= ff_mpeg4_find_frame_end(&s->parse_context, buf, buf_size);
+ }else if(s->codec_id==CODEC_ID_H263){
+ next= h263_find_frame_end(&s->parse_context, buf, buf_size);
+ }else{
+ av_log(s->avctx, AV_LOG_ERROR, "this codec does not support truncated bitstreams\n");
+ return -1;
+ }
+
+ if( ff_combine_frame(&s->parse_context, next, &buf, &buf_size) < 0 )
+ return buf_size;
+ }
+
+
+retry:
+
+ if(s->bitstream_buffer_size && (s->divx_packed || buf_size<20)){ //divx 5.01+/xvid frame reorder
+ init_get_bits(&s->gb, s->bitstream_buffer, s->bitstream_buffer_size*8);
+ }else
+ init_get_bits(&s->gb, buf, buf_size*8);
+ s->bitstream_buffer_size=0;
+
+ if (!s->context_initialized) {
+ if (MPV_common_init(s) < 0) //we need the idct permutaton for reading a custom matrix
+ return -1;
+ }
+
+ //we need to set current_picture_ptr before reading the header, otherwise we cant store anyting im there
+ if(s->current_picture_ptr==NULL || s->current_picture_ptr->data[0]){
+ int i= ff_find_unused_picture(s, 0);
+ s->current_picture_ptr= &s->picture[i];
+ }
+
+ /* let's go :-) */
+ if (s->msmpeg4_version==5) {
+ ret= ff_wmv2_decode_picture_header(s);
+ } else if (s->msmpeg4_version) {
+ ret = msmpeg4_decode_picture_header(s);
+ } else if (s->h263_pred) {
+ if(s->avctx->extradata_size && s->picture_number==0){
+ GetBitContext gb;
+
+ init_get_bits(&gb, s->avctx->extradata, s->avctx->extradata_size*8);
+ ret = ff_mpeg4_decode_picture_header(s, &gb);
+ }
+ ret = ff_mpeg4_decode_picture_header(s, &s->gb);
+
+ if(s->flags& CODEC_FLAG_LOW_DELAY)
+ s->low_delay=1;
+ } 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 {
+ ret = h263_decode_picture_header(s);
+ }
+
+ if(ret==FRAME_SKIPPED) return get_consumed_bytes(s, buf_size);
+
+ /* skip if the header was thrashed */
+ if (ret < 0){
+ av_log(s->avctx, AV_LOG_ERROR, "header damaged\n");
+ return -1;
+ }
+
+ avctx->has_b_frames= !s->low_delay;
+
+ if(s->xvid_build==0 && s->divx_version==0 && s->lavc_build==0){
+ if(s->stream_codec_tag == ff_get_fourcc("XVID") ||
+ s->codec_tag == ff_get_fourcc("XVID") || s->codec_tag == ff_get_fourcc("XVIX") ||
+ s->codec_tag == ff_get_fourcc("RMP4"))
+ s->xvid_build= -1;
+#if 0
+ if(s->codec_tag == ff_get_fourcc("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;
+#endif
+ }
+
+ if(s->xvid_build==0 && s->divx_version==0 && s->lavc_build==0){
+ if(s->codec_tag == ff_get_fourcc("DIVX") && s->vo_type==0 && s->vol_control_parameters==0)
+ s->divx_version= 400; //divx 4
+ }
+
+ if(s->xvid_build && s->divx_version){
+ s->divx_version=
+ s->divx_build= 0;
+ }
+
+ if(s->workaround_bugs&FF_BUG_AUTODETECT){
+ if(s->codec_tag == ff_get_fourcc("XVIX"))
+ s->workaround_bugs|= FF_BUG_XVID_ILACE;
+
+ if(s->codec_tag == ff_get_fourcc("UMP4")){
+ s->workaround_bugs|= FF_BUG_UMP4;
+ }
+
+ if(s->divx_version>=500){
+ s->workaround_bugs|= FF_BUG_QPEL_CHROMA;
+ }
+
+ if(s->divx_version>502){
+ s->workaround_bugs|= FF_BUG_QPEL_CHROMA2;
+ }
+
+ if(s->xvid_build && s->xvid_build<=3)
+ s->padding_bug_score= 256*256*256*64;
+
+ if(s->xvid_build && s->xvid_build<=1)
+ s->workaround_bugs|= FF_BUG_QPEL_CHROMA;
+
+ if(s->xvid_build && s->xvid_build<=12)
+ s->workaround_bugs|= FF_BUG_EDGE;
+
+ if(s->xvid_build && s->xvid_build<=32)
+ s->workaround_bugs|= FF_BUG_DC_CLIP;
+
+#define SET_QPEL_FUNC(postfix1, postfix2) \
+ s->dsp.put_ ## postfix1 = ff_put_ ## postfix2;\
+ 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)
+ s->workaround_bugs|= FF_BUG_STD_QPEL;
+
+ if(s->lavc_build && s->lavc_build<4655)
+ s->workaround_bugs|= FF_BUG_DIRECT_BLOCKSIZE;
+
+ if(s->lavc_build && s->lavc_build<4670){
+ s->workaround_bugs|= FF_BUG_EDGE;
+ }
+
+ if(s->lavc_build && s->lavc_build<=4712)
+ s->workaround_bugs|= FF_BUG_DC_CLIP;
+
+ if(s->divx_version)
+ 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){
+ s->workaround_bugs|= FF_BUG_EDGE;
+ }
+
+ if(s->divx_version)
+ s->workaround_bugs|= FF_BUG_HPEL_CHROMA;
+#if 0
+ if(s->divx_version==500)
+ s->padding_bug_score= 256*256*256*64;
+
+ /* very ugly XVID padding bug detection FIXME/XXX solve this differently
+ * lets hope this at least works
+ */
+ if( s->resync_marker==0 && s->data_partitioning==0 && s->divx_version==0
+ && 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
+ s->workaround_bugs|= FF_BUG_NO_PADDING;
+#endif
+ }
+
+ if(s->workaround_bugs& FF_BUG_STD_QPEL){
+ SET_QPEL_FUNC(qpel_pixels_tab[0][ 5], qpel16_mc11_old_c)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][ 7], qpel16_mc31_old_c)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][ 9], qpel16_mc12_old_c)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][11], qpel16_mc32_old_c)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][13], qpel16_mc13_old_c)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][15], qpel16_mc33_old_c)
+
+ SET_QPEL_FUNC(qpel_pixels_tab[1][ 5], qpel8_mc11_old_c)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][ 7], qpel8_mc31_old_c)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][ 9], qpel8_mc12_old_c)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][11], qpel8_mc32_old_c)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][13], qpel8_mc13_old_c)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][15], qpel8_mc33_old_c)
+ }
+
+ if(avctx->debug & FF_DEBUG_BUGS)
+ av_log(s->avctx, AV_LOG_DEBUG, "bugs: %X lavc_build:%d xvid_build:%d divx_version:%d divx_build:%d %s\n",
+ s->workaround_bugs, s->lavc_build, s->xvid_build, s->divx_version, s->divx_build,
+ s->divx_packed ? "p" : "");
+
+#if 0 // dump bits per frame / qp / complexity
+{
+ static FILE *f=NULL;
+ if(!f) f=fopen("rate_qp_cplx.txt", "w");
+ fprintf(f, "%d %d %f\n", buf_size, s->qscale, buf_size*(double)s->qscale);
+}
+#endif
+
+#if defined(HAVE_MMX) && defined(CONFIG_GPL)
+ if(s->codec_id == CODEC_ID_MPEG4 && s->xvid_build && avctx->idct_algo == FF_IDCT_AUTO && (mm_flags & MM_MMX)){
+ avctx->idct_algo= FF_IDCT_XVIDMMX;
+ avctx->coded_width= 0; // force reinit
+// dsputil_init(&s->dsp, avctx);
+ s->picture_number=0;
+ }
+#endif
+
+ /* After H263 & mpeg4 header decode we have the height, width,*/
+ /* and other parameters. So then we could init the picture */
+ /* FIXME: By the way H263 decoder is evolving it should have */
+ /* an H263EncContext */
+
+ if ( s->width != avctx->coded_width
+ || s->height != avctx->coded_height) {
+ /* H.263 could change picture size any time */
+ ParseContext pc= s->parse_context; //FIXME move these demuxng hack to avformat
+ s->parse_context.buffer=0;
+ MPV_common_end(s);
+ s->parse_context= pc;
+ }
+ if (!s->context_initialized) {
+ avcodec_set_dimensions(avctx, s->width, s->height);
+
+ goto retry;
+ }
+
+ if((s->codec_id==CODEC_ID_H263 || s->codec_id==CODEC_ID_H263P))
+ s->gob_index = ff_h263_get_gob_height(s);
+
+ // for hurry_up==5
+ s->current_picture.pict_type= s->pict_type;
+ s->current_picture.key_frame= s->pict_type == I_TYPE;
+
+ /* skip B-frames if we don't have reference frames */
+ if(s->last_picture_ptr==NULL && (s->pict_type==B_TYPE || s->dropable)) return get_consumed_bytes(s, buf_size);
+ /* skip b frames if we are in a hurry */
+ if(avctx->hurry_up && s->pict_type==B_TYPE) return get_consumed_bytes(s, buf_size);
+ if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==B_TYPE)
+ || (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=I_TYPE)
+ || avctx->skip_frame >= AVDISCARD_ALL)
+ return get_consumed_bytes(s, buf_size);
+ /* skip everything if we are in a hurry>=5 */
+ if(avctx->hurry_up>=5) return get_consumed_bytes(s, buf_size);
+
+ if(s->next_p_frame_damaged){
+ if(s->pict_type==B_TYPE)
+ return get_consumed_bytes(s, buf_size);
+ else
+ s->next_p_frame_damaged=0;
+ }
+
+ if((s->avctx->flags2 & CODEC_FLAG2_FAST) && s->pict_type==B_TYPE){
+ s->me.qpel_put= s->dsp.put_2tap_qpel_pixels_tab;
+ s->me.qpel_avg= s->dsp.avg_2tap_qpel_pixels_tab;
+ }else if((!s->no_rounding) || s->pict_type==B_TYPE){
+ s->me.qpel_put= s->dsp.put_qpel_pixels_tab;
+ s->me.qpel_avg= s->dsp.avg_qpel_pixels_tab;
+ }else{
+ s->me.qpel_put= s->dsp.put_no_rnd_qpel_pixels_tab;
+ s->me.qpel_avg= s->dsp.avg_qpel_pixels_tab;
+ }
+
+ if(MPV_frame_start(s, avctx) < 0)
+ return -1;
+
+#ifdef DEBUG
+ av_log(avctx, AV_LOG_DEBUG, "qscale=%d\n", s->qscale);
+#endif
+
+ ff_er_frame_start(s);
+
+ //the second part of the wmv2 header contains the MB skip bits which are stored in current_picture->mb_type
+ //which isnt available before MPV_frame_start()
+ if (s->msmpeg4_version==5){
+ if(ff_wmv2_decode_secondary_picture_header(s) < 0)
+ return -1;
+ }
+
+ /* decode each macroblock */
+ s->mb_x=0;
+ s->mb_y=0;
+
+ decode_slice(s);
+ while(s->mb_y<s->mb_height){
+ if(s->msmpeg4_version){
+ if(s->slice_height==0 || s->mb_x!=0 || (s->mb_y%s->slice_height)!=0 || get_bits_count(&s->gb) > s->gb.size_in_bits)
+ break;
+ }else{
+ if(ff_h263_resync(s)<0)
+ break;
+ }
+
+ if(s->msmpeg4_version<4 && s->h263_pred)
+ ff_mpeg4_clean_buffers(s);
+
+ decode_slice(s);
+ }
+
+ if (s->h263_msmpeg4 && s->msmpeg4_version<4 && s->pict_type==I_TYPE)
+ if(msmpeg4_decode_ext_header(s, buf_size) < 0){
+ s->error_status_table[s->mb_num-1]= AC_ERROR|DC_ERROR|MV_ERROR;
+ }
+
+ /* divx 5.01+ bistream reorder stuff */
+ if(s->codec_id==CODEC_ID_MPEG4 && s->bitstream_buffer_size==0 && s->divx_packed){
+ int current_pos= get_bits_count(&s->gb)>>3;
+ int startcode_found=0;
+
+ if(buf_size - current_pos > 5){
+ int i;
+ for(i=current_pos; i<buf_size-3; i++){
+ if(buf[i]==0 && buf[i+1]==0 && buf[i+2]==1 && buf[i+3]==0xB6){
+ startcode_found=1;
+ break;
+ }
+ }
+ }
+ if(s->gb.buffer == s->bitstream_buffer && buf_size>20){ //xvid style
+ startcode_found=1;
+ current_pos=0;
+ }
+
+ if(startcode_found){
+ s->bitstream_buffer= av_fast_realloc(
+ s->bitstream_buffer,
+ &s->allocated_bitstream_buffer_size,
+ buf_size - current_pos + FF_INPUT_BUFFER_PADDING_SIZE);
+ memcpy(s->bitstream_buffer, buf + current_pos, buf_size - current_pos);
+ s->bitstream_buffer_size= buf_size - current_pos;
+ }
+ }
+
+ ff_er_frame_end(s);
+
+ MPV_frame_end(s);
+
+assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type);
+assert(s->current_picture.pict_type == s->pict_type);
+ if (s->pict_type == B_TYPE || s->low_delay) {
+ *pict= *(AVFrame*)s->current_picture_ptr;
+ } else if (s->last_picture_ptr != NULL) {
+ *pict= *(AVFrame*)s->last_picture_ptr;
+ }
+
+ if(s->last_picture_ptr || s->low_delay){
+ *data_size = sizeof(AVFrame);
+ ff_print_debug_info(s, pict);
+ }
+
+ /* Return the Picture timestamp as the frame number */
+ /* we substract 1 because it is added on utils.c */
+ avctx->frame_number = s->picture_number - 1;
+
+#ifdef PRINT_FRAME_TIME
+av_log(avctx, AV_LOG_DEBUG, "%"PRId64"\n", rdtsc()-time);
+#endif
+
+ 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,
+};
+
+AVCodec h263_decoder = {
+ "h263",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_H263,
+ sizeof(MpegEncContext),
+ ff_h263_decode_init,
+ NULL,
+ ff_h263_decode_end,
+ ff_h263_decode_frame,
+ CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY,
+ .flush= ff_mpeg_flush,
+};
+
+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,
+};
+
+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,
+};
+
+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,
+};
+
+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,
+};
+
+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,
+};
+
+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
+};
+
+#ifdef CONFIG_H263_PARSER
+AVCodecParser h263_parser = {
+ { CODEC_ID_H263 },
+ sizeof(ParseContext),
+ NULL,
+ h263_parse,
+ ff_parse_close,
+};
+#endif
diff --git a/contrib/ffmpeg/libavcodec/h264.c b/contrib/ffmpeg/libavcodec/h264.c
new file mode 100644
index 000000000..4d72dc2ff
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/h264.c
@@ -0,0 +1,8707 @@
+/*
+ * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder
+ * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * @file h264.c
+ * H.264 / AVC / MPEG4 part10 codec.
+ * @author Michael Niedermayer <michaelni@gmx.at>
+ */
+
+#include "common.h"
+#include "dsputil.h"
+#include "avcodec.h"
+#include "mpegvideo.h"
+#include "h264data.h"
+#include "golomb.h"
+
+#include "cabac.h"
+
+//#undef NDEBUG
+#include <assert.h>
+
+#define interlaced_dct interlaced_dct_is_a_bad_name
+#define mb_intra mb_intra_isnt_initalized_see_mb_type
+
+#define LUMA_DC_BLOCK_INDEX 25
+#define CHROMA_DC_BLOCK_INDEX 26
+
+#define CHROMA_DC_COEFF_TOKEN_VLC_BITS 8
+#define COEFF_TOKEN_VLC_BITS 8
+#define TOTAL_ZEROS_VLC_BITS 9
+#define CHROMA_DC_TOTAL_ZEROS_VLC_BITS 3
+#define RUN_VLC_BITS 3
+#define RUN7_VLC_BITS 6
+
+#define MAX_SPS_COUNT 32
+#define MAX_PPS_COUNT 256
+
+#define MAX_MMCO_COUNT 66
+
+/* Compiling in interlaced support reduces the speed
+ * of progressive decoding by about 2%. */
+#define ALLOW_INTERLACE
+
+#ifdef ALLOW_INTERLACE
+#define MB_MBAFF h->mb_mbaff
+#define MB_FIELD h->mb_field_decoding_flag
+#define FRAME_MBAFF h->mb_aff_frame
+#else
+#define MB_MBAFF 0
+#define MB_FIELD 0
+#define FRAME_MBAFF 0
+#undef IS_INTERLACED
+#define IS_INTERLACED(mb_type) 0
+#endif
+
+/**
+ * Sequence parameter set
+ */
+typedef struct SPS{
+
+ int profile_idc;
+ int level_idc;
+ int transform_bypass; ///< qpprime_y_zero_transform_bypass_flag
+ int log2_max_frame_num; ///< log2_max_frame_num_minus4 + 4
+ int poc_type; ///< pic_order_cnt_type
+ int log2_max_poc_lsb; ///< log2_max_pic_order_cnt_lsb_minus4
+ int delta_pic_order_always_zero_flag;
+ int offset_for_non_ref_pic;
+ int offset_for_top_to_bottom_field;
+ int poc_cycle_length; ///< num_ref_frames_in_pic_order_cnt_cycle
+ int ref_frame_count; ///< num_ref_frames
+ int gaps_in_frame_num_allowed_flag;
+ int mb_width; ///< frame_width_in_mbs_minus1 + 1
+ int mb_height; ///< frame_height_in_mbs_minus1 + 1
+ int frame_mbs_only_flag;
+ int mb_aff; ///<mb_adaptive_frame_field_flag
+ int direct_8x8_inference_flag;
+ int crop; ///< frame_cropping_flag
+ int crop_left; ///< frame_cropping_rect_left_offset
+ int crop_right; ///< frame_cropping_rect_right_offset
+ int crop_top; ///< frame_cropping_rect_top_offset
+ int crop_bottom; ///< frame_cropping_rect_bottom_offset
+ int vui_parameters_present_flag;
+ AVRational sar;
+ int timing_info_present_flag;
+ uint32_t num_units_in_tick;
+ uint32_t time_scale;
+ int fixed_frame_rate_flag;
+ short offset_for_ref_frame[256]; //FIXME dyn aloc?
+ int bitstream_restriction_flag;
+ int num_reorder_frames;
+ int scaling_matrix_present;
+ uint8_t scaling_matrix4[6][16];
+ uint8_t scaling_matrix8[2][64];
+}SPS;
+
+/**
+ * Picture parameter set
+ */
+typedef struct PPS{
+ unsigned int sps_id;
+ int cabac; ///< entropy_coding_mode_flag
+ int pic_order_present; ///< pic_order_present_flag
+ int slice_group_count; ///< num_slice_groups_minus1 + 1
+ int mb_slice_group_map_type;
+ unsigned int ref_count[2]; ///< num_ref_idx_l0/1_active_minus1 + 1
+ int weighted_pred; ///< weighted_pred_flag
+ int weighted_bipred_idc;
+ int init_qp; ///< pic_init_qp_minus26 + 26
+ int init_qs; ///< pic_init_qs_minus26 + 26
+ int chroma_qp_index_offset;
+ int deblocking_filter_parameters_present; ///< deblocking_filter_parameters_present_flag
+ int constrained_intra_pred; ///< constrained_intra_pred_flag
+ int redundant_pic_cnt_present; ///< redundant_pic_cnt_present_flag
+ int transform_8x8_mode; ///< transform_8x8_mode_flag
+ uint8_t scaling_matrix4[6][16];
+ uint8_t scaling_matrix8[2][64];
+}PPS;
+
+/**
+ * Memory management control operation opcode.
+ */
+typedef enum MMCOOpcode{
+ MMCO_END=0,
+ MMCO_SHORT2UNUSED,
+ MMCO_LONG2UNUSED,
+ MMCO_SHORT2LONG,
+ MMCO_SET_MAX_LONG,
+ MMCO_RESET,
+ MMCO_LONG,
+} MMCOOpcode;
+
+/**
+ * Memory management control operation.
+ */
+typedef struct MMCO{
+ MMCOOpcode opcode;
+ int short_frame_num;
+ int long_index;
+} MMCO;
+
+/**
+ * H264Context
+ */
+typedef struct H264Context{
+ MpegEncContext s;
+ int nal_ref_idc;
+ int nal_unit_type;
+ uint8_t *rbsp_buffer;
+ unsigned int rbsp_buffer_size;
+
+ /**
+ * 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)
+
+ int chroma_qp; //QPc
+
+ int prev_mb_skipped;
+ int next_mb_skipped;
+
+ //prediction stuff
+ int chroma_pred_mode;
+ int intra16x16_pred_mode;
+
+ int top_mb_xy;
+ int left_mb_xy[2];
+
+ int8_t intra4x4_pred_mode_cache[5*8];
+ int8_t (*intra4x4_pred_mode)[8];
+ void (*pred4x4 [9+3])(uint8_t *src, uint8_t *topright, int stride);//FIXME move to dsp?
+ void (*pred8x8l [9+3])(uint8_t *src, int topleft, int topright, int stride);
+ void (*pred8x8 [4+3])(uint8_t *src, int stride);
+ void (*pred16x16[4+3])(uint8_t *src, int stride);
+ 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];
+
+ /**
+ * Motion vector cache.
+ */
+ DECLARE_ALIGNED_8(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
+
+ /**
+ * is 1 if the specific list MV&references are set to 0,0,-2.
+ */
+ int mv_cache_clean[2];
+
+ /**
+ * number of neighbors (top and/or left) that used 8x8 dct
+ */
+ int neighbor_transform_size;
+
+ /**
+ * block_offset[ 0..23] for frame macroblocks
+ * block_offset[24..47] for field macroblocks
+ */
+ int block_offset[2*(16+8)];
+
+ uint32_t *mb2b_xy; //FIXME are these 4 a good idea?
+ uint32_t *mb2b8_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;
+
+ int emu_edge_width;
+ int emu_edge_height;
+
+ int halfpel_flag;
+ int thirdpel_flag;
+
+ int unknown_svq3_flag;
+ int next_slice_index;
+
+ SPS sps_buffer[MAX_SPS_COUNT];
+ SPS sps; ///< current sps
+
+ PPS pps_buffer[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 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;
+ uint8_t *slice_table_base;
+ uint8_t *slice_table; ///< slice_table_base + 2*mb_stride + 1
+ int slice_type;
+ int slice_type_fixed;
+
+ //interlacing specific flags
+ int mb_aff_frame;
+ int mb_field_decoding_flag;
+ int mb_mbaff; ///< mb_aff_frame && mb_field_decoding_flag
+
+ unsigned int sub_mb_type[4];
+
+ //POC stuff
+ int poc_lsb;
+ int poc_msb;
+ int delta_poc_bottom;
+ int delta_poc[2];
+ int frame_num;
+ int prev_poc_msb; ///< poc_msb of the last reference pic for POC type 0
+ int prev_poc_lsb; ///< poc_lsb of the last reference pic for POC type 0
+ int frame_num_offset; ///< for POC type 2
+ int prev_frame_num_offset; ///< for POC type 2
+ int prev_frame_num; ///< frame_num of the last pic for POC type 1/2
+
+ /**
+ * frame_num for frames or 2*frame_num for field pics.
+ */
+ int curr_pic_num;
+
+ /**
+ * max_frame_num or 2*max_frame_num for field pics.
+ */
+ 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[32];
+ int map_col_to_list0[2][16];
+ int map_col_to_list0_field[2][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];
+ Picture ref_list[2][48]; ///< 0..15: frame refs, 16..47: mbaff field refs
+ Picture *delayed_pic[18]; //FIXME size?
+ Picture *delayed_output_pic;
+
+ /**
+ * memory management control operations buffer.
+ */
+ MMCO mmco[MAX_MMCO_COUNT];
+ int mmco_index;
+
+ 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_8(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 to 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;
+}H264Context;
+
+static VLC coeff_token_vlc[4];
+static VLC chroma_dc_coeff_token_vlc;
+
+static VLC total_zeros_vlc[15];
+static VLC chroma_dc_total_zeros_vlc[3];
+
+static VLC run_vlc[6];
+static VLC run7_vlc;
+
+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 av_always_inline uint32_t pack16to32(int a, int b){
+#ifdef WORDS_BIGENDIAN
+ return (b&0xFFFF) + (a<<16);
+#else
+ return (a&0xFFFF) + (b<<16);
+#endif
+}
+
+const uint8_t ff_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,
+};
+
+const uint8_t ff_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,
+};
+
+
+/**
+ * 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
+ */
+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(w<=4);
+
+ w *= size;
+ stride *= size;
+
+ assert((((long)vp)&(FFMIN(w, STRIDE_ALIGN)-1)) == 0);
+ assert((stride&(w-1))==0);
+ if(w==2){
+ const uint16_t v= size==4 ? val : val*0x0101;
+ *(uint16_t*)(p + 0*stride)= v;
+ if(h==1) return;
+ *(uint16_t*)(p + 1*stride)= v;
+ if(h==2) return;
+ *(uint16_t*)(p + 2*stride)=
+ *(uint16_t*)(p + 3*stride)= v;
+ }else if(w==4){
+ const uint32_t v= size==4 ? val : val*0x01010101;
+ *(uint32_t*)(p + 0*stride)= v;
+ if(h==1) return;
+ *(uint32_t*)(p + 1*stride)= v;
+ if(h==2) return;
+ *(uint32_t*)(p + 2*stride)=
+ *(uint32_t*)(p + 3*stride)= v;
+ }else if(w==8){
+ //gcc can't optimize 64bit math on x86_32
+#if defined(ARCH_X86_64) || (defined(MP_WORDSIZE) && MP_WORDSIZE >= 64)
+ const uint64_t v= val*0x0100000001ULL;
+ *(uint64_t*)(p + 0*stride)= v;
+ if(h==1) return;
+ *(uint64_t*)(p + 1*stride)= v;
+ if(h==2) return;
+ *(uint64_t*)(p + 2*stride)=
+ *(uint64_t*)(p + 3*stride)= v;
+ }else if(w==16){
+ const uint64_t v= val*0x0100000001ULL;
+ *(uint64_t*)(p + 0+0*stride)=
+ *(uint64_t*)(p + 8+0*stride)=
+ *(uint64_t*)(p + 0+1*stride)=
+ *(uint64_t*)(p + 8+1*stride)= v;
+ if(h==2) return;
+ *(uint64_t*)(p + 0+2*stride)=
+ *(uint64_t*)(p + 8+2*stride)=
+ *(uint64_t*)(p + 0+3*stride)=
+ *(uint64_t*)(p + 8+3*stride)= v;
+#else
+ *(uint32_t*)(p + 0+0*stride)=
+ *(uint32_t*)(p + 4+0*stride)= val;
+ if(h==1) return;
+ *(uint32_t*)(p + 0+1*stride)=
+ *(uint32_t*)(p + 4+1*stride)= val;
+ if(h==2) return;
+ *(uint32_t*)(p + 0+2*stride)=
+ *(uint32_t*)(p + 4+2*stride)=
+ *(uint32_t*)(p + 0+3*stride)=
+ *(uint32_t*)(p + 4+3*stride)= val;
+ }else if(w==16){
+ *(uint32_t*)(p + 0+0*stride)=
+ *(uint32_t*)(p + 4+0*stride)=
+ *(uint32_t*)(p + 8+0*stride)=
+ *(uint32_t*)(p +12+0*stride)=
+ *(uint32_t*)(p + 0+1*stride)=
+ *(uint32_t*)(p + 4+1*stride)=
+ *(uint32_t*)(p + 8+1*stride)=
+ *(uint32_t*)(p +12+1*stride)= val;
+ if(h==2) return;
+ *(uint32_t*)(p + 0+2*stride)=
+ *(uint32_t*)(p + 4+2*stride)=
+ *(uint32_t*)(p + 8+2*stride)=
+ *(uint32_t*)(p +12+2*stride)=
+ *(uint32_t*)(p + 0+3*stride)=
+ *(uint32_t*)(p + 4+3*stride)=
+ *(uint32_t*)(p + 8+3*stride)=
+ *(uint32_t*)(p +12+3*stride)= val;
+#endif
+ }else
+ assert(0);
+ assert(h==4);
+}
+
+static void fill_caches(H264Context *h, int mb_type, int for_deblock){
+ MpegEncContext * const s = &h->s;
+ const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
+ int topleft_xy, top_xy, topright_xy, left_xy[2];
+ int topleft_type, top_type, topright_type, left_type[2];
+ int left_block[8];
+ int i;
+
+ //FIXME deblocking could skip the intra and nnz parts.
+ if(for_deblock && (h->slice_num == 1 || h->slice_table[mb_xy] == h->slice_table[mb_xy-s->mb_stride]) && !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
+
+ top_xy = mb_xy - s->mb_stride;
+ topleft_xy = top_xy - 1;
+ topright_xy= top_xy + 1;
+ left_xy[1] = left_xy[0] = mb_xy-1;
+ left_block[0]= 0;
+ left_block[1]= 1;
+ left_block[2]= 2;
+ left_block[3]= 3;
+ left_block[4]= 7;
+ left_block[5]= 10;
+ left_block[6]= 8;
+ left_block[7]= 11;
+ 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_frame_flag = !IS_INTERLACED(s->current_picture.mb_type[topleft_pair_xy]);
+ const int top_mb_frame_flag = !IS_INTERLACED(s->current_picture.mb_type[top_pair_xy]);
+ const int topright_mb_frame_flag = !IS_INTERLACED(s->current_picture.mb_type[topright_pair_xy]);
+ const int left_mb_frame_flag = !IS_INTERLACED(s->current_picture.mb_type[pair_xy-1]);
+ const int curr_mb_frame_flag = !IS_INTERLACED(mb_type);
+ const int bottom = (s->mb_y & 1);
+ tprintf(s->avctx, "fill_caches: curr_mb_frame_flag:%d, left_mb_frame_flag:%d, topleft_mb_frame_flag:%d, top_mb_frame_flag:%d, topright_mb_frame_flag:%d\n", curr_mb_frame_flag, left_mb_frame_flag, topleft_mb_frame_flag, top_mb_frame_flag, topright_mb_frame_flag);
+ if (bottom
+ ? !curr_mb_frame_flag // bottom macroblock
+ : (!curr_mb_frame_flag && !top_mb_frame_flag) // top macroblock
+ ) {
+ top_xy -= s->mb_stride;
+ }
+ if (bottom
+ ? !curr_mb_frame_flag // bottom macroblock
+ : (!curr_mb_frame_flag && !topleft_mb_frame_flag) // top macroblock
+ ) {
+ topleft_xy -= s->mb_stride;
+ }
+ if (bottom
+ ? !curr_mb_frame_flag // bottom macroblock
+ : (!curr_mb_frame_flag && !topright_mb_frame_flag) // top macroblock
+ ) {
+ topright_xy -= s->mb_stride;
+ }
+ if (left_mb_frame_flag != curr_mb_frame_flag) {
+ left_xy[1] = left_xy[0] = pair_xy - 1;
+ if (curr_mb_frame_flag) {
+ if (bottom) {
+ left_block[0]= 2;
+ left_block[1]= 2;
+ left_block[2]= 3;
+ left_block[3]= 3;
+ left_block[4]= 8;
+ left_block[5]= 11;
+ left_block[6]= 8;
+ left_block[7]= 11;
+ } else {
+ left_block[0]= 0;
+ left_block[1]= 0;
+ left_block[2]= 1;
+ left_block[3]= 1;
+ left_block[4]= 7;
+ left_block[5]= 10;
+ left_block[6]= 7;
+ left_block[7]= 10;
+ }
+ } else {
+ left_xy[1] += s->mb_stride;
+ //left_block[0]= 0;
+ left_block[1]= 2;
+ left_block[2]= 0;
+ left_block[3]= 2;
+ //left_block[4]= 7;
+ left_block[5]= 10;
+ left_block[6]= 7;
+ left_block[7]= 10;
+ }
+ }
+ }
+
+ 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 ] < 255 ? s->current_picture.mb_type[top_xy] : 0;
+ left_type[0] = h->slice_table[left_xy[0] ] < 255 ? s->current_picture.mb_type[left_xy[0]] : 0;
+ left_type[1] = h->slice_table[left_xy[1] ] < 255 ? s->current_picture.mb_type[left_xy[1]] : 0;
+
+ if(FRAME_MBAFF && !IS_INTRA(mb_type)){
+ int list;
+ int v = *(uint16_t*)&h->non_zero_count[mb_xy][14];
+ for(i=0; i<16; i++)
+ h->non_zero_count_cache[scan8[i]] = (v>>i)&1;
+ for(list=0; list<h->list_count; list++){
+ if(USES_LIST(mb_type,list)){
+ uint32_t *src = (uint32_t*)s->current_picture.motion_val[list][h->mb2b_xy[mb_xy]];
+ uint32_t *dst = (uint32_t*)h->mv_cache[list][scan8[0]];
+ int8_t *ref = &s->current_picture.ref_index[list][h->mb2b8_xy[mb_xy]];
+ for(i=0; i<4; i++, dst+=8, src+=h->b_stride){
+ dst[0] = src[0];
+ dst[1] = src[1];
+ dst[2] = src[2];
+ dst[3] = src[3];
+ }
+ *(uint32_t*)&h->ref_cache[list][scan8[ 0]] =
+ *(uint32_t*)&h->ref_cache[list][scan8[ 2]] = pack16to32(ref[0],ref[1])*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])*0x0101;
+ }else{
+ fill_rectangle(&h-> mv_cache[list][scan8[ 0]], 4, 4, 8, 0, 4);
+ fill_rectangle(&h->ref_cache[list][scan8[ 0]], 4, 4, 8, (uint8_t)LIST_NOT_USED, 1);
+ }
+ }
+ }
+ }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)){
+ h->topleft_samples_available=
+ h->top_samples_available=
+ h->left_samples_available= 0xFFFF;
+ h->topright_samples_available= 0xEEEA;
+
+ if(!IS_INTRA(top_type) && (top_type==0 || h->pps.constrained_intra_pred)){
+ h->topleft_samples_available= 0xB3FF;
+ h->top_samples_available= 0x33FF;
+ h->topright_samples_available= 0x26EA;
+ }
+ for(i=0; i<2; i++){
+ if(!IS_INTRA(left_type[i]) && (left_type[i]==0 || h->pps.constrained_intra_pred)){
+ h->topleft_samples_available&= 0xDF5F;
+ h->left_samples_available&= 0x5F5F;
+ }
+ }
+
+ if(!IS_INTRA(topleft_type) && (topleft_type==0 || h->pps.constrained_intra_pred))
+ h->topleft_samples_available&= 0x7FFF;
+
+ if(!IS_INTRA(topright_type) && (topright_type==0 || h->pps.constrained_intra_pred))
+ 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 || (IS_INTER(top_type) && h->pps.constrained_intra_pred))
+ 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] || (IS_INTER(left_type[i]) && h->pps.constrained_intra_pred))
+ 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 (lets 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; list<h->list_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 + 3*h->b_stride;
+ const int b8_xy= h->mb2b8_xy[topleft_xy] + 1 + 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 == 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){
+ MpegEncContext * const s = &h->s;
+ const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
+
+ 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];
+}
+
+/**
+ * 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){
+ 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};
+ int i;
+
+ if(!(h->top_samples_available&0x8000)){
+ for(i=0; i<4; i++){
+ int status= top[ h->intra4x4_pred_mode_cache[scan8[0] + i] ];
+ if(status<0){
+ av_log(h->s.avctx, AV_LOG_ERROR, "top block unavailable for requested intra4x4 mode %d at %d %d\n", status, s->mb_x, s->mb_y);
+ return -1;
+ } else if(status){
+ h->intra4x4_pred_mode_cache[scan8[0] + i]= status;
+ }
+ }
+ }
+
+ if(!(h->left_samples_available&0x8000)){
+ for(i=0; i<4; i++){
+ int status= left[ h->intra4x4_pred_mode_cache[scan8[0] + 8*i] ];
+ if(status<0){
+ av_log(h->s.avctx, AV_LOG_ERROR, "left block unavailable for requested intra4x4 mode %d at %d %d\n", status, s->mb_x, s->mb_y);
+ return -1;
+ } else if(status){
+ h->intra4x4_pred_mode_cache[scan8[0] + 8*i]= status;
+ }
+ }
+ }
+
+ return 0;
+} //FIXME cleanup like next
+
+/**
+ * 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){
+ 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};
+
+ if(mode > 6U) {
+ av_log(h->s.avctx, AV_LOG_ERROR, "out of range intra chroma pred mode at %d %d\n", s->mb_x, s->mb_y);
+ return -1;
+ }
+
+ if(!(h->top_samples_available&0x8000)){
+ mode= top[ mode ];
+ if(mode<0){
+ av_log(h->s.avctx, AV_LOG_ERROR, "top block unavailable for requested intra mode at %d %d\n", s->mb_x, s->mb_y);
+ return -1;
+ }
+ }
+
+ if(!(h->left_samples_available&0x8000)){
+ mode= left[ mode ];
+ if(mode<0){
+ av_log(h->s.avctx, AV_LOG_ERROR, "left block unavailable for requested intra mode at %d %d\n", s->mb_x, s->mb_y);
+ return -1;
+ }
+ }
+
+ 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){
+ MpegEncContext * const s = &h->s;
+ const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
+
+ 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];
+
+ if(FRAME_MBAFF){
+ // store all luma nnzs, for deblocking
+ int v = 0, i;
+ for(i=0; i<16; i++)
+ v += (!!h->non_zero_count_cache[scan8[i]]) << i;
+ *(uint16_t*)&h->non_zero_count[mb_xy][14] = v;
+ }
+}
+
+/**
+ * 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) && !IS_8X8(mb_type))\
+ 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){
+ // leftshift will turn LIST_NOT_USED into PART_NOT_AVAILABLE, but that's ok.
+ SET_DIAG_MV(>>1, <<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 == 0 && *(uint32_t*)h->mv_cache[0][ scan8[0] - 8 ] == 0)
+ || (left_ref == 0 && *(uint32_t*)h->mv_cache[0][ scan8[0] - 1 ] == 0)){
+
+ *mx = *my = 0;
+ return;
+ }
+
+ pred_motion(h, 0, 4, 0, 0, mx, my);
+
+ return;
+}
+
+static inline void direct_dist_scale_factor(H264Context * const h){
+ const int poc = h->s.current_picture_ptr->poc;
+ const int poc1 = h->ref_list[1][0].poc;
+ int i;
+ for(i=0; i<h->ref_count[0]; i++){
+ int poc0 = h->ref_list[0][i].poc;
+ int td = av_clip(poc1 - poc0, -128, 127);
+ if(td == 0 /* FIXME || pic0 is a long-term ref */){
+ h->dist_scale_factor[i] = 256;
+ }else{
+ int tb = av_clip(poc - poc0, -128, 127);
+ int tx = (16384 + (FFABS(td) >> 1)) / td;
+ h->dist_scale_factor[i] = av_clip((tb*tx + 32) >> 6, -1024, 1023);
+ }
+ }
+ if(FRAME_MBAFF){
+ for(i=0; i<h->ref_count[0]; i++){
+ h->dist_scale_factor_field[2*i] =
+ h->dist_scale_factor_field[2*i+1] = h->dist_scale_factor[i];
+ }
+ }
+}
+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, i, j;
+ if(cur->pict_type == I_TYPE)
+ cur->ref_count[0] = 0;
+ if(cur->pict_type != B_TYPE)
+ cur->ref_count[1] = 0;
+ for(list=0; list<2; list++){
+ cur->ref_count[list] = h->ref_count[list];
+ for(j=0; j<h->ref_count[list]; j++)
+ cur->ref_poc[list][j] = h->ref_list[list][j].poc;
+ }
+ if(cur->pict_type != B_TYPE || h->direct_spatial_mv_pred)
+ return;
+ for(list=0; list<2; list++){
+ for(i=0; i<ref1->ref_count[list]; i++){
+ const int poc = ref1->ref_poc[list][i];
+ h->map_col_to_list0[list][i] = 0; /* bogus; fills in for missing frames */
+ for(j=0; j<h->ref_count[list]; j++)
+ if(h->ref_list[list][j].poc == poc){
+ h->map_col_to_list0[list][i] = j;
+ break;
+ }
+ }
+ }
+ if(FRAME_MBAFF){
+ for(list=0; list<2; list++){
+ for(i=0; i<ref1->ref_count[list]; i++){
+ j = h->map_col_to_list0[list][i];
+ h->map_col_to_list0_field[list][2*i] = 2*j;
+ h->map_col_to_list0_field[list][2*i+1] = 2*j+1;
+ }
+ }
+ }
+}
+
+static inline void pred_direct_motion(H264Context * const h, int *mb_type){
+ MpegEncContext * const s = &h->s;
+ const int mb_xy = s->mb_x + s->mb_y*s->mb_stride;
+ const int b8_xy = 2*s->mb_x + 2*s->mb_y*h->b8_stride;
+ const int b4_xy = 4*s->mb_x + 4*s->mb_y*h->b_stride;
+ const int mb_type_col = h->ref_list[1][0].mb_type[mb_xy];
+ const int16_t (*l1mv0)[2] = (const int16_t (*)[2]) &h->ref_list[1][0].motion_val[0][b4_xy];
+ const int16_t (*l1mv1)[2] = (const int16_t (*)[2]) &h->ref_list[1][0].motion_val[1][b4_xy];
+ const int8_t *l1ref0 = &h->ref_list[1][0].ref_index[0][b8_xy];
+ const int8_t *l1ref1 = &h->ref_list[1][0].ref_index[1][b8_xy];
+ const int is_b8x8 = IS_8X8(*mb_type);
+ unsigned int sub_mb_type;
+ int i8, i4;
+
+#define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16|MB_TYPE_INTRA4x4|MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM)
+ if(IS_8X8(mb_type_col) && !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 & 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;
+ }
+ if(!is_b8x8)
+ *mb_type |= MB_TYPE_DIRECT2;
+ if(MB_FIELD)
+ *mb_type |= MB_TYPE_INTERLACED;
+
+ tprintf(s->avctx, "mb_type = %08x, sub_mb_type = %08x, is_b8x8 = %d, mb_type_col = %08x\n", *mb_type, sub_mb_type, is_b8x8, mb_type_col);
+
+ 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 == -2)
+ refc = h->ref_cache[list][scan8[0] - 8 - 1];
+ ref[list] = refa;
+ if(ref[list] < 0 || (refb < ref[list] && refb >= 0))
+ ref[list] = refb;
+ if(ref[list] < 0 || (refc < ref[list] && refc >= 0))
+ ref[list] = 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){
+ *mb_type &= ~MB_TYPE_P0L1;
+ sub_mb_type &= ~MB_TYPE_P0L1;
+ }else if(ref[0] < 0){
+ *mb_type &= ~MB_TYPE_P0L0;
+ sub_mb_type &= ~MB_TYPE_P0L0;
+ }
+
+ 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)
+ && ( (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) && ( l1ref0[x8 + y8*h->b8_stride] == 0
+ || (l1ref0[x8 + y8*h->b8_stride] < 0 && l1ref1[x8 + y8*h->b8_stride] == 0
+ && (h->x264_build>33 || !h->x264_build)))){
+ const int16_t (*l1mv)[2]= l1ref0[x8 + y8*h->b8_stride] == 0 ? l1mv0 : l1mv1;
+ if(IS_SUB_8X8(sub_mb_type)){
+ const int16_t *mv_col = l1mv[x8*3 + y8*3*h->b_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))*h->b_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;
+
+ if(FRAME_MBAFF){
+ if(IS_INTERLACED(*mb_type)){
+ map_col_to_list0[0] = h->map_col_to_list0_field[0];
+ map_col_to_list0[1] = h->map_col_to_list0_field[1];
+ dist_scale_factor = h->dist_scale_factor_field;
+ }
+ if(IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col)){
+ /* FIXME assumes direct_8x8_inference == 1 */
+ const int pair_xy = s->mb_x + (s->mb_y&~1)*s->mb_stride;
+ int mb_types_col[2];
+ int y_shift;
+
+ *mb_type = MB_TYPE_8x8|MB_TYPE_L0L1
+ | (is_b8x8 ? 0 : MB_TYPE_DIRECT2)
+ | (*mb_type & MB_TYPE_INTERLACED);
+ sub_mb_type = MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2|MB_TYPE_16x16;
+
+ if(IS_INTERLACED(*mb_type)){
+ /* frame to field scaling */
+ mb_types_col[0] = h->ref_list[1][0].mb_type[pair_xy];
+ mb_types_col[1] = h->ref_list[1][0].mb_type[pair_xy+s->mb_stride];
+ if(s->mb_y&1){
+ l1ref0 -= 2*h->b8_stride;
+ l1ref1 -= 2*h->b8_stride;
+ l1mv0 -= 4*h->b_stride;
+ l1mv1 -= 4*h->b_stride;
+ }
+ y_shift = 0;
+
+ if( (mb_types_col[0] & MB_TYPE_16x16_OR_INTRA)
+ && (mb_types_col[1] & MB_TYPE_16x16_OR_INTRA)
+ && !is_b8x8)
+ *mb_type |= MB_TYPE_16x8;
+ else
+ *mb_type |= MB_TYPE_8x8;
+ }else{
+ /* field to frame scaling */
+ /* col_mb_y = (mb_y&~1) + (topAbsDiffPOC < bottomAbsDiffPOC ? 0 : 1)
+ * but in MBAFF, top and bottom POC are equal */
+ int dy = (s->mb_y&1) ? 1 : 2;
+ mb_types_col[0] =
+ mb_types_col[1] = h->ref_list[1][0].mb_type[pair_xy+s->mb_stride];
+ l1ref0 += dy*h->b8_stride;
+ l1ref1 += dy*h->b8_stride;
+ l1mv0 += 2*dy*h->b_stride;
+ l1mv1 += 2*dy*h->b_stride;
+ y_shift = 2;
+
+ if((mb_types_col[0] & (MB_TYPE_16x16_OR_INTRA|MB_TYPE_16x8))
+ && !is_b8x8)
+ *mb_type |= MB_TYPE_16x16;
+ else
+ *mb_type |= MB_TYPE_8x8;
+ }
+
+ 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_types_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*2>>y_shift)*h->b8_stride];
+ if(ref0 >= 0)
+ ref0 = map_col_to_list0[0][ref0*2>>y_shift];
+ else{
+ ref0 = map_col_to_list0[1][l1ref1[x8 + (y8*2>>y_shift)*h->b8_stride]*2>>y_shift];
+ 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*6>>y_shift)*h->b_stride];
+ int my_col = (mv_col[1]<<y_shift)/2;
+ int mx = (scale * mv_col[0] + 128) >> 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)){
+ ref=mv0=mv1=0;
+ }else{
+ const int ref0 = l1ref0[0] >= 0 ? map_col_to_list0[0][l1ref0[0]]
+ : map_col_to_list0[1][l1ref1[0]];
+ 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)){
+ 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*h->b8_stride];
+ if(ref0 >= 0)
+ ref0 = map_col_to_list0[0][ref0];
+ else{
+ ref0 = map_col_to_list0[1][l1ref1[x8 + y8*h->b8_stride]];
+ 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*h->b_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))*h->b_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; list<h->list_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 == 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;
+ }
+ }
+}
+
+/**
+ * Decodes a network abstraction layer unit.
+ * @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
+ */
+static uint8_t *decode_nal(H264Context *h, uint8_t *src, int *dst_length, int *consumed, int length){
+ int i, si, di;
+ uint8_t *dst;
+
+// src[0]&0x80; //forbidden bit
+ h->nal_ref_idc= src[0]>>5;
+ h->nal_unit_type= src[0]&0x1F;
+
+ src++; length--;
+#if 0
+ for(i=0; i<length; i++)
+ printf("%2X ", src[i]);
+#endif
+ for(i=0; i+1<length; i+=2){
+ if(src[i]) continue;
+ if(i>0 && src[i-1]==0) i--;
+ if(i+2<length && src[i+1]==0 && src[i+2]<=3){
+ if(src[i+2]!=3){
+ /* startcode, so we must be past the end */
+ length=i;
+ }
+ break;
+ }
+ }
+
+ if(i>=length-1){ //no escaped 0
+ *dst_length= length;
+ *consumed= length+1; //+1 for the header
+ return src;
+ }
+
+ h->rbsp_buffer= av_fast_realloc(h->rbsp_buffer, &h->rbsp_buffer_size, length);
+ dst= h->rbsp_buffer;
+
+ if (dst == NULL){
+ return NULL;
+ }
+
+//printf("decoding esc\n");
+ si=di=0;
+ while(si<length){
+ //remove escapes (very rare 1:2^22)
+ if(si+2<length && src[si]==0 && src[si+1]==0 && src[si+2]<=3){
+ if(src[si+2]==3){ //escape
+ dst[di++]= 0;
+ dst[di++]= 0;
+ si+=3;
+ continue;
+ }else //next start code
+ break;
+ }
+
+ dst[di++]= src[si++];
+ }
+
+ *dst_length= di;
+ *consumed= si + 1;//+1 for the header
+//FIXME store exact number of bits in the getbitcontext (its needed for decoding)
+ return dst;
+}
+
+/**
+ * identifies the exact end of the bitstream
+ * @return the length of the trailing, or 0 if damaged
+ */
+static int decode_rbsp_trailing(H264Context *h, uint8_t *src){
+ int v= *src;
+ int r;
+
+ tprintf(h->s.avctx, "rbsp trailing %X\n", v);
+
+ for(r=1; r<9; r++){
+ if(v&1) return r;
+ v>>=1;
+ }
+ return 0;
+}
+
+/**
+ * idct tranforms the 16 dc values and dequantize them.
+ * @param qp quantization parameter
+ */
+static void h264_luma_dc_dequant_idct_c(DCTELEM *block, int qp, int qmul){
+#define stride 16
+ int i;
+ int temp[16]; //FIXME check if this is a good idea
+ static const int x_offset[4]={0, 1*stride, 4* stride, 5*stride};
+ static const int y_offset[4]={0, 2*stride, 8* stride, 10*stride};
+
+//memset(block, 64, 2*256);
+//return;
+ for(i=0; i<4; i++){
+ const int offset= y_offset[i];
+ const int z0= block[offset+stride*0] + block[offset+stride*4];
+ const int z1= block[offset+stride*0] - block[offset+stride*4];
+ const int z2= block[offset+stride*1] - block[offset+stride*5];
+ const int z3= block[offset+stride*1] + block[offset+stride*5];
+
+ temp[4*i+0]= z0+z3;
+ temp[4*i+1]= z1+z2;
+ temp[4*i+2]= z1-z2;
+ temp[4*i+3]= z0-z3;
+ }
+
+ for(i=0; i<4; i++){
+ const int offset= x_offset[i];
+ const int z0= temp[4*0+i] + temp[4*2+i];
+ const int z1= temp[4*0+i] - temp[4*2+i];
+ const int z2= temp[4*1+i] - temp[4*3+i];
+ const int z3= temp[4*1+i] + temp[4*3+i];
+
+ block[stride*0 +offset]= ((((z0 + z3)*qmul + 128 ) >> 8)); //FIXME think about merging this into decode_resdual
+ block[stride*2 +offset]= ((((z1 + z2)*qmul + 128 ) >> 8));
+ block[stride*8 +offset]= ((((z1 - z2)*qmul + 128 ) >> 8));
+ block[stride*10+offset]= ((((z0 - z3)*qmul + 128 ) >> 8));
+ }
+}
+
+#if 0
+/**
+ * dct tranforms the 16 dc values.
+ * @param qp quantization parameter ??? FIXME
+ */
+static void h264_luma_dc_dct_c(DCTELEM *block/*, int qp*/){
+// const int qmul= dequant_coeff[qp][0];
+ int i;
+ int temp[16]; //FIXME check if this is a good idea
+ static const int x_offset[4]={0, 1*stride, 4* stride, 5*stride};
+ static const int y_offset[4]={0, 2*stride, 8* stride, 10*stride};
+
+ for(i=0; i<4; i++){
+ const int offset= y_offset[i];
+ const int z0= block[offset+stride*0] + block[offset+stride*4];
+ const int z1= block[offset+stride*0] - block[offset+stride*4];
+ const int z2= block[offset+stride*1] - block[offset+stride*5];
+ const int z3= block[offset+stride*1] + block[offset+stride*5];
+
+ temp[4*i+0]= z0+z3;
+ temp[4*i+1]= z1+z2;
+ temp[4*i+2]= z1-z2;
+ temp[4*i+3]= z0-z3;
+ }
+
+ for(i=0; i<4; i++){
+ const int offset= x_offset[i];
+ const int z0= temp[4*0+i] + temp[4*2+i];
+ const int z1= temp[4*0+i] - temp[4*2+i];
+ const int z2= temp[4*1+i] - temp[4*3+i];
+ const int z3= temp[4*1+i] + temp[4*3+i];
+
+ block[stride*0 +offset]= (z0 + z3)>>1;
+ block[stride*2 +offset]= (z1 + z2)>>1;
+ block[stride*8 +offset]= (z1 - z2)>>1;
+ block[stride*10+offset]= (z0 - z3)>>1;
+ }
+}
+#endif
+
+#undef xStride
+#undef stride
+
+static void chroma_dc_dequant_idct_c(DCTELEM *block, int qp, int qmul){
+ const int stride= 16*2;
+ const int xStride= 16;
+ int a,b,c,d,e;
+
+ a= block[stride*0 + xStride*0];
+ b= block[stride*0 + xStride*1];
+ c= block[stride*1 + xStride*0];
+ d= block[stride*1 + xStride*1];
+
+ e= a-b;
+ a= a+b;
+ b= c-d;
+ c= c+d;
+
+ block[stride*0 + xStride*0]= ((a+c)*qmul) >> 7;
+ block[stride*0 + xStride*1]= ((e+b)*qmul) >> 7;
+ block[stride*1 + xStride*0]= ((a-c)*qmul) >> 7;
+ block[stride*1 + xStride*1]= ((e-b)*qmul) >> 7;
+}
+
+#if 0
+static void chroma_dc_dct_c(DCTELEM *block){
+ const int stride= 16*2;
+ const int xStride= 16;
+ int a,b,c,d,e;
+
+ a= block[stride*0 + xStride*0];
+ b= block[stride*0 + xStride*1];
+ c= block[stride*1 + xStride*0];
+ d= block[stride*1 + xStride*1];
+
+ e= a-b;
+ a= a+b;
+ b= c-d;
+ c= c+d;
+
+ block[stride*0 + xStride*0]= (a+c);
+ block[stride*0 + xStride*1]= (e+b);
+ block[stride*1 + xStride*0]= (a-c);
+ block[stride*1 + xStride*1]= (e-b);
+}
+#endif
+
+/**
+ * gets the chroma qp.
+ */
+static inline int get_chroma_qp(int chroma_qp_index_offset, int qscale){
+
+ return chroma_qp[av_clip(qscale + chroma_qp_index_offset, 0, 51)];
+}
+
+//FIXME need to check that this doesnt overflow signed 32 bit for low qp, i am not sure, it's very close
+//FIXME check that gcc inlines this (and optimizes intra & separate_dc stuff away)
+static inline int quantize_c(DCTELEM *block, uint8_t *scantable, int qscale, int intra, int separate_dc){
+ int i;
+ 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);
+ int last_non_zero;
+
+ if(separate_dc){
+ if(qscale<=18){
+ //avoid overflows
+ const int dc_bias= intra ? (1<<(QUANT_SHIFT-2))/3 : (1<<(QUANT_SHIFT-2))/6;
+ const unsigned int dc_threshold1= (1<<(QUANT_SHIFT-2)) - dc_bias - 1;
+ const unsigned int dc_threshold2= (dc_threshold1<<1);
+
+ int level= block[0]*quant_coeff[qscale+18][0];
+ if(((unsigned)(level+dc_threshold1))>dc_threshold2){
+ if(level>0){
+ level= (dc_bias + level)>>(QUANT_SHIFT-2);
+ block[0]= level;
+ }else{
+ level= (dc_bias - level)>>(QUANT_SHIFT-2);
+ block[0]= -level;
+ }
+// last_non_zero = i;
+ }else{
+ block[0]=0;
+ }
+ }else{
+ const int dc_bias= intra ? (1<<(QUANT_SHIFT+1))/3 : (1<<(QUANT_SHIFT+1))/6;
+ const unsigned int dc_threshold1= (1<<(QUANT_SHIFT+1)) - dc_bias - 1;
+ const unsigned int dc_threshold2= (dc_threshold1<<1);
+
+ int level= block[0]*quant_table[0];
+ if(((unsigned)(level+dc_threshold1))>dc_threshold2){
+ if(level>0){
+ level= (dc_bias + level)>>(QUANT_SHIFT+1);
+ block[0]= level;
+ }else{
+ level= (dc_bias - level)>>(QUANT_SHIFT+1);
+ block[0]= -level;
+ }
+// last_non_zero = i;
+ }else{
+ block[0]=0;
+ }
+ }
+ last_non_zero= 0;
+ i=1;
+ }else{
+ last_non_zero= -1;
+ i=0;
+ }
+
+ for(; i<16; i++){
+ const int j= scantable[i];
+ int level= block[j]*quant_table[j];
+
+// if( bias+level >= (1<<(QMAT_SHIFT - 3))
+// || bias-level >= (1<<(QMAT_SHIFT - 3))){
+ if(((unsigned)(level+threshold1))>threshold2){
+ if(level>0){
+ level= (bias + level)>>QUANT_SHIFT;
+ block[j]= level;
+ }else{
+ level= (bias - level)>>QUANT_SHIFT;
+ block[j]= -level;
+ }
+ last_non_zero = i;
+ }else{
+ block[j]=0;
+ }
+ }
+
+ return last_non_zero;
+}
+
+static void pred4x4_vertical_c(uint8_t *src, uint8_t *topright, int stride){
+ const uint32_t a= ((uint32_t*)(src-stride))[0];
+ ((uint32_t*)(src+0*stride))[0]= a;
+ ((uint32_t*)(src+1*stride))[0]= a;
+ ((uint32_t*)(src+2*stride))[0]= a;
+ ((uint32_t*)(src+3*stride))[0]= a;
+}
+
+static void pred4x4_horizontal_c(uint8_t *src, uint8_t *topright, int stride){
+ ((uint32_t*)(src+0*stride))[0]= src[-1+0*stride]*0x01010101;
+ ((uint32_t*)(src+1*stride))[0]= src[-1+1*stride]*0x01010101;
+ ((uint32_t*)(src+2*stride))[0]= src[-1+2*stride]*0x01010101;
+ ((uint32_t*)(src+3*stride))[0]= src[-1+3*stride]*0x01010101;
+}
+
+static void pred4x4_dc_c(uint8_t *src, uint8_t *topright, int stride){
+ const int dc= ( src[-stride] + src[1-stride] + src[2-stride] + src[3-stride]
+ + src[-1+0*stride] + src[-1+1*stride] + src[-1+2*stride] + src[-1+3*stride] + 4) >>3;
+
+ ((uint32_t*)(src+0*stride))[0]=
+ ((uint32_t*)(src+1*stride))[0]=
+ ((uint32_t*)(src+2*stride))[0]=
+ ((uint32_t*)(src+3*stride))[0]= dc* 0x01010101;
+}
+
+static void pred4x4_left_dc_c(uint8_t *src, uint8_t *topright, int stride){
+ const int dc= ( src[-1+0*stride] + src[-1+1*stride] + src[-1+2*stride] + src[-1+3*stride] + 2) >>2;
+
+ ((uint32_t*)(src+0*stride))[0]=
+ ((uint32_t*)(src+1*stride))[0]=
+ ((uint32_t*)(src+2*stride))[0]=
+ ((uint32_t*)(src+3*stride))[0]= dc* 0x01010101;
+}
+
+static void pred4x4_top_dc_c(uint8_t *src, uint8_t *topright, int stride){
+ const int dc= ( src[-stride] + src[1-stride] + src[2-stride] + src[3-stride] + 2) >>2;
+
+ ((uint32_t*)(src+0*stride))[0]=
+ ((uint32_t*)(src+1*stride))[0]=
+ ((uint32_t*)(src+2*stride))[0]=
+ ((uint32_t*)(src+3*stride))[0]= dc* 0x01010101;
+}
+
+static void pred4x4_128_dc_c(uint8_t *src, uint8_t *topright, int stride){
+ ((uint32_t*)(src+0*stride))[0]=
+ ((uint32_t*)(src+1*stride))[0]=
+ ((uint32_t*)(src+2*stride))[0]=
+ ((uint32_t*)(src+3*stride))[0]= 128U*0x01010101U;
+}
+
+
+#define LOAD_TOP_RIGHT_EDGE\
+ const int t4= topright[0];\
+ const int t5= topright[1];\
+ const int t6= topright[2];\
+ const int t7= topright[3];\
+
+#define LOAD_LEFT_EDGE\
+ const int l0= src[-1+0*stride];\
+ const int l1= src[-1+1*stride];\
+ const int l2= src[-1+2*stride];\
+ const int l3= src[-1+3*stride];\
+
+#define LOAD_TOP_EDGE\
+ const int t0= src[ 0-1*stride];\
+ const int t1= src[ 1-1*stride];\
+ const int t2= src[ 2-1*stride];\
+ const int t3= src[ 3-1*stride];\
+
+static void pred4x4_down_right_c(uint8_t *src, uint8_t *topright, int stride){
+ const int lt= src[-1-1*stride];
+ LOAD_TOP_EDGE
+ LOAD_LEFT_EDGE
+
+ src[0+3*stride]=(l3 + 2*l2 + l1 + 2)>>2;
+ src[0+2*stride]=
+ src[1+3*stride]=(l2 + 2*l1 + l0 + 2)>>2;
+ src[0+1*stride]=
+ src[1+2*stride]=
+ src[2+3*stride]=(l1 + 2*l0 + lt + 2)>>2;
+ src[0+0*stride]=
+ src[1+1*stride]=
+ src[2+2*stride]=
+ src[3+3*stride]=(l0 + 2*lt + t0 + 2)>>2;
+ src[1+0*stride]=
+ src[2+1*stride]=
+ src[3+2*stride]=(lt + 2*t0 + t1 + 2)>>2;
+ src[2+0*stride]=
+ src[3+1*stride]=(t0 + 2*t1 + t2 + 2)>>2;
+ src[3+0*stride]=(t1 + 2*t2 + t3 + 2)>>2;
+}
+
+static void pred4x4_down_left_c(uint8_t *src, uint8_t *topright, int stride){
+ LOAD_TOP_EDGE
+ LOAD_TOP_RIGHT_EDGE
+// LOAD_LEFT_EDGE
+
+ src[0+0*stride]=(t0 + t2 + 2*t1 + 2)>>2;
+ src[1+0*stride]=
+ src[0+1*stride]=(t1 + t3 + 2*t2 + 2)>>2;
+ src[2+0*stride]=
+ src[1+1*stride]=
+ src[0+2*stride]=(t2 + t4 + 2*t3 + 2)>>2;
+ src[3+0*stride]=
+ src[2+1*stride]=
+ src[1+2*stride]=
+ src[0+3*stride]=(t3 + t5 + 2*t4 + 2)>>2;
+ src[3+1*stride]=
+ src[2+2*stride]=
+ src[1+3*stride]=(t4 + t6 + 2*t5 + 2)>>2;
+ src[3+2*stride]=
+ src[2+3*stride]=(t5 + t7 + 2*t6 + 2)>>2;
+ src[3+3*stride]=(t6 + 3*t7 + 2)>>2;
+}
+
+static void pred4x4_vertical_right_c(uint8_t *src, uint8_t *topright, int stride){
+ const int lt= src[-1-1*stride];
+ LOAD_TOP_EDGE
+ LOAD_LEFT_EDGE
+ const __attribute__((unused)) int unu= l3;
+
+ src[0+0*stride]=
+ src[1+2*stride]=(lt + t0 + 1)>>1;
+ src[1+0*stride]=
+ src[2+2*stride]=(t0 + t1 + 1)>>1;
+ src[2+0*stride]=
+ src[3+2*stride]=(t1 + t2 + 1)>>1;
+ src[3+0*stride]=(t2 + t3 + 1)>>1;
+ src[0+1*stride]=
+ src[1+3*stride]=(l0 + 2*lt + t0 + 2)>>2;
+ src[1+1*stride]=
+ src[2+3*stride]=(lt + 2*t0 + t1 + 2)>>2;
+ src[2+1*stride]=
+ src[3+3*stride]=(t0 + 2*t1 + t2 + 2)>>2;
+ src[3+1*stride]=(t1 + 2*t2 + t3 + 2)>>2;
+ src[0+2*stride]=(lt + 2*l0 + l1 + 2)>>2;
+ src[0+3*stride]=(l0 + 2*l1 + l2 + 2)>>2;
+}
+
+static void pred4x4_vertical_left_c(uint8_t *src, uint8_t *topright, int stride){
+ LOAD_TOP_EDGE
+ LOAD_TOP_RIGHT_EDGE
+ const __attribute__((unused)) int unu= t7;
+
+ src[0+0*stride]=(t0 + t1 + 1)>>1;
+ src[1+0*stride]=
+ src[0+2*stride]=(t1 + t2 + 1)>>1;
+ src[2+0*stride]=
+ src[1+2*stride]=(t2 + t3 + 1)>>1;
+ src[3+0*stride]=
+ src[2+2*stride]=(t3 + t4+ 1)>>1;
+ src[3+2*stride]=(t4 + t5+ 1)>>1;
+ src[0+1*stride]=(t0 + 2*t1 + t2 + 2)>>2;
+ src[1+1*stride]=
+ src[0+3*stride]=(t1 + 2*t2 + t3 + 2)>>2;
+ src[2+1*stride]=
+ src[1+3*stride]=(t2 + 2*t3 + t4 + 2)>>2;
+ src[3+1*stride]=
+ src[2+3*stride]=(t3 + 2*t4 + t5 + 2)>>2;
+ src[3+3*stride]=(t4 + 2*t5 + t6 + 2)>>2;
+}
+
+static void pred4x4_horizontal_up_c(uint8_t *src, uint8_t *topright, int stride){
+ LOAD_LEFT_EDGE
+
+ src[0+0*stride]=(l0 + l1 + 1)>>1;
+ src[1+0*stride]=(l0 + 2*l1 + l2 + 2)>>2;
+ src[2+0*stride]=
+ src[0+1*stride]=(l1 + l2 + 1)>>1;
+ src[3+0*stride]=
+ src[1+1*stride]=(l1 + 2*l2 + l3 + 2)>>2;
+ src[2+1*stride]=
+ src[0+2*stride]=(l2 + l3 + 1)>>1;
+ src[3+1*stride]=
+ src[1+2*stride]=(l2 + 2*l3 + l3 + 2)>>2;
+ src[3+2*stride]=
+ src[1+3*stride]=
+ src[0+3*stride]=
+ src[2+2*stride]=
+ src[2+3*stride]=
+ src[3+3*stride]=l3;
+}
+
+static void pred4x4_horizontal_down_c(uint8_t *src, uint8_t *topright, int stride){
+ const int lt= src[-1-1*stride];
+ LOAD_TOP_EDGE
+ LOAD_LEFT_EDGE
+ const __attribute__((unused)) int unu= t3;
+
+ src[0+0*stride]=
+ src[2+1*stride]=(lt + l0 + 1)>>1;
+ src[1+0*stride]=
+ src[3+1*stride]=(l0 + 2*lt + t0 + 2)>>2;
+ src[2+0*stride]=(lt + 2*t0 + t1 + 2)>>2;
+ src[3+0*stride]=(t0 + 2*t1 + t2 + 2)>>2;
+ src[0+1*stride]=
+ src[2+2*stride]=(l0 + l1 + 1)>>1;
+ src[1+1*stride]=
+ src[3+2*stride]=(lt + 2*l0 + l1 + 2)>>2;
+ src[0+2*stride]=
+ src[2+3*stride]=(l1 + l2+ 1)>>1;
+ src[1+2*stride]=
+ src[3+3*stride]=(l0 + 2*l1 + l2 + 2)>>2;
+ src[0+3*stride]=(l2 + l3 + 1)>>1;
+ src[1+3*stride]=(l1 + 2*l2 + l3 + 2)>>2;
+}
+
+void ff_pred16x16_vertical_c(uint8_t *src, int stride){
+ int i;
+ const uint32_t a= ((uint32_t*)(src-stride))[0];
+ const uint32_t b= ((uint32_t*)(src-stride))[1];
+ const uint32_t c= ((uint32_t*)(src-stride))[2];
+ const uint32_t d= ((uint32_t*)(src-stride))[3];
+
+ for(i=0; i<16; i++){
+ ((uint32_t*)(src+i*stride))[0]= a;
+ ((uint32_t*)(src+i*stride))[1]= b;
+ ((uint32_t*)(src+i*stride))[2]= c;
+ ((uint32_t*)(src+i*stride))[3]= d;
+ }
+}
+
+void ff_pred16x16_horizontal_c(uint8_t *src, int stride){
+ int i;
+
+ for(i=0; i<16; i++){
+ ((uint32_t*)(src+i*stride))[0]=
+ ((uint32_t*)(src+i*stride))[1]=
+ ((uint32_t*)(src+i*stride))[2]=
+ ((uint32_t*)(src+i*stride))[3]= src[-1+i*stride]*0x01010101;
+ }
+}
+
+void ff_pred16x16_dc_c(uint8_t *src, int stride){
+ int i, dc=0;
+
+ for(i=0;i<16; i++){
+ dc+= src[-1+i*stride];
+ }
+
+ for(i=0;i<16; i++){
+ dc+= src[i-stride];
+ }
+
+ dc= 0x01010101*((dc + 16)>>5);
+
+ for(i=0; i<16; i++){
+ ((uint32_t*)(src+i*stride))[0]=
+ ((uint32_t*)(src+i*stride))[1]=
+ ((uint32_t*)(src+i*stride))[2]=
+ ((uint32_t*)(src+i*stride))[3]= dc;
+ }
+}
+
+static void pred16x16_left_dc_c(uint8_t *src, int stride){
+ int i, dc=0;
+
+ for(i=0;i<16; i++){
+ dc+= src[-1+i*stride];
+ }
+
+ dc= 0x01010101*((dc + 8)>>4);
+
+ for(i=0; i<16; i++){
+ ((uint32_t*)(src+i*stride))[0]=
+ ((uint32_t*)(src+i*stride))[1]=
+ ((uint32_t*)(src+i*stride))[2]=
+ ((uint32_t*)(src+i*stride))[3]= dc;
+ }
+}
+
+static void pred16x16_top_dc_c(uint8_t *src, int stride){
+ int i, dc=0;
+
+ for(i=0;i<16; i++){
+ dc+= src[i-stride];
+ }
+ dc= 0x01010101*((dc + 8)>>4);
+
+ for(i=0; i<16; i++){
+ ((uint32_t*)(src+i*stride))[0]=
+ ((uint32_t*)(src+i*stride))[1]=
+ ((uint32_t*)(src+i*stride))[2]=
+ ((uint32_t*)(src+i*stride))[3]= dc;
+ }
+}
+
+void ff_pred16x16_128_dc_c(uint8_t *src, int stride){
+ int i;
+
+ for(i=0; i<16; i++){
+ ((uint32_t*)(src+i*stride))[0]=
+ ((uint32_t*)(src+i*stride))[1]=
+ ((uint32_t*)(src+i*stride))[2]=
+ ((uint32_t*)(src+i*stride))[3]= 0x01010101U*128U;
+ }
+}
+
+static inline void pred16x16_plane_compat_c(uint8_t *src, int stride, const int svq3){
+ int i, j, k;
+ int a;
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+ const uint8_t * const src0 = src+7-stride;
+ const uint8_t *src1 = src+8*stride-1;
+ const uint8_t *src2 = src1-2*stride; // == src+6*stride-1;
+ int H = src0[1] - src0[-1];
+ int V = src1[0] - src2[ 0];
+ for(k=2; k<=8; ++k) {
+ src1 += stride; src2 -= stride;
+ H += k*(src0[k] - src0[-k]);
+ V += k*(src1[0] - src2[ 0]);
+ }
+ if(svq3){
+ H = ( 5*(H/4) ) / 16;
+ V = ( 5*(V/4) ) / 16;
+
+ /* required for 100% accuracy */
+ i = H; H = V; V = i;
+ }else{
+ H = ( 5*H+32 ) >> 6;
+ V = ( 5*V+32 ) >> 6;
+ }
+
+ a = 16*(src1[0] + src2[16] + 1) - 7*(V+H);
+ for(j=16; j>0; --j) {
+ int b = a;
+ a += V;
+ for(i=-16; i<0; i+=4) {
+ src[16+i] = cm[ (b ) >> 5 ];
+ src[17+i] = cm[ (b+ H) >> 5 ];
+ src[18+i] = cm[ (b+2*H) >> 5 ];
+ src[19+i] = cm[ (b+3*H) >> 5 ];
+ b += 4*H;
+ }
+ src += stride;
+ }
+}
+
+void ff_pred16x16_plane_c(uint8_t *src, int stride){
+ pred16x16_plane_compat_c(src, stride, 0);
+}
+
+void ff_pred8x8_vertical_c(uint8_t *src, int stride){
+ int i;
+ const uint32_t a= ((uint32_t*)(src-stride))[0];
+ const uint32_t b= ((uint32_t*)(src-stride))[1];
+
+ for(i=0; i<8; i++){
+ ((uint32_t*)(src+i*stride))[0]= a;
+ ((uint32_t*)(src+i*stride))[1]= b;
+ }
+}
+
+void ff_pred8x8_horizontal_c(uint8_t *src, int stride){
+ int i;
+
+ for(i=0; i<8; i++){
+ ((uint32_t*)(src+i*stride))[0]=
+ ((uint32_t*)(src+i*stride))[1]= src[-1+i*stride]*0x01010101;
+ }
+}
+
+void ff_pred8x8_128_dc_c(uint8_t *src, int stride){
+ int i;
+
+ for(i=0; i<8; i++){
+ ((uint32_t*)(src+i*stride))[0]=
+ ((uint32_t*)(src+i*stride))[1]= 0x01010101U*128U;
+ }
+}
+
+static void pred8x8_left_dc_c(uint8_t *src, int stride){
+ int i;
+ int dc0, dc2;
+
+ dc0=dc2=0;
+ for(i=0;i<4; i++){
+ dc0+= src[-1+i*stride];
+ dc2+= src[-1+(i+4)*stride];
+ }
+ dc0= 0x01010101*((dc0 + 2)>>2);
+ dc2= 0x01010101*((dc2 + 2)>>2);
+
+ for(i=0; i<4; i++){
+ ((uint32_t*)(src+i*stride))[0]=
+ ((uint32_t*)(src+i*stride))[1]= dc0;
+ }
+ for(i=4; i<8; i++){
+ ((uint32_t*)(src+i*stride))[0]=
+ ((uint32_t*)(src+i*stride))[1]= dc2;
+ }
+}
+
+static void pred8x8_top_dc_c(uint8_t *src, int stride){
+ int i;
+ int dc0, dc1;
+
+ dc0=dc1=0;
+ for(i=0;i<4; i++){
+ dc0+= src[i-stride];
+ dc1+= src[4+i-stride];
+ }
+ dc0= 0x01010101*((dc0 + 2)>>2);
+ dc1= 0x01010101*((dc1 + 2)>>2);
+
+ for(i=0; i<4; i++){
+ ((uint32_t*)(src+i*stride))[0]= dc0;
+ ((uint32_t*)(src+i*stride))[1]= dc1;
+ }
+ for(i=4; i<8; i++){
+ ((uint32_t*)(src+i*stride))[0]= dc0;
+ ((uint32_t*)(src+i*stride))[1]= dc1;
+ }
+}
+
+
+void ff_pred8x8_dc_c(uint8_t *src, int stride){
+ int i;
+ int dc0, dc1, dc2, dc3;
+
+ dc0=dc1=dc2=0;
+ for(i=0;i<4; i++){
+ dc0+= src[-1+i*stride] + src[i-stride];
+ dc1+= src[4+i-stride];
+ dc2+= src[-1+(i+4)*stride];
+ }
+ dc3= 0x01010101*((dc1 + dc2 + 4)>>3);
+ dc0= 0x01010101*((dc0 + 4)>>3);
+ dc1= 0x01010101*((dc1 + 2)>>2);
+ dc2= 0x01010101*((dc2 + 2)>>2);
+
+ for(i=0; i<4; i++){
+ ((uint32_t*)(src+i*stride))[0]= dc0;
+ ((uint32_t*)(src+i*stride))[1]= dc1;
+ }
+ for(i=4; i<8; i++){
+ ((uint32_t*)(src+i*stride))[0]= dc2;
+ ((uint32_t*)(src+i*stride))[1]= dc3;
+ }
+}
+
+void ff_pred8x8_plane_c(uint8_t *src, int stride){
+ int j, k;
+ int a;
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+ const uint8_t * const src0 = src+3-stride;
+ const uint8_t *src1 = src+4*stride-1;
+ const uint8_t *src2 = src1-2*stride; // == src+2*stride-1;
+ int H = src0[1] - src0[-1];
+ int V = src1[0] - src2[ 0];
+ for(k=2; k<=4; ++k) {
+ src1 += stride; src2 -= stride;
+ H += k*(src0[k] - src0[-k]);
+ V += k*(src1[0] - src2[ 0]);
+ }
+ H = ( 17*H+16 ) >> 5;
+ V = ( 17*V+16 ) >> 5;
+
+ a = 16*(src1[0] + src2[8]+1) - 3*(V+H);
+ for(j=8; j>0; --j) {
+ int b = a;
+ a += V;
+ src[0] = cm[ (b ) >> 5 ];
+ src[1] = cm[ (b+ H) >> 5 ];
+ src[2] = cm[ (b+2*H) >> 5 ];
+ src[3] = cm[ (b+3*H) >> 5 ];
+ src[4] = cm[ (b+4*H) >> 5 ];
+ src[5] = cm[ (b+5*H) >> 5 ];
+ src[6] = cm[ (b+6*H) >> 5 ];
+ src[7] = cm[ (b+7*H) >> 5 ];
+ src += stride;
+ }
+}
+
+#define SRC(x,y) src[(x)+(y)*stride]
+#define PL(y) \
+ const int l##y = (SRC(-1,y-1) + 2*SRC(-1,y) + SRC(-1,y+1) + 2) >> 2;
+#define PREDICT_8x8_LOAD_LEFT \
+ const int l0 = ((has_topleft ? SRC(-1,-1) : SRC(-1,0)) \
+ + 2*SRC(-1,0) + SRC(-1,1) + 2) >> 2; \
+ PL(1) PL(2) PL(3) PL(4) PL(5) PL(6) \
+ const int l7 attribute_unused = (SRC(-1,6) + 3*SRC(-1,7) + 2) >> 2
+
+#define PT(x) \
+ const int t##x = (SRC(x-1,-1) + 2*SRC(x,-1) + SRC(x+1,-1) + 2) >> 2;
+#define PREDICT_8x8_LOAD_TOP \
+ const int t0 = ((has_topleft ? SRC(-1,-1) : SRC(0,-1)) \
+ + 2*SRC(0,-1) + SRC(1,-1) + 2) >> 2; \
+ PT(1) PT(2) PT(3) PT(4) PT(5) PT(6) \
+ const int t7 attribute_unused = ((has_topright ? SRC(8,-1) : SRC(7,-1)) \
+ + 2*SRC(7,-1) + SRC(6,-1) + 2) >> 2
+
+#define PTR(x) \
+ t##x = (SRC(x-1,-1) + 2*SRC(x,-1) + SRC(x+1,-1) + 2) >> 2;
+#define PREDICT_8x8_LOAD_TOPRIGHT \
+ int t8, t9, t10, t11, t12, t13, t14, t15; \
+ if(has_topright) { \
+ PTR(8) PTR(9) PTR(10) PTR(11) PTR(12) PTR(13) PTR(14) \
+ t15 = (SRC(14,-1) + 3*SRC(15,-1) + 2) >> 2; \
+ } else t8=t9=t10=t11=t12=t13=t14=t15= SRC(7,-1);
+
+#define PREDICT_8x8_LOAD_TOPLEFT \
+ const int lt = (SRC(-1,0) + 2*SRC(-1,-1) + SRC(0,-1) + 2) >> 2
+
+#define PREDICT_8x8_DC(v) \
+ int y; \
+ for( y = 0; y < 8; y++ ) { \
+ ((uint32_t*)src)[0] = \
+ ((uint32_t*)src)[1] = v; \
+ src += stride; \
+ }
+
+static void pred8x8l_128_dc_c(uint8_t *src, int has_topleft, int has_topright, int stride)
+{
+ PREDICT_8x8_DC(0x80808080);
+}
+static void pred8x8l_left_dc_c(uint8_t *src, int has_topleft, int has_topright, int stride)
+{
+ PREDICT_8x8_LOAD_LEFT;
+ const uint32_t dc = ((l0+l1+l2+l3+l4+l5+l6+l7+4) >> 3) * 0x01010101;
+ PREDICT_8x8_DC(dc);
+}
+static void pred8x8l_top_dc_c(uint8_t *src, int has_topleft, int has_topright, int stride)
+{
+ PREDICT_8x8_LOAD_TOP;
+ const uint32_t dc = ((t0+t1+t2+t3+t4+t5+t6+t7+4) >> 3) * 0x01010101;
+ PREDICT_8x8_DC(dc);
+}
+static void pred8x8l_dc_c(uint8_t *src, int has_topleft, int has_topright, int stride)
+{
+ PREDICT_8x8_LOAD_LEFT;
+ PREDICT_8x8_LOAD_TOP;
+ const uint32_t dc = ((l0+l1+l2+l3+l4+l5+l6+l7
+ +t0+t1+t2+t3+t4+t5+t6+t7+8) >> 4) * 0x01010101;
+ PREDICT_8x8_DC(dc);
+}
+static void pred8x8l_horizontal_c(uint8_t *src, int has_topleft, int has_topright, int stride)
+{
+ PREDICT_8x8_LOAD_LEFT;
+#define ROW(y) ((uint32_t*)(src+y*stride))[0] =\
+ ((uint32_t*)(src+y*stride))[1] = 0x01010101 * l##y
+ ROW(0); ROW(1); ROW(2); ROW(3); ROW(4); ROW(5); ROW(6); ROW(7);
+#undef ROW
+}
+static void pred8x8l_vertical_c(uint8_t *src, int has_topleft, int has_topright, int stride)
+{
+ int y;
+ PREDICT_8x8_LOAD_TOP;
+ src[0] = t0;
+ src[1] = t1;
+ src[2] = t2;
+ src[3] = t3;
+ src[4] = t4;
+ src[5] = t5;
+ src[6] = t6;
+ src[7] = t7;
+ for( y = 1; y < 8; y++ )
+ *(uint64_t*)(src+y*stride) = *(uint64_t*)src;
+}
+static void pred8x8l_down_left_c(uint8_t *src, int has_topleft, int has_topright, int stride)
+{
+ PREDICT_8x8_LOAD_TOP;
+ PREDICT_8x8_LOAD_TOPRIGHT;
+ SRC(0,0)= (t0 + 2*t1 + t2 + 2) >> 2;
+ SRC(0,1)=SRC(1,0)= (t1 + 2*t2 + t3 + 2) >> 2;
+ SRC(0,2)=SRC(1,1)=SRC(2,0)= (t2 + 2*t3 + t4 + 2) >> 2;
+ SRC(0,3)=SRC(1,2)=SRC(2,1)=SRC(3,0)= (t3 + 2*t4 + t5 + 2) >> 2;
+ SRC(0,4)=SRC(1,3)=SRC(2,2)=SRC(3,1)=SRC(4,0)= (t4 + 2*t5 + t6 + 2) >> 2;
+ SRC(0,5)=SRC(1,4)=SRC(2,3)=SRC(3,2)=SRC(4,1)=SRC(5,0)= (t5 + 2*t6 + t7 + 2) >> 2;
+ SRC(0,6)=SRC(1,5)=SRC(2,4)=SRC(3,3)=SRC(4,2)=SRC(5,1)=SRC(6,0)= (t6 + 2*t7 + t8 + 2) >> 2;
+ SRC(0,7)=SRC(1,6)=SRC(2,5)=SRC(3,4)=SRC(4,3)=SRC(5,2)=SRC(6,1)=SRC(7,0)= (t7 + 2*t8 + t9 + 2) >> 2;
+ SRC(1,7)=SRC(2,6)=SRC(3,5)=SRC(4,4)=SRC(5,3)=SRC(6,2)=SRC(7,1)= (t8 + 2*t9 + t10 + 2) >> 2;
+ SRC(2,7)=SRC(3,6)=SRC(4,5)=SRC(5,4)=SRC(6,3)=SRC(7,2)= (t9 + 2*t10 + t11 + 2) >> 2;
+ SRC(3,7)=SRC(4,6)=SRC(5,5)=SRC(6,4)=SRC(7,3)= (t10 + 2*t11 + t12 + 2) >> 2;
+ SRC(4,7)=SRC(5,6)=SRC(6,5)=SRC(7,4)= (t11 + 2*t12 + t13 + 2) >> 2;
+ SRC(5,7)=SRC(6,6)=SRC(7,5)= (t12 + 2*t13 + t14 + 2) >> 2;
+ SRC(6,7)=SRC(7,6)= (t13 + 2*t14 + t15 + 2) >> 2;
+ SRC(7,7)= (t14 + 3*t15 + 2) >> 2;
+}
+static void pred8x8l_down_right_c(uint8_t *src, int has_topleft, int has_topright, int stride)
+{
+ PREDICT_8x8_LOAD_TOP;
+ PREDICT_8x8_LOAD_LEFT;
+ PREDICT_8x8_LOAD_TOPLEFT;
+ SRC(0,7)= (l7 + 2*l6 + l5 + 2) >> 2;
+ SRC(0,6)=SRC(1,7)= (l6 + 2*l5 + l4 + 2) >> 2;
+ SRC(0,5)=SRC(1,6)=SRC(2,7)= (l5 + 2*l4 + l3 + 2) >> 2;
+ SRC(0,4)=SRC(1,5)=SRC(2,6)=SRC(3,7)= (l4 + 2*l3 + l2 + 2) >> 2;
+ SRC(0,3)=SRC(1,4)=SRC(2,5)=SRC(3,6)=SRC(4,7)= (l3 + 2*l2 + l1 + 2) >> 2;
+ SRC(0,2)=SRC(1,3)=SRC(2,4)=SRC(3,5)=SRC(4,6)=SRC(5,7)= (l2 + 2*l1 + l0 + 2) >> 2;
+ SRC(0,1)=SRC(1,2)=SRC(2,3)=SRC(3,4)=SRC(4,5)=SRC(5,6)=SRC(6,7)= (l1 + 2*l0 + lt + 2) >> 2;
+ SRC(0,0)=SRC(1,1)=SRC(2,2)=SRC(3,3)=SRC(4,4)=SRC(5,5)=SRC(6,6)=SRC(7,7)= (l0 + 2*lt + t0 + 2) >> 2;
+ SRC(1,0)=SRC(2,1)=SRC(3,2)=SRC(4,3)=SRC(5,4)=SRC(6,5)=SRC(7,6)= (lt + 2*t0 + t1 + 2) >> 2;
+ SRC(2,0)=SRC(3,1)=SRC(4,2)=SRC(5,3)=SRC(6,4)=SRC(7,5)= (t0 + 2*t1 + t2 + 2) >> 2;
+ SRC(3,0)=SRC(4,1)=SRC(5,2)=SRC(6,3)=SRC(7,4)= (t1 + 2*t2 + t3 + 2) >> 2;
+ SRC(4,0)=SRC(5,1)=SRC(6,2)=SRC(7,3)= (t2 + 2*t3 + t4 + 2) >> 2;
+ SRC(5,0)=SRC(6,1)=SRC(7,2)= (t3 + 2*t4 + t5 + 2) >> 2;
+ SRC(6,0)=SRC(7,1)= (t4 + 2*t5 + t6 + 2) >> 2;
+ SRC(7,0)= (t5 + 2*t6 + t7 + 2) >> 2;
+
+}
+static void pred8x8l_vertical_right_c(uint8_t *src, int has_topleft, int has_topright, int stride)
+{
+ PREDICT_8x8_LOAD_TOP;
+ PREDICT_8x8_LOAD_LEFT;
+ PREDICT_8x8_LOAD_TOPLEFT;
+ SRC(0,6)= (l5 + 2*l4 + l3 + 2) >> 2;
+ SRC(0,7)= (l6 + 2*l5 + l4 + 2) >> 2;
+ SRC(0,4)=SRC(1,6)= (l3 + 2*l2 + l1 + 2) >> 2;
+ SRC(0,5)=SRC(1,7)= (l4 + 2*l3 + l2 + 2) >> 2;
+ SRC(0,2)=SRC(1,4)=SRC(2,6)= (l1 + 2*l0 + lt + 2) >> 2;
+ SRC(0,3)=SRC(1,5)=SRC(2,7)= (l2 + 2*l1 + l0 + 2) >> 2;
+ SRC(0,1)=SRC(1,3)=SRC(2,5)=SRC(3,7)= (l0 + 2*lt + t0 + 2) >> 2;
+ SRC(0,0)=SRC(1,2)=SRC(2,4)=SRC(3,6)= (lt + t0 + 1) >> 1;
+ SRC(1,1)=SRC(2,3)=SRC(3,5)=SRC(4,7)= (lt + 2*t0 + t1 + 2) >> 2;
+ SRC(1,0)=SRC(2,2)=SRC(3,4)=SRC(4,6)= (t0 + t1 + 1) >> 1;
+ SRC(2,1)=SRC(3,3)=SRC(4,5)=SRC(5,7)= (t0 + 2*t1 + t2 + 2) >> 2;
+ SRC(2,0)=SRC(3,2)=SRC(4,4)=SRC(5,6)= (t1 + t2 + 1) >> 1;
+ SRC(3,1)=SRC(4,3)=SRC(5,5)=SRC(6,7)= (t1 + 2*t2 + t3 + 2) >> 2;
+ SRC(3,0)=SRC(4,2)=SRC(5,4)=SRC(6,6)= (t2 + t3 + 1) >> 1;
+ SRC(4,1)=SRC(5,3)=SRC(6,5)=SRC(7,7)= (t2 + 2*t3 + t4 + 2) >> 2;
+ SRC(4,0)=SRC(5,2)=SRC(6,4)=SRC(7,6)= (t3 + t4 + 1) >> 1;
+ SRC(5,1)=SRC(6,3)=SRC(7,5)= (t3 + 2*t4 + t5 + 2) >> 2;
+ SRC(5,0)=SRC(6,2)=SRC(7,4)= (t4 + t5 + 1) >> 1;
+ SRC(6,1)=SRC(7,3)= (t4 + 2*t5 + t6 + 2) >> 2;
+ SRC(6,0)=SRC(7,2)= (t5 + t6 + 1) >> 1;
+ SRC(7,1)= (t5 + 2*t6 + t7 + 2) >> 2;
+ SRC(7,0)= (t6 + t7 + 1) >> 1;
+}
+static void pred8x8l_horizontal_down_c(uint8_t *src, int has_topleft, int has_topright, int stride)
+{
+ PREDICT_8x8_LOAD_TOP;
+ PREDICT_8x8_LOAD_LEFT;
+ PREDICT_8x8_LOAD_TOPLEFT;
+ SRC(0,7)= (l6 + l7 + 1) >> 1;
+ SRC(1,7)= (l5 + 2*l6 + l7 + 2) >> 2;
+ SRC(0,6)=SRC(2,7)= (l5 + l6 + 1) >> 1;
+ SRC(1,6)=SRC(3,7)= (l4 + 2*l5 + l6 + 2) >> 2;
+ SRC(0,5)=SRC(2,6)=SRC(4,7)= (l4 + l5 + 1) >> 1;
+ SRC(1,5)=SRC(3,6)=SRC(5,7)= (l3 + 2*l4 + l5 + 2) >> 2;
+ SRC(0,4)=SRC(2,5)=SRC(4,6)=SRC(6,7)= (l3 + l4 + 1) >> 1;
+ SRC(1,4)=SRC(3,5)=SRC(5,6)=SRC(7,7)= (l2 + 2*l3 + l4 + 2) >> 2;
+ SRC(0,3)=SRC(2,4)=SRC(4,5)=SRC(6,6)= (l2 + l3 + 1) >> 1;
+ SRC(1,3)=SRC(3,4)=SRC(5,5)=SRC(7,6)= (l1 + 2*l2 + l3 + 2) >> 2;
+ SRC(0,2)=SRC(2,3)=SRC(4,4)=SRC(6,5)= (l1 + l2 + 1) >> 1;
+ SRC(1,2)=SRC(3,3)=SRC(5,4)=SRC(7,5)= (l0 + 2*l1 + l2 + 2) >> 2;
+ SRC(0,1)=SRC(2,2)=SRC(4,3)=SRC(6,4)= (l0 + l1 + 1) >> 1;
+ SRC(1,1)=SRC(3,2)=SRC(5,3)=SRC(7,4)= (lt + 2*l0 + l1 + 2) >> 2;
+ SRC(0,0)=SRC(2,1)=SRC(4,2)=SRC(6,3)= (lt + l0 + 1) >> 1;
+ SRC(1,0)=SRC(3,1)=SRC(5,2)=SRC(7,3)= (l0 + 2*lt + t0 + 2) >> 2;
+ SRC(2,0)=SRC(4,1)=SRC(6,2)= (t1 + 2*t0 + lt + 2) >> 2;
+ SRC(3,0)=SRC(5,1)=SRC(7,2)= (t2 + 2*t1 + t0 + 2) >> 2;
+ SRC(4,0)=SRC(6,1)= (t3 + 2*t2 + t1 + 2) >> 2;
+ SRC(5,0)=SRC(7,1)= (t4 + 2*t3 + t2 + 2) >> 2;
+ SRC(6,0)= (t5 + 2*t4 + t3 + 2) >> 2;
+ SRC(7,0)= (t6 + 2*t5 + t4 + 2) >> 2;
+}
+static void pred8x8l_vertical_left_c(uint8_t *src, int has_topleft, int has_topright, int stride)
+{
+ PREDICT_8x8_LOAD_TOP;
+ PREDICT_8x8_LOAD_TOPRIGHT;
+ SRC(0,0)= (t0 + t1 + 1) >> 1;
+ SRC(0,1)= (t0 + 2*t1 + t2 + 2) >> 2;
+ SRC(0,2)=SRC(1,0)= (t1 + t2 + 1) >> 1;
+ SRC(0,3)=SRC(1,1)= (t1 + 2*t2 + t3 + 2) >> 2;
+ SRC(0,4)=SRC(1,2)=SRC(2,0)= (t2 + t3 + 1) >> 1;
+ SRC(0,5)=SRC(1,3)=SRC(2,1)= (t2 + 2*t3 + t4 + 2) >> 2;
+ SRC(0,6)=SRC(1,4)=SRC(2,2)=SRC(3,0)= (t3 + t4 + 1) >> 1;
+ SRC(0,7)=SRC(1,5)=SRC(2,3)=SRC(3,1)= (t3 + 2*t4 + t5 + 2) >> 2;
+ SRC(1,6)=SRC(2,4)=SRC(3,2)=SRC(4,0)= (t4 + t5 + 1) >> 1;
+ SRC(1,7)=SRC(2,5)=SRC(3,3)=SRC(4,1)= (t4 + 2*t5 + t6 + 2) >> 2;
+ SRC(2,6)=SRC(3,4)=SRC(4,2)=SRC(5,0)= (t5 + t6 + 1) >> 1;
+ SRC(2,7)=SRC(3,5)=SRC(4,3)=SRC(5,1)= (t5 + 2*t6 + t7 + 2) >> 2;
+ SRC(3,6)=SRC(4,4)=SRC(5,2)=SRC(6,0)= (t6 + t7 + 1) >> 1;
+ SRC(3,7)=SRC(4,5)=SRC(5,3)=SRC(6,1)= (t6 + 2*t7 + t8 + 2) >> 2;
+ SRC(4,6)=SRC(5,4)=SRC(6,2)=SRC(7,0)= (t7 + t8 + 1) >> 1;
+ SRC(4,7)=SRC(5,5)=SRC(6,3)=SRC(7,1)= (t7 + 2*t8 + t9 + 2) >> 2;
+ SRC(5,6)=SRC(6,4)=SRC(7,2)= (t8 + t9 + 1) >> 1;
+ SRC(5,7)=SRC(6,5)=SRC(7,3)= (t8 + 2*t9 + t10 + 2) >> 2;
+ SRC(6,6)=SRC(7,4)= (t9 + t10 + 1) >> 1;
+ SRC(6,7)=SRC(7,5)= (t9 + 2*t10 + t11 + 2) >> 2;
+ SRC(7,6)= (t10 + t11 + 1) >> 1;
+ SRC(7,7)= (t10 + 2*t11 + t12 + 2) >> 2;
+}
+static void pred8x8l_horizontal_up_c(uint8_t *src, int has_topleft, int has_topright, int stride)
+{
+ PREDICT_8x8_LOAD_LEFT;
+ SRC(0,0)= (l0 + l1 + 1) >> 1;
+ SRC(1,0)= (l0 + 2*l1 + l2 + 2) >> 2;
+ SRC(0,1)=SRC(2,0)= (l1 + l2 + 1) >> 1;
+ SRC(1,1)=SRC(3,0)= (l1 + 2*l2 + l3 + 2) >> 2;
+ SRC(0,2)=SRC(2,1)=SRC(4,0)= (l2 + l3 + 1) >> 1;
+ SRC(1,2)=SRC(3,1)=SRC(5,0)= (l2 + 2*l3 + l4 + 2) >> 2;
+ SRC(0,3)=SRC(2,2)=SRC(4,1)=SRC(6,0)= (l3 + l4 + 1) >> 1;
+ SRC(1,3)=SRC(3,2)=SRC(5,1)=SRC(7,0)= (l3 + 2*l4 + l5 + 2) >> 2;
+ SRC(0,4)=SRC(2,3)=SRC(4,2)=SRC(6,1)= (l4 + l5 + 1) >> 1;
+ SRC(1,4)=SRC(3,3)=SRC(5,2)=SRC(7,1)= (l4 + 2*l5 + l6 + 2) >> 2;
+ SRC(0,5)=SRC(2,4)=SRC(4,3)=SRC(6,2)= (l5 + l6 + 1) >> 1;
+ SRC(1,5)=SRC(3,4)=SRC(5,3)=SRC(7,2)= (l5 + 2*l6 + l7 + 2) >> 2;
+ SRC(0,6)=SRC(2,5)=SRC(4,4)=SRC(6,3)= (l6 + l7 + 1) >> 1;
+ SRC(1,6)=SRC(3,5)=SRC(5,4)=SRC(7,3)= (l6 + 3*l7 + 2) >> 2;
+ SRC(0,7)=SRC(1,7)=SRC(2,6)=SRC(2,7)=SRC(3,6)=
+ SRC(3,7)=SRC(4,5)=SRC(4,6)=SRC(4,7)=SRC(5,5)=
+ SRC(5,6)=SRC(5,7)=SRC(6,4)=SRC(6,5)=SRC(6,6)=
+ SRC(6,7)=SRC(7,4)=SRC(7,5)=SRC(7,6)=SRC(7,7)= l7;
+}
+#undef PREDICT_8x8_LOAD_LEFT
+#undef PREDICT_8x8_LOAD_TOP
+#undef PREDICT_8x8_LOAD_TOPLEFT
+#undef PREDICT_8x8_LOAD_TOPRIGHT
+#undef PREDICT_8x8_DC
+#undef PTR
+#undef PT
+#undef PL
+#undef SRC
+
+static inline void mc_dir_part(H264Context *h, Picture *pic, int n, int square, int chroma_height, int delta, int list,
+ uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
+ int src_x_offset, int src_y_offset,
+ qpel_mc_func *qpix_op, h264_chroma_mc_func chroma_op){
+ MpegEncContext * const s = &h->s;
+ const int mx= h->mv_cache[list][ scan8[n] ][0] + src_x_offset*8;
+ int my= h->mv_cache[list][ scan8[n] ][1] + src_y_offset*8;
+ const int luma_xy= (mx&3) + ((my&3)<<2);
+ uint8_t * src_y = pic->data[0] + (mx>>2) + (my>>2)*h->mb_linesize;
+ uint8_t * src_cb, * src_cr;
+ int extra_width= h->emu_edge_width;
+ int extra_height= h->emu_edge_height;
+ int emu=0;
+ const int full_mx= mx>>2;
+ const int full_my= my>>2;
+ const int pic_width = 16*s->mb_width;
+ const int pic_height = 16*s->mb_height >> MB_MBAFF;
+
+ if(!pic->data[0]) //FIXME this is unacceptable, some senseable error concealment must be done for missing reference frames
+ return;
+
+ if(mx&7) extra_width -= 3;
+ if(my&7) extra_height -= 3;
+
+ if( full_mx < 0-extra_width
+ || full_my < 0-extra_height
+ || full_mx + 16/*FIXME*/ > pic_width + extra_width
+ || full_my + 16/*FIXME*/ > pic_height + extra_height){
+ ff_emulated_edge_mc(s->edge_emu_buffer, src_y - 2 - 2*h->mb_linesize, h->mb_linesize, 16+5, 16+5/*FIXME*/, full_mx-2, full_my-2, pic_width, pic_height);
+ src_y= s->edge_emu_buffer + 2 + 2*h->mb_linesize;
+ emu=1;
+ }
+
+ qpix_op[luma_xy](dest_y, src_y, h->mb_linesize); //FIXME try variable height perhaps?
+ if(!square){
+ qpix_op[luma_xy](dest_y + delta, src_y + delta, h->mb_linesize);
+ }
+
+ if(s->flags&CODEC_FLAG_GRAY) return;
+
+ if(MB_MBAFF){
+ // chroma offset when predicting from a field of opposite parity
+ my += 2 * ((s->mb_y & 1) - (h->ref_cache[list][scan8[n]] & 1));
+ emu |= (my>>3) < 0 || (my>>3) + 8 >= (pic_height>>1);
+ }
+ src_cb= pic->data[1] + (mx>>3) + (my>>3)*h->mb_uvlinesize;
+ src_cr= pic->data[2] + (mx>>3) + (my>>3)*h->mb_uvlinesize;
+
+ if(emu){
+ ff_emulated_edge_mc(s->edge_emu_buffer, src_cb, h->mb_uvlinesize, 9, 9/*FIXME*/, (mx>>3), (my>>3), pic_width>>1, pic_height>>1);
+ src_cb= s->edge_emu_buffer;
+ }
+ chroma_op(dest_cb, src_cb, h->mb_uvlinesize, chroma_height, mx&7, my&7);
+
+ if(emu){
+ ff_emulated_edge_mc(s->edge_emu_buffer, src_cr, h->mb_uvlinesize, 9, 9/*FIXME*/, (mx>>3), (my>>3), pic_width>>1, pic_height>>1);
+ src_cr= s->edge_emu_buffer;
+ }
+ chroma_op(dest_cr, src_cr, h->mb_uvlinesize, chroma_height, mx&7, my&7);
+}
+
+static inline void mc_part_std(H264Context *h, int n, int square, int chroma_height, int delta,
+ uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
+ int x_offset, int y_offset,
+ qpel_mc_func *qpix_put, h264_chroma_mc_func chroma_put,
+ qpel_mc_func *qpix_avg, h264_chroma_mc_func chroma_avg,
+ int list0, int list1){
+ MpegEncContext * const s = &h->s;
+ qpel_mc_func *qpix_op= qpix_put;
+ h264_chroma_mc_func chroma_op= chroma_put;
+
+ dest_y += 2*x_offset + 2*y_offset*h-> mb_linesize;
+ dest_cb += x_offset + y_offset*h->mb_uvlinesize;
+ dest_cr += x_offset + y_offset*h->mb_uvlinesize;
+ x_offset += 8*s->mb_x;
+ y_offset += 8*(s->mb_y >> MB_MBAFF);
+
+ if(list0){
+ Picture *ref= &h->ref_list[0][ h->ref_cache[0][ scan8[n] ] ];
+ mc_dir_part(h, ref, n, square, chroma_height, delta, 0,
+ dest_y, dest_cb, dest_cr, x_offset, y_offset,
+ qpix_op, chroma_op);
+
+ qpix_op= qpix_avg;
+ chroma_op= chroma_avg;
+ }
+
+ if(list1){
+ Picture *ref= &h->ref_list[1][ h->ref_cache[1][ scan8[n] ] ];
+ mc_dir_part(h, ref, n, square, chroma_height, delta, 1,
+ dest_y, dest_cb, dest_cr, x_offset, y_offset,
+ qpix_op, chroma_op);
+ }
+}
+
+static inline void mc_part_weighted(H264Context *h, int n, int square, int chroma_height, int delta,
+ uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
+ int x_offset, int y_offset,
+ qpel_mc_func *qpix_put, h264_chroma_mc_func chroma_put,
+ h264_weight_func luma_weight_op, h264_weight_func chroma_weight_op,
+ h264_biweight_func luma_weight_avg, h264_biweight_func chroma_weight_avg,
+ int list0, int list1){
+ MpegEncContext * const s = &h->s;
+
+ dest_y += 2*x_offset + 2*y_offset*h-> mb_linesize;
+ dest_cb += x_offset + y_offset*h->mb_uvlinesize;
+ dest_cr += x_offset + y_offset*h->mb_uvlinesize;
+ x_offset += 8*s->mb_x;
+ y_offset += 8*(s->mb_y >> MB_MBAFF);
+
+ if(list0 && list1){
+ /* don't optimize for luma-only case, since B-frames usually
+ * use implicit weights => chroma too. */
+ uint8_t *tmp_cb = s->obmc_scratchpad;
+ uint8_t *tmp_cr = s->obmc_scratchpad + 8;
+ uint8_t *tmp_y = s->obmc_scratchpad + 8*h->mb_uvlinesize;
+ int refn0 = h->ref_cache[0][ scan8[n] ];
+ int refn1 = h->ref_cache[1][ scan8[n] ];
+
+ mc_dir_part(h, &h->ref_list[0][refn0], n, square, chroma_height, delta, 0,
+ dest_y, dest_cb, dest_cr,
+ x_offset, y_offset, qpix_put, chroma_put);
+ mc_dir_part(h, &h->ref_list[1][refn1], n, square, chroma_height, delta, 1,
+ tmp_y, tmp_cb, tmp_cr,
+ x_offset, y_offset, qpix_put, chroma_put);
+
+ if(h->use_weight == 2){
+ int weight0 = h->implicit_weight[refn0][refn1];
+ 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]);
+ 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]);
+ 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]);
+ }
+ }else{
+ int list = list1 ? 1 : 0;
+ int refn = h->ref_cache[list][ scan8[n] ];
+ Picture *ref= &h->ref_list[list][refn];
+ mc_dir_part(h, ref, n, square, chroma_height, delta, list,
+ dest_y, dest_cb, dest_cr, x_offset, y_offset,
+ 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]);
+ 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]);
+ 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]);
+ }
+ }
+}
+
+static inline void mc_part(H264Context *h, int n, int square, int chroma_height, int delta,
+ uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
+ int x_offset, int y_offset,
+ qpel_mc_func *qpix_put, h264_chroma_mc_func chroma_put,
+ qpel_mc_func *qpix_avg, h264_chroma_mc_func chroma_avg,
+ h264_weight_func *weight_op, h264_biweight_func *weight_avg,
+ int list0, int list1){
+ if((h->use_weight==2 && list0 && list1
+ && (h->implicit_weight[ h->ref_cache[0][scan8[n]] ][ h->ref_cache[1][scan8[n]] ] != 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,
+ weight_op[0], weight_op[3], weight_avg[0], weight_avg[3], list0, list1);
+ else
+ mc_part_std(h, n, square, chroma_height, delta, dest_y, dest_cb, dest_cr,
+ x_offset, y_offset, qpix_put, chroma_put, qpix_avg, chroma_avg, list0, list1);
+}
+
+static inline void prefetch_motion(H264Context *h, int list){
+ /* fetch pixels for estimated mv 4 macroblocks ahead
+ * optimized for 64byte cache lines */
+ MpegEncContext * const s = &h->s;
+ const int refn = h->ref_cache[list][scan8[0]];
+ if(refn >= 0){
+ const int mx= (h->mv_cache[list][scan8[0]][0]>>2) + 16*s->mb_x + 8;
+ const int my= (h->mv_cache[list][scan8[0]][1]>>2) + 16*s->mb_y;
+ uint8_t **src= h->ref_list[list][refn].data;
+ int off= mx + (my + (s->mb_x&3)*4)*h->mb_linesize + 64;
+ s->dsp.prefetch(src[0]+off, s->linesize, 4);
+ off= (mx>>1) + ((my>>1) + (s->mb_x&7))*s->uvlinesize + 64;
+ s->dsp.prefetch(src[1]+off, src[2]-src[1], 2);
+ }
+}
+
+static void hl_motion(H264Context *h, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
+ qpel_mc_func (*qpix_put)[16], h264_chroma_mc_func (*chroma_put),
+ qpel_mc_func (*qpix_avg)[16], h264_chroma_mc_func (*chroma_avg),
+ h264_weight_func *weight_op, h264_biweight_func *weight_avg){
+ MpegEncContext * const s = &h->s;
+ const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
+ const int mb_type= s->current_picture.mb_type[mb_xy];
+
+ assert(IS_INTER(mb_type));
+
+ prefetch_motion(h, 0);
+
+ 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],
+ 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,
+ qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0],
+ &weight_op[1], &weight_avg[1],
+ IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1));
+ mc_part(h, 8, 0, 4, 8, dest_y, dest_cb, dest_cr, 0, 4,
+ qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0],
+ &weight_op[1], &weight_avg[1],
+ IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1));
+ }else if(IS_8X16(mb_type)){
+ mc_part(h, 0, 0, 8, 8*h->mb_linesize, dest_y, dest_cb, dest_cr, 0, 0,
+ qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],
+ &weight_op[2], &weight_avg[2],
+ IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1));
+ mc_part(h, 4, 0, 8, 8*h->mb_linesize, dest_y, dest_cb, dest_cr, 4, 0,
+ qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],
+ &weight_op[2], &weight_avg[2],
+ IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1));
+ }else{
+ int i;
+
+ assert(IS_8X8(mb_type));
+
+ for(i=0; i<4; i++){
+ const int sub_mb_type= h->sub_mb_type[i];
+ const int n= 4*i;
+ int x_offset= (i&1)<<2;
+ int y_offset= (i&2)<<1;
+
+ if(IS_SUB_8X8(sub_mb_type)){
+ mc_part(h, n, 1, 4, 0, dest_y, dest_cb, dest_cr, x_offset, y_offset,
+ qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],
+ &weight_op[3], &weight_avg[3],
+ IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
+ }else if(IS_SUB_8X4(sub_mb_type)){
+ mc_part(h, n , 0, 2, 4, dest_y, dest_cb, dest_cr, x_offset, y_offset,
+ qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1],
+ &weight_op[4], &weight_avg[4],
+ IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
+ mc_part(h, n+2, 0, 2, 4, dest_y, dest_cb, dest_cr, x_offset, y_offset+2,
+ qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1],
+ &weight_op[4], &weight_avg[4],
+ IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
+ }else if(IS_SUB_4X8(sub_mb_type)){
+ mc_part(h, n , 0, 4, 4*h->mb_linesize, dest_y, dest_cb, dest_cr, x_offset, y_offset,
+ qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],
+ &weight_op[5], &weight_avg[5],
+ IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
+ mc_part(h, n+1, 0, 4, 4*h->mb_linesize, dest_y, dest_cb, dest_cr, x_offset+2, y_offset,
+ qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],
+ &weight_op[5], &weight_avg[5],
+ IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
+ }else{
+ int j;
+ assert(IS_SUB_4X4(sub_mb_type));
+ for(j=0; j<4; j++){
+ int sub_x_offset= x_offset + 2*(j&1);
+ int sub_y_offset= y_offset + (j&2);
+ mc_part(h, n+j, 1, 2, 0, dest_y, dest_cb, dest_cr, sub_x_offset, sub_y_offset,
+ qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],
+ &weight_op[6], &weight_avg[6],
+ IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
+ }
+ }
+ }
+ }
+
+ prefetch_motion(h, 1);
+}
+
+static void decode_init_vlc(){
+ static int done = 0;
+
+ if (!done) {
+ int i;
+ done = 1;
+
+ 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, 1);
+
+ for(i=0; i<4; 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, 1);
+ }
+
+ for(i=0; i<3; i++){
+ 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, 1);
+ }
+ for(i=0; i<15; i++){
+ 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, 1);
+ }
+
+ for(i=0; i<6; i++){
+ init_vlc(&run_vlc[i], RUN_VLC_BITS, 7,
+ &run_len [i][0], 1, 1,
+ &run_bits[i][0], 1, 1, 1);
+ }
+ init_vlc(&run7_vlc, RUN7_VLC_BITS, 16,
+ &run_len [6][0], 1, 1,
+ &run_bits[6][0], 1, 1, 1);
+ }
+}
+
+/**
+ * Sets the intra prediction function pointers.
+ */
+static void init_pred_ptrs(H264Context *h){
+// MpegEncContext * const s = &h->s;
+
+ h->pred4x4[VERT_PRED ]= pred4x4_vertical_c;
+ h->pred4x4[HOR_PRED ]= pred4x4_horizontal_c;
+ h->pred4x4[DC_PRED ]= pred4x4_dc_c;
+ h->pred4x4[DIAG_DOWN_LEFT_PRED ]= pred4x4_down_left_c;
+ h->pred4x4[DIAG_DOWN_RIGHT_PRED]= pred4x4_down_right_c;
+ h->pred4x4[VERT_RIGHT_PRED ]= pred4x4_vertical_right_c;
+ h->pred4x4[HOR_DOWN_PRED ]= pred4x4_horizontal_down_c;
+ h->pred4x4[VERT_LEFT_PRED ]= pred4x4_vertical_left_c;
+ h->pred4x4[HOR_UP_PRED ]= pred4x4_horizontal_up_c;
+ h->pred4x4[LEFT_DC_PRED ]= pred4x4_left_dc_c;
+ h->pred4x4[TOP_DC_PRED ]= pred4x4_top_dc_c;
+ h->pred4x4[DC_128_PRED ]= pred4x4_128_dc_c;
+
+ h->pred8x8l[VERT_PRED ]= pred8x8l_vertical_c;
+ h->pred8x8l[HOR_PRED ]= pred8x8l_horizontal_c;
+ h->pred8x8l[DC_PRED ]= pred8x8l_dc_c;
+ h->pred8x8l[DIAG_DOWN_LEFT_PRED ]= pred8x8l_down_left_c;
+ h->pred8x8l[DIAG_DOWN_RIGHT_PRED]= pred8x8l_down_right_c;
+ h->pred8x8l[VERT_RIGHT_PRED ]= pred8x8l_vertical_right_c;
+ h->pred8x8l[HOR_DOWN_PRED ]= pred8x8l_horizontal_down_c;
+ h->pred8x8l[VERT_LEFT_PRED ]= pred8x8l_vertical_left_c;
+ h->pred8x8l[HOR_UP_PRED ]= pred8x8l_horizontal_up_c;
+ h->pred8x8l[LEFT_DC_PRED ]= pred8x8l_left_dc_c;
+ h->pred8x8l[TOP_DC_PRED ]= pred8x8l_top_dc_c;
+ h->pred8x8l[DC_128_PRED ]= pred8x8l_128_dc_c;
+
+ h->pred8x8[DC_PRED8x8 ]= ff_pred8x8_dc_c;
+ h->pred8x8[VERT_PRED8x8 ]= ff_pred8x8_vertical_c;
+ h->pred8x8[HOR_PRED8x8 ]= ff_pred8x8_horizontal_c;
+ h->pred8x8[PLANE_PRED8x8 ]= ff_pred8x8_plane_c;
+ h->pred8x8[LEFT_DC_PRED8x8]= pred8x8_left_dc_c;
+ h->pred8x8[TOP_DC_PRED8x8 ]= pred8x8_top_dc_c;
+ h->pred8x8[DC_128_PRED8x8 ]= ff_pred8x8_128_dc_c;
+
+ h->pred16x16[DC_PRED8x8 ]= ff_pred16x16_dc_c;
+ h->pred16x16[VERT_PRED8x8 ]= ff_pred16x16_vertical_c;
+ h->pred16x16[HOR_PRED8x8 ]= ff_pred16x16_horizontal_c;
+ h->pred16x16[PLANE_PRED8x8 ]= ff_pred16x16_plane_c;
+ h->pred16x16[LEFT_DC_PRED8x8]= pred16x16_left_dc_c;
+ h->pred16x16[TOP_DC_PRED8x8 ]= pred16x16_top_dc_c;
+ h->pred16x16[DC_128_PRED8x8 ]= ff_pred16x16_128_dc_c;
+}
+
+static void free_tables(H264Context *h){
+ av_freep(&h->intra4x4_pred_mode);
+ av_freep(&h->chroma_pred_mode_table);
+ av_freep(&h->cbp_table);
+ av_freep(&h->mvd_table[0]);
+ av_freep(&h->mvd_table[1]);
+ av_freep(&h->direct_table);
+ av_freep(&h->non_zero_count);
+ av_freep(&h->slice_table_base);
+ av_freep(&h->top_borders[1]);
+ av_freep(&h->top_borders[0]);
+ h->slice_table= NULL;
+
+ av_freep(&h->mb2b_xy);
+ av_freep(&h->mb2b8_xy);
+
+ av_freep(&h->s.obmc_scratchpad);
+}
+
+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
+ h->dequant8_coeff[0] = h->dequant8_buffer[0];
+ h->dequant8_coeff[1] = h->dequant8_buffer[1];
+
+ for(i=0; i<2; i++ ){
+ if(i && !memcmp(h->pps.scaling_matrix8[0], h->pps.scaling_matrix8[1], 64*sizeof(uint8_t))){
+ h->dequant8_coeff[1] = h->dequant8_buffer[0];
+ break;
+ }
+
+ for(q=0; q<52; q++){
+ int shift = ff_div6[q];
+ int idx = ff_rem6[q];
+ for(x=0; x<64; x++)
+ h->dequant8_coeff[i][q][transpose ? (x>>3)|((x&7)<<3) : x] =
+ ((uint32_t)dequant8_coeff_init[idx][ dequant8_coeff_init_scan[((x>>1)&12) | (x&3)] ] *
+ h->pps.scaling_matrix8[i][x]) << shift;
+ }
+ }
+}
+
+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
+ for(i=0; i<6; i++ ){
+ h->dequant4_coeff[i] = h->dequant4_buffer[i];
+ for(j=0; j<i; j++){
+ if(!memcmp(h->pps.scaling_matrix4[j], h->pps.scaling_matrix4[i], 16*sizeof(uint8_t))){
+ h->dequant4_coeff[i] = h->dequant4_buffer[j];
+ break;
+ }
+ }
+ if(j<i)
+ continue;
+
+ for(q=0; q<52; q++){
+ int shift = ff_div6[q] + 2;
+ int idx = ff_rem6[q];
+ for(x=0; x<16; x++)
+ h->dequant4_coeff[i][q][transpose ? (x>>2)|((x<<2)&0xF) : x] =
+ ((uint32_t)dequant4_coeff_init[idx][(x&1) + ((x>>2)&1)] *
+ h->pps.scaling_matrix4[i][x]) << shift;
+ }
+ }
+}
+
+static void init_dequant_tables(H264Context *h){
+ int i,x;
+ init_dequant4_coeff_table(h);
+ if(h->pps.transform_8x8_mode)
+ init_dequant8_coeff_table(h);
+ if(h->sps.transform_bypass){
+ for(i=0; i<6; i++)
+ for(x=0; x<16; x++)
+ h->dequant4_coeff[i][0][x] = 1<<6;
+ if(h->pps.transform_8x8_mode)
+ for(i=0; i<2; i++)
+ for(x=0; x<64; x++)
+ h->dequant8_coeff[i][0][x] = 1<<6;
+ }
+}
+
+
+/**
+ * allocates tables.
+ * needs width/height
+ */
+static int alloc_tables(H264Context *h){
+ MpegEncContext * const s = &h->s;
+ const int big_mb_num= s->mb_stride * (s->mb_height+1);
+ int x,y;
+
+ CHECKED_ALLOCZ(h->intra4x4_pred_mode, big_mb_num * 8 * sizeof(uint8_t))
+
+ 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(uint8_t))
+ CHECKED_ALLOCZ(h->top_borders[0] , s->mb_width * (16+8+8) * sizeof(uint8_t))
+ CHECKED_ALLOCZ(h->top_borders[1] , s->mb_width * (16+8+8) * sizeof(uint8_t))
+ CHECKED_ALLOCZ(h->cbp_table, big_mb_num * sizeof(uint16_t))
+
+ if( h->pps.cabac ) {
+ 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));
+ }
+
+ memset(h->slice_table_base, -1, (big_mb_num+s->mb_stride) * sizeof(uint8_t));
+ 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));
+ for(y=0; y<s->mb_height; y++){
+ for(x=0; x<s->mb_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;
+ }
+ }
+
+ s->obmc_scratchpad = NULL;
+
+ if(!h->dequant4_coeff[0])
+ init_dequant_tables(h);
+
+ return 0;
+fail:
+ free_tables(h);
+ return -1;
+}
+
+static void common_init(H264Context *h){
+ MpegEncContext * const s = &h->s;
+
+ s->width = s->avctx->width;
+ s->height = s->avctx->height;
+ s->codec_id= s->avctx->codec->id;
+
+ init_pred_ptrs(h);
+
+ h->dequant_coeff_pps= -1;
+ s->unrestricted_mv=1;
+ s->decode=1; //FIXME
+
+ memset(h->pps.scaling_matrix4, 16, 6*16*sizeof(uint8_t));
+ memset(h->pps.scaling_matrix8, 16, 2*64*sizeof(uint8_t));
+}
+
+static int decode_init(AVCodecContext *avctx){
+ H264Context *h= avctx->priv_data;
+ MpegEncContext * const s = &h->s;
+
+ MPV_decode_defaults(s);
+
+ s->avctx = avctx;
+ common_init(h);
+
+ s->out_format = FMT_H264;
+ s->workaround_bugs= avctx->workaround_bugs;
+
+ // set defaults
+// s->decode_mb= ff_h263_decode_mb;
+ s->low_delay= 1;
+ avctx->pix_fmt= PIX_FMT_YUV420P;
+
+ 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;
+ }
+
+ return 0;
+}
+
+static int frame_start(H264Context *h){
+ MpegEncContext * const s = &h->s;
+ int i;
+
+ if(MPV_frame_start(s, s->avctx) < 0)
+ return -1;
+ ff_er_frame_start(s);
+
+ assert(s->linesize && s->uvlinesize);
+
+ for(i=0; i<16; i++){
+ h->block_offset[i]= 4*((scan8[i] - scan8[0])&7) + 4*s->linesize*((scan8[i] - scan8[0])>>3);
+ h->block_offset[24+i]= 4*((scan8[i] - scan8[0])&7) + 8*s->linesize*((scan8[i] - scan8[0])>>3);
+ }
+ for(i=0; i<4; i++){
+ h->block_offset[16+i]=
+ h->block_offset[20+i]= 4*((scan8[i] - scan8[0])&7) + 4*s->uvlinesize*((scan8[i] - scan8[0])>>3);
+ h->block_offset[24+16+i]=
+ h->block_offset[24+20+i]= 4*((scan8[i] - scan8[0])&7) + 8*s->uvlinesize*((scan8[i] - scan8[0])>>3);
+ }
+
+ /* can't be in alloc_tables because linesize isn't known there.
+ * FIXME: redo bipred weight to not require extra buffer? */
+ if(!s->obmc_scratchpad)
+ 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)
+ memset(h->slice_table, -1, (s->mb_height*s->mb_stride-1) * sizeof(uint8_t));
+
+// s->decode= (s->flags&CODEC_FLAG_PSNR) || !s->encoding || s->current_picture.reference /*|| h->contains_intra*/ || 1;
+ return 0;
+}
+
+static inline void backup_mb_border(H264Context *h, uint8_t *src_y, uint8_t *src_cb, uint8_t *src_cr, int linesize, int uvlinesize){
+ MpegEncContext * const s = &h->s;
+ int i;
+
+ src_y -= linesize;
+ src_cb -= uvlinesize;
+ src_cr -= uvlinesize;
+
+ // 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[0]= h->top_borders[0][s->mb_x][15];
+ for(i=1; i<17; i++){
+ h->left_border[i]= src_y[15+i* linesize];
+ }
+
+ *(uint64_t*)(h->top_borders[0][s->mb_x]+0)= *(uint64_t*)(src_y + 16*linesize);
+ *(uint64_t*)(h->top_borders[0][s->mb_x]+8)= *(uint64_t*)(src_y +8+16*linesize);
+
+ if(!(s->flags&CODEC_FLAG_GRAY)){
+ h->left_border[17 ]= h->top_borders[0][s->mb_x][16+7];
+ h->left_border[17+9]= h->top_borders[0][s->mb_x][24+7];
+ for(i=1; i<9; i++){
+ h->left_border[i+17 ]= src_cb[7+i*uvlinesize];
+ h->left_border[i+17+9]= src_cr[7+i*uvlinesize];
+ }
+ *(uint64_t*)(h->top_borders[0][s->mb_x]+16)= *(uint64_t*)(src_cb+8*uvlinesize);
+ *(uint64_t*)(h->top_borders[0][s->mb_x]+24)= *(uint64_t*)(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){
+ MpegEncContext * const s = &h->s;
+ int temp8, i;
+ uint64_t temp64;
+ int deblock_left = (s->mb_x > 0);
+ int deblock_top = (s->mb_y > 0);
+
+ src_y -= linesize + 1;
+ src_cb -= uvlinesize + 1;
+ src_cr -= uvlinesize + 1;
+
+#define XCHG(a,b,t,xchg)\
+t= a;\
+if(xchg)\
+ a= b;\
+b= t;
+
+ if(deblock_left){
+ for(i = !deblock_top; i<17; i++){
+ XCHG(h->left_border[i ], src_y [i* linesize], temp8, xchg);
+ }
+ }
+
+ if(deblock_top){
+ XCHG(*(uint64_t*)(h->top_borders[0][s->mb_x]+0), *(uint64_t*)(src_y +1), temp64, xchg);
+ XCHG(*(uint64_t*)(h->top_borders[0][s->mb_x]+8), *(uint64_t*)(src_y +9), temp64, 1);
+ if(s->mb_x+1 < s->mb_width){
+ XCHG(*(uint64_t*)(h->top_borders[0][s->mb_x+1]), *(uint64_t*)(src_y +17), temp64, 1);
+ }
+ }
+
+ if(!(s->flags&CODEC_FLAG_GRAY)){
+ if(deblock_left){
+ for(i = !deblock_top; i<9; i++){
+ XCHG(h->left_border[i+17 ], src_cb[i*uvlinesize], temp8, xchg);
+ XCHG(h->left_border[i+17+9], src_cr[i*uvlinesize], temp8, xchg);
+ }
+ }
+ if(deblock_top){
+ XCHG(*(uint64_t*)(h->top_borders[0][s->mb_x]+16), *(uint64_t*)(src_cb+1), temp64, 1);
+ XCHG(*(uint64_t*)(h->top_borders[0][s->mb_x]+24), *(uint64_t*)(src_cr+1), temp64, 1);
+ }
+ }
+}
+
+static inline void backup_pair_border(H264Context *h, uint8_t *src_y, uint8_t *src_cb, uint8_t *src_cr, int linesize, int uvlinesize){
+ MpegEncContext * const s = &h->s;
+ int i;
+
+ src_y -= 2 * linesize;
+ src_cb -= 2 * uvlinesize;
+ src_cr -= 2 * uvlinesize;
+
+ // 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[0]= h->top_borders[0][s->mb_x][15];
+ h->left_border[1]= h->top_borders[1][s->mb_x][15];
+ for(i=2; i<34; i++){
+ h->left_border[i]= src_y[15+i* linesize];
+ }
+
+ *(uint64_t*)(h->top_borders[0][s->mb_x]+0)= *(uint64_t*)(src_y + 32*linesize);
+ *(uint64_t*)(h->top_borders[0][s->mb_x]+8)= *(uint64_t*)(src_y +8+32*linesize);
+ *(uint64_t*)(h->top_borders[1][s->mb_x]+0)= *(uint64_t*)(src_y + 33*linesize);
+ *(uint64_t*)(h->top_borders[1][s->mb_x]+8)= *(uint64_t*)(src_y +8+33*linesize);
+
+ if(!(s->flags&CODEC_FLAG_GRAY)){
+ h->left_border[34 ]= h->top_borders[0][s->mb_x][16+7];
+ h->left_border[34+ 1]= h->top_borders[1][s->mb_x][16+7];
+ h->left_border[34+18 ]= h->top_borders[0][s->mb_x][24+7];
+ h->left_border[34+18+1]= h->top_borders[1][s->mb_x][24+7];
+ for(i=2; i<18; i++){
+ h->left_border[i+34 ]= src_cb[7+i*uvlinesize];
+ h->left_border[i+34+18]= src_cr[7+i*uvlinesize];
+ }
+ *(uint64_t*)(h->top_borders[0][s->mb_x]+16)= *(uint64_t*)(src_cb+16*uvlinesize);
+ *(uint64_t*)(h->top_borders[0][s->mb_x]+24)= *(uint64_t*)(src_cr+16*uvlinesize);
+ *(uint64_t*)(h->top_borders[1][s->mb_x]+16)= *(uint64_t*)(src_cb+17*uvlinesize);
+ *(uint64_t*)(h->top_borders[1][s->mb_x]+24)= *(uint64_t*)(src_cr+17*uvlinesize);
+ }
+}
+
+static inline void xchg_pair_border(H264Context *h, uint8_t *src_y, uint8_t *src_cb, uint8_t *src_cr, int linesize, int uvlinesize, int xchg){
+ MpegEncContext * const s = &h->s;
+ int temp8, i;
+ uint64_t temp64;
+ int deblock_left = (s->mb_x > 0);
+ int deblock_top = (s->mb_y > 1);
+
+ tprintf(s->avctx, "xchg_pair_border: src_y:%p src_cb:%p src_cr:%p ls:%d uvls:%d\n", src_y, src_cb, src_cr, linesize, uvlinesize);
+
+ src_y -= 2 * linesize + 1;
+ src_cb -= 2 * uvlinesize + 1;
+ src_cr -= 2 * uvlinesize + 1;
+
+#define XCHG(a,b,t,xchg)\
+t= a;\
+if(xchg)\
+ a= b;\
+b= t;
+
+ if(deblock_left){
+ for(i = (!deblock_top)<<1; i<34; i++){
+ XCHG(h->left_border[i ], src_y [i* linesize], temp8, xchg);
+ }
+ }
+
+ if(deblock_top){
+ XCHG(*(uint64_t*)(h->top_borders[0][s->mb_x]+0), *(uint64_t*)(src_y +1), temp64, xchg);
+ XCHG(*(uint64_t*)(h->top_borders[0][s->mb_x]+8), *(uint64_t*)(src_y +9), temp64, 1);
+ XCHG(*(uint64_t*)(h->top_borders[1][s->mb_x]+0), *(uint64_t*)(src_y +1 +linesize), temp64, xchg);
+ XCHG(*(uint64_t*)(h->top_borders[1][s->mb_x]+8), *(uint64_t*)(src_y +9 +linesize), temp64, 1);
+ if(s->mb_x+1 < s->mb_width){
+ XCHG(*(uint64_t*)(h->top_borders[0][s->mb_x+1]), *(uint64_t*)(src_y +17), temp64, 1);
+ XCHG(*(uint64_t*)(h->top_borders[1][s->mb_x+1]), *(uint64_t*)(src_y +17 +linesize), temp64, 1);
+ }
+ }
+
+ if(!(s->flags&CODEC_FLAG_GRAY)){
+ if(deblock_left){
+ for(i = (!deblock_top) << 1; i<18; i++){
+ XCHG(h->left_border[i+34 ], src_cb[i*uvlinesize], temp8, xchg);
+ XCHG(h->left_border[i+34+18], src_cr[i*uvlinesize], temp8, xchg);
+ }
+ }
+ if(deblock_top){
+ XCHG(*(uint64_t*)(h->top_borders[0][s->mb_x]+16), *(uint64_t*)(src_cb+1), temp64, 1);
+ XCHG(*(uint64_t*)(h->top_borders[0][s->mb_x]+24), *(uint64_t*)(src_cr+1), temp64, 1);
+ XCHG(*(uint64_t*)(h->top_borders[1][s->mb_x]+16), *(uint64_t*)(src_cb+1 +uvlinesize), temp64, 1);
+ XCHG(*(uint64_t*)(h->top_borders[1][s->mb_x]+24), *(uint64_t*)(src_cr+1 +uvlinesize), temp64, 1);
+ }
+ }
+}
+
+static void av_always_inline hl_decode_mb_internal(H264Context *h, int simple){
+ MpegEncContext * const s = &h->s;
+ const int mb_x= s->mb_x;
+ const int mb_y= s->mb_y;
+ const int mb_xy= mb_x + mb_y*s->mb_stride;
+ const int mb_type= s->current_picture.mb_type[mb_xy];
+ uint8_t *dest_y, *dest_cb, *dest_cr;
+ int linesize, uvlinesize /*dct_offset*/;
+ int i;
+ int *block_offset = &h->block_offset[0];
+ const unsigned int bottom = mb_y & 1;
+ const int transform_bypass = (s->qscale == 0 && h->sps.transform_bypass), is_h264 = (simple || s->codec_id == CODEC_ID_H264);
+ void (*idct_add)(uint8_t *dst, DCTELEM *block, int stride);
+ void (*idct_dc_add)(uint8_t *dst, DCTELEM *block, int stride);
+
+ dest_y = s->current_picture.data[0] + (mb_y * 16* s->linesize ) + mb_x * 16;
+ dest_cb = s->current_picture.data[1] + (mb_y * 8 * s->uvlinesize) + mb_x * 8;
+ dest_cr = s->current_picture.data[2] + (mb_y * 8 * s->uvlinesize) + mb_x * 8;
+
+ 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);
+
+ if (!simple && MB_FIELD) {
+ linesize = h->mb_linesize = s->linesize * 2;
+ uvlinesize = h->mb_uvlinesize = s->uvlinesize * 2;
+ block_offset = &h->block_offset[24];
+ if(mb_y&1){ //FIXME move out of this func?
+ dest_y -= s->linesize*15;
+ dest_cb-= s->uvlinesize*7;
+ dest_cr-= s->uvlinesize*7;
+ }
+ if(FRAME_MBAFF) {
+ int list;
+ for(list=0; list<h->list_count; list++){
+ if(!USES_LIST(mb_type, list))
+ continue;
+ if(IS_16X16(mb_type)){
+ int8_t *ref = &h->ref_cache[list][scan8[0]];
+ fill_rectangle(ref, 4, 4, 8, 16+*ref^(s->mb_y&1), 1);
+ }else{
+ for(i=0; i<16; i+=4){
+ //FIXME can refs be smaller than 8x8 when !direct_8x8_inference ?
+ int ref = h->ref_cache[list][scan8[i]];
+ if(ref >= 0)
+ fill_rectangle(&h->ref_cache[list][scan8[i]], 2, 2, 8, 16+ref^(s->mb_y&1), 1);
+ }
+ }
+ }
+ }
+ } else {
+ linesize = h->mb_linesize = s->linesize;
+ uvlinesize = h->mb_uvlinesize = s->uvlinesize;
+// dct_offset = s->linesize * 16;
+ }
+
+ if(transform_bypass){
+ idct_dc_add =
+ idct_add = IS_8x8DCT(mb_type) ? s->dsp.add_pixels8 : s->dsp.add_pixels4;
+ }else if(IS_8x8DCT(mb_type)){
+ idct_dc_add = s->dsp.h264_idct8_dc_add;
+ idct_add = s->dsp.h264_idct8_add;
+ }else{
+ idct_dc_add = s->dsp.h264_idct_dc_add;
+ idct_add = s->dsp.h264_idct_add;
+ }
+
+ if(!simple && FRAME_MBAFF && h->deblocking_filter && IS_INTRA(mb_type)
+ && (!bottom || !IS_INTRA(s->current_picture.mb_type[mb_xy-s->mb_stride]))){
+ int mbt_y = mb_y&~1;
+ uint8_t *top_y = s->current_picture.data[0] + (mbt_y * 16* s->linesize ) + mb_x * 16;
+ uint8_t *top_cb = s->current_picture.data[1] + (mbt_y * 8 * s->uvlinesize) + mb_x * 8;
+ uint8_t *top_cr = s->current_picture.data[2] + (mbt_y * 8 * s->uvlinesize) + mb_x * 8;
+ xchg_pair_border(h, top_y, top_cb, top_cr, s->linesize, s->uvlinesize, 1);
+ }
+
+ if (!simple && IS_INTRA_PCM(mb_type)) {
+ unsigned int x, y;
+
+ // The pixels are stored in h->mb array in the same order as levels,
+ // copy them in output in the correct order.
+ for(i=0; i<16; i++) {
+ for (y=0; y<4; y++) {
+ for (x=0; x<4; x++) {
+ *(dest_y + block_offset[i] + y*linesize + x) = h->mb[i*16+y*4+x];
+ }
+ }
+ }
+ for(i=16; i<16+4; i++) {
+ for (y=0; y<4; y++) {
+ for (x=0; x<4; x++) {
+ *(dest_cb + block_offset[i] + y*uvlinesize + x) = h->mb[i*16+y*4+x];
+ }
+ }
+ }
+ for(i=20; i<20+4; i++) {
+ for (y=0; y<4; y++) {
+ for (x=0; x<4; x++) {
+ *(dest_cr + block_offset[i] + y*uvlinesize + x) = h->mb[i*16+y*4+x];
+ }
+ }
+ }
+ } else {
+ if(IS_INTRA(mb_type)){
+ if(h->deblocking_filter && (simple || !FRAME_MBAFF))
+ xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 1);
+
+ if(simple || !(s->flags&CODEC_FLAG_GRAY)){
+ h->pred8x8[ h->chroma_pred_mode ](dest_cb, uvlinesize);
+ h->pred8x8[ h->chroma_pred_mode ](dest_cr, uvlinesize);
+ }
+
+ if(IS_INTRA4x4(mb_type)){
+ if(simple || !s->encoding){
+ if(IS_8x8DCT(mb_type)){
+ for(i=0; i<16; i+=4){
+ uint8_t * const ptr= dest_y + block_offset[i];
+ const int dir= h->intra4x4_pred_mode_cache[ scan8[i] ];
+ const int nnz = h->non_zero_count_cache[ scan8[i] ];
+ h->pred8x8l[ dir ](ptr, (h->topleft_samples_available<<i)&0x8000,
+ (h->topright_samples_available<<i)&0x4000, linesize);
+ if(nnz){
+ if(nnz == 1 && h->mb[i*16])
+ idct_dc_add(ptr, h->mb + i*16, linesize);
+ else
+ idct_add(ptr, h->mb + i*16, linesize);
+ }
+ }
+ }else
+ for(i=0; i<16; i++){
+ uint8_t * const ptr= dest_y + block_offset[i];
+ uint8_t *topright;
+ const int dir= h->intra4x4_pred_mode_cache[ scan8[i] ];
+ int nnz, tr;
+
+ if(dir == DIAG_DOWN_LEFT_PRED || dir == VERT_LEFT_PRED){
+ const int topright_avail= (h->topright_samples_available<<i)&0x8000;
+ assert(mb_y || linesize <= block_offset[i]);
+ if(!topright_avail){
+ tr= ptr[3 - linesize]*0x01010101;
+ topright= (uint8_t*) &tr;
+ }else
+ topright= ptr + 4 - linesize;
+ }else
+ topright= NULL;
+
+ h->pred4x4[ dir ](ptr, topright, linesize);
+ nnz = h->non_zero_count_cache[ scan8[i] ];
+ if(nnz){
+ if(is_h264){
+ if(nnz == 1 && h->mb[i*16])
+ idct_dc_add(ptr, h->mb + i*16, linesize);
+ else
+ idct_add(ptr, h->mb + i*16, linesize);
+ }else
+ svq3_add_idct_c(ptr, h->mb + i*16, linesize, s->qscale, 0);
+ }
+ }
+ }
+ }else{
+ h->pred16x16[ h->intra16x16_pred_mode ](dest_y , linesize);
+ if(is_h264){
+ if(!transform_bypass)
+ h264_luma_dc_dequant_idct_c(h->mb, s->qscale, h->dequant4_coeff[IS_INTRA(mb_type) ? 0:3][s->qscale][0]);
+ }else
+ svq3_luma_dc_dequant_idct_c(h->mb, s->qscale);
+ }
+ if(h->deblocking_filter && (simple || !FRAME_MBAFF))
+ xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 0);
+ }else if(is_h264){
+ 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);
+ }
+
+
+ if(!IS_INTRA4x4(mb_type)){
+ if(is_h264){
+ if(IS_INTRA16x16(mb_type)){
+ for(i=0; i<16; i++){
+ if(h->non_zero_count_cache[ scan8[i] ])
+ idct_add(dest_y + block_offset[i], h->mb + i*16, linesize);
+ else if(h->mb[i*16])
+ idct_dc_add(dest_y + block_offset[i], h->mb + i*16, linesize);
+ }
+ }else{
+ const int di = IS_8x8DCT(mb_type) ? 4 : 1;
+ for(i=0; i<16; i+=di){
+ int nnz = h->non_zero_count_cache[ scan8[i] ];
+ if(nnz){
+ if(nnz==1 && h->mb[i*16])
+ idct_dc_add(dest_y + block_offset[i], h->mb + i*16, linesize);
+ else
+ idct_add(dest_y + block_offset[i], h->mb + i*16, linesize);
+ }
+ }
+ }
+ }else{
+ 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);
+ }
+ }
+ }
+ }
+
+ if(simple || !(s->flags&CODEC_FLAG_GRAY)){
+ uint8_t *dest[2] = {dest_cb, dest_cr};
+ if(transform_bypass){
+ idct_add = idct_dc_add = s->dsp.add_pixels4;
+ }else{
+ idct_add = s->dsp.h264_idct_add;
+ idct_dc_add = s->dsp.h264_idct_dc_add;
+ chroma_dc_dequant_idct_c(h->mb + 16*16, h->chroma_qp, h->dequant4_coeff[IS_INTRA(mb_type) ? 1:4][h->chroma_qp][0]);
+ chroma_dc_dequant_idct_c(h->mb + 16*16+4*16, h->chroma_qp, h->dequant4_coeff[IS_INTRA(mb_type) ? 2:5][h->chroma_qp][0]);
+ }
+ if(is_h264){
+ 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);
+ else if(h->mb[i*16])
+ idct_dc_add(dest[(i&4)>>2] + block_offset[i], h->mb + i*16, uvlinesize);
+ }
+ }else{
+ 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);
+ }
+ }
+ }
+ }
+ }
+ if(h->deblocking_filter) {
+ if (!simple && FRAME_MBAFF) {
+ //FIXME try deblocking one mb at a time?
+ // the reduction in load/storing mvs and such might outweigh the extra backup/xchg_border
+ const int mb_y = s->mb_y - 1;
+ uint8_t *pair_dest_y, *pair_dest_cb, *pair_dest_cr;
+ const int mb_xy= mb_x + mb_y*s->mb_stride;
+ const int mb_type_top = s->current_picture.mb_type[mb_xy];
+ const int mb_type_bottom= s->current_picture.mb_type[mb_xy+s->mb_stride];
+ if (!bottom) return;
+ pair_dest_y = s->current_picture.data[0] + (mb_y * 16* s->linesize ) + mb_x * 16;
+ pair_dest_cb = s->current_picture.data[1] + (mb_y * 8 * s->uvlinesize) + mb_x * 8;
+ pair_dest_cr = s->current_picture.data[2] + (mb_y * 8 * s->uvlinesize) + mb_x * 8;
+
+ if(IS_INTRA(mb_type_top | mb_type_bottom))
+ xchg_pair_border(h, pair_dest_y, pair_dest_cb, pair_dest_cr, s->linesize, s->uvlinesize, 0);
+
+ backup_pair_border(h, pair_dest_y, pair_dest_cb, pair_dest_cr, s->linesize, s->uvlinesize);
+ // deblock a pair
+ // top
+ s->mb_y--;
+ tprintf(h->s.avctx, "call mbaff filter_mb mb_x:%d mb_y:%d pair_dest_y = %p, dest_y = %p\n", mb_x, mb_y, pair_dest_y, dest_y);
+ fill_caches(h, mb_type_top, 1); //FIXME don't fill stuff which isn't used by filter_mb
+ h->chroma_qp = get_chroma_qp(h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mb_xy]);
+ filter_mb(h, mb_x, mb_y, pair_dest_y, pair_dest_cb, pair_dest_cr, linesize, uvlinesize);
+ // bottom
+ s->mb_y++;
+ tprintf(h->s.avctx, "call mbaff filter_mb\n");
+ fill_caches(h, mb_type_bottom, 1); //FIXME don't fill stuff which isn't used by filter_mb
+ h->chroma_qp = get_chroma_qp(h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mb_xy+s->mb_stride]);
+ filter_mb(h, mb_x, mb_y+1, dest_y, dest_cb, dest_cr, linesize, uvlinesize);
+ } else {
+ tprintf(h->s.avctx, "call filter_mb\n");
+ backup_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize);
+ fill_caches(h, mb_type, 1); //FIXME don't fill stuff which isn't used by filter_mb
+ filter_mb_fast(h, mb_x, mb_y, dest_y, dest_cb, dest_cr, linesize, uvlinesize);
+ }
+ }
+}
+
+/**
+ * Process a macroblock; this case avoids checks for expensive uncommon cases.
+ */
+static void hl_decode_mb_simple(H264Context *h){
+ hl_decode_mb_internal(h, 1);
+}
+
+/**
+ * Process a macroblock; this handles edge cases, such as interlacing.
+ */
+static void av_noinline hl_decode_mb_complex(H264Context *h){
+ hl_decode_mb_internal(h, 0);
+}
+
+static void hl_decode_mb(H264Context *h){
+ MpegEncContext * const s = &h->s;
+ const int mb_x= s->mb_x;
+ const int mb_y= s->mb_y;
+ const int mb_xy= mb_x + mb_y*s->mb_stride;
+ const int mb_type= s->current_picture.mb_type[mb_xy];
+ int is_complex = FRAME_MBAFF || MB_FIELD || IS_INTRA_PCM(mb_type) || s->codec_id != CODEC_ID_H264 || (s->flags&CODEC_FLAG_GRAY) || s->encoding;
+
+ if(!s->decode)
+ return;
+
+ if (is_complex)
+ hl_decode_mb_complex(h);
+ else hl_decode_mb_simple(h);
+}
+
+/**
+ * fills the default_ref_list.
+ */
+static int fill_default_ref_list(H264Context *h){
+ MpegEncContext * const s = &h->s;
+ int i;
+ int smallest_poc_greater_than_current = -1;
+ Picture sorted_short_ref[32];
+
+ if(h->slice_type==B_TYPE){
+ int out_i;
+ int limit= INT_MIN;
+
+ /* sort frame according to poc in B slice */
+ for(out_i=0; out_i<h->short_ref_count; out_i++){
+ int best_i=INT_MIN;
+ int best_poc=INT_MAX;
+
+ for(i=0; i<h->short_ref_count; i++){
+ const int poc= h->short_ref[i]->poc;
+ if(poc > limit && poc < best_poc){
+ best_poc= poc;
+ best_i= i;
+ }
+ }
+
+ assert(best_i != INT_MIN);
+
+ limit= best_poc;
+ sorted_short_ref[out_i]= *h->short_ref[best_i];
+ tprintf(h->s.avctx, "sorted poc: %d->%d poc:%d fn:%d\n", best_i, out_i, sorted_short_ref[out_i].poc, sorted_short_ref[out_i].frame_num);
+ if (-1 == smallest_poc_greater_than_current) {
+ if (h->short_ref[best_i]->poc >= s->current_picture_ptr->poc) {
+ smallest_poc_greater_than_current = out_i;
+ }
+ }
+ }
+ }
+
+ if(s->picture_structure == PICT_FRAME){
+ if(h->slice_type==B_TYPE){
+ int list;
+ tprintf(h->s.avctx, "current poc: %d, smallest_poc_greater_than_current: %d\n", s->current_picture_ptr->poc, smallest_poc_greater_than_current);
+
+ // find the largest poc
+ for(list=0; list<2; list++){
+ int index = 0;
+ int j= -99;
+ int step= list ? -1 : 1;
+
+ for(i=0; i<h->short_ref_count && index < h->ref_count[list]; i++, j+=step) {
+ while(j<0 || j>= h->short_ref_count){
+ if(j != -99 && step == (list ? -1 : 1))
+ return -1;
+ step = -step;
+ j= smallest_poc_greater_than_current + (step>>1);
+ }
+ if(sorted_short_ref[j].reference != 3) continue;
+ h->default_ref_list[list][index ]= sorted_short_ref[j];
+ h->default_ref_list[list][index++].pic_id= sorted_short_ref[j].frame_num;
+ }
+
+ for(i = 0; i < 16 && index < h->ref_count[ list ]; i++){
+ if(h->long_ref[i] == NULL) continue;
+ if(h->long_ref[i]->reference != 3) continue;
+
+ h->default_ref_list[ list ][index ]= *h->long_ref[i];
+ h->default_ref_list[ list ][index++].pic_id= i;;
+ }
+
+ if(list && (smallest_poc_greater_than_current<=0 || smallest_poc_greater_than_current>=h->short_ref_count) && (1 < index)){
+ // swap the two first elements of L1 when
+ // L0 and L1 are identical
+ Picture temp= h->default_ref_list[1][0];
+ h->default_ref_list[1][0] = h->default_ref_list[1][1];
+ h->default_ref_list[1][1] = temp;
+ }
+
+ if(index < h->ref_count[ list ])
+ memset(&h->default_ref_list[list][index], 0, sizeof(Picture)*(h->ref_count[ list ] - index));
+ }
+ }else{
+ int index=0;
+ for(i=0; i<h->short_ref_count; i++){
+ if(h->short_ref[i]->reference != 3) continue; //FIXME refernce field shit
+ h->default_ref_list[0][index ]= *h->short_ref[i];
+ h->default_ref_list[0][index++].pic_id= h->short_ref[i]->frame_num;
+ }
+ for(i = 0; i < 16; i++){
+ if(h->long_ref[i] == NULL) continue;
+ if(h->long_ref[i]->reference != 3) continue;
+ h->default_ref_list[0][index ]= *h->long_ref[i];
+ h->default_ref_list[0][index++].pic_id= i;;
+ }
+ if(index < h->ref_count[0])
+ memset(&h->default_ref_list[0][index], 0, sizeof(Picture)*(h->ref_count[0] - index));
+ }
+ }else{ //FIELD
+ if(h->slice_type==B_TYPE){
+ }else{
+ //FIXME second field balh
+ }
+ }
+#ifdef TRACE
+ for (i=0; i<h->ref_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==B_TYPE){
+ for (i=0; i<h->ref_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[0][i].data[0]);
+ }
+ }
+#endif
+ return 0;
+}
+
+static void print_short_term(H264Context *h);
+static void print_long_term(H264Context *h);
+
+static int decode_ref_pic_list_reordering(H264Context *h){
+ MpegEncContext * const s = &h->s;
+ int list, index;
+
+ print_short_term(h);
+ print_long_term(h);
+ if(h->slice_type==I_TYPE || h->slice_type==SI_TYPE) return 0; //FIXME move before func
+
+ for(list=0; list<h->list_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(&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;
+
+ 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;
+
+ for(i= h->short_ref_count-1; i>=0; i--){
+ ref = h->short_ref[i];
+ assert(ref->reference == 3);
+ assert(!ref->long_ref);
+ if(ref->data[0] != NULL && ref->frame_num == pred && ref->long_ref == 0) // ignore non existing pictures by testing data[0] pointer
+ break;
+ }
+ if(i>=0)
+ ref->pic_id= ref->frame_num;
+ }else{
+ pic_id= get_ue_golomb(&s->gb); //long_term_pic_idx
+ if(pic_id>31){
+ av_log(h->s.avctx, AV_LOG_ERROR, "long_term_pic_idx overflow\n");
+ return -1;
+ }
+ ref = h->long_ref[pic_id];
+ if(ref){
+ ref->pic_id= pic_id;
+ assert(ref->reference == 3);
+ 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+1<h->ref_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;
+ }
+ }else{
+ av_log(h->s.avctx, AV_LOG_ERROR, "illegal reordering_of_pic_nums_idc\n");
+ return -1;
+ }
+ }
+ }
+ }
+ for(list=0; list<h->list_count; list++){
+ for(index= 0; index < h->ref_count[list]; index++){
+ if(!h->ref_list[list][index].data[0])
+ h->ref_list[list][index]= s->current_picture;
+ }
+ }
+
+ if(h->slice_type==B_TYPE && !h->direct_spatial_mv_pred)
+ direct_dist_scale_factor(h);
+ direct_ref_list_init(h);
+ 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; i<h->ref_count[list]; i++){
+ Picture *frame = &h->ref_list[list][i];
+ Picture *field = &h->ref_list[list][16+2*i];
+ field[0] = *frame;
+ for(j=0; j<3; j++)
+ field[0].linesize[j] <<= 1;
+ field[1] = field[0];
+ for(j=0; j<3; j++)
+ field[1].data[j] += frame->linesize[j];
+
+ 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; j<h->ref_count[1]; j++){
+ for(i=0; i<h->ref_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;
+ int luma_def, chroma_def;
+
+ h->use_weight= 0;
+ h->use_weight_chroma= 0;
+ h->luma_log2_weight_denom= get_ue_golomb(&s->gb);
+ h->chroma_log2_weight_denom= get_ue_golomb(&s->gb);
+ luma_def = 1<<h->luma_log2_weight_denom;
+ chroma_def = 1<<h->chroma_log2_weight_denom;
+
+ for(list=0; list<2; list++){
+ for(i=0; i<h->ref_count[list]; i++){
+ int luma_weight_flag, chroma_weight_flag;
+
+ 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->use_weight= 1;
+ }else{
+ h->luma_weight[list][i]= luma_def;
+ h->luma_offset[list][i]= 0;
+ }
+
+ chroma_weight_flag= get_bits1(&s->gb);
+ 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->use_weight_chroma= 1;
+ }
+ }else{
+ int j;
+ for(j=0; j<2; j++){
+ h->chroma_weight[list][i][j]= chroma_def;
+ h->chroma_offset[list][i][j]= 0;
+ }
+ }
+ }
+ if(h->slice_type != B_TYPE) break;
+ }
+ h->use_weight= h->use_weight || h->use_weight_chroma;
+ return 0;
+}
+
+static void implicit_weight_table(H264Context *h){
+ MpegEncContext * const s = &h->s;
+ int ref0, ref1;
+ int cur_poc = s->current_picture_ptr->poc;
+
+ if( h->ref_count[0] == 1 && h->ref_count[1] == 1
+ && 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;
+ }
+
+ 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++){
+ int poc0 = h->ref_list[0][ref0].poc;
+ for(ref1=0; ref1 < h->ref_count[1]; ref1++){
+ int poc1 = h->ref_list[1][ref1].poc;
+ int td = av_clip(poc1 - poc0, -128, 127);
+ if(td){
+ int tb = av_clip(cur_poc - poc0, -128, 127);
+ int tx = (16384 + (FFABS(td) >> 1)) / td;
+ int dist_scale_factor = 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;
+ }
+ }
+}
+
+static inline void unreference_pic(H264Context *h, Picture *pic){
+ int i;
+ pic->reference=0;
+ if(pic == h->delayed_output_pic)
+ pic->reference=1;
+ else{
+ for(i = 0; h->delayed_pic[i]; i++)
+ if(pic == h->delayed_pic[i]){
+ pic->reference=1;
+ break;
+ }
+ }
+}
+
+/**
+ * instantaneous decoder refresh.
+ */
+static void idr(H264Context *h){
+ int i;
+
+ for(i=0; i<16; i++){
+ if (h->long_ref[i] != NULL) {
+ unreference_pic(h, h->long_ref[i]);
+ h->long_ref[i]= NULL;
+ }
+ }
+ h->long_ref_count=0;
+
+ for(i=0; i<h->short_ref_count; i++){
+ unreference_pic(h, h->short_ref[i]);
+ h->short_ref[i]= NULL;
+ }
+ h->short_ref_count=0;
+}
+
+/* forget old pics after a seek */
+static void flush_dpb(AVCodecContext *avctx){
+ H264Context *h= avctx->priv_data;
+ int i;
+ for(i=0; i<16; i++) {
+ if(h->delayed_pic[i])
+ h->delayed_pic[i]->reference= 0;
+ h->delayed_pic[i]= NULL;
+ }
+ if(h->delayed_output_pic)
+ h->delayed_output_pic->reference= 0;
+ h->delayed_output_pic= NULL;
+ idr(h);
+ if(h->s.current_picture_ptr)
+ h->s.current_picture_ptr->reference= 0;
+}
+
+/**
+ *
+ * @return the removed picture or NULL if an error occurs
+ */
+static Picture * remove_short(H264Context *h, int frame_num){
+ MpegEncContext * const s = &h->s;
+ 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);
+
+ for(i=0; i<h->short_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){
+ h->short_ref[i]= NULL;
+ memmove(&h->short_ref[i], &h->short_ref[i+1], (h->short_ref_count - i - 1)*sizeof(Picture*));
+ h->short_ref_count--;
+ return pic;
+ }
+ }
+ return NULL;
+}
+
+/**
+ *
+ * @return the removed picture or NULL if an error occurs
+ */
+static Picture * remove_long(H264Context *h, int i){
+ Picture *pic;
+
+ pic= h->long_ref[i];
+ h->long_ref[i]= NULL;
+ if(pic) 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; i<h->short_ref_count; i++){
+ Picture *pic= h->short_ref[i];
+ av_log(h->s.avctx, AV_LOG_DEBUG, "%d fn:%d poc:%d %p\n", i, pic->frame_num, pic->poc, pic->data[0]);
+ }
+ }
+}
+
+/**
+ * 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, j;
+ int current_is_long=0;
+ Picture *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; i<mmco_count; i++){
+ if(s->avctx->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_frame_num, h->mmco[i].long_index);
+
+ switch(mmco[i].opcode){
+ case MMCO_SHORT2UNUSED:
+ pic= remove_short(h, mmco[i].short_frame_num);
+ if(pic)
+ unreference_pic(h, pic);
+ else if(s->avctx->debug&FF_DEBUG_MMCO)
+ av_log(h->s.avctx, AV_LOG_DEBUG, "mmco: remove_short() failure\n");
+ break;
+ case MMCO_SHORT2LONG:
+ pic= remove_long(h, mmco[i].long_index);
+ if(pic) unreference_pic(h, pic);
+
+ h->long_ref[ mmco[i].long_index ]= remove_short(h, mmco[i].short_frame_num);
+ if (h->long_ref[ mmco[i].long_index ]){
+ h->long_ref[ mmco[i].long_index ]->long_ref=1;
+ h->long_ref_count++;
+ }
+ break;
+ case MMCO_LONG2UNUSED:
+ pic= remove_long(h, mmco[i].long_index);
+ if(pic)
+ unreference_pic(h, pic);
+ else if(s->avctx->debug&FF_DEBUG_MMCO)
+ av_log(h->s.avctx, AV_LOG_DEBUG, "mmco: remove_long() failure\n");
+ break;
+ case MMCO_LONG:
+ pic= remove_long(h, mmco[i].long_index);
+ if(pic) unreference_pic(h, pic);
+
+ h->long_ref[ mmco[i].long_index ]= s->current_picture_ptr;
+ h->long_ref[ mmco[i].long_index ]->long_ref=1;
+ h->long_ref_count++;
+
+ current_is_long=1;
+ break;
+ case MMCO_SET_MAX_LONG:
+ assert(mmco[i].long_index <= 16);
+ // just remove the long term which index is greater than new max
+ for(j = mmco[i].long_index; j<16; j++){
+ pic = remove_long(h, j);
+ if (pic) unreference_pic(h, pic);
+ }
+ break;
+ case MMCO_RESET:
+ while(h->short_ref_count){
+ pic= remove_short(h, h->short_ref[0]->frame_num);
+ if(pic) unreference_pic(h, pic);
+ }
+ for(j = 0; j < 16; j++) {
+ pic= remove_long(h, j);
+ if(pic) unreference_pic(h, pic);
+ }
+ break;
+ default: assert(0);
+ }
+ }
+
+ if(!current_is_long){
+ pic= remove_short(h, s->current_picture_ptr->frame_num);
+ if(pic){
+ unreference_pic(h, 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[0]->long_ref=0;
+ h->short_ref_count++;
+ }
+
+ print_short_term(h);
+ print_long_term(h);
+ return 0;
+}
+
+static int decode_ref_pic_marking(H264Context *h){
+ MpegEncContext * const s = &h->s;
+ int i;
+
+ if(h->nal_unit_type == NAL_IDR_SLICE){ //FIXME fields
+ s->broken_link= get_bits1(&s->gb) -1;
+ h->mmco[0].long_index= get_bits1(&s->gb) - 1; // current_long_term_idx
+ if(h->mmco[0].long_index == -1)
+ h->mmco_index= 0;
+ else{
+ h->mmco[0].opcode= MMCO_LONG;
+ h->mmco_index= 1;
+ }
+ }else{
+ if(get_bits1(&s->gb)){ // adaptive_ref_pic_marking_mode_flag
+ for(i= 0; i<MAX_MMCO_COUNT; i++) {
+ MMCOOpcode opcode= get_ue_golomb(&s->gb);;
+
+ h->mmco[i].opcode= opcode;
+ if(opcode==MMCO_SHORT2UNUSED || opcode==MMCO_SHORT2LONG){
+ h->mmco[i].short_frame_num= (h->frame_num - get_ue_golomb(&s->gb) - 1) & ((1<<h->sps.log2_max_frame_num)-1); //FIXME fields
+/* if(h->mmco[i].short_frame_num >= h->short_ref_count || h->short_ref[ h->mmco[i].short_frame_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_index= get_ue_golomb(&s->gb);
+ if(/*h->mmco[i].long_index >= h->long_ref_count || h->long_ref[ h->mmco[i].long_index ] == NULL*/ long_index >= 16){
+ 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_index= long_index;
+ }
+
+ 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->long_ref_count + h->short_ref_count == h->sps.ref_frame_count){ //FIXME fields
+ h->mmco[0].opcode= MMCO_SHORT2UNUSED;
+ h->mmco[0].short_frame_num= h->short_ref[ h->short_ref_count - 1 ]->frame_num;
+ h->mmco_index= 1;
+ }else
+ h->mmco_index= 0;
+ }
+ }
+
+ return 0;
+}
+
+static int init_poc(H264Context *h){
+ MpegEncContext * const s = &h->s;
+ const int max_frame_num= 1<<h->sps.log2_max_frame_num;
+ int field_poc[2];
+
+ if(h->nal_unit_type == NAL_IDR_SLICE){
+ h->frame_num_offset= 0;
+ }else{
+ if(h->frame_num < h->prev_frame_num)
+ h->frame_num_offset= h->prev_frame_num_offset + max_frame_num;
+ else
+ h->frame_num_offset= h->prev_frame_num_offset;
+ }
+
+ if(h->sps.poc_type==0){
+ const int max_poc_lsb= 1<<h->sps.log2_max_poc_lsb;
+
+ if(h->nal_unit_type == NAL_IDR_SLICE){
+ h->prev_poc_msb=
+ h->prev_poc_lsb= 0;
+ }
+
+ if (h->poc_lsb < h->prev_poc_lsb && h->prev_poc_lsb - h->poc_lsb >= max_poc_lsb/2)
+ h->poc_msb = h->prev_poc_msb + max_poc_lsb;
+ else if(h->poc_lsb > h->prev_poc_lsb && h->prev_poc_lsb - h->poc_lsb < -max_poc_lsb/2)
+ h->poc_msb = h->prev_poc_msb - max_poc_lsb;
+ else
+ h->poc_msb = h->prev_poc_msb;
+//printf("poc: %d %d\n", h->poc_msb, h->poc_lsb);
+ field_poc[0] =
+ field_poc[1] = h->poc_msb + h->poc_lsb;
+ if(s->picture_structure == PICT_FRAME)
+ field_poc[1] += h->delta_poc_bottom;
+ }else if(h->sps.poc_type==1){
+ int abs_frame_num, expected_delta_per_poc_cycle, expectedpoc;
+ int i;
+
+ if(h->sps.poc_cycle_length != 0)
+ abs_frame_num = h->frame_num_offset + h->frame_num;
+ else
+ abs_frame_num = 0;
+
+ if(h->nal_ref_idc==0 && abs_frame_num > 0)
+ abs_frame_num--;
+
+ expected_delta_per_poc_cycle = 0;
+ for(i=0; i < h->sps.poc_cycle_length; i++)
+ expected_delta_per_poc_cycle += h->sps.offset_for_ref_frame[ i ]; //FIXME integrate during sps parse
+
+ if(abs_frame_num > 0){
+ int poc_cycle_cnt = (abs_frame_num - 1) / h->sps.poc_cycle_length;
+ int frame_num_in_poc_cycle = (abs_frame_num - 1) % h->sps.poc_cycle_length;
+
+ expectedpoc = poc_cycle_cnt * expected_delta_per_poc_cycle;
+ for(i = 0; i <= frame_num_in_poc_cycle; i++)
+ expectedpoc = expectedpoc + h->sps.offset_for_ref_frame[ i ];
+ } else
+ expectedpoc = 0;
+
+ if(h->nal_ref_idc == 0)
+ expectedpoc = expectedpoc + h->sps.offset_for_non_ref_pic;
+
+ field_poc[0] = expectedpoc + h->delta_poc[0];
+ field_poc[1] = field_poc[0] + h->sps.offset_for_top_to_bottom_field;
+
+ if(s->picture_structure == PICT_FRAME)
+ field_poc[1] += h->delta_poc[1];
+ }else{
+ int poc;
+ if(h->nal_unit_type == NAL_IDR_SLICE){
+ poc= 0;
+ }else{
+ if(h->nal_ref_idc) poc= 2*(h->frame_num_offset + h->frame_num);
+ else poc= 2*(h->frame_num_offset + h->frame_num) - 1;
+ }
+ field_poc[0]= poc;
+ field_poc[1]= poc;
+ }
+
+ if(s->picture_structure != PICT_BOTTOM_FIELD)
+ s->current_picture_ptr->field_poc[0]= field_poc[0];
+ if(s->picture_structure != PICT_TOP_FIELD)
+ s->current_picture_ptr->field_poc[1]= field_poc[1];
+ if(s->picture_structure == PICT_FRAME) // FIXME field pix?
+ s->current_picture_ptr->poc= FFMIN(field_poc[0], field_poc[1]);
+
+ return 0;
+}
+
+/**
+ * decodes a slice header.
+ * this will allso call MPV_common_init() and frame_start() as needed
+ */
+static int decode_slice_header(H264Context *h){
+ MpegEncContext * const s = &h->s;
+ unsigned int first_mb_in_slice;
+ unsigned int pps_id;
+ int num_ref_idx_active_override_flag;
+ static const uint8_t slice_type_map[5]= {P_TYPE, B_TYPE, I_TYPE, SP_TYPE, SI_TYPE};
+ unsigned int slice_type, tmp;
+ int default_ref_list_done = 0;
+
+ s->current_picture.reference= h->nal_ref_idc != 0;
+ s->dropable= h->nal_ref_idc == 0;
+
+ first_mb_in_slice= get_ue_golomb(&s->gb);
+
+ if((s->flags2 & CODEC_FLAG2_CHUNKS) && first_mb_in_slice == 0){
+ h->slice_num = 0;
+ s->current_picture_ptr= NULL;
+ }
+
+ slice_type= get_ue_golomb(&s->gb);
+ if(slice_type > 9){
+ av_log(h->s.avctx, AV_LOG_ERROR, "slice type too large (%d) at %d %d\n", h->slice_type, s->mb_x, s->mb_y);
+ return -1;
+ }
+ if(slice_type > 4){
+ slice_type -= 5;
+ h->slice_type_fixed=1;
+ }else
+ h->slice_type_fixed=0;
+
+ slice_type= slice_type_map[ slice_type ];
+ if (slice_type == I_TYPE
+ || (h->slice_num != 0 && slice_type == h->slice_type) ) {
+ default_ref_list_done = 1;
+ }
+ h->slice_type= slice_type;
+
+ s->pict_type= h->slice_type; // to make a few old func happy, it's wrong though
+
+ pps_id= get_ue_golomb(&s->gb);
+ if(pps_id>=MAX_PPS_COUNT){
+ av_log(h->s.avctx, AV_LOG_ERROR, "pps_id out of range\n");
+ return -1;
+ }
+ h->pps= h->pps_buffer[pps_id];
+ if(h->pps.slice_group_count == 0){
+ av_log(h->s.avctx, AV_LOG_ERROR, "non existing PPS referenced\n");
+ return -1;
+ }
+
+ h->sps= h->sps_buffer[ h->pps.sps_id ];
+ if(h->sps.log2_max_frame_num == 0){
+ av_log(h->s.avctx, AV_LOG_ERROR, "non existing SPS referenced\n");
+ return -1;
+ }
+
+ if(h->dequant_coeff_pps != pps_id){
+ h->dequant_coeff_pps = pps_id;
+ init_dequant_tables(h);
+ }
+
+ s->mb_width= h->sps.mb_width;
+ 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*(h->sps.crop_left + h->sps.crop_right );
+ if(h->sps.frame_mbs_only_flag)
+ s->height= 16*s->mb_height - 2*(h->sps.crop_top + h->sps.crop_bottom);
+ else
+ s->height= 16*s->mb_height - 4*(h->sps.crop_top + h->sps.crop_bottom); //FIXME recheck
+
+ if (s->context_initialized
+ && ( s->width != s->avctx->width || s->height != s->avctx->height)) {
+ free_tables(h);
+ MPV_common_end(s);
+ }
+ if (!s->context_initialized) {
+ if (MPV_common_init(s) < 0)
+ return -1;
+
+ if(s->dsp.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{
+ int i;
+ for(i=0; i<16; i++){
+#define T(x) (x>>2) | ((x<<2) & 0xF)
+ h->zigzag_scan[i] = T(zigzag_scan[i]);
+ h-> field_scan[i] = T( field_scan[i]);
+#undef T
+ }
+ }
+ if(s->dsp.h264_idct8_add == ff_h264_idct8_add_c){
+ memcpy(h->zigzag_scan8x8, zigzag_scan8x8, 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));
+ memcpy(h->field_scan8x8_cavlc, field_scan8x8_cavlc, 64*sizeof(uint8_t));
+ }else{
+ int i;
+ for(i=0; i<64; i++){
+#define T(x) (x>>3) | ((x&7)<<3)
+ h->zigzag_scan8x8[i] = T(zigzag_scan8x8[i]);
+ h->zigzag_scan8x8_cavlc[i] = T(zigzag_scan8x8_cavlc[i]);
+ h->field_scan8x8[i] = T(field_scan8x8[i]);
+ h->field_scan8x8_cavlc[i] = T(field_scan8x8_cavlc[i]);
+#undef T
+ }
+ }
+ if(h->sps.transform_bypass){ //FIXME same ugly
+ h->zigzag_scan_q0 = zigzag_scan;
+ h->zigzag_scan8x8_q0 = zigzag_scan8x8;
+ h->zigzag_scan8x8_cavlc_q0 = zigzag_scan8x8_cavlc;
+ h->field_scan_q0 = field_scan;
+ h->field_scan8x8_q0 = field_scan8x8;
+ h->field_scan8x8_cavlc_q0 = field_scan8x8_cavlc;
+ }else{
+ h->zigzag_scan_q0 = h->zigzag_scan;
+ h->zigzag_scan8x8_q0 = h->zigzag_scan8x8;
+ h->zigzag_scan8x8_cavlc_q0 = h->zigzag_scan8x8_cavlc;
+ h->field_scan_q0 = h->field_scan;
+ h->field_scan8x8_q0 = h->field_scan8x8;
+ h->field_scan8x8_cavlc_q0 = h->field_scan8x8_cavlc;
+ }
+
+ alloc_tables(h);
+
+ 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 * 2, 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);
+ }
+ }
+
+ if(h->slice_num == 0){
+ if(frame_start(h) < 0)
+ return -1;
+ }
+
+ s->current_picture_ptr->frame_num= //FIXME frame_num cleanup
+ h->frame_num= get_bits(&s->gb, h->sps.log2_max_frame_num);
+
+ h->mb_mbaff = 0;
+ h->mb_aff_frame = 0;
+ if(h->sps.frame_mbs_only_flag){
+ s->picture_structure= PICT_FRAME;
+ }else{
+ if(get_bits1(&s->gb)) { //field_pic_flag
+ s->picture_structure= PICT_TOP_FIELD + get_bits1(&s->gb); //bottom_field_flag
+ av_log(h->s.avctx, AV_LOG_ERROR, "PAFF interlacing is not implemented\n");
+ } else {
+ s->picture_structure= PICT_FRAME;
+ h->mb_aff_frame = h->sps.mb_aff;
+ }
+ }
+ assert(s->mb_num == s->mb_width * s->mb_height);
+ if(first_mb_in_slice << h->mb_aff_frame >= s->mb_num ||
+ first_mb_in_slice >= s->mb_num){
+ av_log(h->s.avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\n");
+ return -1;
+ }
+ s->resync_mb_x = s->mb_x = first_mb_in_slice % s->mb_width;
+ s->resync_mb_y = s->mb_y = (first_mb_in_slice / s->mb_width) << h->mb_aff_frame;
+ assert(s->mb_y < s->mb_height);
+
+ if(s->picture_structure==PICT_FRAME){
+ h->curr_pic_num= h->frame_num;
+ h->max_pic_num= 1<< h->sps.log2_max_frame_num;
+ }else{
+ h->curr_pic_num= 2*h->frame_num;
+ h->max_pic_num= 1<<(h->sps.log2_max_frame_num + 1);
+ }
+
+ if(h->nal_unit_type == NAL_IDR_SLICE){
+ get_ue_golomb(&s->gb); /* idr_pic_id */
+ }
+
+ if(h->sps.poc_type==0){
+ h->poc_lsb= get_bits(&s->gb, h->sps.log2_max_poc_lsb);
+
+ if(h->pps.pic_order_present==1 && s->picture_structure==PICT_FRAME){
+ h->delta_poc_bottom= get_se_golomb(&s->gb);
+ }
+ }
+
+ if(h->sps.poc_type==1 && !h->sps.delta_pic_order_always_zero_flag){
+ h->delta_poc[0]= get_se_golomb(&s->gb);
+
+ if(h->pps.pic_order_present==1 && s->picture_structure==PICT_FRAME)
+ h->delta_poc[1]= get_se_golomb(&s->gb);
+ }
+
+ init_poc(h);
+
+ if(h->pps.redundant_pic_cnt_present){
+ h->redundant_pic_count= get_ue_golomb(&s->gb);
+ }
+
+ //set defaults, might be overriden a few line later
+ h->ref_count[0]= h->pps.ref_count[0];
+ h->ref_count[1]= h->pps.ref_count[1];
+
+ if(h->slice_type == P_TYPE || h->slice_type == SP_TYPE || h->slice_type == B_TYPE){
+ if(h->slice_type == B_TYPE){
+ h->direct_spatial_mv_pred= get_bits1(&s->gb);
+ if(h->sps.mb_aff && h->direct_spatial_mv_pred)
+ av_log(h->s.avctx, AV_LOG_ERROR, "MBAFF + spatial direct mode is not implemented\n");
+ }
+ num_ref_idx_active_override_flag= get_bits1(&s->gb);
+
+ if(num_ref_idx_active_override_flag){
+ h->ref_count[0]= get_ue_golomb(&s->gb) + 1;
+ if(h->slice_type==B_TYPE)
+ h->ref_count[1]= get_ue_golomb(&s->gb) + 1;
+
+ if(h->ref_count[0]-1 > 32-1 || h->ref_count[1]-1 > 32-1){
+ av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow\n");
+ h->ref_count[0]= h->ref_count[1]= 1;
+ return -1;
+ }
+ }
+ if(h->slice_type == B_TYPE)
+ h->list_count= 2;
+ else
+ h->list_count= 1;
+ }else
+ h->list_count= 0;
+
+ if(!default_ref_list_done){
+ fill_default_ref_list(h);
+ }
+
+ if(decode_ref_pic_list_reordering(h) < 0)
+ return -1;
+
+ if( (h->pps.weighted_pred && (h->slice_type == P_TYPE || h->slice_type == SP_TYPE ))
+ || (h->pps.weighted_bipred_idc==1 && h->slice_type==B_TYPE ) )
+ pred_weight_table(h);
+ else if(h->pps.weighted_bipred_idc==2 && h->slice_type==B_TYPE)
+ implicit_weight_table(h);
+ else
+ h->use_weight = 0;
+
+ if(s->current_picture.reference)
+ decode_ref_pic_marking(h);
+
+ if(FRAME_MBAFF)
+ fill_mbaff_ref_list(h);
+
+ if( h->slice_type != I_TYPE && h->slice_type != SI_TYPE && h->pps.cabac ){
+ tmp = get_ue_golomb(&s->gb);
+ if(tmp > 2){
+ av_log(s->avctx, AV_LOG_ERROR, "cabac_init_idc overflow\n");
+ return -1;
+ }
+ h->cabac_init_idc= tmp;
+ }
+
+ h->last_qscale_diff = 0;
+ tmp = h->pps.init_qp + get_se_golomb(&s->gb);
+ if(tmp>51){
+ av_log(s->avctx, AV_LOG_ERROR, "QP %u out of range\n", tmp);
+ return -1;
+ }
+ s->qscale= tmp;
+ h->chroma_qp = get_chroma_qp(h->pps.chroma_qp_index_offset, s->qscale);
+ //FIXME qscale / qp ... stuff
+ if(h->slice_type == SP_TYPE){
+ get_bits1(&s->gb); /* sp_for_switch_flag */
+ }
+ if(h->slice_type==SP_TYPE || h->slice_type == SI_TYPE){
+ get_se_golomb(&s->gb); /* slice_qs_delta */
+ }
+
+ h->deblocking_filter = 1;
+ h->slice_alpha_c0_offset = 0;
+ h->slice_beta_offset = 0;
+ if( h->pps.deblocking_filter_parameters_present ) {
+ tmp= get_ue_golomb(&s->gb);
+ if(tmp > 2){
+ av_log(s->avctx, AV_LOG_ERROR, "deblocking_filter_idc %u out of range\n", tmp);
+ return -1;
+ }
+ h->deblocking_filter= tmp;
+ if(h->deblocking_filter < 2)
+ 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;
+ }
+ }
+ if( s->avctx->skip_loop_filter >= AVDISCARD_ALL
+ ||(s->avctx->skip_loop_filter >= AVDISCARD_NONKEY && h->slice_type != I_TYPE)
+ ||(s->avctx->skip_loop_filter >= AVDISCARD_BIDIR && h->slice_type == B_TYPE)
+ ||(s->avctx->skip_loop_filter >= AVDISCARD_NONREF && h->nal_ref_idc == 0))
+ h->deblocking_filter= 0;
+
+#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)
+ slice_group_change_cycle= get_bits(&s->gb, ?);
+#endif
+
+ h->slice_num++;
+
+ h->emu_edge_width= (s->flags&CODEC_FLAG_EMU_EDGE) ? 0 : 16;
+ h->emu_edge_height= FRAME_MBAFF ? 0 : h->emu_edge_width;
+
+ if(s->avctx->debug&FF_DEBUG_PICT_INFO){
+ av_log(h->s.avctx, AV_LOG_DEBUG, "slice:%d %s mb:%d %c pps:%u frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s\n",
+ h->slice_num,
+ (s->picture_structure==PICT_FRAME ? "F" : s->picture_structure==PICT_TOP_FIELD ? "T" : "B"),
+ first_mb_in_slice,
+ av_get_pict_type_char(h->slice_type),
+ pps_id, h->frame_num,
+ 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->use_weight,
+ h->use_weight==1 && h->use_weight_chroma ? "c" : ""
+ );
+ }
+
+ if((s->avctx->flags2 & CODEC_FLAG2_FAST) && !s->current_picture.reference){
+ s->me.qpel_put= s->dsp.put_2tap_qpel_pixels_tab;
+ s->me.qpel_avg= s->dsp.avg_2tap_qpel_pixels_tab;
+ }else{
+ s->me.qpel_put= s->dsp.put_h264_qpel_pixels_tab;
+ s->me.qpel_avg= s->dsp.avg_h264_qpel_pixels_tab;
+ }
+
+ return 0;
+}
+
+/**
+ *
+ */
+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){
+ int i;
+ for(i=0; i<4; i++){
+ if(!IS_SUB_8X8(h->sub_mb_type[i])
+ || (!h->sps.direct_8x8_inference_flag && IS_DIRECT(h->sub_mb_type[i])))
+ return 0;
+ }
+ return 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 occured
+ */
+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);
+
+ for(i=0; i<trailing_ones; i++){
+ level[i]= 1 - 2*get_bits1(gb);
+ }
+
+ if(i<total_coeff) {
+ int level_code, mask;
+ int suffix_length = total_coeff > 10 && trailing_ones < 3;
+ int 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<<suffix_length) + get_bits(gb, suffix_length); //part
+ else
+ level_code= (prefix<<suffix_length); //part
+ }else if(prefix==14){
+ if(suffix_length)
+ level_code= (prefix<<suffix_length) + get_bits(gb, suffix_length); //part
+ else
+ level_code= prefix + get_bits(gb, 4); //part
+ }else if(prefix==15){
+ level_code= (prefix<<suffix_length) + get_bits(gb, 12); //part
+ if(suffix_length==0) level_code+=15; //FIXME doesn't make (much)sense
+ }else{
+ av_log(h->s.avctx, AV_LOG_ERROR, "prefix too large at %d %d\n", s->mb_x, s->mb_y);
+ return -1;
+ }
+
+ if(trailing_ones < 3) level_code += 2;
+
+ suffix_length = 1;
+ if(level_code > 5)
+ suffix_length++;
+ mask= -(level_code&1);
+ level[i]= (((2+level_code)>>1) ^ mask) - mask;
+ i++;
+
+ //remaining coefficients have suffix_length > 0
+ for(;i<total_coeff;i++) {
+ static const int suffix_limit[7] = {0,5,11,23,47,95,INT_MAX };
+ prefix = get_level_prefix(gb);
+ if(prefix<15){
+ level_code = (prefix<<suffix_length) + get_bits(gb, suffix_length);
+ }else if(prefix==15){
+ level_code = (prefix<<suffix_length) + get_bits(gb, 12);
+ }else{
+ av_log(h->s.avctx, AV_LOG_ERROR, "prefix too large at %d %d\n", s->mb_x, s->mb_y);
+ return -1;
+ }
+ mask= -(level_code&1);
+ level[i]= (((2+level_code)>>1) ^ mask) - mask;
+ if(level_code > 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<total_coeff;i++) {
+ if(zeros_left <= 0)
+ run_before = 0;
+ else if(zeros_left < 7){
+ run_before= get_vlc2(gb, run_vlc[zeros_left-1].table, RUN_VLC_BITS, 1);
+ }else{
+ run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2);
+ }
+ zeros_left -= run_before;
+ coeff_num -= 1 + run_before;
+ j= scantable[ coeff_num ];
+
+ block[j]= level[i];
+ }
+ }else{
+ block[j] = (level[0] * qmul[j] + 32)>>6;
+ for(i=1;i<total_coeff;i++) {
+ if(zeros_left <= 0)
+ run_before = 0;
+ else if(zeros_left < 7){
+ run_before= get_vlc2(gb, run_vlc[zeros_left-1].table, RUN_VLC_BITS, 1);
+ }else{
+ run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2);
+ }
+ zeros_left -= run_before;
+ coeff_num -= 1 + run_before;
+ j= scantable[ coeff_num ];
+
+ block[j]= (level[i] * qmul[j] + 32)>>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){
+ 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;
+}
+
+/**
+ * decodes a P_SKIP or B_SKIP macroblock
+ */
+static void decode_mb_skip(H264Context *h){
+ MpegEncContext * const s = &h->s;
+ const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
+ int mb_type=0;
+
+ memset(h->non_zero_count[mb_xy], 0, 16);
+ 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 == B_TYPE )
+ {
+ // just for fill_caches. pred_direct_motion will set the real mb_type
+ mb_type|= MB_TYPE_16x16|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;
+ const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
+ int partition_count;
+ unsigned int mb_type, cbp;
+ int dct8x8_allowed= h->pps.transform_8x8_mode;
+
+ s->dsp.clear_blocks(h->mb); //FIXME avoid if already clear (move after skip handlong?
+
+ 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 != I_TYPE && h->slice_type != SI_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);
+ }else
+ h->mb_field_decoding_flag= (s->picture_structure!=PICT_FRAME);
+
+ h->prev_mb_skipped= 0;
+
+ mb_type= get_ue_golomb(&s->gb);
+ if(h->slice_type == 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 == P_TYPE /*|| h->slice_type == SP_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 == I_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, y;
+
+ // we assume these blocks are very rare so we dont optimize it
+ align_get_bits(&s->gb);
+
+ // The pixels are stored in the same order as levels in h->mb array.
+ for(y=0; y<16; y++){
+ const int index= 4*(y&3) + 32*((y>>2)&1) + 128*(y>>3);
+ for(x=0; x<16; x++){
+ tprintf(s->avctx, "LUMA ICPM LEVEL (%3d)\n", show_bits(&s->gb, 8));
+ h->mb[index + (x&3) + 16*((x>>2)&1) + 64*(x>>3)]= get_bits(&s->gb, 8);
+ }
+ }
+ for(y=0; y<8; y++){
+ const int index= 256 + 4*(y&3) + 32*(y>>2);
+ for(x=0; x<8; x++){
+ tprintf(s->avctx, "CHROMA U ICPM LEVEL (%3d)\n", show_bits(&s->gb, 8));
+ h->mb[index + (x&3) + 16*(x>>2)]= get_bits(&s->gb, 8);
+ }
+ }
+ for(y=0; y<8; y++){
+ const int index= 256 + 64 + 4*(y&3) + 32*(y>>2);
+ for(x=0; x<8; x++){
+ tprintf(s->avctx, "CHROMA V ICPM LEVEL (%3d)\n", show_bits(&s->gb, 8));
+ h->mb[index + (x&3) + 16*(x>>2)]= get_bits(&s->gb, 8);
+ }
+ }
+
+ // In deblocking, the quantizer is 0
+ s->current_picture.qscale_table[mb_xy]= 0;
+ h->chroma_qp = get_chroma_qp(h->pps.chroma_qp_index_offset, 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;
+ }
+
+ pred_mode= check_intra_pred_mode(h, get_ue_golomb(&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 == B_TYPE){
+ for(i=0; i<4; i++){
+ h->sub_mb_type[i]= get_ue_golomb(&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 == P_TYPE || h->slice_type == SP_TYPE); //FIXME SP correct ?
+ for(i=0; i<4; i++){
+ h->sub_mb_type[i]= get_ue_golomb(&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; list<h->list_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 = get_te0_golomb(&s->gb, ref_count); //FIXME init to 0 before and skip?
+ 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; list<h->list_count; list++){
+ const 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])) {
+ 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; j<sub_partition_count[i]; j++){
+ int mx, my;
+ const int index= 4*i + block_width*j;
+ int16_t (* mv_cache)[2]= &h->mv_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; list<h->list_count; list++){
+ unsigned int val;
+ if(IS_DIR(mb_type, 0, list)){
+ val= get_te0_golomb(&s->gb, h->ref_count[list]);
+ 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; list<h->list_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; list<h->list_count; list++){
+ for(i=0; i<2; i++){
+ unsigned int val;
+ if(IS_DIR(mb_type, i, list)){
+ val= get_te0_golomb(&s->gb, h->ref_count[list]);
+ 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; list<h->list_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; list<h->list_count; list++){
+ for(i=0; i<2; i++){
+ unsigned int val;
+ if(IS_DIR(mb_type, i, list)){ //FIXME optimize
+ val= get_te0_golomb(&s->gb, h->ref_count[list]);
+ 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; list<h->list_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(IS_INTRA4x4(mb_type))
+ cbp= golomb_to_intra4x4_cbp[cbp];
+ else
+ cbp= golomb_to_inter_cbp[cbp];
+ }
+ h->cbp = cbp;
+
+ if(dct8x8_allowed && (cbp&15) && !IS_INTRA(mb_type)){
+ if(get_bits1(&s->gb))
+ mb_type |= MB_TYPE_8x8DCT;
+ }
+ s->current_picture.mb_type[mb_xy]= mb_type;
+
+ if(cbp || IS_INTRA16x16(mb_type)){
+ int i8x8, i4x4, chroma_idx;
+ int chroma_qp, 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= chroma_qp= get_chroma_qp(h->pps.chroma_qp_index_offset, 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<<i8x8)){
+ if(IS_8x8DCT(mb_type)){
+ DCTELEM *buf = &h->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++){
+ 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, h->dequant4_coeff[chroma_idx+1+(IS_INTRA( mb_type ) ? 0:3)][chroma_qp], 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( H264Context *h ) {
+ MpegEncContext * const s = &h->s;
+
+ if( h->slice_type == I_TYPE ) {
+ return decode_cabac_intra_mb_type(h, 3, 1);
+ } else if( h->slice_type == 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 */
+ return 3 * get_cabac_noinline( &h->cabac, &h->cabac_state[16] );
+ } else {
+ /* P_L0_D8x16, P_L0_D16x8 */
+ return 2 - get_cabac_noinline( &h->cabac, &h->cabac_state[17] );
+ }
+ } else {
+ return decode_cabac_intra_mb_type(h, 17, 0) + 5;
+ }
+ } else if( h->slice_type == B_TYPE ) {
+ const int mba_xy = h->left_mb_xy[0];
+ const int mbb_xy = h->top_mb_xy;
+ int ctx = 0;
+ int bits;
+
+ 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_* */
+ } else {
+ /* TODO SI/SP frames? */
+ return -1;
+ }
+}
+
+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 = mb_x + mb_y*s->mb_stride;
+ mba_xy = mb_xy - 1;
+ mbb_xy = mb_xy - s->mb_stride;
+ }
+
+ 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 == 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 const uint8_t block_idx_x[16] = {
+ 0, 1, 0, 1, 2, 3, 2, 3, 0, 1, 0, 1, 2, 3, 2, 3
+};
+static const uint8_t block_idx_y[16] = {
+ 0, 0, 1, 1, 0, 0, 1, 1, 2, 2, 3, 3, 2, 2, 3, 3
+};
+static const uint8_t block_idx_xy[4][4] = {
+ { 0, 2, 8, 10},
+ { 1, 3, 9, 11},
+ { 4, 6, 12, 14},
+ { 5, 7, 13, 15}
+};
+
+static int decode_cabac_mb_cbp_luma( H264Context *h) {
+ int cbp = 0;
+ int cbp_b = -1;
+ int i8x8;
+
+ if( h->slice_table[h->top_mb_xy] == h->slice_num ) {
+ cbp_b = h->top_cbp;
+ tprintf(h->s.avctx, "cbp_b = top_cbp = %x\n", cbp_b);
+ }
+
+ for( i8x8 = 0; i8x8 < 4; i8x8++ ) {
+ int cbp_a = -1;
+ int x, y;
+ int ctx = 0;
+
+ x = block_idx_x[4*i8x8];
+ y = block_idx_y[4*i8x8];
+
+ if( x > 0 )
+ cbp_a = cbp;
+ else if( h->slice_table[h->left_mb_xy[0]] == h->slice_num ) {
+ cbp_a = h->left_cbp;
+ tprintf(h->s.avctx, "cbp_a = left_cbp = %x\n", cbp_a);
+ }
+
+ if( y > 0 )
+ cbp_b = cbp;
+
+ /* No need to test for skip as we put 0 for skip block */
+ /* No need to test for IPCM as we put 1 for IPCM block */
+ if( cbp_a >= 0 ) {
+ int i8x8a = block_idx_xy[(x-1)&0x03][y]/4;
+ if( ((cbp_a >> i8x8a)&0x01) == 0 )
+ ctx++;
+ }
+
+ if( cbp_b >= 0 ) {
+ int i8x8b = block_idx_xy[x][(y-1)&0x03]/4;
+ if( ((cbp_b >> i8x8b)&0x01) == 0 )
+ ctx += 2;
+ }
+
+ if( get_cabac( &h->cabac, &h->cabac_state[73 + ctx] ) ) {
+ cbp |= 1 << i8x8;
+ }
+ }
+ 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) {
+ MpegEncContext * const s = &h->s;
+ int mbn_xy;
+ int ctx = 0;
+ int val = 0;
+
+ if( s->mb_x > 0 )
+ mbn_xy = s->mb_x + s->mb_y*s->mb_stride - 1;
+ else
+ mbn_xy = s->mb_width - 1 + (s->mb_y-1)*s->mb_stride;
+
+ if( h->last_qscale_diff != 0 )
+ ctx++;
+
+ while( get_cabac_noinline( &h->cabac, &h->cabac_state[60 + ctx] ) ) {
+ if( ctx < 2 )
+ ctx = 2;
+ else
+ ctx = 3;
+ val++;
+ if(val > 102) //prevent infinite loop
+ return INT_MIN;
+ }
+
+ if( val&0x01 )
+ return (val + 1)/2;
+ else
+ return -(val + 1)/2;
+}
+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 == 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++;
+ if( ctx < 4 )
+ ctx = 4;
+ else
+ ctx = 5;
+ if(ref >= 32 /*h->ref_list[list]*/){
+ av_log(h->s.avctx, AV_LOG_ERROR, "overflow in decode_cabac_mb_ref\n");
+ return 0; //FIXME we should return -1 and check the return everywhere
+ }
+ }
+ 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 ctx, mvd;
+
+ if( amvd < 3 )
+ ctx = 0;
+ else if( amvd > 32 )
+ ctx = 2;
+ else
+ ctx = 1;
+
+ 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 int inline get_cabac_cbf_ctx( H264Context *h, int cat, int idx ) {
+ int nza, nzb;
+ int ctx = 0;
+
+ if( cat == 0 ) {
+ nza = h->left_cbp&0x100;
+ nzb = h-> top_cbp&0x100;
+ } else if( cat == 1 || cat == 2 ) {
+ nza = h->non_zero_count_cache[scan8[idx] - 1];
+ nzb = h->non_zero_count_cache[scan8[idx] - 8];
+ } else if( cat == 3 ) {
+ nza = (h->left_cbp>>(6+idx))&0x01;
+ nzb = (h-> top_cbp>>(6+idx))&0x01;
+ } else {
+ assert(cat == 4);
+ nza = h->non_zero_count_cache[scan8[16+idx] - 1];
+ nzb = h->non_zero_count_cache[scan8[16+idx] - 8];
+ }
+
+ if( nza > 0 )
+ ctx++;
+
+ if( nzb > 0 )
+ ctx += 2;
+
+ return ctx + 4 * cat;
+}
+
+static const __attribute((used)) 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 int decode_cabac_residual( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff) {
+ const int mb_xy = h->s.mb_x + h->s.mb_y*h->s.mb_stride;
+ 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 }
+ };
+
+ int index[64];
+
+ int last;
+ int coeff_count = 0;
+
+ int abslevel1 = 1;
+ int abslevelgt1 = 0;
+
+ uint8_t *significant_coeff_ctx_base;
+ uint8_t *last_coeff_ctx_base;
+ uint8_t *abs_level_m1_ctx_base;
+
+#ifndef 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 = 4 * iCbCr + chroma4x4idx
+ * 5-> Luma8x8 n = 4 * luma8x8idx
+ */
+
+ /* read coded block flag */
+ if( cat != 5 ) {
+ if( get_cabac( CC, &h->cabac_state[85 + get_cabac_cbf_ctx( h, cat, n ) ] ) == 0 ) {
+ if( cat == 1 || cat == 2 )
+ h->non_zero_count_cache[scan8[n]] = 0;
+ else if( cat == 4 )
+ h->non_zero_count_cache[scan8[16+n]] = 0;
+#ifdef CABAC_ON_STACK
+ h->cabac.range = cc.range ;
+ h->cabac.low = cc.low ;
+ h->cabac.bytestream= cc.bytestream;
+#endif
+ return 0;
+ }
+ }
+
+ 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( 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 defined(ARCH_X86) && defined(CONFIG_7REGS) && defined(CONFIG_EBX_AVAILABLE) && !( defined(ARCH_X86_64) && defined(PIC) )
+ 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( cat == 0 )
+ h->cbp_table[mb_xy] |= 0x100;
+ else if( cat == 1 || cat == 2 )
+ h->non_zero_count_cache[scan8[n]] = coeff_count;
+ else if( cat == 3 )
+ h->cbp_table[mb_xy] |= 0x40 << n;
+ else if( cat == 4 )
+ h->non_zero_count_cache[scan8[16+n]] = coeff_count;
+ else {
+ assert( cat == 5 );
+ fill_rectangle(&h->non_zero_count_cache[scan8[n]], 2, 2, 8, coeff_count, 1);
+ }
+
+ for( coeff_count--; coeff_count >= 0; coeff_count-- ) {
+ uint8_t *ctx = (abslevelgt1 != 0 ? 0 : FFMIN( 4, abslevel1 )) + abs_level_m1_ctx_base;
+ int j= scantable[index[coeff_count]];
+
+ if( get_cabac( CC, ctx ) == 0 ) {
+ if( !qmul ) {
+ block[j] = get_cabac_bypass_sign( CC, -1);
+ }else{
+ block[j] = (get_cabac_bypass_sign( CC, -qmul[j]) + 32) >> 6;;
+ }
+
+ abslevel1++;
+ } else {
+ int coeff_abs = 2;
+ ctx = 5 + FFMIN( 4, abslevelgt1 ) + abs_level_m1_ctx_base;
+ 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( !qmul ) {
+ if( get_cabac_bypass( CC ) ) block[j] = -coeff_abs;
+ else block[j] = coeff_abs;
+ }else{
+ if( get_cabac_bypass( CC ) ) block[j] = (-coeff_abs * qmul[j] + 32) >> 6;
+ else block[j] = ( coeff_abs * qmul[j] + 32) >> 6;
+ }
+
+ abslevelgt1++;
+ }
+ }
+#ifdef CABAC_ON_STACK
+ h->cabac.range = cc.range ;
+ h->cabac.low = cc.low ;
+ h->cabac.bytestream= cc.bytestream;
+#endif
+ return 0;
+}
+
+static void inline compute_mb_neighbors(H264Context *h)
+{
+ MpegEncContext * const s = &h->s;
+ const int mb_xy = s->mb_x + s->mb_y*s->mb_stride;
+ 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_frame_flag = !IS_INTERLACED(s->current_picture.mb_type[top_pair_xy]);
+ const int left_mb_frame_flag = !IS_INTERLACED(s->current_picture.mb_type[pair_xy-1]);
+ const int curr_mb_frame_flag = !MB_FIELD;
+ const int bottom = (s->mb_y & 1);
+ if (bottom
+ ? !curr_mb_frame_flag // bottom macroblock
+ : (!curr_mb_frame_flag && !top_mb_frame_flag) // top macroblock
+ ) {
+ h->top_mb_xy -= s->mb_stride;
+ }
+ if (left_mb_frame_flag != curr_mb_frame_flag) {
+ h->left_mb_xy[0] = pair_xy - 1;
+ }
+ }
+ 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;
+ const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
+ int mb_type, partition_count, cbp = 0;
+ int dct8x8_allowed= h->pps.transform_8x8_mode;
+
+ s->dsp.clear_blocks(h->mb); //FIXME avoid if already clear (move after skip handlong?)
+
+ tprintf(s->avctx, "pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y);
+ if( h->slice_type != I_TYPE && h->slice_type != SI_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)
+ predict_field_decoding_flag(h);
+ else
+ 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);
+ }else
+ h->mb_field_decoding_flag= (s->picture_structure!=PICT_FRAME);
+
+ h->prev_mb_skipped = 0;
+
+ compute_mb_neighbors(h);
+ if( ( mb_type = decode_cabac_mb_type( h ) ) < 0 ) {
+ av_log( h->s.avctx, AV_LOG_ERROR, "decode_cabac_mb_type failed\n" );
+ return -1;
+ }
+
+ if( h->slice_type == 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 == 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 == 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;
+ unsigned int x, y;
+
+ // We assume these blocks are very rare so we dont 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.
+ for(y=0; y<16; y++){
+ const int index= 4*(y&3) + 32*((y>>2)&1) + 128*(y>>3);
+ for(x=0; x<16; x++){
+ tprintf(s->avctx, "LUMA ICPM LEVEL (%3d)\n", *ptr);
+ h->mb[index + (x&3) + 16*((x>>2)&1) + 64*(x>>3)]= *ptr++;
+ }
+ }
+ for(y=0; y<8; y++){
+ const int index= 256 + 4*(y&3) + 32*(y>>2);
+ for(x=0; x<8; x++){
+ tprintf(s->avctx, "CHROMA U ICPM LEVEL (%3d)\n", *ptr);
+ h->mb[index + (x&3) + 16*(x>>2)]= *ptr++;
+ }
+ }
+ for(y=0; y<8; y++){
+ const int index= 256 + 64 + 4*(y&3) + 32*(y>>2);
+ for(x=0; x<8; x++){
+ tprintf(s->avctx, "CHROMA V ICPM LEVEL (%3d)\n", *ptr);
+ h->mb[index + (x&3) + 16*(x>>2)]= *ptr++;
+ }
+ }
+
+ 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;
+ h->chroma_qp = get_chroma_qp(h->pps.chroma_qp_index_offset, 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);
+
+ 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;
+ }
+ 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 == 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);
+ 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 );
+ 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; list<h->list_count; list++){
+ for(i=0; i<4; i++){
+ if(IS_DIRECT(h->sub_mb_type[i])){
+ fill_rectangle(h->mvd_cache[list][scan8[4*i]], 2, 2, 8, 0, 4);
+ continue;
+ }
+ h->ref_cache[list][ scan8[4*i] ]=h->ref_cache[list][ scan8[4*i]+1 ];
+
+ 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; j<sub_partition_count[i]; j++){
+ int mpx, mpy;
+ int mx, my;
+ const int index= 4*i + block_width*j;
+ int16_t (* mv_cache)[2]= &h->mv_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; list<h->list_count; list++){
+ if(IS_DIR(mb_type, 0, list)){
+ const int ref = h->ref_count[list] > 1 ? decode_cabac_mb_ref( h, list, 0 ) : 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; list<h->list_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; list<h->list_count; list++){
+ for(i=0; i<2; i++){
+ if(IS_DIR(mb_type, i, list)){
+ const int ref= h->ref_count[list] > 1 ? decode_cabac_mb_ref( h, list, 8*i ) : 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; list<h->list_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; list<h->list_count; list++){
+ for(i=0; i<2; i++){
+ if(IS_DIR(mb_type, i, list)){ //FIXME optimize
+ const int ref= h->ref_count[list] > 1 ? decode_cabac_mb_ref( h, list, 4*i ) : 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; list<h->list_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 );
+ 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;
+ 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 = get_chroma_qp(h->pps.chroma_qp_index_offset, s->qscale);
+
+ if( IS_INTRA16x16( mb_type ) ) {
+ int i;
+ //av_log( s->avctx, AV_LOG_ERROR, "INTRA16x16 DC\n" );
+ if( decode_cabac_residual( h, h->mb, 0, 0, dc_scan, NULL, 16) < 0)
+ return -1;
+ if( cbp&15 ) {
+ for( i = 0; i < 16; i++ ) {
+ //av_log( s->avctx, AV_LOG_ERROR, "INTRA16x16 AC:%d\n", i );
+ if( decode_cabac_residual(h, h->mb + 16*i, 1, i, 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 {
+ int i8x8, i4x4;
+ for( i8x8 = 0; i8x8 < 4; i8x8++ ) {
+ if( cbp & (1<<i8x8) ) {
+ if( IS_8x8DCT(mb_type) ) {
+ if( decode_cabac_residual(h, h->mb + 64*i8x8, 5, 4*i8x8,
+ scan8x8, h->dequant8_coeff[IS_INTRA( mb_type ) ? 0:1][s->qscale], 64) < 0 )
+ return -1;
+ } else
+ 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
+ if( decode_cabac_residual(h, h->mb + 16*index, 2, index, scan, h->dequant4_coeff[IS_INTRA( mb_type ) ? 0:3][s->qscale], 16) < 0 )
+ return -1;
+//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 );
+ if( decode_cabac_residual(h, h->mb + 256 + 16*4*c, 3, c, chroma_dc_scan, NULL, 4) < 0)
+ return -1;
+ }
+ }
+
+ if( cbp&0x20 ) {
+ int c, i;
+ for( c = 0; c < 2; 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 );
+ if( decode_cabac_residual(h, h->mb + 16*index, 4, index - 16, scan + 1, h->dequant4_coeff[c+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp], 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;
+ 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 ) {
+ int i, d;
+ 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( bS[0] < 4 ) {
+ int8_t tc[4];
+ for(i=0; i<4; i++)
+ tc[i] = bS[i] ? (tc0_table+52)[index_a][bS[i] - 1] : -1;
+ h->s.dsp.h264_h_loop_filter_luma(pix, stride, alpha, beta, tc);
+ } else {
+ /* 16px edge length, because bS=4 is triggered by being at
+ * the edge of an intra MB, so all 4 bS are the same */
+ for( d = 0; d < 16; d++ ) {
+ 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_edgev i:%d d:%d\n# bS:4 -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\n", i, d, p2, p1, p0, q0, q1, q2, pix[-2], pix[-1], pix[0], pix[1]);
+ }
+ pix += stride;
+ }
+ }
+}
+static void filter_mb_edgecv( H264Context *h, uint8_t *pix, int stride, int16_t bS[4], int qp ) {
+ int i;
+ 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( bS[0] < 4 ) {
+ int8_t tc[4];
+ for(i=0; i<4; i++)
+ tc[i] = bS[i] ? (tc0_table+52)[index_a][bS[i] - 1] + 1 : 0;
+ 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] - 1];
+ 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] + 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 ) {
+ int i, d;
+ 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];
+ const int pix_next = stride;
+
+ if( bS[0] < 4 ) {
+ int8_t tc[4];
+ for(i=0; i<4; i++)
+ tc[i] = bS[i] ? (tc0_table+52)[index_a][bS[i] - 1] : -1;
+ h->s.dsp.h264_v_loop_filter_luma(pix, stride, alpha, beta, tc);
+ } else {
+ /* 16px edge length, see filter_mb_edgev */
+ for( d = 0; d < 16; d++ ) {
+ const int p0 = pix[-1*pix_next];
+ const int p1 = pix[-2*pix_next];
+ const int p2 = pix[-3*pix_next];
+ const int q0 = pix[0];
+ const int q1 = pix[1*pix_next];
+ const int q2 = pix[2*pix_next];
+
+ if( FFABS( p0 - q0 ) < alpha &&
+ FFABS( p1 - p0 ) < beta &&
+ FFABS( q1 - q0 ) < beta ) {
+
+ const int p3 = pix[-4*pix_next];
+ const int q3 = pix[ 3*pix_next];
+
+ if(FFABS( p0 - q0 ) < (( alpha >> 2 ) + 2 )){
+ if( FFABS( p2 - p0 ) < beta) {
+ /* p0', p1', p2' */
+ pix[-1*pix_next] = ( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3;
+ pix[-2*pix_next] = ( p2 + p1 + p0 + q0 + 2 ) >> 2;
+ pix[-3*pix_next] = ( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3;
+ } else {
+ /* p0' */
+ pix[-1*pix_next] = ( 2*p1 + p0 + q1 + 2 ) >> 2;
+ }
+ if( FFABS( q2 - q0 ) < beta) {
+ /* q0', q1', q2' */
+ pix[0*pix_next] = ( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3;
+ pix[1*pix_next] = ( p0 + q0 + q1 + q2 + 2 ) >> 2;
+ pix[2*pix_next] = ( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3;
+ } else {
+ /* q0' */
+ pix[0*pix_next] = ( 2*q1 + q0 + p1 + 2 ) >> 2;
+ }
+ }else{
+ /* p0', q0' */
+ pix[-1*pix_next] = ( 2*p1 + p0 + q1 + 2 ) >> 2;
+ pix[ 0*pix_next] = ( 2*q1 + q0 + p1 + 2 ) >> 2;
+ }
+ tprintf(h->s.avctx, "filter_mb_edgeh i:%d d:%d, qp:%d, indexA:%d, alpha:%d, beta:%d\n# bS:%d -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\n", i, d, qp, index_a, alpha, beta, bS[i], p2, p1, p0, q0, q1, q2, pix[-2*pix_next], pix[-pix_next], pix[0], pix[pix_next]);
+ }
+ pix++;
+ }
+ }
+}
+
+static void filter_mb_edgech( H264Context *h, uint8_t *pix, int stride, int16_t bS[4], int qp ) {
+ int i;
+ 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( bS[0] < 4 ) {
+ int8_t tc[4];
+ for(i=0; i<4; i++)
+ tc[i] = bS[i] ? (tc0_table+52)[index_a][bS[i] - 1] + 1 : 0;
+ 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_xy, mb_type;
+ int qp, qp0, qp1, qpc, qpc0, qpc1, qp_thresh;
+
+ if(mb_x==0 || mb_y==0 || !s->dsp.h264_loop_filter_strength) {
+ filter_mb(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize);
+ return;
+ }
+ assert(!FRAME_MBAFF);
+
+ mb_xy = mb_x + mb_y*s->mb_stride;
+ 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->pps.chroma_qp_index_offset, qp );
+ qpc0 = get_chroma_qp( h->pps.chroma_qp_index_offset, qp0 );
+ qpc1 = get_chroma_qp( h->pps.chroma_qp_index_offset, 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};
+ 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, bS4, 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, bS4, 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, bS4, qpc1 );
+ filter_mb_edgech( h, &img_cb[2*2*uvlinesize], uvlinesize, bS3, qpc );
+ filter_mb_edgech( h, &img_cr[2*0*uvlinesize], uvlinesize, bS4, 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 == B_TYPE), edges, step, mask_edge0, mask_edge1 );
+ }
+ 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] = 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 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;
+ int dir;
+ /* FIXME: A given frame may occupy more than one position in
+ * the reference list. So ref2frm should be populated with
+ * frame numbers, not indices. */
+ static const int ref2frm[34] = {-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};
+
+ //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 - FFMAX(0, h->pps.chroma_qp_index_offset);
+ 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)
+ && (mb_y == 0 || ((qp + s->current_picture.qscale_table[h->top_mb_xy] + 1)>>1) <= qp_thresh)){
+ return;
+ }
+ }
+
+ if (FRAME_MBAFF
+ // left mb is in picture
+ && h->slice_table[mb_xy-1] != 255
+ // 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 chroma_qp[2];
+ int mb_qp, mbn0_qp, mbn1_qp;
+ int i;
+ first_vertical_edge_done = 1;
+
+ 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 ||
+ /* FIXME: with 8x8dct + cavlc, should check cbp instead of nnz */
+ h->non_zero_count[mbn_xy][MB_FIELD ? i&3 : (i>>2)+(mb_y&1)*2] )
+ bS[i] = 2;
+ else
+ bS[i] = 1;
+ }
+ }
+
+ 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;
+ chroma_qp[0] = ( get_chroma_qp( h->pps.chroma_qp_index_offset, mb_qp ) +
+ get_chroma_qp( h->pps.chroma_qp_index_offset, mbn0_qp ) + 1 ) >> 1;
+ qp[1] = ( mb_qp + mbn1_qp + 1 ) >> 1;
+ chroma_qp[1] = ( get_chroma_qp( h->pps.chroma_qp_index_offset, mb_qp ) +
+ get_chroma_qp( h->pps.chroma_qp_index_offset, mbn1_qp ) + 1 ) >> 1;
+
+ /* Filter edge */
+ tprintf(s->avctx, "filter mb:%d/%d MBAFF, QPy:%d/%d, QPc:%d/%d ls:%d uvls:%d", mb_x, mb_y, qp[0], qp[1], chroma_qp[0], chroma_qp[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, chroma_qp );
+ filter_mb_mbaff_edgecv( h, &img_cr[0], uvlinesize, bS, chroma_qp );
+ }
+ /* dir : 0 -> vertical edge, 1 -> horizontal edge */
+ for( dir = 0; dir < 2; dir++ )
+ {
+ 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 start = h->slice_table[mbm_xy] == 255 ? 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;
+ first_vertical_edge_done = 0;
+ }
+
+ 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, chroma_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 );
+ chroma_qp = ( h->chroma_qp +
+ get_chroma_qp( h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1;
+ filter_mb_edgech( h, &img_cb[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp );
+ filter_mb_edgech( h, &img_cr[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp );
+ }
+
+ 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];
+ 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 == B_TYPE); l++ ) {
+ v |= ref2frm[h->ref_cache[l][b_idx]+2] != ref2frm[h->ref_cache[l][bn_idx]+2] ||
+ 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[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] != 0 ||
+ h->non_zero_count_cache[bn_idx] != 0 ) {
+ bS[i] = 2;
+ }
+ else if(!mv_done)
+ {
+ bS[i] = 0;
+ for( l = 0; l < 1 + (h->slice_type == B_TYPE); l++ ) {
+ if( ref2frm[h->ref_cache[l][b_idx]+2] != ref2frm[h->ref_cache[l][bn_idx]+2] ||
+ 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(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 ) {
+ int chroma_qp = ( h->chroma_qp +
+ get_chroma_qp( h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1;
+ filter_mb_edgecv( h, &img_cb[2*edge], uvlinesize, bS, chroma_qp );
+ filter_mb_edgecv( h, &img_cr[2*edge], uvlinesize, bS, chroma_qp );
+ }
+ } else {
+ filter_mb_edgeh( h, &img_y[4*edge*linesize], linesize, bS, qp );
+ if( (edge&1) == 0 ) {
+ int chroma_qp = ( h->chroma_qp +
+ get_chroma_qp( h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1;
+ filter_mb_edgech( h, &img_cb[2*edge*uvlinesize], uvlinesize, bS, chroma_qp );
+ filter_mb_edgech( h, &img_cr[2*edge*uvlinesize], uvlinesize, bS, chroma_qp );
+ }
+ }
+ }
+ }
+}
+
+static int decode_slice(H264Context *h){
+ MpegEncContext * const s = &h->s;
+ const int part_mask= s->partitioned_frame ? (AC_END|AC_ERROR) : 0x7F;
+
+ s->mb_skip_run= -1;
+
+ if( h->pps.cabac ) {
+ int i;
+
+ /* realign */
+ align_get_bits( &s->gb );
+
+ /* init cabac */
+ 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 == 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 );
+
+ if( pre <= 63 )
+ h->cabac_state[i] = 2 * ( 63 - pre ) + 0;
+ else
+ h->cabac_state[i] = 2 * ( pre - 64 ) + 1;
+ }
+
+ for(;;){
+//START_TIMER
+ int ret = decode_mb_cabac(h);
+ int eos;
+//STOP_TIMER("decode_mb_cabac")
+
+ if(ret>=0) hl_decode_mb(h);
+
+ if( ret >= 0 && FRAME_MBAFF ) { //FIXME optimal? or let mb_decode decode 16x32 ?
+ s->mb_y++;
+
+ if(ret>=0) ret = decode_mb_cabac(h);
+
+ if(ret>=0) hl_decode_mb(h);
+ s->mb_y--;
+ }
+ eos = get_cabac_terminate( &h->cabac );
+
+ 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 (%d)\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);
+ return -1;
+ }
+
+ if( ++s->mb_x >= s->mb_width ) {
+ s->mb_x = 0;
+ ff_draw_horiz_band(s, 16*s->mb_y, 16);
+ ++s->mb_y;
+ if(FRAME_MBAFF) {
+ ++s->mb_y;
+ }
+ }
+
+ if( eos || s->mb_y >= s->mb_height ) {
+ tprintf(s->avctx, "slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits);
+ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
+ return 0;
+ }
+ }
+
+ } else {
+ for(;;){
+ int ret = decode_mb_cavlc(h);
+
+ if(ret>=0) 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);
+
+ if(ret>=0) hl_decode_mb(h);
+ s->mb_y--;
+ }
+
+ if(ret<0){
+ av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d\n", s->mb_x, s->mb_y);
+ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);
+
+ return -1;
+ }
+
+ if(++s->mb_x >= s->mb_width){
+ s->mb_x=0;
+ ff_draw_horiz_band(s, 16*s->mb_y, 16);
+ ++s->mb_y;
+ if(FRAME_MBAFF) {
+ ++s->mb_y;
+ }
+ if(s->mb_y >= s->mb_height){
+ tprintf(s->avctx, "slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits);
+
+ if(get_bits_count(&s->gb) == s->gb.size_in_bits ) {
+ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
+
+ return 0;
+ }else{
+ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
+
+ return -1;
+ }
+ }
+ }
+
+ if(get_bits_count(&s->gb) >= s->gb.size_in_bits && s->mb_skip_run<=0){
+ tprintf(s->avctx, "slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits);
+ if(get_bits_count(&s->gb) == s->gb.size_in_bits ){
+ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
+
+ return 0;
+ }else{
+ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);
+
+ return -1;
+ }
+ }
+ }
+ }
+
+#if 0
+ for(;s->mb_y < s->mb_height; s->mb_y++){
+ for(;s->mb_x < s->mb_width; s->mb_x++){
+ int ret= decode_mb(h);
+
+ hl_decode_mb(h);
+
+ if(ret<0){
+ av_log(s->avctx, AV_LOG_ERROR, "error while decoding MB %d %d\n", s->mb_x, s->mb_y);
+ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);
+
+ return -1;
+ }
+
+ if(++s->mb_x >= s->mb_width){
+ s->mb_x=0;
+ if(++s->mb_y >= s->mb_height){
+ if(get_bits_count(s->gb) == s->gb.size_in_bits){
+ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
+
+ return 0;
+ }else{
+ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
+
+ return -1;
+ }
+ }
+ }
+
+ if(get_bits_count(s->?gb) >= s->gb?.size_in_bits){
+ if(get_bits_count(s->gb) == s->gb.size_in_bits){
+ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
+
+ return 0;
+ }else{
+ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);
+
+ return -1;
+ }
+ }
+ }
+ s->mb_x=0;
+ ff_draw_horiz_band(s, 16*s->mb_y, 16);
+ }
+#endif
+ return -1; //not reached
+}
+
+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; i<sizeof(user_data)-1 && i<size; i++){
+ user_data[i]= get_bits(&s->gb, 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(; i<size; i++)
+ skip_bits(&s->gb, 8);
+
+ return 0;
+}
+
+static int 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 5:
+ if(decode_unregistered_user_data(h, size) < 0)
+ return -1;
+ break;
+ default:
+ skip_bits(&s->gb, 8*size);
+ }
+
+ //FIXME check bits here
+ align_get_bits(&s->gb);
+ }
+
+ return 0;
+}
+
+static inline void decode_hrd_parameters(H264Context *h, SPS *sps){
+ MpegEncContext * const s = &h->s;
+ int cpb_count, i;
+ cpb_count = get_ue_golomb(&s->gb) + 1;
+ get_bits(&s->gb, 4); /* bit_rate_scale */
+ get_bits(&s->gb, 4); /* cpb_size_scale */
+ for(i=0; i<cpb_count; i++){
+ get_ue_golomb(&s->gb); /* bit_rate_value_minus1 */
+ get_ue_golomb(&s->gb); /* cpb_size_value_minus1 */
+ get_bits1(&s->gb); /* cbr_flag */
+ }
+ get_bits(&s->gb, 5); /* initial_cpb_removal_delay_length_minus1 */
+ get_bits(&s->gb, 5); /* cpb_removal_delay_length_minus1 */
+ get_bits(&s->gb, 5); /* dpb_output_delay_length_minus1 */
+ get_bits(&s->gb, 5); /* time_offset_length */
+}
+
+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;
+ int nal_hrd_parameters_present_flag, vcl_hrd_parameters_present_flag;
+
+ 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 < 14){
+ 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 */
+ get_ue_golomb(&s->gb); /* 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);
+ }
+
+ nal_hrd_parameters_present_flag = get_bits1(&s->gb);
+ if(nal_hrd_parameters_present_flag)
+ decode_hrd_parameters(h, sps);
+ vcl_hrd_parameters_present_flag = get_bits1(&s->gb);
+ if(vcl_hrd_parameters_present_flag)
+ decode_hrd_parameters(h, sps);
+ if(nal_hrd_parameters_present_flag || vcl_hrd_parameters_present_flag)
+ get_bits1(&s->gb); /* low_delay_hrd_flag */
+ get_bits1(&s->gb); /* pic_struct_present_flag */
+
+ sps->bitstream_restriction_flag = get_bits1(&s->gb);
+ if(sps->bitstream_restriction_flag){
+ unsigned int num_reorder_frames;
+ 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 */
+ num_reorder_frames= get_ue_golomb(&s->gb);
+ get_ue_golomb(&s->gb); /*max_dec_frame_buffering*/
+
+ if(num_reorder_frames > 16 /*max_dec_frame_buffering || max_dec_frame_buffering > 16*/){
+ av_log(h->s.avctx, AV_LOG_ERROR, "illegal num_reorder_frames %d\n", num_reorder_frames);
+ return -1;
+ }
+
+ sps->num_reorder_frames= num_reorder_frames;
+ }
+
+ 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 : zigzag_scan8x8;
+ 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;i<size;i++){
+ if(next)
+ next = (last + get_se_golomb(&s->gb)) & 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
+ }
+ } else if(fallback_sps) {
+ memcpy(scaling_matrix4, sps->scaling_matrix4, 6*16*sizeof(uint8_t));
+ memcpy(scaling_matrix8, sps->scaling_matrix8, 2*64*sizeof(uint8_t));
+ }
+}
+
+static inline int decode_seq_parameter_set(H264Context *h){
+ MpegEncContext * const s = &h->s;
+ int profile_idc, level_idc;
+ unsigned int sps_id, tmp, mb_width, mb_height;
+ 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(&s->gb);
+
+ if (sps_id >= MAX_SPS_COUNT){
+ // ok it has gone out of hand, someone is sending us bad stuff.
+ av_log(h->s.avctx, AV_LOG_ERROR, "illegal sps_id (%d)\n", sps_id);
+ return -1;
+ }
+
+ sps= &h->sps_buffer[ sps_id ];
+ sps->profile_idc= profile_idc;
+ sps->level_idc= level_idc;
+
+ if(sps->profile_idc >= 100){ //high profile
+ if(get_ue_golomb(&s->gb) == 3) //chroma_format_idc
+ get_bits1(&s->gb); //residual_color_transform_flag
+ get_ue_golomb(&s->gb); //bit_depth_luma_minus8
+ get_ue_golomb(&s->gb); //bit_depth_chroma_minus8
+ sps->transform_bypass = get_bits1(&s->gb);
+ decode_scaling_matrices(h, sps, NULL, 1, sps->scaling_matrix4, sps->scaling_matrix8);
+ }else
+ sps->scaling_matrix_present = 0;
+
+ sps->log2_max_frame_num= get_ue_golomb(&s->gb) + 4;
+ sps->poc_type= get_ue_golomb(&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);
+ tmp= get_ue_golomb(&s->gb);
+
+ if(tmp >= sizeof(sps->offset_for_ref_frame) / sizeof(sps->offset_for_ref_frame[0])){
+ av_log(h->s.avctx, AV_LOG_ERROR, "poc_cycle_length overflow %u\n", tmp);
+ return -1;
+ }
+ sps->poc_cycle_length= tmp;
+
+ for(i=0; i<sps->poc_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);
+ return -1;
+ }
+
+ tmp= get_ue_golomb(&s->gb);
+ if(tmp > MAX_PICTURE_COUNT-2){
+ av_log(h->s.avctx, AV_LOG_ERROR, "too many reference frames\n");
+ }
+ sps->ref_frame_count= tmp;
+ sps->gaps_in_frame_num_allowed_flag= get_bits1(&s->gb);
+ mb_width= get_ue_golomb(&s->gb) + 1;
+ mb_height= get_ue_golomb(&s->gb) + 1;
+ if(mb_width >= INT_MAX/16 || mb_height >= INT_MAX/16 ||
+ avcodec_check_dimensions(NULL, 16*mb_width, 16*mb_height)){
+ av_log(h->s.avctx, AV_LOG_ERROR, "mb_width/height overflow\n");
+ return -1;
+ }
+ sps->mb_width = mb_width;
+ sps->mb_height= mb_height;
+
+ 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
+ if(!sps->direct_8x8_inference_flag && sps->mb_aff)
+ av_log(h->s.avctx, AV_LOG_ERROR, "MBAFF + !direct_8x8_inference is not implemented\n");
+
+ 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");
+ }
+ }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 )
+ decode_vui_parameters(h, sps);
+
+ 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\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" : ""
+ );
+ }
+ return 0;
+}
+
+static inline int decode_picture_parameter_set(H264Context *h, int bit_length){
+ MpegEncContext * const s = &h->s;
+ unsigned int tmp, 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 out of range\n");
+ return -1;
+ }
+ pps = &h->pps_buffer[pps_id];
+
+ tmp= get_ue_golomb(&s->gb);
+ if(tmp>=MAX_SPS_COUNT){
+ av_log(h->s.avctx, AV_LOG_ERROR, "sps_id out of range\n");
+ return -1;
+ }
+ pps->sps_id= tmp;
+
+ 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");
+ pps->ref_count[0]= pps->ref_count[1]= 1;
+ return -1;
+ }
+
+ 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= 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
+ memset(pps->scaling_matrix4, 16, 6*16*sizeof(uint8_t));
+ memset(pps->scaling_matrix8, 16, 2*64*sizeof(uint8_t));
+
+ if(get_bits_count(&s->gb) < bit_length){
+ pps->transform_8x8_mode= get_bits1(&s->gb);
+ decode_scaling_matrices(h, &h->sps_buffer[pps->sps_id], pps, 0, pps->scaling_matrix4, pps->scaling_matrix8);
+ get_se_golomb(&s->gb); //second_chroma_qp_index_offset
+ }
+
+ 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 %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,
+ pps->deblocking_filter_parameters_present ? "LPAR" : "",
+ pps->constrained_intra_pred ? "CONSTR" : "",
+ pps->redundant_pic_cnt_present ? "REDU" : "",
+ pps->transform_8x8_mode ? "8x8DCT" : ""
+ );
+ }
+
+ return 0;
+}
+
+/**
+ * finds the end of the current frame in the bitstream.
+ * @return the position of the first byte of the next frame, or -1
+ */
+static int find_frame_end(H264Context *h, const uint8_t *buf, int buf_size){
+ int i;
+ uint32_t state;
+ ParseContext *pc = &(h->s.parse_context);
+//printf("first %02X%02X%02X%02X\n", buf[0], buf[1],buf[2],buf[3]);
+// mb_addr= pc->mb_addr - 1;
+ state= pc->state;
+ if(state>13)
+ state= 7;
+
+ for(i=0; i<buf_size; i++){
+ if(state==7){
+ for(; i<buf_size; i++){
+ if(!buf[i]){
+ state=2;
+ break;
+ }
+ }
+ }else if(state<=2){
+ if(buf[i]==1) state^= 5; //2->7, 1->4, 0->5
+ else if(buf[i]) state = 7;
+ else state>>=1; //2->1, 1->0, 0->0
+ }else if(state<=5){
+ int v= buf[i] & 0x1F;
+ if(v==7 || v==8 || v==9){
+ if(pc->frame_start_found){
+ i++;
+found:
+ pc->state=7;
+ pc->frame_start_found= 0;
+ return i-(state&5);
+ }
+ }else if(v==1 || v==2 || v==5){
+ if(pc->frame_start_found){
+ state+=8;
+ continue;
+ }else
+ pc->frame_start_found = 1;
+ }
+ state= 7;
+ }else{
+ if(buf[i] & 0x80)
+ goto found;
+ state= 7;
+ }
+ }
+ pc->state= state;
+ return END_NOT_FOUND;
+}
+
+#ifdef CONFIG_H264_PARSER
+static int h264_parse(AVCodecParserContext *s,
+ AVCodecContext *avctx,
+ uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size)
+{
+ H264Context *h = s->priv_data;
+ ParseContext *pc = &h->s.parse_context;
+ int next;
+
+ if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){
+ next= buf_size;
+ }else{
+ next= find_frame_end(h, buf, buf_size);
+
+ if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
+ *poutbuf = NULL;
+ *poutbuf_size = 0;
+ return buf_size;
+ }
+
+ if(next<0){
+ find_frame_end(h, &pc->buffer[pc->last_index + next], -next); //update state
+ }
+ }
+
+ *poutbuf = (uint8_t *)buf;
+ *poutbuf_size = buf_size;
+ return next;
+}
+
+static int h264_split(AVCodecContext *avctx,
+ const uint8_t *buf, int buf_size)
+{
+ int i;
+ uint32_t state = -1;
+ int has_sps= 0;
+
+ for(i=0; i<=buf_size; i++){
+ if((state&0xFFFFFF1F) == 0x107)
+ has_sps=1;
+/* if((state&0xFFFFFF1F) == 0x101 || (state&0xFFFFFF1F) == 0x102 || (state&0xFFFFFF1F) == 0x105){
+ }*/
+ if((state&0xFFFFFF00) == 0x100 && (state&0xFFFFFF1F) != 0x107 && (state&0xFFFFFF1F) != 0x108 && (state&0xFFFFFF1F) != 0x109){
+ if(has_sps){
+ while(i>4 && buf[i-5]==0) i--;
+ return i-4;
+ }
+ }
+ if (i<buf_size)
+ state= (state<<8) | buf[i];
+ }
+ return 0;
+}
+#endif /* CONFIG_H264_PARSER */
+
+static int decode_nal_units(H264Context *h, uint8_t *buf, int buf_size){
+ MpegEncContext * const s = &h->s;
+ AVCodecContext * const avctx= s->avctx;
+ int buf_index=0;
+#if 0
+ int i;
+ for(i=0; i<50; i++){
+ av_log(NULL, AV_LOG_ERROR,"%02X ", buf[i]);
+ }
+#endif
+ if(!(s->flags2 & CODEC_FLAG2_CHUNKS)){
+ h->slice_num = 0;
+ s->current_picture_ptr= NULL;
+ }
+
+ for(;;){
+ int consumed;
+ int dst_length;
+ int bit_length;
+ uint8_t *ptr;
+ int i, nalsize = 0;
+
+ if(h->is_avc) {
+ if(buf_index >= buf_size) break;
+ nalsize = 0;
+ for(i = 0; i < h->nal_length_size; i++)
+ nalsize = (nalsize << 8) | buf[buf_index++];
+ if(nalsize <= 1 || nalsize > buf_size){
+ if(nalsize == 1){
+ buf_index++;
+ continue;
+ }else{
+ av_log(h->s.avctx, AV_LOG_ERROR, "AVC: nal size %d\n", nalsize);
+ break;
+ }
+ }
+ } else {
+ // start code prefix search
+ for(; buf_index + 3 < buf_size; buf_index++){
+ // this should allways succeed in the first iteration
+ if(buf[buf_index] == 0 && buf[buf_index+1] == 0 && buf[buf_index+2] == 1)
+ break;
+ }
+
+ if(buf_index+3 >= buf_size) break;
+
+ buf_index+=3;
+ }
+
+ ptr= decode_nal(h, buf + buf_index, &dst_length, &consumed, h->is_avc ? nalsize : buf_size - buf_index);
+ if (ptr==NULL || dst_length <= 0){
+ return -1;
+ }
+ while(ptr[dst_length - 1] == 0 && dst_length > 1)
+ dst_length--;
+ bit_length= 8*dst_length - decode_rbsp_trailing(h, ptr + dst_length - 1);
+
+ if(s->avctx->debug&FF_DEBUG_STARTCODE){
+ av_log(h->s.avctx, AV_LOG_DEBUG, "NAL %d at %d/%d length %d\n", h->nal_unit_type, buf_index, buf_size, dst_length);
+ }
+
+ if (h->is_avc && (nalsize != consumed))
+ av_log(h->s.avctx, AV_LOG_ERROR, "AVC: Consumed only %d bytes instead of %d\n", consumed, nalsize);
+
+ buf_index += consumed;
+
+ if( (s->hurry_up == 1 && h->nal_ref_idc == 0) //FIXME dont discard SEI id
+ ||(avctx->skip_frame >= AVDISCARD_NONREF && h->nal_ref_idc == 0))
+ continue;
+
+ switch(h->nal_unit_type){
+ case NAL_IDR_SLICE:
+ idr(h); //FIXME ensure we don't loose some frames if there is reordering
+ case NAL_SLICE:
+ init_get_bits(&s->gb, ptr, bit_length);
+ h->intra_gb_ptr=
+ h->inter_gb_ptr= &s->gb;
+ s->data_partitioning = 0;
+
+ if(decode_slice_header(h) < 0){
+ av_log(h->s.avctx, AV_LOG_ERROR, "decode_slice_header error\n");
+ break;
+ }
+ s->current_picture_ptr->key_frame= (h->nal_unit_type == NAL_IDR_SLICE);
+ if(h->redundant_pic_count==0 && s->hurry_up < 5
+ && (avctx->skip_frame < AVDISCARD_NONREF || h->nal_ref_idc)
+ && (avctx->skip_frame < AVDISCARD_BIDIR || h->slice_type!=B_TYPE)
+ && (avctx->skip_frame < AVDISCARD_NONKEY || h->slice_type==I_TYPE)
+ && avctx->skip_frame < AVDISCARD_ALL)
+ decode_slice(h);
+ break;
+ case NAL_DPA:
+ init_get_bits(&s->gb, ptr, bit_length);
+ h->intra_gb_ptr=
+ h->inter_gb_ptr= NULL;
+ s->data_partitioning = 1;
+
+ if(decode_slice_header(h) < 0){
+ av_log(h->s.avctx, AV_LOG_ERROR, "decode_slice_header error\n");
+ }
+ break;
+ case NAL_DPB:
+ init_get_bits(&h->intra_gb, ptr, bit_length);
+ h->intra_gb_ptr= &h->intra_gb;
+ break;
+ case NAL_DPC:
+ init_get_bits(&h->inter_gb, ptr, bit_length);
+ h->inter_gb_ptr= &h->inter_gb;
+
+ if(h->redundant_pic_count==0 && h->intra_gb_ptr && s->data_partitioning
+ && s->context_initialized
+ && s->hurry_up < 5
+ && (avctx->skip_frame < AVDISCARD_NONREF || h->nal_ref_idc)
+ && (avctx->skip_frame < AVDISCARD_BIDIR || h->slice_type!=B_TYPE)
+ && (avctx->skip_frame < AVDISCARD_NONKEY || h->slice_type==I_TYPE)
+ && avctx->skip_frame < AVDISCARD_ALL)
+ decode_slice(h);
+ break;
+ case NAL_SEI:
+ init_get_bits(&s->gb, ptr, bit_length);
+ decode_sei(h);
+ break;
+ case NAL_SPS:
+ init_get_bits(&s->gb, ptr, bit_length);
+ decode_seq_parameter_set(h);
+
+ if(s->flags& CODEC_FLAG_LOW_DELAY)
+ s->low_delay=1;
+
+ if(avctx->has_b_frames < 2)
+ avctx->has_b_frames= !s->low_delay;
+ break;
+ case NAL_PPS:
+ init_get_bits(&s->gb, ptr, bit_length);
+
+ decode_picture_parameter_set(h, bit_length);
+
+ break;
+ case NAL_AUD:
+ case NAL_END_SEQUENCE:
+ case NAL_END_STREAM:
+ case NAL_FILLER_DATA:
+ case NAL_SPS_EXT:
+ case NAL_AUXILIARY_SLICE:
+ break;
+ default:
+ av_log(avctx, AV_LOG_ERROR, "Unknown NAL code: %d\n", h->nal_unit_type);
+ }
+ }
+
+ return buf_index;
+}
+
+/**
+ * returns the number of bytes consumed for building the current frame
+ */
+static int get_consumed_bytes(MpegEncContext *s, int pos, int buf_size){
+ if(s->flags&CODEC_FLAG_TRUNCATED){
+ pos -= s->parse_context.last_index;
+ if(pos<0) pos=0; // FIXME remove (unneeded?)
+
+ return pos;
+ }else{
+ if(pos==0) pos=1; //avoid infinite loops (i doubt thats needed but ...)
+ if(pos+10>buf_size) pos=buf_size; // oops ;)
+
+ return pos;
+ }
+}
+
+static int decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ H264Context *h = avctx->priv_data;
+ MpegEncContext *s = &h->s;
+ AVFrame *pict = data;
+ int buf_index;
+
+ s->flags= avctx->flags;
+ s->flags2= avctx->flags2;
+
+ /* no supplementary picture */
+ if (buf_size == 0) {
+ Picture *out;
+ int i, out_idx;
+
+//FIXME factorize this with the output code below
+ out = h->delayed_pic[0];
+ out_idx = 0;
+ for(i=1; h->delayed_pic[i] && !h->delayed_pic[i]->key_frame; i++)
+ if(h->delayed_pic[i]->poc < out->poc){
+ out = h->delayed_pic[i];
+ out_idx = i;
+ }
+
+ for(i=out_idx; h->delayed_pic[i]; i++)
+ h->delayed_pic[i] = h->delayed_pic[i+1];
+
+ if(out){
+ *data_size = sizeof(AVFrame);
+ *pict= *(AVFrame*)out;
+ }
+
+ return 0;
+ }
+
+ if(s->flags&CODEC_FLAG_TRUNCATED){
+ int next= find_frame_end(h, buf, buf_size);
+
+ if( ff_combine_frame(&s->parse_context, next, &buf, &buf_size) < 0 )
+ return buf_size;
+//printf("next:%d buf_size:%d last_index:%d\n", next, buf_size, s->parse_context.last_index);
+ }
+
+ 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(avctx->frame_number==0 && !h->is_avc && s->avctx->extradata_size){
+ if(decode_nal_units(h, s->avctx->extradata, s->avctx->extradata_size) < 0)
+ return -1;
+ }
+
+ buf_index=decode_nal_units(h, buf, buf_size);
+ if(buf_index < 0)
+ return -1;
+
+ if(!(s->flags2 & CODEC_FLAG2_CHUNKS) && !s->current_picture_ptr){
+ av_log(avctx, AV_LOG_ERROR, "no frame!\n");
+ return -1;
+ }
+
+ 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;
+ Picture *prev = h->delayed_output_pic;
+ int i, pics, cross_idr, out_of_order, out_idx;
+
+ s->mb_y= 0;
+
+ s->current_picture_ptr->qscale_type= FF_QSCALE_TYPE_H264;
+ s->current_picture_ptr->pict_type= s->pict_type;
+
+ h->prev_frame_num_offset= h->frame_num_offset;
+ h->prev_frame_num= h->frame_num;
+ if(s->current_picture_ptr->reference){
+ h->prev_poc_msb= h->poc_msb;
+ h->prev_poc_lsb= h->poc_lsb;
+ }
+ if(s->current_picture_ptr->reference)
+ execute_ref_pic_marking(h, h->mmco, h->mmco_index);
+
+ ff_er_frame_end(s);
+
+ MPV_frame_end(s);
+
+ //FIXME do something with unavailable reference frames
+
+#if 0 //decode order
+ *data_size = sizeof(AVFrame);
+#else
+ /* Sort B-frames into display order */
+
+ 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;
+ }
+
+ pics = 0;
+ while(h->delayed_pic[pics]) pics++;
+
+ assert(pics+1 < sizeof(h->delayed_pic) / sizeof(h->delayed_pic[0]));
+
+ h->delayed_pic[pics++] = cur;
+ if(cur->reference == 0)
+ cur->reference = 1;
+
+ cross_idr = 0;
+ for(i=0; h->delayed_pic[i]; i++)
+ if(h->delayed_pic[i]->key_frame || h->delayed_pic[i]->poc==0)
+ cross_idr = 1;
+
+ out = h->delayed_pic[0];
+ out_idx = 0;
+ for(i=1; h->delayed_pic[i] && !h->delayed_pic[i]->key_frame; i++)
+ if(h->delayed_pic[i]->poc < out->poc){
+ out = h->delayed_pic[i];
+ out_idx = i;
+ }
+
+ out_of_order = !cross_idr && prev && out->poc < prev->poc;
+ if(h->sps.bitstream_restriction_flag && s->avctx->has_b_frames >= h->sps.num_reorder_frames)
+ { }
+ else if(prev && pics <= s->avctx->has_b_frames)
+ out = prev;
+ else if((out_of_order && pics-1 == s->avctx->has_b_frames && pics < 15)
+ || (s->low_delay &&
+ ((!cross_idr && prev && out->poc > prev->poc + 2)
+ || cur->pict_type == B_TYPE)))
+ {
+ s->low_delay = 0;
+ s->avctx->has_b_frames++;
+ out = prev;
+ }
+ else if(out_of_order)
+ out = prev;
+
+ if(out_of_order || pics > s->avctx->has_b_frames){
+ for(i=out_idx; h->delayed_pic[i]; i++)
+ h->delayed_pic[i] = h->delayed_pic[i+1];
+ }
+
+ if(prev == out)
+ *data_size = 0;
+ else
+ *data_size = sizeof(AVFrame);
+ if(prev && prev != out && prev->reference == 1)
+ prev->reference = 0;
+ h->delayed_output_pic = out;
+#endif
+
+ if(out)
+ *pict= *(AVFrame*)out;
+ else
+ av_log(avctx, AV_LOG_DEBUG, "no picture\n");
+ }
+
+ assert(pict->data[0] || !*data_size);
+ ff_print_debug_info(s, pict);
+//printf("out %d\n", (int)pict->data[0]);
+#if 0 //?
+
+ /* Return the Picture timestamp as the frame number */
+ /* we substract 1 because it is added on utils.c */
+ avctx->frame_number = s->picture_number - 1;
+#endif
+ return get_consumed_bytes(s, buf_index, buf_size);
+}
+#if 0
+static inline void fill_mb_avail(H264Context *h){
+ MpegEncContext * const s = &h->s;
+ const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
+
+ if(s->mb_y){
+ h->mb_avail[0]= s->mb_x && h->slice_table[mb_xy - s->mb_stride - 1] == h->slice_num;
+ h->mb_avail[1]= h->slice_table[mb_xy - s->mb_stride ] == h->slice_num;
+ h->mb_avail[2]= s->mb_x+1 < s->mb_width && h->slice_table[mb_xy - s->mb_stride + 1] == h->slice_num;
+ }else{
+ h->mb_avail[0]=
+ h->mb_avail[1]=
+ h->mb_avail[2]= 0;
+ }
+ h->mb_avail[3]= s->mb_x && h->slice_table[mb_xy - 1] == h->slice_num;
+ h->mb_avail[4]= 1; //FIXME move out
+ h->mb_avail[5]= 0; //FIXME move out
+}
+#endif
+
+#if 0 //selftest
+#define COUNT 8000
+#define SIZE (COUNT*40)
+int main(){
+ int i;
+ uint8_t temp[SIZE];
+ PutBitContext pb;
+ GetBitContext gb;
+// int int_temp[10000];
+ DSPContext dsp;
+ AVCodecContext avctx;
+
+ dsputil_init(&dsp, &avctx);
+
+ init_put_bits(&pb, temp, SIZE);
+ printf("testing unsigned exp golomb\n");
+ for(i=0; i<COUNT; i++){
+ START_TIMER
+ set_ue_golomb(&pb, i);
+ STOP_TIMER("set_ue_golomb");
+ }
+ flush_put_bits(&pb);
+
+ init_get_bits(&gb, temp, 8*SIZE);
+ for(i=0; i<COUNT; i++){
+ int j, s;
+
+ s= show_bits(&gb, 24);
+
+ START_TIMER
+ j= get_ue_golomb(&gb);
+ if(j != i){
+ printf("missmatch! at %d (%d should be %d) bits:%6X\n", i, j, i, s);
+// return -1;
+ }
+ STOP_TIMER("get_ue_golomb");
+ }
+
+
+ init_put_bits(&pb, temp, SIZE);
+ printf("testing signed exp golomb\n");
+ for(i=0; i<COUNT; i++){
+ START_TIMER
+ set_se_golomb(&pb, i - COUNT/2);
+ STOP_TIMER("set_se_golomb");
+ }
+ flush_put_bits(&pb);
+
+ init_get_bits(&gb, temp, 8*SIZE);
+ for(i=0; i<COUNT; i++){
+ int j, s;
+
+ s= show_bits(&gb, 24);
+
+ START_TIMER
+ j= get_se_golomb(&gb);
+ if(j != i - COUNT/2){
+ printf("missmatch! at %d (%d should be %d) bits:%6X\n", i, j, i, s);
+// return -1;
+ }
+ STOP_TIMER("get_se_golomb");
+ }
+
+ printf("testing 4x4 (I)DCT\n");
+
+ DCTELEM block[16];
+ uint8_t src[16], ref[16];
+ uint64_t error= 0, max_error=0;
+
+ for(i=0; i<COUNT; i++){
+ int j;
+// printf("%d %d %d\n", r1, r2, (r2-r1)*16);
+ for(j=0; j<16; j++){
+ ref[j]= random()%255;
+ src[j]= random()%255;
+ }
+
+ h264_diff_dct_c(block, src, ref, 4);
+
+ //normalize
+ for(j=0; j<16; j++){
+// printf("%d ", block[j]);
+ block[j]= block[j]*4;
+ if(j&1) block[j]= (block[j]*4 + 2)/5;
+ if(j&4) block[j]= (block[j]*4 + 2)/5;
+ }
+// printf("\n");
+
+ s->dsp.h264_idct_add(ref, block, 4);
+/* for(j=0; j<16; j++){
+ printf("%d ", ref[j]);
+ }
+ printf("\n");*/
+
+ for(j=0; j<16; j++){
+ int diff= FFABS(src[j] - ref[j]);
+
+ error+= diff*diff;
+ max_error= FFMAX(max_error, diff);
+ }
+ }
+ printf("error=%f max_error=%d\n", ((float)error)/COUNT/16, (int)max_error );
+#if 0
+ printf("testing quantizer\n");
+ for(qp=0; qp<52; qp++){
+ for(i=0; i<16; i++)
+ src1_block[i]= src2_block[i]= random()%255;
+
+ }
+#endif
+ printf("Testing NAL layer\n");
+
+ uint8_t bitstream[COUNT];
+ uint8_t nal[COUNT*2];
+ H264Context h;
+ memset(&h, 0, sizeof(H264Context));
+
+ for(i=0; i<COUNT; i++){
+ int zeros= i;
+ int nal_length;
+ int consumed;
+ int out_length;
+ uint8_t *out;
+ int j;
+
+ for(j=0; j<COUNT; j++){
+ bitstream[j]= (random() % 255) + 1;
+ }
+
+ for(j=0; j<zeros; j++){
+ int pos= random() % COUNT;
+ while(bitstream[pos] == 0){
+ pos++;
+ pos %= COUNT;
+ }
+ bitstream[pos]=0;
+ }
+
+ START_TIMER
+
+ nal_length= encode_nal(&h, nal, bitstream, COUNT, COUNT*2);
+ if(nal_length<0){
+ printf("encoding failed\n");
+ return -1;
+ }
+
+ out= decode_nal(&h, nal, &out_length, &consumed, nal_length);
+
+ STOP_TIMER("NAL")
+
+ if(out_length != COUNT){
+ printf("incorrect length %d %d\n", out_length, COUNT);
+ return -1;
+ }
+
+ if(consumed != nal_length){
+ printf("incorrect consumed length %d %d\n", nal_length, consumed);
+ return -1;
+ }
+
+ if(memcmp(bitstream, out, COUNT)){
+ printf("missmatch\n");
+ return -1;
+ }
+ }
+
+ printf("Testing RBSP\n");
+
+
+ return 0;
+}
+#endif
+
+
+static int decode_end(AVCodecContext *avctx)
+{
+ H264Context *h = avctx->priv_data;
+ MpegEncContext *s = &h->s;
+
+ av_freep(&h->rbsp_buffer);
+ free_tables(h); //FIXME cleanup init stuff perhaps
+ MPV_common_end(s);
+
+// memset(h, 0, sizeof(H264Context));
+
+ return 0;
+}
+
+
+AVCodec h264_decoder = {
+ "h264",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_H264,
+ sizeof(H264Context),
+ decode_init,
+ NULL,
+ decode_end,
+ decode_frame,
+ /*CODEC_CAP_DRAW_HORIZ_BAND |*/ CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY,
+ .flush= flush_dpb,
+};
+
+#ifdef CONFIG_H264_PARSER
+AVCodecParser h264_parser = {
+ { CODEC_ID_H264 },
+ sizeof(H264Context),
+ NULL,
+ h264_parse,
+ ff_parse_close,
+ h264_split,
+};
+#endif
+
+#include "svq3.c"
diff --git a/src/libffmpeg/libavcodec/h264data.h b/contrib/ffmpeg/libavcodec/h264data.h
index 74e720421..74e720421 100644
--- a/src/libffmpeg/libavcodec/h264data.h
+++ b/contrib/ffmpeg/libavcodec/h264data.h
diff --git a/contrib/ffmpeg/libavcodec/h264dsp.c b/contrib/ffmpeg/libavcodec/h264dsp.c
new file mode 100644
index 000000000..4f18afac4
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/h264dsp.c
@@ -0,0 +1,81 @@
+/*
+ * H.264/MPEG-4 Part 10 (Base profile) encoder.
+ *
+ * DSP functions
+ *
+ * Copyright (c) 2006 Expertisecentrum Digitale Media, UHasselt
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 h264dsp.c
+ * H.264 encoder related DSP utils
+ *
+ */
+
+#include "dsputil.h"
+
+extern const uint8_t ff_div6[52];
+extern const uint8_t ff_rem6[52];
+
+#define H264_DCT_PART1(X) \
+ a = block[0][X]+block[3][X]; \
+ c = block[0][X]-block[3][X]; \
+ b = block[1][X]+block[2][X]; \
+ d = block[1][X]-block[2][X]; \
+ pieces[0][X] = a+b; \
+ pieces[2][X] = a-b; \
+ pieces[1][X] = (c<<1)+d; \
+ pieces[3][X] = c-(d<<1);
+
+#define H264_DCT_PART2(X) \
+ a = pieces[X][0]+pieces[X][3]; \
+ c = pieces[X][0]-pieces[X][3]; \
+ b = pieces[X][1]+pieces[X][2]; \
+ d = pieces[X][1]-pieces[X][2]; \
+ block[0][X] = a+b; \
+ block[2][X] = a-b; \
+ block[1][X] = (c<<1)+d; \
+ block[3][X] = c-(d<<1);
+
+/**
+ * Transform the provided matrix using the H.264 modified DCT.
+ * @note
+ * we'll always work with transposed input blocks, to avoid having to make a
+ * distinction between C and mmx implementations.
+ *
+ * @param block transposed input block
+ */
+static void h264_dct_c(DCTELEM block[4][4])
+{
+ DCTELEM pieces[4][4];
+ DCTELEM a, b, c, d;
+
+ H264_DCT_PART1(0);
+ H264_DCT_PART1(1);
+ H264_DCT_PART1(2);
+ H264_DCT_PART1(3);
+ H264_DCT_PART2(0);
+ H264_DCT_PART2(1);
+ H264_DCT_PART2(2);
+ H264_DCT_PART2(3);
+}
+
+void ff_h264dsp_init(DSPContext* c, AVCodecContext *avctx)
+{
+ c->h264_dct = h264_dct_c;
+}
+
diff --git a/contrib/ffmpeg/libavcodec/h264enc.c b/contrib/ffmpeg/libavcodec/h264enc.c
new file mode 100644
index 000000000..15e182302
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/h264enc.c
@@ -0,0 +1,107 @@
+/*
+ * H.264 encoder
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 "common.h"
+#include "bitstream.h"
+#include "mpegvideo.h"
+#include "h264data.h"
+
+/**
+ * Write out the provided data into a NAL unit.
+ * @param nal_ref_idc NAL reference IDC
+ * @param nal_unit_type NAL unit payload type
+ * @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 occured
+ */
+static uint8_t *h264_write_nal_unit(int nal_ref_idc, int nal_unit_type, uint8_t *dest, int *destsize,
+ PutBitContext *b2)
+{
+ PutBitContext b;
+ int i, destpos, rbsplen, escape_count;
+ uint8_t *rbsp;
+
+ if (nal_unit_type != NAL_END_STREAM)
+ put_bits(b2,1,1); // rbsp_stop_bit
+
+ // Align b2 on a byte boundary
+ align_put_bits(b2);
+ rbsplen = put_bits_count(b2)/8;
+ flush_put_bits(b2);
+ rbsp = b2->buf;
+
+ init_put_bits(&b,dest,*destsize);
+
+ put_bits(&b,16,0);
+ put_bits(&b,16,0x01);
+
+ put_bits(&b,1,0); // forbidden zero bit
+ put_bits(&b,2,nal_ref_idc); // nal_ref_idc
+ put_bits(&b,5,nal_unit_type); // nal_unit_type
+
+ flush_put_bits(&b);
+
+ destpos = 5;
+ escape_count= 0;
+
+ for (i=0; i<rbsplen; i+=2)
+ {
+ if (rbsp[i]) continue;
+ if (i>0 && rbsp[i-1]==0)
+ i--;
+ if (i+2<rbsplen && rbsp[i+1]==0 && rbsp[i+2]<=3)
+ {
+ escape_count++;
+ i+=2;
+ }
+ }
+
+ if(escape_count==0)
+ {
+ if(dest+destpos != rbsp)
+ {
+ memcpy(dest+destpos, rbsp, rbsplen);
+ *destsize -= (rbsplen+destpos);
+ }
+ return dest+rbsplen+destpos;
+ }
+
+ if(rbsplen + escape_count + 1> *destsize)
+ {
+ av_log(NULL, AV_LOG_ERROR, "Destination buffer too small!\n");
+ return NULL;
+ }
+
+ // this should be damn rare (hopefully)
+ for (i = 0 ; i < rbsplen ; i++)
+ {
+ if (i + 2 < rbsplen && (rbsp[i] == 0 && rbsp[i+1] == 0 && rbsp[i+2] < 4))
+ {
+ dest[destpos++] = rbsp[i++];
+ dest[destpos++] = rbsp[i];
+ dest[destpos++] = 0x03; // emulation prevention byte
+ }
+ else
+ dest[destpos++] = rbsp[i];
+ }
+ *destsize -= destpos;
+ return dest+destpos;
+}
+
diff --git a/src/libffmpeg/libavcodec/h264idct.c b/contrib/ffmpeg/libavcodec/h264idct.c
index a6a56d33a..a6a56d33a 100644
--- a/src/libffmpeg/libavcodec/h264idct.c
+++ b/contrib/ffmpeg/libavcodec/h264idct.c
diff --git a/contrib/ffmpeg/libavcodec/huffyuv.c b/contrib/ffmpeg/libavcodec/huffyuv.c
new file mode 100644
index 000000000..f68d8e7ef
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/huffyuv.c
@@ -0,0 +1,1390 @@
+/*
+ * huffyuv codec for libavcodec
+ *
+ * Copyright (c) 2002-2003 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * see http://www.pcisys.net/~melanson/codecs/huffyuv.txt for a description of
+ * the algorithm used
+ */
+
+/**
+ * @file huffyuv.c
+ * huffyuv codec for libavcodec.
+ */
+
+#include "common.h"
+#include "bitstream.h"
+#include "avcodec.h"
+#include "dsputil.h"
+
+#define VLC_BITS 11
+
+#ifdef WORDS_BIGENDIAN
+#define B 3
+#define G 2
+#define R 1
+#else
+#define B 0
+#define G 1
+#define R 2
+#endif
+
+typedef enum Predictor{
+ LEFT= 0,
+ PLANE,
+ MEDIAN,
+} Predictor;
+
+typedef struct HYuvContext{
+ AVCodecContext *avctx;
+ Predictor predictor;
+ GetBitContext gb;
+ PutBitContext pb;
+ int interlaced;
+ int decorrelate;
+ int bitstream_bpp;
+ int version;
+ int yuy2; //use yuy2 instead of 422P
+ int bgr32; //use bgr32 instead of bgr24
+ int width, height;
+ int flags;
+ int context;
+ int picture_number;
+ int last_slice_end;
+ uint8_t *temp[3];
+ uint64_t stats[3][256];
+ uint8_t len[3][256];
+ uint32_t bits[3][256];
+ VLC vlc[3];
+ AVFrame picture;
+ uint8_t *bitstream_buffer;
+ unsigned int bitstream_buffer_size;
+ DSPContext dsp;
+}HYuvContext;
+
+static const unsigned char classic_shift_luma[] = {
+ 34,36,35,69,135,232,9,16,10,24,11,23,12,16,13,10,14,8,15,8,
+ 16,8,17,20,16,10,207,206,205,236,11,8,10,21,9,23,8,8,199,70,
+ 69,68, 0
+};
+
+static const unsigned char classic_shift_chroma[] = {
+ 66,36,37,38,39,40,41,75,76,77,110,239,144,81,82,83,84,85,118,183,
+ 56,57,88,89,56,89,154,57,58,57,26,141,57,56,58,57,58,57,184,119,
+ 214,245,116,83,82,49,80,79,78,77,44,75,41,40,39,38,37,36,34, 0
+};
+
+static const unsigned char classic_add_luma[256] = {
+ 3, 9, 5, 12, 10, 35, 32, 29, 27, 50, 48, 45, 44, 41, 39, 37,
+ 73, 70, 68, 65, 64, 61, 58, 56, 53, 50, 49, 46, 44, 41, 38, 36,
+ 68, 65, 63, 61, 58, 55, 53, 51, 48, 46, 45, 43, 41, 39, 38, 36,
+ 35, 33, 32, 30, 29, 27, 26, 25, 48, 47, 46, 44, 43, 41, 40, 39,
+ 37, 36, 35, 34, 32, 31, 30, 28, 27, 26, 24, 23, 22, 20, 19, 37,
+ 35, 34, 33, 31, 30, 29, 27, 26, 24, 23, 21, 20, 18, 17, 15, 29,
+ 27, 26, 24, 22, 21, 19, 17, 16, 14, 26, 25, 23, 21, 19, 18, 16,
+ 15, 27, 25, 23, 21, 19, 17, 16, 14, 26, 25, 23, 21, 18, 17, 14,
+ 12, 17, 19, 13, 4, 9, 2, 11, 1, 7, 8, 0, 16, 3, 14, 6,
+ 12, 10, 5, 15, 18, 11, 10, 13, 15, 16, 19, 20, 22, 24, 27, 15,
+ 18, 20, 22, 24, 26, 14, 17, 20, 22, 24, 27, 15, 18, 20, 23, 25,
+ 28, 16, 19, 22, 25, 28, 32, 36, 21, 25, 29, 33, 38, 42, 45, 49,
+ 28, 31, 34, 37, 40, 42, 44, 47, 49, 50, 52, 54, 56, 57, 59, 60,
+ 62, 64, 66, 67, 69, 35, 37, 39, 40, 42, 43, 45, 47, 48, 51, 52,
+ 54, 55, 57, 59, 60, 62, 63, 66, 67, 69, 71, 72, 38, 40, 42, 43,
+ 46, 47, 49, 51, 26, 28, 30, 31, 33, 34, 18, 19, 11, 13, 7, 8,
+};
+
+static const unsigned char classic_add_chroma[256] = {
+ 3, 1, 2, 2, 2, 2, 3, 3, 7, 5, 7, 5, 8, 6, 11, 9,
+ 7, 13, 11, 10, 9, 8, 7, 5, 9, 7, 6, 4, 7, 5, 8, 7,
+ 11, 8, 13, 11, 19, 15, 22, 23, 20, 33, 32, 28, 27, 29, 51, 77,
+ 43, 45, 76, 81, 46, 82, 75, 55, 56,144, 58, 80, 60, 74,147, 63,
+ 143, 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, 27, 30, 21, 22,
+ 17, 14, 5, 6,100, 54, 47, 50, 51, 53,106,107,108,109,110,111,
+ 112,113,114,115, 4,117,118, 92, 94,121,122, 3,124,103, 2, 1,
+ 0,129,130,131,120,119,126,125,136,137,138,139,140,141,142,134,
+ 135,132,133,104, 64,101, 62, 57,102, 95, 93, 59, 61, 28, 97, 96,
+ 52, 49, 48, 29, 32, 25, 24, 46, 23, 98, 45, 44, 43, 20, 42, 41,
+ 19, 18, 99, 40, 15, 39, 38, 16, 13, 12, 11, 37, 10, 9, 8, 36,
+ 7,128,127,105,123,116, 35, 34, 33,145, 31, 79, 42,146, 78, 26,
+ 83, 48, 49, 50, 44, 47, 26, 31, 30, 18, 17, 19, 21, 24, 25, 13,
+ 14, 16, 17, 18, 20, 21, 12, 14, 15, 9, 10, 6, 9, 6, 5, 8,
+ 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; i<w-1; i++){
+ acc+= src[i];
+ dst[i]= acc;
+ i++;
+ acc+= src[i];
+ dst[i]= acc;
+ }
+
+ for(; i<w; i++){
+ acc+= src[i];
+ dst[i]= acc;
+ }
+
+ return acc;
+}
+
+static inline void add_median_prediction(uint8_t *dst, uint8_t *src1, uint8_t *diff, int w, int *left, int *left_top){
+ int i;
+ uint8_t l, lt;
+
+ l= *left;
+ lt= *left_top;
+
+ for(i=0; i<w; i++){
+ l= mid_pred(l, src1[i], (l + src1[i] - lt)&0xFF) + diff[i];
+ lt= src1[i];
+ dst[i]= l;
+ }
+
+ *left= l;
+ *left_top= lt;
+}
+
+static inline void add_left_prediction_bgr32(uint8_t *dst, uint8_t *src, int w, int *red, int *green, int *blue){
+ int i;
+ int r,g,b;
+ r= *red;
+ g= *green;
+ b= *blue;
+
+ for(i=0; i<w; i++){
+ b+= src[4*i+B];
+ g+= src[4*i+G];
+ r+= src[4*i+R];
+
+ dst[4*i+B]= b;
+ dst[4*i+G]= g;
+ dst[4*i+R]= r;
+ }
+
+ *red= r;
+ *green= g;
+ *blue= b;
+}
+
+static inline int sub_left_prediction(HYuvContext *s, uint8_t *dst, uint8_t *src, int w, int left){
+ int i;
+ if(w<32){
+ for(i=0; i<w; i++){
+ const int temp= src[i];
+ dst[i]= temp - left;
+ left= temp;
+ }
+ return left;
+ }else{
+ for(i=0; i<16; i++){
+ const int temp= src[i];
+ dst[i]= temp - left;
+ left= temp;
+ }
+ s->dsp.diff_bytes(dst+16, src+16, src+15, w-16);
+ return src[w-1];
+ }
+}
+
+static inline void sub_left_prediction_bgr32(HYuvContext *s, uint8_t *dst, uint8_t *src, int w, int *red, int *green, int *blue){
+ int i;
+ int r,g,b;
+ r= *red;
+ g= *green;
+ b= *blue;
+ for(i=0; i<FFMIN(w,4); i++){
+ const int rt= src[i*4+R];
+ const int gt= src[i*4+G];
+ const int bt= src[i*4+B];
+ dst[i*4+R]= rt - r;
+ dst[i*4+G]= gt - g;
+ dst[i*4+B]= bt - b;
+ r = rt;
+ g = gt;
+ b = bt;
+ }
+ s->dsp.diff_bytes(dst+16, src+16, src+12, w*4-16);
+ *red= src[(w-1)*4+R];
+ *green= src[(w-1)*4+G];
+ *blue= src[(w-1)*4+B];
+}
+
+static void read_len_table(uint8_t *dst, GetBitContext *gb){
+ int i, val, repeat;
+
+ for(i=0; i<256;){
+ repeat= get_bits(gb, 3);
+ val = get_bits(gb, 5);
+ if(repeat==0)
+ repeat= get_bits(gb, 8);
+//printf("%d %d\n", val, repeat);
+ while (repeat--)
+ dst[i++] = val;
+ }
+}
+
+static int generate_bits_table(uint32_t *dst, uint8_t *len_table){
+ int len, index;
+ uint32_t bits=0;
+
+ for(len=32; len>0; len--){
+ for(index=0; index<256; index++){
+ if(len_table[index]==len)
+ dst[index]= bits++;
+ }
+ if(bits & 1){
+ av_log(NULL, AV_LOG_ERROR, "Error generating huffman table\n");
+ return -1;
+ }
+ bits >>= 1;
+ }
+ return 0;
+}
+
+#ifdef CONFIG_ENCODERS
+static void generate_len_table(uint8_t *dst, uint64_t *stats, int size){
+ uint64_t counts[2*size];
+ int up[2*size];
+ int offset, i, next;
+
+ for(offset=1; ; offset<<=1){
+ for(i=0; i<size; i++){
+ counts[i]= stats[i] + offset - 1;
+ }
+
+ for(next=size; next<size*2; next++){
+ uint64_t min1, min2;
+ int min1_i, min2_i;
+
+ min1=min2= INT64_MAX;
+ min1_i= min2_i=-1;
+
+ for(i=0; i<next; i++){
+ if(min2 > counts[i]){
+ if(min1 > counts[i]){
+ min2= min1;
+ min2_i= min1_i;
+ min1= counts[i];
+ min1_i= i;
+ }else{
+ min2= counts[i];
+ min2_i= i;
+ }
+ }
+ }
+
+ if(min2==INT64_MAX) break;
+
+ counts[next]= min1 + min2;
+ counts[min1_i]=
+ counts[min2_i]= INT64_MAX;
+ up[min1_i]=
+ up[min2_i]= next;
+ up[next]= -1;
+ }
+
+ for(i=0; i<size; i++){
+ int len;
+ int index=i;
+
+ for(len=0; up[index] != -1; len++)
+ index= up[index];
+
+ if(len >= 32) break;
+
+ dst[i]= len;
+ }
+ if(i==size) break;
+ }
+}
+#endif /* CONFIG_ENCODERS */
+
+static int read_huffman_tables(HYuvContext *s, uint8_t *src, int length){
+ GetBitContext gb;
+ int i;
+
+ init_get_bits(&gb, src, length*8);
+
+ for(i=0; i<3; i++){
+ read_len_table(s->len[i], &gb);
+
+ if(generate_bits_table(s->bits[i], s->len[i])<0){
+ return -1;
+ }
+#if 0
+for(j=0; j<256; j++){
+printf("%6X, %2d, %3d\n", s->bits[i][j], s->len[i][j], j);
+}
+#endif
+ free_vlc(&s->vlc[i]);
+ init_vlc(&s->vlc[i], VLC_BITS, 256, s->len[i], 1, 1, s->bits[i], 4, 4, 0);
+ }
+
+ return (get_bits_count(&gb)+7)/8;
+}
+
+static int read_old_huffman_tables(HYuvContext *s){
+#if 1
+ GetBitContext gb;
+ int i;
+
+ init_get_bits(&gb, classic_shift_luma, sizeof(classic_shift_luma)*8);
+ read_len_table(s->len[0], &gb);
+ init_get_bits(&gb, classic_shift_chroma, sizeof(classic_shift_chroma)*8);
+ read_len_table(s->len[1], &gb);
+
+ for(i=0; i<256; i++) s->bits[0][i] = classic_add_luma [i];
+ for(i=0; i<256; i++) s->bits[1][i] = classic_add_chroma[i];
+
+ if(s->bitstream_bpp >= 24){
+ memcpy(s->bits[1], s->bits[0], 256*sizeof(uint32_t));
+ memcpy(s->len[1] , s->len [0], 256*sizeof(uint8_t));
+ }
+ memcpy(s->bits[2], s->bits[1], 256*sizeof(uint32_t));
+ memcpy(s->len[2] , s->len [1], 256*sizeof(uint8_t));
+
+ for(i=0; i<3; i++){
+ free_vlc(&s->vlc[i]);
+ init_vlc(&s->vlc[i], VLC_BITS, 256, s->len[i], 1, 1, s->bits[i], 4, 4, 0);
+ }
+
+ return 0;
+#else
+ av_log(s->avctx, AV_LOG_DEBUG, "v1 huffyuv is not supported \n");
+ return -1;
+#endif
+}
+
+static void alloc_temp(HYuvContext *s){
+ int i;
+
+ if(s->bitstream_bpp<24){
+ for(i=0; i<3; i++){
+ s->temp[i]= av_malloc(s->width + 16);
+ }
+ }else{
+ for(i=0; i<2; i++){
+ s->temp[i]= av_malloc(4*s->width + 16);
+ }
+ }
+}
+
+static int common_init(AVCodecContext *avctx){
+ HYuvContext *s = avctx->priv_data;
+
+ s->avctx= avctx;
+ s->flags= avctx->flags;
+
+ dsputil_init(&s->dsp, avctx);
+
+ s->width= avctx->width;
+ s->height= avctx->height;
+ assert(s->width>0 && s->height>0);
+
+ return 0;
+}
+
+#ifdef CONFIG_DECODERS
+static int decode_init(AVCodecContext *avctx)
+{
+ HYuvContext *s = avctx->priv_data;
+
+ common_init(avctx);
+ memset(s->vlc, 0, 3*sizeof(VLC));
+
+ avctx->coded_frame= &s->picture;
+ s->interlaced= s->height > 288;
+
+s->bgr32=1;
+//if(avctx->extradata)
+// printf("extradata:%X, extradata_size:%d\n", *(uint32_t*)avctx->extradata, avctx->extradata_size);
+ if(avctx->extradata_size){
+ if((avctx->bits_per_sample&7) && avctx->bits_per_sample != 12)
+ s->version=1; // do such files exist at all?
+ else
+ s->version=2;
+ }else
+ s->version=0;
+
+ if(s->version==2){
+ int method, interlace;
+
+ method= ((uint8_t*)avctx->extradata)[0];
+ s->decorrelate= method&64 ? 1 : 0;
+ s->predictor= method&63;
+ s->bitstream_bpp= ((uint8_t*)avctx->extradata)[1];
+ if(s->bitstream_bpp==0)
+ s->bitstream_bpp= avctx->bits_per_sample&~7;
+ interlace= (((uint8_t*)avctx->extradata)[2] & 0x30) >> 4;
+ 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)
+ return -1;
+ }else{
+ switch(avctx->bits_per_sample&7){
+ case 1:
+ s->predictor= LEFT;
+ s->decorrelate= 0;
+ break;
+ case 2:
+ s->predictor= LEFT;
+ s->decorrelate= 1;
+ break;
+ case 3:
+ s->predictor= PLANE;
+ s->decorrelate= avctx->bits_per_sample >= 24;
+ break;
+ case 4:
+ s->predictor= MEDIAN;
+ s->decorrelate= 0;
+ break;
+ default:
+ s->predictor= LEFT; //OLD
+ s->decorrelate= 0;
+ break;
+ }
+ s->bitstream_bpp= avctx->bits_per_sample & ~7;
+ s->context= 0;
+
+ if(read_old_huffman_tables(s) < 0)
+ return -1;
+ }
+
+ switch(s->bitstream_bpp){
+ case 12:
+ avctx->pix_fmt = PIX_FMT_YUV420P;
+ break;
+ case 16:
+ if(s->yuy2){
+ avctx->pix_fmt = PIX_FMT_YUYV422;
+ }else{
+ avctx->pix_fmt = PIX_FMT_YUV422P;
+ }
+ break;
+ case 24:
+ case 32:
+ if(s->bgr32){
+ avctx->pix_fmt = PIX_FMT_RGB32;
+ }else{
+ avctx->pix_fmt = PIX_FMT_BGR24;
+ }
+ break;
+ default:
+ assert(0);
+ }
+
+ alloc_temp(s);
+
+// av_log(NULL, AV_LOG_DEBUG, "pred:%d bpp:%d hbpp:%d il:%d\n", s->predictor, s->bitstream_bpp, avctx->bits_per_sample, s->interlaced);
+
+ return 0;
+}
+#endif
+
+#ifdef CONFIG_ENCODERS
+static int store_table(HYuvContext *s, uint8_t *len, uint8_t *buf){
+ int i;
+ int index= 0;
+
+ for(i=0; i<256;){
+ int val= len[i];
+ int repeat=0;
+
+ for(; i<256 && len[i]==val && repeat<255; i++)
+ repeat++;
+
+ assert(val < 32 && val >0 && repeat<256 && repeat>0);
+ if(repeat>7){
+ buf[index++]= val;
+ buf[index++]= repeat;
+ }else{
+ buf[index++]= val | (repeat<<5);
+ }
+ }
+
+ return index;
+}
+
+static int encode_init(AVCodecContext *avctx)
+{
+ HYuvContext *s = avctx->priv_data;
+ int i, j;
+
+ common_init(avctx);
+
+ avctx->extradata= av_mallocz(1024*30); // 256*3+4 == 772
+ avctx->stats_out= av_mallocz(1024*30); // 21*256*3(%llu ) + 3(\n) + 1(0) = 16132
+ s->version=2;
+
+ avctx->coded_frame= &s->picture;
+
+ switch(avctx->pix_fmt){
+ case PIX_FMT_YUV420P:
+ s->bitstream_bpp= 12;
+ break;
+ case PIX_FMT_YUV422P:
+ s->bitstream_bpp= 16;
+ break;
+ case PIX_FMT_RGB32:
+ s->bitstream_bpp= 24;
+ break;
+ default:
+ av_log(avctx, AV_LOG_ERROR, "format not supported\n");
+ return -1;
+ }
+ avctx->bits_per_sample= s->bitstream_bpp;
+ s->decorrelate= s->bitstream_bpp >= 24;
+ s->predictor= avctx->prediction_method;
+ s->interlaced= avctx->flags&CODEC_FLAG_INTERLACED_ME ? 1 : 0;
+ if(avctx->context_model==1){
+ s->context= avctx->context_model;
+ if(s->flags & (CODEC_FLAG_PASS1|CODEC_FLAG_PASS2)){
+ av_log(avctx, AV_LOG_ERROR, "context=1 is not compatible with 2 pass huffyuv encoding\n");
+ return -1;
+ }
+ }else s->context= 0;
+
+ if(avctx->codec->id==CODEC_ID_HUFFYUV){
+ if(avctx->pix_fmt==PIX_FMT_YUV420P){
+ av_log(avctx, AV_LOG_ERROR, "Error: YV12 is not supported by huffyuv; use vcodec=ffvhuff or format=422p\n");
+ return -1;
+ }
+ if(avctx->context_model){
+ av_log(avctx, AV_LOG_ERROR, "Error: per-frame huffman tables are not supported by huffyuv; use vcodec=ffvhuff\n");
+ return -1;
+ }
+ if(s->interlaced != ( s->height > 288 ))
+ av_log(avctx, AV_LOG_INFO, "using huffyuv 2.2.0 or newer interlacing flag\n");
+ }
+
+ if(s->bitstream_bpp>=24 && s->predictor==MEDIAN){
+ av_log(avctx, AV_LOG_ERROR, "Error: RGB is incompatible with median predictor\n");
+ return -1;
+ }
+
+ ((uint8_t*)avctx->extradata)[0]= s->predictor | (s->decorrelate << 6);
+ ((uint8_t*)avctx->extradata)[1]= s->bitstream_bpp;
+ ((uint8_t*)avctx->extradata)[2]= s->interlaced ? 0x10 : 0x20;
+ if(s->context)
+ ((uint8_t*)avctx->extradata)[2]|= 0x40;
+ ((uint8_t*)avctx->extradata)[3]= 0;
+ s->avctx->extradata_size= 4;
+
+ if(avctx->stats_in){
+ char *p= avctx->stats_in;
+
+ for(i=0; i<3; i++)
+ for(j=0; j<256; j++)
+ s->stats[i][j]= 1;
+
+ for(;;){
+ for(i=0; i<3; i++){
+ char *next;
+
+ for(j=0; j<256; j++){
+ s->stats[i][j]+= strtol(p, &next, 0);
+ if(next==p) return -1;
+ p=next;
+ }
+ }
+ if(p[0]==0 || p[1]==0 || p[2]==0) break;
+ }
+ }else{
+ for(i=0; i<3; i++)
+ for(j=0; j<256; j++){
+ int d= FFMIN(j, 256-j);
+
+ s->stats[i][j]= 100000000/(d+1);
+ }
+ }
+
+ for(i=0; i<3; i++){
+ generate_len_table(s->len[i], s->stats[i], 256);
+
+ if(generate_bits_table(s->bits[i], s->len[i])<0){
+ return -1;
+ }
+
+ s->avctx->extradata_size+=
+ store_table(s, s->len[i], &((uint8_t*)s->avctx->extradata)[s->avctx->extradata_size]);
+ }
+
+ if(s->context){
+ for(i=0; i<3; i++){
+ int pels = s->width*s->height / (i?40:10);
+ for(j=0; j<256; j++){
+ int d= FFMIN(j, 256-j);
+ s->stats[i][j]= pels/(d+1);
+ }
+ }
+ }else{
+ for(i=0; i<3; i++)
+ for(j=0; j<256; j++)
+ s->stats[i][j]= 0;
+ }
+
+// printf("pred:%d bpp:%d hbpp:%d il:%d\n", s->predictor, s->bitstream_bpp, avctx->bits_per_sample, s->interlaced);
+
+ alloc_temp(s);
+
+ s->picture_number=0;
+
+ return 0;
+}
+#endif /* CONFIG_ENCODERS */
+
+static void decode_422_bitstream(HYuvContext *s, int count){
+ int i;
+
+ count/=2;
+
+ for(i=0; i<count; i++){
+ s->temp[0][2*i ]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
+ s->temp[1][ i ]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3);
+ s->temp[0][2*i+1]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
+ s->temp[2][ i ]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3);
+ }
+}
+
+static void decode_gray_bitstream(HYuvContext *s, int count){
+ int i;
+
+ count/=2;
+
+ for(i=0; i<count; i++){
+ s->temp[0][2*i ]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
+ s->temp[0][2*i+1]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
+ }
+}
+
+#ifdef CONFIG_ENCODERS
+static int encode_422_bitstream(HYuvContext *s, int count){
+ int i;
+
+ if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < 2*4*count){
+ av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
+ return -1;
+ }
+
+ count/=2;
+ if(s->flags&CODEC_FLAG_PASS1){
+ for(i=0; i<count; i++){
+ s->stats[0][ s->temp[0][2*i ] ]++;
+ s->stats[1][ s->temp[1][ i ] ]++;
+ s->stats[0][ s->temp[0][2*i+1] ]++;
+ s->stats[2][ s->temp[2][ i ] ]++;
+ }
+ }
+ if(s->avctx->flags2&CODEC_FLAG2_NO_OUTPUT)
+ return 0;
+ if(s->context){
+ for(i=0; i<count; i++){
+ s->stats[0][ s->temp[0][2*i ] ]++;
+ put_bits(&s->pb, s->len[0][ s->temp[0][2*i ] ], s->bits[0][ s->temp[0][2*i ] ]);
+ s->stats[1][ s->temp[1][ i ] ]++;
+ put_bits(&s->pb, s->len[1][ s->temp[1][ i ] ], s->bits[1][ s->temp[1][ i ] ]);
+ s->stats[0][ s->temp[0][2*i+1] ]++;
+ put_bits(&s->pb, s->len[0][ s->temp[0][2*i+1] ], s->bits[0][ s->temp[0][2*i+1] ]);
+ s->stats[2][ s->temp[2][ i ] ]++;
+ put_bits(&s->pb, s->len[2][ s->temp[2][ i ] ], s->bits[2][ s->temp[2][ i ] ]);
+ }
+ }else{
+ for(i=0; i<count; i++){
+ put_bits(&s->pb, s->len[0][ s->temp[0][2*i ] ], s->bits[0][ s->temp[0][2*i ] ]);
+ put_bits(&s->pb, s->len[1][ s->temp[1][ i ] ], s->bits[1][ s->temp[1][ i ] ]);
+ put_bits(&s->pb, s->len[0][ s->temp[0][2*i+1] ], s->bits[0][ s->temp[0][2*i+1] ]);
+ put_bits(&s->pb, s->len[2][ s->temp[2][ i ] ], s->bits[2][ s->temp[2][ i ] ]);
+ }
+ }
+ return 0;
+}
+
+static int encode_gray_bitstream(HYuvContext *s, int count){
+ int i;
+
+ if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < 4*count){
+ av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
+ return -1;
+ }
+
+ count/=2;
+ if(s->flags&CODEC_FLAG_PASS1){
+ for(i=0; i<count; i++){
+ s->stats[0][ s->temp[0][2*i ] ]++;
+ s->stats[0][ s->temp[0][2*i+1] ]++;
+ }
+ }
+ if(s->avctx->flags2&CODEC_FLAG2_NO_OUTPUT)
+ return 0;
+
+ if(s->context){
+ for(i=0; i<count; i++){
+ s->stats[0][ s->temp[0][2*i ] ]++;
+ put_bits(&s->pb, s->len[0][ s->temp[0][2*i ] ], s->bits[0][ s->temp[0][2*i ] ]);
+ s->stats[0][ s->temp[0][2*i+1] ]++;
+ put_bits(&s->pb, s->len[0][ s->temp[0][2*i+1] ], s->bits[0][ s->temp[0][2*i+1] ]);
+ }
+ }else{
+ for(i=0; i<count; i++){
+ put_bits(&s->pb, s->len[0][ s->temp[0][2*i ] ], s->bits[0][ s->temp[0][2*i ] ]);
+ put_bits(&s->pb, s->len[0][ s->temp[0][2*i+1] ], s->bits[0][ s->temp[0][2*i+1] ]);
+ }
+ }
+ return 0;
+}
+#endif /* CONFIG_ENCODERS */
+
+static void decode_bgr_bitstream(HYuvContext *s, int count){
+ int i;
+
+ if(s->decorrelate){
+ if(s->bitstream_bpp==24){
+ for(i=0; i<count; i++){
+ s->temp[0][4*i+G]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3);
+ s->temp[0][4*i+B]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3) + s->temp[0][4*i+G];
+ s->temp[0][4*i+R]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3) + s->temp[0][4*i+G];
+ }
+ }else{
+ for(i=0; i<count; i++){
+ s->temp[0][4*i+G]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3);
+ s->temp[0][4*i+B]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3) + s->temp[0][4*i+G];
+ s->temp[0][4*i+R]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3) + s->temp[0][4*i+G];
+ get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); //?!
+ }
+ }
+ }else{
+ if(s->bitstream_bpp==24){
+ for(i=0; i<count; i++){
+ s->temp[0][4*i+B]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
+ s->temp[0][4*i+G]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3);
+ s->temp[0][4*i+R]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3);
+ }
+ }else{
+ for(i=0; i<count; i++){
+ s->temp[0][4*i+B]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
+ s->temp[0][4*i+G]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3);
+ s->temp[0][4*i+R]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3);
+ get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); //?!
+ }
+ }
+ }
+}
+
+static int encode_bgr_bitstream(HYuvContext *s, int count){
+ int i;
+
+ if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < 3*4*count){
+ av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
+ return -1;
+ }
+
+ if((s->flags&CODEC_FLAG_PASS1) && (s->avctx->flags2&CODEC_FLAG2_NO_OUTPUT)){
+ for(i=0; i<count; i++){
+ int g= s->temp[0][4*i+G];
+ int b= (s->temp[0][4*i+B] - g) & 0xff;
+ int r= (s->temp[0][4*i+R] - g) & 0xff;
+ s->stats[0][b]++;
+ s->stats[1][g]++;
+ s->stats[2][r]++;
+ }
+ }else if(s->context || (s->flags&CODEC_FLAG_PASS1)){
+ for(i=0; i<count; i++){
+ int g= s->temp[0][4*i+G];
+ int b= (s->temp[0][4*i+B] - g) & 0xff;
+ int r= (s->temp[0][4*i+R] - g) & 0xff;
+ s->stats[0][b]++;
+ s->stats[1][g]++;
+ s->stats[2][r]++;
+ put_bits(&s->pb, s->len[1][g], s->bits[1][g]);
+ put_bits(&s->pb, s->len[0][b], s->bits[0][b]);
+ put_bits(&s->pb, s->len[2][r], s->bits[2][r]);
+ }
+ }else{
+ for(i=0; i<count; i++){
+ int g= s->temp[0][4*i+G];
+ int b= (s->temp[0][4*i+B] - g) & 0xff;
+ int r= (s->temp[0][4*i+R] - g) & 0xff;
+ put_bits(&s->pb, s->len[1][g], s->bits[1][g]);
+ put_bits(&s->pb, s->len[0][b], s->bits[0][b]);
+ put_bits(&s->pb, s->len[2][r], s->bits[2][r]);
+ }
+ }
+ return 0;
+}
+
+#ifdef CONFIG_DECODERS
+static void draw_slice(HYuvContext *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->bitstream_bpp==12){
+ cy= y>>1;
+ }else{
+ cy= y;
+ }
+
+ offset[0] = s->picture.linesize[0]*y;
+ offset[1] = s->picture.linesize[1]*cy;
+ offset[2] = s->picture.linesize[2]*cy;
+ offset[3] = 0;
+ emms_c();
+
+ s->avctx->draw_horiz_band(s->avctx, &s->picture, offset, y, 3, h);
+
+ s->last_slice_end= y + h;
+}
+
+static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size){
+ HYuvContext *s = avctx->priv_data;
+ const int width= s->width;
+ const int width2= s->width>>1;
+ const int height= s->height;
+ int fake_ystride, fake_ustride, fake_vstride;
+ AVFrame * const p= &s->picture;
+ int table_size= 0;
+
+ AVFrame *picture = data;
+
+ s->bitstream_buffer= av_fast_realloc(s->bitstream_buffer, &s->bitstream_buffer_size, buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
+
+ s->dsp.bswap_buf((uint32_t*)s->bitstream_buffer, (uint32_t*)buf, buf_size/4);
+
+ 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;
+ }
+
+ if(s->context){
+ table_size = read_huffman_tables(s, s->bitstream_buffer, buf_size);
+ if(table_size < 0)
+ return -1;
+ }
+
+ if((unsigned)(buf_size-table_size) >= INT_MAX/8)
+ return -1;
+
+ init_get_bits(&s->gb, s->bitstream_buffer+table_size, (buf_size-table_size)*8);
+
+ fake_ystride= s->interlaced ? p->linesize[0]*2 : p->linesize[0];
+ fake_ustride= s->interlaced ? p->linesize[1]*2 : p->linesize[1];
+ fake_vstride= s->interlaced ? p->linesize[2]*2 : p->linesize[2];
+
+ s->last_slice_end= 0;
+
+ if(s->bitstream_bpp<24){
+ int y, cy;
+ int lefty, leftu, leftv;
+ int lefttopy, lefttopu, lefttopv;
+
+ if(s->yuy2){
+ p->data[0][3]= get_bits(&s->gb, 8);
+ p->data[0][2]= get_bits(&s->gb, 8);
+ p->data[0][1]= get_bits(&s->gb, 8);
+ p->data[0][0]= get_bits(&s->gb, 8);
+
+ av_log(avctx, AV_LOG_ERROR, "YUY2 output is not implemented yet\n");
+ return -1;
+ }else{
+
+ leftv= p->data[2][0]= get_bits(&s->gb, 8);
+ lefty= p->data[0][1]= get_bits(&s->gb, 8);
+ leftu= p->data[1][0]= get_bits(&s->gb, 8);
+ p->data[0][0]= get_bits(&s->gb, 8);
+
+ switch(s->predictor){
+ case LEFT:
+ case PLANE:
+ decode_422_bitstream(s, width-2);
+ lefty= add_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);
+ }
+
+ for(cy=y=1; y<s->height; y++,cy++){
+ uint8_t *ydst, *udst, *vdst;
+
+ if(s->bitstream_bpp==12){
+ decode_gray_bitstream(s, width);
+
+ ydst= p->data[0] + p->linesize[0]*y;
+
+ lefty= add_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);
+ }
+ y++;
+ if(y>=s->height) break;
+ }
+
+ draw_slice(s, y);
+
+ ydst= p->data[0] + p->linesize[0]*y;
+ udst= p->data[1] + p->linesize[1]*cy;
+ vdst= p->data[2] + p->linesize[2]*cy;
+
+ decode_422_bitstream(s, width);
+ lefty= add_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);
+ }
+ if(s->predictor == PLANE){
+ if(cy>s->interlaced){
+ s->dsp.add_bytes(ydst, ydst - fake_ystride, width);
+ if(!(s->flags&CODEC_FLAG_GRAY)){
+ s->dsp.add_bytes(udst, udst - fake_ustride, width2);
+ s->dsp.add_bytes(vdst, vdst - fake_vstride, width2);
+ }
+ }
+ }
+ }
+ draw_slice(s, height);
+
+ break;
+ 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);
+ 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);
+ }
+
+ cy=y=1;
+
+ /* 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);
+ 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);
+ }
+ 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);
+ 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);
+ }
+
+ /* next line except the first 4 pixels is median predicted */
+ lefttopy= p->data[0][3];
+ decode_422_bitstream(s, width-4);
+ add_median_prediction(p->data[0] + fake_ystride+4, p->data[0]+4, s->temp[0], width-4, &lefty, &lefttopy);
+ if(!(s->flags&CODEC_FLAG_GRAY)){
+ lefttopu= p->data[1][1];
+ lefttopv= p->data[2][1];
+ add_median_prediction(p->data[1] + fake_ustride+2, p->data[1]+2, s->temp[1], width2-2, &leftu, &lefttopu);
+ add_median_prediction(p->data[2] + fake_vstride+2, p->data[2]+2, s->temp[2], width2-2, &leftv, &lefttopv);
+ }
+ y++; cy++;
+
+ for(; y<height; y++,cy++){
+ uint8_t *ydst, *udst, *vdst;
+
+ if(s->bitstream_bpp==12){
+ while(2*cy > y){
+ decode_gray_bitstream(s, width);
+ ydst= p->data[0] + p->linesize[0]*y;
+ add_median_prediction(ydst, ydst - fake_ystride, s->temp[0], width, &lefty, &lefttopy);
+ y++;
+ }
+ if(y>=height) break;
+ }
+ draw_slice(s, y);
+
+ decode_422_bitstream(s, width);
+
+ ydst= p->data[0] + p->linesize[0]*y;
+ udst= p->data[1] + p->linesize[1]*cy;
+ vdst= p->data[2] + p->linesize[2]*cy;
+
+ add_median_prediction(ydst, ydst - fake_ystride, s->temp[0], width, &lefty, &lefttopy);
+ if(!(s->flags&CODEC_FLAG_GRAY)){
+ add_median_prediction(udst, udst - fake_ustride, s->temp[1], width2, &leftu, &lefttopu);
+ add_median_prediction(vdst, vdst - fake_vstride, s->temp[2], width2, &leftv, &lefttopv);
+ }
+ }
+
+ draw_slice(s, height);
+ break;
+ }
+ }
+ }else{
+ int y;
+ int leftr, leftg, leftb;
+ const int last_line= (height-1)*p->linesize[0];
+
+ if(s->bitstream_bpp==32){
+ skip_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);
+ }else{
+ 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);
+ skip_bits(&s->gb, 8);
+ }
+
+ if(s->bgr32){
+ switch(s->predictor){
+ 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);
+
+ for(y=s->height-2; y>=0; y--){ //yes its 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);
+ if(s->predictor == PLANE){
+ if((y&s->interlaced)==0 && y<s->height-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);
+ }
+ }
+ }
+ draw_slice(s, height); // just 1 large slice as this is not possible in reverse order
+ break;
+ default:
+ av_log(avctx, AV_LOG_ERROR, "prediction type not supported!\n");
+ }
+ }else{
+
+ av_log(avctx, AV_LOG_ERROR, "BGR24 output is not implemented yet\n");
+ return -1;
+ }
+ }
+ emms_c();
+
+ *picture= *p;
+ *data_size = sizeof(AVFrame);
+
+ return (get_bits_count(&s->gb)+31)/32*4 + table_size;
+}
+#endif
+
+static int common_end(HYuvContext *s){
+ int i;
+
+ for(i=0; i<3; i++){
+ av_freep(&s->temp[i]);
+ }
+ return 0;
+}
+
+#ifdef CONFIG_DECODERS
+static int decode_end(AVCodecContext *avctx)
+{
+ HYuvContext *s = avctx->priv_data;
+ int i;
+
+ common_end(s);
+ av_freep(&s->bitstream_buffer);
+
+ for(i=0; i<3; i++){
+ free_vlc(&s->vlc[i]);
+ }
+
+ return 0;
+}
+#endif
+
+#ifdef CONFIG_ENCODERS
+static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
+ HYuvContext *s = avctx->priv_data;
+ AVFrame *pict = data;
+ const int width= s->width;
+ const int width2= s->width>>1;
+ const int height= s->height;
+ const int fake_ystride= s->interlaced ? pict->linesize[0]*2 : pict->linesize[0];
+ const int fake_ustride= s->interlaced ? pict->linesize[1]*2 : pict->linesize[1];
+ const int fake_vstride= s->interlaced ? pict->linesize[2]*2 : pict->linesize[2];
+ AVFrame * const p= &s->picture;
+ int i, j, size=0;
+
+ *p = *pict;
+ p->pict_type= FF_I_TYPE;
+ p->key_frame= 1;
+
+ if(s->context){
+ for(i=0; i<3; i++){
+ generate_len_table(s->len[i], s->stats[i], 256);
+ if(generate_bits_table(s->bits[i], s->len[i])<0)
+ return -1;
+ size+= store_table(s, s->len[i], &buf[size]);
+ }
+
+ for(i=0; i<3; i++)
+ for(j=0; j<256; j++)
+ s->stats[i][j] >>= 1;
+ }
+
+ init_put_bits(&s->pb, buf+size, buf_size-size);
+
+ if(avctx->pix_fmt == PIX_FMT_YUV422P || avctx->pix_fmt == PIX_FMT_YUV420P){
+ int lefty, leftu, leftv, y, cy;
+
+ put_bits(&s->pb, 8, leftv= p->data[2][0]);
+ put_bits(&s->pb, 8, lefty= p->data[0][1]);
+ put_bits(&s->pb, 8, leftu= p->data[1][0]);
+ put_bits(&s->pb, 8, p->data[0][0]);
+
+ lefty= sub_left_prediction(s, s->temp[0], p->data[0]+2, width-2 , lefty);
+ leftu= sub_left_prediction(s, s->temp[1], p->data[1]+1, width2-1, leftu);
+ leftv= sub_left_prediction(s, s->temp[2], p->data[2]+1, width2-1, leftv);
+
+ encode_422_bitstream(s, width-2);
+
+ if(s->predictor==MEDIAN){
+ int lefttopy, lefttopu, lefttopv;
+ cy=y=1;
+ if(s->interlaced){
+ lefty= sub_left_prediction(s, s->temp[0], p->data[0]+p->linesize[0], width , lefty);
+ leftu= sub_left_prediction(s, s->temp[1], p->data[1]+p->linesize[1], width2, leftu);
+ leftv= sub_left_prediction(s, s->temp[2], p->data[2]+p->linesize[2], width2, leftv);
+
+ encode_422_bitstream(s, width);
+ y++; cy++;
+ }
+
+ lefty= sub_left_prediction(s, s->temp[0], p->data[0]+fake_ystride, 4, lefty);
+ leftu= sub_left_prediction(s, s->temp[1], p->data[1]+fake_ustride, 2, leftu);
+ leftv= sub_left_prediction(s, s->temp[2], p->data[2]+fake_vstride, 2, leftv);
+
+ encode_422_bitstream(s, 4);
+
+ lefttopy= p->data[0][3];
+ lefttopu= p->data[1][1];
+ lefttopv= p->data[2][1];
+ s->dsp.sub_hfyu_median_prediction(s->temp[0], p->data[0]+4, p->data[0] + fake_ystride+4, width-4 , &lefty, &lefttopy);
+ s->dsp.sub_hfyu_median_prediction(s->temp[1], p->data[1]+2, p->data[1] + fake_ustride+2, width2-2, &leftu, &lefttopu);
+ s->dsp.sub_hfyu_median_prediction(s->temp[2], p->data[2]+2, p->data[2] + fake_vstride+2, width2-2, &leftv, &lefttopv);
+ encode_422_bitstream(s, width-4);
+ y++; cy++;
+
+ for(; y<height; y++,cy++){
+ uint8_t *ydst, *udst, *vdst;
+
+ if(s->bitstream_bpp==12){
+ while(2*cy > y){
+ ydst= p->data[0] + p->linesize[0]*y;
+ s->dsp.sub_hfyu_median_prediction(s->temp[0], ydst - fake_ystride, ydst, width , &lefty, &lefttopy);
+ encode_gray_bitstream(s, width);
+ y++;
+ }
+ if(y>=height) break;
+ }
+ ydst= p->data[0] + p->linesize[0]*y;
+ udst= p->data[1] + p->linesize[1]*cy;
+ vdst= p->data[2] + p->linesize[2]*cy;
+
+ s->dsp.sub_hfyu_median_prediction(s->temp[0], ydst - fake_ystride, ydst, width , &lefty, &lefttopy);
+ s->dsp.sub_hfyu_median_prediction(s->temp[1], udst - fake_ustride, udst, width2, &leftu, &lefttopu);
+ s->dsp.sub_hfyu_median_prediction(s->temp[2], vdst - fake_vstride, vdst, width2, &leftv, &lefttopv);
+
+ encode_422_bitstream(s, width);
+ }
+ }else{
+ for(cy=y=1; y<height; y++,cy++){
+ uint8_t *ydst, *udst, *vdst;
+
+ /* encode a luma only line & y++ */
+ if(s->bitstream_bpp==12){
+ ydst= p->data[0] + p->linesize[0]*y;
+
+ if(s->predictor == PLANE && s->interlaced < y){
+ s->dsp.diff_bytes(s->temp[1], ydst, ydst - fake_ystride, width);
+
+ lefty= sub_left_prediction(s, s->temp[0], s->temp[1], width , lefty);
+ }else{
+ lefty= sub_left_prediction(s, s->temp[0], ydst, width , lefty);
+ }
+ encode_gray_bitstream(s, width);
+ y++;
+ if(y>=height) break;
+ }
+
+ ydst= p->data[0] + p->linesize[0]*y;
+ udst= p->data[1] + p->linesize[1]*cy;
+ vdst= p->data[2] + p->linesize[2]*cy;
+
+ if(s->predictor == PLANE && s->interlaced < cy){
+ s->dsp.diff_bytes(s->temp[1], ydst, ydst - fake_ystride, width);
+ s->dsp.diff_bytes(s->temp[2], udst, udst - fake_ustride, width2);
+ s->dsp.diff_bytes(s->temp[2] + width2, vdst, vdst - fake_vstride, width2);
+
+ lefty= sub_left_prediction(s, s->temp[0], s->temp[1], width , lefty);
+ leftu= sub_left_prediction(s, s->temp[1], s->temp[2], width2, leftu);
+ leftv= sub_left_prediction(s, s->temp[2], s->temp[2] + width2, width2, leftv);
+ }else{
+ lefty= sub_left_prediction(s, s->temp[0], ydst, width , lefty);
+ leftu= sub_left_prediction(s, s->temp[1], udst, width2, leftu);
+ leftv= sub_left_prediction(s, s->temp[2], vdst, width2, leftv);
+ }
+
+ encode_422_bitstream(s, width);
+ }
+ }
+ }else if(avctx->pix_fmt == PIX_FMT_RGB32){
+ uint8_t *data = p->data[0] + (height-1)*p->linesize[0];
+ const int stride = -p->linesize[0];
+ const int fake_stride = -fake_ystride;
+ int y;
+ int leftr, leftg, leftb;
+
+ put_bits(&s->pb, 8, leftr= data[R]);
+ put_bits(&s->pb, 8, leftg= data[G]);
+ put_bits(&s->pb, 8, leftb= data[B]);
+ put_bits(&s->pb, 8, 0);
+
+ sub_left_prediction_bgr32(s, s->temp[0], data+4, width-1, &leftr, &leftg, &leftb);
+ encode_bgr_bitstream(s, width-1);
+
+ for(y=1; y<s->height; y++){
+ uint8_t *dst = data + y*stride;
+ if(s->predictor == PLANE && s->interlaced < y){
+ s->dsp.diff_bytes(s->temp[1], dst, dst - fake_stride, width*4);
+ sub_left_prediction_bgr32(s, s->temp[0], s->temp[1], width, &leftr, &leftg, &leftb);
+ }else{
+ sub_left_prediction_bgr32(s, s->temp[0], dst, width, &leftr, &leftg, &leftb);
+ }
+ encode_bgr_bitstream(s, width);
+ }
+ }else{
+ av_log(avctx, AV_LOG_ERROR, "Format not supported!\n");
+ }
+ emms_c();
+
+ size+= (put_bits_count(&s->pb)+31)/8;
+ size/= 4;
+
+ if((s->flags&CODEC_FLAG_PASS1) && (s->picture_number&31)==0){
+ int j;
+ char *p= avctx->stats_out;
+ char *end= p + 1024*30;
+ for(i=0; i<3; i++){
+ for(j=0; j<256; j++){
+ snprintf(p, end-p, "%"PRIu64" ", s->stats[i][j]);
+ p+= strlen(p);
+ s->stats[i][j]= 0;
+ }
+ snprintf(p, end-p, "\n");
+ p++;
+ }
+ }
+ if(!(s->avctx->flags2 & CODEC_FLAG2_NO_OUTPUT)){
+ flush_put_bits(&s->pb);
+ s->dsp.bswap_buf((uint32_t*)buf, (uint32_t*)buf, size);
+ avctx->stats_out[0] = '\0';
+ }
+
+ s->picture_number++;
+
+ return size*4;
+}
+
+static int encode_end(AVCodecContext *avctx)
+{
+ HYuvContext *s = avctx->priv_data;
+
+ common_end(s);
+
+ av_freep(&avctx->extradata);
+ av_freep(&avctx->stats_out);
+
+ return 0;
+}
+#endif /* CONFIG_ENCODERS */
+
+#ifdef CONFIG_DECODERS
+AVCodec huffyuv_decoder = {
+ "huffyuv",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_HUFFYUV,
+ sizeof(HYuvContext),
+ decode_init,
+ NULL,
+ decode_end,
+ decode_frame,
+ CODEC_CAP_DR1 | CODEC_CAP_DRAW_HORIZ_BAND,
+ NULL
+};
+
+AVCodec ffvhuff_decoder = {
+ "ffvhuff",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_FFVHUFF,
+ sizeof(HYuvContext),
+ decode_init,
+ NULL,
+ decode_end,
+ decode_frame,
+ CODEC_CAP_DR1 | CODEC_CAP_DRAW_HORIZ_BAND,
+ NULL
+};
+#endif
+
+#ifdef CONFIG_ENCODERS
+
+AVCodec huffyuv_encoder = {
+ "huffyuv",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_HUFFYUV,
+ sizeof(HYuvContext),
+ encode_init,
+ encode_frame,
+ encode_end,
+ .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV422P, PIX_FMT_RGB32, -1},
+};
+
+AVCodec ffvhuff_encoder = {
+ "ffvhuff",
+ CODEC_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, -1},
+};
+
+#endif //CONFIG_ENCODERS
diff --git a/contrib/ffmpeg/libavcodec/i386/cavsdsp_mmx.c b/contrib/ffmpeg/libavcodec/i386/cavsdsp_mmx.c
new file mode 100644
index 000000000..51d519a5c
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/i386/cavsdsp_mmx.c
@@ -0,0 +1,518 @@
+/*
+ * Chinese AVS video (AVS1-P2, JiZhun profile) decoder.
+ * Copyright (c) 2006 Stefan Gehrer <stefan.gehrer@gmx.de>
+ *
+ * MMX optimised DSP functions, based on H.264 optimisations by
+ * Michael Niedermayer and Loren Merritt
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "../dsputil.h"
+#include "common.h"
+
+DECLARE_ALIGNED_8(static const uint64_t,ff_pw_4 ) = 0x0004000400040004ULL;
+DECLARE_ALIGNED_8(static const uint64_t,ff_pw_5 ) = 0x0005000500050005ULL;
+DECLARE_ALIGNED_8(static const uint64_t,ff_pw_7 ) = 0x0007000700070007ULL;
+DECLARE_ALIGNED_8(static const uint64_t,ff_pw_42) = 0x002A002A002A002AULL;
+DECLARE_ALIGNED_8(static const uint64_t,ff_pw_64) = 0x0040004000400040ULL;
+DECLARE_ALIGNED_8(static const uint64_t,ff_pw_96) = 0x0060006000600060ULL;
+
+/*****************************************************************************
+ *
+ * inverse transform
+ *
+ ****************************************************************************/
+
+#define SUMSUB_BA( a, b ) \
+ "paddw "#b", "#a" \n\t"\
+ "paddw "#b", "#b" \n\t"\
+ "psubw "#a", "#b" \n\t"
+
+#define SBUTTERFLY(a,b,t,n)\
+ "movq " #a ", " #t " \n\t" /* abcd */\
+ "punpckl" #n " " #b ", " #a " \n\t" /* aebf */\
+ "punpckh" #n " " #b ", " #t " \n\t" /* cgdh */
+
+#define TRANSPOSE4(a,b,c,d,t)\
+ SBUTTERFLY(a,b,t,wd) /* a=aebf t=cgdh */\
+ SBUTTERFLY(c,d,b,wd) /* c=imjn b=kolp */\
+ SBUTTERFLY(a,c,d,dq) /* a=aeim d=bfjn */\
+ SBUTTERFLY(t,b,c,dq) /* t=cgko c=dhlp */
+
+static inline void cavs_idct8_1d(int16_t *block, uint64_t bias)
+{
+ asm volatile(
+ "movq 112(%0), %%mm4 \n\t" /* mm4 = src7 */
+ "movq 16(%0), %%mm5 \n\t" /* mm5 = src1 */
+ "movq 80(%0), %%mm2 \n\t" /* mm2 = src5 */
+ "movq 48(%0), %%mm7 \n\t" /* mm7 = src3 */
+ "movq %%mm4, %%mm0 \n\t"
+ "movq %%mm5, %%mm3 \n\t"
+ "movq %%mm2, %%mm6 \n\t"
+ "movq %%mm7, %%mm1 \n\t"
+
+ "paddw %%mm4, %%mm4 \n\t" /* mm4 = 2*src7 */
+ "paddw %%mm3, %%mm3 \n\t" /* mm3 = 2*src1 */
+ "paddw %%mm6, %%mm6 \n\t" /* mm6 = 2*src5 */
+ "paddw %%mm1, %%mm1 \n\t" /* mm1 = 2*src3 */
+ "paddw %%mm4, %%mm0 \n\t" /* mm0 = 3*src7 */
+ "paddw %%mm3, %%mm5 \n\t" /* mm5 = 3*src1 */
+ "paddw %%mm6, %%mm2 \n\t" /* mm2 = 3*src5 */
+ "paddw %%mm1, %%mm7 \n\t" /* mm7 = 3*src3 */
+ "psubw %%mm4, %%mm5 \n\t" /* mm5 = 3*src1 - 2*src7 = a0 */
+ "paddw %%mm6, %%mm7 \n\t" /* mm7 = 3*src3 + 2*src5 = a1 */
+ "psubw %%mm2, %%mm1 \n\t" /* mm1 = 2*src3 - 3*src5 = a2 */
+ "paddw %%mm0, %%mm3 \n\t" /* mm3 = 2*src1 + 3*src7 = a3 */
+
+ "movq %%mm5, %%mm4 \n\t"
+ "movq %%mm7, %%mm6 \n\t"
+ "movq %%mm3, %%mm0 \n\t"
+ "movq %%mm1, %%mm2 \n\t"
+ SUMSUB_BA( %%mm7, %%mm5 ) /* mm7 = a0 + a1 mm5 = a0 - a1 */
+ "paddw %%mm3, %%mm7 \n\t" /* mm7 = a0 + a1 + a3 */
+ "paddw %%mm1, %%mm5 \n\t" /* mm5 = a0 - a1 + a2 */
+ "paddw %%mm7, %%mm7 \n\t"
+ "paddw %%mm5, %%mm5 \n\t"
+ "paddw %%mm6, %%mm7 \n\t" /* mm7 = b4 */
+ "paddw %%mm4, %%mm5 \n\t" /* mm5 = b5 */
+
+ SUMSUB_BA( %%mm1, %%mm3 ) /* mm1 = a3 + a2 mm3 = a3 - a2 */
+ "psubw %%mm1, %%mm4 \n\t" /* mm4 = a0 - a2 - a3 */
+ "movq %%mm4, %%mm1 \n\t" /* mm1 = a0 - a2 - a3 */
+ "psubw %%mm6, %%mm3 \n\t" /* mm3 = a3 - a2 - a1 */
+ "paddw %%mm1, %%mm1 \n\t"
+ "paddw %%mm3, %%mm3 \n\t"
+ "psubw %%mm2, %%mm1 \n\t" /* mm1 = b7 */
+ "paddw %%mm0, %%mm3 \n\t" /* mm3 = b6 */
+
+ "movq 32(%0), %%mm2 \n\t" /* mm2 = src2 */
+ "movq 96(%0), %%mm6 \n\t" /* mm6 = src6 */
+ "movq %%mm2, %%mm4 \n\t"
+ "movq %%mm6, %%mm0 \n\t"
+ "psllw $2, %%mm4 \n\t" /* mm4 = 4*src2 */
+ "psllw $2, %%mm6 \n\t" /* mm6 = 4*src6 */
+ "paddw %%mm4, %%mm2 \n\t" /* mm2 = 5*src2 */
+ "paddw %%mm6, %%mm0 \n\t" /* mm0 = 5*src6 */
+ "paddw %%mm2, %%mm2 \n\t"
+ "paddw %%mm0, %%mm0 \n\t"
+ "psubw %%mm0, %%mm4 \n\t" /* mm4 = 4*src2 - 10*src6 = a7 */
+ "paddw %%mm2, %%mm6 \n\t" /* mm6 = 4*src6 + 10*src2 = a6 */
+
+ "movq (%0), %%mm2 \n\t" /* mm2 = src0 */
+ "movq 64(%0), %%mm0 \n\t" /* mm0 = src4 */
+ SUMSUB_BA( %%mm0, %%mm2 ) /* mm0 = src0+src4 mm2 = src0-src4 */
+ "psllw $3, %%mm0 \n\t"
+ "psllw $3, %%mm2 \n\t"
+ "paddw %1, %%mm0 \n\t" /* add rounding bias */
+ "paddw %1, %%mm2 \n\t" /* add rounding bias */
+
+ SUMSUB_BA( %%mm6, %%mm0 ) /* mm6 = a4 + a6 mm0 = a4 - a6 */
+ SUMSUB_BA( %%mm4, %%mm2 ) /* mm4 = a5 + a7 mm2 = a5 - a7 */
+ SUMSUB_BA( %%mm7, %%mm6 ) /* mm7 = dst0 mm6 = dst7 */
+ SUMSUB_BA( %%mm5, %%mm4 ) /* mm5 = dst1 mm4 = dst6 */
+ SUMSUB_BA( %%mm3, %%mm2 ) /* mm3 = dst2 mm2 = dst5 */
+ SUMSUB_BA( %%mm1, %%mm0 ) /* mm1 = dst3 mm0 = dst4 */
+ :: "r"(block), "m"(bias)
+ );
+}
+
+static void cavs_idct8_add_mmx(uint8_t *dst, int16_t *block, int stride)
+{
+ int i;
+ DECLARE_ALIGNED_8(int16_t, b2[64]);
+
+ for(i=0; i<2; i++){
+ DECLARE_ALIGNED_8(uint64_t, tmp);
+
+ cavs_idct8_1d(block+4*i, ff_pw_4);
+
+ asm volatile(
+ "psraw $3, %%mm7 \n\t"
+ "psraw $3, %%mm6 \n\t"
+ "psraw $3, %%mm5 \n\t"
+ "psraw $3, %%mm4 \n\t"
+ "psraw $3, %%mm3 \n\t"
+ "psraw $3, %%mm2 \n\t"
+ "psraw $3, %%mm1 \n\t"
+ "psraw $3, %%mm0 \n\t"
+ "movq %%mm7, %0 \n\t"
+ TRANSPOSE4( %%mm0, %%mm2, %%mm4, %%mm6, %%mm7 )
+ "movq %%mm0, 8(%1) \n\t"
+ "movq %%mm6, 24(%1) \n\t"
+ "movq %%mm7, 40(%1) \n\t"
+ "movq %%mm4, 56(%1) \n\t"
+ "movq %0, %%mm7 \n\t"
+ TRANSPOSE4( %%mm7, %%mm5, %%mm3, %%mm1, %%mm0 )
+ "movq %%mm7, (%1) \n\t"
+ "movq %%mm1, 16(%1) \n\t"
+ "movq %%mm0, 32(%1) \n\t"
+ "movq %%mm3, 48(%1) \n\t"
+ : "=m"(tmp)
+ : "r"(b2+32*i)
+ : "memory"
+ );
+ }
+
+ for(i=0; i<2; i++){
+ cavs_idct8_1d(b2+4*i, ff_pw_64);
+
+ asm volatile(
+ "psraw $7, %%mm7 \n\t"
+ "psraw $7, %%mm6 \n\t"
+ "psraw $7, %%mm5 \n\t"
+ "psraw $7, %%mm4 \n\t"
+ "psraw $7, %%mm3 \n\t"
+ "psraw $7, %%mm2 \n\t"
+ "psraw $7, %%mm1 \n\t"
+ "psraw $7, %%mm0 \n\t"
+ "movq %%mm7, (%0) \n\t"
+ "movq %%mm5, 16(%0) \n\t"
+ "movq %%mm3, 32(%0) \n\t"
+ "movq %%mm1, 48(%0) \n\t"
+ "movq %%mm0, 64(%0) \n\t"
+ "movq %%mm2, 80(%0) \n\t"
+ "movq %%mm4, 96(%0) \n\t"
+ "movq %%mm6, 112(%0) \n\t"
+ :: "r"(b2+4*i)
+ : "memory"
+ );
+ }
+
+ add_pixels_clamped_mmx(b2, dst, stride);
+
+ /* clear block */
+ asm volatile(
+ "pxor %%mm7, %%mm7 \n\t"
+ "movq %%mm7, (%0) \n\t"
+ "movq %%mm7, 8(%0) \n\t"
+ "movq %%mm7, 16(%0) \n\t"
+ "movq %%mm7, 24(%0) \n\t"
+ "movq %%mm7, 32(%0) \n\t"
+ "movq %%mm7, 40(%0) \n\t"
+ "movq %%mm7, 48(%0) \n\t"
+ "movq %%mm7, 56(%0) \n\t"
+ "movq %%mm7, 64(%0) \n\t"
+ "movq %%mm7, 72(%0) \n\t"
+ "movq %%mm7, 80(%0) \n\t"
+ "movq %%mm7, 88(%0) \n\t"
+ "movq %%mm7, 96(%0) \n\t"
+ "movq %%mm7, 104(%0) \n\t"
+ "movq %%mm7, 112(%0) \n\t"
+ "movq %%mm7, 120(%0) \n\t"
+ :: "r" (block)
+ );
+}
+
+/*****************************************************************************
+ *
+ * motion compensation
+ *
+ ****************************************************************************/
+
+/* vertical filter [-1 -2 96 42 -7 0] */
+#define QPEL_CAVSV1(A,B,C,D,E,F,OP) \
+ "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"\
+ "psllw $3, "#E" \n\t"\
+ "psubw "#E", %%mm6 \n\t"\
+ "psraw $3, "#E" \n\t"\
+ "paddw %%mm7, %%mm6 \n\t"\
+ "paddw "#E", %%mm6 \n\t"\
+ "paddw "#B", "#B" \n\t"\
+ "pxor %%mm7, %%mm7 \n\t"\
+ "add %2, %0 \n\t"\
+ "punpcklbw %%mm7, "#F" \n\t"\
+ "psubw "#B", %%mm6 \n\t"\
+ "psraw $1, "#B" \n\t"\
+ "psubw "#A", %%mm6 \n\t"\
+ "paddw %4, %%mm6 \n\t"\
+ "psraw $7, %%mm6 \n\t"\
+ "packuswb %%mm6, %%mm6 \n\t"\
+ OP(%%mm6, (%1), A, d) \
+ "add %3, %1 \n\t"
+
+/* vertical filter [ 0 -1 5 5 -1 0] */
+#define QPEL_CAVSV2(A,B,C,D,E,F,OP) \
+ "movd (%0), "#F" \n\t"\
+ "movq "#C", %%mm6 \n\t"\
+ "paddw "#D", %%mm6 \n\t"\
+ "pmullw %5, %%mm6 \n\t"\
+ "add %2, %0 \n\t"\
+ "punpcklbw %%mm7, "#F" \n\t"\
+ "psubw "#B", %%mm6 \n\t"\
+ "psubw "#E", %%mm6 \n\t"\
+ "paddw %4, %%mm6 \n\t"\
+ "psraw $3, %%mm6 \n\t"\
+ "packuswb %%mm6, %%mm6 \n\t"\
+ OP(%%mm6, (%1), A, d) \
+ "add %3, %1 \n\t"
+
+/* vertical filter [ 0 -7 42 96 -2 -1] */
+#define QPEL_CAVSV3(A,B,C,D,E,F,OP) \
+ "movd (%0), "#F" \n\t"\
+ "movq "#C", %%mm6 \n\t"\
+ "pmullw %6, %%mm6 \n\t"\
+ "movq "#D", %%mm7 \n\t"\
+ "pmullw %5, %%mm7 \n\t"\
+ "psllw $3, "#B" \n\t"\
+ "psubw "#B", %%mm6 \n\t"\
+ "psraw $3, "#B" \n\t"\
+ "paddw %%mm7, %%mm6 \n\t"\
+ "paddw "#B", %%mm6 \n\t"\
+ "paddw "#E", "#E" \n\t"\
+ "pxor %%mm7, %%mm7 \n\t"\
+ "add %2, %0 \n\t"\
+ "punpcklbw %%mm7, "#F" \n\t"\
+ "psubw "#E", %%mm6 \n\t"\
+ "psraw $1, "#E" \n\t"\
+ "psubw "#F", %%mm6 \n\t"\
+ "paddw %4, %%mm6 \n\t"\
+ "psraw $7, %%mm6 \n\t"\
+ "packuswb %%mm6, %%mm6 \n\t"\
+ OP(%%mm6, (%1), A, d) \
+ "add %3, %1 \n\t"
+
+
+#define QPEL_CAVSVNUM(VOP,OP,ADD,MUL1,MUL2)\
+ int w= 2;\
+ src -= 2*srcStride;\
+ \
+ while(w--){\
+ asm volatile(\
+ "pxor %%mm7, %%mm7 \n\t"\
+ "movd (%0), %%mm0 \n\t"\
+ "add %2, %0 \n\t"\
+ "movd (%0), %%mm1 \n\t"\
+ "add %2, %0 \n\t"\
+ "movd (%0), %%mm2 \n\t"\
+ "add %2, %0 \n\t"\
+ "movd (%0), %%mm3 \n\t"\
+ "add %2, %0 \n\t"\
+ "movd (%0), %%mm4 \n\t"\
+ "add %2, %0 \n\t"\
+ "punpcklbw %%mm7, %%mm0 \n\t"\
+ "punpcklbw %%mm7, %%mm1 \n\t"\
+ "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)\
+ \
+ : "+a"(src), "+c"(dst)\
+ : "S"((long)srcStride), "D"((long)dstStride), "m"(ADD), "m"(MUL1), "m"(MUL2)\
+ : "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)\
+ \
+ : "+a"(src), "+c"(dst)\
+ : "S"((long)srcStride), "D"((long)dstStride), "m"(ADD), "m"(MUL1), "m"(MUL2)\
+ : "memory"\
+ );\
+ }\
+ src += 4-(h+5)*srcStride;\
+ dst += 4-h*dstStride;\
+ }
+
+#define QPEL_CAVS(OPNAME, OP, MMX)\
+static void OPNAME ## cavs_qpel8_h_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ int h=8;\
+ asm volatile(\
+ "pxor %%mm7, %%mm7 \n\t"\
+ "movq %5, %%mm6 \n\t"\
+ "1: \n\t"\
+ "movq (%0), %%mm0 \n\t"\
+ "movq 1(%0), %%mm2 \n\t"\
+ "movq %%mm0, %%mm1 \n\t"\
+ "movq %%mm2, %%mm3 \n\t"\
+ "punpcklbw %%mm7, %%mm0 \n\t"\
+ "punpckhbw %%mm7, %%mm1 \n\t"\
+ "punpcklbw %%mm7, %%mm2 \n\t"\
+ "punpckhbw %%mm7, %%mm3 \n\t"\
+ "paddw %%mm2, %%mm0 \n\t"\
+ "paddw %%mm3, %%mm1 \n\t"\
+ "pmullw %%mm6, %%mm0 \n\t"\
+ "pmullw %%mm6, %%mm1 \n\t"\
+ "movq -1(%0), %%mm2 \n\t"\
+ "movq 2(%0), %%mm4 \n\t"\
+ "movq %%mm2, %%mm3 \n\t"\
+ "movq %%mm4, %%mm5 \n\t"\
+ "punpcklbw %%mm7, %%mm2 \n\t"\
+ "punpckhbw %%mm7, %%mm3 \n\t"\
+ "punpcklbw %%mm7, %%mm4 \n\t"\
+ "punpckhbw %%mm7, %%mm5 \n\t"\
+ "paddw %%mm4, %%mm2 \n\t"\
+ "paddw %%mm3, %%mm5 \n\t"\
+ "psubw %%mm2, %%mm0 \n\t"\
+ "psubw %%mm5, %%mm1 \n\t"\
+ "movq %6, %%mm5 \n\t"\
+ "paddw %%mm5, %%mm0 \n\t"\
+ "paddw %%mm5, %%mm1 \n\t"\
+ "psraw $3, %%mm0 \n\t"\
+ "psraw $3, %%mm1 \n\t"\
+ "packuswb %%mm1, %%mm0 \n\t"\
+ OP(%%mm0, (%1),%%mm5, q) \
+ "add %3, %0 \n\t"\
+ "add %4, %1 \n\t"\
+ "decl %2 \n\t"\
+ " jnz 1b \n\t"\
+ : "+a"(src), "+c"(dst), "+m"(h)\
+ : "d"((long)srcStride), "S"((long)dstStride), "m"(ff_pw_5), "m"(ff_pw_4)\
+ : "memory"\
+ );\
+}\
+\
+static inline void OPNAME ## cavs_qpel8or16_v1_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
+ QPEL_CAVSVNUM(QPEL_CAVSV1,OP,ff_pw_64,ff_pw_96,ff_pw_42) \
+}\
+\
+static inline void OPNAME ## cavs_qpel8or16_v2_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
+ QPEL_CAVSVNUM(QPEL_CAVSV2,OP,ff_pw_4,ff_pw_5,ff_pw_5) \
+}\
+\
+static inline void OPNAME ## cavs_qpel8or16_v3_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
+ QPEL_CAVSVNUM(QPEL_CAVSV3,OP,ff_pw_64,ff_pw_96,ff_pw_42) \
+}\
+\
+static void OPNAME ## cavs_qpel8_v1_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ OPNAME ## cavs_qpel8or16_v1_ ## MMX(dst , src , dstStride, srcStride, 8);\
+}\
+static void OPNAME ## cavs_qpel16_v1_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ OPNAME ## cavs_qpel8or16_v1_ ## MMX(dst , src , dstStride, srcStride, 16);\
+ OPNAME ## cavs_qpel8or16_v1_ ## MMX(dst+8, src+8, dstStride, srcStride, 16);\
+}\
+\
+static void OPNAME ## cavs_qpel8_v2_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ OPNAME ## cavs_qpel8or16_v2_ ## MMX(dst , src , dstStride, srcStride, 8);\
+}\
+static void OPNAME ## cavs_qpel16_v2_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ OPNAME ## cavs_qpel8or16_v2_ ## MMX(dst , src , dstStride, srcStride, 16);\
+ OPNAME ## cavs_qpel8or16_v2_ ## MMX(dst+8, src+8, dstStride, srcStride, 16);\
+}\
+\
+static void OPNAME ## cavs_qpel8_v3_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ OPNAME ## cavs_qpel8or16_v3_ ## MMX(dst , src , dstStride, srcStride, 8);\
+}\
+static void OPNAME ## cavs_qpel16_v3_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ OPNAME ## cavs_qpel8or16_v3_ ## MMX(dst , src , dstStride, srcStride, 16);\
+ OPNAME ## cavs_qpel8or16_v3_ ## MMX(dst+8, src+8, dstStride, srcStride, 16);\
+}\
+\
+static void OPNAME ## cavs_qpel16_h_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ OPNAME ## cavs_qpel8_h_ ## MMX(dst , src , dstStride, srcStride);\
+ OPNAME ## cavs_qpel8_h_ ## MMX(dst+8, src+8, dstStride, srcStride);\
+ src += 8*srcStride;\
+ dst += 8*dstStride;\
+ OPNAME ## cavs_qpel8_h_ ## MMX(dst , src , dstStride, srcStride);\
+ OPNAME ## cavs_qpel8_h_ ## MMX(dst+8, src+8, dstStride, srcStride);\
+}\
+
+#define CAVS_MC(OPNAME, SIZE, MMX) \
+static void ff_ ## OPNAME ## cavs_qpel ## SIZE ## _mc20_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## cavs_qpel ## SIZE ## _h_ ## MMX(dst, src, stride, stride);\
+}\
+\
+static void ff_ ## OPNAME ## cavs_qpel ## SIZE ## _mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## cavs_qpel ## SIZE ## _v1_ ## MMX(dst, src, stride, stride);\
+}\
+\
+static void ff_ ## OPNAME ## cavs_qpel ## SIZE ## _mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## cavs_qpel ## SIZE ## _v2_ ## MMX(dst, src, stride, stride);\
+}\
+\
+static void ff_ ## OPNAME ## cavs_qpel ## SIZE ## _mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## cavs_qpel ## SIZE ## _v3_ ## MMX(dst, src, stride, stride);\
+}\
+
+#define PUT_OP(a,b,temp, size) "mov" #size " " #a ", " #b " \n\t"
+#define AVG_3DNOW_OP(a,b,temp, size) \
+"mov" #size " " #b ", " #temp " \n\t"\
+"pavgusb " #temp ", " #a " \n\t"\
+"mov" #size " " #a ", " #b " \n\t"
+#define AVG_MMX2_OP(a,b,temp, size) \
+"mov" #size " " #b ", " #temp " \n\t"\
+"pavgb " #temp ", " #a " \n\t"\
+"mov" #size " " #a ", " #b " \n\t"
+
+QPEL_CAVS(put_, PUT_OP, 3dnow)
+QPEL_CAVS(avg_, AVG_3DNOW_OP, 3dnow)
+QPEL_CAVS(put_, PUT_OP, mmx2)
+QPEL_CAVS(avg_, AVG_MMX2_OP, mmx2)
+
+CAVS_MC(put_, 8, 3dnow)
+CAVS_MC(put_, 16,3dnow)
+CAVS_MC(avg_, 8, 3dnow)
+CAVS_MC(avg_, 16,3dnow)
+CAVS_MC(put_, 8, mmx2)
+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; \
+ c->PFX ## _pixels_tab[IDX][ 2] = ff_ ## PFX ## NUM ## _mc20_mmx2; \
+ c->PFX ## _pixels_tab[IDX][ 4] = ff_ ## PFX ## NUM ## _mc01_mmx2; \
+ c->PFX ## _pixels_tab[IDX][ 8] = ff_ ## PFX ## NUM ## _mc02_mmx2; \
+ c->PFX ## _pixels_tab[IDX][12] = ff_ ## PFX ## NUM ## _mc03_mmx2; \
+
+ dspfunc(put_cavs_qpel, 0, 16);
+ dspfunc(put_cavs_qpel, 1, 8);
+ dspfunc(avg_cavs_qpel, 0, 16);
+ dspfunc(avg_cavs_qpel, 1, 8);
+#undef dspfunc
+ c->cavs_idct8_add = cavs_idct8_add_mmx;
+}
+
+void ff_cavsdsp_init_3dnow(DSPContext* c, AVCodecContext *avctx) {
+#define dspfunc(PFX, IDX, NUM) \
+ c->PFX ## _pixels_tab[IDX][ 0] = ff_ ## PFX ## NUM ## _mc00_mmx2; \
+ c->PFX ## _pixels_tab[IDX][ 2] = ff_ ## PFX ## NUM ## _mc20_3dnow; \
+ c->PFX ## _pixels_tab[IDX][ 4] = ff_ ## PFX ## NUM ## _mc01_3dnow; \
+ c->PFX ## _pixels_tab[IDX][ 8] = ff_ ## PFX ## NUM ## _mc02_3dnow; \
+ c->PFX ## _pixels_tab[IDX][12] = ff_ ## PFX ## NUM ## _mc03_3dnow; \
+
+ dspfunc(put_cavs_qpel, 0, 16);
+ dspfunc(put_cavs_qpel, 1, 8);
+ dspfunc(avg_cavs_qpel, 0, 16);
+ dspfunc(avg_cavs_qpel, 1, 8);
+#undef dspfunc
+ c->cavs_idct8_add = cavs_idct8_add_mmx;
+}
diff --git a/src/libffmpeg/libavcodec/i386/cputest.c b/contrib/ffmpeg/libavcodec/i386/cputest.c
index 0705ab3e5..0705ab3e5 100644
--- a/src/libffmpeg/libavcodec/i386/cputest.c
+++ b/contrib/ffmpeg/libavcodec/i386/cputest.c
diff --git a/contrib/ffmpeg/libavcodec/i386/dsputil_h264_template_mmx.c b/contrib/ffmpeg/libavcodec/i386/dsputil_h264_template_mmx.c
new file mode 100644
index 000000000..a943a0371
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/i386/dsputil_h264_template_mmx.c
@@ -0,0 +1,305 @@
+/*
+ * Copyright (c) 2005 Zoltan Hidvegi <hzoli -a- hzoli -d- com>,
+ * Loren Merritt
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * MMX optimized version of (put|avg)_h264_chroma_mc8.
+ * H264_CHROMA_MC8_TMPL must be defined to the desired function name
+ * H264_CHROMA_OP must be defined to empty for put and pavgb/pavgusb for avg
+ * H264_CHROMA_MC8_MV0 must be defined to a (put|avg)_pixels8 function
+ */
+static void H264_CHROMA_MC8_TMPL(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y)
+{
+ DECLARE_ALIGNED_8(uint64_t, AA);
+ DECLARE_ALIGNED_8(uint64_t, DD);
+ int i;
+
+ if(y==0 && x==0) {
+ /* no filter needed */
+ H264_CHROMA_MC8_MV0(dst, src, stride, h);
+ return;
+ }
+
+ assert(x<8 && y<8 && x>=0 && y>=0);
+
+ if(y==0 || x==0)
+ {
+ /* 1 dimensional filter only */
+ const int dxy = x ? 1 : stride;
+
+ asm volatile(
+ "movd %0, %%mm5\n\t"
+ "movq %1, %%mm4\n\t"
+ "punpcklwd %%mm5, %%mm5\n\t"
+ "punpckldq %%mm5, %%mm5\n\t" /* mm5 = B = x */
+ "movq %%mm4, %%mm6\n\t"
+ "pxor %%mm7, %%mm7\n\t"
+ "psubw %%mm5, %%mm4\n\t" /* mm4 = A = 8-x */
+ "psrlw $1, %%mm6\n\t" /* mm6 = 4 */
+ :: "rm"(x+y), "m"(ff_pw_8));
+
+ for(i=0; i<h; i++) {
+ asm volatile(
+ /* mm0 = src[0..7], mm1 = src[1..8] */
+ "movq %0, %%mm0\n\t"
+ "movq %1, %%mm2\n\t"
+ :: "m"(src[0]), "m"(src[dxy]));
+
+ asm volatile(
+ /* [mm0,mm1] = A * src[0..7] */
+ /* [mm2,mm3] = B * src[1..8] */
+ "movq %%mm0, %%mm1\n\t"
+ "movq %%mm2, %%mm3\n\t"
+ "punpcklbw %%mm7, %%mm0\n\t"
+ "punpckhbw %%mm7, %%mm1\n\t"
+ "punpcklbw %%mm7, %%mm2\n\t"
+ "punpckhbw %%mm7, %%mm3\n\t"
+ "pmullw %%mm4, %%mm0\n\t"
+ "pmullw %%mm4, %%mm1\n\t"
+ "pmullw %%mm5, %%mm2\n\t"
+ "pmullw %%mm5, %%mm3\n\t"
+
+ /* dst[0..7] = (A * src[0..7] + B * src[1..8] + 4) >> 3 */
+ "paddw %%mm6, %%mm0\n\t"
+ "paddw %%mm6, %%mm1\n\t"
+ "paddw %%mm2, %%mm0\n\t"
+ "paddw %%mm3, %%mm1\n\t"
+ "psrlw $3, %%mm0\n\t"
+ "psrlw $3, %%mm1\n\t"
+ "packuswb %%mm1, %%mm0\n\t"
+ H264_CHROMA_OP(%0, %%mm0)
+ "movq %%mm0, %0\n\t"
+ : "=m" (dst[0]));
+
+ src += stride;
+ dst += stride;
+ }
+ return;
+ }
+
+ /* general case, bilinear */
+ asm volatile("movd %2, %%mm4\n\t"
+ "movd %3, %%mm6\n\t"
+ "punpcklwd %%mm4, %%mm4\n\t"
+ "punpcklwd %%mm6, %%mm6\n\t"
+ "punpckldq %%mm4, %%mm4\n\t" /* mm4 = x words */
+ "punpckldq %%mm6, %%mm6\n\t" /* mm6 = y words */
+ "movq %%mm4, %%mm5\n\t"
+ "pmullw %%mm6, %%mm4\n\t" /* mm4 = x * y */
+ "psllw $3, %%mm5\n\t"
+ "psllw $3, %%mm6\n\t"
+ "movq %%mm5, %%mm7\n\t"
+ "paddw %%mm6, %%mm7\n\t"
+ "movq %%mm4, %1\n\t" /* DD = x * y */
+ "psubw %%mm4, %%mm5\n\t" /* mm5 = B = 8x - xy */
+ "psubw %%mm4, %%mm6\n\t" /* mm6 = C = 8y - xy */
+ "paddw %4, %%mm4\n\t"
+ "psubw %%mm7, %%mm4\n\t" /* mm4 = A = xy - (8x+8y) + 64 */
+ "pxor %%mm7, %%mm7\n\t"
+ "movq %%mm4, %0\n\t"
+ : "=m" (AA), "=m" (DD) : "rm" (x), "rm" (y), "m" (ff_pw_64));
+
+ asm volatile(
+ /* mm0 = src[0..7], mm1 = src[1..8] */
+ "movq %0, %%mm0\n\t"
+ "movq %1, %%mm1\n\t"
+ : : "m" (src[0]), "m" (src[1]));
+
+ for(i=0; i<h; i++) {
+ src += stride;
+
+ asm volatile(
+ /* mm2 = A * src[0..3] + B * src[1..4] */
+ /* mm3 = A * src[4..7] + B * src[5..8] */
+ "movq %%mm0, %%mm2\n\t"
+ "movq %%mm1, %%mm3\n\t"
+ "punpckhbw %%mm7, %%mm0\n\t"
+ "punpcklbw %%mm7, %%mm1\n\t"
+ "punpcklbw %%mm7, %%mm2\n\t"
+ "punpckhbw %%mm7, %%mm3\n\t"
+ "pmullw %0, %%mm0\n\t"
+ "pmullw %0, %%mm2\n\t"
+ "pmullw %%mm5, %%mm1\n\t"
+ "pmullw %%mm5, %%mm3\n\t"
+ "paddw %%mm1, %%mm2\n\t"
+ "paddw %%mm0, %%mm3\n\t"
+ : : "m" (AA));
+
+ asm volatile(
+ /* [mm2,mm3] += C * src[0..7] */
+ "movq %0, %%mm0\n\t"
+ "movq %%mm0, %%mm1\n\t"
+ "punpcklbw %%mm7, %%mm0\n\t"
+ "punpckhbw %%mm7, %%mm1\n\t"
+ "pmullw %%mm6, %%mm0\n\t"
+ "pmullw %%mm6, %%mm1\n\t"
+ "paddw %%mm0, %%mm2\n\t"
+ "paddw %%mm1, %%mm3\n\t"
+ : : "m" (src[0]));
+
+ asm volatile(
+ /* [mm2,mm3] += D * src[1..8] */
+ "movq %1, %%mm1\n\t"
+ "movq %%mm1, %%mm0\n\t"
+ "movq %%mm1, %%mm4\n\t"
+ "punpcklbw %%mm7, %%mm0\n\t"
+ "punpckhbw %%mm7, %%mm4\n\t"
+ "pmullw %2, %%mm0\n\t"
+ "pmullw %2, %%mm4\n\t"
+ "paddw %%mm0, %%mm2\n\t"
+ "paddw %%mm4, %%mm3\n\t"
+ "movq %0, %%mm0\n\t"
+ : : "m" (src[0]), "m" (src[1]), "m" (DD));
+
+ asm volatile(
+ /* dst[0..7] = ([mm2,mm3] + 32) >> 6 */
+ "paddw %1, %%mm2\n\t"
+ "paddw %1, %%mm3\n\t"
+ "psrlw $6, %%mm2\n\t"
+ "psrlw $6, %%mm3\n\t"
+ "packuswb %%mm3, %%mm2\n\t"
+ H264_CHROMA_OP(%0, %%mm2)
+ "movq %%mm2, %0\n\t"
+ : "=m" (dst[0]) : "m" (ff_pw_32));
+ dst+= stride;
+ }
+}
+
+static void H264_CHROMA_MC4_TMPL(uint8_t *dst/*align 4*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y)
+{
+ asm volatile(
+ "pxor %%mm7, %%mm7 \n\t"
+ "movd %5, %%mm2 \n\t"
+ "movd %6, %%mm3 \n\t"
+ "movq "MANGLE(ff_pw_8)", %%mm4\n\t"
+ "movq "MANGLE(ff_pw_8)", %%mm5\n\t"
+ "punpcklwd %%mm2, %%mm2 \n\t"
+ "punpcklwd %%mm3, %%mm3 \n\t"
+ "punpcklwd %%mm2, %%mm2 \n\t"
+ "punpcklwd %%mm3, %%mm3 \n\t"
+ "psubw %%mm2, %%mm4 \n\t"
+ "psubw %%mm3, %%mm5 \n\t"
+
+ "movd (%1), %%mm0 \n\t"
+ "movd 1(%1), %%mm6 \n\t"
+ "add %3, %1 \n\t"
+ "punpcklbw %%mm7, %%mm0 \n\t"
+ "punpcklbw %%mm7, %%mm6 \n\t"
+ "pmullw %%mm4, %%mm0 \n\t"
+ "pmullw %%mm2, %%mm6 \n\t"
+ "paddw %%mm0, %%mm6 \n\t"
+
+ "1: \n\t"
+ "movd (%1), %%mm0 \n\t"
+ "movd 1(%1), %%mm1 \n\t"
+ "add %3, %1 \n\t"
+ "punpcklbw %%mm7, %%mm0 \n\t"
+ "punpcklbw %%mm7, %%mm1 \n\t"
+ "pmullw %%mm4, %%mm0 \n\t"
+ "pmullw %%mm2, %%mm1 \n\t"
+ "paddw %%mm0, %%mm1 \n\t"
+ "movq %%mm1, %%mm0 \n\t"
+ "pmullw %%mm5, %%mm6 \n\t"
+ "pmullw %%mm3, %%mm1 \n\t"
+ "paddw %4, %%mm6 \n\t"
+ "paddw %%mm6, %%mm1 \n\t"
+ "psrlw $6, %%mm1 \n\t"
+ "packuswb %%mm1, %%mm1 \n\t"
+ H264_CHROMA_OP4((%0), %%mm1, %%mm6)
+ "movd %%mm1, (%0) \n\t"
+ "add %3, %0 \n\t"
+ "movd (%1), %%mm6 \n\t"
+ "movd 1(%1), %%mm1 \n\t"
+ "add %3, %1 \n\t"
+ "punpcklbw %%mm7, %%mm6 \n\t"
+ "punpcklbw %%mm7, %%mm1 \n\t"
+ "pmullw %%mm4, %%mm6 \n\t"
+ "pmullw %%mm2, %%mm1 \n\t"
+ "paddw %%mm6, %%mm1 \n\t"
+ "movq %%mm1, %%mm6 \n\t"
+ "pmullw %%mm5, %%mm0 \n\t"
+ "pmullw %%mm3, %%mm1 \n\t"
+ "paddw %4, %%mm0 \n\t"
+ "paddw %%mm0, %%mm1 \n\t"
+ "psrlw $6, %%mm1 \n\t"
+ "packuswb %%mm1, %%mm1 \n\t"
+ H264_CHROMA_OP4((%0), %%mm1, %%mm0)
+ "movd %%mm1, (%0) \n\t"
+ "add %3, %0 \n\t"
+ "sub $2, %2 \n\t"
+ "jnz 1b \n\t"
+ : "+r"(dst), "+r"(src), "+r"(h)
+ : "r"((long)stride), "m"(ff_pw_32), "m"(x), "m"(y)
+ );
+}
+
+#ifdef H264_CHROMA_MC2_TMPL
+static void H264_CHROMA_MC2_TMPL(uint8_t *dst/*align 2*/, uint8_t *src/*align 1*/, long stride, int h, int x, int y)
+{
+ int tmp = ((1<<16)-1)*x + 8;
+ int CD= tmp*y;
+ int AB= (tmp<<3) - CD;
+ asm volatile(
+ /* mm5 = {A,B,A,B} */
+ /* mm6 = {C,D,C,D} */
+ "movd %0, %%mm5\n\t"
+ "movd %1, %%mm6\n\t"
+ "punpckldq %%mm5, %%mm5\n\t"
+ "punpckldq %%mm6, %%mm6\n\t"
+ "pxor %%mm7, %%mm7\n\t"
+ /* mm0 = src[0,1,1,2] */
+ "movd %2, %%mm2\n\t"
+ "punpcklbw %%mm7, %%mm2\n\t"
+ "pshufw $0x94, %%mm2, %%mm2\n\t"
+ :: "r"(AB), "r"(CD), "m"(src[0]));
+
+
+ asm volatile(
+ "1:\n\t"
+ "add %4, %1\n\t"
+ /* mm1 = A * src[0,1] + B * src[1,2] */
+ "movq %%mm2, %%mm1\n\t"
+ "pmaddwd %%mm5, %%mm1\n\t"
+ /* mm0 = src[0,1,1,2] */
+ "movd (%1), %%mm0\n\t"
+ "punpcklbw %%mm7, %%mm0\n\t"
+ "pshufw $0x94, %%mm0, %%mm0\n\t"
+ /* mm1 += C * src[0,1] + D * src[1,2] */
+ "movq %%mm0, %%mm2\n\t"
+ "pmaddwd %%mm6, %%mm0\n\t"
+ "paddw %3, %%mm1\n\t"
+ "paddw %%mm0, %%mm1\n\t"
+ /* dst[0,1] = pack((mm1 + 32) >> 6) */
+ "psrlw $6, %%mm1\n\t"
+ "packssdw %%mm7, %%mm1\n\t"
+ "packuswb %%mm7, %%mm1\n\t"
+ H264_CHROMA_OP4((%0), %%mm1, %%mm3)
+ "movd %%mm1, %%esi\n\t"
+ "movw %%si, (%0)\n\t"
+ "add %4, %0\n\t"
+ "sub $1, %2\n\t"
+ "jnz 1b\n\t"
+ : "+r" (dst), "+r"(src), "+r"(h)
+ : "m" (ff_pw_32), "r"(stride)
+ : "%esi");
+
+}
+#endif
+
diff --git a/contrib/ffmpeg/libavcodec/i386/dsputil_mmx.c b/contrib/ffmpeg/libavcodec/i386/dsputil_mmx.c
new file mode 100644
index 000000000..23a717acd
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/i386/dsputil_mmx.c
@@ -0,0 +1,3568 @@
+/*
+ * MMX optimized DSP utils
+ * Copyright (c) 2000, 2001 Fabrice Bellard.
+ * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
+ */
+
+#include "../dsputil.h"
+#include "../simple_idct.h"
+#include "../mpegvideo.h"
+#include "x86_cpu.h"
+#include "mmx.h"
+
+//#undef NDEBUG
+//#include <assert.h>
+
+extern void ff_idct_xvid_mmx(short *block);
+extern void ff_idct_xvid_mmx2(short *block);
+
+int mm_flags; /* multimedia extension flags */
+
+/* pixel operations */
+static const uint64_t mm_bone attribute_used __attribute__ ((aligned(8))) = 0x0101010101010101ULL;
+static const uint64_t mm_wone attribute_used __attribute__ ((aligned(8))) = 0x0001000100010001ULL;
+static const uint64_t mm_wtwo attribute_used __attribute__ ((aligned(8))) = 0x0002000200020002ULL;
+
+static const uint64_t ff_pdw_80000000[2] attribute_used __attribute__ ((aligned(16))) =
+{0x8000000080000000ULL, 0x8000000080000000ULL};
+
+static const uint64_t ff_pw_20 attribute_used __attribute__ ((aligned(8))) = 0x0014001400140014ULL;
+static const uint64_t ff_pw_3 attribute_used __attribute__ ((aligned(8))) = 0x0003000300030003ULL;
+static const uint64_t ff_pw_4 attribute_used __attribute__ ((aligned(8))) = 0x0004000400040004ULL;
+static const uint64_t ff_pw_5 attribute_used __attribute__ ((aligned(8))) = 0x0005000500050005ULL;
+static const uint64_t ff_pw_8 attribute_used __attribute__ ((aligned(8))) = 0x0008000800080008ULL;
+static const uint64_t ff_pw_16 attribute_used __attribute__ ((aligned(8))) = 0x0010001000100010ULL;
+static const uint64_t ff_pw_32 attribute_used __attribute__ ((aligned(8))) = 0x0020002000200020ULL;
+static const uint64_t ff_pw_64 attribute_used __attribute__ ((aligned(8))) = 0x0040004000400040ULL;
+static const uint64_t ff_pw_15 attribute_used __attribute__ ((aligned(8))) = 0x000F000F000F000FULL;
+
+static const uint64_t ff_pb_1 attribute_used __attribute__ ((aligned(8))) = 0x0101010101010101ULL;
+static const uint64_t ff_pb_3 attribute_used __attribute__ ((aligned(8))) = 0x0303030303030303ULL;
+static const uint64_t ff_pb_7 attribute_used __attribute__ ((aligned(8))) = 0x0707070707070707ULL;
+static const uint64_t ff_pb_3F attribute_used __attribute__ ((aligned(8))) = 0x3F3F3F3F3F3F3F3FULL;
+static const uint64_t ff_pb_A1 attribute_used __attribute__ ((aligned(8))) = 0xA1A1A1A1A1A1A1A1ULL;
+static const uint64_t ff_pb_5F attribute_used __attribute__ ((aligned(8))) = 0x5F5F5F5F5F5F5F5FULL;
+static const uint64_t ff_pb_FC attribute_used __attribute__ ((aligned(8))) = 0xFCFCFCFCFCFCFCFCULL;
+
+#define JUMPALIGN() __asm __volatile (ASMALIGN(3)::)
+#define MOVQ_ZERO(regd) __asm __volatile ("pxor %%" #regd ", %%" #regd ::)
+
+#define MOVQ_WONE(regd) \
+ __asm __volatile ( \
+ "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
+ "psrlw $15, %%" #regd ::)
+
+#define MOVQ_BFE(regd) \
+ __asm __volatile ( \
+ "pcmpeqd %%" #regd ", %%" #regd " \n\t"\
+ "paddb %%" #regd ", %%" #regd " \n\t" ::)
+
+#ifndef PIC
+#define MOVQ_BONE(regd) __asm __volatile ("movq %0, %%" #regd " \n\t" ::"m"(mm_bone))
+#define MOVQ_WTWO(regd) __asm __volatile ("movq %0, %%" #regd " \n\t" ::"m"(mm_wtwo))
+#else
+// for shared library it's better to use this way for accessing constants
+// pcmpeqd -> -1
+#define MOVQ_BONE(regd) \
+ __asm __volatile ( \
+ "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
+ "psrlw $15, %%" #regd " \n\t" \
+ "packuswb %%" #regd ", %%" #regd " \n\t" ::)
+
+#define MOVQ_WTWO(regd) \
+ __asm __volatile ( \
+ "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
+ "psrlw $15, %%" #regd " \n\t" \
+ "psllw $1, %%" #regd " \n\t"::)
+
+#endif
+
+// using regr as temporary and for the output result
+// first argument is unmodifed and second is trashed
+// regfe is supposed to contain 0xfefefefefefefefe
+#define PAVGB_MMX_NO_RND(rega, regb, regr, regfe) \
+ "movq " #rega ", " #regr " \n\t"\
+ "pand " #regb ", " #regr " \n\t"\
+ "pxor " #rega ", " #regb " \n\t"\
+ "pand " #regfe "," #regb " \n\t"\
+ "psrlq $1, " #regb " \n\t"\
+ "paddb " #regb ", " #regr " \n\t"
+
+#define PAVGB_MMX(rega, regb, regr, regfe) \
+ "movq " #rega ", " #regr " \n\t"\
+ "por " #regb ", " #regr " \n\t"\
+ "pxor " #rega ", " #regb " \n\t"\
+ "pand " #regfe "," #regb " \n\t"\
+ "psrlq $1, " #regb " \n\t"\
+ "psubb " #regb ", " #regr " \n\t"
+
+// mm6 is supposed to contain 0xfefefefefefefefe
+#define PAVGBP_MMX_NO_RND(rega, regb, regr, regc, regd, regp) \
+ "movq " #rega ", " #regr " \n\t"\
+ "movq " #regc ", " #regp " \n\t"\
+ "pand " #regb ", " #regr " \n\t"\
+ "pand " #regd ", " #regp " \n\t"\
+ "pxor " #rega ", " #regb " \n\t"\
+ "pxor " #regc ", " #regd " \n\t"\
+ "pand %%mm6, " #regb " \n\t"\
+ "pand %%mm6, " #regd " \n\t"\
+ "psrlq $1, " #regb " \n\t"\
+ "psrlq $1, " #regd " \n\t"\
+ "paddb " #regb ", " #regr " \n\t"\
+ "paddb " #regd ", " #regp " \n\t"
+
+#define PAVGBP_MMX(rega, regb, regr, regc, regd, regp) \
+ "movq " #rega ", " #regr " \n\t"\
+ "movq " #regc ", " #regp " \n\t"\
+ "por " #regb ", " #regr " \n\t"\
+ "por " #regd ", " #regp " \n\t"\
+ "pxor " #rega ", " #regb " \n\t"\
+ "pxor " #regc ", " #regd " \n\t"\
+ "pand %%mm6, " #regb " \n\t"\
+ "pand %%mm6, " #regd " \n\t"\
+ "psrlq $1, " #regd " \n\t"\
+ "psrlq $1, " #regb " \n\t"\
+ "psubb " #regb ", " #regr " \n\t"\
+ "psubb " #regd ", " #regp " \n\t"
+
+/***********************************/
+/* MMX no rounding */
+#define DEF(x, y) x ## _no_rnd_ ## y ##_mmx
+#define SET_RND MOVQ_WONE
+#define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX_NO_RND(a, b, c, d, e, f)
+#define PAVGB(a, b, c, e) PAVGB_MMX_NO_RND(a, b, c, e)
+
+#include "dsputil_mmx_rnd.h"
+
+#undef DEF
+#undef SET_RND
+#undef PAVGBP
+#undef PAVGB
+/***********************************/
+/* MMX rounding */
+
+#define DEF(x, y) x ## _ ## y ##_mmx
+#define SET_RND MOVQ_WTWO
+#define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX(a, b, c, d, e, f)
+#define PAVGB(a, b, c, e) PAVGB_MMX(a, b, c, e)
+
+#include "dsputil_mmx_rnd.h"
+
+#undef DEF
+#undef SET_RND
+#undef PAVGBP
+#undef PAVGB
+
+/***********************************/
+/* 3Dnow specific */
+
+#define DEF(x) x ## _3dnow
+/* for Athlons PAVGUSB is prefered */
+#define PAVGB "pavgusb"
+
+#include "dsputil_mmx_avg.h"
+
+#undef DEF
+#undef PAVGB
+
+/***********************************/
+/* MMX2 specific */
+
+#define DEF(x) x ## _mmx2
+
+/* Introduced only in MMX2 set */
+#define PAVGB "pavgb"
+
+#include "dsputil_mmx_avg.h"
+
+#undef DEF
+#undef PAVGB
+
+#define SBUTTERFLY(a,b,t,n)\
+ "movq " #a ", " #t " \n\t" /* abcd */\
+ "punpckl" #n " " #b ", " #a " \n\t" /* aebf */\
+ "punpckh" #n " " #b ", " #t " \n\t" /* cgdh */\
+
+/***********************************/
+/* standard MMX */
+
+#ifdef CONFIG_ENCODERS
+static void get_pixels_mmx(DCTELEM *block, const uint8_t *pixels, int line_size)
+{
+ asm volatile(
+ "mov $-128, %%"REG_a" \n\t"
+ "pxor %%mm7, %%mm7 \n\t"
+ ASMALIGN(4)
+ "1: \n\t"
+ "movq (%0), %%mm0 \n\t"
+ "movq (%0, %2), %%mm2 \n\t"
+ "movq %%mm0, %%mm1 \n\t"
+ "movq %%mm2, %%mm3 \n\t"
+ "punpcklbw %%mm7, %%mm0 \n\t"
+ "punpckhbw %%mm7, %%mm1 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t"
+ "punpckhbw %%mm7, %%mm3 \n\t"
+ "movq %%mm0, (%1, %%"REG_a") \n\t"
+ "movq %%mm1, 8(%1, %%"REG_a") \n\t"
+ "movq %%mm2, 16(%1, %%"REG_a") \n\t"
+ "movq %%mm3, 24(%1, %%"REG_a") \n\t"
+ "add %3, %0 \n\t"
+ "add $32, %%"REG_a" \n\t"
+ "js 1b \n\t"
+ : "+r" (pixels)
+ : "r" (block+64), "r" ((long)line_size), "r" ((long)line_size*2)
+ : "%"REG_a
+ );
+}
+
+static inline void diff_pixels_mmx(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, int stride)
+{
+ asm volatile(
+ "pxor %%mm7, %%mm7 \n\t"
+ "mov $-128, %%"REG_a" \n\t"
+ ASMALIGN(4)
+ "1: \n\t"
+ "movq (%0), %%mm0 \n\t"
+ "movq (%1), %%mm2 \n\t"
+ "movq %%mm0, %%mm1 \n\t"
+ "movq %%mm2, %%mm3 \n\t"
+ "punpcklbw %%mm7, %%mm0 \n\t"
+ "punpckhbw %%mm7, %%mm1 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t"
+ "punpckhbw %%mm7, %%mm3 \n\t"
+ "psubw %%mm2, %%mm0 \n\t"
+ "psubw %%mm3, %%mm1 \n\t"
+ "movq %%mm0, (%2, %%"REG_a") \n\t"
+ "movq %%mm1, 8(%2, %%"REG_a") \n\t"
+ "add %3, %0 \n\t"
+ "add %3, %1 \n\t"
+ "add $16, %%"REG_a" \n\t"
+ "jnz 1b \n\t"
+ : "+r" (s1), "+r" (s2)
+ : "r" (block+64), "r" ((long)stride)
+ : "%"REG_a
+ );
+}
+#endif //CONFIG_ENCODERS
+
+void put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
+{
+ const DCTELEM *p;
+ uint8_t *pix;
+
+ /* read the pixels */
+ p = block;
+ pix = pixels;
+ /* unrolled loop */
+ __asm __volatile(
+ "movq %3, %%mm0 \n\t"
+ "movq 8%3, %%mm1 \n\t"
+ "movq 16%3, %%mm2 \n\t"
+ "movq 24%3, %%mm3 \n\t"
+ "movq 32%3, %%mm4 \n\t"
+ "movq 40%3, %%mm5 \n\t"
+ "movq 48%3, %%mm6 \n\t"
+ "movq 56%3, %%mm7 \n\t"
+ "packuswb %%mm1, %%mm0 \n\t"
+ "packuswb %%mm3, %%mm2 \n\t"
+ "packuswb %%mm5, %%mm4 \n\t"
+ "packuswb %%mm7, %%mm6 \n\t"
+ "movq %%mm0, (%0) \n\t"
+ "movq %%mm2, (%0, %1) \n\t"
+ "movq %%mm4, (%0, %1, 2) \n\t"
+ "movq %%mm6, (%0, %2) \n\t"
+ ::"r" (pix), "r" ((long)line_size), "r" ((long)line_size*3), "m"(*p)
+ :"memory");
+ pix += line_size*4;
+ p += 32;
+
+ // if here would be an exact copy of the code above
+ // compiler would generate some very strange code
+ // thus using "r"
+ __asm __volatile(
+ "movq (%3), %%mm0 \n\t"
+ "movq 8(%3), %%mm1 \n\t"
+ "movq 16(%3), %%mm2 \n\t"
+ "movq 24(%3), %%mm3 \n\t"
+ "movq 32(%3), %%mm4 \n\t"
+ "movq 40(%3), %%mm5 \n\t"
+ "movq 48(%3), %%mm6 \n\t"
+ "movq 56(%3), %%mm7 \n\t"
+ "packuswb %%mm1, %%mm0 \n\t"
+ "packuswb %%mm3, %%mm2 \n\t"
+ "packuswb %%mm5, %%mm4 \n\t"
+ "packuswb %%mm7, %%mm6 \n\t"
+ "movq %%mm0, (%0) \n\t"
+ "movq %%mm2, (%0, %1) \n\t"
+ "movq %%mm4, (%0, %1, 2) \n\t"
+ "movq %%mm6, (%0, %2) \n\t"
+ ::"r" (pix), "r" ((long)line_size), "r" ((long)line_size*3), "r"(p)
+ :"memory");
+}
+
+static DECLARE_ALIGNED_8(const unsigned char, vector128[8]) =
+ { 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 };
+
+void put_signed_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
+{
+ int i;
+
+ movq_m2r(*vector128, mm1);
+ for (i = 0; i < 8; i++) {
+ movq_m2r(*(block), mm0);
+ packsswb_m2r(*(block + 4), mm0);
+ block += 8;
+ paddb_r2r(mm1, mm0);
+ movq_r2m(mm0, *pixels);
+ pixels += line_size;
+ }
+}
+
+void add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
+{
+ const DCTELEM *p;
+ uint8_t *pix;
+ int i;
+
+ /* read the pixels */
+ p = block;
+ pix = pixels;
+ MOVQ_ZERO(mm7);
+ i = 4;
+ do {
+ __asm __volatile(
+ "movq (%2), %%mm0 \n\t"
+ "movq 8(%2), %%mm1 \n\t"
+ "movq 16(%2), %%mm2 \n\t"
+ "movq 24(%2), %%mm3 \n\t"
+ "movq %0, %%mm4 \n\t"
+ "movq %1, %%mm6 \n\t"
+ "movq %%mm4, %%mm5 \n\t"
+ "punpcklbw %%mm7, %%mm4 \n\t"
+ "punpckhbw %%mm7, %%mm5 \n\t"
+ "paddsw %%mm4, %%mm0 \n\t"
+ "paddsw %%mm5, %%mm1 \n\t"
+ "movq %%mm6, %%mm5 \n\t"
+ "punpcklbw %%mm7, %%mm6 \n\t"
+ "punpckhbw %%mm7, %%mm5 \n\t"
+ "paddsw %%mm6, %%mm2 \n\t"
+ "paddsw %%mm5, %%mm3 \n\t"
+ "packuswb %%mm1, %%mm0 \n\t"
+ "packuswb %%mm3, %%mm2 \n\t"
+ "movq %%mm0, %0 \n\t"
+ "movq %%mm2, %1 \n\t"
+ :"+m"(*pix), "+m"(*(pix+line_size))
+ :"r"(p)
+ :"memory");
+ pix += line_size*2;
+ p += 16;
+ } while (--i);
+}
+
+static void put_pixels4_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
+{
+ __asm __volatile(
+ "lea (%3, %3), %%"REG_a" \n\t"
+ ASMALIGN(3)
+ "1: \n\t"
+ "movd (%1), %%mm0 \n\t"
+ "movd (%1, %3), %%mm1 \n\t"
+ "movd %%mm0, (%2) \n\t"
+ "movd %%mm1, (%2, %3) \n\t"
+ "add %%"REG_a", %1 \n\t"
+ "add %%"REG_a", %2 \n\t"
+ "movd (%1), %%mm0 \n\t"
+ "movd (%1, %3), %%mm1 \n\t"
+ "movd %%mm0, (%2) \n\t"
+ "movd %%mm1, (%2, %3) \n\t"
+ "add %%"REG_a", %1 \n\t"
+ "add %%"REG_a", %2 \n\t"
+ "subl $4, %0 \n\t"
+ "jnz 1b \n\t"
+ : "+g"(h), "+r" (pixels), "+r" (block)
+ : "r"((long)line_size)
+ : "%"REG_a, "memory"
+ );
+}
+
+static void put_pixels8_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
+{
+ __asm __volatile(
+ "lea (%3, %3), %%"REG_a" \n\t"
+ ASMALIGN(3)
+ "1: \n\t"
+ "movq (%1), %%mm0 \n\t"
+ "movq (%1, %3), %%mm1 \n\t"
+ "movq %%mm0, (%2) \n\t"
+ "movq %%mm1, (%2, %3) \n\t"
+ "add %%"REG_a", %1 \n\t"
+ "add %%"REG_a", %2 \n\t"
+ "movq (%1), %%mm0 \n\t"
+ "movq (%1, %3), %%mm1 \n\t"
+ "movq %%mm0, (%2) \n\t"
+ "movq %%mm1, (%2, %3) \n\t"
+ "add %%"REG_a", %1 \n\t"
+ "add %%"REG_a", %2 \n\t"
+ "subl $4, %0 \n\t"
+ "jnz 1b \n\t"
+ : "+g"(h), "+r" (pixels), "+r" (block)
+ : "r"((long)line_size)
+ : "%"REG_a, "memory"
+ );
+}
+
+static void put_pixels16_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
+{
+ __asm __volatile(
+ "lea (%3, %3), %%"REG_a" \n\t"
+ ASMALIGN(3)
+ "1: \n\t"
+ "movq (%1), %%mm0 \n\t"
+ "movq 8(%1), %%mm4 \n\t"
+ "movq (%1, %3), %%mm1 \n\t"
+ "movq 8(%1, %3), %%mm5 \n\t"
+ "movq %%mm0, (%2) \n\t"
+ "movq %%mm4, 8(%2) \n\t"
+ "movq %%mm1, (%2, %3) \n\t"
+ "movq %%mm5, 8(%2, %3) \n\t"
+ "add %%"REG_a", %1 \n\t"
+ "add %%"REG_a", %2 \n\t"
+ "movq (%1), %%mm0 \n\t"
+ "movq 8(%1), %%mm4 \n\t"
+ "movq (%1, %3), %%mm1 \n\t"
+ "movq 8(%1, %3), %%mm5 \n\t"
+ "movq %%mm0, (%2) \n\t"
+ "movq %%mm4, 8(%2) \n\t"
+ "movq %%mm1, (%2, %3) \n\t"
+ "movq %%mm5, 8(%2, %3) \n\t"
+ "add %%"REG_a", %1 \n\t"
+ "add %%"REG_a", %2 \n\t"
+ "subl $4, %0 \n\t"
+ "jnz 1b \n\t"
+ : "+g"(h), "+r" (pixels), "+r" (block)
+ : "r"((long)line_size)
+ : "%"REG_a, "memory"
+ );
+}
+
+static void clear_blocks_mmx(DCTELEM *blocks)
+{
+ __asm __volatile(
+ "pxor %%mm7, %%mm7 \n\t"
+ "mov $-128*6, %%"REG_a" \n\t"
+ "1: \n\t"
+ "movq %%mm7, (%0, %%"REG_a") \n\t"
+ "movq %%mm7, 8(%0, %%"REG_a") \n\t"
+ "movq %%mm7, 16(%0, %%"REG_a") \n\t"
+ "movq %%mm7, 24(%0, %%"REG_a") \n\t"
+ "add $32, %%"REG_a" \n\t"
+ " js 1b \n\t"
+ : : "r" (((uint8_t *)blocks)+128*6)
+ : "%"REG_a
+ );
+}
+
+#ifdef CONFIG_ENCODERS
+static int pix_sum16_mmx(uint8_t * pix, int line_size){
+ const int h=16;
+ int sum;
+ long index= -line_size*h;
+
+ __asm __volatile(
+ "pxor %%mm7, %%mm7 \n\t"
+ "pxor %%mm6, %%mm6 \n\t"
+ "1: \n\t"
+ "movq (%2, %1), %%mm0 \n\t"
+ "movq (%2, %1), %%mm1 \n\t"
+ "movq 8(%2, %1), %%mm2 \n\t"
+ "movq 8(%2, %1), %%mm3 \n\t"
+ "punpcklbw %%mm7, %%mm0 \n\t"
+ "punpckhbw %%mm7, %%mm1 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t"
+ "punpckhbw %%mm7, %%mm3 \n\t"
+ "paddw %%mm0, %%mm1 \n\t"
+ "paddw %%mm2, %%mm3 \n\t"
+ "paddw %%mm1, %%mm3 \n\t"
+ "paddw %%mm3, %%mm6 \n\t"
+ "add %3, %1 \n\t"
+ " js 1b \n\t"
+ "movq %%mm6, %%mm5 \n\t"
+ "psrlq $32, %%mm6 \n\t"
+ "paddw %%mm5, %%mm6 \n\t"
+ "movq %%mm6, %%mm5 \n\t"
+ "psrlq $16, %%mm6 \n\t"
+ "paddw %%mm5, %%mm6 \n\t"
+ "movd %%mm6, %0 \n\t"
+ "andl $0xFFFF, %0 \n\t"
+ : "=&r" (sum), "+r" (index)
+ : "r" (pix - index), "r" ((long)line_size)
+ );
+
+ return sum;
+}
+#endif //CONFIG_ENCODERS
+
+static void add_bytes_mmx(uint8_t *dst, uint8_t *src, int w){
+ long i=0;
+ asm volatile(
+ "1: \n\t"
+ "movq (%1, %0), %%mm0 \n\t"
+ "movq (%2, %0), %%mm1 \n\t"
+ "paddb %%mm0, %%mm1 \n\t"
+ "movq %%mm1, (%2, %0) \n\t"
+ "movq 8(%1, %0), %%mm0 \n\t"
+ "movq 8(%2, %0), %%mm1 \n\t"
+ "paddb %%mm0, %%mm1 \n\t"
+ "movq %%mm1, 8(%2, %0) \n\t"
+ "add $16, %0 \n\t"
+ "cmp %3, %0 \n\t"
+ " jb 1b \n\t"
+ : "+r" (i)
+ : "r"(src), "r"(dst), "r"((long)w-15)
+ );
+ for(; i<w; i++)
+ dst[i+0] += src[i+0];
+}
+
+#define H263_LOOP_FILTER \
+ "pxor %%mm7, %%mm7 \n\t"\
+ "movq %0, %%mm0 \n\t"\
+ "movq %0, %%mm1 \n\t"\
+ "movq %3, %%mm2 \n\t"\
+ "movq %3, %%mm3 \n\t"\
+ "punpcklbw %%mm7, %%mm0 \n\t"\
+ "punpckhbw %%mm7, %%mm1 \n\t"\
+ "punpcklbw %%mm7, %%mm2 \n\t"\
+ "punpckhbw %%mm7, %%mm3 \n\t"\
+ "psubw %%mm2, %%mm0 \n\t"\
+ "psubw %%mm3, %%mm1 \n\t"\
+ "movq %1, %%mm2 \n\t"\
+ "movq %1, %%mm3 \n\t"\
+ "movq %2, %%mm4 \n\t"\
+ "movq %2, %%mm5 \n\t"\
+ "punpcklbw %%mm7, %%mm2 \n\t"\
+ "punpckhbw %%mm7, %%mm3 \n\t"\
+ "punpcklbw %%mm7, %%mm4 \n\t"\
+ "punpckhbw %%mm7, %%mm5 \n\t"\
+ "psubw %%mm2, %%mm4 \n\t"\
+ "psubw %%mm3, %%mm5 \n\t"\
+ "psllw $2, %%mm4 \n\t"\
+ "psllw $2, %%mm5 \n\t"\
+ "paddw %%mm0, %%mm4 \n\t"\
+ "paddw %%mm1, %%mm5 \n\t"\
+ "pxor %%mm6, %%mm6 \n\t"\
+ "pcmpgtw %%mm4, %%mm6 \n\t"\
+ "pcmpgtw %%mm5, %%mm7 \n\t"\
+ "pxor %%mm6, %%mm4 \n\t"\
+ "pxor %%mm7, %%mm5 \n\t"\
+ "psubw %%mm6, %%mm4 \n\t"\
+ "psubw %%mm7, %%mm5 \n\t"\
+ "psrlw $3, %%mm4 \n\t"\
+ "psrlw $3, %%mm5 \n\t"\
+ "packuswb %%mm5, %%mm4 \n\t"\
+ "packsswb %%mm7, %%mm6 \n\t"\
+ "pxor %%mm7, %%mm7 \n\t"\
+ "movd %4, %%mm2 \n\t"\
+ "punpcklbw %%mm2, %%mm2 \n\t"\
+ "punpcklbw %%mm2, %%mm2 \n\t"\
+ "punpcklbw %%mm2, %%mm2 \n\t"\
+ "psubusb %%mm4, %%mm2 \n\t"\
+ "movq %%mm2, %%mm3 \n\t"\
+ "psubusb %%mm4, %%mm3 \n\t"\
+ "psubb %%mm3, %%mm2 \n\t"\
+ "movq %1, %%mm3 \n\t"\
+ "movq %2, %%mm4 \n\t"\
+ "pxor %%mm6, %%mm3 \n\t"\
+ "pxor %%mm6, %%mm4 \n\t"\
+ "paddusb %%mm2, %%mm3 \n\t"\
+ "psubusb %%mm2, %%mm4 \n\t"\
+ "pxor %%mm6, %%mm3 \n\t"\
+ "pxor %%mm6, %%mm4 \n\t"\
+ "paddusb %%mm2, %%mm2 \n\t"\
+ "packsswb %%mm1, %%mm0 \n\t"\
+ "pcmpgtb %%mm0, %%mm7 \n\t"\
+ "pxor %%mm7, %%mm0 \n\t"\
+ "psubb %%mm7, %%mm0 \n\t"\
+ "movq %%mm0, %%mm1 \n\t"\
+ "psubusb %%mm2, %%mm0 \n\t"\
+ "psubb %%mm0, %%mm1 \n\t"\
+ "pand %5, %%mm1 \n\t"\
+ "psrlw $2, %%mm1 \n\t"\
+ "pxor %%mm7, %%mm1 \n\t"\
+ "psubb %%mm7, %%mm1 \n\t"\
+ "movq %0, %%mm5 \n\t"\
+ "movq %3, %%mm6 \n\t"\
+ "psubb %%mm1, %%mm5 \n\t"\
+ "paddb %%mm1, %%mm6 \n\t"
+
+static void h263_v_loop_filter_mmx(uint8_t *src, int stride, int qscale){
+ const int strength= ff_h263_loop_filter_strength[qscale];
+
+ asm volatile(
+
+ H263_LOOP_FILTER
+
+ "movq %%mm3, %1 \n\t"
+ "movq %%mm4, %2 \n\t"
+ "movq %%mm5, %0 \n\t"
+ "movq %%mm6, %3 \n\t"
+ : "+m" (*(uint64_t*)(src - 2*stride)),
+ "+m" (*(uint64_t*)(src - 1*stride)),
+ "+m" (*(uint64_t*)(src + 0*stride)),
+ "+m" (*(uint64_t*)(src + 1*stride))
+ : "g" (2*strength), "m"(ff_pb_FC)
+ );
+}
+
+static inline void transpose4x4(uint8_t *dst, uint8_t *src, int dst_stride, int src_stride){
+ asm volatile( //FIXME could save 1 instruction if done as 8x4 ...
+ "movd %4, %%mm0 \n\t"
+ "movd %5, %%mm1 \n\t"
+ "movd %6, %%mm2 \n\t"
+ "movd %7, %%mm3 \n\t"
+ "punpcklbw %%mm1, %%mm0 \n\t"
+ "punpcklbw %%mm3, %%mm2 \n\t"
+ "movq %%mm0, %%mm1 \n\t"
+ "punpcklwd %%mm2, %%mm0 \n\t"
+ "punpckhwd %%mm2, %%mm1 \n\t"
+ "movd %%mm0, %0 \n\t"
+ "punpckhdq %%mm0, %%mm0 \n\t"
+ "movd %%mm0, %1 \n\t"
+ "movd %%mm1, %2 \n\t"
+ "punpckhdq %%mm1, %%mm1 \n\t"
+ "movd %%mm1, %3 \n\t"
+
+ : "=m" (*(uint32_t*)(dst + 0*dst_stride)),
+ "=m" (*(uint32_t*)(dst + 1*dst_stride)),
+ "=m" (*(uint32_t*)(dst + 2*dst_stride)),
+ "=m" (*(uint32_t*)(dst + 3*dst_stride))
+ : "m" (*(uint32_t*)(src + 0*src_stride)),
+ "m" (*(uint32_t*)(src + 1*src_stride)),
+ "m" (*(uint32_t*)(src + 2*src_stride)),
+ "m" (*(uint32_t*)(src + 3*src_stride))
+ );
+}
+
+static void h263_h_loop_filter_mmx(uint8_t *src, int stride, int qscale){
+ const int strength= ff_h263_loop_filter_strength[qscale];
+ uint64_t temp[4] __attribute__ ((aligned(8)));
+ uint8_t *btemp= (uint8_t*)temp;
+
+ src -= 2;
+
+ transpose4x4(btemp , src , 8, stride);
+ transpose4x4(btemp+4, src + 4*stride, 8, stride);
+ asm volatile(
+ H263_LOOP_FILTER // 5 3 4 6
+
+ : "+m" (temp[0]),
+ "+m" (temp[1]),
+ "+m" (temp[2]),
+ "+m" (temp[3])
+ : "g" (2*strength), "m"(ff_pb_FC)
+ );
+
+ asm volatile(
+ "movq %%mm5, %%mm1 \n\t"
+ "movq %%mm4, %%mm0 \n\t"
+ "punpcklbw %%mm3, %%mm5 \n\t"
+ "punpcklbw %%mm6, %%mm4 \n\t"
+ "punpckhbw %%mm3, %%mm1 \n\t"
+ "punpckhbw %%mm6, %%mm0 \n\t"
+ "movq %%mm5, %%mm3 \n\t"
+ "movq %%mm1, %%mm6 \n\t"
+ "punpcklwd %%mm4, %%mm5 \n\t"
+ "punpcklwd %%mm0, %%mm1 \n\t"
+ "punpckhwd %%mm4, %%mm3 \n\t"
+ "punpckhwd %%mm0, %%mm6 \n\t"
+ "movd %%mm5, (%0) \n\t"
+ "punpckhdq %%mm5, %%mm5 \n\t"
+ "movd %%mm5, (%0,%2) \n\t"
+ "movd %%mm3, (%0,%2,2) \n\t"
+ "punpckhdq %%mm3, %%mm3 \n\t"
+ "movd %%mm3, (%0,%3) \n\t"
+ "movd %%mm1, (%1) \n\t"
+ "punpckhdq %%mm1, %%mm1 \n\t"
+ "movd %%mm1, (%1,%2) \n\t"
+ "movd %%mm6, (%1,%2,2) \n\t"
+ "punpckhdq %%mm6, %%mm6 \n\t"
+ "movd %%mm6, (%1,%3) \n\t"
+ :: "r" (src),
+ "r" (src + 4*stride),
+ "r" ((long) stride ),
+ "r" ((long)(3*stride))
+ );
+}
+
+#ifdef CONFIG_ENCODERS
+static int pix_norm1_mmx(uint8_t *pix, int line_size) {
+ int tmp;
+ asm volatile (
+ "movl $16,%%ecx\n"
+ "pxor %%mm0,%%mm0\n"
+ "pxor %%mm7,%%mm7\n"
+ "1:\n"
+ "movq (%0),%%mm2\n" /* mm2 = pix[0-7] */
+ "movq 8(%0),%%mm3\n" /* mm3 = pix[8-15] */
+
+ "movq %%mm2,%%mm1\n" /* mm1 = mm2 = pix[0-7] */
+
+ "punpckhbw %%mm0,%%mm1\n" /* mm1 = [pix4-7] */
+ "punpcklbw %%mm0,%%mm2\n" /* mm2 = [pix0-3] */
+
+ "movq %%mm3,%%mm4\n" /* mm4 = mm3 = pix[8-15] */
+ "punpckhbw %%mm0,%%mm3\n" /* mm3 = [pix12-15] */
+ "punpcklbw %%mm0,%%mm4\n" /* mm4 = [pix8-11] */
+
+ "pmaddwd %%mm1,%%mm1\n" /* mm1 = (pix0^2+pix1^2,pix2^2+pix3^2) */
+ "pmaddwd %%mm2,%%mm2\n" /* mm2 = (pix4^2+pix5^2,pix6^2+pix7^2) */
+
+ "pmaddwd %%mm3,%%mm3\n"
+ "pmaddwd %%mm4,%%mm4\n"
+
+ "paddd %%mm1,%%mm2\n" /* mm2 = (pix0^2+pix1^2+pix4^2+pix5^2,
+ pix2^2+pix3^2+pix6^2+pix7^2) */
+ "paddd %%mm3,%%mm4\n"
+ "paddd %%mm2,%%mm7\n"
+
+ "add %2, %0\n"
+ "paddd %%mm4,%%mm7\n"
+ "dec %%ecx\n"
+ "jnz 1b\n"
+
+ "movq %%mm7,%%mm1\n"
+ "psrlq $32, %%mm7\n" /* shift hi dword to lo */
+ "paddd %%mm7,%%mm1\n"
+ "movd %%mm1,%1\n"
+ : "+r" (pix), "=r"(tmp) : "r" ((long)line_size) : "%ecx" );
+ return tmp;
+}
+
+static int sse8_mmx(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
+ int tmp;
+ asm volatile (
+ "movl %4,%%ecx\n"
+ "shr $1,%%ecx\n"
+ "pxor %%mm0,%%mm0\n" /* mm0 = 0 */
+ "pxor %%mm7,%%mm7\n" /* mm7 holds the sum */
+ "1:\n"
+ "movq (%0),%%mm1\n" /* mm1 = pix1[0][0-7] */
+ "movq (%1),%%mm2\n" /* mm2 = pix2[0][0-7] */
+ "movq (%0,%3),%%mm3\n" /* mm3 = pix1[1][0-7] */
+ "movq (%1,%3),%%mm4\n" /* mm4 = pix2[1][0-7] */
+
+ /* todo: mm1-mm2, mm3-mm4 */
+ /* algo: substract mm1 from mm2 with saturation and vice versa */
+ /* OR the results to get absolute difference */
+ "movq %%mm1,%%mm5\n"
+ "movq %%mm3,%%mm6\n"
+ "psubusb %%mm2,%%mm1\n"
+ "psubusb %%mm4,%%mm3\n"
+ "psubusb %%mm5,%%mm2\n"
+ "psubusb %%mm6,%%mm4\n"
+
+ "por %%mm1,%%mm2\n"
+ "por %%mm3,%%mm4\n"
+
+ /* now convert to 16-bit vectors so we can square them */
+ "movq %%mm2,%%mm1\n"
+ "movq %%mm4,%%mm3\n"
+
+ "punpckhbw %%mm0,%%mm2\n"
+ "punpckhbw %%mm0,%%mm4\n"
+ "punpcklbw %%mm0,%%mm1\n" /* mm1 now spread over (mm1,mm2) */
+ "punpcklbw %%mm0,%%mm3\n" /* mm4 now spread over (mm3,mm4) */
+
+ "pmaddwd %%mm2,%%mm2\n"
+ "pmaddwd %%mm4,%%mm4\n"
+ "pmaddwd %%mm1,%%mm1\n"
+ "pmaddwd %%mm3,%%mm3\n"
+
+ "lea (%0,%3,2), %0\n" /* pix1 += 2*line_size */
+ "lea (%1,%3,2), %1\n" /* pix2 += 2*line_size */
+
+ "paddd %%mm2,%%mm1\n"
+ "paddd %%mm4,%%mm3\n"
+ "paddd %%mm1,%%mm7\n"
+ "paddd %%mm3,%%mm7\n"
+
+ "decl %%ecx\n"
+ "jnz 1b\n"
+
+ "movq %%mm7,%%mm1\n"
+ "psrlq $32, %%mm7\n" /* shift hi dword to lo */
+ "paddd %%mm7,%%mm1\n"
+ "movd %%mm1,%2\n"
+ : "+r" (pix1), "+r" (pix2), "=r"(tmp)
+ : "r" ((long)line_size) , "m" (h)
+ : "%ecx");
+ return tmp;
+}
+
+static int sse16_mmx(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
+ int tmp;
+ asm volatile (
+ "movl %4,%%ecx\n"
+ "pxor %%mm0,%%mm0\n" /* mm0 = 0 */
+ "pxor %%mm7,%%mm7\n" /* mm7 holds the sum */
+ "1:\n"
+ "movq (%0),%%mm1\n" /* mm1 = pix1[0-7] */
+ "movq (%1),%%mm2\n" /* mm2 = pix2[0-7] */
+ "movq 8(%0),%%mm3\n" /* mm3 = pix1[8-15] */
+ "movq 8(%1),%%mm4\n" /* mm4 = pix2[8-15] */
+
+ /* todo: mm1-mm2, mm3-mm4 */
+ /* algo: substract mm1 from mm2 with saturation and vice versa */
+ /* OR the results to get absolute difference */
+ "movq %%mm1,%%mm5\n"
+ "movq %%mm3,%%mm6\n"
+ "psubusb %%mm2,%%mm1\n"
+ "psubusb %%mm4,%%mm3\n"
+ "psubusb %%mm5,%%mm2\n"
+ "psubusb %%mm6,%%mm4\n"
+
+ "por %%mm1,%%mm2\n"
+ "por %%mm3,%%mm4\n"
+
+ /* now convert to 16-bit vectors so we can square them */
+ "movq %%mm2,%%mm1\n"
+ "movq %%mm4,%%mm3\n"
+
+ "punpckhbw %%mm0,%%mm2\n"
+ "punpckhbw %%mm0,%%mm4\n"
+ "punpcklbw %%mm0,%%mm1\n" /* mm1 now spread over (mm1,mm2) */
+ "punpcklbw %%mm0,%%mm3\n" /* mm4 now spread over (mm3,mm4) */
+
+ "pmaddwd %%mm2,%%mm2\n"
+ "pmaddwd %%mm4,%%mm4\n"
+ "pmaddwd %%mm1,%%mm1\n"
+ "pmaddwd %%mm3,%%mm3\n"
+
+ "add %3,%0\n"
+ "add %3,%1\n"
+
+ "paddd %%mm2,%%mm1\n"
+ "paddd %%mm4,%%mm3\n"
+ "paddd %%mm1,%%mm7\n"
+ "paddd %%mm3,%%mm7\n"
+
+ "decl %%ecx\n"
+ "jnz 1b\n"
+
+ "movq %%mm7,%%mm1\n"
+ "psrlq $32, %%mm7\n" /* shift hi dword to lo */
+ "paddd %%mm7,%%mm1\n"
+ "movd %%mm1,%2\n"
+ : "+r" (pix1), "+r" (pix2), "=r"(tmp)
+ : "r" ((long)line_size) , "m" (h)
+ : "%ecx");
+ return tmp;
+}
+
+static int sse16_sse2(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
+ int tmp;
+ asm volatile (
+ "shr $1,%2\n"
+ "pxor %%xmm0,%%xmm0\n" /* mm0 = 0 */
+ "pxor %%xmm7,%%xmm7\n" /* mm7 holds the sum */
+ "1:\n"
+ "movdqu (%0),%%xmm1\n" /* mm1 = pix1[0][0-15] */
+ "movdqu (%1),%%xmm2\n" /* mm2 = pix2[0][0-15] */
+ "movdqu (%0,%4),%%xmm3\n" /* mm3 = pix1[1][0-15] */
+ "movdqu (%1,%4),%%xmm4\n" /* mm4 = pix2[1][0-15] */
+
+ /* todo: mm1-mm2, mm3-mm4 */
+ /* algo: substract mm1 from mm2 with saturation and vice versa */
+ /* OR the results to get absolute difference */
+ "movdqa %%xmm1,%%xmm5\n"
+ "movdqa %%xmm3,%%xmm6\n"
+ "psubusb %%xmm2,%%xmm1\n"
+ "psubusb %%xmm4,%%xmm3\n"
+ "psubusb %%xmm5,%%xmm2\n"
+ "psubusb %%xmm6,%%xmm4\n"
+
+ "por %%xmm1,%%xmm2\n"
+ "por %%xmm3,%%xmm4\n"
+
+ /* now convert to 16-bit vectors so we can square them */
+ "movdqa %%xmm2,%%xmm1\n"
+ "movdqa %%xmm4,%%xmm3\n"
+
+ "punpckhbw %%xmm0,%%xmm2\n"
+ "punpckhbw %%xmm0,%%xmm4\n"
+ "punpcklbw %%xmm0,%%xmm1\n" /* mm1 now spread over (mm1,mm2) */
+ "punpcklbw %%xmm0,%%xmm3\n" /* mm4 now spread over (mm3,mm4) */
+
+ "pmaddwd %%xmm2,%%xmm2\n"
+ "pmaddwd %%xmm4,%%xmm4\n"
+ "pmaddwd %%xmm1,%%xmm1\n"
+ "pmaddwd %%xmm3,%%xmm3\n"
+
+ "lea (%0,%4,2), %0\n" /* pix1 += 2*line_size */
+ "lea (%1,%4,2), %1\n" /* pix2 += 2*line_size */
+
+ "paddd %%xmm2,%%xmm1\n"
+ "paddd %%xmm4,%%xmm3\n"
+ "paddd %%xmm1,%%xmm7\n"
+ "paddd %%xmm3,%%xmm7\n"
+
+ "decl %2\n"
+ "jnz 1b\n"
+
+ "movdqa %%xmm7,%%xmm1\n"
+ "psrldq $8, %%xmm7\n" /* shift hi qword to lo */
+ "paddd %%xmm1,%%xmm7\n"
+ "movdqa %%xmm7,%%xmm1\n"
+ "psrldq $4, %%xmm7\n" /* shift hi dword to lo */
+ "paddd %%xmm1,%%xmm7\n"
+ "movd %%xmm7,%3\n"
+ : "+r" (pix1), "+r" (pix2), "+r"(h), "=r"(tmp)
+ : "r" ((long)line_size));
+ return tmp;
+}
+
+static int hf_noise8_mmx(uint8_t * pix1, int line_size, int h) {
+ int tmp;
+ asm volatile (
+ "movl %3,%%ecx\n"
+ "pxor %%mm7,%%mm7\n"
+ "pxor %%mm6,%%mm6\n"
+
+ "movq (%0),%%mm0\n"
+ "movq %%mm0, %%mm1\n"
+ "psllq $8, %%mm0\n"
+ "psrlq $8, %%mm1\n"
+ "psrlq $8, %%mm0\n"
+ "movq %%mm0, %%mm2\n"
+ "movq %%mm1, %%mm3\n"
+ "punpcklbw %%mm7,%%mm0\n"
+ "punpcklbw %%mm7,%%mm1\n"
+ "punpckhbw %%mm7,%%mm2\n"
+ "punpckhbw %%mm7,%%mm3\n"
+ "psubw %%mm1, %%mm0\n"
+ "psubw %%mm3, %%mm2\n"
+
+ "add %2,%0\n"
+
+ "movq (%0),%%mm4\n"
+ "movq %%mm4, %%mm1\n"
+ "psllq $8, %%mm4\n"
+ "psrlq $8, %%mm1\n"
+ "psrlq $8, %%mm4\n"
+ "movq %%mm4, %%mm5\n"
+ "movq %%mm1, %%mm3\n"
+ "punpcklbw %%mm7,%%mm4\n"
+ "punpcklbw %%mm7,%%mm1\n"
+ "punpckhbw %%mm7,%%mm5\n"
+ "punpckhbw %%mm7,%%mm3\n"
+ "psubw %%mm1, %%mm4\n"
+ "psubw %%mm3, %%mm5\n"
+ "psubw %%mm4, %%mm0\n"
+ "psubw %%mm5, %%mm2\n"
+ "pxor %%mm3, %%mm3\n"
+ "pxor %%mm1, %%mm1\n"
+ "pcmpgtw %%mm0, %%mm3\n\t"
+ "pcmpgtw %%mm2, %%mm1\n\t"
+ "pxor %%mm3, %%mm0\n"
+ "pxor %%mm1, %%mm2\n"
+ "psubw %%mm3, %%mm0\n"
+ "psubw %%mm1, %%mm2\n"
+ "paddw %%mm0, %%mm2\n"
+ "paddw %%mm2, %%mm6\n"
+
+ "add %2,%0\n"
+ "1:\n"
+
+ "movq (%0),%%mm0\n"
+ "movq %%mm0, %%mm1\n"
+ "psllq $8, %%mm0\n"
+ "psrlq $8, %%mm1\n"
+ "psrlq $8, %%mm0\n"
+ "movq %%mm0, %%mm2\n"
+ "movq %%mm1, %%mm3\n"
+ "punpcklbw %%mm7,%%mm0\n"
+ "punpcklbw %%mm7,%%mm1\n"
+ "punpckhbw %%mm7,%%mm2\n"
+ "punpckhbw %%mm7,%%mm3\n"
+ "psubw %%mm1, %%mm0\n"
+ "psubw %%mm3, %%mm2\n"
+ "psubw %%mm0, %%mm4\n"
+ "psubw %%mm2, %%mm5\n"
+ "pxor %%mm3, %%mm3\n"
+ "pxor %%mm1, %%mm1\n"
+ "pcmpgtw %%mm4, %%mm3\n\t"
+ "pcmpgtw %%mm5, %%mm1\n\t"
+ "pxor %%mm3, %%mm4\n"
+ "pxor %%mm1, %%mm5\n"
+ "psubw %%mm3, %%mm4\n"
+ "psubw %%mm1, %%mm5\n"
+ "paddw %%mm4, %%mm5\n"
+ "paddw %%mm5, %%mm6\n"
+
+ "add %2,%0\n"
+
+ "movq (%0),%%mm4\n"
+ "movq %%mm4, %%mm1\n"
+ "psllq $8, %%mm4\n"
+ "psrlq $8, %%mm1\n"
+ "psrlq $8, %%mm4\n"
+ "movq %%mm4, %%mm5\n"
+ "movq %%mm1, %%mm3\n"
+ "punpcklbw %%mm7,%%mm4\n"
+ "punpcklbw %%mm7,%%mm1\n"
+ "punpckhbw %%mm7,%%mm5\n"
+ "punpckhbw %%mm7,%%mm3\n"
+ "psubw %%mm1, %%mm4\n"
+ "psubw %%mm3, %%mm5\n"
+ "psubw %%mm4, %%mm0\n"
+ "psubw %%mm5, %%mm2\n"
+ "pxor %%mm3, %%mm3\n"
+ "pxor %%mm1, %%mm1\n"
+ "pcmpgtw %%mm0, %%mm3\n\t"
+ "pcmpgtw %%mm2, %%mm1\n\t"
+ "pxor %%mm3, %%mm0\n"
+ "pxor %%mm1, %%mm2\n"
+ "psubw %%mm3, %%mm0\n"
+ "psubw %%mm1, %%mm2\n"
+ "paddw %%mm0, %%mm2\n"
+ "paddw %%mm2, %%mm6\n"
+
+ "add %2,%0\n"
+ "subl $2, %%ecx\n"
+ " jnz 1b\n"
+
+ "movq %%mm6, %%mm0\n"
+ "punpcklwd %%mm7,%%mm0\n"
+ "punpckhwd %%mm7,%%mm6\n"
+ "paddd %%mm0, %%mm6\n"
+
+ "movq %%mm6,%%mm0\n"
+ "psrlq $32, %%mm6\n"
+ "paddd %%mm6,%%mm0\n"
+ "movd %%mm0,%1\n"
+ : "+r" (pix1), "=r"(tmp)
+ : "r" ((long)line_size) , "g" (h-2)
+ : "%ecx");
+ return tmp;
+}
+
+static int hf_noise16_mmx(uint8_t * pix1, int line_size, int h) {
+ int tmp;
+ uint8_t * pix= pix1;
+ asm volatile (
+ "movl %3,%%ecx\n"
+ "pxor %%mm7,%%mm7\n"
+ "pxor %%mm6,%%mm6\n"
+
+ "movq (%0),%%mm0\n"
+ "movq 1(%0),%%mm1\n"
+ "movq %%mm0, %%mm2\n"
+ "movq %%mm1, %%mm3\n"
+ "punpcklbw %%mm7,%%mm0\n"
+ "punpcklbw %%mm7,%%mm1\n"
+ "punpckhbw %%mm7,%%mm2\n"
+ "punpckhbw %%mm7,%%mm3\n"
+ "psubw %%mm1, %%mm0\n"
+ "psubw %%mm3, %%mm2\n"
+
+ "add %2,%0\n"
+
+ "movq (%0),%%mm4\n"
+ "movq 1(%0),%%mm1\n"
+ "movq %%mm4, %%mm5\n"
+ "movq %%mm1, %%mm3\n"
+ "punpcklbw %%mm7,%%mm4\n"
+ "punpcklbw %%mm7,%%mm1\n"
+ "punpckhbw %%mm7,%%mm5\n"
+ "punpckhbw %%mm7,%%mm3\n"
+ "psubw %%mm1, %%mm4\n"
+ "psubw %%mm3, %%mm5\n"
+ "psubw %%mm4, %%mm0\n"
+ "psubw %%mm5, %%mm2\n"
+ "pxor %%mm3, %%mm3\n"
+ "pxor %%mm1, %%mm1\n"
+ "pcmpgtw %%mm0, %%mm3\n\t"
+ "pcmpgtw %%mm2, %%mm1\n\t"
+ "pxor %%mm3, %%mm0\n"
+ "pxor %%mm1, %%mm2\n"
+ "psubw %%mm3, %%mm0\n"
+ "psubw %%mm1, %%mm2\n"
+ "paddw %%mm0, %%mm2\n"
+ "paddw %%mm2, %%mm6\n"
+
+ "add %2,%0\n"
+ "1:\n"
+
+ "movq (%0),%%mm0\n"
+ "movq 1(%0),%%mm1\n"
+ "movq %%mm0, %%mm2\n"
+ "movq %%mm1, %%mm3\n"
+ "punpcklbw %%mm7,%%mm0\n"
+ "punpcklbw %%mm7,%%mm1\n"
+ "punpckhbw %%mm7,%%mm2\n"
+ "punpckhbw %%mm7,%%mm3\n"
+ "psubw %%mm1, %%mm0\n"
+ "psubw %%mm3, %%mm2\n"
+ "psubw %%mm0, %%mm4\n"
+ "psubw %%mm2, %%mm5\n"
+ "pxor %%mm3, %%mm3\n"
+ "pxor %%mm1, %%mm1\n"
+ "pcmpgtw %%mm4, %%mm3\n\t"
+ "pcmpgtw %%mm5, %%mm1\n\t"
+ "pxor %%mm3, %%mm4\n"
+ "pxor %%mm1, %%mm5\n"
+ "psubw %%mm3, %%mm4\n"
+ "psubw %%mm1, %%mm5\n"
+ "paddw %%mm4, %%mm5\n"
+ "paddw %%mm5, %%mm6\n"
+
+ "add %2,%0\n"
+
+ "movq (%0),%%mm4\n"
+ "movq 1(%0),%%mm1\n"
+ "movq %%mm4, %%mm5\n"
+ "movq %%mm1, %%mm3\n"
+ "punpcklbw %%mm7,%%mm4\n"
+ "punpcklbw %%mm7,%%mm1\n"
+ "punpckhbw %%mm7,%%mm5\n"
+ "punpckhbw %%mm7,%%mm3\n"
+ "psubw %%mm1, %%mm4\n"
+ "psubw %%mm3, %%mm5\n"
+ "psubw %%mm4, %%mm0\n"
+ "psubw %%mm5, %%mm2\n"
+ "pxor %%mm3, %%mm3\n"
+ "pxor %%mm1, %%mm1\n"
+ "pcmpgtw %%mm0, %%mm3\n\t"
+ "pcmpgtw %%mm2, %%mm1\n\t"
+ "pxor %%mm3, %%mm0\n"
+ "pxor %%mm1, %%mm2\n"
+ "psubw %%mm3, %%mm0\n"
+ "psubw %%mm1, %%mm2\n"
+ "paddw %%mm0, %%mm2\n"
+ "paddw %%mm2, %%mm6\n"
+
+ "add %2,%0\n"
+ "subl $2, %%ecx\n"
+ " jnz 1b\n"
+
+ "movq %%mm6, %%mm0\n"
+ "punpcklwd %%mm7,%%mm0\n"
+ "punpckhwd %%mm7,%%mm6\n"
+ "paddd %%mm0, %%mm6\n"
+
+ "movq %%mm6,%%mm0\n"
+ "psrlq $32, %%mm6\n"
+ "paddd %%mm6,%%mm0\n"
+ "movd %%mm0,%1\n"
+ : "+r" (pix1), "=r"(tmp)
+ : "r" ((long)line_size) , "g" (h-2)
+ : "%ecx");
+ return tmp + hf_noise8_mmx(pix+8, line_size, h);
+}
+
+static int nsse16_mmx(void *p, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
+ MpegEncContext *c = p;
+ int score1, score2;
+
+ if(c) score1 = c->dsp.sse[0](c, pix1, pix2, line_size, h);
+ else score1 = sse16_mmx(c, pix1, pix2, line_size, h);
+ score2= hf_noise16_mmx(pix1, line_size, h) - hf_noise16_mmx(pix2, line_size, h);
+
+ if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight;
+ else return score1 + FFABS(score2)*8;
+}
+
+static int nsse8_mmx(void *p, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
+ MpegEncContext *c = p;
+ int score1= sse8_mmx(c, pix1, pix2, line_size, h);
+ int score2= hf_noise8_mmx(pix1, line_size, h) - hf_noise8_mmx(pix2, line_size, h);
+
+ if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight;
+ else return score1 + FFABS(score2)*8;
+}
+
+static int vsad_intra16_mmx(void *v, uint8_t * pix, uint8_t * dummy, int line_size, int h) {
+ int tmp;
+
+ assert( (((int)pix) & 7) == 0);
+ assert((line_size &7) ==0);
+
+#define SUM(in0, in1, out0, out1) \
+ "movq (%0), %%mm2\n"\
+ "movq 8(%0), %%mm3\n"\
+ "add %2,%0\n"\
+ "movq %%mm2, " #out0 "\n"\
+ "movq %%mm3, " #out1 "\n"\
+ "psubusb " #in0 ", %%mm2\n"\
+ "psubusb " #in1 ", %%mm3\n"\
+ "psubusb " #out0 ", " #in0 "\n"\
+ "psubusb " #out1 ", " #in1 "\n"\
+ "por %%mm2, " #in0 "\n"\
+ "por %%mm3, " #in1 "\n"\
+ "movq " #in0 ", %%mm2\n"\
+ "movq " #in1 ", %%mm3\n"\
+ "punpcklbw %%mm7, " #in0 "\n"\
+ "punpcklbw %%mm7, " #in1 "\n"\
+ "punpckhbw %%mm7, %%mm2\n"\
+ "punpckhbw %%mm7, %%mm3\n"\
+ "paddw " #in1 ", " #in0 "\n"\
+ "paddw %%mm3, %%mm2\n"\
+ "paddw %%mm2, " #in0 "\n"\
+ "paddw " #in0 ", %%mm6\n"
+
+
+ asm volatile (
+ "movl %3,%%ecx\n"
+ "pxor %%mm6,%%mm6\n"
+ "pxor %%mm7,%%mm7\n"
+ "movq (%0),%%mm0\n"
+ "movq 8(%0),%%mm1\n"
+ "add %2,%0\n"
+ "subl $2, %%ecx\n"
+ SUM(%%mm0, %%mm1, %%mm4, %%mm5)
+ "1:\n"
+
+ SUM(%%mm4, %%mm5, %%mm0, %%mm1)
+
+ SUM(%%mm0, %%mm1, %%mm4, %%mm5)
+
+ "subl $2, %%ecx\n"
+ "jnz 1b\n"
+
+ "movq %%mm6,%%mm0\n"
+ "psrlq $32, %%mm6\n"
+ "paddw %%mm6,%%mm0\n"
+ "movq %%mm0,%%mm6\n"
+ "psrlq $16, %%mm0\n"
+ "paddw %%mm6,%%mm0\n"
+ "movd %%mm0,%1\n"
+ : "+r" (pix), "=r"(tmp)
+ : "r" ((long)line_size) , "m" (h)
+ : "%ecx");
+ return tmp & 0xFFFF;
+}
+#undef SUM
+
+static int vsad_intra16_mmx2(void *v, uint8_t * pix, uint8_t * dummy, int line_size, int h) {
+ int tmp;
+
+ assert( (((int)pix) & 7) == 0);
+ assert((line_size &7) ==0);
+
+#define SUM(in0, in1, out0, out1) \
+ "movq (%0), " #out0 "\n"\
+ "movq 8(%0), " #out1 "\n"\
+ "add %2,%0\n"\
+ "psadbw " #out0 ", " #in0 "\n"\
+ "psadbw " #out1 ", " #in1 "\n"\
+ "paddw " #in1 ", " #in0 "\n"\
+ "paddw " #in0 ", %%mm6\n"
+
+ asm volatile (
+ "movl %3,%%ecx\n"
+ "pxor %%mm6,%%mm6\n"
+ "pxor %%mm7,%%mm7\n"
+ "movq (%0),%%mm0\n"
+ "movq 8(%0),%%mm1\n"
+ "add %2,%0\n"
+ "subl $2, %%ecx\n"
+ SUM(%%mm0, %%mm1, %%mm4, %%mm5)
+ "1:\n"
+
+ SUM(%%mm4, %%mm5, %%mm0, %%mm1)
+
+ SUM(%%mm0, %%mm1, %%mm4, %%mm5)
+
+ "subl $2, %%ecx\n"
+ "jnz 1b\n"
+
+ "movd %%mm6,%1\n"
+ : "+r" (pix), "=r"(tmp)
+ : "r" ((long)line_size) , "m" (h)
+ : "%ecx");
+ return tmp;
+}
+#undef SUM
+
+static int vsad16_mmx(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
+ int tmp;
+
+ assert( (((int)pix1) & 7) == 0);
+ assert( (((int)pix2) & 7) == 0);
+ assert((line_size &7) ==0);
+
+#define SUM(in0, in1, out0, out1) \
+ "movq (%0),%%mm2\n"\
+ "movq (%1)," #out0 "\n"\
+ "movq 8(%0),%%mm3\n"\
+ "movq 8(%1)," #out1 "\n"\
+ "add %3,%0\n"\
+ "add %3,%1\n"\
+ "psubb " #out0 ", %%mm2\n"\
+ "psubb " #out1 ", %%mm3\n"\
+ "pxor %%mm7, %%mm2\n"\
+ "pxor %%mm7, %%mm3\n"\
+ "movq %%mm2, " #out0 "\n"\
+ "movq %%mm3, " #out1 "\n"\
+ "psubusb " #in0 ", %%mm2\n"\
+ "psubusb " #in1 ", %%mm3\n"\
+ "psubusb " #out0 ", " #in0 "\n"\
+ "psubusb " #out1 ", " #in1 "\n"\
+ "por %%mm2, " #in0 "\n"\
+ "por %%mm3, " #in1 "\n"\
+ "movq " #in0 ", %%mm2\n"\
+ "movq " #in1 ", %%mm3\n"\
+ "punpcklbw %%mm7, " #in0 "\n"\
+ "punpcklbw %%mm7, " #in1 "\n"\
+ "punpckhbw %%mm7, %%mm2\n"\
+ "punpckhbw %%mm7, %%mm3\n"\
+ "paddw " #in1 ", " #in0 "\n"\
+ "paddw %%mm3, %%mm2\n"\
+ "paddw %%mm2, " #in0 "\n"\
+ "paddw " #in0 ", %%mm6\n"
+
+
+ asm volatile (
+ "movl %4,%%ecx\n"
+ "pxor %%mm6,%%mm6\n"
+ "pcmpeqw %%mm7,%%mm7\n"
+ "psllw $15, %%mm7\n"
+ "packsswb %%mm7, %%mm7\n"
+ "movq (%0),%%mm0\n"
+ "movq (%1),%%mm2\n"
+ "movq 8(%0),%%mm1\n"
+ "movq 8(%1),%%mm3\n"
+ "add %3,%0\n"
+ "add %3,%1\n"
+ "subl $2, %%ecx\n"
+ "psubb %%mm2, %%mm0\n"
+ "psubb %%mm3, %%mm1\n"
+ "pxor %%mm7, %%mm0\n"
+ "pxor %%mm7, %%mm1\n"
+ SUM(%%mm0, %%mm1, %%mm4, %%mm5)
+ "1:\n"
+
+ SUM(%%mm4, %%mm5, %%mm0, %%mm1)
+
+ SUM(%%mm0, %%mm1, %%mm4, %%mm5)
+
+ "subl $2, %%ecx\n"
+ "jnz 1b\n"
+
+ "movq %%mm6,%%mm0\n"
+ "psrlq $32, %%mm6\n"
+ "paddw %%mm6,%%mm0\n"
+ "movq %%mm0,%%mm6\n"
+ "psrlq $16, %%mm0\n"
+ "paddw %%mm6,%%mm0\n"
+ "movd %%mm0,%2\n"
+ : "+r" (pix1), "+r" (pix2), "=r"(tmp)
+ : "r" ((long)line_size) , "m" (h)
+ : "%ecx");
+ return tmp & 0x7FFF;
+}
+#undef SUM
+
+static int vsad16_mmx2(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
+ int tmp;
+
+ assert( (((int)pix1) & 7) == 0);
+ assert( (((int)pix2) & 7) == 0);
+ assert((line_size &7) ==0);
+
+#define SUM(in0, in1, out0, out1) \
+ "movq (%0)," #out0 "\n"\
+ "movq (%1),%%mm2\n"\
+ "movq 8(%0)," #out1 "\n"\
+ "movq 8(%1),%%mm3\n"\
+ "add %3,%0\n"\
+ "add %3,%1\n"\
+ "psubb %%mm2, " #out0 "\n"\
+ "psubb %%mm3, " #out1 "\n"\
+ "pxor %%mm7, " #out0 "\n"\
+ "pxor %%mm7, " #out1 "\n"\
+ "psadbw " #out0 ", " #in0 "\n"\
+ "psadbw " #out1 ", " #in1 "\n"\
+ "paddw " #in1 ", " #in0 "\n"\
+ "paddw " #in0 ", %%mm6\n"
+
+ asm volatile (
+ "movl %4,%%ecx\n"
+ "pxor %%mm6,%%mm6\n"
+ "pcmpeqw %%mm7,%%mm7\n"
+ "psllw $15, %%mm7\n"
+ "packsswb %%mm7, %%mm7\n"
+ "movq (%0),%%mm0\n"
+ "movq (%1),%%mm2\n"
+ "movq 8(%0),%%mm1\n"
+ "movq 8(%1),%%mm3\n"
+ "add %3,%0\n"
+ "add %3,%1\n"
+ "subl $2, %%ecx\n"
+ "psubb %%mm2, %%mm0\n"
+ "psubb %%mm3, %%mm1\n"
+ "pxor %%mm7, %%mm0\n"
+ "pxor %%mm7, %%mm1\n"
+ SUM(%%mm0, %%mm1, %%mm4, %%mm5)
+ "1:\n"
+
+ SUM(%%mm4, %%mm5, %%mm0, %%mm1)
+
+ SUM(%%mm0, %%mm1, %%mm4, %%mm5)
+
+ "subl $2, %%ecx\n"
+ "jnz 1b\n"
+
+ "movd %%mm6,%2\n"
+ : "+r" (pix1), "+r" (pix2), "=r"(tmp)
+ : "r" ((long)line_size) , "m" (h)
+ : "%ecx");
+ return tmp;
+}
+#undef SUM
+
+static void diff_bytes_mmx(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
+ long i=0;
+ asm volatile(
+ "1: \n\t"
+ "movq (%2, %0), %%mm0 \n\t"
+ "movq (%1, %0), %%mm1 \n\t"
+ "psubb %%mm0, %%mm1 \n\t"
+ "movq %%mm1, (%3, %0) \n\t"
+ "movq 8(%2, %0), %%mm0 \n\t"
+ "movq 8(%1, %0), %%mm1 \n\t"
+ "psubb %%mm0, %%mm1 \n\t"
+ "movq %%mm1, 8(%3, %0) \n\t"
+ "add $16, %0 \n\t"
+ "cmp %4, %0 \n\t"
+ " jb 1b \n\t"
+ : "+r" (i)
+ : "r"(src1), "r"(src2), "r"(dst), "r"((long)w-15)
+ );
+ for(; i<w; i++)
+ 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){
+ long i=0;
+ uint8_t l, lt;
+
+ asm volatile(
+ "1: \n\t"
+ "movq -1(%1, %0), %%mm0 \n\t" // LT
+ "movq (%1, %0), %%mm1 \n\t" // T
+ "movq -1(%2, %0), %%mm2 \n\t" // L
+ "movq (%2, %0), %%mm3 \n\t" // X
+ "movq %%mm2, %%mm4 \n\t" // L
+ "psubb %%mm0, %%mm2 \n\t"
+ "paddb %%mm1, %%mm2 \n\t" // L + T - LT
+ "movq %%mm4, %%mm5 \n\t" // L
+ "pmaxub %%mm1, %%mm4 \n\t" // max(T, L)
+ "pminub %%mm5, %%mm1 \n\t" // min(T, L)
+ "pminub %%mm2, %%mm4 \n\t"
+ "pmaxub %%mm1, %%mm4 \n\t"
+ "psubb %%mm4, %%mm3 \n\t" // dst - pred
+ "movq %%mm3, (%3, %0) \n\t"
+ "add $8, %0 \n\t"
+ "cmp %4, %0 \n\t"
+ " jb 1b \n\t"
+ : "+r" (i)
+ : "r"(src1), "r"(src2), "r"(dst), "r"((long)w)
+ );
+
+ l= *left;
+ lt= *left_top;
+
+ dst[0]= src2[0] - mid_pred(l, src1[0], (l + src1[0] - lt)&0xFF);
+
+ *left_top= src1[w-1];
+ *left = src2[w-1];
+}
+
+#define LBUTTERFLY2(a1,b1,a2,b2)\
+ "paddw " #b1 ", " #a1 " \n\t"\
+ "paddw " #b2 ", " #a2 " \n\t"\
+ "paddw " #b1 ", " #b1 " \n\t"\
+ "paddw " #b2 ", " #b2 " \n\t"\
+ "psubw " #a1 ", " #b1 " \n\t"\
+ "psubw " #a2 ", " #b2 " \n\t"
+
+#define HADAMARD48\
+ LBUTTERFLY2(%%mm0, %%mm1, %%mm2, %%mm3)\
+ LBUTTERFLY2(%%mm4, %%mm5, %%mm6, %%mm7)\
+ LBUTTERFLY2(%%mm0, %%mm2, %%mm1, %%mm3)\
+ LBUTTERFLY2(%%mm4, %%mm6, %%mm5, %%mm7)\
+ LBUTTERFLY2(%%mm0, %%mm4, %%mm1, %%mm5)\
+ LBUTTERFLY2(%%mm2, %%mm6, %%mm3, %%mm7)\
+
+#define MMABS(a,z)\
+ "pxor " #z ", " #z " \n\t"\
+ "pcmpgtw " #a ", " #z " \n\t"\
+ "pxor " #z ", " #a " \n\t"\
+ "psubw " #z ", " #a " \n\t"
+
+#define MMABS_SUM(a,z, sum)\
+ "pxor " #z ", " #z " \n\t"\
+ "pcmpgtw " #a ", " #z " \n\t"\
+ "pxor " #z ", " #a " \n\t"\
+ "psubw " #z ", " #a " \n\t"\
+ "paddusw " #a ", " #sum " \n\t"
+
+#define MMABS_MMX2(a,z)\
+ "pxor " #z ", " #z " \n\t"\
+ "psubw " #a ", " #z " \n\t"\
+ "pmaxsw " #z ", " #a " \n\t"
+
+#define MMABS_SUM_MMX2(a,z, sum)\
+ "pxor " #z ", " #z " \n\t"\
+ "psubw " #a ", " #z " \n\t"\
+ "pmaxsw " #z ", " #a " \n\t"\
+ "paddusw " #a ", " #sum " \n\t"
+
+#define TRANSPOSE4(a,b,c,d,t)\
+ SBUTTERFLY(a,b,t,wd) /* a=aebf t=cgdh */\
+ SBUTTERFLY(c,d,b,wd) /* c=imjn b=kolp */\
+ SBUTTERFLY(a,c,d,dq) /* a=aeim d=bfjn */\
+ SBUTTERFLY(t,b,c,dq) /* t=cgko c=dhlp */
+
+#define LOAD4(o, a, b, c, d)\
+ "movq "#o"(%1), " #a " \n\t"\
+ "movq "#o"+16(%1), " #b " \n\t"\
+ "movq "#o"+32(%1), " #c " \n\t"\
+ "movq "#o"+48(%1), " #d " \n\t"
+
+#define STORE4(o, a, b, c, d)\
+ "movq "#a", "#o"(%1) \n\t"\
+ "movq "#b", "#o"+16(%1) \n\t"\
+ "movq "#c", "#o"+32(%1) \n\t"\
+ "movq "#d", "#o"+48(%1) \n\t"\
+
+static int hadamard8_diff_mmx(void *s, uint8_t *src1, uint8_t *src2, int stride, int h){
+ DECLARE_ALIGNED_8(uint64_t, temp[16]);
+ int sum=0;
+
+ assert(h==8);
+
+ diff_pixels_mmx((DCTELEM*)temp, src1, src2, stride);
+
+ asm volatile(
+ LOAD4(0 , %%mm0, %%mm1, %%mm2, %%mm3)
+ LOAD4(64, %%mm4, %%mm5, %%mm6, %%mm7)
+
+ HADAMARD48
+
+ "movq %%mm7, 112(%1) \n\t"
+
+ TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm7)
+ STORE4(0 , %%mm0, %%mm3, %%mm7, %%mm2)
+
+ "movq 112(%1), %%mm7 \n\t"
+ TRANSPOSE4(%%mm4, %%mm5, %%mm6, %%mm7, %%mm0)
+ STORE4(64, %%mm4, %%mm7, %%mm0, %%mm6)
+
+ LOAD4(8 , %%mm0, %%mm1, %%mm2, %%mm3)
+ LOAD4(72, %%mm4, %%mm5, %%mm6, %%mm7)
+
+ HADAMARD48
+
+ "movq %%mm7, 120(%1) \n\t"
+
+ TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm7)
+ STORE4(8 , %%mm0, %%mm3, %%mm7, %%mm2)
+
+ "movq 120(%1), %%mm7 \n\t"
+ TRANSPOSE4(%%mm4, %%mm5, %%mm6, %%mm7, %%mm0)
+ "movq %%mm7, %%mm5 \n\t"//FIXME remove
+ "movq %%mm6, %%mm7 \n\t"
+ "movq %%mm0, %%mm6 \n\t"
+// STORE4(72, %%mm4, %%mm7, %%mm0, %%mm6) //FIXME remove
+
+ LOAD4(64, %%mm0, %%mm1, %%mm2, %%mm3)
+// LOAD4(72, %%mm4, %%mm5, %%mm6, %%mm7)
+
+ HADAMARD48
+ "movq %%mm7, 64(%1) \n\t"
+ MMABS(%%mm0, %%mm7)
+ MMABS_SUM(%%mm1, %%mm7, %%mm0)
+ MMABS_SUM(%%mm2, %%mm7, %%mm0)
+ MMABS_SUM(%%mm3, %%mm7, %%mm0)
+ MMABS_SUM(%%mm4, %%mm7, %%mm0)
+ MMABS_SUM(%%mm5, %%mm7, %%mm0)
+ MMABS_SUM(%%mm6, %%mm7, %%mm0)
+ "movq 64(%1), %%mm1 \n\t"
+ MMABS_SUM(%%mm1, %%mm7, %%mm0)
+ "movq %%mm0, 64(%1) \n\t"
+
+ LOAD4(0 , %%mm0, %%mm1, %%mm2, %%mm3)
+ LOAD4(8 , %%mm4, %%mm5, %%mm6, %%mm7)
+
+ HADAMARD48
+ "movq %%mm7, (%1) \n\t"
+ MMABS(%%mm0, %%mm7)
+ MMABS_SUM(%%mm1, %%mm7, %%mm0)
+ MMABS_SUM(%%mm2, %%mm7, %%mm0)
+ MMABS_SUM(%%mm3, %%mm7, %%mm0)
+ MMABS_SUM(%%mm4, %%mm7, %%mm0)
+ MMABS_SUM(%%mm5, %%mm7, %%mm0)
+ MMABS_SUM(%%mm6, %%mm7, %%mm0)
+ "movq (%1), %%mm1 \n\t"
+ MMABS_SUM(%%mm1, %%mm7, %%mm0)
+ "movq 64(%1), %%mm1 \n\t"
+ MMABS_SUM(%%mm1, %%mm7, %%mm0)
+
+ "movq %%mm0, %%mm1 \n\t"
+ "psrlq $32, %%mm0 \n\t"
+ "paddusw %%mm1, %%mm0 \n\t"
+ "movq %%mm0, %%mm1 \n\t"
+ "psrlq $16, %%mm0 \n\t"
+ "paddusw %%mm1, %%mm0 \n\t"
+ "movd %%mm0, %0 \n\t"
+
+ : "=r" (sum)
+ : "r"(temp)
+ );
+ return sum&0xFFFF;
+}
+
+static int hadamard8_diff_mmx2(void *s, uint8_t *src1, uint8_t *src2, int stride, int h){
+ DECLARE_ALIGNED_8(uint64_t, temp[16]);
+ int sum=0;
+
+ assert(h==8);
+
+ diff_pixels_mmx((DCTELEM*)temp, src1, src2, stride);
+
+ asm volatile(
+ LOAD4(0 , %%mm0, %%mm1, %%mm2, %%mm3)
+ LOAD4(64, %%mm4, %%mm5, %%mm6, %%mm7)
+
+ HADAMARD48
+
+ "movq %%mm7, 112(%1) \n\t"
+
+ TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm7)
+ STORE4(0 , %%mm0, %%mm3, %%mm7, %%mm2)
+
+ "movq 112(%1), %%mm7 \n\t"
+ TRANSPOSE4(%%mm4, %%mm5, %%mm6, %%mm7, %%mm0)
+ STORE4(64, %%mm4, %%mm7, %%mm0, %%mm6)
+
+ LOAD4(8 , %%mm0, %%mm1, %%mm2, %%mm3)
+ LOAD4(72, %%mm4, %%mm5, %%mm6, %%mm7)
+
+ HADAMARD48
+
+ "movq %%mm7, 120(%1) \n\t"
+
+ TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm7)
+ STORE4(8 , %%mm0, %%mm3, %%mm7, %%mm2)
+
+ "movq 120(%1), %%mm7 \n\t"
+ TRANSPOSE4(%%mm4, %%mm5, %%mm6, %%mm7, %%mm0)
+ "movq %%mm7, %%mm5 \n\t"//FIXME remove
+ "movq %%mm6, %%mm7 \n\t"
+ "movq %%mm0, %%mm6 \n\t"
+// STORE4(72, %%mm4, %%mm7, %%mm0, %%mm6) //FIXME remove
+
+ LOAD4(64, %%mm0, %%mm1, %%mm2, %%mm3)
+// LOAD4(72, %%mm4, %%mm5, %%mm6, %%mm7)
+
+ HADAMARD48
+ "movq %%mm7, 64(%1) \n\t"
+ MMABS_MMX2(%%mm0, %%mm7)
+ MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
+ MMABS_SUM_MMX2(%%mm2, %%mm7, %%mm0)
+ MMABS_SUM_MMX2(%%mm3, %%mm7, %%mm0)
+ MMABS_SUM_MMX2(%%mm4, %%mm7, %%mm0)
+ MMABS_SUM_MMX2(%%mm5, %%mm7, %%mm0)
+ MMABS_SUM_MMX2(%%mm6, %%mm7, %%mm0)
+ "movq 64(%1), %%mm1 \n\t"
+ MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
+ "movq %%mm0, 64(%1) \n\t"
+
+ LOAD4(0 , %%mm0, %%mm1, %%mm2, %%mm3)
+ LOAD4(8 , %%mm4, %%mm5, %%mm6, %%mm7)
+
+ HADAMARD48
+ "movq %%mm7, (%1) \n\t"
+ MMABS_MMX2(%%mm0, %%mm7)
+ MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
+ MMABS_SUM_MMX2(%%mm2, %%mm7, %%mm0)
+ MMABS_SUM_MMX2(%%mm3, %%mm7, %%mm0)
+ MMABS_SUM_MMX2(%%mm4, %%mm7, %%mm0)
+ MMABS_SUM_MMX2(%%mm5, %%mm7, %%mm0)
+ MMABS_SUM_MMX2(%%mm6, %%mm7, %%mm0)
+ "movq (%1), %%mm1 \n\t"
+ MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
+ "movq 64(%1), %%mm1 \n\t"
+ MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
+
+ "pshufw $0x0E, %%mm0, %%mm1 \n\t"
+ "paddusw %%mm1, %%mm0 \n\t"
+ "pshufw $0x01, %%mm0, %%mm1 \n\t"
+ "paddusw %%mm1, %%mm0 \n\t"
+ "movd %%mm0, %0 \n\t"
+
+ : "=r" (sum)
+ : "r"(temp)
+ );
+ return sum&0xFFFF;
+}
+
+
+WARPER8_16_SQ(hadamard8_diff_mmx, hadamard8_diff16_mmx)
+WARPER8_16_SQ(hadamard8_diff_mmx2, hadamard8_diff16_mmx2)
+
+static int ssd_int8_vs_int16_mmx(int8_t *pix1, int16_t *pix2, int size){
+ int sum;
+ long i=size;
+ asm volatile(
+ "pxor %%mm4, %%mm4 \n"
+ "1: \n"
+ "sub $8, %0 \n"
+ "movq (%2,%0), %%mm2 \n"
+ "movq (%3,%0,2), %%mm0 \n"
+ "movq 8(%3,%0,2), %%mm1 \n"
+ "punpckhbw %%mm2, %%mm3 \n"
+ "punpcklbw %%mm2, %%mm2 \n"
+ "psraw $8, %%mm3 \n"
+ "psraw $8, %%mm2 \n"
+ "psubw %%mm3, %%mm1 \n"
+ "psubw %%mm2, %%mm0 \n"
+ "pmaddwd %%mm1, %%mm1 \n"
+ "pmaddwd %%mm0, %%mm0 \n"
+ "paddd %%mm1, %%mm4 \n"
+ "paddd %%mm0, %%mm4 \n"
+ "jg 1b \n"
+ "movq %%mm4, %%mm3 \n"
+ "psrlq $32, %%mm3 \n"
+ "paddd %%mm3, %%mm4 \n"
+ "movd %%mm4, %1 \n"
+ :"+r"(i), "=r"(sum)
+ :"r"(pix1), "r"(pix2)
+ );
+ return sum;
+}
+
+#endif //CONFIG_ENCODERS
+
+#define put_no_rnd_pixels8_mmx(a,b,c,d) put_pixels8_mmx(a,b,c,d)
+#define put_no_rnd_pixels16_mmx(a,b,c,d) put_pixels16_mmx(a,b,c,d)
+
+#define QPEL_V_LOW(m3,m4,m5,m6, pw_20, pw_3, rnd, in0, in1, in2, in7, out, OP)\
+ "paddw " #m4 ", " #m3 " \n\t" /* x1 */\
+ "movq "MANGLE(ff_pw_20)", %%mm4 \n\t" /* 20 */\
+ "pmullw " #m3 ", %%mm4 \n\t" /* 20x1 */\
+ "movq "#in7", " #m3 " \n\t" /* d */\
+ "movq "#in0", %%mm5 \n\t" /* D */\
+ "paddw " #m3 ", %%mm5 \n\t" /* x4 */\
+ "psubw %%mm5, %%mm4 \n\t" /* 20x1 - x4 */\
+ "movq "#in1", %%mm5 \n\t" /* C */\
+ "movq "#in2", %%mm6 \n\t" /* B */\
+ "paddw " #m6 ", %%mm5 \n\t" /* x3 */\
+ "paddw " #m5 ", %%mm6 \n\t" /* x2 */\
+ "paddw %%mm6, %%mm6 \n\t" /* 2x2 */\
+ "psubw %%mm6, %%mm5 \n\t" /* -2x2 + x3 */\
+ "pmullw "MANGLE(ff_pw_3)", %%mm5 \n\t" /* -6x2 + 3x3 */\
+ "paddw " #rnd ", %%mm4 \n\t" /* x2 */\
+ "paddw %%mm4, %%mm5 \n\t" /* 20x1 - 6x2 + 3x3 - x4 */\
+ "psraw $5, %%mm5 \n\t"\
+ "packuswb %%mm5, %%mm5 \n\t"\
+ OP(%%mm5, out, %%mm7, d)
+
+#define QPEL_BASE(OPNAME, ROUNDER, RND, OP_MMX2, OP_3DNOW)\
+static void OPNAME ## mpeg4_qpel16_h_lowpass_mmx2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
+ uint64_t temp;\
+\
+ asm volatile(\
+ "pxor %%mm7, %%mm7 \n\t"\
+ "1: \n\t"\
+ "movq (%0), %%mm0 \n\t" /* ABCDEFGH */\
+ "movq %%mm0, %%mm1 \n\t" /* ABCDEFGH */\
+ "movq %%mm0, %%mm2 \n\t" /* ABCDEFGH */\
+ "punpcklbw %%mm7, %%mm0 \n\t" /* 0A0B0C0D */\
+ "punpckhbw %%mm7, %%mm1 \n\t" /* 0E0F0G0H */\
+ "pshufw $0x90, %%mm0, %%mm5 \n\t" /* 0A0A0B0C */\
+ "pshufw $0x41, %%mm0, %%mm6 \n\t" /* 0B0A0A0B */\
+ "movq %%mm2, %%mm3 \n\t" /* ABCDEFGH */\
+ "movq %%mm2, %%mm4 \n\t" /* ABCDEFGH */\
+ "psllq $8, %%mm2 \n\t" /* 0ABCDEFG */\
+ "psllq $16, %%mm3 \n\t" /* 00ABCDEF */\
+ "psllq $24, %%mm4 \n\t" /* 000ABCDE */\
+ "punpckhbw %%mm7, %%mm2 \n\t" /* 0D0E0F0G */\
+ "punpckhbw %%mm7, %%mm3 \n\t" /* 0C0D0E0F */\
+ "punpckhbw %%mm7, %%mm4 \n\t" /* 0B0C0D0E */\
+ "paddw %%mm3, %%mm5 \n\t" /* b */\
+ "paddw %%mm2, %%mm6 \n\t" /* c */\
+ "paddw %%mm5, %%mm5 \n\t" /* 2b */\
+ "psubw %%mm5, %%mm6 \n\t" /* c - 2b */\
+ "pshufw $0x06, %%mm0, %%mm5 \n\t" /* 0C0B0A0A */\
+ "pmullw "MANGLE(ff_pw_3)", %%mm6 \n\t" /* 3c - 6b */\
+ "paddw %%mm4, %%mm0 \n\t" /* a */\
+ "paddw %%mm1, %%mm5 \n\t" /* d */\
+ "pmullw "MANGLE(ff_pw_20)", %%mm0 \n\t" /* 20a */\
+ "psubw %%mm5, %%mm0 \n\t" /* 20a - d */\
+ "paddw %6, %%mm6 \n\t"\
+ "paddw %%mm6, %%mm0 \n\t" /* 20a - 6b + 3c - d */\
+ "psraw $5, %%mm0 \n\t"\
+ "movq %%mm0, %5 \n\t"\
+ /* mm1=EFGH, mm2=DEFG, mm3=CDEF, mm4=BCDE, mm7=0 */\
+ \
+ "movq 5(%0), %%mm0 \n\t" /* FGHIJKLM */\
+ "movq %%mm0, %%mm5 \n\t" /* FGHIJKLM */\
+ "movq %%mm0, %%mm6 \n\t" /* FGHIJKLM */\
+ "psrlq $8, %%mm0 \n\t" /* GHIJKLM0 */\
+ "psrlq $16, %%mm5 \n\t" /* HIJKLM00 */\
+ "punpcklbw %%mm7, %%mm0 \n\t" /* 0G0H0I0J */\
+ "punpcklbw %%mm7, %%mm5 \n\t" /* 0H0I0J0K */\
+ "paddw %%mm0, %%mm2 \n\t" /* b */\
+ "paddw %%mm5, %%mm3 \n\t" /* c */\
+ "paddw %%mm2, %%mm2 \n\t" /* 2b */\
+ "psubw %%mm2, %%mm3 \n\t" /* c - 2b */\
+ "movq %%mm6, %%mm2 \n\t" /* FGHIJKLM */\
+ "psrlq $24, %%mm6 \n\t" /* IJKLM000 */\
+ "punpcklbw %%mm7, %%mm2 \n\t" /* 0F0G0H0I */\
+ "punpcklbw %%mm7, %%mm6 \n\t" /* 0I0J0K0L */\
+ "pmullw "MANGLE(ff_pw_3)", %%mm3 \n\t" /* 3c - 6b */\
+ "paddw %%mm2, %%mm1 \n\t" /* a */\
+ "paddw %%mm6, %%mm4 \n\t" /* d */\
+ "pmullw "MANGLE(ff_pw_20)", %%mm1 \n\t" /* 20a */\
+ "psubw %%mm4, %%mm3 \n\t" /* - 6b +3c - d */\
+ "paddw %6, %%mm1 \n\t"\
+ "paddw %%mm1, %%mm3 \n\t" /* 20a - 6b +3c - d */\
+ "psraw $5, %%mm3 \n\t"\
+ "movq %5, %%mm1 \n\t"\
+ "packuswb %%mm3, %%mm1 \n\t"\
+ OP_MMX2(%%mm1, (%1),%%mm4, q)\
+ /* mm0= GHIJ, mm2=FGHI, mm5=HIJK, mm6=IJKL, mm7=0 */\
+ \
+ "movq 9(%0), %%mm1 \n\t" /* JKLMNOPQ */\
+ "movq %%mm1, %%mm4 \n\t" /* JKLMNOPQ */\
+ "movq %%mm1, %%mm3 \n\t" /* JKLMNOPQ */\
+ "psrlq $8, %%mm1 \n\t" /* KLMNOPQ0 */\
+ "psrlq $16, %%mm4 \n\t" /* LMNOPQ00 */\
+ "punpcklbw %%mm7, %%mm1 \n\t" /* 0K0L0M0N */\
+ "punpcklbw %%mm7, %%mm4 \n\t" /* 0L0M0N0O */\
+ "paddw %%mm1, %%mm5 \n\t" /* b */\
+ "paddw %%mm4, %%mm0 \n\t" /* c */\
+ "paddw %%mm5, %%mm5 \n\t" /* 2b */\
+ "psubw %%mm5, %%mm0 \n\t" /* c - 2b */\
+ "movq %%mm3, %%mm5 \n\t" /* JKLMNOPQ */\
+ "psrlq $24, %%mm3 \n\t" /* MNOPQ000 */\
+ "pmullw "MANGLE(ff_pw_3)", %%mm0 \n\t" /* 3c - 6b */\
+ "punpcklbw %%mm7, %%mm3 \n\t" /* 0M0N0O0P */\
+ "paddw %%mm3, %%mm2 \n\t" /* d */\
+ "psubw %%mm2, %%mm0 \n\t" /* -6b + 3c - d */\
+ "movq %%mm5, %%mm2 \n\t" /* JKLMNOPQ */\
+ "punpcklbw %%mm7, %%mm2 \n\t" /* 0J0K0L0M */\
+ "punpckhbw %%mm7, %%mm5 \n\t" /* 0N0O0P0Q */\
+ "paddw %%mm2, %%mm6 \n\t" /* a */\
+ "pmullw "MANGLE(ff_pw_20)", %%mm6 \n\t" /* 20a */\
+ "paddw %6, %%mm0 \n\t"\
+ "paddw %%mm6, %%mm0 \n\t" /* 20a - 6b + 3c - d */\
+ "psraw $5, %%mm0 \n\t"\
+ /* mm1=KLMN, mm2=JKLM, mm3=MNOP, mm4=LMNO, mm5=NOPQ mm7=0 */\
+ \
+ "paddw %%mm5, %%mm3 \n\t" /* a */\
+ "pshufw $0xF9, %%mm5, %%mm6 \n\t" /* 0O0P0Q0Q */\
+ "paddw %%mm4, %%mm6 \n\t" /* b */\
+ "pshufw $0xBE, %%mm5, %%mm4 \n\t" /* 0P0Q0Q0P */\
+ "pshufw $0x6F, %%mm5, %%mm5 \n\t" /* 0Q0Q0P0O */\
+ "paddw %%mm1, %%mm4 \n\t" /* c */\
+ "paddw %%mm2, %%mm5 \n\t" /* d */\
+ "paddw %%mm6, %%mm6 \n\t" /* 2b */\
+ "psubw %%mm6, %%mm4 \n\t" /* c - 2b */\
+ "pmullw "MANGLE(ff_pw_20)", %%mm3 \n\t" /* 20a */\
+ "pmullw "MANGLE(ff_pw_3)", %%mm4 \n\t" /* 3c - 6b */\
+ "psubw %%mm5, %%mm3 \n\t" /* -6b + 3c - d */\
+ "paddw %6, %%mm4 \n\t"\
+ "paddw %%mm3, %%mm4 \n\t" /* 20a - 6b + 3c - d */\
+ "psraw $5, %%mm4 \n\t"\
+ "packuswb %%mm4, %%mm0 \n\t"\
+ OP_MMX2(%%mm0, 8(%1), %%mm4, q)\
+ \
+ "add %3, %0 \n\t"\
+ "add %4, %1 \n\t"\
+ "decl %2 \n\t"\
+ " jnz 1b \n\t"\
+ : "+a"(src), "+c"(dst), "+m"(h)\
+ : "d"((long)srcStride), "S"((long)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(temp), "m"(ROUNDER)\
+ : "memory"\
+ );\
+}\
+\
+static void OPNAME ## mpeg4_qpel16_h_lowpass_3dnow(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
+ int i;\
+ int16_t temp[16];\
+ /* quick HACK, XXX FIXME MUST be optimized */\
+ for(i=0; i<h; i++)\
+ {\
+ temp[ 0]= (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]);\
+ temp[ 1]= (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]);\
+ temp[ 2]= (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]);\
+ temp[ 3]= (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]);\
+ temp[ 4]= (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]);\
+ temp[ 5]= (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]);\
+ temp[ 6]= (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]);\
+ temp[ 7]= (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]);\
+ temp[ 8]= (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]);\
+ temp[ 9]= (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]);\
+ temp[10]= (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]);\
+ temp[11]= (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]);\
+ temp[12]= (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]);\
+ temp[13]= (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]);\
+ temp[14]= (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]);\
+ temp[15]= (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]);\
+ asm volatile(\
+ "movq (%0), %%mm0 \n\t"\
+ "movq 8(%0), %%mm1 \n\t"\
+ "paddw %2, %%mm0 \n\t"\
+ "paddw %2, %%mm1 \n\t"\
+ "psraw $5, %%mm0 \n\t"\
+ "psraw $5, %%mm1 \n\t"\
+ "packuswb %%mm1, %%mm0 \n\t"\
+ OP_3DNOW(%%mm0, (%1), %%mm1, q)\
+ "movq 16(%0), %%mm0 \n\t"\
+ "movq 24(%0), %%mm1 \n\t"\
+ "paddw %2, %%mm0 \n\t"\
+ "paddw %2, %%mm1 \n\t"\
+ "psraw $5, %%mm0 \n\t"\
+ "psraw $5, %%mm1 \n\t"\
+ "packuswb %%mm1, %%mm0 \n\t"\
+ OP_3DNOW(%%mm0, 8(%1), %%mm1, q)\
+ :: "r"(temp), "r"(dst), "m"(ROUNDER)\
+ : "memory"\
+ );\
+ dst+=dstStride;\
+ src+=srcStride;\
+ }\
+}\
+\
+static void OPNAME ## mpeg4_qpel8_h_lowpass_mmx2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
+ uint64_t temp;\
+\
+ asm volatile(\
+ "pxor %%mm7, %%mm7 \n\t"\
+ "1: \n\t"\
+ "movq (%0), %%mm0 \n\t" /* ABCDEFGH */\
+ "movq %%mm0, %%mm1 \n\t" /* ABCDEFGH */\
+ "movq %%mm0, %%mm2 \n\t" /* ABCDEFGH */\
+ "punpcklbw %%mm7, %%mm0 \n\t" /* 0A0B0C0D */\
+ "punpckhbw %%mm7, %%mm1 \n\t" /* 0E0F0G0H */\
+ "pshufw $0x90, %%mm0, %%mm5 \n\t" /* 0A0A0B0C */\
+ "pshufw $0x41, %%mm0, %%mm6 \n\t" /* 0B0A0A0B */\
+ "movq %%mm2, %%mm3 \n\t" /* ABCDEFGH */\
+ "movq %%mm2, %%mm4 \n\t" /* ABCDEFGH */\
+ "psllq $8, %%mm2 \n\t" /* 0ABCDEFG */\
+ "psllq $16, %%mm3 \n\t" /* 00ABCDEF */\
+ "psllq $24, %%mm4 \n\t" /* 000ABCDE */\
+ "punpckhbw %%mm7, %%mm2 \n\t" /* 0D0E0F0G */\
+ "punpckhbw %%mm7, %%mm3 \n\t" /* 0C0D0E0F */\
+ "punpckhbw %%mm7, %%mm4 \n\t" /* 0B0C0D0E */\
+ "paddw %%mm3, %%mm5 \n\t" /* b */\
+ "paddw %%mm2, %%mm6 \n\t" /* c */\
+ "paddw %%mm5, %%mm5 \n\t" /* 2b */\
+ "psubw %%mm5, %%mm6 \n\t" /* c - 2b */\
+ "pshufw $0x06, %%mm0, %%mm5 \n\t" /* 0C0B0A0A */\
+ "pmullw "MANGLE(ff_pw_3)", %%mm6 \n\t" /* 3c - 6b */\
+ "paddw %%mm4, %%mm0 \n\t" /* a */\
+ "paddw %%mm1, %%mm5 \n\t" /* d */\
+ "pmullw "MANGLE(ff_pw_20)", %%mm0 \n\t" /* 20a */\
+ "psubw %%mm5, %%mm0 \n\t" /* 20a - d */\
+ "paddw %6, %%mm6 \n\t"\
+ "paddw %%mm6, %%mm0 \n\t" /* 20a - 6b + 3c - d */\
+ "psraw $5, %%mm0 \n\t"\
+ /* mm1=EFGH, mm2=DEFG, mm3=CDEF, mm4=BCDE, mm7=0 */\
+ \
+ "movd 5(%0), %%mm5 \n\t" /* FGHI */\
+ "punpcklbw %%mm7, %%mm5 \n\t" /* 0F0G0H0I */\
+ "pshufw $0xF9, %%mm5, %%mm6 \n\t" /* 0G0H0I0I */\
+ "paddw %%mm5, %%mm1 \n\t" /* a */\
+ "paddw %%mm6, %%mm2 \n\t" /* b */\
+ "pshufw $0xBE, %%mm5, %%mm6 \n\t" /* 0H0I0I0H */\
+ "pshufw $0x6F, %%mm5, %%mm5 \n\t" /* 0I0I0H0G */\
+ "paddw %%mm6, %%mm3 \n\t" /* c */\
+ "paddw %%mm5, %%mm4 \n\t" /* d */\
+ "paddw %%mm2, %%mm2 \n\t" /* 2b */\
+ "psubw %%mm2, %%mm3 \n\t" /* c - 2b */\
+ "pmullw "MANGLE(ff_pw_20)", %%mm1 \n\t" /* 20a */\
+ "pmullw "MANGLE(ff_pw_3)", %%mm3 \n\t" /* 3c - 6b */\
+ "psubw %%mm4, %%mm3 \n\t" /* -6b + 3c - d */\
+ "paddw %6, %%mm1 \n\t"\
+ "paddw %%mm1, %%mm3 \n\t" /* 20a - 6b + 3c - d */\
+ "psraw $5, %%mm3 \n\t"\
+ "packuswb %%mm3, %%mm0 \n\t"\
+ OP_MMX2(%%mm0, (%1), %%mm4, q)\
+ \
+ "add %3, %0 \n\t"\
+ "add %4, %1 \n\t"\
+ "decl %2 \n\t"\
+ " jnz 1b \n\t"\
+ : "+a"(src), "+c"(dst), "+m"(h)\
+ : "S"((long)srcStride), "D"((long)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(temp), "m"(ROUNDER)\
+ : "memory"\
+ );\
+}\
+\
+static void OPNAME ## mpeg4_qpel8_h_lowpass_3dnow(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
+ int i;\
+ int16_t temp[8];\
+ /* quick HACK, XXX FIXME MUST be optimized */\
+ for(i=0; i<h; i++)\
+ {\
+ temp[ 0]= (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]);\
+ temp[ 1]= (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]);\
+ temp[ 2]= (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]);\
+ temp[ 3]= (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]);\
+ temp[ 4]= (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]);\
+ temp[ 5]= (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 8]);\
+ temp[ 6]= (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 8])*3 - (src[ 3]+src[ 7]);\
+ temp[ 7]= (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 8])*6 + (src[ 5]+src[ 7])*3 - (src[ 4]+src[ 6]);\
+ asm volatile(\
+ "movq (%0), %%mm0 \n\t"\
+ "movq 8(%0), %%mm1 \n\t"\
+ "paddw %2, %%mm0 \n\t"\
+ "paddw %2, %%mm1 \n\t"\
+ "psraw $5, %%mm0 \n\t"\
+ "psraw $5, %%mm1 \n\t"\
+ "packuswb %%mm1, %%mm0 \n\t"\
+ OP_3DNOW(%%mm0, (%1), %%mm1, q)\
+ :: "r"(temp), "r"(dst), "m"(ROUNDER)\
+ :"memory"\
+ );\
+ dst+=dstStride;\
+ src+=srcStride;\
+ }\
+}
+
+#define QPEL_OP(OPNAME, ROUNDER, RND, OP, MMX)\
+\
+static void OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ uint64_t temp[17*4];\
+ uint64_t *temp_ptr= temp;\
+ int count= 17;\
+\
+ /*FIXME unroll */\
+ asm volatile(\
+ "pxor %%mm7, %%mm7 \n\t"\
+ "1: \n\t"\
+ "movq (%0), %%mm0 \n\t"\
+ "movq (%0), %%mm1 \n\t"\
+ "movq 8(%0), %%mm2 \n\t"\
+ "movq 8(%0), %%mm3 \n\t"\
+ "punpcklbw %%mm7, %%mm0 \n\t"\
+ "punpckhbw %%mm7, %%mm1 \n\t"\
+ "punpcklbw %%mm7, %%mm2 \n\t"\
+ "punpckhbw %%mm7, %%mm3 \n\t"\
+ "movq %%mm0, (%1) \n\t"\
+ "movq %%mm1, 17*8(%1) \n\t"\
+ "movq %%mm2, 2*17*8(%1) \n\t"\
+ "movq %%mm3, 3*17*8(%1) \n\t"\
+ "add $8, %1 \n\t"\
+ "add %3, %0 \n\t"\
+ "decl %2 \n\t"\
+ " jnz 1b \n\t"\
+ : "+r" (src), "+r" (temp_ptr), "+r"(count)\
+ : "r" ((long)srcStride)\
+ : "memory"\
+ );\
+ \
+ temp_ptr= temp;\
+ count=4;\
+ \
+/*FIXME reorder for speed */\
+ asm volatile(\
+ /*"pxor %%mm7, %%mm7 \n\t"*/\
+ "1: \n\t"\
+ "movq (%0), %%mm0 \n\t"\
+ "movq 8(%0), %%mm1 \n\t"\
+ "movq 16(%0), %%mm2 \n\t"\
+ "movq 24(%0), %%mm3 \n\t"\
+ QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 16(%0), 8(%0), (%0), 32(%0), (%1), OP)\
+ QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 8(%0), (%0), (%0), 40(%0), (%1, %3), OP)\
+ "add %4, %1 \n\t"\
+ QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, (%0), (%0), 8(%0), 48(%0), (%1), OP)\
+ \
+ QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, (%0), 8(%0), 16(%0), 56(%0), (%1, %3), OP)\
+ "add %4, %1 \n\t"\
+ QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 8(%0), 16(%0), 24(%0), 64(%0), (%1), OP)\
+ QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 16(%0), 24(%0), 32(%0), 72(%0), (%1, %3), OP)\
+ "add %4, %1 \n\t"\
+ QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 24(%0), 32(%0), 40(%0), 80(%0), (%1), OP)\
+ QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 32(%0), 40(%0), 48(%0), 88(%0), (%1, %3), OP)\
+ "add %4, %1 \n\t"\
+ QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 40(%0), 48(%0), 56(%0), 96(%0), (%1), OP)\
+ QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 48(%0), 56(%0), 64(%0),104(%0), (%1, %3), OP)\
+ "add %4, %1 \n\t"\
+ QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 56(%0), 64(%0), 72(%0),112(%0), (%1), OP)\
+ QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 64(%0), 72(%0), 80(%0),120(%0), (%1, %3), OP)\
+ "add %4, %1 \n\t"\
+ QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 72(%0), 80(%0), 88(%0),128(%0), (%1), OP)\
+ \
+ QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 80(%0), 88(%0), 96(%0),128(%0), (%1, %3), OP)\
+ "add %4, %1 \n\t" \
+ QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 88(%0), 96(%0),104(%0),120(%0), (%1), OP)\
+ QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 96(%0),104(%0),112(%0),112(%0), (%1, %3), OP)\
+ \
+ "add $136, %0 \n\t"\
+ "add %6, %1 \n\t"\
+ "decl %2 \n\t"\
+ " jnz 1b \n\t"\
+ \
+ : "+r"(temp_ptr), "+r"(dst), "+g"(count)\
+ : "r"((long)dstStride), "r"(2*(long)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(ROUNDER), "g"(4-14*(long)dstStride)\
+ :"memory"\
+ );\
+}\
+\
+static void OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ uint64_t temp[9*2];\
+ uint64_t *temp_ptr= temp;\
+ int count= 9;\
+\
+ /*FIXME unroll */\
+ asm volatile(\
+ "pxor %%mm7, %%mm7 \n\t"\
+ "1: \n\t"\
+ "movq (%0), %%mm0 \n\t"\
+ "movq (%0), %%mm1 \n\t"\
+ "punpcklbw %%mm7, %%mm0 \n\t"\
+ "punpckhbw %%mm7, %%mm1 \n\t"\
+ "movq %%mm0, (%1) \n\t"\
+ "movq %%mm1, 9*8(%1) \n\t"\
+ "add $8, %1 \n\t"\
+ "add %3, %0 \n\t"\
+ "decl %2 \n\t"\
+ " jnz 1b \n\t"\
+ : "+r" (src), "+r" (temp_ptr), "+r"(count)\
+ : "r" ((long)srcStride)\
+ : "memory"\
+ );\
+ \
+ temp_ptr= temp;\
+ count=2;\
+ \
+/*FIXME reorder for speed */\
+ asm volatile(\
+ /*"pxor %%mm7, %%mm7 \n\t"*/\
+ "1: \n\t"\
+ "movq (%0), %%mm0 \n\t"\
+ "movq 8(%0), %%mm1 \n\t"\
+ "movq 16(%0), %%mm2 \n\t"\
+ "movq 24(%0), %%mm3 \n\t"\
+ QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 16(%0), 8(%0), (%0), 32(%0), (%1), OP)\
+ QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 8(%0), (%0), (%0), 40(%0), (%1, %3), OP)\
+ "add %4, %1 \n\t"\
+ QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, (%0), (%0), 8(%0), 48(%0), (%1), OP)\
+ \
+ QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, (%0), 8(%0), 16(%0), 56(%0), (%1, %3), OP)\
+ "add %4, %1 \n\t"\
+ QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 8(%0), 16(%0), 24(%0), 64(%0), (%1), OP)\
+ \
+ QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 16(%0), 24(%0), 32(%0), 64(%0), (%1, %3), OP)\
+ "add %4, %1 \n\t"\
+ QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 24(%0), 32(%0), 40(%0), 56(%0), (%1), OP)\
+ QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 32(%0), 40(%0), 48(%0), 48(%0), (%1, %3), OP)\
+ \
+ "add $72, %0 \n\t"\
+ "add %6, %1 \n\t"\
+ "decl %2 \n\t"\
+ " jnz 1b \n\t"\
+ \
+ : "+r"(temp_ptr), "+r"(dst), "+g"(count)\
+ : "r"((long)dstStride), "r"(2*(long)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(ROUNDER), "g"(4-6*(long)dstStride)\
+ : "memory"\
+ );\
+}\
+\
+static void OPNAME ## qpel8_mc00_ ## MMX (uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## pixels8_mmx(dst, src, stride, 8);\
+}\
+\
+static void OPNAME ## qpel8_mc10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t temp[8];\
+ uint8_t * const half= (uint8_t*)temp;\
+ put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, stride, 8);\
+ OPNAME ## pixels8_l2_ ## MMX(dst, src, half, stride, stride, 8);\
+}\
+\
+static void OPNAME ## qpel8_mc20_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## mpeg4_qpel8_h_lowpass_ ## MMX(dst, src, stride, stride, 8);\
+}\
+\
+static void OPNAME ## qpel8_mc30_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t temp[8];\
+ uint8_t * const half= (uint8_t*)temp;\
+ put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, stride, 8);\
+ OPNAME ## pixels8_l2_ ## MMX(dst, src+1, half, stride, stride, 8);\
+}\
+\
+static void OPNAME ## qpel8_mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t temp[8];\
+ uint8_t * const half= (uint8_t*)temp;\
+ put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, 8, stride);\
+ OPNAME ## pixels8_l2_ ## MMX(dst, src, half, stride, stride, 8);\
+}\
+\
+static void OPNAME ## qpel8_mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, src, stride, stride);\
+}\
+\
+static void OPNAME ## qpel8_mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t temp[8];\
+ uint8_t * const half= (uint8_t*)temp;\
+ put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, 8, stride);\
+ OPNAME ## pixels8_l2_ ## MMX(dst, src+stride, half, stride, stride, 8);\
+}\
+static void OPNAME ## qpel8_mc11_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t half[8 + 9];\
+ uint8_t * const halfH= ((uint8_t*)half) + 64;\
+ uint8_t * const halfHV= ((uint8_t*)half);\
+ put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
+ put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
+ OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8);\
+}\
+static void OPNAME ## qpel8_mc31_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t half[8 + 9];\
+ uint8_t * const halfH= ((uint8_t*)half) + 64;\
+ uint8_t * const halfHV= ((uint8_t*)half);\
+ put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
+ put ## RND ## pixels8_l2_ ## MMX(halfH, src+1, halfH, 8, stride, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
+ OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8);\
+}\
+static void OPNAME ## qpel8_mc13_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t half[8 + 9];\
+ uint8_t * const halfH= ((uint8_t*)half) + 64;\
+ uint8_t * const halfHV= ((uint8_t*)half);\
+ put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
+ put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
+ OPNAME ## pixels8_l2_ ## MMX(dst, halfH+8, halfHV, stride, 8, 8);\
+}\
+static void OPNAME ## qpel8_mc33_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t half[8 + 9];\
+ uint8_t * const halfH= ((uint8_t*)half) + 64;\
+ uint8_t * const halfHV= ((uint8_t*)half);\
+ put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
+ put ## RND ## pixels8_l2_ ## MMX(halfH, src+1, halfH, 8, stride, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
+ OPNAME ## pixels8_l2_ ## MMX(dst, halfH+8, halfHV, stride, 8, 8);\
+}\
+static void OPNAME ## qpel8_mc21_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t half[8 + 9];\
+ uint8_t * const halfH= ((uint8_t*)half) + 64;\
+ uint8_t * const halfHV= ((uint8_t*)half);\
+ put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
+ OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8);\
+}\
+static void OPNAME ## qpel8_mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t half[8 + 9];\
+ uint8_t * const halfH= ((uint8_t*)half) + 64;\
+ uint8_t * const halfHV= ((uint8_t*)half);\
+ put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
+ OPNAME ## pixels8_l2_ ## MMX(dst, halfH+8, halfHV, stride, 8, 8);\
+}\
+static void OPNAME ## qpel8_mc12_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t half[8 + 9];\
+ uint8_t * const halfH= ((uint8_t*)half);\
+ put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
+ put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9);\
+ OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
+}\
+static void OPNAME ## qpel8_mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t half[8 + 9];\
+ uint8_t * const halfH= ((uint8_t*)half);\
+ put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
+ put ## RND ## pixels8_l2_ ## MMX(halfH, src+1, halfH, 8, stride, 9);\
+ OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
+}\
+static void OPNAME ## qpel8_mc22_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t half[9];\
+ uint8_t * const halfH= ((uint8_t*)half);\
+ put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
+ OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
+}\
+static void OPNAME ## qpel16_mc00_ ## MMX (uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## pixels16_mmx(dst, src, stride, 16);\
+}\
+\
+static void OPNAME ## qpel16_mc10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t temp[32];\
+ uint8_t * const half= (uint8_t*)temp;\
+ put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, stride, 16);\
+ OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, stride, 16);\
+}\
+\
+static void OPNAME ## qpel16_mc20_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## mpeg4_qpel16_h_lowpass_ ## MMX(dst, src, stride, stride, 16);\
+}\
+\
+static void OPNAME ## qpel16_mc30_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t temp[32];\
+ uint8_t * const half= (uint8_t*)temp;\
+ put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, stride, 16);\
+ OPNAME ## pixels16_l2_ ## MMX(dst, src+1, half, stride, stride, 16);\
+}\
+\
+static void OPNAME ## qpel16_mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t temp[32];\
+ uint8_t * const half= (uint8_t*)temp;\
+ put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, stride);\
+ OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, stride, 16);\
+}\
+\
+static void OPNAME ## qpel16_mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, src, stride, stride);\
+}\
+\
+static void OPNAME ## qpel16_mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t temp[32];\
+ uint8_t * const half= (uint8_t*)temp;\
+ put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, stride);\
+ OPNAME ## pixels16_l2_ ## MMX(dst, src+stride, half, stride, stride, 16);\
+}\
+static void OPNAME ## qpel16_mc11_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t half[16*2 + 17*2];\
+ uint8_t * const halfH= ((uint8_t*)half) + 256;\
+ uint8_t * const halfHV= ((uint8_t*)half);\
+ put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
+ put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, stride, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
+ OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16);\
+}\
+static void OPNAME ## qpel16_mc31_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t half[16*2 + 17*2];\
+ uint8_t * const halfH= ((uint8_t*)half) + 256;\
+ uint8_t * const halfHV= ((uint8_t*)half);\
+ put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
+ put ## RND ## pixels16_l2_ ## MMX(halfH, src+1, halfH, 16, stride, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
+ OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16);\
+}\
+static void OPNAME ## qpel16_mc13_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t half[16*2 + 17*2];\
+ uint8_t * const halfH= ((uint8_t*)half) + 256;\
+ uint8_t * const halfHV= ((uint8_t*)half);\
+ put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
+ put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, stride, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
+ OPNAME ## pixels16_l2_ ## MMX(dst, halfH+16, halfHV, stride, 16, 16);\
+}\
+static void OPNAME ## qpel16_mc33_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t half[16*2 + 17*2];\
+ uint8_t * const halfH= ((uint8_t*)half) + 256;\
+ uint8_t * const halfHV= ((uint8_t*)half);\
+ put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
+ put ## RND ## pixels16_l2_ ## MMX(halfH, src+1, halfH, 16, stride, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
+ OPNAME ## pixels16_l2_ ## MMX(dst, halfH+16, halfHV, stride, 16, 16);\
+}\
+static void OPNAME ## qpel16_mc21_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t half[16*2 + 17*2];\
+ uint8_t * const halfH= ((uint8_t*)half) + 256;\
+ uint8_t * const halfHV= ((uint8_t*)half);\
+ put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
+ OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16);\
+}\
+static void OPNAME ## qpel16_mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t half[16*2 + 17*2];\
+ uint8_t * const halfH= ((uint8_t*)half) + 256;\
+ uint8_t * const halfHV= ((uint8_t*)half);\
+ put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
+ OPNAME ## pixels16_l2_ ## MMX(dst, halfH+16, halfHV, stride, 16, 16);\
+}\
+static void OPNAME ## qpel16_mc12_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t half[17*2];\
+ uint8_t * const halfH= ((uint8_t*)half);\
+ put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
+ put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, stride, 17);\
+ OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
+}\
+static void OPNAME ## qpel16_mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t half[17*2];\
+ uint8_t * const halfH= ((uint8_t*)half);\
+ put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
+ put ## RND ## pixels16_l2_ ## MMX(halfH, src+1, halfH, 16, stride, 17);\
+ OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
+}\
+static void OPNAME ## qpel16_mc22_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t half[17*2];\
+ uint8_t * const halfH= ((uint8_t*)half);\
+ put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
+ OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
+}
+
+#define PUT_OP(a,b,temp, size) "mov" #size " " #a ", " #b " \n\t"
+#define AVG_3DNOW_OP(a,b,temp, size) \
+"mov" #size " " #b ", " #temp " \n\t"\
+"pavgusb " #temp ", " #a " \n\t"\
+"mov" #size " " #a ", " #b " \n\t"
+#define AVG_MMX2_OP(a,b,temp, size) \
+"mov" #size " " #b ", " #temp " \n\t"\
+"pavgb " #temp ", " #a " \n\t"\
+"mov" #size " " #a ", " #b " \n\t"
+
+QPEL_BASE(put_ , ff_pw_16, _ , PUT_OP, PUT_OP)
+QPEL_BASE(avg_ , ff_pw_16, _ , AVG_MMX2_OP, AVG_3DNOW_OP)
+QPEL_BASE(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, PUT_OP)
+QPEL_OP(put_ , ff_pw_16, _ , PUT_OP, 3dnow)
+QPEL_OP(avg_ , ff_pw_16, _ , AVG_3DNOW_OP, 3dnow)
+QPEL_OP(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, 3dnow)
+QPEL_OP(put_ , ff_pw_16, _ , PUT_OP, mmx2)
+QPEL_OP(avg_ , ff_pw_16, _ , AVG_MMX2_OP, mmx2)
+QPEL_OP(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, mmx2)
+
+/***********************************/
+/* bilinear qpel: not compliant to any spec, only for -lavdopts fast */
+
+#define QPEL_2TAP_XY(OPNAME, SIZE, MMX, XY, HPEL)\
+static void OPNAME ## 2tap_qpel ## SIZE ## _mc ## XY ## _ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## pixels ## SIZE ## HPEL(dst, src, stride, SIZE);\
+}
+#define QPEL_2TAP_L3(OPNAME, SIZE, MMX, XY, S0, S1, S2)\
+static void OPNAME ## 2tap_qpel ## SIZE ## _mc ## XY ## _ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## 2tap_qpel ## SIZE ## _l3_ ## MMX(dst, src+S0, stride, SIZE, S1, S2);\
+}
+
+#define QPEL_2TAP(OPNAME, SIZE, MMX)\
+QPEL_2TAP_XY(OPNAME, SIZE, MMX, 20, _x2_ ## MMX)\
+QPEL_2TAP_XY(OPNAME, SIZE, MMX, 02, _y2_ ## MMX)\
+QPEL_2TAP_XY(OPNAME, SIZE, MMX, 22, _xy2_mmx)\
+static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc00_ ## MMX =\
+ OPNAME ## qpel ## SIZE ## _mc00_ ## MMX;\
+static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc21_ ## MMX =\
+ OPNAME ## 2tap_qpel ## SIZE ## _mc20_ ## MMX;\
+static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc12_ ## MMX =\
+ OPNAME ## 2tap_qpel ## SIZE ## _mc02_ ## MMX;\
+static void OPNAME ## 2tap_qpel ## SIZE ## _mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## pixels ## SIZE ## _y2_ ## MMX(dst, src+1, stride, SIZE);\
+}\
+static void OPNAME ## 2tap_qpel ## SIZE ## _mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## pixels ## SIZE ## _x2_ ## MMX(dst, src+stride, stride, SIZE);\
+}\
+QPEL_2TAP_L3(OPNAME, SIZE, MMX, 10, 0, 1, 0)\
+QPEL_2TAP_L3(OPNAME, SIZE, MMX, 30, 1, -1, 0)\
+QPEL_2TAP_L3(OPNAME, SIZE, MMX, 01, 0, stride, 0)\
+QPEL_2TAP_L3(OPNAME, SIZE, MMX, 03, stride, -stride, 0)\
+QPEL_2TAP_L3(OPNAME, SIZE, MMX, 11, 0, stride, 1)\
+QPEL_2TAP_L3(OPNAME, SIZE, MMX, 31, 1, stride, -1)\
+QPEL_2TAP_L3(OPNAME, SIZE, MMX, 13, stride, -stride, 1)\
+QPEL_2TAP_L3(OPNAME, SIZE, MMX, 33, stride+1, -stride, -1)\
+
+QPEL_2TAP(put_, 16, mmx2)
+QPEL_2TAP(avg_, 16, mmx2)
+QPEL_2TAP(put_, 8, mmx2)
+QPEL_2TAP(avg_, 8, mmx2)
+QPEL_2TAP(put_, 16, 3dnow)
+QPEL_2TAP(avg_, 16, 3dnow)
+QPEL_2TAP(put_, 8, 3dnow)
+QPEL_2TAP(avg_, 8, 3dnow)
+
+
+#if 0
+static void just_return() { return; }
+#endif
+
+#define SET_QPEL_FUNC(postfix1, postfix2) \
+ c->put_ ## postfix1 = put_ ## postfix2;\
+ c->put_no_rnd_ ## postfix1 = put_no_rnd_ ## postfix2;\
+ c->avg_ ## postfix1 = avg_ ## postfix2;
+
+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;
+ const int ix = ox>>(16+shift);
+ const int iy = oy>>(16+shift);
+ const int oxs = ox>>4;
+ const int oys = oy>>4;
+ const int dxxs = dxx>>4;
+ const int dxys = dxy>>4;
+ const int dyxs = dyx>>4;
+ const int dyys = dyy>>4;
+ const uint16_t r4[4] = {r,r,r,r};
+ const uint16_t dxy4[4] = {dxys,dxys,dxys,dxys};
+ const uint16_t dyy4[4] = {dyys,dyys,dyys,dyys};
+ const uint64_t shift2 = 2*shift;
+ uint8_t edge_buf[(h+1)*stride];
+ int x, y;
+
+ const int dxw = (dxx-(1<<(16+shift)))*(w-1);
+ const int dyh = (dyy-(1<<(16+shift)))*(h-1);
+ const int dxh = dxy*(h-1);
+ const int dyw = dyx*(w-1);
+ if( // non-constant fullpel offset (3% of blocks)
+ (ox^(ox+dxw) | ox^(ox+dxh) | ox^(ox+dxw+dxh) |
+ oy^(oy+dyw) | oy^(oy+dyh) | oy^(oy+dyw+dyh)) >> (16+shift)
+ // uses more than 16 bits of subpel mv (only at huge resolution)
+ || (dxx|dxy|dyx|dyy)&15 )
+ {
+ //FIXME could still use mmx for some of the rows
+ ff_gmc_c(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy, shift, r, width, height);
+ return;
+ }
+
+ src += ix + iy*stride;
+ if( (unsigned)ix >= width-w ||
+ (unsigned)iy >= height-h )
+ {
+ ff_emulated_edge_mc(edge_buf, src, stride, w+1, h+1, ix, iy, width, height);
+ src = edge_buf;
+ }
+
+ asm volatile(
+ "movd %0, %%mm6 \n\t"
+ "pxor %%mm7, %%mm7 \n\t"
+ "punpcklwd %%mm6, %%mm6 \n\t"
+ "punpcklwd %%mm6, %%mm6 \n\t"
+ :: "r"(1<<shift)
+ );
+
+ for(x=0; x<w; x+=4){
+ uint16_t dx4[4] = { oxs - dxys + dxxs*(x+0),
+ oxs - dxys + dxxs*(x+1),
+ oxs - dxys + dxxs*(x+2),
+ oxs - dxys + dxxs*(x+3) };
+ uint16_t dy4[4] = { oys - dyys + dyxs*(x+0),
+ oys - dyys + dyxs*(x+1),
+ oys - dyys + dyxs*(x+2),
+ oys - dyys + dyxs*(x+3) };
+
+ for(y=0; y<h; y++){
+ asm volatile(
+ "movq %0, %%mm4 \n\t"
+ "movq %1, %%mm5 \n\t"
+ "paddw %2, %%mm4 \n\t"
+ "paddw %3, %%mm5 \n\t"
+ "movq %%mm4, %0 \n\t"
+ "movq %%mm5, %1 \n\t"
+ "psrlw $12, %%mm4 \n\t"
+ "psrlw $12, %%mm5 \n\t"
+ : "+m"(*dx4), "+m"(*dy4)
+ : "m"(*dxy4), "m"(*dyy4)
+ );
+
+ asm volatile(
+ "movq %%mm6, %%mm2 \n\t"
+ "movq %%mm6, %%mm1 \n\t"
+ "psubw %%mm4, %%mm2 \n\t"
+ "psubw %%mm5, %%mm1 \n\t"
+ "movq %%mm2, %%mm0 \n\t"
+ "movq %%mm4, %%mm3 \n\t"
+ "pmullw %%mm1, %%mm0 \n\t" // (s-dx)*(s-dy)
+ "pmullw %%mm5, %%mm3 \n\t" // dx*dy
+ "pmullw %%mm5, %%mm2 \n\t" // (s-dx)*dy
+ "pmullw %%mm4, %%mm1 \n\t" // dx*(s-dy)
+
+ "movd %4, %%mm5 \n\t"
+ "movd %3, %%mm4 \n\t"
+ "punpcklbw %%mm7, %%mm5 \n\t"
+ "punpcklbw %%mm7, %%mm4 \n\t"
+ "pmullw %%mm5, %%mm3 \n\t" // src[1,1] * dx*dy
+ "pmullw %%mm4, %%mm2 \n\t" // src[0,1] * (s-dx)*dy
+
+ "movd %2, %%mm5 \n\t"
+ "movd %1, %%mm4 \n\t"
+ "punpcklbw %%mm7, %%mm5 \n\t"
+ "punpcklbw %%mm7, %%mm4 \n\t"
+ "pmullw %%mm5, %%mm1 \n\t" // src[1,0] * dx*(s-dy)
+ "pmullw %%mm4, %%mm0 \n\t" // src[0,0] * (s-dx)*(s-dy)
+ "paddw %5, %%mm1 \n\t"
+ "paddw %%mm3, %%mm2 \n\t"
+ "paddw %%mm1, %%mm0 \n\t"
+ "paddw %%mm2, %%mm0 \n\t"
+
+ "psrlw %6, %%mm0 \n\t"
+ "packuswb %%mm0, %%mm0 \n\t"
+ "movd %%mm0, %0 \n\t"
+
+ : "=m"(dst[x+y*stride])
+ : "m"(src[0]), "m"(src[1]),
+ "m"(src[stride]), "m"(src[stride+1]),
+ "m"(*r4), "m"(shift2)
+ );
+ src += stride;
+ }
+ src += 4-h*stride;
+ }
+}
+
+#ifdef CONFIG_ENCODERS
+static int try_8x8basis_mmx(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale){
+ long i=0;
+
+ assert(FFABS(scale) < 256);
+ scale<<= 16 + 1 - BASIS_SHIFT + RECON_SHIFT;
+
+ asm volatile(
+ "pcmpeqw %%mm6, %%mm6 \n\t" // -1w
+ "psrlw $15, %%mm6 \n\t" // 1w
+ "pxor %%mm7, %%mm7 \n\t"
+ "movd %4, %%mm5 \n\t"
+ "punpcklwd %%mm5, %%mm5 \n\t"
+ "punpcklwd %%mm5, %%mm5 \n\t"
+ "1: \n\t"
+ "movq (%1, %0), %%mm0 \n\t"
+ "movq 8(%1, %0), %%mm1 \n\t"
+ "pmulhw %%mm5, %%mm0 \n\t"
+ "pmulhw %%mm5, %%mm1 \n\t"
+ "paddw %%mm6, %%mm0 \n\t"
+ "paddw %%mm6, %%mm1 \n\t"
+ "psraw $1, %%mm0 \n\t"
+ "psraw $1, %%mm1 \n\t"
+ "paddw (%2, %0), %%mm0 \n\t"
+ "paddw 8(%2, %0), %%mm1 \n\t"
+ "psraw $6, %%mm0 \n\t"
+ "psraw $6, %%mm1 \n\t"
+ "pmullw (%3, %0), %%mm0 \n\t"
+ "pmullw 8(%3, %0), %%mm1 \n\t"
+ "pmaddwd %%mm0, %%mm0 \n\t"
+ "pmaddwd %%mm1, %%mm1 \n\t"
+ "paddd %%mm1, %%mm0 \n\t"
+ "psrld $4, %%mm0 \n\t"
+ "paddd %%mm0, %%mm7 \n\t"
+ "add $16, %0 \n\t"
+ "cmp $128, %0 \n\t" //FIXME optimize & bench
+ " jb 1b \n\t"
+ "movq %%mm7, %%mm6 \n\t"
+ "psrlq $32, %%mm7 \n\t"
+ "paddd %%mm6, %%mm7 \n\t"
+ "psrld $2, %%mm7 \n\t"
+ "movd %%mm7, %0 \n\t"
+
+ : "+r" (i)
+ : "r"(basis), "r"(rem), "r"(weight), "g"(scale)
+ );
+ return i;
+}
+
+static void add_8x8basis_mmx(int16_t rem[64], int16_t basis[64], int scale){
+ long i=0;
+
+ if(FFABS(scale) < 256){
+ scale<<= 16 + 1 - BASIS_SHIFT + RECON_SHIFT;
+ asm volatile(
+ "pcmpeqw %%mm6, %%mm6 \n\t" // -1w
+ "psrlw $15, %%mm6 \n\t" // 1w
+ "movd %3, %%mm5 \n\t"
+ "punpcklwd %%mm5, %%mm5 \n\t"
+ "punpcklwd %%mm5, %%mm5 \n\t"
+ "1: \n\t"
+ "movq (%1, %0), %%mm0 \n\t"
+ "movq 8(%1, %0), %%mm1 \n\t"
+ "pmulhw %%mm5, %%mm0 \n\t"
+ "pmulhw %%mm5, %%mm1 \n\t"
+ "paddw %%mm6, %%mm0 \n\t"
+ "paddw %%mm6, %%mm1 \n\t"
+ "psraw $1, %%mm0 \n\t"
+ "psraw $1, %%mm1 \n\t"
+ "paddw (%2, %0), %%mm0 \n\t"
+ "paddw 8(%2, %0), %%mm1 \n\t"
+ "movq %%mm0, (%2, %0) \n\t"
+ "movq %%mm1, 8(%2, %0) \n\t"
+ "add $16, %0 \n\t"
+ "cmp $128, %0 \n\t" //FIXME optimize & bench
+ " jb 1b \n\t"
+
+ : "+r" (i)
+ : "r"(basis), "r"(rem), "g"(scale)
+ );
+ }else{
+ for(i=0; i<8*8; i++){
+ rem[i] += (basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT);
+ }
+ }
+}
+#endif /* CONFIG_ENCODERS */
+
+#define PREFETCH(name, op) \
+static void name(void *mem, int stride, int h){\
+ const uint8_t *p= mem;\
+ do{\
+ asm volatile(#op" %0" :: "m"(*p));\
+ p+= stride;\
+ }while(--h);\
+}
+PREFETCH(prefetch_mmx2, prefetcht0)
+PREFETCH(prefetch_3dnow, prefetch)
+#undef PREFETCH
+
+#include "h264dsp_mmx.c"
+
+/* AVS specific */
+void ff_cavsdsp_init_mmx2(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);
+}
+void ff_avg_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
+ avg_pixels8_mmx(dst, src, stride, 8);
+}
+void ff_put_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
+ put_pixels16_mmx(dst, src, stride, 16);
+}
+void ff_avg_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
+ avg_pixels16_mmx(dst, src, stride, 16);
+}
+
+/* external functions, from idct_mmx.c */
+void ff_mmx_idct(DCTELEM *block);
+void ff_mmxext_idct(DCTELEM *block);
+
+void ff_vp3_idct_sse2(int16_t *input_data);
+void ff_vp3_idct_mmx(int16_t *data);
+void ff_vp3_dsp_init_mmx(void);
+
+/* XXX: those functions should be suppressed ASAP when all IDCTs are
+ converted */
+#ifdef CONFIG_GPL
+static void ff_libmpeg2mmx_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ ff_mmx_idct (block);
+ put_pixels_clamped_mmx(block, dest, line_size);
+}
+static void ff_libmpeg2mmx_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ ff_mmx_idct (block);
+ add_pixels_clamped_mmx(block, dest, line_size);
+}
+static void ff_libmpeg2mmx2_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ ff_mmxext_idct (block);
+ put_pixels_clamped_mmx(block, dest, line_size);
+}
+static void ff_libmpeg2mmx2_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ ff_mmxext_idct (block);
+ add_pixels_clamped_mmx(block, dest, line_size);
+}
+#endif
+static void ff_vp3_idct_put_sse2(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ ff_vp3_idct_sse2(block);
+ put_signed_pixels_clamped_mmx(block, dest, line_size);
+}
+static void ff_vp3_idct_add_sse2(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ ff_vp3_idct_sse2(block);
+ add_pixels_clamped_mmx(block, dest, line_size);
+}
+static void ff_vp3_idct_put_mmx(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ ff_vp3_idct_mmx(block);
+ put_signed_pixels_clamped_mmx(block, dest, line_size);
+}
+static 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);
+}
+static void ff_idct_xvid_mmx_put(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ ff_idct_xvid_mmx (block);
+ put_pixels_clamped_mmx(block, dest, line_size);
+}
+static void ff_idct_xvid_mmx_add(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ ff_idct_xvid_mmx (block);
+ add_pixels_clamped_mmx(block, dest, line_size);
+}
+static void ff_idct_xvid_mmx2_put(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ ff_idct_xvid_mmx2 (block);
+ put_pixels_clamped_mmx(block, dest, line_size);
+}
+static void ff_idct_xvid_mmx2_add(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ ff_idct_xvid_mmx2 (block);
+ add_pixels_clamped_mmx(block, dest, line_size);
+}
+
+static void vorbis_inverse_coupling_3dnow(float *mag, float *ang, int blocksize)
+{
+ int i;
+ asm volatile("pxor %%mm7, %%mm7":);
+ for(i=0; i<blocksize; i+=2) {
+ asm volatile(
+ "movq %0, %%mm0 \n\t"
+ "movq %1, %%mm1 \n\t"
+ "movq %%mm0, %%mm2 \n\t"
+ "movq %%mm1, %%mm3 \n\t"
+ "pfcmpge %%mm7, %%mm2 \n\t" // m <= 0.0
+ "pfcmpge %%mm7, %%mm3 \n\t" // a <= 0.0
+ "pslld $31, %%mm2 \n\t" // keep only the sign bit
+ "pxor %%mm2, %%mm1 \n\t"
+ "movq %%mm3, %%mm4 \n\t"
+ "pand %%mm1, %%mm3 \n\t"
+ "pandn %%mm1, %%mm4 \n\t"
+ "pfadd %%mm0, %%mm3 \n\t" // a = m + ((a<0) & (a ^ sign(m)))
+ "pfsub %%mm4, %%mm0 \n\t" // m = m + ((a>0) & (a ^ sign(m)))
+ "movq %%mm3, %1 \n\t"
+ "movq %%mm0, %0 \n\t"
+ :"+m"(mag[i]), "+m"(ang[i])
+ ::"memory"
+ );
+ }
+ asm volatile("femms");
+}
+static void vorbis_inverse_coupling_sse(float *mag, float *ang, int blocksize)
+{
+ int i;
+
+ asm volatile(
+ "movaps %0, %%xmm5 \n\t"
+ ::"m"(ff_pdw_80000000[0])
+ );
+ for(i=0; i<blocksize; i+=4) {
+ asm volatile(
+ "movaps %0, %%xmm0 \n\t"
+ "movaps %1, %%xmm1 \n\t"
+ "xorps %%xmm2, %%xmm2 \n\t"
+ "xorps %%xmm3, %%xmm3 \n\t"
+ "cmpleps %%xmm0, %%xmm2 \n\t" // m <= 0.0
+ "cmpleps %%xmm1, %%xmm3 \n\t" // a <= 0.0
+ "andps %%xmm5, %%xmm2 \n\t" // keep only the sign bit
+ "xorps %%xmm2, %%xmm1 \n\t"
+ "movaps %%xmm3, %%xmm4 \n\t"
+ "andps %%xmm1, %%xmm3 \n\t"
+ "andnps %%xmm1, %%xmm4 \n\t"
+ "addps %%xmm0, %%xmm3 \n\t" // a = m + ((a<0) & (a ^ sign(m)))
+ "subps %%xmm4, %%xmm0 \n\t" // m = m + ((a>0) & (a ^ sign(m)))
+ "movaps %%xmm3, %1 \n\t"
+ "movaps %%xmm0, %0 \n\t"
+ :"+m"(mag[i]), "+m"(ang[i])
+ ::"memory"
+ );
+ }
+}
+
+static void vector_fmul_3dnow(float *dst, const float *src, int len){
+ long i = (len-4)*4;
+ asm volatile(
+ "1: \n\t"
+ "movq (%1,%0), %%mm0 \n\t"
+ "movq 8(%1,%0), %%mm1 \n\t"
+ "pfmul (%2,%0), %%mm0 \n\t"
+ "pfmul 8(%2,%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"
+ "femms \n\t"
+ :"+r"(i)
+ :"r"(dst), "r"(src)
+ :"memory"
+ );
+}
+static void vector_fmul_sse(float *dst, const float *src, int len){
+ long i = (len-8)*4;
+ asm volatile(
+ "1: \n\t"
+ "movaps (%1,%0), %%xmm0 \n\t"
+ "movaps 16(%1,%0), %%xmm1 \n\t"
+ "mulps (%2,%0), %%xmm0 \n\t"
+ "mulps 16(%2,%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"(src)
+ :"memory"
+ );
+}
+
+static void vector_fmul_reverse_3dnow2(float *dst, const float *src0, const float *src1, int len){
+ long i = len*4-16;
+ asm volatile(
+ "1: \n\t"
+ "pswapd 8(%1), %%mm0 \n\t"
+ "pswapd (%1), %%mm1 \n\t"
+ "pfmul (%3,%0), %%mm0 \n\t"
+ "pfmul 8(%3,%0), %%mm1 \n\t"
+ "movq %%mm0, (%2,%0) \n\t"
+ "movq %%mm1, 8(%2,%0) \n\t"
+ "add $16, %1 \n\t"
+ "sub $16, %0 \n\t"
+ "jge 1b \n\t"
+ :"+r"(i), "+r"(src1)
+ :"r"(dst), "r"(src0)
+ );
+ asm volatile("femms");
+}
+static void vector_fmul_reverse_sse(float *dst, const float *src0, const float *src1, int len){
+ long i = len*4-32;
+ asm volatile(
+ "1: \n\t"
+ "movaps 16(%1), %%xmm0 \n\t"
+ "movaps (%1), %%xmm1 \n\t"
+ "shufps $0x1b, %%xmm0, %%xmm0 \n\t"
+ "shufps $0x1b, %%xmm1, %%xmm1 \n\t"
+ "mulps (%3,%0), %%xmm0 \n\t"
+ "mulps 16(%3,%0), %%xmm1 \n\t"
+ "movaps %%xmm0, (%2,%0) \n\t"
+ "movaps %%xmm1, 16(%2,%0) \n\t"
+ "add $32, %1 \n\t"
+ "sub $32, %0 \n\t"
+ "jge 1b \n\t"
+ :"+r"(i), "+r"(src1)
+ :"r"(dst), "r"(src0)
+ );
+}
+
+static void vector_fmul_add_add_3dnow(float *dst, const float *src0, const float *src1,
+ const float *src2, int src3, int len, int step){
+ long 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("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){
+ long 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);
+}
+
+static void float_to_int16_3dnow(int16_t *dst, const float *src, int len){
+ // not bit-exact: pf2id uses different rounding than C and SSE
+ int i;
+ for(i=0; i<len; i+=4) {
+ asm volatile(
+ "pf2id %1, %%mm0 \n\t"
+ "pf2id %2, %%mm1 \n\t"
+ "packssdw %%mm1, %%mm0 \n\t"
+ "movq %%mm0, %0 \n\t"
+ :"=m"(dst[i])
+ :"m"(src[i]), "m"(src[i+2])
+ );
+ }
+ asm volatile("femms");
+}
+static void float_to_int16_sse(int16_t *dst, const float *src, int len){
+ int i;
+ for(i=0; i<len; i+=4) {
+ asm volatile(
+ "cvtps2pi %1, %%mm0 \n\t"
+ "cvtps2pi %2, %%mm1 \n\t"
+ "packssdw %%mm1, %%mm0 \n\t"
+ "movq %%mm0, %0 \n\t"
+ :"=m"(dst[i])
+ :"m"(src[i]), "m"(src[i+2])
+ );
+ }
+ asm volatile("emms");
+}
+
+#ifdef CONFIG_SNOW_DECODER
+extern void ff_snow_horizontal_compose97i_sse2(DWTELEM *b, int width);
+extern void ff_snow_horizontal_compose97i_mmx(DWTELEM *b, int width);
+extern void ff_snow_vertical_compose97i_sse2(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWTELEM *b3, DWTELEM *b4, DWTELEM *b5, int width);
+extern void ff_snow_vertical_compose97i_mmx(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWTELEM *b3, DWTELEM *b4, DWTELEM *b5, int width);
+extern 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);
+extern 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);
+#endif
+
+void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
+{
+ mm_flags = mm_support();
+
+ if (avctx->dsp_mask) {
+ if (avctx->dsp_mask & FF_MM_FORCE)
+ mm_flags |= (avctx->dsp_mask & 0xffff);
+ else
+ mm_flags &= ~(avctx->dsp_mask & 0xffff);
+ }
+
+#if 0
+ av_log(avctx, AV_LOG_INFO, "libavcodec: CPU flags:");
+ if (mm_flags & MM_MMX)
+ av_log(avctx, AV_LOG_INFO, " mmx");
+ if (mm_flags & MM_MMXEXT)
+ av_log(avctx, AV_LOG_INFO, " mmxext");
+ if (mm_flags & MM_3DNOW)
+ av_log(avctx, AV_LOG_INFO, " 3dnow");
+ if (mm_flags & MM_SSE)
+ av_log(avctx, AV_LOG_INFO, " sse");
+ if (mm_flags & MM_SSE2)
+ av_log(avctx, AV_LOG_INFO, " sse2");
+ av_log(avctx, AV_LOG_INFO, "\n");
+#endif
+
+ if (mm_flags & MM_MMX) {
+ const int idct_algo= avctx->idct_algo;
+
+#ifdef CONFIG_ENCODERS
+ const int dct_algo = avctx->dct_algo;
+ if(dct_algo==FF_DCT_AUTO || dct_algo==FF_DCT_MMX){
+ if(mm_flags & MM_SSE2){
+ c->fdct = ff_fdct_sse2;
+ }else if(mm_flags & MM_MMXEXT){
+ c->fdct = ff_fdct_mmx2;
+ }else{
+ c->fdct = ff_fdct_mmx;
+ }
+ }
+#endif //CONFIG_ENCODERS
+ if(avctx->lowres==0){
+ if(idct_algo==FF_IDCT_AUTO || idct_algo==FF_IDCT_SIMPLEMMX){
+ c->idct_put= ff_simple_idct_put_mmx;
+ c->idct_add= ff_simple_idct_add_mmx;
+ c->idct = ff_simple_idct_mmx;
+ c->idct_permutation_type= FF_SIMPLE_IDCT_PERM;
+#ifdef CONFIG_GPL
+ }else if(idct_algo==FF_IDCT_LIBMPEG2MMX){
+ if(mm_flags & MM_MMXEXT){
+ c->idct_put= ff_libmpeg2mmx2_idct_put;
+ c->idct_add= ff_libmpeg2mmx2_idct_add;
+ c->idct = ff_mmxext_idct;
+ }else{
+ c->idct_put= ff_libmpeg2mmx_idct_put;
+ c->idct_add= ff_libmpeg2mmx_idct_add;
+ c->idct = ff_mmx_idct;
+ }
+ c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
+#endif
+ }else if(idct_algo==FF_IDCT_VP3 &&
+ avctx->codec->id!=CODEC_ID_THEORA &&
+ !(avctx->flags & CODEC_FLAG_BITEXACT)){
+ if(mm_flags & MM_SSE2){
+ c->idct_put= ff_vp3_idct_put_sse2;
+ c->idct_add= ff_vp3_idct_add_sse2;
+ c->idct = ff_vp3_idct_sse2;
+ c->idct_permutation_type= FF_TRANSPOSE_IDCT_PERM;
+ }else{
+ ff_vp3_dsp_init_mmx();
+ c->idct_put= ff_vp3_idct_put_mmx;
+ c->idct_add= ff_vp3_idct_add_mmx;
+ c->idct = ff_vp3_idct_mmx;
+ c->idct_permutation_type= FF_PARTTRANS_IDCT_PERM;
+ }
+ }else if(idct_algo==FF_IDCT_CAVS){
+ c->idct_permutation_type= FF_TRANSPOSE_IDCT_PERM;
+ }else if(idct_algo==FF_IDCT_XVIDMMX){
+ if(mm_flags & MM_MMXEXT){
+ c->idct_put= ff_idct_xvid_mmx2_put;
+ c->idct_add= ff_idct_xvid_mmx2_add;
+ c->idct = ff_idct_xvid_mmx2;
+ }else{
+ c->idct_put= ff_idct_xvid_mmx_put;
+ c->idct_add= ff_idct_xvid_mmx_add;
+ c->idct = ff_idct_xvid_mmx;
+ }
+ }
+ }
+
+#ifdef CONFIG_ENCODERS
+ c->get_pixels = get_pixels_mmx;
+ c->diff_pixels = diff_pixels_mmx;
+#endif //CONFIG_ENCODERS
+ c->put_pixels_clamped = put_pixels_clamped_mmx;
+ c->put_signed_pixels_clamped = put_signed_pixels_clamped_mmx;
+ c->add_pixels_clamped = add_pixels_clamped_mmx;
+ c->clear_blocks = clear_blocks_mmx;
+#ifdef CONFIG_ENCODERS
+ c->pix_sum = pix_sum16_mmx;
+#endif //CONFIG_ENCODERS
+
+ c->put_pixels_tab[0][0] = put_pixels16_mmx;
+ c->put_pixels_tab[0][1] = put_pixels16_x2_mmx;
+ c->put_pixels_tab[0][2] = put_pixels16_y2_mmx;
+ c->put_pixels_tab[0][3] = put_pixels16_xy2_mmx;
+
+ c->put_no_rnd_pixels_tab[0][0] = put_pixels16_mmx;
+ c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmx;
+ c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmx;
+ c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy2_mmx;
+
+ c->avg_pixels_tab[0][0] = avg_pixels16_mmx;
+ c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmx;
+ c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmx;
+ c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmx;
+
+ c->avg_no_rnd_pixels_tab[0][0] = avg_no_rnd_pixels16_mmx;
+ c->avg_no_rnd_pixels_tab[0][1] = avg_no_rnd_pixels16_x2_mmx;
+ c->avg_no_rnd_pixels_tab[0][2] = avg_no_rnd_pixels16_y2_mmx;
+ c->avg_no_rnd_pixels_tab[0][3] = avg_no_rnd_pixels16_xy2_mmx;
+
+ c->put_pixels_tab[1][0] = put_pixels8_mmx;
+ c->put_pixels_tab[1][1] = put_pixels8_x2_mmx;
+ c->put_pixels_tab[1][2] = put_pixels8_y2_mmx;
+ c->put_pixels_tab[1][3] = put_pixels8_xy2_mmx;
+
+ c->put_no_rnd_pixels_tab[1][0] = put_pixels8_mmx;
+ c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_mmx;
+ c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_mmx;
+ c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels8_xy2_mmx;
+
+ c->avg_pixels_tab[1][0] = avg_pixels8_mmx;
+ c->avg_pixels_tab[1][1] = avg_pixels8_x2_mmx;
+ c->avg_pixels_tab[1][2] = avg_pixels8_y2_mmx;
+ c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mmx;
+
+ c->avg_no_rnd_pixels_tab[1][0] = avg_no_rnd_pixels8_mmx;
+ c->avg_no_rnd_pixels_tab[1][1] = avg_no_rnd_pixels8_x2_mmx;
+ c->avg_no_rnd_pixels_tab[1][2] = avg_no_rnd_pixels8_y2_mmx;
+ c->avg_no_rnd_pixels_tab[1][3] = avg_no_rnd_pixels8_xy2_mmx;
+
+ c->gmc= gmc_mmx;
+
+ c->add_bytes= add_bytes_mmx;
+#ifdef CONFIG_ENCODERS
+ c->diff_bytes= diff_bytes_mmx;
+
+ c->hadamard8_diff[0]= hadamard8_diff16_mmx;
+ c->hadamard8_diff[1]= hadamard8_diff_mmx;
+
+ c->pix_norm1 = pix_norm1_mmx;
+ c->sse[0] = (mm_flags & MM_SSE2) ? sse16_sse2 : sse16_mmx;
+ c->sse[1] = sse8_mmx;
+ c->vsad[4]= vsad_intra16_mmx;
+
+ c->nsse[0] = nsse16_mmx;
+ c->nsse[1] = nsse8_mmx;
+ if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
+ c->vsad[0] = vsad16_mmx;
+ }
+
+ if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
+ c->try_8x8basis= try_8x8basis_mmx;
+ }
+ c->add_8x8basis= add_8x8basis_mmx;
+
+ c->ssd_int8_vs_int16 = ssd_int8_vs_int16_mmx;
+
+#endif //CONFIG_ENCODERS
+
+ c->h263_v_loop_filter= h263_v_loop_filter_mmx;
+ c->h263_h_loop_filter= h263_h_loop_filter_mmx;
+ c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_mmx;
+ c->put_h264_chroma_pixels_tab[1]= put_h264_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;
+
+ if (mm_flags & MM_MMXEXT) {
+ c->prefetch = prefetch_mmx2;
+
+ c->put_pixels_tab[0][1] = put_pixels16_x2_mmx2;
+ c->put_pixels_tab[0][2] = put_pixels16_y2_mmx2;
+
+ c->avg_pixels_tab[0][0] = avg_pixels16_mmx2;
+ c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmx2;
+ c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmx2;
+
+ c->put_pixels_tab[1][1] = put_pixels8_x2_mmx2;
+ c->put_pixels_tab[1][2] = put_pixels8_y2_mmx2;
+
+ c->avg_pixels_tab[1][0] = avg_pixels8_mmx2;
+ c->avg_pixels_tab[1][1] = avg_pixels8_x2_mmx2;
+ c->avg_pixels_tab[1][2] = avg_pixels8_y2_mmx2;
+
+#ifdef CONFIG_ENCODERS
+ c->hadamard8_diff[0]= hadamard8_diff16_mmx2;
+ c->hadamard8_diff[1]= hadamard8_diff_mmx2;
+ c->vsad[4]= vsad_intra16_mmx2;
+#endif //CONFIG_ENCODERS
+
+ c->h264_idct_dc_add= ff_h264_idct_dc_add_mmx2;
+ c->h264_idct8_dc_add= ff_h264_idct8_dc_add_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;
+ c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_mmx2;
+ c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_mmx2;
+ c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmx2;
+ c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mmx2;
+#ifdef CONFIG_ENCODERS
+ c->vsad[0] = vsad16_mmx2;
+#endif //CONFIG_ENCODERS
+ }
+
+#if 1
+ SET_QPEL_FUNC(qpel_pixels_tab[0][ 0], qpel16_mc00_mmx2)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][ 1], qpel16_mc10_mmx2)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][ 2], qpel16_mc20_mmx2)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][ 3], qpel16_mc30_mmx2)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][ 4], qpel16_mc01_mmx2)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][ 5], qpel16_mc11_mmx2)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][ 6], qpel16_mc21_mmx2)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][ 7], qpel16_mc31_mmx2)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][ 8], qpel16_mc02_mmx2)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][ 9], qpel16_mc12_mmx2)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][10], qpel16_mc22_mmx2)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][11], qpel16_mc32_mmx2)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][12], qpel16_mc03_mmx2)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][13], qpel16_mc13_mmx2)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][14], qpel16_mc23_mmx2)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][15], qpel16_mc33_mmx2)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][ 0], qpel8_mc00_mmx2)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][ 1], qpel8_mc10_mmx2)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][ 2], qpel8_mc20_mmx2)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][ 3], qpel8_mc30_mmx2)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][ 4], qpel8_mc01_mmx2)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][ 5], qpel8_mc11_mmx2)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][ 6], qpel8_mc21_mmx2)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][ 7], qpel8_mc31_mmx2)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][ 8], qpel8_mc02_mmx2)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][ 9], qpel8_mc12_mmx2)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][10], qpel8_mc22_mmx2)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][11], qpel8_mc32_mmx2)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][12], qpel8_mc03_mmx2)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][13], qpel8_mc13_mmx2)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][14], qpel8_mc23_mmx2)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][15], qpel8_mc33_mmx2)
+#endif
+
+//FIXME 3dnow too
+#define dspfunc(PFX, IDX, NUM) \
+ c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_mmx2; \
+ c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_mmx2; \
+ c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_mmx2; \
+ c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_mmx2; \
+ c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_mmx2; \
+ c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_mmx2; \
+ c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_mmx2; \
+ c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_mmx2; \
+ c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_mmx2; \
+ c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_mmx2; \
+ c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_mmx2; \
+ c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_mmx2; \
+ c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_mmx2; \
+ c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_mmx2; \
+ c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_mmx2; \
+ c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_mmx2
+
+ dspfunc(put_h264_qpel, 0, 16);
+ dspfunc(put_h264_qpel, 1, 8);
+ dspfunc(put_h264_qpel, 2, 4);
+ dspfunc(avg_h264_qpel, 0, 16);
+ dspfunc(avg_h264_qpel, 1, 8);
+ dspfunc(avg_h264_qpel, 2, 4);
+
+ dspfunc(put_2tap_qpel, 0, 16);
+ dspfunc(put_2tap_qpel, 1, 8);
+ dspfunc(avg_2tap_qpel, 0, 16);
+ dspfunc(avg_2tap_qpel, 1, 8);
+#undef dspfunc
+
+ c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_mmx2;
+ 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;
+ 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;
+
+#ifdef CONFIG_CAVS_DECODER
+ ff_cavsdsp_init_mmx2(c, avctx);
+#endif
+
+#ifdef CONFIG_ENCODERS
+ c->sub_hfyu_median_prediction= sub_hfyu_median_prediction_mmx2;
+#endif //CONFIG_ENCODERS
+ } else if (mm_flags & MM_3DNOW) {
+ c->prefetch = prefetch_3dnow;
+
+ c->put_pixels_tab[0][1] = put_pixels16_x2_3dnow;
+ c->put_pixels_tab[0][2] = put_pixels16_y2_3dnow;
+
+ c->avg_pixels_tab[0][0] = avg_pixels16_3dnow;
+ c->avg_pixels_tab[0][1] = avg_pixels16_x2_3dnow;
+ c->avg_pixels_tab[0][2] = avg_pixels16_y2_3dnow;
+
+ c->put_pixels_tab[1][1] = put_pixels8_x2_3dnow;
+ c->put_pixels_tab[1][2] = put_pixels8_y2_3dnow;
+
+ c->avg_pixels_tab[1][0] = avg_pixels8_3dnow;
+ c->avg_pixels_tab[1][1] = avg_pixels8_x2_3dnow;
+ c->avg_pixels_tab[1][2] = avg_pixels8_y2_3dnow;
+
+ if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
+ c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_3dnow;
+ c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_3dnow;
+ c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_3dnow;
+ c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_3dnow;
+ c->avg_pixels_tab[0][3] = avg_pixels16_xy2_3dnow;
+ c->avg_pixels_tab[1][3] = avg_pixels8_xy2_3dnow;
+ }
+
+ SET_QPEL_FUNC(qpel_pixels_tab[0][ 0], qpel16_mc00_3dnow)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][ 1], qpel16_mc10_3dnow)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][ 2], qpel16_mc20_3dnow)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][ 3], qpel16_mc30_3dnow)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][ 4], qpel16_mc01_3dnow)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][ 5], qpel16_mc11_3dnow)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][ 6], qpel16_mc21_3dnow)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][ 7], qpel16_mc31_3dnow)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][ 8], qpel16_mc02_3dnow)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][ 9], qpel16_mc12_3dnow)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][10], qpel16_mc22_3dnow)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][11], qpel16_mc32_3dnow)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][12], qpel16_mc03_3dnow)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][13], qpel16_mc13_3dnow)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][14], qpel16_mc23_3dnow)
+ SET_QPEL_FUNC(qpel_pixels_tab[0][15], qpel16_mc33_3dnow)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][ 0], qpel8_mc00_3dnow)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][ 1], qpel8_mc10_3dnow)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][ 2], qpel8_mc20_3dnow)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][ 3], qpel8_mc30_3dnow)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][ 4], qpel8_mc01_3dnow)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][ 5], qpel8_mc11_3dnow)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][ 6], qpel8_mc21_3dnow)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][ 7], qpel8_mc31_3dnow)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][ 8], qpel8_mc02_3dnow)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][ 9], qpel8_mc12_3dnow)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][10], qpel8_mc22_3dnow)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][11], qpel8_mc32_3dnow)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][12], qpel8_mc03_3dnow)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][13], qpel8_mc13_3dnow)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][14], qpel8_mc23_3dnow)
+ SET_QPEL_FUNC(qpel_pixels_tab[1][15], qpel8_mc33_3dnow)
+
+#define dspfunc(PFX, IDX, NUM) \
+ c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_3dnow; \
+ c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_3dnow; \
+ c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_3dnow; \
+ c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_3dnow; \
+ c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_3dnow; \
+ c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_3dnow; \
+ c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_3dnow; \
+ c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_3dnow; \
+ c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_3dnow; \
+ c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_3dnow; \
+ c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_3dnow; \
+ c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_3dnow; \
+ c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_3dnow; \
+ c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_3dnow; \
+ c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_3dnow; \
+ c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_3dnow
+
+ dspfunc(put_h264_qpel, 0, 16);
+ dspfunc(put_h264_qpel, 1, 8);
+ dspfunc(put_h264_qpel, 2, 4);
+ dspfunc(avg_h264_qpel, 0, 16);
+ dspfunc(avg_h264_qpel, 1, 8);
+ dspfunc(avg_h264_qpel, 2, 4);
+
+ dspfunc(put_2tap_qpel, 0, 16);
+ dspfunc(put_2tap_qpel, 1, 8);
+ dspfunc(avg_2tap_qpel, 0, 16);
+ dspfunc(avg_2tap_qpel, 1, 8);
+
+ c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_3dnow;
+ c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_3dnow;
+ }
+
+#ifdef CONFIG_SNOW_DECODER
+ if(mm_flags & MM_SSE2){
+ c->horizontal_compose97i = ff_snow_horizontal_compose97i_sse2;
+ c->vertical_compose97i = ff_snow_vertical_compose97i_sse2;
+ c->inner_add_yblock = ff_snow_inner_add_yblock_sse2;
+ }
+ else{
+ c->horizontal_compose97i = ff_snow_horizontal_compose97i_mmx;
+ c->vertical_compose97i = ff_snow_vertical_compose97i_mmx;
+ c->inner_add_yblock = ff_snow_inner_add_yblock_mmx;
+ }
+#endif
+
+ if(mm_flags & MM_3DNOW){
+ c->vorbis_inverse_coupling = vorbis_inverse_coupling_3dnow;
+ c->vector_fmul = vector_fmul_3dnow;
+ if(!(avctx->flags & CODEC_FLAG_BITEXACT))
+ c->float_to_int16 = float_to_int16_3dnow;
+ }
+ if(mm_flags & MM_3DNOWEXT)
+ c->vector_fmul_reverse = vector_fmul_reverse_3dnow2;
+ if(mm_flags & MM_SSE){
+ c->vorbis_inverse_coupling = vorbis_inverse_coupling_sse;
+ c->vector_fmul = vector_fmul_sse;
+ c->float_to_int16 = float_to_int16_sse;
+ c->vector_fmul_reverse = vector_fmul_reverse_sse;
+ c->vector_fmul_add_add = vector_fmul_add_add_sse;
+ }
+ if(mm_flags & MM_3DNOW)
+ c->vector_fmul_add_add = vector_fmul_add_add_3dnow; // faster than sse
+ }
+
+#ifdef CONFIG_ENCODERS
+ dsputil_init_pix_mmx(c, avctx);
+#endif //CONFIG_ENCODERS
+#if 0
+ // for speed testing
+ get_pixels = just_return;
+ put_pixels_clamped = just_return;
+ add_pixels_clamped = just_return;
+
+ pix_abs16x16 = just_return;
+ pix_abs16x16_x2 = just_return;
+ pix_abs16x16_y2 = just_return;
+ pix_abs16x16_xy2 = just_return;
+
+ put_pixels_tab[0] = just_return;
+ put_pixels_tab[1] = just_return;
+ put_pixels_tab[2] = just_return;
+ put_pixels_tab[3] = just_return;
+
+ put_no_rnd_pixels_tab[0] = just_return;
+ put_no_rnd_pixels_tab[1] = just_return;
+ put_no_rnd_pixels_tab[2] = just_return;
+ put_no_rnd_pixels_tab[3] = just_return;
+
+ avg_pixels_tab[0] = just_return;
+ avg_pixels_tab[1] = just_return;
+ avg_pixels_tab[2] = just_return;
+ avg_pixels_tab[3] = just_return;
+
+ avg_no_rnd_pixels_tab[0] = just_return;
+ avg_no_rnd_pixels_tab[1] = just_return;
+ avg_no_rnd_pixels_tab[2] = just_return;
+ avg_no_rnd_pixels_tab[3] = just_return;
+
+ //av_fdct = just_return;
+ //ff_idct = just_return;
+#endif
+}
diff --git a/src/libffmpeg/libavcodec/i386/dsputil_mmx_avg.h b/contrib/ffmpeg/libavcodec/i386/dsputil_mmx_avg.h
index b365cea57..b365cea57 100644
--- a/src/libffmpeg/libavcodec/i386/dsputil_mmx_avg.h
+++ b/contrib/ffmpeg/libavcodec/i386/dsputil_mmx_avg.h
diff --git a/src/libffmpeg/libavcodec/i386/dsputil_mmx_rnd.h b/contrib/ffmpeg/libavcodec/i386/dsputil_mmx_rnd.h
index f53b34662..f53b34662 100644
--- a/src/libffmpeg/libavcodec/i386/dsputil_mmx_rnd.h
+++ b/contrib/ffmpeg/libavcodec/i386/dsputil_mmx_rnd.h
diff --git a/src/libffmpeg/libavcodec/i386/fdct_mmx.c b/contrib/ffmpeg/libavcodec/i386/fdct_mmx.c
index 7e2682a4a..7e2682a4a 100644
--- a/src/libffmpeg/libavcodec/i386/fdct_mmx.c
+++ b/contrib/ffmpeg/libavcodec/i386/fdct_mmx.c
diff --git a/src/libffmpeg/libavcodec/i386/fft_3dn.c b/contrib/ffmpeg/libavcodec/i386/fft_3dn.c
index 8087f1932..8087f1932 100644
--- a/src/libffmpeg/libavcodec/i386/fft_3dn.c
+++ b/contrib/ffmpeg/libavcodec/i386/fft_3dn.c
diff --git a/src/libffmpeg/libavcodec/i386/fft_3dn2.c b/contrib/ffmpeg/libavcodec/i386/fft_3dn2.c
index a4fe5f0b6..a4fe5f0b6 100644
--- a/src/libffmpeg/libavcodec/i386/fft_3dn2.c
+++ b/contrib/ffmpeg/libavcodec/i386/fft_3dn2.c
diff --git a/src/libffmpeg/libavcodec/i386/fft_sse.c b/contrib/ffmpeg/libavcodec/i386/fft_sse.c
index 0dc0c61c1..0dc0c61c1 100644
--- a/src/libffmpeg/libavcodec/i386/fft_sse.c
+++ b/contrib/ffmpeg/libavcodec/i386/fft_sse.c
diff --git a/contrib/ffmpeg/libavcodec/i386/h264dsp_mmx.c b/contrib/ffmpeg/libavcodec/i386/h264dsp_mmx.c
new file mode 100644
index 000000000..56004b674
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/i386/h264dsp_mmx.c
@@ -0,0 +1,1517 @@
+/*
+ * Copyright (c) 2004-2005 Michael Niedermayer, Loren Merritt
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+/***********************************/
+/* IDCT */
+
+/* in/out: mma=mma+mmb, mmb=mmb-mma */
+#define SUMSUB_BA( a, b ) \
+ "paddw "#b", "#a" \n\t"\
+ "paddw "#b", "#b" \n\t"\
+ "psubw "#a", "#b" \n\t"
+
+#define SUMSUB_BADC( a, b, c, d ) \
+ "paddw "#b", "#a" \n\t"\
+ "paddw "#d", "#c" \n\t"\
+ "paddw "#b", "#b" \n\t"\
+ "paddw "#d", "#d" \n\t"\
+ "psubw "#a", "#b" \n\t"\
+ "psubw "#c", "#d" \n\t"
+
+#define SUMSUBD2_AB( a, b, t ) \
+ "movq "#b", "#t" \n\t"\
+ "psraw $1 , "#b" \n\t"\
+ "paddw "#a", "#b" \n\t"\
+ "psraw $1 , "#a" \n\t"\
+ "psubw "#t", "#a" \n\t"
+
+#define IDCT4_1D( s02, s13, d02, d13, t ) \
+ SUMSUB_BA ( s02, d02 )\
+ SUMSUBD2_AB( s13, d13, t )\
+ SUMSUB_BADC( d13, s02, s13, d02 )
+
+#define TRANSPOSE4(a,b,c,d,t)\
+ SBUTTERFLY(a,b,t,wd) /* a=aebf t=cgdh */\
+ SBUTTERFLY(c,d,b,wd) /* c=imjn b=kolp */\
+ SBUTTERFLY(a,c,d,dq) /* a=aeim d=bfjn */\
+ SBUTTERFLY(t,b,c,dq) /* t=cgko c=dhlp */
+
+#define STORE_DIFF_4P( p, t, z ) \
+ "psraw $6, "#p" \n\t"\
+ "movd (%0), "#t" \n\t"\
+ "punpcklbw "#z", "#t" \n\t"\
+ "paddsw "#t", "#p" \n\t"\
+ "packuswb "#z", "#p" \n\t"\
+ "movd "#p", (%0) \n\t"
+
+static void ff_h264_idct_add_mmx(uint8_t *dst, int16_t *block, int stride)
+{
+ /* Load dct coeffs */
+ asm volatile(
+ "movq (%0), %%mm0 \n\t"
+ "movq 8(%0), %%mm1 \n\t"
+ "movq 16(%0), %%mm2 \n\t"
+ "movq 24(%0), %%mm3 \n\t"
+ :: "r"(block) );
+
+ asm volatile(
+ /* mm1=s02+s13 mm2=s02-s13 mm4=d02+d13 mm0=d02-d13 */
+ IDCT4_1D( %%mm2, %%mm1, %%mm0, %%mm3, %%mm4 )
+
+ "movq %0, %%mm6 \n\t"
+ /* in: 1,4,0,2 out: 1,2,3,0 */
+ TRANSPOSE4( %%mm3, %%mm1, %%mm0, %%mm2, %%mm4 )
+
+ "paddw %%mm6, %%mm3 \n\t"
+
+ /* mm2=s02+s13 mm3=s02-s13 mm4=d02+d13 mm1=d02-d13 */
+ IDCT4_1D( %%mm4, %%mm2, %%mm3, %%mm0, %%mm1 )
+
+ "pxor %%mm7, %%mm7 \n\t"
+ :: "m"(ff_pw_32));
+
+ asm volatile(
+ STORE_DIFF_4P( %%mm0, %%mm1, %%mm7)
+ "add %1, %0 \n\t"
+ STORE_DIFF_4P( %%mm2, %%mm1, %%mm7)
+ "add %1, %0 \n\t"
+ STORE_DIFF_4P( %%mm3, %%mm1, %%mm7)
+ "add %1, %0 \n\t"
+ STORE_DIFF_4P( %%mm4, %%mm1, %%mm7)
+ : "+r"(dst)
+ : "r" ((long)stride)
+ );
+}
+
+static inline void h264_idct8_1d(int16_t *block)
+{
+ asm volatile(
+ "movq 112(%0), %%mm7 \n\t"
+ "movq 80(%0), %%mm5 \n\t"
+ "movq 48(%0), %%mm3 \n\t"
+ "movq 16(%0), %%mm1 \n\t"
+
+ "movq %%mm7, %%mm4 \n\t"
+ "movq %%mm3, %%mm6 \n\t"
+ "movq %%mm5, %%mm0 \n\t"
+ "movq %%mm7, %%mm2 \n\t"
+ "psraw $1, %%mm4 \n\t"
+ "psraw $1, %%mm6 \n\t"
+ "psubw %%mm7, %%mm0 \n\t"
+ "psubw %%mm6, %%mm2 \n\t"
+ "psubw %%mm4, %%mm0 \n\t"
+ "psubw %%mm3, %%mm2 \n\t"
+ "psubw %%mm3, %%mm0 \n\t"
+ "paddw %%mm1, %%mm2 \n\t"
+
+ "movq %%mm5, %%mm4 \n\t"
+ "movq %%mm1, %%mm6 \n\t"
+ "psraw $1, %%mm4 \n\t"
+ "psraw $1, %%mm6 \n\t"
+ "paddw %%mm5, %%mm4 \n\t"
+ "paddw %%mm1, %%mm6 \n\t"
+ "paddw %%mm7, %%mm4 \n\t"
+ "paddw %%mm5, %%mm6 \n\t"
+ "psubw %%mm1, %%mm4 \n\t"
+ "paddw %%mm3, %%mm6 \n\t"
+
+ "movq %%mm0, %%mm1 \n\t"
+ "movq %%mm4, %%mm3 \n\t"
+ "movq %%mm2, %%mm5 \n\t"
+ "movq %%mm6, %%mm7 \n\t"
+ "psraw $2, %%mm6 \n\t"
+ "psraw $2, %%mm3 \n\t"
+ "psraw $2, %%mm5 \n\t"
+ "psraw $2, %%mm0 \n\t"
+ "paddw %%mm6, %%mm1 \n\t"
+ "paddw %%mm2, %%mm3 \n\t"
+ "psubw %%mm4, %%mm5 \n\t"
+ "psubw %%mm0, %%mm7 \n\t"
+
+ "movq 32(%0), %%mm2 \n\t"
+ "movq 96(%0), %%mm6 \n\t"
+ "movq %%mm2, %%mm4 \n\t"
+ "movq %%mm6, %%mm0 \n\t"
+ "psraw $1, %%mm4 \n\t"
+ "psraw $1, %%mm6 \n\t"
+ "psubw %%mm0, %%mm4 \n\t"
+ "paddw %%mm2, %%mm6 \n\t"
+
+ "movq (%0), %%mm2 \n\t"
+ "movq 64(%0), %%mm0 \n\t"
+ SUMSUB_BA( %%mm0, %%mm2 )
+ SUMSUB_BA( %%mm6, %%mm0 )
+ SUMSUB_BA( %%mm4, %%mm2 )
+ SUMSUB_BA( %%mm7, %%mm6 )
+ SUMSUB_BA( %%mm5, %%mm4 )
+ SUMSUB_BA( %%mm3, %%mm2 )
+ SUMSUB_BA( %%mm1, %%mm0 )
+ :: "r"(block)
+ );
+}
+
+static void ff_h264_idct8_add_mmx(uint8_t *dst, int16_t *block, int stride)
+{
+ int i;
+ int16_t __attribute__ ((aligned(8))) b2[64];
+
+ block[0] += 32;
+
+ for(i=0; i<2; i++){
+ DECLARE_ALIGNED_8(uint64_t, tmp);
+
+ h264_idct8_1d(block+4*i);
+
+ asm volatile(
+ "movq %%mm7, %0 \n\t"
+ TRANSPOSE4( %%mm0, %%mm2, %%mm4, %%mm6, %%mm7 )
+ "movq %%mm0, 8(%1) \n\t"
+ "movq %%mm6, 24(%1) \n\t"
+ "movq %%mm7, 40(%1) \n\t"
+ "movq %%mm4, 56(%1) \n\t"
+ "movq %0, %%mm7 \n\t"
+ TRANSPOSE4( %%mm7, %%mm5, %%mm3, %%mm1, %%mm0 )
+ "movq %%mm7, (%1) \n\t"
+ "movq %%mm1, 16(%1) \n\t"
+ "movq %%mm0, 32(%1) \n\t"
+ "movq %%mm3, 48(%1) \n\t"
+ : "=m"(tmp)
+ : "r"(b2+32*i)
+ : "memory"
+ );
+ }
+
+ for(i=0; i<2; i++){
+ h264_idct8_1d(b2+4*i);
+
+ asm volatile(
+ "psraw $6, %%mm7 \n\t"
+ "psraw $6, %%mm6 \n\t"
+ "psraw $6, %%mm5 \n\t"
+ "psraw $6, %%mm4 \n\t"
+ "psraw $6, %%mm3 \n\t"
+ "psraw $6, %%mm2 \n\t"
+ "psraw $6, %%mm1 \n\t"
+ "psraw $6, %%mm0 \n\t"
+
+ "movq %%mm7, (%0) \n\t"
+ "movq %%mm5, 16(%0) \n\t"
+ "movq %%mm3, 32(%0) \n\t"
+ "movq %%mm1, 48(%0) \n\t"
+ "movq %%mm0, 64(%0) \n\t"
+ "movq %%mm2, 80(%0) \n\t"
+ "movq %%mm4, 96(%0) \n\t"
+ "movq %%mm6, 112(%0) \n\t"
+ :: "r"(b2+4*i)
+ : "memory"
+ );
+ }
+
+ add_pixels_clamped_mmx(b2, dst, stride);
+}
+
+static void ff_h264_idct_dc_add_mmx2(uint8_t *dst, int16_t *block, int stride)
+{
+ int dc = (block[0] + 32) >> 6;
+ asm volatile(
+ "movd %0, %%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"
+ ::"r"(dc)
+ );
+ asm volatile(
+ "movd %0, %%mm2 \n\t"
+ "movd %1, %%mm3 \n\t"
+ "movd %2, %%mm4 \n\t"
+ "movd %3, %%mm5 \n\t"
+ "paddusb %%mm0, %%mm2 \n\t"
+ "paddusb %%mm0, %%mm3 \n\t"
+ "paddusb %%mm0, %%mm4 \n\t"
+ "paddusb %%mm0, %%mm5 \n\t"
+ "psubusb %%mm1, %%mm2 \n\t"
+ "psubusb %%mm1, %%mm3 \n\t"
+ "psubusb %%mm1, %%mm4 \n\t"
+ "psubusb %%mm1, %%mm5 \n\t"
+ "movd %%mm2, %0 \n\t"
+ "movd %%mm3, %1 \n\t"
+ "movd %%mm4, %2 \n\t"
+ "movd %%mm5, %3 \n\t"
+ :"+m"(*(uint32_t*)(dst+0*stride)),
+ "+m"(*(uint32_t*)(dst+1*stride)),
+ "+m"(*(uint32_t*)(dst+2*stride)),
+ "+m"(*(uint32_t*)(dst+3*stride))
+ );
+}
+
+static void ff_h264_idct8_dc_add_mmx2(uint8_t *dst, int16_t *block, int stride)
+{
+ int dc = (block[0] + 32) >> 6;
+ int y;
+ asm volatile(
+ "movd %0, %%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"
+ ::"r"(dc)
+ );
+ for(y=2; y--; dst += 4*stride){
+ asm volatile(
+ "movq %0, %%mm2 \n\t"
+ "movq %1, %%mm3 \n\t"
+ "movq %2, %%mm4 \n\t"
+ "movq %3, %%mm5 \n\t"
+ "paddusb %%mm0, %%mm2 \n\t"
+ "paddusb %%mm0, %%mm3 \n\t"
+ "paddusb %%mm0, %%mm4 \n\t"
+ "paddusb %%mm0, %%mm5 \n\t"
+ "psubusb %%mm1, %%mm2 \n\t"
+ "psubusb %%mm1, %%mm3 \n\t"
+ "psubusb %%mm1, %%mm4 \n\t"
+ "psubusb %%mm1, %%mm5 \n\t"
+ "movq %%mm2, %0 \n\t"
+ "movq %%mm3, %1 \n\t"
+ "movq %%mm4, %2 \n\t"
+ "movq %%mm5, %3 \n\t"
+ :"+m"(*(uint64_t*)(dst+0*stride)),
+ "+m"(*(uint64_t*)(dst+1*stride)),
+ "+m"(*(uint64_t*)(dst+2*stride)),
+ "+m"(*(uint64_t*)(dst+3*stride))
+ );
+ }
+}
+
+
+/***********************************/
+/* deblocking */
+
+// out: o = |x-y|>a
+// clobbers: t
+#define DIFF_GT_MMX(x,y,a,o,t)\
+ "movq "#y", "#t" \n\t"\
+ "movq "#x", "#o" \n\t"\
+ "psubusb "#x", "#t" \n\t"\
+ "psubusb "#y", "#o" \n\t"\
+ "por "#t", "#o" \n\t"\
+ "psubusb "#a", "#o" \n\t"
+
+// out: o = |x-y|>a
+// clobbers: t
+#define DIFF_GT2_MMX(x,y,a,o,t)\
+ "movq "#y", "#t" \n\t"\
+ "movq "#x", "#o" \n\t"\
+ "psubusb "#x", "#t" \n\t"\
+ "psubusb "#y", "#o" \n\t"\
+ "psubusb "#a", "#t" \n\t"\
+ "psubusb "#a", "#o" \n\t"\
+ "pcmpeqb "#t", "#o" \n\t"\
+
+// in: mm0=p1 mm1=p0 mm2=q0 mm3=q1
+// out: mm5=beta-1, mm7=mask
+// clobbers: mm4,mm6
+#define H264_DEBLOCK_MASK(alpha1, beta1) \
+ "pshufw $0, "#alpha1", %%mm4 \n\t"\
+ "pshufw $0, "#beta1 ", %%mm5 \n\t"\
+ "packuswb %%mm4, %%mm4 \n\t"\
+ "packuswb %%mm5, %%mm5 \n\t"\
+ DIFF_GT_MMX(%%mm1, %%mm2, %%mm4, %%mm7, %%mm6) /* |p0-q0| > alpha-1 */\
+ DIFF_GT_MMX(%%mm0, %%mm1, %%mm5, %%mm4, %%mm6) /* |p1-p0| > beta-1 */\
+ "por %%mm4, %%mm7 \n\t"\
+ DIFF_GT_MMX(%%mm3, %%mm2, %%mm5, %%mm4, %%mm6) /* |q1-q0| > beta-1 */\
+ "por %%mm4, %%mm7 \n\t"\
+ "pxor %%mm6, %%mm6 \n\t"\
+ "pcmpeqb %%mm6, %%mm7 \n\t"
+
+// in: mm0=p1 mm1=p0 mm2=q0 mm3=q1 mm7=(tc&mask)
+// out: mm1=p0' mm2=q0'
+// clobbers: mm0,3-6
+#define H264_DEBLOCK_P0_Q0(pb_01, pb_3f)\
+ "movq %%mm1 , %%mm5 \n\t"\
+ "pxor %%mm2 , %%mm5 \n\t" /* p0^q0*/\
+ "pand "#pb_01" , %%mm5 \n\t" /* (p0^q0)&1*/\
+ "pcmpeqb %%mm4 , %%mm4 \n\t"\
+ "pxor %%mm4 , %%mm3 \n\t"\
+ "pavgb %%mm0 , %%mm3 \n\t" /* (p1 - q1 + 256)>>1*/\
+ "pavgb "MANGLE(ff_pb_3)" , %%mm3 \n\t" /*(((p1 - q1 + 256)>>1)+4)>>1 = 64+2+(p1-q1)>>2*/\
+ "pxor %%mm1 , %%mm4 \n\t"\
+ "pavgb %%mm2 , %%mm4 \n\t" /* (q0 - p0 + 256)>>1*/\
+ "pavgb %%mm5 , %%mm3 \n\t"\
+ "paddusb %%mm4 , %%mm3 \n\t" /* d+128+33*/\
+ "movq "MANGLE(ff_pb_A1)" , %%mm6 \n\t"\
+ "psubusb %%mm3 , %%mm6 \n\t"\
+ "psubusb "MANGLE(ff_pb_A1)" , %%mm3 \n\t"\
+ "pminub %%mm7 , %%mm6 \n\t"\
+ "pminub %%mm7 , %%mm3 \n\t"\
+ "psubusb %%mm6 , %%mm1 \n\t"\
+ "psubusb %%mm3 , %%mm2 \n\t"\
+ "paddusb %%mm3 , %%mm1 \n\t"\
+ "paddusb %%mm6 , %%mm2 \n\t"
+
+// in: mm0=p1 mm1=p0 mm2=q0 mm3=q1 mm7=(tc&mask) %8=mm_bone
+// out: (q1addr) = clip( (q2+((p0+q0+1)>>1))>>1, q1-tc0, q1+tc0 )
+// clobbers: q2, tmp, tc0
+#define H264_DEBLOCK_Q1(p1, q2, q2addr, q1addr, tc0, tmp)\
+ "movq %%mm1, "#tmp" \n\t"\
+ "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 */\
+ "psubusb "#tmp", "#q2" \n\t" /* (p2+((p0+q0+1)>>1))>>1 */\
+ "movq "#p1", "#tmp" \n\t"\
+ "psubusb "#tc0", "#tmp" \n\t"\
+ "paddusb "#p1", "#tc0" \n\t"\
+ "pmaxub "#tmp", "#q2" \n\t"\
+ "pminub "#tc0", "#q2" \n\t"\
+ "movq "#q2", "q1addr" \n\t"
+
+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]);
+
+ 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)
+
+ "movd %5, %%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"
+ "pand %%mm4, %%mm7 \n\t"
+ "movq %%mm7, %0 \n\t"
+
+ /* filter p1 */
+ "movq (%1), %%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
+ "pand 8+%0, %%mm7 \n\t" // mask & tc0
+ "movq %%mm7, %%mm4 \n\t"
+ "psubb %%mm6, %%mm7 \n\t"
+ "pand %%mm4, %%mm6 \n\t" // mask & |p2-p0|<beta & tc0
+ H264_DEBLOCK_Q1(%%mm0, %%mm3, "(%1)", "(%1,%3)", %%mm6, %%mm4)
+
+ /* filter q1 */
+ "movq (%2,%3,2), %%mm4 \n\t" //q2
+ DIFF_GT2_MMX(%%mm2, %%mm4, %%mm5, %%mm6, %%mm3) // |q2-q0|>beta-1
+ "pand %0, %%mm6 \n\t"
+ "movq 8+%0, %%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)
+
+ /* filter p0, q0 */
+ H264_DEBLOCK_P0_Q0(%8, unused)
+ "movq %%mm1, (%1,%3,2) \n\t"
+ "movq %%mm2, (%2) \n\t"
+
+ : "=m"(*tmp0)
+ : "r"(pix-3*stride), "r"(pix), "r"((long)stride),
+ "m"(*tmp0/*unused*/), "m"(*(uint32_t*)tc0), "m"(alpha1), "m"(beta1),
+ "m"(mm_bone)
+ );
+}
+
+static void h264_v_loop_filter_luma_mmx2(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
+{
+ if((tc0[0] & tc0[1]) >= 0)
+ h264_loop_filter_luma_mmx2(pix, stride, alpha-1, beta-1, tc0);
+ if((tc0[2] & tc0[3]) >= 0)
+ h264_loop_filter_luma_mmx2(pix+8, stride, alpha-1, beta-1, tc0+2);
+}
+static void h264_h_loop_filter_luma_mmx2(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
+{
+ //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]);
+ int i;
+ for(i=0; i<2; i++, pix+=8*stride, tc0+=2) {
+ if((tc0[0] & tc0[1]) < 0)
+ continue;
+ transpose4x4(trans, pix-4, 8, stride);
+ transpose4x4(trans +4*8, pix, 8, stride);
+ transpose4x4(trans+4, pix-4+4*stride, 8, stride);
+ transpose4x4(trans+4+4*8, pix +4*stride, 8, stride);
+ h264_loop_filter_luma_mmx2(trans+4*8, 8, alpha-1, beta-1, tc0);
+ transpose4x4(pix-2, trans +2*8, stride, 8);
+ transpose4x4(pix-2+4*stride, trans+4+2*8, stride, 8);
+ }
+}
+
+static inline void h264_loop_filter_chroma_mmx2(uint8_t *pix, int stride, int alpha1, int beta1, int8_t *tc0)
+{
+ asm volatile(
+ "movq (%0), %%mm0 \n\t" //p1
+ "movq (%0,%2), %%mm1 \n\t" //p0
+ "movq (%1), %%mm2 \n\t" //q0
+ "movq (%1,%2), %%mm3 \n\t" //q1
+ H264_DEBLOCK_MASK(%4, %5)
+ "movd %3, %%mm6 \n\t"
+ "punpcklbw %%mm6, %%mm6 \n\t"
+ "pand %%mm6, %%mm7 \n\t" // mm7 = tc&mask
+ H264_DEBLOCK_P0_Q0(%6, %7)
+ "movq %%mm1, (%0,%2) \n\t"
+ "movq %%mm2, (%1) \n\t"
+
+ :: "r"(pix-2*stride), "r"(pix), "r"((long)stride),
+ "r"(*(uint32_t*)tc0),
+ "m"(alpha1), "m"(beta1), "m"(mm_bone), "m"(ff_pb_3F)
+ );
+}
+
+static void h264_v_loop_filter_chroma_mmx2(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
+{
+ h264_loop_filter_chroma_mmx2(pix, stride, alpha-1, beta-1, tc0);
+}
+
+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]);
+ 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);
+ transpose4x4(pix-2, trans, stride, 8);
+ transpose4x4(pix-2+4*stride, trans+4, stride, 8);
+}
+
+// p0 = (p0 + q1 + 2*p1 + 2) >> 2
+#define H264_FILTER_CHROMA4(p0, p1, q1, one) \
+ "movq "#p0", %%mm4 \n\t"\
+ "pxor "#q1", %%mm4 \n\t"\
+ "pand "#one", %%mm4 \n\t" /* mm4 = (p0^q1)&1 */\
+ "pavgb "#q1", "#p0" \n\t"\
+ "psubusb %%mm4, "#p0" \n\t"\
+ "pavgb "#p1", "#p0" \n\t" /* dst = avg(p1, avg(p0,q1) - ((p0^q1)&1)) */\
+
+static inline void h264_loop_filter_chroma_intra_mmx2(uint8_t *pix, int stride, int alpha1, int beta1)
+{
+ asm volatile(
+ "movq (%0), %%mm0 \n\t"
+ "movq (%0,%2), %%mm1 \n\t"
+ "movq (%1), %%mm2 \n\t"
+ "movq (%1,%2), %%mm3 \n\t"
+ H264_DEBLOCK_MASK(%3, %4)
+ "movq %%mm1, %%mm5 \n\t"
+ "movq %%mm2, %%mm6 \n\t"
+ H264_FILTER_CHROMA4(%%mm1, %%mm0, %%mm3, %5) //p0'
+ H264_FILTER_CHROMA4(%%mm2, %%mm3, %%mm0, %5) //q0'
+ "psubb %%mm5, %%mm1 \n\t"
+ "psubb %%mm6, %%mm2 \n\t"
+ "pand %%mm7, %%mm1 \n\t"
+ "pand %%mm7, %%mm2 \n\t"
+ "paddb %%mm5, %%mm1 \n\t"
+ "paddb %%mm6, %%mm2 \n\t"
+ "movq %%mm1, (%0,%2) \n\t"
+ "movq %%mm2, (%1) \n\t"
+ :: "r"(pix-2*stride), "r"(pix), "r"((long)stride),
+ "m"(alpha1), "m"(beta1), "m"(mm_bone)
+ );
+}
+
+static void h264_v_loop_filter_chroma_intra_mmx2(uint8_t *pix, int stride, int alpha, int beta)
+{
+ h264_loop_filter_chroma_intra_mmx2(pix, stride, alpha-1, beta-1);
+}
+
+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]);
+ 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);
+ transpose4x4(pix-2, trans, stride, 8);
+ transpose4x4(pix-2+4*stride, trans+4, stride, 8);
+}
+
+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 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)
+ );
+ // 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 int mask_mv = dir ? mask_mv1 : mask_mv0;
+ DECLARE_ALIGNED_8(const uint64_t, mask_dir) = dir ? 0 : 0xffffffffffffffffULL;
+ int b_idx, edge, l;
+ for( b_idx=12, edge=0; edge<edges; edge+=step, b_idx+=8*step ) {
+ asm volatile(
+ "pand %0, %%mm0 \n\t"
+ ::"m"(mask_dir)
+ );
+ if(!(mask_mv & edge)) {
+ asm volatile("pxor %%mm0, %%mm0 \n\t":);
+ for( l = bidir; l >= 0; l-- ) {
+ 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])
+ );
+ }
+ }
+ 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]
+ ::"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"
+ :"=m"(*bS[dir][edge])
+ ::"memory"
+ );
+ }
+ edges = 4;
+ step = 1;
+ }
+ asm volatile(
+ "movq (%0), %%mm0 \n\t"
+ "movq 8(%0), %%mm1 \n\t"
+ "movq 16(%0), %%mm2 \n\t"
+ "movq 24(%0), %%mm3 \n\t"
+ TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4)
+ "movq %%mm0, (%0) \n\t"
+ "movq %%mm3, 8(%0) \n\t"
+ "movq %%mm4, 16(%0) \n\t"
+ "movq %%mm2, 24(%0) \n\t"
+ ::"r"(bS[0])
+ :"memory"
+ );
+}
+
+/***********************************/
+/* motion compensation */
+
+#define QPEL_H264V(A,B,C,D,E,F,OP)\
+ "movd (%0), "#F" \n\t"\
+ "movq "#C", %%mm6 \n\t"\
+ "paddw "#D", %%mm6 \n\t"\
+ "psllw $2, %%mm6 \n\t"\
+ "psubw "#B", %%mm6 \n\t"\
+ "psubw "#E", %%mm6 \n\t"\
+ "pmullw %4, %%mm6 \n\t"\
+ "add %2, %0 \n\t"\
+ "punpcklbw %%mm7, "#F" \n\t"\
+ "paddw %5, "#A" \n\t"\
+ "paddw "#F", "#A" \n\t"\
+ "paddw "#A", %%mm6 \n\t"\
+ "psraw $5, %%mm6 \n\t"\
+ "packuswb %%mm6, %%mm6 \n\t"\
+ OP(%%mm6, (%1), A, d)\
+ "add %3, %1 \n\t"
+
+#define QPEL_H264HV(A,B,C,D,E,F,OF)\
+ "movd (%0), "#F" \n\t"\
+ "movq "#C", %%mm6 \n\t"\
+ "paddw "#D", %%mm6 \n\t"\
+ "psllw $2, %%mm6 \n\t"\
+ "psubw "#B", %%mm6 \n\t"\
+ "psubw "#E", %%mm6 \n\t"\
+ "pmullw %3, %%mm6 \n\t"\
+ "add %2, %0 \n\t"\
+ "punpcklbw %%mm7, "#F" \n\t"\
+ "paddw "#F", "#A" \n\t"\
+ "paddw "#A", %%mm6 \n\t"\
+ "movq %%mm6, "#OF"(%1) \n\t"
+
+#define QPEL_H264(OPNAME, OP, MMX)\
+static av_noinline void OPNAME ## h264_qpel4_h_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ int h=4;\
+\
+ asm volatile(\
+ "pxor %%mm7, %%mm7 \n\t"\
+ "movq %5, %%mm4 \n\t"\
+ "movq %6, %%mm5 \n\t"\
+ "1: \n\t"\
+ "movd -1(%0), %%mm1 \n\t"\
+ "movd (%0), %%mm2 \n\t"\
+ "movd 1(%0), %%mm3 \n\t"\
+ "movd 2(%0), %%mm0 \n\t"\
+ "punpcklbw %%mm7, %%mm1 \n\t"\
+ "punpcklbw %%mm7, %%mm2 \n\t"\
+ "punpcklbw %%mm7, %%mm3 \n\t"\
+ "punpcklbw %%mm7, %%mm0 \n\t"\
+ "paddw %%mm0, %%mm1 \n\t"\
+ "paddw %%mm3, %%mm2 \n\t"\
+ "movd -2(%0), %%mm0 \n\t"\
+ "movd 3(%0), %%mm3 \n\t"\
+ "punpcklbw %%mm7, %%mm0 \n\t"\
+ "punpcklbw %%mm7, %%mm3 \n\t"\
+ "paddw %%mm3, %%mm0 \n\t"\
+ "psllw $2, %%mm2 \n\t"\
+ "psubw %%mm1, %%mm2 \n\t"\
+ "pmullw %%mm4, %%mm2 \n\t"\
+ "paddw %%mm5, %%mm0 \n\t"\
+ "paddw %%mm2, %%mm0 \n\t"\
+ "psraw $5, %%mm0 \n\t"\
+ "packuswb %%mm0, %%mm0 \n\t"\
+ OP(%%mm0, (%1),%%mm6, d)\
+ "add %3, %0 \n\t"\
+ "add %4, %1 \n\t"\
+ "decl %2 \n\t"\
+ " jnz 1b \n\t"\
+ : "+a"(src), "+c"(dst), "+m"(h)\
+ : "d"((long)srcStride), "S"((long)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\
+ : "memory"\
+ );\
+}\
+static av_noinline void OPNAME ## h264_qpel4_h_lowpass_l2_ ## MMX(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride){\
+ int h=4;\
+ asm volatile(\
+ "pxor %%mm7, %%mm7 \n\t"\
+ "movq %0, %%mm4 \n\t"\
+ "movq %1, %%mm5 \n\t"\
+ :: "m"(ff_pw_5), "m"(ff_pw_16)\
+ );\
+ do{\
+ asm volatile(\
+ "movd -1(%0), %%mm1 \n\t"\
+ "movd (%0), %%mm2 \n\t"\
+ "movd 1(%0), %%mm3 \n\t"\
+ "movd 2(%0), %%mm0 \n\t"\
+ "punpcklbw %%mm7, %%mm1 \n\t"\
+ "punpcklbw %%mm7, %%mm2 \n\t"\
+ "punpcklbw %%mm7, %%mm3 \n\t"\
+ "punpcklbw %%mm7, %%mm0 \n\t"\
+ "paddw %%mm0, %%mm1 \n\t"\
+ "paddw %%mm3, %%mm2 \n\t"\
+ "movd -2(%0), %%mm0 \n\t"\
+ "movd 3(%0), %%mm3 \n\t"\
+ "punpcklbw %%mm7, %%mm0 \n\t"\
+ "punpcklbw %%mm7, %%mm3 \n\t"\
+ "paddw %%mm3, %%mm0 \n\t"\
+ "psllw $2, %%mm2 \n\t"\
+ "psubw %%mm1, %%mm2 \n\t"\
+ "pmullw %%mm4, %%mm2 \n\t"\
+ "paddw %%mm5, %%mm0 \n\t"\
+ "paddw %%mm2, %%mm0 \n\t"\
+ "movd (%2), %%mm3 \n\t"\
+ "psraw $5, %%mm0 \n\t"\
+ "packuswb %%mm0, %%mm0 \n\t"\
+ PAVGB" %%mm3, %%mm0 \n\t"\
+ OP(%%mm0, (%1),%%mm6, d)\
+ "add %4, %0 \n\t"\
+ "add %4, %1 \n\t"\
+ "add %3, %2 \n\t"\
+ : "+a"(src), "+c"(dst), "+d"(src2)\
+ : "D"((long)src2Stride), "S"((long)dstStride)\
+ : "memory"\
+ );\
+ }while(--h);\
+}\
+static av_noinline void OPNAME ## h264_qpel4_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ src -= 2*srcStride;\
+ asm volatile(\
+ "pxor %%mm7, %%mm7 \n\t"\
+ "movd (%0), %%mm0 \n\t"\
+ "add %2, %0 \n\t"\
+ "movd (%0), %%mm1 \n\t"\
+ "add %2, %0 \n\t"\
+ "movd (%0), %%mm2 \n\t"\
+ "add %2, %0 \n\t"\
+ "movd (%0), %%mm3 \n\t"\
+ "add %2, %0 \n\t"\
+ "movd (%0), %%mm4 \n\t"\
+ "add %2, %0 \n\t"\
+ "punpcklbw %%mm7, %%mm0 \n\t"\
+ "punpcklbw %%mm7, %%mm1 \n\t"\
+ "punpcklbw %%mm7, %%mm2 \n\t"\
+ "punpcklbw %%mm7, %%mm3 \n\t"\
+ "punpcklbw %%mm7, %%mm4 \n\t"\
+ QPEL_H264V(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP)\
+ QPEL_H264V(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP)\
+ QPEL_H264V(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP)\
+ QPEL_H264V(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP)\
+ \
+ : "+a"(src), "+c"(dst)\
+ : "S"((long)srcStride), "D"((long)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\
+ : "memory"\
+ );\
+}\
+static av_noinline void OPNAME ## h264_qpel4_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
+ int h=4;\
+ int w=3;\
+ src -= 2*srcStride+2;\
+ while(w--){\
+ asm volatile(\
+ "pxor %%mm7, %%mm7 \n\t"\
+ "movd (%0), %%mm0 \n\t"\
+ "add %2, %0 \n\t"\
+ "movd (%0), %%mm1 \n\t"\
+ "add %2, %0 \n\t"\
+ "movd (%0), %%mm2 \n\t"\
+ "add %2, %0 \n\t"\
+ "movd (%0), %%mm3 \n\t"\
+ "add %2, %0 \n\t"\
+ "movd (%0), %%mm4 \n\t"\
+ "add %2, %0 \n\t"\
+ "punpcklbw %%mm7, %%mm0 \n\t"\
+ "punpcklbw %%mm7, %%mm1 \n\t"\
+ "punpcklbw %%mm7, %%mm2 \n\t"\
+ "punpcklbw %%mm7, %%mm3 \n\t"\
+ "punpcklbw %%mm7, %%mm4 \n\t"\
+ QPEL_H264HV(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, 0*8*3)\
+ QPEL_H264HV(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, 1*8*3)\
+ QPEL_H264HV(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, 2*8*3)\
+ QPEL_H264HV(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, 3*8*3)\
+ \
+ : "+a"(src)\
+ : "c"(tmp), "S"((long)srcStride), "m"(ff_pw_5)\
+ : "memory"\
+ );\
+ tmp += 4;\
+ src += 4 - 9*srcStride;\
+ }\
+ tmp -= 3*4;\
+ asm volatile(\
+ "movq %4, %%mm6 \n\t"\
+ "1: \n\t"\
+ "movq (%0), %%mm0 \n\t"\
+ "paddw 10(%0), %%mm0 \n\t"\
+ "movq 2(%0), %%mm1 \n\t"\
+ "paddw 8(%0), %%mm1 \n\t"\
+ "movq 4(%0), %%mm2 \n\t"\
+ "paddw 6(%0), %%mm2 \n\t"\
+ "psubw %%mm1, %%mm0 \n\t"/*a-b (abccba)*/\
+ "psraw $2, %%mm0 \n\t"/*(a-b)/4 */\
+ "psubw %%mm1, %%mm0 \n\t"/*(a-b)/4-b */\
+ "paddsw %%mm2, %%mm0 \n\t"\
+ "psraw $2, %%mm0 \n\t"/*((a-b)/4-b+c)/4 */\
+ "paddw %%mm6, %%mm2 \n\t"\
+ "paddw %%mm2, %%mm0 \n\t"/*(a-5*b+20*c)/16 +32 */\
+ "psraw $6, %%mm0 \n\t"\
+ "packuswb %%mm0, %%mm0 \n\t"\
+ OP(%%mm0, (%1),%%mm7, d)\
+ "add $24, %0 \n\t"\
+ "add %3, %1 \n\t"\
+ "decl %2 \n\t"\
+ " jnz 1b \n\t"\
+ : "+a"(tmp), "+c"(dst), "+m"(h)\
+ : "S"((long)dstStride), "m"(ff_pw_32)\
+ : "memory"\
+ );\
+}\
+\
+static av_noinline void OPNAME ## h264_qpel8_h_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ int h=8;\
+ asm volatile(\
+ "pxor %%mm7, %%mm7 \n\t"\
+ "movq %5, %%mm6 \n\t"\
+ "1: \n\t"\
+ "movq (%0), %%mm0 \n\t"\
+ "movq 1(%0), %%mm2 \n\t"\
+ "movq %%mm0, %%mm1 \n\t"\
+ "movq %%mm2, %%mm3 \n\t"\
+ "punpcklbw %%mm7, %%mm0 \n\t"\
+ "punpckhbw %%mm7, %%mm1 \n\t"\
+ "punpcklbw %%mm7, %%mm2 \n\t"\
+ "punpckhbw %%mm7, %%mm3 \n\t"\
+ "paddw %%mm2, %%mm0 \n\t"\
+ "paddw %%mm3, %%mm1 \n\t"\
+ "psllw $2, %%mm0 \n\t"\
+ "psllw $2, %%mm1 \n\t"\
+ "movq -1(%0), %%mm2 \n\t"\
+ "movq 2(%0), %%mm4 \n\t"\
+ "movq %%mm2, %%mm3 \n\t"\
+ "movq %%mm4, %%mm5 \n\t"\
+ "punpcklbw %%mm7, %%mm2 \n\t"\
+ "punpckhbw %%mm7, %%mm3 \n\t"\
+ "punpcklbw %%mm7, %%mm4 \n\t"\
+ "punpckhbw %%mm7, %%mm5 \n\t"\
+ "paddw %%mm4, %%mm2 \n\t"\
+ "paddw %%mm3, %%mm5 \n\t"\
+ "psubw %%mm2, %%mm0 \n\t"\
+ "psubw %%mm5, %%mm1 \n\t"\
+ "pmullw %%mm6, %%mm0 \n\t"\
+ "pmullw %%mm6, %%mm1 \n\t"\
+ "movd -2(%0), %%mm2 \n\t"\
+ "movd 7(%0), %%mm5 \n\t"\
+ "punpcklbw %%mm7, %%mm2 \n\t"\
+ "punpcklbw %%mm7, %%mm5 \n\t"\
+ "paddw %%mm3, %%mm2 \n\t"\
+ "paddw %%mm5, %%mm4 \n\t"\
+ "movq %6, %%mm5 \n\t"\
+ "paddw %%mm5, %%mm2 \n\t"\
+ "paddw %%mm5, %%mm4 \n\t"\
+ "paddw %%mm2, %%mm0 \n\t"\
+ "paddw %%mm4, %%mm1 \n\t"\
+ "psraw $5, %%mm0 \n\t"\
+ "psraw $5, %%mm1 \n\t"\
+ "packuswb %%mm1, %%mm0 \n\t"\
+ OP(%%mm0, (%1),%%mm5, q)\
+ "add %3, %0 \n\t"\
+ "add %4, %1 \n\t"\
+ "decl %2 \n\t"\
+ " jnz 1b \n\t"\
+ : "+a"(src), "+c"(dst), "+m"(h)\
+ : "d"((long)srcStride), "S"((long)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\
+ : "memory"\
+ );\
+}\
+\
+static av_noinline void OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride){\
+ int h=8;\
+ asm volatile(\
+ "pxor %%mm7, %%mm7 \n\t"\
+ "movq %0, %%mm6 \n\t"\
+ :: "m"(ff_pw_5)\
+ );\
+ do{\
+ asm volatile(\
+ "movq (%0), %%mm0 \n\t"\
+ "movq 1(%0), %%mm2 \n\t"\
+ "movq %%mm0, %%mm1 \n\t"\
+ "movq %%mm2, %%mm3 \n\t"\
+ "punpcklbw %%mm7, %%mm0 \n\t"\
+ "punpckhbw %%mm7, %%mm1 \n\t"\
+ "punpcklbw %%mm7, %%mm2 \n\t"\
+ "punpckhbw %%mm7, %%mm3 \n\t"\
+ "paddw %%mm2, %%mm0 \n\t"\
+ "paddw %%mm3, %%mm1 \n\t"\
+ "psllw $2, %%mm0 \n\t"\
+ "psllw $2, %%mm1 \n\t"\
+ "movq -1(%0), %%mm2 \n\t"\
+ "movq 2(%0), %%mm4 \n\t"\
+ "movq %%mm2, %%mm3 \n\t"\
+ "movq %%mm4, %%mm5 \n\t"\
+ "punpcklbw %%mm7, %%mm2 \n\t"\
+ "punpckhbw %%mm7, %%mm3 \n\t"\
+ "punpcklbw %%mm7, %%mm4 \n\t"\
+ "punpckhbw %%mm7, %%mm5 \n\t"\
+ "paddw %%mm4, %%mm2 \n\t"\
+ "paddw %%mm3, %%mm5 \n\t"\
+ "psubw %%mm2, %%mm0 \n\t"\
+ "psubw %%mm5, %%mm1 \n\t"\
+ "pmullw %%mm6, %%mm0 \n\t"\
+ "pmullw %%mm6, %%mm1 \n\t"\
+ "movd -2(%0), %%mm2 \n\t"\
+ "movd 7(%0), %%mm5 \n\t"\
+ "punpcklbw %%mm7, %%mm2 \n\t"\
+ "punpcklbw %%mm7, %%mm5 \n\t"\
+ "paddw %%mm3, %%mm2 \n\t"\
+ "paddw %%mm5, %%mm4 \n\t"\
+ "movq %5, %%mm5 \n\t"\
+ "paddw %%mm5, %%mm2 \n\t"\
+ "paddw %%mm5, %%mm4 \n\t"\
+ "paddw %%mm2, %%mm0 \n\t"\
+ "paddw %%mm4, %%mm1 \n\t"\
+ "psraw $5, %%mm0 \n\t"\
+ "psraw $5, %%mm1 \n\t"\
+ "movq (%2), %%mm4 \n\t"\
+ "packuswb %%mm1, %%mm0 \n\t"\
+ PAVGB" %%mm4, %%mm0 \n\t"\
+ OP(%%mm0, (%1),%%mm5, q)\
+ "add %4, %0 \n\t"\
+ "add %4, %1 \n\t"\
+ "add %3, %2 \n\t"\
+ : "+a"(src), "+c"(dst), "+d"(src2)\
+ : "D"((long)src2Stride), "S"((long)dstStride),\
+ "m"(ff_pw_16)\
+ : "memory"\
+ );\
+ }while(--h);\
+}\
+\
+static av_noinline void OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
+ int w= 2;\
+ src -= 2*srcStride;\
+ \
+ while(w--){\
+ asm volatile(\
+ "pxor %%mm7, %%mm7 \n\t"\
+ "movd (%0), %%mm0 \n\t"\
+ "add %2, %0 \n\t"\
+ "movd (%0), %%mm1 \n\t"\
+ "add %2, %0 \n\t"\
+ "movd (%0), %%mm2 \n\t"\
+ "add %2, %0 \n\t"\
+ "movd (%0), %%mm3 \n\t"\
+ "add %2, %0 \n\t"\
+ "movd (%0), %%mm4 \n\t"\
+ "add %2, %0 \n\t"\
+ "punpcklbw %%mm7, %%mm0 \n\t"\
+ "punpcklbw %%mm7, %%mm1 \n\t"\
+ "punpcklbw %%mm7, %%mm2 \n\t"\
+ "punpcklbw %%mm7, %%mm3 \n\t"\
+ "punpcklbw %%mm7, %%mm4 \n\t"\
+ QPEL_H264V(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP)\
+ QPEL_H264V(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP)\
+ QPEL_H264V(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP)\
+ QPEL_H264V(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP)\
+ QPEL_H264V(%%mm4, %%mm5, %%mm0, %%mm1, %%mm2, %%mm3, OP)\
+ QPEL_H264V(%%mm5, %%mm0, %%mm1, %%mm2, %%mm3, %%mm4, OP)\
+ QPEL_H264V(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP)\
+ QPEL_H264V(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP)\
+ \
+ : "+a"(src), "+c"(dst)\
+ : "S"((long)srcStride), "D"((long)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\
+ : "memory"\
+ );\
+ if(h==16){\
+ asm volatile(\
+ QPEL_H264V(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP)\
+ QPEL_H264V(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP)\
+ QPEL_H264V(%%mm4, %%mm5, %%mm0, %%mm1, %%mm2, %%mm3, OP)\
+ QPEL_H264V(%%mm5, %%mm0, %%mm1, %%mm2, %%mm3, %%mm4, OP)\
+ QPEL_H264V(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP)\
+ QPEL_H264V(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP)\
+ QPEL_H264V(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP)\
+ QPEL_H264V(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP)\
+ \
+ : "+a"(src), "+c"(dst)\
+ : "S"((long)srcStride), "D"((long)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\
+ : "memory"\
+ );\
+ }\
+ src += 4-(h+5)*srcStride;\
+ dst += 4-h*dstStride;\
+ }\
+}\
+static av_noinline void OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride, int size){\
+ int h = size;\
+ int w = (size+8)>>2;\
+ src -= 2*srcStride+2;\
+ while(w--){\
+ asm volatile(\
+ "pxor %%mm7, %%mm7 \n\t"\
+ "movd (%0), %%mm0 \n\t"\
+ "add %2, %0 \n\t"\
+ "movd (%0), %%mm1 \n\t"\
+ "add %2, %0 \n\t"\
+ "movd (%0), %%mm2 \n\t"\
+ "add %2, %0 \n\t"\
+ "movd (%0), %%mm3 \n\t"\
+ "add %2, %0 \n\t"\
+ "movd (%0), %%mm4 \n\t"\
+ "add %2, %0 \n\t"\
+ "punpcklbw %%mm7, %%mm0 \n\t"\
+ "punpcklbw %%mm7, %%mm1 \n\t"\
+ "punpcklbw %%mm7, %%mm2 \n\t"\
+ "punpcklbw %%mm7, %%mm3 \n\t"\
+ "punpcklbw %%mm7, %%mm4 \n\t"\
+ QPEL_H264HV(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, 0*48)\
+ QPEL_H264HV(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, 1*48)\
+ QPEL_H264HV(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, 2*48)\
+ QPEL_H264HV(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, 3*48)\
+ QPEL_H264HV(%%mm4, %%mm5, %%mm0, %%mm1, %%mm2, %%mm3, 4*48)\
+ QPEL_H264HV(%%mm5, %%mm0, %%mm1, %%mm2, %%mm3, %%mm4, 5*48)\
+ QPEL_H264HV(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, 6*48)\
+ QPEL_H264HV(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, 7*48)\
+ : "+a"(src)\
+ : "c"(tmp), "S"((long)srcStride), "m"(ff_pw_5)\
+ : "memory"\
+ );\
+ if(size==16){\
+ asm volatile(\
+ QPEL_H264HV(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, 8*48)\
+ QPEL_H264HV(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, 9*48)\
+ QPEL_H264HV(%%mm4, %%mm5, %%mm0, %%mm1, %%mm2, %%mm3, 10*48)\
+ QPEL_H264HV(%%mm5, %%mm0, %%mm1, %%mm2, %%mm3, %%mm4, 11*48)\
+ QPEL_H264HV(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, 12*48)\
+ QPEL_H264HV(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, 13*48)\
+ QPEL_H264HV(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, 14*48)\
+ QPEL_H264HV(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, 15*48)\
+ : "+a"(src)\
+ : "c"(tmp), "S"((long)srcStride), "m"(ff_pw_5)\
+ : "memory"\
+ );\
+ }\
+ tmp += 4;\
+ src += 4 - (size+5)*srcStride;\
+ }\
+ tmp -= size+8;\
+ w = size>>4;\
+ do{\
+ h = size;\
+ asm volatile(\
+ "movq %4, %%mm6 \n\t"\
+ "1: \n\t"\
+ "movq (%0), %%mm0 \n\t"\
+ "movq 8(%0), %%mm3 \n\t"\
+ "movq 2(%0), %%mm1 \n\t"\
+ "movq 10(%0), %%mm4 \n\t"\
+ "paddw %%mm4, %%mm0 \n\t"\
+ "paddw %%mm3, %%mm1 \n\t"\
+ "paddw 18(%0), %%mm3 \n\t"\
+ "paddw 16(%0), %%mm4 \n\t"\
+ "movq 4(%0), %%mm2 \n\t"\
+ "movq 12(%0), %%mm5 \n\t"\
+ "paddw 6(%0), %%mm2 \n\t"\
+ "paddw 14(%0), %%mm5 \n\t"\
+ "psubw %%mm1, %%mm0 \n\t"\
+ "psubw %%mm4, %%mm3 \n\t"\
+ "psraw $2, %%mm0 \n\t"\
+ "psraw $2, %%mm3 \n\t"\
+ "psubw %%mm1, %%mm0 \n\t"\
+ "psubw %%mm4, %%mm3 \n\t"\
+ "paddsw %%mm2, %%mm0 \n\t"\
+ "paddsw %%mm5, %%mm3 \n\t"\
+ "psraw $2, %%mm0 \n\t"\
+ "psraw $2, %%mm3 \n\t"\
+ "paddw %%mm6, %%mm2 \n\t"\
+ "paddw %%mm6, %%mm5 \n\t"\
+ "paddw %%mm2, %%mm0 \n\t"\
+ "paddw %%mm5, %%mm3 \n\t"\
+ "psraw $6, %%mm0 \n\t"\
+ "psraw $6, %%mm3 \n\t"\
+ "packuswb %%mm3, %%mm0 \n\t"\
+ OP(%%mm0, (%1),%%mm7, q)\
+ "add $48, %0 \n\t"\
+ "add %3, %1 \n\t"\
+ "decl %2 \n\t"\
+ " jnz 1b \n\t"\
+ : "+a"(tmp), "+c"(dst), "+m"(h)\
+ : "S"((long)dstStride), "m"(ff_pw_32)\
+ : "memory"\
+ );\
+ tmp += 8 - size*24;\
+ dst += 8 - size*dstStride;\
+ }while(w--);\
+}\
+\
+static void OPNAME ## h264_qpel8_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst , src , dstStride, srcStride, 8);\
+}\
+static av_noinline void OPNAME ## h264_qpel16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst , src , dstStride, srcStride, 16);\
+ OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride, 16);\
+}\
+\
+static av_noinline void OPNAME ## h264_qpel16_h_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst , src , dstStride, srcStride);\
+ OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride);\
+ src += 8*srcStride;\
+ dst += 8*dstStride;\
+ OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst , src , dstStride, srcStride);\
+ OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride);\
+}\
+\
+static av_noinline void OPNAME ## h264_qpel16_h_lowpass_l2_ ## MMX(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride){\
+ OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst , src , src2 , dstStride, src2Stride);\
+ OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst+8, src+8, src2+8, dstStride, src2Stride);\
+ src += 8*dstStride;\
+ dst += 8*dstStride;\
+ src2 += 8*src2Stride;\
+ OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst , src , src2 , dstStride, src2Stride);\
+ OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst+8, src+8, src2+8, dstStride, src2Stride);\
+}\
+\
+static void OPNAME ## h264_qpel8_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
+ OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(dst , tmp , src , dstStride, tmpStride, srcStride, 8);\
+}\
+\
+static void OPNAME ## h264_qpel16_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
+ OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(dst , tmp , src , dstStride, tmpStride, srcStride, 16);\
+}\
+\
+static av_noinline void OPNAME ## pixels4_l2_shift5_ ## MMX(uint8_t *dst, int16_t *src16, uint8_t *src8, int dstStride, int src8Stride, int h)\
+{\
+ asm volatile(\
+ "movq %5, %%mm6 \n\t"\
+ "movq (%1), %%mm0 \n\t"\
+ "movq 24(%1), %%mm1 \n\t"\
+ "paddw %%mm6, %%mm0 \n\t"\
+ "paddw %%mm6, %%mm1 \n\t"\
+ "psraw $5, %%mm0 \n\t"\
+ "psraw $5, %%mm1 \n\t"\
+ "packuswb %%mm0, %%mm0 \n\t"\
+ "packuswb %%mm1, %%mm1 \n\t"\
+ PAVGB" (%0), %%mm0 \n\t"\
+ PAVGB" (%0,%3), %%mm1 \n\t"\
+ OP(%%mm0, (%2), %%mm4, d)\
+ OP(%%mm1, (%2,%4), %%mm5, d)\
+ "lea (%0,%3,2), %0 \n\t"\
+ "lea (%2,%4,2), %2 \n\t"\
+ "movq 48(%1), %%mm0 \n\t"\
+ "movq 72(%1), %%mm1 \n\t"\
+ "paddw %%mm6, %%mm0 \n\t"\
+ "paddw %%mm6, %%mm1 \n\t"\
+ "psraw $5, %%mm0 \n\t"\
+ "psraw $5, %%mm1 \n\t"\
+ "packuswb %%mm0, %%mm0 \n\t"\
+ "packuswb %%mm1, %%mm1 \n\t"\
+ PAVGB" (%0), %%mm0 \n\t"\
+ PAVGB" (%0,%3), %%mm1 \n\t"\
+ OP(%%mm0, (%2), %%mm4, d)\
+ OP(%%mm1, (%2,%4), %%mm5, d)\
+ :"+a"(src8), "+c"(src16), "+d"(dst)\
+ :"S"((long)src8Stride), "D"((long)dstStride), "m"(ff_pw_16)\
+ :"memory");\
+}\
+static av_noinline void OPNAME ## pixels8_l2_shift5_ ## MMX(uint8_t *dst, int16_t *src16, uint8_t *src8, int dstStride, int src8Stride, int h)\
+{\
+ asm volatile(\
+ "movq %0, %%mm6 \n\t"\
+ ::"m"(ff_pw_16)\
+ );\
+ while(h--){\
+ asm volatile(\
+ "movq (%1), %%mm0 \n\t"\
+ "movq 8(%1), %%mm1 \n\t"\
+ "paddw %%mm6, %%mm0 \n\t"\
+ "paddw %%mm6, %%mm1 \n\t"\
+ "psraw $5, %%mm0 \n\t"\
+ "psraw $5, %%mm1 \n\t"\
+ "packuswb %%mm1, %%mm0 \n\t"\
+ PAVGB" (%0), %%mm0 \n\t"\
+ OP(%%mm0, (%2), %%mm5, q)\
+ ::"a"(src8), "c"(src16), "d"(dst)\
+ :"memory");\
+ src8 += src8Stride;\
+ src16 += 24;\
+ dst += dstStride;\
+ }\
+}\
+static void OPNAME ## pixels16_l2_shift5_ ## MMX(uint8_t *dst, int16_t *src16, uint8_t *src8, int dstStride, int src8Stride, int h)\
+{\
+ OPNAME ## pixels8_l2_shift5_ ## MMX(dst , src16 , src8 , dstStride, src8Stride, h);\
+ OPNAME ## pixels8_l2_shift5_ ## MMX(dst+8, src16+8, src8+8, dstStride, src8Stride, h);\
+}\
+
+
+#define H264_MC(OPNAME, SIZE, MMX) \
+static void OPNAME ## h264_qpel ## SIZE ## _mc00_ ## MMX (uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## pixels ## SIZE ## _mmx(dst, src, stride, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, src, stride, stride);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc20_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## h264_qpel ## SIZE ## _h_lowpass_ ## MMX(dst, src, stride, stride);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc30_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, src+1, stride, stride);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t temp[SIZE*SIZE/8];\
+ uint8_t * const half= (uint8_t*)temp;\
+ put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(half, src, SIZE, stride);\
+ OPNAME ## pixels ## SIZE ## _l2_ ## MMX(dst, src, half, stride, stride, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## h264_qpel ## SIZE ## _v_lowpass_ ## MMX(dst, src, stride, stride);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t temp[SIZE*SIZE/8];\
+ uint8_t * const half= (uint8_t*)temp;\
+ put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(half, src, SIZE, stride);\
+ OPNAME ## pixels ## SIZE ## _l2_ ## MMX(dst, src+stride, half, stride, stride, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc11_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t temp[SIZE*SIZE/8];\
+ uint8_t * const halfV= (uint8_t*)temp;\
+ put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(halfV, src, SIZE, stride);\
+ OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, halfV, stride, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc31_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t temp[SIZE*SIZE/8];\
+ uint8_t * const halfV= (uint8_t*)temp;\
+ put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(halfV, src+1, SIZE, stride);\
+ OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, halfV, stride, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc13_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t temp[SIZE*SIZE/8];\
+ uint8_t * const halfV= (uint8_t*)temp;\
+ put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(halfV, src, SIZE, stride);\
+ OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src+stride, halfV, stride, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc33_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t temp[SIZE*SIZE/8];\
+ uint8_t * const halfV= (uint8_t*)temp;\
+ put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(halfV, src+1, SIZE, stride);\
+ OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src+stride, halfV, stride, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc22_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t temp[SIZE*(SIZE<8?12:24)/4];\
+ int16_t * const tmp= (int16_t*)temp;\
+ OPNAME ## h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(dst, tmp, src, stride, SIZE, stride);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc21_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t temp[SIZE*(SIZE<8?12:24)/4 + SIZE*SIZE/8];\
+ uint8_t * const halfHV= (uint8_t*)temp;\
+ int16_t * const tmp= ((int16_t*)temp) + SIZE*SIZE/2;\
+ assert((int)temp & 7 == 0);\
+ put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, tmp, src, SIZE, SIZE, stride);\
+ OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, halfHV, stride, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t temp[SIZE*(SIZE<8?12:24)/4 + SIZE*SIZE/8];\
+ uint8_t * const halfHV= (uint8_t*)temp;\
+ int16_t * const tmp= ((int16_t*)temp) + SIZE*SIZE/2;\
+ assert((int)temp & 7 == 0);\
+ put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, tmp, src, SIZE, SIZE, stride);\
+ OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src+stride, halfHV, stride, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc12_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t temp[SIZE*(SIZE<8?12:24)/4 + SIZE*SIZE/8];\
+ int16_t * const halfV= ((int16_t*)temp) + SIZE*SIZE/2;\
+ uint8_t * const halfHV= ((uint8_t*)temp);\
+ assert((int)temp & 7 == 0);\
+ put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, halfV, src, SIZE, SIZE, stride);\
+ OPNAME ## pixels ## SIZE ## _l2_shift5_ ## MMX(dst, halfV+2, halfHV, stride, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
+ uint64_t temp[SIZE*(SIZE<8?12:24)/4 + SIZE*SIZE/8];\
+ int16_t * const halfV= ((int16_t*)temp) + SIZE*SIZE/2;\
+ uint8_t * const halfHV= ((uint8_t*)temp);\
+ assert((int)temp & 7 == 0);\
+ put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, halfV, src, SIZE, SIZE, stride);\
+ OPNAME ## pixels ## SIZE ## _l2_shift5_ ## MMX(dst, halfV+3, halfHV, stride, SIZE, SIZE);\
+}\
+
+
+#define AVG_3DNOW_OP(a,b,temp, size) \
+"mov" #size " " #b ", " #temp " \n\t"\
+"pavgusb " #temp ", " #a " \n\t"\
+"mov" #size " " #a ", " #b " \n\t"
+#define AVG_MMX2_OP(a,b,temp, size) \
+"mov" #size " " #b ", " #temp " \n\t"\
+"pavgb " #temp ", " #a " \n\t"\
+"mov" #size " " #a ", " #b " \n\t"
+
+#define PAVGB "pavgusb"
+QPEL_H264(put_, PUT_OP, 3dnow)
+QPEL_H264(avg_, AVG_3DNOW_OP, 3dnow)
+#undef PAVGB
+#define PAVGB "pavgb"
+QPEL_H264(put_, PUT_OP, mmx2)
+QPEL_H264(avg_, AVG_MMX2_OP, mmx2)
+#undef PAVGB
+
+H264_MC(put_, 4, 3dnow)
+H264_MC(put_, 8, 3dnow)
+H264_MC(put_, 16,3dnow)
+H264_MC(avg_, 4, 3dnow)
+H264_MC(avg_, 8, 3dnow)
+H264_MC(avg_, 16,3dnow)
+H264_MC(put_, 4, mmx2)
+H264_MC(put_, 8, mmx2)
+H264_MC(put_, 16,mmx2)
+H264_MC(avg_, 4, mmx2)
+H264_MC(avg_, 8, mmx2)
+H264_MC(avg_, 16,mmx2)
+
+
+#define H264_CHROMA_OP(S,D)
+#define H264_CHROMA_OP4(S,D,T)
+#define H264_CHROMA_MC8_TMPL put_h264_chroma_mc8_mmx
+#define H264_CHROMA_MC4_TMPL put_h264_chroma_mc4_mmx
+#define H264_CHROMA_MC2_TMPL put_h264_chroma_mc2_mmx2
+#define H264_CHROMA_MC8_MV0 put_pixels8_mmx
+#include "dsputil_h264_template_mmx.c"
+#undef H264_CHROMA_OP
+#undef H264_CHROMA_OP4
+#undef H264_CHROMA_MC8_TMPL
+#undef H264_CHROMA_MC4_TMPL
+#undef H264_CHROMA_MC2_TMPL
+#undef H264_CHROMA_MC8_MV0
+
+#define H264_CHROMA_OP(S,D) "pavgb " #S ", " #D " \n\t"
+#define H264_CHROMA_OP4(S,D,T) "movd " #S ", " #T " \n\t"\
+ "pavgb " #T ", " #D " \n\t"
+#define H264_CHROMA_MC8_TMPL avg_h264_chroma_mc8_mmx2
+#define H264_CHROMA_MC4_TMPL avg_h264_chroma_mc4_mmx2
+#define H264_CHROMA_MC2_TMPL avg_h264_chroma_mc2_mmx2
+#define H264_CHROMA_MC8_MV0 avg_pixels8_mmx2
+#include "dsputil_h264_template_mmx.c"
+#undef H264_CHROMA_OP
+#undef H264_CHROMA_OP4
+#undef H264_CHROMA_MC8_TMPL
+#undef H264_CHROMA_MC4_TMPL
+#undef H264_CHROMA_MC2_TMPL
+#undef H264_CHROMA_MC8_MV0
+
+#define H264_CHROMA_OP(S,D) "pavgusb " #S ", " #D " \n\t"
+#define H264_CHROMA_OP4(S,D,T) "movd " #S ", " #T " \n\t"\
+ "pavgusb " #T ", " #D " \n\t"
+#define H264_CHROMA_MC8_TMPL avg_h264_chroma_mc8_3dnow
+#define H264_CHROMA_MC4_TMPL avg_h264_chroma_mc4_3dnow
+#define H264_CHROMA_MC8_MV0 avg_pixels8_3dnow
+#include "dsputil_h264_template_mmx.c"
+#undef H264_CHROMA_OP
+#undef H264_CHROMA_OP4
+#undef H264_CHROMA_MC8_TMPL
+#undef H264_CHROMA_MC4_TMPL
+#undef H264_CHROMA_MC8_MV0
+
+/***********************************/
+/* weighted prediction */
+
+static inline void ff_h264_weight_WxH_mmx2(uint8_t *dst, int stride, int log2_denom, int weight, int offset, int w, int h)
+{
+ int x, y;
+ offset <<= log2_denom;
+ offset += (1 << log2_denom) >> 1;
+ asm volatile(
+ "movd %0, %%mm4 \n\t"
+ "movd %1, %%mm5 \n\t"
+ "movd %2, %%mm6 \n\t"
+ "pshufw $0, %%mm4, %%mm4 \n\t"
+ "pshufw $0, %%mm5, %%mm5 \n\t"
+ "pxor %%mm7, %%mm7 \n\t"
+ :: "g"(weight), "g"(offset), "g"(log2_denom)
+ );
+ for(y=0; y<h; y+=2){
+ for(x=0; x<w; x+=4){
+ asm volatile(
+ "movd %0, %%mm0 \n\t"
+ "movd %1, %%mm1 \n\t"
+ "punpcklbw %%mm7, %%mm0 \n\t"
+ "punpcklbw %%mm7, %%mm1 \n\t"
+ "pmullw %%mm4, %%mm0 \n\t"
+ "pmullw %%mm4, %%mm1 \n\t"
+ "paddsw %%mm5, %%mm0 \n\t"
+ "paddsw %%mm5, %%mm1 \n\t"
+ "psraw %%mm6, %%mm0 \n\t"
+ "psraw %%mm6, %%mm1 \n\t"
+ "packuswb %%mm7, %%mm0 \n\t"
+ "packuswb %%mm7, %%mm1 \n\t"
+ "movd %%mm0, %0 \n\t"
+ "movd %%mm1, %1 \n\t"
+ : "+m"(*(uint32_t*)(dst+x)),
+ "+m"(*(uint32_t*)(dst+x+stride))
+ );
+ }
+ dst += 2*stride;
+ }
+}
+
+static inline void ff_h264_biweight_WxH_mmx2(uint8_t *dst, uint8_t *src, int stride, int log2_denom, int weightd, int weights, int offset, int w, int h)
+{
+ int x, y;
+ offset = ((offset + 1) | 1) << log2_denom;
+ asm volatile(
+ "movd %0, %%mm3 \n\t"
+ "movd %1, %%mm4 \n\t"
+ "movd %2, %%mm5 \n\t"
+ "movd %3, %%mm6 \n\t"
+ "pshufw $0, %%mm3, %%mm3 \n\t"
+ "pshufw $0, %%mm4, %%mm4 \n\t"
+ "pshufw $0, %%mm5, %%mm5 \n\t"
+ "pxor %%mm7, %%mm7 \n\t"
+ :: "g"(weightd), "g"(weights), "g"(offset), "g"(log2_denom+1)
+ );
+ for(y=0; y<h; y++){
+ for(x=0; x<w; x+=4){
+ asm volatile(
+ "movd %0, %%mm0 \n\t"
+ "movd %1, %%mm1 \n\t"
+ "punpcklbw %%mm7, %%mm0 \n\t"
+ "punpcklbw %%mm7, %%mm1 \n\t"
+ "pmullw %%mm3, %%mm0 \n\t"
+ "pmullw %%mm4, %%mm1 \n\t"
+ "paddsw %%mm1, %%mm0 \n\t"
+ "paddsw %%mm5, %%mm0 \n\t"
+ "psraw %%mm6, %%mm0 \n\t"
+ "packuswb %%mm0, %%mm0 \n\t"
+ "movd %%mm0, %0 \n\t"
+ : "+m"(*(uint32_t*)(dst+x))
+ : "m"(*(uint32_t*)(src+x))
+ );
+ }
+ src += stride;
+ dst += stride;
+ }
+}
+
+#define H264_WEIGHT(W,H) \
+static void ff_h264_biweight_ ## W ## x ## H ## _mmx2(uint8_t *dst, uint8_t *src, int stride, int log2_denom, int weightd, int weights, int offset){ \
+ ff_h264_biweight_WxH_mmx2(dst, src, stride, log2_denom, weightd, weights, offset, W, H); \
+} \
+static void ff_h264_weight_ ## W ## x ## H ## _mmx2(uint8_t *dst, int stride, int log2_denom, int weight, int offset){ \
+ ff_h264_weight_WxH_mmx2(dst, stride, log2_denom, weight, offset, W, H); \
+}
+
+H264_WEIGHT(16,16)
+H264_WEIGHT(16, 8)
+H264_WEIGHT( 8,16)
+H264_WEIGHT( 8, 8)
+H264_WEIGHT( 8, 4)
+H264_WEIGHT( 4, 8)
+H264_WEIGHT( 4, 4)
+H264_WEIGHT( 4, 2)
+
diff --git a/src/libffmpeg/libavcodec/i386/idct_mmx.c b/contrib/ffmpeg/libavcodec/i386/idct_mmx.c
index 4c548fdce..4c548fdce 100644
--- a/src/libffmpeg/libavcodec/i386/idct_mmx.c
+++ b/contrib/ffmpeg/libavcodec/i386/idct_mmx.c
diff --git a/contrib/ffmpeg/libavcodec/i386/idct_mmx_xvid.c b/contrib/ffmpeg/libavcodec/i386/idct_mmx_xvid.c
new file mode 100644
index 000000000..85cfbc9cd
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/i386/idct_mmx_xvid.c
@@ -0,0 +1,535 @@
+///****************************************************************************
+// *
+// * XVID MPEG-4 VIDEO CODEC
+// * - MMX and XMM forward discrete cosine transform -
+// *
+// * Copyright(C) 2001 Peter Ross <pross@xvid.org>
+// *
+// * This file is part of FFmpeg.
+// *
+// * FFmpeg is free software; you can redistribute it and/or
+// * modify it under the terms of the GNU Lesser General Public
+// * License as published by the Free Software Foundation; either
+// * version 2.1 of the License, or (at your option) any later version.
+// *
+// * FFmpeg is distributed in the hope that it will be useful,
+// * but WITHOUT ANY WARRANTY; without even the implied warranty of
+// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// * Lesser General Public License for more details.
+// *
+// * You should have received a copy of the GNU Lesser General Public License
+// * along with FFmpeg; if not, write to the Free Software Foundation,
+// * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+// *
+// * $Id: idct_mmx_xvid.c 6577 2006-10-07 15:30:46Z diego $
+// *
+// ***************************************************************************/
+
+// ****************************************************************************
+//
+// Originally provided by Intel at AP-922
+// http://developer.intel.com/vtune/cbts/strmsimd/922down.htm
+// (See more app notes at http://developer.intel.com/vtune/cbts/strmsimd/appnotes.htm)
+// but in a limited edition.
+// New macro implements a column part for precise iDCT
+// The routine precision now satisfies IEEE standard 1180-1990.
+//
+// Copyright(C) 2000-2001 Peter Gubanov <peter@elecard.net.ru>
+// Rounding trick Copyright(C) 2000 Michel Lespinasse <walken@zoy.org>
+//
+// http://www.elecard.com/peter/idct.html
+// http://www.linuxvideo.org/mpeg2dec/
+//
+// ***************************************************************************/
+//
+// These examples contain code fragments for first stage iDCT 8x8
+// (for rows) and first stage DCT 8x8 (for columns)
+//
+
+// conversion to gcc syntax by michael niedermayer
+
+
+#include <inttypes.h>
+#include "../avcodec.h"
+
+//=============================================================================
+// Macros and other preprocessor constants
+//=============================================================================
+
+#define BITS_INV_ACC 5 // 4 or 5 for IEEE
+#define SHIFT_INV_ROW (16 - BITS_INV_ACC) //11
+#define SHIFT_INV_COL (1 + BITS_INV_ACC) //6
+#define RND_INV_ROW (1024 * (6 - BITS_INV_ACC))
+#define RND_INV_COL (16 * (BITS_INV_ACC - 3))
+#define RND_INV_CORR (RND_INV_COL - 1)
+
+#define BITS_FRW_ACC 3 // 2 or 3 for accuracy
+#define SHIFT_FRW_COL BITS_FRW_ACC
+#define SHIFT_FRW_ROW (BITS_FRW_ACC + 17)
+#define RND_FRW_ROW (262144*(BITS_FRW_ACC - 1))
+
+
+//-----------------------------------------------------------------------------
+// Various memory constants (trigonometric values or rounding values)
+//-----------------------------------------------------------------------------
+
+
+static const int16_t tg_1_16[4*4] attribute_used __attribute__ ((aligned(8))) = {
+ 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
+
+static const int32_t rounder_0[2*8] attribute_used __attribute__ ((aligned(8))) = {
+ 65536,65536,
+ 3597,3597,
+ 2260,2260,
+ 1203,1203,
+ 0,0,
+ 120,120,
+ 512,512,
+ 512,512};
+
+//-----------------------------------------------------------------------------
+//
+// The first stage iDCT 8x8 - inverse DCTs of rows
+//
+//-----------------------------------------------------------------------------
+// The 8-point inverse DCT direct algorithm
+//-----------------------------------------------------------------------------
+//
+// static const short w[32] = {
+// FIX(cos_4_16), FIX(cos_2_16), FIX(cos_4_16), FIX(cos_6_16),
+// FIX(cos_4_16), FIX(cos_6_16), -FIX(cos_4_16), -FIX(cos_2_16),
+// FIX(cos_4_16), -FIX(cos_6_16), -FIX(cos_4_16), FIX(cos_2_16),
+// FIX(cos_4_16), -FIX(cos_2_16), FIX(cos_4_16), -FIX(cos_6_16),
+// FIX(cos_1_16), FIX(cos_3_16), FIX(cos_5_16), FIX(cos_7_16),
+// FIX(cos_3_16), -FIX(cos_7_16), -FIX(cos_1_16), -FIX(cos_5_16),
+// FIX(cos_5_16), -FIX(cos_1_16), FIX(cos_7_16), FIX(cos_3_16),
+// FIX(cos_7_16), -FIX(cos_5_16), FIX(cos_3_16), -FIX(cos_1_16) };
+//
+// #define DCT_8_INV_ROW(x, y)
+// {
+// int a0, a1, a2, a3, b0, b1, b2, b3;
+//
+// a0 =x[0]*w[0]+x[2]*w[1]+x[4]*w[2]+x[6]*w[3];
+// a1 =x[0]*w[4]+x[2]*w[5]+x[4]*w[6]+x[6]*w[7];
+// a2 = x[0] * w[ 8] + x[2] * w[ 9] + x[4] * w[10] + x[6] * w[11];
+// a3 = x[0] * w[12] + x[2] * w[13] + x[4] * w[14] + x[6] * w[15];
+// b0 = x[1] * w[16] + x[3] * w[17] + x[5] * w[18] + x[7] * w[19];
+// b1 = x[1] * w[20] + x[3] * w[21] + x[5] * w[22] + x[7] * w[23];
+// b2 = x[1] * w[24] + x[3] * w[25] + x[5] * w[26] + x[7] * w[27];
+// b3 = x[1] * w[28] + x[3] * w[29] + x[5] * w[30] + x[7] * w[31];
+//
+// y[0] = SHIFT_ROUND ( a0 + b0 );
+// y[1] = SHIFT_ROUND ( a1 + b1 );
+// y[2] = SHIFT_ROUND ( a2 + b2 );
+// y[3] = SHIFT_ROUND ( a3 + b3 );
+// y[4] = SHIFT_ROUND ( a3 - b3 );
+// y[5] = SHIFT_ROUND ( a2 - b2 );
+// y[6] = SHIFT_ROUND ( a1 - b1 );
+// y[7] = SHIFT_ROUND ( a0 - b0 );
+// }
+//
+//-----------------------------------------------------------------------------
+//
+// In this implementation the outputs of the iDCT-1D are multiplied
+// for rows 0,4 - by cos_4_16,
+// for rows 1,7 - by cos_1_16,
+// for rows 2,6 - by cos_2_16,
+// for rows 3,5 - by cos_3_16
+// and are shifted to the left for better accuracy
+//
+// For the constants used,
+// FIX(float_const) = (short) (float_const * (1<<15) + 0.5)
+//
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+// Tables for mmx processors
+//-----------------------------------------------------------------------------
+
+// Table for rows 0,4 - constants are multiplied by cos_4_16
+static const int16_t tab_i_04_mmx[32*4] attribute_used __attribute__ ((aligned(8))) = {
+ 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
+ -8867,21407,-21407,-8867, // w15 w13 w11 w09
+ 22725,12873,19266,-22725, // w22 w20 w18 w16
+ 19266,4520,-4520,-12873, // w23 w21 w19 w17
+ 12873,4520,4520,19266, // w30 w28 w26 w24
+ -22725,19266,-12873,-22725, // w31 w29 w27 w25
+// Table for rows 1,7 - constants are multiplied by cos_1_16
+ 22725,22725,22725,-22725, // movq-> w06 w04 w02 w00
+ 29692,12299,12299,-29692, // w07 w05 w03 w01
+ 22725,-22725,22725,22725, // w14 w12 w10 w08
+ -12299,29692,-29692,-12299, // w15 w13 w11 w09
+ 31521,17855,26722,-31521, // w22 w20 w18 w16
+ 26722,6270,-6270,-17855, // w23 w21 w19 w17
+ 17855,6270,6270,26722, // w30 w28 w26 w24
+ -31521,26722,-17855,-31521, // w31 w29 w27 w25
+// Table for rows 2,6 - constants are multiplied by cos_2_16
+ 21407,21407,21407,-21407, // movq-> w06 w04 w02 w00
+ 27969,11585,11585,-27969, // w07 w05 w03 w01
+ 21407,-21407,21407,21407, // w14 w12 w10 w08
+ -11585,27969,-27969,-11585, // w15 w13 w11 w09
+ 29692,16819,25172,-29692, // w22 w20 w18 w16
+ 25172,5906,-5906,-16819, // w23 w21 w19 w17
+ 16819,5906,5906,25172, // w30 w28 w26 w24
+ -29692,25172,-16819,-29692, // w31 w29 w27 w25
+// Table for rows 3,5 - constants are multiplied by cos_3_16
+ 19266,19266,19266,-19266, // movq-> w06 w04 w02 w00
+ 25172,10426,10426,-25172, // w07 w05 w03 w01
+ 19266,-19266,19266,19266, // w14 w12 w10 w08
+ -10426,25172,-25172,-10426, // w15 w13 w11 w09
+ 26722,15137,22654,-26722, // w22 w20 w18 w16
+ 22654,5315,-5315,-15137, // w23 w21 w19 w17
+ 15137,5315,5315,22654, // w30 w28 w26 w24
+ -26722,22654,-15137,-26722, // w31 w29 w27 w25
+};
+//-----------------------------------------------------------------------------
+// Tables for xmm processors
+//-----------------------------------------------------------------------------
+
+// %3 for rows 0,4 - constants are multiplied by cos_4_16
+static const int16_t tab_i_04_xmm[32*4] attribute_used __attribute__ ((aligned(8))) = {
+ 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
+ -16384,21407,16384,-8867, // w15 w14 w11 w10
+ 22725,19266,19266,-4520, // w21 w20 w17 w16
+ 12873,4520,-22725,-12873, // w23 w22 w19 w18
+ 12873,-22725,4520,-12873, // w29 w28 w25 w24
+ 4520,19266,19266,-22725, // w31 w30 w27 w26
+// %3 for rows 1,7 - constants are multiplied by cos_1_16
+ 22725,29692,22725,12299, // movq-> w05 w04 w01 w00
+ 22725,12299,-22725,-29692, // w07 w06 w03 w02
+ 22725,-12299,22725,-29692, // w13 w12 w09 w08
+ -22725,29692,22725,-12299, // w15 w14 w11 w10
+ 31521,26722,26722,-6270, // w21 w20 w17 w16
+ 17855,6270,-31521,-17855, // w23 w22 w19 w18
+ 17855,-31521,6270,-17855, // w29 w28 w25 w24
+ 6270,26722,26722,-31521, // w31 w30 w27 w26
+// %3 for rows 2,6 - constants are multiplied by cos_2_16
+ 21407,27969,21407,11585, // movq-> w05 w04 w01 w00
+ 21407,11585,-21407,-27969, // w07 w06 w03 w02
+ 21407,-11585,21407,-27969, // w13 w12 w09 w08
+ -21407,27969,21407,-11585, // w15 w14 w11 w10
+ 29692,25172,25172,-5906, // w21 w20 w17 w16
+ 16819,5906,-29692,-16819, // w23 w22 w19 w18
+ 16819,-29692,5906,-16819, // w29 w28 w25 w24
+ 5906,25172,25172,-29692, // w31 w30 w27 w26
+// %3 for rows 3,5 - constants are multiplied by cos_3_16
+ 19266,25172,19266,10426, // movq-> w05 w04 w01 w00
+ 19266,10426,-19266,-25172, // w07 w06 w03 w02
+ 19266,-10426,19266,-25172, // w13 w12 w09 w08
+ -19266,25172,19266,-10426, // w15 w14 w11 w10
+ 26722,22654,22654,-5315, // w21 w20 w17 w16
+ 15137,5315,-26722,-15137, // w23 w22 w19 w18
+ 15137,-26722,5315,-15137, // w29 w28 w25 w24
+ 5315,22654,22654,-26722, // w31 w30 w27 w26
+};
+//=============================================================================
+// Helper macros for the code
+//=============================================================================
+
+//-----------------------------------------------------------------------------
+// DCT_8_INV_ROW_MMX( INP, OUT, TABLE, ROUNDER
+//-----------------------------------------------------------------------------
+
+#define DCT_8_INV_ROW_MMX(A1,A2,A3,A4)\
+ "movq " #A1 ",%%mm0 \n\t"/* 0 ; x3 x2 x1 x0*/\
+ "movq 8+" #A1 ",%%mm1 \n\t"/* 1 ; x7 x6 x5 x4*/\
+ "movq %%mm0,%%mm2 \n\t"/* 2 ; x3 x2 x1 x0*/\
+ "movq " #A3 ",%%mm3 \n\t"/* 3 ; w06 w04 w02 w00*/\
+ "punpcklwd %%mm1,%%mm0 \n\t"/* x5 x1 x4 x0*/\
+ "movq %%mm0,%%mm5 \n\t"/* 5 ; x5 x1 x4 x0*/\
+ "punpckldq %%mm0,%%mm0 \n\t"/* x4 x0 x4 x0*/\
+ "movq 8+" #A3 ",%%mm4 \n\t"/* 4 ; w07 w05 w03 w01*/\
+ "punpckhwd %%mm1,%%mm2 \n\t"/* 1 ; x7 x3 x6 x2*/\
+ "pmaddwd %%mm0,%%mm3 \n\t"/* x4*w06+x0*w04 x4*w02+x0*w00*/\
+ "movq %%mm2,%%mm6 \n\t"/* 6 ; x7 x3 x6 x2*/\
+ "movq 32+" #A3 ",%%mm1 \n\t"/* 1 ; w22 w20 w18 w16*/\
+ "punpckldq %%mm2,%%mm2 \n\t"/* x6 x2 x6 x2*/\
+ "pmaddwd %%mm2,%%mm4 \n\t"/* x6*w07+x2*w05 x6*w03+x2*w01*/\
+ "punpckhdq %%mm5,%%mm5 \n\t"/* x5 x1 x5 x1*/\
+ "pmaddwd 16+" #A3 ",%%mm0 \n\t"/* x4*w14+x0*w12 x4*w10+x0*w08*/\
+ "punpckhdq %%mm6,%%mm6 \n\t"/* x7 x3 x7 x3*/\
+ "movq 40+" #A3 ",%%mm7 \n\t"/* 7 ; w23 w21 w19 w17*/\
+ "pmaddwd %%mm5,%%mm1 \n\t"/* x5*w22+x1*w20 x5*w18+x1*w16*/\
+ "paddd " #A4 ",%%mm3 \n\t"/* +%4*/\
+ "pmaddwd %%mm6,%%mm7 \n\t"/* x7*w23+x3*w21 x7*w19+x3*w17*/\
+ "pmaddwd 24+" #A3 ",%%mm2 \n\t"/* x6*w15+x2*w13 x6*w11+x2*w09*/\
+ "paddd %%mm4,%%mm3 \n\t"/* 4 ; a1=sum(even1) a0=sum(even0)*/\
+ "pmaddwd 48+" #A3 ",%%mm5 \n\t"/* x5*w30+x1*w28 x5*w26+x1*w24*/\
+ "movq %%mm3,%%mm4 \n\t"/* 4 ; a1 a0*/\
+ "pmaddwd 56+" #A3 ",%%mm6 \n\t"/* x7*w31+x3*w29 x7*w27+x3*w25*/\
+ "paddd %%mm7,%%mm1 \n\t"/* 7 ; b1=sum(odd1) b0=sum(odd0)*/\
+ "paddd " #A4 ",%%mm0 \n\t"/* +%4*/\
+ "psubd %%mm1,%%mm3 \n\t"/* a1-b1 a0-b0*/\
+ "psrad $11,%%mm3 \n\t"/* y6=a1-b1 y7=a0-b0*/\
+ "paddd %%mm4,%%mm1 \n\t"/* 4 ; a1+b1 a0+b0*/\
+ "paddd %%mm2,%%mm0 \n\t"/* 2 ; a3=sum(even3) a2=sum(even2)*/\
+ "psrad $11,%%mm1 \n\t"/* y1=a1+b1 y0=a0+b0*/\
+ "paddd %%mm6,%%mm5 \n\t"/* 6 ; b3=sum(odd3) b2=sum(odd2)*/\
+ "movq %%mm0,%%mm4 \n\t"/* 4 ; a3 a2*/\
+ "paddd %%mm5,%%mm0 \n\t"/* a3+b3 a2+b2*/\
+ "psubd %%mm5,%%mm4 \n\t"/* 5 ; a3-b3 a2-b2*/\
+ "psrad $11,%%mm0 \n\t"/* y3=a3+b3 y2=a2+b2*/\
+ "psrad $11,%%mm4 \n\t"/* y4=a3-b3 y5=a2-b2*/\
+ "packssdw %%mm0,%%mm1 \n\t"/* 0 ; y3 y2 y1 y0*/\
+ "packssdw %%mm3,%%mm4 \n\t"/* 3 ; y6 y7 y4 y5*/\
+ "movq %%mm4,%%mm7 \n\t"/* 7 ; y6 y7 y4 y5*/\
+ "psrld $16,%%mm4 \n\t"/* 0 y6 0 y4*/\
+ "pslld $16,%%mm7 \n\t"/* y7 0 y5 0*/\
+ "movq %%mm1," #A2 " \n\t"/* 1 ; save y3 y2 y1 y0*/\
+ "por %%mm4,%%mm7 \n\t"/* 4 ; y7 y6 y5 y4*/\
+ "movq %%mm7,8 +" #A2 "\n\t"/* 7 ; save y7 y6 y5 y4*/\
+
+
+//-----------------------------------------------------------------------------
+// DCT_8_INV_ROW_XMM( INP, OUT, TABLE, ROUNDER
+//-----------------------------------------------------------------------------
+
+#define DCT_8_INV_ROW_XMM(A1,A2,A3,A4)\
+ "movq " #A1 ",%%mm0 \n\t"/* 0 ; x3 x2 x1 x0*/\
+ "movq 8+" #A1 ",%%mm1 \n\t"/* 1 ; x7 x6 x5 x4*/\
+ "movq %%mm0,%%mm2 \n\t"/* 2 ; x3 x2 x1 x0*/\
+ "movq " #A3 ",%%mm3 \n\t"/* 3 ; w05 w04 w01 w00*/\
+ "pshufw $0x88,%%mm0,%%mm0 \n\t"/* x2 x0 x2 x0*/\
+ "movq 8+" #A3 ",%%mm4 \n\t"/* 4 ; w07 w06 w03 w02*/\
+ "movq %%mm1,%%mm5 \n\t"/* 5 ; x7 x6 x5 x4*/\
+ "pmaddwd %%mm0,%%mm3 \n\t"/* x2*w05+x0*w04 x2*w01+x0*w00*/\
+ "movq 32+" #A3 ",%%mm6 \n\t"/* 6 ; w21 w20 w17 w16*/\
+ "pshufw $0x88,%%mm1,%%mm1 \n\t"/* x6 x4 x6 x4*/\
+ "pmaddwd %%mm1,%%mm4 \n\t"/* x6*w07+x4*w06 x6*w03+x4*w02*/\
+ "movq 40+" #A3 ",%%mm7 \n\t"/* 7 ; w23 w22 w19 w18*/\
+ "pshufw $0xdd,%%mm2,%%mm2 \n\t"/* x3 x1 x3 x1*/\
+ "pmaddwd %%mm2,%%mm6 \n\t"/* x3*w21+x1*w20 x3*w17+x1*w16*/\
+ "pshufw $0xdd,%%mm5,%%mm5 \n\t"/* x7 x5 x7 x5*/\
+ "pmaddwd %%mm5,%%mm7 \n\t"/* x7*w23+x5*w22 x7*w19+x5*w18*/\
+ "paddd " #A4 ",%%mm3 \n\t"/* +%4*/\
+ "pmaddwd 16+" #A3 ",%%mm0 \n\t"/* x2*w13+x0*w12 x2*w09+x0*w08*/\
+ "paddd %%mm4,%%mm3 \n\t"/* 4 ; a1=sum(even1) a0=sum(even0)*/\
+ "pmaddwd 24+" #A3 ",%%mm1 \n\t"/* x6*w15+x4*w14 x6*w11+x4*w10*/\
+ "movq %%mm3,%%mm4 \n\t"/* 4 ; a1 a0*/\
+ "pmaddwd 48+" #A3 ",%%mm2 \n\t"/* x3*w29+x1*w28 x3*w25+x1*w24*/\
+ "paddd %%mm7,%%mm6 \n\t"/* 7 ; b1=sum(odd1) b0=sum(odd0)*/\
+ "pmaddwd 56+" #A3 ",%%mm5 \n\t"/* x7*w31+x5*w30 x7*w27+x5*w26*/\
+ "paddd %%mm6,%%mm3 \n\t"/* a1+b1 a0+b0*/\
+ "paddd " #A4 ",%%mm0 \n\t"/* +%4*/\
+ "psrad $11,%%mm3 \n\t"/* y1=a1+b1 y0=a0+b0*/\
+ "paddd %%mm1,%%mm0 \n\t"/* 1 ; a3=sum(even3) a2=sum(even2)*/\
+ "psubd %%mm6,%%mm4 \n\t"/* 6 ; a1-b1 a0-b0*/\
+ "movq %%mm0,%%mm7 \n\t"/* 7 ; a3 a2*/\
+ "paddd %%mm5,%%mm2 \n\t"/* 5 ; b3=sum(odd3) b2=sum(odd2)*/\
+ "paddd %%mm2,%%mm0 \n\t"/* a3+b3 a2+b2*/\
+ "psrad $11,%%mm4 \n\t"/* y6=a1-b1 y7=a0-b0*/\
+ "psubd %%mm2,%%mm7 \n\t"/* 2 ; a3-b3 a2-b2*/\
+ "psrad $11,%%mm0 \n\t"/* y3=a3+b3 y2=a2+b2*/\
+ "psrad $11,%%mm7 \n\t"/* y4=a3-b3 y5=a2-b2*/\
+ "packssdw %%mm0,%%mm3 \n\t"/* 0 ; y3 y2 y1 y0*/\
+ "packssdw %%mm4,%%mm7 \n\t"/* 4 ; y6 y7 y4 y5*/\
+ "movq %%mm3, " #A2 " \n\t"/* 3 ; save y3 y2 y1 y0*/\
+ "pshufw $0xb1,%%mm7,%%mm7 \n\t"/* y7 y6 y5 y4*/\
+ "movq %%mm7,8 +" #A2 "\n\t"/* 7 ; save y7 y6 y5 y4*/\
+
+
+//-----------------------------------------------------------------------------
+//
+// The first stage DCT 8x8 - forward DCTs of columns
+//
+// The %2puts are multiplied
+// for rows 0,4 - on cos_4_16,
+// for rows 1,7 - on cos_1_16,
+// for rows 2,6 - on cos_2_16,
+// for rows 3,5 - on cos_3_16
+// and are shifted to the left for rise of accuracy
+//
+//-----------------------------------------------------------------------------
+//
+// The 8-point scaled forward DCT algorithm (26a8m)
+//
+//-----------------------------------------------------------------------------
+//
+// #define DCT_8_FRW_COL(x, y)
+//{
+// short t0, t1, t2, t3, t4, t5, t6, t7;
+// short tp03, tm03, tp12, tm12, tp65, tm65;
+// short tp465, tm465, tp765, tm765;
+//
+// t0 = LEFT_SHIFT ( x[0] + x[7] );
+// t1 = LEFT_SHIFT ( x[1] + x[6] );
+// t2 = LEFT_SHIFT ( x[2] + x[5] );
+// t3 = LEFT_SHIFT ( x[3] + x[4] );
+// t4 = LEFT_SHIFT ( x[3] - x[4] );
+// t5 = LEFT_SHIFT ( x[2] - x[5] );
+// t6 = LEFT_SHIFT ( x[1] - x[6] );
+// t7 = LEFT_SHIFT ( x[0] - x[7] );
+//
+// tp03 = t0 + t3;
+// tm03 = t0 - t3;
+// tp12 = t1 + t2;
+// tm12 = t1 - t2;
+//
+// y[0] = tp03 + tp12;
+// y[4] = tp03 - tp12;
+//
+// y[2] = tm03 + tm12 * tg_2_16;
+// y[6] = tm03 * tg_2_16 - tm12;
+//
+// tp65 =(t6 +t5 )*cos_4_16;
+// tm65 =(t6 -t5 )*cos_4_16;
+//
+// tp765 = t7 + tp65;
+// tm765 = t7 - tp65;
+// tp465 = t4 + tm65;
+// tm465 = t4 - tm65;
+//
+// y[1] = tp765 + tp465 * tg_1_16;
+// y[7] = tp765 * tg_1_16 - tp465;
+// y[5] = tm765 * tg_3_16 + tm465;
+// y[3] = tm765 - tm465 * tg_3_16;
+//}
+//
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+// DCT_8_INV_COL_4 INP,OUT
+//-----------------------------------------------------------------------------
+
+#define DCT_8_INV_COL(A1,A2)\
+ "movq 2*8(%3),%%mm0\n\t"\
+ "movq 16*3+" #A1 ",%%mm3\n\t"\
+ "movq %%mm0,%%mm1 \n\t"/* tg_3_16*/\
+ "movq 16*5+" #A1 ",%%mm5\n\t"\
+ "pmulhw %%mm3,%%mm0 \n\t"/* x3*(tg_3_16-1)*/\
+ "movq (%3),%%mm4\n\t"\
+ "pmulhw %%mm5,%%mm1 \n\t"/* x5*(tg_3_16-1)*/\
+ "movq 16*7+" #A1 ",%%mm7\n\t"\
+ "movq %%mm4,%%mm2 \n\t"/* tg_1_16*/\
+ "movq 16*1+" #A1 ",%%mm6\n\t"\
+ "pmulhw %%mm7,%%mm4 \n\t"/* x7*tg_1_16*/\
+ "paddsw %%mm3,%%mm0 \n\t"/* x3*tg_3_16*/\
+ "pmulhw %%mm6,%%mm2 \n\t"/* x1*tg_1_16*/\
+ "paddsw %%mm3,%%mm1 \n\t"/* x3+x5*(tg_3_16-1)*/\
+ "psubsw %%mm5,%%mm0 \n\t"/* x3*tg_3_16-x5 = tm35*/\
+ "movq 3*8(%3),%%mm3\n\t"\
+ "paddsw %%mm5,%%mm1 \n\t"/* x3+x5*tg_3_16 = tp35*/\
+ "paddsw %%mm6,%%mm4 \n\t"/* x1+tg_1_16*x7 = tp17*/\
+ "psubsw %%mm7,%%mm2 \n\t"/* x1*tg_1_16-x7 = tm17*/\
+ "movq %%mm4,%%mm5 \n\t"/* tp17*/\
+ "movq %%mm2,%%mm6 \n\t"/* tm17*/\
+ "paddsw %%mm1,%%mm5 \n\t"/* tp17+tp35 = b0*/\
+ "psubsw %%mm0,%%mm6 \n\t"/* tm17-tm35 = b3*/\
+ "psubsw %%mm1,%%mm4 \n\t"/* tp17-tp35 = t1*/\
+ "paddsw %%mm0,%%mm2 \n\t"/* tm17+tm35 = t2*/\
+ "movq 1*8(%3),%%mm7\n\t"\
+ "movq %%mm4,%%mm1 \n\t"/* t1*/\
+ "movq %%mm5,3*16 +" #A2 "\n\t"/* save b0*/\
+ "paddsw %%mm2,%%mm1 \n\t"/* t1+t2*/\
+ "movq %%mm6,5*16 +" #A2 "\n\t"/* save b3*/\
+ "psubsw %%mm2,%%mm4 \n\t"/* t1-t2*/\
+ "movq 2*16+" #A1 ",%%mm5\n\t"\
+ "movq %%mm7,%%mm0 \n\t"/* tg_2_16*/\
+ "movq 6*16+" #A1 ",%%mm6\n\t"\
+ "pmulhw %%mm5,%%mm0 \n\t"/* x2*tg_2_16*/\
+ "pmulhw %%mm6,%%mm7 \n\t"/* x6*tg_2_16*/\
+ "pmulhw %%mm3,%%mm1 \n\t"/* ocos_4_16*(t1+t2) = b1/2*/\
+ "movq 0*16+" #A1 ",%%mm2\n\t"\
+ "pmulhw %%mm3,%%mm4 \n\t"/* ocos_4_16*(t1-t2) = b2/2*/\
+ "psubsw %%mm6,%%mm0 \n\t"/* t2*tg_2_16-x6 = tm26*/\
+ "movq %%mm2,%%mm3 \n\t"/* x0*/\
+ "movq 4*16+" #A1 ",%%mm6\n\t"\
+ "paddsw %%mm5,%%mm7 \n\t"/* x2+x6*tg_2_16 = tp26*/\
+ "paddsw %%mm6,%%mm2 \n\t"/* x0+x4 = tp04*/\
+ "psubsw %%mm6,%%mm3 \n\t"/* x0-x4 = tm04*/\
+ "movq %%mm2,%%mm5 \n\t"/* tp04*/\
+ "movq %%mm3,%%mm6 \n\t"/* tm04*/\
+ "psubsw %%mm7,%%mm2 \n\t"/* tp04-tp26 = a3*/\
+ "paddsw %%mm0,%%mm3 \n\t"/* tm04+tm26 = a1*/\
+ "paddsw %%mm1,%%mm1 \n\t"/* b1*/\
+ "paddsw %%mm4,%%mm4 \n\t"/* b2*/\
+ "paddsw %%mm7,%%mm5 \n\t"/* tp04+tp26 = a0*/\
+ "psubsw %%mm0,%%mm6 \n\t"/* tm04-tm26 = a2*/\
+ "movq %%mm3,%%mm7 \n\t"/* a1*/\
+ "movq %%mm6,%%mm0 \n\t"/* a2*/\
+ "paddsw %%mm1,%%mm3 \n\t"/* a1+b1*/\
+ "paddsw %%mm4,%%mm6 \n\t"/* a2+b2*/\
+ "psraw $6,%%mm3 \n\t"/* dst1*/\
+ "psubsw %%mm1,%%mm7 \n\t"/* a1-b1*/\
+ "psraw $6,%%mm6 \n\t"/* dst2*/\
+ "psubsw %%mm4,%%mm0 \n\t"/* a2-b2*/\
+ "movq 3*16+" #A2 ",%%mm1 \n\t"/* load b0*/\
+ "psraw $6,%%mm7 \n\t"/* dst6*/\
+ "movq %%mm5,%%mm4 \n\t"/* a0*/\
+ "psraw $6,%%mm0 \n\t"/* dst5*/\
+ "movq %%mm3,1*16+" #A2 "\n\t"\
+ "paddsw %%mm1,%%mm5 \n\t"/* a0+b0*/\
+ "movq %%mm6,2*16+" #A2 "\n\t"\
+ "psubsw %%mm1,%%mm4 \n\t"/* a0-b0*/\
+ "movq 5*16+" #A2 ",%%mm3 \n\t"/* load b3*/\
+ "psraw $6,%%mm5 \n\t"/* dst0*/\
+ "movq %%mm2,%%mm6 \n\t"/* a3*/\
+ "psraw $6,%%mm4 \n\t"/* dst7*/\
+ "movq %%mm0,5*16+" #A2 "\n\t"\
+ "paddsw %%mm3,%%mm2 \n\t"/* a3+b3*/\
+ "movq %%mm7,6*16+" #A2 "\n\t"\
+ "psubsw %%mm3,%%mm6 \n\t"/* a3-b3*/\
+ "movq %%mm5,0*16+" #A2 "\n\t"\
+ "psraw $6,%%mm2 \n\t"/* dst3*/\
+ "movq %%mm4,7*16+" #A2 "\n\t"\
+ "psraw $6,%%mm6 \n\t"/* dst4*/\
+ "movq %%mm2,3*16+" #A2 "\n\t"\
+ "movq %%mm6,4*16+" #A2 "\n\t"
+
+//=============================================================================
+// Code
+//=============================================================================
+
+//-----------------------------------------------------------------------------
+// void idct_mmx(uint16_t block[64]);
+//-----------------------------------------------------------------------------
+
+
+void ff_idct_xvid_mmx(short *block){
+asm volatile(
+ //# Process each row
+ DCT_8_INV_ROW_MMX(0*16(%0), 0*16(%0), 64*0(%2), 8*0(%1))
+ DCT_8_INV_ROW_MMX(1*16(%0), 1*16(%0), 64*1(%2), 8*1(%1))
+ DCT_8_INV_ROW_MMX(2*16(%0), 2*16(%0), 64*2(%2), 8*2(%1))
+ DCT_8_INV_ROW_MMX(3*16(%0), 3*16(%0), 64*3(%2), 8*3(%1))
+ DCT_8_INV_ROW_MMX(4*16(%0), 4*16(%0), 64*0(%2), 8*4(%1))
+ DCT_8_INV_ROW_MMX(5*16(%0), 5*16(%0), 64*3(%2), 8*5(%1))
+ DCT_8_INV_ROW_MMX(6*16(%0), 6*16(%0), 64*2(%2), 8*6(%1))
+ DCT_8_INV_ROW_MMX(7*16(%0), 7*16(%0), 64*1(%2), 8*7(%1))
+
+ //# Process the columns (4 at a time)
+ DCT_8_INV_COL(0(%0), 0(%0))
+ DCT_8_INV_COL(8(%0), 8(%0))
+ :: "r"(block), "r"(rounder_0), "r"(tab_i_04_mmx), "r"(tg_1_16));
+}
+
+//-----------------------------------------------------------------------------
+// void idct_xmm(uint16_t block[64]);
+//-----------------------------------------------------------------------------
+
+
+void ff_idct_xvid_mmx2(short *block){
+asm volatile(
+ //# Process each row
+ DCT_8_INV_ROW_XMM(0*16(%0), 0*16(%0), 64*0(%2), 8*0(%1))
+ DCT_8_INV_ROW_XMM(1*16(%0), 1*16(%0), 64*1(%2), 8*1(%1))
+ DCT_8_INV_ROW_XMM(2*16(%0), 2*16(%0), 64*2(%2), 8*2(%1))
+ DCT_8_INV_ROW_XMM(3*16(%0), 3*16(%0), 64*3(%2), 8*3(%1))
+ DCT_8_INV_ROW_XMM(4*16(%0), 4*16(%0), 64*0(%2), 8*4(%1))
+ DCT_8_INV_ROW_XMM(5*16(%0), 5*16(%0), 64*3(%2), 8*5(%1))
+ DCT_8_INV_ROW_XMM(6*16(%0), 6*16(%0), 64*2(%2), 8*6(%1))
+ DCT_8_INV_ROW_XMM(7*16(%0), 7*16(%0), 64*1(%2), 8*7(%1))
+
+ //# Process the columns (4 at a time)
+ DCT_8_INV_COL(0(%0), 0(%0))
+ DCT_8_INV_COL(8(%0), 8(%0))
+ :: "r"(block), "r"(rounder_0), "r"(tab_i_04_xmm), "r"(tg_1_16));
+}
+
diff --git a/src/libffmpeg/libavcodec/i386/mathops.h b/contrib/ffmpeg/libavcodec/i386/mathops.h
index 3553a4025..3553a4025 100644
--- a/src/libffmpeg/libavcodec/i386/mathops.h
+++ b/contrib/ffmpeg/libavcodec/i386/mathops.h
diff --git a/src/libffmpeg/libavcodec/i386/mmx.h b/contrib/ffmpeg/libavcodec/i386/mmx.h
index 41aae6c21..41aae6c21 100644
--- a/src/libffmpeg/libavcodec/i386/mmx.h
+++ b/contrib/ffmpeg/libavcodec/i386/mmx.h
diff --git a/src/libffmpeg/libavcodec/i386/motion_est_mmx.c b/contrib/ffmpeg/libavcodec/i386/motion_est_mmx.c
index e33870e0f..e33870e0f 100644
--- a/src/libffmpeg/libavcodec/i386/motion_est_mmx.c
+++ b/contrib/ffmpeg/libavcodec/i386/motion_est_mmx.c
diff --git a/src/libffmpeg/libavcodec/i386/mpegvideo_mmx.c b/contrib/ffmpeg/libavcodec/i386/mpegvideo_mmx.c
index 1b7b1c19f..1b7b1c19f 100644
--- a/src/libffmpeg/libavcodec/i386/mpegvideo_mmx.c
+++ b/contrib/ffmpeg/libavcodec/i386/mpegvideo_mmx.c
diff --git a/src/libffmpeg/libavcodec/i386/mpegvideo_mmx_template.c b/contrib/ffmpeg/libavcodec/i386/mpegvideo_mmx_template.c
index d59b6efd9..d59b6efd9 100644
--- a/src/libffmpeg/libavcodec/i386/mpegvideo_mmx_template.c
+++ b/contrib/ffmpeg/libavcodec/i386/mpegvideo_mmx_template.c
diff --git a/src/libffmpeg/libavcodec/i386/simple_idct_mmx.c b/contrib/ffmpeg/libavcodec/i386/simple_idct_mmx.c
index 525ef34f7..525ef34f7 100644
--- a/src/libffmpeg/libavcodec/i386/simple_idct_mmx.c
+++ b/contrib/ffmpeg/libavcodec/i386/simple_idct_mmx.c
diff --git a/contrib/ffmpeg/libavcodec/i386/snowdsp_mmx.c b/contrib/ffmpeg/libavcodec/i386/snowdsp_mmx.c
new file mode 100644
index 000000000..8f182303d
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/i386/snowdsp_mmx.c
@@ -0,0 +1,921 @@
+/*
+ * MMX and SSE2 optimized snow DSP utils
+ * Copyright (c) 2005-2006 Robert Edele <yartrebo@earthlink.net>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 "../snow.h"
+#include "x86_cpu.h"
+
+void ff_snow_horizontal_compose97i_sse2(DWTELEM *b, int width){
+ const int w2= (width+1)>>1;
+ // SSE2 code runs faster with pointers aligned on a 32-byte boundary.
+ DWTELEM temp_buf[(width>>1) + 4];
+ DWTELEM * const temp = temp_buf + 4 - (((int)temp_buf & 0xF) >> 2);
+ const int w_l= (width>>1);
+ const int w_r= w2 - 1;
+ int i;
+
+ { // Lift 0
+ DWTELEM * const ref = b + w2 - 1;
+ DWTELEM b_0 = b[0]; //By allowing the first entry in b[0] to be calculated twice
+ // (the first time erroneously), we allow the SSE2 code to run an extra pass.
+ // The savings in code and time are well worth having to store this value and
+ // calculate b[0] correctly afterwards.
+
+ i = 0;
+ asm volatile(
+ "pcmpeqd %%xmm7, %%xmm7 \n\t"
+ "pslld $31, %%xmm7 \n\t"
+ "psrld $29, %%xmm7 \n\t"
+ ::);
+ for(; i<w_l-7; i+=8){
+ asm volatile(
+ "movdqu (%1), %%xmm1 \n\t"
+ "movdqu 16(%1), %%xmm5 \n\t"
+ "movdqu 4(%1), %%xmm2 \n\t"
+ "movdqu 20(%1), %%xmm6 \n\t"
+ "paddd %%xmm1, %%xmm2 \n\t"
+ "paddd %%xmm5, %%xmm6 \n\t"
+ "movdqa %%xmm2, %%xmm0 \n\t"
+ "movdqa %%xmm6, %%xmm4 \n\t"
+ "paddd %%xmm2, %%xmm2 \n\t"
+ "paddd %%xmm6, %%xmm6 \n\t"
+ "paddd %%xmm0, %%xmm2 \n\t"
+ "paddd %%xmm4, %%xmm6 \n\t"
+ "paddd %%xmm7, %%xmm2 \n\t"
+ "paddd %%xmm7, %%xmm6 \n\t"
+ "psrad $3, %%xmm2 \n\t"
+ "psrad $3, %%xmm6 \n\t"
+ "movdqa (%0), %%xmm0 \n\t"
+ "movdqa 16(%0), %%xmm4 \n\t"
+ "psubd %%xmm2, %%xmm0 \n\t"
+ "psubd %%xmm6, %%xmm4 \n\t"
+ "movdqa %%xmm0, (%0) \n\t"
+ "movdqa %%xmm4, 16(%0) \n\t"
+ :: "r"(&b[i]), "r"(&ref[i])
+ : "memory"
+ );
+ }
+ snow_horizontal_compose_lift_lead_out(i, b, b, ref, width, w_l, 0, W_DM, W_DO, W_DS);
+ b[0] = b_0 - ((W_DM * 2 * ref[1]+W_DO)>>W_DS);
+ }
+
+ { // Lift 1
+ DWTELEM * const dst = b+w2;
+
+ i = 0;
+ for(; (((long)&dst[i]) & 0xF) && i<w_r; i++){
+ dst[i] = dst[i] - (b[i] + b[i + 1]);
+ }
+ for(; i<w_r-7; i+=8){
+ asm volatile(
+ "movdqu (%1), %%xmm1 \n\t"
+ "movdqu 16(%1), %%xmm5 \n\t"
+ "movdqu 4(%1), %%xmm2 \n\t"
+ "movdqu 20(%1), %%xmm6 \n\t"
+ "paddd %%xmm1, %%xmm2 \n\t"
+ "paddd %%xmm5, %%xmm6 \n\t"
+ "movdqa (%0), %%xmm0 \n\t"
+ "movdqa 16(%0), %%xmm4 \n\t"
+ "psubd %%xmm2, %%xmm0 \n\t"
+ "psubd %%xmm6, %%xmm4 \n\t"
+ "movdqa %%xmm0, (%0) \n\t"
+ "movdqa %%xmm4, 16(%0) \n\t"
+ :: "r"(&dst[i]), "r"(&b[i])
+ : "memory"
+ );
+ }
+ snow_horizontal_compose_lift_lead_out(i, dst, dst, b, width, w_r, 1, W_CM, W_CO, W_CS);
+ }
+
+ { // Lift 2
+ DWTELEM * const ref = b+w2 - 1;
+ DWTELEM b_0 = b[0];
+
+ i = 0;
+ asm volatile(
+ "pslld $1, %%xmm7 \n\t" /* xmm7 already holds a '4' from 2 lifts ago. */
+ ::);
+ for(; i<w_l-7; i+=8){
+ asm volatile(
+ "movdqu (%1), %%xmm1 \n\t"
+ "movdqu 16(%1), %%xmm5 \n\t"
+ "movdqu 4(%1), %%xmm0 \n\t"
+ "movdqu 20(%1), %%xmm4 \n\t"
+ "paddd %%xmm1, %%xmm0 \n\t"
+ "paddd %%xmm5, %%xmm4 \n\t"
+ "movdqa %%xmm7, %%xmm1 \n\t"
+ "movdqa %%xmm7, %%xmm5 \n\t"
+ "psubd %%xmm0, %%xmm1 \n\t"
+ "psubd %%xmm4, %%xmm5 \n\t"
+ "movdqa (%0), %%xmm0 \n\t"
+ "movdqa 16(%0), %%xmm4 \n\t"
+ "pslld $2, %%xmm0 \n\t"
+ "pslld $2, %%xmm4 \n\t"
+ "psubd %%xmm0, %%xmm1 \n\t"
+ "psubd %%xmm4, %%xmm5 \n\t"
+ "psrad $4, %%xmm1 \n\t"
+ "psrad $4, %%xmm5 \n\t"
+ "movdqa (%0), %%xmm0 \n\t"
+ "movdqa 16(%0), %%xmm4 \n\t"
+ "psubd %%xmm1, %%xmm0 \n\t"
+ "psubd %%xmm5, %%xmm4 \n\t"
+ "movdqa %%xmm0, (%0) \n\t"
+ "movdqa %%xmm4, 16(%0) \n\t"
+ :: "r"(&b[i]), "r"(&ref[i])
+ : "memory"
+ );
+ }
+ snow_horizontal_compose_liftS_lead_out(i, b, b, ref, width, w_l);
+ b[0] = b_0 - (((-2 * ref[1] + W_BO) - 4 * b_0) >> W_BS);
+ }
+
+ { // Lift 3
+ DWTELEM * const src = b+w2;
+
+ i = 0;
+ for(; (((long)&temp[i]) & 0xF) && i<w_r; i++){
+ temp[i] = src[i] - ((-W_AM*(b[i] + b[i+1]))>>W_AS);
+ }
+ for(; i<w_r-7; i+=8){
+ asm volatile(
+ "movdqu 4(%1), %%xmm2 \n\t"
+ "movdqu 20(%1), %%xmm6 \n\t"
+ "paddd (%1), %%xmm2 \n\t"
+ "paddd 16(%1), %%xmm6 \n\t"
+ "movdqa %%xmm2, %%xmm0 \n\t"
+ "movdqa %%xmm6, %%xmm4 \n\t"
+ "pslld $2, %%xmm2 \n\t"
+ "pslld $2, %%xmm6 \n\t"
+ "psubd %%xmm2, %%xmm0 \n\t"
+ "psubd %%xmm6, %%xmm4 \n\t"
+ "psrad $1, %%xmm0 \n\t"
+ "psrad $1, %%xmm4 \n\t"
+ "movdqu (%0), %%xmm2 \n\t"
+ "movdqu 16(%0), %%xmm6 \n\t"
+ "psubd %%xmm0, %%xmm2 \n\t"
+ "psubd %%xmm4, %%xmm6 \n\t"
+ "movdqa %%xmm2, (%2) \n\t"
+ "movdqa %%xmm6, 16(%2) \n\t"
+ :: "r"(&src[i]), "r"(&b[i]), "r"(&temp[i])
+ : "memory"
+ );
+ }
+ snow_horizontal_compose_lift_lead_out(i, temp, src, b, width, w_r, 1, -W_AM, W_AO, W_AS);
+ }
+
+ {
+ snow_interleave_line_header(&i, width, b, temp);
+
+ for (; (i & 0x1E) != 0x1E; i-=2){
+ b[i+1] = temp[i>>1];
+ b[i] = b[i>>1];
+ }
+ for (i-=30; i>=0; i-=32){
+ asm volatile(
+ "movdqa (%1), %%xmm0 \n\t"
+ "movdqa 16(%1), %%xmm2 \n\t"
+ "movdqa 32(%1), %%xmm4 \n\t"
+ "movdqa 48(%1), %%xmm6 \n\t"
+ "movdqa (%1), %%xmm1 \n\t"
+ "movdqa 16(%1), %%xmm3 \n\t"
+ "movdqa 32(%1), %%xmm5 \n\t"
+ "movdqa 48(%1), %%xmm7 \n\t"
+ "punpckldq (%2), %%xmm0 \n\t"
+ "punpckldq 16(%2), %%xmm2 \n\t"
+ "punpckldq 32(%2), %%xmm4 \n\t"
+ "punpckldq 48(%2), %%xmm6 \n\t"
+ "movdqa %%xmm0, (%0) \n\t"
+ "movdqa %%xmm2, 32(%0) \n\t"
+ "movdqa %%xmm4, 64(%0) \n\t"
+ "movdqa %%xmm6, 96(%0) \n\t"
+ "punpckhdq (%2), %%xmm1 \n\t"
+ "punpckhdq 16(%2), %%xmm3 \n\t"
+ "punpckhdq 32(%2), %%xmm5 \n\t"
+ "punpckhdq 48(%2), %%xmm7 \n\t"
+ "movdqa %%xmm1, 16(%0) \n\t"
+ "movdqa %%xmm3, 48(%0) \n\t"
+ "movdqa %%xmm5, 80(%0) \n\t"
+ "movdqa %%xmm7, 112(%0) \n\t"
+ :: "r"(&(b)[i]), "r"(&(b)[i>>1]), "r"(&(temp)[i>>1])
+ : "memory"
+ );
+ }
+ }
+}
+
+void ff_snow_horizontal_compose97i_mmx(DWTELEM *b, int width){
+ const int w2= (width+1)>>1;
+ DWTELEM temp[width >> 1];
+ const int w_l= (width>>1);
+ const int w_r= w2 - 1;
+ int i;
+
+ { // Lift 0
+ DWTELEM * const ref = b + w2 - 1;
+
+ i = 1;
+ b[0] = b[0] - ((W_DM * 2 * ref[1]+W_DO)>>W_DS);
+ asm volatile(
+ "pcmpeqd %%mm7, %%mm7 \n\t"
+ "pslld $31, %%mm7 \n\t"
+ "psrld $29, %%mm7 \n\t"
+ ::);
+ for(; i<w_l-3; i+=4){
+ asm volatile(
+ "movq (%1), %%mm2 \n\t"
+ "movq 8(%1), %%mm6 \n\t"
+ "paddd 4(%1), %%mm2 \n\t"
+ "paddd 12(%1), %%mm6 \n\t"
+ "movq %%mm2, %%mm0 \n\t"
+ "movq %%mm6, %%mm4 \n\t"
+ "paddd %%mm2, %%mm2 \n\t"
+ "paddd %%mm6, %%mm6 \n\t"
+ "paddd %%mm0, %%mm2 \n\t"
+ "paddd %%mm4, %%mm6 \n\t"
+ "paddd %%mm7, %%mm2 \n\t"
+ "paddd %%mm7, %%mm6 \n\t"
+ "psrad $3, %%mm2 \n\t"
+ "psrad $3, %%mm6 \n\t"
+ "movq (%0), %%mm0 \n\t"
+ "movq 8(%0), %%mm4 \n\t"
+ "psubd %%mm2, %%mm0 \n\t"
+ "psubd %%mm6, %%mm4 \n\t"
+ "movq %%mm0, (%0) \n\t"
+ "movq %%mm4, 8(%0) \n\t"
+ :: "r"(&b[i]), "r"(&ref[i])
+ : "memory"
+ );
+ }
+ snow_horizontal_compose_lift_lead_out(i, b, b, ref, width, w_l, 0, W_DM, W_DO, W_DS);
+ }
+
+ { // Lift 1
+ DWTELEM * const dst = b+w2;
+
+ i = 0;
+ for(; i<w_r-3; i+=4){
+ asm volatile(
+ "movq (%1), %%mm2 \n\t"
+ "movq 8(%1), %%mm6 \n\t"
+ "paddd 4(%1), %%mm2 \n\t"
+ "paddd 12(%1), %%mm6 \n\t"
+ "movq (%0), %%mm0 \n\t"
+ "movq 8(%0), %%mm4 \n\t"
+ "psubd %%mm2, %%mm0 \n\t"
+ "psubd %%mm6, %%mm4 \n\t"
+ "movq %%mm0, (%0) \n\t"
+ "movq %%mm4, 8(%0) \n\t"
+ :: "r"(&dst[i]), "r"(&b[i])
+ : "memory"
+ );
+ }
+ snow_horizontal_compose_lift_lead_out(i, dst, dst, b, width, w_r, 1, W_CM, W_CO, W_CS);
+ }
+
+ { // Lift 2
+ DWTELEM * const ref = b+w2 - 1;
+
+ i = 1;
+ b[0] = b[0] - (((-2 * ref[1] + W_BO) - 4 * b[0]) >> W_BS);
+ asm volatile(
+ "pslld $1, %%mm7 \n\t" /* xmm7 already holds a '4' from 2 lifts ago. */
+ ::);
+ for(; i<w_l-3; i+=4){
+ asm volatile(
+ "movq (%1), %%mm0 \n\t"
+ "movq 8(%1), %%mm4 \n\t"
+ "paddd 4(%1), %%mm0 \n\t"
+ "paddd 12(%1), %%mm4 \n\t"
+ "movq %%mm7, %%mm1 \n\t"
+ "movq %%mm7, %%mm5 \n\t"
+ "psubd %%mm0, %%mm1 \n\t"
+ "psubd %%mm4, %%mm5 \n\t"
+ "movq (%0), %%mm0 \n\t"
+ "movq 8(%0), %%mm4 \n\t"
+ "pslld $2, %%mm0 \n\t"
+ "pslld $2, %%mm4 \n\t"
+ "psubd %%mm0, %%mm1 \n\t"
+ "psubd %%mm4, %%mm5 \n\t"
+ "psrad $4, %%mm1 \n\t"
+ "psrad $4, %%mm5 \n\t"
+ "movq (%0), %%mm0 \n\t"
+ "movq 8(%0), %%mm4 \n\t"
+ "psubd %%mm1, %%mm0 \n\t"
+ "psubd %%mm5, %%mm4 \n\t"
+ "movq %%mm0, (%0) \n\t"
+ "movq %%mm4, 8(%0) \n\t"
+ :: "r"(&b[i]), "r"(&ref[i])
+ : "memory"
+ );
+ }
+ snow_horizontal_compose_liftS_lead_out(i, b, b, ref, width, w_l);
+ }
+
+ { // Lift 3
+ DWTELEM * const src = b+w2;
+ i = 0;
+
+ for(; i<w_r-3; i+=4){
+ asm volatile(
+ "movq 4(%1), %%mm2 \n\t"
+ "movq 12(%1), %%mm6 \n\t"
+ "paddd (%1), %%mm2 \n\t"
+ "paddd 8(%1), %%mm6 \n\t"
+ "movq %%mm2, %%mm0 \n\t"
+ "movq %%mm6, %%mm4 \n\t"
+ "pslld $2, %%mm2 \n\t"
+ "pslld $2, %%mm6 \n\t"
+ "psubd %%mm2, %%mm0 \n\t"
+ "psubd %%mm6, %%mm4 \n\t"
+ "psrad $1, %%mm0 \n\t"
+ "psrad $1, %%mm4 \n\t"
+ "movq (%0), %%mm2 \n\t"
+ "movq 8(%0), %%mm6 \n\t"
+ "psubd %%mm0, %%mm2 \n\t"
+ "psubd %%mm4, %%mm6 \n\t"
+ "movq %%mm2, (%2) \n\t"
+ "movq %%mm6, 8(%2) \n\t"
+ :: "r"(&src[i]), "r"(&b[i]), "r"(&temp[i])
+ : "memory"
+ );
+ }
+ snow_horizontal_compose_lift_lead_out(i, temp, src, b, width, w_r, 1, -W_AM, W_AO, W_AS);
+ }
+
+ {
+ snow_interleave_line_header(&i, width, b, temp);
+
+ for (; (i & 0xE) != 0xE; i-=2){
+ b[i+1] = temp[i>>1];
+ b[i] = b[i>>1];
+ }
+ for (i-=14; i>=0; i-=16){
+ asm volatile(
+ "movq (%1), %%mm0 \n\t"
+ "movq 8(%1), %%mm2 \n\t"
+ "movq 16(%1), %%mm4 \n\t"
+ "movq 24(%1), %%mm6 \n\t"
+ "movq (%1), %%mm1 \n\t"
+ "movq 8(%1), %%mm3 \n\t"
+ "movq 16(%1), %%mm5 \n\t"
+ "movq 24(%1), %%mm7 \n\t"
+ "punpckldq (%2), %%mm0 \n\t"
+ "punpckldq 8(%2), %%mm2 \n\t"
+ "punpckldq 16(%2), %%mm4 \n\t"
+ "punpckldq 24(%2), %%mm6 \n\t"
+ "movq %%mm0, (%0) \n\t"
+ "movq %%mm2, 16(%0) \n\t"
+ "movq %%mm4, 32(%0) \n\t"
+ "movq %%mm6, 48(%0) \n\t"
+ "punpckhdq (%2), %%mm1 \n\t"
+ "punpckhdq 8(%2), %%mm3 \n\t"
+ "punpckhdq 16(%2), %%mm5 \n\t"
+ "punpckhdq 24(%2), %%mm7 \n\t"
+ "movq %%mm1, 8(%0) \n\t"
+ "movq %%mm3, 24(%0) \n\t"
+ "movq %%mm5, 40(%0) \n\t"
+ "movq %%mm7, 56(%0) \n\t"
+ :: "r"(&b[i]), "r"(&b[i>>1]), "r"(&temp[i>>1])
+ : "memory"
+ );
+ }
+ }
+}
+
+#define snow_vertical_compose_sse2_load_add(op,r,t0,t1,t2,t3)\
+ ""op" (%%"r",%%"REG_d",4), %%"t0" \n\t"\
+ ""op" 16(%%"r",%%"REG_d",4), %%"t1" \n\t"\
+ ""op" 32(%%"r",%%"REG_d",4), %%"t2" \n\t"\
+ ""op" 48(%%"r",%%"REG_d",4), %%"t3" \n\t"
+
+#define snow_vertical_compose_sse2_load(r,t0,t1,t2,t3)\
+ snow_vertical_compose_sse2_load_add("movdqa",r,t0,t1,t2,t3)
+
+#define snow_vertical_compose_sse2_add(r,t0,t1,t2,t3)\
+ snow_vertical_compose_sse2_load_add("paddd",r,t0,t1,t2,t3)
+
+#define snow_vertical_compose_sse2_sub(s0,s1,s2,s3,t0,t1,t2,t3)\
+ "psubd %%"s0", %%"t0" \n\t"\
+ "psubd %%"s1", %%"t1" \n\t"\
+ "psubd %%"s2", %%"t2" \n\t"\
+ "psubd %%"s3", %%"t3" \n\t"
+
+#define snow_vertical_compose_sse2_store(w,s0,s1,s2,s3)\
+ "movdqa %%"s0", (%%"w",%%"REG_d",4) \n\t"\
+ "movdqa %%"s1", 16(%%"w",%%"REG_d",4) \n\t"\
+ "movdqa %%"s2", 32(%%"w",%%"REG_d",4) \n\t"\
+ "movdqa %%"s3", 48(%%"w",%%"REG_d",4) \n\t"
+
+#define snow_vertical_compose_sse2_sra(n,t0,t1,t2,t3)\
+ "psrad $"n", %%"t0" \n\t"\
+ "psrad $"n", %%"t1" \n\t"\
+ "psrad $"n", %%"t2" \n\t"\
+ "psrad $"n", %%"t3" \n\t"
+
+#define snow_vertical_compose_sse2_r2r_add(s0,s1,s2,s3,t0,t1,t2,t3)\
+ "paddd %%"s0", %%"t0" \n\t"\
+ "paddd %%"s1", %%"t1" \n\t"\
+ "paddd %%"s2", %%"t2" \n\t"\
+ "paddd %%"s3", %%"t3" \n\t"
+
+#define snow_vertical_compose_sse2_sll(n,t0,t1,t2,t3)\
+ "pslld $"n", %%"t0" \n\t"\
+ "pslld $"n", %%"t1" \n\t"\
+ "pslld $"n", %%"t2" \n\t"\
+ "pslld $"n", %%"t3" \n\t"
+
+#define snow_vertical_compose_sse2_move(s0,s1,s2,s3,t0,t1,t2,t3)\
+ "movdqa %%"s0", %%"t0" \n\t"\
+ "movdqa %%"s1", %%"t1" \n\t"\
+ "movdqa %%"s2", %%"t2" \n\t"\
+ "movdqa %%"s3", %%"t3" \n\t"
+
+void ff_snow_vertical_compose97i_sse2(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWTELEM *b3, DWTELEM *b4, DWTELEM *b5, int width){
+ long i = width;
+
+ while(i & 0xF)
+ {
+ i--;
+ b4[i] -= (W_DM*(b3[i] + b5[i])+W_DO)>>W_DS;
+ b3[i] -= (W_CM*(b2[i] + b4[i])+W_CO)>>W_CS;
+ b2[i] += (W_BM*(b1[i] + b3[i])+4*b2[i]+W_BO)>>W_BS;
+ b1[i] += (W_AM*(b0[i] + b2[i])+W_AO)>>W_AS;
+ }
+
+ asm volatile (
+ "jmp 2f \n\t"
+ "1: \n\t"
+
+ "mov %6, %%"REG_a" \n\t"
+ "mov %4, %%"REG_S" \n\t"
+
+ snow_vertical_compose_sse2_load(REG_S,"xmm0","xmm2","xmm4","xmm6")
+ snow_vertical_compose_sse2_add(REG_a,"xmm0","xmm2","xmm4","xmm6")
+ snow_vertical_compose_sse2_move("xmm0","xmm2","xmm4","xmm6","xmm1","xmm3","xmm5","xmm7")
+ snow_vertical_compose_sse2_sll("1","xmm0","xmm2","xmm4","xmm6")\
+ snow_vertical_compose_sse2_r2r_add("xmm1","xmm3","xmm5","xmm7","xmm0","xmm2","xmm4","xmm6")
+
+ "pcmpeqd %%xmm1, %%xmm1 \n\t"
+ "pslld $31, %%xmm1 \n\t"
+ "psrld $29, %%xmm1 \n\t"
+ "mov %5, %%"REG_a" \n\t"
+
+ snow_vertical_compose_sse2_r2r_add("xmm1","xmm1","xmm1","xmm1","xmm0","xmm2","xmm4","xmm6")
+ snow_vertical_compose_sse2_sra("3","xmm0","xmm2","xmm4","xmm6")
+ snow_vertical_compose_sse2_load(REG_a,"xmm1","xmm3","xmm5","xmm7")
+ snow_vertical_compose_sse2_sub("xmm0","xmm2","xmm4","xmm6","xmm1","xmm3","xmm5","xmm7")
+ snow_vertical_compose_sse2_store(REG_a,"xmm1","xmm3","xmm5","xmm7")
+ "mov %3, %%"REG_c" \n\t"
+ snow_vertical_compose_sse2_load(REG_S,"xmm0","xmm2","xmm4","xmm6")
+ snow_vertical_compose_sse2_add(REG_c,"xmm1","xmm3","xmm5","xmm7")
+ snow_vertical_compose_sse2_sub("xmm1","xmm3","xmm5","xmm7","xmm0","xmm2","xmm4","xmm6")
+ snow_vertical_compose_sse2_store(REG_S,"xmm0","xmm2","xmm4","xmm6")
+ "mov %2, %%"REG_a" \n\t"
+ snow_vertical_compose_sse2_load(REG_c,"xmm1","xmm3","xmm5","xmm7")
+ snow_vertical_compose_sse2_add(REG_a,"xmm0","xmm2","xmm4","xmm6")
+ snow_vertical_compose_sse2_sll("2","xmm1","xmm3","xmm5","xmm7")\
+ snow_vertical_compose_sse2_r2r_add("xmm1","xmm3","xmm5","xmm7","xmm0","xmm2","xmm4","xmm6")
+
+ "pcmpeqd %%xmm1, %%xmm1 \n\t"
+ "pslld $31, %%xmm1 \n\t"
+ "psrld $28, %%xmm1 \n\t"
+ "mov %1, %%"REG_S" \n\t"
+
+ snow_vertical_compose_sse2_r2r_add("xmm1","xmm1","xmm1","xmm1","xmm0","xmm2","xmm4","xmm6")
+ snow_vertical_compose_sse2_sra("4","xmm0","xmm2","xmm4","xmm6")
+ snow_vertical_compose_sse2_add(REG_c,"xmm0","xmm2","xmm4","xmm6")
+ snow_vertical_compose_sse2_store(REG_c,"xmm0","xmm2","xmm4","xmm6")
+ snow_vertical_compose_sse2_add(REG_S,"xmm0","xmm2","xmm4","xmm6")
+ snow_vertical_compose_sse2_move("xmm0","xmm2","xmm4","xmm6","xmm1","xmm3","xmm5","xmm7")
+ snow_vertical_compose_sse2_sll("1","xmm0","xmm2","xmm4","xmm6")\
+ snow_vertical_compose_sse2_r2r_add("xmm1","xmm3","xmm5","xmm7","xmm0","xmm2","xmm4","xmm6")
+ snow_vertical_compose_sse2_sra("1","xmm0","xmm2","xmm4","xmm6")
+ snow_vertical_compose_sse2_add(REG_a,"xmm0","xmm2","xmm4","xmm6")
+ snow_vertical_compose_sse2_store(REG_a,"xmm0","xmm2","xmm4","xmm6")
+
+ "2: \n\t"
+ "sub $16, %%"REG_d" \n\t"
+ "jge 1b \n\t"
+ :"+d"(i)
+ :
+ "m"(b0),"m"(b1),"m"(b2),"m"(b3),"m"(b4),"m"(b5):
+ "%"REG_a"","%"REG_S"","%"REG_c"");
+}
+
+#define snow_vertical_compose_mmx_load_add(op,r,t0,t1,t2,t3)\
+ ""op" (%%"r",%%"REG_d",4), %%"t0" \n\t"\
+ ""op" 8(%%"r",%%"REG_d",4), %%"t1" \n\t"\
+ ""op" 16(%%"r",%%"REG_d",4), %%"t2" \n\t"\
+ ""op" 24(%%"r",%%"REG_d",4), %%"t3" \n\t"
+
+#define snow_vertical_compose_mmx_load(r,t0,t1,t2,t3)\
+ snow_vertical_compose_mmx_load_add("movq",r,t0,t1,t2,t3)
+
+#define snow_vertical_compose_mmx_add(r,t0,t1,t2,t3)\
+ snow_vertical_compose_mmx_load_add("paddd",r,t0,t1,t2,t3)
+
+#define snow_vertical_compose_mmx_sub(s0,s1,s2,s3,t0,t1,t2,t3)\
+ snow_vertical_compose_sse2_sub(s0,s1,s2,s3,t0,t1,t2,t3)
+
+#define snow_vertical_compose_mmx_store(w,s0,s1,s2,s3)\
+ "movq %%"s0", (%%"w",%%"REG_d",4) \n\t"\
+ "movq %%"s1", 8(%%"w",%%"REG_d",4) \n\t"\
+ "movq %%"s2", 16(%%"w",%%"REG_d",4) \n\t"\
+ "movq %%"s3", 24(%%"w",%%"REG_d",4) \n\t"
+
+#define snow_vertical_compose_mmx_sra(n,t0,t1,t2,t3)\
+ snow_vertical_compose_sse2_sra(n,t0,t1,t2,t3)
+
+#define snow_vertical_compose_mmx_r2r_add(s0,s1,s2,s3,t0,t1,t2,t3)\
+ snow_vertical_compose_sse2_r2r_add(s0,s1,s2,s3,t0,t1,t2,t3)
+
+#define snow_vertical_compose_mmx_sll(n,t0,t1,t2,t3)\
+ snow_vertical_compose_sse2_sll(n,t0,t1,t2,t3)
+
+#define snow_vertical_compose_mmx_move(s0,s1,s2,s3,t0,t1,t2,t3)\
+ "movq %%"s0", %%"t0" \n\t"\
+ "movq %%"s1", %%"t1" \n\t"\
+ "movq %%"s2", %%"t2" \n\t"\
+ "movq %%"s3", %%"t3" \n\t"
+
+void ff_snow_vertical_compose97i_mmx(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWTELEM *b3, DWTELEM *b4, DWTELEM *b5, int width){
+ long i = width;
+ while(i & 0x7)
+ {
+ i--;
+ b4[i] -= (W_DM*(b3[i] + b5[i])+W_DO)>>W_DS;
+ b3[i] -= (W_CM*(b2[i] + b4[i])+W_CO)>>W_CS;
+ b2[i] += (W_BM*(b1[i] + b3[i])+4*b2[i]+W_BO)>>W_BS;
+ b1[i] += (W_AM*(b0[i] + b2[i])+W_AO)>>W_AS;
+ }
+
+ asm volatile(
+ "jmp 2f \n\t"
+ "1: \n\t"
+
+ "mov %6, %%"REG_a" \n\t"
+ "mov %4, %%"REG_S" \n\t"
+
+ snow_vertical_compose_mmx_load(REG_S,"mm0","mm2","mm4","mm6")
+ snow_vertical_compose_mmx_add(REG_a,"mm0","mm2","mm4","mm6")
+ snow_vertical_compose_mmx_move("mm0","mm2","mm4","mm6","mm1","mm3","mm5","mm7")
+ snow_vertical_compose_mmx_sll("1","mm0","mm2","mm4","mm6")
+ snow_vertical_compose_mmx_r2r_add("mm1","mm3","mm5","mm7","mm0","mm2","mm4","mm6")
+
+ "pcmpeqd %%mm1, %%mm1 \n\t"
+ "pslld $31, %%mm1 \n\t"
+ "psrld $29, %%mm1 \n\t"
+ "mov %5, %%"REG_a" \n\t"
+
+ snow_vertical_compose_mmx_r2r_add("mm1","mm1","mm1","mm1","mm0","mm2","mm4","mm6")
+ snow_vertical_compose_mmx_sra("3","mm0","mm2","mm4","mm6")
+ snow_vertical_compose_mmx_load(REG_a,"mm1","mm3","mm5","mm7")
+ snow_vertical_compose_mmx_sub("mm0","mm2","mm4","mm6","mm1","mm3","mm5","mm7")
+ snow_vertical_compose_mmx_store(REG_a,"mm1","mm3","mm5","mm7")
+ "mov %3, %%"REG_c" \n\t"
+ snow_vertical_compose_mmx_load(REG_S,"mm0","mm2","mm4","mm6")
+ snow_vertical_compose_mmx_add(REG_c,"mm1","mm3","mm5","mm7")
+ snow_vertical_compose_mmx_sub("mm1","mm3","mm5","mm7","mm0","mm2","mm4","mm6")
+ snow_vertical_compose_mmx_store(REG_S,"mm0","mm2","mm4","mm6")
+ "mov %2, %%"REG_a" \n\t"
+ snow_vertical_compose_mmx_load(REG_c,"mm1","mm3","mm5","mm7")
+ snow_vertical_compose_mmx_add(REG_a,"mm0","mm2","mm4","mm6")
+ snow_vertical_compose_mmx_sll("2","mm1","mm3","mm5","mm7")
+ snow_vertical_compose_mmx_r2r_add("mm1","mm3","mm5","mm7","mm0","mm2","mm4","mm6")
+
+ "pcmpeqd %%mm1, %%mm1 \n\t"
+ "pslld $31, %%mm1 \n\t"
+ "psrld $28, %%mm1 \n\t"
+ "mov %1, %%"REG_S" \n\t"
+
+ snow_vertical_compose_mmx_r2r_add("mm1","mm1","mm1","mm1","mm0","mm2","mm4","mm6")
+ snow_vertical_compose_mmx_sra("4","mm0","mm2","mm4","mm6")
+ snow_vertical_compose_mmx_add(REG_c,"mm0","mm2","mm4","mm6")
+ snow_vertical_compose_mmx_store(REG_c,"mm0","mm2","mm4","mm6")
+ snow_vertical_compose_mmx_add(REG_S,"mm0","mm2","mm4","mm6")
+ snow_vertical_compose_mmx_move("mm0","mm2","mm4","mm6","mm1","mm3","mm5","mm7")
+ snow_vertical_compose_mmx_sll("1","mm0","mm2","mm4","mm6")
+ snow_vertical_compose_mmx_r2r_add("mm1","mm3","mm5","mm7","mm0","mm2","mm4","mm6")
+ snow_vertical_compose_mmx_sra("1","mm0","mm2","mm4","mm6")
+ snow_vertical_compose_mmx_add(REG_a,"mm0","mm2","mm4","mm6")
+ snow_vertical_compose_mmx_store(REG_a,"mm0","mm2","mm4","mm6")
+
+ "2: \n\t"
+ "sub $8, %%"REG_d" \n\t"
+ "jge 1b \n\t"
+ :"+d"(i)
+ :
+ "m"(b0),"m"(b1),"m"(b2),"m"(b3),"m"(b4),"m"(b5):
+ "%"REG_a"","%"REG_S"","%"REG_c"");
+}
+
+#define snow_inner_add_yblock_sse2_header \
+ DWTELEM * * dst_array = sb->line + src_y;\
+ long tmp;\
+ asm volatile(\
+ "mov %7, %%"REG_c" \n\t"\
+ "mov %6, %2 \n\t"\
+ "mov %4, %%"REG_S" \n\t"\
+ "pxor %%xmm7, %%xmm7 \n\t" /* 0 */\
+ "pcmpeqd %%xmm3, %%xmm3 \n\t"\
+ "pslld $31, %%xmm3 \n\t"\
+ "psrld $24, %%xmm3 \n\t" /* FRAC_BITS >> 1 */\
+ "1: \n\t"\
+ "mov %1, %%"REG_D" \n\t"\
+ "mov (%%"REG_D"), %%"REG_D" \n\t"\
+ "add %3, %%"REG_D" \n\t"
+
+#define snow_inner_add_yblock_sse2_start_8(out_reg1, out_reg2, ptr_offset, s_offset)\
+ "mov "PTR_SIZE"*"ptr_offset"(%%"REG_a"), %%"REG_d"; \n\t"\
+ "movq (%%"REG_d"), %%"out_reg1" \n\t"\
+ "movq (%%"REG_d", %%"REG_c"), %%"out_reg2" \n\t"\
+ "punpcklbw %%xmm7, %%"out_reg1" \n\t"\
+ "punpcklbw %%xmm7, %%"out_reg2" \n\t"\
+ "movq "s_offset"(%%"REG_S"), %%xmm0 \n\t"\
+ "movq "s_offset"+16(%%"REG_S"), %%xmm4 \n\t"\
+ "punpcklbw %%xmm7, %%xmm0 \n\t"\
+ "punpcklbw %%xmm7, %%xmm4 \n\t"\
+ "pmullw %%xmm0, %%"out_reg1" \n\t"\
+ "pmullw %%xmm4, %%"out_reg2" \n\t"
+
+#define snow_inner_add_yblock_sse2_start_16(out_reg1, out_reg2, ptr_offset, s_offset)\
+ "mov "PTR_SIZE"*"ptr_offset"(%%"REG_a"), %%"REG_d"; \n\t"\
+ "movq (%%"REG_d"), %%"out_reg1" \n\t"\
+ "movq 8(%%"REG_d"), %%"out_reg2" \n\t"\
+ "punpcklbw %%xmm7, %%"out_reg1" \n\t"\
+ "punpcklbw %%xmm7, %%"out_reg2" \n\t"\
+ "movq "s_offset"(%%"REG_S"), %%xmm0 \n\t"\
+ "movq "s_offset"+8(%%"REG_S"), %%xmm4 \n\t"\
+ "punpcklbw %%xmm7, %%xmm0 \n\t"\
+ "punpcklbw %%xmm7, %%xmm4 \n\t"\
+ "pmullw %%xmm0, %%"out_reg1" \n\t"\
+ "pmullw %%xmm4, %%"out_reg2" \n\t"
+
+#define snow_inner_add_yblock_sse2_accum_8(ptr_offset, s_offset) \
+ snow_inner_add_yblock_sse2_start_8("xmm2", "xmm6", ptr_offset, s_offset)\
+ "paddusw %%xmm2, %%xmm1 \n\t"\
+ "paddusw %%xmm6, %%xmm5 \n\t"
+
+#define snow_inner_add_yblock_sse2_accum_16(ptr_offset, s_offset) \
+ snow_inner_add_yblock_sse2_start_16("xmm2", "xmm6", ptr_offset, s_offset)\
+ "paddusw %%xmm2, %%xmm1 \n\t"\
+ "paddusw %%xmm6, %%xmm5 \n\t"
+
+#define snow_inner_add_yblock_sse2_end_common1\
+ "add $32, %%"REG_S" \n\t"\
+ "add %%"REG_c", %0 \n\t"\
+ "add %%"REG_c", "PTR_SIZE"*3(%%"REG_a");\n\t"\
+ "add %%"REG_c", "PTR_SIZE"*2(%%"REG_a");\n\t"\
+ "add %%"REG_c", "PTR_SIZE"*1(%%"REG_a");\n\t"\
+ "add %%"REG_c", (%%"REG_a") \n\t"
+
+#define snow_inner_add_yblock_sse2_end_common2\
+ "jnz 1b \n\t"\
+ :"+m"(dst8),"+m"(dst_array),"=&r"(tmp)\
+ :\
+ "rm"((long)(src_x<<2)),"m"(obmc),"a"(block),"m"((long)b_h),"m"((long)src_stride):\
+ "%"REG_c"","%"REG_S"","%"REG_D"","%"REG_d"");
+
+#define snow_inner_add_yblock_sse2_end_8\
+ "sal $1, %%"REG_c" \n\t"\
+ "add $"PTR_SIZE"*2, %1 \n\t"\
+ snow_inner_add_yblock_sse2_end_common1\
+ "sar $1, %%"REG_c" \n\t"\
+ "sub $2, %2 \n\t"\
+ snow_inner_add_yblock_sse2_end_common2
+
+#define snow_inner_add_yblock_sse2_end_16\
+ "add $"PTR_SIZE"*1, %1 \n\t"\
+ snow_inner_add_yblock_sse2_end_common1\
+ "dec %2 \n\t"\
+ snow_inner_add_yblock_sse2_end_common2
+
+static void inner_add_yblock_bw_8_obmc_16_bh_even_sse2(const uint8_t *obmc, const long obmc_stride, uint8_t * * block, int b_w, long b_h,
+ int src_x, int src_y, long src_stride, slice_buffer * sb, int add, uint8_t * dst8){
+snow_inner_add_yblock_sse2_header
+snow_inner_add_yblock_sse2_start_8("xmm1", "xmm5", "3", "0")
+snow_inner_add_yblock_sse2_accum_8("2", "8")
+snow_inner_add_yblock_sse2_accum_8("1", "128")
+snow_inner_add_yblock_sse2_accum_8("0", "136")
+
+ "mov %0, %%"REG_d" \n\t"
+ "movdqa (%%"REG_D"), %%xmm0 \n\t"
+ "movdqa %%xmm1, %%xmm2 \n\t"
+
+ "punpckhwd %%xmm7, %%xmm1 \n\t"
+ "punpcklwd %%xmm7, %%xmm2 \n\t"
+ "paddd %%xmm2, %%xmm0 \n\t"
+ "movdqa 16(%%"REG_D"), %%xmm2 \n\t"
+ "paddd %%xmm1, %%xmm2 \n\t"
+ "paddd %%xmm3, %%xmm0 \n\t"
+ "paddd %%xmm3, %%xmm2 \n\t"
+
+ "mov %1, %%"REG_D" \n\t"
+ "mov "PTR_SIZE"(%%"REG_D"), %%"REG_D";\n\t"
+ "add %3, %%"REG_D" \n\t"
+
+ "movdqa (%%"REG_D"), %%xmm4 \n\t"
+ "movdqa %%xmm5, %%xmm6 \n\t"
+ "punpckhwd %%xmm7, %%xmm5 \n\t"
+ "punpcklwd %%xmm7, %%xmm6 \n\t"
+ "paddd %%xmm6, %%xmm4 \n\t"
+ "movdqa 16(%%"REG_D"), %%xmm6 \n\t"
+ "paddd %%xmm5, %%xmm6 \n\t"
+ "paddd %%xmm3, %%xmm4 \n\t"
+ "paddd %%xmm3, %%xmm6 \n\t"
+
+ "psrad $8, %%xmm0 \n\t" /* FRAC_BITS. */
+ "psrad $8, %%xmm2 \n\t" /* FRAC_BITS. */
+ "packssdw %%xmm2, %%xmm0 \n\t"
+ "packuswb %%xmm7, %%xmm0 \n\t"
+ "movq %%xmm0, (%%"REG_d") \n\t"
+
+ "psrad $8, %%xmm4 \n\t" /* FRAC_BITS. */
+ "psrad $8, %%xmm6 \n\t" /* FRAC_BITS. */
+ "packssdw %%xmm6, %%xmm4 \n\t"
+ "packuswb %%xmm7, %%xmm4 \n\t"
+ "movq %%xmm4, (%%"REG_d",%%"REG_c");\n\t"
+snow_inner_add_yblock_sse2_end_8
+}
+
+static void inner_add_yblock_bw_16_obmc_32_sse2(const uint8_t *obmc, const long obmc_stride, uint8_t * * block, int b_w, long b_h,
+ int src_x, int src_y, long src_stride, slice_buffer * sb, int add, uint8_t * dst8){
+snow_inner_add_yblock_sse2_header
+snow_inner_add_yblock_sse2_start_16("xmm1", "xmm5", "3", "0")
+snow_inner_add_yblock_sse2_accum_16("2", "16")
+snow_inner_add_yblock_sse2_accum_16("1", "512")
+snow_inner_add_yblock_sse2_accum_16("0", "528")
+
+ "mov %0, %%"REG_d" \n\t"
+ "movdqa %%xmm1, %%xmm0 \n\t"
+ "movdqa %%xmm5, %%xmm4 \n\t"
+ "punpcklwd %%xmm7, %%xmm0 \n\t"
+ "paddd (%%"REG_D"), %%xmm0 \n\t"
+ "punpckhwd %%xmm7, %%xmm1 \n\t"
+ "paddd 16(%%"REG_D"), %%xmm1 \n\t"
+ "punpcklwd %%xmm7, %%xmm4 \n\t"
+ "paddd 32(%%"REG_D"), %%xmm4 \n\t"
+ "punpckhwd %%xmm7, %%xmm5 \n\t"
+ "paddd 48(%%"REG_D"), %%xmm5 \n\t"
+ "paddd %%xmm3, %%xmm0 \n\t"
+ "paddd %%xmm3, %%xmm1 \n\t"
+ "paddd %%xmm3, %%xmm4 \n\t"
+ "paddd %%xmm3, %%xmm5 \n\t"
+ "psrad $8, %%xmm0 \n\t" /* FRAC_BITS. */
+ "psrad $8, %%xmm1 \n\t" /* FRAC_BITS. */
+ "psrad $8, %%xmm4 \n\t" /* FRAC_BITS. */
+ "psrad $8, %%xmm5 \n\t" /* FRAC_BITS. */
+
+ "packssdw %%xmm1, %%xmm0 \n\t"
+ "packssdw %%xmm5, %%xmm4 \n\t"
+ "packuswb %%xmm4, %%xmm0 \n\t"
+
+ "movdqu %%xmm0, (%%"REG_d") \n\t"
+
+snow_inner_add_yblock_sse2_end_16
+}
+
+#define snow_inner_add_yblock_mmx_header \
+ DWTELEM * * dst_array = sb->line + src_y;\
+ long tmp;\
+ asm volatile(\
+ "mov %7, %%"REG_c" \n\t"\
+ "mov %6, %2 \n\t"\
+ "mov %4, %%"REG_S" \n\t"\
+ "pxor %%mm7, %%mm7 \n\t" /* 0 */\
+ "pcmpeqd %%mm3, %%mm3 \n\t"\
+ "pslld $31, %%mm3 \n\t"\
+ "psrld $24, %%mm3 \n\t" /* FRAC_BITS >> 1 */\
+ "1: \n\t"\
+ "mov %1, %%"REG_D" \n\t"\
+ "mov (%%"REG_D"), %%"REG_D" \n\t"\
+ "add %3, %%"REG_D" \n\t"
+
+#define snow_inner_add_yblock_mmx_start(out_reg1, out_reg2, ptr_offset, s_offset, d_offset)\
+ "mov "PTR_SIZE"*"ptr_offset"(%%"REG_a"), %%"REG_d"; \n\t"\
+ "movd "d_offset"(%%"REG_d"), %%"out_reg1" \n\t"\
+ "movd "d_offset"+4(%%"REG_d"), %%"out_reg2" \n\t"\
+ "punpcklbw %%mm7, %%"out_reg1" \n\t"\
+ "punpcklbw %%mm7, %%"out_reg2" \n\t"\
+ "movd "s_offset"(%%"REG_S"), %%mm0 \n\t"\
+ "movd "s_offset"+4(%%"REG_S"), %%mm4 \n\t"\
+ "punpcklbw %%mm7, %%mm0 \n\t"\
+ "punpcklbw %%mm7, %%mm4 \n\t"\
+ "pmullw %%mm0, %%"out_reg1" \n\t"\
+ "pmullw %%mm4, %%"out_reg2" \n\t"
+
+#define snow_inner_add_yblock_mmx_accum(ptr_offset, s_offset, d_offset) \
+ snow_inner_add_yblock_mmx_start("mm2", "mm6", ptr_offset, s_offset, d_offset)\
+ "paddusw %%mm2, %%mm1 \n\t"\
+ "paddusw %%mm6, %%mm5 \n\t"
+
+#define snow_inner_add_yblock_mmx_mix(read_offset, write_offset)\
+ "mov %0, %%"REG_d" \n\t"\
+ "movq %%mm1, %%mm0 \n\t"\
+ "movq %%mm5, %%mm4 \n\t"\
+ "punpcklwd %%mm7, %%mm0 \n\t"\
+ "paddd "read_offset"(%%"REG_D"), %%mm0 \n\t"\
+ "punpckhwd %%mm7, %%mm1 \n\t"\
+ "paddd "read_offset"+8(%%"REG_D"), %%mm1 \n\t"\
+ "punpcklwd %%mm7, %%mm4 \n\t"\
+ "paddd "read_offset"+16(%%"REG_D"), %%mm4 \n\t"\
+ "punpckhwd %%mm7, %%mm5 \n\t"\
+ "paddd "read_offset"+24(%%"REG_D"), %%mm5 \n\t"\
+ "paddd %%mm3, %%mm0 \n\t"\
+ "paddd %%mm3, %%mm1 \n\t"\
+ "paddd %%mm3, %%mm4 \n\t"\
+ "paddd %%mm3, %%mm5 \n\t"\
+ "psrad $8, %%mm0 \n\t"\
+ "psrad $8, %%mm1 \n\t"\
+ "psrad $8, %%mm4 \n\t"\
+ "psrad $8, %%mm5 \n\t"\
+\
+ "packssdw %%mm1, %%mm0 \n\t"\
+ "packssdw %%mm5, %%mm4 \n\t"\
+ "packuswb %%mm4, %%mm0 \n\t"\
+ "movq %%mm0, "write_offset"(%%"REG_d") \n\t"
+
+#define snow_inner_add_yblock_mmx_end(s_step)\
+ "add $"s_step", %%"REG_S" \n\t"\
+ "add %%"REG_c", "PTR_SIZE"*3(%%"REG_a");\n\t"\
+ "add %%"REG_c", "PTR_SIZE"*2(%%"REG_a");\n\t"\
+ "add %%"REG_c", "PTR_SIZE"*1(%%"REG_a");\n\t"\
+ "add %%"REG_c", (%%"REG_a") \n\t"\
+ "add $"PTR_SIZE"*1, %1 \n\t"\
+ "add %%"REG_c", %0 \n\t"\
+ "dec %2 \n\t"\
+ "jnz 1b \n\t"\
+ :"+m"(dst8),"+m"(dst_array),"=&r"(tmp)\
+ :\
+ "rm"((long)(src_x<<2)),"m"(obmc),"a"(block),"m"((long)b_h),"m"((long)src_stride):\
+ "%"REG_c"","%"REG_S"","%"REG_D"","%"REG_d"");
+
+static void inner_add_yblock_bw_8_obmc_16_mmx(const uint8_t *obmc, const long obmc_stride, uint8_t * * block, int b_w, long b_h,
+ int src_x, int src_y, long src_stride, slice_buffer * sb, int add, uint8_t * dst8){
+snow_inner_add_yblock_mmx_header
+snow_inner_add_yblock_mmx_start("mm1", "mm5", "3", "0", "0")
+snow_inner_add_yblock_mmx_accum("2", "8", "0")
+snow_inner_add_yblock_mmx_accum("1", "128", "0")
+snow_inner_add_yblock_mmx_accum("0", "136", "0")
+snow_inner_add_yblock_mmx_mix("0", "0")
+snow_inner_add_yblock_mmx_end("16")
+}
+
+static void inner_add_yblock_bw_16_obmc_32_mmx(const uint8_t *obmc, const long obmc_stride, uint8_t * * block, int b_w, long b_h,
+ int src_x, int src_y, long src_stride, slice_buffer * sb, int add, uint8_t * dst8){
+snow_inner_add_yblock_mmx_header
+snow_inner_add_yblock_mmx_start("mm1", "mm5", "3", "0", "0")
+snow_inner_add_yblock_mmx_accum("2", "16", "0")
+snow_inner_add_yblock_mmx_accum("1", "512", "0")
+snow_inner_add_yblock_mmx_accum("0", "528", "0")
+snow_inner_add_yblock_mmx_mix("0", "0")
+
+snow_inner_add_yblock_mmx_start("mm1", "mm5", "3", "8", "8")
+snow_inner_add_yblock_mmx_accum("2", "24", "8")
+snow_inner_add_yblock_mmx_accum("1", "520", "8")
+snow_inner_add_yblock_mmx_accum("0", "536", "8")
+snow_inner_add_yblock_mmx_mix("32", "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,
+ 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_sse2(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8);
+ else if (b_w == 8 && obmc_stride == 16) {
+ if (!(b_h & 1))
+ inner_add_yblock_bw_8_obmc_16_bh_even_sse2(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8);
+ else
+ inner_add_yblock_bw_8_obmc_16_mmx(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8);
+ } 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_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);
+ else if (b_w == 8 && obmc_stride == 16)
+ inner_add_yblock_bw_8_obmc_16_mmx(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8);
+ else
+ ff_snow_inner_add_yblock(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8);
+}
diff --git a/src/libffmpeg/libavcodec/i386/vp3dsp_mmx.c b/contrib/ffmpeg/libavcodec/i386/vp3dsp_mmx.c
index f715dc803..f715dc803 100644
--- a/src/libffmpeg/libavcodec/i386/vp3dsp_mmx.c
+++ b/contrib/ffmpeg/libavcodec/i386/vp3dsp_mmx.c
diff --git a/src/libffmpeg/libavcodec/i386/vp3dsp_sse2.c b/contrib/ffmpeg/libavcodec/i386/vp3dsp_sse2.c
index bd2911d59..bd2911d59 100644
--- a/src/libffmpeg/libavcodec/i386/vp3dsp_sse2.c
+++ b/contrib/ffmpeg/libavcodec/i386/vp3dsp_sse2.c
diff --git a/src/libffmpeg/libavcodec/idcinvideo.c b/contrib/ffmpeg/libavcodec/idcinvideo.c
index 112da7bc6..112da7bc6 100644
--- a/src/libffmpeg/libavcodec/idcinvideo.c
+++ b/contrib/ffmpeg/libavcodec/idcinvideo.c
diff --git a/contrib/ffmpeg/libavcodec/imc.c b/contrib/ffmpeg/libavcodec/imc.c
new file mode 100644
index 000000000..6140130b1
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/imc.c
@@ -0,0 +1,813 @@
+/*
+ * IMC compatible decoder
+ * Copyright (c) 2002-2004 Maxim Poliakovski
+ * Copyright (c) 2006 Benjamin Larsson
+ * Copyright (c) 2006 Konstantin Shishkov
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * @file imc.c 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.
+ *
+ */
+
+
+#include <math.h>
+#include <stddef.h>
+#include <stdio.h>
+
+#define ALT_BITSTREAM_READER
+#include "avcodec.h"
+#include "bitstream.h"
+#include "dsputil.h"
+
+#include "imcdata.h"
+
+#define IMC_FRAME_ID 0x21
+#define BANDS 32
+#define COEFFS 256
+
+typedef struct {
+ float old_floor[BANDS];
+ float flcoeffs1[BANDS];
+ float flcoeffs2[BANDS];
+ float flcoeffs3[BANDS];
+ float flcoeffs4[BANDS];
+ float flcoeffs5[BANDS];
+ float flcoeffs6[BANDS];
+ float CWdecoded[COEFFS];
+
+ /** MDCT tables */
+ //@{
+ float mdct_sine_window[COEFFS];
+ float post_cos[COEFFS];
+ float post_sin[COEFFS];
+ float pre_coef1[COEFFS];
+ float pre_coef2[COEFFS];
+ float last_fft_im[COEFFS];
+ //@}
+
+ int bandWidthT[BANDS]; ///< codewords per band
+ int bitsBandT[BANDS]; ///< how many bits per codeword in band
+ int CWlengthT[COEFFS]; ///< how many bits in each codeword
+ int levlCoeffBuf[BANDS];
+ int bandFlagsBuf[BANDS]; ///< flags for each band
+ int sumLenArr[BANDS]; ///< bits for all coeffs in band
+ int skipFlagRaw[BANDS]; ///< skip flags are stored in raw form or not
+ int skipFlagBits[BANDS]; ///< bits used to code skip flags
+ int skipFlagCount[BANDS]; ///< skipped coeffients per band
+ int skipFlags[COEFFS]; ///< skip coefficient decoding or not
+ int codewords[COEFFS]; ///< raw codewords read from bitstream
+ float sqrt_tab[30];
+ GetBitContext gb;
+ VLC huffman_vlc[4][4];
+ int decoder_reset;
+ float one_div_log2;
+
+ DSPContext dsp;
+ FFTContext fft;
+ DECLARE_ALIGNED_16(FFTComplex, samples[COEFFS/2]);
+ DECLARE_ALIGNED_16(float, out_samples[COEFFS]);
+} IMCContext;
+
+
+static int imc_decode_init(AVCodecContext * avctx)
+{
+ int i, j;
+ IMCContext *q = avctx->priv_data;
+ double r1, r2;
+
+ q->decoder_reset = 1;
+
+ for(i = 0; i < BANDS; i++)
+ q->old_floor[i] = 1.0;
+
+ /* Build mdct window, a simple sine window normalized with sqrt(2) */
+ for(i = 0; i < COEFFS; i++)
+ q->mdct_sine_window[i] = sin((i + 0.5) / 512.0 * M_PI) * sqrt(2.0);
+ for(i = 0; i < COEFFS/2; i++){
+ q->post_cos[i] = cos(i / 256.0 * M_PI);
+ q->post_sin[i] = sin(i / 256.0 * M_PI);
+
+ r1 = sin((i * 4.0 + 1.0) / 1024.0 * M_PI);
+ r2 = cos((i * 4.0 + 1.0) / 1024.0 * M_PI);
+
+ if (i & 0x1)
+ {
+ q->pre_coef1[i] = (r1 + r2) * sqrt(2.0);
+ q->pre_coef2[i] = -(r1 - r2) * sqrt(2.0);
+ }
+ else
+ {
+ q->pre_coef1[i] = -(r1 + r2) * sqrt(2.0);
+ q->pre_coef2[i] = (r1 - r2) * sqrt(2.0);
+ }
+
+ q->last_fft_im[i] = 0;
+ }
+
+ /* Generate a square root table */
+
+ for(i = 0; i < 30; i++) {
+ q->sqrt_tab[i] = sqrt(i);
+ }
+
+ /* initialize the VLC tables */
+ for(i = 0; i < 4 ; i++) {
+ for(j = 0; j < 4; j++) {
+ init_vlc (&q->huffman_vlc[i][j], 9, imc_huffman_sizes[i],
+ imc_huffman_lens[i][j], 1, 1,
+ imc_huffman_bits[i][j], 2, 2, 1);
+ }
+ }
+ q->one_div_log2 = 1/log(2);
+
+ ff_fft_init(&q->fft, 7, 1);
+ dsputil_init(&q->dsp, avctx);
+ return 0;
+}
+
+static void imc_calculate_coeffs(IMCContext* q, float* flcoeffs1, float* flcoeffs2, int* bandWidthT,
+ float* flcoeffs3, float* flcoeffs5)
+{
+ float workT1[BANDS];
+ float workT2[BANDS];
+ float workT3[BANDS];
+ float snr_limit = 1.e-30;
+ float accum = 0.0;
+ int i, cnt2;
+
+ for(i = 0; i < BANDS; i++) {
+ flcoeffs5[i] = workT2[i] = 0.0;
+ if (bandWidthT[i]){
+ workT1[i] = flcoeffs1[i] * flcoeffs1[i];
+ flcoeffs3[i] = 2.0 * flcoeffs2[i];
+ } else {
+ workT1[i] = 0.0;
+ flcoeffs3[i] = -30000.0;
+ }
+ workT3[i] = bandWidthT[i] * workT1[i] * 0.01;
+ if (workT3[i] <= snr_limit)
+ workT3[i] = 0.0;
+ }
+
+ for(i = 0; i < BANDS; i++) {
+ for(cnt2 = i; cnt2 < cyclTab[i]; cnt2++)
+ flcoeffs5[cnt2] = flcoeffs5[cnt2] + workT3[i];
+ workT2[cnt2-1] = workT2[cnt2-1] + workT3[i];
+ }
+
+ for(i = 1; i < BANDS; i++) {
+ accum = (workT2[i-1] + accum) * imc_weights1[i-1];
+ flcoeffs5[i] += accum;
+ }
+
+ for(i = 0; i < BANDS; i++)
+ workT2[i] = 0.0;
+
+ for(i = 0; i < BANDS; i++) {
+ for(cnt2 = i-1; cnt2 > cyclTab2[i]; cnt2--)
+ flcoeffs5[cnt2] += workT3[i];
+ workT2[cnt2+1] += workT3[i];
+ }
+
+ accum = 0.0;
+
+ for(i = BANDS-2; i >= 0; i--) {
+ accum = (workT2[i+1] + accum) * imc_weights2[i];
+ flcoeffs5[i] += accum;
+ //there is missing code here, but it seems to never be triggered
+ }
+}
+
+
+static void imc_read_level_coeffs(IMCContext* q, int stream_format_code, int* levlCoeffs)
+{
+ int i;
+ VLC *hufftab[4];
+ int start = 0;
+ const uint8_t *cb_sel;
+ int s;
+
+ s = stream_format_code >> 1;
+ hufftab[0] = &q->huffman_vlc[s][0];
+ hufftab[1] = &q->huffman_vlc[s][1];
+ hufftab[2] = &q->huffman_vlc[s][2];
+ hufftab[3] = &q->huffman_vlc[s][3];
+ cb_sel = imc_cb_select[s];
+
+ if(stream_format_code & 4)
+ start = 1;
+ if(start)
+ levlCoeffs[0] = get_bits(&q->gb, 7);
+ for(i = start; i < BANDS; i++){
+ levlCoeffs[i] = get_vlc2(&q->gb, hufftab[cb_sel[i]]->table, hufftab[cb_sel[i]]->bits, 2);
+ if(levlCoeffs[i] == 17)
+ levlCoeffs[i] += get_bits(&q->gb, 4);
+ }
+}
+
+static void imc_decode_level_coefficients(IMCContext* q, int* levlCoeffBuf, float* flcoeffs1,
+ float* flcoeffs2)
+{
+ int i, level;
+ float tmp, tmp2;
+ //maybe some frequency division thingy
+
+ flcoeffs1[0] = 20000.0 / pow (2, levlCoeffBuf[0] * 0.18945); // 0.18945 = log2(10) * 0.05703125
+ flcoeffs2[0] = log(flcoeffs1[0])/log(2);
+ tmp = flcoeffs1[0];
+ tmp2 = flcoeffs2[0];
+
+ for(i = 1; i < BANDS; i++) {
+ level = levlCoeffBuf[i];
+ if (level == 16) {
+ flcoeffs1[i] = 1.0;
+ flcoeffs2[i] = 0.0;
+ } else {
+ if (level < 17)
+ level -=7;
+ else if (level <= 24)
+ level -=32;
+ else
+ level -=16;
+
+ tmp *= imc_exp_tab[15 + level];
+ tmp2 += 0.83048 * level; // 0.83048 = log2(10) * 0.25
+ flcoeffs1[i] = tmp;
+ flcoeffs2[i] = tmp2;
+ }
+ }
+}
+
+
+static void imc_decode_level_coefficients2(IMCContext* q, int* levlCoeffBuf, float* old_floor, float* flcoeffs1,
+ float* flcoeffs2) {
+ int i;
+ //FIXME maybe flag_buf = noise coding and flcoeffs1 = new scale factors
+ // and flcoeffs2 old scale factors
+ // might be incomplete due to a missing table that is in the binary code
+ for(i = 0; i < BANDS; i++) {
+ flcoeffs1[i] = 0;
+ if(levlCoeffBuf[i] < 16) {
+ flcoeffs1[i] = imc_exp_tab2[levlCoeffBuf[i]] * old_floor[i];
+ flcoeffs2[i] = (levlCoeffBuf[i]-7) * 0.83048 + flcoeffs2[i]; // 0.83048 = log2(10) * 0.25
+ } else {
+ flcoeffs1[i] = old_floor[i];
+ }
+ }
+}
+
+/**
+ * Perform bit allocation depending on bits available
+ */
+static int bit_allocation (IMCContext* q, int stream_format_code, int freebits, int flag) {
+ int i, j;
+ const float limit = -1.e20;
+ float highest = 0.0;
+ int indx;
+ int t1 = 0;
+ int t2 = 1;
+ float summa = 0.0;
+ int iacc = 0;
+ int summer = 0;
+ int rres, cwlen;
+ float lowest = 1.e10;
+ int low_indx = 0;
+ float workT[32];
+ int flg;
+ int found_indx = 0;
+
+ for(i = 0; i < BANDS; i++)
+ highest = FFMAX(highest, q->flcoeffs1[i]);
+
+ for(i = 0; i < BANDS-1; i++) {
+ q->flcoeffs4[i] = q->flcoeffs3[i] - log(q->flcoeffs5[i])/log(2);
+ }
+ q->flcoeffs4[BANDS - 1] = limit;
+
+ highest = highest * 0.25;
+
+ for(i = 0; i < BANDS; i++) {
+ indx = -1;
+ if ((band_tab[i+1] - band_tab[i]) == q->bandWidthT[i])
+ indx = 0;
+
+ if ((band_tab[i+1] - band_tab[i]) > q->bandWidthT[i])
+ indx = 1;
+
+ if (((band_tab[i+1] - band_tab[i])/2) >= q->bandWidthT[i])
+ indx = 2;
+
+ if (indx == -1)
+ return -1;
+
+ q->flcoeffs4[i] = q->flcoeffs4[i] + xTab[(indx*2 + (q->flcoeffs1[i] < highest)) * 2 + flag];
+ }
+
+ if (stream_format_code & 0x2) {
+ q->flcoeffs4[0] = limit;
+ q->flcoeffs4[1] = limit;
+ q->flcoeffs4[2] = limit;
+ q->flcoeffs4[3] = limit;
+ }
+
+ for(i = (stream_format_code & 0x2)?4:0; i < BANDS-1; i++) {
+ iacc += q->bandWidthT[i];
+ summa += q->bandWidthT[i] * q->flcoeffs4[i];
+ }
+ q->bandWidthT[BANDS-1] = 0;
+ summa = (summa * 0.5 - freebits) / iacc;
+
+
+ for(i = 0; i < BANDS/2; i++) {
+ rres = summer - freebits;
+ if((rres >= -8) && (rres <= 8)) break;
+
+ summer = 0;
+ iacc = 0;
+
+ for(j = (stream_format_code & 0x2)?4:0; j < BANDS; j++) {
+ cwlen = av_clip((int)((q->flcoeffs4[j] * 0.5) - summa + 0.5), 0, 6);
+
+ q->bitsBandT[j] = cwlen;
+ summer += q->bandWidthT[j] * cwlen;
+
+ if (cwlen > 0)
+ iacc += q->bandWidthT[j];
+ }
+
+ flg = t2;
+ t2 = 1;
+ if (freebits < summer)
+ t2 = -1;
+ if (i == 0)
+ flg = t2;
+ if(flg != t2)
+ t1++;
+
+ summa = (float)(summer - freebits) / ((t1 + 1) * iacc) + summa;
+ }
+
+ for(i = (stream_format_code & 0x2)?4:0; i < BANDS; i++) {
+ for(j = band_tab[i]; j < band_tab[i+1]; j++)
+ q->CWlengthT[j] = q->bitsBandT[i];
+ }
+
+ if (freebits > summer) {
+ for(i = 0; i < BANDS; i++) {
+ workT[i] = (q->bitsBandT[i] == 6) ? -1.e20 : (q->bitsBandT[i] * -2 + q->flcoeffs4[i] - 0.415);
+ }
+
+ highest = 0.0;
+
+ do{
+ if (highest <= -1.e20)
+ break;
+
+ found_indx = 0;
+ highest = -1.e20;
+
+ for(i = 0; i < BANDS; i++) {
+ if (workT[i] > highest) {
+ highest = workT[i];
+ found_indx = i;
+ }
+ }
+
+ if (highest > -1.e20) {
+ workT[found_indx] -= 2.0;
+ if (++(q->bitsBandT[found_indx]) == 6)
+ workT[found_indx] = -1.e20;
+
+ for(j = band_tab[found_indx]; j < band_tab[found_indx+1] && (freebits > summer); j++){
+ q->CWlengthT[j]++;
+ summer++;
+ }
+ }
+ }while (freebits > summer);
+ }
+ if (freebits < summer) {
+ for(i = 0; i < BANDS; i++) {
+ workT[i] = q->bitsBandT[i] ? (q->bitsBandT[i] * -2 + q->flcoeffs4[i] + 1.585) : 1.e20;
+ }
+ if (stream_format_code & 0x2) {
+ workT[0] = 1.e20;
+ workT[1] = 1.e20;
+ workT[2] = 1.e20;
+ workT[3] = 1.e20;
+ }
+ while (freebits < summer){
+ lowest = 1.e10;
+ low_indx = 0;
+ for(i = 0; i < BANDS; i++) {
+ if (workT[i] < lowest) {
+ lowest = workT[i];
+ low_indx = i;
+ }
+ }
+ //if(lowest >= 1.e10) break;
+ workT[low_indx] = lowest + 2.0;
+
+ if (!(--q->bitsBandT[low_indx]))
+ workT[low_indx] = 1.e20;
+
+ for(j = band_tab[low_indx]; j < band_tab[low_indx+1] && (freebits < summer); j++){
+ if(q->CWlengthT[j] > 0){
+ q->CWlengthT[j]--;
+ summer--;
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+static void imc_get_skip_coeff(IMCContext* q) {
+ int i, j;
+
+ memset(q->skipFlagBits, 0, sizeof(q->skipFlagBits));
+ memset(q->skipFlagCount, 0, sizeof(q->skipFlagCount));
+ for(i = 0; i < BANDS; i++) {
+ if (!q->bandFlagsBuf[i] || !q->bandWidthT[i])
+ continue;
+
+ if (!q->skipFlagRaw[i]) {
+ q->skipFlagBits[i] = band_tab[i+1] - band_tab[i];
+
+ for(j = band_tab[i]; j < band_tab[i+1]; j++) {
+ if ((q->skipFlags[j] = get_bits(&q->gb,1)))
+ q->skipFlagCount[i]++;
+ }
+ } else {
+ for(j = band_tab[i]; j < (band_tab[i+1]-1); j += 2) {
+ if(!get_bits1(&q->gb)){//0
+ q->skipFlagBits[i]++;
+ q->skipFlags[j]=1;
+ q->skipFlags[j+1]=1;
+ q->skipFlagCount[i] += 2;
+ }else{
+ if(get_bits1(&q->gb)){//11
+ q->skipFlagBits[i] +=2;
+ q->skipFlags[j]=0;
+ q->skipFlags[j+1]=1;
+ q->skipFlagCount[i]++;
+ }else{
+ q->skipFlagBits[i] +=3;
+ q->skipFlags[j+1]=0;
+ if(!get_bits1(&q->gb)){//100
+ q->skipFlags[j]=1;
+ q->skipFlagCount[i]++;
+ }else{//101
+ q->skipFlags[j]=0;
+ }
+ }
+ }
+ }
+
+ if (j < band_tab[i+1]) {
+ q->skipFlagBits[i]++;
+ if ((q->skipFlags[j] = get_bits(&q->gb,1)))
+ q->skipFlagCount[i]++;
+ }
+ }
+ }
+}
+
+/**
+ * Increase highest' band coefficient sizes as some bits won't be used
+ */
+static void imc_adjust_bit_allocation (IMCContext* q, int summer) {
+ float workT[32];
+ int corrected = 0;
+ int i, j;
+ float highest = 0;
+ int found_indx=0;
+
+ for(i = 0; i < BANDS; i++) {
+ workT[i] = (q->bitsBandT[i] == 6) ? -1.e20 : (q->bitsBandT[i] * -2 + q->flcoeffs4[i] - 0.415);
+ }
+
+ while (corrected < summer) {
+ if(highest <= -1.e20)
+ break;
+
+ highest = -1.e20;
+
+ for(i = 0; i < BANDS; i++) {
+ if (workT[i] > highest) {
+ highest = workT[i];
+ found_indx = i;
+ }
+ }
+
+ if (highest > -1.e20) {
+ workT[found_indx] -= 2.0;
+ if (++(q->bitsBandT[found_indx]) == 6)
+ workT[found_indx] = -1.e20;
+
+ for(j = band_tab[found_indx]; j < band_tab[found_indx+1] && (corrected < summer); j++) {
+ if (!q->skipFlags[j] && (q->CWlengthT[j] < 6)) {
+ q->CWlengthT[j]++;
+ corrected++;
+ }
+ }
+ }
+ }
+}
+
+static void imc_imdct256(IMCContext *q) {
+ int i;
+ float re, im;
+
+ /* prerotation */
+ for(i=0; i < COEFFS/2; i++){
+ q->samples[i].re = -(q->pre_coef1[i] * q->CWdecoded[COEFFS-1-i*2]) -
+ (q->pre_coef2[i] * q->CWdecoded[i*2]);
+ q->samples[i].im = (q->pre_coef2[i] * q->CWdecoded[COEFFS-1-i*2]) -
+ (q->pre_coef1[i] * q->CWdecoded[i*2]);
+ }
+
+ /* FFT */
+ ff_fft_permute(&q->fft, q->samples);
+ ff_fft_calc (&q->fft, q->samples);
+
+ /* postrotation, window and reorder */
+ for(i = 0; i < COEFFS/2; i++){
+ re = (q->samples[i].re * q->post_cos[i]) + (-q->samples[i].im * q->post_sin[i]);
+ im = (-q->samples[i].im * q->post_cos[i]) - (q->samples[i].re * q->post_sin[i]);
+ q->out_samples[i*2] = (q->mdct_sine_window[COEFFS-1-i*2] * q->last_fft_im[i]) + (q->mdct_sine_window[i*2] * re);
+ q->out_samples[COEFFS-1-i*2] = (q->mdct_sine_window[i*2] * q->last_fft_im[i]) - (q->mdct_sine_window[COEFFS-1-i*2] * re);
+ q->last_fft_im[i] = im;
+ }
+}
+
+static int inverse_quant_coeff (IMCContext* q, int stream_format_code) {
+ int i, j;
+ int middle_value, cw_len, max_size;
+ const float* quantizer;
+
+ for(i = 0; i < BANDS; i++) {
+ for(j = band_tab[i]; j < band_tab[i+1]; j++) {
+ q->CWdecoded[j] = 0;
+ cw_len = q->CWlengthT[j];
+
+ if (cw_len <= 0 || q->skipFlags[j])
+ continue;
+
+ max_size = 1 << cw_len;
+ middle_value = max_size >> 1;
+
+ if (q->codewords[j] >= max_size || q->codewords[j] < 0)
+ return -1;
+
+ if (cw_len >= 4){
+ quantizer = imc_quantizer2[(stream_format_code & 2) >> 1];
+ if (q->codewords[j] >= middle_value)
+ q->CWdecoded[j] = quantizer[q->codewords[j] - 8] * q->flcoeffs6[i];
+ else
+ q->CWdecoded[j] = -quantizer[max_size - q->codewords[j] - 8 - 1] * q->flcoeffs6[i];
+ }else{
+ quantizer = imc_quantizer1[((stream_format_code & 2) >> 1) | (q->bandFlagsBuf[i] << 1)];
+ if (q->codewords[j] >= middle_value)
+ q->CWdecoded[j] = quantizer[q->codewords[j] - 1] * q->flcoeffs6[i];
+ else
+ q->CWdecoded[j] = -quantizer[max_size - 2 - q->codewords[j]] * q->flcoeffs6[i];
+ }
+ }
+ }
+ return 0;
+}
+
+
+static int imc_get_coeffs (IMCContext* q) {
+ int i, j, cw_len, cw;
+
+ for(i = 0; i < BANDS; i++) {
+ if(!q->sumLenArr[i]) continue;
+ if (q->bandFlagsBuf[i] || q->bandWidthT[i]) {
+ for(j = band_tab[i]; j < band_tab[i+1]; j++) {
+ cw_len = q->CWlengthT[j];
+ cw = 0;
+
+ if (get_bits_count(&q->gb) + cw_len > 512){
+//av_log(NULL,0,"Band %i coeff %i cw_len %i\n",i,j,cw_len);
+ return -1;
+ }
+
+ if(cw_len && (!q->bandFlagsBuf[i] || !q->skipFlags[j]))
+ cw = get_bits(&q->gb, cw_len);
+
+ q->codewords[j] = cw;
+ }
+ }
+ }
+ return 0;
+}
+
+static int imc_decode_frame(AVCodecContext * avctx,
+ void *data, int *data_size,
+ uint8_t * buf, int buf_size)
+{
+
+ IMCContext *q = avctx->priv_data;
+
+ int stream_format_code;
+ int imc_hdr, i, j;
+ int flag;
+ int bits, summer;
+ int counter, bitscount;
+ uint16_t *buf16 = (uint16_t *) buf;
+
+ /* FIXME: input should not be modified */
+ for(i = 0; i < FFMIN(buf_size, avctx->block_align) / 2; i++)
+ buf16[i] = bswap_16(buf16[i]);
+
+ init_get_bits(&q->gb, buf, 512);
+
+ /* Check the frame header */
+ imc_hdr = get_bits(&q->gb, 9);
+ if (imc_hdr != IMC_FRAME_ID) {
+ av_log(avctx, AV_LOG_ERROR, "imc frame header check failed!\n");
+ av_log(avctx, AV_LOG_ERROR, "got %x instead of 0x21.\n", imc_hdr);
+ return -1;
+ }
+ stream_format_code = get_bits(&q->gb, 3);
+
+ if(stream_format_code & 1){
+ av_log(avctx, AV_LOG_ERROR, "Stream code format %X is not supported\n", stream_format_code);
+ return -1;
+ }
+
+// av_log(avctx, AV_LOG_DEBUG, "stream_format_code = %d\n", stream_format_code);
+
+ if (stream_format_code & 0x04)
+ q->decoder_reset = 1;
+
+ if(q->decoder_reset) {
+ memset(q->out_samples, 0, sizeof(q->out_samples));
+ for(i = 0; i < BANDS; i++)q->old_floor[i] = 1.0;
+ for(i = 0; i < COEFFS; i++)q->CWdecoded[i] = 0;
+ q->decoder_reset = 0;
+ }
+
+ flag = get_bits1(&q->gb);
+ imc_read_level_coeffs(q, stream_format_code, q->levlCoeffBuf);
+
+ if (stream_format_code & 0x4)
+ imc_decode_level_coefficients(q, q->levlCoeffBuf, q->flcoeffs1, q->flcoeffs2);
+ else
+ imc_decode_level_coefficients2(q, q->levlCoeffBuf, q->old_floor, q->flcoeffs1, q->flcoeffs2);
+
+ memcpy(q->old_floor, q->flcoeffs1, 32 * sizeof(float));
+
+ counter = 0;
+ for (i=0 ; i<BANDS ; i++) {
+ if (q->levlCoeffBuf[i] == 16) {
+ q->bandWidthT[i] = 0;
+ counter++;
+ } else
+ q->bandWidthT[i] = band_tab[i+1] - band_tab[i];
+ }
+ memset(q->bandFlagsBuf, 0, BANDS * sizeof(int));
+ for(i = 0; i < BANDS-1; i++) {
+ if (q->bandWidthT[i])
+ q->bandFlagsBuf[i] = get_bits1(&q->gb);
+ }
+
+ imc_calculate_coeffs(q, q->flcoeffs1, q->flcoeffs2, q->bandWidthT, q->flcoeffs3, q->flcoeffs5);
+
+ bitscount = 0;
+ /* first 4 bands will be assigned 5 bits per coefficient */
+ if (stream_format_code & 0x2) {
+ bitscount += 15;
+
+ q->bitsBandT[0] = 5;
+ q->CWlengthT[0] = 5;
+ q->CWlengthT[1] = 5;
+ q->CWlengthT[2] = 5;
+ for(i = 1; i < 4; i++){
+ bits = (q->levlCoeffBuf[i] == 16) ? 0 : 5;
+ q->bitsBandT[i] = bits;
+ for(j = band_tab[i]; j < band_tab[i+1]; j++) {
+ q->CWlengthT[j] = bits;
+ bitscount += bits;
+ }
+ }
+ }
+
+ if(bit_allocation (q, stream_format_code, 512 - bitscount - get_bits_count(&q->gb), flag) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "Bit allocations failed\n");
+ q->decoder_reset = 1;
+ return -1;
+ }
+
+ for(i = 0; i < BANDS; i++) {
+ q->sumLenArr[i] = 0;
+ q->skipFlagRaw[i] = 0;
+ for(j = band_tab[i]; j < band_tab[i+1]; j++)
+ q->sumLenArr[i] += q->CWlengthT[j];
+ if (q->bandFlagsBuf[i])
+ if( (((band_tab[i+1] - band_tab[i]) * 1.5) > q->sumLenArr[i]) && (q->sumLenArr[i] > 0))
+ q->skipFlagRaw[i] = 1;
+ }
+
+ imc_get_skip_coeff(q);
+
+ for(i = 0; i < BANDS; i++) {
+ q->flcoeffs6[i] = q->flcoeffs1[i];
+ /* band has flag set and at least one coded coefficient */
+ if (q->bandFlagsBuf[i] && (band_tab[i+1] - band_tab[i]) != q->skipFlagCount[i]){
+ q->flcoeffs6[i] *= q->sqrt_tab[band_tab[i+1] - band_tab[i]] /
+ q->sqrt_tab[(band_tab[i+1] - band_tab[i] - q->skipFlagCount[i])];
+ }
+ }
+
+ /* calculate bits left, bits needed and adjust bit allocation */
+ bits = summer = 0;
+
+ for(i = 0; i < BANDS; i++) {
+ if (q->bandFlagsBuf[i]) {
+ for(j = band_tab[i]; j < band_tab[i+1]; j++) {
+ if(q->skipFlags[j]) {
+ summer += q->CWlengthT[j];
+ q->CWlengthT[j] = 0;
+ }
+ }
+ bits += q->skipFlagBits[i];
+ summer -= q->skipFlagBits[i];
+ }
+ }
+ imc_adjust_bit_allocation(q, summer);
+
+ for(i = 0; i < BANDS; i++) {
+ q->sumLenArr[i] = 0;
+
+ for(j = band_tab[i]; j < band_tab[i+1]; j++)
+ if (!q->skipFlags[j])
+ q->sumLenArr[i] += q->CWlengthT[j];
+ }
+
+ memset(q->codewords, 0, sizeof(q->codewords));
+
+ if(imc_get_coeffs(q) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "Read coefficients failed\n");
+ q->decoder_reset = 1;
+ return 0;
+ }
+
+ if(inverse_quant_coeff(q, stream_format_code) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "Inverse quantization of coefficients failed\n");
+ q->decoder_reset = 1;
+ return 0;
+ }
+
+ memset(q->skipFlags, 0, sizeof(q->skipFlags));
+
+ imc_imdct256(q);
+
+ q->dsp.float_to_int16(data, q->out_samples, COEFFS);
+
+ *data_size = COEFFS * sizeof(int16_t);
+
+ return avctx->block_align;
+}
+
+
+static int imc_decode_close(AVCodecContext * avctx)
+{
+ IMCContext *q = avctx->priv_data;
+
+ ff_fft_end(&q->fft);
+ return 0;
+}
+
+
+AVCodec imc_decoder = {
+ .name = "imc",
+ .type = CODEC_TYPE_AUDIO,
+ .id = CODEC_ID_IMC,
+ .priv_data_size = sizeof(IMCContext),
+ .init = imc_decode_init,
+ .close = imc_decode_close,
+ .decode = imc_decode_frame,
+};
diff --git a/contrib/ffmpeg/libavcodec/imcdata.h b/contrib/ffmpeg/libavcodec/imcdata.h
new file mode 100644
index 000000000..92ed275f1
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/imcdata.h
@@ -0,0 +1,164 @@
+/*
+ * IMC compatible decoder
+ * Copyright (c) 2002-2004 Maxim Poliakovski
+ * Copyright (c) 2006 Benjamin Larsson
+ * Copyright (c) 2006 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
+ *
+ */
+
+static const uint16_t band_tab[33] = {
+ 0, 3, 6, 9, 12, 16, 20, 24, 29, 34, 40,
+ 46, 53, 60, 68, 76, 84, 93, 102, 111, 121, 131,
+ 141, 151, 162, 173, 184, 195, 207, 219, 231, 243, 256,
+};
+
+
+static const int8_t cyclTab[32] = {
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
+ 12, 13, 14, 15, 16, 17, 18, 20, 21, 22, 23,
+ 24, 25, 26, 27, 28, 29, 30, 31, 32, 32,
+};
+
+static const int8_t cyclTab2[32] = {
+ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
+ 12, 13, 14, 15, 16, 17, 17, 18, 19, 20, 21, 22,
+23, 24, 25, 26, 27, 28, 29};
+
+static const float imc_weights1[31] = {
+ 0.119595, 0.123124, 0.129192, 9.97377e-2, 8.1923e-2, 9.61153e-2, 8.77885e-2, 8.61174e-2,
+ 9.00882e-2, 9.91658e-2, 0.112991, 0.131126, 0.152886, 0.177292, 0.221782, 0.244917, 0.267386,
+ 0.306816, 0.323046, 0.33729, 0.366773, 0.392557, 0.398076, 0.403302, 0.42451, 0.444777,
+ 0.449188, 0.455445, 0.477853, 0.500669, 0.510395};
+
+static const float imc_weights2[31] = {
+ 3.23466e-3, 3.49886e-3, 3.98413e-3, 1.98116e-3, 1.16465e-3, 1.79283e-3, 1.40372e-3, 1.33274e-3,
+ 1.50523e-3, 1.95064e-3, 2.77472e-3, 4.14725e-3, 6.2776e-3, 9.36401e-3, 1.71397e-2, 2.24052e-2,
+ 2.83971e-2, 4.11689e-2, 4.73165e-2, 5.31631e-2, 6.66614e-2, 8.00824e-2, 8.31588e-2, 8.61397e-2,
+ 9.89229e-2, 0.112197, 0.115227, 0.119613, 0.136174, 0.15445, 0.162685};
+
+static const float imc_quantizer1[4][8] = {
+ { 8.4431201e-1, 4.7358301e-1, 1.448354, 2.7073899e-1, 7.4449003e-1, 1.241991, 1.845484, 0.0},
+ { 8.6876702e-1, 4.7659001e-1, 1.478224, 2.5672799e-1, 7.55777e-1, 1.3229851, 2.03438, 0.0},
+ { 7.5891501e-1, 6.2272799e-1, 1.271322, 3.47904e-1, 7.5317699e-1, 1.150767, 1.628476, 0.0},
+ { 7.65257e-1, 6.44647e-1, 1.263824, 3.4548101e-1, 7.6384902e-1, 1.214466, 1.7638789, 0.0},
+};
+
+static const float imc_quantizer2[2][56] = {
+ { 1.39236e-1, 3.50548e-1, 5.9547901e-1, 8.5772401e-1, 1.121545, 1.3882281, 1.695882, 2.1270809,
+ 7.2221003e-2, 1.85177e-1, 2.9521701e-1, 4.12568e-1, 5.4068601e-1, 6.7679501e-1, 8.1196898e-1, 9.4765198e-1,
+ 1.0779999, 1.203415, 1.337265, 1.481871, 1.639982, 1.814766, 2.0701399, 2.449862,
+ 3.7533998e-2, 1.02722e-1, 1.6021401e-1, 2.16043e-1, 2.7231601e-1, 3.3025399e-1, 3.9022601e-1, 4.52849e-1,
+ 5.1794899e-1, 5.8529502e-1, 6.53956e-1, 7.2312802e-1, 7.9150802e-1, 8.5891002e-1, 9.28141e-1, 9.9706203e-1,
+ 1.062153, 1.12564, 1.189834, 1.256122, 1.324469, 1.3955311, 1.468906, 1.545084,
+ 1.6264729, 1.711524, 1.802705, 1.91023, 2.0533991, 2.22333, 2.4830019, 3.253329 },
+ { 1.11654e-1, 3.54469e-1, 6.4232099e-1, 9.6128798e-1, 1.295053, 1.61777, 1.989839, 2.51107,
+ 5.7721999e-2, 1.69879e-1, 2.97589e-1, 4.3858799e-1, 5.9039903e-1, 7.4934798e-1, 9.1628098e-1, 1.087297,
+ 1.262751, 1.4288321, 1.6040879, 1.79067, 2.000668, 2.2394669, 2.649332, 5.2760072,
+ 2.9722e-2, 8.7316997e-2, 1.4445201e-1, 2.04247e-1, 2.6879501e-1, 3.3716801e-1, 4.08811e-1, 4.8306999e-1,
+ 5.6049401e-1, 6.3955498e-1, 7.2044599e-1, 8.0427998e-1, 8.8933599e-1, 9.7537601e-1, 1.062461, 1.1510431,
+ 1.240236, 1.326715, 1.412513, 1.500502, 1.591749, 1.686413, 1.785239, 1.891233,
+ 2.0051291, 2.127681, 2.2709141, 2.475826, 2.7219379, 3.101985, 4.686213, 6.2287788},
+};
+
+
+static const float xTab[14] = {7.6, 3.6, 4.4, 3.7, 6.1, 5.1, 2.3, 1.6, 6.2, 1.5, 1.8, 1.2, 0, 0}; //10014048
+
+/* precomputed table for 10^(i/4), i=-15..16 */
+static const float imc_exp_tab[32] = {
+ 1.778280e-4, 3.162278e-4, 5.623413e-4, 1.000000e-3,
+ 1.778280e-3, 3.162278e-3, 5.623413e-3, 1.000000e-2,
+ 1.778280e-2, 3.162278e-2, 5.623413e-2, 1.000000e-1,
+ 1.778280e-1, 3.162278e-1, 5.623413e-1, 1.000000e00,
+ 1.778280e00, 3.162278e00, 5.623413e00, 1.000000e01,
+ 1.778280e01, 3.162278e01, 5.623413e01, 1.000000e02,
+ 1.778280e02, 3.162278e02, 5.623413e02, 1.000000e03,
+ 1.778280e03, 3.162278e03, 5.623413e03, 1.000000e04
+};
+static const float *imc_exp_tab2 = imc_exp_tab + 8;
+
+
+static const uint8_t imc_cb_select[4][32] = {
+ { 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2 },
+ { 0, 2, 0, 3, 2, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
+ { 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2 },
+ { 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
+};
+
+static const uint8_t imc_huffman_sizes[4] = {
+ 17, 17, 18, 18
+};
+
+static const uint8_t imc_huffman_lens[4][4][18] = {
+ {
+ { 16, 15, 13, 11, 8, 5, 3, 1, 2, 4, 6, 9, 10, 12, 14, 16, 7, 0 },
+ { 10, 8, 7, 6, 4, 4, 3, 2, 2, 3, 4, 6, 7, 9, 11, 11, 7, 0 },
+ { 15, 15, 14, 11, 8, 6, 4, 2, 1, 4, 5, 7, 9, 10, 12, 13, 4, 0 },
+ { 13, 11, 10, 8, 6, 4, 2, 2, 2, 3, 5, 7, 9, 12, 15, 15, 14, 0 },
+ },
+ {
+ { 14, 12, 10, 8, 7, 4, 2, 2, 2, 3, 5, 7, 9, 11, 13, 14, 7, 0 },
+ { 14, 13, 11, 8, 6, 4, 3, 2, 2, 3, 5, 7, 9, 10, 12, 14, 3, 0 },
+ { 13, 12, 10, 7, 5, 4, 3, 2, 2, 3, 4, 6, 8, 9, 11, 13, 4, 0 },
+ { 13, 12, 10, 7, 5, 4, 3, 2, 2, 3, 4, 6, 8, 9, 11, 13, 4, 0 },
+ },
+ {
+ { 16, 14, 12, 10, 8, 5, 3, 1, 2, 4, 7, 9, 11, 13, 15, 17, 6, 17 },
+ { 15, 13, 11, 8, 6, 4, 2, 2, 2, 3, 5, 7, 10, 12, 14, 16, 9, 16 },
+ { 14, 12, 11, 9, 8, 6, 3, 1, 2, 5, 7, 10, 13, 15, 16, 17, 4, 17 },
+ { 16, 14, 12, 9, 7, 5, 2, 2, 2, 3, 4, 6, 8, 11, 13, 15, 10, 16 },
+ },
+ {
+ { 13, 11, 10, 8, 7, 5, 2, 2, 2, 4, 6, 9, 12, 14, 15, 16, 3, 16 },
+ { 11, 11, 10, 9, 8, 7, 5, 4, 3, 3, 3, 3, 3, 3, 4, 5, 6, 5 },
+ { 9, 9, 7, 6, 5, 4, 3, 3, 2, 3, 4, 5, 4, 5, 5, 6, 8, 6 },
+ { 13, 12, 10, 8, 5, 3, 3, 2, 2, 3, 4, 7, 9, 11, 14, 15, 6, 15 },
+ }
+};
+
+static const uint16_t imc_huffman_bits[4][4][18] = {
+ {
+ { 0xCC32, 0x6618, 0x1987, 0x0660, 0x00CD, 0x0018, 0x0007, 0x0000, 0x0002, 0x000D, 0x0032, 0x0199, 0x0331, 0x0CC2, 0x330D, 0xCC33, 0x0067, 0x0000 },
+ { 0x02FE, 0x00BE, 0x005E, 0x002D, 0x000A, 0x0009, 0x0003, 0x0003, 0x0000, 0x0002, 0x0008, 0x002C, 0x005D, 0x017E, 0x05FE, 0x05FF, 0x005C, 0x0000 },
+ { 0x5169, 0x5168, 0x28B5, 0x0517, 0x00A3, 0x0029, 0x0008, 0x0003, 0x0000, 0x0009, 0x0015, 0x0050, 0x0144, 0x028A, 0x0A2C, 0x145B, 0x000B, 0x0000 },
+ { 0x1231, 0x048D, 0x0247, 0x0090, 0x0025, 0x0008, 0x0001, 0x0003, 0x0000, 0x0005, 0x0013, 0x0049, 0x0122, 0x0919, 0x48C3, 0x48C2, 0x2460, 0x0000 },
+ },
+ {
+ { 0x2D1D, 0x0B46, 0x02D0, 0x00B5, 0x0059, 0x000A, 0x0003, 0x0001, 0x0000, 0x0004, 0x0017, 0x005B, 0x0169, 0x05A2, 0x168F, 0x2D1C, 0x0058, 0x0000 },
+ { 0x1800, 0x0C01, 0x0301, 0x0061, 0x0019, 0x0007, 0x0004, 0x0003, 0x0000, 0x0005, 0x000D, 0x0031, 0x00C1, 0x0181, 0x0601, 0x1801, 0x0002, 0x0000 },
+ { 0x1556, 0x0AAA, 0x02AB, 0x0054, 0x0014, 0x000B, 0x0002, 0x0003, 0x0000, 0x0003, 0x0008, 0x002B, 0x00AB, 0x0154, 0x0554, 0x1557, 0x0009, 0x0000 },
+ { 0x1556, 0x0AAA, 0x02AB, 0x0054, 0x0014, 0x000B, 0x0002, 0x0003, 0x0000, 0x0003, 0x0008, 0x002B, 0x00AB, 0x0154, 0x0554, 0x1557, 0x0009, 0x0000 },
+ },
+ {
+ { 0x2993, 0x0A65, 0x0298, 0x00A7, 0x0028, 0x0004, 0x0000, 0x0001, 0x0001, 0x0003, 0x0015, 0x0052, 0x014D, 0x0533, 0x14C8, 0x5324, 0x000B, 0x5325 },
+ { 0x09B8, 0x026F, 0x009A, 0x0012, 0x0005, 0x0000, 0x0001, 0x0002, 0x0003, 0x0001, 0x0003, 0x0008, 0x004C, 0x0136, 0x04DD, 0x1373, 0x0027, 0x1372 },
+ { 0x0787, 0x01E0, 0x00F1, 0x003D, 0x001F, 0x0006, 0x0001, 0x0001, 0x0001, 0x0002, 0x000E, 0x0079, 0x03C2, 0x0F0D, 0x1E19, 0x3C30, 0x0000, 0x3C31 },
+ { 0x4B06, 0x12C0, 0x04B1, 0x0097, 0x0024, 0x0008, 0x0002, 0x0003, 0x0000, 0x0003, 0x0005, 0x0013, 0x004A, 0x0259, 0x0961, 0x2582, 0x012D, 0x4B07 },
+ },
+ {
+ { 0x0A5A, 0x0297, 0x014A, 0x0053, 0x0028, 0x000B, 0x0003, 0x0000, 0x0002, 0x0004, 0x0015, 0x00A4, 0x052C, 0x14B7, 0x296C, 0x52DB, 0x0003, 0x52DA },
+ { 0x0193, 0x0192, 0x00C8, 0x0065, 0x0033, 0x0018, 0x0007, 0x0004, 0x0000, 0x0004, 0x0005, 0x0007, 0x0006, 0x0003, 0x0005, 0x0005, 0x000D, 0x0004 },
+ { 0x0012, 0x0013, 0x0005, 0x0003, 0x0000, 0x0003, 0x0005, 0x0004, 0x0003, 0x0003, 0x0005, 0x0005, 0x0004, 0x0004, 0x0003, 0x0005, 0x0008, 0x0004 },
+ { 0x0D66, 0x06B2, 0x01AD, 0x006A, 0x000C, 0x0005, 0x0004, 0x0000, 0x0003, 0x0002, 0x0007, 0x0034, 0x00D7, 0x0358, 0x1ACF, 0x359C, 0x001B, 0x359D },
+ }
+};
+
diff --git a/contrib/ffmpeg/libavcodec/imgconvert.c b/contrib/ffmpeg/libavcodec/imgconvert.c
new file mode 100644
index 000000000..2971afaa8
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/imgconvert.c
@@ -0,0 +1,2854 @@
+/*
+ * Misc image convertion routines
+ * Copyright (c) 2001, 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
+ */
+
+/**
+ * @file imgconvert.c
+ * Misc image convertion routines.
+ */
+
+/* TODO:
+ * - write 'ffimg' program to test all the image related stuff
+ * - move all api to slice based system
+ * - integrate deinterlacing, postprocessing and scaling in the conversion process
+ */
+
+#include "avcodec.h"
+#include "dsputil.h"
+
+#ifdef USE_FASTMEMCPY
+#include "libvo/fastmemcpy.h"
+#endif
+
+#ifdef HAVE_MMX
+#include "i386/mmx.h"
+#endif
+
+#define xglue(x, y) x ## y
+#define glue(x, y) xglue(x, y)
+
+#define FF_COLOR_RGB 0 /**< RGB color space */
+#define FF_COLOR_GRAY 1 /**< gray color space */
+#define FF_COLOR_YUV 2 /**< YUV color space. 16 <= Y <= 235, 16 <= U, V <= 240 */
+#define FF_COLOR_YUV_JPEG 3 /**< YUV color space. 0 <= Y <= 255, 0 <= U, V <= 255 */
+
+#define FF_PIXEL_PLANAR 0 /**< each channel has one component in AVPicture */
+#define FF_PIXEL_PACKED 1 /**< only one components containing all the channels */
+#define FF_PIXEL_PALETTE 2 /**< one components containing indexes for a palette */
+
+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 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;
+
+/* this table gives more information about formats */
+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,
+ },
+
+ /* 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,
+ },
+
+ /* 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_RGB32] = {
+ .name = "rgb32",
+ .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_RGB565] = {
+ .name = "rgb565",
+ .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_RGB555] = {
+ .name = "rgb555",
+ .nb_channels = 3,
+ .color_type = FF_COLOR_RGB,
+ .pixel_type = FF_PIXEL_PACKED,
+ .depth = 5,
+ .x_chroma_shift = 0, .y_chroma_shift = 0,
+ },
+
+ /* 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,
+ .depth = 1,
+ },
+
+ /* 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",
+ },
+ [PIX_FMT_XVMC_MPEG2_IDCT] = {
+ .name = "xvmcidct",
+ },
+ [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_BGR32] = {
+ .name = "bgr32",
+ .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_BGR565] = {
+ .name = "bgr565",
+ .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_BGR555] = {
+ .name = "bgr555",
+ .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_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_BGR32_1] = {
+ .name = "bgr32_1",
+ .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_RGB32_1] = {
+ .name = "rgb32_1",
+ .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,
+ },
+};
+
+void avcodec_get_chroma_sub_sample(int 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;
+}
+
+const char *avcodec_get_pix_fmt_name(int pix_fmt)
+{
+ if (pix_fmt < 0 || pix_fmt >= PIX_FMT_NB)
+ return "???";
+ else
+ return pix_fmt_info[pix_fmt].name;
+}
+
+enum PixelFormat avcodec_get_pix_fmt(const char* name)
+{
+ int i;
+
+ for (i=0; i < PIX_FMT_NB; i++)
+ if (!strcmp(pix_fmt_info[i].name, name))
+ break;
+ return i;
+}
+
+int avpicture_fill(AVPicture *picture, uint8_t *ptr,
+ int pix_fmt, int width, int height)
+{
+ int size, w2, h2, size2;
+ const PixFmtInfo *pinfo;
+
+ if(avcodec_check_dimensions(NULL, width, height))
+ goto fail;
+
+ pinfo = &pix_fmt_info[pix_fmt];
+ size = width * height;
+ 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_YUVJ420P:
+ case PIX_FMT_YUVJ422P:
+ case PIX_FMT_YUVJ444P:
+ w2 = (width + (1 << pinfo->x_chroma_shift) - 1) >> pinfo->x_chroma_shift;
+ h2 = (height + (1 << pinfo->y_chroma_shift) - 1) >> pinfo->y_chroma_shift;
+ size2 = w2 * h2;
+ picture->data[0] = ptr;
+ picture->data[1] = picture->data[0] + size;
+ picture->data[2] = picture->data[1] + size2;
+ picture->linesize[0] = width;
+ picture->linesize[1] = w2;
+ picture->linesize[2] = w2;
+ return size + 2 * size2;
+ case PIX_FMT_NV12:
+ case PIX_FMT_NV21:
+ w2 = (width + (1 << pinfo->x_chroma_shift) - 1) >> pinfo->x_chroma_shift;
+ h2 = (height + (1 << pinfo->y_chroma_shift) - 1) >> pinfo->y_chroma_shift;
+ size2 = w2 * h2 * 2;
+ picture->data[0] = ptr;
+ picture->data[1] = picture->data[0] + size;
+ picture->data[2] = NULL;
+ picture->linesize[0] = width;
+ picture->linesize[1] = w2;
+ picture->linesize[2] = 0;
+ return size + 2 * size2;
+ case PIX_FMT_RGB24:
+ case PIX_FMT_BGR24:
+ picture->data[0] = ptr;
+ picture->data[1] = NULL;
+ picture->data[2] = NULL;
+ picture->linesize[0] = width * 3;
+ return size * 3;
+ case PIX_FMT_RGB32:
+ case PIX_FMT_BGR32:
+ case PIX_FMT_RGB32_1:
+ case PIX_FMT_BGR32_1:
+ picture->data[0] = ptr;
+ picture->data[1] = NULL;
+ picture->data[2] = NULL;
+ picture->linesize[0] = width * 4;
+ return size * 4;
+ case PIX_FMT_GRAY16BE:
+ case PIX_FMT_GRAY16LE:
+ case PIX_FMT_BGR555:
+ case PIX_FMT_BGR565:
+ case PIX_FMT_RGB555:
+ case PIX_FMT_RGB565:
+ case PIX_FMT_YUYV422:
+ picture->data[0] = ptr;
+ picture->data[1] = NULL;
+ picture->data[2] = NULL;
+ picture->linesize[0] = width * 2;
+ return size * 2;
+ case PIX_FMT_UYVY422:
+ picture->data[0] = ptr;
+ picture->data[1] = NULL;
+ picture->data[2] = NULL;
+ picture->linesize[0] = width * 2;
+ return size * 2;
+ case PIX_FMT_UYYVYY411:
+ picture->data[0] = ptr;
+ picture->data[1] = NULL;
+ picture->data[2] = NULL;
+ picture->linesize[0] = width + width/2;
+ return size + size/2;
+ case PIX_FMT_RGB8:
+ case PIX_FMT_BGR8:
+ case PIX_FMT_RGB4_BYTE:
+ case PIX_FMT_BGR4_BYTE:
+ case PIX_FMT_GRAY8:
+ picture->data[0] = ptr;
+ picture->data[1] = NULL;
+ picture->data[2] = NULL;
+ picture->linesize[0] = width;
+ return size;
+ case PIX_FMT_RGB4:
+ case PIX_FMT_BGR4:
+ picture->data[0] = ptr;
+ picture->data[1] = NULL;
+ picture->data[2] = NULL;
+ picture->linesize[0] = width / 2;
+ return size / 2;
+ case PIX_FMT_MONOWHITE:
+ case PIX_FMT_MONOBLACK:
+ picture->data[0] = ptr;
+ picture->data[1] = NULL;
+ picture->data[2] = NULL;
+ picture->linesize[0] = (width + 7) >> 3;
+ return picture->linesize[0] * height;
+ case PIX_FMT_PAL8:
+ size2 = (size + 3) & ~3;
+ picture->data[0] = ptr;
+ picture->data[1] = ptr + size2; /* palette is stored here as 256 32 bit words */
+ picture->data[2] = NULL;
+ picture->linesize[0] = width;
+ picture->linesize[1] = 4;
+ return size2 + 256 * 4;
+ default:
+fail:
+ picture->data[0] = NULL;
+ picture->data[1] = NULL;
+ picture->data[2] = NULL;
+ picture->data[3] = NULL;
+ return -1;
+ }
+}
+
+int avpicture_layout(const AVPicture* src, int pix_fmt, int width, int height,
+ unsigned char *dest, int dest_size)
+{
+ const PixFmtInfo* pf = &pix_fmt_info[pix_fmt];
+ int i, j, w, h, data_planes;
+ const unsigned char* s;
+ int size = avpicture_get_size(pix_fmt, width, height);
+
+ if (size > dest_size || size < 0)
+ return -1;
+
+ if (pf->pixel_type == FF_PIXEL_PACKED || pf->pixel_type == FF_PIXEL_PALETTE) {
+ if (pix_fmt == PIX_FMT_YUYV422 ||
+ pix_fmt == PIX_FMT_UYVY422 ||
+ pix_fmt == PIX_FMT_BGR565 ||
+ pix_fmt == PIX_FMT_BGR555 ||
+ pix_fmt == PIX_FMT_RGB565 ||
+ pix_fmt == PIX_FMT_RGB555)
+ w = width * 2;
+ else if (pix_fmt == PIX_FMT_UYYVYY411)
+ w = width + width/2;
+ else if (pix_fmt == PIX_FMT_PAL8)
+ w = width;
+ else
+ w = width * (pf->depth * pf->nb_channels / 8);
+
+ data_planes = 1;
+ h = height;
+ } else {
+ data_planes = pf->nb_channels;
+ w = (width*pf->depth + 7)/8;
+ h = height;
+ }
+
+ for (i=0; i<data_planes; i++) {
+ if (i == 1) {
+ w = width >> pf->x_chroma_shift;
+ h = height >> pf->y_chroma_shift;
+ }
+ s = src->data[i];
+ for(j=0; j<h; j++) {
+ memcpy(dest, s, w);
+ dest += w;
+ s += src->linesize[i];
+ }
+ }
+
+ if (pf->pixel_type == FF_PIXEL_PALETTE)
+ memcpy((unsigned char *)(((size_t)dest + 3) & ~3), src->data[1], 256 * 4);
+
+ return size;
+}
+
+int avpicture_get_size(int pix_fmt, int width, int height)
+{
+ AVPicture dummy_pict;
+ return avpicture_fill(&dummy_pict, NULL, pix_fmt, width, height);
+}
+
+int avcodec_get_pix_fmt_loss(int dst_pix_fmt, int src_pix_fmt,
+ int has_alpha)
+{
+ const PixFmtInfo *pf, *ps;
+ int loss;
+
+ ps = &pix_fmt_info[src_pix_fmt];
+ pf = &pix_fmt_info[dst_pix_fmt];
+
+ /* compute loss */
+ loss = 0;
+ pf = &pix_fmt_info[dst_pix_fmt];
+ if (pf->depth < ps->depth ||
+ (dst_pix_fmt == PIX_FMT_RGB555 && src_pix_fmt == PIX_FMT_RGB565))
+ loss |= FF_LOSS_DEPTH;
+ if (pf->x_chroma_shift > ps->x_chroma_shift ||
+ pf->y_chroma_shift > ps->y_chroma_shift)
+ loss |= FF_LOSS_RESOLUTION;
+ switch(pf->color_type) {
+ case FF_COLOR_RGB:
+ if (ps->color_type != FF_COLOR_RGB &&
+ ps->color_type != FF_COLOR_GRAY)
+ loss |= FF_LOSS_COLORSPACE;
+ break;
+ case FF_COLOR_GRAY:
+ if (ps->color_type != FF_COLOR_GRAY)
+ loss |= FF_LOSS_COLORSPACE;
+ break;
+ case FF_COLOR_YUV:
+ if (ps->color_type != FF_COLOR_YUV)
+ loss |= FF_LOSS_COLORSPACE;
+ break;
+ case FF_COLOR_YUV_JPEG:
+ if (ps->color_type != FF_COLOR_YUV_JPEG &&
+ ps->color_type != FF_COLOR_YUV &&
+ ps->color_type != FF_COLOR_GRAY)
+ loss |= FF_LOSS_COLORSPACE;
+ break;
+ default:
+ /* fail safe test */
+ if (ps->color_type != pf->color_type)
+ loss |= FF_LOSS_COLORSPACE;
+ break;
+ }
+ if (pf->color_type == FF_COLOR_GRAY &&
+ ps->color_type != FF_COLOR_GRAY)
+ loss |= FF_LOSS_CHROMA;
+ if (!pf->is_alpha && (ps->is_alpha && has_alpha))
+ loss |= FF_LOSS_ALPHA;
+ if (pf->pixel_type == FF_PIXEL_PALETTE &&
+ (ps->pixel_type != FF_PIXEL_PALETTE && ps->color_type != FF_COLOR_GRAY))
+ loss |= FF_LOSS_COLORQUANT;
+ return loss;
+}
+
+static int avg_bits_per_pixel(int pix_fmt)
+{
+ int bits;
+ const PixFmtInfo *pf;
+
+ pf = &pix_fmt_info[pix_fmt];
+ switch(pf->pixel_type) {
+ case FF_PIXEL_PACKED:
+ switch(pix_fmt) {
+ case PIX_FMT_YUYV422:
+ case PIX_FMT_UYVY422:
+ case PIX_FMT_RGB565:
+ case PIX_FMT_RGB555:
+ case PIX_FMT_BGR565:
+ case PIX_FMT_BGR555:
+ bits = 16;
+ break;
+ case PIX_FMT_UYYVYY411:
+ bits = 12;
+ break;
+ default:
+ bits = pf->depth * pf->nb_channels;
+ break;
+ }
+ break;
+ case FF_PIXEL_PLANAR:
+ if (pf->x_chroma_shift == 0 && pf->y_chroma_shift == 0) {
+ bits = pf->depth * pf->nb_channels;
+ } else {
+ bits = pf->depth + ((2 * pf->depth) >>
+ (pf->x_chroma_shift + pf->y_chroma_shift));
+ }
+ break;
+ case FF_PIXEL_PALETTE:
+ bits = 8;
+ break;
+ default:
+ bits = -1;
+ break;
+ }
+ return bits;
+}
+
+static int avcodec_find_best_pix_fmt1(int pix_fmt_mask,
+ int src_pix_fmt,
+ int has_alpha,
+ int loss_mask)
+{
+ int dist, i, loss, min_dist, dst_pix_fmt;
+
+ /* find exact color match with smallest size */
+ dst_pix_fmt = -1;
+ min_dist = 0x7fffffff;
+ for(i = 0;i < PIX_FMT_NB; i++) {
+ if (pix_fmt_mask & (1 << i)) {
+ loss = avcodec_get_pix_fmt_loss(i, src_pix_fmt, has_alpha) & loss_mask;
+ if (loss == 0) {
+ dist = avg_bits_per_pixel(i);
+ if (dist < min_dist) {
+ min_dist = dist;
+ dst_pix_fmt = i;
+ }
+ }
+ }
+ }
+ return dst_pix_fmt;
+}
+
+int avcodec_find_best_pix_fmt(int pix_fmt_mask, int src_pix_fmt,
+ int has_alpha, int *loss_ptr)
+{
+ int dst_pix_fmt, loss_mask, i;
+ static const int loss_mask_order[] = {
+ ~0, /* no loss first */
+ ~FF_LOSS_ALPHA,
+ ~FF_LOSS_RESOLUTION,
+ ~(FF_LOSS_COLORSPACE | FF_LOSS_RESOLUTION),
+ ~FF_LOSS_COLORQUANT,
+ ~FF_LOSS_DEPTH,
+ 0,
+ };
+
+ /* try with successive loss */
+ i = 0;
+ for(;;) {
+ loss_mask = loss_mask_order[i++];
+ dst_pix_fmt = avcodec_find_best_pix_fmt1(pix_fmt_mask, src_pix_fmt,
+ has_alpha, loss_mask);
+ if (dst_pix_fmt >= 0)
+ goto found;
+ if (loss_mask == 0)
+ break;
+ }
+ return -1;
+ found:
+ if (loss_ptr)
+ *loss_ptr = avcodec_get_pix_fmt_loss(dst_pix_fmt, src_pix_fmt, has_alpha);
+ return dst_pix_fmt;
+}
+
+void ff_img_copy_plane(uint8_t *dst, int dst_wrap,
+ const uint8_t *src, int src_wrap,
+ int width, int height)
+{
+ if((!dst) || (!src))
+ return;
+ for(;height > 0; height--) {
+ memcpy(dst, src, width);
+ dst += dst_wrap;
+ src += src_wrap;
+ }
+}
+
+void av_picture_copy(AVPicture *dst, const AVPicture *src,
+ int pix_fmt, int width, int height)
+{
+ int bwidth, bits, i;
+ const PixFmtInfo *pf = &pix_fmt_info[pix_fmt];
+
+ pf = &pix_fmt_info[pix_fmt];
+ switch(pf->pixel_type) {
+ case FF_PIXEL_PACKED:
+ switch(pix_fmt) {
+ case PIX_FMT_YUYV422:
+ case PIX_FMT_UYVY422:
+ case PIX_FMT_RGB565:
+ case PIX_FMT_RGB555:
+ case PIX_FMT_BGR565:
+ case PIX_FMT_BGR555:
+ bits = 16;
+ break;
+ case PIX_FMT_UYYVYY411:
+ bits = 12;
+ break;
+ default:
+ bits = pf->depth * pf->nb_channels;
+ break;
+ }
+ bwidth = (width * bits + 7) >> 3;
+ ff_img_copy_plane(dst->data[0], dst->linesize[0],
+ src->data[0], src->linesize[0],
+ bwidth, height);
+ break;
+ case FF_PIXEL_PLANAR:
+ for(i = 0; i < pf->nb_channels; i++) {
+ int w, h;
+ w = width;
+ h = height;
+ if (i == 1 || i == 2) {
+ w >>= pf->x_chroma_shift;
+ h >>= pf->y_chroma_shift;
+ }
+ bwidth = (w * pf->depth + 7) >> 3;
+ ff_img_copy_plane(dst->data[i], dst->linesize[i],
+ src->data[i], src->linesize[i],
+ bwidth, h);
+ }
+ break;
+ case FF_PIXEL_PALETTE:
+ ff_img_copy_plane(dst->data[0], dst->linesize[0],
+ 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);
+ break;
+ }
+}
+
+/* XXX: totally non optimized */
+
+static void yuyv422_to_yuv420p(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ const uint8_t *p, *p1;
+ uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
+ int w;
+
+ p1 = src->data[0];
+ lum1 = dst->data[0];
+ cb1 = dst->data[1];
+ cr1 = dst->data[2];
+
+ for(;height >= 1; height -= 2) {
+ p = p1;
+ lum = lum1;
+ cb = cb1;
+ cr = cr1;
+ for(w = width; w >= 2; w -= 2) {
+ lum[0] = p[0];
+ cb[0] = p[1];
+ lum[1] = p[2];
+ cr[0] = p[3];
+ p += 4;
+ lum += 2;
+ cb++;
+ cr++;
+ }
+ if (w) {
+ lum[0] = p[0];
+ cb[0] = p[1];
+ cr[0] = p[3];
+ cb++;
+ cr++;
+ }
+ p1 += src->linesize[0];
+ lum1 += dst->linesize[0];
+ if (height>1) {
+ p = p1;
+ lum = lum1;
+ for(w = width; w >= 2; w -= 2) {
+ lum[0] = p[0];
+ lum[1] = p[2];
+ p += 4;
+ lum += 2;
+ }
+ if (w) {
+ lum[0] = p[0];
+ }
+ p1 += src->linesize[0];
+ lum1 += dst->linesize[0];
+ }
+ cb1 += dst->linesize[1];
+ cr1 += dst->linesize[2];
+ }
+}
+
+static void uyvy422_to_yuv420p(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ const uint8_t *p, *p1;
+ uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
+ int w;
+
+ p1 = src->data[0];
+
+ lum1 = dst->data[0];
+ cb1 = dst->data[1];
+ cr1 = dst->data[2];
+
+ for(;height >= 1; height -= 2) {
+ p = p1;
+ lum = lum1;
+ cb = cb1;
+ cr = cr1;
+ for(w = width; w >= 2; w -= 2) {
+ lum[0] = p[1];
+ cb[0] = p[0];
+ lum[1] = p[3];
+ cr[0] = p[2];
+ p += 4;
+ lum += 2;
+ cb++;
+ cr++;
+ }
+ if (w) {
+ lum[0] = p[1];
+ cb[0] = p[0];
+ cr[0] = p[2];
+ cb++;
+ cr++;
+ }
+ p1 += src->linesize[0];
+ lum1 += dst->linesize[0];
+ if (height>1) {
+ p = p1;
+ lum = lum1;
+ for(w = width; w >= 2; w -= 2) {
+ lum[0] = p[1];
+ lum[1] = p[3];
+ p += 4;
+ lum += 2;
+ }
+ if (w) {
+ lum[0] = p[1];
+ }
+ p1 += src->linesize[0];
+ lum1 += dst->linesize[0];
+ }
+ cb1 += dst->linesize[1];
+ cr1 += dst->linesize[2];
+ }
+}
+
+
+static void uyvy422_to_yuv422p(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ const uint8_t *p, *p1;
+ uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
+ int w;
+
+ p1 = src->data[0];
+ lum1 = dst->data[0];
+ cb1 = dst->data[1];
+ cr1 = dst->data[2];
+ for(;height > 0; height--) {
+ p = p1;
+ lum = lum1;
+ cb = cb1;
+ cr = cr1;
+ for(w = width; w >= 2; w -= 2) {
+ lum[0] = p[1];
+ cb[0] = p[0];
+ lum[1] = p[3];
+ cr[0] = p[2];
+ p += 4;
+ lum += 2;
+ cb++;
+ cr++;
+ }
+ p1 += src->linesize[0];
+ lum1 += dst->linesize[0];
+ cb1 += dst->linesize[1];
+ cr1 += dst->linesize[2];
+ }
+}
+
+
+static void yuyv422_to_yuv422p(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ const uint8_t *p, *p1;
+ uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
+ int w;
+
+ p1 = src->data[0];
+ lum1 = dst->data[0];
+ cb1 = dst->data[1];
+ cr1 = dst->data[2];
+ for(;height > 0; height--) {
+ p = p1;
+ lum = lum1;
+ cb = cb1;
+ cr = cr1;
+ for(w = width; w >= 2; w -= 2) {
+ lum[0] = p[0];
+ cb[0] = p[1];
+ lum[1] = p[2];
+ cr[0] = p[3];
+ p += 4;
+ lum += 2;
+ cb++;
+ cr++;
+ }
+ p1 += src->linesize[0];
+ lum1 += dst->linesize[0];
+ cb1 += dst->linesize[1];
+ cr1 += dst->linesize[2];
+ }
+}
+
+static void yuv422p_to_yuyv422(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ uint8_t *p, *p1;
+ const uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
+ int w;
+
+ p1 = dst->data[0];
+ lum1 = src->data[0];
+ cb1 = src->data[1];
+ cr1 = src->data[2];
+ for(;height > 0; height--) {
+ p = p1;
+ lum = lum1;
+ cb = cb1;
+ cr = cr1;
+ for(w = width; w >= 2; w -= 2) {
+ p[0] = lum[0];
+ p[1] = cb[0];
+ p[2] = lum[1];
+ p[3] = cr[0];
+ p += 4;
+ lum += 2;
+ cb++;
+ cr++;
+ }
+ p1 += dst->linesize[0];
+ lum1 += src->linesize[0];
+ cb1 += src->linesize[1];
+ cr1 += src->linesize[2];
+ }
+}
+
+static void yuv422p_to_uyvy422(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ uint8_t *p, *p1;
+ const uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
+ int w;
+
+ p1 = dst->data[0];
+ lum1 = src->data[0];
+ cb1 = src->data[1];
+ cr1 = src->data[2];
+ for(;height > 0; height--) {
+ p = p1;
+ lum = lum1;
+ cb = cb1;
+ cr = cr1;
+ for(w = width; w >= 2; w -= 2) {
+ p[1] = lum[0];
+ p[0] = cb[0];
+ p[3] = lum[1];
+ p[2] = cr[0];
+ p += 4;
+ lum += 2;
+ cb++;
+ cr++;
+ }
+ p1 += dst->linesize[0];
+ lum1 += src->linesize[0];
+ cb1 += src->linesize[1];
+ cr1 += src->linesize[2];
+ }
+}
+
+static void uyyvyy411_to_yuv411p(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ const uint8_t *p, *p1;
+ uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
+ int w;
+
+ p1 = src->data[0];
+ lum1 = dst->data[0];
+ cb1 = dst->data[1];
+ cr1 = dst->data[2];
+ for(;height > 0; height--) {
+ p = p1;
+ lum = lum1;
+ cb = cb1;
+ cr = cr1;
+ for(w = width; w >= 4; w -= 4) {
+ cb[0] = p[0];
+ lum[0] = p[1];
+ lum[1] = p[2];
+ cr[0] = p[3];
+ lum[2] = p[4];
+ lum[3] = p[5];
+ p += 6;
+ lum += 4;
+ cb++;
+ cr++;
+ }
+ p1 += src->linesize[0];
+ lum1 += dst->linesize[0];
+ cb1 += dst->linesize[1];
+ cr1 += dst->linesize[2];
+ }
+}
+
+
+static void yuv420p_to_yuyv422(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ int w, h;
+ uint8_t *line1, *line2, *linesrc = dst->data[0];
+ uint8_t *lum1, *lum2, *lumsrc = src->data[0];
+ uint8_t *cb1, *cb2 = src->data[1];
+ uint8_t *cr1, *cr2 = src->data[2];
+
+ for(h = height / 2; h--;) {
+ line1 = linesrc;
+ line2 = linesrc + dst->linesize[0];
+
+ lum1 = lumsrc;
+ lum2 = lumsrc + src->linesize[0];
+
+ cb1 = cb2;
+ cr1 = cr2;
+
+ for(w = width / 2; w--;) {
+ *line1++ = *lum1++; *line2++ = *lum2++;
+ *line1++ = *line2++ = *cb1++;
+ *line1++ = *lum1++; *line2++ = *lum2++;
+ *line1++ = *line2++ = *cr1++;
+ }
+
+ linesrc += dst->linesize[0] * 2;
+ lumsrc += src->linesize[0] * 2;
+ cb2 += src->linesize[1];
+ cr2 += src->linesize[2];
+ }
+}
+
+static void yuv420p_to_uyvy422(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ int w, h;
+ uint8_t *line1, *line2, *linesrc = dst->data[0];
+ uint8_t *lum1, *lum2, *lumsrc = src->data[0];
+ uint8_t *cb1, *cb2 = src->data[1];
+ uint8_t *cr1, *cr2 = src->data[2];
+
+ for(h = height / 2; h--;) {
+ line1 = linesrc;
+ line2 = linesrc + dst->linesize[0];
+
+ lum1 = lumsrc;
+ lum2 = lumsrc + src->linesize[0];
+
+ cb1 = cb2;
+ cr1 = cr2;
+
+ for(w = width / 2; w--;) {
+ *line1++ = *line2++ = *cb1++;
+ *line1++ = *lum1++; *line2++ = *lum2++;
+ *line1++ = *line2++ = *cr1++;
+ *line1++ = *lum1++; *line2++ = *lum2++;
+ }
+
+ linesrc += dst->linesize[0] * 2;
+ lumsrc += src->linesize[0] * 2;
+ cb2 += src->linesize[1];
+ cr2 += src->linesize[2];
+ }
+}
+
+#define SCALEBITS 10
+#define ONE_HALF (1 << (SCALEBITS - 1))
+#define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5))
+
+#define YUV_TO_RGB1_CCIR(cb1, cr1)\
+{\
+ cb = (cb1) - 128;\
+ cr = (cr1) - 128;\
+ r_add = FIX(1.40200*255.0/224.0) * cr + ONE_HALF;\
+ g_add = - FIX(0.34414*255.0/224.0) * cb - FIX(0.71414*255.0/224.0) * cr + \
+ ONE_HALF;\
+ b_add = FIX(1.77200*255.0/224.0) * cb + ONE_HALF;\
+}
+
+#define YUV_TO_RGB2_CCIR(r, g, b, y1)\
+{\
+ y = ((y1) - 16) * FIX(255.0/219.0);\
+ r = cm[(y + r_add) >> SCALEBITS];\
+ g = cm[(y + g_add) >> SCALEBITS];\
+ b = cm[(y + b_add) >> SCALEBITS];\
+}
+
+#define YUV_TO_RGB1(cb1, cr1)\
+{\
+ cb = (cb1) - 128;\
+ cr = (cr1) - 128;\
+ r_add = FIX(1.40200) * cr + ONE_HALF;\
+ g_add = - FIX(0.34414) * cb - FIX(0.71414) * cr + ONE_HALF;\
+ b_add = FIX(1.77200) * cb + ONE_HALF;\
+}
+
+#define YUV_TO_RGB2(r, g, b, y1)\
+{\
+ y = (y1) << SCALEBITS;\
+ r = cm[(y + r_add) >> SCALEBITS];\
+ g = cm[(y + g_add) >> SCALEBITS];\
+ b = cm[(y + b_add) >> SCALEBITS];\
+}
+
+#define Y_CCIR_TO_JPEG(y)\
+ cm[((y) * FIX(255.0/219.0) + (ONE_HALF - 16 * FIX(255.0/219.0))) >> SCALEBITS]
+
+#define Y_JPEG_TO_CCIR(y)\
+ (((y) * FIX(219.0/255.0) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS)
+
+#define C_CCIR_TO_JPEG(y)\
+ cm[(((y) - 128) * FIX(127.0/112.0) + (ONE_HALF + (128 << SCALEBITS))) >> SCALEBITS]
+
+/* NOTE: the clamp is really necessary! */
+static inline int C_JPEG_TO_CCIR(int y) {
+ y = (((y - 128) * FIX(112.0/127.0) + (ONE_HALF + (128 << SCALEBITS))) >> SCALEBITS);
+ if (y < 16)
+ y = 16;
+ return y;
+}
+
+
+#define RGB_TO_Y(r, g, b) \
+((FIX(0.29900) * (r) + FIX(0.58700) * (g) + \
+ FIX(0.11400) * (b) + ONE_HALF) >> SCALEBITS)
+
+#define RGB_TO_U(r1, g1, b1, shift)\
+(((- FIX(0.16874) * r1 - FIX(0.33126) * g1 + \
+ FIX(0.50000) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
+
+#define RGB_TO_V(r1, g1, b1, shift)\
+(((FIX(0.50000) * r1 - FIX(0.41869) * g1 - \
+ FIX(0.08131) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
+
+#define RGB_TO_Y_CCIR(r, g, b) \
+((FIX(0.29900*219.0/255.0) * (r) + FIX(0.58700*219.0/255.0) * (g) + \
+ FIX(0.11400*219.0/255.0) * (b) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS)
+
+#define RGB_TO_U_CCIR(r1, g1, b1, shift)\
+(((- FIX(0.16874*224.0/255.0) * r1 - FIX(0.33126*224.0/255.0) * g1 + \
+ FIX(0.50000*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
+
+#define RGB_TO_V_CCIR(r1, g1, b1, shift)\
+(((FIX(0.50000*224.0/255.0) * r1 - FIX(0.41869*224.0/255.0) * g1 - \
+ FIX(0.08131*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
+
+static uint8_t y_ccir_to_jpeg[256];
+static uint8_t y_jpeg_to_ccir[256];
+static uint8_t c_ccir_to_jpeg[256];
+static uint8_t c_jpeg_to_ccir[256];
+
+/* init various conversion tables */
+static void img_convert_init(void)
+{
+ int i;
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+
+ for(i = 0;i < 256; i++) {
+ y_ccir_to_jpeg[i] = Y_CCIR_TO_JPEG(i);
+ y_jpeg_to_ccir[i] = Y_JPEG_TO_CCIR(i);
+ c_ccir_to_jpeg[i] = C_CCIR_TO_JPEG(i);
+ c_jpeg_to_ccir[i] = C_JPEG_TO_CCIR(i);
+ }
+}
+
+/* apply to each pixel the given table */
+static void img_apply_table(uint8_t *dst, int dst_wrap,
+ const uint8_t *src, int src_wrap,
+ int width, int height, const uint8_t *table1)
+{
+ int n;
+ const uint8_t *s;
+ uint8_t *d;
+ const uint8_t *table;
+
+ table = table1;
+ for(;height > 0; height--) {
+ s = src;
+ d = dst;
+ n = width;
+ while (n >= 4) {
+ d[0] = table[s[0]];
+ d[1] = table[s[1]];
+ d[2] = table[s[2]];
+ d[3] = table[s[3]];
+ d += 4;
+ s += 4;
+ n -= 4;
+ }
+ while (n > 0) {
+ d[0] = table[s[0]];
+ d++;
+ s++;
+ n--;
+ }
+ dst += dst_wrap;
+ src += src_wrap;
+ }
+}
+
+/* XXX: use generic filter ? */
+/* XXX: in most cases, the sampling position is incorrect */
+
+/* 4x1 -> 1x1 */
+static void shrink41(uint8_t *dst, int dst_wrap,
+ const uint8_t *src, int src_wrap,
+ int width, int height)
+{
+ int w;
+ const uint8_t *s;
+ uint8_t *d;
+
+ for(;height > 0; height--) {
+ s = src;
+ d = dst;
+ for(w = width;w > 0; w--) {
+ d[0] = (s[0] + s[1] + s[2] + s[3] + 2) >> 2;
+ s += 4;
+ d++;
+ }
+ src += src_wrap;
+ dst += dst_wrap;
+ }
+}
+
+/* 2x1 -> 1x1 */
+static void shrink21(uint8_t *dst, int dst_wrap,
+ const uint8_t *src, int src_wrap,
+ int width, int height)
+{
+ int w;
+ const uint8_t *s;
+ uint8_t *d;
+
+ for(;height > 0; height--) {
+ s = src;
+ d = dst;
+ for(w = width;w > 0; w--) {
+ d[0] = (s[0] + s[1]) >> 1;
+ s += 2;
+ d++;
+ }
+ src += src_wrap;
+ dst += dst_wrap;
+ }
+}
+
+/* 1x2 -> 1x1 */
+static void shrink12(uint8_t *dst, int dst_wrap,
+ const uint8_t *src, int src_wrap,
+ int width, int height)
+{
+ int w;
+ uint8_t *d;
+ const uint8_t *s1, *s2;
+
+ for(;height > 0; height--) {
+ s1 = src;
+ s2 = s1 + src_wrap;
+ d = dst;
+ for(w = width;w >= 4; w-=4) {
+ d[0] = (s1[0] + s2[0]) >> 1;
+ d[1] = (s1[1] + s2[1]) >> 1;
+ d[2] = (s1[2] + s2[2]) >> 1;
+ d[3] = (s1[3] + s2[3]) >> 1;
+ s1 += 4;
+ s2 += 4;
+ d += 4;
+ }
+ for(;w > 0; w--) {
+ d[0] = (s1[0] + s2[0]) >> 1;
+ s1++;
+ s2++;
+ d++;
+ }
+ src += 2 * src_wrap;
+ dst += dst_wrap;
+ }
+}
+
+/* 2x2 -> 1x1 */
+void ff_shrink22(uint8_t *dst, int dst_wrap,
+ const uint8_t *src, int src_wrap,
+ int width, int height)
+{
+ int w;
+ const uint8_t *s1, *s2;
+ uint8_t *d;
+
+ for(;height > 0; height--) {
+ s1 = src;
+ s2 = s1 + src_wrap;
+ d = dst;
+ for(w = width;w >= 4; w-=4) {
+ d[0] = (s1[0] + s1[1] + s2[0] + s2[1] + 2) >> 2;
+ d[1] = (s1[2] + s1[3] + s2[2] + s2[3] + 2) >> 2;
+ d[2] = (s1[4] + s1[5] + s2[4] + s2[5] + 2) >> 2;
+ d[3] = (s1[6] + s1[7] + s2[6] + s2[7] + 2) >> 2;
+ s1 += 8;
+ s2 += 8;
+ d += 4;
+ }
+ for(;w > 0; w--) {
+ d[0] = (s1[0] + s1[1] + s2[0] + s2[1] + 2) >> 2;
+ s1 += 2;
+ s2 += 2;
+ d++;
+ }
+ src += 2 * src_wrap;
+ dst += dst_wrap;
+ }
+}
+
+/* 4x4 -> 1x1 */
+void ff_shrink44(uint8_t *dst, int dst_wrap,
+ const uint8_t *src, int src_wrap,
+ int width, int height)
+{
+ int w;
+ const uint8_t *s1, *s2, *s3, *s4;
+ uint8_t *d;
+
+ for(;height > 0; height--) {
+ s1 = src;
+ s2 = s1 + src_wrap;
+ s3 = s2 + src_wrap;
+ s4 = s3 + src_wrap;
+ d = dst;
+ for(w = width;w > 0; w--) {
+ d[0] = (s1[0] + s1[1] + s1[2] + s1[3] +
+ s2[0] + s2[1] + s2[2] + s2[3] +
+ s3[0] + s3[1] + s3[2] + s3[3] +
+ s4[0] + s4[1] + s4[2] + s4[3] + 8) >> 4;
+ s1 += 4;
+ s2 += 4;
+ s3 += 4;
+ s4 += 4;
+ d++;
+ }
+ src += 4 * src_wrap;
+ dst += dst_wrap;
+ }
+}
+
+/* 8x8 -> 1x1 */
+void ff_shrink88(uint8_t *dst, int dst_wrap,
+ const uint8_t *src, int src_wrap,
+ int width, int height)
+{
+ int w, i;
+
+ for(;height > 0; height--) {
+ for(w = width;w > 0; w--) {
+ int tmp=0;
+ for(i=0; i<8; i++){
+ tmp += src[0] + src[1] + src[2] + src[3] + src[4] + src[5] + src[6] + src[7];
+ src += src_wrap;
+ }
+ *(dst++) = (tmp + 32)>>6;
+ src += 8 - 8*src_wrap;
+ }
+ src += 8*src_wrap - 8*width;
+ dst += dst_wrap - width;
+ }
+}
+
+static void grow21_line(uint8_t *dst, const uint8_t *src,
+ int width)
+{
+ int w;
+ const uint8_t *s1;
+ uint8_t *d;
+
+ s1 = src;
+ d = dst;
+ for(w = width;w >= 4; w-=4) {
+ d[1] = d[0] = s1[0];
+ d[3] = d[2] = s1[1];
+ s1 += 2;
+ d += 4;
+ }
+ for(;w >= 2; w -= 2) {
+ d[1] = d[0] = s1[0];
+ s1 ++;
+ d += 2;
+ }
+ /* only needed if width is not a multiple of two */
+ /* XXX: veryfy that */
+ if (w) {
+ d[0] = s1[0];
+ }
+}
+
+static void grow41_line(uint8_t *dst, const uint8_t *src,
+ int width)
+{
+ int w, v;
+ const uint8_t *s1;
+ uint8_t *d;
+
+ s1 = src;
+ d = dst;
+ for(w = width;w >= 4; w-=4) {
+ v = s1[0];
+ d[0] = v;
+ d[1] = v;
+ d[2] = v;
+ d[3] = v;
+ s1 ++;
+ d += 4;
+ }
+}
+
+/* 1x1 -> 2x1 */
+static void grow21(uint8_t *dst, int dst_wrap,
+ const uint8_t *src, int src_wrap,
+ int width, int height)
+{
+ for(;height > 0; height--) {
+ grow21_line(dst, src, width);
+ src += src_wrap;
+ dst += dst_wrap;
+ }
+}
+
+/* 1x1 -> 2x2 */
+static void grow22(uint8_t *dst, int dst_wrap,
+ const uint8_t *src, int src_wrap,
+ int width, int height)
+{
+ for(;height > 0; height--) {
+ grow21_line(dst, src, width);
+ if (height%2)
+ src += src_wrap;
+ dst += dst_wrap;
+ }
+}
+
+/* 1x1 -> 4x1 */
+static void grow41(uint8_t *dst, int dst_wrap,
+ const uint8_t *src, int src_wrap,
+ int width, int height)
+{
+ for(;height > 0; height--) {
+ grow41_line(dst, src, width);
+ src += src_wrap;
+ dst += dst_wrap;
+ }
+}
+
+/* 1x1 -> 4x4 */
+static void grow44(uint8_t *dst, int dst_wrap,
+ const uint8_t *src, int src_wrap,
+ int width, int height)
+{
+ for(;height > 0; height--) {
+ grow41_line(dst, src, width);
+ if ((height & 3) == 1)
+ src += src_wrap;
+ dst += dst_wrap;
+ }
+}
+
+/* 1x2 -> 2x1 */
+static void conv411(uint8_t *dst, int dst_wrap,
+ const uint8_t *src, int src_wrap,
+ int width, int height)
+{
+ int w, c;
+ const uint8_t *s1, *s2;
+ uint8_t *d;
+
+ width>>=1;
+
+ for(;height > 0; height--) {
+ s1 = src;
+ s2 = src + src_wrap;
+ d = dst;
+ for(w = width;w > 0; w--) {
+ c = (s1[0] + s2[0]) >> 1;
+ d[0] = c;
+ d[1] = c;
+ s1++;
+ s2++;
+ d += 2;
+ }
+ src += src_wrap * 2;
+ dst += dst_wrap;
+ }
+}
+
+/* XXX: add jpeg quantize code */
+
+#define TRANSP_INDEX (6*6*6)
+
+/* this is maybe slow, but allows for extensions */
+static inline unsigned char gif_clut_index(uint8_t r, uint8_t g, uint8_t b)
+{
+ return ((((r)/47)%6)*6*6+(((g)/47)%6)*6+(((b)/47)%6));
+}
+
+static void build_rgb_palette(uint8_t *palette, int has_alpha)
+{
+ uint32_t *pal;
+ static const uint8_t pal_value[6] = { 0x00, 0x33, 0x66, 0x99, 0xcc, 0xff };
+ int i, r, g, b;
+
+ pal = (uint32_t *)palette;
+ i = 0;
+ for(r = 0; r < 6; r++) {
+ for(g = 0; g < 6; g++) {
+ for(b = 0; b < 6; b++) {
+ pal[i++] = (0xff << 24) | (pal_value[r] << 16) |
+ (pal_value[g] << 8) | pal_value[b];
+ }
+ }
+ }
+ if (has_alpha)
+ pal[i++] = 0;
+ while (i < 256)
+ pal[i++] = 0xff000000;
+}
+
+/* copy bit n to bits 0 ... n - 1 */
+static inline unsigned int bitcopy_n(unsigned int a, int n)
+{
+ int mask;
+ mask = (1 << n) - 1;
+ return (a & (0xff & ~mask)) | ((-((a >> n) & 1)) & mask);
+}
+
+/* rgb555 handling */
+
+#define RGB_NAME rgb555
+
+#define RGB_IN(r, g, b, s)\
+{\
+ unsigned int v = ((const uint16_t *)(s))[0];\
+ r = bitcopy_n(v >> (10 - 3), 3);\
+ g = bitcopy_n(v >> (5 - 3), 3);\
+ b = bitcopy_n(v << 3, 3);\
+}
+
+
+#define RGB_OUT(d, r, g, b)\
+{\
+ ((uint16_t *)(d))[0] = ((r >> 3) << 10) | ((g >> 3) << 5) | (b >> 3);\
+}
+
+#define BPP 2
+
+#include "imgconvert_template.h"
+
+/* rgb565 handling */
+
+#define RGB_NAME rgb565
+
+#define RGB_IN(r, g, b, s)\
+{\
+ unsigned int v = ((const uint16_t *)(s))[0];\
+ r = bitcopy_n(v >> (11 - 3), 3);\
+ g = bitcopy_n(v >> (5 - 2), 2);\
+ b = bitcopy_n(v << 3, 3);\
+}
+
+#define RGB_OUT(d, r, g, b)\
+{\
+ ((uint16_t *)(d))[0] = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3);\
+}
+
+#define BPP 2
+
+#include "imgconvert_template.h"
+
+/* bgr24 handling */
+
+#define RGB_NAME bgr24
+
+#define RGB_IN(r, g, b, s)\
+{\
+ b = (s)[0];\
+ g = (s)[1];\
+ r = (s)[2];\
+}
+
+#define RGB_OUT(d, r, g, b)\
+{\
+ (d)[0] = b;\
+ (d)[1] = g;\
+ (d)[2] = r;\
+}
+
+#define BPP 3
+
+#include "imgconvert_template.h"
+
+#undef RGB_IN
+#undef RGB_OUT
+#undef BPP
+
+/* rgb24 handling */
+
+#define RGB_NAME rgb24
+#define FMT_RGB24
+
+#define RGB_IN(r, g, b, s)\
+{\
+ r = (s)[0];\
+ g = (s)[1];\
+ b = (s)[2];\
+}
+
+#define RGB_OUT(d, r, g, b)\
+{\
+ (d)[0] = r;\
+ (d)[1] = g;\
+ (d)[2] = b;\
+}
+
+#define BPP 3
+
+#include "imgconvert_template.h"
+
+/* rgb32 handling */
+
+#define RGB_NAME rgb32
+#define FMT_RGB32
+
+#define RGB_IN(r, g, b, s)\
+{\
+ unsigned int v = ((const uint32_t *)(s))[0];\
+ r = (v >> 16) & 0xff;\
+ g = (v >> 8) & 0xff;\
+ b = v & 0xff;\
+}
+
+#define RGBA_IN(r, g, b, a, s)\
+{\
+ unsigned int v = ((const uint32_t *)(s))[0];\
+ a = (v >> 24) & 0xff;\
+ r = (v >> 16) & 0xff;\
+ g = (v >> 8) & 0xff;\
+ b = v & 0xff;\
+}
+
+#define RGBA_OUT(d, r, g, b, a)\
+{\
+ ((uint32_t *)(d))[0] = (a << 24) | (r << 16) | (g << 8) | b;\
+}
+
+#define BPP 4
+
+#include "imgconvert_template.h"
+
+static void mono_to_gray(AVPicture *dst, const AVPicture *src,
+ int width, int height, int xor_mask)
+{
+ const unsigned char *p;
+ unsigned char *q;
+ int v, dst_wrap, src_wrap;
+ int y, w;
+
+ p = src->data[0];
+ src_wrap = src->linesize[0] - ((width + 7) >> 3);
+
+ q = dst->data[0];
+ dst_wrap = dst->linesize[0] - width;
+ for(y=0;y<height;y++) {
+ w = width;
+ while (w >= 8) {
+ v = *p++ ^ xor_mask;
+ q[0] = -(v >> 7);
+ q[1] = -((v >> 6) & 1);
+ q[2] = -((v >> 5) & 1);
+ q[3] = -((v >> 4) & 1);
+ q[4] = -((v >> 3) & 1);
+ q[5] = -((v >> 2) & 1);
+ q[6] = -((v >> 1) & 1);
+ q[7] = -((v >> 0) & 1);
+ w -= 8;
+ q += 8;
+ }
+ if (w > 0) {
+ v = *p++ ^ xor_mask;
+ do {
+ q[0] = -((v >> 7) & 1);
+ q++;
+ v <<= 1;
+ } while (--w);
+ }
+ p += src_wrap;
+ q += dst_wrap;
+ }
+}
+
+static void monowhite_to_gray(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ mono_to_gray(dst, src, width, height, 0xff);
+}
+
+static void monoblack_to_gray(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ mono_to_gray(dst, src, width, height, 0x00);
+}
+
+static void gray_to_mono(AVPicture *dst, const AVPicture *src,
+ int width, int height, int xor_mask)
+{
+ int n;
+ const uint8_t *s;
+ uint8_t *d;
+ int j, b, v, n1, src_wrap, dst_wrap, y;
+
+ s = src->data[0];
+ src_wrap = src->linesize[0] - width;
+
+ d = dst->data[0];
+ dst_wrap = dst->linesize[0] - ((width + 7) >> 3);
+
+ for(y=0;y<height;y++) {
+ n = width;
+ while (n >= 8) {
+ v = 0;
+ for(j=0;j<8;j++) {
+ b = s[0];
+ s++;
+ v = (v << 1) | (b >> 7);
+ }
+ d[0] = v ^ xor_mask;
+ d++;
+ n -= 8;
+ }
+ if (n > 0) {
+ n1 = n;
+ v = 0;
+ while (n > 0) {
+ b = s[0];
+ s++;
+ v = (v << 1) | (b >> 7);
+ n--;
+ }
+ d[0] = (v << (8 - (n1 & 7))) ^ xor_mask;
+ d++;
+ }
+ s += src_wrap;
+ d += dst_wrap;
+ }
+}
+
+static void gray_to_monowhite(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ gray_to_mono(dst, src, width, height, 0xff);
+}
+
+static void gray_to_monoblack(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ gray_to_mono(dst, src, width, height, 0x00);
+}
+
+static void gray_to_gray16(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ int x, y, src_wrap, dst_wrap;
+ uint8_t *s, *d;
+ s = src->data[0];
+ src_wrap = src->linesize[0] - width;
+ d = dst->data[0];
+ dst_wrap = dst->linesize[0] - width * 2;
+ for(y=0; y<height; y++){
+ for(x=0; x<width; x++){
+ *d++ = *s;
+ *d++ = *s++;
+ }
+ s += src_wrap;
+ d += dst_wrap;
+ }
+}
+
+static void gray16_to_gray(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ int x, y, src_wrap, dst_wrap;
+ uint8_t *s, *d;
+ s = src->data[0];
+ src_wrap = src->linesize[0] - width * 2;
+ d = dst->data[0];
+ dst_wrap = dst->linesize[0] - width;
+ for(y=0; y<height; y++){
+ for(x=0; x<width; x++){
+ *d++ = *s;
+ s += 2;
+ }
+ s += src_wrap;
+ d += dst_wrap;
+ }
+}
+
+static void gray16be_to_gray(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ gray16_to_gray(dst, src, width, height);
+}
+
+static void gray16le_to_gray(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ gray16_to_gray(dst, src + 1, width, height);
+}
+
+static void gray16_to_gray16(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ int x, y, src_wrap, dst_wrap;
+ uint16_t *s, *d;
+ s = src->data[0];
+ src_wrap = (src->linesize[0] - width * 2)/2;
+ d = dst->data[0];
+ dst_wrap = (dst->linesize[0] - width * 2)/2;
+ for(y=0; y<height; y++){
+ for(x=0; x<width; x++){
+ *d++ = bswap_16(*s++);
+ }
+ s += src_wrap;
+ d += dst_wrap;
+ }
+}
+
+
+typedef struct ConvertEntry {
+ void (*convert)(AVPicture *dst,
+ const AVPicture *src, int width, int height);
+} ConvertEntry;
+
+/* Add each new convertion function in this table. In order to be able
+ to convert from any format to any format, the following constraints
+ must be satisfied:
+
+ - all FF_COLOR_RGB formats must convert to and from PIX_FMT_RGB24
+
+ - all FF_COLOR_GRAY formats must convert to and from PIX_FMT_GRAY8
+
+ - all FF_COLOR_RGB formats with alpha must convert to and from PIX_FMT_RGB32
+
+ - PIX_FMT_YUV444P and PIX_FMT_YUVJ444P must convert to and from
+ PIX_FMT_RGB24.
+
+ - PIX_FMT_422 must convert to and from PIX_FMT_422P.
+
+ The other conversion functions are just optimisations for common cases.
+*/
+static const ConvertEntry convert_table[PIX_FMT_NB][PIX_FMT_NB] = {
+ [PIX_FMT_YUV420P] = {
+ [PIX_FMT_YUYV422] = {
+ .convert = yuv420p_to_yuyv422,
+ },
+ [PIX_FMT_RGB555] = {
+ .convert = yuv420p_to_rgb555
+ },
+ [PIX_FMT_RGB565] = {
+ .convert = yuv420p_to_rgb565
+ },
+ [PIX_FMT_BGR24] = {
+ .convert = yuv420p_to_bgr24
+ },
+ [PIX_FMT_RGB24] = {
+ .convert = yuv420p_to_rgb24
+ },
+ [PIX_FMT_RGB32] = {
+ .convert = yuv420p_to_rgb32
+ },
+ [PIX_FMT_UYVY422] = {
+ .convert = yuv420p_to_uyvy422,
+ },
+ },
+ [PIX_FMT_YUV422P] = {
+ [PIX_FMT_YUYV422] = {
+ .convert = yuv422p_to_yuyv422,
+ },
+ [PIX_FMT_UYVY422] = {
+ .convert = yuv422p_to_uyvy422,
+ },
+ },
+ [PIX_FMT_YUV444P] = {
+ [PIX_FMT_RGB24] = {
+ .convert = yuv444p_to_rgb24
+ },
+ },
+ [PIX_FMT_YUVJ420P] = {
+ [PIX_FMT_RGB555] = {
+ .convert = yuvj420p_to_rgb555
+ },
+ [PIX_FMT_RGB565] = {
+ .convert = yuvj420p_to_rgb565
+ },
+ [PIX_FMT_BGR24] = {
+ .convert = yuvj420p_to_bgr24
+ },
+ [PIX_FMT_RGB24] = {
+ .convert = yuvj420p_to_rgb24
+ },
+ [PIX_FMT_RGB32] = {
+ .convert = yuvj420p_to_rgb32
+ },
+ },
+ [PIX_FMT_YUVJ444P] = {
+ [PIX_FMT_RGB24] = {
+ .convert = yuvj444p_to_rgb24
+ },
+ },
+ [PIX_FMT_YUYV422] = {
+ [PIX_FMT_YUV420P] = {
+ .convert = yuyv422_to_yuv420p,
+ },
+ [PIX_FMT_YUV422P] = {
+ .convert = yuyv422_to_yuv422p,
+ },
+ },
+ [PIX_FMT_UYVY422] = {
+ [PIX_FMT_YUV420P] = {
+ .convert = uyvy422_to_yuv420p,
+ },
+ [PIX_FMT_YUV422P] = {
+ .convert = uyvy422_to_yuv422p,
+ },
+ },
+ [PIX_FMT_RGB24] = {
+ [PIX_FMT_YUV420P] = {
+ .convert = rgb24_to_yuv420p
+ },
+ [PIX_FMT_RGB565] = {
+ .convert = rgb24_to_rgb565
+ },
+ [PIX_FMT_RGB555] = {
+ .convert = rgb24_to_rgb555
+ },
+ [PIX_FMT_RGB32] = {
+ .convert = rgb24_to_rgb32
+ },
+ [PIX_FMT_BGR24] = {
+ .convert = rgb24_to_bgr24
+ },
+ [PIX_FMT_GRAY8] = {
+ .convert = rgb24_to_gray
+ },
+ [PIX_FMT_PAL8] = {
+ .convert = rgb24_to_pal8
+ },
+ [PIX_FMT_YUV444P] = {
+ .convert = rgb24_to_yuv444p
+ },
+ [PIX_FMT_YUVJ420P] = {
+ .convert = rgb24_to_yuvj420p
+ },
+ [PIX_FMT_YUVJ444P] = {
+ .convert = rgb24_to_yuvj444p
+ },
+ },
+ [PIX_FMT_RGB32] = {
+ [PIX_FMT_RGB24] = {
+ .convert = rgb32_to_rgb24
+ },
+ [PIX_FMT_BGR24] = {
+ .convert = rgb32_to_bgr24
+ },
+ [PIX_FMT_RGB565] = {
+ .convert = rgb32_to_rgb565
+ },
+ [PIX_FMT_RGB555] = {
+ .convert = rgb32_to_rgb555
+ },
+ [PIX_FMT_PAL8] = {
+ .convert = rgb32_to_pal8
+ },
+ [PIX_FMT_YUV420P] = {
+ .convert = rgb32_to_yuv420p
+ },
+ [PIX_FMT_GRAY8] = {
+ .convert = rgb32_to_gray
+ },
+ },
+ [PIX_FMT_BGR24] = {
+ [PIX_FMT_RGB32] = {
+ .convert = bgr24_to_rgb32
+ },
+ [PIX_FMT_RGB24] = {
+ .convert = bgr24_to_rgb24
+ },
+ [PIX_FMT_YUV420P] = {
+ .convert = bgr24_to_yuv420p
+ },
+ [PIX_FMT_GRAY8] = {
+ .convert = bgr24_to_gray
+ },
+ },
+ [PIX_FMT_RGB555] = {
+ [PIX_FMT_RGB24] = {
+ .convert = rgb555_to_rgb24
+ },
+ [PIX_FMT_RGB32] = {
+ .convert = rgb555_to_rgb32
+ },
+ [PIX_FMT_YUV420P] = {
+ .convert = rgb555_to_yuv420p
+ },
+ [PIX_FMT_GRAY8] = {
+ .convert = rgb555_to_gray
+ },
+ },
+ [PIX_FMT_RGB565] = {
+ [PIX_FMT_RGB32] = {
+ .convert = rgb565_to_rgb32
+ },
+ [PIX_FMT_RGB24] = {
+ .convert = rgb565_to_rgb24
+ },
+ [PIX_FMT_YUV420P] = {
+ .convert = rgb565_to_yuv420p
+ },
+ [PIX_FMT_GRAY8] = {
+ .convert = rgb565_to_gray
+ },
+ },
+ [PIX_FMT_GRAY16BE] = {
+ [PIX_FMT_GRAY8] = {
+ .convert = gray16be_to_gray
+ },
+ [PIX_FMT_GRAY16LE] = {
+ .convert = gray16_to_gray16
+ },
+ },
+ [PIX_FMT_GRAY16LE] = {
+ [PIX_FMT_GRAY8] = {
+ .convert = gray16le_to_gray
+ },
+ [PIX_FMT_GRAY16BE] = {
+ .convert = gray16_to_gray16
+ },
+ },
+ [PIX_FMT_GRAY8] = {
+ [PIX_FMT_RGB555] = {
+ .convert = gray_to_rgb555
+ },
+ [PIX_FMT_RGB565] = {
+ .convert = gray_to_rgb565
+ },
+ [PIX_FMT_RGB24] = {
+ .convert = gray_to_rgb24
+ },
+ [PIX_FMT_BGR24] = {
+ .convert = gray_to_bgr24
+ },
+ [PIX_FMT_RGB32] = {
+ .convert = gray_to_rgb32
+ },
+ [PIX_FMT_MONOWHITE] = {
+ .convert = gray_to_monowhite
+ },
+ [PIX_FMT_MONOBLACK] = {
+ .convert = gray_to_monoblack
+ },
+ [PIX_FMT_GRAY16LE] = {
+ .convert = gray_to_gray16
+ },
+ [PIX_FMT_GRAY16BE] = {
+ .convert = gray_to_gray16
+ },
+ },
+ [PIX_FMT_MONOWHITE] = {
+ [PIX_FMT_GRAY8] = {
+ .convert = monowhite_to_gray
+ },
+ },
+ [PIX_FMT_MONOBLACK] = {
+ [PIX_FMT_GRAY8] = {
+ .convert = monoblack_to_gray
+ },
+ },
+ [PIX_FMT_PAL8] = {
+ [PIX_FMT_RGB555] = {
+ .convert = pal8_to_rgb555
+ },
+ [PIX_FMT_RGB565] = {
+ .convert = pal8_to_rgb565
+ },
+ [PIX_FMT_BGR24] = {
+ .convert = pal8_to_bgr24
+ },
+ [PIX_FMT_RGB24] = {
+ .convert = pal8_to_rgb24
+ },
+ [PIX_FMT_RGB32] = {
+ .convert = pal8_to_rgb32
+ },
+ },
+ [PIX_FMT_UYYVYY411] = {
+ [PIX_FMT_YUV411P] = {
+ .convert = uyyvyy411_to_yuv411p,
+ },
+ },
+
+};
+
+int avpicture_alloc(AVPicture *picture,
+ int pix_fmt, int width, int height)
+{
+ int size;
+ void *ptr;
+
+ size = avpicture_get_size(pix_fmt, width, height);
+ if(size<0)
+ goto fail;
+ ptr = av_malloc(size);
+ if (!ptr)
+ goto fail;
+ avpicture_fill(picture, ptr, pix_fmt, width, height);
+ return 0;
+ fail:
+ memset(picture, 0, sizeof(AVPicture));
+ return -1;
+}
+
+void avpicture_free(AVPicture *picture)
+{
+ av_free(picture->data[0]);
+}
+
+/* return true if yuv planar */
+static inline int is_yuv_planar(const PixFmtInfo *ps)
+{
+ return (ps->color_type == FF_COLOR_YUV ||
+ ps->color_type == FF_COLOR_YUV_JPEG) &&
+ ps->pixel_type == FF_PIXEL_PLANAR;
+}
+
+int av_picture_crop(AVPicture *dst, const AVPicture *src,
+ int pix_fmt, int top_band, int left_band)
+{
+ int y_shift;
+ int x_shift;
+
+ 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;
+
+ dst->data[0] = src->data[0] + (top_band * src->linesize[0]) + left_band;
+ dst->data[1] = src->data[1] + ((top_band >> y_shift) * src->linesize[1]) + (left_band >> x_shift);
+ dst->data[2] = src->data[2] + ((top_band >> y_shift) * src->linesize[2]) + (left_band >> x_shift);
+
+ dst->linesize[0] = src->linesize[0];
+ dst->linesize[1] = src->linesize[1];
+ dst->linesize[2] = src->linesize[2];
+ return 0;
+}
+
+int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width,
+ int pix_fmt, int padtop, int padbottom, int padleft, int padright,
+ int *color)
+{
+ uint8_t *optr;
+ int y_shift;
+ int x_shift;
+ int yheight;
+ int i, y;
+
+ if (pix_fmt < 0 || pix_fmt >= PIX_FMT_NB ||
+ !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;
+
+ if (padtop || padleft) {
+ memset(dst->data[i], color[i],
+ dst->linesize[i] * (padtop >> y_shift) + (padleft >> x_shift));
+ }
+
+ if (padleft || padright) {
+ optr = dst->data[i] + dst->linesize[i] * (padtop >> y_shift) +
+ (dst->linesize[i] - (padright >> x_shift));
+ yheight = (height - 1 - (padtop + padbottom)) >> y_shift;
+ for (y = 0; y < yheight; y++) {
+ memset(optr, color[i], (padleft + padright) >> x_shift);
+ optr += dst->linesize[i];
+ }
+ }
+
+ if (src) { /* first line */
+ uint8_t *iptr = src->data[i];
+ optr = dst->data[i] + dst->linesize[i] * (padtop >> y_shift) +
+ (padleft >> x_shift);
+ memcpy(optr, iptr, src->linesize[i]);
+ iptr += src->linesize[i];
+ optr = dst->data[i] + dst->linesize[i] * (padtop >> y_shift) +
+ (dst->linesize[i] - (padright >> x_shift));
+ yheight = (height - 1 - (padtop + padbottom)) >> y_shift;
+ for (y = 0; y < yheight; y++) {
+ memset(optr, color[i], (padleft + padright) >> x_shift);
+ memcpy(optr + ((padleft + padright) >> x_shift), iptr,
+ src->linesize[i]);
+ iptr += src->linesize[i];
+ optr += dst->linesize[i];
+ }
+ }
+
+ if (padbottom || padright) {
+ optr = dst->data[i] + dst->linesize[i] *
+ ((height - padbottom) >> y_shift) - (padright >> x_shift);
+ memset(optr, color[i],dst->linesize[i] *
+ (padbottom >> y_shift) + (padright >> x_shift));
+ }
+ }
+ return 0;
+}
+
+#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
+void img_copy(AVPicture *dst, const AVPicture *src,
+ int pix_fmt, int width, int height)
+{
+ av_picture_copy(dst, src, pix_fmt, width, height);
+}
+
+int img_crop(AVPicture *dst, const AVPicture *src,
+ int pix_fmt, int top_band, int left_band)
+{
+ return av_picture_crop(dst, src, pix_fmt, top_band, left_band);
+}
+
+int img_pad(AVPicture *dst, const AVPicture *src, int height, int width,
+ int pix_fmt, int padtop, int padbottom, int padleft, int padright,
+ int *color)
+{
+ return av_picture_pad(dst, src, height, width, pix_fmt, padtop, padbottom, padleft, padright, color);
+}
+#endif
+
+#ifndef CONFIG_SWSCALER
+/* XXX: always use linesize. Return -1 if not supported */
+int img_convert(AVPicture *dst, int dst_pix_fmt,
+ const AVPicture *src, int src_pix_fmt,
+ int src_width, int src_height)
+{
+ static int inited;
+ int i, ret, dst_width, dst_height, int_pix_fmt;
+ const PixFmtInfo *src_pix, *dst_pix;
+ const ConvertEntry *ce;
+ AVPicture tmp1, *tmp = &tmp1;
+
+ if (src_pix_fmt < 0 || src_pix_fmt >= PIX_FMT_NB ||
+ dst_pix_fmt < 0 || dst_pix_fmt >= PIX_FMT_NB)
+ return -1;
+ if (src_width <= 0 || src_height <= 0)
+ return 0;
+
+ if (!inited) {
+ inited = 1;
+ img_convert_init();
+ }
+
+ dst_width = src_width;
+ dst_height = src_height;
+
+ dst_pix = &pix_fmt_info[dst_pix_fmt];
+ src_pix = &pix_fmt_info[src_pix_fmt];
+ if (src_pix_fmt == dst_pix_fmt) {
+ /* no conversion needed: just copy */
+ av_picture_copy(dst, src, dst_pix_fmt, dst_width, dst_height);
+ return 0;
+ }
+
+ ce = &convert_table[src_pix_fmt][dst_pix_fmt];
+ if (ce->convert) {
+ /* specific conversion routine */
+ ce->convert(dst, src, dst_width, dst_height);
+ return 0;
+ }
+
+ /* gray to YUV */
+ if (is_yuv_planar(dst_pix) &&
+ src_pix_fmt == PIX_FMT_GRAY8) {
+ int w, h, y;
+ uint8_t *d;
+
+ if (dst_pix->color_type == FF_COLOR_YUV_JPEG) {
+ ff_img_copy_plane(dst->data[0], dst->linesize[0],
+ src->data[0], src->linesize[0],
+ dst_width, dst_height);
+ } else {
+ img_apply_table(dst->data[0], dst->linesize[0],
+ src->data[0], src->linesize[0],
+ dst_width, dst_height,
+ y_jpeg_to_ccir);
+ }
+ /* fill U and V with 128 */
+ w = dst_width;
+ h = dst_height;
+ w >>= dst_pix->x_chroma_shift;
+ h >>= dst_pix->y_chroma_shift;
+ for(i = 1; i <= 2; i++) {
+ d = dst->data[i];
+ for(y = 0; y< h; y++) {
+ memset(d, 128, w);
+ d += dst->linesize[i];
+ }
+ }
+ return 0;
+ }
+
+ /* YUV to gray */
+ if (is_yuv_planar(src_pix) &&
+ dst_pix_fmt == PIX_FMT_GRAY8) {
+ if (src_pix->color_type == FF_COLOR_YUV_JPEG) {
+ ff_img_copy_plane(dst->data[0], dst->linesize[0],
+ src->data[0], src->linesize[0],
+ dst_width, dst_height);
+ } else {
+ img_apply_table(dst->data[0], dst->linesize[0],
+ src->data[0], src->linesize[0],
+ dst_width, dst_height,
+ y_ccir_to_jpeg);
+ }
+ return 0;
+ }
+
+ /* YUV to YUV planar */
+ if (is_yuv_planar(dst_pix) && is_yuv_planar(src_pix)) {
+ int x_shift, y_shift, w, h, xy_shift;
+ void (*resize_func)(uint8_t *dst, int dst_wrap,
+ const uint8_t *src, int src_wrap,
+ int width, int height);
+
+ /* compute chroma size of the smallest dimensions */
+ w = dst_width;
+ h = dst_height;
+ if (dst_pix->x_chroma_shift >= src_pix->x_chroma_shift)
+ w >>= dst_pix->x_chroma_shift;
+ else
+ w >>= src_pix->x_chroma_shift;
+ if (dst_pix->y_chroma_shift >= src_pix->y_chroma_shift)
+ h >>= dst_pix->y_chroma_shift;
+ else
+ h >>= src_pix->y_chroma_shift;
+
+ x_shift = (dst_pix->x_chroma_shift - src_pix->x_chroma_shift);
+ y_shift = (dst_pix->y_chroma_shift - src_pix->y_chroma_shift);
+ xy_shift = ((x_shift & 0xf) << 4) | (y_shift & 0xf);
+ /* there must be filters for conversion at least from and to
+ YUV444 format */
+ switch(xy_shift) {
+ case 0x00:
+ resize_func = ff_img_copy_plane;
+ break;
+ case 0x10:
+ resize_func = shrink21;
+ break;
+ case 0x20:
+ resize_func = shrink41;
+ break;
+ case 0x01:
+ resize_func = shrink12;
+ break;
+ case 0x11:
+ resize_func = ff_shrink22;
+ break;
+ case 0x22:
+ resize_func = ff_shrink44;
+ break;
+ case 0xf0:
+ resize_func = grow21;
+ break;
+ case 0xe0:
+ resize_func = grow41;
+ break;
+ case 0xff:
+ resize_func = grow22;
+ break;
+ case 0xee:
+ resize_func = grow44;
+ break;
+ case 0xf1:
+ resize_func = conv411;
+ break;
+ default:
+ /* currently not handled */
+ goto no_chroma_filter;
+ }
+
+ ff_img_copy_plane(dst->data[0], dst->linesize[0],
+ src->data[0], src->linesize[0],
+ dst_width, dst_height);
+
+ for(i = 1;i <= 2; i++)
+ resize_func(dst->data[i], dst->linesize[i],
+ src->data[i], src->linesize[i],
+ dst_width>>dst_pix->x_chroma_shift, dst_height>>dst_pix->y_chroma_shift);
+ /* if yuv color space conversion is needed, we do it here on
+ the destination image */
+ if (dst_pix->color_type != src_pix->color_type) {
+ const uint8_t *y_table, *c_table;
+ if (dst_pix->color_type == FF_COLOR_YUV) {
+ y_table = y_jpeg_to_ccir;
+ c_table = c_jpeg_to_ccir;
+ } else {
+ y_table = y_ccir_to_jpeg;
+ c_table = c_ccir_to_jpeg;
+ }
+ img_apply_table(dst->data[0], dst->linesize[0],
+ dst->data[0], dst->linesize[0],
+ dst_width, dst_height,
+ y_table);
+
+ for(i = 1;i <= 2; i++)
+ img_apply_table(dst->data[i], dst->linesize[i],
+ dst->data[i], dst->linesize[i],
+ dst_width>>dst_pix->x_chroma_shift,
+ dst_height>>dst_pix->y_chroma_shift,
+ c_table);
+ }
+ return 0;
+ }
+ no_chroma_filter:
+
+ /* try to use an intermediate format */
+ if (src_pix_fmt == PIX_FMT_YUYV422 ||
+ dst_pix_fmt == PIX_FMT_YUYV422) {
+ /* specific case: convert to YUV422P first */
+ int_pix_fmt = PIX_FMT_YUV422P;
+ } else if (src_pix_fmt == PIX_FMT_UYVY422 ||
+ dst_pix_fmt == PIX_FMT_UYVY422) {
+ /* specific case: convert to YUV422P first */
+ int_pix_fmt = PIX_FMT_YUV422P;
+ } else if (src_pix_fmt == PIX_FMT_UYYVYY411 ||
+ dst_pix_fmt == PIX_FMT_UYYVYY411) {
+ /* specific case: convert to YUV411P first */
+ int_pix_fmt = PIX_FMT_YUV411P;
+ } else if ((src_pix->color_type == FF_COLOR_GRAY &&
+ src_pix_fmt != PIX_FMT_GRAY8) ||
+ (dst_pix->color_type == FF_COLOR_GRAY &&
+ dst_pix_fmt != PIX_FMT_GRAY8)) {
+ /* gray8 is the normalized format */
+ int_pix_fmt = PIX_FMT_GRAY8;
+ } else if ((is_yuv_planar(src_pix) &&
+ src_pix_fmt != PIX_FMT_YUV444P &&
+ src_pix_fmt != PIX_FMT_YUVJ444P)) {
+ /* yuv444 is the normalized format */
+ if (src_pix->color_type == FF_COLOR_YUV_JPEG)
+ int_pix_fmt = PIX_FMT_YUVJ444P;
+ else
+ int_pix_fmt = PIX_FMT_YUV444P;
+ } else if ((is_yuv_planar(dst_pix) &&
+ dst_pix_fmt != PIX_FMT_YUV444P &&
+ dst_pix_fmt != PIX_FMT_YUVJ444P)) {
+ /* yuv444 is the normalized format */
+ if (dst_pix->color_type == FF_COLOR_YUV_JPEG)
+ int_pix_fmt = PIX_FMT_YUVJ444P;
+ else
+ int_pix_fmt = PIX_FMT_YUV444P;
+ } else {
+ /* the two formats are rgb or gray8 or yuv[j]444p */
+ if (src_pix->is_alpha && dst_pix->is_alpha)
+ int_pix_fmt = PIX_FMT_RGB32;
+ else
+ int_pix_fmt = PIX_FMT_RGB24;
+ }
+ if (avpicture_alloc(tmp, int_pix_fmt, dst_width, dst_height) < 0)
+ return -1;
+ ret = -1;
+ if (img_convert(tmp, int_pix_fmt,
+ src, src_pix_fmt, src_width, src_height) < 0)
+ goto fail1;
+ if (img_convert(dst, dst_pix_fmt,
+ tmp, int_pix_fmt, dst_width, dst_height) < 0)
+ goto fail1;
+ ret = 0;
+ fail1:
+ avpicture_free(tmp);
+ return ret;
+}
+#endif
+
+/* NOTE: we scan all the pixels to have an exact information */
+static int get_alpha_info_pal8(const AVPicture *src, int width, int height)
+{
+ const unsigned char *p;
+ int src_wrap, ret, x, y;
+ unsigned int a;
+ uint32_t *palette = (uint32_t *)src->data[1];
+
+ p = src->data[0];
+ src_wrap = src->linesize[0] - width;
+ ret = 0;
+ for(y=0;y<height;y++) {
+ for(x=0;x<width;x++) {
+ a = palette[p[0]] >> 24;
+ if (a == 0x00) {
+ ret |= FF_ALPHA_TRANSP;
+ } else if (a != 0xff) {
+ ret |= FF_ALPHA_SEMI_TRANSP;
+ }
+ p++;
+ }
+ p += src_wrap;
+ }
+ return ret;
+}
+
+int img_get_alpha_info(const AVPicture *src,
+ int pix_fmt, int width, int height)
+{
+ const PixFmtInfo *pf = &pix_fmt_info[pix_fmt];
+ int ret;
+
+ pf = &pix_fmt_info[pix_fmt];
+ /* no alpha can be represented in format */
+ if (!pf->is_alpha)
+ return 0;
+ switch(pix_fmt) {
+ case PIX_FMT_RGB32:
+ ret = get_alpha_info_rgb32(src, width, height);
+ break;
+ case PIX_FMT_PAL8:
+ ret = get_alpha_info_pal8(src, width, height);
+ break;
+ default:
+ /* we do not know, so everything is indicated */
+ ret = FF_ALPHA_TRANSP | FF_ALPHA_SEMI_TRANSP;
+ break;
+ }
+ return ret;
+}
+
+#ifdef HAVE_MMX
+#define DEINT_INPLACE_LINE_LUM \
+ movd_m2r(lum_m4[0],mm0);\
+ movd_m2r(lum_m3[0],mm1);\
+ movd_m2r(lum_m2[0],mm2);\
+ movd_m2r(lum_m1[0],mm3);\
+ movd_m2r(lum[0],mm4);\
+ punpcklbw_r2r(mm7,mm0);\
+ movd_r2m(mm2,lum_m4[0]);\
+ punpcklbw_r2r(mm7,mm1);\
+ punpcklbw_r2r(mm7,mm2);\
+ punpcklbw_r2r(mm7,mm3);\
+ punpcklbw_r2r(mm7,mm4);\
+ paddw_r2r(mm3,mm1);\
+ psllw_i2r(1,mm2);\
+ paddw_r2r(mm4,mm0);\
+ psllw_i2r(2,mm1);\
+ paddw_r2r(mm6,mm2);\
+ paddw_r2r(mm2,mm1);\
+ psubusw_r2r(mm0,mm1);\
+ psrlw_i2r(3,mm1);\
+ packuswb_r2r(mm7,mm1);\
+ movd_r2m(mm1,lum_m2[0]);
+
+#define DEINT_LINE_LUM \
+ movd_m2r(lum_m4[0],mm0);\
+ movd_m2r(lum_m3[0],mm1);\
+ movd_m2r(lum_m2[0],mm2);\
+ movd_m2r(lum_m1[0],mm3);\
+ movd_m2r(lum[0],mm4);\
+ punpcklbw_r2r(mm7,mm0);\
+ punpcklbw_r2r(mm7,mm1);\
+ punpcklbw_r2r(mm7,mm2);\
+ punpcklbw_r2r(mm7,mm3);\
+ punpcklbw_r2r(mm7,mm4);\
+ paddw_r2r(mm3,mm1);\
+ psllw_i2r(1,mm2);\
+ paddw_r2r(mm4,mm0);\
+ psllw_i2r(2,mm1);\
+ paddw_r2r(mm6,mm2);\
+ paddw_r2r(mm2,mm1);\
+ psubusw_r2r(mm0,mm1);\
+ psrlw_i2r(3,mm1);\
+ packuswb_r2r(mm7,mm1);\
+ movd_r2m(mm1,dst[0]);
+#endif
+
+/* filter parameters: [-1 4 2 4 -1] // 8 */
+static void deinterlace_line(uint8_t *dst,
+ const uint8_t *lum_m4, const uint8_t *lum_m3,
+ const uint8_t *lum_m2, const uint8_t *lum_m1,
+ const uint8_t *lum,
+ int size)
+{
+#ifndef HAVE_MMX
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+ int sum;
+
+ for(;size > 0;size--) {
+ sum = -lum_m4[0];
+ sum += lum_m3[0] << 2;
+ sum += lum_m2[0] << 1;
+ sum += lum_m1[0] << 2;
+ sum += -lum[0];
+ dst[0] = cm[(sum + 4) >> 3];
+ lum_m4++;
+ lum_m3++;
+ lum_m2++;
+ lum_m1++;
+ lum++;
+ dst++;
+ }
+#else
+
+ {
+ mmx_t rounder;
+ rounder.uw[0]=4;
+ rounder.uw[1]=4;
+ rounder.uw[2]=4;
+ rounder.uw[3]=4;
+ pxor_r2r(mm7,mm7);
+ movq_m2r(rounder,mm6);
+ }
+ for (;size > 3; size-=4) {
+ DEINT_LINE_LUM
+ lum_m4+=4;
+ lum_m3+=4;
+ lum_m2+=4;
+ lum_m1+=4;
+ lum+=4;
+ dst+=4;
+ }
+#endif
+}
+static void deinterlace_line_inplace(uint8_t *lum_m4, uint8_t *lum_m3, uint8_t *lum_m2, uint8_t *lum_m1, uint8_t *lum,
+ int size)
+{
+#ifndef HAVE_MMX
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+ int sum;
+
+ for(;size > 0;size--) {
+ sum = -lum_m4[0];
+ sum += lum_m3[0] << 2;
+ sum += lum_m2[0] << 1;
+ lum_m4[0]=lum_m2[0];
+ sum += lum_m1[0] << 2;
+ sum += -lum[0];
+ lum_m2[0] = cm[(sum + 4) >> 3];
+ lum_m4++;
+ lum_m3++;
+ lum_m2++;
+ lum_m1++;
+ lum++;
+ }
+#else
+
+ {
+ mmx_t rounder;
+ rounder.uw[0]=4;
+ rounder.uw[1]=4;
+ rounder.uw[2]=4;
+ rounder.uw[3]=4;
+ pxor_r2r(mm7,mm7);
+ movq_m2r(rounder,mm6);
+ }
+ for (;size > 3; size-=4) {
+ DEINT_INPLACE_LINE_LUM
+ lum_m4+=4;
+ lum_m3+=4;
+ lum_m2+=4;
+ lum_m1+=4;
+ lum+=4;
+ }
+#endif
+}
+
+/* deinterlacing : 2 temporal taps, 3 spatial taps linear filter. The
+ top field is copied as is, but the bottom field is deinterlaced
+ against the top field. */
+static void deinterlace_bottom_field(uint8_t *dst, int dst_wrap,
+ const uint8_t *src1, int src_wrap,
+ int width, int height)
+{
+ const uint8_t *src_m2, *src_m1, *src_0, *src_p1, *src_p2;
+ int y;
+
+ src_m2 = src1;
+ src_m1 = src1;
+ src_0=&src_m1[src_wrap];
+ src_p1=&src_0[src_wrap];
+ src_p2=&src_p1[src_wrap];
+ for(y=0;y<(height-2);y+=2) {
+ memcpy(dst,src_m1,width);
+ dst += dst_wrap;
+ deinterlace_line(dst,src_m2,src_m1,src_0,src_p1,src_p2,width);
+ src_m2 = src_0;
+ src_m1 = src_p1;
+ src_0 = src_p2;
+ src_p1 += 2*src_wrap;
+ src_p2 += 2*src_wrap;
+ dst += dst_wrap;
+ }
+ memcpy(dst,src_m1,width);
+ dst += dst_wrap;
+ /* do last line */
+ deinterlace_line(dst,src_m2,src_m1,src_0,src_0,src_0,width);
+}
+
+static void deinterlace_bottom_field_inplace(uint8_t *src1, int src_wrap,
+ int width, int height)
+{
+ uint8_t *src_m1, *src_0, *src_p1, *src_p2;
+ int y;
+ uint8_t *buf;
+ buf = (uint8_t*)av_malloc(width);
+
+ src_m1 = src1;
+ memcpy(buf,src_m1,width);
+ src_0=&src_m1[src_wrap];
+ src_p1=&src_0[src_wrap];
+ src_p2=&src_p1[src_wrap];
+ for(y=0;y<(height-2);y+=2) {
+ deinterlace_line_inplace(buf,src_m1,src_0,src_p1,src_p2,width);
+ src_m1 = src_p1;
+ src_0 = src_p2;
+ src_p1 += 2*src_wrap;
+ src_p2 += 2*src_wrap;
+ }
+ /* do last line */
+ deinterlace_line_inplace(buf,src_m1,src_0,src_0,src_0,width);
+ av_free(buf);
+}
+
+int avpicture_deinterlace(AVPicture *dst, const AVPicture *src,
+ int pix_fmt, int width, int height)
+{
+ int i;
+
+ if (pix_fmt != PIX_FMT_YUV420P &&
+ pix_fmt != PIX_FMT_YUV422P &&
+ pix_fmt != PIX_FMT_YUV444P &&
+ pix_fmt != PIX_FMT_YUV411P)
+ return -1;
+ if ((width & 3) != 0 || (height & 3) != 0)
+ return -1;
+
+ for(i=0;i<3;i++) {
+ if (i == 1) {
+ switch(pix_fmt) {
+ case PIX_FMT_YUV420P:
+ width >>= 1;
+ height >>= 1;
+ break;
+ case PIX_FMT_YUV422P:
+ width >>= 1;
+ break;
+ case PIX_FMT_YUV411P:
+ width >>= 2;
+ break;
+ default:
+ break;
+ }
+ }
+ if (src == dst) {
+ deinterlace_bottom_field_inplace(dst->data[i], dst->linesize[i],
+ width, height);
+ } else {
+ deinterlace_bottom_field(dst->data[i],dst->linesize[i],
+ src->data[i], src->linesize[i],
+ width, height);
+ }
+ }
+#ifdef HAVE_MMX
+ emms();
+#endif
+ return 0;
+}
+
+#undef FIX
diff --git a/contrib/ffmpeg/libavcodec/imgconvert_template.h b/contrib/ffmpeg/libavcodec/imgconvert_template.h
new file mode 100644
index 000000000..70c090bad
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/imgconvert_template.h
@@ -0,0 +1,875 @@
+/*
+ * Templates for image convertion routines
+ * Copyright (c) 2001, 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
+ */
+
+#ifndef RGB_OUT
+#define RGB_OUT(d, r, g, b) RGBA_OUT(d, r, g, b, 0xff)
+#endif
+
+static void glue(yuv420p_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ const uint8_t *y1_ptr, *y2_ptr, *cb_ptr, *cr_ptr;
+ uint8_t *d, *d1, *d2;
+ int w, y, cb, cr, r_add, g_add, b_add, width2;
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+ unsigned int r, g, b;
+
+ d = dst->data[0];
+ y1_ptr = src->data[0];
+ cb_ptr = src->data[1];
+ cr_ptr = src->data[2];
+ width2 = (width + 1) >> 1;
+ for(;height >= 2; height -= 2) {
+ d1 = d;
+ d2 = d + dst->linesize[0];
+ y2_ptr = y1_ptr + src->linesize[0];
+ for(w = width; w >= 2; w -= 2) {
+ YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);
+ /* output 4 pixels */
+ YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
+ RGB_OUT(d1, r, g, b);
+
+ YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[1]);
+ RGB_OUT(d1 + BPP, r, g, b);
+
+ YUV_TO_RGB2_CCIR(r, g, b, y2_ptr[0]);
+ RGB_OUT(d2, r, g, b);
+
+ YUV_TO_RGB2_CCIR(r, g, b, y2_ptr[1]);
+ RGB_OUT(d2 + BPP, r, g, b);
+
+ d1 += 2 * BPP;
+ d2 += 2 * BPP;
+
+ y1_ptr += 2;
+ y2_ptr += 2;
+ cb_ptr++;
+ cr_ptr++;
+ }
+ /* handle odd width */
+ if (w) {
+ YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);
+ YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
+ RGB_OUT(d1, r, g, b);
+
+ YUV_TO_RGB2_CCIR(r, g, b, y2_ptr[0]);
+ RGB_OUT(d2, r, g, b);
+ d1 += BPP;
+ d2 += BPP;
+ y1_ptr++;
+ y2_ptr++;
+ cb_ptr++;
+ cr_ptr++;
+ }
+ d += 2 * dst->linesize[0];
+ y1_ptr += 2 * src->linesize[0] - width;
+ cb_ptr += src->linesize[1] - width2;
+ cr_ptr += src->linesize[2] - width2;
+ }
+ /* handle odd height */
+ if (height) {
+ d1 = d;
+ for(w = width; w >= 2; w -= 2) {
+ YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);
+ /* output 2 pixels */
+ YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
+ RGB_OUT(d1, r, g, b);
+
+ YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[1]);
+ RGB_OUT(d1 + BPP, r, g, b);
+
+ d1 += 2 * BPP;
+
+ y1_ptr += 2;
+ cb_ptr++;
+ cr_ptr++;
+ }
+ /* handle width */
+ if (w) {
+ YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);
+ /* output 2 pixels */
+ YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
+ RGB_OUT(d1, r, g, b);
+ d1 += BPP;
+
+ y1_ptr++;
+ cb_ptr++;
+ cr_ptr++;
+ }
+ }
+}
+
+static void glue(yuvj420p_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ const uint8_t *y1_ptr, *y2_ptr, *cb_ptr, *cr_ptr;
+ uint8_t *d, *d1, *d2;
+ int w, y, cb, cr, r_add, g_add, b_add, width2;
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+ unsigned int r, g, b;
+
+ d = dst->data[0];
+ y1_ptr = src->data[0];
+ cb_ptr = src->data[1];
+ cr_ptr = src->data[2];
+ width2 = (width + 1) >> 1;
+ for(;height >= 2; height -= 2) {
+ d1 = d;
+ d2 = d + dst->linesize[0];
+ y2_ptr = y1_ptr + src->linesize[0];
+ for(w = width; w >= 2; w -= 2) {
+ YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
+ /* output 4 pixels */
+ YUV_TO_RGB2(r, g, b, y1_ptr[0]);
+ RGB_OUT(d1, r, g, b);
+
+ YUV_TO_RGB2(r, g, b, y1_ptr[1]);
+ RGB_OUT(d1 + BPP, r, g, b);
+
+ YUV_TO_RGB2(r, g, b, y2_ptr[0]);
+ RGB_OUT(d2, r, g, b);
+
+ YUV_TO_RGB2(r, g, b, y2_ptr[1]);
+ RGB_OUT(d2 + BPP, r, g, b);
+
+ d1 += 2 * BPP;
+ d2 += 2 * BPP;
+
+ y1_ptr += 2;
+ y2_ptr += 2;
+ cb_ptr++;
+ cr_ptr++;
+ }
+ /* handle odd width */
+ if (w) {
+ YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
+ YUV_TO_RGB2(r, g, b, y1_ptr[0]);
+ RGB_OUT(d1, r, g, b);
+
+ YUV_TO_RGB2(r, g, b, y2_ptr[0]);
+ RGB_OUT(d2, r, g, b);
+ d1 += BPP;
+ d2 += BPP;
+ y1_ptr++;
+ y2_ptr++;
+ cb_ptr++;
+ cr_ptr++;
+ }
+ d += 2 * dst->linesize[0];
+ y1_ptr += 2 * src->linesize[0] - width;
+ cb_ptr += src->linesize[1] - width2;
+ cr_ptr += src->linesize[2] - width2;
+ }
+ /* handle odd height */
+ if (height) {
+ d1 = d;
+ for(w = width; w >= 2; w -= 2) {
+ YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
+ /* output 2 pixels */
+ YUV_TO_RGB2(r, g, b, y1_ptr[0]);
+ RGB_OUT(d1, r, g, b);
+
+ YUV_TO_RGB2(r, g, b, y1_ptr[1]);
+ RGB_OUT(d1 + BPP, r, g, b);
+
+ d1 += 2 * BPP;
+
+ y1_ptr += 2;
+ cb_ptr++;
+ cr_ptr++;
+ }
+ /* handle width */
+ if (w) {
+ YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
+ /* output 2 pixels */
+ YUV_TO_RGB2(r, g, b, y1_ptr[0]);
+ RGB_OUT(d1, r, g, b);
+ d1 += BPP;
+
+ y1_ptr++;
+ cb_ptr++;
+ cr_ptr++;
+ }
+ }
+}
+
+static void glue(RGB_NAME, _to_yuv420p)(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ int wrap, wrap3, width2;
+ int r, g, b, r1, g1, b1, w;
+ uint8_t *lum, *cb, *cr;
+ const uint8_t *p;
+
+ lum = dst->data[0];
+ cb = dst->data[1];
+ cr = dst->data[2];
+
+ width2 = (width + 1) >> 1;
+ wrap = dst->linesize[0];
+ wrap3 = src->linesize[0];
+ p = src->data[0];
+ for(;height>=2;height -= 2) {
+ for(w = width; w >= 2; w -= 2) {
+ RGB_IN(r, g, b, p);
+ r1 = r;
+ g1 = g;
+ b1 = b;
+ lum[0] = RGB_TO_Y_CCIR(r, g, b);
+
+ RGB_IN(r, g, b, p + BPP);
+ r1 += r;
+ g1 += g;
+ b1 += b;
+ lum[1] = RGB_TO_Y_CCIR(r, g, b);
+ p += wrap3;
+ lum += wrap;
+
+ RGB_IN(r, g, b, p);
+ r1 += r;
+ g1 += g;
+ b1 += b;
+ lum[0] = RGB_TO_Y_CCIR(r, g, b);
+
+ RGB_IN(r, g, b, p + BPP);
+ r1 += r;
+ g1 += g;
+ b1 += b;
+ lum[1] = RGB_TO_Y_CCIR(r, g, b);
+
+ cb[0] = RGB_TO_U_CCIR(r1, g1, b1, 2);
+ cr[0] = RGB_TO_V_CCIR(r1, g1, b1, 2);
+
+ cb++;
+ cr++;
+ p += -wrap3 + 2 * BPP;
+ lum += -wrap + 2;
+ }
+ if (w) {
+ RGB_IN(r, g, b, p);
+ r1 = r;
+ g1 = g;
+ b1 = b;
+ lum[0] = RGB_TO_Y_CCIR(r, g, b);
+ p += wrap3;
+ lum += wrap;
+ RGB_IN(r, g, b, p);
+ r1 += r;
+ g1 += g;
+ b1 += b;
+ lum[0] = RGB_TO_Y_CCIR(r, g, b);
+ cb[0] = RGB_TO_U_CCIR(r1, g1, b1, 1);
+ cr[0] = RGB_TO_V_CCIR(r1, g1, b1, 1);
+ cb++;
+ cr++;
+ p += -wrap3 + BPP;
+ lum += -wrap + 1;
+ }
+ p += wrap3 + (wrap3 - width * BPP);
+ lum += wrap + (wrap - width);
+ cb += dst->linesize[1] - width2;
+ cr += dst->linesize[2] - width2;
+ }
+ /* handle odd height */
+ if (height) {
+ for(w = width; w >= 2; w -= 2) {
+ RGB_IN(r, g, b, p);
+ r1 = r;
+ g1 = g;
+ b1 = b;
+ lum[0] = RGB_TO_Y_CCIR(r, g, b);
+
+ RGB_IN(r, g, b, p + BPP);
+ r1 += r;
+ g1 += g;
+ b1 += b;
+ lum[1] = RGB_TO_Y_CCIR(r, g, b);
+ cb[0] = RGB_TO_U_CCIR(r1, g1, b1, 1);
+ cr[0] = RGB_TO_V_CCIR(r1, g1, b1, 1);
+ cb++;
+ cr++;
+ p += 2 * BPP;
+ lum += 2;
+ }
+ if (w) {
+ RGB_IN(r, g, b, p);
+ lum[0] = RGB_TO_Y_CCIR(r, g, b);
+ cb[0] = RGB_TO_U_CCIR(r, g, b, 0);
+ cr[0] = RGB_TO_V_CCIR(r, g, b, 0);
+ }
+ }
+}
+
+static void glue(RGB_NAME, _to_gray)(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ const unsigned char *p;
+ unsigned char *q;
+ int r, g, b, dst_wrap, src_wrap;
+ int x, y;
+
+ p = src->data[0];
+ src_wrap = src->linesize[0] - BPP * width;
+
+ q = dst->data[0];
+ dst_wrap = dst->linesize[0] - width;
+
+ for(y=0;y<height;y++) {
+ for(x=0;x<width;x++) {
+ RGB_IN(r, g, b, p);
+ q[0] = RGB_TO_Y(r, g, b);
+ q++;
+ p += BPP;
+ }
+ p += src_wrap;
+ q += dst_wrap;
+ }
+}
+
+static void glue(gray_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ const unsigned char *p;
+ unsigned char *q;
+ int r, dst_wrap, src_wrap;
+ int x, y;
+
+ p = src->data[0];
+ src_wrap = src->linesize[0] - width;
+
+ q = dst->data[0];
+ dst_wrap = dst->linesize[0] - BPP * width;
+
+ for(y=0;y<height;y++) {
+ for(x=0;x<width;x++) {
+ r = p[0];
+ RGB_OUT(q, r, r, r);
+ q += BPP;
+ p ++;
+ }
+ p += src_wrap;
+ q += dst_wrap;
+ }
+}
+
+static void glue(pal8_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ const unsigned char *p;
+ unsigned char *q;
+ int r, g, b, dst_wrap, src_wrap;
+ int x, y;
+ uint32_t v;
+ const uint32_t *palette;
+
+ p = src->data[0];
+ src_wrap = src->linesize[0] - width;
+ palette = (uint32_t *)src->data[1];
+
+ q = dst->data[0];
+ dst_wrap = dst->linesize[0] - BPP * width;
+
+ for(y=0;y<height;y++) {
+ for(x=0;x<width;x++) {
+ v = palette[p[0]];
+ r = (v >> 16) & 0xff;
+ g = (v >> 8) & 0xff;
+ b = (v) & 0xff;
+#ifdef RGBA_OUT
+ {
+ int a;
+ a = (v >> 24) & 0xff;
+ RGBA_OUT(q, r, g, b, a);
+ }
+#else
+ RGB_OUT(q, r, g, b);
+#endif
+ q += BPP;
+ p ++;
+ }
+ p += src_wrap;
+ q += dst_wrap;
+ }
+}
+
+// RGB24 has optimised routines
+#if !defined(FMT_RGB32) && !defined(FMT_RGB24)
+/* alpha support */
+
+static void glue(rgb32_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ const uint8_t *s;
+ uint8_t *d;
+ int src_wrap, dst_wrap, j, y;
+ unsigned int v, r, g, b;
+#ifdef RGBA_OUT
+ unsigned int a;
+#endif
+
+ s = src->data[0];
+ src_wrap = src->linesize[0] - width * 4;
+
+ d = dst->data[0];
+ dst_wrap = dst->linesize[0] - width * BPP;
+
+ for(y=0;y<height;y++) {
+ for(j = 0;j < width; j++) {
+ v = ((const uint32_t *)(s))[0];
+ r = (v >> 16) & 0xff;
+ g = (v >> 8) & 0xff;
+ b = v & 0xff;
+#ifdef RGBA_OUT
+ a = (v >> 24) & 0xff;
+ RGBA_OUT(d, r, g, b, a);
+#else
+ RGB_OUT(d, r, g, b);
+#endif
+ s += 4;
+ d += BPP;
+ }
+ s += src_wrap;
+ d += dst_wrap;
+ }
+}
+
+static void glue(RGB_NAME, _to_rgb32)(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ const uint8_t *s;
+ uint8_t *d;
+ int src_wrap, dst_wrap, j, y;
+ unsigned int r, g, b;
+#ifdef RGBA_IN
+ unsigned int a;
+#endif
+
+ s = src->data[0];
+ src_wrap = src->linesize[0] - width * BPP;
+
+ d = dst->data[0];
+ dst_wrap = dst->linesize[0] - width * 4;
+
+ for(y=0;y<height;y++) {
+ for(j = 0;j < width; j++) {
+#ifdef RGBA_IN
+ RGBA_IN(r, g, b, a, s);
+ ((uint32_t *)(d))[0] = (a << 24) | (r << 16) | (g << 8) | b;
+#else
+ RGB_IN(r, g, b, s);
+ ((uint32_t *)(d))[0] = (0xff << 24) | (r << 16) | (g << 8) | b;
+#endif
+ d += 4;
+ s += BPP;
+ }
+ s += src_wrap;
+ d += dst_wrap;
+ }
+}
+
+#endif /* !defined(FMT_RGB32) */
+
+#ifndef FMT_RGB24
+
+static void glue(rgb24_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ const uint8_t *s;
+ uint8_t *d;
+ int src_wrap, dst_wrap, j, y;
+ unsigned int r, g, b;
+
+ s = src->data[0];
+ src_wrap = src->linesize[0] - width * 3;
+
+ d = dst->data[0];
+ dst_wrap = dst->linesize[0] - width * BPP;
+
+ for(y=0;y<height;y++) {
+ for(j = 0;j < width; j++) {
+ r = s[0];
+ g = s[1];
+ b = s[2];
+ RGB_OUT(d, r, g, b);
+ s += 3;
+ d += BPP;
+ }
+ s += src_wrap;
+ d += dst_wrap;
+ }
+}
+
+static void glue(RGB_NAME, _to_rgb24)(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ const uint8_t *s;
+ uint8_t *d;
+ int src_wrap, dst_wrap, j, y;
+ unsigned int r, g , b;
+
+ s = src->data[0];
+ src_wrap = src->linesize[0] - width * BPP;
+
+ d = dst->data[0];
+ dst_wrap = dst->linesize[0] - width * 3;
+
+ for(y=0;y<height;y++) {
+ for(j = 0;j < width; j++) {
+ RGB_IN(r, g, b, s)
+ d[0] = r;
+ d[1] = g;
+ d[2] = b;
+ d += 3;
+ s += BPP;
+ }
+ s += src_wrap;
+ d += dst_wrap;
+ }
+}
+
+#endif /* !FMT_RGB24 */
+
+#ifdef FMT_RGB24
+
+static void yuv444p_to_rgb24(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ const uint8_t *y1_ptr, *cb_ptr, *cr_ptr;
+ uint8_t *d, *d1;
+ int w, y, cb, cr, r_add, g_add, b_add;
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+ unsigned int r, g, b;
+
+ d = dst->data[0];
+ y1_ptr = src->data[0];
+ cb_ptr = src->data[1];
+ cr_ptr = src->data[2];
+ for(;height > 0; height --) {
+ d1 = d;
+ for(w = width; w > 0; w--) {
+ YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);
+
+ YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
+ RGB_OUT(d1, r, g, b);
+ d1 += BPP;
+
+ y1_ptr++;
+ cb_ptr++;
+ cr_ptr++;
+ }
+ d += dst->linesize[0];
+ y1_ptr += src->linesize[0] - width;
+ cb_ptr += src->linesize[1] - width;
+ cr_ptr += src->linesize[2] - width;
+ }
+}
+
+static void yuvj444p_to_rgb24(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ const uint8_t *y1_ptr, *cb_ptr, *cr_ptr;
+ uint8_t *d, *d1;
+ int w, y, cb, cr, r_add, g_add, b_add;
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+ unsigned int r, g, b;
+
+ d = dst->data[0];
+ y1_ptr = src->data[0];
+ cb_ptr = src->data[1];
+ cr_ptr = src->data[2];
+ for(;height > 0; height --) {
+ d1 = d;
+ for(w = width; w > 0; w--) {
+ YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
+
+ YUV_TO_RGB2(r, g, b, y1_ptr[0]);
+ RGB_OUT(d1, r, g, b);
+ d1 += BPP;
+
+ y1_ptr++;
+ cb_ptr++;
+ cr_ptr++;
+ }
+ d += dst->linesize[0];
+ y1_ptr += src->linesize[0] - width;
+ cb_ptr += src->linesize[1] - width;
+ cr_ptr += src->linesize[2] - width;
+ }
+}
+
+static void rgb24_to_yuv444p(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ int src_wrap, x, y;
+ int r, g, b;
+ uint8_t *lum, *cb, *cr;
+ const uint8_t *p;
+
+ lum = dst->data[0];
+ cb = dst->data[1];
+ cr = dst->data[2];
+
+ src_wrap = src->linesize[0] - width * BPP;
+ p = src->data[0];
+ for(y=0;y<height;y++) {
+ for(x=0;x<width;x++) {
+ RGB_IN(r, g, b, p);
+ lum[0] = RGB_TO_Y_CCIR(r, g, b);
+ cb[0] = RGB_TO_U_CCIR(r, g, b, 0);
+ cr[0] = RGB_TO_V_CCIR(r, g, b, 0);
+ p += BPP;
+ cb++;
+ cr++;
+ lum++;
+ }
+ p += src_wrap;
+ lum += dst->linesize[0] - width;
+ cb += dst->linesize[1] - width;
+ cr += dst->linesize[2] - width;
+ }
+}
+
+static void rgb24_to_yuvj420p(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ int wrap, wrap3, width2;
+ int r, g, b, r1, g1, b1, w;
+ uint8_t *lum, *cb, *cr;
+ const uint8_t *p;
+
+ lum = dst->data[0];
+ cb = dst->data[1];
+ cr = dst->data[2];
+
+ width2 = (width + 1) >> 1;
+ wrap = dst->linesize[0];
+ wrap3 = src->linesize[0];
+ p = src->data[0];
+ for(;height>=2;height -= 2) {
+ for(w = width; w >= 2; w -= 2) {
+ RGB_IN(r, g, b, p);
+ r1 = r;
+ g1 = g;
+ b1 = b;
+ lum[0] = RGB_TO_Y(r, g, b);
+
+ RGB_IN(r, g, b, p + BPP);
+ r1 += r;
+ g1 += g;
+ b1 += b;
+ lum[1] = RGB_TO_Y(r, g, b);
+ p += wrap3;
+ lum += wrap;
+
+ RGB_IN(r, g, b, p);
+ r1 += r;
+ g1 += g;
+ b1 += b;
+ lum[0] = RGB_TO_Y(r, g, b);
+
+ RGB_IN(r, g, b, p + BPP);
+ r1 += r;
+ g1 += g;
+ b1 += b;
+ lum[1] = RGB_TO_Y(r, g, b);
+
+ cb[0] = RGB_TO_U(r1, g1, b1, 2);
+ cr[0] = RGB_TO_V(r1, g1, b1, 2);
+
+ cb++;
+ cr++;
+ p += -wrap3 + 2 * BPP;
+ lum += -wrap + 2;
+ }
+ if (w) {
+ RGB_IN(r, g, b, p);
+ r1 = r;
+ g1 = g;
+ b1 = b;
+ lum[0] = RGB_TO_Y(r, g, b);
+ p += wrap3;
+ lum += wrap;
+ RGB_IN(r, g, b, p);
+ r1 += r;
+ g1 += g;
+ b1 += b;
+ lum[0] = RGB_TO_Y(r, g, b);
+ cb[0] = RGB_TO_U(r1, g1, b1, 1);
+ cr[0] = RGB_TO_V(r1, g1, b1, 1);
+ cb++;
+ cr++;
+ p += -wrap3 + BPP;
+ lum += -wrap + 1;
+ }
+ p += wrap3 + (wrap3 - width * BPP);
+ lum += wrap + (wrap - width);
+ cb += dst->linesize[1] - width2;
+ cr += dst->linesize[2] - width2;
+ }
+ /* handle odd height */
+ if (height) {
+ for(w = width; w >= 2; w -= 2) {
+ RGB_IN(r, g, b, p);
+ r1 = r;
+ g1 = g;
+ b1 = b;
+ lum[0] = RGB_TO_Y(r, g, b);
+
+ RGB_IN(r, g, b, p + BPP);
+ r1 += r;
+ g1 += g;
+ b1 += b;
+ lum[1] = RGB_TO_Y(r, g, b);
+ cb[0] = RGB_TO_U(r1, g1, b1, 1);
+ cr[0] = RGB_TO_V(r1, g1, b1, 1);
+ cb++;
+ cr++;
+ p += 2 * BPP;
+ lum += 2;
+ }
+ if (w) {
+ RGB_IN(r, g, b, p);
+ lum[0] = RGB_TO_Y(r, g, b);
+ cb[0] = RGB_TO_U(r, g, b, 0);
+ cr[0] = RGB_TO_V(r, g, b, 0);
+ }
+ }
+}
+
+static void rgb24_to_yuvj444p(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ int src_wrap, x, y;
+ int r, g, b;
+ uint8_t *lum, *cb, *cr;
+ const uint8_t *p;
+
+ lum = dst->data[0];
+ cb = dst->data[1];
+ cr = dst->data[2];
+
+ src_wrap = src->linesize[0] - width * BPP;
+ p = src->data[0];
+ for(y=0;y<height;y++) {
+ for(x=0;x<width;x++) {
+ RGB_IN(r, g, b, p);
+ lum[0] = RGB_TO_Y(r, g, b);
+ cb[0] = RGB_TO_U(r, g, b, 0);
+ cr[0] = RGB_TO_V(r, g, b, 0);
+ p += BPP;
+ cb++;
+ cr++;
+ lum++;
+ }
+ p += src_wrap;
+ lum += dst->linesize[0] - width;
+ cb += dst->linesize[1] - width;
+ cr += dst->linesize[2] - width;
+ }
+}
+
+#endif /* FMT_RGB24 */
+
+#if defined(FMT_RGB24) || defined(FMT_RGB32)
+
+static void glue(RGB_NAME, _to_pal8)(AVPicture *dst, const AVPicture *src,
+ int width, int height)
+{
+ const unsigned char *p;
+ unsigned char *q;
+ int dst_wrap, src_wrap;
+ int x, y, has_alpha;
+ unsigned int r, g, b;
+
+ p = src->data[0];
+ src_wrap = src->linesize[0] - BPP * width;
+
+ q = dst->data[0];
+ dst_wrap = dst->linesize[0] - width;
+ has_alpha = 0;
+
+ for(y=0;y<height;y++) {
+ for(x=0;x<width;x++) {
+#ifdef RGBA_IN
+ {
+ unsigned int a;
+ RGBA_IN(r, g, b, a, p);
+ /* crude approximation for alpha ! */
+ if (a < 0x80) {
+ has_alpha = 1;
+ q[0] = TRANSP_INDEX;
+ } else {
+ q[0] = gif_clut_index(r, g, b);
+ }
+ }
+#else
+ RGB_IN(r, g, b, p);
+ q[0] = gif_clut_index(r, g, b);
+#endif
+ q++;
+ p += BPP;
+ }
+ p += src_wrap;
+ q += dst_wrap;
+ }
+
+ build_rgb_palette(dst->data[1], has_alpha);
+}
+
+#endif /* defined(FMT_RGB24) || defined(FMT_RGB32) */
+
+#ifdef RGBA_IN
+
+static int glue(get_alpha_info_, RGB_NAME)(const AVPicture *src,
+ int width, int height)
+{
+ const unsigned char *p;
+ int src_wrap, ret, x, y;
+ unsigned int r, g, b, a;
+
+ p = src->data[0];
+ src_wrap = src->linesize[0] - BPP * width;
+ ret = 0;
+ for(y=0;y<height;y++) {
+ for(x=0;x<width;x++) {
+ RGBA_IN(r, g, b, a, p);
+ if (a == 0x00) {
+ ret |= FF_ALPHA_TRANSP;
+ } else if (a != 0xff) {
+ ret |= FF_ALPHA_SEMI_TRANSP;
+ }
+ p += BPP;
+ }
+ p += src_wrap;
+ }
+ return ret;
+}
+
+#endif /* RGBA_IN */
+
+#undef RGB_IN
+#undef RGBA_IN
+#undef RGB_OUT
+#undef RGBA_OUT
+#undef BPP
+#undef RGB_NAME
+#undef FMT_RGB24
+#undef FMT_RGB32
diff --git a/contrib/ffmpeg/libavcodec/imgresample.c b/contrib/ffmpeg/libavcodec/imgresample.c
new file mode 100644
index 000000000..2722d5acf
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/imgresample.c
@@ -0,0 +1,949 @@
+/*
+ * High quality image resampling with polyphase filters
+ * Copyright (c) 2001 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 imgresample.c
+ * High quality image resampling with polyphase filters .
+ */
+
+#include "avcodec.h"
+#include "swscale.h"
+#include "dsputil.h"
+
+#ifdef USE_FASTMEMCPY
+#include "libvo/fastmemcpy.h"
+#endif
+
+#define NB_COMPONENTS 3
+
+#define PHASE_BITS 4
+#define NB_PHASES (1 << PHASE_BITS)
+#define NB_TAPS 4
+#define FCENTER 1 /* index of the center of the filter */
+//#define TEST 1 /* Test it */
+
+#define POS_FRAC_BITS 16
+#define POS_FRAC (1 << POS_FRAC_BITS)
+/* 6 bits precision is needed for MMX */
+#define FILTER_BITS 8
+
+#define LINE_BUF_HEIGHT (NB_TAPS * 4)
+
+struct SwsContext {
+ struct ImgReSampleContext *resampling_ctx;
+ enum PixelFormat src_pix_fmt, dst_pix_fmt;
+};
+
+struct ImgReSampleContext {
+ int iwidth, iheight, owidth, oheight;
+ int topBand, bottomBand, leftBand, rightBand;
+ int padtop, padbottom, padleft, padright;
+ int pad_owidth, pad_oheight;
+ int h_incr, v_incr;
+ DECLARE_ALIGNED_8(int16_t, h_filters[NB_PHASES][NB_TAPS]); /* horizontal filters */
+ DECLARE_ALIGNED_8(int16_t, v_filters[NB_PHASES][NB_TAPS]); /* vertical filters */
+ uint8_t *line_buf;
+};
+
+void av_build_filter(int16_t *filter, double factor, int tap_count, int phase_count, int scale, int type);
+
+static inline int get_phase(int pos)
+{
+ return ((pos) >> (POS_FRAC_BITS - PHASE_BITS)) & ((1 << PHASE_BITS) - 1);
+}
+
+/* This function must be optimized */
+static void h_resample_fast(uint8_t *dst, int dst_width, const uint8_t *src,
+ int src_width, int src_start, int src_incr,
+ int16_t *filters)
+{
+ int src_pos, phase, sum, i;
+ const uint8_t *s;
+ int16_t *filter;
+
+ src_pos = src_start;
+ for(i=0;i<dst_width;i++) {
+#ifdef TEST
+ /* test */
+ if ((src_pos >> POS_FRAC_BITS) < 0 ||
+ (src_pos >> POS_FRAC_BITS) > (src_width - NB_TAPS))
+ av_abort();
+#endif
+ s = src + (src_pos >> POS_FRAC_BITS);
+ phase = get_phase(src_pos);
+ filter = filters + phase * NB_TAPS;
+#if NB_TAPS == 4
+ sum = s[0] * filter[0] +
+ s[1] * filter[1] +
+ s[2] * filter[2] +
+ s[3] * filter[3];
+#else
+ {
+ int j;
+ sum = 0;
+ for(j=0;j<NB_TAPS;j++)
+ sum += s[j] * filter[j];
+ }
+#endif
+ sum = sum >> FILTER_BITS;
+ if (sum < 0)
+ sum = 0;
+ else if (sum > 255)
+ sum = 255;
+ dst[0] = sum;
+ src_pos += src_incr;
+ dst++;
+ }
+}
+
+/* This function must be optimized */
+static void v_resample(uint8_t *dst, int dst_width, const uint8_t *src,
+ int wrap, int16_t *filter)
+{
+ int sum, i;
+ const uint8_t *s;
+
+ s = src;
+ for(i=0;i<dst_width;i++) {
+#if NB_TAPS == 4
+ sum = s[0 * wrap] * filter[0] +
+ s[1 * wrap] * filter[1] +
+ s[2 * wrap] * filter[2] +
+ s[3 * wrap] * filter[3];
+#else
+ {
+ int j;
+ uint8_t *s1 = s;
+
+ sum = 0;
+ for(j=0;j<NB_TAPS;j++) {
+ sum += s1[0] * filter[j];
+ s1 += wrap;
+ }
+ }
+#endif
+ sum = sum >> FILTER_BITS;
+ if (sum < 0)
+ sum = 0;
+ else if (sum > 255)
+ sum = 255;
+ dst[0] = sum;
+ dst++;
+ s++;
+ }
+}
+
+#ifdef HAVE_MMX
+
+#include "i386/mmx.h"
+
+#define FILTER4(reg) \
+{\
+ s = src + (src_pos >> POS_FRAC_BITS);\
+ phase = get_phase(src_pos);\
+ filter = filters + phase * NB_TAPS;\
+ movq_m2r(*s, reg);\
+ punpcklbw_r2r(mm7, reg);\
+ movq_m2r(*filter, mm6);\
+ pmaddwd_r2r(reg, mm6);\
+ movq_r2r(mm6, reg);\
+ psrlq_i2r(32, reg);\
+ paddd_r2r(mm6, reg);\
+ psrad_i2r(FILTER_BITS, reg);\
+ src_pos += src_incr;\
+}
+
+#define DUMP(reg) movq_r2m(reg, tmp); printf(#reg "=%016"PRIx64"\n", tmp.uq);
+
+/* XXX: do four pixels at a time */
+static void h_resample_fast4_mmx(uint8_t *dst, int dst_width,
+ const uint8_t *src, int src_width,
+ int src_start, int src_incr, int16_t *filters)
+{
+ int src_pos, phase;
+ const uint8_t *s;
+ int16_t *filter;
+ mmx_t tmp;
+
+ src_pos = src_start;
+ pxor_r2r(mm7, mm7);
+
+ while (dst_width >= 4) {
+
+ FILTER4(mm0);
+ FILTER4(mm1);
+ FILTER4(mm2);
+ FILTER4(mm3);
+
+ packuswb_r2r(mm7, mm0);
+ packuswb_r2r(mm7, mm1);
+ packuswb_r2r(mm7, mm3);
+ packuswb_r2r(mm7, mm2);
+ movq_r2m(mm0, tmp);
+ dst[0] = tmp.ub[0];
+ movq_r2m(mm1, tmp);
+ dst[1] = tmp.ub[0];
+ movq_r2m(mm2, tmp);
+ dst[2] = tmp.ub[0];
+ movq_r2m(mm3, tmp);
+ dst[3] = tmp.ub[0];
+ dst += 4;
+ dst_width -= 4;
+ }
+ while (dst_width > 0) {
+ FILTER4(mm0);
+ packuswb_r2r(mm7, mm0);
+ movq_r2m(mm0, tmp);
+ dst[0] = tmp.ub[0];
+ dst++;
+ dst_width--;
+ }
+ emms();
+}
+
+static void v_resample4_mmx(uint8_t *dst, int dst_width, const uint8_t *src,
+ int wrap, int16_t *filter)
+{
+ int sum, i, v;
+ const uint8_t *s;
+ mmx_t tmp;
+ mmx_t coefs[4];
+
+ for(i=0;i<4;i++) {
+ v = filter[i];
+ coefs[i].uw[0] = v;
+ coefs[i].uw[1] = v;
+ coefs[i].uw[2] = v;
+ coefs[i].uw[3] = v;
+ }
+
+ pxor_r2r(mm7, mm7);
+ s = src;
+ while (dst_width >= 4) {
+ movq_m2r(s[0 * wrap], mm0);
+ punpcklbw_r2r(mm7, mm0);
+ movq_m2r(s[1 * wrap], mm1);
+ punpcklbw_r2r(mm7, mm1);
+ movq_m2r(s[2 * wrap], mm2);
+ punpcklbw_r2r(mm7, mm2);
+ movq_m2r(s[3 * wrap], mm3);
+ punpcklbw_r2r(mm7, mm3);
+
+ pmullw_m2r(coefs[0], mm0);
+ pmullw_m2r(coefs[1], mm1);
+ pmullw_m2r(coefs[2], mm2);
+ pmullw_m2r(coefs[3], mm3);
+
+ paddw_r2r(mm1, mm0);
+ paddw_r2r(mm3, mm2);
+ paddw_r2r(mm2, mm0);
+ psraw_i2r(FILTER_BITS, mm0);
+
+ packuswb_r2r(mm7, mm0);
+ movq_r2m(mm0, tmp);
+
+ *(uint32_t *)dst = tmp.ud[0];
+ dst += 4;
+ s += 4;
+ dst_width -= 4;
+ }
+ while (dst_width > 0) {
+ sum = s[0 * wrap] * filter[0] +
+ s[1 * wrap] * filter[1] +
+ s[2 * wrap] * filter[2] +
+ s[3 * wrap] * filter[3];
+ sum = sum >> FILTER_BITS;
+ if (sum < 0)
+ sum = 0;
+ else if (sum > 255)
+ sum = 255;
+ dst[0] = sum;
+ dst++;
+ s++;
+ dst_width--;
+ }
+ emms();
+}
+#endif
+
+#ifdef HAVE_ALTIVEC
+typedef union {
+ vector unsigned char v;
+ unsigned char c[16];
+} vec_uc_t;
+
+typedef union {
+ vector signed short v;
+ signed short s[8];
+} vec_ss_t;
+
+void v_resample16_altivec(uint8_t *dst, int dst_width, const uint8_t *src,
+ int wrap, int16_t *filter)
+{
+ int sum, i;
+ const uint8_t *s;
+ vector unsigned char *tv, tmp, dstv, zero;
+ vec_ss_t srchv[4], srclv[4], fv[4];
+ vector signed short zeros, sumhv, sumlv;
+ s = src;
+
+ for(i=0;i<4;i++)
+ {
+ /*
+ The vec_madds later on does an implicit >>15 on the result.
+ Since FILTER_BITS is 8, and we have 15 bits of magnitude in
+ a signed short, we have just enough bits to pre-shift our
+ filter constants <<7 to compensate for vec_madds.
+ */
+ fv[i].s[0] = filter[i] << (15-FILTER_BITS);
+ fv[i].v = vec_splat(fv[i].v, 0);
+ }
+
+ zero = vec_splat_u8(0);
+ zeros = vec_splat_s16(0);
+
+
+ /*
+ When we're resampling, we'd ideally like both our input buffers,
+ and output buffers to be 16-byte aligned, so we can do both aligned
+ reads and writes. Sadly we can't always have this at the moment, so
+ we opt for aligned writes, as unaligned writes have a huge overhead.
+ To do this, do enough scalar resamples to get dst 16-byte aligned.
+ */
+ i = (-(int)dst) & 0xf;
+ while(i>0) {
+ sum = s[0 * wrap] * filter[0] +
+ s[1 * wrap] * filter[1] +
+ s[2 * wrap] * filter[2] +
+ s[3 * wrap] * filter[3];
+ sum = sum >> FILTER_BITS;
+ if (sum<0) sum = 0; else if (sum>255) sum=255;
+ dst[0] = sum;
+ dst++;
+ s++;
+ dst_width--;
+ i--;
+ }
+
+ /* Do our altivec resampling on 16 pixels at once. */
+ while(dst_width>=16) {
+ /*
+ Read 16 (potentially unaligned) bytes from each of
+ 4 lines into 4 vectors, and split them into shorts.
+ Interleave the multipy/accumulate for the resample
+ filter with the loads to hide the 3 cycle latency
+ the vec_madds have.
+ */
+ tv = (vector unsigned char *) &s[0 * wrap];
+ tmp = vec_perm(tv[0], tv[1], vec_lvsl(0, &s[i * wrap]));
+ srchv[0].v = (vector signed short) vec_mergeh(zero, tmp);
+ srclv[0].v = (vector signed short) vec_mergel(zero, tmp);
+ sumhv = vec_madds(srchv[0].v, fv[0].v, zeros);
+ sumlv = vec_madds(srclv[0].v, fv[0].v, zeros);
+
+ tv = (vector unsigned char *) &s[1 * wrap];
+ tmp = vec_perm(tv[0], tv[1], vec_lvsl(0, &s[1 * wrap]));
+ srchv[1].v = (vector signed short) vec_mergeh(zero, tmp);
+ srclv[1].v = (vector signed short) vec_mergel(zero, tmp);
+ sumhv = vec_madds(srchv[1].v, fv[1].v, sumhv);
+ sumlv = vec_madds(srclv[1].v, fv[1].v, sumlv);
+
+ tv = (vector unsigned char *) &s[2 * wrap];
+ tmp = vec_perm(tv[0], tv[1], vec_lvsl(0, &s[2 * wrap]));
+ srchv[2].v = (vector signed short) vec_mergeh(zero, tmp);
+ srclv[2].v = (vector signed short) vec_mergel(zero, tmp);
+ sumhv = vec_madds(srchv[2].v, fv[2].v, sumhv);
+ sumlv = vec_madds(srclv[2].v, fv[2].v, sumlv);
+
+ tv = (vector unsigned char *) &s[3 * wrap];
+ tmp = vec_perm(tv[0], tv[1], vec_lvsl(0, &s[3 * wrap]));
+ srchv[3].v = (vector signed short) vec_mergeh(zero, tmp);
+ srclv[3].v = (vector signed short) vec_mergel(zero, tmp);
+ sumhv = vec_madds(srchv[3].v, fv[3].v, sumhv);
+ sumlv = vec_madds(srclv[3].v, fv[3].v, sumlv);
+
+ /*
+ Pack the results into our destination vector,
+ and do an aligned write of that back to memory.
+ */
+ dstv = vec_packsu(sumhv, sumlv) ;
+ vec_st(dstv, 0, (vector unsigned char *) dst);
+
+ dst+=16;
+ s+=16;
+ dst_width-=16;
+ }
+
+ /*
+ If there are any leftover pixels, resample them
+ with the slow scalar method.
+ */
+ while(dst_width>0) {
+ sum = s[0 * wrap] * filter[0] +
+ s[1 * wrap] * filter[1] +
+ s[2 * wrap] * filter[2] +
+ s[3 * wrap] * filter[3];
+ sum = sum >> FILTER_BITS;
+ if (sum<0) sum = 0; else if (sum>255) sum=255;
+ dst[0] = sum;
+ dst++;
+ s++;
+ dst_width--;
+ }
+}
+#endif
+
+/* slow version to handle limit cases. Does not need optimisation */
+static void h_resample_slow(uint8_t *dst, int dst_width,
+ const uint8_t *src, int src_width,
+ int src_start, int src_incr, int16_t *filters)
+{
+ int src_pos, phase, sum, j, v, i;
+ const uint8_t *s, *src_end;
+ int16_t *filter;
+
+ src_end = src + src_width;
+ src_pos = src_start;
+ for(i=0;i<dst_width;i++) {
+ s = src + (src_pos >> POS_FRAC_BITS);
+ phase = get_phase(src_pos);
+ filter = filters + phase * NB_TAPS;
+ sum = 0;
+ for(j=0;j<NB_TAPS;j++) {
+ if (s < src)
+ v = src[0];
+ else if (s >= src_end)
+ v = src_end[-1];
+ else
+ v = s[0];
+ sum += v * filter[j];
+ s++;
+ }
+ sum = sum >> FILTER_BITS;
+ if (sum < 0)
+ sum = 0;
+ else if (sum > 255)
+ sum = 255;
+ dst[0] = sum;
+ src_pos += src_incr;
+ dst++;
+ }
+}
+
+static void h_resample(uint8_t *dst, int dst_width, const uint8_t *src,
+ int src_width, int src_start, int src_incr,
+ int16_t *filters)
+{
+ int n, src_end;
+
+ if (src_start < 0) {
+ n = (0 - src_start + src_incr - 1) / src_incr;
+ h_resample_slow(dst, n, src, src_width, src_start, src_incr, filters);
+ dst += n;
+ dst_width -= n;
+ src_start += n * src_incr;
+ }
+ src_end = src_start + dst_width * src_incr;
+ if (src_end > ((src_width - NB_TAPS) << POS_FRAC_BITS)) {
+ n = (((src_width - NB_TAPS + 1) << POS_FRAC_BITS) - 1 - src_start) /
+ src_incr;
+ } else {
+ n = dst_width;
+ }
+#ifdef HAVE_MMX
+ if ((mm_flags & MM_MMX) && NB_TAPS == 4)
+ h_resample_fast4_mmx(dst, n,
+ src, src_width, src_start, src_incr, filters);
+ else
+#endif
+ h_resample_fast(dst, n,
+ src, src_width, src_start, src_incr, filters);
+ if (n < dst_width) {
+ dst += n;
+ dst_width -= n;
+ src_start += n * src_incr;
+ h_resample_slow(dst, dst_width,
+ src, src_width, src_start, src_incr, filters);
+ }
+}
+
+static void component_resample(ImgReSampleContext *s,
+ uint8_t *output, int owrap, int owidth, int oheight,
+ uint8_t *input, int iwrap, int iwidth, int iheight)
+{
+ int src_y, src_y1, last_src_y, ring_y, phase_y, y1, y;
+ uint8_t *new_line, *src_line;
+
+ last_src_y = - FCENTER - 1;
+ /* position of the bottom of the filter in the source image */
+ src_y = (last_src_y + NB_TAPS) * POS_FRAC;
+ ring_y = NB_TAPS; /* position in ring buffer */
+ for(y=0;y<oheight;y++) {
+ /* apply horizontal filter on new lines from input if needed */
+ src_y1 = src_y >> POS_FRAC_BITS;
+ while (last_src_y < src_y1) {
+ if (++ring_y >= LINE_BUF_HEIGHT + NB_TAPS)
+ ring_y = NB_TAPS;
+ last_src_y++;
+ /* handle limit conditions : replicate line (slightly
+ inefficient because we filter multiple times) */
+ y1 = last_src_y;
+ if (y1 < 0) {
+ y1 = 0;
+ } else if (y1 >= iheight) {
+ y1 = iheight - 1;
+ }
+ src_line = input + y1 * iwrap;
+ new_line = s->line_buf + ring_y * owidth;
+ /* apply filter and handle limit cases correctly */
+ h_resample(new_line, owidth,
+ src_line, iwidth, - FCENTER * POS_FRAC, s->h_incr,
+ &s->h_filters[0][0]);
+ /* handle ring buffer wraping */
+ if (ring_y >= LINE_BUF_HEIGHT) {
+ memcpy(s->line_buf + (ring_y - LINE_BUF_HEIGHT) * owidth,
+ new_line, owidth);
+ }
+ }
+ /* apply vertical filter */
+ phase_y = get_phase(src_y);
+#ifdef HAVE_MMX
+ /* desactivated MMX because loss of precision */
+ if ((mm_flags & MM_MMX) && NB_TAPS == 4 && 0)
+ v_resample4_mmx(output, owidth,
+ s->line_buf + (ring_y - NB_TAPS + 1) * owidth, owidth,
+ &s->v_filters[phase_y][0]);
+ else
+#endif
+#ifdef HAVE_ALTIVEC
+ if ((mm_flags & MM_ALTIVEC) && NB_TAPS == 4 && FILTER_BITS <= 6)
+ v_resample16_altivec(output, owidth,
+ s->line_buf + (ring_y - NB_TAPS + 1) * owidth, owidth,
+ &s->v_filters[phase_y][0]);
+ else
+#endif
+ v_resample(output, owidth,
+ s->line_buf + (ring_y - NB_TAPS + 1) * owidth, owidth,
+ &s->v_filters[phase_y][0]);
+
+ src_y += s->v_incr;
+
+ output += owrap;
+ }
+}
+
+ImgReSampleContext *img_resample_init(int owidth, int oheight,
+ int iwidth, int iheight)
+{
+ return img_resample_full_init(owidth, oheight, iwidth, iheight,
+ 0, 0, 0, 0, 0, 0, 0, 0);
+}
+
+ImgReSampleContext *img_resample_full_init(int owidth, int oheight,
+ int iwidth, int iheight,
+ int topBand, int bottomBand,
+ int leftBand, int rightBand,
+ int padtop, int padbottom,
+ int padleft, int padright)
+{
+ ImgReSampleContext *s;
+
+ if (!owidth || !oheight || !iwidth || !iheight)
+ return NULL;
+
+ s = av_mallocz(sizeof(ImgReSampleContext));
+ if (!s)
+ return NULL;
+ if((unsigned)owidth >= UINT_MAX / (LINE_BUF_HEIGHT + NB_TAPS))
+ return NULL;
+ s->line_buf = av_mallocz(owidth * (LINE_BUF_HEIGHT + NB_TAPS));
+ if (!s->line_buf)
+ goto fail;
+
+ s->owidth = owidth;
+ s->oheight = oheight;
+ s->iwidth = iwidth;
+ s->iheight = iheight;
+
+ s->topBand = topBand;
+ s->bottomBand = bottomBand;
+ s->leftBand = leftBand;
+ s->rightBand = rightBand;
+
+ s->padtop = padtop;
+ s->padbottom = padbottom;
+ s->padleft = padleft;
+ s->padright = padright;
+
+ s->pad_owidth = owidth - (padleft + padright);
+ s->pad_oheight = oheight - (padtop + padbottom);
+
+ s->h_incr = ((iwidth - leftBand - rightBand) * POS_FRAC) / s->pad_owidth;
+ s->v_incr = ((iheight - topBand - bottomBand) * POS_FRAC) / s->pad_oheight;
+
+ av_build_filter(&s->h_filters[0][0], (float) s->pad_owidth /
+ (float) (iwidth - leftBand - rightBand), NB_TAPS, NB_PHASES, 1<<FILTER_BITS, 0);
+ av_build_filter(&s->v_filters[0][0], (float) s->pad_oheight /
+ (float) (iheight - topBand - bottomBand), NB_TAPS, NB_PHASES, 1<<FILTER_BITS, 0);
+
+ return s;
+fail:
+ av_free(s);
+ return NULL;
+}
+
+void img_resample(ImgReSampleContext *s,
+ AVPicture *output, const AVPicture *input)
+{
+ int i, shift;
+ uint8_t* optr;
+
+ for (i=0;i<3;i++) {
+ shift = (i == 0) ? 0 : 1;
+
+ optr = output->data[i] + (((output->linesize[i] *
+ s->padtop) + s->padleft) >> shift);
+
+ component_resample(s, optr, output->linesize[i],
+ s->pad_owidth >> shift, s->pad_oheight >> shift,
+ input->data[i] + (input->linesize[i] *
+ (s->topBand >> shift)) + (s->leftBand >> shift),
+ input->linesize[i], ((s->iwidth - s->leftBand -
+ s->rightBand) >> shift),
+ (s->iheight - s->topBand - s->bottomBand) >> shift);
+ }
+}
+
+void img_resample_close(ImgReSampleContext *s)
+{
+ av_free(s->line_buf);
+ av_free(s);
+}
+
+struct SwsContext *sws_getContext(int srcW, int srcH, int srcFormat,
+ int dstW, int dstH, int dstFormat,
+ int flags, SwsFilter *srcFilter,
+ SwsFilter *dstFilter, double *param)
+{
+ struct SwsContext *ctx;
+
+ ctx = av_malloc(sizeof(struct SwsContext));
+ if (ctx == NULL) {
+ av_log(NULL, AV_LOG_ERROR, "Cannot allocate a resampling context!\n");
+
+ return NULL;
+ }
+
+ if ((srcH != dstH) || (srcW != dstW)) {
+ if ((srcFormat != PIX_FMT_YUV420P) || (dstFormat != PIX_FMT_YUV420P)) {
+ av_log(NULL, AV_LOG_INFO, "PIX_FMT_YUV420P will be used as an intermediate format for rescaling\n");
+ }
+ ctx->resampling_ctx = img_resample_init(dstW, dstH, srcW, srcH);
+ } else {
+ ctx->resampling_ctx = av_malloc(sizeof(ImgReSampleContext));
+ ctx->resampling_ctx->iheight = srcH;
+ ctx->resampling_ctx->iwidth = srcW;
+ ctx->resampling_ctx->oheight = dstH;
+ ctx->resampling_ctx->owidth = dstW;
+ }
+ ctx->src_pix_fmt = srcFormat;
+ ctx->dst_pix_fmt = dstFormat;
+
+ return ctx;
+}
+
+void sws_freeContext(struct SwsContext *ctx)
+{
+ if (!ctx)
+ return;
+ if ((ctx->resampling_ctx->iwidth != ctx->resampling_ctx->owidth) ||
+ (ctx->resampling_ctx->iheight != ctx->resampling_ctx->oheight)) {
+ img_resample_close(ctx->resampling_ctx);
+ } else {
+ av_free(ctx->resampling_ctx);
+ }
+ av_free(ctx);
+}
+
+
+/**
+ * Checks if context is valid or reallocs a new one instead.
+ * If context is NULL, just calls sws_getContext() to get a new one.
+ * Otherwise, checks if the parameters are the same already saved in context.
+ * If that is the case, returns the current context.
+ * Otherwise, frees context and gets a new one.
+ *
+ * Be warned that srcFilter, dstFilter are not checked, they are
+ * asumed to remain valid.
+ */
+struct SwsContext *sws_getCachedContext(struct SwsContext *ctx,
+ int srcW, int srcH, int srcFormat,
+ int dstW, int dstH, int dstFormat, int flags,
+ SwsFilter *srcFilter, SwsFilter *dstFilter, double *param)
+{
+ if (ctx != NULL) {
+ if ((ctx->resampling_ctx->iwidth != srcW) ||
+ (ctx->resampling_ctx->iheight != srcH) ||
+ (ctx->src_pix_fmt != srcFormat) ||
+ (ctx->resampling_ctx->owidth != dstW) ||
+ (ctx->resampling_ctx->oheight != dstH) ||
+ (ctx->dst_pix_fmt != dstFormat))
+ {
+ sws_freeContext(ctx);
+ ctx = NULL;
+ }
+ }
+ if (ctx == NULL) {
+ return sws_getContext(srcW, srcH, srcFormat,
+ dstW, dstH, dstFormat, flags,
+ srcFilter, dstFilter, param);
+ }
+ return ctx;
+}
+
+int sws_scale(struct SwsContext *ctx, uint8_t* src[], int srcStride[],
+ int srcSliceY, int srcSliceH, uint8_t* dst[], int dstStride[])
+{
+ AVPicture src_pict, dst_pict;
+ int i, res = 0;
+ AVPicture picture_format_temp;
+ AVPicture picture_resample_temp, *formatted_picture, *resampled_picture;
+ uint8_t *buf1 = NULL, *buf2 = NULL;
+ enum PixelFormat current_pix_fmt;
+
+ for (i = 0; i < 4; i++) {
+ src_pict.data[i] = src[i];
+ src_pict.linesize[i] = srcStride[i];
+ dst_pict.data[i] = dst[i];
+ dst_pict.linesize[i] = dstStride[i];
+ }
+ if ((ctx->resampling_ctx->iwidth != ctx->resampling_ctx->owidth) ||
+ (ctx->resampling_ctx->iheight != ctx->resampling_ctx->oheight)) {
+ /* We have to rescale the picture, but only YUV420P rescaling is supported... */
+
+ if (ctx->src_pix_fmt != PIX_FMT_YUV420P) {
+ int size;
+
+ /* create temporary picture for rescaling input*/
+ size = avpicture_get_size(PIX_FMT_YUV420P, ctx->resampling_ctx->iwidth, ctx->resampling_ctx->iheight);
+ buf1 = av_malloc(size);
+ if (!buf1) {
+ res = -1;
+ goto the_end;
+ }
+ formatted_picture = &picture_format_temp;
+ avpicture_fill((AVPicture*)formatted_picture, buf1,
+ PIX_FMT_YUV420P, ctx->resampling_ctx->iwidth, ctx->resampling_ctx->iheight);
+
+ if (img_convert((AVPicture*)formatted_picture, PIX_FMT_YUV420P,
+ &src_pict, ctx->src_pix_fmt,
+ ctx->resampling_ctx->iwidth, ctx->resampling_ctx->iheight) < 0) {
+
+ av_log(NULL, AV_LOG_ERROR, "pixel format conversion not handled\n");
+ res = -1;
+ goto the_end;
+ }
+ } else {
+ formatted_picture = &src_pict;
+ }
+
+ if (ctx->dst_pix_fmt != PIX_FMT_YUV420P) {
+ int size;
+
+ /* create temporary picture for rescaling output*/
+ size = avpicture_get_size(PIX_FMT_YUV420P, ctx->resampling_ctx->owidth, ctx->resampling_ctx->oheight);
+ buf2 = av_malloc(size);
+ if (!buf2) {
+ res = -1;
+ goto the_end;
+ }
+ resampled_picture = &picture_resample_temp;
+ avpicture_fill((AVPicture*)resampled_picture, buf2,
+ PIX_FMT_YUV420P, ctx->resampling_ctx->owidth, ctx->resampling_ctx->oheight);
+
+ } else {
+ resampled_picture = &dst_pict;
+ }
+
+ /* ...and finally rescale!!! */
+ img_resample(ctx->resampling_ctx, resampled_picture, formatted_picture);
+ current_pix_fmt = PIX_FMT_YUV420P;
+ } else {
+ resampled_picture = &src_pict;
+ current_pix_fmt = ctx->src_pix_fmt;
+ }
+
+ if (current_pix_fmt != ctx->dst_pix_fmt) {
+ if (img_convert(&dst_pict, ctx->dst_pix_fmt,
+ resampled_picture, current_pix_fmt,
+ ctx->resampling_ctx->owidth, ctx->resampling_ctx->oheight) < 0) {
+
+ av_log(NULL, AV_LOG_ERROR, "pixel format conversion not handled\n");
+
+ res = -1;
+ goto the_end;
+ }
+ } else if (resampled_picture != &dst_pict) {
+ av_picture_copy(&dst_pict, resampled_picture, current_pix_fmt,
+ ctx->resampling_ctx->owidth, ctx->resampling_ctx->oheight);
+ }
+
+the_end:
+ av_free(buf1);
+ av_free(buf2);
+ return res;
+}
+
+
+#ifdef TEST
+#include <stdio.h>
+
+/* input */
+#define XSIZE 256
+#define YSIZE 256
+uint8_t img[XSIZE * YSIZE];
+
+/* output */
+#define XSIZE1 512
+#define YSIZE1 512
+uint8_t img1[XSIZE1 * YSIZE1];
+uint8_t img2[XSIZE1 * YSIZE1];
+
+void save_pgm(const char *filename, uint8_t *img, int xsize, int ysize)
+{
+#undef fprintf
+ FILE *f;
+ f=fopen(filename,"w");
+ fprintf(f,"P5\n%d %d\n%d\n", xsize, ysize, 255);
+ fwrite(img,1, xsize * ysize,f);
+ fclose(f);
+#define fprintf please_use_av_log
+}
+
+static void dump_filter(int16_t *filter)
+{
+ int i, ph;
+
+ for(ph=0;ph<NB_PHASES;ph++) {
+ av_log(NULL, AV_LOG_INFO, "%2d: ", ph);
+ for(i=0;i<NB_TAPS;i++) {
+ av_log(NULL, AV_LOG_INFO, " %5.2f", filter[ph * NB_TAPS + i] / 256.0);
+ }
+ av_log(NULL, AV_LOG_INFO, "\n");
+ }
+}
+
+#ifdef HAVE_MMX
+int mm_flags;
+#endif
+
+int main(int argc, char **argv)
+{
+ int x, y, v, i, xsize, ysize;
+ ImgReSampleContext *s;
+ float fact, factors[] = { 1/2.0, 3.0/4.0, 1.0, 4.0/3.0, 16.0/9.0, 2.0 };
+ char buf[256];
+
+ /* build test image */
+ for(y=0;y<YSIZE;y++) {
+ for(x=0;x<XSIZE;x++) {
+ if (x < XSIZE/2 && y < YSIZE/2) {
+ if (x < XSIZE/4 && y < YSIZE/4) {
+ if ((x % 10) <= 6 &&
+ (y % 10) <= 6)
+ v = 0xff;
+ else
+ v = 0x00;
+ } else if (x < XSIZE/4) {
+ if (x & 1)
+ v = 0xff;
+ else
+ v = 0;
+ } else if (y < XSIZE/4) {
+ if (y & 1)
+ v = 0xff;
+ else
+ v = 0;
+ } else {
+ if (y < YSIZE*3/8) {
+ if ((y+x) & 1)
+ v = 0xff;
+ else
+ v = 0;
+ } else {
+ if (((x+3) % 4) <= 1 &&
+ ((y+3) % 4) <= 1)
+ v = 0xff;
+ else
+ v = 0x00;
+ }
+ }
+ } else if (x < XSIZE/2) {
+ v = ((x - (XSIZE/2)) * 255) / (XSIZE/2);
+ } else if (y < XSIZE/2) {
+ v = ((y - (XSIZE/2)) * 255) / (XSIZE/2);
+ } else {
+ v = ((x + y - XSIZE) * 255) / XSIZE;
+ }
+ img[(YSIZE - y) * XSIZE + (XSIZE - x)] = v;
+ }
+ }
+ save_pgm("/tmp/in.pgm", img, XSIZE, YSIZE);
+ for(i=0;i<sizeof(factors)/sizeof(float);i++) {
+ fact = factors[i];
+ xsize = (int)(XSIZE * fact);
+ ysize = (int)((YSIZE - 100) * fact);
+ s = img_resample_full_init(xsize, ysize, XSIZE, YSIZE, 50 ,50, 0, 0, 0, 0, 0, 0);
+ av_log(NULL, AV_LOG_INFO, "Factor=%0.2f\n", fact);
+ dump_filter(&s->h_filters[0][0]);
+ component_resample(s, img1, xsize, xsize, ysize,
+ img + 50 * XSIZE, XSIZE, XSIZE, YSIZE - 100);
+ img_resample_close(s);
+
+ snprintf(buf, sizeof(buf), "/tmp/out%d.pgm", i);
+ save_pgm(buf, img1, xsize, ysize);
+ }
+
+ /* mmx test */
+#ifdef HAVE_MMX
+ av_log(NULL, AV_LOG_INFO, "MMX test\n");
+ fact = 0.72;
+ xsize = (int)(XSIZE * fact);
+ ysize = (int)(YSIZE * fact);
+ mm_flags = MM_MMX;
+ s = img_resample_init(xsize, ysize, XSIZE, YSIZE);
+ component_resample(s, img1, xsize, xsize, ysize,
+ img, XSIZE, XSIZE, YSIZE);
+
+ mm_flags = 0;
+ s = img_resample_init(xsize, ysize, XSIZE, YSIZE);
+ component_resample(s, img2, xsize, xsize, ysize,
+ img, XSIZE, XSIZE, YSIZE);
+ if (memcmp(img1, img2, xsize * ysize) != 0) {
+ av_log(NULL, AV_LOG_ERROR, "mmx error\n");
+ exit(1);
+ }
+ av_log(NULL, AV_LOG_INFO, "MMX OK\n");
+#endif
+ return 0;
+}
+
+#endif
diff --git a/contrib/ffmpeg/libavcodec/indeo2.c b/contrib/ffmpeg/libavcodec/indeo2.c
new file mode 100644
index 000000000..2b129d141
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/indeo2.c
@@ -0,0 +1,221 @@
+/*
+ * Intel Indeo 2 codec
+ * Copyright (c) 2005 Konstantin Shishkov
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * @file indeo2.c
+ * Intel Indeo 2 decoder.
+ */
+#define ALT_BITSTREAM_READER_LE
+#include "avcodec.h"
+#include "bitstream.h"
+#include "indeo2data.h"
+
+typedef struct Ir2Context{
+ AVCodecContext *avctx;
+ AVFrame picture;
+ GetBitContext gb;
+ int decode_delta;
+} Ir2Context;
+
+#define CODE_VLC_BITS 14
+static VLC ir2_vlc;
+
+/* Indeo 2 codes are in range 0x01..0x7F and 0x81..0x90 */
+static inline int ir2_get_code(GetBitContext *gb)
+{
+ return get_vlc2(gb, ir2_vlc.table, CODE_VLC_BITS, 1) + 1;
+}
+
+static int ir2_decode_plane(Ir2Context *ctx, int width, int height, uint8_t *dst, int stride,
+ const uint8_t *table)
+{
+ int i;
+ int j;
+ int out = 0;
+ int c;
+ int t;
+
+ if(width&1)
+ return -1;
+
+ /* first line contain absolute values, other lines contain deltas */
+ while (out < width){
+ c = ir2_get_code(&ctx->gb);
+ if(c >= 0x80) { /* we have a run */
+ c -= 0x7F;
+ if(out + c*2 > width)
+ return -1;
+ for (i = 0; i < c * 2; i++)
+ dst[out++] = 0x80;
+ } else { /* copy two values from table */
+ dst[out++] = table[c * 2];
+ dst[out++] = table[(c * 2) + 1];
+ }
+ }
+ dst += stride;
+
+ for (j = 1; j < height; j++){
+ out = 0;
+ while (out < width){
+ c = ir2_get_code(&ctx->gb);
+ if(c >= 0x80) { /* we have a skip */
+ c -= 0x7F;
+ if(out + c*2 > width)
+ return -1;
+ for (i = 0; i < c * 2; i++) {
+ dst[out] = dst[out - stride];
+ out++;
+ }
+ } else { /* add two deltas from table */
+ t = dst[out - stride] + (table[c * 2] - 128);
+ t= av_clip_uint8(t);
+ dst[out] = t;
+ out++;
+ t = dst[out - stride] + (table[(c * 2) + 1] - 128);
+ t= av_clip_uint8(t);
+ dst[out] = t;
+ out++;
+ }
+ }
+ dst += stride;
+ }
+ return 0;
+}
+
+static int ir2_decode_plane_inter(Ir2Context *ctx, int width, int height, uint8_t *dst, int stride,
+ const uint8_t *table)
+{
+ int j;
+ int out = 0;
+ int c;
+ int t;
+
+ if(width&1)
+ return -1;
+
+ for (j = 0; j < height; j++){
+ out = 0;
+ while (out < width){
+ c = ir2_get_code(&ctx->gb);
+ if(c >= 0x80) { /* we have a skip */
+ c -= 0x7F;
+ out += c * 2;
+ } else { /* add two deltas from table */
+ t = dst[out] + (((table[c * 2] - 128)*3) >> 2);
+ t= av_clip_uint8(t);
+ dst[out] = t;
+ out++;
+ t = dst[out] + (((table[(c * 2) + 1] - 128)*3) >> 2);
+ t= av_clip_uint8(t);
+ dst[out] = t;
+ out++;
+ }
+ }
+ dst += stride;
+ }
+ return 0;
+}
+
+static int ir2_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ Ir2Context * const s = avctx->priv_data;
+ AVFrame *picture = data;
+ AVFrame * const p= (AVFrame*)&s->picture;
+ int start;
+
+ if(p->data[0])
+ avctx->release_buffer(avctx, p);
+
+ p->reference = 1;
+ p->buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
+ if (avctx->reget_buffer(avctx, p)) {
+ av_log(s->avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
+ return -1;
+ }
+
+ s->decode_delta = buf[18];
+
+ /* 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]];
+#endif
+ start = 48; /* hardcoded for now */
+
+ init_get_bits(&s->gb, buf + start, buf_size - start);
+
+ if (s->decode_delta) { /* intraframe */
+ ir2_decode_plane(s, avctx->width, avctx->height,
+ s->picture.data[0], s->picture.linesize[0], ir2_luma_table);
+ /* swapped U and V */
+ ir2_decode_plane(s, avctx->width >> 2, avctx->height >> 2,
+ s->picture.data[2], s->picture.linesize[2], ir2_luma_table);
+ ir2_decode_plane(s, avctx->width >> 2, avctx->height >> 2,
+ s->picture.data[1], s->picture.linesize[1], ir2_luma_table);
+ } else { /* interframe */
+ ir2_decode_plane_inter(s, avctx->width, avctx->height,
+ s->picture.data[0], s->picture.linesize[0], ir2_luma_table);
+ /* swapped U and V */
+ ir2_decode_plane_inter(s, avctx->width >> 2, avctx->height >> 2,
+ s->picture.data[2], s->picture.linesize[2], ir2_luma_table);
+ ir2_decode_plane_inter(s, avctx->width >> 2, avctx->height >> 2,
+ s->picture.data[1], s->picture.linesize[1], ir2_luma_table);
+ }
+
+ *picture= *(AVFrame*)&s->picture;
+ *data_size = sizeof(AVPicture);
+
+ return buf_size;
+}
+
+static int ir2_decode_init(AVCodecContext *avctx){
+ Ir2Context * const ic = avctx->priv_data;
+
+ ic->avctx = avctx;
+
+ avctx->pix_fmt= PIX_FMT_YUV410P;
+
+ if (!ir2_vlc.table)
+ init_vlc(&ir2_vlc, CODE_VLC_BITS, IR2_CODES,
+ &ir2_codes[0][1], 4, 2,
+#ifdef ALT_BITSTREAM_READER_LE
+ &ir2_codes[0][0], 4, 2, INIT_VLC_USE_STATIC | INIT_VLC_LE);
+#else
+ &ir2_codes[0][0], 4, 2, INIT_VLC_USE_STATIC);
+#endif
+
+ return 0;
+}
+
+AVCodec indeo2_decoder = {
+ "indeo2",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_INDEO2,
+ sizeof(Ir2Context),
+ ir2_decode_init,
+ NULL,
+ NULL,
+ ir2_decode_frame,
+ CODEC_CAP_DR1,
+};
diff --git a/src/libffmpeg/libavcodec/indeo2data.h b/contrib/ffmpeg/libavcodec/indeo2data.h
index 71d250af7..71d250af7 100644
--- a/src/libffmpeg/libavcodec/indeo2data.h
+++ b/contrib/ffmpeg/libavcodec/indeo2data.h
diff --git a/contrib/ffmpeg/libavcodec/indeo3.c b/contrib/ffmpeg/libavcodec/indeo3.c
new file mode 100644
index 000000000..1b1914406
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/indeo3.c
@@ -0,0 +1,1149 @@
+/*
+ * Intel Indeo 3 (IV31, IV32, etc.) video decoder for ffmpeg
+ * written, produced, and directed by Alan Smithee
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "common.h"
+#include "avcodec.h"
+#include "dsputil.h"
+#include "mpegvideo.h"
+
+#include "indeo3data.h"
+
+typedef struct
+{
+ unsigned char *Ybuf;
+ unsigned char *Ubuf;
+ unsigned char *Vbuf;
+ unsigned char *the_buf;
+ unsigned int the_buf_size;
+ unsigned short y_w, y_h;
+ unsigned short uv_w, uv_h;
+} YUVBufs;
+
+typedef struct Indeo3DecodeContext {
+ AVCodecContext *avctx;
+ int width, height;
+ AVFrame frame;
+
+ YUVBufs iv_frame[2];
+ YUVBufs *cur_frame;
+ YUVBufs *ref_frame;
+
+ unsigned char *ModPred;
+ unsigned short *corrector_type;
+} Indeo3DecodeContext;
+
+static int corrector_type_0[24] = {
+ 195, 159, 133, 115, 101, 93, 87, 77,
+ 195, 159, 133, 115, 101, 93, 87, 77,
+ 128, 79, 79, 79, 79, 79, 79, 79
+};
+
+static int corrector_type_2[8] = { 9, 7, 6, 8, 5, 4, 3, 2 };
+
+static void build_modpred(Indeo3DecodeContext *s)
+{
+ int i, j;
+
+ s->ModPred = (unsigned char *) av_malloc (8 * 128);
+
+ for (i=0; i < 128; ++i) {
+ s->ModPred[i+0*128] = (i > 126) ? 254 : 2*((i + 1) - ((i + 1) % 2));
+ s->ModPred[i+1*128] = (i == 7) ? 20 : ((i == 119 || i == 120)
+ ? 236 : 2*((i + 2) - ((i + 1) % 3)));
+ s->ModPred[i+2*128] = (i > 125) ? 248 : 2*((i + 2) - ((i + 2) % 4));
+ s->ModPred[i+3*128] = 2*((i + 1) - ((i - 3) % 5));
+ s->ModPred[i+4*128] = (i == 8) ? 20 : 2*((i + 1) - ((i - 3) % 6));
+ s->ModPred[i+5*128] = 2*((i + 4) - ((i + 3) % 7));
+ s->ModPred[i+6*128] = (i > 123) ? 240 : 2*((i + 4) - ((i + 4) % 8));
+ s->ModPred[i+7*128] = 2*((i + 5) - ((i + 4) % 9));
+ }
+
+ s->corrector_type = (unsigned short *) av_malloc (24 * 256 * sizeof(unsigned short));
+
+ for (i=0; i < 24; ++i) {
+ for (j=0; j < 256; ++j) {
+ s->corrector_type[i*256+j] = (j < corrector_type_0[i])
+ ? 1 : ((j < 248 || (i == 16 && j == 248))
+ ? 0 : corrector_type_2[j - 248]);
+ }
+ }
+}
+
+static void iv_Decode_Chunk(Indeo3DecodeContext *s, unsigned char *cur,
+ unsigned char *ref, int width, int height, unsigned char *buf1,
+ long fflags2, unsigned char *hdr,
+ unsigned char *buf2, int min_width_160);
+
+/* ---------------------------------------------------------------------- */
+static void iv_alloc_frames(Indeo3DecodeContext *s)
+{
+ int luma_width, luma_height, luma_pixels, chroma_width, chroma_height,
+ chroma_pixels, i;
+ unsigned int bufsize;
+
+ luma_width = (s->width + 3) & (~3);
+ luma_height = (s->height + 3) & (~3);
+
+ s->iv_frame[0].y_w = s->iv_frame[0].y_h =
+ s->iv_frame[0].the_buf_size = 0;
+ s->iv_frame[1].y_w = s->iv_frame[1].y_h =
+ s->iv_frame[1].the_buf_size = 0;
+ s->iv_frame[1].the_buf = NULL;
+
+ chroma_width = ((luma_width >> 2) + 3) & (~3);
+ chroma_height = ((luma_height>> 2) + 3) & (~3);
+ luma_pixels = luma_width * luma_height;
+ chroma_pixels = chroma_width * chroma_height;
+
+ bufsize = luma_pixels * 2 + luma_width * 3 +
+ (chroma_pixels + chroma_width) * 4;
+
+ if((s->iv_frame[0].the_buf =
+ (s->iv_frame[0].the_buf_size == 0 ? av_malloc(bufsize) :
+ av_realloc(s->iv_frame[0].the_buf, bufsize))) == NULL)
+ return;
+ s->iv_frame[0].y_w = s->iv_frame[1].y_w = luma_width;
+ s->iv_frame[0].y_h = s->iv_frame[1].y_h = luma_height;
+ s->iv_frame[0].uv_w = s->iv_frame[1].uv_w = chroma_width;
+ s->iv_frame[0].uv_h = s->iv_frame[1].uv_h = chroma_height;
+ s->iv_frame[0].the_buf_size = bufsize;
+
+ s->iv_frame[0].Ybuf = s->iv_frame[0].the_buf + luma_width;
+ i = luma_pixels + luma_width * 2;
+ s->iv_frame[1].Ybuf = s->iv_frame[0].the_buf + i;
+ i += (luma_pixels + luma_width);
+ s->iv_frame[0].Ubuf = s->iv_frame[0].the_buf + i;
+ i += (chroma_pixels + chroma_width);
+ s->iv_frame[1].Ubuf = s->iv_frame[0].the_buf + i;
+ i += (chroma_pixels + chroma_width);
+ s->iv_frame[0].Vbuf = s->iv_frame[0].the_buf + i;
+ i += (chroma_pixels + chroma_width);
+ s->iv_frame[1].Vbuf = s->iv_frame[0].the_buf + i;
+
+ for(i = 1; i <= luma_width; i++)
+ s->iv_frame[0].Ybuf[-i] = s->iv_frame[1].Ybuf[-i] =
+ s->iv_frame[0].Ubuf[-i] = 0x80;
+
+ for(i = 1; i <= chroma_width; i++) {
+ s->iv_frame[1].Ubuf[-i] = 0x80;
+ s->iv_frame[0].Vbuf[-i] = 0x80;
+ s->iv_frame[1].Vbuf[-i] = 0x80;
+ s->iv_frame[1].Vbuf[chroma_pixels+i-1] = 0x80;
+ }
+}
+
+/* ---------------------------------------------------------------------- */
+static void iv_free_func(Indeo3DecodeContext *s)
+{
+ int i;
+
+ for(i = 0 ; i < 2 ; i++) {
+ if(s->iv_frame[i].the_buf != NULL)
+ av_free(s->iv_frame[i].the_buf);
+ s->iv_frame[i].Ybuf = s->iv_frame[i].Ubuf =
+ s->iv_frame[i].Vbuf = NULL;
+ s->iv_frame[i].the_buf = NULL;
+ s->iv_frame[i].the_buf_size = 0;
+ s->iv_frame[i].y_w = s->iv_frame[i].y_h = 0;
+ s->iv_frame[i].uv_w = s->iv_frame[i].uv_h = 0;
+ }
+
+ av_free(s->ModPred);
+ av_free(s->corrector_type);
+}
+
+/* ---------------------------------------------------------------------- */
+static unsigned long iv_decode_frame(Indeo3DecodeContext *s,
+ unsigned char *buf, int buf_size)
+{
+ unsigned int hdr_width, hdr_height,
+ chroma_width, chroma_height;
+ unsigned long fflags1, fflags2, fflags3, offs1, offs2, offs3, offs;
+ unsigned char *hdr_pos, *buf_pos;
+
+ buf_pos = buf;
+ buf_pos += 18;
+
+ fflags1 = le2me_16(*(uint16_t *)buf_pos);
+ buf_pos += 2;
+ fflags3 = le2me_32(*(uint32_t *)buf_pos);
+ buf_pos += 4;
+ fflags2 = *buf_pos++;
+ buf_pos += 3;
+ hdr_height = le2me_16(*(uint16_t *)buf_pos);
+ buf_pos += 2;
+ hdr_width = le2me_16(*(uint16_t *)buf_pos);
+
+ if(avcodec_check_dimensions(NULL, hdr_width, hdr_height))
+ return -1;
+
+ buf_pos += 2;
+ chroma_height = ((hdr_height >> 2) + 3) & 0x7ffc;
+ chroma_width = ((hdr_width >> 2) + 3) & 0x7ffc;
+ offs1 = le2me_32(*(uint32_t *)buf_pos);
+ buf_pos += 4;
+ offs2 = le2me_32(*(uint32_t *)buf_pos);
+ buf_pos += 4;
+ offs3 = le2me_32(*(uint32_t *)buf_pos);
+ buf_pos += 8;
+ hdr_pos = buf_pos;
+ if(fflags3 == 0x80) return 4;
+
+ if(fflags1 & 0x200) {
+ s->cur_frame = s->iv_frame + 1;
+ s->ref_frame = s->iv_frame;
+ } else {
+ s->cur_frame = s->iv_frame;
+ s->ref_frame = s->iv_frame + 1;
+ }
+
+ buf_pos = buf + 16 + offs1;
+ offs = le2me_32(*(uint32_t *)buf_pos);
+ buf_pos += 4;
+
+ iv_Decode_Chunk(s, s->cur_frame->Ybuf, s->ref_frame->Ybuf, hdr_width,
+ hdr_height, buf_pos + offs * 2, fflags2, hdr_pos, buf_pos,
+ FFMIN(hdr_width, 160));
+
+ if (!(s->avctx->flags & CODEC_FLAG_GRAY))
+ {
+
+ buf_pos = buf + 16 + offs2;
+ offs = le2me_32(*(uint32_t *)buf_pos);
+ buf_pos += 4;
+
+ iv_Decode_Chunk(s, s->cur_frame->Vbuf, s->ref_frame->Vbuf, chroma_width,
+ chroma_height, buf_pos + offs * 2, fflags2, hdr_pos, buf_pos,
+ FFMIN(chroma_width, 40));
+
+ buf_pos = buf + 16 + offs3;
+ offs = le2me_32(*(uint32_t *)buf_pos);
+ buf_pos += 4;
+
+ iv_Decode_Chunk(s, s->cur_frame->Ubuf, s->ref_frame->Ubuf, chroma_width,
+ chroma_height, buf_pos + offs * 2, fflags2, hdr_pos, buf_pos,
+ FFMIN(chroma_width, 40));
+
+ }
+
+ return 8;
+}
+
+typedef struct {
+ long xpos;
+ long ypos;
+ long width;
+ long height;
+ long split_flag;
+ long split_direction;
+ long usl7;
+} ustr_t;
+
+/* ---------------------------------------------------------------------- */
+
+#define LV1_CHECK(buf1,rle_v3,lv1,lp2) \
+ if((lv1 & 0x80) != 0) { \
+ if(rle_v3 != 0) \
+ rle_v3 = 0; \
+ else { \
+ rle_v3 = 1; \
+ buf1 -= 2; \
+ } \
+ } \
+ lp2 = 4;
+
+
+#define RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3) \
+ if(rle_v3 == 0) { \
+ rle_v2 = *buf1; \
+ rle_v1 = 1; \
+ if(rle_v2 > 32) { \
+ rle_v2 -= 32; \
+ rle_v1 = 0; \
+ } \
+ rle_v3 = 1; \
+ } \
+ buf1--;
+
+
+#define LP2_CHECK(buf1,rle_v3,lp2) \
+ if(lp2 == 0 && rle_v3 != 0) \
+ rle_v3 = 0; \
+ else { \
+ buf1--; \
+ rle_v3 = 1; \
+ }
+
+
+#define RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2) \
+ rle_v2--; \
+ if(rle_v2 == 0) { \
+ rle_v3 = 0; \
+ buf1 += 2; \
+ } \
+ lp2 = 4;
+
+static void iv_Decode_Chunk(Indeo3DecodeContext *s,
+ unsigned char *cur, unsigned char *ref, int width, int height,
+ unsigned char *buf1, long fflags2, unsigned char *hdr,
+ unsigned char *buf2, int min_width_160)
+{
+ unsigned char bit_buf;
+ unsigned long bit_pos, lv, lv1, lv2;
+ long *width_tbl, width_tbl_arr[10];
+ signed char *ref_vectors;
+ unsigned char *cur_frm_pos, *ref_frm_pos, *cp, *cp2;
+ uint32_t *cur_lp, *ref_lp;
+ const uint32_t *correction_lp[2], *correctionloworder_lp[2], *correctionhighorder_lp[2];
+ unsigned short *correction_type_sp[2];
+ ustr_t strip_tbl[20], *strip;
+ int i, j, k, lp1, lp2, flag1, cmd, blks_width, blks_height, region_160_width,
+ rle_v1, rle_v2, rle_v3;
+ unsigned short res;
+
+ bit_buf = 0;
+ ref_vectors = NULL;
+
+ width_tbl = width_tbl_arr + 1;
+ i = (width < 0 ? width + 3 : width)/4;
+ for(j = -1; j < 8; j++)
+ width_tbl[j] = i * j;
+
+ strip = strip_tbl;
+
+ for(region_160_width = 0; region_160_width < (width - min_width_160); region_160_width += min_width_160);
+
+ strip->ypos = strip->xpos = 0;
+ for(strip->width = min_width_160; width > strip->width; strip->width *= 2);
+ strip->height = height;
+ strip->split_direction = 0;
+ strip->split_flag = 0;
+ strip->usl7 = 0;
+
+ bit_pos = 0;
+
+ rle_v1 = rle_v2 = rle_v3 = 0;
+
+ while(strip >= strip_tbl) {
+ if(bit_pos <= 0) {
+ bit_pos = 8;
+ bit_buf = *buf1++;
+ }
+
+ bit_pos -= 2;
+ cmd = (bit_buf >> bit_pos) & 0x03;
+
+ if(cmd == 0) {
+ strip++;
+ memcpy(strip, strip-1, sizeof(ustr_t));
+ strip->split_flag = 1;
+ strip->split_direction = 0;
+ strip->height = (strip->height > 8 ? ((strip->height+8)>>4)<<3 : 4);
+ continue;
+ } else if(cmd == 1) {
+ strip++;
+ memcpy(strip, strip-1, sizeof(ustr_t));
+ strip->split_flag = 1;
+ strip->split_direction = 1;
+ strip->width = (strip->width > 8 ? ((strip->width+8)>>4)<<3 : 4);
+ continue;
+ } else if(cmd == 2) {
+ if(strip->usl7 == 0) {
+ strip->usl7 = 1;
+ ref_vectors = NULL;
+ continue;
+ }
+ } else if(cmd == 3) {
+ if(strip->usl7 == 0) {
+ strip->usl7 = 1;
+ ref_vectors = (signed char*)buf2 + (*buf1 * 2);
+ buf1++;
+ continue;
+ }
+ }
+
+ cur_frm_pos = cur + width * strip->ypos + strip->xpos;
+
+ if((blks_width = strip->width) < 0)
+ blks_width += 3;
+ blks_width >>= 2;
+ blks_height = strip->height;
+
+ if(ref_vectors != NULL) {
+ ref_frm_pos = ref + (ref_vectors[0] + strip->ypos) * width +
+ ref_vectors[1] + strip->xpos;
+ } else
+ ref_frm_pos = cur_frm_pos - width_tbl[4];
+
+ if(cmd == 2) {
+ if(bit_pos <= 0) {
+ bit_pos = 8;
+ bit_buf = *buf1++;
+ }
+
+ bit_pos -= 2;
+ cmd = (bit_buf >> bit_pos) & 0x03;
+
+ if(cmd == 0 || ref_vectors != NULL) {
+ for(lp1 = 0; lp1 < blks_width; lp1++) {
+ for(i = 0, j = 0; i < blks_height; i++, j += width_tbl[1])
+ ((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)ref_frm_pos)[j];
+ cur_frm_pos += 4;
+ ref_frm_pos += 4;
+ }
+ } else if(cmd != 1)
+ return;
+ } else {
+ k = *buf1 >> 4;
+ j = *buf1 & 0x0f;
+ buf1++;
+ lv = j + fflags2;
+
+ if((lv - 8) <= 7 && (k == 0 || k == 3 || k == 10)) {
+ cp2 = s->ModPred + ((lv - 8) << 7);
+ cp = ref_frm_pos;
+ for(i = 0; i < blks_width << 2; i++) {
+ int v = *cp >> 1;
+ *(cp++) = cp2[v];
+ }
+ }
+
+ if(k == 1 || k == 4) {
+ lv = (hdr[j] & 0xf) + fflags2;
+ correction_type_sp[0] = s->corrector_type + (lv << 8);
+ correction_lp[0] = correction + (lv << 8);
+ lv = (hdr[j] >> 4) + fflags2;
+ correction_lp[1] = correction + (lv << 8);
+ correction_type_sp[1] = s->corrector_type + (lv << 8);
+ } else {
+ correctionloworder_lp[0] = correctionloworder_lp[1] = correctionloworder + (lv << 8);
+ correctionhighorder_lp[0] = correctionhighorder_lp[1] = correctionhighorder + (lv << 8);
+ correction_type_sp[0] = correction_type_sp[1] = s->corrector_type + (lv << 8);
+ correction_lp[0] = correction_lp[1] = correction + (lv << 8);
+ }
+
+ switch(k) {
+ case 1:
+ case 0: /********** CASE 0 **********/
+ for( ; blks_height > 0; blks_height -= 4) {
+ for(lp1 = 0; lp1 < blks_width; lp1++) {
+ for(lp2 = 0; lp2 < 4; ) {
+ k = *buf1++;
+ cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2];
+ ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2];
+
+ switch(correction_type_sp[0][k]) {
+ case 0:
+ *cur_lp = le2me_32(((le2me_32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
+ lp2++;
+ break;
+ case 1:
+ res = ((le2me_16(((unsigned short *)(ref_lp))[0]) >> 1) + correction_lp[lp2 & 0x01][*buf1]) << 1;
+ ((unsigned short *)cur_lp)[0] = le2me_16(res);
+ res = ((le2me_16(((unsigned short *)(ref_lp))[1]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1;
+ ((unsigned short *)cur_lp)[1] = le2me_16(res);
+ buf1++;
+ lp2++;
+ break;
+ case 2:
+ if(lp2 == 0) {
+ for(i = 0, j = 0; i < 2; i++, j += width_tbl[1])
+ cur_lp[j] = ref_lp[j];
+ lp2 += 2;
+ }
+ break;
+ case 3:
+ if(lp2 < 2) {
+ for(i = 0, j = 0; i < (3 - lp2); i++, j += width_tbl[1])
+ cur_lp[j] = ref_lp[j];
+ lp2 = 3;
+ }
+ break;
+ case 8:
+ if(lp2 == 0) {
+ RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
+
+ if(rle_v1 == 1 || ref_vectors != NULL) {
+ for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
+ cur_lp[j] = ref_lp[j];
+ }
+
+ RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
+ break;
+ } else {
+ rle_v1 = 1;
+ rle_v2 = *buf1 - 1;
+ }
+ case 5:
+ LP2_CHECK(buf1,rle_v3,lp2)
+ case 4:
+ for(i = 0, j = 0; i < (4 - lp2); i++, j += width_tbl[1])
+ cur_lp[j] = ref_lp[j];
+ lp2 = 4;
+ break;
+
+ case 7:
+ if(rle_v3 != 0)
+ rle_v3 = 0;
+ else {
+ buf1--;
+ rle_v3 = 1;
+ }
+ case 6:
+ if(ref_vectors != NULL) {
+ for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
+ cur_lp[j] = ref_lp[j];
+ }
+ lp2 = 4;
+ break;
+
+ case 9:
+ lv1 = *buf1++;
+ lv = (lv1 & 0x7F) << 1;
+ lv += (lv << 8);
+ lv += (lv << 16);
+ for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
+ cur_lp[j] = lv;
+
+ LV1_CHECK(buf1,rle_v3,lv1,lp2)
+ break;
+ default:
+ return;
+ }
+ }
+
+ cur_frm_pos += 4;
+ ref_frm_pos += 4;
+ }
+
+ cur_frm_pos += ((width - blks_width) * 4);
+ ref_frm_pos += ((width - blks_width) * 4);
+ }
+ break;
+
+ case 4:
+ case 3: /********** CASE 3 **********/
+ if(ref_vectors != NULL)
+ return;
+ flag1 = 1;
+
+ for( ; blks_height > 0; blks_height -= 8) {
+ for(lp1 = 0; lp1 < blks_width; lp1++) {
+ for(lp2 = 0; lp2 < 4; ) {
+ k = *buf1++;
+
+ cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2];
+ ref_lp = ((uint32_t *)cur_frm_pos) + width_tbl[(lp2 * 2) - 1];
+
+ switch(correction_type_sp[lp2 & 0x01][k]) {
+ case 0:
+ cur_lp[width_tbl[1]] = le2me_32(((le2me_32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
+ if(lp2 > 0 || flag1 == 0 || strip->ypos != 0)
+ cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
+ else
+ cur_lp[0] = le2me_32(((le2me_32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
+ lp2++;
+ break;
+
+ case 1:
+ res = ((le2me_16(((unsigned short *)ref_lp)[0]) >> 1) + correction_lp[lp2 & 0x01][*buf1]) << 1;
+ ((unsigned short *)cur_lp)[width_tbl[2]] = le2me_16(res);
+ res = ((le2me_16(((unsigned short *)ref_lp)[1]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1;
+ ((unsigned short *)cur_lp)[width_tbl[2]+1] = le2me_16(res);
+
+ if(lp2 > 0 || flag1 == 0 || strip->ypos != 0)
+ cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
+ else
+ cur_lp[0] = cur_lp[width_tbl[1]];
+ buf1++;
+ lp2++;
+ break;
+
+ case 2:
+ if(lp2 == 0) {
+ for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
+ cur_lp[j] = *ref_lp;
+ lp2 += 2;
+ }
+ break;
+
+ case 3:
+ if(lp2 < 2) {
+ for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1])
+ cur_lp[j] = *ref_lp;
+ lp2 = 3;
+ }
+ break;
+
+ case 6:
+ lp2 = 4;
+ break;
+
+ case 7:
+ if(rle_v3 != 0)
+ rle_v3 = 0;
+ else {
+ buf1--;
+ rle_v3 = 1;
+ }
+ lp2 = 4;
+ break;
+
+ case 8:
+ if(lp2 == 0) {
+ RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
+
+ if(rle_v1 == 1) {
+ for(i = 0, j = 0; i < 8; i++, j += width_tbl[1])
+ cur_lp[j] = ref_lp[j];
+ }
+
+ RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
+ break;
+ } else {
+ rle_v2 = (*buf1) - 1;
+ rle_v1 = 1;
+ }
+ case 5:
+ LP2_CHECK(buf1,rle_v3,lp2)
+ case 4:
+ for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1])
+ cur_lp[j] = *ref_lp;
+ lp2 = 4;
+ break;
+
+ case 9:
+ av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\n");
+ lv1 = *buf1++;
+ lv = (lv1 & 0x7F) << 1;
+ lv += (lv << 8);
+ lv += (lv << 16);
+
+ for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
+ cur_lp[j] = lv;
+
+ LV1_CHECK(buf1,rle_v3,lv1,lp2)
+ break;
+
+ default:
+ return;
+ }
+ }
+
+ cur_frm_pos += 4;
+ }
+
+ cur_frm_pos += (((width * 2) - blks_width) * 4);
+ flag1 = 0;
+ }
+ break;
+
+ case 10: /********** CASE 10 **********/
+ if(ref_vectors == NULL) {
+ flag1 = 1;
+
+ for( ; blks_height > 0; blks_height -= 8) {
+ for(lp1 = 0; lp1 < blks_width; lp1 += 2) {
+ for(lp2 = 0; lp2 < 4; ) {
+ k = *buf1++;
+ cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2];
+ ref_lp = ((uint32_t *)cur_frm_pos) + width_tbl[(lp2 * 2) - 1];
+ lv1 = ref_lp[0];
+ lv2 = ref_lp[1];
+ if(lp2 == 0 && flag1 != 0) {
+#ifdef WORDS_BIGENDIAN
+ lv1 = lv1 & 0xFF00FF00;
+ lv1 = (lv1 >> 8) | lv1;
+ lv2 = lv2 & 0xFF00FF00;
+ lv2 = (lv2 >> 8) | lv2;
+#else
+ lv1 = lv1 & 0x00FF00FF;
+ lv1 = (lv1 << 8) | lv1;
+ lv2 = lv2 & 0x00FF00FF;
+ lv2 = (lv2 << 8) | lv2;
+#endif
+ }
+
+ switch(correction_type_sp[lp2 & 0x01][k]) {
+ case 0:
+ cur_lp[width_tbl[1]] = le2me_32(((le2me_32(lv1) >> 1) + correctionloworder_lp[lp2 & 0x01][k]) << 1);
+ cur_lp[width_tbl[1]+1] = le2me_32(((le2me_32(lv2) >> 1) + correctionhighorder_lp[lp2 & 0x01][k]) << 1);
+ if(lp2 > 0 || strip->ypos != 0 || flag1 == 0) {
+ cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
+ cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
+ } else {
+ cur_lp[0] = cur_lp[width_tbl[1]];
+ cur_lp[1] = cur_lp[width_tbl[1]+1];
+ }
+ lp2++;
+ break;
+
+ case 1:
+ cur_lp[width_tbl[1]] = le2me_32(((le2me_32(lv1) >> 1) + correctionloworder_lp[lp2 & 0x01][*buf1]) << 1);
+ cur_lp[width_tbl[1]+1] = le2me_32(((le2me_32(lv2) >> 1) + correctionloworder_lp[lp2 & 0x01][k]) << 1);
+ if(lp2 > 0 || strip->ypos != 0 || flag1 == 0) {
+ cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
+ cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
+ } else {
+ cur_lp[0] = cur_lp[width_tbl[1]];
+ cur_lp[1] = cur_lp[width_tbl[1]+1];
+ }
+ buf1++;
+ lp2++;
+ break;
+
+ case 2:
+ if(lp2 == 0) {
+ if(flag1 != 0) {
+ for(i = 0, j = width_tbl[1]; i < 3; i++, j += width_tbl[1]) {
+ cur_lp[j] = lv1;
+ cur_lp[j+1] = lv2;
+ }
+ cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
+ cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
+ } else {
+ for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) {
+ cur_lp[j] = lv1;
+ cur_lp[j+1] = lv2;
+ }
+ }
+ lp2 += 2;
+ }
+ break;
+
+ case 3:
+ if(lp2 < 2) {
+ if(lp2 == 0 && flag1 != 0) {
+ for(i = 0, j = width_tbl[1]; i < 5; i++, j += width_tbl[1]) {
+ cur_lp[j] = lv1;
+ cur_lp[j+1] = lv2;
+ }
+ cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
+ cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
+ } else {
+ for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) {
+ cur_lp[j] = lv1;
+ cur_lp[j+1] = lv2;
+ }
+ }
+ lp2 = 3;
+ }
+ break;
+
+ case 8:
+ if(lp2 == 0) {
+ RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
+ if(rle_v1 == 1) {
+ if(flag1 != 0) {
+ for(i = 0, j = width_tbl[1]; i < 7; i++, j += width_tbl[1]) {
+ cur_lp[j] = lv1;
+ cur_lp[j+1] = lv2;
+ }
+ cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
+ cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
+ } else {
+ for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) {
+ cur_lp[j] = lv1;
+ cur_lp[j+1] = lv2;
+ }
+ }
+ }
+ RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
+ break;
+ } else {
+ rle_v1 = 1;
+ rle_v2 = (*buf1) - 1;
+ }
+ case 5:
+ LP2_CHECK(buf1,rle_v3,lp2)
+ case 4:
+ if(lp2 == 0 && flag1 != 0) {
+ for(i = 0, j = width_tbl[1]; i < 7; i++, j += width_tbl[1]) {
+ cur_lp[j] = lv1;
+ cur_lp[j+1] = lv2;
+ }
+ cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
+ cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
+ } else {
+ for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) {
+ cur_lp[j] = lv1;
+ cur_lp[j+1] = lv2;
+ }
+ }
+ lp2 = 4;
+ break;
+
+ case 6:
+ lp2 = 4;
+ break;
+
+ case 7:
+ if(lp2 == 0) {
+ if(rle_v3 != 0)
+ rle_v3 = 0;
+ else {
+ buf1--;
+ rle_v3 = 1;
+ }
+ lp2 = 4;
+ }
+ break;
+
+ case 9:
+ av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\n");
+ lv1 = *buf1;
+ lv = (lv1 & 0x7F) << 1;
+ lv += (lv << 8);
+ lv += (lv << 16);
+ for(i = 0, j = 0; i < 8; i++, j += width_tbl[1])
+ cur_lp[j] = lv;
+ LV1_CHECK(buf1,rle_v3,lv1,lp2)
+ break;
+
+ default:
+ return;
+ }
+ }
+
+ cur_frm_pos += 8;
+ }
+
+ cur_frm_pos += (((width * 2) - blks_width) * 4);
+ flag1 = 0;
+ }
+ } else {
+ for( ; blks_height > 0; blks_height -= 8) {
+ for(lp1 = 0; lp1 < blks_width; lp1 += 2) {
+ for(lp2 = 0; lp2 < 4; ) {
+ k = *buf1++;
+ cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2];
+ ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2 * 2];
+
+ switch(correction_type_sp[lp2 & 0x01][k]) {
+ case 0:
+ lv1 = correctionloworder_lp[lp2 & 0x01][k];
+ lv2 = correctionhighorder_lp[lp2 & 0x01][k];
+ cur_lp[0] = le2me_32(((le2me_32(ref_lp[0]) >> 1) + lv1) << 1);
+ cur_lp[1] = le2me_32(((le2me_32(ref_lp[1]) >> 1) + lv2) << 1);
+ cur_lp[width_tbl[1]] = le2me_32(((le2me_32(ref_lp[width_tbl[1]]) >> 1) + lv1) << 1);
+ cur_lp[width_tbl[1]+1] = le2me_32(((le2me_32(ref_lp[width_tbl[1]+1]) >> 1) + lv2) << 1);
+ lp2++;
+ break;
+
+ case 1:
+ lv1 = correctionloworder_lp[lp2 & 0x01][*buf1++];
+ lv2 = correctionloworder_lp[lp2 & 0x01][k];
+ cur_lp[0] = le2me_32(((le2me_32(ref_lp[0]) >> 1) + lv1) << 1);
+ cur_lp[1] = le2me_32(((le2me_32(ref_lp[1]) >> 1) + lv2) << 1);
+ cur_lp[width_tbl[1]] = le2me_32(((le2me_32(ref_lp[width_tbl[1]]) >> 1) + lv1) << 1);
+ cur_lp[width_tbl[1]+1] = le2me_32(((le2me_32(ref_lp[width_tbl[1]+1]) >> 1) + lv2) << 1);
+ lp2++;
+ break;
+
+ case 2:
+ if(lp2 == 0) {
+ for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) {
+ cur_lp[j] = ref_lp[j];
+ cur_lp[j+1] = ref_lp[j+1];
+ }
+ lp2 += 2;
+ }
+ break;
+
+ case 3:
+ if(lp2 < 2) {
+ for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) {
+ cur_lp[j] = ref_lp[j];
+ cur_lp[j+1] = ref_lp[j+1];
+ }
+ lp2 = 3;
+ }
+ break;
+
+ case 8:
+ if(lp2 == 0) {
+ RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
+ for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) {
+ ((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)ref_frm_pos)[j];
+ ((uint32_t *)cur_frm_pos)[j+1] = ((uint32_t *)ref_frm_pos)[j+1];
+ }
+ RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
+ break;
+ } else {
+ rle_v1 = 1;
+ rle_v2 = (*buf1) - 1;
+ }
+ case 5:
+ case 7:
+ LP2_CHECK(buf1,rle_v3,lp2)
+ case 6:
+ case 4:
+ for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) {
+ cur_lp[j] = ref_lp[j];
+ cur_lp[j+1] = ref_lp[j+1];
+ }
+ lp2 = 4;
+ break;
+
+ case 9:
+ av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\n");
+ lv1 = *buf1;
+ lv = (lv1 & 0x7F) << 1;
+ lv += (lv << 8);
+ lv += (lv << 16);
+ for(i = 0, j = 0; i < 8; i++, j += width_tbl[1])
+ ((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)cur_frm_pos)[j+1] = lv;
+ LV1_CHECK(buf1,rle_v3,lv1,lp2)
+ break;
+
+ default:
+ return;
+ }
+ }
+
+ cur_frm_pos += 8;
+ ref_frm_pos += 8;
+ }
+
+ cur_frm_pos += (((width * 2) - blks_width) * 4);
+ ref_frm_pos += (((width * 2) - blks_width) * 4);
+ }
+ }
+ break;
+
+ case 11: /********** CASE 11 **********/
+ if(ref_vectors == NULL)
+ return;
+
+ for( ; blks_height > 0; blks_height -= 8) {
+ for(lp1 = 0; lp1 < blks_width; lp1++) {
+ for(lp2 = 0; lp2 < 4; ) {
+ k = *buf1++;
+ cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2];
+ ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2 * 2];
+
+ switch(correction_type_sp[lp2 & 0x01][k]) {
+ case 0:
+ cur_lp[0] = le2me_32(((le2me_32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
+ cur_lp[width_tbl[1]] = le2me_32(((le2me_32(ref_lp[width_tbl[1]]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
+ lp2++;
+ break;
+
+ case 1:
+ lv1 = (unsigned short)(correction_lp[lp2 & 0x01][*buf1++]);
+ lv2 = (unsigned short)(correction_lp[lp2 & 0x01][k]);
+ res = (unsigned short)(((le2me_16(((unsigned short *)ref_lp)[0]) >> 1) + lv1) << 1);
+ ((unsigned short *)cur_lp)[0] = le2me_16(res);
+ res = (unsigned short)(((le2me_16(((unsigned short *)ref_lp)[1]) >> 1) + lv2) << 1);
+ ((unsigned short *)cur_lp)[1] = le2me_16(res);
+ res = (unsigned short)(((le2me_16(((unsigned short *)ref_lp)[width_tbl[2]]) >> 1) + lv1) << 1);
+ ((unsigned short *)cur_lp)[width_tbl[2]] = le2me_16(res);
+ res = (unsigned short)(((le2me_16(((unsigned short *)ref_lp)[width_tbl[2]+1]) >> 1) + lv2) << 1);
+ ((unsigned short *)cur_lp)[width_tbl[2]+1] = le2me_16(res);
+ lp2++;
+ break;
+
+ case 2:
+ if(lp2 == 0) {
+ for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
+ cur_lp[j] = ref_lp[j];
+ lp2 += 2;
+ }
+ break;
+
+ case 3:
+ if(lp2 < 2) {
+ for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1])
+ cur_lp[j] = ref_lp[j];
+ lp2 = 3;
+ }
+ break;
+
+ case 8:
+ if(lp2 == 0) {
+ RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
+
+ for(i = 0, j = 0; i < 8; i++, j += width_tbl[1])
+ cur_lp[j] = ref_lp[j];
+
+ RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
+ break;
+ } else {
+ rle_v1 = 1;
+ rle_v2 = (*buf1) - 1;
+ }
+ case 5:
+ case 7:
+ LP2_CHECK(buf1,rle_v3,lp2)
+ case 4:
+ case 6:
+ for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1])
+ cur_lp[j] = ref_lp[j];
+ lp2 = 4;
+ break;
+
+ case 9:
+ av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\n");
+ lv1 = *buf1++;
+ lv = (lv1 & 0x7F) << 1;
+ lv += (lv << 8);
+ lv += (lv << 16);
+ for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
+ cur_lp[j] = lv;
+ LV1_CHECK(buf1,rle_v3,lv1,lp2)
+ break;
+
+ default:
+ return;
+ }
+ }
+
+ cur_frm_pos += 4;
+ ref_frm_pos += 4;
+ }
+
+ cur_frm_pos += (((width * 2) - blks_width) * 4);
+ ref_frm_pos += (((width * 2) - blks_width) * 4);
+ }
+ break;
+
+ default:
+ return;
+ }
+ }
+
+ if(strip < strip_tbl)
+ return;
+
+ for( ; strip >= strip_tbl; strip--) {
+ if(strip->split_flag != 0) {
+ strip->split_flag = 0;
+ strip->usl7 = (strip-1)->usl7;
+
+ if(strip->split_direction) {
+ strip->xpos += strip->width;
+ strip->width = (strip-1)->width - strip->width;
+ if(region_160_width <= strip->xpos && width < strip->width + strip->xpos)
+ strip->width = width - strip->xpos;
+ } else {
+ strip->ypos += strip->height;
+ strip->height = (strip-1)->height - strip->height;
+ }
+ break;
+ }
+ }
+ }
+}
+
+static int indeo3_decode_init(AVCodecContext *avctx)
+{
+ Indeo3DecodeContext *s = avctx->priv_data;
+
+ s->avctx = avctx;
+ s->width = avctx->width;
+ s->height = avctx->height;
+ avctx->pix_fmt = PIX_FMT_YUV410P;
+ avctx->has_b_frames = 0;
+
+ build_modpred(s);
+ iv_alloc_frames(s);
+
+ return 0;
+}
+
+static int indeo3_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ unsigned char *buf, int buf_size)
+{
+ Indeo3DecodeContext *s=avctx->priv_data;
+ unsigned char *src, *dest;
+ int y;
+
+ iv_decode_frame(s, buf, buf_size);
+
+ if(s->frame.data[0])
+ avctx->release_buffer(avctx, &s->frame);
+
+ s->frame.reference = 0;
+ if(avctx->get_buffer(avctx, &s->frame) < 0) {
+ av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ return -1;
+ }
+
+ src = s->cur_frame->Ybuf;
+ dest = s->frame.data[0];
+ for (y = 0; y < s->height; y++) {
+ memcpy(dest, src, s->cur_frame->y_w);
+ src += s->cur_frame->y_w;
+ dest += s->frame.linesize[0];
+ }
+
+ if (!(s->avctx->flags & CODEC_FLAG_GRAY))
+ {
+ src = s->cur_frame->Ubuf;
+ dest = s->frame.data[1];
+ for (y = 0; y < s->height / 4; y++) {
+ memcpy(dest, src, s->cur_frame->uv_w);
+ src += s->cur_frame->uv_w;
+ dest += s->frame.linesize[1];
+ }
+
+ src = s->cur_frame->Vbuf;
+ dest = s->frame.data[2];
+ for (y = 0; y < s->height / 4; y++) {
+ memcpy(dest, src, s->cur_frame->uv_w);
+ src += s->cur_frame->uv_w;
+ dest += s->frame.linesize[2];
+ }
+ }
+
+ *data_size=sizeof(AVFrame);
+ *(AVFrame*)data= s->frame;
+
+ return buf_size;
+}
+
+static int indeo3_decode_end(AVCodecContext *avctx)
+{
+ Indeo3DecodeContext *s = avctx->priv_data;
+
+ iv_free_func(s);
+
+ return 0;
+}
+
+AVCodec indeo3_decoder = {
+ "indeo3",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_INDEO3,
+ sizeof(Indeo3DecodeContext),
+ indeo3_decode_init,
+ NULL,
+ indeo3_decode_end,
+ indeo3_decode_frame,
+ 0,
+ NULL
+};
diff --git a/src/libffmpeg/libavcodec/indeo3data.h b/contrib/ffmpeg/libavcodec/indeo3data.h
index e69a09f0e..e69a09f0e 100644
--- a/src/libffmpeg/libavcodec/indeo3data.h
+++ b/contrib/ffmpeg/libavcodec/indeo3data.h
diff --git a/src/libffmpeg/libavcodec/interplayvideo.c b/contrib/ffmpeg/libavcodec/interplayvideo.c
index 95059c365..95059c365 100644
--- a/src/libffmpeg/libavcodec/interplayvideo.c
+++ b/contrib/ffmpeg/libavcodec/interplayvideo.c
diff --git a/src/libffmpeg/libavcodec/jfdctfst.c b/contrib/ffmpeg/libavcodec/jfdctfst.c
index a9dcfab82..a9dcfab82 100644
--- a/src/libffmpeg/libavcodec/jfdctfst.c
+++ b/contrib/ffmpeg/libavcodec/jfdctfst.c
diff --git a/src/libffmpeg/libavcodec/jfdctint.c b/contrib/ffmpeg/libavcodec/jfdctint.c
index 250312467..250312467 100644
--- a/src/libffmpeg/libavcodec/jfdctint.c
+++ b/contrib/ffmpeg/libavcodec/jfdctint.c
diff --git a/contrib/ffmpeg/libavcodec/jpeg_ls.c b/contrib/ffmpeg/libavcodec/jpeg_ls.c
new file mode 100644
index 000000000..136e3fb80
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/jpeg_ls.c
@@ -0,0 +1,860 @@
+/*
+ * JPEG-LS encoder and decoder
+ * Copyright (c) 2003 Michael Niedermayer
+ * Copyright (c) 2006 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 "golomb.h"
+
+/**
+ * @file jpeg_ls.c
+ * JPEG-LS encoder and decoder.
+ */
+
+typedef struct JpeglsContext{
+ AVCodecContext *avctx;
+ AVFrame picture;
+}JpeglsContext;
+
+typedef struct JLSState{
+ int T1, T2, T3;
+ int A[367], B[367], C[365], N[367];
+ int limit, reset, bpp, qbpp, maxval, range;
+ int near, twonear;
+ int run_index[3];
+}JLSState;
+
+static const uint8_t log2_run[32]={
+ 0, 0, 0, 0, 1, 1, 1, 1,
+ 2, 2, 2, 2, 3, 3, 3, 3,
+ 4, 4, 5, 5, 6, 6, 7, 7,
+ 8, 9,10,11,12,13,14,15
+};
+
+/*
+* Uncomment this to significantly speed up decoding of broken JPEG-LS
+* (or test broken JPEG-LS decoder) and slow down ordinary decoding a bit.
+*
+* There is no Golomb code with length >= 32 bits possible, so check and
+* avoid situation of 32 zeros, FFmpeg Golomb decoder is painfully slow
+* on this errors.
+*/
+//#define JLS_BROKEN
+
+/********** Functions for both encoder and decoder **********/
+
+/**
+ * Calculate initial JPEG-LS parameters
+ */
+static void ls_init_state(JLSState *state){
+ int i;
+
+ state->twonear = state->near * 2 + 1;
+ state->range = ((state->maxval + state->twonear - 1) / state->twonear) + 1;
+
+ // QBPP = ceil(log2(RANGE))
+ for(state->qbpp = 0; (1 << state->qbpp) < state->range; state->qbpp++);
+
+ if(state->bpp < 8)
+ state->limit = 16 + 2 * state->bpp - state->qbpp;
+ else
+ state->limit = (4 * state->bpp) - state->qbpp;
+
+ for(i = 0; i < 367; i++) {
+ state->A[i] = FFMAX((state->range + 32) >> 6, 2);
+ state->N[i] = 1;
+ }
+
+}
+
+/**
+ * Calculate quantized gradient value, used for context determination
+ */
+static inline int quantize(JLSState *s, int v){ //FIXME optimize
+ if(v==0) return 0;
+ if(v < 0){
+ if(v <= -s->T3) return -4;
+ if(v <= -s->T2) return -3;
+ if(v <= -s->T1) return -2;
+ if(v < -s->near) return -1;
+ return 0;
+ }else{
+ if(v <= s->near) return 0;
+ if(v < s->T1) return 1;
+ if(v < s->T2) return 2;
+ if(v < s->T3) return 3;
+ return 4;
+ }
+}
+
+/**
+ * Custom value clipping function used in T1, T2, T3 calculation
+ */
+static inline int iso_clip(int v, int vmin, int vmax){
+ if(v > vmax || v < vmin) return vmin;
+ else return v;
+}
+
+/**
+ * Calculate JPEG-LS codec values
+ */
+static void reset_ls_coding_parameters(JLSState *s, int reset_all){
+ const int basic_t1= 3;
+ const int basic_t2= 7;
+ const int basic_t3= 21;
+ int factor;
+
+ if(s->maxval==0 || reset_all) s->maxval= (1 << s->bpp) - 1;
+
+ if(s->maxval >=128){
+ factor= (FFMIN(s->maxval, 4095) + 128)>>8;
+
+ if(s->T1==0 || reset_all)
+ s->T1= iso_clip(factor*(basic_t1-2) + 2 + 3*s->near, s->near+1, s->maxval);
+ if(s->T2==0 || reset_all)
+ s->T2= iso_clip(factor*(basic_t2-3) + 3 + 5*s->near, s->T1, s->maxval);
+ if(s->T3==0 || reset_all)
+ s->T3= iso_clip(factor*(basic_t3-4) + 4 + 7*s->near, s->T2, s->maxval);
+ }else{
+ factor= 256 / (s->maxval + 1);
+
+ if(s->T1==0 || reset_all)
+ s->T1= iso_clip(FFMAX(2, basic_t1/factor + 3*s->near), s->near+1, s->maxval);
+ if(s->T2==0 || reset_all)
+ s->T2= iso_clip(FFMAX(3, basic_t2/factor + 5*s->near), s->T1, s->maxval);
+ if(s->T3==0 || reset_all)
+ s->T3= iso_clip(FFMAX(4, basic_t3/factor + 6*s->near), s->T2, s->maxval);
+ }
+
+ if(s->reset==0 || reset_all) s->reset= 64;
+// av_log(NULL, AV_LOG_DEBUG, "[JPEG-LS RESET] T=%i,%i,%i\n", s->T1, s->T2, s->T3);
+}
+
+
+/********** Decoder-specific functions **********/
+
+/**
+ * Decode LSE block with initialization parameters
+ */
+static int decode_lse(MJpegDecodeContext *s)
+{
+ int len, id;
+
+ /* XXX: verify len field validity */
+ len = get_bits(&s->gb, 16);
+ id = get_bits(&s->gb, 8);
+
+ switch(id){
+ case 1:
+ s->maxval= get_bits(&s->gb, 16);
+ s->t1= get_bits(&s->gb, 16);
+ s->t2= get_bits(&s->gb, 16);
+ s->t3= get_bits(&s->gb, 16);
+ s->reset= get_bits(&s->gb, 16);
+
+// reset_ls_coding_parameters(s, 0);
+ //FIXME quant table?
+ break;
+ case 2:
+ case 3:
+ av_log(s->avctx, AV_LOG_ERROR, "palette not supported\n");
+ return -1;
+ case 4:
+ av_log(s->avctx, AV_LOG_ERROR, "oversize image not supported\n");
+ return -1;
+ default:
+ av_log(s->avctx, AV_LOG_ERROR, "invalid id %d\n", id);
+ return -1;
+ }
+// av_log(s->avctx, AV_LOG_DEBUG, "ID=%i, T=%i,%i,%i\n", id, s->t1, s->t2, s->t3);
+
+ return 0;
+}
+
+static void inline downscale_state(JLSState *state, int Q){
+ if(state->N[Q] == state->reset){
+ state->A[Q] >>=1;
+ state->B[Q] >>=1;
+ state->N[Q] >>=1;
+ }
+ state->N[Q]++;
+}
+
+static inline int update_state_regular(JLSState *state, int Q, int err){
+ state->A[Q] += FFABS(err);
+ err *= state->twonear;
+ state->B[Q] += err;
+
+ downscale_state(state, Q);
+
+ if(state->B[Q] <= -state->N[Q]) {
+ state->B[Q]= FFMAX(state->B[Q] + state->N[Q], 1-state->N[Q]);
+ if(state->C[Q] > -128)
+ state->C[Q]--;
+ }else if(state->B[Q] > 0){
+ state->B[Q]= FFMIN(state->B[Q] - state->N[Q], 0);
+ if(state->C[Q] < 127)
+ state->C[Q]++;
+ }
+
+ return err;
+}
+
+/**
+ * Get context-dependent Golomb code, decode it and update context
+ */
+static inline int ls_get_code_regular(GetBitContext *gb, JLSState *state, int Q){
+ int k, ret;
+
+ for(k = 0; (state->N[Q] << k) < state->A[Q]; k++);
+
+#ifdef JLS_BROKEN
+ if(!show_bits_long(gb, 32))return -1;
+#endif
+ ret = get_ur_golomb_jpegls(gb, k, state->limit, state->qbpp);
+
+ /* decode mapped error */
+ if(ret & 1)
+ ret = -((ret + 1) >> 1);
+ else
+ ret >>= 1;
+
+ /* for NEAR=0, k=0 and 2*B[Q] <= - N[Q] mapping is reversed */
+ if(!state->near && !k && (2 * state->B[Q] <= -state->N[Q]))
+ ret = -(ret + 1);
+
+ ret= update_state_regular(state, Q, ret);
+
+ return ret;
+}
+
+/**
+ * Get Golomb code, decode it and update state for run termination
+ */
+static inline int ls_get_code_runterm(GetBitContext *gb, JLSState *state, int RItype, int limit_add){
+ int k, ret, temp, map;
+ int Q = 365 + RItype;
+
+ temp= state->A[Q];
+ if(RItype)
+ temp += state->N[Q] >> 1;
+
+ for(k = 0; (state->N[Q] << k) < temp; k++);
+
+#ifdef JLS_BROKEN
+ if(!show_bits_long(gb, 32))return -1;
+#endif
+ ret = get_ur_golomb_jpegls(gb, k, state->limit - limit_add - 1, state->qbpp);
+
+ /* decode mapped error */
+ map = 0;
+ if(!k && (RItype || ret) && (2 * state->B[Q] < state->N[Q]))
+ map = 1;
+ ret += RItype + map;
+
+ if(ret & 1){
+ ret = map - ((ret + 1) >> 1);
+ state->B[Q]++;
+ } else {
+ ret = ret >> 1;
+ }
+
+ /* update state */
+ state->A[Q] += FFABS(ret) - RItype;
+ ret *= state->twonear;
+ downscale_state(state, Q);
+
+ return ret;
+}
+
+#define R(a, i ) (bits == 8 ? ((uint8_t*)(a))[i] : ((uint16_t*)(a))[i] )
+#define W(a, i, v) (bits == 8 ? (((uint8_t*)(a))[i]=v) : (((uint16_t*)(a))[i]=v))
+/**
+ * Decode one line of image
+ */
+static inline void ls_decode_line(JLSState *state, MJpegDecodeContext *s, void *last, void *dst, int last2, int w, int stride, int comp, int bits){
+ int i, x = 0;
+ int Ra, Rb, Rc, Rd;
+ int D0, D1, D2;
+
+ while(x < w) {
+ int err, pred;
+
+ /* compute gradients */
+ Ra = x ? R(dst, x - stride) : R(last, x);
+ Rb = R(last, x);
+ Rc = x ? R(last, x - stride) : last2;
+ Rd = (x >= w - stride) ? R(last, x) : R(last, x + stride);
+ D0 = Rd - Rb;
+ D1 = Rb - Rc;
+ D2 = Rc - Ra;
+ /* run mode */
+ if((FFABS(D0) <= state->near) && (FFABS(D1) <= state->near) && (FFABS(D2) <= state->near)) {
+ int r;
+ int RItype;
+
+ /* decode full runs while available */
+ while(get_bits1(&s->gb)) {
+ int r;
+ r = 1 << log2_run[state->run_index[comp]];
+ if(x + r * stride > w) {
+ r = (w - x) / stride;
+ }
+ for(i = 0; i < r; i++) {
+ W(dst, x, Ra);
+ x += stride;
+ }
+ /* if EOL reached, we stop decoding */
+ if(r != (1 << log2_run[state->run_index[comp]]))
+ return;
+ if(state->run_index[comp] < 31)
+ state->run_index[comp]++;
+ if(x + stride > w)
+ return;
+ }
+ /* decode aborted run */
+ r = log2_run[state->run_index[comp]];
+ if(r)
+ r = get_bits_long(&s->gb, r);
+ for(i = 0; i < r; i++) {
+ W(dst, x, Ra);
+ x += stride;
+ }
+
+ /* decode run termination value */
+ Rb = R(last, x);
+ RItype = (FFABS(Ra - Rb) <= state->near) ? 1 : 0;
+ err = ls_get_code_runterm(&s->gb, state, RItype, log2_run[state->run_index[comp]]);
+ if(state->run_index[comp])
+ state->run_index[comp]--;
+
+ if(state->near && RItype){
+ pred = Ra + err;
+ } else {
+ if(Rb < Ra)
+ pred = Rb - err;
+ else
+ pred = Rb + err;
+ }
+ } else { /* regular mode */
+ int context, sign;
+
+ context = quantize(state, D0) * 81 + quantize(state, D1) * 9 + quantize(state, D2);
+ pred = mid_pred(Ra, Ra + Rb - Rc, Rb);
+
+ if(context < 0){
+ context = -context;
+ sign = 1;
+ }else{
+ sign = 0;
+ }
+
+ if(sign){
+ pred = av_clip(pred - state->C[context], 0, state->maxval);
+ err = -ls_get_code_regular(&s->gb, state, context);
+ } else {
+ pred = av_clip(pred + state->C[context], 0, state->maxval);
+ err = ls_get_code_regular(&s->gb, state, context);
+ }
+
+ /* we have to do something more for near-lossless coding */
+ pred += err;
+ }
+ if(state->near){
+ if(pred < -state->near)
+ pred += state->range * state->twonear;
+ else if(pred > state->maxval + state->near)
+ pred -= state->range * state->twonear;
+ pred = av_clip(pred, 0, state->maxval);
+ }
+
+ pred &= state->maxval;
+ W(dst, x, pred);
+ x += stride;
+ }
+}
+
+static int ls_decode_picture(MJpegDecodeContext *s, int near, int point_transform, int ilv){
+ int i, t = 0;
+ uint8_t *zero, *last, *cur;
+ JLSState *state;
+ int off = 0, stride = 1, width, shift;
+
+ zero = av_mallocz(s->picture.linesize[0]);
+ last = zero;
+ cur = s->picture.data[0];
+
+ state = av_mallocz(sizeof(JLSState));
+ /* initialize JPEG-LS state from JPEG parameters */
+ state->near = near;
+ state->bpp = (s->bits < 2) ? 2 : s->bits;
+ state->maxval = s->maxval;
+ state->T1 = s->t1;
+ state->T2 = s->t2;
+ state->T3 = s->t3;
+ state->reset = s->reset;
+ reset_ls_coding_parameters(state, 0);
+ ls_init_state(state);
+
+ if(s->bits <= 8)
+ shift = point_transform + (8 - s->bits);
+ else
+ shift = point_transform + (16 - s->bits);
+
+// av_log(s->avctx, AV_LOG_DEBUG, "JPEG-LS params: %ix%i NEAR=%i MV=%i T(%i,%i,%i) RESET=%i, LIMIT=%i, qbpp=%i, RANGE=%i\n",s->width,s->height,state->near,state->maxval,state->T1,state->T2,state->T3,state->reset,state->limit,state->qbpp, state->range);
+// av_log(s->avctx, AV_LOG_DEBUG, "JPEG params: ILV=%i Pt=%i BPP=%i, scan = %i\n", ilv, point_transform, s->bits, s->cur_scan);
+ if(ilv == 0) { /* separate planes */
+ off = s->cur_scan - 1;
+ stride = (s->nb_components > 1) ? 3 : 1;
+ width = s->width * stride;
+ cur += off;
+ for(i = 0; i < s->height; i++) {
+ if(s->bits <= 8){
+ ls_decode_line(state, s, last, cur, t, width, stride, off, 8);
+ t = last[0];
+ }else{
+ ls_decode_line(state, s, last, cur, t, width, stride, off, 16);
+ t = *((uint16_t*)last);
+ }
+ last = cur;
+ cur += s->picture.linesize[0];
+
+ if (s->restart_interval && !--s->restart_count) {
+ align_get_bits(&s->gb);
+ skip_bits(&s->gb, 16); /* skip RSTn */
+ }
+ }
+ } else if(ilv == 1) { /* line interleaving */
+ int j;
+ int Rc[3] = {0, 0, 0};
+ memset(cur, 0, s->picture.linesize[0]);
+ width = s->width * 3;
+ for(i = 0; i < s->height; i++) {
+ for(j = 0; j < 3; j++) {
+ ls_decode_line(state, s, last + j, cur + j, Rc[j], width, 3, j, 8);
+ Rc[j] = last[j];
+
+ if (s->restart_interval && !--s->restart_count) {
+ align_get_bits(&s->gb);
+ skip_bits(&s->gb, 16); /* skip RSTn */
+ }
+ }
+ last = cur;
+ cur += s->picture.linesize[0];
+ }
+ } else if(ilv == 2) { /* sample interleaving */
+ av_log(s->avctx, AV_LOG_ERROR, "Sample interleaved images are not supported.\n");
+ av_free(state);
+ av_free(zero);
+ return -1;
+ }
+
+ if(shift){ /* we need to do point transform or normalize samples */
+ int x, w;
+
+ w = s->width * s->nb_components;
+
+ if(s->bits <= 8){
+ uint8_t *src = s->picture.data[0];
+
+ for(i = 0; i < s->height; i++){
+ for(x = off; x < w; x+= stride){
+ src[x] <<= shift;
+ }
+ src += s->picture.linesize[0];
+ }
+ }else{
+ uint16_t *src = (uint16_t*) s->picture.data[0];
+
+ for(i = 0; i < s->height; i++){
+ for(x = 0; x < w; x++){
+ src[x] <<= shift;
+ }
+ src += s->picture.linesize[0]/2;
+ }
+ }
+ }
+ av_free(state);
+ av_free(zero);
+
+ return 0;
+}
+
+#if defined(CONFIG_ENCODERS) && defined(CONFIG_JPEGLS_ENCODER)
+/********** Encoder-specific functions **********/
+
+/**
+ * Encode error from regular symbol
+ */
+static inline void ls_encode_regular(JLSState *state, PutBitContext *pb, int Q, int err){
+ int k;
+ int val;
+ int map;
+
+ for(k = 0; (state->N[Q] << k) < state->A[Q]; k++);
+
+ map = !state->near && !k && (2 * state->B[Q] <= -state->N[Q]);
+
+ if(err < 0)
+ err += state->range;
+ if(err >= ((state->range + 1) >> 1)) {
+ err -= state->range;
+ val = 2 * FFABS(err) - 1 - map;
+ } else
+ val = 2 * err + map;
+
+ set_ur_golomb_jpegls(pb, val, k, state->limit, state->qbpp);
+
+ update_state_regular(state, Q, err);
+}
+
+/**
+ * Encode error from run termination
+ */
+static inline void ls_encode_runterm(JLSState *state, PutBitContext *pb, int RItype, int err, int limit_add){
+ int k;
+ int val, map;
+ int Q = 365 + RItype;
+ int temp;
+
+ temp = state->A[Q];
+ if(RItype)
+ temp += state->N[Q] >> 1;
+ for(k = 0; (state->N[Q] << k) < temp; k++);
+ map = 0;
+ if(!k && err && (2 * state->B[Q] < state->N[Q]))
+ map = 1;
+
+ if(err < 0)
+ val = - (2 * err) - 1 - RItype + map;
+ else
+ val = 2 * err - RItype - map;
+ set_ur_golomb_jpegls(pb, val, k, state->limit - limit_add - 1, state->qbpp);
+
+ if(err < 0)
+ state->B[Q]++;
+ state->A[Q] += (val + 1 - RItype) >> 1;
+
+ downscale_state(state, Q);
+}
+
+/**
+ * Encode run value as specified by JPEG-LS standard
+ */
+static inline void ls_encode_run(JLSState *state, PutBitContext *pb, int run, int comp, int trail){
+ while(run >= (1 << log2_run[state->run_index[comp]])){
+ put_bits(pb, 1, 1);
+ run -= 1 << log2_run[state->run_index[comp]];
+ if(state->run_index[comp] < 31)
+ state->run_index[comp]++;
+ }
+ /* if hit EOL, encode another full run, else encode aborted run */
+ if(!trail && run) {
+ put_bits(pb, 1, 1);
+ }else if(trail){
+ put_bits(pb, 1, 0);
+ if(log2_run[state->run_index[comp]])
+ put_bits(pb, log2_run[state->run_index[comp]], run);
+ }
+}
+
+/**
+ * Encode one line of image
+ */
+static inline void ls_encode_line(JLSState *state, PutBitContext *pb, void *last, void *cur, int last2, int w, int stride, int comp, int bits){
+ int x = 0;
+ int Ra, Rb, Rc, Rd;
+ int D0, D1, D2;
+
+ while(x < w) {
+ int err, pred, sign;
+
+ /* compute gradients */
+ Ra = x ? R(cur, x - stride) : R(last, x);
+ Rb = R(last, x);
+ Rc = x ? R(last, x - stride) : last2;
+ Rd = (x >= w - stride) ? R(last, x) : R(last, x + stride);
+ D0 = Rd - Rb;
+ D1 = Rb - Rc;
+ D2 = Rc - Ra;
+
+ /* run mode */
+ if((FFABS(D0) <= state->near) && (FFABS(D1) <= state->near) && (FFABS(D2) <= state->near)) {
+ int RUNval, RItype, run;
+
+ run = 0;
+ RUNval = Ra;
+ while(x < w && (FFABS(R(cur, x) - RUNval) <= state->near)){
+ run++;
+ W(cur, x, Ra);
+ x += stride;
+ }
+ ls_encode_run(state, pb, run, comp, x < w);
+ if(x >= w)
+ return;
+ Rb = R(last, x);
+ RItype = (FFABS(Ra - Rb) <= state->near);
+ pred = RItype ? Ra : Rb;
+ err = R(cur, x) - pred;
+
+ if(!RItype && Ra > Rb)
+ err = -err;
+
+ if(state->near){
+ if(err > 0)
+ err = (state->near + err) / state->twonear;
+ else
+ err = -(state->near - err) / state->twonear;
+
+ if(RItype || (Rb >= Ra))
+ Ra = av_clip(pred + err * state->twonear, 0, state->maxval);
+ else
+ Ra = av_clip(pred - err * state->twonear, 0, state->maxval);
+ W(cur, x, Ra);
+ }
+ if(err < 0)
+ err += state->range;
+ if(err >= ((state->range + 1) >> 1))
+ err -= state->range;
+
+ ls_encode_runterm(state, pb, RItype, err, log2_run[state->run_index[comp]]);
+
+ if(state->run_index[comp] > 0)
+ state->run_index[comp]--;
+ } else { /* regular mode */
+ int context;
+
+ context = quantize(state, D0) * 81 + quantize(state, D1) * 9 + quantize(state, D2);
+ pred = mid_pred(Ra, Ra + Rb - Rc, Rb);
+
+ if(context < 0){
+ context = -context;
+ sign = 1;
+ pred = av_clip(pred - state->C[context], 0, state->maxval);
+ err = pred - R(cur, x);
+ }else{
+ sign = 0;
+ pred = av_clip(pred + state->C[context], 0, state->maxval);
+ err = R(cur, x) - pred;
+ }
+
+ if(state->near){
+ if(err > 0)
+ err = (state->near + err) / state->twonear;
+ else
+ err = -(state->near - err) / state->twonear;
+ if(!sign)
+ Ra = av_clip(pred + err * state->twonear, 0, state->maxval);
+ else
+ Ra = av_clip(pred - err * state->twonear, 0, state->maxval);
+ W(cur, x, Ra);
+ }
+
+ ls_encode_regular(state, pb, context, err);
+ }
+ x += stride;
+ }
+}
+
+static void ls_store_lse(JLSState *state, PutBitContext *pb){
+ /* Test if we have default params and don't need to store LSE */
+ JLSState state2;
+ memset(&state2, 0, sizeof(JLSState));
+ state2.bpp = state->bpp;
+ state2.near = state->near;
+ reset_ls_coding_parameters(&state2, 1);
+ if(state->T1 == state2.T1 && state->T2 == state2.T2 && state->T3 == state2.T3 && state->reset == state2.reset)
+ return;
+ /* store LSE type 1 */
+ put_marker(pb, LSE);
+ put_bits(pb, 16, 13);
+ put_bits(pb, 8, 1);
+ put_bits(pb, 16, state->maxval);
+ put_bits(pb, 16, state->T1);
+ put_bits(pb, 16, state->T2);
+ put_bits(pb, 16, state->T3);
+ put_bits(pb, 16, state->reset);
+}
+
+static int encode_picture_ls(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
+ JpeglsContext * const s = avctx->priv_data;
+ AVFrame *pict = data;
+ AVFrame * const p= (AVFrame*)&s->picture;
+ const int near = avctx->prediction_method;
+ PutBitContext pb, pb2;
+ GetBitContext gb;
+ uint8_t *buf2, *zero, *cur, *last;
+ JLSState *state;
+ int i, size;
+ int comps;
+
+ buf2 = av_malloc(buf_size);
+
+ init_put_bits(&pb, buf, buf_size);
+ init_put_bits(&pb2, buf2, buf_size);
+
+ *p = *pict;
+ p->pict_type= FF_I_TYPE;
+ p->key_frame= 1;
+
+ if(avctx->pix_fmt == PIX_FMT_GRAY8 || avctx->pix_fmt == PIX_FMT_GRAY16)
+ comps = 1;
+ else
+ comps = 3;
+
+ /* write our own JPEG header, can't use mjpeg_picture_header */
+ put_marker(&pb, SOI);
+ put_marker(&pb, SOF48);
+ put_bits(&pb, 16, 8 + comps * 3); // header size depends on components
+ put_bits(&pb, 8, (avctx->pix_fmt == PIX_FMT_GRAY16) ? 16 : 8); // bpp
+ put_bits(&pb, 16, avctx->height);
+ put_bits(&pb, 16, avctx->width);
+ put_bits(&pb, 8, comps); // components
+ for(i = 1; i <= comps; i++) {
+ put_bits(&pb, 8, i); // component ID
+ put_bits(&pb, 8, 0x11); // subsampling: none
+ put_bits(&pb, 8, 0); // Tiq, used by JPEG-LS ext
+ }
+
+ put_marker(&pb, SOS);
+ put_bits(&pb, 16, 6 + comps * 2);
+ put_bits(&pb, 8, comps);
+ for(i = 1; i <= comps; i++) {
+ put_bits(&pb, 8, i); // component ID
+ put_bits(&pb, 8, 0); // mapping index: none
+ }
+ put_bits(&pb, 8, near);
+ put_bits(&pb, 8, (comps > 1) ? 1 : 0); // interleaving: 0 - plane, 1 - line
+ put_bits(&pb, 8, 0); // point transform: none
+
+ state = av_mallocz(sizeof(JLSState));
+ /* initialize JPEG-LS state from JPEG parameters */
+ state->near = near;
+ state->bpp = (avctx->pix_fmt == PIX_FMT_GRAY16) ? 16 : 8;
+ reset_ls_coding_parameters(state, 0);
+ ls_init_state(state);
+
+ ls_store_lse(state, &pb);
+
+ zero = av_mallocz(p->linesize[0]);
+ last = zero;
+ cur = p->data[0];
+ if(avctx->pix_fmt == PIX_FMT_GRAY8){
+ int t = 0;
+
+ for(i = 0; i < avctx->height; i++) {
+ ls_encode_line(state, &pb2, last, cur, t, avctx->width, 1, 0, 8);
+ t = last[0];
+ last = cur;
+ cur += p->linesize[0];
+ }
+ }else if(avctx->pix_fmt == PIX_FMT_GRAY16){
+ int t = 0;
+
+ for(i = 0; i < avctx->height; i++) {
+ ls_encode_line(state, &pb2, last, cur, t, avctx->width, 1, 0, 16);
+ t = *((uint16_t*)last);
+ last = cur;
+ cur += p->linesize[0];
+ }
+ }else if(avctx->pix_fmt == PIX_FMT_RGB24){
+ int j, width;
+ int Rc[3] = {0, 0, 0};
+
+ width = avctx->width * 3;
+ for(i = 0; i < avctx->height; i++) {
+ for(j = 0; j < 3; j++) {
+ ls_encode_line(state, &pb2, last + j, cur + j, Rc[j], width, 3, j, 8);
+ Rc[j] = last[j];
+ }
+ last = cur;
+ cur += s->picture.linesize[0];
+ }
+ }else if(avctx->pix_fmt == PIX_FMT_BGR24){
+ int j, width;
+ int Rc[3] = {0, 0, 0};
+
+ width = avctx->width * 3;
+ for(i = 0; i < avctx->height; i++) {
+ for(j = 2; j >= 0; j--) {
+ ls_encode_line(state, &pb2, last + j, cur + j, Rc[j], width, 3, j, 8);
+ Rc[j] = last[j];
+ }
+ last = cur;
+ cur += s->picture.linesize[0];
+ }
+ }
+
+ av_free(zero);
+ av_free(state);
+
+ // the specification says that after doing 0xff escaping unused bits in the
+ // last byte must be set to 0, so just append 7 "optional" zero-bits to
+ // avoid special-casing.
+ put_bits(&pb2, 7, 0);
+ size = put_bits_count(&pb2);
+ flush_put_bits(&pb2);
+ /* do escape coding */
+ init_get_bits(&gb, buf2, size);
+ size -= 7;
+ while(get_bits_count(&gb) < size){
+ int v;
+ v = get_bits(&gb, 8);
+ put_bits(&pb, 8, v);
+ if(v == 0xFF){
+ v = get_bits(&gb, 7);
+ put_bits(&pb, 8, v);
+ }
+ }
+ align_put_bits(&pb);
+ av_free(buf2);
+
+ /* End of image */
+ put_marker(&pb, EOI);
+ flush_put_bits(&pb);
+
+ emms_c();
+
+ return put_bits_count(&pb) >> 3;
+}
+
+static int encode_init_ls(AVCodecContext *ctx) {
+ JpeglsContext *c = (JpeglsContext*)ctx->priv_data;
+
+ c->avctx = ctx;
+ ctx->coded_frame = &c->picture;
+
+ if(ctx->pix_fmt != PIX_FMT_GRAY8 && ctx->pix_fmt != PIX_FMT_GRAY16 && ctx->pix_fmt != PIX_FMT_RGB24 && ctx->pix_fmt != PIX_FMT_BGR24){
+ av_log(ctx, AV_LOG_ERROR, "Only grayscale and RGB24/BGR24 images are supported\n");
+ return -1;
+ }
+ return 0;
+}
+
+AVCodec jpegls_encoder = { //FIXME avoid MPV_* lossless jpeg shouldnt need them
+ "jpegls",
+ CODEC_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, -1},
+};
+#endif
diff --git a/src/libffmpeg/libavcodec/jrevdct.c b/contrib/ffmpeg/libavcodec/jrevdct.c
index f055cc1ac..f055cc1ac 100644
--- a/src/libffmpeg/libavcodec/jrevdct.c
+++ b/contrib/ffmpeg/libavcodec/jrevdct.c
diff --git a/contrib/ffmpeg/libavcodec/kmvc.c b/contrib/ffmpeg/libavcodec/kmvc.c
new file mode 100644
index 000000000..08de05188
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/kmvc.c
@@ -0,0 +1,416 @@
+/*
+ * KMVC decoder
+ * Copyright (c) 2006 Konstantin Shishkov
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * @file kmvc.c
+ * Karl Morton's Video Codec decoder
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "common.h"
+#include "avcodec.h"
+
+#define KMVC_KEYFRAME 0x80
+#define KMVC_PALETTE 0x40
+#define KMVC_METHOD 0x0F
+
+/*
+ * Decoder context
+ */
+typedef struct KmvcContext {
+ AVCodecContext *avctx;
+ AVFrame pic;
+
+ int setpal;
+ int palsize;
+ uint32_t pal[256];
+ uint8_t *cur, *prev;
+ uint8_t *frm0, *frm1;
+} KmvcContext;
+
+typedef struct BitBuf {
+ int bits;
+ int bitbuf;
+} BitBuf;
+
+#define BLK(data, x, y) data[(x) + (y) * 320]
+
+#define kmvc_init_getbits(bb, src) bb.bits = 7; bb.bitbuf = *src++;
+
+#define kmvc_getbit(bb, src, res) {\
+ res = 0; \
+ if (bb.bitbuf & (1 << bb.bits)) res = 1; \
+ bb.bits--; \
+ if(bb.bits == -1) { \
+ bb.bitbuf = *src++; \
+ bb.bits = 7; \
+ } \
+}
+
+static void kmvc_decode_intra_8x8(KmvcContext * ctx, uint8_t * src, int w, int h)
+{
+ BitBuf bb;
+ int res, val;
+ int i, j;
+ int bx, by;
+ int l0x, l1x, l0y, l1y;
+ int mx, my;
+
+ kmvc_init_getbits(bb, src);
+
+ for (by = 0; by < h; by += 8)
+ for (bx = 0; bx < w; bx += 8) {
+ kmvc_getbit(bb, src, res);
+ if (!res) { // fill whole 8x8 block
+ val = *src++;
+ for (i = 0; i < 64; i++)
+ BLK(ctx->cur, bx + (i & 0x7), by + (i >> 3)) = val;
+ } else { // handle four 4x4 subblocks
+ for (i = 0; i < 4; i++) {
+ l0x = bx + (i & 1) * 4;
+ l0y = by + (i & 2) * 2;
+ kmvc_getbit(bb, src, res);
+ if (!res) {
+ kmvc_getbit(bb, src, res);
+ if (!res) { // fill whole 4x4 block
+ val = *src++;
+ for (j = 0; j < 16; j++)
+ BLK(ctx->cur, l0x + (j & 3), l0y + (j >> 2)) = val;
+ } else { // copy block from already decoded place
+ val = *src++;
+ mx = val & 0xF;
+ my = val >> 4;
+ for (j = 0; j < 16; j++)
+ BLK(ctx->cur, l0x + (j & 3), l0y + (j >> 2)) =
+ BLK(ctx->cur, l0x + (j & 3) - mx, l0y + (j >> 2) - my);
+ }
+ } else { // descend to 2x2 sub-sub-blocks
+ for (j = 0; j < 4; j++) {
+ l1x = l0x + (j & 1) * 2;
+ l1y = l0y + (j & 2);
+ kmvc_getbit(bb, src, res);
+ if (!res) {
+ kmvc_getbit(bb, src, res);
+ if (!res) { // fill whole 2x2 block
+ val = *src++;
+ BLK(ctx->cur, l1x, l1y) = val;
+ BLK(ctx->cur, l1x + 1, l1y) = val;
+ BLK(ctx->cur, l1x, l1y + 1) = val;
+ BLK(ctx->cur, l1x + 1, l1y + 1) = val;
+ } else { // copy block from already decoded place
+ val = *src++;
+ mx = val & 0xF;
+ my = val >> 4;
+ BLK(ctx->cur, l1x, l1y) = BLK(ctx->cur, l1x - mx, l1y - my);
+ BLK(ctx->cur, l1x + 1, l1y) =
+ BLK(ctx->cur, l1x + 1 - mx, l1y - my);
+ BLK(ctx->cur, l1x, l1y + 1) =
+ BLK(ctx->cur, l1x - mx, l1y + 1 - my);
+ BLK(ctx->cur, l1x + 1, l1y + 1) =
+ BLK(ctx->cur, l1x + 1 - mx, l1y + 1 - my);
+ }
+ } else { // read values for block
+ BLK(ctx->cur, l1x, l1y) = *src++;
+ BLK(ctx->cur, l1x + 1, l1y) = *src++;
+ BLK(ctx->cur, l1x, l1y + 1) = *src++;
+ BLK(ctx->cur, l1x + 1, l1y + 1) = *src++;
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+static void kmvc_decode_inter_8x8(KmvcContext * ctx, uint8_t * src, int w, int h)
+{
+ BitBuf bb;
+ int res, val;
+ int i, j;
+ int bx, by;
+ int l0x, l1x, l0y, l1y;
+ int mx, my;
+
+ kmvc_init_getbits(bb, src);
+
+ for (by = 0; by < h; by += 8)
+ for (bx = 0; bx < w; bx += 8) {
+ kmvc_getbit(bb, src, res);
+ if (!res) {
+ kmvc_getbit(bb, src, res);
+ if (!res) { // fill whole 8x8 block
+ val = *src++;
+ for (i = 0; i < 64; i++)
+ BLK(ctx->cur, bx + (i & 0x7), by + (i >> 3)) = val;
+ } else { // copy block from previous frame
+ for (i = 0; i < 64; i++)
+ BLK(ctx->cur, bx + (i & 0x7), by + (i >> 3)) =
+ BLK(ctx->prev, bx + (i & 0x7), by + (i >> 3));
+ }
+ } else { // handle four 4x4 subblocks
+ for (i = 0; i < 4; i++) {
+ l0x = bx + (i & 1) * 4;
+ l0y = by + (i & 2) * 2;
+ kmvc_getbit(bb, src, res);
+ if (!res) {
+ kmvc_getbit(bb, src, res);
+ if (!res) { // fill whole 4x4 block
+ val = *src++;
+ for (j = 0; j < 16; j++)
+ BLK(ctx->cur, l0x + (j & 3), l0y + (j >> 2)) = val;
+ } else { // copy block
+ val = *src++;
+ mx = (val & 0xF) - 8;
+ my = (val >> 4) - 8;
+ for (j = 0; j < 16; j++)
+ BLK(ctx->cur, l0x + (j & 3), l0y + (j >> 2)) =
+ BLK(ctx->prev, l0x + (j & 3) + mx, l0y + (j >> 2) + my);
+ }
+ } else { // descend to 2x2 sub-sub-blocks
+ for (j = 0; j < 4; j++) {
+ l1x = l0x + (j & 1) * 2;
+ l1y = l0y + (j & 2);
+ kmvc_getbit(bb, src, res);
+ if (!res) {
+ kmvc_getbit(bb, src, res);
+ if (!res) { // fill whole 2x2 block
+ val = *src++;
+ BLK(ctx->cur, l1x, l1y) = val;
+ BLK(ctx->cur, l1x + 1, l1y) = val;
+ BLK(ctx->cur, l1x, l1y + 1) = val;
+ BLK(ctx->cur, l1x + 1, l1y + 1) = val;
+ } else { // copy block
+ val = *src++;
+ mx = (val & 0xF) - 8;
+ my = (val >> 4) - 8;
+ BLK(ctx->cur, l1x, l1y) = BLK(ctx->prev, l1x + mx, l1y + my);
+ BLK(ctx->cur, l1x + 1, l1y) =
+ BLK(ctx->prev, l1x + 1 + mx, l1y + my);
+ BLK(ctx->cur, l1x, l1y + 1) =
+ BLK(ctx->prev, l1x + mx, l1y + 1 + my);
+ BLK(ctx->cur, l1x + 1, l1y + 1) =
+ BLK(ctx->prev, l1x + 1 + mx, l1y + 1 + my);
+ }
+ } else { // read values for block
+ BLK(ctx->cur, l1x, l1y) = *src++;
+ BLK(ctx->cur, l1x + 1, l1y) = *src++;
+ BLK(ctx->cur, l1x, l1y + 1) = *src++;
+ BLK(ctx->cur, l1x + 1, l1y + 1) = *src++;
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+static int decode_frame(AVCodecContext * avctx, void *data, int *data_size, uint8_t * buf,
+ int buf_size)
+{
+ KmvcContext *const ctx = (KmvcContext *) avctx->priv_data;
+ uint8_t *out, *src;
+ int i;
+ int header;
+ int blocksize;
+
+ if (ctx->pic.data[0])
+ avctx->release_buffer(avctx, &ctx->pic);
+
+ ctx->pic.reference = 1;
+ ctx->pic.buffer_hints = FF_BUFFER_HINTS_VALID;
+ if (avctx->get_buffer(avctx, &ctx->pic) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ return -1;
+ }
+
+ header = *buf++;
+
+ /* blocksize 127 is really palette change event */
+ if (buf[0] == 127) {
+ buf += 3;
+ for (i = 0; i < 127; i++) {
+ ctx->pal[i + (header & 0x81)] = (buf[0] << 16) | (buf[1] << 8) | buf[2];
+ buf += 4;
+ }
+ buf -= 127 * 4 + 3;
+ }
+
+ if (header & KMVC_KEYFRAME) {
+ ctx->pic.key_frame = 1;
+ ctx->pic.pict_type = FF_I_TYPE;
+ } else {
+ ctx->pic.key_frame = 0;
+ ctx->pic.pict_type = FF_P_TYPE;
+ }
+
+ /* if palette has been changed, copy it from palctrl */
+ if (ctx->avctx->palctrl && ctx->avctx->palctrl->palette_changed) {
+ memcpy(ctx->pal, ctx->avctx->palctrl->palette, AVPALETTE_SIZE);
+ ctx->setpal = 1;
+ ctx->avctx->palctrl->palette_changed = 0;
+ }
+
+ if (header & KMVC_PALETTE) {
+ ctx->pic.palette_has_changed = 1;
+ // palette starts from index 1 and has 127 entries
+ for (i = 1; i <= ctx->palsize; i++) {
+ ctx->pal[i] = (buf[0] << 16) | (buf[1] << 8) | buf[2];
+ buf += 3;
+ }
+ }
+
+ if (ctx->setpal) {
+ ctx->setpal = 0;
+ ctx->pic.palette_has_changed = 1;
+ }
+
+ /* make the palette available on the way out */
+ memcpy(ctx->pic.data[1], ctx->pal, 1024);
+
+ blocksize = *buf++;
+
+ if (blocksize != 8 && blocksize != 127) {
+ av_log(avctx, AV_LOG_ERROR, "Block size = %i\n", blocksize);
+ return -1;
+ }
+ memset(ctx->cur, 0, 320 * 200);
+ switch (header & KMVC_METHOD) {
+ case 0:
+ case 1: // used in palette changed event
+ memcpy(ctx->cur, ctx->prev, 320 * 200);
+ break;
+ case 3:
+ kmvc_decode_intra_8x8(ctx, buf, avctx->width, avctx->height);
+ break;
+ case 4:
+ kmvc_decode_inter_8x8(ctx, buf, avctx->width, avctx->height);
+ break;
+ default:
+ av_log(avctx, AV_LOG_ERROR, "Unknown compression method %i\n", header & KMVC_METHOD);
+ return -1;
+ }
+
+ out = ctx->pic.data[0];
+ src = ctx->cur;
+ for (i = 0; i < avctx->height; i++) {
+ memcpy(out, src, avctx->width);
+ src += 320;
+ out += ctx->pic.linesize[0];
+ }
+
+ /* flip buffers */
+ if (ctx->cur == ctx->frm0) {
+ ctx->cur = ctx->frm1;
+ ctx->prev = ctx->frm0;
+ } else {
+ ctx->cur = ctx->frm0;
+ ctx->prev = ctx->frm1;
+ }
+
+ *data_size = sizeof(AVFrame);
+ *(AVFrame *) data = ctx->pic;
+
+ /* always report that the buffer was completely consumed */
+ return buf_size;
+}
+
+
+
+/*
+ * Init kmvc decoder
+ */
+static int decode_init(AVCodecContext * avctx)
+{
+ KmvcContext *const c = (KmvcContext *) avctx->priv_data;
+ int i;
+
+ c->avctx = avctx;
+
+ c->pic.data[0] = NULL;
+
+ if (avctx->width > 320 || avctx->height > 200) {
+ av_log(avctx, AV_LOG_ERROR, "KMVC supports frames <= 320x200\n");
+ return -1;
+ }
+
+ c->frm0 = av_mallocz(320 * 200);
+ c->frm1 = av_mallocz(320 * 200);
+ c->cur = c->frm0;
+ c->prev = c->frm1;
+
+ for (i = 0; i < 256; i++) {
+ c->pal[i] = i * 0x10101;
+ }
+
+ if (avctx->extradata_size < 12) {
+ av_log(NULL, 0, "Extradata missing, decoding may not work properly...\n");
+ c->palsize = 127;
+ } else {
+ c->palsize = AV_RL16(avctx->extradata + 10);
+ }
+
+ if (avctx->extradata_size == 1036) { // palette in extradata
+ uint8_t *src = avctx->extradata + 12;
+ for (i = 0; i < 256; i++) {
+ c->pal[i] = AV_RL32(src);
+ src += 4;
+ }
+ c->setpal = 1;
+ if (c->avctx->palctrl) {
+ c->avctx->palctrl->palette_changed = 0;
+ }
+ }
+
+ avctx->pix_fmt = PIX_FMT_PAL8;
+
+ return 0;
+}
+
+
+
+/*
+ * Uninit kmvc decoder
+ */
+static int decode_end(AVCodecContext * avctx)
+{
+ KmvcContext *const c = (KmvcContext *) avctx->priv_data;
+
+ av_freep(&c->frm0);
+ av_freep(&c->frm1);
+ if (c->pic.data[0])
+ avctx->release_buffer(avctx, &c->pic);
+
+ return 0;
+}
+
+AVCodec kmvc_decoder = {
+ "kmvc",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_KMVC,
+ sizeof(KmvcContext),
+ decode_init,
+ NULL,
+ decode_end,
+ decode_frame
+};
diff --git a/src/libffmpeg/libavcodec/lcl.c b/contrib/ffmpeg/libavcodec/lcl.c
index b02ea1543..b02ea1543 100644
--- a/src/libffmpeg/libavcodec/lcl.c
+++ b/contrib/ffmpeg/libavcodec/lcl.c
diff --git a/contrib/ffmpeg/libavcodec/libgsm.c b/contrib/ffmpeg/libavcodec/libgsm.c
new file mode 100644
index 000000000..86dfce575
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/libgsm.c
@@ -0,0 +1,145 @@
+/*
+ * Interface to libgsm for gsm encoding/decoding
+ * Copyright (c) 2005 Alban Bedel <albeu@free.fr>
+ * Copyright (c) 2006, 2007 Michel Bardiaux <mbardiaux@mediaxim.be>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 libgsm.c
+ * 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 <gsm.h>
+
+// gsm.h miss some essential constants
+#define GSM_BLOCK_SIZE 33
+#define GSM_MS_BLOCK_SIZE 65
+#define GSM_FRAME_SIZE 160
+
+static int libgsm_init(AVCodecContext *avctx) {
+ if (avctx->channels > 1 || avctx->sample_rate != 8000 || avctx->bit_rate != 13000)
+ return -1;
+
+ avctx->priv_data = gsm_create();
+
+ switch(avctx->codec_id) {
+ case CODEC_ID_GSM:
+ avctx->frame_size = GSM_FRAME_SIZE;
+ avctx->block_align = GSM_BLOCK_SIZE;
+ break;
+ case CODEC_ID_GSM_MS: {
+ int one = 1;
+ gsm_option(avctx->priv_data, GSM_OPT_WAV49, &one);
+ avctx->frame_size = 2*GSM_FRAME_SIZE;
+ avctx->block_align = GSM_MS_BLOCK_SIZE;
+ }
+ }
+
+ avctx->coded_frame= avcodec_alloc_frame();
+ avctx->coded_frame->key_frame= 1;
+
+ return 0;
+}
+
+static int libgsm_close(AVCodecContext *avctx) {
+ gsm_destroy(avctx->priv_data);
+ avctx->priv_data = NULL;
+ return 0;
+}
+
+static int libgsm_encode_frame(AVCodecContext *avctx,
+ unsigned char *frame, int buf_size, void *data) {
+ // we need a full block
+ if(buf_size < avctx->block_align) return 0;
+
+ switch(avctx->codec_id) {
+ case CODEC_ID_GSM:
+ gsm_encode(avctx->priv_data,data,frame);
+ break;
+ case CODEC_ID_GSM_MS:
+ gsm_encode(avctx->priv_data,data,frame);
+ gsm_encode(avctx->priv_data,((short*)data)+GSM_FRAME_SIZE,frame+32);
+ }
+ return avctx->block_align;
+}
+
+
+AVCodec libgsm_encoder = {
+ "gsm",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_GSM,
+ 0,
+ libgsm_init,
+ libgsm_encode_frame,
+ libgsm_close,
+};
+
+AVCodec libgsm_ms_encoder = {
+ "gsm",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_GSM_MS,
+ 0,
+ libgsm_init,
+ libgsm_encode_frame,
+ libgsm_close,
+};
+
+static int libgsm_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size) {
+
+ if(buf_size < avctx->block_align) return 0;
+
+ switch(avctx->codec_id) {
+ case CODEC_ID_GSM:
+ if(gsm_decode(avctx->priv_data,buf,data)) return -1;
+ *data_size = GSM_FRAME_SIZE*sizeof(int16_t);
+ break;
+ case CODEC_ID_GSM_MS:
+ if(gsm_decode(avctx->priv_data,buf,data) ||
+ gsm_decode(avctx->priv_data,buf+33,((int16_t*)data)+GSM_FRAME_SIZE)) return -1;
+ *data_size = GSM_FRAME_SIZE*sizeof(int16_t)*2;
+ }
+ return avctx->block_align;
+}
+
+AVCodec libgsm_decoder = {
+ "gsm",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_GSM,
+ 0,
+ libgsm_init,
+ NULL,
+ libgsm_close,
+ libgsm_decode_frame,
+};
+
+AVCodec libgsm_ms_decoder = {
+ "gsm_ms",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_GSM_MS,
+ 0,
+ libgsm_init,
+ NULL,
+ libgsm_close,
+ libgsm_decode_frame,
+};
diff --git a/contrib/ffmpeg/libavcodec/libtheoraenc.c b/contrib/ffmpeg/libavcodec/libtheoraenc.c
new file mode 100644
index 000000000..7f531dbee
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/libtheoraenc.c
@@ -0,0 +1,280 @@
+/*
+ * Copyright (c) 2006 Paul Richards <paul.richards@gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*!
+ * \file theoraenc.c
+ * \brief Theora encoder using libtheora.
+ * \author Paul Richards <paul.richards@gmail.com>
+ *
+ * A lot of this is copy / paste from other output codecs in
+ * libavcodec or pure guesswork (or both).
+ *
+ * I have used t_ prefixes on variables which are libtheora types
+ * and o_ prefixes on variables which are libogg types.
+ */
+
+/* FFmpeg includes */
+#include "avcodec.h"
+#include "log.h"
+
+/* libtheora includes */
+#include <theora/theora.h>
+
+typedef struct TheoraContext{
+ theora_state t_state;
+} TheoraContext;
+
+/*!
+ Concatenates an ogg_packet into the extradata.
+*/
+static int concatenate_packet(unsigned int* offset, AVCodecContext* avc_context, const ogg_packet* packet)
+{
+ char* message = NULL;
+ uint8_t* newdata = NULL;
+ int newsize = avc_context->extradata_size + 2 + packet->bytes;
+
+ if (packet->bytes < 0) {
+ message = "ogg_packet has negative size";
+ } else if (packet->bytes > 0xffff) {
+ message = "ogg_packet is larger than 65535 bytes";
+ } else if (newsize < avc_context->extradata_size) {
+ message = "extradata_size would overflow";
+ } else {
+ newdata = av_realloc(avc_context->extradata, newsize);
+ if (newdata == NULL) {
+ message = "av_realloc failed";
+ }
+ }
+ if (message != NULL) {
+ av_log(avc_context, AV_LOG_ERROR, "concatenate_packet failed: %s\n", message);
+ return -1;
+ }
+
+ avc_context->extradata = newdata;
+ avc_context->extradata_size = newsize;
+ avc_context->extradata[ (*offset)++ ] = packet->bytes >> 8;
+ avc_context->extradata[ (*offset)++ ] = packet->bytes & 0xff;
+ memcpy( avc_context->extradata + (*offset), packet->packet, packet->bytes );
+ (*offset) += packet->bytes;
+ return 0;
+}
+
+static int encode_init(AVCodecContext* avc_context)
+{
+ theora_info t_info;
+ theora_comment t_comment;
+ ogg_packet o_packet;
+ unsigned int offset;
+ TheoraContext *h = avc_context->priv_data;
+
+ /* Set up the theora_info struct */
+ theora_info_init( &t_info );
+ t_info.width = avc_context->width;
+ t_info.height = avc_context->height;
+ t_info.frame_width = avc_context->width;
+ t_info.frame_height = avc_context->height;
+ t_info.offset_x = 0;
+ t_info.offset_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_denominator = avc_context->time_base.num;
+ if (avc_context->sample_aspect_ratio.num != 0) {
+ 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_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;
+
+ /* Now initialise libtheora */
+ if (theora_encode_init( &(h->t_state), &t_info ) != 0) {
+ av_log(avc_context, AV_LOG_ERROR, "theora_encode_init failed\n");
+ return -1;
+ }
+
+ /* Clear up theora_info struct */
+ theora_info_clear( &t_info );
+
+ /*
+ Output first header packet consisting of theora
+ header, comment, and tables.
+
+ Each one is prefixed with a 16bit size, then they
+ are concatenated together into ffmpeg's extradata.
+ */
+ offset = 0;
+
+ /* Header */
+ theora_encode_header( &(h->t_state), &o_packet );
+ if (concatenate_packet( &offset, avc_context, &o_packet ) != 0) {
+ return -1;
+ }
+
+ /* Comment */
+ theora_comment_init( &t_comment );
+ theora_encode_comment( &t_comment, &o_packet );
+ if (concatenate_packet( &offset, avc_context, &o_packet ) != 0) {
+ return -1;
+ }
+
+ /* Tables */
+ theora_encode_tables( &(h->t_state), &o_packet );
+ if (concatenate_packet( &offset, avc_context, &o_packet ) != 0) {
+ return -1;
+ }
+
+ /* Clear up theora_comment struct */
+ theora_comment_clear( &t_comment );
+
+ /* Set up the output AVFrame */
+ avc_context->coded_frame= avcodec_alloc_frame();
+
+ return 0;
+}
+
+static int encode_frame(
+ AVCodecContext* avc_context,
+ uint8_t *outbuf,
+ int buf_size,
+ void *data)
+{
+ yuv_buffer t_yuv_buffer;
+ TheoraContext *h = avc_context->priv_data;
+ AVFrame *frame = data;
+ ogg_packet o_packet;
+ int result;
+
+ 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;
+ }
+
+ t_yuv_buffer.y_width = avc_context->width;
+ t_yuv_buffer.y_height = avc_context->height;
+ 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];
+
+ t_yuv_buffer.y = frame->data[0];
+ t_yuv_buffer.u = frame->data[1];
+ t_yuv_buffer.v = frame->data[2];
+
+ /* Now call into theora_encode_YUVin */
+ result = theora_encode_YUVin( &(h->t_state), &t_yuv_buffer );
+ if (result != 0) {
+ 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;
+ }
+ 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);
+ return -1;
+ }
+
+ /* Copy ogg_packet content out to buffer */
+ if (buf_size < o_packet.bytes) {
+ av_log(avc_context, AV_LOG_ERROR, "encoded frame too large\n");
+ return -1;
+ }
+ memcpy(outbuf, o_packet.packet, o_packet.bytes);
+
+ return o_packet.bytes;
+}
+
+static 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) );
+ 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;
+}
+
+static const enum PixelFormat supported_pixel_formats[] = { PIX_FMT_YUV420P, -1 };
+
+/*! AVCodec struct exposed to libavcodec */
+AVCodec libtheora_encoder =
+{
+ .name = "libtheora",
+ .type = CODEC_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,
+};
diff --git a/contrib/ffmpeg/libavcodec/loco.c b/contrib/ffmpeg/libavcodec/loco.c
new file mode 100644
index 000000000..760699d45
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/loco.c
@@ -0,0 +1,287 @@
+/*
+ * LOCO codec
+ * Copyright (c) 2005 Konstantin Shishkov
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * @file loco.c
+ * LOCO codec.
+ */
+
+#include "avcodec.h"
+#include "common.h"
+#include "bitstream.h"
+#include "golomb.h"
+
+enum LOCO_MODE {LOCO_UNKN=0, LOCO_CYUY2=-1, LOCO_CRGB=-2, LOCO_CRGBA=-3, LOCO_CYV12=-4,
+ LOCO_YUY2=1, LOCO_UYVY=2, LOCO_RGB=3, LOCO_RGBA=4, LOCO_YV12=5};
+
+typedef struct LOCOContext{
+ AVCodecContext *avctx;
+ AVFrame pic;
+ int lossy;
+ int mode;
+} LOCOContext;
+
+typedef struct RICEContext{
+ GetBitContext gb;
+ int save, run, run2; /* internal rice decoder state */
+ int sum, count; /* sum and count for getting rice parameter */
+ int lossy;
+}RICEContext;
+
+static int loco_get_rice_param(RICEContext *r)
+{
+ int cnt = 0;
+ int val = r->count;
+
+ while(r->sum > val && cnt < 9) {
+ val <<= 1;
+ cnt++;
+ }
+
+ return cnt;
+}
+
+static inline void loco_update_rice_param(RICEContext *r, int val)
+{
+ r->sum += val;
+ r->count++;
+
+ if(r->count == 16) {
+ r->sum >>= 1;
+ r->count >>= 1;
+ }
+}
+
+static inline int loco_get_rice(RICEContext *r)
+{
+ int v;
+ if (r->run > 0) { /* we have zero run */
+ r->run--;
+ loco_update_rice_param(r, 0);
+ return 0;
+ }
+ v = get_ur_golomb_jpegls(&r->gb, loco_get_rice_param(r), INT_MAX, 0);
+ loco_update_rice_param(r, (v+1)>>1);
+ if (!v) {
+ if (r->save >= 0) {
+ r->run = get_ur_golomb_jpegls(&r->gb, 2, INT_MAX, 0);
+ if(r->run > 1)
+ r->save += r->run + 1;
+ else
+ r->save -= 3;
+ }
+ else
+ r->run2++;
+ } else {
+ v = ((v>>1) + r->lossy) ^ -(v&1);
+ if (r->run2 > 0) {
+ if (r->run2 > 2)
+ r->save += r->run2;
+ else
+ r->save -= 3;
+ r->run2 = 0;
+ }
+ }
+
+ return v;
+}
+
+/* LOCO main predictor - LOCO-I/JPEG-LS predictor */
+static inline int loco_predict(uint8_t* data, int stride, int step)
+{
+ int a, b, c;
+
+ a = data[-stride];
+ b = data[-step];
+ c = data[-stride - step];
+
+ return mid_pred(a, a + b - c, b);
+}
+
+static int loco_decode_plane(LOCOContext *l, uint8_t *data, int width, int height,
+ int stride, uint8_t *buf, int buf_size, int step)
+{
+ RICEContext rc;
+ int val;
+ int i, j;
+
+ init_get_bits(&rc.gb, buf, buf_size*8);
+ rc.save = 0;
+ rc.run = 0;
+ rc.run2 = 0;
+ rc.lossy = l->lossy;
+
+ rc.sum = 8;
+ rc.count = 1;
+
+ /* restore top left pixel */
+ val = loco_get_rice(&rc);
+ data[0] = 128 + val;
+ /* restore top line */
+ for (i = 1; i < width; i++) {
+ val = loco_get_rice(&rc);
+ data[i * step] = data[i * step - step] + val;
+ }
+ data += stride;
+ for (j = 1; j < height; j++) {
+ /* restore left column */
+ val = loco_get_rice(&rc);
+ data[0] = data[-stride] + val;
+ /* restore all other pixels */
+ for (i = 1; i < width; i++) {
+ val = loco_get_rice(&rc);
+ data[i * step] = loco_predict(&data[i * step], stride, step) + val;
+ }
+ data += stride;
+ }
+
+ return ((get_bits_count(&rc.gb) + 7) >> 3);
+}
+
+static int decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ LOCOContext * const l = avctx->priv_data;
+ AVFrame * const p= (AVFrame*)&l->pic;
+ int decoded;
+
+ 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->key_frame = 1;
+
+ switch(l->mode) {
+ case LOCO_CYUY2: case LOCO_YUY2: case LOCO_UYVY:
+ decoded = loco_decode_plane(l, p->data[0], avctx->width, avctx->height,
+ p->linesize[0], buf, buf_size, 1);
+ buf += decoded; buf_size -= decoded;
+ decoded = loco_decode_plane(l, p->data[1], avctx->width / 2, avctx->height,
+ p->linesize[1], buf, buf_size, 1);
+ buf += decoded; buf_size -= decoded;
+ decoded = loco_decode_plane(l, p->data[2], avctx->width / 2, avctx->height,
+ p->linesize[2], buf, buf_size, 1);
+ break;
+ case LOCO_CYV12: case LOCO_YV12:
+ decoded = loco_decode_plane(l, p->data[0], avctx->width, avctx->height,
+ p->linesize[0], buf, buf_size, 1);
+ buf += decoded; buf_size -= decoded;
+ decoded = loco_decode_plane(l, p->data[2], avctx->width / 2, avctx->height / 2,
+ p->linesize[2], buf, buf_size, 1);
+ buf += decoded; buf_size -= decoded;
+ decoded = loco_decode_plane(l, p->data[1], avctx->width / 2, avctx->height / 2,
+ p->linesize[1], buf, buf_size, 1);
+ break;
+ case LOCO_CRGB: case LOCO_RGB:
+ decoded = loco_decode_plane(l, p->data[0] + p->linesize[0]*(avctx->height-1), avctx->width, avctx->height,
+ -p->linesize[0], buf, buf_size, 3);
+ buf += decoded; buf_size -= decoded;
+ decoded = loco_decode_plane(l, p->data[0] + p->linesize[0]*(avctx->height-1) + 1, avctx->width, avctx->height,
+ -p->linesize[0], buf, buf_size, 3);
+ buf += decoded; buf_size -= decoded;
+ decoded = loco_decode_plane(l, p->data[0] + p->linesize[0]*(avctx->height-1) + 2, avctx->width, avctx->height,
+ -p->linesize[0], buf, buf_size, 3);
+ break;
+ case LOCO_RGBA:
+ decoded = loco_decode_plane(l, p->data[0], avctx->width, avctx->height,
+ p->linesize[0], buf, buf_size, 4);
+ buf += decoded; buf_size -= decoded;
+ decoded = loco_decode_plane(l, p->data[0] + 1, avctx->width, avctx->height,
+ p->linesize[0], buf, buf_size, 4);
+ buf += decoded; buf_size -= decoded;
+ decoded = loco_decode_plane(l, p->data[0] + 2, avctx->width, avctx->height,
+ p->linesize[0], buf, buf_size, 4);
+ buf += decoded; buf_size -= decoded;
+ decoded = loco_decode_plane(l, p->data[0] + 3, avctx->width, avctx->height,
+ p->linesize[0], buf, buf_size, 4);
+ break;
+ }
+
+ *data_size = sizeof(AVFrame);
+ *(AVFrame*)data = l->pic;
+
+ return buf_size;
+}
+
+static int decode_init(AVCodecContext *avctx){
+ LOCOContext * const l = avctx->priv_data;
+ int version;
+
+ l->avctx = avctx;
+ if (avctx->extradata_size < 12) {
+ av_log(avctx, AV_LOG_ERROR, "Extradata size must be >= 12 instead of %i\n",
+ avctx->extradata_size);
+ return -1;
+ }
+ version = AV_RL32(avctx->extradata);
+ switch(version) {
+ case 1:
+ l->lossy = 0;
+ break;
+ case 2:
+ l->lossy = AV_RL32(avctx->extradata + 8);
+ break;
+ default:
+ l->lossy = AV_RL32(avctx->extradata + 8);
+ av_log(avctx, AV_LOG_INFO, "This is LOCO codec version %i, please upload file for study\n", version);
+ }
+
+ l->mode = AV_RL32(avctx->extradata + 4);
+ switch(l->mode) {
+ case LOCO_CYUY2: case LOCO_YUY2: case LOCO_UYVY:
+ avctx->pix_fmt = PIX_FMT_YUV422P;
+ break;
+ case LOCO_CRGB: case LOCO_RGB:
+ avctx->pix_fmt = PIX_FMT_BGR24;
+ break;
+ case LOCO_CYV12: case LOCO_YV12:
+ avctx->pix_fmt = PIX_FMT_YUV420P;
+ break;
+ case LOCO_CRGBA: case LOCO_RGBA:
+ avctx->pix_fmt = PIX_FMT_RGB32;
+ break;
+ default:
+ av_log(avctx, AV_LOG_INFO, "Unknown colorspace, index = %i\n", l->mode);
+ return -1;
+ }
+ if(avctx->debug & FF_DEBUG_PICT_INFO)
+ av_log(avctx, AV_LOG_INFO, "lossy:%i, version:%i, mode: %i\n", l->lossy, version, l->mode);
+
+ return 0;
+}
+
+AVCodec loco_decoder = {
+ "loco",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_LOCO,
+ sizeof(LOCOContext),
+ decode_init,
+ NULL,
+ NULL,
+ decode_frame,
+ CODEC_CAP_DR1,
+};
diff --git a/contrib/ffmpeg/libavcodec/lzw.c b/contrib/ffmpeg/libavcodec/lzw.c
new file mode 100644
index 000000000..6bc0b9a48
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/lzw.c
@@ -0,0 +1,229 @@
+/*
+ * LZW decoder
+ * Copyright (c) 2003 Fabrice Bellard.
+ * Copyright (c) 2006 Konstantin Shishkov.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file lzw.c
+ * @brief LZW decoding routines
+ * @author Fabrice Bellard
+ * Modified for use in TIFF by Konstantin Shishkov
+ */
+
+#include "avcodec.h"
+#include "lzw.h"
+
+#define LZW_MAXBITS 12
+#define LZW_SIZTABLE (1<<LZW_MAXBITS)
+
+static const uint16_t mask[17] =
+{
+ 0x0000, 0x0001, 0x0003, 0x0007,
+ 0x000F, 0x001F, 0x003F, 0x007F,
+ 0x00FF, 0x01FF, 0x03FF, 0x07FF,
+ 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF
+};
+
+struct LZWState {
+ uint8_t *pbuf, *ebuf;
+ int bbits;
+ unsigned int bbuf;
+
+ int mode; ///< Decoder mode
+ int cursize; ///< The current code size
+ int curmask;
+ int codesize;
+ int clear_code;
+ int end_code;
+ int newcodes; ///< First available code
+ int top_slot; ///< Highest code for current size
+ int extra_slot;
+ int slot; ///< Last read code
+ int fc, oc;
+ uint8_t *sp;
+ uint8_t stack[LZW_SIZTABLE];
+ uint8_t suffix[LZW_SIZTABLE];
+ uint16_t prefix[LZW_SIZTABLE];
+ int bs; ///< current buffer size for GIF
+};
+
+/* get one code from stream */
+static int lzw_get_code(struct LZWState * s)
+{
+ int c;
+
+ if(s->mode == FF_LZW_GIF) {
+ while (s->bbits < s->cursize) {
+ if (!s->bs) {
+ s->bs = *s->pbuf++;
+ }
+ s->bbuf |= (*s->pbuf++) << s->bbits;
+ s->bbits += 8;
+ s->bs--;
+ }
+ c = s->bbuf;
+ s->bbuf >>= s->cursize;
+ } else { // TIFF
+ while (s->bbits < s->cursize) {
+ s->bbuf = (s->bbuf << 8) | (*s->pbuf++);
+ s->bbits += 8;
+ }
+ c = s->bbuf >> (s->bbits - s->cursize);
+ }
+ s->bbits -= s->cursize;
+ return c & s->curmask;
+}
+
+uint8_t* ff_lzw_cur_ptr(LZWState *p)
+{
+ return ((struct LZWState*)p)->pbuf;
+}
+
+void ff_lzw_decode_tail(LZWState *p)
+{
+ struct LZWState *s = (struct LZWState *)p;
+
+ if(s->mode == FF_LZW_GIF) {
+ while(s->pbuf < s->ebuf && s->bs>0){
+ s->pbuf += s->bs;
+ s->bs = *s->pbuf++;
+ }
+ }else
+ s->pbuf= s->ebuf;
+}
+
+void ff_lzw_decode_open(LZWState **p)
+{
+ *p = av_mallocz(sizeof(struct LZWState));
+}
+
+void ff_lzw_decode_close(LZWState **p)
+{
+ av_freep(p);
+}
+
+/**
+ * Initialize LZW decoder
+ * @param s LZW context
+ * @param csize initial code size in bits
+ * @param buf input data
+ * @param buf_size input data size
+ * @param mode decoder working mode - either GIF or TIFF
+ */
+int ff_lzw_decode_init(LZWState *p, int csize, uint8_t *buf, int buf_size, int mode)
+{
+ struct LZWState *s = (struct LZWState *)p;
+
+ if(csize < 1 || csize > LZW_MAXBITS)
+ return -1;
+ /* read buffer */
+ s->pbuf = buf;
+ s->ebuf = s->pbuf + buf_size;
+ s->bbuf = 0;
+ s->bbits = 0;
+ s->bs = 0;
+
+ /* decoder */
+ s->codesize = csize;
+ s->cursize = s->codesize + 1;
+ s->curmask = mask[s->cursize];
+ s->top_slot = 1 << s->cursize;
+ s->clear_code = 1 << s->codesize;
+ s->end_code = s->clear_code + 1;
+ s->slot = s->newcodes = s->clear_code + 2;
+ s->oc = s->fc = -1;
+ s->sp = s->stack;
+
+ s->mode = mode;
+ s->extra_slot = s->mode == FF_LZW_TIFF;
+ return 0;
+}
+
+/**
+ * Decode given number of bytes
+ * NOTE: the algorithm here is inspired from the LZW GIF decoder
+ * written by Steven A. Bennett in 1987.
+ *
+ * @param s LZW context
+ * @param buf output buffer
+ * @param len number of bytes to decode
+ * @return number of bytes decoded
+ */
+int ff_lzw_decode(LZWState *p, uint8_t *buf, int len){
+ int l, c, code, oc, fc;
+ uint8_t *sp;
+ struct LZWState *s = (struct LZWState *)p;
+
+ if (s->end_code < 0)
+ return 0;
+
+ l = len;
+ sp = s->sp;
+ oc = s->oc;
+ fc = s->fc;
+
+ for (;;) {
+ while (sp > s->stack) {
+ *buf++ = *(--sp);
+ if ((--l) == 0)
+ goto the_end;
+ }
+ c = lzw_get_code(s);
+ if (c == s->end_code) {
+ break;
+ } else if (c == s->clear_code) {
+ s->cursize = s->codesize + 1;
+ s->curmask = mask[s->cursize];
+ s->slot = s->newcodes;
+ s->top_slot = 1 << s->cursize;
+ fc= oc= -1;
+ } else {
+ code = c;
+ if (code == s->slot && fc>=0) {
+ *sp++ = fc;
+ code = oc;
+ }else if(code >= s->slot)
+ break;
+ while (code >= s->newcodes) {
+ *sp++ = s->suffix[code];
+ code = s->prefix[code];
+ }
+ *sp++ = code;
+ if (s->slot < s->top_slot && oc>=0) {
+ s->suffix[s->slot] = code;
+ s->prefix[s->slot++] = oc;
+ }
+ fc = code;
+ oc = c;
+ if (s->slot >= s->top_slot - s->extra_slot) {
+ if (s->cursize < LZW_MAXBITS) {
+ s->top_slot <<= 1;
+ s->curmask = mask[++s->cursize];
+ }
+ }
+ }
+ }
+ s->end_code = -1;
+ the_end:
+ s->sp = sp;
+ s->oc = oc;
+ s->fc = fc;
+ return len - l;
+}
diff --git a/contrib/ffmpeg/libavcodec/lzw.h b/contrib/ffmpeg/libavcodec/lzw.h
new file mode 100644
index 000000000..60f115caf
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/lzw.h
@@ -0,0 +1,49 @@
+/*
+ * LZW decoder
+ * Copyright (c) 2003 Fabrice Bellard.
+ * Copyright (c) 2006 Konstantin Shishkov.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file lzw.h
+ * @brief LZW decoding routines
+ * @author Fabrice Bellard
+ * Modified for use in TIFF by Konstantin Shishkov
+ */
+
+#ifndef LZW_H
+#define LZW_H
+
+enum FF_LZW_MODES{
+ FF_LZW_GIF,
+ FF_LZW_TIFF
+};
+
+/* clients should not know what LZWState is */
+typedef void LZWState;
+
+/* first two functions de/allocate memory for LZWState */
+void ff_lzw_decode_open(LZWState **p);
+void ff_lzw_decode_close(LZWState **p);
+int ff_lzw_decode_init(LZWState *s, int csize, uint8_t *buf, int buf_size, int mode);
+int ff_lzw_decode(LZWState *s, uint8_t *buf, int len);
+uint8_t* ff_lzw_cur_ptr(LZWState *lzw);
+void ff_lzw_decode_tail(LZWState *lzw);
+
+#endif
diff --git a/src/libffmpeg/libavcodec/mace.c b/contrib/ffmpeg/libavcodec/mace.c
index 95839379a..95839379a 100644
--- a/src/libffmpeg/libavcodec/mace.c
+++ b/contrib/ffmpeg/libavcodec/mace.c
diff --git a/src/libffmpeg/libavcodec/mathops.h b/contrib/ffmpeg/libavcodec/mathops.h
index c6ec70597..c6ec70597 100644
--- a/src/libffmpeg/libavcodec/mathops.h
+++ b/contrib/ffmpeg/libavcodec/mathops.h
diff --git a/src/libffmpeg/libavcodec/mdct.c b/contrib/ffmpeg/libavcodec/mdct.c
index de3275289..de3275289 100644
--- a/src/libffmpeg/libavcodec/mdct.c
+++ b/contrib/ffmpeg/libavcodec/mdct.c
diff --git a/src/libffmpeg/libavcodec/mdec.c b/contrib/ffmpeg/libavcodec/mdec.c
index ee43b2777..ee43b2777 100644
--- a/src/libffmpeg/libavcodec/mdec.c
+++ b/contrib/ffmpeg/libavcodec/mdec.c
diff --git a/contrib/ffmpeg/libavcodec/mjpeg.c b/contrib/ffmpeg/libavcodec/mjpeg.c
new file mode 100644
index 000000000..e3583e54e
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/mjpeg.c
@@ -0,0 +1,2651 @@
+/*
+ * MJPEG encoder and decoder
+ * Copyright (c) 2000, 2001 Fabrice Bellard.
+ * Copyright (c) 2003 Alex Beregszaszi
+ * Copyright (c) 2003-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
+ *
+ * Support for external huffman table, various fixes (AVID workaround),
+ * aspecting, new decode_frame mechanism and apple mjpeg-b support
+ * by Alex Beregszaszi <alex@naxine.org>
+ */
+
+/**
+ * @file mjpeg.c
+ * MJPEG encoder and decoder.
+ */
+
+//#define DEBUG
+#include <assert.h>
+
+#include "avcodec.h"
+#include "dsputil.h"
+#include "mpegvideo.h"
+#include "bytestream.h"
+
+/* use two quantizer tables (one for luminance and one for chrominance) */
+/* not yet working */
+#undef TWOMATRIXES
+
+typedef struct MJpegContext {
+ uint8_t huff_size_dc_luminance[12]; //FIXME use array [3] instead of lumi / chrom, for easier addressing
+ uint16_t huff_code_dc_luminance[12];
+ uint8_t huff_size_dc_chrominance[12];
+ uint16_t huff_code_dc_chrominance[12];
+
+ uint8_t huff_size_ac_luminance[256];
+ uint16_t huff_code_ac_luminance[256];
+ uint8_t huff_size_ac_chrominance[256];
+ uint16_t huff_code_ac_chrominance[256];
+} MJpegContext;
+
+/* JPEG marker codes */
+typedef enum {
+ /* start of frame */
+ SOF0 = 0xc0, /* baseline */
+ SOF1 = 0xc1, /* extended sequential, huffman */
+ SOF2 = 0xc2, /* progressive, huffman */
+ SOF3 = 0xc3, /* lossless, huffman */
+
+ SOF5 = 0xc5, /* differential sequential, huffman */
+ SOF6 = 0xc6, /* differential progressive, huffman */
+ SOF7 = 0xc7, /* differential lossless, huffman */
+ JPG = 0xc8, /* reserved for JPEG extension */
+ SOF9 = 0xc9, /* extended sequential, arithmetic */
+ SOF10 = 0xca, /* progressive, arithmetic */
+ SOF11 = 0xcb, /* lossless, arithmetic */
+
+ SOF13 = 0xcd, /* differential sequential, arithmetic */
+ SOF14 = 0xce, /* differential progressive, arithmetic */
+ SOF15 = 0xcf, /* differential lossless, arithmetic */
+
+ DHT = 0xc4, /* define huffman tables */
+
+ DAC = 0xcc, /* define arithmetic-coding conditioning */
+
+ /* restart with modulo 8 count "m" */
+ RST0 = 0xd0,
+ RST1 = 0xd1,
+ RST2 = 0xd2,
+ RST3 = 0xd3,
+ RST4 = 0xd4,
+ RST5 = 0xd5,
+ RST6 = 0xd6,
+ RST7 = 0xd7,
+
+ SOI = 0xd8, /* start of image */
+ EOI = 0xd9, /* end of image */
+ SOS = 0xda, /* start of scan */
+ DQT = 0xdb, /* define quantization tables */
+ DNL = 0xdc, /* define number of lines */
+ DRI = 0xdd, /* define restart interval */
+ DHP = 0xde, /* define hierarchical progression */
+ EXP = 0xdf, /* expand reference components */
+
+ APP0 = 0xe0,
+ APP1 = 0xe1,
+ APP2 = 0xe2,
+ APP3 = 0xe3,
+ APP4 = 0xe4,
+ APP5 = 0xe5,
+ APP6 = 0xe6,
+ APP7 = 0xe7,
+ APP8 = 0xe8,
+ APP9 = 0xe9,
+ APP10 = 0xea,
+ APP11 = 0xeb,
+ APP12 = 0xec,
+ APP13 = 0xed,
+ APP14 = 0xee,
+ APP15 = 0xef,
+
+ JPG0 = 0xf0,
+ JPG1 = 0xf1,
+ JPG2 = 0xf2,
+ JPG3 = 0xf3,
+ JPG4 = 0xf4,
+ JPG5 = 0xf5,
+ JPG6 = 0xf6,
+ SOF48 = 0xf7, ///< JPEG-LS
+ LSE = 0xf8, ///< JPEG-LS extension parameters
+ JPG9 = 0xf9,
+ JPG10 = 0xfa,
+ JPG11 = 0xfb,
+ JPG12 = 0xfc,
+ JPG13 = 0xfd,
+
+ COM = 0xfe, /* comment */
+
+ TEM = 0x01, /* temporary private use for arithmetic coding */
+
+ /* 0x02 -> 0xbf reserved */
+} JPEG_MARKER;
+
+#if 0
+/* These are the sample quantization tables given in JPEG spec section K.1.
+ * The spec says that the values given produce "good" quality, and
+ * when divided by 2, "very good" quality.
+ */
+static const unsigned char std_luminance_quant_tbl[64] = {
+ 16, 11, 10, 16, 24, 40, 51, 61,
+ 12, 12, 14, 19, 26, 58, 60, 55,
+ 14, 13, 16, 24, 40, 57, 69, 56,
+ 14, 17, 22, 29, 51, 87, 80, 62,
+ 18, 22, 37, 56, 68, 109, 103, 77,
+ 24, 35, 55, 64, 81, 104, 113, 92,
+ 49, 64, 78, 87, 103, 121, 120, 101,
+ 72, 92, 95, 98, 112, 100, 103, 99
+};
+static const unsigned char std_chrominance_quant_tbl[64] = {
+ 17, 18, 24, 47, 99, 99, 99, 99,
+ 18, 21, 26, 66, 99, 99, 99, 99,
+ 24, 26, 56, 99, 99, 99, 99, 99,
+ 47, 66, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99
+};
+#endif
+
+/* Set up the standard Huffman tables (cf. JPEG standard section K.3) */
+/* IMPORTANT: these are only valid for 8-bit data precision! */
+static const uint8_t bits_dc_luminance[17] =
+{ /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
+static const uint8_t val_dc_luminance[] =
+{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
+
+static const uint8_t bits_dc_chrominance[17] =
+{ /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
+static const uint8_t val_dc_chrominance[] =
+{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
+
+static const uint8_t bits_ac_luminance[17] =
+{ /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
+static const uint8_t val_ac_luminance[] =
+{ 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
+ 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
+ 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
+ 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
+ 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
+ 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
+ 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
+ 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
+ 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
+ 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
+ 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
+ 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
+ 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
+ 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
+ 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
+ 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
+ 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
+ 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
+ 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
+ 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
+ 0xf9, 0xfa
+};
+
+static const uint8_t bits_ac_chrominance[17] =
+{ /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
+
+static const uint8_t val_ac_chrominance[] =
+{ 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
+ 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
+ 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
+ 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
+ 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
+ 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
+ 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
+ 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
+ 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
+ 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
+ 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
+ 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
+ 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
+ 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
+ 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
+ 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
+ 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
+ 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
+ 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
+ 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
+ 0xf9, 0xfa
+};
+
+/* isn't this function nicer than the one in the libjpeg ? */
+static void build_huffman_codes(uint8_t *huff_size, uint16_t *huff_code,
+ const uint8_t *bits_table, const uint8_t *val_table)
+{
+ int i, j, k,nb, code, sym;
+
+ code = 0;
+ k = 0;
+ for(i=1;i<=16;i++) {
+ nb = bits_table[i];
+ for(j=0;j<nb;j++) {
+ sym = val_table[k++];
+ huff_size[sym] = i;
+ huff_code[sym] = code;
+ code++;
+ }
+ code <<= 1;
+ }
+}
+
+#ifdef CONFIG_ENCODERS
+int mjpeg_init(MpegEncContext *s)
+{
+ MJpegContext *m;
+
+ m = av_malloc(sizeof(MJpegContext));
+ if (!m)
+ return -1;
+
+ s->min_qcoeff=-1023;
+ s->max_qcoeff= 1023;
+
+ /* build all the huffman tables */
+ build_huffman_codes(m->huff_size_dc_luminance,
+ m->huff_code_dc_luminance,
+ bits_dc_luminance,
+ val_dc_luminance);
+ build_huffman_codes(m->huff_size_dc_chrominance,
+ m->huff_code_dc_chrominance,
+ bits_dc_chrominance,
+ val_dc_chrominance);
+ build_huffman_codes(m->huff_size_ac_luminance,
+ m->huff_code_ac_luminance,
+ bits_ac_luminance,
+ val_ac_luminance);
+ build_huffman_codes(m->huff_size_ac_chrominance,
+ m->huff_code_ac_chrominance,
+ bits_ac_chrominance,
+ val_ac_chrominance);
+
+ s->mjpeg_ctx = m;
+ return 0;
+}
+
+void mjpeg_close(MpegEncContext *s)
+{
+ av_free(s->mjpeg_ctx);
+}
+#endif //CONFIG_ENCODERS
+
+#define PREDICT(ret, topleft, top, left, predictor)\
+ switch(predictor){\
+ case 1: ret= left; break;\
+ case 2: ret= top; break;\
+ case 3: ret= topleft; break;\
+ case 4: ret= left + top - topleft; break;\
+ case 5: ret= left + ((top - topleft)>>1); break;\
+ case 6: ret= top + ((left - topleft)>>1); break;\
+ default:\
+ case 7: ret= (left + top)>>1; break;\
+ }
+
+#ifdef CONFIG_ENCODERS
+static inline void put_marker(PutBitContext *p, int code)
+{
+ put_bits(p, 8, 0xff);
+ put_bits(p, 8, code);
+}
+
+/* table_class: 0 = DC coef, 1 = AC coefs */
+static int put_huffman_table(MpegEncContext *s, int table_class, int table_id,
+ const uint8_t *bits_table, const uint8_t *value_table)
+{
+ PutBitContext *p = &s->pb;
+ int n, i;
+
+ put_bits(p, 4, table_class);
+ put_bits(p, 4, table_id);
+
+ n = 0;
+ for(i=1;i<=16;i++) {
+ n += bits_table[i];
+ put_bits(p, 8, bits_table[i]);
+ }
+
+ for(i=0;i<n;i++)
+ put_bits(p, 8, value_table[i]);
+
+ return n + 17;
+}
+
+static void jpeg_table_header(MpegEncContext *s)
+{
+ PutBitContext *p = &s->pb;
+ int i, j, size;
+ uint8_t *ptr;
+
+ /* quant matrixes */
+ put_marker(p, DQT);
+#ifdef TWOMATRIXES
+ put_bits(p, 16, 2 + 2 * (1 + 64));
+#else
+ put_bits(p, 16, 2 + 1 * (1 + 64));
+#endif
+ put_bits(p, 4, 0); /* 8 bit precision */
+ put_bits(p, 4, 0); /* table 0 */
+ for(i=0;i<64;i++) {
+ j = s->intra_scantable.permutated[i];
+ put_bits(p, 8, s->intra_matrix[j]);
+ }
+#ifdef TWOMATRIXES
+ put_bits(p, 4, 0); /* 8 bit precision */
+ put_bits(p, 4, 1); /* table 1 */
+ for(i=0;i<64;i++) {
+ j = s->intra_scantable.permutated[i];
+ put_bits(p, 8, s->chroma_intra_matrix[j]);
+ }
+#endif
+
+ /* huffman table */
+ put_marker(p, DHT);
+ flush_put_bits(p);
+ ptr = pbBufPtr(p);
+ put_bits(p, 16, 0); /* patched later */
+ size = 2;
+ size += put_huffman_table(s, 0, 0, bits_dc_luminance, val_dc_luminance);
+ size += put_huffman_table(s, 0, 1, bits_dc_chrominance, val_dc_chrominance);
+
+ size += put_huffman_table(s, 1, 0, bits_ac_luminance, val_ac_luminance);
+ size += put_huffman_table(s, 1, 1, bits_ac_chrominance, val_ac_chrominance);
+ ptr[0] = size >> 8;
+ ptr[1] = size;
+}
+
+static void jpeg_put_comments(MpegEncContext *s)
+{
+ PutBitContext *p = &s->pb;
+ int size;
+ uint8_t *ptr;
+
+ if (s->aspect_ratio_info /* && !lossless */)
+ {
+ /* JFIF header */
+ put_marker(p, APP0);
+ put_bits(p, 16, 16);
+ ff_put_string(p, "JFIF", 1); /* this puts the trailing zero-byte too */
+ put_bits(p, 16, 0x0201); /* v 1.02 */
+ put_bits(p, 8, 0); /* units type: 0 - aspect ratio */
+ put_bits(p, 16, s->avctx->sample_aspect_ratio.num);
+ put_bits(p, 16, s->avctx->sample_aspect_ratio.den);
+ put_bits(p, 8, 0); /* thumbnail width */
+ put_bits(p, 8, 0); /* thumbnail height */
+ }
+
+ /* comment */
+ if(!(s->flags & CODEC_FLAG_BITEXACT)){
+ put_marker(p, COM);
+ flush_put_bits(p);
+ ptr = pbBufPtr(p);
+ put_bits(p, 16, 0); /* patched later */
+ ff_put_string(p, LIBAVCODEC_IDENT, 1);
+ size = strlen(LIBAVCODEC_IDENT)+3;
+ ptr[0] = size >> 8;
+ ptr[1] = size;
+ }
+
+ if( s->avctx->pix_fmt == PIX_FMT_YUV420P
+ ||s->avctx->pix_fmt == PIX_FMT_YUV422P
+ ||s->avctx->pix_fmt == PIX_FMT_YUV444P){
+ put_marker(p, COM);
+ flush_put_bits(p);
+ ptr = pbBufPtr(p);
+ put_bits(p, 16, 0); /* patched later */
+ ff_put_string(p, "CS=ITU601", 1);
+ size = strlen("CS=ITU601")+3;
+ ptr[0] = size >> 8;
+ ptr[1] = size;
+ }
+}
+
+void mjpeg_picture_header(MpegEncContext *s)
+{
+ const int lossless= s->avctx->codec_id != CODEC_ID_MJPEG;
+ const int ls = s->avctx->codec_id == CODEC_ID_JPEGLS;
+
+ assert(!(ls && s->mjpeg_write_tables));
+
+ put_marker(&s->pb, SOI);
+
+ if (!s->mjpeg_data_only_frames)
+ {
+ jpeg_put_comments(s);
+
+ if (s->mjpeg_write_tables) jpeg_table_header(s);
+
+ switch(s->avctx->codec_id){
+ case CODEC_ID_MJPEG: put_marker(&s->pb, SOF0 ); break;
+ case CODEC_ID_LJPEG: put_marker(&s->pb, SOF3 ); break;
+ case CODEC_ID_JPEGLS: put_marker(&s->pb, SOF48); break;
+ default: assert(0);
+ }
+
+ put_bits(&s->pb, 16, 17);
+ if(lossless && s->avctx->pix_fmt == PIX_FMT_RGB32)
+ put_bits(&s->pb, 8, 9); /* 9 bits/component RCT */
+ else
+ put_bits(&s->pb, 8, 8); /* 8 bits/component */
+ put_bits(&s->pb, 16, s->height);
+ put_bits(&s->pb, 16, s->width);
+ put_bits(&s->pb, 8, 3); /* 3 components */
+
+ /* Y component */
+ put_bits(&s->pb, 8, 1); /* component number */
+ put_bits(&s->pb, 4, s->mjpeg_hsample[0]); /* H factor */
+ put_bits(&s->pb, 4, s->mjpeg_vsample[0]); /* V factor */
+ put_bits(&s->pb, 8, 0); /* select matrix */
+
+ /* Cb component */
+ put_bits(&s->pb, 8, 2); /* component number */
+ put_bits(&s->pb, 4, s->mjpeg_hsample[1]); /* H factor */
+ put_bits(&s->pb, 4, s->mjpeg_vsample[1]); /* V factor */
+#ifdef TWOMATRIXES
+ put_bits(&s->pb, 8, lossless ? 0 : 1); /* select matrix */
+#else
+ put_bits(&s->pb, 8, 0); /* select matrix */
+#endif
+
+ /* Cr component */
+ put_bits(&s->pb, 8, 3); /* component number */
+ put_bits(&s->pb, 4, s->mjpeg_hsample[2]); /* H factor */
+ put_bits(&s->pb, 4, s->mjpeg_vsample[2]); /* V factor */
+#ifdef TWOMATRIXES
+ put_bits(&s->pb, 8, lossless ? 0 : 1); /* select matrix */
+#else
+ put_bits(&s->pb, 8, 0); /* select matrix */
+#endif
+ }
+
+ /* scan header */
+ put_marker(&s->pb, SOS);
+ put_bits(&s->pb, 16, 12); /* length */
+ put_bits(&s->pb, 8, 3); /* 3 components */
+
+ /* Y component */
+ put_bits(&s->pb, 8, 1); /* index */
+ put_bits(&s->pb, 4, 0); /* DC huffman table index */
+ put_bits(&s->pb, 4, 0); /* AC huffman table index */
+
+ /* Cb component */
+ put_bits(&s->pb, 8, 2); /* index */
+ put_bits(&s->pb, 4, 1); /* DC huffman table index */
+ put_bits(&s->pb, 4, lossless ? 0 : 1); /* AC huffman table index */
+
+ /* Cr component */
+ put_bits(&s->pb, 8, 3); /* index */
+ put_bits(&s->pb, 4, 1); /* DC huffman table index */
+ put_bits(&s->pb, 4, lossless ? 0 : 1); /* AC huffman table index */
+
+ put_bits(&s->pb, 8, (lossless && !ls) ? s->avctx->prediction_method+1 : 0); /* Ss (not used) */
+
+ switch(s->avctx->codec_id){
+ case CODEC_ID_MJPEG: put_bits(&s->pb, 8, 63); break; /* Se (not used) */
+ case CODEC_ID_LJPEG: put_bits(&s->pb, 8, 0); break; /* not used */
+ case CODEC_ID_JPEGLS: put_bits(&s->pb, 8, 1); break; /* ILV = line interleaved */
+ default: assert(0);
+ }
+
+ put_bits(&s->pb, 8, 0); /* Ah/Al (not used) */
+
+ //FIXME DC/AC entropy table selectors stuff in jpegls
+}
+
+static void escape_FF(MpegEncContext *s, int start)
+{
+ int size= put_bits_count(&s->pb) - start*8;
+ int i, ff_count;
+ uint8_t *buf= s->pb.buf + start;
+ int align= (-(size_t)(buf))&3;
+
+ assert((size&7) == 0);
+ size >>= 3;
+
+ ff_count=0;
+ for(i=0; i<size && i<align; i++){
+ if(buf[i]==0xFF) ff_count++;
+ }
+ for(; i<size-15; i+=16){
+ int acc, v;
+
+ v= *(uint32_t*)(&buf[i]);
+ acc= (((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010;
+ v= *(uint32_t*)(&buf[i+4]);
+ acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010;
+ v= *(uint32_t*)(&buf[i+8]);
+ acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010;
+ v= *(uint32_t*)(&buf[i+12]);
+ acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010;
+
+ acc>>=4;
+ acc+= (acc>>16);
+ acc+= (acc>>8);
+ ff_count+= acc&0xFF;
+ }
+ for(; i<size; i++){
+ if(buf[i]==0xFF) ff_count++;
+ }
+
+ if(ff_count==0) return;
+
+ /* skip put bits */
+ for(i=0; i<ff_count-3; i+=4)
+ put_bits(&s->pb, 32, 0);
+ put_bits(&s->pb, (ff_count-i)*8, 0);
+ flush_put_bits(&s->pb);
+
+ for(i=size-1; ff_count; i--){
+ int v= buf[i];
+
+ if(v==0xFF){
+//printf("%d %d\n", i, ff_count);
+ buf[i+ff_count]= 0;
+ ff_count--;
+ }
+
+ buf[i+ff_count]= v;
+ }
+}
+
+void ff_mjpeg_stuffing(PutBitContext * pbc)
+{
+ int length;
+ length= (-put_bits_count(pbc))&7;
+ if(length) put_bits(pbc, length, (1<<length)-1);
+}
+
+void mjpeg_picture_trailer(MpegEncContext *s)
+{
+ ff_mjpeg_stuffing(&s->pb);
+ flush_put_bits(&s->pb);
+
+ assert((s->header_bits&7)==0);
+
+ escape_FF(s, s->header_bits>>3);
+
+ put_marker(&s->pb, EOI);
+}
+
+static inline void mjpeg_encode_dc(MpegEncContext *s, int val,
+ uint8_t *huff_size, uint16_t *huff_code)
+{
+ int mant, nbits;
+
+ if (val == 0) {
+ put_bits(&s->pb, huff_size[0], huff_code[0]);
+ } else {
+ mant = val;
+ if (val < 0) {
+ val = -val;
+ mant--;
+ }
+
+ nbits= av_log2_16bit(val) + 1;
+
+ put_bits(&s->pb, huff_size[nbits], huff_code[nbits]);
+
+ put_bits(&s->pb, nbits, mant & ((1 << nbits) - 1));
+ }
+}
+
+static void encode_block(MpegEncContext *s, DCTELEM *block, int n)
+{
+ int mant, nbits, code, i, j;
+ int component, dc, run, last_index, val;
+ MJpegContext *m = s->mjpeg_ctx;
+ uint8_t *huff_size_ac;
+ uint16_t *huff_code_ac;
+
+ /* DC coef */
+ component = (n <= 3 ? 0 : (n&1) + 1);
+ dc = block[0]; /* overflow is impossible */
+ val = dc - s->last_dc[component];
+ if (n < 4) {
+ mjpeg_encode_dc(s, val, m->huff_size_dc_luminance, m->huff_code_dc_luminance);
+ huff_size_ac = m->huff_size_ac_luminance;
+ huff_code_ac = m->huff_code_ac_luminance;
+ } else {
+ mjpeg_encode_dc(s, val, m->huff_size_dc_chrominance, m->huff_code_dc_chrominance);
+ huff_size_ac = m->huff_size_ac_chrominance;
+ huff_code_ac = m->huff_code_ac_chrominance;
+ }
+ s->last_dc[component] = dc;
+
+ /* AC coefs */
+
+ run = 0;
+ last_index = s->block_last_index[n];
+ for(i=1;i<=last_index;i++) {
+ j = s->intra_scantable.permutated[i];
+ val = block[j];
+ if (val == 0) {
+ run++;
+ } else {
+ while (run >= 16) {
+ put_bits(&s->pb, huff_size_ac[0xf0], huff_code_ac[0xf0]);
+ run -= 16;
+ }
+ mant = val;
+ if (val < 0) {
+ val = -val;
+ mant--;
+ }
+
+ nbits= av_log2(val) + 1;
+ code = (run << 4) | nbits;
+
+ put_bits(&s->pb, huff_size_ac[code], huff_code_ac[code]);
+
+ put_bits(&s->pb, nbits, mant & ((1 << nbits) - 1));
+ run = 0;
+ }
+ }
+
+ /* output EOB only if not already 64 values */
+ if (last_index < 63 || run != 0)
+ put_bits(&s->pb, huff_size_ac[0], huff_code_ac[0]);
+}
+
+void mjpeg_encode_mb(MpegEncContext *s,
+ DCTELEM block[6][64])
+{
+ int i;
+ for(i=0;i<5;i++) {
+ encode_block(s, block[i], i);
+ }
+ if (s->chroma_format == CHROMA_420) {
+ encode_block(s, block[5], 5);
+ } else {
+ encode_block(s, block[6], 6);
+ encode_block(s, block[5], 5);
+ encode_block(s, block[7], 7);
+ }
+}
+
+static int encode_picture_lossless(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
+ MpegEncContext * const s = avctx->priv_data;
+ MJpegContext * const m = s->mjpeg_ctx;
+ AVFrame *pict = data;
+ const int width= s->width;
+ const int height= s->height;
+ AVFrame * const p= (AVFrame*)&s->current_picture;
+ const int predictor= avctx->prediction_method+1;
+
+ init_put_bits(&s->pb, buf, buf_size);
+
+ *p = *pict;
+ p->pict_type= FF_I_TYPE;
+ p->key_frame= 1;
+
+ mjpeg_picture_header(s);
+
+ s->header_bits= put_bits_count(&s->pb);
+
+ if(avctx->pix_fmt == PIX_FMT_RGB32){
+ int x, y, i;
+ const int linesize= p->linesize[0];
+ uint16_t (*buffer)[4]= (void *) s->rd_scratchpad;
+ int left[3], top[3], topleft[3];
+
+ for(i=0; i<3; i++){
+ buffer[0][i]= 1 << (9 - 1);
+ }
+
+ for(y = 0; y < height; y++) {
+ const int modified_predictor= y ? predictor : 1;
+ uint8_t *ptr = p->data[0] + (linesize * y);
+
+ if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < width*3*4){
+ av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
+ return -1;
+ }
+
+ for(i=0; i<3; i++){
+ top[i]= left[i]= topleft[i]= buffer[0][i];
+ }
+ for(x = 0; x < width; x++) {
+ buffer[x][1] = ptr[4*x+0] - ptr[4*x+1] + 0x100;
+ buffer[x][2] = ptr[4*x+2] - ptr[4*x+1] + 0x100;
+ buffer[x][0] = (ptr[4*x+0] + 2*ptr[4*x+1] + ptr[4*x+2])>>2;
+
+ for(i=0;i<3;i++) {
+ int pred, diff;
+
+ PREDICT(pred, topleft[i], top[i], left[i], modified_predictor);
+
+ topleft[i]= top[i];
+ top[i]= buffer[x+1][i];
+
+ left[i]= buffer[x][i];
+
+ diff= ((left[i] - pred + 0x100)&0x1FF) - 0x100;
+
+ if(i==0)
+ mjpeg_encode_dc(s, diff, m->huff_size_dc_luminance, m->huff_code_dc_luminance); //FIXME ugly
+ else
+ mjpeg_encode_dc(s, diff, m->huff_size_dc_chrominance, m->huff_code_dc_chrominance);
+ }
+ }
+ }
+ }else{
+ int mb_x, mb_y, i;
+ const int mb_width = (width + s->mjpeg_hsample[0] - 1) / s->mjpeg_hsample[0];
+ const int mb_height = (height + s->mjpeg_vsample[0] - 1) / s->mjpeg_vsample[0];
+
+ for(mb_y = 0; mb_y < mb_height; mb_y++) {
+ if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < mb_width * 4 * 3 * s->mjpeg_hsample[0] * s->mjpeg_vsample[0]){
+ av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
+ return -1;
+ }
+ for(mb_x = 0; mb_x < mb_width; mb_x++) {
+ if(mb_x==0 || mb_y==0){
+ for(i=0;i<3;i++) {
+ uint8_t *ptr;
+ int x, y, h, v, linesize;
+ h = s->mjpeg_hsample[i];
+ v = s->mjpeg_vsample[i];
+ linesize= p->linesize[i];
+
+ for(y=0; y<v; y++){
+ for(x=0; x<h; x++){
+ int pred;
+
+ ptr = p->data[i] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
+ if(y==0 && mb_y==0){
+ if(x==0 && mb_x==0){
+ pred= 128;
+ }else{
+ pred= ptr[-1];
+ }
+ }else{
+ if(x==0 && mb_x==0){
+ pred= ptr[-linesize];
+ }else{
+ PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);
+ }
+ }
+
+ if(i==0)
+ mjpeg_encode_dc(s, (int8_t)(*ptr - pred), m->huff_size_dc_luminance, m->huff_code_dc_luminance); //FIXME ugly
+ else
+ mjpeg_encode_dc(s, (int8_t)(*ptr - pred), m->huff_size_dc_chrominance, m->huff_code_dc_chrominance);
+ }
+ }
+ }
+ }else{
+ for(i=0;i<3;i++) {
+ uint8_t *ptr;
+ int x, y, h, v, linesize;
+ h = s->mjpeg_hsample[i];
+ v = s->mjpeg_vsample[i];
+ linesize= p->linesize[i];
+
+ for(y=0; y<v; y++){
+ for(x=0; x<h; x++){
+ int pred;
+
+ ptr = p->data[i] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
+//printf("%d %d %d %d %8X\n", mb_x, mb_y, x, y, ptr);
+ PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);
+
+ if(i==0)
+ mjpeg_encode_dc(s, (int8_t)(*ptr - pred), m->huff_size_dc_luminance, m->huff_code_dc_luminance); //FIXME ugly
+ else
+ mjpeg_encode_dc(s, (int8_t)(*ptr - pred), m->huff_size_dc_chrominance, m->huff_code_dc_chrominance);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ emms_c();
+
+ mjpeg_picture_trailer(s);
+ s->picture_number++;
+
+ flush_put_bits(&s->pb);
+ return pbBufPtr(&s->pb) - s->pb.buf;
+// return (put_bits_count(&f->pb)+7)/8;
+}
+
+#endif //CONFIG_ENCODERS
+
+/******************************************/
+/* decoding */
+
+#define MAX_COMPONENTS 4
+
+typedef struct MJpegDecodeContext {
+ AVCodecContext *avctx;
+ GetBitContext gb;
+ int mpeg_enc_ctx_allocated; /* true if decoding context allocated */
+
+ int start_code; /* current start code */
+ int buffer_size;
+ uint8_t *buffer;
+
+ int16_t quant_matrixes[4][64];
+ VLC vlcs[2][4];
+ int qscale[4]; ///< quantizer scale calculated from quant_matrixes
+
+ int org_height; /* size given at codec init */
+ int first_picture; /* true if decoding first picture */
+ int interlaced; /* true if interlaced */
+ int bottom_field; /* true if bottom field */
+ int lossless;
+ int ls;
+ int progressive;
+ int rgb;
+ int rct; /* standard rct */
+ int pegasus_rct; /* pegasus reversible colorspace transform */
+ int bits; /* bits per component */
+
+ int maxval;
+ int near; ///< near lossless bound (si 0 for lossless)
+ int t1,t2,t3;
+ int reset; ///< context halfing intervall ?rename
+
+ int width, height;
+ int mb_width, mb_height;
+ int nb_components;
+ int component_id[MAX_COMPONENTS];
+ int h_count[MAX_COMPONENTS]; /* horizontal and vertical count for each component */
+ int v_count[MAX_COMPONENTS];
+ int comp_index[MAX_COMPONENTS];
+ int dc_index[MAX_COMPONENTS];
+ int ac_index[MAX_COMPONENTS];
+ int nb_blocks[MAX_COMPONENTS];
+ int h_scount[MAX_COMPONENTS];
+ int v_scount[MAX_COMPONENTS];
+ int h_max, v_max; /* maximum h and v counts */
+ int quant_index[4]; /* quant table index for each component */
+ int last_dc[MAX_COMPONENTS]; /* last DEQUANTIZED dc (XXX: am I right to do that ?) */
+ AVFrame picture; /* picture structure */
+ int linesize[MAX_COMPONENTS]; ///< linesize << interlaced
+ int8_t *qscale_table;
+ DECLARE_ALIGNED_8(DCTELEM, block[64]);
+ ScanTable scantable;
+ void (*idct_put)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
+ void (*idct_add)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
+
+ int restart_interval;
+ int restart_count;
+
+ int buggy_avid;
+ int cs_itu601;
+ int interlace_polarity;
+
+ int mjpb_skiptosod;
+
+ int cur_scan; /* current scan, used by JPEG-LS */
+} MJpegDecodeContext;
+
+#include "jpeg_ls.c" //FIXME make jpeg-ls more independent
+
+static int mjpeg_decode_dht(MJpegDecodeContext *s);
+
+static int build_vlc(VLC *vlc, const uint8_t *bits_table, const uint8_t *val_table,
+ int nb_codes, int use_static, int is_ac)
+{
+ uint8_t huff_size[256+16];
+ uint16_t huff_code[256+16];
+
+ assert(nb_codes <= 256);
+
+ memset(huff_size, 0, sizeof(huff_size));
+ build_huffman_codes(huff_size, huff_code, bits_table, val_table);
+
+ if(is_ac){
+ memmove(huff_size+16, huff_size, sizeof(uint8_t)*nb_codes);
+ memmove(huff_code+16, huff_code, sizeof(uint16_t)*nb_codes);
+ memset(huff_size, 0, sizeof(uint8_t)*16);
+ memset(huff_code, 0, sizeof(uint16_t)*16);
+ nb_codes += 16;
+ }
+
+ return init_vlc(vlc, 9, nb_codes, huff_size, 1, 1, huff_code, 2, 2, use_static);
+}
+
+static int mjpeg_decode_init(AVCodecContext *avctx)
+{
+ MJpegDecodeContext *s = avctx->priv_data;
+ MpegEncContext s2;
+ memset(s, 0, sizeof(MJpegDecodeContext));
+
+ s->avctx = avctx;
+
+ /* ugly way to get the idct & scantable FIXME */
+ memset(&s2, 0, sizeof(MpegEncContext));
+ s2.avctx= avctx;
+// s2->out_format = FMT_MJPEG;
+ dsputil_init(&s2.dsp, avctx);
+ DCT_common_init(&s2);
+
+ s->scantable= s2.intra_scantable;
+ s->idct_put= s2.dsp.idct_put;
+ s->idct_add= s2.dsp.idct_add;
+
+ s->mpeg_enc_ctx_allocated = 0;
+ s->buffer_size = 0;
+ s->buffer = NULL;
+ s->start_code = -1;
+ s->first_picture = 1;
+ s->org_height = avctx->coded_height;
+
+ build_vlc(&s->vlcs[0][0], bits_dc_luminance, val_dc_luminance, 12, 0, 0);
+ build_vlc(&s->vlcs[0][1], bits_dc_chrominance, val_dc_chrominance, 12, 0, 0);
+ build_vlc(&s->vlcs[1][0], bits_ac_luminance, val_ac_luminance, 251, 0, 1);
+ build_vlc(&s->vlcs[1][1], bits_ac_chrominance, val_ac_chrominance, 251, 0, 1);
+
+ if (avctx->flags & CODEC_FLAG_EXTERN_HUFF)
+ {
+ av_log(avctx, AV_LOG_INFO, "mjpeg: using external huffman table\n");
+ init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size*8);
+ mjpeg_decode_dht(s);
+ /* should check for error - but dunno */
+ }
+ if (avctx->extradata_size > 9 &&
+ AV_RL32(avctx->extradata + 4) == MKTAG('f','i','e','l')) {
+ if (avctx->extradata[9] == 6) { /* quicktime icefloe 019 */
+ s->interlace_polarity = 1; /* bottom field first */
+ av_log(avctx, AV_LOG_DEBUG, "mjpeg bottom field first\n");
+ }
+ }
+
+ return 0;
+}
+
+
+/**
+ * finds the end of the current frame in the bitstream.
+ * @return the position of the first byte of the next frame, or -1
+ */
+static int find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size){
+ int vop_found, i;
+ uint16_t state;
+
+ vop_found= pc->frame_start_found;
+ state= pc->state;
+
+ i=0;
+ if(!vop_found){
+ for(i=0; i<buf_size; i++){
+ state= (state<<8) | buf[i];
+ if(state == 0xFFD8){
+ i++;
+ vop_found=1;
+ break;
+ }
+ }
+ }
+
+ if(vop_found){
+ /* EOF considered as end of frame */
+ if (buf_size == 0)
+ return 0;
+ for(; i<buf_size; i++){
+ state= (state<<8) | buf[i];
+ if(state == 0xFFD8){
+ pc->frame_start_found=0;
+ pc->state=0;
+ return i-1;
+ }
+ }
+ }
+ pc->frame_start_found= vop_found;
+ pc->state= state;
+ return END_NOT_FOUND;
+}
+
+static int jpeg_parse(AVCodecParserContext *s,
+ AVCodecContext *avctx,
+ uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size)
+{
+ ParseContext *pc = s->priv_data;
+ int next;
+
+ next= find_frame_end(pc, buf, buf_size);
+
+ if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
+ *poutbuf = NULL;
+ *poutbuf_size = 0;
+ return buf_size;
+ }
+
+ *poutbuf = (uint8_t *)buf;
+ *poutbuf_size = buf_size;
+ return next;
+}
+
+/* quantize tables */
+static int mjpeg_decode_dqt(MJpegDecodeContext *s)
+{
+ int len, index, i, j;
+
+ len = get_bits(&s->gb, 16) - 2;
+
+ while (len >= 65) {
+ /* only 8 bit precision handled */
+ if (get_bits(&s->gb, 4) != 0)
+ {
+ av_log(s->avctx, AV_LOG_ERROR, "dqt: 16bit precision\n");
+ return -1;
+ }
+ index = get_bits(&s->gb, 4);
+ if (index >= 4)
+ return -1;
+ av_log(s->avctx, AV_LOG_DEBUG, "index=%d\n", index);
+ /* read quant table */
+ for(i=0;i<64;i++) {
+ j = s->scantable.permutated[i];
+ s->quant_matrixes[index][j] = get_bits(&s->gb, 8);
+ }
+
+ //XXX FIXME finetune, and perhaps add dc too
+ s->qscale[index]= FFMAX(
+ s->quant_matrixes[index][s->scantable.permutated[1]],
+ s->quant_matrixes[index][s->scantable.permutated[8]]) >> 1;
+ av_log(s->avctx, AV_LOG_DEBUG, "qscale[%d]: %d\n", index, s->qscale[index]);
+ len -= 65;
+ }
+
+ return 0;
+}
+
+/* decode huffman tables and build VLC decoders */
+static int mjpeg_decode_dht(MJpegDecodeContext *s)
+{
+ int len, index, i, class, n, v, code_max;
+ uint8_t bits_table[17];
+ uint8_t val_table[256];
+
+ len = get_bits(&s->gb, 16) - 2;
+
+ while (len > 0) {
+ if (len < 17)
+ return -1;
+ class = get_bits(&s->gb, 4);
+ if (class >= 2)
+ return -1;
+ index = get_bits(&s->gb, 4);
+ if (index >= 4)
+ return -1;
+ n = 0;
+ for(i=1;i<=16;i++) {
+ bits_table[i] = get_bits(&s->gb, 8);
+ n += bits_table[i];
+ }
+ len -= 17;
+ if (len < n || n > 256)
+ return -1;
+
+ code_max = 0;
+ for(i=0;i<n;i++) {
+ v = get_bits(&s->gb, 8);
+ if (v > code_max)
+ code_max = v;
+ val_table[i] = v;
+ }
+ len -= n;
+
+ /* build VLC and flush previous vlc if present */
+ free_vlc(&s->vlcs[class][index]);
+ av_log(s->avctx, AV_LOG_DEBUG, "class=%d index=%d nb_codes=%d\n",
+ class, index, code_max + 1);
+ if(build_vlc(&s->vlcs[class][index], bits_table, val_table, code_max + 1, 0, class > 0) < 0){
+ return -1;
+ }
+ }
+ return 0;
+}
+
+static int mjpeg_decode_sof(MJpegDecodeContext *s)
+{
+ int len, nb_components, i, width, height, pix_fmt_id;
+
+ /* XXX: verify len field validity */
+ len = get_bits(&s->gb, 16);
+ s->bits= get_bits(&s->gb, 8);
+
+ if(s->pegasus_rct) s->bits=9;
+ if(s->bits==9 && !s->pegasus_rct) s->rct=1; //FIXME ugly
+
+ if (s->bits != 8 && !s->lossless){
+ av_log(s->avctx, AV_LOG_ERROR, "only 8 bits/component accepted\n");
+ return -1;
+ }
+
+ height = get_bits(&s->gb, 16);
+ width = get_bits(&s->gb, 16);
+
+ av_log(s->avctx, AV_LOG_DEBUG, "sof0: picture: %dx%d\n", width, height);
+ if(avcodec_check_dimensions(s->avctx, width, height))
+ return -1;
+
+ nb_components = get_bits(&s->gb, 8);
+ if (nb_components <= 0 ||
+ nb_components > MAX_COMPONENTS)
+ return -1;
+ if (s->ls && !(s->bits <= 8 || nb_components == 1)){
+ av_log(s->avctx, AV_LOG_ERROR, "only <= 8 bits/component or 16-bit gray accepted for JPEG-LS\n");
+ return -1;
+ }
+ s->nb_components = nb_components;
+ s->h_max = 1;
+ s->v_max = 1;
+ for(i=0;i<nb_components;i++) {
+ /* component id */
+ s->component_id[i] = get_bits(&s->gb, 8) - 1;
+ s->h_count[i] = get_bits(&s->gb, 4);
+ s->v_count[i] = get_bits(&s->gb, 4);
+ /* compute hmax and vmax (only used in interleaved case) */
+ if (s->h_count[i] > s->h_max)
+ s->h_max = s->h_count[i];
+ if (s->v_count[i] > s->v_max)
+ s->v_max = s->v_count[i];
+ s->quant_index[i] = get_bits(&s->gb, 8);
+ if (s->quant_index[i] >= 4)
+ return -1;
+ av_log(s->avctx, AV_LOG_DEBUG, "component %d %d:%d id: %d quant:%d\n", i, s->h_count[i],
+ s->v_count[i], s->component_id[i], s->quant_index[i]);
+ }
+
+ if(s->ls && (s->h_max > 1 || s->v_max > 1)) {
+ av_log(s->avctx, AV_LOG_ERROR, "Subsampling in JPEG-LS is not supported.\n");
+ return -1;
+ }
+
+ if(s->v_max==1 && s->h_max==1 && s->lossless==1) s->rgb=1;
+
+ /* if different size, realloc/alloc picture */
+ /* XXX: also check h_count and v_count */
+ if (width != s->width || height != s->height) {
+ av_freep(&s->qscale_table);
+
+ s->width = width;
+ s->height = height;
+
+ /* test interlaced mode */
+ if (s->first_picture &&
+ s->org_height != 0 &&
+ s->height < ((s->org_height * 3) / 4)) {
+ s->interlaced = 1;
+ s->bottom_field = s->interlace_polarity;
+ s->picture.interlaced_frame = 1;
+ s->picture.top_field_first = !s->interlace_polarity;
+ height *= 2;
+ }
+
+ avcodec_set_dimensions(s->avctx, width, height);
+
+ s->qscale_table= av_mallocz((s->width+15)/16);
+
+ s->first_picture = 0;
+ }
+
+ if(s->interlaced && (s->bottom_field == !s->interlace_polarity))
+ return 0;
+
+ /* XXX: not complete test ! */
+ pix_fmt_id = (s->h_count[0] << 20) | (s->v_count[0] << 16) |
+ (s->h_count[1] << 12) | (s->v_count[1] << 8) |
+ (s->h_count[2] << 4) | s->v_count[2];
+ av_log(s->avctx, AV_LOG_DEBUG, "pix fmt id %x\n", pix_fmt_id);
+ switch(pix_fmt_id){
+ case 0x222222:
+ case 0x111111:
+ if(s->rgb){
+ s->avctx->pix_fmt = PIX_FMT_RGB32;
+ }else if(s->nb_components==3)
+ s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV444P : PIX_FMT_YUVJ444P;
+ else
+ s->avctx->pix_fmt = PIX_FMT_GRAY8;
+ break;
+ case 0x211111:
+ case 0x221212:
+ s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV422P : PIX_FMT_YUVJ422P;
+ break;
+ default:
+ case 0x221111:
+ s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV420P : PIX_FMT_YUVJ420P;
+ break;
+ }
+ if(s->ls){
+ if(s->nb_components > 1)
+ s->avctx->pix_fmt = PIX_FMT_RGB24;
+ else if(s->bits <= 8)
+ s->avctx->pix_fmt = PIX_FMT_GRAY8;
+ else
+ s->avctx->pix_fmt = PIX_FMT_GRAY16;
+ }
+
+ if(s->picture.data[0])
+ s->avctx->release_buffer(s->avctx, &s->picture);
+
+ s->picture.reference= 0;
+ if(s->avctx->get_buffer(s->avctx, &s->picture) < 0){
+ av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ return -1;
+ }
+ s->picture.pict_type= I_TYPE;
+ s->picture.key_frame= 1;
+
+ for(i=0; i<3; i++){
+ s->linesize[i]= s->picture.linesize[i] << s->interlaced;
+ }
+
+// printf("%d %d %d %d %d %d\n", s->width, s->height, s->linesize[0], s->linesize[1], s->interlaced, s->avctx->height);
+
+ if (len != (8+(3*nb_components)))
+ {
+ av_log(s->avctx, AV_LOG_DEBUG, "decode_sof0: error, len(%d) mismatch\n", len);
+ }
+
+ /* totally blank picture as progressive JPEG will only add details to it */
+ if(s->progressive){
+ memset(s->picture.data[0], 0, s->picture.linesize[0] * s->height);
+ memset(s->picture.data[1], 0, s->picture.linesize[1] * s->height >> (s->v_max - s->v_count[1]));
+ memset(s->picture.data[2], 0, s->picture.linesize[2] * s->height >> (s->v_max - s->v_count[2]));
+ }
+ return 0;
+}
+
+static inline int mjpeg_decode_dc(MJpegDecodeContext *s, int dc_index)
+{
+ int code;
+ code = get_vlc2(&s->gb, s->vlcs[0][dc_index].table, 9, 2);
+ if (code < 0)
+ {
+ av_log(s->avctx, AV_LOG_WARNING, "mjpeg_decode_dc: bad vlc: %d:%d (%p)\n", 0, dc_index,
+ &s->vlcs[0][dc_index]);
+ return 0xffff;
+ }
+
+ if(code)
+ return get_xbits(&s->gb, code);
+ else
+ return 0;
+}
+
+/* decode block and dequantize */
+static int decode_block(MJpegDecodeContext *s, DCTELEM *block,
+ int component, int dc_index, int ac_index, int16_t *quant_matrix)
+{
+ int code, i, j, level, val;
+
+ /* DC coef */
+ val = mjpeg_decode_dc(s, dc_index);
+ if (val == 0xffff) {
+ av_log(s->avctx, AV_LOG_ERROR, "error dc\n");
+ return -1;
+ }
+ val = val * quant_matrix[0] + s->last_dc[component];
+ s->last_dc[component] = val;
+ block[0] = val;
+ /* AC coefs */
+ i = 0;
+ {OPEN_READER(re, &s->gb)
+ for(;;) {
+ UPDATE_CACHE(re, &s->gb);
+ GET_VLC(code, re, &s->gb, s->vlcs[1][ac_index].table, 9, 2)
+
+ /* EOB */
+ if (code == 0x10)
+ break;
+ i += ((unsigned)code) >> 4;
+ if(code != 0x100){
+ code &= 0xf;
+ if(code > MIN_CACHE_BITS - 16){
+ UPDATE_CACHE(re, &s->gb)
+ }
+ {
+ int cache=GET_CACHE(re,&s->gb);
+ int sign=(~cache)>>31;
+ level = (NEG_USR32(sign ^ cache,code) ^ sign) - sign;
+ }
+
+ LAST_SKIP_BITS(re, &s->gb, code)
+
+ if (i >= 63) {
+ if(i == 63){
+ j = s->scantable.permutated[63];
+ block[j] = level * quant_matrix[j];
+ break;
+ }
+ av_log(s->avctx, AV_LOG_ERROR, "error count: %d\n", i);
+ return -1;
+ }
+ j = s->scantable.permutated[i];
+ block[j] = level * quant_matrix[j];
+ }
+ }
+ CLOSE_READER(re, &s->gb)}
+
+ return 0;
+}
+
+/* decode block and dequantize - progressive JPEG version */
+static int decode_block_progressive(MJpegDecodeContext *s, DCTELEM *block,
+ int component, int dc_index, int ac_index, int16_t *quant_matrix,
+ int ss, int se, int Ah, int Al, int *EOBRUN)
+{
+ int code, i, j, level, val, run;
+
+ /* DC coef */
+ if(!ss){
+ val = mjpeg_decode_dc(s, dc_index);
+ if (val == 0xffff) {
+ av_log(s->avctx, AV_LOG_ERROR, "error dc\n");
+ return -1;
+ }
+ val = (val * quant_matrix[0] << Al) + s->last_dc[component];
+ }else
+ val = 0;
+ s->last_dc[component] = val;
+ block[0] = val;
+ if(!se) return 0;
+ /* AC coefs */
+ if(*EOBRUN){
+ (*EOBRUN)--;
+ return 0;
+ }
+ {OPEN_READER(re, &s->gb)
+ for(i=ss;;i++) {
+ UPDATE_CACHE(re, &s->gb);
+ GET_VLC(code, re, &s->gb, s->vlcs[1][ac_index].table, 9, 2)
+ /* Progressive JPEG use AC coeffs from zero and this decoder sets offset 16 by default */
+ code -= 16;
+ if(code & 0xF) {
+ i += ((unsigned) code) >> 4;
+ code &= 0xf;
+ if(code > MIN_CACHE_BITS - 16){
+ UPDATE_CACHE(re, &s->gb)
+ }
+ {
+ int cache=GET_CACHE(re,&s->gb);
+ int sign=(~cache)>>31;
+ level = (NEG_USR32(sign ^ cache,code) ^ sign) - sign;
+ }
+
+ LAST_SKIP_BITS(re, &s->gb, code)
+
+ if (i >= se) {
+ if(i == se){
+ j = s->scantable.permutated[se];
+ block[j] = level * quant_matrix[j] << Al;
+ break;
+ }
+ av_log(s->avctx, AV_LOG_ERROR, "error count: %d\n", i);
+ return -1;
+ }
+ j = s->scantable.permutated[i];
+ block[j] = level * quant_matrix[j] << Al;
+ }else{
+ run = ((unsigned) code) >> 4;
+ if(run == 0xF){// ZRL - skip 15 coefficients
+ i += 15;
+ }else{
+ val = run;
+ run = (1 << run);
+ UPDATE_CACHE(re, &s->gb);
+ run += (GET_CACHE(re, &s->gb) >> (32 - val)) & (run - 1);
+ if(val)
+ LAST_SKIP_BITS(re, &s->gb, val);
+ *EOBRUN = run - 1;
+ break;
+ }
+ }
+ }
+ CLOSE_READER(re, &s->gb)}
+
+ return 0;
+}
+
+static int ljpeg_decode_rgb_scan(MJpegDecodeContext *s, int predictor, int point_transform){
+ int i, mb_x, mb_y;
+ uint16_t buffer[32768][4];
+ int left[3], top[3], topleft[3];
+ const int linesize= s->linesize[0];
+ const int mask= (1<<s->bits)-1;
+
+ if((unsigned)s->mb_width > 32768) //dynamic alloc
+ return -1;
+
+ for(i=0; i<3; i++){
+ buffer[0][i]= 1 << (s->bits + point_transform - 1);
+ }
+ for(mb_y = 0; mb_y < s->mb_height; mb_y++) {
+ const int modified_predictor= mb_y ? predictor : 1;
+ uint8_t *ptr = s->picture.data[0] + (linesize * mb_y);
+
+ if (s->interlaced && s->bottom_field)
+ ptr += linesize >> 1;
+
+ for(i=0; i<3; i++){
+ top[i]= left[i]= topleft[i]= buffer[0][i];
+ }
+ for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
+ if (s->restart_interval && !s->restart_count)
+ s->restart_count = s->restart_interval;
+
+ for(i=0;i<3;i++) {
+ int pred;
+
+ topleft[i]= top[i];
+ top[i]= buffer[mb_x][i];
+
+ PREDICT(pred, topleft[i], top[i], left[i], modified_predictor);
+
+ left[i]=
+ buffer[mb_x][i]= mask & (pred + (mjpeg_decode_dc(s, s->dc_index[i]) << point_transform));
+ }
+
+ if (s->restart_interval && !--s->restart_count) {
+ align_get_bits(&s->gb);
+ skip_bits(&s->gb, 16); /* skip RSTn */
+ }
+ }
+
+ if(s->rct){
+ for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
+ ptr[4*mb_x+1] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2] - 0x200)>>2);
+ ptr[4*mb_x+0] = buffer[mb_x][1] + ptr[4*mb_x+1];
+ ptr[4*mb_x+2] = buffer[mb_x][2] + ptr[4*mb_x+1];
+ }
+ }else if(s->pegasus_rct){
+ for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
+ ptr[4*mb_x+1] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2])>>2);
+ ptr[4*mb_x+0] = buffer[mb_x][1] + ptr[4*mb_x+1];
+ ptr[4*mb_x+2] = buffer[mb_x][2] + ptr[4*mb_x+1];
+ }
+ }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+1] = buffer[mb_x][1];
+ ptr[4*mb_x+2] = buffer[mb_x][2];
+ }
+ }
+ }
+ return 0;
+}
+
+static int ljpeg_decode_yuv_scan(MJpegDecodeContext *s, int predictor, int point_transform){
+ int i, mb_x, mb_y;
+ const int nb_components=3;
+
+ for(mb_y = 0; mb_y < s->mb_height; mb_y++) {
+ for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
+ if (s->restart_interval && !s->restart_count)
+ s->restart_count = s->restart_interval;
+
+ if(mb_x==0 || mb_y==0 || s->interlaced){
+ for(i=0;i<nb_components;i++) {
+ uint8_t *ptr;
+ int n, h, v, x, y, c, j, linesize;
+ n = s->nb_blocks[i];
+ c = s->comp_index[i];
+ h = s->h_scount[i];
+ v = s->v_scount[i];
+ x = 0;
+ y = 0;
+ linesize= s->linesize[c];
+
+ for(j=0; j<n; j++) {
+ int pred;
+
+ ptr = s->picture.data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
+ if(y==0 && mb_y==0){
+ if(x==0 && mb_x==0){
+ pred= 128 << point_transform;
+ }else{
+ pred= ptr[-1];
+ }
+ }else{
+ if(x==0 && mb_x==0){
+ pred= ptr[-linesize];
+ }else{
+ PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);
+ }
+ }
+
+ if (s->interlaced && s->bottom_field)
+ ptr += linesize >> 1;
+ *ptr= pred + (mjpeg_decode_dc(s, s->dc_index[i]) << point_transform);
+
+ if (++x == h) {
+ x = 0;
+ y++;
+ }
+ }
+ }
+ }else{
+ for(i=0;i<nb_components;i++) {
+ uint8_t *ptr;
+ int n, h, v, x, y, c, j, linesize;
+ n = s->nb_blocks[i];
+ c = s->comp_index[i];
+ h = s->h_scount[i];
+ v = s->v_scount[i];
+ x = 0;
+ y = 0;
+ linesize= s->linesize[c];
+
+ for(j=0; j<n; j++) {
+ int pred;
+
+ ptr = s->picture.data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
+ PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);
+ *ptr= pred + (mjpeg_decode_dc(s, s->dc_index[i]) << point_transform);
+ if (++x == h) {
+ x = 0;
+ y++;
+ }
+ }
+ }
+ }
+ if (s->restart_interval && !--s->restart_count) {
+ align_get_bits(&s->gb);
+ skip_bits(&s->gb, 16); /* skip RSTn */
+ }
+ }
+ }
+ return 0;
+}
+
+static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int ss, int se, int Ah, int Al){
+ int i, mb_x, mb_y;
+ int EOBRUN = 0;
+
+ if(Ah) return 0; /* TODO decode refinement planes too */
+ for(mb_y = 0; mb_y < s->mb_height; mb_y++) {
+ for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
+ if (s->restart_interval && !s->restart_count)
+ s->restart_count = s->restart_interval;
+
+ for(i=0;i<nb_components;i++) {
+ uint8_t *ptr;
+ int n, h, v, x, y, c, j;
+ n = s->nb_blocks[i];
+ c = s->comp_index[i];
+ h = s->h_scount[i];
+ v = s->v_scount[i];
+ x = 0;
+ y = 0;
+ for(j=0;j<n;j++) {
+ memset(s->block, 0, sizeof(s->block));
+ if (!s->progressive && decode_block(s, s->block, i,
+ s->dc_index[i], s->ac_index[i],
+ s->quant_matrixes[ s->quant_index[c] ]) < 0) {
+ av_log(s->avctx, AV_LOG_ERROR, "error y=%d x=%d\n", mb_y, mb_x);
+ return -1;
+ }
+ if (s->progressive && decode_block_progressive(s, s->block, i,
+ s->dc_index[i], s->ac_index[i],
+ s->quant_matrixes[ s->quant_index[c] ], ss, se, Ah, Al, &EOBRUN) < 0) {
+ av_log(s->avctx, AV_LOG_ERROR, "error y=%d x=%d\n", mb_y, mb_x);
+ return -1;
+ }
+// av_log(s->avctx, AV_LOG_DEBUG, "mb: %d %d processed\n", mb_y, mb_x);
+ ptr = s->picture.data[c] +
+ (((s->linesize[c] * (v * mb_y + y) * 8) +
+ (h * mb_x + x) * 8) >> s->avctx->lowres);
+ if (s->interlaced && s->bottom_field)
+ ptr += s->linesize[c] >> 1;
+//av_log(NULL, AV_LOG_DEBUG, "%d %d %d %d %d %d %d %d \n", mb_x, mb_y, x, y, c, s->bottom_field, (v * mb_y + y) * 8, (h * mb_x + x) * 8);
+ if(!s->progressive)
+ s->idct_put(ptr, s->linesize[c], s->block);
+ else
+ s->idct_add(ptr, s->linesize[c], s->block);
+ if (++x == h) {
+ x = 0;
+ y++;
+ }
+ }
+ }
+ /* (< 1350) buggy workaround for Spectralfan.mov, should be fixed */
+ if (s->restart_interval && (s->restart_interval < 1350) &&
+ !--s->restart_count) {
+ align_get_bits(&s->gb);
+ skip_bits(&s->gb, 16); /* skip RSTn */
+ for (i=0; i<nb_components; i++) /* reset dc */
+ s->last_dc[i] = 1024;
+ }
+ }
+ }
+ return 0;
+}
+
+static int mjpeg_decode_sos(MJpegDecodeContext *s)
+{
+ int len, nb_components, i, h, v, predictor, point_transform;
+ int vmax, hmax, index, id;
+ const int block_size= s->lossless ? 1 : 8;
+ int ilv, prev_shift;
+
+ /* XXX: verify len field validity */
+ len = get_bits(&s->gb, 16);
+ nb_components = get_bits(&s->gb, 8);
+ if (len != 6+2*nb_components)
+ {
+ av_log(s->avctx, AV_LOG_ERROR, "decode_sos: invalid len (%d)\n", len);
+ return -1;
+ }
+ vmax = 0;
+ hmax = 0;
+ for(i=0;i<nb_components;i++) {
+ id = get_bits(&s->gb, 8) - 1;
+ av_log(s->avctx, AV_LOG_DEBUG, "component: %d\n", id);
+ /* find component index */
+ for(index=0;index<s->nb_components;index++)
+ if (id == s->component_id[index])
+ break;
+ if (index == s->nb_components)
+ {
+ av_log(s->avctx, AV_LOG_ERROR, "decode_sos: index(%d) out of components\n", index);
+ return -1;
+ }
+
+ s->comp_index[i] = index;
+
+ s->nb_blocks[i] = s->h_count[index] * s->v_count[index];
+ s->h_scount[i] = s->h_count[index];
+ s->v_scount[i] = s->v_count[index];
+
+ s->dc_index[i] = get_bits(&s->gb, 4);
+ s->ac_index[i] = get_bits(&s->gb, 4);
+
+ if (s->dc_index[i] < 0 || s->ac_index[i] < 0 ||
+ s->dc_index[i] >= 4 || s->ac_index[i] >= 4)
+ goto out_of_range;
+#if 0 //buggy
+ switch(s->start_code)
+ {
+ case SOF0:
+ if (dc_index[i] > 1 || ac_index[i] > 1)
+ goto out_of_range;
+ break;
+ case SOF1:
+ case SOF2:
+ if (dc_index[i] > 3 || ac_index[i] > 3)
+ goto out_of_range;
+ break;
+ case SOF3:
+ if (dc_index[i] > 3 || ac_index[i] != 0)
+ goto out_of_range;
+ break;
+ }
+#endif
+ }
+
+ predictor= get_bits(&s->gb, 8); /* JPEG Ss / lossless JPEG predictor /JPEG-LS NEAR */
+ ilv= get_bits(&s->gb, 8); /* JPEG Se / JPEG-LS ILV */
+ prev_shift = get_bits(&s->gb, 4); /* Ah */
+ point_transform= get_bits(&s->gb, 4); /* Al */
+
+ for(i=0;i<nb_components;i++)
+ s->last_dc[i] = 1024;
+
+ if (nb_components > 1) {
+ /* interleaved stream */
+ s->mb_width = (s->width + s->h_max * block_size - 1) / (s->h_max * block_size);
+ s->mb_height = (s->height + s->v_max * block_size - 1) / (s->v_max * block_size);
+ } else if(!s->ls) { /* skip this for JPEG-LS */
+ h = s->h_max / s->h_scount[0];
+ v = s->v_max / s->v_scount[0];
+ s->mb_width = (s->width + h * block_size - 1) / (h * block_size);
+ s->mb_height = (s->height + v * block_size - 1) / (v * block_size);
+ s->nb_blocks[0] = 1;
+ s->h_scount[0] = 1;
+ s->v_scount[0] = 1;
+ }
+
+ 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" : "",
+ predictor, point_transform, ilv, s->bits,
+ s->pegasus_rct ? "PRCT" : (s->rct ? "RCT" : ""));
+
+
+ /* mjpeg-b can have padding bytes between sos and image data, skip them */
+ for (i = s->mjpb_skiptosod; i > 0; i--)
+ skip_bits(&s->gb, 8);
+
+ if(s->lossless){
+ if(s->ls){
+// for(){
+// reset_ls_coding_parameters(s, 0);
+
+ ls_decode_picture(s, predictor, point_transform, ilv);
+ }else{
+ if(s->rgb){
+ if(ljpeg_decode_rgb_scan(s, predictor, point_transform) < 0)
+ return -1;
+ }else{
+ if(ljpeg_decode_yuv_scan(s, predictor, point_transform) < 0)
+ return -1;
+ }
+ }
+ }else{
+ if(mjpeg_decode_scan(s, nb_components, predictor, ilv, prev_shift, point_transform) < 0)
+ return -1;
+ }
+ emms_c();
+ return 0;
+ out_of_range:
+ av_log(s->avctx, AV_LOG_ERROR, "decode_sos: ac/dc index out of range\n");
+ return -1;
+}
+
+static int mjpeg_decode_dri(MJpegDecodeContext *s)
+{
+ if (get_bits(&s->gb, 16) != 4)
+ return -1;
+ s->restart_interval = get_bits(&s->gb, 16);
+ s->restart_count = 0;
+ av_log(s->avctx, AV_LOG_DEBUG, "restart interval: %d\n", s->restart_interval);
+
+ return 0;
+}
+
+static int mjpeg_decode_app(MJpegDecodeContext *s)
+{
+ int len, id;
+
+ len = get_bits(&s->gb, 16);
+ if (len < 5)
+ return -1;
+ if(8*len + get_bits_count(&s->gb) > s->gb.size_in_bits)
+ return -1;
+
+ id = (get_bits(&s->gb, 16) << 16) | get_bits(&s->gb, 16);
+ id = be2me_32(id);
+ len -= 6;
+
+ if(s->avctx->debug & FF_DEBUG_STARTCODE){
+ av_log(s->avctx, AV_LOG_DEBUG, "APPx %8X\n", id);
+ }
+
+ /* buggy AVID, it puts EOI only at every 10th frame */
+ /* also this fourcc is used by non-avid files too, it holds some
+ informations, but it's always present in AVID creates files */
+ if (id == ff_get_fourcc("AVI1"))
+ {
+ /* structure:
+ 4bytes AVI1
+ 1bytes polarity
+ 1bytes always zero
+ 4bytes field_size
+ 4bytes field_size_less_padding
+ */
+ s->buggy_avid = 1;
+// if (s->first_picture)
+// printf("mjpeg: workarounding buggy AVID\n");
+ s->interlace_polarity = get_bits(&s->gb, 8);
+#if 0
+ skip_bits(&s->gb, 8);
+ skip_bits(&s->gb, 32);
+ skip_bits(&s->gb, 32);
+ len -= 10;
+#endif
+// if (s->interlace_polarity)
+// printf("mjpeg: interlace polarity: %d\n", s->interlace_polarity);
+ goto out;
+ }
+
+// len -= 2;
+
+ if (id == ff_get_fourcc("JFIF"))
+ {
+ int t_w, t_h, v1, v2;
+ skip_bits(&s->gb, 8); /* the trailing zero-byte */
+ v1= get_bits(&s->gb, 8);
+ v2= get_bits(&s->gb, 8);
+ skip_bits(&s->gb, 8);
+
+ s->avctx->sample_aspect_ratio.num= get_bits(&s->gb, 16);
+ s->avctx->sample_aspect_ratio.den= get_bits(&s->gb, 16);
+
+ if (s->avctx->debug & FF_DEBUG_PICT_INFO)
+ av_log(s->avctx, AV_LOG_INFO, "mjpeg: JFIF header found (version: %x.%x) SAR=%d/%d\n",
+ v1, v2,
+ s->avctx->sample_aspect_ratio.num,
+ s->avctx->sample_aspect_ratio.den
+ );
+
+ t_w = get_bits(&s->gb, 8);
+ t_h = get_bits(&s->gb, 8);
+ if (t_w && t_h)
+ {
+ /* skip thumbnail */
+ if (len-10-(t_w*t_h*3) > 0)
+ len -= t_w*t_h*3;
+ }
+ len -= 10;
+ goto out;
+ }
+
+ if (id == ff_get_fourcc("Adob") && (get_bits(&s->gb, 8) == 'e'))
+ {
+ if (s->avctx->debug & FF_DEBUG_PICT_INFO)
+ av_log(s->avctx, AV_LOG_INFO, "mjpeg: Adobe header found\n");
+ skip_bits(&s->gb, 16); /* version */
+ skip_bits(&s->gb, 16); /* flags0 */
+ skip_bits(&s->gb, 16); /* flags1 */
+ skip_bits(&s->gb, 8); /* transform */
+ len -= 7;
+ goto out;
+ }
+
+ if (id == ff_get_fourcc("LJIF")){
+ if (s->avctx->debug & FF_DEBUG_PICT_INFO)
+ av_log(s->avctx, AV_LOG_INFO, "Pegasus lossless jpeg header found\n");
+ skip_bits(&s->gb, 16); /* version ? */
+ skip_bits(&s->gb, 16); /* unknwon always 0? */
+ skip_bits(&s->gb, 16); /* unknwon always 0? */
+ skip_bits(&s->gb, 16); /* unknwon always 0? */
+ switch( get_bits(&s->gb, 8)){
+ case 1:
+ s->rgb= 1;
+ s->pegasus_rct=0;
+ break;
+ case 2:
+ s->rgb= 1;
+ s->pegasus_rct=1;
+ break;
+ default:
+ av_log(s->avctx, AV_LOG_ERROR, "unknown colorspace\n");
+ }
+ len -= 9;
+ goto out;
+ }
+
+ /* Apple MJPEG-A */
+ if ((s->start_code == APP1) && (len > (0x28 - 8)))
+ {
+ id = (get_bits(&s->gb, 16) << 16) | get_bits(&s->gb, 16);
+ id = be2me_32(id);
+ len -= 4;
+ if (id == ff_get_fourcc("mjpg")) /* Apple MJPEG-A */
+ {
+#if 0
+ skip_bits(&s->gb, 32); /* field size */
+ skip_bits(&s->gb, 32); /* pad field size */
+ skip_bits(&s->gb, 32); /* next off */
+ skip_bits(&s->gb, 32); /* quant off */
+ skip_bits(&s->gb, 32); /* huff off */
+ skip_bits(&s->gb, 32); /* image off */
+ skip_bits(&s->gb, 32); /* scan off */
+ skip_bits(&s->gb, 32); /* data off */
+#endif
+ if (s->avctx->debug & FF_DEBUG_PICT_INFO)
+ av_log(s->avctx, AV_LOG_INFO, "mjpeg: Apple MJPEG-A header found\n");
+ }
+ }
+
+out:
+ /* slow but needed for extreme adobe jpegs */
+ if (len < 0)
+ av_log(s->avctx, AV_LOG_ERROR, "mjpeg: error, decode_app parser read over the end\n");
+ while(--len > 0)
+ skip_bits(&s->gb, 8);
+
+ return 0;
+}
+
+static int mjpeg_decode_com(MJpegDecodeContext *s)
+{
+ int len = get_bits(&s->gb, 16);
+ if (len >= 2 && 8*len - 16 + get_bits_count(&s->gb) <= s->gb.size_in_bits) {
+ char *cbuf = av_malloc(len - 1);
+ if (cbuf) {
+ int i;
+ for (i = 0; i < len - 2; i++)
+ cbuf[i] = get_bits(&s->gb, 8);
+ if (i > 0 && cbuf[i-1] == '\n')
+ cbuf[i-1] = 0;
+ else
+ cbuf[i] = 0;
+
+ if(s->avctx->debug & FF_DEBUG_PICT_INFO)
+ av_log(s->avctx, AV_LOG_INFO, "mjpeg comment: '%s'\n", cbuf);
+
+ /* buggy avid, it puts EOI only at every 10th frame */
+ if (!strcmp(cbuf, "AVID"))
+ {
+ s->buggy_avid = 1;
+ // if (s->first_picture)
+ // printf("mjpeg: workarounding buggy AVID\n");
+ }
+ else if(!strcmp(cbuf, "CS=ITU601")){
+ s->cs_itu601= 1;
+ }
+
+ av_free(cbuf);
+ }
+ }
+
+ return 0;
+}
+
+#if 0
+static int valid_marker_list[] =
+{
+ /* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f */
+/* 0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+/* 1 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+/* 2 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+/* 3 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+/* 4 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+/* 5 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+/* 6 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+/* 7 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+/* 8 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+/* 9 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+/* a */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+/* b */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+/* c */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+/* d */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+/* e */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+/* f */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
+}
+#endif
+
+/* return the 8 bit start code value and update the search
+ state. Return -1 if no start code found */
+static int find_marker(uint8_t **pbuf_ptr, uint8_t *buf_end)
+{
+ uint8_t *buf_ptr;
+ unsigned int v, v2;
+ int val;
+#ifdef DEBUG
+ int skipped=0;
+#endif
+
+ buf_ptr = *pbuf_ptr;
+ while (buf_ptr < buf_end) {
+ v = *buf_ptr++;
+ v2 = *buf_ptr;
+ if ((v == 0xff) && (v2 >= 0xc0) && (v2 <= 0xfe) && buf_ptr < buf_end) {
+ val = *buf_ptr++;
+ goto found;
+ }
+#ifdef DEBUG
+ skipped++;
+#endif
+ }
+ val = -1;
+found:
+#ifdef DEBUG
+ av_log(NULL, AV_LOG_VERBOSE, "find_marker skipped %d bytes\n", skipped);
+#endif
+ *pbuf_ptr = buf_ptr;
+ return val;
+}
+
+static int mjpeg_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ MJpegDecodeContext *s = avctx->priv_data;
+ uint8_t *buf_end, *buf_ptr;
+ int start_code;
+ AVFrame *picture = data;
+
+ buf_ptr = buf;
+ buf_end = buf + buf_size;
+ while (buf_ptr < buf_end) {
+ /* find start next marker */
+ start_code = find_marker(&buf_ptr, buf_end);
+ {
+ /* EOF */
+ if (start_code < 0) {
+ goto the_end;
+ } else {
+ av_log(avctx, AV_LOG_DEBUG, "marker=%x avail_size_in_buf=%d\n", start_code, buf_end - buf_ptr);
+
+ if ((buf_end - buf_ptr) > s->buffer_size)
+ {
+ av_free(s->buffer);
+ s->buffer_size = buf_end-buf_ptr;
+ s->buffer = av_malloc(s->buffer_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ av_log(avctx, AV_LOG_DEBUG, "buffer too small, expanding to %d bytes\n",
+ s->buffer_size);
+ }
+
+ /* unescape buffer of SOS, use special treatment for JPEG-LS */
+ if (start_code == SOS && !s->ls)
+ {
+ uint8_t *src = buf_ptr;
+ uint8_t *dst = s->buffer;
+
+ while (src<buf_end)
+ {
+ uint8_t x = *(src++);
+
+ *(dst++) = x;
+ if (avctx->codec_id != CODEC_ID_THP)
+ {
+ if (x == 0xff) {
+ while (src < buf_end && x == 0xff)
+ x = *(src++);
+
+ if (x >= 0xd0 && x <= 0xd7)
+ *(dst++) = x;
+ else if (x)
+ break;
+ }
+ }
+ }
+ init_get_bits(&s->gb, s->buffer, (dst - s->buffer)*8);
+
+ av_log(avctx, AV_LOG_DEBUG, "escaping removed %d bytes\n",
+ (buf_end - buf_ptr) - (dst - s->buffer));
+ }
+ else if(start_code == SOS && s->ls){
+ uint8_t *src = buf_ptr;
+ uint8_t *dst = s->buffer;
+ int bit_count = 0;
+ int t = 0, b = 0;
+ PutBitContext pb;
+
+ s->cur_scan++;
+
+ /* find marker */
+ while (src + t < buf_end){
+ uint8_t x = src[t++];
+ if (x == 0xff){
+ while((src + t < buf_end) && x == 0xff)
+ x = src[t++];
+ if (x & 0x80) {
+ t -= 2;
+ break;
+ }
+ }
+ }
+ bit_count = t * 8;
+
+ init_put_bits(&pb, dst, t);
+
+ /* unescape bitstream */
+ while(b < t){
+ uint8_t x = src[b++];
+ put_bits(&pb, 8, x);
+ if(x == 0xFF){
+ x = src[b++];
+ put_bits(&pb, 7, x);
+ bit_count--;
+ }
+ }
+ flush_put_bits(&pb);
+
+ init_get_bits(&s->gb, dst, bit_count);
+ }
+ else
+ init_get_bits(&s->gb, buf_ptr, (buf_end - buf_ptr)*8);
+
+ s->start_code = start_code;
+ if(s->avctx->debug & FF_DEBUG_STARTCODE){
+ av_log(avctx, AV_LOG_DEBUG, "startcode: %X\n", start_code);
+ }
+
+ /* process markers */
+ if (start_code >= 0xd0 && start_code <= 0xd7) {
+ av_log(avctx, AV_LOG_DEBUG, "restart marker: %d\n", start_code&0x0f);
+ /* APP fields */
+ } else if (start_code >= APP0 && start_code <= APP15) {
+ mjpeg_decode_app(s);
+ /* Comment */
+ } else if (start_code == COM){
+ mjpeg_decode_com(s);
+ }
+
+ switch(start_code) {
+ case SOI:
+ s->restart_interval = 0;
+
+ s->restart_count = 0;
+ /* nothing to do on SOI */
+ break;
+ case DQT:
+ mjpeg_decode_dqt(s);
+ break;
+ case DHT:
+ if(mjpeg_decode_dht(s) < 0){
+ av_log(avctx, AV_LOG_ERROR, "huffman table decode error\n");
+ return -1;
+ }
+ break;
+ case SOF0:
+ s->lossless=0;
+ s->ls=0;
+ s->progressive=0;
+ if (mjpeg_decode_sof(s) < 0)
+ return -1;
+ break;
+ case SOF2:
+ s->lossless=0;
+ s->ls=0;
+ s->progressive=1;
+ if (mjpeg_decode_sof(s) < 0)
+ return -1;
+ break;
+ case SOF3:
+ s->lossless=1;
+ s->ls=0;
+ s->progressive=0;
+ if (mjpeg_decode_sof(s) < 0)
+ return -1;
+ break;
+ case SOF48:
+ s->lossless=1;
+ s->ls=1;
+ s->progressive=0;
+ if (mjpeg_decode_sof(s) < 0)
+ return -1;
+ break;
+ case LSE:
+ if (decode_lse(s) < 0)
+ return -1;
+ break;
+ case EOI:
+ s->cur_scan = 0;
+ if ((s->buggy_avid && !s->interlaced) || s->restart_interval)
+ break;
+eoi_parser:
+ {
+ if (s->interlaced) {
+ s->bottom_field ^= 1;
+ /* if not bottom field, do not output image yet */
+ if (s->bottom_field == !s->interlace_polarity)
+ goto not_the_end;
+ }
+ *picture = s->picture;
+ *data_size = sizeof(AVFrame);
+
+ if(!s->lossless){
+ picture->quality= FFMAX(FFMAX(s->qscale[0], s->qscale[1]), s->qscale[2]);
+ picture->qstride= 0;
+ picture->qscale_table= s->qscale_table;
+ memset(picture->qscale_table, picture->quality, (s->width+15)/16);
+ if(avctx->debug & FF_DEBUG_QP)
+ av_log(avctx, AV_LOG_DEBUG, "QP: %d\n", picture->quality);
+ picture->quality*= FF_QP2LAMBDA;
+ }
+
+ goto the_end;
+ }
+ break;
+ case SOS:
+ mjpeg_decode_sos(s);
+ /* buggy avid puts EOI every 10-20th frame */
+ /* if restart period is over process EOI */
+ if ((s->buggy_avid && !s->interlaced) || s->restart_interval)
+ goto eoi_parser;
+ break;
+ case DRI:
+ mjpeg_decode_dri(s);
+ break;
+ case SOF1:
+ case SOF5:
+ case SOF6:
+ case SOF7:
+ case SOF9:
+ case SOF10:
+ case SOF11:
+ case SOF13:
+ case SOF14:
+ case SOF15:
+ case JPG:
+ av_log(avctx, AV_LOG_ERROR, "mjpeg: unsupported coding type (%x)\n", start_code);
+ break;
+// default:
+// printf("mjpeg: unsupported marker (%x)\n", start_code);
+// break;
+ }
+
+not_the_end:
+ /* eof process start code */
+ buf_ptr += (get_bits_count(&s->gb)+7)/8;
+ av_log(avctx, AV_LOG_DEBUG, "marker parser used %d bytes (%d bits)\n",
+ (get_bits_count(&s->gb)+7)/8, get_bits_count(&s->gb));
+ }
+ }
+ }
+the_end:
+ av_log(avctx, AV_LOG_DEBUG, "mjpeg decode frame unused %d bytes\n", buf_end - buf_ptr);
+// return buf_end - buf_ptr;
+ return buf_ptr - buf;
+}
+
+static int mjpegb_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ MJpegDecodeContext *s = avctx->priv_data;
+ uint8_t *buf_end, *buf_ptr;
+ AVFrame *picture = data;
+ GetBitContext hgb; /* for the header */
+ uint32_t dqt_offs, dht_offs, sof_offs, sos_offs, second_field_offs;
+ uint32_t field_size, sod_offs;
+
+ buf_ptr = buf;
+ buf_end = buf + buf_size;
+
+read_header:
+ /* reset on every SOI */
+ s->restart_interval = 0;
+ s->restart_count = 0;
+ s->mjpb_skiptosod = 0;
+
+ init_get_bits(&hgb, buf_ptr, /*buf_size*/(buf_end - buf_ptr)*8);
+
+ skip_bits(&hgb, 32); /* reserved zeros */
+
+ if (get_bits_long(&hgb, 32) != MKBETAG('m','j','p','g'))
+ {
+ av_log(avctx, AV_LOG_WARNING, "not mjpeg-b (bad fourcc)\n");
+ return 0;
+ }
+
+ field_size = get_bits_long(&hgb, 32); /* field size */
+ av_log(avctx, AV_LOG_DEBUG, "field size: 0x%x\n", field_size);
+ skip_bits(&hgb, 32); /* padded field size */
+ second_field_offs = get_bits_long(&hgb, 32);
+ av_log(avctx, AV_LOG_DEBUG, "second field offs: 0x%x\n", second_field_offs);
+ if (second_field_offs)
+ s->interlaced = 1;
+
+ dqt_offs = get_bits_long(&hgb, 32);
+ av_log(avctx, AV_LOG_DEBUG, "dqt offs: 0x%x\n", dqt_offs);
+ if (dqt_offs)
+ {
+ init_get_bits(&s->gb, buf+dqt_offs, (buf_end - (buf+dqt_offs))*8);
+ s->start_code = DQT;
+ mjpeg_decode_dqt(s);
+ }
+
+ dht_offs = get_bits_long(&hgb, 32);
+ av_log(avctx, AV_LOG_DEBUG, "dht offs: 0x%x\n", dht_offs);
+ if (dht_offs)
+ {
+ init_get_bits(&s->gb, buf+dht_offs, (buf_end - (buf+dht_offs))*8);
+ s->start_code = DHT;
+ mjpeg_decode_dht(s);
+ }
+
+ sof_offs = get_bits_long(&hgb, 32);
+ av_log(avctx, AV_LOG_DEBUG, "sof offs: 0x%x\n", sof_offs);
+ if (sof_offs)
+ {
+ init_get_bits(&s->gb, buf+sof_offs, (buf_end - (buf+sof_offs))*8);
+ s->start_code = SOF0;
+ if (mjpeg_decode_sof(s) < 0)
+ return -1;
+ }
+
+ sos_offs = get_bits_long(&hgb, 32);
+ av_log(avctx, AV_LOG_DEBUG, "sos offs: 0x%x\n", sos_offs);
+ sod_offs = get_bits_long(&hgb, 32);
+ av_log(avctx, AV_LOG_DEBUG, "sod offs: 0x%x\n", sod_offs);
+ if (sos_offs)
+ {
+// init_get_bits(&s->gb, buf+sos_offs, (buf_end - (buf+sos_offs))*8);
+ init_get_bits(&s->gb, buf+sos_offs, field_size*8);
+ s->mjpb_skiptosod = (sod_offs - sos_offs - show_bits(&s->gb, 16));
+ s->start_code = SOS;
+ mjpeg_decode_sos(s);
+ }
+
+ if (s->interlaced) {
+ s->bottom_field ^= 1;
+ /* if not bottom field, do not output image yet */
+ if (s->bottom_field && second_field_offs)
+ {
+ buf_ptr = buf + second_field_offs;
+ second_field_offs = 0;
+ goto read_header;
+ }
+ }
+
+ //XXX FIXME factorize, this looks very similar to the EOI code
+
+ *picture= s->picture;
+ *data_size = sizeof(AVFrame);
+
+ if(!s->lossless){
+ picture->quality= FFMAX(FFMAX(s->qscale[0], s->qscale[1]), s->qscale[2]);
+ picture->qstride= 0;
+ picture->qscale_table= s->qscale_table;
+ memset(picture->qscale_table, picture->quality, (s->width+15)/16);
+ if(avctx->debug & FF_DEBUG_QP)
+ av_log(avctx, AV_LOG_DEBUG, "QP: %d\n", picture->quality);
+ picture->quality*= FF_QP2LAMBDA;
+ }
+
+ return buf_ptr - buf;
+}
+
+#include "sp5x.h"
+
+static int sp5x_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+#if 0
+ MJpegDecodeContext *s = avctx->priv_data;
+#endif
+ const int qscale = 5;
+ uint8_t *buf_ptr, *buf_end, *recoded;
+ int i = 0, j = 0;
+
+ if (!avctx->width || !avctx->height)
+ return -1;
+
+ buf_ptr = buf;
+ buf_end = buf + buf_size;
+
+#if 1
+ recoded = av_mallocz(buf_size + 1024);
+ if (!recoded)
+ return -1;
+
+ /* SOI */
+ recoded[j++] = 0xFF;
+ recoded[j++] = 0xD8;
+
+ memcpy(recoded+j, &sp5x_data_dqt[0], sizeof(sp5x_data_dqt));
+ memcpy(recoded+j+5, &sp5x_quant_table[qscale * 2], 64);
+ memcpy(recoded+j+70, &sp5x_quant_table[(qscale * 2) + 1], 64);
+ j += sizeof(sp5x_data_dqt);
+
+ memcpy(recoded+j, &sp5x_data_dht[0], sizeof(sp5x_data_dht));
+ j += sizeof(sp5x_data_dht);
+
+ memcpy(recoded+j, &sp5x_data_sof[0], sizeof(sp5x_data_sof));
+ recoded[j+5] = (avctx->coded_height >> 8) & 0xFF;
+ recoded[j+6] = avctx->coded_height & 0xFF;
+ recoded[j+7] = (avctx->coded_width >> 8) & 0xFF;
+ recoded[j+8] = avctx->coded_width & 0xFF;
+ j += sizeof(sp5x_data_sof);
+
+ memcpy(recoded+j, &sp5x_data_sos[0], sizeof(sp5x_data_sos));
+ j += sizeof(sp5x_data_sos);
+
+ for (i = 14; i < buf_size && j < buf_size+1024-2; i++)
+ {
+ recoded[j++] = buf[i];
+ if (buf[i] == 0xff)
+ recoded[j++] = 0;
+ }
+
+ /* EOI */
+ recoded[j++] = 0xFF;
+ recoded[j++] = 0xD9;
+
+ i = mjpeg_decode_frame(avctx, data, data_size, recoded, j);
+
+ av_free(recoded);
+
+#else
+ /* SOF */
+ s->bits = 8;
+ s->width = avctx->coded_width;
+ s->height = avctx->coded_height;
+ s->nb_components = 3;
+ s->component_id[0] = 0;
+ s->h_count[0] = 2;
+ s->v_count[0] = 2;
+ s->quant_index[0] = 0;
+ s->component_id[1] = 1;
+ s->h_count[1] = 1;
+ s->v_count[1] = 1;
+ s->quant_index[1] = 1;
+ s->component_id[2] = 2;
+ s->h_count[2] = 1;
+ s->v_count[2] = 1;
+ s->quant_index[2] = 1;
+ s->h_max = 2;
+ s->v_max = 2;
+
+ s->qscale_table = av_mallocz((s->width+15)/16);
+ avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV420P : PIX_FMT_YUVJ420;
+ s->interlaced = 0;
+
+ s->picture.reference = 0;
+ if (avctx->get_buffer(avctx, &s->picture) < 0)
+ {
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ return -1;
+ }
+
+ s->picture.pict_type = I_TYPE;
+ s->picture.key_frame = 1;
+
+ for (i = 0; i < 3; i++)
+ s->linesize[i] = s->picture.linesize[i] << s->interlaced;
+
+ /* DQT */
+ for (i = 0; i < 64; i++)
+ {
+ j = s->scantable.permutated[i];
+ s->quant_matrixes[0][j] = sp5x_quant_table[(qscale * 2) + i];
+ }
+ s->qscale[0] = FFMAX(
+ s->quant_matrixes[0][s->scantable.permutated[1]],
+ s->quant_matrixes[0][s->scantable.permutated[8]]) >> 1;
+
+ for (i = 0; i < 64; i++)
+ {
+ j = s->scantable.permutated[i];
+ s->quant_matrixes[1][j] = sp5x_quant_table[(qscale * 2) + 1 + i];
+ }
+ s->qscale[1] = FFMAX(
+ s->quant_matrixes[1][s->scantable.permutated[1]],
+ s->quant_matrixes[1][s->scantable.permutated[8]]) >> 1;
+
+ /* DHT */
+
+ /* SOS */
+ s->comp_index[0] = 0;
+ s->nb_blocks[0] = s->h_count[0] * s->v_count[0];
+ s->h_scount[0] = s->h_count[0];
+ s->v_scount[0] = s->v_count[0];
+ s->dc_index[0] = 0;
+ s->ac_index[0] = 0;
+
+ s->comp_index[1] = 1;
+ s->nb_blocks[1] = s->h_count[1] * s->v_count[1];
+ s->h_scount[1] = s->h_count[1];
+ s->v_scount[1] = s->v_count[1];
+ s->dc_index[1] = 1;
+ s->ac_index[1] = 1;
+
+ s->comp_index[2] = 2;
+ s->nb_blocks[2] = s->h_count[2] * s->v_count[2];
+ s->h_scount[2] = s->h_count[2];
+ s->v_scount[2] = s->v_count[2];
+ s->dc_index[2] = 1;
+ s->ac_index[2] = 1;
+
+ for (i = 0; i < 3; i++)
+ s->last_dc[i] = 1024;
+
+ s->mb_width = (s->width * s->h_max * 8 -1) / (s->h_max * 8);
+ s->mb_height = (s->height * s->v_max * 8 -1) / (s->v_max * 8);
+
+ init_get_bits(&s->gb, buf+14, (buf_size-14)*8);
+
+ return mjpeg_decode_scan(s);
+#endif
+
+ return i;
+}
+
+static int mjpeg_decode_end(AVCodecContext *avctx)
+{
+ MJpegDecodeContext *s = avctx->priv_data;
+ int i, j;
+
+ av_free(s->buffer);
+ av_free(s->qscale_table);
+
+ for(i=0;i<2;i++) {
+ for(j=0;j<4;j++)
+ free_vlc(&s->vlcs[i][j]);
+ }
+ return 0;
+}
+
+static int mjpega_dump_header(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
+ uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size, int keyframe)
+{
+ uint8_t *poutbufp;
+ int i;
+
+ if (avctx->codec_id != CODEC_ID_MJPEG) {
+ av_log(avctx, AV_LOG_ERROR, "mjpega bitstream filter only applies to mjpeg codec\n");
+ return 0;
+ }
+
+ *poutbuf_size = 0;
+ *poutbuf = av_malloc(buf_size + 44 + FF_INPUT_BUFFER_PADDING_SIZE);
+ poutbufp = *poutbuf;
+ bytestream_put_byte(&poutbufp, 0xff);
+ bytestream_put_byte(&poutbufp, SOI);
+ bytestream_put_byte(&poutbufp, 0xff);
+ bytestream_put_byte(&poutbufp, APP1);
+ bytestream_put_be16(&poutbufp, 42); /* size */
+ bytestream_put_be32(&poutbufp, 0);
+ bytestream_put_buffer(&poutbufp, "mjpg", 4);
+ bytestream_put_be32(&poutbufp, buf_size + 44); /* field size */
+ bytestream_put_be32(&poutbufp, buf_size + 44); /* pad field size */
+ bytestream_put_be32(&poutbufp, 0); /* next ptr */
+
+ for (i = 0; i < buf_size - 1; i++) {
+ if (buf[i] == 0xff) {
+ switch (buf[i + 1]) {
+ case DQT: /* quant off */
+ case DHT: /* huff off */
+ case SOF0: /* image off */
+ bytestream_put_be32(&poutbufp, i + 46);
+ break;
+ case SOS:
+ bytestream_put_be32(&poutbufp, i + 46); /* scan off */
+ bytestream_put_be32(&poutbufp, i + 46 + AV_RB16(buf + i + 2)); /* data off */
+ bytestream_put_buffer(&poutbufp, buf + 2, buf_size - 2); /* skip already written SOI */
+ *poutbuf_size = poutbufp - *poutbuf;
+ return 1;
+ case APP1:
+ if (i + 8 < buf_size && AV_RL32(buf + i + 8) == ff_get_fourcc("mjpg")) {
+ av_log(avctx, AV_LOG_ERROR, "bitstream already formatted\n");
+ memcpy(*poutbuf, buf, buf_size);
+ *poutbuf_size = buf_size;
+ return 1;
+ }
+ }
+ }
+ }
+ av_freep(poutbuf);
+ av_log(avctx, AV_LOG_ERROR, "could not find SOS marker in bitstream\n");
+ return 0;
+}
+
+AVCodec mjpeg_decoder = {
+ "mjpeg",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_MJPEG,
+ sizeof(MJpegDecodeContext),
+ mjpeg_decode_init,
+ NULL,
+ mjpeg_decode_end,
+ mjpeg_decode_frame,
+ CODEC_CAP_DR1,
+ NULL
+};
+
+AVCodec thp_decoder = {
+ "thp",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_THP,
+ sizeof(MJpegDecodeContext),
+ mjpeg_decode_init,
+ NULL,
+ mjpeg_decode_end,
+ mjpeg_decode_frame,
+ CODEC_CAP_DR1,
+ NULL
+};
+
+AVCodec mjpegb_decoder = {
+ "mjpegb",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_MJPEGB,
+ sizeof(MJpegDecodeContext),
+ mjpeg_decode_init,
+ NULL,
+ mjpeg_decode_end,
+ mjpegb_decode_frame,
+ CODEC_CAP_DR1,
+ NULL
+};
+
+AVCodec sp5x_decoder = {
+ "sp5x",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_SP5X,
+ sizeof(MJpegDecodeContext),
+ mjpeg_decode_init,
+ NULL,
+ mjpeg_decode_end,
+ sp5x_decode_frame,
+ CODEC_CAP_DR1,
+ NULL
+};
+
+#ifdef CONFIG_ENCODERS
+AVCodec ljpeg_encoder = { //FIXME avoid MPV_* lossless jpeg shouldnt need them
+ "ljpeg",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_LJPEG,
+ sizeof(MpegEncContext),
+ MPV_encode_init,
+ encode_picture_lossless,
+ MPV_encode_end,
+};
+#endif
+
+AVCodecParser mjpeg_parser = {
+ { CODEC_ID_MJPEG },
+ sizeof(ParseContext),
+ NULL,
+ jpeg_parse,
+ ff_parse_close,
+};
+
+AVBitStreamFilter mjpega_dump_header_bsf = {
+ "mjpegadump",
+ 0,
+ mjpega_dump_header,
+};
diff --git a/contrib/ffmpeg/libavcodec/mlib/dsputil_mlib.c b/contrib/ffmpeg/libavcodec/mlib/dsputil_mlib.c
new file mode 100644
index 000000000..b78a54e0e
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/mlib/dsputil_mlib.c
@@ -0,0 +1,464 @@
+/*
+ * Sun mediaLib optimized DSP utils
+ * Copyright (c) 2001 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 "../dsputil.h"
+#include "../mpegvideo.h"
+
+#include <mlib_types.h>
+#include <mlib_status.h>
+#include <mlib_sys.h>
+#include <mlib_algebra.h>
+#include <mlib_video.h>
+
+/* misc */
+
+static void get_pixels_mlib(DCTELEM *restrict block, const uint8_t *pixels, int line_size)
+{
+ int i;
+
+ for (i=0;i<8;i++) {
+ mlib_VectorConvert_S16_U8_Mod((mlib_s16 *)block, (mlib_u8 *)pixels, 8);
+
+ pixels += line_size;
+ block += 8;
+ }
+}
+
+static void diff_pixels_mlib(DCTELEM *restrict block, const uint8_t *s1, const uint8_t *s2, int line_size)
+{
+ int i;
+
+ for (i=0;i<8;i++) {
+ mlib_VectorSub_S16_U8_Mod((mlib_s16 *)block, (mlib_u8 *)s1, (mlib_u8 *)s2, 8);
+
+ s1 += line_size;
+ s2 += line_size;
+ block += 8;
+ }
+}
+
+static void add_pixels_clamped_mlib(const DCTELEM *block, uint8_t *pixels, int line_size)
+{
+ mlib_VideoAddBlock_U8_S16(pixels, (mlib_s16 *)block, line_size);
+}
+
+/* put block, width 16 pixel, height 8/16 */
+
+static void put_pixels16_mlib (uint8_t * dest, const uint8_t * ref,
+ int stride, int height)
+{
+ switch (height) {
+ case 8:
+ mlib_VideoCopyRef_U8_U8_16x8(dest, (uint8_t *)ref, stride);
+ break;
+
+ case 16:
+ mlib_VideoCopyRef_U8_U8_16x16(dest, (uint8_t *)ref, stride);
+ break;
+
+ default:
+ assert(0);
+ }
+}
+
+static void put_pixels16_x2_mlib (uint8_t * dest, const uint8_t * ref,
+ int stride, int height)
+{
+ switch (height) {
+ case 8:
+ mlib_VideoInterpX_U8_U8_16x8(dest, (uint8_t *)ref, stride, stride);
+ break;
+
+ case 16:
+ mlib_VideoInterpX_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
+ break;
+
+ default:
+ assert(0);
+ }
+}
+
+static void put_pixels16_y2_mlib (uint8_t * dest, const uint8_t * ref,
+ int stride, int height)
+{
+ switch (height) {
+ case 8:
+ mlib_VideoInterpY_U8_U8_16x8(dest, (uint8_t *)ref, stride, stride);
+ break;
+
+ case 16:
+ mlib_VideoInterpY_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
+ break;
+
+ default:
+ assert(0);
+ }
+}
+
+static void put_pixels16_xy2_mlib(uint8_t * dest, const uint8_t * ref,
+ int stride, int height)
+{
+ switch (height) {
+ case 8:
+ mlib_VideoInterpXY_U8_U8_16x8(dest, (uint8_t *)ref, stride, stride);
+ break;
+
+ case 16:
+ mlib_VideoInterpXY_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
+ break;
+
+ default:
+ assert(0);
+ }
+}
+
+/* put block, width 8 pixel, height 4/8/16 */
+
+static void put_pixels8_mlib (uint8_t * dest, const uint8_t * ref,
+ int stride, int height)
+{
+ switch (height) {
+ case 4:
+ mlib_VideoCopyRef_U8_U8_8x4(dest, (uint8_t *)ref, stride);
+ break;
+
+ case 8:
+ mlib_VideoCopyRef_U8_U8_8x8(dest, (uint8_t *)ref, stride);
+ break;
+
+ case 16:
+ mlib_VideoCopyRef_U8_U8_8x16(dest, (uint8_t *)ref, stride);
+ break;
+
+ default:
+ assert(0);
+ }
+}
+
+static void put_pixels8_x2_mlib (uint8_t * dest, const uint8_t * ref,
+ int stride, int height)
+{
+ switch (height) {
+ case 4:
+ mlib_VideoInterpX_U8_U8_8x4(dest, (uint8_t *)ref, stride, stride);
+ break;
+
+ case 8:
+ mlib_VideoInterpX_U8_U8_8x8(dest, (uint8_t *)ref, stride, stride);
+ break;
+
+ case 16:
+ mlib_VideoInterpX_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
+ break;
+
+ default:
+ assert(0);
+ }
+}
+
+static void put_pixels8_y2_mlib (uint8_t * dest, const uint8_t * ref,
+ int stride, int height)
+{
+ switch (height) {
+ case 4:
+ mlib_VideoInterpY_U8_U8_8x4(dest, (uint8_t *)ref, stride, stride);
+ break;
+
+ case 8:
+ mlib_VideoInterpY_U8_U8_8x8(dest, (uint8_t *)ref, stride, stride);
+ break;
+
+ case 16:
+ mlib_VideoInterpY_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
+ break;
+
+ default:
+ assert(0);
+ }
+}
+
+static void put_pixels8_xy2_mlib(uint8_t * dest, const uint8_t * ref,
+ int stride, int height)
+{
+ switch (height) {
+ case 4:
+ mlib_VideoInterpXY_U8_U8_8x4(dest, (uint8_t *)ref, stride, stride);
+ break;
+
+ case 8:
+ mlib_VideoInterpXY_U8_U8_8x8(dest, (uint8_t *)ref, stride, stride);
+ break;
+
+ case 16:
+ mlib_VideoInterpXY_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
+ break;
+
+ default:
+ assert(0);
+ }
+}
+
+/* average block, width 16 pixel, height 8/16 */
+
+static void avg_pixels16_mlib (uint8_t * dest, const uint8_t * ref,
+ int stride, int height)
+{
+ switch (height) {
+ case 8:
+ mlib_VideoCopyRefAve_U8_U8_16x8(dest, (uint8_t *)ref, stride);
+ break;
+
+ case 16:
+ mlib_VideoCopyRefAve_U8_U8_16x16(dest, (uint8_t *)ref, stride);
+ break;
+
+ default:
+ assert(0);
+ }
+}
+
+static void avg_pixels16_x2_mlib (uint8_t * dest, const uint8_t * ref,
+ int stride, int height)
+{
+ switch (height) {
+ case 8:
+ mlib_VideoInterpAveX_U8_U8_16x8(dest, (uint8_t *)ref, stride, stride);
+ break;
+
+ case 16:
+ mlib_VideoInterpAveX_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
+ break;
+
+ default:
+ assert(0);
+ }
+}
+
+static void avg_pixels16_y2_mlib (uint8_t * dest, const uint8_t * ref,
+ int stride, int height)
+{
+ switch (height) {
+ case 8:
+ mlib_VideoInterpAveY_U8_U8_16x8(dest, (uint8_t *)ref, stride, stride);
+ break;
+
+ case 16:
+ mlib_VideoInterpAveY_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
+ break;
+
+ default:
+ assert(0);
+ }
+}
+
+static void avg_pixels16_xy2_mlib(uint8_t * dest, const uint8_t * ref,
+ int stride, int height)
+{
+ switch (height) {
+ case 8:
+ mlib_VideoInterpAveXY_U8_U8_16x8(dest, (uint8_t *)ref, stride, stride);
+ break;
+
+ case 16:
+ mlib_VideoInterpAveXY_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
+ break;
+
+ default:
+ assert(0);
+ }
+}
+
+/* average block, width 8 pixel, height 4/8/16 */
+
+static void avg_pixels8_mlib (uint8_t * dest, const uint8_t * ref,
+ int stride, int height)
+{
+ switch (height) {
+ case 4:
+ mlib_VideoCopyRefAve_U8_U8_8x4(dest, (uint8_t *)ref, stride);
+ break;
+
+ case 8:
+ mlib_VideoCopyRefAve_U8_U8_8x8(dest, (uint8_t *)ref, stride);
+ break;
+
+ case 16:
+ mlib_VideoCopyRefAve_U8_U8_8x16(dest, (uint8_t *)ref, stride);
+ break;
+
+ default:
+ assert(0);
+ }
+}
+
+static void avg_pixels8_x2_mlib (uint8_t * dest, const uint8_t * ref,
+ int stride, int height)
+{
+ switch (height) {
+ case 4:
+ mlib_VideoInterpAveX_U8_U8_8x4(dest, (uint8_t *)ref, stride, stride);
+ break;
+
+ case 8:
+ mlib_VideoInterpAveX_U8_U8_8x8(dest, (uint8_t *)ref, stride, stride);
+ break;
+
+ case 16:
+ mlib_VideoInterpAveX_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
+ break;
+
+ default:
+ assert(0);
+ }
+}
+
+static void avg_pixels8_y2_mlib (uint8_t * dest, const uint8_t * ref,
+ int stride, int height)
+{
+ switch (height) {
+ case 4:
+ mlib_VideoInterpAveY_U8_U8_8x4(dest, (uint8_t *)ref, stride, stride);
+ break;
+
+ case 8:
+ mlib_VideoInterpAveY_U8_U8_8x8(dest, (uint8_t *)ref, stride, stride);
+ break;
+
+ case 16:
+ mlib_VideoInterpAveY_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
+ break;
+
+ default:
+ assert(0);
+ }
+}
+
+static void avg_pixels8_xy2_mlib(uint8_t * dest, const uint8_t * ref,
+ int stride, int height)
+{
+ switch (height) {
+ case 4:
+ mlib_VideoInterpAveXY_U8_U8_8x4(dest, (uint8_t *)ref, stride, stride);
+ break;
+
+ case 8:
+ mlib_VideoInterpAveXY_U8_U8_8x8(dest, (uint8_t *)ref, stride, stride);
+ break;
+
+ case 16:
+ mlib_VideoInterpAveXY_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
+ break;
+
+ default:
+ assert(0);
+ }
+}
+
+/* swap byte order of a buffer */
+
+static void bswap_buf_mlib(uint32_t *dst, uint32_t *src, int w)
+{
+ mlib_VectorReverseByteOrder_U32_U32(dst, src, w);
+}
+
+/* transformations */
+
+static void ff_idct_put_mlib(uint8_t *dest, int line_size, DCTELEM *data)
+{
+ int i;
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+
+ mlib_VideoIDCT8x8_S16_S16 (data, data);
+
+ for(i=0;i<8;i++) {
+ dest[0] = cm[data[0]];
+ dest[1] = cm[data[1]];
+ dest[2] = cm[data[2]];
+ dest[3] = cm[data[3]];
+ dest[4] = cm[data[4]];
+ dest[5] = cm[data[5]];
+ dest[6] = cm[data[6]];
+ dest[7] = cm[data[7]];
+
+ dest += line_size;
+ data += 8;
+ }
+}
+
+static void ff_idct_add_mlib(uint8_t *dest, int line_size, DCTELEM *data)
+{
+ mlib_VideoIDCT8x8_S16_S16 (data, data);
+ mlib_VideoAddBlock_U8_S16(dest, (mlib_s16 *)data, line_size);
+}
+
+static void ff_idct_mlib(DCTELEM *data)
+{
+ mlib_VideoIDCT8x8_S16_S16 (data, data);
+}
+
+static void ff_fdct_mlib(DCTELEM *data)
+{
+ mlib_VideoDCT8x8_S16_S16 (data, data);
+}
+
+void dsputil_init_mlib(DSPContext* c, AVCodecContext *avctx)
+{
+ c->get_pixels = get_pixels_mlib;
+ c->diff_pixels = diff_pixels_mlib;
+ c->add_pixels_clamped = add_pixels_clamped_mlib;
+
+ c->put_pixels_tab[0][0] = put_pixels16_mlib;
+ c->put_pixels_tab[0][1] = put_pixels16_x2_mlib;
+ c->put_pixels_tab[0][2] = put_pixels16_y2_mlib;
+ c->put_pixels_tab[0][3] = put_pixels16_xy2_mlib;
+ c->put_pixels_tab[1][0] = put_pixels8_mlib;
+ c->put_pixels_tab[1][1] = put_pixels8_x2_mlib;
+ c->put_pixels_tab[1][2] = put_pixels8_y2_mlib;
+ c->put_pixels_tab[1][3] = put_pixels8_xy2_mlib;
+
+ c->avg_pixels_tab[0][0] = avg_pixels16_mlib;
+ c->avg_pixels_tab[0][1] = avg_pixels16_x2_mlib;
+ c->avg_pixels_tab[0][2] = avg_pixels16_y2_mlib;
+ c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mlib;
+ c->avg_pixels_tab[1][0] = avg_pixels8_mlib;
+ c->avg_pixels_tab[1][1] = avg_pixels8_x2_mlib;
+ c->avg_pixels_tab[1][2] = avg_pixels8_y2_mlib;
+ c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mlib;
+
+ c->put_no_rnd_pixels_tab[0][0] = put_pixels16_mlib;
+ c->put_no_rnd_pixels_tab[1][0] = put_pixels8_mlib;
+
+ c->bswap_buf = bswap_buf_mlib;
+}
+
+void MPV_common_init_mlib(MpegEncContext *s)
+{
+ if(s->avctx->dct_algo==FF_DCT_AUTO || s->avctx->dct_algo==FF_DCT_MLIB){
+ s->dsp.fdct = ff_fdct_mlib;
+ }
+
+ if(s->avctx->idct_algo==FF_IDCT_AUTO || s->avctx->idct_algo==FF_IDCT_MLIB){
+ s->dsp.idct_put= ff_idct_put_mlib;
+ s->dsp.idct_add= ff_idct_add_mlib;
+ s->dsp.idct = ff_idct_mlib;
+ s->dsp.idct_permutation_type= FF_NO_IDCT_PERM;
+ }
+}
diff --git a/src/libffmpeg/libavcodec/mmvideo.c b/contrib/ffmpeg/libavcodec/mmvideo.c
index 7ba1321cb..7ba1321cb 100644
--- a/src/libffmpeg/libavcodec/mmvideo.c
+++ b/contrib/ffmpeg/libavcodec/mmvideo.c
diff --git a/contrib/ffmpeg/libavcodec/motion_est.c b/contrib/ffmpeg/libavcodec/motion_est.c
new file mode 100644
index 000000000..a042f4916
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/motion_est.c
@@ -0,0 +1,2147 @@
+/*
+ * Motion estimation
+ * Copyright (c) 2000,2001 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
+ *
+ * new Motion Estimation (X1/EPZS) by Michael Niedermayer <michaelni@gmx.at>
+ */
+
+/**
+ * @file motion_est.c
+ * Motion estimation.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <limits.h>
+#include "avcodec.h"
+#include "dsputil.h"
+#include "mpegvideo.h"
+
+#undef NDEBUG
+#include <assert.h>
+
+#define SQ(a) ((a)*(a))
+
+#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]
+
+static inline int sad_hpel_motion_search(MpegEncContext * s,
+ int *mx_ptr, int *my_ptr, int dmin,
+ int src_index, int ref_index,
+ int size, int h);
+
+static inline int update_map_generation(MotionEstContext *c)
+{
+ c->map_generation+= 1<<(ME_MAP_MV_BITS*2);
+ if(c->map_generation==0){
+ c->map_generation= 1<<(ME_MAP_MV_BITS*2);
+ memset(c->map, 0, sizeof(uint32_t)*ME_MAP_SIZE);
+ }
+ return c->map_generation;
+}
+
+/* shape adaptive search stuff */
+typedef struct Minima{
+ int height;
+ int x, y;
+ int checked;
+}Minima;
+
+static int minima_cmp(const void *a, const void *b){
+ const Minima *da = (const Minima *) a;
+ const Minima *db = (const Minima *) b;
+
+ return da->height - db->height;
+}
+
+#define FLAG_QPEL 1 //must be 1
+#define FLAG_CHROMA 2
+#define FLAG_DIRECT 4
+
+static inline void init_ref(MotionEstContext *c, uint8_t *src[3], uint8_t *ref[3], uint8_t *ref2[3], int x, int y, int ref_index){
+ const int offset[3]= {
+ y*c-> stride + x,
+ ((y*c->uvstride + x)>>1),
+ ((y*c->uvstride + x)>>1),
+ };
+ int i;
+ for(i=0; i<3; i++){
+ c->src[0][i]= src [i] + offset[i];
+ c->ref[0][i]= ref [i] + offset[i];
+ }
+ if(ref_index){
+ for(i=0; i<3; i++){
+ c->ref[ref_index][i]= ref2[i] + offset[i];
+ }
+ }
+}
+
+static int get_flags(MotionEstContext *c, int direct, int chroma){
+ return ((c->avctx->flags&CODEC_FLAG_QPEL) ? FLAG_QPEL : 0)
+ + (direct ? FLAG_DIRECT : 0)
+ + (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,
+ 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){
+ 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;
+ const int time_pb= s->pb_time;
+ const int mask= 2*qpel+1;
+ if(s->mv_type==MV_TYPE_8X8){
+ int i;
+ for(i=0; i<4; i++){
+ int fx = c->direct_basis_mv[i][0] + hx;
+ int fy = c->direct_basis_mv[i][1] + hy;
+ int bx = hx ? fx - c->co_located_mv[i][0] : c->co_located_mv[i][0]*(time_pb - time_pp)/time_pp + ((i &1)<<(qpel+4));
+ int by = hy ? fy - c->co_located_mv[i][1] : c->co_located_mv[i][1]*(time_pb - time_pp)/time_pp + ((i>>1)<<(qpel+4));
+ int fxy= (fx&mask) + ((fy&mask)<<(qpel+1));
+ int bxy= (bx&mask) + ((by&mask)<<(qpel+1));
+
+ uint8_t *dst= c->temp + 8*(i&1) + 8*stride*(i>>1);
+ if(qpel){
+ c->qpel_put[1][fxy](dst, ref[0] + (fx>>2) + (fy>>2)*stride, stride);
+ c->qpel_avg[1][bxy](dst, ref[8] + (bx>>2) + (by>>2)*stride, stride);
+ }else{
+ c->hpel_put[1][fxy](dst, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 8);
+ c->hpel_avg[1][bxy](dst, ref[8] + (bx>>1) + (by>>1)*stride, stride, 8);
+ }
+ }
+ }else{
+ int fx = c->direct_basis_mv[0][0] + hx;
+ int fy = c->direct_basis_mv[0][1] + hy;
+ int bx = hx ? fx - c->co_located_mv[0][0] : (c->co_located_mv[0][0]*(time_pb - time_pp)/time_pp);
+ int by = hy ? fy - c->co_located_mv[0][1] : (c->co_located_mv[0][1]*(time_pb - time_pp)/time_pp);
+ int fxy= (fx&mask) + ((fy&mask)<<(qpel+1));
+ int bxy= (bx&mask) + ((by&mask)<<(qpel+1));
+
+ if(qpel){
+ c->qpel_put[1][fxy](c->temp , ref[0] + (fx>>2) + (fy>>2)*stride , stride);
+ c->qpel_put[1][fxy](c->temp + 8 , ref[0] + (fx>>2) + (fy>>2)*stride + 8 , stride);
+ c->qpel_put[1][fxy](c->temp + 8*stride, ref[0] + (fx>>2) + (fy>>2)*stride + 8*stride, stride);
+ c->qpel_put[1][fxy](c->temp + 8 + 8*stride, ref[0] + (fx>>2) + (fy>>2)*stride + 8 + 8*stride, stride);
+ c->qpel_avg[1][bxy](c->temp , ref[8] + (bx>>2) + (by>>2)*stride , stride);
+ c->qpel_avg[1][bxy](c->temp + 8 , ref[8] + (bx>>2) + (by>>2)*stride + 8 , stride);
+ c->qpel_avg[1][bxy](c->temp + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride + 8*stride, stride);
+ c->qpel_avg[1][bxy](c->temp + 8 + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride + 8 + 8*stride, stride);
+ }else{
+ assert((fx>>1) + 16*s->mb_x >= -16);
+ assert((fy>>1) + 16*s->mb_y >= -16);
+ assert((fx>>1) + 16*s->mb_x <= s->width);
+ assert((fy>>1) + 16*s->mb_y <= s->height);
+ assert((bx>>1) + 16*s->mb_x >= -16);
+ assert((by>>1) + 16*s->mb_y >= -16);
+ assert((bx>>1) + 16*s->mb_x <= s->width);
+ assert((by>>1) + 16*s->mb_y <= s->height);
+
+ c->hpel_put[0][fxy](c->temp, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 16);
+ c->hpel_avg[0][bxy](c->temp, ref[8] + (bx>>1) + (by>>1)*stride, stride, 16);
+ }
+ }
+ d = cmp_func(s, c->temp, src[0], stride, 16);
+ }else
+ d= 256*256*256*32;
+ }else{
+ int uvdxy; /* no, it might not be used uninitialized */
+ if(dxy){
+ if(qpel){
+ c->qpel_put[size][dxy](c->temp, ref[0] + x + y*stride, stride); //FIXME prototype (add h)
+ if(chroma){
+ int cx= hx/2;
+ int cy= hy/2;
+ cx= (cx>>1)|(cx&1);
+ cy= (cy>>1)|(cy&1);
+ uvdxy= (cx&1) + 2*(cy&1);
+ //FIXME x/y wrong, but mpeg4 qpel is sick anyway, we should drop as much of it as possible in favor for h264
+ }
+ }else{
+ c->hpel_put[size][dxy](c->temp, ref[0] + x + y*stride, stride, h);
+ if(chroma)
+ uvdxy= dxy | (x&1) | (2*(y&1));
+ }
+ d = cmp_func(s, c->temp, src[0], stride, h);
+ }else{
+ d = cmp_func(s, src[0], ref[0] + x + y*stride, stride, h);
+ if(chroma)
+ uvdxy= (x&1) + 2*(y&1);
+ }
+ if(chroma){
+ uint8_t * const uvtemp= c->temp + 16*stride;
+ c->hpel_put[size+1][uvdxy](uvtemp , ref[1] + (x>>1) + (y>>1)*uvstride, uvstride, h>>1);
+ c->hpel_put[size+1][uvdxy](uvtemp+8, ref[2] + (x>>1) + (y>>1)*uvstride, uvstride, h>>1);
+ 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)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);
+ score_map[index]= d;
+ }
+
+ d += (c->mv_penalty[hx - c->pred_x] + c->mv_penalty[hy - c->pred_y])*c->penalty_factor;
+#endif
+ return d;
+}
+
+#include "motion_est_template.c"
+
+static int zero_cmp(void *s, uint8_t *a, uint8_t *b, int stride, int h){
+ return 0;
+}
+
+static void zero_hpel(uint8_t *a, const uint8_t *b, int stride, int h){
+}
+
+void ff_init_me(MpegEncContext *s){
+ MotionEstContext * const c= &s->me;
+ int cache_size= FFMIN(ME_MAP_SIZE>>ME_MAP_SHIFT, 1<<ME_MAP_SHIFT);
+ int dia_size= FFMAX(FFABS(s->avctx->dia_size)&255, FFABS(s->avctx->pre_dia_size)&255);
+ c->avctx= s->avctx;
+
+ if(cache_size < 2*dia_size && !c->stride){
+ av_log(s->avctx, AV_LOG_INFO, "ME_MAP size may be a little small for the selected diamond size\n");
+ }
+
+ ff_set_cmp(&s->dsp, s->dsp.me_pre_cmp, c->avctx->me_pre_cmp);
+ ff_set_cmp(&s->dsp, s->dsp.me_cmp, c->avctx->me_cmp);
+ ff_set_cmp(&s->dsp, s->dsp.me_sub_cmp, c->avctx->me_sub_cmp);
+ ff_set_cmp(&s->dsp, s->dsp.mb_cmp, c->avctx->mb_cmp);
+
+ c->flags = get_flags(c, 0, c->avctx->me_cmp &FF_CMP_CHROMA);
+ c->sub_flags= get_flags(c, 0, c->avctx->me_sub_cmp&FF_CMP_CHROMA);
+ c->mb_flags = get_flags(c, 0, c->avctx->mb_cmp &FF_CMP_CHROMA);
+
+/*FIXME s->no_rounding b_type*/
+ if(s->flags&CODEC_FLAG_QPEL){
+ c->sub_motion_search= qpel_motion_search;
+ c->qpel_avg= s->dsp.avg_qpel_pixels_tab;
+ if(s->no_rounding) c->qpel_put= s->dsp.put_no_rnd_qpel_pixels_tab;
+ else c->qpel_put= s->dsp.put_qpel_pixels_tab;
+ }else{
+ if(c->avctx->me_sub_cmp&FF_CMP_CHROMA)
+ c->sub_motion_search= hpel_motion_search;
+ else if( c->avctx->me_sub_cmp == FF_CMP_SAD
+ && c->avctx-> me_cmp == FF_CMP_SAD
+ && c->avctx-> mb_cmp == FF_CMP_SAD)
+ c->sub_motion_search= sad_hpel_motion_search; // 2050 vs. 2450 cycles
+ else
+ c->sub_motion_search= hpel_motion_search;
+ }
+ c->hpel_avg= s->dsp.avg_pixels_tab;
+ if(s->no_rounding) c->hpel_put= s->dsp.put_no_rnd_pixels_tab;
+ else c->hpel_put= s->dsp.put_pixels_tab;
+
+ if(s->linesize){
+ c->stride = s->linesize;
+ c->uvstride= s->uvlinesize;
+ }else{
+ c->stride = 16*s->mb_width + 32;
+ c->uvstride= 8*s->mb_width + 16;
+ }
+
+ // 8x8 fullpel search would need a 4x4 chroma compare, which we dont have yet, and even if we had the motion estimation code doesnt expect it
+ if(s->codec_id != CODEC_ID_SNOW){
+ if((c->avctx->me_cmp&FF_CMP_CHROMA)/* && !s->dsp.me_cmp[2]*/){
+ s->dsp.me_cmp[2]= zero_cmp;
+ }
+ if((c->avctx->me_sub_cmp&FF_CMP_CHROMA) && !s->dsp.me_sub_cmp[2]){
+ s->dsp.me_sub_cmp[2]= zero_cmp;
+ }
+ c->hpel_put[2][0]= c->hpel_put[2][1]=
+ c->hpel_put[2][2]= c->hpel_put[2][3]= zero_hpel;
+ }
+
+ if(s->codec_id == CODEC_ID_H261){
+ c->sub_motion_search= no_sub_motion_search;
+ }
+
+ c->temp= c->scratchpad;
+}
+
+#if 0
+static int pix_dev(uint8_t * pix, int line_size, int mean)
+{
+ int s, i, j;
+
+ s = 0;
+ for (i = 0; i < 16; i++) {
+ for (j = 0; j < 16; j += 8) {
+ s += FFABS(pix[0]-mean);
+ s += FFABS(pix[1]-mean);
+ s += FFABS(pix[2]-mean);
+ s += FFABS(pix[3]-mean);
+ s += FFABS(pix[4]-mean);
+ s += FFABS(pix[5]-mean);
+ s += FFABS(pix[6]-mean);
+ s += FFABS(pix[7]-mean);
+ pix += 8;
+ }
+ pix += line_size - 16;
+ }
+ return s;
+}
+#endif
+
+static inline void no_motion_search(MpegEncContext * s,
+ int *mx_ptr, int *my_ptr)
+{
+ *mx_ptr = 16 * s->mb_x;
+ *my_ptr = 16 * s->mb_y;
+}
+
+#if 0 /* the use of these functions is inside #if 0 */
+static int full_motion_search(MpegEncContext * s,
+ int *mx_ptr, int *my_ptr, int range,
+ int xmin, int ymin, int xmax, int ymax, uint8_t *ref_picture)
+{
+ int x1, y1, x2, y2, xx, yy, x, y;
+ int mx, my, dmin, d;
+ uint8_t *pix;
+
+ xx = 16 * s->mb_x;
+ yy = 16 * s->mb_y;
+ x1 = xx - range + 1; /* we loose one pixel to avoid boundary pb with half pixel pred */
+ if (x1 < xmin)
+ x1 = xmin;
+ x2 = xx + range - 1;
+ if (x2 > xmax)
+ x2 = xmax;
+ y1 = yy - range + 1;
+ if (y1 < ymin)
+ y1 = ymin;
+ y2 = yy + range - 1;
+ if (y2 > ymax)
+ y2 = ymax;
+ pix = s->new_picture.data[0] + (yy * s->linesize) + xx;
+ dmin = 0x7fffffff;
+ mx = 0;
+ my = 0;
+ for (y = y1; y <= y2; y++) {
+ for (x = x1; x <= x2; x++) {
+ d = s->dsp.pix_abs[0][0](NULL, pix, ref_picture + (y * s->linesize) + x,
+ s->linesize, 16);
+ if (d < dmin ||
+ (d == dmin &&
+ (abs(x - xx) + abs(y - yy)) <
+ (abs(mx - xx) + abs(my - yy)))) {
+ dmin = d;
+ mx = x;
+ my = y;
+ }
+ }
+ }
+
+ *mx_ptr = mx;
+ *my_ptr = my;
+
+#if 0
+ if (*mx_ptr < -(2 * range) || *mx_ptr >= (2 * range) ||
+ *my_ptr < -(2 * range) || *my_ptr >= (2 * range)) {
+ av_log(NULL, AV_LOG_ERROR, "error %d %d\n", *mx_ptr, *my_ptr);
+ }
+#endif
+ return dmin;
+}
+
+
+static int log_motion_search(MpegEncContext * s,
+ int *mx_ptr, int *my_ptr, int range,
+ int xmin, int ymin, int xmax, int ymax, uint8_t *ref_picture)
+{
+ int x1, y1, x2, y2, xx, yy, x, y;
+ int mx, my, dmin, d;
+ uint8_t *pix;
+
+ xx = s->mb_x << 4;
+ yy = s->mb_y << 4;
+
+ /* Left limit */
+ x1 = xx - range;
+ if (x1 < xmin)
+ x1 = xmin;
+
+ /* Right limit */
+ x2 = xx + range;
+ if (x2 > xmax)
+ x2 = xmax;
+
+ /* Upper limit */
+ y1 = yy - range;
+ if (y1 < ymin)
+ y1 = ymin;
+
+ /* Lower limit */
+ y2 = yy + range;
+ if (y2 > ymax)
+ y2 = ymax;
+
+ pix = s->new_picture.data[0] + (yy * s->linesize) + xx;
+ dmin = 0x7fffffff;
+ mx = 0;
+ my = 0;
+
+ do {
+ for (y = y1; y <= y2; y += range) {
+ for (x = x1; x <= x2; x += range) {
+ d = s->dsp.pix_abs[0][0](NULL, pix, ref_picture + (y * s->linesize) + x, s->linesize, 16);
+ if (d < dmin || (d == dmin && (abs(x - xx) + abs(y - yy)) < (abs(mx - xx) + abs(my - yy)))) {
+ dmin = d;
+ mx = x;
+ my = y;
+ }
+ }
+ }
+
+ range = range >> 1;
+
+ x1 = mx - range;
+ if (x1 < xmin)
+ x1 = xmin;
+
+ x2 = mx + range;
+ if (x2 > xmax)
+ x2 = xmax;
+
+ y1 = my - range;
+ if (y1 < ymin)
+ y1 = ymin;
+
+ y2 = my + range;
+ if (y2 > ymax)
+ y2 = ymax;
+
+ } while (range >= 1);
+
+#ifdef DEBUG
+ av_log(s->avctx, AV_LOG_DEBUG, "log - MX: %d\tMY: %d\n", mx, my);
+#endif
+ *mx_ptr = mx;
+ *my_ptr = my;
+ return dmin;
+}
+
+static int phods_motion_search(MpegEncContext * s,
+ int *mx_ptr, int *my_ptr, int range,
+ int xmin, int ymin, int xmax, int ymax, uint8_t *ref_picture)
+{
+ int x1, y1, x2, y2, xx, yy, x, y, lastx, d;
+ int mx, my, dminx, dminy;
+ uint8_t *pix;
+
+ xx = s->mb_x << 4;
+ yy = s->mb_y << 4;
+
+ /* Left limit */
+ x1 = xx - range;
+ if (x1 < xmin)
+ x1 = xmin;
+
+ /* Right limit */
+ x2 = xx + range;
+ if (x2 > xmax)
+ x2 = xmax;
+
+ /* Upper limit */
+ y1 = yy - range;
+ if (y1 < ymin)
+ y1 = ymin;
+
+ /* Lower limit */
+ y2 = yy + range;
+ if (y2 > ymax)
+ y2 = ymax;
+
+ pix = s->new_picture.data[0] + (yy * s->linesize) + xx;
+ mx = 0;
+ my = 0;
+
+ x = xx;
+ y = yy;
+ do {
+ dminx = 0x7fffffff;
+ dminy = 0x7fffffff;
+
+ lastx = x;
+ for (x = x1; x <= x2; x += range) {
+ d = s->dsp.pix_abs[0][0](NULL, pix, ref_picture + (y * s->linesize) + x, s->linesize, 16);
+ if (d < dminx || (d == dminx && (abs(x - xx) + abs(y - yy)) < (abs(mx - xx) + abs(my - yy)))) {
+ dminx = d;
+ mx = x;
+ }
+ }
+
+ x = lastx;
+ for (y = y1; y <= y2; y += range) {
+ d = s->dsp.pix_abs[0][0](NULL, pix, ref_picture + (y * s->linesize) + x, s->linesize, 16);
+ if (d < dminy || (d == dminy && (abs(x - xx) + abs(y - yy)) < (abs(mx - xx) + abs(my - yy)))) {
+ dminy = d;
+ my = y;
+ }
+ }
+
+ range = range >> 1;
+
+ x = mx;
+ y = my;
+ x1 = mx - range;
+ if (x1 < xmin)
+ x1 = xmin;
+
+ x2 = mx + range;
+ if (x2 > xmax)
+ x2 = xmax;
+
+ y1 = my - range;
+ if (y1 < ymin)
+ y1 = ymin;
+
+ y2 = my + range;
+ if (y2 > ymax)
+ y2 = ymax;
+
+ } while (range >= 1);
+
+#ifdef DEBUG
+ av_log(s->avctx, AV_LOG_DEBUG, "phods - MX: %d\tMY: %d\n", mx, my);
+#endif
+
+ /* half pixel search */
+ *mx_ptr = mx;
+ *my_ptr = my;
+ return dminy;
+}
+#endif /* 0 */
+
+#define Z_THRESHOLD 256
+
+#define CHECK_SAD_HALF_MV(suffix, x, y) \
+{\
+ d= s->dsp.pix_abs[size][(x?1:0)+(y?2:0)](NULL, pix, ptr+((x)>>1), stride, h);\
+ d += (mv_penalty[pen_x + x] + mv_penalty[pen_y + y])*penalty_factor;\
+ COPY3_IF_LT(dminh, d, dx, x, dy, y)\
+}
+
+static inline int sad_hpel_motion_search(MpegEncContext * s,
+ int *mx_ptr, int *my_ptr, int dmin,
+ int src_index, int ref_index,
+ int size, int h)
+{
+ MotionEstContext * const c= &s->me;
+ const int penalty_factor= c->sub_penalty_factor;
+ int mx, my, dminh;
+ uint8_t *pix, *ptr;
+ int stride= c->stride;
+ const int flags= c->sub_flags;
+ LOAD_COMMON
+
+ assert(flags == 0);
+
+ if(c->skip){
+// printf("S");
+ *mx_ptr = 0;
+ *my_ptr = 0;
+ return dmin;
+ }
+// printf("N");
+
+ pix = c->src[src_index][0];
+
+ mx = *mx_ptr;
+ my = *my_ptr;
+ ptr = c->ref[ref_index][0] + (my * stride) + mx;
+
+ dminh = dmin;
+
+ if (mx > xmin && mx < xmax &&
+ my > ymin && my < ymax) {
+ int dx=0, dy=0;
+ int d, pen_x, pen_y;
+ const int index= (my<<ME_MAP_SHIFT) + mx;
+ const int t= score_map[(index-(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)];
+ const int l= score_map[(index- 1 )&(ME_MAP_SIZE-1)];
+ const int r= score_map[(index+ 1 )&(ME_MAP_SIZE-1)];
+ const int b= score_map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)];
+ mx<<=1;
+ my<<=1;
+
+
+ pen_x= pred_x + mx;
+ pen_y= pred_y + my;
+
+ ptr-= stride;
+ if(t<=b){
+ CHECK_SAD_HALF_MV(y2 , 0, -1)
+ if(l<=r){
+ CHECK_SAD_HALF_MV(xy2, -1, -1)
+ if(t+r<=b+l){
+ CHECK_SAD_HALF_MV(xy2, +1, -1)
+ ptr+= stride;
+ }else{
+ ptr+= stride;
+ CHECK_SAD_HALF_MV(xy2, -1, +1)
+ }
+ CHECK_SAD_HALF_MV(x2 , -1, 0)
+ }else{
+ CHECK_SAD_HALF_MV(xy2, +1, -1)
+ if(t+l<=b+r){
+ CHECK_SAD_HALF_MV(xy2, -1, -1)
+ ptr+= stride;
+ }else{
+ ptr+= stride;
+ CHECK_SAD_HALF_MV(xy2, +1, +1)
+ }
+ CHECK_SAD_HALF_MV(x2 , +1, 0)
+ }
+ }else{
+ if(l<=r){
+ if(t+l<=b+r){
+ CHECK_SAD_HALF_MV(xy2, -1, -1)
+ ptr+= stride;
+ }else{
+ ptr+= stride;
+ CHECK_SAD_HALF_MV(xy2, +1, +1)
+ }
+ CHECK_SAD_HALF_MV(x2 , -1, 0)
+ CHECK_SAD_HALF_MV(xy2, -1, +1)
+ }else{
+ if(t+r<=b+l){
+ CHECK_SAD_HALF_MV(xy2, +1, -1)
+ ptr+= stride;
+ }else{
+ ptr+= stride;
+ CHECK_SAD_HALF_MV(xy2, -1, +1)
+ }
+ CHECK_SAD_HALF_MV(x2 , +1, 0)
+ CHECK_SAD_HALF_MV(xy2, +1, +1)
+ }
+ CHECK_SAD_HALF_MV(y2 , 0, +1)
+ }
+ mx+=dx;
+ my+=dy;
+
+ }else{
+ mx<<=1;
+ my<<=1;
+ }
+
+ *mx_ptr = mx;
+ *my_ptr = my;
+ return dminh;
+}
+
+static inline void set_p_mv_tables(MpegEncContext * s, int mx, int my, int mv4)
+{
+ const int xy= s->mb_x + s->mb_y*s->mb_stride;
+
+ s->p_mv_table[xy][0] = mx;
+ s->p_mv_table[xy][1] = my;
+
+ /* has already been set to the 4 MV if 4MV is done */
+ if(mv4){
+ int mot_xy= s->block_index[0];
+
+ s->current_picture.motion_val[0][mot_xy ][0]= mx;
+ s->current_picture.motion_val[0][mot_xy ][1]= my;
+ s->current_picture.motion_val[0][mot_xy+1][0]= mx;
+ s->current_picture.motion_val[0][mot_xy+1][1]= my;
+
+ mot_xy += s->b8_stride;
+ s->current_picture.motion_val[0][mot_xy ][0]= mx;
+ s->current_picture.motion_val[0][mot_xy ][1]= my;
+ s->current_picture.motion_val[0][mot_xy+1][0]= mx;
+ s->current_picture.motion_val[0][mot_xy+1][1]= my;
+ }
+}
+
+/**
+ * get fullpel ME search limits.
+ */
+static inline void get_limits(MpegEncContext *s, int x, int y)
+{
+ MotionEstContext * const c= &s->me;
+ int range= c->avctx->me_range >> (1 + !!(c->flags&FLAG_QPEL));
+/*
+ if(c->avctx->me_range) c->range= c->avctx->me_range >> 1;
+ else c->range= 16;
+*/
+ if (s->unrestricted_mv) {
+ c->xmin = - x - 16;
+ c->ymin = - y - 16;
+ c->xmax = - x + s->mb_width *16;
+ c->ymax = - y + s->mb_height*16;
+ } else if (s->out_format == FMT_H261){
+ // Search range of H261 is different from other codec standards
+ c->xmin = (x > 15) ? - 15 : 0;
+ c->ymin = (y > 15) ? - 15 : 0;
+ c->xmax = (x < s->mb_width * 16 - 16) ? 15 : 0;
+ c->ymax = (y < s->mb_height * 16 - 16) ? 15 : 0;
+ } else {
+ c->xmin = - x;
+ c->ymin = - y;
+ c->xmax = - x + s->mb_width *16 - 16;
+ c->ymax = - y + s->mb_height*16 - 16;
+ }
+ if(range){
+ c->xmin = FFMAX(c->xmin,-range);
+ c->xmax = FFMIN(c->xmax, range);
+ c->ymin = FFMAX(c->ymin,-range);
+ c->ymax = FFMIN(c->ymax, range);
+ }
+}
+
+static inline void init_mv4_ref(MotionEstContext *c){
+ const int stride= c->stride;
+
+ c->ref[1][0] = c->ref[0][0] + 8;
+ c->ref[2][0] = c->ref[0][0] + 8*stride;
+ c->ref[3][0] = c->ref[2][0] + 8;
+ c->src[1][0] = c->src[0][0] + 8;
+ c->src[2][0] = c->src[0][0] + 8*stride;
+ c->src[3][0] = c->src[2][0] + 8;
+}
+
+static inline int h263_mv4_search(MpegEncContext *s, int mx, int my, int shift)
+{
+ MotionEstContext * const c= &s->me;
+ const int size= 1;
+ const int h=8;
+ int block;
+ int P[10][2];
+ int dmin_sum=0, mx4_sum=0, my4_sum=0;
+ int same=1;
+ const int stride= c->stride;
+ uint8_t *mv_penalty= c->current_mv_penalty;
+
+ init_mv4_ref(c);
+
+ for(block=0; block<4; block++){
+ int mx4, my4;
+ int pred_x4, pred_y4;
+ int dmin4;
+ static const int off[4]= {2, 1, 1, -1};
+ const int mot_stride = s->b8_stride;
+ const int mot_xy = s->block_index[block];
+
+ P_LEFT[0] = s->current_picture.motion_val[0][mot_xy - 1][0];
+ P_LEFT[1] = s->current_picture.motion_val[0][mot_xy - 1][1];
+
+ if(P_LEFT[0] > (c->xmax<<shift)) P_LEFT[0] = (c->xmax<<shift);
+
+ /* special case for first line */
+ if (s->first_slice_line && block<2) {
+ c->pred_x= pred_x4= P_LEFT[0];
+ c->pred_y= pred_y4= P_LEFT[1];
+ } else {
+ P_TOP[0] = s->current_picture.motion_val[0][mot_xy - mot_stride ][0];
+ P_TOP[1] = s->current_picture.motion_val[0][mot_xy - mot_stride ][1];
+ P_TOPRIGHT[0] = s->current_picture.motion_val[0][mot_xy - mot_stride + off[block]][0];
+ P_TOPRIGHT[1] = s->current_picture.motion_val[0][mot_xy - mot_stride + off[block]][1];
+ if(P_TOP[1] > (c->ymax<<shift)) P_TOP[1] = (c->ymax<<shift);
+ if(P_TOPRIGHT[0] < (c->xmin<<shift)) P_TOPRIGHT[0]= (c->xmin<<shift);
+ if(P_TOPRIGHT[0] > (c->xmax<<shift)) P_TOPRIGHT[0]= (c->xmax<<shift);
+ if(P_TOPRIGHT[1] > (c->ymax<<shift)) P_TOPRIGHT[1]= (c->ymax<<shift);
+
+ P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
+ P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);
+
+ c->pred_x= pred_x4 = P_MEDIAN[0];
+ c->pred_y= pred_y4 = P_MEDIAN[1];
+ }
+ P_MV1[0]= mx;
+ P_MV1[1]= my;
+
+ dmin4 = epzs_motion_search4(s, &mx4, &my4, P, block, block, s->p_mv_table, (1<<16)>>shift);
+
+ dmin4= c->sub_motion_search(s, &mx4, &my4, dmin4, block, block, size, h);
+
+ if(s->dsp.me_sub_cmp[0] != s->dsp.mb_cmp[0]){
+ int dxy;
+ const int offset= ((block&1) + (block>>1)*stride)*8;
+ uint8_t *dest_y = c->scratchpad + offset;
+ if(s->quarter_sample){
+ uint8_t *ref= c->ref[block][0] + (mx4>>2) + (my4>>2)*stride;
+ dxy = ((my4 & 3) << 2) | (mx4 & 3);
+
+ if(s->no_rounding)
+ s->dsp.put_no_rnd_qpel_pixels_tab[1][dxy](dest_y , ref , stride);
+ else
+ s->dsp.put_qpel_pixels_tab [1][dxy](dest_y , ref , stride);
+ }else{
+ uint8_t *ref= c->ref[block][0] + (mx4>>1) + (my4>>1)*stride;
+ dxy = ((my4 & 1) << 1) | (mx4 & 1);
+
+ if(s->no_rounding)
+ s->dsp.put_no_rnd_pixels_tab[1][dxy](dest_y , ref , stride, h);
+ else
+ s->dsp.put_pixels_tab [1][dxy](dest_y , ref , stride, h);
+ }
+ dmin_sum+= (mv_penalty[mx4-pred_x4] + mv_penalty[my4-pred_y4])*c->mb_penalty_factor;
+ }else
+ dmin_sum+= dmin4;
+
+ if(s->quarter_sample){
+ mx4_sum+= mx4/2;
+ my4_sum+= my4/2;
+ }else{
+ mx4_sum+= mx4;
+ my4_sum+= my4;
+ }
+
+ s->current_picture.motion_val[0][ s->block_index[block] ][0]= mx4;
+ s->current_picture.motion_val[0][ s->block_index[block] ][1]= my4;
+
+ if(mx4 != mx || my4 != my) same=0;
+ }
+
+ if(same)
+ return INT_MAX;
+
+ if(s->dsp.me_sub_cmp[0] != s->dsp.mb_cmp[0]){
+ dmin_sum += s->dsp.mb_cmp[0](s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*16*stride, c->scratchpad, stride, 16);
+ }
+
+ if(c->avctx->mb_cmp&FF_CMP_CHROMA){
+ int dxy;
+ int mx, my;
+ int offset;
+
+ mx= ff_h263_round_chroma(mx4_sum);
+ my= ff_h263_round_chroma(my4_sum);
+ dxy = ((my & 1) << 1) | (mx & 1);
+
+ offset= (s->mb_x*8 + (mx>>1)) + (s->mb_y*8 + (my>>1))*s->uvlinesize;
+
+ if(s->no_rounding){
+ s->dsp.put_no_rnd_pixels_tab[1][dxy](c->scratchpad , s->last_picture.data[1] + offset, s->uvlinesize, 8);
+ s->dsp.put_no_rnd_pixels_tab[1][dxy](c->scratchpad+8 , s->last_picture.data[2] + offset, s->uvlinesize, 8);
+ }else{
+ s->dsp.put_pixels_tab [1][dxy](c->scratchpad , s->last_picture.data[1] + offset, s->uvlinesize, 8);
+ s->dsp.put_pixels_tab [1][dxy](c->scratchpad+8 , s->last_picture.data[2] + offset, s->uvlinesize, 8);
+ }
+
+ dmin_sum += s->dsp.mb_cmp[1](s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*8*s->uvlinesize, c->scratchpad , s->uvlinesize, 8);
+ dmin_sum += s->dsp.mb_cmp[1](s, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*8*s->uvlinesize, c->scratchpad+8, s->uvlinesize, 8);
+ }
+
+ c->pred_x= mx;
+ c->pred_y= my;
+
+ switch(c->avctx->mb_cmp&0xFF){
+ /*case FF_CMP_SSE:
+ return dmin_sum+ 32*s->qscale*s->qscale;*/
+ case FF_CMP_RD:
+ return dmin_sum;
+ default:
+ return dmin_sum+ 11*c->mb_penalty_factor;
+ }
+}
+
+static inline void init_interlaced_ref(MpegEncContext *s, int ref_index){
+ MotionEstContext * const c= &s->me;
+
+ c->ref[1+ref_index][0] = c->ref[0+ref_index][0] + s->linesize;
+ c->src[1][0] = c->src[0][0] + s->linesize;
+ if(c->flags & FLAG_CHROMA){
+ c->ref[1+ref_index][1] = c->ref[0+ref_index][1] + s->uvlinesize;
+ c->ref[1+ref_index][2] = c->ref[0+ref_index][2] + s->uvlinesize;
+ c->src[1][1] = c->src[0][1] + s->uvlinesize;
+ c->src[1][2] = c->src[0][2] + s->uvlinesize;
+ }
+}
+
+static int interlaced_search(MpegEncContext *s, int ref_index,
+ int16_t (*mv_tables[2][2])[2], uint8_t *field_select_tables[2], int mx, int my, int user_field_select)
+{
+ MotionEstContext * const c= &s->me;
+ const int size=0;
+ const int h=8;
+ int block;
+ int P[10][2];
+ uint8_t * const mv_penalty= c->current_mv_penalty;
+ int same=1;
+ const int stride= 2*s->linesize;
+ int dmin_sum= 0;
+ const int mot_stride= s->mb_stride;
+ const int xy= s->mb_x + s->mb_y*mot_stride;
+
+ c->ymin>>=1;
+ c->ymax>>=1;
+ c->stride<<=1;
+ c->uvstride<<=1;
+ init_interlaced_ref(s, ref_index);
+
+ for(block=0; block<2; block++){
+ int field_select;
+ int best_dmin= INT_MAX;
+ int best_field= -1;
+
+ for(field_select=0; field_select<2; field_select++){
+ int dmin, mx_i, my_i;
+ int16_t (*mv_table)[2]= mv_tables[block][field_select];
+
+ if(user_field_select){
+ assert(field_select==0 || field_select==1);
+ assert(field_select_tables[block][xy]==0 || field_select_tables[block][xy]==1);
+ if(field_select_tables[block][xy] != field_select)
+ continue;
+ }
+
+ P_LEFT[0] = mv_table[xy - 1][0];
+ P_LEFT[1] = mv_table[xy - 1][1];
+ if(P_LEFT[0] > (c->xmax<<1)) P_LEFT[0] = (c->xmax<<1);
+
+ c->pred_x= P_LEFT[0];
+ c->pred_y= P_LEFT[1];
+
+ if(!s->first_slice_line){
+ P_TOP[0] = mv_table[xy - mot_stride][0];
+ P_TOP[1] = mv_table[xy - mot_stride][1];
+ P_TOPRIGHT[0] = mv_table[xy - mot_stride + 1][0];
+ P_TOPRIGHT[1] = mv_table[xy - mot_stride + 1][1];
+ if(P_TOP[1] > (c->ymax<<1)) P_TOP[1] = (c->ymax<<1);
+ if(P_TOPRIGHT[0] < (c->xmin<<1)) P_TOPRIGHT[0]= (c->xmin<<1);
+ if(P_TOPRIGHT[0] > (c->xmax<<1)) P_TOPRIGHT[0]= (c->xmax<<1);
+ if(P_TOPRIGHT[1] > (c->ymax<<1)) P_TOPRIGHT[1]= (c->ymax<<1);
+
+ P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
+ P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);
+ }
+ P_MV1[0]= mx; //FIXME not correct if block != field_select
+ P_MV1[1]= my / 2;
+
+ dmin = epzs_motion_search2(s, &mx_i, &my_i, P, block, field_select+ref_index, mv_table, (1<<16)>>1);
+
+ dmin= c->sub_motion_search(s, &mx_i, &my_i, dmin, block, field_select+ref_index, size, h);
+
+ mv_table[xy][0]= mx_i;
+ mv_table[xy][1]= my_i;
+
+ if(s->dsp.me_sub_cmp[0] != s->dsp.mb_cmp[0]){
+ int dxy;
+
+ //FIXME chroma ME
+ uint8_t *ref= c->ref[field_select+ref_index][0] + (mx_i>>1) + (my_i>>1)*stride;
+ dxy = ((my_i & 1) << 1) | (mx_i & 1);
+
+ if(s->no_rounding){
+ s->dsp.put_no_rnd_pixels_tab[size][dxy](c->scratchpad, ref , stride, h);
+ }else{
+ s->dsp.put_pixels_tab [size][dxy](c->scratchpad, ref , stride, h);
+ }
+ dmin= s->dsp.mb_cmp[size](s, c->src[block][0], c->scratchpad, stride, h);
+ dmin+= (mv_penalty[mx_i-c->pred_x] + mv_penalty[my_i-c->pred_y] + 1)*c->mb_penalty_factor;
+ }else
+ dmin+= c->mb_penalty_factor; //field_select bits
+
+ dmin += field_select != block; //slightly prefer same field
+
+ if(dmin < best_dmin){
+ best_dmin= dmin;
+ best_field= field_select;
+ }
+ }
+ {
+ int16_t (*mv_table)[2]= mv_tables[block][best_field];
+
+ if(mv_table[xy][0] != mx) same=0; //FIXME check if these checks work and are any good at all
+ if(mv_table[xy][1]&1) same=0;
+ if(mv_table[xy][1]*2 != my) same=0;
+ if(best_field != block) same=0;
+ }
+
+ field_select_tables[block][xy]= best_field;
+ dmin_sum += best_dmin;
+ }
+
+ c->ymin<<=1;
+ c->ymax<<=1;
+ c->stride>>=1;
+ c->uvstride>>=1;
+
+ if(same)
+ return INT_MAX;
+
+ switch(c->avctx->mb_cmp&0xFF){
+ /*case FF_CMP_SSE:
+ return dmin_sum+ 32*s->qscale*s->qscale;*/
+ case FF_CMP_RD:
+ return dmin_sum;
+ default:
+ return dmin_sum+ 11*c->mb_penalty_factor;
+ }
+}
+
+static void clip_input_mv(MpegEncContext * s, int16_t *mv, int interlaced){
+ int ymax= s->me.ymax>>interlaced;
+ int ymin= s->me.ymin>>interlaced;
+
+ if(mv[0] < s->me.xmin) mv[0] = s->me.xmin;
+ if(mv[0] > s->me.xmax) mv[0] = s->me.xmax;
+ if(mv[1] < ymin) mv[1] = ymin;
+ if(mv[1] > ymax) mv[1] = ymax;
+}
+
+static inline int check_input_motion(MpegEncContext * s, int mb_x, int mb_y, int p_type){
+ MotionEstContext * const c= &s->me;
+ Picture *p= s->current_picture_ptr;
+ int mb_xy= mb_x + mb_y*s->mb_stride;
+ int xy= 2*mb_x + 2*mb_y*s->b8_stride;
+ int mb_type= s->current_picture.mb_type[mb_xy];
+ int flags= c->flags;
+ int shift= (flags&FLAG_QPEL) + 1;
+ int mask= (1<<shift)-1;
+ int x, y, i;
+ int d=0;
+ me_cmp_func cmpf= s->dsp.sse[0];
+ me_cmp_func chroma_cmpf= s->dsp.sse[1];
+
+ if(p_type && USES_LIST(mb_type, 1)){
+ av_log(c->avctx, AV_LOG_ERROR, "backward motion vector in P frame\n");
+ return INT_MAX/2;
+ }
+ assert(IS_INTRA(mb_type) || USES_LIST(mb_type,0) || USES_LIST(mb_type,1));
+
+ for(i=0; i<4; i++){
+ int xy= s->block_index[i];
+ clip_input_mv(s, p->motion_val[0][xy], !!IS_INTERLACED(mb_type));
+ clip_input_mv(s, p->motion_val[1][xy], !!IS_INTERLACED(mb_type));
+ }
+
+ if(IS_INTERLACED(mb_type)){
+ int xy2= xy + s->b8_stride;
+ s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTRA;
+ c->stride<<=1;
+ c->uvstride<<=1;
+
+ if(!(s->flags & CODEC_FLAG_INTERLACED_ME)){
+ av_log(c->avctx, AV_LOG_ERROR, "Interlaced macroblock selected but interlaced motion estimation disabled\n");
+ return INT_MAX/2;
+ }
+
+ if(USES_LIST(mb_type, 0)){
+ int field_select0= p->ref_index[0][xy ];
+ int field_select1= p->ref_index[0][xy2];
+ assert(field_select0==0 ||field_select0==1);
+ assert(field_select1==0 ||field_select1==1);
+ init_interlaced_ref(s, 0);
+
+ if(p_type){
+ s->p_field_select_table[0][mb_xy]= field_select0;
+ s->p_field_select_table[1][mb_xy]= field_select1;
+ *(uint32_t*)s->p_field_mv_table[0][field_select0][mb_xy]= *(uint32_t*)p->motion_val[0][xy ];
+ *(uint32_t*)s->p_field_mv_table[1][field_select1][mb_xy]= *(uint32_t*)p->motion_val[0][xy2];
+ s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTER_I;
+ }else{
+ s->b_field_select_table[0][0][mb_xy]= field_select0;
+ s->b_field_select_table[0][1][mb_xy]= field_select1;
+ *(uint32_t*)s->b_field_mv_table[0][0][field_select0][mb_xy]= *(uint32_t*)p->motion_val[0][xy ];
+ *(uint32_t*)s->b_field_mv_table[0][1][field_select1][mb_xy]= *(uint32_t*)p->motion_val[0][xy2];
+ s->mb_type[mb_xy]= CANDIDATE_MB_TYPE_FORWARD_I;
+ }
+
+ x= p->motion_val[0][xy ][0];
+ y= p->motion_val[0][xy ][1];
+ d = cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 8, field_select0, 0, cmpf, chroma_cmpf, flags);
+ x= p->motion_val[0][xy2][0];
+ y= p->motion_val[0][xy2][1];
+ 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];
+ assert(field_select0==0 ||field_select0==1);
+ assert(field_select1==0 ||field_select1==1);
+ init_interlaced_ref(s, 2);
+
+ s->b_field_select_table[1][0][mb_xy]= field_select0;
+ s->b_field_select_table[1][1][mb_xy]= field_select1;
+ *(uint32_t*)s->b_field_mv_table[1][0][field_select0][mb_xy]= *(uint32_t*)p->motion_val[1][xy ];
+ *(uint32_t*)s->b_field_mv_table[1][1][field_select1][mb_xy]= *(uint32_t*)p->motion_val[1][xy2];
+ if(USES_LIST(mb_type, 0)){
+ s->mb_type[mb_xy]= CANDIDATE_MB_TYPE_BIDIR_I;
+ }else{
+ s->mb_type[mb_xy]= CANDIDATE_MB_TYPE_BACKWARD_I;
+ }
+
+ x= p->motion_val[1][xy ][0];
+ y= p->motion_val[1][xy ][1];
+ d = cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 8, field_select0+2, 0, cmpf, chroma_cmpf, flags);
+ x= p->motion_val[1][xy2][0];
+ y= p->motion_val[1][xy2][1];
+ d+= cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 8, field_select1+2, 1, cmpf, chroma_cmpf, flags);
+ //FIXME bidir scores
+ }
+ c->stride>>=1;
+ c->uvstride>>=1;
+ }else if(IS_8X8(mb_type)){
+ if(!(s->flags & CODEC_FLAG_4MV)){
+ av_log(c->avctx, AV_LOG_ERROR, "4MV macroblock selected but 4MV encoding disabled\n");
+ return INT_MAX/2;
+ }
+ cmpf= s->dsp.sse[1];
+ chroma_cmpf= s->dsp.sse[1];
+ init_mv4_ref(c);
+ for(i=0; i<4; i++){
+ xy= s->block_index[i];
+ x= p->motion_val[0][xy][0];
+ y= p->motion_val[0][xy][1];
+ d+= cmp(s, x>>shift, y>>shift, x&mask, y&mask, 1, 8, i, i, cmpf, chroma_cmpf, flags);
+ }
+ s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTER4V;
+ }else{
+ if(USES_LIST(mb_type, 0)){
+ if(p_type){
+ *(uint32_t*)s->p_mv_table[mb_xy]= *(uint32_t*)p->motion_val[0][xy];
+ s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTER;
+ }else if(USES_LIST(mb_type, 1)){
+ *(uint32_t*)s->b_bidir_forw_mv_table[mb_xy]= *(uint32_t*)p->motion_val[0][xy];
+ *(uint32_t*)s->b_bidir_back_mv_table[mb_xy]= *(uint32_t*)p->motion_val[1][xy];
+ s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_BIDIR;
+ }else{
+ *(uint32_t*)s->b_forw_mv_table[mb_xy]= *(uint32_t*)p->motion_val[0][xy];
+ s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_FORWARD;
+ }
+ x= p->motion_val[0][xy][0];
+ y= p->motion_val[0][xy][1];
+ d = cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 16, 0, 0, cmpf, chroma_cmpf, flags);
+ }else if(USES_LIST(mb_type, 1)){
+ *(uint32_t*)s->b_back_mv_table[mb_xy]= *(uint32_t*)p->motion_val[1][xy];
+ s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_BACKWARD;
+
+ x= p->motion_val[1][xy][0];
+ y= p->motion_val[1][xy][1];
+ d = cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 16, 2, 0, cmpf, chroma_cmpf, flags);
+ }else
+ s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTRA;
+ }
+ return d;
+}
+
+void ff_estimate_p_frame_motion(MpegEncContext * s,
+ int mb_x, int mb_y)
+{
+ MotionEstContext * const c= &s->me;
+ uint8_t *pix, *ppix;
+ int sum, mx, my, dmin;
+ int varc; ///< the variance of the block (sum of squared (p[y][x]-average))
+ int vard; ///< sum of squared differences with the estimated motion vector
+ int P[10][2];
+ const int shift= 1+s->quarter_sample;
+ int mb_type=0;
+ Picture * const pic= &s->current_picture;
+
+ init_ref(c, s->new_picture.data, s->last_picture.data, NULL, 16*mb_x, 16*mb_y, 0);
+
+ assert(s->quarter_sample==0 || s->quarter_sample==1);
+ assert(s->linesize == c->stride);
+ assert(s->uvlinesize == c->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->f_code] + MAX_MV;
+
+ get_limits(s, 16*mb_x, 16*mb_y);
+ c->skip=0;
+
+ /* intra / predictive decision */
+ pix = c->src[0][0];
+ sum = s->dsp.pix_sum(pix, s->linesize);
+ varc = s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)(sum*sum))>>8) + 500;
+
+ pic->mb_mean[s->mb_stride * mb_y + mb_x] = (sum+128)>>8;
+ pic->mb_var [s->mb_stride * mb_y + mb_x] = (varc+128)>>8;
+ c->mb_var_sum_temp += (varc+128)>>8;
+
+ if(c->avctx->me_threshold){
+ vard= check_input_motion(s, mb_x, mb_y, 1);
+
+ if((vard+128)>>8 < c->avctx->me_threshold){
+ int p_score= FFMIN(vard, varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*100);
+ int i_score= varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*20;
+ pic->mc_mb_var[s->mb_stride * mb_y + mb_x] = (vard+128)>>8;
+ c->mc_mb_var_sum_temp += (vard+128)>>8;
+ c->scene_change_score+= ff_sqrt(p_score) - ff_sqrt(i_score);
+ return;
+ }
+ if((vard+128)>>8 < c->avctx->mb_threshold)
+ mb_type= s->mb_type[mb_x + mb_y*s->mb_stride];
+ }
+
+ switch(s->me_method) {
+ case ME_ZERO:
+ default:
+ no_motion_search(s, &mx, &my);
+ mx-= mb_x*16;
+ my-= mb_y*16;
+ dmin = 0;
+ break;
+#if 0
+ case ME_FULL:
+ dmin = full_motion_search(s, &mx, &my, range, ref_picture);
+ mx-= mb_x*16;
+ my-= mb_y*16;
+ break;
+ case ME_LOG:
+ dmin = log_motion_search(s, &mx, &my, range / 2, ref_picture);
+ mx-= mb_x*16;
+ my-= mb_y*16;
+ break;
+ case ME_PHODS:
+ dmin = phods_motion_search(s, &mx, &my, range / 2, ref_picture);
+ mx-= mb_x*16;
+ my-= mb_y*16;
+ break;
+#endif
+ case ME_X1:
+ case ME_EPZS:
+ {
+ const int mot_stride = s->b8_stride;
+ const int mot_xy = s->block_index[0];
+
+ P_LEFT[0] = s->current_picture.motion_val[0][mot_xy - 1][0];
+ P_LEFT[1] = s->current_picture.motion_val[0][mot_xy - 1][1];
+
+ if(P_LEFT[0] > (c->xmax<<shift)) P_LEFT[0] = (c->xmax<<shift);
+
+ if(!s->first_slice_line) {
+ P_TOP[0] = s->current_picture.motion_val[0][mot_xy - mot_stride ][0];
+ P_TOP[1] = s->current_picture.motion_val[0][mot_xy - mot_stride ][1];
+ P_TOPRIGHT[0] = s->current_picture.motion_val[0][mot_xy - mot_stride + 2][0];
+ P_TOPRIGHT[1] = s->current_picture.motion_val[0][mot_xy - mot_stride + 2][1];
+ if(P_TOP[1] > (c->ymax<<shift)) P_TOP[1] = (c->ymax<<shift);
+ if(P_TOPRIGHT[0] < (c->xmin<<shift)) P_TOPRIGHT[0]= (c->xmin<<shift);
+ if(P_TOPRIGHT[1] > (c->ymax<<shift)) P_TOPRIGHT[1]= (c->ymax<<shift);
+
+ P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
+ P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);
+
+ if(s->out_format == FMT_H263){
+ c->pred_x = P_MEDIAN[0];
+ c->pred_y = P_MEDIAN[1];
+ }else { /* mpeg1 at least */
+ c->pred_x= P_LEFT[0];
+ c->pred_y= P_LEFT[1];
+ }
+ }else{
+ c->pred_x= P_LEFT[0];
+ c->pred_y= P_LEFT[1];
+ }
+
+ }
+ dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, 0, s->p_mv_table, (1<<16)>>shift, 0, 16);
+
+ break;
+ }
+
+ /* At this point (mx,my) are full-pell and the relative displacement */
+ ppix = c->ref[0][0] + (my * s->linesize) + mx;
+
+ vard = s->dsp.sse[0](NULL, pix, ppix, s->linesize, 16);
+
+ pic->mc_mb_var[s->mb_stride * mb_y + mb_x] = (vard+128)>>8;
+// pic->mb_cmp_score[s->mb_stride * mb_y + mb_x] = dmin;
+ c->mc_mb_var_sum_temp += (vard+128)>>8;
+
+#if 0
+ printf("varc=%4d avg_var=%4d (sum=%4d) vard=%4d mx=%2d my=%2d\n",
+ varc, s->avg_mb_var, sum, vard, mx - xx, my - yy);
+#endif
+ if(mb_type){
+ int p_score= FFMIN(vard, varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*100);
+ int i_score= varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*20;
+ c->scene_change_score+= ff_sqrt(p_score) - ff_sqrt(i_score);
+
+ if(mb_type == CANDIDATE_MB_TYPE_INTER){
+ c->sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);
+ set_p_mv_tables(s, mx, my, 1);
+ }else{
+ mx <<=shift;
+ my <<=shift;
+ }
+ if(mb_type == CANDIDATE_MB_TYPE_INTER4V){
+ h263_mv4_search(s, mx, my, shift);
+
+ set_p_mv_tables(s, mx, my, 0);
+ }
+ if(mb_type == CANDIDATE_MB_TYPE_INTER_I){
+ interlaced_search(s, 0, s->p_field_mv_table, s->p_field_select_table, mx, my, 1);
+ }
+ }else if(c->avctx->mb_decision > FF_MB_DECISION_SIMPLE){
+ int p_score= FFMIN(vard, varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*100);
+ int i_score= varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*20;
+ c->scene_change_score+= ff_sqrt(p_score) - ff_sqrt(i_score);
+
+ if (vard*2 + 200*256 > varc)
+ mb_type|= CANDIDATE_MB_TYPE_INTRA;
+ if (varc*2 + 200*256 > vard || s->qscale > 24){
+// if (varc*2 + 200*256 + 50*(s->lambda2>>FF_LAMBDA_SHIFT) > vard){
+ mb_type|= CANDIDATE_MB_TYPE_INTER;
+ c->sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);
+ if(s->flags&CODEC_FLAG_MV0)
+ if(mx || my)
+ mb_type |= CANDIDATE_MB_TYPE_SKIPPED; //FIXME check difference
+ }else{
+ mx <<=shift;
+ my <<=shift;
+ }
+ if((s->flags&CODEC_FLAG_4MV)
+ && !c->skip && varc>50<<8 && vard>10<<8){
+ if(h263_mv4_search(s, mx, my, shift) < INT_MAX)
+ mb_type|=CANDIDATE_MB_TYPE_INTER4V;
+
+ set_p_mv_tables(s, mx, my, 0);
+ }else
+ set_p_mv_tables(s, mx, my, 1);
+ if((s->flags&CODEC_FLAG_INTERLACED_ME)
+ && !c->skip){ //FIXME varc/d checks
+ if(interlaced_search(s, 0, s->p_field_mv_table, s->p_field_select_table, mx, my, 0) < INT_MAX)
+ mb_type |= CANDIDATE_MB_TYPE_INTER_I;
+ }
+ }else{
+ int intra_score, i;
+ mb_type= CANDIDATE_MB_TYPE_INTER;
+
+ dmin= c->sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);
+ if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip)
+ dmin= ff_get_mb_score(s, mx, my, 0, 0, 0, 16, 1);
+
+ if((s->flags&CODEC_FLAG_4MV)
+ && !c->skip && varc>50<<8 && vard>10<<8){
+ int dmin4= h263_mv4_search(s, mx, my, shift);
+ if(dmin4 < dmin){
+ mb_type= CANDIDATE_MB_TYPE_INTER4V;
+ dmin=dmin4;
+ }
+ }
+ if((s->flags&CODEC_FLAG_INTERLACED_ME)
+ && !c->skip){ //FIXME varc/d checks
+ int dmin_i= interlaced_search(s, 0, s->p_field_mv_table, s->p_field_select_table, mx, my, 0);
+ if(dmin_i < dmin){
+ mb_type = CANDIDATE_MB_TYPE_INTER_I;
+ dmin= dmin_i;
+ }
+ }
+
+// pic->mb_cmp_score[s->mb_stride * mb_y + mb_x] = dmin;
+ set_p_mv_tables(s, mx, my, mb_type!=CANDIDATE_MB_TYPE_INTER4V);
+
+ /* get intra luma score */
+ if((c->avctx->mb_cmp&0xFF)==FF_CMP_SSE){
+ intra_score= varc - 500;
+ }else{
+ int mean= (sum+128)>>8;
+ mean*= 0x01010101;
+
+ for(i=0; i<16; i++){
+ *(uint32_t*)(&c->scratchpad[i*s->linesize+ 0]) = mean;
+ *(uint32_t*)(&c->scratchpad[i*s->linesize+ 4]) = mean;
+ *(uint32_t*)(&c->scratchpad[i*s->linesize+ 8]) = mean;
+ *(uint32_t*)(&c->scratchpad[i*s->linesize+12]) = mean;
+ }
+
+ intra_score= s->dsp.mb_cmp[0](s, c->scratchpad, pix, s->linesize, 16);
+ }
+#if 0 //FIXME
+ /* get chroma score */
+ if(c->avctx->mb_cmp&FF_CMP_CHROMA){
+ for(i=1; i<3; i++){
+ uint8_t *dest_c;
+ int mean;
+
+ if(s->out_format == FMT_H263){
+ mean= (s->dc_val[i][mb_x + mb_y*s->b8_stride] + 4)>>3; //FIXME not exact but simple ;)
+ }else{
+ mean= (s->last_dc[i] + 4)>>3;
+ }
+ dest_c = s->new_picture.data[i] + (mb_y * 8 * (s->uvlinesize)) + mb_x * 8;
+
+ mean*= 0x01010101;
+ for(i=0; i<8; i++){
+ *(uint32_t*)(&c->scratchpad[i*s->uvlinesize+ 0]) = mean;
+ *(uint32_t*)(&c->scratchpad[i*s->uvlinesize+ 4]) = mean;
+ }
+
+ intra_score+= s->dsp.mb_cmp[1](s, c->scratchpad, dest_c, s->uvlinesize);
+ }
+ }
+#endif
+ intra_score += c->mb_penalty_factor*16;
+
+ if(intra_score < dmin){
+ mb_type= CANDIDATE_MB_TYPE_INTRA;
+ s->current_picture.mb_type[mb_y*s->mb_stride + mb_x]= CANDIDATE_MB_TYPE_INTRA; //FIXME cleanup
+ }else
+ s->current_picture.mb_type[mb_y*s->mb_stride + mb_x]= 0;
+
+ {
+ int p_score= FFMIN(vard, varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*100);
+ int i_score= varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*20;
+ c->scene_change_score+= ff_sqrt(p_score) - ff_sqrt(i_score);
+ }
+ }
+
+ s->mb_type[mb_y*s->mb_stride + mb_x]= mb_type;
+}
+
+int ff_pre_estimate_p_frame_motion(MpegEncContext * s,
+ int mb_x, int mb_y)
+{
+ MotionEstContext * const c= &s->me;
+ int mx, my, dmin;
+ int P[10][2];
+ const int shift= 1+s->quarter_sample;
+ const int xy= mb_x + mb_y*s->mb_stride;
+ init_ref(c, s->new_picture.data, s->last_picture.data, NULL, 16*mb_x, 16*mb_y, 0);
+
+ assert(s->quarter_sample==0 || s->quarter_sample==1);
+
+ c->pre_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_pre_cmp);
+ c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_MV;
+
+ get_limits(s, 16*mb_x, 16*mb_y);
+ c->skip=0;
+
+ P_LEFT[0] = s->p_mv_table[xy + 1][0];
+ P_LEFT[1] = s->p_mv_table[xy + 1][1];
+
+ if(P_LEFT[0] < (c->xmin<<shift)) P_LEFT[0] = (c->xmin<<shift);
+
+ /* special case for first line */
+ if (s->first_slice_line) {
+ c->pred_x= P_LEFT[0];
+ c->pred_y= P_LEFT[1];
+ P_TOP[0]= P_TOPRIGHT[0]= P_MEDIAN[0]=
+ P_TOP[1]= P_TOPRIGHT[1]= P_MEDIAN[1]= 0; //FIXME
+ } else {
+ P_TOP[0] = s->p_mv_table[xy + s->mb_stride ][0];
+ P_TOP[1] = s->p_mv_table[xy + s->mb_stride ][1];
+ P_TOPRIGHT[0] = s->p_mv_table[xy + s->mb_stride - 1][0];
+ P_TOPRIGHT[1] = s->p_mv_table[xy + s->mb_stride - 1][1];
+ if(P_TOP[1] < (c->ymin<<shift)) P_TOP[1] = (c->ymin<<shift);
+ if(P_TOPRIGHT[0] > (c->xmax<<shift)) P_TOPRIGHT[0]= (c->xmax<<shift);
+ if(P_TOPRIGHT[1] < (c->ymin<<shift)) P_TOPRIGHT[1]= (c->ymin<<shift);
+
+ P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
+ P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);
+
+ c->pred_x = P_MEDIAN[0];
+ c->pred_y = P_MEDIAN[1];
+ }
+
+ dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, 0, s->p_mv_table, (1<<16)>>shift, 0, 16);
+
+ s->p_mv_table[xy][0] = mx<<shift;
+ s->p_mv_table[xy][1] = my<<shift;
+
+ return dmin;
+}
+
+static int ff_estimate_motion_b(MpegEncContext * s,
+ int mb_x, int mb_y, int16_t (*mv_table)[2], int ref_index, int f_code)
+{
+ MotionEstContext * const c= &s->me;
+ int mx, my, dmin;
+ int P[10][2];
+ const int shift= 1+s->quarter_sample;
+ const int mot_stride = s->mb_stride;
+ const int mot_xy = mb_y*mot_stride + mb_x;
+ uint8_t * const mv_penalty= c->mv_penalty[f_code] + MAX_MV;
+ int mv_scale;
+
+ 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= mv_penalty;
+
+ get_limits(s, 16*mb_x, 16*mb_y);
+
+ switch(s->me_method) {
+ case ME_ZERO:
+ default:
+ no_motion_search(s, &mx, &my);
+ dmin = 0;
+ mx-= mb_x*16;
+ my-= mb_y*16;
+ break;
+#if 0
+ case ME_FULL:
+ dmin = full_motion_search(s, &mx, &my, range, ref_picture);
+ mx-= mb_x*16;
+ my-= mb_y*16;
+ break;
+ case ME_LOG:
+ dmin = log_motion_search(s, &mx, &my, range / 2, ref_picture);
+ mx-= mb_x*16;
+ my-= mb_y*16;
+ break;
+ case ME_PHODS:
+ dmin = phods_motion_search(s, &mx, &my, range / 2, ref_picture);
+ mx-= mb_x*16;
+ my-= mb_y*16;
+ break;
+#endif
+ case ME_X1:
+ case ME_EPZS:
+ {
+ P_LEFT[0] = mv_table[mot_xy - 1][0];
+ P_LEFT[1] = mv_table[mot_xy - 1][1];
+
+ if(P_LEFT[0] > (c->xmax<<shift)) P_LEFT[0] = (c->xmax<<shift);
+
+ /* special case for first line */
+ if (!s->first_slice_line) {
+ P_TOP[0] = mv_table[mot_xy - mot_stride ][0];
+ P_TOP[1] = mv_table[mot_xy - mot_stride ][1];
+ P_TOPRIGHT[0] = mv_table[mot_xy - mot_stride + 1 ][0];
+ P_TOPRIGHT[1] = mv_table[mot_xy - mot_stride + 1 ][1];
+ if(P_TOP[1] > (c->ymax<<shift)) P_TOP[1]= (c->ymax<<shift);
+ if(P_TOPRIGHT[0] < (c->xmin<<shift)) P_TOPRIGHT[0]= (c->xmin<<shift);
+ if(P_TOPRIGHT[1] > (c->ymax<<shift)) P_TOPRIGHT[1]= (c->ymax<<shift);
+
+ P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
+ P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);
+ }
+ c->pred_x= P_LEFT[0];
+ c->pred_y= P_LEFT[1];
+ }
+
+ if(mv_table == s->b_forw_mv_table){
+ mv_scale= (s->pb_time<<16) / (s->pp_time<<shift);
+ }else{
+ mv_scale= ((s->pb_time - s->pp_time)<<16) / (s->pp_time<<shift);
+ }
+
+ dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, ref_index, s->p_mv_table, mv_scale, 0, 16);
+
+ break;
+ }
+
+ dmin= c->sub_motion_search(s, &mx, &my, dmin, 0, ref_index, 0, 16);
+
+ if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip)
+ dmin= ff_get_mb_score(s, mx, my, 0, ref_index, 0, 16, 1);
+
+//printf("%d %d %d %d//", s->mb_x, s->mb_y, mx, my);
+// s->mb_type[mb_y*s->mb_width + mb_x]= mb_type;
+ mv_table[mot_xy][0]= mx;
+ mv_table[mot_xy][1]= my;
+
+ return dmin;
+}
+
+static inline int check_bidir_mv(MpegEncContext * s,
+ int motion_fx, int motion_fy,
+ int motion_bx, int motion_by,
+ int pred_fx, int pred_fy,
+ int pred_bx, int pred_by,
+ int size, int h)
+{
+ //FIXME optimize?
+ //FIXME better f_code prediction (max mv & distance)
+ //FIXME pointers
+ MotionEstContext * const c= &s->me;
+ uint8_t * const mv_penalty_f= c->mv_penalty[s->f_code] + MAX_MV; // f_code of the prev frame
+ uint8_t * const mv_penalty_b= c->mv_penalty[s->b_code] + MAX_MV; // f_code of the prev frame
+ int stride= c->stride;
+ uint8_t *dest_y = c->scratchpad;
+ uint8_t *ptr;
+ int dxy;
+ int src_x, src_y;
+ int fbmin;
+ uint8_t **src_data= c->src[0];
+ uint8_t **ref_data= c->ref[0];
+ uint8_t **ref2_data= c->ref[2];
+
+ if(s->quarter_sample){
+ dxy = ((motion_fy & 3) << 2) | (motion_fx & 3);
+ src_x = motion_fx >> 2;
+ src_y = motion_fy >> 2;
+
+ ptr = ref_data[0] + (src_y * stride) + src_x;
+ s->dsp.put_qpel_pixels_tab[0][dxy](dest_y , ptr , stride);
+
+ dxy = ((motion_by & 3) << 2) | (motion_bx & 3);
+ src_x = motion_bx >> 2;
+ src_y = motion_by >> 2;
+
+ ptr = ref2_data[0] + (src_y * stride) + src_x;
+ s->dsp.avg_qpel_pixels_tab[size][dxy](dest_y , ptr , stride);
+ }else{
+ dxy = ((motion_fy & 1) << 1) | (motion_fx & 1);
+ src_x = motion_fx >> 1;
+ src_y = motion_fy >> 1;
+
+ ptr = ref_data[0] + (src_y * stride) + src_x;
+ s->dsp.put_pixels_tab[size][dxy](dest_y , ptr , stride, h);
+
+ dxy = ((motion_by & 1) << 1) | (motion_bx & 1);
+ src_x = motion_bx >> 1;
+ src_y = motion_by >> 1;
+
+ ptr = ref2_data[0] + (src_y * stride) + src_x;
+ s->dsp.avg_pixels_tab[size][dxy](dest_y , ptr , stride, h);
+ }
+
+ fbmin = (mv_penalty_f[motion_fx-pred_fx] + mv_penalty_f[motion_fy-pred_fy])*c->mb_penalty_factor
+ +(mv_penalty_b[motion_bx-pred_bx] + mv_penalty_b[motion_by-pred_by])*c->mb_penalty_factor
+ + s->dsp.mb_cmp[size](s, src_data[0], dest_y, stride, h); //FIXME new_pic
+
+ if(c->avctx->mb_cmp&FF_CMP_CHROMA){
+ }
+ //FIXME CHROMA !!!
+
+ return fbmin;
+}
+
+/* refine the bidir vectors in hq mode and return the score in both lq & hq mode*/
+static inline int bidir_refine(MpegEncContext * s, int mb_x, int mb_y)
+{
+ MotionEstContext * const c= &s->me;
+ const int mot_stride = s->mb_stride;
+ const int xy = mb_y *mot_stride + mb_x;
+ int fbmin;
+ int pred_fx= s->b_bidir_forw_mv_table[xy-1][0];
+ int pred_fy= s->b_bidir_forw_mv_table[xy-1][1];
+ int pred_bx= s->b_bidir_back_mv_table[xy-1][0];
+ int pred_by= s->b_bidir_back_mv_table[xy-1][1];
+ int motion_fx= s->b_bidir_forw_mv_table[xy][0]= s->b_forw_mv_table[xy][0];
+ int motion_fy= s->b_bidir_forw_mv_table[xy][1]= s->b_forw_mv_table[xy][1];
+ int motion_bx= s->b_bidir_back_mv_table[xy][0]= s->b_back_mv_table[xy][0];
+ int motion_by= s->b_bidir_back_mv_table[xy][1]= s->b_back_mv_table[xy][1];
+ const int flags= c->sub_flags;
+ const int qpel= flags&FLAG_QPEL;
+ const int shift= 1+qpel;
+ const int xmin= c->xmin<<shift;
+ const int ymin= c->ymin<<shift;
+ const int xmax= c->xmax<<shift;
+ const int ymax= c->ymax<<shift;
+ uint8_t map[8][8][8][8];
+
+ memset(map,0,sizeof(map));
+#define BIDIR_MAP(fx,fy,bx,by) \
+ map[(motion_fx+fx)&7][(motion_fy+fy)&7][(motion_bx+bx)&7][(motion_by+by)&7]
+ BIDIR_MAP(0,0,0,0) = 1;
+
+ fbmin= check_bidir_mv(s, motion_fx, motion_fy,
+ motion_bx, motion_by,
+ pred_fx, pred_fy,
+ pred_bx, pred_by,
+ 0, 16);
+
+ if(s->avctx->bidir_refine){
+ int score, end;
+#define CHECK_BIDIR(fx,fy,bx,by)\
+ if( !BIDIR_MAP(fx,fy,bx,by)\
+ &&(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;\
+ 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){\
+ fbmin= score;\
+ motion_fx+=fx;\
+ motion_fy+=fy;\
+ motion_bx+=bx;\
+ motion_by+=by;\
+ end=0;\
+ }\
+ }
+#define CHECK_BIDIR2(a,b,c,d)\
+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{
+ 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)
+ }
+ }
+ }
+ }while(!end);
+ }
+
+ s->b_bidir_forw_mv_table[xy][0]= motion_fx;
+ s->b_bidir_forw_mv_table[xy][1]= motion_fy;
+ s->b_bidir_back_mv_table[xy][0]= motion_bx;
+ s->b_bidir_back_mv_table[xy][1]= motion_by;
+
+ return fbmin;
+}
+
+static inline int direct_search(MpegEncContext * s, int mb_x, int mb_y)
+{
+ MotionEstContext * const c= &s->me;
+ int P[10][2];
+ const int mot_stride = s->mb_stride;
+ const int mot_xy = mb_y*mot_stride + mb_x;
+ const int shift= 1+s->quarter_sample;
+ int dmin, i;
+ const int time_pp= s->pp_time;
+ const int time_pb= s->pb_time;
+ int mx, my, xmin, xmax, ymin, ymax;
+ int16_t (*mv_table)[2]= s->b_direct_mv_table;
+
+ c->current_mv_penalty= c->mv_penalty[1] + MAX_MV;
+ ymin= xmin=(-32)>>shift;
+ ymax= xmax= 31>>shift;
+
+ if(IS_8X8(s->next_picture.mb_type[mot_xy])){
+ s->mv_type= MV_TYPE_8X8;
+ }else{
+ s->mv_type= MV_TYPE_16X16;
+ }
+
+ for(i=0; i<4; i++){
+ int index= s->block_index[i];
+ int min, max;
+
+ c->co_located_mv[i][0]= s->next_picture.motion_val[0][index][0];
+ c->co_located_mv[i][1]= s->next_picture.motion_val[0][index][1];
+ c->direct_basis_mv[i][0]= c->co_located_mv[i][0]*time_pb/time_pp + ((i& 1)<<(shift+3));
+ c->direct_basis_mv[i][1]= c->co_located_mv[i][1]*time_pb/time_pp + ((i>>1)<<(shift+3));
+// c->direct_basis_mv[1][i][0]= c->co_located_mv[i][0]*(time_pb - time_pp)/time_pp + ((i &1)<<(shift+3);
+// c->direct_basis_mv[1][i][1]= c->co_located_mv[i][1]*(time_pb - time_pp)/time_pp + ((i>>1)<<(shift+3);
+
+ max= FFMAX(c->direct_basis_mv[i][0], c->direct_basis_mv[i][0] - c->co_located_mv[i][0])>>shift;
+ min= FFMIN(c->direct_basis_mv[i][0], c->direct_basis_mv[i][0] - c->co_located_mv[i][0])>>shift;
+ max+= 16*mb_x + 1; // +-1 is for the simpler rounding
+ min+= 16*mb_x - 1;
+ xmax= FFMIN(xmax, s->width - max);
+ xmin= FFMAX(xmin, - 16 - min);
+
+ max= FFMAX(c->direct_basis_mv[i][1], c->direct_basis_mv[i][1] - c->co_located_mv[i][1])>>shift;
+ min= FFMIN(c->direct_basis_mv[i][1], c->direct_basis_mv[i][1] - c->co_located_mv[i][1])>>shift;
+ max+= 16*mb_y + 1; // +-1 is for the simpler rounding
+ min+= 16*mb_y - 1;
+ ymax= FFMIN(ymax, s->height - max);
+ ymin= FFMAX(ymin, - 16 - min);
+
+ if(s->mv_type == MV_TYPE_16X16) break;
+ }
+
+ assert(xmax <= 15 && ymax <= 15 && xmin >= -16 && ymin >= -16);
+
+ if(xmax < 0 || xmin >0 || ymax < 0 || ymin > 0){
+ s->b_direct_mv_table[mot_xy][0]= 0;
+ s->b_direct_mv_table[mot_xy][1]= 0;
+
+ return 256*256*256*64;
+ }
+
+ c->xmin= xmin;
+ c->ymin= ymin;
+ c->xmax= xmax;
+ c->ymax= ymax;
+ c->flags |= FLAG_DIRECT;
+ c->sub_flags |= FLAG_DIRECT;
+ c->pred_x=0;
+ c->pred_y=0;
+
+ P_LEFT[0] = av_clip(mv_table[mot_xy - 1][0], xmin<<shift, xmax<<shift);
+ P_LEFT[1] = av_clip(mv_table[mot_xy - 1][1], ymin<<shift, ymax<<shift);
+
+ /* special case for first line */
+ if (!s->first_slice_line) { //FIXME maybe allow this over thread boundary as its clipped
+ P_TOP[0] = av_clip(mv_table[mot_xy - mot_stride ][0], xmin<<shift, xmax<<shift);
+ P_TOP[1] = av_clip(mv_table[mot_xy - mot_stride ][1], ymin<<shift, ymax<<shift);
+ P_TOPRIGHT[0] = av_clip(mv_table[mot_xy - mot_stride + 1 ][0], xmin<<shift, xmax<<shift);
+ P_TOPRIGHT[1] = av_clip(mv_table[mot_xy - mot_stride + 1 ][1], ymin<<shift, ymax<<shift);
+
+ P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
+ P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);
+ }
+
+ dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, 0, mv_table, 1<<(16-shift), 0, 16);
+ if(c->sub_flags&FLAG_QPEL)
+ dmin = qpel_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);
+ else
+ dmin = hpel_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);
+
+ if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip)
+ dmin= ff_get_mb_score(s, mx, my, 0, 0, 0, 16, 1);
+
+ get_limits(s, 16*mb_x, 16*mb_y); //restore c->?min/max, maybe not needed
+
+ mv_table[mot_xy][0]= mx;
+ mv_table[mot_xy][1]= my;
+ c->flags &= ~FLAG_DIRECT;
+ c->sub_flags &= ~FLAG_DIRECT;
+
+ return dmin;
+}
+
+void ff_estimate_b_frame_motion(MpegEncContext * s,
+ int mb_x, int mb_y)
+{
+ MotionEstContext * const c= &s->me;
+ const int penalty_factor= c->mb_penalty_factor;
+ int fmin, bmin, dmin, fbmin, bimin, fimin;
+ int type=0;
+ const int xy = mb_y*s->mb_stride + mb_x;
+ init_ref(c, s->new_picture.data, s->last_picture.data, s->next_picture.data, 16*mb_x, 16*mb_y, 2);
+
+ get_limits(s, 16*mb_x, 16*mb_y);
+
+ c->skip=0;
+
+ if(s->codec_id == CODEC_ID_MPEG4 && s->next_picture.mbskip_table[xy]){
+ int score= direct_search(s, mb_x, mb_y); //FIXME just check 0,0
+
+ score= ((unsigned)(score*score + 128*256))>>16;
+ c->mc_mb_var_sum_temp += score;
+ s->current_picture.mc_mb_var[mb_y*s->mb_stride + mb_x] = score; //FIXME use SSE
+ s->mb_type[mb_y*s->mb_stride + mb_x]= CANDIDATE_MB_TYPE_DIRECT0;
+
+ return;
+ }
+
+ if(c->avctx->me_threshold){
+ int vard= check_input_motion(s, mb_x, mb_y, 0);
+
+ if((vard+128)>>8 < c->avctx->me_threshold){
+// pix = c->src[0][0];
+// sum = s->dsp.pix_sum(pix, s->linesize);
+// varc = s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)(sum*sum))>>8) + 500;
+
+// pic->mb_var [s->mb_stride * mb_y + mb_x] = (varc+128)>>8;
+ s->current_picture.mc_mb_var[s->mb_stride * mb_y + mb_x] = (vard+128)>>8;
+/* pic->mb_mean [s->mb_stride * mb_y + mb_x] = (sum+128)>>8;
+ c->mb_var_sum_temp += (varc+128)>>8;*/
+ c->mc_mb_var_sum_temp += (vard+128)>>8;
+/* if (vard <= 64<<8 || vard < varc) {
+ c->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc);
+ }else{
+ c->scene_change_score+= s->qscale * s->avctx->scenechange_factor;
+ }*/
+ return;
+ }
+ if((vard+128)>>8 < c->avctx->mb_threshold){
+ type= s->mb_type[mb_y*s->mb_stride + mb_x];
+ if(type == CANDIDATE_MB_TYPE_DIRECT){
+ direct_search(s, mb_x, mb_y);
+ }
+ if(type == CANDIDATE_MB_TYPE_FORWARD || type == CANDIDATE_MB_TYPE_BIDIR){
+ c->skip=0;
+ ff_estimate_motion_b(s, mb_x, mb_y, s->b_forw_mv_table, 0, s->f_code);
+ }
+ if(type == CANDIDATE_MB_TYPE_BACKWARD || type == CANDIDATE_MB_TYPE_BIDIR){
+ c->skip=0;
+ ff_estimate_motion_b(s, mb_x, mb_y, s->b_back_mv_table, 2, s->b_code);
+ }
+ if(type == CANDIDATE_MB_TYPE_FORWARD_I || type == CANDIDATE_MB_TYPE_BIDIR_I){
+ c->skip=0;
+ c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_MV;
+ interlaced_search(s, 0,
+ s->b_field_mv_table[0], s->b_field_select_table[0],
+ s->b_forw_mv_table[xy][0], s->b_forw_mv_table[xy][1], 1);
+ }
+ if(type == CANDIDATE_MB_TYPE_BACKWARD_I || type == CANDIDATE_MB_TYPE_BIDIR_I){
+ c->skip=0;
+ c->current_mv_penalty= c->mv_penalty[s->b_code] + MAX_MV;
+ interlaced_search(s, 2,
+ s->b_field_mv_table[1], s->b_field_select_table[1],
+ s->b_back_mv_table[xy][0], s->b_back_mv_table[xy][1], 1);
+ }
+ return;
+ }
+ }
+
+ if (s->codec_id == CODEC_ID_MPEG4)
+ dmin= direct_search(s, mb_x, mb_y);
+ else
+ dmin= INT_MAX;
+//FIXME penalty stuff for non mpeg4
+ c->skip=0;
+ fmin= ff_estimate_motion_b(s, mb_x, mb_y, s->b_forw_mv_table, 0, s->f_code) + 3*penalty_factor;
+
+ c->skip=0;
+ bmin= ff_estimate_motion_b(s, mb_x, mb_y, s->b_back_mv_table, 2, s->b_code) + 2*penalty_factor;
+//printf(" %d %d ", s->b_forw_mv_table[xy][0], s->b_forw_mv_table[xy][1]);
+
+ c->skip=0;
+ fbmin= bidir_refine(s, mb_x, mb_y) + penalty_factor;
+//printf("%d %d %d %d\n", dmin, fmin, bmin, fbmin);
+
+ if(s->flags & CODEC_FLAG_INTERLACED_ME){
+//FIXME mb type penalty
+ c->skip=0;
+ c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_MV;
+ fimin= interlaced_search(s, 0,
+ s->b_field_mv_table[0], s->b_field_select_table[0],
+ s->b_forw_mv_table[xy][0], s->b_forw_mv_table[xy][1], 0);
+ c->current_mv_penalty= c->mv_penalty[s->b_code] + MAX_MV;
+ bimin= interlaced_search(s, 2,
+ s->b_field_mv_table[1], s->b_field_select_table[1],
+ s->b_back_mv_table[xy][0], s->b_back_mv_table[xy][1], 0);
+ }else
+ fimin= bimin= INT_MAX;
+
+ {
+ int score= fmin;
+ type = CANDIDATE_MB_TYPE_FORWARD;
+
+ if (dmin <= score){
+ score = dmin;
+ type = CANDIDATE_MB_TYPE_DIRECT;
+ }
+ if(bmin<score){
+ score=bmin;
+ type= CANDIDATE_MB_TYPE_BACKWARD;
+ }
+ if(fbmin<score){
+ score=fbmin;
+ type= CANDIDATE_MB_TYPE_BIDIR;
+ }
+ if(fimin<score){
+ score=fimin;
+ type= CANDIDATE_MB_TYPE_FORWARD_I;
+ }
+ if(bimin<score){
+ score=bimin;
+ type= CANDIDATE_MB_TYPE_BACKWARD_I;
+ }
+
+ score= ((unsigned)(score*score + 128*256))>>16;
+ c->mc_mb_var_sum_temp += score;
+ s->current_picture.mc_mb_var[mb_y*s->mb_stride + mb_x] = score; //FIXME use SSE
+ }
+
+ if(c->avctx->mb_decision > FF_MB_DECISION_SIMPLE){
+ type= CANDIDATE_MB_TYPE_FORWARD | CANDIDATE_MB_TYPE_BACKWARD | CANDIDATE_MB_TYPE_BIDIR | CANDIDATE_MB_TYPE_DIRECT;
+ if(fimin < INT_MAX)
+ type |= CANDIDATE_MB_TYPE_FORWARD_I;
+ if(bimin < INT_MAX)
+ type |= CANDIDATE_MB_TYPE_BACKWARD_I;
+ if(fimin < INT_MAX && bimin < INT_MAX){
+ type |= CANDIDATE_MB_TYPE_BIDIR_I;
+ }
+ //FIXME something smarter
+ if(dmin>256*256*16) type&= ~CANDIDATE_MB_TYPE_DIRECT; //dont try direct mode if its invalid for this MB
+ if(s->codec_id == CODEC_ID_MPEG4 && type&CANDIDATE_MB_TYPE_DIRECT && s->flags&CODEC_FLAG_MV0 && *(uint32_t*)s->b_direct_mv_table[xy])
+ type |= CANDIDATE_MB_TYPE_DIRECT0;
+#if 0
+ if(s->out_format == FMT_MPEG1)
+ type |= CANDIDATE_MB_TYPE_INTRA;
+#endif
+ }
+
+ s->mb_type[mb_y*s->mb_stride + mb_x]= type;
+}
+
+/* find best f_code for ME which do unlimited searches */
+int ff_get_best_fcode(MpegEncContext * s, int16_t (*mv_table)[2], int type)
+{
+ if(s->me_method>=ME_EPZS){
+ int score[8];
+ int i, y, range= s->avctx->me_range ? s->avctx->me_range : (INT_MAX/2);
+ uint8_t * fcode_tab= s->fcode_tab;
+ int best_fcode=-1;
+ int best_score=-10000000;
+
+ if(s->msmpeg4_version)
+ range= FFMIN(range, 16);
+ else if(s->codec_id == CODEC_ID_MPEG2VIDEO && s->avctx->strict_std_compliance >= FF_COMPLIANCE_NORMAL)
+ range= FFMIN(range, 256);
+
+ for(i=0; i<8; i++) score[i]= s->mb_num*(8-i);
+
+ for(y=0; y<s->mb_height; y++){
+ int x;
+ int xy= y*s->mb_stride;
+ for(x=0; x<s->mb_width; x++){
+ if(s->mb_type[xy] & type){
+ int mx= mv_table[xy][0];
+ int my= mv_table[xy][1];
+ int fcode= FFMAX(fcode_tab[mx + MAX_MV],
+ fcode_tab[my + MAX_MV]);
+ int j;
+
+ if(mx >= range || mx < -range ||
+ my >= range || my < -range)
+ continue;
+
+ for(j=0; j<fcode && j<8; j++){
+ if(s->pict_type==B_TYPE || s->current_picture.mc_mb_var[xy] < s->current_picture.mb_var[xy])
+ score[j]-= 170;
+ }
+ }
+ xy++;
+ }
+ }
+
+ for(i=1; i<8; i++){
+ if(score[i] > best_score){
+ best_score= score[i];
+ best_fcode= i;
+ }
+// printf("%d %d\n", i, score[i]);
+ }
+
+// printf("fcode: %d type: %d\n", i, s->pict_type);
+ return best_fcode;
+/* for(i=0; i<=MAX_FCODE; i++){
+ printf("%d ", mv_num[i]);
+ }
+ printf("\n");*/
+ }else{
+ return 1;
+ }
+}
+
+void ff_fix_long_p_mvs(MpegEncContext * s)
+{
+ MotionEstContext * const c= &s->me;
+ const int f_code= s->f_code;
+ int y, range;
+ assert(s->pict_type==P_TYPE);
+
+ range = (((s->out_format == FMT_MPEG1 || s->msmpeg4_version) ? 8 : 16) << f_code);
+
+ assert(range <= 16 || !s->msmpeg4_version);
+ assert(range <=256 || !(s->codec_id == CODEC_ID_MPEG2VIDEO && s->avctx->strict_std_compliance >= FF_COMPLIANCE_NORMAL));
+
+ if(c->avctx->me_range && range > c->avctx->me_range) range= c->avctx->me_range;
+
+//printf("%d no:%d %d//\n", clip, noclip, f_code);
+ if(s->flags&CODEC_FLAG_4MV){
+ const int wrap= s->b8_stride;
+
+ /* clip / convert to intra 8x8 type MVs */
+ for(y=0; y<s->mb_height; y++){
+ int xy= y*2*wrap;
+ int i= y*s->mb_stride;
+ int x;
+
+ for(x=0; x<s->mb_width; x++){
+ if(s->mb_type[i]&CANDIDATE_MB_TYPE_INTER4V){
+ int block;
+ for(block=0; block<4; block++){
+ int off= (block& 1) + (block>>1)*wrap;
+ int mx= s->current_picture.motion_val[0][ xy + off ][0];
+ int my= s->current_picture.motion_val[0][ xy + off ][1];
+
+ if( mx >=range || mx <-range
+ || my >=range || my <-range){
+ s->mb_type[i] &= ~CANDIDATE_MB_TYPE_INTER4V;
+ s->mb_type[i] |= CANDIDATE_MB_TYPE_INTRA;
+ s->current_picture.mb_type[i]= CANDIDATE_MB_TYPE_INTRA;
+ }
+ }
+ }
+ xy+=2;
+ i++;
+ }
+ }
+ }
+}
+
+/**
+ *
+ * @param truncate 1 for truncation, 0 for using intra
+ */
+void ff_fix_long_mvs(MpegEncContext * s, uint8_t *field_select_table, int field_select,
+ int16_t (*mv_table)[2], int f_code, int type, int truncate)
+{
+ MotionEstContext * const c= &s->me;
+ int y, h_range, v_range;
+
+ // RAL: 8 in MPEG-1, 16 in MPEG-4
+ int range = (((s->out_format == FMT_MPEG1 || s->msmpeg4_version) ? 8 : 16) << f_code);
+
+ if(c->avctx->me_range && range > c->avctx->me_range) range= c->avctx->me_range;
+
+ h_range= range;
+ v_range= field_select_table ? range>>1 : range;
+
+ /* clip / convert to intra 16x16 type MVs */
+ for(y=0; y<s->mb_height; y++){
+ int x;
+ int xy= y*s->mb_stride;
+ for(x=0; x<s->mb_width; x++){
+ if (s->mb_type[xy] & type){ // RAL: "type" test added...
+ if(field_select_table==NULL || field_select_table[xy] == field_select){
+ if( mv_table[xy][0] >=h_range || mv_table[xy][0] <-h_range
+ || mv_table[xy][1] >=v_range || mv_table[xy][1] <-v_range){
+
+ if(truncate){
+ if (mv_table[xy][0] > h_range-1) mv_table[xy][0]= h_range-1;
+ else if(mv_table[xy][0] < -h_range ) mv_table[xy][0]= -h_range;
+ if (mv_table[xy][1] > v_range-1) mv_table[xy][1]= v_range-1;
+ else if(mv_table[xy][1] < -v_range ) mv_table[xy][1]= -v_range;
+ }else{
+ s->mb_type[xy] &= ~type;
+ s->mb_type[xy] |= CANDIDATE_MB_TYPE_INTRA;
+ mv_table[xy][0]=
+ mv_table[xy][1]= 0;
+ }
+ }
+ }
+ }
+ xy++;
+ }
+ }
+}
diff --git a/contrib/ffmpeg/libavcodec/motion_est_template.c b/contrib/ffmpeg/libavcodec/motion_est_template.c
new file mode 100644
index 000000000..37443b022
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/motion_est_template.c
@@ -0,0 +1,1249 @@
+/*
+ * Motion estimation
+ * 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 motion_est_template.c
+ * Motion estimation template.
+ */
+
+//lets hope gcc will remove the unused vars ...(gcc 3.2.2 seems to do it ...)
+#define LOAD_COMMON\
+ uint32_t attribute_unused * const score_map= c->score_map;\
+ const int attribute_unused xmin= c->xmin;\
+ const int attribute_unused ymin= c->ymin;\
+ const int attribute_unused xmax= c->xmax;\
+ const int attribute_unused ymax= c->ymax;\
+ uint8_t *mv_penalty= c->current_mv_penalty;\
+ const int pred_x= c->pred_x;\
+ const int pred_y= c->pred_y;\
+
+#define CHECK_HALF_MV(dx, dy, x, y)\
+{\
+ const int hx= 2*(x)+(dx);\
+ const int hy= 2*(y)+(dy);\
+ d= cmp(s, x, y, dx, dy, size, h, ref_index, src_index, cmp_sub, chroma_cmp_sub, flags);\
+ d += (mv_penalty[hx - pred_x] + mv_penalty[hy - pred_y])*penalty_factor;\
+ COPY3_IF_LT(dmin, d, bx, hx, by, hy)\
+}
+
+#if 0
+static int hpel_motion_search)(MpegEncContext * s,
+ int *mx_ptr, int *my_ptr, int dmin,
+ uint8_t *ref_data[3],
+ int size)
+{
+ const int xx = 16 * s->mb_x + 8*(n&1);
+ const int yy = 16 * s->mb_y + 8*(n>>1);
+ const int mx = *mx_ptr;
+ const int my = *my_ptr;
+ const int penalty_factor= c->sub_penalty_factor;
+
+ LOAD_COMMON
+
+ // INIT;
+ //FIXME factorize
+ me_cmp_func cmp, chroma_cmp, cmp_sub, chroma_cmp_sub;
+
+ if(s->no_rounding /*FIXME b_type*/){
+ hpel_put= &s->dsp.put_no_rnd_pixels_tab[size];
+ chroma_hpel_put= &s->dsp.put_no_rnd_pixels_tab[size+1];
+ }else{
+ hpel_put=& s->dsp.put_pixels_tab[size];
+ chroma_hpel_put= &s->dsp.put_pixels_tab[size+1];
+ }
+ cmpf= s->dsp.me_cmp[size];
+ chroma_cmpf= s->dsp.me_cmp[size+1];
+ cmp_sub= s->dsp.me_sub_cmp[size];
+ chroma_cmp_sub= s->dsp.me_sub_cmp[size+1];
+
+ if(c->skip){ //FIXME somehow move up (benchmark)
+ *mx_ptr = 0;
+ *my_ptr = 0;
+ return dmin;
+ }
+
+ if(c->avctx->me_cmp != c->avctx->me_sub_cmp){
+ CMP_HPEL(dmin, 0, 0, mx, my, size);
+ if(mx || my)
+ dmin += (mv_penalty[2*mx - pred_x] + mv_penalty[2*my - pred_y])*penalty_factor;
+ }
+
+ if (mx > xmin && mx < xmax &&
+ my > ymin && my < ymax) {
+ int bx=2*mx, by=2*my;
+ int d= dmin;
+
+ CHECK_HALF_MV(1, 1, mx-1, my-1)
+ CHECK_HALF_MV(0, 1, mx , my-1)
+ CHECK_HALF_MV(1, 1, mx , my-1)
+ CHECK_HALF_MV(1, 0, mx-1, my )
+ CHECK_HALF_MV(1, 0, mx , my )
+ CHECK_HALF_MV(1, 1, mx-1, my )
+ CHECK_HALF_MV(0, 1, mx , my )
+ CHECK_HALF_MV(1, 1, mx , my )
+
+ assert(bx >= xmin*2 || bx <= xmax*2 || by >= ymin*2 || by <= ymax*2);
+
+ *mx_ptr = bx;
+ *my_ptr = by;
+ }else{
+ *mx_ptr =2*mx;
+ *my_ptr =2*my;
+ }
+
+ return dmin;
+}
+
+#else
+static int hpel_motion_search(MpegEncContext * s,
+ int *mx_ptr, int *my_ptr, int dmin,
+ int src_index, int ref_index,
+ int size, int h)
+{
+ MotionEstContext * const c= &s->me;
+ const int mx = *mx_ptr;
+ const int my = *my_ptr;
+ const int penalty_factor= c->sub_penalty_factor;
+ me_cmp_func cmp_sub, chroma_cmp_sub;
+ int bx=2*mx, by=2*my;
+
+ LOAD_COMMON
+ int flags= c->sub_flags;
+
+ //FIXME factorize
+
+ cmp_sub= s->dsp.me_sub_cmp[size];
+ chroma_cmp_sub= s->dsp.me_sub_cmp[size+1];
+
+ if(c->skip){ //FIXME move out of hpel?
+ *mx_ptr = 0;
+ *my_ptr = 0;
+ return dmin;
+ }
+
+ if(c->avctx->me_cmp != c->avctx->me_sub_cmp){
+ dmin= cmp(s, mx, my, 0, 0, size, h, ref_index, src_index, cmp_sub, chroma_cmp_sub, flags);
+ if(mx || my || size>0)
+ dmin += (mv_penalty[2*mx - pred_x] + mv_penalty[2*my - pred_y])*penalty_factor;
+ }
+
+ if (mx > xmin && mx < xmax &&
+ my > ymin && my < ymax) {
+ int d= dmin;
+ const int index= (my<<ME_MAP_SHIFT) + mx;
+ const int t= score_map[(index-(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)]
+ + (mv_penalty[bx - pred_x] + mv_penalty[by-2 - pred_y])*c->penalty_factor;
+ const int l= score_map[(index- 1 )&(ME_MAP_SIZE-1)]
+ + (mv_penalty[bx-2 - pred_x] + mv_penalty[by - pred_y])*c->penalty_factor;
+ const int r= score_map[(index+ 1 )&(ME_MAP_SIZE-1)]
+ + (mv_penalty[bx+2 - pred_x] + mv_penalty[by - pred_y])*c->penalty_factor;
+ const int b= score_map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)]
+ + (mv_penalty[bx - pred_x] + mv_penalty[by+2 - pred_y])*c->penalty_factor;
+
+#if 1
+ int key;
+ int map_generation= c->map_generation;
+#ifndef NDEBUG
+ uint32_t *map= c->map;
+#endif
+ key= ((my-1)<<ME_MAP_MV_BITS) + (mx) + map_generation;
+ assert(map[(index-(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)] == key);
+ key= ((my+1)<<ME_MAP_MV_BITS) + (mx) + map_generation;
+ assert(map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)] == key);
+ key= ((my)<<ME_MAP_MV_BITS) + (mx+1) + map_generation;
+ assert(map[(index+1)&(ME_MAP_SIZE-1)] == key);
+ key= ((my)<<ME_MAP_MV_BITS) + (mx-1) + map_generation;
+ assert(map[(index-1)&(ME_MAP_SIZE-1)] == key);
+#endif
+ if(t<=b){
+ CHECK_HALF_MV(0, 1, mx ,my-1)
+ if(l<=r){
+ CHECK_HALF_MV(1, 1, mx-1, my-1)
+ if(t+r<=b+l){
+ CHECK_HALF_MV(1, 1, mx , my-1)
+ }else{
+ CHECK_HALF_MV(1, 1, mx-1, my )
+ }
+ CHECK_HALF_MV(1, 0, mx-1, my )
+ }else{
+ CHECK_HALF_MV(1, 1, mx , my-1)
+ if(t+l<=b+r){
+ CHECK_HALF_MV(1, 1, mx-1, my-1)
+ }else{
+ CHECK_HALF_MV(1, 1, mx , my )
+ }
+ CHECK_HALF_MV(1, 0, mx , my )
+ }
+ }else{
+ if(l<=r){
+ if(t+l<=b+r){
+ CHECK_HALF_MV(1, 1, mx-1, my-1)
+ }else{
+ CHECK_HALF_MV(1, 1, mx , my )
+ }
+ CHECK_HALF_MV(1, 0, mx-1, my)
+ CHECK_HALF_MV(1, 1, mx-1, my)
+ }else{
+ if(t+r<=b+l){
+ CHECK_HALF_MV(1, 1, mx , my-1)
+ }else{
+ CHECK_HALF_MV(1, 1, mx-1, my)
+ }
+ CHECK_HALF_MV(1, 0, mx , my)
+ CHECK_HALF_MV(1, 1, mx , my)
+ }
+ CHECK_HALF_MV(0, 1, mx , my)
+ }
+ assert(bx >= xmin*2 && bx <= xmax*2 && by >= ymin*2 && by <= ymax*2);
+ }
+
+ *mx_ptr = bx;
+ *my_ptr = by;
+
+ return dmin;
+}
+#endif
+
+static int no_sub_motion_search(MpegEncContext * s,
+ int *mx_ptr, int *my_ptr, int dmin,
+ int src_index, int ref_index,
+ int size, int h)
+{
+ (*mx_ptr)<<=1;
+ (*my_ptr)<<=1;
+ return dmin;
+}
+
+inline int ff_get_mb_score(MpegEncContext * s, int mx, int my, int src_index,
+ int ref_index, int size, int h, int add_rate)
+{
+// const int check_luma= s->dsp.me_sub_cmp != s->dsp.mb_cmp;
+ MotionEstContext * const c= &s->me;
+ const int penalty_factor= c->mb_penalty_factor;
+ const int flags= c->mb_flags;
+ const int qpel= flags & FLAG_QPEL;
+ const int mask= 1+2*qpel;
+ me_cmp_func cmp_sub, chroma_cmp_sub;
+ int d;
+
+ LOAD_COMMON
+
+ //FIXME factorize
+
+ cmp_sub= s->dsp.mb_cmp[size];
+ chroma_cmp_sub= s->dsp.mb_cmp[size+1];
+
+// assert(!c->skip);
+// assert(c->avctx->me_sub_cmp != c->avctx->mb_cmp);
+
+ d= cmp(s, mx>>(qpel+1), my>>(qpel+1), mx&mask, my&mask, size, h, ref_index, src_index, cmp_sub, chroma_cmp_sub, flags);
+ //FIXME check cbp before adding penalty for (0,0) vector
+ if(add_rate && (mx || my || size>0))
+ d += (mv_penalty[mx - pred_x] + mv_penalty[my - pred_y])*penalty_factor;
+
+ return d;
+}
+
+#define CHECK_QUARTER_MV(dx, dy, x, y)\
+{\
+ const int hx= 4*(x)+(dx);\
+ const int hy= 4*(y)+(dy);\
+ d= cmp(s, x, y, dx, dy, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
+ d += (mv_penalty[hx - pred_x] + mv_penalty[hy - pred_y])*penalty_factor;\
+ COPY3_IF_LT(dmin, d, bx, hx, by, hy)\
+}
+
+static int qpel_motion_search(MpegEncContext * s,
+ int *mx_ptr, int *my_ptr, int dmin,
+ int src_index, int ref_index,
+ int size, int h)
+{
+ MotionEstContext * const c= &s->me;
+ const int mx = *mx_ptr;
+ const int my = *my_ptr;
+ const int penalty_factor= c->sub_penalty_factor;
+ const int map_generation= c->map_generation;
+ const int subpel_quality= c->avctx->me_subpel_quality;
+ uint32_t *map= c->map;
+ me_cmp_func cmpf, chroma_cmpf;
+ me_cmp_func cmp_sub, chroma_cmp_sub;
+
+ LOAD_COMMON
+ int flags= c->sub_flags;
+
+ cmpf= s->dsp.me_cmp[size];
+ chroma_cmpf= s->dsp.me_cmp[size+1]; //factorize FIXME
+ //FIXME factorize
+
+ cmp_sub= s->dsp.me_sub_cmp[size];
+ chroma_cmp_sub= s->dsp.me_sub_cmp[size+1];
+
+ if(c->skip){ //FIXME somehow move up (benchmark)
+ *mx_ptr = 0;
+ *my_ptr = 0;
+ return dmin;
+ }
+
+ if(c->avctx->me_cmp != c->avctx->me_sub_cmp){
+ dmin= cmp(s, mx, my, 0, 0, size, h, ref_index, src_index, cmp_sub, chroma_cmp_sub, flags);
+ if(mx || my || size>0)
+ dmin += (mv_penalty[4*mx - pred_x] + mv_penalty[4*my - pred_y])*penalty_factor;
+ }
+
+ if (mx > xmin && mx < xmax &&
+ my > ymin && my < ymax) {
+ int bx=4*mx, by=4*my;
+ int d= dmin;
+ int i, nx, ny;
+ const int index= (my<<ME_MAP_SHIFT) + mx;
+ const int t= score_map[(index-(1<<ME_MAP_SHIFT) )&(ME_MAP_SIZE-1)];
+ const int l= score_map[(index- 1 )&(ME_MAP_SIZE-1)];
+ const int r= score_map[(index+ 1 )&(ME_MAP_SIZE-1)];
+ const int b= score_map[(index+(1<<ME_MAP_SHIFT) )&(ME_MAP_SIZE-1)];
+ const int c= score_map[(index )&(ME_MAP_SIZE-1)];
+ int best[8];
+ int best_pos[8][2];
+
+ memset(best, 64, sizeof(int)*8);
+#if 1
+ if(s->me.dia_size>=2){
+ const int tl= score_map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
+ const int bl= score_map[(index+(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
+ const int tr= score_map[(index-(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];
+ const int br= score_map[(index+(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];
+
+ for(ny= -3; ny <= 3; ny++){
+ for(nx= -3; nx <= 3; nx++){
+ //FIXME this could overflow (unlikely though)
+ const int64_t t2= nx*nx*(tr + tl - 2*t) + 4*nx*(tr-tl) + 32*t;
+ const int64_t c2= nx*nx*( r + l - 2*c) + 4*nx*( r- l) + 32*c;
+ const int64_t b2= nx*nx*(br + bl - 2*b) + 4*nx*(br-bl) + 32*b;
+ int score= (ny*ny*(b2 + t2 - 2*c2) + 4*ny*(b2 - t2) + 32*c2 + 512)>>10;
+ int i;
+
+ if((nx&3)==0 && (ny&3)==0) continue;
+
+ score += (mv_penalty[4*mx + nx - pred_x] + mv_penalty[4*my + ny - pred_y])*penalty_factor;
+
+// if(nx&1) score-=1024*c->penalty_factor;
+// if(ny&1) score-=1024*c->penalty_factor;
+
+ for(i=0; i<8; i++){
+ if(score < best[i]){
+ memmove(&best[i+1], &best[i], sizeof(int)*(7-i));
+ memmove(&best_pos[i+1][0], &best_pos[i][0], sizeof(int)*2*(7-i));
+ best[i]= score;
+ best_pos[i][0]= nx + 4*mx;
+ best_pos[i][1]= ny + 4*my;
+ break;
+ }
+ }
+ }
+ }
+ }else{
+ int tl;
+ //FIXME this could overflow (unlikely though)
+ const int cx = 4*(r - l);
+ const int cx2= r + l - 2*c;
+ const int cy = 4*(b - t);
+ const int cy2= b + t - 2*c;
+ int cxy;
+
+ if(map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)] == (my<<ME_MAP_MV_BITS) + mx + map_generation && 0){ //FIXME
+ tl= score_map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
+ }else{
+ tl= cmp(s, mx-1, my-1, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);//FIXME wrong if chroma me is different
+ }
+
+ cxy= 2*tl + (cx + cy)/4 - (cx2 + cy2) - 2*c;
+
+ assert(16*cx2 + 4*cx + 32*c == 32*r);
+ assert(16*cx2 - 4*cx + 32*c == 32*l);
+ assert(16*cy2 + 4*cy + 32*c == 32*b);
+ assert(16*cy2 - 4*cy + 32*c == 32*t);
+ assert(16*cxy + 16*cy2 + 16*cx2 - 4*cy - 4*cx + 32*c == 32*tl);
+
+ for(ny= -3; ny <= 3; ny++){
+ for(nx= -3; nx <= 3; nx++){
+ //FIXME this could overflow (unlikely though)
+ int score= ny*nx*cxy + nx*nx*cx2 + ny*ny*cy2 + nx*cx + ny*cy + 32*c; //FIXME factor
+ int i;
+
+ if((nx&3)==0 && (ny&3)==0) continue;
+
+ score += 32*(mv_penalty[4*mx + nx - pred_x] + mv_penalty[4*my + ny - pred_y])*penalty_factor;
+// if(nx&1) score-=32*c->penalty_factor;
+ // if(ny&1) score-=32*c->penalty_factor;
+
+ for(i=0; i<8; i++){
+ if(score < best[i]){
+ memmove(&best[i+1], &best[i], sizeof(int)*(7-i));
+ memmove(&best_pos[i+1][0], &best_pos[i][0], sizeof(int)*2*(7-i));
+ best[i]= score;
+ best_pos[i][0]= nx + 4*mx;
+ best_pos[i][1]= ny + 4*my;
+ break;
+ }
+ }
+ }
+ }
+ }
+ for(i=0; i<subpel_quality; i++){
+ nx= best_pos[i][0];
+ ny= best_pos[i][1];
+ CHECK_QUARTER_MV(nx&3, ny&3, nx>>2, ny>>2)
+ }
+
+#if 0
+ const int tl= score_map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
+ const int bl= score_map[(index+(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
+ const int tr= score_map[(index-(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];
+ const int br= score_map[(index+(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];
+// if(l < r && l < t && l < b && l < tl && l < bl && l < tr && l < br && bl < tl){
+ if(tl<br){
+
+// nx= FFMAX(4*mx - bx, bx - 4*mx);
+// ny= FFMAX(4*my - by, by - 4*my);
+
+ static int stats[7][7], count;
+ count++;
+ stats[4*mx - bx + 3][4*my - by + 3]++;
+ if(256*256*256*64 % count ==0){
+ for(i=0; i<49; i++){
+ if((i%7)==0) printf("\n");
+ printf("%6d ", stats[0][i]);
+ }
+ printf("\n");
+ }
+ }
+#endif
+#else
+
+ CHECK_QUARTER_MV(2, 2, mx-1, my-1)
+ CHECK_QUARTER_MV(0, 2, mx , my-1)
+ CHECK_QUARTER_MV(2, 2, mx , my-1)
+ CHECK_QUARTER_MV(2, 0, mx , my )
+ CHECK_QUARTER_MV(2, 2, mx , my )
+ CHECK_QUARTER_MV(0, 2, mx , my )
+ CHECK_QUARTER_MV(2, 2, mx-1, my )
+ CHECK_QUARTER_MV(2, 0, mx-1, my )
+
+ nx= bx;
+ ny= by;
+
+ for(i=0; i<8; i++){
+ int ox[8]= {0, 1, 1, 1, 0,-1,-1,-1};
+ int oy[8]= {1, 1, 0,-1,-1,-1, 0, 1};
+ CHECK_QUARTER_MV((nx + ox[i])&3, (ny + oy[i])&3, (nx + ox[i])>>2, (ny + oy[i])>>2)
+ }
+#endif
+#if 0
+ //outer ring
+ CHECK_QUARTER_MV(1, 3, mx-1, my-1)
+ CHECK_QUARTER_MV(1, 2, mx-1, my-1)
+ CHECK_QUARTER_MV(1, 1, mx-1, my-1)
+ CHECK_QUARTER_MV(2, 1, mx-1, my-1)
+ CHECK_QUARTER_MV(3, 1, mx-1, my-1)
+ CHECK_QUARTER_MV(0, 1, mx , my-1)
+ CHECK_QUARTER_MV(1, 1, mx , my-1)
+ CHECK_QUARTER_MV(2, 1, mx , my-1)
+ CHECK_QUARTER_MV(3, 1, mx , my-1)
+ CHECK_QUARTER_MV(3, 2, mx , my-1)
+ CHECK_QUARTER_MV(3, 3, mx , my-1)
+ CHECK_QUARTER_MV(3, 0, mx , my )
+ CHECK_QUARTER_MV(3, 1, mx , my )
+ CHECK_QUARTER_MV(3, 2, mx , my )
+ CHECK_QUARTER_MV(3, 3, mx , my )
+ CHECK_QUARTER_MV(2, 3, mx , my )
+ CHECK_QUARTER_MV(1, 3, mx , my )
+ CHECK_QUARTER_MV(0, 3, mx , my )
+ CHECK_QUARTER_MV(3, 3, mx-1, my )
+ CHECK_QUARTER_MV(2, 3, mx-1, my )
+ CHECK_QUARTER_MV(1, 3, mx-1, my )
+ CHECK_QUARTER_MV(1, 2, mx-1, my )
+ CHECK_QUARTER_MV(1, 1, mx-1, my )
+ CHECK_QUARTER_MV(1, 0, mx-1, my )
+#endif
+ assert(bx >= xmin*4 && bx <= xmax*4 && by >= ymin*4 && by <= ymax*4);
+
+ *mx_ptr = bx;
+ *my_ptr = by;
+ }else{
+ *mx_ptr =4*mx;
+ *my_ptr =4*my;
+ }
+
+ return dmin;
+}
+
+
+#define CHECK_MV(x,y)\
+{\
+ const int key= ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
+ const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\
+ assert((x) >= xmin);\
+ assert((x) <= xmax);\
+ assert((y) >= ymin);\
+ assert((y) <= ymax);\
+/*printf("check_mv %d %d\n", x, y);*/\
+ if(map[index]!=key){\
+ d= cmp(s, x, y, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
+ map[index]= key;\
+ score_map[index]= d;\
+ d += (mv_penalty[((x)<<shift)-pred_x] + mv_penalty[((y)<<shift)-pred_y])*penalty_factor;\
+/*printf("score:%d\n", d);*/\
+ COPY3_IF_LT(dmin, d, best[0], x, best[1], y)\
+ }\
+}
+
+#define CHECK_CLIPPED_MV(ax,ay)\
+{\
+ const int Lx= ax;\
+ const int Ly= ay;\
+ const int Lx2= FFMAX(xmin, FFMIN(Lx, xmax));\
+ const int Ly2= FFMAX(ymin, FFMIN(Ly, ymax));\
+ CHECK_MV(Lx2, Ly2)\
+}
+
+#define CHECK_MV_DIR(x,y,new_dir)\
+{\
+ const int key= ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
+ const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\
+/*printf("check_mv_dir %d %d %d\n", x, y, new_dir);*/\
+ if(map[index]!=key){\
+ d= cmp(s, x, y, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
+ map[index]= key;\
+ score_map[index]= d;\
+ d += (mv_penalty[((x)<<shift)-pred_x] + mv_penalty[((y)<<shift)-pred_y])*penalty_factor;\
+/*printf("score:%d\n", d);*/\
+ if(d<dmin){\
+ best[0]=x;\
+ best[1]=y;\
+ dmin=d;\
+ next_dir= new_dir;\
+ }\
+ }\
+}
+
+#define check(x,y,S,v)\
+if( (x)<(xmin<<(S)) ) printf("%d %d %d %d %d xmin" #v, xmin, (x), (y), s->mb_x, s->mb_y);\
+if( (x)>(xmax<<(S)) ) printf("%d %d %d %d %d xmax" #v, xmax, (x), (y), s->mb_x, s->mb_y);\
+if( (y)<(ymin<<(S)) ) printf("%d %d %d %d %d ymin" #v, ymin, (x), (y), s->mb_x, s->mb_y);\
+if( (y)>(ymax<<(S)) ) printf("%d %d %d %d %d ymax" #v, ymax, (x), (y), s->mb_x, s->mb_y);\
+
+#define LOAD_COMMON2\
+ uint32_t *map= c->map;\
+ const int qpel= flags&FLAG_QPEL;\
+ const int shift= 1+qpel;\
+
+static av_always_inline int small_diamond_search(MpegEncContext * s, int *best, int dmin,
+ int src_index, int ref_index, int const penalty_factor,
+ int size, int h, int flags)
+{
+ MotionEstContext * const c= &s->me;
+ me_cmp_func cmpf, chroma_cmpf;
+ int next_dir=-1;
+ LOAD_COMMON
+ LOAD_COMMON2
+ int map_generation= c->map_generation;
+
+ cmpf= s->dsp.me_cmp[size];
+ chroma_cmpf= s->dsp.me_cmp[size+1];
+
+ { /* ensure that the best point is in the MAP as h/qpel refinement needs it */
+ const int key= (best[1]<<ME_MAP_MV_BITS) + best[0] + map_generation;
+ const int index= ((best[1]<<ME_MAP_SHIFT) + best[0])&(ME_MAP_SIZE-1);
+ if(map[index]!=key){ //this will be executed only very rarey
+ score_map[index]= cmp(s, best[0], best[1], 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);
+ map[index]= key;
+ }
+ }
+
+ for(;;){
+ int d;
+ const int dir= next_dir;
+ const int x= best[0];
+ const int y= best[1];
+ next_dir=-1;
+
+//printf("%d", dir);
+ if(dir!=2 && x>xmin) CHECK_MV_DIR(x-1, y , 0)
+ if(dir!=3 && y>ymin) CHECK_MV_DIR(x , y-1, 1)
+ if(dir!=0 && x<xmax) CHECK_MV_DIR(x+1, y , 2)
+ if(dir!=1 && y<ymax) CHECK_MV_DIR(x , y+1, 3)
+
+ if(next_dir==-1){
+ return dmin;
+ }
+ }
+}
+
+static int funny_diamond_search(MpegEncContext * s, int *best, int dmin,
+ int src_index, int ref_index, int const penalty_factor,
+ int size, int h, int flags)
+{
+ MotionEstContext * const c= &s->me;
+ me_cmp_func cmpf, chroma_cmpf;
+ int dia_size;
+ LOAD_COMMON
+ LOAD_COMMON2
+ int map_generation= c->map_generation;
+
+ cmpf= s->dsp.me_cmp[size];
+ chroma_cmpf= s->dsp.me_cmp[size+1];
+
+ for(dia_size=1; dia_size<=4; dia_size++){
+ int dir;
+ const int x= best[0];
+ const int y= best[1];
+
+ if(dia_size&(dia_size-1)) continue;
+
+ if( x + dia_size > xmax
+ || x - dia_size < xmin
+ || y + dia_size > ymax
+ || y - dia_size < ymin)
+ continue;
+
+ for(dir= 0; dir<dia_size; dir+=2){
+ int d;
+
+ CHECK_MV(x + dir , y + dia_size - dir);
+ CHECK_MV(x + dia_size - dir, y - dir );
+ CHECK_MV(x - dir , y - dia_size + dir);
+ CHECK_MV(x - dia_size + dir, y + dir );
+ }
+
+ if(x!=best[0] || y!=best[1])
+ dia_size=0;
+#if 0
+{
+int dx, dy, i;
+static int stats[8*8];
+dx= FFABS(x-best[0]);
+dy= FFABS(y-best[1]);
+if(dy>dx){
+ dx^=dy; dy^=dx; dx^=dy;
+}
+stats[dy*8 + dx] ++;
+if(256*256*256*64 % (stats[0]+1)==0){
+ for(i=0; i<64; i++){
+ if((i&7)==0) printf("\n");
+ printf("%8d ", stats[i]);
+ }
+ printf("\n");
+}
+}
+#endif
+ }
+ return dmin;
+}
+
+static int hex_search(MpegEncContext * s, int *best, int dmin,
+ int src_index, int ref_index, int const penalty_factor,
+ int size, int h, int flags, int dia_size)
+{
+ MotionEstContext * const c= &s->me;
+ me_cmp_func cmpf, chroma_cmpf;
+ LOAD_COMMON
+ LOAD_COMMON2
+ int map_generation= c->map_generation;
+ int x,y,d;
+ const int dec= dia_size & (dia_size-1);
+
+ cmpf= s->dsp.me_cmp[size];
+ chroma_cmpf= s->dsp.me_cmp[size+1];
+
+ for(;dia_size; dia_size= dec ? dia_size-1 : dia_size>>1){
+ do{
+ x= best[0];
+ y= best[1];
+
+ CHECK_CLIPPED_MV(x -dia_size , y);
+ CHECK_CLIPPED_MV(x+ dia_size , y);
+ CHECK_CLIPPED_MV(x+( dia_size>>1), y+dia_size);
+ CHECK_CLIPPED_MV(x+( dia_size>>1), y-dia_size);
+ if(dia_size>1){
+ CHECK_CLIPPED_MV(x+(-dia_size>>1), y+dia_size);
+ CHECK_CLIPPED_MV(x+(-dia_size>>1), y-dia_size);
+ }
+ }while(best[0] != x || best[1] != y);
+ }
+
+ return dmin;
+}
+
+static int l2s_dia_search(MpegEncContext * s, int *best, int dmin,
+ int src_index, int ref_index, int const penalty_factor,
+ int size, int h, int flags)
+{
+ MotionEstContext * const c= &s->me;
+ me_cmp_func cmpf, chroma_cmpf;
+ LOAD_COMMON
+ LOAD_COMMON2
+ int map_generation= c->map_generation;
+ int x,y,i,d;
+ int dia_size= c->dia_size&0xFF;
+ const int dec= dia_size & (dia_size-1);
+ static const int hex[8][2]={{-2, 0}, {-1,-1}, { 0,-2}, { 1,-1},
+ { 2, 0}, { 1, 1}, { 0, 2}, {-1, 1}};
+
+ cmpf= s->dsp.me_cmp[size];
+ chroma_cmpf= s->dsp.me_cmp[size+1];
+
+ for(; dia_size; dia_size= dec ? dia_size-1 : dia_size>>1){
+ do{
+ x= best[0];
+ y= best[1];
+ for(i=0; i<8; i++){
+ CHECK_CLIPPED_MV(x+hex[i][0]*dia_size, y+hex[i][1]*dia_size);
+ }
+ }while(best[0] != x || best[1] != y);
+ }
+
+ x= best[0];
+ y= best[1];
+ CHECK_CLIPPED_MV(x+1, y);
+ CHECK_CLIPPED_MV(x, y+1);
+ CHECK_CLIPPED_MV(x-1, y);
+ CHECK_CLIPPED_MV(x, y-1);
+
+ return dmin;
+}
+
+static int umh_search(MpegEncContext * s, int *best, int dmin,
+ int src_index, int ref_index, int const penalty_factor,
+ int size, int h, int flags)
+{
+ MotionEstContext * const c= &s->me;
+ me_cmp_func cmpf, chroma_cmpf;
+ LOAD_COMMON
+ LOAD_COMMON2
+ int map_generation= c->map_generation;
+ int x,y,x2,y2, i, j, d;
+ const int dia_size= c->dia_size&0xFE;
+ static const int hex[16][2]={{-4,-2}, {-4,-1}, {-4, 0}, {-4, 1}, {-4, 2},
+ { 4,-2}, { 4,-1}, { 4, 0}, { 4, 1}, { 4, 2},
+ {-2, 3}, { 0, 4}, { 2, 3},
+ {-2,-3}, { 0,-4}, { 2,-3},};
+
+ cmpf= s->dsp.me_cmp[size];
+ chroma_cmpf= s->dsp.me_cmp[size+1];
+
+ x= best[0];
+ y= best[1];
+ for(x2=FFMAX(x-dia_size+1, xmin); x2<=FFMIN(x+dia_size-1,xmax); x2+=2){
+ CHECK_MV(x2, y);
+ }
+ for(y2=FFMAX(y-dia_size/2+1, ymin); y2<=FFMIN(y+dia_size/2-1,ymax); y2+=2){
+ CHECK_MV(x, y2);
+ }
+
+ x= best[0];
+ y= best[1];
+ for(y2=FFMAX(y-2, ymin); y2<=FFMIN(y+2,ymax); y2++){
+ for(x2=FFMAX(x-2, xmin); x2<=FFMIN(x+2,xmax); x2++){
+ CHECK_MV(x2, y2);
+ }
+ }
+
+//FIXME prevent the CLIP stuff
+
+ for(j=1; j<=dia_size/4; j++){
+ for(i=0; i<16; i++){
+ CHECK_CLIPPED_MV(x+hex[i][0]*j, y+hex[i][1]*j);
+ }
+ }
+
+ return hex_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags, 2);
+}
+
+#define SAB_CHECK_MV(ax,ay)\
+{\
+ const int key= ((ay)<<ME_MAP_MV_BITS) + (ax) + map_generation;\
+ const int index= (((ay)<<ME_MAP_SHIFT) + (ax))&(ME_MAP_SIZE-1);\
+/*printf("sab check %d %d\n", ax, ay);*/\
+ if(map[index]!=key){\
+ d= cmp(s, ax, ay, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
+ map[index]= key;\
+ score_map[index]= d;\
+ d += (mv_penalty[((ax)<<shift)-pred_x] + mv_penalty[((ay)<<shift)-pred_y])*penalty_factor;\
+/*printf("score: %d\n", d);*/\
+ if(d < minima[minima_count-1].height){\
+ int j=0;\
+ \
+ while(d >= minima[j].height) j++;\
+\
+ memmove(&minima [j+1], &minima [j], (minima_count - j - 1)*sizeof(Minima));\
+\
+ minima[j].checked= 0;\
+ minima[j].height= d;\
+ minima[j].x= ax;\
+ minima[j].y= ay;\
+ \
+ i=-1;\
+ continue;\
+ }\
+ }\
+}
+
+#define MAX_SAB_SIZE ME_MAP_SIZE
+static int sab_diamond_search(MpegEncContext * s, int *best, int dmin,
+ int src_index, int ref_index, int const penalty_factor,
+ int size, int h, int flags)
+{
+ MotionEstContext * const c= &s->me;
+ me_cmp_func cmpf, chroma_cmpf;
+ Minima minima[MAX_SAB_SIZE];
+ const int minima_count= FFABS(c->dia_size);
+ int i, j;
+ LOAD_COMMON
+ LOAD_COMMON2
+ int map_generation= c->map_generation;
+
+ cmpf= s->dsp.me_cmp[size];
+ chroma_cmpf= s->dsp.me_cmp[size+1];
+
+ /*Note j<MAX_SAB_SIZE is needed if MAX_SAB_SIZE < ME_MAP_SIZE as j can
+ become larger due to MVs overflowing their ME_MAP_MV_BITS bits space in map
+ */
+ for(j=i=0; i<ME_MAP_SIZE && j<MAX_SAB_SIZE; i++){
+ uint32_t key= map[i];
+
+ key += (1<<(ME_MAP_MV_BITS-1)) + (1<<(2*ME_MAP_MV_BITS-1));
+
+ if((key&((-1)<<(2*ME_MAP_MV_BITS))) != map_generation) continue;
+
+ minima[j].height= score_map[i];
+ minima[j].x= key & ((1<<ME_MAP_MV_BITS)-1); key>>=ME_MAP_MV_BITS;
+ minima[j].y= key & ((1<<ME_MAP_MV_BITS)-1);
+ minima[j].x-= (1<<(ME_MAP_MV_BITS-1));
+ minima[j].y-= (1<<(ME_MAP_MV_BITS-1));
+
+ // all entries in map should be in range except if the mv overflows their ME_MAP_MV_BITS bits space
+ if( minima[j].x > xmax || minima[j].x < xmin
+ || minima[j].y > ymax || minima[j].y < ymin)
+ continue;
+
+ minima[j].checked=0;
+ if(minima[j].x || minima[j].y)
+ minima[j].height+= (mv_penalty[((minima[j].x)<<shift)-pred_x] + mv_penalty[((minima[j].y)<<shift)-pred_y])*penalty_factor;
+
+ j++;
+ }
+
+ qsort(minima, j, sizeof(Minima), minima_cmp);
+
+ for(; j<minima_count; j++){
+ minima[j].height=256*256*256*64;
+ minima[j].checked=0;
+ minima[j].x= minima[j].y=0;
+ }
+
+ for(i=0; i<minima_count; i++){
+ const int x= minima[i].x;
+ const int y= minima[i].y;
+ int d;
+
+ if(minima[i].checked) continue;
+
+ if( x >= xmax || x <= xmin
+ || y >= ymax || y <= ymin)
+ continue;
+
+ SAB_CHECK_MV(x-1, y)
+ SAB_CHECK_MV(x+1, y)
+ SAB_CHECK_MV(x , y-1)
+ SAB_CHECK_MV(x , y+1)
+
+ minima[i].checked= 1;
+ }
+
+ best[0]= minima[0].x;
+ best[1]= minima[0].y;
+ dmin= minima[0].height;
+
+ if( best[0] < xmax && best[0] > xmin
+ && best[1] < ymax && best[1] > ymin){
+ int d;
+ //ensure that the refernece samples for hpel refinement are in the map
+ CHECK_MV(best[0]-1, best[1])
+ CHECK_MV(best[0]+1, best[1])
+ CHECK_MV(best[0], best[1]-1)
+ CHECK_MV(best[0], best[1]+1)
+ }
+ return dmin;
+}
+
+static int var_diamond_search(MpegEncContext * s, int *best, int dmin,
+ int src_index, int ref_index, int const penalty_factor,
+ int size, int h, int flags)
+{
+ MotionEstContext * const c= &s->me;
+ me_cmp_func cmpf, chroma_cmpf;
+ int dia_size;
+ LOAD_COMMON
+ LOAD_COMMON2
+ int map_generation= c->map_generation;
+
+ cmpf= s->dsp.me_cmp[size];
+ chroma_cmpf= s->dsp.me_cmp[size+1];
+
+ for(dia_size=1; dia_size<=c->dia_size; dia_size++){
+ int dir, start, end;
+ const int x= best[0];
+ const int y= best[1];
+
+ start= FFMAX(0, y + dia_size - ymax);
+ end = FFMIN(dia_size, xmax - x + 1);
+ for(dir= start; dir<end; dir++){
+ int d;
+
+//check(x + dir,y + dia_size - dir,0, a0)
+ CHECK_MV(x + dir , y + dia_size - dir);
+ }
+
+ start= FFMAX(0, x + dia_size - xmax);
+ end = FFMIN(dia_size, y - ymin + 1);
+ for(dir= start; dir<end; dir++){
+ int d;
+
+//check(x + dia_size - dir, y - dir,0, a1)
+ CHECK_MV(x + dia_size - dir, y - dir );
+ }
+
+ start= FFMAX(0, -y + dia_size + ymin );
+ end = FFMIN(dia_size, x - xmin + 1);
+ for(dir= start; dir<end; dir++){
+ int d;
+
+//check(x - dir,y - dia_size + dir,0, a2)
+ CHECK_MV(x - dir , y - dia_size + dir);
+ }
+
+ start= FFMAX(0, -x + dia_size + xmin );
+ end = FFMIN(dia_size, ymax - y + 1);
+ for(dir= start; dir<end; dir++){
+ int d;
+
+//check(x - dia_size + dir, y + dir,0, a3)
+ CHECK_MV(x - dia_size + dir, y + dir );
+ }
+
+ if(x!=best[0] || y!=best[1])
+ dia_size=0;
+#if 0
+{
+int dx, dy, i;
+static int stats[8*8];
+dx= FFABS(x-best[0]);
+dy= FFABS(y-best[1]);
+stats[dy*8 + dx] ++;
+if(256*256*256*64 % (stats[0]+1)==0){
+ for(i=0; i<64; i++){
+ if((i&7)==0) printf("\n");
+ printf("%6d ", stats[i]);
+ }
+ printf("\n");
+}
+}
+#endif
+ }
+ return dmin;
+}
+
+static av_always_inline int diamond_search(MpegEncContext * s, int *best, int dmin,
+ int src_index, int ref_index, int const penalty_factor,
+ int size, int h, int flags){
+ MotionEstContext * const c= &s->me;
+ if(c->dia_size==-1)
+ return funny_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
+ else if(c->dia_size<-1)
+ return sab_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
+ else if(c->dia_size<2)
+ return small_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
+ else if(c->dia_size>768)
+ return umh_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
+ else if(c->dia_size>512)
+ return hex_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags, c->dia_size&0xFF);
+ else if(c->dia_size>256)
+ return l2s_dia_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
+ else
+ return var_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
+}
+
+/*!
+ \param P[10][2] a list of candidate mvs to check before starting the
+ iterative search. If one of the candidates is close to the optimal mv, then
+ it takes fewer iterations. And it increases the chance that we find the
+ optimal mv.
+ */
+static av_always_inline int epzs_motion_search_internal(MpegEncContext * s, int *mx_ptr, int *my_ptr,
+ int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2],
+ int ref_mv_scale, int flags, int size, int h)
+{
+ MotionEstContext * const c= &s->me;
+ int best[2]={0, 0}; /*!< x and y coordinates of the best motion vector.
+ i.e. the difference between the position of the
+ block currently being encoded and the position of
+ the block chosen to predict it from. */
+ int d; ///< the score (cmp + penalty) of any given mv
+ int dmin; /*!< the best value of d, i.e. the score
+ corresponding to the mv stored in best[]. */
+ int map_generation;
+ int penalty_factor;
+ const int ref_mv_stride= s->mb_stride; //pass as arg FIXME
+ const int ref_mv_xy= s->mb_x + s->mb_y*ref_mv_stride; //add to last_mv beforepassing FIXME
+ me_cmp_func cmpf, chroma_cmpf;
+
+ LOAD_COMMON
+ LOAD_COMMON2
+
+ if(c->pre_pass){
+ penalty_factor= c->pre_penalty_factor;
+ cmpf= s->dsp.me_pre_cmp[size];
+ chroma_cmpf= s->dsp.me_pre_cmp[size+1];
+ }else{
+ penalty_factor= c->penalty_factor;
+ cmpf= s->dsp.me_cmp[size];
+ chroma_cmpf= s->dsp.me_cmp[size+1];
+ }
+
+ map_generation= update_map_generation(c);
+
+ assert(cmpf);
+ dmin= cmp(s, 0, 0, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);
+ map[0]= map_generation;
+ score_map[0]= dmin;
+
+ //FIXME precalc first term below?
+ if((s->pict_type == B_TYPE && !(c->flags & FLAG_DIRECT)) || s->flags&CODEC_FLAG_MV0)
+ dmin += (mv_penalty[pred_x] + mv_penalty[pred_y])*penalty_factor;
+
+ /* first line */
+ if (s->first_slice_line) {
+ CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
+ CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
+ (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
+ }else{
+ if(dmin<((h*h*s->avctx->mv0_threshold)>>8)
+ && ( P_LEFT[0] |P_LEFT[1]
+ |P_TOP[0] |P_TOP[1]
+ |P_TOPRIGHT[0]|P_TOPRIGHT[1])==0){
+ *mx_ptr= 0;
+ *my_ptr= 0;
+ c->skip=1;
+ return dmin;
+ }
+ CHECK_MV( P_MEDIAN[0] >>shift , P_MEDIAN[1] >>shift)
+ CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift) , (P_MEDIAN[1]>>shift)-1)
+ CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift) , (P_MEDIAN[1]>>shift)+1)
+ CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift)-1, (P_MEDIAN[1]>>shift) )
+ CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift)+1, (P_MEDIAN[1]>>shift) )
+ CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
+ (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
+ CHECK_MV(P_LEFT[0] >>shift, P_LEFT[1] >>shift)
+ CHECK_MV(P_TOP[0] >>shift, P_TOP[1] >>shift)
+ CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift)
+ }
+ if(dmin>h*h*4){
+ if(c->pre_pass){
+ CHECK_CLIPPED_MV((last_mv[ref_mv_xy-1][0]*ref_mv_scale + (1<<15))>>16,
+ (last_mv[ref_mv_xy-1][1]*ref_mv_scale + (1<<15))>>16)
+ if(!s->first_slice_line)
+ CHECK_CLIPPED_MV((last_mv[ref_mv_xy-ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
+ (last_mv[ref_mv_xy-ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
+ }else{
+ CHECK_CLIPPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16,
+ (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16)
+ if(s->mb_y+1<s->end_mb_y) //FIXME replace at least with last_slice_line
+ CHECK_CLIPPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
+ (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
+ }
+ }
+
+ if(c->avctx->last_predictor_count){
+ const int count= c->avctx->last_predictor_count;
+ const int xstart= FFMAX(0, s->mb_x - count);
+ const int ystart= FFMAX(0, s->mb_y - count);
+ const int xend= FFMIN(s->mb_width , s->mb_x + count + 1);
+ const int yend= FFMIN(s->mb_height, s->mb_y + count + 1);
+ int mb_y;
+
+ for(mb_y=ystart; mb_y<yend; mb_y++){
+ int mb_x;
+ for(mb_x=xstart; mb_x<xend; mb_x++){
+ const int xy= mb_x + 1 + (mb_y + 1)*ref_mv_stride;
+ int mx= (last_mv[xy][0]*ref_mv_scale + (1<<15))>>16;
+ int my= (last_mv[xy][1]*ref_mv_scale + (1<<15))>>16;
+
+ if(mx>xmax || mx<xmin || my>ymax || my<ymin) continue;
+ CHECK_MV(mx,my)
+ }
+ }
+ }
+
+//check(best[0],best[1],0, b0)
+ dmin= diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
+
+//check(best[0],best[1],0, b1)
+ *mx_ptr= best[0];
+ *my_ptr= best[1];
+
+// printf("%d %d %d \n", best[0], best[1], dmin);
+ return dmin;
+}
+
+//this function is dedicated to the braindamaged gcc
+inline int ff_epzs_motion_search(MpegEncContext * s, int *mx_ptr, int *my_ptr,
+ int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2],
+ int ref_mv_scale, int size, int h)
+{
+ MotionEstContext * const c= &s->me;
+//FIXME convert other functions in the same way if faster
+ if(c->flags==0 && h==16 && size==0){
+ return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, 0, 0, 16);
+// case FLAG_QPEL:
+// return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, FLAG_QPEL);
+ }else{
+ return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, c->flags, size, h);
+ }
+}
+
+static int epzs_motion_search4(MpegEncContext * s,
+ int *mx_ptr, int *my_ptr, int P[10][2],
+ int src_index, int ref_index, int16_t (*last_mv)[2],
+ int ref_mv_scale)
+{
+ MotionEstContext * const c= &s->me;
+ int best[2]={0, 0};
+ int d, dmin;
+ int map_generation;
+ const int penalty_factor= c->penalty_factor;
+ const int size=1;
+ const int h=8;
+ const int ref_mv_stride= s->mb_stride;
+ const int ref_mv_xy= s->mb_x + s->mb_y *ref_mv_stride;
+ me_cmp_func cmpf, chroma_cmpf;
+ LOAD_COMMON
+ int flags= c->flags;
+ LOAD_COMMON2
+
+ cmpf= s->dsp.me_cmp[size];
+ chroma_cmpf= s->dsp.me_cmp[size+1];
+
+ map_generation= update_map_generation(c);
+
+ dmin = 1000000;
+//printf("%d %d %d %d //",xmin, ymin, xmax, ymax);
+ /* first line */
+ if (s->first_slice_line) {
+ CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
+ CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
+ (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
+ CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
+ }else{
+ CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
+ //FIXME try some early stop
+ CHECK_MV(P_MEDIAN[0]>>shift, P_MEDIAN[1]>>shift)
+ CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
+ CHECK_MV(P_TOP[0]>>shift, P_TOP[1]>>shift)
+ CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift)
+ CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
+ (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
+ }
+ if(dmin>64*4){
+ CHECK_CLIPPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16,
+ (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16)
+ if(s->mb_y+1<s->end_mb_y) //FIXME replace at least with last_slice_line
+ CHECK_CLIPPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
+ (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
+ }
+
+ dmin= diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
+
+ *mx_ptr= best[0];
+ *my_ptr= best[1];
+
+// printf("%d %d %d \n", best[0], best[1], dmin);
+ return dmin;
+}
+
+//try to merge with above FIXME (needs PSNR test)
+static int epzs_motion_search2(MpegEncContext * s,
+ int *mx_ptr, int *my_ptr, int P[10][2],
+ int src_index, int ref_index, int16_t (*last_mv)[2],
+ int ref_mv_scale)
+{
+ MotionEstContext * const c= &s->me;
+ int best[2]={0, 0};
+ int d, dmin;
+ int map_generation;
+ const int penalty_factor= c->penalty_factor;
+ const int size=0; //FIXME pass as arg
+ const int h=8;
+ const int ref_mv_stride= s->mb_stride;
+ const int ref_mv_xy= s->mb_x + s->mb_y *ref_mv_stride;
+ me_cmp_func cmpf, chroma_cmpf;
+ LOAD_COMMON
+ int flags= c->flags;
+ LOAD_COMMON2
+
+ cmpf= s->dsp.me_cmp[size];
+ chroma_cmpf= s->dsp.me_cmp[size+1];
+
+ map_generation= update_map_generation(c);
+
+ dmin = 1000000;
+//printf("%d %d %d %d //",xmin, ymin, xmax, ymax);
+ /* first line */
+ if (s->first_slice_line) {
+ CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
+ CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
+ (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
+ CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
+ }else{
+ CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
+ //FIXME try some early stop
+ CHECK_MV(P_MEDIAN[0]>>shift, P_MEDIAN[1]>>shift)
+ CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
+ CHECK_MV(P_TOP[0]>>shift, P_TOP[1]>>shift)
+ CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift)
+ CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
+ (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
+ }
+ if(dmin>64*4){
+ CHECK_CLIPPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16,
+ (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16)
+ if(s->mb_y+1<s->end_mb_y) //FIXME replace at least with last_slice_line
+ CHECK_CLIPPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
+ (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
+ }
+
+ dmin= diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
+
+ *mx_ptr= best[0];
+ *my_ptr= best[1];
+
+// printf("%d %d %d \n", best[0], best[1], dmin);
+ return dmin;
+}
diff --git a/contrib/ffmpeg/libavcodec/motion_test.c b/contrib/ffmpeg/libavcodec/motion_test.c
new file mode 100644
index 000000000..ecdb62a4e
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/motion_test.c
@@ -0,0 +1,160 @@
+/*
+ * (c) 2001 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 motion_test.c
+ * motion test.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/time.h>
+#include <unistd.h>
+
+#include "dsputil.h"
+
+#include "i386/mmx.h"
+
+#undef exit
+#undef printf
+
+int pix_abs16x16_mmx(uint8_t *blk1, uint8_t *blk2, int lx);
+int pix_abs16x16_mmx1(uint8_t *blk1, uint8_t *blk2, int lx);
+int pix_abs16x16_c(uint8_t *blk1, uint8_t *blk2, int lx);
+int pix_abs16x16_x2_mmx(uint8_t *blk1, uint8_t *blk2, int lx);
+int pix_abs16x16_x2_mmx1(uint8_t *blk1, uint8_t *blk2, int lx);
+int pix_abs16x16_x2_c(uint8_t *blk1, uint8_t *blk2, int lx);
+int pix_abs16x16_y2_mmx(uint8_t *blk1, uint8_t *blk2, int lx);
+int pix_abs16x16_y2_mmx1(uint8_t *blk1, uint8_t *blk2, int lx);
+int pix_abs16x16_y2_c(uint8_t *blk1, uint8_t *blk2, int lx);
+int pix_abs16x16_xy2_mmx(uint8_t *blk1, uint8_t *blk2, int lx);
+int pix_abs16x16_xy2_mmx1(uint8_t *blk1, uint8_t *blk2, int lx);
+int pix_abs16x16_xy2_c(uint8_t *blk1, uint8_t *blk2, int lx);
+
+typedef int motion_func(uint8_t *blk1, uint8_t *blk2, int lx);
+
+#define WIDTH 64
+#define HEIGHT 64
+
+uint8_t img1[WIDTH * HEIGHT];
+uint8_t img2[WIDTH * HEIGHT];
+
+void fill_random(uint8_t *tab, int size)
+{
+ int i;
+ for(i=0;i<size;i++) {
+#if 1
+ tab[i] = random() % 256;
+#else
+ tab[i] = i;
+#endif
+ }
+}
+
+void help(void)
+{
+ printf("motion-test [-h]\n"
+ "test motion implementations\n");
+ exit(1);
+}
+
+int64_t gettime(void)
+{
+ struct timeval tv;
+ gettimeofday(&tv,NULL);
+ return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
+}
+
+#define NB_ITS 500
+
+int dummy;
+
+void test_motion(const char *name,
+ motion_func *test_func, motion_func *ref_func)
+{
+ int x, y, d1, d2, it;
+ uint8_t *ptr;
+ int64_t ti;
+ printf("testing '%s'\n", name);
+
+ /* test correctness */
+ for(it=0;it<20;it++) {
+
+ fill_random(img1, WIDTH * HEIGHT);
+ fill_random(img2, WIDTH * HEIGHT);
+
+ for(y=0;y<HEIGHT-17;y++) {
+ for(x=0;x<WIDTH-17;x++) {
+ ptr = img2 + y * WIDTH + x;
+ d1 = test_func(img1, ptr, WIDTH);
+ d2 = ref_func(img1, ptr, WIDTH);
+ if (d1 != d2) {
+ printf("error: mmx=%d c=%d\n", d1, d2);
+ }
+ }
+ }
+ }
+ emms();
+
+ /* speed test */
+ ti = gettime();
+ d1 = 0;
+ for(it=0;it<NB_ITS;it++) {
+ for(y=0;y<HEIGHT-17;y++) {
+ for(x=0;x<WIDTH-17;x++) {
+ ptr = img2 + y * WIDTH + x;
+ d1 += test_func(img1, ptr, WIDTH);
+ }
+ }
+ }
+ emms();
+ dummy = d1; /* avoid optimisation */
+ ti = gettime() - ti;
+
+ printf(" %0.0f kop/s\n",
+ (double)NB_ITS * (WIDTH - 16) * (HEIGHT - 16) /
+ (double)(ti / 1000.0));
+}
+
+
+int main(int argc, char **argv)
+{
+ int c;
+
+ for(;;) {
+ c = getopt(argc, argv, "h");
+ if (c == -1)
+ break;
+ switch(c) {
+ case 'h':
+ help();
+ break;
+ }
+ }
+
+ printf("ffmpeg motion test\n");
+
+ test_motion("mmx", pix_abs16x16_mmx, pix_abs16x16_c);
+ test_motion("mmx_x2", pix_abs16x16_x2_mmx, pix_abs16x16_x2_c);
+ test_motion("mmx_y2", pix_abs16x16_y2_mmx, pix_abs16x16_y2_c);
+ test_motion("mmx_xy2", pix_abs16x16_xy2_mmx, pix_abs16x16_xy2_c);
+ return 0;
+}
diff --git a/contrib/ffmpeg/libavcodec/mp3lameaudio.c b/contrib/ffmpeg/libavcodec/mp3lameaudio.c
new file mode 100644
index 000000000..d13350265
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/mp3lameaudio.c
@@ -0,0 +1,221 @@
+/*
+ * Interface to libmp3lame for mp3 encoding
+ * Copyright (c) 2002 Lennert Buytenhek <buytenh@gnu.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file mp3lameaudio.c
+ * Interface to libmp3lame for mp3 encoding.
+ */
+
+#include "avcodec.h"
+#include "mpegaudio.h"
+#include <lame/lame.h>
+
+#define BUFFER_SIZE (2*MPA_FRAME_SIZE)
+typedef struct Mp3AudioContext {
+ lame_global_flags *gfp;
+ int stereo;
+ uint8_t buffer[BUFFER_SIZE];
+ int buffer_index;
+} Mp3AudioContext;
+
+static int MP3lame_encode_init(AVCodecContext *avctx)
+{
+ Mp3AudioContext *s = avctx->priv_data;
+
+ if (avctx->channels > 2)
+ return -1;
+
+ s->stereo = avctx->channels > 1 ? 1 : 0;
+
+ if ((s->gfp = lame_init()) == NULL)
+ goto err;
+ lame_set_in_samplerate(s->gfp, avctx->sample_rate);
+ lame_set_out_samplerate(s->gfp, avctx->sample_rate);
+ lame_set_num_channels(s->gfp, avctx->channels);
+ /* lame 3.91 dies on quality != 5 */
+ lame_set_quality(s->gfp, 5);
+ /* lame 3.91 doesn't work in mono */
+ lame_set_mode(s->gfp, JOINT_STEREO);
+ lame_set_brate(s->gfp, avctx->bit_rate/1000);
+ if(avctx->flags & CODEC_FLAG_QSCALE) {
+ lame_set_brate(s->gfp, 0);
+ lame_set_VBR(s->gfp, vbr_default);
+ lame_set_VBR_q(s->gfp, avctx->global_quality / (float)FF_QP2LAMBDA);
+ }
+ lame_set_bWriteVbrTag(s->gfp,0);
+ if (lame_init_params(s->gfp) < 0)
+ goto err_close;
+
+ avctx->frame_size = lame_get_framesize(s->gfp);
+
+ avctx->coded_frame= avcodec_alloc_frame();
+ avctx->coded_frame->key_frame= 1;
+
+ return 0;
+
+err_close:
+ lame_close(s->gfp);
+err:
+ return -1;
+}
+
+static const int sSampleRates[3] = {
+ 44100, 48000, 32000
+};
+
+static const int sBitRates[2][3][15] = {
+ { { 0, 32, 64, 96,128,160,192,224,256,288,320,352,384,416,448},
+ { 0, 32, 48, 56, 64, 80, 96,112,128,160,192,224,256,320,384},
+ { 0, 32, 40, 48, 56, 64, 80, 96,112,128,160,192,224,256,320}
+ },
+ { { 0, 32, 48, 56, 64, 80, 96,112,128,144,160,176,192,224,256},
+ { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96,112,128,144,160},
+ { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96,112,128,144,160}
+ },
+};
+
+static const int sSamplesPerFrame[2][3] =
+{
+ { 384, 1152, 1152 },
+ { 384, 1152, 576 }
+};
+
+static const int sBitsPerSlot[3] = {
+ 32,
+ 8,
+ 8
+};
+
+static int mp3len(void *data, int *samplesPerFrame, int *sampleRate)
+{
+ uint8_t *dataTmp = (uint8_t *)data;
+ uint32_t header = ( (uint32_t)dataTmp[0] << 24 ) | ( (uint32_t)dataTmp[1] << 16 ) | ( (uint32_t)dataTmp[2] << 8 ) | (uint32_t)dataTmp[3];
+ int layerID = 3 - ((header >> 17) & 0x03);
+ int bitRateID = ((header >> 12) & 0x0f);
+ int sampleRateID = ((header >> 10) & 0x03);
+ int bitsPerSlot = sBitsPerSlot[layerID];
+ int isPadded = ((header >> 9) & 0x01);
+ static int const mode_tab[4]= {2,3,1,0};
+ int mode= mode_tab[(header >> 19) & 0x03];
+ int mpeg_id= mode>0;
+ int temp0, temp1, bitRate;
+
+ if ( (( header >> 21 ) & 0x7ff) != 0x7ff || mode == 3 || layerID==3 || sampleRateID==3) {
+ return -1;
+ }
+
+ if(!samplesPerFrame) samplesPerFrame= &temp0;
+ if(!sampleRate ) sampleRate = &temp1;
+
+// *isMono = ((header >> 6) & 0x03) == 0x03;
+
+ *sampleRate = sSampleRates[sampleRateID]>>mode;
+ bitRate = sBitRates[mpeg_id][layerID][bitRateID] * 1000;
+ *samplesPerFrame = sSamplesPerFrame[mpeg_id][layerID];
+//av_log(NULL, AV_LOG_DEBUG, "sr:%d br:%d spf:%d l:%d m:%d\n", *sampleRate, bitRate, *samplesPerFrame, layerID, mode);
+
+ return *samplesPerFrame * bitRate / (bitsPerSlot * *sampleRate) + isPadded;
+}
+
+static int MP3lame_encode_frame(AVCodecContext *avctx,
+ unsigned char *frame, int buf_size, void *data)
+{
+ Mp3AudioContext *s = avctx->priv_data;
+ int len;
+ int lame_result;
+
+ /* lame 3.91 dies on '1-channel interleaved' data */
+
+ if(data){
+ if (s->stereo) {
+ lame_result = lame_encode_buffer_interleaved(
+ s->gfp,
+ data,
+ avctx->frame_size,
+ s->buffer + s->buffer_index,
+ BUFFER_SIZE - s->buffer_index
+ );
+ } else {
+ lame_result = lame_encode_buffer(
+ s->gfp,
+ data,
+ data,
+ avctx->frame_size,
+ s->buffer + s->buffer_index,
+ BUFFER_SIZE - s->buffer_index
+ );
+ }
+ }else{
+ lame_result= lame_encode_flush(
+ s->gfp,
+ s->buffer + s->buffer_index,
+ BUFFER_SIZE - s->buffer_index
+ );
+ }
+
+ if(lame_result==-1) {
+ /* output buffer too small */
+ av_log(avctx, AV_LOG_ERROR, "lame: output buffer too small (buffer index: %d, free bytes: %d)\n", s->buffer_index, BUFFER_SIZE - s->buffer_index);
+ return 0;
+ }
+
+ s->buffer_index += lame_result;
+
+ if(s->buffer_index<4)
+ return 0;
+
+ len= mp3len(s->buffer, NULL, NULL);
+//av_log(avctx, AV_LOG_DEBUG, "in:%d packet-len:%d index:%d\n", avctx->frame_size, len, s->buffer_index);
+ if(len <= s->buffer_index){
+ memcpy(frame, s->buffer, len);
+ s->buffer_index -= len;
+
+ memmove(s->buffer, s->buffer+len, s->buffer_index);
+ //FIXME fix the audio codec API, so we dont need the memcpy()
+/*for(i=0; i<len; i++){
+ av_log(avctx, AV_LOG_DEBUG, "%2X ", frame[i]);
+}*/
+ return len;
+ }else
+ return 0;
+}
+
+static int MP3lame_encode_close(AVCodecContext *avctx)
+{
+ Mp3AudioContext *s = avctx->priv_data;
+
+ av_freep(&avctx->coded_frame);
+
+ lame_close(s->gfp);
+ return 0;
+}
+
+
+AVCodec mp3lame_encoder = {
+ "mp3",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_MP3,
+ sizeof(Mp3AudioContext),
+ MP3lame_encode_init,
+ MP3lame_encode_frame,
+ MP3lame_encode_close,
+ .capabilities= CODEC_CAP_DELAY,
+};
diff --git a/contrib/ffmpeg/libavcodec/mpc.c b/contrib/ffmpeg/libavcodec/mpc.c
new file mode 100644
index 000000000..f351c549f
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/mpc.c
@@ -0,0 +1,355 @@
+/*
+ * Musepack decoder
+ * Copyright (c) 2006 Konstantin Shishkov
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * @file mpc.c Musepack decoder
+ * MPEG Audio Layer 1/2 -like codec with frames of 1152 samples
+ * divided into 32 subbands.
+ */
+
+#include "avcodec.h"
+#include "bitstream.h"
+#include "dsputil.h"
+#include "random.h"
+
+#ifdef CONFIG_MPEGAUDIO_HP
+#define USE_HIGHPRECISION
+#endif
+#include "mpegaudio.h"
+
+#include "mpcdata.h"
+
+#define BANDS 32
+#define SAMPLES_PER_BAND 36
+#define MPC_FRAME_SIZE (BANDS * SAMPLES_PER_BAND)
+
+static VLC scfi_vlc, dscf_vlc, hdr_vlc, quant_vlc[MPC7_QUANT_VLC_TABLES][2];
+
+static DECLARE_ALIGNED_16(MPA_INT, mpa_window[512]);
+
+typedef struct {
+ DSPContext dsp;
+ int IS, MSS, gapless;
+ int lastframelen, bands;
+ int oldDSCF[2][BANDS];
+ AVRandomState rnd;
+ int frames_to_skip;
+ /* for synthesis */
+ 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]);
+} MPCContext;
+
+/** Subband structure - hold all variables for each subband */
+typedef struct {
+ int msf; ///< mid-stereo flag
+ int res[2];
+ int scfi[2];
+ int scf_idx[2][3];
+ int Q[2];
+}Band;
+
+static int mpc7_decode_init(AVCodecContext * avctx)
+{
+ int i, j;
+ MPCContext *c = avctx->priv_data;
+ GetBitContext gb;
+ uint8_t buf[16];
+ float f1=1.20050805774840750476 * 256;
+ static int vlc_inited = 0;
+
+ if(avctx->extradata_size < 16){
+ av_log(avctx, AV_LOG_ERROR, "Too small extradata size (%i)!\n", avctx->extradata_size);
+ return -1;
+ }
+ memset(c->oldDSCF, 0, sizeof(c->oldDSCF));
+ av_init_random(0xDEADBEEF, &c->rnd);
+ dsputil_init(&c->dsp, avctx);
+ c->dsp.bswap_buf(buf, avctx->extradata, 4);
+ ff_mpa_synth_init(mpa_window);
+ init_get_bits(&gb, buf, 128);
+
+ c->IS = get_bits1(&gb);
+ c->MSS = get_bits1(&gb);
+ c->bands = get_bits(&gb, 6);
+ if(c->bands >= BANDS){
+ av_log(avctx, AV_LOG_ERROR, "Too many bands: %i\n", c->bands);
+ return -1;
+ }
+ skip_bits(&gb, 88);
+ c->gapless = get_bits1(&gb);
+ c->lastframelen = get_bits(&gb, 11);
+ av_log(avctx, AV_LOG_DEBUG, "IS: %d, MSS: %d, TG: %d, LFL: %d, bands: %d\n",
+ c->IS, c->MSS, c->gapless, c->lastframelen, c->bands);
+ c->frames_to_skip = 0;
+
+ if(vlc_inited) return 0;
+ av_log(avctx, AV_LOG_DEBUG, "Initing VLC\n");
+ if(init_vlc(&scfi_vlc, MPC7_SCFI_BITS, MPC7_SCFI_SIZE,
+ &mpc7_scfi[1], 2, 1,
+ &mpc7_scfi[0], 2, 1, INIT_VLC_USE_STATIC)){
+ av_log(avctx, AV_LOG_ERROR, "Cannot init SCFI VLC\n");
+ return -1;
+ }
+ if(init_vlc(&dscf_vlc, MPC7_DSCF_BITS, MPC7_DSCF_SIZE,
+ &mpc7_dscf[1], 2, 1,
+ &mpc7_dscf[0], 2, 1, INIT_VLC_USE_STATIC)){
+ av_log(avctx, AV_LOG_ERROR, "Cannot init DSCF VLC\n");
+ return -1;
+ }
+ if(init_vlc(&hdr_vlc, MPC7_HDR_BITS, MPC7_HDR_SIZE,
+ &mpc7_hdr[1], 2, 1,
+ &mpc7_hdr[0], 2, 1, INIT_VLC_USE_STATIC)){
+ av_log(avctx, AV_LOG_ERROR, "Cannot init HDR VLC\n");
+ return -1;
+ }
+ for(i = 0; i < MPC7_QUANT_VLC_TABLES; i++){
+ for(j = 0; j < 2; j++){
+ if(init_vlc(&quant_vlc[i][j], 9, mpc7_quant_vlc_sizes[i],
+ &mpc7_quant_vlc[i][j][1], 4, 2,
+ &mpc7_quant_vlc[i][j][0], 4, 2, INIT_VLC_USE_STATIC)){
+ av_log(avctx, AV_LOG_ERROR, "Cannot init QUANT VLC %i,%i\n",i,j);
+ return -1;
+ }
+ }
+ }
+ vlc_inited = 1;
+ return 0;
+}
+
+/**
+ * Process decoded Musepack data and produce PCM
+ * @todo make it available for MPC8 and MPC6
+ */
+static void mpc_synth(MPCContext *c, int16_t *out)
+{
+ int dither_state = 0;
+ int i, ch;
+ OUT_INT samples[MPA_MAX_CHANNELS * MPA_FRAME_SIZE], *samples_ptr;
+
+ for(ch = 0; ch < 2; ch++){
+ 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,
+ samples_ptr, 2,
+ c->sb_samples[ch][i]);
+ samples_ptr += 64;
+ }
+ }
+ for(i = 0; i < MPC_FRAME_SIZE*2; i++)
+ *out++=samples[i];
+}
+
+/**
+ * Fill samples for given subband
+ */
+static void inline idx_to_quant(MPCContext *c, GetBitContext *gb, int idx, int *dst)
+{
+ int i, i1, t;
+ switch(idx){
+ case -1:
+ for(i = 0; i < SAMPLES_PER_BAND; i++){
+ *dst++ = (av_random(&c->rnd) & 0x3FC) - 510;
+ }
+ break;
+ case 1:
+ i1 = get_bits1(gb);
+ for(i = 0; i < SAMPLES_PER_BAND/3; i++){
+ t = get_vlc2(gb, quant_vlc[0][i1].table, 9, 2);
+ *dst++ = mpc_idx30[t];
+ *dst++ = mpc_idx31[t];
+ *dst++ = mpc_idx32[t];
+ }
+ break;
+ case 2:
+ i1 = get_bits1(gb);
+ for(i = 0; i < SAMPLES_PER_BAND/2; i++){
+ t = get_vlc2(gb, quant_vlc[1][i1].table, 9, 2);
+ *dst++ = mpc_idx50[t];
+ *dst++ = mpc_idx51[t];
+ }
+ break;
+ case 3: case 4: case 5: case 6: case 7:
+ i1 = get_bits1(gb);
+ for(i = 0; i < SAMPLES_PER_BAND; i++)
+ *dst++ = get_vlc2(gb, quant_vlc[idx-1][i1].table, 9, 2) - mpc7_quant_vlc_off[idx-1];
+ break;
+ case 8: case 9: case 10: case 11: case 12:
+ case 13: case 14: case 15: case 16: case 17:
+ t = (1 << (idx - 2)) - 1;
+ for(i = 0; i < SAMPLES_PER_BAND; i++)
+ *dst++ = get_bits(gb, idx - 1) - t;
+ break;
+ default: // case 0 and -2..-17
+ return;
+ }
+}
+
+static int mpc7_decode_frame(AVCodecContext * avctx,
+ void *data, int *data_size,
+ uint8_t * buf, int buf_size)
+{
+ MPCContext *c = avctx->priv_data;
+ GetBitContext gb;
+ uint8_t *bits;
+ int i, j, ch, t;
+ int mb = -1;
+ Band bands[BANDS];
+ int Q[2][MPC_FRAME_SIZE];
+ int off;
+ float mul;
+ int bits_used, bits_avail;
+
+ memset(bands, 0, sizeof(bands));
+ if(buf_size <= 4){
+ av_log(avctx, AV_LOG_ERROR, "Too small buffer passed (%i bytes)\n", buf_size);
+ }
+
+ bits = av_malloc(((buf_size - 1) & ~3) + FF_INPUT_BUFFER_PADDING_SIZE);
+ c->dsp.bswap_buf(bits, buf + 4, (buf_size - 4) >> 2);
+ init_get_bits(&gb, bits, (buf_size - 4)* 8);
+ skip_bits(&gb, buf[0]);
+
+ /* read subband indexes */
+ for(i = 0; i <= c->bands; i++){
+ for(ch = 0; ch < 2; ch++){
+ 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);
+ else bands[i].res[ch] = bands[i-1].res[ch] + t;
+ }
+
+ if(bands[i].res[0] || bands[i].res[1]){
+ mb = i;
+ if(c->MSS) bands[i].msf = get_bits1(&gb);
+ }
+ }
+ /* get scale indexes coding method */
+ for(i = 0; i <= mb; i++)
+ for(ch = 0; ch < 2; ch++)
+ if(bands[i].res[ch]) bands[i].scfi[ch] = get_vlc2(&gb, scfi_vlc.table, MPC7_SCFI_BITS, 1);
+ /* get scale indexes */
+ for(i = 0; i <= mb; i++){
+ 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);
+ 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);
+ 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][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);
+ break;
+ case 3:
+ bands[i].scf_idx[ch][2] = bands[i].scf_idx[ch][1] = bands[i].scf_idx[ch][0];
+ break;
+ }
+ c->oldDSCF[ch][i] = bands[i].scf_idx[ch][2];
+ }
+ }
+ }
+ /* get quantizers */
+ memset(Q, 0, sizeof(Q));
+ off = 0;
+ for(i = 0; i < BANDS; i++, off += SAMPLES_PER_BAND)
+ for(ch = 0; ch < 2; ch++)
+ idx_to_quant(c, &gb, bands[i].res[ch], Q[ch] + off);
+ /* dequantize */
+ memset(c->sb_samples, 0, sizeof(c->sb_samples));
+ off = 0;
+ for(i = 0; i <= mb; i++, off += SAMPLES_PER_BAND){
+ for(ch = 0; ch < 2; ch++){
+ if(bands[i].res[ch]){
+ j = 0;
+ mul = mpc_CC[bands[i].res[ch]] * mpc7_SCF[bands[i].scf_idx[ch][0]];
+ for(; j < 12; j++)
+ c->sb_samples[ch][j][i] = mul * Q[ch][j + off];
+ mul = mpc_CC[bands[i].res[ch]] * mpc7_SCF[bands[i].scf_idx[ch][1]];
+ for(; j < 24; j++)
+ c->sb_samples[ch][j][i] = mul * Q[ch][j + off];
+ mul = mpc_CC[bands[i].res[ch]] * mpc7_SCF[bands[i].scf_idx[ch][2]];
+ for(; j < 36; j++)
+ c->sb_samples[ch][j][i] = mul * Q[ch][j + off];
+ }
+ }
+ if(bands[i].msf){
+ int t1, t2;
+ for(j = 0; j < SAMPLES_PER_BAND; j++){
+ t1 = c->sb_samples[0][j][i];
+ t2 = c->sb_samples[1][j][i];
+ c->sb_samples[0][j][i] = t1 + t2;
+ c->sb_samples[1][j][i] = t1 - t2;
+ }
+ }
+ }
+
+ mpc_synth(c, data);
+
+ av_free(bits);
+
+ bits_used = get_bits_count(&gb);
+ bits_avail = (buf_size - 4) * 8;
+ if(!buf[1] && ((bits_avail < bits_used) || (bits_used + 32 <= bits_avail))){
+ av_log(NULL,0, "Error decoding frame: used %i of %i bits\n", bits_used, bits_avail);
+ return -1;
+ }
+ if(c->frames_to_skip){
+ c->frames_to_skip--;
+ *data_size = 0;
+ return buf_size;
+ }
+ *data_size = (buf[1] ? c->lastframelen : MPC_FRAME_SIZE) * 4;
+
+ return buf_size;
+}
+
+static void mpc7_decode_flush(AVCodecContext *avctx)
+{
+ MPCContext *c = avctx->priv_data;
+
+ memset(c->oldDSCF, 0, sizeof(c->oldDSCF));
+ c->frames_to_skip = 32;
+}
+
+AVCodec mpc7_decoder = {
+ "mpc sv7",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_MUSEPACK7,
+ sizeof(MPCContext),
+ mpc7_decode_init,
+ NULL,
+ NULL,
+ mpc7_decode_frame,
+ .flush = mpc7_decode_flush,
+};
diff --git a/contrib/ffmpeg/libavcodec/mpcdata.h b/contrib/ffmpeg/libavcodec/mpcdata.h
new file mode 100644
index 000000000..2b74765ed
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/mpcdata.h
@@ -0,0 +1,206 @@
+/*
+ * Musepack decoder
+ * Copyright (c) 2006 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
+ *
+ */
+
+static const int8_t mpc_idx30[] = { -1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1};
+static const int8_t mpc_idx31[] = { -1,-1,-1, 0, 0, 0, 1, 1, 1,-1,-1,-1, 0, 0, 0, 1, 1, 1,-1,-1,-1, 0, 0, 0, 1, 1, 1};
+static const int8_t mpc_idx32[] = { -1,-1,-1,-1,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1};
+static const int8_t mpc_idx50[] = { -2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2};
+static const int8_t mpc_idx51[] = { -2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2};
+
+static const float mpc_CC[18] = {
+ 65536.0000, 21845.3333, 13107.2000, 9362.2857, 7281.7778, 4369.0667, 2114.0645,
+ 1040.2539, 516.0315, 257.0039, 128.2505, 64.0626, 32.0156, 16.0039, 8.0010,
+ 4.0002, 2.0001, 1.0000
+};
+
+#define MPC7_SCFI_SIZE 4
+#define MPC7_SCFI_BITS 3
+static const uint8_t mpc7_scfi[MPC7_SCFI_SIZE * 2] = {
+ 0x2, 3, 0x1, 1, 0x3, 3, 0x0, 2
+};
+
+#define MPC7_DSCF_SIZE 16
+#define MPC7_DSCF_BITS 6
+static const uint8_t mpc7_dscf[MPC7_DSCF_SIZE * 2] = {
+ 0x20, 6, 0x04, 5, 0x11, 5, 0x1E, 5, 0x0D, 4, 0x00, 3, 0x03, 3, 0x09, 4,
+ 0x05, 3, 0x02, 3, 0x0E, 4, 0x03, 4, 0x1F, 5, 0x05, 5, 0x21, 6, 0x0C, 4
+};
+
+#define MPC7_HDR_SIZE 10
+#define MPC7_HDR_BITS 9
+static const uint8_t mpc7_hdr[MPC7_HDR_SIZE * 2] = {
+ 0x5C, 8, 0x2F, 7, 0x0A, 5, 0x04, 4, 0x00, 2,
+ 0x01, 1, 0x03, 3, 0x16, 6, 0xBB, 9, 0xBA, 9
+};
+
+#define MPC7_QUANT_VLC_TABLES 7
+static const uint8_t mpc7_quant_vlc_sizes[MPC7_QUANT_VLC_TABLES * 2] = {
+ 27, 25, 7, 9, 15, 31, 63
+};
+
+static const uint8_t mpc7_quant_vlc_off[MPC7_QUANT_VLC_TABLES] = {
+ 0, 0, 3, 4, 7, 15, 31
+};
+
+static const uint16_t mpc7_quant_vlc[MPC7_QUANT_VLC_TABLES][2][64 * 2] = {
+{
+ {
+ 0x0036, 6, 0x0009, 5, 0x0020, 6, 0x0005, 5, 0x000A, 4, 0x0007, 5,
+ 0x0034, 6, 0x0000, 5, 0x0023, 6, 0x000A, 5, 0x0006, 4, 0x0004, 5,
+ 0x000B, 4, 0x0007, 3, 0x000C, 4, 0x0003, 5, 0x0007, 4, 0x000B, 5,
+ 0x0022, 6, 0x0001, 5, 0x0035, 6, 0x0006, 5, 0x0009, 4, 0x0002, 5,
+ 0x0021, 6, 0x0008, 5, 0x0037, 6
+ },
+ {
+ 0x0067, 8, 0x003E, 7, 0x00E1, 9, 0x0037, 7, 0x0003, 4, 0x0034, 7,
+ 0x0065, 8, 0x003C, 7, 0x00E3, 9, 0x0018, 6, 0x0000, 4, 0x003D, 7,
+ 0x0004, 4, 0x0001, 1, 0x0005, 4, 0x003F, 7, 0x0001, 4, 0x003B, 7,
+ 0x00E2, 9, 0x0039, 7, 0x0064, 8, 0x0035, 7, 0x0002, 4, 0x0036, 7,
+ 0x00E0, 9, 0x003A, 7, 0x0066, 8
+ }
+},
+{
+ {
+ 0x0059, 7, 0x002F, 6, 0x000F, 5, 0x0000, 5, 0x005B, 7, 0x0004, 5,
+ 0x0006, 4, 0x000D, 4, 0x0004, 4, 0x0005, 5, 0x0014, 5, 0x000C, 4,
+ 0x0004, 3, 0x000F, 4, 0x000E, 5, 0x0003, 5, 0x0003, 4, 0x000E, 4,
+ 0x0005, 4, 0x0001, 5, 0x005A, 7, 0x0002, 5, 0x0015, 5, 0x002E, 6,
+ 0x0058, 7
+ },
+ {
+ 0x0399, 10, 0x0071, 7, 0x0033, 6, 0x00E7, 8, 0x039A, 10, 0x0068, 7,
+ 0x001E, 5, 0x0000, 3, 0x001D, 5, 0x0069, 7, 0x0032, 6, 0x0001, 3,
+ 0x0002, 2, 0x0003, 3, 0x0031, 6, 0x006B, 7, 0x001B, 5, 0x0002, 3,
+ 0x001F, 5, 0x0070, 7, 0x0398, 10, 0x006A, 7, 0x0030, 6, 0x0072, 7,
+ 0x039B, 10
+ }
+},
+{
+ {
+ 0x000C, 4, 0x0004, 3, 0x0000, 2, 0x0001, 2, 0x0007, 3, 0x0005, 3, 0x000D, 4
+ },
+ {
+ 0x0004, 5, 0x0003, 4, 0x0002, 2, 0x0003, 2, 0x0001, 2, 0x0000, 3, 0x0005, 5
+ }
+},
+{
+ {
+ 0x0005, 4, 0x0000, 3, 0x0004, 3, 0x0006, 3, 0x0007, 3, 0x0005, 3, 0x0003, 3, 0x0001, 3, 0x0004, 4
+ },
+ {
+ 0x0009, 5, 0x000C, 4, 0x0003, 3, 0x0000, 2, 0x0002, 2, 0x0007, 3, 0x000D, 4, 0x0005, 4, 0x0008, 5
+ }
+},
+{
+ {
+ 0x0039, 6, 0x0017, 5, 0x0008, 4, 0x000A, 4, 0x000D, 4, 0x0000, 3,
+ 0x0002, 3, 0x0003, 3, 0x0001, 3, 0x000F, 4, 0x000C, 4, 0x0009, 4,
+ 0x001D, 5, 0x0016, 5, 0x0038, 6,
+ },
+ {
+ 0x00E5, 8, 0x0038, 6, 0x0007, 5, 0x0002, 4, 0x0000, 3, 0x0003, 3,
+ 0x0005, 3, 0x0006, 3, 0x0004, 3, 0x0002, 3, 0x000F, 4, 0x001D, 5,
+ 0x0006, 5, 0x0073, 7, 0x00E4, 8,
+ },
+},
+{
+ {
+ 0x0041, 7, 0x0006, 6, 0x002C, 6, 0x002D, 6, 0x003B, 6, 0x000D, 5,
+ 0x0011, 5, 0x0013, 5, 0x0017, 5, 0x0015, 5, 0x001A, 5, 0x001E, 5,
+ 0x0000, 4, 0x0002, 4, 0x0005, 4, 0x0007, 4, 0x0003, 4, 0x0004, 4,
+ 0x001F, 5, 0x001C, 5, 0x0019, 5, 0x001B, 5, 0x0018, 5, 0x0014, 5,
+ 0x0012, 5, 0x000C, 5, 0x0002, 5, 0x003A, 6, 0x0021, 6, 0x0007, 6,
+ 0x0040, 7
+ },
+ {
+ 0x1948, 13, 0x194A, 13, 0x0328, 10, 0x0195, 9, 0x00CB, 8, 0x0066, 7,
+ 0x0031, 6, 0x0009, 5, 0x000F, 5, 0x001F, 5, 0x0002, 4, 0x0006, 4,
+ 0x0008, 4, 0x000B, 4, 0x000D, 4, 0x0000, 3, 0x000E, 4, 0x000A, 4,
+ 0x0009, 4, 0x0005, 4, 0x0003, 4, 0x001E, 5, 0x000E, 5, 0x0008, 5,
+ 0x0030, 6, 0x0067, 7, 0x00C9, 8, 0x00C8, 8, 0x0653, 11, 0x1949, 13,
+ 0x194B, 13
+ }
+},
+{
+ {
+ 0x0067, 8, 0x0099, 8, 0x00B5, 8, 0x00E9, 8, 0x0040, 7, 0x0041, 7,
+ 0x004D, 7, 0x0051, 7, 0x005B, 7, 0x0071, 7, 0x0070, 7, 0x0018, 6,
+ 0x001D, 6, 0x0023, 6, 0x0025, 6, 0x0029, 6, 0x002C, 6, 0x002E, 6,
+ 0x0033, 6, 0x0031, 6, 0x0036, 6, 0x0037, 6, 0x0039, 6, 0x003C, 6,
+ 0x0000, 5, 0x0002, 5, 0x000A, 5, 0x0005, 5, 0x0009, 5, 0x0006, 5,
+ 0x000D, 5, 0x0007, 5, 0x000B, 5, 0x000F, 5, 0x0008, 5, 0x0004, 5,
+ 0x0003, 5, 0x0001, 5, 0x003F, 6, 0x003E, 6, 0x003D, 6, 0x0035, 6,
+ 0x003B, 6, 0x0034, 6, 0x0030, 6, 0x002F, 6, 0x002B, 6, 0x002A, 6,
+ 0x0027, 6, 0x0024, 6, 0x0021, 6, 0x001C, 6, 0x0075, 7, 0x0065, 7,
+ 0x0064, 7, 0x0050, 7, 0x0045, 7, 0x0044, 7, 0x0032, 7, 0x00E8, 8,
+ 0x00B4, 8, 0x0098, 8, 0x0066, 8
+ },
+ {
+ 0x37A4, 14, 0x37AD, 14, 0x37A6, 14, 0x37AE, 14, 0x0DEA, 12, 0x02F0, 10,
+ 0x02F1, 10, 0x00A0, 9, 0x00A2, 9, 0x01BC, 9, 0x007A, 8, 0x00DF, 8,
+ 0x003C, 7, 0x0049, 7, 0x006E, 7, 0x000E, 6, 0x0018, 6, 0x0019, 6,
+ 0x0022, 6, 0x0025, 6, 0x0036, 6, 0x0003, 5, 0x0009, 5, 0x000B, 5,
+ 0x0010, 5, 0x0013, 5, 0x0015, 5, 0x0018, 5, 0x001A, 5, 0x001D, 5,
+ 0x001F, 5, 0x0002, 4, 0x0000, 4, 0x001E, 5, 0x001C, 5, 0x0019, 5,
+ 0x0016, 5, 0x0014, 5, 0x000E, 5, 0x000D, 5, 0x0008, 5, 0x0006, 5,
+ 0x0002, 5, 0x002E, 6, 0x0023, 6, 0x001F, 6, 0x0015, 6, 0x000F, 6,
+ 0x005F, 7, 0x0048, 7, 0x0029, 7, 0x00BD, 8, 0x007B, 8, 0x0179, 9,
+ 0x00A1, 9, 0x037B, 10, 0x0147, 10, 0x0146, 10, 0x0DE8, 12, 0x37AF, 14,
+ 0x37A7, 14, 0x37AC, 14, 0x37A5, 14
+ }
+}
+};
+
+static const float mpc7_SCF[128] = {
+ 307.330047607421875000, 255.999984741210937500, 213.243041992187500000, 177.627334594726562500,
+ 147.960128784179687500, 123.247924804687500000, 102.663139343261718750, 85.516410827636718750,
+ 71.233520507812500000, 59.336143493652343750, 49.425861358642578125, 41.170787811279296875,
+ 34.294471740722656250, 28.566631317138671875, 23.795452117919921875, 19.821151733398437500,
+ 16.510635375976562500, 13.753040313720703125, 11.456016540527343750, 9.542640686035156250,
+ 7.948835372924804688, 6.621226310729980469, 5.515353679656982422, 4.594182968139648438,
+ 3.826865673065185547, 3.187705039978027344, 2.655296564102172852, 2.211810588836669922,
+ 1.842395424842834473, 1.534679770469665527, 1.278358578681945801, 1.064847946166992188,
+ 0.886997759342193604, 0.738851964473724365, 0.615449428558349609, 0.512657463550567627,
+ 0.427033752202987671, 0.355710864067077637, 0.296300262212753296, 0.246812388300895691,
+ 0.205589950084686279, 0.171252459287643433, 0.142649993300437927, 0.118824683129787445,
+ 0.098978661000728607, 0.082447312772274017, 0.068677015602588654, 0.057206626981496811,
+ 0.047652013599872589, 0.039693206548690796, 0.033063672482967377, 0.027541399002075195,
+ 0.022941453382372856, 0.019109787419438362, 0.015918083488941193, 0.013259455561637878,
+ 0.011044870130717754, 0.009200163185596466, 0.007663558237254620, 0.006383595988154411,
+ 0.005317411851137877, 0.004429301247000694, 0.003689522389322519, 0.003073300700634718,
+ 0.002560000168159604, 0.002132430672645569, 0.001776273478753865, 0.001479601487517357,
+ 0.001232479466125369, 0.001026631565764546, 0.000855164253152907, 0.000712335284333676,
+ 0.000593361502978951, 0.000494258652906865, 0.000411707907915115, 0.000342944724252447,
+ 0.000285666319541633, 0.000237954518524930, 0.000198211506358348, 0.000165106350323185,
+ 0.000137530398205854, 0.000114560163638089, 0.000095426403277088, 0.000079488345363643,
+ 0.000066212254751008, 0.000055153526773211, 0.000045941822463647, 0.000038268648495432,
+ 0.000031877043511486, 0.000026552961571724, 0.000022118103515822, 0.000018423952496960,
+ 0.000015346795407822, 0.000012783583770215, 0.000010648477655195, 0.000008869976227288,
+ 0.000007388518497464, 0.000006154492893984, 0.000005126573796588, 0.000004270336830814,
+ 0.000003557107902452, 0.000002963002089018, 0.000002468123511790, 0.000002055899130937,
+ 0.000001712524181130, 0.000001426499579793, 0.000001188246528727, 0.000000989786371974,
+ 0.000000824472920158, 0.000000686770022185, 0.000000572066142013, 0.000000476520028769,
+ 0.000000396931966407, 0.000000330636652279, 0.000000275413924555, 0.000000229414467867,
+ 0.000000191097811353, 0.000000159180785886, 0.000000132594522029, 0.000000110448674207,
+ 0.000000092001613439, 0.000000076635565449, 0.000000063835940978, 0.000000053174105119,
+ 0.000000044293003043, 0.000000036895215771, 0.000000030733001921, 0.000000025599996789
+};
diff --git a/contrib/ffmpeg/libavcodec/mpeg12.c b/contrib/ffmpeg/libavcodec/mpeg12.c
new file mode 100644
index 000000000..c0fa7e4bc
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/mpeg12.c
@@ -0,0 +1,3557 @@
+/*
+ * MPEG1 codec / MPEG2 decoder
+ * Copyright (c) 2000,2001 Fabrice Bellard.
+ * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file mpeg12.c
+ * MPEG1/2 codec
+ */
+
+//#define DEBUG
+#include "avcodec.h"
+#include "dsputil.h"
+#include "mpegvideo.h"
+
+#include "mpeg12data.h"
+#include "bytestream.h"
+
+//#undef NDEBUG
+//#include <assert.h>
+
+
+/* Start codes. */
+#define SEQ_END_CODE 0x000001b7
+#define SEQ_START_CODE 0x000001b3
+#define GOP_START_CODE 0x000001b8
+#define PICTURE_START_CODE 0x00000100
+#define SLICE_MIN_START_CODE 0x00000101
+#define SLICE_MAX_START_CODE 0x000001af
+#define EXT_START_CODE 0x000001b5
+#define USER_START_CODE 0x000001b2
+
+#define DC_VLC_BITS 9
+#define MV_VLC_BITS 9
+#define MBINCR_VLC_BITS 9
+#define MB_PAT_VLC_BITS 9
+#define MB_PTYPE_VLC_BITS 6
+#define MB_BTYPE_VLC_BITS 6
+#define TEX_VLC_BITS 9
+
+#ifdef CONFIG_ENCODERS
+static void mpeg1_encode_block(MpegEncContext *s,
+ DCTELEM *block,
+ int component);
+static void mpeg1_encode_motion(MpegEncContext *s, int val, int f_or_b_code); // RAL: f_code parameter added
+#endif //CONFIG_ENCODERS
+static inline int mpeg1_decode_block_inter(MpegEncContext *s,
+ DCTELEM *block,
+ int n);
+static inline int mpeg1_decode_block_intra(MpegEncContext *s,
+ DCTELEM *block,
+ int n);
+static inline int mpeg1_fast_decode_block_inter(MpegEncContext *s, DCTELEM *block, int n);
+static inline int mpeg2_decode_block_non_intra(MpegEncContext *s,
+ DCTELEM *block,
+ int n);
+static inline int mpeg2_decode_block_intra(MpegEncContext *s,
+ DCTELEM *block,
+ int n);
+static inline int mpeg2_fast_decode_block_non_intra(MpegEncContext *s, DCTELEM *block, int n);
+static inline int mpeg2_fast_decode_block_intra(MpegEncContext *s, DCTELEM *block, int n);
+static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred);
+static void exchange_uv(MpegEncContext *s);
+
+#ifdef HAVE_XVMC
+extern int XVMC_field_start(MpegEncContext *s, AVCodecContext *avctx);
+extern int XVMC_field_end(MpegEncContext *s);
+extern void XVMC_pack_pblocks(MpegEncContext *s,int cbp);
+extern void XVMC_init_block(MpegEncContext *s);//set s->block
+#endif
+
+static const enum PixelFormat pixfmt_yuv_420[]= {PIX_FMT_YUV420P,-1};
+static const enum PixelFormat pixfmt_yuv_422[]= {PIX_FMT_YUV422P,-1};
+static const enum PixelFormat pixfmt_yuv_444[]= {PIX_FMT_YUV444P,-1};
+static const enum PixelFormat pixfmt_xvmc_mpg2_420[] = {
+ PIX_FMT_XVMC_MPEG2_IDCT,
+ PIX_FMT_XVMC_MPEG2_MC,
+ -1};
+#ifdef CONFIG_ENCODERS
+static uint8_t mv_penalty[MAX_FCODE+1][MAX_MV*2+1];
+static uint8_t fcode_tab[MAX_MV*2+1];
+
+static uint8_t uni_mpeg1_ac_vlc_len [64*64*2];
+static uint8_t uni_mpeg2_ac_vlc_len [64*64*2];
+
+/* simple include everything table for dc, first byte is bits number next 3 are code*/
+static uint32_t mpeg1_lum_dc_uni[512];
+static uint32_t mpeg1_chr_dc_uni[512];
+
+static uint8_t mpeg1_index_run[2][64];
+static int8_t mpeg1_max_level[2][64];
+#endif //CONFIG_ENCODERS
+
+static uint8_t static_rl_table_store[2][2][2*MAX_RUN + MAX_LEVEL + 3];
+
+static void init_2d_vlc_rl(RLTable *rl, int use_static)
+{
+ int i;
+
+ init_vlc(&rl->vlc, TEX_VLC_BITS, rl->n + 2,
+ &rl->table_vlc[0][1], 4, 2,
+ &rl->table_vlc[0][0], 4, 2, use_static);
+
+ if(use_static)
+ rl->rl_vlc[0]= av_mallocz_static(rl->vlc.table_size*sizeof(RL_VLC_ELEM));
+ else
+ rl->rl_vlc[0]= av_malloc(rl->vlc.table_size*sizeof(RL_VLC_ELEM));
+
+ for(i=0; i<rl->vlc.table_size; i++){
+ int code= rl->vlc.table[i][0];
+ int len = rl->vlc.table[i][1];
+ int level, run;
+
+ if(len==0){ // illegal code
+ run= 65;
+ level= MAX_LEVEL;
+ }else if(len<0){ //more bits needed
+ run= 0;
+ level= code;
+ }else{
+ if(code==rl->n){ //esc
+ run= 65;
+ level= 0;
+ }else if(code==rl->n+1){ //eob
+ run= 0;
+ level= 127;
+ }else{
+ run= rl->table_run [code] + 1;
+ level= rl->table_level[code];
+ }
+ }
+ rl->rl_vlc[0][i].len= len;
+ rl->rl_vlc[0][i].level= level;
+ rl->rl_vlc[0][i].run= run;
+ }
+}
+
+#ifdef CONFIG_ENCODERS
+static void init_uni_ac_vlc(RLTable *rl, uint8_t *uni_ac_vlc_len){
+ int i;
+
+ for(i=0; i<128; i++){
+ int level= i-64;
+ int run;
+ for(run=0; run<64; run++){
+ int len, bits, code;
+
+ int alevel= FFABS(level);
+ int sign= (level>>31)&1;
+
+ if (alevel > rl->max_level[0][run])
+ code= 111; /*rl->n*/
+ else
+ code= rl->index_run[0][run] + alevel - 1;
+
+ if (code < 111 /* rl->n */) {
+ /* store the vlc & sign at once */
+ len= rl->table_vlc[code][1]+1;
+ bits= (rl->table_vlc[code][0]<<1) + sign;
+ } else {
+ len= rl->table_vlc[111/*rl->n*/][1]+6;
+ bits= rl->table_vlc[111/*rl->n*/][0]<<6;
+
+ bits|= run;
+ if (alevel < 128) {
+ bits<<=8; len+=8;
+ bits|= level & 0xff;
+ } else {
+ bits<<=16; len+=16;
+ bits|= level & 0xff;
+ if (level < 0) {
+ bits|= 0x8001 + level + 255;
+ } else {
+ bits|= level & 0xffff;
+ }
+ }
+ }
+
+ uni_ac_vlc_len [UNI_AC_ENC_INDEX(run, i)]= len;
+ }
+ }
+}
+
+
+static int find_frame_rate_index(MpegEncContext *s){
+ int i;
+ int64_t dmin= INT64_MAX;
+ int64_t d;
+
+ for(i=1;i<14;i++) {
+ int64_t n0= 1001LL/ff_frame_rate_tab[i].den*ff_frame_rate_tab[i].num*s->avctx->time_base.num;
+ int64_t n1= 1001LL*s->avctx->time_base.den;
+ if(s->avctx->strict_std_compliance > FF_COMPLIANCE_INOFFICIAL && i>=9) break;
+
+ d = FFABS(n0 - n1);
+ if(d < dmin){
+ dmin=d;
+ s->frame_rate_index= i;
+ }
+ }
+ if(dmin)
+ return -1;
+ else
+ return 0;
+}
+
+static int encode_init(AVCodecContext *avctx)
+{
+ MpegEncContext *s = avctx->priv_data;
+
+ if(MPV_encode_init(avctx) < 0)
+ return -1;
+
+ if(find_frame_rate_index(s) < 0){
+ if(s->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){
+ av_log(avctx, AV_LOG_ERROR, "MPEG1/2 does not support %d/%d fps\n", avctx->time_base.den, avctx->time_base.num);
+ return -1;
+ }else{
+ av_log(avctx, AV_LOG_INFO, "MPEG1/2 does not support %d/%d fps, there may be AV sync issues\n", avctx->time_base.den, avctx->time_base.num);
+ }
+ }
+
+ if(avctx->profile == FF_PROFILE_UNKNOWN){
+ if(avctx->level != FF_LEVEL_UNKNOWN){
+ av_log(avctx, AV_LOG_ERROR, "Set profile and level\n");
+ return -1;
+ }
+ avctx->profile = s->chroma_format == CHROMA_420 ? 4 : 0; /* Main or 4:2:2 */
+ }
+
+ if(avctx->level == FF_LEVEL_UNKNOWN){
+ if(avctx->profile == 0){ /* 4:2:2 */
+ if(avctx->width <= 720 && avctx->height <= 608) avctx->level = 5; /* Main */
+ else avctx->level = 2; /* High */
+ }else{
+ if(avctx->profile != 1 && s->chroma_format != CHROMA_420){
+ av_log(avctx, AV_LOG_ERROR, "Only High(1) and 4:2:2(0) profiles support 4:2:2 color sampling\n");
+ return -1;
+ }
+ if(avctx->width <= 720 && avctx->height <= 576) avctx->level = 8; /* Main */
+ else if(avctx->width <= 1440) avctx->level = 6; /* High 1440 */
+ else avctx->level = 4; /* High */
+ }
+ }
+
+ if((avctx->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE) && s->frame_rate_index != 4){
+ av_log(avctx, AV_LOG_ERROR, "Drop frame time code only allowed with 1001/30000 fps\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+static void put_header(MpegEncContext *s, int header)
+{
+ align_put_bits(&s->pb);
+ put_bits(&s->pb, 16, header>>16);
+ put_bits(&s->pb, 16, header&0xFFFF);
+}
+
+/* put sequence header if needed */
+static void mpeg1_encode_sequence_header(MpegEncContext *s)
+{
+ unsigned int vbv_buffer_size;
+ unsigned int fps, v;
+ int i;
+ uint64_t time_code;
+ float best_aspect_error= 1E10;
+ float aspect_ratio= av_q2d(s->avctx->sample_aspect_ratio);
+ int constraint_parameter_flag;
+
+ if(aspect_ratio==0.0) aspect_ratio= 1.0; //pixel aspect 1:1 (VGA)
+
+ if (s->current_picture.key_frame) {
+ AVRational framerate= ff_frame_rate_tab[s->frame_rate_index];
+
+ /* mpeg1 header repeated every gop */
+ put_header(s, SEQ_START_CODE);
+
+ put_bits(&s->pb, 12, s->width);
+ put_bits(&s->pb, 12, s->height);
+
+ for(i=1; i<15; i++){
+ float error= aspect_ratio;
+ if(s->codec_id == CODEC_ID_MPEG1VIDEO || i <=1)
+ error-= 1.0/mpeg1_aspect[i];
+ else
+ error-= av_q2d(mpeg2_aspect[i])*s->height/s->width;
+
+ error= FFABS(error);
+
+ if(error < best_aspect_error){
+ best_aspect_error= error;
+ s->aspect_ratio_info= i;
+ }
+ }
+
+ put_bits(&s->pb, 4, s->aspect_ratio_info);
+ put_bits(&s->pb, 4, s->frame_rate_index);
+
+ if(s->avctx->rc_max_rate){
+ v = (s->avctx->rc_max_rate + 399) / 400;
+ if (v > 0x3ffff && s->codec_id == CODEC_ID_MPEG1VIDEO)
+ v = 0x3ffff;
+ }else{
+ v= 0x3FFFF;
+ }
+
+ if(s->avctx->rc_buffer_size)
+ vbv_buffer_size = s->avctx->rc_buffer_size;
+ else
+ /* VBV calculation: Scaled so that a VCD has the proper VBV size of 40 kilobytes */
+ vbv_buffer_size = (( 20 * s->bit_rate) / (1151929 / 2)) * 8 * 1024;
+ vbv_buffer_size= (vbv_buffer_size + 16383) / 16384;
+
+ put_bits(&s->pb, 18, v & 0x3FFFF);
+ put_bits(&s->pb, 1, 1); /* marker */
+ put_bits(&s->pb, 10, vbv_buffer_size & 0x3FF);
+
+ constraint_parameter_flag=
+ s->width <= 768 && s->height <= 576 &&
+ s->mb_width * s->mb_height <= 396 &&
+ s->mb_width * s->mb_height * framerate.num <= framerate.den*396*25 &&
+ framerate.num <= framerate.den*30 &&
+ s->avctx->me_range && s->avctx->me_range < 128 &&
+ vbv_buffer_size <= 20 &&
+ v <= 1856000/400 &&
+ s->codec_id == CODEC_ID_MPEG1VIDEO;
+
+ put_bits(&s->pb, 1, constraint_parameter_flag);
+
+ ff_write_quant_matrix(&s->pb, s->avctx->intra_matrix);
+ ff_write_quant_matrix(&s->pb, s->avctx->inter_matrix);
+
+ if(s->codec_id == CODEC_ID_MPEG2VIDEO){
+ put_header(s, EXT_START_CODE);
+ put_bits(&s->pb, 4, 1); //seq ext
+
+ put_bits(&s->pb, 1, s->avctx->profile == 0); //escx 1 for 4:2:2 profile */
+
+ put_bits(&s->pb, 3, s->avctx->profile); //profile
+ put_bits(&s->pb, 4, s->avctx->level); //level
+
+ put_bits(&s->pb, 1, s->progressive_sequence);
+ put_bits(&s->pb, 2, s->chroma_format);
+ put_bits(&s->pb, 2, 0); //horizontal size ext
+ put_bits(&s->pb, 2, 0); //vertical size ext
+ put_bits(&s->pb, 12, v>>18); //bitrate ext
+ put_bits(&s->pb, 1, 1); //marker
+ put_bits(&s->pb, 8, vbv_buffer_size >>10); //vbv buffer ext
+ put_bits(&s->pb, 1, s->low_delay);
+ put_bits(&s->pb, 2, 0); // frame_rate_ext_n
+ put_bits(&s->pb, 5, 0); // frame_rate_ext_d
+ }
+
+ put_header(s, GOP_START_CODE);
+ put_bits(&s->pb, 1, !!(s->avctx->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE)); /* drop frame flag */
+ /* time code : we must convert from the real frame rate to a
+ fake mpeg frame rate in case of low frame rate */
+ fps = (framerate.num + framerate.den/2)/ framerate.den;
+ time_code = s->current_picture_ptr->coded_picture_number + s->avctx->timecode_frame_start;
+
+ s->gop_picture_number = s->current_picture_ptr->coded_picture_number;
+ if (s->avctx->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE) {
+ /* only works for NTSC 29.97 */
+ int d = time_code / 17982;
+ int m = time_code % 17982;
+ //if (m < 2) m += 2; /* not needed since -2,-1 / 1798 in C returns 0 */
+ time_code += 18 * d + 2 * ((m - 2) / 1798);
+ }
+ put_bits(&s->pb, 5, (uint32_t)((time_code / (fps * 3600)) % 24));
+ put_bits(&s->pb, 6, (uint32_t)((time_code / (fps * 60)) % 60));
+ put_bits(&s->pb, 1, 1);
+ put_bits(&s->pb, 6, (uint32_t)((time_code / fps) % 60));
+ put_bits(&s->pb, 6, (uint32_t)((time_code % fps)));
+ put_bits(&s->pb, 1, !!(s->flags & CODEC_FLAG_CLOSED_GOP));
+ put_bits(&s->pb, 1, 0); /* broken link */
+ }
+}
+
+static inline void encode_mb_skip_run(MpegEncContext *s, int run){
+ while (run >= 33) {
+ put_bits(&s->pb, 11, 0x008);
+ run -= 33;
+ }
+ put_bits(&s->pb, mbAddrIncrTable[run][1],
+ mbAddrIncrTable[run][0]);
+}
+#endif //CONFIG_ENCODERS
+
+static void common_init(MpegEncContext *s)
+{
+
+ s->y_dc_scale_table=
+ s->c_dc_scale_table= mpeg2_dc_scale_table[s->intra_dc_precision];
+
+}
+
+void ff_mpeg1_clean_buffers(MpegEncContext *s){
+ s->last_dc[0] = 1 << (7 + s->intra_dc_precision);
+ s->last_dc[1] = s->last_dc[0];
+ s->last_dc[2] = s->last_dc[0];
+ memset(s->last_mv, 0, sizeof(s->last_mv));
+}
+
+#ifdef CONFIG_ENCODERS
+
+static av_always_inline void put_qscale(MpegEncContext *s)
+{
+ if(s->q_scale_type){
+ assert(s->qscale>=1 && s->qscale <=12);
+ put_bits(&s->pb, 5, inv_non_linear_qscale[s->qscale]);
+ }else{
+ put_bits(&s->pb, 5, s->qscale);
+ }
+}
+
+void ff_mpeg1_encode_slice_header(MpegEncContext *s){
+ put_header(s, SLICE_MIN_START_CODE + s->mb_y);
+ put_qscale(s);
+ put_bits(&s->pb, 1, 0); /* slice extra information */
+}
+
+void mpeg1_encode_picture_header(MpegEncContext *s, int picture_number)
+{
+ mpeg1_encode_sequence_header(s);
+
+ /* mpeg1 picture header */
+ put_header(s, PICTURE_START_CODE);
+ /* temporal reference */
+
+ // RAL: s->picture_number instead of s->fake_picture_number
+ put_bits(&s->pb, 10, (s->picture_number -
+ s->gop_picture_number) & 0x3ff);
+ put_bits(&s->pb, 3, s->pict_type);
+
+ s->vbv_delay_ptr= s->pb.buf + put_bits_count(&s->pb)/8;
+ put_bits(&s->pb, 16, 0xFFFF); /* vbv_delay */
+
+ // RAL: Forward f_code also needed for B frames
+ if (s->pict_type == P_TYPE || s->pict_type == B_TYPE) {
+ put_bits(&s->pb, 1, 0); /* half pel coordinates */
+ if(s->codec_id == CODEC_ID_MPEG1VIDEO)
+ put_bits(&s->pb, 3, s->f_code); /* forward_f_code */
+ else
+ put_bits(&s->pb, 3, 7); /* forward_f_code */
+ }
+
+ // RAL: Backward f_code necessary for B frames
+ if (s->pict_type == B_TYPE) {
+ put_bits(&s->pb, 1, 0); /* half pel coordinates */
+ if(s->codec_id == CODEC_ID_MPEG1VIDEO)
+ put_bits(&s->pb, 3, s->b_code); /* backward_f_code */
+ else
+ put_bits(&s->pb, 3, 7); /* backward_f_code */
+ }
+
+ put_bits(&s->pb, 1, 0); /* extra bit picture */
+
+ s->frame_pred_frame_dct = 1;
+ if(s->codec_id == CODEC_ID_MPEG2VIDEO){
+ put_header(s, EXT_START_CODE);
+ put_bits(&s->pb, 4, 8); //pic ext
+ if (s->pict_type == P_TYPE || s->pict_type == B_TYPE) {
+ put_bits(&s->pb, 4, s->f_code);
+ put_bits(&s->pb, 4, s->f_code);
+ }else{
+ put_bits(&s->pb, 8, 255);
+ }
+ if (s->pict_type == B_TYPE) {
+ put_bits(&s->pb, 4, s->b_code);
+ put_bits(&s->pb, 4, s->b_code);
+ }else{
+ put_bits(&s->pb, 8, 255);
+ }
+ put_bits(&s->pb, 2, s->intra_dc_precision);
+
+ assert(s->picture_structure == PICT_FRAME);
+ put_bits(&s->pb, 2, s->picture_structure);
+ if (s->progressive_sequence) {
+ put_bits(&s->pb, 1, 0); /* no repeat */
+ } else {
+ put_bits(&s->pb, 1, s->current_picture_ptr->top_field_first);
+ }
+ /* XXX: optimize the generation of this flag with entropy
+ measures */
+ s->frame_pred_frame_dct = s->progressive_sequence;
+
+ put_bits(&s->pb, 1, s->frame_pred_frame_dct);
+ put_bits(&s->pb, 1, s->concealment_motion_vectors);
+ put_bits(&s->pb, 1, s->q_scale_type);
+ put_bits(&s->pb, 1, s->intra_vlc_format);
+ put_bits(&s->pb, 1, s->alternate_scan);
+ put_bits(&s->pb, 1, s->repeat_first_field);
+ s->progressive_frame = s->progressive_sequence;
+ put_bits(&s->pb, 1, s->chroma_format == CHROMA_420 ? s->progressive_frame : 0); /* chroma_420_type */
+ put_bits(&s->pb, 1, s->progressive_frame);
+ put_bits(&s->pb, 1, 0); //composite_display_flag
+ }
+ if(s->flags & CODEC_FLAG_SVCD_SCAN_OFFSET){
+ int i;
+
+ put_header(s, USER_START_CODE);
+ for(i=0; i<sizeof(svcd_scan_offset_placeholder); i++){
+ put_bits(&s->pb, 8, svcd_scan_offset_placeholder[i]);
+ }
+ }
+
+ s->mb_y=0;
+ ff_mpeg1_encode_slice_header(s);
+}
+
+static inline void put_mb_modes(MpegEncContext *s, int n, int bits,
+ int has_mv, int field_motion)
+{
+ put_bits(&s->pb, n, bits);
+ if (!s->frame_pred_frame_dct) {
+ if (has_mv)
+ put_bits(&s->pb, 2, 2 - field_motion); /* motion_type: frame/field */
+ put_bits(&s->pb, 1, s->interlaced_dct);
+ }
+}
+
+static av_always_inline void mpeg1_encode_mb_internal(MpegEncContext *s,
+ DCTELEM block[6][64],
+ int motion_x, int motion_y,
+ int mb_block_count)
+{
+ int i, cbp;
+ const int mb_x = s->mb_x;
+ const int mb_y = s->mb_y;
+ const int first_mb= mb_x == s->resync_mb_x && mb_y == s->resync_mb_y;
+
+ /* compute cbp */
+ cbp = 0;
+ for(i=0;i<mb_block_count;i++) {
+ if (s->block_last_index[i] >= 0)
+ cbp |= 1 << (mb_block_count - 1 - i);
+ }
+
+ if (cbp == 0 && !first_mb && s->mv_type == MV_TYPE_16X16 &&
+ (mb_x != s->mb_width - 1 || (mb_y != s->mb_height - 1 && s->codec_id == CODEC_ID_MPEG1VIDEO)) &&
+ ((s->pict_type == P_TYPE && (motion_x | motion_y) == 0) ||
+ (s->pict_type == B_TYPE && s->mv_dir == s->last_mv_dir && (((s->mv_dir & MV_DIR_FORWARD) ? ((s->mv[0][0][0] - s->last_mv[0][0][0])|(s->mv[0][0][1] - s->last_mv[0][0][1])) : 0) |
+ ((s->mv_dir & MV_DIR_BACKWARD) ? ((s->mv[1][0][0] - s->last_mv[1][0][0])|(s->mv[1][0][1] - s->last_mv[1][0][1])) : 0)) == 0))) {
+ s->mb_skip_run++;
+ s->qscale -= s->dquant;
+ s->skip_count++;
+ s->misc_bits++;
+ s->last_bits++;
+ if(s->pict_type == P_TYPE){
+ s->last_mv[0][1][0]= s->last_mv[0][0][0]=
+ s->last_mv[0][1][1]= s->last_mv[0][0][1]= 0;
+ }
+ } else {
+ if(first_mb){
+ assert(s->mb_skip_run == 0);
+ encode_mb_skip_run(s, s->mb_x);
+ }else{
+ encode_mb_skip_run(s, s->mb_skip_run);
+ }
+
+ if (s->pict_type == I_TYPE) {
+ if(s->dquant && cbp){
+ put_mb_modes(s, 2, 1, 0, 0); /* macroblock_type : macroblock_quant = 1 */
+ put_qscale(s);
+ }else{
+ put_mb_modes(s, 1, 1, 0, 0); /* macroblock_type : macroblock_quant = 0 */
+ s->qscale -= s->dquant;
+ }
+ s->misc_bits+= get_bits_diff(s);
+ s->i_count++;
+ } else if (s->mb_intra) {
+ if(s->dquant && cbp){
+ put_mb_modes(s, 6, 0x01, 0, 0);
+ put_qscale(s);
+ }else{
+ put_mb_modes(s, 5, 0x03, 0, 0);
+ s->qscale -= s->dquant;
+ }
+ s->misc_bits+= get_bits_diff(s);
+ s->i_count++;
+ memset(s->last_mv, 0, sizeof(s->last_mv));
+ } else if (s->pict_type == P_TYPE) {
+ if(s->mv_type == MV_TYPE_16X16){
+ if (cbp != 0) {
+ if ((motion_x|motion_y) == 0) {
+ if(s->dquant){
+ put_mb_modes(s, 5, 1, 0, 0); /* macroblock_pattern & quant */
+ put_qscale(s);
+ }else{
+ put_mb_modes(s, 2, 1, 0, 0); /* macroblock_pattern only */
+ }
+ s->misc_bits+= get_bits_diff(s);
+ } else {
+ if(s->dquant){
+ put_mb_modes(s, 5, 2, 1, 0); /* motion + cbp */
+ put_qscale(s);
+ }else{
+ put_mb_modes(s, 1, 1, 1, 0); /* motion + cbp */
+ }
+ s->misc_bits+= get_bits_diff(s);
+ mpeg1_encode_motion(s, motion_x - s->last_mv[0][0][0], s->f_code); // RAL: f_code parameter added
+ mpeg1_encode_motion(s, motion_y - s->last_mv[0][0][1], s->f_code); // RAL: f_code parameter added
+ s->mv_bits+= get_bits_diff(s);
+ }
+ } else {
+ put_bits(&s->pb, 3, 1); /* motion only */
+ if (!s->frame_pred_frame_dct)
+ put_bits(&s->pb, 2, 2); /* motion_type: frame */
+ s->misc_bits+= get_bits_diff(s);
+ mpeg1_encode_motion(s, motion_x - s->last_mv[0][0][0], s->f_code); // RAL: f_code parameter added
+ mpeg1_encode_motion(s, motion_y - s->last_mv[0][0][1], s->f_code); // RAL: f_code parameter added
+ s->qscale -= s->dquant;
+ s->mv_bits+= get_bits_diff(s);
+ }
+ s->last_mv[0][1][0]= s->last_mv[0][0][0]= motion_x;
+ s->last_mv[0][1][1]= s->last_mv[0][0][1]= motion_y;
+ }else{
+ assert(!s->frame_pred_frame_dct && s->mv_type == MV_TYPE_FIELD);
+
+ if (cbp) {
+ if(s->dquant){
+ put_mb_modes(s, 5, 2, 1, 1); /* motion + cbp */
+ put_qscale(s);
+ }else{
+ put_mb_modes(s, 1, 1, 1, 1); /* motion + cbp */
+ }
+ } else {
+ put_bits(&s->pb, 3, 1); /* motion only */
+ put_bits(&s->pb, 2, 1); /* motion_type: field */
+ s->qscale -= s->dquant;
+ }
+ s->misc_bits+= get_bits_diff(s);
+ for(i=0; i<2; i++){
+ put_bits(&s->pb, 1, s->field_select[0][i]);
+ mpeg1_encode_motion(s, s->mv[0][i][0] - s->last_mv[0][i][0] , s->f_code);
+ mpeg1_encode_motion(s, s->mv[0][i][1] - (s->last_mv[0][i][1]>>1), s->f_code);
+ s->last_mv[0][i][0]= s->mv[0][i][0];
+ s->last_mv[0][i][1]= 2*s->mv[0][i][1];
+ }
+ s->mv_bits+= get_bits_diff(s);
+ }
+ if(cbp) {
+ if (s->chroma_y_shift) {
+ put_bits(&s->pb, mbPatTable[cbp][1], mbPatTable[cbp][0]);
+ } else {
+ put_bits(&s->pb, mbPatTable[cbp>>2][1], mbPatTable[cbp>>2][0]);
+ put_bits(&s->pb, 2, cbp & 3);
+ }
+ }
+ s->f_count++;
+ } else{
+ static const int mb_type_len[4]={0,3,4,2}; //bak,for,bi
+
+ if(s->mv_type == MV_TYPE_16X16){
+ if (cbp){ // With coded bloc pattern
+ if (s->dquant) {
+ if(s->mv_dir == MV_DIR_FORWARD)
+ put_mb_modes(s, 6, 3, 1, 0);
+ else
+ put_mb_modes(s, mb_type_len[s->mv_dir]+3, 2, 1, 0);
+ put_qscale(s);
+ } else {
+ put_mb_modes(s, mb_type_len[s->mv_dir], 3, 1, 0);
+ }
+ }else{ // No coded bloc pattern
+ put_bits(&s->pb, mb_type_len[s->mv_dir], 2);
+ if (!s->frame_pred_frame_dct)
+ put_bits(&s->pb, 2, 2); /* motion_type: frame */
+ s->qscale -= s->dquant;
+ }
+ s->misc_bits += get_bits_diff(s);
+ if (s->mv_dir&MV_DIR_FORWARD){
+ mpeg1_encode_motion(s, s->mv[0][0][0] - s->last_mv[0][0][0], s->f_code);
+ mpeg1_encode_motion(s, 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){
+ mpeg1_encode_motion(s, s->mv[1][0][0] - s->last_mv[1][0][0], s->b_code);
+ mpeg1_encode_motion(s, 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{
+ assert(s->mv_type == MV_TYPE_FIELD);
+ assert(!s->frame_pred_frame_dct);
+ if (cbp){ // With coded bloc pattern
+ if (s->dquant) {
+ if(s->mv_dir == MV_DIR_FORWARD)
+ put_mb_modes(s, 6, 3, 1, 1);
+ else
+ put_mb_modes(s, mb_type_len[s->mv_dir]+3, 2, 1, 1);
+ put_qscale(s);
+ } else {
+ put_mb_modes(s, mb_type_len[s->mv_dir], 3, 1, 1);
+ }
+ }else{ // No coded bloc pattern
+ put_bits(&s->pb, mb_type_len[s->mv_dir], 2);
+ put_bits(&s->pb, 2, 1); /* motion_type: field */
+ s->qscale -= s->dquant;
+ }
+ s->misc_bits += get_bits_diff(s);
+ if (s->mv_dir&MV_DIR_FORWARD){
+ for(i=0; i<2; i++){
+ put_bits(&s->pb, 1, s->field_select[0][i]);
+ mpeg1_encode_motion(s, s->mv[0][i][0] - s->last_mv[0][i][0] , s->f_code);
+ mpeg1_encode_motion(s, s->mv[0][i][1] - (s->last_mv[0][i][1]>>1), s->f_code);
+ s->last_mv[0][i][0]= s->mv[0][i][0];
+ s->last_mv[0][i][1]= 2*s->mv[0][i][1];
+ }
+ s->f_count++;
+ }
+ if (s->mv_dir&MV_DIR_BACKWARD){
+ for(i=0; i<2; i++){
+ put_bits(&s->pb, 1, s->field_select[1][i]);
+ mpeg1_encode_motion(s, s->mv[1][i][0] - s->last_mv[1][i][0] , s->b_code);
+ mpeg1_encode_motion(s, s->mv[1][i][1] - (s->last_mv[1][i][1]>>1), s->b_code);
+ s->last_mv[1][i][0]= s->mv[1][i][0];
+ s->last_mv[1][i][1]= 2*s->mv[1][i][1];
+ }
+ s->b_count++;
+ }
+ }
+ s->mv_bits += get_bits_diff(s);
+ if(cbp) {
+ if (s->chroma_y_shift) {
+ put_bits(&s->pb, mbPatTable[cbp][1], mbPatTable[cbp][0]);
+ } else {
+ put_bits(&s->pb, mbPatTable[cbp>>2][1], mbPatTable[cbp>>2][0]);
+ put_bits(&s->pb, 2, cbp & 3);
+ }
+ }
+ }
+ for(i=0;i<mb_block_count;i++) {
+ if (cbp & (1 << (mb_block_count - 1 - i))) {
+ mpeg1_encode_block(s, block[i], i);
+ }
+ }
+ s->mb_skip_run = 0;
+ if(s->mb_intra)
+ s->i_tex_bits+= get_bits_diff(s);
+ else
+ s->p_tex_bits+= get_bits_diff(s);
+ }
+}
+
+void mpeg1_encode_mb(MpegEncContext *s, DCTELEM block[6][64], int motion_x, int motion_y)
+{
+ if (s->chroma_format == CHROMA_420) mpeg1_encode_mb_internal(s, block, motion_x, motion_y, 6);
+ else mpeg1_encode_mb_internal(s, block, motion_x, motion_y, 8);
+}
+
+// RAL: Parameter added: f_or_b_code
+static void mpeg1_encode_motion(MpegEncContext *s, int val, int f_or_b_code)
+{
+ int code, bit_size, l, bits, range, sign;
+
+ if (val == 0) {
+ /* zero vector */
+ code = 0;
+ put_bits(&s->pb,
+ mbMotionVectorTable[0][1],
+ mbMotionVectorTable[0][0]);
+ } else {
+ bit_size = f_or_b_code - 1;
+ range = 1 << bit_size;
+ /* modulo encoding */
+ l= INT_BIT - 5 - bit_size;
+ val= (val<<l)>>l;
+
+ if (val >= 0) {
+ val--;
+ code = (val >> bit_size) + 1;
+ bits = val & (range - 1);
+ sign = 0;
+ } else {
+ val = -val;
+ val--;
+ code = (val >> bit_size) + 1;
+ bits = val & (range - 1);
+ sign = 1;
+ }
+
+ assert(code > 0 && code <= 16);
+
+ put_bits(&s->pb,
+ mbMotionVectorTable[code][1],
+ mbMotionVectorTable[code][0]);
+
+ put_bits(&s->pb, 1, sign);
+ if (bit_size > 0) {
+ put_bits(&s->pb, bit_size, bits);
+ }
+ }
+}
+
+void ff_mpeg1_encode_init(MpegEncContext *s)
+{
+ static int done=0;
+
+ common_init(s);
+
+ if(!done){
+ int f_code;
+ int mv;
+ int i;
+
+ done=1;
+ init_rl(&rl_mpeg1, static_rl_table_store[0]);
+ init_rl(&rl_mpeg2, static_rl_table_store[1]);
+
+ for(i=0; i<64; i++)
+ {
+ mpeg1_max_level[0][i]= rl_mpeg1.max_level[0][i];
+ mpeg1_index_run[0][i]= rl_mpeg1.index_run[0][i];
+ }
+
+ init_uni_ac_vlc(&rl_mpeg1, uni_mpeg1_ac_vlc_len);
+ if(s->intra_vlc_format)
+ init_uni_ac_vlc(&rl_mpeg2, uni_mpeg2_ac_vlc_len);
+
+ /* build unified dc encoding tables */
+ for(i=-255; i<256; i++)
+ {
+ int adiff, index;
+ int bits, code;
+ int diff=i;
+
+ adiff = FFABS(diff);
+ if(diff<0) diff--;
+ index = av_log2(2*adiff);
+
+ bits= vlc_dc_lum_bits[index] + index;
+ code= (vlc_dc_lum_code[index]<<index) + (diff & ((1 << index) - 1));
+ mpeg1_lum_dc_uni[i+255]= bits + (code<<8);
+
+ bits= vlc_dc_chroma_bits[index] + index;
+ code= (vlc_dc_chroma_code[index]<<index) + (diff & ((1 << index) - 1));
+ mpeg1_chr_dc_uni[i+255]= bits + (code<<8);
+ }
+
+ for(f_code=1; f_code<=MAX_FCODE; f_code++){
+ for(mv=-MAX_MV; mv<=MAX_MV; mv++){
+ int len;
+
+ if(mv==0) len= mbMotionVectorTable[0][1];
+ else{
+ int val, bit_size, range, code;
+
+ bit_size = f_code - 1;
+ range = 1 << bit_size;
+
+ val=mv;
+ if (val < 0)
+ val = -val;
+ val--;
+ code = (val >> bit_size) + 1;
+ if(code<17){
+ len= mbMotionVectorTable[code][1] + 1 + bit_size;
+ }else{
+ len= mbMotionVectorTable[16][1] + 2 + bit_size;
+ }
+ }
+
+ mv_penalty[f_code][mv+MAX_MV]= len;
+ }
+ }
+
+
+ for(f_code=MAX_FCODE; f_code>0; f_code--){
+ for(mv=-(8<<f_code); mv<(8<<f_code); mv++){
+ fcode_tab[mv+MAX_MV]= f_code;
+ }
+ }
+ }
+ s->me.mv_penalty= mv_penalty;
+ s->fcode_tab= fcode_tab;
+ if(s->codec_id == CODEC_ID_MPEG1VIDEO){
+ s->min_qcoeff=-255;
+ s->max_qcoeff= 255;
+ }else{
+ s->min_qcoeff=-2047;
+ s->max_qcoeff= 2047;
+ }
+ if (s->intra_vlc_format) {
+ s->intra_ac_vlc_length=
+ s->intra_ac_vlc_last_length= uni_mpeg2_ac_vlc_len;
+ } else {
+ s->intra_ac_vlc_length=
+ s->intra_ac_vlc_last_length= uni_mpeg1_ac_vlc_len;
+ }
+ s->inter_ac_vlc_length=
+ s->inter_ac_vlc_last_length= uni_mpeg1_ac_vlc_len;
+}
+
+static inline void encode_dc(MpegEncContext *s, int diff, int component)
+{
+ if(((unsigned) (diff+255)) >= 511){
+ int index;
+
+ if(diff<0){
+ index= av_log2_16bit(-2*diff);
+ diff--;
+ }else{
+ index= av_log2_16bit(2*diff);
+ }
+ if (component == 0) {
+ put_bits(
+ &s->pb,
+ vlc_dc_lum_bits[index] + index,
+ (vlc_dc_lum_code[index]<<index) + (diff & ((1 << index) - 1)));
+ }else{
+ put_bits(
+ &s->pb,
+ vlc_dc_chroma_bits[index] + index,
+ (vlc_dc_chroma_code[index]<<index) + (diff & ((1 << index) - 1)));
+ }
+ }else{
+ if (component == 0) {
+ put_bits(
+ &s->pb,
+ mpeg1_lum_dc_uni[diff+255]&0xFF,
+ mpeg1_lum_dc_uni[diff+255]>>8);
+ } else {
+ put_bits(
+ &s->pb,
+ mpeg1_chr_dc_uni[diff+255]&0xFF,
+ mpeg1_chr_dc_uni[diff+255]>>8);
+ }
+ }
+}
+
+static void mpeg1_encode_block(MpegEncContext *s,
+ DCTELEM *block,
+ int n)
+{
+ int alevel, level, last_non_zero, dc, diff, i, j, run, last_index, sign;
+ int code, component;
+ const uint16_t (*table_vlc)[2] = rl_mpeg1.table_vlc;
+
+ last_index = s->block_last_index[n];
+
+ /* DC coef */
+ if (s->mb_intra) {
+ component = (n <= 3 ? 0 : (n&1) + 1);
+ dc = block[0]; /* overflow is impossible */
+ diff = dc - s->last_dc[component];
+ encode_dc(s, diff, component);
+ s->last_dc[component] = dc;
+ i = 1;
+ if (s->intra_vlc_format)
+ table_vlc = rl_mpeg2.table_vlc;
+ } else {
+ /* encode the first coefficient : needs to be done here because
+ it is handled slightly differently */
+ level = block[0];
+ if (abs(level) == 1) {
+ code = ((uint32_t)level >> 31); /* the sign bit */
+ put_bits(&s->pb, 2, code | 0x02);
+ i = 1;
+ } else {
+ i = 0;
+ last_non_zero = -1;
+ goto next_coef;
+ }
+ }
+
+ /* now quantify & encode AC coefs */
+ last_non_zero = i - 1;
+
+ for(;i<=last_index;i++) {
+ j = s->intra_scantable.permutated[i];
+ level = block[j];
+ next_coef:
+#if 0
+ if (level != 0)
+ dprintf(s->avctx, "level[%d]=%d\n", i, level);
+#endif
+ /* encode using VLC */
+ if (level != 0) {
+ run = i - last_non_zero - 1;
+
+ alevel= level;
+ MASK_ABS(sign, alevel)
+ sign&=1;
+
+ if (alevel <= mpeg1_max_level[0][run]){
+ code= mpeg1_index_run[0][run] + alevel - 1;
+ /* store the vlc & sign at once */
+ put_bits(&s->pb, table_vlc[code][1]+1, (table_vlc[code][0]<<1) + sign);
+ } else {
+ /* escape seems to be pretty rare <5% so i dont optimize it */
+ put_bits(&s->pb, table_vlc[111][1], table_vlc[111][0]);
+ /* escape: only clip in this case */
+ put_bits(&s->pb, 6, run);
+ if(s->codec_id == CODEC_ID_MPEG1VIDEO){
+ if (alevel < 128) {
+ put_bits(&s->pb, 8, level & 0xff);
+ } else {
+ if (level < 0) {
+ put_bits(&s->pb, 16, 0x8001 + level + 255);
+ } else {
+ put_bits(&s->pb, 16, level & 0xffff);
+ }
+ }
+ }else{
+ put_bits(&s->pb, 12, level & 0xfff);
+ }
+ }
+ last_non_zero = i;
+ }
+ }
+ /* end of block */
+ put_bits(&s->pb, table_vlc[112][1], table_vlc[112][0]);
+}
+#endif //CONFIG_ENCODERS
+
+/******************************************/
+/* decoding */
+
+static VLC dc_lum_vlc;
+static VLC dc_chroma_vlc;
+static VLC mv_vlc;
+static VLC mbincr_vlc;
+static VLC mb_ptype_vlc;
+static VLC mb_btype_vlc;
+static VLC mb_pat_vlc;
+
+static void init_vlcs(void)
+{
+ static int done = 0;
+
+ if (!done) {
+ done = 1;
+
+ init_vlc(&dc_lum_vlc, DC_VLC_BITS, 12,
+ vlc_dc_lum_bits, 1, 1,
+ vlc_dc_lum_code, 2, 2, 1);
+ init_vlc(&dc_chroma_vlc, DC_VLC_BITS, 12,
+ vlc_dc_chroma_bits, 1, 1,
+ vlc_dc_chroma_code, 2, 2, 1);
+ init_vlc(&mv_vlc, MV_VLC_BITS, 17,
+ &mbMotionVectorTable[0][1], 2, 1,
+ &mbMotionVectorTable[0][0], 2, 1, 1);
+ init_vlc(&mbincr_vlc, MBINCR_VLC_BITS, 36,
+ &mbAddrIncrTable[0][1], 2, 1,
+ &mbAddrIncrTable[0][0], 2, 1, 1);
+ init_vlc(&mb_pat_vlc, MB_PAT_VLC_BITS, 64,
+ &mbPatTable[0][1], 2, 1,
+ &mbPatTable[0][0], 2, 1, 1);
+
+ init_vlc(&mb_ptype_vlc, MB_PTYPE_VLC_BITS, 7,
+ &table_mb_ptype[0][1], 2, 1,
+ &table_mb_ptype[0][0], 2, 1, 1);
+ init_vlc(&mb_btype_vlc, MB_BTYPE_VLC_BITS, 11,
+ &table_mb_btype[0][1], 2, 1,
+ &table_mb_btype[0][0], 2, 1, 1);
+ init_rl(&rl_mpeg1, static_rl_table_store[0]);
+ init_rl(&rl_mpeg2, static_rl_table_store[1]);
+
+ init_2d_vlc_rl(&rl_mpeg1, 1);
+ init_2d_vlc_rl(&rl_mpeg2, 1);
+ }
+}
+
+static inline int get_dmv(MpegEncContext *s)
+{
+ if(get_bits1(&s->gb))
+ return 1 - (get_bits1(&s->gb) << 1);
+ else
+ return 0;
+}
+
+static inline int get_qscale(MpegEncContext *s)
+{
+ int qscale = get_bits(&s->gb, 5);
+ if (s->q_scale_type) {
+ return non_linear_qscale[qscale];
+ } else {
+ return qscale << 1;
+ }
+}
+
+/* motion type (for mpeg2) */
+#define MT_FIELD 1
+#define MT_FRAME 2
+#define MT_16X8 2
+#define MT_DMV 3
+
+static int mpeg_decode_mb(MpegEncContext *s,
+ DCTELEM block[12][64])
+{
+ int i, j, k, cbp, val, mb_type, motion_type;
+ const int mb_block_count = 4 + (1<< s->chroma_format);
+
+ dprintf(s->avctx, "decode_mb: x=%d y=%d\n", s->mb_x, s->mb_y);
+
+ assert(s->mb_skipped==0);
+
+ if (s->mb_skip_run-- != 0) {
+ if(s->pict_type == I_TYPE){
+ av_log(s->avctx, AV_LOG_ERROR, "skipped MB in I frame at %d %d\n", s->mb_x, s->mb_y);
+ return -1;
+ }
+
+ /* skip mb */
+ s->mb_intra = 0;
+ for(i=0;i<12;i++)
+ s->block_last_index[i] = -1;
+ if(s->picture_structure == PICT_FRAME)
+ s->mv_type = MV_TYPE_16X16;
+ else
+ s->mv_type = MV_TYPE_FIELD;
+ if (s->pict_type == P_TYPE) {
+ /* if P type, zero motion vector is implied */
+ s->mv_dir = MV_DIR_FORWARD;
+ s->mv[0][0][0] = s->mv[0][0][1] = 0;
+ s->last_mv[0][0][0] = s->last_mv[0][0][1] = 0;
+ s->last_mv[0][1][0] = s->last_mv[0][1][1] = 0;
+ s->field_select[0][0]= s->picture_structure - 1;
+ s->mb_skipped = 1;
+ s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ]= MB_TYPE_SKIP | MB_TYPE_L0 | MB_TYPE_16x16;
+ } else {
+ int mb_type;
+
+ if(s->mb_x)
+ mb_type= s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride - 1];
+ else
+ mb_type= s->current_picture.mb_type[ s->mb_width + (s->mb_y-1)*s->mb_stride - 1]; // FIXME not sure if this is allowed in mpeg at all,
+ if(IS_INTRA(mb_type))
+ return -1;
+
+ /* if B type, reuse previous vectors and directions */
+ s->mv[0][0][0] = s->last_mv[0][0][0];
+ s->mv[0][0][1] = s->last_mv[0][0][1];
+ s->mv[1][0][0] = s->last_mv[1][0][0];
+ s->mv[1][0][1] = s->last_mv[1][0][1];
+
+ s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ]=
+ mb_type | MB_TYPE_SKIP;
+// assert(s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride - 1]&(MB_TYPE_16x16|MB_TYPE_16x8));
+
+ if((s->mv[0][0][0]|s->mv[0][0][1]|s->mv[1][0][0]|s->mv[1][0][1])==0)
+ s->mb_skipped = 1;
+ }
+
+ return 0;
+ }
+
+ switch(s->pict_type) {
+ default:
+ case I_TYPE:
+ if (get_bits1(&s->gb) == 0) {
+ if (get_bits1(&s->gb) == 0){
+ av_log(s->avctx, AV_LOG_ERROR, "invalid mb type in I Frame at %d %d\n", s->mb_x, s->mb_y);
+ return -1;
+ }
+ mb_type = MB_TYPE_QUANT | MB_TYPE_INTRA;
+ } else {
+ mb_type = MB_TYPE_INTRA;
+ }
+ break;
+ case P_TYPE:
+ mb_type = get_vlc2(&s->gb, mb_ptype_vlc.table, MB_PTYPE_VLC_BITS, 1);
+ if (mb_type < 0){
+ av_log(s->avctx, AV_LOG_ERROR, "invalid mb type in P Frame at %d %d\n", s->mb_x, s->mb_y);
+ return -1;
+ }
+ mb_type = ptype2mb_type[ mb_type ];
+ break;
+ case B_TYPE:
+ mb_type = get_vlc2(&s->gb, mb_btype_vlc.table, MB_BTYPE_VLC_BITS, 1);
+ if (mb_type < 0){
+ av_log(s->avctx, AV_LOG_ERROR, "invalid mb type in B Frame at %d %d\n", s->mb_x, s->mb_y);
+ return -1;
+ }
+ mb_type = btype2mb_type[ mb_type ];
+ break;
+ }
+ dprintf(s->avctx, "mb_type=%x\n", mb_type);
+// motion_type = 0; /* avoid warning */
+ if (IS_INTRA(mb_type)) {
+ s->dsp.clear_blocks(s->block[0]);
+
+ if(!s->chroma_y_shift){
+ s->dsp.clear_blocks(s->block[6]);
+ }
+
+ /* compute dct type */
+ if (s->picture_structure == PICT_FRAME && //FIXME add a interlaced_dct coded var?
+ !s->frame_pred_frame_dct) {
+ s->interlaced_dct = get_bits1(&s->gb);
+ }
+
+ if (IS_QUANT(mb_type))
+ s->qscale = get_qscale(s);
+
+ if (s->concealment_motion_vectors) {
+ /* just parse them */
+ if (s->picture_structure != PICT_FRAME)
+ skip_bits1(&s->gb); /* field select */
+
+ s->mv[0][0][0]= s->last_mv[0][0][0]= s->last_mv[0][1][0] =
+ mpeg_decode_motion(s, s->mpeg_f_code[0][0], s->last_mv[0][0][0]);
+ s->mv[0][0][1]= s->last_mv[0][0][1]= s->last_mv[0][1][1] =
+ mpeg_decode_motion(s, s->mpeg_f_code[0][1], s->last_mv[0][0][1]);
+
+ skip_bits1(&s->gb); /* marker */
+ }else
+ memset(s->last_mv, 0, sizeof(s->last_mv)); /* reset mv prediction */
+ s->mb_intra = 1;
+#ifdef HAVE_XVMC
+ //one 1 we memcpy blocks in xvmcvideo
+ if(s->avctx->xvmc_acceleration > 1){
+ XVMC_pack_pblocks(s,-1);//inter are always full blocks
+ if(s->swap_uv){
+ exchange_uv(s);
+ }
+ }
+#endif
+
+ if (s->codec_id == CODEC_ID_MPEG2VIDEO) {
+ if(s->flags2 & CODEC_FLAG2_FAST){
+ for(i=0;i<6;i++) {
+ mpeg2_fast_decode_block_intra(s, s->pblocks[i], i);
+ }
+ }else{
+ for(i=0;i<mb_block_count;i++) {
+ if (mpeg2_decode_block_intra(s, s->pblocks[i], i) < 0)
+ return -1;
+ }
+ }
+ } else {
+ for(i=0;i<6;i++) {
+ if (mpeg1_decode_block_intra(s, s->pblocks[i], i) < 0)
+ return -1;
+ }
+ }
+ } else {
+ if (mb_type & MB_TYPE_ZERO_MV){
+ assert(mb_type & MB_TYPE_CBP);
+
+ /* compute dct type */
+ if (s->picture_structure == PICT_FRAME && //FIXME add a interlaced_dct coded var?
+ !s->frame_pred_frame_dct) {
+ s->interlaced_dct = get_bits1(&s->gb);
+ }
+
+ if (IS_QUANT(mb_type))
+ s->qscale = get_qscale(s);
+
+ s->mv_dir = MV_DIR_FORWARD;
+ if(s->picture_structure == PICT_FRAME)
+ s->mv_type = MV_TYPE_16X16;
+ else{
+ s->mv_type = MV_TYPE_FIELD;
+ mb_type |= MB_TYPE_INTERLACED;
+ s->field_select[0][0]= s->picture_structure - 1;
+ }
+ s->last_mv[0][0][0] = 0;
+ s->last_mv[0][0][1] = 0;
+ s->last_mv[0][1][0] = 0;
+ s->last_mv[0][1][1] = 0;
+ s->mv[0][0][0] = 0;
+ s->mv[0][0][1] = 0;
+ }else{
+ assert(mb_type & MB_TYPE_L0L1);
+//FIXME decide if MBs in field pictures are MB_TYPE_INTERLACED
+ /* get additionnal motion vector type */
+ if (s->frame_pred_frame_dct)
+ motion_type = MT_FRAME;
+ else{
+ motion_type = get_bits(&s->gb, 2);
+ }
+
+ /* compute dct type */
+ if (s->picture_structure == PICT_FRAME && //FIXME add a interlaced_dct coded var?
+ !s->frame_pred_frame_dct && HAS_CBP(mb_type)) {
+ s->interlaced_dct = get_bits1(&s->gb);
+ }
+
+ if (IS_QUANT(mb_type))
+ s->qscale = get_qscale(s);
+
+ /* motion vectors */
+ s->mv_dir = 0;
+ for(i=0;i<2;i++) {
+ if (USES_LIST(mb_type, i)) {
+ s->mv_dir |= (MV_DIR_FORWARD >> i);
+ dprintf(s->avctx, "motion_type=%d\n", motion_type);
+ switch(motion_type) {
+ case MT_FRAME: /* or MT_16X8 */
+ if (s->picture_structure == PICT_FRAME) {
+ /* MT_FRAME */
+ mb_type |= MB_TYPE_16x16;
+ s->mv_type = MV_TYPE_16X16;
+ s->mv[i][0][0]= s->last_mv[i][0][0]= s->last_mv[i][1][0] =
+ mpeg_decode_motion(s, s->mpeg_f_code[i][0], s->last_mv[i][0][0]);
+ s->mv[i][0][1]= s->last_mv[i][0][1]= s->last_mv[i][1][1] =
+ mpeg_decode_motion(s, s->mpeg_f_code[i][1], s->last_mv[i][0][1]);
+ /* full_pel: only for mpeg1 */
+ if (s->full_pel[i]){
+ s->mv[i][0][0] <<= 1;
+ s->mv[i][0][1] <<= 1;
+ }
+ } else {
+ /* MT_16X8 */
+ mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED;
+ s->mv_type = MV_TYPE_16X8;
+ for(j=0;j<2;j++) {
+ s->field_select[i][j] = get_bits1(&s->gb);
+ for(k=0;k<2;k++) {
+ val = mpeg_decode_motion(s, s->mpeg_f_code[i][k],
+ s->last_mv[i][j][k]);
+ s->last_mv[i][j][k] = val;
+ s->mv[i][j][k] = val;
+ }
+ }
+ }
+ break;
+ case MT_FIELD:
+ s->mv_type = MV_TYPE_FIELD;
+ if (s->picture_structure == PICT_FRAME) {
+ mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED;
+ for(j=0;j<2;j++) {
+ s->field_select[i][j] = get_bits1(&s->gb);
+ val = mpeg_decode_motion(s, s->mpeg_f_code[i][0],
+ s->last_mv[i][j][0]);
+ s->last_mv[i][j][0] = val;
+ s->mv[i][j][0] = val;
+ dprintf(s->avctx, "fmx=%d\n", val);
+ val = mpeg_decode_motion(s, s->mpeg_f_code[i][1],
+ s->last_mv[i][j][1] >> 1);
+ s->last_mv[i][j][1] = val << 1;
+ s->mv[i][j][1] = val;
+ dprintf(s->avctx, "fmy=%d\n", val);
+ }
+ } else {
+ mb_type |= MB_TYPE_16x16 | MB_TYPE_INTERLACED;
+ s->field_select[i][0] = get_bits1(&s->gb);
+ for(k=0;k<2;k++) {
+ val = mpeg_decode_motion(s, s->mpeg_f_code[i][k],
+ s->last_mv[i][0][k]);
+ s->last_mv[i][0][k] = val;
+ s->last_mv[i][1][k] = val;
+ s->mv[i][0][k] = val;
+ }
+ }
+ break;
+ case MT_DMV:
+ {
+ int dmx, dmy, mx, my, m;
+
+ 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);
+ dmy = get_dmv(s);
+ s->mv_type = MV_TYPE_DMV;
+
+
+ s->last_mv[i][0][1] = my<<1;
+ s->last_mv[i][1][1] = my<<1;
+
+ s->mv[i][0][0] = mx;
+ s->mv[i][0][1] = my;
+ s->mv[i][1][0] = mx;//not used
+ s->mv[i][1][1] = my;//not used
+
+ if (s->picture_structure == PICT_FRAME) {
+ mb_type |= MB_TYPE_16x16 | MB_TYPE_INTERLACED;
+
+ //m = 1 + 2 * s->top_field_first;
+ m = s->top_field_first ? 1 : 3;
+
+ /* top -> top pred */
+ s->mv[i][2][0] = ((mx * m + (mx > 0)) >> 1) + dmx;
+ s->mv[i][2][1] = ((my * m + (my > 0)) >> 1) + dmy - 1;
+ m = 4 - m;
+ s->mv[i][3][0] = ((mx * m + (mx > 0)) >> 1) + dmx;
+ s->mv[i][3][1] = ((my * m + (my > 0)) >> 1) + dmy + 1;
+ } else {
+ mb_type |= MB_TYPE_16x16;
+
+ s->mv[i][2][0] = ((mx + (mx > 0)) >> 1) + dmx;
+ s->mv[i][2][1] = ((my + (my > 0)) >> 1) + dmy;
+ if(s->picture_structure == PICT_TOP_FIELD)
+ s->mv[i][2][1]--;
+ else
+ s->mv[i][2][1]++;
+ }
+ }
+ break;
+ default:
+ av_log(s->avctx, AV_LOG_ERROR, "00 motion_type at %d %d\n", s->mb_x, s->mb_y);
+ return -1;
+ }
+ }
+ }
+ }
+
+ s->mb_intra = 0;
+ if (HAS_CBP(mb_type)) {
+ s->dsp.clear_blocks(s->block[0]);
+
+ if(!s->chroma_y_shift){
+ s->dsp.clear_blocks(s->block[6]);
+ }
+
+ cbp = get_vlc2(&s->gb, mb_pat_vlc.table, MB_PAT_VLC_BITS, 1);
+ if (cbp < 0 || ((cbp == 0) && (s->chroma_format < 2)) ){
+ av_log(s->avctx, AV_LOG_ERROR, "invalid cbp at %d %d\n", s->mb_x, s->mb_y);
+ return -1;
+ }
+ if(mb_block_count > 6){
+ cbp<<= mb_block_count-6;
+ cbp |= get_bits(&s->gb, mb_block_count-6);
+ }
+
+#ifdef HAVE_XVMC
+ //on 1 we memcpy blocks in xvmcvideo
+ if(s->avctx->xvmc_acceleration > 1){
+ XVMC_pack_pblocks(s,cbp);
+ if(s->swap_uv){
+ exchange_uv(s);
+ }
+ }
+#endif
+
+ if (s->codec_id == CODEC_ID_MPEG2VIDEO) {
+ if(s->flags2 & CODEC_FLAG2_FAST){
+ for(i=0;i<6;i++) {
+ if(cbp & 32) {
+ mpeg2_fast_decode_block_non_intra(s, s->pblocks[i], i);
+ } else {
+ s->block_last_index[i] = -1;
+ }
+ cbp+=cbp;
+ }
+ }else{
+ cbp<<= 12-mb_block_count;
+
+ for(i=0;i<mb_block_count;i++) {
+ if ( cbp & (1<<11) ) {
+ if (mpeg2_decode_block_non_intra(s, s->pblocks[i], i) < 0)
+ return -1;
+ } else {
+ s->block_last_index[i] = -1;
+ }
+ cbp+=cbp;
+ }
+ }
+ } else {
+ if(s->flags2 & CODEC_FLAG2_FAST){
+ for(i=0;i<6;i++) {
+ if (cbp & 32) {
+ mpeg1_fast_decode_block_inter(s, s->pblocks[i], i);
+ } else {
+ s->block_last_index[i] = -1;
+ }
+ cbp+=cbp;
+ }
+ }else{
+ for(i=0;i<6;i++) {
+ if (cbp & 32) {
+ if (mpeg1_decode_block_inter(s, s->pblocks[i], i) < 0)
+ return -1;
+ } else {
+ s->block_last_index[i] = -1;
+ }
+ cbp+=cbp;
+ }
+ }
+ }
+ }else{
+ for(i=0;i<12;i++)
+ s->block_last_index[i] = -1;
+ }
+ }
+
+ s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ]= mb_type;
+
+ return 0;
+}
+
+/* as h263, but only 17 codes */
+static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred)
+{
+ int code, sign, val, l, shift;
+
+ 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 = fcode - 1;
+ val = code;
+ if (shift) {
+ val = (val - 1) << shift;
+ val |= get_bits(&s->gb, shift);
+ val++;
+ }
+ if (sign)
+ val = -val;
+ val += pred;
+
+ /* modulo decoding */
+ l= INT_BIT - 5 - shift;
+ val = (val<<l)>>l;
+ return val;
+}
+
+static inline int decode_dc(GetBitContext *gb, int component)
+{
+ int code, diff;
+
+ if (component == 0) {
+ code = get_vlc2(gb, dc_lum_vlc.table, DC_VLC_BITS, 2);
+ } else {
+ code = get_vlc2(gb, dc_chroma_vlc.table, DC_VLC_BITS, 2);
+ }
+ if (code < 0){
+ av_log(NULL, AV_LOG_ERROR, "invalid dc code at\n");
+ return 0xffff;
+ }
+ if (code == 0) {
+ diff = 0;
+ } else {
+ diff = get_xbits(gb, code);
+ }
+ return diff;
+}
+
+static inline int mpeg1_decode_block_intra(MpegEncContext *s,
+ DCTELEM *block,
+ int n)
+{
+ int level, dc, diff, i, j, run;
+ int component;
+ RLTable *rl = &rl_mpeg1;
+ uint8_t * const scantable= s->intra_scantable.permutated;
+ const uint16_t *quant_matrix= s->intra_matrix;
+ const int qscale= s->qscale;
+
+ /* DC coef */
+ component = (n <= 3 ? 0 : n - 4 + 1);
+ diff = decode_dc(&s->gb, component);
+ if (diff >= 0xffff)
+ return -1;
+ dc = s->last_dc[component];
+ dc += diff;
+ s->last_dc[component] = dc;
+ block[0] = dc<<3;
+ dprintf(s->avctx, "dc=%d diff=%d\n", dc, diff);
+ i = 0;
+ {
+ OPEN_READER(re, &s->gb);
+ /* now quantify & encode AC coefs */
+ for(;;) {
+ UPDATE_CACHE(re, &s->gb);
+ GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
+
+ if(level == 127){
+ break;
+ } else if(level != 0) {
+ i += run;
+ j = scantable[i];
+ level= (level*qscale*quant_matrix[j])>>4;
+ level= (level-1)|1;
+ level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
+ LAST_SKIP_BITS(re, &s->gb, 1);
+ } else {
+ /* escape */
+ run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
+ UPDATE_CACHE(re, &s->gb);
+ level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8);
+ if (level == -128) {
+ level = SHOW_UBITS(re, &s->gb, 8) - 256; LAST_SKIP_BITS(re, &s->gb, 8);
+ } else if (level == 0) {
+ level = SHOW_UBITS(re, &s->gb, 8) ; LAST_SKIP_BITS(re, &s->gb, 8);
+ }
+ i += run;
+ j = scantable[i];
+ if(level<0){
+ level= -level;
+ level= (level*qscale*quant_matrix[j])>>4;
+ level= (level-1)|1;
+ level= -level;
+ }else{
+ level= (level*qscale*quant_matrix[j])>>4;
+ level= (level-1)|1;
+ }
+ }
+ if (i > 63){
+ av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
+ return -1;
+ }
+
+ block[j] = level;
+ }
+ CLOSE_READER(re, &s->gb);
+ }
+ s->block_last_index[n] = i;
+ return 0;
+}
+
+static inline int mpeg1_decode_block_inter(MpegEncContext *s,
+ DCTELEM *block,
+ int n)
+{
+ int level, i, j, run;
+ RLTable *rl = &rl_mpeg1;
+ uint8_t * const scantable= s->intra_scantable.permutated;
+ const uint16_t *quant_matrix= s->inter_matrix;
+ const int qscale= s->qscale;
+
+ {
+ OPEN_READER(re, &s->gb);
+ i = -1;
+ /* special case for the first coef. no need to add a second vlc table */
+ UPDATE_CACHE(re, &s->gb);
+ if (((int32_t)GET_CACHE(re, &s->gb)) < 0) {
+ level= (3*qscale*quant_matrix[0])>>5;
+ level= (level-1)|1;
+ if(GET_CACHE(re, &s->gb)&0x40000000)
+ level= -level;
+ block[0] = level;
+ i++;
+ SKIP_BITS(re, &s->gb, 2);
+ if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
+ goto end;
+ }
+
+ /* now quantify & encode AC coefs */
+ for(;;) {
+ GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
+
+ if(level != 0) {
+ i += run;
+ j = scantable[i];
+ level= ((level*2+1)*qscale*quant_matrix[j])>>5;
+ level= (level-1)|1;
+ level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
+ SKIP_BITS(re, &s->gb, 1);
+ } else {
+ /* escape */
+ run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
+ UPDATE_CACHE(re, &s->gb);
+ level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8);
+ if (level == -128) {
+ level = SHOW_UBITS(re, &s->gb, 8) - 256; SKIP_BITS(re, &s->gb, 8);
+ } else if (level == 0) {
+ level = SHOW_UBITS(re, &s->gb, 8) ; SKIP_BITS(re, &s->gb, 8);
+ }
+ i += run;
+ j = scantable[i];
+ if(level<0){
+ level= -level;
+ level= ((level*2+1)*qscale*quant_matrix[j])>>5;
+ level= (level-1)|1;
+ level= -level;
+ }else{
+ level= ((level*2+1)*qscale*quant_matrix[j])>>5;
+ level= (level-1)|1;
+ }
+ }
+ if (i > 63){
+ av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
+ return -1;
+ }
+
+ block[j] = level;
+ if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
+ break;
+ UPDATE_CACHE(re, &s->gb);
+ }
+end:
+ LAST_SKIP_BITS(re, &s->gb, 2);
+ CLOSE_READER(re, &s->gb);
+ }
+ s->block_last_index[n] = i;
+ return 0;
+}
+
+static inline int mpeg1_fast_decode_block_inter(MpegEncContext *s, DCTELEM *block, int n)
+{
+ int level, i, j, run;
+ RLTable *rl = &rl_mpeg1;
+ uint8_t * const scantable= s->intra_scantable.permutated;
+ const int qscale= s->qscale;
+
+ {
+ OPEN_READER(re, &s->gb);
+ i = -1;
+ /* special case for the first coef. no need to add a second vlc table */
+ UPDATE_CACHE(re, &s->gb);
+ if (((int32_t)GET_CACHE(re, &s->gb)) < 0) {
+ level= (3*qscale)>>1;
+ level= (level-1)|1;
+ if(GET_CACHE(re, &s->gb)&0x40000000)
+ level= -level;
+ block[0] = level;
+ i++;
+ SKIP_BITS(re, &s->gb, 2);
+ if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
+ goto end;
+ }
+
+ /* now quantify & encode AC coefs */
+ for(;;) {
+ GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
+
+ if(level != 0) {
+ i += run;
+ j = scantable[i];
+ level= ((level*2+1)*qscale)>>1;
+ level= (level-1)|1;
+ level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
+ SKIP_BITS(re, &s->gb, 1);
+ } else {
+ /* escape */
+ run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
+ UPDATE_CACHE(re, &s->gb);
+ level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8);
+ if (level == -128) {
+ level = SHOW_UBITS(re, &s->gb, 8) - 256; SKIP_BITS(re, &s->gb, 8);
+ } else if (level == 0) {
+ level = SHOW_UBITS(re, &s->gb, 8) ; SKIP_BITS(re, &s->gb, 8);
+ }
+ i += run;
+ j = scantable[i];
+ if(level<0){
+ level= -level;
+ level= ((level*2+1)*qscale)>>1;
+ level= (level-1)|1;
+ level= -level;
+ }else{
+ level= ((level*2+1)*qscale)>>1;
+ level= (level-1)|1;
+ }
+ }
+
+ block[j] = level;
+ if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
+ break;
+ UPDATE_CACHE(re, &s->gb);
+ }
+end:
+ LAST_SKIP_BITS(re, &s->gb, 2);
+ CLOSE_READER(re, &s->gb);
+ }
+ s->block_last_index[n] = i;
+ return 0;
+}
+
+
+static inline int mpeg2_decode_block_non_intra(MpegEncContext *s,
+ DCTELEM *block,
+ int n)
+{
+ int level, i, j, run;
+ RLTable *rl = &rl_mpeg1;
+ uint8_t * const scantable= s->intra_scantable.permutated;
+ const uint16_t *quant_matrix;
+ const int qscale= s->qscale;
+ int mismatch;
+
+ mismatch = 1;
+
+ {
+ OPEN_READER(re, &s->gb);
+ i = -1;
+ if (n < 4)
+ quant_matrix = s->inter_matrix;
+ else
+ quant_matrix = s->chroma_inter_matrix;
+
+ /* special case for the first coef. no need to add a second vlc table */
+ UPDATE_CACHE(re, &s->gb);
+ if (((int32_t)GET_CACHE(re, &s->gb)) < 0) {
+ level= (3*qscale*quant_matrix[0])>>5;
+ if(GET_CACHE(re, &s->gb)&0x40000000)
+ level= -level;
+ block[0] = level;
+ mismatch ^= level;
+ i++;
+ SKIP_BITS(re, &s->gb, 2);
+ if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
+ goto end;
+ }
+
+ /* now quantify & encode AC coefs */
+ for(;;) {
+ GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
+
+ if(level != 0) {
+ i += run;
+ j = scantable[i];
+ level= ((level*2+1)*qscale*quant_matrix[j])>>5;
+ level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
+ SKIP_BITS(re, &s->gb, 1);
+ } else {
+ /* escape */
+ run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
+ UPDATE_CACHE(re, &s->gb);
+ level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12);
+
+ i += run;
+ j = scantable[i];
+ if(level<0){
+ level= ((-level*2+1)*qscale*quant_matrix[j])>>5;
+ level= -level;
+ }else{
+ level= ((level*2+1)*qscale*quant_matrix[j])>>5;
+ }
+ }
+ if (i > 63){
+ av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
+ return -1;
+ }
+
+ mismatch ^= level;
+ block[j] = level;
+ if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
+ break;
+ UPDATE_CACHE(re, &s->gb);
+ }
+end:
+ LAST_SKIP_BITS(re, &s->gb, 2);
+ CLOSE_READER(re, &s->gb);
+ }
+ block[63] ^= (mismatch & 1);
+
+ s->block_last_index[n] = i;
+ return 0;
+}
+
+static inline int mpeg2_fast_decode_block_non_intra(MpegEncContext *s,
+ DCTELEM *block,
+ int n)
+{
+ int level, i, j, run;
+ RLTable *rl = &rl_mpeg1;
+ uint8_t * const scantable= s->intra_scantable.permutated;
+ const int qscale= s->qscale;
+ OPEN_READER(re, &s->gb);
+ i = -1;
+
+ /* special case for the first coef. no need to add a second vlc table */
+ UPDATE_CACHE(re, &s->gb);
+ if (((int32_t)GET_CACHE(re, &s->gb)) < 0) {
+ level= (3*qscale)>>1;
+ if(GET_CACHE(re, &s->gb)&0x40000000)
+ level= -level;
+ block[0] = level;
+ i++;
+ SKIP_BITS(re, &s->gb, 2);
+ if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
+ goto end;
+ }
+
+ /* now quantify & encode AC coefs */
+ for(;;) {
+ GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
+
+ if(level != 0) {
+ i += run;
+ j = scantable[i];
+ level= ((level*2+1)*qscale)>>1;
+ level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
+ SKIP_BITS(re, &s->gb, 1);
+ } else {
+ /* escape */
+ run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
+ UPDATE_CACHE(re, &s->gb);
+ level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12);
+
+ i += run;
+ j = scantable[i];
+ if(level<0){
+ level= ((-level*2+1)*qscale)>>1;
+ level= -level;
+ }else{
+ level= ((level*2+1)*qscale)>>1;
+ }
+ }
+
+ block[j] = level;
+ if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
+ break;
+ UPDATE_CACHE(re, &s->gb);
+ }
+end:
+ LAST_SKIP_BITS(re, &s->gb, 2);
+ CLOSE_READER(re, &s->gb);
+ s->block_last_index[n] = i;
+ return 0;
+}
+
+
+static inline int mpeg2_decode_block_intra(MpegEncContext *s,
+ DCTELEM *block,
+ int n)
+{
+ int level, dc, diff, i, j, run;
+ int component;
+ RLTable *rl;
+ uint8_t * const scantable= s->intra_scantable.permutated;
+ const uint16_t *quant_matrix;
+ const int qscale= s->qscale;
+ int mismatch;
+
+ /* DC coef */
+ if (n < 4){
+ quant_matrix = s->intra_matrix;
+ component = 0;
+ }else{
+ quant_matrix = s->chroma_intra_matrix;
+ component = (n&1) + 1;
+ }
+ diff = decode_dc(&s->gb, component);
+ if (diff >= 0xffff)
+ return -1;
+ dc = s->last_dc[component];
+ dc += diff;
+ s->last_dc[component] = dc;
+ block[0] = dc << (3 - s->intra_dc_precision);
+ dprintf(s->avctx, "dc=%d\n", block[0]);
+ mismatch = block[0] ^ 1;
+ i = 0;
+ if (s->intra_vlc_format)
+ rl = &rl_mpeg2;
+ else
+ rl = &rl_mpeg1;
+
+ {
+ OPEN_READER(re, &s->gb);
+ /* now quantify & encode AC coefs */
+ for(;;) {
+ UPDATE_CACHE(re, &s->gb);
+ GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
+
+ if(level == 127){
+ break;
+ } else if(level != 0) {
+ i += run;
+ j = scantable[i];
+ level= (level*qscale*quant_matrix[j])>>4;
+ level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
+ LAST_SKIP_BITS(re, &s->gb, 1);
+ } else {
+ /* escape */
+ run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
+ UPDATE_CACHE(re, &s->gb);
+ level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12);
+ i += run;
+ j = scantable[i];
+ if(level<0){
+ level= (-level*qscale*quant_matrix[j])>>4;
+ level= -level;
+ }else{
+ level= (level*qscale*quant_matrix[j])>>4;
+ }
+ }
+ if (i > 63){
+ av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
+ return -1;
+ }
+
+ mismatch^= level;
+ block[j] = level;
+ }
+ CLOSE_READER(re, &s->gb);
+ }
+ block[63]^= mismatch&1;
+
+ s->block_last_index[n] = i;
+ return 0;
+}
+
+static inline int mpeg2_fast_decode_block_intra(MpegEncContext *s,
+ DCTELEM *block,
+ int n)
+{
+ int level, dc, diff, j, run;
+ int component;
+ RLTable *rl;
+ uint8_t * scantable= s->intra_scantable.permutated;
+ const uint16_t *quant_matrix;
+ const int qscale= s->qscale;
+
+ /* DC coef */
+ if (n < 4){
+ quant_matrix = s->intra_matrix;
+ component = 0;
+ }else{
+ quant_matrix = s->chroma_intra_matrix;
+ component = (n&1) + 1;
+ }
+ diff = decode_dc(&s->gb, component);
+ if (diff >= 0xffff)
+ return -1;
+ dc = s->last_dc[component];
+ dc += diff;
+ s->last_dc[component] = dc;
+ block[0] = dc << (3 - s->intra_dc_precision);
+ if (s->intra_vlc_format)
+ rl = &rl_mpeg2;
+ else
+ rl = &rl_mpeg1;
+
+ {
+ OPEN_READER(re, &s->gb);
+ /* now quantify & encode AC coefs */
+ for(;;) {
+ UPDATE_CACHE(re, &s->gb);
+ GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
+
+ if(level == 127){
+ break;
+ } else if(level != 0) {
+ scantable += run;
+ j = *scantable;
+ level= (level*qscale*quant_matrix[j])>>4;
+ level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
+ LAST_SKIP_BITS(re, &s->gb, 1);
+ } else {
+ /* escape */
+ run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
+ UPDATE_CACHE(re, &s->gb);
+ level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12);
+ scantable += run;
+ j = *scantable;
+ if(level<0){
+ level= (-level*qscale*quant_matrix[j])>>4;
+ level= -level;
+ }else{
+ level= (level*qscale*quant_matrix[j])>>4;
+ }
+ }
+
+ block[j] = level;
+ }
+ CLOSE_READER(re, &s->gb);
+ }
+
+ s->block_last_index[n] = scantable - s->intra_scantable.permutated;
+ return 0;
+}
+
+typedef struct Mpeg1Context {
+ MpegEncContext mpeg_enc_ctx;
+ int mpeg_enc_ctx_allocated; /* true if decoding context allocated */
+ int repeat_field; /* true if we must repeat the field */
+ AVPanScan pan_scan; /** some temporary storage for the panscan */
+ int slice_count;
+ int swap_uv;//indicate VCR2
+ int save_aspect_info;
+ AVRational frame_rate_ext; ///< MPEG-2 specific framerate modificator
+
+} Mpeg1Context;
+
+static int mpeg_decode_init(AVCodecContext *avctx)
+{
+ Mpeg1Context *s = avctx->priv_data;
+ MpegEncContext *s2 = &s->mpeg_enc_ctx;
+ int i;
+
+ //we need some parmutation to store
+ //matrixes, until MPV_common_init()
+ //set the real permutatuon
+ for(i=0;i<64;i++)
+ s2->dsp.idct_permutation[i]=i;
+
+ MPV_decode_defaults(s2);
+
+ s->mpeg_enc_ctx.avctx= avctx;
+ s->mpeg_enc_ctx.flags= avctx->flags;
+ s->mpeg_enc_ctx.flags2= avctx->flags2;
+ common_init(&s->mpeg_enc_ctx);
+ init_vlcs();
+
+ s->mpeg_enc_ctx_allocated = 0;
+ s->mpeg_enc_ctx.picture_number = 0;
+ s->repeat_field = 0;
+ s->mpeg_enc_ctx.codec_id= avctx->codec->id;
+ return 0;
+}
+
+static void quant_matrix_rebuild(uint16_t *matrix, const uint8_t *old_perm,
+ const uint8_t *new_perm){
+ uint16_t temp_matrix[64];
+ int i;
+
+ memcpy(temp_matrix,matrix,64*sizeof(uint16_t));
+
+ for(i=0;i<64;i++){
+ matrix[new_perm[i]] = temp_matrix[old_perm[i]];
+ }
+}
+
+//Call this function when we know all parameters
+//it may be called in different places for mpeg1 and mpeg2
+static int mpeg_decode_postinit(AVCodecContext *avctx){
+ Mpeg1Context *s1 = avctx->priv_data;
+ MpegEncContext *s = &s1->mpeg_enc_ctx;
+ uint8_t old_permutation[64];
+
+ if (
+ (s1->mpeg_enc_ctx_allocated == 0)||
+ avctx->coded_width != s->width ||
+ avctx->coded_height != s->height||
+ s1->save_aspect_info != s->aspect_ratio_info||
+ 0)
+ {
+
+ if (s1->mpeg_enc_ctx_allocated) {
+ ParseContext pc= s->parse_context;
+ s->parse_context.buffer=0;
+ MPV_common_end(s);
+ s->parse_context= pc;
+ }
+
+ if( (s->width == 0 )||(s->height == 0))
+ return -2;
+
+ avcodec_set_dimensions(avctx, s->width, s->height);
+ avctx->bit_rate = s->bit_rate;
+ s1->save_aspect_info = s->aspect_ratio_info;
+
+ //low_delay may be forced, in this case we will have B frames
+ //that behave like P frames
+ avctx->has_b_frames = !(s->low_delay);
+
+ if(avctx->sub_id==1){//s->codec_id==avctx->codec_id==CODEC_ID
+ //mpeg1 fps
+ avctx->time_base.den= ff_frame_rate_tab[s->frame_rate_index].num;
+ avctx->time_base.num= ff_frame_rate_tab[s->frame_rate_index].den;
+ //mpeg1 aspect
+ avctx->sample_aspect_ratio= av_d2q(
+ 1.0/mpeg1_aspect[s->aspect_ratio_info], 255);
+
+ }else{//mpeg2
+ //mpeg2 fps
+ av_reduce(
+ &s->avctx->time_base.den,
+ &s->avctx->time_base.num,
+ ff_frame_rate_tab[s->frame_rate_index].num * s1->frame_rate_ext.num,
+ ff_frame_rate_tab[s->frame_rate_index].den * s1->frame_rate_ext.den,
+ 1<<30);
+ //mpeg2 aspect
+ if(s->aspect_ratio_info > 1){
+ if( (s1->pan_scan.width == 0 )||(s1->pan_scan.height == 0) ){
+ s->avctx->sample_aspect_ratio=
+ av_div_q(
+ mpeg2_aspect[s->aspect_ratio_info],
+ (AVRational){s->width, s->height}
+ );
+ }else{
+ s->avctx->sample_aspect_ratio=
+ av_div_q(
+ mpeg2_aspect[s->aspect_ratio_info],
+ (AVRational){s1->pan_scan.width, s1->pan_scan.height}
+ );
+ }
+ }else{
+ s->avctx->sample_aspect_ratio=
+ mpeg2_aspect[s->aspect_ratio_info];
+ }
+ }//mpeg2
+
+ if(avctx->xvmc_acceleration){
+ avctx->pix_fmt = avctx->get_format(avctx,pixfmt_xvmc_mpg2_420);
+ }else{
+ if(s->chroma_format < 2){
+ avctx->pix_fmt = avctx->get_format(avctx,pixfmt_yuv_420);
+ }else
+ if(s->chroma_format == 2){
+ avctx->pix_fmt = avctx->get_format(avctx,pixfmt_yuv_422);
+ }else
+ if(s->chroma_format > 2){
+ avctx->pix_fmt = avctx->get_format(avctx,pixfmt_yuv_444);
+ }
+ }
+ //until then pix_fmt may be changed right after codec init
+ if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT )
+ if( avctx->idct_algo == FF_IDCT_AUTO )
+ avctx->idct_algo = FF_IDCT_SIMPLE;
+
+ //quantization matrixes may need reordering
+ //if dct permutation is changed
+ memcpy(old_permutation,s->dsp.idct_permutation,64*sizeof(uint8_t));
+
+ if (MPV_common_init(s) < 0)
+ return -2;
+
+ quant_matrix_rebuild(s->intra_matrix, old_permutation,s->dsp.idct_permutation);
+ quant_matrix_rebuild(s->inter_matrix, old_permutation,s->dsp.idct_permutation);
+ quant_matrix_rebuild(s->chroma_intra_matrix,old_permutation,s->dsp.idct_permutation);
+ quant_matrix_rebuild(s->chroma_inter_matrix,old_permutation,s->dsp.idct_permutation);
+
+ s1->mpeg_enc_ctx_allocated = 1;
+ }
+ return 0;
+}
+
+static int mpeg1_decode_picture(AVCodecContext *avctx,
+ const uint8_t *buf, int buf_size)
+{
+ Mpeg1Context *s1 = avctx->priv_data;
+ 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 */
+ s->pict_type = get_bits(&s->gb, 3);
+ if(s->pict_type == 0 || s->pict_type > 3)
+ return -1;
+
+ vbv_delay= get_bits(&s->gb, 16);
+ if (s->pict_type == P_TYPE || s->pict_type == B_TYPE) {
+ s->full_pel[0] = get_bits1(&s->gb);
+ f_code = get_bits(&s->gb, 3);
+ if (f_code == 0 && avctx->error_resilience >= FF_ER_COMPLIANT)
+ return -1;
+ s->mpeg_f_code[0][0] = f_code;
+ s->mpeg_f_code[0][1] = f_code;
+ }
+ if (s->pict_type == B_TYPE) {
+ s->full_pel[1] = get_bits1(&s->gb);
+ f_code = get_bits(&s->gb, 3);
+ if (f_code == 0 && avctx->error_resilience >= FF_ER_COMPLIANT)
+ return -1;
+ s->mpeg_f_code[1][0] = f_code;
+ s->mpeg_f_code[1][1] = f_code;
+ }
+ s->current_picture.pict_type= s->pict_type;
+ s->current_picture.key_frame= s->pict_type == I_TYPE;
+
+ if(avctx->debug & FF_DEBUG_PICT_INFO)
+ av_log(avctx, AV_LOG_DEBUG, "vbv_delay %d, ref %d type:%d\n", vbv_delay, ref, s->pict_type);
+
+ s->y_dc_scale = 8;
+ s->c_dc_scale = 8;
+ s->first_slice = 1;
+ return 0;
+}
+
+static void mpeg_decode_sequence_extension(Mpeg1Context *s1)
+{
+ MpegEncContext *s= &s1->mpeg_enc_ctx;
+ int horiz_size_ext, vert_size_ext;
+ int bit_rate_ext;
+
+ skip_bits(&s->gb, 1); /* profil and level esc*/
+ s->avctx->profile= get_bits(&s->gb, 3);
+ s->avctx->level= get_bits(&s->gb, 4);
+ s->progressive_sequence = get_bits1(&s->gb); /* progressive_sequence */
+ s->chroma_format = get_bits(&s->gb, 2); /* chroma_format 1=420, 2=422, 3=444 */
+ horiz_size_ext = get_bits(&s->gb, 2);
+ vert_size_ext = get_bits(&s->gb, 2);
+ s->width |= (horiz_size_ext << 12);
+ s->height |= (vert_size_ext << 12);
+ bit_rate_ext = get_bits(&s->gb, 12); /* XXX: handle it */
+ s->bit_rate += (bit_rate_ext << 18) * 400;
+ skip_bits1(&s->gb); /* marker */
+ s->avctx->rc_buffer_size += get_bits(&s->gb, 8)*1024*16<<10;
+
+ s->low_delay = get_bits1(&s->gb);
+ if(s->flags & CODEC_FLAG_LOW_DELAY) s->low_delay=1;
+
+ s1->frame_rate_ext.num = get_bits(&s->gb, 2)+1;
+ s1->frame_rate_ext.den = get_bits(&s->gb, 5)+1;
+
+ dprintf(s->avctx, "sequence extension\n");
+ s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG2VIDEO;
+ s->avctx->sub_id = 2; /* indicates mpeg2 found */
+
+ if(s->avctx->debug & FF_DEBUG_PICT_INFO)
+ av_log(s->avctx, AV_LOG_DEBUG, "profile: %d, level: %d vbv buffer: %d, bitrate:%d\n",
+ s->avctx->profile, s->avctx->level, s->avctx->rc_buffer_size, s->bit_rate);
+
+}
+
+static void mpeg_decode_sequence_display_extension(Mpeg1Context *s1)
+{
+ MpegEncContext *s= &s1->mpeg_enc_ctx;
+ int color_description, w, h;
+
+ skip_bits(&s->gb, 3); /* video format */
+ color_description= get_bits1(&s->gb);
+ if(color_description){
+ skip_bits(&s->gb, 8); /* color primaries */
+ skip_bits(&s->gb, 8); /* transfer_characteristics */
+ skip_bits(&s->gb, 8); /* matrix_coefficients */
+ }
+ w= get_bits(&s->gb, 14);
+ skip_bits(&s->gb, 1); //marker
+ h= get_bits(&s->gb, 14);
+ skip_bits(&s->gb, 1); //marker
+
+ s1->pan_scan.width= 16*w;
+ s1->pan_scan.height=16*h;
+
+ if(s->avctx->debug & FF_DEBUG_PICT_INFO)
+ av_log(s->avctx, AV_LOG_DEBUG, "sde w:%d, h:%d\n", w, h);
+}
+
+static void mpeg_decode_picture_display_extension(Mpeg1Context *s1)
+{
+ MpegEncContext *s= &s1->mpeg_enc_ctx;
+ int i,nofco;
+
+ nofco = 1;
+ if(s->progressive_sequence){
+ if(s->repeat_first_field){
+ nofco++;
+ if(s->top_field_first)
+ nofco++;
+ }
+ }else{
+ if(s->picture_structure == PICT_FRAME){
+ nofco++;
+ if(s->repeat_first_field)
+ nofco++;
+ }
+ }
+ for(i=0; i<nofco; i++){
+ s1->pan_scan.position[i][0]= get_sbits(&s->gb, 16);
+ skip_bits(&s->gb, 1); //marker
+ s1->pan_scan.position[i][1]= get_sbits(&s->gb, 16);
+ skip_bits(&s->gb, 1); //marker
+ }
+
+ if(s->avctx->debug & FF_DEBUG_PICT_INFO)
+ av_log(s->avctx, AV_LOG_DEBUG, "pde (%d,%d) (%d,%d) (%d,%d)\n",
+ s1->pan_scan.position[0][0], s1->pan_scan.position[0][1],
+ s1->pan_scan.position[1][0], s1->pan_scan.position[1][1],
+ s1->pan_scan.position[2][0], s1->pan_scan.position[2][1]
+ );
+}
+
+static void mpeg_decode_quant_matrix_extension(MpegEncContext *s)
+{
+ int i, v, j;
+
+ dprintf(s->avctx, "matrix extension\n");
+
+ if (get_bits1(&s->gb)) {
+ for(i=0;i<64;i++) {
+ v = get_bits(&s->gb, 8);
+ j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
+ s->intra_matrix[j] = v;
+ s->chroma_intra_matrix[j] = v;
+ }
+ }
+ if (get_bits1(&s->gb)) {
+ for(i=0;i<64;i++) {
+ v = get_bits(&s->gb, 8);
+ j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
+ s->inter_matrix[j] = v;
+ s->chroma_inter_matrix[j] = v;
+ }
+ }
+ if (get_bits1(&s->gb)) {
+ for(i=0;i<64;i++) {
+ v = get_bits(&s->gb, 8);
+ j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
+ s->chroma_intra_matrix[j] = v;
+ }
+ }
+ if (get_bits1(&s->gb)) {
+ for(i=0;i<64;i++) {
+ v = get_bits(&s->gb, 8);
+ j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
+ s->chroma_inter_matrix[j] = v;
+ }
+ }
+}
+
+static void mpeg_decode_picture_coding_extension(MpegEncContext *s)
+{
+ s->full_pel[0] = s->full_pel[1] = 0;
+ s->mpeg_f_code[0][0] = get_bits(&s->gb, 4);
+ s->mpeg_f_code[0][1] = get_bits(&s->gb, 4);
+ s->mpeg_f_code[1][0] = get_bits(&s->gb, 4);
+ s->mpeg_f_code[1][1] = get_bits(&s->gb, 4);
+ s->intra_dc_precision = get_bits(&s->gb, 2);
+ s->picture_structure = get_bits(&s->gb, 2);
+ s->top_field_first = get_bits1(&s->gb);
+ s->frame_pred_frame_dct = get_bits1(&s->gb);
+ s->concealment_motion_vectors = get_bits1(&s->gb);
+ s->q_scale_type = get_bits1(&s->gb);
+ s->intra_vlc_format = get_bits1(&s->gb);
+ s->alternate_scan = get_bits1(&s->gb);
+ s->repeat_first_field = get_bits1(&s->gb);
+ s->chroma_420_type = get_bits1(&s->gb);
+ s->progressive_frame = get_bits1(&s->gb);
+
+ if(s->picture_structure == PICT_FRAME){
+ s->first_field=0;
+ s->v_edge_pos= 16*s->mb_height;
+ }else{
+ s->first_field ^= 1;
+ s->v_edge_pos= 8*s->mb_height;
+ memset(s->mbskip_table, 0, s->mb_stride*s->mb_height);
+ }
+
+ if(s->alternate_scan){
+ ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_alternate_vertical_scan);
+ ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_alternate_vertical_scan);
+ }else{
+ ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_zigzag_direct);
+ ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_zigzag_direct);
+ }
+
+ /* composite display not parsed */
+ dprintf(s->avctx, "intra_dc_precision=%d\n", s->intra_dc_precision);
+ dprintf(s->avctx, "picture_structure=%d\n", s->picture_structure);
+ dprintf(s->avctx, "top field first=%d\n", s->top_field_first);
+ dprintf(s->avctx, "repeat first field=%d\n", s->repeat_first_field);
+ dprintf(s->avctx, "conceal=%d\n", s->concealment_motion_vectors);
+ dprintf(s->avctx, "intra_vlc_format=%d\n", s->intra_vlc_format);
+ dprintf(s->avctx, "alternate_scan=%d\n", s->alternate_scan);
+ dprintf(s->avctx, "frame_pred_frame_dct=%d\n", s->frame_pred_frame_dct);
+ 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(s);
+ break;
+ }
+}
+
+static void exchange_uv(MpegEncContext *s){
+ short * tmp = s->pblocks[4];
+ s->pblocks[4] = s->pblocks[5];
+ s->pblocks[5] = tmp;
+}
+
+static int mpeg_field_start(MpegEncContext *s){
+ AVCodecContext *avctx= s->avctx;
+ Mpeg1Context *s1 = (Mpeg1Context*)s;
+
+ /* start frame decoding */
+ if(s->first_field || s->picture_structure==PICT_FRAME){
+ if(MPV_frame_start(s, avctx) < 0)
+ return -1;
+
+ ff_er_frame_start(s);
+
+ /* first check if we must repeat the frame */
+ s->current_picture_ptr->repeat_pict = 0;
+ if (s->repeat_first_field) {
+ if (s->progressive_sequence) {
+ if (s->top_field_first)
+ s->current_picture_ptr->repeat_pict = 4;
+ else
+ s->current_picture_ptr->repeat_pict = 2;
+ } else if (s->progressive_frame) {
+ s->current_picture_ptr->repeat_pict = 1;
+ }
+ }
+
+ *s->current_picture_ptr->pan_scan= s1->pan_scan;
+ }else{ //second field
+ int i;
+
+ if(!s->current_picture_ptr){
+ av_log(s->avctx, AV_LOG_ERROR, "first field missing\n");
+ return -1;
+ }
+
+ for(i=0; i<4; i++){
+ s->current_picture.data[i] = s->current_picture_ptr->data[i];
+ if(s->picture_structure == PICT_BOTTOM_FIELD){
+ s->current_picture.data[i] += s->current_picture_ptr->linesize[i];
+ }
+ }
+ }
+#ifdef HAVE_XVMC
+// MPV_frame_start will call this function too,
+// but we need to call it on every field
+ if(s->avctx->xvmc_acceleration)
+ XVMC_field_start(s,avctx);
+#endif
+
+ return 0;
+}
+
+#define DECODE_SLICE_ERROR -1
+#define DECODE_SLICE_OK 0
+
+/**
+ * decodes a slice. MpegEncContext.mb_y must be set to the MB row from the startcode
+ * @return DECODE_SLICE_ERROR if the slice is damaged<br>
+ * DECODE_SLICE_OK if this slice is ok<br>
+ */
+static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y,
+ const uint8_t **buf, int buf_size)
+{
+ MpegEncContext *s = &s1->mpeg_enc_ctx;
+ AVCodecContext *avctx= s->avctx;
+ int ret;
+ const int field_pic= s->picture_structure != PICT_FRAME;
+ const int lowres= s->avctx->lowres;
+
+ s->resync_mb_x=
+ s->resync_mb_y= -1;
+
+ if (mb_y<<field_pic >= s->mb_height){
+ av_log(s->avctx, AV_LOG_ERROR, "slice below image (%d >= %d)\n", mb_y, s->mb_height);
+ return -1;
+ }
+
+ init_get_bits(&s->gb, *buf, buf_size*8);
+
+ ff_mpeg1_clean_buffers(s);
+ s->interlaced_dct = 0;
+
+ s->qscale = get_qscale(s);
+
+ if(s->qscale == 0){
+ av_log(s->avctx, AV_LOG_ERROR, "qscale == 0\n");
+ return -1;
+ }
+
+ /* extra slice info */
+ while (get_bits1(&s->gb) != 0) {
+ skip_bits(&s->gb, 8);
+ }
+
+ s->mb_x=0;
+
+ 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;
+ ff_init_block_index(s);
+
+ if (s->mb_y==0 && s->mb_x==0 && (s->first_field || s->picture_structure==PICT_FRAME)) {
+ if(s->avctx->debug&FF_DEBUG_PICT_INFO){
+ av_log(s->avctx, AV_LOG_DEBUG, "qp:%d fc:%2d%2d%2d%2d %s %s %s %s %s dc:%d pstruct:%d fdct:%d cmv:%d qtype:%d ivlc:%d rff:%d %s\n",
+ s->qscale, s->mpeg_f_code[0][0],s->mpeg_f_code[0][1],s->mpeg_f_code[1][0],s->mpeg_f_code[1][1],
+ s->pict_type == I_TYPE ? "I" : (s->pict_type == P_TYPE ? "P" : (s->pict_type == B_TYPE ? "B" : "S")),
+ s->progressive_sequence ? "ps" :"", s->progressive_frame ? "pf" : "", s->alternate_scan ? "alt" :"", s->top_field_first ? "top" :"",
+ s->intra_dc_precision, s->picture_structure, s->frame_pred_frame_dct, s->concealment_motion_vectors,
+ s->q_scale_type, s->intra_vlc_format, s->repeat_first_field, s->chroma_420_type ? "420" :"");
+ }
+ }
+
+ for(;;) {
+#ifdef HAVE_XVMC
+ //one 1 we memcpy blocks in xvmcvideo
+ if(s->avctx->xvmc_acceleration > 1)
+ XVMC_init_block(s);//set s->block
+#endif
+
+ ret = mpeg_decode_mb(s, s->block);
+ s->chroma_qscale= s->qscale;
+
+ dprintf(s->avctx, "ret=%d\n", ret);
+ if (ret < 0)
+ return -1;
+
+ if(s->current_picture.motion_val[0] && !s->encoding){ //note motion_val is normally NULL unless we want to extract the MVs
+ const int wrap = field_pic ? 2*s->b8_stride : s->b8_stride;
+ int xy = s->mb_x*2 + s->mb_y*2*wrap;
+ 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++){
+ if (s->mb_intra || (dir==1 && s->pict_type != B_TYPE)) {
+ motion_x = motion_y = 0;
+ }else if (s->mv_type == MV_TYPE_16X16 || (s->mv_type == MV_TYPE_FIELD && field_pic)){
+ motion_x = s->mv[dir][0][0];
+ motion_y = s->mv[dir][0][1];
+ } else /*if ((s->mv_type == MV_TYPE_FIELD) || (s->mv_type == MV_TYPE_16X8))*/ {
+ motion_x = s->mv[dir][i][0];
+ motion_y = s->mv[dir][i][1];
+ }
+
+ s->current_picture.motion_val[dir][xy ][0] = motion_x;
+ s->current_picture.motion_val[dir][xy ][1] = motion_y;
+ s->current_picture.motion_val[dir][xy + 1][0] = motion_x;
+ s->current_picture.motion_val[dir][xy + 1][1] = motion_y;
+ s->current_picture.ref_index [dir][xy ]=
+ s->current_picture.ref_index [dir][xy + 1]= s->field_select[dir][i];
+ assert(s->field_select[dir][i]==0 || s->field_select[dir][i]==1);
+ }
+ xy += wrap;
+ }
+ }
+
+ s->dest[0] += 16 >> lowres;
+ s->dest[1] += 16 >> (s->chroma_x_shift + lowres);
+ s->dest[2] += 16 >> (s->chroma_x_shift + lowres);
+
+ MPV_decode_mb(s, s->block);
+
+ 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);
+
+ s->mb_x = 0;
+ s->mb_y++;
+
+ if(s->mb_y<<field_pic >= s->mb_height){
+ int left= s->gb.size_in_bits - get_bits_count(&s->gb);
+ int is_d10= s->chroma_format==2 && s->pict_type==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*/;
+
+ if(left < 0 || (left && show_bits(&s->gb, FFMIN(left, 23)) && !is_d10)
+ || (avctx->error_resilience >= FF_ER_AGGRESSIVE && left>8)){
+ av_log(avctx, AV_LOG_ERROR, "end mismatch left=%d %0X\n", left, show_bits(&s->gb, FFMIN(left, 23)));
+ return -1;
+ }else
+ goto eos;
+ }
+
+ ff_init_block_index(s);
+ }
+
+ /* skip mb handling */
+ if (s->mb_skip_run == -1) {
+ /* read again increment */
+ s->mb_skip_run = 0;
+ for(;;) {
+ int code = get_vlc2(&s->gb, mbincr_vlc.table, MBINCR_VLC_BITS, 2);
+ if (code < 0){
+ av_log(s->avctx, AV_LOG_ERROR, "mb incr damaged\n");
+ return -1;
+ }
+ if (code >= 33) {
+ if (code == 33) {
+ s->mb_skip_run += 33;
+ }else if(code == 35){
+ if(s->mb_skip_run != 0 || show_bits(&s->gb, 15) != 0){
+ av_log(s->avctx, AV_LOG_ERROR, "slice mismatch\n");
+ return -1;
+ }
+ goto eos; /* end of slice */
+ }
+ /* otherwise, stuffing, nothing to do */
+ } else {
+ s->mb_skip_run += code;
+ break;
+ }
+ }
+ }
+ }
+eos: // end of slice
+ *buf += get_bits_count(&s->gb)/8 - 1;
+//printf("y %d %d %d %d\n", s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y);
+ return 0;
+}
+
+static int slice_decode_thread(AVCodecContext *c, void *arg){
+ MpegEncContext *s= arg;
+ const uint8_t *buf= s->gb.buffer;
+ int mb_y= s->start_mb_y;
+
+ s->error_count= 3*(s->end_mb_y - s->start_mb_y)*s->mb_width;
+
+ for(;;){
+ uint32_t start_code;
+ int ret;
+
+ ret= mpeg_decode_slice((Mpeg1Context*)s, mb_y, &buf, s->gb.buffer_end - buf);
+ emms_c();
+//av_log(c, AV_LOG_DEBUG, "ret:%d resync:%d/%d mb:%d/%d ts:%d/%d ec:%d\n",
+//ret, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, s->start_mb_y, s->end_mb_y, s->error_count);
+ if(ret < 0){
+ if(s->resync_mb_x>=0 && s->resync_mb_y>=0)
+ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, AC_ERROR|DC_ERROR|MV_ERROR);
+ }else{
+ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, AC_END|DC_END|MV_END);
+ }
+
+ if(s->mb_y == s->end_mb_y)
+ return 0;
+
+ start_code= -1;
+ buf = ff_find_start_code(buf, s->gb.buffer_end, &start_code);
+ mb_y= start_code - SLICE_MIN_START_CODE;
+ if(mb_y < 0 || mb_y >= s->end_mb_y)
+ return -1;
+ }
+
+ return 0; //not reached
+}
+
+/**
+ * handles slice ends.
+ * @return 1 if it seems to be the last slice of
+ */
+static int slice_end(AVCodecContext *avctx, AVFrame *pict)
+{
+ Mpeg1Context *s1 = avctx->priv_data;
+ MpegEncContext *s = &s1->mpeg_enc_ctx;
+
+ if (!s1->mpeg_enc_ctx_allocated || !s->current_picture_ptr)
+ return 0;
+
+#ifdef HAVE_XVMC
+ if(s->avctx->xvmc_acceleration)
+ XVMC_field_end(s);
+#endif
+ /* end of slice reached */
+ if (/*s->mb_y<<field_pic == s->mb_height &&*/ !s->first_field) {
+ /* end of image */
+
+ s->current_picture_ptr->qscale_type= FF_QSCALE_TYPE_MPEG2;
+
+ ff_er_frame_end(s);
+
+ MPV_frame_end(s);
+
+ if (s->pict_type == B_TYPE || s->low_delay) {
+ *pict= *(AVFrame*)s->current_picture_ptr;
+ ff_print_debug_info(s, pict);
+ } else {
+ s->picture_number++;
+ /* latency of 1 frame for I and P frames */
+ /* XXX: use another variable than picture_number */
+ if (s->last_picture_ptr != NULL) {
+ *pict= *(AVFrame*)s->last_picture_ptr;
+ ff_print_debug_info(s, pict);
+ }
+ }
+
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+static int mpeg1_decode_sequence(AVCodecContext *avctx,
+ const uint8_t *buf, int buf_size)
+{
+ Mpeg1Context *s1 = avctx->priv_data;
+ MpegEncContext *s = &s1->mpeg_enc_ctx;
+ int width,height;
+ int i, v, j;
+
+ init_get_bits(&s->gb, buf, buf_size*8);
+
+ width = get_bits(&s->gb, 12);
+ height = get_bits(&s->gb, 12);
+ if (width <= 0 || height <= 0 ||
+ (width % 2) != 0 || (height % 2) != 0)
+ return -1;
+ s->aspect_ratio_info= get_bits(&s->gb, 4);
+ if (s->aspect_ratio_info == 0)
+ return -1;
+ s->frame_rate_index = get_bits(&s->gb, 4);
+ if (s->frame_rate_index == 0 || s->frame_rate_index > 13)
+ return -1;
+ s->bit_rate = get_bits(&s->gb, 18) * 400;
+ if (get_bits1(&s->gb) == 0) /* marker */
+ return -1;
+ s->width = width;
+ s->height = height;
+
+ s->avctx->rc_buffer_size= get_bits(&s->gb, 10) * 1024*16;
+ skip_bits(&s->gb, 1);
+
+ /* get matrix */
+ if (get_bits1(&s->gb)) {
+ for(i=0;i<64;i++) {
+ v = get_bits(&s->gb, 8);
+ if(v==0){
+ av_log(s->avctx, AV_LOG_ERROR, "intra matrix damaged\n");
+ return -1;
+ }
+ j = s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
+ s->intra_matrix[j] = v;
+ s->chroma_intra_matrix[j] = v;
+ }
+#ifdef DEBUG
+ dprintf(s->avctx, "intra matrix present\n");
+ for(i=0;i<64;i++)
+ dprintf(s->avctx, " %d", s->intra_matrix[s->dsp.idct_permutation[i]]);
+ dprintf(s->avctx, "\n");
+#endif
+ } else {
+ for(i=0;i<64;i++) {
+ j = s->dsp.idct_permutation[i];
+ v = ff_mpeg1_default_intra_matrix[i];
+ s->intra_matrix[j] = v;
+ s->chroma_intra_matrix[j] = v;
+ }
+ }
+ if (get_bits1(&s->gb)) {
+ for(i=0;i<64;i++) {
+ v = get_bits(&s->gb, 8);
+ if(v==0){
+ av_log(s->avctx, AV_LOG_ERROR, "inter matrix damaged\n");
+ return -1;
+ }
+ j = s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
+ s->inter_matrix[j] = v;
+ s->chroma_inter_matrix[j] = v;
+ }
+#ifdef DEBUG
+ dprintf(s->avctx, "non intra matrix present\n");
+ for(i=0;i<64;i++)
+ dprintf(s->avctx, " %d", s->inter_matrix[s->dsp.idct_permutation[i]]);
+ dprintf(s->avctx, "\n");
+#endif
+ } else {
+ for(i=0;i<64;i++) {
+ int j= s->dsp.idct_permutation[i];
+ v = ff_mpeg1_default_non_intra_matrix[i];
+ s->inter_matrix[j] = v;
+ s->chroma_inter_matrix[j] = v;
+ }
+ }
+
+ if(show_bits(&s->gb, 23) != 0){
+ av_log(s->avctx, AV_LOG_ERROR, "sequence header damaged\n");
+ return -1;
+ }
+
+ /* we set mpeg2 parameters so that it emulates mpeg1 */
+ s->progressive_sequence = 1;
+ s->progressive_frame = 1;
+ s->picture_structure = PICT_FRAME;
+ s->frame_pred_frame_dct = 1;
+ s->chroma_format = 1;
+ s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG1VIDEO;
+ avctx->sub_id = 1; /* indicates mpeg1 */
+ s->out_format = FMT_MPEG1;
+ s->swap_uv = 0;//AFAIK VCR2 don't have SEQ_HEADER
+ if(s->flags & CODEC_FLAG_LOW_DELAY) s->low_delay=1;
+
+ if(s->avctx->debug & FF_DEBUG_PICT_INFO)
+ av_log(s->avctx, AV_LOG_DEBUG, "vbv buffer: %d, bitrate:%d\n",
+ s->avctx->rc_buffer_size, s->bit_rate);
+
+ return 0;
+}
+
+static int vcr2_init_sequence(AVCodecContext *avctx)
+{
+ Mpeg1Context *s1 = avctx->priv_data;
+ MpegEncContext *s = &s1->mpeg_enc_ctx;
+ int i, v;
+
+ /* start new mpeg1 context decoding */
+ s->out_format = FMT_MPEG1;
+ if (s1->mpeg_enc_ctx_allocated) {
+ MPV_common_end(s);
+ }
+ s->width = avctx->coded_width;
+ s->height = avctx->coded_height;
+ avctx->has_b_frames= 0; //true?
+ s->low_delay= 1;
+
+ if(avctx->xvmc_acceleration){
+ avctx->pix_fmt = avctx->get_format(avctx,pixfmt_xvmc_mpg2_420);
+ }else{
+ avctx->pix_fmt = avctx->get_format(avctx,pixfmt_yuv_420);
+ }
+
+ if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT )
+ if( avctx->idct_algo == FF_IDCT_AUTO )
+ avctx->idct_algo = FF_IDCT_SIMPLE;
+
+ if (MPV_common_init(s) < 0)
+ return -1;
+ exchange_uv(s);//common init reset pblocks, so we swap them here
+ s->swap_uv = 1;// in case of xvmc we need to swap uv for each MB
+ s1->mpeg_enc_ctx_allocated = 1;
+
+ for(i=0;i<64;i++) {
+ int j= s->dsp.idct_permutation[i];
+ v = ff_mpeg1_default_intra_matrix[i];
+ s->intra_matrix[j] = v;
+ s->chroma_intra_matrix[j] = v;
+
+ v = ff_mpeg1_default_non_intra_matrix[i];
+ s->inter_matrix[j] = v;
+ s->chroma_inter_matrix[j] = v;
+ }
+
+ s->progressive_sequence = 1;
+ s->progressive_frame = 1;
+ s->picture_structure = PICT_FRAME;
+ s->frame_pred_frame_dct = 1;
+ s->chroma_format = 1;
+ s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG2VIDEO;
+ avctx->sub_id = 2; /* indicates mpeg2 */
+ return 0;
+}
+
+
+static void mpeg_decode_user_data(AVCodecContext *avctx,
+ const uint8_t *buf, int buf_size)
+{
+ const uint8_t *p;
+ int len, flags;
+ p = buf;
+ len = buf_size;
+
+ /* we parse the DTG active format information */
+ if (len >= 5 &&
+ p[0] == 'D' && p[1] == 'T' && p[2] == 'G' && p[3] == '1') {
+ 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)
+ return;
+ avctx->dtg_active_format = p[0] & 0x0f;
+ }
+ }
+}
+
+static void mpeg_decode_gop(AVCodecContext *avctx,
+ const uint8_t *buf, int buf_size){
+ Mpeg1Context *s1 = avctx->priv_data;
+ MpegEncContext *s = &s1->mpeg_enc_ctx;
+
+ int drop_frame_flag;
+ int time_code_hours, time_code_minutes;
+ int time_code_seconds, time_code_pictures;
+ int broken_link;
+
+ init_get_bits(&s->gb, buf, buf_size*8);
+
+ drop_frame_flag = get_bits1(&s->gb);
+
+ time_code_hours=get_bits(&s->gb,5);
+ time_code_minutes = get_bits(&s->gb,6);
+ skip_bits1(&s->gb);//marker bit
+ time_code_seconds = get_bits(&s->gb,6);
+ time_code_pictures = get_bits(&s->gb,6);
+
+ /*broken_link indicate that after editing the
+ reference frames of the first B-Frames after GOP I-Frame
+ are missing (open gop)*/
+ broken_link = get_bits1(&s->gb);
+
+ if(s->avctx->debug & FF_DEBUG_PICT_INFO)
+ av_log(s->avctx, AV_LOG_DEBUG, "GOP (%2d:%02d:%02d.[%02d]) broken_link=%d\n",
+ time_code_hours, time_code_minutes, time_code_seconds,
+ time_code_pictures, broken_link);
+}
+/**
+ * finds the end of the current frame in the bitstream.
+ * @return the position of the first byte of the next frame, or -1
+ */
+static int mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size)
+{
+ int i;
+ uint32_t state= pc->state;
+
+ i=0;
+ if(!pc->frame_start_found){
+ for(i=0; i<buf_size; i++){
+ i= ff_find_start_code(buf+i, buf+buf_size, &state) - buf - 1;
+ if(state >= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE){
+ i++;
+ pc->frame_start_found=1;
+ break;
+ }
+ }
+ }
+
+ if(pc->frame_start_found){
+ /* EOF considered as end of frame */
+ if (buf_size == 0)
+ return 0;
+ for(; i<buf_size; i++){
+ i= ff_find_start_code(buf+i, buf+buf_size, &state) - buf - 1;
+ if((state&0xFFFFFF00) == 0x100){
+ if(state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE){
+ pc->frame_start_found=0;
+ pc->state=-1;
+ return i-3;
+ }
+ }
+ }
+ }
+ pc->state= state;
+ return END_NOT_FOUND;
+}
+
+/* handle buffering and image synchronisation */
+static int mpeg_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ Mpeg1Context *s = avctx->priv_data;
+ const uint8_t *buf_end;
+ const uint8_t *buf_ptr;
+ uint32_t start_code;
+ int ret, input_size;
+ AVFrame *picture = data;
+ MpegEncContext *s2 = &s->mpeg_enc_ctx;
+ dprintf(avctx, "fill_buffer\n");
+
+ if (buf_size == 0) {
+ /* special case for last picture */
+ if (s2->low_delay==0 && s2->next_picture_ptr) {
+ *picture= *(AVFrame*)s2->next_picture_ptr;
+ s2->next_picture_ptr= NULL;
+
+ *data_size = sizeof(AVFrame);
+ }
+ return 0;
+ }
+
+ if(s2->flags&CODEC_FLAG_TRUNCATED){
+ int next= mpeg1_find_frame_end(&s2->parse_context, buf, buf_size);
+
+ if( ff_combine_frame(&s2->parse_context, next, &buf, &buf_size) < 0 )
+ return buf_size;
+ }
+
+ buf_ptr = buf;
+ buf_end = buf + buf_size;
+
+#if 0
+ if (s->repeat_field % 2 == 1) {
+ s->repeat_field++;
+ //fprintf(stderr,"\nRepeating last frame: %d -> %d! pict: %d %d", avctx->frame_number-1, avctx->frame_number,
+ // s2->picture_number, s->repeat_field);
+ if (avctx->flags & CODEC_FLAG_REPEAT_FIELD) {
+ *data_size = sizeof(AVPicture);
+ goto the_end;
+ }
+ }
+#endif
+
+ if(s->mpeg_enc_ctx_allocated==0 && avctx->codec_tag == ff_get_fourcc("VCR2"))
+ vcr2_init_sequence(avctx);
+
+ s->slice_count= 0;
+
+ for(;;) {
+ /* find start next code */
+ start_code = -1;
+ buf_ptr = ff_find_start_code(buf_ptr,buf_end, &start_code);
+ if (start_code > 0x1ff){
+ if(s2->pict_type != B_TYPE || avctx->skip_frame <= AVDISCARD_DEFAULT){
+ if(avctx->thread_count > 1){
+ int i;
+
+ avctx->execute(avctx, slice_decode_thread, (void**)&(s2->thread_context[0]), NULL, s->slice_count);
+ for(i=0; i<s->slice_count; i++)
+ s2->error_count += s2->thread_context[i]->error_count;
+ }
+ if (slice_end(avctx, picture)) {
+ if(s2->last_picture_ptr || s2->low_delay) //FIXME merge with the stuff in mpeg_decode_slice
+ *data_size = sizeof(AVPicture);
+ }
+ }
+ return FFMAX(0, buf_ptr - buf - s2->parse_context.last_index);
+ }
+
+ input_size = buf_end - buf_ptr;
+
+ if(avctx->debug & FF_DEBUG_STARTCODE){
+ av_log(avctx, AV_LOG_DEBUG, "%3X at %zd left %d\n", start_code, buf_ptr-buf, input_size);
+ }
+
+ /* prepare data for next start code */
+ switch(start_code) {
+ case SEQ_START_CODE:
+ mpeg1_decode_sequence(avctx, buf_ptr,
+ input_size);
+ break;
+
+ case PICTURE_START_CODE:
+ /* we have a complete image : we try to decompress it */
+ mpeg1_decode_picture(avctx,
+ buf_ptr, input_size);
+ break;
+ case EXT_START_CODE:
+ mpeg_decode_extension(avctx,
+ buf_ptr, input_size);
+ break;
+ case USER_START_CODE:
+ mpeg_decode_user_data(avctx,
+ buf_ptr, input_size);
+ break;
+ case GOP_START_CODE:
+ s2->first_field=0;
+ mpeg_decode_gop(avctx,
+ buf_ptr, input_size);
+ break;
+ default:
+ if (start_code >= SLICE_MIN_START_CODE &&
+ start_code <= SLICE_MAX_START_CODE) {
+ int mb_y= start_code - SLICE_MIN_START_CODE;
+
+ if(s2->last_picture_ptr==NULL){
+ /* skip b frames if we dont have reference frames */
+ if(s2->pict_type==B_TYPE) break;
+ /* skip P frames if we dont have reference frame no valid header */
+// if(s2->pict_type==P_TYPE && s2->first_field && !s2->first_slice) break;
+ }
+ /* skip b frames if we are in a hurry */
+ if(avctx->hurry_up && s2->pict_type==B_TYPE) break;
+ if( (avctx->skip_frame >= AVDISCARD_NONREF && s2->pict_type==B_TYPE)
+ ||(avctx->skip_frame >= AVDISCARD_NONKEY && s2->pict_type!=I_TYPE)
+ || avctx->skip_frame >= AVDISCARD_ALL)
+ break;
+ /* skip everything if we are in a hurry>=5 */
+ if(avctx->hurry_up>=5) break;
+
+ if (!s->mpeg_enc_ctx_allocated) break;
+
+ if(s2->codec_id == CODEC_ID_MPEG2VIDEO){
+ if(mb_y < avctx->skip_top || mb_y >= s2->mb_height - avctx->skip_bottom)
+ break;
+ }
+
+ if(s2->first_slice){
+ s2->first_slice=0;
+ if(mpeg_field_start(s2) < 0)
+ return -1;
+ }
+ if(!s2->current_picture_ptr){
+ av_log(avctx, AV_LOG_ERROR, "current_picture not initalized\n");
+ return -1;
+ }
+
+ if(avctx->thread_count > 1){
+ int threshold= (s2->mb_height*s->slice_count + avctx->thread_count/2) / avctx->thread_count;
+ if(threshold <= mb_y){
+ MpegEncContext *thread_context= s2->thread_context[s->slice_count];
+
+ thread_context->start_mb_y= mb_y;
+ thread_context->end_mb_y = s2->mb_height;
+ if(s->slice_count){
+ s2->thread_context[s->slice_count-1]->end_mb_y= mb_y;
+ ff_update_duplicate_context(thread_context, s2);
+ }
+ init_get_bits(&thread_context->gb, buf_ptr, input_size*8);
+ s->slice_count++;
+ }
+ buf_ptr += 2; //FIXME add minimum num of bytes per slice
+ }else{
+ ret = mpeg_decode_slice(s, mb_y, &buf_ptr, input_size);
+ emms_c();
+
+ if(ret < 0){
+ if(s2->resync_mb_x>=0 && s2->resync_mb_y>=0)
+ ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x, s2->mb_y, AC_ERROR|DC_ERROR|MV_ERROR);
+ }else{
+ ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x-1, s2->mb_y, AC_END|DC_END|MV_END);
+ }
+ }
+ }
+ break;
+ }
+ }
+}
+
+static int mpeg_decode_end(AVCodecContext *avctx)
+{
+ Mpeg1Context *s = avctx->priv_data;
+
+ if (s->mpeg_enc_ctx_allocated)
+ MPV_common_end(&s->mpeg_enc_ctx);
+ return 0;
+}
+
+AVCodec mpeg1video_decoder = {
+ "mpeg1video",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_MPEG1VIDEO,
+ sizeof(Mpeg1Context),
+ mpeg_decode_init,
+ NULL,
+ mpeg_decode_end,
+ mpeg_decode_frame,
+ CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY,
+ .flush= ff_mpeg_flush,
+};
+
+AVCodec mpeg2video_decoder = {
+ "mpeg2video",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_MPEG2VIDEO,
+ sizeof(Mpeg1Context),
+ mpeg_decode_init,
+ NULL,
+ mpeg_decode_end,
+ mpeg_decode_frame,
+ CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY,
+ .flush= ff_mpeg_flush,
+};
+
+//legacy decoder
+AVCodec mpegvideo_decoder = {
+ "mpegvideo",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_MPEG2VIDEO,
+ sizeof(Mpeg1Context),
+ mpeg_decode_init,
+ NULL,
+ mpeg_decode_end,
+ mpeg_decode_frame,
+ CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY,
+ .flush= ff_mpeg_flush,
+};
+
+#ifdef CONFIG_ENCODERS
+
+AVCodec mpeg1video_encoder = {
+ "mpeg1video",
+ CODEC_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, -1},
+ .capabilities= CODEC_CAP_DELAY,
+};
+
+AVCodec mpeg2video_encoder = {
+ "mpeg2video",
+ CODEC_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, -1},
+ .capabilities= CODEC_CAP_DELAY,
+};
+#endif
+
+#ifdef HAVE_XVMC
+static int mpeg_mc_decode_init(AVCodecContext *avctx){
+ Mpeg1Context *s;
+
+ if( avctx->thread_count > 1)
+ return -1;
+ if( !(avctx->slice_flags & SLICE_FLAG_CODED_ORDER) )
+ return -1;
+ if( !(avctx->slice_flags & SLICE_FLAG_ALLOW_FIELD) ){
+ dprintf(avctx, "mpeg12.c: XvMC decoder will work better if SLICE_FLAG_ALLOW_FIELD is set\n");
+ }
+ mpeg_decode_init(avctx);
+ s = avctx->priv_data;
+
+ avctx->pix_fmt = PIX_FMT_XVMC_MPEG2_IDCT;
+ avctx->xvmc_acceleration = 2;//2 - the blocks are packed!
+
+ return 0;
+}
+
+AVCodec mpeg_xvmc_decoder = {
+ "mpegvideo_xvmc",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_MPEG2VIDEO_XVMC,
+ sizeof(Mpeg1Context),
+ mpeg_mc_decode_init,
+ NULL,
+ mpeg_decode_end,
+ mpeg_decode_frame,
+ CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED| CODEC_CAP_HWACCEL | CODEC_CAP_DELAY,
+ .flush= ff_mpeg_flush,
+};
+
+#endif
+
+#ifdef CONFIG_MPEGVIDEO_PARSER
+static void mpegvideo_extract_headers(AVCodecParserContext *s,
+ AVCodecContext *avctx,
+ const uint8_t *buf, int buf_size)
+{
+ ParseContext1 *pc = s->priv_data;
+ const uint8_t *buf_end;
+ 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;
+//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);
+ bytes_left = buf_end - buf;
+ switch(start_code) {
+ case PICTURE_START_CODE:
+ if (bytes_left >= 2) {
+ s->pict_type = (buf[1] >> 3) & 7;
+ }
+ break;
+ case SEQ_START_CODE:
+ 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);
+ 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;
+ avctx->bit_rate = ((buf[4]<<10) | (buf[5]<<2) | (buf[6]>>6))*400;
+ avctx->codec_id = CODEC_ID_MPEG1VIDEO;
+ avctx->sub_id = 1;
+ }
+ break;
+ case EXT_START_CODE:
+ if (bytes_left >= 1) {
+ ext_type = (buf[0] >> 4);
+ switch(ext_type) {
+ case 0x1: /* sequence extension */
+ if (bytes_left >= 6) {
+ horiz_size_ext = ((buf[1] & 1) << 1) | (buf[2] >> 7);
+ vert_size_ext = (buf[2] >> 5) & 3;
+ bit_rate_ext = ((buf[2] & 0x1F)<<7) | (buf[3]>>1);
+ frame_rate_ext_n = (buf[5] >> 5) & 3;
+ frame_rate_ext_d = (buf[5] & 0x1f);
+ pc->progressive_sequence = buf[1] & (1 << 3);
+ avctx->has_b_frames= !(buf[5] >> 7);
+
+ 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);
+ avctx->time_base.den = pc->frame_rate.den * (frame_rate_ext_n + 1);
+ avctx->time_base.num = pc->frame_rate.num * (frame_rate_ext_d + 1);
+ avctx->codec_id = CODEC_ID_MPEG2VIDEO;
+ avctx->sub_id = 2; /* forces MPEG2 */
+ }
+ break;
+ case 0x8: /* picture coding extension */
+ if (bytes_left >= 5) {
+ picture_structure = buf[2]&3;
+ top_field_first = buf[3] & (1 << 7);
+ repeat_first_field = buf[3] & (1 << 1);
+ progressive_frame = buf[4] & (1 << 7);
+
+ /* check if we must repeat the frame */
+ if (repeat_first_field) {
+ if (pc->progressive_sequence) {
+ if (top_field_first)
+ s->repeat_pict = 4;
+ else
+ s->repeat_pict = 2;
+ } else if (progressive_frame) {
+ s->repeat_pict = 1;
+ }
+ }
+
+ /* the packet only represents half a frame
+ XXX,FIXME maybe find a different solution */
+ if(picture_structure != 3)
+ s->repeat_pict = -1;
+ }
+ break;
+ }
+ }
+ break;
+ case -1:
+ goto the_end;
+ default:
+ /* we stop parsing when we encounter a slice. It ensures
+ that this function takes a negligible amount of time */
+ if (start_code >= SLICE_MIN_START_CODE &&
+ start_code <= SLICE_MAX_START_CODE)
+ goto the_end;
+ break;
+ }
+ }
+ the_end: ;
+}
+
+static int mpegvideo_parse(AVCodecParserContext *s,
+ AVCodecContext *avctx,
+ uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size)
+{
+ ParseContext1 *pc1 = s->priv_data;
+ ParseContext *pc= &pc1->pc;
+ int next;
+
+ if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){
+ next= buf_size;
+ }else{
+ next= mpeg1_find_frame_end(pc, buf, buf_size);
+
+ if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
+ *poutbuf = NULL;
+ *poutbuf_size = 0;
+ return buf_size;
+ }
+
+ }
+ /* we have a full frame : we just parse the first few MPEG headers
+ to have the full timing information. The time take by this
+ function should be negligible for uncorrupted streams */
+ mpegvideo_extract_headers(s, avctx, buf, buf_size);
+#if 0
+ printf("pict_type=%d frame_rate=%0.3f repeat_pict=%d\n",
+ s->pict_type, (double)avctx->time_base.den / avctx->time_base.num, s->repeat_pict);
+#endif
+
+ *poutbuf = (uint8_t *)buf;
+ *poutbuf_size = buf_size;
+ return next;
+}
+
+static int mpegvideo_split(AVCodecContext *avctx,
+ const uint8_t *buf, int buf_size)
+{
+ int i;
+ uint32_t state= -1;
+
+ for(i=0; i<buf_size; i++){
+ state= (state<<8) | buf[i];
+ if(state != 0x1B3 && state != 0x1B5 && state < 0x200 && state >= 0x100)
+ return i-3;
+ }
+ return 0;
+}
+
+AVCodecParser mpegvideo_parser = {
+ { CODEC_ID_MPEG1VIDEO, CODEC_ID_MPEG2VIDEO },
+ sizeof(ParseContext1),
+ NULL,
+ mpegvideo_parse,
+ ff_parse1_close,
+ mpegvideo_split,
+};
+#endif /* !CONFIG_MPEGVIDEO_PARSER */
+
+static int imx_dump_header(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
+ uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size, int keyframe)
+{
+ /* MXF essence element key */
+ static const uint8_t imx_header[16] = { 0x06,0x0e,0x2b,0x34,0x01,0x02,0x01,0x01,0x0d,0x01,0x03,0x01,0x05,0x01,0x01,0x00 };
+ uint8_t *poutbufp;
+
+ if (avctx->codec_id != CODEC_ID_MPEG2VIDEO) {
+ av_log(avctx, AV_LOG_ERROR, "imx bitstream filter only applies to mpeg2video codec\n");
+ return 0;
+ }
+
+ *poutbuf = av_malloc(buf_size + 20 + FF_INPUT_BUFFER_PADDING_SIZE);
+ poutbufp = *poutbuf;
+ bytestream_put_buffer(&poutbufp, imx_header, 16);
+ bytestream_put_byte(&poutbufp, 0x83); /* KLV BER long form */
+ bytestream_put_be24(&poutbufp, buf_size);
+ bytestream_put_buffer(&poutbufp, buf, buf_size);
+ *poutbuf_size = poutbufp - *poutbuf;
+ return 1;
+}
+
+AVBitStreamFilter imx_dump_header_bsf = {
+ "imxdump",
+ 0,
+ imx_dump_header,
+};
+
+/* this is ugly i know, but the alternative is too make
+ hundreds of vars global and prefix them with ff_mpeg1_
+ which is far uglier. */
+#include "mdec.c"
diff --git a/contrib/ffmpeg/libavcodec/mpeg12data.h b/contrib/ffmpeg/libavcodec/mpeg12data.h
new file mode 100644
index 000000000..1176a75fa
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/mpeg12data.h
@@ -0,0 +1,474 @@
+/*
+ * MPEG1 codec / MPEG2 decoder
+ * copyright (c) 2000,2001 Fabrice Bellard
+ * copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file mpeg12data.h
+ * MPEG1/2 tables.
+ */
+
+const uint16_t ff_mpeg1_default_intra_matrix[64] = {
+ 8, 16, 19, 22, 26, 27, 29, 34,
+ 16, 16, 22, 24, 27, 29, 34, 37,
+ 19, 22, 26, 27, 29, 34, 34, 38,
+ 22, 22, 26, 27, 29, 34, 37, 40,
+ 22, 26, 27, 29, 32, 35, 40, 48,
+ 26, 27, 29, 32, 35, 40, 48, 58,
+ 26, 27, 29, 34, 38, 46, 56, 69,
+ 27, 29, 35, 38, 46, 56, 69, 83
+};
+
+const uint16_t ff_mpeg1_default_non_intra_matrix[64] = {
+ 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16,
+};
+
+static const uint16_t vlc_dc_lum_code[12] = {
+ 0x4, 0x0, 0x1, 0x5, 0x6, 0xe, 0x1e, 0x3e, 0x7e, 0xfe, 0x1fe, 0x1ff,
+};
+static const unsigned char vlc_dc_lum_bits[12] = {
+ 3, 2, 2, 3, 3, 4, 5, 6, 7, 8, 9, 9,
+};
+
+static const uint16_t vlc_dc_chroma_code[12] = {
+ 0x0, 0x1, 0x2, 0x6, 0xe, 0x1e, 0x3e, 0x7e, 0xfe, 0x1fe, 0x3fe, 0x3ff,
+};
+static const unsigned char vlc_dc_chroma_bits[12] = {
+ 2, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10,
+};
+
+static const uint16_t mpeg1_vlc[113][2] = {
+ { 0x3, 2 }, { 0x4, 4 }, { 0x5, 5 }, { 0x6, 7 },
+ { 0x26, 8 }, { 0x21, 8 }, { 0xa, 10 }, { 0x1d, 12 },
+ { 0x18, 12 }, { 0x13, 12 }, { 0x10, 12 }, { 0x1a, 13 },
+ { 0x19, 13 }, { 0x18, 13 }, { 0x17, 13 }, { 0x1f, 14 },
+ { 0x1e, 14 }, { 0x1d, 14 }, { 0x1c, 14 }, { 0x1b, 14 },
+ { 0x1a, 14 }, { 0x19, 14 }, { 0x18, 14 }, { 0x17, 14 },
+ { 0x16, 14 }, { 0x15, 14 }, { 0x14, 14 }, { 0x13, 14 },
+ { 0x12, 14 }, { 0x11, 14 }, { 0x10, 14 }, { 0x18, 15 },
+ { 0x17, 15 }, { 0x16, 15 }, { 0x15, 15 }, { 0x14, 15 },
+ { 0x13, 15 }, { 0x12, 15 }, { 0x11, 15 }, { 0x10, 15 },
+ { 0x3, 3 }, { 0x6, 6 }, { 0x25, 8 }, { 0xc, 10 },
+ { 0x1b, 12 }, { 0x16, 13 }, { 0x15, 13 }, { 0x1f, 15 },
+ { 0x1e, 15 }, { 0x1d, 15 }, { 0x1c, 15 }, { 0x1b, 15 },
+ { 0x1a, 15 }, { 0x19, 15 }, { 0x13, 16 }, { 0x12, 16 },
+ { 0x11, 16 }, { 0x10, 16 }, { 0x5, 4 }, { 0x4, 7 },
+ { 0xb, 10 }, { 0x14, 12 }, { 0x14, 13 }, { 0x7, 5 },
+ { 0x24, 8 }, { 0x1c, 12 }, { 0x13, 13 }, { 0x6, 5 },
+ { 0xf, 10 }, { 0x12, 12 }, { 0x7, 6 }, { 0x9, 10 },
+ { 0x12, 13 }, { 0x5, 6 }, { 0x1e, 12 }, { 0x14, 16 },
+ { 0x4, 6 }, { 0x15, 12 }, { 0x7, 7 }, { 0x11, 12 },
+ { 0x5, 7 }, { 0x11, 13 }, { 0x27, 8 }, { 0x10, 13 },
+ { 0x23, 8 }, { 0x1a, 16 }, { 0x22, 8 }, { 0x19, 16 },
+ { 0x20, 8 }, { 0x18, 16 }, { 0xe, 10 }, { 0x17, 16 },
+ { 0xd, 10 }, { 0x16, 16 }, { 0x8, 10 }, { 0x15, 16 },
+ { 0x1f, 12 }, { 0x1a, 12 }, { 0x19, 12 }, { 0x17, 12 },
+ { 0x16, 12 }, { 0x1f, 13 }, { 0x1e, 13 }, { 0x1d, 13 },
+ { 0x1c, 13 }, { 0x1b, 13 }, { 0x1f, 16 }, { 0x1e, 16 },
+ { 0x1d, 16 }, { 0x1c, 16 }, { 0x1b, 16 },
+ { 0x1, 6 }, /* escape */
+ { 0x2, 2 }, /* EOB */
+};
+
+static const uint16_t mpeg2_vlc[113][2] = {
+ {0x02, 2}, {0x06, 3}, {0x07, 4}, {0x1c, 5},
+ {0x1d, 5}, {0x05, 6}, {0x04, 6}, {0x7b, 7},
+ {0x7c, 7}, {0x23, 8}, {0x22, 8}, {0xfa, 8},
+ {0xfb, 8}, {0xfe, 8}, {0xff, 8}, {0x1f,14},
+ {0x1e,14}, {0x1d,14}, {0x1c,14}, {0x1b,14},
+ {0x1a,14}, {0x19,14}, {0x18,14}, {0x17,14},
+ {0x16,14}, {0x15,14}, {0x14,14}, {0x13,14},
+ {0x12,14}, {0x11,14}, {0x10,14}, {0x18,15},
+ {0x17,15}, {0x16,15}, {0x15,15}, {0x14,15},
+ {0x13,15}, {0x12,15}, {0x11,15}, {0x10,15},
+ {0x02, 3}, {0x06, 5}, {0x79, 7}, {0x27, 8},
+ {0x20, 8}, {0x16,13}, {0x15,13}, {0x1f,15},
+ {0x1e,15}, {0x1d,15}, {0x1c,15}, {0x1b,15},
+ {0x1a,15}, {0x19,15}, {0x13,16}, {0x12,16},
+ {0x11,16}, {0x10,16}, {0x05, 5}, {0x07, 7},
+ {0xfc, 8}, {0x0c,10}, {0x14,13}, {0x07, 5},
+ {0x26, 8}, {0x1c,12}, {0x13,13}, {0x06, 6},
+ {0xfd, 8}, {0x12,12}, {0x07, 6}, {0x04, 9},
+ {0x12,13}, {0x06, 7}, {0x1e,12}, {0x14,16},
+ {0x04, 7}, {0x15,12}, {0x05, 7}, {0x11,12},
+ {0x78, 7}, {0x11,13}, {0x7a, 7}, {0x10,13},
+ {0x21, 8}, {0x1a,16}, {0x25, 8}, {0x19,16},
+ {0x24, 8}, {0x18,16}, {0x05, 9}, {0x17,16},
+ {0x07, 9}, {0x16,16}, {0x0d,10}, {0x15,16},
+ {0x1f,12}, {0x1a,12}, {0x19,12}, {0x17,12},
+ {0x16,12}, {0x1f,13}, {0x1e,13}, {0x1d,13},
+ {0x1c,13}, {0x1b,13}, {0x1f,16}, {0x1e,16},
+ {0x1d,16}, {0x1c,16}, {0x1b,16},
+ {0x01,6}, /* escape */
+ {0x06,4}, /* EOB */
+};
+
+static const int8_t mpeg1_level[111] = {
+ 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,
+ 1, 2, 3, 4, 5, 6, 7, 8,
+ 9, 10, 11, 12, 13, 14, 15, 16,
+ 17, 18, 1, 2, 3, 4, 5, 1,
+ 2, 3, 4, 1, 2, 3, 1, 2,
+ 3, 1, 2, 3, 1, 2, 1, 2,
+ 1, 2, 1, 2, 1, 2, 1, 2,
+ 1, 2, 1, 2, 1, 2, 1, 2,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1,
+};
+
+static const int8_t mpeg1_run[111] = {
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 2, 2, 2, 2, 2, 3,
+ 3, 3, 3, 4, 4, 4, 5, 5,
+ 5, 6, 6, 6, 7, 7, 8, 8,
+ 9, 9, 10, 10, 11, 11, 12, 12,
+ 13, 13, 14, 14, 15, 15, 16, 16,
+ 17, 18, 19, 20, 21, 22, 23, 24,
+ 25, 26, 27, 28, 29, 30, 31,
+};
+
+static RLTable rl_mpeg1 = {
+ 111,
+ 111,
+ mpeg1_vlc,
+ mpeg1_run,
+ mpeg1_level,
+};
+
+static RLTable rl_mpeg2 = {
+ 111,
+ 111,
+ mpeg2_vlc,
+ mpeg1_run,
+ mpeg1_level,
+};
+
+static const uint8_t mbAddrIncrTable[36][2] = {
+ {0x1, 1},
+ {0x3, 3},
+ {0x2, 3},
+ {0x3, 4},
+ {0x2, 4},
+ {0x3, 5},
+ {0x2, 5},
+ {0x7, 7},
+ {0x6, 7},
+ {0xb, 8},
+ {0xa, 8},
+ {0x9, 8},
+ {0x8, 8},
+ {0x7, 8},
+ {0x6, 8},
+ {0x17, 10},
+ {0x16, 10},
+ {0x15, 10},
+ {0x14, 10},
+ {0x13, 10},
+ {0x12, 10},
+ {0x23, 11},
+ {0x22, 11},
+ {0x21, 11},
+ {0x20, 11},
+ {0x1f, 11},
+ {0x1e, 11},
+ {0x1d, 11},
+ {0x1c, 11},
+ {0x1b, 11},
+ {0x1a, 11},
+ {0x19, 11},
+ {0x18, 11},
+ {0x8, 11}, /* escape */
+ {0xf, 11}, /* stuffing */
+ {0x0, 8}, /* end (and 15 more 0 bits should follow) */
+};
+
+static const uint8_t mbPatTable[64][2] = {
+ {0x1, 9},
+ {0xb, 5},
+ {0x9, 5},
+ {0xd, 6},
+ {0xd, 4},
+ {0x17, 7},
+ {0x13, 7},
+ {0x1f, 8},
+ {0xc, 4},
+ {0x16, 7},
+ {0x12, 7},
+ {0x1e, 8},
+ {0x13, 5},
+ {0x1b, 8},
+ {0x17, 8},
+ {0x13, 8},
+ {0xb, 4},
+ {0x15, 7},
+ {0x11, 7},
+ {0x1d, 8},
+ {0x11, 5},
+ {0x19, 8},
+ {0x15, 8},
+ {0x11, 8},
+ {0xf, 6},
+ {0xf, 8},
+ {0xd, 8},
+ {0x3, 9},
+ {0xf, 5},
+ {0xb, 8},
+ {0x7, 8},
+ {0x7, 9},
+ {0xa, 4},
+ {0x14, 7},
+ {0x10, 7},
+ {0x1c, 8},
+ {0xe, 6},
+ {0xe, 8},
+ {0xc, 8},
+ {0x2, 9},
+ {0x10, 5},
+ {0x18, 8},
+ {0x14, 8},
+ {0x10, 8},
+ {0xe, 5},
+ {0xa, 8},
+ {0x6, 8},
+ {0x6, 9},
+ {0x12, 5},
+ {0x1a, 8},
+ {0x16, 8},
+ {0x12, 8},
+ {0xd, 5},
+ {0x9, 8},
+ {0x5, 8},
+ {0x5, 9},
+ {0xc, 5},
+ {0x8, 8},
+ {0x4, 8},
+ {0x4, 9},
+ {0x7, 3},
+ {0xa, 5},
+ {0x8, 5},
+ {0xc, 6}
+};
+
+#define MB_TYPE_ZERO_MV 0x20000000
+#define IS_ZERO_MV(a) ((a)&MB_TYPE_ZERO_MV)
+
+static const uint8_t table_mb_ptype[7][2] = {
+ { 3, 5 }, // 0x01 MB_INTRA
+ { 1, 2 }, // 0x02 MB_PAT
+ { 1, 3 }, // 0x08 MB_FOR
+ { 1, 1 }, // 0x0A MB_FOR|MB_PAT
+ { 1, 6 }, // 0x11 MB_QUANT|MB_INTRA
+ { 1, 5 }, // 0x12 MB_QUANT|MB_PAT
+ { 2, 5 }, // 0x1A MB_QUANT|MB_FOR|MB_PAT
+};
+
+static const uint32_t ptype2mb_type[7] = {
+ MB_TYPE_INTRA,
+ MB_TYPE_L0 | MB_TYPE_CBP | MB_TYPE_ZERO_MV | MB_TYPE_16x16,
+ MB_TYPE_L0,
+ MB_TYPE_L0 | MB_TYPE_CBP,
+ MB_TYPE_QUANT | MB_TYPE_INTRA,
+ MB_TYPE_QUANT | MB_TYPE_L0 | MB_TYPE_CBP | MB_TYPE_ZERO_MV | MB_TYPE_16x16,
+ MB_TYPE_QUANT | MB_TYPE_L0 | MB_TYPE_CBP,
+};
+
+static const uint8_t table_mb_btype[11][2] = {
+ { 3, 5 }, // 0x01 MB_INTRA
+ { 2, 3 }, // 0x04 MB_BACK
+ { 3, 3 }, // 0x06 MB_BACK|MB_PAT
+ { 2, 4 }, // 0x08 MB_FOR
+ { 3, 4 }, // 0x0A MB_FOR|MB_PAT
+ { 2, 2 }, // 0x0C MB_FOR|MB_BACK
+ { 3, 2 }, // 0x0E MB_FOR|MB_BACK|MB_PAT
+ { 1, 6 }, // 0x11 MB_QUANT|MB_INTRA
+ { 2, 6 }, // 0x16 MB_QUANT|MB_BACK|MB_PAT
+ { 3, 6 }, // 0x1A MB_QUANT|MB_FOR|MB_PAT
+ { 2, 5 }, // 0x1E MB_QUANT|MB_FOR|MB_BACK|MB_PAT
+};
+
+static const uint32_t btype2mb_type[11] = {
+ MB_TYPE_INTRA,
+ MB_TYPE_L1,
+ MB_TYPE_L1 | MB_TYPE_CBP,
+ MB_TYPE_L0,
+ MB_TYPE_L0 | MB_TYPE_CBP,
+ MB_TYPE_L0L1,
+ MB_TYPE_L0L1 | MB_TYPE_CBP,
+ MB_TYPE_QUANT | MB_TYPE_INTRA,
+ MB_TYPE_QUANT | MB_TYPE_L1 | MB_TYPE_CBP,
+ MB_TYPE_QUANT | MB_TYPE_L0 | MB_TYPE_CBP,
+ MB_TYPE_QUANT | MB_TYPE_L0L1 | MB_TYPE_CBP,
+};
+
+static const uint8_t mbMotionVectorTable[17][2] = {
+{ 0x1, 1 },
+{ 0x1, 2 },
+{ 0x1, 3 },
+{ 0x1, 4 },
+{ 0x3, 6 },
+{ 0x5, 7 },
+{ 0x4, 7 },
+{ 0x3, 7 },
+{ 0xb, 9 },
+{ 0xa, 9 },
+{ 0x9, 9 },
+{ 0x11, 10 },
+{ 0x10, 10 },
+{ 0xf, 10 },
+{ 0xe, 10 },
+{ 0xd, 10 },
+{ 0xc, 10 },
+};
+
+const AVRational ff_frame_rate_tab[] = {
+ { 0, 0},
+ {24000, 1001},
+ { 24, 1},
+ { 25, 1},
+ {30000, 1001},
+ { 30, 1},
+ { 50, 1},
+ {60000, 1001},
+ { 60, 1},
+ // Xing's 15fps: (9)
+ { 15, 1},
+ // libmpeg3's "Unofficial economy rates": (10-13)
+ { 5, 1},
+ { 10, 1},
+ { 12, 1},
+ { 15, 1},
+ { 0, 0},
+};
+
+static const uint8_t non_linear_qscale[32] = {
+ 0, 1, 2, 3, 4, 5, 6, 7,
+ 8,10,12,14,16,18,20,22,
+ 24,28,32,36,40,44,48,52,
+ 56,64,72,80,88,96,104,112,
+};
+
+static const uint8_t inv_non_linear_qscale[13] = {
+ 0, 2, 4, 6, 8,
+ 9,10,11,12,13,14,15,16,
+};
+
+const uint8_t ff_mpeg1_dc_scale_table[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
+ 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,
+ 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,
+ 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,
+ 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,
+};
+
+static const uint8_t *mpeg2_dc_scale_table[4]={
+ ff_mpeg1_dc_scale_table,
+ mpeg2_dc_scale_table1,
+ mpeg2_dc_scale_table2,
+ mpeg2_dc_scale_table3,
+};
+
+static const float mpeg1_aspect[16]={
+ 0.0000,
+ 1.0000,
+ 0.6735,
+ 0.7031,
+
+ 0.7615,
+ 0.8055,
+ 0.8437,
+ 0.8935,
+
+ 0.9157,
+ 0.9815,
+ 1.0255,
+ 1.0695,
+
+ 1.0950,
+ 1.1575,
+ 1.2015,
+};
+
+static const AVRational mpeg2_aspect[16]={
+ {0,1},
+ {1,1},
+ {4,3},
+ {16,9},
+ {221,100},
+ {0,1},
+ {0,1},
+ {0,1},
+ {0,1},
+ {0,1},
+ {0,1},
+ {0,1},
+ {0,1},
+ {0,1},
+ {0,1},
+ {0,1},
+};
+
+static const uint8_t svcd_scan_offset_placeholder[14]={
+ 0x10, 0x0E,
+ 0x00, 0x80, 0x81,
+ 0x00, 0x80, 0x81,
+ 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff,
+};
diff --git a/src/libffmpeg/libavcodec/mpeg4data.h b/contrib/ffmpeg/libavcodec/mpeg4data.h
index e199c6a14..e199c6a14 100644
--- a/src/libffmpeg/libavcodec/mpeg4data.h
+++ b/contrib/ffmpeg/libavcodec/mpeg4data.h
diff --git a/contrib/ffmpeg/libavcodec/mpegaudio.c b/contrib/ffmpeg/libavcodec/mpegaudio.c
new file mode 100644
index 000000000..aa93442d5
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/mpegaudio.c
@@ -0,0 +1,799 @@
+/*
+ * The simplest mpeg audio layer 2 encoder
+ * Copyright (c) 2000, 2001 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 mpegaudio.c
+ * The simplest mpeg audio layer 2 encoder.
+ */
+
+#include "avcodec.h"
+#include "bitstream.h"
+#include "mpegaudio.h"
+
+/* currently, cannot change these constants (need to modify
+ quantization stage) */
+#define MUL(a,b) (((int64_t)(a) * (int64_t)(b)) >> FRAC_BITS)
+#define FIX(a) ((int)((a) * (1 << FRAC_BITS)))
+
+#define SAMPLES_BUF_SIZE 4096
+
+typedef struct MpegAudioContext {
+ PutBitContext pb;
+ int nb_channels;
+ int freq, bit_rate;
+ int lsf; /* 1 if mpeg2 low bitrate selected */
+ int bitrate_index; /* bit rate */
+ int freq_index;
+ int frame_size; /* frame size, in bits, without padding */
+ int64_t nb_samples; /* total number of samples encoded */
+ /* padding computation */
+ int frame_frac, frame_frac_incr, do_padding;
+ short samples_buf[MPA_MAX_CHANNELS][SAMPLES_BUF_SIZE]; /* buffer for filter */
+ int samples_offset[MPA_MAX_CHANNELS]; /* offset in samples_buf */
+ int sb_samples[MPA_MAX_CHANNELS][3][12][SBLIMIT];
+ unsigned char scale_factors[MPA_MAX_CHANNELS][SBLIMIT][3]; /* scale factors */
+ /* code to group 3 scale factors */
+ unsigned char scale_code[MPA_MAX_CHANNELS][SBLIMIT];
+ int sblimit; /* number of used subbands */
+ const unsigned char *alloc_table;
+} MpegAudioContext;
+
+/* define it to use floats in quantization (I don't like floats !) */
+//#define USE_FLOATS
+
+#include "mpegaudiotab.h"
+
+static int MPA_encode_init(AVCodecContext *avctx)
+{
+ MpegAudioContext *s = avctx->priv_data;
+ int freq = avctx->sample_rate;
+ int bitrate = avctx->bit_rate;
+ int channels = avctx->channels;
+ int i, v, table;
+ float a;
+
+ if (channels > 2)
+ return -1;
+ bitrate = bitrate / 1000;
+ s->nb_channels = channels;
+ s->freq = freq;
+ s->bit_rate = bitrate * 1000;
+ avctx->frame_size = MPA_FRAME_SIZE;
+
+ /* encoding freq */
+ s->lsf = 0;
+ for(i=0;i<3;i++) {
+ if (mpa_freq_tab[i] == freq)
+ break;
+ if ((mpa_freq_tab[i] / 2) == freq) {
+ s->lsf = 1;
+ break;
+ }
+ }
+ if (i == 3){
+ av_log(avctx, AV_LOG_ERROR, "Sampling rate %d is not allowed in mp2\n", freq);
+ return -1;
+ }
+ s->freq_index = i;
+
+ /* encoding bitrate & frequency */
+ for(i=0;i<15;i++) {
+ if (mpa_bitrate_tab[s->lsf][1][i] == bitrate)
+ break;
+ }
+ if (i == 15){
+ av_log(avctx, AV_LOG_ERROR, "bitrate %d is not allowed in mp2\n", bitrate);
+ return -1;
+ }
+ s->bitrate_index = i;
+
+ /* compute total header size & pad bit */
+
+ a = (float)(bitrate * 1000 * MPA_FRAME_SIZE) / (freq * 8.0);
+ s->frame_size = ((int)a) * 8;
+
+ /* frame fractional size to compute padding */
+ s->frame_frac = 0;
+ s->frame_frac_incr = (int)((a - floor(a)) * 65536.0);
+
+ /* select the right allocation table */
+ table = l2_select_table(bitrate, s->nb_channels, freq, s->lsf);
+
+ /* number of used subbands */
+ s->sblimit = sblimit_table[table];
+ s->alloc_table = alloc_tables[table];
+
+#ifdef DEBUG
+ av_log(avctx, AV_LOG_DEBUG, "%d kb/s, %d Hz, frame_size=%d bits, table=%d, padincr=%x\n",
+ bitrate, freq, s->frame_size, table, s->frame_frac_incr);
+#endif
+
+ for(i=0;i<s->nb_channels;i++)
+ s->samples_offset[i] = 0;
+
+ for(i=0;i<257;i++) {
+ int v;
+ v = mpa_enwindow[i];
+#if WFRAC_BITS != 16
+ v = (v + (1 << (16 - WFRAC_BITS - 1))) >> (16 - WFRAC_BITS);
+#endif
+ filter_bank[i] = v;
+ if ((i & 63) != 0)
+ v = -v;
+ if (i != 0)
+ filter_bank[512 - i] = v;
+ }
+
+ for(i=0;i<64;i++) {
+ v = (int)(pow(2.0, (3 - i) / 3.0) * (1 << 20));
+ if (v <= 0)
+ v = 1;
+ scale_factor_table[i] = v;
+#ifdef USE_FLOATS
+ scale_factor_inv_table[i] = pow(2.0, -(3 - i) / 3.0) / (float)(1 << 20);
+#else
+#define P 15
+ scale_factor_shift[i] = 21 - P - (i / 3);
+ scale_factor_mult[i] = (1 << P) * pow(2.0, (i % 3) / 3.0);
+#endif
+ }
+ for(i=0;i<128;i++) {
+ v = i - 64;
+ if (v <= -3)
+ v = 0;
+ else if (v < 0)
+ v = 1;
+ else if (v == 0)
+ v = 2;
+ else if (v < 3)
+ v = 3;
+ else
+ v = 4;
+ scale_diff_table[i] = v;
+ }
+
+ for(i=0;i<17;i++) {
+ v = quant_bits[i];
+ if (v < 0)
+ v = -v;
+ else
+ v = v * 3;
+ total_quant_bits[i] = 12 * v;
+ }
+
+ avctx->coded_frame= avcodec_alloc_frame();
+ avctx->coded_frame->key_frame= 1;
+
+ return 0;
+}
+
+/* 32 point floating point IDCT without 1/sqrt(2) coef zero scaling */
+static void idct32(int *out, int *tab)
+{
+ int i, j;
+ int *t, *t1, xr;
+ const int *xp = costab32;
+
+ for(j=31;j>=3;j-=2) tab[j] += tab[j - 2];
+
+ t = tab + 30;
+ t1 = tab + 2;
+ do {
+ t[0] += t[-4];
+ t[1] += t[1 - 4];
+ t -= 4;
+ } while (t != t1);
+
+ t = tab + 28;
+ t1 = tab + 4;
+ do {
+ t[0] += t[-8];
+ t[1] += t[1-8];
+ t[2] += t[2-8];
+ t[3] += t[3-8];
+ t -= 8;
+ } while (t != t1);
+
+ t = tab;
+ t1 = tab + 32;
+ do {
+ t[ 3] = -t[ 3];
+ t[ 6] = -t[ 6];
+
+ t[11] = -t[11];
+ t[12] = -t[12];
+ t[13] = -t[13];
+ t[15] = -t[15];
+ t += 16;
+ } while (t != t1);
+
+
+ t = tab;
+ t1 = tab + 8;
+ do {
+ int x1, x2, x3, x4;
+
+ x3 = MUL(t[16], FIX(SQRT2*0.5));
+ x4 = t[0] - x3;
+ x3 = t[0] + x3;
+
+ x2 = MUL(-(t[24] + t[8]), FIX(SQRT2*0.5));
+ x1 = MUL((t[8] - x2), xp[0]);
+ x2 = MUL((t[8] + x2), xp[1]);
+
+ t[ 0] = x3 + x1;
+ t[ 8] = x4 - x2;
+ t[16] = x4 + x2;
+ t[24] = x3 - x1;
+ t++;
+ } while (t != t1);
+
+ xp += 2;
+ t = tab;
+ t1 = tab + 4;
+ do {
+ xr = MUL(t[28],xp[0]);
+ t[28] = (t[0] - xr);
+ t[0] = (t[0] + xr);
+
+ xr = MUL(t[4],xp[1]);
+ t[ 4] = (t[24] - xr);
+ t[24] = (t[24] + xr);
+
+ xr = MUL(t[20],xp[2]);
+ t[20] = (t[8] - xr);
+ t[ 8] = (t[8] + xr);
+
+ xr = MUL(t[12],xp[3]);
+ t[12] = (t[16] - xr);
+ t[16] = (t[16] + xr);
+ t++;
+ } while (t != t1);
+ xp += 4;
+
+ for (i = 0; i < 4; i++) {
+ xr = MUL(tab[30-i*4],xp[0]);
+ tab[30-i*4] = (tab[i*4] - xr);
+ tab[ i*4] = (tab[i*4] + xr);
+
+ xr = MUL(tab[ 2+i*4],xp[1]);
+ tab[ 2+i*4] = (tab[28-i*4] - xr);
+ tab[28-i*4] = (tab[28-i*4] + xr);
+
+ xr = MUL(tab[31-i*4],xp[0]);
+ tab[31-i*4] = (tab[1+i*4] - xr);
+ tab[ 1+i*4] = (tab[1+i*4] + xr);
+
+ xr = MUL(tab[ 3+i*4],xp[1]);
+ tab[ 3+i*4] = (tab[29-i*4] - xr);
+ tab[29-i*4] = (tab[29-i*4] + xr);
+
+ xp += 2;
+ }
+
+ t = tab + 30;
+ t1 = tab + 1;
+ do {
+ xr = MUL(t1[0], *xp);
+ t1[0] = (t[0] - xr);
+ t[0] = (t[0] + xr);
+ t -= 2;
+ t1 += 2;
+ xp++;
+ } while (t >= tab);
+
+ for(i=0;i<32;i++) {
+ out[i] = tab[bitinv32[i]];
+ }
+}
+
+#define WSHIFT (WFRAC_BITS + 15 - FRAC_BITS)
+
+static void filter(MpegAudioContext *s, int ch, short *samples, int incr)
+{
+ short *p, *q;
+ int sum, offset, i, j;
+ int tmp[64];
+ int tmp1[32];
+ int *out;
+
+ // print_pow1(samples, 1152);
+
+ offset = s->samples_offset[ch];
+ out = &s->sb_samples[ch][0][0][0];
+ for(j=0;j<36;j++) {
+ /* 32 samples at once */
+ for(i=0;i<32;i++) {
+ s->samples_buf[ch][offset + (31 - i)] = samples[0];
+ samples += incr;
+ }
+
+ /* filter */
+ p = s->samples_buf[ch] + offset;
+ q = filter_bank;
+ /* maxsum = 23169 */
+ for(i=0;i<64;i++) {
+ sum = p[0*64] * q[0*64];
+ sum += p[1*64] * q[1*64];
+ sum += p[2*64] * q[2*64];
+ sum += p[3*64] * q[3*64];
+ sum += p[4*64] * q[4*64];
+ sum += p[5*64] * q[5*64];
+ sum += p[6*64] * q[6*64];
+ sum += p[7*64] * q[7*64];
+ tmp[i] = sum;
+ p++;
+ q++;
+ }
+ tmp1[0] = tmp[16] >> WSHIFT;
+ for( i=1; i<=16; i++ ) tmp1[i] = (tmp[i+16]+tmp[16-i]) >> WSHIFT;
+ for( i=17; i<=31; i++ ) tmp1[i] = (tmp[i+16]-tmp[80-i]) >> WSHIFT;
+
+ idct32(out, tmp1);
+
+ /* advance of 32 samples */
+ offset -= 32;
+ out += 32;
+ /* handle the wrap around */
+ if (offset < 0) {
+ memmove(s->samples_buf[ch] + SAMPLES_BUF_SIZE - (512 - 32),
+ s->samples_buf[ch], (512 - 32) * 2);
+ offset = SAMPLES_BUF_SIZE - 512;
+ }
+ }
+ s->samples_offset[ch] = offset;
+
+ // print_pow(s->sb_samples, 1152);
+}
+
+static void compute_scale_factors(unsigned char scale_code[SBLIMIT],
+ unsigned char scale_factors[SBLIMIT][3],
+ int sb_samples[3][12][SBLIMIT],
+ int sblimit)
+{
+ int *p, vmax, v, n, i, j, k, code;
+ int index, d1, d2;
+ unsigned char *sf = &scale_factors[0][0];
+
+ for(j=0;j<sblimit;j++) {
+ for(i=0;i<3;i++) {
+ /* find the max absolute value */
+ p = &sb_samples[i][0][j];
+ vmax = abs(*p);
+ for(k=1;k<12;k++) {
+ p += SBLIMIT;
+ v = abs(*p);
+ if (v > vmax)
+ vmax = v;
+ }
+ /* compute the scale factor index using log 2 computations */
+ if (vmax > 0) {
+ n = av_log2(vmax);
+ /* n is the position of the MSB of vmax. now
+ use at most 2 compares to find the index */
+ index = (21 - n) * 3 - 3;
+ if (index >= 0) {
+ while (vmax <= scale_factor_table[index+1])
+ index++;
+ } else {
+ index = 0; /* very unlikely case of overflow */
+ }
+ } else {
+ index = 62; /* value 63 is not allowed */
+ }
+
+#if 0
+ printf("%2d:%d in=%x %x %d\n",
+ j, i, vmax, scale_factor_table[index], index);
+#endif
+ /* store the scale factor */
+ assert(index >=0 && index <= 63);
+ sf[i] = index;
+ }
+
+ /* compute the transmission factor : look if the scale factors
+ are close enough to each other */
+ d1 = scale_diff_table[sf[0] - sf[1] + 64];
+ d2 = scale_diff_table[sf[1] - sf[2] + 64];
+
+ /* handle the 25 cases */
+ switch(d1 * 5 + d2) {
+ case 0*5+0:
+ case 0*5+4:
+ case 3*5+4:
+ case 4*5+0:
+ case 4*5+4:
+ code = 0;
+ break;
+ case 0*5+1:
+ case 0*5+2:
+ case 4*5+1:
+ case 4*5+2:
+ code = 3;
+ sf[2] = sf[1];
+ break;
+ case 0*5+3:
+ case 4*5+3:
+ code = 3;
+ sf[1] = sf[2];
+ break;
+ case 1*5+0:
+ case 1*5+4:
+ case 2*5+4:
+ code = 1;
+ sf[1] = sf[0];
+ break;
+ case 1*5+1:
+ case 1*5+2:
+ case 2*5+0:
+ case 2*5+1:
+ case 2*5+2:
+ code = 2;
+ sf[1] = sf[2] = sf[0];
+ break;
+ case 2*5+3:
+ case 3*5+3:
+ code = 2;
+ sf[0] = sf[1] = sf[2];
+ break;
+ case 3*5+0:
+ case 3*5+1:
+ case 3*5+2:
+ code = 2;
+ sf[0] = sf[2] = sf[1];
+ break;
+ case 1*5+3:
+ code = 2;
+ if (sf[0] > sf[2])
+ sf[0] = sf[2];
+ sf[1] = sf[2] = sf[0];
+ break;
+ default:
+ assert(0); //cant happen
+ code = 0; /* kill warning */
+ }
+
+#if 0
+ printf("%d: %2d %2d %2d %d %d -> %d\n", j,
+ sf[0], sf[1], sf[2], d1, d2, code);
+#endif
+ scale_code[j] = code;
+ sf += 3;
+ }
+}
+
+/* The most important function : psycho acoustic module. In this
+ encoder there is basically none, so this is the worst you can do,
+ but also this is the simpler. */
+static void psycho_acoustic_model(MpegAudioContext *s, short smr[SBLIMIT])
+{
+ int i;
+
+ for(i=0;i<s->sblimit;i++) {
+ smr[i] = (int)(fixed_smr[i] * 10);
+ }
+}
+
+
+#define SB_NOTALLOCATED 0
+#define SB_ALLOCATED 1
+#define SB_NOMORE 2
+
+/* Try to maximize the smr while using a number of bits inferior to
+ the frame size. I tried to make the code simpler, faster and
+ smaller than other encoders :-) */
+static void compute_bit_allocation(MpegAudioContext *s,
+ short smr1[MPA_MAX_CHANNELS][SBLIMIT],
+ unsigned char bit_alloc[MPA_MAX_CHANNELS][SBLIMIT],
+ int *padding)
+{
+ int i, ch, b, max_smr, max_ch, max_sb, current_frame_size, max_frame_size;
+ int incr;
+ short smr[MPA_MAX_CHANNELS][SBLIMIT];
+ unsigned char subband_status[MPA_MAX_CHANNELS][SBLIMIT];
+ const unsigned char *alloc;
+
+ memcpy(smr, smr1, s->nb_channels * sizeof(short) * SBLIMIT);
+ memset(subband_status, SB_NOTALLOCATED, s->nb_channels * SBLIMIT);
+ memset(bit_alloc, 0, s->nb_channels * SBLIMIT);
+
+ /* compute frame size and padding */
+ max_frame_size = s->frame_size;
+ s->frame_frac += s->frame_frac_incr;
+ if (s->frame_frac >= 65536) {
+ s->frame_frac -= 65536;
+ s->do_padding = 1;
+ max_frame_size += 8;
+ } else {
+ s->do_padding = 0;
+ }
+
+ /* compute the header + bit alloc size */
+ current_frame_size = 32;
+ alloc = s->alloc_table;
+ for(i=0;i<s->sblimit;i++) {
+ incr = alloc[0];
+ current_frame_size += incr * s->nb_channels;
+ alloc += 1 << incr;
+ }
+ for(;;) {
+ /* look for the subband with the largest signal to mask ratio */
+ max_sb = -1;
+ max_ch = -1;
+ max_smr = 0x80000000;
+ for(ch=0;ch<s->nb_channels;ch++) {
+ for(i=0;i<s->sblimit;i++) {
+ if (smr[ch][i] > max_smr && subband_status[ch][i] != SB_NOMORE) {
+ max_smr = smr[ch][i];
+ max_sb = i;
+ max_ch = ch;
+ }
+ }
+ }
+#if 0
+ printf("current=%d max=%d max_sb=%d alloc=%d\n",
+ current_frame_size, max_frame_size, max_sb,
+ bit_alloc[max_sb]);
+#endif
+ if (max_sb < 0)
+ break;
+
+ /* find alloc table entry (XXX: not optimal, should use
+ pointer table) */
+ alloc = s->alloc_table;
+ for(i=0;i<max_sb;i++) {
+ alloc += 1 << alloc[0];
+ }
+
+ if (subband_status[max_ch][max_sb] == SB_NOTALLOCATED) {
+ /* nothing was coded for this band: add the necessary bits */
+ incr = 2 + nb_scale_factors[s->scale_code[max_ch][max_sb]] * 6;
+ incr += total_quant_bits[alloc[1]];
+ } else {
+ /* increments bit allocation */
+ b = bit_alloc[max_ch][max_sb];
+ incr = total_quant_bits[alloc[b + 1]] -
+ total_quant_bits[alloc[b]];
+ }
+
+ if (current_frame_size + incr <= max_frame_size) {
+ /* can increase size */
+ b = ++bit_alloc[max_ch][max_sb];
+ current_frame_size += incr;
+ /* decrease smr by the resolution we added */
+ smr[max_ch][max_sb] = smr1[max_ch][max_sb] - quant_snr[alloc[b]];
+ /* max allocation size reached ? */
+ if (b == ((1 << alloc[0]) - 1))
+ subband_status[max_ch][max_sb] = SB_NOMORE;
+ else
+ subband_status[max_ch][max_sb] = SB_ALLOCATED;
+ } else {
+ /* cannot increase the size of this subband */
+ subband_status[max_ch][max_sb] = SB_NOMORE;
+ }
+ }
+ *padding = max_frame_size - current_frame_size;
+ assert(*padding >= 0);
+
+#if 0
+ for(i=0;i<s->sblimit;i++) {
+ printf("%d ", bit_alloc[i]);
+ }
+ printf("\n");
+#endif
+}
+
+/*
+ * Output the mpeg audio layer 2 frame. Note how the code is small
+ * compared to other encoders :-)
+ */
+static void encode_frame(MpegAudioContext *s,
+ unsigned char bit_alloc[MPA_MAX_CHANNELS][SBLIMIT],
+ int padding)
+{
+ int i, j, k, l, bit_alloc_bits, b, ch;
+ unsigned char *sf;
+ int q[3];
+ PutBitContext *p = &s->pb;
+
+ /* header */
+
+ put_bits(p, 12, 0xfff);
+ put_bits(p, 1, 1 - s->lsf); /* 1 = mpeg1 ID, 0 = mpeg2 lsf ID */
+ put_bits(p, 2, 4-2); /* layer 2 */
+ put_bits(p, 1, 1); /* no error protection */
+ put_bits(p, 4, s->bitrate_index);
+ put_bits(p, 2, s->freq_index);
+ put_bits(p, 1, s->do_padding); /* use padding */
+ put_bits(p, 1, 0); /* private_bit */
+ put_bits(p, 2, s->nb_channels == 2 ? MPA_STEREO : MPA_MONO);
+ put_bits(p, 2, 0); /* mode_ext */
+ put_bits(p, 1, 0); /* no copyright */
+ put_bits(p, 1, 1); /* original */
+ put_bits(p, 2, 0); /* no emphasis */
+
+ /* bit allocation */
+ j = 0;
+ for(i=0;i<s->sblimit;i++) {
+ bit_alloc_bits = s->alloc_table[j];
+ for(ch=0;ch<s->nb_channels;ch++) {
+ put_bits(p, bit_alloc_bits, bit_alloc[ch][i]);
+ }
+ j += 1 << bit_alloc_bits;
+ }
+
+ /* scale codes */
+ for(i=0;i<s->sblimit;i++) {
+ for(ch=0;ch<s->nb_channels;ch++) {
+ if (bit_alloc[ch][i])
+ put_bits(p, 2, s->scale_code[ch][i]);
+ }
+ }
+
+ /* scale factors */
+ for(i=0;i<s->sblimit;i++) {
+ for(ch=0;ch<s->nb_channels;ch++) {
+ if (bit_alloc[ch][i]) {
+ sf = &s->scale_factors[ch][i][0];
+ switch(s->scale_code[ch][i]) {
+ case 0:
+ put_bits(p, 6, sf[0]);
+ put_bits(p, 6, sf[1]);
+ put_bits(p, 6, sf[2]);
+ break;
+ case 3:
+ case 1:
+ put_bits(p, 6, sf[0]);
+ put_bits(p, 6, sf[2]);
+ break;
+ case 2:
+ put_bits(p, 6, sf[0]);
+ break;
+ }
+ }
+ }
+ }
+
+ /* quantization & write sub band samples */
+
+ for(k=0;k<3;k++) {
+ for(l=0;l<12;l+=3) {
+ j = 0;
+ for(i=0;i<s->sblimit;i++) {
+ bit_alloc_bits = s->alloc_table[j];
+ for(ch=0;ch<s->nb_channels;ch++) {
+ b = bit_alloc[ch][i];
+ if (b) {
+ int qindex, steps, m, sample, bits;
+ /* we encode 3 sub band samples of the same sub band at a time */
+ qindex = s->alloc_table[j+b];
+ steps = quant_steps[qindex];
+ for(m=0;m<3;m++) {
+ sample = s->sb_samples[ch][k][l + m][i];
+ /* divide by scale factor */
+#ifdef USE_FLOATS
+ {
+ float a;
+ a = (float)sample * scale_factor_inv_table[s->scale_factors[ch][i][k]];
+ q[m] = (int)((a + 1.0) * steps * 0.5);
+ }
+#else
+ {
+ int q1, e, shift, mult;
+ e = s->scale_factors[ch][i][k];
+ shift = scale_factor_shift[e];
+ mult = scale_factor_mult[e];
+
+ /* normalize to P bits */
+ if (shift < 0)
+ q1 = sample << (-shift);
+ else
+ q1 = sample >> shift;
+ q1 = (q1 * mult) >> P;
+ q[m] = ((q1 + (1 << P)) * steps) >> (P + 1);
+ }
+#endif
+ if (q[m] >= steps)
+ q[m] = steps - 1;
+ assert(q[m] >= 0 && q[m] < steps);
+ }
+ bits = quant_bits[qindex];
+ if (bits < 0) {
+ /* group the 3 values to save bits */
+ put_bits(p, -bits,
+ q[0] + steps * (q[1] + steps * q[2]));
+#if 0
+ printf("%d: gr1 %d\n",
+ i, q[0] + steps * (q[1] + steps * q[2]));
+#endif
+ } else {
+#if 0
+ printf("%d: gr3 %d %d %d\n",
+ i, q[0], q[1], q[2]);
+#endif
+ put_bits(p, bits, q[0]);
+ put_bits(p, bits, q[1]);
+ put_bits(p, bits, q[2]);
+ }
+ }
+ }
+ /* next subband in alloc table */
+ j += 1 << bit_alloc_bits;
+ }
+ }
+ }
+
+ /* padding */
+ for(i=0;i<padding;i++)
+ put_bits(p, 1, 0);
+
+ /* flush */
+ flush_put_bits(p);
+}
+
+static int MPA_encode_frame(AVCodecContext *avctx,
+ unsigned char *frame, int buf_size, void *data)
+{
+ MpegAudioContext *s = avctx->priv_data;
+ short *samples = data;
+ short smr[MPA_MAX_CHANNELS][SBLIMIT];
+ unsigned char bit_alloc[MPA_MAX_CHANNELS][SBLIMIT];
+ int padding, i;
+
+ for(i=0;i<s->nb_channels;i++) {
+ filter(s, i, samples + i, s->nb_channels);
+ }
+
+ for(i=0;i<s->nb_channels;i++) {
+ compute_scale_factors(s->scale_code[i], s->scale_factors[i],
+ s->sb_samples[i], s->sblimit);
+ }
+ for(i=0;i<s->nb_channels;i++) {
+ psycho_acoustic_model(s, smr[i]);
+ }
+ compute_bit_allocation(s, smr, bit_alloc, &padding);
+
+ init_put_bits(&s->pb, frame, MPA_MAX_CODED_FRAME_SIZE);
+
+ encode_frame(s, bit_alloc, padding);
+
+ s->nb_samples += MPA_FRAME_SIZE;
+ return pbBufPtr(&s->pb) - s->pb.buf;
+}
+
+static int MPA_encode_close(AVCodecContext *avctx)
+{
+ av_freep(&avctx->coded_frame);
+ return 0;
+}
+
+AVCodec mp2_encoder = {
+ "mp2",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_MP2,
+ sizeof(MpegAudioContext),
+ MPA_encode_init,
+ MPA_encode_frame,
+ MPA_encode_close,
+ NULL,
+};
+
+#undef FIX
diff --git a/src/libffmpeg/libavcodec/mpegaudio.h b/contrib/ffmpeg/libavcodec/mpegaudio.h
index 3eadf92a8..3eadf92a8 100644
--- a/src/libffmpeg/libavcodec/mpegaudio.h
+++ b/contrib/ffmpeg/libavcodec/mpegaudio.h
diff --git a/contrib/ffmpeg/libavcodec/mpegaudiodec.c b/contrib/ffmpeg/libavcodec/mpegaudiodec.c
new file mode 100644
index 000000000..d64c9f611
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/mpegaudiodec.c
@@ -0,0 +1,2878 @@
+/*
+ * MPEG Audio decoder
+ * Copyright (c) 2001, 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 mpegaudiodec.c
+ * MPEG Audio decoder.
+ */
+
+//#define DEBUG
+#include "avcodec.h"
+#include "bitstream.h"
+#include "dsputil.h"
+
+/*
+ * TODO:
+ * - in low precision mode, use more 16 bit multiplies in synth filter
+ * - test lsf / mpeg25 extensively.
+ */
+
+/* define USE_HIGHPRECISION to have a bit exact (but slower) mpeg
+ audio decoder */
+#ifdef CONFIG_MPEGAUDIO_HP
+# define USE_HIGHPRECISION
+#endif
+
+#include "mpegaudio.h"
+
+#include "mathops.h"
+
+#define FRAC_ONE (1 << FRAC_BITS)
+
+#define FIX(a) ((int)((a) * FRAC_ONE))
+/* WARNING: only correct for posititive numbers */
+#define FIXR(a) ((int)((a) * FRAC_ONE + 0.5))
+#define FRAC_RND(a) (((a) + (FRAC_ONE/2)) >> FRAC_BITS)
+
+#define FIXHR(a) ((int)((a) * (1LL<<32) + 0.5))
+
+/****************/
+
+#define HEADER_SIZE 4
+#define BACKSTEP_SIZE 512
+#define EXTRABYTES 24
+
+struct GranuleDef;
+
+typedef struct MPADecodeContext {
+ DECLARE_ALIGNED_8(uint8_t, last_buf[2*BACKSTEP_SIZE + EXTRABYTES]);
+ int last_buf_size;
+ int frame_size;
+ /* next header (used in free format parsing) */
+ uint32_t free_format_next_header;
+ int error_protection;
+ int layer;
+ int sample_rate;
+ int sample_rate_index; /* between 0 and 8 */
+ int bit_rate;
+ GetBitContext gb;
+ GetBitContext in_gb;
+ int nb_channels;
+ int mode;
+ int mode_ext;
+ int lsf;
+ MPA_INT synth_buf[MPA_MAX_CHANNELS][512 * 2] __attribute__((aligned(16)));
+ int synth_buf_offset[MPA_MAX_CHANNELS];
+ int32_t sb_samples[MPA_MAX_CHANNELS][36][SBLIMIT] __attribute__((aligned(16)));
+ int32_t mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18]; /* previous samples, for layer 3 MDCT */
+#ifdef DEBUG
+ int frame_count;
+#endif
+ void (*compute_antialias)(struct MPADecodeContext *s, struct GranuleDef *g);
+ int adu_mode; ///< 0 for standard mp3, 1 for adu formatted mp3
+ int dither_state;
+ int error_resilience;
+ AVCodecContext* avctx;
+} MPADecodeContext;
+
+/**
+ * Context for MP3On4 decoder
+ */
+typedef struct MP3On4DecodeContext {
+ int frames; ///< number of mp3 frames per block (number of mp3 decoder instances)
+ int chan_cfg; ///< channel config number
+ MPADecodeContext *mp3decctx[5]; ///< MPADecodeContext for every decoder instance
+} MP3On4DecodeContext;
+
+/* 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 MODE_EXT_MS_STEREO 2
+#define MODE_EXT_I_STEREO 1
+
+/* layer 3 huffman tables */
+typedef struct HuffTable {
+ int xsize;
+ const uint8_t *bits;
+ const uint16_t *codes;
+} HuffTable;
+
+#include "mpegaudiodectab.h"
+
+static void compute_antialias_integer(MPADecodeContext *s, GranuleDef *g);
+static void compute_antialias_float(MPADecodeContext *s, GranuleDef *g);
+
+/* vlc structure for decoding layer 3 huffman tables */
+static VLC huff_vlc[16];
+static VLC huff_quad_vlc[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];
+/* intensity stereo coef table */
+static int32_t is_table[2][16];
+static int32_t is_table_lsf[2][2][16];
+static int32_t csa_table[8][4];
+static float csa_table_float[8][4];
+static int32_t mdct_win[8][36];
+
+/* lower 2 bits: modulo 3, higher bits: shift */
+static uint16_t scale_factor_modshift[64];
+/* [i][j]: 2^(-j/3) * FRAC_ONE * 2^(i+2) / (2^(i+2) - 1) */
+static int32_t scale_factor_mult[15][3];
+/* mult table for layer 2 group quantization */
+
+#define SCALE_GEN(v) \
+{ FIXR(1.0 * (v)), FIXR(0.7937005259 * (v)), FIXR(0.6299605249 * (v)) }
+
+static const int32_t scale_factor_mult2[3][3] = {
+ SCALE_GEN(4.0 / 3.0), /* 3 steps */
+ SCALE_GEN(4.0 / 5.0), /* 5 steps */
+ SCALE_GEN(4.0 / 9.0), /* 9 steps */
+};
+
+static MPA_INT window[512] __attribute__((aligned(16)));
+
+/* layer 1 unscaling */
+/* n = number of bits of the mantissa minus 1 */
+static inline int l1_unscale(int n, int mant, int scale_factor)
+{
+ int shift, mod;
+ int64_t val;
+
+ shift = scale_factor_modshift[scale_factor];
+ mod = shift & 3;
+ shift >>= 2;
+ val = MUL64(mant + (-1 << n) + 1, scale_factor_mult[n-1][mod]);
+ shift += n;
+ /* NOTE: at this point, 1 <= shift >= 21 + 15 */
+ return (int)((val + (1LL << (shift - 1))) >> shift);
+}
+
+static inline int l2_unscale_group(int steps, int mant, int scale_factor)
+{
+ int shift, mod, val;
+
+ shift = scale_factor_modshift[scale_factor];
+ mod = shift & 3;
+ shift >>= 2;
+
+ val = (mant - (steps >> 1)) * scale_factor_mult2[steps >> 2][mod];
+ /* NOTE: at this point, 0 <= shift <= 21 */
+ if (shift > 0)
+ val = (val + (1 << (shift - 1))) >> shift;
+ return val;
+}
+
+/* compute value^(4/3) * 2^(exponent/4). It normalized to FRAC_BITS */
+static inline int l3_unscale(int value, int exponent)
+{
+ unsigned int m;
+ int e;
+
+ e = table_4_3_exp [4*value + (exponent&3)];
+ m = table_4_3_value[4*value + (exponent&3)];
+ e -= (exponent >> 2);
+ assert(e>=1);
+ if (e > 31)
+ return 0;
+ m = (m + (1 << (e-1))) >> e;
+
+ return m;
+}
+
+/* all integer n^(4/3) computation code */
+#define DEV_ORDER 13
+
+#define POW_FRAC_BITS 24
+#define POW_FRAC_ONE (1 << POW_FRAC_BITS)
+#define POW_FIX(a) ((int)((a) * POW_FRAC_ONE))
+#define POW_MULL(a,b) (((int64_t)(a) * (int64_t)(b)) >> POW_FRAC_BITS)
+
+static int dev_4_3_coefs[DEV_ORDER];
+
+#if 0 /* unused */
+static int pow_mult3[3] = {
+ POW_FIX(1.0),
+ POW_FIX(1.25992104989487316476),
+ POW_FIX(1.58740105196819947474),
+};
+#endif
+
+static void int_pow_init(void)
+{
+ int i, a;
+
+ a = POW_FIX(1.0);
+ for(i=0;i<DEV_ORDER;i++) {
+ a = POW_MULL(a, POW_FIX(4.0 / 3.0) - i * POW_FIX(1.0)) / (i + 1);
+ dev_4_3_coefs[i] = a;
+ }
+}
+
+#if 0 /* unused, remove? */
+/* return the mantissa and the binary exponent */
+static int int_pow(int i, int *exp_ptr)
+{
+ int e, er, eq, j;
+ int a, a1;
+
+ /* renormalize */
+ a = i;
+ e = POW_FRAC_BITS;
+ while (a < (1 << (POW_FRAC_BITS - 1))) {
+ a = a << 1;
+ e--;
+ }
+ a -= (1 << POW_FRAC_BITS);
+ a1 = 0;
+ for(j = DEV_ORDER - 1; j >= 0; j--)
+ a1 = POW_MULL(a, dev_4_3_coefs[j] + a1);
+ a = (1 << POW_FRAC_BITS) + a1;
+ /* exponent compute (exact) */
+ e = e * 4;
+ er = e % 3;
+ eq = e / 3;
+ a = POW_MULL(a, pow_mult3[er]);
+ while (a >= 2 * POW_FRAC_ONE) {
+ a = a >> 1;
+ eq++;
+ }
+ /* convert to float */
+ while (a < POW_FRAC_ONE) {
+ a = a << 1;
+ eq--;
+ }
+ /* now POW_FRAC_ONE <= a < 2 * POW_FRAC_ONE */
+#if POW_FRAC_BITS > FRAC_BITS
+ a = (a + (1 << (POW_FRAC_BITS - FRAC_BITS - 1))) >> (POW_FRAC_BITS - FRAC_BITS);
+ /* correct overflow */
+ if (a >= 2 * (1 << FRAC_BITS)) {
+ a = a >> 1;
+ eq++;
+ }
+#endif
+ *exp_ptr = eq;
+ return a;
+}
+#endif
+
+static int decode_init(AVCodecContext * avctx)
+{
+ MPADecodeContext *s = avctx->priv_data;
+ static int init=0;
+ int i, j, k;
+
+ s->avctx = avctx;
+
+#if defined(USE_HIGHPRECISION) && defined(CONFIG_AUDIO_NONSHORT)
+ avctx->sample_fmt= SAMPLE_FMT_S32;
+#else
+ avctx->sample_fmt= SAMPLE_FMT_S16;
+#endif
+ s->error_resilience= avctx->error_resilience;
+
+ if(avctx->antialias_algo != FF_AA_FLOAT)
+ s->compute_antialias= compute_antialias_integer;
+ else
+ s->compute_antialias= compute_antialias_float;
+
+ if (!init && !avctx->parse_only) {
+ /* scale factors table for layer 1/2 */
+ for(i=0;i<64;i++) {
+ int shift, mod;
+ /* 1.0 (i = 3) is normalized to 2 ^ FRAC_BITS */
+ shift = (i / 3);
+ mod = i % 3;
+ scale_factor_modshift[i] = mod | (shift << 2);
+ }
+
+ /* scale factor multiply for layer 1 */
+ for(i=0;i<15;i++) {
+ int n, norm;
+ n = i + 2;
+ norm = ((INT64_C(1) << n) * FRAC_ONE) / ((1 << n) - 1);
+ scale_factor_mult[i][0] = MULL(FIXR(1.0 * 2.0), norm);
+ scale_factor_mult[i][1] = MULL(FIXR(0.7937005259 * 2.0), norm);
+ scale_factor_mult[i][2] = MULL(FIXR(0.6299605249 * 2.0), norm);
+ dprintf(avctx, "%d: norm=%x s=%x %x %x\n",
+ i, norm,
+ scale_factor_mult[i][0],
+ scale_factor_mult[i][1],
+ scale_factor_mult[i][2]);
+ }
+
+ ff_mpa_synth_init(window);
+
+ /* huffman decode tables */
+ for(i=1;i<16;i++) {
+ const HuffTable *h = &mpa_huff_tables[i];
+ int xsize, x, y;
+ unsigned int n;
+ uint8_t tmp_bits [512];
+ uint16_t tmp_codes[512];
+
+ memset(tmp_bits , 0, sizeof(tmp_bits ));
+ memset(tmp_codes, 0, sizeof(tmp_codes));
+
+ xsize = h->xsize;
+ n = xsize * xsize;
+
+ j = 0;
+ for(x=0;x<xsize;x++) {
+ for(y=0;y<xsize;y++){
+ tmp_bits [(x << 5) | y | ((x&&y)<<4)]= h->bits [j ];
+ tmp_codes[(x << 5) | y | ((x&&y)<<4)]= h->codes[j++];
+ }
+ }
+
+ /* XXX: fail test */
+ init_vlc(&huff_vlc[i], 7, 512,
+ tmp_bits, 1, 1, tmp_codes, 2, 2, 1);
+ }
+ for(i=0;i<2;i++) {
+ init_vlc(&huff_quad_vlc[i], i == 0 ? 7 : 4, 16,
+ mpa_quad_bits[i], 1, 1, mpa_quad_codes[i], 1, 1, 1);
+ }
+
+ for(i=0;i<9;i++) {
+ k = 0;
+ for(j=0;j<22;j++) {
+ band_index_long[i][j] = k;
+ k += band_size_long[i][j];
+ }
+ band_index_long[i][22] = k;
+ }
+
+ /* compute n ^ (4/3) and store it in mantissa/exp format */
+
+ int_pow_init();
+ for(i=1;i<TABLE_4_3_SIZE;i++) {
+ double f, fm;
+ int e, m;
+ f = pow((double)(i/4), 4.0 / 3.0) * 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;
+// av_log(NULL, AV_LOG_DEBUG, "%d %d %f\n", i, m, pow((double)i, 4.0 / 3.0));
+ table_4_3_exp[i] = -e;
+ }
+ for(i=0; i<512*16; i++){
+ int exponent= (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);
+ }
+
+ for(i=0;i<7;i++) {
+ float f;
+ int v;
+ if (i != 6) {
+ f = tan((double)i * M_PI / 12.0);
+ v = FIXR(f / (1.0 + f));
+ } else {
+ v = FIXR(1.0);
+ }
+ is_table[0][i] = v;
+ is_table[1][6 - i] = v;
+ }
+ /* invalid values */
+ for(i=7;i<16;i++)
+ is_table[0][i] = is_table[1][i] = 0.0;
+
+ for(i=0;i<16;i++) {
+ double f;
+ int e, k;
+
+ for(j=0;j<2;j++) {
+ e = -(j + 1) * ((i + 1) >> 1);
+ f = pow(2.0, e / 4.0);
+ k = i & 1;
+ is_table_lsf[j][k ^ 1][i] = FIXR(f);
+ is_table_lsf[j][k][i] = FIXR(1.0);
+ dprintf(avctx, "is_table_lsf %d %d: %x %x\n",
+ i, j, is_table_lsf[j][0][i], is_table_lsf[j][1][i]);
+ }
+ }
+
+ for(i=0;i<8;i++) {
+ float ci, cs, ca;
+ ci = ci_table[i];
+ cs = 1.0 / sqrt(1.0 + ci * ci);
+ ca = cs * ci;
+ csa_table[i][0] = FIXHR(cs/4);
+ csa_table[i][1] = FIXHR(ca/4);
+ csa_table[i][2] = FIXHR(ca/4) + FIXHR(cs/4);
+ csa_table[i][3] = FIXHR(ca/4) - FIXHR(cs/4);
+ csa_table_float[i][0] = cs;
+ csa_table_float[i][1] = ca;
+ csa_table_float[i][2] = ca + cs;
+ csa_table_float[i][3] = ca - cs;
+// printf("%d %d %d %d\n", FIX(cs), FIX(cs-1), FIX(ca), FIX(cs)-FIX(ca));
+// av_log(NULL, AV_LOG_DEBUG,"%f %f %f %f\n", cs, ca, ca+cs, ca-cs);
+ }
+
+ /* compute mdct windows */
+ for(i=0;i<36;i++) {
+ for(j=0; j<4; j++){
+ double d;
+
+ if(j==2 && i%3 != 1)
+ continue;
+
+ d= sin(M_PI * (i + 0.5) / 36.0);
+ if(j==1){
+ if (i>=30) d= 0;
+ else if(i>=24) d= sin(M_PI * (i - 18 + 0.5) / 12.0);
+ else if(i>=18) d= 1;
+ }else if(j==3){
+ if (i< 6) d= 0;
+ else if(i< 12) d= sin(M_PI * (i - 6 + 0.5) / 12.0);
+ else if(i< 18) d= 1;
+ }
+ //merge last stage of imdct into the window coefficients
+ d*= 0.5 / cos(M_PI*(2*i + 19)/72);
+
+ if(j==2)
+ mdct_win[j][i/3] = FIXHR((d / (1<<5)));
+ else
+ mdct_win[j][i ] = FIXHR((d / (1<<5)));
+// av_log(NULL, AV_LOG_DEBUG, "%2d %d %f\n", i,j,d / (1<<5));
+ }
+ }
+
+ /* NOTE: we do frequency inversion adter the MDCT by changing
+ the sign of the right window coefs */
+ for(j=0;j<4;j++) {
+ for(i=0;i<36;i+=2) {
+ mdct_win[j + 4][i] = mdct_win[j][i];
+ mdct_win[j + 4][i + 1] = -mdct_win[j][i + 1];
+ }
+ }
+
+#if defined(DEBUG)
+ for(j=0;j<8;j++) {
+ av_log(avctx, AV_LOG_DEBUG, "win%d=\n", j);
+ for(i=0;i<36;i++)
+ av_log(avctx, AV_LOG_DEBUG, "%f, ", (double)mdct_win[j][i] / FRAC_ONE);
+ av_log(avctx, AV_LOG_DEBUG, "\n");
+ }
+#endif
+ init = 1;
+ }
+
+#ifdef DEBUG
+ s->frame_count = 0;
+#endif
+ if (avctx->codec_id == CODEC_ID_MP3ADU)
+ s->adu_mode = 1;
+ return 0;
+}
+
+/* tab[i][j] = 1.0 / (2.0 * cos(pi*(2*k+1) / 2^(6 - j))) */
+
+/* cos(i*pi/64) */
+
+#define COS0_0 FIXHR(0.50060299823519630134/2)
+#define COS0_1 FIXHR(0.50547095989754365998/2)
+#define COS0_2 FIXHR(0.51544730992262454697/2)
+#define COS0_3 FIXHR(0.53104259108978417447/2)
+#define COS0_4 FIXHR(0.55310389603444452782/2)
+#define COS0_5 FIXHR(0.58293496820613387367/2)
+#define COS0_6 FIXHR(0.62250412303566481615/2)
+#define COS0_7 FIXHR(0.67480834145500574602/2)
+#define COS0_8 FIXHR(0.74453627100229844977/2)
+#define COS0_9 FIXHR(0.83934964541552703873/2)
+#define COS0_10 FIXHR(0.97256823786196069369/2)
+#define COS0_11 FIXHR(1.16943993343288495515/4)
+#define COS0_12 FIXHR(1.48416461631416627724/4)
+#define COS0_13 FIXHR(2.05778100995341155085/8)
+#define COS0_14 FIXHR(3.40760841846871878570/8)
+#define COS0_15 FIXHR(10.19000812354805681150/32)
+
+#define COS1_0 FIXHR(0.50241928618815570551/2)
+#define COS1_1 FIXHR(0.52249861493968888062/2)
+#define COS1_2 FIXHR(0.56694403481635770368/2)
+#define COS1_3 FIXHR(0.64682178335999012954/2)
+#define COS1_4 FIXHR(0.78815462345125022473/2)
+#define COS1_5 FIXHR(1.06067768599034747134/4)
+#define COS1_6 FIXHR(1.72244709823833392782/4)
+#define COS1_7 FIXHR(5.10114861868916385802/16)
+
+#define COS2_0 FIXHR(0.50979557910415916894/2)
+#define COS2_1 FIXHR(0.60134488693504528054/2)
+#define COS2_2 FIXHR(0.89997622313641570463/2)
+#define COS2_3 FIXHR(2.56291544774150617881/8)
+
+#define COS3_0 FIXHR(0.54119610014619698439/2)
+#define COS3_1 FIXHR(1.30656296487637652785/4)
+
+#define COS4_0 FIXHR(0.70710678118654752439/2)
+
+/* butterfly operator */
+#define BF(a, b, c, s)\
+{\
+ tmp0 = tab[a] + tab[b];\
+ tmp1 = tab[a] - tab[b];\
+ tab[a] = tmp0;\
+ tab[b] = MULH(tmp1<<(s), c);\
+}
+
+#define BF1(a, b, c, d)\
+{\
+ BF(a, b, COS4_0, 1);\
+ BF(c, d,-COS4_0, 1);\
+ tab[c] += tab[d];\
+}
+
+#define BF2(a, b, c, d)\
+{\
+ BF(a, b, COS4_0, 1);\
+ BF(c, d,-COS4_0, 1);\
+ tab[c] += tab[d];\
+ tab[a] += tab[c];\
+ tab[c] += tab[b];\
+ tab[b] += tab[d];\
+}
+
+#define ADD(a, b) tab[a] += tab[b]
+
+/* DCT32 without 1/sqrt(2) coef zero scaling. */
+static void dct32(int32_t *out, int32_t *tab)
+{
+ int tmp0, tmp1;
+
+ /* pass 1 */
+ BF( 0, 31, COS0_0 , 1);
+ BF(15, 16, COS0_15, 5);
+ /* pass 2 */
+ BF( 0, 15, COS1_0 , 1);
+ BF(16, 31,-COS1_0 , 1);
+ /* pass 1 */
+ BF( 7, 24, COS0_7 , 1);
+ BF( 8, 23, COS0_8 , 1);
+ /* pass 2 */
+ BF( 7, 8, COS1_7 , 4);
+ BF(23, 24,-COS1_7 , 4);
+ /* pass 3 */
+ BF( 0, 7, COS2_0 , 1);
+ BF( 8, 15,-COS2_0 , 1);
+ BF(16, 23, COS2_0 , 1);
+ BF(24, 31,-COS2_0 , 1);
+ /* pass 1 */
+ BF( 3, 28, COS0_3 , 1);
+ BF(12, 19, COS0_12, 2);
+ /* pass 2 */
+ BF( 3, 12, COS1_3 , 1);
+ BF(19, 28,-COS1_3 , 1);
+ /* pass 1 */
+ BF( 4, 27, COS0_4 , 1);
+ BF(11, 20, COS0_11, 2);
+ /* pass 2 */
+ BF( 4, 11, COS1_4 , 1);
+ BF(20, 27,-COS1_4 , 1);
+ /* pass 3 */
+ BF( 3, 4, COS2_3 , 3);
+ BF(11, 12,-COS2_3 , 3);
+ BF(19, 20, COS2_3 , 3);
+ BF(27, 28,-COS2_3 , 3);
+ /* pass 4 */
+ BF( 0, 3, COS3_0 , 1);
+ BF( 4, 7,-COS3_0 , 1);
+ BF( 8, 11, COS3_0 , 1);
+ BF(12, 15,-COS3_0 , 1);
+ BF(16, 19, COS3_0 , 1);
+ BF(20, 23,-COS3_0 , 1);
+ BF(24, 27, COS3_0 , 1);
+ BF(28, 31,-COS3_0 , 1);
+
+
+
+ /* pass 1 */
+ BF( 1, 30, COS0_1 , 1);
+ BF(14, 17, COS0_14, 3);
+ /* pass 2 */
+ BF( 1, 14, COS1_1 , 1);
+ BF(17, 30,-COS1_1 , 1);
+ /* pass 1 */
+ BF( 6, 25, COS0_6 , 1);
+ BF( 9, 22, COS0_9 , 1);
+ /* pass 2 */
+ BF( 6, 9, COS1_6 , 2);
+ BF(22, 25,-COS1_6 , 2);
+ /* pass 3 */
+ BF( 1, 6, COS2_1 , 1);
+ BF( 9, 14,-COS2_1 , 1);
+ BF(17, 22, COS2_1 , 1);
+ BF(25, 30,-COS2_1 , 1);
+
+ /* pass 1 */
+ BF( 2, 29, COS0_2 , 1);
+ BF(13, 18, COS0_13, 3);
+ /* pass 2 */
+ BF( 2, 13, COS1_2 , 1);
+ BF(18, 29,-COS1_2 , 1);
+ /* pass 1 */
+ BF( 5, 26, COS0_5 , 1);
+ BF(10, 21, COS0_10, 1);
+ /* pass 2 */
+ BF( 5, 10, COS1_5 , 2);
+ BF(21, 26,-COS1_5 , 2);
+ /* pass 3 */
+ BF( 2, 5, COS2_2 , 1);
+ BF(10, 13,-COS2_2 , 1);
+ BF(18, 21, COS2_2 , 1);
+ BF(26, 29,-COS2_2 , 1);
+ /* pass 4 */
+ BF( 1, 2, COS3_1 , 2);
+ BF( 5, 6,-COS3_1 , 2);
+ BF( 9, 10, COS3_1 , 2);
+ BF(13, 14,-COS3_1 , 2);
+ BF(17, 18, COS3_1 , 2);
+ BF(21, 22,-COS3_1 , 2);
+ BF(25, 26, COS3_1 , 2);
+ BF(29, 30,-COS3_1 , 2);
+
+ /* pass 5 */
+ BF1( 0, 1, 2, 3);
+ BF2( 4, 5, 6, 7);
+ BF1( 8, 9, 10, 11);
+ BF2(12, 13, 14, 15);
+ BF1(16, 17, 18, 19);
+ BF2(20, 21, 22, 23);
+ BF1(24, 25, 26, 27);
+ BF2(28, 29, 30, 31);
+
+ /* pass 6 */
+
+ ADD( 8, 12);
+ ADD(12, 10);
+ ADD(10, 14);
+ ADD(14, 9);
+ ADD( 9, 13);
+ ADD(13, 11);
+ ADD(11, 15);
+
+ out[ 0] = tab[0];
+ out[16] = tab[1];
+ out[ 8] = tab[2];
+ out[24] = tab[3];
+ out[ 4] = tab[4];
+ out[20] = tab[5];
+ out[12] = tab[6];
+ out[28] = tab[7];
+ out[ 2] = tab[8];
+ out[18] = tab[9];
+ out[10] = tab[10];
+ out[26] = tab[11];
+ out[ 6] = tab[12];
+ out[22] = tab[13];
+ out[14] = tab[14];
+ out[30] = tab[15];
+
+ ADD(24, 28);
+ ADD(28, 26);
+ ADD(26, 30);
+ ADD(30, 25);
+ ADD(25, 29);
+ ADD(29, 27);
+ ADD(27, 31);
+
+ out[ 1] = tab[16] + tab[24];
+ out[17] = tab[17] + tab[25];
+ out[ 9] = tab[18] + tab[26];
+ out[25] = tab[19] + tab[27];
+ out[ 5] = tab[20] + tab[28];
+ out[21] = tab[21] + tab[29];
+ out[13] = tab[22] + tab[30];
+ out[29] = tab[23] + tab[31];
+ out[ 3] = tab[24] + tab[20];
+ out[19] = tab[25] + tab[21];
+ out[11] = tab[26] + tab[22];
+ out[27] = tab[27] + tab[23];
+ out[ 7] = tab[28] + tab[18];
+ out[23] = tab[29] + tab[19];
+ out[15] = tab[30] + tab[17];
+ out[31] = tab[31];
+}
+
+#if FRAC_BITS <= 15
+
+static inline int round_sample(int *sum)
+{
+ int sum1;
+ sum1 = (*sum) >> OUT_SHIFT;
+ *sum &= (1<<OUT_SHIFT)-1;
+ if (sum1 < OUT_MIN)
+ sum1 = OUT_MIN;
+ else if (sum1 > OUT_MAX)
+ sum1 = OUT_MAX;
+ return sum1;
+}
+
+/* signed 16x16 -> 32 multiply add accumulate */
+#define MACS(rt, ra, rb) MAC16(rt, ra, rb)
+
+/* signed 16x16 -> 32 multiply */
+#define MULS(ra, rb) MUL16(ra, rb)
+
+#else
+
+static inline int round_sample(int64_t *sum)
+{
+ int sum1;
+ sum1 = (int)((*sum) >> OUT_SHIFT);
+ *sum &= (1<<OUT_SHIFT)-1;
+ if (sum1 < OUT_MIN)
+ sum1 = OUT_MIN;
+ else if (sum1 > OUT_MAX)
+ sum1 = OUT_MAX;
+ return sum1;
+}
+
+# define MULS(ra, rb) MUL64(ra, rb)
+#endif
+
+#define SUM8(sum, op, w, p) \
+{ \
+ sum op MULS((w)[0 * 64], p[0 * 64]);\
+ sum op MULS((w)[1 * 64], p[1 * 64]);\
+ sum op MULS((w)[2 * 64], p[2 * 64]);\
+ sum op MULS((w)[3 * 64], p[3 * 64]);\
+ sum op MULS((w)[4 * 64], p[4 * 64]);\
+ sum op MULS((w)[5 * 64], p[5 * 64]);\
+ sum op MULS((w)[6 * 64], p[6 * 64]);\
+ sum op MULS((w)[7 * 64], p[7 * 64]);\
+}
+
+#define SUM8P2(sum1, op1, sum2, op2, w1, w2, p) \
+{ \
+ int tmp;\
+ tmp = p[0 * 64];\
+ sum1 op1 MULS((w1)[0 * 64], tmp);\
+ sum2 op2 MULS((w2)[0 * 64], tmp);\
+ tmp = p[1 * 64];\
+ sum1 op1 MULS((w1)[1 * 64], tmp);\
+ sum2 op2 MULS((w2)[1 * 64], tmp);\
+ tmp = p[2 * 64];\
+ sum1 op1 MULS((w1)[2 * 64], tmp);\
+ sum2 op2 MULS((w2)[2 * 64], tmp);\
+ tmp = p[3 * 64];\
+ sum1 op1 MULS((w1)[3 * 64], tmp);\
+ sum2 op2 MULS((w2)[3 * 64], tmp);\
+ tmp = p[4 * 64];\
+ sum1 op1 MULS((w1)[4 * 64], tmp);\
+ sum2 op2 MULS((w2)[4 * 64], tmp);\
+ tmp = p[5 * 64];\
+ sum1 op1 MULS((w1)[5 * 64], tmp);\
+ sum2 op2 MULS((w2)[5 * 64], tmp);\
+ tmp = p[6 * 64];\
+ sum1 op1 MULS((w1)[6 * 64], tmp);\
+ sum2 op2 MULS((w2)[6 * 64], tmp);\
+ tmp = p[7 * 64];\
+ sum1 op1 MULS((w1)[7 * 64], tmp);\
+ sum2 op2 MULS((w2)[7 * 64], tmp);\
+}
+
+void ff_mpa_synth_init(MPA_INT *window)
+{
+ int i;
+
+ /* max = 18760, max sum over all 16 coefs : 44736 */
+ for(i=0;i<257;i++) {
+ int v;
+ v = mpa_enwindow[i];
+#if WFRAC_BITS < 16
+ v = (v + (1 << (16 - WFRAC_BITS - 1))) >> (16 - WFRAC_BITS);
+#endif
+ window[i] = v;
+ if ((i & 63) != 0)
+ v = -v;
+ if (i != 0)
+ window[512 - i] = v;
+ }
+}
+
+/* 32 sub band synthesis filter. Input: 32 sub band samples, Output:
+ 32 samples. */
+/* XXX: optimize by avoiding ring buffer usage */
+void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,
+ MPA_INT *window, int *dither_state,
+ OUT_INT *samples, int incr,
+ int32_t sb_samples[SBLIMIT])
+{
+ int32_t tmp[32];
+ register MPA_INT *synth_buf;
+ register const MPA_INT *w, *w2, *p;
+ int j, offset, v;
+ OUT_INT *samples2;
+#if FRAC_BITS <= 15
+ int sum, sum2;
+#else
+ int64_t sum, sum2;
+#endif
+
+ dct32(tmp, sb_samples);
+
+ offset = *synth_buf_offset;
+ synth_buf = synth_buf_ptr + offset;
+
+ for(j=0;j<32;j++) {
+ v = tmp[j];
+#if FRAC_BITS <= 15
+ /* NOTE: can cause a loss in precision if very high amplitude
+ sound */
+ if (v > 32767)
+ v = 32767;
+ else if (v < -32768)
+ v = -32768;
+#endif
+ synth_buf[j] = v;
+ }
+ /* copy to avoid wrap */
+ memcpy(synth_buf + 512, synth_buf, 32 * sizeof(MPA_INT));
+
+ samples2 = samples + 31 * incr;
+ w = window;
+ w2 = window + 31;
+
+ sum = *dither_state;
+ p = synth_buf + 16;
+ SUM8(sum, +=, w, p);
+ p = synth_buf + 48;
+ SUM8(sum, -=, w + 32, p);
+ *samples = round_sample(&sum);
+ samples += incr;
+ w++;
+
+ /* we calculate two samples at the same time to avoid one memory
+ access per two sample */
+ for(j=1;j<16;j++) {
+ sum2 = 0;
+ p = synth_buf + 16 + j;
+ SUM8P2(sum, +=, sum2, -=, w, w2, p);
+ p = synth_buf + 48 - j;
+ SUM8P2(sum, -=, sum2, -=, w + 32, w2 + 32, p);
+
+ *samples = round_sample(&sum);
+ samples += incr;
+ sum += sum2;
+ *samples2 = round_sample(&sum);
+ samples2 -= incr;
+ w++;
+ w2--;
+ }
+
+ p = synth_buf + 32;
+ SUM8(sum, -=, w + 32, p);
+ *samples = round_sample(&sum);
+ *dither_state= sum;
+
+ offset = (offset - 32) & 511;
+ *synth_buf_offset = offset;
+}
+
+#define C3 FIXHR(0.86602540378443864676/2)
+
+/* 0.5 / cos(pi*(2*i+1)/36) */
+static const int icos36[9] = {
+ FIXR(0.50190991877167369479),
+ FIXR(0.51763809020504152469), //0
+ FIXR(0.55168895948124587824),
+ FIXR(0.61038729438072803416),
+ FIXR(0.70710678118654752439), //1
+ FIXR(0.87172339781054900991),
+ FIXR(1.18310079157624925896),
+ FIXR(1.93185165257813657349), //2
+ FIXR(5.73685662283492756461),
+};
+
+/* 0.5 / cos(pi*(2*i+1)/36) */
+static const int icos36h[9] = {
+ FIXHR(0.50190991877167369479/2),
+ FIXHR(0.51763809020504152469/2), //0
+ FIXHR(0.55168895948124587824/2),
+ FIXHR(0.61038729438072803416/2),
+ FIXHR(0.70710678118654752439/2), //1
+ FIXHR(0.87172339781054900991/2),
+ FIXHR(1.18310079157624925896/4),
+ FIXHR(1.93185165257813657349/4), //2
+// FIXHR(5.73685662283492756461),
+};
+
+/* 12 points IMDCT. We compute it "by hand" by factorizing obvious
+ cases. */
+static void imdct12(int *out, int *in)
+{
+ int in0, in1, in2, in3, in4, in5, t1, t2;
+
+ in0= in[0*3];
+ in1= in[1*3] + in[0*3];
+ in2= in[2*3] + in[1*3];
+ in3= in[3*3] + in[2*3];
+ in4= in[4*3] + in[3*3];
+ in5= in[5*3] + in[4*3];
+ in5 += in3;
+ in3 += in1;
+
+ in2= MULH(2*in2, C3);
+ in3= MULH(4*in3, C3);
+
+ t1 = in0 - in4;
+ t2 = MULH(2*(in1 - in5), icos36h[4]);
+
+ out[ 7]=
+ out[10]= t1 + t2;
+ out[ 1]=
+ out[ 4]= t1 - t2;
+
+ in0 += in4>>1;
+ in4 = in0 + in2;
+ in5 += 2*in1;
+ in1 = MULH(in5 + in3, icos36h[1]);
+ out[ 8]=
+ out[ 9]= in4 + in1;
+ out[ 2]=
+ out[ 3]= in4 - in1;
+
+ in0 -= in2;
+ in5 = MULH(2*(in5 - in3), icos36h[7]);
+ out[ 0]=
+ out[ 5]= in0 - in5;
+ out[ 6]=
+ out[11]= in0 + in5;
+}
+
+/* cos(pi*i/18) */
+#define C1 FIXHR(0.98480775301220805936/2)
+#define C2 FIXHR(0.93969262078590838405/2)
+#define C3 FIXHR(0.86602540378443864676/2)
+#define C4 FIXHR(0.76604444311897803520/2)
+#define C5 FIXHR(0.64278760968653932632/2)
+#define C6 FIXHR(0.5/2)
+#define C7 FIXHR(0.34202014332566873304/2)
+#define C8 FIXHR(0.17364817766693034885/2)
+
+
+/* using Lee like decomposition followed by hand coded 9 points DCT */
+static void imdct36(int *out, int *buf, int *in, int *win)
+{
+ int i, j, t0, t1, t2, t3, s0, s1, s2, s3;
+ int tmp[18], *tmp1, *in1;
+
+ for(i=17;i>=1;i--)
+ in[i] += in[i-1];
+ for(i=17;i>=3;i-=2)
+ in[i] += in[i-2];
+
+ for(j=0;j<2;j++) {
+ tmp1 = tmp + j;
+ in1 = in + j;
+#if 0
+//more accurate but slower
+ int64_t t0, t1, t2, t3;
+ t2 = in1[2*4] + in1[2*8] - in1[2*2];
+
+ t3 = (in1[2*0] + (int64_t)(in1[2*6]>>1))<<32;
+ t1 = in1[2*0] - in1[2*6];
+ tmp1[ 6] = t1 - (t2>>1);
+ tmp1[16] = t1 + t2;
+
+ t0 = MUL64(2*(in1[2*2] + in1[2*4]), C2);
+ t1 = MUL64( in1[2*4] - in1[2*8] , -2*C8);
+ t2 = MUL64(2*(in1[2*2] + in1[2*8]), -C4);
+
+ tmp1[10] = (t3 - t0 - t2) >> 32;
+ tmp1[ 2] = (t3 + t0 + t1) >> 32;
+ tmp1[14] = (t3 + t2 - t1) >> 32;
+
+ tmp1[ 4] = MULH(2*(in1[2*5] + in1[2*7] - in1[2*1]), -C3);
+ t2 = MUL64(2*(in1[2*1] + in1[2*5]), C1);
+ t3 = MUL64( in1[2*5] - in1[2*7] , -2*C7);
+ t0 = MUL64(2*in1[2*3], C3);
+
+ t1 = MUL64(2*(in1[2*1] + in1[2*7]), -C5);
+
+ tmp1[ 0] = (t2 + t3 + t0) >> 32;
+ tmp1[12] = (t2 + t1 - t0) >> 32;
+ tmp1[ 8] = (t3 - t1 - t0) >> 32;
+#else
+ t2 = in1[2*4] + in1[2*8] - in1[2*2];
+
+ t3 = in1[2*0] + (in1[2*6]>>1);
+ t1 = in1[2*0] - in1[2*6];
+ tmp1[ 6] = t1 - (t2>>1);
+ tmp1[16] = t1 + t2;
+
+ t0 = MULH(2*(in1[2*2] + in1[2*4]), C2);
+ t1 = MULH( in1[2*4] - in1[2*8] , -2*C8);
+ t2 = MULH(2*(in1[2*2] + in1[2*8]), -C4);
+
+ tmp1[10] = t3 - t0 - t2;
+ tmp1[ 2] = t3 + t0 + t1;
+ tmp1[14] = t3 + t2 - t1;
+
+ tmp1[ 4] = MULH(2*(in1[2*5] + in1[2*7] - in1[2*1]), -C3);
+ t2 = MULH(2*(in1[2*1] + in1[2*5]), C1);
+ t3 = MULH( in1[2*5] - in1[2*7] , -2*C7);
+ t0 = MULH(2*in1[2*3], C3);
+
+ t1 = MULH(2*(in1[2*1] + in1[2*7]), -C5);
+
+ tmp1[ 0] = t2 + t3 + t0;
+ tmp1[12] = t2 + t1 - t0;
+ tmp1[ 8] = t3 - t1 - t0;
+#endif
+ }
+
+ i = 0;
+ for(j=0;j<4;j++) {
+ t0 = tmp[i];
+ t1 = tmp[i + 2];
+ s0 = t1 + t0;
+ s2 = t1 - t0;
+
+ t2 = tmp[i + 1];
+ t3 = tmp[i + 3];
+ s1 = MULH(2*(t3 + t2), icos36h[j]);
+ s3 = MULL(t3 - t2, icos36[8 - j]);
+
+ t0 = s0 + s1;
+ t1 = s0 - s1;
+ out[(9 + j)*SBLIMIT] = MULH(t1, win[9 + j]) + buf[9 + j];
+ out[(8 - j)*SBLIMIT] = MULH(t1, win[8 - j]) + buf[8 - j];
+ buf[9 + j] = MULH(t0, win[18 + 9 + j]);
+ buf[8 - j] = MULH(t0, win[18 + 8 - j]);
+
+ t0 = s2 + s3;
+ t1 = s2 - s3;
+ out[(9 + 8 - j)*SBLIMIT] = MULH(t1, win[9 + 8 - j]) + buf[9 + 8 - j];
+ out[( j)*SBLIMIT] = MULH(t1, win[ j]) + buf[ j];
+ buf[9 + 8 - j] = MULH(t0, win[18 + 9 + 8 - j]);
+ buf[ + j] = MULH(t0, win[18 + j]);
+ i += 4;
+ }
+
+ s0 = tmp[16];
+ s1 = MULH(2*tmp[17], icos36h[4]);
+ t0 = s0 + s1;
+ t1 = s0 - s1;
+ out[(9 + 4)*SBLIMIT] = MULH(t1, win[9 + 4]) + buf[9 + 4];
+ out[(8 - 4)*SBLIMIT] = MULH(t1, win[8 - 4]) + buf[8 - 4];
+ buf[9 + 4] = MULH(t0, win[18 + 9 + 4]);
+ buf[8 - 4] = MULH(t0, win[18 + 8 - 4]);
+}
+
+/* header decoding. MUST check the header before because no
+ consistency check is done there. Return 1 if free format found and
+ that the frame size must be computed externally */
+static int decode_header(MPADecodeContext *s, uint32_t header)
+{
+ int sample_rate, frame_size, mpeg25, padding;
+ int sample_rate_index, bitrate_index;
+ if (header & (1<<20)) {
+ s->lsf = (header & (1<<19)) ? 0 : 1;
+ mpeg25 = 0;
+ } else {
+ s->lsf = 1;
+ mpeg25 = 1;
+ }
+
+ s->layer = 4 - ((header >> 17) & 3);
+ /* extract frequency */
+ sample_rate_index = (header >> 10) & 3;
+ sample_rate = mpa_freq_tab[sample_rate_index] >> (s->lsf + mpeg25);
+ sample_rate_index += 3 * (s->lsf + mpeg25);
+ s->sample_rate_index = sample_rate_index;
+ s->error_protection = ((header >> 16) & 1) ^ 1;
+ s->sample_rate = sample_rate;
+
+ bitrate_index = (header >> 12) & 0xf;
+ padding = (header >> 9) & 1;
+ //extension = (header >> 8) & 1;
+ s->mode = (header >> 6) & 3;
+ s->mode_ext = (header >> 4) & 3;
+ //copyright = (header >> 3) & 1;
+ //original = (header >> 2) & 1;
+ //emphasis = header & 3;
+
+ if (s->mode == MPA_MONO)
+ s->nb_channels = 1;
+ else
+ s->nb_channels = 2;
+
+ if (bitrate_index != 0) {
+ frame_size = mpa_bitrate_tab[s->lsf][s->layer - 1][bitrate_index];
+ s->bit_rate = frame_size * 1000;
+ switch(s->layer) {
+ case 1:
+ frame_size = (frame_size * 12000) / sample_rate;
+ frame_size = (frame_size + padding) * 4;
+ break;
+ case 2:
+ frame_size = (frame_size * 144000) / sample_rate;
+ frame_size += padding;
+ break;
+ default:
+ case 3:
+ frame_size = (frame_size * 144000) / (sample_rate << s->lsf);
+ frame_size += padding;
+ break;
+ }
+ s->frame_size = frame_size;
+ } else {
+ /* if no frame size computed, signal it */
+ return 1;
+ }
+
+#if defined(DEBUG)
+ dprintf(s->avctx, "layer%d, %d Hz, %d kbits/s, ",
+ s->layer, s->sample_rate, s->bit_rate);
+ if (s->nb_channels == 2) {
+ if (s->layer == 3) {
+ if (s->mode_ext & MODE_EXT_MS_STEREO)
+ dprintf(s->avctx, "ms-");
+ if (s->mode_ext & MODE_EXT_I_STEREO)
+ dprintf(s->avctx, "i-");
+ }
+ dprintf(s->avctx, "stereo");
+ } else {
+ dprintf(s->avctx, "mono");
+ }
+ dprintf(s->avctx, "\n");
+#endif
+ return 0;
+}
+
+/* useful helper to get mpeg audio stream infos. Return -1 if error in
+ header, otherwise the coded frame size in bytes */
+int mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate)
+{
+ MPADecodeContext s1, *s = &s1;
+ s1.avctx = avctx;
+
+ if (ff_mpa_check_header(head) != 0)
+ return -1;
+
+ if (decode_header(s, head) != 0) {
+ return -1;
+ }
+
+ switch(s->layer) {
+ case 1:
+ avctx->frame_size = 384;
+ break;
+ case 2:
+ avctx->frame_size = 1152;
+ break;
+ default:
+ case 3:
+ if (s->lsf)
+ avctx->frame_size = 576;
+ else
+ avctx->frame_size = 1152;
+ break;
+ }
+
+ *sample_rate = s->sample_rate;
+ avctx->channels = s->nb_channels;
+ avctx->bit_rate = s->bit_rate;
+ avctx->sub_id = s->layer;
+ return s->frame_size;
+}
+
+/* return the number of decoded frames */
+static int mp_decode_layer1(MPADecodeContext *s)
+{
+ int bound, i, v, n, ch, j, mant;
+ uint8_t allocation[MPA_MAX_CHANNELS][SBLIMIT];
+ uint8_t scale_factors[MPA_MAX_CHANNELS][SBLIMIT];
+
+ if (s->mode == MPA_JSTEREO)
+ bound = (s->mode_ext + 1) * 4;
+ else
+ bound = SBLIMIT;
+
+ /* allocation bits */
+ for(i=0;i<bound;i++) {
+ for(ch=0;ch<s->nb_channels;ch++) {
+ allocation[ch][i] = get_bits(&s->gb, 4);
+ }
+ }
+ for(i=bound;i<SBLIMIT;i++) {
+ allocation[0][i] = get_bits(&s->gb, 4);
+ }
+
+ /* scale factors */
+ for(i=0;i<bound;i++) {
+ for(ch=0;ch<s->nb_channels;ch++) {
+ if (allocation[ch][i])
+ scale_factors[ch][i] = get_bits(&s->gb, 6);
+ }
+ }
+ for(i=bound;i<SBLIMIT;i++) {
+ if (allocation[0][i]) {
+ scale_factors[0][i] = get_bits(&s->gb, 6);
+ scale_factors[1][i] = get_bits(&s->gb, 6);
+ }
+ }
+
+ /* compute samples */
+ for(j=0;j<12;j++) {
+ for(i=0;i<bound;i++) {
+ for(ch=0;ch<s->nb_channels;ch++) {
+ n = allocation[ch][i];
+ if (n) {
+ mant = get_bits(&s->gb, n + 1);
+ v = l1_unscale(n, mant, scale_factors[ch][i]);
+ } else {
+ v = 0;
+ }
+ s->sb_samples[ch][j][i] = v;
+ }
+ }
+ for(i=bound;i<SBLIMIT;i++) {
+ n = allocation[0][i];
+ if (n) {
+ mant = get_bits(&s->gb, n + 1);
+ v = l1_unscale(n, mant, scale_factors[0][i]);
+ s->sb_samples[0][j][i] = v;
+ v = l1_unscale(n, mant, scale_factors[1][i]);
+ s->sb_samples[1][j][i] = v;
+ } else {
+ s->sb_samples[0][j][i] = 0;
+ s->sb_samples[1][j][i] = 0;
+ }
+ }
+ }
+ return 12;
+}
+
+/* bitrate is in kb/s */
+int l2_select_table(int bitrate, int nb_channels, int freq, int lsf)
+{
+ int ch_bitrate, table;
+
+ ch_bitrate = bitrate / nb_channels;
+ if (!lsf) {
+ if ((freq == 48000 && ch_bitrate >= 56) ||
+ (ch_bitrate >= 56 && ch_bitrate <= 80))
+ table = 0;
+ else if (freq != 48000 && ch_bitrate >= 96)
+ table = 1;
+ else if (freq != 32000 && ch_bitrate <= 48)
+ table = 2;
+ else
+ table = 3;
+ } else {
+ table = 4;
+ }
+ return table;
+}
+
+static int mp_decode_layer2(MPADecodeContext *s)
+{
+ int sblimit; /* number of used subbands */
+ const unsigned char *alloc_table;
+ int table, bit_alloc_bits, i, j, ch, bound, v;
+ unsigned char bit_alloc[MPA_MAX_CHANNELS][SBLIMIT];
+ unsigned char scale_code[MPA_MAX_CHANNELS][SBLIMIT];
+ unsigned char scale_factors[MPA_MAX_CHANNELS][SBLIMIT][3], *sf;
+ int scale, qindex, bits, steps, k, l, m, b;
+
+ /* select decoding table */
+ table = l2_select_table(s->bit_rate / 1000, s->nb_channels,
+ s->sample_rate, s->lsf);
+ sblimit = sblimit_table[table];
+ alloc_table = alloc_tables[table];
+
+ if (s->mode == MPA_JSTEREO)
+ bound = (s->mode_ext + 1) * 4;
+ else
+ bound = sblimit;
+
+ dprintf(s->avctx, "bound=%d sblimit=%d\n", bound, sblimit);
+
+ /* sanity check */
+ if( bound > sblimit ) bound = sblimit;
+
+ /* parse bit allocation */
+ j = 0;
+ for(i=0;i<bound;i++) {
+ bit_alloc_bits = alloc_table[j];
+ for(ch=0;ch<s->nb_channels;ch++) {
+ bit_alloc[ch][i] = get_bits(&s->gb, bit_alloc_bits);
+ }
+ j += 1 << bit_alloc_bits;
+ }
+ for(i=bound;i<sblimit;i++) {
+ bit_alloc_bits = alloc_table[j];
+ v = get_bits(&s->gb, bit_alloc_bits);
+ bit_alloc[0][i] = v;
+ bit_alloc[1][i] = v;
+ j += 1 << bit_alloc_bits;
+ }
+
+#ifdef DEBUG
+ {
+ for(ch=0;ch<s->nb_channels;ch++) {
+ for(i=0;i<sblimit;i++)
+ dprintf(s->avctx, " %d", bit_alloc[ch][i]);
+ dprintf(s->avctx, "\n");
+ }
+ }
+#endif
+
+ /* scale codes */
+ for(i=0;i<sblimit;i++) {
+ for(ch=0;ch<s->nb_channels;ch++) {
+ if (bit_alloc[ch][i])
+ scale_code[ch][i] = get_bits(&s->gb, 2);
+ }
+ }
+
+ /* scale factors */
+ for(i=0;i<sblimit;i++) {
+ for(ch=0;ch<s->nb_channels;ch++) {
+ if (bit_alloc[ch][i]) {
+ sf = scale_factors[ch][i];
+ switch(scale_code[ch][i]) {
+ default:
+ case 0:
+ sf[0] = get_bits(&s->gb, 6);
+ sf[1] = get_bits(&s->gb, 6);
+ sf[2] = get_bits(&s->gb, 6);
+ break;
+ case 2:
+ sf[0] = get_bits(&s->gb, 6);
+ sf[1] = sf[0];
+ sf[2] = sf[0];
+ break;
+ case 1:
+ sf[0] = get_bits(&s->gb, 6);
+ sf[2] = get_bits(&s->gb, 6);
+ sf[1] = sf[0];
+ break;
+ case 3:
+ sf[0] = get_bits(&s->gb, 6);
+ sf[2] = get_bits(&s->gb, 6);
+ sf[1] = sf[2];
+ break;
+ }
+ }
+ }
+ }
+
+#ifdef DEBUG
+ for(ch=0;ch<s->nb_channels;ch++) {
+ for(i=0;i<sblimit;i++) {
+ if (bit_alloc[ch][i]) {
+ sf = scale_factors[ch][i];
+ dprintf(s->avctx, " %d %d %d", sf[0], sf[1], sf[2]);
+ } else {
+ dprintf(s->avctx, " -");
+ }
+ }
+ dprintf(s->avctx, "\n");
+ }
+#endif
+
+ /* samples */
+ for(k=0;k<3;k++) {
+ for(l=0;l<12;l+=3) {
+ j = 0;
+ for(i=0;i<bound;i++) {
+ bit_alloc_bits = alloc_table[j];
+ for(ch=0;ch<s->nb_channels;ch++) {
+ b = bit_alloc[ch][i];
+ if (b) {
+ scale = scale_factors[ch][i][k];
+ qindex = alloc_table[j+b];
+ bits = quant_bits[qindex];
+ if (bits < 0) {
+ /* 3 values at the same time */
+ v = get_bits(&s->gb, -bits);
+ steps = quant_steps[qindex];
+ s->sb_samples[ch][k * 12 + l + 0][i] =
+ l2_unscale_group(steps, v % steps, scale);
+ v = v / steps;
+ s->sb_samples[ch][k * 12 + l + 1][i] =
+ l2_unscale_group(steps, v % steps, scale);
+ v = v / steps;
+ s->sb_samples[ch][k * 12 + l + 2][i] =
+ l2_unscale_group(steps, v, scale);
+ } else {
+ for(m=0;m<3;m++) {
+ v = get_bits(&s->gb, bits);
+ v = l1_unscale(bits - 1, v, scale);
+ s->sb_samples[ch][k * 12 + l + m][i] = v;
+ }
+ }
+ } else {
+ s->sb_samples[ch][k * 12 + l + 0][i] = 0;
+ s->sb_samples[ch][k * 12 + l + 1][i] = 0;
+ s->sb_samples[ch][k * 12 + l + 2][i] = 0;
+ }
+ }
+ /* next subband in alloc table */
+ j += 1 << bit_alloc_bits;
+ }
+ /* XXX: find a way to avoid this duplication of code */
+ for(i=bound;i<sblimit;i++) {
+ bit_alloc_bits = alloc_table[j];
+ b = bit_alloc[0][i];
+ if (b) {
+ int mant, scale0, scale1;
+ scale0 = scale_factors[0][i][k];
+ scale1 = scale_factors[1][i][k];
+ qindex = alloc_table[j+b];
+ bits = quant_bits[qindex];
+ if (bits < 0) {
+ /* 3 values at the same time */
+ v = get_bits(&s->gb, -bits);
+ steps = quant_steps[qindex];
+ mant = v % steps;
+ v = v / steps;
+ s->sb_samples[0][k * 12 + l + 0][i] =
+ l2_unscale_group(steps, mant, scale0);
+ s->sb_samples[1][k * 12 + l + 0][i] =
+ l2_unscale_group(steps, mant, scale1);
+ mant = v % steps;
+ v = v / steps;
+ s->sb_samples[0][k * 12 + l + 1][i] =
+ l2_unscale_group(steps, mant, scale0);
+ s->sb_samples[1][k * 12 + l + 1][i] =
+ l2_unscale_group(steps, mant, scale1);
+ s->sb_samples[0][k * 12 + l + 2][i] =
+ l2_unscale_group(steps, v, scale0);
+ s->sb_samples[1][k * 12 + l + 2][i] =
+ l2_unscale_group(steps, v, scale1);
+ } else {
+ for(m=0;m<3;m++) {
+ mant = get_bits(&s->gb, bits);
+ s->sb_samples[0][k * 12 + l + m][i] =
+ l1_unscale(bits - 1, mant, scale0);
+ s->sb_samples[1][k * 12 + l + m][i] =
+ l1_unscale(bits - 1, mant, scale1);
+ }
+ }
+ } else {
+ s->sb_samples[0][k * 12 + l + 0][i] = 0;
+ s->sb_samples[0][k * 12 + l + 1][i] = 0;
+ s->sb_samples[0][k * 12 + l + 2][i] = 0;
+ s->sb_samples[1][k * 12 + l + 0][i] = 0;
+ s->sb_samples[1][k * 12 + l + 1][i] = 0;
+ s->sb_samples[1][k * 12 + l + 2][i] = 0;
+ }
+ /* next subband in alloc table */
+ j += 1 << bit_alloc_bits;
+ }
+ /* fill remaining samples to zero */
+ for(i=sblimit;i<SBLIMIT;i++) {
+ for(ch=0;ch<s->nb_channels;ch++) {
+ s->sb_samples[ch][k * 12 + l + 0][i] = 0;
+ s->sb_samples[ch][k * 12 + l + 1][i] = 0;
+ s->sb_samples[ch][k * 12 + l + 2][i] = 0;
+ }
+ }
+ }
+ }
+ return 3 * 12;
+}
+
+static 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;
+ slen[0] = sf;
+}
+
+static void exponents_from_scale_factors(MPADecodeContext *s,
+ GranuleDef *g,
+ int16_t *exponents)
+{
+ const uint8_t *bstab, *pretab;
+ int len, i, j, k, l, v0, shift, gain, gains[3];
+ int16_t *exp_ptr;
+
+ exp_ptr = exponents;
+ gain = g->global_gain - 210;
+ shift = g->scalefac_scale + 1;
+
+ bstab = band_size_long[s->sample_rate_index];
+ pretab = mpa_pretab[g->preflag];
+ for(i=0;i<g->long_end;i++) {
+ v0 = gain - ((g->scale_factors[i] + pretab[i]) << shift) + 400;
+ len = bstab[i];
+ for(j=len;j>0;j--)
+ *exp_ptr++ = v0;
+ }
+
+ if (g->short_start < 13) {
+ bstab = band_size_short[s->sample_rate_index];
+ gains[0] = gain - (g->subblock_gain[0] << 3);
+ gains[1] = gain - (g->subblock_gain[1] << 3);
+ gains[2] = gain - (g->subblock_gain[2] << 3);
+ k = g->long_end;
+ for(i=g->short_start;i<13;i++) {
+ len = bstab[i];
+ for(l=0;l<3;l++) {
+ v0 = gains[l] - (g->scale_factors[k++] << shift) + 400;
+ for(j=len;j>0;j--)
+ *exp_ptr++ = v0;
+ }
+ }
+ }
+}
+
+/* handle n = 0 too */
+static inline int get_bitsz(GetBitContext *s, int n)
+{
+ if (n == 0)
+ return 0;
+ else
+ return get_bits(s, n);
+}
+
+
+static void switch_buffer(MPADecodeContext *s, int *pos, int *end_pos, int *end_pos2){
+ if(s->in_gb.buffer && *pos >= s->gb.size_in_bits){
+ s->gb= s->in_gb;
+ s->in_gb.buffer=NULL;
+ assert((get_bits_count(&s->gb) & 7) == 0);
+ skip_bits_long(&s->gb, *pos - *end_pos);
+ *end_pos2=
+ *end_pos= *end_pos2 + get_bits_count(&s->gb) - *pos;
+ *pos= get_bits_count(&s->gb);
+ }
+}
+
+static int huffman_decode(MPADecodeContext *s, GranuleDef *g,
+ int16_t *exponents, int end_pos2)
+{
+ int s_index;
+ int i;
+ int last_pos, bits_left;
+ VLC *vlc;
+ int end_pos= FFMIN(end_pos2, s->gb.size_in_bits);
+
+ /* low frequencies (called big values) */
+ s_index = 0;
+ for(i=0;i<3;i++) {
+ int j, k, l, linbits;
+ j = g->region_size[i];
+ if (j == 0)
+ continue;
+ /* select vlc table */
+ k = g->table_select[i];
+ l = mpa_huff_data[k][0];
+ linbits = mpa_huff_data[k][1];
+ vlc = &huff_vlc[l];
+
+ if(!l){
+ memset(&g->sb_hybrid[s_index], 0, sizeof(*g->sb_hybrid)*2*j);
+ s_index += 2*j;
+ continue;
+ }
+
+ /* read huffcode and compute each couple */
+ for(;j>0;j--) {
+ int exponent, x, y, v;
+ int pos= get_bits_count(&s->gb);
+
+ if (pos >= end_pos){
+// av_log(NULL, AV_LOG_ERROR, "pos: %d %d %d %d\n", pos, end_pos, end_pos2, s_index);
+ switch_buffer(s, &pos, &end_pos, &end_pos2);
+// av_log(NULL, AV_LOG_ERROR, "new pos: %d %d\n", pos, end_pos);
+ if(pos >= end_pos)
+ break;
+ }
+ y = get_vlc2(&s->gb, vlc->table, 7, 3);
+
+ if(!y){
+ g->sb_hybrid[s_index ] =
+ g->sb_hybrid[s_index+1] = 0;
+ s_index += 2;
+ continue;
+ }
+
+ exponent= exponents[s_index];
+
+ dprintf(s->avctx, "region=%d n=%d x=%d y=%d exp=%d\n",
+ i, g->region_size[i] - j, x, y, exponent);
+ if(y&16){
+ x = y >> 5;
+ y = y & 0x0f;
+ if (x < 15){
+ v = expval_table[ exponent ][ x ];
+// v = expval_table[ (exponent&3) ][ x ] >> FFMIN(0 - (exponent>>2), 31);
+ }else{
+ x += get_bitsz(&s->gb, linbits);
+ v = l3_unscale(x, exponent);
+ }
+ if (get_bits1(&s->gb))
+ v = -v;
+ g->sb_hybrid[s_index] = v;
+ if (y < 15){
+ v = expval_table[ exponent ][ y ];
+ }else{
+ y += get_bitsz(&s->gb, linbits);
+ v = l3_unscale(y, exponent);
+ }
+ if (get_bits1(&s->gb))
+ v = -v;
+ g->sb_hybrid[s_index+1] = v;
+ }else{
+ x = y >> 5;
+ y = y & 0x0f;
+ x += y;
+ if (x < 15){
+ v = expval_table[ exponent ][ x ];
+ }else{
+ x += get_bitsz(&s->gb, linbits);
+ v = l3_unscale(x, exponent);
+ }
+ if (get_bits1(&s->gb))
+ v = -v;
+ g->sb_hybrid[s_index+!!y] = v;
+ g->sb_hybrid[s_index+ !y] = 0;
+ }
+ s_index+=2;
+ }
+ }
+
+ /* high frequencies */
+ vlc = &huff_quad_vlc[g->count1table_select];
+ last_pos=0;
+ while (s_index <= 572) {
+ int pos, code;
+ pos = get_bits_count(&s->gb);
+ if (pos >= end_pos) {
+ if (pos > end_pos2 && last_pos){
+ /* some encoders generate an incorrect size for this
+ part. We must go back into the data */
+ s_index -= 4;
+ skip_bits_long(&s->gb, last_pos - pos);
+ av_log(NULL, AV_LOG_INFO, "overread, skip %d enddists: %d %d\n", last_pos - pos, end_pos-pos, end_pos2-pos);
+ if(s->error_resilience >= FF_ER_COMPLIANT)
+ s_index=0;
+ break;
+ }
+// av_log(NULL, AV_LOG_ERROR, "pos2: %d %d %d %d\n", pos, end_pos, end_pos2, s_index);
+ switch_buffer(s, &pos, &end_pos, &end_pos2);
+// av_log(NULL, AV_LOG_ERROR, "new pos2: %d %d %d\n", pos, end_pos, s_index);
+ if(pos >= end_pos)
+ break;
+ }
+ last_pos= pos;
+
+ code = get_vlc2(&s->gb, vlc->table, vlc->bits, 1);
+ dprintf(s->avctx, "t=%d code=%d\n", g->count1table_select, code);
+ g->sb_hybrid[s_index+0]=
+ g->sb_hybrid[s_index+1]=
+ g->sb_hybrid[s_index+2]=
+ g->sb_hybrid[s_index+3]= 0;
+ while(code){
+ const static int idxtab[16]={3,3,2,2,1,1,1,1,0,0,0,0,0,0,0,0};
+ int v;
+ int pos= s_index+idxtab[code];
+ code ^= 8>>idxtab[code];
+ v = exp_table[ exponents[pos] ];
+// v = exp_table[ (exponents[pos]&3) ] >> FFMIN(0 - (exponents[pos]>>2), 31);
+ if(get_bits1(&s->gb))
+ v = -v;
+ g->sb_hybrid[pos] = v;
+ }
+ s_index+=4;
+ }
+ /* skip extension bits */
+ bits_left = end_pos2 - get_bits_count(&s->gb);
+//av_log(NULL, AV_LOG_ERROR, "left:%d buf:%p\n", bits_left, s->in_gb.buffer);
+ if (bits_left < 0/* || bits_left > 500*/) {
+ av_log(NULL, AV_LOG_ERROR, "bits_left=%d\n", bits_left);
+ s_index=0;
+ }else if(bits_left > 0 && s->error_resilience >= FF_ER_AGGRESSIVE){
+ av_log(NULL, AV_LOG_ERROR, "bits_left=%d\n", bits_left);
+ s_index=0;
+ }
+ memset(&g->sb_hybrid[s_index], 0, sizeof(*g->sb_hybrid)*(576 - s_index));
+ skip_bits_long(&s->gb, bits_left);
+
+ i= get_bits_count(&s->gb);
+ switch_buffer(s, &i, &end_pos, &end_pos2);
+
+ return 0;
+}
+
+/* Reorder short blocks from bitstream order to interleaved order. It
+ would be faster to do it in parsing, but the code would be far more
+ complicated */
+static void reorder_block(MPADecodeContext *s, GranuleDef *g)
+{
+ int i, j, len;
+ int32_t *ptr, *dst, *ptr1;
+ int32_t tmp[576];
+
+ if (g->block_type != 2)
+ return;
+
+ if (g->switch_point) {
+ if (s->sample_rate_index != 8) {
+ ptr = g->sb_hybrid + 36;
+ } else {
+ ptr = g->sb_hybrid + 48;
+ }
+ } else {
+ ptr = g->sb_hybrid;
+ }
+
+ for(i=g->short_start;i<13;i++) {
+ len = band_size_short[s->sample_rate_index][i];
+ ptr1 = ptr;
+ dst = tmp;
+ for(j=len;j>0;j--) {
+ *dst++ = ptr[0*len];
+ *dst++ = ptr[1*len];
+ *dst++ = ptr[2*len];
+ ptr++;
+ }
+ ptr+=2*len;
+ memcpy(ptr1, tmp, len * 3 * sizeof(*ptr1));
+ }
+}
+
+#define ISQRT2 FIXR(0.70710678118654752440)
+
+static void compute_stereo(MPADecodeContext *s,
+ GranuleDef *g0, GranuleDef *g1)
+{
+ int i, j, k, l;
+ int32_t v1, v2;
+ int sf_max, tmp0, tmp1, sf, len, non_zero_found;
+ int32_t (*is_tab)[16];
+ int32_t *tab0, *tab1;
+ int non_zero_found_short[3];
+
+ /* intensity stereo */
+ if (s->mode_ext & MODE_EXT_I_STEREO) {
+ if (!s->lsf) {
+ is_tab = is_table;
+ sf_max = 7;
+ } else {
+ is_tab = is_table_lsf[g1->scalefac_compress & 1];
+ sf_max = 16;
+ }
+
+ tab0 = g0->sb_hybrid + 576;
+ tab1 = g1->sb_hybrid + 576;
+
+ non_zero_found_short[0] = 0;
+ non_zero_found_short[1] = 0;
+ non_zero_found_short[2] = 0;
+ k = (13 - g1->short_start) * 3 + g1->long_end - 3;
+ for(i = 12;i >= g1->short_start;i--) {
+ /* for last band, use previous scale factor */
+ if (i != 11)
+ k -= 3;
+ len = band_size_short[s->sample_rate_index][i];
+ for(l=2;l>=0;l--) {
+ tab0 -= len;
+ tab1 -= len;
+ if (!non_zero_found_short[l]) {
+ /* test if non zero band. if so, stop doing i-stereo */
+ for(j=0;j<len;j++) {
+ if (tab1[j] != 0) {
+ non_zero_found_short[l] = 1;
+ goto found1;
+ }
+ }
+ sf = g1->scale_factors[k + l];
+ if (sf >= sf_max)
+ goto found1;
+
+ v1 = is_tab[0][sf];
+ v2 = is_tab[1][sf];
+ for(j=0;j<len;j++) {
+ tmp0 = tab0[j];
+ tab0[j] = MULL(tmp0, v1);
+ tab1[j] = MULL(tmp0, v2);
+ }
+ } else {
+ found1:
+ if (s->mode_ext & MODE_EXT_MS_STEREO) {
+ /* lower part of the spectrum : do ms stereo
+ if enabled */
+ for(j=0;j<len;j++) {
+ tmp0 = tab0[j];
+ tmp1 = tab1[j];
+ tab0[j] = MULL(tmp0 + tmp1, ISQRT2);
+ tab1[j] = MULL(tmp0 - tmp1, ISQRT2);
+ }
+ }
+ }
+ }
+ }
+
+ non_zero_found = non_zero_found_short[0] |
+ non_zero_found_short[1] |
+ non_zero_found_short[2];
+
+ for(i = g1->long_end - 1;i >= 0;i--) {
+ len = band_size_long[s->sample_rate_index][i];
+ tab0 -= len;
+ tab1 -= len;
+ /* test if non zero band. if so, stop doing i-stereo */
+ if (!non_zero_found) {
+ for(j=0;j<len;j++) {
+ if (tab1[j] != 0) {
+ non_zero_found = 1;
+ goto found2;
+ }
+ }
+ /* for last band, use previous scale factor */
+ k = (i == 21) ? 20 : i;
+ sf = g1->scale_factors[k];
+ if (sf >= sf_max)
+ goto found2;
+ v1 = is_tab[0][sf];
+ v2 = is_tab[1][sf];
+ for(j=0;j<len;j++) {
+ tmp0 = tab0[j];
+ tab0[j] = MULL(tmp0, v1);
+ tab1[j] = MULL(tmp0, v2);
+ }
+ } else {
+ found2:
+ if (s->mode_ext & MODE_EXT_MS_STEREO) {
+ /* lower part of the spectrum : do ms stereo
+ if enabled */
+ for(j=0;j<len;j++) {
+ tmp0 = tab0[j];
+ tmp1 = tab1[j];
+ tab0[j] = MULL(tmp0 + tmp1, ISQRT2);
+ tab1[j] = MULL(tmp0 - tmp1, ISQRT2);
+ }
+ }
+ }
+ }
+ } else if (s->mode_ext & MODE_EXT_MS_STEREO) {
+ /* ms stereo ONLY */
+ /* NOTE: the 1/sqrt(2) normalization factor is included in the
+ global gain */
+ tab0 = g0->sb_hybrid;
+ tab1 = g1->sb_hybrid;
+ for(i=0;i<576;i++) {
+ tmp0 = tab0[i];
+ tmp1 = tab1[i];
+ tab0[i] = tmp0 + tmp1;
+ tab1[i] = tmp0 - tmp1;
+ }
+ }
+}
+
+static void compute_antialias_integer(MPADecodeContext *s,
+ GranuleDef *g)
+{
+ int32_t *ptr, *csa;
+ int n, i;
+
+ /* we antialias only "long" bands */
+ if (g->block_type == 2) {
+ if (!g->switch_point)
+ return;
+ /* XXX: check this for 8000Hz case */
+ n = 1;
+ } else {
+ n = SBLIMIT - 1;
+ }
+
+ ptr = g->sb_hybrid + 18;
+ for(i = n;i > 0;i--) {
+ int tmp0, tmp1, tmp2;
+ csa = &csa_table[0][0];
+#define INT_AA(j) \
+ tmp0 = ptr[-1-j];\
+ tmp1 = ptr[ j];\
+ tmp2= MULH(tmp0 + tmp1, csa[0+4*j]);\
+ ptr[-1-j] = 4*(tmp2 - MULH(tmp1, csa[2+4*j]));\
+ ptr[ j] = 4*(tmp2 + MULH(tmp0, csa[3+4*j]));
+
+ INT_AA(0)
+ INT_AA(1)
+ INT_AA(2)
+ INT_AA(3)
+ INT_AA(4)
+ INT_AA(5)
+ INT_AA(6)
+ INT_AA(7)
+
+ ptr += 18;
+ }
+}
+
+static void compute_antialias_float(MPADecodeContext *s,
+ GranuleDef *g)
+{
+ int32_t *ptr;
+ int n, i;
+
+ /* we antialias only "long" bands */
+ if (g->block_type == 2) {
+ if (!g->switch_point)
+ return;
+ /* XXX: check this for 8000Hz case */
+ n = 1;
+ } else {
+ n = SBLIMIT - 1;
+ }
+
+ ptr = g->sb_hybrid + 18;
+ for(i = n;i > 0;i--) {
+ float tmp0, tmp1;
+ float *csa = &csa_table_float[0][0];
+#define FLOAT_AA(j)\
+ tmp0= ptr[-1-j];\
+ tmp1= ptr[ j];\
+ ptr[-1-j] = lrintf(tmp0 * csa[0+4*j] - tmp1 * csa[1+4*j]);\
+ ptr[ j] = lrintf(tmp0 * csa[1+4*j] + tmp1 * csa[0+4*j]);
+
+ FLOAT_AA(0)
+ FLOAT_AA(1)
+ FLOAT_AA(2)
+ FLOAT_AA(3)
+ FLOAT_AA(4)
+ FLOAT_AA(5)
+ FLOAT_AA(6)
+ FLOAT_AA(7)
+
+ ptr += 18;
+ }
+}
+
+static void compute_imdct(MPADecodeContext *s,
+ GranuleDef *g,
+ int32_t *sb_samples,
+ int32_t *mdct_buf)
+{
+ int32_t *ptr, *win, *win1, *buf, *out_ptr, *ptr1;
+ int32_t out2[12];
+ int i, j, mdct_long_end, v, sblimit;
+
+ /* find last non zero block */
+ ptr = g->sb_hybrid + 576;
+ ptr1 = g->sb_hybrid + 2 * 18;
+ while (ptr >= ptr1) {
+ ptr -= 6;
+ v = ptr[0] | ptr[1] | ptr[2] | ptr[3] | ptr[4] | ptr[5];
+ if (v != 0)
+ break;
+ }
+ sblimit = ((ptr - g->sb_hybrid) / 18) + 1;
+
+ if (g->block_type == 2) {
+ /* XXX: check for 8000 Hz */
+ if (g->switch_point)
+ mdct_long_end = 2;
+ else
+ mdct_long_end = 0;
+ } else {
+ mdct_long_end = sblimit;
+ }
+
+ buf = mdct_buf;
+ ptr = g->sb_hybrid;
+ for(j=0;j<mdct_long_end;j++) {
+ /* apply window & overlap with previous buffer */
+ out_ptr = sb_samples + j;
+ /* select window */
+ if (g->switch_point && j < 2)
+ win1 = mdct_win[0];
+ else
+ win1 = mdct_win[g->block_type];
+ /* select frequency inversion */
+ win = win1 + ((4 * 36) & -(j & 1));
+ imdct36(out_ptr, buf, ptr, win);
+ out_ptr += 18*SBLIMIT;
+ ptr += 18;
+ buf += 18;
+ }
+ for(j=mdct_long_end;j<sblimit;j++) {
+ /* select frequency inversion */
+ win = mdct_win[2] + ((4 * 36) & -(j & 1));
+ out_ptr = sb_samples + j;
+
+ for(i=0; i<6; i++){
+ *out_ptr = buf[i];
+ out_ptr += SBLIMIT;
+ }
+ imdct12(out2, ptr + 0);
+ for(i=0;i<6;i++) {
+ *out_ptr = MULH(out2[i], win[i]) + buf[i + 6*1];
+ buf[i + 6*2] = MULH(out2[i + 6], win[i + 6]);
+ out_ptr += SBLIMIT;
+ }
+ imdct12(out2, ptr + 1);
+ for(i=0;i<6;i++) {
+ *out_ptr = MULH(out2[i], win[i]) + buf[i + 6*2];
+ buf[i + 6*0] = MULH(out2[i + 6], win[i + 6]);
+ out_ptr += SBLIMIT;
+ }
+ imdct12(out2, ptr + 2);
+ for(i=0;i<6;i++) {
+ buf[i + 6*0] = MULH(out2[i], win[i]) + buf[i + 6*0];
+ buf[i + 6*1] = MULH(out2[i + 6], win[i + 6]);
+ buf[i + 6*2] = 0;
+ }
+ ptr += 18;
+ buf += 18;
+ }
+ /* zero bands */
+ for(j=sblimit;j<SBLIMIT;j++) {
+ /* overlap */
+ out_ptr = sb_samples + j;
+ for(i=0;i<18;i++) {
+ *out_ptr = buf[i];
+ buf[i] = 0;
+ out_ptr += SBLIMIT;
+ }
+ buf += 18;
+ }
+}
+
+#if defined(DEBUG)
+void sample_dump(int fnum, int32_t *tab, int n)
+{
+ static FILE *files[16], *f;
+ char buf[512];
+ int i;
+ int32_t v;
+
+ f = files[fnum];
+ if (!f) {
+ snprintf(buf, sizeof(buf), "/tmp/out%d.%s.pcm",
+ fnum,
+#ifdef USE_HIGHPRECISION
+ "hp"
+#else
+ "lp"
+#endif
+ );
+ f = fopen(buf, "w");
+ if (!f)
+ return;
+ files[fnum] = f;
+ }
+
+ if (fnum == 0) {
+ static int pos = 0;
+ av_log(NULL, AV_LOG_DEBUG, "pos=%d\n", pos);
+ for(i=0;i<n;i++) {
+ av_log(NULL, AV_LOG_DEBUG, " %0.4f", (double)tab[i] / FRAC_ONE);
+ if ((i % 18) == 17)
+ av_log(NULL, AV_LOG_DEBUG, "\n");
+ }
+ pos += n;
+ }
+ for(i=0;i<n;i++) {
+ /* normalize to 23 frac bits */
+ v = tab[i] << (23 - FRAC_BITS);
+ fwrite(&v, 1, sizeof(int32_t), f);
+ }
+}
+#endif
+
+
+/* main layer3 decoding function */
+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;
+ int16_t exponents[576];
+
+ /* read side info */
+ if (s->lsf) {
+ main_data_begin = get_bits(&s->gb, 8);
+ private_bits = get_bits(&s->gb, s->nb_channels);
+ nb_granules = 1;
+ } else {
+ main_data_begin = get_bits(&s->gb, 9);
+ if (s->nb_channels == 2)
+ private_bits = get_bits(&s->gb, 3);
+ else
+ private_bits = get_bits(&s->gb, 5);
+ nb_granules = 2;
+ for(ch=0;ch<s->nb_channels;ch++) {
+ granules[ch][0].scfsi = 0; /* all scale factors are transmitted */
+ granules[ch][1].scfsi = get_bits(&s->gb, 4);
+ }
+ }
+
+ for(gr=0;gr<nb_granules;gr++) {
+ for(ch=0;ch<s->nb_channels;ch++) {
+ dprintf(s->avctx, "gr=%d ch=%d: side_info\n", gr, ch);
+ g = &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){
+ av_log(s->avctx, AV_LOG_ERROR, "big_values too big\n");
+ return -1;
+ }
+
+ g->global_gain = get_bits(&s->gb, 8);
+ /* if MS stereo only is selected, we precompute the
+ 1/sqrt(2) renormalization factor */
+ if ((s->mode_ext & (MODE_EXT_MS_STEREO | MODE_EXT_I_STEREO)) ==
+ MODE_EXT_MS_STEREO)
+ g->global_gain -= 2;
+ if (s->lsf)
+ g->scalefac_compress = get_bits(&s->gb, 9);
+ else
+ g->scalefac_compress = get_bits(&s->gb, 4);
+ blocksplit_flag = get_bits(&s->gb, 1);
+ if (blocksplit_flag) {
+ g->block_type = get_bits(&s->gb, 2);
+ if (g->block_type == 0){
+ av_log(NULL, AV_LOG_ERROR, "invalid block type\n");
+ return -1;
+ }
+ g->switch_point = get_bits(&s->gb, 1);
+ for(i=0;i<2;i++)
+ g->table_select[i] = get_bits(&s->gb, 5);
+ for(i=0;i<3;i++)
+ g->subblock_gain[i] = get_bits(&s->gb, 3);
+ /* compute huffman coded region sizes */
+ if (g->block_type == 2)
+ g->region_size[0] = (36 / 2);
+ else {
+ if (s->sample_rate_index <= 2)
+ g->region_size[0] = (36 / 2);
+ else if (s->sample_rate_index != 8)
+ g->region_size[0] = (54 / 2);
+ else
+ g->region_size[0] = (108 / 2);
+ }
+ g->region_size[1] = (576 / 2);
+ } else {
+ int region_address1, region_address2, l;
+ g->block_type = 0;
+ g->switch_point = 0;
+ for(i=0;i<3;i++)
+ g->table_select[i] = get_bits(&s->gb, 5);
+ /* compute huffman coded region sizes */
+ region_address1 = get_bits(&s->gb, 4);
+ region_address2 = get_bits(&s->gb, 3);
+ dprintf(s->avctx, "region1=%d region2=%d\n",
+ region_address1, region_address2);
+ g->region_size[0] =
+ band_index_long[s->sample_rate_index][region_address1 + 1] >> 1;
+ l = region_address1 + region_address2 + 2;
+ /* should not overflow */
+ if (l > 22)
+ l = 22;
+ g->region_size[1] =
+ band_index_long[s->sample_rate_index][l] >> 1;
+ }
+ /* convert region offsets to region sizes and truncate
+ size to big_values */
+ g->region_size[2] = (576 / 2);
+ j = 0;
+ for(i=0;i<3;i++) {
+ k = FFMIN(g->region_size[i], g->big_values);
+ g->region_size[i] = k - j;
+ j = k;
+ }
+
+ /* compute band indexes */
+ if (g->block_type == 2) {
+ if (g->switch_point) {
+ /* if switched mode, we handle the 36 first samples as
+ long blocks. For 8000Hz, we handle the 48 first
+ exponents as long blocks (XXX: check this!) */
+ if (s->sample_rate_index <= 2)
+ g->long_end = 8;
+ else if (s->sample_rate_index != 8)
+ g->long_end = 6;
+ else
+ g->long_end = 4; /* 8000 Hz */
+
+ g->short_start = 2 + (s->sample_rate_index != 8);
+ } else {
+ g->long_end = 0;
+ g->short_start = 0;
+ }
+ } else {
+ g->short_start = 13;
+ g->long_end = 22;
+ }
+
+ g->preflag = 0;
+ if (!s->lsf)
+ g->preflag = get_bits(&s->gb, 1);
+ g->scalefac_scale = get_bits(&s->gb, 1);
+ g->count1table_select = get_bits(&s->gb, 1);
+ dprintf(s->avctx, "block_type=%d switch_point=%d\n",
+ g->block_type, g->switch_point);
+ }
+ }
+
+ if (!s->adu_mode) {
+ const uint8_t *ptr = s->gb.buffer + (get_bits_count(&s->gb)>>3);
+ assert((get_bits_count(&s->gb) & 7) == 0);
+ /* now we get bits from the main_data_begin offset */
+ dprintf(s->avctx, "seekback: %d\n", main_data_begin);
+//av_log(NULL, AV_LOG_ERROR, "backstep:%d, lastbuf:%d\n", main_data_begin, s->last_buf_size);
+
+ memcpy(s->last_buf + s->last_buf_size, ptr, EXTRABYTES);
+ s->in_gb= s->gb;
+ init_get_bits(&s->gb, s->last_buf, s->last_buf_size*8);
+ skip_bits_long(&s->gb, 8*(s->last_buf_size - main_data_begin));
+ }
+
+ for(gr=0;gr<nb_granules;gr++) {
+ for(ch=0;ch<s->nb_channels;ch++) {
+ g = &granules[ch][gr];
+ if(get_bits_count(&s->gb)<0){
+ av_log(NULL, AV_LOG_ERROR, "mdb:%d, lastbuf:%d skiping 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));
+ if(get_bits_count(&s->gb) >= s->gb.size_in_bits && s->in_gb.buffer){
+ skip_bits_long(&s->in_gb, get_bits_count(&s->gb) - s->gb.size_in_bits);
+ s->gb= s->in_gb;
+ s->in_gb.buffer=NULL;
+ }
+ continue;
+ }
+
+ bits_pos = get_bits_count(&s->gb);
+
+ if (!s->lsf) {
+ uint8_t *sc;
+ int slen, slen1, slen2;
+
+ /* MPEG1 scale factors */
+ slen1 = slen_table[0][g->scalefac_compress];
+ slen2 = slen_table[1][g->scalefac_compress];
+ dprintf(s->avctx, "slen1=%d slen2=%d\n", slen1, slen2);
+ if (g->block_type == 2) {
+ n = g->switch_point ? 17 : 18;
+ j = 0;
+ if(slen1){
+ for(i=0;i<n;i++)
+ g->scale_factors[j++] = get_bits(&s->gb, slen1);
+ }else{
+ for(i=0;i<n;i++)
+ g->scale_factors[j++] = 0;
+ }
+ if(slen2){
+ for(i=0;i<18;i++)
+ g->scale_factors[j++] = get_bits(&s->gb, slen2);
+ for(i=0;i<3;i++)
+ g->scale_factors[j++] = 0;
+ }else{
+ for(i=0;i<21;i++)
+ g->scale_factors[j++] = 0;
+ }
+ } else {
+ sc = granules[ch][0].scale_factors;
+ j = 0;
+ for(k=0;k<4;k++) {
+ n = (k == 0 ? 6 : 5);
+ if ((g->scfsi & (0x8 >> k)) == 0) {
+ slen = (k < 2) ? slen1 : slen2;
+ if(slen){
+ for(i=0;i<n;i++)
+ g->scale_factors[j++] = get_bits(&s->gb, slen);
+ }else{
+ for(i=0;i<n;i++)
+ g->scale_factors[j++] = 0;
+ }
+ } else {
+ /* simply copy from last granule */
+ for(i=0;i<n;i++) {
+ g->scale_factors[j] = sc[j];
+ j++;
+ }
+ }
+ }
+ g->scale_factors[j++] = 0;
+ }
+#if defined(DEBUG)
+ {
+ dprintf(s->avctx, "scfsi=%x gr=%d ch=%d scale_factors:\n",
+ g->scfsi, gr, ch);
+ for(i=0;i<j;i++)
+ dprintf(s->avctx, " %d", g->scale_factors[i]);
+ dprintf(s->avctx, "\n");
+ }
+#endif
+ } else {
+ int tindex, tindex2, slen[4], sl, sf;
+
+ /* LSF scale factors */
+ if (g->block_type == 2) {
+ tindex = g->switch_point ? 2 : 1;
+ } else {
+ tindex = 0;
+ }
+ sf = g->scalefac_compress;
+ if ((s->mode_ext & MODE_EXT_I_STEREO) && ch == 1) {
+ /* intensity stereo case */
+ sf >>= 1;
+ if (sf < 180) {
+ lsf_sf_expand(slen, sf, 6, 6, 0);
+ tindex2 = 3;
+ } else if (sf < 244) {
+ lsf_sf_expand(slen, sf - 180, 4, 4, 0);
+ tindex2 = 4;
+ } else {
+ lsf_sf_expand(slen, sf - 244, 3, 0, 0);
+ tindex2 = 5;
+ }
+ } else {
+ /* normal case */
+ if (sf < 400) {
+ lsf_sf_expand(slen, sf, 5, 4, 4);
+ tindex2 = 0;
+ } else if (sf < 500) {
+ lsf_sf_expand(slen, sf - 400, 5, 4, 0);
+ tindex2 = 1;
+ } else {
+ lsf_sf_expand(slen, sf - 500, 3, 0, 0);
+ tindex2 = 2;
+ g->preflag = 1;
+ }
+ }
+
+ j = 0;
+ for(k=0;k<4;k++) {
+ n = lsf_nsf_table[tindex2][tindex][k];
+ sl = slen[k];
+ if(sl){
+ for(i=0;i<n;i++)
+ g->scale_factors[j++] = get_bits(&s->gb, sl);
+ }else{
+ for(i=0;i<n;i++)
+ g->scale_factors[j++] = 0;
+ }
+ }
+ /* XXX: should compute exact size */
+ for(;j<40;j++)
+ g->scale_factors[j] = 0;
+#if defined(DEBUG)
+ {
+ dprintf(s->avctx, "gr=%d ch=%d scale_factors:\n",
+ gr, ch);
+ for(i=0;i<40;i++)
+ dprintf(s->avctx, " %d", g->scale_factors[i]);
+ dprintf(s->avctx, "\n");
+ }
+#endif
+ }
+
+ exponents_from_scale_factors(s, g, exponents);
+
+ /* read Huffman coded residue */
+ huffman_decode(s, g, exponents, bits_pos + g->part2_3_length);
+#if defined(DEBUG)
+ sample_dump(0, g->sb_hybrid, 576);
+#endif
+ } /* ch */
+
+ if (s->nb_channels == 2)
+ compute_stereo(s, &granules[0][gr], &granules[1][gr]);
+
+ for(ch=0;ch<s->nb_channels;ch++) {
+ g = &granules[ch][gr];
+
+ reorder_block(s, g);
+#if defined(DEBUG)
+ sample_dump(0, g->sb_hybrid, 576);
+#endif
+ s->compute_antialias(s, g);
+#if defined(DEBUG)
+ sample_dump(1, g->sb_hybrid, 576);
+#endif
+ compute_imdct(s, g, &s->sb_samples[ch][18 * gr][0], s->mdct_buf[ch]);
+#if defined(DEBUG)
+ sample_dump(2, &s->sb_samples[ch][18 * gr][0], 576);
+#endif
+ }
+ } /* gr */
+ if(get_bits_count(&s->gb)<0)
+ skip_bits_long(&s->gb, -get_bits_count(&s->gb));
+ return nb_granules * 18;
+}
+
+static int mp_decode_frame(MPADecodeContext *s,
+ OUT_INT *samples, const uint8_t *buf, int buf_size)
+{
+ int i, nb_frames, ch;
+ OUT_INT *samples_ptr;
+
+ init_get_bits(&s->gb, buf + HEADER_SIZE, (buf_size - HEADER_SIZE)*8);
+
+ /* skip error protection field */
+ if (s->error_protection)
+ get_bits(&s->gb, 16);
+
+ dprintf(s->avctx, "frame %d:\n", s->frame_count);
+ switch(s->layer) {
+ case 1:
+ nb_frames = mp_decode_layer1(s);
+ break;
+ case 2:
+ nb_frames = mp_decode_layer2(s);
+ break;
+ case 3:
+ default:
+ nb_frames = mp_decode_layer3(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;
+ 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;
+ }else
+ av_log(NULL, AV_LOG_ERROR, "invalid old backstep %d\n", i);
+ s->gb= s->in_gb;
+ s->in_gb.buffer= NULL;
+ }
+
+ 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;
+
+ if(i<0 || i > BACKSTEP_SIZE || nb_frames<0){
+ av_log(NULL, AV_LOG_ERROR, "invalid new backstep %d\n", i);
+ i= FFMIN(BACKSTEP_SIZE, buf_size - HEADER_SIZE);
+ }
+ assert(i <= buf_size - HEADER_SIZE && i>= 0);
+ memcpy(s->last_buf + s->last_buf_size, s->gb.buffer + buf_size - HEADER_SIZE - i, i);
+ s->last_buf_size += i;
+
+ break;
+ }
+#if defined(DEBUG)
+ for(i=0;i<nb_frames;i++) {
+ for(ch=0;ch<s->nb_channels;ch++) {
+ int j;
+ dprintf(s->avctx, "%d-%d:", i, ch);
+ for(j=0;j<SBLIMIT;j++)
+ dprintf(s->avctx, " %0.6f", (double)s->sb_samples[ch][i][j] / FRAC_ONE);
+ dprintf(s->avctx, "\n");
+ }
+ }
+#endif
+ /* apply the synthesis filter */
+ for(ch=0;ch<s->nb_channels;ch++) {
+ samples_ptr = samples + ch;
+ for(i=0;i<nb_frames;i++) {
+ ff_mpa_synth_filter(s->synth_buf[ch], &(s->synth_buf_offset[ch]),
+ window, &s->dither_state,
+ samples_ptr, s->nb_channels,
+ s->sb_samples[ch][i]);
+ samples_ptr += 32 * s->nb_channels;
+ }
+ }
+#ifdef DEBUG
+ s->frame_count++;
+#endif
+ return nb_frames * 32 * sizeof(OUT_INT) * s->nb_channels;
+}
+
+static int decode_frame(AVCodecContext * avctx,
+ void *data, int *data_size,
+ uint8_t * buf, int buf_size)
+{
+ MPADecodeContext *s = avctx->priv_data;
+ uint32_t header;
+ int out_size;
+ OUT_INT *out_samples = data;
+
+retry:
+ if(buf_size < HEADER_SIZE)
+ return -1;
+
+ header = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
+ if(ff_mpa_check_header(header) < 0){
+ buf++;
+// buf_size--;
+ av_log(avctx, AV_LOG_ERROR, "Header missing skipping one byte.\n");
+ goto retry;
+ }
+
+ if (decode_header(s, header) == 1) {
+ /* free format: prepare to compute frame size */
+ s->frame_size = -1;
+ return -1;
+ }
+ /* update codec info */
+ avctx->channels = s->nb_channels;
+ avctx->bit_rate = s->bit_rate;
+ avctx->sub_id = s->layer;
+ switch(s->layer) {
+ case 1:
+ avctx->frame_size = 384;
+ break;
+ case 2:
+ avctx->frame_size = 1152;
+ break;
+ case 3:
+ if (s->lsf)
+ avctx->frame_size = 576;
+ else
+ avctx->frame_size = 1152;
+ break;
+ }
+
+ if(s->frame_size<=0 || s->frame_size > buf_size){
+ av_log(avctx, AV_LOG_ERROR, "incomplete frame\n");
+ return -1;
+ }else if(s->frame_size < buf_size){
+ av_log(avctx, AV_LOG_ERROR, "incorrect frame size\n");
+ }
+
+ out_size = mp_decode_frame(s, out_samples, buf, buf_size);
+ if(out_size>=0){
+ *data_size = out_size;
+ avctx->sample_rate = s->sample_rate;
+ //FIXME maybe move the other codec info stuff from above here too
+ }else
+ av_log(avctx, AV_LOG_DEBUG, "Error while decoding MPEG audio frame.\n"); //FIXME return -1 / but also return the number of bytes consumed
+ s->frame_size = 0;
+ return buf_size;
+}
+
+static void flush(AVCodecContext *avctx){
+ MPADecodeContext *s = avctx->priv_data;
+ s->last_buf_size= 0;
+}
+
+#ifdef CONFIG_MP3ADU_DECODER
+static int decode_frame_adu(AVCodecContext * avctx,
+ void *data, int *data_size,
+ uint8_t * buf, int buf_size)
+{
+ MPADecodeContext *s = avctx->priv_data;
+ uint32_t header;
+ int len, out_size;
+ OUT_INT *out_samples = data;
+
+ len = buf_size;
+
+ // Discard too short frames
+ if (buf_size < HEADER_SIZE) {
+ *data_size = 0;
+ return buf_size;
+ }
+
+
+ if (len > MPA_MAX_CODED_FRAME_SIZE)
+ len = MPA_MAX_CODED_FRAME_SIZE;
+
+ // Get header and restore sync word
+ header = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3] | 0xffe00000;
+
+ if (ff_mpa_check_header(header) < 0) { // Bad header, discard frame
+ *data_size = 0;
+ return buf_size;
+ }
+
+ decode_header(s, header);
+ /* update codec info */
+ avctx->sample_rate = s->sample_rate;
+ avctx->channels = s->nb_channels;
+ avctx->bit_rate = s->bit_rate;
+ avctx->sub_id = s->layer;
+
+ avctx->frame_size=s->frame_size = len;
+
+ if (avctx->parse_only) {
+ out_size = buf_size;
+ } else {
+ out_size = mp_decode_frame(s, out_samples, buf, buf_size);
+ }
+
+ *data_size = out_size;
+ return buf_size;
+}
+#endif /* CONFIG_MP3ADU_DECODER */
+
+#ifdef CONFIG_MP3ON4_DECODER
+/* Next 3 arrays are indexed by channel config number (passed via codecdata) */
+static int mp3Frames[16] = {0,1,1,2,3,3,4,5,2}; /* number of mp3 decoder instances */
+static int mp3Channels[16] = {0,1,2,3,4,5,6,8,4}; /* total output channels */
+/* offsets into output buffer, assume output order is FL FR BL BR C LFE */
+static int chan_offset[9][5] = {
+ {0},
+ {0}, // C
+ {0}, // FLR
+ {2,0}, // C FLR
+ {2,0,3}, // C FLR BS
+ {4,0,2}, // C FLR BLRS
+ {4,0,2,5}, // C FLR BLRS LFE
+ {4,0,2,6,5}, // C FLR BLRS BLR LFE
+ {0,2} // FLR BLRS
+};
+
+
+static int decode_init_mp3on4(AVCodecContext * avctx)
+{
+ MP3On4DecodeContext *s = avctx->priv_data;
+ int i;
+
+ if ((avctx->extradata_size < 2) || (avctx->extradata == NULL)) {
+ av_log(avctx, AV_LOG_ERROR, "Codec extradata missing or too short.\n");
+ return -1;
+ }
+
+ s->chan_cfg = (((unsigned char *)avctx->extradata)[1] >> 3) & 0x0f;
+ s->frames = mp3Frames[s->chan_cfg];
+ if(!s->frames) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid channel config number.\n");
+ return -1;
+ }
+ avctx->channels = mp3Channels[s->chan_cfg];
+
+ /* Init the first mp3 decoder in standard way, so that all tables get builded
+ * We replace avctx->priv_data with the context of the first decoder so that
+ * decode_init() does not have to be changed.
+ * Other decoders will be inited here copying data from the first context
+ */
+ // Allocate zeroed memory for the first decoder context
+ s->mp3decctx[0] = av_mallocz(sizeof(MPADecodeContext));
+ // Put decoder context in place to make init_decode() happy
+ avctx->priv_data = s->mp3decctx[0];
+ decode_init(avctx);
+ // Restore mp3on4 context pointer
+ avctx->priv_data = s;
+ s->mp3decctx[0]->adu_mode = 1; // Set adu mode
+
+ /* Create a separate codec/context for each frame (first is already ok).
+ * Each frame is 1 or 2 channels - up to 5 frames allowed
+ */
+ for (i = 1; i < s->frames; i++) {
+ s->mp3decctx[i] = av_mallocz(sizeof(MPADecodeContext));
+ s->mp3decctx[i]->compute_antialias = s->mp3decctx[0]->compute_antialias;
+ s->mp3decctx[i]->adu_mode = 1;
+ s->mp3decctx[i]->avctx = avctx;
+ }
+
+ return 0;
+}
+
+
+static int decode_close_mp3on4(AVCodecContext * avctx)
+{
+ MP3On4DecodeContext *s = avctx->priv_data;
+ int i;
+
+ for (i = 0; i < s->frames; i++)
+ if (s->mp3decctx[i])
+ av_free(s->mp3decctx[i]);
+
+ return 0;
+}
+
+
+static int decode_frame_mp3on4(AVCodecContext * avctx,
+ void *data, int *data_size,
+ uint8_t * buf, int buf_size)
+{
+ MP3On4DecodeContext *s = avctx->priv_data;
+ MPADecodeContext *m;
+ int len, out_size = 0;
+ uint32_t header;
+ OUT_INT *out_samples = data;
+ OUT_INT decoded_buf[MPA_FRAME_SIZE * MPA_MAX_CHANNELS];
+ OUT_INT *outptr, *bp;
+ int fsize;
+ unsigned char *start2 = buf, *start;
+ int fr, i, j, n;
+ int off = avctx->channels;
+ int *coff = chan_offset[s->chan_cfg];
+
+ len = buf_size;
+
+ // Discard too short frames
+ if (buf_size < HEADER_SIZE) {
+ *data_size = 0;
+ return buf_size;
+ }
+
+ // If only one decoder interleave is not needed
+ outptr = s->frames == 1 ? out_samples : decoded_buf;
+
+ for (fr = 0; fr < s->frames; fr++) {
+ start = start2;
+ fsize = (start[0] << 4) | (start[1] >> 4);
+ start2 += fsize;
+ if (fsize > len)
+ fsize = len;
+ len -= fsize;
+ if (fsize > MPA_MAX_CODED_FRAME_SIZE)
+ fsize = MPA_MAX_CODED_FRAME_SIZE;
+ m = s->mp3decctx[fr];
+ assert (m != NULL);
+
+ // Get header
+ header = (start[0] << 24) | (start[1] << 16) | (start[2] << 8) | start[3] | 0xfff00000;
+
+ if (ff_mpa_check_header(header) < 0) { // Bad header, discard block
+ *data_size = 0;
+ return buf_size;
+ }
+
+ decode_header(m, header);
+ mp_decode_frame(m, decoded_buf, start, fsize);
+
+ n = MPA_FRAME_SIZE * m->nb_channels;
+ out_size += n * sizeof(OUT_INT);
+ if(s->frames > 1) {
+ /* interleave output data */
+ bp = out_samples + coff[fr];
+ if(m->nb_channels == 1) {
+ for(j = 0; j < n; j++) {
+ *bp = decoded_buf[j];
+ bp += off;
+ }
+ } else {
+ for(j = 0; j < n; j++) {
+ bp[0] = decoded_buf[j++];
+ bp[1] = decoded_buf[j];
+ bp += off;
+ }
+ }
+ }
+ }
+
+ /* update codec info */
+ avctx->sample_rate = s->mp3decctx[0]->sample_rate;
+ avctx->frame_size= buf_size;
+ avctx->bit_rate = 0;
+ for (i = 0; i < s->frames; i++)
+ avctx->bit_rate += s->mp3decctx[i]->bit_rate;
+
+ *data_size = out_size;
+ return buf_size;
+}
+#endif /* CONFIG_MP3ON4_DECODER */
+
+#ifdef CONFIG_MP2_DECODER
+AVCodec mp2_decoder =
+{
+ "mp2",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_MP2,
+ sizeof(MPADecodeContext),
+ decode_init,
+ NULL,
+ NULL,
+ decode_frame,
+ CODEC_CAP_PARSE_ONLY,
+};
+#endif
+#ifdef CONFIG_MP3_DECODER
+AVCodec mp3_decoder =
+{
+ "mp3",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_MP3,
+ sizeof(MPADecodeContext),
+ decode_init,
+ NULL,
+ NULL,
+ decode_frame,
+ CODEC_CAP_PARSE_ONLY,
+ .flush= flush,
+};
+#endif
+#ifdef CONFIG_MP3ADU_DECODER
+AVCodec mp3adu_decoder =
+{
+ "mp3adu",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_MP3ADU,
+ sizeof(MPADecodeContext),
+ decode_init,
+ NULL,
+ NULL,
+ decode_frame_adu,
+ CODEC_CAP_PARSE_ONLY,
+ .flush= flush,
+};
+#endif
+#ifdef CONFIG_MP3ON4_DECODER
+AVCodec mp3on4_decoder =
+{
+ "mp3on4",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_MP3ON4,
+ sizeof(MP3On4DecodeContext),
+ decode_init_mp3on4,
+ NULL,
+ decode_close_mp3on4,
+ decode_frame_mp3on4,
+ .flush= flush,
+};
+#endif
diff --git a/src/libffmpeg/libavcodec/mpegaudiodectab.h b/contrib/ffmpeg/libavcodec/mpegaudiodectab.h
index fdd1096fc..fdd1096fc 100644
--- a/src/libffmpeg/libavcodec/mpegaudiodectab.h
+++ b/contrib/ffmpeg/libavcodec/mpegaudiodectab.h
diff --git a/src/libffmpeg/libavcodec/mpegaudiotab.h b/contrib/ffmpeg/libavcodec/mpegaudiotab.h
index 8fb37ddff..8fb37ddff 100644
--- a/src/libffmpeg/libavcodec/mpegaudiotab.h
+++ b/contrib/ffmpeg/libavcodec/mpegaudiotab.h
diff --git a/contrib/ffmpeg/libavcodec/mpegvideo.c b/contrib/ffmpeg/libavcodec/mpegvideo.c
new file mode 100644
index 000000000..f0069fa1e
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/mpegvideo.c
@@ -0,0 +1,6949 @@
+/*
+ * The simplest mpeg encoder (well, it was the simplest!)
+ * Copyright (c) 2000,2001 Fabrice Bellard.
+ * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * 4MV & hq & b-frame encoding stuff by Michael Niedermayer <michaelni@gmx.at>
+ */
+
+/**
+ * @file mpegvideo.c
+ * The simplest mpeg encoder (well, it was the simplest!).
+ */
+
+#include "avcodec.h"
+#include "dsputil.h"
+#include "mpegvideo.h"
+#include "faandct.h"
+#include <limits.h>
+
+#ifdef USE_FASTMEMCPY
+#include "libvo/fastmemcpy.h"
+#endif
+
+//#undef NDEBUG
+//#include <assert.h>
+
+#ifdef CONFIG_ENCODERS
+static int encode_picture(MpegEncContext *s, int picture_number);
+#endif //CONFIG_ENCODERS
+static void dct_unquantize_mpeg1_intra_c(MpegEncContext *s,
+ DCTELEM *block, int n, int qscale);
+static void dct_unquantize_mpeg1_inter_c(MpegEncContext *s,
+ DCTELEM *block, int n, int qscale);
+static void dct_unquantize_mpeg2_intra_c(MpegEncContext *s,
+ DCTELEM *block, int n, int qscale);
+static void dct_unquantize_mpeg2_intra_bitexact(MpegEncContext *s,
+ DCTELEM *block, int n, int qscale);
+static void dct_unquantize_mpeg2_inter_c(MpegEncContext *s,
+ DCTELEM *block, int n, int qscale);
+static void dct_unquantize_h263_intra_c(MpegEncContext *s,
+ DCTELEM *block, int n, int qscale);
+static void dct_unquantize_h263_inter_c(MpegEncContext *s,
+ DCTELEM *block, int n, int qscale);
+static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w);
+#ifdef CONFIG_ENCODERS
+static int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
+static int dct_quantize_trellis_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
+static int dct_quantize_refine(MpegEncContext *s, DCTELEM *block, int16_t *weight, DCTELEM *orig, int n, int qscale);
+static int sse_mb(MpegEncContext *s);
+static void denoise_dct_c(MpegEncContext *s, DCTELEM *block);
+#endif //CONFIG_ENCODERS
+
+#ifdef HAVE_XVMC
+extern int XVMC_field_start(MpegEncContext*s, AVCodecContext *avctx);
+extern void XVMC_field_end(MpegEncContext *s);
+extern void XVMC_decode_mb(MpegEncContext *s);
+#endif
+
+void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w)= draw_edges_c;
+
+
+/* enable all paranoid tests for rounding, overflows, etc... */
+//#define PARANOID
+
+//#define DEBUG
+
+
+/* for jpeg fast DCT */
+#define CONST_BITS 14
+
+static const uint16_t aanscales[64] = {
+ /* precomputed values scaled up by 14 bits */
+ 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
+ 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
+ 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
+ 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
+ 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
+ 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
+ 8867 , 12299, 11585, 10426, 8867, 6967, 4799, 2446,
+ 4520 , 6270, 5906, 5315, 4520, 3552, 2446, 1247
+};
+
+static const uint8_t h263_chroma_roundtab[16] = {
+// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
+ 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2,
+};
+
+static const uint8_t ff_default_chroma_qscale_table[32]={
+// 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
+ 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
+};
+
+#ifdef CONFIG_ENCODERS
+static uint8_t default_mv_penalty[MAX_FCODE+1][MAX_MV*2+1];
+static uint8_t default_fcode_tab[MAX_MV*2+1];
+
+enum PixelFormat ff_yuv420p_list[2]= {PIX_FMT_YUV420P, -1};
+
+static void convert_matrix(DSPContext *dsp, int (*qmat)[64], uint16_t (*qmat16)[2][64],
+ const uint16_t *quant_matrix, int bias, int qmin, int qmax, int intra)
+{
+ int qscale;
+ int shift=0;
+
+ for(qscale=qmin; qscale<=qmax; qscale++){
+ int i;
+ if (dsp->fdct == ff_jpeg_fdct_islow
+#ifdef FAAN_POSTSCALE
+ || dsp->fdct == ff_faandct
+#endif
+ ) {
+ for(i=0;i<64;i++) {
+ const int j= dsp->idct_permutation[i];
+ /* 16 <= qscale * quant_matrix[i] <= 7905 */
+ /* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */
+ /* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */
+ /* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */
+
+ qmat[qscale][i] = (int)((UINT64_C(1) << QMAT_SHIFT) /
+ (qscale * quant_matrix[j]));
+ }
+ } else if (dsp->fdct == fdct_ifast
+#ifndef FAAN_POSTSCALE
+ || dsp->fdct == ff_faandct
+#endif
+ ) {
+ for(i=0;i<64;i++) {
+ const int j= dsp->idct_permutation[i];
+ /* 16 <= qscale * quant_matrix[i] <= 7905 */
+ /* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */
+ /* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */
+ /* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */
+
+ qmat[qscale][i] = (int)((UINT64_C(1) << (QMAT_SHIFT + 14)) /
+ (aanscales[i] * qscale * quant_matrix[j]));
+ }
+ } else {
+ for(i=0;i<64;i++) {
+ const int j= dsp->idct_permutation[i];
+ /* We can safely suppose that 16 <= quant_matrix[i] <= 255
+ So 16 <= qscale * quant_matrix[i] <= 7905
+ so (1<<19) / 16 >= (1<<19) / (qscale * quant_matrix[i]) >= (1<<19) / 7905
+ so 32768 >= (1<<19) / (qscale * quant_matrix[i]) >= 67
+ */
+ qmat[qscale][i] = (int)((UINT64_C(1) << QMAT_SHIFT) / (qscale * quant_matrix[j]));
+// qmat [qscale][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[i]);
+ qmat16[qscale][0][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[j]);
+
+ if(qmat16[qscale][0][i]==0 || qmat16[qscale][0][i]==128*256) qmat16[qscale][0][i]=128*256-1;
+ qmat16[qscale][1][i]= ROUNDED_DIV(bias<<(16-QUANT_BIAS_SHIFT), qmat16[qscale][0][i]);
+ }
+ }
+
+ for(i=intra; i<64; i++){
+ int64_t max= 8191;
+ if (dsp->fdct == fdct_ifast
+#ifndef FAAN_POSTSCALE
+ || dsp->fdct == ff_faandct
+#endif
+ ) {
+ max= (8191LL*aanscales[i]) >> 14;
+ }
+ while(((max * qmat[qscale][i]) >> shift) > INT_MAX){
+ shift++;
+ }
+ }
+ }
+ if(shift){
+ av_log(NULL, AV_LOG_INFO, "Warning, QMAT_SHIFT is larger than %d, overflows possible\n", QMAT_SHIFT - shift);
+ }
+}
+
+static inline void update_qscale(MpegEncContext *s){
+ s->qscale= (s->lambda*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7);
+ s->qscale= av_clip(s->qscale, s->avctx->qmin, s->avctx->qmax);
+
+ s->lambda2= (s->lambda*s->lambda + FF_LAMBDA_SCALE/2) >> FF_LAMBDA_SHIFT;
+}
+#endif //CONFIG_ENCODERS
+
+void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable){
+ int i;
+ int end;
+
+ st->scantable= src_scantable;
+
+ for(i=0; i<64; i++){
+ int j;
+ j = src_scantable[i];
+ st->permutated[i] = permutation[j];
+#ifdef ARCH_POWERPC
+ st->inverse[j] = i;
+#endif
+ }
+
+ end=-1;
+ for(i=0; i<64; i++){
+ int j;
+ j = st->permutated[i];
+ if(j>end) end=j;
+ st->raster_end[i]= end;
+ }
+}
+
+#ifdef CONFIG_ENCODERS
+void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix){
+ int i;
+
+ if(matrix){
+ put_bits(pb, 1, 1);
+ for(i=0;i<64;i++) {
+ put_bits(pb, 8, matrix[ ff_zigzag_direct[i] ]);
+ }
+ }else
+ put_bits(pb, 1, 0);
+}
+#endif //CONFIG_ENCODERS
+
+const uint8_t *ff_find_start_code(const uint8_t * restrict p, const uint8_t *end, uint32_t * restrict state){
+ int i;
+
+ assert(p<=end);
+ if(p>=end)
+ return end;
+
+ for(i=0; i<3; i++){
+ uint32_t tmp= *state << 8;
+ *state= tmp + *(p++);
+ if(tmp == 0x100 || p==end)
+ return p;
+ }
+
+ while(p<end){
+ if (p[-1] > 1 ) p+= 3;
+ else if(p[-2] ) p+= 2;
+ else if(p[-3]|(p[-1]-1)) p++;
+ else{
+ p++;
+ break;
+ }
+ }
+
+ p= FFMIN(p, end)-4;
+ *state= be2me_32(unaligned32(p));
+
+ return p+4;
+}
+
+/* init common dct for both encoder and decoder */
+int DCT_common_init(MpegEncContext *s)
+{
+ s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_c;
+ s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_c;
+ s->dct_unquantize_mpeg1_intra = dct_unquantize_mpeg1_intra_c;
+ s->dct_unquantize_mpeg1_inter = dct_unquantize_mpeg1_inter_c;
+ s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_c;
+ if(s->flags & CODEC_FLAG_BITEXACT)
+ s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_bitexact;
+ s->dct_unquantize_mpeg2_inter = dct_unquantize_mpeg2_inter_c;
+
+#ifdef CONFIG_ENCODERS
+ s->dct_quantize= dct_quantize_c;
+ s->denoise_dct= denoise_dct_c;
+#endif //CONFIG_ENCODERS
+
+#ifdef HAVE_MMX
+ MPV_common_init_mmx(s);
+#endif
+#ifdef ARCH_ALPHA
+ MPV_common_init_axp(s);
+#endif
+#ifdef HAVE_MLIB
+ MPV_common_init_mlib(s);
+#endif
+#ifdef HAVE_MMI
+ MPV_common_init_mmi(s);
+#endif
+#ifdef ARCH_ARMV4L
+ MPV_common_init_armv4l(s);
+#endif
+#ifdef ARCH_POWERPC
+ MPV_common_init_ppc(s);
+#endif
+
+#ifdef CONFIG_ENCODERS
+ s->fast_dct_quantize= s->dct_quantize;
+
+ if(s->flags&CODEC_FLAG_TRELLIS_QUANT){
+ s->dct_quantize= dct_quantize_trellis_c; //move before MPV_common_init_*
+ }
+
+#endif //CONFIG_ENCODERS
+
+ /* load & permutate scantables
+ note: only wmv uses different ones
+ */
+ if(s->alternate_scan){
+ ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_alternate_vertical_scan);
+ ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_alternate_vertical_scan);
+ }else{
+ ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_zigzag_direct);
+ ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_zigzag_direct);
+ }
+ 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);
+
+ return 0;
+}
+
+static void copy_picture(Picture *dst, Picture *src){
+ *dst = *src;
+ dst->type= FF_BUFFER_TYPE_COPY;
+}
+
+#ifdef CONFIG_ENCODERS
+static void copy_picture_attributes(MpegEncContext *s, AVFrame *dst, AVFrame *src){
+ int i;
+
+ dst->pict_type = src->pict_type;
+ dst->quality = src->quality;
+ dst->coded_picture_number = src->coded_picture_number;
+ dst->display_picture_number = src->display_picture_number;
+// dst->reference = src->reference;
+ dst->pts = src->pts;
+ dst->interlaced_frame = src->interlaced_frame;
+ dst->top_field_first = src->top_field_first;
+
+ if(s->avctx->me_threshold){
+ if(!src->motion_val[0])
+ av_log(s->avctx, AV_LOG_ERROR, "AVFrame.motion_val not set!\n");
+ if(!src->mb_type)
+ av_log(s->avctx, AV_LOG_ERROR, "AVFrame.mb_type not set!\n");
+ if(!src->ref_index[0])
+ av_log(s->avctx, AV_LOG_ERROR, "AVFrame.ref_index not set!\n");
+ if(src->motion_subsample_log2 != dst->motion_subsample_log2)
+ av_log(s->avctx, AV_LOG_ERROR, "AVFrame.motion_subsample_log2 doesn't match! (%d!=%d)\n",
+ src->motion_subsample_log2, dst->motion_subsample_log2);
+
+ memcpy(dst->mb_type, src->mb_type, s->mb_stride * s->mb_height * sizeof(dst->mb_type[0]));
+
+ for(i=0; i<2; i++){
+ int stride= ((16*s->mb_width )>>src->motion_subsample_log2) + 1;
+ int height= ((16*s->mb_height)>>src->motion_subsample_log2);
+
+ if(src->motion_val[i] && src->motion_val[i] != dst->motion_val[i]){
+ 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));
+ }
+ }
+ }
+}
+#endif
+
+/**
+ * allocates a Picture
+ * The pixels are allocated/set by calling get_buffer() if shared=0
+ */
+static int alloc_picture(MpegEncContext *s, Picture *pic, int shared){
+ const int big_mb_num= s->mb_stride*(s->mb_height+1) + 1; //the +1 is needed so memset(,,stride*height) doesnt sig11
+ const int mb_array_size= s->mb_stride*s->mb_height;
+ const int b8_array_size= s->b8_stride*s->mb_height*2;
+ const int b4_array_size= s->b4_stride*s->mb_height*4;
+ int i;
+
+ if(shared){
+ assert(pic->data[0]);
+ assert(pic->type == 0 || pic->type == FF_BUFFER_TYPE_SHARED);
+ pic->type= FF_BUFFER_TYPE_SHARED;
+ }else{
+ int r;
+
+ assert(!pic->data[0]);
+
+ r= s->avctx->get_buffer(s->avctx, (AVFrame*)pic);
+
+ if(r<0 || !pic->age || !pic->type || !pic->data[0]){
+ av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (%d %d %d %p)\n", r, pic->age, pic->type, pic->data[0]);
+ return -1;
+ }
+
+ if(s->linesize && (s->linesize != pic->linesize[0] || s->uvlinesize != pic->linesize[1])){
+ av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (stride changed)\n");
+ return -1;
+ }
+
+ if(pic->linesize[1] != pic->linesize[2]){
+ av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (uv stride mismatch)\n");
+ return -1;
+ }
+
+ s->linesize = pic->linesize[0];
+ s->uvlinesize= pic->linesize[1];
+ }
+
+ 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))
+ }
+
+ 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 * sizeof(uint32_t))
+ pic->mb_type= pic->mb_type_base + 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))
+ pic->motion_val[i]= pic->motion_val_base[i]+4;
+ CHECKED_ALLOCZ(pic->ref_index[i], b8_array_size * sizeof(uint8_t))
+ }
+ 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))
+ pic->motion_val[i]= pic->motion_val_base[i]+4;
+ CHECKED_ALLOCZ(pic->ref_index[i], b8_array_size * sizeof(uint8_t))
+ }
+ 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)
+ }
+ pic->qstride= s->mb_stride;
+ CHECKED_ALLOCZ(pic->pan_scan , 1 * sizeof(AVPanScan))
+ }
+
+ //it might be nicer if the application would keep track of these but it would require a API change
+ memmove(s->prev_pict_types+1, s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE-1);
+ s->prev_pict_types[0]= s->pict_type;
+ if(pic->age < PREV_PICT_TYPES_BUFFER_SIZE && s->prev_pict_types[pic->age] == B_TYPE)
+ pic->age= INT_MAX; // skipped MBs in b frames are quite rare in mpeg1/2 and its a bit tricky to skip them anyway
+
+ return 0;
+fail: //for the CHECKED_ALLOCZ macro
+ return -1;
+}
+
+/**
+ * deallocates a picture
+ */
+static void free_picture(MpegEncContext *s, Picture *pic){
+ int i;
+
+ if(pic->data[0] && pic->type!=FF_BUFFER_TYPE_SHARED){
+ s->avctx->release_buffer(s->avctx, (AVFrame*)pic);
+ }
+
+ av_freep(&pic->mb_var);
+ av_freep(&pic->mc_mb_var);
+ av_freep(&pic->mb_mean);
+ av_freep(&pic->mbskip_table);
+ av_freep(&pic->qscale_table);
+ av_freep(&pic->mb_type_base);
+ av_freep(&pic->dct_coeff);
+ av_freep(&pic->pan_scan);
+ pic->mb_type= NULL;
+ for(i=0; i<2; i++){
+ av_freep(&pic->motion_val_base[i]);
+ av_freep(&pic->ref_index[i]);
+ }
+
+ if(pic->type == FF_BUFFER_TYPE_SHARED){
+ for(i=0; i<4; i++){
+ pic->base[i]=
+ pic->data[i]= NULL;
+ }
+ pic->type= 0;
+ }
+}
+
+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
+ 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 isnt known before get_buffer()
+ CHECKED_ALLOCZ(s->me.scratchpad, (s->width+64)*4*16*2*sizeof(uint8_t))
+ 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))
+ if(s->avctx->noise_reduction){
+ CHECKED_ALLOCZ(s->dct_error_sum, 2 * 64 * sizeof(int))
+ }
+ }
+ CHECKED_ALLOCZ(s->blocks, 64*12*2 * sizeof(DCTELEM))
+ s->block= s->blocks[0];
+
+ for(i=0;i<12;i++){
+ s->pblocks[i] = (short *)(&s->block[i]);
+ }
+ return 0;
+fail:
+ return -1; //free() through MPV_common_end()
+}
+
+static void free_duplicate_context(MpegEncContext *s){
+ if(s==NULL) return;
+
+ av_freep(&s->allocated_edge_emu_buffer); s->edge_emu_buffer= NULL;
+ av_freep(&s->me.scratchpad);
+ s->rd_scratchpad=
+ s->b_scratchpad=
+ s->obmc_scratchpad= NULL;
+
+ av_freep(&s->dct_error_sum);
+ av_freep(&s->me.map);
+ av_freep(&s->me.score_map);
+ av_freep(&s->blocks);
+ s->block= NULL;
+}
+
+static void backup_duplicate_context(MpegEncContext *bak, MpegEncContext *src){
+#define COPY(a) bak->a= src->a
+ COPY(allocated_edge_emu_buffer);
+ COPY(edge_emu_buffer);
+ COPY(me.scratchpad);
+ COPY(rd_scratchpad);
+ COPY(b_scratchpad);
+ COPY(obmc_scratchpad);
+ COPY(me.map);
+ COPY(me.score_map);
+ COPY(blocks);
+ COPY(block);
+ COPY(start_mb_y);
+ COPY(end_mb_y);
+ COPY(me.map_generation);
+ COPY(pb);
+ COPY(dct_error_sum);
+ COPY(dct_count[0]);
+ COPY(dct_count[1]);
+#undef COPY
+}
+
+void ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src){
+ MpegEncContext bak;
+ int i;
+ //FIXME copy only needed parts
+//START_TIMER
+ backup_duplicate_context(&bak, dst);
+ memcpy(dst, src, sizeof(MpegEncContext));
+ backup_duplicate_context(dst, &bak);
+ for(i=0;i<12;i++){
+ dst->pblocks[i] = (short *)(&dst->block[i]);
+ }
+//STOP_TIMER("update_duplicate_context") //about 10k cycles / 0.01 sec for 1000frames on 1ghz with 2 threads
+}
+
+#ifdef CONFIG_ENCODERS
+static void update_duplicate_context_after_me(MpegEncContext *dst, MpegEncContext *src){
+#define COPY(a) dst->a= src->a
+ COPY(pict_type);
+ COPY(current_picture);
+ COPY(f_code);
+ COPY(b_code);
+ COPY(qscale);
+ COPY(lambda);
+ COPY(lambda2);
+ COPY(picture_in_gop_number);
+ COPY(gop_picture_number);
+ COPY(frame_pred_frame_dct); //FIXME don't set in encode_header
+ COPY(progressive_frame); //FIXME don't set in encode_header
+ COPY(partitioned_frame); //FIXME don't set in encode_header
+#undef COPY
+}
+#endif
+
+/**
+ * sets the given MpegEncContext to common defaults (same for encoding and decoding).
+ * the changed fields will not depend upon the prior state of the MpegEncContext.
+ */
+static void MPV_common_defaults(MpegEncContext *s){
+ s->y_dc_scale_table=
+ s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
+ s->chroma_qscale_table= ff_default_chroma_qscale_table;
+ s->progressive_frame= 1;
+ s->progressive_sequence= 1;
+ s->picture_structure= PICT_FRAME;
+
+ s->coded_picture_number = 0;
+ s->picture_number = 0;
+ s->input_picture_number = 0;
+
+ s->picture_in_gop_number = 0;
+
+ s->f_code = 1;
+ s->b_code = 1;
+}
+
+/**
+ * sets the given MpegEncContext to defaults for decoding.
+ * the changed fields will not depend upon the prior state of the MpegEncContext.
+ */
+void MPV_decode_defaults(MpegEncContext *s){
+ MPV_common_defaults(s);
+}
+
+/**
+ * sets the given MpegEncContext to defaults for encoding.
+ * the changed fields will not depend upon the prior state of the MpegEncContext.
+ */
+
+#ifdef CONFIG_ENCODERS
+static void MPV_encode_defaults(MpegEncContext *s){
+ int i;
+ MPV_common_defaults(s);
+
+ for(i=-16; i<16; i++){
+ default_fcode_tab[i + MAX_MV]= 1;
+ }
+ s->me.mv_penalty= default_mv_penalty;
+ s->fcode_tab= default_fcode_tab;
+}
+#endif //CONFIG_ENCODERS
+
+/**
+ * init common structure for both encoder and decoder.
+ * this assumes that some variables like width/height are already set
+ */
+int MPV_common_init(MpegEncContext *s)
+{
+ int y_size, c_size, yc_size, i, mb_array_size, mv_table_size, x, y;
+
+ s->mb_height = (s->height + 15) / 16;
+
+ if(s->avctx->thread_count > MAX_THREADS || (s->avctx->thread_count > s->mb_height && s->mb_height)){
+ av_log(s->avctx, AV_LOG_ERROR, "too many threads\n");
+ return -1;
+ }
+
+ if((s->width || s->height) && avcodec_check_dimensions(s->avctx, s->width, s->height))
+ return -1;
+
+ dsputil_init(&s->dsp, s->avctx);
+ DCT_common_init(s);
+
+ s->flags= s->avctx->flags;
+ s->flags2= s->avctx->flags2;
+
+ s->mb_width = (s->width + 15) / 16;
+ s->mb_stride = s->mb_width + 1;
+ s->b8_stride = s->mb_width*2 + 1;
+ s->b4_stride = s->mb_width*4 + 1;
+ mb_array_size= s->mb_height * s->mb_stride;
+ mv_table_size= (s->mb_height+2) * s->mb_stride + 1;
+
+ /* set chroma shifts */
+ avcodec_get_chroma_sub_sample(s->avctx->pix_fmt,&(s->chroma_x_shift),
+ &(s->chroma_y_shift) );
+
+ /* set default edge pos, will be overriden in decode_header if needed */
+ s->h_edge_pos= s->mb_width*16;
+ s->v_edge_pos= s->mb_height*16;
+
+ s->mb_num = s->mb_width * s->mb_height;
+
+ s->block_wrap[0]=
+ s->block_wrap[1]=
+ s->block_wrap[2]=
+ s->block_wrap[3]= s->b8_stride;
+ s->block_wrap[4]=
+ s->block_wrap[5]= s->mb_stride;
+
+ y_size = s->b8_stride * (2 * s->mb_height + 1);
+ c_size = s->mb_stride * (s->mb_height + 1);
+ yc_size = y_size + 2 * c_size;
+
+ /* convert fourcc to upper case */
+ s->codec_tag= toupper( s->avctx->codec_tag &0xFF)
+ + (toupper((s->avctx->codec_tag>>8 )&0xFF)<<8 )
+ + (toupper((s->avctx->codec_tag>>16)&0xFF)<<16)
+ + (toupper((s->avctx->codec_tag>>24)&0xFF)<<24);
+
+ s->stream_codec_tag= toupper( s->avctx->stream_codec_tag &0xFF)
+ + (toupper((s->avctx->stream_codec_tag>>8 )&0xFF)<<8 )
+ + (toupper((s->avctx->stream_codec_tag>>16)&0xFF)<<16)
+ + (toupper((s->avctx->stream_codec_tag>>24)&0xFF)<<24);
+
+ 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
+ for(y=0; y<s->mb_height; y++){
+ for(x=0; x<s->mb_width; x++){
+ s->mb_index2xy[ x + y*s->mb_width ] = x + y*s->mb_stride;
+ }
+ }
+ s->mb_index2xy[ s->mb_height*s->mb_width ] = (s->mb_height-1)*s->mb_stride + s->mb_width; //FIXME really needed?
+
+ if (s->encoding) {
+ /* Allocate MV tables */
+ 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))
+ s->p_mv_table = s->p_mv_table_base + s->mb_stride + 1;
+ s->b_forw_mv_table = s->b_forw_mv_table_base + s->mb_stride + 1;
+ s->b_back_mv_table = s->b_back_mv_table_base + s->mb_stride + 1;
+ s->b_bidir_forw_mv_table= s->b_bidir_forw_mv_table_base + s->mb_stride + 1;
+ s->b_bidir_back_mv_table= s->b_bidir_back_mv_table_base + s->mb_stride + 1;
+ s->b_direct_mv_table = s->b_direct_mv_table_base + s->mb_stride + 1;
+
+ if(s->msmpeg4_version){
+ CHECKED_ALLOCZ(s->ac_stats, 2*2*(MAX_LEVEL+1)*(MAX_RUN+1)*2*sizeof(int));
+ }
+ CHECKED_ALLOCZ(s->avctx->stats_out, 256);
+
+ /* Allocate MB type table */
+ CHECKED_ALLOCZ(s->mb_type , mb_array_size * sizeof(uint16_t)) //needed for encoding
+
+ CHECKED_ALLOCZ(s->lambda_table, mb_array_size * sizeof(int))
+
+ 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*))
+
+ if(s->avctx->noise_reduction){
+ CHECKED_ALLOCZ(s->dct_offset, 2 * 64 * sizeof(uint16_t))
+ }
+ }
+ CHECKED_ALLOCZ(s->picture, MAX_PICTURE_COUNT * sizeof(Picture))
+
+ CHECKED_ALLOCZ(s->error_status_table, mb_array_size*sizeof(uint8_t))
+
+ if(s->codec_id==CODEC_ID_MPEG4 || (s->flags & CODEC_FLAG_INTERLACED_ME)){
+ /* interlaced direct mode decoding tables */
+ for(i=0; i<2; i++){
+ int j, k;
+ for(j=0; j<2; j++){
+ 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;
+ }
+ 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;
+ }
+ CHECKED_ALLOCZ(s->p_field_select_table[i] , mb_array_size * 2 * sizeof(uint8_t))
+ }
+ }
+ if (s->out_format == FMT_H263) {
+ /* ac values */
+ CHECKED_ALLOCZ(s->ac_val_base, yc_size * sizeof(int16_t) * 16);
+ 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);
+ 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))
+ }
+
+ 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));
+ s->dc_val[0] = s->dc_val_base + s->b8_stride + 1;
+ s->dc_val[1] = s->dc_val_base + y_size + s->mb_stride + 1;
+ s->dc_val[2] = s->dc_val[1] + c_size;
+ for(i=0;i<yc_size;i++)
+ s->dc_val_base[i] = 1024;
+ }
+
+ /* which mb is a intra block */
+ CHECKED_ALLOCZ(s->mbintra_table, mb_array_size);
+ memset(s->mbintra_table, 1, mb_array_size);
+
+ /* init macroblock skip table */
+ CHECKED_ALLOCZ(s->mbskip_table, mb_array_size+2);
+ //Note the +1 is for a quicker mpeg4 slice_end detection
+ CHECKED_ALLOCZ(s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE);
+
+ s->parse_context.state= -1;
+ if((s->avctx->debug&(FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)) || (s->avctx->debug_mv)){
+ s->visualization_buffer[0] = av_malloc((s->mb_width*16 + 2*EDGE_WIDTH) * s->mb_height*16 + 2*EDGE_WIDTH);
+ s->visualization_buffer[1] = av_malloc((s->mb_width*8 + EDGE_WIDTH) * s->mb_height*8 + EDGE_WIDTH);
+ s->visualization_buffer[2] = av_malloc((s->mb_width*8 + EDGE_WIDTH) * s->mb_height*8 + EDGE_WIDTH);
+ }
+
+ s->context_initialized = 1;
+
+ s->thread_context[0]= s;
+ for(i=1; i<s->avctx->thread_count; i++){
+ s->thread_context[i]= av_malloc(sizeof(MpegEncContext));
+ memcpy(s->thread_context[i], s, sizeof(MpegEncContext));
+ }
+
+ for(i=0; i<s->avctx->thread_count; i++){
+ if(init_duplicate_context(s->thread_context[i], s) < 0)
+ goto fail;
+ s->thread_context[i]->start_mb_y= (s->mb_height*(i ) + s->avctx->thread_count/2) / s->avctx->thread_count;
+ s->thread_context[i]->end_mb_y = (s->mb_height*(i+1) + s->avctx->thread_count/2) / s->avctx->thread_count;
+ }
+
+ return 0;
+ fail:
+ MPV_common_end(s);
+ return -1;
+}
+
+/* init common structure for both encoder and decoder */
+void MPV_common_end(MpegEncContext *s)
+{
+ int i, j, k;
+
+ for(i=0; i<s->avctx->thread_count; i++){
+ free_duplicate_context(s->thread_context[i]);
+ }
+ for(i=1; i<s->avctx->thread_count; i++){
+ av_freep(&s->thread_context[i]);
+ }
+
+ av_freep(&s->parse_context.buffer);
+ s->parse_context.buffer_size=0;
+
+ av_freep(&s->mb_type);
+ av_freep(&s->p_mv_table_base);
+ av_freep(&s->b_forw_mv_table_base);
+ av_freep(&s->b_back_mv_table_base);
+ av_freep(&s->b_bidir_forw_mv_table_base);
+ av_freep(&s->b_bidir_back_mv_table_base);
+ av_freep(&s->b_direct_mv_table_base);
+ s->p_mv_table= NULL;
+ s->b_forw_mv_table= NULL;
+ s->b_back_mv_table= NULL;
+ s->b_bidir_forw_mv_table= NULL;
+ s->b_bidir_back_mv_table= NULL;
+ s->b_direct_mv_table= NULL;
+ for(i=0; i<2; i++){
+ for(j=0; j<2; j++){
+ for(k=0; k<2; k++){
+ av_freep(&s->b_field_mv_table_base[i][j][k]);
+ s->b_field_mv_table[i][j][k]=NULL;
+ }
+ av_freep(&s->b_field_select_table[i][j]);
+ av_freep(&s->p_field_mv_table_base[i][j]);
+ s->p_field_mv_table[i][j]=NULL;
+ }
+ av_freep(&s->p_field_select_table[i]);
+ }
+
+ av_freep(&s->dc_val_base);
+ av_freep(&s->ac_val_base);
+ av_freep(&s->coded_block_base);
+ av_freep(&s->mbintra_table);
+ av_freep(&s->cbp_table);
+ av_freep(&s->pred_dir_table);
+
+ av_freep(&s->mbskip_table);
+ av_freep(&s->prev_pict_types);
+ av_freep(&s->bitstream_buffer);
+ s->allocated_bitstream_buffer_size=0;
+
+ av_freep(&s->avctx->stats_out);
+ av_freep(&s->ac_stats);
+ av_freep(&s->error_status_table);
+ av_freep(&s->mb_index2xy);
+ av_freep(&s->lambda_table);
+ av_freep(&s->q_intra_matrix);
+ av_freep(&s->q_inter_matrix);
+ av_freep(&s->q_intra_matrix16);
+ av_freep(&s->q_inter_matrix16);
+ av_freep(&s->input_picture);
+ av_freep(&s->reordered_input_picture);
+ av_freep(&s->dct_offset);
+
+ if(s->picture){
+ for(i=0; i<MAX_PICTURE_COUNT; i++){
+ free_picture(s, &s->picture[i]);
+ }
+ }
+ av_freep(&s->picture);
+ s->context_initialized = 0;
+ s->last_picture_ptr=
+ s->next_picture_ptr=
+ s->current_picture_ptr= NULL;
+ s->linesize= s->uvlinesize= 0;
+
+ for(i=0; i<3; i++)
+ av_freep(&s->visualization_buffer[i]);
+
+ avcodec_default_free_buffers(s->avctx);
+}
+
+#ifdef CONFIG_ENCODERS
+
+/* init video encoder */
+int MPV_encode_init(AVCodecContext *avctx)
+{
+ MpegEncContext *s = avctx->priv_data;
+ int i;
+ int chroma_h_shift, chroma_v_shift;
+
+ MPV_encode_defaults(s);
+
+ switch (avctx->codec_id) {
+ case CODEC_ID_MPEG2VIDEO:
+ if(avctx->pix_fmt != PIX_FMT_YUV420P && avctx->pix_fmt != PIX_FMT_YUV422P){
+ av_log(avctx, AV_LOG_ERROR, "only YUV420 and YUV422 are supported\n");
+ return -1;
+ }
+ break;
+ case CODEC_ID_LJPEG:
+ case CODEC_ID_MJPEG:
+ if(avctx->pix_fmt != PIX_FMT_YUVJ420P && avctx->pix_fmt != PIX_FMT_YUVJ422P &&
+ ((avctx->pix_fmt != PIX_FMT_YUV420P && avctx->pix_fmt != PIX_FMT_YUV422P) || avctx->strict_std_compliance>FF_COMPLIANCE_INOFFICIAL)){
+ av_log(avctx, AV_LOG_ERROR, "colorspace not supported in jpeg\n");
+ return -1;
+ }
+ break;
+ default:
+ if(avctx->pix_fmt != PIX_FMT_YUV420P){
+ av_log(avctx, AV_LOG_ERROR, "only YUV420 is supported\n");
+ return -1;
+ }
+ }
+
+ switch (avctx->pix_fmt) {
+ case PIX_FMT_YUVJ422P:
+ case PIX_FMT_YUV422P:
+ s->chroma_format = CHROMA_422;
+ break;
+ case PIX_FMT_YUVJ420P:
+ case PIX_FMT_YUV420P:
+ default:
+ s->chroma_format = CHROMA_420;
+ break;
+ }
+
+ s->bit_rate = avctx->bit_rate;
+ s->width = avctx->width;
+ s->height = avctx->height;
+ if(avctx->gop_size > 600 && avctx->strict_std_compliance>FF_COMPLIANCE_EXPERIMENTAL){
+ av_log(avctx, AV_LOG_ERROR, "Warning keyframe interval too large! reducing it ...\n");
+ avctx->gop_size=600;
+ }
+ s->gop_size = avctx->gop_size;
+ s->avctx = avctx;
+ s->flags= avctx->flags;
+ s->flags2= avctx->flags2;
+ s->max_b_frames= avctx->max_b_frames;
+ s->codec_id= avctx->codec->id;
+ s->luma_elim_threshold = avctx->luma_elim_threshold;
+ s->chroma_elim_threshold= avctx->chroma_elim_threshold;
+ s->strict_std_compliance= avctx->strict_std_compliance;
+ s->data_partitioning= avctx->flags & CODEC_FLAG_PART;
+ s->quarter_sample= (avctx->flags & CODEC_FLAG_QPEL)!=0;
+ s->mpeg_quant= avctx->mpeg_quant;
+ s->rtp_mode= !!avctx->rtp_payload_size;
+ s->intra_dc_precision= avctx->intra_dc_precision;
+ s->user_specified_pts = AV_NOPTS_VALUE;
+
+ if (s->gop_size <= 1) {
+ s->intra_only = 1;
+ s->gop_size = 12;
+ } else {
+ s->intra_only = 0;
+ }
+
+ s->me_method = avctx->me_method;
+
+ /* Fixed QSCALE */
+ s->fixed_qscale = !!(avctx->flags & CODEC_FLAG_QSCALE);
+
+ s->adaptive_quant= ( s->avctx->lumi_masking
+ || s->avctx->dark_masking
+ || s->avctx->temporal_cplx_masking
+ || s->avctx->spatial_cplx_masking
+ || s->avctx->p_masking
+ || s->avctx->border_masking
+ || (s->flags&CODEC_FLAG_QP_RD))
+ && !s->fixed_qscale;
+
+ s->obmc= !!(s->flags & CODEC_FLAG_OBMC);
+ s->loop_filter= !!(s->flags & CODEC_FLAG_LOOP_FILTER);
+ s->alternate_scan= !!(s->flags & CODEC_FLAG_ALT_SCAN);
+ s->intra_vlc_format= !!(s->flags2 & CODEC_FLAG2_INTRA_VLC);
+ s->q_scale_type= !!(s->flags2 & CODEC_FLAG2_NON_LINEAR_QUANT);
+
+ if(avctx->rc_max_rate && !avctx->rc_buffer_size){
+ av_log(avctx, AV_LOG_ERROR, "a vbv buffer size is needed, for encoding with a maximum bitrate\n");
+ return -1;
+ }
+
+ if(avctx->rc_min_rate && avctx->rc_max_rate != avctx->rc_min_rate){
+ av_log(avctx, AV_LOG_INFO, "Warning min_rate > 0 but min_rate != max_rate isn't recommended!\n");
+ }
+
+ if(avctx->rc_min_rate && avctx->rc_min_rate > avctx->bit_rate){
+ av_log(avctx, AV_LOG_INFO, "bitrate below min bitrate\n");
+ return -1;
+ }
+
+ if(avctx->rc_max_rate && avctx->rc_max_rate < avctx->bit_rate){
+ av_log(avctx, AV_LOG_INFO, "bitrate above max bitrate\n");
+ return -1;
+ }
+
+ if( s->avctx->rc_max_rate && s->avctx->rc_min_rate == s->avctx->rc_max_rate
+ && (s->codec_id == CODEC_ID_MPEG1VIDEO || s->codec_id == CODEC_ID_MPEG2VIDEO)
+ && 90000LL * (avctx->rc_buffer_size-1) > s->avctx->rc_max_rate*0xFFFFLL){
+
+ av_log(avctx, AV_LOG_INFO, "Warning vbv_delay will be set to 0xFFFF (=VBR) as the specified vbv buffer is too large for the given bitrate!\n");
+ }
+
+ if((s->flags & CODEC_FLAG_4MV) && s->codec_id != CODEC_ID_MPEG4
+ && s->codec_id != CODEC_ID_H263 && s->codec_id != CODEC_ID_H263P && s->codec_id != CODEC_ID_FLV1){
+ av_log(avctx, AV_LOG_ERROR, "4MV not supported by codec\n");
+ return -1;
+ }
+
+ if(s->obmc && s->avctx->mb_decision != FF_MB_DECISION_SIMPLE){
+ av_log(avctx, AV_LOG_ERROR, "OBMC is only supported with simple mb decision\n");
+ return -1;
+ }
+
+ if(s->obmc && s->codec_id != CODEC_ID_H263 && s->codec_id != CODEC_ID_H263P){
+ av_log(avctx, AV_LOG_ERROR, "OBMC is only supported with H263(+)\n");
+ return -1;
+ }
+
+ if(s->quarter_sample && s->codec_id != CODEC_ID_MPEG4){
+ av_log(avctx, AV_LOG_ERROR, "qpel not supported by codec\n");
+ return -1;
+ }
+
+ if(s->data_partitioning && s->codec_id != CODEC_ID_MPEG4){
+ av_log(avctx, AV_LOG_ERROR, "data partitioning not supported by codec\n");
+ return -1;
+ }
+
+ if(s->max_b_frames && s->codec_id != CODEC_ID_MPEG4 && s->codec_id != CODEC_ID_MPEG1VIDEO && s->codec_id != CODEC_ID_MPEG2VIDEO){
+ av_log(avctx, AV_LOG_ERROR, "b frames not supported by codec\n");
+ 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");
+ return -1;
+ }
+
+ if(s->mpeg_quant && s->codec_id != CODEC_ID_MPEG4){ //FIXME mpeg2 uses that too
+ av_log(avctx, AV_LOG_ERROR, "mpeg2 style quantization not supported by codec\n");
+ return -1;
+ }
+
+ if((s->flags & CODEC_FLAG_CBP_RD) && !(s->flags & CODEC_FLAG_TRELLIS_QUANT)){
+ av_log(avctx, AV_LOG_ERROR, "CBP RD needs trellis quant\n");
+ return -1;
+ }
+
+ if((s->flags & CODEC_FLAG_QP_RD) && s->avctx->mb_decision != FF_MB_DECISION_RD){
+ av_log(avctx, AV_LOG_ERROR, "QP RD needs mbd=2\n");
+ return -1;
+ }
+
+ if(s->avctx->scenechange_threshold < 1000000000 && (s->flags & CODEC_FLAG_CLOSED_GOP)){
+ av_log(avctx, AV_LOG_ERROR, "closed gop with scene change detection arent supported yet, set threshold to 1000000000\n");
+ return -1;
+ }
+
+ if((s->flags2 & CODEC_FLAG2_INTRA_VLC) && s->codec_id != CODEC_ID_MPEG2VIDEO){
+ av_log(avctx, AV_LOG_ERROR, "intra vlc table not supported by codec\n");
+ return -1;
+ }
+
+ if(s->flags & CODEC_FLAG_LOW_DELAY){
+ if (s->codec_id != CODEC_ID_MPEG2VIDEO && s->codec_id != CODEC_ID_MPEG1VIDEO){
+ av_log(avctx, AV_LOG_ERROR, "low delay forcing is only available for mpeg1/2\n");
+ return -1;
+ }
+ if (s->max_b_frames != 0){
+ av_log(avctx, AV_LOG_ERROR, "b frames cannot be used with low delay\n");
+ return -1;
+ }
+ }
+
+ if(s->q_scale_type == 1){
+ if(s->codec_id != CODEC_ID_MPEG2VIDEO){
+ av_log(avctx, AV_LOG_ERROR, "non linear quant is only available for mpeg2\n");
+ return -1;
+ }
+ if(avctx->qmax > 12){
+ av_log(avctx, AV_LOG_ERROR, "non linear quant only supports qmax <= 12 currently\n");
+ return -1;
+ }
+ }
+
+ if(s->avctx->thread_count > 1 && s->codec_id != CODEC_ID_MPEG4
+ && s->codec_id != CODEC_ID_MPEG1VIDEO && s->codec_id != CODEC_ID_MPEG2VIDEO
+ && (s->codec_id != CODEC_ID_H263P || !(s->flags & CODEC_FLAG_H263P_SLICE_STRUCT))){
+ av_log(avctx, AV_LOG_ERROR, "multi threaded encoding not supported by codec\n");
+ return -1;
+ }
+
+ if(s->avctx->thread_count > 1)
+ s->rtp_mode= 1;
+
+ if(!avctx->time_base.den || !avctx->time_base.num){
+ av_log(avctx, AV_LOG_ERROR, "framerate not set\n");
+ return -1;
+ }
+
+ i= (INT_MAX/2+128)>>8;
+ if(avctx->me_threshold >= i){
+ av_log(avctx, AV_LOG_ERROR, "me_threshold too large, max is %d\n", i - 1);
+ return -1;
+ }
+ if(avctx->mb_threshold >= i){
+ av_log(avctx, AV_LOG_ERROR, "mb_threshold too large, max is %d\n", i - 1);
+ return -1;
+ }
+
+ if(avctx->b_frame_strategy && (avctx->flags&CODEC_FLAG_PASS2)){
+ av_log(avctx, AV_LOG_INFO, "notice: b_frame_strategy only affects the first pass\n");
+ avctx->b_frame_strategy = 0;
+ }
+
+ i= ff_gcd(avctx->time_base.den, avctx->time_base.num);
+ if(i > 1){
+ av_log(avctx, AV_LOG_INFO, "removing common factors from framerate\n");
+ avctx->time_base.den /= i;
+ avctx->time_base.num /= i;
+// 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){
+ s->intra_quant_bias= 3<<(QUANT_BIAS_SHIFT-3); //(a + x*3/8)/x
+ s->inter_quant_bias= 0;
+ }else{
+ s->intra_quant_bias=0;
+ s->inter_quant_bias=-(1<<(QUANT_BIAS_SHIFT-2)); //(a - x/4)/x
+ }
+
+ if(avctx->intra_quant_bias != FF_DEFAULT_QUANT_BIAS)
+ s->intra_quant_bias= avctx->intra_quant_bias;
+ if(avctx->inter_quant_bias != FF_DEFAULT_QUANT_BIAS)
+ s->inter_quant_bias= avctx->inter_quant_bias;
+
+ avcodec_get_chroma_sub_sample(avctx->pix_fmt, &chroma_h_shift, &chroma_v_shift);
+
+ if(avctx->codec_id == CODEC_ID_MPEG4 && s->avctx->time_base.den > (1<<16)-1){
+ av_log(avctx, AV_LOG_ERROR, "timebase not supported by mpeg 4 standard\n");
+ return -1;
+ }
+ s->time_increment_bits = av_log2(s->avctx->time_base.den - 1) + 1;
+
+ switch(avctx->codec->id) {
+ case CODEC_ID_MPEG1VIDEO:
+ s->out_format = FMT_MPEG1;
+ s->low_delay= !!(s->flags & CODEC_FLAG_LOW_DELAY);
+ avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1);
+ break;
+ case CODEC_ID_MPEG2VIDEO:
+ s->out_format = FMT_MPEG1;
+ s->low_delay= !!(s->flags & CODEC_FLAG_LOW_DELAY);
+ avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1);
+ s->rtp_mode= 1;
+ break;
+ case CODEC_ID_LJPEG:
+ case CODEC_ID_JPEGLS:
+ case CODEC_ID_MJPEG:
+ s->out_format = FMT_MJPEG;
+ s->intra_only = 1; /* force intra only for jpeg */
+ s->mjpeg_write_tables = avctx->codec->id != CODEC_ID_JPEGLS;
+ s->mjpeg_data_only_frames = 0; /* write all the needed headers */
+ 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 (mjpeg_init(s) < 0)
+ return -1;
+ avctx->delay=0;
+ s->low_delay=1;
+ break;
+#ifdef CONFIG_H261_ENCODER
+ case CODEC_ID_H261:
+ if (ff_h261_get_picture_format(s->width, s->height) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "The specified picture size of %dx%d is not valid for the H.261 codec.\nValid sizes are 176x144, 352x288\n", s->width, s->height);
+ return -1;
+ }
+ s->out_format = FMT_H261;
+ avctx->delay=0;
+ s->low_delay=1;
+ break;
+#endif
+ case CODEC_ID_H263:
+ if (h263_get_picture_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;
+ }
+ s->out_format = FMT_H263;
+ s->obmc= (avctx->flags & CODEC_FLAG_OBMC) ? 1:0;
+ avctx->delay=0;
+ s->low_delay=1;
+ break;
+ case CODEC_ID_H263P:
+ s->out_format = FMT_H263;
+ s->h263_plus = 1;
+ /* Fx */
+ s->umvplus = (avctx->flags & CODEC_FLAG_H263P_UMV) ? 1:0;
+ s->h263_aic= (avctx->flags & CODEC_FLAG_AC_PRED) ? 1:0;
+ s->modified_quant= s->h263_aic;
+ s->alt_inter_vlc= (avctx->flags & CODEC_FLAG_H263P_AIV) ? 1:0;
+ s->obmc= (avctx->flags & CODEC_FLAG_OBMC) ? 1:0;
+ s->loop_filter= (avctx->flags & CODEC_FLAG_LOOP_FILTER) ? 1:0;
+ s->unrestricted_mv= s->obmc || s->loop_filter || s->umvplus;
+ s->h263_slice_structured= (s->flags & CODEC_FLAG_H263P_SLICE_STRUCT) ? 1:0;
+
+ /* /Fx */
+ /* These are just to be sure */
+ avctx->delay=0;
+ s->low_delay=1;
+ break;
+ case CODEC_ID_FLV1:
+ s->out_format = FMT_H263;
+ s->h263_flv = 2; /* format = 1; 11-bit codes */
+ s->unrestricted_mv = 1;
+ s->rtp_mode=0; /* don't allow GOB */
+ avctx->delay=0;
+ s->low_delay=1;
+ break;
+ case CODEC_ID_RV10:
+ s->out_format = FMT_H263;
+ avctx->delay=0;
+ s->low_delay=1;
+ break;
+ case CODEC_ID_RV20:
+ s->out_format = FMT_H263;
+ avctx->delay=0;
+ s->low_delay=1;
+ s->modified_quant=1;
+ s->h263_aic=1;
+ s->h263_plus=1;
+ s->loop_filter=1;
+ s->unrestricted_mv= s->obmc || s->loop_filter || s->umvplus;
+ break;
+ case CODEC_ID_MPEG4:
+ s->out_format = FMT_H263;
+ s->h263_pred = 1;
+ s->unrestricted_mv = 1;
+ s->low_delay= s->max_b_frames ? 0 : 1;
+ avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1);
+ break;
+ case CODEC_ID_MSMPEG4V1:
+ s->out_format = FMT_H263;
+ s->h263_msmpeg4 = 1;
+ s->h263_pred = 1;
+ s->unrestricted_mv = 1;
+ s->msmpeg4_version= 1;
+ avctx->delay=0;
+ s->low_delay=1;
+ break;
+ case CODEC_ID_MSMPEG4V2:
+ s->out_format = FMT_H263;
+ s->h263_msmpeg4 = 1;
+ s->h263_pred = 1;
+ s->unrestricted_mv = 1;
+ s->msmpeg4_version= 2;
+ avctx->delay=0;
+ s->low_delay=1;
+ break;
+ case CODEC_ID_MSMPEG4V3:
+ s->out_format = FMT_H263;
+ s->h263_msmpeg4 = 1;
+ s->h263_pred = 1;
+ s->unrestricted_mv = 1;
+ s->msmpeg4_version= 3;
+ s->flipflop_rounding=1;
+ avctx->delay=0;
+ s->low_delay=1;
+ break;
+ case CODEC_ID_WMV1:
+ s->out_format = FMT_H263;
+ s->h263_msmpeg4 = 1;
+ s->h263_pred = 1;
+ s->unrestricted_mv = 1;
+ s->msmpeg4_version= 4;
+ s->flipflop_rounding=1;
+ avctx->delay=0;
+ s->low_delay=1;
+ break;
+ case CODEC_ID_WMV2:
+ s->out_format = FMT_H263;
+ s->h263_msmpeg4 = 1;
+ s->h263_pred = 1;
+ s->unrestricted_mv = 1;
+ s->msmpeg4_version= 5;
+ s->flipflop_rounding=1;
+ avctx->delay=0;
+ s->low_delay=1;
+ break;
+ default:
+ return -1;
+ }
+
+ avctx->has_b_frames= !s->low_delay;
+
+ s->encoding = 1;
+
+ /* init */
+ if (MPV_common_init(s) < 0)
+ return -1;
+
+ if(s->modified_quant)
+ s->chroma_qscale_table= ff_h263_chroma_qscale_table;
+ s->progressive_frame=
+ s->progressive_sequence= !(avctx->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME|CODEC_FLAG_ALT_SCAN));
+ s->quant_precision=5;
+
+ ff_set_cmp(&s->dsp, s->dsp.ildct_cmp, s->avctx->ildct_cmp);
+ ff_set_cmp(&s->dsp, s->dsp.frame_skip_cmp, s->avctx->frame_skip_cmp);
+
+#ifdef CONFIG_H261_ENCODER
+ if (s->out_format == FMT_H261)
+ ff_h261_encode_init(s);
+#endif
+ if (s->out_format == FMT_H263)
+ h263_encode_init(s);
+ if(s->msmpeg4_version)
+ ff_msmpeg4_encode_init(s);
+ if (s->out_format == FMT_MPEG1)
+ ff_mpeg1_encode_init(s);
+
+ /* init q matrix */
+ for(i=0;i<64;i++) {
+ int j= s->dsp.idct_permutation[i];
+ if(s->codec_id==CODEC_ID_MPEG4 && s->mpeg_quant){
+ s->intra_matrix[j] = ff_mpeg4_default_intra_matrix[i];
+ s->inter_matrix[j] = ff_mpeg4_default_non_intra_matrix[i];
+ }else if(s->out_format == FMT_H263 || s->out_format == FMT_H261){
+ s->intra_matrix[j] =
+ s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i];
+ }else
+ { /* mpeg1/2 */
+ s->intra_matrix[j] = ff_mpeg1_default_intra_matrix[i];
+ s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i];
+ }
+ if(s->avctx->intra_matrix)
+ s->intra_matrix[j] = s->avctx->intra_matrix[i];
+ if(s->avctx->inter_matrix)
+ s->inter_matrix[j] = s->avctx->inter_matrix[i];
+ }
+
+ /* precompute matrix */
+ /* for mjpeg, we do include qscale in the matrix */
+ if (s->out_format != FMT_MJPEG) {
+ convert_matrix(&s->dsp, s->q_intra_matrix, s->q_intra_matrix16,
+ s->intra_matrix, s->intra_quant_bias, avctx->qmin, 31, 1);
+ convert_matrix(&s->dsp, s->q_inter_matrix, s->q_inter_matrix16,
+ s->inter_matrix, s->inter_quant_bias, avctx->qmin, 31, 0);
+ }
+
+ if(ff_rate_control_init(s) < 0)
+ return -1;
+
+ return 0;
+}
+
+int MPV_encode_end(AVCodecContext *avctx)
+{
+ MpegEncContext *s = avctx->priv_data;
+
+ ff_rate_control_uninit(s);
+
+ MPV_common_end(s);
+ if (s->out_format == FMT_MJPEG)
+ mjpeg_close(s);
+
+ av_freep(&avctx->extradata);
+
+ return 0;
+}
+
+#endif //CONFIG_ENCODERS
+
+void init_rl(RLTable *rl, uint8_t static_store[2][2*MAX_RUN + MAX_LEVEL + 3])
+{
+ int8_t max_level[MAX_RUN+1], max_run[MAX_LEVEL+1];
+ uint8_t index_run[MAX_RUN+1];
+ int last, run, level, start, end, i;
+
+ /* If table is static, we can quit if rl->max_level[0] is not NULL */
+ if(static_store && rl->max_level[0])
+ return;
+
+ /* compute max_level[], max_run[] and index_run[] */
+ for(last=0;last<2;last++) {
+ if (last == 0) {
+ start = 0;
+ end = rl->last;
+ } else {
+ start = rl->last;
+ end = rl->n;
+ }
+
+ memset(max_level, 0, MAX_RUN + 1);
+ memset(max_run, 0, MAX_LEVEL + 1);
+ memset(index_run, rl->n, MAX_RUN + 1);
+ for(i=start;i<end;i++) {
+ run = rl->table_run[i];
+ level = rl->table_level[i];
+ if (index_run[run] == rl->n)
+ index_run[run] = i;
+ if (level > max_level[run])
+ max_level[run] = level;
+ if (run > max_run[level])
+ max_run[level] = run;
+ }
+ if(static_store)
+ rl->max_level[last] = static_store[last];
+ else
+ rl->max_level[last] = av_malloc(MAX_RUN + 1);
+ memcpy(rl->max_level[last], max_level, MAX_RUN + 1);
+ if(static_store)
+ rl->max_run[last] = static_store[last] + MAX_RUN + 1;
+ else
+ rl->max_run[last] = av_malloc(MAX_LEVEL + 1);
+ memcpy(rl->max_run[last], max_run, MAX_LEVEL + 1);
+ if(static_store)
+ rl->index_run[last] = static_store[last] + MAX_RUN + MAX_LEVEL + 2;
+ else
+ rl->index_run[last] = av_malloc(MAX_RUN + 1);
+ memcpy(rl->index_run[last], index_run, MAX_RUN + 1);
+ }
+}
+
+/* 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)
+{
+ uint8_t *ptr, *last_line;
+ int i;
+
+ last_line = buf + (height - 1) * wrap;
+ for(i=0;i<w;i++) {
+ /* top and bottom */
+ memcpy(buf - (i + 1) * wrap, buf, width);
+ memcpy(last_line + (i + 1) * wrap, last_line, width);
+ }
+ /* left and right */
+ ptr = buf;
+ for(i=0;i<height;i++) {
+ memset(ptr - w, ptr[0], w);
+ memset(ptr + width, ptr[width-1], w);
+ ptr += wrap;
+ }
+ /* corners */
+ for(i=0;i<w;i++) {
+ memset(buf - (i + 1) * wrap - w, buf[0], w); /* top left */
+ memset(buf - (i + 1) * wrap + width, buf[width-1], w); /* top right */
+ memset(last_line + (i + 1) * wrap - w, last_line[0], w); /* top left */
+ memset(last_line + (i + 1) * wrap + width, last_line[width-1], w); /* top right */
+ }
+}
+
+int ff_find_unused_picture(MpegEncContext *s, int shared){
+ int i;
+
+ if(shared){
+ for(i=0; i<MAX_PICTURE_COUNT; i++){
+ if(s->picture[i].data[0]==NULL && s->picture[i].type==0) return i;
+ }
+ }else{
+ for(i=0; i<MAX_PICTURE_COUNT; i++){
+ if(s->picture[i].data[0]==NULL && s->picture[i].type!=0) return i; //FIXME
+ }
+ for(i=0; i<MAX_PICTURE_COUNT; i++){
+ if(s->picture[i].data[0]==NULL) return i;
+ }
+ }
+
+ assert(0);
+ return -1;
+}
+
+static void update_noise_reduction(MpegEncContext *s){
+ int intra, i;
+
+ for(intra=0; intra<2; intra++){
+ if(s->dct_count[intra] > (1<<16)){
+ for(i=0; i<64; i++){
+ s->dct_error_sum[intra][i] >>=1;
+ }
+ s->dct_count[intra] >>= 1;
+ }
+
+ for(i=0; i<64; i++){
+ s->dct_offset[intra][i]= (s->avctx->noise_reduction * s->dct_count[intra] + s->dct_error_sum[intra][i]/2) / (s->dct_error_sum[intra][i]+1);
+ }
+ }
+}
+
+/**
+ * generic function for encode/decode called after coding/decoding the header and before a frame is coded/decoded
+ */
+int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx)
+{
+ int i;
+ AVFrame *pic;
+ s->mb_skipped = 0;
+
+ assert(s->last_picture_ptr==NULL || s->out_format != FMT_H264 || s->codec_id == CODEC_ID_SVQ3);
+
+ /* mark&release old frames */
+ if (s->pict_type != B_TYPE && s->last_picture_ptr && s->last_picture_ptr != s->next_picture_ptr && s->last_picture_ptr->data[0]) {
+ if(s->out_format != FMT_H264 || s->codec_id == CODEC_ID_SVQ3){
+ avctx->release_buffer(avctx, (AVFrame*)s->last_picture_ptr);
+
+ /* release forgotten pictures */
+ /* if(mpeg124/h263) */
+ if(!s->encoding){
+ for(i=0; i<MAX_PICTURE_COUNT; i++){
+ if(s->picture[i].data[0] && &s->picture[i] != s->next_picture_ptr && s->picture[i].reference){
+ av_log(avctx, AV_LOG_ERROR, "releasing zombie picture\n");
+ avctx->release_buffer(avctx, (AVFrame*)&s->picture[i]);
+ }
+ }
+ }
+ }
+ }
+alloc:
+ if(!s->encoding){
+ /* release non reference frames */
+ for(i=0; i<MAX_PICTURE_COUNT; i++){
+ if(s->picture[i].data[0] && !s->picture[i].reference /*&& s->picture[i].type!=FF_BUFFER_TYPE_SHARED*/){
+ s->avctx->release_buffer(s->avctx, (AVFrame*)&s->picture[i]);
+ }
+ }
+
+ if(s->current_picture_ptr && s->current_picture_ptr->data[0]==NULL)
+ pic= (AVFrame*)s->current_picture_ptr; //we allready have a unused image (maybe it was set before reading the header)
+ else{
+ i= ff_find_unused_picture(s, 0);
+ pic= (AVFrame*)&s->picture[i];
+ }
+
+ pic->reference= (s->pict_type != B_TYPE || s->codec_id == CODEC_ID_H264)
+ && !s->dropable ? 3 : 0;
+
+ pic->coded_picture_number= s->coded_picture_number++;
+
+ if( alloc_picture(s, (Picture*)pic, 0) < 0)
+ return -1;
+
+ s->current_picture_ptr= (Picture*)pic;
+ s->current_picture_ptr->top_field_first= s->top_field_first; //FIXME use only the vars from current_pic
+ s->current_picture_ptr->interlaced_frame= !s->progressive_frame && !s->progressive_sequence;
+ }
+
+ s->current_picture_ptr->pict_type= s->pict_type;
+// if(s->flags && CODEC_FLAG_QSCALE)
+ // s->current_picture_ptr->quality= s->new_picture_ptr->quality;
+ s->current_picture_ptr->key_frame= s->pict_type == I_TYPE;
+
+ copy_picture(&s->current_picture, s->current_picture_ptr);
+
+ if (s->pict_type != B_TYPE) {
+ s->last_picture_ptr= s->next_picture_ptr;
+ if(!s->dropable)
+ s->next_picture_ptr= s->current_picture_ptr;
+ }
+/* av_log(s->avctx, AV_LOG_DEBUG, "L%p N%p C%p L%p N%p C%p type:%d drop:%d\n", s->last_picture_ptr, s->next_picture_ptr,s->current_picture_ptr,
+ s->last_picture_ptr ? s->last_picture_ptr->data[0] : NULL,
+ s->next_picture_ptr ? s->next_picture_ptr->data[0] : NULL,
+ s->current_picture_ptr ? s->current_picture_ptr->data[0] : NULL,
+ s->pict_type, s->dropable);*/
+
+ if(s->last_picture_ptr) copy_picture(&s->last_picture, s->last_picture_ptr);
+ if(s->next_picture_ptr) copy_picture(&s->next_picture, s->next_picture_ptr);
+
+ if(s->pict_type != I_TYPE && (s->last_picture_ptr==NULL || s->last_picture_ptr->data[0]==NULL) && !s->dropable){
+ av_log(avctx, AV_LOG_ERROR, "warning: first frame is no keyframe\n");
+ assert(s->pict_type != B_TYPE); //these should have been dropped if we don't have a reference
+ goto alloc;
+ }
+
+ assert(s->pict_type == I_TYPE || (s->last_picture_ptr && s->last_picture_ptr->data[0]));
+
+ if(s->picture_structure!=PICT_FRAME){
+ int i;
+ for(i=0; i<4; i++){
+ if(s->picture_structure == PICT_BOTTOM_FIELD){
+ s->current_picture.data[i] += s->current_picture.linesize[i];
+ }
+ s->current_picture.linesize[i] *= 2;
+ s->last_picture.linesize[i] *=2;
+ s->next_picture.linesize[i] *=2;
+ }
+ }
+
+ s->hurry_up= s->avctx->hurry_up;
+ s->error_resilience= avctx->error_resilience;
+
+ /* set dequantizer, we can't do it during init as it might change for mpeg4
+ and we can't do it in the header decode as init isnt called for mpeg4 there yet */
+ if(s->mpeg_quant || s->codec_id == CODEC_ID_MPEG2VIDEO){
+ s->dct_unquantize_intra = s->dct_unquantize_mpeg2_intra;
+ s->dct_unquantize_inter = s->dct_unquantize_mpeg2_inter;
+ }else if(s->out_format == FMT_H263 || s->out_format == FMT_H261){
+ s->dct_unquantize_intra = s->dct_unquantize_h263_intra;
+ s->dct_unquantize_inter = s->dct_unquantize_h263_inter;
+ }else{
+ s->dct_unquantize_intra = s->dct_unquantize_mpeg1_intra;
+ s->dct_unquantize_inter = s->dct_unquantize_mpeg1_inter;
+ }
+
+ if(s->dct_error_sum){
+ assert(s->avctx->noise_reduction && s->encoding);
+
+ update_noise_reduction(s);
+ }
+
+#ifdef HAVE_XVMC
+ if(s->avctx->xvmc_acceleration)
+ return XVMC_field_start(s, avctx);
+#endif
+ return 0;
+}
+
+/* generic function for encode/decode called after a frame has been coded/decoded */
+void MPV_frame_end(MpegEncContext *s)
+{
+ int i;
+ /* draw edge for correct motion prediction if outside */
+#ifdef HAVE_XVMC
+//just to make sure that all data is rendered.
+ if(s->avctx->xvmc_acceleration){
+ XVMC_field_end(s);
+ }else
+#endif
+ if(s->unrestricted_mv && s->current_picture.reference && !s->intra_only && !(s->flags&CODEC_FLAG_EMU_EDGE)) {
+ draw_edges(s->current_picture.data[0], s->linesize , s->h_edge_pos , s->v_edge_pos , EDGE_WIDTH );
+ draw_edges(s->current_picture.data[1], s->uvlinesize, s->h_edge_pos>>1, s->v_edge_pos>>1, EDGE_WIDTH/2);
+ draw_edges(s->current_picture.data[2], s->uvlinesize, s->h_edge_pos>>1, s->v_edge_pos>>1, EDGE_WIDTH/2);
+ }
+ emms_c();
+
+ s->last_pict_type = s->pict_type;
+ s->last_lambda_for[s->pict_type]= s->current_picture_ptr->quality;
+ if(s->pict_type!=B_TYPE){
+ s->last_non_b_pict_type= s->pict_type;
+ }
+#if 0
+ /* copy back current_picture variables */
+ for(i=0; i<MAX_PICTURE_COUNT; i++){
+ if(s->picture[i].data[0] == s->current_picture.data[0]){
+ s->picture[i]= s->current_picture;
+ break;
+ }
+ }
+ assert(i<MAX_PICTURE_COUNT);
+#endif
+
+ if(s->encoding){
+ /* release non-reference frames */
+ for(i=0; i<MAX_PICTURE_COUNT; i++){
+ if(s->picture[i].data[0] && !s->picture[i].reference /*&& s->picture[i].type!=FF_BUFFER_TYPE_SHARED*/){
+ s->avctx->release_buffer(s->avctx, (AVFrame*)&s->picture[i]);
+ }
+ }
+ }
+ // clear copies, to avoid confusion
+#if 0
+ memset(&s->last_picture, 0, sizeof(Picture));
+ memset(&s->next_picture, 0, sizeof(Picture));
+ memset(&s->current_picture, 0, sizeof(Picture));
+#endif
+ s->avctx->coded_frame= (AVFrame*)s->current_picture_ptr;
+}
+
+/**
+ * draws an line from (ex, ey) -> (sx, sy).
+ * @param w width of the image
+ * @param h height of the image
+ * @param stride stride/linesize of the image
+ * @param color color of the arrow
+ */
+static void draw_line(uint8_t *buf, int sx, int sy, int ex, int ey, int w, int h, int stride, int color){
+ int x, y, fr, f;
+
+ sx= av_clip(sx, 0, w-1);
+ sy= av_clip(sy, 0, h-1);
+ ex= av_clip(ex, 0, w-1);
+ ey= av_clip(ey, 0, h-1);
+
+ buf[sy*stride + sx]+= color;
+
+ if(FFABS(ex - sx) > FFABS(ey - sy)){
+ if(sx > ex){
+ FFSWAP(int, sx, ex);
+ FFSWAP(int, sy, ey);
+ }
+ buf+= sx + sy*stride;
+ ex-= sx;
+ f= ((ey-sy)<<16)/ex;
+ for(x= 0; x <= ex; x++){
+ y = (x*f)>>16;
+ fr= (x*f)&0xFFFF;
+ buf[ y *stride + x]+= (color*(0x10000-fr))>>16;
+ buf[(y+1)*stride + x]+= (color* fr )>>16;
+ }
+ }else{
+ if(sy > ey){
+ FFSWAP(int, sx, ex);
+ FFSWAP(int, sy, ey);
+ }
+ buf+= sx + sy*stride;
+ ey-= sy;
+ if(ey) f= ((ex-sx)<<16)/ey;
+ else f= 0;
+ for(y= 0; y <= ey; y++){
+ x = (y*f)>>16;
+ fr= (y*f)&0xFFFF;
+ buf[y*stride + x ]+= (color*(0x10000-fr))>>16;;
+ buf[y*stride + x+1]+= (color* fr )>>16;;
+ }
+ }
+}
+
+/**
+ * draws an arrow from (ex, ey) -> (sx, sy).
+ * @param w width of the image
+ * @param h height of the image
+ * @param stride stride/linesize of the image
+ * @param color color of the arrow
+ */
+static void draw_arrow(uint8_t *buf, int sx, int sy, int ex, int ey, int w, int h, int stride, int color){
+ int dx,dy;
+
+ sx= av_clip(sx, -100, w+100);
+ sy= av_clip(sy, -100, h+100);
+ ex= av_clip(ex, -100, w+100);
+ ey= av_clip(ey, -100, h+100);
+
+ dx= ex - sx;
+ dy= ey - sy;
+
+ if(dx*dx + dy*dy > 3*3){
+ int rx= dx + dy;
+ int ry= -dx + dy;
+ int length= ff_sqrt((rx*rx + ry*ry)<<8);
+
+ //FIXME subpixel accuracy
+ rx= ROUNDED_DIV(rx*3<<4, length);
+ ry= ROUNDED_DIV(ry*3<<4, length);
+
+ draw_line(buf, sx, sy, sx + rx, sy + ry, w, h, stride, color);
+ draw_line(buf, sx, sy, sx - ry, sy + rx, w, h, stride, color);
+ }
+ draw_line(buf, sx, sy, ex, ey, w, h, stride, color);
+}
+
+/**
+ * prints debuging info for the given picture.
+ */
+void ff_print_debug_info(MpegEncContext *s, AVFrame *pict){
+
+ if(!pict || !pict->mb_type) return;
+
+ if(s->avctx->debug&(FF_DEBUG_SKIP | FF_DEBUG_QP | FF_DEBUG_MB_TYPE)){
+ int x,y;
+
+ av_log(s->avctx,AV_LOG_DEBUG,"New frame, type: ");
+ switch (pict->pict_type) {
+ case FF_I_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"I\n"); break;
+ case FF_P_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"P\n"); break;
+ case FF_B_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"B\n"); break;
+ case FF_S_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"S\n"); break;
+ case FF_SI_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"SI\n"); break;
+ case FF_SP_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"SP\n"); break;
+ }
+ for(y=0; y<s->mb_height; y++){
+ for(x=0; x<s->mb_width; x++){
+ if(s->avctx->debug&FF_DEBUG_SKIP){
+ int count= s->mbskip_table[x + y*s->mb_stride];
+ if(count>9) count=9;
+ av_log(s->avctx, AV_LOG_DEBUG, "%1d", count);
+ }
+ if(s->avctx->debug&FF_DEBUG_QP){
+ av_log(s->avctx, AV_LOG_DEBUG, "%2d", pict->qscale_table[x + y*s->mb_stride]);
+ }
+ if(s->avctx->debug&FF_DEBUG_MB_TYPE){
+ int mb_type= pict->mb_type[x + y*s->mb_stride];
+ //Type & MV direction
+ if(IS_PCM(mb_type))
+ av_log(s->avctx, AV_LOG_DEBUG, "P");
+ else if(IS_INTRA(mb_type) && IS_ACPRED(mb_type))
+ av_log(s->avctx, AV_LOG_DEBUG, "A");
+ else if(IS_INTRA4x4(mb_type))
+ av_log(s->avctx, AV_LOG_DEBUG, "i");
+ else if(IS_INTRA16x16(mb_type))
+ av_log(s->avctx, AV_LOG_DEBUG, "I");
+ else if(IS_DIRECT(mb_type) && IS_SKIP(mb_type))
+ av_log(s->avctx, AV_LOG_DEBUG, "d");
+ else if(IS_DIRECT(mb_type))
+ av_log(s->avctx, AV_LOG_DEBUG, "D");
+ else if(IS_GMC(mb_type) && IS_SKIP(mb_type))
+ av_log(s->avctx, AV_LOG_DEBUG, "g");
+ else if(IS_GMC(mb_type))
+ av_log(s->avctx, AV_LOG_DEBUG, "G");
+ else if(IS_SKIP(mb_type))
+ av_log(s->avctx, AV_LOG_DEBUG, "S");
+ else if(!USES_LIST(mb_type, 1))
+ av_log(s->avctx, AV_LOG_DEBUG, ">");
+ else if(!USES_LIST(mb_type, 0))
+ av_log(s->avctx, AV_LOG_DEBUG, "<");
+ else{
+ assert(USES_LIST(mb_type, 0) && USES_LIST(mb_type, 1));
+ av_log(s->avctx, AV_LOG_DEBUG, "X");
+ }
+
+ //segmentation
+ if(IS_8X8(mb_type))
+ av_log(s->avctx, AV_LOG_DEBUG, "+");
+ else if(IS_16X8(mb_type))
+ av_log(s->avctx, AV_LOG_DEBUG, "-");
+ else if(IS_8X16(mb_type))
+ av_log(s->avctx, AV_LOG_DEBUG, "|");
+ else if(IS_INTRA(mb_type) || IS_16X16(mb_type))
+ av_log(s->avctx, AV_LOG_DEBUG, " ");
+ else
+ av_log(s->avctx, AV_LOG_DEBUG, "?");
+
+
+ if(IS_INTERLACED(mb_type) && s->codec_id == CODEC_ID_H264)
+ av_log(s->avctx, AV_LOG_DEBUG, "=");
+ else
+ av_log(s->avctx, AV_LOG_DEBUG, " ");
+ }
+// av_log(s->avctx, AV_LOG_DEBUG, " ");
+ }
+ av_log(s->avctx, AV_LOG_DEBUG, "\n");
+ }
+ }
+
+ if((s->avctx->debug&(FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)) || (s->avctx->debug_mv)){
+ const int shift= 1 + s->quarter_sample;
+ int mb_y;
+ uint8_t *ptr;
+ int i;
+ int h_chroma_shift, v_chroma_shift;
+ const int width = s->avctx->width;
+ const int height= s->avctx->height;
+ const int mv_sample_log2= 4 - pict->motion_subsample_log2;
+ const int mv_stride= (s->mb_width << mv_sample_log2) + (s->codec_id == CODEC_ID_H264 ? 0 : 1);
+ s->low_delay=0; //needed to see the vectors without trashing the buffers
+
+ avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &h_chroma_shift, &v_chroma_shift);
+ for(i=0; i<3; i++){
+ memcpy(s->visualization_buffer[i], pict->data[i], (i==0) ? pict->linesize[i]*height:pict->linesize[i]*height >> v_chroma_shift);
+ pict->data[i]= s->visualization_buffer[i];
+ }
+ pict->type= FF_BUFFER_TYPE_COPY;
+ ptr= pict->data[0];
+
+ for(mb_y=0; mb_y<s->mb_height; mb_y++){
+ int mb_x;
+ for(mb_x=0; mb_x<s->mb_width; mb_x++){
+ const int mb_index= mb_x + mb_y*s->mb_stride;
+ if((s->avctx->debug_mv) && pict->motion_val){
+ int type;
+ for(type=0; type<3; type++){
+ int direction = 0;
+ switch (type) {
+ case 0: if ((!(s->avctx->debug_mv&FF_DEBUG_VIS_MV_P_FOR)) || (pict->pict_type!=FF_P_TYPE))
+ continue;
+ direction = 0;
+ break;
+ case 1: if ((!(s->avctx->debug_mv&FF_DEBUG_VIS_MV_B_FOR)) || (pict->pict_type!=FF_B_TYPE))
+ continue;
+ direction = 0;
+ break;
+ case 2: if ((!(s->avctx->debug_mv&FF_DEBUG_VIS_MV_B_BACK)) || (pict->pict_type!=FF_B_TYPE))
+ continue;
+ direction = 1;
+ break;
+ }
+ if(!USES_LIST(pict->mb_type[mb_index], direction))
+ continue;
+
+ if(IS_8X8(pict->mb_type[mb_index])){
+ int i;
+ for(i=0; i<4; i++){
+ int sx= mb_x*16 + 4 + 8*(i&1);
+ int sy= mb_y*16 + 4 + 8*(i>>1);
+ int xy= (mb_x*2 + (i&1) + (mb_y*2 + (i>>1))*mv_stride) << (mv_sample_log2-1);
+ int mx= (pict->motion_val[direction][xy][0]>>shift) + sx;
+ int my= (pict->motion_val[direction][xy][1]>>shift) + sy;
+ draw_arrow(ptr, sx, sy, mx, my, width, height, s->linesize, 100);
+ }
+ }else if(IS_16X8(pict->mb_type[mb_index])){
+ int i;
+ for(i=0; i<2; i++){
+ int sx=mb_x*16 + 8;
+ int sy=mb_y*16 + 4 + 8*i;
+ int xy= (mb_x*2 + (mb_y*2 + i)*mv_stride) << (mv_sample_log2-1);
+ int mx=(pict->motion_val[direction][xy][0]>>shift);
+ int my=(pict->motion_val[direction][xy][1]>>shift);
+
+ if(IS_INTERLACED(pict->mb_type[mb_index]))
+ my*=2;
+
+ draw_arrow(ptr, sx, sy, mx+sx, my+sy, width, height, s->linesize, 100);
+ }
+ }else if(IS_8X16(pict->mb_type[mb_index])){
+ int i;
+ for(i=0; i<2; i++){
+ int sx=mb_x*16 + 4 + 8*i;
+ int sy=mb_y*16 + 8;
+ int xy= (mb_x*2 + i + mb_y*2*mv_stride) << (mv_sample_log2-1);
+ int mx=(pict->motion_val[direction][xy][0]>>shift);
+ int my=(pict->motion_val[direction][xy][1]>>shift);
+
+ if(IS_INTERLACED(pict->mb_type[mb_index]))
+ my*=2;
+
+ draw_arrow(ptr, sx, sy, mx+sx, my+sy, width, height, s->linesize, 100);
+ }
+ }else{
+ int sx= mb_x*16 + 8;
+ int sy= mb_y*16 + 8;
+ int xy= (mb_x + mb_y*mv_stride) << mv_sample_log2;
+ int mx= (pict->motion_val[direction][xy][0]>>shift) + sx;
+ int my= (pict->motion_val[direction][xy][1]>>shift) + sy;
+ draw_arrow(ptr, sx, sy, mx, my, width, height, s->linesize, 100);
+ }
+ }
+ }
+ if((s->avctx->debug&FF_DEBUG_VIS_QP) && pict->motion_val){
+ uint64_t c= (pict->qscale_table[mb_index]*128/31) * 0x0101010101010101ULL;
+ int y;
+ for(y=0; y<8; y++){
+ *(uint64_t*)(pict->data[1] + 8*mb_x + (8*mb_y + y)*pict->linesize[1])= c;
+ *(uint64_t*)(pict->data[2] + 8*mb_x + (8*mb_y + y)*pict->linesize[2])= c;
+ }
+ }
+ if((s->avctx->debug&FF_DEBUG_VIS_MB_TYPE) && pict->motion_val){
+ int mb_type= pict->mb_type[mb_index];
+ uint64_t u,v;
+ int y;
+#define COLOR(theta, r)\
+u= (int)(128 + r*cos(theta*3.141592/180));\
+v= (int)(128 + r*sin(theta*3.141592/180));
+
+
+ u=v=128;
+ if(IS_PCM(mb_type)){
+ COLOR(120,48)
+ }else if((IS_INTRA(mb_type) && IS_ACPRED(mb_type)) || IS_INTRA16x16(mb_type)){
+ COLOR(30,48)
+ }else if(IS_INTRA4x4(mb_type)){
+ COLOR(90,48)
+ }else if(IS_DIRECT(mb_type) && IS_SKIP(mb_type)){
+// COLOR(120,48)
+ }else if(IS_DIRECT(mb_type)){
+ COLOR(150,48)
+ }else if(IS_GMC(mb_type) && IS_SKIP(mb_type)){
+ COLOR(170,48)
+ }else if(IS_GMC(mb_type)){
+ COLOR(190,48)
+ }else if(IS_SKIP(mb_type)){
+// COLOR(180,48)
+ }else if(!USES_LIST(mb_type, 1)){
+ COLOR(240,48)
+ }else if(!USES_LIST(mb_type, 0)){
+ COLOR(0,48)
+ }else{
+ assert(USES_LIST(mb_type, 0) && USES_LIST(mb_type, 1));
+ COLOR(300,48)
+ }
+
+ u*= 0x0101010101010101ULL;
+ v*= 0x0101010101010101ULL;
+ for(y=0; y<8; y++){
+ *(uint64_t*)(pict->data[1] + 8*mb_x + (8*mb_y + y)*pict->linesize[1])= u;
+ *(uint64_t*)(pict->data[2] + 8*mb_x + (8*mb_y + y)*pict->linesize[2])= v;
+ }
+
+ //segmentation
+ if(IS_8X8(mb_type) || IS_16X8(mb_type)){
+ *(uint64_t*)(pict->data[0] + 16*mb_x + 0 + (16*mb_y + 8)*pict->linesize[0])^= 0x8080808080808080ULL;
+ *(uint64_t*)(pict->data[0] + 16*mb_x + 8 + (16*mb_y + 8)*pict->linesize[0])^= 0x8080808080808080ULL;
+ }
+ if(IS_8X8(mb_type) || IS_8X16(mb_type)){
+ for(y=0; y<16; y++)
+ pict->data[0][16*mb_x + 8 + (16*mb_y + y)*pict->linesize[0]]^= 0x80;
+ }
+ if(IS_8X8(mb_type) && mv_sample_log2 >= 2){
+ int dm= 1 << (mv_sample_log2-2);
+ for(i=0; i<4; i++){
+ int sx= mb_x*16 + 8*(i&1);
+ int sy= mb_y*16 + 8*(i>>1);
+ int xy= (mb_x*2 + (i&1) + (mb_y*2 + (i>>1))*mv_stride) << (mv_sample_log2-1);
+ //FIXME bidir
+ int32_t *mv = (int32_t*)&pict->motion_val[0][xy];
+ if(mv[0] != mv[dm] || mv[dm*mv_stride] != mv[dm*(mv_stride+1)])
+ for(y=0; y<8; y++)
+ pict->data[0][sx + 4 + (sy + y)*pict->linesize[0]]^= 0x80;
+ if(mv[0] != mv[dm*mv_stride] || mv[dm] != mv[dm*(mv_stride+1)])
+ *(uint64_t*)(pict->data[0] + sx + (sy + 4)*pict->linesize[0])^= 0x8080808080808080ULL;
+ }
+ }
+
+ if(IS_INTERLACED(mb_type) && s->codec_id == CODEC_ID_H264){
+ // hmm
+ }
+ }
+ s->mbskip_table[mb_index]=0;
+ }
+ }
+ }
+}
+
+#ifdef CONFIG_ENCODERS
+
+static int get_sae(uint8_t *src, int ref, int stride){
+ int x,y;
+ int acc=0;
+
+ for(y=0; y<16; y++){
+ for(x=0; x<16; x++){
+ acc+= FFABS(src[x+y*stride] - ref);
+ }
+ }
+
+ return acc;
+}
+
+static int get_intra_count(MpegEncContext *s, uint8_t *src, uint8_t *ref, int stride){
+ int x, y, w, h;
+ int acc=0;
+
+ w= s->width &~15;
+ h= s->height&~15;
+
+ for(y=0; y<h; y+=16){
+ for(x=0; x<w; x+=16){
+ int offset= x + y*stride;
+ int sad = s->dsp.sad[0](NULL, src + offset, ref + offset, stride, 16);
+ int mean= (s->dsp.pix_sum(src + offset, stride) + 128)>>8;
+ int sae = get_sae(src + offset, mean, stride);
+
+ acc+= sae + 500 < sad;
+ }
+ }
+ return acc;
+}
+
+
+static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg){
+ AVFrame *pic=NULL;
+ int64_t pts;
+ int i;
+ const int encoding_delay= s->max_b_frames;
+ int direct=1;
+
+ if(pic_arg){
+ pts= pic_arg->pts;
+ pic_arg->display_picture_number= s->input_picture_number++;
+
+ if(pts != AV_NOPTS_VALUE){
+ if(s->user_specified_pts != AV_NOPTS_VALUE){
+ int64_t time= pts;
+ int64_t last= s->user_specified_pts;
+
+ if(time <= last){
+ av_log(s->avctx, AV_LOG_ERROR, "Error, Invalid timestamp=%"PRId64", last=%"PRId64"\n", pts, s->user_specified_pts);
+ return -1;
+ }
+ }
+ s->user_specified_pts= pts;
+ }else{
+ if(s->user_specified_pts != AV_NOPTS_VALUE){
+ s->user_specified_pts=
+ pts= s->user_specified_pts + 1;
+ av_log(s->avctx, AV_LOG_INFO, "Warning: AVFrame.pts=? trying to guess (%"PRId64")\n", pts);
+ }else{
+ pts= pic_arg->display_picture_number;
+ }
+ }
+ }
+
+ if(pic_arg){
+ if(encoding_delay && !(s->flags&CODEC_FLAG_INPUT_PRESERVED)) direct=0;
+ if(pic_arg->linesize[0] != s->linesize) direct=0;
+ if(pic_arg->linesize[1] != s->uvlinesize) direct=0;
+ if(pic_arg->linesize[2] != s->uvlinesize) direct=0;
+
+// av_log(AV_LOG_DEBUG, "%d %d %d %d\n",pic_arg->linesize[0], pic_arg->linesize[1], s->linesize, s->uvlinesize);
+
+ if(direct){
+ i= ff_find_unused_picture(s, 1);
+
+ pic= (AVFrame*)&s->picture[i];
+ pic->reference= 3;
+
+ for(i=0; i<4; i++){
+ pic->data[i]= pic_arg->data[i];
+ pic->linesize[i]= pic_arg->linesize[i];
+ }
+ alloc_picture(s, (Picture*)pic, 1);
+ }else{
+ i= ff_find_unused_picture(s, 0);
+
+ pic= (AVFrame*)&s->picture[i];
+ pic->reference= 3;
+
+ alloc_picture(s, (Picture*)pic, 0);
+
+ if( pic->data[0] + INPLACE_OFFSET == pic_arg->data[0]
+ && pic->data[1] + INPLACE_OFFSET == pic_arg->data[1]
+ && pic->data[2] + INPLACE_OFFSET == pic_arg->data[2]){
+ // empty
+ }else{
+ int h_chroma_shift, v_chroma_shift;
+ avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &h_chroma_shift, &v_chroma_shift);
+
+ for(i=0; i<3; i++){
+ int src_stride= pic_arg->linesize[i];
+ int dst_stride= i ? s->uvlinesize : s->linesize;
+ int h_shift= i ? h_chroma_shift : 0;
+ int v_shift= i ? v_chroma_shift : 0;
+ int w= s->width >>h_shift;
+ int h= s->height>>v_shift;
+ uint8_t *src= pic_arg->data[i];
+ uint8_t *dst= pic->data[i];
+
+ if(!s->avctx->rc_buffer_size)
+ dst +=INPLACE_OFFSET;
+
+ if(src_stride==dst_stride)
+ memcpy(dst, src, src_stride*h);
+ else{
+ while(h--){
+ memcpy(dst, src, w);
+ dst += dst_stride;
+ src += src_stride;
+ }
+ }
+ }
+ }
+ }
+ copy_picture_attributes(s, pic, pic_arg);
+ pic->pts= pts; //we set this here to avoid modifiying pic_arg
+ }
+
+ /* shift buffer entries */
+ for(i=1; i<MAX_PICTURE_COUNT /*s->encoding_delay+1*/; i++)
+ s->input_picture[i-1]= s->input_picture[i];
+
+ s->input_picture[encoding_delay]= (Picture*)pic;
+
+ return 0;
+}
+
+static int skip_check(MpegEncContext *s, Picture *p, Picture *ref){
+ int x, y, plane;
+ int score=0;
+ int64_t score64=0;
+
+ for(plane=0; plane<3; plane++){
+ const int stride= p->linesize[plane];
+ const int bw= plane ? 1 : 2;
+ for(y=0; y<s->mb_height*bw; y++){
+ for(x=0; x<s->mb_width*bw; x++){
+ int off= p->type == FF_BUFFER_TYPE_SHARED ? 0: 16;
+ int v= s->dsp.frame_skip_cmp[1](s, p->data[plane] + 8*(x + y*stride)+off, ref->data[plane] + 8*(x + y*stride), stride, 8);
+
+ switch(s->avctx->frame_skip_exp){
+ case 0: score= FFMAX(score, v); break;
+ case 1: score+= FFABS(v);break;
+ case 2: score+= v*v;break;
+ case 3: score64+= FFABS(v*v*(int64_t)v);break;
+ case 4: score64+= v*v*(int64_t)(v*v);break;
+ }
+ }
+ }
+ }
+
+ if(score) score64= score;
+
+ if(score64 < s->avctx->frame_skip_threshold)
+ return 1;
+ if(score64 < ((s->avctx->frame_skip_factor * (int64_t)s->lambda)>>8))
+ return 1;
+ return 0;
+}
+
+static int estimate_best_b_count(MpegEncContext *s){
+ AVCodec *codec= avcodec_find_encoder(s->avctx->codec_id);
+ AVCodecContext *c= avcodec_alloc_context();
+ AVFrame input[FF_MAX_B_FRAMES+2];
+ const int scale= s->avctx->brd_scale;
+ int i, j, out_size, p_lambda, b_lambda, lambda2;
+ int outbuf_size= s->width * s->height; //FIXME
+ uint8_t *outbuf= av_malloc(outbuf_size);
+ int64_t best_rd= INT64_MAX;
+ int best_b_count= -1;
+
+ assert(scale>=0 && scale <=3);
+
+// emms_c();
+ p_lambda= s->last_lambda_for[P_TYPE]; //s->next_picture_ptr->quality;
+ b_lambda= s->last_lambda_for[B_TYPE]; //p_lambda *FFABS(s->avctx->b_quant_factor) + s->avctx->b_quant_offset;
+ if(!b_lambda) b_lambda= p_lambda; //FIXME we should do this somewhere else
+ lambda2= (b_lambda*b_lambda + (1<<FF_LAMBDA_SHIFT)/2 ) >> FF_LAMBDA_SHIFT;
+
+ c->width = s->width >> scale;
+ c->height= s->height>> scale;
+ c->flags= CODEC_FLAG_QSCALE | CODEC_FLAG_PSNR | CODEC_FLAG_INPUT_PRESERVED /*| CODEC_FLAG_EMU_EDGE*/;
+ c->flags|= s->avctx->flags & CODEC_FLAG_QPEL;
+ c->mb_decision= s->avctx->mb_decision;
+ c->me_cmp= s->avctx->me_cmp;
+ c->mb_cmp= s->avctx->mb_cmp;
+ c->me_sub_cmp= s->avctx->me_sub_cmp;
+ c->pix_fmt = PIX_FMT_YUV420P;
+ c->time_base= s->avctx->time_base;
+ c->max_b_frames= s->max_b_frames;
+
+ if (avcodec_open(c, codec) < 0)
+ return -1;
+
+ for(i=0; i<s->max_b_frames+2; i++){
+ int ysize= c->width*c->height;
+ int csize= (c->width/2)*(c->height/2);
+ Picture pre_input, *pre_input_ptr= i ? s->input_picture[i-1] : s->next_picture_ptr;
+
+ avcodec_get_frame_defaults(&input[i]);
+ input[i].data[0]= av_malloc(ysize + 2*csize);
+ input[i].data[1]= input[i].data[0] + ysize;
+ input[i].data[2]= input[i].data[1] + csize;
+ input[i].linesize[0]= c->width;
+ input[i].linesize[1]=
+ input[i].linesize[2]= c->width/2;
+
+ if(pre_input_ptr && (!i || s->input_picture[i-1])) {
+ pre_input= *pre_input_ptr;
+
+ if(pre_input.type != FF_BUFFER_TYPE_SHARED && i) {
+ pre_input.data[0]+=INPLACE_OFFSET;
+ pre_input.data[1]+=INPLACE_OFFSET;
+ pre_input.data[2]+=INPLACE_OFFSET;
+ }
+
+ s->dsp.shrink[scale](input[i].data[0], input[i].linesize[0], pre_input.data[0], pre_input.linesize[0], c->width, c->height);
+ s->dsp.shrink[scale](input[i].data[1], input[i].linesize[1], pre_input.data[1], pre_input.linesize[1], c->width>>1, c->height>>1);
+ s->dsp.shrink[scale](input[i].data[2], input[i].linesize[2], pre_input.data[2], pre_input.linesize[2], c->width>>1, c->height>>1);
+ }
+ }
+
+ for(j=0; j<s->max_b_frames+1; j++){
+ int64_t rd=0;
+
+ if(!s->input_picture[j])
+ break;
+
+ c->error[0]= c->error[1]= c->error[2]= 0;
+
+ input[0].pict_type= I_TYPE;
+ input[0].quality= 1 * FF_QP2LAMBDA;
+ out_size = avcodec_encode_video(c, outbuf, outbuf_size, &input[0]);
+// rd += (out_size * lambda2) >> FF_LAMBDA_SHIFT;
+
+ for(i=0; i<s->max_b_frames+1; i++){
+ int is_p= i % (j+1) == j || i==s->max_b_frames;
+
+ input[i+1].pict_type= is_p ? P_TYPE : B_TYPE;
+ input[i+1].quality= is_p ? p_lambda : b_lambda;
+ out_size = avcodec_encode_video(c, outbuf, outbuf_size, &input[i+1]);
+ rd += (out_size * lambda2) >> (FF_LAMBDA_SHIFT - 3);
+ }
+
+ /* get the delayed frames */
+ while(out_size){
+ out_size = avcodec_encode_video(c, outbuf, outbuf_size, NULL);
+ rd += (out_size * lambda2) >> (FF_LAMBDA_SHIFT - 3);
+ }
+
+ rd += c->error[0] + c->error[1] + c->error[2];
+
+ if(rd < best_rd){
+ best_rd= rd;
+ best_b_count= j;
+ }
+ }
+
+ av_freep(&outbuf);
+ avcodec_close(c);
+ av_freep(&c);
+
+ for(i=0; i<s->max_b_frames+2; i++){
+ av_freep(&input[i].data[0]);
+ }
+
+ return best_b_count;
+}
+
+static void select_input_picture(MpegEncContext *s){
+ int i;
+
+ for(i=1; i<MAX_PICTURE_COUNT; i++)
+ s->reordered_input_picture[i-1]= s->reordered_input_picture[i];
+ s->reordered_input_picture[MAX_PICTURE_COUNT-1]= NULL;
+
+ /* set next picture type & ordering */
+ if(s->reordered_input_picture[0]==NULL && s->input_picture[0]){
+ if(/*s->picture_in_gop_number >= s->gop_size ||*/ s->next_picture_ptr==NULL || s->intra_only){
+ s->reordered_input_picture[0]= s->input_picture[0];
+ s->reordered_input_picture[0]->pict_type= I_TYPE;
+ s->reordered_input_picture[0]->coded_picture_number= s->coded_picture_number++;
+ }else{
+ int b_frames;
+
+ if(s->avctx->frame_skip_threshold || s->avctx->frame_skip_factor){
+ if(s->picture_in_gop_number < s->gop_size && skip_check(s, s->input_picture[0], s->next_picture_ptr)){
+ //FIXME check that te gop check above is +-1 correct
+//av_log(NULL, AV_LOG_DEBUG, "skip %p %"PRId64"\n", s->input_picture[0]->data[0], s->input_picture[0]->pts);
+
+ if(s->input_picture[0]->type == FF_BUFFER_TYPE_SHARED){
+ for(i=0; i<4; i++)
+ s->input_picture[0]->data[i]= NULL;
+ s->input_picture[0]->type= 0;
+ }else{
+ assert( s->input_picture[0]->type==FF_BUFFER_TYPE_USER
+ || s->input_picture[0]->type==FF_BUFFER_TYPE_INTERNAL);
+
+ s->avctx->release_buffer(s->avctx, (AVFrame*)s->input_picture[0]);
+ }
+
+ emms_c();
+ ff_vbv_update(s, 0);
+
+ goto no_output_pic;
+ }
+ }
+
+ if(s->flags&CODEC_FLAG_PASS2){
+ for(i=0; i<s->max_b_frames+1; i++){
+ int pict_num= s->input_picture[0]->display_picture_number + i;
+
+ if(pict_num >= s->rc_context.num_entries)
+ break;
+ if(!s->input_picture[i]){
+ s->rc_context.entry[pict_num-1].new_pict_type = P_TYPE;
+ break;
+ }
+
+ s->input_picture[i]->pict_type=
+ s->rc_context.entry[pict_num].new_pict_type;
+ }
+ }
+
+ if(s->avctx->b_frame_strategy==0){
+ b_frames= s->max_b_frames;
+ while(b_frames && !s->input_picture[b_frames]) b_frames--;
+ }else if(s->avctx->b_frame_strategy==1){
+ for(i=1; i<s->max_b_frames+1; i++){
+ if(s->input_picture[i] && s->input_picture[i]->b_frame_score==0){
+ s->input_picture[i]->b_frame_score=
+ get_intra_count(s, s->input_picture[i ]->data[0],
+ s->input_picture[i-1]->data[0], s->linesize) + 1;
+ }
+ }
+ for(i=0; i<s->max_b_frames+1; i++){
+ if(s->input_picture[i]==NULL || s->input_picture[i]->b_frame_score - 1 > s->mb_num/s->avctx->b_sensitivity) break;
+ }
+
+ b_frames= FFMAX(0, i-1);
+
+ /* reset scores */
+ for(i=0; i<b_frames+1; i++){
+ s->input_picture[i]->b_frame_score=0;
+ }
+ }else if(s->avctx->b_frame_strategy==2){
+ b_frames= estimate_best_b_count(s);
+ }else{
+ av_log(s->avctx, AV_LOG_ERROR, "illegal b frame strategy\n");
+ b_frames=0;
+ }
+
+ emms_c();
+//static int b_count=0;
+//b_count+= b_frames;
+//av_log(s->avctx, AV_LOG_DEBUG, "b_frames: %d\n", b_count);
+
+ for(i= b_frames - 1; i>=0; i--){
+ int type= s->input_picture[i]->pict_type;
+ if(type && type != B_TYPE)
+ b_frames= i;
+ }
+ if(s->input_picture[b_frames]->pict_type == B_TYPE && b_frames == s->max_b_frames){
+ av_log(s->avctx, AV_LOG_ERROR, "warning, too many b frames in a row\n");
+ }
+
+ if(s->picture_in_gop_number + b_frames >= s->gop_size){
+ if((s->flags2 & CODEC_FLAG2_STRICT_GOP) && s->gop_size > s->picture_in_gop_number){
+ b_frames= s->gop_size - s->picture_in_gop_number - 1;
+ }else{
+ if(s->flags & CODEC_FLAG_CLOSED_GOP)
+ b_frames=0;
+ s->input_picture[b_frames]->pict_type= I_TYPE;
+ }
+ }
+
+ if( (s->flags & CODEC_FLAG_CLOSED_GOP)
+ && b_frames
+ && s->input_picture[b_frames]->pict_type== I_TYPE)
+ b_frames--;
+
+ s->reordered_input_picture[0]= s->input_picture[b_frames];
+ if(s->reordered_input_picture[0]->pict_type != I_TYPE)
+ s->reordered_input_picture[0]->pict_type= P_TYPE;
+ s->reordered_input_picture[0]->coded_picture_number= s->coded_picture_number++;
+ for(i=0; i<b_frames; i++){
+ s->reordered_input_picture[i+1]= s->input_picture[i];
+ s->reordered_input_picture[i+1]->pict_type= B_TYPE;
+ s->reordered_input_picture[i+1]->coded_picture_number= s->coded_picture_number++;
+ }
+ }
+ }
+no_output_pic:
+ if(s->reordered_input_picture[0]){
+ s->reordered_input_picture[0]->reference= s->reordered_input_picture[0]->pict_type!=B_TYPE ? 3 : 0;
+
+ copy_picture(&s->new_picture, s->reordered_input_picture[0]);
+
+ if(s->reordered_input_picture[0]->type == FF_BUFFER_TYPE_SHARED || s->avctx->rc_buffer_size){
+ // input is a shared pix, so we can't modifiy it -> alloc a new one & ensure that the shared one is reuseable
+
+ int i= ff_find_unused_picture(s, 0);
+ Picture *pic= &s->picture[i];
+
+ pic->reference = s->reordered_input_picture[0]->reference;
+ alloc_picture(s, pic, 0);
+
+ /* mark us unused / free shared pic */
+ if(s->reordered_input_picture[0]->type == FF_BUFFER_TYPE_INTERNAL)
+ s->avctx->release_buffer(s->avctx, (AVFrame*)s->reordered_input_picture[0]);
+ for(i=0; i<4; i++)
+ s->reordered_input_picture[0]->data[i]= NULL;
+ s->reordered_input_picture[0]->type= 0;
+
+ copy_picture_attributes(s, (AVFrame*)pic, (AVFrame*)s->reordered_input_picture[0]);
+
+ s->current_picture_ptr= pic;
+ }else{
+ // input is not a shared pix -> reuse buffer for current_pix
+
+ assert( s->reordered_input_picture[0]->type==FF_BUFFER_TYPE_USER
+ || s->reordered_input_picture[0]->type==FF_BUFFER_TYPE_INTERNAL);
+
+ s->current_picture_ptr= s->reordered_input_picture[0];
+ for(i=0; i<4; i++){
+ s->new_picture.data[i]+= INPLACE_OFFSET;
+ }
+ }
+ copy_picture(&s->current_picture, s->current_picture_ptr);
+
+ s->picture_number= s->new_picture.display_picture_number;
+//printf("dpn:%d\n", s->picture_number);
+ }else{
+ memset(&s->new_picture, 0, sizeof(Picture));
+ }
+}
+
+int MPV_encode_picture(AVCodecContext *avctx,
+ unsigned char *buf, int buf_size, void *data)
+{
+ MpegEncContext *s = avctx->priv_data;
+ AVFrame *pic_arg = data;
+ int i, stuffing_count;
+
+ for(i=0; i<avctx->thread_count; i++){
+ int start_y= s->thread_context[i]->start_mb_y;
+ int end_y= s->thread_context[i]-> end_mb_y;
+ int h= s->mb_height;
+ uint8_t *start= buf + (size_t)(((int64_t) buf_size)*start_y/h);
+ uint8_t *end = buf + (size_t)(((int64_t) buf_size)* end_y/h);
+
+ init_put_bits(&s->thread_context[i]->pb, start, end - start);
+ }
+
+ s->picture_in_gop_number++;
+
+ if(load_input_picture(s, pic_arg) < 0)
+ return -1;
+
+ select_input_picture(s);
+
+ /* output? */
+ if(s->new_picture.data[0]){
+ s->pict_type= s->new_picture.pict_type;
+//emms_c();
+//printf("qs:%f %f %d\n", s->new_picture.quality, s->current_picture.quality, s->qscale);
+ MPV_frame_start(s, avctx);
+vbv_retry:
+ if (encode_picture(s, s->picture_number) < 0)
+ return -1;
+
+ avctx->real_pict_num = s->picture_number;
+ avctx->header_bits = s->header_bits;
+ avctx->mv_bits = s->mv_bits;
+ avctx->misc_bits = s->misc_bits;
+ avctx->i_tex_bits = s->i_tex_bits;
+ avctx->p_tex_bits = s->p_tex_bits;
+ avctx->i_count = s->i_count;
+ avctx->p_count = s->mb_num - s->i_count - s->skip_count; //FIXME f/b_count in avctx
+ avctx->skip_count = s->skip_count;
+
+ MPV_frame_end(s);
+
+ if (s->out_format == FMT_MJPEG)
+ mjpeg_picture_trailer(s);
+
+ if(avctx->rc_buffer_size){
+ RateControlContext *rcc= &s->rc_context;
+ int max_size= rcc->buffer_index/3;
+
+ if(put_bits_count(&s->pb) > max_size && s->lambda < s->avctx->lmax){
+ s->next_lambda= FFMAX(s->lambda+1, s->lambda*(s->qscale+1) / s->qscale);
+ if(s->adaptive_quant){
+ int i;
+ for(i=0; i<s->mb_height*s->mb_stride; i++)
+ s->lambda_table[i]= FFMAX(s->lambda_table[i]+1, s->lambda_table[i]*(s->qscale+1) / s->qscale);
+ }
+ s->mb_skipped = 0; //done in MPV_frame_start()
+ if(s->pict_type==P_TYPE){ //done in encode_picture() so we must undo it
+ if(s->flipflop_rounding || s->codec_id == CODEC_ID_H263P || s->codec_id == CODEC_ID_MPEG4)
+ s->no_rounding ^= 1;
+ }
+ if(s->pict_type!=B_TYPE){
+ s->time_base= s->last_time_base;
+ s->last_non_b_time= s->time - s->pp_time;
+ }
+// av_log(NULL, AV_LOG_ERROR, "R:%d ", s->next_lambda);
+ for(i=0; i<avctx->thread_count; i++){
+ PutBitContext *pb= &s->thread_context[i]->pb;
+ init_put_bits(pb, pb->buf, pb->buf_end - pb->buf);
+ }
+ goto vbv_retry;
+ }
+
+ assert(s->avctx->rc_max_rate);
+ }
+
+ if(s->flags&CODEC_FLAG_PASS1)
+ ff_write_pass1_stats(s);
+
+ for(i=0; i<4; i++){
+ s->current_picture_ptr->error[i]= s->current_picture.error[i];
+ avctx->error[i] += s->current_picture_ptr->error[i];
+ }
+
+ if(s->flags&CODEC_FLAG_PASS1)
+ assert(avctx->header_bits + avctx->mv_bits + avctx->misc_bits + avctx->i_tex_bits + avctx->p_tex_bits == put_bits_count(&s->pb));
+ flush_put_bits(&s->pb);
+ s->frame_bits = put_bits_count(&s->pb);
+
+ stuffing_count= ff_vbv_update(s, s->frame_bits);
+ if(stuffing_count){
+ if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < stuffing_count + 50){
+ av_log(s->avctx, AV_LOG_ERROR, "stuffing too large\n");
+ return -1;
+ }
+
+ switch(s->codec_id){
+ case CODEC_ID_MPEG1VIDEO:
+ case CODEC_ID_MPEG2VIDEO:
+ while(stuffing_count--){
+ put_bits(&s->pb, 8, 0);
+ }
+ break;
+ case CODEC_ID_MPEG4:
+ put_bits(&s->pb, 16, 0);
+ put_bits(&s->pb, 16, 0x1C3);
+ stuffing_count -= 4;
+ while(stuffing_count--){
+ put_bits(&s->pb, 8, 0xFF);
+ }
+ break;
+ default:
+ av_log(s->avctx, AV_LOG_ERROR, "vbv buffer overflow\n");
+ }
+ flush_put_bits(&s->pb);
+ s->frame_bits = put_bits_count(&s->pb);
+ }
+
+ /* update mpeg1/2 vbv_delay for CBR */
+ if(s->avctx->rc_max_rate && s->avctx->rc_min_rate == s->avctx->rc_max_rate && s->out_format == FMT_MPEG1
+ && 90000LL * (avctx->rc_buffer_size-1) <= s->avctx->rc_max_rate*0xFFFFLL){
+ int vbv_delay;
+
+ assert(s->repeat_first_field==0);
+
+ vbv_delay= lrintf(90000 * s->rc_context.buffer_index / s->avctx->rc_max_rate);
+ assert(vbv_delay < 0xFFFF);
+
+ s->vbv_delay_ptr[0] &= 0xF8;
+ s->vbv_delay_ptr[0] |= vbv_delay>>13;
+ s->vbv_delay_ptr[1] = vbv_delay>>5;
+ s->vbv_delay_ptr[2] &= 0x07;
+ s->vbv_delay_ptr[2] |= vbv_delay<<3;
+ }
+ s->total_bits += s->frame_bits;
+ avctx->frame_bits = s->frame_bits;
+ }else{
+ assert((pbBufPtr(&s->pb) == s->pb.buf));
+ s->frame_bits=0;
+ }
+ assert((s->frame_bits&7)==0);
+
+ return s->frame_bits/8;
+}
+
+#endif //CONFIG_ENCODERS
+
+static inline void gmc1_motion(MpegEncContext *s,
+ uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
+ uint8_t **ref_picture)
+{
+ uint8_t *ptr;
+ int offset, src_x, src_y, linesize, uvlinesize;
+ int motion_x, motion_y;
+ int emu=0;
+
+ motion_x= s->sprite_offset[0][0];
+ motion_y= s->sprite_offset[0][1];
+ src_x = s->mb_x * 16 + (motion_x >> (s->sprite_warping_accuracy+1));
+ src_y = s->mb_y * 16 + (motion_y >> (s->sprite_warping_accuracy+1));
+ motion_x<<=(3-s->sprite_warping_accuracy);
+ motion_y<<=(3-s->sprite_warping_accuracy);
+ src_x = av_clip(src_x, -16, s->width);
+ if (src_x == s->width)
+ motion_x =0;
+ src_y = av_clip(src_y, -16, s->height);
+ if (src_y == s->height)
+ motion_y =0;
+
+ linesize = s->linesize;
+ uvlinesize = s->uvlinesize;
+
+ ptr = ref_picture[0] + (src_y * linesize) + src_x;
+
+ if(s->flags&CODEC_FLAG_EMU_EDGE){
+ if( (unsigned)src_x >= s->h_edge_pos - 17
+ || (unsigned)src_y >= s->v_edge_pos - 17){
+ ff_emulated_edge_mc(s->edge_emu_buffer, ptr, linesize, 17, 17, src_x, src_y, s->h_edge_pos, s->v_edge_pos);
+ ptr= s->edge_emu_buffer;
+ }
+ }
+
+ if((motion_x|motion_y)&7){
+ s->dsp.gmc1(dest_y , ptr , linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding);
+ s->dsp.gmc1(dest_y+8, ptr+8, linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding);
+ }else{
+ int dxy;
+
+ dxy= ((motion_x>>3)&1) | ((motion_y>>2)&2);
+ if (s->no_rounding){
+ s->dsp.put_no_rnd_pixels_tab[0][dxy](dest_y, ptr, linesize, 16);
+ }else{
+ s->dsp.put_pixels_tab [0][dxy](dest_y, ptr, linesize, 16);
+ }
+ }
+
+ if(s->flags&CODEC_FLAG_GRAY) return;
+
+ motion_x= s->sprite_offset[1][0];
+ motion_y= s->sprite_offset[1][1];
+ src_x = s->mb_x * 8 + (motion_x >> (s->sprite_warping_accuracy+1));
+ src_y = s->mb_y * 8 + (motion_y >> (s->sprite_warping_accuracy+1));
+ motion_x<<=(3-s->sprite_warping_accuracy);
+ motion_y<<=(3-s->sprite_warping_accuracy);
+ src_x = av_clip(src_x, -8, s->width>>1);
+ if (src_x == s->width>>1)
+ motion_x =0;
+ src_y = av_clip(src_y, -8, s->height>>1);
+ if (src_y == s->height>>1)
+ motion_y =0;
+
+ offset = (src_y * uvlinesize) + src_x;
+ ptr = ref_picture[1] + offset;
+ if(s->flags&CODEC_FLAG_EMU_EDGE){
+ if( (unsigned)src_x >= (s->h_edge_pos>>1) - 9
+ || (unsigned)src_y >= (s->v_edge_pos>>1) - 9){
+ ff_emulated_edge_mc(s->edge_emu_buffer, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
+ ptr= s->edge_emu_buffer;
+ emu=1;
+ }
+ }
+ s->dsp.gmc1(dest_cb, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding);
+
+ ptr = ref_picture[2] + offset;
+ if(emu){
+ ff_emulated_edge_mc(s->edge_emu_buffer, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
+ ptr= s->edge_emu_buffer;
+ }
+ s->dsp.gmc1(dest_cr, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding);
+
+ return;
+}
+
+static inline void gmc_motion(MpegEncContext *s,
+ uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
+ uint8_t **ref_picture)
+{
+ uint8_t *ptr;
+ int linesize, uvlinesize;
+ const int a= s->sprite_warping_accuracy;
+ int ox, oy;
+
+ linesize = s->linesize;
+ uvlinesize = s->uvlinesize;
+
+ ptr = ref_picture[0];
+
+ ox= s->sprite_offset[0][0] + s->sprite_delta[0][0]*s->mb_x*16 + s->sprite_delta[0][1]*s->mb_y*16;
+ oy= s->sprite_offset[0][1] + s->sprite_delta[1][0]*s->mb_x*16 + s->sprite_delta[1][1]*s->mb_y*16;
+
+ s->dsp.gmc(dest_y, ptr, linesize, 16,
+ ox,
+ oy,
+ s->sprite_delta[0][0], s->sprite_delta[0][1],
+ s->sprite_delta[1][0], s->sprite_delta[1][1],
+ a+1, (1<<(2*a+1)) - s->no_rounding,
+ s->h_edge_pos, s->v_edge_pos);
+ s->dsp.gmc(dest_y+8, ptr, linesize, 16,
+ ox + s->sprite_delta[0][0]*8,
+ oy + s->sprite_delta[1][0]*8,
+ s->sprite_delta[0][0], s->sprite_delta[0][1],
+ s->sprite_delta[1][0], s->sprite_delta[1][1],
+ a+1, (1<<(2*a+1)) - s->no_rounding,
+ s->h_edge_pos, s->v_edge_pos);
+
+ if(s->flags&CODEC_FLAG_GRAY) return;
+
+ ox= s->sprite_offset[1][0] + s->sprite_delta[0][0]*s->mb_x*8 + s->sprite_delta[0][1]*s->mb_y*8;
+ oy= s->sprite_offset[1][1] + s->sprite_delta[1][0]*s->mb_x*8 + s->sprite_delta[1][1]*s->mb_y*8;
+
+ ptr = ref_picture[1];
+ s->dsp.gmc(dest_cb, ptr, uvlinesize, 8,
+ ox,
+ oy,
+ s->sprite_delta[0][0], s->sprite_delta[0][1],
+ s->sprite_delta[1][0], s->sprite_delta[1][1],
+ a+1, (1<<(2*a+1)) - s->no_rounding,
+ s->h_edge_pos>>1, s->v_edge_pos>>1);
+
+ ptr = ref_picture[2];
+ s->dsp.gmc(dest_cr, ptr, uvlinesize, 8,
+ ox,
+ oy,
+ s->sprite_delta[0][0], s->sprite_delta[0][1],
+ s->sprite_delta[1][0], s->sprite_delta[1][1],
+ a+1, (1<<(2*a+1)) - s->no_rounding,
+ s->h_edge_pos>>1, s->v_edge_pos>>1);
+}
+
+/**
+ * Copies a rectangular area of samples to a temporary buffer and replicates the boarder samples.
+ * @param buf destination buffer
+ * @param src source buffer
+ * @param linesize number of bytes between 2 vertically adjacent samples in both the source and destination buffers
+ * @param block_w width of block
+ * @param block_h height of block
+ * @param src_x x coordinate of the top left sample of the block in the source buffer
+ * @param src_y y coordinate of the top left sample of the block in the source buffer
+ * @param w width of the source buffer
+ * @param h height of the source buffer
+ */
+void ff_emulated_edge_mc(uint8_t *buf, uint8_t *src, int linesize, int block_w, int block_h,
+ int src_x, int src_y, int w, int h){
+ int x, y;
+ int start_y, start_x, end_y, end_x;
+
+ if(src_y>= h){
+ src+= (h-1-src_y)*linesize;
+ src_y=h-1;
+ }else if(src_y<=-block_h){
+ src+= (1-block_h-src_y)*linesize;
+ src_y=1-block_h;
+ }
+ if(src_x>= w){
+ src+= (w-1-src_x);
+ src_x=w-1;
+ }else if(src_x<=-block_w){
+ src+= (1-block_w-src_x);
+ src_x=1-block_w;
+ }
+
+ start_y= FFMAX(0, -src_y);
+ start_x= FFMAX(0, -src_x);
+ end_y= FFMIN(block_h, h-src_y);
+ end_x= FFMIN(block_w, w-src_x);
+
+ // copy existing part
+ for(y=start_y; y<end_y; y++){
+ for(x=start_x; x<end_x; x++){
+ buf[x + y*linesize]= src[x + y*linesize];
+ }
+ }
+
+ //top
+ for(y=0; y<start_y; y++){
+ for(x=start_x; x<end_x; x++){
+ buf[x + y*linesize]= buf[x + start_y*linesize];
+ }
+ }
+
+ //bottom
+ for(y=end_y; y<block_h; y++){
+ for(x=start_x; x<end_x; x++){
+ buf[x + y*linesize]= buf[x + (end_y-1)*linesize];
+ }
+ }
+
+ for(y=0; y<block_h; y++){
+ //left
+ for(x=0; x<start_x; x++){
+ buf[x + y*linesize]= buf[start_x + y*linesize];
+ }
+
+ //right
+ for(x=end_x; x<block_w; x++){
+ buf[x + y*linesize]= buf[end_x - 1 + y*linesize];
+ }
+ }
+}
+
+static inline int hpel_motion(MpegEncContext *s,
+ uint8_t *dest, uint8_t *src,
+ int field_based, int field_select,
+ int src_x, int src_y,
+ int width, int height, int stride,
+ int h_edge_pos, int v_edge_pos,
+ int w, int h, op_pixels_func *pix_op,
+ int motion_x, int motion_y)
+{
+ int dxy;
+ int emu=0;
+
+ dxy = ((motion_y & 1) << 1) | (motion_x & 1);
+ src_x += motion_x >> 1;
+ src_y += motion_y >> 1;
+
+ /* WARNING: do no forget half pels */
+ src_x = av_clip(src_x, -16, width); //FIXME unneeded for emu?
+ if (src_x == width)
+ dxy &= ~1;
+ src_y = av_clip(src_y, -16, height);
+ if (src_y == height)
+ dxy &= ~2;
+ src += src_y * stride + src_x;
+
+ if(s->unrestricted_mv && (s->flags&CODEC_FLAG_EMU_EDGE)){
+ if( (unsigned)src_x > h_edge_pos - (motion_x&1) - w
+ || (unsigned)src_y > v_edge_pos - (motion_y&1) - h){
+ ff_emulated_edge_mc(s->edge_emu_buffer, src, s->linesize, w+1, (h+1)<<field_based,
+ src_x, src_y<<field_based, h_edge_pos, s->v_edge_pos);
+ src= s->edge_emu_buffer;
+ emu=1;
+ }
+ }
+ if(field_select)
+ src += s->linesize;
+ pix_op[dxy](dest, src, stride, h);
+ return emu;
+}
+
+static inline int hpel_motion_lowres(MpegEncContext *s,
+ uint8_t *dest, uint8_t *src,
+ int field_based, int field_select,
+ int src_x, int src_y,
+ int width, int height, int stride,
+ int h_edge_pos, int v_edge_pos,
+ int w, int h, h264_chroma_mc_func *pix_op,
+ int motion_x, int motion_y)
+{
+ const int lowres= s->avctx->lowres;
+ const int s_mask= (2<<lowres)-1;
+ int emu=0;
+ int sx, sy;
+
+ if(s->quarter_sample){
+ motion_x/=2;
+ motion_y/=2;
+ }
+
+ sx= motion_x & s_mask;
+ sy= motion_y & s_mask;
+ src_x += motion_x >> (lowres+1);
+ src_y += motion_y >> (lowres+1);
+
+ src += src_y * stride + src_x;
+
+ if( (unsigned)src_x > h_edge_pos - (!!sx) - w
+ || (unsigned)src_y >(v_edge_pos >> field_based) - (!!sy) - h){
+ ff_emulated_edge_mc(s->edge_emu_buffer, src, s->linesize, w+1, (h+1)<<field_based,
+ src_x, src_y<<field_based, h_edge_pos, v_edge_pos);
+ src= s->edge_emu_buffer;
+ emu=1;
+ }
+
+ sx <<= 2 - lowres;
+ sy <<= 2 - lowres;
+ if(field_select)
+ src += s->linesize;
+ pix_op[lowres](dest, src, stride, h, sx, sy);
+ return emu;
+}
+
+/* apply one mpeg motion vector to the three components */
+static av_always_inline 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)
+{
+ uint8_t *ptr_y, *ptr_cb, *ptr_cr;
+ int dxy, uvdxy, mx, my, src_x, src_y, uvsrc_x, uvsrc_y, v_edge_pos, uvlinesize, linesize;
+
+#if 0
+if(s->quarter_sample)
+{
+ motion_x>>=1;
+ motion_y>>=1;
+}
+#endif
+
+ v_edge_pos = s->v_edge_pos >> field_based;
+ linesize = s->current_picture.linesize[0] << field_based;
+ uvlinesize = s->current_picture.linesize[1] << field_based;
+
+ 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);
+
+ if (s->out_format == FMT_H263) {
+ if((s->workaround_bugs & FF_BUG_HPEL_CHROMA) && field_based){
+ mx = (motion_x>>1)|(motion_x&1);
+ 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);
+ }else{
+ uvdxy = dxy | (motion_y & 2) | ((motion_x & 2) >> 1);
+ uvsrc_x = src_x>>1;
+ uvsrc_y = src_y>>1;
+ }
+ }else if(s->out_format == FMT_H261){//even chroma mv's are full pel in H261
+ mx = motion_x / 4;
+ my = motion_y / 4;
+ uvdxy = 0;
+ uvsrc_x = s->mb_x*8 + mx;
+ uvsrc_y = s->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);
+ } else {
+ if(s->chroma_x_shift){
+ //Chroma422
+ mx = motion_x / 2;
+ uvdxy = ((motion_y & 1) << 1) | (mx & 1);
+ uvsrc_x = s->mb_x* 8 + (mx >> 1);
+ uvsrc_y = src_y;
+ } else {
+ //Chroma444
+ uvdxy = dxy;
+ uvsrc_x = src_x;
+ uvsrc_y = src_y;
+ }
+ }
+ }
+
+ ptr_y = ref_picture[0] + src_y * linesize + src_x;
+ ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x;
+ ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x;
+
+ if( (unsigned)src_x > s->h_edge_pos - (motion_x&1) - 16
+ || (unsigned)src_y > v_edge_pos - (motion_y&1) - h){
+ if(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");
+ return ;
+ }
+ ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based,
+ src_x, src_y<<field_based, s->h_edge_pos, s->v_edge_pos);
+ ptr_y = s->edge_emu_buffer;
+ if(!(s->flags&CODEC_FLAG_GRAY)){
+ uint8_t *uvbuf= s->edge_emu_buffer+18*s->linesize;
+ ff_emulated_edge_mc(uvbuf , ptr_cb, s->uvlinesize, 9, 9+field_based,
+ uvsrc_x, uvsrc_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1);
+ ff_emulated_edge_mc(uvbuf+16, ptr_cr, s->uvlinesize, 9, 9+field_based,
+ uvsrc_x, uvsrc_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1);
+ ptr_cb= uvbuf;
+ ptr_cr= uvbuf+16;
+ }
+ }
+
+ if(bottom_field){ //FIXME use this for field pix too instead of the obnoxious hack which changes picture.data
+ dest_y += s->linesize;
+ dest_cb+= s->uvlinesize;
+ dest_cr+= s->uvlinesize;
+ }
+
+ if(field_select){
+ ptr_y += s->linesize;
+ ptr_cb+= s->uvlinesize;
+ ptr_cr+= s->uvlinesize;
+ }
+
+ pix_op[0][dxy](dest_y, ptr_y, linesize, h);
+
+ if(!(s->flags&CODEC_FLAG_GRAY)){
+ pix_op[s->chroma_x_shift][uvdxy](dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift);
+ pix_op[s->chroma_x_shift][uvdxy](dest_cr, ptr_cr, uvlinesize, h >> s->chroma_y_shift);
+ }
+#if defined(CONFIG_H261_ENCODER) || defined(CONFIG_H261_DECODER)
+ if(s->out_format == FMT_H261){
+ ff_h261_loop_filter(s);
+ }
+#endif
+}
+
+/* apply one mpeg motion vector to the three components */
+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)
+{
+ 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 block_s= 8>>lowres;
+ const int s_mask= (2<<lowres)-1;
+ const int h_edge_pos = s->h_edge_pos >> lowres;
+ const int v_edge_pos = s->v_edge_pos >> lowres;
+ linesize = s->current_picture.linesize[0] << field_based;
+ uvlinesize = s->current_picture.linesize[1] << field_based;
+
+ if(s->quarter_sample){ //FIXME obviously not perfect but qpel wont work in lowres anyway
+ motion_x/=2;
+ motion_y/=2;
+ }
+
+ if(field_based){
+ motion_y += (bottom_field - field_select)*((1<<lowres)-1);
+ }
+
+ 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));
+
+ if (s->out_format == FMT_H263) {
+ uvsx = ((motion_x>>1) & s_mask) | (sx&1);
+ uvsy = ((motion_y>>1) & s_mask) | (sy&1);
+ uvsrc_x = src_x>>1;
+ uvsrc_y = src_y>>1;
+ }else if(s->out_format == FMT_H261){//even chroma mv's are full pel in H261
+ mx = motion_x / 4;
+ my = motion_y / 4;
+ 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);
+ } 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));
+ }
+
+ ptr_y = ref_picture[0] + src_y * linesize + src_x;
+ ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x;
+ ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x;
+
+ if( (unsigned)src_x > h_edge_pos - (!!sx) - 2*block_s
+ || (unsigned)src_y >(v_edge_pos >> field_based) - (!!sy) - h){
+ ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based,
+ src_x, src_y<<field_based, h_edge_pos, v_edge_pos);
+ ptr_y = s->edge_emu_buffer;
+ if(!(s->flags&CODEC_FLAG_GRAY)){
+ uint8_t *uvbuf= s->edge_emu_buffer+18*s->linesize;
+ ff_emulated_edge_mc(uvbuf , ptr_cb, s->uvlinesize, 9, 9+field_based,
+ uvsrc_x, uvsrc_y<<field_based, h_edge_pos>>1, v_edge_pos>>1);
+ ff_emulated_edge_mc(uvbuf+16, ptr_cr, s->uvlinesize, 9, 9+field_based,
+ uvsrc_x, uvsrc_y<<field_based, h_edge_pos>>1, v_edge_pos>>1);
+ ptr_cb= uvbuf;
+ ptr_cr= uvbuf+16;
+ }
+ }
+
+ if(bottom_field){ //FIXME use this for field pix too instead of the obnoxious hack which changes picture.data
+ dest_y += s->linesize;
+ dest_cb+= s->uvlinesize;
+ dest_cr+= s->uvlinesize;
+ }
+
+ if(field_select){
+ ptr_y += s->linesize;
+ ptr_cb+= s->uvlinesize;
+ ptr_cr+= s->uvlinesize;
+ }
+
+ sx <<= 2 - lowres;
+ sy <<= 2 - lowres;
+ pix_op[lowres-1](dest_y, ptr_y, linesize, h, sx, sy);
+
+ if(!(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);
+ }
+ //FIXME h261 lowres loop filter
+}
+
+//FIXME move to dsputil, avg variant, 16x16 version
+static inline void put_obmc(uint8_t *dst, uint8_t *src[5], int stride){
+ int x;
+ uint8_t * const top = src[1];
+ uint8_t * const left = src[2];
+ uint8_t * const mid = src[0];
+ uint8_t * const right = src[3];
+ uint8_t * const bottom= src[4];
+#define OBMC_FILTER(x, t, l, m, r, b)\
+ dst[x]= (t*top[x] + l*left[x] + m*mid[x] + r*right[x] + b*bottom[x] + 4)>>3
+#define OBMC_FILTER4(x, t, l, m, r, b)\
+ OBMC_FILTER(x , t, l, m, r, b);\
+ OBMC_FILTER(x+1 , t, l, m, r, b);\
+ OBMC_FILTER(x +stride, t, l, m, r, b);\
+ OBMC_FILTER(x+1+stride, t, l, m, r, b);
+
+ x=0;
+ OBMC_FILTER (x , 2, 2, 4, 0, 0);
+ OBMC_FILTER (x+1, 2, 1, 5, 0, 0);
+ OBMC_FILTER4(x+2, 2, 1, 5, 0, 0);
+ OBMC_FILTER4(x+4, 2, 0, 5, 1, 0);
+ OBMC_FILTER (x+6, 2, 0, 5, 1, 0);
+ OBMC_FILTER (x+7, 2, 0, 4, 2, 0);
+ x+= stride;
+ OBMC_FILTER (x , 1, 2, 5, 0, 0);
+ OBMC_FILTER (x+1, 1, 2, 5, 0, 0);
+ OBMC_FILTER (x+6, 1, 0, 5, 2, 0);
+ OBMC_FILTER (x+7, 1, 0, 5, 2, 0);
+ x+= stride;
+ OBMC_FILTER4(x , 1, 2, 5, 0, 0);
+ OBMC_FILTER4(x+2, 1, 1, 6, 0, 0);
+ OBMC_FILTER4(x+4, 1, 0, 6, 1, 0);
+ OBMC_FILTER4(x+6, 1, 0, 5, 2, 0);
+ x+= 2*stride;
+ OBMC_FILTER4(x , 0, 2, 5, 0, 1);
+ OBMC_FILTER4(x+2, 0, 1, 6, 0, 1);
+ OBMC_FILTER4(x+4, 0, 0, 6, 1, 1);
+ OBMC_FILTER4(x+6, 0, 0, 5, 2, 1);
+ x+= 2*stride;
+ OBMC_FILTER (x , 0, 2, 5, 0, 1);
+ OBMC_FILTER (x+1, 0, 2, 5, 0, 1);
+ OBMC_FILTER4(x+2, 0, 1, 5, 0, 2);
+ OBMC_FILTER4(x+4, 0, 0, 5, 1, 2);
+ OBMC_FILTER (x+6, 0, 0, 5, 2, 1);
+ OBMC_FILTER (x+7, 0, 0, 5, 2, 1);
+ x+= stride;
+ OBMC_FILTER (x , 0, 2, 4, 0, 2);
+ OBMC_FILTER (x+1, 0, 1, 5, 0, 2);
+ OBMC_FILTER (x+6, 0, 0, 5, 1, 2);
+ OBMC_FILTER (x+7, 0, 0, 4, 2, 2);
+}
+
+/* obmc for 1 8x8 luma block */
+static inline void obmc_motion(MpegEncContext *s,
+ uint8_t *dest, uint8_t *src,
+ int src_x, int src_y,
+ op_pixels_func *pix_op,
+ int16_t mv[5][2]/* mid top left right bottom*/)
+#define MID 0
+{
+ int i;
+ uint8_t *ptr[5];
+
+ assert(s->quarter_sample==0);
+
+ for(i=0; i<5; i++){
+ if(i && mv[i][0]==mv[MID][0] && mv[i][1]==mv[MID][1]){
+ ptr[i]= ptr[MID];
+ }else{
+ ptr[i]= s->obmc_scratchpad + 8*(i&1) + s->linesize*8*(i>>1);
+ hpel_motion(s, ptr[i], src, 0, 0,
+ src_x, src_y,
+ s->width, s->height, s->linesize,
+ s->h_edge_pos, s->v_edge_pos,
+ 8, 8, pix_op,
+ mv[i][0], mv[i][1]);
+ }
+ }
+
+ put_obmc(dest, ptr, s->linesize);
+}
+
+static inline void qpel_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],
+ qpel_mc_func (*qpix_op)[16],
+ int motion_x, int motion_y, int h)
+{
+ uint8_t *ptr_y, *ptr_cb, *ptr_cr;
+ int dxy, uvdxy, mx, my, src_x, src_y, uvsrc_x, uvsrc_y, v_edge_pos, linesize, uvlinesize;
+
+ dxy = ((motion_y & 3) << 2) | (motion_x & 3);
+ src_x = s->mb_x * 16 + (motion_x >> 2);
+ src_y = s->mb_y * (16 >> field_based) + (motion_y >> 2);
+
+ v_edge_pos = s->v_edge_pos >> field_based;
+ linesize = s->linesize << field_based;
+ uvlinesize = s->uvlinesize << field_based;
+
+ if(field_based){
+ mx= motion_x/2;
+ my= motion_y>>1;
+ }else if(s->workaround_bugs&FF_BUG_QPEL_CHROMA2){
+ static const int rtab[8]= {0,0,1,1,0,0,0,1};
+ mx= (motion_x>>1) + rtab[motion_x&7];
+ my= (motion_y>>1) + rtab[motion_y&7];
+ }else if(s->workaround_bugs&FF_BUG_QPEL_CHROMA){
+ mx= (motion_x>>1)|(motion_x&1);
+ my= (motion_y>>1)|(motion_y&1);
+ }else{
+ mx= motion_x/2;
+ my= motion_y/2;
+ }
+ mx= (mx>>1)|(mx&1);
+ my= (my>>1)|(my&1);
+
+ uvdxy= (mx&1) | ((my&1)<<1);
+ mx>>=1;
+ my>>=1;
+
+ uvsrc_x = s->mb_x * 8 + mx;
+ uvsrc_y = s->mb_y * (8 >> field_based) + my;
+
+ ptr_y = ref_picture[0] + src_y * linesize + src_x;
+ ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x;
+ ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x;
+
+ if( (unsigned)src_x > s->h_edge_pos - (motion_x&3) - 16
+ || (unsigned)src_y > v_edge_pos - (motion_y&3) - h ){
+ ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based,
+ src_x, src_y<<field_based, s->h_edge_pos, s->v_edge_pos);
+ ptr_y= s->edge_emu_buffer;
+ if(!(s->flags&CODEC_FLAG_GRAY)){
+ uint8_t *uvbuf= s->edge_emu_buffer + 18*s->linesize;
+ ff_emulated_edge_mc(uvbuf, ptr_cb, s->uvlinesize, 9, 9 + field_based,
+ uvsrc_x, uvsrc_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1);
+ ff_emulated_edge_mc(uvbuf + 16, ptr_cr, s->uvlinesize, 9, 9 + field_based,
+ uvsrc_x, uvsrc_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1);
+ ptr_cb= uvbuf;
+ ptr_cr= uvbuf + 16;
+ }
+ }
+
+ if(!field_based)
+ qpix_op[0][dxy](dest_y, ptr_y, linesize);
+ else{
+ if(bottom_field){
+ dest_y += s->linesize;
+ dest_cb+= s->uvlinesize;
+ dest_cr+= s->uvlinesize;
+ }
+
+ if(field_select){
+ ptr_y += s->linesize;
+ ptr_cb += s->uvlinesize;
+ ptr_cr += s->uvlinesize;
+ }
+ //damn interlaced mode
+ //FIXME boundary mirroring is not exactly correct here
+ qpix_op[1][dxy](dest_y , ptr_y , linesize);
+ qpix_op[1][dxy](dest_y+8, ptr_y+8, linesize);
+ }
+ if(!(s->flags&CODEC_FLAG_GRAY)){
+ pix_op[1][uvdxy](dest_cr, ptr_cr, uvlinesize, h >> 1);
+ pix_op[1][uvdxy](dest_cb, ptr_cb, uvlinesize, h >> 1);
+ }
+}
+
+inline int ff_h263_round_chroma(int x){
+ if (x >= 0)
+ return (h263_chroma_roundtab[x & 0xf] + ((x >> 3) & ~1));
+ else {
+ x = -x;
+ return -(h263_chroma_roundtab[x & 0xf] + ((x >> 3) & ~1));
+ }
+}
+
+/**
+ * h263 chorma 4mv motion compensation.
+ */
+static inline void chroma_4mv_motion(MpegEncContext *s,
+ uint8_t *dest_cb, uint8_t *dest_cr,
+ uint8_t **ref_picture,
+ op_pixels_func *pix_op,
+ int mx, int my){
+ int dxy, emu=0, src_x, src_y, offset;
+ uint8_t *ptr;
+
+ /* In case of 8X8, we construct a single chroma motion vector
+ with a special rounding */
+ mx= ff_h263_round_chroma(mx);
+ my= ff_h263_round_chroma(my);
+
+ dxy = ((my & 1) << 1) | (mx & 1);
+ mx >>= 1;
+ my >>= 1;
+
+ src_x = s->mb_x * 8 + mx;
+ src_y = s->mb_y * 8 + my;
+ src_x = av_clip(src_x, -8, s->width/2);
+ if (src_x == s->width/2)
+ dxy &= ~1;
+ src_y = av_clip(src_y, -8, s->height/2);
+ if (src_y == s->height/2)
+ dxy &= ~2;
+
+ offset = (src_y * (s->uvlinesize)) + src_x;
+ ptr = ref_picture[1] + offset;
+ if(s->flags&CODEC_FLAG_EMU_EDGE){
+ if( (unsigned)src_x > (s->h_edge_pos>>1) - (dxy &1) - 8
+ || (unsigned)src_y > (s->v_edge_pos>>1) - (dxy>>1) - 8){
+ ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
+ ptr= s->edge_emu_buffer;
+ emu=1;
+ }
+ }
+ pix_op[dxy](dest_cb, ptr, s->uvlinesize, 8);
+
+ ptr = ref_picture[2] + offset;
+ if(emu){
+ ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
+ ptr= s->edge_emu_buffer;
+ }
+ pix_op[dxy](dest_cr, ptr, s->uvlinesize, 8);
+}
+
+static inline void chroma_4mv_motion_lowres(MpegEncContext *s,
+ uint8_t *dest_cb, uint8_t *dest_cr,
+ uint8_t **ref_picture,
+ h264_chroma_mc_func *pix_op,
+ int mx, int my){
+ const int lowres= s->avctx->lowres;
+ const int block_s= 8>>lowres;
+ const int s_mask= (2<<lowres)-1;
+ const int h_edge_pos = s->h_edge_pos >> (lowres+1);
+ const int v_edge_pos = s->v_edge_pos >> (lowres+1);
+ int emu=0, src_x, src_y, offset, sx, sy;
+ uint8_t *ptr;
+
+ if(s->quarter_sample){
+ mx/=2;
+ my/=2;
+ }
+
+ /* In case of 8X8, we construct a single chroma motion vector
+ with a special rounding */
+ mx= ff_h263_round_chroma(mx);
+ my= ff_h263_round_chroma(my);
+
+ sx= mx & s_mask;
+ sy= my & s_mask;
+ src_x = s->mb_x*block_s + (mx >> (lowres+1));
+ src_y = s->mb_y*block_s + (my >> (lowres+1));
+
+ offset = src_y * s->uvlinesize + src_x;
+ ptr = ref_picture[1] + offset;
+ if(s->flags&CODEC_FLAG_EMU_EDGE){
+ if( (unsigned)src_x > h_edge_pos - (!!sx) - block_s
+ || (unsigned)src_y > v_edge_pos - (!!sy) - block_s){
+ 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;
+ emu=1;
+ }
+ }
+ sx <<= 2 - lowres;
+ sy <<= 2 - lowres;
+ pix_op[lowres](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);
+}
+
+static inline void prefetch_motion(MpegEncContext *s, uint8_t **pix, int dir){
+ /* fetch pixels for estimated mv 4 macroblocks ahead
+ * optimized for 64byte cache lines */
+ const int shift = s->quarter_sample ? 2 : 1;
+ const int mx= (s->mv[dir][0][0]>>shift) + 16*s->mb_x + 8;
+ const int my= (s->mv[dir][0][1]>>shift) + 16*s->mb_y;
+ int off= mx + (my + (s->mb_x&3)*4)*s->linesize + 64;
+ s->dsp.prefetch(pix[0]+off, s->linesize, 4);
+ off= (mx>>1) + ((my>>1) + (s->mb_x&7))*s->uvlinesize + 64;
+ s->dsp.prefetch(pix[1]+off, pix[2]-pix[1], 2);
+}
+
+/**
+ * motion compensation of a single macroblock
+ * @param s context
+ * @param dest_y luma destination pointer
+ * @param dest_cb chroma cb/u destination pointer
+ * @param dest_cr chroma cr/v destination pointer
+ * @param dir direction (0->forward, 1->backward)
+ * @param ref_picture array[3] of pointers to the 3 planes of the reference picture
+ * @param pic_op halfpel motion compensation function (average or put normally)
+ * @param pic_op qpel motion compensation function (average or put normally)
+ * the motion vectors are taken from s->mv and the MV type from s->mv_type
+ */
+static inline void MPV_motion(MpegEncContext *s,
+ uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
+ int dir, uint8_t **ref_picture,
+ op_pixels_func (*pix_op)[4], qpel_mc_func (*qpix_op)[16])
+{
+ int dxy, mx, my, src_x, src_y, motion_x, motion_y;
+ int mb_x, mb_y, i;
+ uint8_t *ptr, *dest;
+
+ mb_x = s->mb_x;
+ mb_y = s->mb_y;
+
+ prefetch_motion(s, ref_picture, dir);
+
+ if(s->obmc && s->pict_type != B_TYPE){
+ int16_t mv_cache[4][4][2];
+ const int xy= s->mb_x + s->mb_y*s->mb_stride;
+ const int mot_stride= s->b8_stride;
+ const int mot_xy= mb_x*2 + mb_y*2*mot_stride;
+
+ assert(!s->mb_skipped);
+
+ memcpy(mv_cache[1][1], s->current_picture.motion_val[0][mot_xy ], sizeof(int16_t)*4);
+ memcpy(mv_cache[2][1], s->current_picture.motion_val[0][mot_xy+mot_stride], sizeof(int16_t)*4);
+ memcpy(mv_cache[3][1], s->current_picture.motion_val[0][mot_xy+mot_stride], sizeof(int16_t)*4);
+
+ if(mb_y==0 || IS_INTRA(s->current_picture.mb_type[xy-s->mb_stride])){
+ memcpy(mv_cache[0][1], mv_cache[1][1], sizeof(int16_t)*4);
+ }else{
+ memcpy(mv_cache[0][1], s->current_picture.motion_val[0][mot_xy-mot_stride], sizeof(int16_t)*4);
+ }
+
+ if(mb_x==0 || IS_INTRA(s->current_picture.mb_type[xy-1])){
+ *(int32_t*)mv_cache[1][0]= *(int32_t*)mv_cache[1][1];
+ *(int32_t*)mv_cache[2][0]= *(int32_t*)mv_cache[2][1];
+ }else{
+ *(int32_t*)mv_cache[1][0]= *(int32_t*)s->current_picture.motion_val[0][mot_xy-1];
+ *(int32_t*)mv_cache[2][0]= *(int32_t*)s->current_picture.motion_val[0][mot_xy-1+mot_stride];
+ }
+
+ if(mb_x+1>=s->mb_width || IS_INTRA(s->current_picture.mb_type[xy+1])){
+ *(int32_t*)mv_cache[1][3]= *(int32_t*)mv_cache[1][2];
+ *(int32_t*)mv_cache[2][3]= *(int32_t*)mv_cache[2][2];
+ }else{
+ *(int32_t*)mv_cache[1][3]= *(int32_t*)s->current_picture.motion_val[0][mot_xy+2];
+ *(int32_t*)mv_cache[2][3]= *(int32_t*)s->current_picture.motion_val[0][mot_xy+2+mot_stride];
+ }
+
+ mx = 0;
+ my = 0;
+ for(i=0;i<4;i++) {
+ const int x= (i&1)+1;
+ const int y= (i>>1)+1;
+ int16_t mv[5][2]= {
+ {mv_cache[y][x ][0], mv_cache[y][x ][1]},
+ {mv_cache[y-1][x][0], mv_cache[y-1][x][1]},
+ {mv_cache[y][x-1][0], mv_cache[y][x-1][1]},
+ {mv_cache[y][x+1][0], mv_cache[y][x+1][1]},
+ {mv_cache[y+1][x][0], mv_cache[y+1][x][1]}};
+ //FIXME cleanup
+ obmc_motion(s, dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize,
+ ref_picture[0],
+ mb_x * 16 + (i & 1) * 8, mb_y * 16 + (i >>1) * 8,
+ pix_op[1],
+ mv);
+
+ mx += mv[0][0];
+ my += mv[0][1];
+ }
+ if(!(s->flags&CODEC_FLAG_GRAY))
+ chroma_4mv_motion(s, dest_cb, dest_cr, ref_picture, pix_op[1], mx, my);
+
+ return;
+ }
+
+ switch(s->mv_type) {
+ case MV_TYPE_16X16:
+ if(s->mcsel){
+ if(s->real_sprite_warping_points==1){
+ gmc1_motion(s, dest_y, dest_cb, dest_cr,
+ ref_picture);
+ }else{
+ gmc_motion(s, dest_y, dest_cb, dest_cr,
+ ref_picture);
+ }
+ }else if(s->quarter_sample){
+ qpel_motion(s, dest_y, dest_cb, dest_cr,
+ 0, 0, 0,
+ ref_picture, pix_op, qpix_op,
+ s->mv[dir][0][0], s->mv[dir][0][1], 16);
+ }else if(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);
+ }else
+ {
+ 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);
+ }
+ break;
+ case MV_TYPE_8X8:
+ mx = 0;
+ my = 0;
+ if(s->quarter_sample){
+ for(i=0;i<4;i++) {
+ motion_x = s->mv[dir][i][0];
+ motion_y = s->mv[dir][i][1];
+
+ dxy = ((motion_y & 3) << 2) | (motion_x & 3);
+ src_x = mb_x * 16 + (motion_x >> 2) + (i & 1) * 8;
+ src_y = mb_y * 16 + (motion_y >> 2) + (i >>1) * 8;
+
+ /* WARNING: do no forget half pels */
+ src_x = av_clip(src_x, -16, s->width);
+ if (src_x == s->width)
+ dxy &= ~3;
+ src_y = av_clip(src_y, -16, s->height);
+ if (src_y == s->height)
+ dxy &= ~12;
+
+ ptr = ref_picture[0] + (src_y * s->linesize) + (src_x);
+ if(s->flags&CODEC_FLAG_EMU_EDGE){
+ if( (unsigned)src_x > s->h_edge_pos - (motion_x&3) - 8
+ || (unsigned)src_y > s->v_edge_pos - (motion_y&3) - 8 ){
+ ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->linesize, 9, 9, src_x, src_y, s->h_edge_pos, s->v_edge_pos);
+ ptr= s->edge_emu_buffer;
+ }
+ }
+ dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize;
+ qpix_op[1][dxy](dest, ptr, s->linesize);
+
+ mx += s->mv[dir][i][0]/2;
+ my += s->mv[dir][i][1]/2;
+ }
+ }else{
+ for(i=0;i<4;i++) {
+ hpel_motion(s, dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize,
+ ref_picture[0], 0, 0,
+ mb_x * 16 + (i & 1) * 8, mb_y * 16 + (i >>1) * 8,
+ s->width, s->height, s->linesize,
+ s->h_edge_pos, s->v_edge_pos,
+ 8, 8, pix_op[1],
+ s->mv[dir][i][0], s->mv[dir][i][1]);
+
+ mx += s->mv[dir][i][0];
+ my += s->mv[dir][i][1];
+ }
+ }
+
+ if(!(s->flags&CODEC_FLAG_GRAY))
+ chroma_4mv_motion(s, dest_cb, dest_cr, ref_picture, pix_op[1], mx, my);
+ break;
+ case MV_TYPE_FIELD:
+ if (s->picture_structure == PICT_FRAME) {
+ if(s->quarter_sample){
+ for(i=0; i<2; i++){
+ qpel_motion(s, dest_y, dest_cb, dest_cr,
+ 1, i, s->field_select[dir][i],
+ ref_picture, pix_op, qpix_op,
+ s->mv[dir][i][0], s->mv[dir][i][1], 8);
+ }
+ }else{
+ /* top field */
+ 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);
+ /* 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);
+ }
+ } else {
+ if(s->picture_structure != s->field_select[dir][0] + 1 && s->pict_type != B_TYPE && !s->first_field){
+ ref_picture= s->current_picture_ptr->data;
+ }
+
+ 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);
+ }
+ break;
+ case MV_TYPE_16X8:
+ for(i=0; i<2; i++){
+ uint8_t ** ref2picture;
+
+ if(s->picture_structure == s->field_select[dir][i] + 1 || s->pict_type == B_TYPE || s->first_field){
+ ref2picture= ref_picture;
+ }else{
+ ref2picture= s->current_picture_ptr->data;
+ }
+
+ 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);
+
+ dest_y += 16*s->linesize;
+ dest_cb+= (16>>s->chroma_y_shift)*s->uvlinesize;
+ dest_cr+= (16>>s->chroma_y_shift)*s->uvlinesize;
+ }
+ break;
+ case MV_TYPE_DMV:
+ if(s->picture_structure == PICT_FRAME){
+ for(i=0; i<2; i++){
+ int j;
+ for(j=0; j<2; j++){
+ 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);
+ }
+ pix_op = s->dsp.avg_pixels_tab;
+ }
+ }else{
+ for(i=0; i<2; i++){
+ 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);
+
+ // after put we make avg of the same block
+ pix_op=s->dsp.avg_pixels_tab;
+
+ //opposite parity is always in the same frame if this is second field
+ if(!s->first_field){
+ ref_picture = s->current_picture_ptr->data;
+ }
+ }
+ }
+ break;
+ default: assert(0);
+ }
+}
+
+/**
+ * motion compensation of a single macroblock
+ * @param s context
+ * @param dest_y luma destination pointer
+ * @param dest_cb chroma cb/u destination pointer
+ * @param dest_cr chroma cr/v destination pointer
+ * @param dir direction (0->forward, 1->backward)
+ * @param ref_picture array[3] of pointers to the 3 planes of the reference picture
+ * @param pic_op halfpel motion compensation function (average or put normally)
+ * the motion vectors are taken from s->mv and the MV type from s->mv_type
+ */
+static inline void MPV_motion_lowres(MpegEncContext *s,
+ uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
+ int dir, uint8_t **ref_picture,
+ h264_chroma_mc_func *pix_op)
+{
+ int mx, my;
+ int mb_x, mb_y, i;
+ const int lowres= s->avctx->lowres;
+ const int block_s= 8>>lowres;
+
+ mb_x = s->mb_x;
+ mb_y = s->mb_y;
+
+ switch(s->mv_type) {
+ case MV_TYPE_16X16:
+ 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);
+ break;
+ case MV_TYPE_8X8:
+ mx = 0;
+ my = 0;
+ for(i=0;i<4;i++) {
+ hpel_motion_lowres(s, dest_y + ((i & 1) + (i >> 1) * s->linesize)*block_s,
+ ref_picture[0], 0, 0,
+ (2*mb_x + (i & 1))*block_s, (2*mb_y + (i >>1))*block_s,
+ s->width, s->height, s->linesize,
+ s->h_edge_pos >> lowres, s->v_edge_pos >> lowres,
+ block_s, block_s, pix_op,
+ s->mv[dir][i][0], s->mv[dir][i][1]);
+
+ mx += s->mv[dir][i][0];
+ my += s->mv[dir][i][1];
+ }
+
+ if(!(s->flags&CODEC_FLAG_GRAY))
+ chroma_4mv_motion_lowres(s, dest_cb, dest_cr, ref_picture, pix_op, mx, my);
+ break;
+ case MV_TYPE_FIELD:
+ if (s->picture_structure == PICT_FRAME) {
+ /* top field */
+ 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);
+ /* 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);
+ } else {
+ if(s->picture_structure != s->field_select[dir][0] + 1 && s->pict_type != B_TYPE && !s->first_field){
+ ref_picture= s->current_picture_ptr->data;
+ }
+
+ 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);
+ }
+ break;
+ case MV_TYPE_16X8:
+ for(i=0; i<2; i++){
+ uint8_t ** ref2picture;
+
+ if(s->picture_structure == s->field_select[dir][i] + 1 || s->pict_type == B_TYPE || s->first_field){
+ ref2picture= ref_picture;
+ }else{
+ ref2picture= s->current_picture_ptr->data;
+ }
+
+ 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);
+
+ dest_y += 2*block_s*s->linesize;
+ dest_cb+= (2*block_s>>s->chroma_y_shift)*s->uvlinesize;
+ dest_cr+= (2*block_s>>s->chroma_y_shift)*s->uvlinesize;
+ }
+ break;
+ case MV_TYPE_DMV:
+ if(s->picture_structure == PICT_FRAME){
+ for(i=0; i<2; i++){
+ int j;
+ for(j=0; j<2; j++){
+ 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);
+ }
+ pix_op = s->dsp.avg_h264_chroma_pixels_tab;
+ }
+ }else{
+ for(i=0; i<2; i++){
+ 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);
+
+ // after put we make avg of the same block
+ pix_op = s->dsp.avg_h264_chroma_pixels_tab;
+
+ //opposite parity is always in the same frame if this is second field
+ if(!s->first_field){
+ ref_picture = s->current_picture_ptr->data;
+ }
+ }
+ }
+ break;
+ default: assert(0);
+ }
+}
+
+/* put block[] to dest[] */
+static inline void put_dct(MpegEncContext *s,
+ DCTELEM *block, int i, uint8_t *dest, int line_size, int qscale)
+{
+ s->dct_unquantize_intra(s, block, i, qscale);
+ s->dsp.idct_put (dest, line_size, block);
+}
+
+/* add block[] to dest[] */
+static inline void add_dct(MpegEncContext *s,
+ DCTELEM *block, int i, uint8_t *dest, int line_size)
+{
+ if (s->block_last_index[i] >= 0) {
+ s->dsp.idct_add (dest, line_size, block);
+ }
+}
+
+static inline void add_dequant_dct(MpegEncContext *s,
+ DCTELEM *block, int i, uint8_t *dest, int line_size, int qscale)
+{
+ if (s->block_last_index[i] >= 0) {
+ s->dct_unquantize_inter(s, block, i, qscale);
+
+ s->dsp.idct_add (dest, line_size, block);
+ }
+}
+
+/**
+ * cleans dc, ac, coded_block for the current non intra MB
+ */
+void ff_clean_intra_table_entries(MpegEncContext *s)
+{
+ int wrap = s->b8_stride;
+ int xy = s->block_index[0];
+
+ s->dc_val[0][xy ] =
+ s->dc_val[0][xy + 1 ] =
+ s->dc_val[0][xy + wrap] =
+ s->dc_val[0][xy + 1 + wrap] = 1024;
+ /* ac pred */
+ memset(s->ac_val[0][xy ], 0, 32 * sizeof(int16_t));
+ memset(s->ac_val[0][xy + wrap], 0, 32 * sizeof(int16_t));
+ if (s->msmpeg4_version>=3) {
+ s->coded_block[xy ] =
+ s->coded_block[xy + 1 ] =
+ s->coded_block[xy + wrap] =
+ s->coded_block[xy + 1 + wrap] = 0;
+ }
+ /* chroma */
+ wrap = s->mb_stride;
+ xy = s->mb_x + s->mb_y * wrap;
+ s->dc_val[1][xy] =
+ s->dc_val[2][xy] = 1024;
+ /* ac pred */
+ memset(s->ac_val[1][xy], 0, 16 * sizeof(int16_t));
+ memset(s->ac_val[2][xy], 0, 16 * sizeof(int16_t));
+
+ s->mbintra_table[xy]= 0;
+}
+
+/* generic function called after a macroblock has been parsed by the
+ decoder or after it has been encoded by the encoder.
+
+ Important variables used:
+ s->mb_intra : true if intra macroblock
+ s->mv_dir : motion vector direction
+ s->mv_type : motion vector type
+ s->mv : motion vector
+ s->interlaced_dct : true if interlaced dct used (mpeg2)
+ */
+static av_always_inline void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64], int lowres_flag)
+{
+ int mb_x, mb_y;
+ const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
+#ifdef HAVE_XVMC
+ if(s->avctx->xvmc_acceleration){
+ XVMC_decode_mb(s);//xvmc uses pblocks
+ return;
+ }
+#endif
+
+ mb_x = s->mb_x;
+ mb_y = s->mb_y;
+
+ if(s->avctx->debug&FF_DEBUG_DCT_COEFF) {
+ /* save DCT coefficients */
+ int i,j;
+ DCTELEM *dct = &s->current_picture.dct_coeff[mb_xy*64*6];
+ for(i=0; i<6; i++)
+ for(j=0; j<64; j++)
+ *dct++ = block[i][s->dsp.idct_permutation[j]];
+ }
+
+ s->current_picture.qscale_table[mb_xy]= s->qscale;
+
+ /* update DC predictors for P macroblocks */
+ if (!s->mb_intra) {
+ if (s->h263_pred || s->h263_aic) {
+ if(s->mbintra_table[mb_xy])
+ ff_clean_intra_table_entries(s);
+ } else {
+ s->last_dc[0] =
+ s->last_dc[1] =
+ s->last_dc[2] = 128 << s->intra_dc_precision;
+ }
+ }
+ else if (s->h263_pred || s->h263_aic)
+ s->mbintra_table[mb_xy]=1;
+
+ if ((s->flags&CODEC_FLAG_PSNR) || !(s->encoding && (s->intra_only || s->pict_type==B_TYPE) && s->avctx->mb_decision != FF_MB_DECISION_RD)) { //FIXME precalc
+ uint8_t *dest_y, *dest_cb, *dest_cr;
+ int dct_linesize, dct_offset;
+ op_pixels_func (*op_pix)[4];
+ qpel_mc_func (*op_qpix)[16];
+ const int linesize= s->current_picture.linesize[0]; //not s->linesize as this would be wrong for field pics
+ const int uvlinesize= s->current_picture.linesize[1];
+ const int readable= s->pict_type != B_TYPE || s->encoding || s->avctx->draw_horiz_band || lowres_flag;
+ const int block_size= lowres_flag ? 8>>s->avctx->lowres : 8;
+
+ /* avoid copy if macroblock skipped in last frame too */
+ /* skip only during decoding as we might trash the buffers during encoding a bit */
+ if(!s->encoding){
+ uint8_t *mbskip_ptr = &s->mbskip_table[mb_xy];
+ const int age= s->current_picture.age;
+
+ assert(age);
+
+ if (s->mb_skipped) {
+ s->mb_skipped= 0;
+ assert(s->pict_type!=I_TYPE);
+
+ (*mbskip_ptr) ++; /* indicate that this time we skipped it */
+ if(*mbskip_ptr >99) *mbskip_ptr= 99;
+
+ /* if previous was skipped too, then nothing to do ! */
+ if (*mbskip_ptr >= age && s->current_picture.reference){
+ return;
+ }
+ } else if(!s->current_picture.reference){
+ (*mbskip_ptr) ++; /* increase counter so the age can be compared cleanly */
+ if(*mbskip_ptr >99) *mbskip_ptr= 99;
+ } else{
+ *mbskip_ptr = 0; /* not skipped */
+ }
+ }
+
+ dct_linesize = linesize << s->interlaced_dct;
+ dct_offset =(s->interlaced_dct)? linesize : linesize*block_size;
+
+ if(readable){
+ dest_y= s->dest[0];
+ dest_cb= s->dest[1];
+ dest_cr= s->dest[2];
+ }else{
+ dest_y = s->b_scratchpad;
+ dest_cb= s->b_scratchpad+16*linesize;
+ dest_cr= s->b_scratchpad+32*linesize;
+ }
+
+ if (!s->mb_intra) {
+ /* motion handling */
+ /* decoding or more than one mb_type (MC was already done otherwise) */
+ if(!s->encoding){
+ if(lowres_flag){
+ h264_chroma_mc_func *op_pix = s->dsp.put_h264_chroma_pixels_tab;
+
+ if (s->mv_dir & MV_DIR_FORWARD) {
+ MPV_motion_lowres(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.data, op_pix);
+ op_pix = s->dsp.avg_h264_chroma_pixels_tab;
+ }
+ if (s->mv_dir & MV_DIR_BACKWARD) {
+ MPV_motion_lowres(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.data, op_pix);
+ }
+ }else{
+ op_qpix= s->me.qpel_put;
+ if ((!s->no_rounding) || s->pict_type==B_TYPE){
+ op_pix = s->dsp.put_pixels_tab;
+ }else{
+ op_pix = s->dsp.put_no_rnd_pixels_tab;
+ }
+ if (s->mv_dir & MV_DIR_FORWARD) {
+ MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.data, op_pix, op_qpix);
+ op_pix = s->dsp.avg_pixels_tab;
+ op_qpix= s->me.qpel_avg;
+ }
+ if (s->mv_dir & MV_DIR_BACKWARD) {
+ MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.data, op_pix, op_qpix);
+ }
+ }
+ }
+
+ /* skip dequant / idct if we are really late ;) */
+ if(s->hurry_up>1) goto skip_idct;
+ if(s->avctx->skip_idct){
+ if( (s->avctx->skip_idct >= AVDISCARD_NONREF && s->pict_type == B_TYPE)
+ ||(s->avctx->skip_idct >= AVDISCARD_NONKEY && s->pict_type != I_TYPE)
+ || s->avctx->skip_idct >= AVDISCARD_ALL)
+ goto skip_idct;
+ }
+
+ /* add dct residue */
+ if(s->encoding || !( s->h263_msmpeg4 || s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO
+ || (s->codec_id==CODEC_ID_MPEG4 && !s->mpeg_quant))){
+ add_dequant_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale);
+ add_dequant_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale);
+ add_dequant_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale);
+ add_dequant_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale);
+
+ if(!(s->flags&CODEC_FLAG_GRAY)){
+ if (s->chroma_y_shift){
+ add_dequant_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale);
+ add_dequant_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale);
+ }else{
+ dct_linesize >>= 1;
+ dct_offset >>=1;
+ add_dequant_dct(s, block[4], 4, dest_cb, dct_linesize, s->chroma_qscale);
+ add_dequant_dct(s, block[5], 5, dest_cr, dct_linesize, s->chroma_qscale);
+ add_dequant_dct(s, block[6], 6, dest_cb + dct_offset, dct_linesize, s->chroma_qscale);
+ add_dequant_dct(s, block[7], 7, dest_cr + dct_offset, dct_linesize, s->chroma_qscale);
+ }
+ }
+ } else if(s->codec_id != CODEC_ID_WMV2){
+ add_dct(s, block[0], 0, dest_y , dct_linesize);
+ add_dct(s, block[1], 1, dest_y + block_size, dct_linesize);
+ add_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize);
+ add_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize);
+
+ if(!(s->flags&CODEC_FLAG_GRAY)){
+ if(s->chroma_y_shift){//Chroma420
+ add_dct(s, block[4], 4, dest_cb, uvlinesize);
+ add_dct(s, block[5], 5, dest_cr, uvlinesize);
+ }else{
+ //chroma422
+ dct_linesize = uvlinesize << s->interlaced_dct;
+ dct_offset =(s->interlaced_dct)? uvlinesize : uvlinesize*8;
+
+ add_dct(s, block[4], 4, dest_cb, dct_linesize);
+ add_dct(s, block[5], 5, dest_cr, dct_linesize);
+ add_dct(s, block[6], 6, dest_cb+dct_offset, dct_linesize);
+ add_dct(s, block[7], 7, dest_cr+dct_offset, dct_linesize);
+ if(!s->chroma_x_shift){//Chroma444
+ add_dct(s, block[8], 8, dest_cb+8, dct_linesize);
+ add_dct(s, block[9], 9, dest_cr+8, dct_linesize);
+ add_dct(s, block[10], 10, dest_cb+8+dct_offset, dct_linesize);
+ add_dct(s, block[11], 11, dest_cr+8+dct_offset, dct_linesize);
+ }
+ }
+ }//fi gray
+ }
+ else{
+ ff_wmv2_add_mb(s, block, dest_y, dest_cb, dest_cr);
+ }
+ } else {
+ /* dct only in intra block */
+ if(s->encoding || !(s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO)){
+ put_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale);
+ put_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale);
+ put_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale);
+ put_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale);
+
+ if(!(s->flags&CODEC_FLAG_GRAY)){
+ if(s->chroma_y_shift){
+ put_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale);
+ put_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale);
+ }else{
+ dct_offset >>=1;
+ dct_linesize >>=1;
+ put_dct(s, block[4], 4, dest_cb, dct_linesize, s->chroma_qscale);
+ put_dct(s, block[5], 5, dest_cr, dct_linesize, s->chroma_qscale);
+ put_dct(s, block[6], 6, dest_cb + dct_offset, dct_linesize, s->chroma_qscale);
+ put_dct(s, block[7], 7, dest_cr + dct_offset, dct_linesize, s->chroma_qscale);
+ }
+ }
+ }else{
+ s->dsp.idct_put(dest_y , dct_linesize, block[0]);
+ s->dsp.idct_put(dest_y + block_size, dct_linesize, block[1]);
+ s->dsp.idct_put(dest_y + dct_offset , dct_linesize, block[2]);
+ s->dsp.idct_put(dest_y + dct_offset + block_size, dct_linesize, block[3]);
+
+ if(!(s->flags&CODEC_FLAG_GRAY)){
+ if(s->chroma_y_shift){
+ s->dsp.idct_put(dest_cb, uvlinesize, block[4]);
+ s->dsp.idct_put(dest_cr, uvlinesize, block[5]);
+ }else{
+
+ dct_linesize = uvlinesize << s->interlaced_dct;
+ dct_offset =(s->interlaced_dct)? uvlinesize : uvlinesize*8;
+
+ s->dsp.idct_put(dest_cb, dct_linesize, block[4]);
+ s->dsp.idct_put(dest_cr, dct_linesize, block[5]);
+ s->dsp.idct_put(dest_cb + dct_offset, dct_linesize, block[6]);
+ s->dsp.idct_put(dest_cr + dct_offset, dct_linesize, block[7]);
+ if(!s->chroma_x_shift){//Chroma444
+ s->dsp.idct_put(dest_cb + 8, dct_linesize, block[8]);
+ s->dsp.idct_put(dest_cr + 8, dct_linesize, block[9]);
+ s->dsp.idct_put(dest_cb + 8 + dct_offset, dct_linesize, block[10]);
+ s->dsp.idct_put(dest_cr + 8 + dct_offset, dct_linesize, block[11]);
+ }
+ }
+ }//gray
+ }
+ }
+skip_idct:
+ if(!readable){
+ s->dsp.put_pixels_tab[0][0](s->dest[0], dest_y , linesize,16);
+ s->dsp.put_pixels_tab[s->chroma_x_shift][0](s->dest[1], dest_cb, uvlinesize,16 >> s->chroma_y_shift);
+ s->dsp.put_pixels_tab[s->chroma_x_shift][0](s->dest[2], dest_cr, uvlinesize,16 >> s->chroma_y_shift);
+ }
+ }
+}
+
+void MPV_decode_mb(MpegEncContext *s, DCTELEM block[12][64]){
+ if(s->avctx->lowres) MPV_decode_mb_internal(s, block, 1);
+ else MPV_decode_mb_internal(s, block, 0);
+}
+
+#ifdef CONFIG_ENCODERS
+
+static inline void dct_single_coeff_elimination(MpegEncContext *s, int n, int threshold)
+{
+ static const char tab[64]=
+ {3,2,2,1,1,1,1,1,
+ 1,1,1,1,1,1,1,1,
+ 1,1,1,1,1,1,1,1,
+ 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0};
+ int score=0;
+ int run=0;
+ int i;
+ DCTELEM *block= s->block[n];
+ const int last_index= s->block_last_index[n];
+ int skip_dc;
+
+ if(threshold<0){
+ skip_dc=0;
+ threshold= -threshold;
+ }else
+ skip_dc=1;
+
+ /* are all which we could set to zero are allready zero? */
+ if(last_index<=skip_dc - 1) return;
+
+ for(i=0; i<=last_index; i++){
+ const int j = s->intra_scantable.permutated[i];
+ const int level = FFABS(block[j]);
+ if(level==1){
+ if(skip_dc && i==0) continue;
+ score+= tab[run];
+ run=0;
+ }else if(level>1){
+ return;
+ }else{
+ run++;
+ }
+ }
+ if(score >= threshold) return;
+ for(i=skip_dc; i<=last_index; i++){
+ const int j = s->intra_scantable.permutated[i];
+ block[j]=0;
+ }
+ if(block[0]) s->block_last_index[n]= 0;
+ else s->block_last_index[n]= -1;
+}
+
+static inline void clip_coeffs(MpegEncContext *s, DCTELEM *block, int last_index)
+{
+ int i;
+ const int maxlevel= s->max_qcoeff;
+ const int minlevel= s->min_qcoeff;
+ int overflow=0;
+
+ if(s->mb_intra){
+ i=1; //skip clipping of intra dc
+ }else
+ i=0;
+
+ for(;i<=last_index; i++){
+ const int j= s->intra_scantable.permutated[i];
+ int level = block[j];
+
+ if (level>maxlevel){
+ level=maxlevel;
+ overflow++;
+ }else if(level<minlevel){
+ level=minlevel;
+ overflow++;
+ }
+
+ block[j]= level;
+ }
+
+ if(overflow && s->avctx->mb_decision == FF_MB_DECISION_SIMPLE)
+ av_log(s->avctx, AV_LOG_INFO, "warning, clipping %d dct coefficients to %d..%d\n", overflow, minlevel, maxlevel);
+}
+
+#endif //CONFIG_ENCODERS
+
+/**
+ *
+ * @param h is the normal height, this will be reduced automatically if needed for the last row
+ */
+void ff_draw_horiz_band(MpegEncContext *s, int y, int h){
+ if (s->avctx->draw_horiz_band) {
+ AVFrame *src;
+ int offset[4];
+
+ if(s->picture_structure != PICT_FRAME){
+ h <<= 1;
+ y <<= 1;
+ if(s->first_field && !(s->avctx->slice_flags&SLICE_FLAG_ALLOW_FIELD)) return;
+ }
+
+ h= FFMIN(h, s->avctx->height - y);
+
+ if(s->pict_type==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)
+ src= (AVFrame*)s->last_picture_ptr;
+ else
+ return;
+
+ if(s->pict_type==B_TYPE && s->picture_structure == PICT_FRAME && s->out_format != FMT_H264){
+ offset[0]=
+ offset[1]=
+ offset[2]=
+ offset[3]= 0;
+ }else{
+ offset[0]= y * s->linesize;;
+ offset[1]=
+ offset[2]= (y >> s->chroma_y_shift) * s->uvlinesize;
+ offset[3]= 0;
+ }
+
+ emms_c();
+
+ s->avctx->draw_horiz_band(s->avctx, src, offset,
+ y, s->picture_structure, h);
+ }
+}
+
+void ff_init_block_index(MpegEncContext *s){ //FIXME maybe rename
+ const int linesize= s->current_picture.linesize[0]; //not s->linesize as this would be wrong for field pics
+ const int uvlinesize= s->current_picture.linesize[1];
+ const int mb_size= 4 - s->avctx->lowres;
+
+ s->block_index[0]= s->b8_stride*(s->mb_y*2 ) - 2 + s->mb_x*2;
+ s->block_index[1]= s->b8_stride*(s->mb_y*2 ) - 1 + s->mb_x*2;
+ s->block_index[2]= s->b8_stride*(s->mb_y*2 + 1) - 2 + s->mb_x*2;
+ s->block_index[3]= s->b8_stride*(s->mb_y*2 + 1) - 1 + s->mb_x*2;
+ s->block_index[4]= s->mb_stride*(s->mb_y + 1) + s->b8_stride*s->mb_height*2 + s->mb_x - 1;
+ s->block_index[5]= s->mb_stride*(s->mb_y + s->mb_height + 2) + s->b8_stride*s->mb_height*2 + s->mb_x - 1;
+ //block_index is not used by mpeg2, so it is not affected by chroma_format
+
+ s->dest[0] = s->current_picture.data[0] + ((s->mb_x - 1) << mb_size);
+ s->dest[1] = s->current_picture.data[1] + ((s->mb_x - 1) << (mb_size - s->chroma_x_shift));
+ s->dest[2] = s->current_picture.data[2] + ((s->mb_x - 1) << (mb_size - s->chroma_x_shift));
+
+ if(!(s->pict_type==B_TYPE && s->avctx->draw_horiz_band && 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);
+ }
+}
+
+#ifdef CONFIG_ENCODERS
+
+static void get_vissual_weight(int16_t *weight, uint8_t *ptr, int stride){
+ int x, y;
+//FIXME optimize
+ for(y=0; y<8; y++){
+ for(x=0; x<8; x++){
+ int x2, y2;
+ int sum=0;
+ int sqr=0;
+ int count=0;
+
+ for(y2= FFMAX(y-1, 0); y2 < FFMIN(8, y+2); y2++){
+ for(x2= FFMAX(x-1, 0); x2 < FFMIN(8, x+2); x2++){
+ int v= ptr[x2 + y2*stride];
+ sum += v;
+ sqr += v*v;
+ count++;
+ }
+ }
+ weight[x + 8*y]= (36*ff_sqrt(count*sqr - sum*sum)) / count;
+ }
+ }
+}
+
+static av_always_inline void encode_mb_internal(MpegEncContext *s, int motion_x, int motion_y, int mb_block_height, int mb_block_count)
+{
+ int16_t weight[8][64];
+ DCTELEM orig[8][64];
+ const int mb_x= s->mb_x;
+ const int mb_y= s->mb_y;
+ int i;
+ int skip_dct[8];
+ int dct_offset = s->linesize*8; //default for progressive frames
+ uint8_t *ptr_y, *ptr_cb, *ptr_cr;
+ int wrap_y, wrap_c;
+
+ for(i=0; i<mb_block_count; i++) skip_dct[i]=s->skipdct;
+
+ if(s->adaptive_quant){
+ const int last_qp= s->qscale;
+ const int mb_xy= mb_x + mb_y*s->mb_stride;
+
+ s->lambda= s->lambda_table[mb_xy];
+ update_qscale(s);
+
+ if(!(s->flags&CODEC_FLAG_QP_RD)){
+ s->qscale= s->current_picture_ptr->qscale_table[mb_xy];
+ s->dquant= s->qscale - last_qp;
+
+ if(s->out_format==FMT_H263){
+ s->dquant= av_clip(s->dquant, -2, 2);
+
+ if(s->codec_id==CODEC_ID_MPEG4){
+ if(!s->mb_intra){
+ if(s->pict_type == B_TYPE){
+ if(s->dquant&1 || s->mv_dir&MV_DIRECT)
+ s->dquant= 0;
+ }
+ if(s->mv_type==MV_TYPE_8X8)
+ s->dquant=0;
+ }
+ }
+ }
+ }
+ ff_set_qscale(s, last_qp + s->dquant);
+ }else if(s->flags&CODEC_FLAG_QP_RD)
+ ff_set_qscale(s, s->qscale + s->dquant);
+
+ wrap_y = s->linesize;
+ wrap_c = s->uvlinesize;
+ ptr_y = s->new_picture.data[0] + (mb_y * 16 * wrap_y) + mb_x * 16;
+ ptr_cb = s->new_picture.data[1] + (mb_y * mb_block_height * wrap_c) + mb_x * 8;
+ ptr_cr = s->new_picture.data[2] + (mb_y * mb_block_height * wrap_c) + mb_x * 8;
+
+ if(mb_x*16+16 > s->width || mb_y*16+16 > s->height){
+ uint8_t *ebuf= s->edge_emu_buffer + 32;
+ ff_emulated_edge_mc(ebuf , ptr_y , wrap_y,16,16,mb_x*16,mb_y*16, s->width , s->height);
+ ptr_y= ebuf;
+ ff_emulated_edge_mc(ebuf+18*wrap_y , ptr_cb, wrap_c, 8, mb_block_height, mb_x*8, mb_y*8, s->width>>1, s->height>>1);
+ ptr_cb= ebuf+18*wrap_y;
+ ff_emulated_edge_mc(ebuf+18*wrap_y+8, ptr_cr, wrap_c, 8, mb_block_height, mb_x*8, mb_y*8, s->width>>1, s->height>>1);
+ ptr_cr= ebuf+18*wrap_y+8;
+ }
+
+ if (s->mb_intra) {
+ if(s->flags&CODEC_FLAG_INTERLACED_DCT){
+ int progressive_score, interlaced_score;
+
+ s->interlaced_dct=0;
+ progressive_score= s->dsp.ildct_cmp[4](s, ptr_y , NULL, wrap_y, 8)
+ +s->dsp.ildct_cmp[4](s, ptr_y + wrap_y*8, NULL, wrap_y, 8) - 400;
+
+ if(progressive_score > 0){
+ interlaced_score = s->dsp.ildct_cmp[4](s, ptr_y , NULL, wrap_y*2, 8)
+ +s->dsp.ildct_cmp[4](s, ptr_y + wrap_y , NULL, wrap_y*2, 8);
+ if(progressive_score > interlaced_score){
+ s->interlaced_dct=1;
+
+ dct_offset= wrap_y;
+ wrap_y<<=1;
+ if (s->chroma_format == CHROMA_422)
+ wrap_c<<=1;
+ }
+ }
+ }
+
+ s->dsp.get_pixels(s->block[0], ptr_y , wrap_y);
+ s->dsp.get_pixels(s->block[1], ptr_y + 8, wrap_y);
+ s->dsp.get_pixels(s->block[2], ptr_y + dct_offset , wrap_y);
+ s->dsp.get_pixels(s->block[3], ptr_y + dct_offset + 8, wrap_y);
+
+ if(s->flags&CODEC_FLAG_GRAY){
+ skip_dct[4]= 1;
+ skip_dct[5]= 1;
+ }else{
+ s->dsp.get_pixels(s->block[4], ptr_cb, wrap_c);
+ s->dsp.get_pixels(s->block[5], ptr_cr, wrap_c);
+ if(!s->chroma_y_shift){ /* 422 */
+ s->dsp.get_pixels(s->block[6], ptr_cb + (dct_offset>>1), wrap_c);
+ s->dsp.get_pixels(s->block[7], ptr_cr + (dct_offset>>1), wrap_c);
+ }
+ }
+ }else{
+ op_pixels_func (*op_pix)[4];
+ qpel_mc_func (*op_qpix)[16];
+ uint8_t *dest_y, *dest_cb, *dest_cr;
+
+ dest_y = s->dest[0];
+ dest_cb = s->dest[1];
+ dest_cr = s->dest[2];
+
+ if ((!s->no_rounding) || s->pict_type==B_TYPE){
+ op_pix = s->dsp.put_pixels_tab;
+ op_qpix= s->dsp.put_qpel_pixels_tab;
+ }else{
+ op_pix = s->dsp.put_no_rnd_pixels_tab;
+ op_qpix= s->dsp.put_no_rnd_qpel_pixels_tab;
+ }
+
+ if (s->mv_dir & MV_DIR_FORWARD) {
+ MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.data, op_pix, op_qpix);
+ op_pix = s->dsp.avg_pixels_tab;
+ op_qpix= s->dsp.avg_qpel_pixels_tab;
+ }
+ if (s->mv_dir & MV_DIR_BACKWARD) {
+ MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.data, op_pix, op_qpix);
+ }
+
+ if(s->flags&CODEC_FLAG_INTERLACED_DCT){
+ int progressive_score, interlaced_score;
+
+ s->interlaced_dct=0;
+ progressive_score= s->dsp.ildct_cmp[0](s, dest_y , ptr_y , wrap_y, 8)
+ +s->dsp.ildct_cmp[0](s, dest_y + wrap_y*8, ptr_y + wrap_y*8, wrap_y, 8) - 400;
+
+ if(s->avctx->ildct_cmp == FF_CMP_VSSE) progressive_score -= 400;
+
+ if(progressive_score>0){
+ interlaced_score = s->dsp.ildct_cmp[0](s, dest_y , ptr_y , wrap_y*2, 8)
+ +s->dsp.ildct_cmp[0](s, dest_y + wrap_y , ptr_y + wrap_y , wrap_y*2, 8);
+
+ if(progressive_score > interlaced_score){
+ s->interlaced_dct=1;
+
+ dct_offset= wrap_y;
+ wrap_y<<=1;
+ if (s->chroma_format == CHROMA_422)
+ wrap_c<<=1;
+ }
+ }
+ }
+
+ s->dsp.diff_pixels(s->block[0], ptr_y , dest_y , wrap_y);
+ s->dsp.diff_pixels(s->block[1], ptr_y + 8, dest_y + 8, wrap_y);
+ s->dsp.diff_pixels(s->block[2], ptr_y + dct_offset , dest_y + dct_offset , wrap_y);
+ s->dsp.diff_pixels(s->block[3], ptr_y + dct_offset + 8, dest_y + dct_offset + 8, wrap_y);
+
+ if(s->flags&CODEC_FLAG_GRAY){
+ skip_dct[4]= 1;
+ skip_dct[5]= 1;
+ }else{
+ s->dsp.diff_pixels(s->block[4], ptr_cb, dest_cb, wrap_c);
+ s->dsp.diff_pixels(s->block[5], ptr_cr, dest_cr, wrap_c);
+ if(!s->chroma_y_shift){ /* 422 */
+ s->dsp.diff_pixels(s->block[6], ptr_cb + (dct_offset>>1), dest_cb + (dct_offset>>1), wrap_c);
+ s->dsp.diff_pixels(s->block[7], ptr_cr + (dct_offset>>1), dest_cr + (dct_offset>>1), wrap_c);
+ }
+ }
+ /* pre quantization */
+ if(s->current_picture.mc_mb_var[s->mb_stride*mb_y+ mb_x]<2*s->qscale*s->qscale){
+ //FIXME optimize
+ if(s->dsp.sad[1](NULL, ptr_y , dest_y , wrap_y, 8) < 20*s->qscale) skip_dct[0]= 1;
+ if(s->dsp.sad[1](NULL, ptr_y + 8, dest_y + 8, wrap_y, 8) < 20*s->qscale) skip_dct[1]= 1;
+ if(s->dsp.sad[1](NULL, ptr_y +dct_offset , dest_y +dct_offset , wrap_y, 8) < 20*s->qscale) skip_dct[2]= 1;
+ if(s->dsp.sad[1](NULL, ptr_y +dct_offset+ 8, dest_y +dct_offset+ 8, wrap_y, 8) < 20*s->qscale) skip_dct[3]= 1;
+ if(s->dsp.sad[1](NULL, ptr_cb , dest_cb , wrap_c, 8) < 20*s->qscale) skip_dct[4]= 1;
+ if(s->dsp.sad[1](NULL, ptr_cr , dest_cr , wrap_c, 8) < 20*s->qscale) skip_dct[5]= 1;
+ if(!s->chroma_y_shift){ /* 422 */
+ if(s->dsp.sad[1](NULL, ptr_cb +(dct_offset>>1), dest_cb +(dct_offset>>1), wrap_c, 8) < 20*s->qscale) skip_dct[6]= 1;
+ if(s->dsp.sad[1](NULL, ptr_cr +(dct_offset>>1), dest_cr +(dct_offset>>1), wrap_c, 8) < 20*s->qscale) skip_dct[7]= 1;
+ }
+ }
+ }
+
+ if(s->avctx->quantizer_noise_shaping){
+ if(!skip_dct[0]) get_vissual_weight(weight[0], ptr_y , wrap_y);
+ if(!skip_dct[1]) get_vissual_weight(weight[1], ptr_y + 8, wrap_y);
+ if(!skip_dct[2]) get_vissual_weight(weight[2], ptr_y + dct_offset , wrap_y);
+ if(!skip_dct[3]) get_vissual_weight(weight[3], ptr_y + dct_offset + 8, wrap_y);
+ if(!skip_dct[4]) get_vissual_weight(weight[4], ptr_cb , wrap_c);
+ if(!skip_dct[5]) get_vissual_weight(weight[5], ptr_cr , wrap_c);
+ if(!s->chroma_y_shift){ /* 422 */
+ if(!skip_dct[6]) get_vissual_weight(weight[6], ptr_cb + (dct_offset>>1), wrap_c);
+ if(!skip_dct[7]) get_vissual_weight(weight[7], ptr_cr + (dct_offset>>1), wrap_c);
+ }
+ memcpy(orig[0], s->block[0], sizeof(DCTELEM)*64*mb_block_count);
+ }
+
+ /* DCT & quantize */
+ assert(s->out_format!=FMT_MJPEG || s->qscale==8);
+ {
+ for(i=0;i<mb_block_count;i++) {
+ if(!skip_dct[i]){
+ int overflow;
+ s->block_last_index[i] = s->dct_quantize(s, s->block[i], i, s->qscale, &overflow);
+ // FIXME we could decide to change to quantizer instead of clipping
+ // JS: I don't think that would be a good idea it could lower quality instead
+ // of improve it. Just INTRADC clipping deserves changes in quantizer
+ if (overflow) clip_coeffs(s, s->block[i], s->block_last_index[i]);
+ }else
+ s->block_last_index[i]= -1;
+ }
+ if(s->avctx->quantizer_noise_shaping){
+ for(i=0;i<mb_block_count;i++) {
+ if(!skip_dct[i]){
+ s->block_last_index[i] = dct_quantize_refine(s, s->block[i], weight[i], orig[i], i, s->qscale);
+ }
+ }
+ }
+
+ if(s->luma_elim_threshold && !s->mb_intra)
+ for(i=0; i<4; i++)
+ dct_single_coeff_elimination(s, i, s->luma_elim_threshold);
+ if(s->chroma_elim_threshold && !s->mb_intra)
+ for(i=4; i<mb_block_count; i++)
+ dct_single_coeff_elimination(s, i, s->chroma_elim_threshold);
+
+ if(s->flags & CODEC_FLAG_CBP_RD){
+ for(i=0;i<mb_block_count;i++) {
+ if(s->block_last_index[i] == -1)
+ s->coded_score[i]= INT_MAX/256;
+ }
+ }
+ }
+
+ if((s->flags&CODEC_FLAG_GRAY) && s->mb_intra){
+ s->block_last_index[4]=
+ s->block_last_index[5]= 0;
+ s->block[4][0]=
+ s->block[5][0]= (1024 + s->c_dc_scale/2)/ s->c_dc_scale;
+ }
+
+ //non c quantize code returns incorrect block_last_index FIXME
+ if(s->alternate_scan && s->dct_quantize != dct_quantize_c){
+ for(i=0; i<mb_block_count; i++){
+ int j;
+ if(s->block_last_index[i]>0){
+ for(j=63; j>0; j--){
+ if(s->block[i][ s->intra_scantable.permutated[j] ]) break;
+ }
+ s->block_last_index[i]= j;
+ }
+ }
+ }
+
+ /* huffman encode */
+ switch(s->codec_id){ //FIXME funct ptr could be slightly faster
+ case CODEC_ID_MPEG1VIDEO:
+ case CODEC_ID_MPEG2VIDEO:
+ mpeg1_encode_mb(s, s->block, motion_x, motion_y); break;
+ case CODEC_ID_MPEG4:
+ mpeg4_encode_mb(s, s->block, motion_x, motion_y); break;
+ case CODEC_ID_MSMPEG4V2:
+ case CODEC_ID_MSMPEG4V3:
+ case CODEC_ID_WMV1:
+ msmpeg4_encode_mb(s, s->block, motion_x, motion_y); break;
+ case CODEC_ID_WMV2:
+ ff_wmv2_encode_mb(s, s->block, motion_x, motion_y); break;
+#ifdef CONFIG_H261_ENCODER
+ case CODEC_ID_H261:
+ ff_h261_encode_mb(s, s->block, motion_x, motion_y); break;
+#endif
+ case CODEC_ID_H263:
+ case CODEC_ID_H263P:
+ case CODEC_ID_FLV1:
+ case CODEC_ID_RV10:
+ case CODEC_ID_RV20:
+ h263_encode_mb(s, s->block, motion_x, motion_y); break;
+ case CODEC_ID_MJPEG:
+ mjpeg_encode_mb(s, s->block); break;
+ default:
+ assert(0);
+ }
+}
+
+static av_always_inline void encode_mb(MpegEncContext *s, int motion_x, int motion_y)
+{
+ if (s->chroma_format == CHROMA_420) encode_mb_internal(s, motion_x, motion_y, 8, 6);
+ else encode_mb_internal(s, motion_x, motion_y, 16, 8);
+}
+
+#endif //CONFIG_ENCODERS
+
+void ff_mpeg_flush(AVCodecContext *avctx){
+ int i;
+ MpegEncContext *s = avctx->priv_data;
+
+ if(s==NULL || s->picture==NULL)
+ return;
+
+ for(i=0; i<MAX_PICTURE_COUNT; i++){
+ if(s->picture[i].data[0] && ( s->picture[i].type == FF_BUFFER_TYPE_INTERNAL
+ || s->picture[i].type == FF_BUFFER_TYPE_USER))
+ avctx->release_buffer(avctx, (AVFrame*)&s->picture[i]);
+ }
+ s->current_picture_ptr = s->last_picture_ptr = s->next_picture_ptr = NULL;
+
+ s->mb_x= s->mb_y= 0;
+
+ s->parse_context.state= -1;
+ s->parse_context.frame_start_found= 0;
+ s->parse_context.overread= 0;
+ s->parse_context.overread_index= 0;
+ s->parse_context.index= 0;
+ s->parse_context.last_index= 0;
+ s->bitstream_buffer_size=0;
+ s->pp_time=0;
+}
+
+#ifdef CONFIG_ENCODERS
+void ff_copy_bits(PutBitContext *pb, uint8_t *src, int length)
+{
+ const uint16_t *srcw= (uint16_t*)src;
+ int words= length>>4;
+ int bits= length&15;
+ int i;
+
+ if(length==0) return;
+
+ if(words < 16){
+ for(i=0; i<words; i++) put_bits(pb, 16, be2me_16(srcw[i]));
+ }else if(put_bits_count(pb)&7){
+ for(i=0; i<words; i++) put_bits(pb, 16, be2me_16(srcw[i]));
+ }else{
+ for(i=0; put_bits_count(pb)&31; i++)
+ put_bits(pb, 8, src[i]);
+ flush_put_bits(pb);
+ memcpy(pbBufPtr(pb), src+i, 2*words-i);
+ skip_put_bytes(pb, 2*words-i);
+ }
+
+ put_bits(pb, bits, be2me_16(srcw[words])>>(16-bits));
+}
+
+static inline void copy_context_before_encode(MpegEncContext *d, MpegEncContext *s, int type){
+ int i;
+
+ memcpy(d->last_mv, s->last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster then a loop?
+
+ /* mpeg1 */
+ d->mb_skip_run= s->mb_skip_run;
+ for(i=0; i<3; i++)
+ d->last_dc[i]= s->last_dc[i];
+
+ /* statistics */
+ d->mv_bits= s->mv_bits;
+ d->i_tex_bits= s->i_tex_bits;
+ d->p_tex_bits= s->p_tex_bits;
+ d->i_count= s->i_count;
+ d->f_count= s->f_count;
+ d->b_count= s->b_count;
+ d->skip_count= s->skip_count;
+ d->misc_bits= s->misc_bits;
+ d->last_bits= 0;
+
+ d->mb_skipped= 0;
+ d->qscale= s->qscale;
+ d->dquant= s->dquant;
+}
+
+static inline void copy_context_after_encode(MpegEncContext *d, MpegEncContext *s, int type){
+ int i;
+
+ memcpy(d->mv, s->mv, 2*4*2*sizeof(int));
+ memcpy(d->last_mv, s->last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster then a loop?
+
+ /* mpeg1 */
+ d->mb_skip_run= s->mb_skip_run;
+ for(i=0; i<3; i++)
+ d->last_dc[i]= s->last_dc[i];
+
+ /* statistics */
+ d->mv_bits= s->mv_bits;
+ d->i_tex_bits= s->i_tex_bits;
+ d->p_tex_bits= s->p_tex_bits;
+ d->i_count= s->i_count;
+ d->f_count= s->f_count;
+ d->b_count= s->b_count;
+ d->skip_count= s->skip_count;
+ d->misc_bits= s->misc_bits;
+
+ d->mb_intra= s->mb_intra;
+ d->mb_skipped= s->mb_skipped;
+ d->mv_type= s->mv_type;
+ d->mv_dir= s->mv_dir;
+ d->pb= s->pb;
+ if(s->data_partitioning){
+ d->pb2= s->pb2;
+ d->tex_pb= s->tex_pb;
+ }
+ d->block= s->block;
+ for(i=0; i<8; i++)
+ d->block_last_index[i]= s->block_last_index[i];
+ d->interlaced_dct= s->interlaced_dct;
+ d->qscale= s->qscale;
+}
+
+static inline void encode_mb_hq(MpegEncContext *s, MpegEncContext *backup, MpegEncContext *best, int type,
+ PutBitContext pb[2], PutBitContext pb2[2], PutBitContext tex_pb[2],
+ int *dmin, int *next_block, int motion_x, int motion_y)
+{
+ int score;
+ uint8_t *dest_backup[3];
+
+ copy_context_before_encode(s, backup, type);
+
+ s->block= s->blocks[*next_block];
+ s->pb= pb[*next_block];
+ if(s->data_partitioning){
+ s->pb2 = pb2 [*next_block];
+ s->tex_pb= tex_pb[*next_block];
+ }
+
+ if(*next_block){
+ memcpy(dest_backup, s->dest, sizeof(s->dest));
+ s->dest[0] = s->rd_scratchpad;
+ s->dest[1] = s->rd_scratchpad + 16*s->linesize;
+ s->dest[2] = s->rd_scratchpad + 16*s->linesize + 8;
+ assert(s->linesize >= 32); //FIXME
+ }
+
+ encode_mb(s, motion_x, motion_y);
+
+ score= put_bits_count(&s->pb);
+ if(s->data_partitioning){
+ score+= put_bits_count(&s->pb2);
+ score+= put_bits_count(&s->tex_pb);
+ }
+
+ if(s->avctx->mb_decision == FF_MB_DECISION_RD){
+ MPV_decode_mb(s, s->block);
+
+ score *= s->lambda2;
+ score += sse_mb(s) << FF_LAMBDA_SHIFT;
+ }
+
+ if(*next_block){
+ memcpy(s->dest, dest_backup, sizeof(s->dest));
+ }
+
+ if(score<*dmin){
+ *dmin= score;
+ *next_block^=1;
+
+ copy_context_after_encode(best, s, type);
+ }
+}
+
+static int sse(MpegEncContext *s, uint8_t *src1, uint8_t *src2, int w, int h, int stride){
+ uint32_t *sq = ff_squareTbl + 256;
+ int acc=0;
+ int x,y;
+
+ if(w==16 && h==16)
+ return s->dsp.sse[0](NULL, src1, src2, stride, 16);
+ else if(w==8 && h==8)
+ return s->dsp.sse[1](NULL, src1, src2, stride, 8);
+
+ for(y=0; y<h; y++){
+ for(x=0; x<w; x++){
+ acc+= sq[src1[x + y*stride] - src2[x + y*stride]];
+ }
+ }
+
+ assert(acc>=0);
+
+ return acc;
+}
+
+static int sse_mb(MpegEncContext *s){
+ int w= 16;
+ int h= 16;
+
+ if(s->mb_x*16 + 16 > s->width ) w= s->width - s->mb_x*16;
+ if(s->mb_y*16 + 16 > s->height) h= s->height- s->mb_y*16;
+
+ if(w==16 && h==16)
+ if(s->avctx->mb_cmp == FF_CMP_NSSE){
+ return s->dsp.nsse[0](s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], s->linesize, 16)
+ +s->dsp.nsse[1](s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], s->uvlinesize, 8)
+ +s->dsp.nsse[1](s, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], s->uvlinesize, 8);
+ }else{
+ return s->dsp.sse[0](NULL, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], s->linesize, 16)
+ +s->dsp.sse[1](NULL, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], s->uvlinesize, 8)
+ +s->dsp.sse[1](NULL, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], s->uvlinesize, 8);
+ }
+ else
+ return sse(s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], w, h, s->linesize)
+ +sse(s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], w>>1, h>>1, s->uvlinesize)
+ +sse(s, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], w>>1, h>>1, s->uvlinesize);
+}
+
+static int pre_estimate_motion_thread(AVCodecContext *c, void *arg){
+ MpegEncContext *s= arg;
+
+
+ s->me.pre_pass=1;
+ s->me.dia_size= s->avctx->pre_dia_size;
+ s->first_slice_line=1;
+ for(s->mb_y= s->end_mb_y-1; s->mb_y >= s->start_mb_y; s->mb_y--) {
+ for(s->mb_x=s->mb_width-1; s->mb_x >=0 ;s->mb_x--) {
+ ff_pre_estimate_p_frame_motion(s, s->mb_x, s->mb_y);
+ }
+ s->first_slice_line=0;
+ }
+
+ s->me.pre_pass=0;
+
+ return 0;
+}
+
+static int estimate_motion_thread(AVCodecContext *c, void *arg){
+ MpegEncContext *s= arg;
+
+ ff_check_alignment();
+
+ s->me.dia_size= s->avctx->dia_size;
+ s->first_slice_line=1;
+ for(s->mb_y= s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) {
+ s->mb_x=0; //for block init below
+ ff_init_block_index(s);
+ for(s->mb_x=0; s->mb_x < s->mb_width; s->mb_x++) {
+ s->block_index[0]+=2;
+ s->block_index[1]+=2;
+ s->block_index[2]+=2;
+ s->block_index[3]+=2;
+
+ /* compute motion vector & mb_type and store in context */
+ if(s->pict_type==B_TYPE)
+ ff_estimate_b_frame_motion(s, s->mb_x, s->mb_y);
+ else
+ ff_estimate_p_frame_motion(s, s->mb_x, s->mb_y);
+ }
+ s->first_slice_line=0;
+ }
+ return 0;
+}
+
+static int mb_var_thread(AVCodecContext *c, void *arg){
+ MpegEncContext *s= arg;
+ int mb_x, mb_y;
+
+ ff_check_alignment();
+
+ for(mb_y=s->start_mb_y; mb_y < s->end_mb_y; mb_y++) {
+ for(mb_x=0; mb_x < s->mb_width; mb_x++) {
+ int xx = mb_x * 16;
+ int yy = mb_y * 16;
+ uint8_t *pix = s->new_picture.data[0] + (yy * s->linesize) + xx;
+ int varc;
+ int sum = s->dsp.pix_sum(pix, s->linesize);
+
+ varc = (s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)(sum*sum))>>8) + 500 + 128)>>8;
+
+ s->current_picture.mb_var [s->mb_stride * mb_y + mb_x] = varc;
+ s->current_picture.mb_mean[s->mb_stride * mb_y + mb_x] = (sum+128)>>8;
+ s->me.mb_var_sum_temp += varc;
+ }
+ }
+ return 0;
+}
+
+static void write_slice_end(MpegEncContext *s){
+ if(s->codec_id==CODEC_ID_MPEG4){
+ if(s->partitioned_frame){
+ ff_mpeg4_merge_partitions(s);
+ }
+
+ ff_mpeg4_stuffing(&s->pb);
+ }else if(s->out_format == FMT_MJPEG){
+ ff_mjpeg_stuffing(&s->pb);
+ }
+
+ align_put_bits(&s->pb);
+ flush_put_bits(&s->pb);
+
+ if((s->flags&CODEC_FLAG_PASS1) && !s->partitioned_frame)
+ s->misc_bits+= get_bits_diff(s);
+}
+
+static int encode_thread(AVCodecContext *c, void *arg){
+ MpegEncContext *s= arg;
+ int mb_x, mb_y, pdif = 0;
+ int i, j;
+ MpegEncContext best_s, backup_s;
+ uint8_t bit_buf[2][MAX_MB_BYTES];
+ uint8_t bit_buf2[2][MAX_MB_BYTES];
+ uint8_t bit_buf_tex[2][MAX_MB_BYTES];
+ PutBitContext pb[2], pb2[2], tex_pb[2];
+//printf("%d->%d\n", s->resync_mb_y, s->end_mb_y);
+
+ ff_check_alignment();
+
+ for(i=0; i<2; i++){
+ init_put_bits(&pb [i], bit_buf [i], MAX_MB_BYTES);
+ init_put_bits(&pb2 [i], bit_buf2 [i], MAX_MB_BYTES);
+ init_put_bits(&tex_pb[i], bit_buf_tex[i], MAX_MB_BYTES);
+ }
+
+ s->last_bits= put_bits_count(&s->pb);
+ s->mv_bits=0;
+ s->misc_bits=0;
+ s->i_tex_bits=0;
+ s->p_tex_bits=0;
+ s->i_count=0;
+ s->f_count=0;
+ s->b_count=0;
+ s->skip_count=0;
+
+ for(i=0; i<3; i++){
+ /* init last dc values */
+ /* note: quant matrix value (8) is implied here */
+ s->last_dc[i] = 128 << s->intra_dc_precision;
+
+ s->current_picture.error[i] = 0;
+ }
+ s->mb_skip_run = 0;
+ memset(s->last_mv, 0, sizeof(s->last_mv));
+
+ s->last_mv_dir = 0;
+
+ switch(s->codec_id){
+ case CODEC_ID_H263:
+ case CODEC_ID_H263P:
+ case CODEC_ID_FLV1:
+ s->gob_index = ff_h263_get_gob_height(s);
+ break;
+ case CODEC_ID_MPEG4:
+ if(s->partitioned_frame)
+ ff_mpeg4_init_partitions(s);
+ break;
+ }
+
+ s->resync_mb_x=0;
+ s->resync_mb_y=0;
+ s->first_slice_line = 1;
+ s->ptr_lastgob = s->pb.buf;
+ for(mb_y= s->start_mb_y; mb_y < s->end_mb_y; mb_y++) {
+// printf("row %d at %X\n", s->mb_y, (int)s);
+ s->mb_x=0;
+ s->mb_y= mb_y;
+
+ ff_set_qscale(s, s->qscale);
+ ff_init_block_index(s);
+
+ for(mb_x=0; mb_x < s->mb_width; mb_x++) {
+ int xy= mb_y*s->mb_stride + mb_x; // removed const, H261 needs to adjust this
+ int mb_type= s->mb_type[xy];
+// int d;
+ int dmin= INT_MAX;
+ int dir;
+
+ if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < MAX_MB_BYTES){
+ av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
+ return -1;
+ }
+ if(s->data_partitioning){
+ if( s->pb2 .buf_end - s->pb2 .buf - (put_bits_count(&s-> pb2)>>3) < MAX_MB_BYTES
+ || s->tex_pb.buf_end - s->tex_pb.buf - (put_bits_count(&s->tex_pb )>>3) < MAX_MB_BYTES){
+ av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
+ return -1;
+ }
+ }
+
+ s->mb_x = mb_x;
+ s->mb_y = mb_y; // moved into loop, can get changed by H.261
+ ff_update_block_index(s);
+
+#ifdef CONFIG_H261_ENCODER
+ if(s->codec_id == CODEC_ID_H261){
+ ff_h261_reorder_mb_index(s);
+ xy= s->mb_y*s->mb_stride + s->mb_x;
+ mb_type= s->mb_type[xy];
+ }
+#endif
+
+ /* write gob / video packet header */
+ if(s->rtp_mode){
+ int current_packet_size, is_gob_start;
+
+ current_packet_size= ((put_bits_count(&s->pb)+7)>>3) - (s->ptr_lastgob - s->pb.buf);
+
+ is_gob_start= s->avctx->rtp_payload_size && current_packet_size >= s->avctx->rtp_payload_size && mb_y + mb_x>0;
+
+ if(s->start_mb_y == mb_y && mb_y > 0 && mb_x==0) is_gob_start=1;
+
+ switch(s->codec_id){
+ case CODEC_ID_H263:
+ case CODEC_ID_H263P:
+ if(!s->h263_slice_structured)
+ if(s->mb_x || s->mb_y%s->gob_index) is_gob_start=0;
+ break;
+ case CODEC_ID_MPEG2VIDEO:
+ if(s->mb_x==0 && s->mb_y!=0) is_gob_start=1;
+ case CODEC_ID_MPEG1VIDEO:
+ if(s->mb_skip_run) is_gob_start=0;
+ break;
+ }
+
+ if(is_gob_start){
+ if(s->start_mb_y != mb_y || mb_x!=0){
+ write_slice_end(s);
+
+ if(s->codec_id==CODEC_ID_MPEG4 && s->partitioned_frame){
+ ff_mpeg4_init_partitions(s);
+ }
+ }
+
+ assert((put_bits_count(&s->pb)&7) == 0);
+ current_packet_size= pbBufPtr(&s->pb) - s->ptr_lastgob;
+
+ if(s->avctx->error_rate && s->resync_mb_x + s->resync_mb_y > 0){
+ int r= put_bits_count(&s->pb)/8 + s->picture_number + 16 + s->mb_x + s->mb_y;
+ int d= 100 / s->avctx->error_rate;
+ if(r % d == 0){
+ current_packet_size=0;
+#ifndef ALT_BITSTREAM_WRITER
+ s->pb.buf_ptr= s->ptr_lastgob;
+#endif
+ assert(pbBufPtr(&s->pb) == s->ptr_lastgob);
+ }
+ }
+
+ if (s->avctx->rtp_callback){
+ int number_mb = (mb_y - s->resync_mb_y)*s->mb_width + mb_x - s->resync_mb_x;
+ s->avctx->rtp_callback(s->avctx, s->ptr_lastgob, current_packet_size, number_mb);
+ }
+
+ switch(s->codec_id){
+ case CODEC_ID_MPEG4:
+ ff_mpeg4_encode_video_packet_header(s);
+ ff_mpeg4_clean_buffers(s);
+ break;
+ case CODEC_ID_MPEG1VIDEO:
+ case CODEC_ID_MPEG2VIDEO:
+ ff_mpeg1_encode_slice_header(s);
+ ff_mpeg1_clean_buffers(s);
+ break;
+ case CODEC_ID_H263:
+ case CODEC_ID_H263P:
+ h263_encode_gob_header(s, mb_y);
+ break;
+ }
+
+ if(s->flags&CODEC_FLAG_PASS1){
+ int bits= put_bits_count(&s->pb);
+ s->misc_bits+= bits - s->last_bits;
+ s->last_bits= bits;
+ }
+
+ s->ptr_lastgob += current_packet_size;
+ s->first_slice_line=1;
+ s->resync_mb_x=mb_x;
+ s->resync_mb_y=mb_y;
+ }
+ }
+
+ if( (s->resync_mb_x == s->mb_x)
+ && s->resync_mb_y+1 == s->mb_y){
+ s->first_slice_line=0;
+ }
+
+ s->mb_skipped=0;
+ s->dquant=0; //only for QP_RD
+
+ if(mb_type & (mb_type-1) || (s->flags & CODEC_FLAG_QP_RD)){ // more than 1 MB type possible or CODEC_FLAG_QP_RD
+ int next_block=0;
+ int pb_bits_count, pb2_bits_count, tex_pb_bits_count;
+
+ copy_context_before_encode(&backup_s, s, -1);
+ backup_s.pb= s->pb;
+ best_s.data_partitioning= s->data_partitioning;
+ best_s.partitioned_frame= s->partitioned_frame;
+ if(s->data_partitioning){
+ backup_s.pb2= s->pb2;
+ backup_s.tex_pb= s->tex_pb;
+ }
+
+ if(mb_type&CANDIDATE_MB_TYPE_INTER){
+ s->mv_dir = MV_DIR_FORWARD;
+ s->mv_type = MV_TYPE_16X16;
+ s->mb_intra= 0;
+ s->mv[0][0][0] = s->p_mv_table[xy][0];
+ s->mv[0][0][1] = s->p_mv_table[xy][1];
+ encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER, pb, pb2, tex_pb,
+ &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]);
+ }
+ if(mb_type&CANDIDATE_MB_TYPE_INTER_I){
+ s->mv_dir = MV_DIR_FORWARD;
+ s->mv_type = MV_TYPE_FIELD;
+ s->mb_intra= 0;
+ for(i=0; i<2; i++){
+ j= s->field_select[0][i] = s->p_field_select_table[i][xy];
+ s->mv[0][i][0] = s->p_field_mv_table[i][j][xy][0];
+ s->mv[0][i][1] = s->p_field_mv_table[i][j][xy][1];
+ }
+ encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER_I, pb, pb2, tex_pb,
+ &dmin, &next_block, 0, 0);
+ }
+ if(mb_type&CANDIDATE_MB_TYPE_SKIPPED){
+ s->mv_dir = MV_DIR_FORWARD;
+ s->mv_type = MV_TYPE_16X16;
+ s->mb_intra= 0;
+ s->mv[0][0][0] = 0;
+ s->mv[0][0][1] = 0;
+ encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_SKIPPED, pb, pb2, tex_pb,
+ &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]);
+ }
+ if(mb_type&CANDIDATE_MB_TYPE_INTER4V){
+ s->mv_dir = MV_DIR_FORWARD;
+ s->mv_type = MV_TYPE_8X8;
+ s->mb_intra= 0;
+ for(i=0; i<4; i++){
+ s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0];
+ s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1];
+ }
+ encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER4V, pb, pb2, tex_pb,
+ &dmin, &next_block, 0, 0);
+ }
+ if(mb_type&CANDIDATE_MB_TYPE_FORWARD){
+ s->mv_dir = MV_DIR_FORWARD;
+ s->mv_type = MV_TYPE_16X16;
+ s->mb_intra= 0;
+ s->mv[0][0][0] = s->b_forw_mv_table[xy][0];
+ s->mv[0][0][1] = s->b_forw_mv_table[xy][1];
+ encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_FORWARD, pb, pb2, tex_pb,
+ &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]);
+ }
+ if(mb_type&CANDIDATE_MB_TYPE_BACKWARD){
+ s->mv_dir = MV_DIR_BACKWARD;
+ s->mv_type = MV_TYPE_16X16;
+ s->mb_intra= 0;
+ s->mv[1][0][0] = s->b_back_mv_table[xy][0];
+ s->mv[1][0][1] = s->b_back_mv_table[xy][1];
+ encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BACKWARD, pb, pb2, tex_pb,
+ &dmin, &next_block, s->mv[1][0][0], s->mv[1][0][1]);
+ }
+ if(mb_type&CANDIDATE_MB_TYPE_BIDIR){
+ s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD;
+ s->mv_type = MV_TYPE_16X16;
+ s->mb_intra= 0;
+ s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0];
+ s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1];
+ s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0];
+ s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1];
+ encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BIDIR, pb, pb2, tex_pb,
+ &dmin, &next_block, 0, 0);
+ }
+ if(mb_type&CANDIDATE_MB_TYPE_FORWARD_I){
+ s->mv_dir = MV_DIR_FORWARD;
+ s->mv_type = MV_TYPE_FIELD;
+ s->mb_intra= 0;
+ for(i=0; i<2; i++){
+ j= s->field_select[0][i] = s->b_field_select_table[0][i][xy];
+ s->mv[0][i][0] = s->b_field_mv_table[0][i][j][xy][0];
+ s->mv[0][i][1] = s->b_field_mv_table[0][i][j][xy][1];
+ }
+ encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_FORWARD_I, pb, pb2, tex_pb,
+ &dmin, &next_block, 0, 0);
+ }
+ if(mb_type&CANDIDATE_MB_TYPE_BACKWARD_I){
+ s->mv_dir = MV_DIR_BACKWARD;
+ s->mv_type = MV_TYPE_FIELD;
+ s->mb_intra= 0;
+ for(i=0; i<2; i++){
+ j= s->field_select[1][i] = s->b_field_select_table[1][i][xy];
+ s->mv[1][i][0] = s->b_field_mv_table[1][i][j][xy][0];
+ s->mv[1][i][1] = s->b_field_mv_table[1][i][j][xy][1];
+ }
+ encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BACKWARD_I, pb, pb2, tex_pb,
+ &dmin, &next_block, 0, 0);
+ }
+ if(mb_type&CANDIDATE_MB_TYPE_BIDIR_I){
+ s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD;
+ s->mv_type = MV_TYPE_FIELD;
+ s->mb_intra= 0;
+ for(dir=0; dir<2; dir++){
+ for(i=0; i<2; i++){
+ j= s->field_select[dir][i] = s->b_field_select_table[dir][i][xy];
+ s->mv[dir][i][0] = s->b_field_mv_table[dir][i][j][xy][0];
+ s->mv[dir][i][1] = s->b_field_mv_table[dir][i][j][xy][1];
+ }
+ }
+ encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BIDIR_I, pb, pb2, tex_pb,
+ &dmin, &next_block, 0, 0);
+ }
+ if(mb_type&CANDIDATE_MB_TYPE_INTRA){
+ s->mv_dir = 0;
+ s->mv_type = MV_TYPE_16X16;
+ s->mb_intra= 1;
+ s->mv[0][0][0] = 0;
+ s->mv[0][0][1] = 0;
+ encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTRA, pb, pb2, tex_pb,
+ &dmin, &next_block, 0, 0);
+ if(s->h263_pred || s->h263_aic){
+ if(best_s.mb_intra)
+ s->mbintra_table[mb_x + mb_y*s->mb_stride]=1;
+ else
+ ff_clean_intra_table_entries(s); //old mode?
+ }
+ }
+
+ if((s->flags & CODEC_FLAG_QP_RD) && dmin < INT_MAX){
+ if(best_s.mv_type==MV_TYPE_16X16){ //FIXME move 4mv after QPRD
+ const int last_qp= backup_s.qscale;
+ int qpi, qp, dc[6];
+ DCTELEM ac[6][16];
+ const int mvdir= (best_s.mv_dir&MV_DIR_BACKWARD) ? 1 : 0;
+ static const int dquant_tab[4]={-1,1,-2,2};
+
+ assert(backup_s.dquant == 0);
+
+ //FIXME intra
+ s->mv_dir= best_s.mv_dir;
+ s->mv_type = MV_TYPE_16X16;
+ s->mb_intra= best_s.mb_intra;
+ s->mv[0][0][0] = best_s.mv[0][0][0];
+ s->mv[0][0][1] = best_s.mv[0][0][1];
+ s->mv[1][0][0] = best_s.mv[1][0][0];
+ s->mv[1][0][1] = best_s.mv[1][0][1];
+
+ qpi = s->pict_type == B_TYPE ? 2 : 0;
+ for(; qpi<4; qpi++){
+ int dquant= dquant_tab[qpi];
+ qp= last_qp + dquant;
+ if(qp < s->avctx->qmin || qp > s->avctx->qmax)
+ continue;
+ backup_s.dquant= dquant;
+ if(s->mb_intra && s->dc_val[0]){
+ for(i=0; i<6; i++){
+ dc[i]= s->dc_val[0][ s->block_index[i] ];
+ memcpy(ac[i], s->ac_val[0][s->block_index[i]], sizeof(DCTELEM)*16);
+ }
+ }
+
+ encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER /* wrong but unused */, pb, pb2, tex_pb,
+ &dmin, &next_block, s->mv[mvdir][0][0], s->mv[mvdir][0][1]);
+ if(best_s.qscale != qp){
+ if(s->mb_intra && s->dc_val[0]){
+ for(i=0; i<6; i++){
+ s->dc_val[0][ s->block_index[i] ]= dc[i];
+ memcpy(s->ac_val[0][s->block_index[i]], ac[i], sizeof(DCTELEM)*16);
+ }
+ }
+ }
+ }
+ }
+ }
+ if(mb_type&CANDIDATE_MB_TYPE_DIRECT){
+ int mx= s->b_direct_mv_table[xy][0];
+ int my= s->b_direct_mv_table[xy][1];
+
+ backup_s.dquant = 0;
+ s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
+ s->mb_intra= 0;
+ ff_mpeg4_set_direct_mv(s, mx, my);
+ encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_DIRECT, pb, pb2, tex_pb,
+ &dmin, &next_block, mx, my);
+ }
+ if(mb_type&CANDIDATE_MB_TYPE_DIRECT0){
+ backup_s.dquant = 0;
+ s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
+ s->mb_intra= 0;
+ ff_mpeg4_set_direct_mv(s, 0, 0);
+ encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_DIRECT, pb, pb2, tex_pb,
+ &dmin, &next_block, 0, 0);
+ }
+ if(!best_s.mb_intra && s->flags2&CODEC_FLAG2_SKIP_RD){
+ int coded=0;
+ for(i=0; i<6; i++)
+ coded |= s->block_last_index[i];
+ if(coded){
+ int mx,my;
+ memcpy(s->mv, best_s.mv, sizeof(s->mv));
+ if(best_s.mv_dir & MV_DIRECT){
+ mx=my=0; //FIXME find the one we actually used
+ ff_mpeg4_set_direct_mv(s, mx, my);
+ }else if(best_s.mv_dir&MV_DIR_BACKWARD){
+ mx= s->mv[1][0][0];
+ my= s->mv[1][0][1];
+ }else{
+ mx= s->mv[0][0][0];
+ my= s->mv[0][0][1];
+ }
+
+ s->mv_dir= best_s.mv_dir;
+ s->mv_type = best_s.mv_type;
+ s->mb_intra= 0;
+/* s->mv[0][0][0] = best_s.mv[0][0][0];
+ s->mv[0][0][1] = best_s.mv[0][0][1];
+ s->mv[1][0][0] = best_s.mv[1][0][0];
+ s->mv[1][0][1] = best_s.mv[1][0][1];*/
+ backup_s.dquant= 0;
+ s->skipdct=1;
+ encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER /* wrong but unused */, pb, pb2, tex_pb,
+ &dmin, &next_block, mx, my);
+ s->skipdct=0;
+ }
+ }
+
+ s->current_picture.qscale_table[xy]= best_s.qscale;
+
+ copy_context_after_encode(s, &best_s, -1);
+
+ pb_bits_count= put_bits_count(&s->pb);
+ flush_put_bits(&s->pb);
+ ff_copy_bits(&backup_s.pb, bit_buf[next_block^1], pb_bits_count);
+ s->pb= backup_s.pb;
+
+ if(s->data_partitioning){
+ pb2_bits_count= put_bits_count(&s->pb2);
+ flush_put_bits(&s->pb2);
+ ff_copy_bits(&backup_s.pb2, bit_buf2[next_block^1], pb2_bits_count);
+ s->pb2= backup_s.pb2;
+
+ tex_pb_bits_count= put_bits_count(&s->tex_pb);
+ flush_put_bits(&s->tex_pb);
+ ff_copy_bits(&backup_s.tex_pb, bit_buf_tex[next_block^1], tex_pb_bits_count);
+ s->tex_pb= backup_s.tex_pb;
+ }
+ s->last_bits= put_bits_count(&s->pb);
+
+ if (s->out_format == FMT_H263 && s->pict_type!=B_TYPE)
+ ff_h263_update_motion_val(s);
+
+ if(next_block==0){ //FIXME 16 vs linesize16
+ s->dsp.put_pixels_tab[0][0](s->dest[0], s->rd_scratchpad , s->linesize ,16);
+ s->dsp.put_pixels_tab[1][0](s->dest[1], s->rd_scratchpad + 16*s->linesize , s->uvlinesize, 8);
+ s->dsp.put_pixels_tab[1][0](s->dest[2], s->rd_scratchpad + 16*s->linesize + 8, s->uvlinesize, 8);
+ }
+
+ if(s->avctx->mb_decision == FF_MB_DECISION_BITS)
+ MPV_decode_mb(s, s->block);
+ } else {
+ int motion_x = 0, motion_y = 0;
+ s->mv_type=MV_TYPE_16X16;
+ // only one MB-Type possible
+
+ switch(mb_type){
+ case CANDIDATE_MB_TYPE_INTRA:
+ s->mv_dir = 0;
+ s->mb_intra= 1;
+ motion_x= s->mv[0][0][0] = 0;
+ motion_y= s->mv[0][0][1] = 0;
+ break;
+ case CANDIDATE_MB_TYPE_INTER:
+ s->mv_dir = MV_DIR_FORWARD;
+ s->mb_intra= 0;
+ motion_x= s->mv[0][0][0] = s->p_mv_table[xy][0];
+ motion_y= s->mv[0][0][1] = s->p_mv_table[xy][1];
+ break;
+ case CANDIDATE_MB_TYPE_INTER_I:
+ s->mv_dir = MV_DIR_FORWARD;
+ s->mv_type = MV_TYPE_FIELD;
+ s->mb_intra= 0;
+ for(i=0; i<2; i++){
+ j= s->field_select[0][i] = s->p_field_select_table[i][xy];
+ s->mv[0][i][0] = s->p_field_mv_table[i][j][xy][0];
+ s->mv[0][i][1] = s->p_field_mv_table[i][j][xy][1];
+ }
+ break;
+ case CANDIDATE_MB_TYPE_INTER4V:
+ s->mv_dir = MV_DIR_FORWARD;
+ s->mv_type = MV_TYPE_8X8;
+ s->mb_intra= 0;
+ for(i=0; i<4; i++){
+ s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0];
+ s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1];
+ }
+ break;
+ case CANDIDATE_MB_TYPE_DIRECT:
+ s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
+ s->mb_intra= 0;
+ motion_x=s->b_direct_mv_table[xy][0];
+ motion_y=s->b_direct_mv_table[xy][1];
+ ff_mpeg4_set_direct_mv(s, motion_x, motion_y);
+ break;
+ case CANDIDATE_MB_TYPE_DIRECT0:
+ s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
+ s->mb_intra= 0;
+ ff_mpeg4_set_direct_mv(s, 0, 0);
+ break;
+ case CANDIDATE_MB_TYPE_BIDIR:
+ s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD;
+ s->mb_intra= 0;
+ s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0];
+ s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1];
+ s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0];
+ s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1];
+ break;
+ case CANDIDATE_MB_TYPE_BACKWARD:
+ s->mv_dir = MV_DIR_BACKWARD;
+ s->mb_intra= 0;
+ motion_x= s->mv[1][0][0] = s->b_back_mv_table[xy][0];
+ motion_y= s->mv[1][0][1] = s->b_back_mv_table[xy][1];
+ break;
+ case CANDIDATE_MB_TYPE_FORWARD:
+ s->mv_dir = MV_DIR_FORWARD;
+ s->mb_intra= 0;
+ motion_x= s->mv[0][0][0] = s->b_forw_mv_table[xy][0];
+ motion_y= s->mv[0][0][1] = s->b_forw_mv_table[xy][1];
+// printf(" %d %d ", motion_x, motion_y);
+ break;
+ case CANDIDATE_MB_TYPE_FORWARD_I:
+ s->mv_dir = MV_DIR_FORWARD;
+ s->mv_type = MV_TYPE_FIELD;
+ s->mb_intra= 0;
+ for(i=0; i<2; i++){
+ j= s->field_select[0][i] = s->b_field_select_table[0][i][xy];
+ s->mv[0][i][0] = s->b_field_mv_table[0][i][j][xy][0];
+ s->mv[0][i][1] = s->b_field_mv_table[0][i][j][xy][1];
+ }
+ break;
+ case CANDIDATE_MB_TYPE_BACKWARD_I:
+ s->mv_dir = MV_DIR_BACKWARD;
+ s->mv_type = MV_TYPE_FIELD;
+ s->mb_intra= 0;
+ for(i=0; i<2; i++){
+ j= s->field_select[1][i] = s->b_field_select_table[1][i][xy];
+ s->mv[1][i][0] = s->b_field_mv_table[1][i][j][xy][0];
+ s->mv[1][i][1] = s->b_field_mv_table[1][i][j][xy][1];
+ }
+ break;
+ case CANDIDATE_MB_TYPE_BIDIR_I:
+ s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD;
+ s->mv_type = MV_TYPE_FIELD;
+ s->mb_intra= 0;
+ for(dir=0; dir<2; dir++){
+ for(i=0; i<2; i++){
+ j= s->field_select[dir][i] = s->b_field_select_table[dir][i][xy];
+ s->mv[dir][i][0] = s->b_field_mv_table[dir][i][j][xy][0];
+ s->mv[dir][i][1] = s->b_field_mv_table[dir][i][j][xy][1];
+ }
+ }
+ break;
+ default:
+ av_log(s->avctx, AV_LOG_ERROR, "illegal MB type\n");
+ }
+
+ encode_mb(s, motion_x, motion_y);
+
+ // RAL: Update last macroblock type
+ s->last_mv_dir = s->mv_dir;
+
+ if (s->out_format == FMT_H263 && s->pict_type!=B_TYPE)
+ ff_h263_update_motion_val(s);
+
+ MPV_decode_mb(s, s->block);
+ }
+
+ /* clean the MV table in IPS frames for direct mode in B frames */
+ if(s->mb_intra /* && I,P,S_TYPE */){
+ s->p_mv_table[xy][0]=0;
+ s->p_mv_table[xy][1]=0;
+ }
+
+ if(s->flags&CODEC_FLAG_PSNR){
+ int w= 16;
+ int h= 16;
+
+ if(s->mb_x*16 + 16 > s->width ) w= s->width - s->mb_x*16;
+ if(s->mb_y*16 + 16 > s->height) h= s->height- s->mb_y*16;
+
+ s->current_picture.error[0] += sse(
+ s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16,
+ s->dest[0], w, h, s->linesize);
+ s->current_picture.error[1] += sse(
+ s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,
+ s->dest[1], w>>1, h>>1, s->uvlinesize);
+ s->current_picture.error[2] += sse(
+ s, s->new_picture .data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,
+ s->dest[2], w>>1, h>>1, s->uvlinesize);
+ }
+ if(s->loop_filter){
+ if(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));
+ }
+ }
+
+ //not beautiful here but we must write it before flushing so it has to be here
+ if (s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type == I_TYPE)
+ msmpeg4_encode_ext_header(s);
+
+ write_slice_end(s);
+
+ /* Send the last GOB if RTP */
+ if (s->avctx->rtp_callback) {
+ int number_mb = (mb_y - s->resync_mb_y)*s->mb_width - s->resync_mb_x;
+ pdif = pbBufPtr(&s->pb) - s->ptr_lastgob;
+ /* Call the RTP callback to send the last GOB */
+ emms_c();
+ s->avctx->rtp_callback(s->avctx, s->ptr_lastgob, pdif, number_mb);
+ }
+
+ return 0;
+}
+
+#define MERGE(field) dst->field += src->field; src->field=0
+static void merge_context_after_me(MpegEncContext *dst, MpegEncContext *src){
+ MERGE(me.scene_change_score);
+ MERGE(me.mc_mb_var_sum_temp);
+ MERGE(me.mb_var_sum_temp);
+}
+
+static void merge_context_after_encode(MpegEncContext *dst, MpegEncContext *src){
+ int i;
+
+ MERGE(dct_count[0]); //note, the other dct vars are not part of the context
+ MERGE(dct_count[1]);
+ MERGE(mv_bits);
+ MERGE(i_tex_bits);
+ MERGE(p_tex_bits);
+ MERGE(i_count);
+ MERGE(f_count);
+ MERGE(b_count);
+ MERGE(skip_count);
+ MERGE(misc_bits);
+ MERGE(error_count);
+ MERGE(padding_bug_score);
+ MERGE(current_picture.error[0]);
+ MERGE(current_picture.error[1]);
+ MERGE(current_picture.error[2]);
+
+ if(dst->avctx->noise_reduction){
+ for(i=0; i<64; i++){
+ MERGE(dct_error_sum[0][i]);
+ MERGE(dct_error_sum[1][i]);
+ }
+ }
+
+ assert(put_bits_count(&src->pb) % 8 ==0);
+ assert(put_bits_count(&dst->pb) % 8 ==0);
+ ff_copy_bits(&dst->pb, src->pb.buf, put_bits_count(&src->pb));
+ flush_put_bits(&dst->pb);
+}
+
+static int estimate_qp(MpegEncContext *s, int dry_run){
+ if (s->next_lambda){
+ s->current_picture_ptr->quality=
+ s->current_picture.quality = s->next_lambda;
+ if(!dry_run) s->next_lambda= 0;
+ } else if (!s->fixed_qscale) {
+ s->current_picture_ptr->quality=
+ s->current_picture.quality = ff_rate_estimate_qscale(s, dry_run);
+ if (s->current_picture.quality < 0)
+ return -1;
+ }
+
+ if(s->adaptive_quant){
+ switch(s->codec_id){
+ case CODEC_ID_MPEG4:
+ ff_clean_mpeg4_qscales(s);
+ break;
+ case CODEC_ID_H263:
+ case CODEC_ID_H263P:
+ case CODEC_ID_FLV1:
+ ff_clean_h263_qscales(s);
+ break;
+ }
+
+ s->lambda= s->lambda_table[0];
+ //FIXME broken
+ }else
+ s->lambda= s->current_picture.quality;
+//printf("%d %d\n", s->avctx->global_quality, s->current_picture.quality);
+ update_qscale(s);
+ return 0;
+}
+
+static int encode_picture(MpegEncContext *s, int picture_number)
+{
+ int i;
+ int bits;
+
+ s->picture_number = picture_number;
+
+ /* Reset the average MB variance */
+ s->me.mb_var_sum_temp =
+ s->me.mc_mb_var_sum_temp = 0;
+
+ /* we need to initialize some time vars before we can encode b-frames */
+ // RAL: Condition added for MPEG1VIDEO
+ if (s->codec_id == CODEC_ID_MPEG1VIDEO || s->codec_id == CODEC_ID_MPEG2VIDEO || (s->h263_pred && !s->h263_msmpeg4))
+ ff_set_mpeg4_time(s, s->picture_number); //FIXME rename and use has_b_frames or similar
+
+ s->me.scene_change_score=0;
+
+// s->lambda= s->current_picture_ptr->quality; //FIXME qscale / ... stuff for ME ratedistoration
+
+ if(s->pict_type==I_TYPE){
+ if(s->msmpeg4_version >= 3) s->no_rounding=1;
+ else s->no_rounding=0;
+ }else if(s->pict_type!=B_TYPE){
+ if(s->flipflop_rounding || s->codec_id == CODEC_ID_H263P || s->codec_id == CODEC_ID_MPEG4)
+ s->no_rounding ^= 1;
+ }
+
+ if(s->flags & CODEC_FLAG_PASS2){
+ if (estimate_qp(s,1) < 0)
+ return -1;
+ ff_get_2pass_fcode(s);
+ }else if(!(s->flags & CODEC_FLAG_QSCALE)){
+ if(s->pict_type==B_TYPE)
+ s->lambda= s->last_lambda_for[s->pict_type];
+ else
+ s->lambda= s->last_lambda_for[s->last_non_b_pict_type];
+ update_qscale(s);
+ }
+
+ s->mb_intra=0; //for the rate distortion & bit compare functions
+ for(i=1; i<s->avctx->thread_count; i++){
+ ff_update_duplicate_context(s->thread_context[i], s);
+ }
+
+ ff_init_me(s);
+
+ /* Estimate motion for every MB */
+ if(s->pict_type != I_TYPE){
+ s->lambda = (s->lambda * s->avctx->me_penalty_compensation + 128)>>8;
+ s->lambda2= (s->lambda2* (int64_t)s->avctx->me_penalty_compensation + 128)>>8;
+ if(s->pict_type != B_TYPE && s->avctx->me_threshold==0){
+ if((s->avctx->pre_me && s->last_non_b_pict_type==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);
+ }
+ }
+
+ s->avctx->execute(s->avctx, estimate_motion_thread, (void**)&(s->thread_context[0]), NULL, s->avctx->thread_count);
+ }else /* if(s->pict_type == I_TYPE) */{
+ /* I-Frame */
+ for(i=0; i<s->mb_stride*s->mb_height; i++)
+ s->mb_type[i]= CANDIDATE_MB_TYPE_INTRA;
+
+ 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);
+ }
+ }
+ for(i=1; i<s->avctx->thread_count; i++){
+ merge_context_after_me(s, s->thread_context[i]);
+ }
+ s->current_picture.mc_mb_var_sum= s->current_picture_ptr->mc_mb_var_sum= s->me.mc_mb_var_sum_temp;
+ s->current_picture. mb_var_sum= s->current_picture_ptr-> mb_var_sum= s->me. mb_var_sum_temp;
+ emms_c();
+
+ if(s->me.scene_change_score > s->avctx->scenechange_threshold && s->pict_type == P_TYPE){
+ s->pict_type= I_TYPE;
+ for(i=0; i<s->mb_stride*s->mb_height; i++)
+ s->mb_type[i]= CANDIDATE_MB_TYPE_INTRA;
+//printf("Scene change detected, encoding as I Frame %d %d\n", s->current_picture.mb_var_sum, s->current_picture.mc_mb_var_sum);
+ }
+
+ if(!s->umvplus){
+ if(s->pict_type==P_TYPE || s->pict_type==S_TYPE) {
+ s->f_code= ff_get_best_fcode(s, s->p_mv_table, CANDIDATE_MB_TYPE_INTER);
+
+ if(s->flags & CODEC_FLAG_INTERLACED_ME){
+ int a,b;
+ a= ff_get_best_fcode(s, s->p_field_mv_table[0][0], CANDIDATE_MB_TYPE_INTER_I); //FIXME field_select
+ b= ff_get_best_fcode(s, s->p_field_mv_table[1][1], CANDIDATE_MB_TYPE_INTER_I);
+ s->f_code= FFMAX(s->f_code, FFMAX(a,b));
+ }
+
+ ff_fix_long_p_mvs(s);
+ ff_fix_long_mvs(s, NULL, 0, s->p_mv_table, s->f_code, CANDIDATE_MB_TYPE_INTER, 0);
+ if(s->flags & CODEC_FLAG_INTERLACED_ME){
+ int j;
+ for(i=0; i<2; i++){
+ for(j=0; j<2; j++)
+ ff_fix_long_mvs(s, s->p_field_select_table[i], j,
+ s->p_field_mv_table[i][j], s->f_code, CANDIDATE_MB_TYPE_INTER_I, 0);
+ }
+ }
+ }
+
+ if(s->pict_type==B_TYPE){
+ int a, b;
+
+ a = ff_get_best_fcode(s, s->b_forw_mv_table, CANDIDATE_MB_TYPE_FORWARD);
+ b = ff_get_best_fcode(s, s->b_bidir_forw_mv_table, CANDIDATE_MB_TYPE_BIDIR);
+ s->f_code = FFMAX(a, b);
+
+ a = ff_get_best_fcode(s, s->b_back_mv_table, CANDIDATE_MB_TYPE_BACKWARD);
+ b = ff_get_best_fcode(s, s->b_bidir_back_mv_table, CANDIDATE_MB_TYPE_BIDIR);
+ s->b_code = FFMAX(a, b);
+
+ ff_fix_long_mvs(s, NULL, 0, s->b_forw_mv_table, s->f_code, CANDIDATE_MB_TYPE_FORWARD, 1);
+ ff_fix_long_mvs(s, NULL, 0, s->b_back_mv_table, s->b_code, CANDIDATE_MB_TYPE_BACKWARD, 1);
+ ff_fix_long_mvs(s, NULL, 0, s->b_bidir_forw_mv_table, s->f_code, CANDIDATE_MB_TYPE_BIDIR, 1);
+ ff_fix_long_mvs(s, NULL, 0, s->b_bidir_back_mv_table, s->b_code, CANDIDATE_MB_TYPE_BIDIR, 1);
+ if(s->flags & CODEC_FLAG_INTERLACED_ME){
+ int dir, j;
+ for(dir=0; dir<2; dir++){
+ for(i=0; i<2; i++){
+ for(j=0; j<2; j++){
+ int type= dir ? (CANDIDATE_MB_TYPE_BACKWARD_I|CANDIDATE_MB_TYPE_BIDIR_I)
+ : (CANDIDATE_MB_TYPE_FORWARD_I |CANDIDATE_MB_TYPE_BIDIR_I);
+ ff_fix_long_mvs(s, s->b_field_select_table[dir][i], j,
+ s->b_field_mv_table[dir][i][j], dir ? s->b_code : s->f_code, type, 1);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (estimate_qp(s, 0) < 0)
+ return -1;
+
+ if(s->qscale < 3 && s->max_qcoeff<=128 && s->pict_type==I_TYPE && !(s->flags & CODEC_FLAG_QSCALE))
+ s->qscale= 3; //reduce clipping problems
+
+ 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);
+ }
+ 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;
+ }
+
+ //FIXME var duplication
+ s->current_picture_ptr->key_frame=
+ s->current_picture.key_frame= s->pict_type == I_TYPE; //FIXME pic_ptr
+ s->current_picture_ptr->pict_type=
+ s->current_picture.pict_type= s->pict_type;
+
+ if(s->current_picture.key_frame)
+ s->picture_in_gop_number=0;
+
+ s->last_bits= put_bits_count(&s->pb);
+ switch(s->out_format) {
+ case FMT_MJPEG:
+ mjpeg_picture_header(s);
+ break;
+#ifdef CONFIG_H261_ENCODER
+ case FMT_H261:
+ ff_h261_encode_picture_header(s, picture_number);
+ break;
+#endif
+ case FMT_H263:
+ if (s->codec_id == CODEC_ID_WMV2)
+ ff_wmv2_encode_picture_header(s, picture_number);
+ else if (s->h263_msmpeg4)
+ msmpeg4_encode_picture_header(s, picture_number);
+ else if (s->h263_pred)
+ mpeg4_encode_picture_header(s, picture_number);
+#ifdef CONFIG_RV10_ENCODER
+ else if (s->codec_id == CODEC_ID_RV10)
+ rv10_encode_picture_header(s, picture_number);
+#endif
+#ifdef CONFIG_RV20_ENCODER
+ else if (s->codec_id == CODEC_ID_RV20)
+ rv20_encode_picture_header(s, picture_number);
+#endif
+ else if (s->codec_id == CODEC_ID_FLV1)
+ ff_flv_encode_picture_header(s, picture_number);
+ else
+ h263_encode_picture_header(s, picture_number);
+ break;
+ case FMT_MPEG1:
+ mpeg1_encode_picture_header(s, picture_number);
+ break;
+ case FMT_H264:
+ break;
+ default:
+ assert(0);
+ }
+ bits= put_bits_count(&s->pb);
+ s->header_bits= bits - s->last_bits;
+
+ for(i=1; i<s->avctx->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);
+ for(i=1; i<s->avctx->thread_count; i++){
+ merge_context_after_encode(s, s->thread_context[i]);
+ }
+ emms_c();
+ return 0;
+}
+
+static void denoise_dct_c(MpegEncContext *s, DCTELEM *block){
+ const int intra= s->mb_intra;
+ int i;
+
+ s->dct_count[intra]++;
+
+ for(i=0; i<64; i++){
+ int level= block[i];
+
+ if(level){
+ if(level>0){
+ s->dct_error_sum[intra][i] += level;
+ level -= s->dct_offset[intra][i];
+ if(level<0) level=0;
+ }else{
+ s->dct_error_sum[intra][i] -= level;
+ level += s->dct_offset[intra][i];
+ if(level>0) level=0;
+ }
+ block[i]= level;
+ }
+ }
+}
+
+static int dct_quantize_trellis_c(MpegEncContext *s,
+ DCTELEM *block, int n,
+ int qscale, int *overflow){
+ const int *qmat;
+ const uint8_t *scantable= s->intra_scantable.scantable;
+ const uint8_t *perm_scantable= s->intra_scantable.permutated;
+ int max=0;
+ unsigned int threshold1, threshold2;
+ int bias=0;
+ int run_tab[65];
+ int level_tab[65];
+ int score_tab[65];
+ int survivor[65];
+ int survivor_count;
+ int last_run=0;
+ int last_level=0;
+ int last_score= 0;
+ int last_i;
+ int coeff[2][64];
+ int coeff_count[64];
+ int qmul, qadd, start_i, last_non_zero, i, dc;
+ const int esc_length= s->ac_esc_length;
+ uint8_t * length;
+ uint8_t * last_length;
+ const int lambda= s->lambda2 >> (FF_LAMBDA_SHIFT - 6);
+
+ s->dsp.fdct (block);
+
+ if(s->dct_error_sum)
+ s->denoise_dct(s, block);
+ qmul= qscale*16;
+ qadd= ((qscale-1)|1)*8;
+
+ if (s->mb_intra) {
+ int q;
+ if (!s->h263_aic) {
+ if (n < 4)
+ q = s->y_dc_scale;
+ else
+ q = s->c_dc_scale;
+ q = q << 3;
+ } else{
+ /* For AIC we skip quant/dequant of INTRADC */
+ q = 1 << 3;
+ qadd=0;
+ }
+
+ /* note: block[0] is assumed to be positive */
+ block[0] = (block[0] + (q >> 1)) / q;
+ start_i = 1;
+ last_non_zero = 0;
+ qmat = s->q_intra_matrix[qscale];
+ if(s->mpeg_quant || s->out_format == FMT_MPEG1)
+ bias= 1<<(QMAT_SHIFT-1);
+ length = s->intra_ac_vlc_length;
+ last_length= s->intra_ac_vlc_last_length;
+ } else {
+ start_i = 0;
+ last_non_zero = -1;
+ qmat = s->q_inter_matrix[qscale];
+ length = s->inter_ac_vlc_length;
+ last_length= s->inter_ac_vlc_last_length;
+ }
+ last_i= start_i;
+
+ threshold1= (1<<QMAT_SHIFT) - bias - 1;
+ threshold2= (threshold1<<1);
+
+ for(i=63; i>=start_i; i--) {
+ const int j = scantable[i];
+ int level = block[j] * qmat[j];
+
+ if(((unsigned)(level+threshold1))>threshold2){
+ last_non_zero = i;
+ break;
+ }
+ }
+
+ for(i=start_i; i<=last_non_zero; i++) {
+ const int j = scantable[i];
+ int level = block[j] * qmat[j];
+
+// if( bias+level >= (1<<(QMAT_SHIFT - 3))
+// || bias-level >= (1<<(QMAT_SHIFT - 3))){
+ if(((unsigned)(level+threshold1))>threshold2){
+ if(level>0){
+ level= (bias + level)>>QMAT_SHIFT;
+ coeff[0][i]= level;
+ coeff[1][i]= level-1;
+// coeff[2][k]= level-2;
+ }else{
+ level= (bias - level)>>QMAT_SHIFT;
+ coeff[0][i]= -level;
+ coeff[1][i]= -level+1;
+// coeff[2][k]= -level+2;
+ }
+ coeff_count[i]= FFMIN(level, 2);
+ assert(coeff_count[i]);
+ max |=level;
+ }else{
+ coeff[0][i]= (level>>31)|1;
+ coeff_count[i]= 1;
+ }
+ }
+
+ *overflow= s->max_qcoeff < max; //overflow might have happened
+
+ if(last_non_zero < start_i){
+ memset(block + start_i, 0, (64-start_i)*sizeof(DCTELEM));
+ return last_non_zero;
+ }
+
+ score_tab[start_i]= 0;
+ survivor[0]= start_i;
+ survivor_count= 1;
+
+ for(i=start_i; i<=last_non_zero; i++){
+ int level_index, j;
+ const int dct_coeff= FFABS(block[ scantable[i] ]);
+ const int zero_distoration= dct_coeff*dct_coeff;
+ int best_score=256*256*256*120;
+ for(level_index=0; level_index < coeff_count[i]; level_index++){
+ int distoration;
+ int level= coeff[level_index][i];
+ const int alevel= FFABS(level);
+ int unquant_coeff;
+
+ assert(level);
+
+ if(s->out_format == FMT_H263){
+ unquant_coeff= alevel*qmul + qadd;
+ }else{ //MPEG1
+ j= s->dsp.idct_permutation[ scantable[i] ]; //FIXME optimize
+ if(s->mb_intra){
+ unquant_coeff = (int)( alevel * qscale * s->intra_matrix[j]) >> 3;
+ unquant_coeff = (unquant_coeff - 1) | 1;
+ }else{
+ unquant_coeff = ((( alevel << 1) + 1) * qscale * ((int) s->inter_matrix[j])) >> 4;
+ unquant_coeff = (unquant_coeff - 1) | 1;
+ }
+ unquant_coeff<<= 3;
+ }
+
+ distoration= (unquant_coeff - dct_coeff) * (unquant_coeff - dct_coeff) - zero_distoration;
+ level+=64;
+ if((level&(~127)) == 0){
+ for(j=survivor_count-1; j>=0; j--){
+ int run= i - survivor[j];
+ int score= distoration + length[UNI_AC_ENC_INDEX(run, level)]*lambda;
+ score += score_tab[i-run];
+
+ if(score < best_score){
+ best_score= score;
+ run_tab[i+1]= run;
+ level_tab[i+1]= level-64;
+ }
+ }
+
+ if(s->out_format == FMT_H263){
+ for(j=survivor_count-1; j>=0; j--){
+ int run= i - survivor[j];
+ int score= distoration + last_length[UNI_AC_ENC_INDEX(run, level)]*lambda;
+ score += score_tab[i-run];
+ if(score < last_score){
+ last_score= score;
+ last_run= run;
+ last_level= level-64;
+ last_i= i+1;
+ }
+ }
+ }
+ }else{
+ distoration += esc_length*lambda;
+ for(j=survivor_count-1; j>=0; j--){
+ int run= i - survivor[j];
+ int score= distoration + score_tab[i-run];
+
+ if(score < best_score){
+ best_score= score;
+ run_tab[i+1]= run;
+ level_tab[i+1]= level-64;
+ }
+ }
+
+ if(s->out_format == FMT_H263){
+ for(j=survivor_count-1; j>=0; j--){
+ int run= i - survivor[j];
+ int score= distoration + score_tab[i-run];
+ if(score < last_score){
+ last_score= score;
+ last_run= run;
+ last_level= level-64;
+ last_i= i+1;
+ }
+ }
+ }
+ }
+ }
+
+ score_tab[i+1]= best_score;
+
+ //Note: there is a vlc code in mpeg4 which is 1 bit shorter then another one with a shorter run and the same level
+ if(last_non_zero <= 27){
+ for(; survivor_count; survivor_count--){
+ if(score_tab[ survivor[survivor_count-1] ] <= best_score)
+ break;
+ }
+ }else{
+ for(; survivor_count; survivor_count--){
+ if(score_tab[ survivor[survivor_count-1] ] <= best_score + lambda)
+ break;
+ }
+ }
+
+ survivor[ survivor_count++ ]= i+1;
+ }
+
+ if(s->out_format != FMT_H263){
+ last_score= 256*256*256*120;
+ for(i= survivor[0]; i<=last_non_zero + 1; i++){
+ int score= score_tab[i];
+ if(i) score += lambda*2; //FIXME exacter?
+
+ if(score < last_score){
+ last_score= score;
+ last_i= i;
+ last_level= level_tab[i];
+ last_run= run_tab[i];
+ }
+ }
+ }
+
+ s->coded_score[n] = last_score;
+
+ dc= FFABS(block[0]);
+ last_non_zero= last_i - 1;
+ memset(block + start_i, 0, (64-start_i)*sizeof(DCTELEM));
+
+ if(last_non_zero < start_i)
+ return last_non_zero;
+
+ if(last_non_zero == 0 && start_i == 0){
+ int best_level= 0;
+ int best_score= dc * dc;
+
+ for(i=0; i<coeff_count[0]; i++){
+ int level= coeff[i][0];
+ int alevel= FFABS(level);
+ int unquant_coeff, score, distortion;
+
+ if(s->out_format == FMT_H263){
+ unquant_coeff= (alevel*qmul + qadd)>>3;
+ }else{ //MPEG1
+ unquant_coeff = ((( alevel << 1) + 1) * qscale * ((int) s->inter_matrix[0])) >> 4;
+ unquant_coeff = (unquant_coeff - 1) | 1;
+ }
+ unquant_coeff = (unquant_coeff + 4) >> 3;
+ unquant_coeff<<= 3 + 3;
+
+ distortion= (unquant_coeff - dc) * (unquant_coeff - dc);
+ level+=64;
+ if((level&(~127)) == 0) score= distortion + last_length[UNI_AC_ENC_INDEX(0, level)]*lambda;
+ else score= distortion + esc_length*lambda;
+
+ if(score < best_score){
+ best_score= score;
+ best_level= level - 64;
+ }
+ }
+ block[0]= best_level;
+ s->coded_score[n] = best_score - dc*dc;
+ if(best_level == 0) return -1;
+ else return last_non_zero;
+ }
+
+ i= last_i;
+ assert(last_level);
+
+ block[ perm_scantable[last_non_zero] ]= last_level;
+ i -= last_run + 1;
+
+ for(; i>start_i; i -= run_tab[i] + 1){
+ block[ perm_scantable[i-1] ]= level_tab[i];
+ }
+
+ return last_non_zero;
+}
+
+//#define REFINE_STATS 1
+static int16_t basis[64][64];
+
+static void build_basis(uint8_t *perm){
+ int i, j, x, y;
+ emms_c();
+ for(i=0; i<8; i++){
+ for(j=0; j<8; j++){
+ for(y=0; y<8; y++){
+ for(x=0; x<8; x++){
+ double s= 0.25*(1<<BASIS_SHIFT);
+ int index= 8*i + j;
+ int perm_index= perm[index];
+ if(i==0) s*= sqrt(0.5);
+ if(j==0) s*= sqrt(0.5);
+ basis[perm_index][8*x + y]= lrintf(s * cos((M_PI/8.0)*i*(x+0.5)) * cos((M_PI/8.0)*j*(y+0.5)));
+ }
+ }
+ }
+ }
+}
+
+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]);
+ const int *qmat;
+ const uint8_t *scantable= s->intra_scantable.scantable;
+ const uint8_t *perm_scantable= s->intra_scantable.permutated;
+// unsigned int threshold1, threshold2;
+// int bias=0;
+ int run_tab[65];
+ int prev_run=0;
+ int prev_level=0;
+ int qmul, qadd, start_i, last_non_zero, i, dc;
+ uint8_t * length;
+ uint8_t * last_length;
+ int lambda;
+ int rle_index, run, q = 1, sum; //q is only used when s->mb_intra is true
+#ifdef REFINE_STATS
+static int count=0;
+static int after_last=0;
+static int to_zero=0;
+static int from_zero=0;
+static int raise=0;
+static int lower=0;
+static int messed_sign=0;
+#endif
+
+ if(basis[0][0] == 0)
+ build_basis(s->dsp.idct_permutation);
+
+ qmul= qscale*2;
+ qadd= (qscale-1)|1;
+ if (s->mb_intra) {
+ if (!s->h263_aic) {
+ if (n < 4)
+ q = s->y_dc_scale;
+ else
+ q = s->c_dc_scale;
+ } else{
+ /* For AIC we skip quant/dequant of INTRADC */
+ q = 1;
+ qadd=0;
+ }
+ q <<= RECON_SHIFT-3;
+ /* note: block[0] is assumed to be positive */
+ dc= block[0]*q;
+// block[0] = (block[0] + (q >> 1)) / q;
+ start_i = 1;
+ qmat = s->q_intra_matrix[qscale];
+// if(s->mpeg_quant || s->out_format == FMT_MPEG1)
+// bias= 1<<(QMAT_SHIFT-1);
+ length = s->intra_ac_vlc_length;
+ last_length= s->intra_ac_vlc_last_length;
+ } else {
+ dc= 0;
+ start_i = 0;
+ qmat = s->q_inter_matrix[qscale];
+ length = s->inter_ac_vlc_length;
+ last_length= s->inter_ac_vlc_last_length;
+ }
+ last_non_zero = s->block_last_index[n];
+
+#ifdef REFINE_STATS
+{START_TIMER
+#endif
+ dc += (1<<(RECON_SHIFT-1));
+ for(i=0; i<64; i++){
+ rem[i]= dc - (orig[i]<<RECON_SHIFT); //FIXME use orig dirrectly instead of copying to rem[]
+ }
+#ifdef REFINE_STATS
+STOP_TIMER("memset rem[]")}
+#endif
+ sum=0;
+ for(i=0; i<64; i++){
+ int one= 36;
+ int qns=4;
+ int w;
+
+ w= FFABS(weight[i]) + qns*one;
+ w= 15 + (48*qns*one + w/2)/w; // 16 .. 63
+
+ weight[i] = w;
+// w=weight[i] = (63*qns + (w/2)) / w;
+
+ assert(w>0);
+ assert(w<(1<<6));
+ sum += w*w;
+ }
+ lambda= sum*(uint64_t)s->lambda2 >> (FF_LAMBDA_SHIFT - 6 + 6 + 6 + 6);
+#ifdef REFINE_STATS
+{START_TIMER
+#endif
+ run=0;
+ rle_index=0;
+ for(i=start_i; i<=last_non_zero; i++){
+ int j= perm_scantable[i];
+ const int level= block[j];
+ int coeff;
+
+ if(level){
+ if(level<0) coeff= qmul*level - qadd;
+ else coeff= qmul*level + qadd;
+ run_tab[rle_index++]=run;
+ run=0;
+
+ s->dsp.add_8x8basis(rem, basis[j], coeff);
+ }else{
+ run++;
+ }
+ }
+#ifdef REFINE_STATS
+if(last_non_zero>0){
+STOP_TIMER("init rem[]")
+}
+}
+
+{START_TIMER
+#endif
+ for(;;){
+ int best_score=s->dsp.try_8x8basis(rem, weight, basis[0], 0);
+ int best_coeff=0;
+ int best_change=0;
+ int run2, best_unquant_change=0, analyze_gradient;
+#ifdef REFINE_STATS
+{START_TIMER
+#endif
+ analyze_gradient = last_non_zero > 2 || s->avctx->quantizer_noise_shaping >= 3;
+
+ if(analyze_gradient){
+#ifdef REFINE_STATS
+{START_TIMER
+#endif
+ for(i=0; i<64; i++){
+ int w= weight[i];
+
+ d1[i] = (rem[i]*w*w + (1<<(RECON_SHIFT+12-1)))>>(RECON_SHIFT+12);
+ }
+#ifdef REFINE_STATS
+STOP_TIMER("rem*w*w")}
+{START_TIMER
+#endif
+ s->dsp.fdct(d1);
+#ifdef REFINE_STATS
+STOP_TIMER("dct")}
+#endif
+ }
+
+ if(start_i){
+ const int level= block[0];
+ int change, old_coeff;
+
+ assert(s->mb_intra);
+
+ old_coeff= q*level;
+
+ for(change=-1; change<=1; change+=2){
+ int new_level= level + change;
+ int score, new_coeff;
+
+ new_coeff= q*new_level;
+ if(new_coeff >= 2048 || new_coeff < 0)
+ continue;
+
+ score= s->dsp.try_8x8basis(rem, weight, basis[0], new_coeff - old_coeff);
+ if(score<best_score){
+ best_score= score;
+ best_coeff= 0;
+ best_change= change;
+ best_unquant_change= new_coeff - old_coeff;
+ }
+ }
+ }
+
+ run=0;
+ rle_index=0;
+ run2= run_tab[rle_index++];
+ prev_level=0;
+ prev_run=0;
+
+ for(i=start_i; i<64; i++){
+ int j= perm_scantable[i];
+ const int level= block[j];
+ int change, old_coeff;
+
+ if(s->avctx->quantizer_noise_shaping < 3 && i > last_non_zero + 1)
+ break;
+
+ if(level){
+ if(level<0) old_coeff= qmul*level - qadd;
+ else old_coeff= qmul*level + qadd;
+ run2= run_tab[rle_index++]; //FIXME ! maybe after last
+ }else{
+ old_coeff=0;
+ run2--;
+ assert(run2>=0 || i >= last_non_zero );
+ }
+
+ for(change=-1; change<=1; change+=2){
+ int new_level= level + change;
+ int score, new_coeff, unquant_change;
+
+ score=0;
+ if(s->avctx->quantizer_noise_shaping < 2 && FFABS(new_level) > FFABS(level))
+ continue;
+
+ if(new_level){
+ if(new_level<0) new_coeff= qmul*new_level - qadd;
+ else new_coeff= qmul*new_level + qadd;
+ if(new_coeff >= 2048 || new_coeff <= -2048)
+ continue;
+ //FIXME check for overflow
+
+ if(level){
+ if(level < 63 && level > -63){
+ if(i < last_non_zero)
+ score += length[UNI_AC_ENC_INDEX(run, new_level+64)]
+ - length[UNI_AC_ENC_INDEX(run, level+64)];
+ else
+ score += last_length[UNI_AC_ENC_INDEX(run, new_level+64)]
+ - last_length[UNI_AC_ENC_INDEX(run, level+64)];
+ }
+ }else{
+ assert(FFABS(new_level)==1);
+
+ if(analyze_gradient){
+ int g= d1[ scantable[i] ];
+ if(g && (g^new_level) >= 0)
+ continue;
+ }
+
+ if(i < last_non_zero){
+ int next_i= i + run2 + 1;
+ int next_level= block[ perm_scantable[next_i] ] + 64;
+
+ if(next_level&(~127))
+ next_level= 0;
+
+ if(next_i < last_non_zero)
+ score += length[UNI_AC_ENC_INDEX(run, 65)]
+ + length[UNI_AC_ENC_INDEX(run2, next_level)]
+ - length[UNI_AC_ENC_INDEX(run + run2 + 1, next_level)];
+ else
+ score += length[UNI_AC_ENC_INDEX(run, 65)]
+ + last_length[UNI_AC_ENC_INDEX(run2, next_level)]
+ - last_length[UNI_AC_ENC_INDEX(run + run2 + 1, next_level)];
+ }else{
+ score += last_length[UNI_AC_ENC_INDEX(run, 65)];
+ if(prev_level){
+ score += length[UNI_AC_ENC_INDEX(prev_run, prev_level)]
+ - last_length[UNI_AC_ENC_INDEX(prev_run, prev_level)];
+ }
+ }
+ }
+ }else{
+ new_coeff=0;
+ assert(FFABS(level)==1);
+
+ if(i < last_non_zero){
+ int next_i= i + run2 + 1;
+ int next_level= block[ perm_scantable[next_i] ] + 64;
+
+ if(next_level&(~127))
+ next_level= 0;
+
+ if(next_i < last_non_zero)
+ score += length[UNI_AC_ENC_INDEX(run + run2 + 1, next_level)]
+ - length[UNI_AC_ENC_INDEX(run2, next_level)]
+ - length[UNI_AC_ENC_INDEX(run, 65)];
+ else
+ score += last_length[UNI_AC_ENC_INDEX(run + run2 + 1, next_level)]
+ - last_length[UNI_AC_ENC_INDEX(run2, next_level)]
+ - length[UNI_AC_ENC_INDEX(run, 65)];
+ }else{
+ score += -last_length[UNI_AC_ENC_INDEX(run, 65)];
+ if(prev_level){
+ score += last_length[UNI_AC_ENC_INDEX(prev_run, prev_level)]
+ - length[UNI_AC_ENC_INDEX(prev_run, prev_level)];
+ }
+ }
+ }
+
+ score *= lambda;
+
+ unquant_change= new_coeff - old_coeff;
+ assert((score < 100*lambda && score > -100*lambda) || lambda==0);
+
+ score+= s->dsp.try_8x8basis(rem, weight, basis[j], unquant_change);
+ if(score<best_score){
+ best_score= score;
+ best_coeff= i;
+ best_change= change;
+ best_unquant_change= unquant_change;
+ }
+ }
+ if(level){
+ prev_level= level + 64;
+ if(prev_level&(~127))
+ prev_level= 0;
+ prev_run= run;
+ run=0;
+ }else{
+ run++;
+ }
+ }
+#ifdef REFINE_STATS
+STOP_TIMER("iterative step")}
+#endif
+
+ if(best_change){
+ int j= perm_scantable[ best_coeff ];
+
+ block[j] += best_change;
+
+ if(best_coeff > last_non_zero){
+ last_non_zero= best_coeff;
+ assert(block[j]);
+#ifdef REFINE_STATS
+after_last++;
+#endif
+ }else{
+#ifdef REFINE_STATS
+if(block[j]){
+ if(block[j] - best_change){
+ if(FFABS(block[j]) > FFABS(block[j] - best_change)){
+ raise++;
+ }else{
+ lower++;
+ }
+ }else{
+ from_zero++;
+ }
+}else{
+ to_zero++;
+}
+#endif
+ for(; last_non_zero>=start_i; last_non_zero--){
+ if(block[perm_scantable[last_non_zero]])
+ break;
+ }
+ }
+#ifdef REFINE_STATS
+count++;
+if(256*256*256*64 % count == 0){
+ printf("after_last:%d to_zero:%d from_zero:%d raise:%d lower:%d sign:%d xyp:%d/%d/%d\n", after_last, to_zero, from_zero, raise, lower, messed_sign, s->mb_x, s->mb_y, s->picture_number);
+}
+#endif
+ run=0;
+ rle_index=0;
+ for(i=start_i; i<=last_non_zero; i++){
+ int j= perm_scantable[i];
+ const int level= block[j];
+
+ if(level){
+ run_tab[rle_index++]=run;
+ run=0;
+ }else{
+ run++;
+ }
+ }
+
+ s->dsp.add_8x8basis(rem, basis[j], best_unquant_change);
+ }else{
+ break;
+ }
+ }
+#ifdef REFINE_STATS
+if(last_non_zero>0){
+STOP_TIMER("iterative search")
+}
+}
+#endif
+
+ return last_non_zero;
+}
+
+static int dct_quantize_c(MpegEncContext *s,
+ DCTELEM *block, int n,
+ int qscale, int *overflow)
+{
+ int i, j, level, last_non_zero, q, start_i;
+ const int *qmat;
+ const uint8_t *scantable= s->intra_scantable.scantable;
+ int bias;
+ int max=0;
+ unsigned int threshold1, threshold2;
+
+ s->dsp.fdct (block);
+
+ if(s->dct_error_sum)
+ s->denoise_dct(s, block);
+
+ if (s->mb_intra) {
+ if (!s->h263_aic) {
+ if (n < 4)
+ q = s->y_dc_scale;
+ else
+ q = s->c_dc_scale;
+ q = q << 3;
+ } else
+ /* For AIC we skip quant/dequant of INTRADC */
+ q = 1 << 3;
+
+ /* note: block[0] is assumed to be positive */
+ block[0] = (block[0] + (q >> 1)) / q;
+ start_i = 1;
+ last_non_zero = 0;
+ qmat = s->q_intra_matrix[qscale];
+ bias= s->intra_quant_bias<<(QMAT_SHIFT - QUANT_BIAS_SHIFT);
+ } else {
+ start_i = 0;
+ last_non_zero = -1;
+ qmat = s->q_inter_matrix[qscale];
+ bias= s->inter_quant_bias<<(QMAT_SHIFT - QUANT_BIAS_SHIFT);
+ }
+ threshold1= (1<<QMAT_SHIFT) - bias - 1;
+ threshold2= (threshold1<<1);
+ for(i=63;i>=start_i;i--) {
+ j = scantable[i];
+ level = block[j] * qmat[j];
+
+ if(((unsigned)(level+threshold1))>threshold2){
+ last_non_zero = i;
+ break;
+ }else{
+ block[j]=0;
+ }
+ }
+ for(i=start_i; i<=last_non_zero; i++) {
+ j = scantable[i];
+ level = block[j] * qmat[j];
+
+// if( bias+level >= (1<<QMAT_SHIFT)
+// || bias-level >= (1<<QMAT_SHIFT)){
+ if(((unsigned)(level+threshold1))>threshold2){
+ if(level>0){
+ level= (bias + level)>>QMAT_SHIFT;
+ block[j]= level;
+ }else{
+ level= (bias - level)>>QMAT_SHIFT;
+ block[j]= -level;
+ }
+ max |=level;
+ }else{
+ block[j]=0;
+ }
+ }
+ *overflow= s->max_qcoeff < max; //overflow might have happened
+
+ /* we need this permutation so that we correct the IDCT, we only permute the !=0 elements */
+ if (s->dsp.idct_permutation_type != FF_NO_IDCT_PERM)
+ ff_block_permute(block, s->dsp.idct_permutation, scantable, last_non_zero);
+
+ return last_non_zero;
+}
+
+#endif //CONFIG_ENCODERS
+
+static void dct_unquantize_mpeg1_intra_c(MpegEncContext *s,
+ DCTELEM *block, int n, int qscale)
+{
+ int i, level, nCoeffs;
+ const uint16_t *quant_matrix;
+
+ nCoeffs= s->block_last_index[n];
+
+ if (n < 4)
+ block[0] = block[0] * s->y_dc_scale;
+ else
+ block[0] = block[0] * s->c_dc_scale;
+ /* XXX: only mpeg1 */
+ quant_matrix = s->intra_matrix;
+ for(i=1;i<=nCoeffs;i++) {
+ int j= s->intra_scantable.permutated[i];
+ level = block[j];
+ if (level) {
+ if (level < 0) {
+ level = -level;
+ level = (int)(level * qscale * quant_matrix[j]) >> 3;
+ level = (level - 1) | 1;
+ level = -level;
+ } else {
+ level = (int)(level * qscale * quant_matrix[j]) >> 3;
+ level = (level - 1) | 1;
+ }
+ block[j] = level;
+ }
+ }
+}
+
+static void dct_unquantize_mpeg1_inter_c(MpegEncContext *s,
+ DCTELEM *block, int n, int qscale)
+{
+ int i, level, nCoeffs;
+ const uint16_t *quant_matrix;
+
+ nCoeffs= s->block_last_index[n];
+
+ quant_matrix = s->inter_matrix;
+ for(i=0; i<=nCoeffs; i++) {
+ int j= s->intra_scantable.permutated[i];
+ level = block[j];
+ if (level) {
+ if (level < 0) {
+ level = -level;
+ level = (((level << 1) + 1) * qscale *
+ ((int) (quant_matrix[j]))) >> 4;
+ level = (level - 1) | 1;
+ level = -level;
+ } else {
+ level = (((level << 1) + 1) * qscale *
+ ((int) (quant_matrix[j]))) >> 4;
+ level = (level - 1) | 1;
+ }
+ block[j] = level;
+ }
+ }
+}
+
+static void dct_unquantize_mpeg2_intra_c(MpegEncContext *s,
+ DCTELEM *block, int n, int qscale)
+{
+ int i, level, nCoeffs;
+ const uint16_t *quant_matrix;
+
+ if(s->alternate_scan) nCoeffs= 63;
+ else nCoeffs= s->block_last_index[n];
+
+ if (n < 4)
+ block[0] = block[0] * s->y_dc_scale;
+ else
+ block[0] = block[0] * s->c_dc_scale;
+ quant_matrix = s->intra_matrix;
+ for(i=1;i<=nCoeffs;i++) {
+ int j= s->intra_scantable.permutated[i];
+ level = block[j];
+ if (level) {
+ if (level < 0) {
+ level = -level;
+ level = (int)(level * qscale * quant_matrix[j]) >> 3;
+ level = -level;
+ } else {
+ level = (int)(level * qscale * quant_matrix[j]) >> 3;
+ }
+ block[j] = level;
+ }
+ }
+}
+
+static void dct_unquantize_mpeg2_intra_bitexact(MpegEncContext *s,
+ DCTELEM *block, int n, int qscale)
+{
+ int i, level, nCoeffs;
+ const uint16_t *quant_matrix;
+ int sum=-1;
+
+ if(s->alternate_scan) nCoeffs= 63;
+ else nCoeffs= s->block_last_index[n];
+
+ if (n < 4)
+ block[0] = block[0] * s->y_dc_scale;
+ else
+ block[0] = block[0] * s->c_dc_scale;
+ quant_matrix = s->intra_matrix;
+ for(i=1;i<=nCoeffs;i++) {
+ int j= s->intra_scantable.permutated[i];
+ level = block[j];
+ if (level) {
+ if (level < 0) {
+ level = -level;
+ level = (int)(level * qscale * quant_matrix[j]) >> 3;
+ level = -level;
+ } else {
+ level = (int)(level * qscale * quant_matrix[j]) >> 3;
+ }
+ block[j] = level;
+ sum+=level;
+ }
+ }
+ block[63]^=sum&1;
+}
+
+static void dct_unquantize_mpeg2_inter_c(MpegEncContext *s,
+ DCTELEM *block, int n, int qscale)
+{
+ int i, level, nCoeffs;
+ const uint16_t *quant_matrix;
+ int sum=-1;
+
+ if(s->alternate_scan) nCoeffs= 63;
+ else nCoeffs= s->block_last_index[n];
+
+ quant_matrix = s->inter_matrix;
+ for(i=0; i<=nCoeffs; i++) {
+ int j= s->intra_scantable.permutated[i];
+ level = block[j];
+ if (level) {
+ if (level < 0) {
+ level = -level;
+ level = (((level << 1) + 1) * qscale *
+ ((int) (quant_matrix[j]))) >> 4;
+ level = -level;
+ } else {
+ level = (((level << 1) + 1) * qscale *
+ ((int) (quant_matrix[j]))) >> 4;
+ }
+ block[j] = level;
+ sum+=level;
+ }
+ }
+ block[63]^=sum&1;
+}
+
+static void dct_unquantize_h263_intra_c(MpegEncContext *s,
+ DCTELEM *block, int n, int qscale)
+{
+ int i, level, qmul, qadd;
+ int nCoeffs;
+
+ assert(s->block_last_index[n]>=0);
+
+ qmul = qscale << 1;
+
+ if (!s->h263_aic) {
+ if (n < 4)
+ block[0] = block[0] * s->y_dc_scale;
+ else
+ block[0] = block[0] * s->c_dc_scale;
+ qadd = (qscale - 1) | 1;
+ }else{
+ qadd = 0;
+ }
+ if(s->ac_pred)
+ nCoeffs=63;
+ else
+ nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];
+
+ for(i=1; i<=nCoeffs; i++) {
+ level = block[i];
+ if (level) {
+ if (level < 0) {
+ level = level * qmul - qadd;
+ } else {
+ level = level * qmul + qadd;
+ }
+ block[i] = level;
+ }
+ }
+}
+
+static void dct_unquantize_h263_inter_c(MpegEncContext *s,
+ DCTELEM *block, int n, int qscale)
+{
+ int i, level, qmul, qadd;
+ int nCoeffs;
+
+ assert(s->block_last_index[n]>=0);
+
+ qadd = (qscale - 1) | 1;
+ qmul = qscale << 1;
+
+ nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];
+
+ for(i=0; i<=nCoeffs; i++) {
+ level = block[i];
+ if (level) {
+ if (level < 0) {
+ level = level * qmul - qadd;
+ } else {
+ level = level * qmul + qadd;
+ }
+ block[i] = level;
+ }
+ }
+}
+
+#ifdef CONFIG_ENCODERS
+AVCodec h263_encoder = {
+ "h263",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_H263,
+ sizeof(MpegEncContext),
+ MPV_encode_init,
+ MPV_encode_picture,
+ MPV_encode_end,
+ .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1},
+};
+
+AVCodec h263p_encoder = {
+ "h263p",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_H263P,
+ sizeof(MpegEncContext),
+ MPV_encode_init,
+ MPV_encode_picture,
+ MPV_encode_end,
+ .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1},
+};
+
+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, -1},
+};
+
+AVCodec rv10_encoder = {
+ "rv10",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_RV10,
+ sizeof(MpegEncContext),
+ MPV_encode_init,
+ MPV_encode_picture,
+ MPV_encode_end,
+ .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1},
+};
+
+AVCodec rv20_encoder = {
+ "rv20",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_RV20,
+ sizeof(MpegEncContext),
+ MPV_encode_init,
+ MPV_encode_picture,
+ MPV_encode_end,
+ .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1},
+};
+
+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, -1},
+ .capabilities= CODEC_CAP_DELAY,
+};
+
+AVCodec msmpeg4v1_encoder = {
+ "msmpeg4v1",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_MSMPEG4V1,
+ sizeof(MpegEncContext),
+ MPV_encode_init,
+ MPV_encode_picture,
+ MPV_encode_end,
+ .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1},
+};
+
+AVCodec msmpeg4v2_encoder = {
+ "msmpeg4v2",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_MSMPEG4V2,
+ sizeof(MpegEncContext),
+ MPV_encode_init,
+ MPV_encode_picture,
+ MPV_encode_end,
+ .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1},
+};
+
+AVCodec msmpeg4v3_encoder = {
+ "msmpeg4",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_MSMPEG4V3,
+ sizeof(MpegEncContext),
+ MPV_encode_init,
+ MPV_encode_picture,
+ MPV_encode_end,
+ .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1},
+};
+
+AVCodec wmv1_encoder = {
+ "wmv1",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_WMV1,
+ sizeof(MpegEncContext),
+ MPV_encode_init,
+ MPV_encode_picture,
+ MPV_encode_end,
+ .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1},
+};
+
+AVCodec mjpeg_encoder = {
+ "mjpeg",
+ CODEC_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, -1},
+};
+
+#endif //CONFIG_ENCODERS
diff --git a/contrib/ffmpeg/libavcodec/mpegvideo.h b/contrib/ffmpeg/libavcodec/mpegvideo.h
new file mode 100644
index 000000000..80e0f9065
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/mpegvideo.h
@@ -0,0 +1,908 @@
+/*
+ * Generic DCT based hybrid video encoder
+ * 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
+ */
+
+/**
+ * @file mpegvideo.h
+ * mpegvideo header.
+ */
+
+#ifndef AVCODEC_MPEGVIDEO_H
+#define AVCODEC_MPEGVIDEO_H
+
+#include "dsputil.h"
+#include "bitstream.h"
+#include "ratecontrol.h"
+#include "parser.h"
+
+#define FRAME_SKIPPED 100 ///< return value for header parsers if frame is not coded
+
+enum OutputFormat {
+ FMT_MPEG1,
+ FMT_H261,
+ FMT_H263,
+ FMT_MJPEG,
+ FMT_H264,
+};
+
+#define EDGE_WIDTH 16
+
+#define MPEG_BUF_SIZE (16 * 1024)
+
+#define QMAT_SHIFT_MMX 16
+#define QMAT_SHIFT 22
+
+#define MAX_FCODE 7
+#define MAX_MV 2048
+
+#define MAX_THREADS 8
+
+#define MAX_PICTURE_COUNT 32
+
+#define ME_MAP_SIZE 64
+#define ME_MAP_SHIFT 3
+#define ME_MAP_MV_BITS 11
+
+/* run length table */
+#define MAX_RUN 64
+#define MAX_LEVEL 64
+
+#define I_TYPE FF_I_TYPE ///< Intra
+#define P_TYPE FF_P_TYPE ///< Predicted
+#define B_TYPE FF_B_TYPE ///< Bi-dir predicted
+#define S_TYPE FF_S_TYPE ///< S(GMC)-VOP MPEG4
+#define SI_TYPE FF_SI_TYPE ///< Switching Intra
+#define SP_TYPE FF_SP_TYPE ///< Switching Predicted
+
+#define MAX_MB_BYTES (30*16*16*3/8 + 120)
+
+#define INPLACE_OFFSET 16
+
+/**
+ * Scantable.
+ */
+typedef struct ScanTable{
+ const uint8_t *scantable;
+ uint8_t permutated[64];
+ uint8_t raster_end[64];
+#ifdef ARCH_POWERPC
+ /** Used by dct_quantise_alitvec to find last-non-zero */
+ DECLARE_ALIGNED_8(uint8_t, inverse[64]);
+#endif
+} ScanTable;
+
+/**
+ * Picture.
+ */
+typedef struct Picture{
+ FF_COMMON_FRAME
+
+ /**
+ * halfpel luma planes.
+ */
+ uint8_t *interpolated[3];
+ int16_t (*motion_val_base[2])[2];
+ uint32_t *mb_type_base;
+#define MB_TYPE_INTRA MB_TYPE_INTRA4x4 //default mb_type if theres just one type
+#define IS_INTRA4x4(a) ((a)&MB_TYPE_INTRA4x4)
+#define IS_INTRA16x16(a) ((a)&MB_TYPE_INTRA16x16)
+#define IS_PCM(a) ((a)&MB_TYPE_INTRA_PCM)
+#define IS_INTRA(a) ((a)&7)
+#define IS_INTER(a) ((a)&(MB_TYPE_16x16|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_8x8))
+#define IS_SKIP(a) ((a)&MB_TYPE_SKIP)
+#define IS_INTRA_PCM(a) ((a)&MB_TYPE_INTRA_PCM)
+#define IS_INTERLACED(a) ((a)&MB_TYPE_INTERLACED)
+#define IS_DIRECT(a) ((a)&MB_TYPE_DIRECT2)
+#define IS_GMC(a) ((a)&MB_TYPE_GMC)
+#define IS_16X16(a) ((a)&MB_TYPE_16x16)
+#define IS_16X8(a) ((a)&MB_TYPE_16x8)
+#define IS_8X16(a) ((a)&MB_TYPE_8x16)
+#define IS_8X8(a) ((a)&MB_TYPE_8x8)
+#define IS_SUB_8X8(a) ((a)&MB_TYPE_16x16) //note reused
+#define IS_SUB_8X4(a) ((a)&MB_TYPE_16x8) //note reused
+#define IS_SUB_4X8(a) ((a)&MB_TYPE_8x16) //note reused
+#define IS_SUB_4X4(a) ((a)&MB_TYPE_8x8) //note reused
+#define IS_ACPRED(a) ((a)&MB_TYPE_ACPRED)
+#define IS_QUANT(a) ((a)&MB_TYPE_QUANT)
+#define IS_DIR(a, part, list) ((a) & (MB_TYPE_P0L0<<((part)+2*(list))))
+#define USES_LIST(a, list) ((a) & ((MB_TYPE_P0L0|MB_TYPE_P1L0)<<(2*(list)))) ///< does this mb use listX, note doesnt work if subMBs
+#define HAS_CBP(a) ((a)&MB_TYPE_CBP)
+
+ int field_poc[2]; ///< h264 top/bottom POC
+ int poc; ///< h264 frame POC
+ int frame_num; ///< h264 frame_num
+ int pic_id; ///< h264 pic_num or long_term_pic_idx
+ int long_ref; ///< 1->long term reference 0->short term reference
+ int ref_poc[2][16]; ///< h264 POCs of the frames used as reference
+ int ref_count[2]; ///< number of entries in ref_poc
+
+ int mb_var_sum; ///< sum of MB variance for current frame
+ int mc_mb_var_sum; ///< motion compensated MB variance for current frame
+ uint16_t *mb_var; ///< Table for MB variances
+ uint16_t *mc_mb_var; ///< Table for motion compensated MB variances
+ uint8_t *mb_mean; ///< Table for MB luminance
+ int32_t *mb_cmp_score; ///< Table for MB cmp scores, for mb decision FIXME remove
+ int b_frame_score; /* */
+} Picture;
+
+struct MpegEncContext;
+
+/**
+ * Motion estimation context.
+ */
+typedef struct MotionEstContext{
+ AVCodecContext *avctx;
+ int skip; ///< set if ME is skipped for the current MB
+ int co_located_mv[4][2]; ///< mv from last p frame for direct mode ME
+ int direct_basis_mv[4][2];
+ uint8_t *scratchpad; ///< data area for the me algo, so that the ME doesnt need to malloc/free
+ uint8_t *best_mb;
+ uint8_t *temp_mb[2];
+ uint8_t *temp;
+ int best_bits;
+ uint32_t *map; ///< map to avoid duplicate evaluations
+ uint32_t *score_map; ///< map to store the scores
+ int map_generation;
+ int pre_penalty_factor;
+ int penalty_factor; /*!< an estimate of the bits required to
+ code a given mv value, e.g. (1,0) takes
+ more bits than (0,0). We have to
+ estimate whether any reduction in
+ residual is worth the extra bits. */
+ int sub_penalty_factor;
+ int mb_penalty_factor;
+ int flags;
+ int sub_flags;
+ int mb_flags;
+ int pre_pass; ///< = 1 for the pre pass
+ int dia_size;
+ int xmin;
+ int xmax;
+ int ymin;
+ int ymax;
+ int pred_x;
+ int pred_y;
+ uint8_t *src[4][4];
+ uint8_t *ref[4][4];
+ int stride;
+ int uvstride;
+ /* temp variables for picture complexity calculation */
+ int mc_mb_var_sum_temp;
+ int mb_var_sum_temp;
+ int scene_change_score;
+/* cmp, chroma_cmp;*/
+ op_pixels_func (*hpel_put)[4];
+ op_pixels_func (*hpel_avg)[4];
+ qpel_mc_func (*qpel_put)[16];
+ qpel_mc_func (*qpel_avg)[16];
+ uint8_t (*mv_penalty)[MAX_MV*2+1]; ///< amount of bits needed to encode a MV
+ uint8_t *current_mv_penalty;
+ int (*sub_motion_search)(struct MpegEncContext * s,
+ int *mx_ptr, int *my_ptr, int dmin,
+ int src_index, int ref_index,
+ int size, int h);
+}MotionEstContext;
+
+/**
+ * MpegEncContext.
+ */
+typedef struct MpegEncContext {
+ struct AVCodecContext *avctx;
+ /* the following parameters must be initialized before encoding */
+ int width, height;///< picture size. must be a multiple of 16
+ int gop_size;
+ int intra_only; ///< if true, only intra pictures are generated
+ int bit_rate; ///< wanted bit rate
+ enum OutputFormat out_format; ///< output format
+ int h263_pred; ///< use mpeg4/h263 ac/dc predictions
+
+/* the following codec id fields are deprecated in favor of codec_id */
+ int h263_plus; ///< h263 plus headers
+ int h263_msmpeg4; ///< generate MSMPEG4 compatible stream (deprecated, use msmpeg4_version instead)
+ int h263_flv; ///< use flv h263 header
+
+ enum CodecID codec_id; /* see CODEC_ID_xxx */
+ int fixed_qscale; ///< fixed qscale if non zero
+ int encoding; ///< true if we are encoding (vs decoding)
+ int flags; ///< AVCodecContext.flags (HQ, MV4, ...)
+ int flags2; ///< AVCodecContext.flags2
+ int max_b_frames; ///< max number of b-frames for encoding
+ int luma_elim_threshold;
+ int chroma_elim_threshold;
+ int strict_std_compliance; ///< strictly follow the std (MPEG4, ...)
+ int workaround_bugs; ///< workaround bugs in encoders which cannot be detected automatically
+ int codec_tag; ///< internal codec_tag upper case converted from avctx codec_tag
+ int stream_codec_tag; ///< internal stream_codec_tag upper case converted from avctx stream_codec_tag
+ /* the following fields are managed internally by the encoder */
+
+ /** bit output */
+ PutBitContext pb;
+
+ /* sequence parameters */
+ int context_initialized;
+ int input_picture_number; ///< used to set pic->display_picture_number, shouldnt be used for/by anything else
+ int coded_picture_number; ///< used to set pic->coded_picture_number, shouldnt be used for/by anything else
+ int picture_number; //FIXME remove, unclear definition
+ int picture_in_gop_number; ///< 0-> first pic in gop, ...
+ int b_frames_since_non_b; ///< used for encoding, relative to not yet reordered input
+ int64_t user_specified_pts;///< last non zero pts from AVFrame which was passed into avcodec_encode_video()
+ int mb_width, mb_height; ///< number of MBs horizontally & vertically
+ int mb_stride; ///< mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11
+ int b8_stride; ///< 2*mb_width+1 used for some 8x8 block arrays to allow simple addressing
+ int b4_stride; ///< 4*mb_width+1 used for some 4x4 block arrays to allow simple addressing
+ int h_edge_pos, v_edge_pos;///< horizontal / vertical position of the right/bottom edge (pixel replication)
+ int mb_num; ///< number of MBs of a picture
+ int linesize; ///< line size, in bytes, may be different from width
+ int uvlinesize; ///< line size, for chroma in bytes, may be different from width
+ Picture *picture; ///< main picture buffer
+ Picture **input_picture; ///< next pictures on display order for encoding
+ Picture **reordered_input_picture; ///< pointer to the next pictures in codedorder for encoding
+
+ int start_mb_y; ///< start mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y)
+ int end_mb_y; ///< end mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y)
+ struct MpegEncContext *thread_context[MAX_THREADS];
+
+ /**
+ * copy of the previous picture structure.
+ * note, linesize & data, might not match the previous picture (for field pictures)
+ */
+ Picture last_picture;
+
+ /**
+ * copy of the next picture structure.
+ * note, linesize & data, might not match the next picture (for field pictures)
+ */
+ Picture next_picture;
+
+ /**
+ * copy of the source picture structure for encoding.
+ * note, linesize & data, might not match the source picture (for field pictures)
+ */
+ Picture new_picture;
+
+ /**
+ * copy of the current picture structure.
+ * note, linesize & data, might not match the current picture (for field pictures)
+ */
+ Picture current_picture; ///< buffer to store the decompressed current picture
+
+ Picture *last_picture_ptr; ///< pointer to the previous picture.
+ Picture *next_picture_ptr; ///< pointer to the next picture (for bidir pred)
+ Picture *current_picture_ptr; ///< pointer to the current picture
+ uint8_t *visualization_buffer[3]; //< temporary buffer vor MV visualization
+ int last_dc[3]; ///< last DC values for MPEG1
+ int16_t *dc_val_base;
+ int16_t *dc_val[3]; ///< used for mpeg4 DC prediction, all 3 arrays must be continuous
+ int16_t dc_cache[4*5];
+ int y_dc_scale, c_dc_scale;
+ const uint8_t *y_dc_scale_table; ///< qscale -> y_dc_scale table
+ const uint8_t *c_dc_scale_table; ///< qscale -> c_dc_scale table
+ const uint8_t *chroma_qscale_table; ///< qscale -> chroma_qscale (h263)
+ uint8_t *coded_block_base;
+ uint8_t *coded_block; ///< used for coded block pattern prediction (msmpeg4v3, wmv1)
+ int16_t (*ac_val_base)[16];
+ int16_t (*ac_val[3])[16]; ///< used for for mpeg4 AC prediction, all 3 arrays must be continuous
+ int ac_pred;
+ uint8_t *prev_pict_types; ///< previous picture types in bitstream order, used for mb skip
+#define PREV_PICT_TYPES_BUFFER_SIZE 256
+ int mb_skipped; ///< MUST BE SET only during DECODING
+ uint8_t *mbskip_table; /**< used to avoid copy if macroblock skipped (for black regions for example)
+ and used for b-frame encoding & decoding (contains skip table of next P Frame) */
+ uint8_t *mbintra_table; ///< used to avoid setting {ac, dc, cbp}-pred stuff to zero on inter MB decoding
+ uint8_t *cbp_table; ///< used to store cbp, ac_pred for partitioned decoding
+ uint8_t *pred_dir_table; ///< used to store pred_dir for partitioned decoding
+ uint8_t *allocated_edge_emu_buffer;
+ uint8_t *edge_emu_buffer; ///< points into the middle of allocated_edge_emu_buffer
+ uint8_t *rd_scratchpad; ///< scratchpad for rate distortion mb decision
+ uint8_t *obmc_scratchpad;
+ uint8_t *b_scratchpad; ///< scratchpad used for writing into write only buffers
+
+ int qscale; ///< QP
+ int chroma_qscale; ///< chroma QP
+ unsigned int lambda; ///< lagrange multipler used in rate distortion
+ unsigned int lambda2; ///< (lambda*lambda) >> FF_LAMBDA_SHIFT
+ int *lambda_table;
+ int adaptive_quant; ///< use adaptive quantization
+ int dquant; ///< qscale difference to prev qscale
+ int pict_type; ///< I_TYPE, P_TYPE, B_TYPE, ...
+ int last_pict_type; //FIXME removes
+ int last_non_b_pict_type; ///< used for mpeg4 gmc b-frames & ratecontrol
+ int dropable;
+ int frame_rate_index;
+ int last_lambda_for[5]; ///< last lambda for a specific pict type
+ int skipdct; ///< skip dct and code zero residual
+
+ /* motion compensation */
+ int unrestricted_mv; ///< mv can point outside of the coded picture
+ int h263_long_vectors; ///< use horrible h263v1 long vector mode
+ int decode; ///< if 0 then decoding will be skipped (for encoding b frames for example)
+
+ DSPContext dsp; ///< pointers for accelerated dsp functions
+ int f_code; ///< forward MV resolution
+ int b_code; ///< backward MV resolution for B Frames (mpeg4)
+ int16_t (*p_mv_table_base)[2];
+ int16_t (*b_forw_mv_table_base)[2];
+ int16_t (*b_back_mv_table_base)[2];
+ int16_t (*b_bidir_forw_mv_table_base)[2];
+ int16_t (*b_bidir_back_mv_table_base)[2];
+ int16_t (*b_direct_mv_table_base)[2];
+ int16_t (*p_field_mv_table_base[2][2])[2];
+ int16_t (*b_field_mv_table_base[2][2][2])[2];
+ int16_t (*p_mv_table)[2]; ///< MV table (1MV per MB) p-frame encoding
+ int16_t (*b_forw_mv_table)[2]; ///< MV table (1MV per MB) forward mode b-frame encoding
+ int16_t (*b_back_mv_table)[2]; ///< MV table (1MV per MB) backward mode b-frame encoding
+ int16_t (*b_bidir_forw_mv_table)[2]; ///< MV table (1MV per MB) bidir mode b-frame encoding
+ int16_t (*b_bidir_back_mv_table)[2]; ///< MV table (1MV per MB) bidir mode b-frame encoding
+ int16_t (*b_direct_mv_table)[2]; ///< MV table (1MV per MB) direct mode b-frame encoding
+ int16_t (*p_field_mv_table[2][2])[2]; ///< MV table (2MV per MB) interlaced p-frame encoding
+ int16_t (*b_field_mv_table[2][2][2])[2];///< MV table (4MV per MB) interlaced b-frame encoding
+ uint8_t (*p_field_select_table[2]);
+ uint8_t (*b_field_select_table[2][2]);
+ int me_method; ///< ME algorithm
+ int mv_dir;
+#define MV_DIR_BACKWARD 1
+#define MV_DIR_FORWARD 2
+#define MV_DIRECT 4 ///< bidirectional mode where the difference equals the MV of the last P/S/I-Frame (mpeg4)
+ int mv_type;
+#define MV_TYPE_16X16 0 ///< 1 vector for the whole mb
+#define MV_TYPE_8X8 1 ///< 4 vectors (h263, mpeg4 4MV)
+#define MV_TYPE_16X8 2 ///< 2 vectors, one per 16x8 block
+#define MV_TYPE_FIELD 3 ///< 2 vectors, one per field
+#define MV_TYPE_DMV 4 ///< 2 vectors, special mpeg2 Dual Prime Vectors
+ /**motion vectors for a macroblock
+ first coordinate : 0 = forward 1 = backward
+ second " : depend on type
+ third " : 0 = x, 1 = y
+ */
+ int mv[2][4][2];
+ int field_select[2][2];
+ int last_mv[2][2][2]; ///< last MV, used for MV prediction in MPEG1 & B-frame MPEG4
+ uint8_t *fcode_tab; ///< smallest fcode needed for each MV
+ int16_t direct_scale_mv[2][64]; ///< precomputed to avoid divisions in ff_mpeg4_set_direct_mv
+
+ MotionEstContext me;
+
+ int no_rounding; /**< apply no rounding to motion compensation (MPEG4, msmpeg4, ...)
+ for b-frames rounding mode is allways 0 */
+
+ int hurry_up; /**< when set to 1 during decoding, b frames will be skipped
+ when set to 2 idct/dequant will be skipped too */
+
+ /* macroblock layer */
+ int mb_x, mb_y;
+ int mb_skip_run;
+ int mb_intra;
+ uint16_t *mb_type; ///< Table for candidate MB types for encoding
+#define CANDIDATE_MB_TYPE_INTRA 0x01
+#define CANDIDATE_MB_TYPE_INTER 0x02
+#define CANDIDATE_MB_TYPE_INTER4V 0x04
+#define CANDIDATE_MB_TYPE_SKIPPED 0x08
+//#define MB_TYPE_GMC 0x10
+
+#define CANDIDATE_MB_TYPE_DIRECT 0x10
+#define CANDIDATE_MB_TYPE_FORWARD 0x20
+#define CANDIDATE_MB_TYPE_BACKWARD 0x40
+#define CANDIDATE_MB_TYPE_BIDIR 0x80
+
+#define CANDIDATE_MB_TYPE_INTER_I 0x100
+#define CANDIDATE_MB_TYPE_FORWARD_I 0x200
+#define CANDIDATE_MB_TYPE_BACKWARD_I 0x400
+#define CANDIDATE_MB_TYPE_BIDIR_I 0x800
+
+#define CANDIDATE_MB_TYPE_DIRECT0 0x1000
+
+ int block_index[6]; ///< index to current MB in block based arrays with edges
+ int block_wrap[6];
+ uint8_t *dest[3];
+
+ int *mb_index2xy; ///< mb_index -> mb_x + mb_y*mb_stride
+
+ /** matrix transmitted in the bitstream */
+ uint16_t intra_matrix[64];
+ uint16_t chroma_intra_matrix[64];
+ uint16_t inter_matrix[64];
+ uint16_t chroma_inter_matrix[64];
+#define QUANT_BIAS_SHIFT 8
+ int intra_quant_bias; ///< bias for the quantizer
+ int inter_quant_bias; ///< bias for the quantizer
+ int min_qcoeff; ///< minimum encodable coefficient
+ int max_qcoeff; ///< maximum encodable coefficient
+ int ac_esc_length; ///< num of bits needed to encode the longest esc
+ uint8_t *intra_ac_vlc_length;
+ uint8_t *intra_ac_vlc_last_length;
+ uint8_t *inter_ac_vlc_length;
+ uint8_t *inter_ac_vlc_last_length;
+ uint8_t *luma_dc_vlc_length;
+ uint8_t *chroma_dc_vlc_length;
+#define UNI_AC_ENC_INDEX(run,level) ((run)*128 + (level))
+
+ int coded_score[8];
+
+ /** precomputed matrix (combine qscale and DCT renorm) */
+ int (*q_intra_matrix)[64];
+ int (*q_inter_matrix)[64];
+ /** identical to the above but for MMX & these are not permutated, second 64 entries are bias*/
+ uint16_t (*q_intra_matrix16)[2][64];
+ uint16_t (*q_inter_matrix16)[2][64];
+ int block_last_index[12]; ///< last non zero coefficient in block
+ /* scantables */
+ DECLARE_ALIGNED_8(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
+
+ /* noise reduction */
+ int (*dct_error_sum)[64];
+ int dct_count[2];
+ uint16_t (*dct_offset)[64];
+
+ void *opaque; ///< private data for the user
+
+ /* bit rate control */
+ int64_t wanted_bits;
+ int64_t total_bits;
+ int frame_bits; ///< bits used for the current frame
+ int next_lambda; ///< next lambda used for retrying to encode a frame
+ RateControlContext rc_context; ///< contains stuff only accessed in ratecontrol.c
+
+ /* statistics, used for 2-pass encoding */
+ int mv_bits;
+ int header_bits;
+ int i_tex_bits;
+ int p_tex_bits;
+ int i_count;
+ int f_count;
+ int b_count;
+ int skip_count;
+ int misc_bits; ///< cbp, mb_type
+ int last_bits; ///< temp var used for calculating the above vars
+
+ /* error concealment / resync */
+ int error_count;
+ uint8_t *error_status_table; ///< table of the error status of each MB
+#define VP_START 1 ///< current MB is the first after a resync marker
+#define AC_ERROR 2
+#define DC_ERROR 4
+#define MV_ERROR 8
+#define AC_END 16
+#define DC_END 32
+#define MV_END 64
+//FIXME some prefix?
+
+ int resync_mb_x; ///< x position of last resync marker
+ int resync_mb_y; ///< y position of last resync marker
+ GetBitContext last_resync_gb; ///< used to search for the next resync marker
+ int mb_num_left; ///< number of MBs left in this video packet (for partitioned Slices only)
+ int next_p_frame_damaged; ///< set if the next p frame is damaged, to avoid showing trashed b frames
+ int error_resilience;
+
+ ParseContext parse_context;
+
+ /* H.263 specific */
+ int gob_index;
+ int obmc; ///< overlapped block motion compensation
+
+ /* H.263+ specific */
+ int umvplus; ///< == H263+ && unrestricted_mv
+ int h263_aic; ///< Advanded INTRA Coding (AIC)
+ int h263_aic_dir; ///< AIC direction: 0 = left, 1 = top
+ int h263_slice_structured;
+ int alt_inter_vlc; ///< alternative inter vlc
+ int modified_quant;
+ int loop_filter;
+ int custom_pcf;
+
+ /* mpeg4 specific */
+ int time_increment_bits; ///< number of bits to represent the fractional part of time
+ int last_time_base;
+ int time_base; ///< time in seconds of last I,P,S Frame
+ int64_t time; ///< time of current frame
+ int64_t last_non_b_time;
+ uint16_t pp_time; ///< time distance between the last 2 p,s,i frames
+ uint16_t pb_time; ///< time distance between the last b and p,s,i frame
+ uint16_t pp_field_time;
+ uint16_t pb_field_time; ///< like above, just for interlaced
+ int shape;
+ int vol_sprite_usage;
+ int sprite_width;
+ int sprite_height;
+ int sprite_left;
+ int sprite_top;
+ int sprite_brightness_change;
+ int num_sprite_warping_points;
+ int real_sprite_warping_points;
+ int sprite_offset[2][2]; ///< sprite offset[isChroma][isMVY]
+ int sprite_delta[2][2]; ///< sprite_delta [isY][isMVY]
+ int sprite_shift[2]; ///< sprite shift [isChroma]
+ int mcsel;
+ int quant_precision;
+ int quarter_sample; ///< 1->qpel, 0->half pel ME/MC
+ int scalability;
+ int hierachy_type;
+ int enhancement_type;
+ int new_pred;
+ int reduced_res_vop;
+ int aspect_ratio_info; //FIXME remove
+ int sprite_warping_accuracy;
+ int low_latency_sprite;
+ int data_partitioning; ///< data partitioning flag from header
+ int partitioned_frame; ///< is current frame partitioned
+ int rvlc; ///< reversible vlc
+ int resync_marker; ///< could this stream contain resync markers
+ int low_delay; ///< no reordering needed / has no b-frames
+ int vo_type;
+ int vol_control_parameters; ///< does the stream contain the low_delay flag, used to workaround buggy encoders
+ int intra_dc_threshold; ///< QP above whch the ac VLC should be used for intra dc
+ int use_intra_dc_vlc;
+ PutBitContext tex_pb; ///< used for data partitioned VOPs
+ PutBitContext pb2; ///< used for data partitioned VOPs
+ int mpeg_quant;
+ int t_frame; ///< time distance of first I -> B, used for interlaced b frames
+ int padding_bug_score; ///< used to detect the VERY common padding bug in MPEG4
+
+ /* divx specific, used to workaround (many) bugs in divx5 */
+ int divx_version;
+ int divx_build;
+ int divx_packed;
+ uint8_t *bitstream_buffer; //Divx 5.01 puts several frames in a single one, this is used to reorder them
+ int bitstream_buffer_size;
+ unsigned int allocated_bitstream_buffer_size;
+
+ int xvid_build;
+
+ /* lavc specific stuff, used to workaround bugs in libavcodec */
+ int lavc_build;
+
+ /* RV10 specific */
+ int rv10_version; ///< RV10 version: 0 or 3
+ int rv10_first_dc_coded[3];
+
+ /* MJPEG specific */
+ struct MJpegContext *mjpeg_ctx;
+ int mjpeg_vsample[3]; ///< vertical sampling factors, default = {2, 1, 1}
+ int mjpeg_hsample[3]; ///< horizontal sampling factors, default = {2, 1, 1}
+ int mjpeg_write_tables; ///< do we want to have quantisation- and huffmantables in the jpeg file ?
+ int mjpeg_data_only_frames; ///< frames only with SOI, SOS and EOI markers
+
+ /* MSMPEG4 specific */
+ int mv_table_index;
+ int rl_table_index;
+ int rl_chroma_table_index;
+ int dc_table_index;
+ int use_skip_mb_code;
+ int slice_height; ///< in macroblocks
+ int first_slice_line; ///< used in mpeg4 too to handle resync markers
+ int flipflop_rounding;
+ int msmpeg4_version; ///< 0=not msmpeg4, 1=mp41, 2=mp42, 3=mp43/divx3 4=wmv1/7 5=wmv2/8
+ int per_mb_rl_table;
+ int esc3_level_length;
+ int esc3_run_length;
+ /** [mb_intra][isChroma][level][run][last] */
+ int (*ac_stats)[2][MAX_LEVEL+1][MAX_RUN+1][2];
+ int inter_intra_pred;
+ int mspel;
+
+ /* decompression specific */
+ GetBitContext gb;
+
+ /* Mpeg1 specific */
+ int gop_picture_number; ///< index of the first picture of a GOP based on fake_pic_num & mpeg1 specific
+ int last_mv_dir; ///< last mv_dir, used for b frame encoding
+ int broken_link; ///< no_output_of_prior_pics_flag
+ uint8_t *vbv_delay_ptr; ///< pointer to vbv_delay in the bitstream
+
+ /* MPEG2 specific - I wish I had not to support this mess. */
+ int progressive_sequence;
+ int mpeg_f_code[2][2];
+ int picture_structure;
+/* picture type */
+#define PICT_TOP_FIELD 1
+#define PICT_BOTTOM_FIELD 2
+#define PICT_FRAME 3
+
+ int intra_dc_precision;
+ int frame_pred_frame_dct;
+ int top_field_first;
+ int concealment_motion_vectors;
+ int q_scale_type;
+ int intra_vlc_format;
+ int alternate_scan;
+ int repeat_first_field;
+ int chroma_420_type;
+ int chroma_format;
+#define CHROMA_420 1
+#define CHROMA_422 2
+#define CHROMA_444 3
+ int chroma_x_shift;//depend on pix_format, that depend on chroma_format
+ int chroma_y_shift;
+
+ int progressive_frame;
+ int full_pel[2];
+ int interlaced_dct;
+ int first_slice;
+ int first_field; ///< is 1 for the first field of a field picture 0 otherwise
+
+ /* RTP specific */
+ int rtp_mode;
+
+ uint8_t *ptr_lastgob;
+ int swap_uv;//vcr2 codec is mpeg2 varint with UV swaped
+ short * pblocks[12];
+
+ DCTELEM (*block)[64]; ///< points to one of the following blocks
+ DCTELEM (*blocks)[8][64]; // for HQ mode we need to keep the best block
+ int (*decode_mb)(struct MpegEncContext *s, DCTELEM block[6][64]); // used by some codecs to avoid a switch()
+#define SLICE_OK 0
+#define SLICE_ERROR -1
+#define SLICE_END -2 ///<end marker found
+#define SLICE_NOEND -3 ///<no end marker or error found but mb count exceeded
+
+ void (*dct_unquantize_mpeg1_intra)(struct MpegEncContext *s,
+ DCTELEM *block/*align 16*/, int n, int qscale);
+ void (*dct_unquantize_mpeg1_inter)(struct MpegEncContext *s,
+ DCTELEM *block/*align 16*/, int n, int qscale);
+ void (*dct_unquantize_mpeg2_intra)(struct MpegEncContext *s,
+ DCTELEM *block/*align 16*/, int n, int qscale);
+ void (*dct_unquantize_mpeg2_inter)(struct MpegEncContext *s,
+ DCTELEM *block/*align 16*/, int n, int qscale);
+ void (*dct_unquantize_h263_intra)(struct MpegEncContext *s,
+ DCTELEM *block/*align 16*/, int n, int qscale);
+ void (*dct_unquantize_h263_inter)(struct MpegEncContext *s,
+ DCTELEM *block/*align 16*/, int n, int qscale);
+ void (*dct_unquantize_h261_intra)(struct MpegEncContext *s,
+ DCTELEM *block/*align 16*/, int n, int qscale);
+ void (*dct_unquantize_h261_inter)(struct MpegEncContext *s,
+ DCTELEM *block/*align 16*/, int n, int qscale);
+ void (*dct_unquantize_intra)(struct MpegEncContext *s, // unquantizer to use (mpeg4 can use both)
+ DCTELEM *block/*align 16*/, int n, int qscale);
+ void (*dct_unquantize_inter)(struct MpegEncContext *s, // unquantizer to use (mpeg4 can use both)
+ DCTELEM *block/*align 16*/, int n, int qscale);
+ int (*dct_quantize)(struct MpegEncContext *s, DCTELEM *block/*align 16*/, int n, int qscale, int *overflow);
+ int (*fast_dct_quantize)(struct MpegEncContext *s, DCTELEM *block/*align 16*/, int n, int qscale, int *overflow);
+ void (*denoise_dct)(struct MpegEncContext *s, DCTELEM *block);
+} MpegEncContext;
+
+
+int DCT_common_init(MpegEncContext *s);
+void MPV_decode_defaults(MpegEncContext *s);
+int MPV_common_init(MpegEncContext *s);
+void MPV_common_end(MpegEncContext *s);
+void MPV_decode_mb(MpegEncContext *s, DCTELEM block[12][64]);
+int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx);
+void MPV_frame_end(MpegEncContext *s);
+int MPV_encode_init(AVCodecContext *avctx);
+int MPV_encode_end(AVCodecContext *avctx);
+int MPV_encode_picture(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data);
+#ifdef HAVE_MMX
+void MPV_common_init_mmx(MpegEncContext *s);
+#endif
+#ifdef ARCH_ALPHA
+void MPV_common_init_axp(MpegEncContext *s);
+#endif
+#ifdef HAVE_MLIB
+void MPV_common_init_mlib(MpegEncContext *s);
+#endif
+#ifdef HAVE_MMI
+void MPV_common_init_mmi(MpegEncContext *s);
+#endif
+#ifdef ARCH_ARMV4L
+void MPV_common_init_armv4l(MpegEncContext *s);
+#endif
+#ifdef ARCH_POWERPC
+void MPV_common_init_ppc(MpegEncContext *s);
+#endif
+extern void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w);
+void ff_copy_bits(PutBitContext *pb, uint8_t *src, int length);
+void ff_clean_intra_table_entries(MpegEncContext *s);
+void ff_init_scantable(uint8_t *, ScanTable *st, const uint8_t *src_scantable);
+void ff_draw_horiz_band(MpegEncContext *s, int y, int h);
+void ff_emulated_edge_mc(uint8_t *buf, uint8_t *src, int linesize, int block_w, int block_h,
+ int src_x, int src_y, int w, int h);
+void ff_mpeg_flush(AVCodecContext *avctx);
+void ff_print_debug_info(MpegEncContext *s, AVFrame *pict);
+void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix);
+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_er_frame_start(MpegEncContext *s);
+void ff_er_frame_end(MpegEncContext *s);
+void ff_er_add_slice(MpegEncContext *s, int startx, int starty, int endx, int endy, int status);
+
+
+extern enum PixelFormat ff_yuv420p_list[2];
+
+void ff_init_block_index(MpegEncContext *s);
+
+static inline void ff_update_block_index(MpegEncContext *s){
+ const int block_size= 8>>s->avctx->lowres;
+
+ s->block_index[0]+=2;
+ s->block_index[1]+=2;
+ s->block_index[2]+=2;
+ s->block_index[3]+=2;
+ s->block_index[4]++;
+ s->block_index[5]++;
+ s->dest[0]+= 2*block_size;
+ s->dest[1]+= block_size;
+ s->dest[2]+= block_size;
+}
+
+static inline int get_bits_diff(MpegEncContext *s){
+ const int bits= put_bits_count(&s->pb);
+ const int last= s->last_bits;
+
+ s->last_bits = bits;
+
+ return bits - last;
+}
+
+/* motion_est.c */
+void ff_estimate_p_frame_motion(MpegEncContext * s,
+ int mb_x, int mb_y);
+void ff_estimate_b_frame_motion(MpegEncContext * s,
+ int mb_x, int mb_y);
+int ff_get_best_fcode(MpegEncContext * s, int16_t (*mv_table)[2], int type);
+void ff_fix_long_p_mvs(MpegEncContext * s);
+void ff_fix_long_mvs(MpegEncContext * s, uint8_t *field_select_table, int field_select,
+ int16_t (*mv_table)[2], int f_code, int type, int truncate);
+void ff_init_me(MpegEncContext *s);
+int ff_pre_estimate_p_frame_motion(MpegEncContext * s, int mb_x, int mb_y);
+inline int ff_epzs_motion_search(MpegEncContext * s, int *mx_ptr, int *my_ptr,
+ int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2],
+ int ref_mv_scale, int size, int h);
+inline int ff_get_mb_score(MpegEncContext * s, int mx, int my, int src_index,
+ int ref_index, int size, int h, int add_rate);
+
+/* mpeg12.c */
+extern const uint16_t ff_mpeg1_default_intra_matrix[64];
+extern const uint16_t ff_mpeg1_default_non_intra_matrix[64];
+extern const uint8_t ff_mpeg1_dc_scale_table[128];
+
+void mpeg1_encode_picture_header(MpegEncContext *s, int picture_number);
+void mpeg1_encode_mb(MpegEncContext *s,
+ DCTELEM block[6][64],
+ int motion_x, int motion_y);
+void ff_mpeg1_encode_init(MpegEncContext *s);
+void ff_mpeg1_encode_slice_header(MpegEncContext *s);
+void ff_mpeg1_clean_buffers(MpegEncContext *s);
+
+#include "rl.h"
+
+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];
+
+/* h261.c */
+void ff_h261_loop_filter(MpegEncContext *s);
+void ff_h261_reorder_mb_index(MpegEncContext* s);
+void ff_h261_encode_mb(MpegEncContext *s,
+ DCTELEM block[6][64],
+ int motion_x, int motion_y);
+void ff_h261_encode_picture_header(MpegEncContext * s, int picture_number);
+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,
+ uint8_t *buf, int buf_size);
+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, int picture_number);
+void mpeg4_encode_picture_header(MpegEncContext *s, int picture_number);
+#ifdef CONFIG_ENCODERS
+void h263_encode_init(MpegEncContext *s);
+#else
+static void h263_encode_init(MpegEncContext *s) {assert(0);}
+#endif
+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);
+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);
+int ff_h263_round_chroma(int x);
+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);
+void rv20_encode_picture_header(MpegEncContext *s, int picture_number);
+
+
+/* msmpeg4.c */
+void msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number);
+void msmpeg4_encode_ext_header(MpegEncContext * s);
+void msmpeg4_encode_mb(MpegEncContext * s,
+ DCTELEM block[6][64],
+ 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);
+void ff_msmpeg4_encode_init(MpegEncContext *s);
+int ff_wmv2_decode_picture_header(MpegEncContext * s);
+int ff_wmv2_decode_secondary_picture_header(MpegEncContext * s);
+void ff_wmv2_add_mb(MpegEncContext *s, DCTELEM block[6][64], uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr);
+void ff_mspel_motion(MpegEncContext *s,
+ uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
+ uint8_t **ref_picture, op_pixels_func (*pix_op)[4],
+ int motion_x, int motion_y, int h);
+int ff_wmv2_encode_picture_header(MpegEncContext * s, int picture_number);
+void ff_wmv2_encode_mb(MpegEncContext * s,
+ DCTELEM block[6][64],
+ int motion_x, int motion_y);
+
+/* mjpeg.c */
+int mjpeg_init(MpegEncContext *s);
+void mjpeg_close(MpegEncContext *s);
+void mjpeg_encode_mb(MpegEncContext *s,
+ DCTELEM block[6][64]);
+void mjpeg_picture_header(MpegEncContext *s);
+void mjpeg_picture_trailer(MpegEncContext *s);
+void ff_mjpeg_stuffing(PutBitContext * pbc);
+
+#endif /* AVCODEC_MPEGVIDEO_H */
+
diff --git a/contrib/ffmpeg/libavcodec/msmpeg4.c b/contrib/ffmpeg/libavcodec/msmpeg4.c
new file mode 100644
index 000000000..62076d140
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/msmpeg4.c
@@ -0,0 +1,1940 @@
+/*
+ * MSMPEG4 backend for ffmpeg encoder and decoder
+ * Copyright (c) 2001 Fabrice Bellard.
+ * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * msmpeg4v1 & v2 stuff by Michael Niedermayer <michaelni@gmx.at>
+ */
+
+/**
+ * @file msmpeg4.c
+ * MSMPEG4 backend for ffmpeg encoder and decoder.
+ */
+
+#include "avcodec.h"
+#include "dsputil.h"
+#include "mpegvideo.h"
+
+/*
+ * You can also call this codec : MPEG4 with a twist !
+ *
+ * TODO:
+ * - (encoding) select best mv table (two choices)
+ * - (encoding) select best vlc/dc table
+ */
+//#define DEBUG
+
+#define DC_VLC_BITS 9
+#define CBPY_VLC_BITS 6
+#define INTER_INTRA_VLC_BITS 3
+#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
+#define V2_MV_VLC_BITS 9
+#define TEX_VLC_BITS 9
+#define MB_NON_INTRA_VLC_BITS 9
+#define MB_INTRA_VLC_BITS 9
+
+#define II_BITRATE 128*1024
+#define MBAC_BITRATE 50*1024
+
+#define DEFAULT_INTER_INDEX 3
+
+static uint32_t v2_dc_lum_table[512][2];
+static uint32_t v2_dc_chroma_table[512][2];
+
+static inline void msmpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n);
+static inline int msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block,
+ int n, int coded, const uint8_t *scantable);
+static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr);
+static int msmpeg4_decode_motion(MpegEncContext * s,
+ int *mx_ptr, int *my_ptr);
+static void init_h263_dc_for_msmpeg4(void);
+static inline void msmpeg4_memsetw(short *tab, int val, int n);
+#ifdef 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]);
+static int wmv2_decode_mb(MpegEncContext *s, DCTELEM block[6][64]);
+
+/* vc1 externs */
+extern uint8_t wmv3_dc_scale_table[32];
+
+#ifdef DEBUG
+int intra_count = 0;
+int frame_count = 0;
+#endif
+
+#include "msmpeg4data.h"
+
+#ifdef CONFIG_ENCODERS //strangely gcc includes this even if its not references
+static uint8_t rl_length[NB_RL_TABLES][MAX_LEVEL+1][MAX_RUN+1][2];
+#endif //CONFIG_ENCODERS
+
+static uint8_t static_rl_table_store[NB_RL_TABLES][2][2*MAX_RUN + MAX_LEVEL + 3];
+
+static void common_init(MpegEncContext * s)
+{
+ static int inited=0;
+
+ switch(s->msmpeg4_version){
+ case 1:
+ case 2:
+ s->y_dc_scale_table=
+ s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
+ break;
+ case 3:
+ if(s->workaround_bugs){
+ s->y_dc_scale_table= old_ff_y_dc_scale_table;
+ s->c_dc_scale_table= old_ff_c_dc_scale_table;
+ } else{
+ s->y_dc_scale_table= ff_mpeg4_y_dc_scale_table;
+ s->c_dc_scale_table= ff_mpeg4_c_dc_scale_table;
+ }
+ break;
+ case 4:
+ case 5:
+ s->y_dc_scale_table= wmv1_y_dc_scale_table;
+ s->c_dc_scale_table= wmv1_c_dc_scale_table;
+ break;
+#if defined(CONFIG_WMV3_DECODER)||defined(CONFIG_VC1_DECODER)
+ case 6:
+ s->y_dc_scale_table= wmv3_dc_scale_table;
+ s->c_dc_scale_table= wmv3_dc_scale_table;
+ break;
+#endif
+
+ }
+
+
+ if(s->msmpeg4_version>=4){
+ ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , wmv1_scantable[1]);
+ ff_init_scantable(s->dsp.idct_permutation, &s->intra_h_scantable, wmv1_scantable[2]);
+ ff_init_scantable(s->dsp.idct_permutation, &s->intra_v_scantable, wmv1_scantable[3]);
+ ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , wmv1_scantable[0]);
+ }
+ //Note the default tables are set in common_init in mpegvideo.c
+
+ if(!inited){
+ inited=1;
+
+ init_h263_dc_for_msmpeg4();
+ }
+}
+
+#ifdef CONFIG_ENCODERS
+
+/* build the table which associate a (x,y) motion vector to a vlc */
+static void init_mv_table(MVTable *tab)
+{
+ int i, x, y;
+
+ tab->table_mv_index = av_malloc(sizeof(uint16_t) * 4096);
+ /* mark all entries as not used */
+ for(i=0;i<4096;i++)
+ tab->table_mv_index[i] = tab->n;
+
+ for(i=0;i<tab->n;i++) {
+ x = tab->table_mvx[i];
+ y = tab->table_mvy[i];
+ tab->table_mv_index[(x << 6) | y] = i;
+ }
+}
+
+static void code012(PutBitContext *pb, int n)
+{
+ if (n == 0) {
+ put_bits(pb, 1, 0);
+ } else {
+ put_bits(pb, 1, 1);
+ put_bits(pb, 1, (n >= 2));
+ }
+}
+
+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;i<NB_RL_TABLES;i++)
+ init_rl(&rl_table[i], static_rl_table_store[i]);
+
+ for(i=0; i<NB_RL_TABLES; i++){
+ int level;
+ for(level=0; level<=MAX_LEVEL; level++){
+ int run;
+ for(run=0; run<=MAX_RUN; run++){
+ int last;
+ for(last=0; last<2; last++){
+ rl_length[i][level][run][last]= get_size_of_code(s, &rl_table[ i], last, run, level, 0);
+ }
+ }
+ }
+ }
+ }
+}
+
+static int get_size_of_code(MpegEncContext * s, RLTable *rl, int last, int run, int level, int intra){
+ int size=0;
+ int code;
+ int run_diff= intra ? 0 : 1;
+
+ code = get_rl_index(rl, last, run, level);
+ size+= rl->table_vlc[code][1];
+ 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:
+ size++;
+ if (level > MAX_LEVEL)
+ goto esc3;
+ run1 = run - rl->max_run[last][level] - run_diff;
+ if (run1 < 0)
+ goto esc3;
+ code = get_rl_index(rl, last, run1, level);
+ if (code == rl->n) {
+ esc3:
+ /* third escape */
+ size+=1+1+6+8;
+ } else {
+ /* second escape */
+ size+= 1+1+ rl->table_vlc[code][1];
+ }
+ } else {
+ /* first escape */
+ size+= 1+1+ rl->table_vlc[code][1];
+ }
+ } else {
+ size++;
+ }
+ return size;
+}
+
+static void find_best_tables(MpegEncContext * s)
+{
+ int i;
+ int best =-1, best_size =9999999;
+ int chroma_best=-1, best_chroma_size=9999999;
+
+ for(i=0; i<3; i++){
+ int level;
+ int chroma_size=0;
+ int size=0;
+
+ if(i>0){// ;)
+ size++;
+ chroma_size++;
+ }
+ for(level=0; level<=MAX_LEVEL; level++){
+ int run;
+ for(run=0; run<=MAX_RUN; run++){
+ int last;
+ const int last_size= size + chroma_size;
+ for(last=0; last<2; last++){
+ int inter_count = s->ac_stats[0][0][level][run][last] + s->ac_stats[0][1][level][run][last];
+ int intra_luma_count = s->ac_stats[1][0][level][run][last];
+ int intra_chroma_count= s->ac_stats[1][1][level][run][last];
+
+ if(s->pict_type==I_TYPE){
+ size += intra_luma_count *rl_length[i ][level][run][last];
+ chroma_size+= intra_chroma_count*rl_length[i+3][level][run][last];
+ }else{
+ size+= intra_luma_count *rl_length[i ][level][run][last]
+ +intra_chroma_count*rl_length[i+3][level][run][last]
+ +inter_count *rl_length[i+3][level][run][last];
+ }
+ }
+ if(last_size == size+chroma_size) break;
+ }
+ }
+ if(size<best_size){
+ best_size= size;
+ best= i;
+ }
+ if(chroma_size<best_chroma_size){
+ best_chroma_size= chroma_size;
+ chroma_best= i;
+ }
+ }
+
+// printf("type:%d, best:%d, qp:%d, var:%d, mcvar:%d, size:%d //\n",
+// s->pict_type, best, s->qscale, s->mb_var_sum, s->mc_mb_var_sum, best_size);
+
+ if(s->pict_type==P_TYPE) chroma_best= best;
+
+ memset(s->ac_stats, 0, sizeof(int)*(MAX_LEVEL+1)*(MAX_RUN+1)*2*2*2);
+
+ s->rl_table_index = best;
+ s->rl_chroma_table_index= chroma_best;
+
+ if(s->pict_type != s->last_non_b_pict_type){
+ s->rl_table_index= 2;
+ if(s->pict_type==I_TYPE)
+ s->rl_chroma_table_index= 1;
+ else
+ s->rl_chroma_table_index= 2;
+ }
+
+}
+
+/* write MSMPEG4 compatible frame header */
+void msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number)
+{
+ find_best_tables(s);
+
+ align_put_bits(&s->pb);
+ put_bits(&s->pb, 2, s->pict_type - 1);
+
+ put_bits(&s->pb, 5, s->qscale);
+ if(s->msmpeg4_version<=2){
+ s->rl_table_index = 2;
+ s->rl_chroma_table_index = 2;
+ }
+
+ s->dc_table_index = 1;
+ s->mv_table_index = 1; /* only if P frame */
+ s->use_skip_mb_code = 1; /* only if P frame */
+ s->per_mb_rl_table = 0;
+ if(s->msmpeg4_version==4)
+ s->inter_intra_pred= (s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE && s->pict_type==P_TYPE);
+//printf("%d %d %d %d %d\n", s->pict_type, s->bit_rate, s->inter_intra_pred, s->width, s->height);
+
+ if (s->pict_type == I_TYPE) {
+ s->slice_height= s->mb_height/1;
+ put_bits(&s->pb, 5, 0x16 + s->mb_height/s->slice_height);
+
+ if(s->msmpeg4_version==4){
+ msmpeg4_encode_ext_header(s);
+ if(s->bit_rate>MBAC_BITRATE)
+ put_bits(&s->pb, 1, s->per_mb_rl_table);
+ }
+
+ if(s->msmpeg4_version>2){
+ if(!s->per_mb_rl_table){
+ code012(&s->pb, s->rl_chroma_table_index);
+ code012(&s->pb, s->rl_table_index);
+ }
+
+ put_bits(&s->pb, 1, s->dc_table_index);
+ }
+ } else {
+ put_bits(&s->pb, 1, s->use_skip_mb_code);
+
+ if(s->msmpeg4_version==4 && s->bit_rate>MBAC_BITRATE)
+ put_bits(&s->pb, 1, s->per_mb_rl_table);
+
+ if(s->msmpeg4_version>2){
+ if(!s->per_mb_rl_table)
+ code012(&s->pb, s->rl_table_index);
+
+ put_bits(&s->pb, 1, s->dc_table_index);
+
+ put_bits(&s->pb, 1, s->mv_table_index);
+ }
+ }
+
+ s->esc3_level_length= 0;
+ s->esc3_run_length= 0;
+
+#ifdef DEBUG
+ intra_count = 0;
+ av_log(s->avctx, AV_LOG_DEBUG, "*****frame %d:\n", frame_count++);
+#endif
+}
+
+void msmpeg4_encode_ext_header(MpegEncContext * s)
+{
+ put_bits(&s->pb, 5, s->avctx->time_base.den / s->avctx->time_base.num); //yes 29.97 -> 29
+
+ put_bits(&s->pb, 11, FFMIN(s->bit_rate/1024, 2047));
+
+ if(s->msmpeg4_version>=3)
+ put_bits(&s->pb, 1, s->flipflop_rounding);
+ else
+ assert(s->flipflop_rounding==0);
+}
+
+#endif //CONFIG_ENCODERS
+
+/* predict coded block */
+static inline int coded_block_pred(MpegEncContext * s, int n, uint8_t **coded_block_ptr)
+{
+ int xy, wrap, pred, a, b, c;
+
+ xy = s->block_index[n];
+ wrap = s->b8_stride;
+
+ /* B C
+ * A X
+ */
+ a = s->coded_block[xy - 1 ];
+ b = s->coded_block[xy - 1 - wrap];
+ c = s->coded_block[xy - wrap];
+
+ if (b == c) {
+ pred = a;
+ } else {
+ pred = c;
+ }
+
+ /* store value */
+ *coded_block_ptr = &s->coded_block[xy];
+
+ return pred;
+}
+
+#ifdef CONFIG_ENCODERS
+
+static void msmpeg4_encode_motion(MpegEncContext * s,
+ int mx, int my)
+{
+ int code;
+ MVTable *mv;
+
+ /* modulo encoding */
+ /* WARNING : you cannot reach all the MVs even with the modulo
+ encoding. This is a somewhat strange compromise they took !!! */
+ if (mx <= -64)
+ mx += 64;
+ else if (mx >= 64)
+ mx -= 64;
+ if (my <= -64)
+ my += 64;
+ else if (my >= 64)
+ my -= 64;
+
+ mx += 32;
+ my += 32;
+#if 0
+ if ((unsigned)mx >= 64 ||
+ (unsigned)my >= 64)
+ av_log(s->avctx, AV_LOG_ERROR, "error mx=%d my=%d\n", mx, my);
+#endif
+ mv = &mv_tables[s->mv_table_index];
+
+ code = mv->table_mv_index[(mx << 6) | my];
+ put_bits(&s->pb,
+ mv->table_mv_bits[code],
+ mv->table_mv_code[code]);
+ if (code == mv->n) {
+ /* escape : code litterally */
+ put_bits(&s->pb, 6, mx);
+ put_bits(&s->pb, 6, my);
+ }
+}
+
+static inline void handle_slices(MpegEncContext *s){
+ if (s->mb_x == 0) {
+ if (s->slice_height && (s->mb_y % s->slice_height) == 0) {
+ if(s->msmpeg4_version < 4){
+ ff_mpeg4_clean_buffers(s);
+ }
+ s->first_slice_line = 1;
+ } else {
+ s->first_slice_line = 0;
+ }
+ }
+}
+
+void msmpeg4_encode_mb(MpegEncContext * s,
+ DCTELEM block[6][64],
+ int motion_x, int motion_y)
+{
+ int cbp, coded_cbp, i;
+ int pred_x, pred_y;
+ uint8_t *coded_block;
+
+ handle_slices(s);
+
+ if (!s->mb_intra) {
+ /* compute cbp */
+ cbp = 0;
+ for (i = 0; i < 6; i++) {
+ if (s->block_last_index[i] >= 0)
+ cbp |= 1 << (5 - i);
+ }
+ if (s->use_skip_mb_code && (cbp | motion_x | motion_y) == 0) {
+ /* skip macroblock */
+ put_bits(&s->pb, 1, 1);
+ s->last_bits++;
+ s->misc_bits++;
+ s->skip_count++;
+
+ return;
+ }
+ if (s->use_skip_mb_code)
+ put_bits(&s->pb, 1, 0); /* mb coded */
+
+ if(s->msmpeg4_version<=2){
+ put_bits(&s->pb,
+ v2_mb_type[cbp&3][1],
+ v2_mb_type[cbp&3][0]);
+ if((cbp&3) != 3) coded_cbp= cbp ^ 0x3C;
+ else coded_cbp= cbp;
+
+ put_bits(&s->pb,
+ cbpy_tab[coded_cbp>>2][1],
+ cbpy_tab[coded_cbp>>2][0]);
+
+ s->misc_bits += get_bits_diff(s);
+
+ h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
+ msmpeg4v2_encode_motion(s, motion_x - pred_x);
+ msmpeg4v2_encode_motion(s, motion_y - pred_y);
+ }else{
+ put_bits(&s->pb,
+ table_mb_non_intra[cbp + 64][1],
+ table_mb_non_intra[cbp + 64][0]);
+
+ s->misc_bits += get_bits_diff(s);
+
+ /* motion vector */
+ h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
+ msmpeg4_encode_motion(s, motion_x - pred_x,
+ motion_y - pred_y);
+ }
+
+ s->mv_bits += get_bits_diff(s);
+
+ for (i = 0; i < 6; i++) {
+ msmpeg4_encode_block(s, block[i], i);
+ }
+ s->p_tex_bits += get_bits_diff(s);
+ } else {
+ /* compute cbp */
+ cbp = 0;
+ coded_cbp = 0;
+ for (i = 0; i < 6; i++) {
+ int val, pred;
+ val = (s->block_last_index[i] >= 1);
+ cbp |= val << (5 - i);
+ if (i < 4) {
+ /* predict value for close blocks only for luma */
+ pred = coded_block_pred(s, i, &coded_block);
+ *coded_block = val;
+ val = val ^ pred;
+ }
+ coded_cbp |= val << (5 - i);
+ }
+#if 0
+ if (coded_cbp)
+ printf("cbp=%x %x\n", cbp, coded_cbp);
+#endif
+
+ if(s->msmpeg4_version<=2){
+ if (s->pict_type == I_TYPE) {
+ put_bits(&s->pb,
+ v2_intra_cbpc[cbp&3][1], v2_intra_cbpc[cbp&3][0]);
+ } else {
+ if (s->use_skip_mb_code)
+ put_bits(&s->pb, 1, 0); /* mb coded */
+ put_bits(&s->pb,
+ v2_mb_type[(cbp&3) + 4][1],
+ v2_mb_type[(cbp&3) + 4][0]);
+ }
+ put_bits(&s->pb, 1, 0); /* no AC prediction yet */
+ put_bits(&s->pb,
+ cbpy_tab[cbp>>2][1],
+ cbpy_tab[cbp>>2][0]);
+ }else{
+ if (s->pict_type == I_TYPE) {
+ put_bits(&s->pb,
+ ff_msmp4_mb_i_table[coded_cbp][1], ff_msmp4_mb_i_table[coded_cbp][0]);
+ } else {
+ if (s->use_skip_mb_code)
+ put_bits(&s->pb, 1, 0); /* mb coded */
+ put_bits(&s->pb,
+ table_mb_non_intra[cbp][1],
+ table_mb_non_intra[cbp][0]);
+ }
+ put_bits(&s->pb, 1, 0); /* no AC prediction yet */
+ if(s->inter_intra_pred){
+ s->h263_aic_dir=0;
+ put_bits(&s->pb, table_inter_intra[s->h263_aic_dir][1], table_inter_intra[s->h263_aic_dir][0]);
+ }
+ }
+ s->misc_bits += get_bits_diff(s);
+
+ for (i = 0; i < 6; i++) {
+ msmpeg4_encode_block(s, block[i], i);
+ }
+ s->i_tex_bits += get_bits_diff(s);
+ s->i_count++;
+ }
+}
+
+#endif //CONFIG_ENCODERS
+
+static inline int msmpeg4v1_pred_dc(MpegEncContext * s, int n,
+ int32_t **dc_val_ptr)
+{
+ int i;
+
+ if (n < 4) {
+ i= 0;
+ } else {
+ i= n-3;
+ }
+
+ *dc_val_ptr= &s->last_dc[i];
+ return s->last_dc[i];
+}
+
+static int get_dc(uint8_t *src, int stride, int scale)
+{
+ int y;
+ int sum=0;
+ for(y=0; y<8; y++){
+ int x;
+ for(x=0; x<8; x++){
+ sum+=src[x + y*stride];
+ }
+ }
+ return FASTDIV((sum + (scale>>1)), scale);
+}
+
+/* dir = 0: left, dir = 1: top prediction */
+static inline int msmpeg4_pred_dc(MpegEncContext * s, int n,
+ int16_t **dc_val_ptr, int *dir_ptr)
+{
+ int a, b, c, wrap, pred, scale;
+ int16_t *dc_val;
+
+ /* find prediction */
+ if (n < 4) {
+ scale = s->y_dc_scale;
+ } else {
+ scale = s->c_dc_scale;
+ }
+
+ wrap = s->block_wrap[n];
+ dc_val= s->dc_val[0] + s->block_index[n];
+
+ /* B C
+ * A X
+ */
+ a = dc_val[ - 1];
+ b = dc_val[ - 1 - wrap];
+ c = dc_val[ - wrap];
+
+ if(s->first_slice_line && (n&2)==0 && s->msmpeg4_version<4){
+ b=c=1024;
+ }
+
+ /* XXX: the following solution consumes divisions, but it does not
+ necessitate to modify mpegvideo.c. The problem comes from the
+ fact they decided to store the quantized DC (which would lead
+ to problems if Q could vary !) */
+#if (defined(ARCH_X86)) && !defined PIC
+ asm volatile(
+ "movl %3, %%eax \n\t"
+ "shrl $1, %%eax \n\t"
+ "addl %%eax, %2 \n\t"
+ "addl %%eax, %1 \n\t"
+ "addl %0, %%eax \n\t"
+ "mull %4 \n\t"
+ "movl %%edx, %0 \n\t"
+ "movl %1, %%eax \n\t"
+ "mull %4 \n\t"
+ "movl %%edx, %1 \n\t"
+ "movl %2, %%eax \n\t"
+ "mull %4 \n\t"
+ "movl %%edx, %2 \n\t"
+ : "+b" (a), "+c" (b), "+D" (c)
+ : "g" (scale), "S" (ff_inverse[scale])
+ : "%eax", "%edx"
+ );
+#else
+ /* #elif defined (ARCH_ALPHA) */
+ /* Divisions are extremely costly on Alpha; optimize the most
+ common case. But they are costly everywhere...
+ */
+ if (scale == 8) {
+ a = (a + (8 >> 1)) / 8;
+ b = (b + (8 >> 1)) / 8;
+ c = (c + (8 >> 1)) / 8;
+ } else {
+ a = FASTDIV((a + (scale >> 1)), scale);
+ b = FASTDIV((b + (scale >> 1)), scale);
+ c = FASTDIV((c + (scale >> 1)), scale);
+ }
+#endif
+ /* XXX: WARNING: they did not choose the same test as MPEG4. This
+ is very important ! */
+ if(s->msmpeg4_version>3){
+ if(s->inter_intra_pred){
+ uint8_t *dest;
+ int wrap;
+
+ if(n==1){
+ pred=a;
+ *dir_ptr = 0;
+ }else if(n==2){
+ pred=c;
+ *dir_ptr = 1;
+ }else if(n==3){
+ if (abs(a - b) < abs(b - c)) {
+ pred = c;
+ *dir_ptr = 1;
+ } else {
+ pred = a;
+ *dir_ptr = 0;
+ }
+ }else{
+ if(n<4){
+ wrap= s->linesize;
+ dest= s->current_picture.data[0] + (((n>>1) + 2*s->mb_y) * 8* wrap ) + ((n&1) + 2*s->mb_x) * 8;
+ }else{
+ wrap= s->uvlinesize;
+ dest= s->current_picture.data[n-3] + (s->mb_y * 8 * wrap) + s->mb_x * 8;
+ }
+ if(s->mb_x==0) a= (1024 + (scale>>1))/scale;
+ else a= get_dc(dest-8, wrap, scale*8);
+ if(s->mb_y==0) c= (1024 + (scale>>1))/scale;
+ else c= get_dc(dest-8*wrap, wrap, scale*8);
+
+ if (s->h263_aic_dir==0) {
+ pred= a;
+ *dir_ptr = 0;
+ }else if (s->h263_aic_dir==1) {
+ if(n==0){
+ pred= c;
+ *dir_ptr = 1;
+ }else{
+ pred= a;
+ *dir_ptr = 0;
+ }
+ }else if (s->h263_aic_dir==2) {
+ if(n==0){
+ pred= a;
+ *dir_ptr = 0;
+ }else{
+ pred= c;
+ *dir_ptr = 1;
+ }
+ } else {
+ pred= c;
+ *dir_ptr = 1;
+ }
+ }
+ }else{
+ if (abs(a - b) < abs(b - c)) {
+ pred = c;
+ *dir_ptr = 1;
+ } else {
+ pred = a;
+ *dir_ptr = 0;
+ }
+ }
+ }else{
+ if (abs(a - b) <= abs(b - c)) {
+ pred = c;
+ *dir_ptr = 1;
+ } else {
+ pred = a;
+ *dir_ptr = 0;
+ }
+ }
+
+ /* update predictor */
+ *dc_val_ptr = &dc_val[0];
+ return pred;
+}
+
+#define DC_MAX 119
+
+static void msmpeg4_encode_dc(MpegEncContext * s, int level, int n, int *dir_ptr)
+{
+ int sign, code;
+ int pred;
+
+ if(s->msmpeg4_version==1){
+ int32_t *dc_val;
+ pred = msmpeg4v1_pred_dc(s, n, &dc_val);
+
+ /* update predictor */
+ *dc_val= level;
+ }else{
+ int16_t *dc_val;
+ pred = msmpeg4_pred_dc(s, n, &dc_val, dir_ptr);
+
+ /* update predictor */
+ if (n < 4) {
+ *dc_val = level * s->y_dc_scale;
+ } else {
+ *dc_val = level * s->c_dc_scale;
+ }
+ }
+
+ /* do the prediction */
+ level -= pred;
+
+ if(s->msmpeg4_version<=2){
+ if (n < 4) {
+ put_bits(&s->pb,
+ v2_dc_lum_table[level+256][1],
+ v2_dc_lum_table[level+256][0]);
+ }else{
+ put_bits(&s->pb,
+ v2_dc_chroma_table[level+256][1],
+ v2_dc_chroma_table[level+256][0]);
+ }
+ }else{
+ sign = 0;
+ if (level < 0) {
+ level = -level;
+ sign = 1;
+ }
+ code = level;
+ if (code > DC_MAX)
+ code = DC_MAX;
+
+ if (s->dc_table_index == 0) {
+ if (n < 4) {
+ put_bits(&s->pb, ff_table0_dc_lum[code][1], ff_table0_dc_lum[code][0]);
+ } else {
+ put_bits(&s->pb, ff_table0_dc_chroma[code][1], ff_table0_dc_chroma[code][0]);
+ }
+ } else {
+ if (n < 4) {
+ put_bits(&s->pb, ff_table1_dc_lum[code][1], ff_table1_dc_lum[code][0]);
+ } else {
+ put_bits(&s->pb, ff_table1_dc_chroma[code][1], ff_table1_dc_chroma[code][0]);
+ }
+ }
+
+ if (code == DC_MAX)
+ put_bits(&s->pb, 8, level);
+
+ if (level != 0) {
+ put_bits(&s->pb, 1, sign);
+ }
+ }
+}
+
+/* Encoding of a block. Very similar to MPEG4 except for a different
+ escape coding (same as H263) and more vlc tables.
+ */
+static inline void msmpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n)
+{
+ int level, run, last, i, j, last_index;
+ int last_non_zero, sign, slevel;
+ int code, run_diff, dc_pred_dir;
+ const RLTable *rl;
+ const uint8_t *scantable;
+
+ if (s->mb_intra) {
+ msmpeg4_encode_dc(s, block[0], n, &dc_pred_dir);
+ i = 1;
+ if (n < 4) {
+ rl = &rl_table[s->rl_table_index];
+ } else {
+ rl = &rl_table[3 + s->rl_chroma_table_index];
+ }
+ run_diff = 0;
+ scantable= s->intra_scantable.permutated;
+ } else {
+ i = 0;
+ rl = &rl_table[3 + s->rl_table_index];
+ if(s->msmpeg4_version<=2)
+ run_diff = 0;
+ else
+ run_diff = 1;
+ scantable= s->inter_scantable.permutated;
+ }
+
+ /* recalculate block_last_index for M$ wmv1 */
+ if(s->msmpeg4_version>=4 && s->block_last_index[n]>0){
+ for(last_index=63; last_index>=0; last_index--){
+ if(block[scantable[last_index]]) break;
+ }
+ s->block_last_index[n]= last_index;
+ }else
+ last_index = s->block_last_index[n];
+ /* AC coefs */
+ last_non_zero = i - 1;
+ for (; i <= last_index; i++) {
+ j = scantable[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;
+ }
+
+ if(level<=MAX_LEVEL && run<=MAX_RUN){
+ s->ac_stats[s->mb_intra][n>3][level][run][last]++;
+ }
+#if 0
+else
+ s->ac_stats[s->mb_intra][n>3][40][63][0]++; //esc3 like
+#endif
+ 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) {
+ 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(&s->pb, 1, 0);
+ if (level > MAX_LEVEL)
+ goto esc3;
+ run1 = run - rl->max_run[last][level] - run_diff;
+ if (run1 < 0)
+ goto esc3;
+ code = get_rl_index(rl, last, run1, level);
+ if (code == rl->n) {
+ esc3:
+ /* third escape */
+ put_bits(&s->pb, 1, 0);
+ put_bits(&s->pb, 1, last);
+ if(s->msmpeg4_version>=4){
+ if(s->esc3_level_length==0){
+ s->esc3_level_length=8;
+ s->esc3_run_length= 6;
+ if(s->qscale<8)
+ put_bits(&s->pb, 6, 3);
+ else
+ put_bits(&s->pb, 8, 3);
+ }
+ put_bits(&s->pb, s->esc3_run_length, run);
+ put_bits(&s->pb, 1, sign);
+ put_bits(&s->pb, s->esc3_level_length, level);
+ }else{
+ put_bits(&s->pb, 6, run);
+ put_bits(&s->pb, 8, slevel & 0xff);
+ }
+ } else {
+ /* second escape */
+ put_bits(&s->pb, 1, 1);
+ put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
+ put_bits(&s->pb, 1, sign);
+ }
+ } else {
+ /* first escape */
+ put_bits(&s->pb, 1, 1);
+ put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
+ put_bits(&s->pb, 1, sign);
+ }
+ } else {
+ put_bits(&s->pb, 1, sign);
+ }
+ last_non_zero = i;
+ }
+ }
+}
+
+/****************************************/
+/* decoding stuff */
+
+static VLC mb_non_intra_vlc[4];
+VLC ff_msmp4_mb_i_vlc;
+VLC ff_msmp4_dc_luma_vlc[2];
+VLC ff_msmp4_dc_chroma_vlc[2];
+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;
+static VLC inter_intra_vlc;
+
+/* this table is practically identical to the one from h263 except that its inverted */
+static 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= DCtab_lum[size][0];
+ uni_len = DCtab_lum[size][1];
+ uni_code ^= (1<<uni_len)-1; //M$ doesnt like compatibility
+
+ if (size > 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<<uni_len)-1; //M$ doesnt like compatibility
+
+ if (size > 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;
+
+ }
+}
+
+/* init all vlc decoding tables */
+int ff_msmpeg4_decode_init(MpegEncContext *s)
+{
+ static int done = 0;
+ int i;
+ MVTable *mv;
+
+ common_init(s);
+
+ if (!done) {
+ done = 1;
+
+ for(i=0;i<NB_RL_TABLES;i++) {
+ init_rl(&rl_table[i], static_rl_table_store[i]);
+ init_vlc_rl(&rl_table[i], 1);
+ }
+ for(i=0;i<2;i++) {
+ mv = &mv_tables[i];
+ init_vlc(&mv->vlc, MV_VLC_BITS, mv->n + 1,
+ mv->table_mv_bits, 1, 1,
+ mv->table_mv_code, 2, 2, 1);
+ }
+
+ init_vlc(&ff_msmp4_dc_luma_vlc[0], DC_VLC_BITS, 120,
+ &ff_table0_dc_lum[0][1], 8, 4,
+ &ff_table0_dc_lum[0][0], 8, 4, 1);
+ init_vlc(&ff_msmp4_dc_chroma_vlc[0], DC_VLC_BITS, 120,
+ &ff_table0_dc_chroma[0][1], 8, 4,
+ &ff_table0_dc_chroma[0][0], 8, 4, 1);
+ init_vlc(&ff_msmp4_dc_luma_vlc[1], DC_VLC_BITS, 120,
+ &ff_table1_dc_lum[0][1], 8, 4,
+ &ff_table1_dc_lum[0][0], 8, 4, 1);
+ init_vlc(&ff_msmp4_dc_chroma_vlc[1], DC_VLC_BITS, 120,
+ &ff_table1_dc_chroma[0][1], 8, 4,
+ &ff_table1_dc_chroma[0][0], 8, 4, 1);
+
+ init_vlc(&v2_dc_lum_vlc, DC_VLC_BITS, 512,
+ &v2_dc_lum_table[0][1], 8, 4,
+ &v2_dc_lum_table[0][0], 8, 4, 1);
+ init_vlc(&v2_dc_chroma_vlc, DC_VLC_BITS, 512,
+ &v2_dc_chroma_table[0][1], 8, 4,
+ &v2_dc_chroma_table[0][0], 8, 4, 1);
+
+ init_vlc(&cbpy_vlc, CBPY_VLC_BITS, 16,
+ &cbpy_tab[0][1], 2, 1,
+ &cbpy_tab[0][0], 2, 1, 1);
+ init_vlc(&v2_intra_cbpc_vlc, V2_INTRA_CBPC_VLC_BITS, 4,
+ &v2_intra_cbpc[0][1], 2, 1,
+ &v2_intra_cbpc[0][0], 2, 1, 1);
+ init_vlc(&v2_mb_type_vlc, V2_MB_TYPE_VLC_BITS, 8,
+ &v2_mb_type[0][1], 2, 1,
+ &v2_mb_type[0][0], 2, 1, 1);
+ init_vlc(&v2_mv_vlc, V2_MV_VLC_BITS, 33,
+ &mvtab[0][1], 2, 1,
+ &mvtab[0][0], 2, 1, 1);
+
+ for(i=0; i<4; i++){
+ init_vlc(&mb_non_intra_vlc[i], MB_NON_INTRA_VLC_BITS, 128,
+ &wmv2_inter_table[i][0][1], 8, 4,
+ &wmv2_inter_table[i][0][0], 8, 4, 1); //FIXME name?
+ }
+
+ 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, 1);
+
+ init_vlc(&v1_intra_cbpc_vlc, V1_INTRA_CBPC_VLC_BITS, 8,
+ intra_MCBPC_bits, 1, 1,
+ intra_MCBPC_code, 1, 1, 1);
+ init_vlc(&v1_inter_cbpc_vlc, V1_INTER_CBPC_VLC_BITS, 25,
+ inter_MCBPC_bits, 1, 1,
+ inter_MCBPC_code, 1, 1, 1);
+
+ init_vlc(&inter_intra_vlc, INTER_INTRA_VLC_BITS, 4,
+ &table_inter_intra[0][1], 2, 1,
+ &table_inter_intra[0][0], 2, 1, 1);
+ }
+
+ switch(s->msmpeg4_version){
+ case 1:
+ case 2:
+ s->decode_mb= msmpeg4v12_decode_mb;
+ break;
+ case 3:
+ case 4:
+ s->decode_mb= msmpeg4v34_decode_mb;
+ break;
+ case 5:
+ s->decode_mb= wmv2_decode_mb;
+ case 6:
+ //FIXME + TODO VC1 decode mb
+ break;
+ }
+
+ s->slice_height= s->mb_height; //to avoid 1/0 if the first frame isnt a keyframe
+
+ return 0;
+}
+
+int msmpeg4_decode_picture_header(MpegEncContext * s)
+{
+ int code;
+
+#if 0
+{
+int i;
+for(i=0; i<s->gb.size_in_bits; i++)
+ av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb));
+// get_bits1(&s->gb);
+av_log(s->avctx, AV_LOG_DEBUG, "END\n");
+return -1;
+}
+#endif
+
+ if(s->msmpeg4_version==1){
+ int start_code, num;
+ start_code = (get_bits(&s->gb, 16)<<16) | get_bits(&s->gb, 16);
+ if(start_code!=0x00000100){
+ av_log(s->avctx, AV_LOG_ERROR, "invalid startcode\n");
+ return -1;
+ }
+
+ num= get_bits(&s->gb, 5); // frame number */
+ }
+
+ s->pict_type = get_bits(&s->gb, 2) + 1;
+ if (s->pict_type != I_TYPE &&
+ s->pict_type != P_TYPE){
+ av_log(s->avctx, AV_LOG_ERROR, "invalid picture type\n");
+ return -1;
+ }
+#if 0
+{
+ static int had_i=0;
+ if(s->pict_type == I_TYPE) had_i=1;
+ if(!had_i) return -1;
+}
+#endif
+ s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
+ if(s->qscale==0){
+ av_log(s->avctx, AV_LOG_ERROR, "invalid qscale\n");
+ return -1;
+ }
+
+ if (s->pict_type == I_TYPE) {
+ code = get_bits(&s->gb, 5);
+ if(s->msmpeg4_version==1){
+ if(code==0 || code>s->mb_height){
+ av_log(s->avctx, AV_LOG_ERROR, "invalid slice height %d\n", code);
+ return -1;
+ }
+
+ s->slice_height = code;
+ }else{
+ /* 0x17: one slice, 0x18: two slices, ... */
+ if (code < 0x17){
+ av_log(s->avctx, AV_LOG_ERROR, "error, slice code was %X\n", code);
+ return -1;
+ }
+
+ s->slice_height = s->mb_height / (code - 0x16);
+ }
+
+ switch(s->msmpeg4_version){
+ case 1:
+ case 2:
+ s->rl_chroma_table_index = 2;
+ s->rl_table_index = 2;
+
+ s->dc_table_index = 0; //not used
+ break;
+ case 3:
+ s->rl_chroma_table_index = decode012(&s->gb);
+ s->rl_table_index = decode012(&s->gb);
+
+ s->dc_table_index = get_bits1(&s->gb);
+ break;
+ case 4:
+ msmpeg4_decode_ext_header(s, (2+5+5+17+7)/8);
+
+ if(s->bit_rate > MBAC_BITRATE) s->per_mb_rl_table= get_bits1(&s->gb);
+ else s->per_mb_rl_table= 0;
+
+ if(!s->per_mb_rl_table){
+ s->rl_chroma_table_index = decode012(&s->gb);
+ s->rl_table_index = decode012(&s->gb);
+ }
+
+ s->dc_table_index = get_bits1(&s->gb);
+ s->inter_intra_pred= 0;
+ break;
+ }
+ s->no_rounding = 1;
+ if(s->avctx->debug&FF_DEBUG_PICT_INFO)
+ av_log(s->avctx, AV_LOG_DEBUG, "qscale:%d rlc:%d rl:%d dc:%d mbrl:%d slice:%d \n",
+ s->qscale,
+ s->rl_chroma_table_index,
+ s->rl_table_index,
+ s->dc_table_index,
+ s->per_mb_rl_table,
+ s->slice_height);
+ } else {
+ switch(s->msmpeg4_version){
+ case 1:
+ case 2:
+ if(s->msmpeg4_version==1)
+ s->use_skip_mb_code = 1;
+ else
+ s->use_skip_mb_code = get_bits1(&s->gb);
+ s->rl_table_index = 2;
+ s->rl_chroma_table_index = s->rl_table_index;
+ s->dc_table_index = 0; //not used
+ s->mv_table_index = 0;
+ break;
+ case 3:
+ s->use_skip_mb_code = get_bits1(&s->gb);
+ s->rl_table_index = decode012(&s->gb);
+ s->rl_chroma_table_index = s->rl_table_index;
+
+ s->dc_table_index = get_bits1(&s->gb);
+
+ s->mv_table_index = get_bits1(&s->gb);
+ break;
+ case 4:
+ s->use_skip_mb_code = get_bits1(&s->gb);
+
+ if(s->bit_rate > MBAC_BITRATE) s->per_mb_rl_table= get_bits1(&s->gb);
+ else s->per_mb_rl_table= 0;
+
+ if(!s->per_mb_rl_table){
+ s->rl_table_index = decode012(&s->gb);
+ s->rl_chroma_table_index = s->rl_table_index;
+ }
+
+ s->dc_table_index = get_bits1(&s->gb);
+
+ s->mv_table_index = get_bits1(&s->gb);
+ s->inter_intra_pred= (s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE);
+ break;
+ }
+
+ if(s->avctx->debug&FF_DEBUG_PICT_INFO)
+ av_log(s->avctx, AV_LOG_DEBUG, "skip:%d rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d \n",
+ s->use_skip_mb_code,
+ s->rl_table_index,
+ s->rl_chroma_table_index,
+ s->dc_table_index,
+ s->mv_table_index,
+ s->per_mb_rl_table,
+ s->qscale);
+
+ if(s->flipflop_rounding){
+ s->no_rounding ^= 1;
+ }else{
+ s->no_rounding = 0;
+ }
+ }
+//printf("%d %d %d %d %d\n", s->pict_type, s->bit_rate, s->inter_intra_pred, s->width, s->height);
+
+ s->esc3_level_length= 0;
+ s->esc3_run_length= 0;
+
+#ifdef DEBUG
+ av_log(s->avctx, AV_LOG_DEBUG, "*****frame %d:\n", frame_count++);
+#endif
+ return 0;
+}
+
+int msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size)
+{
+ int left= buf_size*8 - get_bits_count(&s->gb);
+ int length= s->msmpeg4_version>=3 ? 17 : 16;
+ /* the alt_bitstream reader could read over the end so we need to check it */
+ if(left>=length && left<length+8)
+ {
+ int fps;
+
+ fps= get_bits(&s->gb, 5);
+ s->bit_rate= get_bits(&s->gb, 11)*1024;
+ if(s->msmpeg4_version>=3)
+ s->flipflop_rounding= get_bits1(&s->gb);
+ else
+ s->flipflop_rounding= 0;
+
+// printf("fps:%2d bps:%2d roundingType:%1d\n", fps, s->bit_rate/1024, s->flipflop_rounding);
+ }
+ else if(left<length+8)
+ {
+ s->flipflop_rounding= 0;
+ if(s->msmpeg4_version != 2)
+ av_log(s->avctx, AV_LOG_ERROR, "ext header missing, %d left\n", left);
+ }
+ else
+ {
+ av_log(s->avctx, AV_LOG_ERROR, "I frame too long, ignoring ext header\n");
+ }
+
+ return 0;
+}
+
+static inline void msmpeg4_memsetw(short *tab, int val, int n)
+{
+ int i;
+ for(i=0;i<n;i++)
+ tab[i] = val;
+}
+
+#ifdef CONFIG_ENCODERS
+static void msmpeg4v2_encode_motion(MpegEncContext * s, int val)
+{
+ int range, 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 = 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);
+ }
+ }
+}
+#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;
+
+ 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 == 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==P_TYPE) cbp^=0x3C;
+ }
+ }
+
+ s->dsp.clear_blocks(s->block[0]);
+ for (i = 0; i < 6; i++) {
+ if (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 == 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, 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 = 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 (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, 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 (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
+static inline int msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block,
+ int n, int coded, const uint8_t *scan_table)
+{
+ int level, i, last, run, run_diff;
+ int dc_pred_dir;
+ RLTable *rl;
+ RL_VLC_ELEM *rl_vlc;
+ int qmul, qadd;
+
+ if (s->mb_intra) {
+ qmul=1;
+ qadd=0;
+
+ /* DC coef */
+ level = msmpeg4_decode_dc(s, n, &dc_pred_dir);
+
+ if (level < 0){
+ av_log(s->avctx, AV_LOG_ERROR, "dc overflow- block: %d qscale: %d//\n", n, s->qscale);
+ if(s->inter_intra_pred) level=0;
+ else return -1;
+ }
+ if (n < 4) {
+ rl = &rl_table[s->rl_table_index];
+ if(level > 256*s->y_dc_scale){
+ av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ L qscale: %d//\n", s->qscale);
+ if(!s->inter_intra_pred) return -1;
+ }
+ } else {
+ rl = &rl_table[3 + s->rl_chroma_table_index];
+ if(level > 256*s->c_dc_scale){
+ av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ C qscale: %d//\n", s->qscale);
+ if(!s->inter_intra_pred) return -1;
+ }
+ }
+ block[0] = level;
+
+ run_diff = 0;
+ i = 0;
+ if (!coded) {
+ goto not_coded;
+ }
+ if (s->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;
+ }
+ rl_vlc= rl->rl_vlc[0];
+ } else {
+ qmul = s->qscale << 1;
+ qadd = (s->qscale - 1) | 1;
+ i = -1;
+ rl = &rl_table[3 + s->rl_table_index];
+
+ if(s->msmpeg4_version==2)
+ run_diff = 0;
+ else
+ run_diff = 1;
+
+ if (!coded) {
+ s->block_last_index[n] = i;
+ return 0;
+ }
+ if(!scan_table)
+ scan_table = s->inter_scantable.permutated;
+ rl_vlc= rl->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) {
+ int cache;
+ cache= GET_CACHE(re, &s->gb);
+ /* escape */
+ if (s->msmpeg4_version==1 || (cache&0x80000000)==0) {
+ if (s->msmpeg4_version==1 || (cache&0x40000000)==0) {
+ /* third escape */
+ if(s->msmpeg4_version!=1) LAST_SKIP_BITS(re, &s->gb, 2);
+ UPDATE_CACHE(re, &s->gb);
+ if(s->msmpeg4_version<=3){
+ last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1);
+ run= SHOW_UBITS(re, &s->gb, 6); SKIP_CACHE(re, &s->gb, 6);
+ level= SHOW_SBITS(re, &s->gb, 8); LAST_SKIP_CACHE(re, &s->gb, 8);
+ SKIP_COUNTER(re, &s->gb, 1+6+8);
+ }else{
+ int sign;
+ last= SHOW_UBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1);
+ if(!s->esc3_level_length){
+ int ll;
+ //printf("ESC-3 %X at %d %d\n", show_bits(&s->gb, 24), s->mb_x, s->mb_y);
+ 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;
+ }
+ }else{
+ ll=2;
+ while(ll<8 && SHOW_UBITS(re, &s->gb, 1)==0){
+ ll++;
+ SKIP_BITS(re, &s->gb, 1);
+ }
+ if(ll<8) SKIP_BITS(re, &s->gb, 1);
+ }
+
+ s->esc3_level_length= ll;
+ s->esc3_run_length= SHOW_UBITS(re, &s->gb, 2) + 3; SKIP_BITS(re, &s->gb, 2);
+//printf("level length:%d, run length: %d\n", ll, s->esc3_run_length);
+ UPDATE_CACHE(re, &s->gb);
+ }
+ run= SHOW_UBITS(re, &s->gb, s->esc3_run_length);
+ SKIP_BITS(re, &s->gb, s->esc3_run_length);
+
+ sign= SHOW_UBITS(re, &s->gb, 1);
+ SKIP_BITS(re, &s->gb, 1);
+
+ level= SHOW_UBITS(re, &s->gb, s->esc3_level_length);
+ SKIP_BITS(re, &s->gb, s->esc3_level_length);
+ if(sign) level= -level;
+ }
+//printf("level: %d, run: %d at %d %d\n", level, run, s->mb_x, s->mb_y);
+#if 0 // waste of time / this will detect very few errors
+ {
+ const int abs_level= FFABS(level);
+ const int run1= run - rl->max_run[last][abs_level] - run_diff;
+ if(abs_level<=MAX_LEVEL && run<=MAX_RUN){
+ if(abs_level <= rl->max_level[last][run]){
+ av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, vlc encoding possible\n");
+ return DECODING_AC_LOST;
+ }
+ 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 DECODING_AC_LOST;
+ }
+ 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 DECODING_AC_LOST;
+ }
+ }
+ }
+#endif
+ //level = level * qmul + (level>0) * qadd - (level<=0) * qadd ;
+ if (level>0) level= level * qmul + qadd;
+ else level= level * qmul - qadd;
+#if 0 // waste of time too :(
+ if(level>2048 || level<-2048){
+ av_log(s->avctx, AV_LOG_ERROR, "|level| overflow in 3. esc\n");
+ return DECODING_AC_LOST;
+ }
+#endif
+ i+= run + 1;
+ if(last) i+=192;
+#ifdef ERROR_DETAILS
+ if(run==66)
+ av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC3 level=%d\n", level);
+ else if((i>62 && i<192) || i>192+63)
+ av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC3 i=%d run=%d level=%d\n", i, run, level);
+#endif
+ } else {
+ /* second escape */
+#if MIN_CACHE_BITS < 23
+ 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] + run_diff; //FIXME opt indexing
+ level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
+ LAST_SKIP_BITS(re, &s->gb, 1);
+#ifdef ERROR_DETAILS
+ if(run==66)
+ av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC2 level=%d\n", level);
+ else if((i>62 && i<192) || i>192+63)
+ av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC2 i=%d run=%d level=%d\n", i, run, level);
+#endif
+ }
+ } else {
+ /* first escape */
+#if MIN_CACHE_BITS < 22
+ 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);
+#ifdef ERROR_DETAILS
+ if(run==66)
+ av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC1 level=%d\n", level);
+ else if((i>62 && i<192) || i>192+63)
+ av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC1 i=%d run=%d level=%d\n", i, run, level);
+#endif
+ }
+ } else {
+ i+= run;
+ level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
+ LAST_SKIP_BITS(re, &s->gb, 1);
+#ifdef ERROR_DETAILS
+ if(run==66)
+ av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code level=%d\n", level);
+ else if((i>62 && i<192) || i>192+63)
+ av_log(s->avctx, AV_LOG_ERROR, "run overflow i=%d run=%d level=%d\n", i, run, level);
+#endif
+ }
+ if (i > 62){
+ i-= 192;
+ if(i&(~63)){
+ const int left= s->gb.size_in_bits - get_bits_count(&s->gb);
+ if(((i+192 == 64 && level/qmul==-1) || s->error_resilience<=1) && left>=0){
+ av_log(s->avctx, AV_LOG_ERROR, "ignoring overflow at %d %d\n", s->mb_x, s->mb_y);
+ break;
+ }else{
+ 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 (s->mb_intra) {
+ mpeg4_pred_ac(s, block, n, dc_pred_dir);
+ if (s->ac_pred) {
+ i = 63; /* XXX: not optimal */
+ }
+ }
+ if(s->msmpeg4_version>=4 && i>0) i=63; //FIXME/XXX optimize
+ s->block_last_index[n] = i;
+
+ 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;
+}
+
+static int msmpeg4_decode_motion(MpegEncContext * s,
+ int *mx_ptr, int *my_ptr)
+{
+ MVTable *mv;
+ int code, mx, my;
+
+ mv = &mv_tables[s->mv_table_index];
+
+ code = get_vlc2(&s->gb, mv->vlc.table, MV_VLC_BITS, 2);
+ if (code < 0){
+ av_log(s->avctx, AV_LOG_ERROR, "illegal MV code at %d %d\n", s->mb_x, s->mb_y);
+ return -1;
+ }
+ if (code == mv->n) {
+//printf("MV ESC %X at %d %d\n", show_bits(&s->gb, 24), s->mb_x, s->mb_y);
+ mx = get_bits(&s->gb, 6);
+ my = get_bits(&s->gb, 6);
+ } else {
+ mx = mv->table_mvx[code];
+ my = mv->table_mvy[code];
+ }
+
+ mx += *mx_ptr - 32;
+ my += *my_ptr - 32;
+ /* WARNING : they do not do exactly modulo encoding */
+ if (mx <= -64)
+ mx += 64;
+ else if (mx >= 64)
+ mx -= 64;
+
+ if (my <= -64)
+ my += 64;
+ else if (my >= 64)
+ my -= 64;
+ *mx_ptr = mx;
+ *my_ptr = my;
+ return 0;
+}
+
+/* cleanest way to support it
+ * there is too much shared between versions so that we cant have 1 file per version & 1 common
+ * as allmost everything would be in the common file
+ */
+#include "wmv2.c"
diff --git a/src/libffmpeg/libavcodec/msmpeg4data.h b/contrib/ffmpeg/libavcodec/msmpeg4data.h
index d1ff70371..d1ff70371 100644
--- a/src/libffmpeg/libavcodec/msmpeg4data.h
+++ b/contrib/ffmpeg/libavcodec/msmpeg4data.h
diff --git a/src/libffmpeg/libavcodec/msrle.c b/contrib/ffmpeg/libavcodec/msrle.c
index fae5616e5..fae5616e5 100644
--- a/src/libffmpeg/libavcodec/msrle.c
+++ b/contrib/ffmpeg/libavcodec/msrle.c
diff --git a/src/libffmpeg/libavcodec/msvideo1.c b/contrib/ffmpeg/libavcodec/msvideo1.c
index 1e3f6cce2..1e3f6cce2 100644
--- a/src/libffmpeg/libavcodec/msvideo1.c
+++ b/contrib/ffmpeg/libavcodec/msvideo1.c
diff --git a/contrib/ffmpeg/libavcodec/nuv.c b/contrib/ffmpeg/libavcodec/nuv.c
new file mode 100644
index 000000000..5989c6cc2
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/nuv.c
@@ -0,0 +1,216 @@
+/*
+ * NuppelVideo decoder
+ * Copyright (c) 2006 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 <stdio.h>
+#include <stdlib.h>
+
+#include "common.h"
+#include "avcodec.h"
+
+#include "bswap.h"
+#include "dsputil.h"
+#include "lzo.h"
+#include "rtjpeg.h"
+
+typedef struct {
+ AVFrame pic;
+ int width, height;
+ unsigned int decomp_size;
+ unsigned char* decomp_buf;
+ uint32_t lq[64], cq[64];
+ RTJpegContext rtj;
+ DSPContext dsp;
+} NuvContext;
+
+/**
+ * \brief copy frame data from buffer to AVFrame, handling stride.
+ * \param f destination AVFrame
+ * \param src source buffer, does not use any line-stride
+ * \param width width of the video frame
+ * \param height height of the video frame
+ */
+static void copy_frame(AVFrame *f, uint8_t *src,
+ int width, int height) {
+ AVPicture pic;
+ avpicture_fill(&pic, src, PIX_FMT_YUV420P, width, height);
+ av_picture_copy((AVPicture *)f, &pic, PIX_FMT_YUV420P, width, height);
+}
+
+/**
+ * \brief extract quantization tables from codec data into our context
+ */
+static int get_quant(AVCodecContext *avctx, NuvContext *c,
+ uint8_t *buf, int size) {
+ int i;
+ if (size < 2 * 64 * 4) {
+ av_log(avctx, AV_LOG_ERROR, "insufficient rtjpeg quant data\n");
+ return -1;
+ }
+ for (i = 0; i < 64; i++, buf += 4)
+ c->lq[i] = AV_RL32(buf);
+ for (i = 0; i < 64; i++, buf += 4)
+ c->cq[i] = AV_RL32(buf);
+ return 0;
+}
+
+static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
+ uint8_t *buf, int buf_size) {
+ NuvContext *c = (NuvContext *)avctx->priv_data;
+ AVFrame *picture = data;
+ int orig_size = buf_size;
+ enum {NUV_UNCOMPRESSED = '0', NUV_RTJPEG = '1',
+ NUV_RTJPEG_IN_LZO = '2', NUV_LZO = '3',
+ NUV_BLACK = 'N', NUV_COPY_LAST = 'L'} comptype;
+
+ if (buf_size < 12) {
+ av_log(avctx, AV_LOG_ERROR, "coded frame too small\n");
+ return -1;
+ }
+
+ if (c->pic.data[0])
+ avctx->release_buffer(avctx, &c->pic);
+ c->pic.reference = 1;
+ c->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_READABLE |
+ FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
+ if (avctx->get_buffer(avctx, &c->pic) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ return -1;
+ }
+
+ // codec data (rtjpeg quant tables)
+ if (buf[0] == 'D' && buf[1] == 'R') {
+ int ret;
+ // skip rest of the frameheader.
+ buf = &buf[12];
+ buf_size -= 12;
+ ret = get_quant(avctx, c, buf, buf_size);
+ if (ret < 0)
+ return ret;
+ rtjpeg_decode_init(&c->rtj, &c->dsp, c->width, c->height, c->lq, c->cq);
+ return orig_size;
+ }
+
+ if (buf[0] != 'V' || buf_size < 12) {
+ av_log(avctx, AV_LOG_ERROR, "not a nuv video frame\n");
+ return -1;
+ }
+ comptype = buf[1];
+ // skip rest of the frameheader.
+ buf = &buf[12];
+ buf_size -= 12;
+
+ c->pic.pict_type = FF_I_TYPE;
+ c->pic.key_frame = 1;
+ // decompress/copy/whatever data
+ switch (comptype) {
+ case NUV_UNCOMPRESSED: {
+ int height = c->height;
+ if (buf_size < c->width * height * 3 / 2) {
+ av_log(avctx, AV_LOG_ERROR, "uncompressed frame too short\n");
+ height = buf_size / c->width / 3 * 2;
+ }
+ copy_frame(&c->pic, buf, c->width, height);
+ break;
+ }
+ case NUV_RTJPEG: {
+ rtjpeg_decode_frame_yuv420(&c->rtj, &c->pic, buf, buf_size);
+ break;
+ }
+ case NUV_RTJPEG_IN_LZO: {
+ int outlen = c->decomp_size, inlen = buf_size;
+ if (lzo1x_decode(c->decomp_buf, &outlen, buf, &inlen))
+ av_log(avctx, AV_LOG_ERROR, "error during lzo decompression\n");
+ rtjpeg_decode_frame_yuv420(&c->rtj, &c->pic, c->decomp_buf, c->decomp_size);
+ break;
+ }
+ case NUV_LZO: {
+ int outlen = c->decomp_size, inlen = buf_size;
+ if (lzo1x_decode(c->decomp_buf, &outlen, buf, &inlen))
+ av_log(avctx, AV_LOG_ERROR, "error during lzo decompression\n");
+ copy_frame(&c->pic, c->decomp_buf, c->width, c->height);
+ break;
+ }
+ case NUV_BLACK: {
+ memset(c->pic.data[0], 0, c->width * c->height);
+ memset(c->pic.data[1], 128, c->width * c->height / 4);
+ memset(c->pic.data[2], 128, c->width * c->height / 4);
+ break;
+ }
+ case NUV_COPY_LAST: {
+ c->pic.pict_type = FF_P_TYPE;
+ c->pic.key_frame = 0;
+ /* nothing more to do here */
+ break;
+ }
+ default:
+ av_log(avctx, AV_LOG_ERROR, "unknown compression\n");
+ return -1;
+ }
+
+ *picture = c->pic;
+ *data_size = sizeof(AVFrame);
+ return orig_size;
+}
+
+static int decode_init(AVCodecContext *avctx) {
+ NuvContext *c = (NuvContext *)avctx->priv_data;
+ avctx->width = (avctx->width + 1) & ~1;
+ avctx->height = (avctx->height + 1) & ~1;
+ if (avcodec_check_dimensions(avctx, avctx->height, avctx->width) < 0) {
+ return 1;
+ }
+ avctx->has_b_frames = 0;
+ avctx->pix_fmt = PIX_FMT_YUV420P;
+ c->pic.data[0] = NULL;
+ c->width = avctx->width;
+ c->height = avctx->height;
+ c->decomp_size = c->height * c->width * 3 / 2;
+ c->decomp_buf = av_malloc(c->decomp_size + LZO_OUTPUT_PADDING);
+ if (!c->decomp_buf) {
+ av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
+ return 1;
+ }
+ dsputil_init(&c->dsp, avctx);
+ if (avctx->extradata_size)
+ get_quant(avctx, c, avctx->extradata, avctx->extradata_size);
+ rtjpeg_decode_init(&c->rtj, &c->dsp, c->width, c->height, c->lq, c->cq);
+ return 0;
+}
+
+static int decode_end(AVCodecContext *avctx) {
+ NuvContext *c = (NuvContext *)avctx->priv_data;
+ av_freep(&c->decomp_buf);
+ if (c->pic.data[0])
+ avctx->release_buffer(avctx, &c->pic);
+ return 0;
+}
+
+AVCodec nuv_decoder = {
+ "nuv",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_NUV,
+ sizeof(NuvContext),
+ decode_init,
+ NULL,
+ decode_end,
+ decode_frame,
+ CODEC_CAP_DR1,
+};
+
diff --git a/contrib/ffmpeg/libavcodec/oggvorbis.c b/contrib/ffmpeg/libavcodec/oggvorbis.c
new file mode 100644
index 000000000..da97e9a78
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/oggvorbis.c
@@ -0,0 +1,383 @@
+/*
+ * copyright (c) 2002 Mark Hills <mark@pogo.org.uk>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have 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 oggvorbis.c
+ * Ogg Vorbis codec support via libvorbisenc.
+ * @author Mark Hills <mark@pogo.org.uk>
+ */
+
+#include <vorbis/vorbisenc.h>
+
+#include "avcodec.h"
+
+#undef NDEBUG
+#include <assert.h>
+
+#define OGGVORBIS_FRAME_SIZE 64
+
+#define BUFFER_SIZE (1024*64)
+
+typedef struct OggVorbisContext {
+ vorbis_info vi ;
+ vorbis_dsp_state vd ;
+ vorbis_block vb ;
+ uint8_t buffer[BUFFER_SIZE];
+ int buffer_index;
+
+ /* decoder */
+ vorbis_comment vc ;
+ ogg_packet op;
+} OggVorbisContext ;
+
+
+static int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avccontext) {
+ double cfreq;
+
+ if(avccontext->flags & CODEC_FLAG_QSCALE) {
+ /* variable bitrate */
+ if(vorbis_encode_setup_vbr(vi, avccontext->channels,
+ avccontext->sample_rate,
+ avccontext->global_quality / (float)FF_QP2LAMBDA))
+ return -1;
+ } else {
+ /* constant bitrate */
+ if(vorbis_encode_setup_managed(vi, avccontext->channels,
+ avccontext->sample_rate, -1, avccontext->bit_rate, -1))
+ return -1;
+
+#ifdef OGGVORBIS_VBR_BY_ESTIMATE
+ /* variable bitrate by estimate */
+ if(vorbis_encode_ctl(vi, OV_ECTL_RATEMANAGE_AVG, NULL))
+ return -1;
+#endif
+ }
+
+ /* cutoff frequency */
+ if(avccontext->cutoff > 0) {
+ cfreq = avccontext->cutoff / 1000.0;
+ if(vorbis_encode_ctl(vi, OV_ECTL_LOWPASS_SET, &cfreq))
+ return -1;
+ }
+
+ return vorbis_encode_setup_init(vi);
+}
+
+static int oggvorbis_encode_init(AVCodecContext *avccontext) {
+ OggVorbisContext *context = avccontext->priv_data ;
+ ogg_packet header, header_comm, header_code;
+ uint8_t *p;
+ unsigned int offset, len;
+
+ vorbis_info_init(&context->vi) ;
+ if(oggvorbis_init_encoder(&context->vi, avccontext) < 0) {
+ av_log(avccontext, AV_LOG_ERROR, "oggvorbis_encode_init: init_encoder failed") ;
+ return -1 ;
+ }
+ vorbis_analysis_init(&context->vd, &context->vi) ;
+ vorbis_block_init(&context->vd, &context->vb) ;
+
+ vorbis_comment_init(&context->vc);
+ vorbis_comment_add_tag(&context->vc, "encoder", LIBAVCODEC_IDENT) ;
+
+ vorbis_analysis_headerout(&context->vd, &context->vc, &header,
+ &header_comm, &header_code);
+
+ len = header.bytes + header_comm.bytes + header_code.bytes;
+ avccontext->extradata_size= 64 + len + len/255;
+ p = avccontext->extradata= av_mallocz(avccontext->extradata_size);
+ p[0] = 2;
+ offset = 1;
+ offset += av_xiphlacing(&p[offset], header.bytes);
+ offset += av_xiphlacing(&p[offset], header_comm.bytes);
+ memcpy(&p[offset], header.packet, header.bytes);
+ offset += header.bytes;
+ memcpy(&p[offset], header_comm.packet, header_comm.bytes);
+ offset += header_comm.bytes;
+ memcpy(&p[offset], header_code.packet, header_code.bytes);
+ offset += header_code.bytes;
+ avccontext->extradata_size = offset;
+ avccontext->extradata= av_realloc(avccontext->extradata, avccontext->extradata_size);
+
+/* vorbis_block_clear(&context->vb);
+ vorbis_dsp_clear(&context->vd);
+ vorbis_info_clear(&context->vi);*/
+ vorbis_comment_clear(&context->vc);
+
+ avccontext->frame_size = OGGVORBIS_FRAME_SIZE ;
+
+ avccontext->coded_frame= avcodec_alloc_frame();
+ avccontext->coded_frame->key_frame= 1;
+
+ return 0 ;
+}
+
+
+static int oggvorbis_encode_frame(AVCodecContext *avccontext,
+ unsigned char *packets,
+ int buf_size, void *data)
+{
+ OggVorbisContext *context = avccontext->priv_data ;
+ float **buffer ;
+ ogg_packet op ;
+ signed short *audio = data ;
+ int l, samples = data ? OGGVORBIS_FRAME_SIZE : 0;
+
+ buffer = vorbis_analysis_buffer(&context->vd, samples) ;
+
+ if(context->vi.channels == 1) {
+ for(l = 0 ; l < samples ; l++)
+ buffer[0][l]=audio[l]/32768.f;
+ } else {
+ for(l = 0 ; l < samples ; l++){
+ buffer[0][l]=audio[l*2]/32768.f;
+ buffer[1][l]=audio[l*2+1]/32768.f;
+ }
+ }
+
+ vorbis_analysis_wrote(&context->vd, samples) ;
+
+ while(vorbis_analysis_blockout(&context->vd, &context->vb) == 1) {
+ vorbis_analysis(&context->vb, NULL);
+ vorbis_bitrate_addblock(&context->vb) ;
+
+ while(vorbis_bitrate_flushpacket(&context->vd, &op)) {
+ /* i'd love to say the following line is a hack, but sadly it's
+ * not, apparently the end of stream decision is in libogg. */
+ if(op.bytes==1)
+ continue;
+ memcpy(context->buffer + context->buffer_index, &op, sizeof(ogg_packet));
+ context->buffer_index += sizeof(ogg_packet);
+ memcpy(context->buffer + context->buffer_index, op.packet, op.bytes);
+ context->buffer_index += op.bytes;
+// av_log(avccontext, AV_LOG_DEBUG, "e%d / %d\n", context->buffer_index, op.bytes);
+ }
+ }
+
+ l=0;
+ if(context->buffer_index){
+ ogg_packet *op2= (ogg_packet*)context->buffer;
+ op2->packet = context->buffer + sizeof(ogg_packet);
+
+ l= op2->bytes;
+ avccontext->coded_frame->pts= av_rescale_q(op2->granulepos, (AVRational){1, avccontext->sample_rate}, avccontext->time_base);
+ //FIXME we should reorder the user supplied pts and not assume that they are spaced by 1/sample_rate
+
+ memcpy(packets, op2->packet, l);
+ context->buffer_index -= l + sizeof(ogg_packet);
+ memcpy(context->buffer, context->buffer + l + sizeof(ogg_packet), context->buffer_index);
+// av_log(avccontext, AV_LOG_DEBUG, "E%d\n", l);
+ }
+
+ return l;
+}
+
+
+static int oggvorbis_encode_close(AVCodecContext *avccontext) {
+ OggVorbisContext *context = avccontext->priv_data ;
+/* ogg_packet op ; */
+
+ vorbis_analysis_wrote(&context->vd, 0) ; /* notify vorbisenc this is EOF */
+
+ vorbis_block_clear(&context->vb);
+ vorbis_dsp_clear(&context->vd);
+ vorbis_info_clear(&context->vi);
+
+ av_freep(&avccontext->coded_frame);
+ av_freep(&avccontext->extradata);
+
+ return 0 ;
+}
+
+
+AVCodec oggvorbis_encoder = {
+ "vorbis",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_VORBIS,
+ sizeof(OggVorbisContext),
+ oggvorbis_encode_init,
+ oggvorbis_encode_frame,
+ oggvorbis_encode_close,
+ .capabilities= CODEC_CAP_DELAY,
+} ;
+
+static int oggvorbis_decode_init(AVCodecContext *avccontext) {
+ OggVorbisContext *context = avccontext->priv_data ;
+ uint8_t *p= avccontext->extradata;
+ int i, hsizes[3];
+ unsigned char *headers[3], *extradata = avccontext->extradata;
+
+ vorbis_info_init(&context->vi) ;
+ vorbis_comment_init(&context->vc) ;
+
+ if(! avccontext->extradata_size || ! p) {
+ av_log(avccontext, AV_LOG_ERROR, "vorbis extradata absent\n");
+ return -1;
+ }
+
+ if(p[0] == 0 && p[1] == 30) {
+ for(i = 0; i < 3; i++){
+ hsizes[i] = *p++ << 8;
+ hsizes[i] += *p++;
+ headers[i] = p;
+ p += hsizes[i];
+ }
+ } else if(*p == 2) {
+ unsigned int offset = 1;
+ p++;
+ for(i=0; i<2; i++) {
+ hsizes[i] = 0;
+ while((*p == 0xFF) && (offset < avccontext->extradata_size)) {
+ hsizes[i] += 0xFF;
+ offset++;
+ p++;
+ }
+ if(offset >= avccontext->extradata_size - 1) {
+ av_log(avccontext, AV_LOG_ERROR,
+ "vorbis header sizes damaged\n");
+ return -1;
+ }
+ hsizes[i] += *p;
+ offset++;
+ p++;
+ }
+ hsizes[2] = avccontext->extradata_size - hsizes[0]-hsizes[1]-offset;
+#if 0
+ av_log(avccontext, AV_LOG_DEBUG,
+ "vorbis header sizes: %d, %d, %d, / extradata_len is %d \n",
+ hsizes[0], hsizes[1], hsizes[2], avccontext->extradata_size);
+#endif
+ headers[0] = extradata + offset;
+ headers[1] = extradata + offset + hsizes[0];
+ headers[2] = extradata + offset + hsizes[0] + hsizes[1];
+ } else {
+ av_log(avccontext, AV_LOG_ERROR,
+ "vorbis initial header len is wrong: %d\n", *p);
+ return -1;
+ }
+
+ for(i=0; i<3; i++){
+ context->op.b_o_s= i==0;
+ context->op.bytes = hsizes[i];
+ context->op.packet = headers[i];
+ if(vorbis_synthesis_headerin(&context->vi, &context->vc, &context->op)<0){
+ av_log(avccontext, AV_LOG_ERROR, "%d. vorbis header damaged\n", i+1);
+ return -1;
+ }
+ }
+
+ avccontext->channels = context->vi.channels;
+ avccontext->sample_rate = context->vi.rate;
+ avccontext->time_base= (AVRational){1, avccontext->sample_rate};
+
+ vorbis_synthesis_init(&context->vd, &context->vi);
+ vorbis_block_init(&context->vd, &context->vb);
+
+ return 0 ;
+}
+
+
+static inline int conv(int samples, float **pcm, char *buf, int channels) {
+ int i, j, val ;
+ ogg_int16_t *ptr, *data = (ogg_int16_t*)buf ;
+ float *mono ;
+
+ for(i = 0 ; i < channels ; i++){
+ ptr = &data[i];
+ mono = pcm[i] ;
+
+ for(j = 0 ; j < samples ; j++) {
+
+ val = mono[j] * 32767.f;
+
+ if(val > 32767) val = 32767 ;
+ if(val < -32768) val = -32768 ;
+
+ *ptr = val ;
+ ptr += channels;
+ }
+ }
+
+ return 0 ;
+}
+
+
+static int oggvorbis_decode_frame(AVCodecContext *avccontext,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ OggVorbisContext *context = avccontext->priv_data ;
+ float **pcm ;
+ ogg_packet *op= &context->op;
+ int samples, total_samples, total_bytes;
+
+ if(!buf_size){
+ //FIXME flush
+ return 0;
+ }
+
+ op->packet = buf;
+ op->bytes = buf_size;
+
+// av_log(avccontext, AV_LOG_DEBUG, "%d %d %d %"PRId64" %"PRId64" %d %d\n", op->bytes, op->b_o_s, op->e_o_s, op->granulepos, op->packetno, buf_size, context->vi.rate);
+
+/* for(i=0; i<op->bytes; i++)
+ av_log(avccontext, AV_LOG_DEBUG, "%02X ", op->packet[i]);
+ av_log(avccontext, AV_LOG_DEBUG, "\n");*/
+
+ if(vorbis_synthesis(&context->vb, op) == 0)
+ vorbis_synthesis_blockin(&context->vd, &context->vb) ;
+
+ total_samples = 0 ;
+ total_bytes = 0 ;
+
+ while((samples = vorbis_synthesis_pcmout(&context->vd, &pcm)) > 0) {
+ conv(samples, pcm, (char*)data + total_bytes, context->vi.channels) ;
+ total_bytes += samples * 2 * context->vi.channels ;
+ total_samples += samples ;
+ vorbis_synthesis_read(&context->vd, samples) ;
+ }
+
+ *data_size = total_bytes ;
+ return buf_size ;
+}
+
+
+static int oggvorbis_decode_close(AVCodecContext *avccontext) {
+ OggVorbisContext *context = avccontext->priv_data ;
+
+ vorbis_info_clear(&context->vi) ;
+ vorbis_comment_clear(&context->vc) ;
+
+ return 0 ;
+}
+
+
+AVCodec oggvorbis_decoder = {
+ "vorbis",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_VORBIS,
+ sizeof(OggVorbisContext),
+ oggvorbis_decode_init,
+ NULL,
+ oggvorbis_decode_close,
+ oggvorbis_decode_frame,
+ .capabilities= CODEC_CAP_DELAY,
+} ;
diff --git a/contrib/ffmpeg/libavcodec/opt.c b/contrib/ffmpeg/libavcodec/opt.c
new file mode 100644
index 000000000..97b593cb2
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/opt.c
@@ -0,0 +1,389 @@
+/*
+ * AVOptions
+ * Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * @file opt.c
+ * AVOptions
+ * @author Michael Niedermayer <michaelni@gmx.at>
+ */
+
+#include "avcodec.h"
+#include "opt.h"
+#include "eval.h"
+
+//FIXME order them and do a bin search
+const AVOption *av_find_opt(void *v, const char *name, const char *unit, int mask, int flags){
+ AVClass *c= *(AVClass**)v; //FIXME silly way of storing AVClass
+ const AVOption *o= c->option;
+
+ for(;o && o->name; o++){
+ if(!strcmp(o->name, name) && (!unit || (o->unit && !strcmp(o->unit, unit))) && (o->flags & mask) == flags )
+ return o;
+ }
+ return NULL;
+}
+
+const AVOption *av_next_option(void *obj, const AVOption *last){
+ if(last && last[1].name) return ++last;
+ else if(last) return NULL;
+ else return (*(AVClass**)obj)->option;
+}
+
+static const AVOption *av_set_number(void *obj, const char *name, double num, int den, int64_t intnum){
+ const AVOption *o= av_find_opt(obj, name, NULL, 0, 0);
+ void *dst;
+ if(!o || o->offset<=0)
+ return NULL;
+
+ if(o->max*den < num*intnum || o->min*den > num*intnum) {
+ av_log(NULL, AV_LOG_ERROR, "Value %lf for parameter '%s' out of range.\n", num, name);
+ return NULL;
+ }
+
+ dst= ((uint8_t*)obj) + o->offset;
+
+ switch(o->type){
+ case FF_OPT_TYPE_FLAGS:
+ case FF_OPT_TYPE_INT: *(int *)dst= lrintf(num/den)*intnum; break;
+ case FF_OPT_TYPE_INT64: *(int64_t *)dst= lrintf(num/den)*intnum; break;
+ case FF_OPT_TYPE_FLOAT: *(float *)dst= num*intnum/den; break;
+ case FF_OPT_TYPE_DOUBLE:*(double *)dst= num*intnum/den; break;
+ case FF_OPT_TYPE_RATIONAL:
+ if((int)num == num) *(AVRational*)dst= (AVRational){num*intnum, den};
+ else *(AVRational*)dst= av_d2q(num*intnum/den, 1<<24);
+ default:
+ return NULL;
+ }
+ return o;
+}
+
+static const AVOption *set_all_opt(void *v, const char *unit, double d){
+ AVClass *c= *(AVClass**)v; //FIXME silly way of storing AVClass
+ const AVOption *o= c->option;
+ const AVOption *ret=NULL;
+
+ for(;o && o->name; o++){
+ if(o->type != FF_OPT_TYPE_CONST && o->unit && !strcmp(o->unit, unit)){
+ double tmp= d;
+ if(o->type == FF_OPT_TYPE_FLAGS)
+ tmp= av_get_int(v, o->name, NULL) | (int64_t)d;
+
+ av_set_number(v, o->name, tmp, 1, 1);
+ ret= o;
+ }
+ }
+ return ret;
+}
+
+static double const_values[]={
+ M_PI,
+ M_E,
+ FF_QP2LAMBDA,
+ 0
+};
+
+static const char *const_names[]={
+ "PI",
+ "E",
+ "QP2LAMBDA",
+ 0
+};
+
+const AVOption *av_set_string(void *obj, const char *name, const char *val){
+ const AVOption *o= av_find_opt(obj, name, NULL, 0, 0);
+ if(o && o->offset==0 && o->type == FF_OPT_TYPE_CONST && o->unit){
+ return set_all_opt(obj, o->unit, o->default_val);
+ }
+ if(!o || !val || o->offset<=0)
+ return NULL;
+ if(o->type != FF_OPT_TYPE_STRING){
+ for(;;){
+ int i;
+ char buf[256];
+ int cmd=0;
+ double d;
+ char *error = NULL;
+
+ if(*val == '+' || *val == '-')
+ cmd= *(val++);
+
+ for(i=0; i<sizeof(buf)-1 && val[i] && val[i]!='+' && val[i]!='-'; i++)
+ buf[i]= val[i];
+ buf[i]=0;
+ val+= i;
+
+ d = ff_eval2(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)
+ d= o_named->default_val;
+ else if(!strcmp(buf, "default")) d= o->default_val;
+ else if(!strcmp(buf, "max" )) d= o->max;
+ else if(!strcmp(buf, "min" )) d= o->min;
+ else if(!strcmp(buf, "none" )) d= 0;
+ else if(!strcmp(buf, "all" )) d= ~0;
+ else {
+ if (!error)
+ av_log(NULL, AV_LOG_ERROR, "Unable to parse option value \"%s\": %s\n", val, error);
+ return NULL;
+ }
+ }
+ if(o->type == FF_OPT_TYPE_FLAGS){
+ if (cmd=='+') d= av_get_int(obj, name, NULL) | (int64_t)d;
+ else if(cmd=='-') d= av_get_int(obj, name, NULL) &~(int64_t)d;
+ }else if(cmd=='-')
+ d= -d;
+
+ av_set_number(obj, name, d, 1, 1);
+ if(!*val)
+ return o;
+ }
+ return NULL;
+ }
+
+ memcpy(((uint8_t*)obj) + o->offset, val, sizeof(val));
+ return o;
+}
+
+const AVOption *av_set_double(void *obj, const char *name, double n){
+ return av_set_number(obj, name, n, 1, 1);
+}
+
+const AVOption *av_set_q(void *obj, const char *name, AVRational n){
+ return av_set_number(obj, name, n.num, n.den, 1);
+}
+
+const AVOption *av_set_int(void *obj, const char *name, int64_t n){
+ return av_set_number(obj, name, 1, 1, n);
+}
+
+/**
+ *
+ * @param buf a buffer which is used for returning non string values as strings, can be NULL
+ * @param buf_len allocated length in bytes of buf
+ */
+const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len){
+ const AVOption *o= av_find_opt(obj, name, NULL, 0, 0);
+ void *dst;
+ if(!o || o->offset<=0)
+ return NULL;
+ if(o->type != FF_OPT_TYPE_STRING && (!buf || !buf_len))
+ return NULL;
+
+ dst= ((uint8_t*)obj) + o->offset;
+ if(o_out) *o_out= o;
+
+ if(o->type == FF_OPT_TYPE_STRING)
+ return dst;
+
+ switch(o->type){
+ case FF_OPT_TYPE_FLAGS: snprintf(buf, buf_len, "0x%08X",*(int *)dst);break;
+ case FF_OPT_TYPE_INT: snprintf(buf, buf_len, "%d" , *(int *)dst);break;
+ case FF_OPT_TYPE_INT64: snprintf(buf, buf_len, "%"PRId64, *(int64_t*)dst);break;
+ case FF_OPT_TYPE_FLOAT: snprintf(buf, buf_len, "%f" , *(float *)dst);break;
+ case FF_OPT_TYPE_DOUBLE: snprintf(buf, buf_len, "%f" , *(double *)dst);break;
+ case FF_OPT_TYPE_RATIONAL: snprintf(buf, buf_len, "%d/%d", ((AVRational*)dst)->num, ((AVRational*)dst)->den);break;
+ default: return NULL;
+ }
+ return buf;
+}
+
+static int av_get_number(void *obj, const char *name, const AVOption **o_out, double *num, int *den, int64_t *intnum){
+ const AVOption *o= av_find_opt(obj, name, NULL, 0, 0);
+ void *dst;
+ if(!o || o->offset<=0)
+ goto error;
+
+ dst= ((uint8_t*)obj) + o->offset;
+
+ if(o_out) *o_out= o;
+
+ switch(o->type){
+ case FF_OPT_TYPE_FLAGS:
+ case FF_OPT_TYPE_INT: *intnum= *(int *)dst;return 0;
+ case FF_OPT_TYPE_INT64: *intnum= *(int64_t*)dst;return 0;
+ case FF_OPT_TYPE_FLOAT: *num= *(float *)dst;return 0;
+ case FF_OPT_TYPE_DOUBLE: *num= *(double *)dst;return 0;
+ case FF_OPT_TYPE_RATIONAL: *intnum= ((AVRational*)dst)->num;
+ *den = ((AVRational*)dst)->den;
+ return 0;
+ }
+error:
+ *den=*intnum=0;
+ return -1;
+}
+
+double av_get_double(void *obj, const char *name, const AVOption **o_out){
+ int64_t intnum=1;
+ double num=1;
+ int den=1;
+
+ av_get_number(obj, name, o_out, &num, &den, &intnum);
+ return num*intnum/den;
+}
+
+AVRational av_get_q(void *obj, const char *name, const AVOption **o_out){
+ int64_t intnum=1;
+ double num=1;
+ int den=1;
+
+ av_get_number(obj, name, o_out, &num, &den, &intnum);
+ if(num == 1.0 && (int)intnum == intnum)
+ return (AVRational){intnum, den};
+ else
+ return av_d2q(num*intnum/den, 1<<24);
+}
+
+int64_t av_get_int(void *obj, const char *name, const AVOption **o_out){
+ int64_t intnum=1;
+ double num=1;
+ int den=1;
+
+ av_get_number(obj, name, o_out, &num, &den, &intnum);
+ return num*intnum/den;
+}
+
+static void opt_list(void *obj, void *av_log_obj, const char *unit)
+{
+ const AVOption *opt=NULL;
+
+ while((opt= av_next_option(obj, opt))){
+ if(!(opt->flags & (AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM)))
+ continue;
+
+ /* Don't print CONST's on level one.
+ * Don't print anything but CONST's on level two.
+ * Only print items from the requested unit.
+ */
+ if (!unit && opt->type==FF_OPT_TYPE_CONST)
+ continue;
+ else if (unit && opt->type!=FF_OPT_TYPE_CONST)
+ continue;
+ else if (unit && opt->type==FF_OPT_TYPE_CONST && strcmp(unit, opt->unit))
+ continue;
+ else if (unit && opt->type == FF_OPT_TYPE_CONST)
+ av_log(av_log_obj, AV_LOG_INFO, " %-15s ", opt->name);
+ else
+ av_log(av_log_obj, AV_LOG_INFO, "-%-17s ", opt->name);
+
+ switch( opt->type )
+ {
+ case FF_OPT_TYPE_FLAGS:
+ av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "<flags>" );
+ break;
+ case FF_OPT_TYPE_INT:
+ av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "<int>" );
+ break;
+ case FF_OPT_TYPE_INT64:
+ av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "<int64>" );
+ break;
+ case FF_OPT_TYPE_DOUBLE:
+ av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "<double>" );
+ break;
+ case FF_OPT_TYPE_FLOAT:
+ av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "<float>" );
+ break;
+ case FF_OPT_TYPE_STRING:
+ av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "<string>" );
+ break;
+ case FF_OPT_TYPE_RATIONAL:
+ av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "<rational>" );
+ break;
+ case FF_OPT_TYPE_CONST:
+ default:
+ av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "" );
+ break;
+ }
+ av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_ENCODING_PARAM) ? 'E' : '.');
+ av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_DECODING_PARAM) ? 'D' : '.');
+ av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_VIDEO_PARAM ) ? 'V' : '.');
+ av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_AUDIO_PARAM ) ? 'A' : '.');
+ av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_SUBTITLE_PARAM) ? 'S' : '.');
+
+ if(opt->help)
+ av_log(av_log_obj, AV_LOG_INFO, " %s", opt->help);
+ av_log(av_log_obj, AV_LOG_INFO, "\n");
+ if (opt->unit && opt->type != FF_OPT_TYPE_CONST) {
+ opt_list(obj, av_log_obj, opt->unit);
+ }
+ }
+}
+
+int av_opt_show(void *obj, void *av_log_obj){
+ if(!obj)
+ return -1;
+
+ av_log(av_log_obj, AV_LOG_INFO, "%s AVOptions:\n", (*(AVClass**)obj)->class_name);
+
+ opt_list(obj, av_log_obj, NULL);
+
+ return 0;
+}
+
+/** Set the values of the AVCodecContext or AVFormatContext structure.
+ * They are set to the defaults specified in the according AVOption options
+ * array default_val field.
+ *
+ * @param s AVCodecContext or AVFormatContext for which the defaults will be set
+ */
+void av_opt_set_defaults2(void *s, int mask, int flags)
+{
+ const AVOption *opt = NULL;
+ while ((opt = av_next_option(s, opt)) != NULL) {
+ if((opt->flags & mask) != flags)
+ continue;
+ switch(opt->type) {
+ case FF_OPT_TYPE_CONST:
+ /* Nothing to be done here */
+ break;
+ case FF_OPT_TYPE_FLAGS:
+ case FF_OPT_TYPE_INT: {
+ int val;
+ val = opt->default_val;
+ av_set_int(s, opt->name, val);
+ }
+ break;
+ case FF_OPT_TYPE_FLOAT: {
+ double val;
+ val = opt->default_val;
+ av_set_double(s, opt->name, val);
+ }
+ break;
+ case FF_OPT_TYPE_RATIONAL: {
+ AVRational val;
+ val = av_d2q(opt->default_val, INT_MAX);
+ av_set_q(s, opt->name, val);
+ }
+ break;
+ case FF_OPT_TYPE_STRING:
+ /* Cannot set default for string as default_val is of type * double */
+ break;
+ default:
+ av_log(s, AV_LOG_DEBUG, "AVOption type %d of option %s not implemented yet\n", opt->type, opt->name);
+ }
+ }
+}
+
+void av_opt_set_defaults(void *s){
+ av_opt_set_defaults2(s, 0, 0);
+}
+
diff --git a/contrib/ffmpeg/libavcodec/opt.h b/contrib/ffmpeg/libavcodec/opt.h
new file mode 100644
index 000000000..151dbb788
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/opt.h
@@ -0,0 +1,85 @@
+/*
+ * AVOptions
+ * copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVOPT_H
+#define AVOPT_H
+
+/**
+ * @file opt.h
+ * AVOptions
+ */
+
+enum AVOptionType{
+ FF_OPT_TYPE_FLAGS,
+ FF_OPT_TYPE_INT,
+ FF_OPT_TYPE_INT64,
+ FF_OPT_TYPE_DOUBLE,
+ FF_OPT_TYPE_FLOAT,
+ FF_OPT_TYPE_STRING,
+ FF_OPT_TYPE_RATIONAL,
+ FF_OPT_TYPE_CONST=128,
+};
+
+/**
+ * AVOption.
+ */
+typedef struct AVOption {
+ const char *name;
+
+ /**
+ * short English text help.
+ * @fixme what about other languages
+ */
+ const char *help;
+ int offset; ///< offset to context structure where the parsed value should be stored
+ enum AVOptionType type;
+
+ double default_val;
+ double min;
+ double max;
+
+ 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
+ const char *unit;
+} AVOption;
+
+
+const AVOption *av_find_opt(void *obj, const char *name, const char *unit, int mask, int flags);
+const AVOption *av_set_string(void *obj, const char *name, const char *val);
+const AVOption *av_set_double(void *obj, const char *name, double n);
+const AVOption *av_set_q(void *obj, const char *name, AVRational n);
+const AVOption *av_set_int(void *obj, const char *name, int64_t n);
+double av_get_double(void *obj, const char *name, const AVOption **o_out);
+AVRational av_get_q(void *obj, const char *name, const AVOption **o_out);
+int64_t av_get_int(void *obj, const char *name, const AVOption **o_out);
+const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len);
+const AVOption *av_next_option(void *obj, const AVOption *last);
+int av_opt_show(void *obj, void *av_log_obj);
+void av_opt_set_defaults(void *s);
+void av_opt_set_defaults2(void *s, int mask, int flags);
+
+#endif
diff --git a/contrib/ffmpeg/libavcodec/os2thread.c b/contrib/ffmpeg/libavcodec/os2thread.c
new file mode 100644
index 000000000..c52b7ae02
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/os2thread.c
@@ -0,0 +1,147 @@
+/*
+ * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+//#define DEBUG
+
+// Ported by Vlad Stelmahovsky
+
+#include "avcodec.h"
+#include "common.h"
+
+#define INCL_DOS
+#define INCL_DOSERRORS
+#define INCL_DOSDEVIOCTL
+#include <os2.h>
+
+typedef struct ThreadContext{
+ AVCodecContext *avctx;
+ int thread;
+ HEV work_sem;
+ HEV done_sem;
+ int (*func)(AVCodecContext *c, void *arg);
+ void *arg;
+ int ret;
+}ThreadContext;
+
+
+void thread_func(void *v){
+ ThreadContext *c= v;
+
+ for(;;){
+ //printf("thread_func %X enter wait\n", (int)v); fflush(stdout);
+ DosWaitEventSem(c->work_sem, SEM_INDEFINITE_WAIT);
+// WaitForSingleObject(c->work_sem, INFINITE);
+//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);
+ else
+ return;
+ //printf("thread_func %X signal complete\n", (int)v); fflush(stdout);
+ DosPostEventSem(c->done_sem);
+// ReleaseSemaphore(c->done_sem, 1, 0);
+ }
+
+ return;
+}
+
+/**
+ * free what has been allocated by avcodec_thread_init().
+ * must be called after decoding has finished, especially dont call while avcodec_thread_execute() is running
+ */
+void avcodec_thread_free(AVCodecContext *s){
+ ThreadContext *c= s->thread_opaque;
+ int i;
+
+ for(i=0; i<s->thread_count; i++){
+
+ c[i].func= NULL;
+ DosPostEventSem(c[i].work_sem);
+ // ReleaseSemaphore(c[i].work_sem, 1, 0);
+ DosWaitThread((PTID)&c[i].thread,DCWW_WAIT);
+// WaitForSingleObject(c[i].thread, INFINITE);
+ if(c[i].work_sem) DosCloseEventSem(c[i].work_sem);//CloseHandle(c[i].work_sem);
+ if(c[i].done_sem) DosCloseEventSem(c[i].done_sem);//CloseHandle(c[i].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){
+ ThreadContext *c= s->thread_opaque;
+ int i;
+
+ 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; i<count; i++){
+
+ c[i].arg= arg[i];
+ c[i].func= func;
+ c[i].ret= 12345;
+
+ DosPostEventSem(c[i].work_sem);
+// ReleaseSemaphore(c[i].work_sem, 1, 0);
+ }
+ for(i=0; i<count; i++){
+ DosWaitEventSem(c[i].done_sem,SEM_INDEFINITE_WAIT);
+// WaitForSingleObject(c[i].done_sem, INFINITE);
+
+ c[i].func= NULL;
+ if(ret) ret[i]= c[i].ret;
+ }
+ return 0;
+}
+
+int avcodec_thread_init(AVCodecContext *s, int thread_count){
+ int i;
+ ThreadContext *c;
+ uint32_t threadid;
+
+ s->thread_count= thread_count;
+
+ assert(!s->thread_opaque);
+ c= av_mallocz(sizeof(ThreadContext)*thread_count);
+ s->thread_opaque= c;
+
+ for(i=0; i<thread_count; i++){
+//printf("init semaphors %d\n", i); fflush(stdout);
+ c[i].avctx= s;
+
+ if (DosCreateEventSem(NULL,&c[i].work_sem,DC_SEM_SHARED,0))
+ goto fail;
+ if (DosCreateEventSem(NULL,&c[i].done_sem,DC_SEM_SHARED,0))
+ goto fail;
+
+//printf("create thread %d\n", i); fflush(stdout);
+// c[i].thread = (HANDLE)_beginthreadex(NULL, 0, thread_func, &c[i], 0, &threadid );
+ c[i].thread = _beginthread(thread_func, NULL, 0x10000, &c[i]);
+ if( c[i].thread <= 0 ) goto fail;
+ }
+//printf("init done\n"); fflush(stdout);
+
+ s->execute= avcodec_thread_execute;
+
+ return 0;
+fail:
+ avcodec_thread_free(s);
+ return -1;
+}
diff --git a/contrib/ffmpeg/libavcodec/parser.c b/contrib/ffmpeg/libavcodec/parser.c
new file mode 100644
index 000000000..f3e7ee335
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/parser.c
@@ -0,0 +1,834 @@
+/*
+ * Audio and Video frame extraction
+ * Copyright (c) 2003 Fabrice Bellard.
+ * 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 "avcodec.h"
+#include "mpegvideo.h"
+#include "mpegaudio.h"
+#include "ac3.h"
+#include "parser.h"
+
+AVCodecParser *av_first_parser = NULL;
+
+void av_register_codec_parser(AVCodecParser *parser)
+{
+ parser->next = av_first_parser;
+ av_first_parser = parser;
+}
+
+AVCodecParserContext *av_parser_init(int codec_id)
+{
+ AVCodecParserContext *s;
+ AVCodecParser *parser;
+ int ret;
+
+ if(codec_id == CODEC_ID_NONE)
+ return NULL;
+
+ for(parser = av_first_parser; parser != NULL; parser = parser->next) {
+ if (parser->codec_ids[0] == codec_id ||
+ parser->codec_ids[1] == codec_id ||
+ parser->codec_ids[2] == codec_id ||
+ parser->codec_ids[3] == codec_id ||
+ parser->codec_ids[4] == codec_id)
+ goto found;
+ }
+ return NULL;
+ found:
+ s = av_mallocz(sizeof(AVCodecParserContext));
+ if (!s)
+ return NULL;
+ s->parser = parser;
+ s->priv_data = av_mallocz(parser->priv_data_size);
+ if (!s->priv_data) {
+ av_free(s);
+ return NULL;
+ }
+ if (parser->parser_init) {
+ ret = parser->parser_init(s);
+ if (ret != 0) {
+ av_free(s->priv_data);
+ av_free(s);
+ return NULL;
+ }
+ }
+ s->fetch_timestamp=1;
+ s->pict_type = FF_I_TYPE;
+ return s;
+}
+
+/**
+ *
+ * @param buf input
+ * @param buf_size input length, to signal EOF, this should be 0 (so that the last frame can be output)
+ * @param pts input presentation timestamp
+ * @param dts input decoding timestamp
+ * @param poutbuf will contain a pointer to the first byte of the output frame
+ * @param poutbuf_size will contain the length of the output frame
+ * @return the number of bytes of the input bitstream used
+ *
+ * Example:
+ * @code
+ * while(in_len){
+ * len = av_parser_parse(myparser, AVCodecContext, &data, &size,
+ * in_data, in_len,
+ * pts, dts);
+ * in_data += len;
+ * in_len -= len;
+ *
+ * if(size)
+ * decode_frame(data, size);
+ * }
+ * @endcode
+ */
+int av_parser_parse(AVCodecParserContext *s,
+ AVCodecContext *avctx,
+ uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size,
+ int64_t pts, int64_t dts)
+{
+ int index, i, k;
+ uint8_t dummy_buf[FF_INPUT_BUFFER_PADDING_SIZE];
+
+ if (buf_size == 0) {
+ /* padding is always necessary even if EOF, so we add it here */
+ memset(dummy_buf, 0, sizeof(dummy_buf));
+ buf = dummy_buf;
+ } else {
+ /* add a new packet descriptor */
+ k = (s->cur_frame_start_index + 1) & (AV_PARSER_PTS_NB - 1);
+ s->cur_frame_start_index = k;
+ s->cur_frame_offset[k] = s->cur_offset;
+ s->cur_frame_pts[k] = pts;
+ s->cur_frame_dts[k] = dts;
+
+ /* fill first PTS/DTS */
+ if (s->fetch_timestamp){
+ s->fetch_timestamp=0;
+ s->last_pts = pts;
+ s->last_dts = dts;
+ s->cur_frame_pts[k] =
+ s->cur_frame_dts[k] = AV_NOPTS_VALUE;
+ }
+ }
+
+ /* WARNING: the returned index can be negative */
+ index = s->parser->parser_parse(s, avctx, poutbuf, poutbuf_size, buf, buf_size);
+//av_log(NULL, AV_LOG_DEBUG, "parser: in:%"PRId64", %"PRId64", out:%"PRId64", %"PRId64", in:%d out:%d id:%d\n", pts, dts, s->last_pts, s->last_dts, buf_size, *poutbuf_size, avctx->codec_id);
+ /* update the file pointer */
+ if (*poutbuf_size) {
+ /* fill the data for the current frame */
+ s->frame_offset = s->last_frame_offset;
+ s->pts = s->last_pts;
+ s->dts = s->last_dts;
+
+ /* offset of the next frame */
+ s->last_frame_offset = s->cur_offset + index;
+ /* find the packet in which the new frame starts. It
+ is tricky because of MPEG video start codes
+ which can begin in one packet and finish in
+ another packet. In the worst case, an MPEG
+ video start code could be in 4 different
+ packets. */
+ k = s->cur_frame_start_index;
+ for(i = 0; i < AV_PARSER_PTS_NB; i++) {
+ if (s->last_frame_offset >= s->cur_frame_offset[k])
+ break;
+ k = (k - 1) & (AV_PARSER_PTS_NB - 1);
+ }
+
+ s->last_pts = s->cur_frame_pts[k];
+ s->last_dts = s->cur_frame_dts[k];
+
+ /* some parsers tell us the packet size even before seeing the first byte of the next packet,
+ so the next pts/dts is in the next chunk */
+ if(index == buf_size){
+ s->fetch_timestamp=1;
+ }
+ }
+ if (index < 0)
+ index = 0;
+ s->cur_offset += index;
+ return index;
+}
+
+/**
+ *
+ * @return 0 if the output buffer is a subset of the input, 1 if it is allocated and must be freed
+ * @deprecated use AVBitstreamFilter
+ */
+int av_parser_change(AVCodecParserContext *s,
+ AVCodecContext *avctx,
+ uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size, int keyframe){
+
+ if(s && s->parser->split){
+ if((avctx->flags & CODEC_FLAG_GLOBAL_HEADER) || (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER)){
+ int i= s->parser->split(avctx, buf, buf_size);
+ buf += i;
+ buf_size -= i;
+ }
+ }
+
+ /* cast to avoid warning about discarding qualifiers */
+ *poutbuf= (uint8_t *) buf;
+ *poutbuf_size= buf_size;
+ if(avctx->extradata){
+ if( (keyframe && (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER))
+ /*||(s->pict_type != I_TYPE && (s->flags & PARSER_FLAG_DUMP_EXTRADATA_AT_NOKEY))*/
+ /*||(? && (s->flags & PARSER_FLAG_DUMP_EXTRADATA_AT_BEGIN)*/){
+ int size= buf_size + avctx->extradata_size;
+ *poutbuf_size= size;
+ *poutbuf= av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
+
+ memcpy(*poutbuf, avctx->extradata, avctx->extradata_size);
+ memcpy((*poutbuf) + avctx->extradata_size, buf, buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+void av_parser_close(AVCodecParserContext *s)
+{
+ if (s->parser->parser_close)
+ s->parser->parser_close(s);
+ av_free(s->priv_data);
+ av_free(s);
+}
+
+/*****************************************************/
+
+/**
+ * combines the (truncated) bitstream to a complete frame
+ * @returns -1 if no complete frame could be created
+ */
+int ff_combine_frame(ParseContext *pc, int next, uint8_t **buf, int *buf_size)
+{
+#if 0
+ if(pc->overread){
+ printf("overread %d, state:%X next:%d index:%d o_index:%d\n", pc->overread, pc->state, next, pc->index, pc->overread_index);
+ printf("%X %X %X %X\n", (*buf)[0], (*buf)[1],(*buf)[2],(*buf)[3]);
+ }
+#endif
+
+ /* copy overreaded bytes from last frame into buffer */
+ for(; pc->overread>0; pc->overread--){
+ pc->buffer[pc->index++]= pc->buffer[pc->overread_index++];
+ }
+
+ /* flush remaining if EOF */
+ if(!*buf_size && next == END_NOT_FOUND){
+ next= 0;
+ }
+
+ pc->last_index= pc->index;
+
+ /* copy into buffer end return */
+ if(next == END_NOT_FOUND){
+ pc->buffer= av_fast_realloc(pc->buffer, &pc->buffer_size, (*buf_size) + pc->index + FF_INPUT_BUFFER_PADDING_SIZE);
+
+ memcpy(&pc->buffer[pc->index], *buf, *buf_size);
+ pc->index += *buf_size;
+ return -1;
+ }
+
+ *buf_size=
+ pc->overread_index= pc->index + next;
+
+ /* append to buffer */
+ if(pc->index){
+ pc->buffer= av_fast_realloc(pc->buffer, &pc->buffer_size, next + pc->index + FF_INPUT_BUFFER_PADDING_SIZE);
+
+ memcpy(&pc->buffer[pc->index], *buf, next + FF_INPUT_BUFFER_PADDING_SIZE );
+ pc->index = 0;
+ *buf= pc->buffer;
+ }
+
+ /* store overread bytes */
+ for(;next < 0; next++){
+ pc->state = (pc->state<<8) | pc->buffer[pc->last_index + next];
+ pc->overread++;
+ }
+
+#if 0
+ if(pc->overread){
+ printf("overread %d, state:%X next:%d index:%d o_index:%d\n", pc->overread, pc->state, next, pc->index, pc->overread_index);
+ printf("%X %X %X %X\n", (*buf)[0], (*buf)[1],(*buf)[2],(*buf)[3]);
+ }
+#endif
+
+ return 0;
+}
+
+void ff_parse_close(AVCodecParserContext *s)
+{
+ ParseContext *pc = s->priv_data;
+
+ av_free(pc->buffer);
+}
+
+void ff_parse1_close(AVCodecParserContext *s)
+{
+ ParseContext1 *pc1 = s->priv_data;
+
+ av_free(pc1->pc.buffer);
+ av_free(pc1->enc);
+}
+
+/*************************/
+
+#ifdef CONFIG_MPEG4VIDEO_PARSER
+/* used by parser */
+/* XXX: make it use less memory */
+static int av_mpeg4_decode_header(AVCodecParserContext *s1,
+ AVCodecContext *avctx,
+ const uint8_t *buf, int buf_size)
+{
+ ParseContext1 *pc = s1->priv_data;
+ MpegEncContext *s = pc->enc;
+ GetBitContext gb1, *gb = &gb1;
+ int ret;
+
+ s->avctx = avctx;
+ s->current_picture_ptr = &s->current_picture;
+
+ if (avctx->extradata_size && pc->first_picture){
+ init_get_bits(gb, avctx->extradata, avctx->extradata_size*8);
+ ret = ff_mpeg4_decode_picture_header(s, gb);
+ }
+
+ init_get_bits(gb, buf, 8 * buf_size);
+ ret = ff_mpeg4_decode_picture_header(s, gb);
+ if (s->width) {
+ avcodec_set_dimensions(avctx, s->width, s->height);
+ }
+ s1->pict_type= s->pict_type;
+ pc->first_picture = 0;
+ return ret;
+}
+
+static int mpeg4video_parse_init(AVCodecParserContext *s)
+{
+ ParseContext1 *pc = s->priv_data;
+
+ pc->enc = av_mallocz(sizeof(MpegEncContext));
+ if (!pc->enc)
+ return -1;
+ pc->first_picture = 1;
+ return 0;
+}
+
+static int mpeg4video_parse(AVCodecParserContext *s,
+ AVCodecContext *avctx,
+ uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size)
+{
+ ParseContext *pc = s->priv_data;
+ int next;
+
+ if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){
+ next= buf_size;
+ }else{
+ next= ff_mpeg4_find_frame_end(pc, buf, buf_size);
+
+ if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
+ *poutbuf = NULL;
+ *poutbuf_size = 0;
+ return buf_size;
+ }
+ }
+ av_mpeg4_decode_header(s, avctx, buf, buf_size);
+
+ *poutbuf = (uint8_t *)buf;
+ *poutbuf_size = buf_size;
+ return next;
+}
+#endif
+
+int ff_mpeg4video_split(AVCodecContext *avctx,
+ const uint8_t *buf, int buf_size)
+{
+ int i;
+ uint32_t state= -1;
+
+ for(i=0; i<buf_size; i++){
+ state= (state<<8) | buf[i];
+ if(state == 0x1B3 || state == 0x1B6)
+ return i-3;
+ }
+ return 0;
+}
+
+/*************************/
+
+#ifdef CONFIG_MPEGAUDIO_PARSER
+typedef struct MpegAudioParseContext {
+ uint8_t inbuf[MPA_MAX_CODED_FRAME_SIZE]; /* input buffer */
+ uint8_t *inbuf_ptr;
+ int frame_size;
+ int free_format_frame_size;
+ int free_format_next_header;
+ uint32_t header;
+ int header_count;
+} MpegAudioParseContext;
+
+#define MPA_HEADER_SIZE 4
+
+/* header + layer + bitrate + freq + lsf/mpeg25 */
+#undef SAME_HEADER_MASK /* mpegaudio.h defines different version */
+#define SAME_HEADER_MASK \
+ (0xffe00000 | (3 << 17) | (3 << 10) | (3 << 19))
+
+static int mpegaudio_parse_init(AVCodecParserContext *s1)
+{
+ MpegAudioParseContext *s = s1->priv_data;
+ s->inbuf_ptr = s->inbuf;
+ return 0;
+}
+
+static int mpegaudio_parse(AVCodecParserContext *s1,
+ AVCodecContext *avctx,
+ uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size)
+{
+ MpegAudioParseContext *s = s1->priv_data;
+ int len, ret, sr;
+ uint32_t header;
+ const uint8_t *buf_ptr;
+
+ *poutbuf = NULL;
+ *poutbuf_size = 0;
+ buf_ptr = buf;
+ while (buf_size > 0) {
+ len = s->inbuf_ptr - s->inbuf;
+ if (s->frame_size == 0) {
+ /* special case for next header for first frame in free
+ format case (XXX: find a simpler method) */
+ if (s->free_format_next_header != 0) {
+ s->inbuf[0] = s->free_format_next_header >> 24;
+ s->inbuf[1] = s->free_format_next_header >> 16;
+ s->inbuf[2] = s->free_format_next_header >> 8;
+ s->inbuf[3] = s->free_format_next_header;
+ s->inbuf_ptr = s->inbuf + 4;
+ s->free_format_next_header = 0;
+ goto got_header;
+ }
+ /* no header seen : find one. We need at least MPA_HEADER_SIZE
+ bytes to parse it */
+ len = FFMIN(MPA_HEADER_SIZE - len, buf_size);
+ if (len > 0) {
+ memcpy(s->inbuf_ptr, buf_ptr, len);
+ buf_ptr += len;
+ buf_size -= len;
+ s->inbuf_ptr += len;
+ }
+ if ((s->inbuf_ptr - s->inbuf) >= MPA_HEADER_SIZE) {
+ got_header:
+ header = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) |
+ (s->inbuf[2] << 8) | s->inbuf[3];
+
+ ret = mpa_decode_header(avctx, header, &sr);
+ if (ret < 0) {
+ s->header_count= -2;
+ /* no sync found : move by one byte (inefficient, but simple!) */
+ memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1);
+ s->inbuf_ptr--;
+ dprintf(avctx, "skip %x\n", header);
+ /* reset free format frame size to give a chance
+ to get a new bitrate */
+ s->free_format_frame_size = 0;
+ } else {
+ if((header&SAME_HEADER_MASK) != (s->header&SAME_HEADER_MASK) && s->header)
+ s->header_count= -3;
+ s->header= header;
+ s->header_count++;
+ s->frame_size = ret;
+
+#if 0
+ /* free format: prepare to compute frame size */
+ if (decode_header(s, header) == 1) {
+ s->frame_size = -1;
+ }
+#endif
+ }
+ if(s->header_count > 1)
+ avctx->sample_rate= sr;
+ }
+ } else
+#if 0
+ if (s->frame_size == -1) {
+ /* free format : find next sync to compute frame size */
+ len = MPA_MAX_CODED_FRAME_SIZE - len;
+ if (len > buf_size)
+ len = buf_size;
+ if (len == 0) {
+ /* frame too long: resync */
+ s->frame_size = 0;
+ memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1);
+ s->inbuf_ptr--;
+ } else {
+ uint8_t *p, *pend;
+ uint32_t header1;
+ int padding;
+
+ memcpy(s->inbuf_ptr, buf_ptr, len);
+ /* check for header */
+ p = s->inbuf_ptr - 3;
+ pend = s->inbuf_ptr + len - 4;
+ while (p <= pend) {
+ header = (p[0] << 24) | (p[1] << 16) |
+ (p[2] << 8) | p[3];
+ header1 = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) |
+ (s->inbuf[2] << 8) | s->inbuf[3];
+ /* check with high probability that we have a
+ valid header */
+ if ((header & SAME_HEADER_MASK) ==
+ (header1 & SAME_HEADER_MASK)) {
+ /* header found: update pointers */
+ len = (p + 4) - s->inbuf_ptr;
+ buf_ptr += len;
+ buf_size -= len;
+ s->inbuf_ptr = p;
+ /* compute frame size */
+ s->free_format_next_header = header;
+ s->free_format_frame_size = s->inbuf_ptr - s->inbuf;
+ padding = (header1 >> 9) & 1;
+ if (s->layer == 1)
+ s->free_format_frame_size -= padding * 4;
+ else
+ s->free_format_frame_size -= padding;
+ dprintf(avctx, "free frame size=%d padding=%d\n",
+ s->free_format_frame_size, padding);
+ decode_header(s, header1);
+ goto next_data;
+ }
+ p++;
+ }
+ /* not found: simply increase pointers */
+ buf_ptr += len;
+ s->inbuf_ptr += len;
+ buf_size -= len;
+ }
+ } else
+#endif
+ if (len < s->frame_size) {
+ if (s->frame_size > MPA_MAX_CODED_FRAME_SIZE)
+ s->frame_size = MPA_MAX_CODED_FRAME_SIZE;
+ len = FFMIN(s->frame_size - len, buf_size);
+ memcpy(s->inbuf_ptr, buf_ptr, len);
+ buf_ptr += len;
+ s->inbuf_ptr += len;
+ buf_size -= len;
+ }
+
+ if(s->frame_size > 0 && buf_ptr - buf == s->inbuf_ptr - s->inbuf
+ && buf_size + buf_ptr - buf >= s->frame_size){
+ if(s->header_count > 0){
+ *poutbuf = buf;
+ *poutbuf_size = s->frame_size;
+ }
+ buf_ptr = buf + s->frame_size;
+ s->inbuf_ptr = s->inbuf;
+ s->frame_size = 0;
+ break;
+ }
+
+ // next_data:
+ if (s->frame_size > 0 &&
+ (s->inbuf_ptr - s->inbuf) >= s->frame_size) {
+ if(s->header_count > 0){
+ *poutbuf = s->inbuf;
+ *poutbuf_size = s->inbuf_ptr - s->inbuf;
+ }
+ s->inbuf_ptr = s->inbuf;
+ s->frame_size = 0;
+ break;
+ }
+ }
+ return buf_ptr - buf;
+}
+#endif /* CONFIG_MPEGAUDIO_PARSER */
+
+#if defined(CONFIG_AC3_PARSER) || defined(CONFIG_AAC_PARSER)
+/* also used for ADTS AAC */
+typedef struct AC3ParseContext {
+ uint8_t *inbuf_ptr;
+ int frame_size;
+ int header_size;
+ int (*sync)(const uint8_t *buf, int *channels, int *sample_rate,
+ int *bit_rate, int *samples);
+ uint8_t inbuf[8192]; /* input buffer */
+} AC3ParseContext;
+
+#define AC3_HEADER_SIZE 7
+#define AAC_HEADER_SIZE 7
+
+#ifdef CONFIG_AC3_PARSER
+
+static const uint8_t eac3_blocks[4] = {
+ 1, 2, 3, 6
+};
+
+#endif /* CONFIG_AC3_PARSER */
+
+#ifdef CONFIG_AAC_PARSER
+static const int aac_sample_rates[16] = {
+ 96000, 88200, 64000, 48000, 44100, 32000,
+ 24000, 22050, 16000, 12000, 11025, 8000, 7350
+};
+
+static const int aac_channels[8] = {
+ 0, 1, 2, 3, 4, 5, 6, 8
+};
+#endif
+
+#ifdef CONFIG_AC3_PARSER
+static int ac3_sync(const uint8_t *buf, int *channels, int *sample_rate,
+ int *bit_rate, int *samples)
+{
+ int err;
+ unsigned int fscod, acmod, bsid, lfeon;
+ unsigned int strmtyp, substreamid, frmsiz, fscod2, numblkscod;
+ GetBitContext bits;
+ AC3HeaderInfo hdr;
+
+ err = ff_ac3_parse_header(buf, &hdr);
+
+ if(err < 0 && err != -2)
+ return 0;
+
+ bsid = hdr.bsid;
+ if(bsid <= 10) { /* Normal AC-3 */
+ *sample_rate = hdr.sample_rate;
+ *bit_rate = hdr.bit_rate;
+ *channels = hdr.channels;
+ *samples = AC3_FRAME_SIZE;
+ return hdr.frame_size;
+ } else if (bsid > 10 && bsid <= 16) { /* Enhanced AC-3 */
+ init_get_bits(&bits, &buf[2], (AC3_HEADER_SIZE-2) * 8);
+ strmtyp = get_bits(&bits, 2);
+ substreamid = get_bits(&bits, 3);
+
+ if (strmtyp != 0 || substreamid != 0)
+ return 0; /* Currently don't support additional streams */
+
+ frmsiz = get_bits(&bits, 11) + 1;
+ fscod = get_bits(&bits, 2);
+ if (fscod == 3) {
+ fscod2 = get_bits(&bits, 2);
+ numblkscod = 3;
+
+ if(fscod2 == 3)
+ return 0;
+
+ *sample_rate = ff_ac3_freqs[fscod2] / 2;
+ } else {
+ numblkscod = get_bits(&bits, 2);
+
+ *sample_rate = ff_ac3_freqs[fscod];
+ }
+
+ acmod = get_bits(&bits, 3);
+ lfeon = get_bits1(&bits);
+
+ *samples = eac3_blocks[numblkscod] * 256;
+ *bit_rate = frmsiz * (*sample_rate) * 16 / (*samples);
+ *channels = ff_ac3_channels[acmod] + lfeon;
+
+ return frmsiz * 2;
+ }
+
+ /* Unsupported bitstream version */
+ return 0;
+}
+#endif /* CONFIG_AC3_PARSER */
+
+#ifdef CONFIG_AAC_PARSER
+static int aac_sync(const uint8_t *buf, int *channels, int *sample_rate,
+ int *bit_rate, int *samples)
+{
+ GetBitContext bits;
+ int size, rdb, ch, sr;
+
+ init_get_bits(&bits, buf, AAC_HEADER_SIZE * 8);
+
+ if(get_bits(&bits, 12) != 0xfff)
+ return 0;
+
+ skip_bits1(&bits); /* id */
+ skip_bits(&bits, 2); /* layer */
+ skip_bits1(&bits); /* protection_absent */
+ skip_bits(&bits, 2); /* profile_objecttype */
+ sr = get_bits(&bits, 4); /* sample_frequency_index */
+ if(!aac_sample_rates[sr])
+ return 0;
+ skip_bits1(&bits); /* private_bit */
+ ch = get_bits(&bits, 3); /* channel_configuration */
+ if(!aac_channels[ch])
+ return 0;
+ skip_bits1(&bits); /* original/copy */
+ skip_bits1(&bits); /* home */
+
+ /* adts_variable_header */
+ skip_bits1(&bits); /* copyright_identification_bit */
+ skip_bits1(&bits); /* copyright_identification_start */
+ size = get_bits(&bits, 13); /* aac_frame_length */
+ skip_bits(&bits, 11); /* adts_buffer_fullness */
+ rdb = get_bits(&bits, 2); /* number_of_raw_data_blocks_in_frame */
+
+ *channels = aac_channels[ch];
+ *sample_rate = aac_sample_rates[sr];
+ *samples = (rdb + 1) * 1024;
+ *bit_rate = size * 8 * *sample_rate / *samples;
+
+ return size;
+}
+#endif /* CONFIG_AAC_PARSER */
+
+#ifdef CONFIG_AC3_PARSER
+static int ac3_parse_init(AVCodecParserContext *s1)
+{
+ AC3ParseContext *s = s1->priv_data;
+ s->inbuf_ptr = s->inbuf;
+ s->header_size = AC3_HEADER_SIZE;
+ s->sync = ac3_sync;
+ return 0;
+}
+#endif
+
+#ifdef CONFIG_AAC_PARSER
+static int aac_parse_init(AVCodecParserContext *s1)
+{
+ AC3ParseContext *s = s1->priv_data;
+ s->inbuf_ptr = s->inbuf;
+ s->header_size = AAC_HEADER_SIZE;
+ s->sync = aac_sync;
+ return 0;
+}
+#endif
+
+/* also used for ADTS AAC */
+static int ac3_parse(AVCodecParserContext *s1,
+ AVCodecContext *avctx,
+ uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size)
+{
+ AC3ParseContext *s = s1->priv_data;
+ const uint8_t *buf_ptr;
+ int len, sample_rate, bit_rate, channels, samples;
+
+ *poutbuf = NULL;
+ *poutbuf_size = 0;
+
+ buf_ptr = buf;
+ while (buf_size > 0) {
+ len = s->inbuf_ptr - s->inbuf;
+ if (s->frame_size == 0) {
+ /* no header seen : find one. We need at least s->header_size
+ bytes to parse it */
+ len = FFMIN(s->header_size - len, buf_size);
+
+ memcpy(s->inbuf_ptr, buf_ptr, len);
+ buf_ptr += len;
+ s->inbuf_ptr += len;
+ buf_size -= len;
+ if ((s->inbuf_ptr - s->inbuf) == s->header_size) {
+ len = s->sync(s->inbuf, &channels, &sample_rate, &bit_rate,
+ &samples);
+ if (len == 0) {
+ /* no sync found : move by one byte (inefficient, but simple!) */
+ memmove(s->inbuf, s->inbuf + 1, s->header_size - 1);
+ s->inbuf_ptr--;
+ } else {
+ s->frame_size = len;
+ /* update codec info */
+ avctx->sample_rate = sample_rate;
+ /* set channels,except if the user explicitly requests 1 or 2 channels, XXX/FIXME this is a bit ugly */
+ if(avctx->codec_id == CODEC_ID_AC3){
+ if(avctx->channels!=1 && avctx->channels!=2){
+ avctx->channels = channels;
+ }
+ } else {
+ avctx->channels = channels;
+ }
+ avctx->bit_rate = bit_rate;
+ avctx->frame_size = samples;
+ }
+ }
+ } else {
+ len = FFMIN(s->frame_size - len, buf_size);
+
+ memcpy(s->inbuf_ptr, buf_ptr, len);
+ buf_ptr += len;
+ s->inbuf_ptr += len;
+ buf_size -= len;
+
+ if(s->inbuf_ptr - s->inbuf == s->frame_size){
+ *poutbuf = s->inbuf;
+ *poutbuf_size = s->frame_size;
+ s->inbuf_ptr = s->inbuf;
+ s->frame_size = 0;
+ break;
+ }
+ }
+ }
+ return buf_ptr - buf;
+}
+#endif /* CONFIG_AC3_PARSER || CONFIG_AAC_PARSER */
+
+#ifdef CONFIG_MPEG4VIDEO_PARSER
+AVCodecParser mpeg4video_parser = {
+ { CODEC_ID_MPEG4 },
+ sizeof(ParseContext1),
+ mpeg4video_parse_init,
+ mpeg4video_parse,
+ ff_parse1_close,
+ ff_mpeg4video_split,
+};
+#endif
+#ifdef CONFIG_MPEGAUDIO_PARSER
+AVCodecParser mpegaudio_parser = {
+ { CODEC_ID_MP2, CODEC_ID_MP3 },
+ sizeof(MpegAudioParseContext),
+ mpegaudio_parse_init,
+ mpegaudio_parse,
+ NULL,
+};
+#endif
+#ifdef CONFIG_AC3_PARSER
+AVCodecParser ac3_parser = {
+ { CODEC_ID_AC3 },
+ sizeof(AC3ParseContext),
+ ac3_parse_init,
+ ac3_parse,
+ NULL,
+};
+#endif
+#ifdef CONFIG_AAC_PARSER
+AVCodecParser aac_parser = {
+ { CODEC_ID_AAC },
+ sizeof(AC3ParseContext),
+ aac_parse_init,
+ ac3_parse,
+ NULL,
+};
+#endif
diff --git a/src/libffmpeg/libavcodec/parser.h b/contrib/ffmpeg/libavcodec/parser.h
index 3496b341f..3496b341f 100644
--- a/src/libffmpeg/libavcodec/parser.h
+++ b/contrib/ffmpeg/libavcodec/parser.h
diff --git a/contrib/ffmpeg/libavcodec/pcm.c b/contrib/ffmpeg/libavcodec/pcm.c
new file mode 100644
index 000000000..5570c01bd
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/pcm.c
@@ -0,0 +1,526 @@
+/*
+ * PCM codecs
+ * Copyright (c) 2001 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 pcm.c
+ * PCM codecs
+ */
+
+#include "avcodec.h"
+#include "bitstream.h" // for ff_reverse
+
+/* 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 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 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 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<v;j++) {
+ linear_to_xlaw[8192 + j] = (i ^ mask);
+ if (j > 0)
+ linear_to_xlaw[8192 - j] = (i ^ (mask ^ 0x80));
+ }
+ }
+ linear_to_xlaw[0] = linear_to_xlaw[1];
+}
+
+static 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);
+ break;
+ case CODEC_ID_PCM_MULAW:
+ build_xlaw_table(linear_to_ulaw, ulaw2linear, 0xff);
+ break;
+ default:
+ break;
+ }
+
+ switch(avctx->codec->id) {
+ case CODEC_ID_PCM_S32LE:
+ case CODEC_ID_PCM_S32BE:
+ case CODEC_ID_PCM_U32LE:
+ case CODEC_ID_PCM_U32BE:
+ avctx->block_align = 4 * avctx->channels;
+ 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:
+ avctx->block_align = 3 * avctx->channels;
+ break;
+ case CODEC_ID_PCM_S16LE:
+ case CODEC_ID_PCM_S16BE:
+ case CODEC_ID_PCM_U16LE:
+ case CODEC_ID_PCM_U16BE:
+ avctx->block_align = 2 * avctx->channels;
+ break;
+ case CODEC_ID_PCM_S8:
+ case CODEC_ID_PCM_U8:
+ case CODEC_ID_PCM_MULAW:
+ case CODEC_ID_PCM_ALAW:
+ avctx->block_align = avctx->channels;
+ break;
+ default:
+ break;
+ }
+
+ avctx->coded_frame= avcodec_alloc_frame();
+ avctx->coded_frame->key_frame= 1;
+
+ return 0;
+}
+
+static int pcm_encode_close(AVCodecContext *avctx)
+{
+ av_freep(&avctx->coded_frame);
+
+ return 0;
+}
+
+/**
+ * \brief convert samples from 16 bit
+ * \param bps byte per sample for the destination format, must be >= 2
+ * \param le 0 for big-, 1 for little-endian
+ * \param us 0 for signed, 1 for unsigned output
+ * \param samples input samples
+ * \param dst output samples
+ * \param n number of samples in samples buffer.
+ */
+static inline void encode_from16(int bps, int le, int us,
+ short **samples, uint8_t **dst, int n) {
+ if (bps > 2)
+ memset(*dst, 0, n * bps);
+ if (le) *dst += bps - 2;
+ for(;n>0;n--) {
+ register int v = *(*samples)++;
+ if (us) v += 0x8000;
+ (*dst)[le] = v >> 8;
+ (*dst)[1 - le] = v;
+ *dst += bps;
+ }
+ if (le) *dst -= bps - 2;
+}
+
+static int pcm_encode_frame(AVCodecContext *avctx,
+ unsigned char *frame, int buf_size, void *data)
+{
+ int n, sample_size, v;
+ short *samples;
+ unsigned char *dst;
+
+ switch(avctx->codec->id) {
+ case CODEC_ID_PCM_S32LE:
+ case CODEC_ID_PCM_S32BE:
+ case CODEC_ID_PCM_U32LE:
+ case CODEC_ID_PCM_U32BE:
+ sample_size = 4;
+ 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:
+ sample_size = 3;
+ break;
+ case CODEC_ID_PCM_S16LE:
+ case CODEC_ID_PCM_S16BE:
+ case CODEC_ID_PCM_U16LE:
+ case CODEC_ID_PCM_U16BE:
+ sample_size = 2;
+ break;
+ default:
+ sample_size = 1;
+ break;
+ }
+ n = buf_size / sample_size;
+ samples = data;
+ dst = frame;
+
+ switch(avctx->codec->id) {
+ case CODEC_ID_PCM_S32LE:
+ encode_from16(4, 1, 0, &samples, &dst, n);
+ break;
+ case CODEC_ID_PCM_S32BE:
+ encode_from16(4, 0, 0, &samples, &dst, n);
+ break;
+ case CODEC_ID_PCM_U32LE:
+ encode_from16(4, 1, 1, &samples, &dst, n);
+ break;
+ case CODEC_ID_PCM_U32BE:
+ encode_from16(4, 0, 1, &samples, &dst, n);
+ break;
+ case CODEC_ID_PCM_S24LE:
+ encode_from16(3, 1, 0, &samples, &dst, n);
+ break;
+ case CODEC_ID_PCM_S24BE:
+ encode_from16(3, 0, 0, &samples, &dst, n);
+ break;
+ case CODEC_ID_PCM_U24LE:
+ encode_from16(3, 1, 1, &samples, &dst, n);
+ break;
+ case CODEC_ID_PCM_U24BE:
+ encode_from16(3, 0, 1, &samples, &dst, n);
+ break;
+ case CODEC_ID_PCM_S24DAUD:
+ for(;n>0;n--) {
+ uint32_t tmp = ff_reverse[*samples >> 8] +
+ (ff_reverse[*samples & 0xff] << 8);
+ tmp <<= 4; // sync flags would go here
+ dst[2] = tmp & 0xff;
+ tmp >>= 8;
+ dst[1] = tmp & 0xff;
+ dst[0] = tmp >> 8;
+ samples++;
+ dst += 3;
+ }
+ break;
+ case CODEC_ID_PCM_S16LE:
+ for(;n>0;n--) {
+ v = *samples++;
+ dst[0] = v & 0xff;
+ dst[1] = v >> 8;
+ dst += 2;
+ }
+ break;
+ case CODEC_ID_PCM_S16BE:
+ for(;n>0;n--) {
+ v = *samples++;
+ dst[0] = v >> 8;
+ dst[1] = v;
+ dst += 2;
+ }
+ break;
+ case CODEC_ID_PCM_U16LE:
+ for(;n>0;n--) {
+ v = *samples++;
+ v += 0x8000;
+ dst[0] = v & 0xff;
+ dst[1] = v >> 8;
+ dst += 2;
+ }
+ break;
+ case CODEC_ID_PCM_U16BE:
+ for(;n>0;n--) {
+ v = *samples++;
+ v += 0x8000;
+ dst[0] = v >> 8;
+ dst[1] = v;
+ dst += 2;
+ }
+ break;
+ case CODEC_ID_PCM_S8:
+ for(;n>0;n--) {
+ v = *samples++;
+ dst[0] = v >> 8;
+ dst++;
+ }
+ break;
+ case CODEC_ID_PCM_U8:
+ for(;n>0;n--) {
+ v = *samples++;
+ dst[0] = (v >> 8) + 128;
+ dst++;
+ }
+ break;
+ case CODEC_ID_PCM_ALAW:
+ for(;n>0;n--) {
+ v = *samples++;
+ dst[0] = linear_to_alaw[(v + 32768) >> 2];
+ dst++;
+ }
+ break;
+ case CODEC_ID_PCM_MULAW:
+ for(;n>0;n--) {
+ v = *samples++;
+ dst[0] = linear_to_ulaw[(v + 32768) >> 2];
+ dst++;
+ }
+ break;
+ default:
+ return -1;
+ }
+ //avctx->frame_size = (dst - frame) / (sample_size * avctx->channels);
+
+ return dst - frame;
+}
+
+typedef struct PCMDecode {
+ short table[256];
+} PCMDecode;
+
+static int pcm_decode_init(AVCodecContext * avctx)
+{
+ PCMDecode *s = avctx->priv_data;
+ int i;
+
+ switch(avctx->codec->id) {
+ case CODEC_ID_PCM_ALAW:
+ for(i=0;i<256;i++)
+ s->table[i] = alaw2linear(i);
+ break;
+ case CODEC_ID_PCM_MULAW:
+ for(i=0;i<256;i++)
+ s->table[i] = ulaw2linear(i);
+ break;
+ default:
+ break;
+ }
+ return 0;
+}
+
+/**
+ * \brief convert samples to 16 bit
+ * \param bps byte per sample for the source format, must be >= 2
+ * \param le 0 for big-, 1 for little-endian
+ * \param us 0 for signed, 1 for unsigned input
+ * \param src input samples
+ * \param samples output samples
+ * \param src_len number of bytes in src
+ */
+static inline void decode_to16(int bps, int le, int us,
+ uint8_t **src, short **samples, int src_len)
+{
+ register int n = src_len / bps;
+ if (le) *src += bps - 2;
+ for(;n>0;n--) {
+ *(*samples)++ = ((*src)[le] << 8 | (*src)[1 - le]) - (us?0x8000:0);
+ *src += bps;
+ }
+ if (le) *src -= bps - 2;
+}
+
+static int pcm_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ PCMDecode *s = avctx->priv_data;
+ int n;
+ short *samples;
+ uint8_t *src;
+
+ samples = data;
+ src = buf;
+
+ n= av_get_bits_per_sample(avctx->codec_id)/8;
+ if(n && buf_size % n){
+ av_log(avctx, AV_LOG_ERROR, "invalid PCM packet\n");
+ return -1;
+ }
+
+ buf_size= FFMIN(buf_size, *data_size/2);
+ *data_size=0;
+
+ switch(avctx->codec->id) {
+ case CODEC_ID_PCM_S32LE:
+ decode_to16(4, 1, 0, &src, &samples, buf_size);
+ break;
+ case CODEC_ID_PCM_S32BE:
+ decode_to16(4, 0, 0, &src, &samples, buf_size);
+ break;
+ case CODEC_ID_PCM_U32LE:
+ decode_to16(4, 1, 1, &src, &samples, buf_size);
+ break;
+ case CODEC_ID_PCM_U32BE:
+ decode_to16(4, 0, 1, &src, &samples, buf_size);
+ break;
+ case CODEC_ID_PCM_S24LE:
+ decode_to16(3, 1, 0, &src, &samples, buf_size);
+ break;
+ case CODEC_ID_PCM_S24BE:
+ decode_to16(3, 0, 0, &src, &samples, buf_size);
+ break;
+ case CODEC_ID_PCM_U24LE:
+ decode_to16(3, 1, 1, &src, &samples, buf_size);
+ break;
+ case CODEC_ID_PCM_U24BE:
+ decode_to16(3, 0, 1, &src, &samples, buf_size);
+ break;
+ case CODEC_ID_PCM_S24DAUD:
+ n = buf_size / 3;
+ for(;n>0;n--) {
+ uint32_t v = src[0] << 16 | src[1] << 8 | src[2];
+ v >>= 4; // sync flags are here
+ *samples++ = ff_reverse[(v >> 8) & 0xff] +
+ (ff_reverse[v & 0xff] << 8);
+ src += 3;
+ }
+ break;
+ case CODEC_ID_PCM_S16LE:
+ n = buf_size >> 1;
+ for(;n>0;n--) {
+ *samples++ = src[0] | (src[1] << 8);
+ src += 2;
+ }
+ break;
+ case CODEC_ID_PCM_S16BE:
+ n = buf_size >> 1;
+ for(;n>0;n--) {
+ *samples++ = (src[0] << 8) | src[1];
+ src += 2;
+ }
+ break;
+ case CODEC_ID_PCM_U16LE:
+ n = buf_size >> 1;
+ for(;n>0;n--) {
+ *samples++ = (src[0] | (src[1] << 8)) - 0x8000;
+ src += 2;
+ }
+ break;
+ case CODEC_ID_PCM_U16BE:
+ n = buf_size >> 1;
+ for(;n>0;n--) {
+ *samples++ = ((src[0] << 8) | src[1]) - 0x8000;
+ src += 2;
+ }
+ break;
+ case CODEC_ID_PCM_S8:
+ n = buf_size;
+ for(;n>0;n--) {
+ *samples++ = src[0] << 8;
+ src++;
+ }
+ break;
+ case CODEC_ID_PCM_U8:
+ n = buf_size;
+ for(;n>0;n--) {
+ *samples++ = ((int)src[0] - 128) << 8;
+ src++;
+ }
+ break;
+ case CODEC_ID_PCM_ALAW:
+ case CODEC_ID_PCM_MULAW:
+ n = buf_size;
+ for(;n>0;n--) {
+ *samples++ = s->table[src[0]];
+ src++;
+ }
+ break;
+ default:
+ return -1;
+ }
+ *data_size = (uint8_t *)samples - (uint8_t *)data;
+ return src - buf;
+}
+
+#define PCM_CODEC(id, name) \
+AVCodec name ## _encoder = { \
+ #name, \
+ CODEC_TYPE_AUDIO, \
+ id, \
+ 0, \
+ pcm_encode_init, \
+ pcm_encode_frame, \
+ pcm_encode_close, \
+ NULL, \
+}; \
+AVCodec name ## _decoder = { \
+ #name, \
+ CODEC_TYPE_AUDIO, \
+ id, \
+ sizeof(PCMDecode), \
+ pcm_decode_init, \
+ NULL, \
+ NULL, \
+ pcm_decode_frame, \
+}
+
+PCM_CODEC(CODEC_ID_PCM_S32LE, pcm_s32le);
+PCM_CODEC(CODEC_ID_PCM_S32BE, pcm_s32be);
+PCM_CODEC(CODEC_ID_PCM_U32LE, pcm_u32le);
+PCM_CODEC(CODEC_ID_PCM_U32BE, pcm_u32be);
+PCM_CODEC(CODEC_ID_PCM_S24LE, pcm_s24le);
+PCM_CODEC(CODEC_ID_PCM_S24BE, pcm_s24be);
+PCM_CODEC(CODEC_ID_PCM_U24LE, pcm_u24le);
+PCM_CODEC(CODEC_ID_PCM_U24BE, pcm_u24be);
+PCM_CODEC(CODEC_ID_PCM_S24DAUD, pcm_s24daud);
+PCM_CODEC(CODEC_ID_PCM_S16LE, pcm_s16le);
+PCM_CODEC(CODEC_ID_PCM_S16BE, pcm_s16be);
+PCM_CODEC(CODEC_ID_PCM_U16LE, pcm_u16le);
+PCM_CODEC(CODEC_ID_PCM_U16BE, pcm_u16be);
+PCM_CODEC(CODEC_ID_PCM_S8, pcm_s8);
+PCM_CODEC(CODEC_ID_PCM_U8, pcm_u8);
+PCM_CODEC(CODEC_ID_PCM_ALAW, pcm_alaw);
+PCM_CODEC(CODEC_ID_PCM_MULAW, pcm_mulaw);
+
+#undef PCM_CODEC
diff --git a/contrib/ffmpeg/libavcodec/png.c b/contrib/ffmpeg/libavcodec/png.c
new file mode 100644
index 000000000..05b4512b7
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/png.c
@@ -0,0 +1,966 @@
+/*
+ * PNG image format
+ * Copyright (c) 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"
+
+/* TODO:
+ * - add 2, 4 and 16 bit depth support
+ * - use filters when generating a png (better compression)
+ */
+
+#include <zlib.h>
+
+//#define DEBUG
+
+#define PNG_COLOR_MASK_PALETTE 1
+#define PNG_COLOR_MASK_COLOR 2
+#define PNG_COLOR_MASK_ALPHA 4
+
+#define PNG_COLOR_TYPE_GRAY 0
+#define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)
+#define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR)
+#define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
+#define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)
+
+#define PNG_FILTER_VALUE_NONE 0
+#define PNG_FILTER_VALUE_SUB 1
+#define PNG_FILTER_VALUE_UP 2
+#define PNG_FILTER_VALUE_AVG 3
+#define PNG_FILTER_VALUE_PAETH 4
+
+#define PNG_IHDR 0x0001
+#define PNG_IDAT 0x0002
+#define PNG_ALLIMAGE 0x0004
+#define PNG_PLTE 0x0008
+
+#define NB_PASSES 7
+
+#define IOBUF_SIZE 4096
+
+typedef struct PNGContext {
+ uint8_t *bytestream;
+ uint8_t *bytestream_start;
+ uint8_t *bytestream_end;
+ AVFrame picture;
+
+ int state;
+ int width, height;
+ int bit_depth;
+ int color_type;
+ int compression_type;
+ int interlace_type;
+ int filter_type;
+ int channels;
+ int bits_per_pixel;
+ int bpp;
+
+ uint8_t *image_buf;
+ int image_linesize;
+ uint32_t palette[256];
+ uint8_t *crow_buf;
+ uint8_t *last_row;
+ uint8_t *tmp_row;
+ int pass;
+ int crow_size; /* compressed row size (include filter type) */
+ int row_size; /* decompressed row size */
+ int pass_row_size; /* decompress row size of the current pass */
+ int y;
+ z_stream zstream;
+ uint8_t buf[IOBUF_SIZE];
+} PNGContext;
+
+static unsigned int get32(uint8_t **b){
+ (*b) += 4;
+ return ((*b)[-4]<<24) + ((*b)[-3]<<16) + ((*b)[-2]<<8) + (*b)[-1];
+}
+
+#ifdef CONFIG_ENCODERS
+static void put32(uint8_t **b, unsigned int v){
+ *(*b)++= v>>24;
+ *(*b)++= v>>16;
+ *(*b)++= v>>8;
+ *(*b)++= v;
+}
+#endif
+
+static const uint8_t pngsig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
+
+/* Mask to determine which y pixels are valid in a pass */
+static const uint8_t png_pass_ymask[NB_PASSES] = {
+ 0x80, 0x80, 0x08, 0x88, 0x22, 0xaa, 0x55,
+};
+
+/* Mask to determine which y pixels can be written in a pass */
+static const uint8_t png_pass_dsp_ymask[NB_PASSES] = {
+ 0xff, 0xff, 0x0f, 0xcc, 0x33, 0xff, 0x55,
+};
+
+/* minimum x value */
+static const uint8_t png_pass_xmin[NB_PASSES] = {
+ 0, 4, 0, 2, 0, 1, 0
+};
+
+/* x shift to get row width */
+static const uint8_t png_pass_xshift[NB_PASSES] = {
+ 3, 3, 2, 2, 1, 1, 0
+};
+
+/* Mask to determine which pixels are valid in a pass */
+static const uint8_t png_pass_mask[NB_PASSES] = {
+ 0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff
+};
+
+/* Mask to determine which pixels to overwrite while displaying */
+static const uint8_t png_pass_dsp_mask[NB_PASSES] = {
+ 0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff
+};
+#if 0
+static int png_probe(AVProbeData *pd)
+{
+ if (pd->buf_size >= 8 &&
+ memcmp(pd->buf, pngsig, 8) == 0)
+ return AVPROBE_SCORE_MAX;
+ else
+ return 0;
+}
+#endif
+static void *png_zalloc(void *opaque, unsigned int items, unsigned int size)
+{
+ if(items >= UINT_MAX / size)
+ return NULL;
+ return av_malloc(items * size);
+}
+
+static void png_zfree(void *opaque, void *ptr)
+{
+ av_free(ptr);
+}
+
+static int png_get_nb_channels(int color_type)
+{
+ int channels;
+ channels = 1;
+ if ((color_type & (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)) ==
+ PNG_COLOR_MASK_COLOR)
+ channels = 3;
+ if (color_type & PNG_COLOR_MASK_ALPHA)
+ channels++;
+ return channels;
+}
+
+/* compute the row size of an interleaved pass */
+static int png_pass_row_size(int pass, int bits_per_pixel, int width)
+{
+ int shift, xmin, pass_width;
+
+ xmin = png_pass_xmin[pass];
+ if (width <= xmin)
+ return 0;
+ shift = png_pass_xshift[pass];
+ pass_width = (width - xmin + (1 << shift) - 1) >> shift;
+ return (pass_width * bits_per_pixel + 7) >> 3;
+}
+
+/* NOTE: we try to construct a good looking image at each pass. width
+ is the original image width. We also do pixel format convertion at
+ this stage */
+static void png_put_interlaced_row(uint8_t *dst, int width,
+ int bits_per_pixel, int pass,
+ int color_type, const uint8_t *src)
+{
+ int x, mask, dsp_mask, j, src_x, b, bpp;
+ uint8_t *d;
+ const uint8_t *s;
+
+ mask = png_pass_mask[pass];
+ dsp_mask = png_pass_dsp_mask[pass];
+ switch(bits_per_pixel) {
+ case 1:
+ /* we must intialize the line to zero before writing to it */
+ if (pass == 0)
+ memset(dst, 0, (width + 7) >> 3);
+ src_x = 0;
+ for(x = 0; x < width; x++) {
+ j = (x & 7);
+ if ((dsp_mask << j) & 0x80) {
+ b = (src[src_x >> 3] >> (7 - (src_x & 7))) & 1;
+ dst[x >> 3] |= b << (7 - j);
+ }
+ if ((mask << j) & 0x80)
+ src_x++;
+ }
+ break;
+ default:
+ bpp = bits_per_pixel >> 3;
+ d = dst;
+ s = src;
+ if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
+ for(x = 0; x < width; x++) {
+ j = x & 7;
+ if ((dsp_mask << j) & 0x80) {
+ *(uint32_t *)d = (s[3] << 24) | (s[0] << 16) | (s[1] << 8) | s[2];
+ }
+ d += bpp;
+ if ((mask << j) & 0x80)
+ s += bpp;
+ }
+ } else {
+ for(x = 0; x < width; x++) {
+ j = x & 7;
+ if ((dsp_mask << j) & 0x80) {
+ memcpy(d, s, bpp);
+ }
+ d += bpp;
+ if ((mask << j) & 0x80)
+ s += bpp;
+ }
+ }
+ break;
+ }
+}
+
+#ifdef CONFIG_ENCODERS
+static void png_get_interlaced_row(uint8_t *dst, int row_size,
+ int bits_per_pixel, int pass,
+ const uint8_t *src, int width)
+{
+ int x, mask, dst_x, j, b, bpp;
+ uint8_t *d;
+ const uint8_t *s;
+
+ mask = png_pass_mask[pass];
+ switch(bits_per_pixel) {
+ case 1:
+ memset(dst, 0, row_size);
+ dst_x = 0;
+ for(x = 0; x < width; x++) {
+ j = (x & 7);
+ if ((mask << j) & 0x80) {
+ b = (src[x >> 3] >> (7 - j)) & 1;
+ dst[dst_x >> 3] |= b << (7 - (dst_x & 7));
+ dst_x++;
+ }
+ }
+ break;
+ default:
+ bpp = bits_per_pixel >> 3;
+ d = dst;
+ s = src;
+ for(x = 0; x < width; x++) {
+ j = x & 7;
+ if ((mask << j) & 0x80) {
+ memcpy(d, s, bpp);
+ d += bpp;
+ }
+ s += bpp;
+ }
+ break;
+ }
+}
+#endif
+
+/* XXX: optimize */
+/* NOTE: 'dst' can be equal to 'last' */
+static void png_filter_row(uint8_t *dst, int filter_type,
+ uint8_t *src, uint8_t *last, int size, int bpp)
+{
+ int i, p;
+
+ switch(filter_type) {
+ case PNG_FILTER_VALUE_NONE:
+ memcpy(dst, src, size);
+ break;
+ case PNG_FILTER_VALUE_SUB:
+ for(i = 0; i < bpp; i++) {
+ dst[i] = src[i];
+ }
+ for(i = bpp; i < size; i++) {
+ p = dst[i - bpp];
+ dst[i] = p + src[i];
+ }
+ break;
+ case PNG_FILTER_VALUE_UP:
+ for(i = 0; i < size; i++) {
+ p = last[i];
+ dst[i] = p + src[i];
+ }
+ break;
+ case PNG_FILTER_VALUE_AVG:
+ for(i = 0; i < bpp; i++) {
+ p = (last[i] >> 1);
+ dst[i] = p + src[i];
+ }
+ for(i = bpp; i < size; i++) {
+ p = ((dst[i - bpp] + last[i]) >> 1);
+ dst[i] = p + src[i];
+ }
+ break;
+ case PNG_FILTER_VALUE_PAETH:
+ for(i = 0; i < bpp; i++) {
+ p = last[i];
+ dst[i] = p + src[i];
+ }
+ for(i = bpp; i < size; i++) {
+ int a, b, c, pa, pb, pc;
+
+ a = dst[i - bpp];
+ b = last[i];
+ c = last[i - bpp];
+
+ p = b - c;
+ pc = a - c;
+
+ pa = abs(p);
+ pb = abs(pc);
+ pc = abs(p + pc);
+
+ if (pa <= pb && pa <= pc)
+ p = a;
+ else if (pb <= pc)
+ p = b;
+ else
+ p = c;
+ dst[i] = p + src[i];
+ }
+ break;
+ }
+}
+
+#ifdef CONFIG_ENCODERS
+static void convert_from_rgb32(uint8_t *dst, const uint8_t *src, int width)
+{
+ uint8_t *d;
+ int j;
+ unsigned int v;
+
+ d = dst;
+ for(j = 0; j < width; j++) {
+ v = ((const uint32_t *)src)[j];
+ d[0] = v >> 16;
+ d[1] = v >> 8;
+ d[2] = v;
+ d[3] = v >> 24;
+ d += 4;
+ }
+}
+#endif
+
+#ifdef CONFIG_DECODERS
+static void convert_to_rgb32(uint8_t *dst, const uint8_t *src, int width)
+{
+ int j;
+ unsigned int r, g, b, a;
+
+ for(j = 0;j < width; j++) {
+ r = src[0];
+ g = src[1];
+ b = src[2];
+ a = src[3];
+ *(uint32_t *)dst = (a << 24) | (r << 16) | (g << 8) | b;
+ dst += 4;
+ src += 4;
+ }
+}
+
+/* process exactly one decompressed row */
+static void png_handle_row(PNGContext *s)
+{
+ uint8_t *ptr, *last_row;
+ int got_line;
+
+ if (!s->interlace_type) {
+ ptr = s->image_buf + s->image_linesize * s->y;
+ /* need to swap bytes correctly for RGB_ALPHA */
+ if (s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
+ png_filter_row(s->tmp_row, s->crow_buf[0], s->crow_buf + 1,
+ s->last_row, s->row_size, s->bpp);
+ memcpy(s->last_row, s->tmp_row, s->row_size);
+ convert_to_rgb32(ptr, s->tmp_row, s->width);
+ } else {
+ /* in normal case, we avoid one copy */
+ if (s->y == 0)
+ last_row = s->last_row;
+ else
+ last_row = ptr - s->image_linesize;
+
+ png_filter_row(ptr, s->crow_buf[0], s->crow_buf + 1,
+ last_row, s->row_size, s->bpp);
+ }
+ s->y++;
+ if (s->y == s->height) {
+ s->state |= PNG_ALLIMAGE;
+ }
+ } else {
+ got_line = 0;
+ for(;;) {
+ ptr = s->image_buf + s->image_linesize * s->y;
+ if ((png_pass_ymask[s->pass] << (s->y & 7)) & 0x80) {
+ /* if we already read one row, it is time to stop to
+ wait for the next one */
+ if (got_line)
+ break;
+ png_filter_row(s->tmp_row, s->crow_buf[0], s->crow_buf + 1,
+ s->last_row, s->pass_row_size, s->bpp);
+ memcpy(s->last_row, s->tmp_row, s->pass_row_size);
+ got_line = 1;
+ }
+ if ((png_pass_dsp_ymask[s->pass] << (s->y & 7)) & 0x80) {
+ /* NOTE: RGB32 is handled directly in png_put_interlaced_row */
+ png_put_interlaced_row(ptr, s->width, s->bits_per_pixel, s->pass,
+ s->color_type, s->last_row);
+ }
+ s->y++;
+ if (s->y == s->height) {
+ for(;;) {
+ if (s->pass == NB_PASSES - 1) {
+ s->state |= PNG_ALLIMAGE;
+ goto the_end;
+ } else {
+ s->pass++;
+ s->y = 0;
+ s->pass_row_size = png_pass_row_size(s->pass,
+ s->bits_per_pixel,
+ s->width);
+ s->crow_size = s->pass_row_size + 1;
+ if (s->pass_row_size != 0)
+ break;
+ /* skip pass if empty row */
+ }
+ }
+ }
+ }
+ the_end: ;
+ }
+}
+
+static int png_decode_idat(PNGContext *s, int length)
+{
+ int ret;
+ s->zstream.avail_in = length;
+ s->zstream.next_in = s->bytestream;
+ s->bytestream += length;
+
+ if(s->bytestream > s->bytestream_end)
+ return -1;
+
+ /* decode one line if possible */
+ while (s->zstream.avail_in > 0) {
+ ret = inflate(&s->zstream, Z_PARTIAL_FLUSH);
+ if (ret != Z_OK && ret != Z_STREAM_END) {
+ return -1;
+ }
+ if (s->zstream.avail_out == 0) {
+ if (!(s->state & PNG_ALLIMAGE)) {
+ png_handle_row(s);
+ }
+ s->zstream.avail_out = s->crow_size;
+ s->zstream.next_out = s->crow_buf;
+ }
+ }
+ return 0;
+}
+
+static int decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ PNGContext * const s = avctx->priv_data;
+ AVFrame *picture = data;
+ AVFrame * const p= (AVFrame*)&s->picture;
+ uint32_t tag, length;
+ int ret, crc;
+
+ s->bytestream_start=
+ s->bytestream= buf;
+ s->bytestream_end= buf + buf_size;
+
+ /* check signature */
+ if (memcmp(s->bytestream, pngsig, 8) != 0)
+ return -1;
+ s->bytestream+= 8;
+ s->y=
+ s->state=0;
+// memset(s, 0, sizeof(PNGContext));
+ /* init the zlib */
+ s->zstream.zalloc = png_zalloc;
+ s->zstream.zfree = png_zfree;
+ s->zstream.opaque = NULL;
+ ret = inflateInit(&s->zstream);
+ if (ret != Z_OK)
+ return -1;
+ for(;;) {
+ int tag32;
+ if (s->bytestream >= s->bytestream_end)
+ goto fail;
+ length = get32(&s->bytestream);
+ if (length > 0x7fffffff)
+ goto fail;
+ tag32 = get32(&s->bytestream);
+ tag = bswap_32(tag32);
+#ifdef DEBUG
+ av_log(avctx, AV_LOG_DEBUG, "png: tag=%c%c%c%c length=%u\n",
+ (tag & 0xff),
+ ((tag >> 8) & 0xff),
+ ((tag >> 16) & 0xff),
+ ((tag >> 24) & 0xff), length);
+#endif
+ switch(tag) {
+ case MKTAG('I', 'H', 'D', 'R'):
+ if (length != 13)
+ goto fail;
+ s->width = get32(&s->bytestream);
+ s->height = get32(&s->bytestream);
+ if(avcodec_check_dimensions(avctx, s->width, s->height)){
+ s->width= s->height= 0;
+ goto fail;
+ }
+ s->bit_depth = *s->bytestream++;
+ s->color_type = *s->bytestream++;
+ s->compression_type = *s->bytestream++;
+ s->filter_type = *s->bytestream++;
+ s->interlace_type = *s->bytestream++;
+ crc = get32(&s->bytestream);
+ s->state |= PNG_IHDR;
+#ifdef DEBUG
+ av_log(avctx, AV_LOG_DEBUG, "width=%d height=%d depth=%d color_type=%d compression_type=%d filter_type=%d interlace_type=%d\n",
+ s->width, s->height, s->bit_depth, s->color_type,
+ s->compression_type, s->filter_type, s->interlace_type);
+#endif
+ break;
+ case MKTAG('I', 'D', 'A', 'T'):
+ if (!(s->state & PNG_IHDR))
+ goto fail;
+ if (!(s->state & PNG_IDAT)) {
+ /* init image info */
+ avctx->width = s->width;
+ avctx->height = s->height;
+
+ s->channels = png_get_nb_channels(s->color_type);
+ s->bits_per_pixel = s->bit_depth * s->channels;
+ s->bpp = (s->bits_per_pixel + 7) >> 3;
+ s->row_size = (avctx->width * s->bits_per_pixel + 7) >> 3;
+
+ if (s->bit_depth == 8 &&
+ s->color_type == PNG_COLOR_TYPE_RGB) {
+ avctx->pix_fmt = PIX_FMT_RGB24;
+ } else if (s->bit_depth == 8 &&
+ s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
+ avctx->pix_fmt = PIX_FMT_RGB32;
+ } else if (s->bit_depth == 8 &&
+ s->color_type == PNG_COLOR_TYPE_GRAY) {
+ avctx->pix_fmt = PIX_FMT_GRAY8;
+ } else if (s->bit_depth == 16 &&
+ s->color_type == PNG_COLOR_TYPE_GRAY) {
+ avctx->pix_fmt = PIX_FMT_GRAY16BE;
+ } else if (s->bit_depth == 1 &&
+ s->color_type == PNG_COLOR_TYPE_GRAY) {
+ avctx->pix_fmt = PIX_FMT_MONOBLACK;
+ } else if (s->color_type == PNG_COLOR_TYPE_PALETTE) {
+ avctx->pix_fmt = PIX_FMT_PAL8;
+ } else {
+ goto fail;
+ }
+ 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");
+ goto fail;
+ }
+ p->pict_type= FF_I_TYPE;
+ p->key_frame= 1;
+ p->interlaced_frame = !!s->interlace_type;
+
+ /* compute the compressed row size */
+ if (!s->interlace_type) {
+ s->crow_size = s->row_size + 1;
+ } else {
+ s->pass = 0;
+ s->pass_row_size = png_pass_row_size(s->pass,
+ s->bits_per_pixel,
+ s->width);
+ s->crow_size = s->pass_row_size + 1;
+ }
+#ifdef DEBUG
+ av_log(avctx, AV_LOG_DEBUG, "row_size=%d crow_size =%d\n",
+ s->row_size, s->crow_size);
+#endif
+ s->image_buf = p->data[0];
+ s->image_linesize = p->linesize[0];
+ /* copy the palette if needed */
+ if (s->color_type == PNG_COLOR_TYPE_PALETTE)
+ memcpy(p->data[1], s->palette, 256 * sizeof(uint32_t));
+ /* empty row is used if differencing to the first row */
+ s->last_row = av_mallocz(s->row_size);
+ if (!s->last_row)
+ goto fail;
+ if (s->interlace_type ||
+ s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
+ s->tmp_row = av_malloc(s->row_size);
+ if (!s->tmp_row)
+ goto fail;
+ }
+ /* compressed row */
+ s->crow_buf = av_malloc(s->row_size + 1);
+ if (!s->crow_buf)
+ goto fail;
+ s->zstream.avail_out = s->crow_size;
+ s->zstream.next_out = s->crow_buf;
+ }
+ s->state |= PNG_IDAT;
+ if (png_decode_idat(s, length) < 0)
+ goto fail;
+ /* skip crc */
+ crc = get32(&s->bytestream);
+ break;
+ case MKTAG('P', 'L', 'T', 'E'):
+ {
+ int n, i, r, g, b;
+
+ if ((length % 3) != 0 || length > 256 * 3)
+ goto skip_tag;
+ /* read the palette */
+ n = length / 3;
+ for(i=0;i<n;i++) {
+ r = *s->bytestream++;
+ g = *s->bytestream++;
+ b = *s->bytestream++;
+ s->palette[i] = (0xff << 24) | (r << 16) | (g << 8) | b;
+ }
+ for(;i<256;i++) {
+ s->palette[i] = (0xff << 24);
+ }
+ s->state |= PNG_PLTE;
+ crc = get32(&s->bytestream);
+ }
+ break;
+ case MKTAG('t', 'R', 'N', 'S'):
+ {
+ int v, i;
+
+ /* read the transparency. XXX: Only palette mode supported */
+ if (s->color_type != PNG_COLOR_TYPE_PALETTE ||
+ length > 256 ||
+ !(s->state & PNG_PLTE))
+ goto skip_tag;
+ for(i=0;i<length;i++) {
+ v = *s->bytestream++;
+ s->palette[i] = (s->palette[i] & 0x00ffffff) | (v << 24);
+ }
+ crc = get32(&s->bytestream);
+ }
+ break;
+ case MKTAG('I', 'E', 'N', 'D'):
+ if (!(s->state & PNG_ALLIMAGE))
+ goto fail;
+ crc = get32(&s->bytestream);
+ goto exit_loop;
+ default:
+ /* skip tag */
+ skip_tag:
+ s->bytestream += length + 4;
+ break;
+ }
+ }
+ exit_loop:
+ *picture= *(AVFrame*)&s->picture;
+ *data_size = sizeof(AVPicture);
+
+ ret = s->bytestream - s->bytestream_start;
+ the_end:
+ inflateEnd(&s->zstream);
+ av_freep(&s->crow_buf);
+ av_freep(&s->last_row);
+ av_freep(&s->tmp_row);
+ return ret;
+ fail:
+ ret = -1;
+ goto the_end;
+}
+#endif
+
+#ifdef CONFIG_ENCODERS
+static void png_write_chunk(uint8_t **f, uint32_t tag,
+ const uint8_t *buf, int length)
+{
+ uint32_t crc;
+ uint8_t tagbuf[4];
+
+ put32(f, length);
+ crc = crc32(0, Z_NULL, 0);
+ tagbuf[0] = tag;
+ tagbuf[1] = tag >> 8;
+ tagbuf[2] = tag >> 16;
+ tagbuf[3] = tag >> 24;
+ crc = crc32(crc, tagbuf, 4);
+ put32(f, bswap_32(tag));
+ if (length > 0) {
+ crc = crc32(crc, buf, length);
+ memcpy(*f, buf, length);
+ *f += length;
+ }
+ put32(f, crc);
+}
+
+/* XXX: use avcodec generic function ? */
+static void to_be32(uint8_t *p, uint32_t v)
+{
+ p[0] = v >> 24;
+ p[1] = v >> 16;
+ p[2] = v >> 8;
+ p[3] = v;
+}
+
+/* XXX: do filtering */
+static int png_write_row(PNGContext *s, const uint8_t *data, int size)
+{
+ int ret;
+
+ s->zstream.avail_in = size;
+ s->zstream.next_in = (uint8_t *)data;
+ while (s->zstream.avail_in > 0) {
+ ret = deflate(&s->zstream, Z_NO_FLUSH);
+ if (ret != Z_OK)
+ return -1;
+ if (s->zstream.avail_out == 0) {
+ if(s->bytestream_end - s->bytestream > IOBUF_SIZE + 100)
+ png_write_chunk(&s->bytestream, MKTAG('I', 'D', 'A', 'T'), s->buf, IOBUF_SIZE);
+ s->zstream.avail_out = IOBUF_SIZE;
+ s->zstream.next_out = s->buf;
+ }
+ }
+ return 0;
+}
+#endif /* CONFIG_ENCODERS */
+
+static int common_init(AVCodecContext *avctx){
+ PNGContext *s = avctx->priv_data;
+
+ avcodec_get_frame_defaults((AVFrame*)&s->picture);
+ avctx->coded_frame= (AVFrame*)&s->picture;
+// s->avctx= avctx;
+
+ return 0;
+}
+
+#ifdef CONFIG_ENCODERS
+static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
+ PNGContext *s = avctx->priv_data;
+ AVFrame *pict = data;
+ AVFrame * const p= (AVFrame*)&s->picture;
+ int bit_depth, color_type, y, len, row_size, ret, is_progressive;
+ int bits_per_pixel, pass_row_size;
+ uint8_t *ptr;
+ uint8_t *crow_buf = NULL;
+ uint8_t *tmp_buf = NULL;
+
+ *p = *pict;
+ p->pict_type= FF_I_TYPE;
+ p->key_frame= 1;
+
+ s->bytestream_start=
+ s->bytestream= buf;
+ s->bytestream_end= buf+buf_size;
+
+ is_progressive = !!(avctx->flags & CODEC_FLAG_INTERLACED_DCT);
+ switch(avctx->pix_fmt) {
+ case PIX_FMT_RGB32:
+ bit_depth = 8;
+ color_type = PNG_COLOR_TYPE_RGB_ALPHA;
+ break;
+ case PIX_FMT_RGB24:
+ bit_depth = 8;
+ color_type = PNG_COLOR_TYPE_RGB;
+ break;
+ case PIX_FMT_GRAY8:
+ bit_depth = 8;
+ color_type = PNG_COLOR_TYPE_GRAY;
+ break;
+ case PIX_FMT_MONOBLACK:
+ bit_depth = 1;
+ color_type = PNG_COLOR_TYPE_GRAY;
+ break;
+ case PIX_FMT_PAL8:
+ bit_depth = 8;
+ color_type = PNG_COLOR_TYPE_PALETTE;
+ break;
+ default:
+ return -1;
+ }
+ bits_per_pixel = png_get_nb_channels(color_type) * bit_depth;
+ row_size = (avctx->width * bits_per_pixel + 7) >> 3;
+
+ s->zstream.zalloc = png_zalloc;
+ s->zstream.zfree = png_zfree;
+ s->zstream.opaque = NULL;
+ ret = deflateInit2(&s->zstream, Z_DEFAULT_COMPRESSION,
+ Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY);
+ if (ret != Z_OK)
+ return -1;
+ crow_buf = av_malloc(row_size + 1);
+ if (!crow_buf)
+ goto fail;
+ if (is_progressive) {
+ tmp_buf = av_malloc(row_size + 1);
+ if (!tmp_buf)
+ goto fail;
+ }
+
+ /* write png header */
+ memcpy(s->bytestream, pngsig, 8);
+ s->bytestream += 8;
+
+ to_be32(s->buf, avctx->width);
+ to_be32(s->buf + 4, avctx->height);
+ s->buf[8] = bit_depth;
+ s->buf[9] = color_type;
+ s->buf[10] = 0; /* compression type */
+ s->buf[11] = 0; /* filter type */
+ s->buf[12] = is_progressive; /* interlace type */
+
+ png_write_chunk(&s->bytestream, MKTAG('I', 'H', 'D', 'R'), s->buf, 13);
+
+ /* put the palette if needed */
+ if (color_type == PNG_COLOR_TYPE_PALETTE) {
+ int has_alpha, alpha, i;
+ unsigned int v;
+ uint32_t *palette;
+ uint8_t *alpha_ptr;
+
+ palette = (uint32_t *)p->data[1];
+ ptr = s->buf;
+ alpha_ptr = s->buf + 256 * 3;
+ has_alpha = 0;
+ for(i = 0; i < 256; i++) {
+ v = palette[i];
+ alpha = v >> 24;
+ if (alpha && alpha != 0xff)
+ has_alpha = 1;
+ *alpha_ptr++ = alpha;
+ ptr[0] = v >> 16;
+ ptr[1] = v >> 8;
+ ptr[2] = v;
+ ptr += 3;
+ }
+ png_write_chunk(&s->bytestream, MKTAG('P', 'L', 'T', 'E'), s->buf, 256 * 3);
+ if (has_alpha) {
+ png_write_chunk(&s->bytestream, MKTAG('t', 'R', 'N', 'S'), s->buf + 256 * 3, 256);
+ }
+ }
+
+ /* now put each row */
+ s->zstream.avail_out = IOBUF_SIZE;
+ s->zstream.next_out = s->buf;
+ if (is_progressive) {
+ uint8_t *ptr1;
+ int pass;
+
+ for(pass = 0; pass < NB_PASSES; pass++) {
+ /* NOTE: a pass is completely omited if no pixels would be
+ output */
+ pass_row_size = png_pass_row_size(pass, bits_per_pixel, avctx->width);
+ if (pass_row_size > 0) {
+ for(y = 0; y < avctx->height; y++) {
+ if ((png_pass_ymask[pass] << (y & 7)) & 0x80) {
+ ptr = p->data[0] + y * p->linesize[0];
+ if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
+ convert_from_rgb32(tmp_buf, ptr, avctx->width);
+ ptr1 = tmp_buf;
+ } else {
+ ptr1 = ptr;
+ }
+ png_get_interlaced_row(crow_buf + 1, pass_row_size,
+ bits_per_pixel, pass,
+ ptr1, avctx->width);
+ crow_buf[0] = PNG_FILTER_VALUE_NONE;
+ png_write_row(s, crow_buf, pass_row_size + 1);
+ }
+ }
+ }
+ }
+ } else {
+ for(y = 0; y < avctx->height; y++) {
+ ptr = p->data[0] + y * p->linesize[0];
+ if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+ convert_from_rgb32(crow_buf + 1, ptr, avctx->width);
+ else
+ memcpy(crow_buf + 1, ptr, row_size);
+ crow_buf[0] = PNG_FILTER_VALUE_NONE;
+ png_write_row(s, crow_buf, row_size + 1);
+ }
+ }
+ /* compress last bytes */
+ for(;;) {
+ ret = deflate(&s->zstream, Z_FINISH);
+ if (ret == Z_OK || ret == Z_STREAM_END) {
+ len = IOBUF_SIZE - s->zstream.avail_out;
+ if (len > 0 && s->bytestream_end - s->bytestream > len + 100) {
+ png_write_chunk(&s->bytestream, MKTAG('I', 'D', 'A', 'T'), s->buf, len);
+ }
+ s->zstream.avail_out = IOBUF_SIZE;
+ s->zstream.next_out = s->buf;
+ if (ret == Z_STREAM_END)
+ break;
+ } else {
+ goto fail;
+ }
+ }
+ png_write_chunk(&s->bytestream, MKTAG('I', 'E', 'N', 'D'), NULL, 0);
+
+ ret = s->bytestream - s->bytestream_start;
+ the_end:
+ av_free(crow_buf);
+ av_free(tmp_buf);
+ deflateEnd(&s->zstream);
+ return ret;
+ fail:
+ ret = -1;
+ goto the_end;
+}
+#endif
+
+#ifdef CONFIG_PNG_DECODER
+AVCodec png_decoder = {
+ "png",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_PNG,
+ sizeof(PNGContext),
+ common_init,
+ NULL,
+ NULL, //decode_end,
+ decode_frame,
+ 0 /*CODEC_CAP_DR1*/ /*| CODEC_CAP_DRAW_HORIZ_BAND*/,
+ NULL
+};
+#endif
+
+#ifdef CONFIG_PNG_ENCODER
+AVCodec png_encoder = {
+ "png",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_PNG,
+ sizeof(PNGContext),
+ common_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, -1},
+};
+#endif // CONFIG_PNG_ENCODER
diff --git a/contrib/ffmpeg/libavcodec/pnm.c b/contrib/ffmpeg/libavcodec/pnm.c
new file mode 100644
index 000000000..4c9c46fee
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/pnm.c
@@ -0,0 +1,606 @@
+/*
+ * 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 "parser.h" //for ParseContext
+
+typedef struct PNMContext {
+ uint8_t *bytestream;
+ uint8_t *bytestream_start;
+ uint8_t *bytestream_end;
+ AVFrame picture;
+} PNMContext;
+
+static inline int pnm_space(int c)
+{
+ return (c == ' ' || c == '\n' || c == '\r' || c == '\t');
+}
+
+static void pnm_get(PNMContext *sc, char *str, int buf_size)
+{
+ char *s;
+ int c;
+
+ /* skip spaces and comments */
+ for(;;) {
+ c = *sc->bytestream++;
+ if (c == '#') {
+ do {
+ c = *sc->bytestream++;
+ } while (c != '\n' && sc->bytestream < sc->bytestream_end);
+ } else if (!pnm_space(c)) {
+ break;
+ }
+ }
+
+ s = str;
+ while (sc->bytestream < sc->bytestream_end && !pnm_space(c)) {
+ if ((s - str) < buf_size - 1)
+ *s++ = c;
+ c = *sc->bytestream++;
+ }
+ *s = '\0';
+}
+
+static 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_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")) {
+ avctx->pix_fmt = PIX_FMT_MONOWHITE;
+ } else if (!strcmp(buf1, "P5")) {
+ 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")) {
+ avctx->pix_fmt = PIX_FMT_RGB24;
+ } else if (!strcmp(buf1, "P7")) {
+ w = -1;
+ h = -1;
+ maxval = -1;
+ depth = -1;
+ tuple_type[0] = '\0';
+ for(;;) {
+ pnm_get(s, buf1, sizeof(buf1));
+ if (!strcmp(buf1, "WIDTH")) {
+ pnm_get(s, buf1, sizeof(buf1));
+ w = strtol(buf1, NULL, 10);
+ } else if (!strcmp(buf1, "HEIGHT")) {
+ pnm_get(s, buf1, sizeof(buf1));
+ h = strtol(buf1, NULL, 10);
+ } else if (!strcmp(buf1, "DEPTH")) {
+ pnm_get(s, buf1, sizeof(buf1));
+ depth = strtol(buf1, NULL, 10);
+ } else if (!strcmp(buf1, "MAXVAL")) {
+ pnm_get(s, buf1, sizeof(buf1));
+ maxval = strtol(buf1, NULL, 10);
+ } else if (!strcmp(buf1, "TUPLETYPE")) {
+ pnm_get(s, tuple_type, sizeof(tuple_type));
+ } else if (!strcmp(buf1, "ENDHDR")) {
+ break;
+ } else {
+ return -1;
+ }
+ }
+ /* check that all tags are present */
+ 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->height = h;
+ if (depth == 1) {
+ if (maxval == 1)
+ avctx->pix_fmt = PIX_FMT_MONOWHITE;
+ else
+ avctx->pix_fmt = PIX_FMT_GRAY8;
+ } else if (depth == 3) {
+ avctx->pix_fmt = PIX_FMT_RGB24;
+ } else if (depth == 4) {
+ avctx->pix_fmt = PIX_FMT_RGB32;
+ } else {
+ return -1;
+ }
+ return 0;
+ } else {
+ return -1;
+ }
+ pnm_get(s, buf1, sizeof(buf1));
+ avctx->width = atoi(buf1);
+ if (avctx->width <= 0)
+ return -1;
+ pnm_get(s, buf1, sizeof(buf1));
+ avctx->height = atoi(buf1);
+ if(avcodec_check_dimensions(avctx, avctx->width, avctx->height))
+ return -1;
+ if (avctx->pix_fmt != PIX_FMT_MONOWHITE) {
+ pnm_get(s, buf1, sizeof(buf1));
+ if(atoi(buf1) == 65535 && avctx->pix_fmt == PIX_FMT_GRAY8)
+ avctx->pix_fmt = PIX_FMT_GRAY16BE;
+ }
+ /* more check if YUV420 */
+ if (avctx->pix_fmt == PIX_FMT_YUV420P) {
+ if ((avctx->width & 1) != 0)
+ return -1;
+ h = (avctx->height * 2);
+ if ((h % 3) != 0)
+ return -1;
+ h /= 3;
+ avctx->height = h;
+ }
+ return 0;
+}
+
+static int pnm_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ PNMContext * const s = avctx->priv_data;
+ AVFrame *picture = data;
+ AVFrame * const p= (AVFrame*)&s->picture;
+ int i, n, linesize, h;
+ unsigned char *ptr;
+
+ s->bytestream_start=
+ s->bytestream= buf;
+ s->bytestream_end= buf + buf_size;
+
+ if(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_RGB24:
+ n = avctx->width * 3;
+ goto do_read;
+ case PIX_FMT_GRAY8:
+ n = avctx->width;
+ goto do_read;
+ case PIX_FMT_GRAY16BE:
+ n = avctx->width * 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++) {
+ memcpy(ptr, s->bytestream, n);
+ 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;
+ 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){
+ 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;
+ h1 = h;
+ switch(avctx->pix_fmt) {
+ case PIX_FMT_MONOWHITE:
+ c = '4';
+ n = (avctx->width + 7) >> 3;
+ break;
+ case PIX_FMT_GRAY8:
+ c = '5';
+ n = avctx->width;
+ break;
+ case PIX_FMT_GRAY16BE:
+ c = '5';
+ n = avctx->width * 2;
+ break;
+ case PIX_FMT_RGB24:
+ c = '6';
+ n = avctx->width * 3;
+ break;
+ case PIX_FMT_YUV420P:
+ 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);
+ s->bytestream += strlen(s->bytestream);
+ if (avctx->pix_fmt != PIX_FMT_MONOWHITE) {
+ snprintf(s->bytestream, s->bytestream_end - s->bytestream,
+ "%d\n", (avctx->pix_fmt != PIX_FMT_GRAY16BE) ? 255 : 65535);
+ s->bytestream += strlen(s->bytestream);
+ }
+
+ ptr = p->data[0];
+ linesize = p->linesize[0];
+ for(i=0;i<h;i++) {
+ memcpy(s->bytestream, ptr, n);
+ s->bytestream += n;
+ ptr += linesize;
+ }
+
+ if (avctx->pix_fmt == PIX_FMT_YUV420P) {
+ h >>= 1;
+ n >>= 1;
+ ptr1 = p->data[1];
+ ptr2 = p->data[2];
+ for(i=0;i<h;i++) {
+ memcpy(s->bytestream, ptr1, n);
+ s->bytestream += n;
+ memcpy(s->bytestream, ptr2, n);
+ s->bytestream += n;
+ ptr1 += p->linesize[1];
+ ptr2 += p->linesize[2];
+ }
+ }
+ 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;i<h;i++) {
+ for(j=0;j<w;j++) {
+ v = ((uint32_t *)ptr)[j];
+ *s->bytestream++ = v >> 16;
+ *s->bytestream++ = v >> 8;
+ *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;
+}
+
+#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
+
+#ifdef CONFIG_PNM_PARSER
+static int pnm_parse(AVCodecParserContext *s,
+ AVCodecContext *avctx,
+ 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--){
+ 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(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){
+ memcpy(pc->buffer + pc->index, buf, pc->index);
+ pc->index += 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;
+ }
+
+ if(ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size)<0){
+ *poutbuf = NULL;
+ *poutbuf_size = 0;
+ return buf_size;
+ }
+ *poutbuf = (uint8_t *)buf;
+ *poutbuf_size = buf_size;
+ return next;
+}
+
+AVCodecParser pnm_parser = {
+ { CODEC_ID_PGM, CODEC_ID_PGMYUV, CODEC_ID_PPM, CODEC_ID_PBM, CODEC_ID_PAM},
+ sizeof(ParseContext),
+ NULL,
+ pnm_parse,
+ ff_parse_close,
+};
+#endif /* CONFIG_PNM_PARSER */
+
+#ifdef CONFIG_PGM_ENCODER
+AVCodec pgm_encoder = {
+ "pgm",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_PGM,
+ sizeof(PNMContext),
+ common_init,
+ pnm_encode_frame,
+ NULL, //encode_end,
+ pnm_decode_frame,
+ .pix_fmts= (enum PixelFormat[]){PIX_FMT_GRAY8, PIX_FMT_GRAY16BE, -1},
+};
+#endif // CONFIG_PGM_ENCODER
+
+#ifdef CONFIG_PGMYUV_ENCODER
+AVCodec pgmyuv_encoder = {
+ "pgmyuv",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_PGMYUV,
+ sizeof(PNMContext),
+ common_init,
+ pnm_encode_frame,
+ NULL, //encode_end,
+ pnm_decode_frame,
+ .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1},
+};
+#endif // CONFIG_PGMYUV_ENCODER
+
+#ifdef CONFIG_PPM_ENCODER
+AVCodec ppm_encoder = {
+ "ppm",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_PPM,
+ sizeof(PNMContext),
+ common_init,
+ pnm_encode_frame,
+ NULL, //encode_end,
+ pnm_decode_frame,
+ .pix_fmts= (enum PixelFormat[]){PIX_FMT_RGB24, -1},
+};
+#endif // CONFIG_PPM_ENCODER
+
+#ifdef CONFIG_PBM_ENCODER
+AVCodec pbm_encoder = {
+ "pbm",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_PBM,
+ sizeof(PNMContext),
+ common_init,
+ pnm_encode_frame,
+ NULL, //encode_end,
+ pnm_decode_frame,
+ .pix_fmts= (enum PixelFormat[]){PIX_FMT_MONOWHITE, -1},
+};
+#endif // CONFIG_PBM_ENCODER
+
+#ifdef CONFIG_PAM_ENCODER
+AVCodec pam_encoder = {
+ "pam",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_PAM,
+ sizeof(PNMContext),
+ common_init,
+ pam_encode_frame,
+ NULL, //encode_end,
+ pnm_decode_frame,
+ .pix_fmts= (enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB32, PIX_FMT_GRAY8, PIX_FMT_MONOWHITE, -1},
+};
+#endif // CONFIG_PAM_ENCODER
diff --git a/src/libffmpeg/libavcodec/ppc/dsputil_altivec.c b/contrib/ffmpeg/libavcodec/ppc/dsputil_altivec.c
index bbc53d761..bbc53d761 100644
--- a/src/libffmpeg/libavcodec/ppc/dsputil_altivec.c
+++ b/contrib/ffmpeg/libavcodec/ppc/dsputil_altivec.c
diff --git a/src/libffmpeg/libavcodec/ppc/dsputil_altivec.h b/contrib/ffmpeg/libavcodec/ppc/dsputil_altivec.h
index 560d778bb..560d778bb 100644
--- a/src/libffmpeg/libavcodec/ppc/dsputil_altivec.h
+++ b/contrib/ffmpeg/libavcodec/ppc/dsputil_altivec.h
diff --git a/contrib/ffmpeg/libavcodec/ppc/dsputil_ppc.c b/contrib/ffmpeg/libavcodec/ppc/dsputil_ppc.c
new file mode 100644
index 000000000..117a7adf1
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/ppc/dsputil_ppc.c
@@ -0,0 +1,325 @@
+/*
+ * Copyright (c) 2002 Brian Foley
+ * Copyright (c) 2002 Dieter Shirley
+ * Copyright (c) 2003-2004 Romain Dolbeau <romain@dolbeau.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "../dsputil.h"
+
+#include "dsputil_ppc.h"
+
+#ifdef HAVE_ALTIVEC
+#include "dsputil_altivec.h"
+
+extern void fdct_altivec(int16_t *block);
+extern void gmc1_altivec(uint8_t *dst, uint8_t *src, int stride, int h,
+ int x16, int y16, int rounder);
+extern void idct_put_altivec(uint8_t *dest, int line_size, int16_t *block);
+extern void idct_add_altivec(uint8_t *dest, int line_size, int16_t *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 snow_init_altivec(DSPContext* c, AVCodecContext *avctx);
+void float_init_altivec(DSPContext* c, AVCodecContext *avctx);
+
+#endif
+
+int mm_flags = 0;
+
+int mm_support(void)
+{
+ int result = 0;
+#ifdef HAVE_ALTIVEC
+ if (has_altivec()) {
+ result |= MM_ALTIVEC;
+ }
+#endif /* result */
+ return result;
+}
+
+#ifdef CONFIG_POWERPC_PERF
+unsigned long long perfdata[POWERPC_NUM_PMC_ENABLED][powerpc_perf_total][powerpc_data_total];
+/* list below must match enum in dsputil_ppc.h */
+static unsigned char* perfname[] = {
+ "ff_fft_calc_altivec",
+ "gmc1_altivec",
+ "dct_unquantize_h263_altivec",
+ "fdct_altivec",
+ "idct_add_altivec",
+ "idct_put_altivec",
+ "put_pixels16_altivec",
+ "avg_pixels16_altivec",
+ "avg_pixels8_altivec",
+ "put_pixels8_xy2_altivec",
+ "put_no_rnd_pixels8_xy2_altivec",
+ "put_pixels16_xy2_altivec",
+ "put_no_rnd_pixels16_xy2_altivec",
+ "hadamard8_diff8x8_altivec",
+ "hadamard8_diff16_altivec",
+ "avg_pixels8_xy2_altivec",
+ "clear_blocks_dcbz32_ppc",
+ "clear_blocks_dcbz128_ppc",
+ "put_h264_chroma_mc8_altivec",
+ "avg_h264_chroma_mc8_altivec",
+ "put_h264_qpel16_h_lowpass_altivec",
+ "avg_h264_qpel16_h_lowpass_altivec",
+ "put_h264_qpel16_v_lowpass_altivec",
+ "avg_h264_qpel16_v_lowpass_altivec",
+ "put_h264_qpel16_hv_lowpass_altivec",
+ "avg_h264_qpel16_hv_lowpass_altivec",
+ ""
+};
+#include <stdio.h>
+#endif
+
+#ifdef CONFIG_POWERPC_PERF
+void powerpc_display_perf_report(void)
+{
+ int i, j;
+ av_log(NULL, AV_LOG_INFO, "PowerPC performance report\n Values are from the PMC registers, and represent whatever the registers are set to record.\n");
+ for(i = 0 ; i < powerpc_perf_total ; i++)
+ {
+ for (j = 0; j < POWERPC_NUM_PMC_ENABLED ; j++)
+ {
+ if (perfdata[j][i][powerpc_data_num] != (unsigned long long)0)
+ av_log(NULL, AV_LOG_INFO,
+ " Function \"%s\" (pmc%d):\n\tmin: %"PRIu64"\n\tmax: %"PRIu64"\n\tavg: %1.2lf (%"PRIu64")\n",
+ perfname[i],
+ j+1,
+ perfdata[j][i][powerpc_data_min],
+ perfdata[j][i][powerpc_data_max],
+ (double)perfdata[j][i][powerpc_data_sum] /
+ (double)perfdata[j][i][powerpc_data_num],
+ perfdata[j][i][powerpc_data_num]);
+ }
+ }
+}
+#endif /* CONFIG_POWERPC_PERF */
+
+/* ***** WARNING ***** WARNING ***** WARNING ***** */
+/*
+ clear_blocks_dcbz32_ppc will not work properly
+ on PowerPC processors with a cache line size
+ not equal to 32 bytes.
+ Fortunately all processor used by Apple up to
+ at least the 7450 (aka second generation G4)
+ use 32 bytes cache line.
+ This is due to the use of the 'dcbz' instruction.
+ It simply clear to zero a single cache line,
+ so you need to know the cache line size to use it !
+ It's absurd, but it's fast...
+
+ update 24/06/2003 : Apple released yesterday the G5,
+ with a PPC970. cache line size : 128 bytes. Oups.
+ The semantic of dcbz was changed, it always clear
+ 32 bytes. so the function below will work, but will
+ be slow. So I fixed check_dcbz_effect to use dcbzl,
+ which is defined to clear a cache line (as dcbz before).
+ So we still can distinguish, and use dcbz (32 bytes)
+ or dcbzl (one cache line) as required.
+
+ see <http://developer.apple.com/technotes/tn/tn2087.html>
+ and <http://developer.apple.com/technotes/tn/tn2086.html>
+*/
+void clear_blocks_dcbz32_ppc(DCTELEM *blocks)
+{
+POWERPC_PERF_DECLARE(powerpc_clear_blocks_dcbz32, 1);
+ register int misal = ((unsigned long)blocks & 0x00000010);
+ register int i = 0;
+POWERPC_PERF_START_COUNT(powerpc_clear_blocks_dcbz32, 1);
+#if 1
+ if (misal) {
+ ((unsigned long*)blocks)[0] = 0L;
+ ((unsigned long*)blocks)[1] = 0L;
+ ((unsigned long*)blocks)[2] = 0L;
+ ((unsigned long*)blocks)[3] = 0L;
+ i += 16;
+ }
+ for ( ; i < sizeof(DCTELEM)*6*64-31 ; i += 32) {
+#ifndef __MWERKS__
+ asm volatile("dcbz %0,%1" : : "b" (blocks), "r" (i) : "memory");
+#else
+ __dcbz( blocks, i );
+#endif
+ }
+ if (misal) {
+ ((unsigned long*)blocks)[188] = 0L;
+ ((unsigned long*)blocks)[189] = 0L;
+ ((unsigned long*)blocks)[190] = 0L;
+ ((unsigned long*)blocks)[191] = 0L;
+ i += 16;
+ }
+#else
+ memset(blocks, 0, sizeof(DCTELEM)*6*64);
+#endif
+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 */
+#ifdef HAVE_DCBZL
+void clear_blocks_dcbz128_ppc(DCTELEM *blocks)
+{
+POWERPC_PERF_DECLARE(powerpc_clear_blocks_dcbz128, 1);
+ register int misal = ((unsigned long)blocks & 0x0000007f);
+ register int i = 0;
+POWERPC_PERF_START_COUNT(powerpc_clear_blocks_dcbz128, 1);
+#if 1
+ if (misal) {
+ // we could probably also optimize this case,
+ // but there's not much point as the machines
+ // aren't available yet (2003-06-26)
+ memset(blocks, 0, sizeof(DCTELEM)*6*64);
+ }
+ else
+ for ( ; i < sizeof(DCTELEM)*6*64 ; i += 128) {
+ asm volatile("dcbzl %0,%1" : : "b" (blocks), "r" (i) : "memory");
+ }
+#else
+ memset(blocks, 0, sizeof(DCTELEM)*6*64);
+#endif
+POWERPC_PERF_STOP_COUNT(powerpc_clear_blocks_dcbz128, 1);
+}
+#else
+void clear_blocks_dcbz128_ppc(DCTELEM *blocks)
+{
+ memset(blocks, 0, sizeof(DCTELEM)*6*64);
+}
+#endif
+
+#ifdef HAVE_DCBZL
+/* check dcbz report how many bytes are set to 0 by dcbz */
+/* update 24/06/2003 : replace dcbz by dcbzl to get
+ the intended effect (Apple "fixed" dcbz)
+ unfortunately this cannot be used unless the assembler
+ knows about dcbzl ... */
+long check_dcbzl_effect(void)
+{
+ register char *fakedata = (char*)av_malloc(1024);
+ register char *fakedata_middle;
+ register long zero = 0;
+ register long i = 0;
+ long count = 0;
+
+ if (!fakedata)
+ {
+ return 0L;
+ }
+
+ fakedata_middle = (fakedata + 512);
+
+ memset(fakedata, 0xFF, 1024);
+
+ /* below the constraint "b" seems to mean "Address base register"
+ in gcc-3.3 / RS/6000 speaks. seems to avoid using r0, so.... */
+ asm volatile("dcbzl %0, %1" : : "b" (fakedata_middle), "r" (zero));
+
+ for (i = 0; i < 1024 ; i ++)
+ {
+ if (fakedata[i] == (char)0)
+ count++;
+ }
+
+ av_free(fakedata);
+
+ return count;
+}
+#else
+long check_dcbzl_effect(void)
+{
+ return 0;
+}
+#endif
+
+static void prefetch_ppc(void *mem, int stride, int h)
+{
+ register const uint8_t *p = mem;
+ do {
+ asm volatile ("dcbt 0,%0" : : "r" (p));
+ p+= stride;
+ } while(--h);
+}
+
+void dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx)
+{
+ // Common optimizations whether Altivec is available or not
+ c->prefetch = prefetch_ppc;
+ switch (check_dcbzl_effect()) {
+ case 32:
+ c->clear_blocks = clear_blocks_dcbz32_ppc;
+ break;
+ case 128:
+ c->clear_blocks = clear_blocks_dcbz128_ppc;
+ break;
+ default:
+ break;
+ }
+
+#ifdef HAVE_ALTIVEC
+ if(ENABLE_H264_DECODER) dsputil_h264_init_ppc(c, avctx);
+
+ if (has_altivec()) {
+ mm_flags |= MM_ALTIVEC;
+
+ dsputil_init_altivec(c, avctx);
+ if(ENABLE_SNOW_DECODER) snow_init_altivec(c, avctx);
+ if(ENABLE_VC1_DECODER || ENABLE_WMV3_DECODER)
+ vc1dsp_init_altivec(c, avctx);
+ float_init_altivec(c, avctx);
+ c->gmc1 = gmc1_altivec;
+
+#ifdef CONFIG_ENCODERS
+ if (avctx->dct_algo == FF_DCT_AUTO ||
+ avctx->dct_algo == FF_DCT_ALTIVEC)
+ {
+ c->fdct = fdct_altivec;
+ }
+#endif //CONFIG_ENCODERS
+
+ if (avctx->lowres==0)
+ {
+ if ((avctx->idct_algo == FF_IDCT_AUTO) ||
+ (avctx->idct_algo == FF_IDCT_ALTIVEC))
+ {
+ c->idct_put = idct_put_altivec;
+ c->idct_add = idct_add_altivec;
+ c->idct_permutation_type = FF_TRANSPOSE_IDCT_PERM;
+ }
+ }
+
+#ifdef CONFIG_POWERPC_PERF
+ {
+ int i, j;
+ for (i = 0 ; i < powerpc_perf_total ; i++)
+ {
+ for (j = 0; j < POWERPC_NUM_PMC_ENABLED ; j++)
+ {
+ perfdata[j][i][powerpc_data_min] = 0xFFFFFFFFFFFFFFFFULL;
+ perfdata[j][i][powerpc_data_max] = 0x0000000000000000ULL;
+ perfdata[j][i][powerpc_data_sum] = 0x0000000000000000ULL;
+ perfdata[j][i][powerpc_data_num] = 0x0000000000000000ULL;
+ }
+ }
+ }
+#endif /* CONFIG_POWERPC_PERF */
+ }
+#endif /* HAVE_ALTIVEC */
+}
diff --git a/contrib/ffmpeg/libavcodec/ppc/dsputil_ppc.h b/contrib/ffmpeg/libavcodec/ppc/dsputil_ppc.h
new file mode 100644
index 000000000..5b25732b2
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/ppc/dsputil_ppc.h
@@ -0,0 +1,155 @@
+/*
+ * Copyright (c) 2003-2004 Romain Dolbeau <romain@dolbeau.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef _DSPUTIL_PPC_
+#define _DSPUTIL_PPC_
+
+#ifdef CONFIG_POWERPC_PERF
+void powerpc_display_perf_report(void);
+/* the 604* have 2, the G3* have 4, the G4s have 6,
+ and the G5 are completely different (they MUST use
+ POWERPC_MODE_64BITS, and let's hope all future 64 bis PPC
+ will use the same PMCs... */
+#define POWERPC_NUM_PMC_ENABLED 6
+/* if you add to the enum below, also add to the perfname array
+ in dsputil_ppc.c */
+enum powerpc_perf_index {
+ altivec_fft_num = 0,
+ altivec_gmc1_num,
+ altivec_dct_unquantize_h263_num,
+ altivec_fdct,
+ altivec_idct_add_num,
+ altivec_idct_put_num,
+ altivec_put_pixels16_num,
+ altivec_avg_pixels16_num,
+ altivec_avg_pixels8_num,
+ altivec_put_pixels8_xy2_num,
+ altivec_put_no_rnd_pixels8_xy2_num,
+ altivec_put_pixels16_xy2_num,
+ altivec_put_no_rnd_pixels16_xy2_num,
+ altivec_hadamard8_diff8x8_num,
+ altivec_hadamard8_diff16_num,
+ altivec_avg_pixels8_xy2_num,
+ powerpc_clear_blocks_dcbz32,
+ powerpc_clear_blocks_dcbz128,
+ altivec_put_h264_chroma_mc8_num,
+ altivec_avg_h264_chroma_mc8_num,
+ altivec_put_h264_qpel16_h_lowpass_num,
+ altivec_avg_h264_qpel16_h_lowpass_num,
+ altivec_put_h264_qpel16_v_lowpass_num,
+ altivec_avg_h264_qpel16_v_lowpass_num,
+ altivec_put_h264_qpel16_hv_lowpass_num,
+ altivec_avg_h264_qpel16_hv_lowpass_num,
+ powerpc_perf_total
+};
+enum powerpc_data_index {
+ powerpc_data_min = 0,
+ powerpc_data_max,
+ powerpc_data_sum,
+ powerpc_data_num,
+ powerpc_data_total
+};
+extern unsigned long long perfdata[POWERPC_NUM_PMC_ENABLED][powerpc_perf_total][powerpc_data_total];
+
+#ifndef POWERPC_MODE_64BITS
+#define POWERP_PMC_DATATYPE unsigned long
+#define POWERPC_GET_PMC1(a) asm volatile("mfspr %0, 937" : "=r" (a))
+#define POWERPC_GET_PMC2(a) asm volatile("mfspr %0, 938" : "=r" (a))
+#if (POWERPC_NUM_PMC_ENABLED > 2)
+#define POWERPC_GET_PMC3(a) asm volatile("mfspr %0, 941" : "=r" (a))
+#define POWERPC_GET_PMC4(a) asm volatile("mfspr %0, 942" : "=r" (a))
+#else
+#define POWERPC_GET_PMC3(a) do {} while (0)
+#define POWERPC_GET_PMC4(a) do {} while (0)
+#endif
+#if (POWERPC_NUM_PMC_ENABLED > 4)
+#define POWERPC_GET_PMC5(a) asm volatile("mfspr %0, 929" : "=r" (a))
+#define POWERPC_GET_PMC6(a) asm volatile("mfspr %0, 930" : "=r" (a))
+#else
+#define POWERPC_GET_PMC5(a) do {} while (0)
+#define POWERPC_GET_PMC6(a) do {} while (0)
+#endif
+#else /* POWERPC_MODE_64BITS */
+#define POWERP_PMC_DATATYPE unsigned long long
+#define POWERPC_GET_PMC1(a) asm volatile("mfspr %0, 771" : "=r" (a))
+#define POWERPC_GET_PMC2(a) asm volatile("mfspr %0, 772" : "=r" (a))
+#if (POWERPC_NUM_PMC_ENABLED > 2)
+#define POWERPC_GET_PMC3(a) asm volatile("mfspr %0, 773" : "=r" (a))
+#define POWERPC_GET_PMC4(a) asm volatile("mfspr %0, 774" : "=r" (a))
+#else
+#define POWERPC_GET_PMC3(a) do {} while (0)
+#define POWERPC_GET_PMC4(a) do {} while (0)
+#endif
+#if (POWERPC_NUM_PMC_ENABLED > 4)
+#define POWERPC_GET_PMC5(a) asm volatile("mfspr %0, 775" : "=r" (a))
+#define POWERPC_GET_PMC6(a) asm volatile("mfspr %0, 776" : "=r" (a))
+#else
+#define POWERPC_GET_PMC5(a) do {} while (0)
+#define POWERPC_GET_PMC6(a) do {} while (0)
+#endif
+#endif /* POWERPC_MODE_64BITS */
+#define POWERPC_PERF_DECLARE(a, cond) \
+ POWERP_PMC_DATATYPE \
+ pmc_start[POWERPC_NUM_PMC_ENABLED], \
+ pmc_stop[POWERPC_NUM_PMC_ENABLED], \
+ pmc_loop_index;
+#define POWERPC_PERF_START_COUNT(a, cond) do { \
+ POWERPC_GET_PMC6(pmc_start[5]); \
+ POWERPC_GET_PMC5(pmc_start[4]); \
+ POWERPC_GET_PMC4(pmc_start[3]); \
+ POWERPC_GET_PMC3(pmc_start[2]); \
+ POWERPC_GET_PMC2(pmc_start[1]); \
+ POWERPC_GET_PMC1(pmc_start[0]); \
+ } while (0)
+#define POWERPC_PERF_STOP_COUNT(a, cond) do { \
+ POWERPC_GET_PMC1(pmc_stop[0]); \
+ POWERPC_GET_PMC2(pmc_stop[1]); \
+ POWERPC_GET_PMC3(pmc_stop[2]); \
+ POWERPC_GET_PMC4(pmc_stop[3]); \
+ POWERPC_GET_PMC5(pmc_stop[4]); \
+ POWERPC_GET_PMC6(pmc_stop[5]); \
+ if (cond) \
+ { \
+ for(pmc_loop_index = 0; \
+ pmc_loop_index < POWERPC_NUM_PMC_ENABLED; \
+ pmc_loop_index++) \
+ { \
+ if (pmc_stop[pmc_loop_index] >= pmc_start[pmc_loop_index]) \
+ { \
+ POWERP_PMC_DATATYPE diff = \
+ pmc_stop[pmc_loop_index] - pmc_start[pmc_loop_index]; \
+ if (diff < perfdata[pmc_loop_index][a][powerpc_data_min]) \
+ perfdata[pmc_loop_index][a][powerpc_data_min] = diff; \
+ if (diff > perfdata[pmc_loop_index][a][powerpc_data_max]) \
+ perfdata[pmc_loop_index][a][powerpc_data_max] = diff; \
+ perfdata[pmc_loop_index][a][powerpc_data_sum] += diff; \
+ perfdata[pmc_loop_index][a][powerpc_data_num] ++; \
+ } \
+ } \
+ } \
+} while (0)
+#else /* CONFIG_POWERPC_PERF */
+// those are needed to avoid empty statements.
+#define POWERPC_PERF_DECLARE(a, cond) int altivec_placeholder __attribute__ ((unused))
+#define POWERPC_PERF_START_COUNT(a, cond) do {} while (0)
+#define POWERPC_PERF_STOP_COUNT(a, cond) do {} while (0)
+#endif /* CONFIG_POWERPC_PERF */
+
+#endif /* _DSPUTIL_PPC_ */
diff --git a/src/libffmpeg/libavcodec/ppc/fdct_altivec.c b/contrib/ffmpeg/libavcodec/ppc/fdct_altivec.c
index 2418c32bb..2418c32bb 100644
--- a/src/libffmpeg/libavcodec/ppc/fdct_altivec.c
+++ b/contrib/ffmpeg/libavcodec/ppc/fdct_altivec.c
diff --git a/src/libffmpeg/libavcodec/ppc/fft_altivec.c b/contrib/ffmpeg/libavcodec/ppc/fft_altivec.c
index 384a774ff..384a774ff 100644
--- a/src/libffmpeg/libavcodec/ppc/fft_altivec.c
+++ b/contrib/ffmpeg/libavcodec/ppc/fft_altivec.c
diff --git a/src/libffmpeg/libavcodec/ppc/float_altivec.c b/contrib/ffmpeg/libavcodec/ppc/float_altivec.c
index 22c2de61a..22c2de61a 100644
--- a/src/libffmpeg/libavcodec/ppc/float_altivec.c
+++ b/contrib/ffmpeg/libavcodec/ppc/float_altivec.c
diff --git a/src/libffmpeg/libavcodec/ppc/gcc_fixes.h b/contrib/ffmpeg/libavcodec/ppc/gcc_fixes.h
index 5a4a55188..5a4a55188 100644
--- a/src/libffmpeg/libavcodec/ppc/gcc_fixes.h
+++ b/contrib/ffmpeg/libavcodec/ppc/gcc_fixes.h
diff --git a/src/libffmpeg/libavcodec/ppc/gmc_altivec.c b/contrib/ffmpeg/libavcodec/ppc/gmc_altivec.c
index 42c936bb3..42c936bb3 100644
--- a/src/libffmpeg/libavcodec/ppc/gmc_altivec.c
+++ b/contrib/ffmpeg/libavcodec/ppc/gmc_altivec.c
diff --git a/src/libffmpeg/libavcodec/ppc/h264_altivec.c b/contrib/ffmpeg/libavcodec/ppc/h264_altivec.c
index bac620e82..bac620e82 100644
--- a/src/libffmpeg/libavcodec/ppc/h264_altivec.c
+++ b/contrib/ffmpeg/libavcodec/ppc/h264_altivec.c
diff --git a/src/libffmpeg/libavcodec/ppc/h264_template_altivec.c b/contrib/ffmpeg/libavcodec/ppc/h264_template_altivec.c
index e8ad67f2f..e8ad67f2f 100644
--- a/src/libffmpeg/libavcodec/ppc/h264_template_altivec.c
+++ b/contrib/ffmpeg/libavcodec/ppc/h264_template_altivec.c
diff --git a/contrib/ffmpeg/libavcodec/ppc/idct_altivec.c b/contrib/ffmpeg/libavcodec/ppc/idct_altivec.c
new file mode 100644
index 000000000..66c8082f7
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/ppc/idct_altivec.c
@@ -0,0 +1,237 @@
+/*
+ * Copyright (c) 2001 Michel Lespinasse
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/*
+ * NOTE: This code is based on GPL code from the libmpeg2 project. The
+ * author, Michel Lespinasses, has given explicit permission to release
+ * under LGPL as part of ffmpeg.
+ *
+ */
+
+/*
+ * FFMpeg integration by Dieter Shirley
+ *
+ * This file is a direct copy of the altivec idct module from the libmpeg2
+ * project. I've deleted all of the libmpeg2 specific code, renamed the functions and
+ * re-ordered the function parameters. The only change to the IDCT function
+ * itself was to factor out the partial transposition, and to perform a full
+ * transpose at the end of the function.
+ */
+
+
+#include <stdlib.h> /* malloc(), free() */
+#include <string.h>
+#include "../dsputil.h"
+
+#include "gcc_fixes.h"
+
+#include "dsputil_altivec.h"
+
+#define vector_s16_t vector signed short
+#define const_vector_s16_t const_vector signed short
+#define vector_u16_t vector unsigned short
+#define vector_s8_t vector signed char
+#define vector_u8_t vector unsigned char
+#define vector_s32_t vector signed int
+#define vector_u32_t vector unsigned int
+
+#define IDCT_HALF \
+ /* 1st stage */ \
+ t1 = vec_mradds (a1, vx7, vx1 ); \
+ t8 = vec_mradds (a1, vx1, vec_subs (zero, vx7)); \
+ t7 = vec_mradds (a2, vx5, vx3); \
+ t3 = vec_mradds (ma2, vx3, vx5); \
+ \
+ /* 2nd stage */ \
+ t5 = vec_adds (vx0, vx4); \
+ t0 = vec_subs (vx0, vx4); \
+ t2 = vec_mradds (a0, vx6, vx2); \
+ t4 = vec_mradds (a0, vx2, vec_subs (zero, vx6)); \
+ t6 = vec_adds (t8, t3); \
+ t3 = vec_subs (t8, t3); \
+ t8 = vec_subs (t1, t7); \
+ t1 = vec_adds (t1, t7); \
+ \
+ /* 3rd stage */ \
+ t7 = vec_adds (t5, t2); \
+ t2 = vec_subs (t5, t2); \
+ t5 = vec_adds (t0, t4); \
+ t0 = vec_subs (t0, t4); \
+ t4 = vec_subs (t8, t3); \
+ t3 = vec_adds (t8, t3); \
+ \
+ /* 4th stage */ \
+ vy0 = vec_adds (t7, t1); \
+ vy7 = vec_subs (t7, t1); \
+ vy1 = vec_mradds (c4, t3, t5); \
+ vy6 = vec_mradds (mc4, t3, t5); \
+ vy2 = vec_mradds (c4, t4, t0); \
+ vy5 = vec_mradds (mc4, t4, t0); \
+ vy3 = vec_adds (t2, t6); \
+ vy4 = vec_subs (t2, t6);
+
+
+#define IDCT \
+ vector_s16_t vx0, vx1, vx2, vx3, vx4, vx5, vx6, vx7; \
+ vector_s16_t vy0, vy1, vy2, vy3, vy4, vy5, vy6, vy7; \
+ vector_s16_t a0, a1, a2, ma2, c4, mc4, zero, bias; \
+ vector_s16_t t0, t1, t2, t3, t4, t5, t6, t7, t8; \
+ vector_u16_t shift; \
+ \
+ c4 = vec_splat (constants[0], 0); \
+ a0 = vec_splat (constants[0], 1); \
+ a1 = vec_splat (constants[0], 2); \
+ a2 = vec_splat (constants[0], 3); \
+ mc4 = vec_splat (constants[0], 4); \
+ ma2 = vec_splat (constants[0], 5); \
+ bias = (vector_s16_t)vec_splat ((vector_s32_t)constants[0], 3); \
+ \
+ zero = vec_splat_s16 (0); \
+ shift = vec_splat_u16 (4); \
+ \
+ vx0 = vec_mradds (vec_sl (block[0], shift), constants[1], zero); \
+ vx1 = vec_mradds (vec_sl (block[1], shift), constants[2], zero); \
+ vx2 = vec_mradds (vec_sl (block[2], shift), constants[3], zero); \
+ vx3 = vec_mradds (vec_sl (block[3], shift), constants[4], zero); \
+ vx4 = vec_mradds (vec_sl (block[4], shift), constants[1], zero); \
+ vx5 = vec_mradds (vec_sl (block[5], shift), constants[4], zero); \
+ vx6 = vec_mradds (vec_sl (block[6], shift), constants[3], zero); \
+ vx7 = vec_mradds (vec_sl (block[7], shift), constants[2], zero); \
+ \
+ IDCT_HALF \
+ \
+ vx0 = vec_mergeh (vy0, vy4); \
+ vx1 = vec_mergel (vy0, vy4); \
+ vx2 = vec_mergeh (vy1, vy5); \
+ vx3 = vec_mergel (vy1, vy5); \
+ vx4 = vec_mergeh (vy2, vy6); \
+ vx5 = vec_mergel (vy2, vy6); \
+ vx6 = vec_mergeh (vy3, vy7); \
+ vx7 = vec_mergel (vy3, vy7); \
+ \
+ vy0 = vec_mergeh (vx0, vx4); \
+ vy1 = vec_mergel (vx0, vx4); \
+ vy2 = vec_mergeh (vx1, vx5); \
+ vy3 = vec_mergel (vx1, vx5); \
+ vy4 = vec_mergeh (vx2, vx6); \
+ vy5 = vec_mergel (vx2, vx6); \
+ vy6 = vec_mergeh (vx3, vx7); \
+ vy7 = vec_mergel (vx3, vx7); \
+ \
+ vx0 = vec_adds (vec_mergeh (vy0, vy4), bias); \
+ vx1 = vec_mergel (vy0, vy4); \
+ vx2 = vec_mergeh (vy1, vy5); \
+ vx3 = vec_mergel (vy1, vy5); \
+ vx4 = vec_mergeh (vy2, vy6); \
+ vx5 = vec_mergel (vy2, vy6); \
+ vx6 = vec_mergeh (vy3, vy7); \
+ vx7 = vec_mergel (vy3, vy7); \
+ \
+ IDCT_HALF \
+ \
+ shift = vec_splat_u16 (6); \
+ vx0 = vec_sra (vy0, shift); \
+ vx1 = vec_sra (vy1, shift); \
+ vx2 = vec_sra (vy2, shift); \
+ vx3 = vec_sra (vy3, shift); \
+ vx4 = vec_sra (vy4, shift); \
+ vx5 = vec_sra (vy5, shift); \
+ vx6 = vec_sra (vy6, shift); \
+ vx7 = vec_sra (vy7, shift);
+
+
+static const_vector_s16_t constants[5] = {
+ (vector_s16_t) AVV(23170, 13573, 6518, 21895, -23170, -21895, 32, 31),
+ (vector_s16_t) AVV(16384, 22725, 21407, 19266, 16384, 19266, 21407, 22725),
+ (vector_s16_t) AVV(22725, 31521, 29692, 26722, 22725, 26722, 29692, 31521),
+ (vector_s16_t) AVV(21407, 29692, 27969, 25172, 21407, 25172, 27969, 29692),
+ (vector_s16_t) AVV(19266, 26722, 25172, 22654, 19266, 22654, 25172, 26722)
+};
+
+void idct_put_altivec(uint8_t* dest, int stride, vector_s16_t* block)
+{
+POWERPC_PERF_DECLARE(altivec_idct_put_num, 1);
+ vector_u8_t tmp;
+
+#ifdef CONFIG_POWERPC_PERF
+POWERPC_PERF_START_COUNT(altivec_idct_put_num, 1);
+#endif
+ IDCT
+
+#define COPY(dest,src) \
+ tmp = vec_packsu (src, src); \
+ vec_ste ((vector_u32_t)tmp, 0, (unsigned int *)dest); \
+ vec_ste ((vector_u32_t)tmp, 4, (unsigned int *)dest);
+
+ COPY (dest, vx0) dest += stride;
+ COPY (dest, vx1) dest += stride;
+ COPY (dest, vx2) dest += stride;
+ COPY (dest, vx3) dest += stride;
+ COPY (dest, vx4) dest += stride;
+ COPY (dest, vx5) dest += stride;
+ COPY (dest, vx6) dest += stride;
+ COPY (dest, vx7)
+
+POWERPC_PERF_STOP_COUNT(altivec_idct_put_num, 1);
+}
+
+void idct_add_altivec(uint8_t* dest, int stride, vector_s16_t* block)
+{
+POWERPC_PERF_DECLARE(altivec_idct_add_num, 1);
+ vector_u8_t tmp;
+ vector_s16_t tmp2, tmp3;
+ vector_u8_t perm0;
+ vector_u8_t perm1;
+ vector_u8_t p0, p1, p;
+
+#ifdef CONFIG_POWERPC_PERF
+POWERPC_PERF_START_COUNT(altivec_idct_add_num, 1);
+#endif
+
+ IDCT
+
+ p0 = vec_lvsl (0, dest);
+ p1 = vec_lvsl (stride, dest);
+ p = vec_splat_u8 (-1);
+ perm0 = vec_mergeh (p, p0);
+ perm1 = vec_mergeh (p, p1);
+
+#define ADD(dest,src,perm) \
+ /* *(uint64_t *)&tmp = *(uint64_t *)dest; */ \
+ tmp = vec_ld (0, dest); \
+ tmp2 = (vector_s16_t)vec_perm (tmp, (vector_u8_t)zero, perm); \
+ tmp3 = vec_adds (tmp2, src); \
+ tmp = vec_packsu (tmp3, tmp3); \
+ vec_ste ((vector_u32_t)tmp, 0, (unsigned int *)dest); \
+ vec_ste ((vector_u32_t)tmp, 4, (unsigned int *)dest);
+
+ ADD (dest, vx0, perm0) dest += stride;
+ ADD (dest, vx1, perm1) dest += stride;
+ ADD (dest, vx2, perm0) dest += stride;
+ ADD (dest, vx3, perm1) dest += stride;
+ ADD (dest, vx4, perm0) dest += stride;
+ ADD (dest, vx5, perm1) dest += stride;
+ ADD (dest, vx6, perm0) dest += stride;
+ ADD (dest, vx7, perm1)
+
+POWERPC_PERF_STOP_COUNT(altivec_idct_add_num, 1);
+}
+
diff --git a/src/libffmpeg/libavcodec/ppc/mathops.h b/contrib/ffmpeg/libavcodec/ppc/mathops.h
index 6af23f246..6af23f246 100644
--- a/src/libffmpeg/libavcodec/ppc/mathops.h
+++ b/contrib/ffmpeg/libavcodec/ppc/mathops.h
diff --git a/src/libffmpeg/libavcodec/ppc/mpegvideo_altivec.c b/contrib/ffmpeg/libavcodec/ppc/mpegvideo_altivec.c
index 3822cb20e..3822cb20e 100644
--- a/src/libffmpeg/libavcodec/ppc/mpegvideo_altivec.c
+++ b/contrib/ffmpeg/libavcodec/ppc/mpegvideo_altivec.c
diff --git a/src/libffmpeg/libavcodec/ppc/mpegvideo_ppc.c b/contrib/ffmpeg/libavcodec/ppc/mpegvideo_ppc.c
index c5e822f77..c5e822f77 100644
--- a/src/libffmpeg/libavcodec/ppc/mpegvideo_ppc.c
+++ b/contrib/ffmpeg/libavcodec/ppc/mpegvideo_ppc.c
diff --git a/src/libffmpeg/libavcodec/ppc/snow_altivec.c b/contrib/ffmpeg/libavcodec/ppc/snow_altivec.c
index b15672ffe..b15672ffe 100644
--- a/src/libffmpeg/libavcodec/ppc/snow_altivec.c
+++ b/contrib/ffmpeg/libavcodec/ppc/snow_altivec.c
diff --git a/src/libffmpeg/libavcodec/ppc/types_altivec.h b/contrib/ffmpeg/libavcodec/ppc/types_altivec.h
index f29026e04..f29026e04 100644
--- a/src/libffmpeg/libavcodec/ppc/types_altivec.h
+++ b/contrib/ffmpeg/libavcodec/ppc/types_altivec.h
diff --git a/src/libffmpeg/libavcodec/ppc/vc1dsp_altivec.c b/contrib/ffmpeg/libavcodec/ppc/vc1dsp_altivec.c
index 114c9d41f..114c9d41f 100644
--- a/src/libffmpeg/libavcodec/ppc/vc1dsp_altivec.c
+++ b/contrib/ffmpeg/libavcodec/ppc/vc1dsp_altivec.c
diff --git a/contrib/ffmpeg/libavcodec/ps2/dsputil_mmi.c b/contrib/ffmpeg/libavcodec/ps2/dsputil_mmi.c
new file mode 100644
index 000000000..0d72ae88c
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/ps2/dsputil_mmi.c
@@ -0,0 +1,163 @@
+/*
+ * MMI optimized DSP utils
+ * Copyright (c) 2000, 2001 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
+ *
+ * MMI optimization by Leon van Stuivenberg
+ * clear_blocks_mmi() by BroadQ
+ */
+
+#include "../dsputil.h"
+#include "mmi.h"
+
+void ff_mmi_idct_put(uint8_t *dest, int line_size, DCTELEM *block);
+void ff_mmi_idct_add(uint8_t *dest, int line_size, DCTELEM *block);
+void ff_mmi_idct(DCTELEM *block);
+
+static void clear_blocks_mmi(DCTELEM * blocks)
+{
+ asm volatile(
+ ".set noreorder \n"
+ "addiu $9, %0, 768 \n"
+ "nop \n"
+ "1: \n"
+ "sq $0, 0(%0) \n"
+ "move $8, %0 \n"
+ "addi %0, %0, 64 \n"
+ "sq $0, 16($8) \n"
+ "slt $10, %0, $9 \n"
+ "sq $0, 32($8) \n"
+ "bnez $10, 1b \n"
+ "sq $0, 48($8) \n"
+ ".set reorder \n"
+ : "+r" (blocks) :: "$8", "$9", "memory" );
+}
+
+
+static void get_pixels_mmi(DCTELEM *block, const uint8_t *pixels, int line_size)
+{
+ asm volatile(
+ ".set push \n\t"
+ ".set mips3 \n\t"
+ "ld $8, 0(%0) \n\t"
+ "add %0, %0, %2 \n\t"
+ "ld $9, 0(%0) \n\t"
+ "add %0, %0, %2 \n\t"
+ "ld $10, 0(%0) \n\t"
+ "pextlb $8, $0, $8 \n\t"
+ "sq $8, 0(%1) \n\t"
+ "add %0, %0, %2 \n\t"
+ "ld $8, 0(%0) \n\t"
+ "pextlb $9, $0, $9 \n\t"
+ "sq $9, 16(%1) \n\t"
+ "add %0, %0, %2 \n\t"
+ "ld $9, 0(%0) \n\t"
+ "pextlb $10, $0, $10 \n\t"
+ "sq $10, 32(%1) \n\t"
+ "add %0, %0, %2 \n\t"
+ "ld $10, 0(%0) \n\t"
+ "pextlb $8, $0, $8 \n\t"
+ "sq $8, 48(%1) \n\t"
+ "add %0, %0, %2 \n\t"
+ "ld $8, 0(%0) \n\t"
+ "pextlb $9, $0, $9 \n\t"
+ "sq $9, 64(%1) \n\t"
+ "add %0, %0, %2 \n\t"
+ "ld $9, 0(%0) \n\t"
+ "pextlb $10, $0, $10 \n\t"
+ "sq $10, 80(%1) \n\t"
+ "pextlb $8, $0, $8 \n\t"
+ "sq $8, 96(%1) \n\t"
+ "pextlb $9, $0, $9 \n\t"
+ "sq $9, 112(%1) \n\t"
+ ".set pop \n\t"
+ : "+r" (pixels) : "r" (block), "r" (line_size) : "$8", "$9", "$10", "memory" );
+}
+
+
+static void put_pixels8_mmi(uint8_t *block, const uint8_t *pixels, int line_size, int h)
+{
+ asm volatile(
+ ".set push \n\t"
+ ".set mips3 \n\t"
+ "1: \n\t"
+ "ldr $8, 0(%1) \n\t"
+ "addiu %2, %2, -1 \n\t"
+ "ldl $8, 7(%1) \n\t"
+ "add %1, %1, %3 \n\t"
+ "sd $8, 0(%0) \n\t"
+ "add %0, %0, %3 \n\t"
+ "bgtz %2, 1b \n\t"
+ ".set pop \n\t"
+ : "+r" (block), "+r" (pixels), "+r" (h) : "r" (line_size)
+ : "$8", "memory" );
+}
+
+
+static void put_pixels16_mmi(uint8_t *block, const uint8_t *pixels, int line_size, int h)
+{
+ asm volatile (
+ ".set push \n\t"
+ ".set mips3 \n\t"
+ "1: \n\t"
+ "ldr $8, 0(%1) \n\t"
+ "add $11, %1, %3 \n\t"
+ "ldl $8, 7(%1) \n\t"
+ "add $10, %0, %3 \n\t"
+ "ldr $9, 8(%1) \n\t"
+ "ldl $9, 15(%1) \n\t"
+ "ldr $12, 0($11) \n\t"
+ "add %1, $11, %3 \n\t"
+ "ldl $12, 7($11) \n\t"
+ "pcpyld $8, $9, $8 \n\t"
+ "sq $8, 0(%0) \n\t"
+ "ldr $13, 8($11) \n\t"
+ "addiu %2, %2, -2 \n\t"
+ "ldl $13, 15($11) \n\t"
+ "add %0, $10, %3 \n\t"
+ "pcpyld $12, $13, $12 \n\t"
+ "sq $12, 0($10) \n\t"
+ "bgtz %2, 1b \n\t"
+ ".set pop \n\t"
+ : "+r" (block), "+r" (pixels), "+r" (h) : "r" (line_size)
+ : "$8", "$9", "$10", "$11", "$12", "$13", "memory" );
+}
+
+
+void dsputil_init_mmi(DSPContext* c, AVCodecContext *avctx)
+{
+ const int idct_algo= avctx->idct_algo;
+
+ c->clear_blocks = clear_blocks_mmi;
+
+ c->put_pixels_tab[1][0] = put_pixels8_mmi;
+ c->put_no_rnd_pixels_tab[1][0] = put_pixels8_mmi;
+
+ c->put_pixels_tab[0][0] = put_pixels16_mmi;
+ c->put_no_rnd_pixels_tab[0][0] = put_pixels16_mmi;
+
+ c->get_pixels = get_pixels_mmi;
+
+ if(idct_algo==FF_IDCT_AUTO || idct_algo==FF_IDCT_PS2){
+ c->idct_put= ff_mmi_idct_put;
+ c->idct_add= ff_mmi_idct_add;
+ c->idct = ff_mmi_idct;
+ c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
+ }
+}
+
diff --git a/contrib/ffmpeg/libavcodec/ps2/idct_mmi.c b/contrib/ffmpeg/libavcodec/ps2/idct_mmi.c
new file mode 100644
index 000000000..dfe9b3726
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/ps2/idct_mmi.c
@@ -0,0 +1,363 @@
+/*
+ * Originally provided by Intel at Application Note AP-922.
+ *
+ * Column code adapted from Peter Gubanov.
+ * Copyright (c) 2000-2001 Peter Gubanov <peter@elecard.net.ru>
+ * http://www.elecard.com/peter/idct.shtml
+ * rounding trick copyright (c) 2000 Michel Lespinasse <walken@zoy.org>
+ *
+ * MMI port and (c) 2002 by Leon van Stuivenberg
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 "../common.h"
+#include "../dsputil.h"
+#include "mmi.h"
+
+#define BITS_INV_ACC 5 // 4 or 5 for IEEE
+#define SHIFT_INV_ROW (16 - BITS_INV_ACC)
+#define SHIFT_INV_COL (1 + BITS_INV_ACC)
+
+#define TG1 6518
+#define TG2 13573
+#define TG3 21895
+#define CS4 23170
+
+#define ROUNDER_0 0
+#define ROUNDER_1 16
+
+#define TAB_i_04 (32+0)
+#define TAB_i_17 (32+64)
+#define TAB_i_26 (32+128)
+#define TAB_i_35 (32+192)
+
+#define TG_1_16 (32+256+0)
+#define TG_2_16 (32+256+16)
+#define TG_3_16 (32+256+32)
+#define COS_4_16 (32+256+48)
+
+#define CLIPMAX (32+256+64+0)
+
+static short consttable[] align16 = {
+/* rounder 0*/ // assume SHIFT_INV_ROW == 11
+ 0x3ff, 1, 0x3ff, 1, 0x3ff, 1, 0x3ff, 1,
+/* rounder 1*/
+ 0x3ff, 0, 0x3ff, 0, 0x3ff, 0, 0x3ff, 0,
+/* row 0/4*/
+ 16384, 21407, -16384, -21407, 22725, 19266, -22725, -12873,
+ 8867, 16384, 8867, 16384, 4520, 12873, -4520, 19266,
+ 16384, -8867, 16384, -8867, 12873, -22725, 19266, -22725,
+ 21407, -16384, -21407, 16384, 19266, 4520, -12873, 4520,
+/* row 1/7*/
+ 22725, 29692, -22725, -29692, 31521, 26722, -31521, -17855,
+ 12299, 22725, 12299, 22725, 6270, 17855, -6270, 26722,
+ 22725, -12299, 22725, -12299, 17855, -31521, 26722, -31521,
+ 29692, -22725, -29692, 22725, 26722, 6270, -17855, 6270,
+/* row 2/6*/
+ 21407, 27969, -21407, -27969, 29692, 25172, -29692, -16819,
+ 11585, 21407, 11585, 21407, 5906, 16819, -5906, 25172,
+ 21407, -11585, 21407, -11585, 16819, -29692, 25172, -29692,
+ 27969, -21407, -27969, 21407, 25172, 5906, -16819, 5906,
+/*row 3/5*/
+ 19266, 25172, -19266, -25172, 26722, 22654, -26722, -15137,
+ 10426, 19266, 10426, 19266, 5315, 15137, -5315, 22654,
+ 19266, -10426, 19266, -10426, 15137, -26722, 22654, -26722,
+ 25172, -19266, -25172, 19266, 22654, 5315, -15137, 5315,
+/*column constants*/
+ TG1, TG1, TG1, TG1, TG1, TG1, TG1, TG1,
+ TG2, TG2, TG2, TG2, TG2, TG2, TG2, TG2,
+ TG3, TG3, TG3, TG3, TG3, TG3, TG3, TG3,
+ CS4, CS4, CS4, CS4, CS4, CS4, CS4, CS4,
+/* clamp */
+ 255, 255, 255, 255, 255, 255, 255, 255
+};
+
+
+#define DCT_8_INV_ROW1(blk, rowoff, taboff, rnd, outreg) { \
+ lq(blk, rowoff, $16); /* r16 = x7 x5 x3 x1 x6 x4 x2 x0 */ \
+ /*slot*/ \
+ lq($24, 0+taboff, $17); /* r17 = w */ \
+ /*delay slot $16*/ \
+ lq($24, 16+taboff, $18);/* r18 = w */ \
+ prevh($16, $2); /* r2 = x1 x3 x5 x7 x0 x2 x4 x6 */ \
+ lq($24, 32+taboff, $19);/* r19 = w */ \
+ phmadh($17, $16, $17); /* r17 = b1"b0'a1"a0' */ \
+ lq($24, 48+taboff, $20);/* r20 = w */ \
+ phmadh($18, $2, $18); /* r18 = b1'b0"a1'a0" */ \
+ phmadh($19, $16, $19); /* r19 = b3"b2'a3"a2' */ \
+ phmadh($20, $2, $20); /* r20 = b3'b2"a3'a2" */ \
+ paddw($17, $18, $17); /* r17 = (b1)(b0)(a1)(a0) */ \
+ paddw($19, $20, $19); /* r19 = (b3)(b2)(a3)(a2) */ \
+ pcpyld($19, $17, $18); /* r18 = (a3)(a2)(a1)(a0) */ \
+ pcpyud($17, $19, $20); /* r20 = (b3)(b2)(b1)(b0) */ \
+ paddw($18, rnd, $18); /* r18 = (a3)(a2)(a1)(a0) */\
+ paddw($18, $20, $17); /* r17 = ()()()(a0+b0) */ \
+ psubw($18, $20, $20); /* r20 = ()()()(a0-b0) */ \
+ psraw($17, SHIFT_INV_ROW, $17); /* r17 = (y3 y2 y1 y0) */ \
+ psraw($20, SHIFT_INV_ROW, $20); /* r20 = (y4 y5 y6 y7) */ \
+ ppach($20, $17, outreg);/* out = y4 y5 y6 y7 y3 y2 y1 y0 Note order */ \
+\
+ prevh(outreg, $2); \
+ pcpyud($2, $2, $2); \
+ pcpyld($2, outreg, outreg); \
+}
+
+
+#define DCT_8_INV_COL8() \
+\
+ lq($24, TG_3_16, $2); /* r2 = tn3 */ \
+\
+ pmulth($11, $2, $17); /* r17 = x3 * tn3 (6420) */ \
+ psraw($17, 15, $17); \
+ pmfhl_uw($3); /* r3 = 7531 */ \
+ psraw($3, 15, $3); \
+ pinteh($3, $17, $17); /* r17 = x3 * tn3 */ \
+ psubh($17, $13, $17); /* r17 = tm35 */ \
+\
+ pmulth($13, $2, $18); /* r18 = x5 * tn3 (6420) */ \
+ psraw($18, 15, $18); \
+ pmfhl_uw($3); /* r3 = 7531 */ \
+ psraw($3, 15, $3); \
+ pinteh($3, $18, $18); /* r18 = x5 * tn3 */ \
+ paddh($18, $11, $18); /* r18 = tp35 */ \
+\
+ lq($24, TG_1_16, $2); /* r2 = tn1 */ \
+\
+ pmulth($15, $2, $19); /* r19 = x7 * tn1 (6420) */ \
+ psraw($19, 15, $19); \
+ pmfhl_uw($3); /* r3 = 7531 */ \
+ psraw($3, 15, $3); \
+ pinteh($3, $19, $19); /* r19 = x7 * tn1 */ \
+ paddh($19, $9, $19); /* r19 = tp17 */ \
+\
+ pmulth($9, $2, $20); /* r20 = x1 * tn1 (6420) */ \
+ psraw($20, 15, $20); \
+ pmfhl_uw($3); /* r3 = 7531 */ \
+ psraw($3, 15, $3); \
+ pinteh($3, $20, $20); /* r20 = x1 * tn1 */ \
+ psubh($20, $15, $20); /* r20 = tm17 */ \
+\
+ psubh($19, $18, $3); /* r3 = t1 */ \
+ paddh($20, $17, $16); /* r16 = t2 */ \
+ psubh($20, $17, $23); /* r23 = b3 */ \
+ paddh($19, $18, $20); /* r20 = b0 */ \
+\
+ lq($24, COS_4_16, $2); /* r2 = cs4 */ \
+\
+ paddh($3, $16, $21); /* r21 = t1+t2 */ \
+ psubh($3, $16, $22); /* r22 = t1-t2 */ \
+\
+ pmulth($21, $2, $21); /* r21 = cs4 * (t1+t2) 6420 */ \
+ psraw($21, 15, $21); \
+ pmfhl_uw($3); /* r3 = 7531 */ \
+ psraw($3, 15, $3); \
+ pinteh($3, $21, $21); /* r21 = b1 */ \
+\
+ pmulth($22, $2, $22); /* r22 = cs4 * (t1-t2) 6420 */ \
+ psraw($22, 15, $22); \
+ pmfhl_uw($3); /* r3 = 7531 */ \
+ psraw($3, 15, $3); \
+ pinteh($3, $22, $22); /* r22 = b2 */ \
+\
+ lq($24, TG_2_16, $2); /* r2 = tn2 */ \
+\
+ pmulth($10, $2, $17); /* r17 = x2 * tn2 (6420) */ \
+ psraw($17, 15, $17); \
+ pmfhl_uw($3); /* r3 = 7531 */ \
+ psraw($3, 15, $3); \
+ pinteh($3, $17, $17); /* r17 = x3 * tn3 */ \
+ psubh($17, $14, $17); /* r17 = tm26 */ \
+\
+ pmulth($14, $2, $18); /* r18 = x6 * tn2 (6420) */ \
+ psraw($18, 15, $18); \
+ pmfhl_uw($3); /* r3 = 7531 */ \
+ psraw($3, 15, $3); \
+ pinteh($3, $18, $18); /* r18 = x6 * tn2 */ \
+ paddh($18, $10, $18); /* r18 = tp26 */ \
+\
+ paddh($8, $12, $2); /* r2 = tp04 */ \
+ psubh($8, $12, $3); /* r3 = tm04 */ \
+\
+ paddh($2, $18, $16); /* r16 = a0 */ \
+ psubh($2, $18, $19); /* r19 = a3 */ \
+ psubh($3, $17, $18); /* r18 = a2 */ \
+ paddh($3, $17, $17); /* r17 = a1 */
+
+
+#define DCT_8_INV_COL8_STORE(blk) \
+\
+ paddh($16, $20, $2); /* y0 a0+b0 */ \
+ psubh($16, $20, $16); /* y7 a0-b0 */ \
+ psrah($2, SHIFT_INV_COL, $2); \
+ psrah($16, SHIFT_INV_COL, $16); \
+ sq($2, 0, blk); \
+ sq($16, 112, blk); \
+\
+ paddh($17, $21, $3); /* y1 a1+b1 */ \
+ psubh($17, $21, $17); /* y6 a1-b1 */ \
+ psrah($3, SHIFT_INV_COL, $3); \
+ psrah($17, SHIFT_INV_COL, $17); \
+ sq($3, 16, blk); \
+ sq($17, 96, blk); \
+\
+ paddh($18, $22, $2); /* y2 a2+b2 */ \
+ psubh($18, $22, $18); /* y5 a2-b2 */ \
+ psrah($2, SHIFT_INV_COL, $2); \
+ psrah($18, SHIFT_INV_COL, $18); \
+ sq($2, 32, blk); \
+ sq($18, 80, blk); \
+\
+ paddh($19, $23, $3); /* y3 a3+b3 */ \
+ psubh($19, $23, $19); /* y4 a3-b3 */ \
+ psrah($3, SHIFT_INV_COL, $3); \
+ psrah($19, SHIFT_INV_COL, $19); \
+ sq($3, 48, blk); \
+ sq($19, 64, blk);
+
+
+
+#define DCT_8_INV_COL8_PMS() \
+ paddh($16, $20, $2); /* y0 a0+b0 */ \
+ psubh($16, $20, $20); /* y7 a0-b0 */ \
+ psrah($2, SHIFT_INV_COL, $16); \
+ psrah($20, SHIFT_INV_COL, $20); \
+\
+ paddh($17, $21, $3); /* y1 a1+b1 */ \
+ psubh($17, $21, $21); /* y6 a1-b1 */ \
+ psrah($3, SHIFT_INV_COL, $17); \
+ psrah($21, SHIFT_INV_COL, $21); \
+\
+ paddh($18, $22, $2); /* y2 a2+b2 */ \
+ psubh($18, $22, $22); /* y5 a2-b2 */ \
+ psrah($2, SHIFT_INV_COL, $18); \
+ psrah($22, SHIFT_INV_COL, $22); \
+\
+ paddh($19, $23, $3); /* y3 a3+b3 */ \
+ psubh($19, $23, $23); /* y4 a3-b3 */ \
+ psrah($3, SHIFT_INV_COL, $19); \
+ psrah($23, SHIFT_INV_COL, $23);
+
+#define PUT(rs) \
+ pminh(rs, $11, $2); \
+ pmaxh($2, $0, $2); \
+ ppacb($0, $2, $2); \
+ sd3(2, 0, 4); \
+ __asm__ __volatile__ ("add $4, $5, $4");
+
+#define DCT_8_INV_COL8_PUT() \
+ PUT($16); \
+ PUT($17); \
+ PUT($18); \
+ PUT($19); \
+ PUT($23); \
+ PUT($22); \
+ PUT($21); \
+ PUT($20);
+
+#define ADD(rs) \
+ ld3(4, 0, 2); \
+ pextlb($0, $2, $2); \
+ paddh($2, rs, $2); \
+ pminh($2, $11, $2); \
+ pmaxh($2, $0, $2); \
+ ppacb($0, $2, $2); \
+ sd3(2, 0, 4); \
+ __asm__ __volatile__ ("add $4, $5, $4");
+
+/*fixme: schedule*/
+#define DCT_8_INV_COL8_ADD() \
+ ADD($16); \
+ ADD($17); \
+ ADD($18); \
+ ADD($19); \
+ ADD($23); \
+ ADD($22); \
+ ADD($21); \
+ ADD($20);
+
+
+void ff_mmi_idct(int16_t * block)
+{
+ /* $4 = block */
+ __asm__ __volatile__("la $24, %0"::"m"(consttable[0]));
+ lq($24, ROUNDER_0, $8);
+ lq($24, ROUNDER_1, $7);
+ DCT_8_INV_ROW1($4, 0, TAB_i_04, $8, $8);
+ DCT_8_INV_ROW1($4, 16, TAB_i_17, $7, $9);
+ DCT_8_INV_ROW1($4, 32, TAB_i_26, $7, $10);
+ DCT_8_INV_ROW1($4, 48, TAB_i_35, $7, $11);
+ DCT_8_INV_ROW1($4, 64, TAB_i_04, $7, $12);
+ DCT_8_INV_ROW1($4, 80, TAB_i_35, $7, $13);
+ DCT_8_INV_ROW1($4, 96, TAB_i_26, $7, $14);
+ DCT_8_INV_ROW1($4, 112, TAB_i_17, $7, $15);
+ DCT_8_INV_COL8();
+ DCT_8_INV_COL8_STORE($4);
+
+ //let savedtemp regs be saved
+ __asm__ __volatile__(" ":::"$16", "$17", "$18", "$19", "$20", "$21", "$22", "$23");
+}
+
+
+void ff_mmi_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ /* $4 = dest, $5 = line_size, $6 = block */
+ __asm__ __volatile__("la $24, %0"::"m"(consttable[0]));
+ lq($24, ROUNDER_0, $8);
+ lq($24, ROUNDER_1, $7);
+ DCT_8_INV_ROW1($6, 0, TAB_i_04, $8, $8);
+ DCT_8_INV_ROW1($6, 16, TAB_i_17, $7, $9);
+ DCT_8_INV_ROW1($6, 32, TAB_i_26, $7, $10);
+ DCT_8_INV_ROW1($6, 48, TAB_i_35, $7, $11);
+ DCT_8_INV_ROW1($6, 64, TAB_i_04, $7, $12);
+ DCT_8_INV_ROW1($6, 80, TAB_i_35, $7, $13);
+ DCT_8_INV_ROW1($6, 96, TAB_i_26, $7, $14);
+ DCT_8_INV_ROW1($6, 112, TAB_i_17, $7, $15);
+ DCT_8_INV_COL8();
+ lq($24, CLIPMAX, $11);
+ DCT_8_INV_COL8_PMS();
+ DCT_8_INV_COL8_PUT();
+
+ //let savedtemp regs be saved
+ __asm__ __volatile__(" ":::"$16", "$17", "$18", "$19", "$20", "$21", "$22", "$23");
+}
+
+
+void ff_mmi_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ /* $4 = dest, $5 = line_size, $6 = block */
+ __asm__ __volatile__("la $24, %0"::"m"(consttable[0]));
+ lq($24, ROUNDER_0, $8);
+ lq($24, ROUNDER_1, $7);
+ DCT_8_INV_ROW1($6, 0, TAB_i_04, $8, $8);
+ DCT_8_INV_ROW1($6, 16, TAB_i_17, $7, $9);
+ DCT_8_INV_ROW1($6, 32, TAB_i_26, $7, $10);
+ DCT_8_INV_ROW1($6, 48, TAB_i_35, $7, $11);
+ DCT_8_INV_ROW1($6, 64, TAB_i_04, $7, $12);
+ DCT_8_INV_ROW1($6, 80, TAB_i_35, $7, $13);
+ DCT_8_INV_ROW1($6, 96, TAB_i_26, $7, $14);
+ DCT_8_INV_ROW1($6, 112, TAB_i_17, $7, $15);
+ DCT_8_INV_COL8();
+ lq($24, CLIPMAX, $11);
+ DCT_8_INV_COL8_PMS();
+ DCT_8_INV_COL8_ADD();
+
+ //let savedtemp regs be saved
+ __asm__ __volatile__(" ":::"$16", "$17", "$18", "$19", "$20", "$21", "$22", "$23");
+}
+
diff --git a/contrib/ffmpeg/libavcodec/ps2/mmi.h b/contrib/ffmpeg/libavcodec/ps2/mmi.h
new file mode 100644
index 000000000..e2e49a86c
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/ps2/mmi.h
@@ -0,0 +1,172 @@
+/*
+ * copyright (c) 2002 Leon van Stuivenberg
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 __mmi_H
+#define __mmi_H
+
+#define align16 __attribute__ ((aligned (16)))
+
+/*
+#define r0 $zero
+#define r1 $at //assembler!
+#define r2 $v0 //return
+#define r3 $v1 //return
+#define r4 $a0 //arg
+#define r5 $a1 //arg
+#define r6 $a2 //arg
+#define r7 $a3 //arg
+#define r8 $t0 //temp
+#define r9 $t1 //temp
+#define r10 $t2 //temp
+#define r11 $t3 //temp
+#define r12 $t4 //temp
+#define r13 $t5 //temp
+#define r14 $t6 //temp
+#define r15 $t7 //temp
+#define r16 $s0 //saved temp
+#define r17 $s1 //saved temp
+#define r18 $s2 //saved temp
+#define r19 $s3 //saved temp
+#define r20 $s4 //saved temp
+#define r21 $s5 //saved temp
+#define r22 $s6 //saved temp
+#define r23 $s7 //saved temp
+#define r24 $t8 //temp
+#define r25 $t9 //temp
+#define r26 $k0 //kernel
+#define r27 $k1 //kernel
+#define r28 $gp //global ptr
+#define r29 $sp //stack ptr
+#define r30 $fp //frame ptr
+#define r31 $ra //return addr
+*/
+
+
+#define lq(base, off, reg) \
+ __asm__ __volatile__ ("lq " #reg ", %0("#base ")" : : "i" (off) )
+
+#define lq2(mem, reg) \
+ __asm__ __volatile__ ("lq " #reg ", %0" : : "r" (mem))
+
+#define sq(reg, off, base) \
+ __asm__ __volatile__ ("sq " #reg ", %0("#base ")" : : "i" (off) )
+
+/*
+#define ld(base, off, reg) \
+ __asm__ __volatile__ ("ld " #reg ", " #off "("#base ")")
+*/
+
+#define ld3(base, off, reg) \
+ __asm__ __volatile__ (".word %0" : : "i" ( 0xdc000000 | (base<<21) | (reg<<16) | (off)))
+
+#define ldr3(base, off, reg) \
+ __asm__ __volatile__ (".word %0" : : "i" ( 0x6c000000 | (base<<21) | (reg<<16) | (off)))
+
+#define ldl3(base, off, reg) \
+ __asm__ __volatile__ (".word %0" : : "i" ( 0x68000000 | (base<<21) | (reg<<16) | (off)))
+
+/*
+#define sd(reg, off, base) \
+ __asm__ __volatile__ ("sd " #reg ", " #off "("#base ")")
+*/
+//seems assembler has bug encoding mnemonic 'sd', so DIY
+#define sd3(reg, off, base) \
+ __asm__ __volatile__ (".word %0" : : "i" ( 0xfc000000 | (base<<21) | (reg<<16) | (off)))
+
+#define sw(reg, off, base) \
+ __asm__ __volatile__ ("sw " #reg ", " #off "("#base ")")
+
+#define sq2(reg, mem) \
+ __asm__ __volatile__ ("sq " #reg ", %0" : : "m" (*(mem)))
+
+#define pinth(rs, rt, rd) \
+ __asm__ __volatile__ ("pinth " #rd ", " #rs ", " #rt )
+
+#define phmadh(rs, rt, rd) \
+ __asm__ __volatile__ ("phmadh " #rd ", " #rs ", " #rt )
+
+#define pcpyud(rs, rt, rd) \
+ __asm__ __volatile__ ("pcpyud " #rd ", " #rs ", " #rt )
+
+#define pcpyld(rs, rt, rd) \
+ __asm__ __volatile__ ("pcpyld " #rd ", " #rs ", " #rt )
+
+#define pcpyh(rt, rd) \
+ __asm__ __volatile__ ("pcpyh " #rd ", " #rt )
+
+#define paddw(rs, rt, rd) \
+ __asm__ __volatile__ ("paddw " #rd ", " #rs ", " #rt )
+
+#define pextlw(rs, rt, rd) \
+ __asm__ __volatile__ ("pextlw " #rd ", " #rs ", " #rt )
+
+#define pextuw(rs, rt, rd) \
+ __asm__ __volatile__ ("pextuw " #rd ", " #rs ", " #rt )
+
+#define pextlh(rs, rt, rd) \
+ __asm__ __volatile__ ("pextlh " #rd ", " #rs ", " #rt )
+
+#define pextuh(rs, rt, rd) \
+ __asm__ __volatile__ ("pextuh " #rd ", " #rs ", " #rt )
+
+#define psubw(rs, rt, rd) \
+ __asm__ __volatile__ ("psubw " #rd ", " #rs ", " #rt )
+
+#define psraw(rt, sa, rd) \
+ __asm__ __volatile__ ("psraw " #rd ", " #rt ", %0" : : "i"(sa) )
+
+#define ppach(rs, rt, rd) \
+ __asm__ __volatile__ ("ppach " #rd ", " #rs ", " #rt )
+
+#define ppacb(rs, rt, rd) \
+ __asm__ __volatile__ ("ppacb " #rd ", " #rs ", " #rt )
+
+#define prevh(rt, rd) \
+ __asm__ __volatile__ ("prevh " #rd ", " #rt )
+
+#define pmulth(rs, rt, rd) \
+ __asm__ __volatile__ ("pmulth " #rd ", " #rs ", " #rt )
+
+#define pmaxh(rs, rt, rd) \
+ __asm__ __volatile__ ("pmaxh " #rd ", " #rs ", " #rt )
+
+#define pminh(rs, rt, rd) \
+ __asm__ __volatile__ ("pminh " #rd ", " #rs ", " #rt )
+
+#define pinteh(rs, rt, rd) \
+ __asm__ __volatile__ ("pinteh " #rd ", " #rs ", " #rt )
+
+#define paddh(rs, rt, rd) \
+ __asm__ __volatile__ ("paddh " #rd ", " #rs ", " #rt )
+
+#define psubh(rs, rt, rd) \
+ __asm__ __volatile__ ("psubh " #rd ", " #rs ", " #rt )
+
+#define psrah(rt, sa, rd) \
+ __asm__ __volatile__ ("psrah " #rd ", " #rt ", %0" : : "i"(sa) )
+
+#define pmfhl_uw(rd) \
+ __asm__ __volatile__ ("pmfhl.uw " #rd)
+
+#define pextlb(rs, rt, rd) \
+ __asm__ __volatile__ ("pextlb " #rd ", " #rs ", " #rt )
+
+#endif
+
diff --git a/contrib/ffmpeg/libavcodec/ps2/mpegvideo_mmi.c b/contrib/ffmpeg/libavcodec/ps2/mpegvideo_mmi.c
new file mode 100644
index 000000000..1e5f08aae
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/ps2/mpegvideo_mmi.c
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2000,2001 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
+ *
+ * MMI optimization by Leon van Stuivenberg
+ */
+
+#include "../dsputil.h"
+#include "../mpegvideo.h"
+#include "../avcodec.h"
+
+static void dct_unquantize_h263_mmi(MpegEncContext *s,
+ DCTELEM *block, int n, int qscale)
+{
+ int level=0, qmul, qadd;
+ int nCoeffs;
+
+ assert(s->block_last_index[n]>=0);
+
+ qadd = (qscale - 1) | 1;
+ qmul = qscale << 1;
+
+ if (s->mb_intra) {
+ if (!s->h263_aic) {
+ if (n < 4)
+ level = block[0] * s->y_dc_scale;
+ else
+ level = block[0] * s->c_dc_scale;
+ }else {
+ qadd = 0;
+ level = block[0];
+ }
+ nCoeffs= 63; //does not allways use zigzag table
+ } else {
+ nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ];
+ }
+
+ asm volatile(
+ "add $14, $0, %3 \n\t"
+ "pcpyld $8, %0, %0 \n\t"
+ "pcpyh $8, $8 \n\t" //r8 = qmul
+ "pcpyld $9, %1, %1 \n\t"
+ "pcpyh $9, $9 \n\t" //r9 = qadd
+ ".p2align 2 \n\t"
+ "1: \n\t"
+ "lq $10, 0($14) \n\t" //r10 = level
+ "addi $14, $14, 16 \n\t" //block+=8
+ "addi %2, %2, -8 \n\t"
+ "pcgth $11, $0, $10 \n\t" //r11 = level < 0 ? -1 : 0
+ "pcgth $12, $10, $0 \n\t" //r12 = level > 0 ? -1 : 0
+ "por $12, $11, $12 \n\t"
+ "pmulth $10, $10, $8 \n\t"
+ "paddh $13, $9, $11 \n\t"
+ "pxor $13, $13, $11 \n\t" //r13 = level < 0 ? -qadd : qadd
+ "pmfhl.uw $11 \n\t"
+ "pinteh $10, $11, $10 \n\t" //r10 = level * qmul
+ "paddh $10, $10, $13 \n\t"
+ "pand $10, $10, $12 \n\t"
+ "sq $10, -16($14) \n\t"
+ "bgez %2, 1b \n\t"
+ :: "r"(qmul), "r" (qadd), "r" (nCoeffs), "r" (block) : "$8", "$9", "$10", "$11", "$12", "$13", "$14", "memory" );
+
+ if(s->mb_intra)
+ block[0]= level;
+}
+
+
+void MPV_common_init_mmi(MpegEncContext *s)
+{
+ s->dct_unquantize_h263_intra =
+ s->dct_unquantize_h263_inter = dct_unquantize_h263_mmi;
+}
+
+
diff --git a/contrib/ffmpeg/libavcodec/pthread.c b/contrib/ffmpeg/libavcodec/pthread.c
new file mode 100644
index 000000000..f2c636bbe
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/pthread.c
@@ -0,0 +1,170 @@
+/*
+ * Copyright (c) 2004 Roman Shaposhnik.
+ *
+ * Many thanks to Steven M. Schultz for providing clever ideas and
+ * to Michael Niedermayer <michaelni@gmx.at> for writing initial
+ * implementation.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 <pthread.h>
+
+#include "avcodec.h"
+#include "common.h"
+
+typedef int (action_t)(AVCodecContext *c, void *arg);
+
+typedef struct ThreadContext {
+ pthread_t *workers;
+ action_t *func;
+ void **args;
+ int *rets;
+ int rets_count;
+ int job_count;
+
+ pthread_cond_t last_job_cond;
+ pthread_cond_t current_job_cond;
+ pthread_mutex_t current_job_lock;
+ int current_job;
+ int done;
+} ThreadContext;
+
+static void* worker(void *v)
+{
+ AVCodecContext *avctx = v;
+ ThreadContext *c = avctx->thread_opaque;
+ int our_job = c->job_count;
+ int thread_count = avctx->thread_count;
+ int self_id;
+
+ pthread_mutex_lock(&c->current_job_lock);
+ self_id = c->current_job++;
+ for (;;){
+ while (our_job >= c->job_count) {
+ if (c->current_job == thread_count + c->job_count)
+ pthread_cond_signal(&c->last_job_cond);
+
+ pthread_cond_wait(&c->current_job_cond, &c->current_job_lock);
+ our_job = self_id;
+
+ if (c->done) {
+ pthread_mutex_unlock(&c->current_job_lock);
+ return NULL;
+ }
+ }
+ pthread_mutex_unlock(&c->current_job_lock);
+
+ c->rets[our_job%c->rets_count] = c->func(avctx, c->args[our_job]);
+
+ pthread_mutex_lock(&c->current_job_lock);
+ our_job = c->current_job++;
+ }
+}
+
+static av_always_inline void avcodec_thread_park_workers(ThreadContext *c, int thread_count)
+{
+ pthread_cond_wait(&c->last_job_cond, &c->current_job_lock);
+ pthread_mutex_unlock(&c->current_job_lock);
+}
+
+void avcodec_thread_free(AVCodecContext *avctx)
+{
+ ThreadContext *c = avctx->thread_opaque;
+ int i;
+
+ pthread_mutex_lock(&c->current_job_lock);
+ c->done = 1;
+ pthread_cond_broadcast(&c->current_job_cond);
+ pthread_mutex_unlock(&c->current_job_lock);
+
+ for (i=0; i<avctx->thread_count; i++)
+ pthread_join(c->workers[i], NULL);
+
+ pthread_mutex_destroy(&c->current_job_lock);
+ pthread_cond_destroy(&c->current_job_cond);
+ pthread_cond_destroy(&c->last_job_cond);
+ av_free(c->workers);
+ av_free(c);
+}
+
+int avcodec_thread_execute(AVCodecContext *avctx, action_t* func, void **arg, int *ret, int job_count)
+{
+ ThreadContext *c= avctx->thread_opaque;
+ int dummy_ret;
+
+ if (job_count <= 0)
+ return 0;
+
+ pthread_mutex_lock(&c->current_job_lock);
+
+ c->current_job = avctx->thread_count;
+ c->job_count = job_count;
+ c->args = arg;
+ c->func = func;
+ if (ret) {
+ c->rets = ret;
+ c->rets_count = job_count;
+ } else {
+ c->rets = &dummy_ret;
+ c->rets_count = 1;
+ }
+ pthread_cond_broadcast(&c->current_job_cond);
+
+ avcodec_thread_park_workers(c, avctx->thread_count);
+
+ return 0;
+}
+
+int avcodec_thread_init(AVCodecContext *avctx, int thread_count)
+{
+ int i;
+ ThreadContext *c;
+
+ c = av_mallocz(sizeof(ThreadContext));
+ if (!c)
+ return -1;
+
+ c->workers = av_mallocz(sizeof(pthread_t)*thread_count);
+ if (!c->workers) {
+ av_free(c);
+ return -1;
+ }
+
+ avctx->thread_opaque = c;
+ avctx->thread_count = thread_count;
+ c->current_job = 0;
+ c->job_count = 0;
+ c->done = 0;
+ pthread_cond_init(&c->current_job_cond, NULL);
+ pthread_cond_init(&c->last_job_cond, NULL);
+ pthread_mutex_init(&c->current_job_lock, NULL);
+ pthread_mutex_lock(&c->current_job_lock);
+ for (i=0; i<thread_count; i++) {
+ if(pthread_create(&c->workers[i], NULL, worker, avctx)) {
+ avctx->thread_count = i;
+ pthread_mutex_unlock(&c->current_job_lock);
+ avcodec_thread_free(avctx);
+ return -1;
+ }
+ }
+
+ avcodec_thread_park_workers(c, thread_count);
+
+ avctx->execute = avcodec_thread_execute;
+ return 0;
+}
diff --git a/src/libffmpeg/libavcodec/qdm2.c b/contrib/ffmpeg/libavcodec/qdm2.c
index a2630fe7f..a2630fe7f 100644
--- a/src/libffmpeg/libavcodec/qdm2.c
+++ b/contrib/ffmpeg/libavcodec/qdm2.c
diff --git a/src/libffmpeg/libavcodec/qdm2data.h b/contrib/ffmpeg/libavcodec/qdm2data.h
index 6d7d07463..6d7d07463 100644
--- a/src/libffmpeg/libavcodec/qdm2data.h
+++ b/contrib/ffmpeg/libavcodec/qdm2data.h
diff --git a/src/libffmpeg/libavcodec/qdrw.c b/contrib/ffmpeg/libavcodec/qdrw.c
index 664be2f4f..664be2f4f 100644
--- a/src/libffmpeg/libavcodec/qdrw.c
+++ b/contrib/ffmpeg/libavcodec/qdrw.c
diff --git a/contrib/ffmpeg/libavcodec/qpeg.c b/contrib/ffmpeg/libavcodec/qpeg.c
new file mode 100644
index 000000000..d995bc3b7
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/qpeg.c
@@ -0,0 +1,323 @@
+/*
+ * QPEG codec
+ * Copyright (c) 2004 Konstantin Shishkov
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * @file qpeg.c
+ * QPEG codec.
+ */
+
+#include "avcodec.h"
+#include "mpegvideo.h"
+
+typedef struct QpegContext{
+ AVCodecContext *avctx;
+ AVFrame pic;
+ uint8_t *refdata;
+} QpegContext;
+
+static void qpeg_decode_intra(uint8_t *src, uint8_t *dst, int size,
+ int stride, int width, int height)
+{
+ int i;
+ int code;
+ int c0, c1;
+ int run, copy;
+ int filled = 0;
+ int rows_to_go;
+
+ rows_to_go = height;
+ height--;
+ dst = dst + height * stride;
+
+ while((size > 0) && (rows_to_go > 0)) {
+ code = *src++;
+ size--;
+ run = copy = 0;
+ if(code == 0xFC) /* end-of-picture code */
+ break;
+ if(code >= 0xF8) { /* very long run */
+ c0 = *src++;
+ c1 = *src++;
+ size -= 2;
+ run = ((code & 0x7) << 16) + (c0 << 8) + c1 + 2;
+ } else if (code >= 0xF0) { /* long run */
+ c0 = *src++;
+ size--;
+ run = ((code & 0xF) << 8) + c0 + 2;
+ } else if (code >= 0xE0) { /* short run */
+ run = (code & 0x1F) + 2;
+ } else if (code >= 0xC0) { /* very long copy */
+ c0 = *src++;
+ c1 = *src++;
+ size -= 2;
+ copy = ((code & 0x3F) << 16) + (c0 << 8) + c1 + 1;
+ } else if (code >= 0x80) { /* long copy */
+ c0 = *src++;
+ size--;
+ copy = ((code & 0x7F) << 8) + c0 + 1;
+ } else { /* short copy */
+ copy = code + 1;
+ }
+
+ /* perform actual run or copy */
+ if(run) {
+ int p;
+
+ p = *src++;
+ size--;
+ for(i = 0; i < run; i++) {
+ dst[filled++] = p;
+ if (filled >= width) {
+ filled = 0;
+ dst -= stride;
+ rows_to_go--;
+ if(rows_to_go <= 0)
+ break;
+ }
+ }
+ } else {
+ size -= copy;
+ for(i = 0; i < copy; i++) {
+ dst[filled++] = *src++;
+ if (filled >= width) {
+ filled = 0;
+ dst -= stride;
+ rows_to_go--;
+ if(rows_to_go <= 0)
+ break;
+ }
+ }
+ }
+ }
+}
+
+static int qpeg_table_h[16] =
+ { 0x00, 0x20, 0x20, 0x20, 0x18, 0x10, 0x10, 0x20, 0x10, 0x08, 0x18, 0x08, 0x08, 0x18, 0x10, 0x04};
+static int qpeg_table_w[16] =
+ { 0x00, 0x20, 0x18, 0x08, 0x18, 0x10, 0x20, 0x10, 0x08, 0x10, 0x20, 0x20, 0x08, 0x10, 0x18, 0x04};
+
+/* Decodes delta frames */
+static void qpeg_decode_inter(uint8_t *src, uint8_t *dst, int size,
+ int stride, int width, int height,
+ int delta, uint8_t *ctable, uint8_t *refdata)
+{
+ int i, j;
+ int code;
+ int filled = 0;
+ int orig_height;
+ uint8_t *blkdata;
+
+ /* copy prev frame */
+ for(i = 0; i < height; i++)
+ memcpy(refdata + (i * width), dst + (i * stride), width);
+
+ orig_height = height;
+ blkdata = src - 0x86;
+ height--;
+ dst = dst + height * stride;
+
+ while((size > 0) && (height >= 0)) {
+ code = *src++;
+ size--;
+
+ if(delta) {
+ /* motion compensation */
+ while((code & 0xF0) == 0xF0) {
+ if(delta == 1) {
+ int me_idx;
+ int me_w, me_h, me_x, me_y;
+ uint8_t *me_plane;
+ int corr, val;
+
+ /* get block size by index */
+ me_idx = code & 0xF;
+ me_w = qpeg_table_w[me_idx];
+ me_h = qpeg_table_h[me_idx];
+
+ /* extract motion vector */
+ corr = *src++;
+ size--;
+
+ val = corr >> 4;
+ if(val > 7)
+ val -= 16;
+ me_x = val;
+
+ val = corr & 0xF;
+ if(val > 7)
+ val -= 16;
+ me_y = val;
+
+ /* check motion vector */
+ if ((me_x + filled < 0) || (me_x + me_w + filled > width) ||
+ (height - me_y - me_h < 0) || (height - me_y > orig_height) ||
+ (filled + me_w > width) || (height - me_h < 0))
+ av_log(NULL, AV_LOG_ERROR, "Bogus motion vector (%i,%i), block size %ix%i at %i,%i\n",
+ me_x, me_y, me_w, me_h, filled, height);
+ else {
+ /* do motion compensation */
+ me_plane = refdata + (filled + me_x) + (height - me_y) * width;
+ for(j = 0; j < me_h; j++) {
+ for(i = 0; i < me_w; i++)
+ dst[filled + i - (j * stride)] = me_plane[i - (j * width)];
+ }
+ }
+ }
+ code = *src++;
+ size--;
+ }
+ }
+
+ if(code == 0xE0) /* end-of-picture code */
+ break;
+ if(code > 0xE0) { /* run code: 0xE1..0xFF */
+ int p;
+
+ code &= 0x1F;
+ p = *src++;
+ size--;
+ for(i = 0; i <= code; i++) {
+ dst[filled++] = p;
+ if(filled >= width) {
+ filled = 0;
+ dst -= stride;
+ height--;
+ }
+ }
+ } else if(code >= 0xC0) { /* copy code: 0xC0..0xDF */
+ code &= 0x1F;
+
+ for(i = 0; i <= code; i++) {
+ dst[filled++] = *src++;
+ if(filled >= width) {
+ filled = 0;
+ dst -= stride;
+ height--;
+ }
+ }
+ size -= code + 1;
+ } else if(code >= 0x80) { /* skip code: 0x80..0xBF */
+ int skip;
+
+ code &= 0x3F;
+ /* codes 0x80 and 0x81 are actually escape codes,
+ skip value minus constant is in the next byte */
+ if(!code)
+ skip = (*src++) + 64;
+ else if(code == 1)
+ skip = (*src++) + 320;
+ else
+ skip = code;
+ filled += skip;
+ while( filled >= width) {
+ filled -= width;
+ dst -= stride;
+ height--;
+ if(height < 0)
+ break;
+ }
+ } else {
+ /* zero code treated as one-pixel skip */
+ if(code)
+ dst[filled++] = ctable[code & 0x7F];
+ else
+ filled++;
+ if(filled >= width) {
+ filled = 0;
+ dst -= stride;
+ height--;
+ }
+ }
+ }
+}
+
+static int decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ QpegContext * const a = avctx->priv_data;
+ AVFrame * const p= (AVFrame*)&a->pic;
+ uint8_t* outdata;
+ int delta;
+
+ 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;
+ }
+ outdata = a->pic.data[0];
+ if(buf[0x85] == 0x10) {
+ qpeg_decode_intra(buf+0x86, outdata, buf_size - 0x86, a->pic.linesize[0], avctx->width, avctx->height);
+ } else {
+ delta = buf[0x85];
+ qpeg_decode_inter(buf+0x86, outdata, buf_size - 0x86, a->pic.linesize[0], avctx->width, avctx->height, delta, buf + 4, a->refdata);
+ }
+
+ /* make the palette available on the way out */
+ memcpy(a->pic.data[1], a->avctx->palctrl->palette, AVPALETTE_SIZE);
+ if (a->avctx->palctrl->palette_changed) {
+ a->pic.palette_has_changed = 1;
+ a->avctx->palctrl->palette_changed = 0;
+ }
+
+ *data_size = sizeof(AVFrame);
+ *(AVFrame*)data = a->pic;
+
+ return buf_size;
+}
+
+static int decode_init(AVCodecContext *avctx){
+ QpegContext * const a = avctx->priv_data;
+
+ a->avctx = avctx;
+ avctx->pix_fmt= PIX_FMT_PAL8;
+ a->pic.data[0] = NULL;
+ a->refdata = av_malloc(avctx->width * avctx->height);
+
+ return 0;
+}
+
+static int decode_end(AVCodecContext *avctx){
+ QpegContext * const a = avctx->priv_data;
+ AVFrame * const p= (AVFrame*)&a->pic;
+
+ if(p->data[0])
+ avctx->release_buffer(avctx, p);
+
+ av_free(a->refdata);
+ return 0;
+}
+
+AVCodec qpeg_decoder = {
+ "qpeg",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_QPEG,
+ sizeof(QpegContext),
+ decode_init,
+ NULL,
+ decode_end,
+ decode_frame,
+ CODEC_CAP_DR1,
+};
diff --git a/contrib/ffmpeg/libavcodec/qtrle.c b/contrib/ffmpeg/libavcodec/qtrle.c
new file mode 100644
index 000000000..415f08098
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/qtrle.c
@@ -0,0 +1,630 @@
+/*
+ * Quicktime Animation (RLE) Video Decoder
+ * Copyright (C) 2004 the ffmpeg project
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * @file qtrle.c
+ * 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/
+ *
+ * The QT RLE decoder has seven modes of operation:
+ * 1, 2, 4, 8, 16, 24, and 32 bits per pixel. For modes 1, 2, 4, and 8
+ * the decoder outputs PAL8 colorspace data. 16-bit data yields RGB555
+ * data. 24-bit data is RGB24 and 32-bit data is RGB32.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "common.h"
+#include "avcodec.h"
+#include "dsputil.h"
+
+typedef struct QtrleContext {
+
+ AVCodecContext *avctx;
+ DSPContext dsp;
+ AVFrame frame;
+
+ unsigned char *buf;
+ int size;
+
+} QtrleContext;
+
+#define CHECK_STREAM_PTR(n) \
+ if ((stream_ptr + n) > s->size) { \
+ av_log (s->avctx, AV_LOG_INFO, "Problem: stream_ptr out of bounds (%d >= %d)\n", \
+ stream_ptr + n, s->size); \
+ return; \
+ }
+
+#define CHECK_PIXEL_PTR(n) \
+ if ((pixel_ptr + n > pixel_limit) || (pixel_ptr + n < 0)) { \
+ av_log (s->avctx, AV_LOG_INFO, "Problem: pixel_ptr = %d, pixel_limit = %d\n", \
+ pixel_ptr + n, pixel_limit); \
+ return; \
+ } \
+
+static void qtrle_decode_1bpp(QtrleContext *s)
+{
+}
+
+static void qtrle_decode_2bpp(QtrleContext *s)
+{
+}
+
+static void qtrle_decode_4bpp(QtrleContext *s)
+{
+ int stream_ptr;
+ int header;
+ int start_line;
+ int lines_to_change;
+ int rle_code;
+ int row_ptr, pixel_ptr;
+ int row_inc = s->frame.linesize[0];
+ unsigned char pi1, pi2, pi3, pi4, pi5, pi6, pi7, pi8; /* 8 palette indices */
+ unsigned char *rgb = s->frame.data[0];
+ int pixel_limit = s->frame.linesize[0] * s->avctx->height;
+
+ /* check if this frame is even supposed to change */
+ if (s->size < 8)
+ return;
+
+ /* start after the chunk size */
+ stream_ptr = 4;
+
+ /* fetch the header */
+ CHECK_STREAM_PTR(2);
+ header = AV_RB16(&s->buf[stream_ptr]);
+ stream_ptr += 2;
+
+ /* if a header is present, fetch additional decoding parameters */
+ if (header & 0x0008) {
+ CHECK_STREAM_PTR(8);
+ start_line = AV_RB16(&s->buf[stream_ptr]);
+ stream_ptr += 4;
+ lines_to_change = AV_RB16(&s->buf[stream_ptr]);
+ stream_ptr += 4;
+ } else {
+ start_line = 0;
+ lines_to_change = s->avctx->height;
+ }
+
+ row_ptr = row_inc * start_line;
+ while (lines_to_change--) {
+ CHECK_STREAM_PTR(2);
+ pixel_ptr = row_ptr + (8 * (s->buf[stream_ptr++] - 1));
+
+ while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) {
+ if (rle_code == 0) {
+ /* there's another skip code in the stream */
+ CHECK_STREAM_PTR(1);
+ pixel_ptr += (8 * (s->buf[stream_ptr++] - 1));
+ CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */
+ } else if (rle_code < 0) {
+ /* decode the run length code */
+ rle_code = -rle_code;
+ /* get the next 4 bytes from the stream, treat them as palette
+ * indices, and output them rle_code times */
+ CHECK_STREAM_PTR(4);
+ pi1 = ((s->buf[stream_ptr]) >> 4) & 0x0f;
+ pi2 = (s->buf[stream_ptr++]) & 0x0f;
+ pi3 = ((s->buf[stream_ptr]) >> 4) & 0x0f;
+ pi4 = (s->buf[stream_ptr++]) & 0x0f;
+ pi5 = ((s->buf[stream_ptr]) >> 4) & 0x0f;
+ pi6 = (s->buf[stream_ptr++]) & 0x0f;
+ pi7 = ((s->buf[stream_ptr]) >> 4) & 0x0f;
+ pi8 = (s->buf[stream_ptr++]) & 0x0f;
+
+ CHECK_PIXEL_PTR(rle_code * 8);
+
+ while (rle_code--) {
+ rgb[pixel_ptr++] = pi1;
+ rgb[pixel_ptr++] = pi2;
+ rgb[pixel_ptr++] = pi3;
+ rgb[pixel_ptr++] = pi4;
+ rgb[pixel_ptr++] = pi5;
+ rgb[pixel_ptr++] = pi6;
+ rgb[pixel_ptr++] = pi7;
+ rgb[pixel_ptr++] = pi8;
+ }
+ } else {
+ /* copy the same pixel directly to output 4 times */
+ rle_code *= 4;
+ CHECK_STREAM_PTR(rle_code);
+ CHECK_PIXEL_PTR(rle_code*2);
+
+ while (rle_code--) {
+ rgb[pixel_ptr++] = ((s->buf[stream_ptr]) >> 4) & 0x0f;
+ rgb[pixel_ptr++] = (s->buf[stream_ptr++]) & 0x0f;
+ }
+ }
+ }
+ row_ptr += row_inc;
+ }
+}
+
+static void qtrle_decode_8bpp(QtrleContext *s)
+{
+ int stream_ptr;
+ int header;
+ int start_line;
+ int lines_to_change;
+ int rle_code;
+ int row_ptr, pixel_ptr;
+ int row_inc = s->frame.linesize[0];
+ unsigned char pi1, pi2, pi3, pi4; /* 4 palette indices */
+ unsigned char *rgb = s->frame.data[0];
+ int pixel_limit = s->frame.linesize[0] * s->avctx->height;
+
+ /* check if this frame is even supposed to change */
+ if (s->size < 8)
+ return;
+
+ /* start after the chunk size */
+ stream_ptr = 4;
+
+ /* fetch the header */
+ CHECK_STREAM_PTR(2);
+ header = AV_RB16(&s->buf[stream_ptr]);
+ stream_ptr += 2;
+
+ /* if a header is present, fetch additional decoding parameters */
+ if (header & 0x0008) {
+ CHECK_STREAM_PTR(8);
+ start_line = AV_RB16(&s->buf[stream_ptr]);
+ stream_ptr += 4;
+ lines_to_change = AV_RB16(&s->buf[stream_ptr]);
+ stream_ptr += 4;
+ } else {
+ start_line = 0;
+ lines_to_change = s->avctx->height;
+ }
+
+ row_ptr = row_inc * start_line;
+ while (lines_to_change--) {
+ CHECK_STREAM_PTR(2);
+ pixel_ptr = row_ptr + (4 * (s->buf[stream_ptr++] - 1));
+
+ while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) {
+ if (rle_code == 0) {
+ /* there's another skip code in the stream */
+ CHECK_STREAM_PTR(1);
+ pixel_ptr += (4 * (s->buf[stream_ptr++] - 1));
+ CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */
+ } else if (rle_code < 0) {
+ /* decode the run length code */
+ rle_code = -rle_code;
+ /* get the next 4 bytes from the stream, treat them as palette
+ * indices, and output them rle_code times */
+ CHECK_STREAM_PTR(4);
+ pi1 = s->buf[stream_ptr++];
+ pi2 = s->buf[stream_ptr++];
+ pi3 = s->buf[stream_ptr++];
+ pi4 = s->buf[stream_ptr++];
+
+ CHECK_PIXEL_PTR(rle_code * 4);
+
+ while (rle_code--) {
+ rgb[pixel_ptr++] = pi1;
+ rgb[pixel_ptr++] = pi2;
+ rgb[pixel_ptr++] = pi3;
+ rgb[pixel_ptr++] = pi4;
+ }
+ } else {
+ /* copy the same pixel directly to output 4 times */
+ rle_code *= 4;
+ CHECK_STREAM_PTR(rle_code);
+ CHECK_PIXEL_PTR(rle_code);
+
+ while (rle_code--) {
+ rgb[pixel_ptr++] = s->buf[stream_ptr++];
+ }
+ }
+ }
+ row_ptr += row_inc;
+ }
+}
+
+static void qtrle_decode_16bpp(QtrleContext *s)
+{
+ int stream_ptr;
+ int header;
+ int start_line;
+ int lines_to_change;
+ int rle_code;
+ int row_ptr, pixel_ptr;
+ int row_inc = s->frame.linesize[0];
+ unsigned short rgb16;
+ unsigned char *rgb = s->frame.data[0];
+ int pixel_limit = s->frame.linesize[0] * s->avctx->height;
+
+ /* check if this frame is even supposed to change */
+ if (s->size < 8)
+ return;
+
+ /* start after the chunk size */
+ stream_ptr = 4;
+
+ /* fetch the header */
+ CHECK_STREAM_PTR(2);
+ header = AV_RB16(&s->buf[stream_ptr]);
+ stream_ptr += 2;
+
+ /* if a header is present, fetch additional decoding parameters */
+ if (header & 0x0008) {
+ CHECK_STREAM_PTR(8);
+ start_line = AV_RB16(&s->buf[stream_ptr]);
+ stream_ptr += 4;
+ lines_to_change = AV_RB16(&s->buf[stream_ptr]);
+ stream_ptr += 4;
+ } else {
+ start_line = 0;
+ lines_to_change = s->avctx->height;
+ }
+
+ row_ptr = row_inc * start_line;
+ while (lines_to_change--) {
+ CHECK_STREAM_PTR(2);
+ pixel_ptr = row_ptr + (s->buf[stream_ptr++] - 1) * 2;
+
+ while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) {
+ if (rle_code == 0) {
+ /* there's another skip code in the stream */
+ CHECK_STREAM_PTR(1);
+ pixel_ptr += (s->buf[stream_ptr++] - 1) * 2;
+ CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */
+ } else if (rle_code < 0) {
+ /* decode the run length code */
+ rle_code = -rle_code;
+ CHECK_STREAM_PTR(2);
+ rgb16 = AV_RB16(&s->buf[stream_ptr]);
+ stream_ptr += 2;
+
+ CHECK_PIXEL_PTR(rle_code * 2);
+
+ while (rle_code--) {
+ *(unsigned short *)(&rgb[pixel_ptr]) = rgb16;
+ pixel_ptr += 2;
+ }
+ } else {
+ CHECK_STREAM_PTR(rle_code * 2);
+ CHECK_PIXEL_PTR(rle_code * 2);
+
+ /* copy pixels directly to output */
+ while (rle_code--) {
+ rgb16 = AV_RB16(&s->buf[stream_ptr]);
+ stream_ptr += 2;
+ *(unsigned short *)(&rgb[pixel_ptr]) = rgb16;
+ pixel_ptr += 2;
+ }
+ }
+ }
+ row_ptr += row_inc;
+ }
+}
+
+static void qtrle_decode_24bpp(QtrleContext *s)
+{
+ int stream_ptr;
+ int header;
+ int start_line;
+ int lines_to_change;
+ int rle_code;
+ int row_ptr, pixel_ptr;
+ int row_inc = s->frame.linesize[0];
+ unsigned char r, g, b;
+ unsigned char *rgb = s->frame.data[0];
+ int pixel_limit = s->frame.linesize[0] * s->avctx->height;
+
+ /* check if this frame is even supposed to change */
+ if (s->size < 8)
+ return;
+
+ /* start after the chunk size */
+ stream_ptr = 4;
+
+ /* fetch the header */
+ CHECK_STREAM_PTR(2);
+ header = AV_RB16(&s->buf[stream_ptr]);
+ stream_ptr += 2;
+
+ /* if a header is present, fetch additional decoding parameters */
+ if (header & 0x0008) {
+ CHECK_STREAM_PTR(8);
+ start_line = AV_RB16(&s->buf[stream_ptr]);
+ stream_ptr += 4;
+ lines_to_change = AV_RB16(&s->buf[stream_ptr]);
+ stream_ptr += 4;
+ } else {
+ start_line = 0;
+ lines_to_change = s->avctx->height;
+ }
+
+ row_ptr = row_inc * start_line;
+ while (lines_to_change--) {
+ CHECK_STREAM_PTR(2);
+ pixel_ptr = row_ptr + (s->buf[stream_ptr++] - 1) * 3;
+
+ while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) {
+ if (rle_code == 0) {
+ /* there's another skip code in the stream */
+ CHECK_STREAM_PTR(1);
+ pixel_ptr += (s->buf[stream_ptr++] - 1) * 3;
+ CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */
+ } else if (rle_code < 0) {
+ /* decode the run length code */
+ rle_code = -rle_code;
+ CHECK_STREAM_PTR(3);
+ r = s->buf[stream_ptr++];
+ g = s->buf[stream_ptr++];
+ b = s->buf[stream_ptr++];
+
+ CHECK_PIXEL_PTR(rle_code * 3);
+
+ while (rle_code--) {
+ rgb[pixel_ptr++] = r;
+ rgb[pixel_ptr++] = g;
+ rgb[pixel_ptr++] = b;
+ }
+ } else {
+ CHECK_STREAM_PTR(rle_code * 3);
+ CHECK_PIXEL_PTR(rle_code * 3);
+
+ /* copy pixels directly to output */
+ while (rle_code--) {
+ rgb[pixel_ptr++] = s->buf[stream_ptr++];
+ rgb[pixel_ptr++] = s->buf[stream_ptr++];
+ rgb[pixel_ptr++] = s->buf[stream_ptr++];
+ }
+ }
+ }
+ row_ptr += row_inc;
+ }
+}
+
+static void qtrle_decode_32bpp(QtrleContext *s)
+{
+ int stream_ptr;
+ int header;
+ int start_line;
+ int lines_to_change;
+ int rle_code;
+ int row_ptr, pixel_ptr;
+ int row_inc = s->frame.linesize[0];
+ unsigned char a, r, g, b;
+ unsigned int argb;
+ unsigned char *rgb = s->frame.data[0];
+ int pixel_limit = s->frame.linesize[0] * s->avctx->height;
+
+ /* check if this frame is even supposed to change */
+ if (s->size < 8)
+ return;
+
+ /* start after the chunk size */
+ stream_ptr = 4;
+
+ /* fetch the header */
+ CHECK_STREAM_PTR(2);
+ header = AV_RB16(&s->buf[stream_ptr]);
+ stream_ptr += 2;
+
+ /* if a header is present, fetch additional decoding parameters */
+ if (header & 0x0008) {
+ CHECK_STREAM_PTR(8);
+ start_line = AV_RB16(&s->buf[stream_ptr]);
+ stream_ptr += 4;
+ lines_to_change = AV_RB16(&s->buf[stream_ptr]);
+ stream_ptr += 4;
+ } else {
+ start_line = 0;
+ lines_to_change = s->avctx->height;
+ }
+
+ row_ptr = row_inc * start_line;
+ while (lines_to_change--) {
+ CHECK_STREAM_PTR(2);
+ pixel_ptr = row_ptr + (s->buf[stream_ptr++] - 1) * 4;
+
+ while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) {
+ if (rle_code == 0) {
+ /* there's another skip code in the stream */
+ CHECK_STREAM_PTR(1);
+ pixel_ptr += (s->buf[stream_ptr++] - 1) * 4;
+ CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */
+ } else if (rle_code < 0) {
+ /* decode the run length code */
+ rle_code = -rle_code;
+ CHECK_STREAM_PTR(4);
+ a = s->buf[stream_ptr++];
+ r = s->buf[stream_ptr++];
+ g = s->buf[stream_ptr++];
+ b = s->buf[stream_ptr++];
+ argb = (a << 24) | (r << 16) | (g << 8) | (b << 0);
+
+ CHECK_PIXEL_PTR(rle_code * 4);
+
+ while (rle_code--) {
+ *(unsigned int *)(&rgb[pixel_ptr]) = argb;
+ pixel_ptr += 4;
+ }
+ } else {
+ CHECK_STREAM_PTR(rle_code * 4);
+ CHECK_PIXEL_PTR(rle_code * 4);
+
+ /* copy pixels directly to output */
+ while (rle_code--) {
+ a = s->buf[stream_ptr++];
+ r = s->buf[stream_ptr++];
+ g = s->buf[stream_ptr++];
+ b = s->buf[stream_ptr++];
+ argb = (a << 24) | (r << 16) | (g << 8) | (b << 0);
+ *(unsigned int *)(&rgb[pixel_ptr]) = argb;
+ pixel_ptr += 4;
+ }
+ }
+ }
+ row_ptr += row_inc;
+ }
+}
+
+static int qtrle_decode_init(AVCodecContext *avctx)
+{
+ QtrleContext *s = (QtrleContext *)avctx->priv_data;
+
+ s->avctx = avctx;
+ switch (avctx->bits_per_sample) {
+ case 1:
+ case 2:
+ case 4:
+ case 8:
+ case 33:
+ case 34:
+ case 36:
+ case 40:
+ avctx->pix_fmt = PIX_FMT_PAL8;
+ break;
+
+ case 16:
+ avctx->pix_fmt = PIX_FMT_RGB555;
+ break;
+
+ case 24:
+ avctx->pix_fmt = PIX_FMT_RGB24;
+ break;
+
+ case 32:
+ avctx->pix_fmt = PIX_FMT_RGB32;
+ break;
+
+ default:
+ av_log (avctx, AV_LOG_ERROR, "Unsupported colorspace: %d bits/sample?\n",
+ avctx->bits_per_sample);
+ break;
+ }
+ avctx->has_b_frames = 0;
+ dsputil_init(&s->dsp, avctx);
+
+ s->frame.data[0] = NULL;
+
+ return 0;
+}
+
+static int qtrle_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ QtrleContext *s = (QtrleContext *)avctx->priv_data;
+
+ s->buf = buf;
+ s->size = buf_size;
+
+ s->frame.reference = 1;
+ s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE |
+ FF_BUFFER_HINTS_REUSABLE | FF_BUFFER_HINTS_READABLE;
+ if (avctx->reget_buffer(avctx, &s->frame)) {
+ av_log (s->avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
+ return -1;
+ }
+
+ switch (avctx->bits_per_sample) {
+ case 1:
+ case 33:
+ qtrle_decode_1bpp(s);
+ break;
+
+ case 2:
+ case 34:
+ qtrle_decode_2bpp(s);
+ break;
+
+ case 4:
+ case 36:
+ qtrle_decode_4bpp(s);
+ /* make the palette available on the way out */
+ memcpy(s->frame.data[1], s->avctx->palctrl->palette, AVPALETTE_SIZE);
+ if (s->avctx->palctrl->palette_changed) {
+ s->frame.palette_has_changed = 1;
+ s->avctx->palctrl->palette_changed = 0;
+ }
+ break;
+
+ case 8:
+ case 40:
+ qtrle_decode_8bpp(s);
+ /* make the palette available on the way out */
+ memcpy(s->frame.data[1], s->avctx->palctrl->palette, AVPALETTE_SIZE);
+ if (s->avctx->palctrl->palette_changed) {
+ s->frame.palette_has_changed = 1;
+ s->avctx->palctrl->palette_changed = 0;
+ }
+ break;
+
+ case 16:
+ qtrle_decode_16bpp(s);
+ break;
+
+ case 24:
+ qtrle_decode_24bpp(s);
+ break;
+
+ case 32:
+ qtrle_decode_32bpp(s);
+ break;
+
+ default:
+ av_log (s->avctx, AV_LOG_ERROR, "Unsupported colorspace: %d bits/sample?\n",
+ avctx->bits_per_sample);
+ break;
+ }
+
+ *data_size = sizeof(AVFrame);
+ *(AVFrame*)data = s->frame;
+
+ /* always report that the buffer was completely consumed */
+ return buf_size;
+}
+
+static int qtrle_decode_end(AVCodecContext *avctx)
+{
+ QtrleContext *s = (QtrleContext *)avctx->priv_data;
+
+ if (s->frame.data[0])
+ avctx->release_buffer(avctx, &s->frame);
+
+ return 0;
+}
+
+AVCodec qtrle_decoder = {
+ "qtrle",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_QTRLE,
+ sizeof(QtrleContext),
+ qtrle_decode_init,
+ NULL,
+ qtrle_decode_end,
+ qtrle_decode_frame,
+ CODEC_CAP_DR1,
+};
+
diff --git a/src/libffmpeg/libavcodec/ra144.c b/contrib/ffmpeg/libavcodec/ra144.c
index c4f4b813b..c4f4b813b 100644
--- a/src/libffmpeg/libavcodec/ra144.c
+++ b/contrib/ffmpeg/libavcodec/ra144.c
diff --git a/src/libffmpeg/libavcodec/ra144.h b/contrib/ffmpeg/libavcodec/ra144.h
index 6d477b2f8..6d477b2f8 100644
--- a/src/libffmpeg/libavcodec/ra144.h
+++ b/contrib/ffmpeg/libavcodec/ra144.h
diff --git a/src/libffmpeg/libavcodec/ra288.c b/contrib/ffmpeg/libavcodec/ra288.c
index 9ba5209ab..9ba5209ab 100644
--- a/src/libffmpeg/libavcodec/ra288.c
+++ b/contrib/ffmpeg/libavcodec/ra288.c
diff --git a/src/libffmpeg/libavcodec/ra288.h b/contrib/ffmpeg/libavcodec/ra288.h
index 8cc290397..8cc290397 100644
--- a/src/libffmpeg/libavcodec/ra288.h
+++ b/contrib/ffmpeg/libavcodec/ra288.h
diff --git a/src/libffmpeg/libavcodec/rangecoder.c b/contrib/ffmpeg/libavcodec/rangecoder.c
index fcd564ace..fcd564ace 100644
--- a/src/libffmpeg/libavcodec/rangecoder.c
+++ b/contrib/ffmpeg/libavcodec/rangecoder.c
diff --git a/src/libffmpeg/libavcodec/rangecoder.h b/contrib/ffmpeg/libavcodec/rangecoder.h
index 68bd3b60e..68bd3b60e 100644
--- a/src/libffmpeg/libavcodec/rangecoder.h
+++ b/contrib/ffmpeg/libavcodec/rangecoder.h
diff --git a/contrib/ffmpeg/libavcodec/ratecontrol.c b/contrib/ffmpeg/libavcodec/ratecontrol.c
new file mode 100644
index 000000000..6d9270da8
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/ratecontrol.c
@@ -0,0 +1,944 @@
+/*
+ * Rate control for video encoders
+ *
+ * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file ratecontrol.c
+ * Rate control for video encoders.
+ */
+
+#include "avcodec.h"
+#include "dsputil.h"
+#include "ratecontrol.h"
+#include "mpegvideo.h"
+#include "eval.h"
+
+#undef NDEBUG // allways check asserts, the speed effect is far too small to disable them
+#include <assert.h>
+
+#ifndef M_E
+#define M_E 2.718281828
+#endif
+
+static int init_pass2(MpegEncContext *s);
+static double get_qscale(MpegEncContext *s, RateControlEntry *rce, double rate_factor, int frame_num);
+
+void ff_write_pass1_stats(MpegEncContext *s){
+ snprintf(s->avctx->stats_out, 256, "in:%d out:%d type:%d q:%d itex:%d ptex:%d mv:%d misc:%d fcode:%d bcode:%d mc-var:%d var:%d icount:%d skipcount:%d hbits:%d;\n",
+ s->current_picture_ptr->display_picture_number, s->current_picture_ptr->coded_picture_number, s->pict_type,
+ s->current_picture.quality, s->i_tex_bits, s->p_tex_bits, s->mv_bits, s->misc_bits,
+ s->f_code, s->b_code, s->current_picture.mc_mb_var_sum, s->current_picture.mb_var_sum, s->i_count, s->skip_count, s->header_bits);
+}
+
+static inline double qp2bits(RateControlEntry *rce, double qp){
+ if(qp<=0.0){
+ av_log(NULL, AV_LOG_ERROR, "qp<=0.0\n");
+ }
+ return rce->qscale * (double)(rce->i_tex_bits + rce->p_tex_bits+1)/ qp;
+}
+
+static inline double bits2qp(RateControlEntry *rce, double bits){
+ if(bits<0.9){
+ av_log(NULL, AV_LOG_ERROR, "bits<0.9\n");
+ }
+ return rce->qscale * (double)(rce->i_tex_bits + rce->p_tex_bits+1)/ bits;
+}
+
+int ff_rate_control_init(MpegEncContext *s)
+{
+ RateControlContext *rcc= &s->rc_context;
+ int i;
+ char *error = NULL;
+ static const char *const_names[]={
+ "PI",
+ "E",
+ "iTex",
+ "pTex",
+ "tex",
+ "mv",
+ "fCode",
+ "iCount",
+ "mcVar",
+ "var",
+ "isI",
+ "isP",
+ "isB",
+ "avgQP",
+ "qComp",
+/* "lastIQP",
+ "lastPQP",
+ "lastBQP",
+ "nextNonBQP",*/
+ "avgIITex",
+ "avgPITex",
+ "avgPPTex",
+ "avgBPTex",
+ "avgTex",
+ NULL
+ };
+ static double (*func1[])(void *, double)={
+ (void *)bits2qp,
+ (void *)qp2bits,
+ NULL
+ };
+ static const char *func1_names[]={
+ "bits2qp",
+ "qp2bits",
+ NULL
+ };
+ emms_c();
+
+ rcc->rc_eq_eval = ff_parse(s->avctx->rc_eq, 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;
+ }
+
+ for(i=0; i<5; i++){
+ rcc->pred[i].coeff= FF_QP2LAMBDA * 7.0;
+ rcc->pred[i].count= 1.0;
+
+ rcc->pred[i].decay= 0.4;
+ rcc->i_cplx_sum [i]=
+ rcc->p_cplx_sum [i]=
+ rcc->mv_bits_sum[i]=
+ rcc->qscale_sum [i]=
+ rcc->frame_count[i]= 1; // 1 is better cuz of 1/0 and such
+ rcc->last_qscale_for[i]=FF_QP2LAMBDA * 5;
+ }
+ rcc->buffer_index= s->avctx->rc_initial_buffer_occupancy;
+
+ if(s->flags&CODEC_FLAG_PASS2){
+ int i;
+ char *p;
+
+ /* find number of pics */
+ p= s->avctx->stats_in;
+ for(i=-1; p; i++){
+ p= strchr(p+1, ';');
+ }
+ i+= s->max_b_frames;
+ if(i<=0 || i>=INT_MAX / sizeof(RateControlEntry))
+ return -1;
+ rcc->entry = (RateControlEntry*)av_mallocz(i*sizeof(RateControlEntry));
+ rcc->num_entries= i;
+
+ /* init all to skipped p frames (with b frames we might have a not encoded frame at the end FIXME) */
+ for(i=0; i<rcc->num_entries; i++){
+ RateControlEntry *rce= &rcc->entry[i];
+ rce->pict_type= rce->new_pict_type=P_TYPE;
+ rce->qscale= rce->new_qscale=FF_QP2LAMBDA * 2;
+ rce->misc_bits= s->mb_num + 10;
+ rce->mb_var_sum= s->mb_num*100;
+ }
+
+ /* read stats */
+ p= s->avctx->stats_in;
+ for(i=0; i<rcc->num_entries - s->max_b_frames; i++){
+ RateControlEntry *rce;
+ int picture_number;
+ int e;
+ char *next;
+
+ next= strchr(p, ';');
+ if(next){
+ (*next)=0; //sscanf in unbelieavle slow on looong strings //FIXME copy / dont write
+ next++;
+ }
+ e= sscanf(p, " in:%d ", &picture_number);
+
+ assert(picture_number >= 0);
+ assert(picture_number < rcc->num_entries);
+ rce= &rcc->entry[picture_number];
+
+ e+=sscanf(p, " in:%*d out:%*d type:%d q:%f itex:%d ptex:%d mv:%d misc:%d fcode:%d bcode:%d mc-var:%d var:%d icount:%d skipcount:%d hbits:%d",
+ &rce->pict_type, &rce->qscale, &rce->i_tex_bits, &rce->p_tex_bits, &rce->mv_bits, &rce->misc_bits,
+ &rce->f_code, &rce->b_code, &rce->mc_mb_var_sum, &rce->mb_var_sum, &rce->i_count, &rce->skip_count, &rce->header_bits);
+ if(e!=14){
+ av_log(s->avctx, AV_LOG_ERROR, "statistics are damaged at line %d, parser out=%d\n", i, e);
+ return -1;
+ }
+
+ p= next;
+ }
+
+ if(init_pass2(s) < 0) return -1;
+
+ //FIXME maybe move to end
+ if((s->flags&CODEC_FLAG_PASS2) && s->avctx->rc_strategy == FF_RC_STRATEGY_XVID) {
+#ifdef CONFIG_XVID
+ return ff_xvid_rate_control_init(s);
+#else
+ av_log(s->avctx, AV_LOG_ERROR, "XviD ratecontrol requires libavcodec compiled with XviD support\n");
+ return -1;
+#endif
+ }
+ }
+
+ if(!(s->flags&CODEC_FLAG_PASS2)){
+
+ rcc->short_term_qsum=0.001;
+ rcc->short_term_qcount=0.001;
+
+ rcc->pass1_rc_eq_output_sum= 0.001;
+ rcc->pass1_wanted_bits=0.001;
+
+ /* init stuff with the user specified complexity */
+ if(s->avctx->rc_initial_cplx){
+ for(i=0; i<60*30; i++){
+ double bits= s->avctx->rc_initial_cplx * (i/10000.0 + 1.0)*s->mb_num;
+ RateControlEntry rce;
+ double q;
+
+ if (i%((s->gop_size+3)/4)==0) rce.pict_type= I_TYPE;
+ else if(i%(s->max_b_frames+1)) rce.pict_type= B_TYPE;
+ else rce.pict_type= P_TYPE;
+
+ rce.new_pict_type= rce.pict_type;
+ rce.mc_mb_var_sum= bits*s->mb_num/100000;
+ rce.mb_var_sum = s->mb_num;
+ rce.qscale = FF_QP2LAMBDA * 2;
+ rce.f_code = 2;
+ rce.b_code = 1;
+ rce.misc_bits= 1;
+
+ if(s->pict_type== I_TYPE){
+ rce.i_count = s->mb_num;
+ rce.i_tex_bits= bits;
+ rce.p_tex_bits= 0;
+ rce.mv_bits= 0;
+ }else{
+ rce.i_count = 0; //FIXME we do know this approx
+ rce.i_tex_bits= 0;
+ rce.p_tex_bits= bits*0.9;
+ rce.mv_bits= bits*0.1;
+ }
+ rcc->i_cplx_sum [rce.pict_type] += rce.i_tex_bits*rce.qscale;
+ rcc->p_cplx_sum [rce.pict_type] += rce.p_tex_bits*rce.qscale;
+ rcc->mv_bits_sum[rce.pict_type] += rce.mv_bits;
+ rcc->frame_count[rce.pict_type] ++;
+
+ bits= rce.i_tex_bits + rce.p_tex_bits;
+
+ q= get_qscale(s, &rce, rcc->pass1_wanted_bits/rcc->pass1_rc_eq_output_sum, i);
+ rcc->pass1_wanted_bits+= s->bit_rate/(1/av_q2d(s->avctx->time_base)); //FIXME missbehaves a little for variable fps
+ }
+ }
+
+ }
+
+ return 0;
+}
+
+void ff_rate_control_uninit(MpegEncContext *s)
+{
+ RateControlContext *rcc= &s->rc_context;
+ emms_c();
+
+ ff_eval_free(rcc->rc_eq_eval);
+ av_freep(&rcc->entry);
+
+#ifdef CONFIG_XVID
+ if((s->flags&CODEC_FLAG_PASS2) && s->avctx->rc_strategy == FF_RC_STRATEGY_XVID)
+ ff_xvid_rate_control_uninit(s);
+#endif
+}
+
+int ff_vbv_update(MpegEncContext *s, int frame_size){
+ RateControlContext *rcc= &s->rc_context;
+ const double fps= 1/av_q2d(s->avctx->time_base);
+ const int buffer_size= s->avctx->rc_buffer_size;
+ const double min_rate= s->avctx->rc_min_rate/fps;
+ const double max_rate= s->avctx->rc_max_rate/fps;
+
+//printf("%d %f %d %f %f\n", buffer_size, rcc->buffer_index, frame_size, min_rate, max_rate);
+ if(buffer_size){
+ int left;
+
+ rcc->buffer_index-= frame_size;
+ if(rcc->buffer_index < 0){
+ av_log(s->avctx, AV_LOG_ERROR, "rc buffer underflow\n");
+ rcc->buffer_index= 0;
+ }
+
+ left= buffer_size - rcc->buffer_index - 1;
+ rcc->buffer_index += av_clip(left, min_rate, max_rate);
+
+ if(rcc->buffer_index > buffer_size){
+ int stuffing= ceil((rcc->buffer_index - buffer_size)/8);
+
+ if(stuffing < 4 && s->codec_id == CODEC_ID_MPEG4)
+ stuffing=4;
+ rcc->buffer_index -= 8*stuffing;
+
+ if(s->avctx->debug & FF_DEBUG_RC)
+ av_log(s->avctx, AV_LOG_DEBUG, "stuffing %d bytes\n", stuffing);
+
+ return stuffing;
+ }
+ }
+ return 0;
+}
+
+/**
+ * modifies the bitrate curve from pass1 for one frame
+ */
+static double get_qscale(MpegEncContext *s, RateControlEntry *rce, double rate_factor, int frame_num){
+ RateControlContext *rcc= &s->rc_context;
+ AVCodecContext *a= s->avctx;
+ double q, bits;
+ const int pict_type= rce->new_pict_type;
+ const double mb_num= s->mb_num;
+ int i;
+
+ double const_values[]={
+ M_PI,
+ M_E,
+ rce->i_tex_bits*rce->qscale,
+ rce->p_tex_bits*rce->qscale,
+ (rce->i_tex_bits + rce->p_tex_bits)*(double)rce->qscale,
+ rce->mv_bits/mb_num,
+ rce->pict_type == B_TYPE ? (rce->f_code + rce->b_code)*0.5 : rce->f_code,
+ rce->i_count/mb_num,
+ rce->mc_mb_var_sum/mb_num,
+ rce->mb_var_sum/mb_num,
+ rce->pict_type == I_TYPE,
+ rce->pict_type == P_TYPE,
+ rce->pict_type == B_TYPE,
+ rcc->qscale_sum[pict_type] / (double)rcc->frame_count[pict_type],
+ a->qcompress,
+/* rcc->last_qscale_for[I_TYPE],
+ rcc->last_qscale_for[P_TYPE],
+ rcc->last_qscale_for[B_TYPE],
+ rcc->next_non_b_qscale,*/
+ rcc->i_cplx_sum[I_TYPE] / (double)rcc->frame_count[I_TYPE],
+ rcc->i_cplx_sum[P_TYPE] / (double)rcc->frame_count[P_TYPE],
+ rcc->p_cplx_sum[P_TYPE] / (double)rcc->frame_count[P_TYPE],
+ rcc->p_cplx_sum[B_TYPE] / (double)rcc->frame_count[B_TYPE],
+ (rcc->i_cplx_sum[pict_type] + rcc->p_cplx_sum[pict_type]) / (double)rcc->frame_count[pict_type],
+ 0
+ };
+
+ bits= ff_parse_eval(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;
+ }
+
+ rcc->pass1_rc_eq_output_sum+= bits;
+ bits*=rate_factor;
+ if(bits<0.0) bits=0.0;
+ bits+= 1.0; //avoid 1/0 issues
+
+ /* user override */
+ for(i=0; i<s->avctx->rc_override_count; i++){
+ RcOverride *rco= s->avctx->rc_override;
+ if(rco[i].start_frame > frame_num) continue;
+ if(rco[i].end_frame < frame_num) continue;
+
+ if(rco[i].qscale)
+ bits= qp2bits(rce, rco[i].qscale); //FIXME move at end to really force it?
+ else
+ bits*= rco[i].quality_factor;
+ }
+
+ q= bits2qp(rce, bits);
+
+ /* I/B difference */
+ if (pict_type==I_TYPE && s->avctx->i_quant_factor<0.0)
+ q= -q*s->avctx->i_quant_factor + s->avctx->i_quant_offset;
+ else if(pict_type==B_TYPE && s->avctx->b_quant_factor<0.0)
+ q= -q*s->avctx->b_quant_factor + s->avctx->b_quant_offset;
+
+ return q;
+}
+
+static double get_diff_limited_q(MpegEncContext *s, RateControlEntry *rce, double q){
+ RateControlContext *rcc= &s->rc_context;
+ AVCodecContext *a= s->avctx;
+ const int pict_type= rce->new_pict_type;
+ const double last_p_q = rcc->last_qscale_for[P_TYPE];
+ const double last_non_b_q= rcc->last_qscale_for[rcc->last_non_b_pict_type];
+
+ if (pict_type==I_TYPE && (a->i_quant_factor>0.0 || rcc->last_non_b_pict_type==P_TYPE))
+ q= last_p_q *FFABS(a->i_quant_factor) + a->i_quant_offset;
+ else if(pict_type==B_TYPE && a->b_quant_factor>0.0)
+ q= last_non_b_q* a->b_quant_factor + a->b_quant_offset;
+
+ /* last qscale / qdiff stuff */
+ if(rcc->last_non_b_pict_type==pict_type || pict_type!=I_TYPE){
+ double last_q= rcc->last_qscale_for[pict_type];
+ const int maxdiff= FF_QP2LAMBDA * a->max_qdiff;
+
+ if (q > last_q + maxdiff) q= last_q + maxdiff;
+ else if(q < last_q - maxdiff) q= last_q - maxdiff;
+ }
+
+ rcc->last_qscale_for[pict_type]= q; //Note we cant do that after blurring
+
+ if(pict_type!=B_TYPE)
+ rcc->last_non_b_pict_type= pict_type;
+
+ return q;
+}
+
+/**
+ * gets the qmin & qmax for pict_type
+ */
+static void get_qminmax(int *qmin_ret, int *qmax_ret, MpegEncContext *s, int pict_type){
+ int qmin= s->avctx->lmin;
+ int qmax= s->avctx->lmax;
+
+ assert(qmin <= qmax);
+
+ if(pict_type==B_TYPE){
+ qmin= (int)(qmin*FFABS(s->avctx->b_quant_factor)+s->avctx->b_quant_offset + 0.5);
+ qmax= (int)(qmax*FFABS(s->avctx->b_quant_factor)+s->avctx->b_quant_offset + 0.5);
+ }else if(pict_type==I_TYPE){
+ qmin= (int)(qmin*FFABS(s->avctx->i_quant_factor)+s->avctx->i_quant_offset + 0.5);
+ qmax= (int)(qmax*FFABS(s->avctx->i_quant_factor)+s->avctx->i_quant_offset + 0.5);
+ }
+
+ qmin= av_clip(qmin, 1, FF_LAMBDA_MAX);
+ qmax= av_clip(qmax, 1, FF_LAMBDA_MAX);
+
+ if(qmax<qmin) qmax= qmin;
+
+ *qmin_ret= qmin;
+ *qmax_ret= qmax;
+}
+
+static double modify_qscale(MpegEncContext *s, RateControlEntry *rce, double q, int frame_num){
+ RateControlContext *rcc= &s->rc_context;
+ int qmin, qmax;
+ double bits;
+ const int pict_type= rce->new_pict_type;
+ const double buffer_size= s->avctx->rc_buffer_size;
+ const double fps= 1/av_q2d(s->avctx->time_base);
+ const double min_rate= s->avctx->rc_min_rate / fps;
+ const double max_rate= s->avctx->rc_max_rate / fps;
+
+ get_qminmax(&qmin, &qmax, s, pict_type);
+
+ /* modulation */
+ if(s->avctx->rc_qmod_freq && frame_num%s->avctx->rc_qmod_freq==0 && pict_type==P_TYPE)
+ q*= s->avctx->rc_qmod_amp;
+
+ bits= qp2bits(rce, q);
+//printf("q:%f\n", q);
+ /* buffer overflow/underflow protection */
+ if(buffer_size){
+ double expected_size= rcc->buffer_index;
+ double q_limit;
+
+ if(min_rate){
+ double d= 2*(buffer_size - expected_size)/buffer_size;
+ if(d>1.0) d=1.0;
+ else if(d<0.0001) d=0.0001;
+ q*= pow(d, 1.0/s->avctx->rc_buffer_aggressivity);
+
+ q_limit= bits2qp(rce, FFMAX((min_rate - buffer_size + rcc->buffer_index)*3, 1));
+ if(q > q_limit){
+ if(s->avctx->debug&FF_DEBUG_RC){
+ av_log(s->avctx, AV_LOG_DEBUG, "limiting QP %f -> %f\n", q, q_limit);
+ }
+ q= q_limit;
+ }
+ }
+
+ if(max_rate){
+ double d= 2*expected_size/buffer_size;
+ if(d>1.0) d=1.0;
+ else if(d<0.0001) d=0.0001;
+ q/= pow(d, 1.0/s->avctx->rc_buffer_aggressivity);
+
+ q_limit= bits2qp(rce, FFMAX(rcc->buffer_index/3, 1));
+ if(q < q_limit){
+ if(s->avctx->debug&FF_DEBUG_RC){
+ av_log(s->avctx, AV_LOG_DEBUG, "limiting QP %f -> %f\n", q, q_limit);
+ }
+ q= q_limit;
+ }
+ }
+ }
+//printf("q:%f max:%f min:%f size:%f index:%d bits:%f agr:%f\n", q,max_rate, min_rate, buffer_size, rcc->buffer_index, bits, s->avctx->rc_buffer_aggressivity);
+ if(s->avctx->rc_qsquish==0.0 || qmin==qmax){
+ if (q<qmin) q=qmin;
+ else if(q>qmax) q=qmax;
+ }else{
+ double min2= log(qmin);
+ double max2= log(qmax);
+
+ q= log(q);
+ q= (q - min2)/(max2-min2) - 0.5;
+ q*= -4.0;
+ q= 1.0/(1.0 + exp(q));
+ q= q*(max2-min2) + min2;
+
+ q= exp(q);
+ }
+
+ return q;
+}
+
+//----------------------------------
+// 1 Pass Code
+
+static double predict_size(Predictor *p, double q, double var)
+{
+ return p->coeff*var / (q*p->count);
+}
+
+/*
+static double predict_qp(Predictor *p, double size, double var)
+{
+//printf("coeff:%f, count:%f, var:%f, size:%f//\n", p->coeff, p->count, var, size);
+ return p->coeff*var / (size*p->count);
+}
+*/
+
+static void update_predictor(Predictor *p, double q, double var, double size)
+{
+ double new_coeff= size*q / (var + 1);
+ if(var<10) return;
+
+ p->count*= p->decay;
+ p->coeff*= p->decay;
+ p->count++;
+ p->coeff+= new_coeff;
+}
+
+static void adaptive_quantization(MpegEncContext *s, double q){
+ int i;
+ const float lumi_masking= s->avctx->lumi_masking / (128.0*128.0);
+ const float dark_masking= s->avctx->dark_masking / (128.0*128.0);
+ const float temp_cplx_masking= s->avctx->temporal_cplx_masking;
+ const float spatial_cplx_masking = s->avctx->spatial_cplx_masking;
+ const float p_masking = s->avctx->p_masking;
+ const float border_masking = s->avctx->border_masking;
+ float bits_sum= 0.0;
+ float cplx_sum= 0.0;
+ float cplx_tab[s->mb_num];
+ float bits_tab[s->mb_num];
+ const int qmin= s->avctx->mb_lmin;
+ const int qmax= s->avctx->mb_lmax;
+ Picture * const pic= &s->current_picture;
+ const int mb_width = s->mb_width;
+ const int mb_height = s->mb_height;
+
+ for(i=0; i<s->mb_num; i++){
+ const int mb_xy= s->mb_index2xy[i];
+ float temp_cplx= sqrt(pic->mc_mb_var[mb_xy]); //FIXME merge in pow()
+ float spat_cplx= sqrt(pic->mb_var[mb_xy]);
+ const int lumi= pic->mb_mean[mb_xy];
+ float bits, cplx, factor;
+ int mb_x = mb_xy % s->mb_stride;
+ int mb_y = mb_xy / s->mb_stride;
+ int mb_distance;
+ float mb_factor = 0.0;
+#if 0
+ if(spat_cplx < q/3) spat_cplx= q/3; //FIXME finetune
+ if(temp_cplx < q/3) temp_cplx= q/3; //FIXME finetune
+#endif
+ if(spat_cplx < 4) spat_cplx= 4; //FIXME finetune
+ if(temp_cplx < 4) temp_cplx= 4; //FIXME finetune
+
+ if((s->mb_type[mb_xy]&CANDIDATE_MB_TYPE_INTRA)){//FIXME hq mode
+ cplx= spat_cplx;
+ factor= 1.0 + p_masking;
+ }else{
+ cplx= temp_cplx;
+ factor= pow(temp_cplx, - temp_cplx_masking);
+ }
+ factor*=pow(spat_cplx, - spatial_cplx_masking);
+
+ if(lumi>127)
+ factor*= (1.0 - (lumi-128)*(lumi-128)*lumi_masking);
+ else
+ factor*= (1.0 - (lumi-128)*(lumi-128)*dark_masking);
+
+ if(mb_x < mb_width/5){
+ mb_distance = mb_width/5 - mb_x;
+ mb_factor = (float)mb_distance / (float)(mb_width/5);
+ }else if(mb_x > 4*mb_width/5){
+ mb_distance = mb_x - 4*mb_width/5;
+ mb_factor = (float)mb_distance / (float)(mb_width/5);
+ }
+ if(mb_y < mb_height/5){
+ mb_distance = mb_height/5 - mb_y;
+ mb_factor = FFMAX(mb_factor, (float)mb_distance / (float)(mb_height/5));
+ }else if(mb_y > 4*mb_height/5){
+ mb_distance = mb_y - 4*mb_height/5;
+ mb_factor = FFMAX(mb_factor, (float)mb_distance / (float)(mb_height/5));
+ }
+
+ factor*= 1.0 - border_masking*mb_factor;
+
+ if(factor<0.00001) factor= 0.00001;
+
+ bits= cplx*factor;
+ cplx_sum+= cplx;
+ bits_sum+= bits;
+ cplx_tab[i]= cplx;
+ bits_tab[i]= bits;
+ }
+
+ /* handle qmin/qmax cliping */
+ if(s->flags&CODEC_FLAG_NORMALIZE_AQP){
+ float factor= bits_sum/cplx_sum;
+ for(i=0; i<s->mb_num; i++){
+ float newq= q*cplx_tab[i]/bits_tab[i];
+ newq*= factor;
+
+ if (newq > qmax){
+ bits_sum -= bits_tab[i];
+ cplx_sum -= cplx_tab[i]*q/qmax;
+ }
+ else if(newq < qmin){
+ bits_sum -= bits_tab[i];
+ cplx_sum -= cplx_tab[i]*q/qmin;
+ }
+ }
+ if(bits_sum < 0.001) bits_sum= 0.001;
+ if(cplx_sum < 0.001) cplx_sum= 0.001;
+ }
+
+ for(i=0; i<s->mb_num; i++){
+ const int mb_xy= s->mb_index2xy[i];
+ float newq= q*cplx_tab[i]/bits_tab[i];
+ int intq;
+
+ if(s->flags&CODEC_FLAG_NORMALIZE_AQP){
+ newq*= bits_sum/cplx_sum;
+ }
+
+ intq= (int)(newq + 0.5);
+
+ if (intq > qmax) intq= qmax;
+ else if(intq < qmin) intq= qmin;
+//if(i%s->mb_width==0) printf("\n");
+//printf("%2d%3d ", intq, ff_sqrt(s->mc_mb_var[i]));
+ s->lambda_table[mb_xy]= intq;
+ }
+}
+
+void ff_get_2pass_fcode(MpegEncContext *s){
+ RateControlContext *rcc= &s->rc_context;
+ int picture_number= s->picture_number;
+ RateControlEntry *rce;
+
+ rce= &rcc->entry[picture_number];
+ s->f_code= rce->f_code;
+ s->b_code= rce->b_code;
+}
+
+//FIXME rd or at least approx for dquant
+
+float ff_rate_estimate_qscale(MpegEncContext *s, int dry_run)
+{
+ float q;
+ int qmin, qmax;
+ float br_compensation;
+ double diff;
+ double short_term_q;
+ double fps;
+ int picture_number= s->picture_number;
+ int64_t wanted_bits;
+ RateControlContext *rcc= &s->rc_context;
+ AVCodecContext *a= s->avctx;
+ RateControlEntry local_rce, *rce;
+ double bits;
+ double rate_factor;
+ int var;
+ const int pict_type= s->pict_type;
+ Picture * const pic= &s->current_picture;
+ emms_c();
+
+#ifdef CONFIG_XVID
+ if((s->flags&CODEC_FLAG_PASS2) && s->avctx->rc_strategy == FF_RC_STRATEGY_XVID)
+ return ff_xvid_rate_estimate_qscale(s, dry_run);
+#endif
+
+ get_qminmax(&qmin, &qmax, s, pict_type);
+
+ fps= 1/av_q2d(s->avctx->time_base);
+//printf("input_pic_num:%d pic_num:%d frame_rate:%d\n", s->input_picture_number, s->picture_number, s->frame_rate);
+ /* update predictors */
+ if(picture_number>2 && !dry_run){
+ const int last_var= s->last_pict_type == I_TYPE ? rcc->last_mb_var_sum : rcc->last_mc_mb_var_sum;
+ update_predictor(&rcc->pred[s->last_pict_type], rcc->last_qscale, sqrt(last_var), s->frame_bits);
+ }
+
+ if(s->flags&CODEC_FLAG_PASS2){
+ assert(picture_number>=0);
+ assert(picture_number<rcc->num_entries);
+ rce= &rcc->entry[picture_number];
+ wanted_bits= rce->expected_bits;
+ }else{
+ rce= &local_rce;
+ wanted_bits= (uint64_t)(s->bit_rate*(double)picture_number/fps);
+ }
+
+ diff= s->total_bits - wanted_bits;
+ br_compensation= (a->bit_rate_tolerance - diff)/a->bit_rate_tolerance;
+ if(br_compensation<=0.0) br_compensation=0.001;
+
+ var= pict_type == I_TYPE ? pic->mb_var_sum : pic->mc_mb_var_sum;
+
+ short_term_q = 0; /* avoid warning */
+ if(s->flags&CODEC_FLAG_PASS2){
+ if(pict_type!=I_TYPE)
+ assert(pict_type == rce->new_pict_type);
+
+ q= rce->new_qscale / br_compensation;
+//printf("%f %f %f last:%d var:%d type:%d//\n", q, rce->new_qscale, br_compensation, s->frame_bits, var, pict_type);
+ }else{
+ rce->pict_type=
+ rce->new_pict_type= pict_type;
+ rce->mc_mb_var_sum= pic->mc_mb_var_sum;
+ rce->mb_var_sum = pic-> mb_var_sum;
+ rce->qscale = FF_QP2LAMBDA * 2;
+ rce->f_code = s->f_code;
+ rce->b_code = s->b_code;
+ rce->misc_bits= 1;
+
+ bits= predict_size(&rcc->pred[pict_type], rce->qscale, sqrt(var));
+ if(pict_type== I_TYPE){
+ rce->i_count = s->mb_num;
+ rce->i_tex_bits= bits;
+ rce->p_tex_bits= 0;
+ rce->mv_bits= 0;
+ }else{
+ rce->i_count = 0; //FIXME we do know this approx
+ rce->i_tex_bits= 0;
+ rce->p_tex_bits= bits*0.9;
+
+ rce->mv_bits= bits*0.1;
+ }
+ rcc->i_cplx_sum [pict_type] += rce->i_tex_bits*rce->qscale;
+ rcc->p_cplx_sum [pict_type] += rce->p_tex_bits*rce->qscale;
+ rcc->mv_bits_sum[pict_type] += rce->mv_bits;
+ rcc->frame_count[pict_type] ++;
+
+ bits= rce->i_tex_bits + rce->p_tex_bits;
+ rate_factor= rcc->pass1_wanted_bits/rcc->pass1_rc_eq_output_sum * br_compensation;
+
+ q= get_qscale(s, rce, rate_factor, picture_number);
+ if (q < 0)
+ return -1;
+
+ assert(q>0.0);
+//printf("%f ", q);
+ q= get_diff_limited_q(s, rce, q);
+//printf("%f ", q);
+ assert(q>0.0);
+
+ if(pict_type==P_TYPE || s->intra_only){ //FIXME type dependent blur like in 2-pass
+ rcc->short_term_qsum*=a->qblur;
+ rcc->short_term_qcount*=a->qblur;
+
+ rcc->short_term_qsum+= q;
+ rcc->short_term_qcount++;
+//printf("%f ", q);
+ q= short_term_q= rcc->short_term_qsum/rcc->short_term_qcount;
+//printf("%f ", q);
+ }
+ assert(q>0.0);
+
+ q= modify_qscale(s, rce, q, picture_number);
+
+ rcc->pass1_wanted_bits+= s->bit_rate/fps;
+
+ assert(q>0.0);
+ }
+
+ if(s->avctx->debug&FF_DEBUG_RC){
+ av_log(s->avctx, AV_LOG_DEBUG, "%c qp:%d<%2.1f<%d %d want:%d total:%d comp:%f st_q:%2.2f size:%d var:%d/%d br:%d fps:%d\n",
+ av_get_pict_type_char(pict_type), qmin, q, qmax, picture_number, (int)wanted_bits/1000, (int)s->total_bits/1000,
+ br_compensation, short_term_q, s->frame_bits, pic->mb_var_sum, pic->mc_mb_var_sum, s->bit_rate/1000, (int)fps
+ );
+ }
+
+ if (q<qmin) q=qmin;
+ else if(q>qmax) q=qmax;
+
+ if(s->adaptive_quant)
+ adaptive_quantization(s, q);
+ else
+ q= (int)(q + 0.5);
+
+ if(!dry_run){
+ rcc->last_qscale= q;
+ rcc->last_mc_mb_var_sum= pic->mc_mb_var_sum;
+ rcc->last_mb_var_sum= pic->mb_var_sum;
+ }
+#if 0
+{
+ static int mvsum=0, texsum=0;
+ mvsum += s->mv_bits;
+ texsum += s->i_tex_bits + s->p_tex_bits;
+ printf("%d %d//\n\n", mvsum, texsum);
+}
+#endif
+ return q;
+}
+
+//----------------------------------------------
+// 2-Pass code
+
+static int init_pass2(MpegEncContext *s)
+{
+ RateControlContext *rcc= &s->rc_context;
+ AVCodecContext *a= s->avctx;
+ int i, toobig;
+ double fps= 1/av_q2d(s->avctx->time_base);
+ double complexity[5]={0,0,0,0,0}; // aproximate bits at quant=1
+ uint64_t const_bits[5]={0,0,0,0,0}; // quantizer independent bits
+ uint64_t all_const_bits;
+ uint64_t all_available_bits= (uint64_t)(s->bit_rate*(double)rcc->num_entries/fps);
+ double rate_factor=0;
+ double step;
+ //int last_i_frame=-10000000;
+ const int filter_size= (int)(a->qblur*4) | 1;
+ double expected_bits;
+ double *qscale, *blured_qscale, qscale_sum;
+
+ /* find complexity & const_bits & decide the pict_types */
+ for(i=0; i<rcc->num_entries; i++){
+ RateControlEntry *rce= &rcc->entry[i];
+
+ rce->new_pict_type= rce->pict_type;
+ rcc->i_cplx_sum [rce->pict_type] += rce->i_tex_bits*rce->qscale;
+ rcc->p_cplx_sum [rce->pict_type] += rce->p_tex_bits*rce->qscale;
+ rcc->mv_bits_sum[rce->pict_type] += rce->mv_bits;
+ rcc->frame_count[rce->pict_type] ++;
+
+ complexity[rce->new_pict_type]+= (rce->i_tex_bits+ rce->p_tex_bits)*(double)rce->qscale;
+ const_bits[rce->new_pict_type]+= rce->mv_bits + rce->misc_bits;
+ }
+ all_const_bits= const_bits[I_TYPE] + const_bits[P_TYPE] + const_bits[B_TYPE];
+
+ if(all_available_bits < all_const_bits){
+ av_log(s->avctx, AV_LOG_ERROR, "requested bitrate is too low\n");
+ return -1;
+ }
+
+ qscale= av_malloc(sizeof(double)*rcc->num_entries);
+ blured_qscale= av_malloc(sizeof(double)*rcc->num_entries);
+ toobig = 0;
+
+ for(step=256*256; step>0.0000001; step*=0.5){
+ expected_bits=0;
+ rate_factor+= step;
+
+ rcc->buffer_index= s->avctx->rc_buffer_size/2;
+
+ /* find qscale */
+ for(i=0; i<rcc->num_entries; i++){
+ qscale[i]= get_qscale(s, &rcc->entry[i], rate_factor, i);
+ }
+ assert(filter_size%2==1);
+
+ /* fixed I/B QP relative to P mode */
+ for(i=rcc->num_entries-1; i>=0; i--){
+ RateControlEntry *rce= &rcc->entry[i];
+
+ qscale[i]= get_diff_limited_q(s, rce, qscale[i]);
+ }
+
+ /* smooth curve */
+ for(i=0; i<rcc->num_entries; i++){
+ RateControlEntry *rce= &rcc->entry[i];
+ const int pict_type= rce->new_pict_type;
+ int j;
+ double q=0.0, sum=0.0;
+
+ for(j=0; j<filter_size; j++){
+ int index= i+j-filter_size/2;
+ double d= index-i;
+ double coeff= a->qblur==0 ? 1.0 : exp(-d*d/(a->qblur * a->qblur));
+
+ if(index < 0 || index >= rcc->num_entries) continue;
+ if(pict_type != rcc->entry[index].new_pict_type) continue;
+ q+= qscale[index] * coeff;
+ sum+= coeff;
+ }
+ blured_qscale[i]= q/sum;
+ }
+
+ /* find expected bits */
+ for(i=0; i<rcc->num_entries; i++){
+ RateControlEntry *rce= &rcc->entry[i];
+ double bits;
+ rce->new_qscale= modify_qscale(s, rce, blured_qscale[i], i);
+ bits= qp2bits(rce, rce->new_qscale) + rce->mv_bits + rce->misc_bits;
+//printf("%d %f\n", rce->new_bits, blured_qscale[i]);
+ bits += 8*ff_vbv_update(s, bits);
+
+ rce->expected_bits= expected_bits;
+ expected_bits += bits;
+ }
+
+ /*
+ av_log(s->avctx, AV_LOG_INFO,
+ "expected_bits: %f all_available_bits: %d rate_factor: %f\n",
+ expected_bits, (int)all_available_bits, rate_factor);
+ */
+ if(expected_bits > all_available_bits) {
+ rate_factor-= step;
+ ++toobig;
+ }
+ }
+ av_free(qscale);
+ av_free(blured_qscale);
+
+ /* check bitrate calculations and print info */
+ qscale_sum = 0.0;
+ for(i=0; i<rcc->num_entries; i++){
+ /* av_log(s->avctx, AV_LOG_DEBUG, "[lavc rc] entry[%d].new_qscale = %.3f qp = %.3f\n",
+ i, rcc->entry[i].new_qscale, rcc->entry[i].new_qscale / FF_QP2LAMBDA); */
+ qscale_sum += av_clip(rcc->entry[i].new_qscale / FF_QP2LAMBDA, s->avctx->qmin, s->avctx->qmax);
+ }
+ assert(toobig <= 40);
+ av_log(s->avctx, AV_LOG_DEBUG,
+ "[lavc rc] requested bitrate: %d bps expected bitrate: %d bps\n",
+ s->bit_rate,
+ (int)(expected_bits / ((double)all_available_bits/s->bit_rate)));
+ av_log(s->avctx, AV_LOG_DEBUG,
+ "[lavc rc] estimated target average qp: %.3f\n",
+ (float)qscale_sum / rcc->num_entries);
+ if (toobig == 0) {
+ av_log(s->avctx, AV_LOG_INFO,
+ "[lavc rc] Using all of requested bitrate is not "
+ "necessary for this video with these parameters.\n");
+ } else if (toobig == 40) {
+ av_log(s->avctx, AV_LOG_ERROR,
+ "[lavc rc] Error: bitrate too low for this video "
+ "with these parameters.\n");
+ return -1;
+ } else if (fabs(expected_bits/all_available_bits - 1.0) > 0.01) {
+ av_log(s->avctx, AV_LOG_ERROR,
+ "[lavc rc] Error: 2pass curve failed to converge\n");
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/src/libffmpeg/libavcodec/ratecontrol.h b/contrib/ffmpeg/libavcodec/ratecontrol.h
index c428923a5..c428923a5 100644
--- a/src/libffmpeg/libavcodec/ratecontrol.h
+++ b/contrib/ffmpeg/libavcodec/ratecontrol.h
diff --git a/contrib/ffmpeg/libavcodec/raw.c b/contrib/ffmpeg/libavcodec/raw.c
new file mode 100644
index 000000000..268779803
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/raw.c
@@ -0,0 +1,224 @@
+/*
+ * Raw Video Codec
+ * Copyright (c) 2001 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 raw.c
+ * Raw Video Codec
+ */
+
+#include "avcodec.h"
+
+typedef struct RawVideoContext {
+ unsigned char * buffer; /* block of memory for holding one frame */
+ int length; /* number of bytes in buffer */
+ AVFrame pic; ///< AVCodecContext.coded_frame
+} RawVideoContext;
+
+typedef struct PixelFormatTag {
+ int pix_fmt;
+ unsigned int fourcc;
+} PixelFormatTag;
+
+static const PixelFormatTag pixelFormatTags[] = {
+ { PIX_FMT_YUV420P, MKTAG('I', '4', '2', '0') }, /* Planar formats */
+ { PIX_FMT_YUV420P, MKTAG('I', 'Y', 'U', 'V') },
+ { PIX_FMT_YUV420P, MKTAG('Y', 'V', '1', '2') },
+ { PIX_FMT_YUV410P, MKTAG('Y', 'U', 'V', '9') },
+ { PIX_FMT_YUV411P, MKTAG('Y', '4', '1', 'B') },
+ { PIX_FMT_YUV422P, MKTAG('Y', '4', '2', 'B') },
+ { 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_UYVY422, MKTAG('U', 'Y', 'V', 'Y') },
+ { 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) },
+
+ /* quicktime */
+ { PIX_FMT_UYVY422, MKTAG('2', 'v', 'u', 'y') },
+ { PIX_FMT_UYVY422, MKTAG('A', 'V', 'U', 'I') }, /* FIXME merge both fields */
+
+ { -1, 0 },
+};
+
+static const PixelFormatTag pixelFormatBpsAVI[] = {
+ { PIX_FMT_PAL8, 8 },
+ { PIX_FMT_RGB555, 15 },
+ { PIX_FMT_RGB555, 16 },
+ { PIX_FMT_BGR24, 24 },
+ { PIX_FMT_RGB32, 32 },
+ { -1, 0 },
+};
+
+static const PixelFormatTag pixelFormatBpsMOV[] = {
+ /* FIXME fix swscaler to support those */
+ /* http://developer.apple.com/documentation/QuickTime/QTFF/QTFFChap3/chapter_4_section_2.html */
+ { PIX_FMT_PAL8, 8 },
+ { PIX_FMT_BGR555, 16 },
+ { PIX_FMT_RGB24, 24 },
+ { PIX_FMT_BGR32_1, 32 },
+ { -1, 0 },
+};
+
+static int findPixelFormat(const PixelFormatTag *tags, unsigned int fourcc)
+{
+ while (tags->pix_fmt >= 0) {
+ if (tags->fourcc == fourcc)
+ return tags->pix_fmt;
+ tags++;
+ }
+ return PIX_FMT_YUV420P;
+}
+
+unsigned int avcodec_pix_fmt_to_codec_tag(enum PixelFormat fmt)
+{
+ const PixelFormatTag * tags = pixelFormatTags;
+ while (tags->pix_fmt >= 0) {
+ if (tags->pix_fmt == fmt)
+ return tags->fourcc;
+ tags++;
+ }
+ return 0;
+}
+
+/* RAW Decoder Implementation */
+
+static int raw_init_decoder(AVCodecContext *avctx)
+{
+ RawVideoContext *context = avctx->priv_data;
+
+ if (avctx->codec_tag == MKTAG('r','a','w',' '))
+ avctx->pix_fmt = findPixelFormat(pixelFormatBpsMOV, avctx->bits_per_sample);
+ else if (avctx->codec_tag)
+ avctx->pix_fmt = findPixelFormat(pixelFormatTags, avctx->codec_tag);
+ else if (avctx->bits_per_sample)
+ avctx->pix_fmt = findPixelFormat(pixelFormatBpsAVI, avctx->bits_per_sample);
+
+ context->length = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
+ context->buffer = av_malloc(context->length);
+ context->pic.pict_type = FF_I_TYPE;
+ context->pic.key_frame = 1;
+
+ avctx->coded_frame= &context->pic;
+
+ if (!context->buffer)
+ return -1;
+
+ return 0;
+}
+
+static void flip(AVCodecContext *avctx, AVPicture * picture){
+ if(!avctx->codec_tag && avctx->bits_per_sample && picture->linesize[2]==0){
+ picture->data[0] += picture->linesize[0] * (avctx->height-1);
+ picture->linesize[0] *= -1;
+ }
+}
+
+static int raw_decode(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ RawVideoContext *context = avctx->priv_data;
+
+ AVFrame * frame = (AVFrame *) data;
+ AVPicture * picture = (AVPicture *) data;
+
+ frame->interlaced_frame = avctx->coded_frame->interlaced_frame;
+ frame->top_field_first = avctx->coded_frame->top_field_first;
+
+ if(buf_size < context->length - (avctx->pix_fmt==PIX_FMT_PAL8 ? 256*4 : 0))
+ return -1;
+
+ avpicture_fill(picture, buf, avctx->pix_fmt, avctx->width, avctx->height);
+ if(avctx->pix_fmt==PIX_FMT_PAL8 && buf_size < context->length){
+ frame->data[1]= context->buffer;
+ }
+ if (avctx->palctrl && avctx->palctrl->palette_changed) {
+ memcpy(frame->data[1], avctx->palctrl->palette, AVPALETTE_SIZE);
+ avctx->palctrl->palette_changed = 0;
+ }
+
+ flip(avctx, picture);
+
+ if (avctx->codec_tag == MKTAG('Y', 'V', '1', '2'))
+ {
+ // swap fields
+ unsigned char *tmp = picture->data[1];
+ picture->data[1] = picture->data[2];
+ picture->data[2] = tmp;
+ }
+
+ *data_size = sizeof(AVPicture);
+ return buf_size;
+}
+
+static int raw_close_decoder(AVCodecContext *avctx)
+{
+ RawVideoContext *context = avctx->priv_data;
+
+ av_freep(&context->buffer);
+ return 0;
+}
+
+/* RAW Encoder Implementation */
+#ifdef CONFIG_RAWVIDEO_ENCODER
+static 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;
+ if(!avctx->codec_tag)
+ avctx->codec_tag = avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt);
+ return 0;
+}
+
+static int raw_encode(AVCodecContext *avctx,
+ unsigned char *frame, int buf_size, void *data)
+{
+ return avpicture_layout((AVPicture *)data, avctx->pix_fmt, avctx->width,
+ avctx->height, frame, buf_size);
+}
+
+AVCodec rawvideo_encoder = {
+ "rawvideo",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_RAWVIDEO,
+ sizeof(AVFrame),
+ raw_init_encoder,
+ raw_encode,
+};
+#endif // CONFIG_RAWVIDEO_ENCODER
+
+AVCodec rawvideo_decoder = {
+ "rawvideo",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_RAWVIDEO,
+ sizeof(RawVideoContext),
+ raw_init_decoder,
+ NULL,
+ raw_close_decoder,
+ raw_decode,
+};
diff --git a/contrib/ffmpeg/libavcodec/resample.c b/contrib/ffmpeg/libavcodec/resample.c
new file mode 100644
index 000000000..ea5c6d61c
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/resample.c
@@ -0,0 +1,250 @@
+/*
+ * Sample rate convertion for both audio and video
+ * Copyright (c) 2000 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 resample.c
+ * Sample rate convertion for both audio and video.
+ */
+
+#include "avcodec.h"
+
+struct AVResampleContext;
+
+struct ReSampleContext {
+ struct AVResampleContext *resample_context;
+ short *temp[2];
+ int temp_len;
+ float ratio;
+ /* channel convert */
+ int input_channels, output_channels, filter_channels;
+};
+
+/* n1: number of samples */
+static void stereo_to_mono(short *output, short *input, int n1)
+{
+ short *p, *q;
+ int n = n1;
+
+ p = input;
+ q = output;
+ while (n >= 4) {
+ q[0] = (p[0] + p[1]) >> 1;
+ q[1] = (p[2] + p[3]) >> 1;
+ q[2] = (p[4] + p[5]) >> 1;
+ q[3] = (p[6] + p[7]) >> 1;
+ q += 4;
+ p += 8;
+ n -= 4;
+ }
+ while (n > 0) {
+ q[0] = (p[0] + p[1]) >> 1;
+ q++;
+ p += 2;
+ n--;
+ }
+}
+
+/* n1: number of samples */
+static void mono_to_stereo(short *output, short *input, int n1)
+{
+ short *p, *q;
+ int n = n1;
+ int v;
+
+ p = input;
+ q = output;
+ while (n >= 4) {
+ v = p[0]; q[0] = v; q[1] = v;
+ v = p[1]; q[2] = v; q[3] = v;
+ v = p[2]; q[4] = v; q[5] = v;
+ v = p[3]; q[6] = v; q[7] = v;
+ q += 8;
+ p += 4;
+ n -= 4;
+ }
+ while (n > 0) {
+ v = p[0]; q[0] = v; q[1] = v;
+ q += 2;
+ p += 1;
+ n--;
+ }
+}
+
+/* XXX: should use more abstract 'N' channels system */
+static void stereo_split(short *output1, short *output2, short *input, int n)
+{
+ int i;
+
+ for(i=0;i<n;i++) {
+ *output1++ = *input++;
+ *output2++ = *input++;
+ }
+}
+
+static void stereo_mux(short *output, short *input1, short *input2, int n)
+{
+ int i;
+
+ for(i=0;i<n;i++) {
+ *output++ = *input1++;
+ *output++ = *input2++;
+ }
+}
+
+static void ac3_5p1_mux(short *output, short *input1, short *input2, int n)
+{
+ int i;
+ short l,r;
+
+ for(i=0;i<n;i++) {
+ l=*input1++;
+ r=*input2++;
+ *output++ = l; /* left */
+ *output++ = (l/2)+(r/2); /* center */
+ *output++ = r; /* right */
+ *output++ = 0; /* left surround */
+ *output++ = 0; /* right surroud */
+ *output++ = 0; /* low freq */
+ }
+}
+
+ReSampleContext *audio_resample_init(int output_channels, int input_channels,
+ int output_rate, int input_rate)
+{
+ ReSampleContext *s;
+
+ if ( input_channels > 2)
+ {
+ av_log(NULL, AV_LOG_ERROR, "Resampling with input channels greater than 2 unsupported.");
+ return NULL;
+ }
+
+ s = av_mallocz(sizeof(ReSampleContext));
+ if (!s)
+ {
+ av_log(NULL, AV_LOG_ERROR, "Can't allocate memory for resample context.");
+ return NULL;
+ }
+
+ s->ratio = (float)output_rate / (float)input_rate;
+
+ s->input_channels = input_channels;
+ s->output_channels = output_channels;
+
+ s->filter_channels = s->input_channels;
+ if (s->output_channels < s->filter_channels)
+ s->filter_channels = s->output_channels;
+
+/*
+ * ac3 output is the only case where filter_channels could be greater than 2.
+ * input channels can't be greater than 2, so resample the 2 channels and then
+ * expand to 6 channels after the resampling.
+ */
+ if(s->filter_channels>2)
+ s->filter_channels = 2;
+
+#define TAPS 16
+ s->resample_context= av_resample_init(output_rate, input_rate, TAPS, 10, 0, 0.8);
+
+ return s;
+}
+
+/* resample audio. 'nb_samples' is the number of input samples */
+/* XXX: optimize it ! */
+int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples)
+{
+ int i, nb_samples1;
+ short *bufin[2];
+ short *bufout[2];
+ short *buftmp2[2], *buftmp3[2];
+ int lenout;
+
+ if (s->input_channels == s->output_channels && s->ratio == 1.0 && 0) {
+ /* nothing to do */
+ memcpy(output, input, nb_samples * s->input_channels * sizeof(short));
+ return nb_samples;
+ }
+
+ /* XXX: move those malloc to resample init code */
+ for(i=0; i<s->filter_channels; i++){
+ bufin[i]= (short*) av_malloc( (nb_samples + s->temp_len) * sizeof(short) );
+ memcpy(bufin[i], s->temp[i], s->temp_len * sizeof(short));
+ buftmp2[i] = bufin[i] + s->temp_len;
+ }
+
+ /* make some zoom to avoid round pb */
+ lenout= (int)(nb_samples * s->ratio) + 16;
+ bufout[0]= (short*) av_malloc( lenout * sizeof(short) );
+ bufout[1]= (short*) av_malloc( lenout * sizeof(short) );
+
+ if (s->input_channels == 2 &&
+ s->output_channels == 1) {
+ buftmp3[0] = output;
+ stereo_to_mono(buftmp2[0], input, nb_samples);
+ } else if (s->output_channels >= 2 && s->input_channels == 1) {
+ buftmp3[0] = bufout[0];
+ memcpy(buftmp2[0], input, nb_samples*sizeof(short));
+ } else if (s->output_channels >= 2) {
+ buftmp3[0] = bufout[0];
+ buftmp3[1] = bufout[1];
+ stereo_split(buftmp2[0], buftmp2[1], input, nb_samples);
+ } else {
+ buftmp3[0] = output;
+ memcpy(buftmp2[0], input, nb_samples*sizeof(short));
+ }
+
+ nb_samples += s->temp_len;
+
+ /* resample each channel */
+ nb_samples1 = 0; /* avoid warning */
+ for(i=0;i<s->filter_channels;i++) {
+ int consumed;
+ int is_last= i+1 == s->filter_channels;
+
+ nb_samples1 = av_resample(s->resample_context, buftmp3[i], bufin[i], &consumed, nb_samples, lenout, is_last);
+ s->temp_len= nb_samples - consumed;
+ s->temp[i]= av_realloc(s->temp[i], s->temp_len*sizeof(short));
+ memcpy(s->temp[i], bufin[i] + consumed, s->temp_len*sizeof(short));
+ }
+
+ if (s->output_channels == 2 && s->input_channels == 1) {
+ mono_to_stereo(output, buftmp3[0], nb_samples1);
+ } else if (s->output_channels == 2) {
+ stereo_mux(output, buftmp3[0], buftmp3[1], nb_samples1);
+ } else if (s->output_channels == 6) {
+ ac3_5p1_mux(output, buftmp3[0], buftmp3[1], nb_samples1);
+ }
+
+ for(i=0; i<s->filter_channels; i++)
+ av_free(bufin[i]);
+
+ av_free(bufout[0]);
+ av_free(bufout[1]);
+ return nb_samples1;
+}
+
+void audio_resample_close(ReSampleContext *s)
+{
+ av_resample_close(s->resample_context);
+ av_freep(&s->temp[0]);
+ av_freep(&s->temp[1]);
+ av_free(s);
+}
diff --git a/contrib/ffmpeg/libavcodec/resample2.c b/contrib/ffmpeg/libavcodec/resample2.c
new file mode 100644
index 000000000..4209b9705
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/resample2.c
@@ -0,0 +1,326 @@
+/*
+ * audio resampling
+ * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * @file resample2.c
+ * audio resampling
+ * @author Michael Niedermayer <michaelni@gmx.at>
+ */
+
+#include "avcodec.h"
+#include "common.h"
+#include "dsputil.h"
+
+#ifndef CONFIG_RESAMPLE_HP
+#define FILTER_SHIFT 15
+
+#define FELEM int16_t
+#define FELEM2 int32_t
+#define FELEML int64_t
+#define FELEM_MAX INT16_MAX
+#define FELEM_MIN INT16_MIN
+#define WINDOW_TYPE 9
+#elif !defined(CONFIG_RESAMPLE_AUDIOPHILE_KIDDY_MODE)
+#define FILTER_SHIFT 30
+
+#define FELEM int32_t
+#define FELEM2 int64_t
+#define FELEML int64_t
+#define FELEM_MAX INT32_MAX
+#define FELEM_MIN INT32_MIN
+#define WINDOW_TYPE 12
+#else
+#define FILTER_SHIFT 0
+
+#define FELEM double
+#define FELEM2 double
+#define FELEML double
+#define WINDOW_TYPE 24
+#endif
+
+
+typedef struct AVResampleContext{
+ FELEM *filter_bank;
+ int filter_length;
+ int ideal_dst_incr;
+ int dst_incr;
+ int index;
+ int frac;
+ int src_incr;
+ int compensation_distance;
+ int phase_shift;
+ int phase_mask;
+ int linear;
+}AVResampleContext;
+
+/**
+ * 0th order modified bessel function of the first kind.
+ */
+static double bessel(double x){
+ double v=1;
+ double t=1;
+ int i;
+
+ x= x*x/4;
+ for(i=1; i<50; i++){
+ t *= x/(i*i);
+ v += t;
+ }
+ return v;
+}
+
+/**
+ * builds a polyphase filterbank.
+ * @param factor resampling factor
+ * @param scale wanted sum of coefficients for each filter
+ * @param type 0->cubic, 1->blackman nuttall windowed sinc, 2..16->kaiser windowed sinc beta=2..16
+ */
+void av_build_filter(FELEM *filter, double factor, int tap_count, int phase_count, int scale, int type){
+ int ph, i, v;
+ double x, y, w, tab[tap_count];
+ const int center= (tap_count-1)/2;
+
+ /* if upsampling, only need to interpolate, no filter */
+ if (factor > 1.0)
+ factor = 1.0;
+
+ for(ph=0;ph<phase_count;ph++) {
+ double norm = 0;
+ for(i=0;i<tap_count;i++) {
+ x = M_PI * ((double)(i - center) - (double)ph / phase_count) * factor;
+ if (x == 0) y = 1.0;
+ else y = sin(x) / x;
+ switch(type){
+ case 0:{
+ const float d= -0.5; //first order derivative = -0.5
+ x = fabs(((double)(i - center) - (double)ph / phase_count) * factor);
+ if(x<1.0) y= 1 - 3*x*x + 2*x*x*x + d*( -x*x + x*x*x);
+ else y= d*(-4 + 8*x - 5*x*x + x*x*x);
+ break;}
+ case 1:
+ w = 2.0*x / (factor*tap_count) + M_PI;
+ y *= 0.3635819 - 0.4891775 * cos(w) + 0.1365995 * cos(2*w) - 0.0106411 * cos(3*w);
+ break;
+ default:
+ w = 2.0*x / (factor*tap_count*M_PI);
+ y *= bessel(type*sqrt(FFMAX(1-w*w, 0)));
+ break;
+ }
+
+ tab[i] = y;
+ norm += y;
+ }
+
+ /* normalize so that an uniform color remains the same */
+ for(i=0;i<tap_count;i++) {
+#ifdef CONFIG_RESAMPLE_AUDIOPHILE_KIDDY_MODE
+ filter[ph * tap_count + i] = tab[i] / norm;
+#else
+ filter[ph * tap_count + i] = av_clip(lrintf(tab[i] * scale / norm), FELEM_MIN, FELEM_MAX);
+#endif
+ }
+ }
+#if 0
+ {
+#define LEN 1024
+ int j,k;
+ double sine[LEN + tap_count];
+ double filtered[LEN];
+ double maxff=-2, minff=2, maxsf=-2, minsf=2;
+ for(i=0; i<LEN; i++){
+ double ss=0, sf=0, ff=0;
+ for(j=0; j<LEN+tap_count; j++)
+ sine[j]= cos(i*j*M_PI/LEN);
+ for(j=0; j<LEN; j++){
+ double sum=0;
+ ph=0;
+ for(k=0; k<tap_count; k++)
+ sum += filter[ph * tap_count + k] * sine[k+j];
+ filtered[j]= sum / (1<<FILTER_SHIFT);
+ ss+= sine[j + center] * sine[j + center];
+ ff+= filtered[j] * filtered[j];
+ sf+= sine[j + center] * filtered[j];
+ }
+ ss= sqrt(2*ss/LEN);
+ ff= sqrt(2*ff/LEN);
+ sf= 2*sf/LEN;
+ maxff= FFMAX(maxff, ff);
+ minff= FFMIN(minff, ff);
+ maxsf= FFMAX(maxsf, sf);
+ minsf= FFMIN(minsf, sf);
+ if(i%11==0){
+ av_log(NULL, AV_LOG_ERROR, "i:%4d ss:%f ff:%13.6e-%13.6e sf:%13.6e-%13.6e\n", i, ss, maxff, minff, maxsf, minsf);
+ minff=minsf= 2;
+ maxff=maxsf= -2;
+ }
+ }
+ }
+#endif
+}
+
+/**
+ * initalizes a audio resampler.
+ * note, if either rate is not a integer then simply scale both rates up so they are
+ */
+AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_size, int phase_shift, int linear, double cutoff){
+ AVResampleContext *c= av_mallocz(sizeof(AVResampleContext));
+ double factor= FFMIN(out_rate * cutoff / in_rate, 1.0);
+ int phase_count= 1<<phase_shift;
+
+ c->phase_shift= phase_shift;
+ c->phase_mask= phase_count-1;
+ c->linear= linear;
+
+ 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_SHIFT, WINDOW_TYPE);
+ memcpy(&c->filter_bank[c->filter_length*phase_count+1], c->filter_bank, (c->filter_length-1)*sizeof(FELEM));
+ c->filter_bank[c->filter_length*phase_count]= c->filter_bank[c->filter_length - 1];
+
+ c->src_incr= out_rate;
+ c->ideal_dst_incr= c->dst_incr= in_rate * phase_count;
+ c->index= -phase_count*((c->filter_length-1)/2);
+
+ return c;
+}
+
+void av_resample_close(AVResampleContext *c){
+ av_freep(&c->filter_bank);
+ av_freep(&c);
+}
+
+/**
+ * Compensates samplerate/timestamp drift. The compensation is done by changing
+ * the resampler parameters, so no audible clicks or similar distortions ocur
+ * @param compensation_distance distance in output samples over which the compensation should be performed
+ * @param sample_delta number of output samples which should be output less
+ *
+ * example: av_resample_compensate(c, 10, 500)
+ * here instead of 510 samples only 500 samples would be output
+ *
+ * note, due to rounding the actual compensation might be slightly different,
+ * especially if the compensation_distance is large and the in_rate used during init is small
+ */
+void av_resample_compensate(AVResampleContext *c, int sample_delta, int compensation_distance){
+// sample_delta += (c->ideal_dst_incr - c->dst_incr)*(int64_t)c->compensation_distance / c->ideal_dst_incr;
+ c->compensation_distance= compensation_distance;
+ c->dst_incr = c->ideal_dst_incr - c->ideal_dst_incr * (int64_t)sample_delta / compensation_distance;
+}
+
+/**
+ * resamples.
+ * @param src an array of unconsumed samples
+ * @param consumed the number of samples of src which have been consumed are returned here
+ * @param src_size the number of unconsumed samples available
+ * @param dst_size the amount of space in samples available in dst
+ * @param update_ctx if this is 0 then the context wont be modified, that way several channels can be resampled with the same context
+ * @return the number of samples written in dst or -1 if an error occured
+ */
+int av_resample(AVResampleContext *c, short *dst, short *src, int *consumed, int src_size, int dst_size, int update_ctx){
+ int dst_index, i;
+ int index= c->index;
+ int frac= c->frac;
+ int dst_incr_frac= c->dst_incr % c->src_incr;
+ int dst_incr= c->dst_incr / c->src_incr;
+ int compensation_distance= c->compensation_distance;
+
+ if(compensation_distance == 0 && c->filter_length == 1 && c->phase_shift==0){
+ int64_t index2= ((int64_t)index)<<32;
+ int64_t incr= (1LL<<32) * c->dst_incr / c->src_incr;
+ dst_size= FFMIN(dst_size, (src_size-1-index) * (int64_t)c->src_incr / c->dst_incr);
+
+ for(dst_index=0; dst_index < dst_size; dst_index++){
+ dst[dst_index] = src[index2>>32];
+ index2 += incr;
+ }
+ frac += dst_index * dst_incr_frac;
+ index += dst_index * dst_incr;
+ index += frac / c->src_incr;
+ frac %= c->src_incr;
+ }else{
+ for(dst_index=0; dst_index < dst_size; dst_index++){
+ FELEM *filter= c->filter_bank + c->filter_length*(index & c->phase_mask);
+ int sample_index= index >> c->phase_shift;
+ FELEM2 val=0;
+
+ if(sample_index < 0){
+ for(i=0; i<c->filter_length; i++)
+ val += src[FFABS(sample_index + i) % src_size] * filter[i];
+ }else if(sample_index + c->filter_length > src_size){
+ break;
+ }else if(c->linear){
+ FELEM2 v2=0;
+ for(i=0; i<c->filter_length; i++){
+ val += src[sample_index + i] * (FELEM2)filter[i];
+ v2 += src[sample_index + i] * (FELEM2)filter[i + c->filter_length];
+ }
+ val+=(v2-val)*(FELEML)frac / c->src_incr;
+ }else{
+ for(i=0; i<c->filter_length; i++){
+ val += src[sample_index + i] * (FELEM2)filter[i];
+ }
+ }
+
+#ifdef CONFIG_RESAMPLE_AUDIOPHILE_KIDDY_MODE
+ dst[dst_index] = av_clip(lrintf(val), -32768, 32767);
+#else
+ val = (val + (1<<(FILTER_SHIFT-1)))>>FILTER_SHIFT;
+ dst[dst_index] = (unsigned)(val + 32768) > 65535 ? (val>>31) ^ 32767 : val;
+#endif
+
+ frac += dst_incr_frac;
+ index += dst_incr;
+ if(frac >= c->src_incr){
+ frac -= c->src_incr;
+ index++;
+ }
+
+ if(dst_index + 1 == compensation_distance){
+ compensation_distance= 0;
+ dst_incr_frac= c->ideal_dst_incr % c->src_incr;
+ dst_incr= c->ideal_dst_incr / c->src_incr;
+ }
+ }
+ }
+ *consumed= FFMAX(index, 0) >> c->phase_shift;
+ if(index>=0) index &= c->phase_mask;
+
+ if(compensation_distance){
+ compensation_distance -= dst_index;
+ assert(compensation_distance > 0);
+ }
+ if(update_ctx){
+ c->frac= frac;
+ c->index= index;
+ c->dst_incr= dst_incr_frac + c->src_incr*dst_incr;
+ c->compensation_distance= compensation_distance;
+ }
+#if 0
+ if(update_ctx && !c->compensation_distance){
+#undef rand
+ av_resample_compensate(c, rand() % (8000*2) - 8000, 8000*2);
+av_log(NULL, AV_LOG_DEBUG, "%d %d %d\n", c->dst_incr, c->ideal_dst_incr, c->compensation_distance);
+ }
+#endif
+
+ return dst_index;
+}
diff --git a/contrib/ffmpeg/libavcodec/rl.h b/contrib/ffmpeg/libavcodec/rl.h
new file mode 100644
index 000000000..1c2aae25a
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/rl.h
@@ -0,0 +1,42 @@
+/**
+ * @file rl.h
+ * rl header.
+ */
+
+#ifndef AVCODEC_RL_H
+#define AVCODEC_RL_H
+
+/** RLTable. */
+typedef struct RLTable {
+ int n; ///< number of entries of table_vlc minus 1
+ int last; ///< number of values for last = 0
+ const uint16_t (*table_vlc)[2];
+ const int8_t *table_run;
+ const int8_t *table_level;
+ uint8_t *index_run[2]; ///< encoding only
+ int8_t *max_level[2]; ///< encoding & decoding
+ int8_t *max_run[2]; ///< encoding & decoding
+ VLC vlc; ///< decoding only deprected FIXME remove
+ RL_VLC_ELEM *rl_vlc[32]; ///< decoding only
+} RLTable;
+
+/**
+ *
+ * @param static_store static uint8_t array[2][2*MAX_RUN + MAX_LEVEL + 3] which will hold
+ * the level and run tables, if this is NULL av_malloc() will be used
+ */
+void init_rl(RLTable *rl, uint8_t static_store[2][2*MAX_RUN + MAX_LEVEL + 3]);
+void init_vlc_rl(RLTable *rl, int use_static);
+
+static inline int get_rl_index(const RLTable *rl, int last, int run, int level)
+{
+ int index;
+ index = rl->index_run[last][run];
+ if (index >= rl->n)
+ return rl->n;
+ if (level > rl->max_level[last][run])
+ return rl->n;
+ return index + level - 1;
+}
+
+#endif
diff --git a/contrib/ffmpeg/libavcodec/roqvideo.c b/contrib/ffmpeg/libavcodec/roqvideo.c
new file mode 100644
index 000000000..2a9aa6242
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/roqvideo.c
@@ -0,0 +1,477 @@
+/*
+ * Copyright (C) 2003 the ffmpeg project
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * @file roqvideo.c
+ * Id RoQ Video Decoder by Dr. Tim Ferguson
+ * For more information about the Id RoQ format, visit:
+ * http://www.csse.monash.edu.au/~timf/
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "common.h"
+#include "avcodec.h"
+#include "dsputil.h"
+
+typedef struct {
+ unsigned char y0, y1, y2, y3, u, v;
+} roq_cell;
+
+typedef struct {
+ int idx[4];
+} roq_qcell;
+
+static int uiclip[1024], *uiclp; /* clipping table */
+#define avg2(a,b) uiclp[(((int)(a)+(int)(b)+1)>>1)]
+#define avg4(a,b,c,d) uiclp[(((int)(a)+(int)(b)+(int)(c)+(int)(d)+2)>>2)]
+
+typedef struct RoqContext {
+
+ AVCodecContext *avctx;
+ DSPContext dsp;
+ AVFrame frames[2];
+ AVFrame *last_frame;
+ AVFrame *current_frame;
+ int first_frame;
+ int y_stride;
+ int c_stride;
+
+ roq_cell cells[256];
+ roq_qcell qcells[256];
+
+ unsigned char *buf;
+ int size;
+
+} RoqContext;
+
+#define RoQ_INFO 0x1001
+#define RoQ_QUAD_CODEBOOK 0x1002
+#define RoQ_QUAD_VQ 0x1011
+#define RoQ_SOUND_MONO 0x1020
+#define RoQ_SOUND_STEREO 0x1021
+
+#define RoQ_ID_MOT 0x00
+#define RoQ_ID_FCC 0x01
+#define RoQ_ID_SLD 0x02
+#define RoQ_ID_CCC 0x03
+
+#define get_byte(in_buffer) *(in_buffer++)
+#define get_word(in_buffer) ((unsigned short)(in_buffer += 2, \
+ (in_buffer[-1] << 8 | in_buffer[-2])))
+#define get_long(in_buffer) ((unsigned long)(in_buffer += 4, \
+ (in_buffer[-1] << 24 | in_buffer[-2] << 16 | in_buffer[-3] << 8 | in_buffer[-4])))
+
+
+static void apply_vector_2x2(RoqContext *ri, int x, int y, roq_cell *cell)
+{
+ unsigned char *yptr;
+
+ yptr = ri->current_frame->data[0] + (y * ri->y_stride) + x;
+ *yptr++ = cell->y0;
+ *yptr++ = cell->y1;
+ yptr += (ri->y_stride - 2);
+ *yptr++ = cell->y2;
+ *yptr++ = cell->y3;
+ ri->current_frame->data[1][(y/2) * (ri->c_stride) + x/2] = cell->u;
+ ri->current_frame->data[2][(y/2) * (ri->c_stride) + x/2] = cell->v;
+}
+
+static void apply_vector_4x4(RoqContext *ri, int x, int y, roq_cell *cell)
+{
+ unsigned long row_inc, c_row_inc;
+ register unsigned char y0, y1, u, v;
+ unsigned char *yptr, *uptr, *vptr;
+
+ yptr = ri->current_frame->data[0] + (y * ri->y_stride) + x;
+ uptr = ri->current_frame->data[1] + (y/2) * (ri->c_stride) + x/2;
+ vptr = ri->current_frame->data[2] + (y/2) * (ri->c_stride) + x/2;
+
+ row_inc = ri->y_stride - 4;
+ c_row_inc = (ri->c_stride) - 2;
+ *yptr++ = y0 = cell->y0; *uptr++ = u = cell->u; *vptr++ = v = cell->v;
+ *yptr++ = y0;
+ *yptr++ = y1 = cell->y1; *uptr++ = u; *vptr++ = v;
+ *yptr++ = y1;
+
+ yptr += row_inc;
+
+ *yptr++ = y0;
+ *yptr++ = y0;
+ *yptr++ = y1;
+ *yptr++ = y1;
+
+ yptr += row_inc; uptr += c_row_inc; vptr += c_row_inc;
+
+ *yptr++ = y0 = cell->y2; *uptr++ = u; *vptr++ = v;
+ *yptr++ = y0;
+ *yptr++ = y1 = cell->y3; *uptr++ = u; *vptr++ = v;
+ *yptr++ = y1;
+
+ yptr += row_inc;
+
+ *yptr++ = y0;
+ *yptr++ = y0;
+ *yptr++ = y1;
+ *yptr++ = y1;
+}
+
+static void apply_motion_4x4(RoqContext *ri, int x, int y, unsigned char mv,
+ signed char mean_x, signed char mean_y)
+{
+ int i, hw, mx, my;
+ unsigned char *pa, *pb;
+
+ mx = x + 8 - (mv >> 4) - mean_x;
+ my = y + 8 - (mv & 0xf) - mean_y;
+
+ /* check MV against frame boundaries */
+ if ((mx < 0) || (mx > ri->avctx->width - 4) ||
+ (my < 0) || (my > ri->avctx->height - 4)) {
+ av_log(ri->avctx, AV_LOG_ERROR, "motion vector out of bounds: MV = (%d, %d), boundaries = (0, 0, %d, %d)\n",
+ mx, my, ri->avctx->width, ri->avctx->height);
+ return;
+ }
+
+ pa = ri->current_frame->data[0] + (y * ri->y_stride) + x;
+ pb = ri->last_frame->data[0] + (my * ri->y_stride) + mx;
+ for(i = 0; i < 4; i++) {
+ pa[0] = pb[0];
+ pa[1] = pb[1];
+ pa[2] = pb[2];
+ pa[3] = pb[3];
+ pa += ri->y_stride;
+ pb += ri->y_stride;
+ }
+
+ hw = ri->y_stride/2;
+ pa = ri->current_frame->data[1] + (y * ri->y_stride)/4 + x/2;
+ pb = ri->last_frame->data[1] + (my/2) * (ri->y_stride/2) + (mx + 1)/2;
+
+ for(i = 0; i < 2; i++) {
+ switch(((my & 0x01) << 1) | (mx & 0x01)) {
+
+ case 0:
+ pa[0] = pb[0];
+ pa[1] = pb[1];
+ pa[hw] = pb[hw];
+ pa[hw+1] = pb[hw+1];
+ break;
+
+ case 1:
+ pa[0] = avg2(pb[0], pb[1]);
+ pa[1] = avg2(pb[1], pb[2]);
+ pa[hw] = avg2(pb[hw], pb[hw+1]);
+ pa[hw+1] = avg2(pb[hw+1], pb[hw+2]);
+ break;
+
+ case 2:
+ pa[0] = avg2(pb[0], pb[hw]);
+ pa[1] = avg2(pb[1], pb[hw+1]);
+ pa[hw] = avg2(pb[hw], pb[hw*2]);
+ pa[hw+1] = avg2(pb[hw+1], pb[(hw*2)+1]);
+ break;
+
+ case 3:
+ pa[0] = avg4(pb[0], pb[1], pb[hw], pb[hw+1]);
+ pa[1] = avg4(pb[1], pb[2], pb[hw+1], pb[hw+2]);
+ pa[hw] = avg4(pb[hw], pb[hw+1], pb[hw*2], pb[(hw*2)+1]);
+ pa[hw+1] = avg4(pb[hw+1], pb[hw+2], pb[(hw*2)+1], pb[(hw*2)+1]);
+ break;
+ }
+
+ pa = ri->current_frame->data[2] + (y * ri->y_stride)/4 + x/2;
+ pb = ri->last_frame->data[2] + (my/2) * (ri->y_stride/2) + (mx + 1)/2;
+ }
+}
+
+static void apply_motion_8x8(RoqContext *ri, int x, int y,
+ unsigned char mv, signed char mean_x, signed char mean_y)
+{
+ int mx, my, i, j, hw;
+ unsigned char *pa, *pb;
+
+ mx = x + 8 - (mv >> 4) - mean_x;
+ my = y + 8 - (mv & 0xf) - mean_y;
+
+ /* check MV against frame boundaries */
+ if ((mx < 0) || (mx > ri->avctx->width - 8) ||
+ (my < 0) || (my > ri->avctx->height - 8)) {
+ av_log(ri->avctx, AV_LOG_ERROR, "motion vector out of bounds: MV = (%d, %d), boundaries = (0, 0, %d, %d)\n",
+ mx, my, ri->avctx->width, ri->avctx->height);
+ return;
+ }
+
+ pa = ri->current_frame->data[0] + (y * ri->y_stride) + x;
+ pb = ri->last_frame->data[0] + (my * ri->y_stride) + mx;
+ for(i = 0; i < 8; i++) {
+ pa[0] = pb[0];
+ pa[1] = pb[1];
+ pa[2] = pb[2];
+ pa[3] = pb[3];
+ pa[4] = pb[4];
+ pa[5] = pb[5];
+ pa[6] = pb[6];
+ pa[7] = pb[7];
+ pa += ri->y_stride;
+ pb += ri->y_stride;
+ }
+
+ hw = ri->c_stride;
+ pa = ri->current_frame->data[1] + (y * ri->y_stride)/4 + x/2;
+ pb = ri->last_frame->data[1] + (my/2) * (ri->y_stride/2) + (mx + 1)/2;
+ for(j = 0; j < 2; j++) {
+ for(i = 0; i < 4; i++) {
+ switch(((my & 0x01) << 1) | (mx & 0x01)) {
+
+ case 0:
+ pa[0] = pb[0];
+ pa[1] = pb[1];
+ pa[2] = pb[2];
+ pa[3] = pb[3];
+ break;
+
+ case 1:
+ pa[0] = avg2(pb[0], pb[1]);
+ pa[1] = avg2(pb[1], pb[2]);
+ pa[2] = avg2(pb[2], pb[3]);
+ pa[3] = avg2(pb[3], pb[4]);
+ break;
+
+ case 2:
+ pa[0] = avg2(pb[0], pb[hw]);
+ pa[1] = avg2(pb[1], pb[hw+1]);
+ pa[2] = avg2(pb[2], pb[hw+2]);
+ pa[3] = avg2(pb[3], pb[hw+3]);
+ break;
+
+ case 3:
+ pa[0] = avg4(pb[0], pb[1], pb[hw], pb[hw+1]);
+ pa[1] = avg4(pb[1], pb[2], pb[hw+1], pb[hw+2]);
+ pa[2] = avg4(pb[2], pb[3], pb[hw+2], pb[hw+3]);
+ pa[3] = avg4(pb[3], pb[4], pb[hw+3], pb[hw+4]);
+ break;
+ }
+ pa += ri->c_stride;
+ pb += ri->c_stride;
+ }
+
+ pa = ri->current_frame->data[2] + (y * ri->y_stride)/4 + x/2;
+ pb = ri->last_frame->data[2] + (my/2) * (ri->y_stride/2) + (mx + 1)/2;
+ }
+}
+
+static void roqvideo_decode_frame(RoqContext *ri)
+{
+ unsigned int chunk_id = 0, chunk_arg = 0;
+ unsigned long chunk_size = 0;
+ int i, j, k, nv1, nv2, vqflg = 0, vqflg_pos = -1;
+ int vqid, bpos, xpos, ypos, xp, yp, x, y;
+ int frame_stats[2][4] = {{0},{0}};
+ roq_qcell *qcell;
+ unsigned char *buf = ri->buf;
+ unsigned char *buf_end = ri->buf + ri->size;
+
+ while (buf < buf_end) {
+ chunk_id = get_word(buf);
+ chunk_size = get_long(buf);
+ chunk_arg = get_word(buf);
+
+ if(chunk_id == RoQ_QUAD_VQ)
+ break;
+ if(chunk_id == RoQ_QUAD_CODEBOOK) {
+ if((nv1 = chunk_arg >> 8) == 0)
+ nv1 = 256;
+ if((nv2 = chunk_arg & 0xff) == 0 && nv1 * 6 < chunk_size)
+ nv2 = 256;
+ for(i = 0; i < nv1; i++) {
+ ri->cells[i].y0 = get_byte(buf);
+ ri->cells[i].y1 = get_byte(buf);
+ ri->cells[i].y2 = get_byte(buf);
+ ri->cells[i].y3 = get_byte(buf);
+ ri->cells[i].u = get_byte(buf);
+ ri->cells[i].v = get_byte(buf);
+ }
+ for(i = 0; i < nv2; i++)
+ for(j = 0; j < 4; j++)
+ ri->qcells[i].idx[j] = get_byte(buf);
+ }
+ }
+
+ bpos = xpos = ypos = 0;
+ while(bpos < chunk_size) {
+ for (yp = ypos; yp < ypos + 16; yp += 8)
+ for (xp = xpos; xp < xpos + 16; xp += 8) {
+ if (vqflg_pos < 0) {
+ vqflg = buf[bpos++]; vqflg |= (buf[bpos++] << 8);
+ vqflg_pos = 7;
+ }
+ vqid = (vqflg >> (vqflg_pos * 2)) & 0x3;
+ frame_stats[0][vqid]++;
+ vqflg_pos--;
+
+ switch(vqid) {
+ case RoQ_ID_MOT:
+ apply_motion_8x8(ri, xp, yp, 0, 8, 8);
+ break;
+ case RoQ_ID_FCC:
+ apply_motion_8x8(ri, xp, yp, buf[bpos++], chunk_arg >> 8,
+ chunk_arg & 0xff);
+ break;
+ case RoQ_ID_SLD:
+ qcell = ri->qcells + buf[bpos++];
+ apply_vector_4x4(ri, xp, yp, ri->cells + qcell->idx[0]);
+ apply_vector_4x4(ri, xp+4, yp, ri->cells + qcell->idx[1]);
+ apply_vector_4x4(ri, xp, yp+4, ri->cells + qcell->idx[2]);
+ apply_vector_4x4(ri, xp+4, yp+4, ri->cells + qcell->idx[3]);
+ break;
+ case RoQ_ID_CCC:
+ for (k = 0; k < 4; k++) {
+ x = xp; y = yp;
+ if(k & 0x01) x += 4;
+ if(k & 0x02) y += 4;
+
+ if (vqflg_pos < 0) {
+ vqflg = buf[bpos++];
+ vqflg |= (buf[bpos++] << 8);
+ vqflg_pos = 7;
+ }
+ vqid = (vqflg >> (vqflg_pos * 2)) & 0x3;
+ frame_stats[1][vqid]++;
+ vqflg_pos--;
+ switch(vqid) {
+ case RoQ_ID_MOT:
+ apply_motion_4x4(ri, x, y, 0, 8, 8);
+ break;
+ case RoQ_ID_FCC:
+ apply_motion_4x4(ri, x, y, buf[bpos++],
+ chunk_arg >> 8, chunk_arg & 0xff);
+ break;
+ case RoQ_ID_SLD:
+ qcell = ri->qcells + buf[bpos++];
+ apply_vector_2x2(ri, x, y, ri->cells + qcell->idx[0]);
+ apply_vector_2x2(ri, x+2, y, ri->cells + qcell->idx[1]);
+ apply_vector_2x2(ri, x, y+2, ri->cells + qcell->idx[2]);
+ apply_vector_2x2(ri, x+2, y+2, ri->cells + qcell->idx[3]);
+ break;
+ case RoQ_ID_CCC:
+ apply_vector_2x2(ri, x, y, ri->cells + buf[bpos]);
+ apply_vector_2x2(ri, x+2, y, ri->cells + buf[bpos+1]);
+ apply_vector_2x2(ri, x, y+2, ri->cells + buf[bpos+2]);
+ apply_vector_2x2(ri, x+2, y+2, ri->cells + buf[bpos+3]);
+ bpos += 4;
+ break;
+ }
+ }
+ break;
+ default:
+ av_log(ri->avctx, AV_LOG_ERROR, "Unknown vq code: %d\n", vqid);
+ }
+ }
+
+ xpos += 16;
+ if (xpos >= ri->avctx->width) {
+ xpos -= ri->avctx->width;
+ ypos += 16;
+ }
+ if(ypos >= ri->avctx->height)
+ break;
+ }
+}
+
+
+static int roq_decode_init(AVCodecContext *avctx)
+{
+ RoqContext *s = avctx->priv_data;
+ int i;
+
+ s->avctx = avctx;
+ s->first_frame = 1;
+ s->last_frame = &s->frames[0];
+ s->current_frame = &s->frames[1];
+ avctx->pix_fmt = PIX_FMT_YUV420P;
+ avctx->has_b_frames = 0;
+ dsputil_init(&s->dsp, avctx);
+
+ uiclp = uiclip+512;
+ for(i = -512; i < 512; i++)
+ uiclp[i] = (i < 0 ? 0 : (i > 255 ? 255 : i));
+
+ return 0;
+}
+
+static int roq_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ RoqContext *s = avctx->priv_data;
+
+ if (avctx->get_buffer(avctx, s->current_frame)) {
+ av_log(avctx, AV_LOG_ERROR, " RoQ: get_buffer() failed\n");
+ return -1;
+ }
+ s->y_stride = s->current_frame->linesize[0];
+ s->c_stride = s->current_frame->linesize[1];
+
+ s->buf = buf;
+ s->size = buf_size;
+ roqvideo_decode_frame(s);
+
+ /* release the last frame if it is allocated */
+ if (s->first_frame)
+ s->first_frame = 0;
+ else
+ avctx->release_buffer(avctx, s->last_frame);
+
+ *data_size = sizeof(AVFrame);
+ *(AVFrame*)data = *s->current_frame;
+
+ /* shuffle frames */
+ FFSWAP(AVFrame *, s->current_frame, s->last_frame);
+
+ return buf_size;
+}
+
+static int roq_decode_end(AVCodecContext *avctx)
+{
+ RoqContext *s = avctx->priv_data;
+
+ /* release the last frame */
+ if (s->last_frame->data[0])
+ avctx->release_buffer(avctx, s->last_frame);
+
+ return 0;
+}
+
+AVCodec roq_decoder = {
+ "roqvideo",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_ROQ,
+ sizeof(RoqContext),
+ roq_decode_init,
+ NULL,
+ roq_decode_end,
+ roq_decode_frame,
+ CODEC_CAP_DR1,
+};
diff --git a/src/libffmpeg/libavcodec/rpza.c b/contrib/ffmpeg/libavcodec/rpza.c
index 8ab5dbb92..8ab5dbb92 100644
--- a/src/libffmpeg/libavcodec/rpza.c
+++ b/contrib/ffmpeg/libavcodec/rpza.c
diff --git a/src/libffmpeg/libavcodec/rtjpeg.c b/contrib/ffmpeg/libavcodec/rtjpeg.c
index dbc6cfd88..dbc6cfd88 100644
--- a/src/libffmpeg/libavcodec/rtjpeg.c
+++ b/contrib/ffmpeg/libavcodec/rtjpeg.c
diff --git a/src/libffmpeg/libavcodec/rtjpeg.h b/contrib/ffmpeg/libavcodec/rtjpeg.h
index daecc8a75..daecc8a75 100644
--- a/src/libffmpeg/libavcodec/rtjpeg.h
+++ b/contrib/ffmpeg/libavcodec/rtjpeg.h
diff --git a/contrib/ffmpeg/libavcodec/rv10.c b/contrib/ffmpeg/libavcodec/rv10.c
new file mode 100644
index 000000000..e1e8287d5
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/rv10.c
@@ -0,0 +1,805 @@
+/*
+ * RV10 codec
+ * Copyright (c) 2000,2001 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
+ */
+
+/**
+ * @file rv10.c
+ * RV10 codec.
+ */
+
+#include "avcodec.h"
+#include "dsputil.h"
+#include "mpegvideo.h"
+
+//#define DEBUG
+
+#define DC_VLC_BITS 14 //FIXME find a better solution
+
+static const uint16_t rv_lum_code[256] =
+{
+ 0x3e7f, 0x0f00, 0x0f01, 0x0f02, 0x0f03, 0x0f04, 0x0f05, 0x0f06,
+ 0x0f07, 0x0f08, 0x0f09, 0x0f0a, 0x0f0b, 0x0f0c, 0x0f0d, 0x0f0e,
+ 0x0f0f, 0x0f10, 0x0f11, 0x0f12, 0x0f13, 0x0f14, 0x0f15, 0x0f16,
+ 0x0f17, 0x0f18, 0x0f19, 0x0f1a, 0x0f1b, 0x0f1c, 0x0f1d, 0x0f1e,
+ 0x0f1f, 0x0f20, 0x0f21, 0x0f22, 0x0f23, 0x0f24, 0x0f25, 0x0f26,
+ 0x0f27, 0x0f28, 0x0f29, 0x0f2a, 0x0f2b, 0x0f2c, 0x0f2d, 0x0f2e,
+ 0x0f2f, 0x0f30, 0x0f31, 0x0f32, 0x0f33, 0x0f34, 0x0f35, 0x0f36,
+ 0x0f37, 0x0f38, 0x0f39, 0x0f3a, 0x0f3b, 0x0f3c, 0x0f3d, 0x0f3e,
+ 0x0f3f, 0x0380, 0x0381, 0x0382, 0x0383, 0x0384, 0x0385, 0x0386,
+ 0x0387, 0x0388, 0x0389, 0x038a, 0x038b, 0x038c, 0x038d, 0x038e,
+ 0x038f, 0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396,
+ 0x0397, 0x0398, 0x0399, 0x039a, 0x039b, 0x039c, 0x039d, 0x039e,
+ 0x039f, 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6,
+ 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce,
+ 0x00cf, 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056,
+ 0x0057, 0x0020, 0x0021, 0x0022, 0x0023, 0x000c, 0x000d, 0x0004,
+ 0x0000, 0x0005, 0x000e, 0x000f, 0x0024, 0x0025, 0x0026, 0x0027,
+ 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f,
+ 0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7,
+ 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df,
+ 0x03a0, 0x03a1, 0x03a2, 0x03a3, 0x03a4, 0x03a5, 0x03a6, 0x03a7,
+ 0x03a8, 0x03a9, 0x03aa, 0x03ab, 0x03ac, 0x03ad, 0x03ae, 0x03af,
+ 0x03b0, 0x03b1, 0x03b2, 0x03b3, 0x03b4, 0x03b5, 0x03b6, 0x03b7,
+ 0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf,
+ 0x0f40, 0x0f41, 0x0f42, 0x0f43, 0x0f44, 0x0f45, 0x0f46, 0x0f47,
+ 0x0f48, 0x0f49, 0x0f4a, 0x0f4b, 0x0f4c, 0x0f4d, 0x0f4e, 0x0f4f,
+ 0x0f50, 0x0f51, 0x0f52, 0x0f53, 0x0f54, 0x0f55, 0x0f56, 0x0f57,
+ 0x0f58, 0x0f59, 0x0f5a, 0x0f5b, 0x0f5c, 0x0f5d, 0x0f5e, 0x0f5f,
+ 0x0f60, 0x0f61, 0x0f62, 0x0f63, 0x0f64, 0x0f65, 0x0f66, 0x0f67,
+ 0x0f68, 0x0f69, 0x0f6a, 0x0f6b, 0x0f6c, 0x0f6d, 0x0f6e, 0x0f6f,
+ 0x0f70, 0x0f71, 0x0f72, 0x0f73, 0x0f74, 0x0f75, 0x0f76, 0x0f77,
+ 0x0f78, 0x0f79, 0x0f7a, 0x0f7b, 0x0f7c, 0x0f7d, 0x0f7e, 0x0f7f,
+};
+
+static const uint8_t rv_lum_bits[256] =
+{
+ 14, 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, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 8, 8, 8, 8, 8, 8, 8,
+ 8, 8, 8, 8, 8, 8, 8, 8,
+ 8, 7, 7, 7, 7, 7, 7, 7,
+ 7, 6, 6, 6, 6, 5, 5, 4,
+ 2, 4, 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,
+ 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10,
+ 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,
+};
+
+static const uint16_t rv_chrom_code[256] =
+{
+ 0xfe7f, 0x3f00, 0x3f01, 0x3f02, 0x3f03, 0x3f04, 0x3f05, 0x3f06,
+ 0x3f07, 0x3f08, 0x3f09, 0x3f0a, 0x3f0b, 0x3f0c, 0x3f0d, 0x3f0e,
+ 0x3f0f, 0x3f10, 0x3f11, 0x3f12, 0x3f13, 0x3f14, 0x3f15, 0x3f16,
+ 0x3f17, 0x3f18, 0x3f19, 0x3f1a, 0x3f1b, 0x3f1c, 0x3f1d, 0x3f1e,
+ 0x3f1f, 0x3f20, 0x3f21, 0x3f22, 0x3f23, 0x3f24, 0x3f25, 0x3f26,
+ 0x3f27, 0x3f28, 0x3f29, 0x3f2a, 0x3f2b, 0x3f2c, 0x3f2d, 0x3f2e,
+ 0x3f2f, 0x3f30, 0x3f31, 0x3f32, 0x3f33, 0x3f34, 0x3f35, 0x3f36,
+ 0x3f37, 0x3f38, 0x3f39, 0x3f3a, 0x3f3b, 0x3f3c, 0x3f3d, 0x3f3e,
+ 0x3f3f, 0x0f80, 0x0f81, 0x0f82, 0x0f83, 0x0f84, 0x0f85, 0x0f86,
+ 0x0f87, 0x0f88, 0x0f89, 0x0f8a, 0x0f8b, 0x0f8c, 0x0f8d, 0x0f8e,
+ 0x0f8f, 0x0f90, 0x0f91, 0x0f92, 0x0f93, 0x0f94, 0x0f95, 0x0f96,
+ 0x0f97, 0x0f98, 0x0f99, 0x0f9a, 0x0f9b, 0x0f9c, 0x0f9d, 0x0f9e,
+ 0x0f9f, 0x03c0, 0x03c1, 0x03c2, 0x03c3, 0x03c4, 0x03c5, 0x03c6,
+ 0x03c7, 0x03c8, 0x03c9, 0x03ca, 0x03cb, 0x03cc, 0x03cd, 0x03ce,
+ 0x03cf, 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6,
+ 0x00e7, 0x0030, 0x0031, 0x0032, 0x0033, 0x0008, 0x0009, 0x0002,
+ 0x0000, 0x0003, 0x000a, 0x000b, 0x0034, 0x0035, 0x0036, 0x0037,
+ 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef,
+ 0x03d0, 0x03d1, 0x03d2, 0x03d3, 0x03d4, 0x03d5, 0x03d6, 0x03d7,
+ 0x03d8, 0x03d9, 0x03da, 0x03db, 0x03dc, 0x03dd, 0x03de, 0x03df,
+ 0x0fa0, 0x0fa1, 0x0fa2, 0x0fa3, 0x0fa4, 0x0fa5, 0x0fa6, 0x0fa7,
+ 0x0fa8, 0x0fa9, 0x0faa, 0x0fab, 0x0fac, 0x0fad, 0x0fae, 0x0faf,
+ 0x0fb0, 0x0fb1, 0x0fb2, 0x0fb3, 0x0fb4, 0x0fb5, 0x0fb6, 0x0fb7,
+ 0x0fb8, 0x0fb9, 0x0fba, 0x0fbb, 0x0fbc, 0x0fbd, 0x0fbe, 0x0fbf,
+ 0x3f40, 0x3f41, 0x3f42, 0x3f43, 0x3f44, 0x3f45, 0x3f46, 0x3f47,
+ 0x3f48, 0x3f49, 0x3f4a, 0x3f4b, 0x3f4c, 0x3f4d, 0x3f4e, 0x3f4f,
+ 0x3f50, 0x3f51, 0x3f52, 0x3f53, 0x3f54, 0x3f55, 0x3f56, 0x3f57,
+ 0x3f58, 0x3f59, 0x3f5a, 0x3f5b, 0x3f5c, 0x3f5d, 0x3f5e, 0x3f5f,
+ 0x3f60, 0x3f61, 0x3f62, 0x3f63, 0x3f64, 0x3f65, 0x3f66, 0x3f67,
+ 0x3f68, 0x3f69, 0x3f6a, 0x3f6b, 0x3f6c, 0x3f6d, 0x3f6e, 0x3f6f,
+ 0x3f70, 0x3f71, 0x3f72, 0x3f73, 0x3f74, 0x3f75, 0x3f76, 0x3f77,
+ 0x3f78, 0x3f79, 0x3f7a, 0x3f7b, 0x3f7c, 0x3f7d, 0x3f7e, 0x3f7f,
+};
+
+static const uint8_t rv_chrom_bits[256] =
+{
+ 16, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 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, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 8, 8, 8, 8, 8, 8, 8,
+ 8, 6, 6, 6, 6, 4, 4, 3,
+ 2, 3, 4, 4, 6, 6, 6, 6,
+ 8, 8, 8, 8, 8, 8, 8, 8,
+ 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10,
+ 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,
+ 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14,
+};
+
+static VLC rv_dc_lum, rv_dc_chrom;
+
+int rv_decode_dc(MpegEncContext *s, int n)
+{
+ int code;
+
+ if (n < 4) {
+ code = get_vlc2(&s->gb, rv_dc_lum.table, DC_VLC_BITS, 2);
+ if (code < 0) {
+ /* XXX: I don't understand why they use LONGER codes than
+ necessary. The following code would be completely useless
+ if they had thought about it !!! */
+ code = get_bits(&s->gb, 7);
+ if (code == 0x7c) {
+ code = (int8_t)(get_bits(&s->gb, 7) + 1);
+ } else if (code == 0x7d) {
+ code = -128 + get_bits(&s->gb, 7);
+ } else if (code == 0x7e) {
+ if (get_bits(&s->gb, 1) == 0)
+ code = (int8_t)(get_bits(&s->gb, 8) + 1);
+ else
+ code = (int8_t)(get_bits(&s->gb, 8));
+ } else if (code == 0x7f) {
+ get_bits(&s->gb, 11);
+ code = 1;
+ }
+ } else {
+ code -= 128;
+ }
+ } else {
+ code = get_vlc2(&s->gb, rv_dc_chrom.table, DC_VLC_BITS, 2);
+ /* same remark */
+ if (code < 0) {
+ code = get_bits(&s->gb, 9);
+ if (code == 0x1fc) {
+ code = (int8_t)(get_bits(&s->gb, 7) + 1);
+ } else if (code == 0x1fd) {
+ code = -128 + get_bits(&s->gb, 7);
+ } else if (code == 0x1fe) {
+ get_bits(&s->gb, 9);
+ code = 1;
+ } else {
+ av_log(s->avctx, AV_LOG_ERROR, "chroma dc error\n");
+ return 0xffff;
+ }
+ } else {
+ code -= 128;
+ }
+ }
+ return -code;
+}
+
+#ifdef CONFIG_ENCODERS
+
+/* write RV 1.0 compatible frame header */
+void rv10_encode_picture_header(MpegEncContext *s, int picture_number)
+{
+ int full_frame= 0;
+
+ align_put_bits(&s->pb);
+
+ put_bits(&s->pb, 1, 1); /* marker */
+
+ put_bits(&s->pb, 1, (s->pict_type == P_TYPE));
+
+ put_bits(&s->pb, 1, 0); /* not PB frame */
+
+ put_bits(&s->pb, 5, s->qscale);
+
+ if (s->pict_type == I_TYPE) {
+ /* specific MPEG like DC coding not used */
+ }
+ /* if multiple packets per frame are sent, the position at which
+ to display the macro blocks is coded here */
+ if(!full_frame){
+ put_bits(&s->pb, 6, 0); /* mb_x */
+ put_bits(&s->pb, 6, 0); /* mb_y */
+ put_bits(&s->pb, 12, s->mb_width * s->mb_height);
+ }
+
+ put_bits(&s->pb, 3, 0); /* ignored */
+}
+
+void rv20_encode_picture_header(MpegEncContext *s, int picture_number){
+ put_bits(&s->pb, 2, s->pict_type); //I 0 vs. 1 ?
+ put_bits(&s->pb, 1, 0); /* unknown bit */
+ put_bits(&s->pb, 5, s->qscale);
+
+ put_bits(&s->pb, 8, picture_number&0xFF); //FIXME wrong, but correct is not known
+ s->mb_x= s->mb_y= 0;
+ ff_h263_encode_mba(s);
+
+ put_bits(&s->pb, 1, s->no_rounding);
+
+ assert(s->f_code == 1);
+ assert(s->unrestricted_mv == 1);
+// assert(s->h263_aic== (s->pict_type == I_TYPE));
+ assert(s->alt_inter_vlc == 0);
+ assert(s->umvplus == 0);
+ assert(s->modified_quant==1);
+ assert(s->loop_filter==1);
+
+ s->h263_aic= s->pict_type == I_TYPE;
+ 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 0 /* unused, remove? */
+static int get_num(GetBitContext *gb)
+{
+ int n, n1;
+
+ n = get_bits(gb, 16);
+ if (n >= 0x4000) {
+ return n - 0x4000;
+ } else {
+ n1 = get_bits(gb, 16);
+ return (n << 16) | n1;
+ }
+}
+#endif
+
+#endif //CONFIG_ENCODERS
+
+/* read RV 1.0 compatible frame header */
+static int rv10_decode_picture_header(MpegEncContext *s)
+{
+ int mb_count, pb_frame, marker, unk, mb_xy;
+
+//printf("ff:%d\n", full_frame);
+ marker = get_bits(&s->gb, 1);
+
+ if (get_bits(&s->gb, 1))
+ s->pict_type = P_TYPE;
+ else
+ s->pict_type = I_TYPE;
+//printf("h:%X ver:%d\n",h,s->rv10_version);
+ if(!marker) av_log(s->avctx, AV_LOG_ERROR, "marker missing\n");
+ pb_frame = get_bits(&s->gb, 1);
+
+#ifdef DEBUG
+ av_log(s->avctx, AV_LOG_DEBUG, "pict_type=%d pb_frame=%d\n", s->pict_type, pb_frame);
+#endif
+
+ if (pb_frame){
+ av_log(s->avctx, AV_LOG_ERROR, "pb frame not supported\n");
+ return -1;
+ }
+
+ s->qscale = get_bits(&s->gb, 5);
+ if(s->qscale==0){
+ av_log(s->avctx, AV_LOG_ERROR, "error, qscale:0\n");
+ return -1;
+ }
+
+ if (s->pict_type == I_TYPE) {
+ if (s->rv10_version == 3) {
+ /* specific MPEG like DC coding not used */
+ s->last_dc[0] = get_bits(&s->gb, 8);
+ s->last_dc[1] = get_bits(&s->gb, 8);
+ s->last_dc[2] = get_bits(&s->gb, 8);
+#ifdef DEBUG
+ av_log(s->avctx, AV_LOG_DEBUG, "DC:%d %d %d\n",
+ s->last_dc[0],
+ s->last_dc[1],
+ s->last_dc[2]);
+#endif
+ }
+ }
+ /* if multiple packets per frame are sent, the position at which
+ to display the macro blocks is coded here */
+
+ mb_xy= s->mb_x + s->mb_y*s->mb_width;
+ if(show_bits(&s->gb, 12)==0 || (mb_xy && mb_xy < s->mb_num)){
+ s->mb_x = get_bits(&s->gb, 6); /* mb_x */
+ s->mb_y = get_bits(&s->gb, 6); /* mb_y */
+ mb_count = get_bits(&s->gb, 12);
+ } else {
+ s->mb_x = 0;
+ s->mb_y = 0;
+ mb_count = s->mb_width * s->mb_height;
+ }
+ unk= get_bits(&s->gb, 3); /* ignored */
+//printf("%d\n", unk);
+ s->f_code = 1;
+ s->unrestricted_mv = 1;
+
+ return mb_count;
+}
+
+static int rv20_decode_picture_header(MpegEncContext *s)
+{
+ int seq, mb_pos, i;
+
+#if 0
+ GetBitContext gb= s->gb;
+ for(i=0; i<64; i++){
+ av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&gb));
+ if(i%4==3) av_log(s->avctx, AV_LOG_DEBUG, " ");
+ }
+ av_log(s->avctx, AV_LOG_DEBUG, "\n");
+#endif
+#if 0
+ av_log(s->avctx, AV_LOG_DEBUG, "%3dx%03d/%02Xx%02X ", s->width, s->height, s->width/4, s->height/4);
+ for(i=0; i<s->avctx->extradata_size; i++){
+ av_log(s->avctx, AV_LOG_DEBUG, "%02X ", ((uint8_t*)s->avctx->extradata)[i]);
+ if(i%4==3) av_log(s->avctx, AV_LOG_DEBUG, " ");
+ }
+ av_log(s->avctx, AV_LOG_DEBUG, "\n");
+#endif
+
+ if(s->avctx->sub_id == 0x30202002 || s->avctx->sub_id == 0x30203002){
+ if (get_bits(&s->gb, 3)){
+ av_log(s->avctx, AV_LOG_ERROR, "unknown triplet set\n");
+ return -1;
+ }
+ }
+
+ i= get_bits(&s->gb, 2);
+ switch(i){
+ case 0: s->pict_type= I_TYPE; break;
+ case 1: s->pict_type= I_TYPE; break; //hmm ...
+ case 2: s->pict_type= P_TYPE; break;
+ case 3: s->pict_type= B_TYPE; break;
+ default:
+ av_log(s->avctx, AV_LOG_ERROR, "unknown frame type\n");
+ return -1;
+ }
+
+ if(s->last_picture_ptr==NULL && s->pict_type==B_TYPE){
+ av_log(s->avctx, AV_LOG_ERROR, "early B pix\n");
+ return -1;
+ }
+
+ if (get_bits(&s->gb, 1)){
+ av_log(s->avctx, AV_LOG_ERROR, "unknown bit set\n");
+ return -1;
+ }
+
+ s->qscale = get_bits(&s->gb, 5);
+ if(s->qscale==0){
+ av_log(s->avctx, AV_LOG_ERROR, "error, qscale:0\n");
+ return -1;
+ }
+ if(s->avctx->sub_id == 0x30203002){
+ if (get_bits(&s->gb, 1)){
+ av_log(s->avctx, AV_LOG_ERROR, "unknown bit2 set\n");
+ return -1;
+ }
+ }
+
+ if(s->avctx->has_b_frames){
+ int f, new_w, new_h;
+ int v= s->avctx->extradata_size >= 4 ? 7&((uint8_t*)s->avctx->extradata)[1] : 0;
+
+ if (get_bits(&s->gb, 1)){
+ av_log(s->avctx, AV_LOG_ERROR, "unknown bit3 set\n");
+// return -1;
+ }
+ seq= get_bits(&s->gb, 13)<<2;
+
+ f= get_bits(&s->gb, av_log2(v)+1);
+
+ if(f){
+ 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;
+ }
+ 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)
+ return -1;
+ MPV_common_end(s);
+ s->width = s->avctx->width = new_w;
+ s->height = s->avctx->height= new_h;
+ if (MPV_common_init(s) < 0)
+ return -1;
+ }
+
+ if(s->avctx->debug & FF_DEBUG_PICT_INFO){
+ av_log(s->avctx, AV_LOG_DEBUG, "F %d/%d\n", f, v);
+ }
+ }else{
+ seq= get_bits(&s->gb, 8)*128;
+ }
+
+// if(s->avctx->sub_id <= 0x20201002){ //0x20201002 definitely needs this
+ mb_pos= ff_h263_decode_mba(s);
+/* }else{
+ mb_pos= get_bits(&s->gb, av_log2(s->mb_num-1)+1);
+ s->mb_x= mb_pos % s->mb_width;
+ s->mb_y= mb_pos / s->mb_width;
+ }*/
+//av_log(s->avctx, AV_LOG_DEBUG, "%d\n", seq);
+ seq |= s->time &~0x7FFF;
+ if(seq - s->time > 0x4000) seq -= 0x8000;
+ if(seq - s->time < -0x4000) seq += 0x8000;
+ if(seq != s->time){
+ if(s->pict_type!=B_TYPE){
+ s->time= seq;
+ s->pp_time= s->time - s->last_non_b_time;
+ s->last_non_b_time= s->time;
+ }else{
+ s->time= seq;
+ 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){
+ av_log(s->avctx, AV_LOG_DEBUG, "messed up order, possible from seeking? skipping current b frame\n");
+ return FRAME_SKIPPED;
+ }
+ ff_mpeg4_init_direct_mv(s);
+ }
+ }
+// printf("%d %d %d %d %d\n", seq, (int)s->time, (int)s->last_non_b_time, s->pp_time, s->pb_time);
+/*for(i=0; i<32; i++){
+ av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb));
+}
+av_log(s->avctx, AV_LOG_DEBUG, "\n");*/
+ s->no_rounding= get_bits1(&s->gb);
+
+ s->f_code = 1;
+ s->unrestricted_mv = 1;
+ s->h263_aic= s->pict_type == I_TYPE;
+// s->alt_inter_vlc=1;
+// s->obmc=1;
+// s->umvplus=1;
+ s->modified_quant=1;
+ s->loop_filter=1;
+
+ if(s->avctx->debug & FF_DEBUG_PICT_INFO){
+ av_log(s->avctx, AV_LOG_INFO, "num:%5d x:%2d y:%2d type:%d qscale:%2d rnd:%d\n",
+ seq, s->mb_x, s->mb_y, s->pict_type, s->qscale, s->no_rounding);
+ }
+
+ assert(s->pict_type != B_TYPE || !s->low_delay);
+
+ return s->mb_width*s->mb_height - mb_pos;
+}
+
+static int rv10_decode_init(AVCodecContext *avctx)
+{
+ MpegEncContext *s = avctx->priv_data;
+ static int done=0;
+
+ MPV_decode_defaults(s);
+
+ s->avctx= avctx;
+ s->out_format = FMT_H263;
+ s->codec_id= avctx->codec_id;
+
+ s->width = avctx->width;
+ s->height = avctx->height;
+
+ s->h263_long_vectors= ((uint8_t*)avctx->extradata)[3] & 1;
+ avctx->sub_id= AV_RB32((uint8_t*)avctx->extradata + 4);
+
+ switch(avctx->sub_id){
+ case 0x10000000:
+ s->rv10_version= 0;
+ s->low_delay=1;
+ break;
+ case 0x10002000:
+ s->rv10_version= 3;
+ s->low_delay=1;
+ s->obmc=1;
+ break;
+ case 0x10003000:
+ s->rv10_version= 3;
+ s->low_delay=1;
+ break;
+ case 0x10003001:
+ s->rv10_version= 3;
+ s->low_delay=1;
+ break;
+ case 0x20001000: /* real rv20 decoder fail on this id */
+ /*case 0x20100001:
+ case 0x20101001:
+ case 0x20103001:*/
+ case 0x20100000 ... 0x2019ffff:
+ s->low_delay=1;
+ break;
+ /*case 0x20200002:
+ case 0x20201002:
+ case 0x20203002:*/
+ case 0x20200002 ... 0x202fffff:
+ case 0x30202002:
+ case 0x30203002:
+ s->low_delay=0;
+ s->avctx->has_b_frames=1;
+ break;
+ default:
+ av_log(s->avctx, AV_LOG_ERROR, "unknown header %X\n", avctx->sub_id);
+ }
+
+ if(avctx->debug & FF_DEBUG_PICT_INFO){
+ av_log(avctx, AV_LOG_DEBUG, "ver:%X ver0:%X\n", avctx->sub_id, avctx->extradata_size >= 4 ? ((uint32_t*)avctx->extradata)[0] : -1);
+ }
+
+ avctx->pix_fmt = PIX_FMT_YUV420P;
+
+ if (MPV_common_init(s) < 0)
+ return -1;
+
+ h263_decode_init_vlc(s);
+
+ /* init rv vlc */
+ if (!done) {
+ init_vlc(&rv_dc_lum, DC_VLC_BITS, 256,
+ rv_lum_bits, 1, 1,
+ rv_lum_code, 2, 2, 1);
+ init_vlc(&rv_dc_chrom, DC_VLC_BITS, 256,
+ rv_chrom_bits, 1, 1,
+ rv_chrom_code, 2, 2, 1);
+ done = 1;
+ }
+
+ return 0;
+}
+
+static int rv10_decode_end(AVCodecContext *avctx)
+{
+ MpegEncContext *s = avctx->priv_data;
+
+ MPV_common_end(s);
+ return 0;
+}
+
+static int rv10_decode_packet(AVCodecContext *avctx,
+ uint8_t *buf, int buf_size)
+{
+ MpegEncContext *s = avctx->priv_data;
+ int mb_count, mb_pos, left, start_mb_x;
+
+ init_get_bits(&s->gb, buf, buf_size*8);
+ if(s->codec_id ==CODEC_ID_RV10)
+ mb_count = rv10_decode_picture_header(s);
+ else
+ mb_count = rv20_decode_picture_header(s);
+ if (mb_count < 0) {
+ av_log(s->avctx, AV_LOG_ERROR, "HEADER ERROR\n");
+ return -1;
+ }
+
+ if (s->mb_x >= s->mb_width ||
+ s->mb_y >= s->mb_height) {
+ av_log(s->avctx, AV_LOG_ERROR, "POS ERROR %d %d\n", s->mb_x, s->mb_y);
+ return -1;
+ }
+ mb_pos = s->mb_y * s->mb_width + s->mb_x;
+ left = s->mb_width * s->mb_height - mb_pos;
+ if (mb_count > left) {
+ av_log(s->avctx, AV_LOG_ERROR, "COUNT ERROR\n");
+ return -1;
+ }
+//if(s->pict_type == P_TYPE) return 0;
+
+ if ((s->mb_x == 0 && s->mb_y == 0) || s->current_picture_ptr==NULL) {
+ if(s->current_picture_ptr){ //FIXME write parser so we always have complete frames?
+ ff_er_frame_end(s);
+ MPV_frame_end(s);
+ s->mb_x= s->mb_y = s->resync_mb_x = s->resync_mb_y= 0;
+ }
+ if(MPV_frame_start(s, avctx) < 0)
+ return -1;
+ ff_er_frame_start(s);
+ }
+
+#ifdef DEBUG
+ av_log(avctx, AV_LOG_DEBUG, "qscale=%d\n", s->qscale);
+#endif
+
+ /* default quantization values */
+ if(s->codec_id== CODEC_ID_RV10){
+ if(s->mb_y==0) s->first_slice_line=1;
+ }else{
+ s->first_slice_line=1;
+ s->resync_mb_x= s->mb_x;
+ }
+ start_mb_x= s->mb_x;
+ s->resync_mb_y= s->mb_y;
+ 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->modified_quant)
+ s->chroma_qscale_table= ff_h263_chroma_qscale_table;
+
+ ff_set_qscale(s, s->qscale);
+
+ s->rv10_first_dc_coded[0] = 0;
+ s->rv10_first_dc_coded[1] = 0;
+ s->rv10_first_dc_coded[2] = 0;
+//printf("%d %X %X\n", s->pict_type, s->current_picture.motion_val[0], s->current_picture.motion_val[1]);
+ s->block_wrap[0]=
+ s->block_wrap[1]=
+ s->block_wrap[2]=
+ s->block_wrap[3]= s->b8_stride;
+ s->block_wrap[4]=
+ s->block_wrap[5]= s->mb_stride;
+ ff_init_block_index(s);
+ /* decode each macroblock */
+
+ for(s->mb_num_left= mb_count; s->mb_num_left>0; s->mb_num_left--) {
+ int ret;
+ ff_update_block_index(s);
+#ifdef DEBUG
+ av_log(avctx, AV_LOG_DEBUG, "**mb x=%d y=%d\n", s->mb_x, s->mb_y);
+#endif
+
+ s->mv_dir = MV_DIR_FORWARD;
+ 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)) {
+ av_log(s->avctx, AV_LOG_ERROR, "ERROR at MB %d %d\n", s->mb_x, s->mb_y);
+ return -1;
+ }
+ if(s->pict_type != B_TYPE)
+ ff_h263_update_motion_val(s);
+ MPV_decode_mb(s, s->block);
+ if(s->loop_filter)
+ ff_h263_loop_filter(s);
+
+ if (++s->mb_x == s->mb_width) {
+ s->mb_x = 0;
+ s->mb_y++;
+ ff_init_block_index(s);
+ }
+ if(s->mb_x == s->resync_mb_x)
+ s->first_slice_line=0;
+ if(ret == SLICE_END) break;
+ }
+
+ 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;
+}
+
+static int rv10_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ MpegEncContext *s = avctx->priv_data;
+ int i;
+ AVFrame *pict = data;
+
+#ifdef DEBUG
+ av_log(avctx, AV_LOG_DEBUG, "*****frame %d size=%d\n", avctx->frame_number, buf_size);
+#endif
+
+ /* no supplementary picture */
+ if (buf_size == 0) {
+ return 0;
+ }
+
+ if(avctx->slice_count){
+ for(i=0; i<avctx->slice_count; i++){
+ int offset= avctx->slice_offset[i];
+ int size;
+
+ if(i+1 == avctx->slice_count)
+ size= buf_size - offset;
+ else
+ size= avctx->slice_offset[i+1] - offset;
+
+ rv10_decode_packet(avctx, buf+offset, size);
+ }
+ }else{
+ rv10_decode_packet(avctx, buf, buf_size);
+ }
+
+ if(s->current_picture_ptr != NULL && s->mb_y>=s->mb_height){
+ ff_er_frame_end(s);
+ MPV_frame_end(s);
+
+ if (s->pict_type == B_TYPE || s->low_delay) {
+ *pict= *(AVFrame*)s->current_picture_ptr;
+ } else if (s->last_picture_ptr != NULL) {
+ *pict= *(AVFrame*)s->last_picture_ptr;
+ }
+
+ if(s->last_picture_ptr || s->low_delay){
+ *data_size = sizeof(AVFrame);
+ ff_print_debug_info(s, pict);
+ }
+ s->current_picture_ptr= NULL; //so we can detect if frame_end wasnt called (find some nicer solution...)
+ }
+
+ return buf_size;
+}
+
+AVCodec rv10_decoder = {
+ "rv10",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_RV10,
+ sizeof(MpegEncContext),
+ rv10_decode_init,
+ NULL,
+ rv10_decode_end,
+ rv10_decode_frame,
+ CODEC_CAP_DR1
+};
+
+AVCodec rv20_decoder = {
+ "rv20",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_RV20,
+ sizeof(MpegEncContext),
+ rv10_decode_init,
+ NULL,
+ rv10_decode_end,
+ rv10_decode_frame,
+ CODEC_CAP_DR1 | CODEC_CAP_DELAY,
+ .flush= ff_mpeg_flush,
+};
+
diff --git a/contrib/ffmpeg/libavcodec/sh4/dsputil_align.c b/contrib/ffmpeg/libavcodec/sh4/dsputil_align.c
new file mode 100644
index 000000000..7e7e3304b
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/sh4/dsputil_align.c
@@ -0,0 +1,430 @@
+/*
+ * aligned/packed access motion
+ *
+ * Copyright (c) 2001-2003 BERO <bero@geocities.co.jp>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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"
+
+
+#define LP(p) *(uint32_t*)(p)
+
+
+#define UNPACK(ph,pl,tt0,tt1) do { \
+ uint32_t t0,t1; t0=tt0;t1=tt1; \
+ ph = ( (t0 & ~BYTE_VEC32(0x03))>>2) + ( (t1 & ~BYTE_VEC32(0x03))>>2); \
+ pl = (t0 & BYTE_VEC32(0x03)) + (t1 & BYTE_VEC32(0x03)); } while(0)
+
+#define rnd_PACK(ph,pl,nph,npl) ph + nph + (((pl + npl + BYTE_VEC32(0x02))>>2) & BYTE_VEC32(0x03))
+#define no_rnd_PACK(ph,pl,nph,npl) ph + nph + (((pl + npl + BYTE_VEC32(0x01))>>2) & BYTE_VEC32(0x03))
+
+/* little endian */
+#define MERGE1(a,b,ofs) (ofs==0)?a:( ((a)>>(8*ofs))|((b)<<(32-8*ofs)) )
+#define MERGE2(a,b,ofs) (ofs==3)?b:( ((a)>>(8*(ofs+1)))|((b)<<(32-8*(ofs+1))) )
+/* big
+#define MERGE1(a,b,ofs) (ofs==0)?a:( ((a)<<(8*ofs))|((b)>>(32-8*ofs)) )
+#define MERGE2(a,b,ofs) (ofs==3)?b:( ((a)<<(8+8*ofs))|((b)>>(32-8-8*ofs)) )
+*/
+
+
+#define put(d,s) d = s
+#define avg(d,s) d = rnd_avg32(s,d)
+
+#define OP_C4(ofs) \
+ ref-=ofs; \
+ do { \
+ OP(LP(dest),MERGE1(LP(ref),LP(ref+4),ofs)); \
+ ref+=stride; \
+ dest+=stride; \
+ } while(--height)
+
+#define OP_C40() \
+ do { \
+ OP(LP(dest),LP(ref)); \
+ ref+=stride; \
+ dest+=stride; \
+ } while(--height)
+
+
+#define OP put
+
+static void put_pixels4_c(uint8_t *dest,const uint8_t *ref, const int stride,int height)
+{
+ switch((int)ref&3){
+ case 0: OP_C40(); return;
+ case 1: OP_C4(1); return;
+ case 2: OP_C4(2); return;
+ case 3: OP_C4(3); return;
+ }
+}
+
+#undef OP
+#define OP avg
+
+static void avg_pixels4_c(uint8_t *dest,const uint8_t *ref, const int stride,int height)
+{
+ switch((int)ref&3){
+ case 0: OP_C40(); return;
+ case 1: OP_C4(1); return;
+ case 2: OP_C4(2); return;
+ case 3: OP_C4(3); return;
+ }
+}
+
+#undef OP
+
+#define OP_C(ofs,sz,avg2) \
+{ \
+ ref-=ofs; \
+ do { \
+ uint32_t t0,t1; \
+ t0 = LP(ref+0); \
+ t1 = LP(ref+4); \
+ OP(LP(dest+0), MERGE1(t0,t1,ofs)); \
+ t0 = LP(ref+8); \
+ OP(LP(dest+4), MERGE1(t1,t0,ofs)); \
+if (sz==16) { \
+ t1 = LP(ref+12); \
+ OP(LP(dest+8), MERGE1(t0,t1,ofs)); \
+ t0 = LP(ref+16); \
+ OP(LP(dest+12), MERGE1(t1,t0,ofs)); \
+} \
+ ref+=stride; \
+ dest+= stride; \
+ } while(--height); \
+}
+
+/* aligned */
+#define OP_C0(sz,avg2) \
+{ \
+ do { \
+ OP(LP(dest+0), LP(ref+0)); \
+ OP(LP(dest+4), LP(ref+4)); \
+if (sz==16) { \
+ OP(LP(dest+8), LP(ref+8)); \
+ OP(LP(dest+12), LP(ref+12)); \
+} \
+ ref+=stride; \
+ dest+= stride; \
+ } while(--height); \
+}
+
+#define OP_X(ofs,sz,avg2) \
+{ \
+ ref-=ofs; \
+ do { \
+ uint32_t t0,t1; \
+ t0 = LP(ref+0); \
+ t1 = LP(ref+4); \
+ OP(LP(dest+0), avg2(MERGE1(t0,t1,ofs),MERGE2(t0,t1,ofs))); \
+ t0 = LP(ref+8); \
+ OP(LP(dest+4), avg2(MERGE1(t1,t0,ofs),MERGE2(t1,t0,ofs))); \
+if (sz==16) { \
+ t1 = LP(ref+12); \
+ OP(LP(dest+8), avg2(MERGE1(t0,t1,ofs),MERGE2(t0,t1,ofs))); \
+ t0 = LP(ref+16); \
+ OP(LP(dest+12), avg2(MERGE1(t1,t0,ofs),MERGE2(t1,t0,ofs))); \
+} \
+ ref+=stride; \
+ dest+= stride; \
+ } while(--height); \
+}
+
+/* aligned */
+#define OP_Y0(sz,avg2) \
+{ \
+ uint32_t t0,t1,t2,t3,t; \
+\
+ t0 = LP(ref+0); \
+ t1 = LP(ref+4); \
+if (sz==16) { \
+ t2 = LP(ref+8); \
+ t3 = LP(ref+12); \
+} \
+ do { \
+ ref += stride; \
+\
+ t = LP(ref+0); \
+ OP(LP(dest+0), avg2(t0,t)); t0 = t; \
+ t = LP(ref+4); \
+ OP(LP(dest+4), avg2(t1,t)); t1 = t; \
+if (sz==16) { \
+ t = LP(ref+8); \
+ OP(LP(dest+8), avg2(t2,t)); t2 = t; \
+ t = LP(ref+12); \
+ OP(LP(dest+12), avg2(t3,t)); t3 = t; \
+} \
+ dest+= stride; \
+ } while(--height); \
+}
+
+#define OP_Y(ofs,sz,avg2) \
+{ \
+ uint32_t t0,t1,t2,t3,t,w0,w1; \
+\
+ ref-=ofs; \
+ w0 = LP(ref+0); \
+ w1 = LP(ref+4); \
+ t0 = MERGE1(w0,w1,ofs); \
+ w0 = LP(ref+8); \
+ t1 = MERGE1(w1,w0,ofs); \
+if (sz==16) { \
+ w1 = LP(ref+12); \
+ t2 = MERGE1(w0,w1,ofs); \
+ w0 = LP(ref+16); \
+ t3 = MERGE1(w1,w0,ofs); \
+} \
+ do { \
+ ref += stride; \
+\
+ w0 = LP(ref+0); \
+ w1 = LP(ref+4); \
+ t = MERGE1(w0,w1,ofs); \
+ OP(LP(dest+0), avg2(t0,t)); t0 = t; \
+ w0 = LP(ref+8); \
+ t = MERGE1(w1,w0,ofs); \
+ OP(LP(dest+4), avg2(t1,t)); t1 = t; \
+if (sz==16) { \
+ w1 = LP(ref+12); \
+ t = MERGE1(w0,w1,ofs); \
+ OP(LP(dest+8), avg2(t2,t)); t2 = t; \
+ w0 = LP(ref+16); \
+ t = MERGE1(w1,w0,ofs); \
+ OP(LP(dest+12), avg2(t3,t)); t3 = t; \
+} \
+ dest+=stride; \
+ } while(--height); \
+}
+
+#define OP_X0(sz,avg2) OP_X(0,sz,avg2)
+#define OP_XY0(sz,PACK) OP_XY(0,sz,PACK)
+#define OP_XY(ofs,sz,PACK) \
+{ \
+ uint32_t t2,t3,w0,w1; \
+ uint32_t a0,a1,a2,a3,a4,a5,a6,a7; \
+\
+ ref -= ofs; \
+ w0 = LP(ref+0); \
+ w1 = LP(ref+4); \
+ UNPACK(a0,a1,MERGE1(w0,w1,ofs),MERGE2(w0,w1,ofs)); \
+ w0 = LP(ref+8); \
+ UNPACK(a2,a3,MERGE1(w1,w0,ofs),MERGE2(w1,w0,ofs)); \
+if (sz==16) { \
+ w1 = LP(ref+12); \
+ UNPACK(a4,a5,MERGE1(w0,w1,ofs),MERGE2(w0,w1,ofs)); \
+ w0 = LP(ref+16); \
+ UNPACK(a6,a7,MERGE1(w1,w0,ofs),MERGE2(w1,w0,ofs)); \
+} \
+ do { \
+ ref+=stride; \
+ w0 = LP(ref+0); \
+ w1 = LP(ref+4); \
+ UNPACK(t2,t3,MERGE1(w0,w1,ofs),MERGE2(w0,w1,ofs)); \
+ OP(LP(dest+0),PACK(a0,a1,t2,t3)); \
+ a0 = t2; a1 = t3; \
+ w0 = LP(ref+8); \
+ UNPACK(t2,t3,MERGE1(w1,w0,ofs),MERGE2(w1,w0,ofs)); \
+ OP(LP(dest+4),PACK(a2,a3,t2,t3)); \
+ a2 = t2; a3 = t3; \
+if (sz==16) { \
+ w1 = LP(ref+12); \
+ UNPACK(t2,t3,MERGE1(w0,w1,ofs),MERGE2(w0,w1,ofs)); \
+ OP(LP(dest+8),PACK(a4,a5,t2,t3)); \
+ a4 = t2; a5 = t3; \
+ w0 = LP(ref+16); \
+ UNPACK(t2,t3,MERGE1(w1,w0,ofs),MERGE2(w1,w0,ofs)); \
+ OP(LP(dest+12),PACK(a6,a7,t2,t3)); \
+ a6 = t2; a7 = t3; \
+} \
+ dest+=stride; \
+ } while(--height); \
+}
+
+#define DEFFUNC(op,rnd,xy,sz,OP_N,avgfunc) \
+static void op##_##rnd##_pixels##sz##_##xy (uint8_t * dest, const uint8_t * ref, \
+ const int stride, int height) \
+{ \
+ switch((int)ref&3) { \
+ case 0:OP_N##0(sz,rnd##_##avgfunc); return; \
+ case 1:OP_N(1,sz,rnd##_##avgfunc); return; \
+ case 2:OP_N(2,sz,rnd##_##avgfunc); return; \
+ case 3:OP_N(3,sz,rnd##_##avgfunc); return; \
+ } \
+}
+
+#define OP put
+
+DEFFUNC(put, rnd,o,8,OP_C,avg2)
+DEFFUNC(put, rnd,x,8,OP_X,avg2)
+DEFFUNC(put,no_rnd,x,8,OP_X,avg2)
+DEFFUNC(put, rnd,y,8,OP_Y,avg2)
+DEFFUNC(put,no_rnd,y,8,OP_Y,avg2)
+DEFFUNC(put, rnd,xy,8,OP_XY,PACK)
+DEFFUNC(put,no_rnd,xy,8,OP_XY,PACK)
+DEFFUNC(put, rnd,o,16,OP_C,avg2)
+DEFFUNC(put, rnd,x,16,OP_X,avg2)
+DEFFUNC(put,no_rnd,x,16,OP_X,avg2)
+DEFFUNC(put, rnd,y,16,OP_Y,avg2)
+DEFFUNC(put,no_rnd,y,16,OP_Y,avg2)
+DEFFUNC(put, rnd,xy,16,OP_XY,PACK)
+DEFFUNC(put,no_rnd,xy,16,OP_XY,PACK)
+
+#undef OP
+#define OP avg
+
+DEFFUNC(avg, rnd,o,8,OP_C,avg2)
+DEFFUNC(avg, rnd,x,8,OP_X,avg2)
+DEFFUNC(avg,no_rnd,x,8,OP_X,avg2)
+DEFFUNC(avg, rnd,y,8,OP_Y,avg2)
+DEFFUNC(avg,no_rnd,y,8,OP_Y,avg2)
+DEFFUNC(avg, rnd,xy,8,OP_XY,PACK)
+DEFFUNC(avg,no_rnd,xy,8,OP_XY,PACK)
+DEFFUNC(avg, rnd,o,16,OP_C,avg2)
+DEFFUNC(avg, rnd,x,16,OP_X,avg2)
+DEFFUNC(avg,no_rnd,x,16,OP_X,avg2)
+DEFFUNC(avg, rnd,y,16,OP_Y,avg2)
+DEFFUNC(avg,no_rnd,y,16,OP_Y,avg2)
+DEFFUNC(avg, rnd,xy,16,OP_XY,PACK)
+DEFFUNC(avg,no_rnd,xy,16,OP_XY,PACK)
+
+#undef OP
+
+#define put_no_rnd_pixels8_o put_rnd_pixels8_o
+#define put_no_rnd_pixels16_o put_rnd_pixels16_o
+#define avg_no_rnd_pixels8_o avg_rnd_pixels8_o
+#define avg_no_rnd_pixels16_o avg_rnd_pixels16_o
+
+#define put_pixels8_c put_rnd_pixels8_o
+#define put_pixels16_c put_rnd_pixels16_o
+#define avg_pixels8_c avg_rnd_pixels8_o
+#define avg_pixels16_c avg_rnd_pixels16_o
+#define put_no_rnd_pixels8_c put_rnd_pixels8_o
+#define put_no_rnd_pixels16_c put_rnd_pixels16_o
+#define avg_no_rnd_pixels8_c avg_rnd_pixels8_o
+#define avg_no_rnd_pixels16_c avg_rnd_pixels16_o
+
+#define QPEL
+
+#ifdef QPEL
+
+#include "qpel.c"
+
+#endif
+
+void dsputil_init_align(DSPContext* c, AVCodecContext *avctx)
+{
+ c->put_pixels_tab[0][0] = put_rnd_pixels16_o;
+ c->put_pixels_tab[0][1] = put_rnd_pixels16_x;
+ c->put_pixels_tab[0][2] = put_rnd_pixels16_y;
+ c->put_pixels_tab[0][3] = put_rnd_pixels16_xy;
+ c->put_pixels_tab[1][0] = put_rnd_pixels8_o;
+ c->put_pixels_tab[1][1] = put_rnd_pixels8_x;
+ c->put_pixels_tab[1][2] = put_rnd_pixels8_y;
+ c->put_pixels_tab[1][3] = put_rnd_pixels8_xy;
+
+ c->put_no_rnd_pixels_tab[0][0] = put_no_rnd_pixels16_o;
+ c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x;
+ c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y;
+ c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy;
+ c->put_no_rnd_pixels_tab[1][0] = put_no_rnd_pixels8_o;
+ c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x;
+ c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y;
+ c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels8_xy;
+
+ c->avg_pixels_tab[0][0] = avg_rnd_pixels16_o;
+ c->avg_pixels_tab[0][1] = avg_rnd_pixels16_x;
+ c->avg_pixels_tab[0][2] = avg_rnd_pixels16_y;
+ c->avg_pixels_tab[0][3] = avg_rnd_pixels16_xy;
+ c->avg_pixels_tab[1][0] = avg_rnd_pixels8_o;
+ c->avg_pixels_tab[1][1] = avg_rnd_pixels8_x;
+ c->avg_pixels_tab[1][2] = avg_rnd_pixels8_y;
+ c->avg_pixels_tab[1][3] = avg_rnd_pixels8_xy;
+
+ c->avg_no_rnd_pixels_tab[0][0] = avg_no_rnd_pixels16_o;
+ c->avg_no_rnd_pixels_tab[0][1] = avg_no_rnd_pixels16_x;
+ c->avg_no_rnd_pixels_tab[0][2] = avg_no_rnd_pixels16_y;
+ c->avg_no_rnd_pixels_tab[0][3] = avg_no_rnd_pixels16_xy;
+ c->avg_no_rnd_pixels_tab[1][0] = avg_no_rnd_pixels8_o;
+ c->avg_no_rnd_pixels_tab[1][1] = avg_no_rnd_pixels8_x;
+ c->avg_no_rnd_pixels_tab[1][2] = avg_no_rnd_pixels8_y;
+ c->avg_no_rnd_pixels_tab[1][3] = avg_no_rnd_pixels8_xy;
+
+#ifdef QPEL
+
+#define dspfunc(PFX, IDX, NUM) \
+ c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_c; \
+ c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_c; \
+ c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_c; \
+ c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_c; \
+ c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_c; \
+ c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_c; \
+ c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_c; \
+ c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_c; \
+ c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_c; \
+ c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_c; \
+ c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_c; \
+ c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_c; \
+ c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_c; \
+ c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_c; \
+ c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_c; \
+ c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_c
+
+ dspfunc(put_qpel, 0, 16);
+ dspfunc(put_no_rnd_qpel, 0, 16);
+
+ dspfunc(avg_qpel, 0, 16);
+ /* dspfunc(avg_no_rnd_qpel, 0, 16); */
+
+ dspfunc(put_qpel, 1, 8);
+ dspfunc(put_no_rnd_qpel, 1, 8);
+
+ dspfunc(avg_qpel, 1, 8);
+ /* dspfunc(avg_no_rnd_qpel, 1, 8); */
+
+ dspfunc(put_h264_qpel, 0, 16);
+ dspfunc(put_h264_qpel, 1, 8);
+ dspfunc(put_h264_qpel, 2, 4);
+ dspfunc(avg_h264_qpel, 0, 16);
+ dspfunc(avg_h264_qpel, 1, 8);
+ dspfunc(avg_h264_qpel, 2, 4);
+
+#undef dspfunc
+ c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_c;
+ c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_c;
+ c->put_h264_chroma_pixels_tab[2]= put_h264_chroma_mc2_c;
+ c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_c;
+ c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_c;
+ c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_c;
+
+ c->put_mspel_pixels_tab[0]= put_mspel8_mc00_c;
+ c->put_mspel_pixels_tab[1]= put_mspel8_mc10_c;
+ c->put_mspel_pixels_tab[2]= put_mspel8_mc20_c;
+ c->put_mspel_pixels_tab[3]= put_mspel8_mc30_c;
+ c->put_mspel_pixels_tab[4]= put_mspel8_mc02_c;
+ c->put_mspel_pixels_tab[5]= put_mspel8_mc12_c;
+ c->put_mspel_pixels_tab[6]= put_mspel8_mc22_c;
+ c->put_mspel_pixels_tab[7]= put_mspel8_mc32_c;
+
+ c->gmc1 = gmc1_c;
+ c->gmc = gmc_c;
+
+#endif
+}
diff --git a/contrib/ffmpeg/libavcodec/sh4/dsputil_sh4.c b/contrib/ffmpeg/libavcodec/sh4/dsputil_sh4.c
new file mode 100644
index 000000000..b38eb2551
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/sh4/dsputil_sh4.c
@@ -0,0 +1,120 @@
+/*
+ * sh4 dsputil
+ *
+ * Copyright (c) 2003 BERO <bero@geocities.co.jp>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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"
+
+static void memzero_align8(void *dst,size_t size)
+{
+#if defined(__SH4__) || defined(__SH4_SINGLE__) || defined(__SH4_SINGLE_ONLY__)
+ (char*)dst+=size;
+ size/=8*4;
+ asm(
+#if defined(__SH4__)
+ " fschg\n" //single float mode
+#endif
+ " fldi0 fr0\n"
+ " fldi0 fr1\n"
+ " fschg\n" // double
+ "1: \n" \
+ " dt %1\n"
+ " fmov dr0,@-%0\n"
+ " fmov dr0,@-%0\n"
+ " fmov dr0,@-%0\n"
+ " bf.s 1b\n"
+ " fmov dr0,@-%0\n"
+#if defined(__SH4_SINGLE__) || defined(__SH4_SINGLE_ONLY__)
+ " fschg" //back to single
+#endif
+ : : "r"(dst),"r"(size): "memory" );
+#else
+ double *d = dst;
+ size/=8*4;
+ do {
+ d[0] = 0.0;
+ d[1] = 0.0;
+ d[2] = 0.0;
+ d[3] = 0.0;
+ d+=4;
+ } while(--size);
+#endif
+}
+
+static void clear_blocks_sh4(DCTELEM *blocks)
+{
+// if (((int)blocks&7)==0)
+ memzero_align8(blocks,sizeof(DCTELEM)*6*64);
+}
+
+extern void idct_sh4(DCTELEM *block);
+static void idct_put(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ idct_sh4(block);
+ int i;
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+ for(i=0;i<8;i++) {
+ dest[0] = cm[block[0]];
+ dest[1] = cm[block[1]];
+ dest[2] = cm[block[2]];
+ dest[3] = cm[block[3]];
+ dest[4] = cm[block[4]];
+ dest[5] = cm[block[5]];
+ dest[6] = cm[block[6]];
+ dest[7] = cm[block[7]];
+ dest+=line_size;
+ block+=8;
+ }
+}
+static void idct_add(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ idct_sh4(block);
+ int i;
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+ for(i=0;i<8;i++) {
+ dest[0] = cm[dest[0]+block[0]];
+ dest[1] = cm[dest[1]+block[1]];
+ dest[2] = cm[dest[2]+block[2]];
+ dest[3] = cm[dest[3]+block[3]];
+ dest[4] = cm[dest[4]+block[4]];
+ dest[5] = cm[dest[5]+block[5]];
+ dest[6] = cm[dest[6]+block[6]];
+ dest[7] = cm[dest[7]+block[7]];
+ dest+=line_size;
+ block+=8;
+ }
+}
+
+extern void dsputil_init_align(DSPContext* c, AVCodecContext *avctx);
+
+void dsputil_init_sh4(DSPContext* c, AVCodecContext *avctx)
+{
+ const int idct_algo= avctx->idct_algo;
+ dsputil_init_align(c,avctx);
+
+ c->clear_blocks = clear_blocks_sh4;
+ if(idct_algo==FF_IDCT_AUTO || idct_algo==FF_IDCT_SH4){
+ c->idct_put = idct_put;
+ c->idct_add = idct_add;
+ c->idct = idct_sh4;
+ c->idct_permutation_type= FF_NO_IDCT_PERM; //FF_SIMPLE_IDCT_PERM; //FF_LIBMPEG2_IDCT_PERM;
+ }
+}
diff --git a/contrib/ffmpeg/libavcodec/sh4/idct_sh4.c b/contrib/ffmpeg/libavcodec/sh4/idct_sh4.c
new file mode 100644
index 000000000..3b8428c3c
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/sh4/idct_sh4.c
@@ -0,0 +1,366 @@
+/*
+ * idct for sh4
+ *
+ * Copyright (c) 2001-2003 BERO <bero@geocities.co.jp>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 "../dsputil.h"
+#define c1 1.38703984532214752434 /* sqrt(2)*cos(1*pi/16) */
+#define c2 1.30656296487637657577 /* sqrt(2)*cos(2*pi/16) */
+#define c3 1.17587560241935884520 /* sqrt(2)*cos(3*pi/16) */
+#define c4 1.00000000000000000000 /* sqrt(2)*cos(4*pi/16) */
+#define c5 0.78569495838710234903 /* sqrt(2)*cos(5*pi/16) */
+#define c6 0.54119610014619712324 /* sqrt(2)*cos(6*pi/16) */
+#define c7 0.27589937928294311353 /* sqrt(2)*cos(7*pi/16) */
+
+static const float even_table[] __attribute__ ((aligned(8))) = {
+ c4, c4, c4, c4,
+ c2, c6,-c6,-c2,
+ c4,-c4,-c4, c4,
+ c6,-c2, c2,-c6
+};
+
+static const float odd_table[] __attribute__ ((aligned(8))) = {
+ c1, c3, c5, c7,
+ c3,-c7,-c1,-c5,
+ c5,-c1, c7, c3,
+ c7,-c5, c3,-c1
+};
+
+#undef c1
+#undef c2
+#undef c3
+#undef c4
+#undef c5
+#undef c6
+#undef c7
+
+#if defined(__SH4_SINGLE__) || defined(__SH4_SINGLE_ONLY__)
+
+#define load_matrix(table) \
+ __asm__ volatile( \
+ " fschg\n" \
+ " fmov @%0+,xd0\n" \
+ " fmov @%0+,xd2\n" \
+ " fmov @%0+,xd4\n" \
+ " fmov @%0+,xd6\n" \
+ " fmov @%0+,xd8\n" \
+ " fmov @%0+,xd10\n" \
+ " fmov @%0+,xd12\n" \
+ " fmov @%0+,xd14\n" \
+ " fschg\n" \
+ :\
+ : "r"(table)\
+ : "0" \
+ )
+
+#define ftrv() \
+ __asm__ volatile("ftrv xmtrx,fv0" \
+ : "=f"(fr0),"=f"(fr1),"=f"(fr2),"=f"(fr3) \
+ : "0"(fr0), "1"(fr1), "2"(fr2), "3"(fr3) );
+
+#define DEFREG \
+ register float fr0 __asm__("fr0"); \
+ register float fr1 __asm__("fr1"); \
+ register float fr2 __asm__("fr2"); \
+ register float fr3 __asm__("fr3")
+
+#else
+
+/* generic C code for check */
+
+static void ftrv_(const float xf[],float fv[])
+{
+ float f0,f1,f2,f3;
+ f0 = fv[0];
+ f1 = fv[1];
+ f2 = fv[2];
+ f3 = fv[3];
+ fv[0] = xf[0]*f0 + xf[4]*f1 + xf[ 8]*f2 + xf[12]*f3;
+ fv[1] = xf[1]*f0 + xf[5]*f1 + xf[ 9]*f2 + xf[13]*f3;
+ fv[2] = xf[2]*f0 + xf[6]*f1 + xf[10]*f2 + xf[14]*f3;
+ fv[3] = xf[3]*f0 + xf[7]*f1 + xf[11]*f2 + xf[15]*f3;
+}
+
+static void load_matrix_(float xf[],const float table[])
+{
+ int i;
+ for(i=0;i<16;i++) xf[i]=table[i];
+}
+
+#define ftrv() ftrv_(xf,fv)
+#define load_matrix(table) load_matrix_(xf,table)
+
+#define DEFREG \
+ float fv[4],xf[16]
+
+#define fr0 fv[0]
+#define fr1 fv[1]
+#define fr2 fv[2]
+#define fr3 fv[3]
+
+#endif
+
+#if 1
+#define DESCALE(x,n) (x)*(1.0f/(1<<(n)))
+#else
+#define DESCALE(x,n) (((int)(x)+(1<<(n-1)))>>(n))
+#endif
+
+/* this code work worse on gcc cvs. 3.2.3 work fine */
+
+
+#if 1
+//optimized
+
+void idct_sh4(DCTELEM *block)
+{
+ DEFREG;
+
+ int i;
+ float tblock[8*8],*fblock;
+ int ofs1,ofs2,ofs3;
+
+#if defined(__SH4__)
+#error "FIXME!! change to single float"
+#endif
+
+ /* row */
+
+ /* even part */
+ load_matrix(even_table);
+
+ fblock = tblock+4;
+ i = 8;
+ do {
+ fr0 = block[0];
+ fr1 = block[2];
+ fr2 = block[4];
+ fr3 = block[6];
+ block+=8;
+ ftrv();
+ *--fblock = fr3;
+ *--fblock = fr2;
+ *--fblock = fr1;
+ *--fblock = fr0;
+ fblock+=8+4;
+ } while(--i);
+ block-=8*8;
+ fblock-=8*8+4;
+
+ load_matrix(odd_table);
+
+ i = 8;
+
+// ofs1 = sizeof(float)*1;
+// ofs2 = sizeof(float)*2;
+// ofs3 = sizeof(float)*3;
+
+ do {
+ float t0,t1,t2,t3;
+ fr0 = block[1];
+ fr1 = block[3];
+ fr2 = block[5];
+ fr3 = block[7];
+ block+=8;
+ ftrv();
+ t0 = *fblock++;
+ t1 = *fblock++;
+ t2 = *fblock++;
+ t3 = *fblock++;
+ fblock+=4;
+ *--fblock = t0 - fr0;
+ *--fblock = t1 - fr1;
+ *--fblock = t2 - fr2;
+ *--fblock = t3 - fr3;
+ *--fblock = t3 + fr3;
+ *--fblock = t2 + fr2;
+ *--fblock = t1 + fr1;
+ *--fblock = t0 + fr0;
+ fblock+=8;
+ } while(--i);
+ block-=8*8;
+ fblock-=8*8;
+
+ /* col */
+
+ /* even part */
+ load_matrix(even_table);
+
+ ofs1 = sizeof(float)*2*8;
+ ofs2 = sizeof(float)*4*8;
+ ofs3 = sizeof(float)*6*8;
+
+ i = 8;
+
+#define OA(fblock,ofs) *(float*)((char*)fblock + ofs)
+
+ do {
+ fr0 = OA(fblock, 0);
+ fr1 = OA(fblock,ofs1);
+ fr2 = OA(fblock,ofs2);
+ fr3 = OA(fblock,ofs3);
+ ftrv();
+ OA(fblock,0 ) = fr0;
+ OA(fblock,ofs1) = fr1;
+ OA(fblock,ofs2) = fr2;
+ OA(fblock,ofs3) = fr3;
+ fblock++;
+ } while(--i);
+ fblock-=8;
+
+ load_matrix(odd_table);
+
+ i=8;
+ do {
+ float t0,t1,t2,t3;
+ t0 = OA(fblock, 0); /* [8*0] */
+ t1 = OA(fblock,ofs1); /* [8*2] */
+ t2 = OA(fblock,ofs2); /* [8*4] */
+ t3 = OA(fblock,ofs3); /* [8*6] */
+ fblock+=8;
+ fr0 = OA(fblock, 0); /* [8*1] */
+ fr1 = OA(fblock,ofs1); /* [8*3] */
+ fr2 = OA(fblock,ofs2); /* [8*5] */
+ fr3 = OA(fblock,ofs3); /* [8*7] */
+ fblock+=-8+1;
+ ftrv();
+ block[8*0] = DESCALE(t0 + fr0,3);
+ block[8*7] = DESCALE(t0 - fr0,3);
+ block[8*1] = DESCALE(t1 + fr1,3);
+ block[8*6] = DESCALE(t1 - fr1,3);
+ block[8*2] = DESCALE(t2 + fr2,3);
+ block[8*5] = DESCALE(t2 - fr2,3);
+ block[8*3] = DESCALE(t3 + fr3,3);
+ block[8*4] = DESCALE(t3 - fr3,3);
+ block++;
+ } while(--i);
+
+#if defined(__SH4__)
+#error "FIXME!! change to double"
+#endif
+}
+#else
+void idct_sh4(DCTELEM *block)
+{
+ DEFREG;
+
+ int i;
+ float tblock[8*8],*fblock;
+
+ /* row */
+
+ /* even part */
+ load_matrix(even_table);
+
+ fblock = tblock;
+ i = 8;
+ do {
+ fr0 = block[0];
+ fr1 = block[2];
+ fr2 = block[4];
+ fr3 = block[6];
+ block+=8;
+ ftrv();
+ fblock[0] = fr0;
+ fblock[2] = fr1;
+ fblock[4] = fr2;
+ fblock[6] = fr3;
+ fblock+=8;
+ } while(--i);
+ block-=8*8;
+ fblock-=8*8;
+
+ load_matrix(odd_table);
+
+ i = 8;
+
+ do {
+ float t0,t1,t2,t3;
+ fr0 = block[1];
+ fr1 = block[3];
+ fr2 = block[5];
+ fr3 = block[7];
+ block+=8;
+ ftrv();
+ t0 = fblock[0];
+ t1 = fblock[2];
+ t2 = fblock[4];
+ t3 = fblock[6];
+ fblock[0] = t0 + fr0;
+ fblock[7] = t0 - fr0;
+ fblock[1] = t1 + fr1;
+ fblock[6] = t1 - fr1;
+ fblock[2] = t2 + fr2;
+ fblock[5] = t2 - fr2;
+ fblock[3] = t3 + fr3;
+ fblock[4] = t3 - fr3;
+ fblock+=8;
+ } while(--i);
+ block-=8*8;
+ fblock-=8*8;
+
+ /* col */
+
+ /* even part */
+ load_matrix(even_table);
+
+ i = 8;
+
+ do {
+ fr0 = fblock[8*0];
+ fr1 = fblock[8*2];
+ fr2 = fblock[8*4];
+ fr3 = fblock[8*6];
+ ftrv();
+ fblock[8*0] = fr0;
+ fblock[8*2] = fr1;
+ fblock[8*4] = fr2;
+ fblock[8*6] = fr3;
+ fblock++;
+ } while(--i);
+ fblock-=8;
+
+ load_matrix(odd_table);
+
+ i=8;
+ do {
+ float t0,t1,t2,t3;
+ fr0 = fblock[8*1];
+ fr1 = fblock[8*3];
+ fr2 = fblock[8*5];
+ fr3 = fblock[8*7];
+ ftrv();
+ t0 = fblock[8*0];
+ t1 = fblock[8*2];
+ t2 = fblock[8*4];
+ t3 = fblock[8*6];
+ fblock++;
+ block[8*0] = DESCALE(t0 + fr0,3);
+ block[8*7] = DESCALE(t0 - fr0,3);
+ block[8*1] = DESCALE(t1 + fr1,3);
+ block[8*6] = DESCALE(t1 - fr1,3);
+ block[8*2] = DESCALE(t2 + fr2,3);
+ block[8*5] = DESCALE(t2 - fr2,3);
+ block[8*3] = DESCALE(t3 + fr3,3);
+ block[8*4] = DESCALE(t3 - fr3,3);
+ block++;
+ } while(--i);
+}
+#endif
diff --git a/contrib/ffmpeg/libavcodec/sh4/qpel.c b/contrib/ffmpeg/libavcodec/sh4/qpel.c
new file mode 100644
index 000000000..7a73ac50d
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/sh4/qpel.c
@@ -0,0 +1,1600 @@
+/*
+ * This is optimized for sh, which have post increment addressing (*p++).
+ * Some CPU may be index (p[n]) faster than post increment (*p++).
+ *
+ * copyright (c) 2001-2003 BERO <bero@geocities.co.jp>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 LD(adr) *(uint32_t*)(adr)
+
+#define PIXOP2(OPNAME, OP) \
+/*static inline void OPNAME ## _no_rnd_pixels8_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, int src_stride1, int src_stride2, int h) \
+{\
+ do {\
+ OP(LP(dst ),no_rnd_avg32(LD32(src1 ),LD32(src2 )) ); \
+ OP(LP(dst+4),no_rnd_avg32(LD32(src1+4),LD32(src2+4)) ); \
+ src1+=src_stride1; \
+ src2+=src_stride2; \
+ dst+=dst_stride; \
+ } while(--h); \
+}\
+\
+static inline void OPNAME ## _pixels8_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, int src_stride1, int src_stride2, int h) \
+{\
+ do {\
+ OP(LP(dst ),rnd_avg32(LD32(src1 ),LD32(src2 )) ); \
+ OP(LP(dst+4),rnd_avg32(LD32(src1+4),LD32(src2+4)) ); \
+ src1+=src_stride1; \
+ src2+=src_stride2; \
+ dst+=dst_stride; \
+ } while(--h); \
+}\
+\
+static inline void OPNAME ## _pixels4_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, int src_stride1, int src_stride2, int h) \
+{\
+ do {\
+ OP(LP(dst ),rnd_avg32(LD32(src1 ),LD32(src2 )) ); \
+ src1+=src_stride1; \
+ src2+=src_stride2; \
+ dst+=dst_stride; \
+ } while(--h); \
+}\
+\
+static inline void OPNAME ## _no_rnd_pixels16_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, int src_stride1, int src_stride2, int h) \
+{\
+ do {\
+ OP(LP(dst ),no_rnd_avg32(LD32(src1 ),LD32(src2 )) ); \
+ OP(LP(dst+4),no_rnd_avg32(LD32(src1+4),LD32(src2+4)) ); \
+ OP(LP(dst+8),no_rnd_avg32(LD32(src1+8),LD32(src2+8)) ); \
+ OP(LP(dst+12),no_rnd_avg32(LD32(src1+12),LD32(src2+12)) ); \
+ src1+=src_stride1; \
+ src2+=src_stride2; \
+ dst+=dst_stride; \
+ } while(--h); \
+}\
+\
+static inline void OPNAME ## _pixels16_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, int src_stride1, int src_stride2, int h) \
+{\
+ do {\
+ OP(LP(dst ),rnd_avg32(LD32(src1 ),LD32(src2 )) ); \
+ OP(LP(dst+4),rnd_avg32(LD32(src1+4),LD32(src2+4)) ); \
+ OP(LP(dst+8),rnd_avg32(LD32(src1+8),LD32(src2+8)) ); \
+ OP(LP(dst+12),rnd_avg32(LD32(src1+12),LD32(src2+12)) ); \
+ src1+=src_stride1; \
+ src2+=src_stride2; \
+ dst+=dst_stride; \
+ } while(--h); \
+}*/\
+\
+static inline void OPNAME ## _pixels4_l2_aligned(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, int src_stride1, int src_stride2, int h) \
+{\
+ do {\
+ OP(LP(dst ),rnd_avg32(LP(src1 ),LP(src2 )) ); \
+ src1+=src_stride1; \
+ src2+=src_stride2; \
+ dst+=dst_stride; \
+ } while(--h); \
+}\
+\
+static inline void OPNAME ## _pixels4_l2_aligned2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, int src_stride1, int src_stride2, int h) \
+{\
+ do {\
+ OP(LP(dst ),rnd_avg32(LD32(src1 ),LP(src2 )) ); \
+ src1+=src_stride1; \
+ src2+=src_stride2; \
+ dst+=dst_stride; \
+ } while(--h); \
+}\
+\
+static inline void OPNAME ## _no_rnd_pixels16_l2_aligned2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, int src_stride1, int src_stride2, int h) \
+{\
+ do {\
+ OP(LP(dst ),no_rnd_avg32(LD32(src1 ),LP(src2 )) ); \
+ OP(LP(dst+4),no_rnd_avg32(LD32(src1+4),LP(src2+4)) ); \
+ OP(LP(dst+8),no_rnd_avg32(LD32(src1+8),LP(src2+8)) ); \
+ OP(LP(dst+12),no_rnd_avg32(LD32(src1+12),LP(src2+12)) ); \
+ src1+=src_stride1; \
+ src2+=src_stride2; \
+ dst+=dst_stride; \
+ } while(--h); \
+}\
+\
+static inline void OPNAME ## _pixels16_l2_aligned2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, int src_stride1, int src_stride2, int h) \
+{\
+ do {\
+ OP(LP(dst ),rnd_avg32(LD32(src1 ),LP(src2 )) ); \
+ OP(LP(dst+4),rnd_avg32(LD32(src1+4),LP(src2+4)) ); \
+ OP(LP(dst+8),rnd_avg32(LD32(src1+8),LP(src2+8)) ); \
+ OP(LP(dst+12),rnd_avg32(LD32(src1+12),LP(src2+12)) ); \
+ src1+=src_stride1; \
+ src2+=src_stride2; \
+ dst+=dst_stride; \
+ } while(--h); \
+}\
+\
+static inline void OPNAME ## _no_rnd_pixels8_l2_aligned2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, int src_stride1, int src_stride2, int h) \
+{\
+ do { /* onlye src2 aligned */\
+ OP(LP(dst ),no_rnd_avg32(LD32(src1 ),LP(src2 )) ); \
+ OP(LP(dst+4),no_rnd_avg32(LD32(src1+4),LP(src2+4)) ); \
+ src1+=src_stride1; \
+ src2+=src_stride2; \
+ dst+=dst_stride; \
+ } while(--h); \
+}\
+\
+static inline void OPNAME ## _pixels8_l2_aligned2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, int src_stride1, int src_stride2, int h) \
+{\
+ do {\
+ OP(LP(dst ),rnd_avg32(LD32(src1 ),LP(src2 )) ); \
+ OP(LP(dst+4),rnd_avg32(LD32(src1+4),LP(src2+4)) ); \
+ src1+=src_stride1; \
+ src2+=src_stride2; \
+ dst+=dst_stride; \
+ } while(--h); \
+}\
+\
+static inline void OPNAME ## _no_rnd_pixels8_l2_aligned(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, int src_stride1, int src_stride2, int h) \
+{\
+ do {\
+ OP(LP(dst ),no_rnd_avg32(LP(src1 ),LP(src2 )) ); \
+ OP(LP(dst+4),no_rnd_avg32(LP(src1+4),LP(src2+4)) ); \
+ src1+=src_stride1; \
+ src2+=src_stride2; \
+ dst+=dst_stride; \
+ } while(--h); \
+}\
+\
+static inline void OPNAME ## _pixels8_l2_aligned(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, int src_stride1, int src_stride2, int h) \
+{\
+ do {\
+ OP(LP(dst ),rnd_avg32(LP(src1 ),LP(src2 )) ); \
+ OP(LP(dst+4),rnd_avg32(LP(src1+4),LP(src2+4)) ); \
+ src1+=src_stride1; \
+ src2+=src_stride2; \
+ dst+=dst_stride; \
+ } while(--h); \
+}\
+\
+static inline void OPNAME ## _no_rnd_pixels16_l2_aligned(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, int src_stride1, int src_stride2, int h) \
+{\
+ do {\
+ OP(LP(dst ),no_rnd_avg32(LP(src1 ),LP(src2 )) ); \
+ OP(LP(dst+4),no_rnd_avg32(LP(src1+4),LP(src2+4)) ); \
+ OP(LP(dst+8),no_rnd_avg32(LP(src1+8),LP(src2+8)) ); \
+ OP(LP(dst+12),no_rnd_avg32(LP(src1+12),LP(src2+12)) ); \
+ src1+=src_stride1; \
+ src2+=src_stride2; \
+ dst+=dst_stride; \
+ } while(--h); \
+}\
+\
+static inline void OPNAME ## _pixels16_l2_aligned(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, int src_stride1, int src_stride2, int h) \
+{\
+ do {\
+ OP(LP(dst ),rnd_avg32(LP(src1 ),LP(src2 )) ); \
+ OP(LP(dst+4),rnd_avg32(LP(src1+4),LP(src2+4)) ); \
+ OP(LP(dst+8),rnd_avg32(LP(src1+8),LP(src2+8)) ); \
+ OP(LP(dst+12),rnd_avg32(LP(src1+12),LP(src2+12)) ); \
+ src1+=src_stride1; \
+ src2+=src_stride2; \
+ dst+=dst_stride; \
+ } while(--h); \
+}\
+\
+static inline void OPNAME ## _no_rnd_pixels16_l2_aligned1(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, int src_stride1, int src_stride2, int h) \
+{ OPNAME ## _no_rnd_pixels16_l2_aligned2(dst,src2,src1,dst_stride,src_stride2,src_stride1,h); } \
+\
+static inline void OPNAME ## _pixels16_l2_aligned1(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, int src_stride1, int src_stride2, int h) \
+{ OPNAME ## _pixels16_l2_aligned2(dst,src2,src1,dst_stride,src_stride2,src_stride1,h); } \
+\
+static inline void OPNAME ## _no_rnd_pixels8_l2_aligned1(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, int src_stride1, int src_stride2, int h) \
+{ OPNAME ## _no_rnd_pixels8_l2_aligned2(dst,src2,src1,dst_stride,src_stride2,src_stride1,h); } \
+\
+static inline void OPNAME ## _pixels8_l2_aligned1(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, int src_stride1, int src_stride2, int h) \
+{ OPNAME ## _pixels8_l2_aligned2(dst,src2,src1,dst_stride,src_stride2,src_stride1,h); } \
+\
+static inline void OPNAME ## _pixels8_l4_aligned(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
+ do { \
+ uint32_t a0,a1,a2,a3; \
+ UNPACK(a0,a1,LP(src1),LP(src2)); \
+ UNPACK(a2,a3,LP(src3),LP(src4)); \
+ OP(LP(dst),rnd_PACK(a0,a1,a2,a3)); \
+ UNPACK(a0,a1,LP(src1+4),LP(src2+4)); \
+ UNPACK(a2,a3,LP(src3+4),LP(src4+4)); \
+ OP(LP(dst+4),rnd_PACK(a0,a1,a2,a3)); \
+ src1+=src_stride1;\
+ src2+=src_stride2;\
+ src3+=src_stride3;\
+ src4+=src_stride4;\
+ dst+=dst_stride;\
+ } while(--h); \
+} \
+\
+static inline void OPNAME ## _no_rnd_pixels8_l4_aligned(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
+ do { \
+ uint32_t a0,a1,a2,a3; \
+ UNPACK(a0,a1,LP(src1),LP(src2)); \
+ UNPACK(a2,a3,LP(src3),LP(src4)); \
+ OP(LP(dst),no_rnd_PACK(a0,a1,a2,a3)); \
+ UNPACK(a0,a1,LP(src1+4),LP(src2+4)); \
+ UNPACK(a2,a3,LP(src3+4),LP(src4+4)); \
+ OP(LP(dst+4),no_rnd_PACK(a0,a1,a2,a3)); \
+ src1+=src_stride1;\
+ src2+=src_stride2;\
+ src3+=src_stride3;\
+ src4+=src_stride4;\
+ dst+=dst_stride;\
+ } while(--h); \
+} \
+\
+static inline void OPNAME ## _pixels8_l4_aligned0(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
+ do { \
+ uint32_t a0,a1,a2,a3; /* src1 only not aligned */\
+ UNPACK(a0,a1,LD32(src1),LP(src2)); \
+ UNPACK(a2,a3,LP(src3),LP(src4)); \
+ OP(LP(dst),rnd_PACK(a0,a1,a2,a3)); \
+ UNPACK(a0,a1,LD32(src1+4),LP(src2+4)); \
+ UNPACK(a2,a3,LP(src3+4),LP(src4+4)); \
+ OP(LP(dst+4),rnd_PACK(a0,a1,a2,a3)); \
+ src1+=src_stride1;\
+ src2+=src_stride2;\
+ src3+=src_stride3;\
+ src4+=src_stride4;\
+ dst+=dst_stride;\
+ } while(--h); \
+} \
+\
+static inline void OPNAME ## _no_rnd_pixels8_l4_aligned0(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
+ do { \
+ uint32_t a0,a1,a2,a3; \
+ UNPACK(a0,a1,LD32(src1),LP(src2)); \
+ UNPACK(a2,a3,LP(src3),LP(src4)); \
+ OP(LP(dst),no_rnd_PACK(a0,a1,a2,a3)); \
+ UNPACK(a0,a1,LD32(src1+4),LP(src2+4)); \
+ UNPACK(a2,a3,LP(src3+4),LP(src4+4)); \
+ OP(LP(dst+4),no_rnd_PACK(a0,a1,a2,a3)); \
+ src1+=src_stride1;\
+ src2+=src_stride2;\
+ src3+=src_stride3;\
+ src4+=src_stride4;\
+ dst+=dst_stride;\
+ } while(--h); \
+} \
+\
+static inline void OPNAME ## _pixels16_l4_aligned(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
+ do { \
+ uint32_t a0,a1,a2,a3; \
+ UNPACK(a0,a1,LP(src1),LP(src2)); \
+ UNPACK(a2,a3,LP(src3),LP(src4)); \
+ OP(LP(dst),rnd_PACK(a0,a1,a2,a3)); \
+ UNPACK(a0,a1,LP(src1+4),LP(src2+4)); \
+ UNPACK(a2,a3,LP(src3+4),LP(src4+4)); \
+ OP(LP(dst+8),rnd_PACK(a0,a1,a2,a3)); \
+ UNPACK(a0,a1,LP(src1+8),LP(src2+8)); \
+ UNPACK(a2,a3,LP(src3+8),LP(src4+8)); \
+ OP(LP(dst+8),rnd_PACK(a0,a1,a2,a3)); \
+ UNPACK(a0,a1,LP(src1+12),LP(src2+12)); \
+ UNPACK(a2,a3,LP(src3+12),LP(src4+12)); \
+ OP(LP(dst+12),rnd_PACK(a0,a1,a2,a3)); \
+ src1+=src_stride1;\
+ src2+=src_stride2;\
+ src3+=src_stride3;\
+ src4+=src_stride4;\
+ dst+=dst_stride;\
+ } while(--h); \
+} \
+\
+static inline void OPNAME ## _no_rnd_pixels16_l4_aligned(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
+ do { \
+ uint32_t a0,a1,a2,a3; \
+ UNPACK(a0,a1,LP(src1),LP(src2)); \
+ UNPACK(a2,a3,LP(src3),LP(src4)); \
+ OP(LP(dst),no_rnd_PACK(a0,a1,a2,a3)); \
+ UNPACK(a0,a1,LP(src1+4),LP(src2+4)); \
+ UNPACK(a2,a3,LP(src3+4),LP(src4+4)); \
+ OP(LP(dst+4),no_rnd_PACK(a0,a1,a2,a3)); \
+ UNPACK(a0,a1,LP(src1+8),LP(src2+8)); \
+ UNPACK(a2,a3,LP(src3+8),LP(src4+8)); \
+ OP(LP(dst+8),no_rnd_PACK(a0,a1,a2,a3)); \
+ UNPACK(a0,a1,LP(src1+12),LP(src2+12)); \
+ UNPACK(a2,a3,LP(src3+12),LP(src4+12)); \
+ OP(LP(dst+12),no_rnd_PACK(a0,a1,a2,a3)); \
+ src1+=src_stride1;\
+ src2+=src_stride2;\
+ src3+=src_stride3;\
+ src4+=src_stride4;\
+ dst+=dst_stride;\
+ } while(--h); \
+} \
+\
+static inline void OPNAME ## _pixels16_l4_aligned0(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
+ do { /* src1 is unaligned */\
+ uint32_t a0,a1,a2,a3; \
+ UNPACK(a0,a1,LD32(src1),LP(src2)); \
+ UNPACK(a2,a3,LP(src3),LP(src4)); \
+ OP(LP(dst),rnd_PACK(a0,a1,a2,a3)); \
+ UNPACK(a0,a1,LD32(src1+4),LP(src2+4)); \
+ UNPACK(a2,a3,LP(src3+4),LP(src4+4)); \
+ OP(LP(dst+8),rnd_PACK(a0,a1,a2,a3)); \
+ UNPACK(a0,a1,LD32(src1+8),LP(src2+8)); \
+ UNPACK(a2,a3,LP(src3+8),LP(src4+8)); \
+ OP(LP(dst+8),rnd_PACK(a0,a1,a2,a3)); \
+ UNPACK(a0,a1,LD32(src1+12),LP(src2+12)); \
+ UNPACK(a2,a3,LP(src3+12),LP(src4+12)); \
+ OP(LP(dst+12),rnd_PACK(a0,a1,a2,a3)); \
+ src1+=src_stride1;\
+ src2+=src_stride2;\
+ src3+=src_stride3;\
+ src4+=src_stride4;\
+ dst+=dst_stride;\
+ } while(--h); \
+} \
+\
+static inline void OPNAME ## _no_rnd_pixels16_l4_aligned0(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
+ do { \
+ uint32_t a0,a1,a2,a3; \
+ UNPACK(a0,a1,LD32(src1),LP(src2)); \
+ UNPACK(a2,a3,LP(src3),LP(src4)); \
+ OP(LP(dst),no_rnd_PACK(a0,a1,a2,a3)); \
+ UNPACK(a0,a1,LD32(src1+4),LP(src2+4)); \
+ UNPACK(a2,a3,LP(src3+4),LP(src4+4)); \
+ OP(LP(dst+4),no_rnd_PACK(a0,a1,a2,a3)); \
+ UNPACK(a0,a1,LD32(src1+8),LP(src2+8)); \
+ UNPACK(a2,a3,LP(src3+8),LP(src4+8)); \
+ OP(LP(dst+8),no_rnd_PACK(a0,a1,a2,a3)); \
+ UNPACK(a0,a1,LD32(src1+12),LP(src2+12)); \
+ UNPACK(a2,a3,LP(src3+12),LP(src4+12)); \
+ OP(LP(dst+12),no_rnd_PACK(a0,a1,a2,a3)); \
+ src1+=src_stride1;\
+ src2+=src_stride2;\
+ src3+=src_stride3;\
+ src4+=src_stride4;\
+ dst+=dst_stride;\
+ } while(--h); \
+} \
+\
+
+#define op_avg(a, b) a = rnd_avg32(a,b)
+#define op_put(a, b) a = b
+
+PIXOP2(avg, op_avg)
+PIXOP2(put, op_put)
+#undef op_avg
+#undef op_put
+
+#define avg2(a,b) ((a+b+1)>>1)
+#define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
+
+
+static void gmc1_c(uint8_t *dst, uint8_t *src, int stride, int h, int x16, int y16, int rounder)
+{
+ const int A=(16-x16)*(16-y16);
+ const int B=( x16)*(16-y16);
+ const int C=(16-x16)*( y16);
+ const int D=( x16)*( y16);
+
+ do {
+ int t0,t1,t2,t3;
+ uint8_t *s0 = src;
+ uint8_t *s1 = src+stride;
+ t0 = *s0++; t2 = *s1++;
+ t1 = *s0++; t3 = *s1++;
+ dst[0]= (A*t0 + B*t1 + C*t2 + D*t3 + rounder)>>8;
+ t0 = *s0++; t2 = *s1++;
+ dst[1]= (A*t1 + B*t0 + C*t3 + D*t2 + rounder)>>8;
+ t1 = *s0++; t3 = *s1++;
+ dst[2]= (A*t0 + B*t1 + C*t2 + D*t3 + rounder)>>8;
+ t0 = *s0++; t2 = *s1++;
+ dst[3]= (A*t1 + B*t0 + C*t3 + D*t2 + rounder)>>8;
+ t1 = *s0++; t3 = *s1++;
+ dst[4]= (A*t0 + B*t1 + C*t2 + D*t3 + rounder)>>8;
+ t0 = *s0++; t2 = *s1++;
+ dst[5]= (A*t1 + B*t0 + C*t3 + D*t2 + rounder)>>8;
+ t1 = *s0++; t3 = *s1++;
+ dst[6]= (A*t0 + B*t1 + C*t2 + D*t3 + rounder)>>8;
+ t0 = *s0++; t2 = *s1++;
+ dst[7]= (A*t1 + B*t0 + C*t3 + D*t2 + rounder)>>8;
+ dst+= stride;
+ src+= stride;
+ }while(--h);
+}
+
+static void gmc_c(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)
+{
+ int y, vx, vy;
+ const int s= 1<<shift;
+
+ width--;
+ height--;
+
+ for(y=0; y<h; y++){
+ int x;
+
+ vx= ox;
+ vy= oy;
+ for(x=0; x<8; x++){ //XXX FIXME optimize
+ int src_x, src_y, frac_x, frac_y, index;
+
+ src_x= vx>>16;
+ src_y= vy>>16;
+ frac_x= src_x&(s-1);
+ frac_y= src_y&(s-1);
+ src_x>>=shift;
+ src_y>>=shift;
+
+ if((unsigned)src_x < width){
+ if((unsigned)src_y < height){
+ index= src_x + src_y*stride;
+ dst[y*stride + x]= ( ( src[index ]*(s-frac_x)
+ + src[index +1]* frac_x )*(s-frac_y)
+ + ( src[index+stride ]*(s-frac_x)
+ + src[index+stride+1]* frac_x )* frac_y
+ + r)>>(shift*2);
+ }else{
+ index= src_x + clip(src_y, 0, height)*stride;
+ dst[y*stride + x]= ( ( src[index ]*(s-frac_x)
+ + src[index +1]* frac_x )*s
+ + r)>>(shift*2);
+ }
+ }else{
+ if((unsigned)src_y < height){
+ index= clip(src_x, 0, width) + src_y*stride;
+ dst[y*stride + x]= ( ( src[index ]*(s-frac_y)
+ + src[index+stride ]* frac_y )*s
+ + r)>>(shift*2);
+ }else{
+ index= clip(src_x, 0, width) + clip(src_y, 0, height)*stride;
+ dst[y*stride + x]= src[index ];
+ }
+ }
+
+ vx+= dxx;
+ vy+= dyx;
+ }
+ ox += dxy;
+ oy += dyy;
+ }
+}
+#define H264_CHROMA_MC(OPNAME, OP)\
+static void OPNAME ## h264_chroma_mc2_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
+ const int A=(8-x)*(8-y);\
+ const int B=( x)*(8-y);\
+ const int C=(8-x)*( y);\
+ const int D=( x)*( y);\
+ \
+ assert(x<8 && y<8 && x>=0 && y>=0);\
+\
+ do {\
+ int t0,t1,t2,t3; \
+ uint8_t *s0 = src; \
+ uint8_t *s1 = src+stride; \
+ t0 = *s0++; t2 = *s1++; \
+ t1 = *s0++; t3 = *s1++; \
+ OP(dst[0], (A*t0 + B*t1 + C*t2 + D*t3));\
+ t0 = *s0++; t2 = *s1++; \
+ OP(dst[1], (A*t1 + B*t0 + C*t3 + D*t2));\
+ dst+= stride;\
+ src+= stride;\
+ }while(--h);\
+}\
+\
+static void OPNAME ## h264_chroma_mc4_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
+ const int A=(8-x)*(8-y);\
+ const int B=( x)*(8-y);\
+ const int C=(8-x)*( y);\
+ const int D=( x)*( y);\
+ \
+ assert(x<8 && y<8 && x>=0 && y>=0);\
+\
+ do {\
+ int t0,t1,t2,t3; \
+ uint8_t *s0 = src; \
+ uint8_t *s1 = src+stride; \
+ t0 = *s0++; t2 = *s1++; \
+ t1 = *s0++; t3 = *s1++; \
+ OP(dst[0], (A*t0 + B*t1 + C*t2 + D*t3));\
+ t0 = *s0++; t2 = *s1++; \
+ OP(dst[1], (A*t1 + B*t0 + C*t3 + D*t2));\
+ t1 = *s0++; t3 = *s1++; \
+ OP(dst[2], (A*t0 + B*t1 + C*t2 + D*t3));\
+ t0 = *s0++; t2 = *s1++; \
+ OP(dst[3], (A*t1 + B*t0 + C*t3 + D*t2));\
+ dst+= stride;\
+ src+= stride;\
+ }while(--h);\
+}\
+\
+static void OPNAME ## h264_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
+ const int A=(8-x)*(8-y);\
+ const int B=( x)*(8-y);\
+ const int C=(8-x)*( y);\
+ const int D=( x)*( y);\
+ \
+ assert(x<8 && y<8 && x>=0 && y>=0);\
+\
+ do {\
+ int t0,t1,t2,t3; \
+ uint8_t *s0 = src; \
+ uint8_t *s1 = src+stride; \
+ t0 = *s0++; t2 = *s1++; \
+ t1 = *s0++; t3 = *s1++; \
+ OP(dst[0], (A*t0 + B*t1 + C*t2 + D*t3));\
+ t0 = *s0++; t2 = *s1++; \
+ OP(dst[1], (A*t1 + B*t0 + C*t3 + D*t2));\
+ t1 = *s0++; t3 = *s1++; \
+ OP(dst[2], (A*t0 + B*t1 + C*t2 + D*t3));\
+ t0 = *s0++; t2 = *s1++; \
+ OP(dst[3], (A*t1 + B*t0 + C*t3 + D*t2));\
+ t1 = *s0++; t3 = *s1++; \
+ OP(dst[4], (A*t0 + B*t1 + C*t2 + D*t3));\
+ t0 = *s0++; t2 = *s1++; \
+ OP(dst[5], (A*t1 + B*t0 + C*t3 + D*t2));\
+ t1 = *s0++; t3 = *s1++; \
+ OP(dst[6], (A*t0 + B*t1 + C*t2 + D*t3));\
+ t0 = *s0++; t2 = *s1++; \
+ OP(dst[7], (A*t1 + B*t0 + C*t3 + D*t2));\
+ dst+= stride;\
+ src+= stride;\
+ }while(--h);\
+}
+
+#define op_avg(a, b) a = (((a)+(((b) + 32)>>6)+1)>>1)
+#define op_put(a, b) a = (((b) + 32)>>6)
+
+H264_CHROMA_MC(put_ , op_put)
+H264_CHROMA_MC(avg_ , op_avg)
+#undef op_avg
+#undef op_put
+
+#define QPEL_MC(r, OPNAME, RND, OP) \
+static void OPNAME ## mpeg4_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
+ do {\
+ uint8_t *s = src; \
+ int src0,src1,src2,src3,src4,src5,src6,src7,src8;\
+ src0= *s++;\
+ src1= *s++;\
+ src2= *s++;\
+ src3= *s++;\
+ src4= *s++;\
+ OP(dst[0], (src0+src1)*20 - (src0+src2)*6 + (src1+src3)*3 - (src2+src4));\
+ src5= *s++;\
+ OP(dst[1], (src1+src2)*20 - (src0+src3)*6 + (src0+src4)*3 - (src1+src5));\
+ src6= *s++;\
+ OP(dst[2], (src2+src3)*20 - (src1+src4)*6 + (src0+src5)*3 - (src0+src6));\
+ src7= *s++;\
+ OP(dst[3], (src3+src4)*20 - (src2+src5)*6 + (src1+src6)*3 - (src0+src7));\
+ src8= *s++;\
+ OP(dst[4], (src4+src5)*20 - (src3+src6)*6 + (src2+src7)*3 - (src1+src8));\
+ OP(dst[5], (src5+src6)*20 - (src4+src7)*6 + (src3+src8)*3 - (src2+src8));\
+ OP(dst[6], (src6+src7)*20 - (src5+src8)*6 + (src4+src8)*3 - (src3+src7));\
+ OP(dst[7], (src7+src8)*20 - (src6+src8)*6 + (src5+src7)*3 - (src4+src6));\
+ dst+=dstStride;\
+ src+=srcStride;\
+ }while(--h);\
+}\
+\
+static void OPNAME ## mpeg4_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
+ int w=8;\
+ do{\
+ uint8_t *s = src, *d=dst;\
+ int src0,src1,src2,src3,src4,src5,src6,src7,src8;\
+ src0 = *s; s+=srcStride; \
+ src1 = *s; s+=srcStride; \
+ src2 = *s; s+=srcStride; \
+ src3 = *s; s+=srcStride; \
+ src4 = *s; s+=srcStride; \
+ OP(*d, (src0+src1)*20 - (src0+src2)*6 + (src1+src3)*3 - (src2+src4));d+=dstStride;\
+ src5 = *s; s+=srcStride; \
+ OP(*d, (src1+src2)*20 - (src0+src3)*6 + (src0+src4)*3 - (src1+src5));d+=dstStride;\
+ src6 = *s; s+=srcStride; \
+ OP(*d, (src2+src3)*20 - (src1+src4)*6 + (src0+src5)*3 - (src0+src6));d+=dstStride;\
+ src7 = *s; s+=srcStride; \
+ OP(*d, (src3+src4)*20 - (src2+src5)*6 + (src1+src6)*3 - (src0+src7));d+=dstStride;\
+ src8 = *s; \
+ OP(*d, (src4+src5)*20 - (src3+src6)*6 + (src2+src7)*3 - (src1+src8));d+=dstStride;\
+ OP(*d, (src5+src6)*20 - (src4+src7)*6 + (src3+src8)*3 - (src2+src8));d+=dstStride;\
+ OP(*d, (src6+src7)*20 - (src5+src8)*6 + (src4+src8)*3 - (src3+src7));d+=dstStride;\
+ OP(*d, (src7+src8)*20 - (src6+src8)*6 + (src5+src7)*3 - (src4+src6));\
+ dst++;\
+ src++;\
+ }while(--w);\
+}\
+\
+static void OPNAME ## mpeg4_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
+ do {\
+ uint8_t *s = src;\
+ int src0,src1,src2,src3,src4,src5,src6,src7,src8;\
+ int src9,src10,src11,src12,src13,src14,src15,src16;\
+ src0= *s++;\
+ src1= *s++;\
+ src2= *s++;\
+ src3= *s++;\
+ src4= *s++;\
+ OP(dst[ 0], (src0 +src1 )*20 - (src0 +src2 )*6 + (src1 +src3 )*3 - (src2 +src4 ));\
+ src5= *s++;\
+ OP(dst[ 1], (src1 +src2 )*20 - (src0 +src3 )*6 + (src0 +src4 )*3 - (src1 +src5 ));\
+ src6= *s++;\
+ OP(dst[ 2], (src2 +src3 )*20 - (src1 +src4 )*6 + (src0 +src5 )*3 - (src0 +src6 ));\
+ src7= *s++;\
+ OP(dst[ 3], (src3 +src4 )*20 - (src2 +src5 )*6 + (src1 +src6 )*3 - (src0 +src7 ));\
+ src8= *s++;\
+ OP(dst[ 4], (src4 +src5 )*20 - (src3 +src6 )*6 + (src2 +src7 )*3 - (src1 +src8 ));\
+ src9= *s++;\
+ OP(dst[ 5], (src5 +src6 )*20 - (src4 +src7 )*6 + (src3 +src8 )*3 - (src2 +src9 ));\
+ src10= *s++;\
+ OP(dst[ 6], (src6 +src7 )*20 - (src5 +src8 )*6 + (src4 +src9 )*3 - (src3 +src10));\
+ src11= *s++;\
+ OP(dst[ 7], (src7 +src8 )*20 - (src6 +src9 )*6 + (src5 +src10)*3 - (src4 +src11));\
+ src12= *s++;\
+ OP(dst[ 8], (src8 +src9 )*20 - (src7 +src10)*6 + (src6 +src11)*3 - (src5 +src12));\
+ src13= *s++;\
+ OP(dst[ 9], (src9 +src10)*20 - (src8 +src11)*6 + (src7 +src12)*3 - (src6 +src13));\
+ src14= *s++;\
+ OP(dst[10], (src10+src11)*20 - (src9 +src12)*6 + (src8 +src13)*3 - (src7 +src14));\
+ src15= *s++;\
+ OP(dst[11], (src11+src12)*20 - (src10+src13)*6 + (src9 +src14)*3 - (src8 +src15));\
+ src16= *s++;\
+ OP(dst[12], (src12+src13)*20 - (src11+src14)*6 + (src10+src15)*3 - (src9 +src16));\
+ OP(dst[13], (src13+src14)*20 - (src12+src15)*6 + (src11+src16)*3 - (src10+src16));\
+ OP(dst[14], (src14+src15)*20 - (src13+src16)*6 + (src12+src16)*3 - (src11+src15));\
+ OP(dst[15], (src15+src16)*20 - (src14+src16)*6 + (src13+src15)*3 - (src12+src14));\
+ dst+=dstStride;\
+ src+=srcStride;\
+ }while(--h);\
+}\
+\
+static void OPNAME ## mpeg4_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
+ int w=16;\
+ do {\
+ uint8_t *s = src, *d=dst;\
+ int src0,src1,src2,src3,src4,src5,src6,src7,src8;\
+ int src9,src10,src11,src12,src13,src14,src15,src16;\
+ src0 = *s; s+=srcStride; \
+ src1 = *s; s+=srcStride; \
+ src2 = *s; s+=srcStride; \
+ src3 = *s; s+=srcStride; \
+ src4 = *s; s+=srcStride; \
+ OP(*d, (src0 +src1 )*20 - (src0 +src2 )*6 + (src1 +src3 )*3 - (src2 +src4 ));d+=dstStride;\
+ src5 = *s; s+=srcStride; \
+ OP(*d, (src1 +src2 )*20 - (src0 +src3 )*6 + (src0 +src4 )*3 - (src1 +src5 ));d+=dstStride;\
+ src6 = *s; s+=srcStride; \
+ OP(*d, (src2 +src3 )*20 - (src1 +src4 )*6 + (src0 +src5 )*3 - (src0 +src6 ));d+=dstStride;\
+ src7 = *s; s+=srcStride; \
+ OP(*d, (src3 +src4 )*20 - (src2 +src5 )*6 + (src1 +src6 )*3 - (src0 +src7 ));d+=dstStride;\
+ src8 = *s; s+=srcStride; \
+ OP(*d, (src4 +src5 )*20 - (src3 +src6 )*6 + (src2 +src7 )*3 - (src1 +src8 ));d+=dstStride;\
+ src9 = *s; s+=srcStride; \
+ OP(*d, (src5 +src6 )*20 - (src4 +src7 )*6 + (src3 +src8 )*3 - (src2 +src9 ));d+=dstStride;\
+ src10 = *s; s+=srcStride; \
+ OP(*d, (src6 +src7 )*20 - (src5 +src8 )*6 + (src4 +src9 )*3 - (src3 +src10));d+=dstStride;\
+ src11 = *s; s+=srcStride; \
+ OP(*d, (src7 +src8 )*20 - (src6 +src9 )*6 + (src5 +src10)*3 - (src4 +src11));d+=dstStride;\
+ src12 = *s; s+=srcStride; \
+ OP(*d, (src8 +src9 )*20 - (src7 +src10)*6 + (src6 +src11)*3 - (src5 +src12));d+=dstStride;\
+ src13 = *s; s+=srcStride; \
+ OP(*d, (src9 +src10)*20 - (src8 +src11)*6 + (src7 +src12)*3 - (src6 +src13));d+=dstStride;\
+ src14 = *s; s+=srcStride; \
+ OP(*d, (src10+src11)*20 - (src9 +src12)*6 + (src8 +src13)*3 - (src7 +src14));d+=dstStride;\
+ src15 = *s; s+=srcStride; \
+ OP(*d, (src11+src12)*20 - (src10+src13)*6 + (src9 +src14)*3 - (src8 +src15));d+=dstStride;\
+ src16 = *s; \
+ OP(*d, (src12+src13)*20 - (src11+src14)*6 + (src10+src15)*3 - (src9 +src16));d+=dstStride;\
+ OP(*d, (src13+src14)*20 - (src12+src15)*6 + (src11+src16)*3 - (src10+src16));d+=dstStride;\
+ OP(*d, (src14+src15)*20 - (src13+src16)*6 + (src12+src16)*3 - (src11+src15));d+=dstStride;\
+ OP(*d, (src15+src16)*20 - (src14+src16)*6 + (src13+src15)*3 - (src12+src14));\
+ dst++;\
+ src++;\
+ }while(--w);\
+}\
+\
+static void OPNAME ## qpel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## pixels8_c(dst, src, stride, 8);\
+}\
+\
+static void OPNAME ## qpel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t half[64];\
+ put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
+ OPNAME ## pixels8_l2_aligned2(dst, src, half, stride, stride, 8, 8);\
+}\
+\
+static void OPNAME ## qpel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## mpeg4_qpel8_h_lowpass(dst, src, stride, stride, 8);\
+}\
+\
+static void OPNAME ## qpel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t half[64];\
+ put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
+ OPNAME ## pixels8_l2_aligned2(dst, src+1, half, stride, stride, 8, 8);\
+}\
+\
+static void OPNAME ## qpel8_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[16*9];\
+ uint8_t half[64];\
+ copy_block9(full, src, 16, stride, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
+ OPNAME ## pixels8_l2_aligned(dst, full, half, stride, 16, 8, 8);\
+}\
+\
+static void OPNAME ## qpel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[16*9];\
+ copy_block9(full, src, 16, stride, 9);\
+ OPNAME ## mpeg4_qpel8_v_lowpass(dst, full, stride, 16);\
+}\
+\
+static void OPNAME ## qpel8_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[16*9];\
+ uint8_t half[64];\
+ copy_block9(full, src, 16, stride, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
+ OPNAME ## pixels8_l2_aligned(dst, full+16, half, stride, 16, 8, 8);\
+}\
+static void ff_ ## OPNAME ## qpel8_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[16*9];\
+ uint8_t halfH[72];\
+ uint8_t halfV[64];\
+ uint8_t halfHV[64];\
+ copy_block9(full, src, 16, stride, 9);\
+ put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+ OPNAME ## pixels8_l4_aligned(dst, full, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
+}\
+static void OPNAME ## qpel8_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[16*9];\
+ uint8_t halfH[72];\
+ uint8_t halfHV[64];\
+ copy_block9(full, src, 16, stride, 9);\
+ put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+ put ## RND ## pixels8_l2_aligned(halfH, halfH, full, 8, 8, 16, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+ OPNAME ## pixels8_l2_aligned(dst, halfH, halfHV, stride, 8, 8, 8);\
+}\
+static void ff_ ## OPNAME ## qpel8_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[16*9];\
+ uint8_t halfH[72];\
+ uint8_t halfV[64];\
+ uint8_t halfHV[64];\
+ copy_block9(full, src, 16, stride, 9);\
+ put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+ OPNAME ## pixels8_l4_aligned0(dst, full+1, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
+}\
+static void OPNAME ## qpel8_mc31_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[16*9];\
+ uint8_t halfH[72];\
+ uint8_t halfHV[64];\
+ copy_block9(full, src, 16, stride, 9);\
+ put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+ put ## RND ## pixels8_l2_aligned1(halfH, halfH, full+1, 8, 8, 16, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+ OPNAME ## pixels8_l2_aligned(dst, halfH, halfHV, stride, 8, 8, 8);\
+}\
+static void ff_ ## OPNAME ## qpel8_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[16*9];\
+ uint8_t halfH[72];\
+ uint8_t halfV[64];\
+ uint8_t halfHV[64];\
+ copy_block9(full, src, 16, stride, 9);\
+ put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+ OPNAME ## pixels8_l4_aligned(dst, full+16, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
+}\
+static void OPNAME ## qpel8_mc13_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[16*9];\
+ uint8_t halfH[72];\
+ uint8_t halfHV[64];\
+ copy_block9(full, src, 16, stride, 9);\
+ put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+ put ## RND ## pixels8_l2_aligned(halfH, halfH, full, 8, 8, 16, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+ OPNAME ## pixels8_l2_aligned(dst, halfH+8, halfHV, stride, 8, 8, 8);\
+}\
+static void ff_ ## OPNAME ## qpel8_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[16*9];\
+ uint8_t halfH[72];\
+ uint8_t halfV[64];\
+ uint8_t halfHV[64];\
+ copy_block9(full, src, 16, stride, 9);\
+ put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full , 8, 16, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+ OPNAME ## pixels8_l4_aligned0(dst, full+17, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
+}\
+static void OPNAME ## qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[16*9];\
+ uint8_t halfH[72];\
+ uint8_t halfHV[64];\
+ copy_block9(full, src, 16, stride, 9);\
+ put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+ put ## RND ## pixels8_l2_aligned1(halfH, halfH, full+1, 8, 8, 16, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+ OPNAME ## pixels8_l2_aligned(dst, halfH+8, halfHV, stride, 8, 8, 8);\
+}\
+static void OPNAME ## qpel8_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t halfH[72];\
+ uint8_t halfHV[64];\
+ put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+ OPNAME ## pixels8_l2_aligned(dst, halfH, halfHV, stride, 8, 8, 8);\
+}\
+static void OPNAME ## qpel8_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t halfH[72];\
+ uint8_t halfHV[64];\
+ put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+ OPNAME ## pixels8_l2_aligned(dst, halfH+8, halfHV, stride, 8, 8, 8);\
+}\
+static void ff_ ## OPNAME ## qpel8_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[16*9];\
+ uint8_t halfH[72];\
+ uint8_t halfV[64];\
+ uint8_t halfHV[64];\
+ copy_block9(full, src, 16, stride, 9);\
+ put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+ OPNAME ## pixels8_l2_aligned(dst, halfV, halfHV, stride, 8, 8, 8);\
+}\
+static void OPNAME ## qpel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[16*9];\
+ uint8_t halfH[72];\
+ copy_block9(full, src, 16, stride, 9);\
+ put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+ put ## RND ## pixels8_l2_aligned(halfH, halfH, full, 8, 8, 16, 9);\
+ OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
+}\
+static void ff_ ## OPNAME ## qpel8_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[16*9];\
+ uint8_t halfH[72];\
+ uint8_t halfV[64];\
+ uint8_t halfHV[64];\
+ copy_block9(full, src, 16, stride, 9);\
+ put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
+ put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
+ OPNAME ## pixels8_l2_aligned(dst, halfV, halfHV, stride, 8, 8, 8);\
+}\
+static void OPNAME ## qpel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[16*9];\
+ uint8_t halfH[72];\
+ copy_block9(full, src, 16, stride, 9);\
+ put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
+ put ## RND ## pixels8_l2_aligned1(halfH, halfH, full+1, 8, 8, 16, 9);\
+ OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
+}\
+static void OPNAME ## qpel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t halfH[72];\
+ put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
+ OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
+}\
+static void OPNAME ## qpel16_mc00_c (uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## pixels16_c(dst, src, stride, 16);\
+}\
+\
+static void OPNAME ## qpel16_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t half[256];\
+ put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
+ OPNAME ## pixels16_l2_aligned2(dst, src, half, stride, stride, 16, 16);\
+}\
+\
+static void OPNAME ## qpel16_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## mpeg4_qpel16_h_lowpass(dst, src, stride, stride, 16);\
+}\
+\
+static void OPNAME ## qpel16_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t half[256];\
+ put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
+ OPNAME ## pixels16_l2_aligned2(dst, src+1, half, stride, stride, 16, 16);\
+}\
+\
+static void OPNAME ## qpel16_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[24*17];\
+ uint8_t half[256];\
+ copy_block17(full, src, 24, stride, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
+ OPNAME ## pixels16_l2_aligned(dst, full, half, stride, 24, 16, 16);\
+}\
+\
+static void OPNAME ## qpel16_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[24*17];\
+ copy_block17(full, src, 24, stride, 17);\
+ OPNAME ## mpeg4_qpel16_v_lowpass(dst, full, stride, 24);\
+}\
+\
+static void OPNAME ## qpel16_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[24*17];\
+ uint8_t half[256];\
+ copy_block17(full, src, 24, stride, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
+ OPNAME ## pixels16_l2_aligned(dst, full+24, half, stride, 24, 16, 16);\
+}\
+static void ff_ ## OPNAME ## qpel16_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[24*17];\
+ uint8_t halfH[272];\
+ uint8_t halfV[256];\
+ uint8_t halfHV[256];\
+ copy_block17(full, src, 24, stride, 17);\
+ put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+ OPNAME ## pixels16_l4_aligned(dst, full, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
+}\
+static void OPNAME ## qpel16_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[24*17];\
+ uint8_t halfH[272];\
+ uint8_t halfHV[256];\
+ copy_block17(full, src, 24, stride, 17);\
+ put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+ put ## RND ## pixels16_l2_aligned(halfH, halfH, full, 16, 16, 24, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+ OPNAME ## pixels16_l2_aligned(dst, halfH, halfHV, stride, 16, 16, 16);\
+}\
+static void ff_ ## OPNAME ## qpel16_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[24*17];\
+ uint8_t halfH[272];\
+ uint8_t halfV[256];\
+ uint8_t halfHV[256];\
+ copy_block17(full, src, 24, stride, 17);\
+ put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+ OPNAME ## pixels16_l4_aligned0(dst, full+1, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
+}\
+static void OPNAME ## qpel16_mc31_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[24*17];\
+ uint8_t halfH[272];\
+ uint8_t halfHV[256];\
+ copy_block17(full, src, 24, stride, 17);\
+ put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+ put ## RND ## pixels16_l2_aligned1(halfH, halfH, full+1, 16, 16, 24, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+ OPNAME ## pixels16_l2_aligned(dst, halfH, halfHV, stride, 16, 16, 16);\
+}\
+static void ff_ ## OPNAME ## qpel16_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[24*17];\
+ uint8_t halfH[272];\
+ uint8_t halfV[256];\
+ uint8_t halfHV[256];\
+ copy_block17(full, src, 24, stride, 17);\
+ put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+ OPNAME ## pixels16_l4_aligned(dst, full+24, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
+}\
+static void OPNAME ## qpel16_mc13_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[24*17];\
+ uint8_t halfH[272];\
+ uint8_t halfHV[256];\
+ copy_block17(full, src, 24, stride, 17);\
+ put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+ put ## RND ## pixels16_l2_aligned(halfH, halfH, full, 16, 16, 24, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+ OPNAME ## pixels16_l2_aligned(dst, halfH+16, halfHV, stride, 16, 16, 16);\
+}\
+static void ff_ ## OPNAME ## qpel16_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[24*17];\
+ uint8_t halfH[272];\
+ uint8_t halfV[256];\
+ uint8_t halfHV[256];\
+ copy_block17(full, src, 24, stride, 17);\
+ put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full , 16, 24, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+ OPNAME ## pixels16_l4_aligned0(dst, full+25, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
+}\
+static void OPNAME ## qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[24*17];\
+ uint8_t halfH[272];\
+ uint8_t halfHV[256];\
+ copy_block17(full, src, 24, stride, 17);\
+ put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+ put ## RND ## pixels16_l2_aligned1(halfH, halfH, full+1, 16, 16, 24, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+ OPNAME ## pixels16_l2_aligned(dst, halfH+16, halfHV, stride, 16, 16, 16);\
+}\
+static void OPNAME ## qpel16_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t halfH[272];\
+ uint8_t halfHV[256];\
+ put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+ OPNAME ## pixels16_l2_aligned(dst, halfH, halfHV, stride, 16, 16, 16);\
+}\
+static void OPNAME ## qpel16_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t halfH[272];\
+ uint8_t halfHV[256];\
+ put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+ OPNAME ## pixels16_l2_aligned(dst, halfH+16, halfHV, stride, 16, 16, 16);\
+}\
+static void ff_ ## OPNAME ## qpel16_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[24*17];\
+ uint8_t halfH[272];\
+ uint8_t halfV[256];\
+ uint8_t halfHV[256];\
+ copy_block17(full, src, 24, stride, 17);\
+ put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+ OPNAME ## pixels16_l2_aligned(dst, halfV, halfHV, stride, 16, 16, 16);\
+}\
+static void OPNAME ## qpel16_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[24*17];\
+ uint8_t halfH[272];\
+ copy_block17(full, src, 24, stride, 17);\
+ put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+ put ## RND ## pixels16_l2_aligned(halfH, halfH, full, 16, 16, 24, 17);\
+ OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
+}\
+static void ff_ ## OPNAME ## qpel16_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[24*17];\
+ uint8_t halfH[272];\
+ uint8_t halfV[256];\
+ uint8_t halfHV[256];\
+ copy_block17(full, src, 24, stride, 17);\
+ put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
+ put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
+ OPNAME ## pixels16_l2_aligned(dst, halfV, halfHV, stride, 16, 16, 16);\
+}\
+static void OPNAME ## qpel16_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[24*17];\
+ uint8_t halfH[272];\
+ copy_block17(full, src, 24, stride, 17);\
+ put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
+ put ## RND ## pixels16_l2_aligned1(halfH, halfH, full+1, 16, 16, 24, 17);\
+ OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
+}\
+static void OPNAME ## qpel16_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t halfH[272];\
+ put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
+ OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
+}
+
+#define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
+#define op_avg_no_rnd(a, b) a = (((a)+cm[((b) + 15)>>5])>>1)
+#define op_put(a, b) a = cm[((b) + 16)>>5]
+#define op_put_no_rnd(a, b) a = cm[((b) + 15)>>5]
+
+QPEL_MC(0, put_ , _ , op_put)
+QPEL_MC(1, put_no_rnd_, _no_rnd_, op_put_no_rnd)
+QPEL_MC(0, avg_ , _ , op_avg)
+//QPEL_MC(1, avg_no_rnd , _ , op_avg)
+#undef op_avg
+#undef op_avg_no_rnd
+#undef op_put
+#undef op_put_no_rnd
+
+#if 1
+#define H264_LOWPASS(OPNAME, OP, OP2) \
+static inline void OPNAME ## h264_qpel_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride,int w,int h){\
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
+ do {\
+ int srcB,srcA,src0,src1,src2,src3,src4,src5,src6;\
+ uint8_t *s = src-2;\
+ srcB = *s++;\
+ srcA = *s++;\
+ src0 = *s++;\
+ src1 = *s++;\
+ src2 = *s++;\
+ src3 = *s++;\
+ OP(dst[0], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
+ src4 = *s++;\
+ OP(dst[1], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
+ src5 = *s++;\
+ OP(dst[2], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
+ src6 = *s++;\
+ OP(dst[3], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
+ if (w>4) { /* it optimized */ \
+ int src7,src8,src9,src10; \
+ src7 = *s++;\
+ OP(dst[4], (src4+src5)*20 - (src3+src6)*5 + (src2+src7));\
+ src8 = *s++;\
+ OP(dst[5], (src5+src6)*20 - (src4+src7)*5 + (src3+src8));\
+ src9 = *s++;\
+ OP(dst[6], (src6+src7)*20 - (src5+src8)*5 + (src4+src9));\
+ src10 = *s++;\
+ OP(dst[7], (src7+src8)*20 - (src6+src9)*5 + (src5+src10));\
+ if (w>8) { \
+ int src11,src12,src13,src14,src15,src16,src17,src18; \
+ src11 = *s++;\
+ OP(dst[8] , (src8 +src9 )*20 - (src7 +src10)*5 + (src6 +src11));\
+ src12 = *s++;\
+ OP(dst[9] , (src9 +src10)*20 - (src8 +src11)*5 + (src7 +src12));\
+ src13 = *s++;\
+ OP(dst[10], (src10+src11)*20 - (src9 +src12)*5 + (src8 +src13));\
+ src14 = *s++;\
+ OP(dst[11], (src11+src12)*20 - (src10+src13)*5 + (src9 +src14));\
+ src15 = *s++;\
+ OP(dst[12], (src12+src13)*20 - (src11+src14)*5 + (src10+src15));\
+ src16 = *s++;\
+ OP(dst[13], (src13+src14)*20 - (src12+src15)*5 + (src11+src16));\
+ src17 = *s++;\
+ OP(dst[14], (src14+src15)*20 - (src13+src16)*5 + (src12+src17));\
+ src18 = *s++;\
+ OP(dst[15], (src15+src16)*20 - (src14+src17)*5 + (src13+src18));\
+ } \
+ } \
+ dst+=dstStride;\
+ src+=srcStride;\
+ }while(--h);\
+}\
+\
+static inline void OPNAME ## h264_qpel_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride,int w,int h){\
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
+ do{\
+ int srcB,srcA,src0,src1,src2,src3,src4,src5,src6;\
+ uint8_t *s = src-2*srcStride,*d=dst;\
+ srcB = *s; s+=srcStride;\
+ srcA = *s; s+=srcStride;\
+ src0 = *s; s+=srcStride;\
+ src1 = *s; s+=srcStride;\
+ src2 = *s; s+=srcStride;\
+ src3 = *s; s+=srcStride;\
+ OP(*d, (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));d+=dstStride;\
+ src4 = *s; s+=srcStride;\
+ OP(*d, (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));d+=dstStride;\
+ src5 = *s; s+=srcStride;\
+ OP(*d, (src2+src3)*20 - (src1+src4)*5 + (src0+src5));d+=dstStride;\
+ src6 = *s; s+=srcStride;\
+ OP(*d, (src3+src4)*20 - (src2+src5)*5 + (src1+src6));d+=dstStride;\
+ if (h>4) { \
+ int src7,src8,src9,src10; \
+ src7 = *s; s+=srcStride;\
+ OP(*d, (src4+src5)*20 - (src3+src6)*5 + (src2+src7));d+=dstStride;\
+ src8 = *s; s+=srcStride;\
+ OP(*d, (src5+src6)*20 - (src4+src7)*5 + (src3+src8));d+=dstStride;\
+ src9 = *s; s+=srcStride;\
+ OP(*d, (src6+src7)*20 - (src5+src8)*5 + (src4+src9));d+=dstStride;\
+ src10 = *s; s+=srcStride;\
+ OP(*d, (src7+src8)*20 - (src6+src9)*5 + (src5+src10));d+=dstStride;\
+ if (h>8) { \
+ int src11,src12,src13,src14,src15,src16,src17,src18; \
+ src11 = *s; s+=srcStride;\
+ OP(*d , (src8 +src9 )*20 - (src7 +src10)*5 + (src6 +src11));d+=dstStride;\
+ src12 = *s; s+=srcStride;\
+ OP(*d , (src9 +src10)*20 - (src8 +src11)*5 + (src7 +src12));d+=dstStride;\
+ src13 = *s; s+=srcStride;\
+ OP(*d, (src10+src11)*20 - (src9 +src12)*5 + (src8 +src13));d+=dstStride;\
+ src14 = *s; s+=srcStride;\
+ OP(*d, (src11+src12)*20 - (src10+src13)*5 + (src9 +src14));d+=dstStride;\
+ src15 = *s; s+=srcStride;\
+ OP(*d, (src12+src13)*20 - (src11+src14)*5 + (src10+src15));d+=dstStride;\
+ src16 = *s; s+=srcStride;\
+ OP(*d, (src13+src14)*20 - (src12+src15)*5 + (src11+src16));d+=dstStride;\
+ src17 = *s; s+=srcStride;\
+ OP(*d, (src14+src15)*20 - (src13+src16)*5 + (src12+src17));d+=dstStride;\
+ src18 = *s; s+=srcStride;\
+ OP(*d, (src15+src16)*20 - (src14+src17)*5 + (src13+src18));d+=dstStride;\
+ } \
+ } \
+ dst++;\
+ src++;\
+ }while(--w);\
+}\
+\
+static inline void OPNAME ## h264_qpel_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride,int w,int h){\
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
+ int i;\
+ src -= 2*srcStride;\
+ i= h+5; \
+ do {\
+ int srcB,srcA,src0,src1,src2,src3,src4,src5,src6;\
+ uint8_t *s = src-2;\
+ srcB = *s++;\
+ srcA = *s++;\
+ src0 = *s++;\
+ src1 = *s++;\
+ src2 = *s++;\
+ src3 = *s++;\
+ tmp[0] = ((src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
+ src4 = *s++;\
+ tmp[1] = ((src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
+ src5 = *s++;\
+ tmp[2] = ((src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
+ src6 = *s++;\
+ tmp[3] = ((src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
+ if (w>4) { /* it optimized */ \
+ int src7,src8,src9,src10; \
+ src7 = *s++;\
+ tmp[4] = ((src4+src5)*20 - (src3+src6)*5 + (src2+src7));\
+ src8 = *s++;\
+ tmp[5] = ((src5+src6)*20 - (src4+src7)*5 + (src3+src8));\
+ src9 = *s++;\
+ tmp[6] = ((src6+src7)*20 - (src5+src8)*5 + (src4+src9));\
+ src10 = *s++;\
+ tmp[7] = ((src7+src8)*20 - (src6+src9)*5 + (src5+src10));\
+ if (w>8) { \
+ int src11,src12,src13,src14,src15,src16,src17,src18; \
+ src11 = *s++;\
+ tmp[8] = ((src8 +src9 )*20 - (src7 +src10)*5 + (src6 +src11));\
+ src12 = *s++;\
+ tmp[9] = ((src9 +src10)*20 - (src8 +src11)*5 + (src7 +src12));\
+ src13 = *s++;\
+ tmp[10] = ((src10+src11)*20 - (src9 +src12)*5 + (src8 +src13));\
+ src14 = *s++;\
+ tmp[11] = ((src11+src12)*20 - (src10+src13)*5 + (src9 +src14));\
+ src15 = *s++;\
+ tmp[12] = ((src12+src13)*20 - (src11+src14)*5 + (src10+src15));\
+ src16 = *s++;\
+ tmp[13] = ((src13+src14)*20 - (src12+src15)*5 + (src11+src16));\
+ src17 = *s++;\
+ tmp[14] = ((src14+src15)*20 - (src13+src16)*5 + (src12+src17));\
+ src18 = *s++;\
+ tmp[15] = ((src15+src16)*20 - (src14+src17)*5 + (src13+src18));\
+ } \
+ } \
+ tmp+=tmpStride;\
+ src+=srcStride;\
+ }while(--i);\
+ tmp -= tmpStride*(h+5-2);\
+ i = w; \
+ do {\
+ int tmpB,tmpA,tmp0,tmp1,tmp2,tmp3,tmp4,tmp5,tmp6;\
+ int16_t *s = tmp-2*tmpStride; \
+ uint8_t *d=dst;\
+ tmpB = *s; s+=tmpStride;\
+ tmpA = *s; s+=tmpStride;\
+ tmp0 = *s; s+=tmpStride;\
+ tmp1 = *s; s+=tmpStride;\
+ tmp2 = *s; s+=tmpStride;\
+ tmp3 = *s; s+=tmpStride;\
+ OP2(*d, (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));d+=dstStride;\
+ tmp4 = *s; s+=tmpStride;\
+ OP2(*d, (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));d+=dstStride;\
+ tmp5 = *s; s+=tmpStride;\
+ OP2(*d, (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));d+=dstStride;\
+ tmp6 = *s; s+=tmpStride;\
+ OP2(*d, (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));d+=dstStride;\
+ if (h>4) { \
+ int tmp7,tmp8,tmp9,tmp10; \
+ tmp7 = *s; s+=tmpStride;\
+ OP2(*d, (tmp4+tmp5)*20 - (tmp3+tmp6)*5 + (tmp2+tmp7));d+=dstStride;\
+ tmp8 = *s; s+=tmpStride;\
+ OP2(*d, (tmp5+tmp6)*20 - (tmp4+tmp7)*5 + (tmp3+tmp8));d+=dstStride;\
+ tmp9 = *s; s+=tmpStride;\
+ OP2(*d, (tmp6+tmp7)*20 - (tmp5+tmp8)*5 + (tmp4+tmp9));d+=dstStride;\
+ tmp10 = *s; s+=tmpStride;\
+ OP2(*d, (tmp7+tmp8)*20 - (tmp6+tmp9)*5 + (tmp5+tmp10));d+=dstStride;\
+ if (h>8) { \
+ int tmp11,tmp12,tmp13,tmp14,tmp15,tmp16,tmp17,tmp18; \
+ tmp11 = *s; s+=tmpStride;\
+ OP2(*d , (tmp8 +tmp9 )*20 - (tmp7 +tmp10)*5 + (tmp6 +tmp11));d+=dstStride;\
+ tmp12 = *s; s+=tmpStride;\
+ OP2(*d , (tmp9 +tmp10)*20 - (tmp8 +tmp11)*5 + (tmp7 +tmp12));d+=dstStride;\
+ tmp13 = *s; s+=tmpStride;\
+ OP2(*d, (tmp10+tmp11)*20 - (tmp9 +tmp12)*5 + (tmp8 +tmp13));d+=dstStride;\
+ tmp14 = *s; s+=tmpStride;\
+ OP2(*d, (tmp11+tmp12)*20 - (tmp10+tmp13)*5 + (tmp9 +tmp14));d+=dstStride;\
+ tmp15 = *s; s+=tmpStride;\
+ OP2(*d, (tmp12+tmp13)*20 - (tmp11+tmp14)*5 + (tmp10+tmp15));d+=dstStride;\
+ tmp16 = *s; s+=tmpStride;\
+ OP2(*d, (tmp13+tmp14)*20 - (tmp12+tmp15)*5 + (tmp11+tmp16));d+=dstStride;\
+ tmp17 = *s; s+=tmpStride;\
+ OP2(*d, (tmp14+tmp15)*20 - (tmp13+tmp16)*5 + (tmp12+tmp17));d+=dstStride;\
+ tmp18 = *s; s+=tmpStride;\
+ OP2(*d, (tmp15+tmp16)*20 - (tmp14+tmp17)*5 + (tmp13+tmp18));d+=dstStride;\
+ } \
+ } \
+ dst++;\
+ tmp++;\
+ }while(--i);\
+}\
+\
+static void OPNAME ## h264_qpel4_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ OPNAME ## h264_qpel_h_lowpass(dst,src,dstStride,srcStride,4,4); \
+}\
+static void OPNAME ## h264_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ OPNAME ## h264_qpel_h_lowpass(dst,src,dstStride,srcStride,8,8); \
+}\
+static void OPNAME ## h264_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ OPNAME ## h264_qpel_h_lowpass(dst,src,dstStride,srcStride,16,16); \
+}\
+\
+static void OPNAME ## h264_qpel4_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ OPNAME ## h264_qpel_v_lowpass(dst,src,dstStride,srcStride,4,4); \
+}\
+static void OPNAME ## h264_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ OPNAME ## h264_qpel_v_lowpass(dst,src,dstStride,srcStride,8,8); \
+}\
+static void OPNAME ## h264_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
+ OPNAME ## h264_qpel_v_lowpass(dst,src,dstStride,srcStride,16,16); \
+}\
+static void OPNAME ## h264_qpel4_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
+ OPNAME ## h264_qpel_hv_lowpass(dst,tmp,src,dstStride,tmpStride,srcStride,4,4); \
+}\
+static void OPNAME ## h264_qpel8_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
+ OPNAME ## h264_qpel_hv_lowpass(dst,tmp,src,dstStride,tmpStride,srcStride,8,8); \
+}\
+static void OPNAME ## h264_qpel16_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
+ OPNAME ## h264_qpel_hv_lowpass(dst,tmp,src,dstStride,tmpStride,srcStride,16,16); \
+}\
+
+#define H264_MC(OPNAME, SIZE) \
+static void OPNAME ## h264_qpel ## SIZE ## _mc00_c (uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## pixels ## SIZE ## _c(dst, src, stride, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc10_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t half[SIZE*SIZE];\
+ put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\
+ OPNAME ## pixels ## SIZE ## _l2_aligned2(dst, src, half, stride, stride, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc20_c(uint8_t *dst, uint8_t *src, int stride){\
+ OPNAME ## h264_qpel ## SIZE ## _h_lowpass(dst, src, stride, stride);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc30_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t half[SIZE*SIZE];\
+ put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\
+ OPNAME ## pixels ## SIZE ## _l2_aligned2(dst, src+1, half, stride, stride, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc01_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[SIZE*(SIZE+5)];\
+ uint8_t * const full_mid= full + SIZE*2;\
+ uint8_t half[SIZE*SIZE];\
+ copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
+ put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\
+ OPNAME ## pixels ## SIZE ## _l2_aligned(dst, full_mid, half, stride, SIZE, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc02_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[SIZE*(SIZE+5)];\
+ uint8_t * const full_mid= full + SIZE*2;\
+ copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
+ OPNAME ## h264_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc03_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[SIZE*(SIZE+5)];\
+ uint8_t * const full_mid= full + SIZE*2;\
+ uint8_t half[SIZE*SIZE];\
+ copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
+ put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\
+ OPNAME ## pixels ## SIZE ## _l2_aligned(dst, full_mid+SIZE, half, stride, SIZE, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc11_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[SIZE*(SIZE+5)];\
+ uint8_t * const full_mid= full + SIZE*2;\
+ uint8_t halfH[SIZE*SIZE];\
+ uint8_t halfV[SIZE*SIZE];\
+ put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
+ copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
+ put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
+ OPNAME ## pixels ## SIZE ## _l2_aligned(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc31_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[SIZE*(SIZE+5)];\
+ uint8_t * const full_mid= full + SIZE*2;\
+ uint8_t halfH[SIZE*SIZE];\
+ uint8_t halfV[SIZE*SIZE];\
+ put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
+ copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
+ put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
+ OPNAME ## pixels ## SIZE ## _l2_aligned(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc13_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[SIZE*(SIZE+5)];\
+ uint8_t * const full_mid= full + SIZE*2;\
+ uint8_t halfH[SIZE*SIZE];\
+ uint8_t halfV[SIZE*SIZE];\
+ put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
+ copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
+ put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
+ OPNAME ## pixels ## SIZE ## _l2_aligned(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc33_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[SIZE*(SIZE+5)];\
+ uint8_t * const full_mid= full + SIZE*2;\
+ uint8_t halfH[SIZE*SIZE];\
+ uint8_t halfV[SIZE*SIZE];\
+ put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
+ copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
+ put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
+ OPNAME ## pixels ## SIZE ## _l2_aligned(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc22_c(uint8_t *dst, uint8_t *src, int stride){\
+ int16_t tmp[SIZE*(SIZE+5)];\
+ OPNAME ## h264_qpel ## SIZE ## _hv_lowpass(dst, tmp, src, stride, SIZE, stride);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc21_c(uint8_t *dst, uint8_t *src, int stride){\
+ int16_t tmp[SIZE*(SIZE+5)];\
+ uint8_t halfH[SIZE*SIZE];\
+ uint8_t halfHV[SIZE*SIZE];\
+ put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
+ put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
+ OPNAME ## pixels ## SIZE ## _l2_aligned(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc23_c(uint8_t *dst, uint8_t *src, int stride){\
+ int16_t tmp[SIZE*(SIZE+5)];\
+ uint8_t halfH[SIZE*SIZE];\
+ uint8_t halfHV[SIZE*SIZE];\
+ put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
+ put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
+ OPNAME ## pixels ## SIZE ## _l2_aligned(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc12_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[SIZE*(SIZE+5)];\
+ uint8_t * const full_mid= full + SIZE*2;\
+ int16_t tmp[SIZE*(SIZE+5)];\
+ uint8_t halfV[SIZE*SIZE];\
+ uint8_t halfHV[SIZE*SIZE];\
+ copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
+ put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
+ put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
+ OPNAME ## pixels ## SIZE ## _l2_aligned(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\
+}\
+\
+static void OPNAME ## h264_qpel ## SIZE ## _mc32_c(uint8_t *dst, uint8_t *src, int stride){\
+ uint8_t full[SIZE*(SIZE+5)];\
+ uint8_t * const full_mid= full + SIZE*2;\
+ int16_t tmp[SIZE*(SIZE+5)];\
+ uint8_t halfV[SIZE*SIZE];\
+ uint8_t halfHV[SIZE*SIZE];\
+ copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
+ put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
+ put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
+ OPNAME ## pixels ## SIZE ## _l2_aligned(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\
+}\
+
+#define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
+//#define op_avg2(a, b) a = (((a)*w1+cm[((b) + 16)>>5]*w2 + o + 64)>>7)
+#define op_put(a, b) a = cm[((b) + 16)>>5]
+#define op2_avg(a, b) a = (((a)+cm[((b) + 512)>>10]+1)>>1)
+#define op2_put(a, b) a = cm[((b) + 512)>>10]
+
+H264_LOWPASS(put_ , op_put, op2_put)
+H264_LOWPASS(avg_ , op_avg, op2_avg)
+H264_MC(put_, 4)
+H264_MC(put_, 8)
+H264_MC(put_, 16)
+H264_MC(avg_, 4)
+H264_MC(avg_, 8)
+H264_MC(avg_, 16)
+
+#undef op_avg
+#undef op_put
+#undef op2_avg
+#undef op2_put
+#endif
+
+static void wmv2_mspel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+
+ do{
+ int src_1,src0,src1,src2,src3,src4,src5,src6,src7,src8,src9;
+ uint8_t *s = src;
+ src_1 = s[-1];
+ src0 = *s++;
+ src1 = *s++;
+ src2 = *s++;
+ dst[0]= cm[(9*(src0 + src1) - (src_1 + src2) + 8)>>4];
+ src3 = *s++;
+ dst[1]= cm[(9*(src1 + src2) - (src0 + src3) + 8)>>4];
+ src4 = *s++;
+ dst[2]= cm[(9*(src2 + src3) - (src1 + src4) + 8)>>4];
+ src5 = *s++;
+ dst[3]= cm[(9*(src3 + src4) - (src2 + src5) + 8)>>4];
+ src6 = *s++;
+ dst[4]= cm[(9*(src4 + src5) - (src3 + src6) + 8)>>4];
+ src7 = *s++;
+ dst[5]= cm[(9*(src5 + src6) - (src4 + src7) + 8)>>4];
+ src8 = *s++;
+ dst[6]= cm[(9*(src6 + src7) - (src5 + src8) + 8)>>4];
+ src9 = *s++;
+ dst[7]= cm[(9*(src7 + src8) - (src6 + src9) + 8)>>4];
+ dst+=dstStride;
+ src+=srcStride;
+ }while(--h);
+}
+
+static void wmv2_mspel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int w){
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+
+ do{
+ int src_1,src0,src1,src2,src3,src4,src5,src6,src7,src8,src9;
+ uint8_t *s = src,*d = dst;
+ src_1 = *(s-srcStride);
+ src0 = *s; s+=srcStride;
+ src1 = *s; s+=srcStride;
+ src2 = *s; s+=srcStride;
+ *d= cm[(9*(src0 + src1) - (src_1 + src2) + 8)>>4]; d+=dstStride;
+ src3 = *s; s+=srcStride;
+ *d= cm[(9*(src1 + src2) - (src0 + src3) + 8)>>4]; d+=dstStride;
+ src4 = *s; s+=srcStride;
+ *d= cm[(9*(src2 + src3) - (src1 + src4) + 8)>>4]; d+=dstStride;
+ src5 = *s; s+=srcStride;
+ *d= cm[(9*(src3 + src4) - (src2 + src5) + 8)>>4]; d+=dstStride;
+ src6 = *s; s+=srcStride;
+ *d= cm[(9*(src4 + src5) - (src3 + src6) + 8)>>4]; d+=dstStride;
+ src7 = *s; s+=srcStride;
+ *d= cm[(9*(src5 + src6) - (src4 + src7) + 8)>>4]; d+=dstStride;
+ src8 = *s; s+=srcStride;
+ *d= cm[(9*(src6 + src7) - (src5 + src8) + 8)>>4]; d+=dstStride;
+ src9 = *s;
+ *d= cm[(9*(src7 + src8) - (src6 + src9) + 8)>>4]; d+=dstStride;
+ src++;
+ dst++;
+ }while(--w);
+}
+
+static void put_mspel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){
+ put_pixels8_c(dst, src, stride, 8);
+}
+
+static void put_mspel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){
+ uint8_t half[64];
+ wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
+ put_pixels8_l2_aligned2(dst, src, half, stride, stride, 8, 8);
+}
+
+static void put_mspel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){
+ wmv2_mspel8_h_lowpass(dst, src, stride, stride, 8);
+}
+
+static void put_mspel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){
+ uint8_t half[64];
+ wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
+ put_pixels8_l2_aligned2(dst, src+1, half, stride, stride, 8, 8);
+}
+
+static void put_mspel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){
+ wmv2_mspel8_v_lowpass(dst, src, stride, stride, 8);
+}
+
+static void put_mspel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){
+ uint8_t halfH[88];
+ uint8_t halfV[64];
+ uint8_t halfHV[64];
+ wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
+ wmv2_mspel8_v_lowpass(halfV, src, 8, stride, 8);
+ wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
+ put_pixels8_l2_aligned(dst, halfV, halfHV, stride, 8, 8, 8);
+}
+static void put_mspel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){
+ uint8_t halfH[88];
+ uint8_t halfV[64];
+ uint8_t halfHV[64];
+ wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
+ wmv2_mspel8_v_lowpass(halfV, src+1, 8, stride, 8);
+ wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
+ put_pixels8_l2_aligned(dst, halfV, halfHV, stride, 8, 8, 8);
+}
+static void put_mspel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){
+ uint8_t halfH[88];
+ wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
+ wmv2_mspel8_v_lowpass(dst, halfH+8, stride, 8, 8);
+}
diff --git a/contrib/ffmpeg/libavcodec/shorten.c b/contrib/ffmpeg/libavcodec/shorten.c
new file mode 100644
index 000000000..efb48b51d
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/shorten.c
@@ -0,0 +1,535 @@
+/*
+ * Shorten decoder
+ * Copyright (c) 2005 Jeff Muizelaar
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 shorten.c
+ * Shorten decoder
+ * @author Jeff Muizelaar
+ *
+ */
+
+#define DEBUG
+#include <limits.h>
+#include "avcodec.h"
+#include "bitstream.h"
+#include "golomb.h"
+
+#define MAX_CHANNELS 8
+#define MAX_BLOCKSIZE 65535
+
+#define OUT_BUFFER_SIZE 16384
+
+#define ULONGSIZE 2
+
+#define WAVE_FORMAT_PCM 0x0001
+
+#define DEFAULT_BLOCK_SIZE 256
+
+#define TYPESIZE 4
+#define CHANSIZE 0
+#define LPCQSIZE 2
+#define ENERGYSIZE 3
+#define BITSHIFTSIZE 2
+
+#define TYPE_S16HL 3
+#define TYPE_S16LH 5
+
+#define NWRAP 3
+#define NSKIPSIZE 1
+
+#define LPCQUANT 5
+#define V2LPCQOFFSET (1 << LPCQUANT)
+
+#define FNSIZE 2
+#define FN_DIFF0 0
+#define FN_DIFF1 1
+#define FN_DIFF2 2
+#define FN_DIFF3 3
+#define FN_QUIT 4
+#define FN_BLOCKSIZE 5
+#define FN_BITSHIFT 6
+#define FN_QLPC 7
+#define FN_ZERO 8
+#define FN_VERBATIM 9
+
+#define VERBATIM_CKSIZE_SIZE 5
+#define VERBATIM_BYTE_SIZE 8
+#define CANONICAL_HEADER_SIZE 44
+
+typedef struct ShortenContext {
+ AVCodecContext *avctx;
+ GetBitContext gb;
+
+ int min_framesize, max_framesize;
+ int channels;
+
+ int32_t *decoded[MAX_CHANNELS];
+ int32_t *offset[MAX_CHANNELS];
+ uint8_t *bitstream;
+ int bitstream_size;
+ int bitstream_index;
+ unsigned int allocated_bitstream_size;
+ int header_size;
+ uint8_t header[OUT_BUFFER_SIZE];
+ int version;
+ int cur_chan;
+ int bitshift;
+ int nmean;
+ int internal_ftype;
+ int nwrap;
+ int blocksize;
+ int bitindex;
+ int32_t lpcqoffset;
+} ShortenContext;
+
+static int shorten_decode_init(AVCodecContext * avctx)
+{
+ ShortenContext *s = avctx->priv_data;
+ s->avctx = avctx;
+
+ return 0;
+}
+
+static int allocate_buffers(ShortenContext *s)
+{
+ int i, chan;
+ for (chan=0; chan<s->channels; chan++) {
+ if(FFMAX(1, s->nmean) >= UINT_MAX/sizeof(int32_t)){
+ av_log(s->avctx, AV_LOG_ERROR, "nmean too large\n");
+ return -1;
+ }
+ if(s->blocksize + s->nwrap >= UINT_MAX/sizeof(int32_t) || s->blocksize + s->nwrap <= (unsigned)s->nwrap){
+ av_log(s->avctx, AV_LOG_ERROR, "s->blocksize + s->nwrap too large\n");
+ return -1;
+ }
+
+ s->offset[chan] = av_realloc(s->offset[chan], sizeof(int32_t)*FFMAX(1, s->nmean));
+
+ s->decoded[chan] = av_realloc(s->decoded[chan], sizeof(int32_t)*(s->blocksize + s->nwrap));
+ for (i=0; i<s->nwrap; i++)
+ s->decoded[chan][i] = 0;
+ s->decoded[chan] += s->nwrap;
+ }
+ return 0;
+}
+
+
+static inline unsigned int get_uint(ShortenContext *s, int k)
+{
+ if (s->version != 0)
+ k = get_ur_golomb_shorten(&s->gb, ULONGSIZE);
+ return get_ur_golomb_shorten(&s->gb, k);
+}
+
+
+static void fix_bitshift(ShortenContext *s, int32_t *buffer)
+{
+ int i;
+
+ if (s->bitshift != 0)
+ for (i = 0; i < s->blocksize; i++)
+ buffer[s->nwrap + i] <<= s->bitshift;
+}
+
+
+static void init_offset(ShortenContext *s)
+{
+ int32_t mean = 0;
+ int chan, i;
+ int nblock = FFMAX(1, s->nmean);
+ /* initialise offset */
+ switch (s->internal_ftype)
+ {
+ case TYPE_S16HL:
+ case TYPE_S16LH:
+ mean = 0;
+ break;
+ default:
+ av_log(s->avctx, AV_LOG_ERROR, "unknown audio type");
+ abort();
+ }
+
+ for (chan = 0; chan < s->channels; chan++)
+ for (i = 0; i < nblock; i++)
+ s->offset[chan][i] = mean;
+}
+
+static int inline get_le32(GetBitContext *gb)
+{
+ return bswap_32(get_bits_long(gb, 32));
+}
+
+static short inline get_le16(GetBitContext *gb)
+{
+ return bswap_16(get_bits_long(gb, 16));
+}
+
+static int decode_wave_header(AVCodecContext *avctx, uint8_t *header, int header_size)
+{
+ GetBitContext hb;
+ int len;
+ int chunk_size;
+ short wave_format;
+
+ init_get_bits(&hb, header, header_size*8);
+ if (get_le32(&hb) != MKTAG('R','I','F','F')) {
+ av_log(avctx, AV_LOG_ERROR, "missing RIFF tag\n");
+ return -1;
+ }
+
+ chunk_size = get_le32(&hb);
+
+ if (get_le32(&hb) != MKTAG('W','A','V','E')) {
+ av_log(avctx, AV_LOG_ERROR, "missing WAVE tag\n");
+ return -1;
+ }
+
+ while (get_le32(&hb) != MKTAG('f','m','t',' ')) {
+ len = get_le32(&hb);
+ skip_bits(&hb, 8*len);
+ }
+ len = get_le32(&hb);
+
+ if (len < 16) {
+ av_log(avctx, AV_LOG_ERROR, "fmt chunk was too short\n");
+ return -1;
+ }
+
+ wave_format = get_le16(&hb);
+
+ switch (wave_format) {
+ case WAVE_FORMAT_PCM:
+ break;
+ default:
+ av_log(avctx, AV_LOG_ERROR, "unsupported wave format\n");
+ return -1;
+ }
+
+ avctx->channels = get_le16(&hb);
+ avctx->sample_rate = get_le32(&hb);
+ avctx->bit_rate = get_le32(&hb) * 8;
+ avctx->block_align = get_le16(&hb);
+ avctx->bits_per_sample = get_le16(&hb);
+
+ if (avctx->bits_per_sample != 16) {
+ av_log(avctx, AV_LOG_ERROR, "unsupported number of bits per sample\n");
+ return -1;
+ }
+
+ len -= 16;
+ if (len > 0)
+ av_log(avctx, AV_LOG_INFO, "%d header bytes unparsed\n", len);
+
+ return 0;
+}
+
+static int16_t * interleave_buffer(int16_t *samples, int nchan, int blocksize, int32_t **buffer) {
+ int i, chan;
+ for (i=0; i<blocksize; i++)
+ for (chan=0; chan < nchan; chan++)
+ *samples++ = FFMIN(buffer[chan][i], 32768);
+ return samples;
+}
+
+static void decode_subframe_lpc(ShortenContext *s, int channel, int residual_size, int pred_order)
+{
+ int sum, i, j;
+ int coeffs[pred_order];
+
+ for (i=0; i<pred_order; i++)
+ coeffs[i] = get_sr_golomb_shorten(&s->gb, LPCQUANT);
+
+ for (i=0; i < s->blocksize; i++) {
+ sum = s->lpcqoffset;
+ for (j=0; j<pred_order; j++)
+ sum += coeffs[j] * s->decoded[channel][i-j-1];
+ s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + (sum >> LPCQUANT);
+ }
+}
+
+
+static int shorten_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ ShortenContext *s = avctx->priv_data;
+ int i, input_buf_size = 0;
+ int16_t *samples = data;
+ if(s->max_framesize == 0){
+ s->max_framesize= 1024; // should hopefully be enough for the first header
+ s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->max_framesize);
+ }
+
+ if(1 && s->max_framesize){//FIXME truncated
+ buf_size= FFMIN(buf_size, s->max_framesize - s->bitstream_size);
+ input_buf_size= buf_size;
+
+ if(s->bitstream_index + s->bitstream_size + buf_size > s->allocated_bitstream_size){
+ // printf("memmove\n");
+ memmove(s->bitstream, &s->bitstream[s->bitstream_index], s->bitstream_size);
+ s->bitstream_index=0;
+ }
+ memcpy(&s->bitstream[s->bitstream_index + s->bitstream_size], buf, buf_size);
+ buf= &s->bitstream[s->bitstream_index];
+ buf_size += s->bitstream_size;
+ s->bitstream_size= buf_size;
+
+ if(buf_size < s->max_framesize){
+ //dprintf(avctx, "wanna more data ... %d\n", buf_size);
+ *data_size = 0;
+ return input_buf_size;
+ }
+ }
+ init_get_bits(&s->gb, buf, buf_size*8);
+ get_bits(&s->gb, s->bitindex);
+ if (!s->blocksize)
+ {
+ int maxnlpc = 0;
+ /* shorten signature */
+ if (get_bits_long(&s->gb, 32) != bswap_32(ff_get_fourcc("ajkg"))) {
+ av_log(s->avctx, AV_LOG_ERROR, "missing shorten magic 'ajkg'\n");
+ return -1;
+ }
+
+ s->lpcqoffset = 0;
+ s->blocksize = DEFAULT_BLOCK_SIZE;
+ s->channels = 1;
+ s->nmean = -1;
+ s->version = get_bits(&s->gb, 8);
+ s->internal_ftype = get_uint(s, TYPESIZE);
+
+ s->channels = get_uint(s, CHANSIZE);
+ if (s->channels > MAX_CHANNELS) {
+ av_log(s->avctx, AV_LOG_ERROR, "too many channels: %d\n", s->channels);
+ return -1;
+ }
+
+ /* get blocksize if version > 0 */
+ if (s->version > 0) {
+ int skip_bytes;
+ s->blocksize = get_uint(s, av_log2(DEFAULT_BLOCK_SIZE));
+ maxnlpc = get_uint(s, LPCQSIZE);
+ s->nmean = get_uint(s, 0);
+
+ skip_bytes = get_uint(s, NSKIPSIZE);
+ for (i=0; i<skip_bytes; i++) {
+ skip_bits(&s->gb, 8);
+ }
+ }
+ s->nwrap = FFMAX(NWRAP, maxnlpc);
+
+ if (allocate_buffers(s))
+ return -1;
+
+ init_offset(s);
+
+ if (s->version > 1)
+ s->lpcqoffset = V2LPCQOFFSET;
+
+ if (get_ur_golomb_shorten(&s->gb, FNSIZE) != FN_VERBATIM) {
+ av_log(s->avctx, AV_LOG_ERROR, "missing verbatim section at begining of stream\n");
+ return -1;
+ }
+
+ s->header_size = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE);
+ if (s->header_size >= OUT_BUFFER_SIZE || s->header_size < CANONICAL_HEADER_SIZE) {
+ av_log(s->avctx, AV_LOG_ERROR, "header is wrong size: %d\n", s->header_size);
+ return -1;
+ }
+
+ for (i=0; i<s->header_size; i++)
+ s->header[i] = (char)get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE);
+
+ if (decode_wave_header(avctx, s->header, s->header_size) < 0)
+ return -1;
+
+ s->cur_chan = 0;
+ s->bitshift = 0;
+ }
+ else
+ {
+ int cmd;
+ int len;
+ cmd = get_ur_golomb_shorten(&s->gb, FNSIZE);
+ switch (cmd) {
+ case FN_ZERO:
+ case FN_DIFF0:
+ case FN_DIFF1:
+ case FN_DIFF2:
+ case FN_DIFF3:
+ case FN_QLPC:
+ {
+ int residual_size = 0;
+ int channel = s->cur_chan;
+ int32_t coffset;
+ if (cmd != FN_ZERO) {
+ residual_size = get_ur_golomb_shorten(&s->gb, ENERGYSIZE);
+ /* this is a hack as version 0 differed in defintion of get_sr_golomb_shorten */
+ if (s->version == 0)
+ residual_size--;
+ }
+
+ if (s->nmean == 0)
+ coffset = s->offset[channel][0];
+ else {
+ int32_t sum = (s->version < 2) ? 0 : s->nmean / 2;
+ for (i=0; i<s->nmean; i++)
+ sum += s->offset[channel][i];
+ coffset = sum / s->nmean;
+ if (s->version >= 2)
+ coffset >>= FFMIN(1, s->bitshift);
+ }
+ switch (cmd) {
+ case FN_ZERO:
+ for (i=0; i<s->blocksize; i++)
+ s->decoded[channel][i] = 0;
+ break;
+ case FN_DIFF0:
+ for (i=0; i<s->blocksize; i++)
+ s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + coffset;
+ break;
+ case FN_DIFF1:
+ for (i=0; i<s->blocksize; i++)
+ s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + s->decoded[channel][i - 1];
+ break;
+ case FN_DIFF2:
+ for (i=0; i<s->blocksize; i++)
+ s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + 2*s->decoded[channel][i-1]
+ - s->decoded[channel][i-2];
+ break;
+ case FN_DIFF3:
+ for (i=0; i<s->blocksize; i++)
+ s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + 3*s->decoded[channel][i-1]
+ - 3*s->decoded[channel][i-2]
+ + s->decoded[channel][i-3];
+ break;
+ case FN_QLPC:
+ {
+ int pred_order = get_ur_golomb_shorten(&s->gb, LPCQSIZE);
+ for (i=0; i<pred_order; i++)
+ s->decoded[channel][i - pred_order] -= coffset;
+ decode_subframe_lpc(s, channel, residual_size, pred_order);
+ if (coffset != 0)
+ for (i=0; i < s->blocksize; i++)
+ s->decoded[channel][i] += coffset;
+ }
+ }
+ if (s->nmean > 0) {
+ int32_t sum = (s->version < 2) ? 0 : s->blocksize / 2;
+ for (i=0; i<s->blocksize; i++)
+ sum += s->decoded[channel][i];
+
+ for (i=1; i<s->nmean; i++)
+ s->offset[channel][i-1] = s->offset[channel][i];
+
+ if (s->version < 2)
+ s->offset[channel][s->nmean - 1] = sum / s->blocksize;
+ else
+ s->offset[channel][s->nmean - 1] = (sum / s->blocksize) << s->bitshift;
+ }
+ for (i=-s->nwrap; i<0; i++)
+ s->decoded[channel][i] = s->decoded[channel][i + s->blocksize];
+
+ fix_bitshift(s, s->decoded[channel]);
+
+ s->cur_chan++;
+ if (s->cur_chan == s->channels) {
+ samples = interleave_buffer(samples, s->channels, s->blocksize, s->decoded);
+ s->cur_chan = 0;
+ goto frame_done;
+ }
+ break;
+ }
+ break;
+ case FN_VERBATIM:
+ len = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE);
+ while (len--) {
+ get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE);
+ }
+ break;
+ case FN_BITSHIFT:
+ s->bitshift = get_ur_golomb_shorten(&s->gb, BITSHIFTSIZE);
+ break;
+ case FN_BLOCKSIZE:
+ s->blocksize = get_uint(s, av_log2(s->blocksize));
+ break;
+ case FN_QUIT:
+ *data_size = 0;
+ return buf_size;
+ break;
+ default:
+ av_log(avctx, AV_LOG_ERROR, "unknown shorten function %d\n", cmd);
+ return -1;
+ break;
+ }
+ }
+frame_done:
+ *data_size = (int8_t *)samples - (int8_t *)data;
+
+ // s->last_blocksize = s->blocksize;
+ s->bitindex = get_bits_count(&s->gb) - 8*((get_bits_count(&s->gb))/8);
+ i= (get_bits_count(&s->gb))/8;
+ if (i > buf_size) {
+ av_log(s->avctx, AV_LOG_ERROR, "overread: %d\n", i - buf_size);
+ s->bitstream_size=0;
+ s->bitstream_index=0;
+ return -1;
+ }
+ if (s->bitstream_size) {
+ s->bitstream_index += i;
+ s->bitstream_size -= i;
+ return input_buf_size;
+ } else
+ return i;
+}
+
+static int shorten_decode_close(AVCodecContext *avctx)
+{
+ ShortenContext *s = avctx->priv_data;
+ int i;
+
+ for (i = 0; i < s->channels; i++) {
+ s->decoded[i] -= s->nwrap;
+ av_freep(&s->decoded[i]);
+ av_freep(&s->offset[i]);
+ }
+ av_freep(&s->bitstream);
+ return 0;
+}
+
+static void shorten_flush(AVCodecContext *avctx){
+ ShortenContext *s = avctx->priv_data;
+
+ s->bitstream_size=
+ s->bitstream_index= 0;
+}
+
+AVCodec shorten_decoder = {
+ "shorten",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_SHORTEN,
+ sizeof(ShortenContext),
+ shorten_decode_init,
+ NULL,
+ shorten_decode_close,
+ shorten_decode_frame,
+ .flush= shorten_flush,
+};
diff --git a/contrib/ffmpeg/libavcodec/simple_idct.c b/contrib/ffmpeg/libavcodec/simple_idct.c
new file mode 100644
index 000000000..dcf752e16
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/simple_idct.c
@@ -0,0 +1,587 @@
+/*
+ * Simple IDCT
+ *
+ * Copyright (c) 2001 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file simple_idct.c
+ * simpleidct in C.
+ */
+
+/*
+ based upon some outcommented c code from mpeg2dec (idct_mmx.c
+ written by Aaron Holtzman <aholtzma@ess.engr.uvic.ca>)
+ */
+#include "avcodec.h"
+#include "dsputil.h"
+#include "simple_idct.h"
+
+#if 0
+#define W1 2841 /* 2048*sqrt (2)*cos (1*pi/16) */
+#define W2 2676 /* 2048*sqrt (2)*cos (2*pi/16) */
+#define W3 2408 /* 2048*sqrt (2)*cos (3*pi/16) */
+#define W4 2048 /* 2048*sqrt (2)*cos (4*pi/16) */
+#define W5 1609 /* 2048*sqrt (2)*cos (5*pi/16) */
+#define W6 1108 /* 2048*sqrt (2)*cos (6*pi/16) */
+#define W7 565 /* 2048*sqrt (2)*cos (7*pi/16) */
+#define ROW_SHIFT 8
+#define COL_SHIFT 17
+#else
+#define W1 22725 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
+#define W2 21407 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
+#define W3 19266 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
+#define W4 16383 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
+#define W5 12873 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
+#define W6 8867 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
+#define W7 4520 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
+#define ROW_SHIFT 11
+#define COL_SHIFT 20 // 6
+#endif
+
+#if defined(ARCH_POWERPC_405)
+
+/* signed 16x16 -> 32 multiply add accumulate */
+#define MAC16(rt, ra, rb) \
+ asm ("maclhw %0, %2, %3" : "=r" (rt) : "0" (rt), "r" (ra), "r" (rb));
+
+/* signed 16x16 -> 32 multiply */
+#define MUL16(rt, ra, rb) \
+ asm ("mullhw %0, %1, %2" : "=r" (rt) : "r" (ra), "r" (rb));
+
+#else
+
+/* signed 16x16 -> 32 multiply add accumulate */
+#define MAC16(rt, ra, rb) rt += (ra) * (rb)
+
+/* signed 16x16 -> 32 multiply */
+#define MUL16(rt, ra, rb) rt = (ra) * (rb)
+
+#endif
+
+static inline void idctRowCondDC (DCTELEM * row)
+{
+ int a0, a1, a2, a3, b0, b1, b2, b3;
+#ifdef HAVE_FAST_64BIT
+ uint64_t temp;
+#else
+ uint32_t temp;
+#endif
+
+#ifdef HAVE_FAST_64BIT
+#ifdef WORDS_BIGENDIAN
+#define ROW0_MASK 0xffff000000000000LL
+#else
+#define ROW0_MASK 0xffffLL
+#endif
+ if(sizeof(DCTELEM)==2){
+ if ( ((((uint64_t *)row)[0] & ~ROW0_MASK) |
+ ((uint64_t *)row)[1]) == 0) {
+ temp = (row[0] << 3) & 0xffff;
+ temp += temp << 16;
+ temp += temp << 32;
+ ((uint64_t *)row)[0] = temp;
+ ((uint64_t *)row)[1] = temp;
+ return;
+ }
+ }else{
+ if (!(row[1]|row[2]|row[3]|row[4]|row[5]|row[6]|row[7])) {
+ row[0]=row[1]=row[2]=row[3]=row[4]=row[5]=row[6]=row[7]= row[0] << 3;
+ return;
+ }
+ }
+#else
+ if(sizeof(DCTELEM)==2){
+ if (!(((uint32_t*)row)[1] |
+ ((uint32_t*)row)[2] |
+ ((uint32_t*)row)[3] |
+ row[1])) {
+ temp = (row[0] << 3) & 0xffff;
+ temp += temp << 16;
+ ((uint32_t*)row)[0]=((uint32_t*)row)[1] =
+ ((uint32_t*)row)[2]=((uint32_t*)row)[3] = temp;
+ return;
+ }
+ }else{
+ if (!(row[1]|row[2]|row[3]|row[4]|row[5]|row[6]|row[7])) {
+ row[0]=row[1]=row[2]=row[3]=row[4]=row[5]=row[6]=row[7]= row[0] << 3;
+ return;
+ }
+ }
+#endif
+
+ a0 = (W4 * row[0]) + (1 << (ROW_SHIFT - 1));
+ a1 = a0;
+ a2 = a0;
+ a3 = a0;
+
+ /* no need to optimize : gcc does it */
+ a0 += W2 * row[2];
+ a1 += W6 * row[2];
+ a2 -= W6 * row[2];
+ a3 -= W2 * row[2];
+
+ MUL16(b0, W1, row[1]);
+ MAC16(b0, W3, row[3]);
+ MUL16(b1, W3, row[1]);
+ MAC16(b1, -W7, row[3]);
+ MUL16(b2, W5, row[1]);
+ MAC16(b2, -W1, row[3]);
+ MUL16(b3, W7, row[1]);
+ MAC16(b3, -W5, row[3]);
+
+#ifdef HAVE_FAST_64BIT
+ temp = ((uint64_t*)row)[1];
+#else
+ temp = ((uint32_t*)row)[2] | ((uint32_t*)row)[3];
+#endif
+ if (temp != 0) {
+ a0 += W4*row[4] + W6*row[6];
+ a1 += - W4*row[4] - W2*row[6];
+ a2 += - W4*row[4] + W2*row[6];
+ a3 += W4*row[4] - W6*row[6];
+
+ MAC16(b0, W5, row[5]);
+ MAC16(b0, W7, row[7]);
+
+ MAC16(b1, -W1, row[5]);
+ MAC16(b1, -W5, row[7]);
+
+ MAC16(b2, W7, row[5]);
+ MAC16(b2, W3, row[7]);
+
+ MAC16(b3, W3, row[5]);
+ MAC16(b3, -W1, row[7]);
+ }
+
+ row[0] = (a0 + b0) >> ROW_SHIFT;
+ row[7] = (a0 - b0) >> ROW_SHIFT;
+ row[1] = (a1 + b1) >> ROW_SHIFT;
+ row[6] = (a1 - b1) >> ROW_SHIFT;
+ row[2] = (a2 + b2) >> ROW_SHIFT;
+ row[5] = (a2 - b2) >> ROW_SHIFT;
+ row[3] = (a3 + b3) >> ROW_SHIFT;
+ row[4] = (a3 - b3) >> ROW_SHIFT;
+}
+
+static inline void idctSparseColPut (uint8_t *dest, int line_size,
+ DCTELEM * col)
+{
+ int a0, a1, a2, a3, b0, b1, b2, b3;
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+
+ /* XXX: I did that only to give same values as previous code */
+ a0 = W4 * (col[8*0] + ((1<<(COL_SHIFT-1))/W4));
+ a1 = a0;
+ a2 = a0;
+ a3 = a0;
+
+ a0 += + W2*col[8*2];
+ a1 += + W6*col[8*2];
+ a2 += - W6*col[8*2];
+ a3 += - W2*col[8*2];
+
+ MUL16(b0, W1, col[8*1]);
+ MUL16(b1, W3, col[8*1]);
+ MUL16(b2, W5, col[8*1]);
+ MUL16(b3, W7, col[8*1]);
+
+ MAC16(b0, + W3, col[8*3]);
+ MAC16(b1, - W7, col[8*3]);
+ MAC16(b2, - W1, col[8*3]);
+ MAC16(b3, - W5, col[8*3]);
+
+ if(col[8*4]){
+ a0 += + W4*col[8*4];
+ a1 += - W4*col[8*4];
+ a2 += - W4*col[8*4];
+ a3 += + W4*col[8*4];
+ }
+
+ if (col[8*5]) {
+ MAC16(b0, + W5, col[8*5]);
+ MAC16(b1, - W1, col[8*5]);
+ MAC16(b2, + W7, col[8*5]);
+ MAC16(b3, + W3, col[8*5]);
+ }
+
+ if(col[8*6]){
+ a0 += + W6*col[8*6];
+ a1 += - W2*col[8*6];
+ a2 += + W2*col[8*6];
+ a3 += - W6*col[8*6];
+ }
+
+ if (col[8*7]) {
+ MAC16(b0, + W7, col[8*7]);
+ MAC16(b1, - W5, col[8*7]);
+ MAC16(b2, + W3, col[8*7]);
+ MAC16(b3, - W1, col[8*7]);
+ }
+
+ dest[0] = cm[(a0 + b0) >> COL_SHIFT];
+ dest += line_size;
+ dest[0] = cm[(a1 + b1) >> COL_SHIFT];
+ dest += line_size;
+ dest[0] = cm[(a2 + b2) >> COL_SHIFT];
+ dest += line_size;
+ dest[0] = cm[(a3 + b3) >> COL_SHIFT];
+ dest += line_size;
+ dest[0] = cm[(a3 - b3) >> COL_SHIFT];
+ dest += line_size;
+ dest[0] = cm[(a2 - b2) >> COL_SHIFT];
+ dest += line_size;
+ dest[0] = cm[(a1 - b1) >> COL_SHIFT];
+ dest += line_size;
+ dest[0] = cm[(a0 - b0) >> COL_SHIFT];
+}
+
+static inline void idctSparseColAdd (uint8_t *dest, int line_size,
+ DCTELEM * col)
+{
+ int a0, a1, a2, a3, b0, b1, b2, b3;
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+
+ /* XXX: I did that only to give same values as previous code */
+ a0 = W4 * (col[8*0] + ((1<<(COL_SHIFT-1))/W4));
+ a1 = a0;
+ a2 = a0;
+ a3 = a0;
+
+ a0 += + W2*col[8*2];
+ a1 += + W6*col[8*2];
+ a2 += - W6*col[8*2];
+ a3 += - W2*col[8*2];
+
+ MUL16(b0, W1, col[8*1]);
+ MUL16(b1, W3, col[8*1]);
+ MUL16(b2, W5, col[8*1]);
+ MUL16(b3, W7, col[8*1]);
+
+ MAC16(b0, + W3, col[8*3]);
+ MAC16(b1, - W7, col[8*3]);
+ MAC16(b2, - W1, col[8*3]);
+ MAC16(b3, - W5, col[8*3]);
+
+ if(col[8*4]){
+ a0 += + W4*col[8*4];
+ a1 += - W4*col[8*4];
+ a2 += - W4*col[8*4];
+ a3 += + W4*col[8*4];
+ }
+
+ if (col[8*5]) {
+ MAC16(b0, + W5, col[8*5]);
+ MAC16(b1, - W1, col[8*5]);
+ MAC16(b2, + W7, col[8*5]);
+ MAC16(b3, + W3, col[8*5]);
+ }
+
+ if(col[8*6]){
+ a0 += + W6*col[8*6];
+ a1 += - W2*col[8*6];
+ a2 += + W2*col[8*6];
+ a3 += - W6*col[8*6];
+ }
+
+ if (col[8*7]) {
+ MAC16(b0, + W7, col[8*7]);
+ MAC16(b1, - W5, col[8*7]);
+ MAC16(b2, + W3, col[8*7]);
+ MAC16(b3, - W1, col[8*7]);
+ }
+
+ dest[0] = cm[dest[0] + ((a0 + b0) >> COL_SHIFT)];
+ dest += line_size;
+ dest[0] = cm[dest[0] + ((a1 + b1) >> COL_SHIFT)];
+ dest += line_size;
+ dest[0] = cm[dest[0] + ((a2 + b2) >> COL_SHIFT)];
+ dest += line_size;
+ dest[0] = cm[dest[0] + ((a3 + b3) >> COL_SHIFT)];
+ dest += line_size;
+ dest[0] = cm[dest[0] + ((a3 - b3) >> COL_SHIFT)];
+ dest += line_size;
+ dest[0] = cm[dest[0] + ((a2 - b2) >> COL_SHIFT)];
+ dest += line_size;
+ dest[0] = cm[dest[0] + ((a1 - b1) >> COL_SHIFT)];
+ dest += line_size;
+ dest[0] = cm[dest[0] + ((a0 - b0) >> COL_SHIFT)];
+}
+
+static inline void idctSparseCol (DCTELEM * col)
+{
+ int a0, a1, a2, a3, b0, b1, b2, b3;
+
+ /* XXX: I did that only to give same values as previous code */
+ a0 = W4 * (col[8*0] + ((1<<(COL_SHIFT-1))/W4));
+ a1 = a0;
+ a2 = a0;
+ a3 = a0;
+
+ a0 += + W2*col[8*2];
+ a1 += + W6*col[8*2];
+ a2 += - W6*col[8*2];
+ a3 += - W2*col[8*2];
+
+ MUL16(b0, W1, col[8*1]);
+ MUL16(b1, W3, col[8*1]);
+ MUL16(b2, W5, col[8*1]);
+ MUL16(b3, W7, col[8*1]);
+
+ MAC16(b0, + W3, col[8*3]);
+ MAC16(b1, - W7, col[8*3]);
+ MAC16(b2, - W1, col[8*3]);
+ MAC16(b3, - W5, col[8*3]);
+
+ if(col[8*4]){
+ a0 += + W4*col[8*4];
+ a1 += - W4*col[8*4];
+ a2 += - W4*col[8*4];
+ a3 += + W4*col[8*4];
+ }
+
+ if (col[8*5]) {
+ MAC16(b0, + W5, col[8*5]);
+ MAC16(b1, - W1, col[8*5]);
+ MAC16(b2, + W7, col[8*5]);
+ MAC16(b3, + W3, col[8*5]);
+ }
+
+ if(col[8*6]){
+ a0 += + W6*col[8*6];
+ a1 += - W2*col[8*6];
+ a2 += + W2*col[8*6];
+ a3 += - W6*col[8*6];
+ }
+
+ if (col[8*7]) {
+ MAC16(b0, + W7, col[8*7]);
+ MAC16(b1, - W5, col[8*7]);
+ MAC16(b2, + W3, col[8*7]);
+ MAC16(b3, - W1, col[8*7]);
+ }
+
+ col[0 ] = ((a0 + b0) >> COL_SHIFT);
+ col[8 ] = ((a1 + b1) >> COL_SHIFT);
+ col[16] = ((a2 + b2) >> COL_SHIFT);
+ col[24] = ((a3 + b3) >> COL_SHIFT);
+ col[32] = ((a3 - b3) >> COL_SHIFT);
+ col[40] = ((a2 - b2) >> COL_SHIFT);
+ col[48] = ((a1 - b1) >> COL_SHIFT);
+ col[56] = ((a0 - b0) >> COL_SHIFT);
+}
+
+void simple_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ int i;
+ for(i=0; i<8; i++)
+ idctRowCondDC(block + i*8);
+
+ for(i=0; i<8; i++)
+ idctSparseColPut(dest + i, line_size, block + i);
+}
+
+void simple_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ int i;
+ for(i=0; i<8; i++)
+ idctRowCondDC(block + i*8);
+
+ for(i=0; i<8; i++)
+ idctSparseColAdd(dest + i, line_size, block + i);
+}
+
+void simple_idct(DCTELEM *block)
+{
+ int i;
+ for(i=0; i<8; i++)
+ idctRowCondDC(block + i*8);
+
+ for(i=0; i<8; i++)
+ idctSparseCol(block + i);
+}
+
+/* 2x4x8 idct */
+
+#define CN_SHIFT 12
+#define C_FIX(x) ((int)((x) * (1 << CN_SHIFT) + 0.5))
+#define C1 C_FIX(0.6532814824)
+#define C2 C_FIX(0.2705980501)
+
+/* row idct is multiple by 16 * sqrt(2.0), col idct4 is normalized,
+ and the butterfly must be multiplied by 0.5 * sqrt(2.0) */
+#define C_SHIFT (4+1+12)
+
+static inline void idct4col(uint8_t *dest, int line_size, const DCTELEM *col)
+{
+ int c0, c1, c2, c3, a0, a1, a2, a3;
+ const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+
+ a0 = col[8*0];
+ a1 = col[8*2];
+ a2 = col[8*4];
+ a3 = col[8*6];
+ c0 = ((a0 + a2) << (CN_SHIFT - 1)) + (1 << (C_SHIFT - 1));
+ c2 = ((a0 - a2) << (CN_SHIFT - 1)) + (1 << (C_SHIFT - 1));
+ c1 = a1 * C1 + a3 * C2;
+ c3 = a1 * C2 - a3 * C1;
+ dest[0] = cm[(c0 + c1) >> C_SHIFT];
+ dest += line_size;
+ dest[0] = cm[(c2 + c3) >> C_SHIFT];
+ dest += line_size;
+ dest[0] = cm[(c2 - c3) >> C_SHIFT];
+ dest += line_size;
+ dest[0] = cm[(c0 - c1) >> C_SHIFT];
+}
+
+#define BF(k) \
+{\
+ int a0, a1;\
+ a0 = ptr[k];\
+ a1 = ptr[8 + k];\
+ ptr[k] = a0 + a1;\
+ ptr[8 + k] = a0 - a1;\
+}
+
+/* only used by DV codec. The input must be interlaced. 128 is added
+ to the pixels before clamping to avoid systematic error
+ (1024*sqrt(2)) offset would be needed otherwise. */
+/* XXX: I think a 1.0/sqrt(2) normalization should be needed to
+ compensate the extra butterfly stage - I don't have the full DV
+ specification */
+void simple_idct248_put(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ int i;
+ DCTELEM *ptr;
+
+ /* butterfly */
+ ptr = block;
+ for(i=0;i<4;i++) {
+ BF(0);
+ BF(1);
+ BF(2);
+ BF(3);
+ BF(4);
+ BF(5);
+ BF(6);
+ BF(7);
+ ptr += 2 * 8;
+ }
+
+ /* IDCT8 on each line */
+ for(i=0; i<8; i++) {
+ idctRowCondDC(block + i*8);
+ }
+
+ /* IDCT4 and store */
+ for(i=0;i<8;i++) {
+ idct4col(dest + i, 2 * line_size, block + i);
+ idct4col(dest + line_size + i, 2 * line_size, block + 8 + i);
+ }
+}
+
+/* 8x4 & 4x8 WMV2 IDCT */
+#undef CN_SHIFT
+#undef C_SHIFT
+#undef C_FIX
+#undef C1
+#undef C2
+#define CN_SHIFT 12
+#define C_FIX(x) ((int)((x) * 1.414213562 * (1 << CN_SHIFT) + 0.5))
+#define C1 C_FIX(0.6532814824)
+#define C2 C_FIX(0.2705980501)
+#define C3 C_FIX(0.5)
+#define C_SHIFT (4+1+12)
+static inline void idct4col_add(uint8_t *dest, int line_size, const DCTELEM *col)
+{
+ int c0, c1, c2, c3, a0, a1, a2, a3;
+ const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+
+ a0 = col[8*0];
+ a1 = col[8*1];
+ a2 = col[8*2];
+ a3 = col[8*3];
+ c0 = (a0 + a2)*C3 + (1 << (C_SHIFT - 1));
+ c2 = (a0 - a2)*C3 + (1 << (C_SHIFT - 1));
+ c1 = a1 * C1 + a3 * C2;
+ c3 = a1 * C2 - a3 * C1;
+ dest[0] = cm[dest[0] + ((c0 + c1) >> C_SHIFT)];
+ dest += line_size;
+ dest[0] = cm[dest[0] + ((c2 + c3) >> C_SHIFT)];
+ dest += line_size;
+ dest[0] = cm[dest[0] + ((c2 - c3) >> C_SHIFT)];
+ dest += line_size;
+ dest[0] = cm[dest[0] + ((c0 - c1) >> C_SHIFT)];
+}
+
+#define RN_SHIFT 15
+#define R_FIX(x) ((int)((x) * 1.414213562 * (1 << RN_SHIFT) + 0.5))
+#define R1 R_FIX(0.6532814824)
+#define R2 R_FIX(0.2705980501)
+#define R3 R_FIX(0.5)
+#define R_SHIFT 11
+static inline void idct4row(DCTELEM *row)
+{
+ int c0, c1, c2, c3, a0, a1, a2, a3;
+ //const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+
+ a0 = row[0];
+ a1 = row[1];
+ a2 = row[2];
+ a3 = row[3];
+ c0 = (a0 + a2)*R3 + (1 << (R_SHIFT - 1));
+ c2 = (a0 - a2)*R3 + (1 << (R_SHIFT - 1));
+ c1 = a1 * R1 + a3 * R2;
+ c3 = a1 * R2 - a3 * R1;
+ row[0]= (c0 + c1) >> R_SHIFT;
+ row[1]= (c2 + c3) >> R_SHIFT;
+ row[2]= (c2 - c3) >> R_SHIFT;
+ row[3]= (c0 - c1) >> R_SHIFT;
+}
+
+void simple_idct84_add(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ int i;
+
+ /* IDCT8 on each line */
+ for(i=0; i<4; i++) {
+ idctRowCondDC(block + i*8);
+ }
+
+ /* IDCT4 and store */
+ for(i=0;i<8;i++) {
+ idct4col_add(dest + i, line_size, block + i);
+ }
+}
+
+void simple_idct48_add(uint8_t *dest, int line_size, DCTELEM *block)
+{
+ int i;
+
+ /* IDCT4 on each line */
+ for(i=0; i<8; i++) {
+ idct4row(block + i*8);
+ }
+
+ /* IDCT8 and store */
+ for(i=0; i<4; i++){
+ idctSparseColAdd(dest + i, line_size, block + i);
+ }
+}
+
diff --git a/src/libffmpeg/libavcodec/simple_idct.h b/contrib/ffmpeg/libavcodec/simple_idct.h
index c4b453329..c4b453329 100644
--- a/src/libffmpeg/libavcodec/simple_idct.h
+++ b/contrib/ffmpeg/libavcodec/simple_idct.h
diff --git a/contrib/ffmpeg/libavcodec/smacker.c b/contrib/ffmpeg/libavcodec/smacker.c
new file mode 100644
index 000000000..0dd76107b
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/smacker.c
@@ -0,0 +1,717 @@
+/*
+ * Smacker decoder
+ * Copyright (c) 2006 Konstantin Shishkov
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * @file smacker.c
+ * Smacker decoder
+ */
+
+/*
+ * Based on http://wiki.multimedia.cx/index.php?title=Smacker
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "common.h"
+#include "avcodec.h"
+
+#define ALT_BITSTREAM_READER_LE
+#include "bitstream.h"
+
+#define SMKTREE_BITS 9
+#define SMK_NODE 0x80000000
+
+/*
+ * Decoder context
+ */
+typedef struct SmackVContext {
+ AVCodecContext *avctx;
+ AVFrame pic;
+
+ int *mmap_tbl, *mclr_tbl, *full_tbl, *type_tbl;
+ int mmap_last[3], mclr_last[3], full_last[3], type_last[3];
+} SmackVContext;
+
+/**
+ * Context used for code reconstructing
+ */
+typedef struct HuffContext {
+ int length;
+ int maxlength;
+ int current;
+ uint32_t *bits;
+ int *lengths;
+ int *values;
+} HuffContext;
+
+/* common parameters used for decode_bigtree */
+typedef struct DBCtx {
+ VLC *v1, *v2;
+ int *recode1, *recode2;
+ int escapes[3];
+ int *last;
+ int lcur;
+} DBCtx;
+
+/* possible runs of blocks */
+static const int block_runs[64] = {
+ 1, 2, 3, 4, 5, 6, 7, 8,
+ 9, 10, 11, 12, 13, 14, 15, 16,
+ 17, 18, 19, 20, 21, 22, 23, 24,
+ 25, 26, 27, 28, 29, 30, 31, 32,
+ 33, 34, 35, 36, 37, 38, 39, 40,
+ 41, 42, 43, 44, 45, 46, 47, 48,
+ 49, 50, 51, 52, 53, 54, 55, 56,
+ 57, 58, 59, 128, 256, 512, 1024, 2048 };
+
+enum SmkBlockTypes {
+ SMK_BLK_MONO = 0,
+ SMK_BLK_FULL = 1,
+ SMK_BLK_SKIP = 2,
+ SMK_BLK_FILL = 3 };
+
+/**
+ * Decode local frame tree
+ */
+static int smacker_decode_tree(GetBitContext *gb, HuffContext *hc, uint32_t prefix, int length)
+{
+ if(!get_bits1(gb)){ //Leaf
+ if(hc->current >= 256){
+ av_log(NULL, AV_LOG_ERROR, "Tree size exceeded!\n");
+ return -1;
+ }
+ if(length){
+ hc->bits[hc->current] = prefix;
+ hc->lengths[hc->current] = length;
+ } else {
+ hc->bits[hc->current] = 0;
+ hc->lengths[hc->current] = 0;
+ }
+ hc->values[hc->current] = get_bits(gb, 8);
+ hc->current++;
+ if(hc->maxlength < length)
+ hc->maxlength = length;
+ return 0;
+ } else { //Node
+ int r;
+ length++;
+ r = smacker_decode_tree(gb, hc, prefix, length);
+ if(r)
+ return r;
+ return smacker_decode_tree(gb, hc, prefix | (1 << (length - 1)), length);
+ }
+}
+
+/**
+ * Decode header tree
+ */
+static int smacker_decode_bigtree(GetBitContext *gb, HuffContext *hc, DBCtx *ctx)
+{
+ if(!get_bits1(gb)){ //Leaf
+ int val, i1, i2, b1, b2;
+ if(hc->current >= hc->length){
+ av_log(NULL, AV_LOG_ERROR, "Tree size exceeded!\n");
+ return -1;
+ }
+ b1 = get_bits_count(gb);
+ i1 = get_vlc2(gb, ctx->v1->table, SMKTREE_BITS, 3);
+ b1 = get_bits_count(gb) - b1;
+ b2 = get_bits_count(gb);
+ i2 = get_vlc2(gb, ctx->v2->table, SMKTREE_BITS, 3);
+ b2 = get_bits_count(gb) - b2;
+ val = ctx->recode1[i1] | (ctx->recode2[i2] << 8);
+ if(val == ctx->escapes[0]) {
+ ctx->last[0] = hc->current;
+ val = 0;
+ } else if(val == ctx->escapes[1]) {
+ ctx->last[1] = hc->current;
+ val = 0;
+ } else if(val == ctx->escapes[2]) {
+ ctx->last[2] = hc->current;
+ val = 0;
+ }
+
+ hc->values[hc->current++] = val;
+ return 1;
+ } else { //Node
+ int r = 0, t;
+
+ t = hc->current++;
+ r = smacker_decode_bigtree(gb, hc, ctx);
+ if(r < 0)
+ return r;
+ hc->values[t] = SMK_NODE | r;
+ r++;
+ r += smacker_decode_bigtree(gb, hc, ctx);
+ return r;
+ }
+}
+
+/**
+ * Store large tree as FFmpeg's vlc codes
+ */
+static int smacker_decode_header_tree(SmackVContext *smk, GetBitContext *gb, int **recodes, int *last, int size)
+{
+ int res;
+ HuffContext huff;
+ HuffContext tmp1, tmp2;
+ VLC vlc[2];
+ int escapes[3];
+ DBCtx ctx;
+
+ if(size >= UINT_MAX>>4){ // (((size + 3) >> 2) + 3) << 2 must not overflow
+ av_log(smk->avctx, AV_LOG_ERROR, "size too large\n");
+ return -1;
+ }
+
+ tmp1.length = 256;
+ tmp1.maxlength = 0;
+ tmp1.current = 0;
+ tmp1.bits = av_mallocz(256 * 4);
+ tmp1.lengths = av_mallocz(256 * sizeof(int));
+ tmp1.values = av_mallocz(256 * sizeof(int));
+
+ tmp2.length = 256;
+ tmp2.maxlength = 0;
+ tmp2.current = 0;
+ tmp2.bits = av_mallocz(256 * 4);
+ tmp2.lengths = av_mallocz(256 * sizeof(int));
+ tmp2.values = av_mallocz(256 * sizeof(int));
+
+ memset(&vlc[0], 0, sizeof(VLC));
+ memset(&vlc[1], 0, sizeof(VLC));
+
+ if(get_bits1(gb)) {
+ smacker_decode_tree(gb, &tmp1, 0, 0);
+ get_bits1(gb);
+ res = init_vlc(&vlc[0], SMKTREE_BITS, tmp1.length,
+ tmp1.lengths, sizeof(int), sizeof(int),
+ tmp1.bits, sizeof(uint32_t), sizeof(uint32_t), INIT_VLC_LE);
+ if(res < 0) {
+ av_log(smk->avctx, AV_LOG_ERROR, "Cannot build VLC table\n");
+ return -1;
+ }
+ } else {
+ av_log(smk->avctx, AV_LOG_ERROR, "Skipping low bytes tree\n");
+ }
+ if(get_bits1(gb)){
+ smacker_decode_tree(gb, &tmp2, 0, 0);
+ get_bits1(gb);
+ res = init_vlc(&vlc[1], SMKTREE_BITS, tmp2.length,
+ tmp2.lengths, sizeof(int), sizeof(int),
+ tmp2.bits, sizeof(uint32_t), sizeof(uint32_t), INIT_VLC_LE);
+ if(res < 0) {
+ av_log(smk->avctx, AV_LOG_ERROR, "Cannot build VLC table\n");
+ return -1;
+ }
+ } else {
+ av_log(smk->avctx, AV_LOG_ERROR, "Skipping high bytes tree\n");
+ }
+
+ escapes[0] = get_bits(gb, 8);
+ escapes[0] |= get_bits(gb, 8) << 8;
+ escapes[1] = get_bits(gb, 8);
+ escapes[1] |= get_bits(gb, 8) << 8;
+ escapes[2] = get_bits(gb, 8);
+ escapes[2] |= get_bits(gb, 8) << 8;
+
+ last[0] = last[1] = last[2] = -1;
+
+ ctx.escapes[0] = escapes[0];
+ ctx.escapes[1] = escapes[1];
+ ctx.escapes[2] = escapes[2];
+ ctx.v1 = &vlc[0];
+ ctx.v2 = &vlc[1];
+ ctx.recode1 = tmp1.values;
+ ctx.recode2 = tmp2.values;
+ ctx.last = last;
+
+ huff.length = ((size + 3) >> 2) + 3;
+ huff.maxlength = 0;
+ huff.current = 0;
+ huff.values = av_mallocz(huff.length * sizeof(int));
+
+ smacker_decode_bigtree(gb, &huff, &ctx);
+ get_bits1(gb);
+ if(ctx.last[0] == -1) ctx.last[0] = huff.current++;
+ if(ctx.last[1] == -1) ctx.last[1] = huff.current++;
+ if(ctx.last[2] == -1) ctx.last[2] = huff.current++;
+
+ *recodes = huff.values;
+
+ if(vlc[0].table)
+ free_vlc(&vlc[0]);
+ if(vlc[1].table)
+ free_vlc(&vlc[1]);
+ av_free(tmp1.bits);
+ av_free(tmp1.lengths);
+ av_free(tmp1.values);
+ av_free(tmp2.bits);
+ av_free(tmp2.lengths);
+ av_free(tmp2.values);
+
+ return 0;
+}
+
+static int decode_header_trees(SmackVContext *smk) {
+ GetBitContext gb;
+ int mmap_size, mclr_size, full_size, type_size;
+
+ mmap_size = AV_RL32(smk->avctx->extradata);
+ mclr_size = AV_RL32(smk->avctx->extradata + 4);
+ full_size = AV_RL32(smk->avctx->extradata + 8);
+ type_size = AV_RL32(smk->avctx->extradata + 12);
+
+ init_get_bits(&gb, smk->avctx->extradata + 16, (smk->avctx->extradata_size - 16) * 8);
+
+ if(!get_bits1(&gb)) {
+ av_log(smk->avctx, AV_LOG_INFO, "Skipping MMAP tree\n");
+ smk->mmap_tbl = av_malloc(sizeof(int) * 2);
+ smk->mmap_tbl[0] = 0;
+ smk->mmap_last[0] = smk->mmap_last[1] = smk->mmap_last[2] = 1;
+ } else {
+ smacker_decode_header_tree(smk, &gb, &smk->mmap_tbl, smk->mmap_last, mmap_size);
+ }
+ if(!get_bits(&gb, 1)) {
+ av_log(smk->avctx, AV_LOG_INFO, "Skipping MCLR tree\n");
+ smk->mclr_tbl = av_malloc(sizeof(int) * 2);
+ smk->mclr_tbl[0] = 0;
+ smk->mclr_last[0] = smk->mclr_last[1] = smk->mclr_last[2] = 1;
+ } else {
+ smacker_decode_header_tree(smk, &gb, &smk->mclr_tbl, smk->mclr_last, mclr_size);
+ }
+ if(!get_bits(&gb, 1)) {
+ av_log(smk->avctx, AV_LOG_INFO, "Skipping FULL tree\n");
+ smk->full_tbl = av_malloc(sizeof(int) * 2);
+ smk->full_tbl[0] = 0;
+ smk->full_last[0] = smk->full_last[1] = smk->full_last[2] = 1;
+ } else {
+ smacker_decode_header_tree(smk, &gb, &smk->full_tbl, smk->full_last, full_size);
+ }
+ if(!get_bits(&gb, 1)) {
+ av_log(smk->avctx, AV_LOG_INFO, "Skipping TYPE tree\n");
+ smk->type_tbl = av_malloc(sizeof(int) * 2);
+ smk->type_tbl[0] = 0;
+ smk->type_last[0] = smk->type_last[1] = smk->type_last[2] = 1;
+ } else {
+ smacker_decode_header_tree(smk, &gb, &smk->type_tbl, smk->type_last, type_size);
+ }
+
+ return 0;
+}
+
+static av_always_inline void last_reset(int *recode, int *last) {
+ recode[last[0]] = recode[last[1]] = recode[last[2]] = 0;
+}
+
+/* get code and update history */
+static av_always_inline int smk_get_code(GetBitContext *gb, int *recode, int *last) {
+ register int *table = recode;
+ int v, b;
+
+ b = get_bits_count(gb);
+ while(*table & SMK_NODE) {
+ if(get_bits1(gb))
+ table += (*table) & (~SMK_NODE);
+ table++;
+ }
+ v = *table;
+ b = get_bits_count(gb) - b;
+
+ if(v != recode[last[0]]) {
+ recode[last[2]] = recode[last[1]];
+ recode[last[1]] = recode[last[0]];
+ recode[last[0]] = v;
+ }
+ return v;
+}
+
+static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size)
+{
+ SmackVContext * const smk = (SmackVContext *)avctx->priv_data;
+ uint8_t *out;
+ uint32_t *pal;
+ GetBitContext gb;
+ int blocks, blk, bw, bh;
+ int i;
+ int stride;
+
+ if(buf_size == 769)
+ return 0;
+ if(smk->pic.data[0])
+ avctx->release_buffer(avctx, &smk->pic);
+
+ smk->pic.reference = 1;
+ smk->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
+ if(avctx->reget_buffer(avctx, &smk->pic) < 0){
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ return -1;
+ }
+
+ /* make the palette available on the way out */
+ out = buf + 1;
+ pal = (uint32_t*)smk->pic.data[1];
+ smk->pic.palette_has_changed = buf[0] & 1;
+ smk->pic.key_frame = !!(buf[0] & 2);
+ if(smk->pic.key_frame)
+ smk->pic.pict_type = FF_I_TYPE;
+ else
+ smk->pic.pict_type = FF_P_TYPE;
+
+ for(i = 0; i < 256; i++) {
+ int r, g, b;
+ r = *out++;
+ g = *out++;
+ b = *out++;
+ *pal++ = (r << 16) | (g << 8) | b;
+ }
+
+ last_reset(smk->mmap_tbl, smk->mmap_last);
+ last_reset(smk->mclr_tbl, smk->mclr_last);
+ last_reset(smk->full_tbl, smk->full_last);
+ last_reset(smk->type_tbl, smk->type_last);
+ init_get_bits(&gb, buf + 769, (buf_size - 769) * 8);
+
+ blk = 0;
+ bw = avctx->width >> 2;
+ bh = avctx->height >> 2;
+ blocks = bw * bh;
+ out = smk->pic.data[0];
+ stride = smk->pic.linesize[0];
+ while(blk < blocks) {
+ int type, run, mode;
+ uint16_t pix;
+
+ type = smk_get_code(&gb, smk->type_tbl, smk->type_last);
+ run = block_runs[(type >> 2) & 0x3F];
+ switch(type & 3){
+ case SMK_BLK_MONO:
+ while(run-- && blk < blocks){
+ int clr, map;
+ int hi, lo;
+ clr = smk_get_code(&gb, smk->mclr_tbl, smk->mclr_last);
+ map = smk_get_code(&gb, smk->mmap_tbl, smk->mmap_last);
+ out = smk->pic.data[0] + (blk / bw) * (stride * 4) + (blk % bw) * 4;
+ hi = clr >> 8;
+ lo = clr & 0xFF;
+ for(i = 0; i < 4; i++) {
+ if(map & 1) out[0] = hi; else out[0] = lo;
+ if(map & 2) out[1] = hi; else out[1] = lo;
+ if(map & 4) out[2] = hi; else out[2] = lo;
+ if(map & 8) out[3] = hi; else out[3] = lo;
+ map >>= 4;
+ out += stride;
+ }
+ blk++;
+ }
+ break;
+ case SMK_BLK_FULL:
+ mode = 0;
+ if(avctx->codec_tag == MKTAG('S', 'M', 'K', '4')) { // In case of Smacker v4 we have three modes
+ if(get_bits1(&gb)) mode = 1;
+ else if(get_bits1(&gb)) mode = 2;
+ }
+ while(run-- && blk < blocks){
+ out = smk->pic.data[0] + (blk / bw) * (stride * 4) + (blk % bw) * 4;
+ switch(mode){
+ case 0:
+ for(i = 0; i < 4; i++) {
+ pix = smk_get_code(&gb, smk->full_tbl, smk->full_last);
+ out[2] = pix & 0xFF;
+ out[3] = pix >> 8;
+ pix = smk_get_code(&gb, smk->full_tbl, smk->full_last);
+ out[0] = pix & 0xFF;
+ out[1] = pix >> 8;
+ out += stride;
+ }
+ break;
+ case 1:
+ pix = smk_get_code(&gb, smk->full_tbl, smk->full_last);
+ out[0] = out[1] = pix & 0xFF;
+ out[2] = out[3] = pix >> 8;
+ out += stride;
+ out[0] = out[1] = pix & 0xFF;
+ out[2] = out[3] = pix >> 8;
+ out += stride;
+ pix = smk_get_code(&gb, smk->full_tbl, smk->full_last);
+ out[0] = out[1] = pix & 0xFF;
+ out[2] = out[3] = pix >> 8;
+ out += stride;
+ out[0] = out[1] = pix & 0xFF;
+ out[2] = out[3] = pix >> 8;
+ out += stride;
+ break;
+ case 2:
+ for(i = 0; i < 2; i++) {
+ uint16_t pix1, pix2;
+ pix1 = smk_get_code(&gb, smk->full_tbl, smk->full_last);
+ pix2 = smk_get_code(&gb, smk->full_tbl, smk->full_last);
+ out[0] = pix1 & 0xFF; out[1] = pix1 >> 8;
+ out[2] = pix2 & 0xFF; out[3] = pix2 >> 8;
+ out += stride;
+ out[0] = pix1 & 0xFF; out[1] = pix1 >> 8;
+ out[2] = pix2 & 0xFF; out[3] = pix2 >> 8;
+ out += stride;
+ }
+ break;
+ }
+ blk++;
+ }
+ break;
+ case SMK_BLK_SKIP:
+ while(run-- && blk < blocks)
+ blk++;
+ break;
+ case SMK_BLK_FILL:
+ mode = type >> 8;
+ while(run-- && blk < blocks){
+ uint32_t col;
+ out = smk->pic.data[0] + (blk / bw) * (stride * 4) + (blk % bw) * 4;
+ col = mode * 0x01010101;
+ for(i = 0; i < 4; i++) {
+ *((uint32_t*)out) = col;
+ out += stride;
+ }
+ blk++;
+ }
+ break;
+ }
+
+ }
+
+ *data_size = sizeof(AVFrame);
+ *(AVFrame*)data = smk->pic;
+
+ /* always report that the buffer was completely consumed */
+ return buf_size;
+}
+
+
+
+/*
+ *
+ * Init smacker decoder
+ *
+ */
+static int decode_init(AVCodecContext *avctx)
+{
+ SmackVContext * const c = (SmackVContext *)avctx->priv_data;
+
+ c->avctx = avctx;
+ avctx->has_b_frames = 0;
+
+ c->pic.data[0] = NULL;
+
+ if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) {
+ return 1;
+ }
+
+ avctx->pix_fmt = PIX_FMT_PAL8;
+
+
+ /* decode huffman trees from extradata */
+ if(avctx->extradata_size < 16){
+ av_log(avctx, AV_LOG_ERROR, "Extradata missing!\n");
+ return -1;
+ }
+
+ decode_header_trees(c);
+
+
+ return 0;
+}
+
+
+
+/*
+ *
+ * Uninit smacker decoder
+ *
+ */
+static int decode_end(AVCodecContext *avctx)
+{
+ SmackVContext * const smk = (SmackVContext *)avctx->priv_data;
+
+ av_freep(&smk->mmap_tbl);
+ av_freep(&smk->mclr_tbl);
+ av_freep(&smk->full_tbl);
+ av_freep(&smk->type_tbl);
+
+ if (smk->pic.data[0])
+ avctx->release_buffer(avctx, &smk->pic);
+
+ return 0;
+}
+
+
+static int smka_decode_init(AVCodecContext *avctx)
+{
+ return 0;
+}
+
+/**
+ * Decode Smacker audio data
+ */
+static int smka_decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size)
+{
+ GetBitContext gb;
+ HuffContext h[4];
+ VLC vlc[4];
+ int16_t *samples = data;
+ int val;
+ int i, res;
+ int unp_size;
+ int bits, stereo;
+ int pred[2] = {0, 0};
+
+ unp_size = AV_RL32(buf);
+
+ init_get_bits(&gb, buf + 4, (buf_size - 4) * 8);
+
+ if(!get_bits1(&gb)){
+ av_log(avctx, AV_LOG_INFO, "Sound: no data\n");
+ *data_size = 0;
+ return 1;
+ }
+ stereo = get_bits1(&gb);
+ bits = get_bits1(&gb);
+
+ memset(vlc, 0, sizeof(VLC) * 4);
+ memset(h, 0, sizeof(HuffContext) * 4);
+ // Initialize
+ for(i = 0; i < (1 << (bits + stereo)); i++) {
+ h[i].length = 256;
+ h[i].maxlength = 0;
+ h[i].current = 0;
+ h[i].bits = av_mallocz(256 * 4);
+ h[i].lengths = av_mallocz(256 * sizeof(int));
+ h[i].values = av_mallocz(256 * sizeof(int));
+ get_bits1(&gb);
+ smacker_decode_tree(&gb, &h[i], 0, 0);
+ get_bits1(&gb);
+ if(h[i].current > 1) {
+ res = init_vlc(&vlc[i], SMKTREE_BITS, h[i].length,
+ h[i].lengths, sizeof(int), sizeof(int),
+ h[i].bits, sizeof(uint32_t), sizeof(uint32_t), INIT_VLC_LE);
+ if(res < 0) {
+ av_log(avctx, AV_LOG_ERROR, "Cannot build VLC table\n");
+ return -1;
+ }
+ }
+ }
+ if(bits) { //decode 16-bit data
+ for(i = stereo; i >= 0; i--)
+ pred[i] = bswap_16(get_bits(&gb, 16));
+ for(i = 0; i < stereo; i++)
+ *samples++ = pred[i];
+ for(i = 0; i < unp_size / 2; i++) {
+ if(i & stereo) {
+ if(vlc[2].table)
+ res = get_vlc2(&gb, vlc[2].table, SMKTREE_BITS, 3);
+ else
+ res = 0;
+ val = h[2].values[res];
+ if(vlc[3].table)
+ res = get_vlc2(&gb, vlc[3].table, SMKTREE_BITS, 3);
+ else
+ res = 0;
+ val |= h[3].values[res] << 8;
+ pred[1] += (int16_t)val;
+ *samples++ = pred[1];
+ } else {
+ if(vlc[0].table)
+ res = get_vlc2(&gb, vlc[0].table, SMKTREE_BITS, 3);
+ else
+ res = 0;
+ val = h[0].values[res];
+ if(vlc[1].table)
+ res = get_vlc2(&gb, vlc[1].table, SMKTREE_BITS, 3);
+ else
+ res = 0;
+ val |= h[1].values[res] << 8;
+ pred[0] += val;
+ *samples++ = pred[0];
+ }
+ }
+ } else { //8-bit data
+ for(i = stereo; i >= 0; i--)
+ pred[i] = get_bits(&gb, 8);
+ for(i = 0; i < stereo; i++)
+ *samples++ = (pred[i] - 0x80) << 8;
+ for(i = 0; i < unp_size; i++) {
+ if(i & stereo){
+ if(vlc[1].table)
+ res = get_vlc2(&gb, vlc[1].table, SMKTREE_BITS, 3);
+ else
+ res = 0;
+ pred[1] += (int8_t)h[1].values[res];
+ *samples++ = (pred[1] - 0x80) << 8;
+ } else {
+ if(vlc[0].table)
+ res = get_vlc2(&gb, vlc[0].table, SMKTREE_BITS, 3);
+ else
+ res = 0;
+ pred[0] += (int8_t)h[0].values[res];
+ *samples++ = (pred[0] - 0x80) << 8;
+ }
+ }
+ unp_size *= 2;
+ }
+
+ for(i = 0; i < 4; i++) {
+ if(vlc[i].table)
+ free_vlc(&vlc[i]);
+ if(h[i].bits)
+ av_free(h[i].bits);
+ if(h[i].lengths)
+ av_free(h[i].lengths);
+ if(h[i].values)
+ av_free(h[i].values);
+ }
+
+ *data_size = unp_size;
+ return buf_size;
+}
+
+AVCodec smacker_decoder = {
+ "smackvid",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_SMACKVIDEO,
+ sizeof(SmackVContext),
+ decode_init,
+ NULL,
+ decode_end,
+ decode_frame
+};
+
+AVCodec smackaud_decoder = {
+ "smackaud",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_SMACKAUDIO,
+ 0,
+ smka_decode_init,
+ NULL,
+ NULL,
+ smka_decode_frame
+};
+
diff --git a/src/libffmpeg/libavcodec/smc.c b/contrib/ffmpeg/libavcodec/smc.c
index 349e5f81c..349e5f81c 100644
--- a/src/libffmpeg/libavcodec/smc.c
+++ b/contrib/ffmpeg/libavcodec/smc.c
diff --git a/contrib/ffmpeg/libavcodec/snow.c b/contrib/ffmpeg/libavcodec/snow.c
new file mode 100644
index 000000000..dc50941fa
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/snow.c
@@ -0,0 +1,4706 @@
+/*
+ * Copyright (C) 2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avcodec.h"
+#include "common.h"
+#include "dsputil.h"
+#include "snow.h"
+
+#include "rangecoder.h"
+
+#include "mpegvideo.h"
+
+#undef NDEBUG
+#include <assert.h>
+
+static const int8_t quant3[256]={
+ 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 0,
+};
+static const int8_t quant3b[256]={
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+-1,-1,-1,-1,-1,-1,-1,-1,-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 int8_t quant3bA[256]={
+ 0, 0, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1,
+ 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1,
+ 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1,
+ 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1,
+ 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1,
+ 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1,
+ 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1,
+ 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1,
+ 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1,
+ 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1,
+ 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1,
+ 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1,
+ 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1,
+ 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1,
+ 1,-1, 1,-1, 1,-1, 1,-1, 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 int8_t quant5[256]={
+ 0, 1, 1, 1, 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,-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,-1,-1,-1,
+};
+static const int8_t quant7[256]={
+ 0, 1, 1, 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, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,
+-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,
+-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,
+-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,
+-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,
+-3,-3,-3,-3,-3,-3,-3,-3,-3,-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,-1,-1,
+};
+static const int8_t quant9[256]={
+ 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 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,-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,-3,-3,-3,-3,
+-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-2,-2,-2,-2,-1,-1,
+};
+static const int8_t quant11[256]={
+ 0, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
+-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
+-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
+-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
+-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
+-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-4,-4,
+-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,
+-4,-4,-4,-4,-4,-3,-3,-3,-3,-3,-3,-3,-2,-2,-2,-1,
+};
+static const int8_t quant13[256]={
+ 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,
+-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,
+-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,
+-6,-6,-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,-5,
+-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
+-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
+-4,-4,-4,-4,-4,-4,-4,-4,-4,-3,-3,-3,-3,-2,-2,-1,
+};
+
+#if 0 //64*cubic
+static const uint8_t obmc32[1024]={
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
+ 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0,
+ 0, 0, 1, 1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 7, 8, 8, 8, 8, 7, 7, 6, 6, 5, 4, 4, 3, 2, 2, 1, 1, 0, 0,
+ 0, 0, 1, 2, 2, 3, 4, 6, 7, 8, 9,10,11,12,12,12,12,12,12,11,10, 9, 8, 7, 6, 4, 3, 2, 2, 1, 0, 0,
+ 0, 1, 1, 2, 3, 5, 6, 8,10,11,13,14,15,16,17,18,18,17,16,15,14,13,11,10, 8, 6, 5, 3, 2, 1, 1, 0,
+ 0, 1, 1, 3, 4, 6, 8,10,13,15,17,19,20,22,22,23,23,22,22,20,19,17,15,13,10, 8, 6, 4, 3, 1, 1, 0,
+ 0, 1, 2, 4, 6, 8,10,13,16,19,21,23,25,27,28,29,29,28,27,25,23,21,19,16,13,10, 8, 6, 4, 2, 1, 0,
+ 0, 1, 2, 4, 7,10,13,16,19,22,25,28,31,33,34,35,35,34,33,31,28,25,22,19,16,13,10, 7, 4, 2, 1, 0,
+ 0, 1, 3, 5, 8,11,15,19,22,26,30,33,36,38,40,41,41,40,38,36,33,30,26,22,19,15,11, 8, 5, 3, 1, 0,
+ 0, 1, 3, 6, 9,12,17,21,25,30,34,38,41,44,45,46,46,45,44,41,38,34,30,25,21,17,12, 9, 6, 3, 1, 0,
+ 0, 1, 3, 6,10,14,19,23,28,33,38,42,45,48,51,52,52,51,48,45,42,38,33,28,23,19,14,10, 6, 3, 1, 0,
+ 0, 1, 4, 7,11,15,20,25,31,36,41,45,49,52,55,56,56,55,52,49,45,41,36,31,25,20,15,11, 7, 4, 1, 0,
+ 0, 2, 4, 7,12,16,22,27,33,38,44,48,52,56,58,60,60,58,56,52,48,44,38,33,27,22,16,12, 7, 4, 2, 0,
+ 0, 1, 4, 8,12,17,22,28,34,40,45,51,55,58,61,62,62,61,58,55,51,45,40,34,28,22,17,12, 8, 4, 1, 0,
+ 0, 2, 4, 8,12,18,23,29,35,41,46,52,56,60,62,64,64,62,60,56,52,46,41,35,29,23,18,12, 8, 4, 2, 0,
+ 0, 2, 4, 8,12,18,23,29,35,41,46,52,56,60,62,64,64,62,60,56,52,46,41,35,29,23,18,12, 8, 4, 2, 0,
+ 0, 1, 4, 8,12,17,22,28,34,40,45,51,55,58,61,62,62,61,58,55,51,45,40,34,28,22,17,12, 8, 4, 1, 0,
+ 0, 2, 4, 7,12,16,22,27,33,38,44,48,52,56,58,60,60,58,56,52,48,44,38,33,27,22,16,12, 7, 4, 2, 0,
+ 0, 1, 4, 7,11,15,20,25,31,36,41,45,49,52,55,56,56,55,52,49,45,41,36,31,25,20,15,11, 7, 4, 1, 0,
+ 0, 1, 3, 6,10,14,19,23,28,33,38,42,45,48,51,52,52,51,48,45,42,38,33,28,23,19,14,10, 6, 3, 1, 0,
+ 0, 1, 3, 6, 9,12,17,21,25,30,34,38,41,44,45,46,46,45,44,41,38,34,30,25,21,17,12, 9, 6, 3, 1, 0,
+ 0, 1, 3, 5, 8,11,15,19,22,26,30,33,36,38,40,41,41,40,38,36,33,30,26,22,19,15,11, 8, 5, 3, 1, 0,
+ 0, 1, 2, 4, 7,10,13,16,19,22,25,28,31,33,34,35,35,34,33,31,28,25,22,19,16,13,10, 7, 4, 2, 1, 0,
+ 0, 1, 2, 4, 6, 8,10,13,16,19,21,23,25,27,28,29,29,28,27,25,23,21,19,16,13,10, 8, 6, 4, 2, 1, 0,
+ 0, 1, 1, 3, 4, 6, 8,10,13,15,17,19,20,22,22,23,23,22,22,20,19,17,15,13,10, 8, 6, 4, 3, 1, 1, 0,
+ 0, 1, 1, 2, 3, 5, 6, 8,10,11,13,14,15,16,17,18,18,17,16,15,14,13,11,10, 8, 6, 5, 3, 2, 1, 1, 0,
+ 0, 0, 1, 2, 2, 3, 4, 6, 7, 8, 9,10,11,12,12,12,12,12,12,11,10, 9, 8, 7, 6, 4, 3, 2, 2, 1, 0, 0,
+ 0, 0, 1, 1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 7, 8, 8, 8, 8, 7, 7, 6, 6, 5, 4, 4, 3, 2, 2, 1, 1, 0, 0,
+ 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0,
+ 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+//error:0.000022
+};
+static const uint8_t obmc16[256]={
+ 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
+ 0, 1, 1, 2, 4, 5, 5, 6, 6, 5, 5, 4, 2, 1, 1, 0,
+ 0, 1, 4, 6, 9,11,13,15,15,13,11, 9, 6, 4, 1, 0,
+ 0, 2, 6,11,15,20,24,26,26,24,20,15,11, 6, 2, 0,
+ 0, 4, 9,15,23,29,34,38,38,34,29,23,15, 9, 4, 0,
+ 0, 5,11,20,29,38,45,49,49,45,38,29,20,11, 5, 0,
+ 1, 5,13,24,34,45,53,57,57,53,45,34,24,13, 5, 1,
+ 1, 6,15,26,38,49,57,62,62,57,49,38,26,15, 6, 1,
+ 1, 6,15,26,38,49,57,62,62,57,49,38,26,15, 6, 1,
+ 1, 5,13,24,34,45,53,57,57,53,45,34,24,13, 5, 1,
+ 0, 5,11,20,29,38,45,49,49,45,38,29,20,11, 5, 0,
+ 0, 4, 9,15,23,29,34,38,38,34,29,23,15, 9, 4, 0,
+ 0, 2, 6,11,15,20,24,26,26,24,20,15,11, 6, 2, 0,
+ 0, 1, 4, 6, 9,11,13,15,15,13,11, 9, 6, 4, 1, 0,
+ 0, 1, 1, 2, 4, 5, 5, 6, 6, 5, 5, 4, 2, 1, 1, 0,
+ 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
+//error:0.000033
+};
+#elif 1 // 64*linear
+static const uint8_t obmc32[1024]={
+ 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0,
+ 0, 4, 4, 4, 8, 8, 8, 12, 12, 16, 16, 16, 20, 20, 20, 24, 24, 20, 20, 20, 16, 16, 16, 12, 12, 8, 8, 8, 4, 4, 4, 0,
+ 0, 4, 8, 8, 12, 12, 16, 20, 20, 24, 28, 28, 32, 32, 36, 40, 40, 36, 32, 32, 28, 28, 24, 20, 20, 16, 12, 12, 8, 8, 4, 0,
+ 0, 4, 8, 12, 16, 20, 24, 28, 28, 32, 36, 40, 44, 48, 52, 56, 56, 52, 48, 44, 40, 36, 32, 28, 28, 24, 20, 16, 12, 8, 4, 0,
+ 4, 8, 12, 16, 20, 24, 28, 32, 40, 44, 48, 52, 56, 60, 64, 68, 68, 64, 60, 56, 52, 48, 44, 40, 32, 28, 24, 20, 16, 12, 8, 4,
+ 4, 8, 12, 20, 24, 32, 36, 40, 48, 52, 56, 64, 68, 76, 80, 84, 84, 80, 76, 68, 64, 56, 52, 48, 40, 36, 32, 24, 20, 12, 8, 4,
+ 4, 8, 16, 24, 28, 36, 44, 48, 56, 60, 68, 76, 80, 88, 96,100,100, 96, 88, 80, 76, 68, 60, 56, 48, 44, 36, 28, 24, 16, 8, 4,
+ 4, 12, 20, 28, 32, 40, 48, 56, 64, 72, 80, 88, 92,100,108,116,116,108,100, 92, 88, 80, 72, 64, 56, 48, 40, 32, 28, 20, 12, 4,
+ 4, 12, 20, 28, 40, 48, 56, 64, 72, 80, 88, 96,108,116,124,132,132,124,116,108, 96, 88, 80, 72, 64, 56, 48, 40, 28, 20, 12, 4,
+ 4, 16, 24, 32, 44, 52, 60, 72, 80, 92,100,108,120,128,136,148,148,136,128,120,108,100, 92, 80, 72, 60, 52, 44, 32, 24, 16, 4,
+ 4, 16, 28, 36, 48, 56, 68, 80, 88,100,112,120,132,140,152,164,164,152,140,132,120,112,100, 88, 80, 68, 56, 48, 36, 28, 16, 4,
+ 4, 16, 28, 40, 52, 64, 76, 88, 96,108,120,132,144,156,168,180,180,168,156,144,132,120,108, 96, 88, 76, 64, 52, 40, 28, 16, 4,
+ 8, 20, 32, 44, 56, 68, 80, 92,108,120,132,144,156,168,180,192,192,180,168,156,144,132,120,108, 92, 80, 68, 56, 44, 32, 20, 8,
+ 8, 20, 32, 48, 60, 76, 88,100,116,128,140,156,168,184,196,208,208,196,184,168,156,140,128,116,100, 88, 76, 60, 48, 32, 20, 8,
+ 8, 20, 36, 52, 64, 80, 96,108,124,136,152,168,180,196,212,224,224,212,196,180,168,152,136,124,108, 96, 80, 64, 52, 36, 20, 8,
+ 8, 24, 40, 56, 68, 84,100,116,132,148,164,180,192,208,224,240,240,224,208,192,180,164,148,132,116,100, 84, 68, 56, 40, 24, 8,
+ 8, 24, 40, 56, 68, 84,100,116,132,148,164,180,192,208,224,240,240,224,208,192,180,164,148,132,116,100, 84, 68, 56, 40, 24, 8,
+ 8, 20, 36, 52, 64, 80, 96,108,124,136,152,168,180,196,212,224,224,212,196,180,168,152,136,124,108, 96, 80, 64, 52, 36, 20, 8,
+ 8, 20, 32, 48, 60, 76, 88,100,116,128,140,156,168,184,196,208,208,196,184,168,156,140,128,116,100, 88, 76, 60, 48, 32, 20, 8,
+ 8, 20, 32, 44, 56, 68, 80, 92,108,120,132,144,156,168,180,192,192,180,168,156,144,132,120,108, 92, 80, 68, 56, 44, 32, 20, 8,
+ 4, 16, 28, 40, 52, 64, 76, 88, 96,108,120,132,144,156,168,180,180,168,156,144,132,120,108, 96, 88, 76, 64, 52, 40, 28, 16, 4,
+ 4, 16, 28, 36, 48, 56, 68, 80, 88,100,112,120,132,140,152,164,164,152,140,132,120,112,100, 88, 80, 68, 56, 48, 36, 28, 16, 4,
+ 4, 16, 24, 32, 44, 52, 60, 72, 80, 92,100,108,120,128,136,148,148,136,128,120,108,100, 92, 80, 72, 60, 52, 44, 32, 24, 16, 4,
+ 4, 12, 20, 28, 40, 48, 56, 64, 72, 80, 88, 96,108,116,124,132,132,124,116,108, 96, 88, 80, 72, 64, 56, 48, 40, 28, 20, 12, 4,
+ 4, 12, 20, 28, 32, 40, 48, 56, 64, 72, 80, 88, 92,100,108,116,116,108,100, 92, 88, 80, 72, 64, 56, 48, 40, 32, 28, 20, 12, 4,
+ 4, 8, 16, 24, 28, 36, 44, 48, 56, 60, 68, 76, 80, 88, 96,100,100, 96, 88, 80, 76, 68, 60, 56, 48, 44, 36, 28, 24, 16, 8, 4,
+ 4, 8, 12, 20, 24, 32, 36, 40, 48, 52, 56, 64, 68, 76, 80, 84, 84, 80, 76, 68, 64, 56, 52, 48, 40, 36, 32, 24, 20, 12, 8, 4,
+ 4, 8, 12, 16, 20, 24, 28, 32, 40, 44, 48, 52, 56, 60, 64, 68, 68, 64, 60, 56, 52, 48, 44, 40, 32, 28, 24, 20, 16, 12, 8, 4,
+ 0, 4, 8, 12, 16, 20, 24, 28, 28, 32, 36, 40, 44, 48, 52, 56, 56, 52, 48, 44, 40, 36, 32, 28, 28, 24, 20, 16, 12, 8, 4, 0,
+ 0, 4, 8, 8, 12, 12, 16, 20, 20, 24, 28, 28, 32, 32, 36, 40, 40, 36, 32, 32, 28, 28, 24, 20, 20, 16, 12, 12, 8, 8, 4, 0,
+ 0, 4, 4, 4, 8, 8, 8, 12, 12, 16, 16, 16, 20, 20, 20, 24, 24, 20, 20, 20, 16, 16, 16, 12, 12, 8, 8, 8, 4, 4, 4, 0,
+ 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0,
+ //error:0.000020
+};
+static const uint8_t obmc16[256]={
+ 0, 4, 4, 8, 8, 12, 12, 16, 16, 12, 12, 8, 8, 4, 4, 0,
+ 4, 8, 16, 20, 28, 32, 40, 44, 44, 40, 32, 28, 20, 16, 8, 4,
+ 4, 16, 24, 36, 44, 56, 64, 76, 76, 64, 56, 44, 36, 24, 16, 4,
+ 8, 20, 36, 48, 64, 76, 92,104,104, 92, 76, 64, 48, 36, 20, 8,
+ 8, 28, 44, 64, 80,100,116,136,136,116,100, 80, 64, 44, 28, 8,
+ 12, 32, 56, 76,100,120,144,164,164,144,120,100, 76, 56, 32, 12,
+ 12, 40, 64, 92,116,144,168,196,196,168,144,116, 92, 64, 40, 12,
+ 16, 44, 76,104,136,164,196,224,224,196,164,136,104, 76, 44, 16,
+ 16, 44, 76,104,136,164,196,224,224,196,164,136,104, 76, 44, 16,
+ 12, 40, 64, 92,116,144,168,196,196,168,144,116, 92, 64, 40, 12,
+ 12, 32, 56, 76,100,120,144,164,164,144,120,100, 76, 56, 32, 12,
+ 8, 28, 44, 64, 80,100,116,136,136,116,100, 80, 64, 44, 28, 8,
+ 8, 20, 36, 48, 64, 76, 92,104,104, 92, 76, 64, 48, 36, 20, 8,
+ 4, 16, 24, 36, 44, 56, 64, 76, 76, 64, 56, 44, 36, 24, 16, 4,
+ 4, 8, 16, 20, 28, 32, 40, 44, 44, 40, 32, 28, 20, 16, 8, 4,
+ 0, 4, 4, 8, 8, 12, 12, 16, 16, 12, 12, 8, 8, 4, 4, 0,
+//error:0.000015
+};
+#else //64*cos
+static const uint8_t obmc32[1024]={
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0,
+ 0, 0, 1, 1, 1, 2, 2, 3, 4, 5, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 5, 5, 4, 3, 2, 2, 1, 1, 1, 0, 0,
+ 0, 0, 1, 1, 2, 3, 4, 5, 6, 7, 9,10,11,11,12,12,12,12,11,11,10, 9, 7, 6, 5, 4, 3, 2, 1, 1, 0, 0,
+ 0, 0, 1, 2, 3, 5, 6, 8, 9,11,12,14,15,16,17,17,17,17,16,15,14,12,11, 9, 8, 6, 5, 3, 2, 1, 0, 0,
+ 0, 1, 1, 2, 4, 6, 8,10,12,15,17,19,20,21,22,23,23,22,21,20,19,17,15,12,10, 8, 6, 4, 2, 1, 1, 0,
+ 0, 1, 2, 3, 5, 8,10,13,16,19,21,24,26,27,28,29,29,28,27,26,24,21,19,16,13,10, 8, 5, 3, 2, 1, 0,
+ 0, 1, 2, 4, 6, 9,12,16,19,23,26,29,31,33,34,35,35,34,33,31,29,26,23,19,16,12, 9, 6, 4, 2, 1, 0,
+ 0, 1, 3, 5, 7,11,15,19,23,26,30,34,37,39,40,41,41,40,39,37,34,30,26,23,19,15,11, 7, 5, 3, 1, 0,
+ 0, 1, 3, 5, 9,12,17,21,26,30,35,38,42,44,46,47,47,46,44,42,38,35,30,26,21,17,12, 9, 5, 3, 1, 0,
+ 0, 1, 3, 6, 9,14,19,24,29,34,38,43,46,49,51,52,52,51,49,46,43,38,34,29,24,19,14, 9, 6, 3, 1, 0,
+ 0, 1, 3, 6,11,15,20,26,31,37,42,46,50,53,56,57,57,56,53,50,46,42,37,31,26,20,15,11, 6, 3, 1, 0,
+ 0, 1, 3, 7,11,16,21,27,33,39,44,49,53,57,59,60,60,59,57,53,49,44,39,33,27,21,16,11, 7, 3, 1, 0,
+ 0, 1, 4, 7,12,17,22,28,34,40,46,51,56,59,61,63,63,61,59,56,51,46,40,34,28,22,17,12, 7, 4, 1, 0,
+ 0, 1, 4, 7,12,17,23,29,35,41,47,52,57,60,63,64,64,63,60,57,52,47,41,35,29,23,17,12, 7, 4, 1, 0,
+ 0, 1, 4, 7,12,17,23,29,35,41,47,52,57,60,63,64,64,63,60,57,52,47,41,35,29,23,17,12, 7, 4, 1, 0,
+ 0, 1, 4, 7,12,17,22,28,34,40,46,51,56,59,61,63,63,61,59,56,51,46,40,34,28,22,17,12, 7, 4, 1, 0,
+ 0, 1, 3, 7,11,16,21,27,33,39,44,49,53,57,59,60,60,59,57,53,49,44,39,33,27,21,16,11, 7, 3, 1, 0,
+ 0, 1, 3, 6,11,15,20,26,31,37,42,46,50,53,56,57,57,56,53,50,46,42,37,31,26,20,15,11, 6, 3, 1, 0,
+ 0, 1, 3, 6, 9,14,19,24,29,34,38,43,46,49,51,52,52,51,49,46,43,38,34,29,24,19,14, 9, 6, 3, 1, 0,
+ 0, 1, 3, 5, 9,12,17,21,26,30,35,38,42,44,46,47,47,46,44,42,38,35,30,26,21,17,12, 9, 5, 3, 1, 0,
+ 0, 1, 3, 5, 7,11,15,19,23,26,30,34,37,39,40,41,41,40,39,37,34,30,26,23,19,15,11, 7, 5, 3, 1, 0,
+ 0, 1, 2, 4, 6, 9,12,16,19,23,26,29,31,33,34,35,35,34,33,31,29,26,23,19,16,12, 9, 6, 4, 2, 1, 0,
+ 0, 1, 2, 3, 5, 8,10,13,16,19,21,24,26,27,28,29,29,28,27,26,24,21,19,16,13,10, 8, 5, 3, 2, 1, 0,
+ 0, 1, 1, 2, 4, 6, 8,10,12,15,17,19,20,21,22,23,23,22,21,20,19,17,15,12,10, 8, 6, 4, 2, 1, 1, 0,
+ 0, 0, 1, 2, 3, 5, 6, 8, 9,11,12,14,15,16,17,17,17,17,16,15,14,12,11, 9, 8, 6, 5, 3, 2, 1, 0, 0,
+ 0, 0, 1, 1, 2, 3, 4, 5, 6, 7, 9,10,11,11,12,12,12,12,11,11,10, 9, 7, 6, 5, 4, 3, 2, 1, 1, 0, 0,
+ 0, 0, 1, 1, 1, 2, 2, 3, 4, 5, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 5, 5, 4, 3, 2, 2, 1, 1, 1, 0, 0,
+ 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+//error:0.000022
+};
+static const uint8_t obmc16[256]={
+ 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
+ 0, 0, 1, 2, 3, 4, 5, 5, 5, 5, 4, 3, 2, 1, 0, 0,
+ 0, 1, 3, 6, 8,11,13,14,14,13,11, 8, 6, 3, 1, 0,
+ 0, 2, 6,10,15,20,24,26,26,24,20,15,10, 6, 2, 0,
+ 0, 3, 8,16,23,30,35,38,38,35,30,23,16, 8, 3, 0,
+ 1, 4,11,20,30,39,46,49,49,46,39,30,20,11, 4, 1,
+ 1, 5,13,24,35,46,54,58,58,54,46,35,24,13, 5, 1,
+ 0, 5,14,26,38,49,58,63,63,58,49,38,26,14, 5, 0,
+ 0, 5,14,26,38,49,58,63,63,58,49,38,26,14, 5, 0,
+ 1, 5,13,24,35,46,54,58,58,54,46,35,24,13, 5, 1,
+ 1, 4,11,20,30,39,46,49,49,46,39,30,20,11, 4, 1,
+ 0, 3, 8,16,23,30,35,38,38,35,30,23,16, 8, 3, 0,
+ 0, 2, 6,10,15,20,24,26,26,24,20,15,10, 6, 2, 0,
+ 0, 1, 3, 6, 8,11,13,14,14,13,11, 8, 6, 3, 1, 0,
+ 0, 0, 1, 2, 3, 4, 5, 5, 5, 5, 4, 3, 2, 1, 0, 0,
+ 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
+//error:0.000022
+};
+#endif
+
+//linear *64
+static const uint8_t obmc8[64]={
+ 4, 12, 20, 28, 28, 20, 12, 4,
+ 12, 36, 60, 84, 84, 60, 36, 12,
+ 20, 60,100,140,140,100, 60, 20,
+ 28, 84,140,196,196,140, 84, 28,
+ 28, 84,140,196,196,140, 84, 28,
+ 20, 60,100,140,140,100, 60, 20,
+ 12, 36, 60, 84, 84, 60, 36, 12,
+ 4, 12, 20, 28, 28, 20, 12, 4,
+//error:0.000000
+};
+
+//linear *64
+static const uint8_t obmc4[16]={
+ 16, 48, 48, 16,
+ 48,144,144, 48,
+ 48,144,144, 48,
+ 16, 48, 48, 16,
+//error:0.000000
+};
+
+static const uint8_t *obmc_tab[4]={
+ obmc32, obmc16, obmc8, obmc4
+};
+
+static int scale_mv_ref[MAX_REF_FRAMES][MAX_REF_FRAMES];
+
+typedef struct BlockNode{
+ int16_t mx;
+ int16_t my;
+ uint8_t ref;
+ uint8_t color[3];
+ uint8_t type;
+//#define TYPE_SPLIT 1
+#define BLOCK_INTRA 1
+#define BLOCK_OPT 2
+//#define TYPE_NOCOLOR 4
+ uint8_t level; //FIXME merge into type?
+}BlockNode;
+
+static const BlockNode null_block= { //FIXME add border maybe
+ .color= {128,128,128},
+ .mx= 0,
+ .my= 0,
+ .ref= 0,
+ .type= 0,
+ .level= 0,
+};
+
+#define LOG2_MB_SIZE 4
+#define MB_SIZE (1<<LOG2_MB_SIZE)
+
+typedef struct x_and_coeff{
+ int16_t x;
+ uint16_t coeff;
+} x_and_coeff;
+
+typedef struct SubBand{
+ int level;
+ int stride;
+ int width;
+ int height;
+ int qlog; ///< log(qscale)/log[2^(1/6)]
+ DWTELEM *buf;
+ int buf_x_offset;
+ int buf_y_offset;
+ int stride_line; ///< Stride measured in lines, not pixels.
+ x_and_coeff * x_coeff;
+ struct SubBand *parent;
+ uint8_t state[/*7*2*/ 7 + 512][32];
+}SubBand;
+
+typedef struct Plane{
+ int width;
+ int height;
+ SubBand band[MAX_DECOMPOSITIONS][4];
+}Plane;
+
+typedef struct SnowContext{
+// MpegEncContext m; // needed for motion estimation, should not be used for anything else, the idea is to make the motion estimation eventually independent of MpegEncContext, so this will be removed then (FIXME/XXX)
+
+ AVCodecContext *avctx;
+ RangeCoder c;
+ DSPContext dsp;
+ AVFrame new_picture;
+ AVFrame input_picture; ///< new_picture with the internal linesizes
+ AVFrame current_picture;
+ AVFrame last_picture[MAX_REF_FRAMES];
+ AVFrame mconly_picture;
+// uint8_t q_context[16];
+ uint8_t header_state[32];
+ uint8_t block_state[128 + 32*128];
+ int keyframe;
+ int always_reset;
+ int version;
+ int spatial_decomposition_type;
+ int last_spatial_decomposition_type;
+ int temporal_decomposition_type;
+ int spatial_decomposition_count;
+ int temporal_decomposition_count;
+ int max_ref_frames;
+ int ref_frames;
+ int16_t (*ref_mvs[MAX_REF_FRAMES])[2];
+ uint32_t *ref_scores[MAX_REF_FRAMES];
+ DWTELEM *spatial_dwt_buffer;
+ int colorspace_type;
+ int chroma_h_shift;
+ int chroma_v_shift;
+ int spatial_scalability;
+ int qlog;
+ int last_qlog;
+ int lambda;
+ int lambda2;
+ int pass1_rc;
+ int mv_scale;
+ int last_mv_scale;
+ int qbias;
+ int last_qbias;
+#define QBIAS_SHIFT 3
+ int b_width;
+ int b_height;
+ int block_max_depth;
+ int last_block_max_depth;
+ Plane plane[MAX_PLANES];
+ BlockNode *block;
+#define ME_CACHE_SIZE 1024
+ int me_cache[ME_CACHE_SIZE];
+ int me_cache_generation;
+ slice_buffer sb;
+
+ MpegEncContext m; // needed for motion estimation, should not be used for anything else, the idea is to make the motion estimation eventually independent of MpegEncContext, so this will be removed then (FIXME/XXX)
+}SnowContext;
+
+typedef struct {
+ DWTELEM *b0;
+ DWTELEM *b1;
+ DWTELEM *b2;
+ DWTELEM *b3;
+ int y;
+} dwt_compose_t;
+
+#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, DWTELEM * 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 = (DWTELEM * *) av_mallocz (sizeof(DWTELEM *) * line_count);
+ buf->data_stack = (DWTELEM * *) av_malloc (sizeof(DWTELEM *) * max_allocated_lines);
+
+ for (i = 0; i < max_allocated_lines; i++)
+ {
+ buf->data_stack[i] = (DWTELEM *) av_malloc (sizeof(DWTELEM) * line_width);
+ }
+
+ buf->data_stack_top = max_allocated_lines - 1;
+}
+
+static DWTELEM * slice_buffer_load_line(slice_buffer * buf, int line)
+{
+ int offset;
+ DWTELEM * buffer;
+
+// av_log(NULL, AV_LOG_DEBUG, "Cache hit: %d\n", line);
+
+ assert(buf->data_stack_top >= 0);
+// assert(!buf->line[line]);
+ if (buf->line[line])
+ return buf->line[line];
+
+ offset = buf->line_width * line;
+ buffer = buf->data_stack[buf->data_stack_top];
+ buf->data_stack_top--;
+ buf->line[line] = buffer;
+
+// av_log(NULL, AV_LOG_DEBUG, "slice_buffer_load_line: line: %d remaining: %d\n", line, buf->data_stack_top + 1);
+
+ return buffer;
+}
+
+static void slice_buffer_release(slice_buffer * buf, int line)
+{
+ int offset;
+ DWTELEM * buffer;
+
+ assert(line >= 0 && line < buf->line_count);
+ assert(buf->line[line]);
+
+ offset = buf->line_width * line;
+ buffer = buf->line[line];
+ buf->data_stack_top++;
+ buf->data_stack[buf->data_stack_top] = buffer;
+ buf->line[line] = NULL;
+
+// av_log(NULL, AV_LOG_DEBUG, "slice_buffer_release: line: %d remaining: %d\n", line, buf->data_stack_top + 1);
+}
+
+static void slice_buffer_flush(slice_buffer * buf)
+{
+ int i;
+ for (i = 0; i < buf->line_count; i++)
+ {
+ if (buf->line[i])
+ {
+// av_log(NULL, AV_LOG_DEBUG, "slice_buffer_flush: line: %d \n", 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--)
+ {
+ assert(buf->data_stack[i]);
+ av_freep(&buf->data_stack[i]);
+ }
+ assert(buf->data_stack);
+ av_freep(&buf->data_stack);
+ assert(buf->line);
+ av_freep(&buf->line);
+}
+
+#ifdef __sgi
+// Avoid a name clash on SGI IRIX
+#undef qexp
+#endif
+#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;
+
+ if(v){
+ const int a= FFABS(v);
+ const int e= av_log2(a);
+#if 1
+ const int el= FFMIN(e, 10);
+ put_rac(c, state+0, 0);
+
+ for(i=0; i<el; i++){
+ put_rac(c, state+1+i, 1); //1..10
+ }
+ for(; i<e; i++){
+ put_rac(c, state+1+9, 1); //1..10
+ }
+ put_rac(c, state+1+FFMIN(i,9), 0);
+
+ for(i=e-1; i>=el; i--){
+ put_rac(c, state+22+9, (a>>i)&1); //22..31
+ }
+ for(; i>=0; i--){
+ put_rac(c, state+22+i, (a>>i)&1); //22..31
+ }
+
+ if(is_signed)
+ put_rac(c, state+11 + el, v < 0); //11..21
+#else
+
+ put_rac(c, state+0, 0);
+ if(e<=9){
+ for(i=0; i<e; i++){
+ put_rac(c, state+1+i, 1); //1..10
+ }
+ put_rac(c, state+1+i, 0);
+
+ for(i=e-1; i>=0; i--){
+ put_rac(c, state+22+i, (a>>i)&1); //22..31
+ }
+
+ if(is_signed)
+ put_rac(c, state+11 + e, v < 0); //11..21
+ }else{
+ for(i=0; i<e; i++){
+ put_rac(c, state+1+FFMIN(i,9), 1); //1..10
+ }
+ put_rac(c, state+1+FFMIN(i,9), 0);
+
+ for(i=e-1; i>=0; i--){
+ put_rac(c, state+22+FFMIN(i,9), (a>>i)&1); //22..31
+ }
+
+ if(is_signed)
+ put_rac(c, state+11 + FFMIN(e,10), v < 0); //11..21
+ }
+#endif
+ }else{
+ put_rac(c, state+0, 1);
+ }
+}
+
+static inline int get_symbol(RangeCoder *c, uint8_t *state, int is_signed){
+ if(get_rac(c, state+0))
+ return 0;
+ else{
+ int i, e, a;
+ e= 0;
+ while(get_rac(c, state+1 + FFMIN(e,9))){ //1..10
+ e++;
+ }
+
+ a= 1;
+ for(i=e-1; i>=0; i--){
+ a += a + get_rac(c, state+22 + FFMIN(i,9)); //22..31
+ }
+
+ if(is_signed && get_rac(c, state+11 + FFMIN(e,10))) //11..21
+ return -a;
+ else
+ return a;
+ }
+}
+
+static inline void put_symbol2(RangeCoder *c, uint8_t *state, int v, int log2){
+ int i;
+ int r= log2>=0 ? 1<<log2 : 1;
+
+ assert(v>=0);
+ assert(log2>=-4);
+
+ while(v >= r){
+ put_rac(c, state+4+log2, 1);
+ v -= r;
+ log2++;
+ if(log2>0) r+=r;
+ }
+ put_rac(c, state+4+log2, 0);
+
+ for(i=log2-1; i>=0; i--){
+ put_rac(c, state+31-i, (v>>i)&1);
+ }
+}
+
+static inline int get_symbol2(RangeCoder *c, uint8_t *state, int log2){
+ int i;
+ int r= log2>=0 ? 1<<log2 : 1;
+ int v=0;
+
+ assert(log2>=-4);
+
+ while(get_rac(c, state+4+log2)){
+ v+= r;
+ log2++;
+ if(log2>0) r+=r;
+ }
+
+ for(i=log2-1; i>=0; i--){
+ v+= get_rac(c, state+31-i)<<i;
+ }
+
+ 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<w; i++){
+ dst[i*dst_step] = LIFT(src[i*src_step], ((mul*(ref[i*ref_step] + ref[(i+1)*ref_step])+add)>>shift), inverse);
+ }
+
+ if(mirror_right){
+ dst[w*dst_step] = LIFT(src[w*src_step], ((mul*2*ref[w*ref_step]+add)>>shift), inverse);
+ }
+}
+
+#ifndef lift5
+static av_always_inline void lift5(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;
+
+ if(mirror_left){
+ int r= 3*2*ref[0];
+ r += r>>4;
+ r += r>>8;
+ dst[0] = LIFT(src[0], ((r+add)>>shift), inverse);
+ dst += dst_step;
+ src += src_step;
+ }
+
+ for(i=0; i<w; i++){
+ int r= 3*(ref[i*ref_step] + ref[(i+1)*ref_step]);
+ r += r>>4;
+ r += r>>8;
+ dst[i*dst_step] = LIFT(src[i*src_step], ((r+add)>>shift), inverse);
+ }
+
+ if(mirror_right){
+ int r= 3*2*ref[w*ref_step];
+ r += r>>4;
+ r += r>>8;
+ dst[w*dst_step] = LIFT(src[w*src_step], ((r+add)>>shift), inverse);
+ }
+}
+#endif
+
+#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*4*(src) + 4*(ref) + 8 + (5<<27))/(5*16) - (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<w; i++){
+ dst[i*dst_step] = LIFTS(src[i*src_step], mul*(ref[i*ref_step] + ref[(i+1)*ref_step])+add, inverse);
+ }
+
+ if(mirror_right){
+ dst[w*dst_step] = LIFTS(src[w*src_step], mul*2*ref[w*ref_step]+add, inverse);
+ }
+}
+#endif
+
+
+static void inplace_lift(DWTELEM *dst, int width, int *coeffs, int n, int shift, int start, int inverse){
+ int x, i;
+
+ for(x=start; x<width; x+=2){
+ int64_t sum=0;
+
+ for(i=0; i<n; i++){
+ int x2= x + 2*i - n + 1;
+ if (x2< 0) x2= -x2;
+ else if(x2>=width) x2= 2*width-x2-2;
+ sum += coeffs[i]*(int64_t)dst[x2];
+ }
+ if(inverse) dst[x] -= (sum + (1<<shift)/2)>>shift;
+ else dst[x] += (sum + (1<<shift)/2)>>shift;
+ }
+}
+
+static void inplace_liftV(DWTELEM *dst, int width, int height, int stride, int *coeffs, int n, int shift, int start, int inverse){
+ int x, y, i;
+ for(y=start; y<height; y+=2){
+ for(x=0; x<width; x++){
+ int64_t sum=0;
+
+ for(i=0; i<n; i++){
+ int y2= y + 2*i - n + 1;
+ if (y2< 0) y2= -y2;
+ else if(y2>=height) y2= 2*height-y2-2;
+ sum += coeffs[i]*(int64_t)dst[x + y2*stride];
+ }
+ if(inverse) dst[x + y*stride] -= (sum + (1<<shift)/2)>>shift;
+ else dst[x + y*stride] += (sum + (1<<shift)/2)>>shift;
+ }
+ }
+}
+
+#define SCALEX 1
+#define LX0 0
+#define LX1 1
+
+#if 0 // more accurate 9/7
+#define N1 2
+#define SHIFT1 14
+#define COEFFS1 (int[]){-25987,-25987}
+#define N2 2
+#define SHIFT2 19
+#define COEFFS2 (int[]){-27777,-27777}
+#define N3 2
+#define SHIFT3 15
+#define COEFFS3 (int[]){28931,28931}
+#define N4 2
+#define SHIFT4 15
+#define COEFFS4 (int[]){14533,14533}
+#elif 1 // 13/7 CRF
+#define N1 4
+#define SHIFT1 4
+#define COEFFS1 (int[]){1,-9,-9,1}
+#define N2 4
+#define SHIFT2 4
+#define COEFFS2 (int[]){-1,5,5,-1}
+#define N3 0
+#define SHIFT3 1
+#define COEFFS3 NULL
+#define N4 0
+#define SHIFT4 1
+#define COEFFS4 NULL
+#elif 1 // 3/5
+#define LX0 1
+#define LX1 0
+#define SCALEX 0.5
+#define N1 2
+#define SHIFT1 1
+#define COEFFS1 (int[]){1,1}
+#define N2 2
+#define SHIFT2 2
+#define COEFFS2 (int[]){-1,-1}
+#define N3 0
+#define SHIFT3 0
+#define COEFFS3 NULL
+#define N4 0
+#define SHIFT4 0
+#define COEFFS4 NULL
+#elif 1 // 11/5
+#define N1 0
+#define SHIFT1 1
+#define COEFFS1 NULL
+#define N2 2
+#define SHIFT2 2
+#define COEFFS2 (int[]){-1,-1}
+#define N3 2
+#define SHIFT3 0
+#define COEFFS3 (int[]){-1,-1}
+#define N4 4
+#define SHIFT4 7
+#define COEFFS4 (int[]){-5,29,29,-5}
+#define SCALEX 4
+#elif 1 // 9/7 CDF
+#define N1 2
+#define SHIFT1 7
+#define COEFFS1 (int[]){-203,-203}
+#define N2 2
+#define SHIFT2 12
+#define COEFFS2 (int[]){-217,-217}
+#define N3 2
+#define SHIFT3 7
+#define COEFFS3 (int[]){113,113}
+#define N4 2
+#define SHIFT4 9
+#define COEFFS4 (int[]){227,227}
+#define SCALEX 1
+#elif 1 // 7/5 CDF
+#define N1 0
+#define SHIFT1 1
+#define COEFFS1 NULL
+#define N2 2
+#define SHIFT2 2
+#define COEFFS2 (int[]){-1,-1}
+#define N3 2
+#define SHIFT3 0
+#define COEFFS3 (int[]){-1,-1}
+#define N4 2
+#define SHIFT4 4
+#define COEFFS4 (int[]){3,3}
+#elif 1 // 9/7 MN
+#define N1 4
+#define SHIFT1 4
+#define COEFFS1 (int[]){1,-9,-9,1}
+#define N2 2
+#define SHIFT2 2
+#define COEFFS2 (int[]){1,1}
+#define N3 0
+#define SHIFT3 1
+#define COEFFS3 NULL
+#define N4 0
+#define SHIFT4 1
+#define COEFFS4 NULL
+#else // 13/7 CRF
+#define N1 4
+#define SHIFT1 4
+#define COEFFS1 (int[]){1,-9,-9,1}
+#define N2 4
+#define SHIFT2 4
+#define COEFFS2 (int[]){-1,5,5,-1}
+#define N3 0
+#define SHIFT3 1
+#define COEFFS3 NULL
+#define N4 0
+#define SHIFT4 1
+#define COEFFS4 NULL
+#endif
+static void horizontal_decomposeX(DWTELEM *b, int width){
+ DWTELEM temp[width];
+ const int width2= width>>1;
+ const int w2= (width+1)>>1;
+ int x;
+
+ inplace_lift(b, width, COEFFS1, N1, SHIFT1, LX1, 0);
+ inplace_lift(b, width, COEFFS2, N2, SHIFT2, LX0, 0);
+ inplace_lift(b, width, COEFFS3, N3, SHIFT3, LX1, 0);
+ inplace_lift(b, width, COEFFS4, N4, SHIFT4, LX0, 0);
+
+ for(x=0; x<width2; x++){
+ temp[x ]= b[2*x ];
+ temp[x+w2]= b[2*x + 1];
+ }
+ if(width&1)
+ temp[x ]= b[2*x ];
+ memcpy(b, temp, width*sizeof(int));
+}
+
+static void horizontal_composeX(DWTELEM *b, int width){
+ DWTELEM temp[width];
+ const int width2= width>>1;
+ int x;
+ const int w2= (width+1)>>1;
+
+ memcpy(temp, b, width*sizeof(int));
+ for(x=0; x<width2; x++){
+ b[2*x ]= temp[x ];
+ b[2*x + 1]= temp[x+w2];
+ }
+ if(width&1)
+ b[2*x ]= temp[x ];
+
+ inplace_lift(b, width, COEFFS4, N4, SHIFT4, LX0, 1);
+ inplace_lift(b, width, COEFFS3, N3, SHIFT3, LX1, 1);
+ inplace_lift(b, width, COEFFS2, N2, SHIFT2, LX0, 1);
+ inplace_lift(b, width, COEFFS1, N1, SHIFT1, LX1, 1);
+}
+
+static void spatial_decomposeX(DWTELEM *buffer, int width, int height, int stride){
+ int x, y;
+
+ for(y=0; y<height; y++){
+ for(x=0; x<width; x++){
+ buffer[y*stride + x] *= SCALEX;
+ }
+ }
+
+ for(y=0; y<height; y++){
+ horizontal_decomposeX(buffer + y*stride, width);
+ }
+
+ inplace_liftV(buffer, width, height, stride, COEFFS1, N1, SHIFT1, LX1, 0);
+ inplace_liftV(buffer, width, height, stride, COEFFS2, N2, SHIFT2, LX0, 0);
+ inplace_liftV(buffer, width, height, stride, COEFFS3, N3, SHIFT3, LX1, 0);
+ inplace_liftV(buffer, width, height, stride, COEFFS4, N4, SHIFT4, LX0, 0);
+}
+
+static void spatial_composeX(DWTELEM *buffer, int width, int height, int stride){
+ int x, y;
+
+ inplace_liftV(buffer, width, height, stride, COEFFS4, N4, SHIFT4, LX0, 1);
+ inplace_liftV(buffer, width, height, stride, COEFFS3, N3, SHIFT3, LX1, 1);
+ inplace_liftV(buffer, width, height, stride, COEFFS2, N2, SHIFT2, LX0, 1);
+ inplace_liftV(buffer, width, height, stride, COEFFS1, N1, SHIFT1, LX1, 1);
+
+ for(y=0; y<height; y++){
+ horizontal_composeX(buffer + y*stride, width);
+ }
+
+ for(y=0; y<height; y++){
+ for(x=0; x<width; x++){
+ buffer[y*stride + x] /= SCALEX;
+ }
+ }
+}
+
+static void horizontal_decompose53i(DWTELEM *b, int width){
+ DWTELEM temp[width];
+ const int width2= width>>1;
+ int x;
+ const int w2= (width+1)>>1;
+
+ for(x=0; x<width2; x++){
+ temp[x ]= b[2*x ];
+ temp[x+w2]= b[2*x + 1];
+ }
+ if(width&1)
+ temp[x ]= b[2*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<width2; x+=2){
+ A3= temp[x+width2];
+ A4= temp[x+1 ];
+ A3 -= (A2 + A4)>>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
+}
+
+static void vertical_decompose53iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
+ int i;
+
+ for(i=0; i<width; i++){
+ b1[i] -= (b0[i] + b2[i])>>1;
+ }
+}
+
+static void vertical_decompose53iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
+ int i;
+
+ for(i=0; i<width; i++){
+ b1[i] += (b0[i] + b2[i] + 2)>>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<height; y+=2){
+ DWTELEM *b2= buffer + mirror(y+1, height-1)*stride;
+ DWTELEM *b3= buffer + mirror(y+2, height-1)*stride;
+
+{START_TIMER
+ if(y+1<(unsigned)height) horizontal_decompose53i(b2, width);
+ if(y+2<(unsigned)height) horizontal_decompose53i(b3, width);
+STOP_TIMER("horizontal_decompose53i")}
+
+{START_TIMER
+ if(y+1<(unsigned)height) vertical_decompose53iH0(b1, b2, b3, width);
+ if(y+0<(unsigned)height) vertical_decompose53iL0(b0, b1, b2, width);
+STOP_TIMER("vertical_decompose53i*")}
+
+ b0=b2;
+ b1=b3;
+ }
+}
+
+static void horizontal_decompose97i(DWTELEM *b, int width){
+ DWTELEM temp[width];
+ const int w2= (width+1)>>1;
+
+ lift (temp+w2, b +1, b , 1, 2, 2, width, -W_AM, W_AO, W_AS, 1, 0);
+ liftS(temp , b , temp+w2, 1, 2, 1, width, -W_BM, W_BO, W_BS, 0, 0);
+ lift5(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<width; i++){
+ b1[i] -= (W_AM*(b0[i] + b2[i])+W_AO)>>W_AS;
+ }
+}
+
+static void vertical_decompose97iH1(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
+ int i;
+
+ for(i=0; i<width; i++){
+#ifdef lift5
+ b1[i] += (W_CM*(b0[i] + b2[i])+W_CO)>>W_CS;
+#else
+ int r= 3*(b0[i] + b2[i]);
+ r+= r>>4;
+ r+= r>>8;
+ b1[i] += (r+W_CO)>>W_CS;
+#endif
+ }
+}
+
+static void vertical_decompose97iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
+ int i;
+
+ for(i=0; i<width; i++){
+#ifdef liftS
+ b1[i] -= (W_BM*(b0[i] + b2[i])+W_BO)>>W_BS;
+#else
+ b1[i] = (16*4*b1[i] - 4*(b0[i] + b2[i]) + 8*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<width; i++){
+ b1[i] += (W_DM*(b0[i] + b2[i])+W_DO)>>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<height; y+=2){
+ DWTELEM *b4= buffer + mirror(y+3, height-1)*stride;
+ DWTELEM *b5= buffer + mirror(y+4, height-1)*stride;
+
+{START_TIMER
+ if(y+3<(unsigned)height) horizontal_decompose97i(b4, width);
+ if(y+4<(unsigned)height) horizontal_decompose97i(b5, width);
+if(width>400){
+STOP_TIMER("horizontal_decompose97i")
+}}
+
+{START_TIMER
+ if(y+3<(unsigned)height) vertical_decompose97iH0(b3, b4, b5, width);
+ if(y+2<(unsigned)height) vertical_decompose97iL0(b2, b3, b4, width);
+ if(y+1<(unsigned)height) vertical_decompose97iH1(b1, b2, b3, width);
+ if(y+0<(unsigned)height) vertical_decompose97iL1(b0, b1, b2, width);
+
+if(width>400){
+STOP_TIMER("vertical_decompose97i")
+}}
+
+ b0=b2;
+ b1=b3;
+ b2=b4;
+ b3=b5;
+ }
+}
+
+void ff_spatial_dwt(DWTELEM *buffer, int width, int height, int stride, int type, int decomposition_count){
+ int level;
+
+ for(level=0; level<decomposition_count; level++){
+ switch(type){
+ case DWT_97: spatial_decompose97i(buffer, width>>level, height>>level, stride<<level); break;
+ case DWT_53: spatial_decompose53i(buffer, width>>level, height>>level, stride<<level); break;
+ case DWT_X: spatial_decomposeX (buffer, width>>level, height>>level, stride<<level); break;
+ }
+ }
+}
+
+static void horizontal_compose53i(DWTELEM *b, int width){
+ DWTELEM temp[width];
+ const int width2= width>>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<width2; x+=2){
+ A3= temp[x+width2];
+ A4= temp[x+1 ];
+ A3 -= (A2 + A4)>>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(temp , b , b+w2, 1, 1, 1, width, 1, 2, 2, 0, 1);
+ lift(temp+w2, b+w2, temp, 1, 1, 1, width, -1, 0, 1, 1, 1);
+#endif
+ for(x=0; x<width2; x++){
+ b[2*x ]= temp[x ];
+ b[2*x + 1]= temp[x+w2];
+ }
+ if(width&1)
+ b[2*x ]= temp[x ];
+}
+
+static void vertical_compose53iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
+ int i;
+
+ for(i=0; i<width; i++){
+ b1[i] += (b0[i] + b2[i])>>1;
+ }
+}
+
+static void vertical_compose53iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
+ int i;
+
+ for(i=0; i<width; i++){
+ b1[i] -= (b0[i] + b2[i] + 2)>>2;
+ }
+}
+
+static void spatial_compose53i_buffered_init(dwt_compose_t *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(dwt_compose_t *cs, DWTELEM *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(dwt_compose_t *cs, slice_buffer * sb, int width, int height, int stride_line){
+ int y= cs->y;
+
+ DWTELEM *b0= cs->b0;
+ DWTELEM *b1= cs->b1;
+ DWTELEM *b2= slice_buffer_get_line(sb, mirror(y+1, height-1) * stride_line);
+ DWTELEM *b3= slice_buffer_get_line(sb, mirror(y+2, height-1) * stride_line);
+
+{START_TIMER
+ if(y+1<(unsigned)height) vertical_compose53iL0(b1, b2, b3, width);
+ if(y+0<(unsigned)height) vertical_compose53iH0(b0, b1, b2, width);
+STOP_TIMER("vertical_compose53i*")}
+
+{START_TIMER
+ if(y-1<(unsigned)height) horizontal_compose53i(b0, width);
+ if(y+0<(unsigned)height) horizontal_compose53i(b1, width);
+STOP_TIMER("horizontal_compose53i")}
+
+ cs->b0 = b2;
+ cs->b1 = b3;
+ cs->y += 2;
+}
+
+static void spatial_compose53i_dy(dwt_compose_t *cs, DWTELEM *buffer, int width, int height, int stride){
+ int y= cs->y;
+ DWTELEM *b0= cs->b0;
+ DWTELEM *b1= cs->b1;
+ DWTELEM *b2= buffer + mirror(y+1, height-1)*stride;
+ DWTELEM *b3= buffer + mirror(y+2, height-1)*stride;
+
+{START_TIMER
+ if(y+1<(unsigned)height) vertical_compose53iL0(b1, b2, b3, width);
+ if(y+0<(unsigned)height) vertical_compose53iH0(b0, b1, b2, width);
+STOP_TIMER("vertical_compose53i*")}
+
+{START_TIMER
+ if(y-1<(unsigned)height) horizontal_compose53i(b0, width);
+ if(y+0<(unsigned)height) horizontal_compose53i(b1, width);
+STOP_TIMER("horizontal_compose53i")}
+
+ cs->b0 = b2;
+ cs->b1 = b3;
+ cs->y += 2;
+}
+
+static void spatial_compose53i(DWTELEM *buffer, int width, int height, int stride){
+ dwt_compose_t 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(DWTELEM *b, int width){
+ DWTELEM temp[width];
+ const int w2= (width+1)>>1;
+
+ lift (temp , b , b +w2, 1, 1, 1, width, W_DM, W_DO, W_DS, 0, 1);
+ lift5(temp+w2, b +w2, temp , 1, 1, 1, width, W_CM, W_CO, W_CS, 1, 1);
+ liftS(b , temp , temp+w2, 2, 1, 1, width, -W_BM, W_BO, W_BS, 0, 1);
+ lift (b+1 , temp+w2, b , 2, 1, 2, width, -W_AM, W_AO, W_AS, 1, 1);
+}
+
+static void vertical_compose97iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
+ int i;
+
+ for(i=0; i<width; i++){
+ b1[i] += (W_AM*(b0[i] + b2[i])+W_AO)>>W_AS;
+ }
+}
+
+static void vertical_compose97iH1(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
+ int i;
+
+ for(i=0; i<width; i++){
+#ifdef lift5
+ b1[i] -= (W_CM*(b0[i] + b2[i])+W_CO)>>W_CS;
+#else
+ int r= 3*(b0[i] + b2[i]);
+ r+= r>>4;
+ r+= r>>8;
+ b1[i] -= (r+W_CO)>>W_CS;
+#endif
+ }
+}
+
+static void vertical_compose97iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
+ int i;
+
+ for(i=0; i<width; i++){
+#ifdef liftS
+ b1[i] += (W_BM*(b0[i] + b2[i])+W_BO)>>W_BS;
+#else
+ b1[i] += (W_BM*(b0[i] + b2[i])+4*b1[i]+W_BO)>>W_BS;
+#endif
+ }
+}
+
+static void vertical_compose97iL1(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
+ int i;
+
+ for(i=0; i<width; i++){
+ b1[i] -= (W_DM*(b0[i] + b2[i])+W_DO)>>W_DS;
+ }
+}
+
+void ff_snow_vertical_compose97i(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWTELEM *b3, DWTELEM *b4, DWTELEM *b5, int width){
+ int i;
+
+ for(i=0; i<width; i++){
+#ifndef lift5
+ int r;
+#endif
+ b4[i] -= (W_DM*(b3[i] + b5[i])+W_DO)>>W_DS;
+#ifdef lift5
+ b3[i] -= (W_CM*(b2[i] + b4[i])+W_CO)>>W_CS;
+#else
+ r= 3*(b2[i] + b4[i]);
+ r+= r>>4;
+ r+= r>>8;
+ b3[i] -= (r+W_CO)>>W_CS;
+#endif
+#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(dwt_compose_t *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(dwt_compose_t *cs, DWTELEM *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, dwt_compose_t *cs, slice_buffer * sb, int width, int height, int stride_line){
+ int y = cs->y;
+
+ DWTELEM *b0= cs->b0;
+ DWTELEM *b1= cs->b1;
+ DWTELEM *b2= cs->b2;
+ DWTELEM *b3= cs->b3;
+ DWTELEM *b4= slice_buffer_get_line(sb, mirror(y + 3, height - 1) * stride_line);
+ DWTELEM *b5= slice_buffer_get_line(sb, mirror(y + 4, height - 1) * stride_line);
+
+{START_TIMER
+ if(y>0 && y+4<height){
+ dsp->vertical_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(width>400){
+STOP_TIMER("vertical_compose97i")}}
+
+{START_TIMER
+ if(y-1<(unsigned)height) dsp->horizontal_compose97i(b0, width);
+ if(y+0<(unsigned)height) dsp->horizontal_compose97i(b1, width);
+if(width>400 && y+0<(unsigned)height){
+STOP_TIMER("horizontal_compose97i")}}
+
+ cs->b0=b2;
+ cs->b1=b3;
+ cs->b2=b4;
+ cs->b3=b5;
+ cs->y += 2;
+}
+
+static void spatial_compose97i_dy(dwt_compose_t *cs, DWTELEM *buffer, int width, int height, int stride){
+ int y = cs->y;
+ DWTELEM *b0= cs->b0;
+ DWTELEM *b1= cs->b1;
+ DWTELEM *b2= cs->b2;
+ DWTELEM *b3= cs->b3;
+ DWTELEM *b4= buffer + mirror(y+3, height-1)*stride;
+ DWTELEM *b5= buffer + mirror(y+4, height-1)*stride;
+
+{START_TIMER
+ 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(width>400){
+STOP_TIMER("vertical_compose97i")}}
+
+{START_TIMER
+ if(y-1<(unsigned)height) ff_snow_horizontal_compose97i(b0, width);
+ if(y+0<(unsigned)height) ff_snow_horizontal_compose97i(b1, width);
+if(width>400 && b0 <= b2){
+STOP_TIMER("horizontal_compose97i")}}
+
+ cs->b0=b2;
+ cs->b1=b3;
+ cs->b2=b4;
+ cs->b3=b5;
+ cs->y += 2;
+}
+
+static void spatial_compose97i(DWTELEM *buffer, int width, int height, int stride){
+ dwt_compose_t 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(dwt_compose_t *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); break;
+ case DWT_53: spatial_compose53i_buffered_init(cs+level, sb, height>>level, stride_line<<level); break;
+ /* not slicified yet */
+ case DWT_X: /*spatial_composeX(buffer, width>>level, height>>level, stride<<level); break;*/
+ av_log(NULL, AV_LOG_ERROR, "spatial_composeX neither buffered nor slicified yet.\n"); break;
+ }
+ }
+}
+
+static void ff_spatial_idwt_init(dwt_compose_t *cs, DWTELEM *buffer, int width, int height, int stride, int type, int decomposition_count){
+ int level;
+ for(level=decomposition_count-1; level>=0; level--){
+ switch(type){
+ case DWT_97: spatial_compose97i_init(cs+level, buffer, height>>level, stride<<level); break;
+ case DWT_53: spatial_compose53i_init(cs+level, buffer, height>>level, stride<<level); break;
+ /* not slicified yet */
+ case DWT_X: spatial_composeX(buffer, width>>level, height>>level, stride<<level); break;
+ }
+ }
+}
+
+static void ff_spatial_idwt_slice(dwt_compose_t *cs, DWTELEM *buffer, int width, int height, int stride, int type, int decomposition_count, int y){
+ const int support = type==1 ? 3 : 5;
+ int level;
+ if(type==2) return;
+
+ for(level=decomposition_count-1; level>=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);
+ break;
+ case DWT_53: spatial_compose53i_dy(cs+level, buffer, width>>level, height>>level, stride<<level);
+ break;
+ case DWT_X: break;
+ }
+ }
+ }
+}
+
+static void ff_spatial_idwt_buffered_slice(DSPContext *dsp, dwt_compose_t *cs, slice_buffer * slice_buf, int width, int height, int stride_line, int type, int decomposition_count, int y){
+ const int support = type==1 ? 3 : 5;
+ int level;
+ if(type==2) return;
+
+ for(level=decomposition_count-1; level>=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);
+ break;
+ case DWT_53: spatial_compose53i_dy_buffered(cs+level, slice_buf, width>>level, height>>level, stride_line<<level);
+ break;
+ case DWT_X: break;
+ }
+ }
+ }
+}
+
+static void ff_spatial_idwt(DWTELEM *buffer, int width, int height, int stride, int type, int decomposition_count){
+ if(type==2){
+ int level;
+ for(level=decomposition_count-1; level>=0; level--)
+ spatial_composeX (buffer, width>>level, height>>level, stride<<level);
+ }else{
+ dwt_compose_t cs[MAX_DECOMPOSITIONS];
+ int y;
+ ff_spatial_idwt_init(cs, buffer, width, height, stride, type, decomposition_count);
+ for(y=0; y<height; y+=4)
+ ff_spatial_idwt_slice(cs, buffer, width, height, stride, type, decomposition_count, y);
+ }
+}
+
+static int encode_subband_c0run(SnowContext *s, SubBand *b, DWTELEM *src, DWTELEM *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<h; y++){
+ for(x=0; x<w; x++){
+ int v, p=0;
+ int /*ll=0, */l=0, lt=0, t=0, rt=0;
+ v= src[x + y*stride];
+
+ if(y){
+ t= src[x + (y-1)*stride];
+ if(x){
+ lt= src[x - 1 + (y-1)*stride];
+ }
+ if(x + 1 < w){
+ rt= src[x + 1 + (y-1)*stride];
+ }
+ }
+ if(x){
+ l= src[x - 1 + y*stride];
+ /*if(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(px<b->parent->width && py<b->parent->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; y<h; y++){
+ if(s->c.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<w; x++){
+ int v, p=0;
+ int /*ll=0, */l=0, lt=0, t=0, rt=0;
+ v= src[x + y*stride];
+
+ if(y){
+ t= src[x + (y-1)*stride];
+ if(x){
+ lt= src[x - 1 + (y-1)*stride];
+ }
+ if(x + 1 < w){
+ rt= src[x + 1 + (y-1)*stride];
+ }
+ }
+ if(x){
+ l= src[x - 1 + y*stride];
+ /*if(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(px<b->parent->width && py<b->parent->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, DWTELEM *src, DWTELEM *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;
+
+ 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; y<h; y++){
+ int v=0;
+ int lt=0, t=0, rt=0;
+
+ if(y && prev_xc->x == 0){
+ rt= prev_xc->coeff;
+ }
+ for(x=0; x<w; x++){
+ int p=0;
+ const int l= v;
+
+ lt= t; t= rt;
+
+ if(y){
+ if(prev_xc->x <= 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++;
+ 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]){
+ const int w= b->width;
+ int y;
+ const int qlog= av_clip(s->qlog + b->qlog, 0, QROOT*16);
+ int qmul= qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT);
+ int qadd= (s->qbias*qmul)>>QBIAS_SHIFT;
+ int new_index = 0;
+
+ START_TIMER
+
+ if(b->buf == s->spatial_dwt_buffer || s->qlog == LOSSLESS_QLOG){
+ qadd= 0;
+ qmul= 1<<QEXPSHIFT;
+ }
+
+ /* If we are on the second or later slice, restore our index. */
+ if (start_y != 0)
+ new_index = save_state[0];
+
+
+ for(y=start_y; y<h; y++){
+ int x = 0;
+ int v;
+ DWTELEM * line = slice_buffer_get_line(sb, y * b->stride_line + b->buf_y_offset) + b->buf_x_offset;
+ memset(line, 0, b->width*sizeof(DWTELEM));
+ v = b->x_coeff[new_index].coeff;
+ x = b->x_coeff[new_index++].x;
+ while(x < w)
+ {
+ register int t= ( (v>>1)*qmul + qadd)>>QEXPSHIFT;
+ register int u= -(v&1);
+ line[x] = (t^u) - u;
+
+ v = b->x_coeff[new_index].coeff;
+ x = b->x_coeff[new_index++].x;
+ }
+ }
+ if(w > 200 && start_y != 0/*level+1 == s->spatial_decomposition_count*/){
+ STOP_TIMER("decode_subband")
+ }
+
+ /* Save our variables for the next slice. */
+ save_state[0] = new_index;
+
+ return;
+}
+
+static void reset_contexts(SnowContext *s){ //FIXME better initial contexts
+ int plane_index, level, orientation;
+
+ for(plane_index=0; plane_index<3; plane_index++){
+ for(level=0; level<s->spatial_decomposition_count; level++){
+ for(orientation=level ? 1:0; orientation<4; orientation++){
+ memset(s->plane[plane_index].band[level][orientation].state, MID_STATE, sizeof(s->plane[plane_index].band[level][orientation].state));
+ }
+ }
+ }
+ memset(s->header_state, MID_STATE, sizeof(s->header_state));
+ memset(s->block_state, MID_STATE, sizeof(s->block_state));
+}
+
+static int alloc_blocks(SnowContext *s){
+ int w= -((-s->avctx->width )>>LOG2_MB_SIZE);
+ int h= -((-s->avctx->height)>>LOG2_MB_SIZE);
+
+ s->b_width = w;
+ s->b_height= h;
+
+ s->block= av_mallocz(w * h * sizeof(BlockNode) << (s->block_max_depth*2));
+ return 0;
+}
+
+static inline void copy_rac_state(RangeCoder *d, RangeCoder *s){
+ uint8_t *bytestream= d->bytestream;
+ uint8_t *bytestream_start= d->bytestream_start;
+ *d= *s;
+ d->bytestream= bytestream;
+ 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;
+ const int index= (x + y*w) << rem_depth;
+ const int block_w= 1<<rem_depth;
+ BlockNode block;
+ int i,j;
+
+ block.color[0]= l;
+ block.color[1]= cb;
+ block.color[2]= cr;
+ block.mx= mx;
+ block.my= my;
+ block.ref= ref;
+ block.type= type;
+ block.level= level;
+
+ for(j=0; j<block_w; j++){
+ for(i=0; i<block_w; i++){
+ s->block[index + i + j*w]= block;
+ }
+ }
+}
+
+static inline void init_ref(MotionEstContext *c, uint8_t *src[3], uint8_t *ref[3], uint8_t *ref2[3], int x, int y, int ref_index){
+ const int offset[3]= {
+ y*c-> stride + x,
+ ((y*c->uvstride + x)>>1),
+ ((y*c->uvstride + x)>>1),
+ };
+ int i;
+ for(i=0; i<3; i++){
+ c->src[0][i]= src [i];
+ c->ref[0][i]= ref [i] + offset[i];
+ }
+ assert(!ref_index);
+}
+
+static inline void pred_mv(SnowContext *s, int *mx, int *my, int ref,
+ const BlockNode *left, const BlockNode *top, const BlockNode *tr){
+ if(s->ref_frames == 1){
+ *mx = mid_pred(left->mx, top->mx, tr->mx);
+ *my = mid_pred(left->my, top->my, tr->my);
+ }else{
+ const int *scale = scale_mv_ref[ref];
+ *mx = mid_pred((left->mx * scale[left->ref] + 128) >>8,
+ (top ->mx * scale[top ->ref] + 128) >>8,
+ (tr ->mx * scale[tr ->ref] + 128) >>8);
+ *my = mid_pred((left->my * scale[left->ref] + 128) >>8,
+ (top ->my * scale[top ->ref] + 128) >>8,
+ (tr ->my * scale[tr ->ref] + 128) >>8);
+ }
+}
+
+//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;
+ 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)<<rem_depth;
+ int try= (y+1)<<rem_depth;
+ const BlockNode *left = x ? &s->block[index-1] : &null_block;
+ const BlockNode *top = y ? &s->block[index-w] : &null_block;
+ const BlockNode *right = trx<w ? &s->block[index+1] : &null_block;
+ const BlockNode *bottom= try<h ? &s->block[index+w] : &null_block;
+ const BlockNode *tl = y && x ? &s->block[index-w-1] : left;
+ const BlockNode *tr = y && trx<w && ((x&1)==0 || level==0) ? &s->block[index-w+(1<<rem_depth)] : tl; //FIXME use lt
+ int pl = left->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+2;
+ c->ymin = - y*block_w - 16+2;
+ c->xmax = - (x+1)*block_w + (w<<(LOG2_MB_SIZE - s->block_max_depth)) + 16-2;
+ c->ymax = - (y+1)*block_w + (h<<(LOG2_MB_SIZE - s->block_max_depth)) + 16-2;
+
+ if(P_LEFT[0] > (c->xmax<<shift)) P_LEFT[0] = (c->xmax<<shift);
+ if(P_LEFT[1] > (c->ymax<<shift)) P_LEFT[1] = (c->ymax<<shift);
+ if(P_TOP[0] > (c->xmax<<shift)) P_TOP[0] = (c->xmax<<shift);
+ if(P_TOP[1] > (c->ymax<<shift)) P_TOP[1] = (c->ymax<<shift);
+ if(P_TOPRIGHT[0] < (c->xmin<<shift)) P_TOPRIGHT[0]= (c->xmin<<shift);
+ if(P_TOPRIGHT[0] > (c->xmax<<shift)) P_TOPRIGHT[0]= (c->xmax<<shift); //due to pmx no clip
+ if(P_TOPRIGHT[1] > (c->ymax<<shift)) P_TOPRIGHT[1]= (c->ymax<<shift);
+
+ P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
+ P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);
+
+ if (!y) {
+ c->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; ref<s->ref_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 cant be compared currently and mb_penalty vs. lambda2
+
+ // subpel search
+ 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*(p_len*8
+ + (pc.outstanding_count - s->c.outstanding_count)*8
+ + (-av_log2(pc.range) + av_log2(s->c.range))
+ ))>>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(&current_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(&current_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*(i_len*8
+ + (ic.outstanding_count - s->c.outstanding_count)*8
+ + (-av_log2(ic.range) + av_log2(s->c.range))
+ ))>>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]));
+ }else{
+ return !((a->mx - b->mx) | (a->my - b->my) | (a->ref - b->ref) | ((a->type ^ b->type)&BLOCK_INTRA));
+ }
+}
+
+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)<<rem_depth;
+ BlockNode *b= &s->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 && trx<w && ((x&1)==0 || level==0) ? &s->block[index-w+(1<<rem_depth)] : tl; //FIXME use lt
+ int pl = left->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;
+ const int index= (x + y*w) << rem_depth;
+ int trx= (x+1)<<rem_depth;
+ 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 && trx<w && ((x&1)==0 || level==0) ? &s->block[index-w+(1<<rem_depth)] : tl; //FIXME use lt
+ int s_context= 2*left->level + 2*top->level + tl->level + tr->level;
+
+ if(s->keyframe){
+ set_blocks(s, level, x, y, null_block.color[0], null_block.color[1], null_block.color[2], null_block.mx, null_block.my, null_block.ref, BLOCK_INTRA);
+ return;
+ }
+
+ if(level==s->block_max_depth || get_rac(&s->c, &s->block_state[4 + s_context])){
+ int type, mx, my;
+ int l = left->color[0];
+ int cb= left->color[1];
+ int cr= left->color[2];
+ int ref = 0;
+ int ref_context= av_log2(2*left->ref) + av_log2(2*top->ref);
+ int mx_context= av_log2(2*FFABS(left->mx - top->mx)) + 0*av_log2(2*FFABS(tr->mx - top->mx));
+ int my_context= av_log2(2*FFABS(left->my - top->my)) + 0*av_log2(2*FFABS(tr->my - top->my));
+
+ type= get_rac(&s->c, &s->block_state[1 + left->type + top->type]) ? BLOCK_INTRA : 0;
+
+ if(type){
+ pred_mv(s, &mx, &my, 0, left, top, tr);
+ l += get_symbol(&s->c, &s->block_state[32], 1);
+ cb+= get_symbol(&s->c, &s->block_state[64], 1);
+ cr+= get_symbol(&s->c, &s->block_state[96], 1);
+ }else{
+ if(s->ref_frames > 1)
+ ref= get_symbol(&s->c, &s->block_state[128 + 1024 + 32*ref_context], 0);
+ pred_mv(s, &mx, &my, ref, left, top, tr);
+ mx+= get_symbol(&s->c, &s->block_state[128 + 32*(mx_context + 16*!!ref)], 1);
+ my+= get_symbol(&s->c, &s->block_state[128 + 32*(my_context + 16*!!ref)], 1);
+ }
+ set_blocks(s, level, x, y, l, cb, cr, mx, my, ref, type);
+ }else{
+ decode_q_branch(s, level+1, 2*x+0, 2*y+0);
+ decode_q_branch(s, level+1, 2*x+1, 2*y+0);
+ decode_q_branch(s, level+1, 2*x+0, 2*y+1);
+ decode_q_branch(s, level+1, 2*x+1, 2*y+1);
+ }
+}
+
+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; y<h; y++){
+ if(s->c.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; x<w; x++){
+ if(s->avctx->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;
+ int h= s->b_height;
+
+ for(y=0; y<h; y++){
+ for(x=0; x<w; x++){
+ decode_q_branch(s, 0, x, y);
+ }
+ }
+}
+
+static void mc_block(uint8_t *dst, uint8_t *src, uint8_t *tmp, int stride, int b_w, int b_h, int dx, int dy){
+ int x, y;
+START_TIMER
+ for(y=0; y < b_h+5; y++){
+ for(x=0; x < b_w; x++){
+ int a0= src[x ];
+ int a1= src[x + 1];
+ int a2= src[x + 2];
+ int a3= src[x + 3];
+ int a4= src[x + 4];
+ int a5= src[x + 5];
+// int am= 9*(a1+a2) - (a0+a3);
+ int am= 20*(a2+a3) - 5*(a1+a4) + (a0+a5);
+// int am= 18*(a2+a3) - 2*(a1+a4);
+// int aL= (-7*a0 + 105*a1 + 35*a2 - 5*a3)>>3;
+// int aR= (-7*a3 + 105*a2 + 35*a1 - 5*a0)>>3;
+
+// if(b_w==16) am= 8*(a1+a2);
+
+ if(dx<8) am = (32*a2*( 8-dx) + am* dx + 128)>>8;
+ else am = ( am*(16-dx) + 32*a3*(dx-8) + 128)>>8;
+
+ /* FIXME Try increasing tmp buffer to 16 bits and not clipping here. Should give marginally better results. - Robert*/
+ if(am&(~255)) am= ~(am>>31);
+
+ tmp[x] = am;
+
+/* if (dx< 4) tmp[x + y*stride]= (16*a1*( 4-dx) + aL* dx + 32)>>6;
+ else if(dx< 8) tmp[x + y*stride]= ( aL*( 8-dx) + am*(dx- 4) + 32)>>6;
+ else if(dx<12) tmp[x + y*stride]= ( am*(12-dx) + aR*(dx- 8) + 32)>>6;
+ else tmp[x + y*stride]= ( aR*(16-dx) + 16*a2*(dx-12) + 32)>>6;*/
+ }
+ tmp += stride;
+ src += stride;
+ }
+ tmp -= (b_h+5)*stride;
+
+ for(y=0; y < b_h; y++){
+ for(x=0; x < b_w; x++){
+ int a0= tmp[x + 0*stride];
+ int a1= tmp[x + 1*stride];
+ int a2= tmp[x + 2*stride];
+ int a3= tmp[x + 3*stride];
+ int a4= tmp[x + 4*stride];
+ int a5= tmp[x + 5*stride];
+ int am= 20*(a2+a3) - 5*(a1+a4) + (a0+a5);
+// int am= 18*(a2+a3) - 2*(a1+a4);
+/* int aL= (-7*a0 + 105*a1 + 35*a2 - 5*a3)>>3;
+ int aR= (-7*a3 + 105*a2 + 35*a1 - 5*a0)>>3;*/
+
+// if(b_w==16) am= 8*(a1+a2);
+
+ if(dy<8) am = (32*a2*( 8-dy) + am* dy + 128)>>8;
+ else am = ( am*(16-dy) + 32*a3*(dy-8) + 128)>>8;
+
+ if(am&(~255)) am= ~(am>>31);
+
+ dst[x] = am;
+/* if (dy< 4) tmp[x + y*stride]= (16*a1*( 4-dy) + aL* dy + 32)>>6;
+ else if(dy< 8) tmp[x + y*stride]= ( aL*( 8-dy) + am*(dy- 4) + 32)>>6;
+ else if(dy<12) tmp[x + y*stride]= ( am*(12-dy) + aR*(dy- 8) + 32)>>6;
+ else tmp[x + y*stride]= ( aR*(16-dy) + 16*a2*(dy-12) + 32)>>6;*/
+ }
+ dst += stride;
+ tmp += stride;
+ }
+STOP_TIMER("mc_block")
+}
+
+#define mca(dx,dy,b_w)\
+static void mc_block_hpel ## dx ## dy ## b_w(uint8_t *dst, uint8_t *src, int stride, int h){\
+ uint8_t tmp[stride*(b_w+5)];\
+ assert(h==b_w);\
+ mc_block(dst, src-2-2*stride, tmp, stride, b_w, b_w, dx, dy);\
+}
+
+mca( 0, 0,16)
+mca( 8, 0,16)
+mca( 0, 8,16)
+mca( 8, 8,16)
+mca( 0, 0,8)
+mca( 8, 0,8)
+mca( 0, 8,8)
+mca( 8, 8,8)
+
+static void pred_block(SnowContext *s, uint8_t *dst, uint8_t *tmp, int stride, int sx, int sy, int b_w, int b_h, BlockNode *block, int plane_index, int w, int h){
+ if(block->type & BLOCK_INTRA){
+ int x, y;
+ const int color = block->color[plane_index];
+ const int color4= color*0x01010101;
+ if(b_w==32){
+ for(y=0; y < b_h; y++){
+ *(uint32_t*)&dst[0 + y*stride]= color4;
+ *(uint32_t*)&dst[4 + y*stride]= color4;
+ *(uint32_t*)&dst[8 + y*stride]= color4;
+ *(uint32_t*)&dst[12+ y*stride]= color4;
+ *(uint32_t*)&dst[16+ y*stride]= color4;
+ *(uint32_t*)&dst[20+ y*stride]= color4;
+ *(uint32_t*)&dst[24+ y*stride]= color4;
+ *(uint32_t*)&dst[28+ y*stride]= color4;
+ }
+ }else if(b_w==16){
+ for(y=0; y < b_h; y++){
+ *(uint32_t*)&dst[0 + y*stride]= color4;
+ *(uint32_t*)&dst[4 + y*stride]= color4;
+ *(uint32_t*)&dst[8 + y*stride]= color4;
+ *(uint32_t*)&dst[12+ y*stride]= color4;
+ }
+ }else if(b_w==8){
+ for(y=0; y < b_h; y++){
+ *(uint32_t*)&dst[0 + y*stride]= color4;
+ *(uint32_t*)&dst[4 + y*stride]= color4;
+ }
+ }else if(b_w==4){
+ for(y=0; y < b_h; y++){
+ *(uint32_t*)&dst[0 + y*stride]= color4;
+ }
+ }else{
+ for(y=0; y < b_h; y++){
+ for(x=0; x < b_w; x++){
+ dst[x + y*stride]= color;
+ }
+ }
+ }
+ }else{
+ uint8_t *src= s->last_picture[block->ref].data[plane_index];
+ const int scale= plane_index ? s->mv_scale : 2*s->mv_scale;
+ int mx= block->mx*scale;
+ int my= block->my*scale;
+ const int dx= mx&15;
+ const int dy= my&15;
+ const int tab_index= 3 - (b_w>>2) + (b_w>>4);
+ sx += (mx>>4) - 2;
+ sy += (my>>4) - 2;
+ src += sx + sy*stride;
+ if( (unsigned)sx >= w - b_w - 4
+ || (unsigned)sy >= h - b_h - 4){
+ ff_emulated_edge_mc(tmp + MB_SIZE, src, stride, b_w+5, b_h+5, sx, sy, w, h);
+ src= tmp + MB_SIZE;
+ }
+// assert(b_w == b_h || 2*b_w == b_h || b_w == 2*b_h);
+// assert(!(b_w&(b_w-1)));
+ assert(b_w>1 && b_h>1);
+ assert(tab_index>=0 && tab_index<4 || b_w==32);
+ if((dx&3) || (dy&3) || !(b_w == b_h || 2*b_w == b_h || b_w == 2*b_h) || (b_w&(b_w-1)))
+ mc_block(dst, src, tmp, stride, b_w, b_h, dx, dy);
+ else if(b_w==32){
+ int y;
+ for(y=0; y<b_h; y+=16){
+ s->dsp.put_h264_qpel_pixels_tab[0][dy+(dx>>2)](dst + y*stride, src + 2 + (y+2)*stride,stride);
+ s->dsp.put_h264_qpel_pixels_tab[0][dy+(dx>>2)](dst + 16 + y*stride, src + 18 + (y+2)*stride,stride);
+ }
+ }else if(b_w==b_h)
+ s->dsp.put_h264_qpel_pixels_tab[tab_index ][dy+(dx>>2)](dst,src + 2 + 2*stride,stride);
+ else if(b_w==2*b_h){
+ s->dsp.put_h264_qpel_pixels_tab[tab_index+1][dy+(dx>>2)](dst ,src + 2 + 2*stride,stride);
+ s->dsp.put_h264_qpel_pixels_tab[tab_index+1][dy+(dx>>2)](dst+b_h,src + 2 + b_h + 2*stride,stride);
+ }else{
+ assert(2*b_w==b_h);
+ s->dsp.put_h264_qpel_pixels_tab[tab_index ][dy+(dx>>2)](dst ,src + 2 + 2*stride ,stride);
+ s->dsp.put_h264_qpel_pixels_tab[tab_index ][dy+(dx>>2)](dst+b_w*stride,src + 2 + 2*stride+b_w*stride,stride);
+ }
+ }
+}
+
+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 y, x;
+ DWTELEM * dst;
+ for(y=0; y<b_h; y++){
+ //FIXME ugly missue of obmc_stride
+ const uint8_t *obmc1= obmc + y*obmc_stride;
+ const uint8_t *obmc2= obmc1+ (obmc_stride>>1);
+ const uint8_t *obmc3= obmc1+ obmc_stride*(obmc_stride>>1);
+ const uint8_t *obmc4= obmc3+ (obmc_stride>>1);
+ dst = slice_buffer_get_line(sb, src_y + y);
+ for(x=0; x<b_w; x++){
+ int v= obmc1[x] * block[3][x + y*src_stride]
+ +obmc2[x] * block[2][x + y*src_stride]
+ +obmc3[x] * block[1][x + y*src_stride]
+ +obmc4[x] * block[0][x + y*src_stride];
+
+ v <<= 8 - LOG2_OBMC_MAX;
+ if(FRAC_BITS != 8){
+ v += 1<<(7 - FRAC_BITS);
+ v >>= 8 - FRAC_BITS;
+ }
+ if(add){
+ v += dst[x + src_x];
+ v = (v + (1<<(FRAC_BITS-1))) >> FRAC_BITS;
+ if(v&(~255)) v= ~(v>>31);
+ dst8[x + y*src_stride] = v;
+ }else{
+ dst[x + src_x] -= v;
+ }
+ }
+ }
+}
+
+//FIXME name clenup (b_w, block_w, b_width stuff)
+static av_always_inline void add_yblock(SnowContext *s, int sliced, slice_buffer *sb, DWTELEM *dst, uint8_t *dst8, const uint8_t *obmc, int src_x, int src_y, int b_w, int b_h, int w, int h, int dst_stride, int src_stride, int obmc_stride, int b_x, int b_y, int add, int offset_dst, int plane_index){
+ const int b_width = s->b_width << s->block_max_depth;
+ const int b_height= s->b_height << s->block_max_depth;
+ const int b_stride= b_width;
+ BlockNode *lt= &s->block[b_x + b_y*b_stride];
+ BlockNode *rt= lt+1;
+ BlockNode *lb= lt+b_stride;
+ BlockNode *rb= lb+1;
+ uint8_t *block[4];
+ int tmp_step= src_stride >= 7*MB_SIZE ? MB_SIZE : MB_SIZE*src_stride;
+ uint8_t tmp[src_stride*7*MB_SIZE]; //FIXME align
+ uint8_t *ptmp;
+ int x,y;
+
+ if(b_x<0){
+ lt= rt;
+ lb= rb;
+ }else if(b_x + 1 >= b_width){
+ rt= lt;
+ rb= lb;
+ }
+ if(b_y<0){
+ lt= lb;
+ rt= rb;
+ }else if(b_y + 1 >= b_height){
+ lb= lt;
+ rb= rt;
+ }
+
+ if(src_x<0){ //FIXME merge with prev & always round internal width upto *16
+ obmc -= src_x;
+ b_w += src_x;
+ if(!sliced && !offset_dst)
+ dst -= src_x;
+ src_x=0;
+ }else if(src_x + b_w > w){
+ b_w = w - src_x;
+ }
+ if(src_y<0){
+ obmc -= src_y*obmc_stride;
+ b_h += src_y;
+ if(!sliced && !offset_dst)
+ dst -= src_y*dst_stride;
+ src_y=0;
+ }else if(src_y + b_h> h){
+ b_h = h - src_y;
+ }
+
+ if(b_w<=0 || b_h<=0) return;
+
+assert(src_stride > 2*MB_SIZE + 5);
+ if(!sliced && offset_dst)
+ dst += src_x + src_y*dst_stride;
+ dst8+= src_x + src_y*src_stride;
+// src += src_x + src_y*src_stride;
+
+ ptmp= tmp + 3*tmp_step;
+ block[0]= ptmp;
+ ptmp+=tmp_step;
+ pred_block(s, block[0], tmp, src_stride, src_x, src_y, b_w, b_h, lt, plane_index, w, h);
+
+ if(same_block(lt, rt)){
+ block[1]= block[0];
+ }else{
+ block[1]= ptmp;
+ ptmp+=tmp_step;
+ pred_block(s, block[1], tmp, src_stride, src_x, src_y, b_w, b_h, rt, plane_index, w, h);
+ }
+
+ if(same_block(lt, lb)){
+ block[2]= block[0];
+ }else if(same_block(rt, lb)){
+ block[2]= block[1];
+ }else{
+ block[2]= ptmp;
+ ptmp+=tmp_step;
+ pred_block(s, block[2], tmp, src_stride, src_x, src_y, b_w, b_h, lb, plane_index, w, h);
+ }
+
+ if(same_block(lt, rb) ){
+ block[3]= block[0];
+ }else if(same_block(rt, rb)){
+ block[3]= block[1];
+ }else if(same_block(lb, rb)){
+ block[3]= block[2];
+ }else{
+ block[3]= ptmp;
+ pred_block(s, block[3], tmp, src_stride, src_x, src_y, b_w, b_h, rb, plane_index, w, h);
+ }
+#if 0
+ for(y=0; y<b_h; y++){
+ for(x=0; x<b_w; x++){
+ int v= obmc [x + y*obmc_stride] * block[3][x + y*src_stride] * (256/OBMC_MAX);
+ if(add) dst[x + y*dst_stride] += v;
+ else dst[x + y*dst_stride] -= v;
+ }
+ }
+ for(y=0; y<b_h; y++){
+ uint8_t *obmc2= obmc + (obmc_stride>>1);
+ for(x=0; x<b_w; x++){
+ int v= obmc2[x + y*obmc_stride] * block[2][x + y*src_stride] * (256/OBMC_MAX);
+ if(add) dst[x + y*dst_stride] += v;
+ else dst[x + y*dst_stride] -= v;
+ }
+ }
+ for(y=0; y<b_h; y++){
+ uint8_t *obmc3= obmc + obmc_stride*(obmc_stride>>1);
+ for(x=0; x<b_w; x++){
+ int v= obmc3[x + y*obmc_stride] * block[1][x + y*src_stride] * (256/OBMC_MAX);
+ if(add) dst[x + y*dst_stride] += v;
+ else dst[x + y*dst_stride] -= v;
+ }
+ }
+ for(y=0; y<b_h; y++){
+ uint8_t *obmc3= obmc + obmc_stride*(obmc_stride>>1);
+ uint8_t *obmc4= obmc3+ (obmc_stride>>1);
+ for(x=0; x<b_w; x++){
+ int v= obmc4[x + y*obmc_stride] * block[0][x + y*src_stride] * (256/OBMC_MAX);
+ if(add) dst[x + y*dst_stride] += v;
+ else dst[x + y*dst_stride] -= v;
+ }
+ }
+#else
+ if(sliced){
+ START_TIMER
+
+ s->dsp.inner_add_yblock(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8);
+ STOP_TIMER("inner_add_yblock")
+ }else
+ for(y=0; y<b_h; y++){
+ //FIXME ugly missue of obmc_stride
+ const uint8_t *obmc1= obmc + y*obmc_stride;
+ const uint8_t *obmc2= obmc1+ (obmc_stride>>1);
+ const uint8_t *obmc3= obmc1+ obmc_stride*(obmc_stride>>1);
+ const uint8_t *obmc4= obmc3+ (obmc_stride>>1);
+ for(x=0; x<b_w; x++){
+ int v= obmc1[x] * block[3][x + y*src_stride]
+ +obmc2[x] * block[2][x + y*src_stride]
+ +obmc3[x] * block[1][x + y*src_stride]
+ +obmc4[x] * block[0][x + y*src_stride];
+
+ v <<= 8 - LOG2_OBMC_MAX;
+ if(FRAC_BITS != 8){
+ v += 1<<(7 - FRAC_BITS);
+ v >>= 8 - FRAC_BITS;
+ }
+ if(add){
+ v += dst[x + y*dst_stride];
+ v = (v + (1<<(FRAC_BITS-1))) >> FRAC_BITS;
+ if(v&(~255)) v= ~(v>>31);
+ dst8[x + y*src_stride] = v;
+ }else{
+ dst[x + y*dst_stride] -= v;
+ }
+ }
+ }
+#endif
+}
+
+static av_always_inline void predict_slice_buffered(SnowContext *s, slice_buffer * sb, DWTELEM * old_buffer, int plane_index, int add, int mb_y){
+ Plane *p= &s->plane[plane_index];
+ const int mb_w= s->b_width << s->block_max_depth;
+ const int mb_h= s->b_height << s->block_max_depth;
+ int x, y, mb_x;
+ int block_size = MB_SIZE >> s->block_max_depth;
+ int block_w = plane_index ? block_size/2 : block_size;
+ const uint8_t *obmc = plane_index ? obmc_tab[s->block_max_depth+1] : obmc_tab[s->block_max_depth];
+ int obmc_stride= plane_index ? block_size : 2*block_size;
+ int ref_stride= s->current_picture.linesize[plane_index];
+ uint8_t *dst8= s->current_picture.data[plane_index];
+ int w= p->width;
+ int h= p->height;
+ START_TIMER
+
+ if(s->keyframe || (s->avctx->debug&512)){
+ if(mb_y==mb_h)
+ return;
+
+ if(add){
+ for(y=block_w*mb_y; y<FFMIN(h,block_w*(mb_y+1)); y++)
+ {
+// DWTELEM * line = slice_buffer_get_line(sb, y);
+ DWTELEM * line = sb->line[y];
+ for(x=0; x<w; x++)
+ {
+// int v= buf[x + y*w] + (128<<FRAC_BITS) + (1<<(FRAC_BITS-1));
+ int v= line[x] + (128<<FRAC_BITS) + (1<<(FRAC_BITS-1));
+ v >>= FRAC_BITS;
+ if(v&(~255)) v= ~(v>>31);
+ dst8[x + y*ref_stride]= v;
+ }
+ }
+ }else{
+ for(y=block_w*mb_y; y<FFMIN(h,block_w*(mb_y+1)); y++)
+ {
+// DWTELEM * line = slice_buffer_get_line(sb, y);
+ DWTELEM * line = sb->line[y];
+ for(x=0; x<w; x++)
+ {
+ line[x] -= 128 << FRAC_BITS;
+// buf[x + y*w]-= 128<<FRAC_BITS;
+ }
+ }
+ }
+
+ return;
+ }
+
+ for(mb_x=0; mb_x<=mb_w; mb_x++){
+ START_TIMER
+
+ add_yblock(s, 1, sb, old_buffer, dst8, obmc,
+ block_w*mb_x - block_w/2,
+ block_w*mb_y - block_w/2,
+ block_w, block_w,
+ w, h,
+ w, ref_stride, obmc_stride,
+ mb_x - 1, mb_y - 1,
+ add, 0, plane_index);
+
+ STOP_TIMER("add_yblock")
+ }
+
+ STOP_TIMER("predict_slice")
+}
+
+static av_always_inline void predict_slice(SnowContext *s, DWTELEM *buf, int plane_index, int add, int mb_y){
+ Plane *p= &s->plane[plane_index];
+ const int mb_w= s->b_width << s->block_max_depth;
+ const int mb_h= s->b_height << s->block_max_depth;
+ int x, y, mb_x;
+ int block_size = MB_SIZE >> s->block_max_depth;
+ int block_w = plane_index ? block_size/2 : block_size;
+ const uint8_t *obmc = plane_index ? obmc_tab[s->block_max_depth+1] : obmc_tab[s->block_max_depth];
+ const int obmc_stride= plane_index ? block_size : 2*block_size;
+ int ref_stride= s->current_picture.linesize[plane_index];
+ uint8_t *dst8= s->current_picture.data[plane_index];
+ int w= p->width;
+ int h= p->height;
+ START_TIMER
+
+ if(s->keyframe || (s->avctx->debug&512)){
+ if(mb_y==mb_h)
+ return;
+
+ if(add){
+ for(y=block_w*mb_y; y<FFMIN(h,block_w*(mb_y+1)); y++){
+ for(x=0; x<w; x++){
+ int v= buf[x + y*w] + (128<<FRAC_BITS) + (1<<(FRAC_BITS-1));
+ v >>= FRAC_BITS;
+ if(v&(~255)) v= ~(v>>31);
+ dst8[x + y*ref_stride]= v;
+ }
+ }
+ }else{
+ for(y=block_w*mb_y; y<FFMIN(h,block_w*(mb_y+1)); y++){
+ for(x=0; x<w; x++){
+ buf[x + y*w]-= 128<<FRAC_BITS;
+ }
+ }
+ }
+
+ return;
+ }
+
+ for(mb_x=0; mb_x<=mb_w; mb_x++){
+ START_TIMER
+
+ add_yblock(s, 0, NULL, buf, dst8, obmc,
+ block_w*mb_x - block_w/2,
+ block_w*mb_y - block_w/2,
+ block_w, block_w,
+ w, h,
+ w, ref_stride, obmc_stride,
+ mb_x - 1, mb_y - 1,
+ add, 1, plane_index);
+
+ STOP_TIMER("add_yblock")
+ }
+
+ STOP_TIMER("predict_slice")
+}
+
+static av_always_inline void predict_plane(SnowContext *s, DWTELEM *buf, int plane_index, int add){
+ const int mb_h= s->b_height << s->block_max_depth;
+ int mb_y;
+ for(mb_y=0; mb_y<=mb_h; mb_y++)
+ predict_slice(s, buf, plane_index, add, mb_y);
+}
+
+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];
+ const int block_size = MB_SIZE >> s->block_max_depth;
+ const int block_w = plane_index ? block_size/2 : block_size;
+ const uint8_t *obmc = plane_index ? obmc_tab[s->block_max_depth+1] : obmc_tab[s->block_max_depth];
+ const int obmc_stride= plane_index ? block_size : 2*block_size;
+ const int ref_stride= s->current_picture.linesize[plane_index];
+ uint8_t *src= s-> input_picture.data[plane_index];
+ DWTELEM *dst= (DWTELEM*)s->m.obmc_scratchpad + plane_index*block_size*block_size*4;
+ const int b_stride = s->b_width << s->block_max_depth;
+ const int w= p->width;
+ const int h= p->height;
+ int index= mb_x + mb_y*b_stride;
+ BlockNode *b= &s->block[index];
+ BlockNode backup= *b;
+ int ab=0;
+ int aa=0;
+
+ b->type|= BLOCK_INTRA;
+ b->color[plane_index]= 0;
+ memset(dst, 0, obmc_stride*obmc_stride*sizeof(DWTELEM));
+
+ for(i=0; i<4; i++){
+ int mb_x2= mb_x + (i &1) - 1;
+ int mb_y2= mb_y + (i>>1) - 1;
+ int x= block_w*mb_x2 + block_w/2;
+ int y= block_w*mb_y2 + block_w/2;
+
+ add_yblock(s, 0, NULL, dst + ((i&1)+(i>>1)*obmc_stride)*block_w, NULL, obmc,
+ x, y, block_w, block_w, w, h, obmc_stride, ref_stride, obmc_stride, mb_x2, mb_y2, 0, 0, plane_index);
+
+ for(y2= FFMAX(y, 0); y2<FFMIN(h, y+block_w); y2++){
+ for(x2= FFMAX(x, 0); x2<FFMIN(w, x+block_w); x2++){
+ int index= x2-(block_w*mb_x - block_w/2) + (y2-(block_w*mb_y - block_w/2))*obmc_stride;
+ int obmc_v= obmc[index];
+ int d;
+ if(y<0) obmc_v += obmc[index + block_w*obmc_stride];
+ if(x<0) obmc_v += obmc[index + block_w];
+ if(y+block_w>h) obmc_v += obmc[index - block_w*obmc_stride];
+ if(x+block_w>w) obmc_v += obmc[index - block_w];
+ //FIXME precalc this or simplify it somehow else
+
+ d = -dst[index] + (1<<(FRAC_BITS-1));
+ dst[index] = d;
+ ab += (src[x2 + y2*ref_stride] - (d>>FRAC_BITS)) * obmc_v;
+ aa += obmc_v * obmc_v; //FIXME precalclate this
+ }
+ }
+ }
+ *b= backup;
+
+ return av_clip(((ab<<LOG2_OBMC_MAX) + aa/2)/aa, 0, 255); //FIXME we shouldnt need cliping
+}
+
+static inline int get_block_bits(SnowContext *s, int x, int y, int w){
+ const int b_stride = s->b_width << s->block_max_depth;
+ const int b_height = s->b_height<< s->block_max_depth;
+ int index= x + y*b_stride;
+ const BlockNode *b = &s->block[index];
+ const BlockNode *left = x ? &s->block[index-1] : &null_block;
+ const BlockNode *top = y ? &s->block[index-b_stride] : &null_block;
+ const BlockNode *tl = y && x ? &s->block[index-b_stride-1] : left;
+ const BlockNode *tr = y && x+w<b_stride ? &s->block[index-b_stride+w] : tl;
+ int dmx, dmy;
+// int mx_context= av_log2(2*FFABS(left->mx - top->mx));
+// int my_context= av_log2(2*FFABS(left->my - top->my));
+
+ if(x<0 || x>=b_stride || y>=b_height)
+ return 0;
+/*
+1 0 0
+01X 1-2 1
+001XX 3-6 2-3
+0001XXX 7-14 4-7
+00001XXXX 15-30 8-15
+*/
+//FIXME try accurate rate
+//FIXME intra and inter predictors if surrounding blocks arent the same type
+ if(b->type & BLOCK_INTRA){
+ return 3+2*( av_log2(2*FFABS(left->color[0] - b->color[0]))
+ + av_log2(2*FFABS(left->color[1] - b->color[1]))
+ + av_log2(2*FFABS(left->color[2] - b->color[2])));
+ }else{
+ pred_mv(s, &dmx, &dmy, b->ref, left, top, tr);
+ dmx-= b->mx;
+ dmy-= b->my;
+ return 2*(1 + av_log2(2*FFABS(dmx)) //FIXME kill the 2* can be merged in lambda
+ + av_log2(2*FFABS(dmy))
+ + av_log2(2*b->ref));
+ }
+}
+
+static int get_block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index, const uint8_t *obmc_edged){
+ Plane *p= &s->plane[plane_index];
+ const int block_size = MB_SIZE >> s->block_max_depth;
+ const int block_w = plane_index ? block_size/2 : block_size;
+ const int obmc_stride= plane_index ? block_size : 2*block_size;
+ const int ref_stride= s->current_picture.linesize[plane_index];
+ uint8_t *dst= s->current_picture.data[plane_index];
+ uint8_t *src= s-> input_picture.data[plane_index];
+ DWTELEM *pred= (DWTELEM*)s->m.obmc_scratchpad + plane_index*block_size*block_size*4;
+ uint8_t cur[ref_stride*2*MB_SIZE]; //FIXME alignment
+ uint8_t tmp[ref_stride*(2*MB_SIZE+5)];
+ const int b_stride = s->b_width << s->block_max_depth;
+ const int b_height = s->b_height<< s->block_max_depth;
+ const int w= p->width;
+ const int h= p->height;
+ int distortion;
+ int rate= 0;
+ const int penalty_factor= get_penalty_factor(s->lambda, s->lambda2, s->avctx->me_cmp);
+ int sx= block_w*mb_x - block_w/2;
+ int sy= block_w*mb_y - block_w/2;
+ int x0= FFMAX(0,-sx);
+ int y0= FFMAX(0,-sy);
+ int x1= FFMIN(block_w*2, w-sx);
+ int y1= FFMIN(block_w*2, h-sy);
+ int i,x,y;
+
+ pred_block(s, cur, tmp, ref_stride, sx, sy, block_w*2, block_w*2, &s->block[mb_x + mb_y*b_stride], plane_index, w, h);
+
+ for(y=y0; y<y1; y++){
+ const uint8_t *obmc1= obmc_edged + y*obmc_stride;
+ const DWTELEM *pred1 = pred + y*obmc_stride;
+ uint8_t *cur1 = cur + y*ref_stride;
+ uint8_t *dst1 = dst + sx + (sy+y)*ref_stride;
+ for(x=x0; x<x1; x++){
+ int v = (cur1[x] * obmc1[x]) << (FRAC_BITS - LOG2_OBMC_MAX);
+ v = (v + pred1[x]) >> FRAC_BITS;
+ if(v&(~255)) v= ~(v>>31);
+ dst1[x] = v;
+ }
+ }
+
+ /* copy the regions where obmc[] = (uint8_t)256 */
+ if(LOG2_OBMC_MAX == 8
+ && (mb_x == 0 || mb_x == b_stride-1)
+ && (mb_y == 0 || mb_y == b_height-1)){
+ if(mb_x == 0)
+ x1 = block_w;
+ else
+ x0 = block_w;
+ if(mb_y == 0)
+ y1 = block_w;
+ else
+ y0 = block_w;
+ for(y=y0; y<y1; y++)
+ memcpy(dst + sx+x0 + (sy+y)*ref_stride, cur + x0 + y*ref_stride, x1-x0);
+ }
+
+ if(block_w==16){
+ /* FIXME rearrange dsputil to fit 32x32 cmp functions */
+ /* FIXME check alignment of the cmp wavelet vs the encoding wavelet */
+ /* FIXME cmps overlap but don't cover the wavelet's whole support,
+ * so improving the score of one block is not strictly guaranteed to
+ * improve the score of the whole frame, so iterative motion est
+ * doesn't 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);
+ 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);
+ else{
+ distortion = 0;
+ for(i=0; i<4; i++){
+ int off = sx+16*(i&1) + (sy+16*(i>>1))*ref_stride;
+ distortion += s->dsp.me_cmp[0](&s->m, src + off, dst + off, ref_stride, 16);
+ }
+ }
+ }else{
+ assert(block_w==8);
+ distortion = s->dsp.me_cmp[0](&s->m, src + sx + sy*ref_stride, dst + sx + sy*ref_stride, ref_stride, block_w*2);
+ }
+
+ if(plane_index==0){
+ for(i=0; i<4; i++){
+/* ..RRr
+ * .RXx.
+ * rxx..
+ */
+ rate += get_block_bits(s, mb_x + (i&1) - (i>>1), mb_y + (i>>1), 1);
+ }
+ if(mb_x == b_stride-2)
+ rate += get_block_bits(s, mb_x + 1, mb_y + 1, 1);
+ }
+ return distortion + rate*penalty_factor;
+}
+
+static int get_4block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index){
+ int i, y2;
+ Plane *p= &s->plane[plane_index];
+ const int block_size = MB_SIZE >> s->block_max_depth;
+ const int block_w = plane_index ? block_size/2 : block_size;
+ const uint8_t *obmc = plane_index ? obmc_tab[s->block_max_depth+1] : obmc_tab[s->block_max_depth];
+ const int obmc_stride= plane_index ? block_size : 2*block_size;
+ const int ref_stride= s->current_picture.linesize[plane_index];
+ uint8_t *dst= s->current_picture.data[plane_index];
+ uint8_t *src= s-> input_picture.data[plane_index];
+ static const DWTELEM zero_dst[4096]; //FIXME
+ const int b_stride = s->b_width << s->block_max_depth;
+ const int w= p->width;
+ const int h= p->height;
+ int distortion= 0;
+ int rate= 0;
+ const int penalty_factor= get_penalty_factor(s->lambda, s->lambda2, s->avctx->me_cmp);
+
+ for(i=0; i<9; i++){
+ int mb_x2= mb_x + (i%3) - 1;
+ int mb_y2= mb_y + (i/3) - 1;
+ int x= block_w*mb_x2 + block_w/2;
+ int y= block_w*mb_y2 + block_w/2;
+
+ add_yblock(s, 0, NULL, zero_dst, dst, obmc,
+ x, y, block_w, block_w, w, h, /*dst_stride*/0, ref_stride, obmc_stride, mb_x2, mb_y2, 1, 1, plane_index);
+
+ //FIXME find a cleaner/simpler way to skip the outside stuff
+ for(y2= y; y2<0; y2++)
+ memcpy(dst + x + y2*ref_stride, src + x + y2*ref_stride, block_w);
+ for(y2= h; y2<y+block_w; y2++)
+ memcpy(dst + x + y2*ref_stride, src + x + y2*ref_stride, block_w);
+ if(x<0){
+ for(y2= y; y2<y+block_w; y2++)
+ memcpy(dst + x + y2*ref_stride, src + x + y2*ref_stride, -x);
+ }
+ if(x+block_w > w){
+ for(y2= y; y2<y+block_w; y2++)
+ memcpy(dst + w + y2*ref_stride, src + w + y2*ref_stride, x+block_w - w);
+ }
+
+ assert(block_w== 8 || block_w==16);
+ distortion += s->dsp.me_cmp[block_w==8](&s->m, src + x + y*ref_stride, dst + x + y*ref_stride, ref_stride, block_w);
+ }
+
+ if(plane_index==0){
+ BlockNode *b= &s->block[mb_x+mb_y*b_stride];
+ int merged= same_block(b,b+1) && same_block(b,b+b_stride) && same_block(b,b+b_stride+1);
+
+/* ..RRRr
+ * .RXXx.
+ * .RXXx.
+ * rxxx.
+ */
+ if(merged)
+ rate = get_block_bits(s, mb_x, mb_y, 2);
+ for(i=merged?4:0; i<9; i++){
+ static const int dxy[9][2] = {{0,0},{1,0},{0,1},{1,1},{2,0},{2,1},{-1,2},{0,2},{1,2}};
+ rate += get_block_bits(s, mb_x + dxy[i][0], mb_y + dxy[i][1], 1);
+ }
+ }
+ return distortion + rate*penalty_factor;
+}
+
+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];
+ BlockNode backup= *block;
+ int rd, index, value;
+
+ assert(mb_x>=0 && mb_y>=0);
+ assert(mb_x<b_stride);
+
+ if(intra){
+ block->color[0] = p[0];
+ block->color[1] = p[1];
+ block->color[2] = p[2];
+ block->type |= BLOCK_INTRA;
+ }else{
+ index= (p[0] + 31*p[1]) & (ME_CACHE_SIZE-1);
+ value= s->me_cache_generation + (p[0]>>10) + (p[1]<<6) + (block->ref<<12);
+ if(s->me_cache[index] == value)
+ return 0;
+ s->me_cache[index]= value;
+
+ block->mx= p[0];
+ block->my= p[1];
+ block->type &= ~BLOCK_INTRA;
+ }
+
+ rd= get_block_rd(s, mb_x, mb_y, 0, obmc_edged);
+
+//FIXME chroma
+ if(rd < *best_rd){
+ *best_rd= rd;
+ return 1;
+ }else{
+ *block= backup;
+ return 0;
+ }
+}
+
+/* special case for int[2] args we discard afterward, fixes compilation prob with gcc 2.95 */
+static av_always_inline int check_block_inter(SnowContext *s, int mb_x, int mb_y, int p0, int p1, const uint8_t *obmc_edged, int *best_rd){
+ int p[2] = {p0, p1};
+ return check_block(s, mb_x, mb_y, p, 0, obmc_edged, best_rd);
+}
+
+static av_always_inline int check_4block_inter(SnowContext *s, int mb_x, int mb_y, int p0, int p1, int ref, int *best_rd){
+ const int b_stride= s->b_width << s->block_max_depth;
+ BlockNode *block= &s->block[mb_x + mb_y * b_stride];
+ BlockNode backup[4]= {block[0], block[1], block[b_stride], block[b_stride+1]};
+ int rd, index, value;
+
+ assert(mb_x>=0 && mb_y>=0);
+ assert(mb_x<b_stride);
+ assert(((mb_x|mb_y)&1) == 0);
+
+ index= (p0 + 31*p1) & (ME_CACHE_SIZE-1);
+ value= s->me_cache_generation + (p0>>10) + (p1<<6) + (block->ref<<12);
+ if(s->me_cache[index] == value)
+ return 0;
+ s->me_cache[index]= value;
+
+ block->mx= p0;
+ block->my= p1;
+ block->ref= ref;
+ block->type &= ~BLOCK_INTRA;
+ block[1]= block[b_stride]= block[b_stride+1]= *block;
+
+ rd= get_4block_rd(s, mb_x, mb_y, 0);
+
+//FIXME chroma
+ if(rd < *best_rd){
+ *best_rd= rd;
+ return 1;
+ }else{
+ block[0]= backup[0];
+ block[1]= backup[1];
+ block[b_stride]= backup[2];
+ block[b_stride+1]= backup[3];
+ return 0;
+ }
+}
+
+static void iterative_me(SnowContext *s){
+ int pass, mb_x, mb_y;
+ const int b_width = s->b_width << s->block_max_depth;
+ const int b_height= s->b_height << s->block_max_depth;
+ const int b_stride= b_width;
+ int color[3];
+
+ {
+ RangeCoder r = s->c;
+ uint8_t state[sizeof(s->block_state)];
+ memcpy(state, s->block_state, sizeof(s->block_state));
+ for(mb_y= 0; mb_y<s->b_height; mb_y++)
+ for(mb_x= 0; mb_x<s->b_width; mb_x++)
+ encode_q_branch(s, 0, mb_x, mb_y);
+ s->c = r;
+ memcpy(s->block_state, state, sizeof(s->block_state));
+ }
+
+ for(pass=0; pass<25; pass++){
+ int change= 0;
+
+ for(mb_y= 0; mb_y<b_height; mb_y++){
+ for(mb_x= 0; mb_x<b_width; mb_x++){
+ int dia_change, i, j, ref;
+ int best_rd= INT_MAX, ref_rd;
+ BlockNode backup, ref_b;
+ const int index= mb_x + mb_y * b_stride;
+ BlockNode *block= &s->block[index];
+ BlockNode *tb = mb_y ? &s->block[index-b_stride ] : NULL;
+ BlockNode *lb = mb_x ? &s->block[index -1] : NULL;
+ BlockNode *rb = mb_x+1<b_width ? &s->block[index +1] : NULL;
+ BlockNode *bb = mb_y+1<b_height ? &s->block[index+b_stride ] : NULL;
+ BlockNode *tlb= mb_x && mb_y ? &s->block[index-b_stride-1] : NULL;
+ BlockNode *trb= mb_x+1<b_width && mb_y ? &s->block[index-b_stride+1] : NULL;
+ BlockNode *blb= mb_x && mb_y+1<b_height ? &s->block[index+b_stride-1] : NULL;
+ BlockNode *brb= mb_x+1<b_width && mb_y+1<b_height ? &s->block[index+b_stride+1] : NULL;
+ const int b_w= (MB_SIZE >> s->block_max_depth);
+ uint8_t obmc_edged[b_w*2][b_w*2];
+
+ if(pass && (block->type & BLOCK_OPT))
+ continue;
+ block->type |= BLOCK_OPT;
+
+ backup= *block;
+
+ if(!s->me_cache_generation)
+ memset(s->me_cache, 0, sizeof(s->me_cache));
+ s->me_cache_generation += 1<<22;
+
+ //FIXME precalc
+ {
+ int x, y;
+ memcpy(obmc_edged, obmc_tab[s->block_max_depth], b_w*b_w*4);
+ if(mb_x==0)
+ for(y=0; y<b_w*2; y++)
+ memset(obmc_edged[y], obmc_edged[y][0] + obmc_edged[y][b_w-1], b_w);
+ if(mb_x==b_stride-1)
+ for(y=0; y<b_w*2; y++)
+ memset(obmc_edged[y]+b_w, obmc_edged[y][b_w] + obmc_edged[y][b_w*2-1], b_w);
+ if(mb_y==0){
+ for(x=0; x<b_w*2; x++)
+ obmc_edged[0][x] += obmc_edged[b_w-1][x];
+ for(y=1; y<b_w; y++)
+ memcpy(obmc_edged[y], obmc_edged[0], b_w*2);
+ }
+ if(mb_y==b_height-1){
+ for(x=0; x<b_w*2; x++)
+ obmc_edged[b_w*2-1][x] += obmc_edged[b_w][x];
+ for(y=b_w; y<b_w*2-1; y++)
+ memcpy(obmc_edged[y], obmc_edged[b_w*2-1], b_w*2);
+ }
+ }
+
+ //skip stuff outside the picture
+ if(mb_x==0 || mb_y==0 || mb_x==b_width-1 || mb_y==b_height-1)
+ {
+ uint8_t *src= s-> input_picture.data[0];
+ uint8_t *dst= s->current_picture.data[0];
+ const int stride= s->current_picture.linesize[0];
+ const int block_w= MB_SIZE >> s->block_max_depth;
+ const int sx= block_w*mb_x - block_w/2;
+ const int sy= block_w*mb_y - block_w/2;
+ const int w= s->plane[0].width;
+ const int h= s->plane[0].height;
+ int y;
+
+ for(y=sy; y<0; y++)
+ memcpy(dst + sx + y*stride, src + sx + y*stride, block_w*2);
+ for(y=h; y<sy+block_w*2; y++)
+ memcpy(dst + sx + y*stride, src + sx + y*stride, block_w*2);
+ if(sx<0){
+ for(y=sy; y<sy+block_w*2; y++)
+ memcpy(dst + sx + y*stride, src + sx + y*stride, -sx);
+ }
+ if(sx+block_w*2 > w){
+ for(y=sy; y<sy+block_w*2; y++)
+ memcpy(dst + w + y*stride, src + w + y*stride, sx+block_w*2 - w);
+ }
+ }
+
+ // intra(black) = neighbors' contribution to the current block
+ for(i=0; i<3; i++)
+ color[i]= get_dc(s, mb_x, mb_y, i);
+
+ // get previous score (cant be cached due to OBMC)
+ if(pass > 0 && (block->type&BLOCK_INTRA)){
+ int color0[3]= {block->color[0], block->color[1], block->color[2]};
+ check_block(s, mb_x, mb_y, color0, 1, *obmc_edged, &best_rd);
+ }else
+ check_block_inter(s, mb_x, mb_y, block->mx, block->my, *obmc_edged, &best_rd);
+
+ ref_b= *block;
+ ref_rd= best_rd;
+ for(ref=0; ref < s->ref_frames; ref++){
+ int16_t (*mvr)[2]= &s->ref_mvs[ref][index];
+ if(s->ref_scores[ref][index] > s->ref_scores[ref_b.ref][index]*3/2) //FIXME tune threshold
+ continue;
+ block->ref= ref;
+ best_rd= INT_MAX;
+
+ check_block_inter(s, mb_x, mb_y, mvr[0][0], mvr[0][1], *obmc_edged, &best_rd);
+ check_block_inter(s, mb_x, mb_y, 0, 0, *obmc_edged, &best_rd);
+ if(tb)
+ check_block_inter(s, mb_x, mb_y, mvr[-b_stride][0], mvr[-b_stride][1], *obmc_edged, &best_rd);
+ if(lb)
+ check_block_inter(s, mb_x, mb_y, mvr[-1][0], mvr[-1][1], *obmc_edged, &best_rd);
+ if(rb)
+ check_block_inter(s, mb_x, mb_y, mvr[1][0], mvr[1][1], *obmc_edged, &best_rd);
+ if(bb)
+ check_block_inter(s, mb_x, mb_y, mvr[b_stride][0], mvr[b_stride][1], *obmc_edged, &best_rd);
+
+ /* fullpel ME */
+ //FIXME avoid subpel interpol / round to nearest integer
+ do{
+ dia_change=0;
+ for(i=0; i<FFMAX(s->avctx->dia_size, 1); i++){
+ for(j=0; j<i; j++){
+ dia_change |= check_block_inter(s, mb_x, mb_y, block->mx+4*(i-j), block->my+(4*j), *obmc_edged, &best_rd);
+ dia_change |= check_block_inter(s, mb_x, mb_y, block->mx-4*(i-j), block->my-(4*j), *obmc_edged, &best_rd);
+ dia_change |= check_block_inter(s, mb_x, mb_y, block->mx+4*(i-j), block->my-(4*j), *obmc_edged, &best_rd);
+ dia_change |= check_block_inter(s, mb_x, mb_y, block->mx-4*(i-j), block->my+(4*j), *obmc_edged, &best_rd);
+ }
+ }
+ }while(dia_change);
+ /* subpel ME */
+ do{
+ static const int square[8][2]= {{+1, 0},{-1, 0},{ 0,+1},{ 0,-1},{+1,+1},{-1,-1},{+1,-1},{-1,+1},};
+ dia_change=0;
+ for(i=0; i<8; i++)
+ dia_change |= check_block_inter(s, mb_x, mb_y, block->mx+square[i][0], block->my+square[i][1], *obmc_edged, &best_rd);
+ }while(dia_change);
+ //FIXME or try the standard 2 pass qpel or similar
+
+ mvr[0][0]= block->mx;
+ mvr[0][1]= block->my;
+ if(ref_rd > best_rd){
+ ref_rd= best_rd;
+ ref_b= *block;
+ }
+ }
+ best_rd= ref_rd;
+ *block= ref_b;
+#if 1
+ check_block(s, mb_x, mb_y, color, 1, *obmc_edged, &best_rd);
+ //FIXME RD style color selection
+#endif
+ if(!same_block(block, &backup)){
+ if(tb ) tb ->type &= ~BLOCK_OPT;
+ if(lb ) lb ->type &= ~BLOCK_OPT;
+ if(rb ) rb ->type &= ~BLOCK_OPT;
+ if(bb ) bb ->type &= ~BLOCK_OPT;
+ if(tlb) tlb->type &= ~BLOCK_OPT;
+ if(trb) trb->type &= ~BLOCK_OPT;
+ if(blb) blb->type &= ~BLOCK_OPT;
+ if(brb) brb->type &= ~BLOCK_OPT;
+ change ++;
+ }
+ }
+ }
+ av_log(NULL, AV_LOG_ERROR, "pass:%d changed:%d\n", pass, change);
+ if(!change)
+ break;
+ }
+
+ if(s->block_max_depth == 1){
+ int change= 0;
+ for(mb_y= 0; mb_y<b_height; mb_y+=2){
+ for(mb_x= 0; mb_x<b_width; mb_x+=2){
+ int i;
+ int best_rd, init_rd;
+ const int index= mb_x + mb_y * b_stride;
+ BlockNode *b[4];
+
+ b[0]= &s->block[index];
+ b[1]= b[0]+1;
+ b[2]= b[0]+b_stride;
+ b[3]= b[2]+1;
+ if(same_block(b[0], b[1]) &&
+ same_block(b[0], b[2]) &&
+ same_block(b[0], b[3]))
+ continue;
+
+ if(!s->me_cache_generation)
+ memset(s->me_cache, 0, sizeof(s->me_cache));
+ s->me_cache_generation += 1<<22;
+
+ init_rd= best_rd= get_4block_rd(s, mb_x, mb_y, 0);
+
+ //FIXME more multiref search?
+ check_4block_inter(s, mb_x, mb_y,
+ (b[0]->mx + b[1]->mx + b[2]->mx + b[3]->mx + 2) >> 2,
+ (b[0]->my + b[1]->my + b[2]->my + b[3]->my + 2) >> 2, 0, &best_rd);
+
+ for(i=0; i<4; i++)
+ if(!(b[i]->type&BLOCK_INTRA))
+ check_4block_inter(s, mb_x, mb_y, b[i]->mx, b[i]->my, b[i]->ref, &best_rd);
+
+ if(init_rd != best_rd)
+ change++;
+ }
+ }
+ av_log(NULL, AV_LOG_ERROR, "pass:4mv changed:%d\n", change*4);
+ }
+}
+
+static void quantize(SnowContext *s, SubBand *b, DWTELEM *src, int stride, int bias){
+ const int level= b->level;
+ const int w= b->width;
+ const int h= b->height;
+ const int qlog= av_clip(s->qlog + b->qlog, 0, QROOT*16);
+ const int qmul= qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT);
+ int x,y, thres1, thres2;
+// START_TIMER
+
+ if(s->qlog == LOSSLESS_QLOG) return;
+
+ bias= bias ? 0 : (3*qmul)>>3;
+ thres1= ((qmul - bias)>>QEXPSHIFT) - 1;
+ thres2= 2*thres1;
+
+ if(!bias){
+ for(y=0; y<h; y++){
+ for(x=0; x<w; x++){
+ int i= src[x + y*stride];
+
+ if((unsigned)(i+thres1) > thres2){
+ if(i>=0){
+ i<<= QEXPSHIFT;
+ i/= qmul; //FIXME optimize
+ src[x + y*stride]= i;
+ }else{
+ i= -i;
+ i<<= QEXPSHIFT;
+ i/= qmul; //FIXME optimize
+ src[x + y*stride]= -i;
+ }
+ }else
+ src[x + y*stride]= 0;
+ }
+ }
+ }else{
+ for(y=0; y<h; y++){
+ for(x=0; x<w; x++){
+ int i= src[x + y*stride];
+
+ if((unsigned)(i+thres1) > thres2){
+ if(i>=0){
+ i<<= QEXPSHIFT;
+ i= (i + bias) / qmul; //FIXME optimize
+ src[x + y*stride]= i;
+ }else{
+ i= -i;
+ i<<= QEXPSHIFT;
+ i= (i + bias) / qmul; //FIXME optimize
+ src[x + y*stride]= -i;
+ }
+ }else
+ src[x + y*stride]= 0;
+ }
+ }
+ }
+ if(level+1 == s->spatial_decomposition_count){
+// STOP_TIMER("quantize")
+ }
+}
+
+static void dequantize_slice_buffered(SnowContext *s, slice_buffer * sb, SubBand *b, DWTELEM *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;
+ START_TIMER
+
+ if(s->qlog == LOSSLESS_QLOG) return;
+
+ for(y=start_y; y<end_y; y++){
+// DWTELEM * line = slice_buffer_get_line_from_address(sb, src + (y * stride));
+ DWTELEM * line = slice_buffer_get_line(sb, (y * b->stride_line) + b->buf_y_offset) + b->buf_x_offset;
+ for(x=0; x<w; x++){
+ int i= line[x];
+ if(i<0){
+ line[x]= -((-i*qmul + qadd)>>(QEXPSHIFT)); //FIXME try different bias
+ }else if(i>0){
+ line[x]= (( i*qmul + qadd)>>(QEXPSHIFT));
+ }
+ }
+ }
+ if(w > 200 /*level+1 == s->spatial_decomposition_count*/){
+ STOP_TIMER("dquant")
+ }
+}
+
+static void dequantize(SnowContext *s, SubBand *b, DWTELEM *src, int stride){
+ const int w= b->width;
+ const int h= b->height;
+ 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;
+ START_TIMER
+
+ if(s->qlog == LOSSLESS_QLOG) return;
+
+ for(y=0; y<h; y++){
+ for(x=0; x<w; x++){
+ int i= src[x + y*stride];
+ if(i<0){
+ src[x + y*stride]= -((-i*qmul + qadd)>>(QEXPSHIFT)); //FIXME try different bias
+ }else if(i>0){
+ src[x + y*stride]= (( i*qmul + qadd)>>(QEXPSHIFT));
+ }
+ }
+ }
+ if(w > 200 /*level+1 == s->spatial_decomposition_count*/){
+ STOP_TIMER("dquant")
+ }
+}
+
+static void decorrelate(SnowContext *s, SubBand *b, DWTELEM *src, int stride, int inverse, int use_median){
+ const int w= b->width;
+ const int h= b->height;
+ int x,y;
+
+ for(y=h-1; y>=0; y--){
+ for(x=w-1; x>=0; x--){
+ int i= x + y*stride;
+
+ if(x){
+ if(use_median){
+ if(y && x+1<w) src[i] -= mid_pred(src[i - 1], src[i - stride], src[i - stride + 1]);
+ else src[i] -= src[i - 1];
+ }else{
+ if(y) src[i] -= mid_pred(src[i - 1], src[i - stride], src[i - 1] + src[i - stride] - src[i - 1 - stride]);
+ else src[i] -= src[i - 1];
+ }
+ }else{
+ if(y) src[i] -= src[i - stride];
+ }
+ }
+ }
+}
+
+static void correlate_slice_buffered(SnowContext *s, slice_buffer * sb, SubBand *b, DWTELEM *src, int stride, int inverse, int use_median, int start_y, int end_y){
+ const int w= b->width;
+ int x,y;
+
+// START_TIMER
+
+ DWTELEM * line=0; // silence silly "could be used without having been initialized" warning
+ DWTELEM * 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; y<end_y; y++){
+ prev = line;
+// line = slice_buffer_get_line_from_address(sb, src + (y * stride));
+ line = slice_buffer_get_line(sb, (y * b->stride_line) + b->buf_y_offset) + b->buf_x_offset;
+ for(x=0; x<w; x++){
+ if(x){
+ if(use_median){
+ if(y && x+1<w) line[x] += mid_pred(line[x - 1], prev[x], prev[x + 1]);
+ else line[x] += line[x - 1];
+ }else{
+ if(y) line[x] += mid_pred(line[x - 1], prev[x], line[x - 1] + prev[x] - prev[x - 1]);
+ else line[x] += line[x - 1];
+ }
+ }else{
+ if(y) line[x] += prev[x];
+ }
+ }
+ }
+
+// STOP_TIMER("correlate")
+}
+
+static void correlate(SnowContext *s, SubBand *b, DWTELEM *src, int stride, int inverse, int use_median){
+ const int w= b->width;
+ const int h= b->height;
+ int x,y;
+
+ for(y=0; y<h; y++){
+ for(x=0; x<w; x++){
+ int i= x + y*stride;
+
+ if(x){
+ if(use_median){
+ if(y && x+1<w) src[i] += mid_pred(src[i - 1], src[i - stride], src[i - stride + 1]);
+ else src[i] += src[i - 1];
+ }else{
+ if(y) src[i] += mid_pred(src[i - 1], src[i - stride], src[i - 1] + src[i - stride] - src[i - 1 - stride]);
+ else src[i] += src[i - 1];
+ }
+ }else{
+ if(y) src[i] += src[i - stride];
+ }
+ }
+ }
+}
+
+static void encode_header(SnowContext *s){
+ int plane_index, level, orientation;
+ uint8_t kstate[32];
+
+ memset(kstate, MID_STATE, sizeof(kstate));
+
+ put_rac(&s->c, kstate, s->keyframe);
+ if(s->keyframe || s->always_reset){
+ reset_contexts(s);
+ s->last_spatial_decomposition_type=
+ s->last_qlog=
+ s->last_qbias=
+ s->last_mv_scale=
+ s->last_block_max_depth= 0;
+ }
+ if(s->keyframe){
+ put_symbol(&s->c, s->header_state, s->version, 0);
+ put_rac(&s->c, s->header_state, s->always_reset);
+ put_symbol(&s->c, s->header_state, s->temporal_decomposition_type, 0);
+ put_symbol(&s->c, s->header_state, s->temporal_decomposition_count, 0);
+ put_symbol(&s->c, s->header_state, s->spatial_decomposition_count, 0);
+ put_symbol(&s->c, s->header_state, s->colorspace_type, 0);
+ put_symbol(&s->c, s->header_state, s->chroma_h_shift, 0);
+ put_symbol(&s->c, s->header_state, s->chroma_v_shift, 0);
+ put_rac(&s->c, s->header_state, s->spatial_scalability);
+// put_rac(&s->c, s->header_state, s->rate_scalability);
+ put_symbol(&s->c, s->header_state, s->max_ref_frames-1, 0);
+
+ for(plane_index=0; plane_index<2; plane_index++){
+ for(level=0; level<s->spatial_decomposition_count; level++){
+ for(orientation=level ? 1:0; orientation<4; orientation++){
+ if(orientation==2) continue;
+ put_symbol(&s->c, s->header_state, s->plane[plane_index].band[level][orientation].qlog, 1);
+ }
+ }
+ }
+ }
+ put_symbol(&s->c, s->header_state, s->spatial_decomposition_type - s->last_spatial_decomposition_type, 1);
+ put_symbol(&s->c, s->header_state, s->qlog - s->last_qlog , 1);
+ put_symbol(&s->c, s->header_state, s->mv_scale - s->last_mv_scale, 1);
+ put_symbol(&s->c, s->header_state, s->qbias - s->last_qbias , 1);
+ put_symbol(&s->c, s->header_state, s->block_max_depth - s->last_block_max_depth, 1);
+
+ s->last_spatial_decomposition_type= s->spatial_decomposition_type;
+ s->last_qlog = s->qlog;
+ s->last_qbias = s->qbias;
+ s->last_mv_scale = s->mv_scale;
+ s->last_block_max_depth = s->block_max_depth;
+}
+
+static int decode_header(SnowContext *s){
+ int plane_index, level, orientation;
+ 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){
+ s->version= get_symbol(&s->c, s->header_state, 0);
+ if(s->version>0){
+ av_log(s->avctx, AV_LOG_ERROR, "version %d not supported", s->version);
+ return -1;
+ }
+ 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);
+ s->spatial_decomposition_count= get_symbol(&s->c, s->header_state, 0);
+ 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);
+ s->max_ref_frames= get_symbol(&s->c, s->header_state, 0)+1;
+
+ for(plane_index=0; plane_index<3; plane_index++){
+ for(level=0; level<s->spatial_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;
+ }
+ }
+ }
+ }
+
+ s->spatial_decomposition_type+= get_symbol(&s->c, s->header_state, 1);
+ if(s->spatial_decomposition_type > 2){
+ av_log(s->avctx, AV_LOG_ERROR, "spatial_decomposition_type %d not supported", s->spatial_decomposition_type);
+ 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; i<QROOT; i++){
+ qexp[i]= lrintf(v);
+ v *= pow(2, 1.0 / QROOT);
+ }
+}
+
+static int common_init(AVCodecContext *avctx){
+ SnowContext *s = avctx->priv_data;
+ int width, height;
+ int level, orientation, plane_index, dec;
+ int i, j;
+
+ s->avctx= avctx;
+
+ 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= s->spatial_decomposition_count= 5;
+ s->spatial_decomposition_type= avctx->prediction_method; //FIXME add decorrelator type r transform_type
+
+ s->chroma_h_shift= 1; //FIXME XXX
+ s->chroma_v_shift= 1;
+
+// dec += FFMAX(s->chroma_h_shift, s->chroma_v_shift);
+
+ width= s->avctx->width;
+ height= s->avctx->height;
+
+ s->spatial_dwt_buffer= av_mallocz(width*height*sizeof(DWTELEM));
+
+ s->mv_scale= (s->avctx->flags & CODEC_FLAG_QPEL) ? 2 : 4;
+ s->block_max_depth= (s->avctx->flags & CODEC_FLAG_4MV) ? 1 : 0;
+
+ 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;
+//av_log(NULL, AV_LOG_DEBUG, "%d %d\n", w, 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;
+ }
+
+ if(level)
+ b->parent= &s->plane[plane_index].band[level-1][orientation];
+ b->x_coeff=av_mallocz(((b->width+1) * b->height+1)*sizeof(x_and_coeff));
+ }
+ w= (w+1)>>1;
+ h= (h+1)>>1;
+ }
+ }
+
+ for(i=0; i<MAX_REF_FRAMES; i++)
+ for(j=0; j<MAX_REF_FRAMES; j++)
+ scale_mv_ref[i][j] = 256*(i+1)/(j+1);
+
+ reset_contexts(s);
+/*
+ width= s->width= avctx->width;
+ height= s->height= avctx->height;
+
+ assert(width && height);
+*/
+ s->avctx->get_buffer(s->avctx, &s->mconly_picture);
+
+ return 0;
+}
+
+static int qscale2qlog(int qscale){
+ return rint(QROOT*log(qscale / (float)FF_QP2LAMBDA)/log(2))
+ + 61*QROOT/8; //<64 >60
+}
+
+static int ratecontrol_1pass(SnowContext *s, AVFrame *pict)
+{
+ /* estimate the frame's complexity as a sum of weighted dwt coefs.
+ * FIXME we know exact mv bits at this point,
+ * but ratecontrol isn't set up to include them. */
+ uint32_t coef_sum= 0;
+ int level, orientation, delta_qlog;
+
+ for(level=0; level<s->spatial_decomposition_count; level++){
+ for(orientation=level ? 1 : 0; orientation<4; orientation++){
+ SubBand *b= &s->plane[0].band[level][orientation];
+ DWTELEM *buf= b->buf;
+ const int w= b->width;
+ const int h= b->height;
+ const int stride= b->stride;
+ const int qlog= av_clip(2*QROOT + b->qlog, 0, QROOT*16);
+ const int qmul= qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT);
+ const int qdiv= (1<<16)/qmul;
+ int x, y;
+ if(orientation==0)
+ decorrelate(s, b, buf, stride, 1, 0);
+ for(y=0; y<h; y++)
+ for(x=0; x<w; x++)
+ coef_sum+= abs(buf[x+y*stride]) * qdiv >> 16;
+ if(orientation==0)
+ correlate(s, b, buf, stride, 1, 0);
+ }
+ }
+
+ /* ugly, ratecontrol just takes a sqrt again */
+ coef_sum = (uint64_t)coef_sum * coef_sum >> 16;
+ assert(coef_sum < INT_MAX);
+
+ if(pict->pict_type == I_TYPE){
+ s->m.current_picture.mb_var_sum= coef_sum;
+ s->m.current_picture.mc_mb_var_sum= 0;
+ }else{
+ s->m.current_picture.mc_mb_var_sum= coef_sum;
+ s->m.current_picture.mb_var_sum= 0;
+ }
+
+ pict->quality= ff_rate_estimate_qscale(&s->m, 1);
+ if (pict->quality < 0)
+ return INT_MIN;
+ s->lambda= pict->quality * 3/2;
+ delta_qlog= qscale2qlog(pict->quality) - s->qlog;
+ s->qlog+= delta_qlog;
+ return delta_qlog;
+}
+
+static void calculate_vissual_weight(SnowContext *s, Plane *p){
+ int width = p->width;
+ int height= p->height;
+ int level, orientation, x, y;
+
+ for(level=0; level<s->spatial_decomposition_count; level++){
+ for(orientation=level ? 1 : 0; orientation<4; orientation++){
+ SubBand *b= &p->band[level][orientation];
+ DWTELEM *buf= b->buf;
+ int64_t error=0;
+
+ memset(s->spatial_dwt_buffer, 0, sizeof(int)*width*height);
+ buf[b->width/2 + b->height/2*b->stride]= 256*256;
+ ff_spatial_idwt(s->spatial_dwt_buffer, width, height, width, s->spatial_decomposition_type, s->spatial_decomposition_count);
+ for(y=0; y<height; y++){
+ for(x=0; x<width; x++){
+ int64_t d= s->spatial_dwt_buffer[x + y*width];
+ error += d*d;
+ }
+ }
+
+ b->qlog= (int)(log(352256.0/sqrt(error)) / log(pow(2.0, 1.0/QROOT))+0.5);
+// av_log(NULL, AV_LOG_DEBUG, "%d %d %d\n", level, orientation, b->qlog/*, sqrt(error)*/);
+ }
+ }
+}
+
+static 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;
+ }
+
+ 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.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));
+
+ for(plane_index=0; plane_index<3; plane_index++){
+ calculate_vissual_weight(s, &s->plane[plane_index]);
+ }
+
+
+ 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, "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; i<s->max_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;
+}
+
+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]){
+ draw_edges(s->current_picture.data[0], s->current_picture.linesize[0], w , h , EDGE_WIDTH );
+ draw_edges(s->current_picture.data[1], s->current_picture.linesize[1], w>>1, h>>1, EDGE_WIDTH/2);
+ draw_edges(s->current_picture.data[2], s->current_picture.linesize[2], w>>1, h>>1, EDGE_WIDTH/2);
+ }
+
+ tmp= s->last_picture[s->max_ref_frames-1];
+ memmove(s->last_picture+1, s->last_picture, (s->max_ref_frames-1)*sizeof(AVFrame));
+ s->last_picture[0]= s->current_picture;
+ s->current_picture= tmp;
+
+ if(s->keyframe){
+ s->ref_frames= 0;
+ }else{
+ int i;
+ for(i=0; i<s->max_ref_frames && s->last_picture[i].data[0]; i++)
+ if(i && s->last_picture[i-1].key_frame)
+ break;
+ s->ref_frames= i;
+ }
+
+ 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;
+ AVFrame *pict = data;
+ const int width= s->avctx->width;
+ const int height= s->avctx->height;
+ int level, orientation, plane_index, i, y;
+ uint8_t rc_header_bak[sizeof(s->header_state)];
+ uint8_t rc_block_bak[sizeof(s->block_state)];
+
+ ff_init_range_encoder(c, buf, buf_size);
+ ff_build_rac_states(c, 0.05*(1LL<<32), 256-8);
+
+ for(i=0; i<3; i++){
+ int shift= !!i;
+ for(y=0; y<(height>>shift); y++)
+ memcpy(&s->input_picture.data[i][y * s->input_picture.linesize[i]],
+ &pict->data[i][y * pict->linesize[i]],
+ width>>shift);
+ }
+ s->new_picture = *pict;
+
+ s->m.picture_number= avctx->frame_number;
+ if(avctx->flags&CODEC_FLAG_PASS2){
+ s->m.pict_type =
+ pict->pict_type= s->m.rc_context.entry[avctx->frame_number].new_pict_type;
+ s->keyframe= pict->pict_type==FF_I_TYPE;
+ if(!(avctx->flags&CODEC_FLAG_QSCALE)) {
+ pict->quality= ff_rate_estimate_qscale(&s->m, 0);
+ if (pict->quality < 0)
+ return -1;
+ }
+ }else{
+ s->keyframe= avctx->gop_size==0 || avctx->frame_number % avctx->gop_size == 0;
+ s->m.pict_type=
+ pict->pict_type= s->keyframe ? FF_I_TYPE : FF_P_TYPE;
+ }
+
+ if(s->pass1_rc && avctx->frame_number == 0)
+ pict->quality= 2*FF_QP2LAMBDA;
+ if(pict->quality){
+ s->qlog= qscale2qlog(pict->quality);
+ s->lambda = pict->quality * 3/2;
+ }
+ if(s->qlog < 0 || (!pict->quality && (avctx->flags & CODEC_FLAG_QSCALE))){
+ s->qlog= LOSSLESS_QLOG;
+ s->lambda = 0;
+ }//else keep previous frame's qlog until after motion est
+
+ frame_start(s);
+
+ s->m.current_picture_ptr= &s->m.current_picture;
+ if(pict->pict_type == P_TYPE){
+ int block_width = (width +15)>>4;
+ int block_height= (height+15)>>4;
+ int stride= s->current_picture.linesize[0];
+
+ assert(s->current_picture.data[0]);
+ assert(s->last_picture[0].data[0]);
+
+ s->m.avctx= s->avctx;
+ s->m.current_picture.data[0]= s->current_picture.data[0];
+ s->m. last_picture.data[0]= s->last_picture[0].data[0];
+ s->m. new_picture.data[0]= s-> input_picture.data[0];
+ s->m. last_picture_ptr= &s->m. last_picture;
+ s->m.linesize=
+ s->m. last_picture.linesize[0]=
+ s->m. new_picture.linesize[0]=
+ s->m.current_picture.linesize[0]= stride;
+ s->m.uvlinesize= s->current_picture.linesize[1];
+ s->m.width = width;
+ s->m.height= height;
+ s->m.mb_width = block_width;
+ s->m.mb_height= block_height;
+ s->m.mb_stride= s->m.mb_width+1;
+ s->m.b8_stride= 2*s->m.mb_width+1;
+ s->m.f_code=1;
+ s->m.pict_type= pict->pict_type;
+ s->m.me_method= s->avctx->me_method;
+ s->m.me.scene_change_score=0;
+ s->m.flags= s->avctx->flags;
+ s->m.quarter_sample= (s->avctx->flags & CODEC_FLAG_QPEL)!=0;
+ s->m.out_format= FMT_H263;
+ s->m.unrestricted_mv= 1;
+
+ s->m.lambda = s->lambda;
+ s->m.qscale= (s->m.lambda*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7);
+ s->lambda2= s->m.lambda2= (s->m.lambda*s->m.lambda + FF_LAMBDA_SCALE/2) >> FF_LAMBDA_SHIFT;
+
+ s->m.dsp= s->dsp; //move
+ ff_init_me(&s->m);
+ s->dsp= s->m.dsp;
+ }
+
+ if(s->pass1_rc){
+ memcpy(rc_header_bak, s->header_state, sizeof(s->header_state));
+ memcpy(rc_block_bak, s->block_state, sizeof(s->block_state));
+ }
+
+redo_frame:
+
+ s->m.pict_type = pict->pict_type;
+ s->qbias= pict->pict_type == P_TYPE ? 2 : 0;
+
+ encode_header(s);
+ s->m.misc_bits = 8*(s->c.bytestream - s->c.bytestream_start);
+ encode_blocks(s, 1);
+ s->m.mv_bits = 8*(s->c.bytestream - s->c.bytestream_start) - s->m.misc_bits;
+
+ 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 bits= put_bits_count(&s->c.pb);
+
+ if(!(avctx->flags2 & CODEC_FLAG2_MEMC_ONLY)){
+ //FIXME optimize
+ if(pict->data[plane_index]) //FIXME gray hack
+ for(y=0; y<h; y++){
+ for(x=0; x<w; x++){
+ s->spatial_dwt_buffer[y*w + x]= pict->data[plane_index][y*pict->linesize[plane_index] + x]<<FRAC_BITS;
+ }
+ }
+ predict_plane(s, s->spatial_dwt_buffer, plane_index, 0);
+
+ if( plane_index==0
+ && pict->pict_type == P_TYPE
+ && !(avctx->flags&CODEC_FLAG_PASS2)
+ && s->m.me.scene_change_score > s->avctx->scenechange_threshold){
+ ff_init_range_encoder(c, buf, buf_size);
+ ff_build_rac_states(c, 0.05*(1LL<<32), 256-8);
+ pict->pict_type= FF_I_TYPE;
+ s->keyframe=1;
+ s->current_picture.key_frame=1;
+ goto redo_frame;
+ }
+
+ if(s->qlog == LOSSLESS_QLOG){
+ for(y=0; y<h; y++){
+ for(x=0; x<w; x++){
+ s->spatial_dwt_buffer[y*w + x]= (s->spatial_dwt_buffer[y*w + x] + (1<<(FRAC_BITS-1))-1)>>FRAC_BITS;
+ }
+ }
+ }
+
+ ff_spatial_dwt(s->spatial_dwt_buffer, w, h, w, s->spatial_decomposition_type, s->spatial_decomposition_count);
+
+ if(s->pass1_rc && plane_index==0){
+ int delta_qlog = ratecontrol_1pass(s, pict);
+ if (delta_qlog <= INT_MIN)
+ return -1;
+ if(delta_qlog){
+ //reordering qlog in the bitstream would eliminate this reset
+ ff_init_range_encoder(c, buf, buf_size);
+ memcpy(s->header_state, rc_header_bak, sizeof(s->header_state));
+ memcpy(s->block_state, rc_block_bak, sizeof(s->block_state));
+ encode_header(s);
+ encode_blocks(s, 0);
+ }
+ }
+
+ for(level=0; level<s->spatial_decomposition_count; level++){
+ for(orientation=level ? 1 : 0; orientation<4; orientation++){
+ SubBand *b= &p->band[level][orientation];
+
+ quantize(s, b, b->buf, b->stride, s->qbias);
+ if(orientation==0)
+ decorrelate(s, b, b->buf, b->stride, pict->pict_type == P_TYPE, 0);
+ encode_subband(s, b, b->buf, b->parent ? b->parent->buf : NULL, b->stride, orientation);
+ assert(b->parent==NULL || b->parent->stride == b->stride*2);
+ if(orientation==0)
+ correlate(s, b, b->buf, b->stride, 1, 0);
+ }
+ }
+// av_log(NULL, AV_LOG_DEBUG, "plane:%d bits:%d\n", plane_index, put_bits_count(&s->c.pb) - bits);
+
+ for(level=0; level<s->spatial_decomposition_count; level++){
+ for(orientation=level ? 1 : 0; orientation<4; orientation++){
+ SubBand *b= &p->band[level][orientation];
+
+ dequantize(s, b, b->buf, b->stride);
+ }
+ }
+
+ ff_spatial_idwt(s->spatial_dwt_buffer, w, h, w, s->spatial_decomposition_type, s->spatial_decomposition_count);
+ if(s->qlog == LOSSLESS_QLOG){
+ for(y=0; y<h; y++){
+ for(x=0; x<w; x++){
+ s->spatial_dwt_buffer[y*w + x]<<=FRAC_BITS;
+ }
+ }
+ }
+{START_TIMER
+ predict_plane(s, s->spatial_dwt_buffer, plane_index, 1);
+STOP_TIMER("pred-conv")}
+ }else{
+ //ME/MC only
+ if(pict->pict_type == I_TYPE){
+ for(y=0; y<h; y++){
+ for(x=0; x<w; x++){
+ s->current_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x]=
+ pict->data[plane_index][y*pict->linesize[plane_index] + x];
+ }
+ }
+ }else{
+ memset(s->spatial_dwt_buffer, 0, sizeof(DWTELEM)*w*h);
+ predict_plane(s, s->spatial_dwt_buffer, plane_index, 1);
+ }
+ }
+ if(s->avctx->flags&CODEC_FLAG_PSNR){
+ int64_t error= 0;
+
+ if(pict->data[plane_index]) //FIXME gray hack
+ for(y=0; y<h; y++){
+ for(x=0; x<w; x++){
+ int d= s->current_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x] - pict->data[plane_index][y*pict->linesize[plane_index] + x];
+ error += d*d;
+ }
+ }
+ s->avctx->error[plane_index] += error;
+ s->current_picture.error[plane_index] = error;
+ }
+ }
+
+ if(s->last_picture[s->max_ref_frames-1].data[0])
+ avctx->release_buffer(avctx, &s->last_picture[s->max_ref_frames-1]);
+
+ s->current_picture.coded_picture_number = avctx->frame_number;
+ s->current_picture.pict_type = pict->pict_type;
+ s->current_picture.quality = pict->quality;
+ s->m.frame_bits = 8*(s->c.bytestream - s->c.bytestream_start);
+ s->m.p_tex_bits = s->m.frame_bits - s->m.misc_bits - s->m.mv_bits;
+ s->m.current_picture.display_picture_number =
+ s->m.current_picture.coded_picture_number = avctx->frame_number;
+ s->m.current_picture.quality = pict->quality;
+ s->m.total_bits += 8*(s->c.bytestream - s->c.bytestream_start);
+ if(s->pass1_rc)
+ if (ff_rate_estimate_qscale(&s->m, 0) < 0)
+ return -1;
+ if(avctx->flags&CODEC_FLAG_PASS1)
+ ff_write_pass1_stats(&s->m);
+ s->m.last_pict_type = s->m.pict_type;
+ avctx->frame_bits = s->m.frame_bits;
+ avctx->mv_bits = s->m.mv_bits;
+ avctx->misc_bits = s->m.misc_bits;
+ avctx->p_tex_bits = s->m.p_tex_bits;
+
+ emms_c();
+
+ return ff_rac_terminate(c);
+}
+
+static void common_end(SnowContext *s){
+ int plane_index, level, orientation, i;
+
+ av_freep(&s->spatial_dwt_buffer);
+
+ 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);
+
+ for(i=0; i<MAX_REF_FRAMES; i++){
+ av_freep(&s->ref_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 int encode_end(AVCodecContext *avctx)
+{
+ SnowContext *s = avctx->priv_data;
+
+ common_end(s);
+ av_free(avctx->stats_out);
+
+ return 0;
+}
+
+static int decode_init(AVCodecContext *avctx)
+{
+ SnowContext *s = avctx->priv_data;
+ int block_size;
+
+ avctx->pix_fmt= PIX_FMT_YUV420P;
+
+ common_init(avctx);
+
+ block_size = MB_SIZE >> s->block_max_depth;
+ slice_buffer_init(&s->sb, s->plane[0].height, (block_size) + (s->spatial_decomposition_count * (s->spatial_decomposition_count + 3)) + 1, s->plane[0].width, s->spatial_dwt_buffer);
+
+ return 0;
+}
+
+static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_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
+ decode_header(s);
+ if(!s->block) alloc_blocks(s);
+
+ frame_start(s);
+ //keyframe flag dupliaction 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_dwt_buffer, plane_index, 1);
+
+ for(y=0; y<h; y++){
+ for(x=0; x<w; x++){
+ int v= s->current_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;
+ }
+ }
+}
+
+{ START_TIMER
+ for(level=0; level<s->spatial_decomposition_count; level++){
+ for(orientation=level ? 1 : 0; orientation<4; orientation++){
+ SubBand *b= &p->band[level][orientation];
+ unpack_coeffs(s, b, b->parent, orientation);
+ }
+ }
+ STOP_TIMER("unpack coeffs");
+}
+
+{START_TIMER
+ 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;
+ dwt_compose_t 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);
+ }
+
+ {
+ START_TIMER
+ for(level=0; level<s->spatial_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->buf, correlate_band->stride, 1, 0, correlate_start_y, correlate_end_y);
+ dequantize_slice_buffered(s, &s->sb, correlate_band, correlate_band->buf, correlate_band->stride, start_y, end_y);
+ }
+ else
+ decode_subband_slice_buffered(s, b, &s->sb, start_y, end_y, decode_state[level][orientation]);
+ }
+ }
+ }
+ STOP_TIMER("decode_subband_slice");
+ }
+
+{ START_TIMER
+ for(; yd<slice_h; yd+=4){
+ ff_spatial_idwt_buffered_slice(&s->dsp, cs, &s->sb, w, h, 1, s->spatial_decomposition_type, s->spatial_decomposition_count, yd);
+ }
+ STOP_TIMER("idwt slice");}
+
+
+ if(s->qlog == LOSSLESS_QLOG){
+ for(; yq<slice_h && yq<h; yq++){
+ DWTELEM * line = slice_buffer_get_line(&s->sb, yq);
+ for(x=0; x<w; x++){
+ line[x] <<= FRAC_BITS;
+ }
+ }
+ }
+
+ predict_slice_buffered(s, &s->sb, s->spatial_dwt_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);
+
+STOP_TIMER("idwt + predict_slices")}
+ }
+
+ emms_c();
+
+ if(s->last_picture[s->max_ref_frames-1].data[0])
+ avctx->release_buffer(avctx, &s->last_picture[s->max_ref_frames-1]);
+
+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 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,
+ 0 /*CODEC_CAP_DR1*/ /*| CODEC_CAP_DRAW_HORIZ_BAND*/,
+ NULL
+};
+
+#ifdef CONFIG_ENCODERS
+AVCodec snow_encoder = {
+ "snow",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_SNOW,
+ sizeof(SnowContext),
+ encode_init,
+ encode_frame,
+ encode_end,
+};
+#endif
+
+
+#if 0
+#undef malloc
+#undef free
+#undef printf
+
+int main(){
+ int width=256;
+ int height=256;
+ int buffer[2][width*height];
+ SnowContext s;
+ int i;
+ s.spatial_decomposition_count=6;
+ s.spatial_decomposition_type=1;
+
+ printf("testing 5/3 DWT\n");
+ for(i=0; i<width*height; i++)
+ buffer[0][i]= buffer[1][i]= random()%54321 - 12345;
+
+ ff_spatial_dwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
+ ff_spatial_idwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
+
+ for(i=0; i<width*height; i++)
+ if(buffer[0][i]!= buffer[1][i]) printf("fsck: %d %d %d\n",i, buffer[0][i], buffer[1][i]);
+
+ printf("testing 9/7 DWT\n");
+ s.spatial_decomposition_type=0;
+ for(i=0; i<width*height; i++)
+ buffer[0][i]= buffer[1][i]= random()%54321 - 12345;
+
+ ff_spatial_dwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
+ ff_spatial_idwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
+
+ for(i=0; i<width*height; i++)
+ if(FFABS(buffer[0][i] - buffer[1][i])>20) printf("fsck: %d %d %d\n",i, buffer[0][i], buffer[1][i]);
+
+#if 0
+ printf("testing AC coder\n");
+ memset(s.header_state, 0, sizeof(s.header_state));
+ ff_init_range_encoder(&s.c, buffer[0], 256*256);
+ ff_init_cabac_states(&s.c, ff_h264_lps_range, ff_h264_mps_state, ff_h264_lps_state, 64);
+
+ for(i=-256; i<256; i++){
+START_TIMER
+ put_symbol(&s.c, s.header_state, i*i*i/3*FFABS(i), 1);
+STOP_TIMER("put_symbol")
+ }
+ ff_rac_terminate(&s.c);
+
+ memset(s.header_state, 0, sizeof(s.header_state));
+ ff_init_range_decoder(&s.c, buffer[0], 256*256);
+ ff_init_cabac_states(&s.c, ff_h264_lps_range, ff_h264_mps_state, ff_h264_lps_state, 64);
+
+ for(i=-256; i<256; i++){
+ int j;
+START_TIMER
+ j= get_symbol(&s.c, s.header_state, 1);
+STOP_TIMER("get_symbol")
+ if(j!=i*i*i/3*FFABS(i)) printf("fsck: %d != %d\n", i, j);
+ }
+#endif
+{
+int level, orientation, x, y;
+int64_t errors[8][4];
+int64_t g=0;
+
+ memset(errors, 0, sizeof(errors));
+ s.spatial_decomposition_count=3;
+ s.spatial_decomposition_type=0;
+ for(level=0; level<s.spatial_decomposition_count; level++){
+ for(orientation=level ? 1 : 0; orientation<4; orientation++){
+ int w= width >> (s.spatial_decomposition_count-level);
+ int h= height >> (s.spatial_decomposition_count-level);
+ int stride= width << (s.spatial_decomposition_count-level);
+ DWTELEM *buf= buffer[0];
+ int64_t error=0;
+
+ if(orientation&1) buf+=w;
+ if(orientation>1) buf+=stride>>1;
+
+ memset(buffer[0], 0, sizeof(int)*width*height);
+ buf[w/2 + h/2*stride]= 256*256;
+ ff_spatial_idwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
+ for(y=0; y<height; y++){
+ for(x=0; x<width; x++){
+ int64_t d= buffer[0][x + y*width];
+ error += d*d;
+ if(FFABS(width/2-x)<9 && FFABS(height/2-y)<9 && level==2) printf("%8"PRId64" ", d);
+ }
+ if(FFABS(height/2-y)<9 && level==2) printf("\n");
+ }
+ error= (int)(sqrt(error)+0.5);
+ errors[level][orientation]= error;
+ if(g) g=ff_gcd(g, error);
+ else g= error;
+ }
+ }
+ printf("static int const visual_weight[][4]={\n");
+ for(level=0; level<s.spatial_decomposition_count; level++){
+ printf(" {");
+ for(orientation=0; orientation<4; orientation++){
+ printf("%8"PRId64",", errors[level][orientation]/g);
+ }
+ printf("},\n");
+ }
+ printf("};\n");
+ {
+ int level=2;
+ int orientation=3;
+ int w= width >> (s.spatial_decomposition_count-level);
+ int h= height >> (s.spatial_decomposition_count-level);
+ int stride= width << (s.spatial_decomposition_count-level);
+ DWTELEM *buf= buffer[0];
+ int64_t error=0;
+
+ buf+=w;
+ buf+=stride>>1;
+
+ memset(buffer[0], 0, sizeof(int)*width*height);
+#if 1
+ for(y=0; y<height; y++){
+ for(x=0; x<width; x++){
+ int tab[4]={0,2,3,1};
+ buffer[0][x+width*y]= 256*256*tab[(x&1) + 2*(y&1)];
+ }
+ }
+ ff_spatial_dwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
+#else
+ for(y=0; y<h; y++){
+ for(x=0; x<w; x++){
+ buf[x + y*stride ]=169;
+ buf[x + y*stride-w]=64;
+ }
+ }
+ ff_spatial_idwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
+#endif
+ for(y=0; y<height; y++){
+ for(x=0; x<width; x++){
+ int64_t d= buffer[0][x + y*width];
+ error += d*d;
+ if(FFABS(width/2-x)<9 && FFABS(height/2-y)<9) printf("%8"PRId64" ", d);
+ }
+ if(FFABS(height/2-y)<9) printf("\n");
+ }
+ }
+
+}
+ return 0;
+}
+#endif
+
diff --git a/contrib/ffmpeg/libavcodec/snow.h b/contrib/ffmpeg/libavcodec/snow.h
new file mode 100644
index 000000000..d75d6e3e0
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/snow.h
@@ -0,0 +1,176 @@
+/*
+ * Copyright (C) 2004 Michael Niedermayer <michaelni@gmx.at>
+ * Copyright (C) 2006 Robert Edele <yartrebo@earthlink.net>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 _SNOW_H
+#define _SNOW_H
+
+#include "dsputil.h"
+
+#define MID_STATE 128
+
+#define MAX_DECOMPOSITIONS 8
+#define MAX_PLANES 4
+#define QSHIFT 5
+#define QROOT (1<<QSHIFT)
+#define LOSSLESS_QLOG -128
+#define FRAC_BITS 8
+#define MAX_REF_FRAMES 8
+
+#define LOG2_OBMC_MAX 8
+#define OBMC_MAX (1<<(LOG2_OBMC_MAX))
+
+#define DWT_97 0
+#define DWT_53 1
+#define DWT_X 2
+
+/** Used to minimize the amount of memory used in order to optimize cache performance. **/
+struct slice_buffer_s {
+ DWTELEM * * line; ///< For use by idwt and predict_slices.
+ DWTELEM * * data_stack; ///< Used for internal purposes.
+ int data_stack_top;
+ int line_count;
+ int line_width;
+ int data_count;
+ DWTELEM * base_buffer; ///< Buffer that this structure is caching.
+};
+
+#define liftS lift
+#define lift5 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
+
+extern void ff_snow_vertical_compose97i(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWTELEM *b3, DWTELEM *b4, DWTELEM *b5, int width);
+extern void ff_snow_horizontal_compose97i(DWTELEM *b, int width);
+extern 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);
+
+#ifdef CONFIG_SNOW_ENCODER
+int w53_32_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h);
+int w97_32_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h);
+#else
+static int w53_32_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {assert (0);}
+static int w97_32_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {assert (0);}
+#endif
+
+/* C bits used by mmx/sse2/altivec */
+
+static av_always_inline void snow_interleave_line_header(int * i, int width, DWTELEM * low, DWTELEM * high){
+ (*i) = (width) - 2;
+
+ if (width & 1){
+ low[(*i)+1] = low[((*i)+1)>>1];
+ (*i)--;
+ }
+}
+
+static av_always_inline void snow_interleave_line_footer(int * i, DWTELEM * low, DWTELEM * high){
+ for (; (*i)>=0; (*i)-=2){
+ low[(*i)+1] = high[(*i)>>1];
+ low[*i] = low[(*i)>>1];
+ }
+}
+
+static av_always_inline void snow_horizontal_compose_lift_lead_out(int i, DWTELEM * dst, DWTELEM * src, DWTELEM * ref, int width, int w, int lift_high, int mul, int add, int shift){
+ for(; i<w; i++){
+ dst[i] = src[i] - ((mul * (ref[i] + ref[i + 1]) + add) >> shift);
+ }
+
+ if((width^lift_high)&1){
+ dst[w] = src[w] - ((mul * 2 * ref[w] + add) >> shift);
+ }
+}
+
+static av_always_inline void snow_horizontal_compose_liftS_lead_out(int i, DWTELEM * dst, DWTELEM * src, DWTELEM * ref, int width, int w){
+ for(; i<w; i++){
+ dst[i] = src[i] - (((-(ref[i] + ref[(i+1)])+W_BO) - 4 * src[i]) >> W_BS);
+ }
+
+ if(width&1){
+ dst[w] = src[w] - (((-2 * ref[w] + W_BO) - 4 * src[w]) >> W_BS);
+ }
+}
+
+#endif
diff --git a/contrib/ffmpeg/libavcodec/sonic.c b/contrib/ffmpeg/libavcodec/sonic.c
new file mode 100644
index 000000000..f3388589b
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/sonic.c
@@ -0,0 +1,981 @@
+/*
+ * Simple free lossless/lossy audio codec
+ * Copyright (c) 2004 Alex Beregszaszi
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include "avcodec.h"
+#include "bitstream.h"
+#include "golomb.h"
+
+/**
+ * @file sonic.c
+ * Simple free lossless/lossy audio codec
+ * Based on Paul Francis Harrison's Bonk (http://www.logarithmic.net/pfh/bonk)
+ * Written and designed by Alex Beregszaszi
+ *
+ * TODO:
+ * - CABAC put/get_symbol
+ * - independent quantizer for channels
+ * - >2 channels support
+ * - more decorrelation types
+ * - more tap_quant tests
+ * - selectable intlist writers/readers (bonk-style, golomb, cabac)
+ */
+
+#define MAX_CHANNELS 2
+
+#define MID_SIDE 0
+#define LEFT_SIDE 1
+#define RIGHT_SIDE 2
+
+typedef struct SonicContext {
+ int lossless, decorrelation;
+
+ int num_taps, downsampling;
+ double quantization;
+
+ int channels, samplerate, block_align, frame_size;
+
+ int *tap_quant;
+ int *int_samples;
+ int *coded_samples[MAX_CHANNELS];
+
+ // for encoding
+ int *tail;
+ int tail_size;
+ int *window;
+ int window_size;
+
+ // for decoding
+ int *predictor_k;
+ int *predictor_state[MAX_CHANNELS];
+} SonicContext;
+
+#define LATTICE_SHIFT 10
+#define SAMPLE_SHIFT 4
+#define LATTICE_FACTOR (1 << LATTICE_SHIFT)
+#define SAMPLE_FACTOR (1 << SAMPLE_SHIFT)
+
+#define BASE_QUANT 0.6
+#define RATE_VARIATION 3.0
+
+static inline int divide(int a, int b)
+{
+ if (a < 0)
+ return -( (-a + b/2)/b );
+ else
+ return (a + b/2)/b;
+}
+
+static inline int shift(int a,int b)
+{
+ return (a+(1<<(b-1))) >> b;
+}
+
+static inline int shift_down(int a,int b)
+{
+ return (a>>b)+((a<0)?1:0);
+}
+
+#if 1
+static inline int intlist_write(PutBitContext *pb, int *buf, int entries, int base_2_part)
+{
+ int i;
+
+ for (i = 0; i < entries; i++)
+ set_se_golomb(pb, buf[i]);
+
+ return 1;
+}
+
+static inline int intlist_read(GetBitContext *gb, int *buf, int entries, int base_2_part)
+{
+ int i;
+
+ for (i = 0; i < entries; i++)
+ buf[i] = get_se_golomb(gb);
+
+ return 1;
+}
+
+#else
+
+#define ADAPT_LEVEL 8
+
+static int bits_to_store(uint64_t x)
+{
+ int res = 0;
+
+ while(x)
+ {
+ res++;
+ x >>= 1;
+ }
+ return res;
+}
+
+static void write_uint_max(PutBitContext *pb, unsigned int value, unsigned int max)
+{
+ int i, bits;
+
+ if (!max)
+ return;
+
+ bits = bits_to_store(max);
+
+ for (i = 0; i < bits-1; i++)
+ put_bits(pb, 1, value & (1 << i));
+
+ if ( (value | (1 << (bits-1))) <= max)
+ put_bits(pb, 1, value & (1 << (bits-1)));
+}
+
+static unsigned int read_uint_max(GetBitContext *gb, int max)
+{
+ int i, bits, value = 0;
+
+ if (!max)
+ return 0;
+
+ bits = bits_to_store(max);
+
+ for (i = 0; i < bits-1; i++)
+ if (get_bits1(gb))
+ value += 1 << i;
+
+ if ( (value | (1<<(bits-1))) <= max)
+ if (get_bits1(gb))
+ value += 1 << (bits-1);
+
+ return value;
+}
+
+static int intlist_write(PutBitContext *pb, int *buf, int entries, int base_2_part)
+{
+ int i, j, x = 0, low_bits = 0, max = 0;
+ int step = 256, pos = 0, dominant = 0, any = 0;
+ int *copy, *bits;
+
+ copy = av_mallocz(4* entries);
+ if (!copy)
+ return -1;
+
+ if (base_2_part)
+ {
+ int energy = 0;
+
+ for (i = 0; i < entries; i++)
+ energy += abs(buf[i]);
+
+ low_bits = bits_to_store(energy / (entries * 2));
+ if (low_bits > 15)
+ low_bits = 15;
+
+ put_bits(pb, 4, low_bits);
+ }
+
+ for (i = 0; i < entries; i++)
+ {
+ put_bits(pb, low_bits, abs(buf[i]));
+ copy[i] = abs(buf[i]) >> low_bits;
+ if (copy[i] > max)
+ max = abs(copy[i]);
+ }
+
+ bits = av_mallocz(4* entries*max);
+ if (!bits)
+ {
+// av_free(copy);
+ return -1;
+ }
+
+ for (i = 0; i <= max; i++)
+ {
+ for (j = 0; j < entries; j++)
+ if (copy[j] >= i)
+ bits[x++] = copy[j] > i;
+ }
+
+ // store bitstream
+ while (pos < x)
+ {
+ int steplet = step >> 8;
+
+ if (pos + steplet > x)
+ steplet = x - pos;
+
+ for (i = 0; i < steplet; i++)
+ if (bits[i+pos] != dominant)
+ any = 1;
+
+ put_bits(pb, 1, any);
+
+ if (!any)
+ {
+ pos += steplet;
+ step += step / ADAPT_LEVEL;
+ }
+ else
+ {
+ int interloper = 0;
+
+ while (((pos + interloper) < x) && (bits[pos + interloper] == dominant))
+ interloper++;
+
+ // note change
+ write_uint_max(pb, interloper, (step >> 8) - 1);
+
+ pos += interloper + 1;
+ step -= step / ADAPT_LEVEL;
+ }
+
+ if (step < 256)
+ {
+ step = 65536 / step;
+ dominant = !dominant;
+ }
+ }
+
+ // store signs
+ for (i = 0; i < entries; i++)
+ if (buf[i])
+ put_bits(pb, 1, buf[i] < 0);
+
+// av_free(bits);
+// av_free(copy);
+
+ return 0;
+}
+
+static int intlist_read(GetBitContext *gb, int *buf, int entries, int base_2_part)
+{
+ int i, low_bits = 0, x = 0;
+ int n_zeros = 0, step = 256, dominant = 0;
+ int pos = 0, level = 0;
+ int *bits = av_mallocz(4* entries);
+
+ if (!bits)
+ return -1;
+
+ if (base_2_part)
+ {
+ low_bits = get_bits(gb, 4);
+
+ if (low_bits)
+ for (i = 0; i < entries; i++)
+ buf[i] = get_bits(gb, low_bits);
+ }
+
+// av_log(NULL, AV_LOG_INFO, "entries: %d, low bits: %d\n", entries, low_bits);
+
+ while (n_zeros < entries)
+ {
+ int steplet = step >> 8;
+
+ if (!get_bits1(gb))
+ {
+ for (i = 0; i < steplet; i++)
+ bits[x++] = dominant;
+
+ if (!dominant)
+ n_zeros += steplet;
+
+ step += step / ADAPT_LEVEL;
+ }
+ else
+ {
+ int actual_run = read_uint_max(gb, steplet-1);
+
+// av_log(NULL, AV_LOG_INFO, "actual run: %d\n", actual_run);
+
+ for (i = 0; i < actual_run; i++)
+ bits[x++] = dominant;
+
+ bits[x++] = !dominant;
+
+ if (!dominant)
+ n_zeros += actual_run;
+ else
+ n_zeros++;
+
+ step -= step / ADAPT_LEVEL;
+ }
+
+ if (step < 256)
+ {
+ step = 65536 / step;
+ dominant = !dominant;
+ }
+ }
+
+ // reconstruct unsigned values
+ n_zeros = 0;
+ for (i = 0; n_zeros < entries; i++)
+ {
+ while(1)
+ {
+ if (pos >= entries)
+ {
+ pos = 0;
+ level += 1 << low_bits;
+ }
+
+ if (buf[pos] >= level)
+ break;
+
+ pos++;
+ }
+
+ if (bits[i])
+ buf[pos] += 1 << low_bits;
+ else
+ n_zeros++;
+
+ pos++;
+ }
+// av_free(bits);
+
+ // read signs
+ for (i = 0; i < entries; i++)
+ if (buf[i] && get_bits1(gb))
+ buf[i] = -buf[i];
+
+// av_log(NULL, AV_LOG_INFO, "zeros: %d pos: %d\n", n_zeros, pos);
+
+ return 0;
+}
+#endif
+
+static void predictor_init_state(int *k, int *state, int order)
+{
+ int i;
+
+ for (i = order-2; i >= 0; i--)
+ {
+ int j, p, x = state[i];
+
+ for (j = 0, p = i+1; p < order; j++,p++)
+ {
+ int tmp = x + shift_down(k[j] * state[p], LATTICE_SHIFT);
+ state[p] += shift_down(k[j]*x, LATTICE_SHIFT);
+ x = tmp;
+ }
+ }
+}
+
+static int predictor_calc_error(int *k, int *state, int order, int error)
+{
+ int i, x = error - shift_down(k[order-1] * state[order-1], LATTICE_SHIFT);
+
+#if 1
+ int *k_ptr = &(k[order-2]),
+ *state_ptr = &(state[order-2]);
+ for (i = order-2; i >= 0; i--, k_ptr--, state_ptr--)
+ {
+ int k_value = *k_ptr, state_value = *state_ptr;
+ x -= shift_down(k_value * state_value, LATTICE_SHIFT);
+ state_ptr[1] = state_value + shift_down(k_value * x, LATTICE_SHIFT);
+ }
+#else
+ for (i = order-2; i >= 0; i--)
+ {
+ x -= shift_down(k[i] * state[i], LATTICE_SHIFT);
+ state[i+1] = state[i] + shift_down(k[i] * x, LATTICE_SHIFT);
+ }
+#endif
+
+ // don't drift too far, to avoid overflows
+ if (x > (SAMPLE_FACTOR<<16)) x = (SAMPLE_FACTOR<<16);
+ if (x < -(SAMPLE_FACTOR<<16)) x = -(SAMPLE_FACTOR<<16);
+
+ state[0] = x;
+
+ return x;
+}
+
+#ifdef CONFIG_ENCODERS
+// Heavily modified Levinson-Durbin algorithm which
+// copes better with quantization, and calculates the
+// actual whitened result as it goes.
+
+static void modified_levinson_durbin(int *window, int window_entries,
+ int *out, int out_entries, int channels, int *tap_quant)
+{
+ int i;
+ int *state = av_mallocz(4* window_entries);
+
+ memcpy(state, window, 4* window_entries);
+
+ for (i = 0; i < out_entries; i++)
+ {
+ int step = (i+1)*channels, k, j;
+ double xx = 0.0, xy = 0.0;
+#if 1
+ int *x_ptr = &(window[step]), *state_ptr = &(state[0]);
+ j = window_entries - step;
+ for (;j>=0;j--,x_ptr++,state_ptr++)
+ {
+ double x_value = *x_ptr, state_value = *state_ptr;
+ xx += state_value*state_value;
+ xy += x_value*state_value;
+ }
+#else
+ for (j = 0; j <= (window_entries - step); j++);
+ {
+ double stepval = window[step+j], stateval = window[j];
+// xx += (double)window[j]*(double)window[j];
+// xy += (double)window[step+j]*(double)window[j];
+ xx += stateval*stateval;
+ xy += stepval*stateval;
+ }
+#endif
+ if (xx == 0.0)
+ k = 0;
+ else
+ k = (int)(floor(-xy/xx * (double)LATTICE_FACTOR / (double)(tap_quant[i]) + 0.5));
+
+ if (k > (LATTICE_FACTOR/tap_quant[i]))
+ k = LATTICE_FACTOR/tap_quant[i];
+ if (-k > (LATTICE_FACTOR/tap_quant[i]))
+ k = -(LATTICE_FACTOR/tap_quant[i]);
+
+ out[i] = k;
+ k *= tap_quant[i];
+
+#if 1
+ x_ptr = &(window[step]);
+ state_ptr = &(state[0]);
+ j = window_entries - step;
+ for (;j>=0;j--,x_ptr++,state_ptr++)
+ {
+ int x_value = *x_ptr, state_value = *state_ptr;
+ *x_ptr = x_value + shift_down(k*state_value,LATTICE_SHIFT);
+ *state_ptr = state_value + shift_down(k*x_value, LATTICE_SHIFT);
+ }
+#else
+ for (j=0; j <= (window_entries - step); j++)
+ {
+ int stepval = window[step+j], stateval=state[j];
+ window[step+j] += shift_down(k * stateval, LATTICE_SHIFT);
+ state[j] += shift_down(k * stepval, LATTICE_SHIFT);
+ }
+#endif
+ }
+
+ av_free(state);
+}
+#endif /* CONFIG_ENCODERS */
+
+static int samplerate_table[] =
+ { 44100, 22050, 11025, 96000, 48000, 32000, 24000, 16000, 8000 };
+
+#ifdef CONFIG_ENCODERS
+
+static inline int code_samplerate(int samplerate)
+{
+ switch (samplerate)
+ {
+ case 44100: return 0;
+ case 22050: return 1;
+ case 11025: return 2;
+ case 96000: return 3;
+ case 48000: return 4;
+ case 32000: return 5;
+ case 24000: return 6;
+ case 16000: return 7;
+ case 8000: return 8;
+ }
+ return -1;
+}
+
+static int sonic_encode_init(AVCodecContext *avctx)
+{
+ SonicContext *s = avctx->priv_data;
+ PutBitContext pb;
+ int i, version = 0;
+
+ if (avctx->channels > MAX_CHANNELS)
+ {
+ av_log(avctx, AV_LOG_ERROR, "Only mono and stereo streams are supported by now\n");
+ return -1; /* only stereo or mono for now */
+ }
+
+ if (avctx->channels == 2)
+ s->decorrelation = MID_SIDE;
+
+ if (avctx->codec->id == CODEC_ID_SONIC_LS)
+ {
+ s->lossless = 1;
+ s->num_taps = 32;
+ s->downsampling = 1;
+ s->quantization = 0.0;
+ }
+ else
+ {
+ s->num_taps = 128;
+ s->downsampling = 2;
+ s->quantization = 1.0;
+ }
+
+ // max tap 2048
+ if ((s->num_taps < 32) || (s->num_taps > 1024) ||
+ ((s->num_taps>>5)<<5 != s->num_taps))
+ {
+ av_log(avctx, AV_LOG_ERROR, "Invalid number of taps\n");
+ return -1;
+ }
+
+ // generate taps
+ s->tap_quant = av_mallocz(4* s->num_taps);
+ for (i = 0; i < s->num_taps; i++)
+ s->tap_quant[i] = (int)(sqrt(i+1));
+
+ s->channels = avctx->channels;
+ s->samplerate = avctx->sample_rate;
+
+ s->block_align = (int)(2048.0*s->samplerate/44100)/s->downsampling;
+ s->frame_size = s->channels*s->block_align*s->downsampling;
+
+ s->tail = av_mallocz(4* s->num_taps*s->channels);
+ if (!s->tail)
+ return -1;
+ s->tail_size = s->num_taps*s->channels;
+
+ s->predictor_k = av_mallocz(4 * s->num_taps);
+ if (!s->predictor_k)
+ return -1;
+
+ for (i = 0; i < s->channels; i++)
+ {
+ s->coded_samples[i] = av_mallocz(4* s->block_align);
+ if (!s->coded_samples[i])
+ return -1;
+ }
+
+ s->int_samples = av_mallocz(4* s->frame_size);
+
+ s->window_size = ((2*s->tail_size)+s->frame_size);
+ s->window = av_mallocz(4* s->window_size);
+ if (!s->window)
+ return -1;
+
+ avctx->extradata = av_mallocz(16);
+ if (!avctx->extradata)
+ return -1;
+ init_put_bits(&pb, avctx->extradata, 16*8);
+
+ put_bits(&pb, 2, version); // version
+ if (version == 1)
+ {
+ put_bits(&pb, 2, s->channels);
+ put_bits(&pb, 4, code_samplerate(s->samplerate));
+ }
+ put_bits(&pb, 1, s->lossless);
+ if (!s->lossless)
+ put_bits(&pb, 3, SAMPLE_SHIFT); // XXX FIXME: sample precision
+ put_bits(&pb, 2, s->decorrelation);
+ put_bits(&pb, 2, s->downsampling);
+ put_bits(&pb, 5, (s->num_taps >> 5)-1); // 32..1024
+ put_bits(&pb, 1, 0); // XXX FIXME: no custom tap quant table
+
+ flush_put_bits(&pb);
+ avctx->extradata_size = put_bits_count(&pb)/8;
+
+ av_log(avctx, AV_LOG_INFO, "Sonic: ver: %d ls: %d dr: %d taps: %d block: %d frame: %d downsamp: %d\n",
+ version, s->lossless, s->decorrelation, s->num_taps, s->block_align, s->frame_size, s->downsampling);
+
+ avctx->coded_frame = avcodec_alloc_frame();
+ if (!avctx->coded_frame)
+ return AVERROR(ENOMEM);
+ avctx->coded_frame->key_frame = 1;
+ avctx->frame_size = s->block_align*s->downsampling;
+
+ return 0;
+}
+
+static int sonic_encode_close(AVCodecContext *avctx)
+{
+ SonicContext *s = avctx->priv_data;
+ int i;
+
+ av_freep(&avctx->coded_frame);
+
+ for (i = 0; i < s->channels; i++)
+ av_free(s->coded_samples[i]);
+
+ av_free(s->predictor_k);
+ av_free(s->tail);
+ av_free(s->tap_quant);
+ av_free(s->window);
+ av_free(s->int_samples);
+
+ return 0;
+}
+
+static int sonic_encode_frame(AVCodecContext *avctx,
+ uint8_t *buf, int buf_size, void *data)
+{
+ SonicContext *s = avctx->priv_data;
+ PutBitContext pb;
+ int i, j, ch, quant = 0, x = 0;
+ short *samples = data;
+
+ init_put_bits(&pb, buf, buf_size*8);
+
+ // short -> internal
+ for (i = 0; i < s->frame_size; i++)
+ s->int_samples[i] = samples[i];
+
+ if (!s->lossless)
+ for (i = 0; i < s->frame_size; i++)
+ s->int_samples[i] = s->int_samples[i] << SAMPLE_SHIFT;
+
+ switch(s->decorrelation)
+ {
+ case MID_SIDE:
+ for (i = 0; i < s->frame_size; i += s->channels)
+ {
+ s->int_samples[i] += s->int_samples[i+1];
+ s->int_samples[i+1] -= shift(s->int_samples[i], 1);
+ }
+ break;
+ case LEFT_SIDE:
+ for (i = 0; i < s->frame_size; i += s->channels)
+ s->int_samples[i+1] -= s->int_samples[i];
+ break;
+ case RIGHT_SIDE:
+ for (i = 0; i < s->frame_size; i += s->channels)
+ s->int_samples[i] -= s->int_samples[i+1];
+ break;
+ }
+
+ memset(s->window, 0, 4* s->window_size);
+
+ for (i = 0; i < s->tail_size; i++)
+ s->window[x++] = s->tail[i];
+
+ for (i = 0; i < s->frame_size; i++)
+ s->window[x++] = s->int_samples[i];
+
+ for (i = 0; i < s->tail_size; i++)
+ s->window[x++] = 0;
+
+ for (i = 0; i < s->tail_size; i++)
+ s->tail[i] = s->int_samples[s->frame_size - s->tail_size + i];
+
+ // generate taps
+ modified_levinson_durbin(s->window, s->window_size,
+ s->predictor_k, s->num_taps, s->channels, s->tap_quant);
+ if (intlist_write(&pb, s->predictor_k, s->num_taps, 0) < 0)
+ return -1;
+
+ for (ch = 0; ch < s->channels; ch++)
+ {
+ x = s->tail_size+ch;
+ for (i = 0; i < s->block_align; i++)
+ {
+ int sum = 0;
+ for (j = 0; j < s->downsampling; j++, x += s->channels)
+ sum += s->window[x];
+ s->coded_samples[ch][i] = sum;
+ }
+ }
+
+ // simple rate control code
+ if (!s->lossless)
+ {
+ double energy1 = 0.0, energy2 = 0.0;
+ for (ch = 0; ch < s->channels; ch++)
+ {
+ for (i = 0; i < s->block_align; i++)
+ {
+ double sample = s->coded_samples[ch][i];
+ energy2 += sample*sample;
+ energy1 += fabs(sample);
+ }
+ }
+
+ energy2 = sqrt(energy2/(s->channels*s->block_align));
+ energy1 = sqrt(2.0)*energy1/(s->channels*s->block_align);
+
+ // increase bitrate when samples are like a gaussian distribution
+ // reduce bitrate when samples are like a two-tailed exponential distribution
+
+ if (energy2 > energy1)
+ energy2 += (energy2-energy1)*RATE_VARIATION;
+
+ quant = (int)(BASE_QUANT*s->quantization*energy2/SAMPLE_FACTOR);
+// av_log(avctx, AV_LOG_DEBUG, "quant: %d energy: %f / %f\n", quant, energy1, energy2);
+
+ if (quant < 1)
+ quant = 1;
+ if (quant > 65535)
+ quant = 65535;
+
+ set_ue_golomb(&pb, quant);
+
+ quant *= SAMPLE_FACTOR;
+ }
+
+ // write out coded samples
+ for (ch = 0; ch < s->channels; ch++)
+ {
+ if (!s->lossless)
+ for (i = 0; i < s->block_align; i++)
+ s->coded_samples[ch][i] = divide(s->coded_samples[ch][i], quant);
+
+ if (intlist_write(&pb, s->coded_samples[ch], s->block_align, 1) < 0)
+ return -1;
+ }
+
+// av_log(avctx, AV_LOG_DEBUG, "used bytes: %d\n", (put_bits_count(&pb)+7)/8);
+
+ flush_put_bits(&pb);
+ return (put_bits_count(&pb)+7)/8;
+}
+#endif //CONFIG_ENCODERS
+
+#ifdef CONFIG_DECODERS
+static int sonic_decode_init(AVCodecContext *avctx)
+{
+ SonicContext *s = avctx->priv_data;
+ GetBitContext gb;
+ int i, version;
+
+ s->channels = avctx->channels;
+ s->samplerate = avctx->sample_rate;
+
+ if (!avctx->extradata)
+ {
+ av_log(avctx, AV_LOG_ERROR, "No mandatory headers present\n");
+ return -1;
+ }
+
+ init_get_bits(&gb, avctx->extradata, avctx->extradata_size);
+
+ version = get_bits(&gb, 2);
+ if (version > 1)
+ {
+ av_log(avctx, AV_LOG_ERROR, "Unsupported Sonic version, please report\n");
+ return -1;
+ }
+
+ if (version == 1)
+ {
+ s->channels = get_bits(&gb, 2);
+ s->samplerate = samplerate_table[get_bits(&gb, 4)];
+ av_log(avctx, AV_LOG_INFO, "Sonicv2 chans: %d samprate: %d\n",
+ s->channels, s->samplerate);
+ }
+
+ if (s->channels > MAX_CHANNELS)
+ {
+ av_log(avctx, AV_LOG_ERROR, "Only mono and stereo streams are supported by now\n");
+ return -1;
+ }
+
+ s->lossless = get_bits1(&gb);
+ if (!s->lossless)
+ skip_bits(&gb, 3); // XXX FIXME
+ s->decorrelation = get_bits(&gb, 2);
+
+ s->downsampling = get_bits(&gb, 2);
+ s->num_taps = (get_bits(&gb, 5)+1)<<5;
+ if (get_bits1(&gb)) // XXX FIXME
+ av_log(avctx, AV_LOG_INFO, "Custom quant table\n");
+
+ s->block_align = (int)(2048.0*(s->samplerate/44100))/s->downsampling;
+ s->frame_size = s->channels*s->block_align*s->downsampling;
+// avctx->frame_size = s->block_align;
+
+ av_log(avctx, AV_LOG_INFO, "Sonic: ver: %d ls: %d dr: %d taps: %d block: %d frame: %d downsamp: %d\n",
+ version, s->lossless, s->decorrelation, s->num_taps, s->block_align, s->frame_size, s->downsampling);
+
+ // generate taps
+ s->tap_quant = av_mallocz(4* s->num_taps);
+ for (i = 0; i < s->num_taps; i++)
+ s->tap_quant[i] = (int)(sqrt(i+1));
+
+ s->predictor_k = av_mallocz(4* s->num_taps);
+
+ for (i = 0; i < s->channels; i++)
+ {
+ s->predictor_state[i] = av_mallocz(4* s->num_taps);
+ if (!s->predictor_state[i])
+ return -1;
+ }
+
+ for (i = 0; i < s->channels; i++)
+ {
+ s->coded_samples[i] = av_mallocz(4* s->block_align);
+ if (!s->coded_samples[i])
+ return -1;
+ }
+ s->int_samples = av_mallocz(4* s->frame_size);
+
+ return 0;
+}
+
+static int sonic_decode_close(AVCodecContext *avctx)
+{
+ SonicContext *s = avctx->priv_data;
+ int i;
+
+ av_free(s->int_samples);
+ av_free(s->tap_quant);
+ av_free(s->predictor_k);
+
+ for (i = 0; i < s->channels; i++)
+ {
+ av_free(s->predictor_state[i]);
+ av_free(s->coded_samples[i]);
+ }
+
+ return 0;
+}
+
+static int sonic_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ SonicContext *s = avctx->priv_data;
+ GetBitContext gb;
+ int i, quant, ch, j;
+ short *samples = data;
+
+ if (buf_size == 0) return 0;
+
+// av_log(NULL, AV_LOG_INFO, "buf_size: %d\n", buf_size);
+
+ init_get_bits(&gb, buf, buf_size*8);
+
+ intlist_read(&gb, s->predictor_k, s->num_taps, 0);
+
+ // dequantize
+ for (i = 0; i < s->num_taps; i++)
+ s->predictor_k[i] *= s->tap_quant[i];
+
+ if (s->lossless)
+ quant = 1;
+ else
+ quant = get_ue_golomb(&gb) * SAMPLE_FACTOR;
+
+// av_log(NULL, AV_LOG_INFO, "quant: %d\n", quant);
+
+ for (ch = 0; ch < s->channels; ch++)
+ {
+ int x = ch;
+
+ predictor_init_state(s->predictor_k, s->predictor_state[ch], s->num_taps);
+
+ intlist_read(&gb, s->coded_samples[ch], s->block_align, 1);
+
+ for (i = 0; i < s->block_align; i++)
+ {
+ for (j = 0; j < s->downsampling - 1; j++)
+ {
+ s->int_samples[x] = predictor_calc_error(s->predictor_k, s->predictor_state[ch], s->num_taps, 0);
+ x += s->channels;
+ }
+
+ s->int_samples[x] = predictor_calc_error(s->predictor_k, s->predictor_state[ch], s->num_taps, s->coded_samples[ch][i] * quant);
+ x += s->channels;
+ }
+
+ for (i = 0; i < s->num_taps; i++)
+ s->predictor_state[ch][i] = s->int_samples[s->frame_size - s->channels + ch - i*s->channels];
+ }
+
+ switch(s->decorrelation)
+ {
+ case MID_SIDE:
+ for (i = 0; i < s->frame_size; i += s->channels)
+ {
+ s->int_samples[i+1] += shift(s->int_samples[i], 1);
+ s->int_samples[i] -= s->int_samples[i+1];
+ }
+ break;
+ case LEFT_SIDE:
+ for (i = 0; i < s->frame_size; i += s->channels)
+ s->int_samples[i+1] += s->int_samples[i];
+ break;
+ case RIGHT_SIDE:
+ for (i = 0; i < s->frame_size; i += s->channels)
+ s->int_samples[i] += s->int_samples[i+1];
+ break;
+ }
+
+ if (!s->lossless)
+ for (i = 0; i < s->frame_size; i++)
+ s->int_samples[i] = shift(s->int_samples[i], SAMPLE_SHIFT);
+
+ // internal -> short
+ for (i = 0; i < s->frame_size; i++)
+ {
+ if (s->int_samples[i] > 32767)
+ samples[i] = 32767;
+ else if (s->int_samples[i] < -32768)
+ samples[i] = -32768;
+ else
+ samples[i] = s->int_samples[i];
+ }
+
+ align_get_bits(&gb);
+
+ *data_size = s->frame_size * 2;
+
+ return (get_bits_count(&gb)+7)/8;
+}
+#endif
+
+#ifdef CONFIG_ENCODERS
+AVCodec sonic_encoder = {
+ "sonic",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_SONIC,
+ sizeof(SonicContext),
+ sonic_encode_init,
+ sonic_encode_frame,
+ sonic_encode_close,
+ NULL,
+};
+
+AVCodec sonic_ls_encoder = {
+ "sonicls",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_SONIC_LS,
+ sizeof(SonicContext),
+ sonic_encode_init,
+ sonic_encode_frame,
+ sonic_encode_close,
+ NULL,
+};
+#endif
+
+#ifdef CONFIG_DECODERS
+AVCodec sonic_decoder = {
+ "sonic",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_SONIC,
+ sizeof(SonicContext),
+ sonic_decode_init,
+ NULL,
+ sonic_decode_close,
+ sonic_decode_frame,
+};
+#endif
diff --git a/src/libffmpeg/libavcodec/sp5x.h b/contrib/ffmpeg/libavcodec/sp5x.h
index 0d0d3551f..0d0d3551f 100644
--- a/src/libffmpeg/libavcodec/sp5x.h
+++ b/contrib/ffmpeg/libavcodec/sp5x.h
diff --git a/src/libffmpeg/libavcodec/sparc/dsputil_vis.c b/contrib/ffmpeg/libavcodec/sparc/dsputil_vis.c
index 5e59ce776..5e59ce776 100644
--- a/src/libffmpeg/libavcodec/sparc/dsputil_vis.c
+++ b/contrib/ffmpeg/libavcodec/sparc/dsputil_vis.c
diff --git a/src/libffmpeg/libavcodec/sparc/vis.h b/contrib/ffmpeg/libavcodec/sparc/vis.h
index d4a8ce092..d4a8ce092 100644
--- a/src/libffmpeg/libavcodec/sparc/vis.h
+++ b/contrib/ffmpeg/libavcodec/sparc/vis.h
diff --git a/contrib/ffmpeg/libavcodec/svq1.c b/contrib/ffmpeg/libavcodec/svq1.c
new file mode 100644
index 000000000..5087ba8cc
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/svq1.c
@@ -0,0 +1,1425 @@
+/*
+ *
+ * Copyright (C) 2002 the xine project
+ * Copyright (C) 2002 the ffmpeg project
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * (SVQ1 Decoder)
+ * Ported to mplayer by Arpi <arpi@thot.banki.hu>
+ * Ported to libavcodec by Nick Kurshev <nickols_k@mail.ru>
+ *
+ * SVQ1 Encoder (c) 2004 Mike Melanson <melanson@pcisys.net>
+ */
+
+/**
+ * @file svq1.c
+ * Sorenson Vector Quantizer #1 (SVQ1) video codec.
+ * For more information of the SVQ1 algorithm, visit:
+ * http://www.pcisys.net/~melanson/codecs/
+ */
+
+
+//#define DEBUG_SVQ1
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <limits.h>
+
+#include "common.h"
+#include "avcodec.h"
+#include "dsputil.h"
+#include "mpegvideo.h"
+#include "bswap.h"
+
+#undef NDEBUG
+#include <assert.h>
+
+extern const uint8_t mvtab[33][2];
+
+static VLC svq1_block_type;
+static VLC svq1_motion_component;
+static VLC svq1_intra_multistage[6];
+static VLC svq1_inter_multistage[6];
+static VLC svq1_intra_mean;
+static VLC svq1_inter_mean;
+
+#define SVQ1_BLOCK_SKIP 0
+#define SVQ1_BLOCK_INTER 1
+#define SVQ1_BLOCK_INTER_4V 2
+#define SVQ1_BLOCK_INTRA 3
+
+typedef struct SVQ1Context {
+ MpegEncContext m; // needed for motion estimation, should not be used for anything else, the idea is to make the motion estimation eventually independent of MpegEncContext, so this will be removed then (FIXME/XXX)
+ AVCodecContext *avctx;
+ DSPContext dsp;
+ AVFrame picture;
+ AVFrame current_picture;
+ AVFrame last_picture;
+ PutBitContext pb;
+ GetBitContext gb;
+
+ PutBitContext reorder_pb[6]; //why ooh why this sick breadth first order, everything is slower and more complex
+
+ int frame_width;
+ int frame_height;
+
+ /* Y plane block dimensions */
+ int y_block_width;
+ int y_block_height;
+
+ /* U & V plane (C planes) block dimensions */
+ int c_block_width;
+ int c_block_height;
+
+ uint16_t *mb_type;
+ uint32_t *dummy;
+ int16_t (*motion_val8[3])[2];
+ int16_t (*motion_val16[3])[2];
+
+ int64_t rd_total;
+} SVQ1Context;
+
+/* motion vector (prediction) */
+typedef struct svq1_pmv_s {
+ int x;
+ int y;
+} svq1_pmv_t;
+
+#include "svq1_cb.h"
+#include "svq1_vlc.h"
+
+static const uint16_t checksum_table[256] = {
+ 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
+ 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
+ 0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
+ 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
+ 0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
+ 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
+ 0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
+ 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
+ 0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
+ 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
+ 0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
+ 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
+ 0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
+ 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
+ 0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
+ 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
+ 0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
+ 0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
+ 0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
+ 0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
+ 0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
+ 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
+ 0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
+ 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
+ 0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
+ 0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
+ 0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
+ 0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
+ 0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
+ 0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
+ 0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
+ 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0
+};
+
+static const uint8_t string_table[256] = {
+ 0x00, 0xD5, 0x7F, 0xAA, 0xFE, 0x2B, 0x81, 0x54,
+ 0x29, 0xFC, 0x56, 0x83, 0xD7, 0x02, 0xA8, 0x7D,
+ 0x52, 0x87, 0x2D, 0xF8, 0xAC, 0x79, 0xD3, 0x06,
+ 0x7B, 0xAE, 0x04, 0xD1, 0x85, 0x50, 0xFA, 0x2F,
+ 0xA4, 0x71, 0xDB, 0x0E, 0x5A, 0x8F, 0x25, 0xF0,
+ 0x8D, 0x58, 0xF2, 0x27, 0x73, 0xA6, 0x0C, 0xD9,
+ 0xF6, 0x23, 0x89, 0x5C, 0x08, 0xDD, 0x77, 0xA2,
+ 0xDF, 0x0A, 0xA0, 0x75, 0x21, 0xF4, 0x5E, 0x8B,
+ 0x9D, 0x48, 0xE2, 0x37, 0x63, 0xB6, 0x1C, 0xC9,
+ 0xB4, 0x61, 0xCB, 0x1E, 0x4A, 0x9F, 0x35, 0xE0,
+ 0xCF, 0x1A, 0xB0, 0x65, 0x31, 0xE4, 0x4E, 0x9B,
+ 0xE6, 0x33, 0x99, 0x4C, 0x18, 0xCD, 0x67, 0xB2,
+ 0x39, 0xEC, 0x46, 0x93, 0xC7, 0x12, 0xB8, 0x6D,
+ 0x10, 0xC5, 0x6F, 0xBA, 0xEE, 0x3B, 0x91, 0x44,
+ 0x6B, 0xBE, 0x14, 0xC1, 0x95, 0x40, 0xEA, 0x3F,
+ 0x42, 0x97, 0x3D, 0xE8, 0xBC, 0x69, 0xC3, 0x16,
+ 0xEF, 0x3A, 0x90, 0x45, 0x11, 0xC4, 0x6E, 0xBB,
+ 0xC6, 0x13, 0xB9, 0x6C, 0x38, 0xED, 0x47, 0x92,
+ 0xBD, 0x68, 0xC2, 0x17, 0x43, 0x96, 0x3C, 0xE9,
+ 0x94, 0x41, 0xEB, 0x3E, 0x6A, 0xBF, 0x15, 0xC0,
+ 0x4B, 0x9E, 0x34, 0xE1, 0xB5, 0x60, 0xCA, 0x1F,
+ 0x62, 0xB7, 0x1D, 0xC8, 0x9C, 0x49, 0xE3, 0x36,
+ 0x19, 0xCC, 0x66, 0xB3, 0xE7, 0x32, 0x98, 0x4D,
+ 0x30, 0xE5, 0x4F, 0x9A, 0xCE, 0x1B, 0xB1, 0x64,
+ 0x72, 0xA7, 0x0D, 0xD8, 0x8C, 0x59, 0xF3, 0x26,
+ 0x5B, 0x8E, 0x24, 0xF1, 0xA5, 0x70, 0xDA, 0x0F,
+ 0x20, 0xF5, 0x5F, 0x8A, 0xDE, 0x0B, 0xA1, 0x74,
+ 0x09, 0xDC, 0x76, 0xA3, 0xF7, 0x22, 0x88, 0x5D,
+ 0xD6, 0x03, 0xA9, 0x7C, 0x28, 0xFD, 0x57, 0x82,
+ 0xFF, 0x2A, 0x80, 0x55, 0x01, 0xD4, 0x7E, 0xAB,
+ 0x84, 0x51, 0xFB, 0x2E, 0x7A, 0xAF, 0x05, 0xD0,
+ 0xAD, 0x78, 0xD2, 0x07, 0x53, 0x86, 0x2C, 0xF9
+};
+
+#define SVQ1_PROCESS_VECTOR()\
+ for (; level > 0; i++) {\
+ /* process next depth */\
+ if (i == m) {\
+ m = n;\
+ if (--level == 0)\
+ break;\
+ }\
+ /* divide block if next bit set */\
+ if (get_bits (bitbuf, 1) == 0)\
+ break;\
+ /* add child nodes */\
+ list[n++] = list[i];\
+ list[n++] = list[i] + (((level & 1) ? pitch : 1) << ((level / 2) + 1));\
+ }
+
+#define SVQ1_ADD_CODEBOOK()\
+ /* add codebook entries to vector */\
+ for (j=0; j < stages; j++) {\
+ n3 = codebook[entries[j]] ^ 0x80808080;\
+ n1 += ((n3 & 0xFF00FF00) >> 8);\
+ n2 += (n3 & 0x00FF00FF);\
+ }\
+\
+ /* clip to [0..255] */\
+ if (n1 & 0xFF00FF00) {\
+ n3 = ((( n1 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;\
+ n1 += 0x7F007F00;\
+ n1 |= (((~n1 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;\
+ n1 &= (n3 & 0x00FF00FF);\
+ }\
+\
+ if (n2 & 0xFF00FF00) {\
+ n3 = ((( n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;\
+ n2 += 0x7F007F00;\
+ n2 |= (((~n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;\
+ n2 &= (n3 & 0x00FF00FF);\
+ }
+
+#define SVQ1_DO_CODEBOOK_INTRA()\
+ for (y=0; y < height; y++) {\
+ for (x=0; x < (width / 4); x++, codebook++) {\
+ n1 = n4;\
+ n2 = n4;\
+ SVQ1_ADD_CODEBOOK()\
+ /* store result */\
+ dst[x] = (n1 << 8) | n2;\
+ }\
+ dst += (pitch / 4);\
+ }
+
+#define SVQ1_DO_CODEBOOK_NONINTRA()\
+ for (y=0; y < height; y++) {\
+ for (x=0; x < (width / 4); x++, codebook++) {\
+ n3 = dst[x];\
+ /* add mean value to vector */\
+ n1 = ((n3 & 0xFF00FF00) >> 8) + n4;\
+ n2 = (n3 & 0x00FF00FF) + n4;\
+ SVQ1_ADD_CODEBOOK()\
+ /* store result */\
+ dst[x] = (n1 << 8) | n2;\
+ }\
+ dst += (pitch / 4);\
+ }
+
+#define SVQ1_CALC_CODEBOOK_ENTRIES(cbook)\
+ codebook = (const uint32_t *) cbook[level];\
+ bit_cache = get_bits (bitbuf, 4*stages);\
+ /* calculate codebook entries for this vector */\
+ for (j=0; j < stages; j++) {\
+ entries[j] = (((bit_cache >> (4*(stages - j - 1))) & 0xF) + 16*j) << (level + 1);\
+ }\
+ mean -= (stages * 128);\
+ n4 = ((mean + (mean >> 31)) << 16) | (mean & 0xFFFF);
+
+static int svq1_decode_block_intra (GetBitContext *bitbuf, uint8_t *pixels, int pitch ) {
+ uint32_t bit_cache;
+ uint8_t *list[63];
+ uint32_t *dst;
+ const uint32_t *codebook;
+ int entries[6];
+ int i, j, m, n;
+ int mean, stages;
+ unsigned x, y, width, height, level;
+ uint32_t n1, n2, n3, n4;
+
+ /* initialize list for breadth first processing of vectors */
+ list[0] = pixels;
+
+ /* recursively process vector */
+ for (i=0, m=1, n=1, level=5; i < n; i++) {
+ SVQ1_PROCESS_VECTOR();
+
+ /* destination address and vector size */
+ dst = (uint32_t *) list[i];
+ width = 1 << ((4 + level) /2);
+ height = 1 << ((3 + level) /2);
+
+ /* get number of stages (-1 skips vector, 0 for mean only) */
+ stages = get_vlc2(bitbuf, svq1_intra_multistage[level].table, 3, 3) - 1;
+
+ if (stages == -1) {
+ for (y=0; y < height; y++) {
+ memset (&dst[y*(pitch / 4)], 0, width);
+ }
+ continue; /* skip vector */
+ }
+
+ if ((stages > 0) && (level >= 4)) {
+#ifdef DEBUG_SVQ1
+ av_log(s->avctx, AV_LOG_INFO, "Error (svq1_decode_block_intra): invalid vector: stages=%i level=%i\n",stages,level);
+#endif
+ return -1; /* invalid vector */
+ }
+
+ mean = get_vlc2(bitbuf, svq1_intra_mean.table, 8, 3);
+
+ if (stages == 0) {
+ for (y=0; y < height; y++) {
+ memset (&dst[y*(pitch / 4)], mean, width);
+ }
+ } else {
+ SVQ1_CALC_CODEBOOK_ENTRIES(svq1_intra_codebooks);
+ SVQ1_DO_CODEBOOK_INTRA()
+ }
+ }
+
+ return 0;
+}
+
+static int svq1_decode_block_non_intra (GetBitContext *bitbuf, uint8_t *pixels, int pitch ) {
+ uint32_t bit_cache;
+ uint8_t *list[63];
+ uint32_t *dst;
+ const uint32_t *codebook;
+ int entries[6];
+ int i, j, m, n;
+ int mean, stages;
+ int x, y, width, height, level;
+ uint32_t n1, n2, n3, n4;
+
+ /* initialize list for breadth first processing of vectors */
+ list[0] = pixels;
+
+ /* recursively process vector */
+ for (i=0, m=1, n=1, level=5; i < n; i++) {
+ SVQ1_PROCESS_VECTOR();
+
+ /* destination address and vector size */
+ dst = (uint32_t *) list[i];
+ width = 1 << ((4 + level) /2);
+ height = 1 << ((3 + level) /2);
+
+ /* get number of stages (-1 skips vector, 0 for mean only) */
+ stages = get_vlc2(bitbuf, svq1_inter_multistage[level].table, 3, 2) - 1;
+
+ if (stages == -1) continue; /* skip vector */
+
+ if ((stages > 0) && (level >= 4)) {
+#ifdef DEBUG_SVQ1
+ av_log(s->avctx, AV_LOG_INFO, "Error (svq1_decode_block_non_intra): invalid vector: stages=%i level=%i\n",stages,level);
+#endif
+ return -1; /* invalid vector */
+ }
+
+ mean = get_vlc2(bitbuf, svq1_inter_mean.table, 9, 3) - 256;
+
+ SVQ1_CALC_CODEBOOK_ENTRIES(svq1_inter_codebooks);
+ SVQ1_DO_CODEBOOK_NONINTRA()
+ }
+ return 0;
+}
+
+static int svq1_decode_motion_vector (GetBitContext *bitbuf, svq1_pmv_t *mv, svq1_pmv_t **pmv) {
+ int diff;
+ int i;
+
+ for (i=0; i < 2; i++) {
+
+ /* get motion code */
+ diff = get_vlc2(bitbuf, svq1_motion_component.table, 7, 2);
+ if(diff<0)
+ return -1;
+ else if(diff){
+ if(get_bits1(bitbuf)) diff= -diff;
+ }
+
+ /* add median of motion vector predictors and clip result */
+ if (i == 1)
+ mv->y = ((diff + mid_pred(pmv[0]->y, pmv[1]->y, pmv[2]->y)) << 26) >> 26;
+ else
+ mv->x = ((diff + mid_pred(pmv[0]->x, pmv[1]->x, pmv[2]->x)) << 26) >> 26;
+ }
+
+ return 0;
+}
+
+static void svq1_skip_block (uint8_t *current, uint8_t *previous, int pitch, int x, int y) {
+ uint8_t *src;
+ uint8_t *dst;
+ int i;
+
+ src = &previous[x + y*pitch];
+ dst = current;
+
+ for (i=0; i < 16; i++) {
+ memcpy (dst, src, 16);
+ src += pitch;
+ dst += pitch;
+ }
+}
+
+static int svq1_motion_inter_block (MpegEncContext *s, GetBitContext *bitbuf,
+ uint8_t *current, uint8_t *previous, int pitch,
+ svq1_pmv_t *motion, int x, int y) {
+ uint8_t *src;
+ uint8_t *dst;
+ svq1_pmv_t mv;
+ svq1_pmv_t *pmv[3];
+ int result;
+
+ /* predict and decode motion vector */
+ pmv[0] = &motion[0];
+ if (y == 0) {
+ pmv[1] =
+ pmv[2] = pmv[0];
+ }
+ else {
+ pmv[1] = &motion[(x / 8) + 2];
+ pmv[2] = &motion[(x / 8) + 4];
+ }
+
+ result = svq1_decode_motion_vector (bitbuf, &mv, pmv);
+
+ if (result != 0)
+ return result;
+
+ motion[0].x =
+ motion[(x / 8) + 2].x =
+ motion[(x / 8) + 3].x = mv.x;
+ motion[0].y =
+ motion[(x / 8) + 2].y =
+ motion[(x / 8) + 3].y = mv.y;
+
+ if(y + (mv.y >> 1)<0)
+ mv.y= 0;
+ if(x + (mv.x >> 1)<0)
+ mv.x= 0;
+
+#if 0
+ int w= (s->width+15)&~15;
+ int h= (s->height+15)&~15;
+ if(x + (mv.x >> 1)<0 || y + (mv.y >> 1)<0 || x + (mv.x >> 1) + 16 > w || y + (mv.y >> 1) + 16> h)
+ av_log(s->avctx, AV_LOG_INFO, "%d %d %d %d\n", x, y, x + (mv.x >> 1), y + (mv.y >> 1));
+#endif
+
+ src = &previous[(x + (mv.x >> 1)) + (y + (mv.y >> 1))*pitch];
+ dst = current;
+
+ s->dsp.put_pixels_tab[0][((mv.y & 1) << 1) | (mv.x & 1)](dst,src,pitch,16);
+
+ return 0;
+}
+
+static int svq1_motion_inter_4v_block (MpegEncContext *s, GetBitContext *bitbuf,
+ uint8_t *current, uint8_t *previous, int pitch,
+ svq1_pmv_t *motion,int x, int y) {
+ uint8_t *src;
+ uint8_t *dst;
+ svq1_pmv_t mv;
+ svq1_pmv_t *pmv[4];
+ int i, result;
+
+ /* predict and decode motion vector (0) */
+ pmv[0] = &motion[0];
+ if (y == 0) {
+ pmv[1] =
+ pmv[2] = pmv[0];
+ }
+ else {
+ pmv[1] = &motion[(x / 8) + 2];
+ pmv[2] = &motion[(x / 8) + 4];
+ }
+
+ result = svq1_decode_motion_vector (bitbuf, &mv, pmv);
+
+ if (result != 0)
+ return result;
+
+ /* predict and decode motion vector (1) */
+ pmv[0] = &mv;
+ if (y == 0) {
+ pmv[1] =
+ pmv[2] = pmv[0];
+ }
+ else {
+ pmv[1] = &motion[(x / 8) + 3];
+ }
+ result = svq1_decode_motion_vector (bitbuf, &motion[0], pmv);
+
+ if (result != 0)
+ return result;
+
+ /* predict and decode motion vector (2) */
+ pmv[1] = &motion[0];
+ pmv[2] = &motion[(x / 8) + 1];
+
+ result = svq1_decode_motion_vector (bitbuf, &motion[(x / 8) + 2], pmv);
+
+ if (result != 0)
+ return result;
+
+ /* predict and decode motion vector (3) */
+ pmv[2] = &motion[(x / 8) + 2];
+ pmv[3] = &motion[(x / 8) + 3];
+
+ result = svq1_decode_motion_vector (bitbuf, pmv[3], pmv);
+
+ if (result != 0)
+ return result;
+
+ /* form predictions */
+ for (i=0; i < 4; i++) {
+ int mvx= pmv[i]->x + (i&1)*16;
+ int mvy= pmv[i]->y + (i>>1)*16;
+
+ ///XXX /FIXME cliping or padding?
+ if(y + (mvy >> 1)<0)
+ mvy= 0;
+ if(x + (mvx >> 1)<0)
+ mvx= 0;
+
+#if 0
+ int w= (s->width+15)&~15;
+ int h= (s->height+15)&~15;
+ if(x + (mvx >> 1)<0 || y + (mvy >> 1)<0 || x + (mvx >> 1) + 8 > w || y + (mvy >> 1) + 8> h)
+ av_log(s->avctx, AV_LOG_INFO, "%d %d %d %d\n", x, y, x + (mvx >> 1), y + (mvy >> 1));
+#endif
+ src = &previous[(x + (mvx >> 1)) + (y + (mvy >> 1))*pitch];
+ dst = current;
+
+ s->dsp.put_pixels_tab[1][((mvy & 1) << 1) | (mvx & 1)](dst,src,pitch,8);
+
+ /* select next block */
+ if (i & 1) {
+ current += 8*(pitch - 1);
+ } else {
+ current += 8;
+ }
+ }
+
+ return 0;
+}
+
+static int svq1_decode_delta_block (MpegEncContext *s, GetBitContext *bitbuf,
+ uint8_t *current, uint8_t *previous, int pitch,
+ svq1_pmv_t *motion, int x, int y) {
+ uint32_t block_type;
+ int result = 0;
+
+ /* get block type */
+ block_type = get_vlc2(bitbuf, svq1_block_type.table, 2, 2);
+
+ /* reset motion vectors */
+ if (block_type == SVQ1_BLOCK_SKIP || block_type == SVQ1_BLOCK_INTRA) {
+ motion[0].x =
+ motion[0].y =
+ motion[(x / 8) + 2].x =
+ motion[(x / 8) + 2].y =
+ motion[(x / 8) + 3].x =
+ motion[(x / 8) + 3].y = 0;
+ }
+
+ switch (block_type) {
+ case SVQ1_BLOCK_SKIP:
+ svq1_skip_block (current, previous, pitch, x, y);
+ break;
+
+ case SVQ1_BLOCK_INTER:
+ result = svq1_motion_inter_block (s, bitbuf, current, previous, pitch, motion, x, y);
+
+ if (result != 0)
+ {
+#ifdef DEBUG_SVQ1
+ av_log(s->avctx, AV_LOG_INFO, "Error in svq1_motion_inter_block %i\n",result);
+#endif
+ break;
+ }
+ result = svq1_decode_block_non_intra (bitbuf, current, pitch);
+ break;
+
+ case SVQ1_BLOCK_INTER_4V:
+ result = svq1_motion_inter_4v_block (s, bitbuf, current, previous, pitch, motion, x, y);
+
+ if (result != 0)
+ {
+#ifdef DEBUG_SVQ1
+ av_log(s->avctx, AV_LOG_INFO, "Error in svq1_motion_inter_4v_block %i\n",result);
+#endif
+ break;
+ }
+ result = svq1_decode_block_non_intra (bitbuf, current, pitch);
+ break;
+
+ case SVQ1_BLOCK_INTRA:
+ result = svq1_decode_block_intra (bitbuf, current, pitch);
+ break;
+ }
+
+ return result;
+}
+
+/* standard video sizes */
+static struct { int width; int height; } svq1_frame_size_table[8] = {
+ { 160, 120 }, { 128, 96 }, { 176, 144 }, { 352, 288 },
+ { 704, 576 }, { 240, 180 }, { 320, 240 }, { -1, -1 }
+};
+
+static uint16_t svq1_packet_checksum (uint8_t *data, int length, int value) {
+ int i;
+
+ for (i=0; i < length; i++) {
+ value = checksum_table[data[i] ^ (value >> 8)] ^ ((value & 0xFF) << 8);
+ }
+
+ return value;
+}
+
+#if 0 /* unused, remove? */
+static uint16_t svq1_component_checksum (uint16_t *pixels, int pitch,
+ int width, int height, int value) {
+ int x, y;
+
+ for (y=0; y < height; y++) {
+ for (x=0; x < width; x++) {
+ value = checksum_table[pixels[x] ^ (value >> 8)] ^ ((value & 0xFF) << 8);
+ }
+
+ pixels += pitch;
+ }
+
+ return value;
+}
+#endif
+
+#ifdef CONFIG_DECODERS
+static void svq1_parse_string (GetBitContext *bitbuf, uint8_t *out) {
+ uint8_t seed;
+ int i;
+
+ out[0] = get_bits (bitbuf, 8);
+
+ seed = string_table[out[0]];
+
+ for (i=1; i <= out[0]; i++) {
+ out[i] = get_bits (bitbuf, 8) ^ seed;
+ seed = string_table[out[i] ^ seed];
+ }
+}
+
+static int svq1_decode_frame_header (GetBitContext *bitbuf,MpegEncContext *s) {
+ int frame_size_code;
+ int temporal_reference;
+
+ temporal_reference = get_bits (bitbuf, 8);
+
+ /* frame type */
+ s->pict_type= get_bits (bitbuf, 2)+1;
+ if(s->pict_type==4)
+ return -1;
+
+ if (s->pict_type == I_TYPE) {
+
+ /* unknown fields */
+ if (s->f_code == 0x50 || s->f_code == 0x60) {
+ int csum = get_bits (bitbuf, 16);
+
+ csum = svq1_packet_checksum ((uint8_t *)bitbuf->buffer, bitbuf->size_in_bits>>3, csum);
+
+// av_log(s->avctx, AV_LOG_INFO, "%s checksum (%02x) for packet data\n",
+// (csum == 0) ? "correct" : "incorrect", csum);
+ }
+
+ if ((s->f_code ^ 0x10) >= 0x50) {
+ uint8_t msg[256];
+
+ svq1_parse_string (bitbuf, msg);
+
+ av_log(s->avctx, AV_LOG_INFO, "embedded message: \"%s\"\n", (char *) msg);
+ }
+
+ skip_bits (bitbuf, 2);
+ skip_bits (bitbuf, 2);
+ skip_bits1 (bitbuf);
+
+ /* load frame size */
+ frame_size_code = get_bits (bitbuf, 3);
+
+ if (frame_size_code == 7) {
+ /* load width, height (12 bits each) */
+ s->width = get_bits (bitbuf, 12);
+ s->height = get_bits (bitbuf, 12);
+
+ if (!s->width || !s->height)
+ return -1;
+ } else {
+ /* get width, height from table */
+ s->width = svq1_frame_size_table[frame_size_code].width;
+ s->height = svq1_frame_size_table[frame_size_code].height;
+ }
+ }
+
+ /* unknown fields */
+ if (get_bits (bitbuf, 1) == 1) {
+ skip_bits1 (bitbuf); /* use packet checksum if (1) */
+ skip_bits1 (bitbuf); /* component checksums after image data if (1) */
+
+ if (get_bits (bitbuf, 2) != 0)
+ return -1;
+ }
+
+ if (get_bits (bitbuf, 1) == 1) {
+ skip_bits1 (bitbuf);
+ skip_bits (bitbuf, 4);
+ skip_bits1 (bitbuf);
+ skip_bits (bitbuf, 2);
+
+ while (get_bits (bitbuf, 1) == 1) {
+ skip_bits (bitbuf, 8);
+ }
+ }
+
+ return 0;
+}
+
+static int svq1_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ MpegEncContext *s=avctx->priv_data;
+ uint8_t *current, *previous;
+ int result, i, x, y, width, height;
+ AVFrame *pict = data;
+
+ /* initialize bit buffer */
+ init_get_bits(&s->gb,buf,buf_size*8);
+
+ /* decode frame header */
+ s->f_code = get_bits (&s->gb, 22);
+
+ if ((s->f_code & ~0x70) || !(s->f_code & 0x60))
+ return -1;
+
+ /* swap some header bytes (why?) */
+ if (s->f_code != 0x20) {
+ uint32_t *src = (uint32_t *) (buf + 4);
+
+ for (i=0; i < 4; i++) {
+ src[i] = ((src[i] << 16) | (src[i] >> 16)) ^ src[7 - i];
+ }
+ }
+
+ result = svq1_decode_frame_header (&s->gb, s);
+
+ if (result != 0)
+ {
+#ifdef DEBUG_SVQ1
+ av_log(s->avctx, AV_LOG_INFO, "Error in svq1_decode_frame_header %i\n",result);
+#endif
+ return result;
+ }
+
+ //FIXME this avoids some confusion for "B frames" without 2 references
+ //this should be removed after libavcodec can handle more flexible picture types & ordering
+ if(s->pict_type==B_TYPE && s->last_picture_ptr==NULL) return buf_size;
+
+ if(avctx->hurry_up && s->pict_type==B_TYPE) return buf_size;
+ if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==B_TYPE)
+ ||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=I_TYPE)
+ || avctx->skip_frame >= AVDISCARD_ALL)
+ return buf_size;
+
+ if(MPV_frame_start(s, avctx) < 0)
+ return -1;
+
+ /* decode y, u and v components */
+ for (i=0; i < 3; i++) {
+ int linesize;
+ if (i == 0) {
+ width = (s->width+15)&~15;
+ height = (s->height+15)&~15;
+ linesize= s->linesize;
+ } else {
+ if(s->flags&CODEC_FLAG_GRAY) break;
+ width = (s->width/4+15)&~15;
+ height = (s->height/4+15)&~15;
+ linesize= s->uvlinesize;
+ }
+
+ current = s->current_picture.data[i];
+
+ if(s->pict_type==B_TYPE){
+ previous = s->next_picture.data[i];
+ }else{
+ previous = s->last_picture.data[i];
+ }
+
+ if (s->pict_type == I_TYPE) {
+ /* keyframe */
+ for (y=0; y < height; y+=16) {
+ for (x=0; x < width; x+=16) {
+ result = svq1_decode_block_intra (&s->gb, &current[x], linesize);
+ if (result != 0)
+ {
+//#ifdef DEBUG_SVQ1
+ av_log(s->avctx, AV_LOG_INFO, "Error in svq1_decode_block %i (keyframe)\n",result);
+//#endif
+ return result;
+ }
+ }
+ current += 16*linesize;
+ }
+ } else {
+ svq1_pmv_t pmv[width/8+3];
+ /* delta frame */
+ memset (pmv, 0, ((width / 8) + 3) * sizeof(svq1_pmv_t));
+
+ for (y=0; y < height; y+=16) {
+ for (x=0; x < width; x+=16) {
+ result = svq1_decode_delta_block (s, &s->gb, &current[x], previous,
+ linesize, pmv, x, y);
+ if (result != 0)
+ {
+#ifdef DEBUG_SVQ1
+ av_log(s->avctx, AV_LOG_INFO, "Error in svq1_decode_delta_block %i\n",result);
+#endif
+ return result;
+ }
+ }
+
+ pmv[0].x =
+ pmv[0].y = 0;
+
+ current += 16*linesize;
+ }
+ }
+ }
+
+ *pict = *(AVFrame*)&s->current_picture;
+
+
+ MPV_frame_end(s);
+
+ *data_size=sizeof(AVFrame);
+ return buf_size;
+}
+
+static int svq1_decode_init(AVCodecContext *avctx)
+{
+ MpegEncContext *s = avctx->priv_data;
+ int i;
+
+ MPV_decode_defaults(s);
+
+ s->avctx = avctx;
+ s->width = (avctx->width+3)&~3;
+ s->height = (avctx->height+3)&~3;
+ s->codec_id= avctx->codec->id;
+ avctx->pix_fmt = PIX_FMT_YUV410P;
+ avctx->has_b_frames= 1; // not true, but DP frames and these behave like unidirectional b frames
+ s->flags= avctx->flags;
+ if (MPV_common_init(s) < 0) return -1;
+
+ init_vlc(&svq1_block_type, 2, 4,
+ &svq1_block_type_vlc[0][1], 2, 1,
+ &svq1_block_type_vlc[0][0], 2, 1, 1);
+
+ init_vlc(&svq1_motion_component, 7, 33,
+ &mvtab[0][1], 2, 1,
+ &mvtab[0][0], 2, 1, 1);
+
+ for (i = 0; i < 6; i++) {
+ init_vlc(&svq1_intra_multistage[i], 3, 8,
+ &svq1_intra_multistage_vlc[i][0][1], 2, 1,
+ &svq1_intra_multistage_vlc[i][0][0], 2, 1, 1);
+ init_vlc(&svq1_inter_multistage[i], 3, 8,
+ &svq1_inter_multistage_vlc[i][0][1], 2, 1,
+ &svq1_inter_multistage_vlc[i][0][0], 2, 1, 1);
+ }
+
+ init_vlc(&svq1_intra_mean, 8, 256,
+ &svq1_intra_mean_vlc[0][1], 4, 2,
+ &svq1_intra_mean_vlc[0][0], 4, 2, 1);
+
+ init_vlc(&svq1_inter_mean, 9, 512,
+ &svq1_inter_mean_vlc[0][1], 4, 2,
+ &svq1_inter_mean_vlc[0][0], 4, 2, 1);
+
+ return 0;
+}
+
+static int svq1_decode_end(AVCodecContext *avctx)
+{
+ MpegEncContext *s = avctx->priv_data;
+
+ MPV_common_end(s);
+ return 0;
+}
+#endif /* CONFIG_DECODERS */
+
+#ifdef CONFIG_ENCODERS
+static void svq1_write_header(SVQ1Context *s, int frame_type)
+{
+ int i;
+
+ /* frame code */
+ put_bits(&s->pb, 22, 0x20);
+
+ /* temporal reference (sure hope this is a "don't care") */
+ put_bits(&s->pb, 8, 0x00);
+
+ /* frame type */
+ put_bits(&s->pb, 2, frame_type - 1);
+
+ if (frame_type == I_TYPE) {
+
+ /* no checksum since frame code is 0x20 */
+
+ /* no embedded string either */
+
+ /* 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 ((svq1_frame_size_table[i].width == s->frame_width) &&
+ (svq1_frame_size_table[i].height == s->frame_height))
+ {
+ put_bits(&s->pb, 3, i);
+ break;
+ }
+ }
+
+ 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);
+ }
+ }
+
+ /* no checksum or extra data (next 2 bits get 0) */
+ put_bits(&s->pb, 2, 0);
+}
+
+
+#define QUALITY_THRESHOLD 100
+#define THRESHOLD_MULTIPLIER 0.6
+
+#if defined(HAVE_ALTIVEC)
+#undef vector
+#endif
+
+static int encode_block(SVQ1Context *s, uint8_t *src, uint8_t *ref, uint8_t *decoded, int stride, int level, int threshold, int lambda, int intra){
+ int count, y, x, i, j, split, best_mean, best_score, best_count;
+ int best_vector[6];
+ int block_sum[7]= {0, 0, 0, 0, 0, 0};
+ int w= 2<<((level+2)>>1);
+ int h= 2<<((level+1)>>1);
+ int size=w*h;
+ int16_t block[7][256];
+ const int8_t *codebook_sum, *codebook;
+ const uint16_t (*mean_vlc)[2];
+ const uint8_t (*multistage_vlc)[2];
+
+ best_score=0;
+ //FIXME optimize, this doenst need to be done multiple times
+ if(intra){
+ codebook_sum= svq1_intra_codebook_sum[level];
+ codebook= svq1_intra_codebooks[level];
+ mean_vlc= svq1_intra_mean_vlc;
+ multistage_vlc= svq1_intra_multistage_vlc[level];
+ for(y=0; y<h; y++){
+ for(x=0; x<w; x++){
+ int v= src[x + y*stride];
+ block[0][x + w*y]= v;
+ best_score += v*v;
+ block_sum[0] += v;
+ }
+ }
+ }else{
+ codebook_sum= svq1_inter_codebook_sum[level];
+ codebook= svq1_inter_codebooks[level];
+ mean_vlc= svq1_inter_mean_vlc + 256;
+ multistage_vlc= svq1_inter_multistage_vlc[level];
+ for(y=0; y<h; y++){
+ for(x=0; x<w; x++){
+ int v= src[x + y*stride] - ref[x + y*stride];
+ block[0][x + w*y]= v;
+ best_score += v*v;
+ block_sum[0] += v;
+ }
+ }
+ }
+
+ best_count=0;
+ best_score -= ((block_sum[0]*block_sum[0])>>(level+3));
+ best_mean= (block_sum[0] + (size>>1)) >> (level+3);
+
+ if(level<4){
+ for(count=1; count<7; count++){
+ int best_vector_score= INT_MAX;
+ int best_vector_sum=-999, best_vector_mean=-999;
+ const int stage= count-1;
+ const int8_t *vector;
+
+ for(i=0; i<16; i++){
+ int sum= codebook_sum[stage*16 + i];
+ int sqr, diff, score;
+
+ vector = codebook + stage*size*16 + i*size;
+ sqr = s->dsp.ssd_int8_vs_int16(vector, block[stage], size);
+ diff= block_sum[stage] - sum;
+ score= sqr - ((diff*(int64_t)diff)>>(level+3)); //FIXME 64bit slooow
+ if(score < best_vector_score){
+ int mean= (diff + (size>>1)) >> (level+3);
+ assert(mean >-300 && mean<300);
+ mean= av_clip(mean, intra?0:-256, 255);
+ best_vector_score= score;
+ best_vector[stage]= i;
+ best_vector_sum= sum;
+ best_vector_mean= mean;
+ }
+ }
+ assert(best_vector_mean != -999);
+ vector= codebook + stage*size*16 + best_vector[stage]*size;
+ for(j=0; j<size; j++){
+ block[stage+1][j] = block[stage][j] - vector[j];
+ }
+ block_sum[stage+1]= block_sum[stage] - best_vector_sum;
+ best_vector_score +=
+ lambda*(+ 1 + 4*count
+ + multistage_vlc[1+count][1]
+ + mean_vlc[best_vector_mean][1]);
+
+ if(best_vector_score < best_score){
+ best_score= best_vector_score;
+ best_count= count;
+ best_mean= best_vector_mean;
+ }
+ }
+ }
+
+ split=0;
+ if(best_score > threshold && level){
+ int score=0;
+ int offset= (level&1) ? stride*h/2 : w/2;
+ PutBitContext backup[6];
+
+ for(i=level-1; i>=0; i--){
+ backup[i]= s->reorder_pb[i];
+ }
+ score += encode_block(s, src , ref , decoded , stride, level-1, threshold>>1, lambda, intra);
+ score += encode_block(s, src + offset, ref + offset, decoded + offset, stride, level-1, threshold>>1, lambda, intra);
+ score += lambda;
+
+ if(score < best_score){
+ best_score= score;
+ split=1;
+ }else{
+ for(i=level-1; i>=0; i--){
+ s->reorder_pb[i]= backup[i];
+ }
+ }
+ }
+ if (level > 0)
+ put_bits(&s->reorder_pb[level], 1, split);
+
+ if(!split){
+ assert((best_mean >= 0 && best_mean<256) || !intra);
+ assert(best_mean >= -256 && best_mean<256);
+ assert(best_count >=0 && best_count<7);
+ assert(level<4 || best_count==0);
+
+ /* output the encoding */
+ put_bits(&s->reorder_pb[level],
+ multistage_vlc[1 + best_count][1],
+ multistage_vlc[1 + best_count][0]);
+ put_bits(&s->reorder_pb[level], mean_vlc[best_mean][1],
+ mean_vlc[best_mean][0]);
+
+ for (i = 0; i < best_count; i++){
+ assert(best_vector[i]>=0 && best_vector[i]<16);
+ put_bits(&s->reorder_pb[level], 4, best_vector[i]);
+ }
+
+ for(y=0; y<h; y++){
+ for(x=0; x<w; x++){
+ decoded[x + y*stride]= src[x + y*stride] - block[best_count][x + w*y] + best_mean;
+ }
+ }
+ }
+
+ return best_score;
+}
+
+
+static int svq1_encode_plane(SVQ1Context *s, int plane, unsigned char *src_plane, unsigned char *ref_plane, unsigned char *decoded_plane,
+ int width, int height, int src_stride, int stride)
+{
+ int x, y;
+ int i;
+ int block_width, block_height;
+ int level;
+ int threshold[6];
+ const int lambda= (s->picture.quality*s->picture.quality) >> (2*FF_LAMBDA_SHIFT);
+
+ /* figure out the acceptable level thresholds in advance */
+ threshold[5] = QUALITY_THRESHOLD;
+ for (level = 4; level >= 0; level--)
+ threshold[level] = threshold[level + 1] * THRESHOLD_MULTIPLIER;
+
+ block_width = (width + 15) / 16;
+ block_height = (height + 15) / 16;
+
+ if(s->picture.pict_type == P_TYPE){
+ s->m.avctx= s->avctx;
+ s->m.current_picture_ptr= &s->m.current_picture;
+ s->m.last_picture_ptr = &s->m.last_picture;
+ s->m.last_picture.data[0]= ref_plane;
+ s->m.linesize=
+ s->m.last_picture.linesize[0]=
+ s->m.new_picture.linesize[0]=
+ s->m.current_picture.linesize[0]= stride;
+ s->m.width= width;
+ s->m.height= height;
+ s->m.mb_width= block_width;
+ s->m.mb_height= block_height;
+ s->m.mb_stride= s->m.mb_width+1;
+ s->m.b8_stride= 2*s->m.mb_width+1;
+ s->m.f_code=1;
+ s->m.pict_type= s->picture.pict_type;
+ s->m.me_method= s->avctx->me_method;
+ s->m.me.scene_change_score=0;
+ s->m.flags= s->avctx->flags;
+// s->m.out_format = FMT_H263;
+// s->m.unrestricted_mv= 1;
+
+ s->m.lambda= s->picture.quality;
+ s->m.qscale= (s->m.lambda*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7);
+ s->m.lambda2= (s->m.lambda*s->m.lambda + FF_LAMBDA_SCALE/2) >> FF_LAMBDA_SHIFT;
+
+ if(!s->motion_val8[plane]){
+ s->motion_val8 [plane]= av_mallocz((s->m.b8_stride*block_height*2 + 2)*2*sizeof(int16_t));
+ s->motion_val16[plane]= av_mallocz((s->m.mb_stride*(block_height + 2) + 1)*2*sizeof(int16_t));
+ }
+
+ s->m.mb_type= s->mb_type;
+
+ //dummies, to avoid segfaults
+ s->m.current_picture.mb_mean= (uint8_t *)s->dummy;
+ s->m.current_picture.mb_var= (uint16_t*)s->dummy;
+ s->m.current_picture.mc_mb_var= (uint16_t*)s->dummy;
+ s->m.current_picture.mb_type= s->dummy;
+
+ s->m.current_picture.motion_val[0]= s->motion_val8[plane] + 2;
+ s->m.p_mv_table= s->motion_val16[plane] + s->m.mb_stride + 1;
+ s->m.dsp= s->dsp; //move
+ ff_init_me(&s->m);
+
+ 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;
+
+ for(i=0; i<16 && i + 16*y<height; i++){
+ memcpy(&src[i*stride], &src_plane[(i+16*y)*src_stride], width);
+ for(x=width; x<16*block_width; x++)
+ src[i*stride+x]= src[i*stride+x-1];
+ }
+ for(; i<16 && i + 16*y<16*block_height; i++)
+ memcpy(&src[i*stride], &src[(i-1)*stride], 16*block_width);
+
+ for (x = 0; x < block_width; x++) {
+ s->m.mb_x= x;
+ ff_init_block_index(&s->m);
+ ff_update_block_index(&s->m);
+
+ ff_estimate_p_frame_motion(&s->m, x, y);
+ }
+ s->m.first_slice_line=0;
+ }
+
+ ff_fix_long_p_mvs(&s->m);
+ ff_fix_long_mvs(&s->m, NULL, 0, s->m.p_mv_table, s->m.f_code, CANDIDATE_MB_TYPE_INTER, 0);
+ }
+
+ 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*y<height; i++){
+ memcpy(&src[i*stride], &src_plane[(i+16*y)*src_stride], width);
+ for(x=width; x<16*block_width; x++)
+ src[i*stride+x]= src[i*stride+x-1];
+ }
+ for(; i<16 && i + 16*y<16*block_height; i++)
+ memcpy(&src[i*stride], &src[(i-1)*stride], 16*block_width);
+
+ s->m.mb_y= y;
+ for (x = 0; x < block_width; x++) {
+ uint8_t reorder_buffer[3][6][7*32];
+ int count[3][6];
+ int offset = y * 16 * stride + x * 16;
+ uint8_t *decoded= decoded_plane + offset;
+ uint8_t *ref= ref_plane + offset;
+ int score[4]={0,0,0,0}, best;
+ uint8_t temp[16*stride];
+
+ if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < 3000){ //FIXME check size
+ av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
+ return -1;
+ }
+
+ s->m.mb_x= x;
+ ff_init_block_index(&s->m);
+ ff_update_block_index(&s->m);
+
+ if(s->picture.pict_type == I_TYPE || (s->m.mb_type[x + y*s->m.mb_stride]&CANDIDATE_MB_TYPE_INTRA)){
+ for(i=0; i<6; i++){
+ init_put_bits(&s->reorder_pb[i], reorder_buffer[0][i], 7*32);
+ }
+ if(s->picture.pict_type == P_TYPE){
+ const uint8_t *vlc= svq1_block_type_vlc[SVQ1_BLOCK_INTRA];
+ put_bits(&s->reorder_pb[5], vlc[1], vlc[0]);
+ score[0]= vlc[1]*lambda;
+ }
+ score[0]+= encode_block(s, src+16*x, NULL, temp, stride, 5, 64, lambda, 1);
+ for(i=0; i<6; i++){
+ count[0][i]= put_bits_count(&s->reorder_pb[i]);
+ flush_put_bits(&s->reorder_pb[i]);
+ }
+ }else
+ score[0]= INT_MAX;
+
+ best=0;
+
+ if(s->picture.pict_type == P_TYPE){
+ const uint8_t *vlc= svq1_block_type_vlc[SVQ1_BLOCK_INTER];
+ int mx, my, pred_x, pred_y, dxy;
+ int16_t *motion_ptr;
+
+ motion_ptr= h263_pred_motion(&s->m, 0, 0, &pred_x, &pred_y);
+ if(s->m.mb_type[x + y*s->m.mb_stride]&CANDIDATE_MB_TYPE_INTER){
+ for(i=0; i<6; i++)
+ init_put_bits(&s->reorder_pb[i], reorder_buffer[1][i], 7*32);
+
+ put_bits(&s->reorder_pb[5], vlc[1], vlc[0]);
+
+ s->m.pb= s->reorder_pb[5];
+ mx= motion_ptr[0];
+ my= motion_ptr[1];
+ assert(mx>=-32 && mx<=31);
+ assert(my>=-32 && my<=31);
+ assert(pred_x>=-32 && pred_x<=31);
+ assert(pred_y>=-32 && pred_y<=31);
+ ff_h263_encode_motion(&s->m, mx - pred_x, 1);
+ ff_h263_encode_motion(&s->m, my - pred_y, 1);
+ s->reorder_pb[5]= s->m.pb;
+ score[1] += lambda*put_bits_count(&s->reorder_pb[5]);
+
+ dxy= (mx&1) + 2*(my&1);
+
+ s->dsp.put_pixels_tab[0][dxy](temp+16, ref + (mx>>1) + stride*(my>>1), stride, 16);
+
+ score[1]+= encode_block(s, src+16*x, temp+16, decoded, stride, 5, 64, lambda, 0);
+ best= score[1] <= score[0];
+
+ vlc= svq1_block_type_vlc[SVQ1_BLOCK_SKIP];
+ score[2]= s->dsp.sse[0](NULL, src+16*x, ref, stride, 16);
+ score[2]+= vlc[1]*lambda;
+ if(score[2] < score[best] && mx==0 && my==0){
+ best=2;
+ s->dsp.put_pixels_tab[0][0](decoded, ref, stride, 16);
+ for(i=0; i<6; i++){
+ count[2][i]=0;
+ }
+ put_bits(&s->pb, vlc[1], vlc[0]);
+ }
+ }
+
+ if(best==1){
+ for(i=0; i<6; i++){
+ count[1][i]= put_bits_count(&s->reorder_pb[i]);
+ flush_put_bits(&s->reorder_pb[i]);
+ }
+ }else{
+ motion_ptr[0 ] = motion_ptr[1 ]=
+ motion_ptr[2 ] = motion_ptr[3 ]=
+ motion_ptr[0+2*s->m.b8_stride] = motion_ptr[1+2*s->m.b8_stride]=
+ motion_ptr[2+2*s->m.b8_stride] = motion_ptr[3+2*s->m.b8_stride]=0;
+ }
+ }
+
+ s->rd_total += score[best];
+
+ for(i=5; i>=0; i--){
+ ff_copy_bits(&s->pb, reorder_buffer[best][i], count[best][i]);
+ }
+ if(best==0){
+ s->dsp.put_pixels_tab[0][0](decoded, temp, stride, 16);
+ }
+ }
+ s->m.first_slice_line=0;
+ }
+ return 0;
+}
+
+static int svq1_encode_init(AVCodecContext *avctx)
+{
+ SVQ1Context * const s = avctx->priv_data;
+
+ dsputil_init(&s->dsp, avctx);
+ avctx->coded_frame= (AVFrame*)&s->picture;
+
+ s->frame_width = avctx->width;
+ s->frame_height = avctx->height;
+
+ s->y_block_width = (s->frame_width + 15) / 16;
+ s->y_block_height = (s->frame_height + 15) / 16;
+
+ s->c_block_width = (s->frame_width / 4 + 15) / 16;
+ s->c_block_height = (s->frame_height / 4 + 15) / 16;
+
+ s->avctx= avctx;
+ s->m.avctx= avctx;
+ 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->mb_type = av_mallocz((s->y_block_width+1)*s->y_block_height*sizeof(int16_t));
+ s->dummy = av_mallocz((s->y_block_width+1)*s->y_block_height*sizeof(int32_t));
+ h263_encode_init(&s->m); //mv_penalty
+
+ return 0;
+}
+
+static int svq1_encode_frame(AVCodecContext *avctx, unsigned char *buf,
+ int buf_size, void *data)
+{
+ SVQ1Context * const s = avctx->priv_data;
+ AVFrame *pict = data;
+ AVFrame * const p= (AVFrame*)&s->picture;
+ AVFrame temp;
+ int i;
+
+ if(avctx->pix_fmt != PIX_FMT_YUV410P){
+ av_log(avctx, AV_LOG_ERROR, "unsupported pixel format\n");
+ return -1;
+ }
+
+ if(!s->current_picture.data[0]){
+ avctx->get_buffer(avctx, &s->current_picture);
+ avctx->get_buffer(avctx, &s->last_picture);
+ }
+
+ temp= s->current_picture;
+ s->current_picture= s->last_picture;
+ s->last_picture= temp;
+
+ init_put_bits(&s->pb, buf, buf_size);
+
+ *p = *pict;
+ p->pict_type = avctx->gop_size && avctx->frame_number % avctx->gop_size ? P_TYPE : I_TYPE;
+ p->key_frame = p->pict_type == I_TYPE;
+
+ svq1_write_header(s, p->pict_type);
+ for(i=0; i<3; i++){
+ if(svq1_encode_plane(s, i,
+ s->picture.data[i], s->last_picture.data[i], s->current_picture.data[i],
+ s->frame_width / (i?4:1), s->frame_height / (i?4:1),
+ s->picture.linesize[i], s->current_picture.linesize[i]) < 0)
+ return -1;
+ }
+
+// align_put_bits(&s->pb);
+ while(put_bits_count(&s->pb) & 31)
+ put_bits(&s->pb, 1, 0);
+
+ flush_put_bits(&s->pb);
+
+ return (put_bits_count(&s->pb) / 8);
+}
+
+static int svq1_encode_end(AVCodecContext *avctx)
+{
+ SVQ1Context * const s = avctx->priv_data;
+ int i;
+
+ av_log(avctx, AV_LOG_DEBUG, "RD: %f\n", s->rd_total/(double)(avctx->width*avctx->height*avctx->frame_number));
+
+ av_freep(&s->m.me.scratchpad);
+ av_freep(&s->m.me.map);
+ av_freep(&s->m.me.score_map);
+ av_freep(&s->mb_type);
+ av_freep(&s->dummy);
+
+ for(i=0; i<3; i++){
+ av_freep(&s->motion_val8[i]);
+ av_freep(&s->motion_val16[i]);
+ }
+
+ return 0;
+}
+
+#endif //CONFIG_ENCODERS
+
+#ifdef CONFIG_DECODERS
+AVCodec svq1_decoder = {
+ "svq1",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_SVQ1,
+ sizeof(MpegEncContext),
+ svq1_decode_init,
+ NULL,
+ svq1_decode_end,
+ svq1_decode_frame,
+ CODEC_CAP_DR1,
+ .flush= ff_mpeg_flush,
+ .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV410P, -1},
+};
+#endif
+
+#ifdef CONFIG_ENCODERS
+
+AVCodec svq1_encoder = {
+ "svq1",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_SVQ1,
+ sizeof(SVQ1Context),
+ svq1_encode_init,
+ svq1_encode_frame,
+ svq1_encode_end,
+ .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV410P, -1},
+};
+
+#endif //CONFIG_ENCODERS
diff --git a/src/libffmpeg/libavcodec/svq1_cb.h b/contrib/ffmpeg/libavcodec/svq1_cb.h
index a0748bd44..a0748bd44 100644
--- a/src/libffmpeg/libavcodec/svq1_cb.h
+++ b/contrib/ffmpeg/libavcodec/svq1_cb.h
diff --git a/src/libffmpeg/libavcodec/svq1_vlc.h b/contrib/ffmpeg/libavcodec/svq1_vlc.h
index 56463700f..56463700f 100644
--- a/src/libffmpeg/libavcodec/svq1_vlc.h
+++ b/contrib/ffmpeg/libavcodec/svq1_vlc.h
diff --git a/contrib/ffmpeg/libavcodec/svq3.c b/contrib/ffmpeg/libavcodec/svq3.c
new file mode 100644
index 000000000..db601010b
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/svq3.c
@@ -0,0 +1,1015 @@
+/*
+ * Copyright (c) 2003 The FFmpeg Project.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ *
+ * How to use this decoder:
+ * SVQ3 data is transported within Apple Quicktime files. Quicktime files
+ * have stsd atoms to describe media trak properties. A stsd atom for a
+ * video trak contains 1 or more ImageDescription atoms. These atoms begin
+ * with the 4-byte length of the atom followed by the codec fourcc. Some
+ * decoders need information in this atom to operate correctly. Such
+ * is the case with SVQ3. In order to get the best use out of this decoder,
+ * the calling app must make the SVQ3 ImageDescription atom available
+ * via the AVCodecContext's extradata[_size] field:
+ *
+ * AVCodecContext.extradata = pointer to ImageDescription, first characters
+ * are expected to be 'S', 'V', 'Q', and '3', NOT the 4-byte atom length
+ * AVCodecContext.extradata_size = size of ImageDescription atom memory
+ * buffer (which will be the same as the ImageDescription atom size field
+ * from the QT file, minus 4 bytes since the length is missing)
+ *
+ * You will know you have these parameters passed correctly when the decoder
+ * correctly decodes this file:
+ * ftp://ftp.mplayerhq.hu/MPlayer/samples/V-codecs/SVQ3/Vertical400kbit.sorenson3.mov
+ *
+ */
+
+/**
+ * @file svq3.c
+ * svq3 decoder.
+ */
+
+#define FULLPEL_MODE 1
+#define HALFPEL_MODE 2
+#define THIRDPEL_MODE 3
+#define PREDICT_MODE 4
+
+/* dual scan (from some older h264 draft)
+ o-->o-->o o
+ | /|
+ o o o / o
+ | / | |/ |
+ o o o o
+ /
+ o-->o-->o-->o
+*/
+static const uint8_t svq3_scan[16]={
+ 0+0*4, 1+0*4, 2+0*4, 2+1*4,
+ 2+2*4, 3+0*4, 3+1*4, 3+2*4,
+ 0+1*4, 0+2*4, 1+1*4, 1+2*4,
+ 0+3*4, 1+3*4, 2+3*4, 3+3*4,
+};
+
+static const uint8_t svq3_pred_0[25][2] = {
+ { 0, 0 },
+ { 1, 0 }, { 0, 1 },
+ { 0, 2 }, { 1, 1 }, { 2, 0 },
+ { 3, 0 }, { 2, 1 }, { 1, 2 }, { 0, 3 },
+ { 0, 4 }, { 1, 3 }, { 2, 2 }, { 3, 1 }, { 4, 0 },
+ { 4, 1 }, { 3, 2 }, { 2, 3 }, { 1, 4 },
+ { 2, 4 }, { 3, 3 }, { 4, 2 },
+ { 4, 3 }, { 3, 4 },
+ { 4, 4 }
+};
+
+static const int8_t svq3_pred_1[6][6][5] = {
+ { { 2,-1,-1,-1,-1 }, { 2, 1,-1,-1,-1 }, { 1, 2,-1,-1,-1 },
+ { 2, 1,-1,-1,-1 }, { 1, 2,-1,-1,-1 }, { 1, 2,-1,-1,-1 } },
+ { { 0, 2,-1,-1,-1 }, { 0, 2, 1, 4, 3 }, { 0, 1, 2, 4, 3 },
+ { 0, 2, 1, 4, 3 }, { 2, 0, 1, 3, 4 }, { 0, 4, 2, 1, 3 } },
+ { { 2, 0,-1,-1,-1 }, { 2, 1, 0, 4, 3 }, { 1, 2, 4, 0, 3 },
+ { 2, 1, 0, 4, 3 }, { 2, 1, 4, 3, 0 }, { 1, 2, 4, 0, 3 } },
+ { { 2, 0,-1,-1,-1 }, { 2, 0, 1, 4, 3 }, { 1, 2, 0, 4, 3 },
+ { 2, 1, 0, 4, 3 }, { 2, 1, 3, 4, 0 }, { 2, 4, 1, 0, 3 } },
+ { { 0, 2,-1,-1,-1 }, { 0, 2, 1, 3, 4 }, { 1, 2, 3, 0, 4 },
+ { 2, 0, 1, 3, 4 }, { 2, 1, 3, 0, 4 }, { 2, 0, 4, 3, 1 } },
+ { { 0, 2,-1,-1,-1 }, { 0, 2, 4, 1, 3 }, { 1, 4, 2, 0, 3 },
+ { 4, 2, 0, 1, 3 }, { 2, 0, 1, 4, 3 }, { 4, 2, 1, 0, 3 } },
+};
+
+static const struct { uint8_t run; uint8_t level; } svq3_dct_tables[2][16] = {
+ { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 2, 1 }, { 0, 2 }, { 3, 1 }, { 4, 1 }, { 5, 1 },
+ { 0, 3 }, { 1, 2 }, { 2, 2 }, { 6, 1 }, { 7, 1 }, { 8, 1 }, { 9, 1 }, { 0, 4 } },
+ { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 0, 2 }, { 2, 1 }, { 0, 3 }, { 0, 4 }, { 0, 5 },
+ { 3, 1 }, { 4, 1 }, { 1, 2 }, { 1, 3 }, { 0, 6 }, { 0, 7 }, { 0, 8 }, { 0, 9 } }
+};
+
+static const uint32_t svq3_dequant_coeff[32] = {
+ 3881, 4351, 4890, 5481, 6154, 6914, 7761, 8718,
+ 9781, 10987, 12339, 13828, 15523, 17435, 19561, 21873,
+ 24552, 27656, 30847, 34870, 38807, 43747, 49103, 54683,
+ 61694, 68745, 77615, 89113,100253,109366,126635,141533
+};
+
+
+static void svq3_luma_dc_dequant_idct_c(DCTELEM *block, int qp){
+ const int qmul= svq3_dequant_coeff[qp];
+#define stride 16
+ int i;
+ int temp[16];
+ static const int x_offset[4]={0, 1*stride, 4* stride, 5*stride};
+ static const int y_offset[4]={0, 2*stride, 8* stride, 10*stride};
+
+ for(i=0; i<4; i++){
+ const int offset= y_offset[i];
+ const int z0= 13*(block[offset+stride*0] + block[offset+stride*4]);
+ const int z1= 13*(block[offset+stride*0] - block[offset+stride*4]);
+ const int z2= 7* block[offset+stride*1] - 17*block[offset+stride*5];
+ const int z3= 17* block[offset+stride*1] + 7*block[offset+stride*5];
+
+ temp[4*i+0]= z0+z3;
+ temp[4*i+1]= z1+z2;
+ temp[4*i+2]= z1-z2;
+ temp[4*i+3]= z0-z3;
+ }
+
+ for(i=0; i<4; i++){
+ const int offset= x_offset[i];
+ const int z0= 13*(temp[4*0+i] + temp[4*2+i]);
+ const int z1= 13*(temp[4*0+i] - temp[4*2+i]);
+ const int z2= 7* temp[4*1+i] - 17*temp[4*3+i];
+ const int z3= 17* temp[4*1+i] + 7*temp[4*3+i];
+
+ block[stride*0 +offset]= ((z0 + z3)*qmul + 0x80000)>>20;
+ block[stride*2 +offset]= ((z1 + z2)*qmul + 0x80000)>>20;
+ block[stride*8 +offset]= ((z1 - z2)*qmul + 0x80000)>>20;
+ block[stride*10+offset]= ((z0 - z3)*qmul + 0x80000)>>20;
+ }
+}
+#undef stride
+
+static void svq3_add_idct_c (uint8_t *dst, DCTELEM *block, int stride, int qp, int dc){
+ const int qmul= svq3_dequant_coeff[qp];
+ int i;
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+
+ if (dc) {
+ dc = 13*13*((dc == 1) ? 1538*block[0] : ((qmul*(block[0] >> 3)) / 2));
+ block[0] = 0;
+ }
+
+ for (i=0; i < 4; i++) {
+ const int z0= 13*(block[0 + 4*i] + block[2 + 4*i]);
+ const int z1= 13*(block[0 + 4*i] - block[2 + 4*i]);
+ const int z2= 7* block[1 + 4*i] - 17*block[3 + 4*i];
+ const int z3= 17* block[1 + 4*i] + 7*block[3 + 4*i];
+
+ block[0 + 4*i]= z0 + z3;
+ block[1 + 4*i]= z1 + z2;
+ block[2 + 4*i]= z1 - z2;
+ block[3 + 4*i]= z0 - z3;
+ }
+
+ for (i=0; i < 4; i++) {
+ const int z0= 13*(block[i + 4*0] + block[i + 4*2]);
+ const int z1= 13*(block[i + 4*0] - block[i + 4*2]);
+ const int z2= 7* block[i + 4*1] - 17*block[i + 4*3];
+ const int z3= 17* block[i + 4*1] + 7*block[i + 4*3];
+ const int rr= (dc + 0x80000);
+
+ dst[i + stride*0]= cm[ dst[i + stride*0] + (((z0 + z3)*qmul + rr) >> 20) ];
+ dst[i + stride*1]= cm[ dst[i + stride*1] + (((z1 + z2)*qmul + rr) >> 20) ];
+ dst[i + stride*2]= cm[ dst[i + stride*2] + (((z1 - z2)*qmul + rr) >> 20) ];
+ dst[i + stride*3]= cm[ dst[i + stride*3] + (((z0 - z3)*qmul + rr) >> 20) ];
+ }
+}
+
+static void pred4x4_down_left_svq3_c(uint8_t *src, uint8_t *topright, int stride){
+ LOAD_TOP_EDGE
+ LOAD_LEFT_EDGE
+ const __attribute__((unused)) int unu0= t0;
+ const __attribute__((unused)) int unu1= l0;
+
+ src[0+0*stride]=(l1 + t1)>>1;
+ src[1+0*stride]=
+ src[0+1*stride]=(l2 + t2)>>1;
+ src[2+0*stride]=
+ src[1+1*stride]=
+ src[0+2*stride]=
+ src[3+0*stride]=
+ src[2+1*stride]=
+ src[1+2*stride]=
+ src[0+3*stride]=
+ src[3+1*stride]=
+ src[2+2*stride]=
+ src[1+3*stride]=
+ src[3+2*stride]=
+ src[2+3*stride]=
+ src[3+3*stride]=(l3 + t3)>>1;
+}
+
+static void pred16x16_plane_svq3_c(uint8_t *src, int stride){
+ pred16x16_plane_compat_c(src, stride, 1);
+}
+
+static inline int svq3_decode_block (GetBitContext *gb, DCTELEM *block,
+ int index, const int type) {
+
+ static const uint8_t *const scan_patterns[4] =
+ { luma_dc_zigzag_scan, zigzag_scan, svq3_scan, chroma_dc_scan };
+
+ int run, level, sign, vlc, limit;
+ const int intra = (3 * type) >> 2;
+ const uint8_t *const scan = scan_patterns[type];
+
+ for (limit=(16 >> intra); index < 16; index=limit, limit+=8) {
+ for (; (vlc = svq3_get_ue_golomb (gb)) != 0; index++) {
+
+ if (vlc == INVALID_VLC)
+ return -1;
+
+ sign = (vlc & 0x1) - 1;
+ vlc = (vlc + 1) >> 1;
+
+ if (type == 3) {
+ if (vlc < 3) {
+ run = 0;
+ level = vlc;
+ } else if (vlc < 4) {
+ run = 1;
+ level = 1;
+ } else {
+ run = (vlc & 0x3);
+ level = ((vlc + 9) >> 2) - run;
+ }
+ } else {
+ if (vlc < 16) {
+ run = svq3_dct_tables[intra][vlc].run;
+ level = svq3_dct_tables[intra][vlc].level;
+ } else if (intra) {
+ run = (vlc & 0x7);
+ level = (vlc >> 3) + ((run == 0) ? 8 : ((run < 2) ? 2 : ((run < 5) ? 0 : -1)));
+ } else {
+ run = (vlc & 0xF);
+ level = (vlc >> 4) + ((run == 0) ? 4 : ((run < 3) ? 2 : ((run < 10) ? 1 : 0)));
+ }
+ }
+
+ if ((index += run) >= limit)
+ return -1;
+
+ block[scan[index]] = (level ^ sign) - sign;
+ }
+
+ if (type != 2) {
+ break;
+ }
+ }
+
+ return 0;
+}
+
+static inline void svq3_mc_dir_part (MpegEncContext *s,
+ int x, int y, int width, int height,
+ int mx, int my, int dxy,
+ int thirdpel, int dir, int avg) {
+
+ const Picture *pic = (dir == 0) ? &s->last_picture : &s->next_picture;
+ uint8_t *src, *dest;
+ int i, emu = 0;
+ int blocksize= 2 - (width>>3); //16->0, 8->1, 4->2
+
+ mx += x;
+ my += y;
+
+ if (mx < 0 || mx >= (s->h_edge_pos - width - 1) ||
+ my < 0 || my >= (s->v_edge_pos - height - 1)) {
+
+ if ((s->flags & CODEC_FLAG_EMU_EDGE)) {
+ emu = 1;
+ }
+
+ mx = av_clip (mx, -16, (s->h_edge_pos - width + 15));
+ my = av_clip (my, -16, (s->v_edge_pos - height + 15));
+ }
+
+ /* form component predictions */
+ dest = s->current_picture.data[0] + x + y*s->linesize;
+ src = pic->data[0] + mx + my*s->linesize;
+
+ if (emu) {
+ ff_emulated_edge_mc (s->edge_emu_buffer, src, s->linesize, (width + 1), (height + 1),
+ mx, my, s->h_edge_pos, s->v_edge_pos);
+ src = s->edge_emu_buffer;
+ }
+ if(thirdpel)
+ (avg ? s->dsp.avg_tpel_pixels_tab : s->dsp.put_tpel_pixels_tab)[dxy](dest, src, s->linesize, width, height);
+ else
+ (avg ? s->dsp.avg_pixels_tab : s->dsp.put_pixels_tab)[blocksize][dxy](dest, src, s->linesize, height);
+
+ if (!(s->flags & CODEC_FLAG_GRAY)) {
+ mx = (mx + (mx < (int) x)) >> 1;
+ my = (my + (my < (int) y)) >> 1;
+ width = (width >> 1);
+ height = (height >> 1);
+ blocksize++;
+
+ for (i=1; i < 3; i++) {
+ dest = s->current_picture.data[i] + (x >> 1) + (y >> 1)*s->uvlinesize;
+ src = pic->data[i] + mx + my*s->uvlinesize;
+
+ if (emu) {
+ ff_emulated_edge_mc (s->edge_emu_buffer, src, s->uvlinesize, (width + 1), (height + 1),
+ mx, my, (s->h_edge_pos >> 1), (s->v_edge_pos >> 1));
+ src = s->edge_emu_buffer;
+ }
+ if(thirdpel)
+ (avg ? s->dsp.avg_tpel_pixels_tab : s->dsp.put_tpel_pixels_tab)[dxy](dest, src, s->uvlinesize, width, height);
+ else
+ (avg ? s->dsp.avg_pixels_tab : s->dsp.put_pixels_tab)[blocksize][dxy](dest, src, s->uvlinesize, height);
+ }
+ }
+}
+
+static inline int svq3_mc_dir (H264Context *h, int size, int mode, int dir, int avg) {
+
+ int i, j, k, mx, my, dx, dy, x, y;
+ MpegEncContext *const s = (MpegEncContext *) h;
+ const int part_width = ((size & 5) == 4) ? 4 : 16 >> (size & 1);
+ const int part_height = 16 >> ((unsigned) (size + 1) / 3);
+ const int extra_width = (mode == PREDICT_MODE) ? -16*6 : 0;
+ const int h_edge_pos = 6*(s->h_edge_pos - part_width ) - extra_width;
+ const int v_edge_pos = 6*(s->v_edge_pos - part_height) - extra_width;
+
+ for (i=0; i < 16; i+=part_height) {
+ for (j=0; j < 16; j+=part_width) {
+ const int b_xy = (4*s->mb_x+(j>>2)) + (4*s->mb_y+(i>>2))*h->b_stride;
+ int dxy;
+ x = 16*s->mb_x + j;
+ y = 16*s->mb_y + i;
+ k = ((j>>2)&1) + ((i>>1)&2) + ((j>>1)&4) + (i&8);
+
+ if (mode != PREDICT_MODE) {
+ pred_motion (h, k, (part_width >> 2), dir, 1, &mx, &my);
+ } else {
+ mx = s->next_picture.motion_val[0][b_xy][0]<<1;
+ my = s->next_picture.motion_val[0][b_xy][1]<<1;
+
+ if (dir == 0) {
+ mx = ((mx * h->frame_num_offset) / h->prev_frame_num_offset + 1)>>1;
+ my = ((my * h->frame_num_offset) / h->prev_frame_num_offset + 1)>>1;
+ } else {
+ mx = ((mx * (h->frame_num_offset - h->prev_frame_num_offset)) / h->prev_frame_num_offset + 1)>>1;
+ my = ((my * (h->frame_num_offset - h->prev_frame_num_offset)) / h->prev_frame_num_offset + 1)>>1;
+ }
+ }
+
+ /* clip motion vector prediction to frame border */
+ mx = av_clip (mx, extra_width - 6*x, h_edge_pos - 6*x);
+ my = av_clip (my, extra_width - 6*y, v_edge_pos - 6*y);
+
+ /* get (optional) motion vector differential */
+ if (mode == PREDICT_MODE) {
+ dx = dy = 0;
+ } else {
+ dy = svq3_get_se_golomb (&s->gb);
+ dx = svq3_get_se_golomb (&s->gb);
+
+ if (dx == INVALID_VLC || dy == INVALID_VLC) {
+ av_log(h->s.avctx, AV_LOG_ERROR, "invalid MV vlc\n");
+ return -1;
+ }
+ }
+
+ /* compute motion vector */
+ if (mode == THIRDPEL_MODE) {
+ int fx, fy;
+ mx = ((mx + 1)>>1) + dx;
+ my = ((my + 1)>>1) + dy;
+ fx= ((unsigned)(mx + 0x3000))/3 - 0x1000;
+ fy= ((unsigned)(my + 0x3000))/3 - 0x1000;
+ dxy= (mx - 3*fx) + 4*(my - 3*fy);
+
+ svq3_mc_dir_part (s, x, y, part_width, part_height, fx, fy, dxy, 1, dir, avg);
+ mx += mx;
+ my += my;
+ } else if (mode == HALFPEL_MODE || mode == PREDICT_MODE) {
+ mx = ((unsigned)(mx + 1 + 0x3000))/3 + dx - 0x1000;
+ my = ((unsigned)(my + 1 + 0x3000))/3 + dy - 0x1000;
+ dxy= (mx&1) + 2*(my&1);
+
+ svq3_mc_dir_part (s, x, y, part_width, part_height, mx>>1, my>>1, dxy, 0, dir, avg);
+ mx *= 3;
+ my *= 3;
+ } else {
+ mx = ((unsigned)(mx + 3 + 0x6000))/6 + dx - 0x1000;
+ my = ((unsigned)(my + 3 + 0x6000))/6 + dy - 0x1000;
+
+ svq3_mc_dir_part (s, x, y, part_width, part_height, mx, my, 0, 0, dir, avg);
+ mx *= 6;
+ my *= 6;
+ }
+
+ /* update mv_cache */
+ if (mode != PREDICT_MODE) {
+ int32_t mv = pack16to32(mx,my);
+
+ if (part_height == 8 && i < 8) {
+ *(int32_t *) h->mv_cache[dir][scan8[k] + 1*8] = mv;
+
+ if (part_width == 8 && j < 8) {
+ *(int32_t *) h->mv_cache[dir][scan8[k] + 1 + 1*8] = mv;
+ }
+ }
+ if (part_width == 8 && j < 8) {
+ *(int32_t *) h->mv_cache[dir][scan8[k] + 1] = mv;
+ }
+ if (part_width == 4 || part_height == 4) {
+ *(int32_t *) h->mv_cache[dir][scan8[k]] = mv;
+ }
+ }
+
+ /* write back motion vectors */
+ fill_rectangle(s->current_picture.motion_val[dir][b_xy], part_width>>2, part_height>>2, h->b_stride, pack16to32(mx,my), 4);
+ }
+ }
+
+ return 0;
+}
+
+static int svq3_decode_mb (H264Context *h, unsigned int mb_type) {
+ int i, j, k, m, dir, mode;
+ int cbp = 0;
+ uint32_t vlc;
+ int8_t *top, *left;
+ MpegEncContext *const s = (MpegEncContext *) h;
+ const int mb_xy = s->mb_x + s->mb_y*s->mb_stride;
+ const int b_xy = 4*s->mb_x + 4*s->mb_y*h->b_stride;
+
+ h->top_samples_available = (s->mb_y == 0) ? 0x33FF : 0xFFFF;
+ h->left_samples_available = (s->mb_x == 0) ? 0x5F5F : 0xFFFF;
+ h->topright_samples_available = 0xFFFF;
+
+ if (mb_type == 0) { /* SKIP */
+ if (s->pict_type == P_TYPE || s->next_picture.mb_type[mb_xy] == -1) {
+ svq3_mc_dir_part (s, 16*s->mb_x, 16*s->mb_y, 16, 16, 0, 0, 0, 0, 0, 0);
+
+ if (s->pict_type == B_TYPE) {
+ svq3_mc_dir_part (s, 16*s->mb_x, 16*s->mb_y, 16, 16, 0, 0, 0, 0, 1, 1);
+ }
+
+ mb_type = MB_TYPE_SKIP;
+ } else {
+ mb_type= FFMIN(s->next_picture.mb_type[mb_xy], 6);
+ if(svq3_mc_dir (h, mb_type, PREDICT_MODE, 0, 0) < 0)
+ return -1;
+ if(svq3_mc_dir (h, mb_type, PREDICT_MODE, 1, 1) < 0)
+ return -1;
+
+ mb_type = MB_TYPE_16x16;
+ }
+ } else if (mb_type < 8) { /* INTER */
+ if (h->thirdpel_flag && h->halfpel_flag == !get_bits (&s->gb, 1)) {
+ mode = THIRDPEL_MODE;
+ } else if (h->halfpel_flag && h->thirdpel_flag == !get_bits (&s->gb, 1)) {
+ mode = HALFPEL_MODE;
+ } else {
+ mode = FULLPEL_MODE;
+ }
+
+ /* fill caches */
+ /* note ref_cache should contain here:
+ ????????
+ ???11111
+ N??11111
+ N??11111
+ N??11111
+ N
+ */
+
+ for (m=0; m < 2; m++) {
+ if (s->mb_x > 0 && h->intra4x4_pred_mode[mb_xy - 1][0] != -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];
+ }
+ } else {
+ for (i=0; i < 4; i++) {
+ *(uint32_t *) h->mv_cache[m][scan8[0] - 1 + i*8] = 0;
+ }
+ }
+ 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);
+
+ 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;
+ }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;
+ }else
+ h->ref_cache[m][scan8[0] - 1 - 1*8] = PART_NOT_AVAILABLE;
+ }else
+ memset (&h->ref_cache[m][scan8[0] - 1*8 - 1], PART_NOT_AVAILABLE, 8);
+
+ if (s->pict_type != B_TYPE)
+ break;
+ }
+
+ /* decode motion vector(s) and form prediction(s) */
+ if (s->pict_type == P_TYPE) {
+ if(svq3_mc_dir (h, (mb_type - 1), mode, 0, 0) < 0)
+ return -1;
+ } else { /* B_TYPE */
+ if (mb_type != 2) {
+ if(svq3_mc_dir (h, 0, mode, 0, 0) < 0)
+ return -1;
+ } else {
+ for (i=0; i < 4; i++) {
+ memset (s->current_picture.motion_val[0][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t));
+ }
+ }
+ if (mb_type != 1) {
+ if(svq3_mc_dir (h, 0, mode, 1, (mb_type == 3)) < 0)
+ return -1;
+ } else {
+ for (i=0; i < 4; i++) {
+ memset (s->current_picture.motion_val[1][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t));
+ }
+ }
+ }
+
+ mb_type = MB_TYPE_16x16;
+ } else if (mb_type == 8 || mb_type == 33) { /* INTRA4x4 */
+ memset (h->intra4x4_pred_mode_cache, -1, 8*5*sizeof(int8_t));
+
+ 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];
+ }
+ 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];
+
+ if (h->intra4x4_pred_mode_cache[4+8*0] == -1) {
+ h->top_samples_available = 0x33FF;
+ }
+ }
+
+ /* decode prediction codes for luma blocks */
+ for (i=0; i < 16; i+=2) {
+ vlc = svq3_get_ue_golomb (&s->gb);
+
+ if (vlc >= 25){
+ av_log(h->s.avctx, AV_LOG_ERROR, "luma prediction:%d\n", vlc);
+ return -1;
+ }
+
+ left = &h->intra4x4_pred_mode_cache[scan8[i] - 1];
+ top = &h->intra4x4_pred_mode_cache[scan8[i] - 8];
+
+ left[1] = svq3_pred_1[top[0] + 1][left[0] + 1][svq3_pred_0[vlc][0]];
+ left[2] = svq3_pred_1[top[1] + 1][left[1] + 1][svq3_pred_0[vlc][1]];
+
+ if (left[1] == -1 || left[2] == -1){
+ av_log(h->s.avctx, AV_LOG_ERROR, "weird prediction\n");
+ return -1;
+ }
+ }
+ } else { /* mb_type == 33, DC_128_PRED block type */
+ for (i=0; i < 4; i++) {
+ memset (&h->intra4x4_pred_mode_cache[scan8[0] + 8*i], DC_PRED, 4);
+ }
+ }
+
+ write_back_intra_pred_mode (h);
+
+ if (mb_type == 8) {
+ 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;
+ } else {
+ for (i=0; i < 4; i++) {
+ memset (&h->intra4x4_pred_mode_cache[scan8[0] + 8*i], DC_128_PRED, 4);
+ }
+
+ h->top_samples_available = 0x33FF;
+ h->left_samples_available = 0x5F5F;
+ }
+
+ mb_type = MB_TYPE_INTRA4x4;
+ } else { /* INTRA16x16 */
+ 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){
+ av_log(h->s.avctx, AV_LOG_ERROR, "check_intra_pred_mode = -1\n");
+ return -1;
+ }
+
+ cbp = i_mb_type_info[mb_type - 8].cbp;
+ mb_type = MB_TYPE_INTRA16x16;
+ }
+
+ if (!IS_INTER(mb_type) && s->pict_type != I_TYPE) {
+ for (i=0; i < 4; i++) {
+ memset (s->current_picture.motion_val[0][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t));
+ }
+ if (s->pict_type == B_TYPE) {
+ for (i=0; i < 4; i++) {
+ memset (s->current_picture.motion_val[1][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t));
+ }
+ }
+ }
+ if (!IS_INTRA4x4(mb_type)) {
+ memset (h->intra4x4_pred_mode[mb_xy], DC_PRED, 8);
+ }
+ if (!IS_SKIP(mb_type) || s->pict_type == B_TYPE) {
+ memset (h->non_zero_count_cache + 8, 0, 4*9*sizeof(uint8_t));
+ s->dsp.clear_blocks(h->mb);
+ }
+
+ if (!IS_INTRA16x16(mb_type) && (!IS_SKIP(mb_type) || s->pict_type == B_TYPE)) {
+ if ((vlc = svq3_get_ue_golomb (&s->gb)) >= 48){
+ av_log(h->s.avctx, AV_LOG_ERROR, "cbp_vlc=%d\n", vlc);
+ return -1;
+ }
+
+ cbp = IS_INTRA(mb_type) ? golomb_to_intra4x4_cbp[vlc] : golomb_to_inter_cbp[vlc];
+ }
+ if (IS_INTRA16x16(mb_type) || (s->pict_type != I_TYPE && s->adaptive_quant && cbp)) {
+ s->qscale += svq3_get_se_golomb (&s->gb);
+
+ if (s->qscale > 31){
+ av_log(h->s.avctx, AV_LOG_ERROR, "qscale:%d\n", s->qscale);
+ return -1;
+ }
+ }
+ if (IS_INTRA16x16(mb_type)) {
+ if (svq3_decode_block (&s->gb, h->mb, 0, 0)){
+ av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding intra luma dc\n");
+ return -1;
+ }
+ }
+
+ if (cbp) {
+ const int index = IS_INTRA16x16(mb_type) ? 1 : 0;
+ const int type = ((s->qscale < 24 && IS_INTRA4x4(mb_type)) ? 2 : 1);
+
+ for (i=0; i < 4; i++) {
+ if ((cbp & (1 << i))) {
+ for (j=0; j < 4; j++) {
+ k = index ? ((j&1) + 2*(i&1) + 2*(j&2) + 4*(i&2)) : (4*i + j);
+ h->non_zero_count_cache[ scan8[k] ] = 1;
+
+ if (svq3_decode_block (&s->gb, &h->mb[16*k], index, type)){
+ av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding block\n");
+ return -1;
+ }
+ }
+ }
+ }
+
+ if ((cbp & 0x30)) {
+ for (i=0; i < 2; ++i) {
+ if (svq3_decode_block (&s->gb, &h->mb[16*(16 + 4*i)], 0, 3)){
+ av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding chroma dc block\n");
+ return -1;
+ }
+ }
+
+ if ((cbp & 0x20)) {
+ for (i=0; i < 8; i++) {
+ h->non_zero_count_cache[ scan8[16+i] ] = 1;
+
+ if (svq3_decode_block (&s->gb, &h->mb[16*(16 + i)], 1, 1)){
+ av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding chroma ac block\n");
+ return -1;
+ }
+ }
+ }
+ }
+ }
+
+ 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);
+ }
+
+ return 0;
+}
+
+static int svq3_decode_slice_header (H264Context *h) {
+ MpegEncContext *const s = (MpegEncContext *) h;
+ const int mb_xy = s->mb_x + s->mb_y*s->mb_stride;
+ int i, header;
+
+ header = get_bits (&s->gb, 8);
+
+ if (((header & 0x9F) != 1 && (header & 0x9F) != 2) || (header & 0x60) == 0) {
+ /* TODO: what? */
+ av_log(h->s.avctx, AV_LOG_ERROR, "unsupported slice header (%02X)\n", header);
+ return -1;
+ } else {
+ int length = (header >> 5) & 3;
+
+ h->next_slice_index = get_bits_count(&s->gb) + 8*show_bits (&s->gb, 8*length) + 8*length;
+
+ if (h->next_slice_index > s->gb.size_in_bits){
+ av_log(h->s.avctx, AV_LOG_ERROR, "slice after bitstream end\n");
+ return -1;
+ }
+
+ s->gb.size_in_bits = h->next_slice_index - 8*(length - 1);
+ skip_bits(&s->gb, 8);
+
+ if (length > 0) {
+ memcpy ((uint8_t *) &s->gb.buffer[get_bits_count(&s->gb) >> 3],
+ &s->gb.buffer[s->gb.size_in_bits >> 3], (length - 1));
+ }
+ }
+
+ if ((i = svq3_get_ue_golomb (&s->gb)) == INVALID_VLC || i >= 3){
+ av_log(h->s.avctx, AV_LOG_ERROR, "illegal slice type %d \n", i);
+ return -1;
+ }
+
+ h->slice_type = golomb_to_pict_type[i];
+
+ if ((header & 0x9F) == 2) {
+ i = (s->mb_num < 64) ? 6 : (1 + av_log2 (s->mb_num - 1));
+ s->mb_skip_run = get_bits (&s->gb, i) - (s->mb_x + (s->mb_y * s->mb_width));
+ } else {
+ get_bits1 (&s->gb);
+ s->mb_skip_run = 0;
+ }
+
+ h->slice_num = get_bits (&s->gb, 8);
+ s->qscale = get_bits (&s->gb, 5);
+ s->adaptive_quant = get_bits1 (&s->gb);
+
+ /* unknown fields */
+ get_bits1 (&s->gb);
+
+ if (h->unknown_svq3_flag) {
+ get_bits1 (&s->gb);
+ }
+
+ get_bits1 (&s->gb);
+ get_bits (&s->gb, 2);
+
+ while (get_bits1 (&s->gb)) {
+ get_bits (&s->gb, 8);
+ }
+
+ /* 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);
+ }
+ 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));
+
+ if (s->mb_x > 0) {
+ h->intra4x4_pred_mode[mb_xy - s->mb_stride - 1][3] = -1;
+ }
+ }
+
+ return 0;
+}
+
+static int svq3_decode_frame (AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size) {
+ MpegEncContext *const s = avctx->priv_data;
+ H264Context *const h = avctx->priv_data;
+ int m, mb_type;
+ unsigned char *extradata;
+ unsigned int size;
+
+ s->flags = avctx->flags;
+ s->flags2 = avctx->flags2;
+ s->unrestricted_mv = 1;
+
+ if (!s->context_initialized) {
+ s->width = avctx->width;
+ s->height = avctx->height;
+ h->pred4x4[DIAG_DOWN_LEFT_PRED] = pred4x4_down_left_svq3_c;
+ h->pred16x16[PLANE_PRED8x8] = pred16x16_plane_svq3_c;
+ h->halfpel_flag = 1;
+ h->thirdpel_flag = 1;
+ h->unknown_svq3_flag = 0;
+ h->chroma_qp = 4;
+
+ if (MPV_common_init (s) < 0)
+ return -1;
+
+ h->b_stride = 4*s->mb_width;
+
+ alloc_tables (h);
+
+ /* prowl for the "SEQH" marker in the extradata */
+ extradata = (unsigned char *)avctx->extradata;
+ for (m = 0; m < avctx->extradata_size; m++) {
+ if (!memcmp (extradata, "SEQH", 4))
+ break;
+ extradata++;
+ }
+
+ /* if a match was found, parse the extra data */
+ if (extradata && !memcmp (extradata, "SEQH", 4)) {
+
+ GetBitContext gb;
+
+ size = AV_RB32(&extradata[4]);
+ init_get_bits (&gb, extradata + 8, size*8);
+
+ /* 'frame size code' and optional 'width, height' */
+ if (get_bits (&gb, 3) == 7) {
+ get_bits (&gb, 12);
+ get_bits (&gb, 12);
+ }
+
+ h->halfpel_flag = get_bits1 (&gb);
+ h->thirdpel_flag = get_bits1 (&gb);
+
+ /* unknown fields */
+ get_bits1 (&gb);
+ get_bits1 (&gb);
+ get_bits1 (&gb);
+ get_bits1 (&gb);
+
+ s->low_delay = get_bits1 (&gb);
+
+ /* unknown field */
+ get_bits1 (&gb);
+
+ while (get_bits1 (&gb)) {
+ get_bits (&gb, 8);
+ }
+
+ h->unknown_svq3_flag = get_bits1 (&gb);
+ avctx->has_b_frames = !s->low_delay;
+ }
+ }
+
+ /* special case for last picture */
+ if (buf_size == 0) {
+ if (s->next_picture_ptr && !s->low_delay) {
+ *(AVFrame *) data = *(AVFrame *) &s->next_picture;
+ *data_size = sizeof(AVFrame);
+ }
+ return 0;
+ }
+
+ init_get_bits (&s->gb, buf, 8*buf_size);
+
+ s->mb_x = s->mb_y = 0;
+
+ if (svq3_decode_slice_header (h))
+ return -1;
+
+ s->pict_type = h->slice_type;
+ s->picture_number = h->slice_num;
+
+ if(avctx->debug&FF_DEBUG_PICT_INFO){
+ av_log(h->s.avctx, AV_LOG_DEBUG, "%c hpel:%d, tpel:%d aqp:%d qp:%d\n",
+ av_get_pict_type_char(s->pict_type), h->halfpel_flag, h->thirdpel_flag,
+ s->adaptive_quant, s->qscale
+ );
+ }
+
+ /* for hurry_up==5 */
+ s->current_picture.pict_type = s->pict_type;
+ s->current_picture.key_frame = (s->pict_type == I_TYPE);
+
+ /* skip b frames if we dont have reference frames */
+ if (s->last_picture_ptr == NULL && s->pict_type == B_TYPE) return 0;
+ /* skip b frames if we are in a hurry */
+ if (avctx->hurry_up && s->pict_type == B_TYPE) return 0;
+ /* skip everything if we are in a hurry >= 5 */
+ if (avctx->hurry_up >= 5) return 0;
+ if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==B_TYPE)
+ ||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=I_TYPE)
+ || avctx->skip_frame >= AVDISCARD_ALL)
+ return 0;
+
+ if (s->next_p_frame_damaged) {
+ if (s->pict_type == B_TYPE)
+ return 0;
+ else
+ s->next_p_frame_damaged = 0;
+ }
+
+ if (frame_start (h) < 0)
+ return -1;
+
+ if (s->pict_type == B_TYPE) {
+ h->frame_num_offset = (h->slice_num - h->prev_frame_num);
+
+ if (h->frame_num_offset < 0) {
+ h->frame_num_offset += 256;
+ }
+ if (h->frame_num_offset == 0 || h->frame_num_offset >= h->prev_frame_num_offset) {
+ av_log(h->s.avctx, AV_LOG_ERROR, "error in B-frame picture id\n");
+ return -1;
+ }
+ } else {
+ h->prev_frame_num = h->frame_num;
+ h->frame_num = h->slice_num;
+ h->prev_frame_num_offset = (h->frame_num - h->prev_frame_num);
+
+ if (h->prev_frame_num_offset < 0) {
+ h->prev_frame_num_offset += 256;
+ }
+ }
+
+ for(m=0; m<2; m++){
+ int i;
+ for(i=0; i<4; i++){
+ int j;
+ for(j=-1; j<4; j++)
+ h->ref_cache[m][scan8[0] + 8*i + j]= 1;
+ h->ref_cache[m][scan8[0] + 8*i + j]= PART_NOT_AVAILABLE;
+ }
+ }
+
+ for (s->mb_y=0; s->mb_y < s->mb_height; s->mb_y++) {
+ for (s->mb_x=0; s->mb_x < s->mb_width; s->mb_x++) {
+
+ if ( (get_bits_count(&s->gb) + 7) >= s->gb.size_in_bits &&
+ ((get_bits_count(&s->gb) & 7) == 0 || show_bits (&s->gb, (-get_bits_count(&s->gb) & 7)) == 0)) {
+
+ skip_bits(&s->gb, h->next_slice_index - get_bits_count(&s->gb));
+ s->gb.size_in_bits = 8*buf_size;
+
+ if (svq3_decode_slice_header (h))
+ return -1;
+
+ /* TODO: support s->mb_skip_run */
+ }
+
+ mb_type = svq3_get_ue_golomb (&s->gb);
+
+ if (s->pict_type == I_TYPE) {
+ mb_type += 8;
+ } else if (s->pict_type == B_TYPE && mb_type >= 4) {
+ mb_type += 4;
+ }
+ if (mb_type > 33 || svq3_decode_mb (h, mb_type)) {
+ av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d\n", s->mb_x, s->mb_y);
+ return -1;
+ }
+
+ if (mb_type != 0) {
+ hl_decode_mb (h);
+ }
+
+ if (s->pict_type != B_TYPE && !s->low_delay) {
+ s->current_picture.mb_type[s->mb_x + s->mb_y*s->mb_stride] =
+ (s->pict_type == P_TYPE && mb_type < 8) ? (mb_type - 1) : -1;
+ }
+ }
+
+ ff_draw_horiz_band(s, 16*s->mb_y, 16);
+ }
+
+ MPV_frame_end(s);
+
+ if (s->pict_type == B_TYPE || s->low_delay) {
+ *(AVFrame *) data = *(AVFrame *) &s->current_picture;
+ } else {
+ *(AVFrame *) data = *(AVFrame *) &s->last_picture;
+ }
+
+ avctx->frame_number = s->picture_number - 1;
+
+ /* dont output the last pic after seeking */
+ if (s->last_picture_ptr || s->low_delay) {
+ *data_size = sizeof(AVFrame);
+ }
+
+ return buf_size;
+}
+
+
+AVCodec svq3_decoder = {
+ "svq3",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_SVQ3,
+ sizeof(H264Context),
+ decode_init,
+ NULL,
+ decode_end,
+ svq3_decode_frame,
+ CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_DELAY,
+};
diff --git a/contrib/ffmpeg/libavcodec/targa.c b/contrib/ffmpeg/libavcodec/targa.c
new file mode 100644
index 000000000..d637bedae
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/targa.c
@@ -0,0 +1,254 @@
+/*
+ * Targa (.tga) image decoder
+ * Copyright (c) 2006 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"
+
+enum TargaCompr{
+ TGA_NODATA = 0, // no image data
+ TGA_PAL = 1, // palettized
+ TGA_RGB = 2, // true-color
+ TGA_BW = 3, // black & white or grayscale
+ TGA_RLE = 8, // flag pointing that data is RLE-coded
+};
+
+typedef struct TargaContext {
+ AVFrame picture;
+
+ int width, height;
+ int bpp;
+ int color_type;
+ int compression_type;
+} TargaContext;
+
+static void targa_decode_rle(AVCodecContext *avctx, TargaContext *s, uint8_t *src, uint8_t *dst, int w, int h, int stride, int bpp)
+{
+ int i, x, y;
+ int depth = (bpp + 1) >> 3;
+ int type, count;
+ int diff;
+
+ diff = stride - w * depth;
+ x = y = 0;
+ while(y < h){
+ type = *src++;
+ count = (type & 0x7F) + 1;
+ type &= 0x80;
+ if((x + count > w) && (x + count + 1 > (h - y) * w)){
+ av_log(avctx, AV_LOG_ERROR, "Packet went out of bounds: position (%i,%i) size %i\n", x, y, count);
+ return;
+ }
+ for(i = 0; i < count; i++){
+ switch(depth){
+ case 1:
+ *dst = *src;
+ break;
+ case 2:
+ *((uint16_t*)dst) = AV_RL16(src);
+ break;
+ case 3:
+ dst[0] = src[0];
+ dst[1] = src[1];
+ dst[2] = src[2];
+ break;
+ case 4:
+ *((uint32_t*)dst) = AV_RL32(src);
+ break;
+ }
+ dst += depth;
+ if(!type)
+ src += depth;
+
+ x++;
+ if(x == w){
+ x = 0;
+ y++;
+ dst += diff;
+ }
+ }
+ if(type)
+ src += depth;
+ }
+}
+
+static int decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ TargaContext * const s = avctx->priv_data;
+ AVFrame *picture = data;
+ AVFrame * const p= (AVFrame*)&s->picture;
+ uint8_t *dst;
+ int stride;
+ int idlen, pal, compr, x, y, w, h, bpp, flags;
+ int first_clr, colors, csize;
+
+ /* parse image header */
+ idlen = *buf++;
+ pal = *buf++;
+ compr = *buf++;
+ first_clr = AV_RL16(buf); buf += 2;
+ colors = AV_RL16(buf); buf += 2;
+ csize = *buf++;
+ x = AV_RL16(buf); buf += 2;
+ y = AV_RL16(buf); buf += 2;
+ w = AV_RL16(buf); buf += 2;
+ h = AV_RL16(buf); buf += 2;
+ bpp = *buf++;
+ flags = *buf++;
+ //skip identifier if any
+ buf += idlen;
+ s->bpp = bpp;
+ s->width = w;
+ s->height = h;
+ switch(s->bpp){
+ case 8:
+ avctx->pix_fmt = ((compr & (~TGA_RLE)) == TGA_BW) ? PIX_FMT_GRAY8 : PIX_FMT_PAL8;
+ break;
+ case 15:
+ avctx->pix_fmt = PIX_FMT_RGB555;
+ break;
+ case 16:
+ avctx->pix_fmt = PIX_FMT_RGB555;
+ break;
+ case 24:
+ avctx->pix_fmt = PIX_FMT_BGR24;
+ break;
+ case 32:
+ avctx->pix_fmt = PIX_FMT_RGB32;
+ break;
+ default:
+ av_log(avctx, AV_LOG_ERROR, "Bit depth %i is not supported\n", s->bpp);
+ return -1;
+ }
+
+ if(s->picture.data[0])
+ avctx->release_buffer(avctx, &s->picture);
+
+ if(avcodec_check_dimensions(avctx, w, h))
+ return -1;
+ if(w != avctx->width || h != avctx->height)
+ avcodec_set_dimensions(avctx, w, h);
+ if(avctx->get_buffer(avctx, p) < 0){
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ return -1;
+ }
+ if(flags & 0x20){
+ dst = p->data[0];
+ stride = p->linesize[0];
+ }else{ //image is upside-down
+ dst = p->data[0] + p->linesize[0] * (h - 1);
+ stride = -p->linesize[0];
+ }
+
+ if(avctx->pix_fmt == PIX_FMT_PAL8 && avctx->palctrl){
+ memcpy(p->data[1], avctx->palctrl->palette, AVPALETTE_SIZE);
+ if(avctx->palctrl->palette_changed){
+ p->palette_has_changed = 1;
+ avctx->palctrl->palette_changed = 0;
+ }
+ }
+ if(colors){
+ if((colors + first_clr) > 256){
+ av_log(avctx, AV_LOG_ERROR, "Incorrect palette: %i colors with offset %i\n", colors, first_clr);
+ return -1;
+ }
+ if(csize != 24){
+ av_log(avctx, AV_LOG_ERROR, "Palette entry size %i bits is not supported\n", csize);
+ return -1;
+ }
+ if(avctx->pix_fmt != PIX_FMT_PAL8)//should not occur but skip palette anyway
+ buf += colors * ((csize + 1) >> 3);
+ else{
+ int r, g, b, t;
+ int32_t *pal = ((int32_t*)p->data[1]) + first_clr;
+ for(t = 0; t < colors; t++){
+ r = *buf++;
+ g = *buf++;
+ b = *buf++;
+ *pal++ = (b << 16) | (g << 8) | r;
+ }
+ p->palette_has_changed = 1;
+ avctx->palctrl->palette_changed = 0;
+ }
+ }
+ if((compr & (~TGA_RLE)) == TGA_NODATA)
+ memset(p->data[0], 0, p->linesize[0] * s->height);
+ else{
+ if(compr & TGA_RLE)
+ targa_decode_rle(avctx, s, buf, dst, avctx->width, avctx->height, stride, bpp);
+ else{
+ for(y = 0; y < s->height; y++){
+#ifdef WORDS_BIGENDIAN
+ if((s->bpp + 1) >> 3 == 2){
+ uint16_t *dst16 = (uint16_t*)dst;
+ for(x = 0; x < s->width; x++)
+ dst16[x] = AV_RL16(buf + x * 2);
+ }else if((s->bpp + 1) >> 3 == 4){
+ uint32_t *dst32 = (uint32_t*)dst;
+ for(x = 0; x < s->width; x++)
+ dst32[x] = AV_RL32(buf + x * 4);
+ }else
+#endif
+ memcpy(dst, buf, s->width * ((s->bpp + 1) >> 3));
+
+ dst += stride;
+ buf += s->width * ((s->bpp + 1) >> 3);
+ }
+ }
+ }
+
+ *picture= *(AVFrame*)&s->picture;
+ *data_size = sizeof(AVPicture);
+
+ return buf_size;
+}
+
+static int targa_init(AVCodecContext *avctx){
+ TargaContext *s = avctx->priv_data;
+
+ avcodec_get_frame_defaults((AVFrame*)&s->picture);
+ avctx->coded_frame= (AVFrame*)&s->picture;
+ s->picture.data[0] = NULL;
+
+ return 0;
+}
+
+static int targa_end(AVCodecContext *avctx){
+ TargaContext *s = avctx->priv_data;
+
+ if(s->picture.data[0])
+ avctx->release_buffer(avctx, &s->picture);
+
+ return 0;
+}
+
+AVCodec targa_decoder = {
+ "targa",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_TARGA,
+ sizeof(TargaContext),
+ targa_init,
+ NULL,
+ targa_end,
+ decode_frame,
+ 0,
+ NULL
+};
diff --git a/contrib/ffmpeg/libavcodec/targaenc.c b/contrib/ffmpeg/libavcodec/targaenc.c
new file mode 100644
index 000000000..8b36e1d3d
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/targaenc.c
@@ -0,0 +1,199 @@
+/*
+ * Targa (.tga) image encoder
+ * Copyright (c) 2007 Bobby Bingham
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+#include "avcodec.h"
+
+/**
+ * Count up to 127 consecutive pixels which are either all the same or
+ * all differ from the previous and next pixels.
+ * @param start Pointer to the first pixel
+ * @param len Maximum number of pixels
+ * @param bpp Bytes per pixel
+ * @param same 1 if searching for identical pixel values. 0 for differing
+ * @return Number of matching consecutive pixels found
+ */
+static int count_pixels(uint8_t *start, int len, int bpp, int same)
+{
+ uint8_t *pos;
+ int count = 1;
+
+ for(pos = start + bpp; count < FFMIN(128, len); pos += bpp, count ++) {
+ if(same != !memcmp(pos-bpp, pos, bpp)) {
+ if(!same) {
+ /* if bpp == 1, then 0 1 1 0 is more efficiently encoded as a single
+ * raw block of pixels. for larger bpp, RLE is as good or better */
+ if(bpp == 1 && count + 1 < FFMIN(128, len) && *pos != *(pos+1))
+ continue;
+
+ /* if RLE can encode the next block better than as a raw block,
+ * back up and leave _all_ the identical pixels for RLE */
+ count --;
+ }
+ break;
+ }
+ }
+
+ return count;
+}
+
+/**
+ * RLE compress the image, with maximum size of out_size
+ * @param outbuf Output buffer
+ * @param out_size Maximum output size
+ * @param pic Image to compress
+ * @param bpp Bytes per pixel
+ * @param w Image width
+ * @param h Image height
+ * @return Size of output in bytes, or -1 if larger than out_size
+ */
+static int targa_encode_rle(uint8_t *outbuf, int out_size, AVFrame *pic,
+ int bpp, int w, int h)
+{
+ int count, x, y;
+ uint8_t *ptr, *line, *out;
+
+ out = outbuf;
+ line = pic->data[0];
+
+ for(y = 0; y < h; y ++) {
+ ptr = line;
+
+ for(x = 0; x < w; x += count) {
+ /* see if we can encode the next set of pixels with RLE */
+ if((count = count_pixels(ptr, w-x, bpp, 1)) > 1) {
+ if(out + bpp + 1 > outbuf + out_size) return -1;
+ *out++ = 0x80 | (count - 1);
+ memcpy(out, ptr, bpp);
+ out += bpp;
+ } else {
+ /* fall back on uncompressed */
+ count = count_pixels(ptr, w-x, bpp, 0);
+ *out++ = count - 1;
+
+ if(out + bpp*count > outbuf + out_size) return -1;
+ memcpy(out, ptr, bpp * count);
+ out += bpp * count;
+ }
+ ptr += count * bpp;
+ }
+
+ line += pic->linesize[0];
+ }
+
+ return out - outbuf;
+}
+
+static int targa_encode_normal(uint8_t *outbuf, AVFrame *pic, int bpp, int w, int h)
+{
+ int i, n = bpp * w;
+ uint8_t *out = outbuf;
+ uint8_t *ptr = pic->data[0];
+
+ for(i=0; i < h; i++) {
+ memcpy(out, ptr, n);
+ out += n;
+ ptr += pic->linesize[0];
+ }
+
+ return out - outbuf;
+}
+
+static int targa_encode_frame(AVCodecContext *avctx,
+ unsigned char *outbuf,
+ int buf_size, void *data){
+ AVFrame *p = data;
+ int bpp, picsize, datasize;
+ uint8_t *out;
+
+ if(avctx->width > 0xffff || avctx->height > 0xffff) {
+ av_log(avctx, AV_LOG_ERROR, "image dimensions too large\n");
+ return -1;
+ }
+ picsize = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
+ if(buf_size < picsize + 45) {
+ av_log(avctx, AV_LOG_ERROR, "encoded frame too large\n");
+ return -1;
+ }
+
+ p->pict_type= FF_I_TYPE;
+ p->key_frame= 1;
+
+ /* zero out the header and only set applicable fields */
+ memset(outbuf, 0, 11);
+ AV_WL16(outbuf+12, avctx->width);
+ AV_WL16(outbuf+14, avctx->height);
+ outbuf[17] = 0x20; /* origin is top-left. no alpha */
+
+ /* TODO: support alpha channel */
+ switch(avctx->pix_fmt) {
+ case PIX_FMT_GRAY8:
+ outbuf[2] = 3; /* uncompressed grayscale image */
+ outbuf[16] = 8; /* bpp */
+ break;
+ case PIX_FMT_RGB555:
+ outbuf[2] = 2; /* uncompresses true-color image */
+ outbuf[16] = 16; /* bpp */
+ break;
+ case PIX_FMT_BGR24:
+ outbuf[2] = 2; /* uncompressed true-color image */
+ outbuf[16] = 24; /* bpp */
+ break;
+ default:
+ return -1;
+ }
+ bpp = outbuf[16] >> 3;
+
+ 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 that worked well, mark the picture as RLE compressed */
+ if(datasize >= 0)
+ outbuf[2] |= 8;
+
+ /* if RLE didn't make it smaller, go back to no compression */
+ else datasize = targa_encode_normal(out, p, bpp, avctx->width, avctx->height);
+
+ out += datasize;
+
+ /* The standard recommends including this section, even if we don't use
+ * any of the features it affords. TODO: take advantage of the pixel
+ * aspect ratio and encoder ID fields available? */
+ memcpy(out, "\0\0\0\0\0\0\0\0TRUEVISION-XFILE.", 26);
+
+ return out + 26 - outbuf;
+}
+
+static int targa_encode_init(AVCodecContext *avctx)
+{
+ return 0;
+}
+
+AVCodec targa_encoder = {
+ .name = "targa",
+ .type = CODEC_TYPE_VIDEO,
+ .id = CODEC_ID_TARGA,
+ .priv_data_size = 0,
+ .init = targa_encode_init,
+ .encode = targa_encode_frame,
+ .pix_fmts= (enum PixelFormat[]){PIX_FMT_BGR24, PIX_FMT_RGB555, PIX_FMT_GRAY8, -1},
+};
diff --git a/contrib/ffmpeg/libavcodec/tiertexseqv.c b/contrib/ffmpeg/libavcodec/tiertexseqv.c
new file mode 100644
index 000000000..ca3baf09e
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/tiertexseqv.c
@@ -0,0 +1,232 @@
+/*
+ * Tiertex Limited SEQ Video Decoder
+ * Copyright (c) 2006 Gregory Montoir (cyx@users.sourceforge.net)
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 tiertexseqv.c
+ * Tiertex Limited SEQ video decoder
+ */
+
+#include "avcodec.h"
+#include "common.h"
+#define ALT_BITSTREAM_READER_LE
+#include "bitstream.h"
+
+
+typedef struct SeqVideoContext {
+ AVCodecContext *avctx;
+ AVFrame frame;
+ unsigned int palette[256];
+ unsigned char block[8 * 8];
+} SeqVideoContext;
+
+
+static unsigned char *seq_unpack_rle_block(unsigned char *src, unsigned char *dst, int dst_size)
+{
+ int i, len, sz;
+ GetBitContext gb;
+ int code_table[64];
+
+ /* get the rle codes (at most 64 bytes) */
+ init_get_bits(&gb, src, 64 * 8);
+ for (i = 0, sz = 0; i < 64 && sz < dst_size; i++) {
+ code_table[i] = get_sbits(&gb, 4);
+ sz += FFABS(code_table[i]);
+ }
+ src += (get_bits_count(&gb) + 7) / 8;
+
+ /* do the rle unpacking */
+ for (i = 0; i < 64 && dst_size > 0; i++) {
+ len = code_table[i];
+ if (len < 0) {
+ len = -len;
+ memset(dst, *src++, FFMIN(len, dst_size));
+ } else {
+ memcpy(dst, src, FFMIN(len, dst_size));
+ src += len;
+ }
+ dst += len;
+ dst_size -= len;
+ }
+ return src;
+}
+
+static unsigned char *seq_decode_op1(SeqVideoContext *seq, unsigned char *src, unsigned char *dst)
+{
+ unsigned char *color_table;
+ int b, i, len, bits;
+ GetBitContext gb;
+
+ len = *src++;
+ if (len & 0x80) {
+ switch (len & 3) {
+ case 1:
+ src = seq_unpack_rle_block(src, seq->block, sizeof(seq->block));
+ for (b = 0; b < 8; b++) {
+ memcpy(dst, &seq->block[b * 8], 8);
+ dst += seq->frame.linesize[0];
+ }
+ break;
+ case 2:
+ src = seq_unpack_rle_block(src, seq->block, sizeof(seq->block));
+ for (i = 0; i < 8; i++) {
+ for (b = 0; b < 8; b++)
+ dst[b * seq->frame.linesize[0]] = seq->block[i * 8 + b];
+ ++dst;
+ }
+ break;
+ }
+ } else {
+ color_table = src;
+ src += len;
+ bits = ff_log2_tab[len - 1] + 1;
+ init_get_bits(&gb, src, bits * 8 * 8); src += bits * 8;
+ for (b = 0; b < 8; b++) {
+ for (i = 0; i < 8; i++)
+ dst[i] = color_table[get_bits(&gb, bits)];
+ dst += seq->frame.linesize[0];
+ }
+ }
+
+ return src;
+}
+
+static unsigned char *seq_decode_op2(SeqVideoContext *seq, unsigned char *src, unsigned char *dst)
+{
+ int i;
+
+ for (i = 0; i < 8; i++) {
+ memcpy(dst, src, 8);
+ src += 8;
+ dst += seq->frame.linesize[0];
+ }
+
+ return src;
+}
+
+static unsigned char *seq_decode_op3(SeqVideoContext *seq, unsigned char *src, unsigned char *dst)
+{
+ int pos, offset;
+
+ do {
+ pos = *src++;
+ offset = ((pos >> 3) & 7) * seq->frame.linesize[0] + (pos & 7);
+ dst[offset] = *src++;
+ } while (!(pos & 0x80));
+
+ return src;
+}
+
+static void seqvideo_decode(SeqVideoContext *seq, unsigned char *data, int data_size)
+{
+ GetBitContext gb;
+ int flags, i, j, x, y, op;
+ unsigned char c[3];
+ unsigned char *dst;
+
+ flags = *data++;
+
+ if (flags & 1) {
+ for (i = 0; i < 256; i++) {
+ for (j = 0; j < 3; j++, data++)
+ c[j] = (*data << 2) | (*data >> 4);
+ seq->palette[i] = (c[0] << 16) | (c[1] << 8) | c[2];
+ }
+ memcpy(seq->frame.data[1], seq->palette, sizeof(seq->palette));
+ seq->frame.palette_has_changed = 1;
+ }
+
+ if (flags & 2) {
+ init_get_bits(&gb, data, 128 * 8); data += 128;
+ for (y = 0; y < 128; y += 8)
+ for (x = 0; x < 256; x += 8) {
+ dst = &seq->frame.data[0][y * seq->frame.linesize[0] + x];
+ op = get_bits(&gb, 2);
+ switch (op) {
+ case 1:
+ data = seq_decode_op1(seq, data, dst);
+ break;
+ case 2:
+ data = seq_decode_op2(seq, data, dst);
+ break;
+ case 3:
+ data = seq_decode_op3(seq, data, dst);
+ break;
+ }
+ }
+ }
+}
+
+static int seqvideo_decode_init(AVCodecContext *avctx)
+{
+ SeqVideoContext *seq = (SeqVideoContext *)avctx->priv_data;
+
+ seq->avctx = avctx;
+ avctx->pix_fmt = PIX_FMT_PAL8;
+ avctx->has_b_frames = 0;
+
+ seq->frame.data[0] = NULL;
+
+ return 0;
+}
+
+static int seqvideo_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+
+ SeqVideoContext *seq = (SeqVideoContext *)avctx->priv_data;
+
+ seq->frame.reference = 1;
+ seq->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
+ if (avctx->reget_buffer(avctx, &seq->frame)) {
+ av_log(seq->avctx, AV_LOG_ERROR, "tiertexseqvideo: reget_buffer() failed\n");
+ return -1;
+ }
+
+ seqvideo_decode(seq, buf, buf_size);
+
+ *data_size = sizeof(AVFrame);
+ *(AVFrame *)data = seq->frame;
+
+ return buf_size;
+}
+
+static int seqvideo_decode_end(AVCodecContext *avctx)
+{
+ SeqVideoContext *seq = (SeqVideoContext *)avctx->priv_data;
+
+ if (seq->frame.data[0])
+ avctx->release_buffer(avctx, &seq->frame);
+
+ return 0;
+}
+
+AVCodec tiertexseqvideo_decoder = {
+ "tiertexseqvideo",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_TIERTEXSEQVIDEO,
+ sizeof(SeqVideoContext),
+ seqvideo_decode_init,
+ NULL,
+ seqvideo_decode_end,
+ seqvideo_decode_frame,
+ CODEC_CAP_DR1,
+};
diff --git a/contrib/ffmpeg/libavcodec/tiff.c b/contrib/ffmpeg/libavcodec/tiff.c
new file mode 100644
index 000000000..344b5a311
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/tiff.c
@@ -0,0 +1,532 @@
+/*
+ * TIFF image decoder
+ * Copyright (c) 2006 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"
+#ifdef CONFIG_ZLIB
+#include <zlib.h>
+#endif
+#include "lzw.h"
+
+/* abridged list of TIFF tags */
+enum TiffTags{
+ TIFF_WIDTH = 0x100,
+ TIFF_HEIGHT,
+ TIFF_BPP,
+ TIFF_COMPR,
+ TIFF_INVERT = 0x106,
+ TIFF_STRIP_OFFS = 0x111,
+ TIFF_ROWSPERSTRIP = 0x116,
+ TIFF_STRIP_SIZE,
+ TIFF_PLANAR = 0x11C,
+ TIFF_XPOS = 0x11E,
+ TIFF_YPOS = 0x11F,
+ TIFF_PREDICTOR = 0x13D,
+ TIFF_PAL = 0x140
+};
+
+enum TiffCompr{
+ TIFF_RAW = 1,
+ TIFF_CCITT_RLE,
+ TIFF_G3,
+ TIFF_G4,
+ TIFF_LZW,
+ TIFF_JPEG,
+ TIFF_NEWJPEG,
+ TIFF_ADOBE_DEFLATE,
+ TIFF_PACKBITS = 0x8005,
+ TIFF_DEFLATE = 0x80B2
+};
+
+enum TiffTypes{
+ TIFF_BYTE = 1,
+ TIFF_STRING,
+ TIFF_SHORT,
+ TIFF_LONG,
+ TIFF_LONGLONG
+};
+
+/** sizes of various TIFF field types */
+static const int type_sizes[6] = {
+ 0, 1, 100, 2, 4, 8
+};
+
+typedef struct TiffContext {
+ AVCodecContext *avctx;
+ AVFrame picture;
+
+ int width, height;
+ unsigned int bpp;
+ int le;
+ int compr;
+ int invert;
+
+ int strips, rps;
+ int sot;
+ uint8_t* stripdata;
+ uint8_t* stripsizes;
+ int stripsize, stripoff;
+ LZWState *lzw;
+} TiffContext;
+
+static int tget_short(uint8_t **p, int le){
+ int v = le ? AV_RL16(*p) : AV_RB16(*p);
+ *p += 2;
+ return v;
+}
+
+static int tget_long(uint8_t **p, int le){
+ int v = le ? AV_RL32(*p) : AV_RB32(*p);
+ *p += 4;
+ return v;
+}
+
+static int tget(uint8_t **p, int type, int le){
+ switch(type){
+ case TIFF_BYTE : return *(*p)++;
+ case TIFF_SHORT: return tget_short(p, le);
+ case TIFF_LONG : return tget_long (p, le);
+ default : return -1;
+ }
+}
+
+static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, uint8_t *src, int size, int lines){
+ int c, line, pixels, code;
+ uint8_t *ssrc = src;
+ int width = s->width * (s->bpp / 8);
+#ifdef CONFIG_ZLIB
+ uint8_t *zbuf; unsigned long outlen;
+
+ if(s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE){
+ 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);
+ av_free(zbuf);
+ return -1;
+ }
+ src = zbuf;
+ for(line = 0; line < lines; line++){
+ memcpy(dst, src, width);
+ dst += stride;
+ src += width;
+ }
+ av_free(zbuf);
+ return 0;
+ }
+#endif
+ if(s->compr == TIFF_LZW){
+ if(ff_lzw_decode_init(s->lzw, 8, src, size, FF_LZW_TIFF) < 0){
+ av_log(s->avctx, AV_LOG_ERROR, "Error initializing LZW decoder\n");
+ return -1;
+ }
+ }
+ for(line = 0; line < lines; line++){
+ if(src - ssrc > size){
+ av_log(s->avctx, AV_LOG_ERROR, "Source data overread\n");
+ return -1;
+ }
+ switch(s->compr){
+ case TIFF_RAW:
+ memcpy(dst, src, s->width * (s->bpp / 8));
+ src += s->width * (s->bpp / 8);
+ break;
+ case TIFF_PACKBITS:
+ for(pixels = 0; pixels < width;){
+ code = (int8_t)*src++;
+ if(code >= 0){
+ code++;
+ if(pixels + code > width){
+ av_log(s->avctx, AV_LOG_ERROR, "Copy went out of bounds\n");
+ return -1;
+ }
+ memcpy(dst + pixels, src, code);
+ src += code;
+ pixels += code;
+ }else if(code != -128){ // -127..-1
+ code = (-code) + 1;
+ if(pixels + code > width){
+ av_log(s->avctx, AV_LOG_ERROR, "Run went out of bounds\n");
+ return -1;
+ }
+ c = *src++;
+ memset(dst + pixels, c, code);
+ pixels += code;
+ }
+ }
+ break;
+ case TIFF_LZW:
+ pixels = ff_lzw_decode(s->lzw, dst, width);
+ if(pixels < width){
+ av_log(s->avctx, AV_LOG_ERROR, "Decoded only %i bytes of %i\n", pixels, width);
+ return -1;
+ }
+ break;
+ }
+ dst += stride;
+ }
+ return 0;
+}
+
+
+static int tiff_decode_tag(TiffContext *s, uint8_t *start, uint8_t *buf, uint8_t *end_buf, AVFrame *pic)
+{
+ int tag, type, count, off, value = 0;
+ uint8_t *src, *dst;
+ int i, j, ssize, soff, stride;
+ int *pal, *rp, *gp, *bp;
+
+ tag = tget_short(&buf, s->le);
+ type = tget_short(&buf, s->le);
+ count = tget_long(&buf, s->le);
+ off = tget_long(&buf, s->le);
+
+ if(count == 1){
+ switch(type){
+ case TIFF_BYTE:
+ case TIFF_SHORT:
+ buf -= 4;
+ value = tget(&buf, type, s->le);
+ buf = NULL;
+ break;
+ case TIFF_LONG:
+ value = off;
+ buf = NULL;
+ break;
+ default:
+ value = -1;
+ buf = start + off;
+ }
+ }else if(type_sizes[type] * count <= 4){
+ buf -= 4;
+ }else{
+ buf = start + off;
+ }
+
+ if(buf && (buf < start || buf > end_buf)){
+ av_log(s->avctx, AV_LOG_ERROR, "Tag referencing position outside the image\n");
+ return -1;
+ }
+
+ switch(tag){
+ case TIFF_WIDTH:
+ s->width = value;
+ break;
+ case TIFF_HEIGHT:
+ s->height = value;
+ break;
+ case TIFF_BPP:
+ if(count == 1) s->bpp = value;
+ else{
+ switch(type){
+ case TIFF_BYTE:
+ s->bpp = (off & 0xFF) + ((off >> 8) & 0xFF) + ((off >> 16) & 0xFF) + ((off >> 24) & 0xFF);
+ break;
+ case TIFF_SHORT:
+ case TIFF_LONG:
+ s->bpp = 0;
+ for(i = 0; i < count; i++) s->bpp += tget(&buf, type, s->le);
+ break;
+ default:
+ s->bpp = -1;
+ }
+ }
+ switch(s->bpp){
+ case 8:
+ s->avctx->pix_fmt = PIX_FMT_PAL8;
+ break;
+ case 24:
+ s->avctx->pix_fmt = PIX_FMT_RGB24;
+ break;
+ case 16:
+ if(count == 1){
+ s->avctx->pix_fmt = PIX_FMT_GRAY16BE;
+ }else{
+ av_log(s->avctx, AV_LOG_ERROR, "This format is not supported (bpp=%i)\n", s->bpp);
+ return -1;
+ }
+ break;
+ default:
+ av_log(s->avctx, AV_LOG_ERROR, "This format is not supported (bpp=%i)\n", s->bpp);
+ return -1;
+ }
+ 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->bpp == 8){
+ /* make default grayscale pal */
+ pal = s->picture.data[1];
+ for(i = 0; i < 256; i++)
+ pal[i] = i * 0x010101;
+ }
+ break;
+ case TIFF_COMPR:
+ s->compr = value;
+ switch(s->compr){
+ case TIFF_RAW:
+ case TIFF_PACKBITS:
+ case TIFF_LZW:
+ break;
+ case TIFF_DEFLATE:
+ case TIFF_ADOBE_DEFLATE:
+#ifdef CONFIG_ZLIB
+ break;
+#else
+ av_log(s->avctx, AV_LOG_ERROR, "Deflate: ZLib not compiled in\n");
+ return -1;
+#endif
+ case TIFF_G3:
+ av_log(s->avctx, AV_LOG_ERROR, "CCITT G3 compression is not supported\n");
+ return -1;
+ case TIFF_G4:
+ av_log(s->avctx, AV_LOG_ERROR, "CCITT G4 compression is not supported\n");
+ return -1;
+ case TIFF_CCITT_RLE:
+ av_log(s->avctx, AV_LOG_ERROR, "CCITT RLE compression is not supported\n");
+ return -1;
+ case TIFF_JPEG:
+ case TIFF_NEWJPEG:
+ av_log(s->avctx, AV_LOG_ERROR, "JPEG compression is not supported\n");
+ return -1;
+ default:
+ av_log(s->avctx, AV_LOG_ERROR, "Unknown compression method %i\n", s->compr);
+ return -1;
+ }
+ break;
+ case TIFF_ROWSPERSTRIP:
+ if(value < 1){
+ av_log(s->avctx, AV_LOG_ERROR, "Incorrect value of rows per strip\n");
+ return -1;
+ }
+ s->rps = value;
+ break;
+ case TIFF_STRIP_OFFS:
+ if(count == 1){
+ s->stripdata = NULL;
+ s->stripoff = value;
+ }else
+ s->stripdata = start + off;
+ s->strips = count;
+ if(s->strips == 1) s->rps = s->height;
+ s->sot = type;
+ if(s->stripdata > end_buf){
+ av_log(s->avctx, AV_LOG_ERROR, "Tag referencing position outside the image\n");
+ return -1;
+ }
+ break;
+ case TIFF_STRIP_SIZE:
+ if(count == 1){
+ s->stripsizes = NULL;
+ s->stripsize = value;
+ s->strips = 1;
+ }else{
+ s->stripsizes = start + off;
+ }
+ s->strips = count;
+ if(s->stripsizes > end_buf){
+ av_log(s->avctx, AV_LOG_ERROR, "Tag referencing position outside the image\n");
+ return -1;
+ }
+ if(!pic->data[0]){
+ av_log(s->avctx, AV_LOG_ERROR, "Picture initialization missing\n");
+ return -1;
+ }
+ /* now we have the data and may start decoding */
+ stride = pic->linesize[0];
+ dst = pic->data[0];
+ for(i = 0; i < s->height; i += s->rps){
+ if(s->stripsizes)
+ ssize = tget(&s->stripsizes, type, s->le);
+ else
+ ssize = s->stripsize;
+
+ if(s->stripdata){
+ soff = tget(&s->stripdata, s->sot, s->le);
+ }else
+ soff = s->stripoff;
+ src = start + soff;
+ if(tiff_unpack_strip(s, dst, stride, src, ssize, FFMIN(s->rps, s->height - i)) < 0)
+ break;
+ dst += s->rps * stride;
+ }
+ break;
+ case TIFF_PREDICTOR:
+ if(!pic->data[0]){
+ av_log(s->avctx, AV_LOG_ERROR, "Picture initialization missing\n");
+ return -1;
+ }
+ if(value == 2){
+ src = pic->data[0];
+ stride = pic->linesize[0];
+ soff = s->bpp >> 3;
+ ssize = s->width * soff;
+ for(i = 0; i < s->height; i++) {
+ for(j = soff; j < ssize; j++)
+ src[j] += src[j - soff];
+ src += stride;
+ }
+ }
+ break;
+ case TIFF_INVERT:
+ switch(value){
+ case 0:
+ s->invert = 1;
+ break;
+ case 1:
+ s->invert = 0;
+ break;
+ case 2:
+ case 3:
+ break;
+ default:
+ av_log(s->avctx, AV_LOG_ERROR, "Color mode %d is not supported\n", value);
+ return -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");
+ return -1;
+ }
+ pal = s->picture.data[1];
+ off = type_sizes[type];
+ rp = buf;
+ gp = buf + count / 3 * off;
+ bp = buf + count / 3 * off * 2;
+ off = (type_sizes[type] - 1) << 3;
+ for(i = 0; i < count / 3; i++){
+ j = (tget(&rp, type, s->le) >> off) << 16;
+ j |= (tget(&gp, type, s->le) >> off) << 8;
+ j |= tget(&bp, type, s->le) >> off;
+ pal[i] = j;
+ }
+ break;
+ case TIFF_PLANAR:
+ if(value == 2){
+ av_log(s->avctx, AV_LOG_ERROR, "Planar format is not supported\n");
+ return -1;
+ }
+ break;
+ }
+ return 0;
+}
+
+static int decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ TiffContext * const s = avctx->priv_data;
+ AVFrame *picture = data;
+ AVFrame * const p= (AVFrame*)&s->picture;
+ uint8_t *orig_buf = buf, *end_buf = buf + buf_size;
+ int id, le, off;
+ int i, entries;
+
+ //parse image header
+ id = AV_RL16(buf); buf += 2;
+ if(id == 0x4949) le = 1;
+ else if(id == 0x4D4D) le = 0;
+ else{
+ av_log(avctx, AV_LOG_ERROR, "TIFF header not found\n");
+ return -1;
+ }
+ s->le = le;
+ s->invert = 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){
+ av_log(avctx, AV_LOG_ERROR, "The answer to life, universe and everything is not correct!\n");
+ return -1;
+ }
+ /* parse image file directory */
+ off = tget_long(&buf, le);
+ if(orig_buf + off + 14 >= end_buf){
+ av_log(avctx, AV_LOG_ERROR, "IFD offset is greater than image size\n");
+ return -1;
+ }
+ buf = orig_buf + off;
+ entries = tget_short(&buf, le);
+ for(i = 0; i < entries; i++){
+ if(tiff_decode_tag(s, orig_buf, buf, end_buf, p) < 0)
+ return -1;
+ buf += 12;
+ }
+
+ if(s->invert){
+ uint8_t *src;
+ int j;
+
+ src = s->picture.data[0];
+ for(j = 0; j < s->height; j++){
+ for(i = 0; i < s->picture.linesize[0]; i++)
+ src[i] = 255 - src[i];
+ src += s->picture.linesize[0];
+ }
+ }
+ *picture= *(AVFrame*)&s->picture;
+ *data_size = sizeof(AVPicture);
+
+ return buf_size;
+}
+
+static int tiff_init(AVCodecContext *avctx){
+ TiffContext *s = avctx->priv_data;
+
+ s->width = 0;
+ s->height = 0;
+ s->avctx = avctx;
+ avcodec_get_frame_defaults((AVFrame*)&s->picture);
+ avctx->coded_frame= (AVFrame*)&s->picture;
+ s->picture.data[0] = NULL;
+ ff_lzw_decode_open(&s->lzw);
+
+ return 0;
+}
+
+static int tiff_end(AVCodecContext *avctx)
+{
+ TiffContext * const s = avctx->priv_data;
+
+ ff_lzw_decode_close(&s->lzw);
+ if(s->picture.data[0])
+ avctx->release_buffer(avctx, &s->picture);
+ return 0;
+}
+
+AVCodec tiff_decoder = {
+ "tiff",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_TIFF,
+ sizeof(TiffContext),
+ tiff_init,
+ NULL,
+ tiff_end,
+ decode_frame,
+ 0,
+ NULL
+};
diff --git a/contrib/ffmpeg/libavcodec/truemotion1.c b/contrib/ffmpeg/libavcodec/truemotion1.c
new file mode 100644
index 000000000..a7d3544f4
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/truemotion1.c
@@ -0,0 +1,928 @@
+/*
+ * Duck TrueMotion 1.0 Decoder
+ * Copyright (C) 2003 Alex Beregszaszi & Mike Melanson
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 truemotion1.c
+ * Duck TrueMotion v1 Video Decoder by
+ * Alex Beregszaszi (alex@fsn.hu) and
+ * Mike Melanson (melanson@pcisys.net)
+ *
+ * The TrueMotion v1 decoder presently only decodes 16-bit TM1 data and
+ * outputs RGB555 (or RGB565) data. 24-bit TM1 data is not supported yet.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "common.h"
+#include "avcodec.h"
+#include "dsputil.h"
+
+#include "truemotion1data.h"
+
+typedef struct TrueMotion1Context {
+ AVCodecContext *avctx;
+ AVFrame frame;
+ AVFrame prev_frame;
+
+ uint8_t *buf;
+ int size;
+
+ uint8_t *mb_change_bits;
+ int mb_change_bits_row_size;
+ uint8_t *index_stream;
+ int index_stream_size;
+
+ int flags;
+ int x, y, w, h;
+
+ uint32_t y_predictor_table[1024];
+ uint32_t c_predictor_table[1024];
+ uint32_t fat_y_predictor_table[1024];
+ uint32_t fat_c_predictor_table[1024];
+
+ int compression;
+ int block_type;
+ int block_width;
+ int block_height;
+
+ int16_t ydt[8];
+ int16_t cdt[8];
+ int16_t fat_ydt[8];
+ int16_t fat_cdt[8];
+
+ int last_deltaset, last_vectable;
+
+ unsigned int *vert_pred;
+
+} TrueMotion1Context;
+
+#define FLAG_SPRITE 32
+#define FLAG_KEYFRAME 16
+#define FLAG_INTERFRAME 8
+#define FLAG_INTERPOLATED 4
+
+struct frame_header {
+ uint8_t header_size;
+ uint8_t compression;
+ uint8_t deltaset;
+ uint8_t vectable;
+ uint16_t ysize;
+ uint16_t xsize;
+ uint16_t checksum;
+ uint8_t version;
+ uint8_t header_type;
+ uint8_t flags;
+ uint8_t control;
+ uint16_t xoffset;
+ uint16_t yoffset;
+ uint16_t width;
+ uint16_t height;
+};
+
+#define ALGO_NOP 0
+#define ALGO_RGB16V 1
+#define ALGO_RGB16H 2
+#define ALGO_RGB24H 3
+
+/* these are the various block sizes that can occupy a 4x4 block */
+#define BLOCK_2x2 0
+#define BLOCK_2x4 1
+#define BLOCK_4x2 2
+#define BLOCK_4x4 3
+
+typedef struct comp_types {
+ int algorithm;
+ int block_width; // vres
+ int block_height; // hres
+ int block_type;
+} comp_types;
+
+/* { valid for metatype }, algorithm, num of deltas, vert res, horiz res */
+static comp_types compression_types[17] = {
+ { ALGO_NOP, 0, 0, 0 },
+
+ { ALGO_RGB16V, 4, 4, BLOCK_4x4 },
+ { ALGO_RGB16H, 4, 4, BLOCK_4x4 },
+ { ALGO_RGB16V, 4, 2, BLOCK_4x2 },
+ { ALGO_RGB16H, 4, 2, BLOCK_4x2 },
+
+ { ALGO_RGB16V, 2, 4, BLOCK_2x4 },
+ { ALGO_RGB16H, 2, 4, BLOCK_2x4 },
+ { ALGO_RGB16V, 2, 2, BLOCK_2x2 },
+ { ALGO_RGB16H, 2, 2, BLOCK_2x2 },
+
+ { ALGO_NOP, 4, 4, BLOCK_4x4 },
+ { ALGO_RGB24H, 4, 4, BLOCK_4x4 },
+ { ALGO_NOP, 4, 2, BLOCK_4x2 },
+ { ALGO_RGB24H, 4, 2, BLOCK_4x2 },
+
+ { ALGO_NOP, 2, 4, BLOCK_2x4 },
+ { ALGO_RGB24H, 2, 4, BLOCK_2x4 },
+ { ALGO_NOP, 2, 2, BLOCK_2x2 },
+ { ALGO_RGB24H, 2, 2, BLOCK_2x2 }
+};
+
+static void select_delta_tables(TrueMotion1Context *s, int delta_table_index)
+{
+ int i;
+
+ if (delta_table_index > 3)
+ return;
+
+ memcpy(s->ydt, ydts[delta_table_index], 8 * sizeof(int16_t));
+ memcpy(s->cdt, cdts[delta_table_index], 8 * sizeof(int16_t));
+ memcpy(s->fat_ydt, fat_ydts[delta_table_index], 8 * sizeof(int16_t));
+ memcpy(s->fat_cdt, fat_cdts[delta_table_index], 8 * sizeof(int16_t));
+
+ /* Y skinny deltas need to be halved for some reason; maybe the
+ * skinny Y deltas should be modified */
+ for (i = 0; i < 8; i++)
+ {
+ /* drop the lsb before dividing by 2-- net effect: round down
+ * when dividing a negative number (e.g., -3/2 = -2, not -1) */
+ s->ydt[i] &= 0xFFFE;
+ s->ydt[i] /= 2;
+ }
+}
+
+#ifdef WORDS_BIGENDIAN
+static int make_ydt15_entry(int p2, int p1, int16_t *ydt)
+#else
+static int make_ydt15_entry(int p1, int p2, int16_t *ydt)
+#endif
+{
+ int lo, hi;
+
+ lo = ydt[p1];
+ lo += (lo << 5) + (lo << 10);
+ hi = ydt[p2];
+ hi += (hi << 5) + (hi << 10);
+ return ((lo + (hi << 16)) << 1);
+}
+
+#ifdef WORDS_BIGENDIAN
+static int make_cdt15_entry(int p2, int p1, int16_t *cdt)
+#else
+static int make_cdt15_entry(int p1, int p2, int16_t *cdt)
+#endif
+{
+ int r, b, lo;
+
+ b = cdt[p2];
+ r = cdt[p1] << 10;
+ lo = b + r;
+ return ((lo + (lo << 16)) << 1);
+}
+
+#ifdef WORDS_BIGENDIAN
+static int make_ydt16_entry(int p2, int p1, int16_t *ydt)
+#else
+static int make_ydt16_entry(int p1, int p2, int16_t *ydt)
+#endif
+{
+ int lo, hi;
+
+ lo = ydt[p1];
+ lo += (lo << 6) + (lo << 11);
+ hi = ydt[p2];
+ hi += (hi << 6) + (hi << 11);
+ return ((lo + (hi << 16)) << 1);
+}
+
+#ifdef WORDS_BIGENDIAN
+static int make_cdt16_entry(int p2, int p1, int16_t *cdt)
+#else
+static int make_cdt16_entry(int p1, int p2, int16_t *cdt)
+#endif
+{
+ int r, b, lo;
+
+ b = cdt[p2];
+ r = cdt[p1] << 11;
+ lo = b + r;
+ return ((lo + (lo << 16)) << 1);
+}
+
+#ifdef WORDS_BIGENDIAN
+static int make_ydt24_entry(int p2, int p1, int16_t *ydt)
+#else
+static int make_ydt24_entry(int p1, int p2, int16_t *ydt)
+#endif
+{
+ int lo, hi;
+
+ lo = ydt[p1];
+ hi = ydt[p2];
+ return ((lo + (hi << 8) + (hi << 16)) << 1);
+}
+
+#ifdef WORDS_BIGENDIAN
+static int make_cdt24_entry(int p2, int p1, int16_t *cdt)
+#else
+static int make_cdt24_entry(int p1, int p2, int16_t *cdt)
+#endif
+{
+ int r, b;
+
+ b = cdt[p2];
+ r = cdt[p1]<<16;
+ return ((b+r) << 1);
+}
+
+static void gen_vector_table15(TrueMotion1Context *s, const uint8_t *sel_vector_table)
+{
+ int len, i, j;
+ unsigned char delta_pair;
+
+ for (i = 0; i < 1024; i += 4)
+ {
+ len = *sel_vector_table++ / 2;
+ for (j = 0; j < len; j++)
+ {
+ delta_pair = *sel_vector_table++;
+ s->y_predictor_table[i+j] = 0xfffffffe &
+ make_ydt15_entry(delta_pair >> 4, delta_pair & 0xf, s->ydt);
+ s->c_predictor_table[i+j] = 0xfffffffe &
+ make_cdt15_entry(delta_pair >> 4, delta_pair & 0xf, s->cdt);
+ }
+ s->y_predictor_table[i+(j-1)] |= 1;
+ s->c_predictor_table[i+(j-1)] |= 1;
+ }
+}
+
+static void gen_vector_table16(TrueMotion1Context *s, const uint8_t *sel_vector_table)
+{
+ int len, i, j;
+ unsigned char delta_pair;
+
+ for (i = 0; i < 1024; i += 4)
+ {
+ len = *sel_vector_table++ / 2;
+ for (j = 0; j < len; j++)
+ {
+ delta_pair = *sel_vector_table++;
+ s->y_predictor_table[i+j] = 0xfffffffe &
+ make_ydt16_entry(delta_pair >> 4, delta_pair & 0xf, s->ydt);
+ s->c_predictor_table[i+j] = 0xfffffffe &
+ make_cdt16_entry(delta_pair >> 4, delta_pair & 0xf, s->cdt);
+ }
+ s->y_predictor_table[i+(j-1)] |= 1;
+ s->c_predictor_table[i+(j-1)] |= 1;
+ }
+}
+
+static void gen_vector_table24(TrueMotion1Context *s, const uint8_t *sel_vector_table)
+{
+ int len, i, j;
+ unsigned char delta_pair;
+
+ for (i = 0; i < 1024; i += 4)
+ {
+ len = *sel_vector_table++ / 2;
+ for (j = 0; j < len; j++)
+ {
+ delta_pair = *sel_vector_table++;
+ s->y_predictor_table[i+j] = 0xfffffffe &
+ make_ydt24_entry(delta_pair >> 4, delta_pair & 0xf, s->ydt);
+ s->c_predictor_table[i+j] = 0xfffffffe &
+ make_cdt24_entry(delta_pair >> 4, delta_pair & 0xf, s->cdt);
+ s->fat_y_predictor_table[i+j] = 0xfffffffe &
+ make_ydt24_entry(delta_pair >> 4, delta_pair & 0xf, s->fat_ydt);
+ s->fat_c_predictor_table[i+j] = 0xfffffffe &
+ make_cdt24_entry(delta_pair >> 4, delta_pair & 0xf, s->fat_cdt);
+ }
+ s->y_predictor_table[i+(j-1)] |= 1;
+ s->c_predictor_table[i+(j-1)] |= 1;
+ s->fat_y_predictor_table[i+(j-1)] |= 1;
+ s->fat_c_predictor_table[i+(j-1)] |= 1;
+ }
+}
+
+/* Returns the number of bytes consumed from the bytestream. Returns -1 if
+ * there was an error while decoding the header */
+static int truemotion1_decode_header(TrueMotion1Context *s)
+{
+ int i;
+ struct frame_header header;
+ uint8_t header_buffer[128]; /* logical maximum size of the header */
+ const uint8_t *sel_vector_table;
+
+ /* There is 1 change bit per 4 pixels, so each change byte represents
+ * 32 pixels; divide width by 4 to obtain the number of change bits and
+ * then round up to the nearest byte. */
+ s->mb_change_bits_row_size = ((s->avctx->width >> 2) + 7) >> 3;
+
+ header.header_size = ((s->buf[0] >> 5) | (s->buf[0] << 3)) & 0x7f;
+ if (s->buf[0] < 0x10)
+ {
+ av_log(s->avctx, AV_LOG_ERROR, "invalid header size (%d)\n", s->buf[0]);
+ return -1;
+ }
+
+ /* unscramble the header bytes with a XOR operation */
+ memset(header_buffer, 0, 128);
+ for (i = 1; i < header.header_size; i++)
+ header_buffer[i - 1] = s->buf[i] ^ s->buf[i + 1];
+
+ header.compression = header_buffer[0];
+ header.deltaset = header_buffer[1];
+ header.vectable = header_buffer[2];
+ header.ysize = AV_RL16(&header_buffer[3]);
+ header.xsize = AV_RL16(&header_buffer[5]);
+ header.checksum = AV_RL16(&header_buffer[7]);
+ header.version = header_buffer[9];
+ header.header_type = header_buffer[10];
+ header.flags = header_buffer[11];
+ header.control = header_buffer[12];
+
+ /* Version 2 */
+ if (header.version >= 2)
+ {
+ if (header.header_type > 3)
+ {
+ av_log(s->avctx, AV_LOG_ERROR, "invalid header type (%d)\n", header.header_type);
+ return -1;
+ } else if ((header.header_type == 2) || (header.header_type == 3)) {
+ s->flags = header.flags;
+ if (!(s->flags & FLAG_INTERFRAME))
+ s->flags |= FLAG_KEYFRAME;
+ } else
+ s->flags = FLAG_KEYFRAME;
+ } else /* Version 1 */
+ s->flags = FLAG_KEYFRAME;
+
+ if (s->flags & FLAG_SPRITE) {
+ av_log(s->avctx, AV_LOG_INFO, "SPRITE frame found, please report the sample to the developers\n");
+ /* FIXME header.width, height, xoffset and yoffset aren't initialized */
+#if 0
+ s->w = header.width;
+ s->h = header.height;
+ s->x = header.xoffset;
+ s->y = header.yoffset;
+#else
+ return -1;
+#endif
+ } else {
+ s->w = header.xsize;
+ s->h = header.ysize;
+ if (header.header_type < 2) {
+ if ((s->w < 213) && (s->h >= 176))
+ {
+ s->flags |= FLAG_INTERPOLATED;
+ av_log(s->avctx, AV_LOG_INFO, "INTERPOLATION selected, please report the sample to the developers\n");
+ }
+ }
+ }
+
+ if (header.compression > 17) {
+ av_log(s->avctx, AV_LOG_ERROR, "invalid compression type (%d)\n", header.compression);
+ return -1;
+ }
+
+ if ((header.deltaset != s->last_deltaset) ||
+ (header.vectable != s->last_vectable))
+ select_delta_tables(s, header.deltaset);
+
+ if ((header.compression & 1) && header.header_type)
+ sel_vector_table = pc_tbl2;
+ else {
+ if (header.vectable < 4)
+ sel_vector_table = tables[header.vectable - 1];
+ else {
+ av_log(s->avctx, AV_LOG_ERROR, "invalid vector table id (%d)\n", header.vectable);
+ return -1;
+ }
+ }
+
+ // FIXME: where to place this ?!?!
+ if (compression_types[header.compression].algorithm == ALGO_RGB24H)
+ s->avctx->pix_fmt = PIX_FMT_RGB32;
+ else
+ s->avctx->pix_fmt = PIX_FMT_RGB555; // RGB565 is supported as well
+
+ if ((header.deltaset != s->last_deltaset) || (header.vectable != s->last_vectable))
+ {
+ if (compression_types[header.compression].algorithm == ALGO_RGB24H)
+ gen_vector_table24(s, sel_vector_table);
+ else
+ if (s->avctx->pix_fmt == PIX_FMT_RGB555)
+ gen_vector_table15(s, sel_vector_table);
+ else
+ gen_vector_table16(s, sel_vector_table);
+ }
+
+ /* set up pointers to the other key data chunks */
+ s->mb_change_bits = s->buf + header.header_size;
+ if (s->flags & FLAG_KEYFRAME) {
+ /* no change bits specified for a keyframe; only index bytes */
+ s->index_stream = s->mb_change_bits;
+ } else {
+ /* one change bit per 4x4 block */
+ s->index_stream = s->mb_change_bits +
+ (s->mb_change_bits_row_size * (s->avctx->height >> 2));
+ }
+ s->index_stream_size = s->size - (s->index_stream - s->buf);
+
+ s->last_deltaset = header.deltaset;
+ s->last_vectable = header.vectable;
+ s->compression = header.compression;
+ s->block_width = compression_types[header.compression].block_width;
+ s->block_height = compression_types[header.compression].block_height;
+ s->block_type = compression_types[header.compression].block_type;
+
+ if (s->avctx->debug & FF_DEBUG_PICT_INFO)
+ av_log(s->avctx, AV_LOG_INFO, "tables: %d / %d c:%d %dx%d t:%d %s%s%s%s\n",
+ s->last_deltaset, s->last_vectable, s->compression, s->block_width,
+ s->block_height, s->block_type,
+ s->flags & FLAG_KEYFRAME ? " KEY" : "",
+ s->flags & FLAG_INTERFRAME ? " INTER" : "",
+ s->flags & FLAG_SPRITE ? " SPRITE" : "",
+ s->flags & FLAG_INTERPOLATED ? " INTERPOL" : "");
+
+ return header.header_size;
+}
+
+static int truemotion1_decode_init(AVCodecContext *avctx)
+{
+ TrueMotion1Context *s = (TrueMotion1Context *)avctx->priv_data;
+
+ s->avctx = avctx;
+
+ // FIXME: it may change ?
+// if (avctx->bits_per_sample == 24)
+// avctx->pix_fmt = PIX_FMT_RGB24;
+// else
+// avctx->pix_fmt = PIX_FMT_RGB555;
+
+ avctx->has_b_frames = 0;
+ s->frame.data[0] = s->prev_frame.data[0] = NULL;
+
+ /* there is a vertical predictor for each pixel in a line; each vertical
+ * predictor is 0 to start with */
+ s->vert_pred =
+ (unsigned int *)av_malloc(s->avctx->width * sizeof(unsigned int));
+
+ return 0;
+}
+
+/*
+Block decoding order:
+
+dxi: Y-Y
+dxic: Y-C-Y
+dxic2: Y-C-Y-C
+
+hres,vres,i,i%vres (0 < i < 4)
+2x2 0: 0 dxic2
+2x2 1: 1 dxi
+2x2 2: 0 dxic2
+2x2 3: 1 dxi
+2x4 0: 0 dxic2
+2x4 1: 1 dxi
+2x4 2: 2 dxi
+2x4 3: 3 dxi
+4x2 0: 0 dxic
+4x2 1: 1 dxi
+4x2 2: 0 dxic
+4x2 3: 1 dxi
+4x4 0: 0 dxic
+4x4 1: 1 dxi
+4x4 2: 2 dxi
+4x4 3: 3 dxi
+*/
+
+#define GET_NEXT_INDEX() \
+{\
+ if (index_stream_index >= s->index_stream_size) { \
+ av_log(s->avctx, AV_LOG_INFO, " help! truemotion1 decoder went out of bounds\n"); \
+ return; \
+ } \
+ index = s->index_stream[index_stream_index++] * 4; \
+}
+
+#define APPLY_C_PREDICTOR() \
+ predictor_pair = s->c_predictor_table[index]; \
+ horiz_pred += (predictor_pair >> 1); \
+ if (predictor_pair & 1) { \
+ GET_NEXT_INDEX() \
+ if (!index) { \
+ GET_NEXT_INDEX() \
+ predictor_pair = s->c_predictor_table[index]; \
+ horiz_pred += ((predictor_pair >> 1) * 5); \
+ if (predictor_pair & 1) \
+ GET_NEXT_INDEX() \
+ else \
+ index++; \
+ } \
+ } else \
+ index++;
+
+#define APPLY_C_PREDICTOR_24() \
+ predictor_pair = s->c_predictor_table[index]; \
+ horiz_pred += (predictor_pair >> 1); \
+ if (predictor_pair & 1) { \
+ GET_NEXT_INDEX() \
+ if (!index) { \
+ GET_NEXT_INDEX() \
+ predictor_pair = s->fat_c_predictor_table[index]; \
+ horiz_pred += (predictor_pair >> 1); \
+ if (predictor_pair & 1) \
+ GET_NEXT_INDEX() \
+ else \
+ index++; \
+ } \
+ } else \
+ index++;
+
+
+#define APPLY_Y_PREDICTOR() \
+ predictor_pair = s->y_predictor_table[index]; \
+ horiz_pred += (predictor_pair >> 1); \
+ if (predictor_pair & 1) { \
+ GET_NEXT_INDEX() \
+ if (!index) { \
+ GET_NEXT_INDEX() \
+ predictor_pair = s->y_predictor_table[index]; \
+ horiz_pred += ((predictor_pair >> 1) * 5); \
+ if (predictor_pair & 1) \
+ GET_NEXT_INDEX() \
+ else \
+ index++; \
+ } \
+ } else \
+ index++;
+
+#define APPLY_Y_PREDICTOR_24() \
+ predictor_pair = s->y_predictor_table[index]; \
+ horiz_pred += (predictor_pair >> 1); \
+ if (predictor_pair & 1) { \
+ GET_NEXT_INDEX() \
+ if (!index) { \
+ GET_NEXT_INDEX() \
+ predictor_pair = s->fat_y_predictor_table[index]; \
+ horiz_pred += (predictor_pair >> 1); \
+ if (predictor_pair & 1) \
+ GET_NEXT_INDEX() \
+ else \
+ index++; \
+ } \
+ } else \
+ index++;
+
+#define OUTPUT_PIXEL_PAIR() \
+ *current_pixel_pair = *vert_pred + horiz_pred; \
+ *vert_pred++ = *current_pixel_pair++; \
+ prev_pixel_pair++;
+
+static void truemotion1_decode_16bit(TrueMotion1Context *s)
+{
+ int y;
+ int pixels_left; /* remaining pixels on this line */
+ unsigned int predictor_pair;
+ unsigned int horiz_pred;
+ unsigned int *vert_pred;
+ unsigned int *current_pixel_pair;
+ unsigned int *prev_pixel_pair;
+ unsigned char *current_line = s->frame.data[0];
+ unsigned char *prev_line = s->prev_frame.data[0];
+ int keyframe = s->flags & FLAG_KEYFRAME;
+
+ /* these variables are for managing the stream of macroblock change bits */
+ unsigned char *mb_change_bits = s->mb_change_bits;
+ unsigned char mb_change_byte;
+ unsigned char mb_change_byte_mask;
+ int mb_change_index;
+
+ /* these variables are for managing the main index stream */
+ int index_stream_index = 0; /* yes, the index into the index stream */
+ int index;
+
+ /* clean out the line buffer */
+ memset(s->vert_pred, 0, s->avctx->width * sizeof(unsigned int));
+
+ GET_NEXT_INDEX();
+
+ for (y = 0; y < s->avctx->height; y++) {
+
+ /* re-init variables for the next line iteration */
+ horiz_pred = 0;
+ current_pixel_pair = (unsigned int *)current_line;
+ prev_pixel_pair = (unsigned int *)prev_line;
+ vert_pred = s->vert_pred;
+ mb_change_index = 0;
+ mb_change_byte = mb_change_bits[mb_change_index++];
+ mb_change_byte_mask = 0x01;
+ pixels_left = s->avctx->width;
+
+ while (pixels_left > 0) {
+
+ if (keyframe || ((mb_change_byte & mb_change_byte_mask) == 0)) {
+
+ switch (y & 3) {
+ case 0:
+ /* if macroblock width is 2, apply C-Y-C-Y; else
+ * apply C-Y-Y */
+ if (s->block_width == 2) {
+ APPLY_C_PREDICTOR();
+ APPLY_Y_PREDICTOR();
+ OUTPUT_PIXEL_PAIR();
+ APPLY_C_PREDICTOR();
+ APPLY_Y_PREDICTOR();
+ OUTPUT_PIXEL_PAIR();
+ } else {
+ APPLY_C_PREDICTOR();
+ APPLY_Y_PREDICTOR();
+ OUTPUT_PIXEL_PAIR();
+ APPLY_Y_PREDICTOR();
+ OUTPUT_PIXEL_PAIR();
+ }
+ break;
+
+ case 1:
+ case 3:
+ /* always apply 2 Y predictors on these iterations */
+ APPLY_Y_PREDICTOR();
+ OUTPUT_PIXEL_PAIR();
+ APPLY_Y_PREDICTOR();
+ OUTPUT_PIXEL_PAIR();
+ break;
+
+ case 2:
+ /* this iteration might be C-Y-C-Y, Y-Y, or C-Y-Y
+ * depending on the macroblock type */
+ if (s->block_type == BLOCK_2x2) {
+ APPLY_C_PREDICTOR();
+ APPLY_Y_PREDICTOR();
+ OUTPUT_PIXEL_PAIR();
+ APPLY_C_PREDICTOR();
+ APPLY_Y_PREDICTOR();
+ OUTPUT_PIXEL_PAIR();
+ } else if (s->block_type == BLOCK_4x2) {
+ APPLY_C_PREDICTOR();
+ APPLY_Y_PREDICTOR();
+ OUTPUT_PIXEL_PAIR();
+ APPLY_Y_PREDICTOR();
+ OUTPUT_PIXEL_PAIR();
+ } else {
+ APPLY_Y_PREDICTOR();
+ OUTPUT_PIXEL_PAIR();
+ APPLY_Y_PREDICTOR();
+ OUTPUT_PIXEL_PAIR();
+ }
+ break;
+ }
+
+ } else {
+
+ /* skip (copy) four pixels, but reassign the horizontal
+ * predictor */
+ *current_pixel_pair = *prev_pixel_pair++;
+ *vert_pred++ = *current_pixel_pair++;
+ *current_pixel_pair = *prev_pixel_pair++;
+ horiz_pred = *current_pixel_pair - *vert_pred;
+ *vert_pred++ = *current_pixel_pair++;
+
+ }
+
+ if (!keyframe) {
+ mb_change_byte_mask <<= 1;
+
+ /* next byte */
+ if (!mb_change_byte_mask) {
+ mb_change_byte = mb_change_bits[mb_change_index++];
+ mb_change_byte_mask = 0x01;
+ }
+ }
+
+ pixels_left -= 4;
+ }
+
+ /* next change row */
+ if (((y + 1) & 3) == 0)
+ mb_change_bits += s->mb_change_bits_row_size;
+
+ current_line += s->frame.linesize[0];
+ prev_line += s->prev_frame.linesize[0];
+ }
+}
+
+static void truemotion1_decode_24bit(TrueMotion1Context *s)
+{
+ int y;
+ int pixels_left; /* remaining pixels on this line */
+ unsigned int predictor_pair;
+ unsigned int horiz_pred;
+ unsigned int *vert_pred;
+ unsigned int *current_pixel_pair;
+ unsigned int *prev_pixel_pair;
+ unsigned char *current_line = s->frame.data[0];
+ unsigned char *prev_line = s->prev_frame.data[0];
+ int keyframe = s->flags & FLAG_KEYFRAME;
+
+ /* these variables are for managing the stream of macroblock change bits */
+ unsigned char *mb_change_bits = s->mb_change_bits;
+ unsigned char mb_change_byte;
+ unsigned char mb_change_byte_mask;
+ int mb_change_index;
+
+ /* these variables are for managing the main index stream */
+ int index_stream_index = 0; /* yes, the index into the index stream */
+ int index;
+
+ /* clean out the line buffer */
+ memset(s->vert_pred, 0, s->avctx->width * sizeof(unsigned int));
+
+ GET_NEXT_INDEX();
+
+ for (y = 0; y < s->avctx->height; y++) {
+
+ /* re-init variables for the next line iteration */
+ horiz_pred = 0;
+ current_pixel_pair = (unsigned int *)current_line;
+ prev_pixel_pair = (unsigned int *)prev_line;
+ vert_pred = s->vert_pred;
+ mb_change_index = 0;
+ mb_change_byte = mb_change_bits[mb_change_index++];
+ mb_change_byte_mask = 0x01;
+ pixels_left = s->avctx->width;
+
+ while (pixels_left > 0) {
+
+ if (keyframe || ((mb_change_byte & mb_change_byte_mask) == 0)) {
+
+ switch (y & 3) {
+ case 0:
+ /* if macroblock width is 2, apply C-Y-C-Y; else
+ * apply C-Y-Y */
+ if (s->block_width == 2) {
+ APPLY_C_PREDICTOR_24();
+ APPLY_Y_PREDICTOR_24();
+ OUTPUT_PIXEL_PAIR();
+ APPLY_C_PREDICTOR_24();
+ APPLY_Y_PREDICTOR_24();
+ OUTPUT_PIXEL_PAIR();
+ } else {
+ APPLY_C_PREDICTOR_24();
+ APPLY_Y_PREDICTOR_24();
+ OUTPUT_PIXEL_PAIR();
+ APPLY_Y_PREDICTOR_24();
+ OUTPUT_PIXEL_PAIR();
+ }
+ break;
+
+ case 1:
+ case 3:
+ /* always apply 2 Y predictors on these iterations */
+ APPLY_Y_PREDICTOR_24();
+ OUTPUT_PIXEL_PAIR();
+ APPLY_Y_PREDICTOR_24();
+ OUTPUT_PIXEL_PAIR();
+ break;
+
+ case 2:
+ /* this iteration might be C-Y-C-Y, Y-Y, or C-Y-Y
+ * depending on the macroblock type */
+ if (s->block_type == BLOCK_2x2) {
+ APPLY_C_PREDICTOR_24();
+ APPLY_Y_PREDICTOR_24();
+ OUTPUT_PIXEL_PAIR();
+ APPLY_C_PREDICTOR_24();
+ APPLY_Y_PREDICTOR_24();
+ OUTPUT_PIXEL_PAIR();
+ } else if (s->block_type == BLOCK_4x2) {
+ APPLY_C_PREDICTOR_24();
+ APPLY_Y_PREDICTOR_24();
+ OUTPUT_PIXEL_PAIR();
+ APPLY_Y_PREDICTOR_24();
+ OUTPUT_PIXEL_PAIR();
+ } else {
+ APPLY_Y_PREDICTOR_24();
+ OUTPUT_PIXEL_PAIR();
+ APPLY_Y_PREDICTOR_24();
+ OUTPUT_PIXEL_PAIR();
+ }
+ break;
+ }
+
+ } else {
+
+ /* skip (copy) four pixels, but reassign the horizontal
+ * predictor */
+ *current_pixel_pair = *prev_pixel_pair++;
+ *vert_pred++ = *current_pixel_pair++;
+ *current_pixel_pair = *prev_pixel_pair++;
+ horiz_pred = *current_pixel_pair - *vert_pred;
+ *vert_pred++ = *current_pixel_pair++;
+
+ }
+
+ if (!keyframe) {
+ mb_change_byte_mask <<= 1;
+
+ /* next byte */
+ if (!mb_change_byte_mask) {
+ mb_change_byte = mb_change_bits[mb_change_index++];
+ mb_change_byte_mask = 0x01;
+ }
+ }
+
+ pixels_left -= 4;
+ }
+
+ /* next change row */
+ if (((y + 1) & 3) == 0)
+ mb_change_bits += s->mb_change_bits_row_size;
+
+ current_line += s->frame.linesize[0];
+ prev_line += s->prev_frame.linesize[0];
+ }
+}
+
+
+static int truemotion1_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ TrueMotion1Context *s = (TrueMotion1Context *)avctx->priv_data;
+
+ s->buf = buf;
+ s->size = buf_size;
+
+ if (truemotion1_decode_header(s) == -1)
+ return -1;
+
+ s->frame.reference = 1;
+ if (avctx->get_buffer(avctx, &s->frame) < 0) {
+ av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ return -1;
+ }
+
+ /* check for a do-nothing frame and copy the previous frame */
+ if (compression_types[s->compression].algorithm == ALGO_NOP)
+ {
+ memcpy(s->frame.data[0], s->prev_frame.data[0],
+ s->frame.linesize[0] * s->avctx->height);
+ } else if (compression_types[s->compression].algorithm == ALGO_RGB24H) {
+ truemotion1_decode_24bit(s);
+ } else {
+ truemotion1_decode_16bit(s);
+ }
+
+ if (s->prev_frame.data[0])
+ avctx->release_buffer(avctx, &s->prev_frame);
+
+ /* shuffle frames */
+ s->prev_frame = s->frame;
+
+ *data_size = sizeof(AVFrame);
+ *(AVFrame*)data = s->frame;
+
+ /* report that the buffer was completely consumed */
+ return buf_size;
+}
+
+static int truemotion1_decode_end(AVCodecContext *avctx)
+{
+ TrueMotion1Context *s = (TrueMotion1Context *)avctx->priv_data;
+
+ /* release the last frame */
+ if (s->prev_frame.data[0])
+ avctx->release_buffer(avctx, &s->prev_frame);
+
+ av_free(s->vert_pred);
+
+ return 0;
+}
+
+AVCodec truemotion1_decoder = {
+ "truemotion1",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_TRUEMOTION1,
+ sizeof(TrueMotion1Context),
+ truemotion1_decode_init,
+ NULL,
+ truemotion1_decode_end,
+ truemotion1_decode_frame,
+ CODEC_CAP_DR1,
+};
diff --git a/src/libffmpeg/libavcodec/truemotion1data.h b/contrib/ffmpeg/libavcodec/truemotion1data.h
index 63d307c65..63d307c65 100644
--- a/src/libffmpeg/libavcodec/truemotion1data.h
+++ b/contrib/ffmpeg/libavcodec/truemotion1data.h
diff --git a/contrib/ffmpeg/libavcodec/truemotion2.c b/contrib/ffmpeg/libavcodec/truemotion2.c
new file mode 100644
index 000000000..b282c967b
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/truemotion2.c
@@ -0,0 +1,892 @@
+/*
+ * Duck/ON2 TrueMotion 2 Decoder
+ * Copyright (c) 2005 Konstantin Shishkov
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * @file truemotion2.c
+ * Duck TrueMotion2 decoder.
+ */
+
+#include "avcodec.h"
+#include "common.h"
+#include "bitstream.h"
+#include "dsputil.h"
+
+#define TM2_ESCAPE 0x80000000
+#define TM2_DELTAS 64
+/* Huffman-coded streams of different types of blocks */
+enum TM2_STREAMS{ TM2_C_HI = 0, TM2_C_LO, TM2_L_HI, TM2_L_LO,
+ TM2_UPD, TM2_MOT, TM2_TYPE, TM2_NUM_STREAMS};
+/* Block types */
+enum TM2_BLOCKS{ TM2_HI_RES = 0, TM2_MED_RES, TM2_LOW_RES, TM2_NULL_RES,
+ TM2_UPDATE, TM2_STILL, TM2_MOTION};
+
+typedef struct TM2Context{
+ AVCodecContext *avctx;
+ AVFrame pic;
+
+ GetBitContext gb;
+ DSPContext dsp;
+
+ /* TM2 streams */
+ int *tokens[TM2_NUM_STREAMS];
+ int tok_lens[TM2_NUM_STREAMS];
+ int tok_ptrs[TM2_NUM_STREAMS];
+ int deltas[TM2_NUM_STREAMS][TM2_DELTAS];
+ /* for blocks decoding */
+ int D[4];
+ int CD[4];
+ int *last;
+ int *clast;
+
+ /* data for current and previous frame */
+ int *Y1, *U1, *V1, *Y2, *U2, *V2;
+ int cur;
+} TM2Context;
+
+/**
+* Huffman codes for each of streams
+*/
+typedef struct TM2Codes{
+ VLC vlc; ///< table for FFmpeg bitstream reader
+ int bits;
+ int *recode; ///< table for converting from code indexes to values
+ int length;
+} TM2Codes;
+
+/**
+* structure for gathering Huffman codes information
+*/
+typedef struct TM2Huff{
+ int val_bits; ///< length of literal
+ int max_bits; ///< maximum length of code
+ int min_bits; ///< minimum length of code
+ int nodes; ///< total number of nodes in tree
+ int num; ///< current number filled
+ int max_num; ///< total number of codes
+ int *nums; ///< literals
+ uint32_t *bits; ///< codes
+ int *lens; ///< codelengths
+} TM2Huff;
+
+static int tm2_read_tree(TM2Context *ctx, uint32_t prefix, int length, TM2Huff *huff)
+{
+ if(length > huff->max_bits) {
+ av_log(ctx->avctx, AV_LOG_ERROR, "Tree exceeded its given depth (%i)\n", huff->max_bits);
+ return -1;
+ }
+
+ if(!get_bits1(&ctx->gb)) { /* literal */
+ if (length == 0) {
+ length = 1;
+ }
+ if(huff->num >= huff->max_num) {
+ av_log(ctx->avctx, AV_LOG_DEBUG, "Too many literals\n");
+ return -1;
+ }
+ huff->nums[huff->num] = get_bits_long(&ctx->gb, huff->val_bits);
+ huff->bits[huff->num] = prefix;
+ huff->lens[huff->num] = length;
+ huff->num++;
+ return 0;
+ } else { /* non-terminal node */
+ if(tm2_read_tree(ctx, prefix << 1, length + 1, huff) == -1)
+ return -1;
+ if(tm2_read_tree(ctx, (prefix << 1) | 1, length + 1, huff) == -1)
+ return -1;
+ }
+ return 0;
+}
+
+static int tm2_build_huff_table(TM2Context *ctx, TM2Codes *code)
+{
+ TM2Huff huff;
+ int res = 0;
+
+ huff.val_bits = get_bits(&ctx->gb, 5);
+ huff.max_bits = get_bits(&ctx->gb, 5);
+ huff.min_bits = get_bits(&ctx->gb, 5);
+ huff.nodes = get_bits_long(&ctx->gb, 17);
+ huff.num = 0;
+
+ /* check for correct codes parameters */
+ if((huff.val_bits < 1) || (huff.val_bits > 32) ||
+ (huff.max_bits < 0) || (huff.max_bits > 32)) {
+ av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect tree parameters - literal length: %i, max code length: %i\n",
+ huff.val_bits, huff.max_bits);
+ return -1;
+ }
+ if((huff.nodes < 0) || (huff.nodes > 0x10000)) {
+ av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect number of Huffman tree nodes: %i\n", huff.nodes);
+ return -1;
+ }
+ /* one-node tree */
+ if(huff.max_bits == 0)
+ huff.max_bits = 1;
+
+ /* allocate space for codes - it is exactly ceil(nodes / 2) entries */
+ huff.max_num = (huff.nodes + 1) >> 1;
+ huff.nums = av_mallocz(huff.max_num * sizeof(int));
+ huff.bits = av_mallocz(huff.max_num * sizeof(uint32_t));
+ huff.lens = av_mallocz(huff.max_num * sizeof(int));
+
+ if(tm2_read_tree(ctx, 0, 0, &huff) == -1)
+ res = -1;
+
+ if(huff.num != huff.max_num) {
+ av_log(ctx->avctx, AV_LOG_ERROR, "Got less codes than expected: %i of %i\n",
+ huff.num, huff.max_num);
+ res = -1;
+ }
+
+ /* convert codes to vlc_table */
+ if(res != -1) {
+ int i;
+
+ res = init_vlc(&code->vlc, huff.max_bits, huff.max_num,
+ huff.lens, sizeof(int), sizeof(int),
+ huff.bits, sizeof(uint32_t), sizeof(uint32_t), 0);
+ if(res < 0) {
+ av_log(ctx->avctx, AV_LOG_ERROR, "Cannot build VLC table\n");
+ res = -1;
+ } else
+ res = 0;
+ if(res != -1) {
+ code->bits = huff.max_bits;
+ code->length = huff.max_num;
+ code->recode = av_malloc(code->length * sizeof(int));
+ for(i = 0; i < code->length; i++)
+ code->recode[i] = huff.nums[i];
+ }
+ }
+ /* free allocated memory */
+ av_free(huff.nums);
+ av_free(huff.bits);
+ av_free(huff.lens);
+
+ return res;
+}
+
+static void tm2_free_codes(TM2Codes *code)
+{
+ if(code->recode)
+ av_free(code->recode);
+ if(code->vlc.table)
+ free_vlc(&code->vlc);
+}
+
+static inline int tm2_get_token(GetBitContext *gb, TM2Codes *code)
+{
+ int val;
+ val = get_vlc2(gb, code->vlc.table, code->bits, 1);
+ return code->recode[val];
+}
+
+static inline int tm2_read_header(TM2Context *ctx, uint8_t *buf)
+{
+ uint32_t magic;
+ uint8_t *obuf;
+ int length;
+
+ obuf = buf;
+
+ magic = AV_RL32(buf);
+ buf += 4;
+
+ if(magic == 0x00000100) { /* old header */
+/* av_log (ctx->avctx, AV_LOG_ERROR, "TM2 old header: not implemented (yet)\n"); */
+ return 40;
+ } else if(magic == 0x00000101) { /* new header */
+ int w, h, size, flags, xr, yr;
+
+ length = AV_RL32(buf);
+ buf += 4;
+
+ init_get_bits(&ctx->gb, buf, 32 * 8);
+ size = get_bits_long(&ctx->gb, 31);
+ h = get_bits(&ctx->gb, 15);
+ w = get_bits(&ctx->gb, 15);
+ flags = get_bits_long(&ctx->gb, 31);
+ yr = get_bits(&ctx->gb, 9);
+ xr = get_bits(&ctx->gb, 9);
+
+ return 40;
+ } else {
+ av_log (ctx->avctx, AV_LOG_ERROR, "Not a TM2 header: 0x%08X\n", magic);
+ return -1;
+ }
+
+ return (buf - obuf);
+}
+
+static int tm2_read_deltas(TM2Context *ctx, int stream_id) {
+ int d, mb;
+ int i, v;
+
+ d = get_bits(&ctx->gb, 9);
+ mb = get_bits(&ctx->gb, 5);
+
+ if((d < 1) || (d > TM2_DELTAS) || (mb < 1) || (mb > 32)) {
+ av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect delta table: %i deltas x %i bits\n", d, mb);
+ return -1;
+ }
+
+ for(i = 0; i < d; i++) {
+ v = get_bits_long(&ctx->gb, mb);
+ if(v & (1 << (mb - 1)))
+ ctx->deltas[stream_id][i] = v - (1 << mb);
+ else
+ ctx->deltas[stream_id][i] = v;
+ }
+ for(; i < TM2_DELTAS; i++)
+ ctx->deltas[stream_id][i] = 0;
+
+ return 0;
+}
+
+static int tm2_read_stream(TM2Context *ctx, uint8_t *buf, int stream_id) {
+ int i;
+ int cur = 0;
+ int skip = 0;
+ int len, toks;
+ TM2Codes codes;
+
+ /* get stream length in dwords */
+ len = AV_RB32(buf); buf += 4; cur += 4;
+ skip = len * 4 + 4;
+
+ if(len == 0)
+ return 4;
+
+ toks = AV_RB32(buf); buf += 4; cur += 4;
+ if(toks & 1) {
+ len = AV_RB32(buf); buf += 4; cur += 4;
+ if(len == TM2_ESCAPE) {
+ len = AV_RB32(buf); buf += 4; cur += 4;
+ }
+ if(len > 0) {
+ init_get_bits(&ctx->gb, buf, (skip - cur) * 8);
+ if(tm2_read_deltas(ctx, stream_id) == -1)
+ return -1;
+ buf += ((get_bits_count(&ctx->gb) + 31) >> 5) << 2;
+ cur += ((get_bits_count(&ctx->gb) + 31) >> 5) << 2;
+ }
+ }
+ /* skip unused fields */
+ if(AV_RB32(buf) == TM2_ESCAPE) {
+ buf += 4; cur += 4; /* some unknown length - could be escaped too */
+ }
+ buf += 4; cur += 4;
+ buf += 4; cur += 4; /* unused by decoder */
+
+ init_get_bits(&ctx->gb, buf, (skip - cur) * 8);
+ if(tm2_build_huff_table(ctx, &codes) == -1)
+ return -1;
+ buf += ((get_bits_count(&ctx->gb) + 31) >> 5) << 2;
+ cur += ((get_bits_count(&ctx->gb) + 31) >> 5) << 2;
+
+ toks >>= 1;
+ /* check if we have sane number of tokens */
+ if((toks < 0) || (toks > 0xFFFFFF)){
+ av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect number of tokens: %i\n", toks);
+ tm2_free_codes(&codes);
+ return -1;
+ }
+ ctx->tokens[stream_id] = av_realloc(ctx->tokens[stream_id], toks * sizeof(int));
+ ctx->tok_lens[stream_id] = toks;
+ len = AV_RB32(buf); buf += 4; cur += 4;
+ if(len > 0) {
+ init_get_bits(&ctx->gb, buf, (skip - cur) * 8);
+ for(i = 0; i < toks; i++)
+ ctx->tokens[stream_id][i] = tm2_get_token(&ctx->gb, &codes);
+ } else {
+ for(i = 0; i < toks; i++)
+ ctx->tokens[stream_id][i] = codes.recode[0];
+ }
+ tm2_free_codes(&codes);
+
+ return skip;
+}
+
+static inline int GET_TOK(TM2Context *ctx,int type) {
+ if(ctx->tok_ptrs[type] >= ctx->tok_lens[type]) {
+ av_log(ctx->avctx, AV_LOG_ERROR, "Read token from stream %i out of bounds (%i>=%i)\n", type, ctx->tok_ptrs[type], ctx->tok_lens[type]);
+ return 0;
+ }
+ if(type <= TM2_MOT)
+ return ctx->deltas[type][ctx->tokens[type][ctx->tok_ptrs[type]++]];
+ return ctx->tokens[type][ctx->tok_ptrs[type]++];
+}
+
+/* blocks decoding routines */
+
+/* common Y, U, V pointers initialisation */
+#define TM2_INIT_POINTERS() \
+ int *last, *clast; \
+ int *Y, *U, *V;\
+ int Ystride, Ustride, Vstride;\
+\
+ Ystride = ctx->avctx->width;\
+ Vstride = (ctx->avctx->width + 1) >> 1;\
+ Ustride = (ctx->avctx->width + 1) >> 1;\
+ Y = (ctx->cur?ctx->Y2:ctx->Y1) + by * 4 * Ystride + bx * 4;\
+ V = (ctx->cur?ctx->V2:ctx->V1) + by * 2 * Vstride + bx * 2;\
+ U = (ctx->cur?ctx->U2:ctx->U1) + by * 2 * Ustride + bx * 2;\
+ last = ctx->last + bx * 4;\
+ clast = ctx->clast + bx * 4;
+
+#define TM2_INIT_POINTERS_2() \
+ int *Yo, *Uo, *Vo;\
+ int oYstride, oUstride, oVstride;\
+\
+ TM2_INIT_POINTERS();\
+ oYstride = Ystride;\
+ oVstride = Vstride;\
+ oUstride = Ustride;\
+ Yo = (ctx->cur?ctx->Y1:ctx->Y2) + by * 4 * oYstride + bx * 4;\
+ Vo = (ctx->cur?ctx->V1:ctx->V2) + by * 2 * oVstride + bx * 2;\
+ Uo = (ctx->cur?ctx->U1:ctx->U2) + by * 2 * oUstride + bx * 2;
+
+/* recalculate last and delta values for next blocks */
+#define TM2_RECALC_BLOCK(CHR, stride, last, CD) {\
+ CD[0] = (CHR[1] - 128) - last[1];\
+ CD[1] = (int)CHR[stride + 1] - (int)CHR[1];\
+ last[0] = (int)CHR[stride + 0] - 128;\
+ last[1] = (int)CHR[stride + 1] - 128;}
+
+/* common operations - add deltas to 4x4 block of luma or 2x2 blocks of chroma */
+static inline void tm2_apply_deltas(TM2Context *ctx, int* Y, int stride, int *deltas, int *last)
+{
+ int ct, d;
+ int i, j;
+
+ for(j = 0; j < 4; j++){
+ ct = ctx->D[j];
+ for(i = 0; i < 4; i++){
+ d = deltas[i + j * 4];
+ ct += d;
+ last[i] += ct;
+ Y[i] = av_clip_uint8(last[i]);
+ }
+ Y += stride;
+ ctx->D[j] = ct;
+ }
+}
+
+static inline void tm2_high_chroma(int *data, int stride, int *last, int *CD, int *deltas)
+{
+ int i, j;
+ for(j = 0; j < 2; j++){
+ for(i = 0; i < 2; i++){
+ CD[j] += deltas[i + j * 2];
+ last[i] += CD[j];
+ data[i] = last[i] + 128;
+ }
+ data += stride;
+ }
+}
+
+static inline void tm2_low_chroma(int *data, int stride, int *clast, int *CD, int *deltas, int bx)
+{
+ int t;
+ int l;
+ int prev;
+
+ if(bx > 0)
+ prev = clast[-3];
+ else
+ prev = 0;
+ t = (CD[0] + CD[1]) >> 1;
+ l = (prev - CD[0] - CD[1] + clast[1]) >> 1;
+ CD[1] = CD[0] + CD[1] - t;
+ CD[0] = t;
+ clast[0] = l;
+
+ tm2_high_chroma(data, stride, clast, CD, deltas);
+}
+
+static inline void tm2_hi_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
+{
+ int i;
+ int deltas[16];
+ TM2_INIT_POINTERS();
+
+ /* hi-res chroma */
+ for(i = 0; i < 4; i++) {
+ deltas[i] = GET_TOK(ctx, TM2_C_HI);
+ deltas[i + 4] = GET_TOK(ctx, TM2_C_HI);
+ }
+ tm2_high_chroma(U, Ustride, clast, ctx->CD, deltas);
+ tm2_high_chroma(V, Vstride, clast + 2, ctx->CD + 2, deltas + 4);
+
+ /* hi-res luma */
+ for(i = 0; i < 16; i++)
+ deltas[i] = GET_TOK(ctx, TM2_L_HI);
+
+ tm2_apply_deltas(ctx, Y, Ystride, deltas, last);
+}
+
+static inline void tm2_med_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
+{
+ int i;
+ int deltas[16];
+ TM2_INIT_POINTERS();
+
+ /* low-res chroma */
+ deltas[0] = GET_TOK(ctx, TM2_C_LO);
+ deltas[1] = deltas[2] = deltas[3] = 0;
+ tm2_low_chroma(U, Ustride, clast, ctx->CD, deltas, bx);
+
+ deltas[0] = GET_TOK(ctx, TM2_C_LO);
+ deltas[1] = deltas[2] = deltas[3] = 0;
+ tm2_low_chroma(V, Vstride, clast + 2, ctx->CD + 2, deltas, bx);
+
+ /* hi-res luma */
+ for(i = 0; i < 16; i++)
+ deltas[i] = GET_TOK(ctx, TM2_L_HI);
+
+ tm2_apply_deltas(ctx, Y, Ystride, deltas, last);
+}
+
+static inline void tm2_low_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
+{
+ int i;
+ int t1, t2;
+ int deltas[16];
+ TM2_INIT_POINTERS();
+
+ /* low-res chroma */
+ deltas[0] = GET_TOK(ctx, TM2_C_LO);
+ deltas[1] = deltas[2] = deltas[3] = 0;
+ tm2_low_chroma(U, Ustride, clast, ctx->CD, deltas, bx);
+
+ deltas[0] = GET_TOK(ctx, TM2_C_LO);
+ deltas[1] = deltas[2] = deltas[3] = 0;
+ tm2_low_chroma(V, Vstride, clast + 2, ctx->CD + 2, deltas, bx);
+
+ /* low-res luma */
+ for(i = 0; i < 16; i++)
+ deltas[i] = 0;
+
+ deltas[ 0] = GET_TOK(ctx, TM2_L_LO);
+ deltas[ 2] = GET_TOK(ctx, TM2_L_LO);
+ deltas[ 8] = GET_TOK(ctx, TM2_L_LO);
+ deltas[10] = GET_TOK(ctx, TM2_L_LO);
+
+ if(bx > 0)
+ last[0] = (last[-1] - ctx->D[0] - ctx->D[1] - ctx->D[2] - ctx->D[3] + last[1]) >> 1;
+ else
+ last[0] = (last[1] - ctx->D[0] - ctx->D[1] - ctx->D[2] - ctx->D[3])>> 1;
+ last[2] = (last[1] + last[3]) >> 1;
+
+ t1 = ctx->D[0] + ctx->D[1];
+ ctx->D[0] = t1 >> 1;
+ ctx->D[1] = t1 - (t1 >> 1);
+ t2 = ctx->D[2] + ctx->D[3];
+ ctx->D[2] = t2 >> 1;
+ ctx->D[3] = t2 - (t2 >> 1);
+
+ tm2_apply_deltas(ctx, Y, Ystride, deltas, last);
+}
+
+static inline void tm2_null_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
+{
+ int i;
+ int ct;
+ int left, right, diff;
+ int deltas[16];
+ TM2_INIT_POINTERS();
+
+ /* null chroma */
+ deltas[0] = deltas[1] = deltas[2] = deltas[3] = 0;
+ tm2_low_chroma(U, Ustride, clast, ctx->CD, deltas, bx);
+
+ deltas[0] = deltas[1] = deltas[2] = deltas[3] = 0;
+ tm2_low_chroma(V, Vstride, clast + 2, ctx->CD + 2, deltas, bx);
+
+ /* null luma */
+ for(i = 0; i < 16; i++)
+ deltas[i] = 0;
+
+ ct = ctx->D[0] + ctx->D[1] + ctx->D[2] + ctx->D[3];
+
+ if(bx > 0)
+ left = last[-1] - ct;
+ else
+ left = 0;
+
+ right = last[3];
+ diff = right - left;
+ last[0] = left + (diff >> 2);
+ last[1] = left + (diff >> 1);
+ last[2] = right - (diff >> 2);
+ last[3] = right;
+ {
+ int tp = left;
+
+ ctx->D[0] = (tp + (ct >> 2)) - left;
+ left += ctx->D[0];
+ ctx->D[1] = (tp + (ct >> 1)) - left;
+ left += ctx->D[1];
+ ctx->D[2] = ((tp + ct) - (ct >> 2)) - left;
+ left += ctx->D[2];
+ ctx->D[3] = (tp + ct) - left;
+ }
+ tm2_apply_deltas(ctx, Y, Ystride, deltas, last);
+}
+
+static inline void tm2_still_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
+{
+ int i, j;
+ TM2_INIT_POINTERS_2();
+
+ /* update chroma */
+ for(j = 0; j < 2; j++){
+ for(i = 0; i < 2; i++){
+ U[i] = Uo[i];
+ V[i] = Vo[i];
+ }
+ U += Ustride; V += Vstride;
+ Uo += oUstride; Vo += oVstride;
+ }
+ U -= Ustride * 2;
+ V -= Vstride * 2;
+ TM2_RECALC_BLOCK(U, Ustride, clast, ctx->CD);
+ TM2_RECALC_BLOCK(V, Vstride, (clast + 2), (ctx->CD + 2));
+
+ /* update deltas */
+ ctx->D[0] = Yo[3] - last[3];
+ ctx->D[1] = Yo[3 + oYstride] - Yo[3];
+ ctx->D[2] = Yo[3 + oYstride * 2] - Yo[3 + oYstride];
+ ctx->D[3] = Yo[3 + oYstride * 3] - Yo[3 + oYstride * 2];
+
+ for(j = 0; j < 4; j++){
+ for(i = 0; i < 4; i++){
+ Y[i] = Yo[i];
+ last[i] = Yo[i];
+ }
+ Y += Ystride;
+ Yo += oYstride;
+ }
+}
+
+static inline void tm2_update_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
+{
+ int i, j;
+ int d;
+ TM2_INIT_POINTERS_2();
+
+ /* update chroma */
+ for(j = 0; j < 2; j++){
+ for(i = 0; i < 2; i++){
+ U[i] = Uo[i] + GET_TOK(ctx, TM2_UPD);
+ V[i] = Vo[i] + GET_TOK(ctx, TM2_UPD);
+ }
+ U += Ustride; V += Vstride;
+ Uo += oUstride; Vo += oVstride;
+ }
+ U -= Ustride * 2;
+ V -= Vstride * 2;
+ TM2_RECALC_BLOCK(U, Ustride, clast, ctx->CD);
+ TM2_RECALC_BLOCK(V, Vstride, (clast + 2), (ctx->CD + 2));
+
+ /* update deltas */
+ ctx->D[0] = Yo[3] - last[3];
+ ctx->D[1] = Yo[3 + oYstride] - Yo[3];
+ ctx->D[2] = Yo[3 + oYstride * 2] - Yo[3 + oYstride];
+ ctx->D[3] = Yo[3 + oYstride * 3] - Yo[3 + oYstride * 2];
+
+ for(j = 0; j < 4; j++){
+ d = last[3];
+ for(i = 0; i < 4; i++){
+ Y[i] = Yo[i] + GET_TOK(ctx, TM2_UPD);
+ last[i] = Y[i];
+ }
+ ctx->D[j] = last[3] - d;
+ Y += Ystride;
+ Yo += oYstride;
+ }
+}
+
+static inline void tm2_motion_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
+{
+ int i, j;
+ int mx, my;
+ TM2_INIT_POINTERS_2();
+
+ mx = GET_TOK(ctx, TM2_MOT);
+ my = GET_TOK(ctx, TM2_MOT);
+
+ Yo += my * oYstride + mx;
+ Uo += (my >> 1) * oUstride + (mx >> 1);
+ Vo += (my >> 1) * oVstride + (mx >> 1);
+
+ /* copy chroma */
+ for(j = 0; j < 2; j++){
+ for(i = 0; i < 2; i++){
+ U[i] = Uo[i];
+ V[i] = Vo[i];
+ }
+ U += Ustride; V += Vstride;
+ Uo += oUstride; Vo += oVstride;
+ }
+ U -= Ustride * 2;
+ V -= Vstride * 2;
+ TM2_RECALC_BLOCK(U, Ustride, clast, ctx->CD);
+ TM2_RECALC_BLOCK(V, Vstride, (clast + 2), (ctx->CD + 2));
+
+ /* copy luma */
+ for(j = 0; j < 4; j++){
+ for(i = 0; i < 4; i++){
+ Y[i] = Yo[i];
+ }
+ Y += Ystride;
+ Yo += oYstride;
+ }
+ /* calculate deltas */
+ Y -= Ystride * 4;
+ ctx->D[0] = Y[3] - last[3];
+ ctx->D[1] = Y[3 + Ystride] - Y[3];
+ ctx->D[2] = Y[3 + Ystride * 2] - Y[3 + Ystride];
+ ctx->D[3] = Y[3 + Ystride * 3] - Y[3 + Ystride * 2];
+ for(i = 0; i < 4; i++)
+ last[i] = Y[i + Ystride * 3];
+}
+
+static int tm2_decode_blocks(TM2Context *ctx, AVFrame *p)
+{
+ int i, j;
+ int bw, bh;
+ int type;
+ int keyframe = 1;
+ uint8_t *Y, *U, *V;
+ int *src;
+
+ bw = ctx->avctx->width >> 2;
+ bh = ctx->avctx->height >> 2;
+
+ for(i = 0; i < TM2_NUM_STREAMS; i++)
+ ctx->tok_ptrs[i] = 0;
+
+ if (ctx->tok_lens[TM2_TYPE]<bw*bh){
+ av_log(ctx->avctx,AV_LOG_ERROR,"Got %i tokens for %i blocks\n",ctx->tok_lens[TM2_TYPE],bw*bh);
+ return -1;
+ }
+
+ memset(ctx->last, 0, 4 * bw * sizeof(int));
+ memset(ctx->clast, 0, 4 * bw * sizeof(int));
+
+ for(j = 0; j < bh; j++) {
+ memset(ctx->D, 0, 4 * sizeof(int));
+ memset(ctx->CD, 0, 4 * sizeof(int));
+ for(i = 0; i < bw; i++) {
+ type = GET_TOK(ctx, TM2_TYPE);
+ switch(type) {
+ case TM2_HI_RES:
+ tm2_hi_res_block(ctx, p, i, j);
+ break;
+ case TM2_MED_RES:
+ tm2_med_res_block(ctx, p, i, j);
+ break;
+ case TM2_LOW_RES:
+ tm2_low_res_block(ctx, p, i, j);
+ break;
+ case TM2_NULL_RES:
+ tm2_null_res_block(ctx, p, i, j);
+ break;
+ case TM2_UPDATE:
+ tm2_update_block(ctx, p, i, j);
+ keyframe = 0;
+ break;
+ case TM2_STILL:
+ tm2_still_block(ctx, p, i, j);
+ keyframe = 0;
+ break;
+ case TM2_MOTION:
+ tm2_motion_block(ctx, p, i, j);
+ keyframe = 0;
+ break;
+ default:
+ av_log(ctx->avctx, AV_LOG_ERROR, "Skipping unknown block type %i\n", type);
+ }
+ }
+ }
+
+ /* copy data from our buffer to AVFrame */
+ Y = p->data[0];
+ src = (ctx->cur?ctx->Y2:ctx->Y1);
+ for(j = 0; j < ctx->avctx->height; j++){
+ for(i = 0; i < ctx->avctx->width; i++){
+ Y[i] = av_clip_uint8(*src++);
+ }
+ Y += p->linesize[0];
+ }
+ U = p->data[2];
+ src = (ctx->cur?ctx->U2:ctx->U1);
+ for(j = 0; j < (ctx->avctx->height + 1) >> 1; j++){
+ for(i = 0; i < (ctx->avctx->width + 1) >> 1; i++){
+ U[i] = av_clip_uint8(*src++);
+ }
+ U += p->linesize[2];
+ }
+ V = p->data[1];
+ src = (ctx->cur?ctx->V2:ctx->V1);
+ for(j = 0; j < (ctx->avctx->height + 1) >> 1; j++){
+ for(i = 0; i < (ctx->avctx->width + 1) >> 1; i++){
+ V[i] = av_clip_uint8(*src++);
+ }
+ V += p->linesize[1];
+ }
+
+ return keyframe;
+}
+
+static int decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ TM2Context * const l = avctx->priv_data;
+ AVFrame * const p= (AVFrame*)&l->pic;
+ int skip, t;
+
+ p->reference = 1;
+ p->buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
+ if(avctx->reget_buffer(avctx, p) < 0){
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ return -1;
+ }
+
+ l->dsp.bswap_buf((uint32_t*)buf, (uint32_t*)buf, buf_size >> 2);
+ skip = tm2_read_header(l, buf);
+
+ if(skip == -1)
+ return -1;
+
+ t = tm2_read_stream(l, buf + skip, TM2_C_HI);
+ if(t == -1)
+ return -1;
+ skip += t;
+ t = tm2_read_stream(l, buf + skip, TM2_C_LO);
+ if(t == -1)
+ return -1;
+ skip += t;
+ t = tm2_read_stream(l, buf + skip, TM2_L_HI);
+ if(t == -1)
+ return -1;
+ skip += t;
+ t = tm2_read_stream(l, buf + skip, TM2_L_LO);
+ if(t == -1)
+ return -1;
+ skip += t;
+ t = tm2_read_stream(l, buf + skip, TM2_UPD);
+ if(t == -1)
+ return -1;
+ skip += t;
+ t = tm2_read_stream(l, buf + skip, TM2_MOT);
+ if(t == -1)
+ return -1;
+ skip += t;
+ t = tm2_read_stream(l, buf + skip, TM2_TYPE);
+ if(t == -1)
+ return -1;
+ p->key_frame = tm2_decode_blocks(l, p);
+ if(p->key_frame)
+ p->pict_type = FF_I_TYPE;
+ else
+ p->pict_type = FF_P_TYPE;
+
+ l->cur = !l->cur;
+ *data_size = sizeof(AVFrame);
+ *(AVFrame*)data = l->pic;
+
+ return buf_size;
+}
+
+static 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;
+ }
+
+ l->avctx = avctx;
+ l->pic.data[0]=NULL;
+ avctx->pix_fmt = PIX_FMT_YUV420P;
+
+ dsputil_init(&l->dsp, avctx);
+
+ l->last = av_malloc(4 * sizeof(int) * (avctx->width >> 2));
+ l->clast = av_malloc(4 * sizeof(int) * (avctx->width >> 2));
+
+ for(i = 0; i < TM2_NUM_STREAMS; i++) {
+ l->tokens[i] = NULL;
+ l->tok_lens[i] = 0;
+ }
+
+ l->Y1 = av_malloc(sizeof(int) * avctx->width * avctx->height);
+ l->U1 = av_malloc(sizeof(int) * ((avctx->width + 1) >> 1) * ((avctx->height + 1) >> 1));
+ l->V1 = av_malloc(sizeof(int) * ((avctx->width + 1) >> 1) * ((avctx->height + 1) >> 1));
+ l->Y2 = av_malloc(sizeof(int) * avctx->width * avctx->height);
+ l->U2 = av_malloc(sizeof(int) * ((avctx->width + 1) >> 1) * ((avctx->height + 1) >> 1));
+ l->V2 = av_malloc(sizeof(int) * ((avctx->width + 1) >> 1) * ((avctx->height + 1) >> 1));
+ l->cur = 0;
+
+ return 0;
+}
+
+static int decode_end(AVCodecContext *avctx){
+ TM2Context * const l = avctx->priv_data;
+ int i;
+
+ if(l->last)
+ av_free(l->last);
+ if(l->clast)
+ av_free(l->clast);
+ for(i = 0; i < TM2_NUM_STREAMS; i++)
+ if(l->tokens[i])
+ av_free(l->tokens[i]);
+ if(l->Y1){
+ av_free(l->Y1);
+ av_free(l->U1);
+ av_free(l->V1);
+ av_free(l->Y2);
+ av_free(l->U2);
+ av_free(l->V2);
+ }
+ return 0;
+}
+
+AVCodec truemotion2_decoder = {
+ "truemotion2",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_TRUEMOTION2,
+ sizeof(TM2Context),
+ decode_init,
+ NULL,
+ decode_end,
+ decode_frame,
+ CODEC_CAP_DR1,
+};
diff --git a/contrib/ffmpeg/libavcodec/truespeech.c b/contrib/ffmpeg/libavcodec/truespeech.c
new file mode 100644
index 000000000..a03f2a0ce
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/truespeech.c
@@ -0,0 +1,381 @@
+/*
+ * DSP Group TrueSpeech compatible decoder
+ * Copyright (c) 2005 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 "truespeech_data.h"
+/**
+ * @file truespeech.c
+ * TrueSpeech decoder.
+ */
+
+/**
+ * TrueSpeech decoder context
+ */
+typedef struct {
+ /* input data */
+ int16_t vector[8]; //< input vector: 5/5/4/4/4/3/3/3
+ int offset1[2]; //< 8-bit value, used in one copying offset
+ int offset2[4]; //< 7-bit value, encodes offsets for copying and for two-point filter
+ int pulseoff[4]; //< 4-bit offset of pulse values block
+ int pulsepos[4]; //< 27-bit variable, encodes 7 pulse positions
+ int pulseval[4]; //< 7x2-bit pulse values
+ int flag; //< 1-bit flag, shows how to choose filters
+ /* temporary data */
+ int filtbuf[146]; // some big vector used for storing filters
+ int prevfilt[8]; // filter from previous frame
+ int16_t tmp1[8]; // coefficients for adding to out
+ int16_t tmp2[8]; // coefficients for adding to out
+ int16_t tmp3[8]; // coefficients for adding to out
+ int16_t cvector[8]; // correlated input vector
+ int filtval; // gain value for one function
+ int16_t newvec[60]; // tmp vector
+ int16_t filters[32]; // filters for every subframe
+} TSContext;
+
+static int truespeech_decode_init(AVCodecContext * avctx)
+{
+// TSContext *c = avctx->priv_data;
+
+ return 0;
+}
+
+static void truespeech_read_frame(TSContext *dec, uint8_t *input)
+{
+ uint32_t t;
+
+ /* first dword */
+ t = AV_RL32(input);
+ input += 4;
+
+ dec->flag = t & 1;
+
+ dec->vector[0] = ts_codebook[0][(t >> 1) & 0x1F];
+ dec->vector[1] = ts_codebook[1][(t >> 6) & 0x1F];
+ dec->vector[2] = ts_codebook[2][(t >> 11) & 0xF];
+ dec->vector[3] = ts_codebook[3][(t >> 15) & 0xF];
+ dec->vector[4] = ts_codebook[4][(t >> 19) & 0xF];
+ dec->vector[5] = ts_codebook[5][(t >> 23) & 0x7];
+ dec->vector[6] = ts_codebook[6][(t >> 26) & 0x7];
+ dec->vector[7] = ts_codebook[7][(t >> 29) & 0x7];
+
+ /* second dword */
+ t = AV_RL32(input);
+ input += 4;
+
+ dec->offset2[0] = (t >> 0) & 0x7F;
+ dec->offset2[1] = (t >> 7) & 0x7F;
+ dec->offset2[2] = (t >> 14) & 0x7F;
+ dec->offset2[3] = (t >> 21) & 0x7F;
+
+ dec->offset1[0] = ((t >> 28) & 0xF) << 4;
+
+ /* third dword */
+ t = AV_RL32(input);
+ input += 4;
+
+ dec->pulseval[0] = (t >> 0) & 0x3FFF;
+ dec->pulseval[1] = (t >> 14) & 0x3FFF;
+
+ dec->offset1[1] = (t >> 28) & 0x0F;
+
+ /* fourth dword */
+ t = AV_RL32(input);
+ input += 4;
+
+ dec->pulseval[2] = (t >> 0) & 0x3FFF;
+ dec->pulseval[3] = (t >> 14) & 0x3FFF;
+
+ dec->offset1[1] |= ((t >> 28) & 0x0F) << 4;
+
+ /* fifth dword */
+ t = AV_RL32(input);
+ input += 4;
+
+ dec->pulsepos[0] = (t >> 4) & 0x7FFFFFF;
+
+ dec->pulseoff[0] = (t >> 0) & 0xF;
+
+ dec->offset1[0] |= (t >> 31) & 1;
+
+ /* sixth dword */
+ t = AV_RL32(input);
+ input += 4;
+
+ dec->pulsepos[1] = (t >> 4) & 0x7FFFFFF;
+
+ dec->pulseoff[1] = (t >> 0) & 0xF;
+
+ dec->offset1[0] |= ((t >> 31) & 1) << 1;
+
+ /* seventh dword */
+ t = AV_RL32(input);
+ input += 4;
+
+ dec->pulsepos[2] = (t >> 4) & 0x7FFFFFF;
+
+ dec->pulseoff[2] = (t >> 0) & 0xF;
+
+ dec->offset1[0] |= ((t >> 31) & 1) << 2;
+
+ /* eighth dword */
+ t = AV_RL32(input);
+ input += 4;
+
+ dec->pulsepos[3] = (t >> 4) & 0x7FFFFFF;
+
+ dec->pulseoff[3] = (t >> 0) & 0xF;
+
+ dec->offset1[0] |= ((t >> 31) & 1) << 3;
+
+}
+
+static void truespeech_correlate_filter(TSContext *dec)
+{
+ int16_t tmp[8];
+ int i, j;
+
+ for(i = 0; i < 8; i++){
+ if(i > 0){
+ memcpy(tmp, dec->cvector, i * 2);
+ for(j = 0; j < i; j++)
+ dec->cvector[j] = ((tmp[i - j - 1] * dec->vector[i]) +
+ (dec->cvector[j] << 15) + 0x4000) >> 15;
+ }
+ dec->cvector[i] = (8 - dec->vector[i]) >> 3;
+ }
+ for(i = 0; i < 8; i++)
+ dec->cvector[i] = (dec->cvector[i] * ts_230[i]) >> 15;
+
+ dec->filtval = dec->vector[0];
+}
+
+static void truespeech_filters_merge(TSContext *dec)
+{
+ int i;
+
+ if(!dec->flag){
+ for(i = 0; i < 8; i++){
+ dec->filters[i + 0] = dec->prevfilt[i];
+ dec->filters[i + 8] = dec->prevfilt[i];
+ }
+ }else{
+ for(i = 0; i < 8; i++){
+ dec->filters[i + 0]=(dec->cvector[i] * 21846 + dec->prevfilt[i] * 10923 + 16384) >> 15;
+ dec->filters[i + 8]=(dec->cvector[i] * 10923 + dec->prevfilt[i] * 21846 + 16384) >> 15;
+ }
+ }
+ for(i = 0; i < 8; i++){
+ dec->filters[i + 16] = dec->cvector[i];
+ dec->filters[i + 24] = dec->cvector[i];
+ }
+}
+
+static void truespeech_apply_twopoint_filter(TSContext *dec, int quart)
+{
+ int16_t tmp[146 + 60], *ptr0, *ptr1;
+ const int16_t *filter;
+ int i, t, off;
+
+ t = dec->offset2[quart];
+ if(t == 127){
+ memset(dec->newvec, 0, 60 * 2);
+ return;
+ }
+ for(i = 0; i < 146; i++)
+ tmp[i] = dec->filtbuf[i];
+ off = (t / 25) + dec->offset1[quart >> 1] + 18;
+ ptr0 = tmp + 145 - off;
+ ptr1 = tmp + 146;
+ filter = (const int16_t*)ts_240 + (t % 25) * 2;
+ for(i = 0; i < 60; i++){
+ t = (ptr0[0] * filter[0] + ptr0[1] * filter[1] + 0x2000) >> 14;
+ ptr0++;
+ dec->newvec[i] = t;
+ ptr1[i] = t;
+ }
+}
+
+static void truespeech_place_pulses(TSContext *dec, int16_t *out, int quart)
+{
+ int16_t tmp[7];
+ int i, j, t;
+ const int16_t *ptr1;
+ int16_t *ptr2;
+ int coef;
+
+ memset(out, 0, 60 * 2);
+ for(i = 0; i < 7; i++) {
+ t = dec->pulseval[quart] & 3;
+ dec->pulseval[quart] >>= 2;
+ tmp[6 - i] = ts_562[dec->pulseoff[quart] * 4 + t];
+ }
+
+ coef = dec->pulsepos[quart] >> 15;
+ ptr1 = (const int16_t*)ts_140 + 30;
+ ptr2 = tmp;
+ for(i = 0, j = 3; (i < 30) && (j > 0); i++){
+ t = *ptr1++;
+ if(coef >= t)
+ coef -= t;
+ else{
+ out[i] = *ptr2++;
+ ptr1 += 30;
+ j--;
+ }
+ }
+ coef = dec->pulsepos[quart] & 0x7FFF;
+ ptr1 = (const int16_t*)ts_140;
+ for(i = 30, j = 4; (i < 60) && (j > 0); i++){
+ t = *ptr1++;
+ if(coef >= t)
+ coef -= t;
+ else{
+ out[i] = *ptr2++;
+ ptr1 += 30;
+ j--;
+ }
+ }
+
+}
+
+static void truespeech_update_filters(TSContext *dec, int16_t *out, int quart)
+{
+ int i;
+
+ for(i = 0; i < 86; i++)
+ dec->filtbuf[i] = dec->filtbuf[i + 60];
+ for(i = 0; i < 60; i++){
+ dec->filtbuf[i + 86] = out[i] + dec->newvec[i] - (dec->newvec[i] >> 3);
+ out[i] += dec->newvec[i];
+ }
+}
+
+static void truespeech_synth(TSContext *dec, int16_t *out, int quart)
+{
+ int i,k;
+ int t[8];
+ int16_t *ptr0, *ptr1;
+
+ ptr0 = dec->tmp1;
+ ptr1 = dec->filters + quart * 8;
+ for(i = 0; i < 60; i++){
+ int sum = 0;
+ for(k = 0; k < 8; k++)
+ sum += ptr0[k] * ptr1[k];
+ sum = (sum + (out[i] << 12) + 0x800) >> 12;
+ out[i] = av_clip(sum, -0x7FFE, 0x7FFE);
+ for(k = 7; k > 0; k--)
+ ptr0[k] = ptr0[k - 1];
+ ptr0[0] = out[i];
+ }
+
+ for(i = 0; i < 8; i++)
+ t[i] = (ts_5E2[i] * ptr1[i]) >> 15;
+
+ ptr0 = dec->tmp2;
+ for(i = 0; i < 60; i++){
+ int sum = 0;
+ for(k = 0; k < 8; k++)
+ sum += ptr0[k] * t[k];
+ for(k = 7; k > 0; k--)
+ ptr0[k] = ptr0[k - 1];
+ ptr0[0] = out[i];
+ out[i] = ((out[i] << 12) - sum) >> 12;
+ }
+
+ for(i = 0; i < 8; i++)
+ t[i] = (ts_5F2[i] * ptr1[i]) >> 15;
+
+ ptr0 = dec->tmp3;
+ for(i = 0; i < 60; i++){
+ int sum = out[i] << 12;
+ for(k = 0; k < 8; k++)
+ sum += ptr0[k] * t[k];
+ for(k = 7; k > 0; k--)
+ ptr0[k] = ptr0[k - 1];
+ ptr0[0] = av_clip((sum + 0x800) >> 12, -0x7FFE, 0x7FFE);
+
+ sum = ((ptr0[1] * (dec->filtval - (dec->filtval >> 2))) >> 4) + sum;
+ sum = sum - (sum >> 3);
+ out[i] = av_clip((sum + 0x800) >> 12, -0x7FFE, 0x7FFE);
+ }
+}
+
+static void truespeech_save_prevvec(TSContext *c)
+{
+ int i;
+
+ for(i = 0; i < 8; i++)
+ c->prevfilt[i] = c->cvector[i];
+}
+
+static int truespeech_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ TSContext *c = avctx->priv_data;
+
+ int i;
+ short *samples = data;
+ int consumed = 0;
+ int16_t out_buf[240];
+
+ if (!buf_size)
+ return 0;
+
+ while (consumed < buf_size) {
+ truespeech_read_frame(c, buf + consumed);
+ consumed += 32;
+
+ truespeech_correlate_filter(c);
+ truespeech_filters_merge(c);
+
+ memset(out_buf, 0, 240 * 2);
+ for(i = 0; i < 4; i++) {
+ truespeech_apply_twopoint_filter(c, i);
+ truespeech_place_pulses(c, out_buf + i * 60, i);
+ truespeech_update_filters(c, out_buf + i * 60, i);
+ truespeech_synth(c, out_buf + i * 60, i);
+ }
+
+ truespeech_save_prevvec(c);
+
+ /* finally output decoded frame */
+ for(i = 0; i < 240; i++)
+ *samples++ = out_buf[i];
+
+ }
+
+ *data_size = consumed * 15;
+
+ return buf_size;
+}
+
+AVCodec truespeech_decoder = {
+ "truespeech",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_TRUESPEECH,
+ sizeof(TSContext),
+ truespeech_decode_init,
+ NULL,
+ NULL,
+ truespeech_decode_frame,
+};
diff --git a/src/libffmpeg/libavcodec/truespeech_data.h b/contrib/ffmpeg/libavcodec/truespeech_data.h
index cd8822fde..cd8822fde 100644
--- a/src/libffmpeg/libavcodec/truespeech_data.h
+++ b/contrib/ffmpeg/libavcodec/truespeech_data.h
diff --git a/contrib/ffmpeg/libavcodec/tscc.c b/contrib/ffmpeg/libavcodec/tscc.c
new file mode 100644
index 000000000..1453eb568
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/tscc.c
@@ -0,0 +1,347 @@
+/*
+ * TechSmith Camtasia decoder
+ * Copyright (c) 2004 Konstantin Shishkov
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * @file tscc.c
+ * TechSmith Camtasia decoder
+ *
+ * Fourcc: TSCC
+ *
+ * Codec is very simple:
+ * it codes picture (picture difference, really)
+ * with algorithm almost identical to Windows RLE8,
+ * only without padding and with greater pixel sizes,
+ * then this coded picture is packed with ZLib
+ *
+ * Supports: BGR8,BGR555,BGR24 - only BGR8 and BGR555 tested
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "common.h"
+#include "avcodec.h"
+
+#ifdef CONFIG_ZLIB
+#include <zlib.h>
+#endif
+
+
+/*
+ * Decoder context
+ */
+typedef struct TsccContext {
+
+ AVCodecContext *avctx;
+ AVFrame pic;
+
+ // Bits per pixel
+ int bpp;
+ // Decompressed data size
+ unsigned int decomp_size;
+ // Decompression buffer
+ unsigned char* decomp_buf;
+ int height;
+#ifdef CONFIG_ZLIB
+ z_stream zstream;
+#endif
+} CamtasiaContext;
+
+/*
+ *
+ * Decode RLE - almost identical to Windows BMP RLE8
+ * and enhanced to bigger color depths
+ *
+ */
+
+static int decode_rle(CamtasiaContext *c, unsigned int srcsize)
+{
+ unsigned char *src = c->decomp_buf;
+ unsigned char *output, *output_end;
+ int p1, p2, line=c->height, pos=0, i;
+ uint16_t pix16;
+ uint32_t pix32;
+
+ output = c->pic.data[0] + (c->height - 1) * c->pic.linesize[0];
+ output_end = c->pic.data[0] + (c->height) * c->pic.linesize[0];
+ while(src < c->decomp_buf + srcsize) {
+ p1 = *src++;
+ if(p1 == 0) { //Escape code
+ p2 = *src++;
+ if(p2 == 0) { //End-of-line
+ output = c->pic.data[0] + (--line) * c->pic.linesize[0];
+ if (line < 0)
+ return -1;
+ pos = 0;
+ continue;
+ } else if(p2 == 1) { //End-of-picture
+ return 0;
+ } else if(p2 == 2) { //Skip
+ p1 = *src++;
+ p2 = *src++;
+ line -= p2;
+ if (line < 0)
+ return -1;
+ pos += p1;
+ output = c->pic.data[0] + line * c->pic.linesize[0] + pos * (c->bpp / 8);
+ continue;
+ }
+ // Copy data
+ if (output + p2 * (c->bpp / 8) > output_end) {
+ src += p2 * (c->bpp / 8);
+ continue;
+ }
+ if ((c->bpp == 8) || (c->bpp == 24)) {
+ for(i = 0; i < p2 * (c->bpp / 8); i++) {
+ *output++ = *src++;
+ }
+ // RLE8 copy is actually padded - and runs are not!
+ if(c->bpp == 8 && (p2 & 1)) {
+ src++;
+ }
+ } else if (c->bpp == 16) {
+ for(i = 0; i < p2; i++) {
+ pix16 = AV_RL16(src);
+ src += 2;
+ *(uint16_t*)output = pix16;
+ output += 2;
+ }
+ } else if (c->bpp == 32) {
+ for(i = 0; i < p2; i++) {
+ pix32 = AV_RL32(src);
+ src += 4;
+ *(uint32_t*)output = pix32;
+ output += 4;
+ }
+ }
+ pos += p2;
+ } else { //Run of pixels
+ int pix[4]; //original pixel
+ switch(c->bpp){
+ case 8: pix[0] = *src++;
+ break;
+ case 16: pix16 = AV_RL16(src);
+ src += 2;
+ *(uint16_t*)pix = pix16;
+ break;
+ case 24: pix[0] = *src++;
+ pix[1] = *src++;
+ pix[2] = *src++;
+ break;
+ case 32: pix32 = AV_RL32(src);
+ src += 4;
+ *(uint32_t*)pix = pix32;
+ break;
+ }
+ if (output + p1 * (c->bpp / 8) > output_end)
+ continue;
+ for(i = 0; i < p1; i++) {
+ switch(c->bpp){
+ case 8: *output++ = pix[0];
+ break;
+ case 16: *(uint16_t*)output = pix16;
+ output += 2;
+ break;
+ case 24: *output++ = pix[0];
+ *output++ = pix[1];
+ *output++ = pix[2];
+ break;
+ case 32: *(uint32_t*)output = pix32;
+ output += 4;
+ break;
+ }
+ }
+ pos += p1;
+ }
+ }
+
+ av_log(c->avctx, AV_LOG_ERROR, "Camtasia warning: no End-of-picture code\n");
+ return 1;
+}
+
+/*
+ *
+ * Decode a frame
+ *
+ */
+static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size)
+{
+ CamtasiaContext * const c = (CamtasiaContext *)avctx->priv_data;
+ unsigned char *encoded = (unsigned char *)buf;
+ unsigned char *outptr;
+#ifdef CONFIG_ZLIB
+ int zret; // Zlib return code
+#endif
+ int len = buf_size;
+
+ if(c->pic.data[0])
+ avctx->release_buffer(avctx, &c->pic);
+
+ c->pic.reference = 1;
+ c->pic.buffer_hints = FF_BUFFER_HINTS_VALID;
+ if(avctx->get_buffer(avctx, &c->pic) < 0){
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ return -1;
+ }
+
+ outptr = c->pic.data[0]; // Output image pointer
+
+#ifdef CONFIG_ZLIB
+ zret = inflateReset(&(c->zstream));
+ if (zret != Z_OK) {
+ av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret);
+ return -1;
+ }
+ c->zstream.next_in = encoded;
+ c->zstream.avail_in = len;
+ c->zstream.next_out = c->decomp_buf;
+ c->zstream.avail_out = c->decomp_size;
+ zret = inflate(&(c->zstream), Z_FINISH);
+ // Z_DATA_ERROR means empty picture
+ if ((zret != Z_OK) && (zret != Z_STREAM_END) && (zret != Z_DATA_ERROR)) {
+ av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", zret);
+ return -1;
+ }
+
+
+ if(zret != Z_DATA_ERROR)
+ decode_rle(c, c->zstream.avail_out);
+
+ /* make the palette available on the way out */
+ if (c->avctx->pix_fmt == PIX_FMT_PAL8) {
+ memcpy(c->pic.data[1], c->avctx->palctrl->palette, AVPALETTE_SIZE);
+ if (c->avctx->palctrl->palette_changed) {
+ c->pic.palette_has_changed = 1;
+ c->avctx->palctrl->palette_changed = 0;
+ }
+ }
+
+#else
+ av_log(avctx, AV_LOG_ERROR, "BUG! Zlib support not compiled in frame decoder.\n");
+ return -1;
+#endif
+
+ *data_size = sizeof(AVFrame);
+ *(AVFrame*)data = c->pic;
+
+ /* always report that the buffer was completely consumed */
+ return buf_size;
+}
+
+
+
+/*
+ *
+ * Init tscc decoder
+ *
+ */
+static int decode_init(AVCodecContext *avctx)
+{
+ CamtasiaContext * const c = (CamtasiaContext *)avctx->priv_data;
+ int zret; // Zlib return code
+
+ c->avctx = avctx;
+
+ c->pic.data[0] = NULL;
+ c->height = avctx->height;
+
+ if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) {
+ return 1;
+ }
+
+#ifdef CONFIG_ZLIB
+ // Needed if zlib unused or init aborted before inflateInit
+ memset(&(c->zstream), 0, sizeof(z_stream));
+#else
+ av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled.\n");
+ return 1;
+#endif
+ switch(avctx->bits_per_sample){
+ case 8: avctx->pix_fmt = PIX_FMT_PAL8; break;
+ case 16: avctx->pix_fmt = PIX_FMT_RGB555; break;
+ case 24:
+ avctx->pix_fmt = PIX_FMT_BGR24;
+ break;
+ case 32: avctx->pix_fmt = PIX_FMT_RGB32; break;
+ default: av_log(avctx, AV_LOG_ERROR, "Camtasia error: unknown depth %i bpp\n", avctx->bits_per_sample);
+ return -1;
+ }
+ c->bpp = avctx->bits_per_sample;
+ c->decomp_size = (avctx->width * c->bpp + (avctx->width + 254) / 255 + 2) * avctx->height + 2;//RLE in the 'best' case
+
+ /* Allocate decompression buffer */
+ if (c->decomp_size) {
+ if ((c->decomp_buf = av_malloc(c->decomp_size)) == NULL) {
+ av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
+ return 1;
+ }
+ }
+
+#ifdef CONFIG_ZLIB
+ c->zstream.zalloc = Z_NULL;
+ c->zstream.zfree = Z_NULL;
+ c->zstream.opaque = Z_NULL;
+ zret = inflateInit(&(c->zstream));
+ if (zret != Z_OK) {
+ av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
+ return 1;
+ }
+#endif
+
+ return 0;
+}
+
+
+
+/*
+ *
+ * Uninit tscc decoder
+ *
+ */
+static int decode_end(AVCodecContext *avctx)
+{
+ CamtasiaContext * const c = (CamtasiaContext *)avctx->priv_data;
+
+ av_freep(&c->decomp_buf);
+
+ if (c->pic.data[0])
+ avctx->release_buffer(avctx, &c->pic);
+#ifdef CONFIG_ZLIB
+ inflateEnd(&(c->zstream));
+#endif
+
+ return 0;
+}
+
+AVCodec tscc_decoder = {
+ "camtasia",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_TSCC,
+ sizeof(CamtasiaContext),
+ decode_init,
+ NULL,
+ decode_end,
+ decode_frame,
+ CODEC_CAP_DR1,
+};
+
diff --git a/src/libffmpeg/libavcodec/tta.c b/contrib/ffmpeg/libavcodec/tta.c
index 82713fb0f..82713fb0f 100644
--- a/src/libffmpeg/libavcodec/tta.c
+++ b/contrib/ffmpeg/libavcodec/tta.c
diff --git a/contrib/ffmpeg/libavcodec/ulti.c b/contrib/ffmpeg/libavcodec/ulti.c
new file mode 100644
index 000000000..d84a88dad
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/ulti.c
@@ -0,0 +1,427 @@
+/*
+ * IBM Ultimotion Video Decoder
+ * Copyright (C) 2004 Konstantin Shishkov
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * @file ulti.c
+ * IBM Ultimotion Video Decoder.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "common.h"
+#include "avcodec.h"
+
+#include "ulti_cb.h"
+
+typedef struct UltimotionDecodeContext {
+ AVCodecContext *avctx;
+ int width, height, blocks;
+ AVFrame frame;
+ const uint8_t *ulti_codebook;
+} UltimotionDecodeContext;
+
+static int ulti_decode_init(AVCodecContext *avctx)
+{
+ UltimotionDecodeContext *s = avctx->priv_data;
+
+ s->avctx = avctx;
+ s->width = avctx->width;
+ s->height = avctx->height;
+ s->blocks = (s->width / 8) * (s->height / 8);
+ avctx->pix_fmt = PIX_FMT_YUV410P;
+ avctx->coded_frame = (AVFrame*) &s->frame;
+ s->ulti_codebook = ulti_codebook;
+
+ return 0;
+}
+
+static int block_coords[8] = // 4x4 block coords in 8x8 superblock
+ { 0, 0, 0, 4, 4, 4, 4, 0};
+
+static int angle_by_index[4] = { 0, 2, 6, 12};
+
+/* Lookup tables for luma and chroma - used by ulti_convert_yuv() */
+static uint8_t ulti_lumas[64] =
+ { 0x10, 0x13, 0x17, 0x1A, 0x1E, 0x21, 0x25, 0x28,
+ 0x2C, 0x2F, 0x33, 0x36, 0x3A, 0x3D, 0x41, 0x44,
+ 0x48, 0x4B, 0x4F, 0x52, 0x56, 0x59, 0x5C, 0x60,
+ 0x63, 0x67, 0x6A, 0x6E, 0x71, 0x75, 0x78, 0x7C,
+ 0x7F, 0x83, 0x86, 0x8A, 0x8D, 0x91, 0x94, 0x98,
+ 0x9B, 0x9F, 0xA2, 0xA5, 0xA9, 0xAC, 0xB0, 0xB3,
+ 0xB7, 0xBA, 0xBE, 0xC1, 0xC5, 0xC8, 0xCC, 0xCF,
+ 0xD3, 0xD6, 0xDA, 0xDD, 0xE1, 0xE4, 0xE8, 0xEB};
+
+static uint8_t ulti_chromas[16] =
+ { 0x60, 0x67, 0x6D, 0x73, 0x7A, 0x80, 0x86, 0x8D,
+ 0x93, 0x99, 0xA0, 0xA6, 0xAC, 0xB3, 0xB9, 0xC0};
+
+/* convert Ultimotion YUV block (sixteen 6-bit Y samples and
+ two 4-bit chroma samples) into standard YUV and put it into frame */
+static void ulti_convert_yuv(AVFrame *frame, int x, int y,
+ uint8_t *luma,int chroma)
+{
+ uint8_t *y_plane, *cr_plane, *cb_plane;
+ int i;
+
+ y_plane = frame->data[0] + x + y * frame->linesize[0];
+ cr_plane = frame->data[1] + (x / 4) + (y / 4) * frame->linesize[1];
+ cb_plane = frame->data[2] + (x / 4) + (y / 4) * frame->linesize[2];
+
+ cr_plane[0] = ulti_chromas[chroma >> 4];
+
+ cb_plane[0] = ulti_chromas[chroma & 0xF];
+
+
+ for(i = 0; i < 16; i++){
+ y_plane[i & 3] = ulti_lumas[luma[i]];
+ if((i & 3) == 3) { //next row
+ y_plane += frame->linesize[0];
+ }
+ }
+}
+
+/* generate block like in MS Video1 */
+static void ulti_pattern(AVFrame *frame, int x, int y,
+ int f0, int f1, int Y0, int Y1, int chroma)
+{
+ uint8_t Luma[16];
+ int mask, i;
+ for(mask = 0x80, i = 0; mask; mask >>= 1, i++) {
+ if(f0 & mask)
+ Luma[i] = Y1;
+ else
+ Luma[i] = Y0;
+ }
+
+ for(mask = 0x80, i = 8; mask; mask >>= 1, i++) {
+ if(f1 & mask)
+ Luma[i] = Y1;
+ else
+ Luma[i] = Y0;
+ }
+
+ ulti_convert_yuv(frame, x, y, Luma, chroma);
+}
+
+/* fill block with some gradient */
+static void ulti_grad(AVFrame *frame, int x, int y, uint8_t *Y, int chroma, int angle)
+{
+ uint8_t Luma[16];
+ if(angle & 8) { //reverse order
+ int t;
+ angle &= 0x7;
+ t = Y[0];
+ Y[0] = Y[3];
+ Y[3] = t;
+ t = Y[1];
+ Y[1] = Y[2];
+ Y[2] = t;
+ }
+ switch(angle){
+ case 0:
+ Luma[0] = Y[0]; Luma[1] = Y[1]; Luma[2] = Y[2]; Luma[3] = Y[3];
+ Luma[4] = Y[0]; Luma[5] = Y[1]; Luma[6] = Y[2]; Luma[7] = Y[3];
+ Luma[8] = Y[0]; Luma[9] = Y[1]; Luma[10] = Y[2]; Luma[11] = Y[3];
+ Luma[12] = Y[0]; Luma[13] = Y[1]; Luma[14] = Y[2]; Luma[15] = Y[3];
+ break;
+ case 1:
+ Luma[0] = Y[1]; Luma[1] = Y[2]; Luma[2] = Y[3]; Luma[3] = Y[3];
+ Luma[4] = Y[0]; Luma[5] = Y[1]; Luma[6] = Y[2]; Luma[7] = Y[3];
+ Luma[8] = Y[0]; Luma[9] = Y[1]; Luma[10] = Y[2]; Luma[11] = Y[3];
+ Luma[12] = Y[0]; Luma[13] = Y[0]; Luma[14] = Y[1]; Luma[15] = Y[2];
+ break;
+ case 2:
+ Luma[0] = Y[1]; Luma[1] = Y[2]; Luma[2] = Y[3]; Luma[3] = Y[3];
+ Luma[4] = Y[1]; Luma[5] = Y[2]; Luma[6] = Y[2]; Luma[7] = Y[3];
+ Luma[8] = Y[0]; Luma[9] = Y[1]; Luma[10] = Y[1]; Luma[11] = Y[2];
+ Luma[12] = Y[0]; Luma[13] = Y[0]; Luma[14] = Y[1]; Luma[15] = Y[2];
+ break;
+ case 3:
+ Luma[0] = Y[2]; Luma[1] = Y[3]; Luma[2] = Y[3]; Luma[3] = Y[3];
+ Luma[4] = Y[1]; Luma[5] = Y[2]; Luma[6] = Y[2]; Luma[7] = Y[3];
+ Luma[8] = Y[0]; Luma[9] = Y[1]; Luma[10] = Y[1]; Luma[11] = Y[2];
+ Luma[12] = Y[0]; Luma[13] = Y[0]; Luma[14] = Y[0]; Luma[15] = Y[1];
+ break;
+ case 4:
+ Luma[0] = Y[3]; Luma[1] = Y[3]; Luma[2] = Y[3]; Luma[3] = Y[3];
+ Luma[4] = Y[2]; Luma[5] = Y[2]; Luma[6] = Y[2]; Luma[7] = Y[2];
+ Luma[8] = Y[1]; Luma[9] = Y[1]; Luma[10] = Y[1]; Luma[11] = Y[1];
+ Luma[12] = Y[0]; Luma[13] = Y[0]; Luma[14] = Y[0]; Luma[15] = Y[0];
+ break;
+ case 5:
+ Luma[0] = Y[3]; Luma[1] = Y[3]; Luma[2] = Y[3]; Luma[3] = Y[2];
+ Luma[4] = Y[3]; Luma[5] = Y[2]; Luma[6] = Y[2]; Luma[7] = Y[1];
+ Luma[8] = Y[2]; Luma[9] = Y[1]; Luma[10] = Y[1]; Luma[11] = Y[0];
+ Luma[12] = Y[1]; Luma[13] = Y[0]; Luma[14] = Y[0]; Luma[15] = Y[0];
+ break;
+ case 6:
+ Luma[0] = Y[3]; Luma[1] = Y[3]; Luma[2] = Y[2]; Luma[3] = Y[2];
+ Luma[4] = Y[3]; Luma[5] = Y[2]; Luma[6] = Y[1]; Luma[7] = Y[1];
+ Luma[8] = Y[2]; Luma[9] = Y[2]; Luma[10] = Y[1]; Luma[11] = Y[0];
+ Luma[12] = Y[1]; Luma[13] = Y[1]; Luma[14] = Y[0]; Luma[15] = Y[0];
+ break;
+ case 7:
+ Luma[0] = Y[3]; Luma[1] = Y[3]; Luma[2] = Y[2]; Luma[3] = Y[1];
+ Luma[4] = Y[3]; Luma[5] = Y[2]; Luma[6] = Y[1]; Luma[7] = Y[0];
+ Luma[8] = Y[3]; Luma[9] = Y[2]; Luma[10] = Y[1]; Luma[11] = Y[0];
+ Luma[12] = Y[2]; Luma[13] = Y[1]; Luma[14] = Y[0]; Luma[15] = Y[0];
+ break;
+ default:
+ Luma[0] = Y[0]; Luma[1] = Y[0]; Luma[2] = Y[1]; Luma[3] = Y[1];
+ Luma[4] = Y[0]; Luma[5] = Y[0]; Luma[6] = Y[1]; Luma[7] = Y[1];
+ Luma[8] = Y[2]; Luma[9] = Y[2]; Luma[10] = Y[3]; Luma[11] = Y[3];
+ Luma[12] = Y[2]; Luma[13] = Y[2]; Luma[14] = Y[3]; Luma[15] = Y[3];
+ break;
+ }
+
+ ulti_convert_yuv(frame, x, y, Luma, chroma);
+}
+
+static int ulti_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ UltimotionDecodeContext *s=avctx->priv_data;
+ int modifier = 0;
+ int uniq = 0;
+ int mode = 0;
+ int blocks = 0;
+ int done = 0;
+ int x = 0, y = 0;
+ int i;
+ int skip;
+ int tmp;
+
+ if(s->frame.data[0])
+ avctx->release_buffer(avctx, &s->frame);
+
+ s->frame.reference = 1;
+ s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
+ if(avctx->get_buffer(avctx, &s->frame) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ return -1;
+ }
+
+ while(!done) {
+ int idx;
+ if(blocks >= s->blocks || y >= s->height)
+ break;//all blocks decoded
+
+ idx = *buf++;
+ if((idx & 0xF8) == 0x70) {
+ switch(idx) {
+ case 0x70: //change modifier
+ modifier = *buf++;
+ if(modifier>1)
+ av_log(avctx, AV_LOG_INFO, "warning: modifier must be 0 or 1, got %i\n", modifier);
+ break;
+ case 0x71: // set uniq flag
+ uniq = 1;
+ break;
+ case 0x72: //toggle mode
+ mode = !mode;
+ break;
+ case 0x73: //end-of-frame
+ done = 1;
+ break;
+ case 0x74: //skip some blocks
+ skip = *buf++;
+ if ((blocks + skip) >= s->blocks)
+ break;
+ blocks += skip;
+ x += skip * 8;
+ while(x >= s->width) {
+ x -= s->width;
+ y += 8;
+ }
+ break;
+ default:
+ av_log(avctx, AV_LOG_INFO, "warning: unknown escape 0x%02X\n", idx);
+ }
+ } else { //handle one block
+ int code;
+ int cf;
+ int angle = 0;
+ uint8_t Y[4]; // luma samples of block
+ int tx = 0, ty = 0; //coords of subblock
+ int chroma = 0;
+ if (mode || uniq) {
+ uniq = 0;
+ cf = 1;
+ chroma = 0;
+ } else {
+ cf = 0;
+ if (idx)
+ chroma = *buf++;
+ }
+ for (i = 0; i < 4; i++) { // for every subblock
+ code = (idx >> (6 - i*2)) & 3; //extract 2 bits
+ if(!code) //skip subblock
+ continue;
+ if(cf)
+ chroma = *buf++;
+ tx = x + block_coords[i * 2];
+ ty = y + block_coords[(i * 2) + 1];
+ switch(code) {
+ case 1:
+ tmp = *buf++;
+
+ angle = angle_by_index[(tmp >> 6) & 0x3];
+
+ Y[0] = tmp & 0x3F;
+ Y[1] = Y[0];
+
+ if (angle) {
+ Y[2] = Y[0]+1;
+ if (Y[2] > 0x3F)
+ Y[2] = 0x3F;
+ Y[3] = Y[2];
+ } else {
+ Y[2] = Y[0];
+ Y[3] = Y[0];
+ }
+ break;
+
+ case 2:
+ if (modifier) { // unpack four luma samples
+ tmp = (*buf++) << 16;
+ tmp += (*buf++) << 8;
+ tmp += *buf++;
+
+ Y[0] = (tmp >> 18) & 0x3F;
+ Y[1] = (tmp >> 12) & 0x3F;
+ Y[2] = (tmp >> 6) & 0x3F;
+ Y[3] = tmp & 0x3F;
+ angle = 16;
+ } else { // retrieve luma samples from codebook
+ tmp = (*buf++) << 8;
+ tmp += (*buf++);
+
+ angle = (tmp >> 12) & 0xF;
+ tmp &= 0xFFF;
+ tmp <<= 2;
+ Y[0] = s->ulti_codebook[tmp];
+ Y[1] = s->ulti_codebook[tmp + 1];
+ Y[2] = s->ulti_codebook[tmp + 2];
+ Y[3] = s->ulti_codebook[tmp + 3];
+ }
+ break;
+
+ case 3:
+ if (modifier) { // all 16 luma samples
+ uint8_t Luma[16];
+
+ tmp = (*buf++) << 16;
+ tmp += (*buf++) << 8;
+ tmp += *buf++;
+ Luma[0] = (tmp >> 18) & 0x3F;
+ Luma[1] = (tmp >> 12) & 0x3F;
+ Luma[2] = (tmp >> 6) & 0x3F;
+ Luma[3] = tmp & 0x3F;
+
+ tmp = (*buf++) << 16;
+ tmp += (*buf++) << 8;
+ tmp += *buf++;
+ Luma[4] = (tmp >> 18) & 0x3F;
+ Luma[5] = (tmp >> 12) & 0x3F;
+ Luma[6] = (tmp >> 6) & 0x3F;
+ Luma[7] = tmp & 0x3F;
+
+ tmp = (*buf++) << 16;
+ tmp += (*buf++) << 8;
+ tmp += *buf++;
+ Luma[8] = (tmp >> 18) & 0x3F;
+ Luma[9] = (tmp >> 12) & 0x3F;
+ Luma[10] = (tmp >> 6) & 0x3F;
+ Luma[11] = tmp & 0x3F;
+
+ tmp = (*buf++) << 16;
+ tmp += (*buf++) << 8;
+ tmp += *buf++;
+ Luma[12] = (tmp >> 18) & 0x3F;
+ Luma[13] = (tmp >> 12) & 0x3F;
+ Luma[14] = (tmp >> 6) & 0x3F;
+ Luma[15] = tmp & 0x3F;
+
+ ulti_convert_yuv(&s->frame, tx, ty, Luma, chroma);
+ } else {
+ tmp = *buf++;
+ if(tmp & 0x80) {
+ angle = (tmp >> 4) & 0x7;
+ tmp = (tmp << 8) + *buf++;
+ Y[0] = (tmp >> 6) & 0x3F;
+ Y[1] = tmp & 0x3F;
+ Y[2] = (*buf++) & 0x3F;
+ Y[3] = (*buf++) & 0x3F;
+ ulti_grad(&s->frame, tx, ty, Y, chroma, angle); //draw block
+ } else { // some patterns
+ int f0, f1;
+ f0 = *buf++;
+ f1 = tmp;
+ Y[0] = (*buf++) & 0x3F;
+ Y[1] = (*buf++) & 0x3F;
+ ulti_pattern(&s->frame, tx, ty, f1, f0, Y[0], Y[1], chroma);
+ }
+ }
+ break;
+ }
+ if(code != 3)
+ ulti_grad(&s->frame, tx, ty, Y, chroma, angle); // draw block
+ }
+ blocks++;
+ x += 8;
+ if(x >= s->width) {
+ x = 0;
+ y += 8;
+ }
+ }
+ }
+
+ *data_size=sizeof(AVFrame);
+ *(AVFrame*)data= s->frame;
+
+ return buf_size;
+}
+
+static int ulti_decode_end(AVCodecContext *avctx)
+{
+/* UltimotionDecodeContext *s = avctx->priv_data;*/
+
+ return 0;
+}
+
+AVCodec ulti_decoder = {
+ "ultimotion",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_ULTI,
+ sizeof(UltimotionDecodeContext),
+ ulti_decode_init,
+ NULL,
+ ulti_decode_end,
+ ulti_decode_frame,
+ CODEC_CAP_DR1,
+ NULL
+};
+
diff --git a/src/libffmpeg/libavcodec/ulti_cb.h b/contrib/ffmpeg/libavcodec/ulti_cb.h
index 2d8c9082c..2d8c9082c 100644
--- a/src/libffmpeg/libavcodec/ulti_cb.h
+++ b/contrib/ffmpeg/libavcodec/ulti_cb.h
diff --git a/contrib/ffmpeg/libavcodec/utils.c b/contrib/ffmpeg/libavcodec/utils.c
new file mode 100644
index 000000000..2129c9d15
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/utils.c
@@ -0,0 +1,1340 @@
+/*
+ * utils for libavcodec
+ * Copyright (c) 2001 Fabrice Bellard.
+ * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file utils.c
+ * utils.
+ */
+
+#include "avcodec.h"
+#include "dsputil.h"
+#include "mpegvideo.h"
+#include "integer.h"
+#include "opt.h"
+#include "crc.h"
+#include <stdarg.h>
+#include <limits.h>
+#include <float.h>
+#ifdef __MINGW32__
+#include <fcntl.h>
+#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;
+
+void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size)
+{
+ if(min_size < *size)
+ return ptr;
+
+ *size= FFMAX(17*min_size/16 + 32, min_size);
+
+ return av_realloc(ptr, *size);
+}
+
+static unsigned int last_static = 0;
+static unsigned int allocated_static = 0;
+static void** array_static = NULL;
+
+void *av_mallocz_static(unsigned int size)
+{
+ void *ptr = av_mallocz(size);
+
+ if(ptr){
+ array_static =av_fast_realloc(array_static, &allocated_static, sizeof(void*)*(last_static+1));
+ if(!array_static)
+ return NULL;
+ array_static[last_static++] = ptr;
+ }
+
+ return ptr;
+}
+
+void *ff_realloc_static(void *ptr, unsigned int size)
+{
+ int i;
+ if(!ptr)
+ return av_mallocz_static(size);
+ /* Look for the old ptr */
+ for(i = 0; i < last_static; i++) {
+ if(array_static[i] == ptr) {
+ array_static[i] = av_realloc(array_static[i], size);
+ return array_static[i];
+ }
+ }
+ return NULL;
+
+}
+
+void av_free_static(void)
+{
+ while(last_static){
+ av_freep(&array_static[--last_static]);
+ }
+ av_freep(&array_static);
+}
+
+/**
+ * Call av_free_static automatically before it's too late
+ */
+
+static void do_free(void) __attribute__ ((destructor));
+
+static void do_free(void)
+{
+ av_free_static();
+}
+
+
+/* encoder management */
+AVCodec *first_avcodec = NULL;
+
+void register_avcodec(AVCodec *format)
+{
+ AVCodec **p;
+ p = &first_avcodec;
+ while (*p != NULL) p = &(*p)->next;
+ *p = format;
+ format->next = NULL;
+}
+
+void avcodec_set_dimensions(AVCodecContext *s, int width, int height){
+ s->coded_width = width;
+ s->coded_height= height;
+ s->width = -((-width )>>s->lowres);
+ s->height= -((-height)>>s->lowres);
+}
+
+typedef struct InternalBuffer{
+ int last_pic_num;
+ uint8_t *base[4];
+ uint8_t *data[4];
+ int linesize[4];
+}InternalBuffer;
+
+#define INTERNAL_BUFFER_SIZE 32
+
+#define ALIGN(x, a) (((x)+(a)-1)&~((a)-1))
+
+void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){
+ int w_align= 1;
+ int h_align= 1;
+
+ switch(s->pix_fmt){
+ case PIX_FMT_YUV420P:
+ case PIX_FMT_YUYV422:
+ case PIX_FMT_UYVY422:
+ case PIX_FMT_YUV422P:
+ 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_YUVJ444P:
+ w_align= 16; //FIXME check for non mpeg style codecs and use less alignment
+ h_align= 16;
+ break;
+ case PIX_FMT_YUV411P:
+ case PIX_FMT_UYYVYY411:
+ w_align=32;
+ h_align=8;
+ break;
+ case PIX_FMT_YUV410P:
+ if(s->codec_id == CODEC_ID_SVQ1){
+ w_align=64;
+ h_align=64;
+ }
+ case PIX_FMT_RGB555:
+ if(s->codec_id == CODEC_ID_RPZA){
+ w_align=4;
+ h_align=4;
+ }
+ case PIX_FMT_PAL8:
+ if(s->codec_id == CODEC_ID_SMC){
+ w_align=4;
+ h_align=4;
+ }
+ break;
+ case PIX_FMT_BGR24:
+ if((s->codec_id == CODEC_ID_MSZH) || (s->codec_id == CODEC_ID_ZLIB)){
+ w_align=4;
+ h_align=4;
+ }
+ break;
+ default:
+ w_align= 1;
+ h_align= 1;
+ break;
+ }
+
+ *width = ALIGN(*width , w_align);
+ *height= ALIGN(*height, h_align);
+}
+
+int avcodec_check_dimensions(void *av_log_ctx, unsigned int w, unsigned int h){
+ if((int)w>0 && (int)h>0 && (w+128)*(uint64_t)(h+128) < INT_MAX/4)
+ return 0;
+
+ av_log(av_log_ctx, AV_LOG_ERROR, "picture size invalid (%ux%u)\n", w, h);
+ return -1;
+}
+
+int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){
+ int i;
+ int w= s->width;
+ int h= s->height;
+ InternalBuffer *buf;
+ int *picture_number;
+
+ if(pic->data[0]!=NULL) {
+ av_log(s, AV_LOG_ERROR, "pic->data[0]!=NULL in avcodec_default_get_buffer\n");
+ return -1;
+ }
+ if(s->internal_buffer_count >= INTERNAL_BUFFER_SIZE) {
+ av_log(s, AV_LOG_ERROR, "internal_buffer_count overflow (missing release_buffer?)\n");
+ return -1;
+ }
+
+ if(avcodec_check_dimensions(s,w,h))
+ return -1;
+
+ if(s->internal_buffer==NULL){
+ s->internal_buffer= av_mallocz(INTERNAL_BUFFER_SIZE*sizeof(InternalBuffer));
+ }
+#if 0
+ s->internal_buffer= av_fast_realloc(
+ s->internal_buffer,
+ &s->internal_buffer_size,
+ sizeof(InternalBuffer)*FFMAX(99, s->internal_buffer_count+1)/*FIXME*/
+ );
+#endif
+
+ buf= &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];
+ picture_number= &(((InternalBuffer*)s->internal_buffer)[INTERNAL_BUFFER_SIZE-1]).last_pic_num; //FIXME ugly hack
+ (*picture_number)++;
+
+ if(buf->base[0]){
+ pic->age= *picture_number - buf->last_pic_num;
+ buf->last_pic_num= *picture_number;
+ }else{
+ int h_chroma_shift, v_chroma_shift;
+ int pixel_size, size[3];
+ AVPicture picture;
+
+ avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);
+
+ avcodec_align_dimensions(s, &w, &h);
+
+ if(!(s->flags&CODEC_FLAG_EMU_EDGE)){
+ w+= EDGE_WIDTH*2;
+ h+= EDGE_WIDTH*2;
+ }
+ avpicture_fill(&picture, NULL, s->pix_fmt, w, h);
+ pixel_size= picture.linesize[0]*8 / w;
+//av_log(NULL, AV_LOG_ERROR, "%d %d %d %d\n", (int)picture.data[1], w, h, s->pix_fmt);
+ assert(pixel_size>=1);
+ //FIXME next ensures that linesize= 2^x uvlinesize, thats needed because some MC code assumes it
+ if(pixel_size == 3*8)
+ w= ALIGN(w, STRIDE_ALIGN<<h_chroma_shift);
+ else
+ w= ALIGN(pixel_size*w, STRIDE_ALIGN<<(h_chroma_shift+3)) / pixel_size;
+ size[1] = avpicture_fill(&picture, NULL, s->pix_fmt, w, h);
+ size[0] = picture.linesize[0] * h;
+ size[1] -= size[0];
+ if(picture.data[2])
+ size[1]= size[2]= size[1]/2;
+ else
+ size[2]= 0;
+
+ buf->last_pic_num= -256*256*256*64;
+ memset(buf->base, 0, sizeof(buf->base));
+ memset(buf->data, 0, sizeof(buf->data));
+
+ for(i=0; i<3 && size[i]; i++){
+ const int h_shift= i==0 ? 0 : h_chroma_shift;
+ const int v_shift= i==0 ? 0 : v_chroma_shift;
+
+ buf->linesize[i]= picture.linesize[i];
+
+ buf->base[i]= av_malloc(size[i]+16); //FIXME 16
+ if(buf->base[i]==NULL) return -1;
+ memset(buf->base[i], 128, size[i]);
+
+ // no edge if EDEG EMU or not planar YUV, we check for PAL8 redundantly to protect against a exploitable bug regression ...
+ if((s->flags&CODEC_FLAG_EMU_EDGE) || (s->pix_fmt == PIX_FMT_PAL8) || !size[2])
+ buf->data[i] = buf->base[i];
+ else
+ buf->data[i] = buf->base[i] + ALIGN((buf->linesize[i]*EDGE_WIDTH>>v_shift) + (EDGE_WIDTH>>h_shift), STRIDE_ALIGN);
+ }
+ pic->age= 256*256*256*64;
+ }
+ pic->type= FF_BUFFER_TYPE_INTERNAL;
+
+ for(i=0; i<4; i++){
+ pic->base[i]= buf->base[i];
+ pic->data[i]= buf->data[i];
+ pic->linesize[i]= buf->linesize[i];
+ }
+ s->internal_buffer_count++;
+
+ return 0;
+}
+
+void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){
+ int i;
+ InternalBuffer *buf, *last;
+
+ assert(pic->type==FF_BUFFER_TYPE_INTERNAL);
+ assert(s->internal_buffer_count);
+
+ buf = NULL; /* avoids warning */
+ for(i=0; i<s->internal_buffer_count; i++){ //just 3-5 checks so is not worth to optimize
+ buf= &((InternalBuffer*)s->internal_buffer)[i];
+ if(buf->data[0] == pic->data[0])
+ break;
+ }
+ assert(i < s->internal_buffer_count);
+ s->internal_buffer_count--;
+ last = &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];
+
+ FFSWAP(InternalBuffer, *buf, *last);
+
+ for(i=0; i<3; i++){
+ pic->data[i]=NULL;
+// pic->base[i]=NULL;
+ }
+//printf("R%X\n", pic->opaque);
+}
+
+int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic){
+ AVFrame temp_pic;
+ int i;
+
+ /* If no picture return a new buffer */
+ if(pic->data[0] == NULL) {
+ /* We will copy from buffer, so must be readable */
+ pic->buffer_hints |= FF_BUFFER_HINTS_READABLE;
+ return s->get_buffer(s, pic);
+ }
+
+ /* If internal buffer type return the same buffer */
+ if(pic->type == FF_BUFFER_TYPE_INTERNAL)
+ return 0;
+
+ /*
+ * Not internal type and reget_buffer not overridden, emulate cr buffer
+ */
+ temp_pic = *pic;
+ for(i = 0; i < 4; i++)
+ pic->data[i] = pic->base[i] = NULL;
+ pic->opaque = NULL;
+ /* Allocate new frame */
+ if (s->get_buffer(s, pic))
+ return -1;
+ /* Copy image data from old buffer to new buffer */
+ av_picture_copy((AVPicture*)pic, (AVPicture*)&temp_pic, s->pix_fmt, s->width,
+ s->height);
+ s->release_buffer(s, &temp_pic); // Release old frame
+ return 0;
+}
+
+int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count){
+ int i;
+
+ for(i=0; i<count; i++){
+ int r= func(c, arg[i]);
+ if(ret) ret[i]= r;
+ }
+ return 0;
+}
+
+enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat * fmt){
+ return fmt[0];
+}
+
+static const char* context_to_name(void* ptr) {
+ AVCodecContext *avc= ptr;
+
+ if(avc && avc->codec && avc->codec->name)
+ return avc->codec->name;
+ else
+ return "NULL";
+}
+
+#define OFFSET(x) offsetof(AVCodecContext,x)
+#define DEFAULT 0 //should be NAN but it doesnt work as its not a constant in glibc as required by ANSI/ISO C
+//these names are too long to be readable
+#define V AV_OPT_FLAG_VIDEO_PARAM
+#define A AV_OPT_FLAG_AUDIO_PARAM
+#define S AV_OPT_FLAG_SUBTITLE_PARAM
+#define E AV_OPT_FLAG_ENCODING_PARAM
+#define D AV_OPT_FLAG_DECODING_PARAM
+
+#define AV_CODEC_DEFAULT_BITRATE 200*1000
+
+static const AVOption options[]={
+{"b", "set bitrate (in bits/s)", OFFSET(bit_rate), FF_OPT_TYPE_INT, AV_CODEC_DEFAULT_BITRATE, INT_MIN, INT_MAX, V|E},
+{"ab", "set bitrate (in bits/s)", OFFSET(bit_rate), FF_OPT_TYPE_INT, 64*1000, INT_MIN, INT_MAX, A|E},
+{"bt", "set video bitrate tolerance (in bits/s)", OFFSET(bit_rate_tolerance), FF_OPT_TYPE_INT, AV_CODEC_DEFAULT_BITRATE*20, 1, INT_MAX, V|E},
+{"flags", NULL, OFFSET(flags), FF_OPT_TYPE_FLAGS, DEFAULT, INT_MIN, INT_MAX, V|A|E|D, "flags"},
+{"mv4", "use four motion vector by macroblock (mpeg4)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_4MV, INT_MIN, INT_MAX, V|E, "flags"},
+{"obmc", "use overlapped block motion compensation (h263+)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_OBMC, INT_MIN, INT_MAX, V|E, "flags"},
+{"qpel", "use 1/4 pel motion compensation", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_QPEL, INT_MIN, INT_MAX, V|E, "flags"},
+{"loop", "use loop filter", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_LOOP_FILTER, INT_MIN, INT_MAX, V|E, "flags"},
+{"qscale", "use fixed qscale", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_QSCALE, INT_MIN, INT_MAX, 0, "flags"},
+{"gmc", "use gmc", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_GMC, INT_MIN, INT_MAX, V|E, "flags"},
+{"mv0", "always try a mb with mv=<0,0>", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_MV0, INT_MIN, INT_MAX, V|E, "flags"},
+{"part", "use data partitioning", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_PART, INT_MIN, INT_MAX, V|E, "flags"},
+{"input_preserved", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG_INPUT_PRESERVED, INT_MIN, INT_MAX, 0, "flags"},
+{"pass1", "use internal 2pass ratecontrol in first pass mode", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_PASS1, INT_MIN, INT_MAX, 0, "flags"},
+{"pass2", "use internal 2pass ratecontrol in second pass mode", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_PASS2, INT_MIN, INT_MAX, 0, "flags"},
+{"extern_huff", "use external huffman table (for mjpeg)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_EXTERN_HUFF, INT_MIN, INT_MAX, 0, "flags"},
+{"gray", "only decode/encode grayscale", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_GRAY, INT_MIN, INT_MAX, V|E|D, "flags"},
+{"emu_edge", "don't draw edges", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_EMU_EDGE, INT_MIN, INT_MAX, 0, "flags"},
+{"psnr", "error[?] variables will be set during encoding", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_PSNR, INT_MIN, INT_MAX, V|E, "flags"},
+{"truncated", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG_TRUNCATED, INT_MIN, INT_MAX, 0, "flags"},
+{"naq", "normalize adaptive quantization", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_NORMALIZE_AQP, INT_MIN, INT_MAX, V|E, "flags"},
+{"ildct", "use interlaced dct", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_INTERLACED_DCT, INT_MIN, INT_MAX, V|E, "flags"},
+{"low_delay", "force low delay", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_LOW_DELAY, INT_MIN, INT_MAX, V|D|E, "flags"},
+{"alt", "enable alternate scantable (mpeg2/mpeg4)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_ALT_SCAN, INT_MIN, INT_MAX, V|E, "flags"},
+{"trell", "use trellis quantization", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_TRELLIS_QUANT, INT_MIN, INT_MAX, V|E, "flags"},
+{"global_header", "place global headers in extradata instead of every keyframe", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_GLOBAL_HEADER, INT_MIN, INT_MAX, 0, "flags"},
+{"bitexact", "use only bitexact stuff (except (i)dct)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_BITEXACT, INT_MIN, INT_MAX, A|V|S|D|E, "flags"},
+{"aic", "h263 advanced intra coding / mpeg4 ac prediction", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_AC_PRED, INT_MIN, INT_MAX, V|E, "flags"},
+{"umv", "use unlimited motion vectors", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_H263P_UMV, INT_MIN, INT_MAX, V|E, "flags"},
+{"cbp", "use rate distortion optimization for cbp", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_CBP_RD, INT_MIN, INT_MAX, V|E, "flags"},
+{"qprd", "use rate distortion optimization for qp selection", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_QP_RD, INT_MIN, INT_MAX, V|E, "flags"},
+{"aiv", "h263 alternative inter vlc", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_H263P_AIV, INT_MIN, INT_MAX, V|E, "flags"},
+{"slice", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG_H263P_SLICE_STRUCT, INT_MIN, INT_MAX, V|E, "flags"},
+{"ilme", "interlaced motion estimation", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_INTERLACED_ME, INT_MIN, INT_MAX, V|E, "flags"},
+{"scan_offset", "will reserve space for svcd scan offset user data", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_SVCD_SCAN_OFFSET, INT_MIN, INT_MAX, V|E, "flags"},
+{"cgop", "closed gop", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_CLOSED_GOP, INT_MIN, INT_MAX, V|E, "flags"},
+{"fast", "allow non spec compliant speedup tricks", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_FAST, INT_MIN, INT_MAX, V|E, "flags2"},
+{"sgop", "strictly enforce gop size", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_STRICT_GOP, INT_MIN, INT_MAX, V|E, "flags2"},
+{"noout", "skip bitstream encoding", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_NO_OUTPUT, INT_MIN, INT_MAX, V|E, "flags2"},
+{"local_header", "place global headers at every keyframe instead of in extradata", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_LOCAL_HEADER, INT_MIN, INT_MAX, V|E, "flags2"},
+{"sub_id", NULL, OFFSET(sub_id), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"me_method", "set motion estimation method", OFFSET(me_method), FF_OPT_TYPE_INT, ME_EPZS, INT_MIN, INT_MAX, V|E, "me_method"},
+{"extradata_size", NULL, OFFSET(extradata_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"time_base", NULL, OFFSET(time_base), FF_OPT_TYPE_RATIONAL, DEFAULT, INT_MIN, INT_MAX},
+{"g", "set the group of picture size", OFFSET(gop_size), FF_OPT_TYPE_INT, 12, INT_MIN, INT_MAX, V|E},
+{"rate_emu", "frame rate emulation", OFFSET(rate_emu), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"ar", "set audio sampling rate (in Hz)", OFFSET(sample_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"ac", "set number of audio channels", OFFSET(channels), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"cutoff", "set cutoff bandwidth", OFFSET(cutoff), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, A|E},
+{"frame_size", NULL, OFFSET(frame_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, A|E},
+{"frame_number", NULL, OFFSET(frame_number), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"real_pict_num", NULL, OFFSET(real_pict_num), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"delay", NULL, OFFSET(delay), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"qcomp", "video quantizer scale compression (VBR)", OFFSET(qcompress), FF_OPT_TYPE_FLOAT, 0.5, FLT_MIN, FLT_MAX, V|E},
+{"qblur", "video quantizer scale blur (VBR)", OFFSET(qblur), FF_OPT_TYPE_FLOAT, 0.5, FLT_MIN, FLT_MAX, V|E},
+{"qmin", "min video quantizer scale (VBR)", OFFSET(qmin), FF_OPT_TYPE_INT, 2, 1, 51, V|E},
+{"qmax", "max video quantizer scale (VBR)", OFFSET(qmax), FF_OPT_TYPE_INT, 31, 1, 51, V|E},
+{"qdiff", "max difference between the quantizer scale (VBR)", OFFSET(max_qdiff), FF_OPT_TYPE_INT, 3, INT_MIN, INT_MAX, V|E},
+{"bf", "use 'frames' B frames", OFFSET(max_b_frames), FF_OPT_TYPE_INT, DEFAULT, 0, FF_MAX_B_FRAMES, V|E},
+{"b_qfactor", "qp factor between p and b frames", OFFSET(b_quant_factor), FF_OPT_TYPE_FLOAT, 1.25, FLT_MIN, 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},
+{"hurry_up", NULL, OFFSET(hurry_up), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D},
+#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
+{"rtp_mode", NULL, OFFSET(rtp_mode), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+#endif
+{"ps", "rtp payload size in bits", 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},
+{"header_bits", NULL, OFFSET(header_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"i_tex_bits", NULL, OFFSET(i_tex_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"p_tex_bits", NULL, OFFSET(p_tex_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"i_count", NULL, OFFSET(i_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"p_count", NULL, OFFSET(p_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"skip_count", NULL, OFFSET(skip_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"misc_bits", NULL, OFFSET(misc_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"frame_bits", NULL, OFFSET(frame_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"codec_tag", NULL, OFFSET(codec_tag), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"bug", "workaround not auto detected encoder bugs", OFFSET(workaround_bugs), FF_OPT_TYPE_FLAGS, FF_BUG_AUTODETECT, INT_MIN, INT_MAX, V|D, "bug"},
+{"autodetect", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_AUTODETECT, INT_MIN, INT_MAX, V|D, "bug"},
+{"old_msmpeg4", "some old lavc generated msmpeg4v3 files (no autodetection)", 0, FF_OPT_TYPE_CONST, FF_BUG_OLD_MSMPEG4, INT_MIN, INT_MAX, V|D, "bug"},
+{"xvid_ilace", "Xvid interlacing bug (autodetected if fourcc==XVIX)", 0, FF_OPT_TYPE_CONST, FF_BUG_XVID_ILACE, INT_MIN, INT_MAX, V|D, "bug"},
+{"ump4", "(autodetected if fourcc==UMP4)", 0, FF_OPT_TYPE_CONST, FF_BUG_UMP4, INT_MIN, INT_MAX, V|D, "bug"},
+{"no_padding", "padding bug (autodetected)", 0, FF_OPT_TYPE_CONST, FF_BUG_NO_PADDING, INT_MIN, INT_MAX, V|D, "bug"},
+{"amv", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_AMV, INT_MIN, INT_MAX, V|D, "bug"},
+{"ac_vlc", "illegal vlc bug (autodetected per fourcc)", 0, FF_OPT_TYPE_CONST, FF_BUG_AC_VLC, INT_MIN, INT_MAX, V|D, "bug"},
+{"qpel_chroma", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_QPEL_CHROMA, INT_MIN, INT_MAX, V|D, "bug"},
+{"std_qpel", "old standard qpel (autodetected per fourcc/version)", 0, FF_OPT_TYPE_CONST, FF_BUG_STD_QPEL, INT_MIN, INT_MAX, V|D, "bug"},
+{"qpel_chroma2", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_QPEL_CHROMA2, INT_MIN, INT_MAX, V|D, "bug"},
+{"direct_blocksize", "direct-qpel-blocksize bug (autodetected per fourcc/version)", 0, FF_OPT_TYPE_CONST, FF_BUG_DIRECT_BLOCKSIZE, INT_MIN, INT_MAX, V|D, "bug"},
+{"edge", "edge padding bug (autodetected per fourcc/version)", 0, FF_OPT_TYPE_CONST, FF_BUG_EDGE, INT_MIN, INT_MAX, V|D, "bug"},
+{"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"},
+{"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, "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|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|E, "strict"},
+{"normal", NULL, 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_NORMAL, INT_MIN, INT_MAX, V|E, "strict"},
+{"inofficial", "allow inofficial extensions", 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_INOFFICIAL, INT_MIN, INT_MAX, V|E, "strict"},
+{"experimental", "allow non standarized experimental things", 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_EXPERIMENTAL, INT_MIN, INT_MAX, V|E, "strict"},
+{"b_qoffset", "qp offset between p and b frames", OFFSET(b_quant_offset), FF_OPT_TYPE_FLOAT, 1.25, FLT_MIN, FLT_MAX, V|E},
+{"er", "set error resilience strategy", OFFSET(error_resilience), FF_OPT_TYPE_INT, FF_ER_CAREFUL, INT_MIN, INT_MAX, A|V|D, "er"},
+{"careful", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_CAREFUL, INT_MIN, INT_MAX, V|D, "er"},
+{"compliant", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_COMPLIANT, INT_MIN, INT_MAX, V|D, "er"},
+{"aggressive", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_AGGRESSIVE, INT_MIN, INT_MAX, V|D, "er"},
+{"very_aggressive", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_VERY_AGGRESSIVE, INT_MIN, INT_MAX, V|D, "er"},
+{"has_b_frames", NULL, OFFSET(has_b_frames), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"block_align", NULL, OFFSET(block_align), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"parse_only", NULL, OFFSET(parse_only), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"mpeg_quant", "use MPEG quantizers instead of H.263", OFFSET(mpeg_quant), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"stats_out", NULL, OFFSET(stats_out), FF_OPT_TYPE_STRING, DEFAULT, CHAR_MIN, CHAR_MAX},
+{"stats_in", NULL, OFFSET(stats_in), FF_OPT_TYPE_STRING, DEFAULT, CHAR_MIN, CHAR_MAX},
+{"qsquish", "how to keep quantizer between qmin and qmax (0 = clip, 1 = use differentiable function)", OFFSET(rc_qsquish), FF_OPT_TYPE_FLOAT, DEFAULT, 0, 99, V|E},
+{"rc_qmod_amp", "experimental quantizer modulation", OFFSET(rc_qmod_amp), FF_OPT_TYPE_FLOAT, DEFAULT, -FLT_MAX, FLT_MAX, V|E},
+{"rc_qmod_freq", "experimental quantizer modulation", OFFSET(rc_qmod_freq), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"rc_override_count", NULL, OFFSET(rc_override_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"rc_eq", "set rate control equation", OFFSET(rc_eq), FF_OPT_TYPE_STRING, DEFAULT, CHAR_MIN, CHAR_MAX, V|E},
+{"maxrate", "set max video bitrate tolerance (in bits/s)", OFFSET(rc_max_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"minrate", "set min video bitrate tolerance (in bits/s)", OFFSET(rc_min_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"bufsize", "set ratecontrol buffer size (in bits)", OFFSET(rc_buffer_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"rc_buf_aggressivity", "currently useless", OFFSET(rc_buffer_aggressivity), FF_OPT_TYPE_FLOAT, 1.0, FLT_MIN, FLT_MAX, V|E},
+{"i_qfactor", "qp factor between p and i frames", OFFSET(i_quant_factor), FF_OPT_TYPE_FLOAT, -0.8, -FLT_MAX, FLT_MAX, V|E},
+{"i_qoffset", "qp offset between p and i frames", OFFSET(i_quant_offset), FF_OPT_TYPE_FLOAT, 0.0, -FLT_MAX, FLT_MAX, V|E},
+{"rc_init_cplx", "initial complexity for 1-pass encoding", OFFSET(rc_initial_cplx), FF_OPT_TYPE_FLOAT, DEFAULT, -FLT_MAX, FLT_MAX, V|E},
+{"dct", "DCT algorithm", OFFSET(dct_algo), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, V|E, "dct"},
+{"auto", "autoselect a good one (default)", 0, FF_OPT_TYPE_CONST, FF_DCT_AUTO, INT_MIN, INT_MAX, V|E, "dct"},
+{"fastint", "fast integer", 0, FF_OPT_TYPE_CONST, FF_DCT_FASTINT, INT_MIN, INT_MAX, V|E, "dct"},
+{"int", "accurate integer", 0, FF_OPT_TYPE_CONST, FF_DCT_INT, INT_MIN, INT_MAX, V|E, "dct"},
+{"mmx", NULL, 0, FF_OPT_TYPE_CONST, FF_DCT_MMX, INT_MIN, INT_MAX, V|E, "dct"},
+{"mlib", NULL, 0, FF_OPT_TYPE_CONST, FF_DCT_MLIB, INT_MIN, INT_MAX, V|E, "dct"},
+{"altivec", NULL, 0, FF_OPT_TYPE_CONST, FF_DCT_ALTIVEC, INT_MIN, INT_MAX, V|E, "dct"},
+{"faan", "floating point AAN DCT", 0, FF_OPT_TYPE_CONST, FF_DCT_FAAN, INT_MIN, INT_MAX, V|E, "dct"},
+{"lumi_mask", "compresses bright areas stronger than medium ones", OFFSET(lumi_masking), FF_OPT_TYPE_FLOAT, 0, -FLT_MAX, FLT_MAX, V|E},
+{"tcplx_mask", "temporal complexity masking", OFFSET(temporal_cplx_masking), FF_OPT_TYPE_FLOAT, 0, -FLT_MAX, FLT_MAX, V|E},
+{"scplx_mask", "spatial complexity masking", OFFSET(spatial_cplx_masking), FF_OPT_TYPE_FLOAT, 0, -FLT_MAX, FLT_MAX, V|E},
+{"p_mask", "inter masking", OFFSET(p_masking), FF_OPT_TYPE_FLOAT, 0, -FLT_MAX, FLT_MAX, V|E},
+{"dark_mask", "compresses dark areas stronger than medium ones", OFFSET(dark_masking), FF_OPT_TYPE_FLOAT, 0, -FLT_MAX, FLT_MAX, V|E},
+{"unused", NULL, OFFSET(unused), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"idct", "select IDCT implementation", OFFSET(idct_algo), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, V|E|D, "idct"},
+{"auto", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_AUTO, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"int", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_INT, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"simple", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLE, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"simplemmx", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLEMMX, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"libmpeg2mmx", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_LIBMPEG2MMX, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"ps2", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_PS2, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"mlib", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_MLIB, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"arm", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_ARM, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"altivec", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_ALTIVEC, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"sh4", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SH4, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"simplearm", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLEARM, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"simplearmv5te", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLEARMV5TE, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"h264", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_H264, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"vp3", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_VP3, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"ipp", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_IPP, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"xvidmmx", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_XVIDMMX, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"slice_count", NULL, OFFSET(slice_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"ec", "set error concealment strategy", OFFSET(error_concealment), FF_OPT_TYPE_FLAGS, 3, INT_MIN, INT_MAX, V|D, "ec"},
+{"guess_mvs", "iterative motion vector (MV) search (slow)", 0, FF_OPT_TYPE_CONST, FF_EC_GUESS_MVS, INT_MIN, INT_MAX, V|D, "ec"},
+{"deblock", "use strong deblock filter for damaged MBs", 0, FF_OPT_TYPE_CONST, FF_EC_DEBLOCK, INT_MIN, INT_MAX, V|D, "ec"},
+{"bits_per_sample", NULL, OFFSET(bits_per_sample), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"pred", "prediction method", OFFSET(prediction_method), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "pred"},
+{"left", NULL, 0, FF_OPT_TYPE_CONST, FF_PRED_LEFT, INT_MIN, INT_MAX, V|E, "pred"},
+{"plane", NULL, 0, FF_OPT_TYPE_CONST, FF_PRED_PLANE, INT_MIN, INT_MAX, V|E, "pred"},
+{"median", NULL, 0, FF_OPT_TYPE_CONST, FF_PRED_MEDIAN, INT_MIN, INT_MAX, V|E, "pred"},
+{"aspect", "sample aspect ratio", OFFSET(sample_aspect_ratio), FF_OPT_TYPE_RATIONAL, DEFAULT, 0, 10, V|E},
+{"debug", "print specific debug info", OFFSET(debug), FF_OPT_TYPE_FLAGS, DEFAULT, 0, INT_MAX, V|A|S|E|D, "debug"},
+{"pict", "picture info", 0, FF_OPT_TYPE_CONST, FF_DEBUG_PICT_INFO, INT_MIN, INT_MAX, V|D, "debug"},
+{"rc", "rate control", 0, FF_OPT_TYPE_CONST, FF_DEBUG_RC, INT_MIN, INT_MAX, V|E, "debug"},
+{"bitstream", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_BITSTREAM, INT_MIN, INT_MAX, V|D, "debug"},
+{"mb_type", "macroblock (MB) type", 0, FF_OPT_TYPE_CONST, FF_DEBUG_MB_TYPE, INT_MIN, INT_MAX, V|D, "debug"},
+{"qp", "per-block quantization parameter (QP)", 0, FF_OPT_TYPE_CONST, FF_DEBUG_QP, INT_MIN, INT_MAX, V|D, "debug"},
+{"mv", "motion vector", 0, FF_OPT_TYPE_CONST, FF_DEBUG_MV, INT_MIN, INT_MAX, V|D, "debug"},
+{"dct_coeff", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_DCT_COEFF, INT_MIN, INT_MAX, V|D, "debug"},
+{"skip", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_SKIP, INT_MIN, INT_MAX, V|D, "debug"},
+{"startcode", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_STARTCODE, INT_MIN, INT_MAX, V|D, "debug"},
+{"pts", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_PTS, INT_MIN, INT_MAX, V|D, "debug"},
+{"er", "error resilience", 0, FF_OPT_TYPE_CONST, FF_DEBUG_ER, INT_MIN, INT_MAX, V|D, "debug"},
+{"mmco", "memory management control operations (H.264)", 0, FF_OPT_TYPE_CONST, FF_DEBUG_MMCO, INT_MIN, INT_MAX, V|D, "debug"},
+{"bugs", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_BUGS, INT_MIN, INT_MAX, V|D, "debug"},
+{"vis_qp", "visualize quantization parameter (QP), lower QP are tinted greener", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_QP, INT_MIN, INT_MAX, V|D, "debug"},
+{"vis_mb_type", "visualize block types", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MB_TYPE, INT_MIN, INT_MAX, V|D, "debug"},
+{"vismv", "visualize motion vectors (MVs)", OFFSET(debug_mv), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, V|D, "debug_mv"},
+{"pf", "forward predicted MVs of P-frames", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MV_P_FOR, INT_MIN, INT_MAX, V|D, "debug_mv"},
+{"bf", "forward predicted MVs of B-frames", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MV_B_FOR, INT_MIN, INT_MAX, V|D, "debug_mv"},
+{"bb", "backward predicted MVs of B-frames", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MV_B_BACK, INT_MIN, INT_MAX, V|D, "debug_mv"},
+{"mb_qmin", "obsolete, use qmin", OFFSET(mb_qmin), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"mb_qmax", "obsolete, use qmax", OFFSET(mb_qmax), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"cmp", "full pel me compare function", OFFSET(me_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"subcmp", "sub pel me compare function", OFFSET(me_sub_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"mbcmp", "macroblock compare function", OFFSET(mb_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"ildctcmp", "interlaced dct compare function", OFFSET(ildct_cmp), FF_OPT_TYPE_INT, FF_CMP_VSAD, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"dia_size", "diamond type & size for motion estimation", OFFSET(dia_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"last_pred", "amount of motion predictors from the previous frame", OFFSET(last_predictor_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"preme", "pre motion estimation", OFFSET(pre_me), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"precmp", "pre motion estimation compare function", OFFSET(me_pre_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"sad", "sum of absolute differences, fast (default)", 0, FF_OPT_TYPE_CONST, FF_CMP_SAD, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"sse", "sum of squared errors", 0, FF_OPT_TYPE_CONST, FF_CMP_SSE, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"satd", "sum of absolute Hadamard transformed differences", 0, FF_OPT_TYPE_CONST, FF_CMP_SATD, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"dct", "sum of absolute DCT transformed differences", 0, FF_OPT_TYPE_CONST, FF_CMP_DCT, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"psnr", "sum of squared quantization errors (avoid, low quality)", 0, FF_OPT_TYPE_CONST, FF_CMP_PSNR, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"bit", "number of bits needed for the block", 0, FF_OPT_TYPE_CONST, FF_CMP_BIT, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"rd", "rate distortion optimal, slow", 0, FF_OPT_TYPE_CONST, FF_CMP_RD, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"zero", "0", 0, FF_OPT_TYPE_CONST, FF_CMP_ZERO, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"vsad", "sum of absolute vertical differences", 0, FF_OPT_TYPE_CONST, FF_CMP_VSAD, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"vsse","sum of squared vertical differences", 0, FF_OPT_TYPE_CONST, FF_CMP_VSSE, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"nsse", "noise preserving sum of squared differences", 0, FF_OPT_TYPE_CONST, FF_CMP_NSSE, INT_MIN, INT_MAX, V|E, "cmp_func"},
+#ifdef CONFIG_SNOW_ENCODER
+{"w53", "5/3 wavelet, only used in snow", 0, FF_OPT_TYPE_CONST, FF_CMP_W53, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"w97", "9/7 wavelet, only used in snow", 0, FF_OPT_TYPE_CONST, FF_CMP_W97, INT_MIN, INT_MAX, V|E, "cmp_func"},
+#endif
+{"dctmax", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_DCTMAX, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"chroma", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_CHROMA, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"pre_dia_size", "diamond type & size for motion estimation pre-pass", OFFSET(pre_dia_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"subq", "sub pel motion estimation quality", OFFSET(me_subpel_quality), FF_OPT_TYPE_INT, 8, INT_MIN, INT_MAX, V|E},
+{"dtg_active_format", NULL, OFFSET(dtg_active_format), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"me_range", "limit motion vectors range (1023 for DivX player)", OFFSET(me_range), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"ibias", "intra quant bias", OFFSET(intra_quant_bias), FF_OPT_TYPE_INT, FF_DEFAULT_QUANT_BIAS, INT_MIN, INT_MAX, V|E},
+{"pbias", "inter quant bias", OFFSET(inter_quant_bias), FF_OPT_TYPE_INT, FF_DEFAULT_QUANT_BIAS, INT_MIN, INT_MAX, V|E},
+{"color_table_id", NULL, OFFSET(color_table_id), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"internal_buffer_count", NULL, OFFSET(internal_buffer_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"global_quality", NULL, OFFSET(global_quality), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"coder", NULL, OFFSET(coder_type), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "coder"},
+{"vlc", "variable length coder / huffman coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_VLC, INT_MIN, INT_MAX, V|E, "coder"},
+{"ac", "arithmetic coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_AC, INT_MIN, INT_MAX, V|E, "coder"},
+{"context", "context model", OFFSET(context_model), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"slice_flags", NULL, OFFSET(slice_flags), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"xvmc_acceleration", NULL, OFFSET(xvmc_acceleration), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"mbd", "macroblock decision algorithm (high quality mode)", OFFSET(mb_decision), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "mbd"},
+{"simple", "use mbcmp (default)", 0, FF_OPT_TYPE_CONST, FF_MB_DECISION_SIMPLE, INT_MIN, INT_MAX, V|E, "mbd"},
+{"bits", "use fewest bits", 0, FF_OPT_TYPE_CONST, FF_MB_DECISION_BITS, INT_MIN, INT_MAX, V|E, "mbd"},
+{"rd", "use best rate distortion", 0, FF_OPT_TYPE_CONST, FF_MB_DECISION_RD, INT_MIN, INT_MAX, V|E, "mbd"},
+{"stream_codec_tag", NULL, OFFSET(stream_codec_tag), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"sc_threshold", "scene change threshold", OFFSET(scenechange_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"lmin", "min lagrange factor (VBR)", OFFSET(lmin), FF_OPT_TYPE_INT, 2*FF_QP2LAMBDA, 0, INT_MAX, V|E},
+{"lmax", "max lagrange factor (VBR)", OFFSET(lmax), FF_OPT_TYPE_INT, 31*FF_QP2LAMBDA, 0, INT_MAX, V|E},
+{"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, INT_MIN, INT_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"},
+{"fastint", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_FASTINT, INT_MIN, INT_MAX, V|D, "aa"},
+{"int", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_INT, INT_MIN, INT_MAX, V|D, "aa"},
+{"float", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_FLOAT, INT_MIN, INT_MAX, V|D, "aa"},
+{"qns", "quantizer noise shaping", OFFSET(quantizer_noise_shaping), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"threads", NULL, OFFSET(thread_count), FF_OPT_TYPE_INT, 1, INT_MIN, INT_MAX, V|E|D},
+{"me_threshold", "motion estimaton threshold", OFFSET(me_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
+{"mb_threshold", "macroblock threshold", OFFSET(mb_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"dc", "intra_dc_precision", OFFSET(intra_dc_precision), FF_OPT_TYPE_INT, 0, INT_MIN, INT_MAX, V|E},
+{"nssew", "nsse weight", OFFSET(nsse_weight), FF_OPT_TYPE_INT, 8, INT_MIN, INT_MAX, V|E},
+{"skip_top", "number of macroblock rows at the top which are skipped", OFFSET(skip_top), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D},
+{"skip_bottom", "number of macroblock rows at the bottom which are skipped", OFFSET(skip_bottom), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D},
+{"profile", NULL, OFFSET(profile), FF_OPT_TYPE_INT, FF_PROFILE_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "profile"},
+{"unknown", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "profile"},
+{"level", NULL, OFFSET(level), FF_OPT_TYPE_INT, FF_LEVEL_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "level"},
+{"unknown", NULL, 0, FF_OPT_TYPE_CONST, FF_LEVEL_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "level"},
+{"lowres", "decode at 1= 1/2, 2=1/4, 3=1/8 resolutions", OFFSET(lowres), FF_OPT_TYPE_INT, 0, 0, INT_MAX, V|D},
+{"skip_threshold", "frame skip threshold", OFFSET(frame_skip_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"skip_factor", "frame skip factor", OFFSET(frame_skip_factor), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"skip_exp", "frame skip exponent", OFFSET(frame_skip_exp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"skipcmp", "frame skip compare function", OFFSET(frame_skip_cmp), FF_OPT_TYPE_INT, FF_CMP_DCTMAX, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"border_mask", "increases the quantizer for macroblocks close to borders", OFFSET(border_masking), FF_OPT_TYPE_FLOAT, DEFAULT, -FLT_MAX, FLT_MAX, V|E},
+{"mblmin", "min macroblock lagrange factor (VBR)", OFFSET(mb_lmin), FF_OPT_TYPE_INT, FF_QP2LAMBDA * 2, 1, FF_LAMBDA_MAX, V|E},
+{"mblmax", "max macroblock lagrange factor (VBR)", OFFSET(mb_lmax), FF_OPT_TYPE_INT, FF_QP2LAMBDA * 31, 1, FF_LAMBDA_MAX, V|E},
+{"mepc", "motion estimation bitrate penalty compensation (1.0 = 256)", OFFSET(me_penalty_compensation), FF_OPT_TYPE_INT, 256, INT_MIN, INT_MAX, V|E},
+{"bidir_refine", "refine the two motion vectors used in bidirectional macroblocks", OFFSET(bidir_refine), FF_OPT_TYPE_INT, DEFAULT, 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},
+{"keyint_min", "minimum interval between IDR-frames (x264)", OFFSET(keyint_min), FF_OPT_TYPE_INT, 25, INT_MIN, INT_MAX, V|E},
+{"refs", "reference frames to consider for motion compensation (Snow)", OFFSET(refs), FF_OPT_TYPE_INT, 1, INT_MIN, INT_MAX, V|E},
+{"chromaoffset", "chroma qp offset from luma", OFFSET(chromaoffset), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"bframebias", "influences how often B-frames are used", OFFSET(bframebias), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"trellis", "rate-distortion optimal quantization", OFFSET(trellis), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|A|E},
+{"directpred", "direct mv prediction mode - 0 (none), 1 (spatial), 2 (temporal)", OFFSET(directpred), FF_OPT_TYPE_INT, 2, INT_MIN, INT_MAX, V|E},
+{"bpyramid", "allows B-frames to be used as references for predicting", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_BPYRAMID, INT_MIN, INT_MAX, V|E, "flags2"},
+{"wpred", "weighted biprediction for b-frames (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_WPRED, INT_MIN, INT_MAX, V|E, "flags2"},
+{"mixed_refs", "one reference per partition, as opposed to one reference per macroblock", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_MIXED_REFS, INT_MIN, INT_MAX, V|E, "flags2"},
+{"dct8x8", "high profile 8x8 transform (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_8X8DCT, INT_MIN, INT_MAX, V|E, "flags2"},
+{"fastpskip", "fast pskip (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_FASTPSKIP, INT_MIN, INT_MAX, V|E, "flags2"},
+{"aud", "access unit delimiters (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_AUD, INT_MIN, INT_MAX, V|E, "flags2"},
+{"brdo", "b-frame rate-distortion optimization", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_BRDO, INT_MIN, INT_MAX, V|E, "flags2"},
+{"skiprd", "RD optimal MB level residual skiping", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_SKIP_RD, INT_MIN, INT_MAX, V|E, "flags2"},
+{"complexityblur", "reduce fluctuations in qp (before curve compression)", OFFSET(complexityblur), FF_OPT_TYPE_FLOAT, 20.0, FLT_MIN, FLT_MAX, V|E},
+{"deblockalpha", "in-loop deblocking filter alphac0 parameter", OFFSET(deblockalpha), FF_OPT_TYPE_INT, DEFAULT, -6, 6, V|E},
+{"deblockbeta", "in-loop deblocking filter beta parameter", OFFSET(deblockbeta), FF_OPT_TYPE_INT, DEFAULT, -6, 6, V|E},
+{"partitions", "macroblock subpartition sizes to consider", OFFSET(partitions), FF_OPT_TYPE_FLAGS, DEFAULT, INT_MIN, INT_MAX, V|E, "partitions"},
+{"parti4x4", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_I4X4, INT_MIN, INT_MAX, V|E, "partitions"},
+{"parti8x8", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_I8X8, INT_MIN, INT_MAX, V|E, "partitions"},
+{"partp4x4", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_P4X4, INT_MIN, INT_MAX, V|E, "partitions"},
+{"partp8x8", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_P8X8, INT_MIN, INT_MAX, V|E, "partitions"},
+{"partb8x8", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_B8X8, INT_MIN, INT_MAX, V|E, "partitions"},
+{"sc_factor", "multiplied by qscale for each frame and added to scene_change_score", OFFSET(scenechange_factor), FF_OPT_TYPE_INT, 6, 0, INT_MAX, V|E},
+{"mv0_threshold", NULL, OFFSET(mv0_threshold), FF_OPT_TYPE_INT, 256, 0, INT_MAX, V|E},
+{"ivlc", "intra vlc table", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_INTRA_VLC, INT_MIN, INT_MAX, V|E, "flags2"},
+{"b_sensitivity", "adjusts sensitivity of b_frame_strategy 1", OFFSET(b_sensitivity), FF_OPT_TYPE_INT, 40, 1, INT_MAX, V|E},
+{"compression_level", NULL, OFFSET(compression_level), FF_OPT_TYPE_INT, FF_COMPRESSION_DEFAULT, INT_MIN, INT_MAX, V|A|E},
+{"use_lpc", "sets whether to use LPC mode (FLAC)", OFFSET(use_lpc), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
+{"lpc_coeff_precision", "LPC coefficient precision (FLAC)", OFFSET(lpc_coeff_precision), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, A|E},
+{"min_prediction_order", NULL, OFFSET(min_prediction_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
+{"max_prediction_order", NULL, OFFSET(max_prediction_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
+{"prediction_order_method", "search method for selecting prediction order", OFFSET(prediction_order_method), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
+{"min_partition_order", NULL, OFFSET(min_partition_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
+{"max_partition_order", NULL, OFFSET(max_partition_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
+{"timecode_frame_start", "GOP timecode frame start number, in non drop frame format", OFFSET(timecode_frame_start), FF_OPT_TYPE_INT, 0, 0, INT_MAX, V|E},
+{"drop_frame_timecode", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_DROP_FRAME_TIMECODE, INT_MIN, INT_MAX, V|E, "flags2"},
+{"non_linear_q", "use non linear quantizer", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_NON_LINEAR_QUANT, INT_MIN, INT_MAX, V|E, "flags2"},
+{NULL},
+};
+
+#undef A
+#undef V
+#undef S
+#undef E
+#undef D
+#undef DEFAULT
+
+static AVClass av_codec_context_class = { "AVCodecContext", context_to_name, options };
+
+void avcodec_get_context_defaults2(AVCodecContext *s, enum CodecType codec_type){
+ int flags=0;
+ memset(s, 0, sizeof(AVCodecContext));
+
+ s->av_class= &av_codec_context_class;
+
+ if(codec_type == CODEC_TYPE_AUDIO)
+ flags= AV_OPT_FLAG_AUDIO_PARAM;
+ else if(codec_type == CODEC_TYPE_VIDEO)
+ flags= AV_OPT_FLAG_VIDEO_PARAM;
+ else if(codec_type == CODEC_TYPE_SUBTITLE)
+ flags= AV_OPT_FLAG_SUBTITLE_PARAM;
+ av_opt_set_defaults2(s, flags, flags);
+
+ s->rc_eq= "tex^qComp";
+ s->time_base= (AVRational){0,1};
+ s->get_buffer= avcodec_default_get_buffer;
+ s->release_buffer= avcodec_default_release_buffer;
+ s->get_format= avcodec_default_get_format;
+ s->execute= avcodec_default_execute;
+ s->sample_aspect_ratio= (AVRational){0,1};
+ s->pix_fmt= PIX_FMT_NONE;
+ s->sample_fmt= SAMPLE_FMT_S16; // FIXME: set to NONE
+
+ s->palctrl = NULL;
+ s->reget_buffer= avcodec_default_reget_buffer;
+}
+
+AVCodecContext *avcodec_alloc_context2(enum CodecType codec_type){
+ AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));
+
+ if(avctx==NULL) return NULL;
+
+ avcodec_get_context_defaults2(avctx, codec_type);
+
+ return avctx;
+}
+
+void avcodec_get_context_defaults(AVCodecContext *s){
+ avcodec_get_context_defaults2(s, CODEC_TYPE_UNKNOWN);
+}
+
+AVCodecContext *avcodec_alloc_context(void){
+ return avcodec_alloc_context2(CODEC_TYPE_UNKNOWN);
+}
+
+void avcodec_get_frame_defaults(AVFrame *pic){
+ memset(pic, 0, sizeof(AVFrame));
+
+ pic->pts= AV_NOPTS_VALUE;
+ pic->key_frame= 1;
+}
+
+AVFrame *avcodec_alloc_frame(void){
+ AVFrame *pic= av_malloc(sizeof(AVFrame));
+
+ if(pic==NULL) return NULL;
+
+ avcodec_get_frame_defaults(pic);
+
+ return pic;
+}
+
+int avcodec_open(AVCodecContext *avctx, AVCodec *codec)
+{
+ int ret= -1;
+
+ entangled_thread_counter++;
+ if(entangled_thread_counter != 1){
+ av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
+ goto end;
+ }
+
+ if(avctx->codec)
+ goto end;
+
+ if (codec->priv_data_size > 0) {
+ avctx->priv_data = av_mallocz(codec->priv_data_size);
+ if (!avctx->priv_data)
+ goto end;
+ } else {
+ avctx->priv_data = NULL;
+ }
+
+ if(avctx->coded_width && avctx->coded_height)
+ avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
+ else if(avctx->width && 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);
+ goto end;
+ }
+
+ avctx->codec = codec;
+ avctx->codec_id = codec->id;
+ 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;
+ }
+ }
+ ret=0;
+end:
+ entangled_thread_counter--;
+ return ret;
+}
+
+int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
+ const short *samples)
+{
+ if(buf_size < FF_MIN_BUFFER_SIZE && 0){
+ av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n");
+ return -1;
+ }
+ if((avctx->codec->capabilities & CODEC_CAP_DELAY) || samples){
+ int ret = avctx->codec->encode(avctx, buf, buf_size, (void *)samples);
+ avctx->frame_number++;
+ return ret;
+ }else
+ return 0;
+}
+
+int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
+ const AVFrame *pict)
+{
+ if(buf_size < FF_MIN_BUFFER_SIZE){
+ av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n");
+ return -1;
+ }
+ if(avcodec_check_dimensions(avctx,avctx->width,avctx->height))
+ return -1;
+ if((avctx->codec->capabilities & CODEC_CAP_DELAY) || pict){
+ int ret = avctx->codec->encode(avctx, buf, buf_size, (void *)pict);
+ avctx->frame_number++;
+ emms_c(); //needed to avoid an emms_c() call before every return;
+
+ return ret;
+ }else
+ return 0;
+}
+
+int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
+ const AVSubtitle *sub)
+{
+ int ret;
+ ret = avctx->codec->encode(avctx, buf, buf_size, (void *)sub);
+ avctx->frame_number++;
+ return ret;
+}
+
+int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
+ int *got_picture_ptr,
+ uint8_t *buf, int buf_size)
+{
+ int ret;
+
+ *got_picture_ptr= 0;
+ if((avctx->coded_width||avctx->coded_height) && avcodec_check_dimensions(avctx,avctx->coded_width,avctx->coded_height))
+ return -1;
+ if((avctx->codec->capabilities & CODEC_CAP_DELAY) || buf_size){
+ ret = avctx->codec->decode(avctx, picture, got_picture_ptr,
+ buf, buf_size);
+
+ emms_c(); //needed to avoid an emms_c() call before every return;
+
+ if (*got_picture_ptr)
+ avctx->frame_number++;
+ }else
+ ret= 0;
+
+ return ret;
+}
+
+int avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples,
+ int *frame_size_ptr,
+ uint8_t *buf, int buf_size)
+{
+ int ret;
+
+ if((avctx->codec->capabilities & CODEC_CAP_DELAY) || buf_size){
+ //FIXME remove the check below _after_ ensuring that all audio check that the available space is enough
+ if(*frame_size_ptr < AVCODEC_MAX_AUDIO_FRAME_SIZE){
+ av_log(avctx, AV_LOG_ERROR, "buffer smaller than AVCODEC_MAX_AUDIO_FRAME_SIZE\n");
+ return -1;
+ }
+ if(*frame_size_ptr < FF_MIN_BUFFER_SIZE ||
+ *frame_size_ptr < avctx->channels * avctx->frame_size * sizeof(int16_t) ||
+ *frame_size_ptr < buf_size){
+ av_log(avctx, AV_LOG_ERROR, "buffer %d too small\n", *frame_size_ptr);
+ return -1;
+ }
+
+ ret = avctx->codec->decode(avctx, samples, frame_size_ptr,
+ buf, buf_size);
+ avctx->frame_number++;
+ }else{
+ ret= 0;
+ *frame_size_ptr=0;
+ }
+ return ret;
+}
+
+#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
+int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples,
+ int *frame_size_ptr,
+ uint8_t *buf, int buf_size){
+ *frame_size_ptr= AVCODEC_MAX_AUDIO_FRAME_SIZE;
+ return avcodec_decode_audio2(avctx, samples, frame_size_ptr, buf, buf_size);
+}
+#endif
+
+int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub,
+ int *got_sub_ptr,
+ const uint8_t *buf, int buf_size)
+{
+ int ret;
+
+ *got_sub_ptr = 0;
+ ret = avctx->codec->decode(avctx, sub, got_sub_ptr,
+ (uint8_t *)buf, buf_size);
+ if (*got_sub_ptr)
+ avctx->frame_number++;
+ return ret;
+}
+
+int avcodec_close(AVCodecContext *avctx)
+{
+ entangled_thread_counter++;
+ if(entangled_thread_counter != 1){
+ av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
+ entangled_thread_counter--;
+ return -1;
+ }
+
+ if (avctx->codec->close)
+ avctx->codec->close(avctx);
+ avcodec_default_free_buffers(avctx);
+ av_freep(&avctx->priv_data);
+ avctx->codec = NULL;
+ entangled_thread_counter--;
+ return 0;
+}
+
+AVCodec *avcodec_find_encoder(enum CodecID id)
+{
+ AVCodec *p;
+ p = first_avcodec;
+ while (p) {
+ if (p->encode != NULL && p->id == id)
+ return p;
+ p = p->next;
+ }
+ return NULL;
+}
+
+AVCodec *avcodec_find_encoder_by_name(const char *name)
+{
+ AVCodec *p;
+ p = first_avcodec;
+ while (p) {
+ if (p->encode != NULL && strcmp(name,p->name) == 0)
+ return p;
+ p = p->next;
+ }
+ return NULL;
+}
+
+AVCodec *avcodec_find_decoder(enum CodecID id)
+{
+ AVCodec *p;
+ p = first_avcodec;
+ while (p) {
+ if (p->decode != NULL && p->id == id)
+ return p;
+ p = p->next;
+ }
+ return NULL;
+}
+
+AVCodec *avcodec_find_decoder_by_name(const char *name)
+{
+ AVCodec *p;
+ p = first_avcodec;
+ while (p) {
+ if (p->decode != NULL && strcmp(name,p->name) == 0)
+ return p;
+ p = p->next;
+ }
+ return NULL;
+}
+
+void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
+{
+ const char *codec_name;
+ AVCodec *p;
+ char buf1[32];
+ char channels_str[100];
+ int bitrate;
+
+ if (encode)
+ p = avcodec_find_encoder(enc->codec_id);
+ else
+ p = avcodec_find_decoder(enc->codec_id);
+
+ if (p) {
+ codec_name = p->name;
+ if (!encode && enc->codec_id == CODEC_ID_MP3) {
+ if (enc->sub_id == 2)
+ codec_name = "mp2";
+ else if (enc->sub_id == 1)
+ codec_name = "mp1";
+ }
+ } else if (enc->codec_id == CODEC_ID_MPEG2TS) {
+ /* fake mpeg2 transport stream codec (currently not
+ registered) */
+ codec_name = "mpeg2ts";
+ } else if (enc->codec_name[0] != '\0') {
+ codec_name = enc->codec_name;
+ } else {
+ /* output avi tags */
+ if( isprint(enc->codec_tag&0xFF) && isprint((enc->codec_tag>>8)&0xFF)
+ && isprint((enc->codec_tag>>16)&0xFF) && isprint((enc->codec_tag>>24)&0xFF)){
+ snprintf(buf1, sizeof(buf1), "%c%c%c%c / 0x%04X",
+ enc->codec_tag & 0xff,
+ (enc->codec_tag >> 8) & 0xff,
+ (enc->codec_tag >> 16) & 0xff,
+ (enc->codec_tag >> 24) & 0xff,
+ enc->codec_tag);
+ } else {
+ snprintf(buf1, sizeof(buf1), "0x%04x", enc->codec_tag);
+ }
+ codec_name = buf1;
+ }
+
+ switch(enc->codec_type) {
+ case CODEC_TYPE_VIDEO:
+ snprintf(buf, buf_size,
+ "Video: %s%s",
+ codec_name, enc->mb_decision ? " (hq)" : "");
+ if (enc->pix_fmt != PIX_FMT_NONE) {
+ snprintf(buf + strlen(buf), buf_size - strlen(buf),
+ ", %s",
+ avcodec_get_pix_fmt_name(enc->pix_fmt));
+ }
+ if (enc->width) {
+ snprintf(buf + strlen(buf), buf_size - strlen(buf),
+ ", %dx%d",
+ enc->width, enc->height);
+ if(av_log_level >= AV_LOG_DEBUG){
+ int g= ff_gcd(enc->time_base.num, enc->time_base.den);
+ snprintf(buf + strlen(buf), buf_size - strlen(buf),
+ ", %d/%d",
+ enc->time_base.num/g, enc->time_base.den/g);
+ }
+ }
+ if (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:
+ snprintf(buf, buf_size,
+ "Audio: %s",
+ codec_name);
+ switch (enc->channels) {
+ case 1:
+ strcpy(channels_str, "mono");
+ break;
+ case 2:
+ strcpy(channels_str, "stereo");
+ break;
+ case 6:
+ strcpy(channels_str, "5:1");
+ break;
+ default:
+ snprintf(channels_str, sizeof(channels_str), "%d channels", enc->channels);
+ break;
+ }
+ if (enc->sample_rate) {
+ snprintf(buf + strlen(buf), buf_size - strlen(buf),
+ ", %d Hz, %s",
+ enc->sample_rate,
+ channels_str);
+ }
+
+ /* for PCM codecs, compute bitrate directly */
+ switch(enc->codec_id) {
+ case CODEC_ID_PCM_S32LE:
+ case CODEC_ID_PCM_S32BE:
+ case CODEC_ID_PCM_U32LE:
+ case CODEC_ID_PCM_U32BE:
+ 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_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:
+ bitrate = enc->sample_rate * enc->channels * 8;
+ break;
+ default:
+ bitrate = enc->bit_rate;
+ break;
+ }
+ break;
+ case CODEC_TYPE_DATA:
+ snprintf(buf, buf_size, "Data: %s", codec_name);
+ bitrate = enc->bit_rate;
+ break;
+ case CODEC_TYPE_SUBTITLE:
+ snprintf(buf, buf_size, "Subtitle: %s", codec_name);
+ bitrate = enc->bit_rate;
+ break;
+ default:
+ snprintf(buf, buf_size, "Invalid Codec type %d", enc->codec_type);
+ return;
+ }
+ if (encode) {
+ if (enc->flags & CODEC_FLAG_PASS1)
+ snprintf(buf + strlen(buf), buf_size - strlen(buf),
+ ", pass 1");
+ if (enc->flags & CODEC_FLAG_PASS2)
+ snprintf(buf + strlen(buf), buf_size - strlen(buf),
+ ", pass 2");
+ }
+ if (bitrate != 0) {
+ snprintf(buf + strlen(buf), buf_size - strlen(buf),
+ ", %d kb/s", bitrate / 1000);
+ }
+}
+
+unsigned avcodec_version( void )
+{
+ return LIBAVCODEC_VERSION_INT;
+}
+
+unsigned avcodec_build( void )
+{
+ return LIBAVCODEC_BUILD;
+}
+
+static void init_crcs(void){
+#if LIBAVUTIL_VERSION_INT < (50<<16)
+ av_crc04C11DB7= av_mallocz_static(sizeof(AVCRC) * 257);
+ av_crc8005 = av_mallocz_static(sizeof(AVCRC) * 257);
+ av_crc07 = av_mallocz_static(sizeof(AVCRC) * 257);
+#endif
+ av_crc_init(av_crc04C11DB7, 0, 32, 0x04c11db7, sizeof(AVCRC)*257);
+ av_crc_init(av_crc8005 , 0, 16, 0x8005 , sizeof(AVCRC)*257);
+ av_crc_init(av_crc07 , 0, 8, 0x07 , sizeof(AVCRC)*257);
+}
+
+void avcodec_init(void)
+{
+ static int inited = 0;
+
+ if (inited != 0)
+ return;
+ inited = 1;
+
+ dsputil_static_init();
+ init_crcs();
+}
+
+void avcodec_flush_buffers(AVCodecContext *avctx)
+{
+ if(avctx->codec->flush)
+ avctx->codec->flush(avctx);
+}
+
+void avcodec_default_free_buffers(AVCodecContext *s){
+ int i, j;
+
+ if(s->internal_buffer==NULL) return;
+
+ for(i=0; i<INTERNAL_BUFFER_SIZE; i++){
+ InternalBuffer *buf= &((InternalBuffer*)s->internal_buffer)[i];
+ for(j=0; j<4; j++){
+ av_freep(&buf->base[j]);
+ buf->data[j]= NULL;
+ }
+ }
+ av_freep(&s->internal_buffer);
+
+ s->internal_buffer_count=0;
+}
+
+char av_get_pict_type_char(int pict_type){
+ switch(pict_type){
+ case I_TYPE: return 'I';
+ case P_TYPE: return 'P';
+ case B_TYPE: return 'B';
+ case S_TYPE: return 'S';
+ case SI_TYPE:return 'i';
+ case SP_TYPE:return 'p';
+ default: return '?';
+ }
+}
+
+int av_get_bits_per_sample(enum CodecID codec_id){
+ switch(codec_id){
+ case CODEC_ID_ADPCM_SBPRO_2:
+ return 2;
+ case CODEC_ID_ADPCM_SBPRO_3:
+ return 3;
+ case CODEC_ID_ADPCM_SBPRO_4:
+ case CODEC_ID_ADPCM_CT:
+ return 4;
+ case CODEC_ID_PCM_ALAW:
+ case CODEC_ID_PCM_MULAW:
+ case CODEC_ID_PCM_S8:
+ case CODEC_ID_PCM_U8:
+ return 8;
+ case CODEC_ID_PCM_S16BE:
+ case CODEC_ID_PCM_S16LE:
+ case CODEC_ID_PCM_U16BE:
+ case CODEC_ID_PCM_U16LE:
+ return 16;
+ case CODEC_ID_PCM_S24DAUD:
+ case CODEC_ID_PCM_S24BE:
+ case CODEC_ID_PCM_S24LE:
+ case CODEC_ID_PCM_U24BE:
+ case CODEC_ID_PCM_U24LE:
+ return 24;
+ case CODEC_ID_PCM_S32BE:
+ case CODEC_ID_PCM_S32LE:
+ case CODEC_ID_PCM_U32BE:
+ case CODEC_ID_PCM_U32LE:
+ return 32;
+ default:
+ return 0;
+ }
+}
+
+#if !defined(HAVE_THREADS)
+int avcodec_thread_init(AVCodecContext *s, int thread_count){
+ return -1;
+}
+#endif
+
+unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
+{
+ unsigned int n = 0;
+
+ while(v >= 0xff) {
+ *s++ = 0xff;
+ v -= 0xff;
+ n++;
+ }
+ *s = v;
+ n++;
+ return n;
+}
+
+/* Wrapper to work around the lack of mkstemp() on mingw/cygin.
+ * Also, tries to create file in /tmp first, if possible.
+ * *prefix can be a character constant; *filename will be allocated internally.
+ * Returns file descriptor of opened file (or -1 on error)
+ * and opened file name in **filename. */
+int av_tempfile(char *prefix, char **filename) {
+ int fd=-1;
+#ifdef __MINGW32__
+ *filename = tempnam(".", prefix);
+#else
+ size_t len = strlen(prefix) + 12; /* room for "/tmp/" and "XXXXXX\0" */
+ *filename = av_malloc(len);
+#endif
+ /* -----common section-----*/
+ if (*filename == NULL) {
+ av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot allocate file name\n");
+ return -1;
+ }
+#ifdef __MINGW32__
+ fd = open(*filename, _O_RDWR | _O_BINARY | _O_CREAT, 0444);
+#else
+ snprintf(*filename, len, "/tmp/%sXXXXXX", prefix);
+ fd = mkstemp(*filename);
+ if (fd < 0) {
+ snprintf(*filename, len, "./%sXXXXXX", prefix);
+ fd = mkstemp(*filename);
+ }
+#endif
+ /* -----common section-----*/
+ if (fd < 0) {
+ av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot open temporary file %s\n", *filename);
+ return -1;
+ }
+ return fd; /* success */
+}
diff --git a/contrib/ffmpeg/libavcodec/vc1.c b/contrib/ffmpeg/libavcodec/vc1.c
new file mode 100644
index 000000000..84868904d
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/vc1.c
@@ -0,0 +1,4626 @@
+/*
+ * VC-1 and WMV3 decoder
+ * Copyright (c) 2006-2007 Konstantin Shishkov
+ * Partly based on vc9.c (c) 2005 Anonymous, Alex Beregszaszi, 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 vc1.c
+ * VC-1 and WMV3 decoder
+ *
+ */
+#include "common.h"
+#include "dsputil.h"
+#include "avcodec.h"
+#include "mpegvideo.h"
+#include "vc1data.h"
+#include "vc1acdata.h"
+
+#undef NDEBUG
+#include <assert.h>
+
+extern const uint32_t ff_table0_dc_lum[120][2], ff_table1_dc_lum[120][2];
+extern const uint32_t ff_table0_dc_chroma[120][2], ff_table1_dc_chroma[120][2];
+extern VLC ff_msmp4_dc_luma_vlc[2], ff_msmp4_dc_chroma_vlc[2];
+#define MB_INTRA_VLC_BITS 9
+extern VLC ff_msmp4_mb_i_vlc;
+extern const uint16_t ff_msmp4_mb_i_table[64][2];
+#define DC_VLC_BITS 9
+#define AC_VLC_BITS 9
+static const uint16_t table_mb_intra[64][2];
+
+/** Markers used if VC-1 AP frame data */
+//@{
+enum VC1Code{
+ VC1_CODE_RES0 = 0x00000100,
+ VC1_CODE_ENDOFSEQ = 0x0000010A,
+ VC1_CODE_SLICE,
+ VC1_CODE_FIELD,
+ VC1_CODE_FRAME,
+ VC1_CODE_ENTRYPOINT,
+ VC1_CODE_SEQHDR,
+};
+//@}
+
+/** Available Profiles */
+//@{
+enum Profile {
+ PROFILE_SIMPLE,
+ PROFILE_MAIN,
+ PROFILE_COMPLEX, ///< TODO: WMV9 specific
+ PROFILE_ADVANCED
+};
+//@}
+
+/** Sequence quantizer mode */
+//@{
+enum QuantMode {
+ QUANT_FRAME_IMPLICIT, ///< Implicitly specified at frame level
+ QUANT_FRAME_EXPLICIT, ///< Explicitly specified at frame level
+ QUANT_NON_UNIFORM, ///< Non-uniform quant used for all frames
+ QUANT_UNIFORM ///< Uniform quant used for all frames
+};
+//@}
+
+/** Where quant can be changed */
+//@{
+enum DQProfile {
+ DQPROFILE_FOUR_EDGES,
+ DQPROFILE_DOUBLE_EDGES,
+ DQPROFILE_SINGLE_EDGE,
+ DQPROFILE_ALL_MBS
+};
+//@}
+
+/** @name Where quant can be changed
+ */
+//@{
+enum DQSingleEdge {
+ DQSINGLE_BEDGE_LEFT,
+ DQSINGLE_BEDGE_TOP,
+ DQSINGLE_BEDGE_RIGHT,
+ DQSINGLE_BEDGE_BOTTOM
+};
+//@}
+
+/** Which pair of edges is quantized with ALTPQUANT */
+//@{
+enum DQDoubleEdge {
+ DQDOUBLE_BEDGE_TOPLEFT,
+ DQDOUBLE_BEDGE_TOPRIGHT,
+ DQDOUBLE_BEDGE_BOTTOMRIGHT,
+ DQDOUBLE_BEDGE_BOTTOMLEFT
+};
+//@}
+
+/** MV modes for P frames */
+//@{
+enum MVModes {
+ MV_PMODE_1MV_HPEL_BILIN,
+ MV_PMODE_1MV,
+ MV_PMODE_1MV_HPEL,
+ MV_PMODE_MIXED_MV,
+ MV_PMODE_INTENSITY_COMP
+};
+//@}
+
+/** @name MV types for B frames */
+//@{
+enum BMVTypes {
+ BMV_TYPE_BACKWARD,
+ BMV_TYPE_FORWARD,
+ BMV_TYPE_INTERPOLATED
+};
+//@}
+
+/** @name Block types for P/B frames */
+//@{
+enum TransformTypes {
+ TT_8X8,
+ TT_8X4_BOTTOM,
+ TT_8X4_TOP,
+ TT_8X4, //Both halves
+ TT_4X8_RIGHT,
+ TT_4X8_LEFT,
+ TT_4X8, //Both halves
+ TT_4X4
+};
+//@}
+
+/** Table for conversion between TTBLK and TTMB */
+static const int ttblk_to_tt[3][8] = {
+ { TT_8X4, TT_4X8, TT_8X8, TT_4X4, TT_8X4_TOP, TT_8X4_BOTTOM, TT_4X8_RIGHT, TT_4X8_LEFT },
+ { TT_8X8, TT_4X8_RIGHT, TT_4X8_LEFT, TT_4X4, TT_8X4, TT_4X8, TT_8X4_BOTTOM, TT_8X4_TOP },
+ { TT_8X8, TT_4X8, TT_4X4, TT_8X4_BOTTOM, TT_4X8_RIGHT, TT_4X8_LEFT, TT_8X4, TT_8X4_TOP }
+};
+
+static const int ttfrm_to_tt[4] = { TT_8X8, TT_8X4, TT_4X8, TT_4X4 };
+
+/** MV P mode - the 5th element is only used for mode 1 */
+static const uint8_t mv_pmode_table[2][5] = {
+ { MV_PMODE_1MV_HPEL_BILIN, MV_PMODE_1MV, MV_PMODE_1MV_HPEL, MV_PMODE_INTENSITY_COMP, MV_PMODE_MIXED_MV },
+ { MV_PMODE_1MV, MV_PMODE_MIXED_MV, MV_PMODE_1MV_HPEL, MV_PMODE_INTENSITY_COMP, MV_PMODE_1MV_HPEL_BILIN }
+};
+static const uint8_t mv_pmode_table2[2][4] = {
+ { MV_PMODE_1MV_HPEL_BILIN, MV_PMODE_1MV, MV_PMODE_1MV_HPEL, MV_PMODE_MIXED_MV },
+ { MV_PMODE_1MV, MV_PMODE_MIXED_MV, MV_PMODE_1MV_HPEL, MV_PMODE_1MV_HPEL_BILIN }
+};
+
+/** One more frame type */
+#define BI_TYPE 7
+
+static const int fps_nr[5] = { 24, 25, 30, 50, 60 },
+ fps_dr[2] = { 1000, 1001 };
+static const uint8_t pquant_table[3][32] = {
+ { /* Implicit quantizer */
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 6, 7, 8, 9, 10, 11, 12,
+ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 29, 31
+ },
+ { /* Explicit quantizer, pquantizer uniform */
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
+ },
+ { /* Explicit quantizer, pquantizer non-uniform */
+ 0, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
+ 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29, 31
+ }
+};
+
+/** @name VC-1 VLC tables and defines
+ * @todo TODO move this into the context
+ */
+//@{
+#define VC1_BFRACTION_VLC_BITS 7
+static VLC vc1_bfraction_vlc;
+#define VC1_IMODE_VLC_BITS 4
+static VLC vc1_imode_vlc;
+#define VC1_NORM2_VLC_BITS 3
+static VLC vc1_norm2_vlc;
+#define VC1_NORM6_VLC_BITS 9
+static VLC vc1_norm6_vlc;
+/* Could be optimized, one table only needs 8 bits */
+#define VC1_TTMB_VLC_BITS 9 //12
+static VLC vc1_ttmb_vlc[3];
+#define VC1_MV_DIFF_VLC_BITS 9 //15
+static VLC vc1_mv_diff_vlc[4];
+#define VC1_CBPCY_P_VLC_BITS 9 //14
+static VLC vc1_cbpcy_p_vlc[4];
+#define VC1_4MV_BLOCK_PATTERN_VLC_BITS 6
+static VLC vc1_4mv_block_pattern_vlc[4];
+#define VC1_TTBLK_VLC_BITS 5
+static VLC vc1_ttblk_vlc[3];
+#define VC1_SUBBLKPAT_VLC_BITS 6
+static VLC vc1_subblkpat_vlc[3];
+
+static VLC vc1_ac_coeff_table[8];
+//@}
+
+enum CodingSet {
+ CS_HIGH_MOT_INTRA = 0,
+ CS_HIGH_MOT_INTER,
+ CS_LOW_MOT_INTRA,
+ CS_LOW_MOT_INTER,
+ CS_MID_RATE_INTRA,
+ CS_MID_RATE_INTER,
+ CS_HIGH_RATE_INTRA,
+ CS_HIGH_RATE_INTER
+};
+
+/** @name Overlap conditions for Advanced Profile */
+//@{
+enum COTypes {
+ CONDOVER_NONE = 0,
+ CONDOVER_ALL,
+ CONDOVER_SELECT
+};
+//@}
+
+
+/** The VC1 Context
+ * @fixme Change size wherever another size is more efficient
+ * Many members are only used for Advanced Profile
+ */
+typedef struct VC1Context{
+ MpegEncContext s;
+
+ int bits;
+
+ /** Simple/Main Profile sequence header */
+ //@{
+ int res_sm; ///< reserved, 2b
+ int res_x8; ///< reserved
+ int multires; ///< frame-level RESPIC syntax element present
+ int res_fasttx; ///< reserved, always 1
+ int res_transtab; ///< reserved, always 0
+ int rangered; ///< RANGEREDFRM (range reduction) syntax element present
+ ///< at frame level
+ int res_rtm_flag; ///< reserved, set to 1
+ int reserved; ///< reserved
+ //@}
+
+ /** Advanced Profile */
+ //@{
+ int level; ///< 3bits, for Advanced/Simple Profile, provided by TS layer
+ int chromaformat; ///< 2bits, 2=4:2:0, only defined
+ int postprocflag; ///< Per-frame processing suggestion flag present
+ int broadcast; ///< TFF/RFF present
+ int interlace; ///< Progressive/interlaced (RPTFTM syntax element)
+ int tfcntrflag; ///< TFCNTR present
+ int panscanflag; ///< NUMPANSCANWIN, TOPLEFT{X,Y}, BOTRIGHT{X,Y} present
+ int extended_dmv; ///< Additional extended dmv range at P/B frame-level
+ int color_prim; ///< 8bits, chroma coordinates of the color primaries
+ int transfer_char; ///< 8bits, Opto-electronic transfer characteristics
+ int matrix_coef; ///< 8bits, Color primaries->YCbCr transform matrix
+ int hrd_param_flag; ///< Presence of Hypothetical Reference
+ ///< Decoder parameters
+ int psf; ///< Progressive Segmented Frame
+ //@}
+
+ /** Sequence header data for all Profiles
+ * TODO: choose between ints, uint8_ts and monobit flags
+ */
+ //@{
+ int profile; ///< 2bits, Profile
+ int frmrtq_postproc; ///< 3bits,
+ int bitrtq_postproc; ///< 5bits, quantized framerate-based postprocessing strength
+ int fastuvmc; ///< Rounding of qpel vector to hpel ? (not in Simple)
+ int extended_mv; ///< Ext MV in P/B (not in Simple)
+ int dquant; ///< How qscale varies with MBs, 2bits (not in Simple)
+ int vstransform; ///< variable-size [48]x[48] transform type + info
+ int overlap; ///< overlapped transforms in use
+ int quantizer_mode; ///< 2bits, quantizer mode used for sequence, see QUANT_*
+ int finterpflag; ///< INTERPFRM present
+ //@}
+
+ /** Frame decoding info for all profiles */
+ //@{
+ uint8_t mv_mode; ///< MV coding monde
+ uint8_t mv_mode2; ///< Secondary MV coding mode (B frames)
+ int k_x; ///< Number of bits for MVs (depends on MV range)
+ int k_y; ///< Number of bits for MVs (depends on MV range)
+ int range_x, range_y; ///< MV range
+ uint8_t pq, altpq; ///< Current/alternate frame quantizer scale
+ /** pquant parameters */
+ //@{
+ uint8_t dquantfrm;
+ uint8_t dqprofile;
+ uint8_t dqsbedge;
+ uint8_t dqbilevel;
+ //@}
+ /** AC coding set indexes
+ * @see 8.1.1.10, p(1)10
+ */
+ //@{
+ int c_ac_table_index; ///< Chroma index from ACFRM element
+ int y_ac_table_index; ///< Luma index from AC2FRM element
+ //@}
+ int ttfrm; ///< Transform type info present at frame level
+ uint8_t ttmbf; ///< Transform type flag
+ uint8_t ttblk4x4; ///< Value of ttblk which indicates a 4x4 transform
+ int codingset; ///< index of current table set from 11.8 to use for luma block decoding
+ int codingset2; ///< index of current table set from 11.8 to use for chroma block decoding
+ int pqindex; ///< raw pqindex used in coding set selection
+ int a_avail, c_avail;
+ uint8_t *mb_type_base, *mb_type[3];
+
+
+ /** Luma compensation parameters */
+ //@{
+ uint8_t lumscale;
+ uint8_t lumshift;
+ //@}
+ int16_t bfraction; ///< Relative position % anchors=> how to scale MVs
+ uint8_t halfpq; ///< Uniform quant over image and qp+.5
+ uint8_t respic; ///< Frame-level flag for resized images
+ int buffer_fullness; ///< HRD info
+ /** Ranges:
+ * -# 0 -> [-64n 63.f] x [-32, 31.f]
+ * -# 1 -> [-128, 127.f] x [-64, 63.f]
+ * -# 2 -> [-512, 511.f] x [-128, 127.f]
+ * -# 3 -> [-1024, 1023.f] x [-256, 255.f]
+ */
+ uint8_t mvrange;
+ uint8_t pquantizer; ///< Uniform (over sequence) quantizer in use
+ VLC *cbpcy_vlc; ///< CBPCY VLC table
+ int tt_index; ///< Index for Transform Type tables
+ uint8_t* mv_type_mb_plane; ///< bitplane for mv_type == (4MV)
+ uint8_t* direct_mb_plane; ///< bitplane for "direct" MBs
+ int mv_type_is_raw; ///< mv type mb plane is not coded
+ int dmb_is_raw; ///< direct mb plane is raw
+ int skip_is_raw; ///< skip mb plane is not coded
+ uint8_t luty[256], lutuv[256]; // lookup tables used for intensity compensation
+ int use_ic; ///< use intensity compensation in B-frames
+ int rnd; ///< rounding control
+
+ /** Frame decoding info for S/M profiles only */
+ //@{
+ uint8_t rangeredfrm; ///< out_sample = CLIP((in_sample-128)*2+128)
+ uint8_t interpfrm;
+ //@}
+
+ /** Frame decoding info for Advanced profile */
+ //@{
+ uint8_t fcm; ///< 0->Progressive, 2->Frame-Interlace, 3->Field-Interlace
+ uint8_t numpanscanwin;
+ uint8_t tfcntr;
+ uint8_t rptfrm, tff, rff;
+ uint16_t topleftx;
+ uint16_t toplefty;
+ uint16_t bottomrightx;
+ uint16_t bottomrighty;
+ uint8_t uvsamp;
+ uint8_t postproc;
+ int hrd_num_leaky_buckets;
+ uint8_t bit_rate_exponent;
+ uint8_t buffer_size_exponent;
+ uint8_t* acpred_plane; ///< AC prediction flags bitplane
+ int acpred_is_raw;
+ uint8_t* over_flags_plane; ///< Overflags bitplane
+ int overflg_is_raw;
+ uint8_t condover;
+ uint16_t *hrd_rate, *hrd_buffer;
+ uint8_t *hrd_fullness;
+ uint8_t range_mapy_flag;
+ uint8_t range_mapuv_flag;
+ uint8_t range_mapy;
+ uint8_t range_mapuv;
+ //@}
+
+ int p_frame_skipped;
+ int bi_type;
+} VC1Context;
+
+/**
+ * Get unary code of limited length
+ * @fixme FIXME Slow and ugly
+ * @param gb GetBitContext
+ * @param[in] stop The bitstop value (unary code of 1's or 0's)
+ * @param[in] len Maximum length
+ * @return Unary length/index
+ */
+static int get_prefix(GetBitContext *gb, int stop, int len)
+{
+#if 1
+ int i;
+
+ for(i = 0; i < len && get_bits1(gb) != stop; i++);
+ return i;
+/* int i = 0, tmp = !stop;
+
+ while (i != len && tmp != stop)
+ {
+ tmp = get_bits(gb, 1);
+ i++;
+ }
+ if (i == len && tmp != stop) return len+1;
+ return i;*/
+#else
+ unsigned int buf;
+ int log;
+
+ OPEN_READER(re, gb);
+ UPDATE_CACHE(re, gb);
+ buf=GET_CACHE(re, gb); //Still not sure
+ if (stop) buf = ~buf;
+
+ log= av_log2(-buf); //FIXME: -?
+ if (log < limit){
+ LAST_SKIP_BITS(re, gb, log+1);
+ CLOSE_READER(re, gb);
+ return log;
+ }
+
+ LAST_SKIP_BITS(re, gb, limit);
+ CLOSE_READER(re, gb);
+ return limit;
+#endif
+}
+
+static inline int decode210(GetBitContext *gb){
+ int n;
+ n = get_bits1(gb);
+ if (n == 1)
+ return 0;
+ else
+ return 2 - get_bits1(gb);
+}
+
+/**
+ * Init VC-1 specific tables and VC1Context members
+ * @param v The VC1Context to initialize
+ * @return Status
+ */
+static int vc1_init_common(VC1Context *v)
+{
+ static int done = 0;
+ int i = 0;
+
+ v->hrd_rate = v->hrd_buffer = NULL;
+
+ /* VLC tables */
+ if(!done)
+ {
+ done = 1;
+ init_vlc(&vc1_bfraction_vlc, VC1_BFRACTION_VLC_BITS, 23,
+ vc1_bfraction_bits, 1, 1,
+ vc1_bfraction_codes, 1, 1, 1);
+ init_vlc(&vc1_norm2_vlc, VC1_NORM2_VLC_BITS, 4,
+ vc1_norm2_bits, 1, 1,
+ vc1_norm2_codes, 1, 1, 1);
+ init_vlc(&vc1_norm6_vlc, VC1_NORM6_VLC_BITS, 64,
+ vc1_norm6_bits, 1, 1,
+ vc1_norm6_codes, 2, 2, 1);
+ init_vlc(&vc1_imode_vlc, VC1_IMODE_VLC_BITS, 7,
+ vc1_imode_bits, 1, 1,
+ vc1_imode_codes, 1, 1, 1);
+ for (i=0; i<3; i++)
+ {
+ init_vlc(&vc1_ttmb_vlc[i], VC1_TTMB_VLC_BITS, 16,
+ vc1_ttmb_bits[i], 1, 1,
+ vc1_ttmb_codes[i], 2, 2, 1);
+ init_vlc(&vc1_ttblk_vlc[i], VC1_TTBLK_VLC_BITS, 8,
+ vc1_ttblk_bits[i], 1, 1,
+ vc1_ttblk_codes[i], 1, 1, 1);
+ init_vlc(&vc1_subblkpat_vlc[i], VC1_SUBBLKPAT_VLC_BITS, 15,
+ vc1_subblkpat_bits[i], 1, 1,
+ vc1_subblkpat_codes[i], 1, 1, 1);
+ }
+ for(i=0; i<4; i++)
+ {
+ init_vlc(&vc1_4mv_block_pattern_vlc[i], VC1_4MV_BLOCK_PATTERN_VLC_BITS, 16,
+ vc1_4mv_block_pattern_bits[i], 1, 1,
+ vc1_4mv_block_pattern_codes[i], 1, 1, 1);
+ init_vlc(&vc1_cbpcy_p_vlc[i], VC1_CBPCY_P_VLC_BITS, 64,
+ vc1_cbpcy_p_bits[i], 1, 1,
+ vc1_cbpcy_p_codes[i], 2, 2, 1);
+ init_vlc(&vc1_mv_diff_vlc[i], VC1_MV_DIFF_VLC_BITS, 73,
+ vc1_mv_diff_bits[i], 1, 1,
+ vc1_mv_diff_codes[i], 2, 2, 1);
+ }
+ for(i=0; i<8; i++)
+ init_vlc(&vc1_ac_coeff_table[i], AC_VLC_BITS, vc1_ac_sizes[i],
+ &vc1_ac_tables[i][0][1], 8, 4,
+ &vc1_ac_tables[i][0][0], 8, 4, 1);
+ 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, 1);
+ }
+
+ /* Other defaults */
+ v->pq = -1;
+ v->mvrange = 0; /* 7.1.1.18, p80 */
+
+ return 0;
+}
+
+/***********************************************************************/
+/**
+ * @defgroup bitplane VC9 Bitplane decoding
+ * @see 8.7, p56
+ * @{
+ */
+
+/** @addtogroup bitplane
+ * Imode types
+ * @{
+ */
+enum Imode {
+ IMODE_RAW,
+ IMODE_NORM2,
+ IMODE_DIFF2,
+ IMODE_NORM6,
+ IMODE_DIFF6,
+ IMODE_ROWSKIP,
+ IMODE_COLSKIP
+};
+/** @} */ //imode defines
+
+/** Decode rows by checking if they are skipped
+ * @param plane Buffer to store decoded bits
+ * @param[in] width Width of this buffer
+ * @param[in] height Height of this buffer
+ * @param[in] stride of this buffer
+ */
+static void decode_rowskip(uint8_t* plane, int width, int height, int stride, GetBitContext *gb){
+ int x, y;
+
+ for (y=0; y<height; y++){
+ if (!get_bits(gb, 1)) //rowskip
+ memset(plane, 0, width);
+ else
+ for (x=0; x<width; x++)
+ plane[x] = get_bits(gb, 1);
+ plane += stride;
+ }
+}
+
+/** Decode columns by checking if they are skipped
+ * @param plane Buffer to store decoded bits
+ * @param[in] width Width of this buffer
+ * @param[in] height Height of this buffer
+ * @param[in] stride of this buffer
+ * @fixme FIXME: Optimize
+ */
+static void decode_colskip(uint8_t* plane, int width, int height, int stride, GetBitContext *gb){
+ int x, y;
+
+ for (x=0; x<width; x++){
+ if (!get_bits(gb, 1)) //colskip
+ for (y=0; y<height; y++)
+ plane[y*stride] = 0;
+ else
+ for (y=0; y<height; y++)
+ plane[y*stride] = get_bits(gb, 1);
+ plane ++;
+ }
+}
+
+/** Decode a bitplane's bits
+ * @param bp Bitplane where to store the decode bits
+ * @param v VC-1 context for bit reading and logging
+ * @return Status
+ * @fixme FIXME: Optimize
+ */
+static int bitplane_decoding(uint8_t* data, int *raw_flag, VC1Context *v)
+{
+ GetBitContext *gb = &v->s.gb;
+
+ int imode, x, y, code, offset;
+ uint8_t invert, *planep = data;
+ int width, height, stride;
+
+ width = v->s.mb_width;
+ height = v->s.mb_height;
+ stride = v->s.mb_stride;
+ invert = get_bits(gb, 1);
+ imode = get_vlc2(gb, vc1_imode_vlc.table, VC1_IMODE_VLC_BITS, 1);
+
+ *raw_flag = 0;
+ switch (imode)
+ {
+ case IMODE_RAW:
+ //Data is actually read in the MB layer (same for all tests == "raw")
+ *raw_flag = 1; //invert ignored
+ return invert;
+ case IMODE_DIFF2:
+ case IMODE_NORM2:
+ if ((height * width) & 1)
+ {
+ *planep++ = get_bits(gb, 1);
+ offset = 1;
+ }
+ else offset = 0;
+ // decode bitplane as one long line
+ for (y = offset; y < height * width; y += 2) {
+ code = get_vlc2(gb, vc1_norm2_vlc.table, VC1_NORM2_VLC_BITS, 1);
+ *planep++ = code & 1;
+ offset++;
+ if(offset == width) {
+ offset = 0;
+ planep += stride - width;
+ }
+ *planep++ = code >> 1;
+ offset++;
+ if(offset == width) {
+ offset = 0;
+ planep += stride - width;
+ }
+ }
+ break;
+ case IMODE_DIFF6:
+ case IMODE_NORM6:
+ if(!(height % 3) && (width % 3)) { // use 2x3 decoding
+ for(y = 0; y < height; y+= 3) {
+ for(x = width & 1; x < width; x += 2) {
+ code = get_vlc2(gb, vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2);
+ if(code < 0){
+ av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");
+ return -1;
+ }
+ planep[x + 0] = (code >> 0) & 1;
+ planep[x + 1] = (code >> 1) & 1;
+ planep[x + 0 + stride] = (code >> 2) & 1;
+ planep[x + 1 + stride] = (code >> 3) & 1;
+ planep[x + 0 + stride * 2] = (code >> 4) & 1;
+ planep[x + 1 + stride * 2] = (code >> 5) & 1;
+ }
+ planep += stride * 3;
+ }
+ if(width & 1) decode_colskip(data, 1, height, stride, &v->s.gb);
+ } else { // 3x2
+ planep += (height & 1) * stride;
+ for(y = height & 1; y < height; y += 2) {
+ for(x = width % 3; x < width; x += 3) {
+ code = get_vlc2(gb, vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2);
+ if(code < 0){
+ av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");
+ return -1;
+ }
+ planep[x + 0] = (code >> 0) & 1;
+ planep[x + 1] = (code >> 1) & 1;
+ planep[x + 2] = (code >> 2) & 1;
+ planep[x + 0 + stride] = (code >> 3) & 1;
+ planep[x + 1 + stride] = (code >> 4) & 1;
+ planep[x + 2 + stride] = (code >> 5) & 1;
+ }
+ planep += stride * 2;
+ }
+ x = width % 3;
+ if(x) decode_colskip(data , x, height , stride, &v->s.gb);
+ if(height & 1) decode_rowskip(data+x, width - x, 1, stride, &v->s.gb);
+ }
+ break;
+ case IMODE_ROWSKIP:
+ decode_rowskip(data, width, height, stride, &v->s.gb);
+ break;
+ case IMODE_COLSKIP:
+ decode_colskip(data, width, height, stride, &v->s.gb);
+ break;
+ default: break;
+ }
+
+ /* Applying diff operator */
+ if (imode == IMODE_DIFF2 || imode == IMODE_DIFF6)
+ {
+ planep = data;
+ planep[0] ^= invert;
+ for (x=1; x<width; x++)
+ planep[x] ^= planep[x-1];
+ for (y=1; y<height; y++)
+ {
+ planep += stride;
+ planep[0] ^= planep[-stride];
+ for (x=1; x<width; x++)
+ {
+ if (planep[x-1] != planep[x-stride]) planep[x] ^= invert;
+ else planep[x] ^= planep[x-1];
+ }
+ }
+ }
+ else if (invert)
+ {
+ planep = data;
+ for (x=0; x<stride*height; x++) planep[x] = !planep[x]; //FIXME stride
+ }
+ return (imode<<1) + invert;
+}
+
+/** @} */ //Bitplane group
+
+/***********************************************************************/
+/** VOP Dquant decoding
+ * @param v VC-1 Context
+ */
+static int vop_dquant_decoding(VC1Context *v)
+{
+ GetBitContext *gb = &v->s.gb;
+ int pqdiff;
+
+ //variable size
+ if (v->dquant == 2)
+ {
+ pqdiff = get_bits(gb, 3);
+ if (pqdiff == 7) v->altpq = get_bits(gb, 5);
+ else v->altpq = v->pq + pqdiff + 1;
+ }
+ else
+ {
+ v->dquantfrm = get_bits(gb, 1);
+ if ( v->dquantfrm )
+ {
+ v->dqprofile = get_bits(gb, 2);
+ switch (v->dqprofile)
+ {
+ case DQPROFILE_SINGLE_EDGE:
+ case DQPROFILE_DOUBLE_EDGES:
+ v->dqsbedge = get_bits(gb, 2);
+ break;
+ case DQPROFILE_ALL_MBS:
+ v->dqbilevel = get_bits(gb, 1);
+ default: break; //Forbidden ?
+ }
+ if (v->dqbilevel || v->dqprofile != DQPROFILE_ALL_MBS)
+ {
+ pqdiff = get_bits(gb, 3);
+ if (pqdiff == 7) v->altpq = get_bits(gb, 5);
+ else v->altpq = v->pq + pqdiff + 1;
+ }
+ }
+ }
+ return 0;
+}
+
+/** Put block onto picture
+ */
+static void vc1_put_block(VC1Context *v, DCTELEM block[6][64])
+{
+ uint8_t *Y;
+ int ys, us, vs;
+ DSPContext *dsp = &v->s.dsp;
+
+ if(v->rangeredfrm) {
+ int i, j, k;
+ for(k = 0; k < 6; k++)
+ for(j = 0; j < 8; j++)
+ for(i = 0; i < 8; i++)
+ block[k][i + j*8] = ((block[k][i + j*8] - 128) << 1) + 128;
+
+ }
+ ys = v->s.current_picture.linesize[0];
+ us = v->s.current_picture.linesize[1];
+ vs = v->s.current_picture.linesize[2];
+ Y = v->s.dest[0];
+
+ dsp->put_pixels_clamped(block[0], Y, ys);
+ dsp->put_pixels_clamped(block[1], Y + 8, ys);
+ Y += ys * 8;
+ dsp->put_pixels_clamped(block[2], Y, ys);
+ dsp->put_pixels_clamped(block[3], Y + 8, ys);
+
+ if(!(v->s.flags & CODEC_FLAG_GRAY)) {
+ dsp->put_pixels_clamped(block[4], v->s.dest[1], us);
+ dsp->put_pixels_clamped(block[5], v->s.dest[2], vs);
+ }
+}
+
+/** Do motion compensation over 1 macroblock
+ * Mostly adapted hpel_motion and qpel_motion from mpegvideo.c
+ */
+static void vc1_mc_1mv(VC1Context *v, int dir)
+{
+ MpegEncContext *s = &v->s;
+ DSPContext *dsp = &v->s.dsp;
+ uint8_t *srcY, *srcU, *srcV;
+ int dxy, uvdxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y;
+
+ if(!v->s.last_picture.data[0])return;
+
+ mx = s->mv[dir][0][0];
+ my = s->mv[dir][0][1];
+
+ // store motion vectors for further use in B frames
+ if(s->pict_type == P_TYPE) {
+ s->current_picture.motion_val[1][s->block_index[0]][0] = mx;
+ s->current_picture.motion_val[1][s->block_index[0]][1] = my;
+ }
+ uvmx = (mx + ((mx & 3) == 3)) >> 1;
+ uvmy = (my + ((my & 3) == 3)) >> 1;
+ if(v->fastuvmc) {
+ uvmx = uvmx + ((uvmx<0)?(uvmx&1):-(uvmx&1));
+ uvmy = uvmy + ((uvmy<0)?(uvmy&1):-(uvmy&1));
+ }
+ if(!dir) {
+ srcY = s->last_picture.data[0];
+ srcU = s->last_picture.data[1];
+ srcV = s->last_picture.data[2];
+ } else {
+ srcY = s->next_picture.data[0];
+ srcU = s->next_picture.data[1];
+ srcV = s->next_picture.data[2];
+ }
+
+ src_x = s->mb_x * 16 + (mx >> 2);
+ src_y = s->mb_y * 16 + (my >> 2);
+ uvsrc_x = s->mb_x * 8 + (uvmx >> 2);
+ uvsrc_y = s->mb_y * 8 + (uvmy >> 2);
+
+ if(v->profile != PROFILE_ADVANCED){
+ src_x = av_clip( src_x, -16, s->mb_width * 16);
+ src_y = av_clip( src_y, -16, s->mb_height * 16);
+ uvsrc_x = av_clip(uvsrc_x, -8, s->mb_width * 8);
+ uvsrc_y = av_clip(uvsrc_y, -8, s->mb_height * 8);
+ }else{
+ src_x = av_clip( src_x, -17, s->avctx->coded_width);
+ src_y = av_clip( src_y, -18, s->avctx->coded_height + 1);
+ uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width >> 1);
+ uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1);
+ }
+
+ srcY += src_y * s->linesize + src_x;
+ srcU += uvsrc_y * s->uvlinesize + uvsrc_x;
+ srcV += uvsrc_y * s->uvlinesize + uvsrc_x;
+
+ /* for grayscale we should not try to read from unknown area */
+ if(s->flags & CODEC_FLAG_GRAY) {
+ srcU = s->edge_emu_buffer + 18 * s->linesize;
+ srcV = s->edge_emu_buffer + 18 * s->linesize;
+ }
+
+ if(v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP)
+ || (unsigned)(src_x - s->mspel) > s->h_edge_pos - (mx&3) - 16 - s->mspel*3
+ || (unsigned)(src_y - s->mspel) > s->v_edge_pos - (my&3) - 16 - s->mspel*3){
+ uint8_t *uvbuf= s->edge_emu_buffer + 19 * s->linesize;
+
+ srcY -= s->mspel * (1 + s->linesize);
+ ff_emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize, 17+s->mspel*2, 17+s->mspel*2,
+ src_x - s->mspel, src_y - s->mspel, s->h_edge_pos, s->v_edge_pos);
+ srcY = s->edge_emu_buffer;
+ ff_emulated_edge_mc(uvbuf , srcU, s->uvlinesize, 8+1, 8+1,
+ uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
+ ff_emulated_edge_mc(uvbuf + 16, srcV, s->uvlinesize, 8+1, 8+1,
+ uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
+ srcU = uvbuf;
+ srcV = uvbuf + 16;
+ /* if we deal with range reduction we need to scale source blocks */
+ if(v->rangeredfrm) {
+ int i, j;
+ uint8_t *src, *src2;
+
+ src = srcY;
+ for(j = 0; j < 17 + s->mspel*2; j++) {
+ for(i = 0; i < 17 + s->mspel*2; i++) src[i] = ((src[i] - 128) >> 1) + 128;
+ src += s->linesize;
+ }
+ src = srcU; src2 = srcV;
+ for(j = 0; j < 9; j++) {
+ for(i = 0; i < 9; i++) {
+ src[i] = ((src[i] - 128) >> 1) + 128;
+ src2[i] = ((src2[i] - 128) >> 1) + 128;
+ }
+ src += s->uvlinesize;
+ src2 += s->uvlinesize;
+ }
+ }
+ /* if we deal with intensity compensation we need to scale source blocks */
+ if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {
+ int i, j;
+ uint8_t *src, *src2;
+
+ src = srcY;
+ for(j = 0; j < 17 + s->mspel*2; j++) {
+ for(i = 0; i < 17 + s->mspel*2; i++) src[i] = v->luty[src[i]];
+ src += s->linesize;
+ }
+ src = srcU; src2 = srcV;
+ for(j = 0; j < 9; j++) {
+ for(i = 0; i < 9; i++) {
+ src[i] = v->lutuv[src[i]];
+ src2[i] = v->lutuv[src2[i]];
+ }
+ src += s->uvlinesize;
+ src2 += s->uvlinesize;
+ }
+ }
+ srcY += s->mspel * (1 + s->linesize);
+ }
+
+ if(s->mspel) {
+ dxy = ((my & 3) << 2) | (mx & 3);
+ dsp->put_vc1_mspel_pixels_tab[dxy](s->dest[0] , srcY , s->linesize, v->rnd);
+ dsp->put_vc1_mspel_pixels_tab[dxy](s->dest[0] + 8, srcY + 8, s->linesize, v->rnd);
+ srcY += s->linesize * 8;
+ dsp->put_vc1_mspel_pixels_tab[dxy](s->dest[0] + 8 * s->linesize , srcY , s->linesize, v->rnd);
+ dsp->put_vc1_mspel_pixels_tab[dxy](s->dest[0] + 8 * s->linesize + 8, srcY + 8, s->linesize, v->rnd);
+ } else { // hpel mc - always used for luma
+ dxy = (my & 2) | ((mx & 2) >> 1);
+
+ if(!v->rnd)
+ dsp->put_pixels_tab[0][dxy](s->dest[0], srcY, s->linesize, 16);
+ else
+ dsp->put_no_rnd_pixels_tab[0][dxy](s->dest[0], srcY, s->linesize, 16);
+ }
+
+ if(s->flags & CODEC_FLAG_GRAY) return;
+ /* Chroma MC always uses qpel bilinear */
+ uvdxy = ((uvmy & 3) << 2) | (uvmx & 3);
+ uvmx = (uvmx&3)<<1;
+ uvmy = (uvmy&3)<<1;
+ if(!v->rnd){
+ dsp->put_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);
+ dsp->put_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);
+ }else{
+ dsp->put_no_rnd_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);
+ dsp->put_no_rnd_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);
+ }
+}
+
+/** Do motion compensation for 4-MV macroblock - luminance block
+ */
+static void vc1_mc_4mv_luma(VC1Context *v, int n)
+{
+ MpegEncContext *s = &v->s;
+ DSPContext *dsp = &v->s.dsp;
+ uint8_t *srcY;
+ int dxy, mx, my, src_x, src_y;
+ int off;
+
+ if(!v->s.last_picture.data[0])return;
+ mx = s->mv[0][n][0];
+ my = s->mv[0][n][1];
+ srcY = s->last_picture.data[0];
+
+ off = s->linesize * 4 * (n&2) + (n&1) * 8;
+
+ src_x = s->mb_x * 16 + (n&1) * 8 + (mx >> 2);
+ src_y = s->mb_y * 16 + (n&2) * 4 + (my >> 2);
+
+ if(v->profile != PROFILE_ADVANCED){
+ src_x = av_clip( src_x, -16, s->mb_width * 16);
+ src_y = av_clip( src_y, -16, s->mb_height * 16);
+ }else{
+ src_x = av_clip( src_x, -17, s->avctx->coded_width);
+ src_y = av_clip( src_y, -18, s->avctx->coded_height + 1);
+ }
+
+ srcY += src_y * s->linesize + src_x;
+
+ if(v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP)
+ || (unsigned)(src_x - s->mspel) > s->h_edge_pos - (mx&3) - 8 - s->mspel*2
+ || (unsigned)(src_y - s->mspel) > s->v_edge_pos - (my&3) - 8 - s->mspel*2){
+ srcY -= s->mspel * (1 + s->linesize);
+ ff_emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize, 9+s->mspel*2, 9+s->mspel*2,
+ src_x - s->mspel, src_y - s->mspel, s->h_edge_pos, s->v_edge_pos);
+ srcY = s->edge_emu_buffer;
+ /* if we deal with range reduction we need to scale source blocks */
+ if(v->rangeredfrm) {
+ int i, j;
+ uint8_t *src;
+
+ src = srcY;
+ for(j = 0; j < 9 + s->mspel*2; j++) {
+ for(i = 0; i < 9 + s->mspel*2; i++) src[i] = ((src[i] - 128) >> 1) + 128;
+ src += s->linesize;
+ }
+ }
+ /* if we deal with intensity compensation we need to scale source blocks */
+ if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {
+ int i, j;
+ uint8_t *src;
+
+ src = srcY;
+ for(j = 0; j < 9 + s->mspel*2; j++) {
+ for(i = 0; i < 9 + s->mspel*2; i++) src[i] = v->luty[src[i]];
+ src += s->linesize;
+ }
+ }
+ srcY += s->mspel * (1 + s->linesize);
+ }
+
+ if(s->mspel) {
+ dxy = ((my & 3) << 2) | (mx & 3);
+ dsp->put_vc1_mspel_pixels_tab[dxy](s->dest[0] + off, srcY, s->linesize, v->rnd);
+ } else { // hpel mc - always used for luma
+ dxy = (my & 2) | ((mx & 2) >> 1);
+ if(!v->rnd)
+ dsp->put_pixels_tab[1][dxy](s->dest[0] + off, srcY, s->linesize, 8);
+ else
+ dsp->put_no_rnd_pixels_tab[1][dxy](s->dest[0] + off, srcY, s->linesize, 8);
+ }
+}
+
+static inline int median4(int a, int b, int c, int d)
+{
+ if(a < b) {
+ if(c < d) return (FFMIN(b, d) + FFMAX(a, c)) / 2;
+ else return (FFMIN(b, c) + FFMAX(a, d)) / 2;
+ } else {
+ if(c < d) return (FFMIN(a, d) + FFMAX(b, c)) / 2;
+ else return (FFMIN(a, c) + FFMAX(b, d)) / 2;
+ }
+}
+
+
+/** Do motion compensation for 4-MV macroblock - both chroma blocks
+ */
+static void vc1_mc_4mv_chroma(VC1Context *v)
+{
+ MpegEncContext *s = &v->s;
+ DSPContext *dsp = &v->s.dsp;
+ uint8_t *srcU, *srcV;
+ int uvdxy, uvmx, uvmy, uvsrc_x, uvsrc_y;
+ int i, idx, tx = 0, ty = 0;
+ int mvx[4], mvy[4], intra[4];
+ static const int count[16] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};
+
+ if(!v->s.last_picture.data[0])return;
+ if(s->flags & CODEC_FLAG_GRAY) return;
+
+ for(i = 0; i < 4; i++) {
+ mvx[i] = s->mv[0][i][0];
+ mvy[i] = s->mv[0][i][1];
+ intra[i] = v->mb_type[0][s->block_index[i]];
+ }
+
+ /* calculate chroma MV vector from four luma MVs */
+ idx = (intra[3] << 3) | (intra[2] << 2) | (intra[1] << 1) | intra[0];
+ if(!idx) { // all blocks are inter
+ tx = median4(mvx[0], mvx[1], mvx[2], mvx[3]);
+ ty = median4(mvy[0], mvy[1], mvy[2], mvy[3]);
+ } else if(count[idx] == 1) { // 3 inter blocks
+ switch(idx) {
+ case 0x1:
+ tx = mid_pred(mvx[1], mvx[2], mvx[3]);
+ ty = mid_pred(mvy[1], mvy[2], mvy[3]);
+ break;
+ case 0x2:
+ tx = mid_pred(mvx[0], mvx[2], mvx[3]);
+ ty = mid_pred(mvy[0], mvy[2], mvy[3]);
+ break;
+ case 0x4:
+ tx = mid_pred(mvx[0], mvx[1], mvx[3]);
+ ty = mid_pred(mvy[0], mvy[1], mvy[3]);
+ break;
+ case 0x8:
+ tx = mid_pred(mvx[0], mvx[1], mvx[2]);
+ ty = mid_pred(mvy[0], mvy[1], mvy[2]);
+ break;
+ }
+ } else if(count[idx] == 2) {
+ int t1 = 0, t2 = 0;
+ for(i=0; i<3;i++) if(!intra[i]) {t1 = i; break;}
+ for(i= t1+1; i<4; i++)if(!intra[i]) {t2 = i; break;}
+ tx = (mvx[t1] + mvx[t2]) / 2;
+ ty = (mvy[t1] + mvy[t2]) / 2;
+ } else {
+ s->current_picture.motion_val[1][s->block_index[0]][0] = 0;
+ s->current_picture.motion_val[1][s->block_index[0]][1] = 0;
+ return; //no need to do MC for inter blocks
+ }
+
+ s->current_picture.motion_val[1][s->block_index[0]][0] = tx;
+ s->current_picture.motion_val[1][s->block_index[0]][1] = ty;
+ uvmx = (tx + ((tx&3) == 3)) >> 1;
+ uvmy = (ty + ((ty&3) == 3)) >> 1;
+ if(v->fastuvmc) {
+ uvmx = uvmx + ((uvmx<0)?(uvmx&1):-(uvmx&1));
+ uvmy = uvmy + ((uvmy<0)?(uvmy&1):-(uvmy&1));
+ }
+
+ uvsrc_x = s->mb_x * 8 + (uvmx >> 2);
+ uvsrc_y = s->mb_y * 8 + (uvmy >> 2);
+
+ if(v->profile != PROFILE_ADVANCED){
+ uvsrc_x = av_clip(uvsrc_x, -8, s->mb_width * 8);
+ uvsrc_y = av_clip(uvsrc_y, -8, s->mb_height * 8);
+ }else{
+ uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width >> 1);
+ uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1);
+ }
+
+ srcU = s->last_picture.data[1] + uvsrc_y * s->uvlinesize + uvsrc_x;
+ srcV = s->last_picture.data[2] + uvsrc_y * s->uvlinesize + uvsrc_x;
+ if(v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP)
+ || (unsigned)uvsrc_x > (s->h_edge_pos >> 1) - 9
+ || (unsigned)uvsrc_y > (s->v_edge_pos >> 1) - 9){
+ ff_emulated_edge_mc(s->edge_emu_buffer , srcU, s->uvlinesize, 8+1, 8+1,
+ uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
+ ff_emulated_edge_mc(s->edge_emu_buffer + 16, srcV, s->uvlinesize, 8+1, 8+1,
+ uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
+ srcU = s->edge_emu_buffer;
+ srcV = s->edge_emu_buffer + 16;
+
+ /* if we deal with range reduction we need to scale source blocks */
+ if(v->rangeredfrm) {
+ int i, j;
+ uint8_t *src, *src2;
+
+ src = srcU; src2 = srcV;
+ for(j = 0; j < 9; j++) {
+ for(i = 0; i < 9; i++) {
+ src[i] = ((src[i] - 128) >> 1) + 128;
+ src2[i] = ((src2[i] - 128) >> 1) + 128;
+ }
+ src += s->uvlinesize;
+ src2 += s->uvlinesize;
+ }
+ }
+ /* if we deal with intensity compensation we need to scale source blocks */
+ if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {
+ int i, j;
+ uint8_t *src, *src2;
+
+ src = srcU; src2 = srcV;
+ for(j = 0; j < 9; j++) {
+ for(i = 0; i < 9; i++) {
+ src[i] = v->lutuv[src[i]];
+ src2[i] = v->lutuv[src2[i]];
+ }
+ src += s->uvlinesize;
+ src2 += s->uvlinesize;
+ }
+ }
+ }
+
+ /* Chroma MC always uses qpel bilinear */
+ uvdxy = ((uvmy & 3) << 2) | (uvmx & 3);
+ uvmx = (uvmx&3)<<1;
+ uvmy = (uvmy&3)<<1;
+ if(!v->rnd){
+ dsp->put_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);
+ dsp->put_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);
+ }else{
+ dsp->put_no_rnd_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);
+ dsp->put_no_rnd_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);
+ }
+}
+
+static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb);
+
+/**
+ * Decode Simple/Main Profiles sequence header
+ * @see Figure 7-8, p16-17
+ * @param avctx Codec context
+ * @param gb GetBit context initialized from Codec context extra_data
+ * @return Status
+ */
+static int decode_sequence_header(AVCodecContext *avctx, GetBitContext *gb)
+{
+ VC1Context *v = avctx->priv_data;
+
+ av_log(avctx, AV_LOG_DEBUG, "Header: %0X\n", show_bits(gb, 32));
+ v->profile = get_bits(gb, 2);
+ if (v->profile == PROFILE_COMPLEX)
+ {
+ av_log(avctx, AV_LOG_ERROR, "WMV3 Complex Profile is not fully supported\n");
+ }
+
+ if (v->profile == PROFILE_ADVANCED)
+ {
+ return decode_sequence_header_adv(v, gb);
+ }
+ else
+ {
+ v->res_sm = get_bits(gb, 2); //reserved
+ if (v->res_sm)
+ {
+ av_log(avctx, AV_LOG_ERROR,
+ "Reserved RES_SM=%i is forbidden\n", v->res_sm);
+ return -1;
+ }
+ }
+
+ // (fps-2)/4 (->30)
+ v->frmrtq_postproc = get_bits(gb, 3); //common
+ // (bitrate-32kbps)/64kbps
+ v->bitrtq_postproc = get_bits(gb, 5); //common
+ v->s.loop_filter = get_bits(gb, 1); //common
+ if(v->s.loop_filter == 1 && v->profile == PROFILE_SIMPLE)
+ {
+ av_log(avctx, AV_LOG_ERROR,
+ "LOOPFILTER shell not be enabled in simple profile\n");
+ }
+
+ v->res_x8 = get_bits(gb, 1); //reserved
+ if (v->res_x8)
+ {
+ av_log(avctx, AV_LOG_ERROR,
+ "1 for reserved RES_X8 is forbidden\n");
+ //return -1;
+ }
+ v->multires = get_bits(gb, 1);
+ v->res_fasttx = get_bits(gb, 1);
+ if (!v->res_fasttx)
+ {
+ av_log(avctx, AV_LOG_ERROR,
+ "0 for reserved RES_FASTTX is forbidden\n");
+ //return -1;
+ }
+
+ v->fastuvmc = get_bits(gb, 1); //common
+ if (!v->profile && !v->fastuvmc)
+ {
+ av_log(avctx, AV_LOG_ERROR,
+ "FASTUVMC unavailable in Simple Profile\n");
+ return -1;
+ }
+ v->extended_mv = get_bits(gb, 1); //common
+ if (!v->profile && v->extended_mv)
+ {
+ av_log(avctx, AV_LOG_ERROR,
+ "Extended MVs unavailable in Simple Profile\n");
+ return -1;
+ }
+ v->dquant = get_bits(gb, 2); //common
+ v->vstransform = get_bits(gb, 1); //common
+
+ v->res_transtab = get_bits(gb, 1);
+ if (v->res_transtab)
+ {
+ av_log(avctx, AV_LOG_ERROR,
+ "1 for reserved RES_TRANSTAB is forbidden\n");
+ return -1;
+ }
+
+ v->overlap = get_bits(gb, 1); //common
+
+ v->s.resync_marker = get_bits(gb, 1);
+ v->rangered = get_bits(gb, 1);
+ if (v->rangered && v->profile == PROFILE_SIMPLE)
+ {
+ av_log(avctx, AV_LOG_INFO,
+ "RANGERED should be set to 0 in simple profile\n");
+ }
+
+ v->s.max_b_frames = avctx->max_b_frames = get_bits(gb, 3); //common
+ v->quantizer_mode = get_bits(gb, 2); //common
+
+ v->finterpflag = get_bits(gb, 1); //common
+ v->res_rtm_flag = get_bits(gb, 1); //reserved
+ if (!v->res_rtm_flag)
+ {
+// av_log(avctx, AV_LOG_ERROR,
+// "0 for reserved RES_RTM_FLAG is forbidden\n");
+ av_log(avctx, AV_LOG_ERROR,
+ "Old WMV3 version detected, only I-frames will be decoded\n");
+ //return -1;
+ }
+ //TODO: figure out what they mean (always 0x402F)
+ if(!v->res_fasttx) skip_bits(gb, 16);
+ av_log(avctx, AV_LOG_DEBUG,
+ "Profile %i:\nfrmrtq_postproc=%i, bitrtq_postproc=%i\n"
+ "LoopFilter=%i, MultiRes=%i, FastUVMC=%i, Extended MV=%i\n"
+ "Rangered=%i, VSTransform=%i, Overlap=%i, SyncMarker=%i\n"
+ "DQuant=%i, Quantizer mode=%i, Max B frames=%i\n",
+ v->profile, v->frmrtq_postproc, v->bitrtq_postproc,
+ v->s.loop_filter, v->multires, v->fastuvmc, v->extended_mv,
+ v->rangered, v->vstransform, v->overlap, v->s.resync_marker,
+ v->dquant, v->quantizer_mode, avctx->max_b_frames
+ );
+ return 0;
+}
+
+static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb)
+{
+ v->res_rtm_flag = 1;
+ v->level = get_bits(gb, 3);
+ if(v->level >= 5)
+ {
+ av_log(v->s.avctx, AV_LOG_ERROR, "Reserved LEVEL %i\n",v->level);
+ }
+ v->chromaformat = get_bits(gb, 2);
+ if (v->chromaformat != 1)
+ {
+ av_log(v->s.avctx, AV_LOG_ERROR,
+ "Only 4:2:0 chroma format supported\n");
+ return -1;
+ }
+
+ // (fps-2)/4 (->30)
+ v->frmrtq_postproc = get_bits(gb, 3); //common
+ // (bitrate-32kbps)/64kbps
+ v->bitrtq_postproc = get_bits(gb, 5); //common
+ v->postprocflag = get_bits(gb, 1); //common
+
+ v->s.avctx->coded_width = (get_bits(gb, 12) + 1) << 1;
+ v->s.avctx->coded_height = (get_bits(gb, 12) + 1) << 1;
+ v->s.avctx->width = v->s.avctx->coded_width;
+ v->s.avctx->height = v->s.avctx->coded_height;
+ v->broadcast = get_bits1(gb);
+ v->interlace = get_bits1(gb);
+ v->tfcntrflag = get_bits1(gb);
+ v->finterpflag = get_bits1(gb);
+ get_bits1(gb); // reserved
+
+ v->s.h_edge_pos = v->s.avctx->coded_width;
+ v->s.v_edge_pos = v->s.avctx->coded_height;
+
+ av_log(v->s.avctx, AV_LOG_DEBUG,
+ "Advanced Profile level %i:\nfrmrtq_postproc=%i, bitrtq_postproc=%i\n"
+ "LoopFilter=%i, ChromaFormat=%i, Pulldown=%i, Interlace: %i\n"
+ "TFCTRflag=%i, FINTERPflag=%i\n",
+ v->level, v->frmrtq_postproc, v->bitrtq_postproc,
+ v->s.loop_filter, v->chromaformat, v->broadcast, v->interlace,
+ v->tfcntrflag, v->finterpflag
+ );
+
+ v->psf = get_bits1(gb);
+ if(v->psf) { //PsF, 6.1.13
+ av_log(v->s.avctx, AV_LOG_ERROR, "Progressive Segmented Frame mode: not supported (yet)\n");
+ return -1;
+ }
+ v->s.max_b_frames = v->s.avctx->max_b_frames = 7;
+ if(get_bits1(gb)) { //Display Info - decoding is not affected by it
+ int w, h, ar = 0;
+ av_log(v->s.avctx, AV_LOG_DEBUG, "Display extended info:\n");
+ v->s.avctx->width = v->s.width = w = get_bits(gb, 14) + 1;
+ v->s.avctx->height = v->s.height = h = get_bits(gb, 14) + 1;
+ av_log(v->s.avctx, AV_LOG_DEBUG, "Display dimensions: %ix%i\n", w, h);
+ if(get_bits1(gb))
+ ar = get_bits(gb, 4);
+ if(ar && ar < 14){
+ v->s.avctx->sample_aspect_ratio = vc1_pixel_aspect[ar];
+ }else if(ar == 15){
+ w = get_bits(gb, 8);
+ h = get_bits(gb, 8);
+ v->s.avctx->sample_aspect_ratio = (AVRational){w, h};
+ }
+
+ if(get_bits1(gb)){ //framerate stuff
+ if(get_bits1(gb)) {
+ v->s.avctx->time_base.num = 32;
+ v->s.avctx->time_base.den = get_bits(gb, 16) + 1;
+ } else {
+ int nr, dr;
+ nr = get_bits(gb, 8);
+ dr = get_bits(gb, 4);
+ if(nr && nr < 8 && dr && dr < 3){
+ v->s.avctx->time_base.num = fps_dr[dr - 1];
+ v->s.avctx->time_base.den = fps_nr[nr - 1] * 1000;
+ }
+ }
+ }
+
+ if(get_bits1(gb)){
+ v->color_prim = get_bits(gb, 8);
+ v->transfer_char = get_bits(gb, 8);
+ v->matrix_coef = get_bits(gb, 8);
+ }
+ }
+
+ v->hrd_param_flag = get_bits1(gb);
+ if(v->hrd_param_flag) {
+ int i;
+ v->hrd_num_leaky_buckets = get_bits(gb, 5);
+ get_bits(gb, 4); //bitrate exponent
+ get_bits(gb, 4); //buffer size exponent
+ for(i = 0; i < v->hrd_num_leaky_buckets; i++) {
+ get_bits(gb, 16); //hrd_rate[n]
+ get_bits(gb, 16); //hrd_buffer[n]
+ }
+ }
+ return 0;
+}
+
+static int decode_entry_point(AVCodecContext *avctx, GetBitContext *gb)
+{
+ VC1Context *v = avctx->priv_data;
+ int i, blink, clentry, refdist;
+
+ av_log(avctx, AV_LOG_DEBUG, "Entry point: %08X\n", show_bits_long(gb, 32));
+ blink = get_bits1(gb); // broken link
+ clentry = get_bits1(gb); // closed entry
+ v->panscanflag = get_bits1(gb);
+ refdist = get_bits1(gb); // refdist flag
+ v->s.loop_filter = get_bits1(gb);
+ v->fastuvmc = get_bits1(gb);
+ v->extended_mv = get_bits1(gb);
+ v->dquant = get_bits(gb, 2);
+ v->vstransform = get_bits1(gb);
+ v->overlap = get_bits1(gb);
+ v->quantizer_mode = get_bits(gb, 2);
+
+ if(v->hrd_param_flag){
+ for(i = 0; i < v->hrd_num_leaky_buckets; i++) {
+ get_bits(gb, 8); //hrd_full[n]
+ }
+ }
+
+ if(get_bits1(gb)){
+ avctx->coded_width = (get_bits(gb, 12)+1)<<1;
+ avctx->coded_height = (get_bits(gb, 12)+1)<<1;
+ }
+ if(v->extended_mv)
+ v->extended_dmv = get_bits1(gb);
+ if(get_bits1(gb)) {
+ av_log(avctx, AV_LOG_ERROR, "Luma scaling is not supported, expect wrong picture\n");
+ skip_bits(gb, 3); // Y range, ignored for now
+ }
+ if(get_bits1(gb)) {
+ av_log(avctx, AV_LOG_ERROR, "Chroma scaling is not supported, expect wrong picture\n");
+ skip_bits(gb, 3); // UV range, ignored for now
+ }
+
+ av_log(avctx, AV_LOG_DEBUG, "Entry point info:\n"
+ "BrokenLink=%i, ClosedEntry=%i, PanscanFlag=%i\n"
+ "RefDist=%i, Postproc=%i, FastUVMC=%i, ExtMV=%i\n"
+ "DQuant=%i, VSTransform=%i, Overlap=%i, Qmode=%i\n",
+ blink, clentry, v->panscanflag, refdist, v->s.loop_filter,
+ v->fastuvmc, v->extended_mv, v->dquant, v->vstransform, v->overlap, v->quantizer_mode);
+
+ return 0;
+}
+
+static int vc1_parse_frame_header(VC1Context *v, GetBitContext* gb)
+{
+ int pqindex, lowquant, status;
+
+ if(v->finterpflag) v->interpfrm = get_bits(gb, 1);
+ skip_bits(gb, 2); //framecnt unused
+ v->rangeredfrm = 0;
+ if (v->rangered) v->rangeredfrm = get_bits(gb, 1);
+ v->s.pict_type = get_bits(gb, 1);
+ if (v->s.avctx->max_b_frames) {
+ if (!v->s.pict_type) {
+ if (get_bits(gb, 1)) v->s.pict_type = I_TYPE;
+ else v->s.pict_type = B_TYPE;
+ } else v->s.pict_type = P_TYPE;
+ } else v->s.pict_type = v->s.pict_type ? P_TYPE : I_TYPE;
+
+ v->bi_type = 0;
+ if(v->s.pict_type == B_TYPE) {
+ v->bfraction = get_vlc2(gb, vc1_bfraction_vlc.table, VC1_BFRACTION_VLC_BITS, 1);
+ v->bfraction = vc1_bfraction_lut[v->bfraction];
+ if(v->bfraction == 0) {
+ v->s.pict_type = BI_TYPE;
+ }
+ }
+ if(v->s.pict_type == I_TYPE || v->s.pict_type == BI_TYPE)
+ get_bits(gb, 7); // skip buffer fullness
+
+ /* calculate RND */
+ if(v->s.pict_type == I_TYPE || v->s.pict_type == BI_TYPE)
+ v->rnd = 1;
+ if(v->s.pict_type == P_TYPE)
+ v->rnd ^= 1;
+
+ /* Quantizer stuff */
+ pqindex = get_bits(gb, 5);
+ if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
+ v->pq = pquant_table[0][pqindex];
+ else
+ v->pq = pquant_table[1][pqindex];
+
+ v->pquantizer = 1;
+ if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
+ v->pquantizer = pqindex < 9;
+ if (v->quantizer_mode == QUANT_NON_UNIFORM)
+ v->pquantizer = 0;
+ v->pqindex = pqindex;
+ if (pqindex < 9) v->halfpq = get_bits(gb, 1);
+ else v->halfpq = 0;
+ if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)
+ v->pquantizer = get_bits(gb, 1);
+ v->dquantfrm = 0;
+ if (v->extended_mv == 1) v->mvrange = get_prefix(gb, 0, 3);
+ v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
+ v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
+ v->range_x = 1 << (v->k_x - 1);
+ v->range_y = 1 << (v->k_y - 1);
+ if (v->profile == PROFILE_ADVANCED)
+ {
+ if (v->postprocflag) v->postproc = get_bits(gb, 1);
+ }
+ else
+ if (v->multires && v->s.pict_type != B_TYPE) v->respic = get_bits(gb, 2);
+
+ if(v->res_x8 && (v->s.pict_type == I_TYPE || v->s.pict_type == BI_TYPE)){
+ if(get_bits1(gb))return -1;
+ }
+//av_log(v->s.avctx, AV_LOG_INFO, "%c Frame: QP=[%i]%i (+%i/2) %i\n",
+// (v->s.pict_type == P_TYPE) ? 'P' : ((v->s.pict_type == I_TYPE) ? 'I' : 'B'), pqindex, v->pq, v->halfpq, v->rangeredfrm);
+
+ if(v->s.pict_type == I_TYPE || v->s.pict_type == P_TYPE) v->use_ic = 0;
+
+ switch(v->s.pict_type) {
+ case P_TYPE:
+ if (v->pq < 5) v->tt_index = 0;
+ else if(v->pq < 13) v->tt_index = 1;
+ else v->tt_index = 2;
+
+ lowquant = (v->pq > 12) ? 0 : 1;
+ v->mv_mode = mv_pmode_table[lowquant][get_prefix(gb, 1, 4)];
+ if (v->mv_mode == MV_PMODE_INTENSITY_COMP)
+ {
+ int scale, shift, i;
+ v->mv_mode2 = mv_pmode_table2[lowquant][get_prefix(gb, 1, 3)];
+ v->lumscale = get_bits(gb, 6);
+ v->lumshift = get_bits(gb, 6);
+ v->use_ic = 1;
+ /* fill lookup tables for intensity compensation */
+ if(!v->lumscale) {
+ scale = -64;
+ shift = (255 - v->lumshift * 2) << 6;
+ if(v->lumshift > 31)
+ shift += 128 << 6;
+ } else {
+ scale = v->lumscale + 32;
+ if(v->lumshift > 31)
+ shift = (v->lumshift - 64) << 6;
+ else
+ shift = v->lumshift << 6;
+ }
+ for(i = 0; i < 256; i++) {
+ v->luty[i] = av_clip_uint8((scale * i + shift + 32) >> 6);
+ v->lutuv[i] = av_clip_uint8((scale * (i - 128) + 128*64 + 32) >> 6);
+ }
+ }
+ if(v->mv_mode == MV_PMODE_1MV_HPEL || v->mv_mode == MV_PMODE_1MV_HPEL_BILIN)
+ v->s.quarter_sample = 0;
+ else if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {
+ if(v->mv_mode2 == MV_PMODE_1MV_HPEL || v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN)
+ v->s.quarter_sample = 0;
+ else
+ v->s.quarter_sample = 1;
+ } else
+ v->s.quarter_sample = 1;
+ v->s.mspel = !(v->mv_mode == MV_PMODE_1MV_HPEL_BILIN || (v->mv_mode == MV_PMODE_INTENSITY_COMP && v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN));
+
+ if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
+ v->mv_mode2 == MV_PMODE_MIXED_MV)
+ || v->mv_mode == MV_PMODE_MIXED_MV)
+ {
+ status = bitplane_decoding(v->mv_type_mb_plane, &v->mv_type_is_raw, v);
+ if (status < 0) return -1;
+ av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "
+ "Imode: %i, Invert: %i\n", status>>1, status&1);
+ } else {
+ v->mv_type_is_raw = 0;
+ memset(v->mv_type_mb_plane, 0, v->s.mb_stride * v->s.mb_height);
+ }
+ status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
+ if (status < 0) return -1;
+ av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
+ "Imode: %i, Invert: %i\n", status>>1, status&1);
+
+ /* Hopefully this is correct for P frames */
+ v->s.mv_table_index = get_bits(gb, 2); //but using vc1_ tables
+ v->cbpcy_vlc = &vc1_cbpcy_p_vlc[get_bits(gb, 2)];
+
+ if (v->dquant)
+ {
+ av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
+ vop_dquant_decoding(v);
+ }
+
+ v->ttfrm = 0; //FIXME Is that so ?
+ if (v->vstransform)
+ {
+ v->ttmbf = get_bits(gb, 1);
+ if (v->ttmbf)
+ {
+ v->ttfrm = ttfrm_to_tt[get_bits(gb, 2)];
+ }
+ } else {
+ v->ttmbf = 1;
+ v->ttfrm = TT_8X8;
+ }
+ break;
+ case B_TYPE:
+ if (v->pq < 5) v->tt_index = 0;
+ else if(v->pq < 13) v->tt_index = 1;
+ else v->tt_index = 2;
+
+ lowquant = (v->pq > 12) ? 0 : 1;
+ v->mv_mode = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN;
+ v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV);
+ v->s.mspel = v->s.quarter_sample;
+
+ status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v);
+ if (status < 0) return -1;
+ av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "
+ "Imode: %i, Invert: %i\n", status>>1, status&1);
+ status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
+ if (status < 0) return -1;
+ av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
+ "Imode: %i, Invert: %i\n", status>>1, status&1);
+
+ v->s.mv_table_index = get_bits(gb, 2);
+ v->cbpcy_vlc = &vc1_cbpcy_p_vlc[get_bits(gb, 2)];
+
+ if (v->dquant)
+ {
+ av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
+ vop_dquant_decoding(v);
+ }
+
+ v->ttfrm = 0;
+ if (v->vstransform)
+ {
+ v->ttmbf = get_bits(gb, 1);
+ if (v->ttmbf)
+ {
+ v->ttfrm = ttfrm_to_tt[get_bits(gb, 2)];
+ }
+ } else {
+ v->ttmbf = 1;
+ v->ttfrm = TT_8X8;
+ }
+ break;
+ }
+
+ /* AC Syntax */
+ v->c_ac_table_index = decode012(gb);
+ if (v->s.pict_type == I_TYPE || v->s.pict_type == BI_TYPE)
+ {
+ v->y_ac_table_index = decode012(gb);
+ }
+ /* DC Syntax */
+ v->s.dc_table_index = get_bits(gb, 1);
+
+ if(v->s.pict_type == BI_TYPE) {
+ v->s.pict_type = B_TYPE;
+ v->bi_type = 1;
+ }
+ return 0;
+}
+
+static int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
+{
+ int pqindex, lowquant;
+ int status;
+
+ v->p_frame_skipped = 0;
+
+ if(v->interlace){
+ v->fcm = decode012(gb);
+ if(v->fcm) return -1; // interlaced frames/fields are not implemented
+ }
+ switch(get_prefix(gb, 0, 4)) {
+ case 0:
+ v->s.pict_type = P_TYPE;
+ break;
+ case 1:
+ v->s.pict_type = B_TYPE;
+ break;
+ case 2:
+ v->s.pict_type = I_TYPE;
+ break;
+ case 3:
+ v->s.pict_type = BI_TYPE;
+ break;
+ case 4:
+ v->s.pict_type = P_TYPE; // skipped pic
+ v->p_frame_skipped = 1;
+ return 0;
+ }
+ if(v->tfcntrflag)
+ get_bits(gb, 8);
+ if(v->broadcast) {
+ if(!v->interlace || v->psf) {
+ v->rptfrm = get_bits(gb, 2);
+ } else {
+ v->tff = get_bits1(gb);
+ v->rptfrm = get_bits1(gb);
+ }
+ }
+ if(v->panscanflag) {
+ //...
+ }
+ v->rnd = get_bits1(gb);
+ if(v->interlace)
+ v->uvsamp = get_bits1(gb);
+ if(v->finterpflag) v->interpfrm = get_bits(gb, 1);
+ if(v->s.pict_type == B_TYPE) {
+ v->bfraction = get_vlc2(gb, vc1_bfraction_vlc.table, VC1_BFRACTION_VLC_BITS, 1);
+ v->bfraction = vc1_bfraction_lut[v->bfraction];
+ if(v->bfraction == 0) {
+ v->s.pict_type = BI_TYPE; /* XXX: should not happen here */
+ }
+ }
+ pqindex = get_bits(gb, 5);
+ v->pqindex = pqindex;
+ if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
+ v->pq = pquant_table[0][pqindex];
+ else
+ v->pq = pquant_table[1][pqindex];
+
+ v->pquantizer = 1;
+ if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
+ v->pquantizer = pqindex < 9;
+ if (v->quantizer_mode == QUANT_NON_UNIFORM)
+ v->pquantizer = 0;
+ v->pqindex = pqindex;
+ if (pqindex < 9) v->halfpq = get_bits(gb, 1);
+ else v->halfpq = 0;
+ if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)
+ v->pquantizer = get_bits(gb, 1);
+
+ if(v->s.pict_type == I_TYPE || v->s.pict_type == P_TYPE) v->use_ic = 0;
+
+ switch(v->s.pict_type) {
+ case I_TYPE:
+ case BI_TYPE:
+ status = bitplane_decoding(v->acpred_plane, &v->acpred_is_raw, v);
+ if (status < 0) return -1;
+ av_log(v->s.avctx, AV_LOG_DEBUG, "ACPRED plane encoding: "
+ "Imode: %i, Invert: %i\n", status>>1, status&1);
+ v->condover = CONDOVER_NONE;
+ if(v->overlap && v->pq <= 8) {
+ v->condover = decode012(gb);
+ if(v->condover == CONDOVER_SELECT) {
+ status = bitplane_decoding(v->over_flags_plane, &v->overflg_is_raw, v);
+ if (status < 0) return -1;
+ av_log(v->s.avctx, AV_LOG_DEBUG, "CONDOVER plane encoding: "
+ "Imode: %i, Invert: %i\n", status>>1, status&1);
+ }
+ }
+ break;
+ case P_TYPE:
+ if(v->postprocflag)
+ v->postproc = get_bits1(gb);
+ if (v->extended_mv) v->mvrange = get_prefix(gb, 0, 3);
+ else v->mvrange = 0;
+ v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
+ v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
+ v->range_x = 1 << (v->k_x - 1);
+ v->range_y = 1 << (v->k_y - 1);
+
+ if (v->pq < 5) v->tt_index = 0;
+ else if(v->pq < 13) v->tt_index = 1;
+ else v->tt_index = 2;
+
+ lowquant = (v->pq > 12) ? 0 : 1;
+ v->mv_mode = mv_pmode_table[lowquant][get_prefix(gb, 1, 4)];
+ if (v->mv_mode == MV_PMODE_INTENSITY_COMP)
+ {
+ int scale, shift, i;
+ v->mv_mode2 = mv_pmode_table2[lowquant][get_prefix(gb, 1, 3)];
+ v->lumscale = get_bits(gb, 6);
+ v->lumshift = get_bits(gb, 6);
+ /* fill lookup tables for intensity compensation */
+ if(!v->lumscale) {
+ scale = -64;
+ shift = (255 - v->lumshift * 2) << 6;
+ if(v->lumshift > 31)
+ shift += 128 << 6;
+ } else {
+ scale = v->lumscale + 32;
+ if(v->lumshift > 31)
+ shift = (v->lumshift - 64) << 6;
+ else
+ shift = v->lumshift << 6;
+ }
+ for(i = 0; i < 256; i++) {
+ v->luty[i] = av_clip_uint8((scale * i + shift + 32) >> 6);
+ v->lutuv[i] = av_clip_uint8((scale * (i - 128) + 128*64 + 32) >> 6);
+ }
+ v->use_ic = 1;
+ }
+ if(v->mv_mode == MV_PMODE_1MV_HPEL || v->mv_mode == MV_PMODE_1MV_HPEL_BILIN)
+ v->s.quarter_sample = 0;
+ else if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {
+ if(v->mv_mode2 == MV_PMODE_1MV_HPEL || v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN)
+ v->s.quarter_sample = 0;
+ else
+ v->s.quarter_sample = 1;
+ } else
+ v->s.quarter_sample = 1;
+ v->s.mspel = !(v->mv_mode == MV_PMODE_1MV_HPEL_BILIN || (v->mv_mode == MV_PMODE_INTENSITY_COMP && v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN));
+
+ if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
+ v->mv_mode2 == MV_PMODE_MIXED_MV)
+ || v->mv_mode == MV_PMODE_MIXED_MV)
+ {
+ status = bitplane_decoding(v->mv_type_mb_plane, &v->mv_type_is_raw, v);
+ if (status < 0) return -1;
+ av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "
+ "Imode: %i, Invert: %i\n", status>>1, status&1);
+ } else {
+ v->mv_type_is_raw = 0;
+ memset(v->mv_type_mb_plane, 0, v->s.mb_stride * v->s.mb_height);
+ }
+ status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
+ if (status < 0) return -1;
+ av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
+ "Imode: %i, Invert: %i\n", status>>1, status&1);
+
+ /* Hopefully this is correct for P frames */
+ v->s.mv_table_index = get_bits(gb, 2); //but using vc1_ tables
+ v->cbpcy_vlc = &vc1_cbpcy_p_vlc[get_bits(gb, 2)];
+ if (v->dquant)
+ {
+ av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
+ vop_dquant_decoding(v);
+ }
+
+ v->ttfrm = 0; //FIXME Is that so ?
+ if (v->vstransform)
+ {
+ v->ttmbf = get_bits(gb, 1);
+ if (v->ttmbf)
+ {
+ v->ttfrm = ttfrm_to_tt[get_bits(gb, 2)];
+ }
+ } else {
+ v->ttmbf = 1;
+ v->ttfrm = TT_8X8;
+ }
+ break;
+ case B_TYPE:
+ if(v->postprocflag)
+ v->postproc = get_bits1(gb);
+ if (v->extended_mv) v->mvrange = get_prefix(gb, 0, 3);
+ else v->mvrange = 0;
+ v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
+ v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
+ v->range_x = 1 << (v->k_x - 1);
+ v->range_y = 1 << (v->k_y - 1);
+
+ if (v->pq < 5) v->tt_index = 0;
+ else if(v->pq < 13) v->tt_index = 1;
+ else v->tt_index = 2;
+
+ lowquant = (v->pq > 12) ? 0 : 1;
+ v->mv_mode = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN;
+ v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV);
+ v->s.mspel = v->s.quarter_sample;
+
+ status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v);
+ if (status < 0) return -1;
+ av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "
+ "Imode: %i, Invert: %i\n", status>>1, status&1);
+ status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
+ if (status < 0) return -1;
+ av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
+ "Imode: %i, Invert: %i\n", status>>1, status&1);
+
+ v->s.mv_table_index = get_bits(gb, 2);
+ v->cbpcy_vlc = &vc1_cbpcy_p_vlc[get_bits(gb, 2)];
+
+ if (v->dquant)
+ {
+ av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
+ vop_dquant_decoding(v);
+ }
+
+ v->ttfrm = 0;
+ if (v->vstransform)
+ {
+ v->ttmbf = get_bits(gb, 1);
+ if (v->ttmbf)
+ {
+ v->ttfrm = ttfrm_to_tt[get_bits(gb, 2)];
+ }
+ } else {
+ v->ttmbf = 1;
+ v->ttfrm = TT_8X8;
+ }
+ break;
+ }
+
+ /* AC Syntax */
+ v->c_ac_table_index = decode012(gb);
+ if (v->s.pict_type == I_TYPE || v->s.pict_type == BI_TYPE)
+ {
+ v->y_ac_table_index = decode012(gb);
+ }
+ /* DC Syntax */
+ v->s.dc_table_index = get_bits(gb, 1);
+ if ((v->s.pict_type == I_TYPE || v->s.pict_type == BI_TYPE) && v->dquant) {
+ av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
+ vop_dquant_decoding(v);
+ }
+
+ v->bi_type = 0;
+ if(v->s.pict_type == BI_TYPE) {
+ v->s.pict_type = B_TYPE;
+ v->bi_type = 1;
+ }
+ return 0;
+}
+
+/***********************************************************************/
+/**
+ * @defgroup block VC-1 Block-level functions
+ * @see 7.1.4, p91 and 8.1.1.7, p(1)04
+ * @{
+ */
+
+/**
+ * @def GET_MQUANT
+ * @brief Get macroblock-level quantizer scale
+ */
+#define GET_MQUANT() \
+ if (v->dquantfrm) \
+ { \
+ int edges = 0; \
+ if (v->dqprofile == DQPROFILE_ALL_MBS) \
+ { \
+ if (v->dqbilevel) \
+ { \
+ mquant = (get_bits(gb, 1)) ? v->altpq : v->pq; \
+ } \
+ else \
+ { \
+ mqdiff = get_bits(gb, 3); \
+ if (mqdiff != 7) mquant = v->pq + mqdiff; \
+ else mquant = get_bits(gb, 5); \
+ } \
+ } \
+ if(v->dqprofile == DQPROFILE_SINGLE_EDGE) \
+ edges = 1 << v->dqsbedge; \
+ else if(v->dqprofile == DQPROFILE_DOUBLE_EDGES) \
+ edges = (3 << v->dqsbedge) % 15; \
+ else if(v->dqprofile == DQPROFILE_FOUR_EDGES) \
+ edges = 15; \
+ if((edges&1) && !s->mb_x) \
+ mquant = v->altpq; \
+ if((edges&2) && s->first_slice_line) \
+ mquant = v->altpq; \
+ if((edges&4) && s->mb_x == (s->mb_width - 1)) \
+ mquant = v->altpq; \
+ if((edges&8) && s->mb_y == (s->mb_height - 1)) \
+ mquant = v->altpq; \
+ }
+
+/**
+ * @def GET_MVDATA(_dmv_x, _dmv_y)
+ * @brief Get MV differentials
+ * @see MVDATA decoding from 8.3.5.2, p(1)20
+ * @param _dmv_x Horizontal differential for decoded MV
+ * @param _dmv_y Vertical differential for decoded MV
+ */
+#define GET_MVDATA(_dmv_x, _dmv_y) \
+ index = 1 + get_vlc2(gb, vc1_mv_diff_vlc[s->mv_table_index].table,\
+ VC1_MV_DIFF_VLC_BITS, 2); \
+ if (index > 36) \
+ { \
+ mb_has_coeffs = 1; \
+ index -= 37; \
+ } \
+ else mb_has_coeffs = 0; \
+ s->mb_intra = 0; \
+ if (!index) { _dmv_x = _dmv_y = 0; } \
+ else if (index == 35) \
+ { \
+ _dmv_x = get_bits(gb, v->k_x - 1 + s->quarter_sample); \
+ _dmv_y = get_bits(gb, v->k_y - 1 + s->quarter_sample); \
+ } \
+ else if (index == 36) \
+ { \
+ _dmv_x = 0; \
+ _dmv_y = 0; \
+ s->mb_intra = 1; \
+ } \
+ else \
+ { \
+ index1 = index%6; \
+ if (!s->quarter_sample && index1 == 5) val = 1; \
+ else val = 0; \
+ if(size_table[index1] - val > 0) \
+ val = get_bits(gb, size_table[index1] - val); \
+ else val = 0; \
+ sign = 0 - (val&1); \
+ _dmv_x = (sign ^ ((val>>1) + offset_table[index1])) - sign; \
+ \
+ index1 = index/6; \
+ if (!s->quarter_sample && index1 == 5) val = 1; \
+ else val = 0; \
+ if(size_table[index1] - val > 0) \
+ val = get_bits(gb, size_table[index1] - val); \
+ else val = 0; \
+ sign = 0 - (val&1); \
+ _dmv_y = (sign ^ ((val>>1) + offset_table[index1])) - sign; \
+ }
+
+/** Predict and set motion vector
+ */
+static inline void vc1_pred_mv(MpegEncContext *s, int n, int dmv_x, int dmv_y, int mv1, int r_x, int r_y, uint8_t* is_intra)
+{
+ int xy, wrap, off = 0;
+ int16_t *A, *B, *C;
+ int px, py;
+ int sum;
+
+ /* scale MV difference to be quad-pel */
+ dmv_x <<= 1 - s->quarter_sample;
+ dmv_y <<= 1 - s->quarter_sample;
+
+ wrap = s->b8_stride;
+ xy = s->block_index[n];
+
+ if(s->mb_intra){
+ s->mv[0][n][0] = s->current_picture.motion_val[0][xy][0] = 0;
+ s->mv[0][n][1] = s->current_picture.motion_val[0][xy][1] = 0;
+ s->current_picture.motion_val[1][xy][0] = 0;
+ s->current_picture.motion_val[1][xy][1] = 0;
+ if(mv1) { /* duplicate motion data for 1-MV block */
+ s->current_picture.motion_val[0][xy + 1][0] = 0;
+ s->current_picture.motion_val[0][xy + 1][1] = 0;
+ s->current_picture.motion_val[0][xy + wrap][0] = 0;
+ s->current_picture.motion_val[0][xy + wrap][1] = 0;
+ s->current_picture.motion_val[0][xy + wrap + 1][0] = 0;
+ s->current_picture.motion_val[0][xy + wrap + 1][1] = 0;
+ s->current_picture.motion_val[1][xy + 1][0] = 0;
+ s->current_picture.motion_val[1][xy + 1][1] = 0;
+ s->current_picture.motion_val[1][xy + wrap][0] = 0;
+ s->current_picture.motion_val[1][xy + wrap][1] = 0;
+ s->current_picture.motion_val[1][xy + wrap + 1][0] = 0;
+ s->current_picture.motion_val[1][xy + wrap + 1][1] = 0;
+ }
+ return;
+ }
+
+ C = s->current_picture.motion_val[0][xy - 1];
+ A = s->current_picture.motion_val[0][xy - wrap];
+ if(mv1)
+ off = (s->mb_x == (s->mb_width - 1)) ? -1 : 2;
+ else {
+ //in 4-MV mode different blocks have different B predictor position
+ switch(n){
+ case 0:
+ off = (s->mb_x > 0) ? -1 : 1;
+ break;
+ case 1:
+ off = (s->mb_x == (s->mb_width - 1)) ? -1 : 1;
+ break;
+ case 2:
+ off = 1;
+ break;
+ case 3:
+ off = -1;
+ }
+ }
+ B = s->current_picture.motion_val[0][xy - wrap + off];
+
+ if(!s->first_slice_line || (n==2 || n==3)) { // predictor A is not out of bounds
+ if(s->mb_width == 1) {
+ px = A[0];
+ py = A[1];
+ } else {
+ px = mid_pred(A[0], B[0], C[0]);
+ py = mid_pred(A[1], B[1], C[1]);
+ }
+ } else if(s->mb_x || (n==1 || n==3)) { // predictor C is not out of bounds
+ px = C[0];
+ py = C[1];
+ } else {
+ px = py = 0;
+ }
+ /* Pullback MV as specified in 8.3.5.3.4 */
+ {
+ int qx, qy, X, Y;
+ qx = (s->mb_x << 6) + ((n==1 || n==3) ? 32 : 0);
+ qy = (s->mb_y << 6) + ((n==2 || n==3) ? 32 : 0);
+ X = (s->mb_width << 6) - 4;
+ Y = (s->mb_height << 6) - 4;
+ if(mv1) {
+ if(qx + px < -60) px = -60 - qx;
+ if(qy + py < -60) py = -60 - qy;
+ } else {
+ if(qx + px < -28) px = -28 - qx;
+ if(qy + py < -28) py = -28 - qy;
+ }
+ if(qx + px > X) px = X - qx;
+ if(qy + py > Y) py = Y - qy;
+ }
+ /* Calculate hybrid prediction as specified in 8.3.5.3.5 */
+ if((!s->first_slice_line || (n==2 || n==3)) && (s->mb_x || (n==1 || n==3))) {
+ if(is_intra[xy - wrap])
+ sum = FFABS(px) + FFABS(py);
+ else
+ sum = FFABS(px - A[0]) + FFABS(py - A[1]);
+ if(sum > 32) {
+ if(get_bits1(&s->gb)) {
+ px = A[0];
+ py = A[1];
+ } else {
+ px = C[0];
+ py = C[1];
+ }
+ } else {
+ if(is_intra[xy - 1])
+ sum = FFABS(px) + FFABS(py);
+ else
+ sum = FFABS(px - C[0]) + FFABS(py - C[1]);
+ if(sum > 32) {
+ if(get_bits1(&s->gb)) {
+ px = A[0];
+ py = A[1];
+ } else {
+ px = C[0];
+ py = C[1];
+ }
+ }
+ }
+ }
+ /* store MV using signed modulus of MV range defined in 4.11 */
+ s->mv[0][n][0] = s->current_picture.motion_val[0][xy][0] = ((px + dmv_x + r_x) & ((r_x << 1) - 1)) - r_x;
+ s->mv[0][n][1] = s->current_picture.motion_val[0][xy][1] = ((py + dmv_y + r_y) & ((r_y << 1) - 1)) - r_y;
+ if(mv1) { /* duplicate motion data for 1-MV block */
+ s->current_picture.motion_val[0][xy + 1][0] = s->current_picture.motion_val[0][xy][0];
+ s->current_picture.motion_val[0][xy + 1][1] = s->current_picture.motion_val[0][xy][1];
+ s->current_picture.motion_val[0][xy + wrap][0] = s->current_picture.motion_val[0][xy][0];
+ s->current_picture.motion_val[0][xy + wrap][1] = s->current_picture.motion_val[0][xy][1];
+ s->current_picture.motion_val[0][xy + wrap + 1][0] = s->current_picture.motion_val[0][xy][0];
+ s->current_picture.motion_val[0][xy + wrap + 1][1] = s->current_picture.motion_val[0][xy][1];
+ }
+}
+
+/** Motion compensation for direct or interpolated blocks in B-frames
+ */
+static void vc1_interp_mc(VC1Context *v)
+{
+ MpegEncContext *s = &v->s;
+ DSPContext *dsp = &v->s.dsp;
+ uint8_t *srcY, *srcU, *srcV;
+ int dxy, uvdxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y;
+
+ if(!v->s.next_picture.data[0])return;
+
+ mx = s->mv[1][0][0];
+ my = s->mv[1][0][1];
+ uvmx = (mx + ((mx & 3) == 3)) >> 1;
+ uvmy = (my + ((my & 3) == 3)) >> 1;
+ if(v->fastuvmc) {
+ uvmx = uvmx + ((uvmx<0)?-(uvmx&1):(uvmx&1));
+ uvmy = uvmy + ((uvmy<0)?-(uvmy&1):(uvmy&1));
+ }
+ srcY = s->next_picture.data[0];
+ srcU = s->next_picture.data[1];
+ srcV = s->next_picture.data[2];
+
+ src_x = s->mb_x * 16 + (mx >> 2);
+ src_y = s->mb_y * 16 + (my >> 2);
+ uvsrc_x = s->mb_x * 8 + (uvmx >> 2);
+ uvsrc_y = s->mb_y * 8 + (uvmy >> 2);
+
+ if(v->profile != PROFILE_ADVANCED){
+ src_x = av_clip( src_x, -16, s->mb_width * 16);
+ src_y = av_clip( src_y, -16, s->mb_height * 16);
+ uvsrc_x = av_clip(uvsrc_x, -8, s->mb_width * 8);
+ uvsrc_y = av_clip(uvsrc_y, -8, s->mb_height * 8);
+ }else{
+ src_x = av_clip( src_x, -17, s->avctx->coded_width);
+ src_y = av_clip( src_y, -18, s->avctx->coded_height + 1);
+ uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width >> 1);
+ uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1);
+ }
+
+ srcY += src_y * s->linesize + src_x;
+ srcU += uvsrc_y * s->uvlinesize + uvsrc_x;
+ srcV += uvsrc_y * s->uvlinesize + uvsrc_x;
+
+ /* for grayscale we should not try to read from unknown area */
+ if(s->flags & CODEC_FLAG_GRAY) {
+ srcU = s->edge_emu_buffer + 18 * s->linesize;
+ srcV = s->edge_emu_buffer + 18 * s->linesize;
+ }
+
+ if(v->rangeredfrm
+ || (unsigned)src_x > s->h_edge_pos - (mx&3) - 16
+ || (unsigned)src_y > s->v_edge_pos - (my&3) - 16){
+ uint8_t *uvbuf= s->edge_emu_buffer + 19 * s->linesize;
+
+ srcY -= s->mspel * (1 + s->linesize);
+ ff_emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize, 17+s->mspel*2, 17+s->mspel*2,
+ src_x - s->mspel, src_y - s->mspel, s->h_edge_pos, s->v_edge_pos);
+ srcY = s->edge_emu_buffer;
+ ff_emulated_edge_mc(uvbuf , srcU, s->uvlinesize, 8+1, 8+1,
+ uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
+ ff_emulated_edge_mc(uvbuf + 16, srcV, s->uvlinesize, 8+1, 8+1,
+ uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
+ srcU = uvbuf;
+ srcV = uvbuf + 16;
+ /* if we deal with range reduction we need to scale source blocks */
+ if(v->rangeredfrm) {
+ int i, j;
+ uint8_t *src, *src2;
+
+ src = srcY;
+ for(j = 0; j < 17 + s->mspel*2; j++) {
+ for(i = 0; i < 17 + s->mspel*2; i++) src[i] = ((src[i] - 128) >> 1) + 128;
+ src += s->linesize;
+ }
+ src = srcU; src2 = srcV;
+ for(j = 0; j < 9; j++) {
+ for(i = 0; i < 9; i++) {
+ src[i] = ((src[i] - 128) >> 1) + 128;
+ src2[i] = ((src2[i] - 128) >> 1) + 128;
+ }
+ src += s->uvlinesize;
+ src2 += s->uvlinesize;
+ }
+ }
+ srcY += s->mspel * (1 + s->linesize);
+ }
+
+ mx >>= 1;
+ my >>= 1;
+ dxy = ((my & 1) << 1) | (mx & 1);
+
+ dsp->avg_pixels_tab[0][dxy](s->dest[0], srcY, s->linesize, 16);
+
+ if(s->flags & CODEC_FLAG_GRAY) return;
+ /* Chroma MC always uses qpel blilinear */
+ uvdxy = ((uvmy & 3) << 2) | (uvmx & 3);
+ uvmx = (uvmx&3)<<1;
+ uvmy = (uvmy&3)<<1;
+ dsp->avg_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);
+ dsp->avg_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);
+}
+
+static av_always_inline int scale_mv(int value, int bfrac, int inv, int qs)
+{
+ int n = bfrac;
+
+#if B_FRACTION_DEN==256
+ if(inv)
+ n -= 256;
+ if(!qs)
+ return 2 * ((value * n + 255) >> 9);
+ return (value * n + 128) >> 8;
+#else
+ if(inv)
+ n -= B_FRACTION_DEN;
+ if(!qs)
+ return 2 * ((value * n + B_FRACTION_DEN - 1) / (2 * B_FRACTION_DEN));
+ return (value * n + B_FRACTION_DEN/2) / B_FRACTION_DEN;
+#endif
+}
+
+/** Reconstruct motion vector for B-frame and do motion compensation
+ */
+static inline void vc1_b_mc(VC1Context *v, int dmv_x[2], int dmv_y[2], int direct, int mode)
+{
+ if(v->use_ic) {
+ v->mv_mode2 = v->mv_mode;
+ v->mv_mode = MV_PMODE_INTENSITY_COMP;
+ }
+ if(direct) {
+ vc1_mc_1mv(v, 0);
+ vc1_interp_mc(v);
+ if(v->use_ic) v->mv_mode = v->mv_mode2;
+ return;
+ }
+ if(mode == BMV_TYPE_INTERPOLATED) {
+ vc1_mc_1mv(v, 0);
+ vc1_interp_mc(v);
+ if(v->use_ic) v->mv_mode = v->mv_mode2;
+ return;
+ }
+
+ if(v->use_ic && (mode == BMV_TYPE_BACKWARD)) v->mv_mode = v->mv_mode2;
+ vc1_mc_1mv(v, (mode == BMV_TYPE_BACKWARD));
+ if(v->use_ic) v->mv_mode = v->mv_mode2;
+}
+
+static inline void vc1_pred_b_mv(VC1Context *v, int dmv_x[2], int dmv_y[2], int direct, int mvtype)
+{
+ MpegEncContext *s = &v->s;
+ int xy, wrap, off = 0;
+ int16_t *A, *B, *C;
+ int px, py;
+ int sum;
+ int r_x, r_y;
+ const uint8_t *is_intra = v->mb_type[0];
+
+ r_x = v->range_x;
+ r_y = v->range_y;
+ /* scale MV difference to be quad-pel */
+ dmv_x[0] <<= 1 - s->quarter_sample;
+ dmv_y[0] <<= 1 - s->quarter_sample;
+ dmv_x[1] <<= 1 - s->quarter_sample;
+ dmv_y[1] <<= 1 - s->quarter_sample;
+
+ wrap = s->b8_stride;
+ xy = s->block_index[0];
+
+ if(s->mb_intra) {
+ s->current_picture.motion_val[0][xy][0] =
+ s->current_picture.motion_val[0][xy][1] =
+ s->current_picture.motion_val[1][xy][0] =
+ s->current_picture.motion_val[1][xy][1] = 0;
+ return;
+ }
+ s->mv[0][0][0] = scale_mv(s->next_picture.motion_val[1][xy][0], v->bfraction, 0, s->quarter_sample);
+ s->mv[0][0][1] = scale_mv(s->next_picture.motion_val[1][xy][1], v->bfraction, 0, s->quarter_sample);
+ s->mv[1][0][0] = scale_mv(s->next_picture.motion_val[1][xy][0], v->bfraction, 1, s->quarter_sample);
+ s->mv[1][0][1] = scale_mv(s->next_picture.motion_val[1][xy][1], v->bfraction, 1, s->quarter_sample);
+ if(direct) {
+ s->current_picture.motion_val[0][xy][0] = s->mv[0][0][0];
+ s->current_picture.motion_val[0][xy][1] = s->mv[0][0][1];
+ s->current_picture.motion_val[1][xy][0] = s->mv[1][0][0];
+ s->current_picture.motion_val[1][xy][1] = s->mv[1][0][1];
+ return;
+ }
+
+ if((mvtype == BMV_TYPE_FORWARD) || (mvtype == BMV_TYPE_INTERPOLATED)) {
+ C = s->current_picture.motion_val[0][xy - 2];
+ A = s->current_picture.motion_val[0][xy - wrap*2];
+ off = (s->mb_x == (s->mb_width - 1)) ? -2 : 2;
+ B = s->current_picture.motion_val[0][xy - wrap*2 + off];
+
+ if(!s->first_slice_line) { // predictor A is not out of bounds
+ if(s->mb_width == 1) {
+ px = A[0];
+ py = A[1];
+ } else {
+ px = mid_pred(A[0], B[0], C[0]);
+ py = mid_pred(A[1], B[1], C[1]);
+ }
+ } else if(s->mb_x) { // predictor C is not out of bounds
+ px = C[0];
+ py = C[1];
+ } else {
+ px = py = 0;
+ }
+ /* Pullback MV as specified in 8.3.5.3.4 */
+ {
+ int qx, qy, X, Y;
+ if(v->profile < PROFILE_ADVANCED) {
+ qx = (s->mb_x << 5);
+ qy = (s->mb_y << 5);
+ X = (s->mb_width << 5) - 4;
+ Y = (s->mb_height << 5) - 4;
+ if(qx + px < -28) px = -28 - qx;
+ if(qy + py < -28) py = -28 - qy;
+ if(qx + px > X) px = X - qx;
+ if(qy + py > Y) py = Y - qy;
+ } else {
+ qx = (s->mb_x << 6);
+ qy = (s->mb_y << 6);
+ X = (s->mb_width << 6) - 4;
+ Y = (s->mb_height << 6) - 4;
+ if(qx + px < -60) px = -60 - qx;
+ if(qy + py < -60) py = -60 - qy;
+ if(qx + px > X) px = X - qx;
+ if(qy + py > Y) py = Y - qy;
+ }
+ }
+ /* Calculate hybrid prediction as specified in 8.3.5.3.5 */
+ if(0 && !s->first_slice_line && s->mb_x) {
+ if(is_intra[xy - wrap])
+ sum = FFABS(px) + FFABS(py);
+ else
+ sum = FFABS(px - A[0]) + FFABS(py - A[1]);
+ if(sum > 32) {
+ if(get_bits1(&s->gb)) {
+ px = A[0];
+ py = A[1];
+ } else {
+ px = C[0];
+ py = C[1];
+ }
+ } else {
+ if(is_intra[xy - 2])
+ sum = FFABS(px) + FFABS(py);
+ else
+ sum = FFABS(px - C[0]) + FFABS(py - C[1]);
+ if(sum > 32) {
+ if(get_bits1(&s->gb)) {
+ px = A[0];
+ py = A[1];
+ } else {
+ px = C[0];
+ py = C[1];
+ }
+ }
+ }
+ }
+ /* store MV using signed modulus of MV range defined in 4.11 */
+ s->mv[0][0][0] = ((px + dmv_x[0] + r_x) & ((r_x << 1) - 1)) - r_x;
+ s->mv[0][0][1] = ((py + dmv_y[0] + r_y) & ((r_y << 1) - 1)) - r_y;
+ }
+ if((mvtype == BMV_TYPE_BACKWARD) || (mvtype == BMV_TYPE_INTERPOLATED)) {
+ C = s->current_picture.motion_val[1][xy - 2];
+ A = s->current_picture.motion_val[1][xy - wrap*2];
+ off = (s->mb_x == (s->mb_width - 1)) ? -2 : 2;
+ B = s->current_picture.motion_val[1][xy - wrap*2 + off];
+
+ if(!s->first_slice_line) { // predictor A is not out of bounds
+ if(s->mb_width == 1) {
+ px = A[0];
+ py = A[1];
+ } else {
+ px = mid_pred(A[0], B[0], C[0]);
+ py = mid_pred(A[1], B[1], C[1]);
+ }
+ } else if(s->mb_x) { // predictor C is not out of bounds
+ px = C[0];
+ py = C[1];
+ } else {
+ px = py = 0;
+ }
+ /* Pullback MV as specified in 8.3.5.3.4 */
+ {
+ int qx, qy, X, Y;
+ if(v->profile < PROFILE_ADVANCED) {
+ qx = (s->mb_x << 5);
+ qy = (s->mb_y << 5);
+ X = (s->mb_width << 5) - 4;
+ Y = (s->mb_height << 5) - 4;
+ if(qx + px < -28) px = -28 - qx;
+ if(qy + py < -28) py = -28 - qy;
+ if(qx + px > X) px = X - qx;
+ if(qy + py > Y) py = Y - qy;
+ } else {
+ qx = (s->mb_x << 6);
+ qy = (s->mb_y << 6);
+ X = (s->mb_width << 6) - 4;
+ Y = (s->mb_height << 6) - 4;
+ if(qx + px < -60) px = -60 - qx;
+ if(qy + py < -60) py = -60 - qy;
+ if(qx + px > X) px = X - qx;
+ if(qy + py > Y) py = Y - qy;
+ }
+ }
+ /* Calculate hybrid prediction as specified in 8.3.5.3.5 */
+ if(0 && !s->first_slice_line && s->mb_x) {
+ if(is_intra[xy - wrap])
+ sum = FFABS(px) + FFABS(py);
+ else
+ sum = FFABS(px - A[0]) + FFABS(py - A[1]);
+ if(sum > 32) {
+ if(get_bits1(&s->gb)) {
+ px = A[0];
+ py = A[1];
+ } else {
+ px = C[0];
+ py = C[1];
+ }
+ } else {
+ if(is_intra[xy - 2])
+ sum = FFABS(px) + FFABS(py);
+ else
+ sum = FFABS(px - C[0]) + FFABS(py - C[1]);
+ if(sum > 32) {
+ if(get_bits1(&s->gb)) {
+ px = A[0];
+ py = A[1];
+ } else {
+ px = C[0];
+ py = C[1];
+ }
+ }
+ }
+ }
+ /* store MV using signed modulus of MV range defined in 4.11 */
+
+ s->mv[1][0][0] = ((px + dmv_x[1] + r_x) & ((r_x << 1) - 1)) - r_x;
+ s->mv[1][0][1] = ((py + dmv_y[1] + r_y) & ((r_y << 1) - 1)) - r_y;
+ }
+ s->current_picture.motion_val[0][xy][0] = s->mv[0][0][0];
+ s->current_picture.motion_val[0][xy][1] = s->mv[0][0][1];
+ s->current_picture.motion_val[1][xy][0] = s->mv[1][0][0];
+ s->current_picture.motion_val[1][xy][1] = s->mv[1][0][1];
+}
+
+/** Get predicted DC value for I-frames only
+ * prediction dir: left=0, top=1
+ * @param s MpegEncContext
+ * @param[in] n block index in the current MB
+ * @param dc_val_ptr Pointer to DC predictor
+ * @param dir_ptr Prediction direction for use in AC prediction
+ */
+static inline int vc1_i_pred_dc(MpegEncContext *s, int overlap, int pq, int n,
+ int16_t **dc_val_ptr, int *dir_ptr)
+{
+ int a, b, c, wrap, pred, scale;
+ int16_t *dc_val;
+ static const uint16_t dcpred[32] = {
+ -1, 1024, 512, 341, 256, 205, 171, 146, 128,
+ 114, 102, 93, 85, 79, 73, 68, 64,
+ 60, 57, 54, 51, 49, 47, 45, 43,
+ 41, 39, 38, 37, 35, 34, 33
+ };
+
+ /* find prediction - wmv3_dc_scale always used here in fact */
+ if (n < 4) scale = s->y_dc_scale;
+ else scale = s->c_dc_scale;
+
+ wrap = s->block_wrap[n];
+ dc_val= s->dc_val[0] + s->block_index[n];
+
+ /* B A
+ * C X
+ */
+ c = dc_val[ - 1];
+ b = dc_val[ - 1 - wrap];
+ a = dc_val[ - wrap];
+
+ if (pq < 9 || !overlap)
+ {
+ /* Set outer values */
+ if (s->first_slice_line && (n!=2 && n!=3)) b=a=dcpred[scale];
+ if (s->mb_x == 0 && (n!=1 && n!=3)) b=c=dcpred[scale];
+ }
+ else
+ {
+ /* Set outer values */
+ if (s->first_slice_line && (n!=2 && n!=3)) b=a=0;
+ if (s->mb_x == 0 && (n!=1 && n!=3)) b=c=0;
+ }
+
+ if (abs(a - b) <= abs(b - c)) {
+ pred = c;
+ *dir_ptr = 1;//left
+ } else {
+ pred = a;
+ *dir_ptr = 0;//top
+ }
+
+ /* update predictor */
+ *dc_val_ptr = &dc_val[0];
+ return pred;
+}
+
+
+/** Get predicted DC value
+ * prediction dir: left=0, top=1
+ * @param s MpegEncContext
+ * @param[in] n block index in the current MB
+ * @param dc_val_ptr Pointer to DC predictor
+ * @param dir_ptr Prediction direction for use in AC prediction
+ */
+static inline int vc1_pred_dc(MpegEncContext *s, int overlap, int pq, int n,
+ int a_avail, int c_avail,
+ int16_t **dc_val_ptr, int *dir_ptr)
+{
+ int a, b, c, wrap, pred, scale;
+ int16_t *dc_val;
+ int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
+ int q1, q2 = 0;
+
+ /* find prediction - wmv3_dc_scale always used here in fact */
+ if (n < 4) scale = s->y_dc_scale;
+ else scale = s->c_dc_scale;
+
+ wrap = s->block_wrap[n];
+ dc_val= s->dc_val[0] + s->block_index[n];
+
+ /* B A
+ * C X
+ */
+ c = dc_val[ - 1];
+ b = dc_val[ - 1 - wrap];
+ a = dc_val[ - wrap];
+ /* scale predictors if needed */
+ q1 = s->current_picture.qscale_table[mb_pos];
+ if(c_avail && (n!= 1 && n!=3)) {
+ q2 = s->current_picture.qscale_table[mb_pos - 1];
+ if(q2 && q2 != q1)
+ c = (c * s->y_dc_scale_table[q2] * vc1_dqscale[s->y_dc_scale_table[q1] - 1] + 0x20000) >> 18;
+ }
+ if(a_avail && (n!= 2 && n!=3)) {
+ q2 = s->current_picture.qscale_table[mb_pos - s->mb_stride];
+ if(q2 && q2 != q1)
+ a = (a * s->y_dc_scale_table[q2] * vc1_dqscale[s->y_dc_scale_table[q1] - 1] + 0x20000) >> 18;
+ }
+ if(a_avail && c_avail && (n!=3)) {
+ int off = mb_pos;
+ if(n != 1) off--;
+ if(n != 2) off -= s->mb_stride;
+ q2 = s->current_picture.qscale_table[off];
+ if(q2 && q2 != q1)
+ b = (b * s->y_dc_scale_table[q2] * vc1_dqscale[s->y_dc_scale_table[q1] - 1] + 0x20000) >> 18;
+ }
+
+ if(a_avail && c_avail) {
+ if(abs(a - b) <= abs(b - c)) {
+ pred = c;
+ *dir_ptr = 1;//left
+ } else {
+ pred = a;
+ *dir_ptr = 0;//top
+ }
+ } else if(a_avail) {
+ pred = a;
+ *dir_ptr = 0;//top
+ } else if(c_avail) {
+ pred = c;
+ *dir_ptr = 1;//left
+ } else {
+ pred = 0;
+ *dir_ptr = 1;//left
+ }
+
+ /* update predictor */
+ *dc_val_ptr = &dc_val[0];
+ return pred;
+}
+
+
+/**
+ * @defgroup std_mb VC1 Macroblock-level functions in Simple/Main Profiles
+ * @see 7.1.4, p91 and 8.1.1.7, p(1)04
+ * @{
+ */
+
+static inline int vc1_coded_block_pred(MpegEncContext * s, int n, uint8_t **coded_block_ptr)
+{
+ int xy, wrap, pred, a, b, c;
+
+ xy = s->block_index[n];
+ wrap = s->b8_stride;
+
+ /* B C
+ * A X
+ */
+ a = s->coded_block[xy - 1 ];
+ b = s->coded_block[xy - 1 - wrap];
+ c = s->coded_block[xy - wrap];
+
+ if (b == c) {
+ pred = a;
+ } else {
+ pred = c;
+ }
+
+ /* store value */
+ *coded_block_ptr = &s->coded_block[xy];
+
+ return pred;
+}
+
+/**
+ * Decode one AC coefficient
+ * @param v The VC1 context
+ * @param last Last coefficient
+ * @param skip How much zero coefficients to skip
+ * @param value Decoded AC coefficient value
+ * @see 8.1.3.4
+ */
+static void vc1_decode_ac_coeff(VC1Context *v, int *last, int *skip, int *value, int codingset)
+{
+ GetBitContext *gb = &v->s.gb;
+ int index, escape, run = 0, level = 0, lst = 0;
+
+ index = get_vlc2(gb, vc1_ac_coeff_table[codingset].table, AC_VLC_BITS, 3);
+ if (index != vc1_ac_sizes[codingset] - 1) {
+ run = vc1_index_decode_table[codingset][index][0];
+ level = vc1_index_decode_table[codingset][index][1];
+ lst = index >= vc1_last_decode_table[codingset];
+ if(get_bits(gb, 1))
+ level = -level;
+ } else {
+ escape = decode210(gb);
+ if (escape != 2) {
+ index = get_vlc2(gb, vc1_ac_coeff_table[codingset].table, AC_VLC_BITS, 3);
+ run = vc1_index_decode_table[codingset][index][0];
+ level = vc1_index_decode_table[codingset][index][1];
+ lst = index >= vc1_last_decode_table[codingset];
+ if(escape == 0) {
+ if(lst)
+ level += vc1_last_delta_level_table[codingset][run];
+ else
+ level += vc1_delta_level_table[codingset][run];
+ } else {
+ if(lst)
+ run += vc1_last_delta_run_table[codingset][level] + 1;
+ else
+ run += vc1_delta_run_table[codingset][level] + 1;
+ }
+ if(get_bits(gb, 1))
+ level = -level;
+ } else {
+ int sign;
+ lst = get_bits(gb, 1);
+ if(v->s.esc3_level_length == 0) {
+ if(v->pq < 8 || v->dquantfrm) { // table 59
+ v->s.esc3_level_length = get_bits(gb, 3);
+ if(!v->s.esc3_level_length)
+ v->s.esc3_level_length = get_bits(gb, 2) + 8;
+ } else { //table 60
+ v->s.esc3_level_length = get_prefix(gb, 1, 6) + 2;
+ }
+ v->s.esc3_run_length = 3 + get_bits(gb, 2);
+ }
+ run = get_bits(gb, v->s.esc3_run_length);
+ sign = get_bits(gb, 1);
+ level = get_bits(gb, v->s.esc3_level_length);
+ if(sign)
+ level = -level;
+ }
+ }
+
+ *last = lst;
+ *skip = run;
+ *value = level;
+}
+
+/** Decode intra block in intra frames - should be faster than decode_intra_block
+ * @param v VC1Context
+ * @param block block to decode
+ * @param coded are AC coeffs present or not
+ * @param codingset set of VLC to decode data
+ */
+static int vc1_decode_i_block(VC1Context *v, DCTELEM block[64], int n, int coded, int codingset)
+{
+ GetBitContext *gb = &v->s.gb;
+ MpegEncContext *s = &v->s;
+ int dc_pred_dir = 0; /* Direction of the DC prediction used */
+ int run_diff, i;
+ int16_t *dc_val;
+ int16_t *ac_val, *ac_val2;
+ int dcdiff;
+
+ /* Get DC differential */
+ if (n < 4) {
+ dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
+ } else {
+ dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
+ }
+ if (dcdiff < 0){
+ av_log(s->avctx, AV_LOG_ERROR, "Illegal DC VLC\n");
+ return -1;
+ }
+ if (dcdiff)
+ {
+ if (dcdiff == 119 /* ESC index value */)
+ {
+ /* TODO: Optimize */
+ if (v->pq == 1) dcdiff = get_bits(gb, 10);
+ else if (v->pq == 2) dcdiff = get_bits(gb, 9);
+ else dcdiff = get_bits(gb, 8);
+ }
+ else
+ {
+ if (v->pq == 1)
+ dcdiff = (dcdiff<<2) + get_bits(gb, 2) - 3;
+ else if (v->pq == 2)
+ dcdiff = (dcdiff<<1) + get_bits(gb, 1) - 1;
+ }
+ if (get_bits(gb, 1))
+ dcdiff = -dcdiff;
+ }
+
+ /* Prediction */
+ dcdiff += vc1_i_pred_dc(&v->s, v->overlap, v->pq, n, &dc_val, &dc_pred_dir);
+ *dc_val = dcdiff;
+
+ /* Store the quantized DC coeff, used for prediction */
+ if (n < 4) {
+ block[0] = dcdiff * s->y_dc_scale;
+ } else {
+ block[0] = dcdiff * s->c_dc_scale;
+ }
+ /* Skip ? */
+ run_diff = 0;
+ i = 0;
+ if (!coded) {
+ goto not_coded;
+ }
+
+ //AC Decoding
+ i = 1;
+
+ {
+ int last = 0, skip, value;
+ const int8_t *zz_table;
+ int scale;
+ int k;
+
+ scale = v->pq * 2 + v->halfpq;
+
+ if(v->s.ac_pred) {
+ if(!dc_pred_dir)
+ zz_table = vc1_horizontal_zz;
+ else
+ zz_table = vc1_vertical_zz;
+ } else
+ zz_table = vc1_normal_zz;
+
+ ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
+ ac_val2 = ac_val;
+ if(dc_pred_dir) //left
+ ac_val -= 16;
+ else //top
+ ac_val -= 16 * s->block_wrap[n];
+
+ while (!last) {
+ vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);
+ i += skip;
+ if(i > 63)
+ break;
+ block[zz_table[i++]] = value;
+ }
+
+ /* apply AC prediction if needed */
+ if(s->ac_pred) {
+ if(dc_pred_dir) { //left
+ for(k = 1; k < 8; k++)
+ block[k << 3] += ac_val[k];
+ } else { //top
+ for(k = 1; k < 8; k++)
+ block[k] += ac_val[k + 8];
+ }
+ }
+ /* save AC coeffs for further prediction */
+ for(k = 1; k < 8; k++) {
+ ac_val2[k] = block[k << 3];
+ ac_val2[k + 8] = block[k];
+ }
+
+ /* scale AC coeffs */
+ for(k = 1; k < 64; k++)
+ if(block[k]) {
+ block[k] *= scale;
+ if(!v->pquantizer)
+ block[k] += (block[k] < 0) ? -v->pq : v->pq;
+ }
+
+ if(s->ac_pred) i = 63;
+ }
+
+not_coded:
+ if(!coded) {
+ int k, scale;
+ ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
+ ac_val2 = ac_val;
+
+ scale = v->pq * 2 + v->halfpq;
+ memset(ac_val2, 0, 16 * 2);
+ if(dc_pred_dir) {//left
+ ac_val -= 16;
+ if(s->ac_pred)
+ memcpy(ac_val2, ac_val, 8 * 2);
+ } else {//top
+ ac_val -= 16 * s->block_wrap[n];
+ if(s->ac_pred)
+ memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
+ }
+
+ /* apply AC prediction if needed */
+ if(s->ac_pred) {
+ if(dc_pred_dir) { //left
+ for(k = 1; k < 8; k++) {
+ block[k << 3] = ac_val[k] * scale;
+ if(!v->pquantizer && block[k << 3])
+ block[k << 3] += (block[k << 3] < 0) ? -v->pq : v->pq;
+ }
+ } else { //top
+ for(k = 1; k < 8; k++) {
+ block[k] = ac_val[k + 8] * scale;
+ if(!v->pquantizer && block[k])
+ block[k] += (block[k] < 0) ? -v->pq : v->pq;
+ }
+ }
+ i = 63;
+ }
+ }
+ s->block_last_index[n] = i;
+
+ return 0;
+}
+
+/** Decode intra block in intra frames - should be faster than decode_intra_block
+ * @param v VC1Context
+ * @param block block to decode
+ * @param coded are AC coeffs present or not
+ * @param codingset set of VLC to decode data
+ */
+static int vc1_decode_i_block_adv(VC1Context *v, DCTELEM block[64], int n, int coded, int codingset, int mquant)
+{
+ GetBitContext *gb = &v->s.gb;
+ MpegEncContext *s = &v->s;
+ int dc_pred_dir = 0; /* Direction of the DC prediction used */
+ int run_diff, i;
+ int16_t *dc_val;
+ int16_t *ac_val, *ac_val2;
+ int dcdiff;
+ int a_avail = v->a_avail, c_avail = v->c_avail;
+ int use_pred = s->ac_pred;
+ int scale;
+ int q1, q2 = 0;
+ int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
+
+ /* Get DC differential */
+ if (n < 4) {
+ dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
+ } else {
+ dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
+ }
+ if (dcdiff < 0){
+ av_log(s->avctx, AV_LOG_ERROR, "Illegal DC VLC\n");
+ return -1;
+ }
+ if (dcdiff)
+ {
+ if (dcdiff == 119 /* ESC index value */)
+ {
+ /* TODO: Optimize */
+ if (mquant == 1) dcdiff = get_bits(gb, 10);
+ else if (mquant == 2) dcdiff = get_bits(gb, 9);
+ else dcdiff = get_bits(gb, 8);
+ }
+ else
+ {
+ if (mquant == 1)
+ dcdiff = (dcdiff<<2) + get_bits(gb, 2) - 3;
+ else if (mquant == 2)
+ dcdiff = (dcdiff<<1) + get_bits(gb, 1) - 1;
+ }
+ if (get_bits(gb, 1))
+ dcdiff = -dcdiff;
+ }
+
+ /* Prediction */
+ dcdiff += vc1_pred_dc(&v->s, v->overlap, mquant, n, v->a_avail, v->c_avail, &dc_val, &dc_pred_dir);
+ *dc_val = dcdiff;
+
+ /* Store the quantized DC coeff, used for prediction */
+ if (n < 4) {
+ block[0] = dcdiff * s->y_dc_scale;
+ } else {
+ block[0] = dcdiff * s->c_dc_scale;
+ }
+ /* Skip ? */
+ run_diff = 0;
+ i = 0;
+
+ //AC Decoding
+ i = 1;
+
+ /* check if AC is needed at all and adjust direction if needed */
+ if(!a_avail) dc_pred_dir = 1;
+ if(!c_avail) dc_pred_dir = 0;
+ if(!a_avail && !c_avail) use_pred = 0;
+ ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
+ ac_val2 = ac_val;
+
+ scale = mquant * 2 + v->halfpq;
+
+ if(dc_pred_dir) //left
+ ac_val -= 16;
+ else //top
+ ac_val -= 16 * s->block_wrap[n];
+
+ q1 = s->current_picture.qscale_table[mb_pos];
+ if(dc_pred_dir && c_avail && mb_pos) q2 = s->current_picture.qscale_table[mb_pos - 1];
+ if(!dc_pred_dir && a_avail && mb_pos >= s->mb_stride) q2 = s->current_picture.qscale_table[mb_pos - s->mb_stride];
+ if(dc_pred_dir && n==1) q2 = q1;
+ if(!dc_pred_dir && n==2) q2 = q1;
+ if(n==3) q2 = q1;
+
+ if(coded) {
+ int last = 0, skip, value;
+ const int8_t *zz_table;
+ int k;
+
+ if(v->s.ac_pred) {
+ if(!dc_pred_dir)
+ zz_table = vc1_horizontal_zz;
+ else
+ zz_table = vc1_vertical_zz;
+ } else
+ zz_table = vc1_normal_zz;
+
+ while (!last) {
+ vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);
+ i += skip;
+ if(i > 63)
+ break;
+ block[zz_table[i++]] = value;
+ }
+
+ /* apply AC prediction if needed */
+ if(use_pred) {
+ /* scale predictors if needed*/
+ if(q2 && q1!=q2) {
+ q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
+ q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
+
+ if(dc_pred_dir) { //left
+ for(k = 1; k < 8; k++)
+ block[k << 3] += (ac_val[k] * q2 * vc1_dqscale[q1 - 1] + 0x20000) >> 18;
+ } else { //top
+ for(k = 1; k < 8; k++)
+ block[k] += (ac_val[k + 8] * q2 * vc1_dqscale[q1 - 1] + 0x20000) >> 18;
+ }
+ } else {
+ if(dc_pred_dir) { //left
+ for(k = 1; k < 8; k++)
+ block[k << 3] += ac_val[k];
+ } else { //top
+ for(k = 1; k < 8; k++)
+ block[k] += ac_val[k + 8];
+ }
+ }
+ }
+ /* save AC coeffs for further prediction */
+ for(k = 1; k < 8; k++) {
+ ac_val2[k] = block[k << 3];
+ ac_val2[k + 8] = block[k];
+ }
+
+ /* scale AC coeffs */
+ for(k = 1; k < 64; k++)
+ if(block[k]) {
+ block[k] *= scale;
+ if(!v->pquantizer)
+ block[k] += (block[k] < 0) ? -mquant : mquant;
+ }
+
+ if(use_pred) i = 63;
+ } else { // no AC coeffs
+ int k;
+
+ memset(ac_val2, 0, 16 * 2);
+ if(dc_pred_dir) {//left
+ if(use_pred) {
+ memcpy(ac_val2, ac_val, 8 * 2);
+ if(q2 && q1!=q2) {
+ q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
+ q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
+ for(k = 1; k < 8; k++)
+ ac_val2[k] = (ac_val2[k] * q2 * vc1_dqscale[q1 - 1] + 0x20000) >> 18;
+ }
+ }
+ } else {//top
+ if(use_pred) {
+ memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
+ if(q2 && q1!=q2) {
+ q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
+ q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
+ for(k = 1; k < 8; k++)
+ ac_val2[k + 8] = (ac_val2[k + 8] * q2 * vc1_dqscale[q1 - 1] + 0x20000) >> 18;
+ }
+ }
+ }
+
+ /* apply AC prediction if needed */
+ if(use_pred) {
+ if(dc_pred_dir) { //left
+ for(k = 1; k < 8; k++) {
+ block[k << 3] = ac_val2[k] * scale;
+ if(!v->pquantizer && block[k << 3])
+ block[k << 3] += (block[k << 3] < 0) ? -mquant : mquant;
+ }
+ } else { //top
+ for(k = 1; k < 8; k++) {
+ block[k] = ac_val2[k + 8] * scale;
+ if(!v->pquantizer && block[k])
+ block[k] += (block[k] < 0) ? -mquant : mquant;
+ }
+ }
+ i = 63;
+ }
+ }
+ s->block_last_index[n] = i;
+
+ return 0;
+}
+
+/** Decode intra block in inter frames - more generic version than vc1_decode_i_block
+ * @param v VC1Context
+ * @param block block to decode
+ * @param coded are AC coeffs present or not
+ * @param mquant block quantizer
+ * @param codingset set of VLC to decode data
+ */
+static int vc1_decode_intra_block(VC1Context *v, DCTELEM block[64], int n, int coded, int mquant, int codingset)
+{
+ GetBitContext *gb = &v->s.gb;
+ MpegEncContext *s = &v->s;
+ int dc_pred_dir = 0; /* Direction of the DC prediction used */
+ int run_diff, i;
+ int16_t *dc_val;
+ int16_t *ac_val, *ac_val2;
+ int dcdiff;
+ int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
+ int a_avail = v->a_avail, c_avail = v->c_avail;
+ int use_pred = s->ac_pred;
+ int scale;
+ int q1, q2 = 0;
+
+ /* XXX: Guard against dumb values of mquant */
+ mquant = (mquant < 1) ? 0 : ( (mquant>31) ? 31 : mquant );
+
+ /* Set DC scale - y and c use the same */
+ s->y_dc_scale = s->y_dc_scale_table[mquant];
+ s->c_dc_scale = s->c_dc_scale_table[mquant];
+
+ /* Get DC differential */
+ if (n < 4) {
+ dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
+ } else {
+ dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
+ }
+ if (dcdiff < 0){
+ av_log(s->avctx, AV_LOG_ERROR, "Illegal DC VLC\n");
+ return -1;
+ }
+ if (dcdiff)
+ {
+ if (dcdiff == 119 /* ESC index value */)
+ {
+ /* TODO: Optimize */
+ if (mquant == 1) dcdiff = get_bits(gb, 10);
+ else if (mquant == 2) dcdiff = get_bits(gb, 9);
+ else dcdiff = get_bits(gb, 8);
+ }
+ else
+ {
+ if (mquant == 1)
+ dcdiff = (dcdiff<<2) + get_bits(gb, 2) - 3;
+ else if (mquant == 2)
+ dcdiff = (dcdiff<<1) + get_bits(gb, 1) - 1;
+ }
+ if (get_bits(gb, 1))
+ dcdiff = -dcdiff;
+ }
+
+ /* Prediction */
+ dcdiff += vc1_pred_dc(&v->s, v->overlap, mquant, n, a_avail, c_avail, &dc_val, &dc_pred_dir);
+ *dc_val = dcdiff;
+
+ /* Store the quantized DC coeff, used for prediction */
+
+ if (n < 4) {
+ block[0] = dcdiff * s->y_dc_scale;
+ } else {
+ block[0] = dcdiff * s->c_dc_scale;
+ }
+ /* Skip ? */
+ run_diff = 0;
+ i = 0;
+
+ //AC Decoding
+ i = 1;
+
+ /* check if AC is needed at all and adjust direction if needed */
+ if(!a_avail) dc_pred_dir = 1;
+ if(!c_avail) dc_pred_dir = 0;
+ if(!a_avail && !c_avail) use_pred = 0;
+ ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
+ ac_val2 = ac_val;
+
+ scale = mquant * 2 + v->halfpq;
+
+ if(dc_pred_dir) //left
+ ac_val -= 16;
+ else //top
+ ac_val -= 16 * s->block_wrap[n];
+
+ q1 = s->current_picture.qscale_table[mb_pos];
+ if(dc_pred_dir && c_avail && mb_pos) q2 = s->current_picture.qscale_table[mb_pos - 1];
+ if(!dc_pred_dir && a_avail && mb_pos >= s->mb_stride) q2 = s->current_picture.qscale_table[mb_pos - s->mb_stride];
+ if(dc_pred_dir && n==1) q2 = q1;
+ if(!dc_pred_dir && n==2) q2 = q1;
+ if(n==3) q2 = q1;
+
+ if(coded) {
+ int last = 0, skip, value;
+ const int8_t *zz_table;
+ int k;
+
+ zz_table = vc1_simple_progressive_8x8_zz;
+
+ while (!last) {
+ vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);
+ i += skip;
+ if(i > 63)
+ break;
+ block[zz_table[i++]] = value;
+ }
+
+ /* apply AC prediction if needed */
+ if(use_pred) {
+ /* scale predictors if needed*/
+ if(q2 && q1!=q2) {
+ q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
+ q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
+
+ if(dc_pred_dir) { //left
+ for(k = 1; k < 8; k++)
+ block[k << 3] += (ac_val[k] * q2 * vc1_dqscale[q1 - 1] + 0x20000) >> 18;
+ } else { //top
+ for(k = 1; k < 8; k++)
+ block[k] += (ac_val[k + 8] * q2 * vc1_dqscale[q1 - 1] + 0x20000) >> 18;
+ }
+ } else {
+ if(dc_pred_dir) { //left
+ for(k = 1; k < 8; k++)
+ block[k << 3] += ac_val[k];
+ } else { //top
+ for(k = 1; k < 8; k++)
+ block[k] += ac_val[k + 8];
+ }
+ }
+ }
+ /* save AC coeffs for further prediction */
+ for(k = 1; k < 8; k++) {
+ ac_val2[k] = block[k << 3];
+ ac_val2[k + 8] = block[k];
+ }
+
+ /* scale AC coeffs */
+ for(k = 1; k < 64; k++)
+ if(block[k]) {
+ block[k] *= scale;
+ if(!v->pquantizer)
+ block[k] += (block[k] < 0) ? -mquant : mquant;
+ }
+
+ if(use_pred) i = 63;
+ } else { // no AC coeffs
+ int k;
+
+ memset(ac_val2, 0, 16 * 2);
+ if(dc_pred_dir) {//left
+ if(use_pred) {
+ memcpy(ac_val2, ac_val, 8 * 2);
+ if(q2 && q1!=q2) {
+ q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
+ q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
+ for(k = 1; k < 8; k++)
+ ac_val2[k] = (ac_val2[k] * q2 * vc1_dqscale[q1 - 1] + 0x20000) >> 18;
+ }
+ }
+ } else {//top
+ if(use_pred) {
+ memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
+ if(q2 && q1!=q2) {
+ q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
+ q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
+ for(k = 1; k < 8; k++)
+ ac_val2[k + 8] = (ac_val2[k + 8] * q2 * vc1_dqscale[q1 - 1] + 0x20000) >> 18;
+ }
+ }
+ }
+
+ /* apply AC prediction if needed */
+ if(use_pred) {
+ if(dc_pred_dir) { //left
+ for(k = 1; k < 8; k++) {
+ block[k << 3] = ac_val2[k] * scale;
+ if(!v->pquantizer && block[k << 3])
+ block[k << 3] += (block[k << 3] < 0) ? -mquant : mquant;
+ }
+ } else { //top
+ for(k = 1; k < 8; k++) {
+ block[k] = ac_val2[k + 8] * scale;
+ if(!v->pquantizer && block[k])
+ block[k] += (block[k] < 0) ? -mquant : mquant;
+ }
+ }
+ i = 63;
+ }
+ }
+ s->block_last_index[n] = i;
+
+ return 0;
+}
+
+/** Decode P block
+ */
+static int vc1_decode_p_block(VC1Context *v, DCTELEM block[64], int n, int mquant, int ttmb, int first_block)
+{
+ MpegEncContext *s = &v->s;
+ GetBitContext *gb = &s->gb;
+ int i, j;
+ int subblkpat = 0;
+ int scale, off, idx, last, skip, value;
+ int ttblk = ttmb & 7;
+
+ if(ttmb == -1) {
+ ttblk = ttblk_to_tt[v->tt_index][get_vlc2(gb, vc1_ttblk_vlc[v->tt_index].table, VC1_TTBLK_VLC_BITS, 1)];
+ }
+ if(ttblk == TT_4X4) {
+ subblkpat = ~(get_vlc2(gb, vc1_subblkpat_vlc[v->tt_index].table, VC1_SUBBLKPAT_VLC_BITS, 1) + 1);
+ }
+ if((ttblk != TT_8X8 && ttblk != TT_4X4) && (v->ttmbf || (ttmb != -1 && (ttmb & 8) && !first_block))) {
+ subblkpat = decode012(gb);
+ if(subblkpat) subblkpat ^= 3; //swap decoded pattern bits
+ if(ttblk == TT_8X4_TOP || ttblk == TT_8X4_BOTTOM) ttblk = TT_8X4;
+ if(ttblk == TT_4X8_RIGHT || ttblk == TT_4X8_LEFT) ttblk = TT_4X8;
+ }
+ scale = 2 * mquant + v->halfpq;
+
+ // convert transforms like 8X4_TOP to generic TT and SUBBLKPAT
+ if(ttblk == TT_8X4_TOP || ttblk == TT_8X4_BOTTOM) {
+ subblkpat = 2 - (ttblk == TT_8X4_TOP);
+ ttblk = TT_8X4;
+ }
+ if(ttblk == TT_4X8_RIGHT || ttblk == TT_4X8_LEFT) {
+ subblkpat = 2 - (ttblk == TT_4X8_LEFT);
+ ttblk = TT_4X8;
+ }
+ switch(ttblk) {
+ case TT_8X8:
+ i = 0;
+ last = 0;
+ while (!last) {
+ vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
+ i += skip;
+ if(i > 63)
+ break;
+ idx = vc1_simple_progressive_8x8_zz[i++];
+ block[idx] = value * scale;
+ if(!v->pquantizer)
+ block[idx] += (block[idx] < 0) ? -mquant : mquant;
+ }
+ s->dsp.vc1_inv_trans_8x8(block);
+ break;
+ case TT_4X4:
+ for(j = 0; j < 4; j++) {
+ last = subblkpat & (1 << (3 - j));
+ i = 0;
+ off = (j & 1) * 4 + (j & 2) * 16;
+ while (!last) {
+ vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
+ i += skip;
+ if(i > 15)
+ break;
+ idx = vc1_simple_progressive_4x4_zz[i++];
+ block[idx + off] = value * scale;
+ if(!v->pquantizer)
+ block[idx + off] += (block[idx + off] < 0) ? -mquant : mquant;
+ }
+ if(!(subblkpat & (1 << (3 - j))))
+ s->dsp.vc1_inv_trans_4x4(block, j);
+ }
+ break;
+ case TT_8X4:
+ for(j = 0; j < 2; j++) {
+ last = subblkpat & (1 << (1 - j));
+ i = 0;
+ off = j * 32;
+ while (!last) {
+ vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
+ i += skip;
+ if(i > 31)
+ break;
+ if(v->profile < PROFILE_ADVANCED)
+ idx = vc1_simple_progressive_8x4_zz[i++];
+ else
+ idx = vc1_adv_progressive_8x4_zz[i++];
+ block[idx + off] = value * scale;
+ if(!v->pquantizer)
+ block[idx + off] += (block[idx + off] < 0) ? -mquant : mquant;
+ }
+ if(!(subblkpat & (1 << (1 - j))))
+ s->dsp.vc1_inv_trans_8x4(block, j);
+ }
+ break;
+ case TT_4X8:
+ for(j = 0; j < 2; j++) {
+ last = subblkpat & (1 << (1 - j));
+ i = 0;
+ off = j * 4;
+ while (!last) {
+ vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
+ i += skip;
+ if(i > 31)
+ break;
+ if(v->profile < PROFILE_ADVANCED)
+ idx = vc1_simple_progressive_4x8_zz[i++];
+ else
+ idx = vc1_adv_progressive_4x8_zz[i++];
+ block[idx + off] = value * scale;
+ if(!v->pquantizer)
+ block[idx + off] += (block[idx + off] < 0) ? -mquant : mquant;
+ }
+ if(!(subblkpat & (1 << (1 - j))))
+ s->dsp.vc1_inv_trans_4x8(block, j);
+ }
+ break;
+ }
+ return 0;
+}
+
+
+/** Decode one P-frame MB (in Simple/Main profile)
+ */
+static int vc1_decode_p_mb(VC1Context *v)
+{
+ MpegEncContext *s = &v->s;
+ GetBitContext *gb = &s->gb;
+ int i, j;
+ int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
+ int cbp; /* cbp decoding stuff */
+ int mqdiff, mquant; /* MB quantization */
+ int ttmb = v->ttfrm; /* MB Transform type */
+ int status;
+
+ static const int size_table[6] = { 0, 2, 3, 4, 5, 8 },
+ offset_table[6] = { 0, 1, 3, 7, 15, 31 };
+ int mb_has_coeffs = 1; /* last_flag */
+ int dmv_x, dmv_y; /* Differential MV components */
+ int index, index1; /* LUT indices */
+ int val, sign; /* temp values */
+ int first_block = 1;
+ int dst_idx, off;
+ int skipped, fourmv;
+
+ mquant = v->pq; /* Loosy initialization */
+
+ if (v->mv_type_is_raw)
+ fourmv = get_bits1(gb);
+ else
+ fourmv = v->mv_type_mb_plane[mb_pos];
+ if (v->skip_is_raw)
+ skipped = get_bits1(gb);
+ else
+ skipped = v->s.mbskip_table[mb_pos];
+
+ s->dsp.clear_blocks(s->block[0]);
+
+ if (!fourmv) /* 1MV mode */
+ {
+ if (!skipped)
+ {
+ GET_MVDATA(dmv_x, dmv_y);
+
+ if (s->mb_intra) {
+ s->current_picture.motion_val[1][s->block_index[0]][0] = 0;
+ s->current_picture.motion_val[1][s->block_index[0]][1] = 0;
+ }
+ s->current_picture.mb_type[mb_pos] = s->mb_intra ? MB_TYPE_INTRA : MB_TYPE_16x16;
+ vc1_pred_mv(s, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0]);
+
+ /* FIXME Set DC val for inter block ? */
+ if (s->mb_intra && !mb_has_coeffs)
+ {
+ GET_MQUANT();
+ s->ac_pred = get_bits(gb, 1);
+ cbp = 0;
+ }
+ else if (mb_has_coeffs)
+ {
+ if (s->mb_intra) s->ac_pred = get_bits(gb, 1);
+ cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
+ GET_MQUANT();
+ }
+ else
+ {
+ mquant = v->pq;
+ cbp = 0;
+ }
+ s->current_picture.qscale_table[mb_pos] = mquant;
+
+ if (!v->ttmbf && !s->mb_intra && mb_has_coeffs)
+ ttmb = get_vlc2(gb, vc1_ttmb_vlc[v->tt_index].table,
+ VC1_TTMB_VLC_BITS, 2);
+ if(!s->mb_intra) vc1_mc_1mv(v, 0);
+ dst_idx = 0;
+ for (i=0; i<6; i++)
+ {
+ s->dc_val[0][s->block_index[i]] = 0;
+ dst_idx += i >> 2;
+ val = ((cbp >> (5 - i)) & 1);
+ off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
+ v->mb_type[0][s->block_index[i]] = s->mb_intra;
+ if(s->mb_intra) {
+ /* check if prediction blocks A and C are available */
+ v->a_avail = v->c_avail = 0;
+ if(i == 2 || i == 3 || !s->first_slice_line)
+ v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
+ if(i == 1 || i == 3 || s->mb_x)
+ v->c_avail = v->mb_type[0][s->block_index[i] - 1];
+
+ vc1_decode_intra_block(v, s->block[i], i, val, mquant, (i&4)?v->codingset2:v->codingset);
+ if((i>3) && (s->flags & CODEC_FLAG_GRAY)) continue;
+ s->dsp.vc1_inv_trans_8x8(s->block[i]);
+ if(v->rangeredfrm) for(j = 0; j < 64; j++) s->block[i][j] <<= 1;
+ for(j = 0; j < 64; j++) s->block[i][j] += 128;
+ if(!v->res_fasttx && v->res_x8) for(j = 0; j < 64; j++) s->block[i][j] += 16;
+ s->dsp.put_pixels_clamped(s->block[i], s->dest[dst_idx] + off, s->linesize >> ((i & 4) >> 2));
+ if(v->pq >= 9 && v->overlap) {
+ if(v->c_avail)
+ s->dsp.vc1_h_overlap(s->dest[dst_idx] + off, s->linesize >> ((i & 4) >> 2));
+ if(v->a_avail)
+ s->dsp.vc1_v_overlap(s->dest[dst_idx] + off, s->linesize >> ((i & 4) >> 2));
+ }
+ } else if(val) {
+ vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block);
+ if(!v->ttmbf && ttmb < 8) ttmb = -1;
+ first_block = 0;
+ if((i<4) || !(s->flags & CODEC_FLAG_GRAY))
+ s->dsp.add_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize);
+ }
+ }
+ }
+ else //Skipped
+ {
+ s->mb_intra = 0;
+ for(i = 0; i < 6; i++) {
+ v->mb_type[0][s->block_index[i]] = 0;
+ s->dc_val[0][s->block_index[i]] = 0;
+ }
+ s->current_picture.mb_type[mb_pos] = MB_TYPE_SKIP;
+ s->current_picture.qscale_table[mb_pos] = 0;
+ vc1_pred_mv(s, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type[0]);
+ vc1_mc_1mv(v, 0);
+ return 0;
+ }
+ } //1MV mode
+ else //4MV mode
+ {
+ if (!skipped /* unskipped MB */)
+ {
+ int intra_count = 0, coded_inter = 0;
+ int is_intra[6], is_coded[6];
+ /* Get CBPCY */
+ cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
+ for (i=0; i<6; i++)
+ {
+ val = ((cbp >> (5 - i)) & 1);
+ s->dc_val[0][s->block_index[i]] = 0;
+ s->mb_intra = 0;
+ if(i < 4) {
+ dmv_x = dmv_y = 0;
+ s->mb_intra = 0;
+ mb_has_coeffs = 0;
+ if(val) {
+ GET_MVDATA(dmv_x, dmv_y);
+ }
+ vc1_pred_mv(s, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0]);
+ if(!s->mb_intra) vc1_mc_4mv_luma(v, i);
+ intra_count += s->mb_intra;
+ is_intra[i] = s->mb_intra;
+ is_coded[i] = mb_has_coeffs;
+ }
+ if(i&4){
+ is_intra[i] = (intra_count >= 3);
+ is_coded[i] = val;
+ }
+ if(i == 4) vc1_mc_4mv_chroma(v);
+ v->mb_type[0][s->block_index[i]] = is_intra[i];
+ if(!coded_inter) coded_inter = !is_intra[i] & is_coded[i];
+ }
+ // if there are no coded blocks then don't do anything more
+ if(!intra_count && !coded_inter) return 0;
+ dst_idx = 0;
+ GET_MQUANT();
+ s->current_picture.qscale_table[mb_pos] = mquant;
+ /* test if block is intra and has pred */
+ {
+ int intrapred = 0;
+ for(i=0; i<6; i++)
+ if(is_intra[i]) {
+ if(((!s->first_slice_line || (i==2 || i==3)) && v->mb_type[0][s->block_index[i] - s->block_wrap[i]])
+ || ((s->mb_x || (i==1 || i==3)) && v->mb_type[0][s->block_index[i] - 1])) {
+ intrapred = 1;
+ break;
+ }
+ }
+ if(intrapred)s->ac_pred = get_bits(gb, 1);
+ else s->ac_pred = 0;
+ }
+ if (!v->ttmbf && coded_inter)
+ ttmb = get_vlc2(gb, vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
+ for (i=0; i<6; i++)
+ {
+ dst_idx += i >> 2;
+ off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
+ s->mb_intra = is_intra[i];
+ if (is_intra[i]) {
+ /* check if prediction blocks A and C are available */
+ v->a_avail = v->c_avail = 0;
+ if(i == 2 || i == 3 || !s->first_slice_line)
+ v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
+ if(i == 1 || i == 3 || s->mb_x)
+ v->c_avail = v->mb_type[0][s->block_index[i] - 1];
+
+ vc1_decode_intra_block(v, s->block[i], i, is_coded[i], mquant, (i&4)?v->codingset2:v->codingset);
+ if((i>3) && (s->flags & CODEC_FLAG_GRAY)) continue;
+ s->dsp.vc1_inv_trans_8x8(s->block[i]);
+ if(v->rangeredfrm) for(j = 0; j < 64; j++) s->block[i][j] <<= 1;
+ for(j = 0; j < 64; j++) s->block[i][j] += 128;
+ if(!v->res_fasttx && v->res_x8) for(j = 0; j < 64; j++) s->block[i][j] += 16;
+ s->dsp.put_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize);
+ if(v->pq >= 9 && v->overlap) {
+ if(v->c_avail)
+ s->dsp.vc1_h_overlap(s->dest[dst_idx] + off, s->linesize >> ((i & 4) >> 2));
+ if(v->a_avail)
+ s->dsp.vc1_v_overlap(s->dest[dst_idx] + off, s->linesize >> ((i & 4) >> 2));
+ }
+ } else if(is_coded[i]) {
+ status = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block);
+ if(!v->ttmbf && ttmb < 8) ttmb = -1;
+ first_block = 0;
+ if((i<4) || !(s->flags & CODEC_FLAG_GRAY))
+ s->dsp.add_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize);
+ }
+ }
+ return status;
+ }
+ else //Skipped MB
+ {
+ s->mb_intra = 0;
+ s->current_picture.qscale_table[mb_pos] = 0;
+ for (i=0; i<6; i++) {
+ v->mb_type[0][s->block_index[i]] = 0;
+ s->dc_val[0][s->block_index[i]] = 0;
+ }
+ for (i=0; i<4; i++)
+ {
+ vc1_pred_mv(s, i, 0, 0, 0, v->range_x, v->range_y, v->mb_type[0]);
+ vc1_mc_4mv_luma(v, i);
+ }
+ vc1_mc_4mv_chroma(v);
+ s->current_picture.qscale_table[mb_pos] = 0;
+ return 0;
+ }
+ }
+
+ /* Should never happen */
+ return -1;
+}
+
+/** Decode one B-frame MB (in Main profile)
+ */
+static void vc1_decode_b_mb(VC1Context *v)
+{
+ MpegEncContext *s = &v->s;
+ GetBitContext *gb = &s->gb;
+ int i, j;
+ int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
+ int cbp = 0; /* cbp decoding stuff */
+ int mqdiff, mquant; /* MB quantization */
+ int ttmb = v->ttfrm; /* MB Transform type */
+
+ static const int size_table[6] = { 0, 2, 3, 4, 5, 8 },
+ offset_table[6] = { 0, 1, 3, 7, 15, 31 };
+ int mb_has_coeffs = 0; /* last_flag */
+ int index, index1; /* LUT indices */
+ int val, sign; /* temp values */
+ int first_block = 1;
+ int dst_idx, off;
+ int skipped, direct;
+ int dmv_x[2], dmv_y[2];
+ int bmvtype = BMV_TYPE_BACKWARD;
+
+ mquant = v->pq; /* Loosy initialization */
+ s->mb_intra = 0;
+
+ if (v->dmb_is_raw)
+ direct = get_bits1(gb);
+ else
+ direct = v->direct_mb_plane[mb_pos];
+ if (v->skip_is_raw)
+ skipped = get_bits1(gb);
+ else
+ skipped = v->s.mbskip_table[mb_pos];
+
+ s->dsp.clear_blocks(s->block[0]);
+ dmv_x[0] = dmv_x[1] = dmv_y[0] = dmv_y[1] = 0;
+ for(i = 0; i < 6; i++) {
+ v->mb_type[0][s->block_index[i]] = 0;
+ s->dc_val[0][s->block_index[i]] = 0;
+ }
+ s->current_picture.qscale_table[mb_pos] = 0;
+
+ if (!direct) {
+ if (!skipped) {
+ GET_MVDATA(dmv_x[0], dmv_y[0]);
+ dmv_x[1] = dmv_x[0];
+ dmv_y[1] = dmv_y[0];
+ }
+ if(skipped || !s->mb_intra) {
+ bmvtype = decode012(gb);
+ switch(bmvtype) {
+ case 0:
+ bmvtype = (v->bfraction >= (B_FRACTION_DEN/2)) ? BMV_TYPE_BACKWARD : BMV_TYPE_FORWARD;
+ break;
+ case 1:
+ bmvtype = (v->bfraction >= (B_FRACTION_DEN/2)) ? BMV_TYPE_FORWARD : BMV_TYPE_BACKWARD;
+ break;
+ case 2:
+ bmvtype = BMV_TYPE_INTERPOLATED;
+ dmv_x[0] = dmv_y[0] = 0;
+ }
+ }
+ }
+ for(i = 0; i < 6; i++)
+ v->mb_type[0][s->block_index[i]] = s->mb_intra;
+
+ if (skipped) {
+ if(direct) bmvtype = BMV_TYPE_INTERPOLATED;
+ vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
+ vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
+ return;
+ }
+ if (direct) {
+ cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
+ GET_MQUANT();
+ s->mb_intra = 0;
+ mb_has_coeffs = 0;
+ s->current_picture.qscale_table[mb_pos] = mquant;
+ if(!v->ttmbf)
+ ttmb = get_vlc2(gb, vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
+ dmv_x[0] = dmv_y[0] = dmv_x[1] = dmv_y[1] = 0;
+ vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
+ vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
+ } else {
+ if(!mb_has_coeffs && !s->mb_intra) {
+ /* no coded blocks - effectively skipped */
+ vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
+ vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
+ return;
+ }
+ if(s->mb_intra && !mb_has_coeffs) {
+ GET_MQUANT();
+ s->current_picture.qscale_table[mb_pos] = mquant;
+ s->ac_pred = get_bits1(gb);
+ cbp = 0;
+ vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
+ } else {
+ if(bmvtype == BMV_TYPE_INTERPOLATED) {
+ GET_MVDATA(dmv_x[0], dmv_y[0]);
+ if(!mb_has_coeffs) {
+ /* interpolated skipped block */
+ vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
+ vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
+ return;
+ }
+ }
+ vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
+ if(!s->mb_intra) {
+ vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
+ }
+ if(s->mb_intra)
+ s->ac_pred = get_bits1(gb);
+ cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
+ GET_MQUANT();
+ s->current_picture.qscale_table[mb_pos] = mquant;
+ if(!v->ttmbf && !s->mb_intra && mb_has_coeffs)
+ ttmb = get_vlc2(gb, vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
+ }
+ }
+ dst_idx = 0;
+ for (i=0; i<6; i++)
+ {
+ s->dc_val[0][s->block_index[i]] = 0;
+ dst_idx += i >> 2;
+ val = ((cbp >> (5 - i)) & 1);
+ off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
+ v->mb_type[0][s->block_index[i]] = s->mb_intra;
+ if(s->mb_intra) {
+ /* check if prediction blocks A and C are available */
+ v->a_avail = v->c_avail = 0;
+ if(i == 2 || i == 3 || !s->first_slice_line)
+ v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
+ if(i == 1 || i == 3 || s->mb_x)
+ v->c_avail = v->mb_type[0][s->block_index[i] - 1];
+
+ vc1_decode_intra_block(v, s->block[i], i, val, mquant, (i&4)?v->codingset2:v->codingset);
+ if((i>3) && (s->flags & CODEC_FLAG_GRAY)) continue;
+ s->dsp.vc1_inv_trans_8x8(s->block[i]);
+ if(v->rangeredfrm) for(j = 0; j < 64; j++) s->block[i][j] <<= 1;
+ for(j = 0; j < 64; j++) s->block[i][j] += 128;
+ s->dsp.put_pixels_clamped(s->block[i], s->dest[dst_idx] + off, s->linesize >> ((i & 4) >> 2));
+ } else if(val) {
+ vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block);
+ if(!v->ttmbf && ttmb < 8) ttmb = -1;
+ first_block = 0;
+ if((i<4) || !(s->flags & CODEC_FLAG_GRAY))
+ s->dsp.add_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize);
+ }
+ }
+}
+
+/** Decode blocks of I-frame
+ */
+static void vc1_decode_i_blocks(VC1Context *v)
+{
+ int k, j;
+ MpegEncContext *s = &v->s;
+ int cbp, val;
+ uint8_t *coded_val;
+ int mb_pos;
+
+ /* select codingmode used for VLC tables selection */
+ switch(v->y_ac_table_index){
+ case 0:
+ v->codingset = (v->pqindex <= 8) ? CS_HIGH_RATE_INTRA : CS_LOW_MOT_INTRA;
+ break;
+ case 1:
+ v->codingset = CS_HIGH_MOT_INTRA;
+ break;
+ case 2:
+ v->codingset = CS_MID_RATE_INTRA;
+ break;
+ }
+
+ switch(v->c_ac_table_index){
+ case 0:
+ v->codingset2 = (v->pqindex <= 8) ? CS_HIGH_RATE_INTER : CS_LOW_MOT_INTER;
+ break;
+ case 1:
+ v->codingset2 = CS_HIGH_MOT_INTER;
+ break;
+ case 2:
+ v->codingset2 = CS_MID_RATE_INTER;
+ break;
+ }
+
+ /* Set DC scale - y and c use the same */
+ s->y_dc_scale = s->y_dc_scale_table[v->pq];
+ s->c_dc_scale = s->c_dc_scale_table[v->pq];
+
+ //do frame decode
+ s->mb_x = s->mb_y = 0;
+ s->mb_intra = 1;
+ s->first_slice_line = 1;
+ ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END));
+ for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
+ for(s->mb_x = 0; s->mb_x < s->mb_width; s->mb_x++) {
+ ff_init_block_index(s);
+ ff_update_block_index(s);
+ s->dsp.clear_blocks(s->block[0]);
+ mb_pos = s->mb_x + s->mb_y * s->mb_width;
+ s->current_picture.mb_type[mb_pos] = MB_TYPE_INTRA;
+ s->current_picture.qscale_table[mb_pos] = v->pq;
+ s->current_picture.motion_val[1][s->block_index[0]][0] = 0;
+ s->current_picture.motion_val[1][s->block_index[0]][1] = 0;
+
+ // do actual MB decoding and displaying
+ cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2);
+ v->s.ac_pred = get_bits(&v->s.gb, 1);
+
+ for(k = 0; k < 6; k++) {
+ val = ((cbp >> (5 - k)) & 1);
+
+ if (k < 4) {
+ int pred = vc1_coded_block_pred(&v->s, k, &coded_val);
+ val = val ^ pred;
+ *coded_val = val;
+ }
+ cbp |= val << (5 - k);
+
+ vc1_decode_i_block(v, s->block[k], k, val, (k<4)? v->codingset : v->codingset2);
+
+ s->dsp.vc1_inv_trans_8x8(s->block[k]);
+ if(!v->res_fasttx && !v->res_x8) for(j = 0; j < 64; j++) s->block[k][j] -= 16;
+ if(v->pq >= 9 && v->overlap) {
+ for(j = 0; j < 64; j++) s->block[k][j] += 128;
+ }
+ }
+
+ vc1_put_block(v, s->block);
+ if(v->pq >= 9 && v->overlap) {
+ if(s->mb_x) {
+ s->dsp.vc1_h_overlap(s->dest[0], s->linesize);
+ s->dsp.vc1_h_overlap(s->dest[0] + 8 * s->linesize, s->linesize);
+ if(!(s->flags & CODEC_FLAG_GRAY)) {
+ s->dsp.vc1_h_overlap(s->dest[1], s->uvlinesize);
+ s->dsp.vc1_h_overlap(s->dest[2], s->uvlinesize);
+ }
+ }
+ s->dsp.vc1_h_overlap(s->dest[0] + 8, s->linesize);
+ s->dsp.vc1_h_overlap(s->dest[0] + 8 * s->linesize + 8, s->linesize);
+ if(!s->first_slice_line) {
+ s->dsp.vc1_v_overlap(s->dest[0], s->linesize);
+ s->dsp.vc1_v_overlap(s->dest[0] + 8, s->linesize);
+ if(!(s->flags & CODEC_FLAG_GRAY)) {
+ s->dsp.vc1_v_overlap(s->dest[1], s->uvlinesize);
+ s->dsp.vc1_v_overlap(s->dest[2], s->uvlinesize);
+ }
+ }
+ s->dsp.vc1_v_overlap(s->dest[0] + 8 * s->linesize, s->linesize);
+ s->dsp.vc1_v_overlap(s->dest[0] + 8 * s->linesize + 8, s->linesize);
+ }
+
+ if(get_bits_count(&s->gb) > v->bits) {
+ av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n", get_bits_count(&s->gb), v->bits);
+ return;
+ }
+ }
+ ff_draw_horiz_band(s, s->mb_y * 16, 16);
+ s->first_slice_line = 0;
+ }
+}
+
+/** Decode blocks of I-frame for advanced profile
+ */
+static void vc1_decode_i_blocks_adv(VC1Context *v)
+{
+ int k, j;
+ MpegEncContext *s = &v->s;
+ int cbp, val;
+ uint8_t *coded_val;
+ int mb_pos;
+ int mquant = v->pq;
+ int mqdiff;
+ int overlap;
+ GetBitContext *gb = &s->gb;
+
+ /* select codingmode used for VLC tables selection */
+ switch(v->y_ac_table_index){
+ case 0:
+ v->codingset = (v->pqindex <= 8) ? CS_HIGH_RATE_INTRA : CS_LOW_MOT_INTRA;
+ break;
+ case 1:
+ v->codingset = CS_HIGH_MOT_INTRA;
+ break;
+ case 2:
+ v->codingset = CS_MID_RATE_INTRA;
+ break;
+ }
+
+ switch(v->c_ac_table_index){
+ case 0:
+ v->codingset2 = (v->pqindex <= 8) ? CS_HIGH_RATE_INTER : CS_LOW_MOT_INTER;
+ break;
+ case 1:
+ v->codingset2 = CS_HIGH_MOT_INTER;
+ break;
+ case 2:
+ v->codingset2 = CS_MID_RATE_INTER;
+ break;
+ }
+
+ //do frame decode
+ s->mb_x = s->mb_y = 0;
+ s->mb_intra = 1;
+ s->first_slice_line = 1;
+ ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END));
+ for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
+ for(s->mb_x = 0; s->mb_x < s->mb_width; s->mb_x++) {
+ ff_init_block_index(s);
+ ff_update_block_index(s);
+ s->dsp.clear_blocks(s->block[0]);
+ mb_pos = s->mb_x + s->mb_y * s->mb_stride;
+ s->current_picture.mb_type[mb_pos] = MB_TYPE_INTRA;
+ s->current_picture.motion_val[1][s->block_index[0]][0] = 0;
+ s->current_picture.motion_val[1][s->block_index[0]][1] = 0;
+
+ // do actual MB decoding and displaying
+ cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2);
+ if(v->acpred_is_raw)
+ v->s.ac_pred = get_bits(&v->s.gb, 1);
+ else
+ v->s.ac_pred = v->acpred_plane[mb_pos];
+
+ if(v->condover == CONDOVER_SELECT) {
+ if(v->overflg_is_raw)
+ overlap = get_bits(&v->s.gb, 1);
+ else
+ overlap = v->over_flags_plane[mb_pos];
+ } else
+ overlap = (v->condover == CONDOVER_ALL);
+
+ GET_MQUANT();
+
+ s->current_picture.qscale_table[mb_pos] = mquant;
+ /* Set DC scale - y and c use the same */
+ s->y_dc_scale = s->y_dc_scale_table[mquant];
+ s->c_dc_scale = s->c_dc_scale_table[mquant];
+
+ for(k = 0; k < 6; k++) {
+ val = ((cbp >> (5 - k)) & 1);
+
+ if (k < 4) {
+ int pred = vc1_coded_block_pred(&v->s, k, &coded_val);
+ val = val ^ pred;
+ *coded_val = val;
+ }
+ cbp |= val << (5 - k);
+
+ v->a_avail = !s->first_slice_line || (k==2 || k==3);
+ v->c_avail = !!s->mb_x || (k==1 || k==3);
+
+ vc1_decode_i_block_adv(v, s->block[k], k, val, (k<4)? v->codingset : v->codingset2, mquant);
+
+ s->dsp.vc1_inv_trans_8x8(s->block[k]);
+ for(j = 0; j < 64; j++) s->block[k][j] += 128;
+ }
+
+ vc1_put_block(v, s->block);
+ if(overlap) {
+ if(s->mb_x) {
+ s->dsp.vc1_h_overlap(s->dest[0], s->linesize);
+ s->dsp.vc1_h_overlap(s->dest[0] + 8 * s->linesize, s->linesize);
+ if(!(s->flags & CODEC_FLAG_GRAY)) {
+ s->dsp.vc1_h_overlap(s->dest[1], s->uvlinesize);
+ s->dsp.vc1_h_overlap(s->dest[2], s->uvlinesize);
+ }
+ }
+ s->dsp.vc1_h_overlap(s->dest[0] + 8, s->linesize);
+ s->dsp.vc1_h_overlap(s->dest[0] + 8 * s->linesize + 8, s->linesize);
+ if(!s->first_slice_line) {
+ s->dsp.vc1_v_overlap(s->dest[0], s->linesize);
+ s->dsp.vc1_v_overlap(s->dest[0] + 8, s->linesize);
+ if(!(s->flags & CODEC_FLAG_GRAY)) {
+ s->dsp.vc1_v_overlap(s->dest[1], s->uvlinesize);
+ s->dsp.vc1_v_overlap(s->dest[2], s->uvlinesize);
+ }
+ }
+ s->dsp.vc1_v_overlap(s->dest[0] + 8 * s->linesize, s->linesize);
+ s->dsp.vc1_v_overlap(s->dest[0] + 8 * s->linesize + 8, s->linesize);
+ }
+
+ if(get_bits_count(&s->gb) > v->bits) {
+ av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n", get_bits_count(&s->gb), v->bits);
+ return;
+ }
+ }
+ ff_draw_horiz_band(s, s->mb_y * 16, 16);
+ s->first_slice_line = 0;
+ }
+}
+
+static void vc1_decode_p_blocks(VC1Context *v)
+{
+ MpegEncContext *s = &v->s;
+
+ /* select codingmode used for VLC tables selection */
+ switch(v->c_ac_table_index){
+ case 0:
+ v->codingset = (v->pqindex <= 8) ? CS_HIGH_RATE_INTRA : CS_LOW_MOT_INTRA;
+ break;
+ case 1:
+ v->codingset = CS_HIGH_MOT_INTRA;
+ break;
+ case 2:
+ v->codingset = CS_MID_RATE_INTRA;
+ break;
+ }
+
+ switch(v->c_ac_table_index){
+ case 0:
+ v->codingset2 = (v->pqindex <= 8) ? CS_HIGH_RATE_INTER : CS_LOW_MOT_INTER;
+ break;
+ case 1:
+ v->codingset2 = CS_HIGH_MOT_INTER;
+ break;
+ case 2:
+ v->codingset2 = CS_MID_RATE_INTER;
+ break;
+ }
+
+ ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END));
+ s->first_slice_line = 1;
+ for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
+ for(s->mb_x = 0; s->mb_x < s->mb_width; s->mb_x++) {
+ ff_init_block_index(s);
+ ff_update_block_index(s);
+ s->dsp.clear_blocks(s->block[0]);
+
+ vc1_decode_p_mb(v);
+ if(get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) {
+ av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i at %ix%i\n", get_bits_count(&s->gb), v->bits,s->mb_x,s->mb_y);
+ return;
+ }
+ }
+ ff_draw_horiz_band(s, s->mb_y * 16, 16);
+ s->first_slice_line = 0;
+ }
+}
+
+static void vc1_decode_b_blocks(VC1Context *v)
+{
+ MpegEncContext *s = &v->s;
+
+ /* select codingmode used for VLC tables selection */
+ switch(v->c_ac_table_index){
+ case 0:
+ v->codingset = (v->pqindex <= 8) ? CS_HIGH_RATE_INTRA : CS_LOW_MOT_INTRA;
+ break;
+ case 1:
+ v->codingset = CS_HIGH_MOT_INTRA;
+ break;
+ case 2:
+ v->codingset = CS_MID_RATE_INTRA;
+ break;
+ }
+
+ switch(v->c_ac_table_index){
+ case 0:
+ v->codingset2 = (v->pqindex <= 8) ? CS_HIGH_RATE_INTER : CS_LOW_MOT_INTER;
+ break;
+ case 1:
+ v->codingset2 = CS_HIGH_MOT_INTER;
+ break;
+ case 2:
+ v->codingset2 = CS_MID_RATE_INTER;
+ break;
+ }
+
+ ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END));
+ s->first_slice_line = 1;
+ for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
+ for(s->mb_x = 0; s->mb_x < s->mb_width; s->mb_x++) {
+ ff_init_block_index(s);
+ ff_update_block_index(s);
+ s->dsp.clear_blocks(s->block[0]);
+
+ vc1_decode_b_mb(v);
+ if(get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) {
+ av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i at %ix%i\n", get_bits_count(&s->gb), v->bits,s->mb_x,s->mb_y);
+ return;
+ }
+ }
+ ff_draw_horiz_band(s, s->mb_y * 16, 16);
+ s->first_slice_line = 0;
+ }
+}
+
+static void vc1_decode_skip_blocks(VC1Context *v)
+{
+ MpegEncContext *s = &v->s;
+
+ ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END));
+ s->first_slice_line = 1;
+ for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
+ s->mb_x = 0;
+ ff_init_block_index(s);
+ ff_update_block_index(s);
+ memcpy(s->dest[0], s->last_picture.data[0] + s->mb_y * 16 * s->linesize, s->linesize * 16);
+ memcpy(s->dest[1], s->last_picture.data[1] + s->mb_y * 8 * s->uvlinesize, s->uvlinesize * 8);
+ memcpy(s->dest[2], s->last_picture.data[2] + s->mb_y * 8 * s->uvlinesize, s->uvlinesize * 8);
+ ff_draw_horiz_band(s, s->mb_y * 16, 16);
+ s->first_slice_line = 0;
+ }
+ s->pict_type = P_TYPE;
+}
+
+static void vc1_decode_blocks(VC1Context *v)
+{
+
+ v->s.esc3_level_length = 0;
+
+ switch(v->s.pict_type) {
+ case I_TYPE:
+ if(v->profile == PROFILE_ADVANCED)
+ vc1_decode_i_blocks_adv(v);
+ else
+ vc1_decode_i_blocks(v);
+ break;
+ case P_TYPE:
+ if(v->p_frame_skipped)
+ vc1_decode_skip_blocks(v);
+ else
+ vc1_decode_p_blocks(v);
+ break;
+ case B_TYPE:
+ if(v->bi_type){
+ if(v->profile == PROFILE_ADVANCED)
+ vc1_decode_i_blocks_adv(v);
+ else
+ vc1_decode_i_blocks(v);
+ }else
+ vc1_decode_b_blocks(v);
+ break;
+ }
+}
+
+#define IS_MARKER(x) (((x) & ~0xFF) == VC1_CODE_RES0)
+
+/** Find VC-1 marker in buffer
+ * @return position where next marker starts or end of buffer if no marker found
+ */
+static av_always_inline uint8_t* find_next_marker(uint8_t *src, uint8_t *end)
+{
+ uint32_t mrk = 0xFFFFFFFF;
+
+ if(end-src < 4) return end;
+ while(src < end){
+ mrk = (mrk << 8) | *src++;
+ if(IS_MARKER(mrk))
+ return src-4;
+ }
+ return end;
+}
+
+static av_always_inline int vc1_unescape_buffer(uint8_t *src, int size, uint8_t *dst)
+{
+ int dsize = 0, i;
+
+ if(size < 4){
+ for(dsize = 0; dsize < size; dsize++) *dst++ = *src++;
+ return size;
+ }
+ for(i = 0; i < size; i++, src++) {
+ if(src[0] == 3 && i >= 2 && !src[-1] && !src[-2] && i < size-1 && src[1] < 4) {
+ dst[dsize++] = src[1];
+ src++;
+ i++;
+ } else
+ dst[dsize++] = *src;
+ }
+ return dsize;
+}
+
+/** Initialize a VC1/WMV3 decoder
+ * @todo TODO: Handle VC-1 IDUs (Transport level?)
+ * @todo TODO: Decypher remaining bits in extra_data
+ */
+static int vc1_decode_init(AVCodecContext *avctx)
+{
+ VC1Context *v = avctx->priv_data;
+ MpegEncContext *s = &v->s;
+ GetBitContext gb;
+
+ if (!avctx->extradata_size || !avctx->extradata) return -1;
+ if (!(avctx->flags & CODEC_FLAG_GRAY))
+ avctx->pix_fmt = PIX_FMT_YUV420P;
+ else
+ avctx->pix_fmt = PIX_FMT_GRAY8;
+ v->s.avctx = avctx;
+ avctx->flags |= CODEC_FLAG_EMU_EDGE;
+ v->s.flags |= CODEC_FLAG_EMU_EDGE;
+
+ if(ff_h263_decode_init(avctx) < 0)
+ return -1;
+ if (vc1_init_common(v) < 0) return -1;
+
+ avctx->coded_width = avctx->width;
+ avctx->coded_height = avctx->height;
+ if (avctx->codec_id == CODEC_ID_WMV3)
+ {
+ int count = 0;
+
+ // looks like WMV3 has a sequence header stored in the extradata
+ // advanced sequence header may be before the first frame
+ // the last byte of the extradata is a version number, 1 for the
+ // samples we can decode
+
+ init_get_bits(&gb, avctx->extradata, avctx->extradata_size*8);
+
+ if (decode_sequence_header(avctx, &gb) < 0)
+ return -1;
+
+ count = avctx->extradata_size*8 - get_bits_count(&gb);
+ if (count>0)
+ {
+ av_log(avctx, AV_LOG_INFO, "Extra data: %i bits left, value: %X\n",
+ count, get_bits(&gb, count));
+ }
+ else if (count < 0)
+ {
+ av_log(avctx, AV_LOG_INFO, "Read %i bits in overflow\n", -count);
+ }
+ } else { // VC1/WVC1
+ uint8_t *start = avctx->extradata, *end = avctx->extradata + avctx->extradata_size;
+ uint8_t *next; int size, buf2_size;
+ uint8_t *buf2 = NULL;
+ int seq_inited = 0, ep_inited = 0;
+
+ if(avctx->extradata_size < 16) {
+ av_log(avctx, AV_LOG_ERROR, "Extradata size too small: %i\n", avctx->extradata_size);
+ return -1;
+ }
+
+ buf2 = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ if(start[0]) start++; // in WVC1 extradata first byte is its size
+ next = start;
+ for(; next < end; start = next){
+ next = find_next_marker(start + 4, end);
+ size = next - start - 4;
+ if(size <= 0) continue;
+ buf2_size = vc1_unescape_buffer(start + 4, size, buf2);
+ init_get_bits(&gb, buf2, buf2_size * 8);
+ switch(AV_RB32(start)){
+ case VC1_CODE_SEQHDR:
+ if(decode_sequence_header(avctx, &gb) < 0){
+ av_free(buf2);
+ return -1;
+ }
+ seq_inited = 1;
+ break;
+ case VC1_CODE_ENTRYPOINT:
+ if(decode_entry_point(avctx, &gb) < 0){
+ av_free(buf2);
+ return -1;
+ }
+ ep_inited = 1;
+ break;
+ }
+ }
+ av_free(buf2);
+ if(!seq_inited || !ep_inited){
+ av_log(avctx, AV_LOG_ERROR, "Incomplete extradata\n");
+ return -1;
+ }
+ }
+ avctx->has_b_frames= !!(avctx->max_b_frames);
+ s->low_delay = !avctx->has_b_frames;
+
+ s->mb_width = (avctx->coded_width+15)>>4;
+ s->mb_height = (avctx->coded_height+15)>>4;
+
+ /* Allocate mb bitplanes */
+ v->mv_type_mb_plane = av_malloc(s->mb_stride * s->mb_height);
+ v->direct_mb_plane = av_malloc(s->mb_stride * s->mb_height);
+ v->acpred_plane = av_malloc(s->mb_stride * s->mb_height);
+ v->over_flags_plane = av_malloc(s->mb_stride * s->mb_height);
+
+ /* allocate block type info in that way so it could be used with s->block_index[] */
+ v->mb_type_base = av_malloc(s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2);
+ v->mb_type[0] = v->mb_type_base + s->b8_stride + 1;
+ v->mb_type[1] = v->mb_type_base + s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride + 1;
+ v->mb_type[2] = v->mb_type[1] + s->mb_stride * (s->mb_height + 1);
+
+ /* Init coded blocks info */
+ if (v->profile == PROFILE_ADVANCED)
+ {
+// if (alloc_bitplane(&v->over_flags_plane, s->mb_width, s->mb_height) < 0)
+// return -1;
+// if (alloc_bitplane(&v->ac_pred_plane, s->mb_width, s->mb_height) < 0)
+// return -1;
+ }
+
+ return 0;
+}
+
+
+/** Decode a VC1/WMV3 frame
+ * @todo TODO: Handle VC-1 IDUs (Transport level?)
+ */
+static int vc1_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ VC1Context *v = avctx->priv_data;
+ MpegEncContext *s = &v->s;
+ AVFrame *pict = data;
+ uint8_t *buf2 = NULL;
+
+ /* no supplementary picture */
+ if (buf_size == 0) {
+ /* special case for last picture */
+ if (s->low_delay==0 && s->next_picture_ptr) {
+ *pict= *(AVFrame*)s->next_picture_ptr;
+ s->next_picture_ptr= NULL;
+
+ *data_size = sizeof(AVFrame);
+ }
+
+ return 0;
+ }
+
+ //we need to set current_picture_ptr before reading the header, otherwise we cant store anyting im there
+ if(s->current_picture_ptr==NULL || s->current_picture_ptr->data[0]){
+ int i= ff_find_unused_picture(s, 0);
+ s->current_picture_ptr= &s->picture[i];
+ }
+
+ //for advanced profile we may need to parse and unescape data
+ if (avctx->codec_id == CODEC_ID_VC1) {
+ int buf_size2 = 0;
+ buf2 = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
+
+ if(IS_MARKER(AV_RB32(buf))){ /* frame starts with marker and needs to be parsed */
+ uint8_t *dst = buf2, *start, *end, *next;
+ int size;
+
+ next = buf;
+ for(start = buf, end = buf + buf_size; next < end; start = next){
+ next = find_next_marker(start + 4, end);
+ size = next - start - 4;
+ if(size <= 0) continue;
+ switch(AV_RB32(start)){
+ case VC1_CODE_FRAME:
+ buf_size2 = vc1_unescape_buffer(start + 4, size, buf2);
+ break;
+ case VC1_CODE_ENTRYPOINT: /* it should be before frame data */
+ buf_size2 = vc1_unescape_buffer(start + 4, size, buf2);
+ init_get_bits(&s->gb, buf2, buf_size2*8);
+ decode_entry_point(avctx, &s->gb);
+ break;
+ case VC1_CODE_SLICE:
+ av_log(avctx, AV_LOG_ERROR, "Sliced decoding is not implemented (yet)\n");
+ av_free(buf2);
+ return -1;
+ }
+ }
+ }else if(v->interlace && ((buf[0] & 0xC0) == 0xC0)){ /* WVC1 interlaced stores both fields divided by marker */
+ uint8_t *divider;
+
+ divider = find_next_marker(buf, buf + buf_size);
+ if((divider == (buf + buf_size)) || AV_RB32(divider) != VC1_CODE_FIELD){
+ av_log(avctx, AV_LOG_ERROR, "Error in WVC1 interlaced frame\n");
+ return -1;
+ }
+
+ buf_size2 = vc1_unescape_buffer(buf, divider - buf, buf2);
+ // TODO
+ av_free(buf2);return -1;
+ }else{
+ buf_size2 = vc1_unescape_buffer(buf, buf_size, buf2);
+ }
+ init_get_bits(&s->gb, buf2, buf_size2*8);
+ } else
+ init_get_bits(&s->gb, buf, buf_size*8);
+ // do parse frame header
+ if(v->profile < PROFILE_ADVANCED) {
+ if(vc1_parse_frame_header(v, &s->gb) == -1) {
+ av_free(buf2);
+ return -1;
+ }
+ } else {
+ if(vc1_parse_frame_header_adv(v, &s->gb) == -1) {
+ av_free(buf2);
+ return -1;
+ }
+ }
+
+ if(s->pict_type != I_TYPE && !v->res_rtm_flag){
+ av_free(buf2);
+ return -1;
+ }
+
+ // for hurry_up==5
+ s->current_picture.pict_type= s->pict_type;
+ s->current_picture.key_frame= s->pict_type == I_TYPE;
+
+ /* skip B-frames if we don't have reference frames */
+ if(s->last_picture_ptr==NULL && (s->pict_type==B_TYPE || s->dropable)){
+ av_free(buf2);
+ return -1;//buf_size;
+ }
+ /* skip b frames if we are in a hurry */
+ if(avctx->hurry_up && s->pict_type==B_TYPE) return -1;//buf_size;
+ if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==B_TYPE)
+ || (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=I_TYPE)
+ || avctx->skip_frame >= AVDISCARD_ALL) {
+ av_free(buf2);
+ return buf_size;
+ }
+ /* skip everything if we are in a hurry>=5 */
+ if(avctx->hurry_up>=5) {
+ av_free(buf2);
+ return -1;//buf_size;
+ }
+
+ if(s->next_p_frame_damaged){
+ if(s->pict_type==B_TYPE)
+ return buf_size;
+ else
+ s->next_p_frame_damaged=0;
+ }
+
+ if(MPV_frame_start(s, avctx) < 0) {
+ av_free(buf2);
+ return -1;
+ }
+
+ ff_er_frame_start(s);
+
+ v->bits = buf_size * 8;
+ vc1_decode_blocks(v);
+//av_log(s->avctx, AV_LOG_INFO, "Consumed %i/%i bits\n", get_bits_count(&s->gb), buf_size*8);
+// if(get_bits_count(&s->gb) > buf_size * 8)
+// return -1;
+ ff_er_frame_end(s);
+
+ MPV_frame_end(s);
+
+assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type);
+assert(s->current_picture.pict_type == s->pict_type);
+ if (s->pict_type == B_TYPE || s->low_delay) {
+ *pict= *(AVFrame*)s->current_picture_ptr;
+ } else if (s->last_picture_ptr != NULL) {
+ *pict= *(AVFrame*)s->last_picture_ptr;
+ }
+
+ if(s->last_picture_ptr || s->low_delay){
+ *data_size = sizeof(AVFrame);
+ ff_print_debug_info(s, pict);
+ }
+
+ /* Return the Picture timestamp as the frame number */
+ /* we substract 1 because it is added on utils.c */
+ avctx->frame_number = s->picture_number - 1;
+
+ av_free(buf2);
+ return buf_size;
+}
+
+
+/** Close a VC1/WMV3 decoder
+ * @warning Initial try at using MpegEncContext stuff
+ */
+static int vc1_decode_end(AVCodecContext *avctx)
+{
+ VC1Context *v = avctx->priv_data;
+
+ av_freep(&v->hrd_rate);
+ av_freep(&v->hrd_buffer);
+ MPV_common_end(&v->s);
+ av_freep(&v->mv_type_mb_plane);
+ av_freep(&v->direct_mb_plane);
+ av_freep(&v->acpred_plane);
+ av_freep(&v->over_flags_plane);
+ av_freep(&v->mb_type_base);
+ return 0;
+}
+
+
+AVCodec vc1_decoder = {
+ "vc1",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_VC1,
+ sizeof(VC1Context),
+ vc1_decode_init,
+ NULL,
+ vc1_decode_end,
+ vc1_decode_frame,
+ CODEC_CAP_DELAY,
+ NULL
+};
+
+AVCodec wmv3_decoder = {
+ "wmv3",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_WMV3,
+ sizeof(VC1Context),
+ vc1_decode_init,
+ NULL,
+ vc1_decode_end,
+ vc1_decode_frame,
+ CODEC_CAP_DELAY,
+ NULL
+};
+
+#ifdef CONFIG_VC1_PARSER
+/**
+ * finds the end of the current frame in the bitstream.
+ * @return the position of the first byte of the next frame, or -1
+ */
+static int vc1_find_frame_end(ParseContext *pc, const uint8_t *buf,
+ int buf_size) {
+ int pic_found, i;
+ uint32_t state;
+
+ pic_found= pc->frame_start_found;
+ state= pc->state;
+
+ i=0;
+ if(!pic_found){
+ for(i=0; i<buf_size; i++){
+ state= (state<<8) | buf[i];
+ if(state == VC1_CODE_FRAME || state == VC1_CODE_FIELD){
+ i++;
+ pic_found=1;
+ break;
+ }
+ }
+ }
+
+ if(pic_found){
+ /* EOF considered as end of frame */
+ if (buf_size == 0)
+ return 0;
+ for(; i<buf_size; i++){
+ state= (state<<8) | buf[i];
+ if(IS_MARKER(state) && state != VC1_CODE_FIELD && state != VC1_CODE_SLICE){
+ pc->frame_start_found=0;
+ pc->state=-1;
+ return i-3;
+ }
+ }
+ }
+ pc->frame_start_found= pic_found;
+ pc->state= state;
+ return END_NOT_FOUND;
+}
+
+static int vc1_parse(AVCodecParserContext *s,
+ AVCodecContext *avctx,
+ uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size)
+{
+ ParseContext *pc = s->priv_data;
+ int next;
+
+ if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){
+ next= buf_size;
+ }else{
+ next= vc1_find_frame_end(pc, buf, buf_size);
+
+ if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
+ *poutbuf = NULL;
+ *poutbuf_size = 0;
+ return buf_size;
+ }
+ }
+ *poutbuf = (uint8_t *)buf;
+ *poutbuf_size = buf_size;
+ return next;
+}
+
+int vc1_split(AVCodecContext *avctx,
+ const uint8_t *buf, int buf_size)
+{
+ int i;
+ uint32_t state= -1;
+
+ for(i=0; i<buf_size; i++){
+ state= (state<<8) | buf[i];
+ if(IS_MARKER(state) && state != VC1_CODE_SEQHDR && state != VC1_CODE_ENTRYPOINT)
+ return i-3;
+ }
+ return 0;
+}
+
+AVCodecParser vc1_parser = {
+ { CODEC_ID_VC1 },
+ sizeof(ParseContext1),
+ NULL,
+ vc1_parse,
+ ff_parse1_close,
+ vc1_split,
+};
+#endif /* CONFIG_VC1_PARSER */
diff --git a/src/libffmpeg/libavcodec/vc1acdata.h b/contrib/ffmpeg/libavcodec/vc1acdata.h
index a6acecd78..a6acecd78 100644
--- a/src/libffmpeg/libavcodec/vc1acdata.h
+++ b/contrib/ffmpeg/libavcodec/vc1acdata.h
diff --git a/contrib/ffmpeg/libavcodec/vc1data.h b/contrib/ffmpeg/libavcodec/vc1data.h
new file mode 100644
index 000000000..9b0a854bf
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/vc1data.h
@@ -0,0 +1,652 @@
+/*
+ * VC-1 and WMV3 decoder
+ * copyright (c) 2006 Konstantin Shishkov
+ * (c) 2005 anonymous, Alex Beregszaszi, 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 vc1data.h
+ * VC-1 tables.
+ */
+
+#ifndef VC1DATA_H
+#define VC1DATA_H
+
+#if 0 //original bfraction from vc9data.h, not conforming to standard
+/* Denominator used for vc1_bfraction_lut */
+#define B_FRACTION_DEN 840
+
+/* bfraction is fractional, we scale to the GCD 3*5*7*8 = 840 */
+const int16_t vc1_bfraction_lut[23] = {
+ 420 /*1/2*/, 280 /*1/3*/, 560 /*2/3*/, 210 /*1/4*/,
+ 630 /*3/4*/, 168 /*1/5*/, 336 /*2/5*/,
+ 504 /*3/5*/, 672 /*4/5*/, 140 /*1/6*/, 700 /*5/6*/,
+ 120 /*1/7*/, 240 /*2/7*/, 360 /*3/7*/, 480 /*4/7*/,
+ 600 /*5/7*/, 720 /*6/7*/, 105 /*1/8*/, 315 /*3/8*/,
+ 525 /*5/8*/, 735 /*7/8*/,
+ -1 /*inv.*/, 0 /*BI fm*/
+};
+#else
+/* Denominator used for vc1_bfraction_lut */
+#define B_FRACTION_DEN 256
+
+/* pre-computed scales for all bfractions and base=256 */
+static const int16_t vc1_bfraction_lut[23] = {
+ 128 /*1/2*/, 85 /*1/3*/, 170 /*2/3*/, 64 /*1/4*/,
+ 192 /*3/4*/, 51 /*1/5*/, 102 /*2/5*/,
+ 153 /*3/5*/, 204 /*4/5*/, 43 /*1/6*/, 215 /*5/6*/,
+ 37 /*1/7*/, 74 /*2/7*/, 111 /*3/7*/, 148 /*4/7*/,
+ 185 /*5/7*/, 222 /*6/7*/, 32 /*1/8*/, 96 /*3/8*/,
+ 160 /*5/8*/, 224 /*7/8*/,
+ -1 /*inv.*/, 0 /*BI fm*/
+};
+#endif
+
+static const uint8_t vc1_bfraction_bits[23] = {
+ 3, 3, 3, 3,
+ 3, 3, 3,
+ 7, 7, 7, 7,
+ 7, 7, 7, 7,
+ 7, 7, 7, 7,
+ 7, 7,
+ 7, 7
+};
+static const uint8_t vc1_bfraction_codes[23] = {
+ 0, 1, 2, 3,
+ 4, 5, 6,
+ 112, 113, 114, 115,
+ 116, 117, 118, 119,
+ 120, 121, 122, 123,
+ 124, 125,
+ 126, 127
+};
+
+//Same as H.264
+static const AVRational vc1_pixel_aspect[16]={
+ {0, 1},
+ {1, 1},
+ {12, 11},
+ {10, 11},
+ {16, 11},
+ {40, 33},
+ {24, 11},
+ {20, 11},
+ {32, 11},
+ {80, 33},
+ {18, 11},
+ {15, 11},
+ {64, 33},
+ {160, 99},
+ {0, 1},
+ {0, 1}
+};
+
+/* BitPlane IMODE - such a small table... */
+static const uint8_t vc1_imode_codes[7] = {
+ 0, 2, 1, 3, 1, 2, 3
+};
+static const uint8_t vc1_imode_bits[7] = {
+ 4, 2, 3, 2, 4, 3, 3
+};
+
+/* Normal-2 imode */
+static const uint8_t vc1_norm2_codes[4] = {
+ 0, 4, 5, 3
+};
+static const uint8_t vc1_norm2_bits[4] = {
+ 1, 3, 3, 2
+};
+
+static const uint16_t vc1_norm6_codes[64] = {
+0x001, 0x002, 0x003, 0x000, 0x004, 0x001, 0x002, 0x047, 0x005, 0x003, 0x004, 0x04B, 0x005, 0x04D, 0x04E, 0x30E,
+0x006, 0x006, 0x007, 0x053, 0x008, 0x055, 0x056, 0x30D, 0x009, 0x059, 0x05A, 0x30C, 0x05C, 0x30B, 0x30A, 0x037,
+0x007, 0x00A, 0x00B, 0x043, 0x00C, 0x045, 0x046, 0x309, 0x00D, 0x049, 0x04A, 0x308, 0x04C, 0x307, 0x306, 0x036,
+0x00E, 0x051, 0x052, 0x305, 0x054, 0x304, 0x303, 0x035, 0x058, 0x302, 0x301, 0x034, 0x300, 0x033, 0x032, 0x007,
+};
+
+static const uint8_t vc1_norm6_bits[64] = {
+ 1, 4, 4, 8, 4, 8, 8, 10, 4, 8, 8, 10, 8, 10, 10, 13,
+ 4, 8, 8, 10, 8, 10, 10, 13, 8, 10, 10, 13, 10, 13, 13, 9,
+ 4, 8, 8, 10, 8, 10, 10, 13, 8, 10, 10, 13, 10, 13, 13, 9,
+ 8, 10, 10, 13, 10, 13, 13, 9, 10, 13, 13, 9, 13, 9, 9, 6,
+};
+/* Normal-6 imode */
+static const uint8_t vc1_norm6_spec[64][5] = {
+{ 0, 1, 1 },
+{ 1, 2, 4 },
+{ 2, 3, 4 },
+{ 3, 0, 8 },
+{ 4, 4, 4 },
+{ 5, 1, 8 },
+{ 6, 2, 8 },
+{ 7, 2, 5, 7, 5 },
+{ 8, 5, 4 },
+{ 9, 3, 8 },
+{10, 4, 8 },
+{11, 2, 5, 11, 5 },
+{12, 5, 8 },
+{13, 2, 5, 13, 5 },
+{14, 2, 5, 14, 5 },
+{15, 3, 5, 14, 8 },
+{16, 6, 4 },
+{17, 6, 8 },
+{18, 7, 8 },
+{19, 2, 5, 19, 5 },
+{20, 8, 8 },
+{21, 2, 5, 21, 5 },
+{22, 2, 5, 22, 5 },
+{23, 3, 5, 13, 8 },
+{24, 9, 8 },
+{25, 2, 5, 25, 5 },
+{26, 2, 5, 26, 5 },
+{27, 3, 5, 12, 8 },
+{28, 2, 5, 28, 5 },
+{29, 3, 5, 11, 8 },
+{30, 3, 5, 10, 8 },
+{31, 3, 5, 7, 4 },
+{32, 7, 4 },
+{33, 10, 8 },
+{34, 11, 8 },
+{35, 2, 5, 3, 5 },
+{36, 12, 8 },
+{37, 2, 5, 5, 5 },
+{38, 2, 5, 6, 5 },
+{39, 3, 5, 9, 8 },
+{40, 13, 8 },
+{41, 2, 5, 9, 5 },
+{42, 2, 5, 10, 5 },
+{43, 3, 5, 8, 8 },
+{44, 2, 5, 12, 5 },
+{45, 3, 5, 7, 8 },
+{46, 3, 5, 6, 8 },
+{47, 3, 5, 6, 4 },
+{48, 14, 8 },
+{49, 2, 5, 17, 5 },
+{50, 2, 5, 18, 5 },
+{51, 3, 5, 5, 8 },
+{52, 2, 5, 20, 5 },
+{53, 3, 5, 4, 8 },
+{54, 3, 5, 3, 8 },
+{55, 3, 5, 5, 4 },
+{56, 2, 5, 24, 5 },
+{57, 3, 5, 2, 8 },
+{58, 3, 5, 1, 8 },
+{59, 3, 5, 4, 4 },
+{60, 3, 5, 0, 8 },
+{61, 3, 5, 3, 4 },
+{62, 3, 5, 2, 4 },
+{63, 3, 5, 1, 1 },
+};
+
+/* 4MV Block pattern VLC tables */
+static const uint8_t vc1_4mv_block_pattern_codes[4][16] = {
+ { 14, 58, 59, 25, 12, 26, 15, 15, 13, 24, 27, 0, 28, 1, 2, 2},
+ { 8, 18, 19, 4, 20, 5, 30, 11, 21, 31, 6, 12, 7, 13, 14, 0},
+ { 15, 6, 7, 2, 8, 3, 28, 9, 10, 29, 4, 11, 5, 12, 13, 0},
+ { 0, 11, 12, 4, 13, 5, 30, 16, 14, 31, 6, 17, 7, 18, 19, 10}
+};
+static const uint8_t vc1_4mv_block_pattern_bits[4][16] = {
+ { 5, 6, 6, 5, 5, 5, 5, 4, 5, 5, 5, 3, 5, 3, 3, 2},
+ { 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 4, 4, 4, 4, 4, 2},
+ { 4, 4, 4, 4, 4, 4, 5, 4, 4, 5, 4, 4, 4, 4, 4, 3},
+ { 2, 4, 4, 4, 4, 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 4}
+};
+
+const uint8_t wmv3_dc_scale_table[32]={
+ 0, 2, 4, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,21
+};
+
+/* P-Picture CBPCY VLC tables */
+#if 1 // Looks like original tables are not conforming to standard at all. Are they used for old WMV?
+static const uint16_t vc1_cbpcy_p_codes[4][64] = {
+ {
+ 0, 6, 15, 13, 13, 11, 3, 13, 5, 8, 49, 10, 12, 114, 102, 119,
+ 1, 54, 96, 8, 10, 111, 5, 15, 12, 10, 2, 12, 13, 115, 53, 63,
+ 1, 7, 1, 7, 14, 12, 4, 14, 1, 9, 97, 11, 7, 58, 52, 62,
+ 4, 103, 1, 9, 11, 56, 101, 118, 4, 110, 100, 30, 2, 5, 4, 3
+ },
+ {
+ 0, 9, 1, 18, 5, 14, 237, 26, 3, 121, 3, 22, 13, 16, 6, 30,
+ 2, 10, 1, 20, 12, 241, 5, 28, 16, 12, 3, 24, 28, 124, 239, 247,
+ 1, 240, 1, 19, 18, 15, 4, 27, 1, 122, 2, 23, 1, 17, 7, 31,
+ 1, 11, 2, 21, 19, 246, 238, 29, 17, 13, 236, 25, 58, 63, 8, 125
+ },
+ {
+ 0, 201, 25, 231, 5, 221, 1, 3, 2, 414, 2, 241, 16, 225, 195, 492,
+ 2, 412, 1, 240, 7, 224, 98, 245, 1, 220, 96, 5, 9, 230, 101, 247,
+ 1, 102, 1, 415, 24, 3, 2, 244, 3, 54, 3, 484, 17, 114, 200, 493,
+ 3, 413, 1, 4, 13, 113, 99, 485, 4, 111, 194, 243, 5, 29, 26, 31
+ },
+ {
+ 0, 28, 12, 44, 3, 36, 20, 52, 2, 32, 16, 48, 8, 40, 24, 28,
+ 1, 30, 14, 46, 6, 38, 22, 54, 3, 34, 18, 50, 10, 42, 26, 30,
+ 1, 29, 13, 45, 5, 37, 21, 53, 2, 33, 17, 49, 9, 41, 25, 29,
+ 1, 31, 15, 47, 7, 39, 23, 55, 4, 35, 19, 51, 11, 43, 27, 31
+ }
+};
+
+static const uint8_t vc1_cbpcy_p_bits[4][64] = {
+ {
+ 13, 13, 7, 13, 7, 13, 13, 12, 6, 13, 7, 12, 6, 8, 8, 8,
+ 5, 7, 8, 12, 6, 8, 13, 12, 7, 13, 13, 12, 6, 8, 7, 7,
+ 6, 13, 8, 12, 7, 13, 13, 12, 7, 13, 8, 12, 5, 7, 7, 7,
+ 6, 8, 13, 12, 6, 7, 8, 8, 5, 8, 8, 6, 3, 3, 3, 2
+ },
+ {
+ 14, 13, 8, 13, 3, 13, 8, 13, 3, 7, 8, 13, 4, 13, 13, 13,
+ 3, 13, 13, 13, 4, 8, 13, 13, 5, 13, 13, 13, 5, 7, 8, 8,
+ 3, 8, 14, 13, 5, 13, 13, 13, 4, 7, 13, 13, 6, 13, 13, 13,
+ 5, 13, 8, 13, 5, 8, 8, 13, 5, 13, 8, 13, 6, 6, 13, 7
+ },
+ {
+ 13, 8, 6, 8, 4, 8, 13, 12, 4, 9, 8, 8, 5, 8, 8, 9,
+ 5, 9, 10, 8, 4, 8, 7, 8, 6, 8, 7, 13, 4, 8, 7, 8,
+ 5, 7, 8, 9, 6, 13, 13, 8, 4, 6, 8, 9, 5, 7, 8, 9,
+ 5, 9, 9, 13, 5, 7, 7, 9, 4, 7, 8, 8, 3, 5, 5, 5
+ },
+ {
+ 9, 9, 9, 9, 2, 9, 9, 9, 2, 9, 9, 9, 9, 9, 9, 8,
+ 3, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8,
+ 2, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8
+ }
+};
+#else
+static const uint16_t vc1_cbpcy_p_codes[4][64] = {
+ {
+ 0, 1, 1, 4, 5, 1, 12, 4, 13, 14, 10, 11, 12, 7, 13, 2,
+ 15, 1, 96, 1, 49, 97, 2, 100, 3, 4, 5, 101, 102, 52, 53, 4,
+ 6, 7, 54, 103, 8, 9, 10, 110, 11, 12, 111, 56, 114, 58, 115, 5,
+ 13, 7, 8, 9, 10, 11, 12, 30, 13, 14, 15, 118, 119, 62, 63, 3
+ },
+ {
+ 0, 1, 2, 1, 3, 1, 16, 17, 5, 18, 12, 19, 13, 1, 28, 58,
+ 1, 1, 1, 2, 3, 2, 3, 236, 237, 4, 5, 238, 6, 7, 239, 8,
+ 9, 240, 10, 11, 121, 122, 12, 13, 14, 15, 241, 246, 16, 17, 124, 63,
+ 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 247, 125
+ },
+ {
+ 0, 1, 2, 3, 2, 3, 1, 4, 5, 24, 7, 13, 16, 17, 9, 5,
+ 25, 1, 1, 1, 2, 3, 96, 194, 1, 2, 98, 99, 195, 200, 101, 26,
+ 201, 102, 412, 413, 414, 54, 220, 111, 221, 3, 224, 113, 225, 114, 230, 29,
+ 231, 415, 240, 4, 241, 484, 5, 243, 3, 244, 245, 485, 492, 493, 247, 31
+ },
+ {
+ 0, 1, 1, 1, 2, 2, 3, 4, 3, 5, 6, 7, 8, 9, 10, 11,
+ 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
+ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
+ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 28, 29, 30, 31
+ }
+};
+static const uint8_t vc1_cbpcy_p_bits[4][64] = {
+ {
+ 13, 6, 5, 6, 6, 7, 7, 5, 7, 7, 6, 6, 6, 5, 6, 3,
+ 7, 8, 8, 13, 7, 8, 13, 8, 13, 13, 13, 8, 8, 7, 7, 3,
+ 13, 13, 7, 8, 13, 13, 13, 8, 13, 13, 8, 7, 8, 7, 8, 3,
+ 13, 12, 12, 12, 12, 12, 12, 6, 12, 12, 12, 8, 8, 7, 7, 2
+ },
+ {
+ 14, 3, 3, 5, 3, 4, 5, 5, 3, 5, 4, 5, 4, 6, 5, 6,
+ 8, 14, 13, 8, 8, 13, 13, 8, 8, 13, 13, 8, 13, 13, 8, 13,
+ 13, 8, 13, 13, 7, 7, 13, 13, 13, 13, 8, 8, 13, 13, 7, 6,
+ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 8, 7
+ },
+ {
+ 13, 5, 5, 5, 4, 4, 6, 4, 4, 6, 4, 5, 5, 5, 4, 3,
+ 6, 8, 10, 9, 8, 8, 7, 8, 13, 13, 7, 7, 8, 8, 7, 5,
+ 8, 7, 9, 9, 9, 6, 8, 7, 8, 13, 8, 7, 8, 7, 8, 5,
+ 8, 9, 8, 13, 8, 9, 13, 8, 12, 8, 8, 9, 9, 9, 8, 5
+ },
+ {
+ 9, 2, 3, 9, 2, 9, 9, 9, 2, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8
+ }
+};
+#endif
+
+/* MacroBlock Transform Type: 7.1.3.11, p89
+ * 8x8:B
+ * 8x4:B:btm 8x4:B:top 8x4:B:both,
+ * 4x8:B:right 4x8:B:left 4x8:B:both
+ * 4x4:B 8x8:MB
+ * 8x4:MB:btm 8x4:MB:top 8x4,MB,both
+ * 4x8,MB,right 4x8,MB,left
+ * 4x4,MB */
+static const uint16_t vc1_ttmb_codes[3][16] = {
+ {
+ 0x0003,
+ 0x002E, 0x005F, 0x0000,
+ 0x0016, 0x0015, 0x0001,
+ 0x0004, 0x0014,
+ 0x02F1, 0x0179, 0x017B,
+ 0x0BC0, 0x0BC1, 0x05E1,
+ 0x017A
+ },
+ {
+ 0x0006,
+ 0x0006, 0x0003, 0x0007,
+ 0x000F, 0x000E, 0x0000,
+ 0x0002, 0x0002,
+ 0x0014, 0x0011, 0x000B,
+ 0x0009, 0x0021, 0x0015,
+ 0x0020
+ },
+ {
+ 0x0006,
+ 0x0000, 0x000E, 0x0005,
+ 0x0002, 0x0003, 0x0003,
+ 0x000F, 0x0002,
+ 0x0081, 0x0021, 0x0009,
+ 0x0101, 0x0041, 0x0011,
+ 0x0100
+ }
+};
+
+static const uint8_t vc1_ttmb_bits[3][16] = {
+ {
+ 2,
+ 6, 7, 2,
+ 5, 5, 2,
+ 3, 5,
+ 10, 9, 9,
+ 12, 12, 11,
+ 9
+ },
+ {
+ 3,
+ 4, 4, 4,
+ 4, 4, 3,
+ 3, 2,
+ 7, 7, 6,
+ 6, 8, 7,
+ 8
+ },
+ {
+ 3,
+ 3, 4, 5,
+ 3, 3, 4,
+ 4, 2,
+ 10, 8, 6,
+ 11, 9, 7,
+ 11
+ }
+};
+
+/* TTBLK (Transform Type per Block) tables */
+static const uint8_t vc1_ttblk_codes[3][8] = {
+ { 0, 1, 3, 5, 16, 17, 18, 19},
+ { 3, 0, 1, 2, 3, 5, 8, 9},
+ { 1, 0, 1, 4, 6, 7, 10, 11}
+};
+static const uint8_t vc1_ttblk_bits[3][8] = {
+ { 2, 2, 2, 3, 5, 5, 5, 5},
+ { 2, 3, 3, 3, 3, 3, 4, 4},
+ { 2, 3, 3, 3, 3, 3, 4, 4}
+};
+
+/* SUBBLKPAT tables, p93-94, reordered */
+static const uint8_t vc1_subblkpat_codes[3][15] = {
+ { 14, 12, 7, 11, 9, 26, 2, 10, 27, 8, 0, 6, 1, 15, 1},
+ { 14, 0, 8, 15, 10, 4, 23, 13, 5, 9, 25, 3, 24, 22, 1},
+ { 5, 6, 2, 2, 8, 0, 28, 3, 1, 3, 29, 1, 19, 18, 15}
+};
+static const uint8_t vc1_subblkpat_bits[3][15] = {
+ { 5, 5, 5, 5, 5, 6, 4, 5, 6, 5, 4, 5, 4, 5, 1},
+ { 4, 3, 4, 4, 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 2},
+ { 3, 3, 4, 3, 4, 5, 5, 3, 5, 4, 5, 4, 5, 5, 4}
+};
+
+/* MV differential tables, p265 */
+static const uint16_t vc1_mv_diff_codes[4][73] = {
+ {
+ 0, 2, 3, 8, 576, 3, 2, 6,
+ 5, 577, 578, 7, 8, 9, 40, 19,
+ 37, 82, 21, 22, 23, 579, 580, 166,
+ 96, 167, 49, 194, 195, 581, 582, 583,
+ 292, 293, 294, 13, 2, 7, 24, 50,
+ 102, 295, 13, 7, 8, 18, 50, 103,
+ 38, 20, 21, 22, 39, 204, 103, 23,
+ 24, 25, 104, 410, 105, 106, 107, 108,
+ 109, 220, 411, 442, 222, 443, 446, 447,
+ 7 /* 73 elements */
+ },
+ {
+ 0, 4, 5, 3, 4, 3, 4, 5,
+ 20, 6, 21, 44, 45, 46, 3008, 95,
+ 112, 113, 57, 3009, 3010, 116, 117, 3011,
+ 118, 3012, 3013, 3014, 3015, 3016, 3017, 3018,
+ 3019, 3020, 3021, 3022, 1, 4, 15, 160,
+ 161, 41, 6, 11, 42, 162, 43, 119,
+ 56, 57, 58, 163, 236, 237, 3023, 119,
+ 120, 242, 122, 486, 1512, 487, 246, 494,
+ 1513, 495, 1514, 1515, 1516, 1517, 1518, 1519,
+ 31 /* 73 elements */
+ },
+ {
+ 0, 512, 513, 514, 515, 2, 3, 258,
+ 259, 260, 261, 262, 263, 264, 265, 266,
+ 267, 268, 269, 270, 271, 272, 273, 274,
+ 275, 276, 277, 278, 279, 280, 281, 282,
+ 283, 284, 285, 286, 1, 5, 287, 288,
+ 289, 290, 6, 7, 291, 292, 293, 294,
+ 295, 296, 297, 298, 299, 300, 301, 302,
+ 303, 304, 305, 306, 307, 308, 309, 310,
+ 311, 312, 313, 314, 315, 316, 317, 318,
+ 319 /* 73 elements */
+ },
+ {
+ 0, 1, 1, 2, 3, 4, 1, 5,
+ 4, 3, 5, 8, 6, 9, 10, 11,
+ 12, 7, 104, 14, 105, 4, 10, 15,
+ 11, 6, 14, 8, 106, 107, 108, 15,
+ 109, 9, 55, 10, 1, 2, 1, 2,
+ 3, 12, 6, 2, 6, 7, 28, 7,
+ 15, 8, 5, 18, 29, 152, 77, 24,
+ 25, 26, 39, 108, 13, 109, 55, 56,
+ 57, 116, 11, 153, 234, 235, 118, 119,
+ 15 /* 73 elements */
+ }
+};
+static const uint8_t vc1_mv_diff_bits[4][73] = {
+ {
+ 6, 7, 7, 8, 14, 6, 5, 6, 7, 14, 14, 6, 6, 6, 8, 9,
+ 10, 9, 7, 7, 7, 14, 14, 10, 9, 10, 8, 10, 10, 14, 14, 14,
+ 13, 13, 13, 6, 3, 5, 6, 8, 9, 13, 5, 4, 4, 5, 7, 9,
+ 6, 5, 5, 5, 6, 9, 8, 5, 5, 5, 7, 10, 7, 7, 7, 7,
+ 7, 8, 10, 9, 8, 9, 9, 9, 3 /* 73 elements */
+ },
+ {
+ 5, 7, 7, 6, 6, 5, 5, 6, 7, 5, 7, 8, 8, 8, 14, 9,
+ 9, 9, 8, 14, 14, 9, 9, 14, 9, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 2, 3, 6, 8, 8, 6, 3, 4, 6, 8, 6, 9,
+ 6, 6, 6, 8, 8, 8, 14, 7, 7, 8, 7, 9, 13, 9, 8, 9,
+ 13, 9, 13, 13, 13, 13, 13, 13, 5 /* 73 elements */
+
+ },
+ {
+ 3, 12, 12, 12, 12, 3, 4, 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, 5, 11, 11, 11, 11, 4, 4, 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 /* 73 elements */
+ },
+ {
+ 15, 11, 15, 15, 15, 15, 12, 15, 12, 11, 12, 12, 15, 12, 12, 12,
+ 12, 15, 15, 12, 15, 10, 11, 12, 11, 10, 11, 10, 15, 15, 15, 11,
+ 15, 10, 14, 10, 4, 4, 5, 7, 8, 9, 5, 3, 4, 5, 6, 8,
+ 5, 4, 3, 5, 6, 8, 7, 5, 5, 5, 6, 7, 9, 7, 6, 6,
+ 6, 7, 10, 8, 8, 8, 7, 7, 4 /* 73 elements */
+ }
+};
+
+/* DC differentials low+hi-mo, p217 are the same as in msmpeg4data .h */
+
+/* Scantables/ZZ scan are at 11.9 (p262) and 8.1.1.12 (p10) */
+static const int8_t vc1_normal_zz[64] = {
+ 0, 8, 1, 2, 9, 16, 24, 17,
+ 10, 3, 4, 11, 18, 25, 32, 40,
+ 33, 48, 26, 19, 12, 5, 6, 13,
+ 20, 27, 34, 41, 56, 49, 57, 42,
+ 35, 28, 21, 14, 7, 15, 22, 29,
+ 36, 43, 50, 58, 51, 59, 44, 37,
+ 30, 23, 31, 38, 45, 52, 60, 53,
+ 61, 46, 39, 47, 54, 62, 55, 63
+};
+
+static const int8_t vc1_horizontal_zz [64] = /* Table 227 */
+{
+ 0, 1, 8, 2, 3, 9, 16, 24,
+ 17, 10, 4, 5, 11, 18, 25, 32,
+ 40, 48, 33, 26, 19, 12, 6, 7,
+ 13, 20, 27, 34, 41, 56, 49, 57,
+ 42, 35, 28, 21, 14, 15, 22, 29,
+ 36, 43, 50, 58, 51, 44, 37, 30,
+ 23, 31, 38, 45, 52, 59, 60, 53,
+ 46, 39, 47, 54, 61, 62, 55, 63
+};
+
+static const int8_t vc1_vertical_zz [64] = /* Table 228 */
+{
+ 0, 8, 16, 1, 24, 32, 40, 9,
+ 2, 3, 10, 17, 25, 48, 56, 41,
+ 33, 26, 18, 11, 4, 5, 12, 19,
+ 27, 34, 49, 57, 50, 42, 35, 28,
+ 20, 13, 6, 7, 14, 21, 29, 36,
+ 43, 51, 58, 59, 52, 44, 37, 30,
+ 22, 15, 23, 31, 38, 45, 60, 53,
+ 46, 39, 47, 54, 61, 62, 55, 63
+};
+
+static const int8_t vc1_simple_progressive_8x8_zz [64] =
+/* Table 229 */
+{
+ 0, 8, 1, 2, 9, 16, 24, 17,
+ 10, 3, 4, 11, 18, 25, 32, 40,
+ 48, 56, 41, 33, 26, 19, 12, 5,
+ 6, 13, 20, 27, 34, 49, 57, 58,
+ 50, 42, 35, 28, 21, 14, 7, 15,
+ 22, 29, 36, 43, 51, 59, 60, 52,
+ 44, 37, 30, 23, 31, 38, 45, 53,
+ 61, 62, 54, 46, 39, 47, 55, 63
+};
+
+static const int8_t vc1_simple_progressive_8x4_zz [32] = /* Table 230 */
+{
+ 0, 1, 2, 8, 3, 9, 10, 16,
+ 4, 11, 17, 24, 18, 12, 5, 19,
+ 25, 13, 20, 26, 27, 6, 21, 28,
+ 14, 22, 29, 7, 30, 15, 23, 31
+};
+
+static const int8_t vc1_simple_progressive_4x8_zz [32] = /* Table 231 */
+{
+ 0, 8, 1, 16,
+ 9, 24, 17, 2,
+ 32, 10, 25, 40,
+ 18, 48, 33, 26,
+ 56, 41, 34, 3,
+ 49, 57, 11, 42,
+ 19, 50, 27, 58,
+ 35, 43, 51, 59
+};
+
+/* Table 232 */
+static const int8_t vc1_simple_progressive_4x4_zz [16] =
+{
+ 0, 8, 16, 1,
+ 9, 24, 17, 2,
+ 10, 18, 25, 3,
+ 11, 26, 19, 27
+};
+
+static const int8_t vc1_adv_progressive_8x4_zz [32] = /* Table 233 */
+{
+ 0, 8, 1, 16, 2, 9, 10, 3,
+ 24, 17, 4, 11, 18, 12, 5, 19,
+ 25, 13, 20, 26, 27, 6, 21, 28,
+ 14, 22, 29, 7, 30, 15, 23, 31
+};
+
+static const int8_t vc1_adv_progressive_4x8_zz [32] = /* Table 234 */
+{
+ 0, 1, 8, 2,
+ 9, 16, 17, 24,
+ 10, 32, 25, 18,
+ 40, 3, 33, 26,
+ 48, 11, 56, 41,
+ 34, 49, 57, 42,
+ 19, 50, 27, 58,
+ 35, 43, 51, 59
+};
+
+static const int8_t vc1_adv_interlaced_8x8_zz [64] = /* Table 235 */
+{
+ 0, 8, 1, 16, 24, 9, 2, 32,
+ 40, 48, 56, 17, 10, 3, 25, 18,
+ 11, 4, 33, 41, 49, 57, 26, 34,
+ 42, 50, 58, 19, 12, 5, 27, 20,
+ 13, 6, 35, 28, 21, 14, 7, 15,
+ 22, 29, 36, 43, 51, 59, 60, 52,
+ 44, 37, 30, 23, 31, 38, 45, 53,
+ 61, 62, 54, 46, 39, 47, 55, 63
+};
+
+static const int8_t vc1_adv_interlaced_8x4_zz [32] = /* Table 236 */
+{
+ 0, 8, 16, 24, 1, 9, 2, 17,
+ 25, 10, 3, 18, 26, 4, 11, 19,
+ 12, 5, 13, 20, 27, 6, 21, 28,
+ 14, 22, 29, 7, 30, 15, 23, 31
+};
+
+static const int8_t vc1_adv_interlaced_4x8_zz [32] = /* Table 237 */
+{
+ 0, 1, 2, 8,
+ 16, 9, 24, 17,
+ 10, 3, 32, 40,
+ 48, 56, 25, 18,
+ 33, 26, 41, 34,
+ 49, 57, 11, 42,
+ 19, 50, 27, 58,
+ 35, 43, 51, 59
+};
+
+static const int8_t vc1_adv_interlaced_4x4_zz [16] = /* Table 238 */
+{
+ 0, 8, 16, 24,
+ 1, 9, 17, 2,
+ 25, 10, 18, 3,
+ 26, 11, 19, 27
+};
+
+
+/* DQScale as specified in 8.1.3.9 - almost identical to 0x40000/i */
+static const int32_t vc1_dqscale[63] = {
+0x40000, 0x20000, 0x15555, 0x10000, 0xCCCD, 0xAAAB, 0x9249, 0x8000,
+ 0x71C7, 0x6666, 0x5D17, 0x5555, 0x4EC5, 0x4925, 0x4444, 0x4000,
+ 0x3C3C, 0x38E4, 0x35E5, 0x3333, 0x30C3, 0x2E8C, 0x2C86, 0x2AAB,
+ 0x28F6, 0x2762, 0x25ED, 0x2492, 0x234F, 0x2222, 0x2108, 0x2000,
+ 0x1F08, 0x1E1E, 0x1D42, 0x1C72, 0x1BAD, 0x1AF3, 0x1A42, 0x199A,
+ 0x18FA, 0x1862, 0x17D0, 0x1746, 0x16C1, 0x1643, 0x15CA, 0x1555,
+ 0x14E6, 0x147B, 0x1414, 0x13B1, 0x1352, 0x12F7, 0x129E, 0x1249,
+ 0x11F7, 0x11A8, 0x115B, 0x1111, 0x10C9, 0x1084, 0x1000
+};
+#endif /* VC1DATA_H */
diff --git a/contrib/ffmpeg/libavcodec/vc1dsp.c b/contrib/ffmpeg/libavcodec/vc1dsp.c
new file mode 100644
index 000000000..6102c0960
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/vc1dsp.c
@@ -0,0 +1,463 @@
+/*
+ * VC-1 and WMV3 decoder - DSP functions
+ * Copyright (c) 2006 Konstantin Shishkov
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+* @file vc1dsp.c
+ * VC-1 and WMV3 decoder
+ *
+ */
+
+#include "dsputil.h"
+
+
+/** Apply overlap transform to horizontal edge
+*/
+static void vc1_v_overlap_c(uint8_t* src, int stride)
+{
+ int i;
+ int a, b, c, d;
+ int d1, d2;
+ int rnd = 1;
+ for(i = 0; i < 8; i++) {
+ a = src[-2*stride];
+ b = src[-stride];
+ c = src[0];
+ d = src[stride];
+ d1 = (a - d + 3 + rnd) >> 3;
+ d2 = (a - d + b - c + 4 - rnd) >> 3;
+
+ src[-2*stride] = a - d1;
+ src[-stride] = b - d2;
+ src[0] = c + d2;
+ src[stride] = d + d1;
+ src++;
+ rnd = !rnd;
+ }
+}
+
+/** Apply overlap transform to vertical edge
+*/
+static void vc1_h_overlap_c(uint8_t* src, int stride)
+{
+ int i;
+ int a, b, c, d;
+ int d1, d2;
+ int rnd = 1;
+ for(i = 0; i < 8; i++) {
+ a = src[-2];
+ b = src[-1];
+ c = src[0];
+ d = src[1];
+ d1 = (a - d + 3 + rnd) >> 3;
+ d2 = (a - d + b - c + 4 - rnd) >> 3;
+
+ src[-2] = a - d1;
+ src[-1] = b - d2;
+ src[0] = c + d2;
+ src[1] = d + d1;
+ src += stride;
+ rnd = !rnd;
+ }
+}
+
+
+/** Do inverse transform on 8x8 block
+*/
+static void vc1_inv_trans_8x8_c(DCTELEM block[64])
+{
+ int i;
+ register int t1,t2,t3,t4,t5,t6,t7,t8;
+ DCTELEM *src, *dst;
+
+ src = block;
+ dst = block;
+ for(i = 0; i < 8; i++){
+ t1 = 12 * (src[0] + src[4]);
+ t2 = 12 * (src[0] - src[4]);
+ t3 = 16 * src[2] + 6 * src[6];
+ t4 = 6 * src[2] - 16 * src[6];
+
+ t5 = t1 + t3;
+ t6 = t2 + t4;
+ t7 = t2 - t4;
+ t8 = t1 - t3;
+
+ t1 = 16 * src[1] + 15 * src[3] + 9 * src[5] + 4 * src[7];
+ t2 = 15 * src[1] - 4 * src[3] - 16 * src[5] - 9 * src[7];
+ t3 = 9 * src[1] - 16 * src[3] + 4 * src[5] + 15 * src[7];
+ t4 = 4 * src[1] - 9 * src[3] + 15 * src[5] - 16 * src[7];
+
+ dst[0] = (t5 + t1 + 4) >> 3;
+ dst[1] = (t6 + t2 + 4) >> 3;
+ dst[2] = (t7 + t3 + 4) >> 3;
+ dst[3] = (t8 + t4 + 4) >> 3;
+ dst[4] = (t8 - t4 + 4) >> 3;
+ dst[5] = (t7 - t3 + 4) >> 3;
+ dst[6] = (t6 - t2 + 4) >> 3;
+ dst[7] = (t5 - t1 + 4) >> 3;
+
+ src += 8;
+ dst += 8;
+ }
+
+ src = block;
+ dst = block;
+ for(i = 0; i < 8; i++){
+ t1 = 12 * (src[ 0] + src[32]);
+ t2 = 12 * (src[ 0] - src[32]);
+ t3 = 16 * src[16] + 6 * src[48];
+ t4 = 6 * src[16] - 16 * src[48];
+
+ t5 = t1 + t3;
+ t6 = t2 + t4;
+ t7 = t2 - t4;
+ t8 = t1 - t3;
+
+ t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56];
+ t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56];
+ t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56];
+ t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56];
+
+ dst[ 0] = (t5 + t1 + 64) >> 7;
+ dst[ 8] = (t6 + t2 + 64) >> 7;
+ dst[16] = (t7 + t3 + 64) >> 7;
+ dst[24] = (t8 + t4 + 64) >> 7;
+ dst[32] = (t8 - t4 + 64 + 1) >> 7;
+ dst[40] = (t7 - t3 + 64 + 1) >> 7;
+ dst[48] = (t6 - t2 + 64 + 1) >> 7;
+ dst[56] = (t5 - t1 + 64 + 1) >> 7;
+
+ src++;
+ dst++;
+ }
+}
+
+/** Do inverse transform on 8x4 part of block
+*/
+static void vc1_inv_trans_8x4_c(DCTELEM block[64], int n)
+{
+ int i;
+ register int t1,t2,t3,t4,t5,t6,t7,t8;
+ DCTELEM *src, *dst;
+ int off;
+
+ off = n * 32;
+ src = block + off;
+ dst = block + off;
+ for(i = 0; i < 4; i++){
+ t1 = 12 * (src[0] + src[4]);
+ t2 = 12 * (src[0] - src[4]);
+ t3 = 16 * src[2] + 6 * src[6];
+ t4 = 6 * src[2] - 16 * src[6];
+
+ t5 = t1 + t3;
+ t6 = t2 + t4;
+ t7 = t2 - t4;
+ t8 = t1 - t3;
+
+ t1 = 16 * src[1] + 15 * src[3] + 9 * src[5] + 4 * src[7];
+ t2 = 15 * src[1] - 4 * src[3] - 16 * src[5] - 9 * src[7];
+ t3 = 9 * src[1] - 16 * src[3] + 4 * src[5] + 15 * src[7];
+ t4 = 4 * src[1] - 9 * src[3] + 15 * src[5] - 16 * src[7];
+
+ dst[0] = (t5 + t1 + 4) >> 3;
+ dst[1] = (t6 + t2 + 4) >> 3;
+ dst[2] = (t7 + t3 + 4) >> 3;
+ dst[3] = (t8 + t4 + 4) >> 3;
+ dst[4] = (t8 - t4 + 4) >> 3;
+ dst[5] = (t7 - t3 + 4) >> 3;
+ dst[6] = (t6 - t2 + 4) >> 3;
+ dst[7] = (t5 - t1 + 4) >> 3;
+
+ src += 8;
+ dst += 8;
+ }
+
+ src = block + off;
+ dst = block + off;
+ for(i = 0; i < 8; i++){
+ t1 = 17 * (src[ 0] + src[16]);
+ t2 = 17 * (src[ 0] - src[16]);
+ t3 = 22 * src[ 8];
+ t4 = 22 * src[24];
+ t5 = 10 * src[ 8];
+ t6 = 10 * src[24];
+
+ dst[ 0] = (t1 + t3 + t6 + 64) >> 7;
+ dst[ 8] = (t2 - t4 + t5 + 64) >> 7;
+ dst[16] = (t2 + t4 - t5 + 64) >> 7;
+ dst[24] = (t1 - t3 - t6 + 64) >> 7;
+
+ src ++;
+ dst ++;
+ }
+}
+
+/** Do inverse transform on 4x8 parts of block
+*/
+static void vc1_inv_trans_4x8_c(DCTELEM block[64], int n)
+{
+ int i;
+ register int t1,t2,t3,t4,t5,t6,t7,t8;
+ DCTELEM *src, *dst;
+ int off;
+
+ off = n * 4;
+ src = block + off;
+ dst = block + off;
+ for(i = 0; i < 8; i++){
+ t1 = 17 * (src[0] + src[2]);
+ t2 = 17 * (src[0] - src[2]);
+ t3 = 22 * src[1];
+ t4 = 22 * src[3];
+ t5 = 10 * src[1];
+ t6 = 10 * src[3];
+
+ dst[0] = (t1 + t3 + t6 + 4) >> 3;
+ dst[1] = (t2 - t4 + t5 + 4) >> 3;
+ dst[2] = (t2 + t4 - t5 + 4) >> 3;
+ dst[3] = (t1 - t3 - t6 + 4) >> 3;
+
+ src += 8;
+ dst += 8;
+ }
+
+ src = block + off;
+ dst = block + off;
+ for(i = 0; i < 4; i++){
+ t1 = 12 * (src[ 0] + src[32]);
+ t2 = 12 * (src[ 0] - src[32]);
+ t3 = 16 * src[16] + 6 * src[48];
+ t4 = 6 * src[16] - 16 * src[48];
+
+ t5 = t1 + t3;
+ t6 = t2 + t4;
+ t7 = t2 - t4;
+ t8 = t1 - t3;
+
+ t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56];
+ t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56];
+ t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56];
+ t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56];
+
+ dst[ 0] = (t5 + t1 + 64) >> 7;
+ dst[ 8] = (t6 + t2 + 64) >> 7;
+ dst[16] = (t7 + t3 + 64) >> 7;
+ dst[24] = (t8 + t4 + 64) >> 7;
+ dst[32] = (t8 - t4 + 64 + 1) >> 7;
+ dst[40] = (t7 - t3 + 64 + 1) >> 7;
+ dst[48] = (t6 - t2 + 64 + 1) >> 7;
+ dst[56] = (t5 - t1 + 64 + 1) >> 7;
+
+ src++;
+ dst++;
+ }
+}
+
+/** Do inverse transform on 4x4 part of block
+*/
+static void vc1_inv_trans_4x4_c(DCTELEM block[64], int n)
+{
+ int i;
+ register int t1,t2,t3,t4,t5,t6;
+ DCTELEM *src, *dst;
+ int off;
+
+ off = (n&1) * 4 + (n&2) * 16;
+ src = block + off;
+ dst = block + off;
+ for(i = 0; i < 4; i++){
+ t1 = 17 * (src[0] + src[2]);
+ t2 = 17 * (src[0] - src[2]);
+ t3 = 22 * src[1];
+ t4 = 22 * src[3];
+ t5 = 10 * src[1];
+ t6 = 10 * src[3];
+
+ dst[0] = (t1 + t3 + t6 + 4) >> 3;
+ dst[1] = (t2 - t4 + t5 + 4) >> 3;
+ dst[2] = (t2 + t4 - t5 + 4) >> 3;
+ dst[3] = (t1 - t3 - t6 + 4) >> 3;
+
+ src += 8;
+ dst += 8;
+ }
+
+ src = block + off;
+ dst = block + off;
+ for(i = 0; i < 4; i++){
+ t1 = 17 * (src[ 0] + src[16]);
+ t2 = 17 * (src[ 0] - src[16]);
+ t3 = 22 * src[ 8];
+ t4 = 22 * src[24];
+ t5 = 10 * src[ 8];
+ t6 = 10 * src[24];
+
+ dst[ 0] = (t1 + t3 + t6 + 64) >> 7;
+ dst[ 8] = (t2 - t4 + t5 + 64) >> 7;
+ dst[16] = (t2 + t4 - t5 + 64) >> 7;
+ dst[24] = (t1 - t3 - t6 + 64) >> 7;
+
+ src ++;
+ dst ++;
+ }
+}
+
+/* motion compensation functions */
+
+/** Filter used to interpolate fractional pel values
+ */
+static av_always_inline int vc1_mspel_filter(const uint8_t *src, int stride, int mode, int r)
+{
+ switch(mode){
+ case 0: //no shift
+ return src[0];
+ case 1: // 1/4 shift
+ return (-4*src[-stride] + 53*src[0] + 18*src[stride] - 3*src[stride*2] + 32 - r) >> 6;
+ case 2: // 1/2 shift
+ return (-src[-stride] + 9*src[0] + 9*src[stride] - src[stride*2] + 8 - r) >> 4;
+ case 3: // 3/4 shift
+ return (-3*src[-stride] + 18*src[0] + 53*src[stride] - 4*src[stride*2] + 32 - r) >> 6;
+ }
+ return 0; //should not occur
+}
+
+/** Function used to do motion compensation with bicubic interpolation
+ */
+static void vc1_mspel_mc(uint8_t *dst, const uint8_t *src, int stride, int mode, int rnd)
+{
+ int i, j;
+ uint8_t tmp[8*11], *tptr;
+ int m, r;
+
+ m = (mode & 3);
+ r = rnd;
+ src -= stride;
+ tptr = tmp;
+ for(j = 0; j < 11; j++) {
+ for(i = 0; i < 8; i++)
+ tptr[i] = av_clip_uint8(vc1_mspel_filter(src + i, 1, m, r));
+ src += stride;
+ tptr += 8;
+ }
+ r = 1 - rnd;
+ m = (mode >> 2) & 3;
+
+ tptr = tmp + 8;
+ for(j = 0; j < 8; j++) {
+ for(i = 0; i < 8; i++)
+ dst[i] = av_clip_uint8(vc1_mspel_filter(tptr + i, 8, m, r));
+ dst += stride;
+ tptr += 8;
+ }
+}
+
+/* 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);
+
+static void ff_put_vc1_mspel_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
+ vc1_mspel_mc(dst, src, stride, 0x1, rnd);
+}
+
+static void ff_put_vc1_mspel_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
+ vc1_mspel_mc(dst, src, stride, 0x2, rnd);
+}
+
+static void ff_put_vc1_mspel_mc30_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
+ vc1_mspel_mc(dst, src, stride, 0x3, rnd);
+}
+
+static void ff_put_vc1_mspel_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
+ vc1_mspel_mc(dst, src, stride, 0x4, rnd);
+}
+
+static void ff_put_vc1_mspel_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
+ vc1_mspel_mc(dst, src, stride, 0x5, rnd);
+}
+
+static void ff_put_vc1_mspel_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
+ vc1_mspel_mc(dst, src, stride, 0x6, rnd);
+}
+
+static void ff_put_vc1_mspel_mc31_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
+ vc1_mspel_mc(dst, src, stride, 0x7, rnd);
+}
+
+static void ff_put_vc1_mspel_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
+ vc1_mspel_mc(dst, src, stride, 0x8, rnd);
+}
+
+static void ff_put_vc1_mspel_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
+ vc1_mspel_mc(dst, src, stride, 0x9, rnd);
+}
+
+static void ff_put_vc1_mspel_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
+ vc1_mspel_mc(dst, src, stride, 0xA, rnd);
+}
+
+static void ff_put_vc1_mspel_mc32_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
+ vc1_mspel_mc(dst, src, stride, 0xB, rnd);
+}
+
+static void ff_put_vc1_mspel_mc03_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
+ vc1_mspel_mc(dst, src, stride, 0xC, rnd);
+}
+
+static void ff_put_vc1_mspel_mc13_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
+ vc1_mspel_mc(dst, src, stride, 0xD, rnd);
+}
+
+static void ff_put_vc1_mspel_mc23_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
+ vc1_mspel_mc(dst, src, stride, 0xE, rnd);
+}
+
+static void ff_put_vc1_mspel_mc33_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
+ vc1_mspel_mc(dst, src, stride, 0xF, rnd);
+}
+
+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;
+ dsp->vc1_inv_trans_4x4 = vc1_inv_trans_4x4_c;
+ dsp->vc1_h_overlap = vc1_h_overlap_c;
+ dsp->vc1_v_overlap = vc1_v_overlap_c;
+
+ dsp->put_vc1_mspel_pixels_tab[ 0] = ff_put_vc1_mspel_mc00_c;
+ dsp->put_vc1_mspel_pixels_tab[ 1] = ff_put_vc1_mspel_mc10_c;
+ dsp->put_vc1_mspel_pixels_tab[ 2] = ff_put_vc1_mspel_mc20_c;
+ dsp->put_vc1_mspel_pixels_tab[ 3] = ff_put_vc1_mspel_mc30_c;
+ dsp->put_vc1_mspel_pixels_tab[ 4] = ff_put_vc1_mspel_mc01_c;
+ dsp->put_vc1_mspel_pixels_tab[ 5] = ff_put_vc1_mspel_mc11_c;
+ dsp->put_vc1_mspel_pixels_tab[ 6] = ff_put_vc1_mspel_mc21_c;
+ dsp->put_vc1_mspel_pixels_tab[ 7] = ff_put_vc1_mspel_mc31_c;
+ dsp->put_vc1_mspel_pixels_tab[ 8] = ff_put_vc1_mspel_mc02_c;
+ dsp->put_vc1_mspel_pixels_tab[ 9] = ff_put_vc1_mspel_mc12_c;
+ dsp->put_vc1_mspel_pixels_tab[10] = ff_put_vc1_mspel_mc22_c;
+ dsp->put_vc1_mspel_pixels_tab[11] = ff_put_vc1_mspel_mc32_c;
+ dsp->put_vc1_mspel_pixels_tab[12] = ff_put_vc1_mspel_mc03_c;
+ dsp->put_vc1_mspel_pixels_tab[13] = ff_put_vc1_mspel_mc13_c;
+ dsp->put_vc1_mspel_pixels_tab[14] = ff_put_vc1_mspel_mc23_c;
+ dsp->put_vc1_mspel_pixels_tab[15] = ff_put_vc1_mspel_mc33_c;
+}
diff --git a/src/libffmpeg/libavcodec/vcr1.c b/contrib/ffmpeg/libavcodec/vcr1.c
index 62bf12320..62bf12320 100644
--- a/src/libffmpeg/libavcodec/vcr1.c
+++ b/contrib/ffmpeg/libavcodec/vcr1.c
diff --git a/contrib/ffmpeg/libavcodec/vmdav.c b/contrib/ffmpeg/libavcodec/vmdav.c
new file mode 100644
index 000000000..69e8a44d3
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/vmdav.c
@@ -0,0 +1,572 @@
+/*
+ * Sierra VMD Audio & Video Decoders
+ * Copyright (C) 2004 the ffmpeg project
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * @file vmdvideo.c
+ * Sierra VMD audio & video decoders
+ * by Vladimir "VAG" Gneushev (vagsoft at mail.ru)
+ * for more information on the Sierra VMD format, visit:
+ * http://www.pcisys.net/~melanson/codecs/
+ *
+ * The video decoder outputs PAL8 colorspace data. The decoder expects
+ * a 0x330-byte VMD file header to be transmitted via extradata during
+ * codec initialization. Each encoded frame that is sent to this decoder
+ * is expected to be prepended with the appropriate 16-byte frame
+ * information record from the VMD file.
+ *
+ * The audio decoder, like the video decoder, expects each encoded data
+ * chunk to be prepended with the appropriate 16-byte frame information
+ * record from the VMD file. It does not require the 0x330-byte VMD file
+ * header, but it does need the audio setup parameters passed in through
+ * normal libavcodec API means.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "common.h"
+#include "avcodec.h"
+#include "dsputil.h"
+
+#define VMD_HEADER_SIZE 0x330
+#define PALETTE_COUNT 256
+
+/*
+ * Video Decoder
+ */
+
+typedef struct VmdVideoContext {
+
+ AVCodecContext *avctx;
+ DSPContext dsp;
+ AVFrame frame;
+ AVFrame prev_frame;
+
+ unsigned char *buf;
+ int size;
+
+ unsigned char palette[PALETTE_COUNT * 4];
+ unsigned char *unpack_buffer;
+ int unpack_buffer_size;
+
+} VmdVideoContext;
+
+#define QUEUE_SIZE 0x1000
+#define QUEUE_MASK 0x0FFF
+
+static void lz_unpack(unsigned char *src, unsigned char *dest, int dest_len)
+{
+ unsigned char *s;
+ unsigned char *d;
+ unsigned char *d_end;
+ unsigned char queue[QUEUE_SIZE];
+ unsigned int qpos;
+ unsigned int dataleft;
+ unsigned int chainofs;
+ unsigned int chainlen;
+ unsigned int speclen;
+ unsigned char tag;
+ unsigned int i, j;
+
+ s = src;
+ d = dest;
+ d_end = d + dest_len;
+ dataleft = AV_RL32(s);
+ s += 4;
+ memset(queue, 0x20, QUEUE_SIZE);
+ if (AV_RL32(s) == 0x56781234) {
+ s += 4;
+ qpos = 0x111;
+ speclen = 0xF + 3;
+ } else {
+ qpos = 0xFEE;
+ speclen = 100; /* no speclen */
+ }
+
+ while (dataleft > 0) {
+ tag = *s++;
+ if ((tag == 0xFF) && (dataleft > 8)) {
+ if (d + 8 > d_end)
+ return;
+ for (i = 0; i < 8; i++) {
+ queue[qpos++] = *d++ = *s++;
+ qpos &= QUEUE_MASK;
+ }
+ dataleft -= 8;
+ } else {
+ for (i = 0; i < 8; i++) {
+ if (dataleft == 0)
+ break;
+ if (tag & 0x01) {
+ if (d + 1 > d_end)
+ return;
+ queue[qpos++] = *d++ = *s++;
+ qpos &= QUEUE_MASK;
+ dataleft--;
+ } else {
+ chainofs = *s++;
+ chainofs |= ((*s & 0xF0) << 4);
+ chainlen = (*s++ & 0x0F) + 3;
+ if (chainlen == speclen)
+ chainlen = *s++ + 0xF + 3;
+ if (d + chainlen > d_end)
+ return;
+ for (j = 0; j < chainlen; j++) {
+ *d = queue[chainofs++ & QUEUE_MASK];
+ queue[qpos++] = *d++;
+ qpos &= QUEUE_MASK;
+ }
+ dataleft -= chainlen;
+ }
+ tag >>= 1;
+ }
+ }
+ }
+}
+
+static int rle_unpack(unsigned char *src, unsigned char *dest,
+ int src_len, int dest_len)
+{
+ unsigned char *ps;
+ unsigned char *pd;
+ int i, l;
+ unsigned char *dest_end = dest + dest_len;
+
+ ps = src;
+ pd = dest;
+ if (src_len & 1)
+ *pd++ = *ps++;
+
+ src_len >>= 1;
+ i = 0;
+ do {
+ l = *ps++;
+ if (l & 0x80) {
+ l = (l & 0x7F) * 2;
+ if (pd + l > dest_end)
+ return (ps - src);
+ memcpy(pd, ps, l);
+ ps += l;
+ pd += l;
+ } else {
+ if (pd + i > dest_end)
+ return (ps - src);
+ for (i = 0; i < l; i++) {
+ *pd++ = ps[0];
+ *pd++ = ps[1];
+ }
+ ps += 2;
+ }
+ i += l;
+ } while (i < src_len);
+
+ return (ps - src);
+}
+
+static void vmd_decode(VmdVideoContext *s)
+{
+ int i;
+ unsigned int *palette32;
+ unsigned char r, g, b;
+
+ /* point to the start of the encoded data */
+ unsigned char *p = s->buf + 16;
+
+ unsigned char *pb;
+ unsigned char meth;
+ unsigned char *dp; /* pointer to current frame */
+ unsigned char *pp; /* pointer to previous frame */
+ unsigned char len;
+ int ofs;
+
+ int frame_x, frame_y;
+ int frame_width, frame_height;
+ int dp_size;
+
+ frame_x = AV_RL16(&s->buf[6]);
+ frame_y = AV_RL16(&s->buf[8]);
+ frame_width = AV_RL16(&s->buf[10]) - frame_x + 1;
+ frame_height = AV_RL16(&s->buf[12]) - frame_y + 1;
+
+ /* if only a certain region will be updated, copy the entire previous
+ * frame before the decode */
+ if (frame_x || frame_y || (frame_width != s->avctx->width) ||
+ (frame_height != s->avctx->height)) {
+
+ memcpy(s->frame.data[0], s->prev_frame.data[0],
+ s->avctx->height * s->frame.linesize[0]);
+ }
+
+ /* check if there is a new palette */
+ if (s->buf[15] & 0x02) {
+ p += 2;
+ palette32 = (unsigned int *)s->palette;
+ for (i = 0; i < PALETTE_COUNT; i++) {
+ r = *p++ * 4;
+ g = *p++ * 4;
+ b = *p++ * 4;
+ palette32[i] = (r << 16) | (g << 8) | (b);
+ }
+ s->size -= (256 * 3 + 2);
+ }
+ if (s->size >= 0) {
+ /* originally UnpackFrame in VAG's code */
+ pb = p;
+ meth = *pb++;
+ if (meth & 0x80) {
+ lz_unpack(pb, s->unpack_buffer, s->unpack_buffer_size);
+ meth &= 0x7F;
+ pb = s->unpack_buffer;
+ }
+
+ dp = &s->frame.data[0][frame_y * s->frame.linesize[0] + frame_x];
+ dp_size = s->frame.linesize[0] * s->avctx->height;
+ pp = &s->prev_frame.data[0][frame_y * s->prev_frame.linesize[0] + frame_x];
+ switch (meth) {
+ case 1:
+ for (i = 0; i < frame_height; i++) {
+ ofs = 0;
+ do {
+ len = *pb++;
+ if (len & 0x80) {
+ len = (len & 0x7F) + 1;
+ if (ofs + len > frame_width)
+ return;
+ memcpy(&dp[ofs], pb, len);
+ pb += len;
+ ofs += len;
+ } else {
+ /* interframe pixel copy */
+ if (ofs + len + 1 > frame_width)
+ return;
+ memcpy(&dp[ofs], &pp[ofs], len + 1);
+ ofs += len + 1;
+ }
+ } while (ofs < frame_width);
+ if (ofs > frame_width) {
+ av_log(s->avctx, AV_LOG_ERROR, "VMD video: offset > width (%d > %d)\n",
+ ofs, frame_width);
+ break;
+ }
+ dp += s->frame.linesize[0];
+ pp += s->prev_frame.linesize[0];
+ }
+ break;
+
+ case 2:
+ for (i = 0; i < frame_height; i++) {
+ memcpy(dp, pb, frame_width);
+ pb += frame_width;
+ dp += s->frame.linesize[0];
+ pp += s->prev_frame.linesize[0];
+ }
+ break;
+
+ case 3:
+ for (i = 0; i < frame_height; i++) {
+ ofs = 0;
+ do {
+ len = *pb++;
+ if (len & 0x80) {
+ len = (len & 0x7F) + 1;
+ if (*pb++ == 0xFF)
+ len = rle_unpack(pb, &dp[ofs], len, frame_width - ofs);
+ else
+ memcpy(&dp[ofs], pb, len);
+ pb += len;
+ ofs += len;
+ } else {
+ /* interframe pixel copy */
+ if (ofs + len + 1 > frame_width)
+ return;
+ memcpy(&dp[ofs], &pp[ofs], len + 1);
+ ofs += len + 1;
+ }
+ } while (ofs < frame_width);
+ if (ofs > frame_width) {
+ av_log(s->avctx, AV_LOG_ERROR, "VMD video: offset > width (%d > %d)\n",
+ ofs, frame_width);
+ }
+ dp += s->frame.linesize[0];
+ pp += s->prev_frame.linesize[0];
+ }
+ break;
+ }
+ }
+}
+
+static int vmdvideo_decode_init(AVCodecContext *avctx)
+{
+ VmdVideoContext *s = (VmdVideoContext *)avctx->priv_data;
+ int i;
+ unsigned int *palette32;
+ int palette_index = 0;
+ unsigned char r, g, b;
+ unsigned char *vmd_header;
+ unsigned char *raw_palette;
+
+ s->avctx = avctx;
+ avctx->pix_fmt = PIX_FMT_PAL8;
+ avctx->has_b_frames = 0;
+ dsputil_init(&s->dsp, avctx);
+
+ /* make sure the VMD header made it */
+ if (s->avctx->extradata_size != VMD_HEADER_SIZE) {
+ av_log(s->avctx, AV_LOG_ERROR, "VMD video: expected extradata size of %d\n",
+ VMD_HEADER_SIZE);
+ return -1;
+ }
+ vmd_header = (unsigned char *)avctx->extradata;
+
+ s->unpack_buffer_size = AV_RL32(&vmd_header[800]);
+ s->unpack_buffer = av_malloc(s->unpack_buffer_size);
+ if (!s->unpack_buffer)
+ return -1;
+
+ /* load up the initial palette */
+ raw_palette = &vmd_header[28];
+ palette32 = (unsigned int *)s->palette;
+ for (i = 0; i < PALETTE_COUNT; i++) {
+ r = raw_palette[palette_index++] * 4;
+ g = raw_palette[palette_index++] * 4;
+ b = raw_palette[palette_index++] * 4;
+ palette32[i] = (r << 16) | (g << 8) | (b);
+ }
+
+ s->frame.data[0] = s->prev_frame.data[0] = NULL;
+
+ return 0;
+}
+
+static int vmdvideo_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ VmdVideoContext *s = (VmdVideoContext *)avctx->priv_data;
+
+ s->buf = buf;
+ s->size = buf_size;
+
+ if (buf_size < 16)
+ return buf_size;
+
+ s->frame.reference = 1;
+ if (avctx->get_buffer(avctx, &s->frame)) {
+ av_log(s->avctx, AV_LOG_ERROR, "VMD Video: get_buffer() failed\n");
+ return -1;
+ }
+
+ vmd_decode(s);
+
+ /* make the palette available on the way out */
+ memcpy(s->frame.data[1], s->palette, PALETTE_COUNT * 4);
+
+ if (s->prev_frame.data[0])
+ avctx->release_buffer(avctx, &s->prev_frame);
+
+ /* shuffle frames */
+ s->prev_frame = s->frame;
+
+ *data_size = sizeof(AVFrame);
+ *(AVFrame*)data = s->frame;
+
+ /* report that the buffer was completely consumed */
+ return buf_size;
+}
+
+static int vmdvideo_decode_end(AVCodecContext *avctx)
+{
+ VmdVideoContext *s = (VmdVideoContext *)avctx->priv_data;
+
+ if (s->prev_frame.data[0])
+ avctx->release_buffer(avctx, &s->prev_frame);
+ av_free(s->unpack_buffer);
+
+ return 0;
+}
+
+
+/*
+ * Audio Decoder
+ */
+
+typedef struct VmdAudioContext {
+ AVCodecContext *avctx;
+ int channels;
+ int bits;
+ int block_align;
+ int predictors[2];
+} VmdAudioContext;
+
+static uint16_t vmdaudio_table[128] = {
+ 0x000, 0x008, 0x010, 0x020, 0x030, 0x040, 0x050, 0x060, 0x070, 0x080,
+ 0x090, 0x0A0, 0x0B0, 0x0C0, 0x0D0, 0x0E0, 0x0F0, 0x100, 0x110, 0x120,
+ 0x130, 0x140, 0x150, 0x160, 0x170, 0x180, 0x190, 0x1A0, 0x1B0, 0x1C0,
+ 0x1D0, 0x1E0, 0x1F0, 0x200, 0x208, 0x210, 0x218, 0x220, 0x228, 0x230,
+ 0x238, 0x240, 0x248, 0x250, 0x258, 0x260, 0x268, 0x270, 0x278, 0x280,
+ 0x288, 0x290, 0x298, 0x2A0, 0x2A8, 0x2B0, 0x2B8, 0x2C0, 0x2C8, 0x2D0,
+ 0x2D8, 0x2E0, 0x2E8, 0x2F0, 0x2F8, 0x300, 0x308, 0x310, 0x318, 0x320,
+ 0x328, 0x330, 0x338, 0x340, 0x348, 0x350, 0x358, 0x360, 0x368, 0x370,
+ 0x378, 0x380, 0x388, 0x390, 0x398, 0x3A0, 0x3A8, 0x3B0, 0x3B8, 0x3C0,
+ 0x3C8, 0x3D0, 0x3D8, 0x3E0, 0x3E8, 0x3F0, 0x3F8, 0x400, 0x440, 0x480,
+ 0x4C0, 0x500, 0x540, 0x580, 0x5C0, 0x600, 0x640, 0x680, 0x6C0, 0x700,
+ 0x740, 0x780, 0x7C0, 0x800, 0x900, 0xA00, 0xB00, 0xC00, 0xD00, 0xE00,
+ 0xF00, 0x1000, 0x1400, 0x1800, 0x1C00, 0x2000, 0x3000, 0x4000
+};
+
+static int vmdaudio_decode_init(AVCodecContext *avctx)
+{
+ VmdAudioContext *s = (VmdAudioContext *)avctx->priv_data;
+
+ s->avctx = avctx;
+ s->channels = avctx->channels;
+ s->bits = avctx->bits_per_sample;
+ s->block_align = avctx->block_align;
+
+ av_log(s->avctx, AV_LOG_DEBUG, "%d channels, %d bits/sample, block align = %d, sample rate = %d\n",
+ s->channels, s->bits, s->block_align, avctx->sample_rate);
+
+ return 0;
+}
+
+static void vmdaudio_decode_audio(VmdAudioContext *s, unsigned char *data,
+ uint8_t *buf, int stereo)
+{
+ int i;
+ int chan = 0;
+ int16_t *out = (int16_t*)data;
+
+ for(i = 0; i < s->block_align; i++) {
+ if(buf[i] & 0x80)
+ s->predictors[chan] -= vmdaudio_table[buf[i] & 0x7F];
+ else
+ s->predictors[chan] += vmdaudio_table[buf[i]];
+ s->predictors[chan] = av_clip(s->predictors[chan], -32768, 32767);
+ out[i] = s->predictors[chan];
+ chan ^= stereo;
+ }
+}
+
+static int vmdaudio_loadsound(VmdAudioContext *s, unsigned char *data,
+ uint8_t *buf, int silence)
+{
+ int bytes_decoded = 0;
+ int i;
+
+// if (silence)
+// av_log(s->avctx, AV_LOG_INFO, "silent block!\n");
+ if (s->channels == 2) {
+
+ /* stereo handling */
+ if (silence) {
+ memset(data, 0, s->block_align * 2);
+ } else {
+ if (s->bits == 16)
+ vmdaudio_decode_audio(s, data, buf, 1);
+ else {
+ /* copy the data but convert it to signed */
+ for (i = 0; i < s->block_align; i++){
+ *data++ = buf[i] + 0x80;
+ *data++ = buf[i] + 0x80;
+ }
+ }
+ }
+ } else {
+ bytes_decoded = s->block_align * 2;
+
+ /* mono handling */
+ if (silence) {
+ memset(data, 0, s->block_align * 2);
+ } else {
+ if (s->bits == 16) {
+ vmdaudio_decode_audio(s, data, buf, 0);
+ } else {
+ /* copy the data but convert it to signed */
+ for (i = 0; i < s->block_align; i++){
+ *data++ = buf[i] + 0x80;
+ *data++ = buf[i] + 0x80;
+ }
+ }
+ }
+ }
+
+ return s->block_align * 2;
+}
+
+static int vmdaudio_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ VmdAudioContext *s = (VmdAudioContext *)avctx->priv_data;
+ unsigned char *output_samples = (unsigned char *)data;
+
+ /* point to the start of the encoded data */
+ unsigned char *p = buf + 16;
+
+ if (buf_size < 16)
+ return buf_size;
+
+ if (buf[6] == 1) {
+ /* the chunk contains audio */
+ *data_size = vmdaudio_loadsound(s, output_samples, p, 0);
+ } else if (buf[6] == 2) {
+ /* the chunk may contain audio */
+ p += 4;
+ *data_size = vmdaudio_loadsound(s, output_samples, p, (buf_size == 16));
+ output_samples += (s->block_align * s->bits / 8);
+ } else if (buf[6] == 3) {
+ /* silent chunk */
+ *data_size = vmdaudio_loadsound(s, output_samples, p, 1);
+ }
+
+ return buf_size;
+}
+
+
+/*
+ * Public Data Structures
+ */
+
+AVCodec vmdvideo_decoder = {
+ "vmdvideo",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_VMDVIDEO,
+ sizeof(VmdVideoContext),
+ vmdvideo_decode_init,
+ NULL,
+ vmdvideo_decode_end,
+ vmdvideo_decode_frame,
+ CODEC_CAP_DR1,
+};
+
+AVCodec vmdaudio_decoder = {
+ "vmdaudio",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_VMDAUDIO,
+ sizeof(VmdAudioContext),
+ vmdaudio_decode_init,
+ NULL,
+ NULL,
+ vmdaudio_decode_frame,
+};
diff --git a/contrib/ffmpeg/libavcodec/vmnc.c b/contrib/ffmpeg/libavcodec/vmnc.c
new file mode 100644
index 000000000..b430a7e66
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/vmnc.c
@@ -0,0 +1,524 @@
+/*
+ * VMware Screen Codec (VMnc) decoder
+ * Copyright (c) 2006 Konstantin Shishkov
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * @file vmnc.c
+ * VMware Screen Codec (VMnc) decoder
+ * As Alex Beregszaszi discovered, this is effectively RFB data dump
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "common.h"
+#include "avcodec.h"
+
+enum EncTypes {
+ MAGIC_WMVd = 0x574D5664,
+ MAGIC_WMVe,
+ MAGIC_WMVf,
+ MAGIC_WMVg,
+ MAGIC_WMVh,
+ MAGIC_WMVi,
+ MAGIC_WMVj
+};
+
+enum HexTile_Flags {
+ HT_RAW = 1, // tile is raw
+ HT_BKG = 2, // background color is present
+ HT_FG = 4, // foreground color is present
+ HT_SUB = 8, // subrects are present
+ HT_CLR = 16 // each subrect has own color
+};
+
+/*
+ * Decoder context
+ */
+typedef struct VmncContext {
+ AVCodecContext *avctx;
+ AVFrame pic;
+
+ int bpp;
+ int bpp2;
+ int bigendian;
+ uint8_t pal[768];
+ int width, height;
+
+ /* cursor data */
+ int cur_w, cur_h;
+ int cur_x, cur_y;
+ int cur_hx, cur_hy;
+ uint8_t* curbits, *curmask;
+ uint8_t* screendta;
+} VmncContext;
+
+/* read pixel value from stream */
+static av_always_inline int vmnc_get_pixel(uint8_t* buf, int bpp, int be) {
+ switch(bpp * 2 + be) {
+ case 2:
+ case 3: return *buf;
+ case 4: return AV_RL16(buf);
+ case 5: return AV_RB16(buf);
+ case 8: return AV_RL32(buf);
+ case 9: return AV_RB32(buf);
+ default: return 0;
+ }
+}
+
+static void load_cursor(VmncContext *c, uint8_t *src)
+{
+ int i, j, p;
+ const int bpp = c->bpp2;
+ uint8_t *dst8 = c->curbits;
+ uint16_t *dst16 = (uint16_t*)c->curbits;
+ uint32_t *dst32 = (uint32_t*)c->curbits;
+
+ for(j = 0; j < c->cur_h; j++) {
+ for(i = 0; i < c->cur_w; i++) {
+ p = vmnc_get_pixel(src, bpp, c->bigendian);
+ src += bpp;
+ if(bpp == 1) *dst8++ = p;
+ if(bpp == 2) *dst16++ = p;
+ if(bpp == 4) *dst32++ = p;
+ }
+ }
+ dst8 = c->curmask;
+ dst16 = (uint16_t*)c->curmask;
+ dst32 = (uint32_t*)c->curmask;
+ for(j = 0; j < c->cur_h; j++) {
+ for(i = 0; i < c->cur_w; i++) {
+ p = vmnc_get_pixel(src, bpp, c->bigendian);
+ src += bpp;
+ if(bpp == 1) *dst8++ = p;
+ if(bpp == 2) *dst16++ = p;
+ if(bpp == 4) *dst32++ = p;
+ }
+ }
+}
+
+static void put_cursor(uint8_t *dst, int stride, VmncContext *c, int dx, int dy)
+{
+ int i, j;
+ int w, h, x, y;
+ w = c->cur_w;
+ if(c->width < c->cur_x + c->cur_w) w = c->width - c->cur_x;
+ h = c->cur_h;
+ if(c->height < c->cur_y + c->cur_h) h = c->height - c->cur_y;
+ x = c->cur_x;
+ y = c->cur_y;
+ if(x < 0) {
+ w += x;
+ x = 0;
+ }
+ if(y < 0) {
+ h += y;
+ y = 0;
+ }
+
+ if((w < 1) || (h < 1)) return;
+ dst += x * c->bpp2 + y * stride;
+
+ if(c->bpp2 == 1) {
+ uint8_t* cd = c->curbits, *msk = c->curmask;
+ for(j = 0; j < h; j++) {
+ for(i = 0; i < w; i++)
+ dst[i] = (dst[i] & cd[i]) ^ msk[i];
+ msk += c->cur_w;
+ cd += c->cur_w;
+ dst += stride;
+ }
+ } else if(c->bpp2 == 2) {
+ uint16_t* cd = (uint16_t*)c->curbits, *msk = (uint16_t*)c->curmask;
+ uint16_t* dst2;
+ for(j = 0; j < h; j++) {
+ dst2 = (uint16_t*)dst;
+ for(i = 0; i < w; i++)
+ dst2[i] = (dst2[i] & cd[i]) ^ msk[i];
+ msk += c->cur_w;
+ cd += c->cur_w;
+ dst += stride;
+ }
+ } else if(c->bpp2 == 4) {
+ uint32_t* cd = (uint32_t*)c->curbits, *msk = (uint32_t*)c->curmask;
+ uint32_t* dst2;
+ for(j = 0; j < h; j++) {
+ dst2 = (uint32_t*)dst;
+ for(i = 0; i < w; i++)
+ dst2[i] = (dst2[i] & cd[i]) ^ msk[i];
+ msk += c->cur_w;
+ cd += c->cur_w;
+ dst += stride;
+ }
+ }
+}
+
+/* fill rectangle with given colour */
+static av_always_inline void paint_rect(uint8_t *dst, int dx, int dy, int w, int h, int color, int bpp, int stride)
+{
+ int i, j;
+ dst += dx * bpp + dy * stride;
+ if(bpp == 1){
+ for(j = 0; j < h; j++) {
+ memset(dst, color, w);
+ dst += stride;
+ }
+ }else if(bpp == 2){
+ uint16_t* dst2;
+ for(j = 0; j < h; j++) {
+ dst2 = (uint16_t*)dst;
+ for(i = 0; i < w; i++) {
+ *dst2++ = color;
+ }
+ dst += stride;
+ }
+ }else if(bpp == 4){
+ uint32_t* dst2;
+ for(j = 0; j < h; j++) {
+ dst2 = (uint32_t*)dst;
+ for(i = 0; i < w; i++) {
+ dst2[i] = color;
+ }
+ dst += stride;
+ }
+ }
+}
+
+static av_always_inline void paint_raw(uint8_t *dst, int w, int h, uint8_t* src, int bpp, int be, int stride)
+{
+ int i, j, p;
+ for(j = 0; j < h; j++) {
+ for(i = 0; i < w; i++) {
+ p = vmnc_get_pixel(src, bpp, be);
+ src += bpp;
+ switch(bpp){
+ case 1:
+ dst[i] = p;
+ break;
+ case 2:
+ ((uint16_t*)dst)[i] = p;
+ break;
+ case 4:
+ ((uint32_t*)dst)[i] = p;
+ break;
+ }
+ }
+ dst += stride;
+ }
+}
+
+static int decode_hextile(VmncContext *c, uint8_t* dst, uint8_t* src, int ssize, int w, int h, int stride)
+{
+ int i, j, k;
+ int bg = 0, fg = 0, rects, color, flags, xy, wh;
+ const int bpp = c->bpp2;
+ uint8_t *dst2;
+ int bw = 16, bh = 16;
+ uint8_t *ssrc=src;
+
+ for(j = 0; j < h; j += 16) {
+ dst2 = dst;
+ bw = 16;
+ if(j + 16 > h) bh = h - j;
+ for(i = 0; i < w; i += 16, dst2 += 16 * bpp) {
+ if(src - ssrc >= ssize) {
+ av_log(c->avctx, AV_LOG_ERROR, "Premature end of data!\n");
+ return -1;
+ }
+ if(i + 16 > w) bw = w - i;
+ flags = *src++;
+ if(flags & HT_RAW) {
+ if(src - ssrc > ssize - bw * bh * bpp) {
+ av_log(c->avctx, AV_LOG_ERROR, "Premature end of data!\n");
+ return -1;
+ }
+ paint_raw(dst2, bw, bh, src, bpp, c->bigendian, stride);
+ src += bw * bh * bpp;
+ } else {
+ if(flags & HT_BKG) {
+ bg = vmnc_get_pixel(src, bpp, c->bigendian); src += bpp;
+ }
+ if(flags & HT_FG) {
+ fg = vmnc_get_pixel(src, bpp, c->bigendian); src += bpp;
+ }
+ rects = 0;
+ if(flags & HT_SUB)
+ rects = *src++;
+ color = !!(flags & HT_CLR);
+
+ paint_rect(dst2, 0, 0, bw, bh, bg, bpp, stride);
+
+ if(src - ssrc > ssize - rects * (color * bpp + 2)) {
+ av_log(c->avctx, AV_LOG_ERROR, "Premature end of data!\n");
+ return -1;
+ }
+ for(k = 0; k < rects; k++) {
+ if(color) {
+ fg = vmnc_get_pixel(src, bpp, c->bigendian); src += bpp;
+ }
+ xy = *src++;
+ wh = *src++;
+ paint_rect(dst2, xy >> 4, xy & 0xF, (wh>>4)+1, (wh & 0xF)+1, fg, bpp, stride);
+ }
+ }
+ }
+ dst += stride * 16;
+ }
+ return src - ssrc;
+}
+
+static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size)
+{
+ VmncContext * const c = (VmncContext *)avctx->priv_data;
+ uint8_t *outptr;
+ uint8_t *src = buf;
+ int dx, dy, w, h, depth, enc, chunks, res, size_left;
+
+ c->pic.reference = 1;
+ c->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
+ if(avctx->reget_buffer(avctx, &c->pic) < 0){
+ av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
+ return -1;
+ }
+
+ c->pic.key_frame = 0;
+ c->pic.pict_type = FF_P_TYPE;
+
+ //restore screen after cursor
+ if(c->screendta) {
+ int i;
+ w = c->cur_w;
+ if(c->width < c->cur_x + w) w = c->width - c->cur_x;
+ h = c->cur_h;
+ if(c->height < c->cur_y + h) h = c->height - c->cur_y;
+ dx = c->cur_x;
+ if(dx < 0) {
+ w += dx;
+ dx = 0;
+ }
+ dy = c->cur_y;
+ if(dy < 0) {
+ h += dy;
+ dy = 0;
+ }
+ if((w > 0) && (h > 0)) {
+ outptr = c->pic.data[0] + dx * c->bpp2 + dy * c->pic.linesize[0];
+ for(i = 0; i < h; i++) {
+ memcpy(outptr, c->screendta + i * c->cur_w * c->bpp2, w * c->bpp2);
+ outptr += c->pic.linesize[0];
+ }
+ }
+ }
+ src += 2;
+ chunks = AV_RB16(src); src += 2;
+ while(chunks--) {
+ dx = AV_RB16(src); src += 2;
+ dy = AV_RB16(src); src += 2;
+ w = AV_RB16(src); src += 2;
+ h = AV_RB16(src); src += 2;
+ enc = AV_RB32(src); src += 4;
+ outptr = c->pic.data[0] + dx * c->bpp2 + dy * c->pic.linesize[0];
+ size_left = buf_size - (src - buf);
+ switch(enc) {
+ case MAGIC_WMVd: // cursor
+ if(size_left < 2 + w * h * c->bpp2 * 2) {
+ av_log(avctx, AV_LOG_ERROR, "Premature end of data! (need %i got %i)\n", 2 + w * h * c->bpp2 * 2, size_left);
+ return -1;
+ }
+ src += 2;
+ c->cur_w = w;
+ c->cur_h = h;
+ c->cur_hx = dx;
+ c->cur_hy = dy;
+ if((c->cur_hx > c->cur_w) || (c->cur_hy > c->cur_h)) {
+ av_log(avctx, AV_LOG_ERROR, "Cursor hot spot is not in image: %ix%i of %ix%i cursor size\n", c->cur_hx, c->cur_hy, c->cur_w, c->cur_h);
+ c->cur_hx = c->cur_hy = 0;
+ }
+ c->curbits = av_realloc(c->curbits, c->cur_w * c->cur_h * c->bpp2);
+ c->curmask = av_realloc(c->curmask, c->cur_w * c->cur_h * c->bpp2);
+ c->screendta = av_realloc(c->screendta, c->cur_w * c->cur_h * c->bpp2);
+ load_cursor(c, src);
+ src += w * h * c->bpp2 * 2;
+ break;
+ case MAGIC_WMVe: // unknown
+ src += 2;
+ break;
+ case MAGIC_WMVf: // update cursor position
+ c->cur_x = dx - c->cur_hx;
+ c->cur_y = dy - c->cur_hy;
+ break;
+ case MAGIC_WMVg: // unknown
+ src += 10;
+ break;
+ case MAGIC_WMVh: // unknown
+ src += 4;
+ break;
+ case MAGIC_WMVi: // ServerInitialization struct
+ c->pic.key_frame = 1;
+ c->pic.pict_type = FF_I_TYPE;
+ depth = *src++;
+ if(depth != c->bpp) {
+ av_log(avctx, AV_LOG_INFO, "Depth mismatch. Container %i bpp, Frame data: %i bpp\n", c->bpp, depth);
+ }
+ src++;
+ c->bigendian = *src++;
+ if(c->bigendian & (~1)) {
+ av_log(avctx, AV_LOG_INFO, "Invalid header: bigendian flag = %i\n", c->bigendian);
+ return -1;
+ }
+ //skip the rest of pixel format data
+ src += 13;
+ break;
+ case MAGIC_WMVj: // unknown
+ src += 2;
+ break;
+ case 0x00000000: // raw rectangle data
+ if((dx + w > c->width) || (dy + h > c->height)) {
+ av_log(avctx, AV_LOG_ERROR, "Incorrect frame size: %ix%i+%ix%i of %ix%i\n", w, h, dx, dy, c->width, c->height);
+ return -1;
+ }
+ if(size_left < w * h * c->bpp2) {
+ av_log(avctx, AV_LOG_ERROR, "Premature end of data! (need %i got %i)\n", w * h * c->bpp2, size_left);
+ return -1;
+ }
+ paint_raw(outptr, w, h, src, c->bpp2, c->bigendian, c->pic.linesize[0]);
+ src += w * h * c->bpp2;
+ break;
+ case 0x00000005: // HexTile encoded rectangle
+ if((dx + w > c->width) || (dy + h > c->height)) {
+ av_log(avctx, AV_LOG_ERROR, "Incorrect frame size: %ix%i+%ix%i of %ix%i\n", w, h, dx, dy, c->width, c->height);
+ return -1;
+ }
+ res = decode_hextile(c, outptr, src, size_left, w, h, c->pic.linesize[0]);
+ if(res < 0)
+ return -1;
+ src += res;
+ break;
+ default:
+ av_log(avctx, AV_LOG_ERROR, "Unsupported block type 0x%08X\n", enc);
+ chunks = 0; // leave chunks decoding loop
+ }
+ }
+ if(c->screendta){
+ int i;
+ //save screen data before painting cursor
+ w = c->cur_w;
+ if(c->width < c->cur_x + w) w = c->width - c->cur_x;
+ h = c->cur_h;
+ if(c->height < c->cur_y + h) h = c->height - c->cur_y;
+ dx = c->cur_x;
+ if(dx < 0) {
+ w += dx;
+ dx = 0;
+ }
+ dy = c->cur_y;
+ if(dy < 0) {
+ h += dy;
+ dy = 0;
+ }
+ if((w > 0) && (h > 0)) {
+ outptr = c->pic.data[0] + dx * c->bpp2 + dy * c->pic.linesize[0];
+ for(i = 0; i < h; i++) {
+ memcpy(c->screendta + i * c->cur_w * c->bpp2, outptr, w * c->bpp2);
+ outptr += c->pic.linesize[0];
+ }
+ outptr = c->pic.data[0];
+ put_cursor(outptr, c->pic.linesize[0], c, c->cur_x, c->cur_y);
+ }
+ }
+ *data_size = sizeof(AVFrame);
+ *(AVFrame*)data = c->pic;
+
+ /* always report that the buffer was completely consumed */
+ return buf_size;
+}
+
+
+
+/*
+ *
+ * Init VMnc decoder
+ *
+ */
+static int decode_init(AVCodecContext *avctx)
+{
+ VmncContext * const c = (VmncContext *)avctx->priv_data;
+
+ c->avctx = avctx;
+
+ c->pic.data[0] = NULL;
+ 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_sample;
+ c->bpp2 = c->bpp/8;
+
+ switch(c->bpp){
+ case 8:
+ avctx->pix_fmt = PIX_FMT_PAL8;
+ break;
+ case 16:
+ avctx->pix_fmt = PIX_FMT_RGB555;
+ break;
+ case 32:
+ avctx->pix_fmt = PIX_FMT_RGB32;
+ break;
+ default:
+ av_log(avctx, AV_LOG_ERROR, "Unsupported bitdepth %i\n", c->bpp);
+ }
+
+ return 0;
+}
+
+
+
+/*
+ *
+ * Uninit VMnc decoder
+ *
+ */
+static int decode_end(AVCodecContext *avctx)
+{
+ VmncContext * const c = (VmncContext *)avctx->priv_data;
+
+ if (c->pic.data[0])
+ avctx->release_buffer(avctx, &c->pic);
+
+ av_free(c->curbits);
+ av_free(c->curmask);
+ av_free(c->screendta);
+ return 0;
+}
+
+AVCodec vmnc_decoder = {
+ "VMware video",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_VMNC,
+ sizeof(VmncContext),
+ decode_init,
+ NULL,
+ decode_end,
+ decode_frame
+};
+
diff --git a/contrib/ffmpeg/libavcodec/vorbis.c b/contrib/ffmpeg/libavcodec/vorbis.c
new file mode 100644
index 000000000..7e5f0d349
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/vorbis.c
@@ -0,0 +1,1790 @@
+/**
+ * @file vorbis.c
+ * 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
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 V_DEBUG
+//#define V_DEBUG
+//#define AV_DEBUG(...) av_log(NULL, AV_LOG_INFO, __VA_ARGS__)
+
+#include <math.h>
+
+#define ALT_BITSTREAM_READER_LE
+#include "avcodec.h"
+#include "bitstream.h"
+#include "dsputil.h"
+
+#include "vorbis.h"
+#include "xiph.h"
+
+#define V_NB_BITS 8
+#define V_NB_BITS2 11
+#define V_MAX_VLCS (1<<16)
+
+#ifndef V_DEBUG
+#define AV_DEBUG(...)
+#endif
+
+#undef NDEBUG
+#include <assert.h>
+
+typedef struct {
+ uint_fast8_t dimensions;
+ uint_fast8_t lookup_type;
+ uint_fast8_t maxdepth;
+ VLC vlc;
+ float *codevectors;
+ unsigned int nb_bits;
+} vorbis_codebook;
+
+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;
+typedef
+uint_fast8_t (* vorbis_floor_decode_func)
+ (struct vorbis_context_s *, vorbis_floor_data *, float *);
+typedef struct {
+ uint_fast8_t floor_type;
+ vorbis_floor_decode_func decode;
+ 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];
+ 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;
+ } t0;
+ struct vorbis_floor1_s
+ {
+ uint_fast8_t partitions;
+ uint_fast8_t maximum_class;
+ uint_fast8_t partition_class[32];
+ uint_fast8_t class_dimensions[16];
+ uint_fast8_t class_subclasses[16];
+ uint_fast8_t class_masterbook[16];
+ int_fast16_t subclass_books[16][8];
+ uint_fast8_t multiplier;
+ uint_fast16_t x_list_dim;
+ floor1_entry_t * list;
+ } t1;
+ } data;
+} vorbis_floor;
+
+typedef struct {
+ uint_fast16_t type;
+ 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;
+} vorbis_residue;
+
+typedef struct {
+ 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];
+} vorbis_mapping;
+
+typedef struct {
+ uint_fast8_t blockflag;
+ uint_fast16_t windowtype;
+ uint_fast16_t transformtype;
+ uint_fast8_t mapping;
+} vorbis_mode;
+
+typedef struct vorbis_context_s {
+ AVCodecContext *avccontext;
+ GetBitContext gb;
+ DSPContext dsp;
+
+ MDCTContext mdct[2];
+ uint_fast8_t first_frame;
+ uint_fast32_t version;
+ 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];
+ uint_fast16_t codebook_count;
+ vorbis_codebook *codebooks;
+ uint_fast8_t floor_count;
+ vorbis_floor *floors;
+ uint_fast8_t residue_count;
+ vorbis_residue *residues;
+ 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
+ float *channel_residues;
+ float *channel_floors;
+ float *saved;
+ uint_fast16_t saved_start;
+ float *ret;
+ float *buf;
+ float *buf_tmp;
+ uint_fast32_t add_bias; // for float->int conversion
+ uint_fast32_t exp_bias;
+} vorbis_context;
+
+/* Helper functions */
+
+#define BARK(x) \
+ (13.1f*atan(0.00074f*(x))+2.24f*atan(1.85e-8f*(x)*(x))+1e-4f*(x))
+
+unsigned int ff_vorbis_nth_root(unsigned int x, unsigned int n) { // x^(1/n)
+ unsigned int ret=0, i, j;
+
+ do {
+ ++ret;
+ for(i=0,j=ret;i<n-1;i++) j*=ret;
+ } while (j<=x);
+
+ return (ret-1);
+}
+
+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));
+}
+
+
+// Generate vlc codes from vorbis huffman code lengths
+
+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;
+
+#ifdef V_DEBUG
+ GetBitContext gb;
+#endif
+
+ for(p=0;(bits[p]==0) && (p<num);++p);
+ if (p==num) {
+// av_log(vc->avccontext, AV_LOG_INFO, "An empty codebook. Heh?! \n");
+ return 0;
+ }
+
+ codes[p]=0;
+ 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<bits[p];++i) {
+ av_log(NULL, AV_LOG_INFO, "%s", get_bits1(&gb) ? "1" : "0");
+ }
+ av_log(NULL, AV_LOG_INFO, "\n");
+#endif
+
+ ++p;
+
+ for(;p<num;++p) {
+ 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;
+ // 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;
+
+#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<bits[p];++i) {
+ av_log(NULL, AV_LOG_INFO, "%s", get_bits1(&gb) ? "1" : "0");
+ }
+ av_log(NULL, AV_LOG_INFO, "\n");
+#endif
+
+ }
+
+ //no exits should be left (underspecified tree - ie. unused valid vlcs - not allowed by SPEC)
+ for (p=1; p<33; p++)
+ if (exit_at_level[p]) return 1;
+
+ return 0;
+}
+
+void ff_vorbis_ready_floor1_list(floor1_entry_t * list, int values) {
+ int i;
+ list[0].sort = 0;
+ list[1].sort = 1;
+ for (i = 2; i < values; i++) {
+ int j;
+ list[i].low = 0;
+ list[i].high = 1;
+ list[i].sort = i;
+ for (j = 2; j < i; j++) {
+ int tmp = list[j].x;
+ if (tmp < list[i].x) {
+ if (tmp > list[list[i].low].x) list[i].low = j;
+ } else {
+ if (tmp < list[list[i].high].x) list[i].high = j;
+ }
+ }
+ }
+ for (i = 0; i < values - 1; i++) {
+ int j;
+ for (j = i + 1; j < values; j++) {
+ if (list[list[i].sort].x > list[list[j].sort].x) {
+ int tmp = list[i].sort;
+ list[i].sort = list[j].sort;
+ list[j].sort = tmp;
+ }
+ }
+ }
+}
+
+// Free all allocated memory -----------------------------------------
+
+static void vorbis_free(vorbis_context *vc) {
+ int_fast16_t i;
+
+ av_freep(&vc->channel_residues);
+ av_freep(&vc->channel_floors);
+ av_freep(&vc->saved);
+ av_freep(&vc->ret);
+ av_freep(&vc->buf);
+ av_freep(&vc->buf_tmp);
+
+ av_freep(&vc->residues);
+ av_freep(&vc->modes);
+
+ ff_mdct_end(&vc->mdct[0]);
+ ff_mdct_end(&vc->mdct[1]);
+
+ 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;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 {
+ av_free(vc->floors[i].data.t1.list);
+ }
+ }
+ av_freep(&vc->floors);
+
+ 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);
+ }
+ av_freep(&vc->mappings);
+
+ if(vc->exp_bias){
+ av_freep(&vc->win[0]);
+ av_freep(&vc->win[1]);
+ }
+}
+
+// Parse setup header -------------------------------------------------
+
+// Process codebooks part
+
+static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc) {
+ uint_fast16_t cb;
+ uint8_t *tmp_vlc_bits;
+ uint32_t *tmp_vlc_codes;
+ GetBitContext *gb=&vc->gb;
+
+ vc->codebook_count=get_bits(gb,8)+1;
+
+ AV_DEBUG(" Codebooks: %d \n", vc->codebook_count);
+
+ vc->codebooks=(vorbis_codebook *)av_mallocz(vc->codebook_count * sizeof(vorbis_codebook));
+ tmp_vlc_bits=(uint8_t *)av_mallocz(V_MAX_VLCS * sizeof(uint8_t));
+ tmp_vlc_codes=(uint32_t *)av_mallocz(V_MAX_VLCS * sizeof(uint32_t));
+
+ 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 entries;
+
+ AV_DEBUG(" %d. Codebook \n", cb);
+
+ 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);
+ goto error;
+ }
+ 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);
+
+ 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);
+
+ AV_DEBUG(" not ordered \n");
+
+ if (sparse) {
+ AV_DEBUG(" sparse \n");
+
+ used_entries=0;
+ for(ce=0;ce<entries;++ce) {
+ flag=get_bits1(gb);
+ if (flag) {
+ tmp_vlc_bits[ce]=get_bits(gb, 5)+1;
+ ++used_entries;
+ }
+ else tmp_vlc_bits[ce]=0;
+ }
+ } else {
+ AV_DEBUG(" not sparse \n");
+
+ used_entries=entries;
+ for(ce=0;ce<entries;++ce) {
+ tmp_vlc_bits[ce]=get_bits(gb, 5)+1;
+ }
+ }
+ } else {
+ uint_fast16_t current_entry=0;
+ uint_fast8_t current_length=get_bits(gb, 5)+1;
+
+ AV_DEBUG(" ordered, current length: %d \n", current_length); //FIXME
+
+ used_entries=entries;
+ for(;current_entry<used_entries;++current_length) {
+ uint_fast16_t i, number;
+
+ AV_DEBUG(" number bits: %d ", ilog(entries - current_entry));
+
+ number=get_bits(gb, ilog(entries - current_entry));
+
+ AV_DEBUG(" number: %d \n", number);
+
+ for(i=current_entry;i<number+current_entry;++i) {
+ if (i<used_entries) tmp_vlc_bits[i]=current_length;
+ }
+
+ current_entry+=number;
+ }
+ if (current_entry>used_entries) {
+ av_log(vc->avccontext, AV_LOG_ERROR, " More codelengths than codes in codebook. \n");
+ goto error;
+ }
+ }
+
+ 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" );
+
+// If the codebook is used for (inverse) VQ, calculate codevectors.
+
+ 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_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);
+
+ 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;i<codebook_lookup_values;++i) {
+ codebook_multiplicands[i]=get_bits(gb, codebook_value_bits);
+
+ AV_DEBUG(" multiplicands*delta+minmum : %e \n", (float)codebook_multiplicands[i]*codebook_delta_value+codebook_minimum_value);
+ AV_DEBUG(" multiplicand %d \n", codebook_multiplicands[i]);
+ }
+
+// Weed out unused vlcs and build codevector vector
+ codebook_setup->codevectors=(float *)av_mallocz(used_entries*codebook_setup->dimensions * sizeof(float));
+ 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;
+
+#ifdef V_DEBUG
+ av_log(vc->avccontext, AV_LOG_INFO, "Lookup offset %d ,", i);
+#endif
+
+ for(k=0;k<dim;++k) {
+ uint_fast32_t multiplicand_offset = lookup_offset % codebook_lookup_values;
+ 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];
+
+#ifdef V_DEBUG
+ av_log(vc->avccontext, AV_LOG_INFO, "real lookup offset %d, vector: ", j);
+ 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) {
+ 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) {
+ av_log(vc->avccontext, AV_LOG_ERROR, "Codebook lookup type not supported. \n");
+ goto error;
+ }
+
+// Initialize VLC table
+ if (ff_vorbis_len2vlc(tmp_vlc_bits, tmp_vlc_codes, entries)) {
+ av_log(vc->avccontext, AV_LOG_ERROR, " Invalid code lengths while generating vlcs. \n");
+ goto error;
+ }
+ 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;
+
+ 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");
+ goto error;
+ }
+ }
+
+ av_free(tmp_vlc_bits);
+ av_free(tmp_vlc_codes);
+ return 0;
+
+// Error:
+error:
+ av_free(tmp_vlc_bits);
+ av_free(tmp_vlc_codes);
+ 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;
+ uint_fast8_t i;
+ uint_fast8_t vorbis_time_count=get_bits(gb, 6)+1;
+
+ for(i=0;i<vorbis_time_count;++i) {
+ uint_fast16_t vorbis_tdtransform=get_bits(gb, 16);
+
+ AV_DEBUG(" Vorbis time domain transform %d: %d \n", vorbis_time_count, vorbis_tdtransform);
+
+ if (vorbis_tdtransform) {
+ av_log(vc->avccontext, AV_LOG_ERROR, "Vorbis time domain transform data nonzero. \n");
+ return 1;
+ }
+ }
+ return 0;
+}
+
+// Process floors part
+
+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 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;
+ uint_fast16_t i,j,k;
+
+ vc->floor_count=get_bits(gb, 6)+1;
+
+ vc->floors=(vorbis_floor *)av_mallocz(vc->floor_count * sizeof(vorbis_floor));
+
+ for (i=0;i<vc->floor_count;++i) {
+ vorbis_floor *floor_setup=&vc->floors[i];
+
+ 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;
+
+ floor_setup->decode=vorbis_floor1_decode;
+
+ 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;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]);
+
+ }
+
+ AV_DEBUG(" maximum class %d \n", 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);
+
+ 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);
+
+ AV_DEBUG(" masterbook: %d \n", floor_setup->data.t1.class_masterbook[j]);
+ }
+
+ for(k=0;k<(1<<floor_setup->data.t1.class_subclasses[j]);++k) {
+ floor_setup->data.t1.subclass_books[j][k]=(int16_t)get_bits(gb, 8)-1;
+
+ 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;
+
+ 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=(floor1_entry_t *)av_mallocz(floor_setup->data.t1.x_list_dim * sizeof(floor1_entry_t));
+
+
+ rangebits=get_bits(gb, 4);
+ floor_setup->data.t1.list[0].x = 0;
+ floor_setup->data.t1.list[1].x = (1<<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);
+ }
+ }
+
+// 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;
+
+ 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);
+ /* 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;
+ }
+ 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=
+ av_malloc(floor_setup->data.t0.num_books);
+ if(!floor_setup->data.t0.book_list) { return 1; }
+ /* read book indexes */
+ {
+ int idx;
+ uint_fast8_t book_idx;
+ for (idx=0;idx<floor_setup->data.t0.num_books;++idx) {
+ book_idx=get_bits(gb, 8);
+ floor_setup->data.t0.book_list[idx]=book_idx;
+ 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;
+ }
+ }
+
+ 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=
+ av_malloc((floor_setup->data.t0.order+1 + max_codebook_dim)
+ * sizeof(float));
+ if(!floor_setup->data.t0.lsp) { return 1; }
+ }
+
+#ifdef V_DEBUG /* debug output parsed headers */
+ AV_DEBUG("floor0 order: %u\n", floor_setup->data.t0.order);
+ AV_DEBUG("floor0 rate: %u\n", floor_setup->data.t0.rate);
+ AV_DEBUG("floor0 bark map size: %u\n",
+ floor_setup->data.t0.bark_map_size);
+ AV_DEBUG("floor0 amplitude bits: %u\n",
+ floor_setup->data.t0.amplitude_bits);
+ AV_DEBUG("floor0 amplitude offset: %u\n",
+ floor_setup->data.t0.amplitude_offset);
+ AV_DEBUG("floor0 number of books: %u\n",
+ floor_setup->data.t0.num_books);
+ AV_DEBUG("floor0 book list pointer: %p\n",
+ floor_setup->data.t0.book_list);
+ {
+ int 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 {
+ av_log(vc->avccontext, AV_LOG_ERROR, "Invalid floor type!\n");
+ return 1;
+ }
+ }
+ return 0;
+}
+
+// Process residues part
+
+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=(vorbis_residue *)av_mallocz(vc->residue_count * sizeof(vorbis_residue));
+
+ AV_DEBUG(" There are %d residues. \n", vc->residue_count);
+
+ 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);
+
+ 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);
+
+ 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;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;j<res_setup->classifications;++j) {
+ for(k=0;k<8;++k) {
+ if (cascade[j]&(1<<k)) {
+ res_setup->books[j][k]=get_bits(gb, 8);
+
+ 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;
+ }
+ } else {
+ res_setup->books[j][k]=-1;
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+// Process mappings part
+
+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=(vorbis_mapping *)av_mallocz(vc->mapping_count * sizeof(vorbis_mapping));
+
+ AV_DEBUG(" There are %d mappings. \n", vc->mapping_count);
+
+ 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;
+ }
+ if (get_bits1(gb)) {
+ mapping_setup->submaps=get_bits(gb, 4)+1;
+ } else {
+ mapping_setup->submaps=1;
+ }
+
+ if (get_bits1(gb)) {
+ mapping_setup->coupling_steps=get_bits(gb, 8)+1;
+ mapping_setup->magnitude=(uint_fast8_t *)av_mallocz(mapping_setup->coupling_steps * sizeof(uint_fast8_t));
+ mapping_setup->angle=(uint_fast8_t *)av_mallocz(mapping_setup->coupling_steps * sizeof(uint_fast8_t));
+ for(j=0;j<mapping_setup->coupling_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
+ }
+ } else {
+ mapping_setup->coupling_steps=0;
+ }
+
+ AV_DEBUG(" %d mapping coupling steps: %d \n", i, mapping_setup->coupling_steps);
+
+ if(get_bits(gb, 2)) {
+ av_log(vc->avccontext, AV_LOG_ERROR, "%d. mapping setup data invalid. \n", i);
+ return 1; // following spec.
+ }
+
+ if (mapping_setup->submaps>1) {
+ mapping_setup->mux=(uint_fast8_t *)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;j<mapping_setup->submaps;++j) {
+ get_bits(gb, 8); // FIXME check?
+ mapping_setup->submap_floor[j]=get_bits(gb, 8);
+ mapping_setup->submap_residue[j]=get_bits(gb, 8);
+
+ AV_DEBUG(" %d mapping %d submap : floor %d, residue %d \n", i, j, mapping_setup->submap_floor[j], mapping_setup->submap_residue[j]);
+ }
+ }
+ return 0;
+}
+
+// Process modes part
+
+static void create_map( vorbis_context * vc, uint_fast8_t floor_number )
+{
+ vorbis_floor * floors=vc->floors;
+ vorbis_floor0 * vf;
+ int idx;
+ int_fast8_t blockflag;
+ 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
+
+ map=floors[floor_number].data.t0.map[blockflag];
+ vf=&floors[floor_number].data.t0;
+
+ 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;
+ }
+
+# ifdef V_DEBUG
+ 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;
+ uint_fast8_t i;
+
+ vc->mode_count=get_bits(gb, 6)+1;
+ vc->modes=(vorbis_mode *)av_mallocz(vc->mode_count * sizeof(vorbis_mode));
+
+ AV_DEBUG(" There are %d modes.\n", vc->mode_count);
+
+ for(i=0;i<vc->mode_count;++i) {
+ vorbis_mode *mode_setup=&vc->modes[i];
+
+ mode_setup->blockflag=get_bits(gb, 1);
+ 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
+
+ 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);
+ }
+ return 0;
+}
+
+// Process the whole setup header using the functions above
+
+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')) {
+ av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (no vorbis signature). \n");
+ 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;
+ }
+ 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;
+ }
+ if (vorbis_parse_setup_hdr_floors(vc)) {
+ av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (floors). \n");
+ 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;
+ }
+ if (vorbis_parse_setup_hdr_mappings(vc)) {
+ av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (mappings). \n");
+ 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;
+ }
+ 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 0;
+}
+
+// Process the identification header
+
+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')) {
+ av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (no vorbis signature). \n");
+ 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<<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;
+ }
+ // output format int16
+ 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;
+ }
+ vc->win[0]=ff_vorbis_vwin[bl0-6];
+ vc->win[1]=ff_vorbis_vwin[bl1-6];
+
+ if(vc->exp_bias){
+ int i, j;
+ for(j=0; j<2; j++){
+ float *win = av_malloc(vc->blocksize[j]/2 * sizeof(float));
+ for(i=0; i<vc->blocksize[j]/2; i++)
+ win[i] = vc->win[j][i] * (1<<15);
+ vc->win[j] = win;
+ }
+ }
+
+ if ((get_bits1(gb)) == 0) {
+ av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (framing flag not set). \n");
+ return 2;
+ }
+
+ vc->channel_residues=(float *)av_malloc((vc->blocksize[1]/2)*vc->audio_channels * sizeof(float));
+ vc->channel_floors=(float *)av_malloc((vc->blocksize[1]/2)*vc->audio_channels * sizeof(float));
+ vc->saved=(float *)av_malloc((vc->blocksize[1]/2)*vc->audio_channels * sizeof(float));
+ vc->ret=(float *)av_malloc((vc->blocksize[1]/2)*vc->audio_channels * sizeof(float));
+ vc->buf=(float *)av_malloc(vc->blocksize[1] * sizeof(float));
+ vc->buf_tmp=(float *)av_malloc(vc->blocksize[1] * sizeof(float));
+ vc->saved_start=0;
+
+ ff_mdct_init(&vc->mdct[0], bl0, 1);
+ ff_mdct_init(&vc->mdct[1], bl1, 1);
+
+ 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;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)));
+ }
+*/
+
+ return 0;
+}
+
+// Process the extradata using the functions above (identification header, setup header)
+
+static 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 *header_start[3];
+ int header_len[3];
+ GetBitContext *gb = &(vc->gb);
+ int hdr_type;
+
+ vc->avccontext = avccontext;
+ dsputil_init(&vc->dsp, avccontext);
+
+ if(vc->dsp.float_to_int16 == ff_float_to_int16_c) {
+ vc->add_bias = 385;
+ vc->exp_bias = 0;
+ } else {
+ vc->add_bias = 0;
+ vc->exp_bias = 15<<23;
+ }
+
+ if (!headers_len) {
+ av_log(avccontext, AV_LOG_ERROR, "Extradata corrupt.\n");
+ return -1;
+ }
+
+ if (ff_split_xiph_headers(headers, headers_len, 30, header_start, header_len) < 0) {
+ av_log(avccontext, AV_LOG_ERROR, "Extradata corrupt.\n");
+ return -1;
+ }
+
+ init_get_bits(gb, header_start[0], header_len[0]*8);
+ 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;
+ }
+ if (vorbis_parse_id_hdr(vc)) {
+ av_log(avccontext, AV_LOG_ERROR, "Id header corrupt.\n");
+ vorbis_free(vc);
+ return -1;
+ }
+
+ init_get_bits(gb, header_start[2], header_len[2]*8);
+ hdr_type=get_bits(gb, 8);
+ if (hdr_type!=5) {
+ av_log(avccontext, AV_LOG_ERROR, "Third header is not the setup header.\n");
+ return -1;
+ }
+ if (vorbis_parse_setup_hdr(vc)) {
+ av_log(avccontext, AV_LOG_ERROR, "Setup header corrupt.\n");
+ vorbis_free(vc);
+ return -1;
+ }
+
+ avccontext->channels = vc->audio_channels;
+ avccontext->sample_rate = vc->audio_samplerate;
+
+ return 0 ;
+}
+
+// Decode audiopackets -------------------------------------------------
+
+// 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;
+ uint_fast32_t amplitude;
+ uint_fast32_t book_idx;
+ uint_fast8_t blockflag=vc->modes[vc->mode_number].blockflag;
+
+ 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" );
+ //FIXME: look above
+ }
+ AV_DEBUG( "floor0 dec: booknumber: %u\n", book_idx );
+ codebook=vc->codebooks[vf->book_list[book_idx]];
+
+ while (lsp_len<vf->order) {
+ int vec_off;
+
+ 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 );
+ /* copy each vector component and add last to it */
+ for (idx=0; idx<codebook.dimensions; ++idx) {
+ lsp[lsp_len+idx]=codebook.codevectors[vec_off+idx]+last;
+ }
+ last=lsp[lsp_len+idx-1]; /* set last to last vector component */
+
+ lsp_len += codebook.dimensions;
+ }
+#ifdef V_DEBUG
+ /* DEBUG: output lsp coeffs */
+ {
+ int idx;
+ for ( idx = 0; idx < lsp_len; ++idx )
+ AV_DEBUG("floor0 dec: coeff at %d is %f\n", idx, lsp[idx] );
+ }
+#endif
+
+ /* synthesize floor output vector */
+ {
+ int i;
+ int order=vf->order;
+ float wstep=M_PI/vf->bark_map_size;
+
+ for(i=0;i<order;i++) { lsp[i]=2.0f*cos(lsp[i]); }
+
+ AV_DEBUG("floor0 synth: map_size=%d; m=%d; wstep=%f\n",
+ vf->map_size, order, wstep);
+
+ 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<order;j+=2) {
+ q *= lsp[j] -two_cos_w;
+ p *= lsp[j+1]-two_cos_w;
+ }
+ if(j==order) { // even order
+ p *= p*(2.0f-two_cos_w);
+ q *= q*(2.0f+two_cos_w);
+ }
+ else { // odd order
+ q *= two_cos_w-lsp[j]; // one more time for q
+
+ /* final step and square */
+ p *= p*(4.f-two_cos_w*two_cos_w);
+ q *= q;
+ }
+
+ /* calculate linear floor value */
+ {
+ 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);
+ }
+ }
+ }
+ else {
+ /* this channel is unused */
+ return 1;
+ }
+
+ AV_DEBUG(" Floor0 decoded\n");
+
+ return 0;
+}
+
+static void render_line(int x0, int y0, int x1, int y1, float * buf, int n) {
+ int dy = y1 - y0;
+ int adx = x1 - x0;
+ int ady = FFABS(dy);
+ int base = dy / adx;
+ int x = x0;
+ int y = y0;
+ int err = 0;
+ int sy;
+ if (dy < 0) sy = base - 1;
+ else sy = base + 1;
+ ady = ady - FFABS(base) * adx;
+ if (x >= n) return;
+ buf[x] = ff_vorbis_floor1_inverse_db_table[y];
+ for (x = x0 + 1; x < x1; x++) {
+ if (x >= n) return;
+ err += ady;
+ if (err >= adx) {
+ err -= adx;
+ y += sy;
+ } else {
+ y += base;
+ }
+ buf[x] = ff_vorbis_floor1_inverse_db_table[y];
+ }
+}
+
+void ff_vorbis_floor1_render_list(floor1_entry_t * 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;
+ for (i = 1; i < values; i++) {
+ int pos = list[i].sort;
+ if (flag[pos]) {
+ render_line(lx, ly, list[pos].x, y_list[pos] * multiplier, out, samples);
+ lx = list[pos].x;
+ ly = y_list[pos] * multiplier;
+ }
+ if (lx >= samples) break;
+ }
+ if (lx < samples) render_line(lx, ly, samples, ly, out, samples);
+}
+
+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];
+ uint_fast8_t class_;
+ uint_fast8_t cdim;
+ uint_fast8_t cbits;
+ uint_fast8_t csub;
+ uint_fast8_t cval;
+ 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 ?
+ int_fast16_t dy, err;
+
+
+ if (!get_bits1(gb)) return 1; // silence
+
+// 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));
+
+ AV_DEBUG("floor 0 Y %d floor 1 Y %d \n", floor1_Y[0], floor1_Y[1]);
+
+ offset=2;
+ for(i=0;i<vf->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);
+ }
+
+ 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,
+ vc->codebooks[book].nb_bits, 3);
+ } else {
+ floor1_Y[offset+j]=0;
+ }
+
+ AV_DEBUG(" floor(%d) = %d \n", vf->list[offset+j].x, floor1_Y[offset+j]);
+ }
+ offset+=cdim;
+ }
+
+// 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];
+
+ 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;
+ } else {
+ predicted=floor1_Y_final[low_neigh_offs]+off;
+ } // render_point end
+
+ val=floor1_Y[i];
+ highroom=range-predicted;
+ lowroom=predicted;
+ if (highroom < lowroom) {
+ room=highroom*2;
+ } else {
+ 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) {
+ if (highroom > lowroom) {
+ floor1_Y_final[i]=val-lowroom+predicted;
+ } else {
+ floor1_Y_final[i]=predicted-val+highroom-1;
+ }
+ } else {
+ if (val & 1) {
+ floor1_Y_final[i]=predicted-(val+1)/2;
+ } else {
+ floor1_Y_final[i]=predicted+val/2;
+ }
+ }
+ } else {
+ 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);
+ }
+
+// Curve synth - connect the calculated dots and convert from dB scale FIXME optimize ?
+
+ ff_vorbis_floor1_render_list(vf->list, vf->x_list_dim, floor1_Y_final, floor1_flag, vf->multiplier, vec, vf->list[1].x);
+
+ AV_DEBUG(" Floor decoded\n");
+
+ return 0;
+}
+
+// Read and decode residue
+
+static 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) {
+ 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;j<ch;++j) {
+ do_not_decode[0]&=do_not_decode[j]; // FIXME - clobbering input
+ }
+ if (do_not_decode[0]) return 0;
+ ch_used=1;
+ } else {
+ ch_used=ch;
+ }
+
+ AV_DEBUG(" residue type 0/1/2 decode begin, ch: %d cpc %d \n", ch, c_p_c);
+
+ 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_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;j<ch_used;++j) {
+ if (!do_not_decode[j]) {
+ 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;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;
+ }
+ }
+ j_times_ptns_to_read+=ptns_to_read;
+ }
+ }
+ for(i=0;(i<c_p_c) && (partition_count<ptns_to_read);++i) {
+ for(j_times_ptns_to_read=0, j=0;j<ch_used;++j) {
+ uint_fast16_t voffs;
+
+ if (!do_not_decode[j]) {
+ uint_fast8_t vqclass=classifs[j_times_ptns_to_read+partition_count];
+ int_fast16_t vqbook=vr->books[vqclass][pass];
+
+ if (vqbook>=0) {
+ 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];
+
+ if (vr->type==0) {
+
+ voffs=voffset+j*vlen;
+ for(k=0;k<step;++k) {
+ coffs=get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * dim;
+ for(l=0;l<dim;++l) {
+ vec[voffs+k+l*step]+=codebook.codevectors[coffs+l]; // FPMATH
+ }
+ }
+ }
+ else if (vr->type==1) {
+ voffs=voffset+j*vlen;
+ for(k=0;k<step;++k) {
+ coffs=get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * dim;
+ for(l=0;l<dim;++l, ++voffs) {
+ vec[voffs]+=codebook.codevectors[coffs+l]; // FPMATH
+
+ AV_DEBUG(" pass %d offs: %d curr: %f change: %f cv offs.: %d \n", pass, voffs, vec[voffs], codebook.codevectors[coffs+l], coffs);
+ }
+ }
+ }
+ 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;k<step;++k) {
+ coffs=get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * 2;
+ vec[voffs+k ]+=codebook.codevectors[coffs ]; // FPMATH
+ vec[voffs+k+vlen]+=codebook.codevectors[coffs+1]; // FPMATH
+ }
+ } else
+ for(k=0;k<step;++k) {
+ coffs=get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * dim;
+ for(l=0;l<dim;l+=2, voffs++) {
+ vec[voffs ]+=codebook.codevectors[coffs+l ]; // FPMATH
+ vec[voffs+vlen]+=codebook.codevectors[coffs+l+1]; // FPMATH
+
+ AV_DEBUG(" pass %d offs: %d curr: %f change: %f cv offs.: %d+%d \n", pass, voffset/ch+(voffs%ch)*vlen, vec[voffset/ch+(voffs%ch)*vlen], codebook.codevectors[coffs+l], coffs, l);
+ }
+ }
+
+ }
+ else if (vr->type==2) {
+ voffs=voffset;
+
+ for(k=0;k<step;++k) {
+ coffs=get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * dim;
+ for(l=0;l<dim;++l, ++voffs) {
+ vec[voffs/ch+(voffs%ch)*vlen]+=codebook.codevectors[coffs+l]; // FPMATH FIXME use if and counter instead of / and %
+
+ AV_DEBUG(" pass %d offs: %d curr: %f change: %f cv offs.: %d+%d \n", pass, voffset/ch+(voffs%ch)*vlen, vec[voffset/ch+(voffs%ch)*vlen], codebook.codevectors[coffs+l], coffs, l);
+ }
+ }
+ } else {
+ av_log(vc->avccontext, AV_LOG_ERROR, " Invalid residue type while residue decode?! \n");
+ return 1;
+ }
+ }
+ }
+ j_times_ptns_to_read+=ptns_to_read;
+ }
+ ++partition_count;
+ voffset+=vr->partition_size;
+ }
+ }
+ }
+ return 0;
+}
+
+void vorbis_inverse_coupling(float *mag, float *ang, int blocksize)
+{
+ int 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;
+ }
+ } else {
+ if (ang[i]>0.0) {
+ ang[i]+=mag[i];
+ } else {
+ float temp=ang[i];
+ ang[i]=mag[i];
+ mag[i]-=temp;
+ }
+ }
+ }
+}
+
+// Decode the audio packet using the functions above
+
+static int vorbis_parse_audio_packet(vorbis_context *vc) {
+ GetBitContext *gb=&vc->gb;
+
+ uint_fast8_t previous_window=0,next_window=0;
+ uint_fast8_t mode_number;
+ uint_fast16_t blocksize;
+ int_fast32_t i,j;
+ 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;
+ uint_fast8_t res_chan[vc->audio_channels];
+ uint_fast8_t res_num=0;
+ int_fast16_t retlen=0;
+ uint_fast16_t saved_start=0;
+ float fadd_bias = vc->add_bias;
+
+ if (get_bits1(gb)) {
+ av_log(vc->avccontext, AV_LOG_ERROR, "Not a Vorbis I audio packet.\n");
+ return -1; // packet type not audio
+ }
+
+ if (vc->mode_count==1) {
+ mode_number=0;
+ } else {
+ mode_number=get_bits(gb, ilog(vc->mode_count-1));
+ }
+ 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);
+
+ if (vc->modes[mode_number].blockflag) {
+ previous_window=get_bits1(gb);
+ next_window=get_bits1(gb);
+ }
+
+ blocksize=vc->blocksize[vc->modes[mode_number].blockflag];
+ 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;i<vc->audio_channels;++i) {
+ vorbis_floor *floor;
+ if (mapping->submaps>1) {
+ floor=&vc->floors[mapping->submap_floor[mapping->mux[i]]];
+ } else {
+ floor=&vc->floors[mapping->submap_floor[0]];
+ }
+
+ 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) {
+ if (!(no_residue[mapping->magnitude[i]] & no_residue[mapping->angle[i]])) {
+ no_residue[mapping->magnitude[i]]=0;
+ no_residue[mapping->angle[i]]=0;
+ }
+ }
+
+// Decode residue
+
+ for(i=0;i<mapping->submaps;++i) {
+ vorbis_residue *residue;
+ uint_fast8_t ch=0;
+
+ 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;
+ } else {
+ do_not_decode[ch]=0;
+ }
+ ++ch;
+ ++res_num;
+ }
+ }
+ 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;
+ }
+
+// Inverse coupling
+
+ 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);
+ }
+
+// Dotproduct
+
+ for(j=0, ch_floor_ptr=vc->channel_floors;j<vc->audio_channels;++j,ch_floor_ptr+=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);
+ }
+
+// MDCT, overlap/add, save data for next overlapping FPMATH
+
+ for(j=0;j<vc->audio_channels;++j) {
+ uint_fast8_t step=vc->audio_channels;
+ uint_fast16_t k;
+ float *saved=vc->saved+j*vc->blocksize[1]/2;
+ float *ret=vc->ret;
+ const float *lwin=vc->win[1];
+ const float *swin=vc->win[0];
+ float *buf=vc->buf;
+ float *buf_tmp=vc->buf_tmp;
+
+ ch_floor_ptr=vc->channel_floors+j*blocksize/2;
+
+ saved_start=vc->saved_start;
+
+ vc->mdct[0].fft.imdct_calc(&vc->mdct[vc->modes[mode_number].blockflag], buf, ch_floor_ptr, buf_tmp);
+
+ //FIXME process channels together, to allow faster simd vector_fmul_add_add?
+ if (vc->modes[mode_number].blockflag) {
+ // -- overlap/add
+ if (previous_window) {
+ vc->dsp.vector_fmul_add_add(ret+j, buf, lwin, saved, vc->add_bias, vc->blocksize[1]/2, step);
+ retlen=vc->blocksize[1]/2;
+ } else {
+ int len = (vc->blocksize[1]-vc->blocksize[0])/4;
+ buf += len;
+ vc->dsp.vector_fmul_add_add(ret+j, buf, swin, saved, vc->add_bias, vc->blocksize[0]/2, step);
+ k = vc->blocksize[0]/2*step + j;
+ buf += vc->blocksize[0]/2;
+ if(vc->exp_bias){
+ for(i=0; i<len; i++, k+=step)
+ ((uint32_t*)ret)[k] = ((uint32_t*)buf)[i] + vc->exp_bias; // ret[k]=buf[i]*(1<<bias)
+ } else {
+ for(i=0; i<len; i++, k+=step)
+ ret[k] = buf[i] + fadd_bias;
+ }
+ buf=vc->buf;
+ retlen=vc->blocksize[0]/2+len;
+ }
+ // -- save
+ if (next_window) {
+ buf += vc->blocksize[1]/2;
+ vc->dsp.vector_fmul_reverse(saved, buf, lwin, vc->blocksize[1]/2);
+ saved_start=0;
+ } else {
+ saved_start=(vc->blocksize[1]-vc->blocksize[0])/4;
+ buf += vc->blocksize[1]/2;
+ for(i=0; i<saved_start; i++)
+ ((uint32_t*)saved)[i] = ((uint32_t*)buf)[i] + vc->exp_bias;
+ vc->dsp.vector_fmul_reverse(saved+saved_start, buf+saved_start, swin, vc->blocksize[0]/2);
+ }
+ } else {
+ // --overlap/add
+ if(vc->add_bias) {
+ for(k=j, i=0;i<saved_start;++i, k+=step)
+ ret[k] = saved[i] + fadd_bias;
+ } else {
+ for(k=j, i=0;i<saved_start;++i, k+=step)
+ ret[k] = saved[i];
+ }
+ vc->dsp.vector_fmul_add_add(ret+k, buf, swin, saved+saved_start, vc->add_bias, vc->blocksize[0]/2, step);
+ retlen=saved_start+vc->blocksize[0]/2;
+ // -- save
+ buf += vc->blocksize[0]/2;
+ vc->dsp.vector_fmul_reverse(saved, buf, swin, vc->blocksize[0]/2);
+ saved_start=0;
+ }
+ }
+ vc->saved_start=saved_start;
+
+ return retlen*vc->audio_channels;
+}
+
+// Return the decoded audio packet through the standard api
+
+static int vorbis_decode_frame(AVCodecContext *avccontext,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ vorbis_context *vc = avccontext->priv_data ;
+ GetBitContext *gb = &(vc->gb);
+
+ int_fast16_t len;
+
+ 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);
+
+ if (len<=0) {
+ *data_size=0;
+ return buf_size;
+ }
+
+ if (!vc->first_frame) {
+ 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);
+
+ vc->dsp.float_to_int16(data, vc->ret, len);
+ *data_size=len*2;
+
+ return buf_size ;
+}
+
+// Close decoder
+
+static int vorbis_decode_close(AVCodecContext *avccontext) {
+ vorbis_context *vc = avccontext->priv_data;
+
+ vorbis_free(vc);
+
+ return 0 ;
+}
+
+AVCodec vorbis_decoder = {
+ "vorbis",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_VORBIS,
+ sizeof(vorbis_context),
+ vorbis_decode_init,
+ NULL,
+ vorbis_decode_close,
+ vorbis_decode_frame,
+};
+
diff --git a/src/libffmpeg/libavcodec/vorbis.h b/contrib/ffmpeg/libavcodec/vorbis.h
index cda909aa9..cda909aa9 100644
--- a/src/libffmpeg/libavcodec/vorbis.h
+++ b/contrib/ffmpeg/libavcodec/vorbis.h
diff --git a/src/libffmpeg/libavcodec/vorbis_data.c b/contrib/ffmpeg/libavcodec/vorbis_data.c
index 5dc9c5f00..5dc9c5f00 100644
--- a/src/libffmpeg/libavcodec/vorbis_data.c
+++ b/contrib/ffmpeg/libavcodec/vorbis_data.c
diff --git a/contrib/ffmpeg/libavcodec/vorbis_enc.c b/contrib/ffmpeg/libavcodec/vorbis_enc.c
new file mode 100644
index 000000000..3789ef7a2
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/vorbis_enc.c
@@ -0,0 +1,1087 @@
+/*
+ * copyright (c) 2006 Oded Shimon <ods15@ods15.dyndns.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file vorbis_enc.c
+ * Native Vorbis encoder.
+ * @author Oded Shimon <ods15@ods15.dyndns.org>
+ */
+
+#include <float.h>
+#include "avcodec.h"
+#include "dsputil.h"
+#include "vorbis.h"
+#include "vorbis_enc_data.h"
+
+#undef NDEBUG
+#include <assert.h>
+
+typedef struct {
+ int nentries;
+ uint8_t * lens;
+ uint32_t * codewords;
+ int ndimentions;
+ float min;
+ float delta;
+ int seq_p;
+ int lookup;
+ int * quantlist;
+ float * dimentions;
+ float * pow2;
+} codebook_t;
+
+typedef struct {
+ int dim;
+ int subclass;
+ int masterbook;
+ int * books;
+} floor_class_t;
+
+typedef struct {
+ int partitions;
+ int * partition_to_class;
+ int nclasses;
+ floor_class_t * classes;
+ int multiplier;
+ int rangebits;
+ int values;
+ floor1_entry_t * list;
+} floor_t;
+
+typedef struct {
+ int type;
+ int begin;
+ int end;
+ int partition_size;
+ int classifications;
+ int classbook;
+ int8_t (*books)[8];
+ float (*maxes)[2];
+} residue_t;
+
+typedef struct {
+ int submaps;
+ int * mux;
+ int * floor;
+ int * residue;
+ int coupling_steps;
+ int * magnitude;
+ int * angle;
+} mapping_t;
+
+typedef struct {
+ int blockflag;
+ int mapping;
+} vorbis_mode_t;
+
+typedef struct {
+ int channels;
+ int sample_rate;
+ int log2_blocksize[2];
+ MDCTContext 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 quality;
+
+ int ncodebooks;
+ codebook_t * codebooks;
+
+ int nfloors;
+ floor_t * floors;
+
+ int nresidues;
+ residue_t * residues;
+
+ int nmappings;
+ mapping_t * mappings;
+
+ int nmodes;
+ vorbis_mode_t * modes;
+} venc_context_t;
+
+typedef struct {
+ int total;
+ int total_pos;
+ int pos;
+ uint8_t * buf_ptr;
+} PutBitContext;
+
+static inline void init_put_bits(PutBitContext * pb, uint8_t * buf, int buffer_len) {
+ pb->total = buffer_len * 8;
+ pb->total_pos = 0;
+ pb->pos = 0;
+ pb->buf_ptr = buf;
+}
+
+static void put_bits(PutBitContext * pb, int bits, uint64_t val) {
+ if ((pb->total_pos += bits) >= pb->total) return;
+ if (!bits) return;
+ if (pb->pos) {
+ if (pb->pos > bits) {
+ *pb->buf_ptr |= val << (8 - pb->pos);
+ pb->pos -= bits;
+ bits = 0;
+ } else {
+ *pb->buf_ptr++ |= (val << (8 - pb->pos)) & 0xFF;
+ val >>= pb->pos;
+ bits -= pb->pos;
+ pb->pos = 0;
+ }
+ }
+ for (; bits >= 8; bits -= 8) {
+ *pb->buf_ptr++ = val & 0xFF;
+ val >>= 8;
+ }
+ if (bits) {
+ *pb->buf_ptr = val;
+ pb->pos = 8 - bits;
+ }
+}
+
+static inline void flush_put_bits(PutBitContext * pb) {
+}
+
+static inline int put_bits_count(PutBitContext * pb) {
+ return pb->total_pos;
+}
+
+static inline void put_codeword(PutBitContext * pb, codebook_t * 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;
+ return 0;
+}
+
+static void ready_codebook(codebook_t * cb) {
+ int i;
+
+ ff_vorbis_len2vlc(cb->lens, cb->codewords, cb->nentries);
+
+ if (!cb->lookup)
+ cb->pow2 = cb->dimentions = NULL;
+ 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);
+ for (i = 0; i < cb->nentries; i++) {
+ float last = 0;
+ int j;
+ int div = 1;
+ for (j = 0; j < cb->ndimentions; j++) {
+ int off;
+ if (cb->lookup == 1)
+ off = (i / div) % vals; // lookup type 1
+ else
+ off = i * cb->ndimentions + j; // lookup type 2
+
+ 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];
+ div *= vals;
+ }
+ cb->pow2[i] /= 2.;
+ }
+ }
+}
+
+static void ready_residue(residue_t * rc, venc_context_t * venc) {
+ int i;
+ assert(rc->type == 2);
+ rc->maxes = av_mallocz(sizeof(float[2]) * rc->classifications);
+ for (i = 0; i < rc->classifications; i++) {
+ int j;
+ codebook_t * cb;
+ for (j = 0; j < 8; j++)
+ if (rc->books[i][j] != -1) break;
+ if (j == 8) continue; // zero
+ 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;
+ a = fabs(cb->dimentions[j * cb->ndimentions]);
+ if (a > rc->maxes[i][0])
+ rc->maxes[i][0] = a;
+ a = fabs(cb->dimentions[j * cb->ndimentions + 1]);
+ if (a > rc->maxes[i][1])
+ rc->maxes[i][1] = a;
+ }
+ }
+ // small bias
+ for (i = 0; i < rc->classifications; i++) {
+ rc->maxes[i][0] += 0.8;
+ rc->maxes[i][1] += 0.8;
+ }
+}
+
+static void create_vorbis_context(venc_context_t * venc, AVCodecContext * avccontext) {
+ floor_t * fc;
+ residue_t * rc;
+ mapping_t * mc;
+ int i, book;
+
+ venc->channels = avccontext->channels;
+ venc->sample_rate = avccontext->sample_rate;
+ venc->log2_blocksize[0] = venc->log2_blocksize[1] = 11;
+
+ venc->ncodebooks = sizeof(cvectors)/sizeof(cvectors[0]);
+ venc->codebooks = av_malloc(sizeof(codebook_t) * 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++) {
+ codebook_t * 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->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);
+
+ if (cb->lookup) {
+ vals = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries);
+ cb->quantlist = av_malloc(sizeof(int) * vals);
+ for (i = 0; i < vals; i++)
+ cb->quantlist[i] = cvectors[book].quant[i];
+ } else {
+ cb->quantlist = NULL;
+ }
+ ready_codebook(cb);
+ }
+
+ venc->nfloors = 1;
+ venc->floors = av_malloc(sizeof(floor_t) * venc->nfloors);
+
+ // just 1 floor
+ fc = &venc->floors[0];
+ fc->partitions = 8;
+ fc->partition_to_class = av_malloc(sizeof(int) * fc->partitions);
+ fc->nclasses = 0;
+ for (i = 0; i < fc->partitions; i++) {
+ 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]);
+ }
+ fc->nclasses++;
+ fc->classes = av_malloc(sizeof(floor_class_t) * fc->nclasses);
+ for (i = 0; i < fc->nclasses; i++) {
+ floor_class_t * c = &fc->classes[i];
+ int j, books;
+ 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);
+ 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->values = 2;
+ for (i = 0; i < fc->partitions; i++)
+ fc->values += fc->classes[fc->partition_to_class[i]].dim;
+
+ fc->list = av_malloc(sizeof(floor1_entry_t) * fc->values);
+ fc->list[0].x = 0;
+ fc->list[1].x = 1 << fc->rangebits;
+ for (i = 2; i < fc->values; i++) {
+ static const int a[] = {
+ 93, 23,372, 6, 46,186,750, 14, 33, 65,
+ 130,260,556, 3, 10, 18, 28, 39, 55, 79,
+ 111,158,220,312,464,650,850
+ };
+ fc->list[i].x = a[i - 2];
+ }
+ ff_vorbis_ready_floor1_list(fc->list, fc->values);
+
+ venc->nresidues = 1;
+ venc->residues = av_malloc(sizeof(residue_t) * venc->nresidues);
+
+ // single residue
+ rc = &venc->residues[0];
+ 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);
+ {
+ static const int8_t a[10][8] = {
+ { -1, -1, -1, -1, -1, -1, -1, -1, },
+ { -1, -1, 16, -1, -1, -1, -1, -1, },
+ { -1, -1, 17, -1, -1, -1, -1, -1, },
+ { -1, -1, 18, -1, -1, -1, -1, -1, },
+ { -1, -1, 19, -1, -1, -1, -1, -1, },
+ { -1, -1, 20, -1, -1, -1, -1, -1, },
+ { -1, -1, 21, -1, -1, -1, -1, -1, },
+ { 22, 23, -1, -1, -1, -1, -1, -1, },
+ { 24, 25, -1, -1, -1, -1, -1, -1, },
+ { 26, 27, 28, -1, -1, -1, -1, -1, },
+ };
+ memcpy(rc->books, a, sizeof a);
+ }
+ ready_residue(rc, venc);
+
+ venc->nmappings = 1;
+ venc->mappings = av_malloc(sizeof(mapping_t) * venc->nmappings);
+
+ // single mapping
+ mc = &venc->mappings[0];
+ mc->submaps = 1;
+ 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->residue = av_malloc(sizeof(int) * mc->submaps);
+ for (i = 0; i < mc->submaps; i++) {
+ 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);
+ if (mc->coupling_steps) {
+ mc->magnitude[0] = 0;
+ mc->angle[0] = 1;
+ }
+
+ venc->nmodes = 1;
+ venc->modes = av_malloc(sizeof(vorbis_mode_t) * venc->nmodes);
+
+ // single mode
+ venc->modes[0].blockflag = 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->win[0] = ff_vorbis_vwin[venc->log2_blocksize[0] - 6];
+ venc->win[1] = ff_vorbis_vwin[venc->log2_blocksize[1] - 6];
+
+ ff_mdct_init(&venc->mdct[0], venc->log2_blocksize[0], 0);
+ ff_mdct_init(&venc->mdct[1], venc->log2_blocksize[1], 0);
+}
+
+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; }
+ res |= mant | (exp << 21);
+ put_bits(pb, 32, res);
+}
+
+static void put_codebook_header(PutBitContext * pb, codebook_t * cb) {
+ int i;
+ int ordered = 0;
+
+ put_bits(pb, 24, 0x564342); //magic
+ put_bits(pb, 16, cb->ndimentions);
+ put_bits(pb, 24, cb->nentries);
+
+ for (i = 1; i < cb->nentries; i++)
+ if (cb->lens[i] < cb->lens[i-1]) break;
+ if (i == cb->nentries)
+ ordered = 1;
+
+ put_bits(pb, 1, ordered);
+ if (ordered) {
+ int len = cb->lens[0];
+ put_bits(pb, 5, len - 1);
+ i = 0;
+ while (i < cb->nentries) {
+ int j;
+ for (j = 0; j+i < cb->nentries; j++)
+ if (cb->lens[j+i] != len) break;
+ put_bits(pb, ilog(cb->nentries - i), j);
+ i += j;
+ len++;
+ }
+ } else {
+ int sparse = 0;
+ for (i = 0; i < cb->nentries; i++)
+ 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);
+ }
+ }
+
+ put_bits(pb, 4, cb->lookup);
+ if (cb->lookup) {
+ int tmp = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries);
+ int bits = ilog(cb->quantlist[0]);
+
+ for (i = 1; i < tmp; i++)
+ bits = FFMAX(bits, ilog(cb->quantlist[i]));
+
+ put_float(pb, cb->min);
+ put_float(pb, cb->delta);
+
+ put_bits(pb, 4, bits - 1);
+ put_bits(pb, 1, cb->seq_p);
+
+ for (i = 0; i < tmp; i++)
+ put_bits(pb, bits, cb->quantlist[i]);
+ }
+}
+
+static void put_floor_header(PutBitContext * pb, floor_t * fc) {
+ int i;
+
+ put_bits(pb, 16, 1); // type, only floor1 is supported
+
+ put_bits(pb, 5, fc->partitions);
+
+ for (i = 0; i < fc->partitions; i++)
+ put_bits(pb, 4, fc->partition_to_class[i]);
+
+ for (i = 0; i < fc->nclasses; i++) {
+ int j, books;
+
+ put_bits(pb, 3, fc->classes[i].dim - 1);
+ put_bits(pb, 2, fc->classes[i].subclass);
+
+ if (fc->classes[i].subclass)
+ put_bits(pb, 8, fc->classes[i].masterbook);
+
+ books = (1 << fc->classes[i].subclass);
+
+ for (j = 0; j < books; j++)
+ put_bits(pb, 8, fc->classes[i].books[j] + 1);
+ }
+
+ put_bits(pb, 2, fc->multiplier - 1);
+ put_bits(pb, 4, fc->rangebits);
+
+ for (i = 2; i < fc->values; i++)
+ put_bits(pb, fc->rangebits, fc->list[i].x);
+}
+
+static void put_residue_header(PutBitContext * pb, residue_t * rc) {
+ int i;
+
+ put_bits(pb, 16, rc->type);
+
+ put_bits(pb, 24, rc->begin);
+ put_bits(pb, 24, rc->end);
+ put_bits(pb, 24, rc->partition_size - 1);
+ put_bits(pb, 6, rc->classifications - 1);
+ put_bits(pb, 8, rc->classbook);
+
+ for (i = 0; i < rc->classifications; i++) {
+ int j, tmp = 0;
+ for (j = 0; j < 8; j++)
+ tmp |= (rc->books[i][j] != -1) << j;
+
+ put_bits(pb, 3, tmp & 7);
+ put_bits(pb, 1, tmp > 7);
+
+ if (tmp > 7)
+ put_bits(pb, 5, tmp >> 3);
+ }
+
+ for (i = 0; i < rc->classifications; i++) {
+ int j;
+ for (j = 0; j < 8; j++)
+ if (rc->books[i][j] != -1)
+ put_bits(pb, 8, rc->books[i][j]);
+ }
+}
+
+static int put_main_header(venc_context_t * venc, uint8_t ** out) {
+ int i;
+ PutBitContext pb;
+ uint8_t buffer[50000] = {0}, * p = buffer;
+ int buffer_len = sizeof buffer;
+ int len, hlens[3];
+
+ // identification header
+ init_put_bits(&pb, p, buffer_len);
+ 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
+
+ flush_put_bits(&pb);
+ hlens[0] = (put_bits_count(&pb) + 7) / 8;
+ buffer_len -= hlens[0];
+ p += hlens[0];
+
+ // comment header
+ init_put_bits(&pb, p, buffer_len);
+ 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
+
+ flush_put_bits(&pb);
+ hlens[1] = (put_bits_count(&pb) + 7) / 8;
+ buffer_len -= hlens[1];
+ p += hlens[1];
+
+ // setup header
+ init_put_bits(&pb, p, buffer_len);
+ put_bits(&pb, 8, 5); //magic
+ for (i = 0; "vorbis"[i]; i++)
+ put_bits(&pb, 8, "vorbis"[i]);
+
+ // codebooks
+ put_bits(&pb, 8, venc->ncodebooks - 1);
+ for (i = 0; i < venc->ncodebooks; i++)
+ put_codebook_header(&pb, &venc->codebooks[i]);
+
+ // time domain, reserved, zero
+ put_bits(&pb, 6, 0);
+ put_bits(&pb, 16, 0);
+
+ // floors
+ put_bits(&pb, 6, venc->nfloors - 1);
+ for (i = 0; i < venc->nfloors; i++)
+ put_floor_header(&pb, &venc->floors[i]);
+
+ // residues
+ put_bits(&pb, 6, venc->nresidues - 1);
+ for (i = 0; i < venc->nresidues; i++)
+ put_residue_header(&pb, &venc->residues[i]);
+
+ // mappings
+ put_bits(&pb, 6, venc->nmappings - 1);
+ for (i = 0; i < venc->nmappings; i++) {
+ mapping_t * mc = &venc->mappings[i];
+ int j;
+ put_bits(&pb, 16, 0); // mapping type
+
+ put_bits(&pb, 1, mc->submaps > 1);
+ if (mc->submaps > 1)
+ put_bits(&pb, 4, mc->submaps - 1);
+
+ put_bits(&pb, 1, !!mc->coupling_steps);
+ if (mc->coupling_steps) {
+ put_bits(&pb, 8, mc->coupling_steps - 1);
+ for (j = 0; j < mc->coupling_steps; j++) {
+ put_bits(&pb, ilog(venc->channels - 1), mc->magnitude[j]);
+ put_bits(&pb, ilog(venc->channels - 1), mc->angle[j]);
+ }
+ }
+
+ put_bits(&pb, 2, 0); // reserved
+
+ if (mc->submaps > 1)
+ for (j = 0; j < venc->channels; j++)
+ put_bits(&pb, 4, mc->mux[j]);
+
+ for (j = 0; j < mc->submaps; j++) {
+ put_bits(&pb, 8, 0); // reserved time configuration
+ put_bits(&pb, 8, mc->floor[j]);
+ put_bits(&pb, 8, mc->residue[j]);
+ }
+ }
+
+ // modes
+ put_bits(&pb, 6, venc->nmodes - 1);
+ for (i = 0; i < venc->nmodes; i++) {
+ put_bits(&pb, 1, venc->modes[i].blockflag);
+ put_bits(&pb, 16, 0); // reserved window type
+ put_bits(&pb, 16, 0); // reserved transform type
+ put_bits(&pb, 8, venc->modes[i].mapping);
+ }
+
+ put_bits(&pb, 1, 1); // framing
+
+ flush_put_bits(&pb);
+ hlens[2] = (put_bits_count(&pb) + 7) / 8;
+
+ len = hlens[0] + hlens[1] + hlens[2];
+ p = *out = av_mallocz(64 + len + len/255);
+
+ *p++ = 2;
+ p += av_xiphlacing(p, hlens[0]);
+ p += av_xiphlacing(p, hlens[1]);
+ buffer_len = 0;
+ for (i = 0; i < 3; i++) {
+ memcpy(p, buffer + buffer_len, hlens[i]);
+ p += hlens[i];
+ buffer_len += hlens[i];
+ }
+
+ return p - *out;
+}
+
+static float get_floor_average(floor_t * 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;
+ float average = 0;
+
+ for (j = begin; j < end; j++)
+ average += fabs(coeffs[j]);
+ return average / (end - begin);
+}
+
+static void floor_fit(venc_context_t * venc, floor_t * 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++){
+ averages[i] = get_floor_average(fc, coeffs, i);
+ tot_average += averages[i];
+ }
+ tot_average /= fc->values;
+ tot_average /= venc->quality;
+
+ for (i = 0; i < fc->values; i++) {
+ 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;
+ posts[fc->list[i].sort] = j;
+ }
+}
+
+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(venc_context_t * venc, floor_t * 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;
+
+ put_bits(pb, 1, 1); // non zero
+ put_bits(pb, ilog(range - 1), posts[0]);
+ put_bits(pb, ilog(range - 1), posts[1]);
+ coded[0] = coded[1] = 1;
+
+ for (i = 2; i < fc->values; i++) {
+ int predicted = render_point(fc->list[fc->list[i].low].x,
+ posts[fc->list[i].low],
+ fc->list[fc->list[i].high].x,
+ posts[fc->list[i].high],
+ fc->list[i].x);
+ int highroom = range - predicted;
+ int lowroom = predicted;
+ int room = FFMIN(highroom, lowroom);
+ if (predicted == posts[i]) {
+ 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 (posts[i] > predicted) {
+ if (posts[i] - predicted > room)
+ coded[i] = posts[i] - predicted + lowroom;
+ else
+ coded[i] = (posts[i] - predicted) << 1;
+ } else {
+ if (predicted - posts[i] > room)
+ coded[i] = predicted - posts[i] + highroom - 1;
+ else
+ coded[i] = ((predicted - posts[i]) << 1) - 1;
+ }
+ }
+
+ counter = 2;
+ for (i = 0; i < fc->partitions; i++) {
+ floor_class_t * c = &fc->classes[fc->partition_to_class[i]];
+ int k, cval = 0, csub = 1<<c->subclass;
+ if (c->subclass) {
+ codebook_t * book = &venc->codebooks[c->masterbook];
+ int cshift = 0;
+ for (k = 0; k < c->dim; k++) {
+ int l;
+ for (l = 0; l < csub; l++) {
+ int maxval = 1;
+ if (c->books[l] != -1)
+ maxval = venc->codebooks[c->books[l]].nentries;
+ // coded could be -1, but this still works, cause thats 0
+ if (coded[counter + k] < maxval) break;
+ }
+ assert(l != csub);
+ 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 entry = coded[counter++];
+ cval >>= c->subclass;
+ 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);
+}
+
+static float * put_vector(codebook_t * 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;
+ for (j = 0; j < book->ndimentions; j++)
+ d -= vec[j] * num[j];
+ if (distance > d) {
+ entry = i;
+ distance = d;
+ }
+ }
+ put_codeword(pb, book, entry);
+ return &book->dimentions[entry * book->ndimentions];
+}
+
+static void residue_encode(venc_context_t * venc, residue_t * rc, PutBitContext * pb, float * coeffs, int samples, int real_ch) {
+ int pass, i, j, p, k;
+ int psize = rc->partition_size;
+ int partitions = (rc->end - rc->begin) / psize;
+ int channels = (rc->type == 2) ? 1 : real_ch;
+ int classes[channels][partitions];
+ int classwords = venc->codebooks[rc->classbook].ndimentions;
+
+ assert(rc->type == 2);
+ assert(real_ch == 2);
+ for (p = 0; p < partitions; p++) {
+ float max1 = 0., max2 = 0.;
+ int s = rc->begin + p * psize;
+ for (k = s; k < s + psize; k += 2) {
+ max1 = FFMAX(max1, fabs(coeffs[ k / real_ch]));
+ 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;
+ }
+ classes[0][p] = i;
+ }
+
+ for (pass = 0; pass < 8; pass++) {
+ p = 0;
+ while (p < partitions) {
+ if (pass == 0)
+ for (j = 0; j < channels; j++) {
+ codebook_t * book = &venc->codebooks[rc->classbook];
+ int entry = 0;
+ for (i = 0; i < classwords; i++) {
+ entry *= rc->classifications;
+ entry += classes[j][p + i];
+ }
+ put_codeword(pb, book, entry);
+ }
+ for (i = 0; i < classwords && p < partitions; i++, p++) {
+ for (j = 0; j < channels; j++) {
+ int nbook = rc->books[classes[j][p]][pass];
+ codebook_t * book = &venc->codebooks[nbook];
+ 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]);
+ int l;
+ for (l = 0; l < book->ndimentions; l++)
+ buf[k + l] -= a[l];
+ }
+ } else {
+ int s = rc->begin + p * psize, a1, b1;
+ a1 = (s % real_ch) * samples;
+ b1 = s / real_ch;
+ s = real_ch * samples;
+ for (k = 0; k < psize; k += book->ndimentions) {
+ int dim, a2 = a1, b2 = b1;
+ float vec[book->ndimentions], * pv = vec;
+ for (dim = book->ndimentions; dim--; ) {
+ *pv++ = coeffs[a2 + b2];
+ if ((a2 += samples) == s) {
+ a2=0;
+ b2++;
+ }
+ }
+ pv = put_vector(book, pb, vec);
+ for (dim = book->ndimentions; dim--; ) {
+ coeffs[a1 + b1] -= *pv++;
+ if ((a1 += samples) == s) {
+ a1=0;
+ b1++;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+static int apply_window_and_mdct(venc_context_t * 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) {
+ 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);
+ }
+ }
+
+ if (samples) {
+ for (channel = 0; channel < venc->channels; channel++) {
+ float * offset = venc->samples + channel*window_len*2 + window_len;
+ j = channel;
+ for (i = 0; i < samples; i++, j += venc->channels)
+ 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++) {
+ ff_mdct_calc(&venc->mdct[0], venc->coeffs + channel*window_len, venc->samples + channel*window_len*2, venc->floor/*tmp*/);
+ }
+
+ if (samples) {
+ for (channel = 0; channel < venc->channels; channel++) {
+ 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
+ }
+ venc->have_saved = 1;
+ } else {
+ venc->have_saved = 0;
+ }
+ return 1;
+}
+
+static int vorbis_encode_init(AVCodecContext * avccontext)
+{
+ venc_context_t * venc = avccontext->priv_data;
+
+ if (avccontext->channels != 2) {
+ av_log(avccontext, AV_LOG_ERROR, "Current FFmpeg Vorbis encoder only supports 2 channels.\n");
+ return -1;
+ }
+
+ create_vorbis_context(venc, avccontext);
+
+ if (avccontext->flags & CODEC_FLAG_QSCALE)
+ venc->quality = avccontext->global_quality / (float)FF_QP2LAMBDA / 10.;
+ else
+ venc->quality = 1.;
+ venc->quality *= venc->quality;
+
+ avccontext->extradata_size = put_main_header(venc, (uint8_t**)&avccontext->extradata);
+
+ avccontext->frame_size = 1 << (venc->log2_blocksize[0] - 1);
+
+ 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)
+{
+ venc_context_t * venc = avccontext->priv_data;
+ signed short * audio = data;
+ int samples = data ? avccontext->frame_size : 0;
+ vorbis_mode_t * mode;
+ mapping_t * mapping;
+ PutBitContext pb;
+ int i;
+
+ if (!apply_window_and_mdct(venc, audio, samples)) return 0;
+ samples = 1 << (venc->log2_blocksize[0] - 1);
+
+ init_put_bits(&pb, packets, buf_size);
+
+ put_bits(&pb, 1, 0); // magic bit
+
+ put_bits(&pb, ilog(venc->nmodes - 1), 0); // 0 bits, the mode
+
+ mode = &venc->modes[0];
+ mapping = &venc->mappings[mode->mapping];
+ if (mode->blockflag) {
+ put_bits(&pb, 1, 0);
+ put_bits(&pb, 1, 0);
+ }
+
+ for (i = 0; i < venc->channels; i++) {
+ floor_t * 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++) {
+ 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;
+ 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;
+ }
+ }
+
+ residue_encode(venc, &venc->residues[mapping->residue[mapping->mux[0]]], &pb, venc->coeffs, samples, venc->channels);
+
+ flush_put_bits(&pb);
+ return (put_bits_count(&pb) + 7) / 8;
+}
+
+
+static int vorbis_encode_close(AVCodecContext * avccontext)
+{
+ venc_context_t * venc = avccontext->priv_data;
+ int i;
+
+ if (venc->codebooks)
+ for (i = 0; i < venc->ncodebooks; i++) {
+ av_freep(&venc->codebooks[i].lens);
+ av_freep(&venc->codebooks[i].codewords);
+ av_freep(&venc->codebooks[i].quantlist);
+ av_freep(&venc->codebooks[i].dimentions);
+ av_freep(&venc->codebooks[i].pow2);
+ }
+ av_freep(&venc->codebooks);
+
+ if (venc->floors)
+ for (i = 0; i < venc->nfloors; i++) {
+ int j;
+ if (venc->floors[i].classes)
+ for (j = 0; j < venc->floors[i].nclasses; j++)
+ av_freep(&venc->floors[i].classes[j].books);
+ av_freep(&venc->floors[i].classes);
+ av_freep(&venc->floors[i].partition_to_class);
+ av_freep(&venc->floors[i].list);
+ }
+ av_freep(&venc->floors);
+
+ if (venc->residues)
+ for (i = 0; i < venc->nresidues; i++) {
+ av_freep(&venc->residues[i].books);
+ av_freep(&venc->residues[i].maxes);
+ }
+ av_freep(&venc->residues);
+
+ if (venc->mappings)
+ for (i = 0; i < venc->nmappings; i++) {
+ av_freep(&venc->mappings[i].mux);
+ av_freep(&venc->mappings[i].floor);
+ av_freep(&venc->mappings[i].residue);
+ av_freep(&venc->mappings[i].magnitude);
+ av_freep(&venc->mappings[i].angle);
+ }
+ av_freep(&venc->mappings);
+
+ av_freep(&venc->modes);
+
+ av_freep(&venc->saved);
+ av_freep(&venc->samples);
+ av_freep(&venc->floor);
+ av_freep(&venc->coeffs);
+
+ ff_mdct_end(&venc->mdct[0]);
+ ff_mdct_end(&venc->mdct[1]);
+
+ av_freep(&avccontext->coded_frame);
+ av_freep(&avccontext->extradata);
+
+ return 0 ;
+}
+
+AVCodec vorbis_encoder = {
+ "vorbis",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_VORBIS,
+ sizeof(venc_context_t),
+ vorbis_encode_init,
+ vorbis_encode_frame,
+ vorbis_encode_close,
+ .capabilities= CODEC_CAP_DELAY,
+};
diff --git a/contrib/ffmpeg/libavcodec/vorbis_enc_data.h b/contrib/ffmpeg/libavcodec/vorbis_enc_data.h
new file mode 100644
index 000000000..e56dc5df5
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/vorbis_enc_data.h
@@ -0,0 +1,498 @@
+/*
+ * copyright (c) 2006 Oded Shimon <ods15@ods15.dyndns.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+static const uint8_t codebook0[] = {
+ 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,
+};
+
+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,
+};
+
+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,
+};
+
+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,
+};
+
+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,
+};
+
+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,
+};
+
+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,
+};
+
+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,
+};
+
+static const uint8_t codebook9[] = {
+ 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,
+};
+
+static const uint8_t codebook11[] = {
+ 3, 7, 3, 8, 3, 10, 3, 8, 3, 9, 3, 8, 4, 9, 4,
+ 9, 5, 9, 6, 10, 6, 9, 7, 11, 7, 12, 9, 13, 10, 13,
+ 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,
+};
+
+static const uint8_t codebook12[] = {
+ 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,
+};
+
+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,
+};
+
+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,
+};
+
+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,
+};
+
+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,
+};
+
+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,
+};
+
+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,
+};
+
+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,
+};
+
+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,
+};
+
+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,
+};
+
+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,
+};
+
+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,
+};
+
+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,
+};
+
+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,
+};
+
+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,
+};
+
+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,
+};
+
+static const struct {
+ int dim;
+ int len;
+ int real_len;
+ const uint8_t * clens;
+ int lookup;
+ float min;
+ float delta;
+ const uint8_t * quant;
+} cvectors[] = {
+ { 2, 16, 16, codebook0, 0 },
+ { 2, 8, 8, codebook1, 0 },
+ { 2, 256, 256, codebook2, 0 },
+ { 2, 64, 64, codebook3, 0 },
+ { 2, 128, 128, codebook4, 0 },
+ { 2, 32, 32, codebook5, 0 },
+ { 2, 96, 96, codebook6, 0 },
+ { 2, 32, 32, codebook7, 0 },
+ { 2, 96, 96, codebook8, 0 },
+ { 2, 17, 17, codebook9, 0 },
+ { 2, 32, 32, codebook10, 0 },
+ { 2, 78, 78, codebook11, 0 },
+ { 2, 17, 17, codebook12, 0 },
+ { 2, 32, 32, codebook13, 0 },
+ { 2, 78, 78, codebook14, 0 },
+ { 2, 100, 100, codebook15, 0 },
+ { 8, 1641, 6561, codebook16, 1, -1.0, 1.0, (const uint8_t[]){ 1, 0, 2, } },
+ { 4, 443, 625, codebook17, 1, -2.0, 1.0, (const uint8_t[]){ 2, 1, 3, 0, 4, } },
+ { 4, 105, 625, codebook18, 1, -2.0, 1.0, (const uint8_t[]){ 2, 1, 3, 0, 4, } },
+ { 2, 68, 81, codebook19, 1, -4.0, 1.0, (const uint8_t[]){ 4, 3, 5, 2, 6, 1, 7, 0, 8, } },
+ { 2, 81, 81, codebook20, 1, -4.0, 1.0, (const uint8_t[]){ 4, 3, 5, 2, 6, 1, 7, 0, 8, } },
+ { 2, 289, 289, codebook21, 1, -8.0, 1.0, (const uint8_t[]){ 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15, 0, 16, } },
+ { 4, 81, 81, codebook22, 1, -11.0, 11.0, (const uint8_t[]){ 1, 0, 2, } },
+ { 2, 121, 121, codebook23, 1, -5.0, 1.0, (const uint8_t[]){ 5, 4, 6, 3, 7, 2, 8, 1, 9, 0, 10, } },
+ { 2, 169, 169, codebook24, 1, -30.0, 5.0, (const uint8_t[]){ 6, 5, 7, 4, 8, 3, 9, 2, 10, 1, 11, 0, 12, } },
+ { 2, 25, 25, codebook25, 1, -2.0, 1.0, (const uint8_t[]){ 2, 1, 3, 0, 4, } },
+ { 2, 169, 169, codebook26, 1, -1530.0, 255.0, (const uint8_t[]){ 6, 5, 7, 4, 8, 3, 9, 2, 10, 1, 11, 0, 12, } },
+ { 2, 225, 225, codebook27, 1, -119.0, 17.0, (const uint8_t[]){ 7, 6, 8, 5, 9, 4, 10, 3, 11, 2, 12, 1, 13, 0, 14, } },
+ { 2, 289, 289, codebook28, 1, -8.0, 1.0, (const uint8_t[]){ 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15, 0, 16, } },
+};
+
+static const struct {
+ int dim;
+ int subclass;
+ int masterbook;
+ const int * nbooks;
+} floor_classes[] = {
+ { 3, 0, 0, (const int[]){ 4 } },
+ { 4, 1, 0, (const int[]){ 5, 6 } },
+ { 3, 1, 1, (const int[]){ 7, 8 } },
+ { 4, 2, 2, (const int[]){ -1, 9, 10, 11 } },
+ { 3, 2, 3, (const int[]){ -1, 12, 13, 14 } },
+};
diff --git a/contrib/ffmpeg/libavcodec/vp3.c b/contrib/ffmpeg/libavcodec/vp3.c
new file mode 100644
index 000000000..bf17c2da7
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/vp3.c
@@ -0,0 +1,2665 @@
+/*
+ * Copyright (C) 2003-2004 the ffmpeg project
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * @file vp3.c
+ * On2 VP3 Video Decoder
+ *
+ * VP3 Video Decoder by Mike Melanson (mike at multimedia.cx)
+ * For more information about the VP3 coding process, visit:
+ * http://multimedia.cx/
+ *
+ * Theora decoder by Alex Beregszaszi
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "common.h"
+#include "avcodec.h"
+#include "dsputil.h"
+#include "mpegvideo.h"
+
+#include "vp3data.h"
+#include "xiph.h"
+
+#define FRAGMENT_PIXELS 8
+
+/*
+ * Debugging Variables
+ *
+ * Define one or more of the following compile-time variables to 1 to obtain
+ * elaborate information about certain aspects of the decoding process.
+ *
+ * KEYFRAMES_ONLY: set this to 1 to only see keyframes (VP3 slideshow mode)
+ * DEBUG_VP3: high-level decoding flow
+ * DEBUG_INIT: initialization parameters
+ * DEBUG_DEQUANTIZERS: display how the dequanization tables are built
+ * DEBUG_BLOCK_CODING: unpacking the superblock/macroblock/fragment coding
+ * DEBUG_MODES: unpacking the coding modes for individual fragments
+ * DEBUG_VECTORS: display the motion vectors
+ * DEBUG_TOKEN: display exhaustive information about each DCT token
+ * DEBUG_VLC: display the VLCs as they are extracted from the stream
+ * DEBUG_DC_PRED: display the process of reversing DC prediction
+ * DEBUG_IDCT: show every detail of the IDCT process
+ */
+
+#define KEYFRAMES_ONLY 0
+
+#define DEBUG_VP3 0
+#define DEBUG_INIT 0
+#define DEBUG_DEQUANTIZERS 0
+#define DEBUG_BLOCK_CODING 0
+#define DEBUG_MODES 0
+#define DEBUG_VECTORS 0
+#define DEBUG_TOKEN 0
+#define DEBUG_VLC 0
+#define DEBUG_DC_PRED 0
+#define DEBUG_IDCT 0
+
+#if DEBUG_VP3
+#define debug_vp3(args...) av_log(NULL, AV_LOG_DEBUG, ## args)
+#else
+static inline void debug_vp3(const char *format, ...) { }
+#endif
+
+#if DEBUG_INIT
+#define debug_init(args...) av_log(NULL, AV_LOG_DEBUG, ## args)
+#else
+static inline void debug_init(const char *format, ...) { }
+#endif
+
+#if DEBUG_DEQUANTIZERS
+#define debug_dequantizers(args...) av_log(NULL, AV_LOG_DEBUG, ## args)
+#else
+static inline void debug_dequantizers(const char *format, ...) { }
+#endif
+
+#if DEBUG_BLOCK_CODING
+#define debug_block_coding(args...) av_log(NULL, AV_LOG_DEBUG, ## args)
+#else
+static inline void debug_block_coding(const char *format, ...) { }
+#endif
+
+#if DEBUG_MODES
+#define debug_modes(args...) av_log(NULL, AV_LOG_DEBUG, ## args)
+#else
+static inline void debug_modes(const char *format, ...) { }
+#endif
+
+#if DEBUG_VECTORS
+#define debug_vectors(args...) av_log(NULL, AV_LOG_DEBUG, ## args)
+#else
+static inline void debug_vectors(const char *format, ...) { }
+#endif
+
+#if DEBUG_TOKEN
+#define debug_token(args...) av_log(NULL, AV_LOG_DEBUG, ## args)
+#else
+static inline void debug_token(const char *format, ...) { }
+#endif
+
+#if DEBUG_VLC
+#define debug_vlc(args...) av_log(NULL, AV_LOG_DEBUG, ## args)
+#else
+static inline void debug_vlc(const char *format, ...) { }
+#endif
+
+#if DEBUG_DC_PRED
+#define debug_dc_pred(args...) av_log(NULL, AV_LOG_DEBUG, ## args)
+#else
+static inline void debug_dc_pred(const char *format, ...) { }
+#endif
+
+#if DEBUG_IDCT
+#define debug_idct(args...) av_log(NULL, AV_LOG_DEBUG, ## args)
+#else
+static inline void debug_idct(const char *format, ...) { }
+#endif
+
+typedef struct Coeff {
+ struct Coeff *next;
+ DCTELEM coeff;
+ uint8_t index;
+} Coeff;
+
+//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;
+ uint8_t coding_method;
+ uint8_t coeff_count;
+ int8_t motion_x;
+ int8_t motion_y;
+} Vp3Fragment;
+
+#define SB_NOT_CODED 0
+#define SB_PARTIALLY_CODED 1
+#define SB_FULLY_CODED 2
+
+#define MODE_INTER_NO_MV 0
+#define MODE_INTRA 1
+#define MODE_INTER_PLUS_MV 2
+#define MODE_INTER_LAST_MV 3
+#define MODE_INTER_PRIOR_LAST 4
+#define MODE_USING_GOLDEN 5
+#define MODE_GOLDEN_MV 6
+#define MODE_INTER_FOURMV 7
+#define CODING_MODE_COUNT 8
+
+/* special internal mode */
+#define MODE_COPY 8
+
+/* There are 6 preset schemes, plus a free-form scheme */
+static int ModeAlphabet[7][CODING_MODE_COUNT] =
+{
+ /* this is the custom scheme */
+ { 0, 0, 0, 0, 0, 0, 0, 0 },
+
+ /* scheme 1: Last motion vector dominates */
+ { MODE_INTER_LAST_MV, MODE_INTER_PRIOR_LAST,
+ MODE_INTER_PLUS_MV, MODE_INTER_NO_MV,
+ MODE_INTRA, MODE_USING_GOLDEN,
+ MODE_GOLDEN_MV, MODE_INTER_FOURMV },
+
+ /* scheme 2 */
+ { MODE_INTER_LAST_MV, MODE_INTER_PRIOR_LAST,
+ MODE_INTER_NO_MV, MODE_INTER_PLUS_MV,
+ MODE_INTRA, MODE_USING_GOLDEN,
+ MODE_GOLDEN_MV, MODE_INTER_FOURMV },
+
+ /* scheme 3 */
+ { MODE_INTER_LAST_MV, MODE_INTER_PLUS_MV,
+ MODE_INTER_PRIOR_LAST, MODE_INTER_NO_MV,
+ MODE_INTRA, MODE_USING_GOLDEN,
+ MODE_GOLDEN_MV, MODE_INTER_FOURMV },
+
+ /* scheme 4 */
+ { MODE_INTER_LAST_MV, MODE_INTER_PLUS_MV,
+ MODE_INTER_NO_MV, MODE_INTER_PRIOR_LAST,
+ MODE_INTRA, MODE_USING_GOLDEN,
+ MODE_GOLDEN_MV, MODE_INTER_FOURMV },
+
+ /* scheme 5: No motion vector dominates */
+ { MODE_INTER_NO_MV, MODE_INTER_LAST_MV,
+ MODE_INTER_PRIOR_LAST, MODE_INTER_PLUS_MV,
+ MODE_INTRA, MODE_USING_GOLDEN,
+ MODE_GOLDEN_MV, MODE_INTER_FOURMV },
+
+ /* scheme 6 */
+ { MODE_INTER_NO_MV, MODE_USING_GOLDEN,
+ MODE_INTER_LAST_MV, MODE_INTER_PRIOR_LAST,
+ MODE_INTER_PLUS_MV, MODE_INTRA,
+ MODE_GOLDEN_MV, MODE_INTER_FOURMV },
+
+};
+
+#define MIN_DEQUANT_VAL 2
+
+typedef struct Vp3DecodeContext {
+ AVCodecContext *avctx;
+ int theora, theora_tables;
+ int version;
+ int width, height;
+ AVFrame golden_frame;
+ AVFrame last_frame;
+ AVFrame current_frame;
+ int keyframe;
+ DSPContext dsp;
+ int flipped_image;
+
+ int qis[3];
+ int nqis;
+ int quality_index;
+ int last_quality_index;
+
+ int superblock_count;
+ int superblock_width;
+ int superblock_height;
+ int y_superblock_width;
+ int y_superblock_height;
+ int c_superblock_width;
+ int c_superblock_height;
+ int u_superblock_start;
+ int v_superblock_start;
+ unsigned char *superblock_coding;
+
+ int macroblock_count;
+ int macroblock_width;
+ int macroblock_height;
+
+ int fragment_count;
+ int fragment_width;
+ int fragment_height;
+
+ Vp3Fragment *all_fragments;
+ Coeff *coeffs;
+ Coeff *next_coeff;
+ int fragment_start[3];
+
+ ScanTable scantable;
+
+ /* tables */
+ uint16_t coded_dc_scale_factor[64];
+ uint32_t coded_ac_scale_factor[64];
+ uint8_t base_matrix[384][64];
+ uint8_t qr_count[2][3];
+ uint8_t qr_size [2][3][64];
+ uint16_t qr_base[2][3][64];
+
+ /* this is a list of indices into the all_fragments array indicating
+ * which of the fragments are coded */
+ int *coded_fragment_list;
+ int coded_fragment_list_index;
+ int pixel_addresses_inited;
+
+ VLC dc_vlc[16];
+ VLC ac_vlc_1[16];
+ VLC ac_vlc_2[16];
+ VLC ac_vlc_3[16];
+ VLC ac_vlc_4[16];
+
+ VLC superblock_run_length_vlc;
+ VLC fragment_run_length_vlc;
+ VLC mode_code_vlc;
+ VLC motion_vector_vlc;
+
+ /* these arrays need to be on 16-byte boundaries since SSE2 operations
+ * index into them */
+ DECLARE_ALIGNED_16(int16_t, qmat[2][4][64]); //<qmat[is_inter][plane]
+
+ /* This table contains superblock_count * 16 entries. Each set of 16
+ * numbers corresponds to the fragment indices 0..15 of the superblock.
+ * An entry will be -1 to indicate that no entry corresponds to that
+ * index. */
+ int *superblock_fragments;
+
+ /* This table contains superblock_count * 4 entries. Each set of 4
+ * numbers corresponds to the macroblock indices 0..3 of the superblock.
+ * An entry will be -1 to indicate that no entry corresponds to that
+ * index. */
+ int *superblock_macroblocks;
+
+ /* This table contains macroblock_count * 6 entries. Each set of 6
+ * numbers corresponds to the fragment indices 0..5 which comprise
+ * the macroblock (4 Y fragments and 2 C fragments). */
+ int *macroblock_fragments;
+ /* This is an array that indicates how a particular macroblock
+ * is coded. */
+ unsigned char *macroblock_coding;
+
+ int first_coded_y_fragment;
+ int first_coded_c_fragment;
+ int last_coded_y_fragment;
+ int last_coded_c_fragment;
+
+ uint8_t edge_emu_buffer[9*2048]; //FIXME dynamic alloc
+ int8_t qscale_table[2048]; //FIXME dynamic alloc (width+15)/16
+
+ /* Huffman decode */
+ int hti;
+ unsigned int hbits;
+ int entries;
+ int huff_code_size;
+ uint16_t huffman_table[80][32][2];
+
+ uint32_t filter_limit_values[64];
+ int bounding_values_array[256];
+} Vp3DecodeContext;
+
+static int theora_decode_tables(AVCodecContext *avctx, GetBitContext *gb);
+
+/************************************************************************
+ * VP3 specific functions
+ ************************************************************************/
+
+/*
+ * This function sets up all of the various blocks mappings:
+ * superblocks <-> fragments, macroblocks <-> fragments,
+ * superblocks <-> macroblocks
+ *
+ * Returns 0 is successful; returns 1 if *anything* went wrong.
+ */
+static int init_block_mapping(Vp3DecodeContext *s)
+{
+ int i, j;
+ signed int hilbert_walk_mb[4];
+
+ int current_fragment = 0;
+ int current_width = 0;
+ int current_height = 0;
+ int right_edge = 0;
+ int bottom_edge = 0;
+ int superblock_row_inc = 0;
+ int *hilbert = NULL;
+ int mapping_index = 0;
+
+ int current_macroblock;
+ int c_fragment;
+
+ 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
+ };
+
+ debug_vp3(" vp3: initialize block mapping tables\n");
+
+ 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++) {
+ debug_init(" superblock %d (u starts @ %d, v starts @ %d)\n",
+ i, s->u_superblock_start, s->v_superblock_start);
+
+ /* 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;
+ debug_init(" mapping fragment %d to superblock %d, position %d (%d/%d x %d/%d)\n",
+ s->superblock_fragments[mapping_index], i, j,
+ current_width, right_edge, current_height, bottom_edge);
+ } else {
+ s->superblock_fragments[mapping_index] = -1;
+ debug_init(" superblock %d, position %d has no fragment (%d/%d x %d/%d)\n",
+ i, j,
+ current_width, right_edge, current_height, bottom_edge);
+ }
+
+ 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);;
+ hilbert = hilbert_walk_mb;
+ 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;
+ debug_init(" mapping macroblock %d to superblock %d, position %d (%d/%d x %d/%d)\n",
+ s->superblock_macroblocks[mapping_index], i, j,
+ current_width, right_edge, current_height, bottom_edge);
+ } else {
+ s->superblock_macroblocks[mapping_index] = -1;
+ debug_init(" superblock %d, position %d has no macroblock (%d/%d x %d/%d)\n",
+ i, j,
+ current_width, right_edge, current_height, bottom_edge);
+ }
+
+ 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) {
+
+ debug_init(" macroblock %d contains fragments: ", current_macroblock);
+ s->all_fragments[current_fragment].macroblock = current_macroblock;
+ s->macroblock_fragments[mapping_index++] = current_fragment;
+ debug_init("%d ", 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;
+ debug_init("%d ", 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;
+ debug_init("%d ", 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;
+ debug_init("%d ", 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;
+ debug_init("%d ", 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;
+ debug_init("%d ", c_fragment);
+
+ debug_init("\n");
+
+ if (j + 2 <= s->fragment_width)
+ current_fragment += 2;
+ else
+ current_fragment++;
+ current_macroblock++;
+ }
+
+ current_fragment += s->fragment_width;
+ }
+
+ 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->all_fragments[i].coeff_count = 0;
+ s->all_fragments[i].motion_x = 127;
+ s->all_fragments[i].motion_y = 127;
+ s->all_fragments[i].next_coeff= NULL;
+ 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.
+ */
+static void init_dequantizer(Vp3DecodeContext *s)
+{
+ int ac_scale_factor = s->coded_ac_scale_factor[s->quality_index];
+ int dc_scale_factor = s->coded_dc_scale_factor[s->quality_index];
+ int i, plane, inter, qri, bmi, bmj, qistart;
+
+ debug_vp3(" vp3: initializing dequantization tables\n");
+
+ for(inter=0; inter<2; inter++){
+ for(plane=0; plane<3; plane++){
+ int sum=0;
+ for(qri=0; qri<s->qr_count[inter][plane]; qri++){
+ sum+= s->qr_size[inter][plane][qri];
+ if(s->quality_index <= sum)
+ break;
+ }
+ qistart= sum - s->qr_size[inter][plane][qri];
+ bmi= s->qr_base[inter][plane][qri ];
+ bmj= s->qr_base[inter][plane][qri+1];
+ for(i=0; i<64; i++){
+ int coeff= ( 2*(sum -s->quality_index)*s->base_matrix[bmi][i]
+ - 2*(qistart-s->quality_index)*s->base_matrix[bmj][i]
+ + s->qr_size[inter][plane][qri])
+ / (2*s->qr_size[inter][plane][qri]);
+
+ int qmin= 8<<(inter + !i);
+ int qscale= i ? ac_scale_factor : dc_scale_factor;
+
+ s->qmat[inter][plane][i]= av_clip((qscale * coeff)/100 * 4, qmin, 4096);
+ }
+ }
+ }
+
+ memset(s->qscale_table, (FFMAX(s->qmat[0][0][1], s->qmat[0][1][1])+8)/16, 512); //FIXME finetune
+}
+
+/*
+ * This function initializes the loop filter boundary limits if the frame's
+ * quality index is different from the previous frame's.
+ */
+static void init_loop_filter(Vp3DecodeContext *s)
+{
+ int *bounding_values= s->bounding_values_array+127;
+ int filter_limit;
+ int x;
+
+ filter_limit = s->filter_limit_values[s->quality_index];
+
+ /* set up the bounding values */
+ memset(s->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;
+ }
+}
+
+/*
+ * This function unpacks all of the superblock/macroblock/fragment coding
+ * information from the bitstream.
+ */
+static int unpack_superblocks(Vp3DecodeContext *s, GetBitContext *gb)
+{
+ 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 i, j;
+ int current_fragment;
+
+ debug_vp3(" vp3: unpacking superblock coding\n");
+
+ if (s->keyframe) {
+
+ debug_vp3(" keyframe-- all superblocks are fully coded\n");
+ memset(s->superblock_coding, SB_FULLY_CODED, s->superblock_count);
+
+ } else {
+
+ /* unpack the list of partially-coded superblocks */
+ bit = get_bits(gb, 1);
+ /* 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;
+ current_run = get_vlc2(gb,
+ s->superblock_run_length_vlc.table, 6, 2);
+ if (current_run == 33)
+ current_run += get_bits(gb, 12);
+ debug_block_coding(" setting superblocks %d..%d to %s\n",
+ current_superblock,
+ current_superblock + current_run - 1,
+ (bit) ? "partially coded" : "not coded");
+
+ /* 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;
+ }
+ }
+ s->superblock_coding[current_superblock++] = bit;
+ }
+
+ /* 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) {
+
+ current_superblock = 0;
+ current_run = 0;
+ bit = get_bits(gb, 1);
+ /* 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) {
+
+ /* 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);
+ }
+
+ debug_block_coding(" setting superblock %d to %s\n",
+ current_superblock,
+ (bit) ? "fully coded" : "not coded");
+ s->superblock_coding[current_superblock] = 2*bit;
+ }
+ current_superblock++;
+ }
+ }
+
+ /* if there were partial blocks, initialize bitstream for
+ * unpacking fragment codings */
+ if (decode_partial_blocks) {
+
+ current_run = 0;
+ bit = get_bits(gb, 1);
+ /* toggle the bit because as soon as the first run length is
+ * fetched the bit will be toggled again */
+ bit ^= 1;
+ }
+ }
+
+ /* 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;
+ memset(s->macroblock_coding, MODE_COPY, s->macroblock_count);
+ for (i = 0; i < s->superblock_count; 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) {
+
+ /* 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) {
+
+ /* fragment may or may not be coded; this is the case
+ * that cares about the fragment coding runs */
+ if (current_run-- == 0) {
+ bit ^= 1;
+ current_run = get_vlc2(gb,
+ s->fragment_run_length_vlc.table, 5, 2);
+ }
+
+ if (bit) {
+ /* 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] =
+ 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;
+ debug_block_coding(" superblock %d is partially coded, fragment %d is coded\n",
+ i, current_fragment);
+ } else {
+ /* not coded; copy this fragment from the prior frame */
+ s->all_fragments[current_fragment].coding_method =
+ MODE_COPY;
+ debug_block_coding(" superblock %d is partially coded, fragment %d is not coded\n",
+ i, current_fragment);
+ }
+
+ } 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;
+ debug_block_coding(" superblock %d is fully coded, fragment %d is coded\n",
+ i, current_fragment);
+ }
+ }
+ }
+ }
+
+ 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;
+
+ debug_block_coding(" %d total coded fragments, y: %d -> %d, c: %d -> %d\n",
+ s->coded_fragment_list_index,
+ s->first_coded_y_fragment,
+ s->last_coded_y_fragment,
+ s->first_coded_c_fragment,
+ s->last_coded_c_fragment);
+
+ return 0;
+}
+
+/*
+ * This function unpacks all the coding mode data for individual macroblocks
+ * from the bitstream.
+ */
+static int unpack_modes(Vp3DecodeContext *s, GetBitContext *gb)
+{
+ int i, j, k;
+ int scheme;
+ int current_macroblock;
+ int current_fragment;
+ int coding_mode;
+
+ debug_vp3(" vp3: unpacking encoding modes\n");
+
+ if (s->keyframe) {
+ debug_vp3(" keyframe-- all blocks are coded as INTRA\n");
+
+ for (i = 0; i < s->fragment_count; i++)
+ s->all_fragments[i].coding_method = MODE_INTRA;
+
+ } else {
+
+ /* fetch the mode coding scheme for this frame */
+ scheme = get_bits(gb, 3);
+ debug_modes(" using mode alphabet %d\n", scheme);
+
+ /* is it a custom coding scheme? */
+ if (scheme == 0) {
+ debug_modes(" custom mode alphabet ahead:\n");
+ for (i = 0; i < 8; i++)
+ ModeAlphabet[scheme][get_bits(gb, 3)] = i;
+ }
+
+ for (i = 0; i < 8; i++)
+ debug_modes(" mode[%d][%d] = %d\n", scheme, i,
+ ModeAlphabet[scheme][i]);
+
+ /* iterate through all of the macroblocks that contain 1 or more
+ * coded fragments */
+ for (i = 0; i < s->u_superblock_start; i++) {
+
+ 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))
+ 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
+ coding_mode = ModeAlphabet[scheme]
+ [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;
+ }
+
+ debug_modes(" coding method for macroblock starting @ fragment %d = %d\n",
+ s->macroblock_fragments[current_macroblock * 6], coding_mode);
+ }
+ }
+ }
+
+ return 0;
+}
+
+/*
+ * This function unpacks all the motion vectors for the individual
+ * macroblocks from the bitstream.
+ */
+static int unpack_vectors(Vp3DecodeContext *s, GetBitContext *gb)
+{
+ int i, j, k;
+ int coding_mode;
+ int motion_x[6];
+ int motion_y[6];
+ 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;
+
+ debug_vp3(" vp3: unpacking motion vectors\n");
+ if (s->keyframe) {
+
+ debug_vp3(" keyframe-- there are no motion vectors\n");
+
+ } else {
+
+ 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_bits(gb, 1);
+ debug_vectors(" using %s scheme for unpacking motion vectors\n",
+ (coding_mode == 0) ? "VLC" : "fixed-length");
+
+ /* iterate through all of the macroblocks that contain 1 or more
+ * coded fragments */
+ for (i = 0; i < s->u_superblock_start; i++) {
+
+ 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))
+ 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:
+ case MODE_GOLDEN_MV:
+ /* all 6 fragments use the same motion vector */
+ if (coding_mode == 0) {
+ motion_x[0] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)];
+ motion_y[0] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)];
+ } else {
+ motion_x[0] = fixed_motion_vector_table[get_bits(gb, 6)];
+ 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) {
+ prior_last_motion_x = last_motion_x;
+ prior_last_motion_y = last_motion_y;
+ last_motion_x = motion_x[0];
+ last_motion_y = motion_y[0];
+ }
+ break;
+
+ case MODE_INTER_FOURMV:
+ /* 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++) {
+ 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)];
+ } else {
+ motion_x[k] = fixed_motion_vector_table[get_bits(gb, 6)];
+ motion_y[k] = fixed_motion_vector_table[get_bits(gb, 6)];
+ }
+ 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);
+
+ /* vector maintenance; vector[3] is treated as the
+ * last vector in this case */
+ prior_last_motion_x = last_motion_x;
+ prior_last_motion_y = last_motion_y;
+ last_motion_x = motion_x[3];
+ last_motion_y = motion_y[3];
+ 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) */
+ break;
+
+ case MODE_INTER_PRIOR_LAST:
+ /* all 6 fragments use the motion vector prior to the
+ * 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;
+ prior_last_motion_y = last_motion_y;
+ last_motion_x = motion_x[0];
+ last_motion_y = motion_y[0];
+ break;
+
+ default:
+ /* covers intra, inter without MV, golden without MV */
+ memset(motion_x, 0, 6 * sizeof(int));
+ memset(motion_y, 0, 6 * sizeof(int));
+
+ /* no vector maintenance */
+ break;
+ }
+
+ /* assign the motion vectors to the correct fragments */
+ debug_vectors(" vectors for macroblock starting @ fragment %d (coding method %d):\n",
+ current_fragment,
+ s->macroblock_coding[current_macroblock]);
+ 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_vectors(): bad fragment number (%d >= %d)\n",
+ current_fragment, s->fragment_count);
+ return 1;
+ }
+ s->all_fragments[current_fragment].motion_x = motion_x[k];
+ s->all_fragments[current_fragment].motion_y = motion_y[k];
+ debug_vectors(" vector %d: fragment %d = (%d, %d)\n",
+ k, current_fragment, motion_x[k], motion_y[k]);
+ }
+ }
+ }
+ }
+
+ return 0;
+}
+
+/*
+ * This function is called by unpack_dct_coeffs() to extract the VLCs from
+ * the bitstream. The VLCs encode tokens which are used to unpack DCT
+ * data. This function unpacks all the VLCs for either the Y plane or both
+ * C planes, and is called for DC coefficients or different AC coefficient
+ * levels (since different coefficient types require different VLC tables.
+ *
+ * This function returns a residual eob run. E.g, if a particular token gave
+ * instructions to EOB the next 5 fragments and there were only 2 fragments
+ * left in the current fragment range, 3 would be returned so that it could
+ * be passed into the next call to this same function.
+ */
+static int unpack_vlcs(Vp3DecodeContext *s, GetBitContext *gb,
+ VLC *table, int coeff_index,
+ int first_fragment, int last_fragment,
+ int eob_run)
+{
+ int i;
+ int token;
+ int zero_run = 0;
+ DCTELEM coeff = 0;
+ Vp3Fragment *fragment;
+ uint8_t *perm= s->scantable.permutated;
+ int bits_to_get;
+
+ if ((first_fragment >= s->fragment_count) ||
+ (last_fragment >= s->fragment_count)) {
+
+ av_log(s->avctx, AV_LOG_ERROR, " vp3:unpack_vlcs(): bad fragment number (%d -> %d ?)\n",
+ first_fragment, last_fragment);
+ return 0;
+ }
+
+ for (i = first_fragment; i <= last_fragment; i++) {
+
+ fragment = &s->all_fragments[s->coded_fragment_list[i]];
+ if (fragment->coeff_count > coeff_index)
+ continue;
+
+ if (!eob_run) {
+ /* decode a VLC into a token */
+ token = get_vlc2(gb, table->table, 5, 3);
+ debug_vlc(" token = %2d, ", token);
+ /* 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;
+ } 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)];
+
+ 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) {
+ fragment->coeff_count += zero_run;
+ if (fragment->coeff_count < 64){
+ fragment->next_coeff->coeff= coeff;
+ fragment->next_coeff->index= perm[fragment->coeff_count++]; //FIXME perm here already?
+ fragment->next_coeff->next= s->next_coeff;
+ s->next_coeff->next=NULL;
+ fragment->next_coeff= s->next_coeff++;
+ }
+ debug_vlc(" fragment %d coeff = %d\n",
+ s->coded_fragment_list[i], fragment->next_coeff[coeff_index]);
+ } else {
+ fragment->coeff_count |= 128;
+ debug_vlc(" fragment %d eob with %d coefficients\n",
+ s->coded_fragment_list[i], fragment->coeff_count&127);
+ eob_run--;
+ }
+ }
+
+ return eob_run;
+}
+
+/*
+ * This function unpacks all of the DCT coefficient data from the
+ * bitstream.
+ */
+static int unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb)
+{
+ int i;
+ int dc_y_table;
+ int dc_c_table;
+ int ac_y_table;
+ int ac_c_table;
+ int residual_eob_run = 0;
+
+ /* fetch the DC table indices */
+ dc_y_table = get_bits(gb, 4);
+ dc_c_table = get_bits(gb, 4);
+
+ /* unpack the Y plane DC coefficients */
+ debug_vp3(" vp3: unpacking Y plane DC coefficients using table %d\n",
+ dc_y_table);
+ 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);
+
+ /* unpack the C plane DC coefficients */
+ debug_vp3(" vp3: unpacking C plane DC coefficients using table %d\n",
+ dc_c_table);
+ 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);
+
+ /* fetch the AC table indices */
+ ac_y_table = get_bits(gb, 4);
+ ac_c_table = get_bits(gb, 4);
+
+ /* unpack the group 1 AC coefficients (coeffs 1-5) */
+ for (i = 1; i <= 5; i++) {
+
+ debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n",
+ i, ac_y_table);
+ 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);
+
+ debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n",
+ i, ac_c_table);
+ 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);
+ }
+
+ /* unpack the group 2 AC coefficients (coeffs 6-14) */
+ for (i = 6; i <= 14; i++) {
+
+ debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n",
+ i, ac_y_table);
+ 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);
+
+ debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n",
+ i, ac_c_table);
+ 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);
+ }
+
+ /* unpack the group 3 AC coefficients (coeffs 15-27) */
+ for (i = 15; i <= 27; i++) {
+
+ debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n",
+ i, ac_y_table);
+ 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);
+
+ debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n",
+ i, ac_c_table);
+ 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);
+ }
+
+ /* unpack the group 4 AC coefficients (coeffs 28-63) */
+ for (i = 28; i <= 63; i++) {
+
+ debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n",
+ i, ac_y_table);
+ 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);
+
+ debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n",
+ i, ac_c_table);
+ 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);
+ }
+
+ return 0;
+}
+
+/*
+ * This function reverses the DC prediction for each coded fragment in
+ * the frame. Much of this function is adapted directly from the original
+ * VP3 source code.
+ */
+#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
+
+static void reverse_dc_prediction(Vp3DecodeContext *s,
+ int first_fragment,
+ int fragment_width,
+ int fragment_height)
+{
+
+#define PUL 8
+#define PU 4
+#define PUR 2
+#define PL 1
+
+ int x, y;
+ int i = first_fragment;
+
+ int predicted_dc;
+
+ /* DC values for the left, up-left, up, and up-right fragments */
+ int vl, vul, vu, vur;
+
+ /* indices for the left, up-left, up, and up-right fragments */
+ int l, ul, u, ur;
+
+ /*
+ * The 6 fields mean:
+ * 0: up-left multiplier
+ * 1: up multiplier
+ * 2: up-right multiplier
+ * 3: left multiplier
+ */
+ int predictor_transform[16][4] = {
+ { 0, 0, 0, 0},
+ { 0, 0, 0,128}, // PL
+ { 0, 0,128, 0}, // PUR
+ { 0, 0, 53, 75}, // PUR|PL
+ { 0,128, 0, 0}, // PU
+ { 0, 64, 0, 64}, // PU|PL
+ { 0,128, 0, 0}, // PU|PUR
+ { 0, 0, 53, 75}, // PU|PUR|PL
+ {128, 0, 0, 0}, // PUL
+ { 0, 0, 0,128}, // PUL|PL
+ { 64, 0, 64, 0}, // PUL|PUR
+ { 0, 0, 53, 75}, // PUL|PUR|PL
+ { 0,128, 0, 0}, // PUL|PU
+ {-104,116, 0,116}, // PUL|PU|PL
+ { 24, 80, 24, 0}, // PUL|PU|PUR
+ {-104,116, 0,116} // PUL|PU|PUR|PL
+ };
+
+ /* This table shows which types of blocks can use other blocks for
+ * prediction. For example, INTRA is the only mode in this table to
+ * have a frame number of 0. That means INTRA blocks can only predict
+ * 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] = {
+ 1, /* MODE_INTER_NO_MV */
+ 0, /* MODE_INTRA */
+ 1, /* MODE_INTER_PLUS_MV */
+ 1, /* MODE_INTER_LAST_MV */
+ 1, /* MODE_INTER_PRIOR_MV */
+ 2, /* MODE_USING_GOLDEN */
+ 2, /* MODE_GOLDEN_MV */
+ 1 /* MODE_INTER_FOUR_MV */
+ };
+ int current_frame_type;
+
+ /* there is a last DC predictor for each of the 3 frame types */
+ short last_dc[3];
+
+ int transform = 0;
+
+ debug_vp3(" vp3: reversing DC prediction\n");
+
+ vul = vu = vur = vl = 0;
+ last_dc[0] = last_dc[1] = last_dc[2] = 0;
+
+ /* for each fragment row... */
+ for (y = 0; y < fragment_height; y++) {
+
+ /* for each fragment in a row... */
+ for (x = 0; x < fragment_width; x++, i++) {
+
+ /* reverse prediction if this block was coded */
+ if (s->all_fragments[i].coding_method != MODE_COPY) {
+
+ current_frame_type =
+ compatible_frame[s->all_fragments[i].coding_method];
+ debug_dc_pred(" frag %d: orig DC = %d, ",
+ i, DC_COEFF(i));
+
+ transform= 0;
+ if(x){
+ l= i-1;
+ vl = DC_COEFF(l);
+ if(FRAME_CODED(l) && COMPATIBLE_FRAME(l))
+ transform |= PL;
+ }
+ if(y){
+ u= i-fragment_width;
+ vu = DC_COEFF(u);
+ if(FRAME_CODED(u) && COMPATIBLE_FRAME(u))
+ transform |= PU;
+ if(x){
+ ul= i-fragment_width-1;
+ vul = DC_COEFF(ul);
+ if(FRAME_CODED(ul) && 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))
+ transform |= PUR;
+ }
+ }
+
+ debug_dc_pred("transform = %d, ", transform);
+
+ if (transform == 0) {
+
+ /* if there were no fragments to predict from, use last
+ * DC saved */
+ predicted_dc = last_dc[current_frame_type];
+ debug_dc_pred("from last DC (%d) = %d\n",
+ current_frame_type, DC_COEFF(i));
+
+ } else {
+
+ /* apply the appropriate predictor transform */
+ predicted_dc =
+ (predictor_transform[transform][0] * vul) +
+ (predictor_transform[transform][1] * vu) +
+ (predictor_transform[transform][2] * vur) +
+ (predictor_transform[transform][3] * vl);
+
+ predicted_dc /= 128;
+
+ /* check for outranging on the [ul u l] and
+ * [ul u ur l] predictors */
+ if ((transform == 13) || (transform == 15)) {
+ if (FFABS(predicted_dc - vu) > 128)
+ predicted_dc = vu;
+ else if (FFABS(predicted_dc - vl) > 128)
+ predicted_dc = vl;
+ else if (FFABS(predicted_dc - vul) > 128)
+ predicted_dc = vul;
+ }
+
+ debug_dc_pred("from pred DC = %d\n",
+ DC_COEFF(i));
+ }
+
+ /* 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;
+ /* save the DC */
+ last_dc[current_frame_type] = DC_COEFF(i);
+ if(DC_COEFF(i) && !(s->all_fragments[i].coeff_count&127)){
+ s->all_fragments[i].coeff_count= 129;
+// s->all_fragments[i].next_coeff= s->next_coeff;
+ s->coeffs[i].next= s->next_coeff;
+ (s->next_coeff++)->next=NULL;
+ }
+ }
+ }
+ }
+}
+
+
+static void horizontal_filter(unsigned char *first_pixel, int stride,
+ int *bounding_values);
+static void vertical_filter(unsigned char *first_pixel, int stride,
+ int *bounding_values);
+
+/*
+ * Perform the final rendering for a particular slice of data.
+ * The slice number ranges from 0..(macroblock_height - 1).
+ */
+static void render_slice(Vp3DecodeContext *s, int slice)
+{
+ int x;
+ int m, n;
+ int16_t *dequantizer;
+ DECLARE_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;
+
+ if (slice >= s->macroblock_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];
+ 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];
+
+ if (!s->flipped_image) stride = -stride;
+
+
+ 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 fragment in a row... */
+ for (x = 0; x < plane_width; x += 8, i++) {
+
+ if ((i < 0) || (i >= s->fragment_count)) {
+ av_log(s->avctx, AV_LOG_ERROR, " vp3:render_slice(): bad fragment number (%d)\n", i);
+ return;
+ }
+
+ /* 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_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_halfpel_index = 0;
+
+ /* sort out the motion vector if this fragment is coded
+ * using a motion vector method */
+ 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);
+ }
+
+ 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);
+
+ motion_halfpel_index = motion_x & 0x01;
+ motion_source += (motion_x >> 1);
+
+ motion_halfpel_index |= (motion_y & 0x01) << 1;
+ motion_source += ((motion_y >> 1) * stride);
+
+ if(src_x<0 || src_y<0 || src_x + 9 >= plane_width || src_y + 9 >= plane_height){
+ uint8_t *temp= s->edge_emu_buffer;
+ if(stride<0) temp -= 9*stride;
+ else temp += 9*stride;
+
+ ff_emulated_edge_mc(temp, motion_source, stride, 9, 9, src_x, src_y, plane_width, plane_height);
+ motion_source= temp;
+ }
+ }
+
+
+ /* first, take care of copying a block from either the
+ * previous or the golden frame */
+ if (s->all_fragments[i].coding_method != MODE_INTRA) {
+ /* Note, it is possible to implement all MC cases with
+ put_no_rnd_pixels_l2 which would look more like the
+ VP3 source but this would be slower as
+ 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,
+ 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,
+ motion_source - d,
+ motion_source + stride + 1 + d,
+ stride, 8);
+ }
+ dequantizer = s->qmat[1][plane];
+ }else{
+ dequantizer = s->qmat[0][plane];
+ }
+
+ /* dequantize the DCT coefficients */
+ debug_idct("fragment %d, coding mode %d, DC = %d, dequant = %d:\n",
+ i, s->all_fragments[i].coding_method,
+ DC_COEFF(i), dequantizer[0]);
+
+ if(s->avctx->idct_algo==FF_IDCT_VP3){
+ Coeff *coeff= s->coeffs + i;
+ memset(block, 0, sizeof(block));
+ while(coeff->next){
+ block[coeff->index]= coeff->coeff * dequantizer[coeff->index];
+ coeff= coeff->next;
+ }
+ }else{
+ Coeff *coeff= s->coeffs + i;
+ memset(block, 0, sizeof(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) {
+ if(s->avctx->idct_algo!=FF_IDCT_VP3)
+ block[0] += 128<<3;
+ s->dsp.idct_put(
+ output_plane + s->all_fragments[i].first_pixel,
+ stride,
+ block);
+ } else {
+ s->dsp.idct_add(
+ output_plane + s->all_fragments[i].first_pixel,
+ stride,
+ block);
+ }
+
+ debug_idct("block after idct_%s():\n",
+ (s->all_fragments[i].coding_method == MODE_INTRA)?
+ "put" : "add");
+ for (m = 0; m < 8; m++) {
+ for (n = 0; n < 8; n++) {
+ debug_idct(" %3d", *(output_plane +
+ s->all_fragments[i].first_pixel + (m * stride + n)));
+ }
+ debug_idct("\n");
+ }
+ debug_idct("\n");
+
+ } 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,
+ 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
+ }
+ }
+ }
+
+ /* this looks like a good place for slice dispatch... */
+ /* algorithm:
+ * if (slice == s->macroblock_height - 1)
+ * dispatch (both last slice & 2nd-to-last slice);
+ * else if (slice > 0)
+ * dispatch (slice - 1);
+ */
+
+ emms_c();
+}
+
+static void horizontal_filter(unsigned char *first_pixel, int stride,
+ int *bounding_values)
+{
+ unsigned char *end;
+ int filter_value;
+
+ for (end= first_pixel + 8*stride; first_pixel != end; first_pixel += stride) {
+ filter_value =
+ (first_pixel[-2] - first_pixel[ 1])
+ +3*(first_pixel[ 0] - first_pixel[-1]);
+ filter_value = bounding_values[(filter_value + 4) >> 3];
+ first_pixel[-1] = av_clip_uint8(first_pixel[-1] + filter_value);
+ first_pixel[ 0] = av_clip_uint8(first_pixel[ 0] - filter_value);
+ }
+}
+
+static void vertical_filter(unsigned char *first_pixel, int stride,
+ int *bounding_values)
+{
+ unsigned char *end;
+ int filter_value;
+ const int nstride= -stride;
+
+ for (end= first_pixel + 8; first_pixel < end; first_pixel++) {
+ filter_value =
+ (first_pixel[2 * nstride] - first_pixel[ stride])
+ +3*(first_pixel[0 ] - first_pixel[nstride]);
+ filter_value = bounding_values[(filter_value + 4) >> 3];
+ first_pixel[nstride] = av_clip_uint8(first_pixel[nstride] + filter_value);
+ first_pixel[0] = av_clip_uint8(first_pixel[0] - filter_value);
+ }
+}
+
+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++) {
+START_TIMER
+ /* do not perform left edge filter for left columns frags */
+ if ((x > 0) &&
+ (s->all_fragments[fragment].coding_method != MODE_COPY)) {
+ horizontal_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)) {
+ vertical_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)) {
+ horizontal_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)) {
+ vertical_filter(
+ plane_data + s->all_fragments[fragment + width].first_pixel,
+ stride, bounding_values);
+ }
+
+ fragment++;
+STOP_TIMER("loop filter")
+ }
+ }
+ }
+}
+
+/*
+ * 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)
+{
+
+ int i, x, y;
+
+ /* figure out the first pixel addresses for each of the fragments */
+ /* Y plane */
+ i = 0;
+ for (y = s->fragment_height; y > 0; y--) {
+ 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;
+ debug_init(" fragment %d, first pixel @ %d\n",
+ i-1, s->all_fragments[i-1].first_pixel);
+ }
+ }
+
+ /* U plane */
+ i = s->fragment_start[1];
+ for (y = s->fragment_height / 2; y > 0; y--) {
+ 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;
+ debug_init(" fragment %d, first pixel @ %d\n",
+ i-1, s->all_fragments[i-1].first_pixel);
+ }
+ }
+
+ /* V plane */
+ i = s->fragment_start[2];
+ for (y = s->fragment_height / 2; y > 0; y--) {
+ 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;
+ debug_init(" fragment %d, first pixel @ %d\n",
+ i-1, s->all_fragments[i-1].first_pixel);
+ }
+ }
+}
+
+/* FIXME: this should be merged with the above! */
+static void theora_calculate_pixel_addresses(Vp3DecodeContext *s)
+{
+
+ int i, x, y;
+
+ /* figure out the first pixel addresses for each of the fragments */
+ /* Y plane */
+ i = 0;
+ for (y = 1; y <= s->fragment_height; y++) {
+ 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;
+ debug_init(" fragment %d, first pixel @ %d\n",
+ i-1, s->all_fragments[i-1].first_pixel);
+ }
+ }
+
+ /* U plane */
+ i = s->fragment_start[1];
+ for (y = 1; y <= s->fragment_height / 2; y++) {
+ 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;
+ debug_init(" fragment %d, first pixel @ %d\n",
+ i-1, s->all_fragments[i-1].first_pixel);
+ }
+ }
+
+ /* V plane */
+ i = s->fragment_start[2];
+ for (y = 1; y <= s->fragment_height / 2; y++) {
+ 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;
+ debug_init(" fragment %d, first pixel @ %d\n",
+ i-1, s->all_fragments[i-1].first_pixel);
+ }
+ }
+}
+
+/*
+ * This is the ffmpeg/libavcodec API init function.
+ */
+static int vp3_decode_init(AVCodecContext *avctx)
+{
+ Vp3DecodeContext *s = avctx->priv_data;
+ int i, inter, plane;
+ int c_width;
+ int c_height;
+ int y_superblock_count;
+ int c_superblock_count;
+
+ if (avctx->codec_tag == MKTAG('V','P','3','0'))
+ s->version = 0;
+ else
+ s->version = 1;
+
+ s->avctx = avctx;
+ s->width = (avctx->width + 15) & 0xFFFFFFF0;
+ s->height = (avctx->height + 15) & 0xFFFFFFF0;
+ avctx->pix_fmt = PIX_FMT_YUV420P;
+ avctx->has_b_frames = 0;
+ if(avctx->idct_algo==FF_IDCT_AUTO)
+ avctx->idct_algo=FF_IDCT_VP3;
+ dsputil_init(&s->dsp, avctx);
+
+ ff_init_scantable(s->dsp.idct_permutation, &s->scantable, ff_zigzag_direct);
+
+ /* initialize to an impossible value which will force a recalculation
+ * in the first frame decode */
+ s->quality_index = -1;
+
+ 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;
+
+ /* work out the dimensions for the C planes */
+ c_width = s->width / 2;
+ c_height = s->height / 2;
+ 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->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_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;
+
+ /* 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;
+
+ debug_init(" Y plane: %d x %d\n", s->width, s->height);
+ debug_init(" C plane: %d x %d\n", c_width, c_height);
+ debug_init(" Y superblocks: %d x %d, %d total\n",
+ s->y_superblock_width, s->y_superblock_height, y_superblock_count);
+ debug_init(" C superblocks: %d x %d, %d total\n",
+ s->c_superblock_width, s->c_superblock_height, c_superblock_count);
+ debug_init(" total superblocks = %d, U starts @ %d, V starts @ %d\n",
+ s->superblock_count, s->u_superblock_start, s->v_superblock_start);
+ debug_init(" macroblocks: %d x %d, %d total\n",
+ s->macroblock_width, s->macroblock_height, s->macroblock_count);
+ debug_init(" %d fragments, %d x %d, u starts @ %d, v starts @ %d\n",
+ s->fragment_count,
+ s->fragment_width,
+ s->fragment_height,
+ s->fragment_start[1],
+ s->fragment_start[2]);
+
+ s->all_fragments = av_malloc(s->fragment_count * sizeof(Vp3Fragment));
+ s->coeffs = av_malloc(s->fragment_count * sizeof(Coeff) * 65);
+ s->coded_fragment_list = av_malloc(s->fragment_count * sizeof(int));
+ s->pixel_addresses_inited = 0;
+
+ if (!s->theora_tables)
+ {
+ for (i = 0; i < 64; i++) {
+ s->coded_dc_scale_factor[i] = vp31_dc_scale_factor[i];
+ s->coded_ac_scale_factor[i] = vp31_ac_scale_factor[i];
+ s->base_matrix[0][i] = vp31_intra_y_dequant[i];
+ s->base_matrix[1][i] = vp31_intra_c_dequant[i];
+ s->base_matrix[2][i] = vp31_inter_dequant[i];
+ s->filter_limit_values[i] = vp31_filter_limit_values[i];
+ }
+
+ for(inter=0; inter<2; inter++){
+ for(plane=0; plane<3; plane++){
+ s->qr_count[inter][plane]= 1;
+ s->qr_size [inter][plane][0]= 63;
+ s->qr_base [inter][plane][0]=
+ s->qr_base [inter][plane][1]= 2*inter + (!!plane)*!inter;
+ }
+ }
+
+ /* init VLC tables */
+ for (i = 0; i < 16; i++) {
+
+ /* DC histograms */
+ init_vlc(&s->dc_vlc[i], 5, 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,
+ &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,
+ &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,
+ &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,
+ &ac_bias_3[i][0][1], 4, 2,
+ &ac_bias_3[i][0][0], 4, 2, 0);
+ }
+ } else {
+ for (i = 0; i < 16; i++) {
+
+ /* DC histograms */
+ 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);
+
+ /* group 1 AC histograms */
+ 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);
+
+ /* group 2 AC histograms */
+ 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);
+
+ /* group 3 AC histograms */
+ 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);
+
+ /* group 4 AC histograms */
+ 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);
+ }
+ }
+
+ init_vlc(&s->superblock_run_length_vlc, 6, 34,
+ &superblock_run_length_vlc_table[0][1], 4, 2,
+ &superblock_run_length_vlc_table[0][0], 4, 2, 0);
+
+ init_vlc(&s->fragment_run_length_vlc, 5, 30,
+ &fragment_run_length_vlc_table[0][1], 4, 2,
+ &fragment_run_length_vlc_table[0][0], 4, 2, 0);
+
+ init_vlc(&s->mode_code_vlc, 3, 8,
+ &mode_code_vlc_table[0][1], 2, 1,
+ &mode_code_vlc_table[0][0], 2, 1, 0);
+
+ init_vlc(&s->motion_vector_vlc, 6, 63,
+ &motion_vector_vlc_table[0][1], 2, 1,
+ &motion_vector_vlc_table[0][0], 2, 1, 0);
+
+ /* 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);
+ init_block_mapping(s);
+
+ for (i = 0; i < 3; i++) {
+ s->current_frame.data[i] = NULL;
+ s->last_frame.data[i] = NULL;
+ s->golden_frame.data[i] = NULL;
+ }
+
+ return 0;
+}
+
+/*
+ * This is the ffmpeg/libavcodec API frame decode function.
+ */
+static int vp3_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ Vp3DecodeContext *s = avctx->priv_data;
+ GetBitContext gb;
+ static int counter = 0;
+ int i;
+
+ init_get_bits(&gb, buf, buf_size * 8);
+
+ if (s->theora && get_bits1(&gb))
+ {
+#if 1
+ av_log(avctx, AV_LOG_ERROR, "Header packet passed to frame decoder, skipping\n");
+ return -1;
+#else
+ int ptype = get_bits(&gb, 7);
+
+ skip_bits(&gb, 6*8); /* "theora" */
+
+ switch(ptype)
+ {
+ case 1:
+ theora_decode_comments(avctx, &gb);
+ break;
+ case 2:
+ theora_decode_tables(avctx, &gb);
+ init_dequantizer(s);
+ break;
+ default:
+ av_log(avctx, AV_LOG_ERROR, "Unknown Theora config packet: %d\n", ptype);
+ }
+ return buf_size;
+#endif
+ }
+
+ s->keyframe = !get_bits1(&gb);
+ if (!s->theora)
+ skip_bits(&gb, 1);
+ s->last_quality_index = s->quality_index;
+
+ s->nqis=0;
+ do{
+ s->qis[s->nqis++]= get_bits(&gb, 6);
+ } while(s->theora >= 0x030200 && s->nqis<3 && get_bits1(&gb));
+
+ s->quality_index= s->qis[0];
+
+ if (s->avctx->debug & FF_DEBUG_PICT_INFO)
+ av_log(s->avctx, AV_LOG_INFO, " VP3 %sframe #%d: Q index = %d\n",
+ s->keyframe?"key":"", counter, s->quality_index);
+ counter++;
+
+ if (s->quality_index != s->last_quality_index) {
+ init_dequantizer(s);
+ init_loop_filter(s);
+ }
+
+ if (s->keyframe) {
+ if (!s->theora)
+ {
+ skip_bits(&gb, 4); /* width code */
+ skip_bits(&gb, 4); /* height code */
+ if (s->version)
+ {
+ s->version = get_bits(&gb, 5);
+ if (counter == 1)
+ av_log(s->avctx, AV_LOG_DEBUG, "VP version: %d\n", s->version);
+ }
+ }
+ if (s->version || s->theora)
+ {
+ if (get_bits1(&gb))
+ 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_inited)
+ {
+ if (!s->flipped_image)
+ vp3_calculate_pixel_addresses(s);
+ else
+ theora_calculate_pixel_addresses(s);
+ s->pixel_addresses_inited = 1;
+ }
+ } else {
+ /* allocate a new current frame */
+ s->current_frame.reference = 3;
+ if (!s->pixel_addresses_inited) {
+ 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;
+ }
+ }
+
+ s->current_frame.qscale_table= s->qscale_table; //FIXME allocate individual tables per AVFrame
+ s->current_frame.qstride= 0;
+
+ {START_TIMER
+ init_frame(s, &gb);
+ STOP_TIMER("init_frame")}
+
+#if KEYFRAMES_ONLY
+if (!s->keyframe) {
+
+ memcpy(s->current_frame.data[0], s->golden_frame.data[0],
+ s->current_frame.linesize[0] * s->height);
+ memcpy(s->current_frame.data[1], s->golden_frame.data[1],
+ s->current_frame.linesize[1] * s->height / 2);
+ memcpy(s->current_frame.data[2], s->golden_frame.data[2],
+ s->current_frame.linesize[2] * s->height / 2);
+
+} else {
+#endif
+
+ {START_TIMER
+ if (unpack_superblocks(s, &gb)){
+ av_log(s->avctx, AV_LOG_ERROR, "error in unpack_superblocks\n");
+ return -1;
+ }
+ STOP_TIMER("unpack_superblocks")}
+ {START_TIMER
+ if (unpack_modes(s, &gb)){
+ av_log(s->avctx, AV_LOG_ERROR, "error in unpack_modes\n");
+ return -1;
+ }
+ STOP_TIMER("unpack_modes")}
+ {START_TIMER
+ if (unpack_vectors(s, &gb)){
+ av_log(s->avctx, AV_LOG_ERROR, "error in unpack_vectors\n");
+ return -1;
+ }
+ STOP_TIMER("unpack_vectors")}
+ {START_TIMER
+ if (unpack_dct_coeffs(s, &gb)){
+ av_log(s->avctx, AV_LOG_ERROR, "error in unpack_dct_coeffs\n");
+ return -1;
+ }
+ STOP_TIMER("unpack_dct_coeffs")}
+ {START_TIMER
+
+ 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);
+ }
+ STOP_TIMER("reverse_dc_prediction")}
+ {START_TIMER
+
+ for (i = 0; i < s->macroblock_height; i++)
+ render_slice(s, i);
+ STOP_TIMER("render_fragments")}
+
+ {START_TIMER
+ apply_loop_filter(s);
+ STOP_TIMER("apply_loop_filter")}
+#if KEYFRAMES_ONLY
+}
+#endif
+
+ *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]))
+ avctx->release_buffer(avctx, &s->last_frame);
+
+ /* shuffle frames (last = current) */
+ s->last_frame= s->current_frame;
+ s->current_frame.data[0]= NULL; /* ensure that we catch any access to this released frame */
+
+ return buf_size;
+}
+
+/*
+ * This is the ffmpeg/libavcodec API module cleanup function.
+ */
+static int vp3_decode_end(AVCodecContext *avctx)
+{
+ Vp3DecodeContext *s = avctx->priv_data;
+
+ av_free(s->all_fragments);
+ av_free(s->coeffs);
+ av_free(s->coded_fragment_list);
+ av_free(s->superblock_fragments);
+ av_free(s->superblock_macroblocks);
+ av_free(s->macroblock_fragments);
+ av_free(s->macroblock_coding);
+
+ /* release all frames */
+ if (s->golden_frame.data[0] && s->golden_frame.data[0] != s->last_frame.data[0])
+ avctx->release_buffer(avctx, &s->golden_frame);
+ if (s->last_frame.data[0])
+ 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 */
+
+ return 0;
+}
+
+static int read_huffman_tree(AVCodecContext *avctx, GetBitContext *gb)
+{
+ Vp3DecodeContext *s = avctx->priv_data;
+
+ if (get_bits(gb, 1)) {
+ int token;
+ if (s->entries >= 32) { /* overflow */
+ av_log(avctx, AV_LOG_ERROR, "huffman tree overflow\n");
+ return -1;
+ }
+ token = get_bits(gb, 5);
+ //av_log(avctx, AV_LOG_DEBUG, "hti %d hbits %x token %d entry : %d size %d\n", s->hti, s->hbits, token, s->entries, s->huff_code_size);
+ s->huffman_table[s->hti][token][0] = s->hbits;
+ s->huffman_table[s->hti][token][1] = s->huff_code_size;
+ s->entries++;
+ }
+ else {
+ if (s->huff_code_size >= 32) {/* overflow */
+ av_log(avctx, AV_LOG_ERROR, "huffman tree overflow\n");
+ return -1;
+ }
+ s->huff_code_size++;
+ s->hbits <<= 1;
+ read_huffman_tree(avctx, gb);
+ s->hbits |= 1;
+ read_huffman_tree(avctx, gb);
+ s->hbits >>= 1;
+ s->huff_code_size--;
+ }
+ return 0;
+}
+
+static int theora_decode_header(AVCodecContext *avctx, GetBitContext *gb)
+{
+ Vp3DecodeContext *s = avctx->priv_data;
+
+ s->theora = get_bits_long(gb, 24);
+ av_log(avctx, AV_LOG_INFO, "Theora bitstream version %X\n", s->theora);
+
+ /* 3.2.0 aka alpha3 has the same frame orientation as original vp3 */
+ /* but previous versions have the image flipped relative to vp3 */
+ if (s->theora < 0x030200)
+ {
+ s->flipped_image = 1;
+ av_log(avctx, AV_LOG_DEBUG, "Old (<alpha3) Theora bitstream, flipped image\n");
+ }
+
+ s->width = get_bits(gb, 16) << 4;
+ s->height = get_bits(gb, 16) << 4;
+
+ if(avcodec_check_dimensions(avctx, s->width, s->height)){
+ av_log(avctx, AV_LOG_ERROR, "Invalid dimensions (%dx%d)\n", s->width, s->height);
+ s->width= s->height= 0;
+ 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 */
+
+ skip_bits(gb, 24); /* frame width */
+ skip_bits(gb, 24); /* frame height */
+ }
+ else
+ {
+ skip_bits(gb, 24); /* frame width */
+ skip_bits(gb, 24); /* frame height */
+ }
+
+ if (s->theora >= 0x030200) {
+ skip_bits(gb, 8); /* offset x */
+ skip_bits(gb, 8); /* offset y */
+ }
+
+ skip_bits(gb, 32); /* fps numerator */
+ skip_bits(gb, 32); /* fps denumerator */
+ skip_bits(gb, 24); /* aspect numerator */
+ skip_bits(gb, 24); /* aspect denumerator */
+
+ 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 */
+ skip_bits(gb, 24); /* bitrate */
+
+ skip_bits(gb, 6); /* quality hint */
+
+ if (s->theora >= 0x030200)
+ {
+ skip_bits(gb, 5); /* keyframe frequency force */
+
+ if (s->theora < 0x030400)
+ skip_bits(gb, 5); /* spare bits */
+ }
+
+// align_get_bits(gb);
+
+ avctx->width = s->width;
+ avctx->height = s->height;
+
+ return 0;
+}
+
+static int theora_decode_tables(AVCodecContext *avctx, GetBitContext *gb)
+{
+ Vp3DecodeContext *s = avctx->priv_data;
+ int i, n, matrices, inter, plane;
+
+ if (s->theora >= 0x030200) {
+ n = get_bits(gb, 3);
+ /* loop filter limit values table */
+ for (i = 0; i < 64; i++)
+ s->filter_limit_values[i] = get_bits(gb, n);
+ }
+
+ if (s->theora >= 0x030200)
+ n = get_bits(gb, 4) + 1;
+ else
+ n = 16;
+ /* quality threshold table */
+ for (i = 0; i < 64; i++)
+ s->coded_ac_scale_factor[i] = get_bits(gb, n);
+
+ if (s->theora >= 0x030200)
+ n = get_bits(gb, 4) + 1;
+ else
+ n = 16;
+ /* dc scale factor table */
+ for (i = 0; i < 64; i++)
+ s->coded_dc_scale_factor[i] = get_bits(gb, n);
+
+ if (s->theora >= 0x030200)
+ matrices = get_bits(gb, 9) + 1;
+ else
+ matrices = 3;
+
+ if(matrices > 384){
+ av_log(avctx, AV_LOG_ERROR, "invalid number of base matrixes\n");
+ return -1;
+ }
+
+ for(n=0; n<matrices; n++){
+ for (i = 0; i < 64; i++)
+ s->base_matrix[n][i]= get_bits(gb, 8);
+ }
+
+ for (inter = 0; inter <= 1; inter++) {
+ for (plane = 0; plane <= 2; plane++) {
+ int newqr= 1;
+ if (inter || plane > 0)
+ newqr = get_bits(gb, 1);
+ if (!newqr) {
+ int qtj, plj;
+ if(inter && get_bits(gb, 1)){
+ qtj = 0;
+ plj = plane;
+ }else{
+ qtj= (3*inter + plane - 1) / 3;
+ plj= (plane + 2) % 3;
+ }
+ s->qr_count[inter][plane]= s->qr_count[qtj][plj];
+ memcpy(s->qr_size[inter][plane], s->qr_size[qtj][plj], sizeof(s->qr_size[0][0]));
+ memcpy(s->qr_base[inter][plane], s->qr_base[qtj][plj], sizeof(s->qr_base[0][0]));
+ } else {
+ int qri= 0;
+ int qi = 0;
+
+ for(;;){
+ i= get_bits(gb, av_log2(matrices-1)+1);
+ if(i>= matrices){
+ av_log(avctx, AV_LOG_ERROR, "invalid base matrix index\n");
+ return -1;
+ }
+ s->qr_base[inter][plane][qri]= i;
+ if(qi >= 63)
+ break;
+ i = get_bits(gb, av_log2(63-qi)+1) + 1;
+ s->qr_size[inter][plane][qri++]= i;
+ qi += i;
+ }
+
+ if (qi > 63) {
+ av_log(avctx, AV_LOG_ERROR, "invalid qi %d > 63\n", qi);
+ return -1;
+ }
+ s->qr_count[inter][plane]= qri;
+ }
+ }
+ }
+
+ /* Huffman tables */
+ for (s->hti = 0; s->hti < 80; s->hti++) {
+ s->entries = 0;
+ s->huff_code_size = 1;
+ if (!get_bits(gb, 1)) {
+ s->hbits = 0;
+ read_huffman_tree(avctx, gb);
+ s->hbits = 1;
+ read_huffman_tree(avctx, gb);
+ }
+ }
+
+ s->theora_tables = 1;
+
+ return 0;
+}
+
+#if ENABLE_THEORA_DECODER
+static int theora_decode_init(AVCodecContext *avctx)
+{
+ Vp3DecodeContext *s = avctx->priv_data;
+ GetBitContext gb;
+ int ptype;
+ uint8_t *header_start[3];
+ int header_len[3];
+ int i;
+
+ s->theora = 1;
+
+ if (!avctx->extradata_size)
+ {
+ av_log(avctx, AV_LOG_ERROR, "Missing extradata!\n");
+ return -1;
+ }
+
+ if (ff_split_xiph_headers(avctx->extradata, avctx->extradata_size,
+ 42, header_start, header_len) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "Corrupt extradata\n");
+ return -1;
+ }
+
+ for(i=0;i<3;i++) {
+ init_get_bits(&gb, header_start[i], header_len[i]);
+
+ ptype = get_bits(&gb, 8);
+ debug_vp3("Theora headerpacket type: %x\n", ptype);
+
+ if (!(ptype & 0x80))
+ {
+ av_log(avctx, AV_LOG_ERROR, "Invalid extradata!\n");
+// return -1;
+ }
+
+ // FIXME: Check for this as well.
+ skip_bits(&gb, 6*8); /* "theora" */
+
+ switch(ptype)
+ {
+ case 0x80:
+ theora_decode_header(avctx, &gb);
+ break;
+ case 0x81:
+// FIXME: is this needed? it breaks sometimes
+// theora_decode_comments(avctx, gb);
+ break;
+ case 0x82:
+ theora_decode_tables(avctx, &gb);
+ break;
+ default:
+ av_log(avctx, AV_LOG_ERROR, "Unknown Theora config packet: %d\n", ptype&~0x80);
+ break;
+ }
+ if(8*header_len[i] != get_bits_count(&gb))
+ av_log(avctx, AV_LOG_ERROR, "%d bits left in packet %X\n", 8*header_len[i] - get_bits_count(&gb), ptype);
+ if (s->theora < 0x030200)
+ break;
+ }
+
+ vp3_decode_init(avctx);
+ return 0;
+}
+#endif
+
+AVCodec vp3_decoder = {
+ "vp3",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_VP3,
+ sizeof(Vp3DecodeContext),
+ vp3_decode_init,
+ NULL,
+ vp3_decode_end,
+ vp3_decode_frame,
+ 0,
+ NULL
+};
+
+#if ENABLE_THEORA_DECODER
+AVCodec theora_decoder = {
+ "theora",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_THEORA,
+ sizeof(Vp3DecodeContext),
+ theora_decode_init,
+ NULL,
+ vp3_decode_end,
+ vp3_decode_frame,
+ 0,
+ NULL
+};
+#endif
diff --git a/src/libffmpeg/libavcodec/vp3data.h b/contrib/ffmpeg/libavcodec/vp3data.h
index d69ddfa28..d69ddfa28 100644
--- a/src/libffmpeg/libavcodec/vp3data.h
+++ b/contrib/ffmpeg/libavcodec/vp3data.h
diff --git a/src/libffmpeg/libavcodec/vp3dsp.c b/contrib/ffmpeg/libavcodec/vp3dsp.c
index bb9fed091..bb9fed091 100644
--- a/src/libffmpeg/libavcodec/vp3dsp.c
+++ b/contrib/ffmpeg/libavcodec/vp3dsp.c
diff --git a/contrib/ffmpeg/libavcodec/vp5.c b/contrib/ffmpeg/libavcodec/vp5.c
new file mode 100644
index 000000000..8a8c217c0
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/vp5.c
@@ -0,0 +1,290 @@
+/**
+ * @file vp5.c
+ * VP5 compatible video decoder
+ *
+ * Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "avcodec.h"
+#include "dsputil.h"
+#include "bitstream.h"
+#include "mpegvideo.h"
+
+#include "vp56.h"
+#include "vp56data.h"
+#include "vp5data.h"
+
+
+static int vp5_parse_header(vp56_context_t *s, uint8_t *buf, int buf_size,
+ int *golden_frame)
+{
+ vp56_range_coder_t *c = &s->c;
+ int rows, cols;
+
+ vp56_init_range_decoder(&s->c, buf, buf_size);
+ s->framep[VP56_FRAME_CURRENT]->key_frame = !vp56_rac_get(c);
+ vp56_rac_get(c);
+ vp56_init_dequant(s, vp56_rac_gets(c, 6));
+ if (s->framep[VP56_FRAME_CURRENT]->key_frame)
+ {
+ vp56_rac_gets(c, 8);
+ if(vp56_rac_gets(c, 5) > 5)
+ return 0;
+ vp56_rac_gets(c, 2);
+ if (vp56_rac_get(c)) {
+ av_log(s->avctx, AV_LOG_ERROR, "interlacing not supported\n");
+ return 0;
+ }
+ rows = vp56_rac_gets(c, 8); /* number of stored macroblock rows */
+ cols = vp56_rac_gets(c, 8); /* number of stored macroblock cols */
+ vp56_rac_gets(c, 8); /* number of displayed macroblock rows */
+ vp56_rac_gets(c, 8); /* number of displayed macroblock cols */
+ vp56_rac_gets(c, 2);
+ if (16*cols != s->avctx->coded_width ||
+ 16*rows != s->avctx->coded_height) {
+ avcodec_set_dimensions(s->avctx, 16*cols, 16*rows);
+ return 2;
+ }
+ }
+ 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(vp56_context_t *s, vp56_mv_t *vect)
+{
+ vp56_range_coder_t *c = &s->c;
+ int comp, di;
+
+ for (comp=0; comp<2; comp++) {
+ int delta = 0;
+ if (vp56_rac_get_prob(c, s->vector_model_dct[comp])) {
+ int sign = vp56_rac_get_prob(c, s->vector_model_sig[comp]);
+ di = vp56_rac_get_prob(c, s->vector_model_pdi[comp][0]);
+ di |= vp56_rac_get_prob(c, s->vector_model_pdi[comp][1]) << 1;
+ delta = vp56_rac_get_tree(c, vp56_pva_tree,
+ s->vector_model_pdv[comp]);
+ delta = di | (delta << 2);
+ delta = (delta ^ -sign) + sign;
+ }
+ if (!comp)
+ vect->x = delta;
+ else
+ vect->y = delta;
+ }
+}
+
+static void vp5_parse_vector_models(vp56_context_t *s)
+{
+ vp56_range_coder_t *c = &s->c;
+ int comp, node;
+
+ for (comp=0; comp<2; comp++) {
+ if (vp56_rac_get_prob(c, vp5_vmc_pct[comp][0]))
+ s->vector_model_dct[comp] = vp56_rac_gets_nn(c, 7);
+ if (vp56_rac_get_prob(c, vp5_vmc_pct[comp][1]))
+ s->vector_model_sig[comp] = vp56_rac_gets_nn(c, 7);
+ if (vp56_rac_get_prob(c, vp5_vmc_pct[comp][2]))
+ s->vector_model_pdi[comp][0] = vp56_rac_gets_nn(c, 7);
+ if (vp56_rac_get_prob(c, vp5_vmc_pct[comp][3]))
+ s->vector_model_pdi[comp][1] = vp56_rac_gets_nn(c, 7);
+ }
+
+ for (comp=0; comp<2; comp++)
+ for (node=0; node<7; node++)
+ if (vp56_rac_get_prob(c, vp5_vmc_pct[comp][4 + node]))
+ s->vector_model_pdv[comp][node] = vp56_rac_gets_nn(c, 7);
+}
+
+static void vp5_parse_coeff_models(vp56_context_t *s)
+{
+ vp56_range_coder_t *c = &s->c;
+ uint8_t def_prob[11];
+ int node, cg, ctx;
+ int ct; /* code type */
+ int pt; /* plane type (0 for Y, 1 for U or V) */
+
+ memset(def_prob, 0x80, sizeof(def_prob));
+
+ for (pt=0; pt<2; pt++)
+ for (node=0; node<11; node++)
+ if (vp56_rac_get_prob(c, vp5_dccv_pct[pt][node])) {
+ def_prob[node] = vp56_rac_gets_nn(c, 7);
+ s->coeff_model_dccv[pt][node] = def_prob[node];
+ } else if (s->framep[VP56_FRAME_CURRENT]->key_frame) {
+ s->coeff_model_dccv[pt][node] = def_prob[node];
+ }
+
+ for (ct=0; ct<3; ct++)
+ for (pt=0; pt<2; pt++)
+ for (cg=0; cg<6; cg++)
+ for (node=0; node<11; node++)
+ if (vp56_rac_get_prob(c, vp5_ract_pct[ct][pt][cg][node])) {
+ def_prob[node] = vp56_rac_gets_nn(c, 7);
+ s->coeff_model_ract[pt][ct][cg][node] = def_prob[node];
+ } else if (s->framep[VP56_FRAME_CURRENT]->key_frame) {
+ s->coeff_model_ract[pt][ct][cg][node] = def_prob[node];
+ }
+
+ /* coeff_model_dcct is a linear combination of coeff_model_dccv */
+ for (pt=0; pt<2; pt++)
+ for (ctx=0; ctx<36; ctx++)
+ for (node=0; node<5; node++)
+ s->coeff_model_dcct[pt][ctx][node] = av_clip(((s->coeff_model_dccv[pt][node] * vp5_dccv_lc[node][ctx][0] + 128) >> 8) + vp5_dccv_lc[node][ctx][1], 1, 254);
+
+ /* coeff_model_acct is a linear combination of coeff_model_ract */
+ for (ct=0; ct<3; ct++)
+ for (pt=0; pt<2; pt++)
+ for (cg=0; cg<3; cg++)
+ for (ctx=0; ctx<6; ctx++)
+ for (node=0; node<5; node++)
+ s->coeff_model_acct[pt][ct][cg][ctx][node] = av_clip(((s->coeff_model_ract[pt][ct][cg][node] * vp5_ract_lc[ct][cg][node][ctx][0] + 128) >> 8) + vp5_ract_lc[ct][cg][node][ctx][1], 1, 254);
+}
+
+static void vp5_parse_coeff(vp56_context_t *s)
+{
+ vp56_range_coder_t *c = &s->c;
+ uint8_t *permute = s->scantable.permutated;
+ uint8_t *model, *model2;
+ int coeff, sign, coeff_idx;
+ int b, i, cg, idx, ctx, ctx_last;
+ int pt = 0; /* plane type (0 for Y, 1 for U or V) */
+
+ for (b=0; b<6; b++) {
+ int ct = 1; /* code type */
+
+ if (b > 3) pt = 1;
+
+ ctx = 6*s->coeff_ctx[vp56_b6to4[b]][0]
+ + s->above_blocks[s->above_block_idx[b]].not_null_dc;
+ model = s->coeff_model_dccv[pt];
+ model2 = s->coeff_model_dcct[pt][ctx];
+
+ for (coeff_idx=0; coeff_idx<64; ) {
+ if (vp56_rac_get_prob(c, model2[0])) {
+ if (vp56_rac_get_prob(c, model2[2])) {
+ if (vp56_rac_get_prob(c, model2[3])) {
+ s->coeff_ctx[vp56_b6to4[b]][coeff_idx] = 4;
+ idx = vp56_rac_get_tree(c, vp56_pc_tree, model);
+ sign = vp56_rac_get(c);
+ coeff = vp56_coeff_bias[idx];
+ for (i=vp56_coeff_bit_length[idx]; i>=0; i--)
+ coeff += vp56_rac_get_prob(c, vp56_coeff_parse_table[idx][i]) << i;
+ } else {
+ if (vp56_rac_get_prob(c, model2[4])) {
+ coeff = 3 + vp56_rac_get_prob(c, model[5]);
+ s->coeff_ctx[vp56_b6to4[b]][coeff_idx] = 3;
+ } else {
+ coeff = 2;
+ s->coeff_ctx[vp56_b6to4[b]][coeff_idx] = 2;
+ }
+ sign = vp56_rac_get(c);
+ }
+ ct = 2;
+ } else {
+ ct = 1;
+ s->coeff_ctx[vp56_b6to4[b]][coeff_idx] = 1;
+ sign = vp56_rac_get(c);
+ coeff = 1;
+ }
+ coeff = (coeff ^ -sign) + sign;
+ if (coeff_idx)
+ coeff *= s->dequant_ac;
+ s->block_coeff[b][permute[coeff_idx]] = coeff;
+ } else {
+ if (ct && !vp56_rac_get_prob(c, model2[1]))
+ break;
+ ct = 0;
+ s->coeff_ctx[vp56_b6to4[b]][coeff_idx] = 0;
+ }
+
+ cg = vp5_coeff_groups[++coeff_idx];
+ ctx = s->coeff_ctx[vp56_b6to4[b]][coeff_idx];
+ model = s->coeff_model_ract[pt][ct][cg];
+ model2 = cg > 2 ? model : s->coeff_model_acct[pt][ct][cg][ctx];
+ }
+
+ ctx_last = FFMIN(s->coeff_ctx_last[vp56_b6to4[b]], 24);
+ s->coeff_ctx_last[vp56_b6to4[b]] = coeff_idx;
+ if (coeff_idx < ctx_last)
+ for (i=coeff_idx; i<=ctx_last; i++)
+ s->coeff_ctx[vp56_b6to4[b]][i] = 5;
+ s->above_blocks[s->above_block_idx[b]].not_null_dc = s->coeff_ctx[vp56_b6to4[b]][0];
+ }
+}
+
+static void vp5_default_models_init(vp56_context_t *s)
+{
+ int i;
+
+ for (i=0; i<2; i++) {
+ s->vector_model_sig[i] = 0x80;
+ s->vector_model_dct[i] = 0x80;
+ s->vector_model_pdi[i][0] = 0x55;
+ s->vector_model_pdi[i][1] = 0x80;
+ }
+ memcpy(s->mb_types_stats, vp56_def_mb_types_stats, sizeof(s->mb_types_stats));
+ memset(s->vector_model_pdv, 0x80, sizeof(s->vector_model_pdv));
+}
+
+static int vp5_decode_init(AVCodecContext *avctx)
+{
+ vp56_context_t *s = avctx->priv_data;
+
+ vp56_init(s, avctx, 1);
+ 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;
+ s->parse_coeff_models = vp5_parse_coeff_models;
+ s->parse_header = vp5_parse_header;
+
+ return 0;
+}
+
+AVCodec vp5_decoder = {
+ "vp5",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_VP5,
+ sizeof(vp56_context_t),
+ vp5_decode_init,
+ NULL,
+ vp56_free,
+ vp56_decode_frame,
+};
diff --git a/contrib/ffmpeg/libavcodec/vp56.c b/contrib/ffmpeg/libavcodec/vp56.c
new file mode 100644
index 000000000..abd1b3a63
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/vp56.c
@@ -0,0 +1,665 @@
+/**
+ * @file vp56.c
+ * VP5 and VP6 compatible video decoder (common features)
+ *
+ * Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avcodec.h"
+
+#include "vp56.h"
+#include "vp56data.h"
+
+
+void vp56_init_dequant(vp56_context_t *s, int quantizer)
+{
+ s->quantizer = quantizer;
+ s->dequant_dc = vp56_dc_dequant[quantizer] << 2;
+ s->dequant_ac = vp56_ac_dequant[quantizer] << 2;
+}
+
+static int vp56_get_vectors_predictors(vp56_context_t *s, int row, int col,
+ vp56_frame_t ref_frame)
+{
+ int nb_pred = 0;
+ vp56_mv_t vect[2] = {{0,0}, {0,0}};
+ int pos, offset;
+ vp56_mv_t mvp;
+
+ for (pos=0; pos<12; pos++) {
+ mvp.x = col + vp56_candidate_predictor_pos[pos][0];
+ mvp.y = row + vp56_candidate_predictor_pos[pos][1];
+ if (mvp.x < 0 || mvp.x >= s->mb_width ||
+ mvp.y < 0 || mvp.y >= s->mb_height)
+ continue;
+ offset = mvp.x + s->mb_width*mvp.y;
+
+ if (vp56_reference_frame[s->macroblocks[offset].type] != ref_frame)
+ continue;
+ if ((s->macroblocks[offset].mv.x == vect[0].x &&
+ s->macroblocks[offset].mv.y == vect[0].y) ||
+ (s->macroblocks[offset].mv.x == 0 &&
+ s->macroblocks[offset].mv.y == 0))
+ continue;
+
+ vect[nb_pred++] = s->macroblocks[offset].mv;
+ if (nb_pred > 1) {
+ nb_pred = -1;
+ break;
+ }
+ s->vector_candidate_pos = pos;
+ }
+
+ s->vector_candidate[0] = vect[0];
+ s->vector_candidate[1] = vect[1];
+
+ return nb_pred+1;
+}
+
+static void vp56_parse_mb_type_models(vp56_context_t *s)
+{
+ vp56_range_coder_t *c = &s->c;
+ int i, ctx, type;
+
+ for (ctx=0; ctx<3; ctx++) {
+ if (vp56_rac_get_prob(c, 174)) {
+ int idx = vp56_rac_gets(c, 4);
+ memcpy(s->mb_types_stats[ctx],vp56_pre_def_mb_type_stats[idx][ctx],
+ sizeof(s->mb_types_stats[ctx]));
+ }
+ if (vp56_rac_get_prob(c, 254)) {
+ for (type=0; type<10; type++) {
+ for(i=0; i<2; i++) {
+ if (vp56_rac_get_prob(c, 205)) {
+ int delta, sign = vp56_rac_get(c);
+
+ delta = vp56_rac_get_tree(c, vp56_pmbtm_tree,
+ vp56_mb_type_model_model);
+ if (!delta)
+ delta = 4 * vp56_rac_gets(c, 7);
+ s->mb_types_stats[ctx][type][i] += (delta ^ -sign) + sign;
+ }
+ }
+ }
+ }
+ }
+
+ /* compute MB type probability tables based on previous MB type */
+ for (ctx=0; ctx<3; ctx++) {
+ int p[10];
+
+ for (type=0; type<10; type++)
+ p[type] = 100 * s->mb_types_stats[ctx][type][1];
+
+ for (type=0; type<10; type++) {
+ int p02, p34, p0234, p17, p56, p89, p5689, p156789;
+
+ /* conservative MB type probability */
+ s->mb_type_model[ctx][type][0] = 255 - (255 * s->mb_types_stats[ctx][type][0]) / (1 + s->mb_types_stats[ctx][type][0] + s->mb_types_stats[ctx][type][1]);
+
+ p[type] = 0; /* same MB type => weight is null */
+
+ /* binary tree parsing probabilities */
+ p02 = p[0] + p[2];
+ p34 = p[3] + p[4];
+ p0234 = p02 + p34;
+ p17 = p[1] + p[7];
+ p56 = p[5] + p[6];
+ p89 = p[8] + p[9];
+ p5689 = p56 + p89;
+ p156789 = p17 + p5689;
+
+ s->mb_type_model[ctx][type][1] = 1 + 255 * p0234/(1+p0234+p156789);
+ s->mb_type_model[ctx][type][2] = 1 + 255 * p02 / (1+p0234);
+ s->mb_type_model[ctx][type][3] = 1 + 255 * p17 / (1+p156789);
+ s->mb_type_model[ctx][type][4] = 1 + 255 * p[0] / (1+p02);
+ s->mb_type_model[ctx][type][5] = 1 + 255 * p[3] / (1+p34);
+ s->mb_type_model[ctx][type][6] = 1 + 255 * p[1] / (1+p17);
+ s->mb_type_model[ctx][type][7] = 1 + 255 * p56 / (1+p5689);
+ s->mb_type_model[ctx][type][8] = 1 + 255 * p[5] / (1+p56);
+ s->mb_type_model[ctx][type][9] = 1 + 255 * p[8] / (1+p89);
+
+ /* restore initial value */
+ p[type] = 100 * s->mb_types_stats[ctx][type][1];
+ }
+ }
+}
+
+static vp56_mb_t vp56_parse_mb_type(vp56_context_t *s,
+ vp56_mb_t prev_type, int ctx)
+{
+ uint8_t *mb_type_model = s->mb_type_model[ctx][prev_type];
+ vp56_range_coder_t *c = &s->c;
+
+ if (vp56_rac_get_prob(c, mb_type_model[0]))
+ return prev_type;
+ else
+ return vp56_rac_get_tree(c, vp56_pmbt_tree, mb_type_model);
+}
+
+static void vp56_decode_4mv(vp56_context_t *s, int row, int col)
+{
+ vp56_mv_t mv = {0,0};
+ int type[4];
+ int b;
+
+ /* parse each block type */
+ for (b=0; b<4; b++) {
+ type[b] = vp56_rac_gets(&s->c, 2);
+ if (type[b])
+ type[b]++; /* only returns 0, 2, 3 or 4 (all INTER_PF) */
+ }
+
+ /* get vectors */
+ for (b=0; b<4; b++) {
+ switch (type[b]) {
+ case VP56_MB_INTER_NOVEC_PF:
+ s->mv[b] = (vp56_mv_t) {0,0};
+ break;
+ case VP56_MB_INTER_DELTA_PF:
+ s->parse_vector_adjustment(s, &s->mv[b]);
+ break;
+ case VP56_MB_INTER_V1_PF:
+ s->mv[b] = s->vector_candidate[0];
+ break;
+ case VP56_MB_INTER_V2_PF:
+ s->mv[b] = s->vector_candidate[1];
+ break;
+ }
+ mv.x += s->mv[b].x;
+ mv.y += s->mv[b].y;
+ }
+
+ /* this is the one selected for the whole MB for prediction */
+ s->macroblocks[row * s->mb_width + col].mv = s->mv[3];
+
+ /* chroma vectors are average luma vectors */
+ if (s->avctx->codec->id == CODEC_ID_VP5) {
+ s->mv[4].x = s->mv[5].x = RSHIFT(mv.x,2);
+ s->mv[4].y = s->mv[5].y = RSHIFT(mv.y,2);
+ } else {
+ s->mv[4] = s->mv[5] = (vp56_mv_t) {mv.x/4, mv.y/4};
+ }
+}
+
+static vp56_mb_t vp56_decode_mv(vp56_context_t *s, int row, int col)
+{
+ vp56_mv_t *mv, vect = {0,0};
+ int ctx, b;
+
+ ctx = vp56_get_vectors_predictors(s, row, col, VP56_FRAME_PREVIOUS);
+ s->mb_type = vp56_parse_mb_type(s, s->mb_type, ctx);
+ s->macroblocks[row * s->mb_width + col].type = s->mb_type;
+
+ switch (s->mb_type) {
+ case VP56_MB_INTER_V1_PF:
+ mv = &s->vector_candidate[0];
+ break;
+
+ case VP56_MB_INTER_V2_PF:
+ mv = &s->vector_candidate[1];
+ break;
+
+ case VP56_MB_INTER_V1_GF:
+ vp56_get_vectors_predictors(s, row, col, VP56_FRAME_GOLDEN);
+ mv = &s->vector_candidate[0];
+ break;
+
+ case VP56_MB_INTER_V2_GF:
+ vp56_get_vectors_predictors(s, row, col, VP56_FRAME_GOLDEN);
+ mv = &s->vector_candidate[1];
+ break;
+
+ case VP56_MB_INTER_DELTA_PF:
+ s->parse_vector_adjustment(s, &vect);
+ mv = &vect;
+ break;
+
+ case VP56_MB_INTER_DELTA_GF:
+ vp56_get_vectors_predictors(s, row, col, VP56_FRAME_GOLDEN);
+ s->parse_vector_adjustment(s, &vect);
+ mv = &vect;
+ break;
+
+ case VP56_MB_INTER_4V:
+ vp56_decode_4mv(s, row, col);
+ return s->mb_type;
+
+ default:
+ mv = &vect;
+ break;
+ }
+
+ s->macroblocks[row*s->mb_width + col].mv = *mv;
+
+ /* same vector for all blocks */
+ for (b=0; b<6; b++)
+ s->mv[b] = *mv;
+
+ return s->mb_type;
+}
+
+static void vp56_add_predictors_dc(vp56_context_t *s, vp56_frame_t ref_frame)
+{
+ int idx = s->scantable.permutated[0];
+ int i;
+
+ for (i=0; i<6; i++) {
+ vp56_ref_dc_t *ab = &s->above_blocks[s->above_block_idx[i]];
+ vp56_ref_dc_t *lb = &s->left_block[vp56_b6to4[i]];
+ int count = 0;
+ int dc = 0;
+
+ if (ref_frame == lb->ref_frame) {
+ dc += lb->dc_coeff;
+ count++;
+ }
+ if (ref_frame == ab->ref_frame) {
+ dc += ab->dc_coeff;
+ count++;
+ }
+ if (s->avctx->codec->id == CODEC_ID_VP5) {
+ if (count < 2 && ref_frame == ab[-1].ref_frame) {
+ dc += ab[-1].dc_coeff;
+ count++;
+ }
+ if (count < 2 && ref_frame == ab[1].ref_frame) {
+ dc += ab[1].dc_coeff;
+ count++;
+ }
+ }
+ if (count == 0)
+ dc = s->prev_dc[vp56_b6to3[i]][ref_frame];
+ else if (count == 2)
+ dc /= 2;
+
+ s->block_coeff[i][idx] += dc;
+ s->prev_dc[vp56_b6to3[i]][ref_frame] = s->block_coeff[i][idx];
+ ab->dc_coeff = s->block_coeff[i][idx];
+ ab->ref_frame = ref_frame;
+ lb->dc_coeff = s->block_coeff[i][idx];
+ lb->ref_frame = ref_frame;
+ s->block_coeff[i][idx] *= s->dequant_dc;
+ }
+}
+
+static void vp56_edge_filter(vp56_context_t *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(vp56_context_t *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);
+}
+
+static void vp56_mc(vp56_context_t *s, int b, uint8_t *src,
+ int stride, int x, int y)
+{
+ int plane = vp56_b6to3[b];
+ uint8_t *dst=s->framep[VP56_FRAME_CURRENT]->data[plane]+s->block_offset[b];
+ uint8_t *src_block;
+ int src_offset;
+ int overlap_offset = 0;
+ int mask = s->vp56_coord_div[b] - 1;
+ int deblock_filtering = s->deblock_filtering;
+ int dx;
+ int dy;
+
+ if (s->avctx->skip_loop_filter >= AVDISCARD_ALL ||
+ (s->avctx->skip_loop_filter >= AVDISCARD_NONKEY
+ && !s->framep[VP56_FRAME_CURRENT]->key_frame))
+ deblock_filtering = 0;
+
+ dx = s->mv[b].x / s->vp56_coord_div[b];
+ dy = s->mv[b].y / s->vp56_coord_div[b];
+
+ if (b >= 4) {
+ x /= 2;
+ y /= 2;
+ }
+ x += dx - 2;
+ y += dy - 2;
+
+ if (x<0 || x+12>=s->plane_width[plane] ||
+ y<0 || y+12>=s->plane_height[plane]) {
+ ff_emulated_edge_mc(s->edge_emu_buffer,
+ src + s->block_offset[b] + (dy-2)*stride + (dx-2),
+ stride, 12, 12, x, y,
+ s->plane_width[plane],
+ s->plane_height[plane]);
+ src_block = s->edge_emu_buffer;
+ src_offset = 2 + 2*stride;
+ } else if (deblock_filtering) {
+ /* only need a 12x12 block, but there is no such dsp function, */
+ /* so copy a 16x12 block */
+ s->dsp.put_pixels_tab[0][0](s->edge_emu_buffer,
+ src + s->block_offset[b] + (dy-2)*stride + (dx-2),
+ stride, 12);
+ src_block = s->edge_emu_buffer;
+ src_offset = 2 + 2*stride;
+ } else {
+ src_block = src;
+ src_offset = s->block_offset[b] + dy*stride + dx;
+ }
+
+ if (deblock_filtering)
+ vp56_deblock_filter(s, src_block, stride, dx&7, dy&7);
+
+ if (s->mv[b].x & mask)
+ overlap_offset += (s->mv[b].x > 0) ? 1 : -1;
+ if (s->mv[b].y & mask)
+ overlap_offset += (s->mv[b].y > 0) ? stride : -stride;
+
+ if (overlap_offset) {
+ if (s->filter)
+ s->filter(s, dst, src_block, src_offset, src_offset+overlap_offset,
+ stride, s->mv[b], mask, s->filter_selection, b<4);
+ else
+ s->dsp.put_no_rnd_pixels_l2[1](dst, src_block+src_offset,
+ src_block+src_offset+overlap_offset,
+ stride, 8);
+ } else {
+ s->dsp.put_pixels_tab[1][0](dst, src_block+src_offset, stride, 8);
+ }
+}
+
+static void vp56_decode_mb(vp56_context_t *s, int row, int col)
+{
+ AVFrame *frame_current, *frame_ref;
+ vp56_mb_t mb_type;
+ vp56_frame_t ref_frame;
+ int b, plan, off;
+
+ if (s->framep[VP56_FRAME_CURRENT]->key_frame)
+ mb_type = VP56_MB_INTRA;
+ else
+ mb_type = vp56_decode_mv(s, row, col);
+ ref_frame = vp56_reference_frame[mb_type];
+
+ memset(s->block_coeff, 0, sizeof(s->block_coeff));
+
+ s->parse_coeff(s);
+
+ vp56_add_predictors_dc(s, ref_frame);
+
+ frame_current = s->framep[VP56_FRAME_CURRENT];
+ frame_ref = s->framep[ref_frame];
+
+ switch (mb_type) {
+ case VP56_MB_INTRA:
+ for (b=0; b<6; b++) {
+ plan = vp56_b6to3[b];
+ s->dsp.idct_put(frame_current->data[plan] + s->block_offset[b],
+ s->stride[plan], s->block_coeff[b]);
+ }
+ break;
+
+ case VP56_MB_INTER_NOVEC_PF:
+ case VP56_MB_INTER_NOVEC_GF:
+ for (b=0; b<6; b++) {
+ plan = vp56_b6to3[b];
+ off = s->block_offset[b];
+ s->dsp.put_pixels_tab[1][0](frame_current->data[plan] + off,
+ frame_ref->data[plan] + off,
+ s->stride[plan], 8);
+ s->dsp.idct_add(frame_current->data[plan] + off,
+ s->stride[plan], s->block_coeff[b]);
+ }
+ break;
+
+ case VP56_MB_INTER_DELTA_PF:
+ case VP56_MB_INTER_V1_PF:
+ case VP56_MB_INTER_V2_PF:
+ case VP56_MB_INTER_DELTA_GF:
+ case VP56_MB_INTER_4V:
+ case VP56_MB_INTER_V1_GF:
+ case VP56_MB_INTER_V2_GF:
+ for (b=0; b<6; b++) {
+ int x_off = b==1 || b==3 ? 8 : 0;
+ int y_off = b==2 || b==3 ? 8 : 0;
+ plan = vp56_b6to3[b];
+ vp56_mc(s, b, frame_ref->data[plan], s->stride[plan],
+ 16*col+x_off, 16*row+y_off);
+ s->dsp.idct_add(frame_current->data[plan] + s->block_offset[b],
+ s->stride[plan], s->block_coeff[b]);
+ }
+ break;
+ }
+}
+
+static int vp56_size_changed(AVCodecContext *avctx, vp56_context_t *s)
+{
+ int stride = s->framep[VP56_FRAME_CURRENT]->linesize[0];
+ int i;
+
+ s->plane_width[0] = s->avctx->coded_width;
+ s->plane_width[1] = s->plane_width[2] = s->avctx->coded_width/2;
+ s->plane_height[0] = s->avctx->coded_height;
+ s->plane_height[1] = s->plane_height[2] = s->avctx->coded_height/2;
+
+ for (i=0; i<3; i++)
+ s->stride[i] = s->flip * s->framep[VP56_FRAME_CURRENT]->linesize[i];
+
+ s->mb_width = (s->avctx->coded_width+15) / 16;
+ s->mb_height = (s->avctx->coded_height+15) / 16;
+
+ if (s->mb_width > 1000 || s->mb_height > 1000) {
+ av_log(avctx, AV_LOG_ERROR, "picture too big\n");
+ return -1;
+ }
+
+ s->above_blocks = av_realloc(s->above_blocks,
+ (4*s->mb_width+6) * sizeof(*s->above_blocks));
+ s->macroblocks = av_realloc(s->macroblocks,
+ s->mb_width*s->mb_height*sizeof(*s->macroblocks));
+ av_free(s->edge_emu_buffer_alloc);
+ s->edge_emu_buffer_alloc = av_malloc(16*stride);
+ s->edge_emu_buffer = s->edge_emu_buffer_alloc;
+ if (s->flip < 0)
+ s->edge_emu_buffer += 15 * stride;
+
+ return 0;
+}
+
+int vp56_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ vp56_context_t *s = avctx->priv_data;
+ AVFrame *const p = s->framep[VP56_FRAME_CURRENT];
+ int mb_row, mb_col, mb_row_flip, mb_offset = 0;
+ int block, y, uv, stride_y, stride_uv;
+ int golden_frame = 0;
+ int res;
+
+ res = s->parse_header(s, buf, buf_size, &golden_frame);
+ if (!res)
+ return -1;
+
+ p->reference = 1;
+ if (avctx->get_buffer(avctx, p) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ return -1;
+ }
+
+ if (res == 2)
+ if (vp56_size_changed(avctx, s)) {
+ avctx->release_buffer(avctx, p);
+ return -1;
+ }
+
+ if (p->key_frame) {
+ p->pict_type = FF_I_TYPE;
+ s->default_models_init(s);
+ for (block=0; block<s->mb_height*s->mb_width; block++)
+ s->macroblocks[block].type = VP56_MB_INTRA;
+ } else {
+ p->pict_type = FF_P_TYPE;
+ vp56_parse_mb_type_models(s);
+ s->parse_vector_models(s);
+ s->mb_type = VP56_MB_INTER_NOVEC_PF;
+ }
+
+ s->parse_coeff_models(s);
+
+ memset(s->prev_dc, 0, sizeof(s->prev_dc));
+ s->prev_dc[1][VP56_FRAME_CURRENT] = 128;
+ s->prev_dc[2][VP56_FRAME_CURRENT] = 128;
+
+ for (block=0; block < 4*s->mb_width+6; block++) {
+ s->above_blocks[block].ref_frame = -1;
+ s->above_blocks[block].dc_coeff = 0;
+ s->above_blocks[block].not_null_dc = 0;
+ }
+ s->above_blocks[2*s->mb_width + 2].ref_frame = 0;
+ s->above_blocks[3*s->mb_width + 4].ref_frame = 0;
+
+ stride_y = p->linesize[0];
+ stride_uv = p->linesize[1];
+
+ if (s->flip < 0)
+ mb_offset = 7;
+
+ /* main macroblocks loop */
+ for (mb_row=0; mb_row<s->mb_height; mb_row++) {
+ if (s->flip < 0)
+ mb_row_flip = s->mb_height - mb_row - 1;
+ else
+ mb_row_flip = mb_row;
+
+ for (block=0; block<4; block++) {
+ s->left_block[block].ref_frame = -1;
+ s->left_block[block].dc_coeff = 0;
+ s->left_block[block].not_null_dc = 0;
+ memset(s->coeff_ctx[block], 0, 64*sizeof(s->coeff_ctx[block][0]));
+ }
+ memset(s->coeff_ctx_last, 24, sizeof(s->coeff_ctx_last));
+
+ s->above_block_idx[0] = 1;
+ s->above_block_idx[1] = 2;
+ s->above_block_idx[2] = 1;
+ s->above_block_idx[3] = 2;
+ s->above_block_idx[4] = 2*s->mb_width + 2 + 1;
+ s->above_block_idx[5] = 3*s->mb_width + 4 + 1;
+
+ s->block_offset[s->frbi] = (mb_row_flip*16 + mb_offset) * stride_y;
+ s->block_offset[s->srbi] = s->block_offset[s->frbi] + 8*stride_y;
+ s->block_offset[1] = s->block_offset[0] + 8;
+ s->block_offset[3] = s->block_offset[2] + 8;
+ s->block_offset[4] = (mb_row_flip*8 + mb_offset) * stride_uv;
+ s->block_offset[5] = s->block_offset[4];
+
+ for (mb_col=0; mb_col<s->mb_width; mb_col++) {
+ vp56_decode_mb(s, mb_row, mb_col);
+
+ for (y=0; y<4; y++) {
+ s->above_block_idx[y] += 2;
+ s->block_offset[y] += 16;
+ }
+
+ for (uv=4; uv<6; uv++) {
+ s->above_block_idx[uv] += 1;
+ s->block_offset[uv] += 8;
+ }
+ }
+ }
+
+ if (s->framep[VP56_FRAME_PREVIOUS] == s->framep[VP56_FRAME_GOLDEN])
+ FFSWAP(AVFrame *, s->framep[VP56_FRAME_PREVIOUS],
+ s->framep[VP56_FRAME_UNUSED]);
+ else if (s->framep[VP56_FRAME_PREVIOUS]->data[0])
+ avctx->release_buffer(avctx, s->framep[VP56_FRAME_PREVIOUS]);
+ if (p->key_frame || golden_frame) {
+ if (s->framep[VP56_FRAME_GOLDEN]->data[0])
+ avctx->release_buffer(avctx, s->framep[VP56_FRAME_GOLDEN]);
+ s->framep[VP56_FRAME_GOLDEN] = p;
+ }
+ FFSWAP(AVFrame *, s->framep[VP56_FRAME_CURRENT],
+ s->framep[VP56_FRAME_PREVIOUS]);
+
+ *(AVFrame*)data = *p;
+ *data_size = sizeof(AVFrame);
+
+ return buf_size;
+}
+
+void vp56_init(vp56_context_t *s, AVCodecContext *avctx, int flip)
+{
+ int i;
+
+ s->avctx = avctx;
+ avctx->pix_fmt = PIX_FMT_YUV420P;
+
+ if (s->avctx->idct_algo == FF_IDCT_AUTO)
+ s->avctx->idct_algo = FF_IDCT_VP3;
+ dsputil_init(&s->dsp, s->avctx);
+ ff_init_scantable(s->dsp.idct_permutation, &s->scantable,ff_zigzag_direct);
+
+ avcodec_set_dimensions(s->avctx, 0, 0);
+
+ for (i=0; i<3; i++)
+ s->framep[i] = &s->frames[i];
+ s->framep[VP56_FRAME_UNUSED] = s->framep[VP56_FRAME_GOLDEN];
+ s->edge_emu_buffer_alloc = NULL;
+
+ s->above_blocks = NULL;
+ s->macroblocks = NULL;
+ s->quantizer = -1;
+ s->deblock_filtering = 1;
+
+ s->filter = NULL;
+
+ if (flip) {
+ s->flip = -1;
+ s->frbi = 2;
+ s->srbi = 0;
+ } else {
+ s->flip = 1;
+ s->frbi = 0;
+ s->srbi = 2;
+ }
+}
+
+int vp56_free(AVCodecContext *avctx)
+{
+ vp56_context_t *s = avctx->priv_data;
+
+ av_free(s->above_blocks);
+ av_free(s->macroblocks);
+ av_free(s->edge_emu_buffer_alloc);
+ if (s->framep[VP56_FRAME_GOLDEN]->data[0]
+ && (s->framep[VP56_FRAME_PREVIOUS] != s->framep[VP56_FRAME_GOLDEN]))
+ avctx->release_buffer(avctx, s->framep[VP56_FRAME_GOLDEN]);
+ if (s->framep[VP56_FRAME_PREVIOUS]->data[0])
+ avctx->release_buffer(avctx, s->framep[VP56_FRAME_PREVIOUS]);
+ return 0;
+}
diff --git a/contrib/ffmpeg/libavcodec/vp56.h b/contrib/ffmpeg/libavcodec/vp56.h
new file mode 100644
index 000000000..fb8bbba6f
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/vp56.h
@@ -0,0 +1,253 @@
+/**
+ * @file vp56.h
+ * VP5 and VP6 compatible video decoder (common features)
+ *
+ * Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef VP56_H
+#define VP56_H
+
+#include "vp56data.h"
+#include "dsputil.h"
+#include "mpegvideo.h"
+
+
+typedef struct vp56_context vp56_context_t;
+typedef struct vp56_mv vp56_mv_t;
+
+typedef void (*vp56_parse_vector_adjustment_t)(vp56_context_t *s,
+ vp56_mv_t *vect);
+typedef int (*vp56_adjust_t)(int v, int t);
+typedef void (*vp56_filter_t)(vp56_context_t *s, uint8_t *dst, uint8_t *src,
+ int offset1, int offset2, int stride,
+ vp56_mv_t mv, int mask, int select, int luma);
+typedef void (*vp56_parse_coeff_t)(vp56_context_t *s);
+typedef void (*vp56_default_models_init_t)(vp56_context_t *s);
+typedef void (*vp56_parse_vector_models_t)(vp56_context_t *s);
+typedef void (*vp56_parse_coeff_models_t)(vp56_context_t *s);
+typedef int (*vp56_parse_header_t)(vp56_context_t *s, uint8_t *buf,
+ int buf_size, int *golden_frame);
+
+typedef struct {
+ int high;
+ int bits;
+ const uint8_t *buffer;
+ unsigned long code_word;
+} vp56_range_coder_t;
+
+typedef struct {
+ uint8_t not_null_dc;
+ vp56_frame_t ref_frame;
+ DCTELEM dc_coeff;
+} vp56_ref_dc_t;
+
+struct vp56_mv {
+ int x;
+ int y;
+};
+
+typedef struct {
+ uint8_t type;
+ vp56_mv_t mv;
+} vp56_macroblock_t;
+
+struct vp56_context {
+ AVCodecContext *avctx;
+ DSPContext dsp;
+ ScanTable scantable;
+ AVFrame frames[3];
+ AVFrame *framep[4];
+ uint8_t *edge_emu_buffer_alloc;
+ uint8_t *edge_emu_buffer;
+ vp56_range_coder_t c;
+ vp56_range_coder_t cc;
+ vp56_range_coder_t *ccp;
+ int sub_version;
+
+ /* frame info */
+ int plane_width[3];
+ int plane_height[3];
+ int mb_width; /* number of horizontal MB */
+ int mb_height; /* number of vertical MB */
+ int block_offset[6];
+
+ int quantizer;
+ uint16_t dequant_dc;
+ uint16_t dequant_ac;
+
+ /* DC predictors management */
+ vp56_ref_dc_t *above_blocks;
+ vp56_ref_dc_t left_block[4];
+ int above_block_idx[6];
+ DCTELEM prev_dc[3][3]; /* [plan][ref_frame] */
+
+ /* blocks / macroblock */
+ vp56_mb_t mb_type;
+ vp56_macroblock_t *macroblocks;
+ DECLARE_ALIGNED_16(DCTELEM, block_coeff[6][64]);
+ uint8_t coeff_reorder[64]; /* used in vp6 only */
+ uint8_t coeff_index_to_pos[64]; /* used in vp6 only */
+
+ /* motion vectors */
+ vp56_mv_t mv[6]; /* vectors for each block in MB */
+ vp56_mv_t vector_candidate[2];
+ int vector_candidate_pos;
+
+ /* filtering hints */
+ int filter_header; /* used in vp6 only */
+ int deblock_filtering;
+ int filter_selection;
+ int filter_mode;
+ int max_vector_length;
+ int sample_variance_threshold;
+
+ /* AC models */
+ uint8_t vector_model_sig[2]; /* delta sign */
+ uint8_t vector_model_dct[2]; /* delta coding types */
+ uint8_t vector_model_pdi[2][2]; /* predefined delta init */
+ uint8_t vector_model_pdv[2][7]; /* predefined delta values */
+ uint8_t vector_model_fdv[2][8]; /* 8 bit delta value definition */
+ uint8_t mb_type_model[3][10][10]; /* model for decoding MB type */
+ uint8_t coeff_model_dccv[2][11]; /* DC coeff value */
+ uint8_t coeff_model_ract[2][3][6][11]; /* Run/AC coding type and AC coeff value */
+ uint8_t coeff_model_acct[2][3][3][6][5];/* vp5 only AC coding type for coding group < 3 */
+ uint8_t coeff_model_dcct[2][36][5]; /* DC coeff coding type */
+ uint8_t coeff_model_runv[2][14]; /* run value (vp6 only) */
+ uint8_t mb_types_stats[3][10][2]; /* contextual, next MB type stats */
+ uint8_t coeff_ctx[4][64]; /* used in vp5 only */
+ uint8_t coeff_ctx_last[4]; /* used in vp5 only */
+
+ /* upside-down flipping hints */
+ int flip; /* are we flipping ? */
+ int frbi; /* first row block index in MB */
+ int srbi; /* second row block index in MB */
+ int stride[3]; /* stride for each plan */
+
+ const uint8_t *vp56_coord_div;
+ vp56_parse_vector_adjustment_t parse_vector_adjustment;
+ vp56_adjust_t adjust;
+ vp56_filter_t filter;
+ vp56_parse_coeff_t parse_coeff;
+ vp56_default_models_init_t default_models_init;
+ vp56_parse_vector_models_t parse_vector_models;
+ vp56_parse_coeff_models_t parse_coeff_models;
+ vp56_parse_header_t parse_header;
+};
+
+
+void vp56_init(vp56_context_t *s, AVCodecContext *avctx, int flip);
+int vp56_free(AVCodecContext *avctx);
+void vp56_init_dequant(vp56_context_t *s, int quantizer);
+int vp56_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
+ uint8_t *buf, int buf_size);
+
+
+/**
+ * vp56 specific range coder implementation
+ */
+
+static inline void vp56_init_range_decoder(vp56_range_coder_t *c,
+ const uint8_t *buf, int buf_size)
+{
+ c->high = 255;
+ c->bits = 8;
+ c->buffer = buf;
+ c->code_word = *c->buffer++ << 8;
+ c->code_word |= *c->buffer++;
+}
+
+static inline int vp56_rac_get_prob(vp56_range_coder_t *c, uint8_t prob)
+{
+ unsigned int low = 1 + (((c->high - 1) * prob) / 256);
+ unsigned int low_shift = low << 8;
+ int bit = c->code_word >= low_shift;
+
+ if (bit) {
+ c->high -= low;
+ c->code_word -= low_shift;
+ } else {
+ c->high = low;
+ }
+
+ /* normalize */
+ while (c->high < 128) {
+ c->high <<= 1;
+ c->code_word <<= 1;
+ if (--c->bits == 0) {
+ c->bits = 8;
+ c->code_word |= *c->buffer++;
+ }
+ }
+ return bit;
+}
+
+static inline int vp56_rac_get(vp56_range_coder_t *c)
+{
+ /* equiprobable */
+ int low = (c->high + 1) >> 1;
+ unsigned int low_shift = low << 8;
+ int bit = c->code_word >= low_shift;
+ if (bit) {
+ c->high = (c->high - low) << 1;
+ c->code_word -= low_shift;
+ } else {
+ c->high = low << 1;
+ }
+
+ /* normalize */
+ c->code_word <<= 1;
+ if (--c->bits == 0) {
+ c->bits = 8;
+ c->code_word |= *c->buffer++;
+ }
+ return bit;
+}
+
+static inline int vp56_rac_gets(vp56_range_coder_t *c, int bits)
+{
+ int value = 0;
+
+ while (bits--) {
+ value = (value << 1) | vp56_rac_get(c);
+ }
+
+ return value;
+}
+
+static inline int vp56_rac_gets_nn(vp56_range_coder_t *c, int bits)
+{
+ int v = vp56_rac_gets(c, 7) << 1;
+ return v + !v;
+}
+
+static inline int vp56_rac_get_tree(vp56_range_coder_t *c,
+ const vp56_tree_t *tree,
+ const uint8_t *probs)
+{
+ while (tree->val > 0) {
+ if (vp56_rac_get_prob(c, probs[tree->prob_idx]))
+ tree += tree->val;
+ else
+ tree++;
+ }
+ return -tree->val;
+}
+
+#endif /* VP56_H */
diff --git a/src/libffmpeg/libavcodec/vp56data.c b/contrib/ffmpeg/libavcodec/vp56data.c
index e75c6d1ce..e75c6d1ce 100644
--- a/src/libffmpeg/libavcodec/vp56data.c
+++ b/contrib/ffmpeg/libavcodec/vp56data.c
diff --git a/contrib/ffmpeg/libavcodec/vp56data.h b/contrib/ffmpeg/libavcodec/vp56data.h
new file mode 100644
index 000000000..d784b9803
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/vp56data.h
@@ -0,0 +1,249 @@
+/**
+ * @file vp56data.h
+ * VP5 and VP6 compatible video decoder (common data)
+ *
+ * Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef VP56DATA_H
+#define VP56DATA_H
+
+#include "common.h"
+
+typedef enum {
+ VP56_FRAME_CURRENT = 0,
+ VP56_FRAME_PREVIOUS = 1,
+ VP56_FRAME_GOLDEN = 2,
+ VP56_FRAME_UNUSED = 3,
+} vp56_frame_t;
+
+typedef enum {
+ VP56_MB_INTER_NOVEC_PF = 0, /**< Inter MB, no vector, from previous frame */
+ VP56_MB_INTRA = 1, /**< Intra MB */
+ VP56_MB_INTER_DELTA_PF = 2, /**< Inter MB, above/left vector + delta, from previous frame */
+ VP56_MB_INTER_V1_PF = 3, /**< Inter MB, first vector, from previous frame */
+ VP56_MB_INTER_V2_PF = 4, /**< Inter MB, second vector, from previous frame */
+ VP56_MB_INTER_NOVEC_GF = 5, /**< Inter MB, no vector, from golden frame */
+ VP56_MB_INTER_DELTA_GF = 6, /**< Inter MB, above/left vector + delta, from golden frame */
+ VP56_MB_INTER_4V = 7, /**< Inter MB, 4 vectors, from previous frame */
+ VP56_MB_INTER_V1_GF = 8, /**< Inter MB, first vector, from golden frame */
+ VP56_MB_INTER_V2_GF = 9, /**< Inter MB, second vector, from golden frame */
+} vp56_mb_t;
+
+typedef struct {
+ int8_t val;
+ int8_t prob_idx;
+} vp56_tree_t;
+
+extern const uint8_t vp56_b6to3[];
+extern const uint8_t vp56_b6to4[];
+extern const uint8_t vp56_coeff_parse_table[6][11];
+extern const uint8_t vp56_def_mb_types_stats[3][10][2];
+extern const vp56_tree_t vp56_pva_tree[];
+extern const vp56_tree_t vp56_pc_tree[];
+extern const uint8_t vp56_coeff_bias[];
+extern const uint8_t vp56_coeff_bit_length[];
+
+static const vp56_frame_t vp56_reference_frame[] = {
+ VP56_FRAME_PREVIOUS, /* VP56_MB_INTER_NOVEC_PF */
+ VP56_FRAME_CURRENT, /* VP56_MB_INTRA */
+ VP56_FRAME_PREVIOUS, /* VP56_MB_INTER_DELTA_PF */
+ VP56_FRAME_PREVIOUS, /* VP56_MB_INTER_V1_PF */
+ VP56_FRAME_PREVIOUS, /* VP56_MB_INTER_V2_PF */
+ VP56_FRAME_GOLDEN, /* VP56_MB_INTER_NOVEC_GF */
+ VP56_FRAME_GOLDEN, /* VP56_MB_INTER_DELTA_GF */
+ VP56_FRAME_PREVIOUS, /* VP56_MB_INTER_4V */
+ VP56_FRAME_GOLDEN, /* VP56_MB_INTER_V1_GF */
+ VP56_FRAME_GOLDEN, /* VP56_MB_INTER_V2_GF */
+};
+
+static const uint8_t vp56_ac_dequant[64] = {
+ 94, 92, 90, 88, 86, 82, 78, 74,
+ 70, 66, 62, 58, 54, 53, 52, 51,
+ 50, 49, 48, 47, 46, 45, 44, 43,
+ 42, 40, 39, 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,
+};
+
+static const uint8_t vp56_dc_dequant[64] = {
+ 47, 47, 47, 47, 45, 43, 43, 43,
+ 43, 43, 42, 41, 41, 40, 40, 40,
+ 40, 35, 35, 35, 35, 33, 33, 33,
+ 33, 32, 32, 32, 27, 27, 26, 26,
+ 25, 25, 24, 24, 23, 23, 19, 19,
+ 19, 19, 18, 18, 17, 16, 16, 16,
+ 16, 16, 15, 11, 11, 11, 10, 10,
+ 9, 8, 7, 5, 3, 3, 2, 2,
+};
+
+static const uint8_t vp56_pre_def_mb_type_stats[16][3][10][2] = {
+ { { { 9, 15 }, { 32, 25 }, { 7, 19 }, { 9, 21 }, { 1, 12 },
+ { 14, 12 }, { 3, 18 }, { 14, 23 }, { 3, 10 }, { 0, 4 }, },
+ { { 41, 22 }, { 1, 0 }, { 1, 31 }, { 0, 0 }, { 0, 0 },
+ { 0, 1 }, { 1, 7 }, { 0, 1 }, { 98, 25 }, { 4, 10 }, },
+ { { 2, 3 }, { 2, 3 }, { 0, 2 }, { 0, 2 }, { 0, 0 },
+ { 11, 4 }, { 1, 4 }, { 0, 2 }, { 3, 2 }, { 0, 4 }, }, },
+ { { { 48, 39 }, { 1, 2 }, { 11, 27 }, { 29, 44 }, { 7, 27 },
+ { 1, 4 }, { 0, 3 }, { 1, 6 }, { 1, 2 }, { 0, 0 }, },
+ { { 123, 37 }, { 6, 4 }, { 1, 27 }, { 0, 0 }, { 0, 0 },
+ { 5, 8 }, { 1, 7 }, { 0, 1 }, { 12, 10 }, { 0, 2 }, },
+ { { 49, 46 }, { 3, 4 }, { 7, 31 }, { 42, 41 }, { 0, 0 },
+ { 2, 6 }, { 1, 7 }, { 1, 4 }, { 2, 4 }, { 0, 1 }, }, },
+ { { { 21, 32 }, { 1, 2 }, { 4, 10 }, { 32, 43 }, { 6, 23 },
+ { 2, 3 }, { 1, 19 }, { 1, 6 }, { 12, 21 }, { 0, 7 }, },
+ { { 26, 14 }, { 14, 12 }, { 0, 24 }, { 0, 0 }, { 0, 0 },
+ { 55, 17 }, { 1, 9 }, { 0, 36 }, { 5, 7 }, { 1, 3 }, },
+ { { 26, 25 }, { 1, 1 }, { 2, 10 }, { 67, 39 }, { 0, 0 },
+ { 1, 1 }, { 0, 14 }, { 0, 2 }, { 31, 26 }, { 1, 6 }, }, },
+ { { { 69, 83 }, { 0, 0 }, { 0, 2 }, { 10, 29 }, { 3, 12 },
+ { 0, 1 }, { 0, 3 }, { 0, 3 }, { 2, 2 }, { 0, 0 }, },
+ { { 209, 5 }, { 0, 0 }, { 0, 27 }, { 0, 0 }, { 0, 0 },
+ { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 0 }, { 0, 0 }, },
+ { { 103, 46 }, { 1, 2 }, { 2, 10 }, { 33, 42 }, { 0, 0 },
+ { 1, 4 }, { 0, 3 }, { 0, 1 }, { 1, 3 }, { 0, 0 }, }, },
+ { { { 11, 20 }, { 1, 4 }, { 18, 36 }, { 43, 48 }, { 13, 35 },
+ { 0, 2 }, { 0, 5 }, { 3, 12 }, { 1, 2 }, { 0, 0 }, },
+ { { 2, 5 }, { 4, 5 }, { 0, 121 }, { 0, 0 }, { 0, 0 },
+ { 0, 3 }, { 2, 4 }, { 1, 4 }, { 2, 2 }, { 0, 1 }, },
+ { { 14, 31 }, { 9, 13 }, { 14, 54 }, { 22, 29 }, { 0, 0 },
+ { 2, 6 }, { 4, 18 }, { 6, 13 }, { 1, 5 }, { 0, 1 }, }, },
+ { { { 70, 44 }, { 0, 1 }, { 2, 10 }, { 37, 46 }, { 8, 26 },
+ { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 1 }, { 0, 0 }, },
+ { { 175, 5 }, { 0, 1 }, { 0, 48 }, { 0, 0 }, { 0, 0 },
+ { 0, 2 }, { 0, 1 }, { 0, 2 }, { 0, 1 }, { 0, 0 }, },
+ { { 85, 39 }, { 0, 0 }, { 1, 9 }, { 69, 40 }, { 0, 0 },
+ { 0, 1 }, { 0, 3 }, { 0, 1 }, { 2, 3 }, { 0, 0 }, }, },
+ { { { 8, 15 }, { 0, 1 }, { 8, 21 }, { 74, 53 }, { 22, 42 },
+ { 0, 1 }, { 0, 2 }, { 0, 3 }, { 1, 2 }, { 0, 0 }, },
+ { { 83, 5 }, { 2, 3 }, { 0, 102 }, { 0, 0 }, { 0, 0 },
+ { 1, 3 }, { 0, 2 }, { 0, 1 }, { 0, 0 }, { 0, 0 }, },
+ { { 31, 28 }, { 0, 0 }, { 3, 14 }, { 130, 34 }, { 0, 0 },
+ { 0, 1 }, { 0, 3 }, { 0, 1 }, { 3, 3 }, { 0, 1 }, }, },
+ { { { 141, 42 }, { 0, 0 }, { 1, 4 }, { 11, 24 }, { 1, 11 },
+ { 0, 1 }, { 0, 1 }, { 0, 2 }, { 0, 0 }, { 0, 0 }, },
+ { { 233, 6 }, { 0, 0 }, { 0, 8 }, { 0, 0 }, { 0, 0 },
+ { 0, 1 }, { 0, 1 }, { 0, 0 }, { 0, 1 }, { 0, 0 }, },
+ { { 171, 25 }, { 0, 0 }, { 1, 5 }, { 25, 21 }, { 0, 0 },
+ { 0, 1 }, { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, }, },
+ { { { 8, 19 }, { 4, 10 }, { 24, 45 }, { 21, 37 }, { 9, 29 },
+ { 0, 3 }, { 1, 7 }, { 11, 25 }, { 0, 2 }, { 0, 1 }, },
+ { { 34, 16 }, { 112, 21 }, { 1, 28 }, { 0, 0 }, { 0, 0 },
+ { 6, 8 }, { 1, 7 }, { 0, 3 }, { 2, 5 }, { 0, 2 }, },
+ { { 17, 21 }, { 68, 29 }, { 6, 15 }, { 13, 22 }, { 0, 0 },
+ { 6, 12 }, { 3, 14 }, { 4, 10 }, { 1, 7 }, { 0, 3 }, }, },
+ { { { 46, 42 }, { 0, 1 }, { 2, 10 }, { 54, 51 }, { 10, 30 },
+ { 0, 2 }, { 0, 2 }, { 0, 1 }, { 0, 1 }, { 0, 0 }, },
+ { { 159, 35 }, { 2, 2 }, { 0, 25 }, { 0, 0 }, { 0, 0 },
+ { 3, 6 }, { 0, 5 }, { 0, 1 }, { 4, 4 }, { 0, 1 }, },
+ { { 51, 39 }, { 0, 1 }, { 2, 12 }, { 91, 44 }, { 0, 0 },
+ { 0, 2 }, { 0, 3 }, { 0, 1 }, { 2, 3 }, { 0, 1 }, }, },
+ { { { 28, 32 }, { 0, 0 }, { 3, 10 }, { 75, 51 }, { 14, 33 },
+ { 0, 1 }, { 0, 2 }, { 0, 1 }, { 1, 2 }, { 0, 0 }, },
+ { { 75, 39 }, { 5, 7 }, { 2, 48 }, { 0, 0 }, { 0, 0 },
+ { 3, 11 }, { 2, 16 }, { 1, 4 }, { 7, 10 }, { 0, 2 }, },
+ { { 81, 25 }, { 0, 0 }, { 2, 9 }, { 106, 26 }, { 0, 0 },
+ { 0, 1 }, { 0, 1 }, { 0, 1 }, { 1, 1 }, { 0, 0 }, }, },
+ { { { 100, 46 }, { 0, 1 }, { 3, 9 }, { 21, 37 }, { 5, 20 },
+ { 0, 1 }, { 0, 2 }, { 1, 2 }, { 0, 1 }, { 0, 0 }, },
+ { { 212, 21 }, { 0, 1 }, { 0, 9 }, { 0, 0 }, { 0, 0 },
+ { 1, 2 }, { 0, 2 }, { 0, 0 }, { 2, 2 }, { 0, 0 }, },
+ { { 140, 37 }, { 0, 1 }, { 1, 8 }, { 24, 33 }, { 0, 0 },
+ { 1, 2 }, { 0, 2 }, { 0, 1 }, { 1, 2 }, { 0, 0 }, }, },
+ { { { 27, 29 }, { 0, 1 }, { 9, 25 }, { 53, 51 }, { 12, 34 },
+ { 0, 1 }, { 0, 3 }, { 1, 5 }, { 0, 2 }, { 0, 0 }, },
+ { { 4, 2 }, { 0, 0 }, { 0, 172 }, { 0, 0 }, { 0, 0 },
+ { 0, 1 }, { 0, 2 }, { 0, 0 }, { 2, 0 }, { 0, 0 }, },
+ { { 14, 23 }, { 1, 3 }, { 11, 53 }, { 90, 31 }, { 0, 0 },
+ { 0, 3 }, { 1, 5 }, { 2, 6 }, { 1, 2 }, { 0, 0 }, }, },
+ { { { 80, 38 }, { 0, 0 }, { 1, 4 }, { 69, 33 }, { 5, 16 },
+ { 0, 1 }, { 0, 1 }, { 0, 0 }, { 0, 1 }, { 0, 0 }, },
+ { { 187, 22 }, { 1, 1 }, { 0, 17 }, { 0, 0 }, { 0, 0 },
+ { 3, 6 }, { 0, 4 }, { 0, 1 }, { 4, 4 }, { 0, 1 }, },
+ { { 123, 29 }, { 0, 0 }, { 1, 7 }, { 57, 30 }, { 0, 0 },
+ { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 0 }, }, },
+ { { { 16, 20 }, { 0, 0 }, { 2, 8 }, { 104, 49 }, { 15, 33 },
+ { 0, 1 }, { 0, 1 }, { 0, 1 }, { 1, 1 }, { 0, 0 }, },
+ { { 133, 6 }, { 1, 2 }, { 1, 70 }, { 0, 0 }, { 0, 0 },
+ { 0, 2 }, { 0, 4 }, { 0, 3 }, { 1, 1 }, { 0, 0 }, },
+ { { 13, 14 }, { 0, 0 }, { 4, 20 }, { 175, 20 }, { 0, 0 },
+ { 0, 1 }, { 0, 1 }, { 0, 1 }, { 1, 1 }, { 0, 0 }, }, },
+ { { { 194, 16 }, { 0, 0 }, { 1, 1 }, { 1, 9 }, { 1, 3 },
+ { 0, 0 }, { 0, 1 }, { 0, 1 }, { 0, 0 }, { 0, 0 }, },
+ { { 251, 1 }, { 0, 0 }, { 0, 2 }, { 0, 0 }, { 0, 0 },
+ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, },
+ { { 202, 23 }, { 0, 0 }, { 1, 3 }, { 2, 9 }, { 0, 0 },
+ { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 0 }, { 0, 0 }, }, },
+};
+
+static const uint8_t vp56_filter_threshold[] = {
+ 14, 14, 13, 13, 12, 12, 10, 10,
+ 10, 10, 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, 7, 7, 7, 7,
+ 7, 7, 6, 6, 6, 6, 6, 6,
+ 5, 5, 5, 5, 4, 4, 4, 4,
+ 4, 4, 4, 3, 3, 3, 3, 2,
+};
+
+static const uint8_t vp56_mb_type_model_model[] = {
+ 171, 83, 199, 140, 125, 104,
+};
+
+static const vp56_tree_t vp56_pmbtm_tree[] = {
+ { 4, 0},
+ { 2, 1}, {-8}, {-4},
+ { 8, 2},
+ { 6, 3},
+ { 4, 4},
+ { 2, 5}, {-24}, {-20}, {-16}, {-12}, {-0},
+};
+
+static const vp56_tree_t vp56_pmbt_tree[] = {
+ { 8, 1},
+ { 4, 2},
+ { 2, 4}, {-VP56_MB_INTER_NOVEC_PF}, {-VP56_MB_INTER_DELTA_PF},
+ { 2, 5}, {-VP56_MB_INTER_V1_PF}, {-VP56_MB_INTER_V2_PF},
+ { 4, 3},
+ { 2, 6}, {-VP56_MB_INTRA}, {-VP56_MB_INTER_4V},
+ { 4, 7},
+ { 2, 8}, {-VP56_MB_INTER_NOVEC_GF}, {-VP56_MB_INTER_DELTA_GF},
+ { 2, 9}, {-VP56_MB_INTER_V1_GF}, {-VP56_MB_INTER_V2_GF},
+};
+
+/* relative pos of surrounding blocks, from closest to farthest */
+static const int8_t vp56_candidate_predictor_pos[12][2] = {
+ { 0, -1 },
+ { -1, 0 },
+ { -1, -1 },
+ { 1, -1 },
+ { 0, -2 },
+ { -2, 0 },
+ { -2, -1 },
+ { -1, -2 },
+ { 1, -2 },
+ { 2, -1 },
+ { -2, -2 },
+ { 2, -2 },
+};
+
+#endif /* VP56DATA */
diff --git a/src/libffmpeg/libavcodec/vp5data.h b/contrib/ffmpeg/libavcodec/vp5data.h
index effc17c2c..effc17c2c 100644
--- a/src/libffmpeg/libavcodec/vp5data.h
+++ b/contrib/ffmpeg/libavcodec/vp5data.h
diff --git a/contrib/ffmpeg/libavcodec/vp6.c b/contrib/ffmpeg/libavcodec/vp6.c
new file mode 100644
index 000000000..2e904b7e0
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/vp6.c
@@ -0,0 +1,556 @@
+/**
+ * @file vp6.c
+ * VP6 compatible video decoder
+ *
+ * Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ *
+ * The VP6F decoder accept an optional 1 byte extradata. It is composed of:
+ * - upper 4bits: difference between encoded width and visible width
+ * - lower 4bits: difference between encoded height and visible height
+ */
+
+#include <stdlib.h>
+
+#include "avcodec.h"
+#include "dsputil.h"
+#include "bitstream.h"
+#include "mpegvideo.h"
+
+#include "vp56.h"
+#include "vp56data.h"
+#include "vp6data.h"
+
+
+static int vp6_parse_header(vp56_context_t *s, uint8_t *buf, int buf_size,
+ int *golden_frame)
+{
+ vp56_range_coder_t *c = &s->c;
+ int parse_filter_info = 0;
+ int coeff_offset = 0;
+ int vrt_shift = 0;
+ int sub_version;
+ int rows, cols;
+ int res = 1;
+ int separated_coeff = buf[0] & 1;
+
+ s->framep[VP56_FRAME_CURRENT]->key_frame = !(buf[0] & 0x80);
+ vp56_init_dequant(s, (buf[0] >> 1) & 0x3F);
+
+ if (s->framep[VP56_FRAME_CURRENT]->key_frame) {
+ sub_version = buf[1] >> 3;
+ if (sub_version > 8)
+ return 0;
+ s->filter_header = buf[1] & 0x06;
+ if (buf[1] & 1) {
+ av_log(s->avctx, AV_LOG_ERROR, "interlacing not supported\n");
+ return 0;
+ }
+ if (separated_coeff || !s->filter_header) {
+ coeff_offset = AV_RB16(buf+2) - 2;
+ buf += 2;
+ buf_size -= 2;
+ }
+
+ rows = buf[2]; /* number of stored macroblock rows */
+ cols = buf[3]; /* number of stored macroblock cols */
+ /* buf[4] is number of displayed macroblock rows */
+ /* buf[5] is number of displayed macroblock cols */
+
+ if (16*cols != s->avctx->coded_width ||
+ 16*rows != s->avctx->coded_height) {
+ avcodec_set_dimensions(s->avctx, 16*cols, 16*rows);
+ if (s->avctx->extradata_size == 1) {
+ s->avctx->width -= s->avctx->extradata[0] >> 4;
+ s->avctx->height -= s->avctx->extradata[0] & 0x0F;
+ }
+ res = 2;
+ }
+
+ vp56_init_range_decoder(c, buf+6, buf_size-6);
+ vp56_rac_gets(c, 2);
+
+ parse_filter_info = s->filter_header;
+ if (sub_version < 8)
+ vrt_shift = 5;
+ s->sub_version = sub_version;
+ } else {
+ if (!s->sub_version)
+ return 0;
+
+ if (separated_coeff || !s->filter_header) {
+ coeff_offset = AV_RB16(buf+1) - 2;
+ buf += 2;
+ buf_size -= 2;
+ }
+ vp56_init_range_decoder(c, buf+1, buf_size-1);
+
+ *golden_frame = vp56_rac_get(c);
+ if (s->filter_header) {
+ s->deblock_filtering = vp56_rac_get(c);
+ if (s->deblock_filtering)
+ vp56_rac_get(c);
+ if (s->sub_version > 7)
+ parse_filter_info = vp56_rac_get(c);
+ }
+ }
+
+ if (parse_filter_info) {
+ if (vp56_rac_get(c)) {
+ s->filter_mode = 2;
+ s->sample_variance_threshold = vp56_rac_gets(c, 5) << vrt_shift;
+ s->max_vector_length = 2 << vp56_rac_gets(c, 3);
+ } else if (vp56_rac_get(c)) {
+ s->filter_mode = 1;
+ } else {
+ s->filter_mode = 0;
+ }
+ if (s->sub_version > 7)
+ s->filter_selection = vp56_rac_gets(c, 4);
+ else
+ s->filter_selection = 16;
+ }
+
+ vp56_rac_get(c);
+
+ if (coeff_offset) {
+ vp56_init_range_decoder(&s->cc, buf+coeff_offset,
+ buf_size-coeff_offset);
+ s->ccp = &s->cc;
+ } else {
+ s->ccp = &s->c;
+ }
+
+ return res;
+}
+
+static void vp6_coeff_order_table_init(vp56_context_t *s)
+{
+ int i, pos, idx = 1;
+
+ s->coeff_index_to_pos[0] = 0;
+ for (i=0; i<16; i++)
+ for (pos=1; pos<64; pos++)
+ if (s->coeff_reorder[pos] == i)
+ s->coeff_index_to_pos[idx++] = pos;
+}
+
+static void vp6_default_models_init(vp56_context_t *s)
+{
+ s->vector_model_dct[0] = 0xA2;
+ s->vector_model_dct[1] = 0xA4;
+ s->vector_model_sig[0] = 0x80;
+ s->vector_model_sig[1] = 0x80;
+
+ memcpy(s->mb_types_stats, vp56_def_mb_types_stats, sizeof(s->mb_types_stats));
+ memcpy(s->vector_model_fdv, vp6_def_fdv_vector_model, sizeof(s->vector_model_fdv));
+ memcpy(s->vector_model_pdv, vp6_def_pdv_vector_model, sizeof(s->vector_model_pdv));
+ memcpy(s->coeff_model_runv, vp6_def_runv_coeff_model, sizeof(s->coeff_model_runv));
+ memcpy(s->coeff_reorder, vp6_def_coeff_reorder, sizeof(s->coeff_reorder));
+
+ vp6_coeff_order_table_init(s);
+}
+
+static void vp6_parse_vector_models(vp56_context_t *s)
+{
+ vp56_range_coder_t *c = &s->c;
+ int comp, node;
+
+ for (comp=0; comp<2; comp++) {
+ if (vp56_rac_get_prob(c, vp6_sig_dct_pct[comp][0]))
+ s->vector_model_dct[comp] = vp56_rac_gets_nn(c, 7);
+ if (vp56_rac_get_prob(c, vp6_sig_dct_pct[comp][1]))
+ s->vector_model_sig[comp] = vp56_rac_gets_nn(c, 7);
+ }
+
+ for (comp=0; comp<2; comp++)
+ for (node=0; node<7; node++)
+ if (vp56_rac_get_prob(c, vp6_pdv_pct[comp][node]))
+ s->vector_model_pdv[comp][node] = vp56_rac_gets_nn(c, 7);
+
+ for (comp=0; comp<2; comp++)
+ for (node=0; node<8; node++)
+ if (vp56_rac_get_prob(c, vp6_fdv_pct[comp][node]))
+ s->vector_model_fdv[comp][node] = vp56_rac_gets_nn(c, 7);
+}
+
+static void vp6_parse_coeff_models(vp56_context_t *s)
+{
+ vp56_range_coder_t *c = &s->c;
+ int def_prob[11];
+ int node, cg, ctx, pos;
+ int ct; /* code type */
+ int pt; /* plane type (0 for Y, 1 for U or V) */
+
+ memset(def_prob, 0x80, sizeof(def_prob));
+
+ for (pt=0; pt<2; pt++)
+ for (node=0; node<11; node++)
+ if (vp56_rac_get_prob(c, vp6_dccv_pct[pt][node])) {
+ def_prob[node] = vp56_rac_gets_nn(c, 7);
+ s->coeff_model_dccv[pt][node] = def_prob[node];
+ } else if (s->framep[VP56_FRAME_CURRENT]->key_frame) {
+ s->coeff_model_dccv[pt][node] = def_prob[node];
+ }
+
+ if (vp56_rac_get(c)) {
+ for (pos=1; pos<64; pos++)
+ if (vp56_rac_get_prob(c, vp6_coeff_reorder_pct[pos]))
+ s->coeff_reorder[pos] = vp56_rac_gets(c, 4);
+ vp6_coeff_order_table_init(s);
+ }
+
+ for (cg=0; cg<2; cg++)
+ for (node=0; node<14; node++)
+ if (vp56_rac_get_prob(c, vp6_runv_pct[cg][node]))
+ s->coeff_model_runv[cg][node] = vp56_rac_gets_nn(c, 7);
+
+ for (ct=0; ct<3; ct++)
+ for (pt=0; pt<2; pt++)
+ for (cg=0; cg<6; cg++)
+ for (node=0; node<11; node++)
+ if (vp56_rac_get_prob(c, vp6_ract_pct[ct][pt][cg][node])) {
+ def_prob[node] = vp56_rac_gets_nn(c, 7);
+ s->coeff_model_ract[pt][ct][cg][node] = def_prob[node];
+ } else if (s->framep[VP56_FRAME_CURRENT]->key_frame) {
+ s->coeff_model_ract[pt][ct][cg][node] = def_prob[node];
+ }
+
+ /* coeff_model_dcct is a linear combination of coeff_model_dccv */
+ for (pt=0; pt<2; pt++)
+ for (ctx=0; ctx<3; ctx++)
+ for (node=0; node<5; node++)
+ s->coeff_model_dcct[pt][ctx][node] = av_clip(((s->coeff_model_dccv[pt][node] * vp6_dccv_lc[ctx][node][0] + 128) >> 8) + vp6_dccv_lc[ctx][node][1], 1, 255);
+}
+
+static void vp6_parse_vector_adjustment(vp56_context_t *s, vp56_mv_t *vect)
+{
+ vp56_range_coder_t *c = &s->c;
+ int comp;
+
+ *vect = (vp56_mv_t) {0,0};
+ if (s->vector_candidate_pos < 2)
+ *vect = s->vector_candidate[0];
+
+ for (comp=0; comp<2; comp++) {
+ int i, delta = 0;
+
+ if (vp56_rac_get_prob(c, s->vector_model_dct[comp])) {
+ static const uint8_t prob_order[] = {0, 1, 2, 7, 6, 5, 4};
+ for (i=0; i<sizeof(prob_order); i++) {
+ int j = prob_order[i];
+ delta |= vp56_rac_get_prob(c, s->vector_model_fdv[comp][j])<<j;
+ }
+ if (delta & 0xF0)
+ delta |= vp56_rac_get_prob(c, s->vector_model_fdv[comp][3])<<3;
+ else
+ delta |= 8;
+ } else {
+ delta = vp56_rac_get_tree(c, vp56_pva_tree,
+ s->vector_model_pdv[comp]);
+ }
+
+ if (delta && vp56_rac_get_prob(c, s->vector_model_sig[comp]))
+ delta = -delta;
+
+ if (!comp)
+ vect->x += delta;
+ else
+ vect->y += delta;
+ }
+}
+
+static void vp6_parse_coeff(vp56_context_t *s)
+{
+ vp56_range_coder_t *c = s->ccp;
+ uint8_t *permute = s->scantable.permutated;
+ uint8_t *model, *model2, *model3;
+ int coeff, sign, coeff_idx;
+ int b, i, cg, idx, ctx;
+ int pt = 0; /* plane type (0 for Y, 1 for U or V) */
+
+ for (b=0; b<6; b++) {
+ int ct = 1; /* code type */
+ int run = 1;
+
+ if (b > 3) pt = 1;
+
+ ctx = s->left_block[vp56_b6to4[b]].not_null_dc
+ + s->above_blocks[s->above_block_idx[b]].not_null_dc;
+ model = s->coeff_model_dccv[pt];
+ model2 = s->coeff_model_dcct[pt][ctx];
+
+ for (coeff_idx=0; coeff_idx<64; ) {
+ if ((coeff_idx>1 && ct==0) || vp56_rac_get_prob(c, model2[0])) {
+ /* parse a coeff */
+ if (coeff_idx == 0) {
+ s->left_block[vp56_b6to4[b]].not_null_dc = 1;
+ s->above_blocks[s->above_block_idx[b]].not_null_dc = 1;
+ }
+
+ if (vp56_rac_get_prob(c, model2[2])) {
+ if (vp56_rac_get_prob(c, model2[3])) {
+ idx = vp56_rac_get_tree(c, vp56_pc_tree, model);
+ coeff = vp56_coeff_bias[idx];
+ for (i=vp56_coeff_bit_length[idx]; i>=0; i--)
+ coeff += vp56_rac_get_prob(c, vp56_coeff_parse_table[idx][i]) << i;
+ } else {
+ if (vp56_rac_get_prob(c, model2[4]))
+ coeff = 3 + vp56_rac_get_prob(c, model[5]);
+ else
+ coeff = 2;
+ }
+ ct = 2;
+ } else {
+ ct = 1;
+ coeff = 1;
+ }
+ sign = vp56_rac_get(c);
+ coeff = (coeff ^ -sign) + sign;
+ if (coeff_idx)
+ coeff *= s->dequant_ac;
+ idx = s->coeff_index_to_pos[coeff_idx];
+ s->block_coeff[b][permute[idx]] = coeff;
+ run = 1;
+ } else {
+ /* parse a run */
+ ct = 0;
+ if (coeff_idx == 0) {
+ s->left_block[vp56_b6to4[b]].not_null_dc = 0;
+ s->above_blocks[s->above_block_idx[b]].not_null_dc = 0;
+ } else {
+ if (!vp56_rac_get_prob(c, model2[1]))
+ break;
+
+ model3 = s->coeff_model_runv[coeff_idx >= 6];
+ run = vp56_rac_get_tree(c, vp6_pcr_tree, model3);
+ if (!run)
+ for (run=9, i=0; i<6; i++)
+ run += vp56_rac_get_prob(c, model3[i+8]) << i;
+ }
+ }
+
+ cg = vp6_coeff_groups[coeff_idx+=run];
+ model = model2 = s->coeff_model_ract[pt][ct][cg];
+ }
+ }
+}
+
+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;
+ int y, x;
+
+ for (y=0; y<8; y+=2) {
+ for (x=0; x<8; x+=2) {
+ sum += src[x];
+ square_sum += src[x]*src[x];
+ }
+ src += 2*stride;
+ }
+ return (16*square_sum - sum*sum) >> 8;
+}
+
+static void vp6_filter_hv2(vp56_context_t *s, uint8_t *dst, uint8_t *src,
+ int stride, int delta, int16_t weight)
+{
+ s->dsp.put_pixels_tab[1][0](dst, src, stride, 8);
+ s->dsp.biweight_h264_pixels_tab[3](dst, src+delta, stride, 2,
+ 8-weight, weight, 0);
+}
+
+static void vp6_filter_hv4(uint8_t *dst, uint8_t *src, int stride,
+ int delta, const int16_t *weights)
+{
+ int x, y;
+
+ for (y=0; y<8; y++) {
+ for (x=0; x<8; x++) {
+ dst[x] = av_clip_uint8(( src[x-delta ] * weights[0]
+ + src[x ] * weights[1]
+ + src[x+delta ] * weights[2]
+ + src[x+2*delta] * weights[3] + 64) >> 7);
+ }
+ src += stride;
+ dst += stride;
+ }
+}
+
+static void vp6_filter_diag2(vp56_context_t *s, uint8_t *dst, uint8_t *src,
+ int stride, int h_weight, int v_weight)
+{
+ uint8_t *tmp = s->edge_emu_buffer+16;
+ int x, xmax;
+
+ s->dsp.put_pixels_tab[1][0](tmp, src, stride, 8);
+ s->dsp.biweight_h264_pixels_tab[3](tmp, src+1, stride, 2,
+ 8-h_weight, h_weight, 0);
+ /* we need a 8x9 block to do vertical filter, so compute one more line */
+ for (x=8*stride, xmax=x+8; x<xmax; x++)
+ tmp[x] = (src[x]*(8-h_weight) + src[x+1]*h_weight + 4) >> 3;
+
+ s->dsp.put_pixels_tab[1][0](dst, tmp, stride, 8);
+ s->dsp.biweight_h264_pixels_tab[3](dst, tmp+stride, stride, 2,
+ 8-v_weight, v_weight, 0);
+}
+
+static void vp6_filter_diag4(uint8_t *dst, uint8_t *src, int stride,
+ const int16_t *h_weights,const int16_t *v_weights)
+{
+ int x, y;
+ int tmp[8*11];
+ int *t = tmp;
+
+ src -= stride;
+
+ for (y=0; y<11; y++) {
+ for (x=0; x<8; x++) {
+ t[x] = av_clip_uint8(( src[x-1] * h_weights[0]
+ + src[x ] * h_weights[1]
+ + src[x+1] * h_weights[2]
+ + src[x+2] * h_weights[3] + 64) >> 7);
+ }
+ src += stride;
+ t += 8;
+ }
+
+ t = tmp + 8;
+ for (y=0; y<8; y++) {
+ for (x=0; x<8; x++) {
+ dst[x] = av_clip_uint8(( t[x-8 ] * v_weights[0]
+ + t[x ] * v_weights[1]
+ + t[x+8 ] * v_weights[2]
+ + t[x+16] * v_weights[3] + 64) >> 7);
+ }
+ dst += stride;
+ t += 8;
+ }
+}
+
+static void vp6_filter(vp56_context_t *s, uint8_t *dst, uint8_t *src,
+ int offset1, int offset2, int stride,
+ vp56_mv_t mv, int mask, int select, int luma)
+{
+ int filter4 = 0;
+ int x8 = mv.x & mask;
+ int y8 = mv.y & mask;
+
+ if (luma) {
+ x8 *= 2;
+ y8 *= 2;
+ filter4 = s->filter_mode;
+ if (filter4 == 2) {
+ if (s->max_vector_length &&
+ (FFABS(mv.x) > s->max_vector_length ||
+ FFABS(mv.y) > s->max_vector_length)) {
+ filter4 = 0;
+ } else if (s->sample_variance_threshold
+ && (vp6_block_variance(src+offset1, stride)
+ < s->sample_variance_threshold)) {
+ filter4 = 0;
+ }
+ }
+ }
+
+ if ((y8 && (offset2-offset1)*s->flip<0) || (!y8 && offset1 > offset2)) {
+ offset1 = offset2;
+ }
+
+ if (filter4) {
+ if (!y8) { /* left or right combine */
+ vp6_filter_hv4(dst, src+offset1, stride, 1,
+ vp6_block_copy_filter[select][x8]);
+ } else if (!x8) { /* above or below combine */
+ vp6_filter_hv4(dst, src+offset1, stride, stride,
+ vp6_block_copy_filter[select][y8]);
+ } else if ((mv.x^mv.y) >> 31) { /* lower-left or upper-right combine */
+ vp6_filter_diag4(dst, src+offset1-1, stride,
+ vp6_block_copy_filter[select][x8],
+ vp6_block_copy_filter[select][y8]);
+ } else { /* lower-right or upper-left combine */
+ vp6_filter_diag4(dst, src+offset1, stride,
+ vp6_block_copy_filter[select][x8],
+ vp6_block_copy_filter[select][y8]);
+ }
+ } else {
+ if (!y8) { /* left or right combine */
+ vp6_filter_hv2(s, dst, src+offset1, stride, 1, x8);
+ } else if (!x8) { /* above or below combine */
+ vp6_filter_hv2(s, dst, src+offset1, stride, stride, y8);
+ } else if ((mv.x^mv.y) >> 31) { /* lower-left or upper-right combine */
+ vp6_filter_diag2(s, dst, src+offset1-1, stride, x8, y8);
+ } else { /* lower-right or upper-left combine */
+ vp6_filter_diag2(s, dst, src+offset1, stride, x8, y8);
+ }
+ }
+}
+
+static int vp6_decode_init(AVCodecContext *avctx)
+{
+ vp56_context_t *s = avctx->priv_data;
+
+ vp56_init(s, avctx, avctx->codec->id == CODEC_ID_VP6);
+ s->vp56_coord_div = vp6_coord_div;
+ s->parse_vector_adjustment = vp6_parse_vector_adjustment;
+ s->adjust = vp6_adjust;
+ s->filter = vp6_filter;
+ s->parse_coeff = vp6_parse_coeff;
+ s->default_models_init = vp6_default_models_init;
+ s->parse_vector_models = vp6_parse_vector_models;
+ s->parse_coeff_models = vp6_parse_coeff_models;
+ s->parse_header = vp6_parse_header;
+
+ return 0;
+}
+
+AVCodec vp6_decoder = {
+ "vp6",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_VP6,
+ sizeof(vp56_context_t),
+ vp6_decode_init,
+ NULL,
+ vp56_free,
+ vp56_decode_frame,
+};
+
+/* flash version, not flipped upside-down */
+AVCodec vp6f_decoder = {
+ "vp6f",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_VP6F,
+ sizeof(vp56_context_t),
+ vp6_decode_init,
+ NULL,
+ vp56_free,
+ vp56_decode_frame,
+};
diff --git a/src/libffmpeg/libavcodec/vp6data.h b/contrib/ffmpeg/libavcodec/vp6data.h
index 0545a9d66..0545a9d66 100644
--- a/src/libffmpeg/libavcodec/vp6data.h
+++ b/contrib/ffmpeg/libavcodec/vp6data.h
diff --git a/src/libffmpeg/libavcodec/vqavideo.c b/contrib/ffmpeg/libavcodec/vqavideo.c
index 57fe6cf44..57fe6cf44 100644
--- a/src/libffmpeg/libavcodec/vqavideo.c
+++ b/contrib/ffmpeg/libavcodec/vqavideo.c
diff --git a/contrib/ffmpeg/libavcodec/w32thread.c b/contrib/ffmpeg/libavcodec/w32thread.c
new file mode 100644
index 000000000..e749a64af
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/w32thread.c
@@ -0,0 +1,136 @@
+/*
+ * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+//#define DEBUG
+
+#include "avcodec.h"
+#include "common.h"
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <process.h>
+
+typedef struct ThreadContext{
+ AVCodecContext *avctx;
+ HANDLE thread;
+ HANDLE work_sem;
+ HANDLE done_sem;
+ int (*func)(AVCodecContext *c, void *arg);
+ void *arg;
+ int ret;
+}ThreadContext;
+
+
+static unsigned __stdcall thread_func(void *v){
+ ThreadContext *c= v;
+
+ for(;;){
+//printf("thread_func %X enter wait\n", (int)v); fflush(stdout);
+ WaitForSingleObject(c->work_sem, INFINITE);
+//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);
+ else
+ return 0;
+//printf("thread_func %X signal complete\n", (int)v); fflush(stdout);
+ ReleaseSemaphore(c->done_sem, 1, 0);
+ }
+
+ return 0;
+}
+
+/**
+ * free what has been allocated by avcodec_thread_init().
+ * must be called after decoding has finished, especially dont call while avcodec_thread_execute() is running
+ */
+void avcodec_thread_free(AVCodecContext *s){
+ ThreadContext *c= s->thread_opaque;
+ int i;
+
+ for(i=0; i<s->thread_count; i++){
+
+ c[i].func= NULL;
+ ReleaseSemaphore(c[i].work_sem, 1, 0);
+ 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);
+ }
+
+ av_freep(&s->thread_opaque);
+}
+
+int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count){
+ ThreadContext *c= s->thread_opaque;
+ int i;
+
+ 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; i<count; i++){
+ c[i].arg= arg[i];
+ c[i].func= func;
+ c[i].ret= 12345;
+
+ ReleaseSemaphore(c[i].work_sem, 1, 0);
+ }
+ for(i=0; i<count; i++){
+ WaitForSingleObject(c[i].done_sem, INFINITE);
+
+ c[i].func= NULL;
+ if(ret) ret[i]= c[i].ret;
+ }
+ return 0;
+}
+
+int avcodec_thread_init(AVCodecContext *s, int thread_count){
+ int i;
+ ThreadContext *c;
+ uint32_t threadid;
+
+ s->thread_count= thread_count;
+
+ assert(!s->thread_opaque);
+ c= av_mallocz(sizeof(ThreadContext)*thread_count);
+ s->thread_opaque= c;
+
+ for(i=0; i<thread_count; i++){
+//printf("init semaphors %d\n", i); fflush(stdout);
+ c[i].avctx= s;
+
+ if(!(c[i].work_sem = CreateSemaphore(NULL, 0, s->thread_count, NULL)))
+ goto fail;
+ if(!(c[i].done_sem = CreateSemaphore(NULL, 0, s->thread_count, NULL)))
+ goto fail;
+
+//printf("create thread %d\n", i); fflush(stdout);
+ c[i].thread = (HANDLE)_beginthreadex(NULL, 0, thread_func, &c[i], 0, &threadid );
+ if( !c[i].thread ) goto fail;
+ }
+//printf("init done\n"); fflush(stdout);
+
+ s->execute= avcodec_thread_execute;
+
+ return 0;
+fail:
+ avcodec_thread_free(s);
+ return -1;
+}
diff --git a/contrib/ffmpeg/libavcodec/wavpack.c b/contrib/ffmpeg/libavcodec/wavpack.c
new file mode 100644
index 000000000..e79d4a570
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/wavpack.c
@@ -0,0 +1,562 @@
+/*
+ * WavPack lossless audio decoder
+ * Copyright (c) 2006 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
+ */
+#define ALT_BITSTREAM_READER_LE
+#include "avcodec.h"
+#include "bitstream.h"
+
+/**
+ * @file wavpack.c
+ * WavPack lossless audio decoder
+ */
+
+#define WV_JOINT 0x0010
+
+enum WP_ID_Flags{
+ WP_IDF_MASK = 0x1F,
+ WP_IDF_IGNORE = 0x20,
+ WP_IDF_ODD = 0x40,
+ WP_IDF_LONG = 0x80
+};
+
+enum WP_ID{
+ WP_ID_DUMMY = 0,
+ WP_ID_ENCINFO,
+ WP_ID_DECTERMS,
+ WP_ID_DECWEIGHTS,
+ WP_ID_DECSAMPLES,
+ WP_ID_ENTROPY,
+ WP_ID_HYBRID,
+ WP_ID_SHAPING,
+ WP_ID_FLOATINFO,
+ WP_ID_INT32INFO,
+ WP_ID_DATA,
+ WP_ID_CORR,
+ WP_ID_FLT,
+ WP_ID_CHANINFO
+};
+
+#define MAX_TERMS 16
+
+typedef struct Decorr {
+ int delta;
+ int value;
+ int weightA;
+ int weightB;
+ int samplesA[8];
+ int samplesB[8];
+} Decorr;
+
+typedef struct WavpackContext {
+ AVCodecContext *avctx;
+ int stereo;
+ int joint;
+ uint32_t CRC;
+ GetBitContext gb;
+ int data_size; // in bits
+ int samples;
+ int median[6];
+ int terms;
+ Decorr decorr[MAX_TERMS];
+ int zero, one, zeroes;
+} WavpackContext;
+
+// exponent table copied from WavPack source
+static const uint8_t wp_exp2_table [256] = {
+ 0x00, 0x01, 0x01, 0x02, 0x03, 0x03, 0x04, 0x05, 0x06, 0x06, 0x07, 0x08, 0x08, 0x09, 0x0a, 0x0b,
+ 0x0b, 0x0c, 0x0d, 0x0e, 0x0e, 0x0f, 0x10, 0x10, 0x11, 0x12, 0x13, 0x13, 0x14, 0x15, 0x16, 0x16,
+ 0x17, 0x18, 0x19, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1d, 0x1e, 0x1f, 0x20, 0x20, 0x21, 0x22, 0x23,
+ 0x24, 0x24, 0x25, 0x26, 0x27, 0x28, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3a, 0x3b, 0x3c, 0x3d,
+ 0x3e, 0x3f, 0x40, 0x41, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x48, 0x49, 0x4a, 0x4b,
+ 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a,
+ 0x5b, 0x5c, 0x5d, 0x5e, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
+ 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
+ 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x87, 0x88, 0x89, 0x8a,
+ 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,
+ 0x9c, 0x9d, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad,
+ 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0,
+ 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc8, 0xc9, 0xca, 0xcb, 0xcd, 0xce, 0xcf, 0xd0, 0xd2, 0xd3, 0xd4,
+ 0xd6, 0xd7, 0xd8, 0xd9, 0xdb, 0xdc, 0xdd, 0xde, 0xe0, 0xe1, 0xe2, 0xe4, 0xe5, 0xe6, 0xe8, 0xe9,
+ 0xea, 0xec, 0xed, 0xee, 0xf0, 0xf1, 0xf2, 0xf4, 0xf5, 0xf6, 0xf8, 0xf9, 0xfa, 0xfc, 0xfd, 0xff
+};
+
+static av_always_inline int wp_exp2(int16_t val)
+{
+ int res, neg = 0;
+
+ if(val < 0){
+ val = -val;
+ neg = 1;
+ }
+
+ res = wp_exp2_table[val & 0xFF] | 0x100;
+ val >>= 8;
+ res = (val > 9) ? (res << (val - 9)) : (res >> (9 - val));
+ return neg ? -res : res;
+}
+
+static inline int get_unary(GetBitContext *gb){
+ int r=0;
+ while(get_bits1(gb) && r<33)r++;
+ return r;
+}
+
+// macros for manipulating median values
+#define GET_MED(n) ((median[n] >> 4) + 1)
+#define DEC_MED(n) median[n] -= ((median[n] + (128>>n) - 2) / (128>>n)) * 2
+#define INC_MED(n) median[n] += ((median[n] + (128>>n)) / (128>>n)) * 5
+
+// macros for applying weight
+#define UPDATE_WEIGHT_CLIP(weight, delta, samples, in) \
+ if(samples && in){ \
+ if((samples ^ in) < 0){ \
+ weight -= delta; \
+ if(weight < -1024) weight = -1024; \
+ }else{ \
+ weight += delta; \
+ if(weight > 1024) weight = 1024; \
+ } \
+ }
+
+
+static av_always_inline int get_tail(GetBitContext *gb, int k)
+{
+ int p, e, res;
+
+ if(k<1)return 0;
+ p = av_log2(k);
+ e = (1 << (p + 1)) - k - 1;
+ res = p ? get_bits(gb, p) : 0;
+ if(res >= e){
+ res = (res<<1) - e + get_bits1(gb);
+ }
+ return res;
+}
+
+static int wv_get_value(WavpackContext *ctx, GetBitContext *gb, int *median, int *last)
+{
+ int t, t2;
+ int sign, base, add, ret;
+
+ *last = 0;
+
+ if((ctx->median[0] < 2U) && (ctx->median[3] < 2U) && !ctx->zero && !ctx->one){
+ if(ctx->zeroes){
+ ctx->zeroes--;
+ if(ctx->zeroes)
+ return 0;
+ }else{
+ t = get_unary(gb);
+ if(t >= 2) t = get_bits(gb, t - 1) | (1 << (t-1));
+ ctx->zeroes = t;
+ if(ctx->zeroes){
+ memset(ctx->median, 0, sizeof(ctx->median));
+ return 0;
+ }
+ }
+ }
+
+ if(get_bits_count(gb) >= ctx->data_size){
+ *last = 1;
+ return 0;
+ }
+
+ if(ctx->zero){
+ t = 0;
+ ctx->zero = 0;
+ }else{
+ t = get_unary(gb);
+ if(get_bits_count(gb) >= ctx->data_size){
+ *last = 1;
+ return 0;
+ }
+ if(t == 16) {
+ t2 = get_unary(gb);
+ if(t2 < 2) t += t2;
+ else t += get_bits(gb, t2 - 1) | (1 << (t2 - 1));
+ }
+
+ if(ctx->one){
+ ctx->one = t&1;
+ t = (t>>1) + 1;
+ }else{
+ ctx->one = t&1;
+ t >>= 1;
+ }
+ ctx->zero = !ctx->one;
+ }
+
+ if(!t){
+ base = 0;
+ add = GET_MED(0) - 1;
+ DEC_MED(0);
+ }else if(t == 1){
+ base = GET_MED(0);
+ add = GET_MED(1) - 1;
+ INC_MED(0);
+ DEC_MED(1);
+ }else if(t == 2){
+ base = GET_MED(0) + GET_MED(1);
+ add = GET_MED(2) - 1;
+ INC_MED(0);
+ INC_MED(1);
+ DEC_MED(2);
+ }else{
+ base = GET_MED(0) + GET_MED(1) + GET_MED(2) * (t - 2);
+ add = GET_MED(2) - 1;
+ INC_MED(0);
+ INC_MED(1);
+ INC_MED(2);
+ }
+ ret = base + get_tail(gb, add);
+ sign = get_bits1(gb);
+ return sign ? ~ret : ret;
+}
+
+static int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, int16_t *dst)
+{
+ int i, j, count = 0;
+ int last, t;
+ int A, B, L, L2, R, R2;
+ int pos = 0;
+ uint32_t crc = 0xFFFFFFFF;
+
+ s->one = s->zero = s->zeroes = 0;
+ do{
+ L = wv_get_value(s, gb, s->median, &last);
+ if(last) break;
+ R = wv_get_value(s, gb, s->median + 3, &last);
+ if(last) break;
+ for(i = 0; i < s->terms; i++){
+ t = s->decorr[i].value;
+ j = 0;
+ if(t > 0){
+ if(t > 8){
+ if(t & 1){
+ A = 2 * s->decorr[i].samplesA[0] - s->decorr[i].samplesA[1];
+ B = 2 * s->decorr[i].samplesB[0] - s->decorr[i].samplesB[1];
+ }else{
+ A = (3 * s->decorr[i].samplesA[0] - s->decorr[i].samplesA[1]) >> 1;
+ B = (3 * s->decorr[i].samplesB[0] - s->decorr[i].samplesB[1]) >> 1;
+ }
+ s->decorr[i].samplesA[1] = s->decorr[i].samplesA[0];
+ s->decorr[i].samplesB[1] = s->decorr[i].samplesB[0];
+ j = 0;
+ }else{
+ A = s->decorr[i].samplesA[pos];
+ B = s->decorr[i].samplesB[pos];
+ j = (pos + t) & 7;
+ }
+ L2 = L + ((s->decorr[i].weightA * A + 512) >> 10);
+ R2 = R + ((s->decorr[i].weightB * B + 512) >> 10);
+ if(A && L) s->decorr[i].weightA -= ((((L ^ A) >> 30) & 2) - 1) * s->decorr[i].delta;
+ if(B && R) s->decorr[i].weightB -= ((((R ^ B) >> 30) & 2) - 1) * s->decorr[i].delta;
+ s->decorr[i].samplesA[j] = L = L2;
+ s->decorr[i].samplesB[j] = R = R2;
+ }else if(t == -1){
+ L2 = L + ((s->decorr[i].weightA * s->decorr[i].samplesA[0] + 512) >> 10);
+ UPDATE_WEIGHT_CLIP(s->decorr[i].weightA, s->decorr[i].delta, s->decorr[i].samplesA[0], L);
+ L = L2;
+ R2 = R + ((s->decorr[i].weightB * L2 + 512) >> 10);
+ UPDATE_WEIGHT_CLIP(s->decorr[i].weightB, s->decorr[i].delta, L2, R);
+ R = R2;
+ s->decorr[i].samplesA[0] = R;
+ }else{
+ R2 = R + ((s->decorr[i].weightB * s->decorr[i].samplesB[0] + 512) >> 10);
+ UPDATE_WEIGHT_CLIP(s->decorr[i].weightB, s->decorr[i].delta, s->decorr[i].samplesB[0], R);
+ R = R2;
+
+ if(t == -3){
+ R2 = s->decorr[i].samplesA[0];
+ s->decorr[i].samplesA[0] = R;
+ }
+
+ L2 = L + ((s->decorr[i].weightA * R2 + 512) >> 10);
+ UPDATE_WEIGHT_CLIP(s->decorr[i].weightA, s->decorr[i].delta, R2, L);
+ L = L2;
+ s->decorr[i].samplesB[0] = L;
+ }
+ }
+ pos = (pos + 1) & 7;
+ if(s->joint)
+ L += (R -= (L >> 1));
+ crc = (crc * 3 + L) * 3 + R;
+ *dst++ = L;
+ *dst++ = R;
+
+ count++;
+ }while(!last && count < s->samples);
+
+ if(crc != s->CRC){
+ av_log(s->avctx, AV_LOG_ERROR, "CRC error\n");
+ return -1;
+ }
+ return count * 2;
+}
+
+static int wv_unpack_mono(WavpackContext *s, GetBitContext *gb, int16_t *dst)
+{
+ int i, j, count = 0;
+ int last, t;
+ int A, S, T;
+ int pos = 0;
+ uint32_t crc = 0xFFFFFFFF;
+
+ s->one = s->zero = s->zeroes = 0;
+ do{
+ T = wv_get_value(s, gb, s->median, &last);
+ S = 0;
+ if(last) break;
+ for(i = 0; i < s->terms; i++){
+ t = s->decorr[i].value;
+ if(t > 8){
+ if(t & 1)
+ A = 2 * s->decorr[i].samplesA[0] - s->decorr[i].samplesA[1];
+ else
+ A = (3 * s->decorr[i].samplesA[0] - s->decorr[i].samplesA[1]) >> 1;
+ s->decorr[i].samplesA[1] = s->decorr[i].samplesA[0];
+ j = 0;
+ }else{
+ A = s->decorr[i].samplesA[pos];
+ j = (pos + t) & 7;
+ }
+ S = T + ((s->decorr[i].weightA * A + 512) >> 10);
+ if(A && T) s->decorr[i].weightA -= ((((T ^ A) >> 30) & 2) - 1) * s->decorr[i].delta;
+ s->decorr[i].samplesA[j] = T = S;
+ }
+ pos = (pos + 1) & 7;
+ crc = crc * 3 + S;
+ *dst++ = S;
+ count++;
+ }while(!last && count < s->samples);
+
+ if(crc != s->CRC){
+ av_log(s->avctx, AV_LOG_ERROR, "CRC error\n");
+ return -1;
+ }
+ return count;
+}
+
+static int wavpack_decode_init(AVCodecContext *avctx)
+{
+ WavpackContext *s = avctx->priv_data;
+
+ s->avctx = avctx;
+ s->stereo = (avctx->channels == 2);
+
+ return 0;
+}
+
+static int wavpack_decode_close(AVCodecContext *avctx)
+{
+// WavpackContext *s = avctx->priv_data;
+
+ return 0;
+}
+
+static int wavpack_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ WavpackContext *s = avctx->priv_data;
+ int16_t *samples = data;
+ int samplecount;
+ int got_terms = 0, got_weights = 0, got_samples = 0, got_entropy = 0, got_bs = 0;
+ uint8_t* buf_end = buf + buf_size;
+ int i, j, id, size, ssize, weights, t;
+
+ if (buf_size == 0){
+ *data_size = 0;
+ return 0;
+ }
+
+ memset(s->decorr, 0, MAX_TERMS * sizeof(Decorr));
+
+ s->samples = AV_RL32(buf); buf += 4;
+ if(!s->samples){
+ *data_size = 0;
+ return buf_size;
+ }
+ /* should not happen but who knows */
+ if(s->samples * 2 * avctx->channels > *data_size){
+ av_log(avctx, AV_LOG_ERROR, "Packet size is too big to be handled in lavc!\n");
+ return -1;
+ }
+ s->joint = AV_RL32(buf) & WV_JOINT; buf += 4;
+ s->CRC = AV_RL32(buf); buf += 4;
+ // parse metadata blocks
+ while(buf < buf_end){
+ id = *buf++;
+ size = *buf++;
+ if(id & WP_IDF_LONG) {
+ size |= (*buf++) << 8;
+ size |= (*buf++) << 16;
+ }
+ size <<= 1; // size is specified in words
+ ssize = size;
+ if(id & WP_IDF_ODD) size--;
+ if(size < 0){
+ av_log(avctx, AV_LOG_ERROR, "Got incorrect block %02X with size %i\n", id, size);
+ break;
+ }
+ if(buf + ssize > buf_end){
+ av_log(avctx, AV_LOG_ERROR, "Block size %i is out of bounds\n", size);
+ break;
+ }
+ if(id & WP_IDF_IGNORE){
+ buf += ssize;
+ continue;
+ }
+ switch(id & WP_IDF_MASK){
+ case WP_ID_DECTERMS:
+ s->terms = size;
+ if(s->terms > MAX_TERMS){
+ av_log(avctx, AV_LOG_ERROR, "Too many decorrelation terms\n");
+ buf += ssize;
+ continue;
+ }
+ for(i = 0; i < s->terms; i++) {
+ s->decorr[s->terms - i - 1].value = (*buf & 0x1F) - 5;
+ s->decorr[s->terms - i - 1].delta = *buf >> 5;
+ buf++;
+ }
+ got_terms = 1;
+ break;
+ case WP_ID_DECWEIGHTS:
+ if(!got_terms){
+ av_log(avctx, AV_LOG_ERROR, "No decorrelation terms met\n");
+ continue;
+ }
+ weights = size >> s->stereo;
+ if(weights > MAX_TERMS || weights > s->terms){
+ av_log(avctx, AV_LOG_ERROR, "Too many decorrelation weights\n");
+ buf += ssize;
+ continue;
+ }
+ for(i = 0; i < weights; i++) {
+ t = (int8_t)(*buf++);
+ s->decorr[s->terms - i - 1].weightA = t << 3;
+ if(s->decorr[s->terms - i - 1].weightA > 0)
+ s->decorr[s->terms - i - 1].weightA += (s->decorr[s->terms - i - 1].weightA + 64) >> 7;
+ if(s->stereo){
+ t = (int8_t)(*buf++);
+ s->decorr[s->terms - i - 1].weightB = t << 3;
+ if(s->decorr[s->terms - i - 1].weightB > 0)
+ s->decorr[s->terms - i - 1].weightB += (s->decorr[s->terms - i - 1].weightB + 64) >> 7;
+ }
+ }
+ got_weights = 1;
+ break;
+ case WP_ID_DECSAMPLES:
+ if(!got_terms){
+ av_log(avctx, AV_LOG_ERROR, "No decorrelation terms met\n");
+ continue;
+ }
+ t = 0;
+ for(i = s->terms - 1; (i >= 0) && (t < size); i--) {
+ if(s->decorr[i].value > 8){
+ s->decorr[i].samplesA[0] = wp_exp2(AV_RL16(buf)); buf += 2;
+ s->decorr[i].samplesA[1] = wp_exp2(AV_RL16(buf)); buf += 2;
+ if(s->stereo){
+ s->decorr[i].samplesB[0] = wp_exp2(AV_RL16(buf)); buf += 2;
+ s->decorr[i].samplesB[1] = wp_exp2(AV_RL16(buf)); buf += 2;
+ t += 4;
+ }
+ t += 4;
+ }else if(s->decorr[i].value < 0){
+ s->decorr[i].samplesA[0] = wp_exp2(AV_RL16(buf)); buf += 2;
+ s->decorr[i].samplesB[0] = wp_exp2(AV_RL16(buf)); buf += 2;
+ t += 4;
+ }else{
+ for(j = 0; j < s->decorr[i].value; j++){
+ s->decorr[i].samplesA[j] = wp_exp2(AV_RL16(buf)); buf += 2;
+ if(s->stereo){
+ s->decorr[i].samplesB[j] = wp_exp2(AV_RL16(buf)); buf += 2;
+ }
+ }
+ t += s->decorr[i].value * 2 * avctx->channels;
+ }
+ }
+ got_samples = 1;
+ break;
+ case WP_ID_ENTROPY:
+ if(size != 6 * avctx->channels){
+ av_log(avctx, AV_LOG_ERROR, "Entropy vars size should be %i, got %i", 6 * avctx->channels, size);
+ buf += ssize;
+ continue;
+ }
+ for(i = 0; i < 3 * avctx->channels; i++){
+ s->median[i] = wp_exp2(AV_RL16(buf));
+ buf += 2;
+ }
+ got_entropy = 1;
+ break;
+ case WP_ID_DATA:
+ init_get_bits(&s->gb, buf, size * 8);
+ s->data_size = size * 8;
+ buf += size;
+ got_bs = 1;
+ break;
+ default:
+ buf += size;
+ }
+ 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(!got_bs){
+ av_log(avctx, AV_LOG_ERROR, "Packed samples not found\n");
+ return -1;
+ }
+
+ if(s->stereo)
+ samplecount = wv_unpack_stereo(s, &s->gb, samples);
+ else
+ samplecount = wv_unpack_mono(s, &s->gb, samples);
+ *data_size = samplecount * 2;
+
+ return buf_size;
+}
+
+AVCodec wavpack_decoder = {
+ "wavpack",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_WAVPACK,
+ sizeof(WavpackContext),
+ wavpack_decode_init,
+ NULL,
+ wavpack_decode_close,
+ wavpack_decode_frame,
+};
diff --git a/contrib/ffmpeg/libavcodec/wma.c b/contrib/ffmpeg/libavcodec/wma.c
new file mode 100644
index 000000000..2241a07a0
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/wma.c
@@ -0,0 +1,386 @@
+/*
+ * WMA compatible codec
+ * Copyright (c) 2002-2007 The FFmpeg Project.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avcodec.h"
+#include "wma.h"
+#include "wmadata.h"
+
+#undef NDEBUG
+#include <assert.h>
+
+/* 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,
+ const CoefVLCTable *vlc_table)
+{
+ int n = vlc_table->n;
+ const uint8_t *table_bits = vlc_table->huffbits;
+ const uint32_t *table_codes = vlc_table->huffcodes;
+ const uint16_t *levels_table = vlc_table->levels;
+ uint16_t *run_table, *level_table, *int_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));
+ int_table = av_malloc(n * sizeof(uint16_t));
+ i = 2;
+ level = 1;
+ k = 0;
+ while (i < n) {
+ int_table[k]= i;
+ l = levels_table[k++];
+ for(j=0;j<l;j++) {
+ run_table[i] = j;
+ level_table[i] = level;
+ i++;
+ }
+ level++;
+ }
+ *prun_table = run_table;
+ *plevel_table = level_table;
+ *pint_table= int_table;
+}
+
+int ff_wma_init(AVCodecContext * avctx, int flags2)
+{
+ WMACodecContext *s = avctx->priv_data;
+ int i;
+ float *window;
+ float bps1, high_freq;
+ volatile float bps;
+ int sample_rate1;
+ int coef_vlc_table;
+
+ s->sample_rate = avctx->sample_rate;
+ s->nb_channels = avctx->channels;
+ s->bit_rate = avctx->bit_rate;
+ s->block_align = avctx->block_align;
+
+ dsputil_init(&s->dsp, avctx);
+
+ if (avctx->codec->id == CODEC_ID_WMAV1) {
+ s->version = 1;
+ } else {
+ s->version = 2;
+ }
+
+ /* compute MDCT block size */
+ if (s->sample_rate <= 16000) {
+ s->frame_len_bits = 9;
+ } else if (s->sample_rate <= 22050 ||
+ (s->sample_rate <= 32000 && s->version == 1)) {
+ s->frame_len_bits = 10;
+ } else {
+ s->frame_len_bits = 11;
+ }
+ s->frame_len = 1 << s->frame_len_bits;
+ if (s->use_variable_block_len) {
+ int nb_max, nb;
+ nb = ((flags2 >> 3) & 3) + 1;
+ if ((s->bit_rate / s->nb_channels) >= 32000)
+ nb += 2;
+ nb_max = s->frame_len_bits - BLOCK_MIN_BITS;
+ if (nb > nb_max)
+ nb = nb_max;
+ s->nb_block_sizes = nb + 1;
+ } else {
+ s->nb_block_sizes = 1;
+ }
+
+ /* init rate dependent parameters */
+ s->use_noise_coding = 1;
+ high_freq = s->sample_rate * 0.5;
+
+ /* if version 2, then the rates are normalized */
+ sample_rate1 = s->sample_rate;
+ if (s->version == 2) {
+ if (sample_rate1 >= 44100)
+ sample_rate1 = 44100;
+ else if (sample_rate1 >= 22050)
+ sample_rate1 = 22050;
+ else if (sample_rate1 >= 16000)
+ sample_rate1 = 16000;
+ else if (sample_rate1 >= 11025)
+ sample_rate1 = 11025;
+ else if (sample_rate1 >= 8000)
+ sample_rate1 = 8000;
+ }
+
+ bps = (float)s->bit_rate / (float)(s->nb_channels * s->sample_rate);
+ s->byte_offset_bits = av_log2((int)(bps * s->frame_len / 8.0 + 0.5)) + 2;
+
+ /* compute high frequency value and choose if noise coding should
+ be activated */
+ bps1 = bps;
+ if (s->nb_channels == 2)
+ bps1 = bps * 1.6;
+ if (sample_rate1 == 44100) {
+ if (bps1 >= 0.61)
+ s->use_noise_coding = 0;
+ else
+ high_freq = high_freq * 0.4;
+ } else if (sample_rate1 == 22050) {
+ if (bps1 >= 1.16)
+ s->use_noise_coding = 0;
+ else if (bps1 >= 0.72)
+ high_freq = high_freq * 0.7;
+ else
+ high_freq = high_freq * 0.6;
+ } else if (sample_rate1 == 16000) {
+ if (bps > 0.5)
+ high_freq = high_freq * 0.5;
+ else
+ high_freq = high_freq * 0.3;
+ } else if (sample_rate1 == 11025) {
+ high_freq = high_freq * 0.7;
+ } else if (sample_rate1 == 8000) {
+ if (bps <= 0.625) {
+ high_freq = high_freq * 0.5;
+ } else if (bps > 0.75) {
+ s->use_noise_coding = 0;
+ } else {
+ high_freq = high_freq * 0.65;
+ }
+ } else {
+ if (bps >= 0.8) {
+ high_freq = high_freq * 0.75;
+ } else if (bps >= 0.6) {
+ high_freq = high_freq * 0.6;
+ } else {
+ high_freq = high_freq * 0.5;
+ }
+ }
+ dprintf(s->avctx, "flags2=0x%x\n", flags2);
+ dprintf(s->avctx, "version=%d channels=%d sample_rate=%d bitrate=%d block_align=%d\n",
+ s->version, s->nb_channels, s->sample_rate, s->bit_rate,
+ s->block_align);
+ dprintf(s->avctx, "bps=%f bps1=%f high_freq=%f bitoffset=%d\n",
+ bps, bps1, high_freq, s->byte_offset_bits);
+ dprintf(s->avctx, "use_noise_coding=%d use_exp_vlc=%d nb_block_sizes=%d\n",
+ s->use_noise_coding, s->use_exp_vlc, s->nb_block_sizes);
+
+ /* compute the scale factor band sizes for each MDCT block size */
+ {
+ int a, b, pos, lpos, k, block_len, i, j, n;
+ const uint8_t *table;
+
+ if (s->version == 1) {
+ s->coefs_start = 3;
+ } else {
+ s->coefs_start = 0;
+ }
+ for(k = 0; k < s->nb_block_sizes; k++) {
+ block_len = s->frame_len >> k;
+
+ if (s->version == 1) {
+ lpos = 0;
+ for(i=0;i<25;i++) {
+ a = wma_critical_freqs[i];
+ b = s->sample_rate;
+ pos = ((block_len * 2 * a) + (b >> 1)) / b;
+ if (pos > block_len)
+ pos = block_len;
+ s->exponent_bands[0][i] = pos - lpos;
+ if (pos >= block_len) {
+ i++;
+ break;
+ }
+ lpos = pos;
+ }
+ s->exponent_sizes[0] = i;
+ } else {
+ /* hardcoded tables */
+ table = NULL;
+ a = s->frame_len_bits - BLOCK_MIN_BITS - k;
+ if (a < 3) {
+ if (s->sample_rate >= 44100)
+ table = exponent_band_44100[a];
+ else if (s->sample_rate >= 32000)
+ table = exponent_band_32000[a];
+ else if (s->sample_rate >= 22050)
+ table = exponent_band_22050[a];
+ }
+ if (table) {
+ n = *table++;
+ for(i=0;i<n;i++)
+ s->exponent_bands[k][i] = table[i];
+ s->exponent_sizes[k] = n;
+ } else {
+ j = 0;
+ lpos = 0;
+ for(i=0;i<25;i++) {
+ a = wma_critical_freqs[i];
+ b = s->sample_rate;
+ pos = ((block_len * 2 * a) + (b << 1)) / (4 * b);
+ pos <<= 2;
+ if (pos > block_len)
+ pos = block_len;
+ if (pos > lpos)
+ s->exponent_bands[k][j++] = pos - lpos;
+ if (pos >= block_len)
+ break;
+ lpos = pos;
+ }
+ s->exponent_sizes[k] = j;
+ }
+ }
+
+ /* max number of coefs */
+ s->coefs_end[k] = (s->frame_len - ((s->frame_len * 9) / 100)) >> k;
+ /* high freq computation */
+ s->high_band_start[k] = (int)((block_len * 2 * high_freq) /
+ s->sample_rate + 0.5);
+ n = s->exponent_sizes[k];
+ j = 0;
+ pos = 0;
+ for(i=0;i<n;i++) {
+ int start, end;
+ start = pos;
+ pos += s->exponent_bands[k][i];
+ end = pos;
+ if (start < s->high_band_start[k])
+ start = s->high_band_start[k];
+ if (end > s->coefs_end[k])
+ end = s->coefs_end[k];
+ if (end > start)
+ s->exponent_high_bands[k][j++] = end - start;
+ }
+ s->exponent_high_sizes[k] = j;
+#if 0
+ tprintf(s->avctx, "%5d: coefs_end=%d high_band_start=%d nb_high_bands=%d: ",
+ s->frame_len >> k,
+ s->coefs_end[k],
+ s->high_band_start[k],
+ s->exponent_high_sizes[k]);
+ for(j=0;j<s->exponent_high_sizes[k];j++)
+ tprintf(s->avctx, " %d", s->exponent_high_bands[k][j]);
+ tprintf(s->avctx, "\n");
+#endif
+ }
+ }
+
+#ifdef TRACE
+ {
+ int i, j;
+ for(i = 0; i < s->nb_block_sizes; i++) {
+ tprintf(s->avctx, "%5d: n=%2d:",
+ s->frame_len >> i,
+ s->exponent_sizes[i]);
+ for(j=0;j<s->exponent_sizes[i];j++)
+ tprintf(s->avctx, " %d", s->exponent_bands[i][j]);
+ tprintf(s->avctx, "\n");
+ }
+ }
+#endif
+
+ /* init MDCT windows : simple sinus window */
+ for(i = 0; i < s->nb_block_sizes; i++) {
+ int n, j;
+ float alpha;
+ n = 1 << (s->frame_len_bits - i);
+ window = av_malloc(sizeof(float) * n);
+ alpha = M_PI / (2.0 * n);
+ for(j=0;j<n;j++) {
+ window[j] = sin((j + 0.5) * alpha);
+ }
+ s->windows[i] = window;
+ }
+
+ s->reset_block_lengths = 1;
+
+ if (s->use_noise_coding) {
+
+ /* init the noise generator */
+ if (s->use_exp_vlc)
+ s->noise_mult = 0.02;
+ else
+ s->noise_mult = 0.04;
+
+#ifdef TRACE
+ for(i=0;i<NOISE_TAB_SIZE;i++)
+ s->noise_table[i] = 1.0 * s->noise_mult;
+#else
+ {
+ unsigned int seed;
+ float norm;
+ seed = 1;
+ norm = (1.0 / (float)(1LL << 31)) * sqrt(3) * s->noise_mult;
+ for(i=0;i<NOISE_TAB_SIZE;i++) {
+ seed = seed * 314159 + 1;
+ s->noise_table[i] = (float)((int)seed) * norm;
+ }
+ }
+#endif
+ }
+
+ /* choose the VLC tables for the coefficients */
+ coef_vlc_table = 2;
+ if (s->sample_rate >= 32000) {
+ if (bps1 < 0.72)
+ coef_vlc_table = 0;
+ else if (bps1 < 1.16)
+ coef_vlc_table = 1;
+ }
+ s->coef_vlcs[0]= &coef_vlcs[coef_vlc_table * 2 ];
+ s->coef_vlcs[1]= &coef_vlcs[coef_vlc_table * 2 + 1];
+ init_coef_vlc(&s->coef_vlc[0], &s->run_table[0], &s->level_table[0], &s->int_table[0],
+ s->coef_vlcs[0]);
+ init_coef_vlc(&s->coef_vlc[1], &s->run_table[1], &s->level_table[1], &s->int_table[1],
+ s->coef_vlcs[1]);
+
+ return 0;
+}
+
+int ff_wma_total_gain_to_bits(int total_gain){
+ if (total_gain < 15) return 13;
+ else if (total_gain < 32) return 12;
+ else if (total_gain < 40) return 11;
+ else if (total_gain < 45) return 10;
+ else return 9;
+}
+
+int ff_wma_end(AVCodecContext *avctx)
+{
+ WMACodecContext *s = avctx->priv_data;
+ int i;
+
+ for(i = 0; i < s->nb_block_sizes; i++)
+ ff_mdct_end(&s->mdct_ctx[i]);
+ for(i = 0; i < s->nb_block_sizes; i++)
+ av_free(s->windows[i]);
+
+ if (s->use_exp_vlc) {
+ free_vlc(&s->exp_vlc);
+ }
+ if (s->use_noise_coding) {
+ free_vlc(&s->hgain_vlc);
+ }
+ for(i = 0;i < 2; i++) {
+ free_vlc(&s->coef_vlc[i]);
+ av_free(s->run_table[i]);
+ av_free(s->level_table[i]);
+ }
+
+ return 0;
+}
diff --git a/contrib/ffmpeg/libavcodec/wma.h b/contrib/ffmpeg/libavcodec/wma.h
new file mode 100644
index 000000000..cd4daa7e5
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/wma.h
@@ -0,0 +1,149 @@
+/*
+ * WMA compatible codec
+ * Copyright (c) 2002-2007 The FFmpeg Project.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef WMA_H
+#define WMA_H
+
+#include "bitstream.h"
+#include "dsputil.h"
+
+/* size of blocks */
+#define BLOCK_MIN_BITS 7
+#define BLOCK_MAX_BITS 11
+#define BLOCK_MAX_SIZE (1 << BLOCK_MAX_BITS)
+
+#define BLOCK_NB_SIZES (BLOCK_MAX_BITS - BLOCK_MIN_BITS + 1)
+
+/* XXX: find exact max size */
+#define HIGH_BAND_MAX_SIZE 16
+
+#define NB_LSP_COEFS 10
+
+/* XXX: is it a suitable value ? */
+#define MAX_CODED_SUPERFRAME_SIZE 16384
+
+#define MAX_CHANNELS 2
+
+#define NOISE_TAB_SIZE 8192
+
+#define LSP_POW_BITS 7
+
+//FIXME should be in wmadec
+#define VLCBITS 9
+#define VLCMAX ((22+VLCBITS-1)/VLCBITS)
+
+typedef struct CoefVLCTable {
+ int n; ///< total number of codes
+ int max_level;
+ const uint32_t *huffcodes; ///< VLC bit values
+ const uint8_t *huffbits; ///< VLC bit size
+ const uint16_t *levels; ///< table to build run/level tables
+} CoefVLCTable;
+
+typedef struct WMACodecContext {
+ AVCodecContext* avctx;
+ GetBitContext gb;
+ PutBitContext pb;
+ int sample_rate;
+ int nb_channels;
+ int bit_rate;
+ int version; ///< 1 = 0x160 (WMAV1), 2 = 0x161 (WMAV2)
+ int block_align;
+ int use_bit_reservoir;
+ int use_variable_block_len;
+ int use_exp_vlc; ///< exponent coding: 0 = lsp, 1 = vlc + delta
+ int use_noise_coding; ///< true if perceptual noise is added
+ int byte_offset_bits;
+ VLC exp_vlc;
+ int exponent_sizes[BLOCK_NB_SIZES];
+ uint16_t exponent_bands[BLOCK_NB_SIZES][25];
+ int high_band_start[BLOCK_NB_SIZES]; ///< index of first coef in high band
+ int coefs_start; ///< first coded coef
+ int coefs_end[BLOCK_NB_SIZES]; ///< max number of coded coefficients
+ int exponent_high_sizes[BLOCK_NB_SIZES];
+ int exponent_high_bands[BLOCK_NB_SIZES][HIGH_BAND_MAX_SIZE];
+ VLC hgain_vlc;
+
+ /* coded values in high bands */
+ int high_band_coded[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
+ int high_band_values[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
+
+ /* there are two possible tables for spectral coefficients */
+//FIXME the following 3 tables should be shared between decoders
+ VLC coef_vlc[2];
+ uint16_t *run_table[2];
+ uint16_t *level_table[2];
+ uint16_t *int_table[2];
+ CoefVLCTable *coef_vlcs[2];
+ /* frame info */
+ int frame_len; ///< frame length in samples
+ int frame_len_bits; ///< frame_len = 1 << frame_len_bits
+ int nb_block_sizes; ///< number of block sizes
+ /* block info */
+ int reset_block_lengths;
+ int block_len_bits; ///< log2 of current block length
+ int next_block_len_bits; ///< log2 of next block length
+ int prev_block_len_bits; ///< log2 of prev block length
+ int block_len; ///< block length in samples
+ int block_num; ///< block number in current frame
+ int block_pos; ///< current position in frame
+ uint8_t ms_stereo; ///< true if mid/side stereo mode
+ uint8_t channel_coded[MAX_CHANNELS]; ///< true if channel is coded
+ DECLARE_ALIGNED_16(float, exponents[MAX_CHANNELS][BLOCK_MAX_SIZE]);
+ float max_exponent[MAX_CHANNELS];
+ int16_t 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];
+ float *windows[BLOCK_NB_SIZES];
+ DECLARE_ALIGNED_16(FFTSample, mdct_tmp[BLOCK_MAX_SIZE]); ///< temporary storage for imdct
+ /* output buffer for one frame and the last for IMDCT windowing */
+ 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;
+ int last_superframe_len;
+ float noise_table[NOISE_TAB_SIZE];
+ int noise_index;
+ float noise_mult; /* XXX: suppress that and integrate it in the noise array */
+ /* lsp_to_curve tables */
+ float lsp_cos_table[BLOCK_MAX_SIZE];
+ float lsp_pow_e_table[256];
+ float lsp_pow_m_table1[(1 << LSP_POW_BITS)];
+ float lsp_pow_m_table2[(1 << LSP_POW_BITS)];
+ DSPContext dsp;
+
+#ifdef TRACE
+ int frame_count;
+#endif
+} WMACodecContext;
+
+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];
+
+int ff_wma_init(AVCodecContext * avctx, int flags2);
+int ff_wma_total_gain_to_bits(int total_gain);
+int ff_wma_end(AVCodecContext *avctx);
+
+#endif
diff --git a/contrib/ffmpeg/libavcodec/wmadata.h b/contrib/ffmpeg/libavcodec/wmadata.h
new file mode 100644
index 000000000..31ed89bf0
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/wmadata.h
@@ -0,0 +1,1433 @@
+/*
+ * WMA compatible decoder
+ * copyright (c) 2002 The FFmpeg Project
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file wmadata.h
+ * Various WMA tables.
+ */
+
+static const uint16_t 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,
+ 24500,
+};
+
+/* first value is number of bands */
+static const uint8_t exponent_band_22050[3][25] = {
+ { 10, 4, 8, 4, 8, 8, 12, 20, 24, 24, 16, },
+ { 14, 4, 8, 8, 4, 12, 12, 16, 24, 16, 20, 24, 32, 40, 36, },
+ { 23, 4, 4, 4, 8, 4, 4, 8, 8, 8, 8, 8, 12, 12, 16, 16, 24, 24, 32, 44, 48, 60, 84, 72, },
+};
+
+static const uint8_t exponent_band_32000[3][25] = {
+ { 11, 4, 4, 8, 4, 4, 12, 16, 24, 20, 28, 4, },
+ { 15, 4, 8, 4, 4, 8, 8, 16, 20, 12, 20, 20, 28, 40, 56, 8, },
+ { 16, 8, 4, 8, 8, 12, 16, 20, 24, 40, 32, 32, 44, 56, 80, 112, 16, },
+};
+
+static const uint8_t exponent_band_44100[3][25] = {
+ { 12, 4, 4, 4, 4, 4, 8, 8, 8, 12, 16, 20, 36, },
+ { 15, 4, 8, 4, 8, 8, 4, 8, 8, 12, 12, 12, 24, 28, 40, 76, },
+ { 17, 4, 8, 8, 4, 12, 12, 8, 8, 24, 16, 20, 24, 32, 40, 60, 80, 152, },
+};
+
+const uint16_t ff_wma_hgain_huffcodes[37] = {
+ 0x00003, 0x002e7, 0x00001, 0x005cd, 0x0005d, 0x005c9, 0x0005e, 0x00003,
+ 0x00016, 0x0000b, 0x00001, 0x00006, 0x00001, 0x00006, 0x00004, 0x00005,
+ 0x00004, 0x00007, 0x00003, 0x00007, 0x00004, 0x0000a, 0x0000a, 0x00002,
+ 0x00003, 0x00000, 0x00005, 0x00002, 0x0005f, 0x00004, 0x00003, 0x00002,
+ 0x005c8, 0x000b8, 0x005ca, 0x005cb, 0x005cc,
+};
+
+const uint8_t ff_wma_hgain_huffbits[37] = {
+ 10, 12, 10, 13, 9, 13, 9, 8,
+ 7, 5, 5, 4, 4, 3, 3, 3,
+ 4, 3, 4, 4, 5, 5, 6, 8,
+ 7, 10, 8, 10, 9, 8, 9, 9,
+ 13, 10, 13, 13, 13,
+};
+
+const float ff_wma_lsp_codebook[NB_LSP_COEFS][16] = {
+ { 1.98732877, 1.97944528, 1.97179088, 1.96260549, 1.95038374, 1.93336114, 1.90719232, 1.86191415, },
+ { 1.97260000, 1.96083160, 1.94982586, 1.93806164, 1.92516608, 1.91010199, 1.89232331, 1.87149812,
+ 1.84564818, 1.81358067, 1.77620070, 1.73265264, 1.67907855, 1.60959081, 1.50829650, 1.33120330, },
+ { 1.90109110, 1.86482426, 1.83419671, 1.80168452, 1.76650116, 1.72816320, 1.68502700, 1.63738256,
+ 1.58501580, 1.51795181, 1.43679906, 1.33950585, 1.24176208, 1.12260729, 0.96749668, 0.74048265, },
+ { 1.76943864, 1.67822463, 1.59946365, 1.53560582, 1.47470796, 1.41210167, 1.34509536, 1.27339507,
+ 1.19303814, 1.09765169, 0.98818722, 0.87239446, 0.74369172, 0.59768184, 0.43168630, 0.17977021, },
+ { 1.43428349, 1.32038354, 1.21074086, 1.10577988, 1.00561746, 0.90335924, 0.80437489, 0.70709671,
+ 0.60427395, 0.49814048, 0.38509539, 0.27106800, 0.14407416, 0.00219910, -0.16725141, -0.36936085, },
+ { 0.99895687, 0.84188166, 0.70753739, 0.57906595, 0.47055563, 0.36966965, 0.26826648, 0.17163380,
+ 0.07208392, -0.03062936, -1.40037388, -0.25128968, -0.37213937, -0.51075646, -0.64887512, -0.80308031, },
+ { 0.26515280, 0.06313551, -0.08872080, -0.21103548, -0.31069678, -0.39680323, -0.47223474, -0.54167135,
+ -0.61444740, -0.68943343, -0.76580211, -0.85170082, -0.95289061, -1.06514703, -1.20510707, -1.37617746, },
+ { -0.53940301, -0.73770929, -0.88424876, -1.01117930, -1.13389091, -1.26830073, -1.42041987, -1.62033919,
+ -1.10158808, -1.16512566, -1.23337128, -1.30414401, -1.37663312, -1.46853845, -1.57625798, -1.66893638, },
+ { -0.38601997, -0.56009350, -0.66978483, -0.76028471, -0.83846064, -0.90868087, -0.97408881, -1.03694962, },
+ { -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,
+ 0x0004a, 0x0004d, 0x00061, 0x00070, 0x00073, 0x00048, 0x00052, 0x0005a,
+ 0x0005d, 0x0006e, 0x00099, 0x0009e, 0x000c1, 0x000ce, 0x000e4, 0x000f0,
+ 0x00093, 0x0009e, 0x000a2, 0x000a1, 0x000b8, 0x000d2, 0x000d3, 0x0012e,
+ 0x00130, 0x000de, 0x0012d, 0x0019b, 0x001e4, 0x00139, 0x0013a, 0x0013f,
+ 0x0014f, 0x0016d, 0x001a2, 0x0027c, 0x0027e, 0x00332, 0x0033c, 0x0033f,
+ 0x0038b, 0x00396, 0x003c5, 0x00270, 0x0027c, 0x0025a, 0x00395, 0x00248,
+ 0x004bd, 0x004fb, 0x00662, 0x00661, 0x0071b, 0x004e6, 0x004ff, 0x00666,
+ 0x0071c, 0x0071a, 0x0071f, 0x00794, 0x00536, 0x004e2, 0x0078e, 0x004ee,
+ 0x00518, 0x00535, 0x004fb, 0x0078d, 0x00530, 0x00680, 0x0068f, 0x005cb,
+ 0x00965, 0x006a6, 0x00967, 0x0097f, 0x00682, 0x006ae, 0x00cd0, 0x00e28,
+ 0x00f13, 0x00f1f, 0x009f5, 0x00cd3, 0x00f11, 0x00926, 0x00964, 0x00f32,
+ 0x00f12, 0x00f30, 0x00966, 0x00d0b, 0x00a68, 0x00b91, 0x009c7, 0x00b73,
+ 0x012fa, 0x0131d, 0x013f9, 0x01ca0, 0x0199c, 0x01c7a, 0x0198c, 0x01248,
+ 0x01c74, 0x01c64, 0x0139e, 0x012fd, 0x00a77, 0x012fc, 0x01c7b, 0x012ca,
+ 0x014cc, 0x014d2, 0x014e3, 0x014dc, 0x012dc, 0x03344, 0x02598, 0x0263c,
+ 0x0333b, 0x025e6, 0x01a1c, 0x01e3c, 0x014e2, 0x033d4, 0x01a11, 0x03349,
+ 0x03cce, 0x014e1, 0x01a34, 0x0273e, 0x02627, 0x0273f, 0x038ee, 0x03971,
+ 0x03c67, 0x03c61, 0x0333d, 0x038c2, 0x0263f, 0x038cd, 0x02638, 0x02e41,
+ 0x0351f, 0x03348, 0x03c66, 0x03562, 0x02989, 0x027d5, 0x0333c, 0x02e4f,
+ 0x0343b, 0x02ddf, 0x04bc8, 0x029c0, 0x02e57, 0x04c72, 0x025b7, 0x03547,
+ 0x03540, 0x029d3, 0x04c45, 0x025bb, 0x06600, 0x04c73, 0x04bce, 0x0357b,
+ 0x029a6, 0x029d2, 0x0263e, 0x0298a, 0x07183, 0x06602, 0x07958, 0x04b66,
+ 0x0537d, 0x05375, 0x04fe9, 0x04b67, 0x0799f, 0x04bc9, 0x051fe, 0x06a3b,
+ 0x05bb6, 0x04fa8, 0x0728f, 0x05376, 0x0492c, 0x0537e, 0x0795a, 0x06a3c,
+ 0x0e515, 0x07887, 0x0683a, 0x051f9, 0x051fd, 0x0cc6a, 0x06a8a, 0x0cc6d,
+ 0x05bb3, 0x0683b, 0x051fc, 0x05378, 0x0728e, 0x07886, 0x05bb7, 0x0f2a4,
+ 0x0795b, 0x0683c, 0x09fc1, 0x0683d, 0x0b752, 0x09678, 0x0a3e8, 0x06ac7,
+ 0x051f0, 0x0b759, 0x06af3, 0x04b6b, 0x0f2a0, 0x0f2ad, 0x096c3, 0x0e518,
+ 0x0b75c, 0x0d458, 0x0cc6b, 0x0537c, 0x067aa, 0x04fea, 0x0343a, 0x0cc71,
+ 0x0967f, 0x09fc4, 0x096c2, 0x0e516, 0x0f2a1, 0x0d45c, 0x0d45d, 0x0d45e,
+ 0x12fb9, 0x0967e, 0x1982f, 0x09883, 0x096c4, 0x0b753, 0x12fb8, 0x0f2a8,
+ 0x1ca21, 0x096c5, 0x0e51a, 0x1ca27, 0x12f3c, 0x0d471, 0x0f2aa, 0x0b75b,
+ 0x12fbb, 0x0f2a9, 0x0f2ac, 0x0d45a, 0x0b74f, 0x096c8, 0x16e91, 0x096ca,
+ 0x12fbf, 0x0d0a7, 0x13103, 0x0d516, 0x16e99, 0x12cbd, 0x0a3ea, 0x19829,
+ 0x0b755, 0x29ba7, 0x1ca28, 0x29ba5, 0x16e93, 0x1982c, 0x19828, 0x25994,
+ 0x0a3eb, 0x1ca29, 0x16e90, 0x1ca25, 0x1982d, 0x1ca26, 0x16e9b, 0x0b756,
+ 0x0967c, 0x25997, 0x0b75f, 0x198d3, 0x0b757, 0x19a2a, 0x0d45b, 0x0e517,
+ 0x1ca24, 0x1ca23, 0x1ca22, 0x0b758, 0x16e97, 0x0cd14, 0x13100, 0x00007,
+ 0x0003b, 0x0006b, 0x00097, 0x00138, 0x00125, 0x00173, 0x00258, 0x00335,
+ 0x0028e, 0x004c6, 0x00715, 0x00729, 0x004ef, 0x00519, 0x004ed, 0x00532,
+ 0x0068c, 0x00686, 0x00978, 0x00e5d, 0x00e31, 0x009f4, 0x00b92, 0x012f8,
+ 0x00d06, 0x00a67, 0x00d44, 0x00a76, 0x00d59, 0x012cd, 0x01c78, 0x01c75,
+ 0x0199f, 0x0198f, 0x01c67, 0x014c6, 0x01c79, 0x01c76, 0x00b94, 0x00d1b,
+ 0x01e32, 0x01e31, 0x01ab0, 0x01a05, 0x01aa1, 0x0333a, 0x025e5, 0x02626,
+ 0x03541, 0x03544, 0x03421, 0x03546, 0x02e55, 0x02e56, 0x0492d, 0x02dde,
+ 0x0299b, 0x02ddc, 0x0357a, 0x0249c, 0x0668b, 0x1c77f, 0x1ca20, 0x0d45f,
+ 0x09886, 0x16e9a, 0x0f2a7, 0x0b751, 0x0a3ee, 0x0cf59, 0x0cf57, 0x0b754,
+ 0x0d0a6, 0x16e98, 0x0b760, 0x06ac6, 0x0a3f0, 0x12fbe, 0x13104, 0x0f2a5,
+ 0x0a3ef, 0x0d472, 0x12cba, 0x1982e, 0x16e9c, 0x1c77e, 0x198d0, 0x13105,
+ 0x16e92, 0x0b75d, 0x0d459, 0x0001a, 0x000c0, 0x0016c, 0x003cd, 0x00350,
+ 0x0067b, 0x0051e, 0x006a9, 0x009f4, 0x00b72, 0x00d09, 0x01249, 0x01e3d,
+ 0x01ca1, 0x01a1f, 0x01721, 0x01a8a, 0x016e8, 0x03347, 0x01a35, 0x0249d,
+ 0x0299a, 0x02596, 0x02e4e, 0x0298b, 0x07182, 0x04c46, 0x025ba, 0x02e40,
+ 0x027d6, 0x04fe8, 0x06607, 0x05310, 0x09884, 0x072e1, 0x06a3d, 0x04b6a,
+ 0x04c7a, 0x06603, 0x04c7b, 0x03428, 0x06605, 0x09664, 0x09fc0, 0x071de,
+ 0x06601, 0x05bb2, 0x09885, 0x0a3e2, 0x1c61f, 0x12cbb, 0x0b750, 0x0cf58,
+ 0x0967d, 0x25995, 0x668ad, 0x0b75a, 0x09fc2, 0x0537f, 0x0b75e, 0x13fae,
+ 0x12fbc, 0x00031, 0x001c4, 0x004c5, 0x005b8, 0x00cf4, 0x0096f, 0x00d46,
+ 0x01e57, 0x01a04, 0x02625, 0x03346, 0x028f9, 0x04c47, 0x072e0, 0x04b69,
+ 0x03420, 0x07957, 0x06639, 0x0799e, 0x07959, 0x07881, 0x04b68, 0x09fc3,
+ 0x09fd6, 0x0cc70, 0x0a3f1, 0x12cbe, 0x0e30e, 0x0e51b, 0x06af2, 0x12cbc,
+ 0x1c77d, 0x0f2ab, 0x12fbd, 0x1aa2f, 0x0a3ec, 0x0d473, 0x05377, 0x0a3e9,
+ 0x1982b, 0x0e300, 0x12f3f, 0x0cf5f, 0x096c0, 0x38c3c, 0x16e94, 0x16e95,
+ 0x12f3d, 0x29ba4, 0x29ba6, 0x1c77c, 0x6a8ba, 0x3545c, 0x33457, 0x668ac,
+ 0x6a8bb, 0x16e9d, 0x0e519, 0x25996, 0x12f3e, 0x00036, 0x0033e, 0x006ad,
+ 0x00d03, 0x012c8, 0x0124a, 0x03c42, 0x03ccd, 0x06606, 0x07880, 0x06852,
+ 0x06a3a, 0x05bb4, 0x0f2a2, 0x09fc7, 0x12cb9, 0x0cc6c, 0x0a6e8, 0x096c1,
+ 0x0004a, 0x00355, 0x012f9, 0x014e8, 0x01abe, 0x025b6, 0x0492e, 0x09fc6,
+ 0x051ff, 0x0cc6f, 0x096cb, 0x0d071, 0x198d1, 0x12cb8, 0x38c3d, 0x13faf,
+ 0x096c9, 0x0009d, 0x00539, 0x012ce, 0x0341f, 0x029c1, 0x04b33, 0x0a3e3,
+ 0x0d070, 0x16e96, 0x0b763, 0x000a0, 0x009ce, 0x038cc, 0x0343d, 0x051fa,
+ 0x09888, 0x12fba, 0x000df, 0x00a75, 0x029a7, 0x09fc5, 0x0e301, 0x0967b,
+ 0x001e7, 0x012c9, 0x051fb, 0x09889, 0x0f2a6, 0x0016f, 0x01cb9, 0x0cf5a,
+ 0x12cbf, 0x09679, 0x00272, 0x01a15, 0x0967a, 0x003cb, 0x025f6, 0x0b762,
+ 0x0028d, 0x03c60, 0x0cf5e, 0x00352, 0x03ccc, 0x0072f, 0x07186, 0x004ec,
+ 0x05379, 0x0068e, 0x09887, 0x006a7, 0x06af1, 0x00e29, 0x0cf5b, 0x00f31,
+ 0x0d470, 0x009c6, 0x013fb, 0x13102, 0x019a5, 0x13101, 0x01983, 0x01c65,
+ 0x0124f, 0x014c7, 0x01726, 0x01abf, 0x03304, 0x02624, 0x03c41, 0x027d7,
+ 0x02ddd, 0x02e54, 0x0343c, 0x06604, 0x07181, 0x0663a, 0x04fa9, 0x0663b,
+ 0x05311, 0x0537a, 0x06839, 0x05bb5, 0x0492f, 0x06af0, 0x096c7, 0x0cc6e,
+ 0x0537b, 0x0cf5c, 0x0cf56, 0x198d2, 0x0cf5d, 0x0a3ed, 0x0f2a3, 0x1982a,
+ 0x0b761, 0x096c6,
+};
+
+static const uint8_t coef0_huffbits[666] = {
+ 11, 6, 2, 3, 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,
+ 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 11, 11, 11, 10, 11,
+ 11, 11, 11, 11, 11, 11, 11, 11,
+ 11, 11, 11, 11, 12, 12, 11, 12,
+ 12, 12, 12, 11, 12, 12, 12, 12,
+ 12, 12, 12, 12, 12, 12, 12, 12,
+ 12, 12, 12, 12, 12, 13, 13, 12,
+ 12, 12, 13, 13, 13, 13, 13, 13,
+ 13, 13, 13, 13, 13, 13, 13, 14,
+ 13, 13, 13, 13, 13, 13, 13, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 13, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 15,
+ 15, 14, 14, 15, 15, 15, 14, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 14, 15, 15, 15, 15, 16,
+ 16, 16, 15, 16, 15, 15, 16, 16,
+ 16, 16, 15, 16, 16, 16, 15, 16,
+ 16, 15, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 15, 15, 16, 16,
+ 15, 16, 16, 16, 17, 17, 17, 16,
+ 16, 17, 16, 16, 16, 16, 17, 16,
+ 17, 17, 16, 16, 15, 15, 15, 16,
+ 17, 16, 17, 16, 16, 17, 17, 17,
+ 17, 17, 17, 16, 17, 17, 17, 16,
+ 17, 17, 16, 17, 17, 17, 16, 17,
+ 17, 16, 16, 17, 17, 17, 18, 17,
+ 17, 17, 17, 17, 18, 18, 17, 17,
+ 17, 19, 17, 19, 18, 17, 17, 18,
+ 17, 17, 18, 17, 17, 17, 18, 17,
+ 17, 18, 17, 17, 17, 17, 17, 16,
+ 17, 17, 17, 17, 18, 16, 17, 4,
+ 6, 8, 9, 9, 10, 10, 10, 10,
+ 11, 11, 11, 11, 12, 12, 12, 12,
+ 12, 12, 12, 12, 12, 13, 13, 13,
+ 13, 13, 13, 13, 13, 13, 13, 13,
+ 13, 13, 13, 14, 13, 13, 13, 13,
+ 13, 13, 14, 14, 14, 14, 14, 14,
+ 15, 15, 15, 15, 15, 15, 16, 15,
+ 15, 15, 15, 15, 15, 17, 17, 17,
+ 16, 18, 16, 17, 17, 16, 16, 17,
+ 17, 18, 17, 16, 17, 17, 17, 16,
+ 17, 17, 18, 17, 18, 17, 17, 17,
+ 18, 17, 17, 5, 8, 10, 10, 11,
+ 11, 12, 12, 12, 13, 13, 14, 13,
+ 13, 14, 14, 14, 14, 14, 14, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 16, 16, 15, 16, 16,
+ 15, 15, 15, 15, 15, 16, 16, 15,
+ 15, 16, 16, 17, 17, 18, 17, 16,
+ 17, 18, 19, 17, 16, 16, 17, 17,
+ 17, 6, 9, 11, 12, 12, 13, 13,
+ 13, 14, 14, 14, 15, 15, 15, 16,
+ 15, 15, 15, 15, 15, 15, 16, 16,
+ 16, 16, 17, 18, 16, 16, 16, 18,
+ 17, 16, 17, 18, 17, 17, 16, 17,
+ 17, 16, 17, 16, 17, 18, 18, 18,
+ 17, 19, 19, 17, 20, 19, 18, 19,
+ 20, 18, 16, 18, 17, 7, 10, 12,
+ 13, 13, 14, 14, 14, 15, 15, 16,
+ 16, 16, 16, 16, 18, 16, 17, 17,
+ 8, 11, 13, 14, 14, 15, 16, 16,
+ 16, 16, 17, 17, 17, 18, 18, 17,
+ 17, 8, 12, 14, 15, 15, 15, 17,
+ 17, 18, 17, 9, 12, 14, 15, 16,
+ 16, 17, 9, 13, 15, 16, 16, 17,
+ 9, 13, 16, 16, 16, 10, 13, 16,
+ 18, 17, 10, 14, 17, 10, 14, 17,
+ 11, 14, 16, 11, 14, 11, 15, 12,
+ 16, 12, 16, 12, 16, 12, 16, 12,
+ 17, 13, 13, 17, 13, 17, 13, 13,
+ 14, 14, 14, 14, 14, 14, 14, 15,
+ 15, 15, 15, 15, 15, 15, 16, 15,
+ 16, 16, 16, 16, 16, 16, 17, 16,
+ 16, 16, 16, 17, 16, 17, 16, 17,
+ 17, 17,
+};
+
+static const uint32_t coef1_huffcodes[555] = {
+ 0x00115, 0x00002, 0x00001, 0x00000, 0x0000d, 0x00007, 0x00013, 0x0001d,
+ 0x00008, 0x0000c, 0x00023, 0x0002b, 0x0003f, 0x00017, 0x0001b, 0x00043,
+ 0x00049, 0x00050, 0x00055, 0x00054, 0x00067, 0x00064, 0x0007b, 0x0002d,
+ 0x00028, 0x0002a, 0x00085, 0x00089, 0x0002b, 0x00035, 0x00090, 0x00091,
+ 0x00094, 0x00088, 0x000c1, 0x000c6, 0x000f2, 0x000e3, 0x000c5, 0x000e2,
+ 0x00036, 0x000f0, 0x000a7, 0x000cd, 0x000fb, 0x00059, 0x00116, 0x00103,
+ 0x00108, 0x0012b, 0x0012d, 0x00188, 0x0012e, 0x0014c, 0x001c3, 0x00187,
+ 0x001e7, 0x0006f, 0x00094, 0x00069, 0x001e6, 0x001ca, 0x00147, 0x00195,
+ 0x000a7, 0x00213, 0x00209, 0x00303, 0x00295, 0x00289, 0x0028c, 0x0028d,
+ 0x00312, 0x00330, 0x0029b, 0x00308, 0x00328, 0x0029a, 0x0025e, 0x003c5,
+ 0x00384, 0x0039f, 0x00397, 0x00296, 0x0032e, 0x00332, 0x003c6, 0x003e6,
+ 0x0012d, 0x000d1, 0x00402, 0x000dd, 0x00161, 0x0012b, 0x00127, 0x0045d,
+ 0x00601, 0x004ab, 0x0045f, 0x00410, 0x004bf, 0x00528, 0x0045c, 0x00424,
+ 0x00400, 0x00511, 0x00618, 0x0073d, 0x0063a, 0x00614, 0x0073c, 0x007c0,
+ 0x007cf, 0x00802, 0x00966, 0x00964, 0x00951, 0x008a0, 0x00346, 0x00803,
+ 0x00a52, 0x0024a, 0x007c1, 0x0063f, 0x00126, 0x00406, 0x00789, 0x008a2,
+ 0x00960, 0x00967, 0x00c05, 0x00c70, 0x00c79, 0x00a5d, 0x00c26, 0x00c4d,
+ 0x00372, 0x008a5, 0x00c08, 0x002c5, 0x00f11, 0x00cc4, 0x00f8e, 0x00e16,
+ 0x00496, 0x00e77, 0x00f9c, 0x00c25, 0x00f1e, 0x00c27, 0x00f1f, 0x00e17,
+ 0x00ccd, 0x00355, 0x00c09, 0x00c78, 0x00f90, 0x00521, 0x00357, 0x00356,
+ 0x0068e, 0x00f9d, 0x00c04, 0x00e58, 0x00a20, 0x00a2c, 0x00c4c, 0x0052f,
+ 0x00f8d, 0x01178, 0x01053, 0x01097, 0x0180f, 0x0180d, 0x012fb, 0x012aa,
+ 0x0202a, 0x00a40, 0x018ed, 0x01ceb, 0x01455, 0x018e3, 0x012a1, 0x00354,
+ 0x00353, 0x00f1c, 0x00c7b, 0x00c37, 0x0101d, 0x012cb, 0x01142, 0x0197d,
+ 0x01095, 0x01e3b, 0x0186b, 0x00588, 0x01c2a, 0x014b8, 0x01e3a, 0x018ec,
+ 0x01f46, 0x012fa, 0x00a53, 0x01ce8, 0x00a55, 0x01c29, 0x0117b, 0x01052,
+ 0x012a0, 0x00589, 0x00950, 0x01c2b, 0x00a50, 0x0208b, 0x0180e, 0x02027,
+ 0x02556, 0x01e20, 0x006e7, 0x01c28, 0x0197a, 0x00684, 0x020a2, 0x01f22,
+ 0x03018, 0x039cf, 0x03e25, 0x02557, 0x0294c, 0x028a6, 0x00d11, 0x028a9,
+ 0x02979, 0x00d46, 0x00a56, 0x039ce, 0x030cc, 0x0329a, 0x0149d, 0x0510f,
+ 0x0451c, 0x02028, 0x03299, 0x01ced, 0x014b9, 0x00f85, 0x00c7a, 0x01800,
+ 0x00341, 0x012ca, 0x039c8, 0x0329d, 0x00d0d, 0x03e20, 0x05144, 0x00d45,
+ 0x030d0, 0x0186d, 0x030d5, 0x00d0f, 0x00d40, 0x04114, 0x020a1, 0x0297f,
+ 0x03e24, 0x032f1, 0x04047, 0x030d4, 0x028a8, 0x00d0e, 0x0451d, 0x04044,
+ 0x0297e, 0x04042, 0x030d2, 0x030cf, 0x03e21, 0x03e26, 0x028a5, 0x0451a,
+ 0x00d48, 0x01a16, 0x00d44, 0x04518, 0x0149b, 0x039ca, 0x01498, 0x0403d,
+ 0x0451b, 0x0149c, 0x032f3, 0x030cb, 0x08073, 0x03e22, 0x0529a, 0x020aa,
+ 0x039cc, 0x0738a, 0x06530, 0x07389, 0x06193, 0x08071, 0x04043, 0x030ce,
+ 0x05147, 0x07388, 0x05145, 0x08072, 0x04521, 0x00d47, 0x0297c, 0x030cd,
+ 0x030ca, 0x0000b, 0x0000c, 0x00083, 0x000e4, 0x00048, 0x00102, 0x001cc,
+ 0x001f5, 0x00097, 0x0020b, 0x00124, 0x00453, 0x00627, 0x00639, 0x00605,
+ 0x00517, 0x001b8, 0x00663, 0x00667, 0x007c3, 0x00823, 0x00961, 0x00963,
+ 0x00e5a, 0x00e59, 0x00a2b, 0x00cbf, 0x00292, 0x00a2d, 0x007d0, 0x00953,
+ 0x00cc5, 0x00f84, 0x004ab, 0x014a7, 0x0068a, 0x0117a, 0x0052e, 0x01442,
+ 0x0052c, 0x00c77, 0x00f8f, 0x004aa, 0x01094, 0x01801, 0x012c4, 0x0297b,
+ 0x00952, 0x01f19, 0x006a5, 0x01149, 0x012c5, 0x01803, 0x022f2, 0x0329b,
+ 0x04520, 0x0149e, 0x00d13, 0x01f16, 0x01ce9, 0x0101c, 0x006e6, 0x039c9,
+ 0x06191, 0x07c8e, 0x06192, 0x0ca63, 0x039cd, 0x06190, 0x06884, 0x06885,
+ 0x07382, 0x00d49, 0x00d41, 0x0450c, 0x0149a, 0x030d1, 0x08077, 0x03e23,
+ 0x01a15, 0x0e701, 0x0e702, 0x08079, 0x0822a, 0x0a218, 0x07887, 0x0403f,
+ 0x0520b, 0x0529b, 0x0e700, 0x04519, 0x00007, 0x000e0, 0x000d0, 0x0039b,
+ 0x003e5, 0x00163, 0x0063e, 0x007c9, 0x00806, 0x00954, 0x01044, 0x01f44,
+ 0x0197c, 0x01f45, 0x00a51, 0x01f47, 0x00951, 0x0052d, 0x02291, 0x0092f,
+ 0x00a54, 0x00d12, 0x0297d, 0x00d0c, 0x01499, 0x0329e, 0x032f0, 0x02025,
+ 0x039c6, 0x00a57, 0x03e46, 0x00d42, 0x0738b, 0x05146, 0x04046, 0x08078,
+ 0x0510e, 0x07886, 0x02904, 0x04156, 0x04157, 0x06032, 0x030d3, 0x08bce,
+ 0x04040, 0x0403e, 0x0a414, 0x10457, 0x08075, 0x06887, 0x07c8f, 0x039c7,
+ 0x07387, 0x08070, 0x08bcf, 0x1482a, 0x10456, 0x1482b, 0x01a17, 0x06886,
+ 0x0450d, 0x00013, 0x0006b, 0x00615, 0x0080b, 0x0082b, 0x00952, 0x00e5b,
+ 0x018e2, 0x0186c, 0x01f18, 0x0329f, 0x00d43, 0x03e29, 0x05140, 0x05141,
+ 0x0ca62, 0x06033, 0x03c42, 0x03e28, 0x0450f, 0x0a21a, 0x07384, 0x0a219,
+ 0x0e703, 0x0a21b, 0x01a14, 0x07383, 0x045e6, 0x0007a, 0x0012c, 0x00ccc,
+ 0x0068f, 0x01802, 0x00a52, 0x00953, 0x04045, 0x01a20, 0x0451f, 0x000a4,
+ 0x00735, 0x01cec, 0x02029, 0x020a3, 0x0451e, 0x00069, 0x00c24, 0x02024,
+ 0x032f2, 0x05142, 0x00196, 0x00523, 0x000a6, 0x0197b, 0x0030b, 0x0092e,
+ 0x003e9, 0x03e27, 0x00160, 0x05143, 0x00652, 0x04041, 0x00734, 0x028a7,
+ 0x0080f, 0x01483, 0x0097c, 0x00340, 0x0068b, 0x00522, 0x01054, 0x01096,
+ 0x01f17, 0x0202b, 0x01cea, 0x020a0, 0x02978, 0x02026, 0x0297a, 0x039cb,
+ 0x03e2b, 0x0149f, 0x0329c, 0x07385, 0x08074, 0x0450e, 0x03e2a, 0x05149,
+ 0x08076, 0x07386, 0x05148,
+};
+
+static const uint8_t coef1_huffbits[555] = {
+ 9, 5, 2, 4, 4, 5, 5, 5,
+ 6, 6, 6, 6, 6, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 8,
+ 8, 8, 8, 8, 8, 8, 8, 8,
+ 8, 8, 8, 8, 8, 8, 8, 8,
+ 9, 8, 8, 8, 8, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 10, 10, 10, 9, 9, 9, 9,
+ 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10,
+ 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, 12, 12, 12, 12, 12, 12, 12,
+ 12, 12, 11, 11, 11, 11, 11, 12,
+ 12, 12, 12, 12, 12, 12, 12, 12,
+ 13, 12, 12, 12, 12, 12, 12, 12,
+ 13, 12, 12, 12, 12, 12, 12, 12,
+ 12, 13, 12, 12, 12, 13, 13, 13,
+ 13, 12, 12, 12, 12, 12, 12, 13,
+ 12, 13, 13, 13, 13, 13, 13, 13,
+ 14, 14, 13, 13, 13, 13, 13, 13,
+ 13, 12, 12, 12, 13, 13, 13, 13,
+ 13, 13, 13, 13, 13, 13, 13, 13,
+ 13, 13, 14, 13, 14, 13, 13, 13,
+ 13, 13, 14, 13, 14, 14, 13, 14,
+ 14, 13, 14, 13, 13, 14, 14, 13,
+ 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 15, 14, 14, 14, 14, 15, 15,
+ 15, 14, 14, 13, 13, 12, 12, 13,
+ 13, 13, 14, 14, 15, 14, 15, 15,
+ 14, 13, 14, 15, 15, 15, 14, 14,
+ 14, 14, 15, 14, 14, 15, 15, 15,
+ 14, 15, 14, 14, 14, 14, 14, 15,
+ 15, 16, 15, 15, 15, 14, 15, 15,
+ 15, 15, 14, 14, 16, 14, 15, 14,
+ 14, 15, 15, 15, 15, 16, 15, 14,
+ 15, 15, 15, 16, 15, 15, 14, 14,
+ 14, 4, 7, 8, 8, 9, 9, 9,
+ 9, 10, 10, 11, 11, 11, 11, 11,
+ 11, 12, 11, 11, 11, 12, 12, 12,
+ 12, 12, 12, 12, 12, 12, 11, 12,
+ 12, 12, 13, 13, 13, 13, 13, 13,
+ 13, 12, 12, 13, 13, 13, 13, 14,
+ 14, 13, 14, 13, 13, 13, 14, 14,
+ 15, 15, 14, 13, 13, 13, 14, 14,
+ 15, 15, 15, 16, 14, 15, 17, 17,
+ 15, 15, 15, 15, 15, 14, 16, 14,
+ 16, 16, 16, 16, 16, 16, 15, 15,
+ 17, 15, 16, 15, 6, 8, 10, 10,
+ 10, 11, 11, 11, 12, 12, 13, 13,
+ 13, 13, 14, 13, 14, 13, 14, 14,
+ 14, 14, 14, 15, 15, 14, 14, 14,
+ 14, 14, 14, 15, 15, 15, 15, 16,
+ 15, 15, 16, 15, 15, 15, 14, 16,
+ 15, 15, 18, 17, 16, 17, 15, 14,
+ 15, 16, 16, 19, 17, 19, 16, 17,
+ 15, 7, 10, 11, 12, 12, 12, 12,
+ 13, 13, 13, 14, 15, 14, 15, 15,
+ 16, 15, 14, 14, 15, 16, 15, 16,
+ 16, 16, 16, 15, 15, 7, 11, 12,
+ 13, 13, 14, 14, 15, 15, 15, 8,
+ 11, 13, 14, 14, 15, 9, 12, 14,
+ 14, 15, 9, 13, 10, 13, 10, 14,
+ 10, 14, 11, 15, 11, 15, 11, 14,
+ 12, 15, 12, 13, 13, 13, 13, 13,
+ 13, 14, 13, 14, 14, 14, 14, 14,
+ 14, 15, 14, 15, 16, 15, 14, 15,
+ 16, 15, 15,
+};
+
+static const uint32_t coef2_huffcodes[1336] = {
+ 0x003e6, 0x000f6, 0x00000, 0x00002, 0x00006, 0x0000f, 0x0001b, 0x00028,
+ 0x00039, 0x0003f, 0x0006b, 0x00076, 0x000b7, 0x000e8, 0x000ef, 0x00169,
+ 0x001a7, 0x001d4, 0x001dc, 0x002c4, 0x00349, 0x00355, 0x00391, 0x003dc,
+ 0x00581, 0x005b2, 0x00698, 0x0070c, 0x00755, 0x0073a, 0x00774, 0x007cf,
+ 0x00b0a, 0x00b66, 0x00d2e, 0x00d5e, 0x00e1b, 0x00eac, 0x00e5a, 0x00f7e,
+ 0x00fa1, 0x0163e, 0x01a37, 0x01a52, 0x01c39, 0x01ab3, 0x01d5f, 0x01cb6,
+ 0x01f52, 0x01dd9, 0x02c04, 0x02c2e, 0x02c2d, 0x02c23, 0x03467, 0x034a3,
+ 0x0351b, 0x03501, 0x03a5d, 0x0351c, 0x03875, 0x03dea, 0x0397b, 0x039db,
+ 0x03df1, 0x039d8, 0x03bb4, 0x0580a, 0x0584d, 0x05842, 0x05b13, 0x058ea,
+ 0x0697d, 0x06a06, 0x068cc, 0x06ac7, 0x06a96, 0x072f4, 0x07543, 0x072b4,
+ 0x07d20, 0x0b003, 0x073b5, 0x07be6, 0x0d180, 0x07bd1, 0x07cb8, 0x07d06,
+ 0x07d25, 0x0d2f2, 0x0d19a, 0x0d334, 0x0e1dc, 0x0d529, 0x0d584, 0x0e1d2,
+ 0x0e5e3, 0x0eec4, 0x0e564, 0x0fa49, 0x16001, 0x0eedc, 0x0f7fa, 0x1a32c,
+ 0x16131, 0x16003, 0x0f9c8, 0x1ef80, 0x1d2a0, 0x1aa4b, 0x0f7ce, 0x1abfe,
+ 0x1aa50, 0x1a458, 0x1a816, 0x1cae4, 0x1d2fe, 0x1d52e, 0x1aa4c, 0x2c245,
+ 0x1d2a1, 0x1a35d, 0x1ca1b, 0x1d5d8, 0x1f531, 0x1ca1c, 0x1f389, 0x1f4af,
+ 0x3a5e7, 0x351fb, 0x2c24b, 0x34bce, 0x2c24d, 0x2c249, 0x2c24a, 0x72dfc,
+ 0x357ef, 0x35002, 0x3a5e6, 0x39431, 0x5843b, 0x34a77, 0x58431, 0x3a5f3,
+ 0x3a5dd, 0x3e5e5, 0x356bd, 0x3976e, 0x6a3d2, 0x3500d, 0x694c4, 0x580bd,
+ 0x3e5e8, 0x74b95, 0x34a6e, 0x3977c, 0x39432, 0x5b0d2, 0x6a3d8, 0x580b8,
+ 0x5b0cb, 0x5b0d7, 0x72dee, 0x72ded, 0x72dec, 0x74b9c, 0x3977f, 0x72dea,
+ 0x74b9e, 0x7be7d, 0x580bf, 0x5b0d5, 0x7cba8, 0x74b91, 0x3e5dd, 0xb6171,
+ 0xd46b3, 0xd46b9, 0x7cba1, 0x74b9f, 0x72de1, 0xe59f5, 0x3e5eb, 0x00004,
+ 0x00015, 0x00038, 0x00075, 0x000e8, 0x001d3, 0x00347, 0x0039c, 0x00690,
+ 0x0074a, 0x00b60, 0x00e93, 0x00f74, 0x0163d, 0x01a5a, 0x01d24, 0x01cbe,
+ 0x01f4b, 0x03468, 0x03562, 0x03947, 0x03e82, 0x05804, 0x05b12, 0x05803,
+ 0x0696d, 0x06a9e, 0x0697c, 0x06978, 0x06afb, 0x074b2, 0x072f5, 0x073c0,
+ 0x07541, 0x06944, 0x074b7, 0x070d3, 0x07ba9, 0x0b0b1, 0x0d1af, 0x0e1dd,
+ 0x0e5e2, 0x0e1a3, 0x0eec3, 0x1612f, 0x0e961, 0x0eeda, 0x0e78e, 0x0fa48,
+ 0x1612c, 0x0e511, 0x0e565, 0x0e953, 0x1aa4a, 0x0e59d, 0x1d52c, 0x1a811,
+ 0x1cae7, 0x1abfc, 0x1d52d, 0x1cacf, 0x1cf05, 0x2c254, 0x34a72, 0x1f4ac,
+ 0x3976b, 0x34a71, 0x2c6d9, 0x2d873, 0x34a6a, 0x357e7, 0x3464c, 0x3e5f5,
+ 0x58433, 0x1f53a, 0x3500a, 0x357ea, 0x34a73, 0x3942f, 0x357e5, 0x39775,
+ 0x694cd, 0x39772, 0x7cba5, 0x6a3ef, 0x35483, 0x74b98, 0x5b0c1, 0x39770,
+ 0x3a5d7, 0x39433, 0x39434, 0x694ce, 0x580be, 0x3e5ff, 0x6a3ec, 0xb616f,
+ 0xd46b1, 0x6a3d1, 0x72de5, 0x74b6e, 0x72de9, 0x3e700, 0xd46b6, 0x6a3e9,
+ 0x74b69, 0xe5675, 0xd46b8, 0x7cbaa, 0x3a5d1, 0x0000c, 0x0003c, 0x000eb,
+ 0x001f1, 0x003a4, 0x006a8, 0x007d5, 0x00d43, 0x00e77, 0x016c5, 0x01cb1,
+ 0x02c5d, 0x03a55, 0x03a56, 0x03e51, 0x03bb5, 0x05b0a, 0x06a9f, 0x074b8,
+ 0x07d28, 0x0d187, 0x0d40e, 0x0d52e, 0x0d425, 0x0eae3, 0x0e1d3, 0x1612e,
+ 0x0e59e, 0x0eec2, 0x0e578, 0x0e51a, 0x0e579, 0x0e515, 0x0e960, 0x0d183,
+ 0x0d220, 0x0d2cb, 0x0e512, 0x16c3e, 0x16002, 0x16c42, 0x1cae9, 0x3461a,
+ 0x1d2fa, 0x1a308, 0x1a849, 0x1cf07, 0x1f38f, 0x34b65, 0x2c253, 0x1ef9e,
+ 0x1cbc3, 0x1cbc1, 0x2c255, 0x1f384, 0x58435, 0x2c5cd, 0x3a5f7, 0x2c252,
+ 0x3959c, 0x2c6d8, 0x3a5d3, 0x6ad78, 0x6a3f2, 0x7cba9, 0xb6176, 0x72deb,
+ 0x39764, 0x3e5f6, 0x3a5d8, 0x74a8c, 0x6a3e6, 0x694d1, 0x6ad79, 0x1a4592,
+ 0xe59fb, 0x7cbb3, 0x5b0cd, 0x00017, 0x000b5, 0x002c3, 0x005b7, 0x00b1c,
+ 0x00e5c, 0x0163f, 0x01ab2, 0x01efa, 0x0348a, 0x0396e, 0x058da, 0x06963,
+ 0x06a30, 0x072cd, 0x073cf, 0x07ce7, 0x0d2ca, 0x0d2d8, 0x0e764, 0x0e794,
+ 0x16008, 0x16167, 0x1617e, 0x1aa49, 0x1a30b, 0x1a813, 0x2c6da, 0x1a580,
+ 0x1cbc2, 0x0f9ca, 0x1617f, 0x1d2fe, 0x0f7fc, 0x16c40, 0x0e513, 0x0eec5,
+ 0x0f7c3, 0x1d508, 0x1a81e, 0x1d2fd, 0x39430, 0x35486, 0x3e5fd, 0x2c24c,
+ 0x2c75a, 0x34a74, 0x3a5f4, 0x3464d, 0x694ca, 0x3a5f1, 0x1d509, 0x1d5c0,
+ 0x34648, 0x3464e, 0x6a3d5, 0x6a3e8, 0x6a3e7, 0x5b0c3, 0x2c248, 0x1f38a,
+ 0x3a5f2, 0x6a3e5, 0x00029, 0x00168, 0x0058c, 0x00b67, 0x00f9d, 0x01c3d,
+ 0x01cbf, 0x02c20, 0x0351d, 0x03df6, 0x06af9, 0x072b5, 0x0b1d7, 0x0b0b2,
+ 0x0d40a, 0x0d52b, 0x0e952, 0x0e797, 0x163c3, 0x1c3a0, 0x1f386, 0x1ca21,
+ 0x34655, 0x2c247, 0x1f53b, 0x2c250, 0x2c24f, 0x1f385, 0x1ef5d, 0x1cf15,
+ 0x1caea, 0x1ab0a, 0x1cf19, 0x1f53d, 0x1d5c2, 0x1d2fb, 0x1ef58, 0x34a78,
+ 0x357ec, 0x1f533, 0x3a5e1, 0x694d2, 0x58482, 0x3a5ee, 0x2c6dc, 0x357eb,
+ 0x5b0c4, 0x39778, 0x6a3e1, 0x7cbb4, 0x3a5e1, 0x74b68, 0x3a5ef, 0x3a5d2,
+ 0x39424, 0x72de2, 0xe59f6, 0xe59f7, 0x3e702, 0x3e5ec, 0x1f38b, 0x0003b,
+ 0x001f0, 0x00777, 0x00fa8, 0x01cb2, 0x02d84, 0x03a57, 0x03dd6, 0x06917,
+ 0x06a11, 0x07d07, 0x0eae2, 0x0e796, 0x0f9c9, 0x0f7fb, 0x16166, 0x16160,
+ 0x1ab1b, 0x1abfa, 0x2d87b, 0x1d2f7, 0x39768, 0x1f38c, 0x34653, 0x34651,
+ 0x6a3d9, 0x35001, 0x3abbd, 0x38742, 0x39426, 0x34a76, 0x3a5ec, 0x34a75,
+ 0x35000, 0x35488, 0x1cf10, 0x2c6db, 0x357ed, 0x357e8, 0x357e9, 0x3a5f0,
+ 0x694c2, 0xb6178, 0x72df5, 0x39425, 0x3942b, 0x74b6d, 0x74b6f, 0xb6177,
+ 0xb6179, 0x74b6a, 0xb6172, 0x58487, 0x3e5ee, 0x3e5ed, 0x72df2, 0x72df4,
+ 0x7cbae, 0x6a3ca, 0x70e86, 0x34bcf, 0x6a3c8, 0x00059, 0x00384, 0x00d5b,
+ 0x01c38, 0x03560, 0x0395b, 0x0584e, 0x06964, 0x073cd, 0x0b1e7, 0x0e798,
+ 0x0e78d, 0x0fa43, 0x1a848, 0x1a32f, 0x1aa4e, 0x3464a, 0x1f4ab, 0x1f38d,
+ 0x3a5eb, 0x3a5d4, 0x3548a, 0x6a3c7, 0x5b0d0, 0x6a3c5, 0x7cbb0, 0x694cb,
+ 0x3a5e5, 0x3e5e2, 0x3942c, 0x2d872, 0x1f4ae, 0x3a5d5, 0x694d3, 0x58481,
+ 0x35009, 0x39774, 0x58432, 0xb616c, 0x5b0db, 0x3548b, 0xb6174, 0x1d5d95,
+ 0xb004c, 0x7cbb2, 0x3a5e5, 0x74a8f, 0xe59f9, 0x72df6, 0xe59fd, 0x7cbad,
+ 0xd427d, 0x72cff, 0x3977a, 0x5b0d9, 0xb616d, 0xb616b, 0x1a4593, 0x7cbaf,
+ 0x5b0da, 0x00071, 0x003eb, 0x01603, 0x02c6c, 0x03961, 0x068c8, 0x06a31,
+ 0x072bd, 0x0d2c2, 0x0e51b, 0x0e5e6, 0x1abfb, 0x1d2ff, 0x1cae5, 0x1ef5c,
+ 0x1ef5e, 0x1cf13, 0x34a6d, 0x3976d, 0xb616a, 0x3e5f2, 0x6a3c4, 0xb6169,
+ 0x3e5dc, 0x580b9, 0x74b99, 0x75764, 0x58434, 0x3a5d9, 0x6945a, 0x69459,
+ 0x3548c, 0x3a5e9, 0x69457, 0x72df1, 0x6945e, 0x6a35e, 0x3e701, 0xb6168,
+ 0x5b0dd, 0x3a5de, 0x6a3c2, 0xd4278, 0x6a3cc, 0x72dfd, 0xb6165, 0x16009a,
+ 0x7cbb1, 0xd427c, 0xb6162, 0xe765e, 0x1cecbe, 0x7cbb6, 0x69454, 0xb6160,
+ 0xd427a, 0x1d5d96, 0xb1d6d, 0xe59f4, 0x72de8, 0x3a5db, 0x0007a, 0x006ae,
+ 0x01c3c, 0x03aba, 0x058e9, 0x072cc, 0x0d2dd, 0x0d22d, 0x0eec1, 0x0eedb,
+ 0x1d2a2, 0x1ef5b, 0x357e2, 0x3abbf, 0x1d2f9, 0x35004, 0x3a5dc, 0x351fc,
+ 0x3976c, 0x6a3c6, 0x6a3cb, 0x3e5ea, 0xe59f3, 0x6a3ce, 0x69452, 0xe59f0,
+ 0x74b90, 0xd4279, 0xd427b, 0x7cbb5, 0x5b0c5, 0x3a5e3, 0x3a5e2, 0x000d0,
+ 0x00775, 0x01efe, 0x03dd5, 0x0728c, 0x07cb9, 0x0e1a2, 0x0ea85, 0x0eed8,
+ 0x1a30a, 0x1aa4f, 0x3a5df, 0x35008, 0x3a5e0, 0x3e5f4, 0x3e5f7, 0xb1d6c,
+ 0x5843e, 0x34a70, 0x72df8, 0x74b6b, 0xd427f, 0x72df0, 0x5b0bf, 0x5b0c0,
+ 0xd46b0, 0x72def, 0xe59f8, 0x162e64, 0xb1d6f, 0x3a5e0, 0x39427, 0x69166,
+ 0x6a3e2, 0x6a3e3, 0x74a8d, 0xd427e, 0x1d5d97, 0xd46b4, 0x5b0d8, 0x6a3d3,
+ 0x000e0, 0x00b63, 0x034cc, 0x06a33, 0x073c9, 0x0e1a0, 0x0f7fd, 0x0f9cc,
+ 0x1617d, 0x1caeb, 0x1f4a9, 0x3abb3, 0x69450, 0x39420, 0x39777, 0x3e5e0,
+ 0x6a3d4, 0x6a3ed, 0xb6166, 0xe59f1, 0xb1d6e, 0xe5676, 0x6a3ea, 0xe5674,
+ 0xb6163, 0xd46b7, 0x7cba6, 0xd46ba, 0x1d5d94, 0xb6164, 0x6a3f1, 0x7cba2,
+ 0x69451, 0x72dfa, 0xd46bb, 0x72df7, 0x74b94, 0x1cecbf, 0xe59fa, 0x16009b,
+ 0x6a3e4, 0x000e6, 0x00e94, 0x03876, 0x070ef, 0x0d52a, 0x16015, 0x16014,
+ 0x1abf9, 0x1cf17, 0x34a79, 0x34650, 0x3e705, 0x6a3d0, 0x58430, 0x74b9d,
+ 0x7be7e, 0x5b0be, 0x39773, 0x6a3de, 0x000fb, 0x00f7b, 0x03dd7, 0x07bd0,
+ 0x0e59c, 0x0f9cd, 0x1cf18, 0x1d2ff, 0x34a7a, 0x39429, 0x3500c, 0x72de0,
+ 0x69456, 0x7be7c, 0xd46b5, 0xd46b2, 0x6a3dd, 0x001a2, 0x0163b, 0x06913,
+ 0x0b016, 0x0fa42, 0x1a32d, 0x1cf06, 0x34a7c, 0x34a7d, 0xb6161, 0x35481,
+ 0x3e5fa, 0x7cba0, 0x7be7f, 0x7cba3, 0x7cba7, 0x5b0d3, 0x72de6, 0x6a3dc,
+ 0x001a9, 0x01ab4, 0x06a34, 0x0d46a, 0x16130, 0x1ef5f, 0x1f532, 0x1f536,
+ 0x3942e, 0x58436, 0x6a3db, 0x6945b, 0x001c9, 0x01ca0, 0x0728b, 0x0eed9,
+ 0x1f539, 0x1ca1d, 0x39765, 0x39766, 0x58439, 0x6945d, 0x39767, 0x001d3,
+ 0x01f2c, 0x07bfc, 0x16161, 0x34652, 0x3a5ed, 0x3548d, 0x58438, 0x6a3da,
+ 0x002c1, 0x02c5e, 0x0d335, 0x1ab1a, 0x2d874, 0x35006, 0x35484, 0x5b0cc,
+ 0x74b9a, 0x72df3, 0x6a3d6, 0x002da, 0x034b3, 0x0d5ae, 0x1caee, 0x2d871,
+ 0x357e3, 0x74b97, 0x72df9, 0x580ba, 0x5b0d4, 0x0034d, 0x0354e, 0x0f750,
+ 0x1cbc0, 0x3a5e7, 0x3a5e4, 0x00385, 0x03a58, 0x16c41, 0x2c5cf, 0x3e5e1,
+ 0x74b6c, 0xe5677, 0x6a3df, 0x00390, 0x03e50, 0x163c2, 0x2d876, 0x35482,
+ 0x5b0d6, 0x5843a, 0x0039f, 0x0585e, 0x1a583, 0x3500f, 0x74b93, 0x39771,
+ 0x003e4, 0x06912, 0x16c43, 0x357e1, 0x0058a, 0x0696f, 0x1f538, 0x5b0c9,
+ 0x6a3cf, 0x005b6, 0x06af8, 0x1f534, 0x58483, 0x6a3e0, 0x00695, 0x07d02,
+ 0x1cae8, 0x58485, 0x006a2, 0x0754a, 0x357ee, 0x3977b, 0x00748, 0x074b2,
+ 0x34a7b, 0x00729, 0x0b1e0, 0x34649, 0x3e5e3, 0x0073d, 0x0d2c4, 0x3e5e6,
+ 0x007bb, 0x0b099, 0x39762, 0x5b0ce, 0x6945f, 0x007d1, 0x0d5ab, 0x39779,
+ 0x007d3, 0x0d52f, 0x39763, 0x6945c, 0x00b1a, 0x0d2c5, 0x35489, 0x00d23,
+ 0x0eaed, 0x3e5f8, 0x00d32, 0x16016, 0x3e5fb, 0x00d41, 0x0e768, 0x3a5ed,
+ 0x00e1f, 0x16017, 0x58027, 0x00ead, 0x0fa07, 0x69455, 0x00e54, 0x1612b,
+ 0x00e55, 0x1a581, 0x00f78, 0x1a32b, 0x580bc, 0x6a3ee, 0x00f79, 0x1abfd,
+ 0x00f95, 0x1ab18, 0x6a3f0, 0x01637, 0x1aa4d, 0x0162d, 0x1f53c, 0x6a3f3,
+ 0x01a31, 0x1a810, 0x39769, 0x01a50, 0x1caef, 0x01a36, 0x1a32e, 0x01a67,
+ 0x1f38e, 0x01a85, 0x1ef59, 0x01aa6, 0x1ef83, 0x01d51, 0x2c012, 0x01d53,
+ 0x2d879, 0x01d5e, 0x35005, 0x01cba, 0x1cf04, 0x69453, 0x01d2d, 0x351ff,
+ 0x01f2d, 0x2d86f, 0x01f29, 0x35007, 0x02c22, 0x351fa, 0x02c03, 0x3a5ec,
+ 0x02c5f, 0x3a5eb, 0x02c58, 0x34a6b, 0x03469, 0x356be, 0x02c59, 0x34a6c,
+ 0x0346a, 0x3a5ea, 0x034bd, 0x034bf, 0x356bf, 0x0386a, 0x03ab9, 0x5843f,
+ 0x0386b, 0x3a5f5, 0x03a4b, 0x39421, 0x03aa4, 0x3a5e9, 0x03a5a, 0x03960,
+ 0x3977e, 0x03de9, 0x03958, 0x03df7, 0x039e1, 0x3e5e4, 0x0395f, 0x69458,
+ 0x03e91, 0x03df2, 0x39428, 0x058f2, 0x03e80, 0x6a3c3, 0x03e93, 0x694c0,
+ 0x058b8, 0x5b0ca, 0x0584f, 0x694c1, 0x058f1, 0x068d6, 0x06a10, 0x06ac3,
+ 0x06a32, 0x070d2, 0x06911, 0x074b1, 0x07494, 0x06ad4, 0x06ad6, 0x072b8,
+ 0x06afa, 0x074b3, 0x07540, 0x073ce, 0x0b005, 0x074b3, 0x07495, 0x074b9,
+ 0x0d336, 0x07bff, 0x07763, 0x073c8, 0x07d29, 0x0b622, 0x0d221, 0x0d181,
+ 0x0b1d1, 0x074b8, 0x0b1d0, 0x0d19b, 0x0d2c3, 0x0b172, 0x0d2dc, 0x0b623,
+ 0x0d5aa, 0x0d426, 0x0d182, 0x0e795, 0x0e1d1, 0x0d337, 0x0e96c, 0x0e5e4,
+ 0x0e514, 0x0eaee, 0x16000, 0x0e767, 0x0e1a1, 0x0e78f, 0x16004, 0x0f7c2,
+ 0x0e799, 0x0e5e7, 0x0e566, 0x0e769, 0x0f751, 0x0eede, 0x0fa06, 0x16005,
+ 0x0fa9f, 0x1a5e6, 0x0e766, 0x1636f, 0x0eedd, 0x0eec0, 0x1a309, 0x1ceca,
+ 0x163cd, 0x0f9cb, 0x0eedf, 0x1a582, 0x1612d, 0x0e5e5, 0x1abf8, 0x1a30c,
+ 0x1ca1f, 0x163cc, 0x1a35c, 0x1ca1e, 0x1aa51, 0x163ac, 0x1a84e, 0x1a53f,
+ 0x1cf16, 0x1d2fc, 0x1a5b3, 0x1ab19, 0x1a81f, 0x1d5c3, 0x16c3f, 0x1d5c1,
+ 0x1d2fc, 0x1f4aa, 0x1a812, 0x1f535, 0x1cf12, 0x1a817, 0x1617c, 0x1ab0b,
+ 0x1d2f8, 0x1ef82, 0x2d87a, 0x1d52f, 0x1f530, 0x1aa48, 0x35487, 0x1d2fd,
+ 0x1f4ad, 0x1cf11, 0x3461b, 0x35485, 0x1ca20, 0x1caed, 0x1cae6, 0x1abff,
+ 0x3464f, 0x34a6f, 0x1ef81, 0x3464b, 0x39d96, 0x1f383, 0x1f537, 0x1cf14,
+ 0x2c5ce, 0x3500e, 0x2c251, 0x1caec, 0x1f387, 0x34654, 0x357e4, 0x2d878,
+ 0x3500b, 0x35480, 0x3a5e8, 0x3548e, 0x34b64, 0x1f4a8, 0x35003, 0x3e5df,
+ 0x2d870, 0x357e6, 0x3e5f0, 0x1ef5a, 0x3a5ea, 0x1f388, 0x3e703, 0x2c24e,
+ 0x3a5e2, 0x351fd, 0x2c6dd, 0x3e704, 0x351fe, 0x2d875, 0x5b0c7, 0x3976a,
+ 0x3a5e6, 0x39423, 0x58480, 0x2c246, 0x3a5e3, 0x2d877, 0x3e5f1, 0x3abbe,
+ 0x58489, 0x3e5f9, 0x357e0, 0x3abbc, 0x5b0c6, 0x69167, 0x69165, 0x3e5e9,
+ 0x39422, 0x3976f, 0x3977d, 0x3e5de, 0x6a3c9, 0x58b98, 0x3a5f6, 0x3a5d0,
+ 0x58486, 0x6a3c1, 0x3e5fc, 0x5b0dc, 0x3548f, 0x3942d, 0x694c9, 0x58484,
+ 0x3a5e8, 0x74b9b, 0x74b96, 0x694d0, 0x58488, 0x3a5e4, 0x3942a, 0x72ec2,
+ 0x39776, 0x5b0d1, 0x5b0cf, 0x3a5d6, 0xe59fc, 0x5b0c8, 0x3e5e7, 0x7cbb7,
+ 0x70e87, 0x7cbab, 0x5b0c2, 0x694c3, 0x74a8e, 0x3e5f3, 0x6a3cd, 0x72dfe,
+ 0x73b2e, 0x72ec0, 0x694c5, 0x58437, 0x694c8, 0x72dff, 0x39435, 0x5843d,
+ 0x6a3d7, 0x72ec1, 0xd22c8, 0x694cf, 0xb6173, 0x3e5fe, 0x580bb, 0xe59f2,
+ 0xb616e, 0xb6175, 0x3a5da, 0x5b0bd, 0x694cc, 0x5843c, 0x694c7, 0x74b92,
+ 0x72ec3, 0x694c6, 0xb6170, 0x7cbac, 0xb1733, 0x7cba4, 0xb6167, 0x72de7,
+ 0x72de4, 0x6a3c0, 0x3e5ef, 0x162e65, 0x72de3, 0x72dfb, 0x6a35f, 0x6a3eb,
+};
+
+static const uint8_t coef2_huffbits[1336] = {
+ 11, 9, 2, 3, 4, 4, 5, 6,
+ 6, 7, 7, 8, 8, 8, 9, 9,
+ 9, 9, 10, 10, 10, 10, 11, 11,
+ 11, 11, 11, 11, 11, 12, 12, 12,
+ 12, 12, 12, 12, 12, 12, 13, 13,
+ 13, 13, 13, 13, 13, 13, 13, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 16, 15, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16,
+ 17, 17, 17, 17, 17, 17, 17, 17,
+ 17, 17, 17, 18, 17, 17, 17, 17,
+ 17, 17, 17, 18, 18, 17, 17, 18,
+ 17, 17, 18, 17, 18, 18, 18, 18,
+ 19, 18, 18, 18, 18, 18, 18, 20,
+ 18, 18, 18, 19, 19, 18, 19, 18,
+ 19, 19, 18, 19, 19, 18, 19, 19,
+ 19, 19, 18, 19, 19, 19, 19, 19,
+ 19, 19, 20, 20, 20, 19, 19, 20,
+ 19, 20, 19, 19, 20, 19, 19, 20,
+ 20, 20, 20, 19, 20, 21, 19, 3,
+ 5, 7, 8, 9, 9, 10, 11, 11,
+ 12, 12, 12, 13, 13, 13, 13, 14,
+ 14, 14, 14, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 16, 16,
+ 15, 15, 15, 15, 16, 16, 16, 16,
+ 17, 16, 17, 17, 16, 17, 17, 17,
+ 17, 17, 17, 16, 17, 17, 17, 17,
+ 18, 17, 17, 18, 18, 18, 18, 18,
+ 19, 18, 18, 18, 18, 18, 18, 19,
+ 19, 18, 18, 18, 18, 19, 18, 19,
+ 19, 19, 20, 19, 18, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 20,
+ 20, 19, 20, 19, 20, 19, 20, 19,
+ 19, 21, 20, 20, 19, 4, 7, 8,
+ 10, 11, 11, 12, 12, 13, 13, 14,
+ 14, 14, 14, 15, 15, 15, 15, 15,
+ 16, 16, 16, 16, 16, 16, 16, 17,
+ 17, 17, 17, 17, 17, 17, 16, 16,
+ 16, 16, 17, 17, 17, 17, 18, 18,
+ 18, 17, 17, 18, 18, 18, 18, 18,
+ 18, 18, 18, 18, 19, 18, 18, 18,
+ 19, 18, 19, 19, 19, 20, 20, 20,
+ 19, 19, 19, 19, 19, 19, 19, 21,
+ 21, 20, 19, 5, 8, 10, 11, 12,
+ 13, 13, 13, 14, 14, 15, 15, 15,
+ 15, 16, 16, 16, 16, 16, 17, 17,
+ 17, 17, 17, 17, 17, 17, 18, 17,
+ 18, 17, 17, 17, 17, 17, 17, 17,
+ 17, 17, 17, 17, 19, 18, 19, 18,
+ 18, 18, 18, 18, 19, 18, 17, 17,
+ 18, 18, 19, 19, 19, 19, 18, 18,
+ 18, 19, 6, 9, 11, 12, 13, 13,
+ 14, 14, 14, 15, 15, 16, 16, 16,
+ 16, 16, 16, 17, 17, 17, 18, 18,
+ 18, 18, 18, 18, 18, 18, 18, 18,
+ 18, 17, 18, 18, 17, 18, 18, 18,
+ 18, 18, 18, 19, 19, 18, 18, 18,
+ 19, 19, 19, 20, 19, 19, 18, 19,
+ 19, 20, 21, 21, 19, 19, 18, 6,
+ 10, 12, 13, 14, 14, 14, 15, 15,
+ 15, 16, 16, 17, 17, 17, 17, 17,
+ 17, 17, 18, 18, 19, 18, 18, 18,
+ 19, 18, 18, 18, 19, 18, 18, 18,
+ 18, 18, 18, 18, 18, 18, 18, 18,
+ 19, 20, 20, 19, 19, 19, 19, 20,
+ 20, 19, 20, 19, 19, 19, 20, 20,
+ 20, 19, 19, 18, 19, 7, 10, 12,
+ 13, 14, 15, 15, 15, 16, 16, 17,
+ 17, 17, 17, 17, 17, 18, 18, 18,
+ 18, 19, 18, 19, 19, 19, 20, 19,
+ 18, 19, 19, 18, 18, 19, 19, 19,
+ 18, 19, 19, 20, 19, 18, 20, 21,
+ 20, 20, 19, 19, 21, 20, 21, 20,
+ 20, 20, 19, 19, 20, 20, 21, 20,
+ 19, 7, 11, 13, 14, 15, 15, 15,
+ 16, 16, 17, 17, 17, 17, 18, 18,
+ 18, 18, 18, 19, 20, 19, 19, 20,
+ 19, 19, 19, 19, 19, 19, 19, 19,
+ 18, 18, 19, 20, 19, 19, 19, 20,
+ 19, 19, 19, 20, 19, 20, 20, 21,
+ 20, 20, 20, 21, 22, 20, 19, 20,
+ 20, 21, 20, 21, 20, 19, 8, 11,
+ 13, 14, 15, 16, 16, 16, 17, 17,
+ 17, 18, 18, 18, 18, 18, 19, 18,
+ 19, 19, 19, 19, 21, 19, 19, 21,
+ 19, 20, 20, 20, 19, 18, 18, 8,
+ 12, 14, 15, 16, 16, 16, 16, 17,
+ 17, 17, 19, 18, 18, 19, 19, 20,
+ 19, 18, 20, 19, 20, 20, 19, 19,
+ 20, 20, 21, 21, 20, 19, 19, 19,
+ 19, 19, 19, 20, 21, 20, 19, 19,
+ 8, 12, 14, 15, 16, 16, 17, 17,
+ 17, 18, 18, 18, 19, 19, 19, 19,
+ 19, 19, 20, 21, 20, 21, 19, 21,
+ 20, 20, 20, 20, 21, 20, 19, 20,
+ 19, 20, 20, 20, 19, 22, 21, 21,
+ 19, 9, 12, 14, 15, 16, 17, 17,
+ 17, 18, 18, 18, 19, 19, 19, 19,
+ 20, 19, 19, 19, 9, 13, 15, 16,
+ 17, 17, 18, 18, 18, 19, 18, 20,
+ 19, 20, 20, 20, 19, 9, 13, 15,
+ 16, 17, 17, 18, 18, 18, 20, 18,
+ 19, 20, 20, 20, 20, 19, 20, 19,
+ 9, 13, 15, 16, 17, 18, 18, 18,
+ 19, 19, 19, 19, 10, 14, 16, 17,
+ 18, 18, 19, 19, 19, 19, 19, 10,
+ 14, 16, 17, 18, 18, 18, 19, 19,
+ 10, 14, 16, 17, 18, 18, 18, 19,
+ 19, 20, 19, 10, 14, 16, 18, 18,
+ 18, 19, 20, 19, 19, 10, 14, 17,
+ 18, 18, 18, 10, 15, 17, 18, 19,
+ 19, 21, 19, 11, 15, 17, 18, 18,
+ 19, 19, 11, 15, 17, 18, 19, 19,
+ 11, 15, 17, 18, 11, 15, 18, 19,
+ 19, 11, 15, 18, 19, 19, 11, 16,
+ 18, 19, 11, 15, 18, 19, 11, 16,
+ 18, 12, 16, 18, 19, 12, 16, 19,
+ 12, 16, 19, 19, 19, 12, 16, 19,
+ 12, 16, 19, 19, 12, 16, 18, 12,
+ 16, 19, 12, 17, 19, 12, 17, 19,
+ 12, 17, 19, 12, 17, 19, 13, 17,
+ 13, 17, 13, 17, 19, 19, 13, 17,
+ 13, 17, 19, 13, 17, 13, 18, 19,
+ 13, 17, 19, 13, 18, 13, 17, 13,
+ 18, 13, 18, 13, 18, 13, 18, 13,
+ 18, 13, 18, 14, 18, 19, 14, 18,
+ 14, 18, 14, 18, 14, 18, 14, 19,
+ 14, 19, 14, 18, 14, 18, 14, 18,
+ 14, 19, 14, 14, 18, 14, 14, 19,
+ 14, 18, 14, 19, 14, 19, 14, 15,
+ 19, 15, 15, 15, 15, 19, 15, 19,
+ 15, 15, 19, 15, 15, 19, 15, 19,
+ 15, 19, 15, 19, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 16,
+ 15, 15, 15, 16, 16, 16, 15, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 17, 16, 16, 16, 17,
+ 17, 16, 17, 17, 16, 17, 17, 17,
+ 17, 17, 17, 17, 17, 17, 17, 17,
+ 17, 17, 17, 17, 17, 17, 17, 18,
+ 17, 17, 17, 17, 17, 17, 17, 17,
+ 18, 17, 17, 18, 17, 17, 17, 17,
+ 18, 18, 17, 17, 17, 17, 17, 17,
+ 17, 18, 17, 18, 18, 17, 17, 17,
+ 18, 18, 18, 17, 18, 17, 18, 18,
+ 18, 18, 18, 18, 18, 18, 18, 17,
+ 18, 18, 18, 18, 19, 18, 18, 18,
+ 18, 18, 18, 18, 18, 18, 18, 18,
+ 18, 18, 18, 18, 18, 18, 18, 19,
+ 18, 18, 19, 18, 18, 18, 19, 18,
+ 19, 18, 18, 19, 18, 18, 19, 19,
+ 19, 19, 19, 18, 19, 18, 19, 18,
+ 19, 19, 18, 18, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 18, 19,
+ 19, 19, 19, 19, 18, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 20,
+ 19, 19, 19, 19, 21, 19, 19, 20,
+ 19, 20, 19, 19, 19, 19, 19, 20,
+ 20, 20, 19, 19, 19, 20, 19, 19,
+ 19, 20, 20, 19, 20, 19, 19, 21,
+ 20, 20, 19, 19, 19, 19, 19, 19,
+ 20, 19, 20, 20, 20, 20, 20, 20,
+ 20, 19, 19, 21, 20, 20, 19, 19,
+};
+
+static const uint32_t coef3_huffcodes[1072] = {
+ 0x001b2, 0x00069, 0x00000, 0x00004, 0x00006, 0x0000e, 0x00014, 0x00019,
+ 0x00016, 0x0002b, 0x00030, 0x0003d, 0x0003c, 0x0005a, 0x0005f, 0x0006d,
+ 0x0007e, 0x0005f, 0x0007f, 0x000b6, 0x000bc, 0x000d8, 0x000f2, 0x000fe,
+ 0x000bc, 0x000fc, 0x00161, 0x0016e, 0x00174, 0x00176, 0x001a2, 0x001e3,
+ 0x001f3, 0x00174, 0x0017a, 0x001ea, 0x002a8, 0x002c4, 0x002e6, 0x00314,
+ 0x00346, 0x00367, 0x003e9, 0x002e5, 0x002ee, 0x003d6, 0x00555, 0x00554,
+ 0x00557, 0x005c3, 0x005d6, 0x006e0, 0x0062f, 0x006e2, 0x00799, 0x00789,
+ 0x007fa, 0x005ce, 0x007fe, 0x005ec, 0x007cc, 0x007af, 0x00aa7, 0x00b19,
+ 0x00b94, 0x00b85, 0x00b9f, 0x00c48, 0x00c45, 0x00dd8, 0x00c4c, 0x00c4b,
+ 0x00d99, 0x00d1f, 0x00dc2, 0x00f95, 0x00fa2, 0x00bb5, 0x00b9f, 0x00f5d,
+ 0x00bbf, 0x00f47, 0x0154a, 0x00fd5, 0x00f45, 0x00f7f, 0x0160d, 0x01889,
+ 0x01757, 0x01722, 0x018b3, 0x0172d, 0x01a39, 0x01a18, 0x01bb3, 0x01b30,
+ 0x01e63, 0x0173c, 0x01b35, 0x01723, 0x01e80, 0x01fee, 0x01761, 0x01ffc,
+ 0x01f7f, 0x02c7c, 0x01fa1, 0x0177b, 0x01755, 0x0175a, 0x01fa6, 0x02eab,
+ 0x0310a, 0x02c69, 0x03669, 0x03127, 0x03103, 0x02e43, 0x03662, 0x03165,
+ 0x03124, 0x0313b, 0x03111, 0x03668, 0x0343b, 0x03c52, 0x03efc, 0x02e6c,
+ 0x03fda, 0x03ef8, 0x02e7b, 0x03ee2, 0x03cc5, 0x03d72, 0x058c0, 0x03df8,
+ 0x02ea9, 0x03e7e, 0x0556d, 0x05c82, 0x03d71, 0x03e7b, 0x03c42, 0x058d7,
+ 0x03f4e, 0x06200, 0x03d70, 0x05cb2, 0x05c96, 0x05cb0, 0x03f45, 0x05cb1,
+ 0x02e6d, 0x03110, 0x02f68, 0x05c90, 0x07ca6, 0x07c88, 0x06204, 0x062c8,
+ 0x078a6, 0x07986, 0x079d5, 0x0b1ad, 0x07989, 0x0b079, 0x05cdd, 0x0aad4,
+ 0x05de8, 0x07dcd, 0x07987, 0x05d67, 0x05d99, 0x0b91d, 0x07cf1, 0x05d9b,
+ 0x079d7, 0x0b07b, 0x05c85, 0x05d9a, 0x07dcc, 0x07ebf, 0x07dce, 0x07dfb,
+ 0x07ec0, 0x07d1a, 0x07a07, 0x05c84, 0x0c471, 0x07cf2, 0x0baef, 0x0b9d2,
+ 0x05deb, 0x07bd6, 0x0b845, 0x05d98, 0x0b91a, 0x0bae8, 0x0c4e0, 0x0dc31,
+ 0x0f93d, 0x0bbce, 0x0d1d2, 0x0f7a9, 0x0d9b9, 0x0bbcb, 0x0b900, 0x0aad7,
+ 0x0babd, 0x0c4e1, 0x0f46f, 0x0c588, 0x0c58b, 0x160e6, 0x0bbcf, 0x0bac3,
+ 0x0f945, 0x0f7a3, 0x0d1c1, 0x0fb8e, 0x0f7a4, 0x0fb8c, 0x0f40c, 0x0c473,
+ 0x0fd72, 0x0bbcd, 0x0fffa, 0x0f940, 0x0bbc9, 0x0f7a8, 0x1a1ed, 0x0bbc5,
+ 0x1f26f, 0x163fd, 0x160c7, 0x1a1f5, 0x0f947, 0x163fc, 0x154b3, 0x0fff6,
+ 0x163f6, 0x160e9, 0x1a1f0, 0x0bab9, 0x0baba, 0x17086, 0x0b903, 0x0fd75,
+ 0x0f308, 0x176f3, 0x163ff, 0x0fd7d, 0x1bb78, 0x163fb, 0x188db, 0x1a1f7,
+ 0x154b2, 0x172fd, 0x163f4, 0x1bb73, 0x172ff, 0x0babc, 0x0f97d, 0x1a1f3,
+ 0x1bb6d, 0x1ffd5, 0x1a1f4, 0x1f272, 0x17380, 0x17382, 0x1ffe7, 0x0bac8,
+ 0x0bbc4, 0x188d3, 0x160e0, 0x0fd7b, 0x1725f, 0x172f5, 0x1bb79, 0x1fad9,
+ 0x1f269, 0x188d0, 0x0bac4, 0x0bac5, 0x31185, 0x188d2, 0x188cc, 0x31187,
+ 0x3e7fe, 0x188d1, 0x1bb6c, 0x1f268, 0x1fad2, 0x1ffd9, 0x1a1ea, 0x1bb68,
+ 0x1facb, 0x3fdb2, 0x1e81a, 0x188ce, 0x172fb, 0x1a1ef, 0x1face, 0x1bb70,
+ 0x0bac1, 0x1bb6b, 0x172f8, 0x1bb66, 0x1ffdf, 0x1bb6a, 0x1ffd7, 0x1f266,
+ 0x176f8, 0x37653, 0x1fa7e, 0x31182, 0x1fac8, 0x2c7e3, 0x370ee, 0x176ec,
+ 0x176e9, 0x2e4bc, 0x160c5, 0x3765a, 0x3ce9c, 0x17373, 0x176e8, 0x188d4,
+ 0x176f1, 0x176ef, 0x37659, 0x1bb7c, 0x1ffde, 0x176f2, 0x3118b, 0x2c7d4,
+ 0x37651, 0x5ce9f, 0x37650, 0x31191, 0x3f4f6, 0x3f4f5, 0x7a06c, 0x1fac1,
+ 0x5c97b, 0x2c7e0, 0x79d3a, 0x3e7fd, 0x2c7df, 0x3f4f0, 0x7a06d, 0x376c1,
+ 0x79d3b, 0x00004, 0x00014, 0x00059, 0x000ab, 0x000b8, 0x00177, 0x001f5,
+ 0x001f2, 0x00315, 0x003fc, 0x005bd, 0x0062d, 0x006e8, 0x007dd, 0x00b04,
+ 0x007cd, 0x00b1e, 0x00d1e, 0x00f15, 0x00f3b, 0x00f41, 0x01548, 0x018b0,
+ 0x0173b, 0x01884, 0x01a1c, 0x01bb4, 0x01f25, 0x017b5, 0x0176d, 0x01ef8,
+ 0x02e73, 0x03107, 0x03125, 0x03105, 0x02e49, 0x03ce8, 0x03ef9, 0x03e5e,
+ 0x02e72, 0x03471, 0x03fd9, 0x0623f, 0x078a0, 0x06867, 0x05cb3, 0x06272,
+ 0x068ec, 0x06e9a, 0x079d4, 0x06e98, 0x0b1aa, 0x06e1a, 0x07985, 0x068ee,
+ 0x06e9b, 0x05c88, 0x0b1ac, 0x07dfa, 0x05d65, 0x07cf0, 0x07cbf, 0x0c475,
+ 0x160eb, 0x1bb7e, 0x0f7a6, 0x1fedd, 0x160e3, 0x0fffb, 0x0fb8d, 0x0fff9,
+ 0x0d1c0, 0x0c58c, 0x1a1e9, 0x0bab8, 0x0f5cf, 0x0fff5, 0x376c5, 0x1a1ec,
+ 0x160ed, 0x1fede, 0x1fac9, 0x1a1eb, 0x1f224, 0x176ee, 0x0fd79, 0x17080,
+ 0x17387, 0x1bb7a, 0x1ffe9, 0x176f7, 0x17385, 0x17781, 0x2c7d5, 0x17785,
+ 0x1ffe3, 0x163f5, 0x1fac2, 0x3e7f9, 0x3118d, 0x3fdb1, 0x1ffe2, 0x1f226,
+ 0x3118a, 0x2c7d9, 0x31190, 0x3118c, 0x3f4f3, 0x1bb7f, 0x1bb72, 0x31184,
+ 0xb92f4, 0x3e7fb, 0x6e1d9, 0x1faca, 0x62300, 0x3fdb8, 0x3d037, 0x3e7fc,
+ 0x62301, 0x3f4f2, 0x1f26a, 0x0000e, 0x00063, 0x000f8, 0x001ee, 0x00377,
+ 0x003f7, 0x006e3, 0x005cc, 0x00b05, 0x00dd2, 0x00fd4, 0x0172e, 0x0172a,
+ 0x01e23, 0x01f2d, 0x01763, 0x01769, 0x0176c, 0x02e75, 0x03104, 0x02ec1,
+ 0x03e58, 0x0583f, 0x03f62, 0x03f44, 0x058c5, 0x0623c, 0x05cf4, 0x07bd7,
+ 0x05d9d, 0x0aad2, 0x05d66, 0x0b1a9, 0x0b078, 0x07cfe, 0x0b918, 0x0c46f,
+ 0x0b919, 0x0b847, 0x06e1b, 0x0b84b, 0x0aad8, 0x0fd74, 0x172f4, 0x17081,
+ 0x0f97c, 0x1f273, 0x0f7a0, 0x0fd7c, 0x172f7, 0x0fd7a, 0x1bb77, 0x172fe,
+ 0x1f270, 0x0fd73, 0x1bb7b, 0x1a1bc, 0x1bb7d, 0x0bbc3, 0x172f6, 0x0baeb,
+ 0x0fb8f, 0x3f4f4, 0x3fdb4, 0x376c8, 0x3e7fa, 0x1ffd0, 0x62303, 0xb92f5,
+ 0x1f261, 0x31189, 0x3fdb5, 0x2c7db, 0x376c9, 0x1fad6, 0x1fad1, 0x00015,
+ 0x000f0, 0x002e0, 0x0058e, 0x005d7, 0x00c4d, 0x00fa1, 0x00bdb, 0x01756,
+ 0x01f70, 0x02c19, 0x0313c, 0x0370f, 0x03cc0, 0x02ea8, 0x058c6, 0x058c7,
+ 0x02eb7, 0x058d0, 0x07d18, 0x0aa58, 0x0b848, 0x05d9e, 0x05d6c, 0x0b84c,
+ 0x0c589, 0x0b901, 0x163f8, 0x0bac9, 0x0b9c5, 0x0f93c, 0x188d8, 0x0bbc7,
+ 0x160ec, 0x0fd6f, 0x188d9, 0x160ea, 0x0f7a7, 0x0f944, 0x0baab, 0x0dc3a,
+ 0x188cf, 0x176fb, 0x2c7d8, 0x2c7d7, 0x1bb75, 0x5ce9e, 0x62302, 0x370ed,
+ 0x176f4, 0x1ffd1, 0x370ef, 0x3f4f8, 0x376c7, 0x1ffe1, 0x376c6, 0x176ff,
+ 0x6e1d8, 0x176f6, 0x17087, 0x0f5cd, 0x00035, 0x001a0, 0x0058b, 0x00aac,
+ 0x00b9a, 0x0175f, 0x01e22, 0x01e8c, 0x01fb2, 0x0310b, 0x058d1, 0x0552e,
+ 0x05c27, 0x0686e, 0x07ca7, 0x0c474, 0x0dc33, 0x07bf2, 0x05de9, 0x07a35,
+ 0x0baaa, 0x0b9eb, 0x0fb95, 0x0b9b8, 0x17381, 0x1f262, 0x188cd, 0x17088,
+ 0x172fa, 0x0f7a2, 0x1fad3, 0x0bac0, 0x3765c, 0x1fedf, 0x1f225, 0x1fad4,
+ 0x2c7da, 0x5ce9d, 0x3e7f8, 0x1e203, 0x188d7, 0x00054, 0x002c0, 0x007a1,
+ 0x00f78, 0x01b36, 0x01fa3, 0x0313a, 0x03436, 0x0343a, 0x07d1d, 0x07bd8,
+ 0x05cdf, 0x0b846, 0x0b189, 0x0d9b8, 0x0fff8, 0x0d9be, 0x0c58a, 0x05dea,
+ 0x0d1d3, 0x160e4, 0x1f26b, 0x188da, 0x1e202, 0x2c7d2, 0x163fe, 0x31193,
+ 0x17782, 0x376c2, 0x2c7d1, 0x3fdb0, 0x3765d, 0x2c7d0, 0x1fad0, 0x1e201,
+ 0x188dd, 0x2c7e2, 0x37657, 0x37655, 0x376c4, 0x376c0, 0x176ea, 0x0006f,
+ 0x003cf, 0x00dd5, 0x01f23, 0x02c61, 0x02ed0, 0x05d54, 0x0552d, 0x07883,
+ 0x0b1a8, 0x0b91c, 0x0babf, 0x0b902, 0x0f7aa, 0x0f7a5, 0x1a1e8, 0x1ffd6,
+ 0x0babe, 0x1a1bf, 0x163f3, 0x1ffd8, 0x1fad7, 0x1f275, 0x1ffdc, 0x0007d,
+ 0x005bc, 0x01549, 0x02a99, 0x03def, 0x06273, 0x079d6, 0x07d1b, 0x0aad3,
+ 0x0d0fc, 0x2c7dd, 0x188d6, 0x0bac2, 0x2c7e1, 0x1bb76, 0x1a1bd, 0x31186,
+ 0x0fd78, 0x1a1be, 0x31183, 0x3fdb6, 0x3f4f1, 0x37652, 0x1fad5, 0x3f4f9,
+ 0x3e7ff, 0x5ce9c, 0x3765b, 0x31188, 0x17372, 0x000bd, 0x0078b, 0x01f21,
+ 0x03c43, 0x03ded, 0x0aad6, 0x07ec1, 0x0f942, 0x05c86, 0x17089, 0x0babb,
+ 0x1ffe8, 0x2c7de, 0x1f26e, 0x1fac4, 0x3f4f7, 0x37656, 0x1fa7d, 0x376c3,
+ 0x3fdb3, 0x3118f, 0x1fac6, 0x000f8, 0x007ed, 0x01efd, 0x03e7a, 0x05c91,
+ 0x0aad9, 0x0baec, 0x0dc32, 0x0f46e, 0x1e200, 0x176fa, 0x3765e, 0x3fdb7,
+ 0x2c7d6, 0x3fdb9, 0x37654, 0x37658, 0x3118e, 0x1ffdb, 0x000f6, 0x00c43,
+ 0x03106, 0x068ef, 0x0b84d, 0x0b188, 0x0bbcc, 0x1f264, 0x1bb69, 0x17386,
+ 0x1fac0, 0x00171, 0x00f39, 0x03e41, 0x068ed, 0x0d9bc, 0x0f7a1, 0x1bb67,
+ 0x1ffdd, 0x176f9, 0x001b9, 0x00f7d, 0x03f63, 0x0d0fd, 0x0b9ea, 0x188dc,
+ 0x1fac3, 0x1a1f2, 0x31192, 0x1ffe4, 0x001f6, 0x01754, 0x06865, 0x0f309,
+ 0x160e5, 0x176f5, 0x3765f, 0x1facc, 0x001e9, 0x01a1a, 0x06201, 0x0f105,
+ 0x176f0, 0x002df, 0x01756, 0x05d6d, 0x163fa, 0x176ed, 0x00342, 0x02e40,
+ 0x0d0ff, 0x17082, 0x003cd, 0x02a98, 0x0fffc, 0x2c7dc, 0x1fa7f, 0x003fe,
+ 0x03764, 0x0fffd, 0x176fc, 0x1fac5, 0x002f7, 0x02ed1, 0x0fb97, 0x0058a,
+ 0x02edc, 0x0bbc8, 0x005d4, 0x0623d, 0x160e8, 0x0062e, 0x05830, 0x163f9,
+ 0x006eb, 0x06205, 0x1f274, 0x007de, 0x062c9, 0x1f265, 0x005c9, 0x05cde,
+ 0x1ffd3, 0x005d4, 0x07988, 0x007ce, 0x0b849, 0x00b1b, 0x05c89, 0x1fac7,
+ 0x00b93, 0x05c83, 0x00b9e, 0x0f14f, 0x00c4a, 0x0b9c7, 0x00dd4, 0x0c470,
+ 0x1f271, 0x00f38, 0x0fb96, 0x176eb, 0x00fa0, 0x163f7, 0x00bb2, 0x0b91b,
+ 0x00bbe, 0x0f102, 0x00f44, 0x0f946, 0x1facd, 0x00f79, 0x0d9bd, 0x0154d,
+ 0x0bbc6, 0x00fd2, 0x160e7, 0x0172b, 0x188cb, 0x0175e, 0x0fd76, 0x0175c,
+ 0x1bb71, 0x0189f, 0x1a1ee, 0x01f24, 0x1a1f6, 0x01ba7, 0x0bbca, 0x01f7d,
+ 0x0ffff, 0x01f2e, 0x1bb65, 0x01bb5, 0x172f9, 0x01fef, 0x1f26c, 0x01f3e,
+ 0x0fd77, 0x01762, 0x1bb6e, 0x01ef9, 0x172fc, 0x01fa0, 0x02ab7, 0x02e4a,
+ 0x1f267, 0x01fb3, 0x1ffda, 0x02e42, 0x03101, 0x17780, 0x0313d, 0x03475,
+ 0x17784, 0x03126, 0x1facf, 0x03c51, 0x17783, 0x03e40, 0x1ffe5, 0x03663,
+ 0x1ffe0, 0x03e8f, 0x1f26d, 0x0343c, 0x03cc1, 0x176fd, 0x03e45, 0x02ec0,
+ 0x03f61, 0x03dee, 0x03fd8, 0x0583e, 0x02e45, 0x03e59, 0x03d02, 0x05ce8,
+ 0x05568, 0x176fe, 0x02f69, 0x1fad8, 0x058c1, 0x05c83, 0x1ffe6, 0x06271,
+ 0x06e1c, 0x062c7, 0x068e1, 0x0552f, 0x06864, 0x06866, 0x06e99, 0x05cbc,
+ 0x07ca5, 0x078a1, 0x05c82, 0x07dcf, 0x0623b, 0x0623e, 0x068e8, 0x07a36,
+ 0x05d9c, 0x0b077, 0x07cf3, 0x07a34, 0x07ca4, 0x07d19, 0x079d2, 0x07d1c,
+ 0x07bd9, 0x0b84a, 0x0fb94, 0x0aad5, 0x0dc30, 0x07bf3, 0x0baee, 0x0b07a,
+ 0x0c472, 0x0b91e, 0x0d9ba, 0x05d9f, 0x0d0fe, 0x0b9c6, 0x05c87, 0x0f14e,
+ 0x0baed, 0x0b92e, 0x0f103, 0x0b9c4, 0x0fb91, 0x0d9bb, 0x0b1ab, 0x0c58d,
+ 0x0fffe, 0x0f93b, 0x0f941, 0x0baea, 0x0b91f, 0x0f5cc, 0x0d9bf, 0x0f943,
+ 0x0f104, 0x1f260, 0x0fb92, 0x0f93f, 0x0f3a6, 0x0bac7, 0x0f7ab, 0x0bac6,
+ 0x17383, 0x0fd6d, 0x0bae9, 0x0fd6e, 0x1e74f, 0x188ca, 0x1f227, 0x0fb93,
+ 0x0fb90, 0x0fff7, 0x17085, 0x17083, 0x160e1, 0x17084, 0x0f93e, 0x160e2,
+ 0x160c6, 0x1a1f1, 0x1bb6f, 0x17384, 0x0fd70, 0x1f263, 0x188d5, 0x173a6,
+ 0x0f5ce, 0x163f2, 0x0fd71, 0x1ffd2, 0x160c4, 0x1ffd4, 0x2c7d3, 0x1bb74,
+};
+
+static const uint8_t coef3_huffbits[1072] = {
+ 9, 7, 2, 3, 4, 4, 5, 5,
+ 6, 6, 6, 6, 7, 7, 7, 7,
+ 7, 8, 8, 8, 8, 8, 8, 8,
+ 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 11, 11, 11, 11, 11,
+ 11, 11, 11, 11, 11, 11, 11, 11,
+ 11, 12, 11, 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, 14, 13, 14, 14, 13, 14, 13,
+ 13, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 15,
+ 14, 14, 15, 14, 14, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 14, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 14, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 16, 15, 16, 16, 16,
+ 16, 15, 15, 16, 16, 16, 16, 16,
+ 15, 16, 16, 16, 15, 16, 15, 15,
+ 16, 15, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 17, 16, 17, 16, 17, 17, 16,
+ 17, 16, 17, 16, 16, 17, 17, 17,
+ 16, 17, 16, 16, 17, 16, 17, 16,
+ 17, 17, 16, 16, 17, 17, 17, 17,
+ 17, 17, 17, 17, 16, 17, 17, 16,
+ 17, 17, 17, 17, 17, 17, 17, 17,
+ 16, 18, 17, 17, 17, 17, 17, 17,
+ 17, 17, 17, 17, 17, 17, 16, 17,
+ 17, 17, 17, 17, 17, 17, 17, 17,
+ 17, 17, 17, 17, 17, 17, 17, 18,
+ 17, 17, 17, 17, 18, 17, 17, 18,
+ 19, 17, 17, 17, 18, 17, 17, 17,
+ 18, 18, 18, 17, 17, 17, 18, 17,
+ 17, 17, 17, 17, 17, 17, 17, 17,
+ 18, 18, 18, 18, 18, 18, 18, 18,
+ 18, 18, 17, 18, 18, 18, 18, 17,
+ 18, 18, 18, 17, 17, 18, 18, 18,
+ 18, 19, 18, 18, 19, 19, 20, 18,
+ 19, 18, 19, 19, 18, 19, 20, 18,
+ 19, 4, 6, 7, 8, 9, 9, 9,
+ 10, 10, 10, 11, 11, 11, 11, 12,
+ 12, 12, 12, 12, 12, 13, 13, 13,
+ 13, 13, 13, 13, 13, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 16, 15, 15, 15,
+ 15, 16, 16, 15, 16, 16, 15, 16,
+ 17, 17, 17, 17, 17, 16, 16, 16,
+ 16, 16, 17, 17, 17, 16, 18, 17,
+ 17, 17, 18, 17, 17, 18, 17, 17,
+ 17, 17, 17, 18, 17, 18, 18, 18,
+ 17, 17, 18, 19, 18, 18, 17, 17,
+ 18, 18, 18, 18, 19, 17, 17, 18,
+ 20, 19, 19, 18, 19, 18, 19, 19,
+ 19, 19, 17, 5, 7, 9, 10, 10,
+ 11, 11, 12, 12, 12, 13, 13, 13,
+ 13, 13, 14, 14, 14, 14, 14, 15,
+ 14, 15, 15, 15, 15, 15, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 15, 16, 16, 17, 17, 17,
+ 16, 17, 17, 17, 17, 17, 17, 17,
+ 17, 17, 17, 17, 17, 17, 17, 16,
+ 16, 19, 18, 18, 19, 17, 19, 20,
+ 17, 18, 18, 18, 18, 18, 18, 6,
+ 8, 10, 11, 12, 12, 12, 13, 13,
+ 13, 14, 14, 14, 14, 15, 15, 15,
+ 15, 15, 15, 16, 16, 16, 16, 16,
+ 16, 17, 17, 17, 16, 16, 17, 17,
+ 17, 17, 17, 17, 17, 16, 16, 16,
+ 17, 18, 18, 18, 17, 19, 19, 18,
+ 18, 17, 18, 19, 18, 17, 18, 18,
+ 19, 18, 17, 17, 6, 9, 11, 12,
+ 13, 13, 13, 14, 14, 14, 15, 15,
+ 15, 15, 15, 16, 16, 16, 16, 16,
+ 16, 17, 16, 17, 17, 17, 17, 17,
+ 17, 17, 18, 17, 18, 17, 17, 18,
+ 18, 19, 19, 17, 17, 7, 10, 12,
+ 13, 13, 14, 14, 14, 14, 15, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 17, 17, 17, 17, 18, 17, 18,
+ 18, 18, 18, 18, 18, 18, 18, 17,
+ 17, 18, 18, 18, 18, 18, 18, 7,
+ 10, 12, 13, 14, 15, 15, 15, 15,
+ 16, 16, 17, 17, 17, 17, 17, 17,
+ 17, 17, 17, 17, 18, 17, 17, 8,
+ 11, 13, 14, 15, 15, 15, 15, 16,
+ 16, 18, 17, 17, 18, 17, 17, 18,
+ 17, 17, 18, 18, 19, 18, 18, 19,
+ 19, 19, 18, 18, 18, 8, 11, 13,
+ 14, 15, 16, 16, 16, 16, 17, 17,
+ 17, 18, 17, 18, 19, 18, 18, 18,
+ 18, 18, 18, 8, 12, 14, 15, 15,
+ 16, 16, 16, 17, 17, 18, 18, 18,
+ 18, 18, 18, 18, 18, 17, 9, 12,
+ 14, 15, 16, 16, 17, 17, 17, 17,
+ 18, 9, 12, 14, 15, 16, 17, 17,
+ 17, 18, 9, 13, 15, 16, 17, 17,
+ 18, 17, 18, 17, 9, 13, 15, 16,
+ 17, 18, 18, 18, 10, 13, 15, 16,
+ 18, 10, 14, 16, 17, 18, 10, 14,
+ 16, 17, 10, 14, 16, 18, 18, 10,
+ 14, 16, 18, 18, 11, 15, 16, 11,
+ 15, 17, 11, 15, 17, 11, 15, 17,
+ 11, 15, 17, 11, 15, 17, 12, 16,
+ 17, 12, 15, 12, 16, 12, 16, 18,
+ 12, 16, 12, 16, 12, 16, 12, 16,
+ 17, 12, 16, 18, 12, 17, 13, 16,
+ 13, 16, 13, 16, 18, 13, 16, 13,
+ 17, 13, 17, 13, 17, 13, 17, 13,
+ 17, 13, 17, 13, 17, 13, 17, 13,
+ 16, 13, 17, 13, 17, 13, 17, 14,
+ 17, 14, 17, 14, 17, 14, 14, 14,
+ 17, 14, 17, 14, 14, 18, 14, 14,
+ 18, 14, 18, 14, 18, 14, 17, 14,
+ 17, 14, 17, 14, 14, 18, 14, 15,
+ 15, 15, 14, 15, 15, 14, 15, 15,
+ 15, 18, 15, 18, 15, 15, 17, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 16, 15, 15, 15, 15, 16,
+ 16, 16, 16, 16, 15, 15, 15, 15,
+ 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 17, 16, 16,
+ 16, 17, 16, 16, 16, 17, 17, 17,
+ 17, 17, 16, 17, 17, 17, 17, 16,
+ 16, 16, 17, 17, 17, 17, 16, 17,
+ 17, 17, 17, 17, 17, 17, 17, 17,
+ 17, 17, 17, 17, 17, 17, 18, 17,
+};
+
+static const uint32_t coef4_huffcodes[476] = {
+ 0x00f01, 0x0001e, 0x00000, 0x00004, 0x00006, 0x0000d, 0x0000a, 0x00017,
+ 0x0001d, 0x00017, 0x0002c, 0x00031, 0x00039, 0x0003e, 0x00039, 0x0005a,
+ 0x00066, 0x00070, 0x0007b, 0x00070, 0x00077, 0x000af, 0x000c9, 0x000f2,
+ 0x000f4, 0x000b2, 0x000e3, 0x0015b, 0x0015d, 0x00181, 0x0019d, 0x001e3,
+ 0x001c5, 0x002b5, 0x002db, 0x00338, 0x003c3, 0x003cc, 0x003f0, 0x002cd,
+ 0x003fa, 0x003a1, 0x005b4, 0x00657, 0x007ab, 0x0074d, 0x0074c, 0x00ac1,
+ 0x00ac5, 0x0076b, 0x00ca8, 0x00f04, 0x00f00, 0x00fe3, 0x00f3c, 0x00f10,
+ 0x00f39, 0x00fe6, 0x00e26, 0x00e90, 0x016c5, 0x01827, 0x01954, 0x015c5,
+ 0x01958, 0x01f8a, 0x01c4a, 0x02b0f, 0x02b41, 0x02b0e, 0x033c6, 0x03050,
+ 0x01c4f, 0x02d88, 0x0305c, 0x03c18, 0x02b4f, 0x02cc2, 0x03a47, 0x05680,
+ 0x0569d, 0x06442, 0x06443, 0x06446, 0x0656e, 0x06444, 0x07120, 0x0748a,
+ 0x0c1ba, 0x07e22, 0x07aa6, 0x07f25, 0x07aa7, 0x07e20, 0x0c11b, 0x0c118,
+ 0x07aa5, 0x0ad0a, 0x0f389, 0x19ebb, 0x0caad, 0x0fe42, 0x0fe40, 0x16c34,
+ 0x2b4e5, 0x33d65, 0x16c30, 0x1e7ae, 0x1e25c, 0x18370, 0x1e703, 0x19eba,
+ 0x16c37, 0x0e234, 0x16c6e, 0x00004, 0x0002a, 0x00061, 0x00075, 0x000cb,
+ 0x000ff, 0x00190, 0x001eb, 0x001d1, 0x002b9, 0x00307, 0x00339, 0x0033f,
+ 0x003fb, 0x003b4, 0x0060c, 0x00679, 0x00645, 0x0067d, 0x0078a, 0x007e3,
+ 0x00749, 0x00ac4, 0x00ad2, 0x00ae3, 0x00c10, 0x00c16, 0x00ad1, 0x00cf4,
+ 0x00fe2, 0x01586, 0x00e9d, 0x019f1, 0x01664, 0x01e26, 0x01d38, 0x02b4d,
+ 0x033c5, 0x01fc2, 0x01fc3, 0x01d28, 0x03c1d, 0x0598e, 0x0f094, 0x07aa4,
+ 0x0ad38, 0x0ac0c, 0x0c11a, 0x079ea, 0x0c881, 0x0fe44, 0x0b635, 0x0ac0d,
+ 0x0b61e, 0x05987, 0x07121, 0x0f382, 0x0f387, 0x0e237, 0x0fe47, 0x0f383,
+ 0x0f091, 0x0f385, 0x0e233, 0x182ee, 0x19eb8, 0x1663e, 0x0f093, 0x00014,
+ 0x00058, 0x00159, 0x00167, 0x00300, 0x003d4, 0x005b5, 0x0079d, 0x0076a,
+ 0x00b67, 0x00b60, 0x00f05, 0x00cf0, 0x00f17, 0x00e95, 0x01822, 0x01913,
+ 0x016c2, 0x0182f, 0x01959, 0x01fcb, 0x01e27, 0x01c40, 0x033c7, 0x01e7b,
+ 0x01c49, 0x02d89, 0x01e23, 0x01660, 0x03f12, 0x02cc6, 0x033e1, 0x05b34,
+ 0x0609a, 0x06569, 0x07488, 0x07e21, 0x0cf5f, 0x0712c, 0x0389d, 0x067cf,
+ 0x07f28, 0x1663f, 0x33d67, 0x1663d, 0x1e25d, 0x3c1ab, 0x15c44, 0x16c36,
+ 0x0001f, 0x000ec, 0x00323, 0x005b2, 0x0079f, 0x00ac2, 0x00f16, 0x00e9e,
+ 0x01956, 0x01e0f, 0x019ea, 0x01666, 0x02b89, 0x02b02, 0x02d8c, 0x03c1b,
+ 0x03c19, 0x032b5, 0x03f9c, 0x02ccf, 0x03897, 0x05b35, 0x0ad02, 0x07f29,
+ 0x06441, 0x03884, 0x07888, 0x0784e, 0x06568, 0x0c1bb, 0x05986, 0x067cc,
+ 0x0fe49, 0x0fe48, 0x0c1bc, 0x0fe41, 0x18371, 0x1663c, 0x0e231, 0x0711e,
+ 0x0ad09, 0x0f092, 0x0002d, 0x001db, 0x00781, 0x00c1a, 0x00f55, 0x01580,
+ 0x01ea8, 0x02d9b, 0x032af, 0x03f16, 0x03c1c, 0x07834, 0x03c45, 0x0389c,
+ 0x067ce, 0x06445, 0x0c1b9, 0x07889, 0x07f3a, 0x0784f, 0x07f2b, 0x0ad0b,
+ 0x0f090, 0x0c11d, 0x0e94e, 0x0711f, 0x0e9f1, 0x0f38e, 0x079e9, 0x0ad03,
+ 0x0f09b, 0x0caae, 0x0fe46, 0x2b4e6, 0x0e9f0, 0x19eb6, 0x67ac1, 0x67ac0,
+ 0x33d66, 0x0f388, 0x00071, 0x003a0, 0x00ca9, 0x01829, 0x01d39, 0x02b43,
+ 0x02cc4, 0x06554, 0x0f09a, 0x0b61f, 0x067cd, 0x0711c, 0x0b636, 0x07f2a,
+ 0x0b634, 0x0c11f, 0x0cf5e, 0x0b61d, 0x0f06b, 0x0caab, 0x0c1be, 0x0e94c,
+ 0x0f099, 0x182ed, 0x0e94f, 0x0c119, 0x0e232, 0x2b4e4, 0x0f38a, 0x19eb4,
+ 0x1e25f, 0x0e94d, 0x000b7, 0x00785, 0x016cc, 0x03051, 0x033c4, 0x0656f,
+ 0x03891, 0x0711d, 0x0caaf, 0x0f097, 0x07489, 0x0f098, 0x0c880, 0x0caaa,
+ 0x0f386, 0x19eb7, 0x16c6f, 0x0f384, 0x182e8, 0x182e9, 0x0e230, 0x1e700,
+ 0x33d62, 0x33d63, 0x33d64, 0x16c33, 0x0e216, 0x000fd, 0x00c15, 0x01665,
+ 0x03c4a, 0x07f3b, 0x07896, 0x0c11c, 0x0e215, 0x16c32, 0x0f38b, 0x0f38d,
+ 0x182ea, 0x1e701, 0x712df, 0x15c46, 0x00194, 0x00fe0, 0x03f13, 0x0748b,
+ 0x0f096, 0x0cf80, 0x1e25e, 0xe25bd, 0x33d61, 0x16c31, 0x001f9, 0x01912,
+ 0x05710, 0x0f3d0, 0x0c1bf, 0x00301, 0x01e24, 0x0ad08, 0x003cd, 0x01c41,
+ 0x0c1bd, 0x00563, 0x03a52, 0x0f3d1, 0x00570, 0x02cce, 0x0e217, 0x0067b,
+ 0x0655d, 0x0074b, 0x06447, 0x00c12, 0x074fb, 0x00f08, 0x0b61c, 0x00e22,
+ 0x0fe43, 0x016c7, 0x01836, 0x019f2, 0x01c43, 0x01d3f, 0x01fcf, 0x02b4c,
+ 0x0304c, 0x032b6, 0x03a46, 0x05607, 0x03f17, 0x02cc5, 0x0609b, 0x0655c,
+ 0x07e23, 0x067c1, 0x07f26, 0x07f27, 0x0f095, 0x0e9f3, 0x0cf81, 0x0c11e,
+ 0x0caac, 0x0f38f, 0x0e9f2, 0x074fa, 0x0e236, 0x0fe45, 0x1c428, 0x0e235,
+ 0x182ef, 0x19eb5, 0x0f3d6, 0x182ec, 0x16c35, 0x0f38c, 0x2b4e7, 0x15c47,
+ 0xe25bc, 0x1e702, 0x1c4b6, 0x0e25a, 0x3c1aa, 0x15c45, 0x1c429, 0x19eb9,
+ 0x1e7af, 0x182eb, 0x1e0d4, 0x3896e,
+};
+
+static const uint8_t coef4_huffbits[476] = {
+ 12, 6, 2, 3, 4, 4, 5, 5,
+ 5, 6, 6, 6, 6, 6, 7, 7,
+ 7, 7, 7, 8, 8, 8, 8, 8,
+ 8, 9, 9, 9, 9, 9, 9, 9,
+ 10, 10, 10, 10, 10, 10, 10, 11,
+ 10, 11, 11, 11, 11, 12, 12, 12,
+ 12, 12, 12, 12, 12, 12, 12, 12,
+ 12, 12, 13, 13, 13, 13, 13, 13,
+ 13, 13, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 16, 16,
+ 16, 15, 15, 15, 15, 15, 16, 16,
+ 15, 16, 16, 17, 16, 16, 16, 17,
+ 18, 18, 17, 17, 17, 17, 17, 17,
+ 17, 17, 17, 4, 6, 7, 8, 8,
+ 8, 9, 9, 10, 10, 10, 10, 10,
+ 10, 11, 11, 11, 11, 11, 11, 11,
+ 12, 12, 12, 12, 12, 12, 12, 12,
+ 12, 13, 13, 13, 14, 13, 14, 14,
+ 14, 13, 13, 14, 14, 16, 16, 15,
+ 16, 16, 16, 15, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 17, 16, 16,
+ 16, 16, 17, 17, 17, 18, 16, 5,
+ 8, 9, 10, 10, 10, 11, 11, 12,
+ 12, 12, 12, 12, 12, 13, 13, 13,
+ 13, 13, 13, 13, 13, 14, 14, 13,
+ 14, 14, 13, 14, 14, 15, 14, 15,
+ 15, 15, 16, 15, 16, 16, 15, 15,
+ 15, 18, 18, 18, 17, 18, 17, 17,
+ 6, 9, 10, 11, 11, 12, 12, 13,
+ 13, 13, 13, 14, 14, 14, 14, 14,
+ 14, 14, 14, 15, 15, 15, 16, 15,
+ 15, 15, 15, 15, 15, 16, 16, 15,
+ 16, 16, 16, 16, 17, 18, 17, 16,
+ 16, 16, 7, 10, 11, 12, 12, 13,
+ 13, 14, 14, 14, 14, 15, 14, 15,
+ 15, 15, 16, 15, 15, 15, 15, 16,
+ 16, 16, 17, 16, 17, 16, 15, 16,
+ 16, 16, 16, 18, 17, 17, 19, 19,
+ 18, 16, 7, 11, 12, 13, 14, 14,
+ 15, 15, 16, 16, 15, 16, 16, 15,
+ 16, 16, 16, 16, 16, 16, 16, 17,
+ 16, 17, 17, 16, 17, 18, 16, 17,
+ 17, 17, 8, 11, 13, 14, 14, 15,
+ 15, 16, 16, 16, 16, 16, 16, 16,
+ 16, 17, 17, 16, 17, 17, 17, 17,
+ 18, 18, 18, 17, 17, 8, 12, 14,
+ 14, 15, 15, 16, 17, 17, 16, 16,
+ 17, 17, 20, 17, 9, 12, 14, 16,
+ 16, 16, 17, 21, 18, 17, 9, 13,
+ 15, 16, 16, 10, 13, 16, 10, 14,
+ 16, 11, 15, 16, 11, 15, 17, 11,
+ 15, 12, 15, 12, 16, 12, 16, 13,
+ 16, 13, 13, 13, 14, 14, 13, 14,
+ 14, 14, 15, 15, 14, 15, 15, 15,
+ 15, 15, 15, 15, 16, 17, 16, 16,
+ 16, 16, 17, 16, 17, 16, 18, 17,
+ 17, 17, 16, 17, 17, 16, 18, 17,
+ 21, 17, 18, 17, 18, 17, 18, 17,
+ 17, 17, 17, 19,
+};
+
+static const uint32_t coef5_huffcodes[435] = {
+ 0x00347, 0x0000b, 0x00001, 0x00001, 0x0000c, 0x00004, 0x00010, 0x00015,
+ 0x0001f, 0x0000b, 0x00023, 0x00026, 0x00029, 0x00035, 0x00037, 0x00001,
+ 0x00015, 0x0001a, 0x0001d, 0x0001c, 0x0001e, 0x0004e, 0x00049, 0x00051,
+ 0x00078, 0x00004, 0x00000, 0x00008, 0x0000d, 0x0007b, 0x00005, 0x00032,
+ 0x00095, 0x00091, 0x00096, 0x000a1, 0x000d9, 0x00003, 0x00019, 0x00061,
+ 0x00066, 0x00060, 0x00017, 0x0000e, 0x00063, 0x001a0, 0x001b7, 0x001e6,
+ 0x001e7, 0x001b6, 0x00018, 0x001e8, 0x00038, 0x00031, 0x00005, 0x0003d,
+ 0x00027, 0x001ea, 0x0001a, 0x000c5, 0x000f9, 0x000ff, 0x000db, 0x00250,
+ 0x000fc, 0x0025c, 0x00008, 0x00075, 0x003d7, 0x003d3, 0x001b0, 0x0007c,
+ 0x003ca, 0x00036, 0x00189, 0x004a6, 0x004a2, 0x004fb, 0x000c0, 0x0007f,
+ 0x0009a, 0x00311, 0x0006e, 0x0009b, 0x0068c, 0x006c0, 0x00484, 0x00012,
+ 0x000c3, 0x0094f, 0x00979, 0x009f9, 0x00d09, 0x00da6, 0x00da8, 0x00901,
+ 0x000c1, 0x00373, 0x00d08, 0x009fa, 0x00d8b, 0x00d85, 0x00d86, 0x000df,
+ 0x006e2, 0x000ce, 0x00f24, 0x009fe, 0x001f7, 0x007c1, 0x000cf, 0x009fc,
+ 0x009ff, 0x00d89, 0x00da9, 0x009fd, 0x001f8, 0x01a36, 0x0128c, 0x0129d,
+ 0x01a37, 0x00196, 0x003ea, 0x00f8b, 0x00d93, 0x01e45, 0x01e58, 0x01e4b,
+ 0x01e59, 0x013f1, 0x00309, 0x00265, 0x00308, 0x0243a, 0x027e1, 0x00f89,
+ 0x00324, 0x03cbc, 0x03c86, 0x03695, 0x0243c, 0x0243b, 0x0243e, 0x01e4a,
+ 0x003a5, 0x03468, 0x03428, 0x03c84, 0x027e0, 0x025e2, 0x01880, 0x00197,
+ 0x00325, 0x03cb7, 0x0791e, 0x007ec, 0x06c75, 0x004c8, 0x04bc7, 0x004c6,
+ 0x00983, 0x0481e, 0x01b53, 0x0251b, 0x01b58, 0x00984, 0x04fa8, 0x03cbb,
+ 0x00f8a, 0x00322, 0x0346a, 0x0243d, 0x00326, 0x03469, 0x0481f, 0x0481d,
+ 0x00746, 0x09032, 0x01b50, 0x01d13, 0x0d8e4, 0x0481b, 0x06c74, 0x0796b,
+ 0x07969, 0x00985, 0x0d8e3, 0x00986, 0x00fa2, 0x01301, 0x06c7c, 0x00987,
+ 0x03cb8, 0x0f4af, 0x00e88, 0x1b1c0, 0x00fce, 0x033eb, 0x03f6a, 0x03f69,
+ 0x00fcf, 0x0791f, 0x004c9, 0x04871, 0x00fcd, 0x00982, 0x00fcc, 0x00fa3,
+ 0x01d12, 0x0796c, 0x01b47, 0x00321, 0x0796a, 0x0d8e2, 0x04872, 0x04873,
+ 0x0000e, 0x00014, 0x0000a, 0x000a0, 0x00012, 0x0007d, 0x001a2, 0x0003b,
+ 0x0025f, 0x000dd, 0x0027c, 0x00343, 0x00368, 0x0036b, 0x0003e, 0x001fa,
+ 0x00485, 0x001b3, 0x0007f, 0x001b1, 0x0019e, 0x004ba, 0x007ad, 0x00339,
+ 0x00066, 0x007a4, 0x00793, 0x006c6, 0x0007e, 0x000f1, 0x00372, 0x009fb,
+ 0x00d83, 0x00d8a, 0x00947, 0x009f4, 0x001d0, 0x01b09, 0x01b4b, 0x007ec,
+ 0x003e1, 0x000ca, 0x003ec, 0x02539, 0x04fa9, 0x01b57, 0x03429, 0x03d2a,
+ 0x00d97, 0x003a7, 0x00dc0, 0x00d96, 0x00dc1, 0x007eb, 0x03cba, 0x00c43,
+ 0x00c41, 0x01b52, 0x007ef, 0x00323, 0x03cb9, 0x03c83, 0x007d0, 0x007ed,
+ 0x06c7f, 0x09033, 0x03f6c, 0x36383, 0x1e95d, 0x06c78, 0x00747, 0x01b51,
+ 0x00022, 0x00016, 0x00039, 0x00252, 0x00079, 0x00486, 0x00338, 0x00369,
+ 0x00d88, 0x00026, 0x00d87, 0x00f4b, 0x00d82, 0x00027, 0x001e1, 0x01a15,
+ 0x007c7, 0x012f0, 0x001e0, 0x006d0, 0x01a16, 0x01e44, 0x01e5f, 0x03690,
+ 0x00d90, 0x00c42, 0x00daf, 0x00d92, 0x00f80, 0x00cfb, 0x0342f, 0x0487f,
+ 0x01b46, 0x07968, 0x00d95, 0x00d91, 0x01b55, 0x03f68, 0x04bc6, 0x03cbd,
+ 0x00f81, 0x00320, 0x00069, 0x000fe, 0x006d5, 0x0033f, 0x000de, 0x007c6,
+ 0x01e40, 0x00d94, 0x00f88, 0x03c8e, 0x03694, 0x00dae, 0x00dad, 0x00267,
+ 0x003a6, 0x00327, 0x0487e, 0x007ee, 0x00749, 0x004c7, 0x03692, 0x01b56,
+ 0x00fd1, 0x07a56, 0x06c77, 0x09031, 0x00748, 0x06c7a, 0x0796d, 0x033ea,
+ 0x06c76, 0x00fd0, 0x36382, 0x1e417, 0x00745, 0x04faf, 0x0d8e1, 0x03f6b,
+ 0x1e95c, 0x04fad, 0x0009e, 0x004bd, 0x0067c, 0x01b08, 0x003eb, 0x01b45,
+ 0x03691, 0x0d8e5, 0x07904, 0x00981, 0x007ea, 0x019f4, 0x06c7d, 0x04fab,
+ 0x04fac, 0x06c7e, 0x01300, 0x06c7b, 0x0006f, 0x003f7, 0x03c85, 0x004c4,
+ 0x0001e, 0x006e1, 0x03693, 0x01b44, 0x00241, 0x01e46, 0x0019d, 0x00266,
+ 0x004bb, 0x02538, 0x007ac, 0x01b54, 0x00902, 0x04870, 0x00da7, 0x00900,
+ 0x00185, 0x06c79, 0x006e3, 0x003e9, 0x01e94, 0x003ed, 0x003f2, 0x0342e,
+ 0x0346b, 0x0251a, 0x004c5, 0x01881, 0x0481c, 0x01b59, 0x03c87, 0x04fae,
+ 0x007e9, 0x03f6d, 0x0f20a, 0x09030, 0x04faa, 0x0d8e6, 0x03f6f, 0x0481a,
+ 0x03f6e, 0x1e416, 0x0d8e7,
+};
+
+static const uint8_t coef5_huffbits[435] = {
+ 10, 4, 2, 4, 4, 5, 5, 5,
+ 5, 6, 6, 6, 6, 6, 6, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 8, 8, 8, 8, 7, 8, 8,
+ 8, 8, 8, 8, 8, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 10, 9, 10, 10, 10, 10,
+ 10, 9, 10, 10, 10, 10, 10, 10,
+ 10, 10, 11, 11, 10, 10, 11, 11,
+ 10, 11, 11, 11, 11, 11, 12, 12,
+ 12, 12, 12, 12, 11, 11, 11, 12,
+ 12, 12, 12, 12, 12, 12, 12, 12,
+ 12, 12, 12, 12, 12, 12, 12, 13,
+ 13, 13, 12, 12, 13, 13, 13, 12,
+ 12, 12, 12, 12, 13, 13, 13, 13,
+ 13, 14, 14, 14, 14, 13, 13, 13,
+ 13, 13, 14, 14, 14, 14, 14, 14,
+ 15, 14, 14, 14, 14, 14, 14, 13,
+ 14, 14, 14, 14, 14, 14, 15, 14,
+ 15, 14, 15, 15, 15, 15, 15, 15,
+ 16, 15, 15, 14, 15, 16, 15, 14,
+ 14, 15, 14, 14, 15, 14, 15, 15,
+ 15, 16, 15, 17, 16, 15, 15, 15,
+ 15, 16, 16, 16, 16, 17, 15, 16,
+ 14, 16, 16, 17, 16, 16, 16, 16,
+ 16, 15, 15, 15, 16, 16, 16, 16,
+ 17, 15, 15, 15, 15, 16, 15, 15,
+ 4, 7, 8, 8, 9, 9, 9, 10,
+ 10, 10, 10, 10, 10, 10, 11, 11,
+ 11, 11, 11, 11, 11, 11, 11, 12,
+ 12, 11, 11, 11, 12, 12, 12, 12,
+ 12, 12, 12, 12, 13, 13, 13, 13,
+ 12, 13, 14, 14, 15, 15, 14, 14,
+ 14, 14, 14, 14, 14, 15, 14, 14,
+ 14, 15, 15, 15, 14, 14, 15, 15,
+ 15, 16, 16, 18, 17, 15, 15, 15,
+ 6, 9, 10, 10, 11, 11, 12, 12,
+ 12, 13, 12, 12, 12, 13, 13, 13,
+ 13, 13, 13, 13, 13, 13, 13, 14,
+ 14, 14, 14, 14, 14, 14, 14, 15,
+ 15, 15, 14, 14, 15, 16, 15, 14,
+ 14, 15, 7, 10, 11, 12, 13, 13,
+ 13, 14, 14, 14, 14, 14, 14, 14,
+ 14, 15, 15, 15, 15, 15, 14, 15,
+ 16, 15, 15, 16, 15, 15, 15, 16,
+ 15, 16, 18, 17, 15, 15, 16, 16,
+ 17, 15, 8, 11, 13, 13, 14, 15,
+ 14, 16, 15, 16, 15, 15, 15, 15,
+ 15, 15, 17, 15, 9, 12, 14, 15,
+ 10, 13, 14, 15, 10, 13, 11, 14,
+ 11, 14, 11, 15, 12, 15, 12, 12,
+ 13, 15, 13, 14, 13, 14, 14, 14,
+ 14, 14, 15, 15, 15, 15, 14, 15,
+ 15, 16, 16, 16, 15, 16, 16, 15,
+ 16, 17, 16,
+};
+
+static const uint16_t levels0[60] = {
+317, 92, 62, 60, 19, 17, 10, 7,
+ 6, 5, 5, 3, 3, 3, 2, 2,
+ 2, 2, 2, 2, 2, 1, 2, 2,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1,
+};
+
+static const uint16_t levels1[40] = {
+311, 91, 61, 28, 10, 6, 5, 2,
+ 2, 2, 2, 2, 2, 2, 2, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+};
+
+static const uint16_t levels2[340] = {
+181,110, 78, 63, 61, 62, 60, 61,
+ 33, 41, 41, 19, 17, 19, 12, 11,
+ 9, 11, 10, 6, 8, 7, 6, 4,
+ 5, 5, 4, 4, 3, 4, 3, 5,
+ 3, 4, 3, 3, 3, 3, 3, 3,
+ 2, 2, 4, 2, 3, 2, 3, 3,
+ 2, 2, 2, 2, 2, 2, 2, 2,
+ 3, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 1, 2, 1, 2, 2,
+ 2, 2, 1, 2, 1, 1, 1, 2,
+ 2, 1, 2, 1, 2, 2, 2, 2,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1,
+};
+
+static const uint16_t levels3[180] = {
+351,122, 76, 61, 41, 42, 24, 30,
+ 22, 19, 11, 9, 10, 8, 5, 5,
+ 4, 5, 5, 3, 3, 3, 3, 3,
+ 3, 3, 2, 2, 3, 2, 2, 2,
+ 3, 3, 2, 2, 2, 3, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 1, 1,
+ 2, 2, 1, 2, 1, 2, 2, 2,
+ 2, 2, 2, 1, 2, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 2,
+ 2, 1, 2, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1,
+};
+
+static const uint16_t levels4[70] = {
+113, 68, 49, 42, 40, 32, 27, 15,
+ 10, 5, 3, 3, 3, 3, 2, 2,
+ 2, 2, 2, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1,
+};
+
+static const uint16_t levels5[40] = {
+214, 72, 42, 40, 18, 4, 4, 2,
+ 2, 2, 2, 2, 1, 1, 2, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+};
+
+static const CoefVLCTable coef_vlcs[6] = {
+ {
+ sizeof(coef0_huffbits), sizeof(levels0)/2, coef0_huffcodes, coef0_huffbits, levels0,
+ },
+ {
+ sizeof(coef1_huffbits), sizeof(levels1)/2, coef1_huffcodes, coef1_huffbits, levels1,
+ },
+ {
+ sizeof(coef2_huffbits), sizeof(levels2)/2, coef2_huffcodes, coef2_huffbits, levels2,
+ },
+ {
+ sizeof(coef3_huffbits), sizeof(levels3)/2, coef3_huffcodes, coef3_huffbits, levels3,
+ },
+ {
+ sizeof(coef4_huffbits), sizeof(levels4)/2, coef4_huffcodes, coef4_huffbits, levels4,
+ },
+ {
+ sizeof(coef5_huffbits), sizeof(levels5)/2, coef5_huffcodes, coef5_huffbits, levels5,
+ },
+};
diff --git a/contrib/ffmpeg/libavcodec/wmadec.c b/contrib/ffmpeg/libavcodec/wmadec.c
new file mode 100644
index 000000000..ef3cc7a33
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/wmadec.c
@@ -0,0 +1,912 @@
+/*
+ * WMA compatible decoder
+ * Copyright (c) 2002 The FFmpeg Project.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file wmadec.c
+ * 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
+ * (ASF/AVI/WAV). WMA v2 is identified by audio format 0x161.
+ *
+ * To use this decoder, a calling application must supply the extra data
+ * bytes provided with the WMA data. These are the extra, codec-specific
+ * bytes at the end of a WAVEFORMATEX data structure. Transmit these bytes
+ * to the decoder using the extradata[_size] fields in AVCodecContext. There
+ * should be 4 extra bytes for v1 data and 6 extra bytes for v2 data.
+ */
+
+#include "avcodec.h"
+#include "wma.h"
+
+#undef NDEBUG
+#include <assert.h>
+
+#define EXPVLCBITS 8
+#define EXPMAX ((19+EXPVLCBITS-1)/EXPVLCBITS)
+
+#define HGAINVLCBITS 9
+#define HGAINMAX ((13+HGAINVLCBITS-1)/HGAINVLCBITS)
+
+static void wma_lsp_to_curve_init(WMACodecContext *s, int frame_len);
+
+#ifdef TRACE
+static void dump_shorts(WMADecodeContext *s, const char *name, const short *tab, int n)
+{
+ int i;
+
+ tprintf(s->avctx, "%s[%d]:\n", name, n);
+ for(i=0;i<n;i++) {
+ if ((i & 7) == 0)
+ tprintf(s->avctx, "%4d: ", i);
+ tprintf(s->avctx, " %5d.0", tab[i]);
+ if ((i & 7) == 7)
+ tprintf(s->avctx, "\n");
+ }
+}
+
+static void dump_floats(WMADecodeContext *s, const char *name, int prec, const float *tab, int n)
+{
+ int i;
+
+ tprintf(s->avctx, "%s[%d]:\n", name, n);
+ for(i=0;i<n;i++) {
+ if ((i & 7) == 0)
+ tprintf(s->avctx, "%4d: ", i);
+ tprintf(s->avctx, " %8.*f", prec, tab[i]);
+ if ((i & 7) == 7)
+ tprintf(s->avctx, "\n");
+ }
+ if ((i & 7) != 0)
+ tprintf(s->avctx, "\n");
+}
+#endif
+
+static int wma_decode_init(AVCodecContext * avctx)
+{
+ WMACodecContext *s = avctx->priv_data;
+ int i, flags1, 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 = extradata[0] | (extradata[1] << 8);
+ flags2 = extradata[2] | (extradata[3] << 8);
+ } else if (avctx->codec->id == CODEC_ID_WMAV2 && avctx->extradata_size >= 6) {
+ flags1 = extradata[0] | (extradata[1] << 8) |
+ (extradata[2] << 16) | (extradata[3] << 24);
+ flags2 = extradata[4] | (extradata[5] << 8);
+ }
+// for(i=0; i<avctx->extradata_size; i++)
+// av_log(NULL, AV_LOG_ERROR, "%02X ", extradata[i]);
+
+ s->use_exp_vlc = flags2 & 0x0001;
+ s->use_bit_reservoir = flags2 & 0x0002;
+ s->use_variable_block_len = flags2 & 0x0004;
+
+ ff_wma_init(avctx, flags2);
+
+ /* init MDCT */
+ for(i = 0; i < s->nb_block_sizes; i++)
+ ff_mdct_init(&s->mdct_ctx[i], s->frame_len_bits - i + 1, 1);
+
+ if (s->use_noise_coding) {
+ init_vlc(&s->hgain_vlc, HGAINVLCBITS, sizeof(ff_wma_hgain_huffbits),
+ ff_wma_hgain_huffbits, 1, 1,
+ ff_wma_hgain_huffcodes, 2, 2, 0);
+ }
+
+ 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);
+ } else {
+ wma_lsp_to_curve_init(s, s->frame_len);
+ }
+
+ return 0;
+}
+
+/**
+ * interpolate values for a bigger or smaller block. The block must
+ * have multiple sizes
+ */
+static void interpolate_array(float *scale, int old_size, int new_size)
+{
+ int i, j, jincr, k;
+ float v;
+
+ if (new_size > old_size) {
+ jincr = new_size / old_size;
+ j = new_size;
+ for(i = old_size - 1; i >=0; i--) {
+ v = scale[i];
+ k = jincr;
+ do {
+ scale[--j] = v;
+ } while (--k);
+ }
+ } else if (new_size < old_size) {
+ j = 0;
+ jincr = old_size / new_size;
+ for(i = 0; i < new_size; i++) {
+ scale[i] = scale[j];
+ j += jincr;
+ }
+ }
+}
+
+/**
+ * compute x^-0.25 with an exponent and mantissa table. We use linear
+ * interpolation to reduce the mantissa table size at a small speed
+ * expense (linear interpolation approximately doubles the number of
+ * bits of precision).
+ */
+static inline float pow_m1_4(WMACodecContext *s, float x)
+{
+ union {
+ float f;
+ unsigned int v;
+ } u, t;
+ unsigned int e, m;
+ float a, b;
+
+ u.f = x;
+ e = u.v >> 23;
+ m = (u.v >> (23 - LSP_POW_BITS)) & ((1 << LSP_POW_BITS) - 1);
+ /* build interpolation scale: 1 <= t < 2. */
+ t.v = ((u.v << LSP_POW_BITS) & ((1 << 23) - 1)) | (127 << 23);
+ a = s->lsp_pow_m_table1[m];
+ b = s->lsp_pow_m_table2[m];
+ return s->lsp_pow_e_table[e] * (a + b * t.f);
+}
+
+static void wma_lsp_to_curve_init(WMACodecContext *s, int frame_len)
+{
+ float wdel, a, b;
+ int i, e, m;
+
+ wdel = M_PI / frame_len;
+ for(i=0;i<frame_len;i++)
+ s->lsp_cos_table[i] = 2.0f * cos(wdel * i);
+
+ /* tables for x^-0.25 computation */
+ for(i=0;i<256;i++) {
+ e = i - 126;
+ s->lsp_pow_e_table[i] = pow(2.0, e * -0.25);
+ }
+
+ /* NOTE: these two tables are needed to avoid two operations in
+ pow_m1_4 */
+ b = 1.0;
+ for(i=(1 << LSP_POW_BITS) - 1;i>=0;i--) {
+ m = (1 << LSP_POW_BITS) + i;
+ a = (float)m * (0.5 / (1 << LSP_POW_BITS));
+ a = pow(a, -0.25);
+ s->lsp_pow_m_table1[i] = 2 * a - b;
+ s->lsp_pow_m_table2[i] = b - a;
+ b = a;
+ }
+#if 0
+ for(i=1;i<20;i++) {
+ float v, r1, r2;
+ v = 5.0 / i;
+ r1 = pow_m1_4(s, v);
+ r2 = pow(v,-0.25);
+ printf("%f^-0.25=%f e=%f\n", v, r1, r2 - r1);
+ }
+#endif
+}
+
+/**
+ * NOTE: We use the same code as Vorbis here
+ * @todo optimize it further with SSE/3Dnow
+ */
+static void wma_lsp_to_curve(WMACodecContext *s,
+ float *out, float *val_max_ptr,
+ int n, float *lsp)
+{
+ int i, j;
+ float p, q, w, v, val_max;
+
+ val_max = 0;
+ for(i=0;i<n;i++) {
+ p = 0.5f;
+ q = 0.5f;
+ w = s->lsp_cos_table[i];
+ for(j=1;j<NB_LSP_COEFS;j+=2){
+ q *= w - lsp[j - 1];
+ p *= w - lsp[j];
+ }
+ p *= p * (2.0f - w);
+ q *= q * (2.0f + w);
+ v = p + q;
+ v = pow_m1_4(s, v);
+ if (v > val_max)
+ val_max = v;
+ out[i] = v;
+ }
+ *val_max_ptr = val_max;
+}
+
+/**
+ * decode exponents coded with LSP coefficients (same idea as Vorbis)
+ */
+static void decode_exp_lsp(WMACodecContext *s, int ch)
+{
+ float lsp_coefs[NB_LSP_COEFS];
+ int val, i;
+
+ for(i = 0; i < NB_LSP_COEFS; i++) {
+ if (i == 0 || i >= 8)
+ val = get_bits(&s->gb, 3);
+ else
+ val = get_bits(&s->gb, 4);
+ lsp_coefs[i] = ff_wma_lsp_codebook[i][val];
+ }
+
+ wma_lsp_to_curve(s, s->exponents[ch], &s->max_exponent[ch],
+ s->block_len, lsp_coefs);
+}
+
+/**
+ * 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;
+
+ band_ptr = s->exponent_bands[s->frame_len_bits - s->block_len_bits];
+ ptr = band_ptr;
+ q = 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));
+ max_scale = v;
+ n = *ptr++;
+ do {
+ *q++ = v;
+ } while (--n);
+ }else
+ last_exp = 36;
+
+ while (q < q_end) {
+ code = get_vlc2(&s->gb, s->exp_vlc.table, EXPVLCBITS, EXPMAX);
+ if (code < 0)
+ 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 (v > max_scale)
+ max_scale = v;
+ n = *ptr++;
+ do {
+ *q++ = v;
+ } while (--n);
+ }
+ s->max_exponent[ch] = max_scale;
+ return 0;
+}
+
+
+/**
+ * Apply MDCT window and add into output.
+ *
+ * We ensure that when the windows overlap their squared sum
+ * is always 1 (MDCT reconstruction rule).
+ */
+static void wma_window(WMACodecContext *s, float *out)
+{
+ float *in = s->output;
+ int block_len, bsize, n;
+
+ /* left part */
+ if (s->block_len_bits <= s->prev_block_len_bits) {
+ 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);
+
+ } 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);
+
+ memcpy(out+n+block_len, in+n+block_len, n*sizeof(float));
+ }
+
+ out += s->block_len;
+ in += s->block_len;
+
+ /* right part */
+ if (s->block_len_bits <= s->next_block_len_bits) {
+ block_len = s->block_len;
+ bsize = s->frame_len_bits - s->block_len_bits;
+
+ s->dsp.vector_fmul_reverse(out, in, s->windows[bsize], block_len);
+
+ } else {
+ block_len = 1 << s->next_block_len_bits;
+ n = (s->block_len - block_len) / 2;
+ bsize = s->frame_len_bits - s->next_block_len_bits;
+
+ memcpy(out, in, n*sizeof(float));
+
+ s->dsp.vector_fmul_reverse(out+n, in+n, s->windows[bsize], block_len);
+
+ memset(out+n+block_len, 0, n*sizeof(float));
+ }
+}
+
+
+/**
+ * @return 0 if OK. 1 if last block of frame. return -1 if
+ * unrecorrable error.
+ */
+static int wma_decode_block(WMACodecContext *s)
+{
+ int n, v, a, ch, code, bsize;
+ int coef_nb_bits, total_gain, parse_exponents;
+ int nb_coefs[MAX_CHANNELS];
+ float mdct_norm;
+
+#ifdef TRACE
+ tprintf(s->avctx, "***decode_block: %d:%d\n", s->frame_count - 1, s->block_num);
+#endif
+
+ /* compute current block length */
+ if (s->use_variable_block_len) {
+ n = av_log2(s->nb_block_sizes - 1) + 1;
+
+ if (s->reset_block_lengths) {
+ s->reset_block_lengths = 0;
+ v = get_bits(&s->gb, n);
+ if (v >= s->nb_block_sizes)
+ return -1;
+ s->prev_block_len_bits = s->frame_len_bits - v;
+ v = get_bits(&s->gb, n);
+ if (v >= s->nb_block_sizes)
+ return -1;
+ s->block_len_bits = s->frame_len_bits - v;
+ } else {
+ /* update block lengths */
+ s->prev_block_len_bits = s->block_len_bits;
+ s->block_len_bits = s->next_block_len_bits;
+ }
+ v = get_bits(&s->gb, n);
+ if (v >= s->nb_block_sizes)
+ return -1;
+ s->next_block_len_bits = s->frame_len_bits - v;
+ } else {
+ /* fixed block len */
+ s->next_block_len_bits = s->frame_len_bits;
+ s->prev_block_len_bits = s->frame_len_bits;
+ s->block_len_bits = s->frame_len_bits;
+ }
+
+ /* 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)
+ return -1;
+
+ if (s->nb_channels == 2) {
+ s->ms_stereo = get_bits(&s->gb, 1);
+ }
+ v = 0;
+ for(ch = 0; ch < s->nb_channels; ch++) {
+ a = get_bits(&s->gb, 1);
+ s->channel_coded[ch] = a;
+ v |= a;
+ }
+ /* if no channel coded, no need to go further */
+ /* XXX: fix potential framing problems */
+ if (!v)
+ goto next;
+
+ bsize = s->frame_len_bits - s->block_len_bits;
+
+ /* read total gain and extract corresponding number of bits for
+ coef escape coding */
+ total_gain = 1;
+ for(;;) {
+ a = get_bits(&s->gb, 7);
+ total_gain += a;
+ if (a != 127)
+ break;
+ }
+
+ coef_nb_bits= ff_wma_total_gain_to_bits(total_gain);
+
+ /* compute number of coefficients */
+ n = s->coefs_end[bsize] - s->coefs_start;
+ for(ch = 0; ch < s->nb_channels; ch++)
+ nb_coefs[ch] = n;
+
+ /* complex coding */
+ if (s->use_noise_coding) {
+
+ for(ch = 0; ch < s->nb_channels; ch++) {
+ if (s->channel_coded[ch]) {
+ int i, n, a;
+ n = s->exponent_high_sizes[bsize];
+ for(i=0;i<n;i++) {
+ a = get_bits(&s->gb, 1);
+ s->high_band_coded[ch][i] = a;
+ /* if noise coding, the coefficients are not transmitted */
+ if (a)
+ nb_coefs[ch] -= s->exponent_high_bands[bsize][i];
+ }
+ }
+ }
+ for(ch = 0; ch < s->nb_channels; ch++) {
+ if (s->channel_coded[ch]) {
+ int i, n, val, code;
+
+ n = s->exponent_high_sizes[bsize];
+ val = (int)0x80000000;
+ for(i=0;i<n;i++) {
+ if (s->high_band_coded[ch][i]) {
+ if (val == (int)0x80000000) {
+ val = get_bits(&s->gb, 7) - 19;
+ } else {
+ code = get_vlc2(&s->gb, s->hgain_vlc.table, HGAINVLCBITS, HGAINMAX);
+ if (code < 0)
+ return -1;
+ val += code - 18;
+ }
+ s->high_band_values[ch][i] = val;
+ }
+ }
+ }
+ }
+ }
+
+ /* exposant can be interpolated in short blocks. */
+ parse_exponents = 1;
+ if (s->block_len_bits != s->frame_len_bits) {
+ parse_exponents = get_bits(&s->gb, 1);
+ }
+
+ if (parse_exponents) {
+ for(ch = 0; ch < s->nb_channels; ch++) {
+ if (s->channel_coded[ch]) {
+ if (s->use_exp_vlc) {
+ if (decode_exp_vlc(s, ch) < 0)
+ return -1;
+ } else {
+ decode_exp_lsp(s, ch);
+ }
+ }
+ }
+ } else {
+ for(ch = 0; ch < s->nb_channels; ch++) {
+ if (s->channel_coded[ch]) {
+ interpolate_array(s->exponents[ch], 1 << s->prev_block_len_bits,
+ s->block_len);
+ }
+ }
+ }
+
+ /* parse spectral coefficients : just RLE encoding */
+ for(ch = 0; ch < s->nb_channels; ch++) {
+ if (s->channel_coded[ch]) {
+ VLC *coef_vlc;
+ int level, run, sign, tindex;
+ int16_t *ptr, *eptr;
+ const uint16_t *level_table, *run_table;
+
+ /* special VLC tables are used for ms stereo because
+ there is potentially less energy there */
+ tindex = (ch == 1 && s->ms_stereo);
+ coef_vlc = &s->coef_vlc[tindex];
+ run_table = s->run_table[tindex];
+ level_table = s->level_table[tindex];
+ /* XXX: optimize */
+ ptr = &s->coefs1[ch][0];
+ eptr = ptr + nb_coefs[ch];
+ memset(ptr, 0, s->block_len * sizeof(int16_t));
+ for(;;) {
+ code = get_vlc2(&s->gb, coef_vlc->table, VLCBITS, VLCMAX);
+ if (code < 0)
+ return -1;
+ if (code == 1) {
+ /* EOB */
+ break;
+ } else if (code == 0) {
+ /* escape */
+ level = get_bits(&s->gb, coef_nb_bits);
+ /* NOTE: this is rather suboptimal. reading
+ block_len_bits would be better */
+ run = get_bits(&s->gb, s->frame_len_bits);
+ } else {
+ /* normal code */
+ run = run_table[code];
+ level = level_table[code];
+ }
+ sign = get_bits(&s->gb, 1);
+ if (!sign)
+ level = -level;
+ ptr += run;
+ if (ptr >= eptr)
+ {
+ av_log(NULL, AV_LOG_ERROR, "overflow in spectral RLE, ignoring\n");
+ break;
+ }
+ *ptr++ = level;
+ /* NOTE: EOB can be omitted */
+ if (ptr >= eptr)
+ break;
+ }
+ }
+ if (s->version == 1 && s->nb_channels >= 2) {
+ align_get_bits(&s->gb);
+ }
+ }
+
+ /* normalize */
+ {
+ int n4 = s->block_len / 2;
+ mdct_norm = 1.0 / (float)n4;
+ if (s->version == 1) {
+ mdct_norm *= sqrt(n4);
+ }
+ }
+
+ /* finally compute the MDCT coefficients */
+ for(ch = 0; ch < s->nb_channels; ch++) {
+ if (s->channel_coded[ch]) {
+ int16_t *coefs1;
+ float *coefs, *exponents, mult, mult1, noise, *exp_ptr;
+ int i, j, n, n1, last_high_band;
+ float exp_power[HIGH_BAND_MAX_SIZE];
+
+ coefs1 = s->coefs1[ch];
+ exponents = s->exponents[ch];
+ mult = pow(10, total_gain * 0.05) / s->max_exponent[ch];
+ mult *= mdct_norm;
+ coefs = s->coefs[ch];
+ if (s->use_noise_coding) {
+ mult1 = mult;
+ /* very low freqs : noise */
+ for(i = 0;i < s->coefs_start; i++) {
+ *coefs++ = s->noise_table[s->noise_index] * (*exponents++) * mult1;
+ s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
+ }
+
+ n1 = s->exponent_high_sizes[bsize];
+
+ /* compute power of high bands */
+ exp_ptr = exponents +
+ s->high_band_start[bsize] -
+ s->coefs_start;
+ last_high_band = 0; /* avoid warning */
+ for(j=0;j<n1;j++) {
+ n = s->exponent_high_bands[s->frame_len_bits -
+ s->block_len_bits][j];
+ if (s->high_band_coded[ch][j]) {
+ float e2, v;
+ e2 = 0;
+ for(i = 0;i < n; i++) {
+ v = exp_ptr[i];
+ e2 += v * v;
+ }
+ exp_power[j] = e2 / n;
+ last_high_band = j;
+ tprintf(s->avctx, "%d: power=%f (%d)\n", j, exp_power[j], n);
+ }
+ exp_ptr += n;
+ }
+
+ /* main freqs and high freqs */
+ for(j=-1;j<n1;j++) {
+ if (j < 0) {
+ n = s->high_band_start[bsize] -
+ s->coefs_start;
+ } else {
+ n = s->exponent_high_bands[s->frame_len_bits -
+ s->block_len_bits][j];
+ }
+ if (j >= 0 && s->high_band_coded[ch][j]) {
+ /* use noise with specified power */
+ mult1 = sqrt(exp_power[j] / exp_power[last_high_band]);
+ /* XXX: use a table */
+ mult1 = mult1 * pow(10, s->high_band_values[ch][j] * 0.05);
+ mult1 = mult1 / (s->max_exponent[ch] * s->noise_mult);
+ mult1 *= mdct_norm;
+ for(i = 0;i < n; i++) {
+ noise = s->noise_table[s->noise_index];
+ s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
+ *coefs++ = (*exponents++) * noise * mult1;
+ }
+ } else {
+ /* coded values + small noise */
+ for(i = 0;i < n; i++) {
+ noise = s->noise_table[s->noise_index];
+ s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
+ *coefs++ = ((*coefs1++) + noise) * (*exponents++) * mult;
+ }
+ }
+ }
+
+ /* very high freqs : noise */
+ n = s->block_len - s->coefs_end[bsize];
+ mult1 = mult * exponents[-1];
+ for(i = 0; i < n; i++) {
+ *coefs++ = s->noise_table[s->noise_index] * mult1;
+ s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
+ }
+ } else {
+ /* XXX: optimize more */
+ for(i = 0;i < s->coefs_start; i++)
+ *coefs++ = 0.0;
+ n = nb_coefs[ch];
+ for(i = 0;i < n; i++) {
+ *coefs++ = coefs1[i] * exponents[i] * mult;
+ }
+ n = s->block_len - s->coefs_end[bsize];
+ for(i = 0;i < n; i++)
+ *coefs++ = 0.0;
+ }
+ }
+ }
+
+#ifdef TRACE
+ for(ch = 0; ch < s->nb_channels; ch++) {
+ if (s->channel_coded[ch]) {
+ dump_floats(s, "exponents", 3, s->exponents[ch], s->block_len);
+ dump_floats(s, "coefs", 1, s->coefs[ch], s->block_len);
+ }
+ }
+#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 */
+ if (!s->channel_coded[0]) {
+ tprintf(s->avctx, "rare ms-stereo case happened\n");
+ memset(s->coefs[0], 0, sizeof(float) * s->block_len);
+ 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;
+ }
+ }
+
+ for(ch = 0; ch < s->nb_channels; ch++) {
+ if (s->channel_coded[ch]) {
+ int n4, index, n;
+
+ n = s->block_len;
+ n4 = s->block_len / 2;
+ s->mdct_ctx[bsize].fft.imdct_calc(&s->mdct_ctx[bsize],
+ s->output, s->coefs[ch], s->mdct_tmp);
+
+ /* multiply by the window and add in the frame */
+ index = (s->frame_len / 2) + s->block_pos - n4;
+ wma_window(s, &s->frame_out[ch][index]);
+
+ /* specific fast case for ms-stereo : add to second
+ channel if it is not coded */
+ if (s->ms_stereo && !s->channel_coded[1]) {
+ wma_window(s, &s->frame_out[1][index]);
+ }
+ }
+ }
+ next:
+ /* update block number */
+ s->block_num++;
+ s->block_pos += s->block_len;
+ if (s->block_pos >= s->frame_len)
+ return 1;
+ else
+ return 0;
+}
+
+/* decode a frame of frame_len samples */
+static int wma_decode_frame(WMACodecContext *s, int16_t *samples)
+{
+ int ret, i, n, a, ch, incr;
+ int16_t *ptr;
+ float *iptr;
+
+#ifdef TRACE
+ tprintf(s->avctx, "***decode_frame: %d size=%d\n", s->frame_count++, s->frame_len);
+#endif
+
+ /* read each block */
+ s->block_num = 0;
+ s->block_pos = 0;
+ for(;;) {
+ ret = wma_decode_block(s);
+ if (ret < 0)
+ return -1;
+ if (ret)
+ break;
+ }
+
+ /* 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];
+
+ for(i=0;i<n;i++) {
+ a = lrintf(*iptr++);
+ if (a > 32767)
+ a = 32767;
+ else if (a < -32768)
+ a = -32768;
+ *ptr = a;
+ ptr += incr;
+ }
+ /* prepare for next block */
+ memmove(&s->frame_out[ch][0], &s->frame_out[ch][s->frame_len],
+ s->frame_len * sizeof(float));
+ }
+
+#ifdef TRACE
+ dump_shorts(s, "samples", samples, n * s->nb_channels);
+#endif
+ return 0;
+}
+
+static int wma_decode_superframe(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
+{
+ WMACodecContext *s = avctx->priv_data;
+ int nb_frames, bit_offset, i, pos, len;
+ uint8_t *q;
+ int16_t *samples;
+
+ tprintf(avctx, "***decode_superframe:\n");
+
+ if(buf_size==0){
+ s->last_superframe_len = 0;
+ return 0;
+ }
+
+ samples = data;
+
+ init_get_bits(&s->gb, buf, buf_size*8);
+
+ if (s->use_bit_reservoir) {
+ /* read super frame header */
+ get_bits(&s->gb, 4); /* super frame index */
+ nb_frames = get_bits(&s->gb, 4) - 1;
+
+ bit_offset = get_bits(&s->gb, s->byte_offset_bits + 3);
+
+ if (s->last_superframe_len > 0) {
+ // printf("skip=%d\n", s->last_bitoffset);
+ /* add bit_offset bits to last frame */
+ if ((s->last_superframe_len + ((bit_offset + 7) >> 3)) >
+ MAX_CODED_SUPERFRAME_SIZE)
+ goto fail;
+ q = s->last_superframe + s->last_superframe_len;
+ len = bit_offset;
+ while (len > 7) {
+ *q++ = (get_bits)(&s->gb, 8);
+ len -= 8;
+ }
+ if (len > 0) {
+ *q++ = (get_bits)(&s->gb, len) << (8 - len);
+ }
+
+ /* XXX: bit_offset bits into last frame */
+ init_get_bits(&s->gb, s->last_superframe, MAX_CODED_SUPERFRAME_SIZE*8);
+ /* skip unused bits */
+ if (s->last_bitoffset > 0)
+ skip_bits(&s->gb, s->last_bitoffset);
+ /* this frame is stored in the last superframe and in the
+ current one */
+ if (wma_decode_frame(s, samples) < 0)
+ goto fail;
+ samples += s->nb_channels * s->frame_len;
+ }
+
+ /* read each frame starting from bit_offset */
+ pos = bit_offset + 4 + 4 + s->byte_offset_bits + 3;
+ init_get_bits(&s->gb, buf + (pos >> 3), (MAX_CODED_SUPERFRAME_SIZE - (pos >> 3))*8);
+ len = pos & 7;
+ if (len > 0)
+ skip_bits(&s->gb, len);
+
+ s->reset_block_lengths = 1;
+ for(i=0;i<nb_frames;i++) {
+ if (wma_decode_frame(s, samples) < 0)
+ goto fail;
+ samples += s->nb_channels * s->frame_len;
+ }
+
+ /* we copy the end of the frame in the last frame buffer */
+ pos = get_bits_count(&s->gb) + ((bit_offset + 4 + 4 + s->byte_offset_bits + 3) & ~7);
+ s->last_bitoffset = pos & 7;
+ pos >>= 3;
+ len = buf_size - pos;
+ if (len > MAX_CODED_SUPERFRAME_SIZE || len < 0) {
+ goto fail;
+ }
+ s->last_superframe_len = len;
+ memcpy(s->last_superframe, buf + pos, len);
+ } else {
+ /* single frame decode */
+ if (wma_decode_frame(s, samples) < 0)
+ goto fail;
+ samples += s->nb_channels * s->frame_len;
+ }
+
+//av_log(NULL, AV_LOG_ERROR, "%d %d %d %d outbytes:%d eaten:%d\n", s->frame_len_bits, s->block_len_bits, s->frame_len, s->block_len, (int8_t *)samples - (int8_t *)data, s->block_align);
+
+ *data_size = (int8_t *)samples - (int8_t *)data;
+ return s->block_align;
+ fail:
+ /* when error, we reset the bit reservoir */
+ s->last_superframe_len = 0;
+ return -1;
+}
+
+AVCodec wmav1_decoder =
+{
+ "wmav1",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_WMAV1,
+ sizeof(WMACodecContext),
+ wma_decode_init,
+ NULL,
+ ff_wma_end,
+ wma_decode_superframe,
+};
+
+AVCodec wmav2_decoder =
+{
+ "wmav2",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_WMAV2,
+ sizeof(WMACodecContext),
+ wma_decode_init,
+ NULL,
+ ff_wma_end,
+ wma_decode_superframe,
+};
diff --git a/contrib/ffmpeg/libavcodec/wmaenc.c b/contrib/ffmpeg/libavcodec/wmaenc.c
new file mode 100644
index 000000000..e902a6aff
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/wmaenc.c
@@ -0,0 +1,407 @@
+/*
+ * WMA compatible encoder
+ * 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
+ */
+
+#include "avcodec.h"
+#include "wma.h"
+
+#undef NDEBUG
+#include <assert.h>
+
+
+static int encode_init(AVCodecContext * avctx){
+ WMACodecContext *s = avctx->priv_data;
+ int i, flags1, flags2;
+ uint8_t *extradata;
+
+ s->avctx = avctx;
+
+ if(avctx->channels > MAX_CHANNELS)
+ return -1;
+
+ if(avctx->bit_rate < 24*1000)
+ return -1;
+
+ /* extract flag infos */
+ flags1 = 0;
+ flags2 = 1;
+ if (avctx->codec->id == CODEC_ID_WMAV1) {
+ extradata= av_malloc(4);
+ avctx->extradata_size= 4;
+ extradata[0] = flags1;
+ extradata[1] = flags1>>8;
+ extradata[2] = flags2;
+ extradata[3] = flags2>>8;
+ } else if (avctx->codec->id == CODEC_ID_WMAV2) {
+ extradata= av_mallocz(10);
+ avctx->extradata_size= 10;
+ extradata[0] = flags1;
+ extradata[1] = flags1>>8;
+ extradata[2] = flags1>>16;
+ extradata[3] = flags1>>24;
+ extradata[4] = flags2;
+ extradata[5] = flags2>>8;
+ }else
+ assert(0);
+ avctx->extradata= extradata;
+ s->use_exp_vlc = flags2 & 0x0001;
+ s->use_bit_reservoir = flags2 & 0x0002;
+ s->use_variable_block_len = flags2 & 0x0004;
+
+ ff_wma_init(avctx, flags2);
+
+ /* init MDCT */
+ for(i = 0; i < s->nb_block_sizes; i++)
+ ff_mdct_init(&s->mdct_ctx[i], s->frame_len_bits - i + 1, 0);
+
+ avctx->block_align=
+ s->block_align= avctx->bit_rate*(int64_t)s->frame_len / (avctx->sample_rate*8);
+//av_log(NULL, AV_LOG_ERROR, "%d %d %d %d\n", s->block_align, avctx->bit_rate, s->frame_len, avctx->sample_rate);
+ avctx->frame_size= s->frame_len;
+
+ return 0;
+}
+
+
+static void apply_window_and_mdct(AVCodecContext * avctx, signed short * audio, int len) {
+ WMACodecContext *s = avctx->priv_data;
+ int window_index= s->frame_len_bits - s->block_len_bits;
+ int i, j, channel;
+ const float * win = s->windows[window_index];
+ int window_len = 1 << s->block_len_bits;
+ float n = window_len/2;
+
+ for (channel = 0; channel < avctx->channels; channel++) {
+ memcpy(s->output, s->frame_out[channel], sizeof(float)*window_len);
+ j = channel;
+ for (i = 0; i < len; i++, j += avctx->channels){
+ s->output[i+window_len] = audio[j] / n * win[window_len - i - 1];
+ s->frame_out[channel][i] = audio[j] / n * win[i];
+ }
+ ff_mdct_calc(&s->mdct_ctx[window_index], s->coefs[channel], s->output, s->mdct_tmp);
+ }
+}
+
+//FIXME use for decoding too
+static void init_exp(WMACodecContext *s, int ch, int *exp_param){
+ int n;
+ const uint16_t *ptr;
+ float v, *q, max_scale, *q_end;
+
+ ptr = s->exponent_bands[s->frame_len_bits - s->block_len_bits];
+ q = s->exponents[ch];
+ q_end = q + s->block_len;
+ max_scale = 0;
+ while (q < q_end) {
+ /* XXX: use a table */
+ v = pow(10, *exp_param++ * (1.0 / 16.0));
+ max_scale= FFMAX(max_scale, v);
+ n = *ptr++;
+ do {
+ *q++ = v;
+ } while (--n);
+ }
+ s->max_exponent[ch] = max_scale;
+}
+
+static void encode_exp_vlc(WMACodecContext *s, int ch, const int *exp_param){
+ int last_exp;
+ const uint16_t *ptr;
+ float *q, *q_end;
+
+ ptr = s->exponent_bands[s->frame_len_bits - s->block_len_bits];
+ q = s->exponents[ch];
+ q_end = q + s->block_len;
+ if (s->version == 1) {
+ last_exp= *exp_param++;
+ assert(last_exp-10 >= 0 && last_exp-10 < 32);
+ put_bits(&s->pb, 5, last_exp - 10);
+ q+= *ptr++;
+ }else
+ last_exp = 36;
+ while (q < q_end) {
+ 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]);
+ /* XXX: use a table */
+ q+= *ptr++;
+ last_exp= exp;
+ }
+}
+
+static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE], int total_gain){
+ int v, bsize, ch, coef_nb_bits, parse_exponents;
+ float mdct_norm;
+ int nb_coefs[MAX_CHANNELS];
+ static const int fixed_exp[25]={20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20};
+
+ //FIXME remove duplication relative to decoder
+ if (s->use_variable_block_len) {
+ assert(0); //FIXME not implemented
+ }else{
+ /* fixed block len */
+ s->next_block_len_bits = s->frame_len_bits;
+ s->prev_block_len_bits = s->frame_len_bits;
+ s->block_len_bits = s->frame_len_bits;
+ }
+
+ s->block_len = 1 << s->block_len_bits;
+// assert((s->block_pos + s->block_len) <= s->frame_len);
+ bsize = s->frame_len_bits - s->block_len_bits;
+
+ //FIXME factor
+ v = s->coefs_end[bsize] - s->coefs_start;
+ for(ch = 0; ch < s->nb_channels; ch++)
+ nb_coefs[ch] = v;
+ {
+ int n4 = s->block_len / 2;
+ mdct_norm = 1.0 / (float)n4;
+ if (s->version == 1) {
+ mdct_norm *= sqrt(n4);
+ }
+ }
+
+ if (s->nb_channels == 2) {
+ put_bits(&s->pb, 1, s->ms_stereo= 1);
+ }
+
+ for(ch = 0; ch < s->nb_channels; ch++) {
+ if (s->channel_coded[ch]= 1) { //FIXME
+ init_exp(s, ch, fixed_exp);
+ }
+ }
+
+ for(ch = 0; ch < s->nb_channels; ch++) {
+ if (s->channel_coded[ch]) {
+ int16_t *coefs1;
+ float *coefs, *exponents, mult;
+ int i, n;
+
+ coefs1 = s->coefs1[ch];
+ exponents = s->exponents[ch];
+ mult = pow(10, total_gain * 0.05) / s->max_exponent[ch];
+ mult *= mdct_norm;
+ coefs = src_coefs[ch];
+ if (s->use_noise_coding && 0) {
+ assert(0); //FIXME not implemented
+ } else {
+ coefs += s->coefs_start;
+ n = nb_coefs[ch];
+ for(i = 0;i < n; i++){
+ double t= *coefs++ / (exponents[i] * mult);
+ if(t<-32768 || t>32767)
+ return -1;
+
+ coefs1[i] = lrint(t);
+ }
+ }
+ }
+ }
+
+ v = 0;
+ for(ch = 0; ch < s->nb_channels; ch++) {
+ int a = s->channel_coded[ch];
+ put_bits(&s->pb, 1, a);
+ v |= a;
+ }
+
+ if (!v)
+ return 1;
+
+ for(v= total_gain-1; v>=127; v-= 127)
+ put_bits(&s->pb, 7, 127);
+ put_bits(&s->pb, 7, v);
+
+ coef_nb_bits= ff_wma_total_gain_to_bits(total_gain);
+
+ if (s->use_noise_coding) {
+ for(ch = 0; ch < s->nb_channels; ch++) {
+ if (s->channel_coded[ch]) {
+ int i, n;
+ n = s->exponent_high_sizes[bsize];
+ for(i=0;i<n;i++) {
+ put_bits(&s->pb, 1, s->high_band_coded[ch][i]= 0);
+ if (0)
+ nb_coefs[ch] -= s->exponent_high_bands[bsize][i];
+ }
+ }
+ }
+ }
+
+ parse_exponents = 1;
+ if (s->block_len_bits != s->frame_len_bits) {
+ put_bits(&s->pb, 1, parse_exponents);
+ }
+
+ if (parse_exponents) {
+ for(ch = 0; ch < s->nb_channels; ch++) {
+ if (s->channel_coded[ch]) {
+ if (s->use_exp_vlc) {
+ encode_exp_vlc(s, ch, fixed_exp);
+ } else {
+ assert(0); //FIXME not implemented
+// encode_exp_lsp(s, ch);
+ }
+ }
+ }
+ } else {
+ assert(0); //FIXME not implemented
+ }
+
+ for(ch = 0; ch < s->nb_channels; ch++) {
+ if (s->channel_coded[ch]) {
+ int run, tindex;
+ int16_t *ptr, *eptr;
+ tindex = (ch == 1 && s->ms_stereo);
+ ptr = &s->coefs1[ch][0];
+ eptr = ptr + nb_coefs[ch];
+
+ run=0;
+ for(;ptr < eptr; ptr++){
+ if(*ptr){
+ int level= *ptr;
+ int abs_level= FFABS(level);
+ int code= 0;
+ if(abs_level <= s->coef_vlcs[tindex]->max_level){
+ if(run < s->coef_vlcs[tindex]->levels[abs_level-1])
+ code= run + s->int_table[tindex][abs_level-1];
+ }
+
+ assert(code < s->coef_vlcs[tindex]->n);
+ put_bits(&s->pb, s->coef_vlcs[tindex]->huffbits[code], s->coef_vlcs[tindex]->huffcodes[code]);
+
+ if(code == 0){
+ if(1<<coef_nb_bits <= abs_level)
+ return -1;
+
+ put_bits(&s->pb, coef_nb_bits, abs_level);
+ put_bits(&s->pb, s->frame_len_bits, run);
+ }
+ put_bits(&s->pb, 1, level < 0); //FIXME the sign is fliped somewhere
+ run=0;
+ }else{
+ run++;
+ }
+ }
+ if(run)
+ put_bits(&s->pb, s->coef_vlcs[tindex]->huffbits[1], s->coef_vlcs[tindex]->huffcodes[1]);
+ }
+ if (s->version == 1 && s->nb_channels >= 2) {
+ align_put_bits(&s->pb);
+ }
+ }
+ return 0;
+}
+
+static int encode_frame(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE], uint8_t *buf, int buf_size, int total_gain){
+ init_put_bits(&s->pb, buf, buf_size);
+
+ if (s->use_bit_reservoir) {
+ assert(0);//FIXME not implemented
+ }else{
+ if(encode_block(s, src_coefs, total_gain) < 0)
+ return INT_MAX;
+ }
+
+ align_put_bits(&s->pb);
+
+ return put_bits_count(&s->pb)/8 - s->block_align;
+}
+
+static int encode_superframe(AVCodecContext *avctx,
+ unsigned char *buf, int buf_size, void *data){
+ WMACodecContext *s = avctx->priv_data;
+ short *samples = data;
+ int i, total_gain, best;
+
+ s->block_len_bits= s->frame_len_bits; //required by non variable block len
+ s->block_len = 1 << s->block_len_bits;
+
+ apply_window_and_mdct(avctx, samples, avctx->frame_size);
+
+ if (s->ms_stereo) {
+ float a, b;
+ int i;
+
+ for(i = 0; i < s->block_len; i++) {
+ a = s->coefs[0][i]*0.5;
+ b = s->coefs[1][i]*0.5;
+ s->coefs[0][i] = a + b;
+ s->coefs[1][i] = a - b;
+ }
+ }
+
+#if 1
+ total_gain= 128;
+ for(i=64; i; i>>=1){
+ int error= encode_frame(s, s->coefs, buf, buf_size, total_gain-i);
+ if(error<0)
+ total_gain-= i;
+ }
+#else
+ total_gain= 90;
+ best= encode_frame(s, s->coefs, buf, buf_size, total_gain);
+ for(i=32; i; i>>=1){
+ int scoreL= encode_frame(s, s->coefs, buf, buf_size, total_gain-i);
+ int scoreR= encode_frame(s, s->coefs, buf, buf_size, total_gain+i);
+ av_log(NULL, AV_LOG_ERROR, "%d %d %d (%d)\n", scoreL, best, scoreR, total_gain);
+ if(scoreL < FFMIN(best, scoreR)){
+ best = scoreL;
+ total_gain -= i;
+ }else if(scoreR < best){
+ best = scoreR;
+ total_gain += i;
+ }
+ }
+#endif
+
+ encode_frame(s, s->coefs, buf, buf_size, total_gain);
+ assert((put_bits_count(&s->pb) & 7) == 0);
+ i= s->block_align - (put_bits_count(&s->pb)+7)/8;
+ assert(i>=0);
+ while(i--)
+ put_bits(&s->pb, 8, 'N');
+
+ flush_put_bits(&s->pb);
+ return pbBufPtr(&s->pb) - s->pb.buf;
+}
+
+AVCodec wmav1_encoder =
+{
+ "wmav1",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_WMAV1,
+ sizeof(WMACodecContext),
+ encode_init,
+ encode_superframe,
+ ff_wma_end,
+};
+
+AVCodec wmav2_encoder =
+{
+ "wmav2",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_WMAV2,
+ sizeof(WMACodecContext),
+ encode_init,
+ encode_superframe,
+ ff_wma_end,
+};
diff --git a/contrib/ffmpeg/libavcodec/wmv2.c b/contrib/ffmpeg/libavcodec/wmv2.c
new file mode 100644
index 000000000..d57eaa5e4
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/wmv2.c
@@ -0,0 +1,861 @@
+/*
+ * Copyright (c) 2002 The FFmpeg Project.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * @file wmv2.c
+ * wmv2 codec.
+ */
+
+#include "simple_idct.h"
+
+#define SKIP_TYPE_NONE 0
+#define SKIP_TYPE_MPEG 1
+#define SKIP_TYPE_ROW 2
+#define SKIP_TYPE_COL 3
+
+
+typedef struct Wmv2Context{
+ MpegEncContext s;
+ int j_type_bit;
+ int j_type;
+ int flag3;
+ int flag63;
+ int abt_flag;
+ int abt_type;
+ int abt_type_table[6];
+ int per_mb_abt;
+ int per_block_abt;
+ int mspel_bit;
+ int cbp_table_index;
+ int top_left_mv_flag;
+ int per_mb_rl_bit;
+ int skip_type;
+ int hshift;
+
+ ScanTable abt_scantable[2];
+ DECLARE_ALIGNED_8(DCTELEM, abt_block2[6][64]);
+}Wmv2Context;
+
+static void wmv2_common_init(Wmv2Context * w){
+ MpegEncContext * const s= &w->s;
+
+ ff_init_scantable(s->dsp.idct_permutation, &w->abt_scantable[0], wmv2_scantableA);
+ ff_init_scantable(s->dsp.idct_permutation, &w->abt_scantable[1], wmv2_scantableB);
+}
+
+#ifdef CONFIG_ENCODERS
+
+static int encode_ext_header(Wmv2Context *w){
+ MpegEncContext * const s= &w->s;
+ PutBitContext pb;
+ int code;
+
+ init_put_bits(&pb, s->avctx->extradata, s->avctx->extradata_size);
+
+ put_bits(&pb, 5, s->avctx->time_base.den / s->avctx->time_base.num); //yes 29.97 -> 29
+ put_bits(&pb, 11, FFMIN(s->bit_rate/1024, 2047));
+
+ put_bits(&pb, 1, w->mspel_bit=1);
+ put_bits(&pb, 1, w->flag3=1);
+ put_bits(&pb, 1, w->abt_flag=1);
+ put_bits(&pb, 1, w->j_type_bit=1);
+ put_bits(&pb, 1, w->top_left_mv_flag=0);
+ put_bits(&pb, 1, w->per_mb_rl_bit=1);
+ put_bits(&pb, 3, code=1);
+
+ flush_put_bits(&pb);
+
+ s->slice_height = s->mb_height / code;
+
+ return 0;
+}
+
+static int wmv2_encode_init(AVCodecContext *avctx){
+ Wmv2Context * const w= avctx->priv_data;
+
+ if(MPV_encode_init(avctx) < 0)
+ return -1;
+
+ wmv2_common_init(w);
+
+ avctx->extradata_size= 4;
+ avctx->extradata= av_mallocz(avctx->extradata_size + 10);
+ encode_ext_header(w);
+
+ return 0;
+}
+
+#if 0 /* unused, remove? */
+static int wmv2_encode_end(AVCodecContext *avctx){
+
+ if(MPV_encode_end(avctx) < 0)
+ return -1;
+
+ avctx->extradata_size= 0;
+ av_freep(&avctx->extradata);
+
+ return 0;
+}
+#endif
+
+int ff_wmv2_encode_picture_header(MpegEncContext * s, int picture_number)
+{
+ Wmv2Context * const w= (Wmv2Context*)s;
+
+ put_bits(&s->pb, 1, s->pict_type - 1);
+ if(s->pict_type == I_TYPE){
+ put_bits(&s->pb, 7, 0);
+ }
+ put_bits(&s->pb, 5, s->qscale);
+
+ s->dc_table_index = 1;
+ s->mv_table_index = 1; /* only if P frame */
+// s->use_skip_mb_code = 1; /* only if P frame */
+ s->per_mb_rl_table = 0;
+ s->mspel= 0;
+ w->per_mb_abt=0;
+ w->abt_type=0;
+ w->j_type=0;
+
+ assert(s->flipflop_rounding);
+
+ if (s->pict_type == I_TYPE) {
+ assert(s->no_rounding==1);
+ if(w->j_type_bit) put_bits(&s->pb, 1, w->j_type);
+
+ if(w->per_mb_rl_bit) put_bits(&s->pb, 1, s->per_mb_rl_table);
+
+ if(!s->per_mb_rl_table){
+ code012(&s->pb, s->rl_chroma_table_index);
+ code012(&s->pb, s->rl_table_index);
+ }
+
+ put_bits(&s->pb, 1, s->dc_table_index);
+
+ s->inter_intra_pred= 0;
+ }else{
+ int cbp_index;
+
+ put_bits(&s->pb, 2, SKIP_TYPE_NONE);
+
+ code012(&s->pb, cbp_index=0);
+ if(s->qscale <= 10){
+ int map[3]= {0,2,1};
+ w->cbp_table_index= map[cbp_index];
+ }else if(s->qscale <= 20){
+ int map[3]= {1,0,2};
+ w->cbp_table_index= map[cbp_index];
+ }else{
+ int map[3]= {2,1,0};
+ w->cbp_table_index= map[cbp_index];
+ }
+
+ if(w->mspel_bit) put_bits(&s->pb, 1, s->mspel);
+
+ if(w->abt_flag){
+ put_bits(&s->pb, 1, w->per_mb_abt^1);
+ if(!w->per_mb_abt){
+ code012(&s->pb, w->abt_type);
+ }
+ }
+
+ if(w->per_mb_rl_bit) put_bits(&s->pb, 1, s->per_mb_rl_table);
+
+ if(!s->per_mb_rl_table){
+ code012(&s->pb, s->rl_table_index);
+ s->rl_chroma_table_index = s->rl_table_index;
+ }
+ put_bits(&s->pb, 1, s->dc_table_index);
+ put_bits(&s->pb, 1, s->mv_table_index);
+
+ s->inter_intra_pred= 0;//(s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE);
+ }
+ s->esc3_level_length= 0;
+ s->esc3_run_length= 0;
+
+ return 0;
+}
+
+// nearly idential to wmv1 but thats just because we dont use the useless M$ crap features
+// its duplicated here in case someone wants to add support for these carp features
+void ff_wmv2_encode_mb(MpegEncContext * s,
+ DCTELEM block[6][64],
+ int motion_x, int motion_y)
+{
+ Wmv2Context * const w= (Wmv2Context*)s;
+ int cbp, coded_cbp, i;
+ int pred_x, pred_y;
+ uint8_t *coded_block;
+
+ handle_slices(s);
+
+ if (!s->mb_intra) {
+ /* compute cbp */
+ cbp = 0;
+ for (i = 0; i < 6; i++) {
+ if (s->block_last_index[i] >= 0)
+ cbp |= 1 << (5 - i);
+ }
+
+ put_bits(&s->pb,
+ wmv2_inter_table[w->cbp_table_index][cbp + 64][1],
+ wmv2_inter_table[w->cbp_table_index][cbp + 64][0]);
+
+ /* motion vector */
+ h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
+ msmpeg4_encode_motion(s, motion_x - pred_x,
+ motion_y - pred_y);
+ } else {
+ /* compute cbp */
+ cbp = 0;
+ coded_cbp = 0;
+ for (i = 0; i < 6; i++) {
+ int val, pred;
+ val = (s->block_last_index[i] >= 1);
+ cbp |= val << (5 - i);
+ if (i < 4) {
+ /* predict value for close blocks only for luma */
+ pred = coded_block_pred(s, i, &coded_block);
+ *coded_block = val;
+ val = val ^ pred;
+ }
+ coded_cbp |= val << (5 - i);
+ }
+#if 0
+ if (coded_cbp)
+ printf("cbp=%x %x\n", cbp, coded_cbp);
+#endif
+
+ if (s->pict_type == I_TYPE) {
+ put_bits(&s->pb,
+ ff_msmp4_mb_i_table[coded_cbp][1], ff_msmp4_mb_i_table[coded_cbp][0]);
+ } else {
+ put_bits(&s->pb,
+ wmv2_inter_table[w->cbp_table_index][cbp][1],
+ wmv2_inter_table[w->cbp_table_index][cbp][0]);
+ }
+ put_bits(&s->pb, 1, 0); /* no AC prediction yet */
+ if(s->inter_intra_pred){
+ s->h263_aic_dir=0;
+ put_bits(&s->pb, table_inter_intra[s->h263_aic_dir][1], table_inter_intra[s->h263_aic_dir][0]);
+ }
+ }
+
+ for (i = 0; i < 6; i++) {
+ msmpeg4_encode_block(s, block[i], i);
+ }
+}
+#endif //CONFIG_ENCODERS
+
+static void parse_mb_skip(Wmv2Context * w){
+ int mb_x, mb_y;
+ MpegEncContext * const s= &w->s;
+ uint32_t * const mb_type= s->current_picture_ptr->mb_type;
+
+ w->skip_type= get_bits(&s->gb, 2);
+ switch(w->skip_type){
+ case SKIP_TYPE_NONE:
+ for(mb_y=0; mb_y<s->mb_height; mb_y++){
+ for(mb_x=0; mb_x<s->mb_width; mb_x++){
+ mb_type[mb_y*s->mb_stride + mb_x]= MB_TYPE_16x16 | MB_TYPE_L0;
+ }
+ }
+ break;
+ case SKIP_TYPE_MPEG:
+ for(mb_y=0; mb_y<s->mb_height; mb_y++){
+ for(mb_x=0; mb_x<s->mb_width; mb_x++){
+ mb_type[mb_y*s->mb_stride + mb_x]= (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_L0;
+ }
+ }
+ break;
+ case SKIP_TYPE_ROW:
+ for(mb_y=0; mb_y<s->mb_height; mb_y++){
+ if(get_bits1(&s->gb)){
+ for(mb_x=0; mb_x<s->mb_width; mb_x++){
+ mb_type[mb_y*s->mb_stride + mb_x]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
+ }
+ }else{
+ for(mb_x=0; mb_x<s->mb_width; mb_x++){
+ mb_type[mb_y*s->mb_stride + mb_x]= (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_L0;
+ }
+ }
+ }
+ break;
+ case SKIP_TYPE_COL:
+ for(mb_x=0; mb_x<s->mb_width; mb_x++){
+ if(get_bits1(&s->gb)){
+ for(mb_y=0; mb_y<s->mb_height; mb_y++){
+ mb_type[mb_y*s->mb_stride + mb_x]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
+ }
+ }else{
+ for(mb_y=0; mb_y<s->mb_height; mb_y++){
+ mb_type[mb_y*s->mb_stride + mb_x]= (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_L0;
+ }
+ }
+ }
+ break;
+ }
+}
+
+static int decode_ext_header(Wmv2Context *w){
+ MpegEncContext * const s= &w->s;
+ GetBitContext gb;
+ int fps;
+ int code;
+
+ if(s->avctx->extradata_size<4) return -1;
+
+ init_get_bits(&gb, s->avctx->extradata, s->avctx->extradata_size*8);
+
+ fps = get_bits(&gb, 5);
+ s->bit_rate = get_bits(&gb, 11)*1024;
+ w->mspel_bit = get_bits1(&gb);
+ w->flag3 = get_bits1(&gb);
+ w->abt_flag = get_bits1(&gb);
+ w->j_type_bit = get_bits1(&gb);
+ w->top_left_mv_flag= get_bits1(&gb);
+ w->per_mb_rl_bit = get_bits1(&gb);
+ code = get_bits(&gb, 3);
+
+ if(code==0) return -1;
+
+ s->slice_height = s->mb_height / code;
+
+ if(s->avctx->debug&FF_DEBUG_PICT_INFO){
+ av_log(s->avctx, AV_LOG_DEBUG, "fps:%d, br:%d, qpbit:%d, abt_flag:%d, j_type_bit:%d, tl_mv_flag:%d, mbrl_bit:%d, code:%d, flag3:%d, slices:%d\n",
+ fps, s->bit_rate, w->mspel_bit, w->abt_flag, w->j_type_bit, w->top_left_mv_flag, w->per_mb_rl_bit, code, w->flag3,
+ code);
+ }
+ return 0;
+}
+
+int ff_wmv2_decode_picture_header(MpegEncContext * s)
+{
+ Wmv2Context * const w= (Wmv2Context*)s;
+ int code;
+
+#if 0
+{
+int i;
+for(i=0; i<s->gb.size*8; i++)
+ printf("%d", get_bits1(&s->gb));
+// get_bits1(&s->gb);
+printf("END\n");
+return -1;
+}
+#endif
+ if(s->picture_number==0)
+ decode_ext_header(w);
+
+ s->pict_type = get_bits(&s->gb, 1) + 1;
+ if(s->pict_type == I_TYPE){
+ code = get_bits(&s->gb, 7);
+ av_log(s->avctx, AV_LOG_DEBUG, "I7:%X/\n", code);
+ }
+ s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
+ if(s->qscale < 0)
+ return -1;
+
+ return 0;
+}
+
+int ff_wmv2_decode_secondary_picture_header(MpegEncContext * s)
+{
+ Wmv2Context * const w= (Wmv2Context*)s;
+
+ if (s->pict_type == I_TYPE) {
+ if(w->j_type_bit) w->j_type= get_bits1(&s->gb);
+ else w->j_type= 0; //FIXME check
+
+ if(!w->j_type){
+ if(w->per_mb_rl_bit) s->per_mb_rl_table= get_bits1(&s->gb);
+ else s->per_mb_rl_table= 0;
+
+ if(!s->per_mb_rl_table){
+ s->rl_chroma_table_index = decode012(&s->gb);
+ s->rl_table_index = decode012(&s->gb);
+ }
+
+ s->dc_table_index = get_bits1(&s->gb);
+ }
+ s->inter_intra_pred= 0;
+ s->no_rounding = 1;
+ if(s->avctx->debug&FF_DEBUG_PICT_INFO){
+ av_log(s->avctx, AV_LOG_DEBUG, "qscale:%d rlc:%d rl:%d dc:%d mbrl:%d j_type:%d \n",
+ s->qscale,
+ s->rl_chroma_table_index,
+ s->rl_table_index,
+ s->dc_table_index,
+ s->per_mb_rl_table,
+ w->j_type);
+ }
+ }else{
+ int cbp_index;
+ w->j_type=0;
+
+ parse_mb_skip(w);
+ cbp_index= decode012(&s->gb);
+ if(s->qscale <= 10){
+ int map[3]= {0,2,1};
+ w->cbp_table_index= map[cbp_index];
+ }else if(s->qscale <= 20){
+ int map[3]= {1,0,2};
+ w->cbp_table_index= map[cbp_index];
+ }else{
+ int map[3]= {2,1,0};
+ w->cbp_table_index= map[cbp_index];
+ }
+
+ if(w->mspel_bit) s->mspel= get_bits1(&s->gb);
+ else s->mspel= 0; //FIXME check
+
+ if(w->abt_flag){
+ w->per_mb_abt= get_bits1(&s->gb)^1;
+ if(!w->per_mb_abt){
+ w->abt_type= decode012(&s->gb);
+ }
+ }
+
+ if(w->per_mb_rl_bit) s->per_mb_rl_table= get_bits1(&s->gb);
+ else s->per_mb_rl_table= 0;
+
+ if(!s->per_mb_rl_table){
+ s->rl_table_index = decode012(&s->gb);
+ s->rl_chroma_table_index = s->rl_table_index;
+ }
+
+ s->dc_table_index = get_bits1(&s->gb);
+ s->mv_table_index = get_bits1(&s->gb);
+
+ s->inter_intra_pred= 0;//(s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE);
+ s->no_rounding ^= 1;
+
+ if(s->avctx->debug&FF_DEBUG_PICT_INFO){
+ av_log(s->avctx, AV_LOG_DEBUG, "rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d mspel:%d per_mb_abt:%d abt_type:%d cbp:%d ii:%d\n",
+ s->rl_table_index,
+ s->rl_chroma_table_index,
+ s->dc_table_index,
+ s->mv_table_index,
+ s->per_mb_rl_table,
+ s->qscale,
+ s->mspel,
+ w->per_mb_abt,
+ w->abt_type,
+ w->cbp_table_index,
+ s->inter_intra_pred);
+ }
+ }
+ s->esc3_level_length= 0;
+ s->esc3_run_length= 0;
+
+s->picture_number++; //FIXME ?
+
+
+// if(w->j_type)
+// return wmv2_decode_j_picture(w); //FIXME
+
+ if(w->j_type){
+ av_log(s->avctx, AV_LOG_ERROR, "J-type picture is not supported\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+static inline int wmv2_decode_motion(Wmv2Context *w, int *mx_ptr, int *my_ptr){
+ MpegEncContext * const s= &w->s;
+ int ret;
+
+ ret= msmpeg4_decode_motion(s, mx_ptr, my_ptr);
+
+ if(ret<0) return -1;
+
+ if((((*mx_ptr)|(*my_ptr)) & 1) && s->mspel)
+ w->hshift= get_bits1(&s->gb);
+ else
+ w->hshift= 0;
+
+//printf("%d %d ", *mx_ptr, *my_ptr);
+
+ return 0;
+}
+
+static int16_t *wmv2_pred_motion(Wmv2Context *w, int *px, int *py){
+ MpegEncContext * const s= &w->s;
+ int xy, wrap, diff, type;
+ int16_t *A, *B, *C, *mot_val;
+
+ wrap = s->b8_stride;
+ xy = s->block_index[0];
+
+ mot_val = s->current_picture.motion_val[0][xy];
+
+ A = s->current_picture.motion_val[0][xy - 1];
+ B = s->current_picture.motion_val[0][xy - wrap];
+ C = s->current_picture.motion_val[0][xy + 2 - wrap];
+
+ if(s->mb_x && !s->first_slice_line && !s->mspel && w->top_left_mv_flag)
+ diff= FFMAX(FFABS(A[0] - B[0]), FFABS(A[1] - B[1]));
+ else
+ diff=0;
+
+ if(diff >= 8)
+ type= get_bits1(&s->gb);
+ else
+ type= 2;
+
+ if(type == 0){
+ *px= A[0];
+ *py= A[1];
+ }else if(type == 1){
+ *px= B[0];
+ *py= B[1];
+ }else{
+ /* special case for first (slice) line */
+ if (s->first_slice_line) {
+ *px = A[0];
+ *py = A[1];
+ } else {
+ *px = mid_pred(A[0], B[0], C[0]);
+ *py = mid_pred(A[1], B[1], C[1]);
+ }
+ }
+
+ return mot_val;
+}
+
+static inline int wmv2_decode_inter_block(Wmv2Context *w, DCTELEM *block, int n, int cbp){
+ MpegEncContext * const s= &w->s;
+ static const int sub_cbp_table[3]= {2,3,1};
+ int sub_cbp;
+
+ if(!cbp){
+ s->block_last_index[n] = -1;
+
+ return 0;
+ }
+
+ if(w->per_block_abt)
+ w->abt_type= decode012(&s->gb);
+#if 0
+ if(w->per_block_abt)
+ printf("B%d", w->abt_type);
+#endif
+ w->abt_type_table[n]= w->abt_type;
+
+ if(w->abt_type){
+// const uint8_t *scantable= w->abt_scantable[w->abt_type-1].permutated;
+ const uint8_t *scantable= w->abt_scantable[w->abt_type-1].scantable;
+// const uint8_t *scantable= w->abt_type-1 ? w->abt_scantable[1].permutated : w->abt_scantable[0].scantable;
+
+ sub_cbp= sub_cbp_table[ decode012(&s->gb) ];
+// printf("S%d", sub_cbp);
+
+ if(sub_cbp&1){
+ if (msmpeg4_decode_block(s, block, n, 1, scantable) < 0)
+ return -1;
+ }
+
+ if(sub_cbp&2){
+ if (msmpeg4_decode_block(s, w->abt_block2[n], n, 1, scantable) < 0)
+ return -1;
+ }
+ s->block_last_index[n] = 63;
+
+ return 0;
+ }else{
+ return msmpeg4_decode_block(s, block, n, 1, s->inter_scantable.permutated);
+ }
+}
+
+static void wmv2_add_block(Wmv2Context *w, DCTELEM *block1, uint8_t *dst, int stride, int n){
+ MpegEncContext * const s= &w->s;
+
+ if (s->block_last_index[n] >= 0) {
+ switch(w->abt_type_table[n]){
+ case 0:
+ s->dsp.idct_add (dst, stride, block1);
+ break;
+ case 1:
+ simple_idct84_add(dst , stride, block1);
+ simple_idct84_add(dst + 4*stride, stride, w->abt_block2[n]);
+ memset(w->abt_block2[n], 0, 64*sizeof(DCTELEM));
+ break;
+ case 2:
+ simple_idct48_add(dst , stride, block1);
+ simple_idct48_add(dst + 4 , stride, w->abt_block2[n]);
+ memset(w->abt_block2[n], 0, 64*sizeof(DCTELEM));
+ break;
+ default:
+ av_log(s->avctx, AV_LOG_ERROR, "internal error in WMV2 abt\n");
+ }
+ }
+}
+
+void ff_wmv2_add_mb(MpegEncContext *s, DCTELEM block1[6][64], uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr){
+ Wmv2Context * const w= (Wmv2Context*)s;
+
+ wmv2_add_block(w, block1[0], dest_y , s->linesize, 0);
+ wmv2_add_block(w, block1[1], dest_y + 8 , s->linesize, 1);
+ wmv2_add_block(w, block1[2], dest_y + 8*s->linesize, s->linesize, 2);
+ wmv2_add_block(w, block1[3], dest_y + 8 + 8*s->linesize, s->linesize, 3);
+
+ if(s->flags&CODEC_FLAG_GRAY) return;
+
+ wmv2_add_block(w, block1[4], dest_cb , s->uvlinesize, 4);
+ wmv2_add_block(w, block1[5], dest_cr , s->uvlinesize, 5);
+}
+
+void ff_mspel_motion(MpegEncContext *s,
+ uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
+ uint8_t **ref_picture, op_pixels_func (*pix_op)[4],
+ int motion_x, int motion_y, int h)
+{
+ Wmv2Context * const w= (Wmv2Context*)s;
+ uint8_t *ptr;
+ int dxy, offset, mx, my, src_x, src_y, v_edge_pos, linesize, uvlinesize;
+ int emu=0;
+
+ dxy = ((motion_y & 1) << 1) | (motion_x & 1);
+ dxy = 2*dxy + w->hshift;
+ src_x = s->mb_x * 16 + (motion_x >> 1);
+ src_y = s->mb_y * 16 + (motion_y >> 1);
+
+ /* WARNING: do no forget half pels */
+ v_edge_pos = s->v_edge_pos;
+ src_x = av_clip(src_x, -16, s->width);
+ src_y = av_clip(src_y, -16, s->height);
+
+ if(src_x<=-16 || src_x >= s->width)
+ dxy &= ~3;
+ if(src_y<=-16 || src_y >= s->height)
+ dxy &= ~4;
+
+ linesize = s->linesize;
+ uvlinesize = s->uvlinesize;
+ ptr = ref_picture[0] + (src_y * linesize) + src_x;
+
+ if(s->flags&CODEC_FLAG_EMU_EDGE){
+ if(src_x<1 || src_y<1 || src_x + 17 >= s->h_edge_pos
+ || src_y + h+1 >= v_edge_pos){
+ ff_emulated_edge_mc(s->edge_emu_buffer, ptr - 1 - s->linesize, s->linesize, 19, 19,
+ src_x-1, src_y-1, s->h_edge_pos, s->v_edge_pos);
+ ptr= s->edge_emu_buffer + 1 + s->linesize;
+ emu=1;
+ }
+ }
+
+ s->dsp.put_mspel_pixels_tab[dxy](dest_y , ptr , linesize);
+ s->dsp.put_mspel_pixels_tab[dxy](dest_y+8 , ptr+8 , linesize);
+ s->dsp.put_mspel_pixels_tab[dxy](dest_y +8*linesize, ptr +8*linesize, linesize);
+ s->dsp.put_mspel_pixels_tab[dxy](dest_y+8+8*linesize, ptr+8+8*linesize, linesize);
+
+ if(s->flags&CODEC_FLAG_GRAY) return;
+
+ if (s->out_format == FMT_H263) {
+ dxy = 0;
+ if ((motion_x & 3) != 0)
+ dxy |= 1;
+ if ((motion_y & 3) != 0)
+ dxy |= 2;
+ mx = motion_x >> 2;
+ my = motion_y >> 2;
+ } else {
+ mx = motion_x / 2;
+ my = motion_y / 2;
+ dxy = ((my & 1) << 1) | (mx & 1);
+ mx >>= 1;
+ my >>= 1;
+ }
+
+ src_x = s->mb_x * 8 + mx;
+ src_y = s->mb_y * 8 + my;
+ src_x = av_clip(src_x, -8, s->width >> 1);
+ if (src_x == (s->width >> 1))
+ dxy &= ~1;
+ src_y = av_clip(src_y, -8, s->height >> 1);
+ if (src_y == (s->height >> 1))
+ dxy &= ~2;
+ offset = (src_y * uvlinesize) + src_x;
+ ptr = ref_picture[1] + offset;
+ if(emu){
+ ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9,
+ src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
+ ptr= s->edge_emu_buffer;
+ }
+ pix_op[1][dxy](dest_cb, ptr, uvlinesize, h >> 1);
+
+ ptr = ref_picture[2] + offset;
+ if(emu){
+ ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9,
+ src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
+ ptr= s->edge_emu_buffer;
+ }
+ pix_op[1][dxy](dest_cr, ptr, uvlinesize, h >> 1);
+}
+
+
+static int wmv2_decode_mb(MpegEncContext *s, DCTELEM block[6][64])
+{
+ Wmv2Context * const w= (Wmv2Context*)s;
+ int cbp, code, i;
+ uint8_t *coded_val;
+
+ if(w->j_type) return 0;
+
+ if (s->pict_type == P_TYPE) {
+ if(IS_SKIP(s->current_picture.mb_type[s->mb_y * s->mb_stride + s->mb_x])){
+ /* 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;
+ w->hshift=0;
+ return 0;
+ }
+
+ code = get_vlc2(&s->gb, mb_non_intra_vlc[w->cbp_table_index].table, MB_NON_INTRA_VLC_BITS, 3);
+ if (code < 0)
+ return -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){
+ av_log(s->avctx, AV_LOG_ERROR, "II-cbp illegal at %d %d\n", s->mb_x, s->mb_y);
+ 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 = 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);
+ wmv2_pred_motion(w, &mx, &my);
+
+ if(cbp){
+ s->dsp.clear_blocks(s->block[0]);
+ if(s->per_mb_rl_table){
+ s->rl_table_index = decode012(&s->gb);
+ s->rl_chroma_table_index = s->rl_table_index;
+ }
+
+ if(w->abt_flag && w->per_mb_abt){
+ w->per_block_abt= get_bits1(&s->gb);
+ if(!w->per_block_abt)
+ w->abt_type= decode012(&s->gb);
+ }else
+ w->per_block_abt=0;
+ }
+
+ if (wmv2_decode_motion(w, &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;
+
+ for (i = 0; i < 6; i++) {
+ if (wmv2_decode_inter_block(w, block[i], i, (cbp >> (5 - i)) & 1) < 0)
+ {
+ av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding inter block: %d x %d (%d)\n", s->mb_x, s->mb_y, i);
+ return -1;
+ }
+ }
+ } else {
+//if(s->pict_type==P_TYPE)
+// printf("%d%d ", s->inter_intra_pred, cbp);
+//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);
+ if(s->inter_intra_pred){
+ s->h263_aic_dir= get_vlc2(&s->gb, 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 (msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
+ {
+ av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding intra block: %d x %d (%d)\n", s->mb_x, s->mb_y, i);
+ return -1;
+ }
+ }
+ }
+
+ return 0;
+}
+
+static int wmv2_decode_init(AVCodecContext *avctx){
+ Wmv2Context * const w= avctx->priv_data;
+
+ if(ff_h263_decode_init(avctx) < 0)
+ return -1;
+
+ wmv2_common_init(w);
+
+ return 0;
+}
+
+AVCodec wmv2_decoder = {
+ "wmv2",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_WMV2,
+ sizeof(Wmv2Context),
+ wmv2_decode_init,
+ NULL,
+ ff_h263_decode_end,
+ ff_h263_decode_frame,
+ CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
+};
+
+#ifdef CONFIG_ENCODERS
+AVCodec wmv2_encoder = {
+ "wmv2",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_WMV2,
+ sizeof(Wmv2Context),
+ wmv2_encode_init,
+ MPV_encode_picture,
+ MPV_encode_end,
+ .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1},
+};
+#endif
diff --git a/src/libffmpeg/libavcodec/wnv1.c b/contrib/ffmpeg/libavcodec/wnv1.c
index 46b31a5c5..46b31a5c5 100644
--- a/src/libffmpeg/libavcodec/wnv1.c
+++ b/contrib/ffmpeg/libavcodec/wnv1.c
diff --git a/src/libffmpeg/libavcodec/ws-snd1.c b/contrib/ffmpeg/libavcodec/ws-snd1.c
index 3624909a3..3624909a3 100644
--- a/src/libffmpeg/libavcodec/ws-snd1.c
+++ b/contrib/ffmpeg/libavcodec/ws-snd1.c
diff --git a/contrib/ffmpeg/libavcodec/x264.c b/contrib/ffmpeg/libavcodec/x264.c
new file mode 100644
index 000000000..c9df820f5
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/x264.c
@@ -0,0 +1,300 @@
+/*
+ * H.264 encoding using the x264 library
+ * Copyright (C) 2005 Mans Rullgard <mru@inprovide.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avcodec.h"
+#include <x264.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+typedef struct X264Context {
+ x264_param_t params;
+ x264_t *enc;
+ x264_picture_t pic;
+ AVFrame out_pic;
+} X264Context;
+
+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,
+ [X264_LOG_WARNING] = AV_LOG_ERROR,
+ [X264_LOG_INFO] = AV_LOG_INFO,
+ [X264_LOG_DEBUG] = AV_LOG_DEBUG
+ };
+
+ if(level < 0 || level > X264_LOG_DEBUG)
+ return;
+
+ av_vlog(p, level_map[level], fmt, args);
+}
+
+
+static int
+encode_nals(uint8_t *buf, int size, x264_nal_t *nals, int nnal)
+{
+ uint8_t *p = buf;
+ int i;
+
+ for(i = 0; i < nnal; i++){
+ int s = x264_nal_encode(p, &size, 1, nals + i);
+ if(s < 0)
+ return -1;
+ p += s;
+ }
+
+ return p - buf;
+}
+
+static int
+X264_frame(AVCodecContext *ctx, uint8_t *buf, int bufsize, void *data)
+{
+ X264Context *x4 = ctx->priv_data;
+ AVFrame *frame = data;
+ x264_nal_t *nal;
+ int nnal, i;
+ x264_picture_t pic_out;
+
+ 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];
+ x4->pic.img.i_stride[i] = frame->linesize[i];
+ }
+
+ 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))
+ return -1;
+
+ bufsize = encode_nals(buf, bufsize, nal, nnal);
+ if(bufsize < 0)
+ return -1;
+
+ /* FIXME: dts */
+ x4->out_pic.pts = pic_out.i_pts;
+
+ switch(pic_out.i_type){
+ case X264_TYPE_IDR:
+ case X264_TYPE_I:
+ x4->out_pic.pict_type = FF_I_TYPE;
+ break;
+ case X264_TYPE_P:
+ x4->out_pic.pict_type = FF_P_TYPE;
+ break;
+ case X264_TYPE_B:
+ case X264_TYPE_BREF:
+ x4->out_pic.pict_type = FF_B_TYPE;
+ break;
+ }
+
+ x4->out_pic.key_frame = pic_out.i_type == X264_TYPE_IDR;
+ x4->out_pic.quality = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA;
+
+ return bufsize;
+}
+
+static int
+X264_close(AVCodecContext *avctx)
+{
+ X264Context *x4 = avctx->priv_data;
+
+ if(x4->enc)
+ x264_encoder_close(x4->enc);
+
+ return 0;
+}
+
+static int
+X264_init(AVCodecContext *avctx)
+{
+ X264Context *x4 = avctx->priv_data;
+
+ x264_param_default(&x4->params);
+
+ 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.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.f_rf_constant = avctx->crf;
+ }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;
+
+ x4->params.i_bframe = avctx->max_b_frames;
+ x4->params.b_cabac = avctx->coder_type == FF_CODER_TYPE_AC;
+ x4->params.b_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_keyint_min = avctx->keyint_min;
+ if(x4->params.i_keyint_min > x4->params.i_keyint_max)
+ x4->params.i_keyint_min = x4->params.i_keyint_max;
+
+ x4->params.i_scenecut_threshold = avctx->scenechange_threshold;
+
+ x4->params.b_deblocking_filter = (avctx->flags & CODEC_FLAG_LOOP_FILTER);
+ x4->params.i_deblocking_filter_alphac0 = avctx->deblockalpha;
+ x4->params.i_deblocking_filter_beta = avctx->deblockbeta;
+
+ x4->params.rc.i_qp_min = avctx->qmin;
+ x4->params.rc.i_qp_max = avctx->qmax;
+ 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_complexity_blur = avctx->complexityblur;
+
+ 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.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)
+ x4->params.analyse.inter |= X264_ANALYSE_I8x8;
+ if(avctx->partitions & X264_PART_P8X8)
+ x4->params.analyse.inter |= X264_ANALYSE_PSUB16x16;
+ if(avctx->partitions & X264_PART_P4X4)
+ x4->params.analyse.inter |= X264_ANALYSE_PSUB8x8;
+ if(avctx->partitions & X264_PART_B8X8)
+ x4->params.analyse.inter |= X264_ANALYSE_BSUB16x16;
+ }
+
+ x4->params.analyse.i_direct_mv_pred = avctx->directpred;
+
+ x4->params.analyse.b_weighted_bipred = (avctx->flags2 & CODEC_FLAG2_WPRED);
+
+ if(avctx->me_method == ME_EPZS)
+ x4->params.analyse.i_me_method = X264_ME_DIA;
+ else if(avctx->me_method == ME_HEX)
+ x4->params.analyse.i_me_method = X264_ME_HEX;
+ else if(avctx->me_method == ME_UMH)
+ x4->params.analyse.i_me_method = X264_ME_UMH;
+ else if(avctx->me_method == ME_FULL)
+ x4->params.analyse.i_me_method = X264_ME_ESA;
+ 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.analyse.b_bidir_me = (avctx->bidir_refine > 0);
+ x4->params.analyse.b_bframe_rdo = (avctx->flags2 & CODEC_FLAG2_BRDO);
+ 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)){
+ 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;
+
+ 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.rc.psz_rc_eq = avctx->rc_eq;
+
+ x4->params.analyse.b_psnr = (avctx->flags & CODEC_FLAG_PSNR);
+ x4->params.i_log_level = X264_LOG_DEBUG;
+
+ x4->params.b_aud = (avctx->flags2 & CODEC_FLAG2_AUD);
+
+ x4->params.i_threads = avctx->thread_count;
+
+ if(avctx->flags & CODEC_FLAG_GLOBAL_HEADER){
+ x4->params.b_repeat_headers = 0;
+ }
+
+ x4->enc = x264_encoder_open(&x4->params);
+ if(!x4->enc)
+ return -1;
+
+ avctx->coded_frame = &x4->out_pic;
+
+ if(avctx->flags & CODEC_FLAG_GLOBAL_HEADER){
+ x264_nal_t *nal;
+ int nnal, i, s = 0;
+
+ 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;
+
+ avctx->extradata = av_malloc(s);
+ avctx->extradata_size = encode_nals(avctx->extradata, s, nal, nnal);
+ }
+
+ return 0;
+}
+
+AVCodec x264_encoder = {
+ .name = "h264",
+ .type = CODEC_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, -1 }
+};
diff --git a/src/libffmpeg/libavcodec/xan.c b/contrib/ffmpeg/libavcodec/xan.c
index f697514a0..f697514a0 100644
--- a/src/libffmpeg/libavcodec/xan.c
+++ b/contrib/ffmpeg/libavcodec/xan.c
diff --git a/contrib/ffmpeg/libavcodec/xiph.c b/contrib/ffmpeg/libavcodec/xiph.c
new file mode 100644
index 000000000..65c9d5603
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/xiph.c
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2007 FFmpeg Project
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "xiph.h"
+
+int ff_split_xiph_headers(uint8_t *extradata, int extradata_size,
+ int first_header_size, uint8_t *header_start[3],
+ int header_len[3])
+{
+ int i, j;
+
+ if (AV_RB16(extradata) == first_header_size) {
+ for (i=0; i<3; i++) {
+ header_len[i] = AV_RB16(extradata);
+ extradata += 2;
+ header_start[i] = extradata;
+ extradata += header_len[i];
+ }
+ } else if (extradata[0] == 2) {
+ for (i=0,j=1; i<2; i++,j++) {
+ header_len[i] = 0;
+ for (; j<extradata_size && extradata[j]==0xff; j++) {
+ header_len[i] += 0xff;
+ }
+ if (j >= extradata_size)
+ return -1;
+
+ header_len[i] += extradata[j];
+ }
+ header_len[2] = extradata_size - header_len[0] - header_len[1] - j;
+ extradata += j;
+ header_start[0] = extradata;
+ header_start[1] = header_start[0] + header_len[0];
+ header_start[2] = header_start[1] + header_len[1];
+ } else {
+ return -1;
+ }
+ return 0;
+}
diff --git a/contrib/ffmpeg/libavcodec/xiph.h b/contrib/ffmpeg/libavcodec/xiph.h
new file mode 100644
index 000000000..85cfeebaf
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/xiph.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2007 FFmpeg Project
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "common.h"
+
+/**
+ * Splits a single extradata buffer into the three headers that most
+ * Xiph codecs use. (e.g. Theora and Vorbis)
+ * Works both with Matroska's packing and lavc's packing.
+ *
+ * @param[in] extradata The single chunk that combines all three headers
+ * @param[in] extradata_size The size of the extradata buffer
+ * @param[in] first_header_size The size of the first header, used to
+ * differentiate between the Matroska packing and lavc packing.
+ * @param[out] header_start Pointers to the start of the three separate headers.
+ * @param[out] header_len The sizes of each of the three headers.
+ * @return On error a negative value is returned, on success zero.
+ */
+int ff_split_xiph_headers(uint8_t *extradata, int extradata_size,
+ int first_header_size, uint8_t *header_start[3],
+ int header_len[3]);
diff --git a/src/libffmpeg/libavcodec/xl.c b/contrib/ffmpeg/libavcodec/xl.c
index 8a011d887..8a011d887 100644
--- a/src/libffmpeg/libavcodec/xl.c
+++ b/contrib/ffmpeg/libavcodec/xl.c
diff --git a/contrib/ffmpeg/libavcodec/xvid_internal.h b/contrib/ffmpeg/libavcodec/xvid_internal.h
new file mode 100644
index 000000000..49c59c205
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/xvid_internal.h
@@ -0,0 +1,32 @@
+/*
+ * copyright (C) 2006 Corey Hickey
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 XVID_INTERNAL_H
+#define XVID_INTERNAL_H
+
+/**
+ * @file xvid_internal.h
+ * common functions for use with the XviD wrappers
+ */
+
+
+int av_tempfile(char *prefix, char **filename);
+
+#endif /* XVID_INTERNAL_H */
diff --git a/contrib/ffmpeg/libavcodec/xvid_rc.c b/contrib/ffmpeg/libavcodec/xvid_rc.c
new file mode 100644
index 000000000..6a0029e6d
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/xvid_rc.c
@@ -0,0 +1,148 @@
+/*
+ * xvid Rate control wrapper for lavc video encoders
+ *
+ * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <xvid.h>
+#include <unistd.h>
+#include "avcodec.h"
+#include "xvid_internal.h"
+//#include "dsputil.h"
+#include "mpegvideo.h"
+
+#undef NDEBUG
+#include <assert.h>
+
+extern unsigned int xvid_debug;
+
+int ff_xvid_rate_control_init(MpegEncContext *s){
+ char *tmp_name;
+ int fd, i;
+ xvid_plg_create_t xvid_plg_create;
+ xvid_plugin_2pass2_t xvid_2pass2;
+
+//xvid_debug=-1;
+
+ fd=av_tempfile("xvidrc.", &tmp_name);
+ if (fd == -1) {
+ av_log(NULL, AV_LOG_ERROR, "Can't create temporary pass2 file.\n");
+ return -1;
+ }
+
+ for(i=0; i<s->rc_context.num_entries; i++){
+ static const char *frame_types = " ipbs";
+ char tmp[256];
+ RateControlEntry *rce;
+
+ rce= &s->rc_context.entry[i];
+
+ snprintf(tmp, sizeof(tmp), "%c %d %d %d %d %d %d\n",
+ frame_types[rce->pict_type], (int)lrintf(rce->qscale / FF_QP2LAMBDA), rce->i_count, s->mb_num - rce->i_count - rce->skip_count,
+ rce->skip_count, (rce->i_tex_bits + rce->p_tex_bits + rce->misc_bits+7)/8, (rce->header_bits+rce->mv_bits+7)/8);
+
+//av_log(NULL, AV_LOG_ERROR, "%s\n", tmp);
+ write(fd, tmp, strlen(tmp));
+ }
+
+ close(fd);
+
+ memset(&xvid_2pass2, 0, sizeof(xvid_2pass2));
+ xvid_2pass2.version= XVID_MAKE_VERSION(1,1,0);
+ xvid_2pass2.filename= tmp_name;
+ xvid_2pass2.bitrate= s->avctx->bit_rate;
+ xvid_2pass2.vbv_size= s->avctx->rc_buffer_size;
+ xvid_2pass2.vbv_maxrate= s->avctx->rc_max_rate;
+ xvid_2pass2.vbv_initial= s->avctx->rc_initial_buffer_occupancy;
+
+ memset(&xvid_plg_create, 0, sizeof(xvid_plg_create));
+ xvid_plg_create.version= XVID_MAKE_VERSION(1,1,0);
+ xvid_plg_create.fbase= s->avctx->time_base.den;
+ xvid_plg_create.fincr= s->avctx->time_base.num;
+ xvid_plg_create.param= &xvid_2pass2;
+
+ if(xvid_plugin_2pass2(NULL, XVID_PLG_CREATE, &xvid_plg_create, &s->rc_context.non_lavc_opaque)<0){
+ av_log(NULL, AV_LOG_ERROR, "xvid_plugin_2pass2 failed\n");
+ return -1;
+ }
+ return 0;
+}
+
+float ff_xvid_rate_estimate_qscale(MpegEncContext *s, int dry_run){
+ xvid_plg_data_t xvid_plg_data;
+
+ memset(&xvid_plg_data, 0, sizeof(xvid_plg_data));
+ xvid_plg_data.version= XVID_MAKE_VERSION(1,1,0);
+ xvid_plg_data.width = s->width;
+ xvid_plg_data.height= s->height;
+ xvid_plg_data.mb_width = s->mb_width;
+ xvid_plg_data.mb_height= s->mb_height;
+ xvid_plg_data.fbase= s->avctx->time_base.den;
+ xvid_plg_data.fincr= s->avctx->time_base.num;
+ xvid_plg_data.min_quant[0]= s->avctx->qmin;
+ xvid_plg_data.min_quant[1]= s->avctx->qmin;
+ xvid_plg_data.min_quant[2]= s->avctx->qmin; //FIXME i/b factor & offset
+ xvid_plg_data.max_quant[0]= s->avctx->qmax;
+ xvid_plg_data.max_quant[1]= s->avctx->qmax;
+ xvid_plg_data.max_quant[2]= s->avctx->qmax; //FIXME i/b factor & offset
+ xvid_plg_data.bquant_offset = 0; // 100 * s->avctx->b_quant_offset;
+ xvid_plg_data.bquant_ratio = 100; // * s->avctx->b_quant_factor;
+
+#if 0
+ xvid_plg_data.stats.hlength= X
+#endif
+
+ if(!s->rc_context.dry_run_qscale){
+ if(s->picture_number){
+ xvid_plg_data.length=
+ xvid_plg_data.stats.length= (s->frame_bits + 7)/8;
+ xvid_plg_data.frame_num= s->rc_context.last_picture_number;
+ xvid_plg_data.quant= s->qscale;
+
+ xvid_plg_data.type= s->last_pict_type;
+ if(xvid_plugin_2pass2(s->rc_context.non_lavc_opaque, XVID_PLG_AFTER, &xvid_plg_data, NULL)){
+ av_log(s->avctx, AV_LOG_ERROR, "xvid_plugin_2pass2(handle, XVID_PLG_AFTER, ...) FAILED\n");
+ return -1;
+ }
+ }
+ s->rc_context.last_picture_number=
+ xvid_plg_data.frame_num= s->picture_number;
+ xvid_plg_data.quant= 0;
+ if(xvid_plugin_2pass2(s->rc_context.non_lavc_opaque, XVID_PLG_BEFORE, &xvid_plg_data, NULL)){
+ av_log(s->avctx, AV_LOG_ERROR, "xvid_plugin_2pass2(handle, XVID_PLG_BEFORE, ...) FAILED\n");
+ return -1;
+ }
+ s->rc_context.dry_run_qscale= xvid_plg_data.quant;
+ }
+ xvid_plg_data.quant= s->rc_context.dry_run_qscale;
+ if(!dry_run)
+ s->rc_context.dry_run_qscale= 0;
+
+ if(s->pict_type == B_TYPE) //FIXME this is not exactly identical to xvid
+ return xvid_plg_data.quant * FF_QP2LAMBDA * s->avctx->b_quant_factor + s->avctx->b_quant_offset;
+ else
+ return xvid_plg_data.quant * FF_QP2LAMBDA;
+}
+
+void ff_xvid_rate_control_uninit(MpegEncContext *s){
+ xvid_plg_destroy_t xvid_plg_destroy;
+
+ xvid_plugin_2pass2(s->rc_context.non_lavc_opaque, XVID_PLG_DESTROY, &xvid_plg_destroy, NULL);
+}
+
diff --git a/contrib/ffmpeg/libavcodec/xvidff.c b/contrib/ffmpeg/libavcodec/xvidff.c
new file mode 100644
index 000000000..590fe4b30
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/xvidff.c
@@ -0,0 +1,768 @@
+/*
+ * Interface to xvidcore for mpeg4 encoding
+ * Copyright (c) 2004 Adam Thayer <krevnik@comcast.net>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 xvidmpeg4.c
+ * Interface to xvidcore for MPEG-4 compliant encoding.
+ * @author Adam Thayer (krevnik@comcast.net)
+ */
+
+#include <xvid.h>
+#include <unistd.h>
+#include "common.h"
+#include "avcodec.h"
+#include "xvid_internal.h"
+
+/**
+ * Buffer management macros.
+ */
+#define BUFFER_SIZE 1024
+#define BUFFER_REMAINING(x) (BUFFER_SIZE - strlen(x))
+#define BUFFER_CAT(x) (&((x)[strlen(x)]))
+
+/* For PPC Use */
+#if HAVE_ALTIVEC==1
+extern int has_altivec(void);
+#endif
+
+/**
+ * Structure for the private XviD context.
+ * This stores all the private context for the codec.
+ */
+typedef struct xvid_context {
+ void *encoder_handle; /** Handle for XviD Encoder */
+ int xsize, ysize; /** Frame size */
+ int vop_flags; /** VOP flags for XviD Encoder */
+ int vol_flags; /** VOL flags for XviD Encoder */
+ int me_flags; /** Motion Estimation flags */
+ int qscale; /** Do we use constant scale? */
+ int quicktime_format; /** Are we in a QT-based format? */
+ AVFrame encoded_picture; /** Encoded frame information */
+ char *twopassbuffer; /** Character buffer for two-pass */
+ char *old_twopassbuffer; /** Old character buffer (two-pass) */
+ char *twopassfile; /** second pass temp file name */
+ unsigned char *intra_matrix; /** P-Frame Quant Matrix */
+ unsigned char *inter_matrix; /** I-Frame Quant Matrix */
+} xvid_context_t;
+
+/**
+ * Structure for the private first-pass plugin.
+ */
+typedef struct xvid_ff_pass1 {
+ int version; /** XviD version */
+ xvid_context_t *context; /** Pointer to private context */
+} xvid_ff_pass1_t;
+
+/* Prototypes - See function implementation for details */
+int xvid_strip_vol_header(AVCodecContext *avctx, unsigned char *frame, unsigned int header_len, unsigned int frame_len);
+int xvid_ff_2pass(void *ref, int opt, void *p1, void *p2);
+void xvid_correct_framerate(AVCodecContext *avctx);
+
+/**
+ * Creates the private context for the encoder.
+ * All buffers are allocated, settings are loaded from the user,
+ * and the encoder context created.
+ *
+ * @param avctx AVCodecContext pointer to context
+ * @return Returns 0 on success, -1 on failure
+ */
+int ff_xvid_encode_init(AVCodecContext *avctx) {
+ int xerr, i;
+ int xvid_flags = avctx->flags;
+ xvid_context_t *x = avctx->priv_data;
+ uint16_t *intra, *inter;
+ int fd;
+
+ xvid_plugin_single_t single;
+ xvid_ff_pass1_t rc2pass1;
+ xvid_plugin_2pass2_t rc2pass2;
+ xvid_gbl_init_t xvid_gbl_init;
+ xvid_enc_create_t xvid_enc_create;
+ xvid_enc_plugin_t plugins[7];
+
+ /* Bring in VOP flags from ffmpeg command-line */
+ x->vop_flags = XVID_VOP_HALFPEL; /* Bare minimum quality */
+ if( xvid_flags & CODEC_FLAG_4MV )
+ x->vop_flags |= XVID_VOP_INTER4V; /* Level 3 */
+ if( xvid_flags & CODEC_FLAG_TRELLIS_QUANT)
+ x->vop_flags |= XVID_VOP_TRELLISQUANT; /* Level 5 */
+ if( xvid_flags & CODEC_FLAG_AC_PRED )
+ x->vop_flags |= XVID_VOP_HQACPRED; /* Level 6 */
+ if( xvid_flags & CODEC_FLAG_GRAY )
+ x->vop_flags |= XVID_VOP_GREYSCALE;
+
+ /* Decide which ME quality setting to use */
+ x->me_flags = 0;
+ switch( avctx->me_method ) {
+ case ME_FULL: /* Quality 6 */
+ x->me_flags |= XVID_ME_EXTSEARCH16
+ | XVID_ME_EXTSEARCH8;
+
+ case ME_EPZS: /* Quality 4 */
+ x->me_flags |= XVID_ME_ADVANCEDDIAMOND8
+ | XVID_ME_HALFPELREFINE8
+ | XVID_ME_CHROMA_PVOP
+ | XVID_ME_CHROMA_BVOP;
+
+ case ME_LOG: /* Quality 2 */
+ case ME_PHODS:
+ case ME_X1:
+ x->me_flags |= XVID_ME_ADVANCEDDIAMOND16
+ | XVID_ME_HALFPELREFINE16;
+
+ case ME_ZERO: /* Quality 0 */
+ default:
+ break;
+ }
+
+ /* Decide how we should decide blocks */
+ switch( avctx->mb_decision ) {
+ case 2:
+ x->vop_flags |= XVID_VOP_MODEDECISION_RD;
+ x->me_flags |= XVID_ME_HALFPELREFINE8_RD
+ | XVID_ME_QUARTERPELREFINE8_RD
+ | XVID_ME_EXTSEARCH_RD
+ | XVID_ME_CHECKPREDICTION_RD;
+ case 1:
+ if( !(x->vop_flags & XVID_VOP_MODEDECISION_RD) )
+ x->vop_flags |= XVID_VOP_FAST_MODEDECISION_RD;
+ x->me_flags |= XVID_ME_HALFPELREFINE16_RD
+ | XVID_ME_QUARTERPELREFINE16_RD;
+
+ default:
+ break;
+ }
+
+ /* Bring in VOL flags from ffmpeg command-line */
+ x->vol_flags = 0;
+ if( xvid_flags & CODEC_FLAG_GMC ) {
+ x->vol_flags |= XVID_VOL_GMC;
+ x->me_flags |= XVID_ME_GME_REFINE;
+ }
+ if( xvid_flags & CODEC_FLAG_QPEL ) {
+ x->vol_flags |= XVID_VOL_QUARTERPEL;
+ x->me_flags |= XVID_ME_QUARTERPELREFINE16;
+ if( x->vop_flags & XVID_VOP_INTER4V )
+ x->me_flags |= XVID_ME_QUARTERPELREFINE8;
+ }
+
+ memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init));
+ xvid_gbl_init.version = XVID_VERSION;
+ xvid_gbl_init.debug = 0;
+
+#ifdef ARCH_POWERPC
+ /* XviD's PPC support is borked, use libavcodec to detect */
+#if HAVE_ALTIVEC==1
+ if( has_altivec() ) {
+ xvid_gbl_init.cpu_flags = XVID_CPU_FORCE | XVID_CPU_ALTIVEC;
+ } else
+#endif
+ xvid_gbl_init.cpu_flags = XVID_CPU_FORCE;
+#else
+ /* XviD can detect on x86 */
+ xvid_gbl_init.cpu_flags = 0;
+#endif
+
+ /* Initialize */
+ xvid_global(NULL, XVID_GBL_INIT, &xvid_gbl_init, NULL);
+
+ /* Create the encoder reference */
+ memset(&xvid_enc_create, 0, sizeof(xvid_enc_create));
+ xvid_enc_create.version = XVID_VERSION;
+
+ /* Store the desired frame size */
+ xvid_enc_create.width = x->xsize = avctx->width;
+ xvid_enc_create.height = x->ysize = avctx->height;
+
+ /* XviD can determine the proper profile to use */
+ /* xvid_enc_create.profile = XVID_PROFILE_S_L3; */
+
+ /* We don't use zones or threads */
+ xvid_enc_create.zones = NULL;
+ xvid_enc_create.num_zones = 0;
+ xvid_enc_create.num_threads = 0;
+
+ xvid_enc_create.plugins = plugins;
+ xvid_enc_create.num_plugins = 0;
+
+ /* Initialize Buffers */
+ x->twopassbuffer = NULL;
+ x->old_twopassbuffer = NULL;
+ x->twopassfile = NULL;
+
+ if( xvid_flags & CODEC_FLAG_PASS1 ) {
+ memset(&rc2pass1, 0, sizeof(xvid_ff_pass1_t));
+ rc2pass1.version = XVID_VERSION;
+ rc2pass1.context = x;
+ x->twopassbuffer = av_malloc(BUFFER_SIZE);
+ x->old_twopassbuffer = av_malloc(BUFFER_SIZE);
+ if( x->twopassbuffer == NULL || x->old_twopassbuffer == NULL ) {
+ av_log(avctx, AV_LOG_ERROR,
+ "XviD: Cannot allocate 2-pass log buffers\n");
+ return -1;
+ }
+ x->twopassbuffer[0] = x->old_twopassbuffer[0] = 0;
+
+ plugins[xvid_enc_create.num_plugins].func = xvid_ff_2pass;
+ plugins[xvid_enc_create.num_plugins].param = &rc2pass1;
+ xvid_enc_create.num_plugins++;
+ } else if( xvid_flags & CODEC_FLAG_PASS2 ) {
+ memset(&rc2pass2, 0, sizeof(xvid_plugin_2pass2_t));
+ rc2pass2.version = XVID_VERSION;
+ rc2pass2.bitrate = avctx->bit_rate;
+
+ fd = av_tempfile("xvidff.", &(x->twopassfile));
+ if( fd == -1 ) {
+ av_log(avctx, AV_LOG_ERROR,
+ "XviD: Cannot write 2-pass pipe\n");
+ return -1;
+ }
+
+ if( avctx->stats_in == NULL ) {
+ av_log(avctx, AV_LOG_ERROR,
+ "XviD: No 2-pass information loaded for second pass\n");
+ return -1;
+ }
+
+ if( strlen(avctx->stats_in) >
+ write(fd, avctx->stats_in, strlen(avctx->stats_in)) ) {
+ close(fd);
+ av_log(avctx, AV_LOG_ERROR,
+ "XviD: Cannot write to 2-pass pipe\n");
+ return -1;
+ }
+
+ close(fd);
+ rc2pass2.filename = x->twopassfile;
+ plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass2;
+ plugins[xvid_enc_create.num_plugins].param = &rc2pass2;
+ xvid_enc_create.num_plugins++;
+ } else if( !(xvid_flags & CODEC_FLAG_QSCALE) ) {
+ /* Single Pass Bitrate Control! */
+ memset(&single, 0, sizeof(xvid_plugin_single_t));
+ single.version = XVID_VERSION;
+ single.bitrate = avctx->bit_rate;
+
+ plugins[xvid_enc_create.num_plugins].func = xvid_plugin_single;
+ plugins[xvid_enc_create.num_plugins].param = &single;
+ xvid_enc_create.num_plugins++;
+ }
+
+ /* Luminance Masking */
+ if( 0.0 != avctx->lumi_masking ) {
+ plugins[xvid_enc_create.num_plugins].func = xvid_plugin_lumimasking;
+ plugins[xvid_enc_create.num_plugins].param = NULL;
+ xvid_enc_create.num_plugins++;
+ }
+
+ /* Frame Rate and Key Frames */
+ xvid_correct_framerate(avctx);
+ xvid_enc_create.fincr = avctx->time_base.num;
+ xvid_enc_create.fbase = avctx->time_base.den;
+ if( avctx->gop_size > 0 )
+ xvid_enc_create.max_key_interval = avctx->gop_size;
+ else
+ xvid_enc_create.max_key_interval = 240; /* XviD's best default */
+
+ /* Quants */
+ if( xvid_flags & CODEC_FLAG_QSCALE ) x->qscale = 1;
+ else x->qscale = 0;
+
+ xvid_enc_create.min_quant[0] = avctx->qmin;
+ xvid_enc_create.min_quant[1] = avctx->qmin;
+ xvid_enc_create.min_quant[2] = avctx->qmin;
+ xvid_enc_create.max_quant[0] = avctx->qmax;
+ xvid_enc_create.max_quant[1] = avctx->qmax;
+ xvid_enc_create.max_quant[2] = avctx->qmax;
+
+ /* Quant Matrices */
+ x->intra_matrix = x->inter_matrix = NULL;
+ if( avctx->mpeg_quant )
+ x->vol_flags |= XVID_VOL_MPEGQUANT;
+ if( (avctx->intra_matrix || avctx->inter_matrix) ) {
+ x->vol_flags |= XVID_VOL_MPEGQUANT;
+
+ if( avctx->intra_matrix ) {
+ intra = avctx->intra_matrix;
+ x->intra_matrix = av_malloc(sizeof(unsigned char) * 64);
+ } else
+ intra = NULL;
+ if( avctx->inter_matrix ) {
+ inter = avctx->inter_matrix;
+ x->inter_matrix = av_malloc(sizeof(unsigned char) * 64);
+ } else
+ inter = NULL;
+
+ for( i = 0; i < 64; i++ ) {
+ if( intra )
+ x->intra_matrix[i] = (unsigned char)intra[i];
+ if( inter )
+ x->inter_matrix[i] = (unsigned char)inter[i];
+ }
+ }
+
+ /* Misc Settings */
+ xvid_enc_create.frame_drop_ratio = 0;
+ xvid_enc_create.global = 0;
+ if( xvid_flags & CODEC_FLAG_CLOSED_GOP )
+ xvid_enc_create.global |= XVID_GLOBAL_CLOSED_GOP;
+
+ /* Determines which codec mode we are operating in */
+ avctx->extradata = NULL;
+ avctx->extradata_size = 0;
+ if( xvid_flags & CODEC_FLAG_GLOBAL_HEADER ) {
+ /* In this case, we are claiming to be MPEG4 */
+ x->quicktime_format = 1;
+ avctx->codec_id = CODEC_ID_MPEG4;
+ } else {
+ /* We are claiming to be XviD */
+ x->quicktime_format = 0;
+ if(!avctx->codec_tag)
+ avctx->codec_tag = ff_get_fourcc("xvid");
+ }
+
+ /* Bframes */
+ xvid_enc_create.max_bframes = avctx->max_b_frames;
+ xvid_enc_create.bquant_offset = 100 * avctx->b_quant_offset;
+ xvid_enc_create.bquant_ratio = 100 * avctx->b_quant_factor;
+ if( avctx->max_b_frames > 0 && !x->quicktime_format ) xvid_enc_create.global |= XVID_GLOBAL_PACKED;
+
+ /* Create encoder context */
+ xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL);
+ if( xerr ) {
+ av_log(avctx, AV_LOG_ERROR, "XviD: Could not create encoder reference\n");
+ return -1;
+ }
+
+ x->encoder_handle = xvid_enc_create.handle;
+ avctx->coded_frame = &x->encoded_picture;
+
+ return 0;
+}
+
+/**
+ * Encodes a single frame.
+ *
+ * @param avctx AVCodecContext pointer to context
+ * @param frame Pointer to encoded frame buffer
+ * @param buf_size Size of encoded frame buffer
+ * @param data Pointer to AVFrame of unencoded frame
+ * @return Returns 0 on success, -1 on failure
+ */
+int ff_xvid_encode_frame(AVCodecContext *avctx,
+ unsigned char *frame, int buf_size, void *data) {
+ int xerr, i;
+ char *tmp;
+ xvid_context_t *x = avctx->priv_data;
+ AVFrame *picture = data;
+ AVFrame *p = &(x->encoded_picture);
+
+ xvid_enc_frame_t xvid_enc_frame;
+ xvid_enc_stats_t xvid_enc_stats;
+
+ /* Start setting up the frame */
+ memset(&xvid_enc_frame, 0, sizeof(xvid_enc_frame));
+ xvid_enc_frame.version = XVID_VERSION;
+ memset(&xvid_enc_stats, 0, sizeof(xvid_enc_stats));
+ xvid_enc_stats.version = XVID_VERSION;
+ *p = *picture;
+
+ /* Let XviD know where to put the frame. */
+ xvid_enc_frame.bitstream = frame;
+ xvid_enc_frame.length = buf_size;
+
+ /* Initialize input image fields */
+ if( avctx->pix_fmt != PIX_FMT_YUV420P ) {
+ av_log(avctx, AV_LOG_ERROR, "XviD: Color spaces other than 420p not supported\n");
+ return -1;
+ }
+
+ xvid_enc_frame.input.csp = XVID_CSP_PLANAR; /* YUV420P */
+
+ for( i = 0; i < 4; i++ ) {
+ xvid_enc_frame.input.plane[i] = picture->data[i];
+ xvid_enc_frame.input.stride[i] = picture->linesize[i];
+ }
+
+ /* Encoder Flags */
+ xvid_enc_frame.vop_flags = x->vop_flags;
+ xvid_enc_frame.vol_flags = x->vol_flags;
+ xvid_enc_frame.motion = x->me_flags;
+ xvid_enc_frame.type = XVID_TYPE_AUTO;
+
+ /* Quant Setting */
+ if( x->qscale ) xvid_enc_frame.quant = picture->quality / FF_QP2LAMBDA;
+ else xvid_enc_frame.quant = 0;
+
+ /* Matrices */
+ xvid_enc_frame.quant_intra_matrix = x->intra_matrix;
+ xvid_enc_frame.quant_inter_matrix = x->inter_matrix;
+
+ /* Encode */
+ xerr = xvid_encore(x->encoder_handle, XVID_ENC_ENCODE,
+ &xvid_enc_frame, &xvid_enc_stats);
+
+ /* Two-pass log buffer swapping */
+ avctx->stats_out = NULL;
+ if( x->twopassbuffer ) {
+ tmp = x->old_twopassbuffer;
+ x->old_twopassbuffer = x->twopassbuffer;
+ x->twopassbuffer = tmp;
+ x->twopassbuffer[0] = 0;
+ if( x->old_twopassbuffer[0] != 0 ) {
+ avctx->stats_out = x->old_twopassbuffer;
+ }
+ }
+
+ if( 0 <= xerr ) {
+ p->quality = xvid_enc_stats.quant * FF_QP2LAMBDA;
+ if( xvid_enc_stats.type == XVID_TYPE_PVOP )
+ p->pict_type = FF_P_TYPE;
+ else if( xvid_enc_stats.type == XVID_TYPE_BVOP )
+ p->pict_type = FF_B_TYPE;
+ else if( xvid_enc_stats.type == XVID_TYPE_SVOP )
+ p->pict_type = FF_S_TYPE;
+ else
+ p->pict_type = FF_I_TYPE;
+ if( xvid_enc_frame.out_flags & XVID_KEYFRAME ) {
+ p->key_frame = 1;
+ if( x->quicktime_format )
+ return xvid_strip_vol_header(avctx, frame,
+ xvid_enc_stats.hlength, xerr);
+ } else
+ p->key_frame = 0;
+
+ return xerr;
+ } else {
+ av_log(avctx, AV_LOG_ERROR, "XviD: Encoding Error Occurred: %i\n", xerr);
+ return -1;
+ }
+}
+
+/**
+ * Destroys the private context for the encoder.
+ * All buffers are freed, and the XviD encoder context is destroyed.
+ *
+ * @param avctx AVCodecContext pointer to context
+ * @return Returns 0, success guaranteed
+ */
+int ff_xvid_encode_close(AVCodecContext *avctx) {
+ xvid_context_t *x = avctx->priv_data;
+
+ xvid_encore(x->encoder_handle, XVID_ENC_DESTROY, NULL, NULL);
+
+ if( avctx->extradata != NULL )
+ av_free(avctx->extradata);
+ if( x->twopassbuffer != NULL ) {
+ av_free(x->twopassbuffer);
+ av_free(x->old_twopassbuffer);
+ }
+ if( x->twopassfile != NULL )
+ av_free(x->twopassfile);
+ if( x->intra_matrix != NULL )
+ av_free(x->intra_matrix);
+ if( x->inter_matrix != NULL )
+ av_free(x->inter_matrix);
+
+ return 0;
+}
+
+/**
+ * Routine to create a global VO/VOL header for MP4 container.
+ * What we do here is extract the header from the XviD bitstream
+ * as it is encoded. We also strip the repeated headers from the
+ * bitstream when a global header is requested for MPEG-4 ISO
+ * compliance.
+ *
+ * @param avctx AVCodecContext pointer to context
+ * @param frame Pointer to encoded frame data
+ * @param header_len Length of header to search
+ * @param frame_len Length of encoded frame data
+ * @return Returns new length of frame data
+ */
+int xvid_strip_vol_header(AVCodecContext *avctx,
+ unsigned char *frame,
+ unsigned int header_len,
+ unsigned int frame_len) {
+ int vo_len = 0, i;
+
+ for( i = 0; i < header_len - 3; i++ ) {
+ if( frame[i] == 0x00 &&
+ frame[i+1] == 0x00 &&
+ frame[i+2] == 0x01 &&
+ frame[i+3] == 0xB6 ) {
+ vo_len = i;
+ break;
+ }
+ }
+
+ if( vo_len > 0 ) {
+ /* We need to store the header, so extract it */
+ if( avctx->extradata == NULL ) {
+ avctx->extradata = av_malloc(vo_len);
+ memcpy(avctx->extradata, frame, vo_len);
+ avctx->extradata_size = vo_len;
+ }
+ /* Less dangerous now, memmove properly copies the two
+ chunks of overlapping data */
+ memmove(frame, &(frame[vo_len]), frame_len - vo_len);
+ return frame_len - vo_len;
+ } else
+ return frame_len;
+}
+
+/**
+ * Routine to correct a possibly erroneous framerate being fed to us.
+ * XviD currently chokes on framerates where the ticks per frame is
+ * extremely large. This function works to correct problems in this area
+ * by estimating a new framerate and taking the simpler fraction of
+ * the two presented.
+ *
+ * @param avctx Context that contains the framerate to correct.
+ */
+void xvid_correct_framerate(AVCodecContext *avctx) {
+ int frate, fbase;
+ int est_frate, est_fbase;
+ int gcd;
+ float est_fps, fps;
+
+ frate = avctx->time_base.den;
+ fbase = avctx->time_base.num;
+
+ gcd = ff_gcd(frate, fbase);
+ if( gcd > 1 ) {
+ frate /= gcd;
+ fbase /= gcd;
+ }
+
+ if( frate <= 65000 && fbase <= 65000 ) {
+ avctx->time_base.den = frate;
+ avctx->time_base.num = fbase;
+ return;
+ }
+
+ fps = (float)frate / (float)fbase;
+ est_fps = roundf(fps * 1000.0) / 1000.0;
+
+ est_frate = (int)est_fps;
+ if( est_fps > (int)est_fps ) {
+ est_frate = (est_frate + 1) * 1000;
+ est_fbase = (int)roundf((float)est_frate / est_fps);
+ } else
+ est_fbase = 1;
+
+ gcd = ff_gcd(est_frate, est_fbase);
+ if( gcd > 1 ) {
+ est_frate /= gcd;
+ est_fbase /= gcd;
+ }
+
+ if( fbase > est_fbase ) {
+ avctx->time_base.den = est_frate;
+ avctx->time_base.num = est_fbase;
+ av_log(avctx, AV_LOG_DEBUG,
+ "XviD: framerate re-estimated: %.2f, %.3f%% correction\n",
+ est_fps, (((est_fps - fps)/fps) * 100.0));
+ } else {
+ avctx->time_base.den = frate;
+ avctx->time_base.num = fbase;
+ }
+}
+
+/*
+ * XviD 2-Pass Kludge Section
+ *
+ * XviD's default 2-pass doesn't allow us to create data as we need to, so
+ * this section spends time replacing the first pass plugin so we can write
+ * statistic information as libavcodec requests in. We have another kludge
+ * that allows us to pass data to the second pass in XviD without a custom
+ * rate-control plugin.
+ */
+
+/**
+ * Initializes the two-pass plugin and context.
+ *
+ * @param param Input construction parameter structure
+ * @param handle Private context handle
+ * @return Returns XVID_ERR_xxxx on failure, or 0 on success.
+ */
+static int xvid_ff_2pass_create(xvid_plg_create_t * param,
+ void ** handle) {
+ xvid_ff_pass1_t *x = (xvid_ff_pass1_t *)param->param;
+ char *log = x->context->twopassbuffer;
+
+ /* Do a quick bounds check */
+ if( log == NULL )
+ return XVID_ERR_FAIL;
+
+ /* We use snprintf() */
+ /* This is because we can safely prevent a buffer overflow */
+ log[0] = 0;
+ snprintf(log, BUFFER_REMAINING(log),
+ "# ffmpeg 2-pass log file, using xvid codec\n");
+ snprintf(BUFFER_CAT(log), BUFFER_REMAINING(log),
+ "# Do not modify. libxvidcore version: %d.%d.%d\n\n",
+ XVID_VERSION_MAJOR(XVID_VERSION),
+ XVID_VERSION_MINOR(XVID_VERSION),
+ XVID_VERSION_PATCH(XVID_VERSION));
+
+ *handle = x->context;
+ return 0;
+}
+
+/**
+ * Destroys the two-pass plugin context.
+ *
+ * @param ref Context pointer for the plugin
+ * @param param Destrooy context
+ * @return Returns 0, success guaranteed
+ */
+static int xvid_ff_2pass_destroy(xvid_context_t *ref,
+ xvid_plg_destroy_t *param) {
+ /* Currently cannot think of anything to do on destruction */
+ /* Still, the framework should be here for reference/use */
+ if( ref->twopassbuffer != NULL )
+ ref->twopassbuffer[0] = 0;
+ return 0;
+}
+
+/**
+ * Enables fast encode mode during the first pass.
+ *
+ * @param ref Context pointer for the plugin
+ * @param param Frame data
+ * @return Returns 0, success guaranteed
+ */
+static int xvid_ff_2pass_before(xvid_context_t *ref,
+ xvid_plg_data_t *param) {
+ int motion_remove;
+ int motion_replacements;
+ int vop_remove;
+
+ /* Nothing to do here, result is changed too much */
+ if( param->zone && param->zone->mode == XVID_ZONE_QUANT )
+ return 0;
+
+ /* We can implement a 'turbo' first pass mode here */
+ param->quant = 2;
+
+ /* Init values */
+ motion_remove = ~XVID_ME_CHROMA_PVOP &
+ ~XVID_ME_CHROMA_BVOP &
+ ~XVID_ME_EXTSEARCH16 &
+ ~XVID_ME_ADVANCEDDIAMOND16;
+ motion_replacements = XVID_ME_FAST_MODEINTERPOLATE |
+ XVID_ME_SKIP_DELTASEARCH |
+ XVID_ME_FASTREFINE16 |
+ XVID_ME_BFRAME_EARLYSTOP;
+ vop_remove = ~XVID_VOP_MODEDECISION_RD &
+ ~XVID_VOP_FAST_MODEDECISION_RD &
+ ~XVID_VOP_TRELLISQUANT &
+ ~XVID_VOP_INTER4V &
+ ~XVID_VOP_HQACPRED;
+
+ param->vol_flags &= ~XVID_VOL_GMC;
+ param->vop_flags &= vop_remove;
+ param->motion_flags &= motion_remove;
+ param->motion_flags |= motion_replacements;
+
+ return 0;
+}
+
+/**
+ * Captures statistic data and writes it during first pass.
+ *
+ * @param ref Context pointer for the plugin
+ * @param param Statistic data
+ * @return Returns XVID_ERR_xxxx on failure, or 0 on success
+ */
+static int xvid_ff_2pass_after(xvid_context_t *ref,
+ xvid_plg_data_t *param) {
+ char *log = ref->twopassbuffer;
+ char *frame_types = " ipbs";
+ char frame_type;
+
+ /* Quick bounds check */
+ if( log == NULL )
+ return XVID_ERR_FAIL;
+
+ /* Convert the type given to us into a character */
+ if( param->type < 5 && param->type > 0 ) {
+ frame_type = frame_types[param->type];
+ } else {
+ return XVID_ERR_FAIL;
+ }
+
+ snprintf(BUFFER_CAT(log), BUFFER_REMAINING(log),
+ "%c %d %d %d %d %d %d\n",
+ frame_type, param->stats.quant, param->stats.kblks, param->stats.mblks,
+ param->stats.ublks, param->stats.length, param->stats.hlength);
+
+ return 0;
+}
+
+/**
+ * Dispatch function for our custom plugin.
+ * This handles the dispatch for the XviD plugin. It passes data
+ * on to other functions for actual processing.
+ *
+ * @param ref Context pointer for the plugin
+ * @param cmd The task given for us to complete
+ * @param p1 First parameter (varies)
+ * @param p2 Second parameter (varies)
+ * @return Returns XVID_ERR_xxxx on failure, or 0 on success
+ */
+int xvid_ff_2pass(void *ref, int cmd, void *p1, void *p2) {
+ switch( cmd ) {
+ case XVID_PLG_INFO:
+ case XVID_PLG_FRAME:
+ return 0;
+
+ case XVID_PLG_BEFORE:
+ return xvid_ff_2pass_before(ref, p1);
+
+ case XVID_PLG_CREATE:
+ return xvid_ff_2pass_create(p1, p2);
+
+ case XVID_PLG_AFTER:
+ return xvid_ff_2pass_after(ref, p1);
+
+ case XVID_PLG_DESTROY:
+ return xvid_ff_2pass_destroy(ref, p1);
+
+ default:
+ return XVID_ERR_FAIL;
+ }
+}
+
+/**
+ * XviD codec definition for libavcodec.
+ */
+AVCodec xvid_encoder = {
+ "xvid",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_XVID,
+ sizeof(xvid_context_t),
+ ff_xvid_encode_init,
+ ff_xvid_encode_frame,
+ ff_xvid_encode_close,
+ .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1},
+};
diff --git a/contrib/ffmpeg/libavcodec/xvmc_render.h b/contrib/ffmpeg/libavcodec/xvmc_render.h
new file mode 100644
index 000000000..37b342294
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/xvmc_render.h
@@ -0,0 +1,50 @@
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xatom.h>
+#include <X11/extensions/Xv.h>
+#include <X11/extensions/Xvlib.h>
+#include <X11/extensions/XvMClib.h>
+
+
+//the surface should be shown, video driver manipulate this
+#define MP_XVMC_STATE_DISPLAY_PENDING 1
+//the surface is needed for prediction, codec manipulate this
+#define MP_XVMC_STATE_PREDICTION 2
+//this surface is needed for subpicture rendering
+#define MP_XVMC_STATE_OSD_SOURCE 4
+// 1337 IDCT MCo
+#define MP_XVMC_RENDER_MAGIC 0x1DC711C0
+
+typedef struct{
+//these are not changed by decoder!
+ int magic;
+
+ short * data_blocks;
+ XvMCMacroBlock * mv_blocks;
+ int total_number_of_mv_blocks;
+ int total_number_of_data_blocks;
+ int mc_type;//XVMC_MPEG1/2/4,XVMC_H263 without XVMC_IDCT
+ int idct;//does we use IDCT acceleration?
+ int chroma_format;//420,422,444
+ int unsigned_intra;//+-128 for intra pictures after clip
+ XvMCSurface* p_surface;//pointer to rendered surface, never changed
+
+//these are changed by decoder
+//used by XvMCRenderSurface function
+ XvMCSurface* p_past_surface;//pointer to the past surface
+ XvMCSurface* p_future_surface;//pointer to the future prediction surface
+
+ unsigned int picture_structure;//top/bottom fields or frame !
+ unsigned int flags;//XVMC_SECOND_FIELD - 1'st or 2'd field in the sequence
+ unsigned int display_flags; //1,2 or 1+2 fields for XvMCPutSurface,
+
+//these are internal communication one
+ int state;//0-free,1 Waiting to Display,2 Waiting for prediction
+ int start_mv_blocks_num;//offset in the array for the current slice,updated by vo
+ int filled_mv_blocks_num;//processed mv block in this slice,change by decoder
+
+ int next_free_data_block_num;//used in add_mv_block, pointer to next free block
+//extensions
+ void * p_osd_target_surface_render;//pointer to the surface where subpicture is rendered
+
+} xvmc_render_state_t;
diff --git a/contrib/ffmpeg/libavcodec/xvmcvideo.c b/contrib/ffmpeg/libavcodec/xvmcvideo.c
new file mode 100644
index 000000000..4a0677f6e
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/xvmcvideo.c
@@ -0,0 +1,318 @@
+/*
+ * XVideo Motion Compensation
+ * Copyright (c) 2003 Ivan Kalvachev
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 <limits.h>
+
+//avcodec include
+#include "avcodec.h"
+#include "dsputil.h"
+#include "mpegvideo.h"
+
+#undef NDEBUG
+#include <assert.h>
+
+#ifdef USE_FASTMEMCPY
+#include "libvo/fastmemcpy.h"
+#endif
+
+#ifdef HAVE_XVMC
+
+//X11 includes are in the xvmc_render.h
+//by replacing it with none-X one
+//XvMC emulation could be performed
+
+#include "xvmc_render.h"
+
+//#include "xvmc_debug.h"
+
+//set s->block
+inline void XVMC_init_block(MpegEncContext *s){
+xvmc_render_state_t * render;
+ render = (xvmc_render_state_t*)s->current_picture.data[2];
+ assert(render != NULL);
+ if( (render == NULL) || (render->magic != MP_XVMC_RENDER_MAGIC) ){
+ assert(0);
+ return;//make sure that this is render packet
+ }
+ s->block =(DCTELEM *)(render->data_blocks+(render->next_free_data_block_num)*64);
+}
+
+void XVMC_pack_pblocks(MpegEncContext *s, int cbp){
+int i,j;
+const int mb_block_count = 4+(1<<s->chroma_format);
+
+ j=0;
+ cbp<<= 12-mb_block_count;
+ for(i=0; i<mb_block_count; i++){
+ if(cbp & (1<<11)) {
+ s->pblocks[i] = (short *)(&s->block[(j++)]);
+ }else{
+ s->pblocks[i] = NULL;
+ }
+ cbp+=cbp;
+// printf("s->pblocks[%d]=%p ,s->block=%p cbp=%d\n",i,s->pblocks[i],s->block,cbp);
+ }
+}
+
+//these functions should be called on every new field or/and frame
+//They should be safe if they are called few times for same field!
+int XVMC_field_start(MpegEncContext*s, AVCodecContext *avctx){
+xvmc_render_state_t * render,* last, * next;
+
+ assert(avctx != NULL);
+
+ render = (xvmc_render_state_t*)s->current_picture.data[2];
+ assert(render != NULL);
+ if( (render == NULL) || (render->magic != MP_XVMC_RENDER_MAGIC) )
+ return -1;//make sure that this is render packet
+
+ render->picture_structure = s->picture_structure;
+ render->flags = (s->first_field)? 0: XVMC_SECOND_FIELD;
+
+//make sure that all data is drawn by XVMC_end_frame
+ assert(render->filled_mv_blocks_num==0);
+
+ render->p_future_surface = NULL;
+ render->p_past_surface = NULL;
+
+ switch(s->pict_type){
+ case I_TYPE:
+ return 0;// no prediction from other frames
+ case B_TYPE:
+ next = (xvmc_render_state_t*)s->next_picture.data[2];
+ assert(next!=NULL);
+ assert(next->state & MP_XVMC_STATE_PREDICTION);
+ if(next == NULL) return -1;
+ if(next->magic != MP_XVMC_RENDER_MAGIC) return -1;
+ render->p_future_surface = next->p_surface;
+ //no return here, going to set forward prediction
+ case P_TYPE:
+ last = (xvmc_render_state_t*)s->last_picture.data[2];
+ if(last == NULL)// && !s->first_field)
+ last = render;//predict second field from the first
+ if(last->magic != MP_XVMC_RENDER_MAGIC) return -1;
+ assert(last->state & MP_XVMC_STATE_PREDICTION);
+ render->p_past_surface = last->p_surface;
+ return 0;
+ }
+
+return -1;
+}
+
+void XVMC_field_end(MpegEncContext *s){
+xvmc_render_state_t * render;
+ render = (xvmc_render_state_t*)s->current_picture.data[2];
+ assert(render != NULL);
+
+ if(render->filled_mv_blocks_num > 0){
+// printf("xvmcvideo.c: rendering %d left blocks after last slice!!!\n",render->filled_mv_blocks_num );
+ ff_draw_horiz_band(s,0,0);
+ }
+}
+
+void XVMC_decode_mb(MpegEncContext *s){
+XvMCMacroBlock * mv_block;
+xvmc_render_state_t * render;
+int i,cbp,blocks_per_mb;
+
+const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
+
+
+ if(s->encoding){
+ av_log(s->avctx, AV_LOG_ERROR, "XVMC doesn't support encoding!!!\n");
+ return;
+ }
+
+ //from MPV_decode_mb(),
+ /* update DC predictors for P macroblocks */
+ if (!s->mb_intra) {
+ s->last_dc[0] =
+ s->last_dc[1] =
+ s->last_dc[2] = 128 << s->intra_dc_precision;
+ }
+
+ //MC doesn't skip blocks
+ s->mb_skipped = 0;
+
+
+ // do I need to export quant when I could not perform postprocessing?
+ // anyway, it doesn't hurrt
+ s->current_picture.qscale_table[mb_xy] = s->qscale;
+
+//START OF XVMC specific code
+ render = (xvmc_render_state_t*)s->current_picture.data[2];
+ assert(render!=NULL);
+ assert(render->magic==MP_XVMC_RENDER_MAGIC);
+ assert(render->mv_blocks);
+
+ //take the next free macroblock
+ mv_block = &render->mv_blocks[render->start_mv_blocks_num +
+ render->filled_mv_blocks_num ];
+
+// memset(mv_block,0,sizeof(XvMCMacroBlock));
+
+ mv_block->x = s->mb_x;
+ mv_block->y = s->mb_y;
+ mv_block->dct_type = s->interlaced_dct;//XVMC_DCT_TYPE_FRAME/FIELD;
+// mv_block->motion_type = 0; //zero to silense warnings
+ if(s->mb_intra){
+ mv_block->macroblock_type = XVMC_MB_TYPE_INTRA;//no MC, all done
+ }else{
+ mv_block->macroblock_type = XVMC_MB_TYPE_PATTERN;
+
+ if(s->mv_dir & MV_DIR_FORWARD){
+ mv_block->macroblock_type|= XVMC_MB_TYPE_MOTION_FORWARD;
+ //pmv[n][dir][xy]=mv[dir][n][xy]
+ mv_block->PMV[0][0][0] = s->mv[0][0][0];
+ mv_block->PMV[0][0][1] = s->mv[0][0][1];
+ mv_block->PMV[1][0][0] = s->mv[0][1][0];
+ mv_block->PMV[1][0][1] = s->mv[0][1][1];
+ }
+ if(s->mv_dir & MV_DIR_BACKWARD){
+ mv_block->macroblock_type|=XVMC_MB_TYPE_MOTION_BACKWARD;
+ mv_block->PMV[0][1][0] = s->mv[1][0][0];
+ mv_block->PMV[0][1][1] = s->mv[1][0][1];
+ mv_block->PMV[1][1][0] = s->mv[1][1][0];
+ mv_block->PMV[1][1][1] = s->mv[1][1][1];
+ }
+
+ switch(s->mv_type){
+ case MV_TYPE_16X16:
+ mv_block->motion_type = XVMC_PREDICTION_FRAME;
+ break;
+ case MV_TYPE_16X8:
+ mv_block->motion_type = XVMC_PREDICTION_16x8;
+ break;
+ case MV_TYPE_FIELD:
+ mv_block->motion_type = XVMC_PREDICTION_FIELD;
+ if(s->picture_structure == PICT_FRAME){
+ mv_block->PMV[0][0][1]<<=1;
+ mv_block->PMV[1][0][1]<<=1;
+ mv_block->PMV[0][1][1]<<=1;
+ mv_block->PMV[1][1][1]<<=1;
+ }
+ break;
+ case MV_TYPE_DMV:
+ mv_block->motion_type = XVMC_PREDICTION_DUAL_PRIME;
+ if(s->picture_structure == PICT_FRAME){
+
+ mv_block->PMV[0][0][0] = s->mv[0][0][0];//top from top
+ mv_block->PMV[0][0][1] = s->mv[0][0][1]<<1;
+
+ mv_block->PMV[0][1][0] = s->mv[0][0][0];//bottom from bottom
+ mv_block->PMV[0][1][1] = s->mv[0][0][1]<<1;
+
+ mv_block->PMV[1][0][0] = s->mv[0][2][0];//dmv00, top from bottom
+ mv_block->PMV[1][0][1] = s->mv[0][2][1]<<1;//dmv01
+
+ mv_block->PMV[1][1][0] = s->mv[0][3][0];//dmv10, bottom from top
+ mv_block->PMV[1][1][1] = s->mv[0][3][1]<<1;//dmv11
+
+ }else{
+ mv_block->PMV[0][1][0] = s->mv[0][2][0];//dmv00
+ mv_block->PMV[0][1][1] = s->mv[0][2][1];//dmv01
+ }
+ break;
+ default:
+ assert(0);
+ }
+
+ mv_block->motion_vertical_field_select = 0;
+
+//set correct field referenses
+ if(s->mv_type == MV_TYPE_FIELD || s->mv_type == MV_TYPE_16X8){
+ if( s->field_select[0][0] ) mv_block->motion_vertical_field_select|=1;
+ if( s->field_select[1][0] ) mv_block->motion_vertical_field_select|=2;
+ if( s->field_select[0][1] ) mv_block->motion_vertical_field_select|=4;
+ if( s->field_select[1][1] ) mv_block->motion_vertical_field_select|=8;
+ }
+ }//!intra
+//time to handle data blocks;
+ mv_block->index = render->next_free_data_block_num;
+
+ blocks_per_mb = 6;
+ if( s->chroma_format >= 2){
+ blocks_per_mb = 4 + (1 << (s->chroma_format));
+ }
+
+// calculate cbp
+ cbp = 0;
+ for(i=0; i<blocks_per_mb; i++) {
+ cbp+= cbp;
+ if(s->block_last_index[i] >= 0)
+ cbp++;
+ }
+
+ if(s->flags & CODEC_FLAG_GRAY){
+ if(s->mb_intra){//intra frames are alwasy full chroma block
+ for(i=4; i<blocks_per_mb; i++){
+ memset(s->pblocks[i],0,sizeof(short)*8*8);//so we need to clear them
+ if(!render->unsigned_intra)
+ s->pblocks[i][0] = 1<<10;
+ }
+ }else{
+ cbp&= 0xf << (blocks_per_mb - 4);
+ blocks_per_mb = 4;//Luminance blocks only
+ }
+ }
+ mv_block->coded_block_pattern = cbp;
+ if(cbp == 0)
+ mv_block->macroblock_type &= ~XVMC_MB_TYPE_PATTERN;
+
+ for(i=0; i<blocks_per_mb; i++){
+ if(s->block_last_index[i] >= 0){
+ // i do not have unsigned_intra MOCO to test, hope it is OK
+ if( (s->mb_intra) && ( render->idct || (!render->idct && !render->unsigned_intra)) )
+ s->pblocks[i][0]-=1<<10;
+ if(!render->idct){
+ s->dsp.idct(s->pblocks[i]);
+ //!!TODO!clip!!!
+ }
+//copy blocks only if the codec doesn't support pblocks reordering
+ if(s->avctx->xvmc_acceleration == 1){
+ memcpy(&render->data_blocks[(render->next_free_data_block_num)*64],
+ s->pblocks[i],sizeof(short)*8*8);
+ }else{
+/* if(s->pblocks[i] != &render->data_blocks[
+ (render->next_free_data_block_num)*64]){
+ printf("ERROR mb(%d,%d) s->pblocks[i]=%p data_block[]=%p\n",
+ s->mb_x,s->mb_y, s->pblocks[i],
+ &render->data_blocks[(render->next_free_data_block_num)*64]);
+ }*/
+ }
+ render->next_free_data_block_num++;
+ }
+ }
+ render->filled_mv_blocks_num++;
+
+ assert(render->filled_mv_blocks_num <= render->total_number_of_mv_blocks);
+ assert(render->next_free_data_block_num <= render->total_number_of_data_blocks);
+
+
+ if(render->filled_mv_blocks_num >= render->total_number_of_mv_blocks)
+ ff_draw_horiz_band(s,0,0);
+
+// DumpRenderInfo(render);
+// DumpMBlockInfo(mv_block);
+
+}
+
+#endif
diff --git a/contrib/ffmpeg/libavcodec/zmbv.c b/contrib/ffmpeg/libavcodec/zmbv.c
new file mode 100644
index 000000000..89b8418c5
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/zmbv.c
@@ -0,0 +1,691 @@
+/*
+ * Zip Motion Blocks Video (ZMBV) decoder
+ * Copyright (c) 2006 Konstantin Shishkov
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * @file zmbv.c
+ * Zip Motion Blocks Video decoder
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "common.h"
+#include "avcodec.h"
+
+#ifdef CONFIG_ZLIB
+#include <zlib.h>
+#endif
+
+#define ZMBV_KEYFRAME 1
+#define ZMBV_DELTAPAL 2
+
+enum ZmbvFormat {
+ ZMBV_FMT_NONE = 0,
+ ZMBV_FMT_1BPP = 1,
+ ZMBV_FMT_2BPP = 2,
+ ZMBV_FMT_4BPP = 3,
+ ZMBV_FMT_8BPP = 4,
+ ZMBV_FMT_15BPP = 5,
+ ZMBV_FMT_16BPP = 6,
+ ZMBV_FMT_24BPP = 7,
+ ZMBV_FMT_32BPP = 8
+};
+
+/*
+ * Decoder context
+ */
+typedef struct ZmbvContext {
+ AVCodecContext *avctx;
+ AVFrame pic;
+
+ int bpp;
+ unsigned int decomp_size;
+ uint8_t* decomp_buf;
+ uint8_t pal[768];
+ uint8_t *prev, *cur;
+ int width, height;
+ int fmt;
+ int comp;
+ int flags;
+ int bw, bh, bx, by;
+ int decomp_len;
+#ifdef CONFIG_ZLIB
+ z_stream zstream;
+#endif
+ int (*decode_intra)(struct ZmbvContext *c);
+ int (*decode_xor)(struct ZmbvContext *c);
+} ZmbvContext;
+
+/**
+ * Decode XOR'ed frame - 8bpp version
+ */
+
+static int zmbv_decode_xor_8(ZmbvContext *c)
+{
+ uint8_t *src = c->decomp_buf;
+ uint8_t *output, *prev;
+ int8_t *mvec;
+ int x, y;
+ int d, dx, dy, bw2, bh2;
+ int block;
+ int i, j;
+ int mx, my;
+
+ output = c->cur;
+ prev = c->prev;
+
+ if(c->flags & ZMBV_DELTAPAL){
+ for(i = 0; i < 768; i++)
+ c->pal[i] ^= *src++;
+ }
+
+ mvec = (int8_t*)src;
+ src += ((c->bx * c->by * 2 + 3) & ~3);
+
+ block = 0;
+ for(y = 0; y < c->height; y += c->bh) {
+ bh2 = ((c->height - y) > c->bh) ? c->bh : (c->height - y);
+ for(x = 0; x < c->width; x += c->bw) {
+ uint8_t *out, *tprev;
+
+ d = mvec[block] & 1;
+ dx = mvec[block] >> 1;
+ dy = mvec[block + 1] >> 1;
+ block += 2;
+
+ bw2 = ((c->width - x) > c->bw) ? c->bw : (c->width - x);
+
+ /* copy block - motion vectors out of bounds are used to zero blocks */
+ out = output + x;
+ tprev = prev + x + dx + dy * c->width;
+ mx = x + dx;
+ my = y + dy;
+ for(j = 0; j < bh2; j++){
+ if((my + j < 0) || (my + j >= c->height)) {
+ memset(out, 0, bw2);
+ } else {
+ for(i = 0; i < bw2; i++){
+ if((mx + i < 0) || (mx + i >= c->width))
+ out[i] = 0;
+ else
+ out[i] = tprev[i];
+ }
+ }
+ out += c->width;
+ tprev += c->width;
+ }
+
+ if(d) { /* apply XOR'ed difference */
+ out = output + x;
+ for(j = 0; j < bh2; j++){
+ for(i = 0; i < bw2; i++)
+ out[i] ^= *src++;
+ out += c->width;
+ }
+ }
+ }
+ output += c->width * c->bh;
+ prev += c->width * c->bh;
+ }
+ if(src - c->decomp_buf != c->decomp_len)
+ av_log(c->avctx, AV_LOG_ERROR, "Used %i of %i bytes\n", src-c->decomp_buf, c->decomp_len);
+ return 0;
+}
+
+/**
+ * Decode XOR'ed frame - 15bpp and 16bpp version
+ */
+
+static int zmbv_decode_xor_16(ZmbvContext *c)
+{
+ uint8_t *src = c->decomp_buf;
+ uint16_t *output, *prev;
+ int8_t *mvec;
+ int x, y;
+ int d, dx, dy, bw2, bh2;
+ int block;
+ int i, j;
+ int mx, my;
+
+ output = (uint16_t*)c->cur;
+ prev = (uint16_t*)c->prev;
+
+ mvec = (int8_t*)src;
+ src += ((c->bx * c->by * 2 + 3) & ~3);
+
+ block = 0;
+ for(y = 0; y < c->height; y += c->bh) {
+ bh2 = ((c->height - y) > c->bh) ? c->bh : (c->height - y);
+ for(x = 0; x < c->width; x += c->bw) {
+ uint16_t *out, *tprev;
+
+ d = mvec[block] & 1;
+ dx = mvec[block] >> 1;
+ dy = mvec[block + 1] >> 1;
+ block += 2;
+
+ bw2 = ((c->width - x) > c->bw) ? c->bw : (c->width - x);
+
+ /* copy block - motion vectors out of bounds are used to zero blocks */
+ out = output + x;
+ tprev = prev + x + dx + dy * c->width;
+ mx = x + dx;
+ my = y + dy;
+ for(j = 0; j < bh2; j++){
+ if((my + j < 0) || (my + j >= c->height)) {
+ memset(out, 0, bw2 * 2);
+ } else {
+ for(i = 0; i < bw2; i++){
+ if((mx + i < 0) || (mx + i >= c->width))
+ out[i] = 0;
+ else
+ out[i] = tprev[i];
+ }
+ }
+ out += c->width;
+ tprev += c->width;
+ }
+
+ if(d) { /* apply XOR'ed difference */
+ out = output + x;
+ for(j = 0; j < bh2; j++){
+ for(i = 0; i < bw2; i++) {
+ out[i] ^= *((uint16_t*)src);
+ src += 2;
+ }
+ out += c->width;
+ }
+ }
+ }
+ output += c->width * c->bh;
+ prev += c->width * c->bh;
+ }
+ if(src - c->decomp_buf != c->decomp_len)
+ av_log(c->avctx, AV_LOG_ERROR, "Used %i of %i bytes\n", src-c->decomp_buf, c->decomp_len);
+ return 0;
+}
+
+#ifdef ZMBV_ENABLE_24BPP
+/**
+ * Decode XOR'ed frame - 24bpp version
+ */
+
+static int zmbv_decode_xor_24(ZmbvContext *c)
+{
+ uint8_t *src = c->decomp_buf;
+ uint8_t *output, *prev;
+ int8_t *mvec;
+ int x, y;
+ int d, dx, dy, bw2, bh2;
+ int block;
+ int i, j;
+ int mx, my;
+ int stride;
+
+ output = c->cur;
+ prev = c->prev;
+
+ stride = c->width * 3;
+ mvec = (int8_t*)src;
+ src += ((c->bx * c->by * 2 + 3) & ~3);
+
+ block = 0;
+ for(y = 0; y < c->height; y += c->bh) {
+ bh2 = ((c->height - y) > c->bh) ? c->bh : (c->height - y);
+ for(x = 0; x < c->width; x += c->bw) {
+ uint8_t *out, *tprev;
+
+ d = mvec[block] & 1;
+ dx = mvec[block] >> 1;
+ dy = mvec[block + 1] >> 1;
+ block += 2;
+
+ bw2 = ((c->width - x) > c->bw) ? c->bw : (c->width - x);
+
+ /* copy block - motion vectors out of bounds are used to zero blocks */
+ out = output + x * 3;
+ tprev = prev + (x + dx) * 3 + dy * stride;
+ mx = x + dx;
+ my = y + dy;
+ for(j = 0; j < bh2; j++){
+ if((my + j < 0) || (my + j >= c->height)) {
+ memset(out, 0, bw2 * 3);
+ } else {
+ for(i = 0; i < bw2; i++){
+ if((mx + i < 0) || (mx + i >= c->width)) {
+ out[i * 3 + 0] = 0;
+ out[i * 3 + 1] = 0;
+ out[i * 3 + 2] = 0;
+ } else {
+ out[i * 3 + 0] = tprev[i * 3 + 0];
+ out[i * 3 + 1] = tprev[i * 3 + 1];
+ out[i * 3 + 2] = tprev[i * 3 + 2];
+ }
+ }
+ }
+ out += stride;
+ tprev += stride;
+ }
+
+ if(d) { /* apply XOR'ed difference */
+ out = output + x * 3;
+ for(j = 0; j < bh2; j++){
+ for(i = 0; i < bw2; i++) {
+ out[i * 3 + 0] ^= *src++;
+ out[i * 3 + 1] ^= *src++;
+ out[i * 3 + 2] ^= *src++;
+ }
+ out += stride;
+ }
+ }
+ }
+ output += stride * c->bh;
+ prev += stride * c->bh;
+ }
+ if(src - c->decomp_buf != c->decomp_len)
+ av_log(c->avctx, AV_LOG_ERROR, "Used %i of %i bytes\n", src-c->decomp_buf, c->decomp_len);
+ return 0;
+}
+#endif //ZMBV_ENABLE_24BPP
+
+/**
+ * Decode XOR'ed frame - 32bpp version
+ */
+
+static int zmbv_decode_xor_32(ZmbvContext *c)
+{
+ uint8_t *src = c->decomp_buf;
+ uint32_t *output, *prev;
+ int8_t *mvec;
+ int x, y;
+ int d, dx, dy, bw2, bh2;
+ int block;
+ int i, j;
+ int mx, my;
+
+ output = (uint32_t*)c->cur;
+ prev = (uint32_t*)c->prev;
+
+ mvec = (int8_t*)src;
+ src += ((c->bx * c->by * 2 + 3) & ~3);
+
+ block = 0;
+ for(y = 0; y < c->height; y += c->bh) {
+ bh2 = ((c->height - y) > c->bh) ? c->bh : (c->height - y);
+ for(x = 0; x < c->width; x += c->bw) {
+ uint32_t *out, *tprev;
+
+ d = mvec[block] & 1;
+ dx = mvec[block] >> 1;
+ dy = mvec[block + 1] >> 1;
+ block += 2;
+
+ bw2 = ((c->width - x) > c->bw) ? c->bw : (c->width - x);
+
+ /* copy block - motion vectors out of bounds are used to zero blocks */
+ out = output + x;
+ tprev = prev + x + dx + dy * c->width;
+ mx = x + dx;
+ my = y + dy;
+ for(j = 0; j < bh2; j++){
+ if((my + j < 0) || (my + j >= c->height)) {
+ memset(out, 0, bw2 * 4);
+ } else {
+ for(i = 0; i < bw2; i++){
+ if((mx + i < 0) || (mx + i >= c->width))
+ out[i] = 0;
+ else
+ out[i] = tprev[i];
+ }
+ }
+ out += c->width;
+ tprev += c->width;
+ }
+
+ if(d) { /* apply XOR'ed difference */
+ out = output + x;
+ for(j = 0; j < bh2; j++){
+ for(i = 0; i < bw2; i++) {
+ out[i] ^= *((uint32_t*)src);
+ src += 4;
+ }
+ out += c->width;
+ }
+ }
+ }
+ output += c->width * c->bh;
+ prev += c->width * c->bh;
+ }
+ if(src - c->decomp_buf != c->decomp_len)
+ av_log(c->avctx, AV_LOG_ERROR, "Used %i of %i bytes\n", src-c->decomp_buf, c->decomp_len);
+ return 0;
+}
+
+/**
+ * Decode intraframe
+ */
+static int zmbv_decode_intra(ZmbvContext *c)
+{
+ uint8_t *src = c->decomp_buf;
+
+ /* make the palette available on the way out */
+ if (c->fmt == ZMBV_FMT_8BPP) {
+ memcpy(c->pal, src, 768);
+ src += 768;
+ }
+
+ memcpy(c->cur, src, c->width * c->height * (c->bpp / 8));
+ return 0;
+}
+
+static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size)
+{
+ ZmbvContext * const c = (ZmbvContext *)avctx->priv_data;
+ uint8_t *outptr;
+#ifdef CONFIG_ZLIB
+ int zret = Z_OK; // Zlib return code
+#endif
+ int len = buf_size;
+ int hi_ver, lo_ver;
+
+ if(c->pic.data[0])
+ avctx->release_buffer(avctx, &c->pic);
+
+ c->pic.reference = 1;
+ c->pic.buffer_hints = FF_BUFFER_HINTS_VALID;
+ if(avctx->get_buffer(avctx, &c->pic) < 0){
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ return -1;
+ }
+
+ outptr = c->pic.data[0]; // Output image pointer
+
+ /* parse header */
+ c->flags = buf[0];
+ buf++; len--;
+ if(c->flags & ZMBV_KEYFRAME) {
+ hi_ver = buf[0];
+ lo_ver = buf[1];
+ c->comp = buf[2];
+ c->fmt = buf[3];
+ c->bw = buf[4];
+ c->bh = buf[5];
+
+ buf += 6;
+ len -= 6;
+ av_log(avctx, AV_LOG_DEBUG, "Flags=%X ver=%i.%i comp=%i fmt=%i blk=%ix%i\n",c->flags,hi_ver,lo_ver,c->comp,c->fmt,c->bw,c->bh);
+ if(hi_ver != 0 || lo_ver != 1) {
+ av_log(avctx, AV_LOG_ERROR, "Unsupported version %i.%i\n", hi_ver, lo_ver);
+ return -1;
+ }
+ if(c->bw == 0 || c->bh == 0) {
+ av_log(avctx, AV_LOG_ERROR, "Unsupported block size %ix%i\n", c->bw, c->bh);
+ }
+ if(c->comp != 0 && c->comp != 1) {
+ av_log(avctx, AV_LOG_ERROR, "Unsupported compression type %i\n", c->comp);
+ return -1;
+ }
+
+ switch(c->fmt) {
+ case ZMBV_FMT_8BPP:
+ c->bpp = 8;
+ c->decode_intra = zmbv_decode_intra;
+ c->decode_xor = zmbv_decode_xor_8;
+ break;
+ case ZMBV_FMT_15BPP:
+ case ZMBV_FMT_16BPP:
+ c->bpp = 16;
+ c->decode_intra = zmbv_decode_intra;
+ c->decode_xor = zmbv_decode_xor_16;
+ break;
+#ifdef ZMBV_ENABLE_24BPP
+ case ZMBV_FMT_24BPP:
+ c->bpp = 24;
+ c->decode_intra = zmbv_decode_intra;
+ c->decode_xor = zmbv_decode_xor_24;
+ break;
+#endif //ZMBV_ENABLE_24BPP
+ case ZMBV_FMT_32BPP:
+ c->bpp = 32;
+ c->decode_intra = zmbv_decode_intra;
+ c->decode_xor = zmbv_decode_xor_32;
+ break;
+ default:
+ c->decode_intra = NULL;
+ c->decode_xor = NULL;
+ av_log(avctx, AV_LOG_ERROR, "Unsupported (for now) format %i\n", c->fmt);
+ return -1;
+ }
+#ifdef CONFIG_ZLIB
+ zret = inflateReset(&c->zstream);
+ if (zret != Z_OK) {
+ av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret);
+ return -1;
+ }
+#else
+ av_log(avctx, AV_LOG_ERROR, "BUG! Zlib support not compiled in frame decoder.\n");
+ return -1;
+#endif /* CONFIG_ZLIB */
+ c->cur = av_realloc(c->cur, avctx->width * avctx->height * (c->bpp / 8));
+ c->prev = av_realloc(c->prev, avctx->width * avctx->height * (c->bpp / 8));
+ c->bx = (c->width + c->bw - 1) / c->bw;
+ c->by = (c->height+ c->bh - 1) / c->bh;
+ }
+
+ if(c->decode_intra == NULL) {
+ av_log(avctx, AV_LOG_ERROR, "Error! Got no format or no keyframe!\n");
+ return -1;
+ }
+
+ if(c->comp == 0) { //Uncompressed data
+ memcpy(c->decomp_buf, buf, len);
+ c->decomp_size = 1;
+ } else { // ZLIB-compressed data
+#ifdef CONFIG_ZLIB
+ c->zstream.total_in = c->zstream.total_out = 0;
+ c->zstream.next_in = buf;
+ c->zstream.avail_in = len;
+ c->zstream.next_out = c->decomp_buf;
+ c->zstream.avail_out = c->decomp_size;
+ inflate(&c->zstream, Z_FINISH);
+ c->decomp_len = c->zstream.total_out;
+#else
+ av_log(avctx, AV_LOG_ERROR, "BUG! Zlib support not compiled in frame decoder.\n");
+ return -1;
+#endif
+ }
+ if(c->flags & ZMBV_KEYFRAME) {
+ c->pic.key_frame = 1;
+ c->pic.pict_type = FF_I_TYPE;
+ c->decode_intra(c);
+ } else {
+ c->pic.key_frame = 0;
+ c->pic.pict_type = FF_P_TYPE;
+ c->decode_xor(c);
+ }
+
+ /* update frames */
+ {
+ uint8_t *out, *src;
+ int i, j;
+
+ out = c->pic.data[0];
+ src = c->cur;
+ switch(c->fmt) {
+ case ZMBV_FMT_8BPP:
+ for(j = 0; j < c->height; j++) {
+ for(i = 0; i < c->width; i++) {
+ out[i * 3 + 0] = c->pal[(*src) * 3 + 0];
+ out[i * 3 + 1] = c->pal[(*src) * 3 + 1];
+ out[i * 3 + 2] = c->pal[(*src) * 3 + 2];
+ *src++;
+ }
+ out += c->pic.linesize[0];
+ }
+ break;
+ case ZMBV_FMT_15BPP:
+ for(j = 0; j < c->height; j++) {
+ for(i = 0; i < c->width; i++) {
+ uint16_t tmp = AV_RL16(src);
+ src += 2;
+ out[i * 3 + 0] = (tmp & 0x7C00) >> 7;
+ out[i * 3 + 1] = (tmp & 0x03E0) >> 2;
+ out[i * 3 + 2] = (tmp & 0x001F) << 3;
+ }
+ out += c->pic.linesize[0];
+ }
+ break;
+ case ZMBV_FMT_16BPP:
+ for(j = 0; j < c->height; j++) {
+ for(i = 0; i < c->width; i++) {
+ uint16_t tmp = AV_RL16(src);
+ src += 2;
+ out[i * 3 + 0] = (tmp & 0xF800) >> 8;
+ out[i * 3 + 1] = (tmp & 0x07E0) >> 3;
+ out[i * 3 + 2] = (tmp & 0x001F) << 3;
+ }
+ out += c->pic.linesize[0];
+ }
+ break;
+#ifdef ZMBV_ENABLE_24BPP
+ case ZMBV_FMT_24BPP:
+ for(j = 0; j < c->height; j++) {
+ memcpy(out, src, c->width * 3);
+ src += c->width * 3;
+ out += c->pic.linesize[0];
+ }
+ break;
+#endif //ZMBV_ENABLE_24BPP
+ case ZMBV_FMT_32BPP:
+ for(j = 0; j < c->height; j++) {
+ for(i = 0; i < c->width; i++) {
+ uint32_t tmp = AV_RL32(src);
+ src += 4;
+ out[i * 3 + 0] = tmp >> 16;
+ out[i * 3 + 1] = tmp >> 8;
+ out[i * 3 + 2] = tmp >> 0;
+ }
+ out += c->pic.linesize[0];
+ }
+ break;
+ default:
+ av_log(avctx, AV_LOG_ERROR, "Cannot handle format %i\n", c->fmt);
+ }
+ memcpy(c->prev, c->cur, c->width * c->height * (c->bpp / 8));
+ }
+ *data_size = sizeof(AVFrame);
+ *(AVFrame*)data = c->pic;
+
+ /* always report that the buffer was completely consumed */
+ return buf_size;
+}
+
+
+
+/*
+ *
+ * Init zmbv decoder
+ *
+ */
+static int decode_init(AVCodecContext *avctx)
+{
+ ZmbvContext * const c = (ZmbvContext *)avctx->priv_data;
+ int zret; // Zlib return code
+
+ c->avctx = avctx;
+
+ c->pic.data[0] = NULL;
+ 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_sample;
+
+#ifdef CONFIG_ZLIB
+ // Needed if zlib unused or init aborted before inflateInit
+ memset(&(c->zstream), 0, sizeof(z_stream));
+#else
+ av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled.\n");
+ return 1;
+#endif
+ avctx->pix_fmt = PIX_FMT_RGB24;
+ c->decomp_size = (avctx->width + 255) * 4 * (avctx->height + 64);
+
+ /* Allocate decompression buffer */
+ if (c->decomp_size) {
+ if ((c->decomp_buf = av_malloc(c->decomp_size)) == NULL) {
+ av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
+ return 1;
+ }
+ }
+
+#ifdef CONFIG_ZLIB
+ c->zstream.zalloc = Z_NULL;
+ c->zstream.zfree = Z_NULL;
+ c->zstream.opaque = Z_NULL;
+ zret = inflateInit(&(c->zstream));
+ if (zret != Z_OK) {
+ av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
+ return 1;
+ }
+#endif
+
+ return 0;
+}
+
+
+
+/*
+ *
+ * Uninit zmbv decoder
+ *
+ */
+static int decode_end(AVCodecContext *avctx)
+{
+ ZmbvContext * const c = (ZmbvContext *)avctx->priv_data;
+
+ av_freep(&c->decomp_buf);
+
+ if (c->pic.data[0])
+ avctx->release_buffer(avctx, &c->pic);
+#ifdef CONFIG_ZLIB
+ inflateEnd(&(c->zstream));
+#endif
+ av_freep(&c->cur);
+ av_freep(&c->prev);
+
+ return 0;
+}
+
+AVCodec zmbv_decoder = {
+ "zmbv",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_ZMBV,
+ sizeof(ZmbvContext),
+ decode_init,
+ NULL,
+ decode_end,
+ decode_frame
+};
+
diff --git a/contrib/ffmpeg/libavcodec/zmbvenc.c b/contrib/ffmpeg/libavcodec/zmbvenc.c
new file mode 100644
index 000000000..a79964449
--- /dev/null
+++ b/contrib/ffmpeg/libavcodec/zmbvenc.c
@@ -0,0 +1,328 @@
+/*
+ * Zip Motion Blocks Video (ZMBV) encoder
+ * Copyright (c) 2006 Konstantin Shishkov
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * @file zmbvenc.c
+ * Zip Motion Blocks Video encoder
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "common.h"
+#include "avcodec.h"
+
+#include <zlib.h>
+
+#define ZMBV_KEYFRAME 1
+#define ZMBV_DELTAPAL 2
+
+#define ZMBV_BLOCK 16
+
+/**
+ * Encoder context
+ */
+typedef struct ZmbvEncContext {
+ AVCodecContext *avctx;
+ AVFrame pic;
+
+ int range;
+ uint8_t *comp_buf, *work_buf;
+ uint8_t pal[768];
+ uint32_t pal2[256]; //for quick comparisons
+ uint8_t *prev;
+ int pstride;
+ int comp_size;
+ int keyint, curfrm;
+ z_stream zstream;
+} ZmbvEncContext;
+
+/** Block comparing function
+ * 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)
+{
+ int sum = 0;
+ int i, j;
+
+ for(j = 0; j < bh; j++){
+ for(i = 0; i < bw; i++)
+ sum += src[i] ^ src2[i];
+ src += stride;
+ src2 += stride2;
+ }
+ return sum;
+}
+
+/** 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)
+{
+ 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);
+ 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);
+ if(tv < bv){
+ bv = tv;
+ *mx = dx;
+ *my = dy;
+ if(!bv) return 0;
+ }
+ }
+ }
+ return bv;
+}
+
+static int encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_size, void *data)
+{
+ ZmbvEncContext * const c = (ZmbvEncContext *)avctx->priv_data;
+ AVFrame *pict = data;
+ AVFrame * const p = &c->pic;
+ uint8_t *src, *prev;
+ uint32_t *palptr;
+ int zret = Z_OK;
+ int len = 0;
+ int keyframe, chpal;
+ int fl;
+ int work_size = 0;
+ int bw, bh;
+ int i, j;
+
+ keyframe = !c->curfrm;
+ c->curfrm++;
+ if(c->curfrm == c->keyint)
+ c->curfrm = 0;
+ *p = *pict;
+ p->pict_type= keyframe ? FF_I_TYPE : FF_P_TYPE;
+ p->key_frame= keyframe;
+ chpal = !keyframe && memcmp(p->data[1], c->pal2, 1024);
+
+ fl = (keyframe ? ZMBV_KEYFRAME : 0) | (chpal ? ZMBV_DELTAPAL : 0);
+ *buf++ = fl; len++;
+ if(keyframe){
+ deflateReset(&c->zstream);
+ *buf++ = 0; len++; // hi ver
+ *buf++ = 1; len++; // lo ver
+ *buf++ = 1; len++; // comp
+ *buf++ = 4; len++; // format - 8bpp
+ *buf++ = ZMBV_BLOCK; len++; // block width
+ *buf++ = ZMBV_BLOCK; len++; // block height
+ }
+ palptr = (uint32_t*)p->data[1];
+ src = p->data[0];
+ prev = c->prev;
+ if(chpal){
+ uint8_t tpal[3];
+ for(i = 0; i < 256; i++){
+ tpal[0] = palptr[i] >> 16;
+ tpal[1] = palptr[i] >> 8;
+ tpal[2] = palptr[i];
+ c->work_buf[work_size++] = tpal[0] ^ c->pal[i * 3 + 0];
+ c->work_buf[work_size++] = tpal[1] ^ c->pal[i * 3 + 1];
+ c->work_buf[work_size++] = tpal[2] ^ c->pal[i * 3 + 2];
+ c->pal[i * 3 + 0] = tpal[0];
+ c->pal[i * 3 + 1] = tpal[1];
+ c->pal[i * 3 + 2] = tpal[2];
+ }
+ memcpy(c->pal2, p->data[1], 1024);
+ }
+ if(keyframe){
+ for(i = 0; i < 256; i++){
+ c->pal[i*3 + 0] = palptr[i] >> 16;
+ c->pal[i*3 + 1] = palptr[i] >> 8;
+ c->pal[i*3 + 2] = palptr[i];
+ }
+ memcpy(c->work_buf, c->pal, 768);
+ memcpy(c->pal2, p->data[1], 1024);
+ work_size = 768;
+ for(i = 0; i < avctx->height; i++){
+ memcpy(c->work_buf + work_size, src, avctx->width);
+ src += p->linesize[0];
+ work_size += avctx->width;
+ }
+ }else{
+ int x, y, bh2, bw2;
+ uint8_t *tsrc, *tprev;
+ uint8_t *mv;
+ int mx, my, bv;
+
+ bw = (avctx->width + ZMBV_BLOCK - 1) / ZMBV_BLOCK;
+ bh = (avctx->height + ZMBV_BLOCK - 1) / ZMBV_BLOCK;
+ mv = c->work_buf + work_size;
+ memset(c->work_buf + work_size, 0, (bw * bh * 2 + 3) & ~3);
+ work_size += (bw * bh * 2 + 3) & ~3;
+ /* for now just XOR'ing */
+ for(y = 0; y < avctx->height; y += ZMBV_BLOCK) {
+ bh2 = FFMIN(avctx->height - y, ZMBV_BLOCK);
+ for(x = 0; x < avctx->width; x += ZMBV_BLOCK, mv += 2) {
+ bw2 = FFMIN(avctx->width - x, ZMBV_BLOCK);
+
+ 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;
+ mv[1] = my << 1;
+ tprev += mx + my * c->pstride;
+ if(bv){
+ for(j = 0; j < bh2; j++){
+ for(i = 0; i < bw2; i++)
+ c->work_buf[work_size++] = tsrc[i] ^ tprev[i];
+ tsrc += p->linesize[0];
+ tprev += c->pstride;
+ }
+ }
+ }
+ src += p->linesize[0] * ZMBV_BLOCK;
+ prev += c->pstride * ZMBV_BLOCK;
+ }
+ }
+ /* save the previous frame */
+ src = p->data[0];
+ prev = c->prev;
+ for(i = 0; i < avctx->height; i++){
+ memcpy(prev, src, avctx->width);
+ prev += c->pstride;
+ src += p->linesize[0];
+ }
+
+ c->zstream.next_in = c->work_buf;
+ c->zstream.avail_in = work_size;
+ c->zstream.total_in = 0;
+
+ c->zstream.next_out = c->comp_buf;
+ c->zstream.avail_out = c->comp_size;
+ c->zstream.total_out = 0;
+ if((zret = deflate(&c->zstream, Z_SYNC_FLUSH)) != Z_OK){
+ av_log(avctx, AV_LOG_ERROR, "Error compressing data\n");
+ return -1;
+ }
+
+ memcpy(buf, c->comp_buf, c->zstream.total_out);
+ return len + c->zstream.total_out;
+}
+
+
+/**
+ * Init zmbv encoder
+ */
+static int encode_init(AVCodecContext *avctx)
+{
+ ZmbvEncContext * const c = (ZmbvEncContext *)avctx->priv_data;
+ int zret; // Zlib return code
+ int lvl = 9;
+
+ c->avctx = avctx;
+
+ c->pic.data[0] = NULL;
+ c->curfrm = 0;
+ c->keyint = avctx->keyint_min;
+ c->range = 8;
+ if(avctx->me_range > 0)
+ c->range = FFMIN(avctx->me_range, 127);
+
+ if(avctx->compression_level >= 0)
+ lvl = avctx->compression_level;
+ if(lvl < 0 || lvl > 9){
+ av_log(avctx, AV_LOG_ERROR, "Compression level should be 0-9, not %i\n", lvl);
+ 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 +
+ ((avctx->width + ZMBV_BLOCK - 1) / ZMBV_BLOCK) * ((avctx->height + ZMBV_BLOCK - 1) / ZMBV_BLOCK) * 2 + 4;
+ if ((c->work_buf = av_malloc(c->comp_size)) == NULL) {
+ av_log(avctx, AV_LOG_ERROR, "Can't allocate work buffer.\n");
+ return -1;
+ }
+ /* Conservative upper bound taken from zlib v1.2.1 source via lcl.c */
+ c->comp_size = c->comp_size + ((c->comp_size + 7) >> 3) +
+ ((c->comp_size + 63) >> 6) + 11;
+
+ /* Allocate compression buffer */
+ if ((c->comp_buf = av_malloc(c->comp_size)) == NULL) {
+ av_log(avctx, AV_LOG_ERROR, "Can't allocate compression buffer.\n");
+ return -1;
+ }
+ c->pstride = (avctx->width + 15) & ~15;
+ if ((c->prev = av_malloc(c->pstride * avctx->height)) == NULL) {
+ av_log(avctx, AV_LOG_ERROR, "Can't allocate picture.\n");
+ return -1;
+ }
+
+ c->zstream.zalloc = Z_NULL;
+ c->zstream.zfree = Z_NULL;
+ c->zstream.opaque = Z_NULL;
+ zret = deflateInit(&(c->zstream), lvl);
+ if (zret != Z_OK) {
+ av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
+ return -1;
+ }
+
+ return 0;
+}
+
+
+
+/**
+ * Uninit zmbv encoder
+ */
+static int encode_end(AVCodecContext *avctx)
+{
+ ZmbvEncContext * const c = (ZmbvEncContext *)avctx->priv_data;
+
+ av_freep(&c->comp_buf);
+ av_freep(&c->work_buf);
+
+ deflateEnd(&(c->zstream));
+ av_freep(&c->prev);
+
+ return 0;
+}
+
+AVCodec zmbv_encoder = {
+ "zmbv",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_ZMBV,
+ sizeof(ZmbvEncContext),
+ encode_init,
+ encode_frame,
+ encode_end,
+ .pix_fmts = (enum PixelFormat[]){PIX_FMT_PAL8, -1},
+};
diff --git a/contrib/ffmpeg/libavformat/4xm.c b/contrib/ffmpeg/libavformat/4xm.c
new file mode 100644
index 000000000..bf10b9e82
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/4xm.c
@@ -0,0 +1,331 @@
+/*
+ * 4X Technologies .4xm File Demuxer (no muxer)
+ * Copyright (c) 2003 The ffmpeg Project
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file 4xm.c
+ * 4X Technologies file demuxer
+ * by Mike Melanson (melanson@pcisys.net)
+ * for more information on the .4xm file format, visit:
+ * http://www.pcisys.net/~melanson/codecs/
+ */
+
+#include "avformat.h"
+
+#define RIFF_TAG MKTAG('R', 'I', 'F', 'F')
+#define _4XMV_TAG MKTAG('4', 'X', 'M', 'V')
+#define LIST_TAG MKTAG('L', 'I', 'S', 'T')
+#define HEAD_TAG MKTAG('H', 'E', 'A', 'D')
+#define TRK__TAG MKTAG('T', 'R', 'K', '_')
+#define MOVI_TAG MKTAG('M', 'O', 'V', 'I')
+#define VTRK_TAG MKTAG('V', 'T', 'R', 'K')
+#define STRK_TAG MKTAG('S', 'T', 'R', 'K')
+#define std__TAG MKTAG('s', 't', 'd', '_')
+#define name_TAG MKTAG('n', 'a', 'm', 'e')
+#define vtrk_TAG MKTAG('v', 't', 'r', 'k')
+#define strk_TAG MKTAG('s', 't', 'r', 'k')
+#define ifrm_TAG MKTAG('i', 'f', 'r', 'm')
+#define pfrm_TAG MKTAG('p', 'f', 'r', 'm')
+#define cfrm_TAG MKTAG('c', 'f', 'r', 'm')
+#define snd__TAG MKTAG('s', 'n', 'd', '_')
+
+#define vtrk_SIZE 0x44
+#define strk_SIZE 0x28
+
+#define GET_LIST_HEADER() \
+ fourcc_tag = get_le32(pb); \
+ size = get_le32(pb); \
+ if (fourcc_tag != LIST_TAG) \
+ return AVERROR_INVALIDDATA; \
+ fourcc_tag = get_le32(pb);
+
+typedef struct AudioTrack {
+ int sample_rate;
+ int bits;
+ int channels;
+ int stream_index;
+ int adpcm;
+} AudioTrack;
+
+typedef struct FourxmDemuxContext {
+ int width;
+ int height;
+ int video_stream_index;
+ int track_count;
+ AudioTrack *tracks;
+ int selected_track;
+
+ int64_t audio_pts;
+ int64_t video_pts;
+ float fps;
+} FourxmDemuxContext;
+
+static int fourxm_probe(AVProbeData *p)
+{
+ if (p->buf_size < 12)
+ return 0;
+
+ if ((AV_RL32(&p->buf[0]) != RIFF_TAG) ||
+ (AV_RL32(&p->buf[8]) != _4XMV_TAG))
+ return 0;
+
+ return AVPROBE_SCORE_MAX;
+}
+
+static int fourxm_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ ByteIOContext *pb = &s->pb;
+ unsigned int fourcc_tag;
+ unsigned int size;
+ int header_size;
+ FourxmDemuxContext *fourxm = (FourxmDemuxContext *)s->priv_data;
+ unsigned char *header;
+ int i;
+ int current_track = -1;
+ AVStream *st;
+
+ fourxm->track_count = 0;
+ fourxm->tracks = NULL;
+ fourxm->selected_track = 0;
+ fourxm->fps = 1.0;
+
+ /* skip the first 3 32-bit numbers */
+ url_fseek(pb, 12, SEEK_CUR);
+
+ /* check for LIST-HEAD */
+ GET_LIST_HEADER();
+ header_size = size - 4;
+ if (fourcc_tag != HEAD_TAG)
+ return AVERROR_INVALIDDATA;
+
+ /* allocate space for the header and load the whole thing */
+ header = av_malloc(header_size);
+ if (!header)
+ return AVERROR_NOMEM;
+ if (get_buffer(pb, header, header_size) != header_size)
+ return AVERROR_IO;
+
+ /* take the lazy approach and search for any and all vtrk and strk chunks */
+ for (i = 0; i < header_size - 8; i++) {
+ fourcc_tag = AV_RL32(&header[i]);
+ size = AV_RL32(&header[i + 4]);
+
+ if (fourcc_tag == std__TAG) {
+ fourxm->fps = av_int2flt(AV_RL32(&header[i + 12]));
+ } else if (fourcc_tag == vtrk_TAG) {
+ /* check that there is enough data */
+ if (size != vtrk_SIZE) {
+ av_free(header);
+ return AVERROR_INVALIDDATA;
+ }
+ fourxm->width = AV_RL32(&header[i + 36]);
+ fourxm->height = AV_RL32(&header[i + 40]);
+ i += 8 + size;
+
+ /* allocate a new AVStream */
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+ av_set_pts_info(st, 60, 1, fourxm->fps);
+
+ fourxm->video_stream_index = st->index;
+
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ st->codec->codec_id = CODEC_ID_4XM;
+ st->codec->codec_tag = 0; /* no fourcc */
+ st->codec->width = fourxm->width;
+ st->codec->height = fourxm->height;
+
+ } else if (fourcc_tag == strk_TAG) {
+ /* check that there is enough data */
+ if (size != strk_SIZE) {
+ av_free(header);
+ return AVERROR_INVALIDDATA;
+ }
+ current_track = AV_RL32(&header[i + 8]);
+ if (current_track + 1 > fourxm->track_count) {
+ fourxm->track_count = current_track + 1;
+ if((unsigned)fourxm->track_count >= UINT_MAX / sizeof(AudioTrack))
+ return -1;
+ fourxm->tracks = av_realloc(fourxm->tracks,
+ fourxm->track_count * sizeof(AudioTrack));
+ if (!fourxm->tracks) {
+ av_free(header);
+ return AVERROR_NOMEM;
+ }
+ }
+ fourxm->tracks[current_track].adpcm = AV_RL32(&header[i + 12]);
+ fourxm->tracks[current_track].channels = AV_RL32(&header[i + 36]);
+ fourxm->tracks[current_track].sample_rate = AV_RL32(&header[i + 40]);
+ fourxm->tracks[current_track].bits = AV_RL32(&header[i + 44]);
+ i += 8 + size;
+
+ /* allocate a new AVStream */
+ st = av_new_stream(s, current_track);
+ if (!st)
+ return AVERROR_NOMEM;
+
+ av_set_pts_info(st, 60, 1, fourxm->tracks[current_track].sample_rate);
+
+ fourxm->tracks[current_track].stream_index = st->index;
+
+ st->codec->codec_type = CODEC_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;
+ st->codec->bits_per_sample = fourxm->tracks[current_track].bits;
+ st->codec->bit_rate = st->codec->channels * st->codec->sample_rate *
+ st->codec->bits_per_sample;
+ st->codec->block_align = st->codec->channels * st->codec->bits_per_sample;
+ if (fourxm->tracks[current_track].adpcm)
+ st->codec->codec_id = CODEC_ID_ADPCM_4XM;
+ else if (st->codec->bits_per_sample == 8)
+ st->codec->codec_id = CODEC_ID_PCM_U8;
+ else
+ st->codec->codec_id = CODEC_ID_PCM_S16LE;
+ }
+ }
+
+ av_free(header);
+
+ /* skip over the LIST-MOVI chunk (which is where the stream should be */
+ GET_LIST_HEADER();
+ if (fourcc_tag != MOVI_TAG)
+ return AVERROR_INVALIDDATA;
+
+ /* initialize context members */
+ fourxm->video_pts = -1; /* first frame will push to 0 */
+ fourxm->audio_pts = 0;
+
+ return 0;
+}
+
+static int fourxm_read_packet(AVFormatContext *s,
+ AVPacket *pkt)
+{
+ FourxmDemuxContext *fourxm = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ unsigned int fourcc_tag;
+ unsigned int size, out_size;
+ int ret = 0;
+ int track_number;
+ int packet_read = 0;
+ unsigned char header[8];
+ int audio_frame_count;
+
+ while (!packet_read) {
+
+ if ((ret = get_buffer(&s->pb, header, 8)) < 0)
+ return ret;
+ fourcc_tag = AV_RL32(&header[0]);
+ size = AV_RL32(&header[4]);
+ if (url_feof(pb))
+ return AVERROR_IO;
+ switch (fourcc_tag) {
+
+ case LIST_TAG:
+ /* this is a good time to bump the video pts */
+ fourxm->video_pts ++;
+
+ /* skip the LIST-* tag and move on to the next fourcc */
+ get_le32(pb);
+ break;
+
+ case ifrm_TAG:
+ case pfrm_TAG:
+ case cfrm_TAG:{
+
+ /* allocate 8 more bytes than 'size' to account for fourcc
+ * and size */
+ if (size + 8 < size || av_new_packet(pkt, size + 8))
+ return AVERROR_IO;
+ pkt->stream_index = fourxm->video_stream_index;
+ pkt->pts = fourxm->video_pts;
+ pkt->pos = url_ftell(&s->pb);
+ memcpy(pkt->data, header, 8);
+ ret = get_buffer(&s->pb, &pkt->data[8], size);
+
+ if (ret < 0)
+ av_free_packet(pkt);
+ else
+ packet_read = 1;
+ break;
+ }
+
+ case snd__TAG:
+ track_number = get_le32(pb);
+ out_size= get_le32(pb);
+ size-=8;
+
+ if (track_number == fourxm->selected_track) {
+ ret= av_get_packet(&s->pb, pkt, size);
+ if(ret<0)
+ return AVERROR_IO;
+ pkt->stream_index =
+ fourxm->tracks[fourxm->selected_track].stream_index;
+ pkt->pts = fourxm->audio_pts;
+ packet_read = 1;
+
+ /* pts accounting */
+ audio_frame_count = size;
+ if (fourxm->tracks[fourxm->selected_track].adpcm)
+ audio_frame_count -=
+ 2 * (fourxm->tracks[fourxm->selected_track].channels);
+ audio_frame_count /=
+ fourxm->tracks[fourxm->selected_track].channels;
+ if (fourxm->tracks[fourxm->selected_track].adpcm)
+ audio_frame_count *= 2;
+ else
+ audio_frame_count /=
+ (fourxm->tracks[fourxm->selected_track].bits / 8);
+ fourxm->audio_pts += audio_frame_count;
+
+ } else {
+ url_fseek(pb, size, SEEK_CUR);
+ }
+ break;
+
+ default:
+ url_fseek(pb, size, SEEK_CUR);
+ break;
+ }
+ }
+ return ret;
+}
+
+static int fourxm_read_close(AVFormatContext *s)
+{
+ FourxmDemuxContext *fourxm = (FourxmDemuxContext *)s->priv_data;
+
+ av_free(fourxm->tracks);
+
+ return 0;
+}
+
+AVInputFormat fourxm_demuxer = {
+ "4xm",
+ "4X Technologies format",
+ sizeof(FourxmDemuxContext),
+ fourxm_probe,
+ fourxm_read_header,
+ fourxm_read_packet,
+ fourxm_read_close,
+};
diff --git a/contrib/ffmpeg/libavformat/Makefile b/contrib/ffmpeg/libavformat/Makefile
new file mode 100644
index 000000000..f1339bd9d
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/Makefile
@@ -0,0 +1,179 @@
+#
+# libavformat Makefile
+# (c) 2000-2003 Fabrice Bellard
+#
+include ../config.mak
+
+CFLAGS+=-I$(SRC_PATH)/libavcodec
+
+OBJS= utils.o cutils.o os_support.o allformats.o
+
+HEADERS = avformat.h avio.h rtp.h rtsp.h rtspcodes.h
+
+# muxers/demuxers
+OBJS-$(CONFIG_FOURXM_DEMUXER) += 4xm.o
+OBJS-$(CONFIG_ADTS_MUXER) += adtsenc.o
+OBJS-$(CONFIG_AIFF_DEMUXER) += aiff.o riff.o
+OBJS-$(CONFIG_AIFF_MUXER) += aiff.o riff.o
+OBJS-$(CONFIG_AMR_DEMUXER) += amr.o
+OBJS-$(CONFIG_AMR_MUXER) += amr.o
+OBJS-$(CONFIG_ASF_DEMUXER) += asf.o riff.o
+OBJS-$(CONFIG_ASF_MUXER) += asf-enc.o riff.o
+OBJS-$(CONFIG_ASF_STREAM_MUXER) += asf-enc.o riff.o
+OBJS-$(CONFIG_AU_DEMUXER) += au.o riff.o
+OBJS-$(CONFIG_AU_MUXER) += au.o riff.o
+OBJS-$(CONFIG_AVI_DEMUXER) += avidec.o riff.o
+OBJS-$(CONFIG_AVI_MUXER) += avienc.o riff.o
+OBJS-$(CONFIG_AVISYNTH) += avisynth.o
+OBJS-$(CONFIG_AVS_DEMUXER) += avs.o vocdec.o voc.o riff.o
+OBJS-$(CONFIG_CRC_MUXER) += crc.o
+OBJS-$(CONFIG_FRAMECRC_MUXER) += crc.o
+OBJS-$(CONFIG_DAUD_DEMUXER) += daud.o
+OBJS-$(CONFIG_DC1394_DEMUXER) += dc1394.o
+OBJS-$(CONFIG_DSICIN_DEMUXER) += dsicin.o
+OBJS-$(CONFIG_DV_DEMUXER) += dv.o
+OBJS-$(CONFIG_DV_MUXER) += dvenc.o
+OBJS-$(CONFIG_DV1394_DEMUXER) += dv1394.o
+OBJS-$(CONFIG_DXA_DEMUXER) += dxa.o
+OBJS-$(CONFIG_EA_DEMUXER) += electronicarts.o
+OBJS-$(CONFIG_FFM_DEMUXER) += ffm.o
+OBJS-$(CONFIG_FFM_MUXER) += ffm.o
+OBJS-$(CONFIG_FLIC_DEMUXER) += flic.o
+OBJS-$(CONFIG_FLV_DEMUXER) += flvdec.o
+OBJS-$(CONFIG_FLV_MUXER) += flvenc.o
+OBJS-$(CONFIG_GIF_MUXER) += gif.o
+OBJS-$(CONFIG_GIF_DEMUXER) += gifdec.o
+OBJS-$(CONFIG_GXF_DEMUXER) += gxf.o
+OBJS-$(CONFIG_GXF_MUXER) += gxfenc.o
+OBJS-$(CONFIG_IDCIN_DEMUXER) += idcin.o
+OBJS-$(CONFIG_ROQ_DEMUXER) += idroq.o
+OBJS-$(CONFIG_IMAGE2_DEMUXER) += img2.o
+OBJS-$(CONFIG_IMAGE2PIPE_DEMUXER) += img2.o
+OBJS-$(CONFIG_IMAGE2_MUXER) += img2.o
+OBJS-$(CONFIG_IMAGE2PIPE_MUXER) += img2.o
+OBJS-$(CONFIG_IPMOVIE_DEMUXER) += ipmovie.o
+OBJS-$(CONFIG_MATROSKA_DEMUXER) += matroska.o riff.o
+OBJS-$(CONFIG_MM_DEMUXER) += mm.o
+OBJS-$(CONFIG_MMF_DEMUXER) += mmf.o riff.o
+OBJS-$(CONFIG_MMF_MUXER) += mmf.o riff.o
+OBJS-$(CONFIG_MOV_DEMUXER) += mov.o riff.o isom.o
+OBJS-$(CONFIG_MOV_MUXER) += movenc.o riff.o isom.o
+OBJS-$(CONFIG_TGP_MUXER) += movenc.o riff.o isom.o
+OBJS-$(CONFIG_MP4_MUXER) += movenc.o riff.o isom.o
+OBJS-$(CONFIG_PSP_MUXER) += movenc.o riff.o isom.o
+OBJS-$(CONFIG_TG2_MUXER) += movenc.o riff.o isom.o
+OBJS-$(CONFIG_MP3_DEMUXER) += mp3.o
+OBJS-$(CONFIG_MP2_MUXER) += mp3.o
+OBJS-$(CONFIG_MP3_MUXER) += mp3.o
+OBJS-$(CONFIG_MPC_DEMUXER) += mpc.o
+OBJS-$(CONFIG_MPEG1SYSTEM_MUXER) += mpeg.o
+OBJS-$(CONFIG_MPEG1VCD_MUXER) += mpeg.o
+OBJS-$(CONFIG_MPEG2VOB_MUXER) += mpeg.o
+OBJS-$(CONFIG_MPEG2SVCD_MUXER) += mpeg.o
+OBJS-$(CONFIG_MPEG2DVD_MUXER) += mpeg.o
+OBJS-$(CONFIG_MPEGPS_DEMUXER) += mpeg.o
+OBJS-$(CONFIG_MPEGTS_DEMUXER) += mpegts.o
+OBJS-$(CONFIG_MPEGTS_MUXER) += mpegtsenc.o
+OBJS-$(CONFIG_MPJPEG_MUXER) += mpjpeg.o
+OBJS-$(CONFIG_MTV_DEMUXER) += mtv.o
+OBJS-$(CONFIG_MXF_DEMUXER) += mxf.o
+OBJS-$(CONFIG_NSV_DEMUXER) += nsvdec.o riff.o
+OBJS-$(CONFIG_NUV_DEMUXER) += nuv.o riff.o
+OBJS-$(CONFIG_OGG_DEMUXER) += ogg2.o \
+ oggparsevorbis.o \
+ oggparsetheora.o \
+ oggparseflac.o \
+ oggparseogm.o \
+ riff.o
+OBJS-$(CONFIG_OGG_MUXER) += ogg.o
+OBJS-$(CONFIG_STR_DEMUXER) += psxstr.o
+OBJS-$(CONFIG_SHORTEN_DEMUXER) += raw.o
+OBJS-$(CONFIG_FLAC_DEMUXER) += raw.o
+OBJS-$(CONFIG_FLAC_MUXER) += raw.o
+OBJS-$(CONFIG_AC3_DEMUXER) += raw.o
+OBJS-$(CONFIG_AC3_MUXER) += raw.o
+OBJS-$(CONFIG_DTS_DEMUXER) += raw.o
+OBJS-$(CONFIG_AAC_DEMUXER) += raw.o
+OBJS-$(CONFIG_H261_DEMUXER) += raw.o
+OBJS-$(CONFIG_H261_MUXER) += raw.o
+OBJS-$(CONFIG_H263_DEMUXER) += raw.o
+OBJS-$(CONFIG_H263_MUXER) += raw.o
+OBJS-$(CONFIG_M4V_DEMUXER) += raw.o
+OBJS-$(CONFIG_M4V_MUXER) += raw.o
+OBJS-$(CONFIG_H264_DEMUXER) += raw.o
+OBJS-$(CONFIG_H264_MUXER) += raw.o
+OBJS-$(CONFIG_MPEGVIDEO_DEMUXER) += raw.o
+OBJS-$(CONFIG_MPEG1VIDEO_MUXER) += raw.o
+OBJS-$(CONFIG_MPEG2VIDEO_MUXER) += raw.o
+OBJS-$(CONFIG_MJPEG_DEMUXER) += raw.o
+OBJS-$(CONFIG_INGENIENT_DEMUXER) += raw.o
+OBJS-$(CONFIG_MJPEG_MUXER) += raw.o
+OBJS-$(CONFIG_RAWVIDEO_DEMUXER) += raw.o
+OBJS-$(CONFIG_RAWVIDEO_MUXER) += raw.o
+OBJS-$(CONFIG_NULL_MUXER) += raw.o
+OBJS-$(CONFIG_NUT_DEMUXER) += nutdec.o riff.o
+OBJS-$(CONFIG_RM_DEMUXER) += rm.o
+OBJS-$(CONFIG_RM_MUXER) += rm.o
+OBJS-$(CONFIG_SEGAFILM_DEMUXER) += segafilm.o
+OBJS-$(CONFIG_VMD_DEMUXER) += sierravmd.o
+OBJS-$(CONFIG_SMACKER_DEMUXER) += smacker.o
+OBJS-$(CONFIG_SOL_DEMUXER) += sol.o
+OBJS-$(CONFIG_SWF_DEMUXER) += swf.o
+OBJS-$(CONFIG_SWF_MUXER) += swf.o
+OBJS-$(CONFIG_THP_DEMUXER) += thp.o
+OBJS-$(CONFIG_TIERTEXSEQ_DEMUXER) += tiertexseq.o
+OBJS-$(CONFIG_TTA_DEMUXER) += tta.o
+OBJS-$(CONFIG_V4L2_DEMUXER) += v4l2.o
+OBJS-$(CONFIG_VOC_DEMUXER) += vocdec.o voc.o riff.o
+OBJS-$(CONFIG_VOC_MUXER) += vocenc.o voc.o riff.o
+OBJS-$(CONFIG_WAV_DEMUXER) += wav.o riff.o
+OBJS-$(CONFIG_WAV_MUXER) += wav.o riff.o
+OBJS-$(CONFIG_WC3_DEMUXER) += wc3movie.o
+OBJS-$(CONFIG_WSAUD_DEMUXER) += westwood.o
+OBJS-$(CONFIG_WSVQA_DEMUXER) += westwood.o
+OBJS-$(CONFIG_WV_DEMUXER) += wv.o
+OBJS-$(CONFIG_X11_GRAB_DEVICE_DEMUXER) += x11grab.o
+OBJS-$(CONFIG_YUV4MPEGPIPE_MUXER) += yuv4mpeg.o
+OBJS-$(CONFIG_YUV4MPEGPIPE_DEMUXER) += yuv4mpeg.o
+
+# external libraries
+OBJS-$(CONFIG_LIBNUT_DEMUXER) += libnut.o riff.o
+OBJS-$(CONFIG_LIBNUT_MUXER) += libnut.o riff.o
+
+OBJS+= framehook.o
+
+ifeq ($(CONFIG_V4L),yes)
+OBJS-$(CONFIG_VIDEO_GRAB_DEVICE_DEMUXER) += grab.o
+endif
+
+ifeq ($(CONFIG_BKTR),yes)
+OBJS-$(CONFIG_VIDEO_GRAB_DEVICE_DEMUXER) += grab_bktr.o
+endif
+
+ifeq ($(CONFIG_AUDIO_OSS),yes)
+OBJS-$(CONFIG_AUDIO_DEMUXER) += audio.o
+OBJS-$(CONFIG_AUDIO_MUXER) += audio.o
+endif
+
+EXTRALIBS := -L$(BUILD_ROOT)/libavutil -lavutil$(BUILDSUF) \
+ -lavcodec$(BUILDSUF) -L$(BUILD_ROOT)/libavcodec $(EXTRALIBS)
+
+ifeq ($(CONFIG_AUDIO_BEOS),yes)
+CPPOBJS+= beosaudio.o
+endif
+
+# protocols I/O
+OBJS+= avio.o aviobuf.o
+
+ifeq ($(CONFIG_PROTOCOLS),yes)
+OBJS+= file.o
+ifeq ($(CONFIG_NETWORK),yes)
+OBJS+= udp.o tcp.o http.o rtsp.o rtp.o rtpproto.o mpegts.o rtp_h264.o
+endif
+endif
+
+NAME=avformat
+LIBVERSION=$(LAVFVERSION)
+LIBMAJOR=$(LAVFMAJOR)
+
+include ../common.mak
diff --git a/contrib/ffmpeg/libavformat/adtsenc.c b/contrib/ffmpeg/libavformat/adtsenc.c
new file mode 100644
index 000000000..1ef683838
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/adtsenc.c
@@ -0,0 +1,123 @@
+/*
+ * ADTS muxer.
+ * Copyright (c) 2006 Baptiste Coudurier <baptiste.coudurier@smartjog.com>
+ * Mans Rullgard <mru@inprovide.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include "avformat.h"
+#include "bitstream.h"
+
+#define ADTS_HEADER_SIZE 7
+
+typedef struct {
+ int write_adts;
+ int objecttype;
+ int sample_rate_index;
+ int channel_conf;
+} ADTSContext;
+
+static int decode_extradata(ADTSContext *adts, uint8_t *buf, int size)
+{
+ GetBitContext gb;
+
+ init_get_bits(&gb, buf, size * 8);
+ adts->objecttype = get_bits(&gb, 5) - 1;
+ adts->sample_rate_index = get_bits(&gb, 4);
+ adts->channel_conf = get_bits(&gb, 4);
+
+ adts->write_adts = 1;
+
+ return 0;
+}
+
+static int adts_write_header(AVFormatContext *s)
+{
+ ADTSContext *adts = s->priv_data;
+ AVCodecContext *avc = s->streams[0]->codec;
+
+ if(avc->extradata_size > 0)
+ decode_extradata(adts, avc->extradata, avc->extradata_size);
+
+ return 0;
+}
+
+static int adts_write_frame_header(AVFormatContext *s, int size)
+{
+ ADTSContext *ctx = s->priv_data;
+ PutBitContext pb;
+ uint8_t buf[ADTS_HEADER_SIZE];
+
+ init_put_bits(&pb, buf, ADTS_HEADER_SIZE);
+
+ /* adts_fixed_header */
+ put_bits(&pb, 12, 0xfff); /* syncword */
+ put_bits(&pb, 1, 0); /* ID */
+ put_bits(&pb, 2, 0); /* layer */
+ put_bits(&pb, 1, 1); /* protection_absent */
+ put_bits(&pb, 2, ctx->objecttype); /* profile_objecttype */
+ put_bits(&pb, 4, ctx->sample_rate_index);
+ put_bits(&pb, 1, 0); /* private_bit */
+ put_bits(&pb, 3, ctx->channel_conf); /* channel_configuration */
+ put_bits(&pb, 1, 0); /* original_copy */
+ put_bits(&pb, 1, 0); /* home */
+
+ /* 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); /* 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);
+
+ return 0;
+}
+
+static int adts_write_trailer(AVFormatContext *s)
+{
+ return 0;
+}
+
+static int adts_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ ADTSContext *adts = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+
+ if (!pkt->size)
+ return 0;
+ if(adts->write_adts)
+ adts_write_frame_header(s, pkt->size);
+ put_buffer(pb, pkt->data, pkt->size);
+ put_flush_packet(pb);
+
+ return 0;
+}
+
+AVOutputFormat adts_muxer = {
+ "adts",
+ "ADTS AAC",
+ "audio/aac",
+ "aac",
+ sizeof(ADTSContext),
+ CODEC_ID_AAC,
+ CODEC_ID_NONE,
+ adts_write_header,
+ adts_write_packet,
+ adts_write_trailer,
+};
diff --git a/contrib/ffmpeg/libavformat/aiff.c b/contrib/ffmpeg/libavformat/aiff.c
new file mode 100644
index 000000000..868d55219
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/aiff.c
@@ -0,0 +1,444 @@
+/*
+ * AIFF/AIFF-C muxer and 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 "avformat.h"
+#include "allformats.h"
+#include "riff.h"
+#include "intfloat_readwrite.h"
+
+static const AVCodecTag 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_ALAW, MKTAG('a','l','a','w') },
+ { CODEC_ID_PCM_ALAW, MKTAG('A','L','A','W') },
+ { CODEC_ID_PCM_MULAW, MKTAG('u','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') },
+ { 0, 0 },
+};
+
+#define AIFF 0
+#define AIFF_C_VERSION1 0xA2805140
+
+static int 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 0;
+}
+
+/* returns the size of the found tag */
+static int get_tag(ByteIOContext *pb, uint32_t * tag)
+{
+ int size;
+
+ if (url_feof(pb))
+ return AVERROR_IO;
+
+ *tag = get_le32(pb);
+ size = get_be32(pb);
+
+ if (size < 0)
+ size = 0x7fffffff;
+
+ return size;
+}
+
+/* Metadata string read */
+static void get_meta(ByteIOContext *pb, char * str, int strsize, int size)
+{
+ int res;
+
+ if (size > strsize-1)
+ res = get_buffer(pb, (uint8_t*)str, strsize-1);
+ else
+ res = get_buffer(pb, (uint8_t*)str, size);
+
+ if (res < 0)
+ return;
+
+ str[res] = 0;
+ if (size & 1)
+ size++;
+ size -= res;
+ if (size)
+ url_fskip(pb, size);
+}
+
+/* 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 = CODEC_TYPE_AUDIO;
+ codec->channels = get_be16(pb);
+ num_frames = get_be32(pb);
+ codec->bits_per_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 = codec_get_id (codec_aiff_tags, codec->codec_tag);
+
+ if (codec->codec_id == CODEC_ID_PCM_S16BE) {
+ codec->codec_id = aiff_codec_get_id (codec->bits_per_sample);
+ codec->bits_per_sample = av_get_bits_per_sample(codec->codec_id);
+ }
+
+ size -= 4;
+ } else {
+ /* Need the codec type */
+ codec->codec_id = aiff_codec_get_id (codec->bits_per_sample);
+ codec->bits_per_sample = av_get_bits_per_sample(codec->codec_id);
+ }
+
+ if (!codec->codec_id)
+ return AVERROR_INVALIDDATA;
+
+ /* Block align needs to be computed in all cases, as the definition
+ * is specific to applications -> here we use the WAVE format definition */
+ codec->block_align = (codec->bits_per_sample * codec->channels) >> 3;
+
+ codec->bit_rate = codec->sample_rate * (codec->block_align << 3);
+
+ /* Chunk is over */
+ if (size)
+ url_fseek(pb, size, SEEK_CUR);
+
+ return num_frames;
+}
+
+#ifdef CONFIG_MUXERS
+typedef struct {
+ offset_t form;
+ offset_t frames;
+ offset_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) {
+ /* 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_sample)
+ enc->bits_per_sample = av_get_bits_per_sample(enc->codec_id);
+ if (!enc->bits_per_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_sample * enc->channels) >> 3;
+
+ put_be16(pb, enc->bits_per_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 */
+ offset_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, (uint32_t)(file_size - aiff->form - 4));
+
+ /* Number of sample frames */
+ url_fseek(pb, aiff->frames, SEEK_SET);
+ put_be32(pb, ((uint32_t)(file_size-aiff->ssnd-12))/enc->block_align);
+
+ /* Sound Data chunk size */
+ url_fseek(pb, aiff->ssnd, SEEK_SET);
+ put_be32(pb, (uint32_t)(file_size - aiff->ssnd - 4));
+
+ /* return to the end */
+ url_fseek(pb, end_size, SEEK_SET);
+
+ put_flush_packet(pb);
+ }
+
+ return 0;
+}
+#endif //CONFIG_MUXERS
+
+static int aiff_probe(AVProbeData *p)
+{
+ /* check file header */
+ if (p->buf_size < 16)
+ return 0;
+ 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, offset;
+ uint32_t tag;
+ unsigned version = AIFF_C_VERSION1;
+ ByteIOContext *pb = &s->pb;
+ AVStream * st = s->streams[0];
+
+ /* 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_NOMEM;
+
+ 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;
+ 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 (pb, s->title, sizeof(s->title), size);
+ break;
+
+ case MKTAG('A', 'U', 'T', 'H'): /* Author chunk */
+ get_meta (pb, s->author, sizeof(s->author), size);
+ break;
+
+ case MKTAG('(', 'c', ')', ' '): /* Copyright chunk */
+ get_meta (pb, s->copyright, sizeof(s->copyright), size);
+ break;
+
+ case MKTAG('A', 'N', 'N', 'O'): /* Annotation chunk */
+ get_meta (pb, s->comment, sizeof(s->comment), size);
+ break;
+
+ case MKTAG('S', 'S', 'N', 'D'): /* Sampled sound chunk */
+ get_be32(pb); /* Block align... don't care */
+ offset = get_be32(pb); /* Offset of sound data */
+ goto got_sound;
+
+ default: /* Jump */
+ if (size & 1) /* Always even aligned */
+ size++;
+ url_fskip (pb, size);
+ }
+ }
+
+ /* End of loop and didn't get sound */
+ return AVERROR_INVALIDDATA;
+
+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->nb_frames;
+
+ /* Position the stream at the first block */
+ url_fskip(pb, offset);
+
+ return 0;
+}
+
+#define MAX_SIZE 4096
+
+static int aiff_read_packet(AVFormatContext *s,
+ AVPacket *pkt)
+{
+ AVStream *st = s->streams[0];
+ int res;
+
+ /* End of stream may be reached */
+ if (url_feof(&s->pb))
+ return AVERROR_IO;
+
+ /* Now for that packet */
+ res = av_get_packet(&s->pb, pkt, (MAX_SIZE / st->codec->block_align) * st->codec->block_align);
+ if (res < 0)
+ return res;
+
+ /* Only one stream in an AIFF file */
+ pkt->stream_index = 0;
+ return 0;
+}
+
+static int aiff_read_close(AVFormatContext *s)
+{
+ return 0;
+}
+
+static int aiff_read_seek(AVFormatContext *s,
+ int stream_index, int64_t timestamp, int flags)
+{
+ return pcm_read_seek(s, stream_index, timestamp, flags);
+}
+
+#ifdef CONFIG_AIFF_DEMUXER
+AVInputFormat aiff_demuxer = {
+ "aiff",
+ "Audio IFF",
+ 0,
+ aiff_probe,
+ aiff_read_header,
+ aiff_read_packet,
+ aiff_read_close,
+ aiff_read_seek,
+ .codec_tag= (const AVCodecTag*[]){codec_aiff_tags, 0},
+};
+#endif
+
+#ifdef CONFIG_AIFF_MUXER
+AVOutputFormat aiff_muxer = {
+ "aiff",
+ "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*[]){codec_aiff_tags, 0},
+};
+#endif
diff --git a/contrib/ffmpeg/libavformat/allformats.c b/contrib/ffmpeg/libavformat/allformats.c
new file mode 100644
index 000000000..8534a18f6
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/allformats.c
@@ -0,0 +1,172 @@
+/*
+ * Register all the formats and protocols
+ * Copyright (c) 2000, 2001, 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
+ */
+#include "avformat.h"
+#include "allformats.h"
+
+#define REGISTER_MUXER(X,x) \
+ if(ENABLE_##X##_MUXER) av_register_output_format(&x##_muxer)
+#define REGISTER_DEMUXER(X,x) \
+ if(ENABLE_##X##_DEMUXER) av_register_input_format(&x##_demuxer)
+#define REGISTER_MUXDEMUX(X,x) REGISTER_MUXER(X,x); REGISTER_DEMUXER(X,x)
+
+/* If you do not call this function, then you can select exactly which
+ formats you want to support */
+
+/**
+ * Initialize libavformat and register all the (de)muxers and protocols.
+ */
+void av_register_all(void)
+{
+ static int inited = 0;
+
+ if (inited != 0)
+ return;
+ inited = 1;
+
+ avcodec_init();
+ avcodec_register_all();
+
+ REGISTER_DEMUXER (AAC, aac);
+ REGISTER_MUXDEMUX(AC3, ac3);
+ REGISTER_MUXER (ADTS, adts);
+ REGISTER_MUXDEMUX(AIFF, aiff);
+ REGISTER_MUXDEMUX(AMR, amr);
+ REGISTER_MUXDEMUX(ASF, asf);
+ REGISTER_MUXER (ASF_STREAM, asf_stream);
+ REGISTER_MUXDEMUX(AU, au);
+ REGISTER_MUXDEMUX(AUDIO, audio);
+ REGISTER_MUXDEMUX(AVI, avi);
+#ifdef CONFIG_AVISYNTH
+ av_register_input_format(&avisynth_demuxer);
+#endif
+ REGISTER_DEMUXER (AVS, avs);
+ REGISTER_MUXER (CRC, crc);
+ REGISTER_DEMUXER (DAUD, daud);
+ REGISTER_DEMUXER (DC1394, dc1394);
+ REGISTER_DEMUXER (DSICIN, dsicin);
+ REGISTER_DEMUXER (DTS, dts);
+ REGISTER_MUXDEMUX(DV, dv);
+ REGISTER_DEMUXER (DV1394, dv1394);
+ REGISTER_DEMUXER (DXA, dxa);
+ REGISTER_DEMUXER (EA, ea);
+ REGISTER_MUXDEMUX(FFM, ffm);
+ REGISTER_MUXDEMUX(FLAC, flac);
+ REGISTER_DEMUXER (FLIC, flic);
+ REGISTER_MUXDEMUX(FLV, flv);
+ REGISTER_DEMUXER (FOURXM, fourxm);
+ REGISTER_MUXER (FRAMECRC, framecrc);
+ REGISTER_MUXDEMUX(GIF, gif);
+ REGISTER_DEMUXER (GXF, gxf);
+ REGISTER_MUXER (GXF, gxf);
+ REGISTER_MUXDEMUX(H261, h261);
+ REGISTER_MUXDEMUX(H263, h263);
+ REGISTER_MUXDEMUX(H264, h264);
+ REGISTER_DEMUXER (IDCIN, idcin);
+ REGISTER_MUXDEMUX(IMAGE2, image2);
+ REGISTER_MUXDEMUX(IMAGE2PIPE, image2pipe);
+ REGISTER_DEMUXER (INGENIENT, ingenient);
+ REGISTER_DEMUXER (IPMOVIE, ipmovie);
+ if (!ENABLE_NUT_DEMUXER) REGISTER_DEMUXER (LIBNUT, libnut);
+ REGISTER_MUXER (LIBNUT, libnut);
+ REGISTER_MUXDEMUX(M4V, m4v);
+ REGISTER_DEMUXER (MATROSKA, matroska);
+ REGISTER_MUXDEMUX(MJPEG, mjpeg);
+ REGISTER_DEMUXER (MM, mm);
+ REGISTER_MUXDEMUX(MMF, mmf);
+ REGISTER_MUXDEMUX(MOV, mov);
+ REGISTER_MUXER (MP2, mp2);
+ REGISTER_MUXDEMUX(MP3, mp3);
+ REGISTER_MUXER (MP4, mp4);
+ REGISTER_DEMUXER (MPC, mpc);
+ REGISTER_MUXER (MPEG1SYSTEM, mpeg1system);
+ REGISTER_MUXER (MPEG1VCD, mpeg1vcd);
+ REGISTER_MUXER (MPEG1VIDEO, mpeg1video);
+ REGISTER_MUXER (MPEG2DVD, mpeg2dvd);
+ REGISTER_MUXER (MPEG2SVCD, mpeg2svcd);
+ REGISTER_MUXER (MPEG2VIDEO, mpeg2video);
+ REGISTER_MUXER (MPEG2VOB, mpeg2vob);
+ REGISTER_DEMUXER (MPEGPS, mpegps);
+ REGISTER_MUXDEMUX(MPEGTS, mpegts);
+ REGISTER_DEMUXER (MPEGVIDEO, mpegvideo);
+ REGISTER_MUXER (MPJPEG, mpjpeg);
+ REGISTER_DEMUXER (MTV, mtv);
+ REGISTER_DEMUXER (MXF, mxf);
+ REGISTER_DEMUXER (NSV, nsv);
+ REGISTER_MUXER (NULL, null);
+ REGISTER_DEMUXER (NUT, nut);
+ REGISTER_DEMUXER (NUV, nuv);
+ REGISTER_DEMUXER (OGG, ogg);
+ REGISTER_MUXER (OGG, ogg);
+ REGISTER_MUXDEMUX(PCM_ALAW, pcm_alaw);
+ REGISTER_MUXDEMUX(PCM_MULAW, pcm_mulaw);
+ REGISTER_MUXDEMUX(PCM_S16BE, pcm_s16be);
+ REGISTER_MUXDEMUX(PCM_S16LE, pcm_s16le);
+ REGISTER_MUXDEMUX(PCM_S8, pcm_s8);
+ REGISTER_MUXDEMUX(PCM_U16BE, pcm_u16be);
+ REGISTER_MUXDEMUX(PCM_U16LE, pcm_u16le);
+ REGISTER_MUXDEMUX(PCM_U8, pcm_u8);
+ REGISTER_MUXER (PSP, psp);
+ REGISTER_MUXDEMUX(RAWVIDEO, rawvideo);
+ REGISTER_MUXDEMUX(RM, rm);
+ REGISTER_DEMUXER (ROQ, roq);
+ REGISTER_DEMUXER (REDIR, redir);
+ REGISTER_MUXER (RTP, rtp);
+ REGISTER_DEMUXER (RTSP, rtsp);
+ REGISTER_DEMUXER (SDP, sdp);
+#ifdef CONFIG_NETWORK
+ av_register_rtp_dynamic_payload_handlers();
+#endif
+ REGISTER_DEMUXER (SEGAFILM, segafilm);
+ REGISTER_DEMUXER (SHORTEN, shorten);
+ REGISTER_DEMUXER (SMACKER, smacker);
+ REGISTER_DEMUXER (SOL, sol);
+ REGISTER_DEMUXER (STR, str);
+ REGISTER_MUXDEMUX(SWF, swf);
+ REGISTER_MUXER (TG2, tg2);
+ REGISTER_MUXER (TGP, tgp);
+ REGISTER_DEMUXER (THP, thp);
+ REGISTER_DEMUXER (TIERTEXSEQ, tiertexseq);
+ REGISTER_DEMUXER (TTA, tta);
+ REGISTER_DEMUXER (V4L2, v4l2);
+ REGISTER_DEMUXER (VC1, vc1);
+ REGISTER_DEMUXER (VIDEO_GRAB_DEVICE, video_grab_device);
+ REGISTER_DEMUXER (VMD, vmd);
+ REGISTER_MUXDEMUX(VOC, voc);
+ REGISTER_MUXDEMUX(WAV, wav);
+ REGISTER_DEMUXER (WC3, wc3);
+ REGISTER_DEMUXER (WSAUD, wsaud);
+ REGISTER_DEMUXER (WSVQA, wsvqa);
+ REGISTER_DEMUXER (WV, wv);
+ REGISTER_DEMUXER (X11_GRAB_DEVICE, x11_grab_device);
+ REGISTER_MUXDEMUX(YUV4MPEGPIPE, yuv4mpegpipe);
+
+#ifdef CONFIG_PROTOCOLS
+ /* file protocols */
+ register_protocol(&file_protocol);
+ register_protocol(&pipe_protocol);
+#ifdef CONFIG_NETWORK
+ register_protocol(&udp_protocol);
+ register_protocol(&rtp_protocol);
+ register_protocol(&tcp_protocol);
+ register_protocol(&http_protocol);
+#endif
+#endif
+}
diff --git a/contrib/ffmpeg/libavformat/allformats.h b/contrib/ffmpeg/libavformat/allformats.h
new file mode 100644
index 000000000..9734940d3
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/allformats.h
@@ -0,0 +1,182 @@
+/*
+ * Register all the formats and protocols.
+ * copyright (c) 2000, 2001, 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
+ */
+
+#ifndef ALLFORMATS_H
+#define ALLFORMATS_H
+
+extern AVInputFormat fourxm_demuxer;
+extern AVOutputFormat adts_muxer;
+extern AVInputFormat aiff_demuxer;
+extern AVOutputFormat aiff_muxer;
+extern AVInputFormat amr_demuxer;
+extern AVOutputFormat amr_muxer;
+extern AVInputFormat asf_demuxer;
+extern AVOutputFormat asf_muxer;
+extern AVOutputFormat asf_stream_muxer;
+extern AVInputFormat au_demuxer;
+extern AVOutputFormat au_muxer;
+extern AVInputFormat audio_demuxer;
+extern AVOutputFormat audio_muxer;
+extern AVInputFormat avi_demuxer;
+extern AVOutputFormat avi_muxer;
+extern AVInputFormat avisynth_demuxer;
+extern AVInputFormat avs_demuxer;
+extern AVOutputFormat crc_muxer;
+extern AVOutputFormat framecrc_muxer;
+extern AVInputFormat daud_demuxer;
+extern AVInputFormat dc1394_demuxer;
+extern AVInputFormat dsicin_demuxer;
+extern AVInputFormat dv1394_demuxer;
+extern AVInputFormat dv_demuxer;
+extern AVOutputFormat dv_muxer;
+extern AVInputFormat dxa_demuxer;
+extern AVInputFormat ea_demuxer;
+extern AVInputFormat ffm_demuxer;
+extern AVOutputFormat ffm_muxer;
+extern AVInputFormat flic_demuxer;
+extern AVInputFormat flv_demuxer;
+extern AVOutputFormat flv_muxer;
+extern AVOutputFormat gif_muxer;
+extern AVInputFormat gif_demuxer;
+extern AVInputFormat video_grab_device_demuxer;
+extern AVInputFormat gxf_demuxer;
+extern AVOutputFormat gxf_muxer;
+extern AVInputFormat idcin_demuxer;
+extern AVInputFormat roq_demuxer;
+extern AVInputFormat image2_demuxer;
+extern AVInputFormat image2pipe_demuxer;
+extern AVOutputFormat image2_muxer;
+extern AVOutputFormat image2pipe_muxer;
+extern AVInputFormat image_demuxer;
+extern AVInputFormat imagepipe_demuxer;
+extern AVOutputFormat image_muxer;
+extern AVOutputFormat imagepipe_muxer;
+extern AVInputFormat ipmovie_demuxer;
+extern AVInputFormat libnut_demuxer;
+extern AVOutputFormat libnut_muxer;
+extern AVInputFormat matroska_demuxer;
+extern AVInputFormat mm_demuxer;
+extern AVInputFormat mmf_demuxer;
+extern AVOutputFormat mmf_muxer;
+extern AVInputFormat mov_demuxer;
+extern AVOutputFormat mov_muxer;
+extern AVOutputFormat tgp_muxer;
+extern AVOutputFormat mp4_muxer;
+extern AVOutputFormat psp_muxer;
+extern AVOutputFormat tg2_muxer;
+extern AVInputFormat mp3_demuxer;
+extern AVOutputFormat mp2_muxer;
+extern AVOutputFormat mp3_muxer;
+extern AVInputFormat mpc_demuxer;
+extern AVOutputFormat mpeg1system_muxer;
+extern AVOutputFormat mpeg1vcd_muxer;
+extern AVOutputFormat mpeg2vob_muxer;
+extern AVOutputFormat mpeg2svcd_muxer;
+extern AVOutputFormat mpeg2dvd_muxer;
+extern AVInputFormat mpegps_demuxer;
+extern AVInputFormat mpegts_demuxer;
+extern AVOutputFormat mpegts_muxer;
+extern AVOutputFormat mpjpeg_muxer;
+extern AVInputFormat mtv_demuxer;
+extern AVInputFormat mxf_demuxer;
+extern AVInputFormat nsv_demuxer;
+extern AVInputFormat nut_demuxer;
+extern AVInputFormat nuv_demuxer;
+extern AVInputFormat ogg_demuxer;
+extern AVOutputFormat ogg_muxer;
+extern AVInputFormat str_demuxer;
+extern AVInputFormat shorten_demuxer;
+extern AVInputFormat flac_demuxer;
+extern AVOutputFormat flac_muxer;
+extern AVInputFormat ac3_demuxer;
+extern AVOutputFormat ac3_muxer;
+extern AVInputFormat dts_demuxer;
+extern AVInputFormat aac_demuxer;
+extern AVInputFormat h261_demuxer;
+extern AVOutputFormat h261_muxer;
+extern AVInputFormat h263_demuxer;
+extern AVOutputFormat h263_muxer;
+extern AVInputFormat m4v_demuxer;
+extern AVOutputFormat m4v_muxer;
+extern AVInputFormat h264_demuxer;
+extern AVOutputFormat h264_muxer;
+extern AVInputFormat mpegvideo_demuxer;
+extern AVOutputFormat mpeg1video_muxer;
+extern AVOutputFormat mpeg2video_muxer;
+extern AVInputFormat mjpeg_demuxer;
+extern AVInputFormat ingenient_demuxer;
+extern AVOutputFormat mjpeg_muxer;
+extern AVInputFormat pcm_s16le_demuxer;
+extern AVOutputFormat pcm_s16le_muxer;
+extern AVInputFormat pcm_s16be_demuxer;
+extern AVOutputFormat pcm_s16be_muxer;
+extern AVInputFormat pcm_u16le_demuxer;
+extern AVOutputFormat pcm_u16le_muxer;
+extern AVInputFormat pcm_u16be_demuxer;
+extern AVOutputFormat pcm_u16be_muxer;
+extern AVInputFormat pcm_s8_demuxer;
+extern AVOutputFormat pcm_s8_muxer;
+extern AVInputFormat pcm_u8_demuxer;
+extern AVOutputFormat pcm_u8_muxer;
+extern AVInputFormat pcm_mulaw_demuxer;
+extern AVOutputFormat pcm_mulaw_muxer;
+extern AVInputFormat pcm_alaw_demuxer;
+extern AVOutputFormat pcm_alaw_muxer;
+extern AVInputFormat rawvideo_demuxer;
+extern AVOutputFormat rawvideo_muxer;
+extern AVOutputFormat null_muxer;
+extern AVInputFormat rm_demuxer;
+extern AVOutputFormat rm_muxer;
+extern AVInputFormat sdp_demuxer;
+extern AVInputFormat redir_demuxer;
+extern AVInputFormat segafilm_demuxer;
+extern AVInputFormat vmd_demuxer;
+extern AVInputFormat smacker_demuxer;
+extern AVInputFormat sol_demuxer;
+extern AVInputFormat swf_demuxer;
+extern AVOutputFormat swf_muxer;
+extern AVInputFormat tta_demuxer;
+extern AVInputFormat v4l2_demuxer;
+extern AVInputFormat vc1_demuxer;
+extern AVInputFormat voc_demuxer;
+extern AVOutputFormat voc_muxer;
+extern AVInputFormat wav_demuxer;
+extern AVOutputFormat wav_muxer;
+extern AVInputFormat wc3_demuxer;
+extern AVInputFormat wsaud_demuxer;
+extern AVInputFormat wsvqa_demuxer;
+extern AVInputFormat wv_demuxer;
+extern AVOutputFormat yuv4mpegpipe_muxer;
+extern AVInputFormat yuv4mpegpipe_demuxer;
+extern AVInputFormat tiertexseq_demuxer;
+extern AVInputFormat x11_grab_device_demuxer;
+extern AVInputFormat thp_demuxer;
+
+/* raw.c */
+int pcm_read_seek(AVFormatContext *s,
+ int stream_index, int64_t timestamp, int flags);
+
+/* rtsp.c */
+int redir_open(AVFormatContext **ic_ptr, ByteIOContext *f);
+/* rtp.c */
+void av_register_rtp_dynamic_payload_handlers();
+
+#endif
diff --git a/contrib/ffmpeg/libavformat/amr.c b/contrib/ffmpeg/libavformat/amr.c
new file mode 100644
index 000000000..635a898fa
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/amr.c
@@ -0,0 +1,201 @@
+/*
+ * amr file format
+ * Copyright (c) 2001 ffmpeg project
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*
+Write and read amr data according to RFC3267, http://www.ietf.org/rfc/rfc3267.txt?number=3267
+
+Only mono files are supported.
+
+*/
+#include "avformat.h"
+
+static const char AMR_header [] = "#!AMR\n";
+static const char AMRWB_header [] = "#!AMR-WB\n";
+
+#ifdef CONFIG_MUXERS
+static int amr_write_header(AVFormatContext *s)
+{
+ ByteIOContext *pb = &s->pb;
+ AVCodecContext *enc = s->streams[0]->codec;
+
+ s->priv_data = NULL;
+
+ if (enc->codec_id == CODEC_ID_AMR_NB)
+ {
+ put_tag(pb, AMR_header); /* magic number */
+ }
+ else if(enc->codec_id == CODEC_ID_AMR_WB)
+ {
+ put_tag(pb, AMRWB_header); /* magic number */
+ }
+ else
+ {
+ return -1;
+ }
+ put_flush_packet(pb);
+ return 0;
+}
+
+static int amr_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ put_buffer(&s->pb, pkt->data, pkt->size);
+ put_flush_packet(&s->pb);
+ return 0;
+}
+
+static int amr_write_trailer(AVFormatContext *s)
+{
+ return 0;
+}
+#endif /* CONFIG_MUXERS */
+
+static int amr_probe(AVProbeData *p)
+{
+ //Only check for "#!AMR" which could be amr-wb, amr-nb.
+ //This will also trigger multichannel files: "#!AMR_MC1.0\n" and
+ //"#!AMR-WB_MC1.0\n" (not supported)
+
+ if (p->buf_size < 5)
+ return 0;
+ if(memcmp(p->buf,AMR_header,5)==0)
+ return AVPROBE_SCORE_MAX;
+ else
+ return 0;
+}
+
+/* amr input */
+static int amr_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ ByteIOContext *pb = &s->pb;
+ AVStream *st;
+ uint8_t header[9];
+
+ get_buffer(pb, header, 6);
+
+ st = av_new_stream(s, 0);
+ if (!st)
+ {
+ return AVERROR_NOMEM;
+ }
+ if(memcmp(header,AMR_header,6)!=0)
+ {
+ get_buffer(pb, header+6, 3);
+ if(memcmp(header,AMRWB_header,9)!=0)
+ {
+ return -1;
+ }
+
+ st->codec->codec_tag = MKTAG('s', 'a', 'w', 'b');
+ st->codec->codec_id = CODEC_ID_AMR_WB;
+ st->codec->sample_rate = 16000;
+ }
+ else
+ {
+ st->codec->codec_tag = MKTAG('s', 'a', 'm', 'r');
+ st->codec->codec_id = CODEC_ID_AMR_NB;
+ st->codec->sample_rate = 8000;
+ }
+ st->codec->channels = 1;
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ av_set_pts_info(st, 64, 1, st->codec->sample_rate);
+
+ return 0;
+}
+
+static int amr_read_packet(AVFormatContext *s,
+ AVPacket *pkt)
+{
+ AVCodecContext *enc = s->streams[0]->codec;
+ int read, size, toc, mode;
+
+ if (url_feof(&s->pb))
+ {
+ return AVERROR_IO;
+ }
+
+//FIXME this is wrong, this should rather be in a AVParset
+ toc=get_byte(&s->pb);
+ mode = (toc >> 3) & 0x0F;
+
+ if (enc->codec_id == CODEC_ID_AMR_NB)
+ {
+ static const uint8_t packed_size[16] = {12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0};
+
+ size=packed_size[mode]+1;
+ }
+ else if(enc->codec_id == CODEC_ID_AMR_WB)
+ {
+ static uint8_t packed_size[16] = {18, 24, 33, 37, 41, 47, 51, 59, 61, 6, 6, 0, 0, 0, 1, 1};
+
+ size=packed_size[mode];
+ }
+ else
+ {
+ assert(0);
+ }
+
+ if ( (size==0) || av_new_packet(pkt, size))
+ {
+ return AVERROR_IO;
+ }
+
+ pkt->stream_index = 0;
+ pkt->pos= url_ftell(&s->pb);
+ pkt->data[0]=toc;
+ pkt->duration= enc->codec_id == CODEC_ID_AMR_NB ? 160 : 320;
+ read = get_buffer(&s->pb, pkt->data+1, size-1);
+
+ if (read != size-1)
+ {
+ av_free_packet(pkt);
+ return AVERROR_IO;
+ }
+
+ return 0;
+}
+
+#ifdef CONFIG_AMR_DEMUXER
+AVInputFormat amr_demuxer = {
+ "amr",
+ "3gpp amr file format",
+ 0, /*priv_data_size*/
+ amr_probe,
+ amr_read_header,
+ amr_read_packet,
+ NULL,
+};
+#endif
+
+#ifdef CONFIG_AMR_MUXER
+AVOutputFormat amr_muxer = {
+ "amr",
+ "3gpp amr file format",
+ "audio/amr",
+ "amr",
+ 0,
+ CODEC_ID_AMR_NB,
+ CODEC_ID_NONE,
+ amr_write_header,
+ amr_write_packet,
+ amr_write_trailer,
+};
+#endif
diff --git a/contrib/ffmpeg/libavformat/asf-enc.c b/contrib/ffmpeg/libavformat/asf-enc.c
new file mode 100644
index 000000000..f1d9c6903
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/asf-enc.c
@@ -0,0 +1,853 @@
+/*
+ * Adaptive stream format muxer
+ * Copyright (c) 2000, 2001 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 "avformat.h"
+#include "riff.h"
+#include "asf.h"
+
+#undef NDEBUG
+#include <assert.h>
+
+
+#define ASF_INDEXED_INTERVAL 10000000
+#define ASF_INDEX_BLOCK 600
+
+#define ASF_PACKET_ERROR_CORRECTION_DATA_SIZE 0x2
+#define ASF_PACKET_ERROR_CORRECTION_FLAGS (\
+ ASF_PACKET_FLAG_ERROR_CORRECTION_PRESENT | \
+ ASF_PACKET_ERROR_CORRECTION_DATA_SIZE\
+ )
+
+#if (ASF_PACKET_ERROR_CORRECTION_FLAGS != 0)
+# define ASF_PACKET_ERROR_CORRECTION_FLAGS_FIELD_SIZE 1
+#else
+# define ASF_PACKET_ERROR_CORRECTION_FLAGS_FIELD_SIZE 0
+#endif
+
+#define ASF_PPI_PROPERTY_FLAGS (\
+ ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_IS_BYTE | \
+ ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_IS_DWORD | \
+ ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_IS_BYTE | \
+ ASF_PL_FLAG_STREAM_NUMBER_LENGTH_FIELD_IS_BYTE \
+ )
+
+#define ASF_PPI_LENGTH_TYPE_FLAGS 0
+
+#define ASF_PAYLOAD_FLAGS ASF_PL_FLAG_PAYLOAD_LENGTH_FIELD_IS_WORD
+
+#if (ASF_PPI_FLAG_SEQUENCE_FIELD_IS_BYTE == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_SEQUENCE_FIELD_SIZE))
+# define ASF_PPI_SEQUENCE_FIELD_SIZE 1
+#endif
+#if (ASF_PPI_FLAG_SEQUENCE_FIELD_IS_WORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_SEQUENCE_FIELD_SIZE))
+# define ASF_PPI_SEQUENCE_FIELD_SIZE 2
+#endif
+#if (ASF_PPI_FLAG_SEQUENCE_FIELD_IS_DWORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_SEQUENCE_FIELD_SIZE))
+# define ASF_PPI_SEQUENCE_FIELD_SIZE 4
+#endif
+#ifndef ASF_PPI_SEQUENCE_FIELD_SIZE
+# define ASF_PPI_SEQUENCE_FIELD_SIZE 0
+#endif
+
+
+#if (ASF_PPI_FLAG_PACKET_LENGTH_FIELD_IS_BYTE == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PACKET_LENGTH_FIELD_SIZE))
+# define ASF_PPI_PACKET_LENGTH_FIELD_SIZE 1
+#endif
+#if (ASF_PPI_FLAG_PACKET_LENGTH_FIELD_IS_WORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PACKET_LENGTH_FIELD_SIZE))
+# define ASF_PPI_PACKET_LENGTH_FIELD_SIZE 2
+#endif
+#if (ASF_PPI_FLAG_PACKET_LENGTH_FIELD_IS_DWORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PACKET_LENGTH_FIELD_SIZE))
+# define ASF_PPI_PACKET_LENGTH_FIELD_SIZE 4
+#endif
+#ifndef ASF_PPI_PACKET_LENGTH_FIELD_SIZE
+# define ASF_PPI_PACKET_LENGTH_FIELD_SIZE 0
+#endif
+
+#if (ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PADDING_LENGTH_FIELD_SIZE))
+# define ASF_PPI_PADDING_LENGTH_FIELD_SIZE 1
+#endif
+#if (ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PADDING_LENGTH_FIELD_SIZE))
+# define ASF_PPI_PADDING_LENGTH_FIELD_SIZE 2
+#endif
+#if (ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_DWORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PADDING_LENGTH_FIELD_SIZE))
+# define ASF_PPI_PADDING_LENGTH_FIELD_SIZE 4
+#endif
+#ifndef ASF_PPI_PADDING_LENGTH_FIELD_SIZE
+# define ASF_PPI_PADDING_LENGTH_FIELD_SIZE 0
+#endif
+
+#if (ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_IS_BYTE == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_REPLICATED_DATA_LENGTH_FIELD_SIZE))
+# define ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE 1
+#endif
+#if (ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_IS_WORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_REPLICATED_DATA_LENGTH_FIELD_SIZE))
+# define ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE 2
+#endif
+#if (ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_IS_DWORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_REPLICATED_DATA_LENGTH_FIELD_SIZE))
+# define ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE 4
+#endif
+#ifndef ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE
+# define ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE 0
+#endif
+
+#if (ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_IS_BYTE == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_SIZE))
+# define ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE 1
+#endif
+#if (ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_IS_WORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_SIZE))
+# define ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE 2
+#endif
+#if (ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_IS_DWORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_SIZE))
+# define ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE 4
+#endif
+#ifndef ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE
+# define ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE 0
+#endif
+
+#if (ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_IS_BYTE == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_SIZE))
+# define ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE 1
+#endif
+#if (ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_IS_WORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_SIZE))
+# define ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE 2
+#endif
+#if (ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_IS_DWORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_SIZE))
+# define ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE 4
+#endif
+#ifndef ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE
+# define ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE 0
+#endif
+
+#if (ASF_PL_FLAG_PAYLOAD_LENGTH_FIELD_IS_BYTE == (ASF_PAYLOAD_FLAGS & ASF_PL_MASK_PAYLOAD_LENGTH_FIELD_SIZE))
+# define ASF_PAYLOAD_LENGTH_FIELD_SIZE 1
+#endif
+#if (ASF_PL_FLAG_PAYLOAD_LENGTH_FIELD_IS_WORD == (ASF_PAYLOAD_FLAGS & ASF_PL_MASK_PAYLOAD_LENGTH_FIELD_SIZE))
+# define ASF_PAYLOAD_LENGTH_FIELD_SIZE 2
+#endif
+#ifndef ASF_PAYLOAD_LENGTH_FIELD_SIZE
+# define ASF_PAYLOAD_LENGTH_FIELD_SIZE 0
+#endif
+
+#define PACKET_HEADER_MIN_SIZE (\
+ ASF_PACKET_ERROR_CORRECTION_FLAGS_FIELD_SIZE + \
+ ASF_PACKET_ERROR_CORRECTION_DATA_SIZE + \
+ 1 + /*Length Type Flags*/ \
+ 1 + /*Property Flags*/ \
+ ASF_PPI_PACKET_LENGTH_FIELD_SIZE + \
+ ASF_PPI_SEQUENCE_FIELD_SIZE + \
+ ASF_PPI_PADDING_LENGTH_FIELD_SIZE + \
+ 4 + /*Send Time Field*/ \
+ 2 /*Duration Field*/ \
+ )
+
+
+// Replicated Data shall be at least 8 bytes long.
+#define ASF_PAYLOAD_REPLICATED_DATA_LENGTH 0x08
+
+#define PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD (\
+ 1 + /*Stream Number*/ \
+ ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE + \
+ ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE + \
+ ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE + \
+ ASF_PAYLOAD_REPLICATED_DATA_LENGTH \
+ )
+
+#define PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS (\
+ 1 + /*Stream Number*/ \
+ ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE + \
+ ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE + \
+ ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE + \
+ ASF_PAYLOAD_REPLICATED_DATA_LENGTH + \
+ ASF_PAYLOAD_LENGTH_FIELD_SIZE \
+ )
+
+#define SINGLE_PAYLOAD_DATA_LENGTH (\
+ PACKET_SIZE - \
+ PACKET_HEADER_MIN_SIZE - \
+ PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD \
+ )
+
+#define MULTI_PAYLOAD_CONSTANT (\
+ PACKET_SIZE - \
+ PACKET_HEADER_MIN_SIZE - \
+ 1 - /*Payload Flags*/ \
+ 2*PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS \
+ )
+
+static const AVCodecTag codec_asf_bmp_tags[] = {
+ { CODEC_ID_MPEG4, MKTAG('M', 'P', '4', 'S') },
+ { CODEC_ID_MPEG4, MKTAG('M', '4', 'S', '2') },
+ { CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', '4', '3') },
+ { CODEC_ID_NONE, 0 },
+};
+
+#define PREROLL_TIME 3100
+
+static void put_guid(ByteIOContext *s, const GUID *g)
+{
+ assert(sizeof(*g) == 16);
+ 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);
+}
+
+static void put_str16_nolen(ByteIOContext *s, const char *tag)
+{
+ int c;
+
+ do{
+ c = (uint8_t)*tag++;
+ put_le16(s, c);
+ }while(c);
+}
+
+static int64_t put_header(ByteIOContext *pb, const GUID *g)
+{
+ int64_t pos;
+
+ pos = url_ftell(pb);
+ put_guid(pb, g);
+ put_le64(pb, 24);
+ return pos;
+}
+
+/* update header size */
+static void end_header(ByteIOContext *pb, int64_t pos)
+{
+ int64_t pos1;
+
+ pos1 = url_ftell(pb);
+ url_fseek(pb, pos + 16, SEEK_SET);
+ put_le64(pb, pos1 - pos);
+ url_fseek(pb, pos1, SEEK_SET);
+}
+
+/* write an asf chunk (only used in streaming case) */
+static void put_chunk(AVFormatContext *s, int type, int payload_length, int flags)
+{
+ ASFContext *asf = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ int length;
+
+ length = payload_length + 8;
+ put_le16(pb, type);
+ put_le16(pb, length); //size
+ put_le32(pb, asf->seqno);//sequence number
+ put_le16(pb, flags); /* unknown bytes */
+ put_le16(pb, length); //size_confirm
+ asf->seqno++;
+}
+
+/* convert from unix to windows time */
+static int64_t unix_to_file_time(int ti)
+{
+ int64_t t;
+
+ t = ti * INT64_C(10000000);
+ t += INT64_C(116444736000000000);
+ return t;
+}
+
+/* write the header (used two times if non streamed) */
+static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data_chunk_size)
+{
+ ASFContext *asf = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ int header_size, n, extra_size, extra_size2, wav_extra_size, file_time;
+ int has_title;
+ AVCodecContext *enc;
+ int64_t header_offset, cur_pos, hpos;
+ int bit_rate;
+ int64_t duration;
+
+ duration = asf->duration + PREROLL_TIME * 10000;
+ has_title = (s->title[0] || s->author[0] || s->copyright[0] || s->comment[0]);
+
+ bit_rate = 0;
+ for(n=0;n<s->nb_streams;n++) {
+ enc = s->streams[n]->codec;
+
+ av_set_pts_info(s->streams[n], 32, 1, 1000); /* 32 bit pts in ms */
+
+ bit_rate += enc->bit_rate;
+ }
+
+ if (asf->is_streamed) {
+ put_chunk(s, 0x4824, 0, 0xc00); /* start of stream (length will be patched later) */
+ }
+
+ put_guid(pb, &asf_header);
+ put_le64(pb, -1); /* header length, will be patched after */
+ put_le32(pb, 3 + has_title + s->nb_streams); /* number of chunks in header */
+ put_byte(pb, 1); /* ??? */
+ put_byte(pb, 2); /* ??? */
+
+ /* file header */
+ header_offset = url_ftell(pb);
+ hpos = put_header(pb, &file_header);
+ put_guid(pb, &my_guid);
+ put_le64(pb, file_size);
+ file_time = 0;
+ put_le64(pb, unix_to_file_time(file_time));
+ put_le64(pb, asf->nb_packets); /* number of packets */
+ put_le64(pb, duration); /* end time stamp (in 100ns units) */
+ put_le64(pb, asf->duration); /* duration (in 100ns units) */
+ put_le64(pb, PREROLL_TIME); /* start time stamp */
+ put_le32(pb, (asf->is_streamed || url_is_streamed(pb)) ? 3 : 2); /* ??? */
+ put_le32(pb, asf->packet_size); /* packet size */
+ put_le32(pb, asf->packet_size); /* packet size */
+ put_le32(pb, bit_rate); /* Nominal data rate in bps */
+ end_header(pb, hpos);
+
+ /* unknown headers */
+ hpos = put_header(pb, &head1_guid);
+ put_guid(pb, &head2_guid);
+ put_le32(pb, 6);
+ put_le16(pb, 0);
+ end_header(pb, hpos);
+
+ /* title and other infos */
+ if (has_title) {
+ hpos = put_header(pb, &comment_header);
+ if ( s->title[0] ) { put_le16(pb, 2 * (strlen(s->title ) + 1)); } else { put_le16(pb, 0); }
+ if ( s->author[0] ) { put_le16(pb, 2 * (strlen(s->author ) + 1)); } else { put_le16(pb, 0); }
+ if ( s->copyright[0] ) { put_le16(pb, 2 * (strlen(s->copyright) + 1)); } else { put_le16(pb, 0); }
+ if ( s->comment[0] ) { put_le16(pb, 2 * (strlen(s->comment ) + 1)); } else { put_le16(pb, 0); }
+ put_le16(pb, 0);
+ if ( s->title[0] ) put_str16_nolen(pb, s->title);
+ if ( s->author[0] ) put_str16_nolen(pb, s->author);
+ if ( s->copyright[0] ) put_str16_nolen(pb, s->copyright);
+ if ( s->comment[0] ) put_str16_nolen(pb, s->comment);
+ end_header(pb, hpos);
+ }
+
+ /* stream headers */
+ for(n=0;n<s->nb_streams;n++) {
+ int64_t es_pos;
+ // ASFStream *stream = &asf->streams[n];
+
+ enc = s->streams[n]->codec;
+ asf->streams[n].num = n + 1;
+ asf->streams[n].seq = 0;
+
+
+ switch(enc->codec_type) {
+ case CODEC_TYPE_AUDIO:
+ wav_extra_size = 0;
+ extra_size = 18 + wav_extra_size;
+ extra_size2 = 8;
+ break;
+ default:
+ case CODEC_TYPE_VIDEO:
+ wav_extra_size = enc->extradata_size;
+ extra_size = 0x33 + wav_extra_size;
+ extra_size2 = 0;
+ break;
+ }
+
+ hpos = put_header(pb, &stream_header);
+ if (enc->codec_type == CODEC_TYPE_AUDIO) {
+ put_guid(pb, &audio_stream);
+ put_guid(pb, &audio_conceal_spread);
+ } else {
+ put_guid(pb, &video_stream);
+ put_guid(pb, &video_conceal_none);
+ }
+ put_le64(pb, 0); /* ??? */
+ es_pos = url_ftell(pb);
+ put_le32(pb, extra_size); /* wav header len */
+ put_le32(pb, extra_size2); /* additional data len */
+ put_le16(pb, n + 1); /* stream number */
+ put_le32(pb, 0); /* ??? */
+
+ if (enc->codec_type == CODEC_TYPE_AUDIO) {
+ /* WAVEFORMATEX header */
+ int wavsize = put_wav_header(pb, enc);
+ if ((enc->codec_id != CODEC_ID_MP3) && (enc->codec_id != CODEC_ID_MP2) && (enc->codec_id != CODEC_ID_ADPCM_IMA_WAV) && (enc->extradata_size==0)) {
+ wavsize += 2;
+ put_le16(pb, 0);
+ }
+
+ if (wavsize < 0)
+ return -1;
+ if (wavsize != extra_size) {
+ cur_pos = url_ftell(pb);
+ url_fseek(pb, es_pos, SEEK_SET);
+ put_le32(pb, wavsize); /* wav header len */
+ url_fseek(pb, cur_pos, SEEK_SET);
+ }
+ /* ERROR Correction */
+ put_byte(pb, 0x01);
+ if(enc->codec_id == CODEC_ID_ADPCM_G726 || !enc->block_align){
+ put_le16(pb, 0x0190);
+ put_le16(pb, 0x0190);
+ }else{
+ put_le16(pb, enc->block_align);
+ put_le16(pb, enc->block_align);
+ }
+ put_le16(pb, 0x01);
+ put_byte(pb, 0x00);
+ } else {
+ put_le32(pb, enc->width);
+ put_le32(pb, enc->height);
+ put_byte(pb, 2); /* ??? */
+ put_le16(pb, 40 + enc->extradata_size); /* size */
+
+ /* BITMAPINFOHEADER header */
+ put_bmp_header(pb, enc, codec_bmp_tags, 1);
+ }
+ end_header(pb, hpos);
+ }
+
+ /* media comments */
+
+ hpos = put_header(pb, &codec_comment_header);
+ put_guid(pb, &codec_comment1_header);
+ put_le32(pb, s->nb_streams);
+ for(n=0;n<s->nb_streams;n++) {
+ AVCodec *p;
+
+ enc = s->streams[n]->codec;
+ p = avcodec_find_encoder(enc->codec_id);
+
+ if(enc->codec_type == CODEC_TYPE_AUDIO)
+ put_le16(pb, 2);
+ else if(enc->codec_type == CODEC_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");
+ else
+ put_str16(pb, p ? p->name : enc->codec_name);
+ put_le16(pb, 0); /* no parameters */
+
+
+ /* id */
+ if (enc->codec_type == CODEC_TYPE_AUDIO) {
+ put_le16(pb, 2);
+ put_le16(pb, enc->codec_tag);
+ } else {
+ put_le16(pb, 4);
+ put_le32(pb, enc->codec_tag);
+ }
+ if(!enc->codec_tag)
+ return -1;
+ }
+ end_header(pb, hpos);
+
+ /* patch the header size fields */
+
+ cur_pos = url_ftell(pb);
+ header_size = cur_pos - header_offset;
+ if (asf->is_streamed) {
+ header_size += 8 + 30 + 50;
+
+ url_fseek(pb, header_offset - 10 - 30, SEEK_SET);
+ put_le16(pb, header_size);
+ url_fseek(pb, header_offset - 2 - 30, SEEK_SET);
+ put_le16(pb, header_size);
+
+ header_size -= 8 + 30 + 50;
+ }
+ header_size += 24 + 6;
+ url_fseek(pb, header_offset - 14, SEEK_SET);
+ put_le64(pb, header_size);
+ url_fseek(pb, cur_pos, SEEK_SET);
+
+ /* movie chunk, followed by packets of packet_size */
+ asf->data_offset = cur_pos;
+ put_guid(pb, &data_header);
+ put_le64(pb, data_chunk_size);
+ put_guid(pb, &my_guid);
+ put_le64(pb, asf->nb_packets); /* nb packets */
+ put_byte(pb, 1); /* ??? */
+ put_byte(pb, 1); /* ??? */
+ return 0;
+}
+
+static int asf_write_header(AVFormatContext *s)
+{
+ ASFContext *asf = s->priv_data;
+
+ asf->packet_size = PACKET_SIZE;
+ asf->nb_packets = 0;
+
+ asf->last_indexed_pts = 0;
+ asf->index_ptr = (ASFIndex*)av_malloc( sizeof(ASFIndex) * ASF_INDEX_BLOCK );
+ asf->nb_index_memory_alloc = ASF_INDEX_BLOCK;
+ asf->nb_index_count = 0;
+ asf->maximum_packet = 0;
+
+ if (asf_write_header1(s, 0, 0) < 0) {
+ //av_free(asf);
+ return -1;
+ }
+
+ put_flush_packet(&s->pb);
+
+ asf->packet_nb_payloads = 0;
+ asf->packet_timestamp_start = -1;
+ asf->packet_timestamp_end = -1;
+ init_put_byte(&asf->pb, asf->packet_buf, asf->packet_size, 1,
+ NULL, NULL, NULL, NULL);
+
+ return 0;
+}
+
+static int asf_write_stream_header(AVFormatContext *s)
+{
+ ASFContext *asf = s->priv_data;
+
+ asf->is_streamed = 1;
+
+ return asf_write_header(s);
+}
+
+static int put_payload_parsing_info(
+ AVFormatContext *s,
+ unsigned int sendtime,
+ unsigned int duration,
+ int nb_payloads,
+ int padsize
+ )
+{
+ ASFContext *asf = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ int ppi_size, i;
+ int64_t start= url_ftell(pb);
+
+ int iLengthTypeFlags = ASF_PPI_LENGTH_TYPE_FLAGS;
+
+ padsize -= PACKET_HEADER_MIN_SIZE;
+ if(asf->multi_payloads_present)
+ padsize--;
+ assert(padsize>=0);
+
+ put_byte(pb, ASF_PACKET_ERROR_CORRECTION_FLAGS);
+ for (i = 0; i < ASF_PACKET_ERROR_CORRECTION_DATA_SIZE; i++){
+ put_byte(pb, 0x0);
+ }
+
+ if (asf->multi_payloads_present)
+ iLengthTypeFlags |= ASF_PPI_FLAG_MULTIPLE_PAYLOADS_PRESENT;
+
+ if (padsize > 0) {
+ if (padsize < 256)
+ iLengthTypeFlags |= ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE;
+ else
+ iLengthTypeFlags |= ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD;
+ }
+ put_byte(pb, iLengthTypeFlags);
+
+ put_byte(pb, ASF_PPI_PROPERTY_FLAGS);
+
+ if (iLengthTypeFlags & ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD)
+ put_le16(pb, padsize - 2);
+ if (iLengthTypeFlags & ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE)
+ put_byte(pb, padsize - 1);
+
+ put_le32(pb, sendtime);
+ put_le16(pb, duration);
+ if (asf->multi_payloads_present)
+ put_byte(pb, nb_payloads | ASF_PAYLOAD_FLAGS);
+
+ ppi_size = url_ftell(pb) - start;
+
+ return ppi_size;
+}
+
+static void flush_packet(AVFormatContext *s)
+{
+ ASFContext *asf = s->priv_data;
+ int packet_hdr_size, packet_filled_size;
+
+ if (asf->is_streamed) {
+ put_chunk(s, 0x4424, asf->packet_size, 0);
+ }
+
+ packet_hdr_size = put_payload_parsing_info(
+ s,
+ asf->packet_timestamp_start,
+ asf->packet_timestamp_end - asf->packet_timestamp_start,
+ asf->packet_nb_payloads,
+ asf->packet_size_left
+ );
+
+ packet_filled_size = PACKET_SIZE - asf->packet_size_left;
+ assert(packet_hdr_size <= asf->packet_size_left);
+ memset(asf->packet_buf + packet_filled_size, 0, asf->packet_size_left);
+
+ put_buffer(&s->pb, asf->packet_buf, asf->packet_size - packet_hdr_size);
+
+ put_flush_packet(&s->pb);
+ asf->nb_packets++;
+ asf->packet_nb_payloads = 0;
+ asf->packet_timestamp_start = -1;
+ asf->packet_timestamp_end = -1;
+ init_put_byte(&asf->pb, asf->packet_buf, asf->packet_size, 1,
+ NULL, NULL, NULL, NULL);
+}
+
+static void put_payload_header(
+ AVFormatContext *s,
+ ASFStream *stream,
+ int presentation_time,
+ int m_obj_size,
+ int m_obj_offset,
+ int payload_len,
+ int flags
+ )
+{
+ ASFContext *asf = s->priv_data;
+ ByteIOContext *pb = &asf->pb;
+ int val;
+
+ val = stream->num;
+ if (flags & PKT_FLAG_KEY)
+ val |= ASF_PL_FLAG_KEY_FRAME;
+ put_byte(pb, val);
+
+ put_byte(pb, stream->seq); //Media object number
+ put_le32(pb, m_obj_offset); //Offset Into Media Object
+
+ // Replicated Data shall be at least 8 bytes long.
+ // The first 4 bytes of data shall contain the
+ // Size of the Media Object that the payload belongs to.
+ // The next 4 bytes of data shall contain the
+ // Presentation Time for the media object that the payload belongs to.
+ put_byte(pb, ASF_PAYLOAD_REPLICATED_DATA_LENGTH);
+
+ put_le32(pb, m_obj_size); //Replicated Data - Media Object Size
+ put_le32(pb, presentation_time);//Replicated Data - Presentation Time
+
+ if (asf->multi_payloads_present){
+ put_le16(pb, payload_len); //payload length
+ }
+}
+
+static void put_frame(
+ AVFormatContext *s,
+ ASFStream *stream,
+ AVStream *avst,
+ int timestamp,
+ const uint8_t *buf,
+ int m_obj_size,
+ int flags
+ )
+{
+ ASFContext *asf = s->priv_data;
+ int m_obj_offset, payload_len, frag_len1;
+
+ m_obj_offset = 0;
+ while (m_obj_offset < m_obj_size) {
+ payload_len = m_obj_size - m_obj_offset;
+ if (asf->packet_timestamp_start == -1) {
+ asf->multi_payloads_present = (payload_len < MULTI_PAYLOAD_CONSTANT);
+
+ asf->packet_size_left = PACKET_SIZE;
+ if (asf->multi_payloads_present){
+ frag_len1 = MULTI_PAYLOAD_CONSTANT - 1;
+ }
+ else {
+ frag_len1 = SINGLE_PAYLOAD_DATA_LENGTH;
+ }
+ asf->packet_timestamp_start = timestamp;
+ }
+ else {
+ // multi payloads
+ frag_len1 = asf->packet_size_left - PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS - PACKET_HEADER_MIN_SIZE - 1;
+
+ asf->packet_timestamp_start = timestamp;
+
+ if(frag_len1 < payload_len && avst->codec->codec_type == CODEC_TYPE_AUDIO){
+ flush_packet(s);
+ continue;
+ }
+ }
+ if (frag_len1 > 0) {
+ if (payload_len > frag_len1)
+ payload_len = frag_len1;
+ else if (payload_len == (frag_len1 - 1))
+ payload_len = frag_len1 - 2; //additional byte need to put padding length
+
+ put_payload_header(s, stream, timestamp+PREROLL_TIME, m_obj_size, m_obj_offset, payload_len, flags);
+ put_buffer(&asf->pb, buf, payload_len);
+
+ if (asf->multi_payloads_present)
+ asf->packet_size_left -= (payload_len + PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS);
+ else
+ asf->packet_size_left -= (payload_len + PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD);
+ asf->packet_timestamp_end = timestamp;
+
+ asf->packet_nb_payloads++;
+ } else {
+ payload_len = 0;
+ }
+ m_obj_offset += payload_len;
+ buf += payload_len;
+
+ if (!asf->multi_payloads_present)
+ flush_packet(s);
+ else if (asf->packet_size_left <= (PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS + PACKET_HEADER_MIN_SIZE + 1))
+ flush_packet(s);
+ }
+ stream->seq++;
+}
+
+static int asf_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ ASFContext *asf = s->priv_data;
+ ASFStream *stream;
+ int64_t duration;
+ AVCodecContext *codec;
+ int64_t packet_st,pts;
+ int start_sec,i;
+ int flags= pkt->flags;
+
+ codec = s->streams[pkt->stream_index]->codec;
+ stream = &asf->streams[pkt->stream_index];
+
+ if(codec->codec_type == CODEC_TYPE_AUDIO)
+ flags &= ~PKT_FLAG_KEY;
+
+ //XXX /FIXME use duration from AVPacket (quick hack by)
+ pts = (pkt->pts != AV_NOPTS_VALUE) ? pkt->pts : pkt->dts;
+ assert(pts != AV_NOPTS_VALUE);
+ duration = pts * 10000;
+ asf->duration= FFMAX(asf->duration, duration);
+
+ packet_st = asf->nb_packets;
+ 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)) {
+ start_sec = (int)(duration / INT64_C(10000000));
+ if (start_sec != (int)(asf->last_indexed_pts / INT64_C(10000000))) {
+ for(i=asf->nb_index_count;i<start_sec;i++) {
+ if (i>=asf->nb_index_memory_alloc) {
+ asf->nb_index_memory_alloc += ASF_INDEX_BLOCK;
+ asf->index_ptr = (ASFIndex*)av_realloc( asf->index_ptr, sizeof(ASFIndex) * asf->nb_index_memory_alloc );
+ }
+ // store
+ asf->index_ptr[i].packet_number = (uint32_t)packet_st;
+ asf->index_ptr[i].packet_count = (uint16_t)(asf->nb_packets-packet_st);
+ asf->maximum_packet = FFMAX(asf->maximum_packet, (uint16_t)(asf->nb_packets-packet_st));
+ }
+ asf->nb_index_count = start_sec;
+ asf->last_indexed_pts = duration;
+ }
+ }
+ return 0;
+}
+
+//
+static int asf_write_index(AVFormatContext *s, ASFIndex *index, uint16_t max, uint32_t count)
+{
+ ByteIOContext *pb = &s->pb;
+ int i;
+
+ put_guid(pb, &simple_index_header);
+ put_le64(pb, 24 + 16 + 8 + 4 + 4 + (4 + 2)*count);
+ put_guid(pb, &my_guid);
+ put_le64(pb, ASF_INDEXED_INTERVAL);
+ put_le32(pb, max);
+ put_le32(pb, count);
+ for(i=0; i<count; i++) {
+ put_le32(pb, index[i].packet_number);
+ put_le16(pb, index[i].packet_count);
+ }
+
+ return 0;
+}
+
+static int asf_write_trailer(AVFormatContext *s)
+{
+ ASFContext *asf = s->priv_data;
+ int64_t file_size,data_size;
+
+ /* flush the current packet */
+ if (asf->pb.buf_ptr > asf->pb.buffer)
+ flush_packet(s);
+
+ /* write index */
+ data_size = url_ftell(&s->pb);
+ if ((!asf->is_streamed) && (asf->nb_index_count != 0)) {
+ asf_write_index(s, asf->index_ptr, asf->maximum_packet, asf->nb_index_count);
+ }
+ put_flush_packet(&s->pb);
+
+ if (asf->is_streamed || url_is_streamed(&s->pb)) {
+ put_chunk(s, 0x4524, 0, 0); /* end of stream */
+ } else {
+ /* rewrite an updated header */
+ file_size = url_ftell(&s->pb);
+ url_fseek(&s->pb, 0, SEEK_SET);
+ asf_write_header1(s, file_size, data_size - asf->data_offset);
+ }
+
+ put_flush_packet(&s->pb);
+ av_free(asf->index_ptr);
+ return 0;
+}
+
+#ifdef CONFIG_ASF_MUXER
+AVOutputFormat asf_muxer = {
+ "asf",
+ "asf format",
+ "video/x-ms-asf",
+ "asf,wmv,wma",
+ sizeof(ASFContext),
+#ifdef CONFIG_LIBMP3LAME
+ CODEC_ID_MP3,
+#else
+ CODEC_ID_MP2,
+#endif
+ CODEC_ID_MSMPEG4V3,
+ asf_write_header,
+ asf_write_packet,
+ asf_write_trailer,
+ .flags = AVFMT_GLOBALHEADER,
+ .codec_tag= (const AVCodecTag*[]){codec_asf_bmp_tags, codec_bmp_tags, codec_wav_tags, 0},
+};
+#endif
+
+#ifdef CONFIG_ASF_STREAM_MUXER
+AVOutputFormat asf_stream_muxer = {
+ "asf_stream",
+ "asf format",
+ "video/x-ms-asf",
+ "asf,wmv,wma",
+ sizeof(ASFContext),
+#ifdef CONFIG_LIBMP3LAME
+ CODEC_ID_MP3,
+#else
+ CODEC_ID_MP2,
+#endif
+ CODEC_ID_MSMPEG4V3,
+ asf_write_stream_header,
+ asf_write_packet,
+ asf_write_trailer,
+ .flags = AVFMT_GLOBALHEADER,
+ .codec_tag= (const AVCodecTag*[]){codec_asf_bmp_tags, codec_bmp_tags, codec_wav_tags, 0},
+};
+#endif //CONFIG_ASF_STREAM_MUXER
diff --git a/contrib/ffmpeg/libavformat/asf.c b/contrib/ffmpeg/libavformat/asf.c
new file mode 100644
index 000000000..498f6e79e
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/asf.c
@@ -0,0 +1,1037 @@
+/*
+ * ASF compatible demuxer
+ * Copyright (c) 2000, 2001 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 "avformat.h"
+#include "riff.h"
+#include "mpegaudio.h"
+#include "asf.h"
+#include "common.h"
+
+#undef NDEBUG
+#include <assert.h>
+
+#define FRAME_HEADER_SIZE 17
+// Fix Me! FRAME_HEADER_SIZE may be different.
+
+static const GUID index_guid = {
+ 0x90, 0x08, 0x00, 0x33, 0xb1, 0xe5, 0xcf, 0x11, 0x89, 0xf4, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xcb
+};
+
+static const GUID stream_bitrate_guid = { /* (http://get.to/sdp) */
+ 0xce, 0x75, 0xf8, 0x7b, 0x8d, 0x46, 0xd1, 0x11, 0x8d, 0x82, 0x00, 0x60, 0x97, 0xc9, 0xa2, 0xb2
+};
+/**********************************/
+/* decoding */
+
+//#define DEBUG
+
+#ifdef DEBUG
+#define PRINT_IF_GUID(g,cmp) \
+if (!memcmp(g, &cmp, sizeof(GUID))) \
+ printf("(GUID: %s) ", #cmp)
+
+static void print_guid(const GUID *g)
+{
+ int i;
+ PRINT_IF_GUID(g, asf_header);
+ else PRINT_IF_GUID(g, file_header);
+ else PRINT_IF_GUID(g, stream_header);
+ else PRINT_IF_GUID(g, audio_stream);
+ else PRINT_IF_GUID(g, audio_conceal_none);
+ else PRINT_IF_GUID(g, video_stream);
+ else PRINT_IF_GUID(g, video_conceal_none);
+ else PRINT_IF_GUID(g, command_stream);
+ else PRINT_IF_GUID(g, comment_header);
+ else PRINT_IF_GUID(g, codec_comment_header);
+ else PRINT_IF_GUID(g, codec_comment1_header);
+ else PRINT_IF_GUID(g, data_header);
+ else PRINT_IF_GUID(g, index_guid);
+ else PRINT_IF_GUID(g, head1_guid);
+ else PRINT_IF_GUID(g, head2_guid);
+ else PRINT_IF_GUID(g, my_guid);
+ else PRINT_IF_GUID(g, ext_stream_header);
+ else PRINT_IF_GUID(g, extended_content_header);
+ else PRINT_IF_GUID(g, ext_stream_embed_stream_header);
+ else PRINT_IF_GUID(g, ext_stream_audio_stream);
+ else PRINT_IF_GUID(g, metadata_header);
+ else PRINT_IF_GUID(g, stream_bitrate_guid);
+ else
+ printf("(GUID: unknown) ");
+ for(i=0;i<16;i++)
+ printf(" 0x%02x,", (*g)[i]);
+ printf("}\n");
+}
+#undef PRINT_IF_GUID
+#endif
+
+static void get_guid(ByteIOContext *s, GUID *g)
+{
+ assert(sizeof(*g) == 16);
+ get_buffer(s, g, sizeof(*g));
+}
+
+#if 0
+static void get_str16(ByteIOContext *pb, char *buf, int buf_size)
+{
+ int len, c;
+ char *q;
+
+ len = get_le16(pb);
+ q = buf;
+ while (len > 0) {
+ c = get_le16(pb);
+ if ((q - buf) < buf_size - 1)
+ *q++ = c;
+ len--;
+ }
+ *q = '\0';
+}
+#endif
+
+static void get_str16_nolen(ByteIOContext *pb, int len, char *buf, int buf_size)
+{
+ char* q = buf;
+ len /= 2;
+ while (len--) {
+ uint8_t tmp;
+ PUT_UTF8(get_le16(pb), tmp, if (q - buf < buf_size - 1) *q++ = tmp;)
+ }
+ *q = '\0';
+}
+
+static int asf_probe(AVProbeData *pd)
+{
+ /* check file header */
+ if (pd->buf_size <= 32)
+ return 0;
+
+ if (!memcmp(pd->buf, &asf_header, sizeof(GUID)))
+ return AVPROBE_SCORE_MAX;
+ else
+ return 0;
+}
+
+static int get_value(ByteIOContext *pb, int type){
+ switch(type){
+ case 2: return get_le32(pb);
+ case 3: return get_le32(pb);
+ case 4: return get_le64(pb);
+ case 5: return get_le16(pb);
+ default:return INT_MIN;
+ }
+}
+
+static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+ ASFContext *asf = s->priv_data;
+ GUID g;
+ ByteIOContext *pb = &s->pb;
+ AVStream *st;
+ ASFStream *asf_st;
+ int size, i;
+ int64_t gsize;
+ AVRational dar[128];
+
+ memset(dar, 0, sizeof(dar));
+
+ get_guid(pb, &g);
+ if (memcmp(&g, &asf_header, sizeof(GUID)))
+ goto fail;
+ get_le64(pb);
+ get_le32(pb);
+ get_byte(pb);
+ get_byte(pb);
+ memset(&asf->asfid2avid, -1, sizeof(asf->asfid2avid));
+ for(;;) {
+ get_guid(pb, &g);
+ gsize = get_le64(pb);
+#ifdef DEBUG
+ printf("%08"PRIx64": ", url_ftell(pb) - 24);
+ print_guid(&g);
+ printf(" size=0x%"PRIx64"\n", gsize);
+#endif
+ if (!memcmp(&g, &data_header, sizeof(GUID))) {
+ asf->data_object_offset = url_ftell(pb);
+ // if not streaming, gsize is not unlimited (how?), and there is enough space in the file..
+ if (!(asf->hdr.flags & 0x01) && gsize >= 100) {
+ asf->data_object_size = gsize - 24;
+ } else {
+ asf->data_object_size = (uint64_t)-1;
+ }
+ break;
+ }
+ if (gsize < 24)
+ goto fail;
+ if (!memcmp(&g, &file_header, sizeof(GUID))) {
+ get_guid(pb, &asf->hdr.guid);
+ asf->hdr.file_size = get_le64(pb);
+ asf->hdr.create_time = get_le64(pb);
+ asf->nb_packets = get_le64(pb);
+ asf->hdr.send_time = get_le64(pb);
+ asf->hdr.play_time = get_le64(pb);
+ asf->hdr.preroll = get_le32(pb);
+ asf->hdr.ignore = get_le32(pb);
+ asf->hdr.flags = get_le32(pb);
+ asf->hdr.min_pktsize = get_le32(pb);
+ asf->hdr.max_pktsize = get_le32(pb);
+ asf->hdr.max_bitrate = get_le32(pb);
+ asf->packet_size = asf->hdr.max_pktsize;
+ } else if (!memcmp(&g, &stream_header, sizeof(GUID))) {
+ int type, type_specific_size, sizeX;
+ uint64_t total_size;
+ unsigned int tag1;
+ int64_t pos1, pos2;
+ int test_for_ext_stream_audio;
+
+ pos1 = url_ftell(pb);
+
+ st = av_new_stream(s, 0);
+ if (!st)
+ goto fail;
+ av_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */
+ asf_st = av_mallocz(sizeof(ASFStream));
+ if (!asf_st)
+ goto fail;
+ st->priv_data = asf_st;
+ st->start_time = asf->hdr.preroll;
+ if(!(asf->hdr.flags & 0x01)) { // if we aren't streaming...
+ st->duration = asf->hdr.send_time /
+ (10000000 / 1000) - st->start_time;
+ }
+ get_guid(pb, &g);
+
+ test_for_ext_stream_audio = 0;
+ if (!memcmp(&g, &audio_stream, sizeof(GUID))) {
+ type = CODEC_TYPE_AUDIO;
+ } else if (!memcmp(&g, &video_stream, sizeof(GUID))) {
+ type = CODEC_TYPE_VIDEO;
+ } else if (!memcmp(&g, &command_stream, sizeof(GUID))) {
+ type = CODEC_TYPE_UNKNOWN;
+ } else if (!memcmp(&g, &ext_stream_embed_stream_header, sizeof(GUID))) {
+ test_for_ext_stream_audio = 1;
+ type = CODEC_TYPE_UNKNOWN;
+ } else {
+ goto fail;
+ }
+ get_guid(pb, &g);
+ total_size = get_le64(pb);
+ type_specific_size = get_le32(pb);
+ get_le32(pb);
+ st->id = get_le16(pb) & 0x7f; /* stream id */
+ // mapping of asf ID to AV stream ID;
+ asf->asfid2avid[st->id] = s->nb_streams - 1;
+
+ get_le32(pb);
+
+ if (test_for_ext_stream_audio) {
+ get_guid(pb, &g);
+ if (!memcmp(&g, &ext_stream_audio_stream, sizeof(GUID))) {
+ type = CODEC_TYPE_AUDIO;
+ get_guid(pb, &g);
+ get_le32(pb);
+ get_le32(pb);
+ get_le32(pb);
+ get_guid(pb, &g);
+ get_le32(pb);
+ }
+ }
+
+ st->codec->codec_type = type;
+ if (type == CODEC_TYPE_AUDIO) {
+ get_wav_header(pb, st->codec, type_specific_size);
+ st->need_parsing = 1;
+ /* We have to init the frame size at some point .... */
+ pos2 = url_ftell(pb);
+ if (gsize >= (pos2 + 8 - pos1 + 24)) {
+ asf_st->ds_span = get_byte(pb);
+ asf_st->ds_packet_size = get_le16(pb);
+ asf_st->ds_chunk_size = get_le16(pb);
+ get_le16(pb); //ds_data_size
+ get_byte(pb); //ds_silence_data
+ }
+ //printf("Descrambling: ps:%d cs:%d ds:%d s:%d sd:%d\n",
+ // asf_st->ds_packet_size, asf_st->ds_chunk_size,
+ // asf_st->ds_data_size, asf_st->ds_span, asf_st->ds_silence_data);
+ if (asf_st->ds_span > 1) {
+ if (!asf_st->ds_chunk_size
+ || (asf_st->ds_packet_size/asf_st->ds_chunk_size <= 1)
+ || asf_st->ds_packet_size % asf_st->ds_chunk_size)
+ asf_st->ds_span = 0; // disable descrambling
+ }
+ switch (st->codec->codec_id) {
+ case CODEC_ID_MP3:
+ st->codec->frame_size = MPA_FRAME_SIZE;
+ break;
+ case CODEC_ID_PCM_S16LE:
+ case CODEC_ID_PCM_S16BE:
+ case CODEC_ID_PCM_U16LE:
+ case CODEC_ID_PCM_U16BE:
+ case CODEC_ID_PCM_S8:
+ case CODEC_ID_PCM_U8:
+ case CODEC_ID_PCM_ALAW:
+ case CODEC_ID_PCM_MULAW:
+ st->codec->frame_size = 1;
+ break;
+ default:
+ /* This is probably wrong, but it prevents a crash later */
+ st->codec->frame_size = 1;
+ break;
+ }
+ } else if (type == CODEC_TYPE_VIDEO) {
+ get_le32(pb);
+ get_le32(pb);
+ get_byte(pb);
+ size = get_le16(pb); /* size */
+ sizeX= get_le32(pb); /* size */
+ st->codec->width = get_le32(pb);
+ st->codec->height = get_le32(pb);
+ /* not available for asf */
+ get_le16(pb); /* panes */
+ st->codec->bits_per_sample = get_le16(pb); /* depth */
+ tag1 = get_le32(pb);
+ url_fskip(pb, 20);
+// av_log(NULL, AV_LOG_DEBUG, "size:%d tsize:%d sizeX:%d\n", size, total_size, sizeX);
+ size= sizeX;
+ if (size > 40) {
+ st->codec->extradata_size = size - 40;
+ st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ get_buffer(pb, st->codec->extradata, st->codec->extradata_size);
+ }
+
+ /* Extract palette from extradata if bpp <= 8 */
+ /* This code assumes that extradata contains only palette */
+ /* This is true for all paletted codecs implemented in ffmpeg */
+ if (st->codec->extradata_size && (st->codec->bits_per_sample <= 8)) {
+ st->codec->palctrl = av_mallocz(sizeof(AVPaletteControl));
+#ifdef WORDS_BIGENDIAN
+ for (i = 0; i < FFMIN(st->codec->extradata_size, AVPALETTE_SIZE)/4; i++)
+ st->codec->palctrl->palette[i] = bswap_32(((uint32_t*)st->codec->extradata)[i]);
+#else
+ memcpy(st->codec->palctrl->palette, st->codec->extradata,
+ FFMIN(st->codec->extradata_size, AVPALETTE_SIZE));
+#endif
+ st->codec->palctrl->palette_changed = 1;
+ }
+
+ st->codec->codec_tag = tag1;
+ st->codec->codec_id = codec_get_id(codec_bmp_tags, tag1);
+ if(tag1 == MKTAG('D', 'V', 'R', ' '))
+ st->need_parsing = 1;
+ }
+ pos2 = url_ftell(pb);
+ url_fskip(pb, gsize - (pos2 - pos1 + 24));
+ } else if (!memcmp(&g, &comment_header, sizeof(GUID))) {
+ int len1, len2, len3, len4, len5;
+
+ len1 = get_le16(pb);
+ len2 = get_le16(pb);
+ len3 = get_le16(pb);
+ len4 = get_le16(pb);
+ len5 = get_le16(pb);
+ get_str16_nolen(pb, len1, s->title , sizeof(s->title));
+ get_str16_nolen(pb, len2, s->author , sizeof(s->author));
+ get_str16_nolen(pb, len3, s->copyright, sizeof(s->copyright));
+ get_str16_nolen(pb, len4, s->comment , sizeof(s->comment));
+ url_fskip(pb, len5);
+ } else if (!memcmp(&g, &stream_bitrate_guid, sizeof(GUID))) {
+ int stream_count = get_le16(pb);
+ int j;
+
+// av_log(NULL, AV_LOG_ERROR, "stream bitrate properties\n");
+// av_log(NULL, AV_LOG_ERROR, "streams %d\n", streams);
+ for(j = 0; j < stream_count; j++) {
+ int flags, bitrate, stream_id;
+
+ flags= get_le16(pb);
+ bitrate= get_le32(pb);
+ stream_id= (flags & 0x7f);
+// av_log(NULL, AV_LOG_ERROR, "flags: 0x%x stream id %d, bitrate %d\n", flags, stream_id, bitrate);
+ asf->stream_bitrates[stream_id-1]= bitrate;
+ }
+ } else if (!memcmp(&g, &extended_content_header, sizeof(GUID))) {
+ int desc_count, i;
+
+ desc_count = get_le16(pb);
+ for(i=0;i<desc_count;i++)
+ {
+ int name_len,value_type,value_len;
+ uint64_t value_num = 0;
+ char name[1024];
+
+ name_len = get_le16(pb);
+ get_str16_nolen(pb, name_len, name, sizeof(name));
+ value_type = get_le16(pb);
+ value_len = get_le16(pb);
+ if ((value_type == 0) || (value_type == 1)) // unicode or byte
+ {
+ if (!strcmp(name,"WM/AlbumTitle")) get_str16_nolen(pb, value_len, s->album, sizeof(s->album));
+ else if(!strcmp(name,"WM/Genre" )) get_str16_nolen(pb, value_len, s->genre, sizeof(s->genre));
+ else url_fskip(pb, value_len);
+ }
+ if ((value_type >= 2) && (value_type <= 5)) // boolean or DWORD or QWORD or WORD
+ {
+ value_num= get_value(pb, value_type);
+ if (!strcmp(name,"WM/Track" )) s->track = value_num + 1;
+ if (!strcmp(name,"WM/TrackNumber")) s->track = value_num;
+ }
+ }
+ } else if (!memcmp(&g, &metadata_header, sizeof(GUID))) {
+ int n, stream_num, name_len, value_len, value_type, value_num;
+ n = get_le16(pb);
+
+ for(i=0;i<n;i++) {
+ char name[1024];
+
+ get_le16(pb); //lang_list_index
+ stream_num= get_le16(pb);
+ name_len= get_le16(pb);
+ value_type= get_le16(pb);
+ value_len= get_le32(pb);
+
+ get_str16_nolen(pb, name_len, name, sizeof(name));
+//av_log(NULL, AV_LOG_ERROR, "%d %d %d %d %d <%s>\n", i, stream_num, name_len, value_type, value_len, name);
+ value_num= get_le16(pb);//we should use get_value() here but it doesnt work 2 is le16 here but le32 elsewhere
+ url_fskip(pb, value_len - 2);
+
+ if(stream_num<128){
+ if (!strcmp(name, "AspectRatioX")) dar[stream_num].num= value_num;
+ else if(!strcmp(name, "AspectRatioY")) dar[stream_num].den= value_num;
+ }
+ }
+ } else if (!memcmp(&g, &ext_stream_header, sizeof(GUID))) {
+ int ext_len, payload_ext_ct, stream_ct;
+ uint32_t ext_d;
+ int64_t pos_ex_st;
+ pos_ex_st = url_ftell(pb);
+
+ get_le64(pb); // starttime
+ get_le64(pb); // endtime
+ get_le32(pb); // leak-datarate
+ get_le32(pb); // bucket-datasize
+ get_le32(pb); // init-bucket-fullness
+ get_le32(pb); // alt-leak-datarate
+ get_le32(pb); // alt-bucket-datasize
+ get_le32(pb); // alt-init-bucket-fullness
+ get_le32(pb); // max-object-size
+ get_le32(pb); // flags (reliable,seekable,no_cleanpoints?,resend-live-cleanpoints, rest of bits reserved)
+ get_le16(pb); // stream-num
+ get_le16(pb); // stream-language-id-index
+ get_le64(pb); // avg frametime in 100ns units
+ stream_ct = get_le16(pb); //stream-name-count
+ payload_ext_ct = get_le16(pb); //payload-extension-system-count
+
+ for (i=0; i<stream_ct; i++){
+ get_le16(pb);
+ ext_len = get_le16(pb);
+ url_fseek(pb, ext_len, SEEK_CUR);
+ }
+
+ for (i=0; i<payload_ext_ct; i++){
+ get_guid(pb, &g);
+ ext_d=get_le16(pb);
+ ext_len=get_le32(pb);
+ url_fseek(pb, ext_len, SEEK_CUR);
+ }
+
+ // there could be a optional stream properties object to follow
+ // if so the next iteration will pick it up
+ } else if (!memcmp(&g, &head1_guid, sizeof(GUID))) {
+ int v1, v2;
+ get_guid(pb, &g);
+ v1 = get_le32(pb);
+ v2 = get_le16(pb);
+#if 0
+ } else if (!memcmp(&g, &codec_comment_header, sizeof(GUID))) {
+ int len, v1, n, num;
+ char str[256], *q;
+ char tag[16];
+
+ get_guid(pb, &g);
+ print_guid(&g);
+
+ n = get_le32(pb);
+ for(i=0;i<n;i++) {
+ num = get_le16(pb); /* stream number */
+ get_str16(pb, str, sizeof(str));
+ get_str16(pb, str, sizeof(str));
+ len = get_le16(pb);
+ q = tag;
+ while (len > 0) {
+ v1 = get_byte(pb);
+ if ((q - tag) < sizeof(tag) - 1)
+ *q++ = v1;
+ len--;
+ }
+ *q = '\0';
+ }
+#endif
+ } else if (url_feof(pb)) {
+ goto fail;
+ } else {
+ url_fseek(pb, gsize - 24, SEEK_CUR);
+ }
+ }
+ get_guid(pb, &g);
+ get_le64(pb);
+ get_byte(pb);
+ get_byte(pb);
+ if (url_feof(pb))
+ goto fail;
+ asf->data_offset = url_ftell(pb);
+ asf->packet_size_left = 0;
+
+
+ for(i=0; i<128; i++){
+ int stream_num= asf->asfid2avid[i];
+ if(stream_num>=0 && dar[i].num>0 && dar[i].den>0){
+ AVCodecContext *codec= s->streams[stream_num]->codec;
+ av_reduce(&codec->sample_aspect_ratio.num,
+ &codec->sample_aspect_ratio.den,
+ dar[i].num, dar[i].den, INT_MAX);
+//av_log(NULL, AV_LOG_ERROR, "dar %d:%d sar=%d:%d\n", dar[i].num, dar[i].den, codec->sample_aspect_ratio.num, codec->sample_aspect_ratio.den);
+ }
+ }
+
+ return 0;
+
+ fail:
+ for(i=0;i<s->nb_streams;i++) {
+ AVStream *st = s->streams[i];
+ if (st) {
+ av_free(st->priv_data);
+ av_free(st->codec->extradata);
+ }
+ av_free(st);
+ }
+ return -1;
+}
+
+#define DO_2BITS(bits, var, defval) \
+ switch (bits & 3) \
+ { \
+ case 3: var = get_le32(pb); rsize += 4; break; \
+ case 2: var = get_le16(pb); rsize += 2; break; \
+ case 1: var = get_byte(pb); rsize++; break; \
+ default: var = defval; break; \
+ }
+
+/**
+ *
+ * @return <0 in case of an error
+ */
+static int asf_get_packet(AVFormatContext *s)
+{
+ ASFContext *asf = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ uint32_t packet_length, padsize;
+ int rsize = 8;
+ int c, d, e, off;
+
+ off= (url_ftell(&s->pb) - s->data_offset) % asf->packet_size + 3;
+
+ c=d=e=-1;
+ while(off-- > 0){
+ c=d; d=e;
+ e= get_byte(pb);
+ if(c == 0x82 && !d && !e)
+ break;
+ }
+
+ if (c != 0x82) {
+ if (!url_feof(pb))
+ av_log(s, AV_LOG_ERROR, "ff asf bad header %x at:%"PRId64"\n", c, url_ftell(pb));
+ }
+ if ((c & 0x8f) == 0x82) {
+ if (d || e) {
+ if (!url_feof(pb))
+ av_log(s, AV_LOG_ERROR, "ff asf bad non zero\n");
+ return -1;
+ }
+ c= get_byte(pb);
+ d= get_byte(pb);
+ rsize+=3;
+ }else{
+ url_fseek(pb, -1, SEEK_CUR); //FIXME
+ }
+
+ asf->packet_flags = c;
+ asf->packet_property = d;
+
+ DO_2BITS(asf->packet_flags >> 5, packet_length, asf->packet_size);
+ DO_2BITS(asf->packet_flags >> 1, padsize, 0); // sequence ignored
+ DO_2BITS(asf->packet_flags >> 3, padsize, 0); // padding length
+
+ //the following checks prevent overflows and infinite loops
+ if(packet_length >= (1U<<29)){
+ av_log(s, AV_LOG_ERROR, "invalid packet_length %d at:%"PRId64"\n", packet_length, url_ftell(pb));
+ return -1;
+ }
+ if(padsize >= packet_length){
+ av_log(s, AV_LOG_ERROR, "invalid padsize %d at:%"PRId64"\n", padsize, url_ftell(pb));
+ return -1;
+ }
+
+ asf->packet_timestamp = get_le32(pb);
+ get_le16(pb); /* duration */
+ // rsize has at least 11 bytes which have to be present
+
+ if (asf->packet_flags & 0x01) {
+ asf->packet_segsizetype = get_byte(pb); rsize++;
+ asf->packet_segments = asf->packet_segsizetype & 0x3f;
+ } else {
+ asf->packet_segments = 1;
+ asf->packet_segsizetype = 0x80;
+ }
+ asf->packet_size_left = packet_length - padsize - rsize;
+ if (packet_length < asf->hdr.min_pktsize)
+ padsize += asf->hdr.min_pktsize - packet_length;
+ asf->packet_padsize = padsize;
+#ifdef DEBUG
+ printf("packet: size=%d padsize=%d left=%d\n", asf->packet_size, asf->packet_padsize, asf->packet_size_left);
+#endif
+ return 0;
+}
+
+/**
+ *
+ * @return <0 if error
+ */
+static int asf_read_frame_header(AVFormatContext *s){
+ ASFContext *asf = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ int rsize = 1;
+ int num = get_byte(pb);
+ int64_t ts0, ts1;
+
+ asf->packet_segments--;
+ asf->packet_key_frame = num >> 7;
+ asf->stream_index = asf->asfid2avid[num & 0x7f];
+ // sequence should be ignored!
+ DO_2BITS(asf->packet_property >> 4, asf->packet_seq, 0);
+ DO_2BITS(asf->packet_property >> 2, asf->packet_frag_offset, 0);
+ DO_2BITS(asf->packet_property, asf->packet_replic_size, 0);
+//printf("key:%d stream:%d seq:%d offset:%d replic_size:%d\n", asf->packet_key_frame, asf->stream_index, asf->packet_seq, //asf->packet_frag_offset, asf->packet_replic_size);
+ if (asf->packet_replic_size >= 8) {
+ asf->packet_obj_size = get_le32(pb);
+ if(asf->packet_obj_size >= (1<<24) || asf->packet_obj_size <= 0){
+ av_log(s, AV_LOG_ERROR, "packet_obj_size invalid\n");
+ return -1;
+ }
+ asf->packet_frag_timestamp = get_le32(pb); // timestamp
+ if(asf->packet_replic_size >= 8+38+4){
+// for(i=0; i<asf->packet_replic_size-8; i++)
+// av_log(s, AV_LOG_DEBUG, "%02X ",get_byte(pb));
+// av_log(s, AV_LOG_DEBUG, "\n");
+ url_fskip(pb, 10);
+ ts0= get_le64(pb);
+ ts1= get_le64(pb);
+ url_fskip(pb, 12);
+ get_le32(pb);
+ url_fskip(pb, asf->packet_replic_size - 8 - 38 - 4);
+ if(ts0!= -1) asf->packet_frag_timestamp= ts0/10000;
+ else asf->packet_frag_timestamp= AV_NOPTS_VALUE;
+ }else
+ url_fskip(pb, asf->packet_replic_size - 8);
+ rsize += asf->packet_replic_size; // FIXME - check validity
+ } else if (asf->packet_replic_size==1){
+ // multipacket - frag_offset is begining timestamp
+ asf->packet_time_start = asf->packet_frag_offset;
+ asf->packet_frag_offset = 0;
+ asf->packet_frag_timestamp = asf->packet_timestamp;
+
+ asf->packet_time_delta = get_byte(pb);
+ rsize++;
+ }else if(asf->packet_replic_size!=0){
+ av_log(s, AV_LOG_ERROR, "unexpected packet_replic_size of %d\n", asf->packet_replic_size);
+ return -1;
+ }
+ if (asf->packet_flags & 0x01) {
+ DO_2BITS(asf->packet_segsizetype >> 6, asf->packet_frag_size, 0); // 0 is illegal
+ if(asf->packet_frag_size > asf->packet_size_left - rsize){
+ av_log(s, AV_LOG_ERROR, "packet_frag_size is invalid\n");
+ return -1;
+ }
+ //printf("Fragsize %d\n", asf->packet_frag_size);
+ } else {
+ asf->packet_frag_size = asf->packet_size_left - rsize;
+ //printf("Using rest %d %d %d\n", asf->packet_frag_size, asf->packet_size_left, rsize);
+ }
+ if (asf->packet_replic_size == 1) {
+ asf->packet_multi_size = asf->packet_frag_size;
+ if (asf->packet_multi_size > asf->packet_size_left)
+ return -1;
+ }
+ asf->packet_size_left -= rsize;
+ //printf("___objsize____ %d %d rs:%d\n", asf->packet_obj_size, asf->packet_frag_offset, rsize);
+
+ return 0;
+}
+
+static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ ASFContext *asf = s->priv_data;
+ ASFStream *asf_st = 0;
+ ByteIOContext *pb = &s->pb;
+ //static int pc = 0;
+ for (;;) {
+ if(url_feof(pb))
+ return AVERROR_IO;
+ if (asf->packet_size_left < FRAME_HEADER_SIZE
+ || asf->packet_segments < 1) {
+ //asf->packet_size_left <= asf->packet_padsize) {
+ int ret = asf->packet_size_left + asf->packet_padsize;
+ //printf("PacketLeftSize:%d Pad:%d Pos:%"PRId64"\n", asf->packet_size_left, asf->packet_padsize, url_ftell(pb));
+ assert(ret>=0);
+ /* fail safe */
+ url_fskip(pb, ret);
+
+ asf->packet_pos= url_ftell(&s->pb);
+ if (asf->data_object_size != (uint64_t)-1 &&
+ (asf->packet_pos - asf->data_object_offset >= asf->data_object_size))
+ return AVERROR_IO; /* Do not exceed the size of the data object */
+ ret = asf_get_packet(s);
+ //printf("READ ASF PACKET %d r:%d c:%d\n", ret, asf->packet_size_left, pc++);
+ if (ret < 0)
+ assert(asf->packet_size_left < FRAME_HEADER_SIZE || asf->packet_segments < 1);
+ asf->packet_time_start = 0;
+ continue;
+ }
+ if (asf->packet_time_start == 0) {
+ if(asf_read_frame_header(s) < 0){
+ asf->packet_segments= 0;
+ continue;
+ }
+ if (asf->stream_index < 0
+ || s->streams[asf->stream_index]->discard >= AVDISCARD_ALL
+ || (!asf->packet_key_frame && s->streams[asf->stream_index]->discard >= AVDISCARD_NONKEY)
+ ) {
+ asf->packet_time_start = 0;
+ /* unhandled packet (should not happen) */
+ url_fskip(pb, asf->packet_frag_size);
+ asf->packet_size_left -= asf->packet_frag_size;
+ if(asf->stream_index < 0)
+ av_log(s, AV_LOG_ERROR, "ff asf skip %d (unknown stream)\n", asf->packet_frag_size);
+ continue;
+ }
+ asf->asf_st = s->streams[asf->stream_index]->priv_data;
+ }
+ asf_st = asf->asf_st;
+
+ if (asf->packet_replic_size == 1) {
+ // frag_offset is here used as the begining timestamp
+ asf->packet_frag_timestamp = asf->packet_time_start;
+ asf->packet_time_start += asf->packet_time_delta;
+ asf->packet_obj_size = asf->packet_frag_size = get_byte(pb);
+ asf->packet_size_left--;
+ asf->packet_multi_size--;
+ if (asf->packet_multi_size < asf->packet_obj_size)
+ {
+ asf->packet_time_start = 0;
+ url_fskip(pb, asf->packet_multi_size);
+ asf->packet_size_left -= asf->packet_multi_size;
+ continue;
+ }
+ asf->packet_multi_size -= asf->packet_obj_size;
+ //printf("COMPRESS size %d %d %d ms:%d\n", asf->packet_obj_size, asf->packet_frag_timestamp, asf->packet_size_left, asf->packet_multi_size);
+ }
+ if ( asf_st->pkt.size != asf->packet_obj_size
+ || asf_st->frag_offset + asf->packet_frag_size > asf_st->pkt.size) { //FIXME is this condition sufficient?
+ if(asf_st->pkt.data){
+ av_log(s, AV_LOG_INFO, "freeing incomplete packet size %d, new %d\n", asf_st->pkt.size, asf->packet_obj_size);
+ asf_st->frag_offset = 0;
+ av_free_packet(&asf_st->pkt);
+ }
+ /* new packet */
+ av_new_packet(&asf_st->pkt, asf->packet_obj_size);
+ asf_st->seq = asf->packet_seq;
+ asf_st->pkt.pts = asf->packet_frag_timestamp;
+ asf_st->pkt.stream_index = asf->stream_index;
+ 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->packet_key_frame = 1;
+ if (asf->packet_key_frame)
+ asf_st->pkt.flags |= PKT_FLAG_KEY;
+ }
+
+ /* read data */
+ //printf("READ PACKET s:%d os:%d o:%d,%d l:%d DATA:%p\n",
+ // asf->packet_size, asf_st->pkt.size, asf->packet_frag_offset,
+ // asf_st->frag_offset, asf->packet_frag_size, asf_st->pkt.data);
+ asf->packet_size_left -= asf->packet_frag_size;
+ if (asf->packet_size_left < 0)
+ continue;
+
+ if( asf->packet_frag_offset >= asf_st->pkt.size
+ || asf->packet_frag_size > asf_st->pkt.size - asf->packet_frag_offset){
+ av_log(s, AV_LOG_ERROR, "packet fragment position invalid %u,%u not in %u\n",
+ asf->packet_frag_offset, asf->packet_frag_size, asf_st->pkt.size);
+ continue;
+ }
+
+ get_buffer(pb, asf_st->pkt.data + asf->packet_frag_offset,
+ asf->packet_frag_size);
+ asf_st->frag_offset += asf->packet_frag_size;
+ /* test if whole packet is read */
+ if (asf_st->frag_offset == asf_st->pkt.size) {
+ /* return packet */
+ if (asf_st->ds_span > 1) {
+ if(asf_st->pkt.size != asf_st->ds_packet_size * asf_st->ds_span){
+ av_log(s, AV_LOG_ERROR, "pkt.size != ds_packet_size * ds_span\n");
+ }else{
+ /* packet descrambling */
+ uint8_t *newdata = av_malloc(asf_st->pkt.size);
+ if (newdata) {
+ int offset = 0;
+ while (offset < asf_st->pkt.size) {
+ int off = offset / asf_st->ds_chunk_size;
+ int row = off / asf_st->ds_span;
+ int col = off % asf_st->ds_span;
+ int idx = row + col * asf_st->ds_packet_size / asf_st->ds_chunk_size;
+ //printf("off:%d row:%d col:%d idx:%d\n", off, row, col, idx);
+
+ assert(offset + asf_st->ds_chunk_size <= asf_st->pkt.size);
+ assert(idx+1 <= asf_st->pkt.size / asf_st->ds_chunk_size);
+ memcpy(newdata + offset,
+ asf_st->pkt.data + idx * asf_st->ds_chunk_size,
+ asf_st->ds_chunk_size);
+ offset += asf_st->ds_chunk_size;
+ }
+ av_free(asf_st->pkt.data);
+ asf_st->pkt.data = newdata;
+ }
+ }
+ }
+ asf_st->frag_offset = 0;
+ *pkt= asf_st->pkt;
+ //printf("packet %d %d\n", asf_st->pkt.size, asf->packet_frag_size);
+ asf_st->pkt.size = 0;
+ asf_st->pkt.data = 0;
+ break; // packet completed
+ }
+ }
+ return 0;
+}
+
+static int asf_read_close(AVFormatContext *s)
+{
+ int i;
+
+ for(i=0;i<s->nb_streams;i++) {
+ AVStream *st = s->streams[i];
+ av_free(st->priv_data);
+ av_free(st->codec->palctrl);
+ }
+ return 0;
+}
+
+// Added to support seeking after packets have been read
+// If information is not reset, read_packet fails due to
+// leftover information from previous reads
+static void asf_reset_header(AVFormatContext *s)
+{
+ ASFContext *asf = s->priv_data;
+ ASFStream *asf_st;
+ int i;
+
+ asf->packet_nb_frames = 0;
+ asf->packet_size_left = 0;
+ asf->packet_segments = 0;
+ asf->packet_flags = 0;
+ asf->packet_property = 0;
+ asf->packet_timestamp = 0;
+ asf->packet_segsizetype = 0;
+ asf->packet_segments = 0;
+ asf->packet_seq = 0;
+ asf->packet_replic_size = 0;
+ asf->packet_key_frame = 0;
+ asf->packet_padsize = 0;
+ asf->packet_frag_offset = 0;
+ asf->packet_frag_size = 0;
+ asf->packet_frag_timestamp = 0;
+ asf->packet_multi_size = 0;
+ asf->packet_obj_size = 0;
+ asf->packet_time_delta = 0;
+ asf->packet_time_start = 0;
+
+ for(i=0; i<s->nb_streams; i++){
+ asf_st= s->streams[i]->priv_data;
+ av_free_packet(&asf_st->pkt);
+ asf_st->frag_offset=0;
+ asf_st->seq=0;
+ }
+ asf->asf_st= NULL;
+}
+
+static int64_t asf_read_pts(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit)
+{
+ ASFContext *asf = s->priv_data;
+ AVPacket pkt1, *pkt = &pkt1;
+ ASFStream *asf_st;
+ int64_t pts;
+ int64_t pos= *ppos;
+ int i;
+ int64_t start_pos[s->nb_streams];
+
+ for(i=0; i<s->nb_streams; i++){
+ start_pos[i]= pos;
+ }
+
+ pos= (pos+asf->packet_size-1-s->data_offset)/asf->packet_size*asf->packet_size+ s->data_offset;
+ *ppos= pos;
+ url_fseek(&s->pb, pos, SEEK_SET);
+
+//printf("asf_read_pts\n");
+ asf_reset_header(s);
+ for(;;){
+ if (av_read_frame(s, pkt) < 0){
+ av_log(s, AV_LOG_INFO, "asf_read_pts failed\n");
+ return AV_NOPTS_VALUE;
+ }
+
+ pts= pkt->pts;
+
+ av_free_packet(pkt);
+ if(pkt->flags&PKT_FLAG_KEY){
+ i= pkt->stream_index;
+
+ asf_st= s->streams[i]->priv_data;
+
+// assert((asf_st->packet_pos - s->data_offset) % asf->packet_size == 0);
+ pos= asf_st->packet_pos;
+
+ av_add_index_entry(s->streams[i], pos, pts, pkt->size, pos - start_pos[i] + 1, AVINDEX_KEYFRAME);
+ start_pos[i]= asf_st->packet_pos + 1;
+
+ if(pkt->stream_index == stream_index)
+ break;
+ }
+ }
+
+ *ppos= pos;
+//printf("found keyframe at %"PRId64" stream %d stamp:%"PRId64"\n", *ppos, stream_index, pts);
+
+ return pts;
+}
+
+static void asf_build_simple_index(AVFormatContext *s, int stream_index)
+{
+ GUID g;
+ ASFContext *asf = s->priv_data;
+ int64_t gsize, itime;
+ int64_t pos, current_pos, index_pts;
+ int i;
+ int pct,ict;
+
+ current_pos = url_ftell(&s->pb);
+
+ url_fseek(&s->pb, asf->data_object_offset + asf->data_object_size, SEEK_SET);
+ get_guid(&s->pb, &g);
+ if (!memcmp(&g, &index_guid, sizeof(GUID))) {
+ gsize = get_le64(&s->pb);
+ get_guid(&s->pb, &g);
+ itime=get_le64(&s->pb);
+ pct=get_le32(&s->pb);
+ ict=get_le32(&s->pb);
+ av_log(NULL, AV_LOG_DEBUG, "itime:0x%"PRIx64", pct:%d, ict:%d\n",itime,pct,ict);
+
+ for (i=0;i<ict;i++){
+ int pktnum=get_le32(&s->pb);
+ int pktct =get_le16(&s->pb);
+ av_log(NULL, AV_LOG_DEBUG, "pktnum:%d, pktct:%d\n", pktnum, pktct);
+
+ pos=s->data_offset + asf->packet_size*(int64_t)pktnum;
+ index_pts=av_rescale(itime, i, 10000);
+
+ av_add_index_entry(s->streams[stream_index], pos, index_pts, asf->packet_size, 0, AVINDEX_KEYFRAME);
+ }
+ asf->index_read= 1;
+ }
+ url_fseek(&s->pb, current_pos, SEEK_SET);
+}
+
+static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flags)
+{
+ ASFContext *asf = s->priv_data;
+ AVStream *st = s->streams[stream_index];
+ int64_t pos;
+ int index;
+
+ if (asf->packet_size <= 0)
+ return -1;
+
+ if (!asf->index_read)
+ asf_build_simple_index(s, stream_index);
+
+ if(!(asf->index_read && st->index_entries)){
+ if(av_seek_frame_binary(s, stream_index, pts, flags)<0)
+ return -1;
+ }else{
+ index= av_index_search_timestamp(st, pts, flags);
+ if(index<0)
+ return -1;
+
+ /* find the position */
+ pos = st->index_entries[index].pos;
+ pts = st->index_entries[index].timestamp;
+
+ // various attempts to find key frame have failed so far
+ // asf_reset_header(s);
+ // url_fseek(&s->pb, pos, SEEK_SET);
+ // key_pos = pos;
+ // for(i=0;i<16;i++){
+ // pos = url_ftell(&s->pb);
+ // if (av_read_frame(s, &pkt) < 0){
+ // av_log(s, AV_LOG_INFO, "seek failed\n");
+ // return -1;
+ // }
+ // asf_st = s->streams[stream_index]->priv_data;
+ // pos += st->parser->frame_offset;
+ //
+ // if (pkt.size > b) {
+ // b = pkt.size;
+ // key_pos = pos;
+ // }
+ //
+ // av_free_packet(&pkt);
+ // }
+
+ /* do the seek */
+ av_log(NULL, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", pos);
+ url_fseek(&s->pb, pos, SEEK_SET);
+ }
+ asf_reset_header(s);
+ return 0;
+}
+
+AVInputFormat asf_demuxer = {
+ "asf",
+ "asf format",
+ sizeof(ASFContext),
+ asf_probe,
+ asf_read_header,
+ asf_read_packet,
+ asf_read_close,
+ asf_read_seek,
+ asf_read_pts,
+};
diff --git a/contrib/ffmpeg/libavformat/asf.h b/contrib/ffmpeg/libavformat/asf.h
new file mode 100644
index 000000000..6d76ebecb
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/asf.h
@@ -0,0 +1,280 @@
+/*
+ * Copyright (c) 2000, 2001 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
+ */
+#define PACKET_SIZE 3200
+
+typedef struct {
+ int num;
+ unsigned char seq;
+ /* use for reading */
+ AVPacket pkt;
+ int frag_offset;
+ int timestamp;
+ int64_t duration;
+
+ int ds_span; /* descrambling */
+ int ds_packet_size;
+ int ds_chunk_size;
+
+ int64_t packet_pos;
+
+} ASFStream;
+
+typedef uint8_t GUID[16];
+
+typedef struct {
+ GUID guid; ///< generated by client computer
+ uint64_t file_size; /**< in bytes
+ * invalid if broadcasting */
+ uint64_t create_time; /**< time of creation, in 100-nanosecond units since 1.1.1601
+ * invalid if broadcasting */
+ uint64_t play_time; /**< play time, in 100-nanosecond units
+ * invalid if broadcasting */
+ uint64_t send_time; /**< time to send file, in 100-nanosecond units
+ * invalid if broadcasting (could be ignored) */
+ uint32_t preroll; /**< timestamp of the first packet, in milliseconds
+ * if nonzero - substract from time */
+ uint32_t ignore; ///< preroll is 64bit - but let's just ignore it
+ uint32_t flags; /**< 0x01 - broadcast
+ * 0x02 - seekable
+ * rest is reserved should be 0 */
+ uint32_t min_pktsize; /**< size of a data packet
+ * invalid if broadcasting */
+ uint32_t max_pktsize; /**< shall be the same as for min_pktsize
+ * invalid if broadcasting */
+ uint32_t max_bitrate; /**< bandwith of stream in bps
+ * should be the sum of bitrates of the
+ * individual media streams */
+} ASFMainHeader;
+
+
+typedef struct {
+ uint32_t packet_number;
+ uint16_t packet_count;
+} ASFIndex;
+
+
+typedef struct {
+ uint32_t seqno;
+ unsigned int packet_size;
+ int is_streamed;
+ int asfid2avid[128]; ///< conversion table from asf ID 2 AVStream ID
+ ASFStream streams[128]; ///< it's max number and it's not that big
+ uint32_t stream_bitrates[128]; ///< max number of streams, bitrate for each (for streaming)
+ /* non streamed additonnal info */
+ uint64_t nb_packets; ///< how many packets are there in the file, invalid if broadcasting
+ int64_t duration; ///< in 100ns units
+ /* packet filling */
+ unsigned char multi_payloads_present;
+ int packet_size_left;
+ int packet_timestamp_start;
+ int packet_timestamp_end;
+ unsigned int packet_nb_payloads;
+ int packet_nb_frames;
+ uint8_t packet_buf[PACKET_SIZE];
+ ByteIOContext pb;
+ /* only for reading */
+ uint64_t data_offset; ///< begining of the first data packet
+ uint64_t data_object_offset; ///< data object offset (excl. GUID & size)
+ uint64_t data_object_size; ///< size of the data object
+ int index_read;
+
+ ASFMainHeader hdr;
+
+ int packet_flags;
+ int packet_property;
+ int packet_timestamp;
+ int packet_segsizetype;
+ int packet_segments;
+ int packet_seq;
+ int packet_replic_size;
+ int packet_key_frame;
+ int packet_padsize;
+ unsigned int packet_frag_offset;
+ unsigned int packet_frag_size;
+ int64_t packet_frag_timestamp;
+ int packet_multi_size;
+ int packet_obj_size;
+ int packet_time_delta;
+ int packet_time_start;
+ int64_t packet_pos;
+
+ int stream_index;
+
+
+ int64_t last_indexed_pts;
+ ASFIndex* index_ptr;
+ uint32_t nb_index_count;
+ uint32_t nb_index_memory_alloc;
+ uint16_t maximum_packet;
+
+ ASFStream* asf_st; ///< currently decoded stream
+} ASFContext;
+
+static const GUID asf_header = {
+ 0x30, 0x26, 0xB2, 0x75, 0x8E, 0x66, 0xCF, 0x11, 0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C
+};
+
+static const GUID file_header = {
+ 0xA1, 0xDC, 0xAB, 0x8C, 0x47, 0xA9, 0xCF, 0x11, 0x8E, 0xE4, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65
+};
+
+static const GUID stream_header = {
+ 0x91, 0x07, 0xDC, 0xB7, 0xB7, 0xA9, 0xCF, 0x11, 0x8E, 0xE6, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65
+};
+
+static const GUID ext_stream_header = {
+ 0xCB, 0xA5, 0xE6, 0x14, 0x72, 0xC6, 0x32, 0x43, 0x83, 0x99, 0xA9, 0x69, 0x52, 0x06, 0x5B, 0x5A
+};
+
+static const GUID audio_stream = {
+ 0x40, 0x9E, 0x69, 0xF8, 0x4D, 0x5B, 0xCF, 0x11, 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B
+};
+
+static const GUID audio_conceal_none = {
+ // 0x40, 0xa4, 0xf1, 0x49, 0x4ece, 0x11d0, 0xa3, 0xac, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6
+ // New value lifted from avifile
+ 0x00, 0x57, 0xfb, 0x20, 0x55, 0x5B, 0xCF, 0x11, 0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b
+};
+
+static const GUID audio_conceal_spread = {
+ 0x50, 0xCD, 0xC3, 0xBF, 0x8F, 0x61, 0xCF, 0x11, 0x8B, 0xB2, 0x00, 0xAA, 0x00, 0xB4, 0xE2, 0x20
+};
+
+static const GUID video_stream = {
+ 0xC0, 0xEF, 0x19, 0xBC, 0x4D, 0x5B, 0xCF, 0x11, 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B
+};
+
+static const GUID video_conceal_none = {
+ 0x00, 0x57, 0xFB, 0x20, 0x55, 0x5B, 0xCF, 0x11, 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B
+};
+
+static const GUID command_stream = {
+ 0xC0, 0xCF, 0xDA, 0x59, 0xE6, 0x59, 0xD0, 0x11, 0xA3, 0xAC, 0x00, 0xA0, 0xC9, 0x03, 0x48, 0xF6
+};
+
+static const GUID comment_header = {
+ 0x33, 0x26, 0xb2, 0x75, 0x8E, 0x66, 0xCF, 0x11, 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c
+};
+
+static const GUID codec_comment_header = {
+ 0x40, 0x52, 0xD1, 0x86, 0x1D, 0x31, 0xD0, 0x11, 0xA3, 0xA4, 0x00, 0xA0, 0xC9, 0x03, 0x48, 0xF6
+};
+static const GUID codec_comment1_header = {
+ 0x41, 0x52, 0xd1, 0x86, 0x1D, 0x31, 0xD0, 0x11, 0xa3, 0xa4, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6
+};
+
+static const GUID data_header = {
+ 0x36, 0x26, 0xb2, 0x75, 0x8E, 0x66, 0xCF, 0x11, 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c
+};
+
+static const GUID head1_guid = {
+ 0xb5, 0x03, 0xbf, 0x5f, 0x2E, 0xA9, 0xCF, 0x11, 0x8e, 0xe3, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65
+};
+
+static const GUID head2_guid = {
+ 0x11, 0xd2, 0xd3, 0xab, 0xBA, 0xA9, 0xCF, 0x11, 0x8e, 0xe6, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65
+};
+
+static const GUID extended_content_header = {
+ 0x40, 0xA4, 0xD0, 0xD2, 0x07, 0xE3, 0xD2, 0x11, 0x97, 0xF0, 0x00, 0xA0, 0xC9, 0x5E, 0xA8, 0x50
+};
+
+static const GUID simple_index_header = {
+ 0x90, 0x08, 0x00, 0x33, 0xB1, 0xE5, 0xCF, 0x11, 0x89, 0xF4, 0x00, 0xA0, 0xC9, 0x03, 0x49, 0xCB
+};
+
+static const GUID ext_stream_embed_stream_header = {
+ 0xe2, 0x65, 0xfb, 0x3a, 0xEF, 0x47, 0xF2, 0x40, 0xac, 0x2c, 0x70, 0xa9, 0x0d, 0x71, 0xd3, 0x43
+};
+
+static const GUID ext_stream_audio_stream = {
+ 0x9d, 0x8c, 0x17, 0x31, 0xE1, 0x03, 0x28, 0x45, 0xb5, 0x82, 0x3d, 0xf9, 0xdb, 0x22, 0xf5, 0x03
+};
+
+static const GUID metadata_header = {
+ 0xea, 0xcb, 0xf8, 0xc5, 0xaf, 0x5b, 0x77, 0x48, 0x84, 0x67, 0xaa, 0x8c, 0x44, 0xfa, 0x4c, 0xca
+};
+
+/* I am not a number !!! This GUID is the one found on the PC used to
+ generate the stream */
+static const GUID my_guid = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+#define ASF_PACKET_FLAG_ERROR_CORRECTION_PRESENT 0x80 //1000 0000
+
+
+// ASF data packet structure
+// =========================
+//
+//
+// -----------------------------------
+// | Error Correction Data | Optional
+// -----------------------------------
+// | Payload Parsing Information (PPI) |
+// -----------------------------------
+// | Payload Data |
+// -----------------------------------
+// | Padding Data |
+// -----------------------------------
+
+
+// PPI_FLAG - Payload parsing information flags
+#define ASF_PPI_FLAG_MULTIPLE_PAYLOADS_PRESENT 1
+
+#define ASF_PPI_FLAG_SEQUENCE_FIELD_IS_BYTE 0x02 //0000 0010
+#define ASF_PPI_FLAG_SEQUENCE_FIELD_IS_WORD 0x04 //0000 0100
+#define ASF_PPI_FLAG_SEQUENCE_FIELD_IS_DWORD 0x06 //0000 0110
+#define ASF_PPI_MASK_SEQUENCE_FIELD_SIZE 0x06 //0000 0110
+
+#define ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE 0x08 //0000 1000
+#define ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD 0x10 //0001 0000
+#define ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_DWORD 0x18 //0001 1000
+#define ASF_PPI_MASK_PADDING_LENGTH_FIELD_SIZE 0x18 //0001 1000
+
+#define ASF_PPI_FLAG_PACKET_LENGTH_FIELD_IS_BYTE 0x20 //0010 0000
+#define ASF_PPI_FLAG_PACKET_LENGTH_FIELD_IS_WORD 0x40 //0100 0000
+#define ASF_PPI_FLAG_PACKET_LENGTH_FIELD_IS_DWORD 0x60 //0110 0000
+#define ASF_PPI_MASK_PACKET_LENGTH_FIELD_SIZE 0x60 //0110 0000
+
+// PL_FLAG - Payload flags
+#define ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_IS_BYTE 0x01 //0000 0001
+#define ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_IS_WORD 0x02 //0000 0010
+#define ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_IS_DWORD 0x03 //0000 0011
+#define ASF_PL_MASK_REPLICATED_DATA_LENGTH_FIELD_SIZE 0x03 //0000 0011
+
+#define ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_IS_BYTE 0x04 //0000 0100
+#define ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_IS_WORD 0x08 //0000 1000
+#define ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_IS_DWORD 0x0c //0000 1100
+#define ASF_PL_MASK_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_SIZE 0x0c //0000 1100
+
+#define ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_IS_BYTE 0x10 //0001 0000
+#define ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_IS_WORD 0x20 //0010 0000
+#define ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_IS_DWORD 0x30 //0011 0000
+#define ASF_PL_MASK_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_SIZE 0x30 //0011 0000
+
+#define ASF_PL_FLAG_STREAM_NUMBER_LENGTH_FIELD_IS_BYTE 0x40 //0100 0000
+#define ASF_PL_MASK_STREAM_NUMBER_LENGTH_FIELD_SIZE 0xc0 //1100 0000
+
+#define ASF_PL_FLAG_PAYLOAD_LENGTH_FIELD_IS_BYTE 0x40 //0100 0000
+#define ASF_PL_FLAG_PAYLOAD_LENGTH_FIELD_IS_WORD 0x80 //1000 0000
+#define ASF_PL_MASK_PAYLOAD_LENGTH_FIELD_SIZE 0xc0 //1100 0000
+
+#define ASF_PL_FLAG_KEY_FRAME 0x80 //1000 0000
diff --git a/contrib/ffmpeg/libavformat/au.c b/contrib/ffmpeg/libavformat/au.c
new file mode 100644
index 000000000..9e84c9d31
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/au.c
@@ -0,0 +1,209 @@
+/*
+ * AU muxer and demuxer
+ * Copyright (c) 2001 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
+ */
+
+/*
+ * First version by Francois Revol revol@free.fr
+ *
+ * Reference documents:
+ * http://www.opengroup.org/public/pubs/external/auformat.html
+ * http://www.goice.co.jp/member/mo/formats/au.html
+ */
+
+#include "avformat.h"
+#include "allformats.h"
+#include "riff.h"
+
+/* if we don't know the size in advance */
+#define AU_UNKNOWN_SIZE ((uint32_t)(~0))
+
+/* The ffmpeg codecs we support, and the IDs they have in the file */
+static const AVCodecTag codec_au_tags[] = {
+ { CODEC_ID_PCM_MULAW, 1 },
+ { CODEC_ID_PCM_S16BE, 3 },
+ { CODEC_ID_PCM_ALAW, 27 },
+ { 0, 0 },
+};
+
+#ifdef CONFIG_MUXERS
+/* AUDIO_FILE header */
+static int put_au_header(ByteIOContext *pb, AVCodecContext *enc)
+{
+ if(!enc->codec_tag)
+ return -1;
+ put_tag(pb, ".snd"); /* magic number */
+ put_be32(pb, 24); /* header size */
+ put_be32(pb, AU_UNKNOWN_SIZE); /* data size */
+ put_be32(pb, (uint32_t)enc->codec_tag); /* codec ID */
+ put_be32(pb, enc->sample_rate);
+ put_be32(pb, (uint32_t)enc->channels);
+ return 0;
+}
+
+static int au_write_header(AVFormatContext *s)
+{
+ ByteIOContext *pb = &s->pb;
+
+ s->priv_data = NULL;
+
+ /* format header */
+ if (put_au_header(pb, s->streams[0]->codec) < 0) {
+ return -1;
+ }
+
+ put_flush_packet(pb);
+
+ return 0;
+}
+
+static int au_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ ByteIOContext *pb = &s->pb;
+ put_buffer(pb, pkt->data, pkt->size);
+ return 0;
+}
+
+static int au_write_trailer(AVFormatContext *s)
+{
+ ByteIOContext *pb = &s->pb;
+ offset_t file_size;
+
+ if (!url_is_streamed(&s->pb)) {
+
+ /* update file size */
+ file_size = url_ftell(pb);
+ url_fseek(pb, 8, SEEK_SET);
+ put_be32(pb, (uint32_t)(file_size - 24));
+ url_fseek(pb, file_size, SEEK_SET);
+
+ put_flush_packet(pb);
+ }
+
+ return 0;
+}
+#endif //CONFIG_MUXERS
+
+static int au_probe(AVProbeData *p)
+{
+ /* check file header */
+ if (p->buf_size <= 24)
+ return 0;
+ if (p->buf[0] == '.' && p->buf[1] == 's' &&
+ p->buf[2] == 'n' && p->buf[3] == 'd')
+ return AVPROBE_SCORE_MAX;
+ else
+ return 0;
+}
+
+/* au input */
+static int au_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ int size;
+ unsigned int tag;
+ ByteIOContext *pb = &s->pb;
+ unsigned int id, codec, channels, rate;
+ AVStream *st;
+
+ /* check ".snd" header */
+ tag = get_le32(pb);
+ if (tag != MKTAG('.', 's', 'n', 'd'))
+ return -1;
+ size = get_be32(pb); /* header size */
+ get_be32(pb); /* data size */
+
+ id = get_be32(pb);
+ rate = get_be32(pb);
+ channels = get_be32(pb);
+
+ codec = codec_get_id(codec_au_tags, id);
+
+ if (size >= 24) {
+ /* skip unused data */
+ url_fseek(pb, size - 24, SEEK_CUR);
+ }
+
+ /* 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_tag = id;
+ st->codec->codec_id = codec;
+ st->codec->channels = channels;
+ st->codec->sample_rate = rate;
+ av_set_pts_info(st, 64, 1, rate);
+ return 0;
+}
+
+#define MAX_SIZE 4096
+
+static int au_read_packet(AVFormatContext *s,
+ AVPacket *pkt)
+{
+ int ret;
+
+ if (url_feof(&s->pb))
+ return AVERROR_IO;
+ ret= av_get_packet(&s->pb, pkt, MAX_SIZE);
+ if (ret < 0)
+ return AVERROR_IO;
+ pkt->stream_index = 0;
+
+ /* note: we need to modify the packet size here to handle the last
+ packet */
+ pkt->size = ret;
+ return 0;
+}
+
+static int au_read_close(AVFormatContext *s)
+{
+ return 0;
+}
+
+#ifdef CONFIG_AU_DEMUXER
+AVInputFormat au_demuxer = {
+ "au",
+ "SUN AU Format",
+ 0,
+ au_probe,
+ au_read_header,
+ au_read_packet,
+ au_read_close,
+ pcm_read_seek,
+ .codec_tag= (const AVCodecTag*[]){codec_au_tags, 0},
+};
+#endif
+
+#ifdef CONFIG_AU_MUXER
+AVOutputFormat au_muxer = {
+ "au",
+ "SUN AU Format",
+ "audio/basic",
+ "au",
+ 0,
+ CODEC_ID_PCM_S16BE,
+ CODEC_ID_NONE,
+ au_write_header,
+ au_write_packet,
+ au_write_trailer,
+ .codec_tag= (const AVCodecTag*[]){codec_au_tags, 0},
+};
+#endif //CONFIG_AU_MUXER
diff --git a/contrib/ffmpeg/libavformat/audio.c b/contrib/ffmpeg/libavformat/audio.c
new file mode 100644
index 000000000..a9e5bffd5
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/audio.c
@@ -0,0 +1,344 @@
+/*
+ * Linux audio play and grab interface
+ * Copyright (c) 2000, 2001 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 "avformat.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#ifdef HAVE_SOUNDCARD_H
+#include <soundcard.h>
+#else
+#include <sys/soundcard.h>
+#endif
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/time.h>
+
+#define AUDIO_BLOCK_SIZE 4096
+
+typedef struct {
+ int fd;
+ int sample_rate;
+ int channels;
+ int frame_size; /* in bytes ! */
+ int codec_id;
+ int flip_left : 1;
+ uint8_t buffer[AUDIO_BLOCK_SIZE];
+ int buffer_ptr;
+} AudioData;
+
+static int audio_open(AudioData *s, int is_output, const char *audio_device)
+{
+ int audio_fd;
+ int tmp, err;
+ char *flip = getenv("AUDIO_FLIP_LEFT");
+
+ if (is_output)
+ audio_fd = open(audio_device, O_WRONLY);
+ else
+ audio_fd = open(audio_device, O_RDONLY);
+ if (audio_fd < 0) {
+ perror(audio_device);
+ return AVERROR_IO;
+ }
+
+ if (flip && *flip == '1') {
+ s->flip_left = 1;
+ }
+
+ /* non blocking mode */
+ if (!is_output)
+ fcntl(audio_fd, F_SETFL, O_NONBLOCK);
+
+ s->frame_size = AUDIO_BLOCK_SIZE;
+#if 0
+ tmp = (NB_FRAGMENTS << 16) | FRAGMENT_BITS;
+ err = ioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &tmp);
+ if (err < 0) {
+ perror("SNDCTL_DSP_SETFRAGMENT");
+ }
+#endif
+
+ /* select format : favour native format */
+ err = ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &tmp);
+
+#ifdef WORDS_BIGENDIAN
+ if (tmp & AFMT_S16_BE) {
+ tmp = AFMT_S16_BE;
+ } else if (tmp & AFMT_S16_LE) {
+ tmp = AFMT_S16_LE;
+ } else {
+ tmp = 0;
+ }
+#else
+ if (tmp & AFMT_S16_LE) {
+ tmp = AFMT_S16_LE;
+ } else if (tmp & AFMT_S16_BE) {
+ tmp = AFMT_S16_BE;
+ } else {
+ tmp = 0;
+ }
+#endif
+
+ switch(tmp) {
+ case AFMT_S16_LE:
+ s->codec_id = CODEC_ID_PCM_S16LE;
+ break;
+ case AFMT_S16_BE:
+ s->codec_id = CODEC_ID_PCM_S16BE;
+ break;
+ default:
+ av_log(NULL, AV_LOG_ERROR, "Soundcard does not support 16 bit sample format\n");
+ close(audio_fd);
+ return AVERROR_IO;
+ }
+ err=ioctl(audio_fd, SNDCTL_DSP_SETFMT, &tmp);
+ if (err < 0) {
+ perror("SNDCTL_DSP_SETFMT");
+ goto fail;
+ }
+
+ tmp = (s->channels == 2);
+ err = ioctl(audio_fd, SNDCTL_DSP_STEREO, &tmp);
+ if (err < 0) {
+ perror("SNDCTL_DSP_STEREO");
+ goto fail;
+ }
+ if (tmp)
+ s->channels = 2;
+
+ tmp = s->sample_rate;
+ err = ioctl(audio_fd, SNDCTL_DSP_SPEED, &tmp);
+ if (err < 0) {
+ perror("SNDCTL_DSP_SPEED");
+ goto fail;
+ }
+ s->sample_rate = tmp; /* store real sample rate */
+ s->fd = audio_fd;
+
+ return 0;
+ fail:
+ close(audio_fd);
+ return AVERROR_IO;
+}
+
+static int audio_close(AudioData *s)
+{
+ close(s->fd);
+ return 0;
+}
+
+/* sound output support */
+static int audio_write_header(AVFormatContext *s1)
+{
+ AudioData *s = s1->priv_data;
+ AVStream *st;
+ int ret;
+
+ st = s1->streams[0];
+ s->sample_rate = st->codec->sample_rate;
+ s->channels = st->codec->channels;
+ ret = audio_open(s, 1, NULL);
+ if (ret < 0) {
+ return AVERROR_IO;
+ } else {
+ return 0;
+ }
+}
+
+static int audio_write_packet(AVFormatContext *s1, AVPacket *pkt)
+{
+ AudioData *s = s1->priv_data;
+ int len, ret;
+ int size= pkt->size;
+ uint8_t *buf= pkt->data;
+
+ while (size > 0) {
+ len = AUDIO_BLOCK_SIZE - s->buffer_ptr;
+ if (len > size)
+ len = size;
+ memcpy(s->buffer + s->buffer_ptr, buf, len);
+ s->buffer_ptr += len;
+ if (s->buffer_ptr >= AUDIO_BLOCK_SIZE) {
+ for(;;) {
+ ret = write(s->fd, s->buffer, AUDIO_BLOCK_SIZE);
+ if (ret > 0)
+ break;
+ if (ret < 0 && (errno != EAGAIN && errno != EINTR))
+ return AVERROR_IO;
+ }
+ s->buffer_ptr = 0;
+ }
+ buf += len;
+ size -= len;
+ }
+ return 0;
+}
+
+static int audio_write_trailer(AVFormatContext *s1)
+{
+ AudioData *s = s1->priv_data;
+
+ audio_close(s);
+ return 0;
+}
+
+/* grab support */
+
+static int audio_read_header(AVFormatContext *s1, AVFormatParameters *ap)
+{
+ AudioData *s = s1->priv_data;
+ AVStream *st;
+ int ret;
+
+ if (ap->sample_rate <= 0 || ap->channels <= 0)
+ return -1;
+
+ st = av_new_stream(s1, 0);
+ if (!st) {
+ return AVERROR(ENOMEM);
+ }
+ s->sample_rate = ap->sample_rate;
+ s->channels = ap->channels;
+
+ ret = audio_open(s, 0, s1->filename);
+ if (ret < 0) {
+ av_free(st);
+ return AVERROR_IO;
+ }
+
+ /* take real parameters */
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_id = s->codec_id;
+ st->codec->sample_rate = s->sample_rate;
+ st->codec->channels = s->channels;
+
+ av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
+ return 0;
+}
+
+static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt)
+{
+ AudioData *s = s1->priv_data;
+ int ret, bdelay;
+ int64_t cur_time;
+ struct audio_buf_info abufi;
+
+ if (av_new_packet(pkt, s->frame_size) < 0)
+ return AVERROR_IO;
+ for(;;) {
+ struct timeval tv;
+ fd_set fds;
+
+ tv.tv_sec = 0;
+ tv.tv_usec = 30 * 1000; /* 30 msecs -- a bit shorter than 1 frame at 30fps */
+
+ FD_ZERO(&fds);
+ FD_SET(s->fd, &fds);
+
+ /* This will block until data is available or we get a timeout */
+ (void) select(s->fd + 1, &fds, 0, 0, &tv);
+
+ ret = read(s->fd, pkt->data, pkt->size);
+ if (ret > 0)
+ break;
+ if (ret == -1 && (errno == EAGAIN || errno == EINTR)) {
+ av_free_packet(pkt);
+ pkt->size = 0;
+ pkt->pts = av_gettime();
+ return 0;
+ }
+ if (!(ret == 0 || (ret == -1 && (errno == EAGAIN || errno == EINTR)))) {
+ av_free_packet(pkt);
+ return AVERROR_IO;
+ }
+ }
+ pkt->size = ret;
+
+ /* compute pts of the start of the packet */
+ cur_time = av_gettime();
+ bdelay = ret;
+ if (ioctl(s->fd, SNDCTL_DSP_GETISPACE, &abufi) == 0) {
+ bdelay += abufi.bytes;
+ }
+ /* substract time represented by the number of bytes in the audio fifo */
+ cur_time -= (bdelay * 1000000LL) / (s->sample_rate * s->channels);
+
+ /* convert to wanted units */
+ pkt->pts = cur_time;
+
+ if (s->flip_left && s->channels == 2) {
+ int i;
+ short *p = (short *) pkt->data;
+
+ for (i = 0; i < ret; i += 4) {
+ *p = ~*p;
+ p += 2;
+ }
+ }
+ return 0;
+}
+
+static int audio_read_close(AVFormatContext *s1)
+{
+ AudioData *s = s1->priv_data;
+
+ audio_close(s);
+ return 0;
+}
+
+#ifdef CONFIG_AUDIO_DEMUXER
+AVInputFormat audio_demuxer = {
+ "audio_device",
+ "audio grab and output",
+ sizeof(AudioData),
+ NULL,
+ audio_read_header,
+ audio_read_packet,
+ audio_read_close,
+ .flags = AVFMT_NOFILE,
+};
+#endif
+
+#ifdef CONFIG_AUDIO_MUXER
+AVOutputFormat audio_muxer = {
+ "audio_device",
+ "audio grab and output",
+ "",
+ "",
+ sizeof(AudioData),
+ /* XXX: we make the assumption that the soundcard accepts this format */
+ /* XXX: find better solution with "preinit" method, needed also in
+ other formats */
+#ifdef WORDS_BIGENDIAN
+ CODEC_ID_PCM_S16BE,
+#else
+ CODEC_ID_PCM_S16LE,
+#endif
+ CODEC_ID_NONE,
+ audio_write_header,
+ audio_write_packet,
+ audio_write_trailer,
+ .flags = AVFMT_NOFILE,
+};
+#endif
diff --git a/contrib/ffmpeg/libavformat/avformat.h b/contrib/ffmpeg/libavformat/avformat.h
new file mode 100644
index 000000000..eb8c4e153
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/avformat.h
@@ -0,0 +1,888 @@
+/*
+ * copyright (c) 2001 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
+ */
+
+#ifndef AVFORMAT_H
+#define AVFORMAT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define LIBAVFORMAT_VERSION_INT ((51<<16)+(11<<8)+0)
+#define LIBAVFORMAT_VERSION 51.11.0
+#define LIBAVFORMAT_BUILD LIBAVFORMAT_VERSION_INT
+
+#define LIBAVFORMAT_IDENT "Lavf" AV_STRINGIFY(LIBAVFORMAT_VERSION)
+
+#include <time.h>
+#include <stdio.h> /* FILE */
+#include "avcodec.h"
+
+#include "avio.h"
+
+/* packet functions */
+
+typedef struct AVPacket {
+ int64_t pts; ///< presentation time stamp in time_base units
+ int64_t dts; ///< decompression time stamp in time_base units
+ uint8_t *data;
+ int size;
+ int stream_index;
+ int flags;
+ int duration; ///< presentation duration in time_base units (0 if not available)
+ void (*destruct)(struct AVPacket *);
+ void *priv;
+ int64_t pos; ///< byte position in stream, -1 if unknown
+} AVPacket;
+#define PKT_FLAG_KEY 0x0001
+
+void av_destruct_packet_nofree(AVPacket *pkt);
+
+/**
+ * Default packet destructor.
+ */
+void av_destruct_packet(AVPacket *pkt);
+
+/* initialize optional fields of a packet */
+static inline void av_init_packet(AVPacket *pkt)
+{
+ pkt->pts = AV_NOPTS_VALUE;
+ pkt->dts = AV_NOPTS_VALUE;
+ pkt->pos = -1;
+ pkt->duration = 0;
+ pkt->flags = 0;
+ pkt->stream_index = 0;
+ pkt->destruct= av_destruct_packet_nofree;
+}
+
+/**
+ * Allocate the payload of a packet and intialized its fields to default values.
+ *
+ * @param pkt packet
+ * @param size wanted payload size
+ * @return 0 if OK. AVERROR_xxx otherwise.
+ */
+int av_new_packet(AVPacket *pkt, int size);
+
+/**
+ * Allocate and read the payload of a packet and intialized its fields to default values.
+ *
+ * @param pkt packet
+ * @param size wanted payload size
+ * @return >0 (read size) if OK. AVERROR_xxx otherwise.
+ */
+int av_get_packet(ByteIOContext *s, AVPacket *pkt, int size);
+
+/**
+ * @warning This is a hack - the packet memory allocation stuff is broken. The
+ * packet is allocated if it was not really allocated
+ */
+int av_dup_packet(AVPacket *pkt);
+
+/**
+ * Free a packet
+ *
+ * @param pkt packet to free
+ */
+static inline void av_free_packet(AVPacket *pkt)
+{
+ if (pkt && pkt->destruct) {
+ pkt->destruct(pkt);
+ }
+}
+
+/*************************************************/
+/* fractional numbers for exact pts handling */
+
+/* the exact value of the fractional number is: 'val + num / den'. num
+ is assumed to be such as 0 <= num < den */
+typedef struct AVFrac {
+ int64_t val, num, den;
+} AVFrac attribute_deprecated;
+
+/*************************************************/
+/* input/output formats */
+
+struct AVCodecTag;
+
+struct AVFormatContext;
+
+/** this structure contains the data a format has to probe a file */
+typedef struct AVProbeData {
+ const char *filename;
+ unsigned char *buf;
+ int buf_size;
+} AVProbeData;
+
+#define AVPROBE_SCORE_MAX 100 ///< max score, half of that is used for file extension based detection
+
+typedef struct AVFormatParameters {
+ AVRational time_base;
+ int sample_rate;
+ int channels;
+ int width;
+ int height;
+ enum PixelFormat pix_fmt;
+ int channel; /**< used to select dv channel */
+#if LIBAVFORMAT_VERSION_INT < (52<<16)
+ const char *device; /**< video, audio or DV device */
+#endif
+ const char *standard; /**< tv standard, NTSC, PAL, SECAM */
+ int mpeg2ts_raw:1; /**< force raw MPEG2 transport stream output, if possible */
+ int mpeg2ts_compute_pcr:1; /**< compute exact PCR for each transport
+ stream packet (only meaningful if
+ mpeg2ts_raw is TRUE */
+ int initial_pause:1; /**< do not begin to play the stream
+ immediately (RTSP only) */
+ int prealloced_context:1;
+ enum CodecID video_codec_id;
+ enum CodecID audio_codec_id;
+} AVFormatParameters;
+
+//! demuxer will use url_fopen, no opened file should be provided by the caller
+#define AVFMT_NOFILE 0x0001
+#define AVFMT_NEEDNUMBER 0x0002 /**< needs '%d' in filename */
+#define AVFMT_SHOW_IDS 0x0008 /**< show format stream IDs numbers */
+#define AVFMT_RAWPICTURE 0x0020 /**< format wants AVPicture structure for
+ raw picture data */
+#define AVFMT_GLOBALHEADER 0x0040 /**< format wants global header */
+#define AVFMT_NOTIMESTAMPS 0x0080 /**< format doesnt need / has any timestamps */
+#define AVFMT_GENERIC_INDEX 0x0100 /**< use generic index building code */
+
+typedef struct AVOutputFormat {
+ const char *name;
+ const char *long_name;
+ const char *mime_type;
+ const char *extensions; /**< comma separated filename extensions */
+ /** size of private data so that it can be allocated in the wrapper */
+ int priv_data_size;
+ /* output support */
+ enum CodecID audio_codec; /**< default audio codec */
+ enum CodecID video_codec; /**< default video codec */
+ int (*write_header)(struct AVFormatContext *);
+ int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
+ int (*write_trailer)(struct AVFormatContext *);
+ /** can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_GLOBALHEADER */
+ int flags;
+ /** currently only used to set pixel format if not YUV420P */
+ int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
+ int (*interleave_packet)(struct AVFormatContext *, AVPacket *out, AVPacket *in, int flush);
+
+ /**
+ * list of supported codec_id-codec_tag pairs, ordered by "better choice first"
+ * the arrays are all CODEC_ID_NONE terminated
+ */
+ const struct AVCodecTag **codec_tag;
+
+ /* private fields */
+ struct AVOutputFormat *next;
+} AVOutputFormat;
+
+typedef struct AVInputFormat {
+ const char *name;
+ const char *long_name;
+ /** size of private data so that it can be allocated in the wrapper */
+ int priv_data_size;
+ /** tell if a given file has a chance of being parsing by this format */
+ int (*read_probe)(AVProbeData *);
+ /** read the format header and initialize the AVFormatContext
+ structure. Return 0 if OK. 'ap' if non NULL contains
+ additionnal paramters. Only used in raw format right
+ now. 'av_new_stream' should be called to create new streams. */
+ int (*read_header)(struct AVFormatContext *,
+ AVFormatParameters *ap);
+ /** read one packet and put it in 'pkt'. pts and flags are also
+ set. 'av_new_stream' can be called only if the flag
+ AVFMTCTX_NOHEADER is used. */
+ int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
+ /** close the stream. The AVFormatContext and AVStreams are not
+ freed by this function */
+ int (*read_close)(struct AVFormatContext *);
+ /**
+ * seek to a given timestamp relative to the frames in
+ * stream component stream_index
+ * @param stream_index must not be -1
+ * @param flags selects which direction should be preferred if no exact
+ * match is available
+ */
+ int (*read_seek)(struct AVFormatContext *,
+ int stream_index, int64_t timestamp, int flags);
+ /**
+ * gets the next timestamp in AV_TIME_BASE units.
+ */
+ int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
+ int64_t *pos, int64_t pos_limit);
+ /** can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER */
+ int flags;
+ /** if extensions are defined, then no probe is done. You should
+ usually not use extension format guessing because it is not
+ reliable enough */
+ const char *extensions;
+ /** general purpose read only value that the format can use */
+ int value;
+
+ /** start/resume playing - only meaningful if using a network based format
+ (RTSP) */
+ int (*read_play)(struct AVFormatContext *);
+
+ /** pause playing - only meaningful if using a network based format
+ (RTSP) */
+ int (*read_pause)(struct AVFormatContext *);
+
+ const struct AVCodecTag **codec_tag;
+
+ /* private fields */
+ struct AVInputFormat *next;
+} AVInputFormat;
+
+typedef struct AVIndexEntry {
+ int64_t pos;
+ int64_t timestamp;
+#define AVINDEX_KEYFRAME 0x0001
+ int flags:2;
+ int size:30; //yeah trying to keep the size of this small to reduce memory requirements (its 24 vs 32 byte due to possible 8byte align)
+ int min_distance; /**< min distance between this and the previous keyframe, used to avoid unneeded searching */
+} AVIndexEntry;
+
+typedef struct AVStream {
+ int index; /**< stream index in AVFormatContext */
+ int id; /**< format specific stream id */
+ AVCodecContext *codec; /**< codec context */
+ /**
+ * real base frame rate of the stream.
+ * this is the lowest framerate with which all timestamps can be
+ * represented accurately (its the least common multiple of all
+ * framerates in the stream), Note, this value is just a guess!
+ * for example if the timebase is 1/90000 and all frames have either
+ * approximately 3600 or 1800 timer ticks then r_frame_rate will be 50/1
+ */
+ AVRational r_frame_rate;
+ void *priv_data;
+#if LIBAVFORMAT_VERSION_INT < (52<<16)
+ /* internal data used in av_find_stream_info() */
+ int64_t codec_info_duration;
+ int codec_info_nb_frames;
+#endif
+ /** encoding: PTS generation when outputing stream */
+ AVFrac pts;
+
+ /**
+ * this is the fundamental unit of time (in seconds) in terms
+ * of which frame timestamps are represented. for fixed-fps content,
+ * timebase should be 1/framerate and timestamp increments should be
+ * identically 1.
+ */
+ AVRational time_base;
+ int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
+ /* ffmpeg.c private use */
+ int stream_copy; /**< if set, just copy stream */
+ enum AVDiscard discard; ///< selects which packets can be discarded at will and dont need to be demuxed
+ //FIXME move stuff to a flags field?
+ /** quality, as it has been removed from AVCodecContext and put in AVVideoFrame
+ * MN:dunno if thats the right place, for it */
+ float quality;
+ /** decoding: position of the first frame of the component, in
+ AV_TIME_BASE fractional seconds. */
+ int64_t start_time;
+ /** decoding: duration of the stream, in AV_TIME_BASE fractional
+ seconds. */
+ int64_t duration;
+
+ char language[4]; /** ISO 639 3-letter language code (empty string if undefined) */
+
+ /* av_read_frame() support */
+ int need_parsing; ///< 1->full parsing needed, 2->only parse headers dont repack
+ struct AVCodecParserContext *parser;
+
+ int64_t cur_dts;
+ int last_IP_duration;
+ int64_t last_IP_pts;
+ /* av_seek_frame() support */
+ AVIndexEntry *index_entries; /**< only used if the format does not
+ support seeking natively */
+ int nb_index_entries;
+ unsigned int index_entries_allocated_size;
+
+ int64_t nb_frames; ///< number of frames in this stream if known or 0
+
+#define MAX_REORDER_DELAY 4
+ int64_t pts_buffer[MAX_REORDER_DELAY+1];
+} AVStream;
+
+#define AVFMTCTX_NOHEADER 0x0001 /**< signal that no header is present
+ (streams are added dynamically) */
+
+#define MAX_STREAMS 20
+
+/* format I/O context */
+typedef struct AVFormatContext {
+ const AVClass *av_class; /**< set by av_alloc_format_context */
+ /* can only be iformat or oformat, not both at the same time */
+ struct AVInputFormat *iformat;
+ struct AVOutputFormat *oformat;
+ void *priv_data;
+ ByteIOContext pb;
+ unsigned int nb_streams;
+ AVStream *streams[MAX_STREAMS];
+ char filename[1024]; /**< input or output filename */
+ /* stream info */
+ int64_t timestamp;
+ char title[512];
+ char author[512];
+ char copyright[512];
+ char comment[512];
+ char album[512];
+ int year; /**< ID3 year, 0 if none */
+ int track; /**< track number, 0 if none */
+ char genre[32]; /**< ID3 genre */
+
+ int ctx_flags; /**< format specific flags, see AVFMTCTX_xx */
+ /* private data for pts handling (do not modify directly) */
+ /** This buffer is only needed when packets were already buffered but
+ not decoded, for example to get the codec parameters in mpeg
+ streams */
+ struct AVPacketList *packet_buffer;
+
+ /** decoding: position of the first frame of the component, in
+ AV_TIME_BASE fractional seconds. NEVER set this value directly:
+ 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. */
+ int64_t duration;
+ /** decoding: total file size. 0 if unknown */
+ int64_t file_size;
+ /** decoding: total stream bitrate in bit/s, 0 if not
+ available. Never set it directly if the file_size and the
+ duration are known as ffmpeg can compute it automatically. */
+ int bit_rate;
+
+ /* av_read_frame() support */
+ AVStream *cur_st;
+ const uint8_t *cur_ptr;
+ int cur_len;
+ AVPacket cur_pkt;
+
+ /* av_seek_frame() support */
+ int64_t data_offset; /** offset of the first packet */
+ int index_built;
+
+ int mux_rate;
+ int packet_size;
+ int preload;
+ int max_delay;
+
+#define AVFMT_NOOUTPUTLOOP -1
+#define AVFMT_INFINITEOUTPUTLOOP 0
+ /** number of times to loop output in formats that support it */
+ int loop_output;
+
+ int flags;
+#define AVFMT_FLAG_GENPTS 0x0001 ///< generate pts if missing even if it requires parsing future frames
+#define AVFMT_FLAG_IGNIDX 0x0002 ///< ignore index
+
+ int loop_input;
+ /** decoding: size of data to probe; encoding unused */
+ unsigned int probesize;
+
+ /**
+ * maximum duration in AV_TIME_BASE units over which the input should be analyzed in av_find_stream_info()
+ */
+ int max_analyze_duration;
+
+ const uint8_t *key;
+ int keylen;
+} AVFormatContext;
+
+typedef struct AVPacketList {
+ AVPacket pkt;
+ struct AVPacketList *next;
+} AVPacketList;
+
+extern AVInputFormat *first_iformat;
+extern AVOutputFormat *first_oformat;
+
+enum CodecID av_guess_image2_codec(const char *filename);
+
+/* XXX: use automatic init with either ELF sections or C file parser */
+/* modules */
+
+#include "rtp.h"
+
+#include "rtsp.h"
+
+/* utils.c */
+void av_register_input_format(AVInputFormat *format);
+void av_register_output_format(AVOutputFormat *format);
+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);
+
+/**
+ * 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);
+
+/**
+ * Send a nice hexadecimal dump of a buffer to the specified file stream.
+ *
+ * @param f The file stream pointer where the dump should be sent to.
+ * @param buf buffer
+ * @param size buffer size
+ *
+ * @see av_hex_dump_log, av_pkt_dump, av_pkt_dump_log
+ */
+void av_hex_dump(FILE *f, uint8_t *buf, int size);
+
+/**
+ * Send a nice hexadecimal dump of a buffer to the log.
+ *
+ * @param avcl A pointer to an arbitrary struct of which the first field is a
+ * pointer to an AVClass struct.
+ * @param level The importance level of the message, lower values signifying
+ * higher importance.
+ * @param buf buffer
+ * @param size buffer size
+ *
+ * @see av_hex_dump, av_pkt_dump, av_pkt_dump_log
+ */
+void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
+
+/**
+ * Send a nice dump of a packet to the specified file stream.
+ *
+ * @param f The file stream pointer where the dump should be sent to.
+ * @param pkt packet to dump
+ * @param dump_payload true if the payload must be displayed too
+ */
+void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
+
+/**
+ * Send a nice dump of a packet to the log.
+ *
+ * @param avcl A pointer to an arbitrary struct of which the first field is a
+ * pointer to an AVClass struct.
+ * @param level The importance level of the message, lower values signifying
+ * higher importance.
+ * @param pkt packet to dump
+ * @param dump_payload true if the payload must be displayed too
+ */
+void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload);
+
+void av_register_all(void);
+
+/** codec tag <-> codec id */
+enum CodecID av_codec_get_id(const struct AVCodecTag **tags, unsigned int tag);
+unsigned int av_codec_get_tag(const struct AVCodecTag **tags, enum CodecID id);
+
+/* media file input */
+
+/**
+ * finds AVInputFormat based on input format's short name.
+ */
+AVInputFormat *av_find_input_format(const char *short_name);
+
+/**
+ * Guess file format.
+ *
+ * @param is_opened whether the file is already opened, determines whether
+ * demuxers with or without AVFMT_NOFILE are probed
+ */
+AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
+
+/**
+ * Allocates all the structures needed to read an input stream.
+ * This does not open the needed codecs for decoding the stream[s].
+ */
+int av_open_input_stream(AVFormatContext **ic_ptr,
+ ByteIOContext *pb, const char *filename,
+ AVInputFormat *fmt, AVFormatParameters *ap);
+
+/**
+ * Open a media file as input. The codec are not opened. Only the file
+ * header (if present) is read.
+ *
+ * @param ic_ptr the opened media file handle is put here
+ * @param filename filename to open.
+ * @param fmt if non NULL, force the file format to use
+ * @param buf_size optional buffer size (zero if default is OK)
+ * @param ap additionnal parameters needed when opening the file (NULL if default)
+ * @return 0 if OK. AVERROR_xxx otherwise.
+ */
+int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
+ AVInputFormat *fmt,
+ int buf_size,
+ AVFormatParameters *ap);
+/** no av_open for output, so applications will need this: */
+AVFormatContext *av_alloc_format_context(void);
+
+/**
+ * Read packets of a media file to get stream information. This
+ * is useful for file formats with no headers such as MPEG. This
+ * function also computes the real frame rate in case of mpeg2 repeat
+ * frame mode.
+ * The logical file position is not changed by this function;
+ * examined packets may be buffered for later processing.
+ *
+ * @param ic media file handle
+ * @return >=0 if OK. AVERROR_xxx if error.
+ * @todo let user decide somehow what information is needed so we dont waste time geting stuff the user doesnt need
+ */
+int av_find_stream_info(AVFormatContext *ic);
+
+/**
+ * Read a transport packet from a media file.
+ *
+ * This function is absolete and should never be used.
+ * Use av_read_frame() instead.
+ *
+ * @param s media file handle
+ * @param pkt is filled
+ * @return 0 if OK. AVERROR_xxx if error.
+ */
+int av_read_packet(AVFormatContext *s, AVPacket *pkt);
+
+/**
+ * Return the next frame of a stream.
+ *
+ * The returned packet is valid
+ * until the next av_read_frame() or until av_close_input_file() and
+ * must be freed with av_free_packet. For video, the packet contains
+ * exactly one frame. For audio, it contains an integer number of
+ * frames if each frame has a known fixed size (e.g. PCM or ADPCM
+ * data). If the audio frames have a variable size (e.g. MPEG audio),
+ * then it contains one frame.
+ *
+ * pkt->pts, pkt->dts and pkt->duration are always set to correct
+ * values in AVStream.timebase units (and guessed if the format cannot
+ * provided them). pkt->pts can be AV_NOPTS_VALUE if the video format
+ * has B frames, so it is better to rely on pkt->dts if you do not
+ * decompress the payload.
+ *
+ * @return 0 if OK, < 0 if error or end of file.
+ */
+int av_read_frame(AVFormatContext *s, AVPacket *pkt);
+
+/**
+ * Seek to the key frame at timestamp.
+ * 'timestamp' in 'stream_index'.
+ * @param stream_index If stream_index is (-1), a default
+ * stream is selected, and timestamp is automatically converted
+ * from AV_TIME_BASE units to the stream specific time_base.
+ * @param timestamp timestamp in AVStream.time_base units
+ * or if there is no stream specified then in AV_TIME_BASE units
+ * @param flags flags which select direction and seeking mode
+ * @return >= 0 on success
+ */
+int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags);
+
+/**
+ * start playing a network based stream (e.g. RTSP stream) at the
+ * current position
+ */
+int av_read_play(AVFormatContext *s);
+
+/**
+ * Pause a network based stream (e.g. RTSP stream).
+ *
+ * Use av_read_play() to resume it.
+ */
+int av_read_pause(AVFormatContext *s);
+
+/**
+ * Close a media file (but not its codecs).
+ *
+ * @param s media file handle
+ */
+void av_close_input_file(AVFormatContext *s);
+
+/**
+ * Add a new stream to a media file.
+ *
+ * Can only be called in the read_header() function. If the flag
+ * AVFMTCTX_NOHEADER is in the format context, then new streams
+ * can be added in read_packet too.
+ *
+ * @param s media file handle
+ * @param id file format dependent stream id
+ */
+AVStream *av_new_stream(AVFormatContext *s, int id);
+
+/**
+ * Set the pts for a given stream.
+ *
+ * @param s stream
+ * @param pts_wrap_bits number of bits effectively used by the pts
+ * (used for wrap control, 33 is the value for MPEG)
+ * @param pts_num numerator to convert to seconds (MPEG: 1)
+ * @param pts_den denominator to convert to seconds (MPEG: 90000)
+ */
+void av_set_pts_info(AVStream *s, int pts_wrap_bits,
+ int pts_num, int pts_den);
+
+#define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
+#define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes
+#define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non keyframes
+
+int av_find_default_stream_index(AVFormatContext *s);
+
+/**
+ * Gets the index for a specific timestamp.
+ * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond to
+ * the timestamp which is <= the requested one, if backward is 0
+ * then it will be >=
+ * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
+ * @return < 0 if no such timestamp could be found
+ */
+int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
+
+/**
+ * Add a index entry into a sorted list updateing if it is already there.
+ *
+ * @param timestamp timestamp in the timebase of the given stream
+ */
+int av_add_index_entry(AVStream *st,
+ int64_t pos, int64_t timestamp, int size, int distance, int flags);
+
+/**
+ * Does a binary search using av_index_search_timestamp() and AVCodec.read_timestamp().
+ * this isnt supposed to be called directly by a user application, but by demuxers
+ * @param target_ts target timestamp in the time base of the given stream
+ * @param stream_index stream number
+ */
+int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags);
+
+/**
+ * Updates cur_dts of all streams based on given timestamp and AVStream.
+ *
+ * Stream ref_st unchanged, others set cur_dts in their native timebase
+ * only needed for timestamp wrapping or if (dts not set and pts!=dts)
+ * @param timestamp new dts expressed in time_base of param ref_st
+ * @param ref_st reference stream giving time_base of param timestamp
+ */
+void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
+
+/**
+ * Does a binary search using read_timestamp().
+ * this isnt supposed to be called directly by a user application, but by demuxers
+ * @param target_ts target timestamp in the time base of the given stream
+ * @param stream_index stream number
+ */
+int64_t av_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, int64_t pos_min, int64_t pos_max, int64_t pos_limit, int64_t ts_min, int64_t ts_max, int flags, int64_t *ts_ret, int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
+
+/** media file output */
+int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
+
+/**
+ * allocate the stream private data and write the stream header to an
+ * output media file
+ *
+ * @param s media file handle
+ * @return 0 if OK. AVERROR_xxx if error.
+ */
+int av_write_header(AVFormatContext *s);
+
+/**
+ * Write a packet to an output media file.
+ *
+ * The packet shall contain one audio or video frame.
+ * The packet must be correctly interleaved according to the container specification,
+ * if not then av_interleaved_write_frame must be used
+ *
+ * @param s media file handle
+ * @param pkt the packet, which contains the stream_index, buf/buf_size, dts/pts, ...
+ * @return < 0 if error, = 0 if OK, 1 if end of stream wanted.
+ */
+int av_write_frame(AVFormatContext *s, AVPacket *pkt);
+
+/**
+ * Writes a packet to an output media file ensuring correct interleaving.
+ *
+ * The packet must contain one audio or video frame.
+ * If the packets are already correctly interleaved the application should
+ * call av_write_frame() instead as its slightly faster, its also important
+ * to keep in mind that completly non interleaved input will need huge amounts
+ * of memory to interleave with this, so its prefereable to interleave at the
+ * demuxer level
+ *
+ * @param s media file handle
+ * @param pkt the packet, which contains the stream_index, buf/buf_size, dts/pts, ...
+ * @return < 0 if error, = 0 if OK, 1 if end of stream wanted.
+ */
+int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
+
+/**
+ * Interleave a packet per DTS in an output media file.
+ *
+ * Packets with pkt->destruct == av_destruct_packet will be freed inside this function,
+ * so they cannot be used after it, note calling av_free_packet() on them is still safe.
+ *
+ * @param s media file handle
+ * @param out the interleaved packet will be output here
+ * @param in the input packet
+ * @param flush 1 if no further packets are available as input and all
+ * remaining packets should be output
+ * @return 1 if a packet was output, 0 if no packet could be output,
+ * < 0 if an error occured
+ */
+int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush);
+
+/**
+ * @brief Write the stream trailer to an output media file and
+ * free the file private data.
+ *
+ * @param s media file handle
+ * @return 0 if OK. AVERROR_xxx if error.
+ */
+int av_write_trailer(AVFormatContext *s);
+
+void dump_format(AVFormatContext *ic,
+ int index,
+ const char *url,
+ int is_output);
+
+/**
+ * parses width and height out of string str.
+ */
+int parse_image_size(int *width_ptr, int *height_ptr, const char *str);
+
+/**
+ * Converts frame rate from string to a fraction.
+ */
+int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg);
+
+/**
+ * Converts date string to number of seconds since Jan 1st, 1970.
+ *
+ * @code
+ * Syntax:
+ * - If not a duration:
+ * [{YYYY-MM-DD|YYYYMMDD}]{T| }{HH[:MM[:SS[.m...]]][Z]|HH[MM[SS[.m...]]][Z]}
+ * Time is localtime unless Z is suffixed to the end. In this case GMT
+ * Return the date in micro seconds since 1970
+ *
+ * - If a duration:
+ * HH[:MM[:SS[.m...]]]
+ * S+[.m...]
+ * @endcode
+ */
+int64_t parse_date(const char *datestr, int duration);
+
+int64_t av_gettime(void);
+
+/* ffm specific for ffserver */
+#define FFM_PACKET_SIZE 4096
+offset_t ffm_read_write_index(int fd);
+void ffm_write_write_index(int fd, offset_t pos);
+void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size);
+
+/**
+ * Attempts to find a specific tag in a URL.
+ *
+ * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done.
+ * Return 1 if found.
+ */
+int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
+
+/**
+ * Returns in 'buf' the path with '%d' replaced by number.
+
+ * Also handles the '%0nd' format where 'n' is the total number
+ * of digits and '%%'.
+ *
+ * @param buf destination buffer
+ * @param buf_size destination buffer size
+ * @param path numbered sequence string
+ * @number frame number
+ * @return 0 if OK, -1 if format error.
+ */
+int av_get_frame_filename(char *buf, int buf_size,
+ const char *path, int number);
+
+/**
+ * Check whether filename actually is a numbered sequence generator.
+ *
+ * @param filename possible numbered sequence string
+ * @return 1 if a valid numbered sequence string, 0 otherwise.
+ */
+int av_filename_number_test(const char *filename);
+
+/* grab specific */
+int video_grab_init(void);
+int audio_init(void);
+
+/* DV1394 */
+int dv1394_init(void);
+int dc1394_init(void);
+
+#ifdef HAVE_AV_CONFIG_H
+
+#include "os_support.h"
+
+int strstart(const char *str, const char *val, const char **ptr);
+int stristart(const char *str, const char *val, const char **ptr);
+void pstrcpy(char *buf, int buf_size, const char *str);
+char *pstrcat(char *buf, int buf_size, const char *s);
+
+void __dynarray_add(unsigned long **tab_ptr, int *nb_ptr, unsigned long 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 */\
+ __dynarray_add((unsigned long **)_tab, nb_ptr, (unsigned long)_elem);\
+} while(0)
+#else
+#define dynarray_add(tab, nb_ptr, elem)\
+do {\
+ __dynarray_add((unsigned long **)(tab), nb_ptr, (unsigned long)(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);
+
+int match_ext(const char *filename, const char *extensions);
+
+#endif /* HAVE_AV_CONFIG_H */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* AVFORMAT_H */
+
diff --git a/contrib/ffmpeg/libavformat/avi.h b/contrib/ffmpeg/libavformat/avi.h
new file mode 100644
index 000000000..2c360689b
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/avi.h
@@ -0,0 +1,39 @@
+/*
+ * copyright (c) 2001 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
+ */
+
+#ifndef FFMPEG_AVI_H
+#define FFMPEG_AVI_H
+
+#include "avcodec.h"
+
+#define AVIF_HASINDEX 0x00000010 // Index at end of file?
+#define AVIF_MUSTUSEINDEX 0x00000020
+#define AVIF_ISINTERLEAVED 0x00000100
+#define AVIF_TRUSTCKTYPE 0x00000800 // Use CKType to find key frames?
+#define AVIF_WASCAPTUREFILE 0x00010000
+#define AVIF_COPYRIGHTED 0x00020000
+
+#define AVI_MAX_RIFF_SIZE 0x40000000LL
+#define AVI_MASTER_INDEX_SIZE 256
+
+/* index flags */
+#define AVIIF_INDEX 0x10
+
+#endif /* FFMPEG_AVI_H */
diff --git a/contrib/ffmpeg/libavformat/avidec.c b/contrib/ffmpeg/libavformat/avidec.c
new file mode 100644
index 000000000..23c130ab7
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/avidec.c
@@ -0,0 +1,1018 @@
+/*
+ * AVI demuxer
+ * Copyright (c) 2001 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 "avformat.h"
+#include "avi.h"
+#include "dv.h"
+#include "riff.h"
+
+#undef NDEBUG
+#include <assert.h>
+
+//#define DEBUG
+//#define DEBUG_SEEK
+
+typedef struct AVIStream {
+ int64_t frame_offset; /* current frame (video) or byte (audio) counter
+ (used to compute the pts) */
+ int remaining;
+ int packet_size;
+
+ int scale;
+ int rate;
+ int sample_size; /* size of one sample (or packet) (in the rate/scale sense) in bytes */
+
+ int64_t cum_len; /* temporary storage (used during seek) */
+
+ int prefix; ///< normally 'd'<<8 + 'c' or 'w'<<8 + 'b'
+ int prefix_count;
+} AVIStream;
+
+typedef struct {
+ int64_t riff_end;
+ int64_t movi_end;
+ offset_t movi_list;
+ int index_loaded;
+ int is_odml;
+ int non_interleaved;
+ int stream_index;
+ DVDemuxContext* dv_demux;
+} AVIContext;
+
+static int avi_load_index(AVFormatContext *s);
+static int guess_ni_flag(AVFormatContext *s);
+
+#ifdef DEBUG
+static void print_tag(const char *str, unsigned int tag, int size)
+{
+ printf("%s: tag=%c%c%c%c size=0x%x\n",
+ str, tag & 0xff,
+ (tag >> 8) & 0xff,
+ (tag >> 16) & 0xff,
+ (tag >> 24) & 0xff,
+ size);
+}
+#endif
+
+static int get_riff(AVIContext *avi, ByteIOContext *pb)
+{
+ uint32_t tag;
+ /* check RIFF header */
+ tag = get_le32(pb);
+
+ if (tag != MKTAG('R', 'I', 'F', 'F'))
+ return -1;
+ avi->riff_end = get_le32(pb); /* RIFF chunk size */
+ avi->riff_end += url_ftell(pb); /* RIFF chunk end */
+ tag = get_le32(pb);
+ if(tag == MKTAG('A', 'V', 'I', 0x19))
+ av_log(NULL, AV_LOG_INFO, "file has been generated with a totally broken muxer\n");
+ else
+ if (tag != MKTAG('A', 'V', 'I', ' ') && tag != MKTAG('A', 'V', 'I', 'X'))
+ return -1;
+
+ return 0;
+}
+
+static int read_braindead_odml_indx(AVFormatContext *s, int frame_num){
+ AVIContext *avi = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ int longs_pre_entry= get_le16(pb);
+ int index_sub_type = get_byte(pb);
+ int index_type = get_byte(pb);
+ int entries_in_use = get_le32(pb);
+ int chunk_id = get_le32(pb);
+ int64_t base = get_le64(pb);
+ int stream_id= 10*((chunk_id&0xFF) - '0') + (((chunk_id>>8)&0xFF) - '0');
+ AVStream *st;
+ AVIStream *ast;
+ int i;
+ int64_t last_pos= -1;
+ int64_t filesize= url_fsize(&s->pb);
+
+#ifdef DEBUG_SEEK
+ av_log(s, AV_LOG_ERROR, "longs_pre_entry:%d index_type:%d entries_in_use:%d chunk_id:%X base:%16"PRIX64"\n",
+ longs_pre_entry,index_type, entries_in_use, chunk_id, base);
+#endif
+
+ if(stream_id > s->nb_streams || stream_id < 0)
+ return -1;
+ st= s->streams[stream_id];
+ ast = st->priv_data;
+
+ if(index_sub_type)
+ return -1;
+
+ get_le32(pb);
+
+ if(index_type && longs_pre_entry != 2)
+ return -1;
+ if(index_type>1)
+ return -1;
+
+ if(filesize > 0 && base >= filesize){
+ av_log(s, AV_LOG_ERROR, "ODML index invalid\n");
+ if(base>>32 == (base & 0xFFFFFFFF) && (base & 0xFFFFFFFF) < filesize && filesize <= 0xFFFFFFFF)
+ base &= 0xFFFFFFFF;
+ else
+ return -1;
+ }
+
+ for(i=0; i<entries_in_use; i++){
+ if(index_type){
+ int64_t pos= get_le32(pb) + base - 8;
+ int len = get_le32(pb);
+ int key= len >= 0;
+ len &= 0x7FFFFFFF;
+
+#ifdef DEBUG_SEEK
+ av_log(s, AV_LOG_ERROR, "pos:%"PRId64", len:%X\n", pos, len);
+#endif
+ if(last_pos == pos || pos == base - 8)
+ avi->non_interleaved= 1;
+ else
+ av_add_index_entry(st, pos, ast->cum_len / FFMAX(1, ast->sample_size), len, 0, key ? AVINDEX_KEYFRAME : 0);
+
+ if(ast->sample_size)
+ ast->cum_len += len;
+ else
+ ast->cum_len ++;
+ last_pos= pos;
+ }else{
+ int64_t offset, pos;
+ int duration;
+ offset = get_le64(pb);
+ get_le32(pb); /* size */
+ duration = get_le32(pb);
+ pos = url_ftell(pb);
+
+ url_fseek(pb, offset+8, SEEK_SET);
+ read_braindead_odml_indx(s, frame_num);
+ frame_num += duration;
+
+ url_fseek(pb, pos, SEEK_SET);
+ }
+ }
+ avi->index_loaded=1;
+ return 0;
+}
+
+static void clean_index(AVFormatContext *s){
+ int i;
+ int64_t j;
+
+ for(i=0; i<s->nb_streams; i++){
+ AVStream *st = s->streams[i];
+ AVIStream *ast = st->priv_data;
+ int n= st->nb_index_entries;
+ int max= ast->sample_size;
+ int64_t pos, size, ts;
+
+ if(n != 1 || ast->sample_size==0)
+ continue;
+
+ while(max < 1024) max+=max;
+
+ pos= st->index_entries[0].pos;
+ size= st->index_entries[0].size;
+ ts= st->index_entries[0].timestamp;
+
+ for(j=0; j<size; j+=max){
+ av_add_index_entry(st, pos+j, ts + j/ast->sample_size, FFMIN(max, size-j), 0, AVINDEX_KEYFRAME);
+ }
+ }
+}
+
+static int avi_read_tag(ByteIOContext *pb, char *buf, int maxlen, unsigned int size)
+{
+ offset_t i = url_ftell(pb);
+ size += (size & 1);
+ get_strz(pb, buf, maxlen);
+ url_fseek(pb, i+size, SEEK_SET);
+ return 0;
+}
+
+static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+ AVIContext *avi = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ uint32_t tag, tag1, handler;
+ int codec_type, stream_index, frame_period, bit_rate;
+ unsigned int size, nb_frames;
+ int i;
+ AVStream *st;
+ AVIStream *ast = NULL;
+ char str_track[4];
+
+ avi->stream_index= -1;
+
+ if (get_riff(avi, pb) < 0)
+ return -1;
+
+ /* first list tag */
+ stream_index = -1;
+ codec_type = -1;
+ frame_period = 0;
+ for(;;) {
+ if (url_feof(pb))
+ goto fail;
+ tag = get_le32(pb);
+ size = get_le32(pb);
+#ifdef DEBUG
+ print_tag("tag", tag, size);
+#endif
+
+ switch(tag) {
+ case MKTAG('L', 'I', 'S', 'T'):
+ /* ignored, except when start of video packets */
+ tag1 = get_le32(pb);
+#ifdef DEBUG
+ print_tag("list", tag1, 0);
+#endif
+ if (tag1 == MKTAG('m', 'o', 'v', 'i')) {
+ avi->movi_list = url_ftell(pb) - 4;
+ if(size) avi->movi_end = avi->movi_list + size + (size & 1);
+ else avi->movi_end = url_fsize(pb);
+#ifdef DEBUG
+ printf("movi end=%"PRIx64"\n", avi->movi_end);
+#endif
+ goto end_of_header;
+ }
+ break;
+ case MKTAG('d', 'm', 'l', 'h'):
+ avi->is_odml = 1;
+ url_fskip(pb, size + (size & 1));
+ break;
+ case MKTAG('a', 'v', 'i', 'h'):
+ /* avi header */
+ /* using frame_period is bad idea */
+ frame_period = get_le32(pb);
+ bit_rate = get_le32(pb) * 8;
+ get_le32(pb);
+ avi->non_interleaved |= get_le32(pb) & AVIF_MUSTUSEINDEX;
+
+ url_fskip(pb, 2 * 4);
+ get_le32(pb);
+
+ url_fskip(pb, size - 7 * 4);
+ break;
+ case MKTAG('s', 't', 'r', 'h'):
+ /* stream header */
+
+ tag1 = get_le32(pb);
+ handler = get_le32(pb); /* codec tag */
+
+ if(tag1 == MKTAG('p', 'a', 'd', 's')){
+ url_fskip(pb, size - 8);
+ break;
+ }else{
+ stream_index++;
+ st = av_new_stream(s, stream_index);
+ if (!st)
+ goto fail;
+
+ ast = av_mallocz(sizeof(AVIStream));
+ if (!ast)
+ goto fail;
+ st->priv_data = ast;
+ }
+
+#ifdef DEBUG
+ print_tag("strh", tag1, -1);
+#endif
+ if(tag1 == MKTAG('i', 'a', 'v', 's') || tag1 == MKTAG('i', 'v', 'a', 's')){
+ int64_t dv_dur;
+
+ /*
+ * After some consideration -- I don't think we
+ * have to support anything but DV in a type1 AVIs.
+ */
+ if (s->nb_streams != 1)
+ goto fail;
+
+ if (handler != MKTAG('d', 'v', 's', 'd') &&
+ handler != MKTAG('d', 'v', 'h', 'd') &&
+ handler != MKTAG('d', 'v', 's', 'l'))
+ goto fail;
+
+ ast = s->streams[0]->priv_data;
+ av_freep(&s->streams[0]->codec->extradata);
+ av_freep(&s->streams[0]);
+ s->nb_streams = 0;
+ if (ENABLE_DV_DEMUXER) {
+ avi->dv_demux = dv_init_demux(s);
+ if (!avi->dv_demux)
+ goto fail;
+ }
+ s->streams[0]->priv_data = ast;
+ url_fskip(pb, 3 * 4);
+ ast->scale = get_le32(pb);
+ ast->rate = get_le32(pb);
+ url_fskip(pb, 4); /* start time */
+
+ dv_dur = get_le32(pb);
+ if (ast->scale > 0 && ast->rate > 0 && dv_dur > 0) {
+ dv_dur *= AV_TIME_BASE;
+ s->duration = av_rescale(dv_dur, ast->scale, ast->rate);
+ }
+ /*
+ * else, leave duration alone; timing estimation in utils.c
+ * will make a guess based on bit rate.
+ */
+
+ stream_index = s->nb_streams - 1;
+ url_fskip(pb, size - 9*4);
+ break;
+ }
+
+ assert(stream_index < s->nb_streams);
+ st->codec->stream_codec_tag= handler;
+
+ get_le32(pb); /* flags */
+ get_le16(pb); /* priority */
+ get_le16(pb); /* language */
+ get_le32(pb); /* initial frame */
+ ast->scale = get_le32(pb);
+ ast->rate = get_le32(pb);
+ if(ast->scale && ast->rate){
+ }else if(frame_period){
+ ast->rate = 1000000;
+ ast->scale = frame_period;
+ }else{
+ ast->rate = 25;
+ ast->scale = 1;
+ }
+ av_set_pts_info(st, 64, ast->scale, ast->rate);
+
+ ast->cum_len=get_le32(pb); /* start */
+ 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 */
+ ast->cum_len *= FFMAX(1, ast->sample_size);
+// av_log(NULL, AV_LOG_DEBUG, "%d %d %d %d\n", ast->rate, ast->scale, ast->start, ast->sample_size);
+
+ switch(tag1) {
+ case MKTAG('v', 'i', 'd', 's'):
+ codec_type = CODEC_TYPE_VIDEO;
+
+ ast->sample_size = 0;
+ break;
+ case MKTAG('a', 'u', 'd', 's'):
+ codec_type = CODEC_TYPE_AUDIO;
+ break;
+ case MKTAG('t', 'x', 't', 's'):
+ //FIXME
+ codec_type = CODEC_TYPE_DATA; //CODEC_TYPE_SUB ? FIXME
+ break;
+ default:
+ av_log(s, AV_LOG_ERROR, "unknown stream type %X\n", tag1);
+ goto fail;
+ }
+ ast->frame_offset= ast->cum_len;
+ url_fskip(pb, size - 12 * 4);
+ break;
+ case MKTAG('s', 't', 'r', 'f'):
+ /* stream header */
+ if (stream_index >= (unsigned)s->nb_streams || avi->dv_demux) {
+ url_fskip(pb, size);
+ } else {
+ st = s->streams[stream_index];
+ switch(codec_type) {
+ case CODEC_TYPE_VIDEO:
+ get_le32(pb); /* size */
+ st->codec->width = get_le32(pb);
+ st->codec->height = get_le32(pb);
+ get_le16(pb); /* panes */
+ st->codec->bits_per_sample= get_le16(pb); /* depth */
+ tag1 = get_le32(pb);
+ get_le32(pb); /* ImageSize */
+ get_le32(pb); /* XPelsPerMeter */
+ get_le32(pb); /* YPelsPerMeter */
+ get_le32(pb); /* ClrUsed */
+ get_le32(pb); /* ClrImportant */
+
+ if(size > 10*4 && size<(1<<30)){
+ st->codec->extradata_size= size - 10*4;
+ st->codec->extradata= av_malloc(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ get_buffer(pb, st->codec->extradata, st->codec->extradata_size);
+ }
+
+ if(st->codec->extradata_size & 1) //FIXME check if the encoder really did this correctly
+ get_byte(pb);
+
+ /* Extract palette from extradata if bpp <= 8 */
+ /* This code assumes that extradata contains only palette */
+ /* This is true for all paletted codecs implemented in ffmpeg */
+ if (st->codec->extradata_size && (st->codec->bits_per_sample <= 8)) {
+ st->codec->palctrl = av_mallocz(sizeof(AVPaletteControl));
+#ifdef WORDS_BIGENDIAN
+ for (i = 0; i < FFMIN(st->codec->extradata_size, AVPALETTE_SIZE)/4; i++)
+ st->codec->palctrl->palette[i] = bswap_32(((uint32_t*)st->codec->extradata)[i]);
+#else
+ memcpy(st->codec->palctrl->palette, st->codec->extradata,
+ FFMIN(st->codec->extradata_size, AVPALETTE_SIZE));
+#endif
+ st->codec->palctrl->palette_changed = 1;
+ }
+
+#ifdef DEBUG
+ print_tag("video", tag1, 0);
+#endif
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ st->codec->codec_tag = tag1;
+ st->codec->codec_id = codec_get_id(codec_bmp_tags, tag1);
+ st->need_parsing = 2; //only parse headers dont do slower repacketization, this is needed to get the pict type which is needed for generating correct pts
+// url_fskip(pb, size - 5 * 4);
+ break;
+ case CODEC_TYPE_AUDIO:
+ 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_DEBUG, "invalid sample size or block align detected\n");
+ if (size%2) /* 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. */
+ st->need_parsing = 1;
+ /* ADTS header is in extradata, AAC without header must be stored as exact frames, parser not needed and it will fail */
+ if (st->codec->codec_id == CODEC_ID_AAC && st->codec->extradata_size)
+ st->need_parsing = 0;
+ /* AVI files with Xan DPCM audio (wrongly) declare PCM
+ * audio in the header but have Axan as stream_code_tag. */
+ if (st->codec->stream_codec_tag == ff_get_fourcc("Axan")){
+ st->codec->codec_id = CODEC_ID_XAN_DPCM;
+ st->codec->codec_tag = 0;
+ }
+ break;
+ default:
+ st->codec->codec_type = CODEC_TYPE_DATA;
+ st->codec->codec_id= CODEC_ID_NONE;
+ st->codec->codec_tag= 0;
+ url_fskip(pb, size);
+ break;
+ }
+ }
+ break;
+ case MKTAG('i', 'n', 'd', 'x'):
+ i= url_ftell(pb);
+ if(!url_is_streamed(pb) && !(s->flags & AVFMT_FLAG_IGNIDX)){
+ read_braindead_odml_indx(s, 0);
+ }
+ url_fseek(pb, i+size, SEEK_SET);
+ break;
+ case MKTAG('I', 'N', 'A', 'M'):
+ avi_read_tag(pb, s->title, sizeof(s->title), size);
+ break;
+ case MKTAG('I', 'A', 'R', 'T'):
+ avi_read_tag(pb, s->author, sizeof(s->author), size);
+ break;
+ case MKTAG('I', 'C', 'O', 'P'):
+ avi_read_tag(pb, s->copyright, sizeof(s->copyright), size);
+ break;
+ case MKTAG('I', 'C', 'M', 'T'):
+ avi_read_tag(pb, s->comment, sizeof(s->comment), size);
+ break;
+ case MKTAG('I', 'G', 'N', 'R'):
+ avi_read_tag(pb, s->genre, sizeof(s->genre), size);
+ break;
+ case MKTAG('I', 'P', 'R', 'D'):
+ avi_read_tag(pb, s->album, sizeof(s->album), size);
+ break;
+ case MKTAG('I', 'P', 'R', 'T'):
+ avi_read_tag(pb, str_track, sizeof(str_track), size);
+ sscanf(str_track, "%d", &s->track);
+ break;
+ default:
+ if(size > 1000000){
+ av_log(s, AV_LOG_ERROR, "well something went wrong during header parsing, "
+ "ill ignore it and try to continue anyway\n");
+ avi->movi_list = url_ftell(pb) - 4;
+ avi->movi_end = url_fsize(pb);
+ goto end_of_header;
+ }
+ /* skip tag */
+ size += (size & 1);
+ url_fskip(pb, size);
+ break;
+ }
+ }
+ end_of_header:
+ /* check stream number */
+ if (stream_index != s->nb_streams - 1) {
+ fail:
+ for(i=0;i<s->nb_streams;i++) {
+ av_freep(&s->streams[i]->codec->extradata);
+ av_freep(&s->streams[i]);
+ }
+ return -1;
+ }
+
+ if(!avi->index_loaded && !url_is_streamed(pb))
+ avi_load_index(s);
+ avi->index_loaded = 1;
+ avi->non_interleaved |= guess_ni_flag(s);
+ if(avi->non_interleaved)
+ clean_index(s);
+
+ return 0;
+}
+
+static int avi_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ AVIContext *avi = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ int n, d[8], size;
+ offset_t i, sync;
+ void* dstr;
+
+ if (ENABLE_DV_DEMUXER && avi->dv_demux) {
+ size = dv_get_packet(avi->dv_demux, pkt);
+ if (size >= 0)
+ return size;
+ }
+
+ if(avi->non_interleaved){
+ int best_stream_index = 0;
+ AVStream *best_st= NULL;
+ AVIStream *best_ast;
+ int64_t best_ts= INT64_MAX;
+ int i;
+
+ for(i=0; i<s->nb_streams; i++){
+ AVStream *st = s->streams[i];
+ AVIStream *ast = st->priv_data;
+ int64_t ts= ast->frame_offset;
+
+ if(ast->sample_size)
+ ts /= ast->sample_size;
+ ts= av_rescale(ts, AV_TIME_BASE * (int64_t)st->time_base.num, st->time_base.den);
+
+// av_log(NULL, AV_LOG_DEBUG, "%"PRId64" %d/%d %"PRId64"\n", ts, st->time_base.num, st->time_base.den, ast->frame_offset);
+ if(ts < best_ts){
+ best_ts= ts;
+ best_st= st;
+ best_stream_index= i;
+ }
+ }
+ best_ast = best_st->priv_data;
+ best_ts= av_rescale(best_ts, best_st->time_base.den, AV_TIME_BASE * (int64_t)best_st->time_base.num); //FIXME a little ugly
+ 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);
+
+// av_log(NULL, AV_LOG_DEBUG, "%d\n", i);
+ if(i>=0){
+ int64_t pos= best_st->index_entries[i].pos;
+ pos += best_ast->packet_size - best_ast->remaining;
+ url_fseek(&s->pb, pos + 8, SEEK_SET);
+// av_log(NULL, AV_LOG_DEBUG, "pos=%"PRId64"\n", pos);
+
+ assert(best_ast->remaining <= best_ast->packet_size);
+
+ avi->stream_index= best_stream_index;
+ if(!best_ast->remaining)
+ best_ast->packet_size=
+ best_ast->remaining= best_st->index_entries[i].size;
+ }
+ }
+
+resync:
+ if(avi->stream_index >= 0){
+ AVStream *st= s->streams[ avi->stream_index ];
+ AVIStream *ast= st->priv_data;
+ int size;
+
+ 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;
+ else
+ size= ast->sample_size;
+
+ if(size > ast->remaining)
+ size= ast->remaining;
+ av_get_packet(pb, pkt, size);
+
+ if (ENABLE_DV_DEMUXER && avi->dv_demux) {
+ dstr = pkt->destruct;
+ size = dv_produce_packet(avi->dv_demux, pkt,
+ pkt->data, pkt->size);
+ pkt->destruct = dstr;
+ pkt->flags |= PKT_FLAG_KEY;
+ } else {
+ /* XXX: how to handle B frames in avi ? */
+ pkt->dts = ast->frame_offset;
+// pkt->dts += ast->start;
+ if(ast->sample_size)
+ pkt->dts /= ast->sample_size;
+//av_log(NULL, 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) {
+ AVIndexEntry *e;
+ int index;
+ assert(st->index_entries);
+
+ index= av_index_search_timestamp(st, pkt->dts, 0);
+ e= &st->index_entries[index];
+
+ if(index >= 0 && e->timestamp == ast->frame_offset){
+ if (e->flags & AVINDEX_KEYFRAME)
+ pkt->flags |= PKT_FLAG_KEY;
+ }
+ } else {
+ pkt->flags |= PKT_FLAG_KEY;
+ }
+ if(ast->sample_size)
+ ast->frame_offset += pkt->size;
+ else
+ ast->frame_offset++;
+ }
+ ast->remaining -= size;
+ if(!ast->remaining){
+ avi->stream_index= -1;
+ ast->packet_size= 0;
+ }
+
+ return size;
+ }
+
+ memset(d, -1, sizeof(int)*8);
+ for(i=sync=url_ftell(pb); !url_feof(pb); i++) {
+ int j;
+
+ if (i >= avi->movi_end) {
+ if (avi->is_odml) {
+ url_fskip(pb, avi->riff_end - i);
+ avi->riff_end = avi->movi_end = url_fsize(pb);
+ } else
+ break;
+ }
+
+ for(j=0; j<7; j++)
+ d[j]= d[j+1];
+ d[7]= get_byte(pb);
+
+ size= d[4] + (d[5]<<8) + (d[6]<<16) + (d[7]<<24);
+
+ if( d[2] >= '0' && d[2] <= '9'
+ && d[3] >= '0' && d[3] <= '9'){
+ n= (d[2] - '0') * 10 + (d[3] - '0');
+ }else{
+ n= 100; //invalid stream id
+ }
+//av_log(NULL, AV_LOG_DEBUG, "%X %X %X %X %X %X %X %X %"PRId64" %d %d\n", d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], i, size, n);
+ if(i + size > avi->movi_end || d[0]<0)
+ continue;
+
+ //parse ix##
+ if( (d[0] == 'i' && d[1] == 'x' && n < s->nb_streams)
+ //parse JUNK
+ ||(d[0] == 'J' && d[1] == 'U' && d[2] == 'N' && d[3] == 'K')){
+ url_fskip(pb, size);
+//av_log(NULL, AV_LOG_DEBUG, "SKIP\n");
+ goto resync;
+ }
+
+ if( d[0] >= '0' && d[0] <= '9'
+ && d[1] >= '0' && d[1] <= '9'){
+ n= (d[0] - '0') * 10 + (d[1] - '0');
+ }else{
+ n= 100; //invalid stream id
+ }
+
+ //parse ##dc/##wb
+ if(n < s->nb_streams){
+ AVStream *st;
+ AVIStream *ast;
+ st = s->streams[n];
+ ast = st->priv_data;
+
+ if( (st->discard >= AVDISCARD_DEFAULT && size==0)
+ /*|| (st->discard >= AVDISCARD_NONKEY && !(pkt->flags & PKT_FLAG_KEY))*/ //FIXME needs a little reordering
+ || st->discard >= AVDISCARD_ALL){
+ if(ast->sample_size) ast->frame_offset += pkt->size;
+ else ast->frame_offset++;
+ url_fskip(pb, size);
+ goto resync;
+ }
+
+ if( ((ast->prefix_count<5 || sync+9 > i) && d[2]<128 && d[3]<128) ||
+ d[2]*256+d[3] == ast->prefix /*||
+ (d[2] == 'd' && d[3] == 'c') ||
+ (d[2] == 'w' && d[3] == 'b')*/) {
+
+//av_log(NULL, AV_LOG_DEBUG, "OK\n");
+ if(d[2]*256+d[3] == ast->prefix)
+ ast->prefix_count++;
+ else{
+ ast->prefix= d[2]*256+d[3];
+ ast->prefix_count= 0;
+ }
+
+ avi->stream_index= n;
+ ast->packet_size= size + 8;
+ ast->remaining= 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);
+ }
+ }
+ goto resync;
+ }
+ }
+ /* palette changed chunk */
+ if ( d[0] >= '0' && d[0] <= '9'
+ && d[1] >= '0' && d[1] <= '9'
+ && ((d[2] == 'p' && d[3] == 'c'))
+ && n < s->nb_streams && i + size <= avi->movi_end) {
+
+ AVStream *st;
+ int first, clr, flags, k, p;
+
+ st = s->streams[n];
+
+ first = get_byte(pb);
+ clr = get_byte(pb);
+ if(!clr) /* all 256 colors used */
+ clr = 256;
+ flags = get_le16(pb);
+ p = 4;
+ for (k = first; k < clr + first; k++) {
+ int r, g, b;
+ r = get_byte(pb);
+ g = get_byte(pb);
+ b = get_byte(pb);
+ get_byte(pb);
+ st->codec->palctrl->palette[k] = b + (g << 8) + (r << 16);
+ }
+ st->codec->palctrl->palette_changed = 1;
+ goto resync;
+ }
+
+ }
+
+ return -1;
+}
+
+/* XXX: we make the implicit supposition that the position are sorted
+ for each stream */
+static int avi_read_idx1(AVFormatContext *s, int size)
+{
+ AVIContext *avi = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ int nb_index_entries, i;
+ AVStream *st;
+ AVIStream *ast;
+ unsigned int index, tag, flags, pos, len;
+ unsigned last_pos= -1;
+
+ nb_index_entries = size / 16;
+ if (nb_index_entries <= 0)
+ return -1;
+
+ /* read the entries and sort them in each stream component */
+ for(i = 0; i < nb_index_entries; i++) {
+ tag = get_le32(pb);
+ flags = get_le32(pb);
+ pos = get_le32(pb);
+ len = get_le32(pb);
+#if defined(DEBUG_SEEK)
+ av_log(NULL, AV_LOG_DEBUG, "%d: tag=0x%x flags=0x%x pos=0x%x len=%d/",
+ i, tag, flags, pos, len);
+#endif
+ if(i==0 && pos > avi->movi_list)
+ avi->movi_list= 0; //FIXME better check
+ pos += avi->movi_list;
+
+ index = ((tag & 0xff) - '0') * 10;
+ index += ((tag >> 8) & 0xff) - '0';
+ if (index >= s->nb_streams)
+ continue;
+ st = s->streams[index];
+ ast = st->priv_data;
+
+#if defined(DEBUG_SEEK)
+ av_log(NULL, AV_LOG_DEBUG, "%d cum_len=%"PRId64"\n", len, ast->cum_len);
+#endif
+ 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);
+ if(ast->sample_size)
+ ast->cum_len += len;
+ else
+ ast->cum_len ++;
+ last_pos= pos;
+ }
+ return 0;
+}
+
+static int guess_ni_flag(AVFormatContext *s){
+ int i;
+ int64_t last_start=0;
+ int64_t first_end= INT64_MAX;
+
+ for(i=0; i<s->nb_streams; i++){
+ AVStream *st = s->streams[i];
+ int n= st->nb_index_entries;
+
+ if(n <= 0)
+ continue;
+
+ if(st->index_entries[0].pos > last_start)
+ last_start= st->index_entries[0].pos;
+ if(st->index_entries[n-1].pos < first_end)
+ first_end= st->index_entries[n-1].pos;
+ }
+ return last_start > first_end;
+}
+
+static int avi_load_index(AVFormatContext *s)
+{
+ AVIContext *avi = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ uint32_t tag, size;
+ offset_t pos= url_ftell(pb);
+
+ url_fseek(pb, avi->movi_end, SEEK_SET);
+#ifdef DEBUG_SEEK
+ printf("movi_end=0x%"PRIx64"\n", avi->movi_end);
+#endif
+ for(;;) {
+ if (url_feof(pb))
+ break;
+ tag = get_le32(pb);
+ size = get_le32(pb);
+#ifdef DEBUG_SEEK
+ printf("tag=%c%c%c%c size=0x%x\n",
+ tag & 0xff,
+ (tag >> 8) & 0xff,
+ (tag >> 16) & 0xff,
+ (tag >> 24) & 0xff,
+ size);
+#endif
+ switch(tag) {
+ case MKTAG('i', 'd', 'x', '1'):
+ if (avi_read_idx1(s, size) < 0)
+ goto skip;
+ else
+ goto the_end;
+ break;
+ default:
+ skip:
+ size += (size & 1);
+ url_fskip(pb, size);
+ break;
+ }
+ }
+ the_end:
+ url_fseek(pb, pos, SEEK_SET);
+ return 0;
+}
+
+static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
+{
+ AVIContext *avi = s->priv_data;
+ AVStream *st;
+ int i, index;
+ int64_t pos;
+
+ if (!avi->index_loaded) {
+ /* we only load the index on demand */
+ avi_load_index(s);
+ avi->index_loaded = 1;
+ }
+ assert(stream_index>= 0);
+
+ st = s->streams[stream_index];
+ index= av_index_search_timestamp(st, timestamp, flags);
+ if(index<0)
+ return -1;
+
+ /* find the position */
+ pos = st->index_entries[index].pos;
+ timestamp = st->index_entries[index].timestamp;
+
+// av_log(NULL, AV_LOG_DEBUG, "XX %"PRId64" %d %"PRId64"\n", timestamp, index, st->index_entries[index].timestamp);
+
+ if (ENABLE_DV_DEMUXER && avi->dv_demux) {
+ /* One and only one real stream for DV in AVI, and it has video */
+ /* offsets. Calling with other stream indices should have failed */
+ /* the av_index_search_timestamp call above. */
+ assert(stream_index == 0);
+
+ /* Feed the DV video stream version of the timestamp to the */
+ /* DV demux so it can synth correct timestamps */
+ dv_offset_reset(avi->dv_demux, timestamp);
+
+ url_fseek(&s->pb, pos, SEEK_SET);
+ avi->stream_index= -1;
+ return 0;
+ }
+
+ for(i = 0; i < s->nb_streams; i++) {
+ AVStream *st2 = s->streams[i];
+ AVIStream *ast2 = st2->priv_data;
+
+ ast2->packet_size=
+ ast2->remaining= 0;
+
+ if (st2->nb_index_entries <= 0)
+ continue;
+
+// assert(st2->codec->block_align);
+ assert(st2->time_base.den == ast2->rate);
+ assert(st2->time_base.num == ast2->scale);
+ index = av_index_search_timestamp(
+ st2,
+ av_rescale(timestamp, st2->time_base.den*(int64_t)st->time_base.num, st->time_base.den * (int64_t)st2->time_base.num),
+ flags | AVSEEK_FLAG_BACKWARD);
+ if(index<0)
+ index=0;
+
+ if(!avi->non_interleaved){
+ while(index>0 && st2->index_entries[index].pos > pos)
+ index--;
+ while(index+1 < st2->nb_index_entries && st2->index_entries[index].pos < pos)
+ index++;
+ }
+
+// av_log(NULL, 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 */
+ url_fseek(&s->pb, pos, SEEK_SET);
+ avi->stream_index= -1;
+ return 0;
+}
+
+static int avi_read_close(AVFormatContext *s)
+{
+ int i;
+ AVIContext *avi = s->priv_data;
+
+ for(i=0;i<s->nb_streams;i++) {
+ AVStream *st = s->streams[i];
+ AVIStream *ast = st->priv_data;
+ av_free(ast);
+ av_free(st->codec->palctrl);
+ }
+
+ if (avi->dv_demux)
+ av_free(avi->dv_demux);
+
+ return 0;
+}
+
+static int avi_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] == 'A' && p->buf[9] == 'V' &&
+ p->buf[10] == 'I' && (p->buf[11] == ' ' || p->buf[11] == 0x19))
+ return AVPROBE_SCORE_MAX;
+ else
+ return 0;
+}
+
+AVInputFormat avi_demuxer = {
+ "avi",
+ "avi format",
+ sizeof(AVIContext),
+ avi_probe,
+ avi_read_header,
+ avi_read_packet,
+ avi_read_close,
+ avi_read_seek,
+};
diff --git a/contrib/ffmpeg/libavformat/avienc.c b/contrib/ffmpeg/libavformat/avienc.c
new file mode 100644
index 000000000..ac8b2670d
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/avienc.c
@@ -0,0 +1,580 @@
+/*
+ * AVI muxer
+ * Copyright (c) 2000 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 "avformat.h"
+#include "avi.h"
+#include "riff.h"
+
+/*
+ * TODO:
+ * - fill all fields if non streamed (nb_frames for example)
+ */
+
+#ifdef CONFIG_AVI_MUXER
+typedef struct AVIIentry {
+ unsigned int flags, pos, len;
+} AVIIentry;
+
+#define AVI_INDEX_CLUSTER_SIZE 16384
+
+typedef struct AVIIndex {
+ offset_t indx_start;
+ int entry;
+ int ents_allocated;
+ AVIIentry** cluster;
+} AVIIndex;
+
+typedef struct {
+ offset_t riff_start, movi_list, odml_list;
+ offset_t frames_hdr_all, frames_hdr_strm[MAX_STREAMS];
+ int audio_strm_length[MAX_STREAMS];
+ int riff_id;
+ int packet_count[MAX_STREAMS];
+
+ AVIIndex indexes[MAX_STREAMS];
+} AVIContext;
+
+static inline AVIIentry* avi_get_ientry(AVIIndex* idx, int ent_id)
+{
+ int cl = ent_id / AVI_INDEX_CLUSTER_SIZE;
+ int id = ent_id % AVI_INDEX_CLUSTER_SIZE;
+ return &idx->cluster[cl][id];
+}
+
+static offset_t avi_start_new_riff(AVIContext *avi, ByteIOContext *pb,
+ const char* riff_tag, const char* list_tag)
+{
+ offset_t loff;
+ int i;
+
+ avi->riff_id++;
+ for (i=0; i<MAX_STREAMS; i++)
+ avi->indexes[i].entry = 0;
+
+ avi->riff_start = start_tag(pb, "RIFF");
+ put_tag(pb, riff_tag);
+ loff = start_tag(pb, "LIST");
+ put_tag(pb, list_tag);
+ return loff;
+}
+
+static char* avi_stream2fourcc(char* tag, int index, enum CodecType type)
+{
+ tag[0] = '0';
+ tag[1] = '0' + index;
+ if (type == CODEC_TYPE_VIDEO) {
+ tag[2] = 'd';
+ tag[3] = 'c';
+ } else {
+ tag[2] = 'w';
+ tag[3] = 'b';
+ }
+ tag[4] = '\0';
+ return tag;
+}
+
+static void avi_write_info_tag(ByteIOContext *pb, const char *tag, const char *str)
+{
+ int len = strlen(str);
+ if (len > 0) {
+ len++;
+ put_tag(pb, tag);
+ put_le32(pb, len);
+ put_strz(pb, str);
+ if (len & 1)
+ put_byte(pb, 0);
+ }
+}
+
+static int avi_write_counters(AVFormatContext* s, int riff_id)
+{
+ ByteIOContext *pb = &s->pb;
+ AVIContext *avi = s->priv_data;
+ int n, au_byterate, au_ssize, au_scale, nb_frames = 0;
+ offset_t file_size;
+ AVCodecContext* stream;
+
+ file_size = url_ftell(pb);
+ for(n = 0; n < s->nb_streams; n++) {
+ assert(avi->frames_hdr_strm[n]);
+ stream = s->streams[n]->codec;
+ url_fseek(pb, avi->frames_hdr_strm[n], SEEK_SET);
+ ff_parse_specific_params(stream, &au_byterate, &au_ssize, &au_scale);
+ if(au_ssize == 0) {
+ put_le32(pb, avi->packet_count[n]);
+ } else {
+ put_le32(pb, avi->audio_strm_length[n] / au_ssize);
+ }
+ if(stream->codec_type == CODEC_TYPE_VIDEO)
+ nb_frames = FFMAX(nb_frames, avi->packet_count[n]);
+ }
+ if(riff_id == 1) {
+ assert(avi->frames_hdr_all);
+ url_fseek(pb, avi->frames_hdr_all, SEEK_SET);
+ put_le32(pb, nb_frames);
+ }
+ url_fseek(pb, file_size, SEEK_SET);
+
+ return 0;
+}
+
+static int avi_write_header(AVFormatContext *s)
+{
+ AVIContext *avi = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ int bitrate, n, i, nb_frames, au_byterate, au_ssize, au_scale;
+ AVCodecContext *stream, *video_enc;
+ offset_t list1, list2, strh, strf;
+
+ /* header list */
+ avi->riff_id = 0;
+ list1 = avi_start_new_riff(avi, pb, "AVI ", "hdrl");
+
+ /* avi header */
+ put_tag(pb, "avih");
+ put_le32(pb, 14 * 4);
+ bitrate = 0;
+
+ video_enc = NULL;
+ for(n=0;n<s->nb_streams;n++) {
+ stream = s->streams[n]->codec;
+ bitrate += stream->bit_rate;
+ if (stream->codec_type == CODEC_TYPE_VIDEO)
+ video_enc = stream;
+ }
+
+ nb_frames = 0;
+
+ if(video_enc){
+ put_le32(pb, (uint32_t)(INT64_C(1000000) * video_enc->time_base.num / video_enc->time_base.den));
+ } else {
+ put_le32(pb, 0);
+ }
+ put_le32(pb, bitrate / 8); /* XXX: not quite exact */
+ put_le32(pb, 0); /* padding */
+ if (url_is_streamed(pb))
+ put_le32(pb, AVIF_TRUSTCKTYPE | AVIF_ISINTERLEAVED); /* flags */
+ else
+ put_le32(pb, AVIF_TRUSTCKTYPE | AVIF_HASINDEX | AVIF_ISINTERLEAVED); /* flags */
+ avi->frames_hdr_all = url_ftell(pb); /* remember this offset to fill later */
+ put_le32(pb, nb_frames); /* nb frames, filled later */
+ put_le32(pb, 0); /* initial frame */
+ put_le32(pb, s->nb_streams); /* nb streams */
+ put_le32(pb, 1024 * 1024); /* suggested buffer size */
+ if(video_enc){
+ put_le32(pb, video_enc->width);
+ put_le32(pb, video_enc->height);
+ } else {
+ put_le32(pb, 0);
+ put_le32(pb, 0);
+ }
+ put_le32(pb, 0); /* reserved */
+ put_le32(pb, 0); /* reserved */
+ put_le32(pb, 0); /* reserved */
+ put_le32(pb, 0); /* reserved */
+
+ /* stream list */
+ for(i=0;i<n;i++) {
+ list2 = start_tag(pb, "LIST");
+ put_tag(pb, "strl");
+
+ stream = s->streams[i]->codec;
+
+ /* FourCC should really be set by the codec itself */
+ if (! stream->codec_tag) {
+ stream->codec_tag = codec_get_bmp_tag(stream->codec_id);
+ }
+
+ /* stream generic header */
+ strh = start_tag(pb, "strh");
+ switch(stream->codec_type) {
+ 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;
+ }
+ if(stream->codec_type == CODEC_TYPE_VIDEO)
+ put_le32(pb, stream->codec_tag);
+ else
+ put_le32(pb, 1);
+ put_le32(pb, 0); /* flags */
+ put_le16(pb, 0); /* priority */
+ put_le16(pb, 0); /* language */
+ put_le32(pb, 0); /* initial frame */
+
+ ff_parse_specific_params(stream, &au_byterate, &au_ssize, &au_scale);
+
+ put_le32(pb, au_scale); /* scale */
+ put_le32(pb, au_byterate); /* rate */
+ 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 */
+ 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)
+ put_le32(pb, 1024 * 1024);
+ else if(stream->codec_type == CODEC_TYPE_AUDIO)
+ put_le32(pb, 12 * 1024);
+ else
+ put_le32(pb, 0);
+ put_le32(pb, -1); /* quality */
+ put_le32(pb, au_ssize); /* sample size */
+ put_le32(pb, 0);
+ put_le16(pb, stream->width);
+ put_le16(pb, stream->height);
+ end_tag(pb, strh);
+
+ if(stream->codec_type != CODEC_TYPE_DATA){
+ strf = start_tag(pb, "strf");
+ switch(stream->codec_type) {
+ case CODEC_TYPE_VIDEO:
+ put_bmp_header(pb, stream, codec_bmp_tags, 0);
+ break;
+ case CODEC_TYPE_AUDIO:
+ if (put_wav_header(pb, stream) < 0) {
+ av_free(avi);
+ return -1;
+ }
+ break;
+ default:
+ return -1;
+ }
+ end_tag(pb, strf);
+ }
+
+ if (!url_is_streamed(pb)) {
+ unsigned char tag[5];
+ int j;
+
+ /* Starting to lay out AVI OpenDML master index.
+ * We want to make it JUNK entry for now, since we'd
+ * 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 = 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) */
+ put_le32(pb, 0); /* nEntriesInUse (will fill out later on) */
+ put_tag(pb, avi_stream2fourcc(&tag[0], i, stream->codec_type));
+ /* dwChunkId */
+ put_le64(pb, 0); /* dwReserved[3]
+ put_le32(pb, 0); Must be 0. */
+ for (j=0; j < AVI_MASTER_INDEX_SIZE * 2; j++)
+ put_le64(pb, 0);
+ end_tag(pb, avi->indexes[i].indx_start);
+ }
+
+ end_tag(pb, list2);
+ }
+
+ if (!url_is_streamed(pb)) {
+ /* AVI could become an OpenDML one, if it grows beyond 2Gb range */
+ avi->odml_list = start_tag(pb, "JUNK");
+ put_tag(pb, "odml");
+ put_tag(pb, "dmlh");
+ put_le32(pb, 248);
+ for (i = 0; i < 248; i+= 4)
+ put_le32(pb, 0);
+ end_tag(pb, avi->odml_list);
+ }
+
+ end_tag(pb, list1);
+
+ list2 = start_tag(pb, "LIST");
+ put_tag(pb, "INFO");
+ avi_write_info_tag(pb, "INAM", s->title);
+ avi_write_info_tag(pb, "IART", s->author);
+ avi_write_info_tag(pb, "ICOP", s->copyright);
+ avi_write_info_tag(pb, "ICMT", s->comment);
+ avi_write_info_tag(pb, "IPRD", s->album);
+ avi_write_info_tag(pb, "IGNR", s->genre);
+ if (s->track) {
+ char str_track[4];
+ snprintf(str_track, 4, "%d", s->track);
+ avi_write_info_tag(pb, "IPRT", str_track);
+ }
+ if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT))
+ avi_write_info_tag(pb, "ISFT", LIBAVFORMAT_IDENT);
+ end_tag(pb, list2);
+
+ /* some padding for easier tag editing */
+ list2 = start_tag(pb, "JUNK");
+ for (i = 0; i < 1016; i += 4)
+ put_le32(pb, 0);
+ end_tag(pb, list2);
+
+ avi->movi_list = start_tag(pb, "LIST");
+ put_tag(pb, "movi");
+
+ put_flush_packet(pb);
+
+ return 0;
+}
+
+static int avi_write_ix(AVFormatContext *s)
+{
+ ByteIOContext *pb = &s->pb;
+ AVIContext *avi = s->priv_data;
+ char tag[5];
+ char ix_tag[] = "ix00";
+ int i, j;
+
+ assert(!url_is_streamed(pb));
+
+ if (avi->riff_id > AVI_MASTER_INDEX_SIZE)
+ return -1;
+
+ for (i=0;i<s->nb_streams;i++) {
+ offset_t ix, pos;
+
+ avi_stream2fourcc(&tag[0], i, s->streams[i]->codec->codec_type);
+ ix_tag[3] = '0' + i;
+
+ /* 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);
+ /* 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);
+ /* 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; j<avi->indexes[i].entry; j++) {
+ AVIIentry* ie = avi_get_ientry(&avi->indexes[i], j);
+ put_le32(pb, ie->pos + 8);
+ put_le32(pb, ((uint32_t)ie->len & ~0x80000000) |
+ (ie->flags & 0x10 ? 0 : 0x80000000));
+ }
+ put_flush_packet(pb);
+ pos = url_ftell(pb);
+
+ /* Updating one entry in the AVI OpenDML master index */
+ url_fseek(pb, avi->indexes[i].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 */
+
+ url_fseek(pb, pos, SEEK_SET);
+ }
+ return 0;
+}
+
+static int avi_write_idx1(AVFormatContext *s)
+{
+ ByteIOContext *pb = &s->pb;
+ AVIContext *avi = s->priv_data;
+ offset_t idx_chunk;
+ int i;
+ char tag[5];
+
+ if (!url_is_streamed(pb)) {
+ AVIIentry* ie = 0, *tie;
+ int entry[MAX_STREAMS];
+ int empty, stream_id = -1;
+
+ idx_chunk = start_tag(pb, "idx1");
+ memset(&entry[0], 0, sizeof(entry));
+ do {
+ empty = 1;
+ for (i=0; i<s->nb_streams; i++) {
+ if (avi->indexes[i].entry <= entry[i])
+ continue;
+
+ tie = avi_get_ientry(&avi->indexes[i], entry[i]);
+ if (empty || tie->pos < ie->pos) {
+ ie = tie;
+ stream_id = i;
+ }
+ empty = 0;
+ }
+ if (!empty) {
+ 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]++;
+ }
+ } while (!empty);
+ end_tag(pb, idx_chunk);
+
+ avi_write_counters(s, avi->riff_id);
+ }
+ return 0;
+}
+
+static int avi_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ AVIContext *avi = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ unsigned char tag[5];
+ unsigned int flags=0;
+ const int stream_index= pkt->stream_index;
+ 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]){
+ AVPacket empty_packet;
+
+ av_init_packet(&empty_packet);
+ empty_packet.size= 0;
+ empty_packet.data= NULL;
+ empty_packet.stream_index= stream_index;
+ avi_write_packet(s, &empty_packet);
+// av_log(s, AV_LOG_DEBUG, "dup %"PRId64" %d\n", pkt->dts, avi->packet_count[stream_index]);
+ }
+ avi->packet_count[stream_index]++;
+
+ // Make sure to put an OpenDML chunk when the file size exceeds the limits
+ if (!url_is_streamed(pb) &&
+ (url_ftell(pb) - avi->riff_start > AVI_MAX_RIFF_SIZE)) {
+
+ avi_write_ix(s);
+ end_tag(pb, avi->movi_list);
+
+ if (avi->riff_id == 1)
+ avi_write_idx1(s);
+
+ end_tag(pb, avi->riff_start);
+ avi->movi_list = avi_start_new_riff(avi, pb, "AVIX", "movi");
+ }
+
+ avi_stream2fourcc(&tag[0], stream_index, enc->codec_type);
+ if(pkt->flags&PKT_FLAG_KEY)
+ flags = 0x10;
+ if (enc->codec_type == CODEC_TYPE_AUDIO) {
+ avi->audio_strm_length[stream_index] += size;
+ }
+
+ if (!url_is_streamed(&s->pb)) {
+ AVIIndex* idx = &avi->indexes[stream_index];
+ int cl = idx->entry / AVI_INDEX_CLUSTER_SIZE;
+ int id = idx->entry % AVI_INDEX_CLUSTER_SIZE;
+ if (idx->ents_allocated <= idx->entry) {
+ idx->cluster = av_realloc(idx->cluster, (cl+1)*sizeof(void*));
+ if (!idx->cluster)
+ return -1;
+ idx->cluster[cl] = av_malloc(AVI_INDEX_CLUSTER_SIZE*sizeof(AVIIentry));
+ if (!idx->cluster[cl])
+ return -1;
+ idx->ents_allocated += AVI_INDEX_CLUSTER_SIZE;
+ }
+
+ idx->cluster[cl][id].flags = flags;
+ idx->cluster[cl][id].pos = url_ftell(pb) - avi->movi_list;
+ idx->cluster[cl][id].len = size;
+ idx->entry++;
+ }
+
+ put_buffer(pb, tag, 4);
+ put_le32(pb, size);
+ put_buffer(pb, pkt->data, size);
+ if (size & 1)
+ put_byte(pb, 0);
+
+ put_flush_packet(pb);
+ return 0;
+}
+
+static int avi_write_trailer(AVFormatContext *s)
+{
+ AVIContext *avi = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ int res = 0;
+ int i, j, n, nb_frames;
+ offset_t file_size;
+
+ if (!url_is_streamed(pb)){
+ if (avi->riff_id == 1) {
+ end_tag(pb, avi->movi_list);
+ res = avi_write_idx1(s);
+ end_tag(pb, avi->riff_start);
+ } else {
+ avi_write_ix(s);
+ end_tag(pb, avi->movi_list);
+ end_tag(pb, avi->riff_start);
+
+ file_size = url_ftell(pb);
+ url_fseek(pb, avi->odml_list - 8, SEEK_SET);
+ put_tag(pb, "LIST"); /* Making this AVI OpenDML one */
+ url_fskip(pb, 16);
+
+ for (n=nb_frames=0;n<s->nb_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];
+ } else {
+ if (stream->codec_id == CODEC_ID_MP2 || stream->codec_id == CODEC_ID_MP3) {
+ nb_frames += avi->packet_count[n];
+ }
+ }
+ }
+ put_le32(pb, nb_frames);
+ url_fseek(pb, file_size, SEEK_SET);
+
+ avi_write_counters(s, avi->riff_id);
+ }
+ }
+ put_flush_packet(pb);
+
+ for (i=0; i<MAX_STREAMS; i++) {
+ for (j=0; j<avi->indexes[i].ents_allocated/AVI_INDEX_CLUSTER_SIZE; j++)
+ av_free(avi->indexes[i].cluster[j]);
+ av_free(avi->indexes[i].cluster);
+ avi->indexes[i].cluster = NULL;
+ avi->indexes[i].ents_allocated = avi->indexes[i].entry = 0;
+ }
+
+ return res;
+}
+
+AVOutputFormat avi_muxer = {
+ "avi",
+ "avi format",
+ "video/x-msvideo",
+ "avi",
+ sizeof(AVIContext),
+ CODEC_ID_MP2,
+ CODEC_ID_MPEG4,
+ avi_write_header,
+ avi_write_packet,
+ avi_write_trailer,
+ .codec_tag= (const AVCodecTag*[]){codec_bmp_tags, codec_wav_tags, 0},
+};
+#endif //CONFIG_AVI_MUXER
diff --git a/contrib/ffmpeg/libavformat/avio.c b/contrib/ffmpeg/libavformat/avio.c
new file mode 100644
index 000000000..a22bd22f3
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/avio.c
@@ -0,0 +1,186 @@
+/*
+ * Unbuffered io for ffmpeg system
+ * Copyright (c) 2001 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 "avformat.h"
+
+static int default_interrupt_cb(void);
+
+URLProtocol *first_protocol = NULL;
+URLInterruptCB *url_interrupt_cb = default_interrupt_cb;
+
+int register_protocol(URLProtocol *protocol)
+{
+ URLProtocol **p;
+ p = &first_protocol;
+ while (*p != NULL) p = &(*p)->next;
+ *p = protocol;
+ protocol->next = NULL;
+ return 0;
+}
+
+int url_open(URLContext **puc, const char *filename, int flags)
+{
+ URLContext *uc;
+ URLProtocol *up;
+ const char *p;
+ char proto_str[128], *q;
+ int err;
+
+ p = filename;
+ q = proto_str;
+ while (*p != '\0' && *p != ':') {
+ /* protocols can only contain alphabetic chars */
+ if (!isalpha(*p))
+ goto file_proto;
+ if ((q - proto_str) < sizeof(proto_str) - 1)
+ *q++ = *p;
+ p++;
+ }
+ /* if the protocol has length 1, we consider it is a dos drive */
+ if (*p == '\0' || (q - proto_str) <= 1) {
+ file_proto:
+ strcpy(proto_str, "file");
+ } else {
+ *q = '\0';
+ }
+
+ up = first_protocol;
+ while (up != NULL) {
+ if (!strcmp(proto_str, up->name))
+ goto found;
+ up = up->next;
+ }
+ err = AVERROR(ENOENT);
+ goto fail;
+ found:
+ uc = av_malloc(sizeof(URLContext) + strlen(filename) + 1);
+ if (!uc) {
+ err = AVERROR(ENOMEM);
+ goto fail;
+ }
+#if LIBAVFORMAT_VERSION_INT >= (52<<16)
+ uc->filename = (char *) &uc[1];
+#endif
+ strcpy(uc->filename, filename);
+ uc->prot = up;
+ uc->flags = flags;
+ uc->is_streamed = 0; /* default = not streamed */
+ uc->max_packet_size = 0; /* default: stream file */
+ err = up->url_open(uc, filename, flags);
+ if (err < 0) {
+ av_free(uc);
+ *puc = NULL;
+ return err;
+ }
+ *puc = uc;
+ return 0;
+ fail:
+ *puc = NULL;
+ return err;
+}
+
+int url_read(URLContext *h, unsigned char *buf, int size)
+{
+ int ret;
+ if (h->flags & URL_WRONLY)
+ return AVERROR_IO;
+ ret = h->prot->url_read(h, buf, size);
+ return ret;
+}
+
+#if defined(CONFIG_MUXERS) || defined(CONFIG_PROTOCOLS)
+int url_write(URLContext *h, unsigned char *buf, int size)
+{
+ int ret;
+ if (!(h->flags & (URL_WRONLY | URL_RDWR)))
+ return AVERROR_IO;
+ /* avoid sending too big packets */
+ if (h->max_packet_size && size > h->max_packet_size)
+ return AVERROR_IO;
+ ret = h->prot->url_write(h, buf, size);
+ return ret;
+}
+#endif //CONFIG_MUXERS || CONFIG_PROTOCOLS
+
+offset_t url_seek(URLContext *h, offset_t pos, int whence)
+{
+ offset_t ret;
+
+ if (!h->prot->url_seek)
+ return AVERROR(EPIPE);
+ ret = h->prot->url_seek(h, pos, whence);
+ return ret;
+}
+
+int url_close(URLContext *h)
+{
+ int ret;
+
+ ret = h->prot->url_close(h);
+ av_free(h);
+ return ret;
+}
+
+int url_exist(const char *filename)
+{
+ URLContext *h;
+ if (url_open(&h, filename, URL_RDONLY) < 0)
+ return 0;
+ url_close(h);
+ return 1;
+}
+
+offset_t url_filesize(URLContext *h)
+{
+ offset_t pos, size;
+
+ size= url_seek(h, 0, AVSEEK_SIZE);
+ if(size<0){
+ pos = url_seek(h, 0, SEEK_CUR);
+ if ((size = url_seek(h, -1, SEEK_END)) < 0)
+ return size;
+ size++;
+ url_seek(h, pos, SEEK_SET);
+ }
+ return size;
+}
+
+int url_get_max_packet_size(URLContext *h)
+{
+ return h->max_packet_size;
+}
+
+void url_get_filename(URLContext *h, char *buf, int buf_size)
+{
+ pstrcpy(buf, buf_size, h->filename);
+}
+
+
+static int default_interrupt_cb(void)
+{
+ return 0;
+}
+
+void url_set_interrupt_cb(URLInterruptCB *interrupt_cb)
+{
+ if (!interrupt_cb)
+ interrupt_cb = default_interrupt_cb;
+ url_interrupt_cb = interrupt_cb;
+}
diff --git a/contrib/ffmpeg/libavformat/avio.h b/contrib/ffmpeg/libavformat/avio.h
new file mode 100644
index 000000000..be78c9a7b
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/avio.h
@@ -0,0 +1,272 @@
+/*
+ * unbuffered io for ffmpeg system
+ * copyright (c) 2001 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
+ */
+#ifndef AVIO_H
+#define AVIO_H
+
+/* output byte stream handling */
+
+typedef int64_t offset_t;
+
+/* unbuffered I/O */
+
+struct URLContext {
+ struct URLProtocol *prot;
+ int flags;
+ 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;
+#if LIBAVFORMAT_VERSION_INT >= (52<<16)
+ char *filename; /**< specified filename */
+#else
+ char filename[1]; /**< specified filename */
+#endif
+};
+
+typedef struct URLContext URLContext;
+
+typedef struct URLPollEntry {
+ URLContext *handle;
+ int events;
+ int revents;
+} URLPollEntry;
+
+#define URL_RDONLY 0
+#define URL_WRONLY 1
+#define URL_RDWR 2
+
+typedef int URLInterruptCB(void);
+
+int url_open(URLContext **h, const char *filename, int flags);
+int url_read(URLContext *h, unsigned char *buf, int size);
+int url_write(URLContext *h, unsigned char *buf, int size);
+offset_t url_seek(URLContext *h, offset_t pos, int whence);
+int url_close(URLContext *h);
+int url_exist(const char *filename);
+offset_t url_filesize(URLContext *h);
+
+/**
+ * Return the maximum packet size associated to packetized file
+ * handle. If the file is not packetized (stream like http or file on
+ * disk), then 0 is returned.
+ *
+ * @param h file handle
+ * @return maximum packet size in bytes
+ */
+int url_get_max_packet_size(URLContext *h);
+void url_get_filename(URLContext *h, char *buf, int buf_size);
+
+/**
+ * the callback is called in blocking functions to test regulary if
+ * asynchronous interruption is needed. AVERROR(EINTR) is returned
+ * in this case by the interrupted function. 'NULL' means no interrupt
+ * callback is given. i
+ */
+void url_set_interrupt_cb(URLInterruptCB *interrupt_cb);
+
+/* not implemented */
+int url_poll(URLPollEntry *poll_table, int n, int timeout);
+
+/**
+ * passing this as the "whence" parameter to a seek function causes it to
+ * return the filesize without seeking anywhere, supporting this is optional
+ * if its not supprted then the seek function will return <0
+ */
+#define AVSEEK_SIZE 0x10000
+
+typedef struct URLProtocol {
+ const char *name;
+ int (*url_open)(URLContext *h, const char *filename, int flags);
+ int (*url_read)(URLContext *h, unsigned char *buf, int size);
+ int (*url_write)(URLContext *h, unsigned char *buf, int size);
+ offset_t (*url_seek)(URLContext *h, offset_t pos, int whence);
+ int (*url_close)(URLContext *h);
+ struct URLProtocol *next;
+} URLProtocol;
+
+extern URLProtocol *first_protocol;
+extern URLInterruptCB *url_interrupt_cb;
+
+int register_protocol(URLProtocol *protocol);
+
+typedef struct {
+ unsigned char *buffer;
+ int buffer_size;
+ unsigned char *buf_ptr, *buf_end;
+ void *opaque;
+ int (*read_packet)(void *opaque, uint8_t *buf, int buf_size);
+ int (*write_packet)(void *opaque, uint8_t *buf, int buf_size);
+ offset_t (*seek)(void *opaque, offset_t offset, int whence);
+ offset_t pos; /**< position in the file of the current buffer */
+ int must_flush; /**< true if the next seek should flush */
+ int eof_reached; /**< true if eof reached */
+ int write_flag; /**< true if open for writing */
+ int is_streamed;
+ int max_packet_size;
+ unsigned long checksum;
+ unsigned char *checksum_ptr;
+ unsigned long (*update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size);
+ int error; ///< contains the error code or 0 if no error happened
+} ByteIOContext;
+
+int init_put_byte(ByteIOContext *s,
+ unsigned char *buffer,
+ int buffer_size,
+ int write_flag,
+ void *opaque,
+ int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
+ int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
+ offset_t (*seek)(void *opaque, offset_t offset, int whence));
+
+void put_byte(ByteIOContext *s, int b);
+void put_buffer(ByteIOContext *s, const unsigned char *buf, int size);
+void put_le64(ByteIOContext *s, uint64_t val);
+void put_be64(ByteIOContext *s, uint64_t val);
+void put_le32(ByteIOContext *s, unsigned int val);
+void put_be32(ByteIOContext *s, unsigned int val);
+void put_le24(ByteIOContext *s, unsigned int val);
+void put_be24(ByteIOContext *s, unsigned int val);
+void put_le16(ByteIOContext *s, unsigned int val);
+void put_be16(ByteIOContext *s, unsigned int val);
+void put_tag(ByteIOContext *s, const char *tag);
+
+void put_strz(ByteIOContext *s, const char *buf);
+
+offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence);
+void url_fskip(ByteIOContext *s, offset_t offset);
+offset_t url_ftell(ByteIOContext *s);
+offset_t url_fsize(ByteIOContext *s);
+int url_feof(ByteIOContext *s);
+int url_ferror(ByteIOContext *s);
+
+#define URL_EOF (-1)
+/** @note return URL_EOF (-1) if EOF */
+int url_fgetc(ByteIOContext *s);
+
+/** @warning currently size is limited */
+#ifdef __GNUC__
+int url_fprintf(ByteIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
+#else
+int url_fprintf(ByteIOContext *s, const char *fmt, ...);
+#endif
+
+/** @note unlike fgets, the EOL character is not returned and a whole
+ line is parsed. return NULL if first char read was EOF */
+char *url_fgets(ByteIOContext *s, char *buf, int buf_size);
+
+void put_flush_packet(ByteIOContext *s);
+
+int get_buffer(ByteIOContext *s, unsigned char *buf, int size);
+int get_partial_buffer(ByteIOContext *s, unsigned char *buf, int size);
+
+/** @note return 0 if EOF, so you cannot use it if EOF handling is
+ necessary */
+int get_byte(ByteIOContext *s);
+unsigned int get_le24(ByteIOContext *s);
+unsigned int get_le32(ByteIOContext *s);
+uint64_t get_le64(ByteIOContext *s);
+unsigned int get_le16(ByteIOContext *s);
+
+char *get_strz(ByteIOContext *s, char *buf, int maxlen);
+unsigned int get_be16(ByteIOContext *s);
+unsigned int get_be24(ByteIOContext *s);
+unsigned int get_be32(ByteIOContext *s);
+uint64_t get_be64(ByteIOContext *s);
+
+static inline int url_is_streamed(ByteIOContext *s)
+{
+ return s->is_streamed;
+}
+
+int url_fdopen(ByteIOContext *s, URLContext *h);
+
+/** @warning must be called before any I/O */
+int url_setbufsize(ByteIOContext *s, int buf_size);
+
+/** @note when opened as read/write, the buffers are only used for
+ reading */
+int url_fopen(ByteIOContext *s, const char *filename, int flags);
+int url_fclose(ByteIOContext *s);
+URLContext *url_fileno(ByteIOContext *s);
+
+/**
+ * Return the maximum packet size associated to packetized buffered file
+ * handle. If the file is not packetized (stream like http or file on
+ * disk), then 0 is returned.
+ *
+ * @param h buffered file handle
+ * @return maximum packet size in bytes
+ */
+int url_fget_max_packet_size(ByteIOContext *s);
+
+int url_open_buf(ByteIOContext *s, uint8_t *buf, int buf_size, int flags);
+
+/** return the written or read size */
+int url_close_buf(ByteIOContext *s);
+
+/**
+ * Open a write only memory stream.
+ *
+ * @param s new IO context
+ * @return zero if no error.
+ */
+int url_open_dyn_buf(ByteIOContext *s);
+
+/**
+ * Open a write only packetized memory stream with a maximum packet
+ * size of 'max_packet_size'. The stream is stored in a memory buffer
+ * with a big endian 4 byte header giving the packet size in bytes.
+ *
+ * @param s new IO context
+ * @param max_packet_size maximum packet size (must be > 0)
+ * @return zero if no error.
+ */
+int url_open_dyn_packet_buf(ByteIOContext *s, int max_packet_size);
+
+/**
+ * Return the written size and a pointer to the buffer. The buffer
+ * must be freed with av_free().
+ * @param s IO context
+ * @param pointer to a byte buffer
+ * @return the length of the byte buffer
+ */
+int url_close_dyn_buf(ByteIOContext *s, uint8_t **pbuffer);
+
+unsigned long get_checksum(ByteIOContext *s);
+void init_checksum(ByteIOContext *s, unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), unsigned long checksum);
+
+/* file.c */
+extern URLProtocol file_protocol;
+extern URLProtocol pipe_protocol;
+
+/* udp.c */
+extern URLProtocol udp_protocol;
+int udp_set_remote_url(URLContext *h, const char *uri);
+int udp_get_local_port(URLContext *h);
+int udp_get_file_handle(URLContext *h);
+
+/* tcp.c */
+extern URLProtocol tcp_protocol;
+
+/* http.c */
+extern URLProtocol http_protocol;
+
+#endif
+
diff --git a/contrib/ffmpeg/libavformat/aviobuf.c b/contrib/ffmpeg/libavformat/aviobuf.c
new file mode 100644
index 000000000..2cc247b62
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/aviobuf.c
@@ -0,0 +1,755 @@
+/*
+ * Buffered I/O for ffmpeg system
+ * Copyright (c) 2000,2001 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 "avformat.h"
+#include "avio.h"
+#include <stdarg.h>
+
+#define IO_BUFFER_SIZE 32768
+
+static void fill_buffer(ByteIOContext *s);
+
+int init_put_byte(ByteIOContext *s,
+ unsigned char *buffer,
+ int buffer_size,
+ int write_flag,
+ void *opaque,
+ int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
+ int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
+ offset_t (*seek)(void *opaque, offset_t offset, int whence))
+{
+ s->buffer = buffer;
+ s->buffer_size = buffer_size;
+ s->buf_ptr = buffer;
+ s->write_flag = write_flag;
+ if (!s->write_flag)
+ s->buf_end = buffer;
+ else
+ s->buf_end = buffer + buffer_size;
+ s->opaque = opaque;
+ s->write_packet = write_packet;
+ s->read_packet = read_packet;
+ s->seek = seek;
+ s->pos = 0;
+ s->must_flush = 0;
+ s->eof_reached = 0;
+ s->error = 0;
+ s->is_streamed = 0;
+ s->max_packet_size = 0;
+ s->update_checksum= NULL;
+ if(!read_packet && !write_flag){
+ s->pos = buffer_size;
+ s->buf_end = s->buffer + buffer_size;
+ }
+ return 0;
+}
+
+static void flush_buffer(ByteIOContext *s)
+{
+ if (s->buf_ptr > s->buffer) {
+ if (s->write_packet && !s->error){
+ int ret= s->write_packet(s->opaque, s->buffer, s->buf_ptr - s->buffer);
+ if(ret < 0){
+ s->error = ret;
+ }
+ }
+ if(s->update_checksum){
+ s->checksum= s->update_checksum(s->checksum, s->checksum_ptr, s->buf_ptr - s->checksum_ptr);
+ s->checksum_ptr= s->buffer;
+ }
+ s->pos += s->buf_ptr - s->buffer;
+ }
+ s->buf_ptr = s->buffer;
+}
+
+void put_byte(ByteIOContext *s, int b)
+{
+ *(s->buf_ptr)++ = b;
+ if (s->buf_ptr >= s->buf_end)
+ flush_buffer(s);
+}
+
+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;
+ memcpy(s->buf_ptr, buf, len);
+ s->buf_ptr += len;
+
+ if (s->buf_ptr >= s->buf_end)
+ flush_buffer(s);
+
+ buf += len;
+ size -= len;
+ }
+}
+
+void put_flush_packet(ByteIOContext *s)
+{
+ flush_buffer(s);
+ s->must_flush = 0;
+}
+
+offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence)
+{
+ offset_t offset1;
+ offset_t pos= s->pos - (s->write_flag ? 0 : (s->buf_end - s->buffer));
+
+ if (whence != SEEK_CUR && whence != SEEK_SET)
+ return AVERROR(EINVAL);
+
+ if (whence == SEEK_CUR) {
+ offset1 = pos + (s->buf_ptr - s->buffer);
+ if (offset == 0)
+ return offset1;
+ offset += offset1;
+ }
+ offset1 = offset - pos;
+ if (!s->must_flush &&
+ 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)){
+ while(s->pos < offset && !s->eof_reached)
+ fill_buffer(s);
+ s->buf_ptr = s->buf_end + offset - s->pos;
+ } else {
+ offset_t res = AVERROR(EPIPE);
+
+#if defined(CONFIG_MUXERS) || defined(CONFIG_NETWORK)
+ if (s->write_flag) {
+ flush_buffer(s);
+ s->must_flush = 1;
+ } else
+#endif /* defined(CONFIG_MUXERS) || defined(CONFIG_NETWORK) */
+ {
+ s->buf_end = s->buffer;
+ }
+ s->buf_ptr = s->buffer;
+ if (!s->seek || (res = s->seek(s->opaque, offset, SEEK_SET)) < 0)
+ return res;
+ s->pos = offset;
+ }
+ s->eof_reached = 0;
+ return offset;
+}
+
+void url_fskip(ByteIOContext *s, offset_t offset)
+{
+ url_fseek(s, offset, SEEK_CUR);
+}
+
+offset_t url_ftell(ByteIOContext *s)
+{
+ return url_fseek(s, 0, SEEK_CUR);
+}
+
+offset_t url_fsize(ByteIOContext *s)
+{
+ offset_t size;
+
+ if (!s->seek)
+ return AVERROR(EPIPE);
+ size = s->seek(s->opaque, 0, AVSEEK_SIZE);
+ if(size<0){
+ if ((size = s->seek(s->opaque, -1, SEEK_END)) < 0)
+ return size;
+ size++;
+ s->seek(s->opaque, s->pos, SEEK_SET);
+ }
+ return size;
+}
+
+int url_feof(ByteIOContext *s)
+{
+ return s->eof_reached;
+}
+
+int url_ferror(ByteIOContext *s)
+{
+ return s->error;
+}
+
+void put_le32(ByteIOContext *s, unsigned int val)
+{
+ put_byte(s, val);
+ put_byte(s, val >> 8);
+ put_byte(s, val >> 16);
+ put_byte(s, val >> 24);
+}
+
+void put_be32(ByteIOContext *s, unsigned int val)
+{
+ put_byte(s, val >> 24);
+ put_byte(s, val >> 16);
+ put_byte(s, val >> 8);
+ put_byte(s, val);
+}
+
+void put_strz(ByteIOContext *s, const char *str)
+{
+ if (str)
+ put_buffer(s, (const unsigned char *) str, strlen(str) + 1);
+ else
+ put_byte(s, 0);
+}
+
+void put_le64(ByteIOContext *s, uint64_t val)
+{
+ put_le32(s, (uint32_t)(val & 0xffffffff));
+ put_le32(s, (uint32_t)(val >> 32));
+}
+
+void put_be64(ByteIOContext *s, uint64_t val)
+{
+ put_be32(s, (uint32_t)(val >> 32));
+ put_be32(s, (uint32_t)(val & 0xffffffff));
+}
+
+void put_le16(ByteIOContext *s, unsigned int val)
+{
+ put_byte(s, val);
+ put_byte(s, val >> 8);
+}
+
+void put_be16(ByteIOContext *s, unsigned int val)
+{
+ put_byte(s, val >> 8);
+ put_byte(s, val);
+}
+
+void put_le24(ByteIOContext *s, unsigned int val)
+{
+ put_le16(s, val & 0xffff);
+ put_byte(s, val >> 16);
+}
+
+void put_be24(ByteIOContext *s, unsigned int val)
+{
+ put_be16(s, val >> 8);
+ put_byte(s, val);
+}
+
+void put_tag(ByteIOContext *s, const char *tag)
+{
+ while (*tag) {
+ put_byte(s, *tag++);
+ }
+}
+
+/* Input stream */
+
+static void fill_buffer(ByteIOContext *s)
+{
+ int len;
+
+ /* no need to do anything if EOF already reached */
+ if (s->eof_reached)
+ return;
+
+ if(s->update_checksum){
+ if(s->buf_end > s->checksum_ptr)
+ s->checksum= s->update_checksum(s->checksum, s->checksum_ptr, s->buf_end - s->checksum_ptr);
+ s->checksum_ptr= s->buffer;
+ }
+
+ len = s->read_packet(s->opaque, s->buffer, s->buffer_size);
+ if (len <= 0) {
+ /* do not modify buffer if EOF reached so that a seek back can
+ be done without rereading data */
+ s->eof_reached = 1;
+ if(len<0)
+ s->error= len;
+ } else {
+ s->pos += len;
+ s->buf_ptr = s->buffer;
+ s->buf_end = s->buffer + len;
+ }
+}
+
+unsigned long get_checksum(ByteIOContext *s){
+ s->checksum= s->update_checksum(s->checksum, s->checksum_ptr, s->buf_ptr - s->checksum_ptr);
+ s->update_checksum= NULL;
+ return s->checksum;
+}
+
+void init_checksum(ByteIOContext *s, unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), unsigned long checksum){
+ s->update_checksum= update_checksum;
+ if(s->update_checksum){
+ s->checksum= checksum;
+ s->checksum_ptr= s->buf_ptr;
+ }
+}
+
+/* XXX: put an inline version */
+int get_byte(ByteIOContext *s)
+{
+ if (s->buf_ptr < s->buf_end) {
+ return *s->buf_ptr++;
+ } else {
+ fill_buffer(s);
+ if (s->buf_ptr < s->buf_end)
+ return *s->buf_ptr++;
+ else
+ return 0;
+ }
+}
+
+int url_fgetc(ByteIOContext *s)
+{
+ if (s->buf_ptr < s->buf_end) {
+ return *s->buf_ptr++;
+ } else {
+ fill_buffer(s);
+ if (s->buf_ptr < s->buf_end)
+ return *s->buf_ptr++;
+ else
+ return URL_EOF;
+ }
+}
+
+int get_buffer(ByteIOContext *s, unsigned char *buf, int size)
+{
+ int len, size1;
+
+ size1 = size;
+ while (size > 0) {
+ len = s->buf_end - s->buf_ptr;
+ if (len > size)
+ len = size;
+ if (len == 0) {
+ if(size > s->buffer_size && !s->update_checksum){
+ len = s->read_packet(s->opaque, buf, size);
+ if (len <= 0) {
+ /* do not modify buffer if EOF reached so that a seek back can
+ be done without rereading data */
+ s->eof_reached = 1;
+ if(len<0)
+ s->error= len;
+ break;
+ } else {
+ s->pos += len;
+ size -= len;
+ buf += len;
+ s->buf_ptr = s->buffer;
+ s->buf_end = s->buffer/* + len*/;
+ }
+ }else{
+ fill_buffer(s);
+ len = s->buf_end - s->buf_ptr;
+ if (len == 0)
+ break;
+ }
+ } else {
+ memcpy(buf, s->buf_ptr, len);
+ buf += len;
+ s->buf_ptr += len;
+ size -= len;
+ }
+ }
+ return size1 - size;
+}
+
+int get_partial_buffer(ByteIOContext *s, unsigned char *buf, int size)
+{
+ int len;
+
+ if(size<0)
+ return -1;
+
+ len = s->buf_end - s->buf_ptr;
+ if (len == 0) {
+ fill_buffer(s);
+ len = s->buf_end - s->buf_ptr;
+ }
+ if (len > size)
+ len = size;
+ memcpy(buf, s->buf_ptr, len);
+ s->buf_ptr += len;
+ return len;
+}
+
+unsigned int get_le16(ByteIOContext *s)
+{
+ unsigned int val;
+ val = get_byte(s);
+ val |= get_byte(s) << 8;
+ return val;
+}
+
+unsigned int get_le24(ByteIOContext *s)
+{
+ unsigned int val;
+ val = get_le16(s);
+ val |= get_byte(s) << 16;
+ return val;
+}
+
+unsigned int get_le32(ByteIOContext *s)
+{
+ unsigned int val;
+ val = get_le16(s);
+ val |= get_le16(s) << 16;
+ return val;
+}
+
+uint64_t get_le64(ByteIOContext *s)
+{
+ uint64_t val;
+ val = (uint64_t)get_le32(s);
+ val |= (uint64_t)get_le32(s) << 32;
+ return val;
+}
+
+unsigned int get_be16(ByteIOContext *s)
+{
+ unsigned int val;
+ val = get_byte(s) << 8;
+ val |= get_byte(s);
+ return val;
+}
+
+unsigned int get_be24(ByteIOContext *s)
+{
+ unsigned int val;
+ val = get_be16(s) << 8;
+ val |= get_byte(s);
+ return val;
+}
+unsigned int get_be32(ByteIOContext *s)
+{
+ unsigned int val;
+ val = get_be16(s) << 16;
+ val |= get_be16(s);
+ return val;
+}
+
+char *get_strz(ByteIOContext *s, char *buf, int maxlen)
+{
+ int i = 0;
+ char c;
+
+ while ((c = get_byte(s))) {
+ if (i < maxlen-1)
+ buf[i++] = c;
+ }
+
+ buf[i] = 0; /* Ensure null terminated, but may be truncated */
+
+ return buf;
+}
+
+uint64_t get_be64(ByteIOContext *s)
+{
+ uint64_t val;
+ val = (uint64_t)get_be32(s) << 32;
+ val |= (uint64_t)get_be32(s);
+ return val;
+}
+
+/* link with avio functions */
+
+#ifdef CONFIG_MUXERS
+static int url_write_packet(void *opaque, uint8_t *buf, int buf_size)
+{
+ URLContext *h = opaque;
+ return url_write(h, buf, buf_size);
+}
+#else
+#define url_write_packet NULL
+#endif //CONFIG_MUXERS
+
+static int url_read_packet(void *opaque, uint8_t *buf, int buf_size)
+{
+ URLContext *h = opaque;
+ return url_read(h, buf, buf_size);
+}
+
+static offset_t url_seek_packet(void *opaque, offset_t offset, int whence)
+{
+ URLContext *h = opaque;
+ return url_seek(h, offset, whence);
+ //return 0;
+}
+
+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 */
+ } else {
+ buffer_size = IO_BUFFER_SIZE;
+ }
+ buffer = av_malloc(buffer_size);
+ if (!buffer)
+ return AVERROR(ENOMEM);
+
+ if (init_put_byte(s, buffer, buffer_size,
+ (h->flags & URL_WRONLY || h->flags & URL_RDWR), h,
+ url_read_packet, url_write_packet, url_seek_packet) < 0) {
+ av_free(buffer);
+ return AVERROR_IO;
+ }
+ s->is_streamed = h->is_streamed;
+ s->max_packet_size = max_packet_size;
+ return 0;
+}
+
+int url_setbufsize(ByteIOContext *s, int buf_size)
+{
+ uint8_t *buffer;
+ buffer = av_malloc(buf_size);
+ if (!buffer)
+ return AVERROR(ENOMEM);
+
+ av_free(s->buffer);
+ s->buffer = buffer;
+ s->buffer_size = buf_size;
+ s->buf_ptr = buffer;
+ if (!s->write_flag)
+ s->buf_end = buffer;
+ else
+ s->buf_end = buffer + buf_size;
+ return 0;
+}
+
+int url_fopen(ByteIOContext *s, const char *filename, int flags)
+{
+ URLContext *h;
+ int err;
+
+ err = url_open(&h, filename, flags);
+ if (err < 0)
+ return err;
+ err = url_fdopen(s, h);
+ if (err < 0) {
+ url_close(h);
+ return err;
+ }
+ return 0;
+}
+
+int url_fclose(ByteIOContext *s)
+{
+ URLContext *h = s->opaque;
+
+ av_free(s->buffer);
+ memset(s, 0, sizeof(ByteIOContext));
+ return url_close(h);
+}
+
+URLContext *url_fileno(ByteIOContext *s)
+{
+ return s->opaque;
+}
+
+#ifdef CONFIG_MUXERS
+int url_fprintf(ByteIOContext *s, const char *fmt, ...)
+{
+ va_list ap;
+ char buf[4096];
+ int ret;
+
+ va_start(ap, fmt);
+ ret = vsnprintf(buf, sizeof(buf), fmt, ap);
+ va_end(ap);
+ put_buffer(s, buf, strlen(buf));
+ return ret;
+}
+#endif //CONFIG_MUXERS
+
+char *url_fgets(ByteIOContext *s, char *buf, int buf_size)
+{
+ int c;
+ char *q;
+
+ c = url_fgetc(s);
+ if (c == EOF)
+ return NULL;
+ q = buf;
+ for(;;) {
+ if (c == EOF || c == '\n')
+ break;
+ if ((q - buf) < buf_size - 1)
+ *q++ = c;
+ c = url_fgetc(s);
+ }
+ if (buf_size > 0)
+ *q = '\0';
+ return buf;
+}
+
+int url_fget_max_packet_size(ByteIOContext *s)
+{
+ return s->max_packet_size;
+}
+
+/* url_open_dyn_buf and url_close_dyn_buf are used in rtp.c to send a response
+ * back to the server even if CONFIG_MUXERS is not set. */
+#if defined(CONFIG_MUXERS) || defined(CONFIG_NETWORK)
+/* buffer handling */
+int url_open_buf(ByteIOContext *s, uint8_t *buf, int buf_size, int flags)
+{
+ return init_put_byte(s, buf, buf_size,
+ (flags & URL_WRONLY || flags & URL_RDWR),
+ NULL, NULL, NULL, NULL);
+}
+
+int url_close_buf(ByteIOContext *s)
+{
+ put_flush_packet(s);
+ return s->buf_ptr - s->buffer;
+}
+
+/* output in a dynamic buffer */
+
+typedef struct DynBuffer {
+ int pos, size, allocated_size;
+ uint8_t *buffer;
+ int io_buffer_size;
+ uint8_t io_buffer[1];
+} DynBuffer;
+
+static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
+{
+ DynBuffer *d = opaque;
+ int new_size, new_allocated_size;
+
+ /* reallocate buffer if needed */
+ new_size = d->pos + buf_size;
+ new_allocated_size = d->allocated_size;
+ if(new_size < d->pos || new_size > INT_MAX/2)
+ return -1;
+ while (new_size > new_allocated_size) {
+ if (!new_allocated_size)
+ new_allocated_size = new_size;
+ else
+ new_allocated_size += new_allocated_size / 2 + 1;
+ }
+
+ if (new_allocated_size > d->allocated_size) {
+ d->buffer = av_realloc(d->buffer, new_allocated_size);
+ if(d->buffer == NULL)
+ return -1234;
+ d->allocated_size = new_allocated_size;
+ }
+ memcpy(d->buffer + d->pos, buf, buf_size);
+ d->pos = new_size;
+ if (d->pos > d->size)
+ d->size = d->pos;
+ return buf_size;
+}
+
+static int dyn_packet_buf_write(void *opaque, uint8_t *buf, int buf_size)
+{
+ unsigned char buf1[4];
+ int ret;
+
+ /* packetized write: output the header */
+ buf1[0] = (buf_size >> 24);
+ buf1[1] = (buf_size >> 16);
+ buf1[2] = (buf_size >> 8);
+ buf1[3] = (buf_size);
+ ret= dyn_buf_write(opaque, buf1, 4);
+ if(ret < 0)
+ return ret;
+
+ /* then the data */
+ return dyn_buf_write(opaque, buf, buf_size);
+}
+
+static offset_t dyn_buf_seek(void *opaque, offset_t offset, int whence)
+{
+ DynBuffer *d = opaque;
+
+ if (whence == SEEK_CUR)
+ offset += d->pos;
+ else if (whence == SEEK_END)
+ offset += d->size;
+ if (offset < 0 || offset > 0x7fffffffLL)
+ return -1;
+ d->pos = offset;
+ return 0;
+}
+
+static int url_open_dyn_buf_internal(ByteIOContext *s, int max_packet_size)
+{
+ DynBuffer *d;
+ int io_buffer_size, ret;
+
+ if (max_packet_size)
+ io_buffer_size = max_packet_size;
+ else
+ io_buffer_size = 1024;
+
+ if(sizeof(DynBuffer) + io_buffer_size < io_buffer_size)
+ return -1;
+ d = av_malloc(sizeof(DynBuffer) + io_buffer_size);
+ if (!d)
+ return -1;
+ d->io_buffer_size = io_buffer_size;
+ d->buffer = NULL;
+ d->pos = 0;
+ d->size = 0;
+ d->allocated_size = 0;
+ ret = init_put_byte(s, d->io_buffer, io_buffer_size,
+ 1, d, NULL,
+ max_packet_size ? dyn_packet_buf_write : dyn_buf_write,
+ max_packet_size ? NULL : dyn_buf_seek);
+ if (ret == 0) {
+ s->max_packet_size = max_packet_size;
+ }
+ return ret;
+}
+
+int url_open_dyn_buf(ByteIOContext *s)
+{
+ return url_open_dyn_buf_internal(s, 0);
+}
+
+int url_open_dyn_packet_buf(ByteIOContext *s, int max_packet_size)
+{
+ if (max_packet_size <= 0)
+ return -1;
+ return url_open_dyn_buf_internal(s, max_packet_size);
+}
+
+int url_close_dyn_buf(ByteIOContext *s, uint8_t **pbuffer)
+{
+ DynBuffer *d = s->opaque;
+ int size;
+
+ put_flush_packet(s);
+
+ *pbuffer = d->buffer;
+ size = d->size;
+ av_free(d);
+ return size;
+}
+#endif /* CONFIG_MUXERS || CONFIG_NETWORK */
diff --git a/contrib/ffmpeg/libavformat/avisynth.c b/contrib/ffmpeg/libavformat/avisynth.c
new file mode 100644
index 000000000..1afcdea5e
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/avisynth.c
@@ -0,0 +1,222 @@
+/*
+ * AVISynth support for ffmpeg system
+ * Copyright (c) 2006 DivX, 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
+ */
+
+#include "avformat.h"
+#include "riff.h"
+
+#include <windows.h>
+#include <vfw.h>
+
+typedef struct {
+ PAVISTREAM handle;
+ AVISTREAMINFO info;
+ DWORD read;
+ LONG chunck_size;
+ LONG chunck_samples;
+} AVISynthStream;
+
+typedef struct {
+ PAVIFILE file;
+ AVISynthStream *streams;
+ int nb_streams;
+ int next_stream;
+} AVISynthContext;
+
+static int avisynth_read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+ AVISynthContext *avs = s->priv_data;
+ HRESULT res;
+ AVIFILEINFO info;
+ DWORD id;
+ AVStream *st;
+ AVISynthStream *stream;
+
+ AVIFileInit();
+
+ res = AVIFileOpen(&avs->file, s->filename, OF_READ|OF_SHARE_DENY_WRITE, NULL);
+ if (res != S_OK)
+ {
+ av_log(s, AV_LOG_ERROR, "AVIFileOpen failed with error %ld", res);
+ AVIFileExit();
+ return -1;
+ }
+
+ res = AVIFileInfo(avs->file, &info, sizeof(info));
+ if (res != S_OK)
+ {
+ av_log(s, AV_LOG_ERROR, "AVIFileInfo failed with error %ld", res);
+ AVIFileExit();
+ return -1;
+ }
+
+ avs->streams = av_mallocz(info.dwStreams * sizeof(AVISynthStream));
+
+ for (id=0; id<info.dwStreams; id++)
+ {
+ stream = &avs->streams[id];
+ stream->read = 0;
+ if (AVIFileGetStream(avs->file, &stream->handle, 0, id) == S_OK)
+ {
+ if (AVIStreamInfo(stream->handle, &stream->info, sizeof(stream->info)) == S_OK)
+ {
+ if (stream->info.fccType == streamtypeAUDIO)
+ {
+ WAVEFORMATEX wvfmt;
+ LONG struct_size = sizeof(WAVEFORMATEX);
+ if (AVIStreamReadFormat(stream->handle, 0, &wvfmt, &struct_size) != S_OK)
+ continue;
+
+ st = av_new_stream(s, id);
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+
+ st->codec->block_align = wvfmt.nBlockAlign;
+ st->codec->channels = wvfmt.nChannels;
+ st->codec->sample_rate = wvfmt.nSamplesPerSec;
+ st->codec->bit_rate = wvfmt.nAvgBytesPerSec * 8;
+ st->codec->bits_per_sample = wvfmt.wBitsPerSample;
+
+ stream->chunck_samples = wvfmt.nSamplesPerSec * (uint64_t)info.dwScale / (uint64_t)info.dwRate;
+ stream->chunck_size = stream->chunck_samples * wvfmt.nChannels * wvfmt.wBitsPerSample / 8;
+
+ st->codec->codec_tag = wvfmt.wFormatTag;
+ st->codec->codec_id = wav_codec_get_id(wvfmt.wFormatTag, st->codec->bits_per_sample);
+ }
+ else if (stream->info.fccType == streamtypeVIDEO)
+ {
+ BITMAPINFO imgfmt;
+ LONG struct_size = sizeof(BITMAPINFO);
+
+ stream->chunck_size = stream->info.dwSampleSize;
+ stream->chunck_samples = 1;
+
+ if (AVIStreamReadFormat(stream->handle, 0, &imgfmt, &struct_size) != S_OK)
+ continue;
+
+ st = av_new_stream(s, id);
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ st->r_frame_rate.num = stream->info.dwRate;
+ st->r_frame_rate.den = stream->info.dwScale;
+
+ st->codec->width = imgfmt.bmiHeader.biWidth;
+ st->codec->height = imgfmt.bmiHeader.biHeight;
+
+ st->codec->bits_per_sample = imgfmt.bmiHeader.biBitCount;
+ st->codec->bit_rate = (uint64_t)stream->info.dwSampleSize * (uint64_t)stream->info.dwRate * 8 / (uint64_t)stream->info.dwScale;
+ st->codec->codec_tag = imgfmt.bmiHeader.biCompression;
+ st->codec->codec_id = codec_get_id(codec_bmp_tags, imgfmt.bmiHeader.biCompression);
+
+ st->duration = stream->info.dwLength;
+ }
+ else
+ {
+ AVIStreamRelease(stream->handle);
+ continue;
+ }
+
+ avs->nb_streams++;
+
+ st->codec->stream_codec_tag = stream->info.fccHandler;
+
+ av_set_pts_info(st, 64, info.dwScale, info.dwRate);
+ st->start_time = stream->info.dwStart;
+ }
+ }
+ }
+
+ return 0;
+}
+
+static int avisynth_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ AVISynthContext *avs = s->priv_data;
+ HRESULT res;
+ AVISynthStream *stream;
+ int stream_id = avs->next_stream;
+ LONG read_size;
+
+ // handle interleaving manually...
+ stream = &avs->streams[stream_id];
+
+ if (stream->read >= stream->info.dwLength)
+ return AVERROR_IO;
+
+ if (av_new_packet(pkt, stream->chunck_size))
+ return AVERROR_IO;
+ pkt->stream_index = stream_id;
+ pkt->pts = avs->streams[stream_id].read / avs->streams[stream_id].chunck_samples;
+
+ res = AVIStreamRead(stream->handle, stream->read, stream->chunck_samples, pkt->data, stream->chunck_size, &read_size, NULL);
+
+ pkt->pts = stream->read;
+ pkt->size = read_size;
+
+ stream->read += stream->chunck_samples;
+
+ // prepare for the next stream to read
+ do {
+ avs->next_stream = (avs->next_stream+1) % avs->nb_streams;
+ } while (avs->next_stream != stream_id && s->streams[avs->next_stream]->discard >= AVDISCARD_ALL);
+
+ return (res == S_OK) ? pkt->size : -1;
+}
+
+static int avisynth_read_close(AVFormatContext *s)
+{
+ AVISynthContext *avs = s->priv_data;
+ int i;
+
+ for (i=0;i<avs->nb_streams;i++)
+ {
+ AVIStreamRelease(avs->streams[i].handle);
+ }
+
+ av_free(avs->streams);
+ AVIFileRelease(avs->file);
+ AVIFileExit();
+ return 0;
+}
+
+static int avisynth_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flags)
+{
+ AVISynthContext *avs = s->priv_data;
+ int stream_id;
+
+ for (stream_id = 0; stream_id < avs->nb_streams; stream_id++)
+ {
+ avs->streams[stream_id].read = pts * avs->streams[stream_id].chunck_samples;
+ }
+
+ return 0;
+}
+
+AVInputFormat avisynth_demuxer = {
+ "avs",
+ "AVISynth",
+ sizeof(AVISynthContext),
+ NULL,
+ avisynth_read_header,
+ avisynth_read_packet,
+ avisynth_read_close,
+ avisynth_read_seek,
+ NULL,
+ 0,
+ "avs",
+};
diff --git a/contrib/ffmpeg/libavformat/avs.c b/contrib/ffmpeg/libavformat/avs.c
new file mode 100644
index 000000000..0fa77deff
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/avs.c
@@ -0,0 +1,227 @@
+/*
+ * AVS demuxer.
+ * Copyright (c) 2006 Aurelien Jacobs <aurel@gnuage.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avformat.h"
+#include "voc.h"
+
+
+typedef struct avs_format {
+ voc_dec_context_t voc;
+ AVStream *st_video;
+ AVStream *st_audio;
+ int width;
+ int height;
+ int bits_per_sample;
+ int fps;
+ int nb_frames;
+ int remaining_frame_size;
+ int remaining_audio_size;
+} avs_format_t;
+
+typedef enum avs_block_type {
+ AVS_VIDEO = 0x01,
+ AVS_AUDIO = 0x02,
+ AVS_PALETTE = 0x03,
+ AVS_GAME_DATA = 0x04,
+} avs_block_type_t;
+
+static int avs_probe(AVProbeData * p)
+{
+ const uint8_t *d;
+
+ if (p->buf_size < 2)
+ return 0;
+ d = p->buf;
+ if (d[0] == 'w' && d[1] == 'W' && d[2] == 0x10 && d[3] == 0)
+ return 50;
+
+ return 0;
+}
+
+static int avs_read_header(AVFormatContext * s, AVFormatParameters * ap)
+{
+ avs_format_t *avs = s->priv_data;
+
+ s->ctx_flags |= AVFMTCTX_NOHEADER;
+
+ url_fskip(&s->pb, 4);
+ avs->width = get_le16(&s->pb);
+ avs->height = get_le16(&s->pb);
+ avs->bits_per_sample = get_le16(&s->pb);
+ avs->fps = get_le16(&s->pb);
+ avs->nb_frames = get_le32(&s->pb);
+ avs->remaining_frame_size = 0;
+ avs->remaining_audio_size = 0;
+
+ avs->st_video = avs->st_audio = NULL;
+
+ if (avs->width != 318 || avs->height != 198)
+ av_log(s, AV_LOG_ERROR, "This avs pretend to be %dx%d "
+ "when the avs format is supposed to be 318x198 only.\n",
+ avs->width, avs->height);
+
+ return 0;
+}
+
+static int
+avs_read_video_packet(AVFormatContext * s, AVPacket * pkt,
+ avs_block_type_t type, int sub_type, int size,
+ uint8_t * palette, int palette_size)
+{
+ avs_format_t *avs = s->priv_data;
+ int ret;
+
+ ret = av_new_packet(pkt, size + palette_size);
+ if (ret < 0)
+ return ret;
+
+ if (palette_size) {
+ pkt->data[0] = 0x00;
+ pkt->data[1] = 0x03;
+ pkt->data[2] = palette_size & 0xFF;
+ pkt->data[3] = (palette_size >> 8) & 0xFF;
+ memcpy(pkt->data + 4, palette, palette_size - 4);
+ }
+
+ pkt->data[palette_size + 0] = sub_type;
+ pkt->data[palette_size + 1] = type;
+ pkt->data[palette_size + 2] = size & 0xFF;
+ pkt->data[palette_size + 3] = (size >> 8) & 0xFF;
+ ret = get_buffer(&s->pb, pkt->data + palette_size + 4, size - 4) + 4;
+ if (ret < size) {
+ av_free_packet(pkt);
+ return AVERROR_IO;
+ }
+
+ pkt->size = ret + palette_size;
+ pkt->stream_index = avs->st_video->index;
+ if (sub_type == 0)
+ pkt->flags |= PKT_FLAG_KEY;
+
+ return 0;
+}
+
+static int avs_read_audio_packet(AVFormatContext * s, AVPacket * pkt)
+{
+ avs_format_t *avs = s->priv_data;
+ int ret, size;
+
+ size = url_ftell(&s->pb);
+ ret = voc_get_packet(s, pkt, avs->st_audio, avs->remaining_audio_size);
+ size = url_ftell(&s->pb) - size;
+ avs->remaining_audio_size -= size;
+
+ if (ret == AVERROR_IO)
+ return 0; /* this indicate EOS */
+ if (ret < 0)
+ return ret;
+
+ pkt->stream_index = avs->st_audio->index;
+ pkt->flags |= PKT_FLAG_KEY;
+
+ return size;
+}
+
+static int avs_read_packet(AVFormatContext * s, AVPacket * pkt)
+{
+ avs_format_t *avs = s->priv_data;
+ int sub_type = 0, size = 0;
+ avs_block_type_t type = 0;
+ int palette_size = 0;
+ uint8_t palette[4 + 3 * 256];
+ int ret;
+
+ if (avs->remaining_audio_size > 0)
+ if (avs_read_audio_packet(s, pkt) > 0)
+ return 0;
+
+ while (1) {
+ if (avs->remaining_frame_size <= 0) {
+ if (!get_le16(&s->pb)) /* found EOF */
+ return AVERROR_IO;
+ avs->remaining_frame_size = get_le16(&s->pb) - 4;
+ }
+
+ while (avs->remaining_frame_size > 0) {
+ sub_type = get_byte(&s->pb);
+ type = get_byte(&s->pb);
+ size = get_le16(&s->pb);
+ avs->remaining_frame_size -= size;
+
+ switch (type) {
+ case AVS_PALETTE:
+ ret = get_buffer(&s->pb, palette, size - 4);
+ if (ret < size - 4)
+ return AVERROR_IO;
+ palette_size = size;
+ break;
+
+ case AVS_VIDEO:
+ if (!avs->st_video) {
+ avs->st_video = av_new_stream(s, AVS_VIDEO);
+ if (avs->st_video == NULL)
+ return AVERROR_NOMEM;
+ avs->st_video->codec->codec_type = CODEC_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;
+ avs->st_video->codec->bits_per_sample=avs->bits_per_sample;
+ avs->st_video->nb_frames = avs->nb_frames;
+ avs->st_video->codec->time_base = (AVRational) {
+ 1, avs->fps};
+ }
+ return avs_read_video_packet(s, pkt, type, sub_type, size,
+ palette, palette_size);
+
+ case AVS_AUDIO:
+ if (!avs->st_audio) {
+ avs->st_audio = av_new_stream(s, AVS_AUDIO);
+ if (avs->st_audio == NULL)
+ return AVERROR_NOMEM;
+ avs->st_audio->codec->codec_type = CODEC_TYPE_AUDIO;
+ }
+ avs->remaining_audio_size = size - 4;
+ size = avs_read_audio_packet(s, pkt);
+ if (size != 0)
+ return size;
+ break;
+
+ default:
+ url_fskip(&s->pb, size - 4);
+ }
+ }
+ }
+}
+
+static int avs_read_close(AVFormatContext * s)
+{
+ return 0;
+}
+
+AVInputFormat avs_demuxer = {
+ "avs",
+ "avs format",
+ sizeof(avs_format_t),
+ avs_probe,
+ avs_read_header,
+ avs_read_packet,
+ avs_read_close,
+};
diff --git a/contrib/ffmpeg/libavformat/beosaudio.cpp b/contrib/ffmpeg/libavformat/beosaudio.cpp
new file mode 100644
index 000000000..6c16f0048
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/beosaudio.cpp
@@ -0,0 +1,465 @@
+/*
+ * BeOS audio play interface
+ * Copyright (c) 2000, 2001 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 <signal.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/time.h>
+
+#include <Application.h>
+#include <SoundPlayer.h>
+
+extern "C" {
+#include "avformat.h"
+}
+
+#ifdef HAVE_BSOUNDRECORDER
+#include <SoundRecorder.h>
+using namespace BPrivate::Media::Experimental;
+#endif
+
+/* enable performance checks */
+//#define PERF_CHECK
+
+/* enable Media Kit latency checks */
+//#define LATENCY_CHECK
+
+#define AUDIO_BLOCK_SIZE 4096
+#define AUDIO_BLOCK_COUNT 8
+
+#define AUDIO_BUFFER_SIZE (AUDIO_BLOCK_SIZE*AUDIO_BLOCK_COUNT)
+
+typedef struct {
+ int fd; // UNUSED
+ int sample_rate;
+ int channels;
+ int frame_size; /* in bytes ! */
+ CodecID codec_id;
+ uint8_t buffer[AUDIO_BUFFER_SIZE];
+ int buffer_ptr;
+ /* ring buffer */
+ sem_id input_sem;
+ int input_index;
+ sem_id output_sem;
+ int output_index;
+ BSoundPlayer *player;
+#ifdef HAVE_BSOUNDRECORDER
+ BSoundRecorder *recorder;
+#endif
+ int has_quit; /* signal callbacks not to wait */
+ volatile bigtime_t starve_time;
+} AudioData;
+
+static thread_id main_thid;
+static thread_id bapp_thid;
+static int own_BApp_created = 0;
+static int refcount = 0;
+
+/* create the BApplication and Run() it */
+static int32 bapp_thread(void *arg)
+{
+ new BApplication("application/x-vnd.ffmpeg");
+ own_BApp_created = 1;
+ be_app->Run();
+ /* kill the process group */
+// kill(0, SIGINT);
+// kill(main_thid, SIGHUP);
+ return B_OK;
+}
+
+/* create the BApplication only if needed */
+static void create_bapp_if_needed(void)
+{
+ if (refcount++ == 0) {
+ /* needed by libmedia */
+ if (be_app == NULL) {
+ bapp_thid = spawn_thread(bapp_thread, "ffmpeg BApplication", B_NORMAL_PRIORITY, NULL);
+ resume_thread(bapp_thid);
+ while (!own_BApp_created)
+ snooze(50000);
+ }
+ }
+}
+
+static void destroy_bapp_if_needed(void)
+{
+ if (--refcount == 0 && own_BApp_created) {
+ be_app->Lock();
+ be_app->Quit();
+ be_app = NULL;
+ }
+}
+
+/* called back by BSoundPlayer */
+static void audioplay_callback(void *cookie, void *buffer, size_t bufferSize, const media_raw_audio_format &format)
+{
+ AudioData *s;
+ size_t len, amount;
+ unsigned char *buf = (unsigned char *)buffer;
+
+ s = (AudioData *)cookie;
+ if (s->has_quit)
+ return;
+ while (bufferSize > 0) {
+#ifdef PERF_CHECK
+ bigtime_t t;
+ t = system_time();
+#endif
+ len = MIN(AUDIO_BLOCK_SIZE, bufferSize);
+ if (acquire_sem_etc(s->output_sem, len, B_CAN_INTERRUPT, 0LL) < B_OK) {
+ s->has_quit = 1;
+ s->player->SetHasData(false);
+ return;
+ }
+ amount = MIN(len, (AUDIO_BUFFER_SIZE - s->output_index));
+ memcpy(buf, &s->buffer[s->output_index], amount);
+ s->output_index += amount;
+ if (s->output_index >= AUDIO_BUFFER_SIZE) {
+ s->output_index %= AUDIO_BUFFER_SIZE;
+ memcpy(buf + amount, &s->buffer[s->output_index], len - amount);
+ s->output_index += len-amount;
+ s->output_index %= AUDIO_BUFFER_SIZE;
+ }
+ release_sem_etc(s->input_sem, len, 0);
+#ifdef PERF_CHECK
+ t = system_time() - t;
+ s->starve_time = MAX(s->starve_time, t);
+#endif
+ buf += len;
+ bufferSize -= len;
+ }
+}
+
+#ifdef HAVE_BSOUNDRECORDER
+/* called back by BSoundRecorder */
+static void audiorecord_callback(void *cookie, bigtime_t timestamp, void *buffer, size_t bufferSize, const media_multi_audio_format &format)
+{
+ AudioData *s;
+ size_t len, amount;
+ unsigned char *buf = (unsigned char *)buffer;
+
+ s = (AudioData *)cookie;
+ if (s->has_quit)
+ return;
+
+ while (bufferSize > 0) {
+ len = MIN(bufferSize, AUDIO_BLOCK_SIZE);
+ //printf("acquire_sem(input, %d)\n", len);
+ if (acquire_sem_etc(s->input_sem, len, B_CAN_INTERRUPT, 0LL) < B_OK) {
+ s->has_quit = 1;
+ return;
+ }
+ amount = MIN(len, (AUDIO_BUFFER_SIZE - s->input_index));
+ memcpy(&s->buffer[s->input_index], buf, amount);
+ s->input_index += amount;
+ if (s->input_index >= AUDIO_BUFFER_SIZE) {
+ s->input_index %= AUDIO_BUFFER_SIZE;
+ memcpy(&s->buffer[s->input_index], buf + amount, len - amount);
+ s->input_index += len - amount;
+ }
+ release_sem_etc(s->output_sem, len, 0);
+ //printf("release_sem(output, %d)\n", len);
+ buf += len;
+ bufferSize -= len;
+ }
+}
+#endif
+
+static int audio_open(AudioData *s, int is_output, const char *audio_device)
+{
+ int p[2];
+ int ret;
+ media_raw_audio_format format;
+ media_multi_audio_format iformat;
+
+#ifndef HAVE_BSOUNDRECORDER
+ if (!is_output)
+ return AVERROR(EIO); /* not for now */
+#endif
+ s->input_sem = create_sem(AUDIO_BUFFER_SIZE, "ffmpeg_ringbuffer_input");
+ if (s->input_sem < B_OK)
+ return AVERROR(EIO);
+ s->output_sem = create_sem(0, "ffmpeg_ringbuffer_output");
+ if (s->output_sem < B_OK) {
+ delete_sem(s->input_sem);
+ return AVERROR(EIO);
+ }
+ s->input_index = 0;
+ s->output_index = 0;
+ create_bapp_if_needed();
+ s->frame_size = AUDIO_BLOCK_SIZE;
+ /* bump up the priority (avoid realtime though) */
+ set_thread_priority(find_thread(NULL), B_DISPLAY_PRIORITY+1);
+#ifdef HAVE_BSOUNDRECORDER
+ if (!is_output) {
+ bool wait_for_input = false;
+ if (audio_device && !strcmp(audio_device, "wait:"))
+ wait_for_input = true;
+ s->recorder = new BSoundRecorder(&iformat, wait_for_input, "ffmpeg input", audiorecord_callback);
+ if (wait_for_input && (s->recorder->InitCheck() == B_OK)) {
+ s->recorder->WaitForIncomingConnection(&iformat);
+ }
+ if (s->recorder->InitCheck() != B_OK || iformat.format != media_raw_audio_format::B_AUDIO_SHORT) {
+ delete s->recorder;
+ s->recorder = NULL;
+ if (s->input_sem)
+ delete_sem(s->input_sem);
+ if (s->output_sem)
+ delete_sem(s->output_sem);
+ return AVERROR(EIO);
+ }
+ s->codec_id = (iformat.byte_order == B_MEDIA_LITTLE_ENDIAN)?CODEC_ID_PCM_S16LE:CODEC_ID_PCM_S16BE;
+ s->channels = iformat.channel_count;
+ s->sample_rate = (int)iformat.frame_rate;
+ s->frame_size = iformat.buffer_size;
+ s->recorder->SetCookie(s);
+ s->recorder->SetVolume(1.0);
+ s->recorder->Start();
+ return 0;
+ }
+#endif
+ format = media_raw_audio_format::wildcard;
+ format.format = media_raw_audio_format::B_AUDIO_SHORT;
+ format.byte_order = B_HOST_IS_LENDIAN ? B_MEDIA_LITTLE_ENDIAN : B_MEDIA_BIG_ENDIAN;
+ format.channel_count = s->channels;
+ format.buffer_size = s->frame_size;
+ format.frame_rate = s->sample_rate;
+ s->player = new BSoundPlayer(&format, "ffmpeg output", audioplay_callback);
+ if (s->player->InitCheck() != B_OK) {
+ delete s->player;
+ s->player = NULL;
+ if (s->input_sem)
+ delete_sem(s->input_sem);
+ if (s->output_sem)
+ delete_sem(s->output_sem);
+ return AVERROR(EIO);
+ }
+ s->player->SetCookie(s);
+ s->player->SetVolume(1.0);
+ s->player->Start();
+ s->player->SetHasData(true);
+ return 0;
+}
+
+static int audio_close(AudioData *s)
+{
+ if (s->input_sem)
+ delete_sem(s->input_sem);
+ if (s->output_sem)
+ delete_sem(s->output_sem);
+ s->has_quit = 1;
+ if (s->player) {
+ s->player->Stop();
+ }
+ if (s->player)
+ delete s->player;
+#ifdef HAVE_BSOUNDRECORDER
+ if (s->recorder)
+ delete s->recorder;
+#endif
+ destroy_bapp_if_needed();
+ return 0;
+}
+
+/* sound output support */
+static int audio_write_header(AVFormatContext *s1)
+{
+ AudioData *s = (AudioData *)s1->priv_data;
+ AVStream *st;
+ int ret;
+
+ st = s1->streams[0];
+ s->sample_rate = st->codec->sample_rate;
+ s->channels = st->codec->channels;
+ ret = audio_open(s, 1, NULL);
+ if (ret < 0)
+ return AVERROR(EIO);
+ return 0;
+}
+
+static int audio_write_packet(AVFormatContext *s1, int stream_index,
+ const uint8_t *buf, int size, int64_t force_pts)
+{
+ AudioData *s = (AudioData *)s1->priv_data;
+ int len, ret;
+#ifdef LATENCY_CHECK
+bigtime_t lat1, lat2;
+lat1 = s->player->Latency();
+#endif
+#ifdef PERF_CHECK
+ bigtime_t t = s->starve_time;
+ s->starve_time = 0;
+ printf("starve_time: %lld \n", t);
+#endif
+ while (size > 0) {
+ int amount;
+ len = MIN(size, AUDIO_BLOCK_SIZE);
+ if (acquire_sem_etc(s->input_sem, len, B_CAN_INTERRUPT, 0LL) < B_OK)
+ return AVERROR(EIO);
+ amount = MIN(len, (AUDIO_BUFFER_SIZE - s->input_index));
+ memcpy(&s->buffer[s->input_index], buf, amount);
+ s->input_index += amount;
+ if (s->input_index >= AUDIO_BUFFER_SIZE) {
+ s->input_index %= AUDIO_BUFFER_SIZE;
+ memcpy(&s->buffer[s->input_index], buf + amount, len - amount);
+ s->input_index += len - amount;
+ }
+ release_sem_etc(s->output_sem, len, 0);
+ buf += len;
+ size -= len;
+ }
+#ifdef LATENCY_CHECK
+lat2 = s->player->Latency();
+printf("#### BSoundPlayer::Latency(): before= %lld, after= %lld\n", lat1, lat2);
+#endif
+ return 0;
+}
+
+static int audio_write_trailer(AVFormatContext *s1)
+{
+ AudioData *s = (AudioData *)s1->priv_data;
+
+ audio_close(s);
+ return 0;
+}
+
+/* grab support */
+
+static int audio_read_header(AVFormatContext *s1, AVFormatParameters *ap)
+{
+ AudioData *s = (AudioData *)s1->priv_data;
+ AVStream *st;
+ int ret;
+
+ if (!ap || ap->sample_rate <= 0 || ap->channels <= 0)
+ return -1;
+
+ st = av_new_stream(s1, 0);
+ if (!st) {
+ return AVERROR(ENOMEM);
+ }
+ s->sample_rate = ap->sample_rate;
+ s->channels = ap->channels;
+
+ ret = audio_open(s, 0, s1->filename);
+ if (ret < 0) {
+ av_free(st);
+ return AVERROR(EIO);
+ }
+ /* take real parameters */
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_id = s->codec_id;
+ st->codec->sample_rate = s->sample_rate;
+ st->codec->channels = s->channels;
+ return 0;
+ av_set_pts_info(s1, 48, 1, 1000000); /* 48 bits pts in us */
+}
+
+static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt)
+{
+ AudioData *s = (AudioData *)s1->priv_data;
+ int size;
+ size_t len, amount;
+ unsigned char *buf;
+ status_t err;
+
+ if (av_new_packet(pkt, s->frame_size) < 0)
+ return AVERROR(EIO);
+ buf = (unsigned char *)pkt->data;
+ size = pkt->size;
+ while (size > 0) {
+ len = MIN(AUDIO_BLOCK_SIZE, size);
+ //printf("acquire_sem(output, %d)\n", len);
+ while ((err=acquire_sem_etc(s->output_sem, len, B_CAN_INTERRUPT, 0LL)) == B_INTERRUPTED);
+ if (err < B_OK) {
+ av_free_packet(pkt);
+ return AVERROR(EIO);
+ }
+ amount = MIN(len, (AUDIO_BUFFER_SIZE - s->output_index));
+ memcpy(buf, &s->buffer[s->output_index], amount);
+ s->output_index += amount;
+ if (s->output_index >= AUDIO_BUFFER_SIZE) {
+ s->output_index %= AUDIO_BUFFER_SIZE;
+ memcpy(buf + amount, &s->buffer[s->output_index], len - amount);
+ s->output_index += len-amount;
+ s->output_index %= AUDIO_BUFFER_SIZE;
+ }
+ release_sem_etc(s->input_sem, len, 0);
+ //printf("release_sem(input, %d)\n", len);
+ buf += len;
+ size -= len;
+ }
+ //XXX: add pts info
+ return 0;
+}
+
+static int audio_read_close(AVFormatContext *s1)
+{
+ AudioData *s = (AudioData *)s1->priv_data;
+
+ audio_close(s);
+ return 0;
+}
+
+static AVInputFormat audio_demuxer = {
+ "audio_device",
+ "audio grab and output",
+ sizeof(AudioData),
+ NULL,
+ audio_read_header,
+ audio_read_packet,
+ audio_read_close,
+ NULL,
+ AVFMT_NOFILE,
+};
+
+AVOutputFormat audio_muxer = {
+ "audio_device",
+ "audio grab and output",
+ "",
+ "",
+ sizeof(AudioData),
+#ifdef WORDS_BIGENDIAN
+ CODEC_ID_PCM_S16BE,
+#else
+ CODEC_ID_PCM_S16LE,
+#endif
+ CODEC_ID_NONE,
+ audio_write_header,
+ audio_write_packet,
+ audio_write_trailer,
+ AVFMT_NOFILE,
+};
+
+extern "C" {
+
+int audio_init(void)
+{
+ main_thid = find_thread(NULL);
+ av_register_input_format(&audio_demuxer);
+ av_register_output_format(&audio_muxer);
+ return 0;
+}
+
+} // "C"
+
diff --git a/contrib/ffmpeg/libavformat/crc.c b/contrib/ffmpeg/libavformat/crc.c
new file mode 100644
index 000000000..bdbe8bcff
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/crc.c
@@ -0,0 +1,98 @@
+/*
+ * CRC decoder (for codec/format testing)
+ * 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
+ */
+#include "avformat.h"
+#include "adler32.h"
+
+#ifdef CONFIG_CRC_MUXER
+typedef struct CRCState {
+ uint32_t crcval;
+} CRCState;
+
+static int crc_write_header(struct AVFormatContext *s)
+{
+ CRCState *crc = s->priv_data;
+
+ /* init CRC */
+ crc->crcval = 1;
+
+ return 0;
+}
+
+static int crc_write_packet(struct AVFormatContext *s, AVPacket *pkt)
+{
+ CRCState *crc = s->priv_data;
+ crc->crcval = av_adler32_update(crc->crcval, pkt->data, pkt->size);
+ return 0;
+}
+
+static int crc_write_trailer(struct AVFormatContext *s)
+{
+ CRCState *crc = s->priv_data;
+ char buf[64];
+
+ snprintf(buf, sizeof(buf), "CRC=0x%08x\n", crc->crcval);
+ put_buffer(&s->pb, buf, strlen(buf));
+ put_flush_packet(&s->pb);
+ return 0;
+}
+#endif
+
+#ifdef CONFIG_FRAMECRC_MUXER
+static int framecrc_write_packet(struct AVFormatContext *s, AVPacket *pkt)
+{
+ uint32_t crc = av_adler32_update(0, pkt->data, pkt->size);
+ char buf[256];
+
+ snprintf(buf, sizeof(buf), "%d, %"PRId64", %d, 0x%08x\n", pkt->stream_index, pkt->dts, pkt->size, crc);
+ put_buffer(&s->pb, buf, strlen(buf));
+ put_flush_packet(&s->pb);
+ return 0;
+}
+#endif
+
+#ifdef CONFIG_CRC_MUXER
+AVOutputFormat crc_muxer = {
+ "crc",
+ "crc testing format",
+ NULL,
+ "",
+ sizeof(CRCState),
+ CODEC_ID_PCM_S16LE,
+ CODEC_ID_RAWVIDEO,
+ crc_write_header,
+ crc_write_packet,
+ crc_write_trailer,
+};
+#endif
+#ifdef CONFIG_FRAMECRC_MUXER
+AVOutputFormat framecrc_muxer = {
+ "framecrc",
+ "framecrc testing format",
+ NULL,
+ "",
+ 0,
+ CODEC_ID_PCM_S16LE,
+ CODEC_ID_RAWVIDEO,
+ NULL,
+ framecrc_write_packet,
+ NULL,
+};
+#endif
diff --git a/contrib/ffmpeg/libavformat/cutils.c b/contrib/ffmpeg/libavformat/cutils.c
new file mode 100644
index 000000000..45959ec39
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/cutils.c
@@ -0,0 +1,275 @@
+/*
+ * Various simple utilities for ffmpeg system
+ * Copyright (c) 2000, 2001, 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
+ */
+#include "avformat.h"
+
+#if !defined(CONFIG_NOCUTILS)
+/**
+ * Return TRUE if val is a prefix of str. If it returns TRUE, ptr is
+ * set to the next character in 'str' after the prefix.
+ *
+ * @param str input string
+ * @param val prefix to test
+ * @param ptr updated after the prefix in str in there is a match
+ * @return TRUE if there is a match
+ */
+int strstart(const char *str, const char *val, const char **ptr)
+{
+ const char *p, *q;
+ p = str;
+ q = val;
+ while (*q != '\0') {
+ if (*p != *q)
+ return 0;
+ p++;
+ q++;
+ }
+ if (ptr)
+ *ptr = p;
+ return 1;
+}
+
+/**
+ * Return TRUE if val is a prefix of str (case independent). If it
+ * returns TRUE, ptr is set to the next character in 'str' after the
+ * prefix.
+ *
+ * @param str input string
+ * @param val prefix to test
+ * @param ptr updated after the prefix in str in there is a match
+ * @return TRUE if there is a match */
+int stristart(const char *str, const char *val, const char **ptr)
+{
+ const char *p, *q;
+ p = str;
+ q = val;
+ while (*q != '\0') {
+ if (toupper(*(const unsigned char *)p) != toupper(*(const unsigned char *)q))
+ return 0;
+ p++;
+ q++;
+ }
+ if (ptr)
+ *ptr = p;
+ return 1;
+}
+
+/**
+ * Copy the string str to buf. If str length is bigger than buf_size -
+ * 1 then it is clamped to buf_size - 1.
+ * NOTE: this function does what strncpy should have done to be
+ * useful. NEVER use strncpy.
+ *
+ * @param buf destination buffer
+ * @param buf_size size of destination buffer
+ * @param str source string
+ */
+void pstrcpy(char *buf, int buf_size, const char *str)
+{
+ int c;
+ char *q = buf;
+
+ if (buf_size <= 0)
+ return;
+
+ for(;;) {
+ c = *str++;
+ if (c == 0 || q >= buf + buf_size - 1)
+ break;
+ *q++ = c;
+ }
+ *q = '\0';
+}
+
+/* strcat and truncate. */
+char *pstrcat(char *buf, int buf_size, const char *s)
+{
+ int len;
+ len = strlen(buf);
+ if (len < buf_size)
+ pstrcpy(buf + len, buf_size - len, s);
+ return buf;
+}
+
+#endif
+
+/* add one element to a dynamic array */
+void __dynarray_add(unsigned long **tab_ptr, int *nb_ptr, unsigned long elem)
+{
+ int nb, nb_alloc;
+ unsigned long *tab;
+
+ nb = *nb_ptr;
+ tab = *tab_ptr;
+ if ((nb & (nb - 1)) == 0) {
+ if (nb == 0)
+ nb_alloc = 1;
+ else
+ nb_alloc = nb * 2;
+ tab = av_realloc(tab, nb_alloc * sizeof(unsigned long));
+ *tab_ptr = tab;
+ }
+ tab[nb++] = elem;
+ *nb_ptr = nb;
+}
+
+time_t mktimegm(struct tm *tm)
+{
+ time_t t;
+
+ int y = tm->tm_year + 1900, m = tm->tm_mon + 1, d = tm->tm_mday;
+
+ if (m < 3) {
+ m += 12;
+ y--;
+ }
+
+ t = 86400 *
+ (d + (153 * m - 457) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 719469);
+
+ t += 3600 * tm->tm_hour + 60 * tm->tm_min + tm->tm_sec;
+
+ return t;
+}
+
+#define ISLEAP(y) (((y) % 4 == 0) && (((y) % 100) != 0 || ((y) % 400) == 0))
+#define LEAPS_COUNT(y) ((y)/4 - (y)/100 + (y)/400)
+
+/* this is our own gmtime_r. it differs from its POSIX counterpart in a
+ couple of places, though. */
+struct tm *brktimegm(time_t secs, struct tm *tm)
+{
+ int days, y, ny, m;
+ int md[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
+
+ days = secs / 86400;
+ secs %= 86400;
+ tm->tm_hour = secs / 3600;
+ tm->tm_min = (secs % 3600) / 60;
+ tm->tm_sec = secs % 60;
+
+ /* oh well, may be someone some day will invent a formula for this stuff */
+ y = 1970; /* start "guessing" */
+ while (days >= (ISLEAP(y)?366:365)) {
+ ny = (y + days/366);
+ days -= (ny - y) * 365 + LEAPS_COUNT(ny - 1) - LEAPS_COUNT(y - 1);
+ y = ny;
+ }
+ md[1] = ISLEAP(y)?29:28;
+ for (m=0; days >= md[m]; m++)
+ days -= md[m];
+
+ tm->tm_year = y; /* unlike gmtime_r we store complete year here */
+ tm->tm_mon = m+1; /* unlike gmtime_r tm_mon is from 1 to 12 */
+ tm->tm_mday = days+1;
+
+ return tm;
+}
+
+/* get a positive number between n_min and n_max, for a maximum length
+ of len_max. Return -1 if error. */
+static int date_get_num(const char **pp,
+ int n_min, int n_max, int len_max)
+{
+ int i, val, c;
+ const char *p;
+
+ p = *pp;
+ val = 0;
+ for(i = 0; i < len_max; i++) {
+ c = *p;
+ if (!isdigit(c))
+ break;
+ val = (val * 10) + c - '0';
+ p++;
+ }
+ /* no number read ? */
+ if (p == *pp)
+ return -1;
+ if (val < n_min || val > n_max)
+ return -1;
+ *pp = p;
+ return val;
+}
+
+/* small strptime for ffmpeg */
+const char *small_strptime(const char *p, const char *fmt,
+ struct tm *dt)
+{
+ int c, val;
+
+ for(;;) {
+ c = *fmt++;
+ if (c == '\0') {
+ return p;
+ } else if (c == '%') {
+ c = *fmt++;
+ switch(c) {
+ case 'H':
+ val = date_get_num(&p, 0, 23, 2);
+ if (val == -1)
+ return NULL;
+ dt->tm_hour = val;
+ break;
+ case 'M':
+ val = date_get_num(&p, 0, 59, 2);
+ if (val == -1)
+ return NULL;
+ dt->tm_min = val;
+ break;
+ case 'S':
+ val = date_get_num(&p, 0, 59, 2);
+ if (val == -1)
+ return NULL;
+ dt->tm_sec = val;
+ break;
+ case 'Y':
+ val = date_get_num(&p, 0, 9999, 4);
+ if (val == -1)
+ return NULL;
+ dt->tm_year = val - 1900;
+ break;
+ case 'm':
+ val = date_get_num(&p, 1, 12, 2);
+ if (val == -1)
+ return NULL;
+ dt->tm_mon = val - 1;
+ break;
+ case 'd':
+ val = date_get_num(&p, 1, 31, 2);
+ if (val == -1)
+ return NULL;
+ dt->tm_mday = val;
+ break;
+ case '%':
+ goto match;
+ default:
+ return NULL;
+ }
+ } else {
+ match:
+ if (c != *p)
+ return NULL;
+ p++;
+ }
+ }
+ return p;
+}
+
diff --git a/contrib/ffmpeg/libavformat/daud.c b/contrib/ffmpeg/libavformat/daud.c
new file mode 100644
index 000000000..ec81b7b1c
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/daud.c
@@ -0,0 +1,58 @@
+/*
+ * D-Cinema audio demuxer
+ * Copyright (c) 2005 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 "avformat.h"
+
+static int daud_header(AVFormatContext *s, AVFormatParameters *ap) {
+ AVStream *st = av_new_stream(s, 0);
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_id = CODEC_ID_PCM_S24DAUD;
+ st->codec->codec_tag = MKTAG('d', 'a', 'u', 'd');
+ st->codec->channels = 6;
+ st->codec->sample_rate = 96000;
+ st->codec->bit_rate = 3 * 6 * 96000 * 8;
+ st->codec->block_align = 3 * 6;
+ st->codec->bits_per_sample = 24;
+ return 0;
+}
+
+static int daud_packet(AVFormatContext *s, AVPacket *pkt) {
+ ByteIOContext *pb = &s->pb;
+ int ret, size;
+ if (url_feof(pb))
+ return AVERROR_IO;
+ size = get_be16(pb);
+ get_be16(pb); // unknown
+ ret = av_get_packet(pb, pkt, size);
+ pkt->stream_index = 0;
+ return ret;
+}
+
+AVInputFormat daud_demuxer = {
+ "daud",
+ "D-Cinema audio format",
+ 0,
+ NULL,
+ daud_header,
+ daud_packet,
+ NULL,
+ NULL,
+ .extensions = "302",
+};
diff --git a/contrib/ffmpeg/libavformat/dc1394.c b/contrib/ffmpeg/libavformat/dc1394.c
new file mode 100644
index 000000000..bf140c466
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/dc1394.c
@@ -0,0 +1,193 @@
+/*
+ * IIDC1394 grab interface (uses libdc1394 and libraw1394)
+ * Copyright (c) 2004 Roman Shaposhnik
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 <libraw1394/raw1394.h>
+#include <libdc1394/dc1394_control.h>
+
+#undef free
+
+typedef struct dc1394_data {
+ raw1394handle_t handle;
+ dc1394_cameracapture camera;
+ int current_frame;
+ int fps;
+
+ AVPacket packet;
+} dc1394_data;
+
+struct dc1394_frame_format {
+ int width;
+ int height;
+ enum PixelFormat pix_fmt;
+ int frame_size_id;
+} dc1394_frame_formats[] = {
+ { 320, 240, PIX_FMT_UYVY422, MODE_320x240_YUV422 },
+ { 640, 480, PIX_FMT_UYYVYY411, MODE_640x480_YUV411 },
+ { 640, 480, PIX_FMT_UYVY422, MODE_640x480_YUV422 },
+ { 0, 0, 0, MODE_320x240_YUV422 } /* default -- gotta be the last one */
+};
+
+struct dc1394_frame_rate {
+ int frame_rate;
+ int frame_rate_id;
+} dc1394_frame_rates[] = {
+ { 1875, FRAMERATE_1_875 },
+ { 3750, FRAMERATE_3_75 },
+ { 7500, FRAMERATE_7_5 },
+ { 15000, FRAMERATE_15 },
+ { 30000, FRAMERATE_30 },
+ { 60000, FRAMERATE_60 },
+ { 0, FRAMERATE_30 } /* default -- gotta be the last one */
+};
+
+static int dc1394_read_header(AVFormatContext *c, AVFormatParameters * ap)
+{
+ dc1394_data* dc1394 = c->priv_data;
+ AVStream* vst;
+ nodeid_t* camera_nodes;
+ int res;
+ struct dc1394_frame_format *fmt;
+ struct dc1394_frame_rate *fps;
+
+ for (fmt = dc1394_frame_formats; fmt->width; fmt++)
+ if (fmt->pix_fmt == ap->pix_fmt && fmt->width == ap->width && fmt->height == ap->height)
+ break;
+
+ for (fps = dc1394_frame_rates; fps->frame_rate; fps++)
+ if (fps->frame_rate == av_rescale(1000, ap->time_base.den, ap->time_base.num))
+ break;
+
+ /* create a video stream */
+ vst = av_new_stream(c, 0);
+ if (!vst)
+ return -1;
+ av_set_pts_info(vst, 64, 1, 1000);
+ vst->codec->codec_type = CODEC_TYPE_VIDEO;
+ vst->codec->codec_id = CODEC_ID_RAWVIDEO;
+ vst->codec->time_base.den = fps->frame_rate;
+ vst->codec->time_base.num = 1000;
+ vst->codec->width = fmt->width;
+ vst->codec->height = fmt->height;
+ vst->codec->pix_fmt = fmt->pix_fmt;
+
+ /* packet init */
+ av_init_packet(&dc1394->packet);
+ dc1394->packet.size = avpicture_get_size(fmt->pix_fmt, fmt->width, fmt->height);
+ dc1394->packet.stream_index = vst->index;
+ dc1394->packet.flags |= PKT_FLAG_KEY;
+
+ dc1394->current_frame = 0;
+ dc1394->fps = fps->frame_rate;
+
+ vst->codec->bit_rate = av_rescale(dc1394->packet.size * 8, fps->frame_rate, 1000);
+
+ /* Now lets prep the hardware */
+ dc1394->handle = dc1394_create_handle(0); /* FIXME: gotta have ap->port */
+ if (!dc1394->handle) {
+ av_log(c, AV_LOG_ERROR, "Can't acquire dc1394 handle on port %d\n", 0 /* ap->port */);
+ goto out;
+ }
+ camera_nodes = dc1394_get_camera_nodes(dc1394->handle, &res, 1);
+ if (!camera_nodes || camera_nodes[ap->channel] == DC1394_NO_CAMERA) {
+ av_log(c, AV_LOG_ERROR, "There's no IIDC camera on the channel %d\n", ap->channel);
+ goto out_handle;
+ }
+ res = dc1394_dma_setup_capture(dc1394->handle, camera_nodes[ap->channel],
+ 0,
+ FORMAT_VGA_NONCOMPRESSED,
+ fmt->frame_size_id,
+ SPEED_400,
+ fps->frame_rate_id, 8, 1,
+ c->filename,
+ &dc1394->camera);
+ dc1394_free_camera_nodes(camera_nodes);
+ if (res != DC1394_SUCCESS) {
+ av_log(c, AV_LOG_ERROR, "Can't prepare camera for the DMA capture\n");
+ goto out_handle;
+ }
+
+ res = dc1394_start_iso_transmission(dc1394->handle, dc1394->camera.node);
+ if (res != DC1394_SUCCESS) {
+ av_log(c, AV_LOG_ERROR, "Can't start isochronous transmission\n");
+ goto out_handle_dma;
+ }
+
+ return 0;
+
+out_handle_dma:
+ dc1394_dma_unlisten(dc1394->handle, &dc1394->camera);
+ dc1394_dma_release_camera(dc1394->handle, &dc1394->camera);
+out_handle:
+ dc1394_destroy_handle(dc1394->handle);
+out:
+ return -1;
+}
+
+static int dc1394_read_packet(AVFormatContext *c, AVPacket *pkt)
+{
+ struct dc1394_data *dc1394 = c->priv_data;
+ int res;
+
+ /* discard stale frame */
+ if (dc1394->current_frame++) {
+ if (dc1394_dma_done_with_buffer(&dc1394->camera) != DC1394_SUCCESS)
+ av_log(c, AV_LOG_ERROR, "failed to release %d frame\n", dc1394->current_frame);
+ }
+
+ res = dc1394_dma_single_capture(&dc1394->camera);
+
+ if (res == DC1394_SUCCESS) {
+ dc1394->packet.data = (uint8_t *)(dc1394->camera.capture_buffer);
+ dc1394->packet.pts = (dc1394->current_frame * 1000000) / dc1394->fps;
+ res = dc1394->packet.size;
+ } else {
+ av_log(c, AV_LOG_ERROR, "DMA capture failed\n");
+ dc1394->packet.data = NULL;
+ res = -1;
+ }
+
+ *pkt = dc1394->packet;
+ return res;
+}
+
+static int dc1394_close(AVFormatContext * context)
+{
+ struct dc1394_data *dc1394 = context->priv_data;
+
+ dc1394_stop_iso_transmission(dc1394->handle, dc1394->camera.node);
+ dc1394_dma_unlisten(dc1394->handle, &dc1394->camera);
+ dc1394_dma_release_camera(dc1394->handle, &dc1394->camera);
+ dc1394_destroy_handle(dc1394->handle);
+
+ return 0;
+}
+
+AVInputFormat dc1394_demuxer = {
+ .name = "dc1394",
+ .long_name = "dc1394 A/V grab",
+ .priv_data_size = sizeof(struct dc1394_data),
+ .read_header = dc1394_read_header,
+ .read_packet = dc1394_read_packet,
+ .read_close = dc1394_close,
+ .flags = AVFMT_NOFILE
+};
diff --git a/contrib/ffmpeg/libavformat/dsicin.c b/contrib/ffmpeg/libavformat/dsicin.c
new file mode 100644
index 000000000..fb9cb50df
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/dsicin.c
@@ -0,0 +1,224 @@
+/*
+ * Delphine Software International CIN File Demuxer
+ * Copyright (c) 2006 Gregory Montoir (cyx@users.sourceforge.net)
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 dsicin.c
+ * Delphine Software International CIN file demuxer
+ */
+
+#include "avformat.h"
+
+
+typedef struct CinFileHeader {
+ int video_frame_size;
+ int video_frame_width;
+ int video_frame_height;
+ int audio_frequency;
+ int audio_bits;
+ int audio_stereo;
+ int audio_frame_size;
+} CinFileHeader;
+
+typedef struct CinFrameHeader {
+ int audio_frame_type;
+ int video_frame_type;
+ int pal_colors_count;
+ int audio_frame_size;
+ int video_frame_size;
+} CinFrameHeader;
+
+typedef struct CinDemuxContext {
+ int audio_stream_index;
+ int video_stream_index;
+ CinFileHeader file_header;
+ int64_t audio_stream_pts;
+ int64_t video_stream_pts;
+ CinFrameHeader frame_header;
+ int audio_buffer_size;
+} CinDemuxContext;
+
+
+static int cin_probe(AVProbeData *p)
+{
+ if (p->buf_size < 18)
+ return 0;
+
+ /* header starts with this special marker */
+ if (AV_RL32(&p->buf[0]) != 0x55AA0000)
+ return 0;
+
+ /* for accuracy, check some header field values */
+ if (AV_RL32(&p->buf[12]) != 22050 || p->buf[16] != 16 || p->buf[17] != 0)
+ return 0;
+
+ return AVPROBE_SCORE_MAX;
+}
+
+static int cin_read_file_header(CinDemuxContext *cin, ByteIOContext *pb) {
+ CinFileHeader *hdr = &cin->file_header;
+
+ if (get_le32(pb) != 0x55AA0000)
+ return AVERROR_INVALIDDATA;
+
+ hdr->video_frame_size = get_le32(pb);
+ hdr->video_frame_width = get_le16(pb);
+ hdr->video_frame_height = get_le16(pb);
+ hdr->audio_frequency = get_le32(pb);
+ hdr->audio_bits = get_byte(pb);
+ hdr->audio_stereo = get_byte(pb);
+ hdr->audio_frame_size = get_le16(pb);
+
+ if (hdr->audio_frequency != 22050 || hdr->audio_bits != 16 || hdr->audio_stereo != 0)
+ return AVERROR_INVALIDDATA;
+
+ return 0;
+}
+
+static int cin_read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+ int rc;
+ CinDemuxContext *cin = (CinDemuxContext *)s->priv_data;
+ CinFileHeader *hdr = &cin->file_header;
+ ByteIOContext *pb = &s->pb;
+ AVStream *st;
+
+ rc = cin_read_file_header(cin, pb);
+ if (rc)
+ return rc;
+
+ cin->video_stream_pts = 0;
+ cin->audio_stream_pts = 0;
+ cin->audio_buffer_size = 0;
+
+ /* initialize the video decoder stream */
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+
+ av_set_pts_info(st, 32, 1, 12);
+ cin->video_stream_index = st->index;
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ st->codec->codec_id = CODEC_ID_DSICINVIDEO;
+ st->codec->codec_tag = 0; /* no fourcc */
+ st->codec->width = hdr->video_frame_width;
+ st->codec->height = hdr->video_frame_height;
+
+ /* initialize the audio decoder stream */
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+
+ av_set_pts_info(st, 32, 1, 22050);
+ cin->audio_stream_index = st->index;
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_id = CODEC_ID_DSICINAUDIO;
+ st->codec->codec_tag = 0; /* no tag */
+ st->codec->channels = 1;
+ st->codec->sample_rate = 22050;
+ st->codec->bits_per_sample = 16;
+ st->codec->bit_rate = st->codec->sample_rate * st->codec->bits_per_sample * st->codec->channels;
+ st->codec->block_align = st->codec->channels * st->codec->bits_per_sample;
+
+ return 0;
+}
+
+static int cin_read_frame_header(CinDemuxContext *cin, ByteIOContext *pb) {
+ CinFrameHeader *hdr = &cin->frame_header;
+
+ hdr->video_frame_type = get_byte(pb);
+ hdr->audio_frame_type = get_byte(pb);
+ hdr->pal_colors_count = get_le16(pb);
+ hdr->video_frame_size = get_le32(pb);
+ hdr->audio_frame_size = get_le32(pb);
+
+ if (url_feof(pb) || url_ferror(pb))
+ return AVERROR_IO;
+
+ if (get_le32(pb) != 0xAA55AA55)
+ return AVERROR_INVALIDDATA;
+
+ return 0;
+}
+
+static int cin_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ CinDemuxContext *cin = (CinDemuxContext *)s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ CinFrameHeader *hdr = &cin->frame_header;
+ int rc, palette_type, pkt_size;
+
+ if (cin->audio_buffer_size == 0) {
+ rc = cin_read_frame_header(cin, pb);
+ if (rc)
+ return rc;
+
+ if ((int16_t)hdr->pal_colors_count < 0) {
+ hdr->pal_colors_count = -(int16_t)hdr->pal_colors_count;
+ palette_type = 1;
+ } else {
+ palette_type = 0;
+ }
+
+ /* 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_NOMEM;
+
+ pkt->stream_index = cin->video_stream_index;
+ pkt->pts = cin->video_stream_pts++;
+
+ pkt->data[0] = palette_type;
+ pkt->data[1] = hdr->pal_colors_count & 0xFF;
+ 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_IO;
+
+ /* sound buffer will be processed on next read_packet() call */
+ cin->audio_buffer_size = hdr->audio_frame_size;
+ return 0;
+ }
+
+ /* audio packet */
+ if (av_new_packet(pkt, cin->audio_buffer_size))
+ return AVERROR_NOMEM;
+
+ 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_IO;
+
+ cin->audio_buffer_size = 0;
+ return 0;
+}
+
+AVInputFormat dsicin_demuxer = {
+ "dsicin",
+ "Delphine Software International CIN format",
+ sizeof(CinDemuxContext),
+ cin_probe,
+ cin_read_header,
+ cin_read_packet,
+};
diff --git a/contrib/ffmpeg/libavformat/dv.c b/contrib/ffmpeg/libavformat/dv.c
new file mode 100644
index 000000000..10a306260
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/dv.c
@@ -0,0 +1,451 @@
+/*
+ * General DV muxer/demuxer
+ * Copyright (c) 2003 Roman Shaposhnik
+ *
+ * Many thanks to Dan Dennedy <dan@dennedy.org> for providing wealth
+ * of DV technical info.
+ *
+ * Raw DV format
+ * Copyright (c) 2002 Fabrice Bellard.
+ *
+ * 50 Mbps (DVCPRO50) support
+ * Copyright (c) 2006 Daniel Maas <dmaas@maasdigital.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include <time.h>
+#include "avformat.h"
+#include "dvdata.h"
+#include "dv.h"
+
+struct DVDemuxContext {
+ const DVprofile* sys; /* Current DV profile. E.g.: 525/60, 625/50 */
+ AVFormatContext* fctx;
+ AVStream* vst;
+ AVStream* ast[2];
+ AVPacket audio_pkt[2];
+ uint8_t audio_buf[2][8192];
+ int ach;
+ int frames;
+ uint64_t abytes;
+};
+
+static inline uint16_t dv_audio_12to16(uint16_t sample)
+{
+ uint16_t shift, result;
+
+ sample = (sample < 0x800) ? sample : sample | 0xf000;
+ shift = (sample & 0xf00) >> 8;
+
+ if (shift < 0x2 || shift > 0xd) {
+ result = sample;
+ } else if (shift < 0x8) {
+ shift--;
+ result = (sample - (256 * shift)) << shift;
+ } else {
+ shift = 0xe - shift;
+ result = ((sample + ((256 * shift) + 1)) << shift) - 1;
+ }
+
+ return result;
+}
+
+/*
+ * This is the dumbest implementation of all -- it simply looks at
+ * a fixed offset and if pack isn't there -- fails. We might want
+ * to have a fallback mechanism for complete search of missing packs.
+ */
+static const uint8_t* dv_extract_pack(uint8_t* frame, enum dv_pack_type t)
+{
+ int offs;
+
+ switch (t) {
+ case dv_audio_source:
+ offs = (80*6 + 80*16*3 + 3);
+ break;
+ case dv_audio_control:
+ offs = (80*6 + 80*16*4 + 3);
+ break;
+ case dv_video_control:
+ offs = (80*5 + 48 + 5);
+ break;
+ default:
+ return NULL;
+ }
+
+ return (frame[offs] == t ? &frame[offs] : NULL);
+}
+
+/*
+ * There's a couple of assumptions being made here:
+ * 1. By default we silence erroneous (0x8000/16bit 0x800/12bit) audio samples.
+ * We can pass them upwards when ffmpeg will be ready to deal with them.
+ * 2. We don't do software emphasis.
+ * 3. Audio is always returned as 16bit linear samples: 12bit nonlinear samples
+ * are converted into 16bit linear ones.
+ */
+static int dv_extract_audio(uint8_t* frame, uint8_t* pcm, uint8_t* pcm2,
+ const DVprofile *sys)
+{
+ int size, chan, i, j, d, of, smpls, freq, quant, half_ch;
+ uint16_t lc, rc;
+ const uint8_t* as_pack;
+
+ as_pack = dv_extract_pack(frame, dv_audio_source);
+ if (!as_pack) /* No audio ? */
+ return 0;
+
+ smpls = as_pack[1] & 0x3f; /* samples in this frame - min. samples */
+ freq = (as_pack[4] >> 3) & 0x07; /* 0 - 48KHz, 1 - 44,1kHz, 2 - 32 kHz */
+ quant = as_pack[4] & 0x07; /* 0 - 16bit linear, 1 - 12bit nonlinear */
+
+ if (quant > 1)
+ return -1; /* Unsupported quantization */
+
+ size = (sys->audio_min_samples[freq] + smpls) * 4; /* 2ch, 2bytes */
+ half_ch = sys->difseg_size/2;
+
+ /* for each DIF channel */
+ for (chan = 0; chan < sys->n_difchan; chan++) {
+ /* for each DIF segment */
+ for (i = 0; i < sys->difseg_size; i++) {
+ frame += 6 * 80; /* skip DIF segment header */
+ if (quant == 1 && i == half_ch) {
+ /* next stereo channel (12bit mode only) */
+ if (!pcm2)
+ break;
+ else
+ pcm = pcm2;
+ }
+
+ /* for each AV sequence */
+ for (j = 0; j < 9; j++) {
+ for (d = 8; d < 80; d += 2) {
+ if (quant == 0) { /* 16bit quantization */
+ of = sys->audio_shuffle[i][j] + (d - 8)/2 * sys->audio_stride;
+ if (of*2 >= size)
+ continue;
+
+ pcm[of*2] = frame[d+1]; // FIXME: may be we have to admit
+ pcm[of*2+1] = frame[d]; // that DV is a big endian PCM
+ if (pcm[of*2+1] == 0x80 && pcm[of*2] == 0x00)
+ pcm[of*2+1] = 0;
+ } else { /* 12bit quantization */
+ lc = ((uint16_t)frame[d] << 4) |
+ ((uint16_t)frame[d+2] >> 4);
+ rc = ((uint16_t)frame[d+1] << 4) |
+ ((uint16_t)frame[d+2] & 0x0f);
+ lc = (lc == 0x800 ? 0 : dv_audio_12to16(lc));
+ rc = (rc == 0x800 ? 0 : dv_audio_12to16(rc));
+
+ of = sys->audio_shuffle[i%half_ch][j] + (d - 8)/3 * sys->audio_stride;
+ if (of*2 >= size)
+ continue;
+
+ pcm[of*2] = lc & 0xff; // FIXME: may be we have to admit
+ pcm[of*2+1] = lc >> 8; // that DV is a big endian PCM
+ of = sys->audio_shuffle[i%half_ch+half_ch][j] +
+ (d - 8)/3 * sys->audio_stride;
+ pcm[of*2] = rc & 0xff; // FIXME: may be we have to admit
+ pcm[of*2+1] = rc >> 8; // that DV is a big endian PCM
+ ++d;
+ }
+ }
+
+ frame += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */
+ }
+ }
+
+ /* next stereo channel (50Mbps only) */
+ if(!pcm2)
+ break;
+ pcm = pcm2;
+ }
+
+ return size;
+}
+
+static int dv_extract_audio_info(DVDemuxContext* c, uint8_t* frame)
+{
+ const uint8_t* as_pack;
+ int freq, stype, smpls, quant, i, ach;
+
+ as_pack = dv_extract_pack(frame, dv_audio_source);
+ if (!as_pack || !c->sys) { /* No audio ? */
+ c->ach = 0;
+ return 0;
+ }
+
+ smpls = as_pack[1] & 0x3f; /* samples in this frame - min. samples */
+ freq = (as_pack[4] >> 3) & 0x07; /* 0 - 48KHz, 1 - 44,1kHz, 2 - 32 kHz */
+ stype = (as_pack[3] & 0x1f); /* 0 - 2CH, 2 - 4CH */
+ quant = as_pack[4] & 0x07; /* 0 - 16bit linear, 1 - 12bit nonlinear */
+
+ /* note: ach counts PAIRS of channels (i.e. stereo channels) */
+ ach = (stype == 2 || (quant && (freq == 2))) ? 2 : 1;
+
+ /* Dynamic handling of the audio streams in DV */
+ for (i=0; i<ach; i++) {
+ if (!c->ast[i]) {
+ c->ast[i] = av_new_stream(c->fctx, 0);
+ 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_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->ast[i]->codec->sample_rate = dv_audio_frequency[freq];
+ c->ast[i]->codec->channels = 2;
+ c->ast[i]->codec->bit_rate = 2 * dv_audio_frequency[freq] * 16;
+ c->ast[i]->start_time = 0;
+ }
+ c->ach = i;
+
+ return (c->sys->audio_min_samples[freq] + smpls) * 4; /* 2ch, 2bytes */;
+}
+
+static int dv_extract_video_info(DVDemuxContext *c, uint8_t* frame)
+{
+ const uint8_t* vsc_pack;
+ AVCodecContext* avctx;
+ int apt, is16_9;
+ int size = 0;
+
+ if (c->sys) {
+ avctx = c->vst->codec;
+
+ av_set_pts_info(c->vst, 64, c->sys->frame_rate_base, c->sys->frame_rate);
+ avctx->time_base= (AVRational){c->sys->frame_rate_base, c->sys->frame_rate};
+ if(!avctx->width){
+ avctx->width = c->sys->width;
+ avctx->height = c->sys->height;
+ }
+ avctx->pix_fmt = c->sys->pix_fmt;
+
+ /* finding out SAR is a little bit messy */
+ vsc_pack = dv_extract_pack(frame, dv_video_control);
+ apt = frame[4] & 0x07;
+ is16_9 = (vsc_pack && ((vsc_pack[2] & 0x07) == 0x02 ||
+ (!apt && (vsc_pack[2] & 0x07) == 0x07)));
+ avctx->sample_aspect_ratio = c->sys->sar[is16_9];
+ avctx->bit_rate = av_rescale(c->sys->frame_size * 8,
+ c->sys->frame_rate,
+ c->sys->frame_rate_base);
+ size = c->sys->frame_size;
+ }
+ return size;
+}
+
+/*
+ * The following 3 functions constitute our interface to the world
+ */
+
+DVDemuxContext* dv_init_demux(AVFormatContext *s)
+{
+ DVDemuxContext *c;
+
+ c = av_mallocz(sizeof(DVDemuxContext));
+ if (!c)
+ return NULL;
+
+ c->vst = av_new_stream(s, 0);
+ if (!c->vst) {
+ av_free(c);
+ return NULL;
+ }
+
+ c->sys = NULL;
+ c->fctx = s;
+ c->ast[0] = c->ast[1] = NULL;
+ c->ach = 0;
+ c->frames = 0;
+ c->abytes = 0;
+
+ c->vst->codec->codec_type = CODEC_TYPE_VIDEO;
+ c->vst->codec->codec_id = CODEC_ID_DVVIDEO;
+ c->vst->codec->bit_rate = 25000000;
+ c->vst->start_time = 0;
+
+ return c;
+}
+
+int dv_get_packet(DVDemuxContext *c, AVPacket *pkt)
+{
+ int size = -1;
+ int i;
+
+ for (i=0; i<c->ach; i++) {
+ if (c->ast[i] && c->audio_pkt[i].size) {
+ *pkt = c->audio_pkt[i];
+ c->audio_pkt[i].size = 0;
+ size = pkt->size;
+ break;
+ }
+ }
+
+ return size;
+}
+
+int dv_produce_packet(DVDemuxContext *c, AVPacket *pkt,
+ uint8_t* buf, int buf_size)
+{
+ int size, i;
+
+ if (buf_size < DV_PROFILE_BYTES ||
+ !(c->sys = dv_frame_profile(buf)) ||
+ buf_size < c->sys->frame_size) {
+ return -1; /* Broken frame, or not enough data */
+ }
+
+ /* Queueing audio packet */
+ /* FIXME: in case of no audio/bad audio we have to do something */
+ size = dv_extract_audio_info(c, buf);
+ for (i=0; i<c->ach; i++) {
+ c->audio_pkt[i].size = size;
+ c->audio_pkt[i].pts = c->abytes * 30000*8 / c->ast[i]->codec->bit_rate;
+ }
+ dv_extract_audio(buf, c->audio_buf[0], c->audio_buf[1], c->sys);
+ c->abytes += size;
+
+ /* Now it's time to return video packet */
+ size = dv_extract_video_info(c, buf);
+ av_init_packet(pkt);
+ pkt->data = buf;
+ pkt->size = size;
+ pkt->flags |= PKT_FLAG_KEY;
+ pkt->stream_index = c->vst->id;
+ pkt->pts = c->frames;
+
+ c->frames++;
+
+ return size;
+}
+
+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);
+ 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;
+ else if (offset < 0) offset = 0;
+
+ return offset;
+}
+
+void dv_offset_reset(DVDemuxContext *c, int64_t frame_offset)
+{
+ c->frames= frame_offset;
+ if (c->ach)
+ c->abytes= av_rescale(c->frames,
+ c->ast[0]->codec->bit_rate * (int64_t)c->sys->frame_rate_base,
+ 8*c->sys->frame_rate);
+ c->audio_pkt[0].size = c->audio_pkt[1].size = 0;
+}
+
+/************************************************************
+ * Implementation of the easiest DV storage of all -- raw DV.
+ ************************************************************/
+
+typedef struct RawDVContext {
+ DVDemuxContext* dv_demux;
+ uint8_t buf[DV_MAX_FRAME_SIZE];
+} RawDVContext;
+
+static int dv_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ RawDVContext *c = s->priv_data;
+
+ c->dv_demux = dv_init_demux(s);
+ if (!c->dv_demux)
+ return -1;
+
+ if (get_buffer(&s->pb, c->buf, DV_PROFILE_BYTES) <= 0 ||
+ url_fseek(&s->pb, -DV_PROFILE_BYTES, SEEK_CUR) < 0)
+ return AVERROR_IO;
+
+ c->dv_demux->sys = dv_frame_profile(c->buf);
+ s->bit_rate = av_rescale(c->dv_demux->sys->frame_size * 8,
+ c->dv_demux->sys->frame_rate,
+ c->dv_demux->sys->frame_rate_base);
+
+ return 0;
+}
+
+
+static int dv_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ int size;
+ RawDVContext *c = s->priv_data;
+
+ size = dv_get_packet(c->dv_demux, pkt);
+
+ if (size < 0) {
+ size = c->dv_demux->sys->frame_size;
+ if (get_buffer(&s->pb, c->buf, size) <= 0)
+ return AVERROR_IO;
+
+ size = dv_produce_packet(c->dv_demux, pkt, c->buf, size);
+ }
+
+ return size;
+}
+
+static int dv_read_seek(AVFormatContext *s, int stream_index,
+ int64_t timestamp, int flags)
+{
+ RawDVContext *r = s->priv_data;
+ DVDemuxContext *c = r->dv_demux;
+ int64_t offset= dv_frame_offset(s, c, timestamp, flags);
+
+ dv_offset_reset(c, offset / c->sys->frame_size);
+
+ return url_fseek(&s->pb, offset, SEEK_SET);
+}
+
+static int dv_read_close(AVFormatContext *s)
+{
+ RawDVContext *c = s->priv_data;
+ av_free(c->dv_demux);
+ return 0;
+}
+
+#ifdef CONFIG_DV_DEMUXER
+AVInputFormat dv_demuxer = {
+ "dv",
+ "DV video format",
+ sizeof(RawDVContext),
+ NULL,
+ dv_read_header,
+ dv_read_packet,
+ dv_read_close,
+ dv_read_seek,
+ .extensions = "dv,dif",
+};
+#endif
diff --git a/contrib/ffmpeg/libavformat/dv.h b/contrib/ffmpeg/libavformat/dv.h
new file mode 100644
index 000000000..2fa30036c
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/dv.h
@@ -0,0 +1,37 @@
+/*
+ * General DV muxer/demuxer
+ * Copyright (c) 2003 Roman Shaposhnik
+ *
+ * Many thanks to Dan Dennedy <dan@dennedy.org> for providing wealth
+ * of DV technical info.
+ *
+ * Raw DV format
+ * 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
+ */
+
+typedef struct DVDemuxContext DVDemuxContext;
+DVDemuxContext* dv_init_demux(AVFormatContext* s);
+int dv_get_packet(DVDemuxContext*, AVPacket *);
+int dv_produce_packet(DVDemuxContext*, AVPacket*, uint8_t*, int);
+void dv_offset_reset(DVDemuxContext *c, int64_t frame_offset);
+
+typedef struct DVMuxContext DVMuxContext;
+DVMuxContext* dv_init_mux(AVFormatContext* s);
+int dv_assemble_frame(DVMuxContext *c, AVStream*, const uint8_t*, int, uint8_t**);
+void dv_delete_mux(DVMuxContext*);
diff --git a/contrib/ffmpeg/libavformat/dv1394.c b/contrib/ffmpeg/libavformat/dv1394.c
new file mode 100644
index 000000000..3a5f479c8
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/dv1394.c
@@ -0,0 +1,236 @@
+/*
+ * Linux DV1394 interface
+ * Copyright (c) 2003 Max Krasnyansky <maxk@qualcomm.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/poll.h>
+#include <sys/time.h>
+#include <time.h>
+
+#include "avformat.h"
+
+#undef DV1394_DEBUG
+
+#include "dv1394.h"
+#include "dv.h"
+
+struct dv1394_data {
+ int fd;
+ int channel;
+ int format;
+
+ uint8_t *ring; /* Ring buffer */
+ int index; /* Current frame index */
+ int avail; /* Number of frames available for reading */
+ int done; /* Number of completed frames */
+
+ DVDemuxContext* dv_demux; /* Generic DV muxing/demuxing context */
+};
+
+/*
+ * The trick here is to kludge around well known problem with kernel Ooopsing
+ * when you try to capture PAL on a device node configure for NTSC. That's
+ * why we have to configure the device node for PAL, and then read only NTSC
+ * amount of data.
+ */
+static int dv1394_reset(struct dv1394_data *dv)
+{
+ struct dv1394_init init;
+
+ init.channel = dv->channel;
+ init.api_version = DV1394_API_VERSION;
+ init.n_frames = DV1394_RING_FRAMES;
+ init.format = DV1394_PAL;
+
+ if (ioctl(dv->fd, DV1394_INIT, &init) < 0)
+ return -1;
+
+ dv->avail = dv->done = 0;
+ return 0;
+}
+
+static int dv1394_start(struct dv1394_data *dv)
+{
+ /* Tell DV1394 driver to enable receiver */
+ if (ioctl(dv->fd, DV1394_START_RECEIVE, 0) < 0) {
+ perror("Failed to start receiver");
+ return -1;
+ }
+ return 0;
+}
+
+static int dv1394_read_header(AVFormatContext * context, AVFormatParameters * ap)
+{
+ struct dv1394_data *dv = context->priv_data;
+
+ dv->dv_demux = dv_init_demux(context);
+ if (!dv->dv_demux)
+ goto failed;
+
+ if (ap->standard && !strcasecmp(ap->standard, "pal"))
+ dv->format = DV1394_PAL;
+ else
+ dv->format = DV1394_NTSC;
+
+ if (ap->channel)
+ dv->channel = ap->channel;
+ else
+ dv->channel = DV1394_DEFAULT_CHANNEL;
+
+ /* Open and initialize DV1394 device */
+ dv->fd = open(context->filename, O_RDONLY);
+ if (dv->fd < 0) {
+ perror("Failed to open DV interface");
+ goto failed;
+ }
+
+ if (dv1394_reset(dv) < 0) {
+ perror("Failed to initialize DV interface");
+ goto failed;
+ }
+
+ dv->ring = mmap(NULL, DV1394_PAL_FRAME_SIZE * DV1394_RING_FRAMES,
+ PROT_READ, MAP_PRIVATE, dv->fd, 0);
+ if (dv->ring == MAP_FAILED) {
+ perror("Failed to mmap DV ring buffer");
+ goto failed;
+ }
+
+ if (dv1394_start(dv) < 0)
+ goto failed;
+
+ return 0;
+
+failed:
+ close(dv->fd);
+ return AVERROR_IO;
+}
+
+static int dv1394_read_packet(AVFormatContext *context, AVPacket *pkt)
+{
+ struct dv1394_data *dv = context->priv_data;
+ int size;
+
+ size = dv_get_packet(dv->dv_demux, pkt);
+ if (size > 0)
+ return size;
+
+ if (!dv->avail) {
+ struct dv1394_status s;
+ struct pollfd p;
+
+ if (dv->done) {
+ /* Request more frames */
+ if (ioctl(dv->fd, DV1394_RECEIVE_FRAMES, dv->done) < 0) {
+ /* This usually means that ring buffer overflowed.
+ * We have to reset :(.
+ */
+
+ av_log(context, AV_LOG_ERROR, "DV1394: Ring buffer overflow. Reseting ..\n");
+
+ dv1394_reset(dv);
+ dv1394_start(dv);
+ }
+ dv->done = 0;
+ }
+
+ /* Wait until more frames are available */
+restart_poll:
+ p.fd = dv->fd;
+ p.events = POLLIN | POLLERR | POLLHUP;
+ if (poll(&p, 1, -1) < 0) {
+ if (errno == EAGAIN || errno == EINTR)
+ goto restart_poll;
+ perror("Poll failed");
+ return AVERROR_IO;
+ }
+
+ if (ioctl(dv->fd, DV1394_GET_STATUS, &s) < 0) {
+ perror("Failed to get status");
+ return AVERROR_IO;
+ }
+#ifdef DV1394_DEBUG
+ av_log(context, AV_LOG_DEBUG, "DV1394: status\n"
+ "\tactive_frame\t%d\n"
+ "\tfirst_clear_frame\t%d\n"
+ "\tn_clear_frames\t%d\n"
+ "\tdropped_frames\t%d\n",
+ s.active_frame, s.first_clear_frame,
+ s.n_clear_frames, s.dropped_frames);
+#endif
+
+ dv->avail = s.n_clear_frames;
+ dv->index = s.first_clear_frame;
+ dv->done = 0;
+
+ if (s.dropped_frames) {
+ av_log(context, AV_LOG_ERROR, "DV1394: Frame drop detected (%d). Reseting ..\n",
+ s.dropped_frames);
+
+ dv1394_reset(dv);
+ dv1394_start(dv);
+ }
+ }
+
+#ifdef DV1394_DEBUG
+ av_log(context, AV_LOG_DEBUG, "index %d, avail %d, done %d\n", dv->index, dv->avail,
+ dv->done);
+#endif
+
+ size = dv_produce_packet(dv->dv_demux, pkt,
+ dv->ring + (dv->index * DV1394_PAL_FRAME_SIZE),
+ DV1394_PAL_FRAME_SIZE);
+ dv->index = (dv->index + 1) % DV1394_RING_FRAMES;
+ dv->done++; dv->avail--;
+
+ return size;
+}
+
+static int dv1394_close(AVFormatContext * context)
+{
+ struct dv1394_data *dv = context->priv_data;
+
+ /* Shutdown DV1394 receiver */
+ if (ioctl(dv->fd, DV1394_SHUTDOWN, 0) < 0)
+ perror("Failed to shutdown DV1394");
+
+ /* Unmap ring buffer */
+ if (munmap(dv->ring, DV1394_NTSC_FRAME_SIZE * DV1394_RING_FRAMES) < 0)
+ perror("Failed to munmap DV1394 ring buffer");
+
+ close(dv->fd);
+ av_free(dv->dv_demux);
+
+ return 0;
+}
+
+AVInputFormat dv1394_demuxer = {
+ .name = "dv1394",
+ .long_name = "dv1394 A/V grab",
+ .priv_data_size = sizeof(struct dv1394_data),
+ .read_header = dv1394_read_header,
+ .read_packet = dv1394_read_packet,
+ .read_close = dv1394_close,
+ .flags = AVFMT_NOFILE
+};
diff --git a/contrib/ffmpeg/libavformat/dv1394.h b/contrib/ffmpeg/libavformat/dv1394.h
new file mode 100644
index 000000000..f7db40108
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/dv1394.h
@@ -0,0 +1,357 @@
+/*
+ * dv1394.h - DV input/output over IEEE 1394 on OHCI chips
+ * Copyright (C)2001 Daniel Maas <dmaas@dcine.com>
+ * receive, proc_fs by Dan Dennedy <dan@dennedy.org>
+ *
+ * based on:
+ * video1394.h - driver for OHCI 1394 boards
+ * Copyright (C)1999,2000 Sebastien Rougeaux <sebastien.rougeaux@anu.edu.au>
+ * Peter Schlaile <udbz@rz.uni-karlsruhe.de>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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_1394_H
+#define _DV_1394_H
+
+#define DV1394_DEFAULT_CHANNEL 63
+#define DV1394_DEFAULT_CARD 0
+#define DV1394_RING_FRAMES 20
+
+#define DV1394_WIDTH 720
+#define DV1394_NTSC_HEIGHT 480
+#define DV1394_PAL_HEIGHT 576
+
+/* This is the public user-space interface. Try not to break it. */
+
+#define DV1394_API_VERSION 0x20011127
+
+/* ********************
+ ** **
+ ** DV1394 API **
+ ** **
+ ********************
+
+ There are two methods of operating the DV1394 DV output device.
+
+ 1)
+
+ The simplest is an interface based on write(): simply write
+ full DV frames of data to the device, and they will be transmitted
+ as quickly as possible. The FD may be set for non-blocking I/O,
+ in which case you can use select() or poll() to wait for output
+ buffer space.
+
+ To set the DV output parameters (e.g. whether you want NTSC or PAL
+ video), use the DV1394_INIT ioctl, passing in the parameters you
+ want in a struct dv1394_init.
+
+ Example 1:
+ To play a raw .DV file: cat foo.DV > /dev/dv1394
+ (cat will use write() internally)
+
+ Example 2:
+ static struct dv1394_init init = {
+ 0x63, (broadcast channel)
+ 4, (four-frame ringbuffer)
+ DV1394_NTSC, (send NTSC video)
+ 0, 0 (default empty packet rate)
+ }
+
+ ioctl(fd, DV1394_INIT, &init);
+
+ while(1) {
+ read( <a raw DV file>, buf, DV1394_NTSC_FRAME_SIZE );
+ write( <the dv1394 FD>, buf, DV1394_NTSC_FRAME_SIZE );
+ }
+
+ 2)
+
+ For more control over buffering, and to avoid unnecessary copies
+ of the DV data, you can use the more sophisticated the mmap() interface.
+ First, call the DV1394_INIT ioctl to specify your parameters,
+ including the number of frames in the ringbuffer. Then, calling mmap()
+ on the dv1394 device will give you direct access to the ringbuffer
+ from which the DV card reads your frame data.
+
+ The ringbuffer is simply one large, contiguous region of memory
+ containing two or more frames of packed DV data. Each frame of DV data
+ is 120000 bytes (NTSC) or 144000 bytes (PAL).
+
+ Fill one or more frames in the ringbuffer, then use the DV1394_SUBMIT_FRAMES
+ ioctl to begin I/O. You can use either the DV1394_WAIT_FRAMES ioctl
+ or select()/poll() to wait until the frames are transmitted. Next, you'll
+ need to call the DV1394_GET_STATUS ioctl to determine which ringbuffer
+ frames are clear (ready to be filled with new DV data). Finally, use
+ DV1394_SUBMIT_FRAMES again to send the new data to the DV output.
+
+
+ Example: here is what a four-frame ringbuffer might look like
+ during DV transmission:
+
+
+ frame 0 frame 1 frame 2 frame 3
+
+ *--------------------------------------*
+ | CLEAR | DV data | DV data | CLEAR |
+ *--------------------------------------*
+ <ACTIVE>
+
+ transmission goes in this direction --->>>
+
+
+ The DV hardware is currently transmitting the data in frame 1.
+ Once frame 1 is finished, it will automatically transmit frame 2.
+ (if frame 2 finishes before frame 3 is submitted, the device
+ will continue to transmit frame 2, and will increase the dropped_frames
+ counter each time it repeats the transmission).
+
+
+ If you called DV1394_GET_STATUS at this instant, you would
+ receive the following values:
+
+ n_frames = 4
+ active_frame = 1
+ first_clear_frame = 3
+ n_clear_frames = 2
+
+ At this point, you should write new DV data into frame 3 and optionally
+ frame 0. Then call DV1394_SUBMIT_FRAMES to inform the device that
+ it may transmit the new frames.
+
+ ERROR HANDLING
+
+ An error (buffer underflow/overflow or a break in the DV stream due
+ to a 1394 bus reset) can be detected by checking the dropped_frames
+ field of struct dv1394_status (obtained through the
+ DV1394_GET_STATUS ioctl).
+
+ The best way to recover from such an error is to re-initialize
+ dv1394, either by using the DV1394_INIT ioctl call, or closing the
+ file descriptor and opening it again. (note that you must unmap all
+ ringbuffer mappings when closing the file descriptor, or else
+ dv1394 will still be considered 'in use').
+
+ MAIN LOOP
+
+ For maximum efficiency and robustness against bus errors, you are
+ advised to model the main loop of your application after the
+ following pseudo-code example:
+
+ (checks of system call return values omitted for brevity; always
+ check return values in your code!)
+
+ while( frames left ) {
+
+ struct pollfd *pfd = ...;
+
+ pfd->fd = dv1394_fd;
+ pfd->revents = 0;
+ pfd->events = POLLOUT | POLLIN; (OUT for transmit, IN for receive)
+
+ (add other sources of I/O here)
+
+ poll(pfd, 1, -1); (or select(); add a timeout if you want)
+
+ if(pfd->revents) {
+ struct dv1394_status status;
+
+ ioctl(dv1394_fd, DV1394_GET_STATUS, &status);
+
+ if(status.dropped_frames > 0) {
+ reset_dv1394();
+ } else {
+ for(int i = 0; i < status.n_clear_frames; i++) {
+ copy_DV_frame();
+ }
+ }
+ }
+ }
+
+ where copy_DV_frame() reads or writes on the dv1394 file descriptor
+ (read/write mode) or copies data to/from the mmap ringbuffer and
+ then calls ioctl(DV1394_SUBMIT_FRAMES) to notify dv1394 that new
+ frames are availble (mmap mode).
+
+ reset_dv1394() is called in the event of a buffer
+ underflow/overflow or a halt in the DV stream (e.g. due to a 1394
+ bus reset). To guarantee recovery from the error, this function
+ should close the dv1394 file descriptor (and munmap() all
+ ringbuffer mappings, if you are using them), then re-open the
+ dv1394 device (and re-map the ringbuffer).
+
+*/
+
+
+/* maximum number of frames in the ringbuffer */
+#define DV1394_MAX_FRAMES 32
+
+/* number of *full* isochronous packets per DV frame */
+#define DV1394_NTSC_PACKETS_PER_FRAME 250
+#define DV1394_PAL_PACKETS_PER_FRAME 300
+
+/* size of one frame's worth of DV data, in bytes */
+#define DV1394_NTSC_FRAME_SIZE (480 * DV1394_NTSC_PACKETS_PER_FRAME)
+#define DV1394_PAL_FRAME_SIZE (480 * DV1394_PAL_PACKETS_PER_FRAME)
+
+
+/* ioctl() commands */
+
+enum {
+ /* I don't like using 0 as a valid ioctl() */
+ DV1394_INVALID = 0,
+
+
+ /* get the driver ready to transmit video.
+ pass a struct dv1394_init* as the parameter (see below),
+ or NULL to get default parameters */
+ DV1394_INIT,
+
+
+ /* stop transmitting video and free the ringbuffer */
+ DV1394_SHUTDOWN,
+
+
+ /* submit N new frames to be transmitted, where
+ the index of the first new frame is first_clear_buffer,
+ and the index of the last new frame is
+ (first_clear_buffer + N) % n_frames */
+ DV1394_SUBMIT_FRAMES,
+
+
+ /* block until N buffers are clear (pass N as the parameter)
+ Because we re-transmit the last frame on underrun, there
+ will at most be n_frames - 1 clear frames at any time */
+ DV1394_WAIT_FRAMES,
+
+ /* capture new frames that have been received, where
+ the index of the first new frame is first_clear_buffer,
+ and the index of the last new frame is
+ (first_clear_buffer + N) % n_frames */
+ DV1394_RECEIVE_FRAMES,
+
+
+ DV1394_START_RECEIVE,
+
+
+ /* pass a struct dv1394_status* as the parameter (see below) */
+ DV1394_GET_STATUS,
+};
+
+
+
+enum pal_or_ntsc {
+ DV1394_NTSC = 0,
+ DV1394_PAL
+};
+
+
+
+
+/* this is the argument to DV1394_INIT */
+struct dv1394_init {
+ /* DV1394_API_VERSION */
+ unsigned int api_version;
+
+ /* isochronous transmission channel to use */
+ unsigned int channel;
+
+ /* number of frames in the ringbuffer. Must be at least 2
+ and at most DV1394_MAX_FRAMES. */
+ unsigned int n_frames;
+
+ /* send/receive PAL or NTSC video format */
+ enum pal_or_ntsc format;
+
+ /* the following are used only for transmission */
+
+ /* set these to zero unless you want a
+ non-default empty packet rate (see below) */
+ unsigned long cip_n;
+ unsigned long cip_d;
+
+ /* set this to zero unless you want a
+ non-default SYT cycle offset (default = 3 cycles) */
+ unsigned int syt_offset;
+};
+
+/* NOTE: you may only allocate the DV frame ringbuffer once each time
+ you open the dv1394 device. DV1394_INIT will fail if you call it a
+ second time with different 'n_frames' or 'format' arguments (which
+ would imply a different size for the ringbuffer). If you need a
+ different buffer size, simply close and re-open the device, then
+ initialize it with your new settings. */
+
+/* Q: What are cip_n and cip_d? */
+
+/*
+ A: DV video streams do not utilize 100% of the potential bandwidth offered
+ by IEEE 1394 (FireWire). To achieve the correct rate of data transmission,
+ DV devices must periodically insert empty packets into the 1394 data stream.
+ Typically there is one empty packet per 14-16 data-carrying packets.
+
+ Some DV devices will accept a wide range of empty packet rates, while others
+ require a precise rate. If the dv1394 driver produces empty packets at
+ a rate that your device does not accept, you may see ugly patterns on the
+ DV output, or even no output at all.
+
+ The default empty packet insertion rate seems to work for many people; if
+ your DV output is stable, you can simply ignore this discussion. However,
+ we have exposed the empty packet rate as a parameter to support devices that
+ do not work with the default rate.
+
+ The decision to insert an empty packet is made with a numerator/denominator
+ algorithm. Empty packets are produced at an average rate of CIP_N / CIP_D.
+ You can alter the empty packet rate by passing non-zero values for cip_n
+ and cip_d to the INIT ioctl.
+
+ */
+
+
+
+struct dv1394_status {
+ /* this embedded init struct returns the current dv1394
+ parameters in use */
+ struct dv1394_init init;
+
+ /* the ringbuffer frame that is currently being
+ displayed. (-1 if the device is not transmitting anything) */
+ int active_frame;
+
+ /* index of the first buffer (ahead of active_frame) that
+ is ready to be filled with data */
+ unsigned int first_clear_frame;
+
+ /* how many buffers, including first_clear_buffer, are
+ ready to be filled with data */
+ unsigned int n_clear_frames;
+
+ /* how many times the DV stream has underflowed, overflowed,
+ or otherwise encountered an error, since the previous call
+ to DV1394_GET_STATUS */
+ unsigned int dropped_frames;
+
+ /* N.B. The dropped_frames counter is only a lower bound on the actual
+ number of dropped frames, with the special case that if dropped_frames
+ is zero, then it is guaranteed that NO frames have been dropped
+ since the last call to DV1394_GET_STATUS.
+ */
+};
+
+
+#endif /* _DV_1394_H */
diff --git a/contrib/ffmpeg/libavformat/dvenc.c b/contrib/ffmpeg/libavformat/dvenc.c
new file mode 100644
index 000000000..bdac43784
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/dvenc.c
@@ -0,0 +1,411 @@
+/*
+ * General DV muxer/demuxer
+ * Copyright (c) 2003 Roman Shaposhnik
+ *
+ * Many thanks to Dan Dennedy <dan@dennedy.org> for providing wealth
+ * of DV technical info.
+ *
+ * Raw DV format
+ * Copyright (c) 2002 Fabrice Bellard.
+ *
+ * 50 Mbps (DVCPRO50) support
+ * Copyright (c) 2006 Daniel Maas <dmaas@maasdigital.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include <time.h>
+#include <stdarg.h>
+#include "avformat.h"
+#include "dvdata.h"
+#include "dv.h"
+#include "fifo.h"
+
+struct DVMuxContext {
+ const DVprofile* sys; /* Current DV profile. E.g.: 525/60, 625/50 */
+ int n_ast; /* Number of stereo audio streams (up to 2) */
+ AVStream *ast[2]; /* Stereo audio streams */
+ AVFifoBuffer audio_data[2]; /* Fifo for storing excessive amounts of PCM */
+ int frames; /* Number of a current frame */
+ time_t start_time; /* Start time of recording */
+ int has_audio; /* frame under contruction has audio */
+ int has_video; /* frame under contruction has video */
+ uint8_t frame_buf[DV_MAX_FRAME_SIZE]; /* frame under contruction */
+};
+
+static const int dv_aaux_packs_dist[12][9] = {
+ { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
+ { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
+ { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
+ { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
+ { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
+ { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
+ { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
+ { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
+ { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
+ { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
+ { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
+ { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
+};
+
+static int dv_audio_frame_size(const DVprofile* sys, int frame)
+{
+ return sys->audio_samples_dist[frame % (sizeof(sys->audio_samples_dist)/
+ sizeof(sys->audio_samples_dist[0]))];
+}
+
+static int dv_write_pack(enum dv_pack_type pack_id, DVMuxContext *c, uint8_t* buf, ...)
+{
+ struct tm tc;
+ time_t ct;
+ int ltc_frame;
+ va_list ap;
+
+ buf[0] = (uint8_t)pack_id;
+ switch (pack_id) {
+ case dv_timecode:
+ ct = (time_t)(c->frames / ((float)c->sys->frame_rate /
+ (float)c->sys->frame_rate_base));
+ brktimegm(ct, &tc);
+ /*
+ * LTC drop-frame frame counter drops two frames (0 and 1) every
+ * minute, unless it is exactly divisible by 10
+ */
+ ltc_frame = (c->frames + 2*ct/60 - 2*ct/600) % c->sys->ltc_divisor;
+ buf[1] = (0 << 7) | /* Color fame: 0 - unsync; 1 - sync mode */
+ (1 << 6) | /* Drop frame timecode: 0 - nondrop; 1 - drop */
+ ((ltc_frame / 10) << 4) | /* Tens of frames */
+ (ltc_frame % 10); /* Units of frames */
+ buf[2] = (1 << 7) | /* Biphase mark polarity correction: 0 - even; 1 - odd */
+ ((tc.tm_sec / 10) << 4) | /* Tens of seconds */
+ (tc.tm_sec % 10); /* Units of seconds */
+ buf[3] = (1 << 7) | /* Binary group flag BGF0 */
+ ((tc.tm_min / 10) << 4) | /* Tens of minutes */
+ (tc.tm_min % 10); /* Units of minutes */
+ buf[4] = (1 << 7) | /* Binary group flag BGF2 */
+ (1 << 6) | /* Binary group flag BGF1 */
+ ((tc.tm_hour / 10) << 4) | /* Tens of hours */
+ (tc.tm_hour % 10); /* Units of hours */
+ break;
+ case dv_audio_source: /* AAUX source pack */
+ va_start(ap, buf);
+ buf[1] = (1 << 7) | /* locked mode -- SMPTE only supports locked mode */
+ (1 << 6) | /* reserved -- always 1 */
+ (dv_audio_frame_size(c->sys, c->frames) -
+ c->sys->audio_min_samples[0]);
+ /* # of samples */
+ buf[2] = (0 << 7) | /* multi-stereo */
+ (0 << 5) | /* #of audio channels per block: 0 -- 1 channel */
+ (0 << 4) | /* pair bit: 0 -- one pair of channels */
+ !!va_arg(ap, int); /* audio mode */
+ buf[3] = (1 << 7) | /* res */
+ (1 << 6) | /* multi-language flag */
+ (c->sys->dsf << 5) | /* system: 60fields/50fields */
+ (c->sys->n_difchan & 2); /* definition: 0 -- 25Mbps, 2 -- 50Mbps */
+ buf[4] = (1 << 7) | /* emphasis: 1 -- off */
+ (0 << 6) | /* emphasis time constant: 0 -- reserved */
+ (0 << 3) | /* frequency: 0 -- 48Khz, 1 -- 44,1Khz, 2 -- 32Khz */
+ 0; /* quantization: 0 -- 16bit linear, 1 -- 12bit nonlinear */
+ va_end(ap);
+ break;
+ case dv_audio_control:
+ buf[1] = (0 << 6) | /* copy protection: 0 -- unrestricted */
+ (1 << 4) | /* input source: 1 -- digital input */
+ (3 << 2) | /* compression: 3 -- no information */
+ 0; /* misc. info/SMPTE emphasis off */
+ buf[2] = (1 << 7) | /* recording start point: 1 -- no */
+ (1 << 6) | /* recording end point: 1 -- no */
+ (1 << 3) | /* recording mode: 1 -- original */
+ 7;
+ buf[3] = (1 << 7) | /* direction: 1 -- forward */
+ (c->sys->pix_fmt == PIX_FMT_YUV420P ? 0x20 : /* speed */
+ c->sys->ltc_divisor*4);
+ buf[4] = (1 << 7) | /* reserved -- always 1 */
+ 0x7f; /* genre category */
+ break;
+ case dv_audio_recdate:
+ case dv_video_recdate: /* VAUX recording date */
+ ct = c->start_time + (time_t)(c->frames /
+ ((float)c->sys->frame_rate / (float)c->sys->frame_rate_base));
+ brktimegm(ct, &tc);
+ buf[1] = 0xff; /* ds, tm, tens of time zone, units of time zone */
+ /* 0xff is very likely to be "unknown" */
+ buf[2] = (3 << 6) | /* reserved -- always 1 */
+ ((tc.tm_mday / 10) << 4) | /* Tens of day */
+ (tc.tm_mday % 10); /* Units of day */
+ buf[3] = /* we set high 4 bits to 0, shouldn't we set them to week? */
+ ((tc.tm_mon / 10) << 4) | /* Tens of month */
+ (tc.tm_mon % 10); /* Units of month */
+ buf[4] = (((tc.tm_year % 100) / 10) << 4) | /* Tens of year */
+ (tc.tm_year % 10); /* Units of year */
+ break;
+ case dv_audio_rectime: /* AAUX recording time */
+ case dv_video_rectime: /* VAUX recording time */
+ ct = c->start_time + (time_t)(c->frames /
+ ((float)c->sys->frame_rate / (float)c->sys->frame_rate_base));
+ brktimegm(ct, &tc);
+ buf[1] = (3 << 6) | /* reserved -- always 1 */
+ 0x3f; /* tens of frame, units of frame: 0x3f - "unknown" ? */
+ buf[2] = (1 << 7) | /* reserved -- always 1 */
+ ((tc.tm_sec / 10) << 4) | /* Tens of seconds */
+ (tc.tm_sec % 10); /* Units of seconds */
+ buf[3] = (1 << 7) | /* reserved -- always 1 */
+ ((tc.tm_min / 10) << 4) | /* Tens of minutes */
+ (tc.tm_min % 10); /* Units of minutes */
+ buf[4] = (3 << 6) | /* reserved -- always 1 */
+ ((tc.tm_hour / 10) << 4) | /* Tens of hours */
+ (tc.tm_hour % 10); /* Units of hours */
+ break;
+ default:
+ buf[1] = buf[2] = buf[3] = buf[4] = 0xff;
+ }
+ return 5;
+}
+
+static void dv_inject_audio(DVMuxContext *c, int channel, uint8_t* frame_ptr)
+{
+ int i, j, d, of, size;
+ size = 4 * dv_audio_frame_size(c->sys, c->frames);
+ frame_ptr += channel * c->sys->difseg_size * 150 * 80;
+ for (i = 0; i < c->sys->difseg_size; i++) {
+ frame_ptr += 6 * 80; /* skip DIF segment header */
+ for (j = 0; j < 9; j++) {
+ dv_write_pack(dv_aaux_packs_dist[i][j], c, &frame_ptr[3], i >= c->sys->difseg_size/2);
+ for (d = 8; d < 80; d+=2) {
+ of = c->sys->audio_shuffle[i][j] + (d - 8)/2 * c->sys->audio_stride;
+ if (of*2 >= size)
+ continue;
+
+ frame_ptr[d] = av_fifo_peek(&c->audio_data[channel], of*2+1); // FIXME: may be we have to admit
+ frame_ptr[d+1] = av_fifo_peek(&c->audio_data[channel], of*2); // that DV is a big endian PCM
+ }
+ frame_ptr += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */
+ }
+ }
+}
+
+static void dv_inject_metadata(DVMuxContext *c, uint8_t* frame)
+{
+ int j, k;
+ uint8_t* buf;
+
+ for (buf = frame; buf < frame + c->sys->frame_size; buf += 150 * 80) {
+ /* DV subcode: 2nd and 3d DIFs */
+ for (j = 80; j < 80 * 3; j += 80) {
+ for (k = 6; k < 6 * 8; k += 8)
+ dv_write_pack(dv_timecode, c, &buf[j+k]);
+
+ if (((long)(buf-frame)/(c->sys->frame_size/(c->sys->difseg_size*c->sys->n_difchan))%c->sys->difseg_size) > 5) { /* FIXME: is this really needed ? */
+ dv_write_pack(dv_video_recdate, c, &buf[j+14]);
+ dv_write_pack(dv_video_rectime, c, &buf[j+22]);
+ dv_write_pack(dv_video_recdate, c, &buf[j+38]);
+ dv_write_pack(dv_video_rectime, c, &buf[j+46]);
+ }
+ }
+
+ /* DV VAUX: 4th, 5th and 6th 3DIFs */
+ for (j = 80*3 + 3; j < 80*6; j += 80) {
+ dv_write_pack(dv_video_recdate, c, &buf[j+5*2]);
+ dv_write_pack(dv_video_rectime, c, &buf[j+5*3]);
+ dv_write_pack(dv_video_recdate, c, &buf[j+5*11]);
+ dv_write_pack(dv_video_rectime, c, &buf[j+5*12]);
+ }
+ }
+}
+
+/*
+ * The following 3 functions constitute our interface to the world
+ */
+
+int dv_assemble_frame(DVMuxContext *c, AVStream* st,
+ const uint8_t* data, int data_size, uint8_t** frame)
+{
+ int i, reqasize;
+
+ *frame = &c->frame_buf[0];
+ reqasize = 4 * dv_audio_frame_size(c->sys, c->frames);
+
+ switch (st->codec->codec_type) {
+ case CODEC_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);
+
+ memcpy(*frame, data, c->sys->frame_size);
+ c->has_video = 1;
+ break;
+ case CODEC_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 */
+ if (av_fifo_size(&c->audio_data[i]) + data_size >= 100*AVCODEC_MAX_AUDIO_FRAME_SIZE)
+ av_log(st->codec, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient video data or severe sync problem.\n", c->frames);
+ av_fifo_write(&c->audio_data[i], data, data_size);
+
+ /* Lets see if we've got enough audio for one DV frame */
+ c->has_audio |= ((reqasize <= av_fifo_size(&c->audio_data[i])) << i);
+
+ break;
+ default:
+ break;
+ }
+
+ /* Lets see if we have enough data to construct one DV frame */
+ if (c->has_video == 1 && c->has_audio + 1 == 1<<c->n_ast) {
+ dv_inject_metadata(c, *frame);
+ for (i=0; i<c->n_ast; i++) {
+ dv_inject_audio(c, i, *frame);
+ av_fifo_drain(&c->audio_data[i], reqasize);
+ }
+
+ c->has_video = 0;
+ c->has_audio = 0;
+ c->frames++;
+
+ return c->sys->frame_size;
+ }
+
+ return 0;
+}
+
+DVMuxContext* dv_init_mux(AVFormatContext* s)
+{
+ DVMuxContext *c = (DVMuxContext *)s->priv_data;
+ AVStream *vst = NULL;
+ int i;
+
+ /* we support at most 1 video and 2 audio streams */
+ if (s->nb_streams > 3)
+ return NULL;
+
+ c->n_ast = 0;
+ c->ast[0] = c->ast[1] = NULL;
+
+ /* We have to sort out where audio and where video stream is */
+ for (i=0; i<s->nb_streams; i++) {
+ switch (s->streams[i]->codec->codec_type) {
+ case CODEC_TYPE_VIDEO:
+ vst = s->streams[i];
+ break;
+ case CODEC_TYPE_AUDIO:
+ c->ast[c->n_ast++] = s->streams[i];
+ break;
+ default:
+ goto bail_out;
+ }
+ }
+
+ /* Some checks -- DV format is very picky about its incoming streams */
+ if (!vst || vst->codec->codec_id != CODEC_ID_DVVIDEO)
+ goto bail_out;
+ for (i=0; i<c->n_ast; i++) {
+ if (c->ast[i] && (c->ast[i]->codec->codec_id != CODEC_ID_PCM_S16LE ||
+ c->ast[i]->codec->sample_rate != 48000 ||
+ c->ast[i]->codec->channels != 2))
+ goto bail_out;
+ }
+ c->sys = dv_codec_profile(vst->codec);
+ if (!c->sys)
+ goto bail_out;
+
+ if((c->n_ast > 1) && (c->sys->n_difchan < 2)) {
+ /* only 1 stereo pair is allowed in 25Mbps mode */
+ goto bail_out;
+ }
+
+ /* Ok, everything seems to be in working order */
+ c->frames = 0;
+ c->has_audio = 0;
+ c->has_video = 0;
+ c->start_time = (time_t)s->timestamp;
+
+ for (i=0; i<c->n_ast; i++) {
+ if (c->ast[i] && av_fifo_init(&c->audio_data[i], 100*AVCODEC_MAX_AUDIO_FRAME_SIZE) < 0) {
+ while (i>0) {
+ i--;
+ av_fifo_free(&c->audio_data[i]);
+ }
+ goto bail_out;
+ }
+ }
+
+ return c;
+
+bail_out:
+ return NULL;
+}
+
+void dv_delete_mux(DVMuxContext *c)
+{
+ int i;
+ for (i=0; i < c->n_ast; i++)
+ av_fifo_free(&c->audio_data[i]);
+}
+
+#ifdef CONFIG_MUXERS
+static int dv_write_header(AVFormatContext *s)
+{
+ if (!dv_init_mux(s)) {
+ av_log(s, AV_LOG_ERROR, "Can't initialize DV format!\n"
+ "Make sure that you supply exactly two streams:\n"
+ " video: 25fps or 29.97fps, audio: 2ch/48Khz/PCM\n"
+ " (50Mbps allows an optional second audio stream)\n");
+ return -1;
+ }
+ return 0;
+}
+
+static int dv_write_packet(struct AVFormatContext *s, AVPacket *pkt)
+{
+ uint8_t* frame;
+ int fsize;
+
+ fsize = dv_assemble_frame((DVMuxContext *)s->priv_data, s->streams[pkt->stream_index],
+ pkt->data, pkt->size, &frame);
+ if (fsize > 0) {
+ put_buffer(&s->pb, frame, fsize);
+ put_flush_packet(&s->pb);
+ }
+ return 0;
+}
+
+/*
+ * We might end up with some extra A/V data without matching counterpart.
+ * E.g. video data without enough audio to write the complete frame.
+ * Currently we simply drop the last frame. I don't know whether this
+ * is the best strategy of all
+ */
+static int dv_write_trailer(struct AVFormatContext *s)
+{
+ dv_delete_mux((DVMuxContext *)s->priv_data);
+ return 0;
+}
+#endif /* CONFIG_MUXERS */
+
+#ifdef CONFIG_DV_MUXER
+AVOutputFormat dv_muxer = {
+ "dv",
+ "DV video format",
+ NULL,
+ "dv",
+ sizeof(DVMuxContext),
+ CODEC_ID_PCM_S16LE,
+ CODEC_ID_DVVIDEO,
+ dv_write_header,
+ dv_write_packet,
+ dv_write_trailer,
+};
+#endif
diff --git a/contrib/ffmpeg/libavformat/dxa.c b/contrib/ffmpeg/libavformat/dxa.c
new file mode 100644
index 000000000..f49d3d4ac
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/dxa.c
@@ -0,0 +1,214 @@
+/*
+ * DXA demuxer
+ * Copyright (c) 2007 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 "avformat.h"
+#include "riff.h"
+
+#define DXA_EXTRA_SIZE 9
+
+typedef struct{
+ int frames;
+ int has_sound;
+ int bpc;
+ uint32_t bytes_left;
+ int64_t wavpos, vidpos;
+ int readvid;
+}DXAContext;
+
+static int dxa_probe(AVProbeData *p)
+{
+ /* check file header */
+ if (p->buf_size <= 4)
+ return 0;
+ if (p->buf[0] == 'D' && p->buf[1] == 'E' &&
+ p->buf[2] == 'X' && p->buf[3] == 'A')
+ return AVPROBE_SCORE_MAX;
+ else
+ return 0;
+}
+
+static int dxa_read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+ ByteIOContext *pb = &s->pb;
+ DXAContext *c = s->priv_data;
+ AVStream *st, *ast;
+ uint32_t tag;
+ int32_t fps;
+ int w, h;
+ int num, den;
+ int flags;
+
+ tag = get_le32(pb);
+ if (tag != MKTAG('D', 'E', 'X', 'A'))
+ return -1;
+ flags = get_byte(pb);
+ c->frames = get_be16(pb);
+ if(!c->frames){
+ av_log(s, AV_LOG_ERROR, "File contains no frames ???\n");
+ return -1;
+ }
+
+ fps = get_be32(pb);
+ if(fps > 0){
+ den = 1000;
+ num = fps;
+ }else if (fps < 0){
+ den = 100000;
+ num = -fps;
+ }else{
+ den = 10;
+ num = 1;
+ }
+ w = get_be16(pb);
+ h = get_be16(pb);
+ c->has_sound = 0;
+
+ st = av_new_stream(s, 0);
+ if (!st)
+ return -1;
+
+ // Parse WAV data header
+ if(get_le32(pb) == MKTAG('W', 'A', 'V', 'E')){
+ uint32_t size, fsize;
+ c->has_sound = 1;
+ size = get_be32(pb);
+ c->vidpos = url_ftell(pb) + size;
+ url_fskip(pb, 16);
+ fsize = get_le32(pb);
+
+ ast = av_new_stream(s, 0);
+ if (!ast)
+ return -1;
+ get_wav_header(pb, ast->codec, fsize);
+ // find 'data' chunk
+ while(url_ftell(pb) < c->vidpos && !url_feof(pb)){
+ tag = get_le32(pb);
+ fsize = get_le32(pb);
+ if(tag == MKTAG('d', 'a', 't', 'a')) break;
+ url_fskip(pb, fsize);
+ }
+ c->bpc = (fsize + c->frames - 1) / c->frames;
+ if(ast->codec->block_align)
+ c->bpc = ((c->bpc + ast->codec->block_align - 1) / ast->codec->block_align) * ast->codec->block_align;
+ c->bytes_left = fsize;
+ c->wavpos = url_ftell(pb);
+ url_fseek(pb, c->vidpos, SEEK_SET);
+ }
+
+ /* now we are ready: build format streams */
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ st->codec->codec_id = CODEC_ID_DXA;
+ st->codec->width = w;
+ st->codec->height = h;
+ av_reduce(&den, &num, den, num, (1UL<<31)-1);
+ av_set_pts_info(st, 33, num, den);
+ /* flags & 0x80 means that image is interlaced,
+ * flags & 0x40 means that image has double height
+ * either way set true height
+ */
+ if(flags & 0xC0){
+ st->codec->height >>= 1;
+ }
+ c->readvid = !c->has_sound;
+ c->vidpos = url_ftell(pb);
+ s->start_time = 0;
+ s->duration = (int64_t)c->frames * AV_TIME_BASE * num / den;
+ av_log(s, AV_LOG_DEBUG, "%d frame(s)\n",c->frames);
+
+ return 0;
+}
+
+static int dxa_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ DXAContext *c = s->priv_data;
+ int ret;
+ uint32_t size;
+ uint8_t buf[DXA_EXTRA_SIZE], pal[768+4];
+ int pal_size = 0;
+
+ if(!c->readvid && c->has_sound && c->bytes_left){
+ c->readvid = 1;
+ url_fseek(&s->pb, c->wavpos, SEEK_SET);
+ size = FFMIN(c->bytes_left, c->bpc);
+ ret = av_get_packet(&s->pb, pkt, size);
+ pkt->stream_index = 1;
+ if(ret != size)
+ return AVERROR_IO;
+ c->bytes_left -= size;
+ c->wavpos = url_ftell(&s->pb);
+ return 0;
+ }
+ url_fseek(&s->pb, c->vidpos, SEEK_SET);
+ while(!url_feof(&s->pb) && c->frames){
+ get_buffer(&s->pb, buf, 4);
+ switch(AV_RL32(buf)){
+ case MKTAG('N', 'U', 'L', 'L'):
+ if(av_new_packet(pkt, 4 + pal_size) < 0)
+ return AVERROR_NOMEM;
+ pkt->stream_index = 0;
+ if(pal_size) memcpy(pkt->data, pal, pal_size);
+ memcpy(pkt->data + pal_size, buf, 4);
+ c->frames--;
+ c->vidpos = url_ftell(&s->pb);
+ c->readvid = 0;
+ return 0;
+ case MKTAG('C', 'M', 'A', 'P'):
+ pal_size = 768+4;
+ memcpy(pal, buf, 4);
+ get_buffer(&s->pb, pal + 4, 768);
+ break;
+ case MKTAG('F', 'R', 'A', 'M'):
+ get_buffer(&s->pb, buf + 4, DXA_EXTRA_SIZE - 4);
+ size = AV_RB32(buf + 5);
+ if(size > 0xFFFFFF){
+ av_log(s, AV_LOG_ERROR, "Frame size is too big: %d\n", size);
+ return -1;
+ }
+ if(av_new_packet(pkt, size + DXA_EXTRA_SIZE + pal_size) < 0)
+ return AVERROR_NOMEM;
+ memcpy(pkt->data + pal_size, buf, DXA_EXTRA_SIZE);
+ ret = get_buffer(&s->pb, pkt->data + DXA_EXTRA_SIZE + pal_size, size);
+ if(ret != size){
+ av_free_packet(pkt);
+ return AVERROR_IO;
+ }
+ if(pal_size) memcpy(pkt->data, pal, pal_size);
+ pkt->stream_index = 0;
+ c->frames--;
+ c->vidpos = url_ftell(&s->pb);
+ c->readvid = 0;
+ return 0;
+ default:
+ av_log(s, AV_LOG_ERROR, "Unknown tag %c%c%c%c\n", buf[0], buf[1], buf[2], buf[3]);
+ return -1;
+ }
+ }
+ return AVERROR(EIO);
+}
+
+AVInputFormat dxa_demuxer = {
+ "dxa",
+ "dxa",
+ sizeof(DXAContext),
+ dxa_probe,
+ dxa_read_header,
+ dxa_read_packet,
+};
diff --git a/contrib/ffmpeg/libavformat/electronicarts.c b/contrib/ffmpeg/libavformat/electronicarts.c
new file mode 100644
index 000000000..762d658ab
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/electronicarts.c
@@ -0,0 +1,291 @@
+/* Electronic Arts Multimedia File Demuxer
+ * Copyright (c) 2004 The ffmpeg Project
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file electronicarts.c
+ * Electronic Arts Multimedia file demuxer (WVE/UV2/etc.)
+ * by Robin Kay (komadori at gekkou.co.uk)
+ */
+
+#include "avformat.h"
+
+#define SCHl_TAG MKTAG('S', 'C', 'H', 'l')
+#define PT00_TAG MKTAG('P', 'T', 0x0, 0x0)
+#define SCDl_TAG MKTAG('S', 'C', 'D', 'l')
+#define pIQT_TAG MKTAG('p', 'I', 'Q', 'T')
+#define SCEl_TAG MKTAG('S', 'C', 'E', 'l')
+#define _TAG MKTAG('', '', '', '')
+
+#define EA_SAMPLE_RATE 22050
+#define EA_BITS_PER_SAMPLE 16
+#define EA_PREAMBLE_SIZE 8
+
+typedef struct EaDemuxContext {
+ int width;
+ int height;
+ int video_stream_index;
+ int track_count;
+
+ int audio_stream_index;
+ int audio_frame_counter;
+
+ int64_t audio_pts;
+ int64_t video_pts;
+ int video_pts_inc;
+ float fps;
+
+ int num_channels;
+ int num_samples;
+ int compression_type;
+} EaDemuxContext;
+
+static uint32_t read_arbitary(ByteIOContext *pb) {
+ uint8_t size, byte;
+ int i;
+ uint32_t word;
+
+ size = get_byte(pb);
+
+ word = 0;
+ for (i = 0; i < size; i++) {
+ byte = get_byte(pb);
+ word <<= 8;
+ word |= byte;
+ }
+
+ return word;
+}
+
+/*
+ * Process WVE file header
+ * Returns 1 if the WVE file is valid and successfully opened, 0 otherwise
+ */
+static int process_ea_header(AVFormatContext *s) {
+ int inHeader;
+ uint32_t blockid, size;
+ EaDemuxContext *ea = (EaDemuxContext *)s->priv_data;
+ ByteIOContext *pb = &s->pb;
+
+ if (get_buffer(pb, (void*)&blockid, 4) != 4) {
+ return 0;
+ }
+ if (le2me_32(blockid) != SCHl_TAG) {
+ return 0;
+ }
+
+ if (get_buffer(pb, (void*)&size, 4) != 4) {
+ return 0;
+ }
+ size = le2me_32(size);
+
+ if (get_buffer(pb, (void*)&blockid, 4) != 4) {
+ return 0;
+ }
+ if (le2me_32(blockid) != PT00_TAG) {
+ av_log (s, AV_LOG_ERROR, "PT header missing\n");
+ return 0;
+ }
+
+ inHeader = 1;
+ while (inHeader) {
+ int inSubheader;
+ uint8_t byte;
+ byte = get_byte(pb) & 0xFF;
+
+ switch (byte) {
+ case 0xFD:
+ av_log (s, AV_LOG_INFO, "entered audio subheader\n");
+ inSubheader = 1;
+ while (inSubheader) {
+ uint8_t subbyte;
+ subbyte = get_byte(pb) & 0xFF;
+
+ switch (subbyte) {
+ case 0x82:
+ ea->num_channels = read_arbitary(pb);
+ av_log (s, AV_LOG_INFO, "num_channels (element 0x82) set to 0x%08x\n", ea->num_channels);
+ break;
+ case 0x83:
+ ea->compression_type = read_arbitary(pb);
+ av_log (s, AV_LOG_INFO, "compression_type (element 0x83) set to 0x%08x\n", ea->compression_type);
+ break;
+ case 0x85:
+ ea->num_samples = read_arbitary(pb);
+ av_log (s, AV_LOG_INFO, "num_samples (element 0x85) set to 0x%08x\n", ea->num_samples);
+ break;
+ case 0x8A:
+ av_log (s, AV_LOG_INFO, "element 0x%02x set to 0x%08x\n", subbyte, read_arbitary(pb));
+ av_log (s, AV_LOG_INFO, "exited audio subheader\n");
+ inSubheader = 0;
+ break;
+ default:
+ av_log (s, AV_LOG_INFO, "element 0x%02x set to 0x%08x\n", subbyte, read_arbitary(pb));
+ break;
+ }
+ }
+ break;
+ case 0xFF:
+ av_log (s, AV_LOG_INFO, "end of header block reached\n");
+ inHeader = 0;
+ break;
+ default:
+ av_log (s, AV_LOG_INFO, "header element 0x%02x set to 0x%08x\n", byte, read_arbitary(pb));
+ break;
+ }
+ }
+
+ if ((ea->num_channels != 2) || (ea->compression_type != 7)) {
+ av_log (s, AV_LOG_ERROR, "unsupported stream type\n");
+ return 0;
+ }
+
+ /* skip to the start of the data */
+ url_fseek(pb, size, SEEK_SET);
+
+ return 1;
+}
+
+
+static int ea_probe(AVProbeData *p)
+{
+ if (p->buf_size < 4)
+ return 0;
+
+ if (AV_RL32(&p->buf[0]) != SCHl_TAG)
+ return 0;
+
+ return AVPROBE_SCORE_MAX;
+}
+
+static int ea_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ EaDemuxContext *ea = (EaDemuxContext *)s->priv_data;
+ AVStream *st;
+
+ if (!process_ea_header(s))
+ return AVERROR_IO;
+
+#if 0
+ /* initialize the video decoder stream */
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+ av_set_pts_info(st, 33, 1, 90000);
+ ea->video_stream_index = st->index;
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ st->codec->codec_id = CODEC_ID_EA_MJPEG;
+ st->codec->codec_tag = 0; /* no fourcc */
+#endif
+
+ /* initialize the audio decoder stream */
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+ av_set_pts_info(st, 33, 1, EA_SAMPLE_RATE);
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_id = CODEC_ID_ADPCM_EA;
+ st->codec->codec_tag = 0; /* no tag */
+ st->codec->channels = ea->num_channels;
+ st->codec->sample_rate = EA_SAMPLE_RATE;
+ st->codec->bits_per_sample = EA_BITS_PER_SAMPLE;
+ st->codec->bit_rate = st->codec->channels * st->codec->sample_rate *
+ st->codec->bits_per_sample / 4;
+ st->codec->block_align = st->codec->channels * st->codec->bits_per_sample;
+
+ ea->audio_stream_index = st->index;
+ ea->audio_frame_counter = 0;
+
+ return 1;
+}
+
+static int ea_read_packet(AVFormatContext *s,
+ AVPacket *pkt)
+{
+ EaDemuxContext *ea = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ int ret = 0;
+ int packet_read = 0;
+ unsigned char preamble[EA_PREAMBLE_SIZE];
+ unsigned int chunk_type, chunk_size;
+
+ while (!packet_read) {
+
+ if (get_buffer(pb, preamble, EA_PREAMBLE_SIZE) != EA_PREAMBLE_SIZE)
+ return AVERROR_IO;
+ chunk_type = AV_RL32(&preamble[0]);
+ chunk_size = AV_RL32(&preamble[4]) - EA_PREAMBLE_SIZE;
+
+ switch (chunk_type) {
+ /* audio data */
+ case SCDl_TAG:
+ ret = av_get_packet(pb, pkt, chunk_size);
+ if (ret != chunk_size)
+ ret = AVERROR_IO;
+ else {
+ pkt->stream_index = ea->audio_stream_index;
+ pkt->pts = 90000;
+ pkt->pts *= ea->audio_frame_counter;
+ pkt->pts /= EA_SAMPLE_RATE;
+
+ /* 2 samples/byte, 1 or 2 samples per frame depending
+ * on stereo; chunk also has 12-byte header */
+ ea->audio_frame_counter += ((chunk_size - 12) * 2) /
+ ea->num_channels;
+ }
+
+ packet_read = 1;
+ break;
+
+ /* ending tag */
+ case SCEl_TAG:
+ ret = AVERROR_IO;
+ packet_read = 1;
+ break;
+
+ default:
+ url_fseek(pb, chunk_size, SEEK_CUR);
+ break;
+ }
+
+ /* ending packet */
+ if (chunk_type == SCEl_TAG) {
+ }
+ }
+
+ return ret;
+}
+
+static int ea_read_close(AVFormatContext *s)
+{
+// EaDemuxContext *ea = (EaDemuxContext *)s->priv_data;
+
+ return 0;
+}
+
+AVInputFormat ea_demuxer = {
+ "ea",
+ "Electronic Arts Multimedia Format",
+ sizeof(EaDemuxContext),
+ ea_probe,
+ ea_read_header,
+ ea_read_packet,
+ ea_read_close,
+};
diff --git a/contrib/ffmpeg/libavformat/ffm.c b/contrib/ffmpeg/libavformat/ffm.c
new file mode 100644
index 000000000..a2970ae42
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/ffm.c
@@ -0,0 +1,794 @@
+/*
+ * FFM (ffserver live feed) muxer and demuxer
+ * Copyright (c) 2001 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 "avformat.h"
+#include <unistd.h>
+
+/* The FFM file is made of blocks of fixed size */
+#define FFM_HEADER_SIZE 14
+#define PACKET_ID 0x666d
+
+/* each packet contains frames (which can span several packets */
+#define FRAME_HEADER_SIZE 8
+#define FLAG_KEY_FRAME 0x01
+
+typedef struct FFMStream {
+ int64_t pts;
+} FFMStream;
+
+enum {
+ READ_HEADER,
+ READ_DATA,
+};
+
+typedef struct FFMContext {
+ /* only reading mode */
+ offset_t write_index, file_size;
+ int read_state;
+ uint8_t header[FRAME_HEADER_SIZE];
+
+ /* read and write */
+ int first_packet; /* true if first packet, needed to set the discontinuity tag */
+ int first_frame_in_packet; /* true if first frame in packet, needed to know if PTS information is valid */
+ int packet_size;
+ int frame_offset;
+ int64_t pts;
+ uint8_t *packet_ptr, *packet_end;
+ uint8_t packet[FFM_PACKET_SIZE];
+} FFMContext;
+
+static int64_t get_pts(AVFormatContext *s, offset_t pos);
+
+/* disable pts hack for testing */
+int ffm_nopts = 0;
+
+#ifdef CONFIG_MUXERS
+static void flush_packet(AVFormatContext *s)
+{
+ FFMContext *ffm = s->priv_data;
+ int fill_size, h;
+ ByteIOContext *pb = &s->pb;
+
+ fill_size = ffm->packet_end - ffm->packet_ptr;
+ memset(ffm->packet_ptr, 0, fill_size);
+
+ if (url_ftell(pb) % ffm->packet_size)
+ av_abort();
+
+ /* put header */
+ put_be16(pb, PACKET_ID);
+ put_be16(pb, fill_size);
+ put_be64(pb, ffm->pts);
+ h = ffm->frame_offset;
+ if (ffm->first_packet)
+ h |= 0x8000;
+ put_be16(pb, h);
+ put_buffer(pb, ffm->packet, ffm->packet_end - ffm->packet);
+ put_flush_packet(pb);
+
+ /* prepare next packet */
+ ffm->frame_offset = 0; /* no key frame */
+ ffm->pts = 0; /* no pts */
+ ffm->packet_ptr = ffm->packet;
+ ffm->first_packet = 0;
+}
+
+/* 'first' is true if first data of a frame */
+static void ffm_write_data(AVFormatContext *s,
+ const uint8_t *buf, int size,
+ int64_t pts, int first)
+{
+ FFMContext *ffm = s->priv_data;
+ int len;
+
+ if (first && ffm->frame_offset == 0)
+ ffm->frame_offset = ffm->packet_ptr - ffm->packet + FFM_HEADER_SIZE;
+ if (first && ffm->pts == 0)
+ ffm->pts = pts;
+
+ /* write as many packets as needed */
+ while (size > 0) {
+ len = ffm->packet_end - ffm->packet_ptr;
+ if (len > size)
+ len = size;
+ memcpy(ffm->packet_ptr, buf, len);
+
+ ffm->packet_ptr += len;
+ buf += len;
+ size -= len;
+ if (ffm->packet_ptr >= ffm->packet_end) {
+ /* special case : no pts in packet : we leave the current one */
+ if (ffm->pts == 0)
+ ffm->pts = pts;
+
+ flush_packet(s);
+ }
+ }
+}
+
+static int ffm_write_header(AVFormatContext *s)
+{
+ FFMContext *ffm = s->priv_data;
+ AVStream *st;
+ FFMStream *fst;
+ ByteIOContext *pb = &s->pb;
+ AVCodecContext *codec;
+ int bit_rate, i;
+
+ ffm->packet_size = FFM_PACKET_SIZE;
+
+ /* header */
+ put_le32(pb, MKTAG('F', 'F', 'M', '1'));
+ put_be32(pb, ffm->packet_size);
+ /* XXX: store write position in other file ? */
+ put_be64(pb, ffm->packet_size); /* current write position */
+
+ put_be32(pb, s->nb_streams);
+ bit_rate = 0;
+ for(i=0;i<s->nb_streams;i++) {
+ st = s->streams[i];
+ bit_rate += st->codec->bit_rate;
+ }
+ put_be32(pb, bit_rate);
+
+ /* list of streams */
+ for(i=0;i<s->nb_streams;i++) {
+ st = s->streams[i];
+ fst = av_mallocz(sizeof(FFMStream));
+ if (!fst)
+ goto fail;
+ av_set_pts_info(st, 64, 1, 1000000);
+ st->priv_data = fst;
+
+ codec = st->codec;
+ /* generic info */
+ put_be32(pb, codec->codec_id);
+ put_byte(pb, codec->codec_type);
+ put_be32(pb, codec->bit_rate);
+ put_be32(pb, st->quality);
+ put_be32(pb, codec->flags);
+ put_be32(pb, codec->flags2);
+ put_be32(pb, codec->debug);
+ /* specific info */
+ switch(codec->codec_type) {
+ case CODEC_TYPE_VIDEO:
+ put_be32(pb, codec->time_base.num);
+ put_be32(pb, codec->time_base.den);
+ put_be16(pb, codec->width);
+ put_be16(pb, codec->height);
+ put_be16(pb, codec->gop_size);
+ put_be32(pb, codec->pix_fmt);
+ put_byte(pb, codec->qmin);
+ put_byte(pb, codec->qmax);
+ put_byte(pb, codec->max_qdiff);
+ put_be16(pb, (int) (codec->qcompress * 10000.0));
+ put_be16(pb, (int) (codec->qblur * 10000.0));
+ put_be32(pb, codec->bit_rate_tolerance);
+ put_strz(pb, codec->rc_eq);
+ put_be32(pb, codec->rc_max_rate);
+ put_be32(pb, codec->rc_min_rate);
+ put_be32(pb, codec->rc_buffer_size);
+ put_be64(pb, av_dbl2int(codec->i_quant_factor));
+ put_be64(pb, av_dbl2int(codec->b_quant_factor));
+ put_be64(pb, av_dbl2int(codec->i_quant_offset));
+ put_be64(pb, av_dbl2int(codec->b_quant_offset));
+ put_be32(pb, codec->dct_algo);
+ put_be32(pb, codec->strict_std_compliance);
+ put_be32(pb, codec->max_b_frames);
+ put_be32(pb, codec->luma_elim_threshold);
+ put_be32(pb, codec->chroma_elim_threshold);
+ put_be32(pb, codec->mpeg_quant);
+ put_be32(pb, codec->intra_dc_precision);
+ put_be32(pb, codec->me_method);
+ put_be32(pb, codec->mb_decision);
+ put_be32(pb, codec->nsse_weight);
+ put_be32(pb, codec->frame_skip_cmp);
+ put_be64(pb, av_dbl2int(codec->rc_buffer_aggressivity));
+ put_be32(pb, codec->codec_tag);
+ break;
+ case CODEC_TYPE_AUDIO:
+ put_be32(pb, codec->sample_rate);
+ put_le16(pb, codec->channels);
+ put_le16(pb, codec->frame_size);
+ break;
+ default:
+ return -1;
+ }
+ /* hack to have real time */
+ if (ffm_nopts)
+ fst->pts = 0;
+ else
+ fst->pts = av_gettime();
+ }
+
+ /* flush until end of block reached */
+ while ((url_ftell(pb) % ffm->packet_size) != 0)
+ put_byte(pb, 0);
+
+ put_flush_packet(pb);
+
+ /* init packet mux */
+ ffm->packet_ptr = ffm->packet;
+ ffm->packet_end = ffm->packet + ffm->packet_size - FFM_HEADER_SIZE;
+ assert(ffm->packet_end >= ffm->packet);
+ ffm->frame_offset = 0;
+ ffm->pts = 0;
+ ffm->first_packet = 1;
+
+ return 0;
+ fail:
+ for(i=0;i<s->nb_streams;i++) {
+ st = s->streams[i];
+ av_freep(&st->priv_data);
+ }
+ return -1;
+}
+
+static int ffm_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ AVStream *st = s->streams[pkt->stream_index];
+ FFMStream *fst = st->priv_data;
+ int64_t pts;
+ uint8_t header[FRAME_HEADER_SIZE];
+ int duration;
+ int size= pkt->size;
+
+ //XXX/FIXME use duration from pkt
+ if (st->codec->codec_type == CODEC_TYPE_AUDIO) {
+ duration = ((float)st->codec->frame_size / st->codec->sample_rate * 1000000.0);
+ } else {
+ duration = (1000000.0 * st->codec->time_base.num / (float)st->codec->time_base.den);
+ }
+
+ pts = fst->pts;
+ /* packet size & key_frame */
+ header[0] = pkt->stream_index;
+ header[1] = 0;
+ if (pkt->flags & PKT_FLAG_KEY)
+ header[1] |= FLAG_KEY_FRAME;
+ header[2] = (size >> 16) & 0xff;
+ header[3] = (size >> 8) & 0xff;
+ header[4] = size & 0xff;
+ header[5] = (duration >> 16) & 0xff;
+ header[6] = (duration >> 8) & 0xff;
+ header[7] = duration & 0xff;
+ ffm_write_data(s, header, FRAME_HEADER_SIZE, pts, 1);
+ ffm_write_data(s, pkt->data, size, pts, 0);
+
+ fst->pts += duration;
+ return 0;
+}
+
+static int ffm_write_trailer(AVFormatContext *s)
+{
+ ByteIOContext *pb = &s->pb;
+ FFMContext *ffm = s->priv_data;
+
+ /* flush packets */
+ if (ffm->packet_ptr > ffm->packet)
+ flush_packet(s);
+
+ put_flush_packet(pb);
+
+ if (!url_is_streamed(pb)) {
+ int64_t size;
+ /* update the write offset */
+ size = url_ftell(pb);
+ url_fseek(pb, 8, SEEK_SET);
+ put_be64(pb, size);
+ put_flush_packet(pb);
+ }
+
+ return 0;
+}
+#endif //CONFIG_MUXERS
+
+/* ffm demux */
+
+static int ffm_is_avail_data(AVFormatContext *s, int size)
+{
+ FFMContext *ffm = s->priv_data;
+ offset_t pos, avail_size;
+ int len;
+
+ len = ffm->packet_end - ffm->packet_ptr;
+ if (!ffm_nopts) {
+ /* XXX: I don't understand this test, so I disabled it for testing */
+ if (size <= len)
+ return 1;
+ }
+ pos = url_ftell(&s->pb);
+ if (pos == ffm->write_index) {
+ /* exactly at the end of stream */
+ return 0;
+ } else if (pos < ffm->write_index) {
+ avail_size = ffm->write_index - pos;
+ } else {
+ avail_size = (ffm->file_size - pos) + (ffm->write_index - FFM_PACKET_SIZE);
+ }
+ avail_size = (avail_size / ffm->packet_size) * (ffm->packet_size - FFM_HEADER_SIZE) + len;
+ if (size <= avail_size)
+ return 1;
+ else
+ return 0;
+}
+
+/* first is true if we read the frame header */
+static int ffm_read_data(AVFormatContext *s,
+ uint8_t *buf, int size, int first)
+{
+ FFMContext *ffm = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ int len, fill_size, size1, frame_offset;
+
+ size1 = size;
+ while (size > 0) {
+ redo:
+ len = ffm->packet_end - ffm->packet_ptr;
+ if (len > size)
+ len = size;
+ if (len == 0) {
+ if (url_ftell(pb) == ffm->file_size)
+ url_fseek(pb, ffm->packet_size, SEEK_SET);
+ retry_read:
+ get_be16(pb); /* PACKET_ID */
+ fill_size = get_be16(pb);
+ ffm->pts = get_be64(pb);
+ ffm->first_frame_in_packet = 1;
+ frame_offset = get_be16(pb);
+ get_buffer(pb, ffm->packet, ffm->packet_size - FFM_HEADER_SIZE);
+ ffm->packet_end = ffm->packet + (ffm->packet_size - FFM_HEADER_SIZE - fill_size);
+ if (ffm->packet_end < ffm->packet)
+ return -1;
+ /* if first packet or resynchronization packet, we must
+ handle it specifically */
+ if (ffm->first_packet || (frame_offset & 0x8000)) {
+ if (!frame_offset) {
+ /* This packet has no frame headers in it */
+ if (url_ftell(pb) >= ffm->packet_size * 3) {
+ url_fseek(pb, -ffm->packet_size * 2, SEEK_CUR);
+ goto retry_read;
+ }
+ /* This is bad, we cannot find a valid frame header */
+ return 0;
+ }
+ ffm->first_packet = 0;
+ if ((frame_offset & 0x7ffff) < FFM_HEADER_SIZE)
+ return -1;
+ ffm->packet_ptr = ffm->packet + (frame_offset & 0x7fff) - FFM_HEADER_SIZE;
+ if (!first)
+ break;
+ } else {
+ ffm->packet_ptr = ffm->packet;
+ }
+ goto redo;
+ }
+ memcpy(buf, ffm->packet_ptr, len);
+ buf += len;
+ ffm->packet_ptr += len;
+ size -= len;
+ first = 0;
+ }
+ return size1 - size;
+}
+
+
+static void adjust_write_index(AVFormatContext *s)
+{
+ FFMContext *ffm = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ int64_t pts;
+ //offset_t orig_write_index = ffm->write_index;
+ offset_t pos_min, pos_max;
+ int64_t pts_start;
+ offset_t ptr = url_ftell(pb);
+
+
+ pos_min = 0;
+ pos_max = ffm->file_size - 2 * FFM_PACKET_SIZE;
+
+ pts_start = get_pts(s, pos_min);
+
+ pts = get_pts(s, pos_max);
+
+ if (pts - 100000 > pts_start)
+ goto end;
+
+ ffm->write_index = FFM_PACKET_SIZE;
+
+ pts_start = get_pts(s, pos_min);
+
+ pts = get_pts(s, pos_max);
+
+ if (pts - 100000 <= pts_start) {
+ while (1) {
+ offset_t newpos;
+ int64_t newpts;
+
+ newpos = ((pos_max + pos_min) / (2 * FFM_PACKET_SIZE)) * FFM_PACKET_SIZE;
+
+ if (newpos == pos_min)
+ break;
+
+ newpts = get_pts(s, newpos);
+
+ if (newpts - 100000 <= pts) {
+ pos_max = newpos;
+ pts = newpts;
+ } else {
+ pos_min = newpos;
+ }
+ }
+ ffm->write_index += pos_max;
+ }
+
+ //printf("Adjusted write index from %"PRId64" to %"PRId64": pts=%0.6f\n", orig_write_index, ffm->write_index, pts / 1000000.);
+ //printf("pts range %0.6f - %0.6f\n", get_pts(s, 0) / 1000000. , get_pts(s, ffm->file_size - 2 * FFM_PACKET_SIZE) / 1000000. );
+
+ end:
+ url_fseek(pb, ptr, SEEK_SET);
+}
+
+
+static int ffm_read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+ FFMContext *ffm = s->priv_data;
+ AVStream *st;
+ FFMStream *fst;
+ ByteIOContext *pb = &s->pb;
+ AVCodecContext *codec;
+ int i, nb_streams;
+ uint32_t tag;
+
+ /* header */
+ tag = get_le32(pb);
+ if (tag != MKTAG('F', 'F', 'M', '1'))
+ goto fail;
+ ffm->packet_size = get_be32(pb);
+ if (ffm->packet_size != FFM_PACKET_SIZE)
+ goto fail;
+ ffm->write_index = get_be64(pb);
+ /* get also filesize */
+ if (!url_is_streamed(pb)) {
+ ffm->file_size = url_fsize(pb);
+ adjust_write_index(s);
+ } else {
+ ffm->file_size = (UINT64_C(1) << 63) - 1;
+ }
+
+ nb_streams = get_be32(pb);
+ get_be32(pb); /* total bitrate */
+ /* read each stream */
+ for(i=0;i<nb_streams;i++) {
+ char rc_eq_buf[128];
+
+ st = av_new_stream(s, 0);
+ if (!st)
+ goto fail;
+ fst = av_mallocz(sizeof(FFMStream));
+ if (!fst)
+ goto fail;
+ s->streams[i] = st;
+
+ av_set_pts_info(st, 64, 1, 1000000);
+
+ st->priv_data = fst;
+
+ codec = st->codec;
+ /* generic info */
+ codec->codec_id = get_be32(pb);
+ codec->codec_type = get_byte(pb); /* codec_type */
+ codec->bit_rate = get_be32(pb);
+ st->quality = get_be32(pb);
+ codec->flags = get_be32(pb);
+ codec->flags2 = get_be32(pb);
+ codec->debug = get_be32(pb);
+ /* specific info */
+ switch(codec->codec_type) {
+ case CODEC_TYPE_VIDEO:
+ codec->time_base.num = get_be32(pb);
+ codec->time_base.den = get_be32(pb);
+ codec->width = get_be16(pb);
+ codec->height = get_be16(pb);
+ codec->gop_size = get_be16(pb);
+ codec->pix_fmt = get_be32(pb);
+ codec->qmin = get_byte(pb);
+ codec->qmax = get_byte(pb);
+ codec->max_qdiff = get_byte(pb);
+ codec->qcompress = get_be16(pb) / 10000.0;
+ codec->qblur = get_be16(pb) / 10000.0;
+ codec->bit_rate_tolerance = get_be32(pb);
+ codec->rc_eq = av_strdup(get_strz(pb, rc_eq_buf, sizeof(rc_eq_buf)));
+ codec->rc_max_rate = get_be32(pb);
+ codec->rc_min_rate = get_be32(pb);
+ codec->rc_buffer_size = get_be32(pb);
+ codec->i_quant_factor = av_int2dbl(get_be64(pb));
+ codec->b_quant_factor = av_int2dbl(get_be64(pb));
+ codec->i_quant_offset = av_int2dbl(get_be64(pb));
+ codec->b_quant_offset = av_int2dbl(get_be64(pb));
+ codec->dct_algo = get_be32(pb);
+ codec->strict_std_compliance = get_be32(pb);
+ codec->max_b_frames = get_be32(pb);
+ codec->luma_elim_threshold = get_be32(pb);
+ codec->chroma_elim_threshold = get_be32(pb);
+ codec->mpeg_quant = get_be32(pb);
+ codec->intra_dc_precision = get_be32(pb);
+ codec->me_method = get_be32(pb);
+ codec->mb_decision = get_be32(pb);
+ codec->nsse_weight = get_be32(pb);
+ codec->frame_skip_cmp = get_be32(pb);
+ codec->rc_buffer_aggressivity = av_int2dbl(get_be64(pb));
+ codec->codec_tag = get_be32(pb);
+ break;
+ case CODEC_TYPE_AUDIO:
+ codec->sample_rate = get_be32(pb);
+ codec->channels = get_le16(pb);
+ codec->frame_size = get_le16(pb);
+ break;
+ default:
+ goto fail;
+ }
+
+ }
+
+ /* get until end of block reached */
+ while ((url_ftell(pb) % ffm->packet_size) != 0)
+ get_byte(pb);
+
+ /* init packet demux */
+ ffm->packet_ptr = ffm->packet;
+ ffm->packet_end = ffm->packet;
+ ffm->frame_offset = 0;
+ ffm->pts = 0;
+ ffm->read_state = READ_HEADER;
+ ffm->first_packet = 1;
+ return 0;
+ fail:
+ for(i=0;i<s->nb_streams;i++) {
+ st = s->streams[i];
+ if (st) {
+ av_freep(&st->priv_data);
+ av_free(st);
+ }
+ }
+ return -1;
+}
+
+/* return < 0 if eof */
+static int ffm_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ int size;
+ FFMContext *ffm = s->priv_data;
+ int duration;
+
+ switch(ffm->read_state) {
+ case READ_HEADER:
+ if (!ffm_is_avail_data(s, FRAME_HEADER_SIZE)) {
+ return AVERROR(EAGAIN);
+ }
+#if 0
+ printf("pos=%08"PRIx64" spos=%"PRIx64", write_index=%"PRIx64" size=%"PRIx64"\n",
+ url_ftell(&s->pb), s->pb.pos, ffm->write_index, ffm->file_size);
+#endif
+ if (ffm_read_data(s, ffm->header, FRAME_HEADER_SIZE, 1) !=
+ FRAME_HEADER_SIZE)
+ return AVERROR(EAGAIN);
+#if 0
+ {
+ int i;
+ for(i=0;i<FRAME_HEADER_SIZE;i++)
+ printf("%02x ", ffm->header[i]);
+ printf("\n");
+ }
+#endif
+ ffm->read_state = READ_DATA;
+ /* fall thru */
+ case READ_DATA:
+ size = (ffm->header[2] << 16) | (ffm->header[3] << 8) | ffm->header[4];
+ if (!ffm_is_avail_data(s, size)) {
+ return AVERROR(EAGAIN);
+ }
+
+ duration = (ffm->header[5] << 16) | (ffm->header[6] << 8) | ffm->header[7];
+
+ av_new_packet(pkt, size);
+ pkt->stream_index = ffm->header[0];
+ pkt->pos = url_ftell(&s->pb);
+ if (ffm->header[1] & FLAG_KEY_FRAME)
+ pkt->flags |= PKT_FLAG_KEY;
+
+ ffm->read_state = READ_HEADER;
+ if (ffm_read_data(s, pkt->data, size, 0) != size) {
+ /* bad case: desynchronized packet. we cancel all the packet loading */
+ av_free_packet(pkt);
+ return AVERROR(EAGAIN);
+ }
+ if (ffm->first_frame_in_packet)
+ {
+ pkt->pts = ffm->pts;
+ ffm->first_frame_in_packet = 0;
+ }
+ pkt->duration = duration;
+ break;
+ }
+ return 0;
+}
+
+//#define DEBUG_SEEK
+
+/* pos is between 0 and file_size - FFM_PACKET_SIZE. It is translated
+ by the write position inside this function */
+static void ffm_seek1(AVFormatContext *s, offset_t pos1)
+{
+ FFMContext *ffm = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ offset_t pos;
+
+ pos = pos1 + ffm->write_index;
+ if (pos >= ffm->file_size)
+ pos -= (ffm->file_size - FFM_PACKET_SIZE);
+#ifdef DEBUG_SEEK
+ printf("seek to %"PRIx64" -> %"PRIx64"\n", pos1, pos);
+#endif
+ url_fseek(pb, pos, SEEK_SET);
+}
+
+static int64_t get_pts(AVFormatContext *s, offset_t pos)
+{
+ ByteIOContext *pb = &s->pb;
+ int64_t pts;
+
+ ffm_seek1(s, pos);
+ url_fskip(pb, 4);
+ pts = get_be64(pb);
+#ifdef DEBUG_SEEK
+ printf("pts=%0.6f\n", pts / 1000000.0);
+#endif
+ return pts;
+}
+
+/* seek to a given time in the file. The file read pointer is
+ positionned at or before pts. XXX: the following code is quite
+ approximative */
+static int ffm_seek(AVFormatContext *s, int stream_index, int64_t wanted_pts, int flags)
+{
+ FFMContext *ffm = s->priv_data;
+ offset_t pos_min, pos_max, pos;
+ int64_t pts_min, pts_max, pts;
+ double pos1;
+
+#ifdef DEBUG_SEEK
+ printf("wanted_pts=%0.6f\n", wanted_pts / 1000000.0);
+#endif
+ /* find the position using linear interpolation (better than
+ dichotomy in typical cases) */
+ pos_min = 0;
+ pos_max = ffm->file_size - 2 * FFM_PACKET_SIZE;
+ while (pos_min <= pos_max) {
+ pts_min = get_pts(s, pos_min);
+ pts_max = get_pts(s, pos_max);
+ /* linear interpolation */
+ pos1 = (double)(pos_max - pos_min) * (double)(wanted_pts - pts_min) /
+ (double)(pts_max - pts_min);
+ pos = (((int64_t)pos1) / FFM_PACKET_SIZE) * FFM_PACKET_SIZE;
+ if (pos <= pos_min)
+ pos = pos_min;
+ else if (pos >= pos_max)
+ pos = pos_max;
+ pts = get_pts(s, pos);
+ /* check if we are lucky */
+ if (pts == wanted_pts) {
+ goto found;
+ } else if (pts > wanted_pts) {
+ pos_max = pos - FFM_PACKET_SIZE;
+ } else {
+ pos_min = pos + FFM_PACKET_SIZE;
+ }
+ }
+ pos = (flags & AVSEEK_FLAG_BACKWARD) ? pos_min : pos_max;
+ if (pos > 0)
+ pos -= FFM_PACKET_SIZE;
+ found:
+ ffm_seek1(s, pos);
+ return 0;
+}
+
+#ifdef CONFIG_FFSERVER
+offset_t ffm_read_write_index(int fd)
+{
+ uint8_t buf[8];
+ offset_t pos;
+ int i;
+
+ lseek(fd, 8, SEEK_SET);
+ read(fd, buf, 8);
+ pos = 0;
+ for(i=0;i<8;i++)
+ pos |= (int64_t)buf[i] << (56 - i * 8);
+ return pos;
+}
+
+void ffm_write_write_index(int fd, offset_t pos)
+{
+ uint8_t buf[8];
+ int i;
+
+ for(i=0;i<8;i++)
+ buf[i] = (pos >> (56 - i * 8)) & 0xff;
+ lseek(fd, 8, SEEK_SET);
+ write(fd, buf, 8);
+}
+
+void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size)
+{
+ FFMContext *ffm = s->priv_data;
+ ffm->write_index = pos;
+ ffm->file_size = file_size;
+}
+#endif // CONFIG_FFSERVER
+
+static int ffm_read_close(AVFormatContext *s)
+{
+ AVStream *st;
+ int i;
+
+ for(i=0;i<s->nb_streams;i++) {
+ st = s->streams[i];
+ av_freep(&st->priv_data);
+ }
+ return 0;
+}
+
+static int ffm_probe(AVProbeData *p)
+{
+ if (p->buf_size >= 4 &&
+ p->buf[0] == 'F' && p->buf[1] == 'F' && p->buf[2] == 'M' &&
+ p->buf[3] == '1')
+ return AVPROBE_SCORE_MAX + 1;
+ return 0;
+}
+
+#ifdef CONFIG_FFM_DEMUXER
+AVInputFormat ffm_demuxer = {
+ "ffm",
+ "ffm format",
+ sizeof(FFMContext),
+ ffm_probe,
+ ffm_read_header,
+ ffm_read_packet,
+ ffm_read_close,
+ ffm_seek,
+};
+#endif
+#ifdef CONFIG_FFM_MUXER
+AVOutputFormat ffm_muxer = {
+ "ffm",
+ "ffm format",
+ "",
+ "ffm",
+ sizeof(FFMContext),
+ /* not really used */
+ CODEC_ID_MP2,
+ CODEC_ID_MPEG1VIDEO,
+ ffm_write_header,
+ ffm_write_packet,
+ ffm_write_trailer,
+};
+#endif //CONFIG_FFM_MUXER
diff --git a/contrib/ffmpeg/libavformat/file.c b/contrib/ffmpeg/libavformat/file.c
new file mode 100644
index 000000000..3caf80a61
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/file.c
@@ -0,0 +1,130 @@
+/*
+ * Buffered file io for ffmpeg system
+ * Copyright (c) 2001 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 "avformat.h"
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/time.h>
+
+
+/* standard file protocol */
+
+static int file_open(URLContext *h, const char *filename, int flags)
+{
+ int access;
+ int fd;
+
+ strstart(filename, "file:", &filename);
+
+ if (flags & URL_RDWR) {
+ access = O_CREAT | O_TRUNC | O_RDWR;
+ } else if (flags & URL_WRONLY) {
+ access = O_CREAT | O_TRUNC | O_WRONLY;
+ } else {
+ access = O_RDONLY;
+ }
+#if defined(__MINGW32__) || defined(CONFIG_OS2) || defined(__CYGWIN__)
+ access |= O_BINARY;
+#endif
+ fd = open(filename, access, 0666);
+ if (fd < 0)
+ return AVERROR(ENOENT);
+ h->priv_data = (void *)(size_t)fd;
+ return 0;
+}
+
+static int file_read(URLContext *h, unsigned char *buf, int size)
+{
+ int fd = (size_t)h->priv_data;
+ return read(fd, buf, size);
+}
+
+static int file_write(URLContext *h, unsigned char *buf, int size)
+{
+ int fd = (size_t)h->priv_data;
+ return write(fd, buf, size);
+}
+
+/* XXX: use llseek */
+static offset_t file_seek(URLContext *h, offset_t pos, int whence)
+{
+ int fd = (size_t)h->priv_data;
+ return lseek(fd, pos, whence);
+}
+
+static int file_close(URLContext *h)
+{
+ int fd = (size_t)h->priv_data;
+ return close(fd);
+}
+
+URLProtocol file_protocol = {
+ "file",
+ file_open,
+ file_read,
+ file_write,
+ file_seek,
+ file_close,
+};
+
+/* pipe protocol */
+
+static int pipe_open(URLContext *h, const char *filename, int flags)
+{
+ int fd;
+
+ if (flags & URL_WRONLY) {
+ fd = 1;
+ } else {
+ fd = 0;
+ }
+#if defined(__MINGW32__) || defined(CONFIG_OS2) || defined(__CYGWIN__)
+ setmode(fd, O_BINARY);
+#endif
+ h->priv_data = (void *)(size_t)fd;
+ h->is_streamed = 1;
+ return 0;
+}
+
+static int pipe_read(URLContext *h, unsigned char *buf, int size)
+{
+ int fd = (size_t)h->priv_data;
+ return read(fd, buf, size);
+}
+
+static int pipe_write(URLContext *h, unsigned char *buf, int size)
+{
+ int fd = (size_t)h->priv_data;
+ return write(fd, buf, size);
+}
+
+static int pipe_close(URLContext *h)
+{
+ return 0;
+}
+
+URLProtocol pipe_protocol = {
+ "pipe",
+ pipe_open,
+ pipe_read,
+ pipe_write,
+ NULL,
+ pipe_close,
+};
diff --git a/contrib/ffmpeg/libavformat/flic.c b/contrib/ffmpeg/libavformat/flic.c
new file mode 100644
index 000000000..0c3a7f01f
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/flic.c
@@ -0,0 +1,223 @@
+/*
+ * FLI/FLC Animation File Demuxer
+ * Copyright (c) 2003 The ffmpeg Project
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file flic.c
+ * 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".
+ */
+
+#include "avformat.h"
+
+#define FLIC_FILE_MAGIC_1 0xAF11
+#define FLIC_FILE_MAGIC_2 0xAF12
+#define FLIC_FILE_MAGIC_3 0xAF44 /* Flic Type for Extended FLX Format which
+ originated in Dave's Targa Animator (DTA) */
+#define FLIC_CHUNK_MAGIC_1 0xF1FA
+#define FLIC_CHUNK_MAGIC_2 0xF5FA
+#define FLIC_MC_PTS_INC 6000 /* pts increment for Magic Carpet game FLIs */
+#define FLIC_DEFAULT_PTS_INC 6000 /* for FLIs that have 0 speed */
+
+#define FLIC_HEADER_SIZE 128
+#define FLIC_PREAMBLE_SIZE 6
+
+typedef struct FlicDemuxContext {
+ int frame_pts_inc;
+ int64_t pts;
+ int video_stream_index;
+} FlicDemuxContext;
+
+static int flic_probe(AVProbeData *p)
+{
+ int magic_number;
+
+ if (p->buf_size < 6)
+ return 0;
+
+ magic_number = AV_RL16(&p->buf[4]);
+ if ((magic_number != FLIC_FILE_MAGIC_1) &&
+ (magic_number != FLIC_FILE_MAGIC_2) &&
+ (magic_number != FLIC_FILE_MAGIC_3))
+ return 0;
+
+ return AVPROBE_SCORE_MAX;
+}
+
+static int flic_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ FlicDemuxContext *flic = (FlicDemuxContext *)s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ unsigned char header[FLIC_HEADER_SIZE];
+ AVStream *st;
+ int speed;
+ int magic_number;
+
+ flic->pts = 0;
+
+ /* load the whole header and pull out the width and height */
+ if (get_buffer(pb, header, FLIC_HEADER_SIZE) != FLIC_HEADER_SIZE)
+ return AVERROR_IO;
+
+ magic_number = AV_RL16(&header[4]);
+ speed = AV_RL32(&header[0x10]);
+
+ /* initialize the decoder streams */
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+ flic->video_stream_index = st->index;
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ st->codec->codec_id = CODEC_ID_FLIC;
+ st->codec->codec_tag = 0; /* no fourcc */
+ st->codec->width = AV_RL16(&header[0x08]);
+ st->codec->height = AV_RL16(&header[0x0A]);
+
+ if (!st->codec->width || !st->codec->height)
+ return AVERROR_INVALIDDATA;
+
+ /* send over the whole 128-byte FLIC header */
+ st->codec->extradata_size = FLIC_HEADER_SIZE;
+ st->codec->extradata = av_malloc(FLIC_HEADER_SIZE);
+ memcpy(st->codec->extradata, header, FLIC_HEADER_SIZE);
+
+ av_set_pts_info(st, 33, 1, 90000);
+
+ /* 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) {
+
+ flic->frame_pts_inc = FLIC_MC_PTS_INC;
+
+ /* rewind the stream since the first chunk is at offset 12 */
+ url_fseek(pb, 12, SEEK_SET);
+
+ /* send over abbreviated FLIC header chunk */
+ av_free(st->codec->extradata);
+ st->codec->extradata_size = 12;
+ st->codec->extradata = av_malloc(12);
+ memcpy(st->codec->extradata, header, 12);
+
+ } else if (magic_number == FLIC_FILE_MAGIC_1) {
+ /*
+ * in this case, the speed (n) is number of 1/70s ticks between frames:
+ *
+ * pts n * frame #
+ * -------- = ----------- => pts = n * (90000/70) * frame #
+ * 90000 70
+ *
+ * therefore, the frame pts increment = n * 1285.7
+ */
+ flic->frame_pts_inc = speed * 1285.7;
+ } else if ((magic_number == FLIC_FILE_MAGIC_2) ||
+ (magic_number == FLIC_FILE_MAGIC_3)) {
+ /*
+ * in this case, the speed (n) is number of milliseconds between frames:
+ *
+ * pts n * frame #
+ * -------- = ----------- => pts = n * 90 * frame #
+ * 90000 1000
+ *
+ * therefore, the frame pts increment = n * 90
+ */
+ flic->frame_pts_inc = speed * 90;
+ } else {
+ av_log(s, AV_LOG_INFO, "Invalid or unsupported magic chunk in file\n");
+ return AVERROR_INVALIDDATA;
+ }
+
+ if (flic->frame_pts_inc == 0)
+ flic->frame_pts_inc = FLIC_DEFAULT_PTS_INC;
+
+ return 0;
+}
+
+static int flic_read_packet(AVFormatContext *s,
+ AVPacket *pkt)
+{
+ FlicDemuxContext *flic = (FlicDemuxContext *)s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ int packet_read = 0;
+ unsigned int size;
+ int magic;
+ int ret = 0;
+ unsigned char preamble[FLIC_PREAMBLE_SIZE];
+
+ while (!packet_read) {
+
+ if ((ret = get_buffer(pb, preamble, FLIC_PREAMBLE_SIZE)) !=
+ FLIC_PREAMBLE_SIZE) {
+ ret = AVERROR_IO;
+ break;
+ }
+
+ size = AV_RL32(&preamble[0]);
+ magic = AV_RL16(&preamble[4]);
+
+ if (((magic == FLIC_CHUNK_MAGIC_1) || (magic == FLIC_CHUNK_MAGIC_2)) && size > FLIC_PREAMBLE_SIZE) {
+ if (av_new_packet(pkt, size)) {
+ ret = AVERROR_IO;
+ break;
+ }
+ pkt->stream_index = flic->video_stream_index;
+ pkt->pts = flic->pts;
+ pkt->pos = url_ftell(pb);
+ memcpy(pkt->data, preamble, FLIC_PREAMBLE_SIZE);
+ ret = get_buffer(pb, pkt->data + FLIC_PREAMBLE_SIZE,
+ size - FLIC_PREAMBLE_SIZE);
+ if (ret != size - FLIC_PREAMBLE_SIZE) {
+ av_free_packet(pkt);
+ ret = AVERROR_IO;
+ }
+ flic->pts += flic->frame_pts_inc;
+ packet_read = 1;
+ } else {
+ /* not interested in this chunk */
+ url_fseek(pb, size - 6, SEEK_CUR);
+ }
+ }
+
+ return ret;
+}
+
+static int flic_read_close(AVFormatContext *s)
+{
+// FlicDemuxContext *flic = (FlicDemuxContext *)s->priv_data;
+
+ return 0;
+}
+
+AVInputFormat flic_demuxer = {
+ "flic",
+ "FLI/FLC/FLX animation format",
+ sizeof(FlicDemuxContext),
+ flic_probe,
+ flic_read_header,
+ flic_read_packet,
+ flic_read_close,
+};
diff --git a/contrib/ffmpeg/libavformat/flv.h b/contrib/ffmpeg/libavformat/flv.h
new file mode 100644
index 000000000..1484ac15d
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/flv.h
@@ -0,0 +1,110 @@
+/**
+ * @file flv.h
+ * FLV common header
+ *
+ * Copyright (c) 2006 The FFmpeg Project.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef FLV_H
+#define FLV_H
+
+/* offsets for packed values */
+#define FLV_AUDIO_SAMPLESSIZE_OFFSET 1
+#define FLV_AUDIO_SAMPLERATE_OFFSET 2
+#define FLV_AUDIO_CODECID_OFFSET 4
+
+#define FLV_VIDEO_FRAMETYPE_OFFSET 4
+
+/* bitmasks to isolate specific values */
+#define FLV_AUDIO_CHANNEL_MASK 0x01
+#define FLV_AUDIO_SAMPLESIZE_MASK 0x02
+#define FLV_AUDIO_SAMPLERATE_MASK 0x0c
+#define FLV_AUDIO_CODECID_MASK 0xf0
+
+#define FLV_VIDEO_CODECID_MASK 0x0f
+#define FLV_VIDEO_FRAMETYPE_MASK 0xf0
+
+#define AMF_END_OF_OBJECT 0x09
+
+enum {
+ FLV_HEADER_FLAG_HASVIDEO = 1,
+ FLV_HEADER_FLAG_HASAUDIO = 4,
+};
+
+enum {
+ FLV_TAG_TYPE_AUDIO = 0x08,
+ FLV_TAG_TYPE_VIDEO = 0x09,
+ FLV_TAG_TYPE_META = 0x12,
+};
+
+enum {
+ FLV_MONO = 0,
+ FLV_STEREO = 1,
+};
+
+enum {
+ FLV_SAMPLESSIZE_8BIT = 0,
+ FLV_SAMPLESSIZE_16BIT = 1 << FLV_AUDIO_SAMPLESSIZE_OFFSET,
+};
+
+enum {
+ FLV_SAMPLERATE_SPECIAL = 0, /**< signifies 5512Hz and 8000Hz in the case of NELLYMOSER */
+ FLV_SAMPLERATE_11025HZ = 1 << FLV_AUDIO_SAMPLERATE_OFFSET,
+ FLV_SAMPLERATE_22050HZ = 2 << FLV_AUDIO_SAMPLERATE_OFFSET,
+ FLV_SAMPLERATE_44100HZ = 3 << FLV_AUDIO_SAMPLERATE_OFFSET,
+};
+
+enum {
+ FLV_CODECID_PCM_BE = 0,
+ FLV_CODECID_ADPCM = 1 << FLV_AUDIO_CODECID_OFFSET,
+ FLV_CODECID_MP3 = 2 << FLV_AUDIO_CODECID_OFFSET,
+ FLV_CODECID_PCM_LE = 3 << FLV_AUDIO_CODECID_OFFSET,
+ FLV_CODECID_NELLYMOSER_8HZ_MONO = 5 << FLV_AUDIO_CODECID_OFFSET,
+ FLV_CODECID_NELLYMOSER = 6 << FLV_AUDIO_CODECID_OFFSET,
+};
+
+enum {
+ FLV_CODECID_H263 = 2,
+ FLV_CODECID_SCREEN = 3,
+ FLV_CODECID_VP6 = 4,
+ FLV_CODECID_VP6A = 5,
+ FLV_CODECID_SCREEN2 = 6,
+};
+
+enum {
+ FLV_FRAME_KEY = 1 << FLV_VIDEO_FRAMETYPE_OFFSET,
+ FLV_FRAME_INTER = 2 << FLV_VIDEO_FRAMETYPE_OFFSET,
+ FLV_FRAME_DISP_INTER = 3 << FLV_VIDEO_FRAMETYPE_OFFSET,
+};
+
+typedef enum {
+ AMF_DATA_TYPE_NUMBER = 0x00,
+ AMF_DATA_TYPE_BOOL = 0x01,
+ AMF_DATA_TYPE_STRING = 0x02,
+ AMF_DATA_TYPE_OBJECT = 0x03,
+ AMF_DATA_TYPE_NULL = 0x05,
+ AMF_DATA_TYPE_UNDEFINED = 0x06,
+ AMF_DATA_TYPE_REFERENCE = 0x07,
+ AMF_DATA_TYPE_MIXEDARRAY = 0x08,
+ AMF_DATA_TYPE_ARRAY = 0x0a,
+ AMF_DATA_TYPE_DATE = 0x0b,
+ AMF_DATA_TYPE_UNSUPPORTED = 0x0d,
+} AMFDataType;
+
+#endif /* FLV_H */
diff --git a/contrib/ffmpeg/libavformat/flvdec.c b/contrib/ffmpeg/libavformat/flvdec.c
new file mode 100644
index 000000000..bf91fbbc7
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/flvdec.c
@@ -0,0 +1,395 @@
+/*
+ * FLV demuxer
+ * Copyright (c) 2003 The FFmpeg Project.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ *
+ * This demuxer will generate a 1 byte extradata for VP6F content.
+ * It is composed of:
+ * - upper 4bits: difference between encoded width and visible width
+ * - lower 4bits: difference between encoded height and visible height
+ */
+#include "avformat.h"
+#include "flv.h"
+
+static int flv_probe(AVProbeData *p)
+{
+ const uint8_t *d;
+
+ if (p->buf_size < 6)
+ return 0;
+ d = p->buf;
+ if (d[0] == 'F' && d[1] == 'L' && d[2] == 'V' && d[3] < 5 && d[5]==0) {
+ return AVPROBE_SCORE_MAX;
+ }
+ return 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_BE:
+ acodec->codec_id = acodec->bits_per_sample == 8 ? CODEC_ID_PCM_S8 : CODEC_ID_PCM_S16BE; break;
+ case FLV_CODECID_PCM_LE:
+ acodec->codec_id = acodec->bits_per_sample == 8 ? CODEC_ID_PCM_S8 : CODEC_ID_PCM_S16LE; break;
+ case FLV_CODECID_ADPCM: acodec->codec_id = CODEC_ID_ADPCM_SWF; break;
+ case FLV_CODECID_MP3 : acodec->codec_id = CODEC_ID_MP3 ; astream->need_parsing = 1 ; break;
+ case FLV_CODECID_NELLYMOSER_8HZ_MONO:
+ acodec->sample_rate = 8000; //in case metadata does not otherwise declare samplerate
+ case FLV_CODECID_NELLYMOSER:
+ default:
+ av_log(s, AV_LOG_INFO, "Unsupported audio codec (%x)\n", flv_codecid >> FLV_AUDIO_CODECID_OFFSET);
+ acodec->codec_tag = flv_codecid >> FLV_AUDIO_CODECID_OFFSET;
+ }
+}
+
+static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream, int flv_codecid) {
+ AVCodecContext *vcodec = vstream->codec;
+ 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_VP6 : vcodec->codec_id = CODEC_ID_VP6F ;
+ if(vcodec->extradata_size != 1) {
+ vcodec->extradata_size = 1;
+ vcodec->extradata = av_malloc(1);
+ }
+ vcodec->extradata[0] = get_byte(&s->pb);
+ return 1; // 1 byte body size adjustment for flv_read_packet()
+ default:
+ av_log(s, AV_LOG_INFO, "Unsupported video codec (%x)\n", flv_codecid);
+ vcodec->codec_tag = flv_codecid;
+ }
+
+ return 0;
+}
+
+static int amf_get_string(ByteIOContext *ioc, char *buffer, int buffsize) {
+ int length = get_be16(ioc);
+ if(length >= buffsize) {
+ url_fskip(ioc, length);
+ return -1;
+ }
+
+ get_buffer(ioc, buffer, length);
+
+ buffer[length] = '\0';
+
+ return length;
+}
+
+static int amf_parse_object(AVFormatContext *s, AVStream *astream, AVStream *vstream, const char *key, unsigned int max_pos, int depth) {
+ AVCodecContext *acodec, *vcodec;
+ ByteIOContext *ioc;
+ AMFDataType amf_type;
+ char str_val[256];
+ double num_val;
+
+ num_val = 0;
+ ioc = &s->pb;
+
+ amf_type = get_byte(ioc);
+
+ switch(amf_type) {
+ case AMF_DATA_TYPE_NUMBER:
+ num_val = av_int2dbl(get_be64(ioc)); break;
+ case AMF_DATA_TYPE_BOOL:
+ num_val = get_byte(ioc); break;
+ case AMF_DATA_TYPE_STRING:
+ if(amf_get_string(ioc, str_val, sizeof(str_val)) < 0)
+ return -1;
+ break;
+ case AMF_DATA_TYPE_OBJECT: {
+ unsigned int keylen;
+
+ while(url_ftell(ioc) < max_pos - 2 && (keylen = get_be16(ioc))) {
+ url_fskip(ioc, keylen); //skip key string
+ if(amf_parse_object(s, NULL, NULL, NULL, max_pos, depth + 1) < 0)
+ return -1; //if we couldn't skip, bomb out.
+ }
+ if(get_byte(ioc) != AMF_END_OF_OBJECT)
+ return -1;
+ }
+ break;
+ case AMF_DATA_TYPE_NULL:
+ case AMF_DATA_TYPE_UNDEFINED:
+ case AMF_DATA_TYPE_UNSUPPORTED:
+ break; //these take up no additional space
+ case AMF_DATA_TYPE_MIXEDARRAY:
+ url_fskip(ioc, 4); //skip 32-bit max array index
+ while(url_ftell(ioc) < max_pos - 2 && amf_get_string(ioc, str_val, sizeof(str_val)) > 0) {
+ //this is the only case in which we would want a nested parse to not skip over the object
+ if(amf_parse_object(s, astream, vstream, str_val, max_pos, depth + 1) < 0)
+ return -1;
+ }
+ if(get_byte(ioc) != AMF_END_OF_OBJECT)
+ return -1;
+ break;
+ case AMF_DATA_TYPE_ARRAY: {
+ unsigned int arraylen, i;
+
+ arraylen = get_be32(ioc);
+ for(i = 0; i < arraylen && url_ftell(ioc) < max_pos - 1; i++) {
+ if(amf_parse_object(s, NULL, NULL, NULL, max_pos, depth + 1) < 0)
+ return -1; //if we couldn't skip, bomb out.
+ }
+ }
+ break;
+ case AMF_DATA_TYPE_DATE:
+ url_fskip(ioc, 8 + 2); //timestamp (double) and UTC offset (int16)
+ break;
+ default: //unsupported type, we couldn't skip
+ return -1;
+ }
+
+ if(depth == 1 && key) { //only look for metadata values when we are not nested and key != NULL
+ acodec = astream ? astream->codec : NULL;
+ vcodec = vstream ? vstream->codec : NULL;
+
+ if(amf_type == AMF_DATA_TYPE_BOOL) {
+ if(!strcmp(key, "stereo") && acodec) acodec->channels = num_val > 0 ? 2 : 1;
+ } else if(amf_type == AMF_DATA_TYPE_NUMBER) {
+ if(!strcmp(key, "duration")) s->duration = num_val * AV_TIME_BASE;
+// else if(!strcmp(key, "width") && vcodec && num_val > 0) vcodec->width = num_val;
+// else if(!strcmp(key, "height") && vcodec && num_val > 0) vcodec->height = num_val;
+ else if(!strcmp(key, "audiocodecid") && acodec) flv_set_audio_codec(s, astream, (int)num_val << FLV_AUDIO_CODECID_OFFSET);
+ else if(!strcmp(key, "videocodecid") && vcodec) flv_set_video_codec(s, vstream, (int)num_val);
+ else if(!strcmp(key, "audiosamplesize") && acodec && num_val >= 0) {
+ acodec->bits_per_sample = num_val;
+ //we may have to rewrite a previously read codecid because FLV only marks PCM endianness.
+ if(num_val == 8 && (acodec->codec_id == CODEC_ID_PCM_S16BE || acodec->codec_id == CODEC_ID_PCM_S16LE))
+ acodec->codec_id = CODEC_ID_PCM_S8;
+ }
+ else if(!strcmp(key, "audiosamplerate") && acodec && num_val >= 0) {
+ //some tools, like FLVTool2, write consistently approximate metadata sample rates
+ switch((int)num_val) {
+ case 44000: acodec->sample_rate = 44100 ; break;
+ case 22000: acodec->sample_rate = 22050 ; break;
+ case 11000: acodec->sample_rate = 11025 ; break;
+ case 5000 : acodec->sample_rate = 5512 ; break;
+ default : acodec->sample_rate = num_val;
+ }
+ }
+ }
+ }
+
+ return 0;
+}
+
+static int flv_read_metabody(AVFormatContext *s, unsigned int next_pos) {
+ AMFDataType type;
+ AVStream *stream, *astream, *vstream;
+ ByteIOContext *ioc;
+ int i, keylen;
+ char buffer[11]; //only needs to hold the string "onMetaData". Anything longer is something we don't want.
+
+ astream = NULL;
+ vstream = NULL;
+ keylen = 0;
+ ioc = &s->pb;
+
+ //first object needs to be "onMetaData" string
+ type = get_byte(ioc);
+ if(type != AMF_DATA_TYPE_STRING || amf_get_string(ioc, buffer, sizeof(buffer)) < 0 || strcmp(buffer, "onMetaData"))
+ return -1;
+
+ //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;
+ }
+
+ //parse the second object (we want a mixed array)
+ if(amf_parse_object(s, astream, vstream, buffer, next_pos, 0) < 0)
+ return -1;
+
+ return 0;
+}
+
+static int flv_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ int offset, flags;
+ AVStream *st;
+
+ url_fskip(&s->pb, 4);
+ flags = get_byte(&s->pb);
+ /* old flvtool cleared this field */
+ /* FIXME: better fix needed */
+ if (!flags) {
+ flags = FLV_HEADER_FLAG_HASVIDEO | FLV_HEADER_FLAG_HASAUDIO;
+ av_log(s, AV_LOG_WARNING, "Broken FLV file, which says no streams present, this might fail\n");
+ }
+
+ if(flags & FLV_HEADER_FLAG_HASVIDEO){
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ av_set_pts_info(st, 24, 1, 1000); /* 24 bit pts in ms */
+ }
+ if(flags & FLV_HEADER_FLAG_HASAUDIO){
+ st = av_new_stream(s, 1);
+ if (!st)
+ return AVERROR_NOMEM;
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ av_set_pts_info(st, 24, 1, 1000); /* 24 bit pts in ms */
+ }
+
+ offset = get_be32(&s->pb);
+ url_fseek(&s->pb, offset, SEEK_SET);
+
+ s->start_time = 0;
+
+ return 0;
+}
+
+static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ int ret, i, type, size, pts, flags, is_audio, next, pos;
+ AVStream *st = NULL;
+
+ for(;;){
+ pos = url_ftell(&s->pb);
+ url_fskip(&s->pb, 4); /* size of previous packet */
+ type = get_byte(&s->pb);
+ size = get_be24(&s->pb);
+ pts = get_be24(&s->pb);
+// av_log(s, AV_LOG_DEBUG, "type:%d, size:%d, pts:%d\n", type, size, pts);
+ if (url_feof(&s->pb))
+ return AVERROR_IO;
+ url_fskip(&s->pb, 4); /* reserved */
+ flags = 0;
+
+ if(size == 0)
+ continue;
+
+ next= size + url_ftell(&s->pb);
+
+ if (type == FLV_TAG_TYPE_AUDIO) {
+ is_audio=1;
+ flags = get_byte(&s->pb);
+ } else if (type == FLV_TAG_TYPE_VIDEO) {
+ is_audio=0;
+ flags = get_byte(&s->pb);
+ } else {
+ if (type == FLV_TAG_TYPE_META && size > 13+1+4)
+ flv_read_metabody(s, next);
+ else /* skip packet */
+ av_log(s, AV_LOG_ERROR, "skipping flv packet: type %d, size %d, flags %d\n", type, size, flags);
+ url_fseek(&s->pb, next, SEEK_SET);
+ continue;
+ }
+
+ /* now find stream */
+ for(i=0;i<s->nb_streams;i++) {
+ st = s->streams[i];
+ if (st->id == is_audio)
+ break;
+ }
+ if(i == s->nb_streams){
+ av_log(NULL, AV_LOG_ERROR, "invalid stream\n");
+ url_fseek(&s->pb, next, SEEK_SET);
+ continue;
+ }
+// av_log(NULL, AV_LOG_DEBUG, "%d %X %d \n", is_audio, flags, st->discard);
+ if( (st->discard >= AVDISCARD_NONKEY && !((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY || is_audio))
+ ||(st->discard >= AVDISCARD_BIDIR && ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_DISP_INTER && !is_audio))
+ || st->discard >= AVDISCARD_ALL
+ ){
+ url_fseek(&s->pb, next, SEEK_SET);
+ continue;
+ }
+ if ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY)
+ av_add_index_entry(st, pos, pts, size, 0, AVINDEX_KEYFRAME);
+ break;
+ }
+
+ // 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){
+ int size;
+ const int pos= url_ftell(&s->pb);
+ const int fsize= url_fsize(&s->pb);
+ url_fseek(&s->pb, fsize-4, SEEK_SET);
+ 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;
+ }
+ url_fseek(&s->pb, pos, SEEK_SET);
+ }
+
+ if(is_audio){
+ if(!st->codec->sample_rate || !st->codec->bits_per_sample || (!st->codec->codec_id && !st->codec->codec_tag)) {
+ st->codec->channels = (flags & FLV_AUDIO_CHANNEL_MASK) == FLV_STEREO ? 2 : 1;
+ if((flags & FLV_AUDIO_CODECID_MASK) == FLV_CODECID_NELLYMOSER_8HZ_MONO)
+ st->codec->sample_rate= 8000;
+ else
+ st->codec->sample_rate = (44100 << ((flags & FLV_AUDIO_SAMPLERATE_MASK) >> FLV_AUDIO_SAMPLERATE_OFFSET) >> 3);
+ st->codec->bits_per_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8;
+ flv_set_audio_codec(s, st, flags & FLV_AUDIO_CODECID_MASK);
+ }
+ }else{
+ size -= flv_set_video_codec(s, st, flags & FLV_VIDEO_CODECID_MASK);
+ }
+
+ ret= av_get_packet(&s->pb, pkt, size - 1);
+ if (ret <= 0) {
+ return AVERROR_IO;
+ }
+ /* note: we need to modify the packet size here to handle the last
+ packet */
+ pkt->size = ret;
+ pkt->pts = pts;
+ pkt->stream_index = st->index;
+
+ if (is_audio || ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY))
+ pkt->flags |= PKT_FLAG_KEY;
+
+ return ret;
+}
+
+static int flv_read_close(AVFormatContext *s)
+{
+ return 0;
+}
+
+static int flv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
+{
+ AVStream *st = s->streams[stream_index];
+ int index = av_index_search_timestamp(st, timestamp, flags);
+ if (index < 0)
+ return -1;
+ url_fseek(&s->pb, st->index_entries[index].pos, SEEK_SET);
+
+ return 0;
+}
+
+AVInputFormat flv_demuxer = {
+ "flv",
+ "flv format",
+ 0,
+ flv_probe,
+ flv_read_header,
+ flv_read_packet,
+ flv_read_close,
+ flv_read_seek,
+ .extensions = "flv",
+ .value = CODEC_ID_FLV1,
+};
diff --git a/contrib/ffmpeg/libavformat/flvenc.c b/contrib/ffmpeg/libavformat/flvenc.c
new file mode 100644
index 000000000..ece585d77
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/flvenc.c
@@ -0,0 +1,336 @@
+/*
+ * FLV muxer
+ * Copyright (c) 2003 The FFmpeg Project.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include "avformat.h"
+#include "flv.h"
+#include "riff.h"
+
+#undef NDEBUG
+#include <assert.h>
+
+static const AVCodecTag flv_video_codec_ids[] = {
+ {CODEC_ID_FLV1, FLV_CODECID_H263 },
+ {CODEC_ID_FLASHSV, FLV_CODECID_SCREEN},
+ {CODEC_ID_VP6F, FLV_CODECID_VP6 },
+ {CODEC_ID_VP6, FLV_CODECID_VP6 },
+ {CODEC_ID_NONE, 0}
+};
+
+static const AVCodecTag flv_audio_codec_ids[] = {
+ {CODEC_ID_MP3, FLV_CODECID_MP3 >> FLV_AUDIO_CODECID_OFFSET},
+ {CODEC_ID_PCM_S8, FLV_CODECID_PCM_BE >> FLV_AUDIO_CODECID_OFFSET},
+ {CODEC_ID_PCM_S16BE, FLV_CODECID_PCM_BE >> 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_NONE, 0}
+};
+
+typedef struct FLVContext {
+ int hasAudio;
+ int hasVideo;
+ int reserved;
+ offset_t duration_offset;
+ offset_t filesize_offset;
+ int64_t duration;
+} FLVContext;
+
+static int get_audio_flags(AVCodecContext *enc){
+ int flags = (enc->bits_per_sample == 16) ? FLV_SAMPLESSIZE_16BIT : FLV_SAMPLESSIZE_8BIT;
+
+ switch (enc->sample_rate) {
+ case 44100:
+ flags |= FLV_SAMPLERATE_44100HZ;
+ break;
+ case 22050:
+ flags |= FLV_SAMPLERATE_22050HZ;
+ break;
+ case 11025:
+ flags |= FLV_SAMPLERATE_11025HZ;
+ break;
+ case 8000: //nellymoser only
+ case 5512: //not mp3
+ flags |= FLV_SAMPLERATE_SPECIAL;
+ break;
+ default:
+ av_log(enc, AV_LOG_ERROR, "flv doesnt support that sample rate, choose from (44100, 22050, 11025)\n");
+ return -1;
+ }
+
+ if (enc->channels > 1) {
+ flags |= FLV_STEREO;
+ }
+
+ switch(enc->codec_id){
+ case CODEC_ID_MP3:
+ flags |= FLV_CODECID_MP3 | FLV_SAMPLESSIZE_16BIT;
+ break;
+ case CODEC_ID_PCM_S8:
+ flags |= FLV_CODECID_PCM_BE | FLV_SAMPLESSIZE_8BIT;
+ break;
+ case CODEC_ID_PCM_S16BE:
+ flags |= FLV_CODECID_PCM_BE | FLV_SAMPLESSIZE_16BIT;
+ break;
+ case CODEC_ID_PCM_S16LE:
+ flags |= FLV_CODECID_PCM_LE | FLV_SAMPLESSIZE_16BIT;
+ break;
+ case CODEC_ID_ADPCM_SWF:
+ flags |= FLV_CODECID_ADPCM | FLV_SAMPLESSIZE_16BIT;
+ break;
+ case 0:
+ flags |= enc->codec_tag<<4;
+ break;
+ default:
+ av_log(enc, AV_LOG_ERROR, "codec not compatible with flv\n");
+ return -1;
+ }
+
+ return flags;
+}
+
+static void put_amf_string(ByteIOContext *pb, const char *str)
+{
+ size_t len = strlen(str);
+ put_be16(pb, len);
+ put_buffer(pb, str, len);
+}
+
+static void put_amf_double(ByteIOContext *pb, double d)
+{
+ put_byte(pb, AMF_DATA_TYPE_NUMBER);
+ put_be64(pb, av_dbl2int(d));
+}
+
+static void put_amf_bool(ByteIOContext *pb, int b) {
+ put_byte(pb, AMF_DATA_TYPE_BOOL);
+ put_byte(pb, !!b);
+}
+
+static int flv_write_header(AVFormatContext *s)
+{
+ ByteIOContext *pb = &s->pb;
+ FLVContext *flv = s->priv_data;
+ int i, width, height, samplerate, samplesize, channels, audiocodecid, videocodecid;
+ double framerate = 0.0;
+ int metadata_size_pos, data_size;
+
+ flv->hasAudio = 0;
+ flv->hasVideo = 0;
+
+ for(i=0; i<s->nb_streams; i++){
+ AVCodecContext *enc = s->streams[i]->codec;
+ if (enc->codec_type == CODEC_TYPE_VIDEO) {
+ width = enc->width;
+ height = enc->height;
+ 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 {
+ framerate = 1/av_q2d(s->streams[i]->codec->time_base);
+ }
+ flv->hasVideo=1;
+
+ videocodecid = enc->codec_tag;
+ if(videocodecid == 0) {
+ av_log(enc, AV_LOG_ERROR, "video codec not compatible with flv\n");
+ return -1;
+ }
+ } else {
+ flv->hasAudio=1;
+ samplerate = enc->sample_rate;
+ channels = enc->channels;
+
+ audiocodecid = enc->codec_tag;
+ samplesize = (enc->codec_id == CODEC_ID_PCM_S8) ? 8 : 16;
+
+ if(get_audio_flags(enc)<0)
+ return -1;
+ }
+ av_set_pts_info(s->streams[i], 24, 1, 1000); /* 24 bit pts in ms */
+ }
+ put_tag(pb,"FLV");
+ put_byte(pb,1);
+ put_byte(pb, FLV_HEADER_FLAG_HASAUDIO * flv->hasAudio
+ + FLV_HEADER_FLAG_HASVIDEO * flv->hasVideo);
+ put_be32(pb,9);
+ put_be32(pb,0);
+
+ for(i=0; i<s->nb_streams; i++){
+ if(s->streams[i]->codec->codec_tag == 5){
+ put_byte(pb,8); // message type
+ put_be24(pb,0); // include flags
+ put_be24(pb,0); // time stamp
+ put_be32(pb,0); // reserved
+ put_be32(pb,11); // size
+ flv->reserved=5;
+ }
+ }
+
+ /* write meta_tag */
+ put_byte(pb, 18); // tag type META
+ metadata_size_pos= url_ftell(pb);
+ put_be24(pb, 0); // size of data part (sum of all parts below)
+ put_be24(pb, 0); // time stamp
+ put_be32(pb, 0); // reserved
+
+ /* now data of data_size size */
+
+ /* first event name as a string */
+ put_byte(pb, AMF_DATA_TYPE_STRING);
+ put_amf_string(pb, "onMetaData"); // 12 bytes
+
+ /* mixed array (hash) with size and string/type/data tuples */
+ put_byte(pb, AMF_DATA_TYPE_MIXEDARRAY);
+ put_be32(pb, 5*flv->hasVideo + 4*flv->hasAudio + 2); // +2 for duration and file size
+
+ put_amf_string(pb, "duration");
+ flv->duration_offset= url_ftell(pb);
+ put_amf_double(pb, 0); // delayed write
+
+ if(flv->hasVideo){
+ put_amf_string(pb, "width");
+ put_amf_double(pb, width);
+
+ put_amf_string(pb, "height");
+ put_amf_double(pb, height);
+
+ put_amf_string(pb, "videodatarate");
+ put_amf_double(pb, s->bit_rate / 1024.0);
+
+ put_amf_string(pb, "framerate");
+ put_amf_double(pb, framerate);
+
+ put_amf_string(pb, "videocodecid");
+ put_amf_double(pb, videocodecid);
+ }
+
+ if(flv->hasAudio){
+ put_amf_string(pb, "audiosamplerate");
+ put_amf_double(pb, samplerate);
+
+ put_amf_string(pb, "audiosamplesize");
+ put_amf_double(pb, samplesize);
+
+ put_amf_string(pb, "stereo");
+ put_amf_bool(pb, (channels == 2));
+
+ put_amf_string(pb, "audiocodecid");
+ put_amf_double(pb, audiocodecid);
+ }
+
+ put_amf_string(pb, "filesize");
+ flv->filesize_offset= url_ftell(pb);
+ put_amf_double(pb, 0); // delayed write
+
+ put_amf_string(pb, "");
+ put_byte(pb, AMF_END_OF_OBJECT);
+
+ /* write total size of tag */
+ data_size= url_ftell(pb) - metadata_size_pos - 10;
+ url_fseek(pb, metadata_size_pos, SEEK_SET);
+ put_be24(pb, data_size);
+ url_fseek(pb, data_size + 10 - 3, SEEK_CUR);
+ put_be32(pb, data_size + 11);
+
+ return 0;
+}
+
+static int flv_write_trailer(AVFormatContext *s)
+{
+ int64_t file_size;
+
+ ByteIOContext *pb = &s->pb;
+ FLVContext *flv = s->priv_data;
+
+ file_size = url_ftell(pb);
+
+ /* update informations */
+ url_fseek(pb, flv->duration_offset, SEEK_SET);
+ put_amf_double(pb, flv->duration / (double)1000);
+ url_fseek(pb, flv->filesize_offset, SEEK_SET);
+ put_amf_double(pb, file_size);
+
+ url_fseek(pb, file_size, SEEK_SET);
+ return 0;
+}
+
+static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ ByteIOContext *pb = &s->pb;
+ AVCodecContext *enc = s->streams[pkt->stream_index]->codec;
+ FLVContext *flv = s->priv_data;
+ int size= pkt->size;
+ int flags;
+
+// av_log(s, AV_LOG_DEBUG, "type:%d pts: %"PRId64" size:%d\n", enc->codec_type, timestamp, size);
+
+ if (enc->codec_type == CODEC_TYPE_VIDEO) {
+ put_byte(pb, FLV_TAG_TYPE_VIDEO);
+
+ flags = enc->codec_tag;
+ if(flags == 0) {
+ av_log(enc, AV_LOG_ERROR, "video codec %X not compatible with flv\n",enc->codec_id);
+ return -1;
+ }
+
+ flags |= pkt->flags & PKT_FLAG_KEY ? FLV_FRAME_KEY : FLV_FRAME_INTER;
+ } else {
+ assert(enc->codec_type == CODEC_TYPE_AUDIO);
+ flags = get_audio_flags(enc);
+
+ assert(size);
+
+ put_byte(pb, FLV_TAG_TYPE_AUDIO);
+ }
+
+ if ((enc->codec_id == CODEC_ID_VP6) || (enc->codec_id == CODEC_ID_VP6F))
+ put_be24(pb,size+2); // include the extra byte needed for VP6 in flv and flags
+ else
+ put_be24(pb,size+1); // include flags
+ put_be24(pb,pkt->pts);
+ put_be32(pb,flv->reserved);
+ put_byte(pb,flags);
+ if (enc->codec_id == CODEC_ID_VP6)
+ put_byte(pb,0);
+ if (enc->codec_id == CODEC_ID_VP6F)
+ put_byte(pb, enc->extradata_size ? enc->extradata[0] : 0);
+ put_buffer(pb, pkt->data, size);
+ put_be32(pb,size+1+11); // previous tag size
+ flv->duration = pkt->pts + pkt->duration;
+
+ put_flush_packet(pb);
+ return 0;
+}
+
+AVOutputFormat flv_muxer = {
+ "flv",
+ "flv format",
+ "video/x-flv",
+ "flv",
+ sizeof(FLVContext),
+#ifdef CONFIG_LIBMP3LAME
+ CODEC_ID_MP3,
+#else // CONFIG_LIBMP3LAME
+ CODEC_ID_NONE,
+#endif // CONFIG_LIBMP3LAME
+ CODEC_ID_FLV1,
+ flv_write_header,
+ flv_write_packet,
+ flv_write_trailer,
+ .codec_tag= (const AVCodecTag*[]){flv_video_codec_ids, flv_audio_codec_ids, 0},
+};
diff --git a/contrib/ffmpeg/libavformat/framehook.c b/contrib/ffmpeg/libavformat/framehook.c
new file mode 100644
index 000000000..8738f8030
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/framehook.c
@@ -0,0 +1,120 @@
+/*
+ * Video processing hooks
+ * Copyright (c) 2000, 2001 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 <errno.h>
+#include "config.h"
+#include "avformat.h"
+#include "framehook.h"
+
+#ifdef HAVE_DLFCN_H
+#include <dlfcn.h>
+#endif
+
+
+typedef struct _FrameHookEntry {
+ struct _FrameHookEntry *next;
+ FrameHookConfigureFn Configure;
+ FrameHookProcessFn Process;
+ FrameHookReleaseFn Release;
+ void *ctx;
+} FrameHookEntry;
+
+static FrameHookEntry *first_hook;
+
+/* Returns 0 on OK */
+int frame_hook_add(int argc, char *argv[])
+{
+#ifdef CONFIG_VHOOK
+ void *loaded;
+ FrameHookEntry *fhe, **fhep;
+
+ if (argc < 1) {
+ return ENOENT;
+ }
+
+ loaded = dlopen(argv[0], RTLD_NOW);
+ if (!loaded) {
+ av_log(NULL, AV_LOG_ERROR, "%s\n", dlerror());
+ return -1;
+ }
+
+ fhe = av_mallocz(sizeof(*fhe));
+ if (!fhe) {
+ return AVERROR(ENOMEM);
+ }
+
+ fhe->Configure = dlsym(loaded, "Configure");
+ fhe->Process = dlsym(loaded, "Process");
+ fhe->Release = dlsym(loaded, "Release"); /* Optional */
+
+ if (!fhe->Process) {
+ av_log(NULL, AV_LOG_ERROR, "Failed to find Process entrypoint in %s\n", argv[0]);
+ return AVERROR(ENOENT);
+ }
+
+ if (!fhe->Configure && argc > 1) {
+ av_log(NULL, AV_LOG_ERROR, "Failed to find Configure entrypoint in %s\n", argv[0]);
+ return AVERROR(ENOENT);
+ }
+
+ if (argc > 1 || fhe->Configure) {
+ if (fhe->Configure(&fhe->ctx, argc, argv)) {
+ av_log(NULL, AV_LOG_ERROR, "Failed to Configure %s\n", argv[0]);
+ return AVERROR(EINVAL);
+ }
+ }
+
+ for (fhep = &first_hook; *fhep; fhep = &((*fhep)->next)) {
+ }
+
+ *fhep = fhe;
+
+ return 0;
+#else
+ av_log(NULL, AV_LOG_ERROR, "Video hooking not compiled into this version\n");
+ return 1;
+#endif
+}
+
+void frame_hook_process(AVPicture *pict, enum PixelFormat pix_fmt, int width, int height, int64_t pts)
+{
+ if (first_hook) {
+ FrameHookEntry *fhe;
+
+ for (fhe = first_hook; fhe; fhe = fhe->next) {
+ fhe->Process(fhe->ctx, pict, pix_fmt, width, height, pts);
+ }
+ }
+}
+
+void frame_hook_release(void)
+{
+ FrameHookEntry *fhe;
+ FrameHookEntry *fhenext;
+
+ for (fhe = first_hook; fhe; fhe = fhenext) {
+ fhenext = fhe->next;
+ if (fhe->Release)
+ fhe->Release(fhe->ctx);
+ av_free(fhe);
+ }
+
+ first_hook = NULL;
+}
diff --git a/contrib/ffmpeg/libavformat/framehook.h b/contrib/ffmpeg/libavformat/framehook.h
new file mode 100644
index 000000000..06ed4f889
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/framehook.h
@@ -0,0 +1,52 @@
+/*
+ * video processing hooks
+ * copyright (c) 2000, 2001 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
+ */
+
+#ifndef _FRAMEHOOK_H
+#define _FRAMEHOOK_H
+
+#warning VHOOK is deprecated please help porting libmpcodecs or a better filter system to ffmpeg instead of wasting your time writing new fiters for this crappy one
+
+/*
+ * Prototypes for interface to .so that implement a video processing hook
+ */
+
+#include "avcodec.h"
+
+/* Function must be called 'Configure' */
+typedef int (FrameHookConfigure)(void **ctxp, int argc, char *argv[]);
+typedef FrameHookConfigure *FrameHookConfigureFn;
+extern FrameHookConfigure Configure;
+
+/* Function must be called 'Process' */
+typedef void (FrameHookProcess)(void *ctx, struct AVPicture *pict, enum PixelFormat pix_fmt, int width, int height, int64_t pts);
+typedef FrameHookProcess *FrameHookProcessFn;
+extern FrameHookProcess Process;
+
+/* Function must be called 'Release' */
+typedef void (FrameHookRelease)(void *ctx);
+typedef FrameHookRelease *FrameHookReleaseFn;
+extern FrameHookRelease Release;
+
+extern int frame_hook_add(int argc, char *argv[]);
+extern void frame_hook_process(struct AVPicture *pict, enum PixelFormat pix_fmt, int width, int height, int64_t pts);
+extern void frame_hook_release(void);
+
+#endif
diff --git a/contrib/ffmpeg/libavformat/gif.c b/contrib/ffmpeg/libavformat/gif.c
new file mode 100644
index 000000000..1083710d5
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/gif.c
@@ -0,0 +1,419 @@
+/*
+ * Animated GIF muxer
+ * Copyright (c) 2000 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
+ */
+
+/*
+ * First version by Francois Revol revol@free.fr
+ *
+ * Features and limitations:
+ * - currently no compression is performed,
+ * in fact the size of the data is 9/8 the size of the image in 8bpp
+ * - uses only a global standard palette
+ * - tested with IE 5.0, Opera for BeOS, NetPositive (BeOS), and Mozilla (BeOS).
+ *
+ * Reference documents:
+ * http://www.goice.co.jp/member/mo/formats/gif.html
+ * http://astronomy.swin.edu.au/pbourke/dataformats/gif/
+ * http://www.dcs.ed.ac.uk/home/mxr/gfx/2d/GIF89a.txt
+ *
+ * this url claims to have an LZW algorithm not covered by Unisys patent:
+ * http://www.msg.net/utility/whirlgif/gifencod.html
+ * could help reduce the size of the files _a lot_...
+ * some sites mentions an RLE type compression also.
+ */
+
+#include "avformat.h"
+#include "bitstream.h"
+
+/* bitstream minipacket size */
+#define GIF_CHUNKS 100
+
+/* slows down the decoding (and some browsers don't like it) */
+/* update on the 'some browsers don't like it issue from above: this was probably due to missing 'Data Sub-block Terminator' (byte 19) in the app_header */
+#define GIF_ADD_APP_HEADER // required to enable looping of animated gif
+
+typedef struct {
+ unsigned char r;
+ unsigned char g;
+ unsigned char b;
+} rgb_triplet;
+
+/* we use the standard 216 color palette */
+
+/* this script was used to create the palette:
+ * for r in 00 33 66 99 cc ff; do for g in 00 33 66 99 cc ff; do echo -n " "; for b in 00 33 66 99 cc ff; do
+ * echo -n "{ 0x$r, 0x$g, 0x$b }, "; done; echo ""; done; done
+ */
+
+static const rgb_triplet gif_clut[216] = {
+ { 0x00, 0x00, 0x00 }, { 0x00, 0x00, 0x33 }, { 0x00, 0x00, 0x66 }, { 0x00, 0x00, 0x99 }, { 0x00, 0x00, 0xcc }, { 0x00, 0x00, 0xff },
+ { 0x00, 0x33, 0x00 }, { 0x00, 0x33, 0x33 }, { 0x00, 0x33, 0x66 }, { 0x00, 0x33, 0x99 }, { 0x00, 0x33, 0xcc }, { 0x00, 0x33, 0xff },
+ { 0x00, 0x66, 0x00 }, { 0x00, 0x66, 0x33 }, { 0x00, 0x66, 0x66 }, { 0x00, 0x66, 0x99 }, { 0x00, 0x66, 0xcc }, { 0x00, 0x66, 0xff },
+ { 0x00, 0x99, 0x00 }, { 0x00, 0x99, 0x33 }, { 0x00, 0x99, 0x66 }, { 0x00, 0x99, 0x99 }, { 0x00, 0x99, 0xcc }, { 0x00, 0x99, 0xff },
+ { 0x00, 0xcc, 0x00 }, { 0x00, 0xcc, 0x33 }, { 0x00, 0xcc, 0x66 }, { 0x00, 0xcc, 0x99 }, { 0x00, 0xcc, 0xcc }, { 0x00, 0xcc, 0xff },
+ { 0x00, 0xff, 0x00 }, { 0x00, 0xff, 0x33 }, { 0x00, 0xff, 0x66 }, { 0x00, 0xff, 0x99 }, { 0x00, 0xff, 0xcc }, { 0x00, 0xff, 0xff },
+ { 0x33, 0x00, 0x00 }, { 0x33, 0x00, 0x33 }, { 0x33, 0x00, 0x66 }, { 0x33, 0x00, 0x99 }, { 0x33, 0x00, 0xcc }, { 0x33, 0x00, 0xff },
+ { 0x33, 0x33, 0x00 }, { 0x33, 0x33, 0x33 }, { 0x33, 0x33, 0x66 }, { 0x33, 0x33, 0x99 }, { 0x33, 0x33, 0xcc }, { 0x33, 0x33, 0xff },
+ { 0x33, 0x66, 0x00 }, { 0x33, 0x66, 0x33 }, { 0x33, 0x66, 0x66 }, { 0x33, 0x66, 0x99 }, { 0x33, 0x66, 0xcc }, { 0x33, 0x66, 0xff },
+ { 0x33, 0x99, 0x00 }, { 0x33, 0x99, 0x33 }, { 0x33, 0x99, 0x66 }, { 0x33, 0x99, 0x99 }, { 0x33, 0x99, 0xcc }, { 0x33, 0x99, 0xff },
+ { 0x33, 0xcc, 0x00 }, { 0x33, 0xcc, 0x33 }, { 0x33, 0xcc, 0x66 }, { 0x33, 0xcc, 0x99 }, { 0x33, 0xcc, 0xcc }, { 0x33, 0xcc, 0xff },
+ { 0x33, 0xff, 0x00 }, { 0x33, 0xff, 0x33 }, { 0x33, 0xff, 0x66 }, { 0x33, 0xff, 0x99 }, { 0x33, 0xff, 0xcc }, { 0x33, 0xff, 0xff },
+ { 0x66, 0x00, 0x00 }, { 0x66, 0x00, 0x33 }, { 0x66, 0x00, 0x66 }, { 0x66, 0x00, 0x99 }, { 0x66, 0x00, 0xcc }, { 0x66, 0x00, 0xff },
+ { 0x66, 0x33, 0x00 }, { 0x66, 0x33, 0x33 }, { 0x66, 0x33, 0x66 }, { 0x66, 0x33, 0x99 }, { 0x66, 0x33, 0xcc }, { 0x66, 0x33, 0xff },
+ { 0x66, 0x66, 0x00 }, { 0x66, 0x66, 0x33 }, { 0x66, 0x66, 0x66 }, { 0x66, 0x66, 0x99 }, { 0x66, 0x66, 0xcc }, { 0x66, 0x66, 0xff },
+ { 0x66, 0x99, 0x00 }, { 0x66, 0x99, 0x33 }, { 0x66, 0x99, 0x66 }, { 0x66, 0x99, 0x99 }, { 0x66, 0x99, 0xcc }, { 0x66, 0x99, 0xff },
+ { 0x66, 0xcc, 0x00 }, { 0x66, 0xcc, 0x33 }, { 0x66, 0xcc, 0x66 }, { 0x66, 0xcc, 0x99 }, { 0x66, 0xcc, 0xcc }, { 0x66, 0xcc, 0xff },
+ { 0x66, 0xff, 0x00 }, { 0x66, 0xff, 0x33 }, { 0x66, 0xff, 0x66 }, { 0x66, 0xff, 0x99 }, { 0x66, 0xff, 0xcc }, { 0x66, 0xff, 0xff },
+ { 0x99, 0x00, 0x00 }, { 0x99, 0x00, 0x33 }, { 0x99, 0x00, 0x66 }, { 0x99, 0x00, 0x99 }, { 0x99, 0x00, 0xcc }, { 0x99, 0x00, 0xff },
+ { 0x99, 0x33, 0x00 }, { 0x99, 0x33, 0x33 }, { 0x99, 0x33, 0x66 }, { 0x99, 0x33, 0x99 }, { 0x99, 0x33, 0xcc }, { 0x99, 0x33, 0xff },
+ { 0x99, 0x66, 0x00 }, { 0x99, 0x66, 0x33 }, { 0x99, 0x66, 0x66 }, { 0x99, 0x66, 0x99 }, { 0x99, 0x66, 0xcc }, { 0x99, 0x66, 0xff },
+ { 0x99, 0x99, 0x00 }, { 0x99, 0x99, 0x33 }, { 0x99, 0x99, 0x66 }, { 0x99, 0x99, 0x99 }, { 0x99, 0x99, 0xcc }, { 0x99, 0x99, 0xff },
+ { 0x99, 0xcc, 0x00 }, { 0x99, 0xcc, 0x33 }, { 0x99, 0xcc, 0x66 }, { 0x99, 0xcc, 0x99 }, { 0x99, 0xcc, 0xcc }, { 0x99, 0xcc, 0xff },
+ { 0x99, 0xff, 0x00 }, { 0x99, 0xff, 0x33 }, { 0x99, 0xff, 0x66 }, { 0x99, 0xff, 0x99 }, { 0x99, 0xff, 0xcc }, { 0x99, 0xff, 0xff },
+ { 0xcc, 0x00, 0x00 }, { 0xcc, 0x00, 0x33 }, { 0xcc, 0x00, 0x66 }, { 0xcc, 0x00, 0x99 }, { 0xcc, 0x00, 0xcc }, { 0xcc, 0x00, 0xff },
+ { 0xcc, 0x33, 0x00 }, { 0xcc, 0x33, 0x33 }, { 0xcc, 0x33, 0x66 }, { 0xcc, 0x33, 0x99 }, { 0xcc, 0x33, 0xcc }, { 0xcc, 0x33, 0xff },
+ { 0xcc, 0x66, 0x00 }, { 0xcc, 0x66, 0x33 }, { 0xcc, 0x66, 0x66 }, { 0xcc, 0x66, 0x99 }, { 0xcc, 0x66, 0xcc }, { 0xcc, 0x66, 0xff },
+ { 0xcc, 0x99, 0x00 }, { 0xcc, 0x99, 0x33 }, { 0xcc, 0x99, 0x66 }, { 0xcc, 0x99, 0x99 }, { 0xcc, 0x99, 0xcc }, { 0xcc, 0x99, 0xff },
+ { 0xcc, 0xcc, 0x00 }, { 0xcc, 0xcc, 0x33 }, { 0xcc, 0xcc, 0x66 }, { 0xcc, 0xcc, 0x99 }, { 0xcc, 0xcc, 0xcc }, { 0xcc, 0xcc, 0xff },
+ { 0xcc, 0xff, 0x00 }, { 0xcc, 0xff, 0x33 }, { 0xcc, 0xff, 0x66 }, { 0xcc, 0xff, 0x99 }, { 0xcc, 0xff, 0xcc }, { 0xcc, 0xff, 0xff },
+ { 0xff, 0x00, 0x00 }, { 0xff, 0x00, 0x33 }, { 0xff, 0x00, 0x66 }, { 0xff, 0x00, 0x99 }, { 0xff, 0x00, 0xcc }, { 0xff, 0x00, 0xff },
+ { 0xff, 0x33, 0x00 }, { 0xff, 0x33, 0x33 }, { 0xff, 0x33, 0x66 }, { 0xff, 0x33, 0x99 }, { 0xff, 0x33, 0xcc }, { 0xff, 0x33, 0xff },
+ { 0xff, 0x66, 0x00 }, { 0xff, 0x66, 0x33 }, { 0xff, 0x66, 0x66 }, { 0xff, 0x66, 0x99 }, { 0xff, 0x66, 0xcc }, { 0xff, 0x66, 0xff },
+ { 0xff, 0x99, 0x00 }, { 0xff, 0x99, 0x33 }, { 0xff, 0x99, 0x66 }, { 0xff, 0x99, 0x99 }, { 0xff, 0x99, 0xcc }, { 0xff, 0x99, 0xff },
+ { 0xff, 0xcc, 0x00 }, { 0xff, 0xcc, 0x33 }, { 0xff, 0xcc, 0x66 }, { 0xff, 0xcc, 0x99 }, { 0xff, 0xcc, 0xcc }, { 0xff, 0xcc, 0xff },
+ { 0xff, 0xff, 0x00 }, { 0xff, 0xff, 0x33 }, { 0xff, 0xff, 0x66 }, { 0xff, 0xff, 0x99 }, { 0xff, 0xff, 0xcc }, { 0xff, 0xff, 0xff },
+};
+
+/* The GIF format uses reversed order for bitstreams... */
+/* at least they don't use PDP_ENDIAN :) */
+/* so we 'extend' PutBitContext. hmmm, OOP :) */
+/* seems this thing changed slightly since I wrote it... */
+
+#ifdef ALT_BITSTREAM_WRITER
+# error no ALT_BITSTREAM_WRITER support for now
+#endif
+
+static void gif_put_bits_rev(PutBitContext *s, int n, unsigned int value)
+{
+ unsigned int bit_buf;
+ int bit_cnt;
+
+ // printf("put_bits=%d %x\n", n, value);
+ assert(n == 32 || value < (1U << n));
+
+ bit_buf = s->bit_buf;
+ bit_cnt = 32 - s->bit_left; /* XXX:lazyness... was = s->bit_cnt; */
+
+ // printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf);
+ /* XXX: optimize */
+ if (n < (32-bit_cnt)) {
+ bit_buf |= value << (bit_cnt);
+ bit_cnt+=n;
+ } else {
+ bit_buf |= value << (bit_cnt);
+
+ *s->buf_ptr = bit_buf & 0xff;
+ s->buf_ptr[1] = (bit_buf >> 8) & 0xff;
+ s->buf_ptr[2] = (bit_buf >> 16) & 0xff;
+ s->buf_ptr[3] = (bit_buf >> 24) & 0xff;
+
+ //printf("bitbuf = %08x\n", bit_buf);
+ s->buf_ptr+=4;
+ if (s->buf_ptr >= s->buf_end)
+ puts("bit buffer overflow !!"); // should never happen ! who got rid of the callback ???
+// flush_buffer_rev(s);
+ bit_cnt=bit_cnt + n - 32;
+ if (bit_cnt == 0) {
+ bit_buf = 0;
+ } else {
+ bit_buf = value >> (n - bit_cnt);
+ }
+ }
+
+ s->bit_buf = bit_buf;
+ s->bit_left = 32 - bit_cnt;
+}
+
+/* pad the end of the output stream with zeros */
+static void gif_flush_put_bits_rev(PutBitContext *s)
+{
+ while (s->bit_left < 32) {
+ /* XXX: should test end of buffer */
+ *s->buf_ptr++=s->bit_buf & 0xff;
+ s->bit_buf>>=8;
+ s->bit_left+=8;
+ }
+// flush_buffer_rev(s);
+ s->bit_left=32;
+ s->bit_buf=0;
+}
+
+/* !RevPutBitContext */
+
+/* GIF header */
+static int gif_image_write_header(ByteIOContext *pb,
+ int width, int height, int loop_count,
+ uint32_t *palette)
+{
+ int i;
+ unsigned int v;
+
+ put_tag(pb, "GIF");
+ put_tag(pb, "89a");
+ put_le16(pb, width);
+ put_le16(pb, height);
+
+ put_byte(pb, 0xf7); /* flags: global clut, 256 entries */
+ put_byte(pb, 0x1f); /* background color index */
+ put_byte(pb, 0); /* aspect ratio */
+
+ /* the global palette */
+ if (!palette) {
+ put_buffer(pb, (const unsigned char *)gif_clut, 216*3);
+ for(i=0;i<((256-216)*3);i++)
+ put_byte(pb, 0);
+ } else {
+ for(i=0;i<256;i++) {
+ v = palette[i];
+ put_byte(pb, (v >> 16) & 0xff);
+ put_byte(pb, (v >> 8) & 0xff);
+ put_byte(pb, (v) & 0xff);
+ }
+ }
+
+ /* update: this is the 'NETSCAPE EXTENSION' that allows for looped animated gif
+ see http://members.aol.com/royalef/gifabout.htm#net-extension
+
+ byte 1 : 33 (hex 0x21) GIF Extension code
+ byte 2 : 255 (hex 0xFF) Application Extension Label
+ byte 3 : 11 (hex (0x0B) Length of Application Block
+ (eleven bytes of data to follow)
+ bytes 4 to 11 : "NETSCAPE"
+ bytes 12 to 14 : "2.0"
+ byte 15 : 3 (hex 0x03) Length of Data Sub-Block
+ (three bytes of data to follow)
+ byte 16 : 1 (hex 0x01)
+ bytes 17 to 18 : 0 to 65535, an unsigned integer in
+ lo-hi byte format. This indicate the
+ number of iterations the loop should
+ be executed.
+ bytes 19 : 0 (hex 0x00) a Data Sub-block Terminator
+ */
+
+ /* application extension header */
+#ifdef GIF_ADD_APP_HEADER
+ if (loop_count >= 0 && loop_count <= 65535) {
+ put_byte(pb, 0x21);
+ put_byte(pb, 0xff);
+ put_byte(pb, 0x0b);
+ put_tag(pb, "NETSCAPE2.0"); // bytes 4 to 14
+ put_byte(pb, 0x03); // byte 15
+ put_byte(pb, 0x01); // byte 16
+ put_le16(pb, (uint16_t)loop_count);
+ put_byte(pb, 0x00); // byte 19
+ }
+#endif
+ return 0;
+}
+
+/* this is maybe slow, but allows for extensions */
+static inline unsigned char gif_clut_index(uint8_t r, uint8_t g, uint8_t b)
+{
+ return ((((r)/47)%6)*6*6+(((g)/47)%6)*6+(((b)/47)%6));
+}
+
+
+static int gif_image_write_image(ByteIOContext *pb,
+ int x1, int y1, int width, int height,
+ const uint8_t *buf, int linesize, int pix_fmt)
+{
+ PutBitContext p;
+ uint8_t buffer[200]; /* 100 * 9 / 8 = 113 */
+ int i, left, w, v;
+ const uint8_t *ptr;
+ /* image block */
+
+ put_byte(pb, 0x2c);
+ put_le16(pb, x1);
+ put_le16(pb, y1);
+ put_le16(pb, width);
+ put_le16(pb, height);
+ put_byte(pb, 0x00); /* flags */
+ /* no local clut */
+
+ put_byte(pb, 0x08);
+
+ left= width * height;
+
+ 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) {
+
+ gif_put_bits_rev(&p, 9, 0x0100); /* clear code */
+
+ for(i=(left<GIF_CHUNKS)?left:GIF_CHUNKS;i;i--) {
+ if (pix_fmt == PIX_FMT_RGB24) {
+ v = gif_clut_index(ptr[0], ptr[1], ptr[2]);
+ ptr+=3;
+ } else {
+ v = *ptr++;
+ }
+ gif_put_bits_rev(&p, 9, v);
+ if (--w == 0) {
+ w = width;
+ buf += linesize;
+ ptr = buf;
+ }
+ }
+
+ if(left<=GIF_CHUNKS) {
+ gif_put_bits_rev(&p, 9, 0x101); /* end of stream */
+ gif_flush_put_bits_rev(&p);
+ }
+ if(pbBufPtr(&p) - p.buf > 0) {
+ put_byte(pb, pbBufPtr(&p) - p.buf); /* byte count of the packet */
+ put_buffer(pb, p.buf, pbBufPtr(&p) - p.buf); /* the actual buffer */
+ p.buf_ptr = p.buf; /* dequeue the bytes off the bitstream */
+ }
+ left-=GIF_CHUNKS;
+ }
+ put_byte(pb, 0x00); /* end of image block */
+
+ return 0;
+}
+
+typedef struct {
+ int64_t time, file_time;
+ uint8_t buffer[100]; /* data chunks */
+} GIFContext;
+
+static int gif_write_header(AVFormatContext *s)
+{
+ GIFContext *gif = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ AVCodecContext *enc, *video_enc;
+ int i, width, height, loop_count /*, rate*/;
+
+/* XXX: do we reject audio streams or just ignore them ?
+ if(s->nb_streams > 1)
+ return -1;
+*/
+ gif->time = 0;
+ gif->file_time = 0;
+
+ video_enc = NULL;
+ for(i=0;i<s->nb_streams;i++) {
+ enc = s->streams[i]->codec;
+ if (enc->codec_type != CODEC_TYPE_AUDIO)
+ video_enc = enc;
+ }
+
+ if (!video_enc) {
+ av_free(gif);
+ return -1;
+ } else {
+ width = video_enc->width;
+ height = video_enc->height;
+ loop_count = s->loop_output;
+// rate = video_enc->time_base.den;
+ }
+
+ if (video_enc->pix_fmt != PIX_FMT_RGB24) {
+ av_log(s, AV_LOG_ERROR, "ERROR: gif only handles the rgb24 pixel format. Use -pix_fmt rgb24.\n");
+ return AVERROR_IO;
+ }
+
+ gif_image_write_header(pb, width, height, loop_count, NULL);
+
+ put_flush_packet(&s->pb);
+ return 0;
+}
+
+static int gif_write_video(AVFormatContext *s,
+ AVCodecContext *enc, const uint8_t *buf, int size)
+{
+ ByteIOContext *pb = &s->pb;
+ GIFContext *gif = s->priv_data;
+ int jiffies;
+ int64_t delay;
+
+ /* graphic control extension block */
+ put_byte(pb, 0x21);
+ put_byte(pb, 0xf9);
+ put_byte(pb, 0x04); /* block size */
+ put_byte(pb, 0x04); /* flags */
+
+ /* 1 jiffy is 1/70 s */
+ /* the delay_time field indicates the number of jiffies - 1 */
+ delay = gif->file_time - gif->time;
+
+ /* XXX: should use delay, in order to be more accurate */
+ /* instead of using the same rounded value each time */
+ /* XXX: don't even remember if I really use it for now */
+ jiffies = (70*enc->time_base.num/enc->time_base.den) - 1;
+
+ put_le16(pb, jiffies);
+
+ put_byte(pb, 0x1f); /* transparent color index */
+ put_byte(pb, 0x00);
+
+ gif_image_write_image(pb, 0, 0, enc->width, enc->height,
+ buf, enc->width * 3, PIX_FMT_RGB24);
+
+ put_flush_packet(&s->pb);
+ return 0;
+}
+
+static int gif_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ AVCodecContext *codec = s->streams[pkt->stream_index]->codec;
+ if (codec->codec_type == CODEC_TYPE_AUDIO)
+ return 0; /* just ignore audio */
+ else
+ return gif_write_video(s, codec, pkt->data, pkt->size);
+}
+
+static int gif_write_trailer(AVFormatContext *s)
+{
+ ByteIOContext *pb = &s->pb;
+
+ put_byte(pb, 0x3b);
+ put_flush_packet(&s->pb);
+ return 0;
+}
+
+AVOutputFormat gif_muxer = {
+ "gif",
+ "GIF Animation",
+ "image/gif",
+ "gif",
+ sizeof(GIFContext),
+ CODEC_ID_NONE,
+ CODEC_ID_RAWVIDEO,
+ gif_write_header,
+ gif_write_packet,
+ gif_write_trailer,
+};
diff --git a/contrib/ffmpeg/libavformat/gifdec.c b/contrib/ffmpeg/libavformat/gifdec.c
new file mode 100644
index 000000000..1d31211f6
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/gifdec.c
@@ -0,0 +1,593 @@
+/*
+ * GIF demuxer
+ * Copyright (c) 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 "avformat.h"
+
+//#define DEBUG
+
+#define MAXBITS 12
+#define SIZTABLE (1<<MAXBITS)
+
+#define GCE_DISPOSAL_NONE 0
+#define GCE_DISPOSAL_INPLACE 1
+#define GCE_DISPOSAL_BACKGROUND 2
+#define GCE_DISPOSAL_RESTORE 3
+
+typedef struct GifState {
+ int screen_width;
+ int screen_height;
+ int bits_per_pixel;
+ int background_color_index;
+ int transparent_color_index;
+ int color_resolution;
+ uint8_t *image_buf;
+ int image_linesize;
+ uint32_t *image_palette;
+ int pix_fmt;
+
+ /* after the frame is displayed, the disposal method is used */
+ int gce_disposal;
+ /* delay during which the frame is shown */
+ int gce_delay;
+
+ /* LZW compatible decoder */
+ ByteIOContext *f;
+ int eob_reached;
+ uint8_t *pbuf, *ebuf;
+ int bbits;
+ unsigned int bbuf;
+
+ int cursize; /* The current code size */
+ int curmask;
+ int codesize;
+ int clear_code;
+ int end_code;
+ int newcodes; /* First available code */
+ int top_slot; /* Highest code for current size */
+ int slot; /* Last read code */
+ int fc, oc;
+ uint8_t *sp;
+ uint8_t stack[SIZTABLE];
+ uint8_t suffix[SIZTABLE];
+ uint16_t prefix[SIZTABLE];
+
+ /* aux buffers */
+ uint8_t global_palette[256 * 3];
+ uint8_t local_palette[256 * 3];
+ uint8_t buf[256];
+} GifState;
+
+
+static const uint8_t gif87a_sig[6] = "GIF87a";
+static const uint8_t gif89a_sig[6] = "GIF89a";
+
+static const uint16_t mask[17] =
+{
+ 0x0000, 0x0001, 0x0003, 0x0007,
+ 0x000F, 0x001F, 0x003F, 0x007F,
+ 0x00FF, 0x01FF, 0x03FF, 0x07FF,
+ 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF
+};
+
+/* Probe gif video format or gif image format. The current heuristic
+ supposes the gif87a is always a single image. For gif89a, we
+ consider it as a video only if a GCE extension is present in the
+ first kilobyte. */
+static int gif_video_probe(AVProbeData * pd)
+{
+ const uint8_t *p, *p_end;
+ int bits_per_pixel, has_global_palette, ext_code, ext_len;
+ int gce_flags, gce_disposal;
+
+ if (pd->buf_size < 24 ||
+ memcmp(pd->buf, gif89a_sig, 6) != 0)
+ return 0;
+ p_end = pd->buf + pd->buf_size;
+ p = pd->buf + 6;
+ bits_per_pixel = (p[4] & 0x07) + 1;
+ has_global_palette = (p[4] & 0x80);
+ p += 7;
+ if (has_global_palette)
+ p += (1 << bits_per_pixel) * 3;
+ for(;;) {
+ if (p >= p_end)
+ return 0;
+ if (*p != '!')
+ break;
+ p++;
+ if (p >= p_end)
+ return 0;
+ ext_code = *p++;
+ if (p >= p_end)
+ return 0;
+ ext_len = *p++;
+ if (ext_code == 0xf9) {
+ if (p >= p_end)
+ return 0;
+ /* if GCE extension found with gce_disposal != 0: it is
+ likely to be an animation */
+ gce_flags = *p++;
+ gce_disposal = (gce_flags >> 2) & 0x7;
+ if (gce_disposal != 0)
+ return AVPROBE_SCORE_MAX;
+ else
+ return 0;
+ }
+ for(;;) {
+ if (ext_len == 0)
+ break;
+ p += ext_len;
+ if (p >= p_end)
+ return 0;
+ ext_len = *p++;
+ }
+ }
+ return 0;
+}
+
+static void GLZWDecodeInit(GifState * s, int csize)
+{
+ /* read buffer */
+ s->eob_reached = 0;
+ s->pbuf = s->buf;
+ s->ebuf = s->buf;
+ s->bbuf = 0;
+ s->bbits = 0;
+
+ /* decoder */
+ s->codesize = csize;
+ s->cursize = s->codesize + 1;
+ s->curmask = mask[s->cursize];
+ s->top_slot = 1 << s->cursize;
+ s->clear_code = 1 << s->codesize;
+ s->end_code = s->clear_code + 1;
+ s->slot = s->newcodes = s->clear_code + 2;
+ s->oc = s->fc = 0;
+ s->sp = s->stack;
+}
+
+/* XXX: optimize */
+static inline int GetCode(GifState * s)
+{
+ int c, sizbuf;
+ uint8_t *ptr;
+
+ while (s->bbits < s->cursize) {
+ ptr = s->pbuf;
+ if (ptr >= s->ebuf) {
+ if (!s->eob_reached) {
+ sizbuf = get_byte(s->f);
+ s->ebuf = s->buf + sizbuf;
+ s->pbuf = s->buf;
+ if (sizbuf > 0) {
+ get_buffer(s->f, s->buf, sizbuf);
+ } else {
+ s->eob_reached = 1;
+ }
+ }
+ ptr = s->pbuf;
+ }
+ s->bbuf |= ptr[0] << s->bbits;
+ ptr++;
+ s->pbuf = ptr;
+ s->bbits += 8;
+ }
+ c = s->bbuf & s->curmask;
+ s->bbuf >>= s->cursize;
+ s->bbits -= s->cursize;
+ return c;
+}
+
+/* NOTE: the algorithm here is inspired from the LZW GIF decoder
+ written by Steven A. Bennett in 1987. */
+/* return the number of byte decoded */
+static int GLZWDecode(GifState * s, uint8_t * buf, int len)
+{
+ int l, c, code, oc, fc;
+ uint8_t *sp;
+
+ if (s->end_code < 0)
+ return 0;
+
+ l = len;
+ sp = s->sp;
+ oc = s->oc;
+ fc = s->fc;
+
+ while (sp > s->stack) {
+ *buf++ = *(--sp);
+ if ((--l) == 0)
+ goto the_end;
+ }
+
+ for (;;) {
+ c = GetCode(s);
+ if (c == s->end_code) {
+ s->end_code = -1;
+ break;
+ } else if (c == s->clear_code) {
+ s->cursize = s->codesize + 1;
+ s->curmask = mask[s->cursize];
+ s->slot = s->newcodes;
+ s->top_slot = 1 << s->cursize;
+ while ((c = GetCode(s)) == s->clear_code);
+ if (c == s->end_code) {
+ s->end_code = -1;
+ break;
+ }
+ /* test error */
+ if (c >= s->slot)
+ c = 0;
+ fc = oc = c;
+ *buf++ = c;
+ if ((--l) == 0)
+ break;
+ } else {
+ code = c;
+ if (code >= s->slot) {
+ *sp++ = fc;
+ code = oc;
+ }
+ while (code >= s->newcodes) {
+ *sp++ = s->suffix[code];
+ code = s->prefix[code];
+ }
+ *sp++ = code;
+ if (s->slot < s->top_slot) {
+ s->suffix[s->slot] = fc = code;
+ s->prefix[s->slot++] = oc;
+ oc = c;
+ }
+ if (s->slot >= s->top_slot) {
+ if (s->cursize < MAXBITS) {
+ s->top_slot <<= 1;
+ s->curmask = mask[++s->cursize];
+ }
+ }
+ while (sp > s->stack) {
+ *buf++ = *(--sp);
+ if ((--l) == 0)
+ goto the_end;
+ }
+ }
+ }
+ the_end:
+ s->sp = sp;
+ s->oc = oc;
+ s->fc = fc;
+ return len - l;
+}
+
+static int gif_read_image(GifState *s)
+{
+ ByteIOContext *f = s->f;
+ int left, top, width, height, bits_per_pixel, code_size, flags;
+ int is_interleaved, has_local_palette, y, x, pass, y1, linesize, n, i;
+ uint8_t *ptr, *line, *d, *spal, *palette, *sptr, *ptr1;
+
+ left = get_le16(f);
+ top = get_le16(f);
+ width = get_le16(f);
+ height = get_le16(f);
+ flags = get_byte(f);
+ is_interleaved = flags & 0x40;
+ has_local_palette = flags & 0x80;
+ bits_per_pixel = (flags & 0x07) + 1;
+#ifdef DEBUG
+ printf("gif: image x=%d y=%d w=%d h=%d\n", left, top, width, height);
+#endif
+
+ if (has_local_palette) {
+ get_buffer(f, s->local_palette, 3 * (1 << bits_per_pixel));
+ palette = s->local_palette;
+ } else {
+ palette = s->global_palette;
+ bits_per_pixel = s->bits_per_pixel;
+ }
+
+ /* verify that all the image is inside the screen dimensions */
+ if (left + width > s->screen_width ||
+ top + height > s->screen_height)
+ return AVERROR(EINVAL);
+
+ /* build the palette */
+ if (s->pix_fmt == PIX_FMT_RGB24) {
+ line = av_malloc(width);
+ if (!line)
+ return AVERROR(ENOMEM);
+ } else {
+ n = (1 << bits_per_pixel);
+ spal = palette;
+ for(i = 0; i < n; i++) {
+ s->image_palette[i] = (0xff << 24) |
+ (spal[0] << 16) | (spal[1] << 8) | (spal[2]);
+ spal += 3;
+ }
+ for(; i < 256; i++)
+ s->image_palette[i] = (0xff << 24);
+ /* handle transparency */
+ if (s->transparent_color_index >= 0)
+ s->image_palette[s->transparent_color_index] = 0;
+ line = NULL;
+ }
+
+ /* now get the image data */
+ s->f = f;
+ code_size = get_byte(f);
+ GLZWDecodeInit(s, code_size);
+
+ /* read all the image */
+ linesize = s->image_linesize;
+ ptr1 = s->image_buf + top * linesize + (left * 3);
+ ptr = ptr1;
+ pass = 0;
+ y1 = 0;
+ for (y = 0; y < height; y++) {
+ if (s->pix_fmt == PIX_FMT_RGB24) {
+ /* transcode to RGB24 */
+ GLZWDecode(s, line, width);
+ d = ptr;
+ sptr = line;
+ for(x = 0; x < width; x++) {
+ spal = palette + sptr[0] * 3;
+ d[0] = spal[0];
+ d[1] = spal[1];
+ d[2] = spal[2];
+ d += 3;
+ sptr++;
+ }
+ } else {
+ GLZWDecode(s, ptr, width);
+ }
+ if (is_interleaved) {
+ switch(pass) {
+ default:
+ case 0:
+ case 1:
+ y1 += 8;
+ ptr += linesize * 8;
+ if (y1 >= height) {
+ y1 = 4;
+ if (pass == 0)
+ ptr = ptr1 + linesize * 4;
+ else
+ ptr = ptr1 + linesize * 2;
+ pass++;
+ }
+ break;
+ case 2:
+ y1 += 4;
+ ptr += linesize * 4;
+ if (y1 >= height) {
+ y1 = 1;
+ ptr = ptr1 + linesize;
+ pass++;
+ }
+ break;
+ case 3:
+ y1 += 2;
+ ptr += linesize * 2;
+ break;
+ }
+ } else {
+ ptr += linesize;
+ }
+ }
+ av_free(line);
+
+ /* read the garbage data until end marker is found */
+ while (!s->eob_reached)
+ GetCode(s);
+ return 0;
+}
+
+static int gif_read_extension(GifState *s)
+{
+ ByteIOContext *f = s->f;
+ int ext_code, ext_len, i, gce_flags, gce_transparent_index;
+
+ /* extension */
+ ext_code = get_byte(f);
+ ext_len = get_byte(f);
+#ifdef DEBUG
+ printf("gif: ext_code=0x%x len=%d\n", ext_code, ext_len);
+#endif
+ switch(ext_code) {
+ case 0xf9:
+ if (ext_len != 4)
+ goto discard_ext;
+ s->transparent_color_index = -1;
+ gce_flags = get_byte(f);
+ s->gce_delay = get_le16(f);
+ gce_transparent_index = get_byte(f);
+ if (gce_flags & 0x01)
+ s->transparent_color_index = gce_transparent_index;
+ else
+ s->transparent_color_index = -1;
+ s->gce_disposal = (gce_flags >> 2) & 0x7;
+#ifdef DEBUG
+ printf("gif: gce_flags=%x delay=%d tcolor=%d disposal=%d\n",
+ gce_flags, s->gce_delay,
+ s->transparent_color_index, s->gce_disposal);
+#endif
+ ext_len = get_byte(f);
+ break;
+ }
+
+ /* NOTE: many extension blocks can come after */
+ discard_ext:
+ while (ext_len != 0) {
+ for (i = 0; i < ext_len; i++)
+ get_byte(f);
+ ext_len = get_byte(f);
+#ifdef DEBUG
+ printf("gif: ext_len1=%d\n", ext_len);
+#endif
+ }
+ return 0;
+}
+
+static int gif_read_header1(GifState *s)
+{
+ ByteIOContext *f = s->f;
+ uint8_t sig[6];
+ int ret, v, n;
+ int has_global_palette;
+
+ /* read gif signature */
+ ret = get_buffer(f, sig, 6);
+ if (ret != 6)
+ return -1;
+ if (memcmp(sig, gif87a_sig, 6) != 0 &&
+ memcmp(sig, gif89a_sig, 6) != 0)
+ return -1;
+
+ /* read screen header */
+ s->transparent_color_index = -1;
+ s->screen_width = get_le16(f);
+ s->screen_height = get_le16(f);
+ if( (unsigned)s->screen_width > 32767
+ || (unsigned)s->screen_height > 32767){
+ av_log(NULL, AV_LOG_ERROR, "picture size too large\n");
+ return -1;
+ }
+
+ v = get_byte(f);
+ s->color_resolution = ((v & 0x70) >> 4) + 1;
+ has_global_palette = (v & 0x80);
+ s->bits_per_pixel = (v & 0x07) + 1;
+ s->background_color_index = get_byte(f);
+ get_byte(f); /* ignored */
+#ifdef DEBUG
+ printf("gif: screen_w=%d screen_h=%d bpp=%d global_palette=%d\n",
+ s->screen_width, s->screen_height, s->bits_per_pixel,
+ has_global_palette);
+#endif
+ if (has_global_palette) {
+ n = 1 << s->bits_per_pixel;
+ get_buffer(f, s->global_palette, n * 3);
+ }
+ return 0;
+}
+
+static int gif_parse_next_image(GifState *s)
+{
+ ByteIOContext *f = s->f;
+ int ret, code;
+
+ for (;;) {
+ code = url_fgetc(f);
+#ifdef DEBUG
+ printf("gif: code=%02x '%c'\n", code, code);
+#endif
+ switch (code) {
+ case ',':
+ if (gif_read_image(s) < 0)
+ return AVERROR_IO;
+ ret = 0;
+ goto the_end;
+ case ';':
+ /* end of image */
+ ret = AVERROR_IO;
+ goto the_end;
+ case '!':
+ if (gif_read_extension(s) < 0)
+ return AVERROR_IO;
+ break;
+ case EOF:
+ default:
+ /* error or errneous EOF */
+ ret = AVERROR_IO;
+ goto the_end;
+ }
+ }
+ the_end:
+ return ret;
+}
+
+static int gif_read_header(AVFormatContext * s1,
+ AVFormatParameters * ap)
+{
+ GifState *s = s1->priv_data;
+ ByteIOContext *f = &s1->pb;
+ AVStream *st;
+
+ s->f = f;
+ if (gif_read_header1(s) < 0)
+ return -1;
+
+ /* allocate image buffer */
+ s->image_linesize = s->screen_width * 3;
+ s->image_buf = av_malloc(s->screen_height * s->image_linesize);
+ if (!s->image_buf)
+ return AVERROR(ENOMEM);
+ s->pix_fmt = PIX_FMT_RGB24;
+ /* now we are ready: build format streams */
+ st = av_new_stream(s1, 0);
+ if (!st)
+ return -1;
+
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ st->codec->codec_id = CODEC_ID_RAWVIDEO;
+ st->codec->time_base.den = 5;
+ st->codec->time_base.num = 1;
+ /* XXX: check if screen size is always valid */
+ st->codec->width = s->screen_width;
+ st->codec->height = s->screen_height;
+ st->codec->pix_fmt = PIX_FMT_RGB24;
+ return 0;
+}
+
+static int gif_read_packet(AVFormatContext * s1,
+ AVPacket * pkt)
+{
+ GifState *s = s1->priv_data;
+ int ret;
+
+ ret = gif_parse_next_image(s);
+ if (ret < 0)
+ return ret;
+
+ /* XXX: avoid copying */
+ if (av_new_packet(pkt, s->screen_width * s->screen_height * 3)) {
+ return AVERROR_IO;
+ }
+ pkt->stream_index = 0;
+ memcpy(pkt->data, s->image_buf, s->screen_width * s->screen_height * 3);
+ return 0;
+}
+
+static int gif_read_close(AVFormatContext *s1)
+{
+ GifState *s = s1->priv_data;
+ av_free(s->image_buf);
+ return 0;
+}
+
+AVInputFormat gif_demuxer =
+{
+ "gif",
+ "gif format",
+ sizeof(GifState),
+ gif_video_probe,
+ gif_read_header,
+ gif_read_packet,
+ gif_read_close,
+};
diff --git a/contrib/ffmpeg/libavformat/grab.c b/contrib/ffmpeg/libavformat/grab.c
new file mode 100644
index 000000000..5e778ecc0
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/grab.c
@@ -0,0 +1,860 @@
+/*
+ * Linux video grab interface
+ * Copyright (c) 2000,2001 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 "avformat.h"
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/time.h>
+#define _LINUX_TIME_H 1
+#include <linux/videodev.h>
+#include <time.h>
+
+typedef struct {
+ int fd;
+ int frame_format; /* see VIDEO_PALETTE_xxx */
+ int use_mmap;
+ int width, height;
+ int frame_rate;
+ int frame_rate_base;
+ int64_t time_frame;
+ int frame_size;
+ struct video_capability video_cap;
+ struct video_audio audio_saved;
+ uint8_t *video_buf;
+ struct video_mbuf gb_buffers;
+ struct video_mmap gb_buf;
+ int gb_frame;
+
+ /* ATI All In Wonder specific stuff */
+ /* XXX: remove and merge in libavcodec/imgconvert.c */
+ int aiw_enabled;
+ int deint;
+ int halfw;
+ uint8_t *src_mem;
+ uint8_t *lum_m4_mem;
+} VideoData;
+
+static int aiw_init(VideoData *s);
+static int aiw_read_picture(VideoData *s, uint8_t *data);
+static int aiw_close(VideoData *s);
+
+static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
+{
+ VideoData *s = s1->priv_data;
+ AVStream *st;
+ int width, height;
+ int video_fd, frame_size;
+ int ret, frame_rate, frame_rate_base;
+ int desired_palette, desired_depth;
+ struct video_tuner tuner;
+ struct video_audio audio;
+ struct video_picture pict;
+ int j;
+
+ if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) {
+ av_log(s1, AV_LOG_ERROR, "Bad capture size (%dx%d) or wrong time base (%d)\n",
+ ap->width, ap->height, ap->time_base.den);
+
+ return -1;
+ }
+
+ width = ap->width;
+ height = ap->height;
+ frame_rate = ap->time_base.den;
+ frame_rate_base = ap->time_base.num;
+
+ if((unsigned)width > 32767 || (unsigned)height > 32767) {
+ av_log(s1, AV_LOG_ERROR, "Capture size is out of range: %dx%d\n",
+ width, height);
+
+ return -1;
+ }
+
+ st = av_new_stream(s1, 0);
+ if (!st)
+ return AVERROR(ENOMEM);
+ av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
+
+ s->width = width;
+ s->height = height;
+ s->frame_rate = frame_rate;
+ s->frame_rate_base = frame_rate_base;
+
+ video_fd = open(s1->filename, O_RDWR);
+ if (video_fd < 0) {
+ perror(s1->filename);
+ goto fail;
+ }
+
+ if (ioctl(video_fd,VIDIOCGCAP, &s->video_cap) < 0) {
+ perror("VIDIOCGCAP");
+ goto fail;
+ }
+
+ if (!(s->video_cap.type & VID_TYPE_CAPTURE)) {
+ av_log(s1, AV_LOG_ERROR, "Fatal: grab device does not handle capture\n");
+ goto fail;
+ }
+
+ desired_palette = -1;
+ desired_depth = -1;
+ if (ap->pix_fmt == PIX_FMT_YUV420P) {
+ desired_palette = VIDEO_PALETTE_YUV420P;
+ desired_depth = 12;
+ } else if (ap->pix_fmt == PIX_FMT_YUYV422) {
+ desired_palette = VIDEO_PALETTE_YUV422;
+ desired_depth = 16;
+ } else if (ap->pix_fmt == PIX_FMT_BGR24) {
+ desired_palette = VIDEO_PALETTE_RGB24;
+ desired_depth = 24;
+ }
+
+ /* set tv standard */
+ if (ap->standard && !ioctl(video_fd, VIDIOCGTUNER, &tuner)) {
+ if (!strcasecmp(ap->standard, "pal"))
+ tuner.mode = VIDEO_MODE_PAL;
+ else if (!strcasecmp(ap->standard, "secam"))
+ tuner.mode = VIDEO_MODE_SECAM;
+ else
+ tuner.mode = VIDEO_MODE_NTSC;
+ ioctl(video_fd, VIDIOCSTUNER, &tuner);
+ }
+
+ /* unmute audio */
+ audio.audio = 0;
+ ioctl(video_fd, VIDIOCGAUDIO, &audio);
+ memcpy(&s->audio_saved, &audio, sizeof(audio));
+ audio.flags &= ~VIDEO_AUDIO_MUTE;
+ ioctl(video_fd, VIDIOCSAUDIO, &audio);
+
+ ioctl(video_fd, VIDIOCGPICT, &pict);
+#if 0
+ printf("v4l: colour=%d hue=%d brightness=%d constrast=%d whiteness=%d\n",
+ pict.colour,
+ pict.hue,
+ pict.brightness,
+ pict.contrast,
+ pict.whiteness);
+#endif
+ /* try to choose a suitable video format */
+ pict.palette = desired_palette;
+ pict.depth= desired_depth;
+ if (desired_palette == -1 || (ret = ioctl(video_fd, VIDIOCSPICT, &pict)) < 0) {
+ pict.palette=VIDEO_PALETTE_YUV420P;
+ pict.depth=12;
+ ret = ioctl(video_fd, VIDIOCSPICT, &pict);
+ if (ret < 0) {
+ pict.palette=VIDEO_PALETTE_YUV422;
+ pict.depth=16;
+ ret = ioctl(video_fd, VIDIOCSPICT, &pict);
+ if (ret < 0) {
+ pict.palette=VIDEO_PALETTE_RGB24;
+ pict.depth=24;
+ ret = ioctl(video_fd, VIDIOCSPICT, &pict);
+ if (ret < 0) {
+ pict.palette=VIDEO_PALETTE_GREY;
+ pict.depth=8;
+ ret = ioctl(video_fd, VIDIOCSPICT, &pict);
+ if (ret < 0)
+ goto fail1;
+ }
+ }
+ }
+ }
+
+ ret = ioctl(video_fd,VIDIOCGMBUF,&s->gb_buffers);
+ if (ret < 0) {
+ /* try to use read based access */
+ struct video_window win;
+ int val;
+
+ win.x = 0;
+ win.y = 0;
+ win.width = width;
+ win.height = height;
+ win.chromakey = -1;
+ win.flags = 0;
+
+ ioctl(video_fd, VIDIOCSWIN, &win);
+
+ s->frame_format = pict.palette;
+
+ val = 1;
+ ioctl(video_fd, VIDIOCCAPTURE, &val);
+
+ s->time_frame = av_gettime() * s->frame_rate / s->frame_rate_base;
+ s->use_mmap = 0;
+
+ /* ATI All In Wonder automatic activation */
+ if (!strcmp(s->video_cap.name, "Km")) {
+ if (aiw_init(s) < 0)
+ goto fail;
+ s->aiw_enabled = 1;
+ /* force 420P format because convertion from YUV422 to YUV420P
+ is done in this driver (ugly) */
+ s->frame_format = VIDEO_PALETTE_YUV420P;
+ }
+ } else {
+ s->video_buf = mmap(0,s->gb_buffers.size,PROT_READ|PROT_WRITE,MAP_SHARED,video_fd,0);
+ if ((unsigned char*)-1 == s->video_buf) {
+ s->video_buf = mmap(0,s->gb_buffers.size,PROT_READ|PROT_WRITE,MAP_PRIVATE,video_fd,0);
+ if ((unsigned char*)-1 == s->video_buf) {
+ perror("mmap");
+ goto fail;
+ }
+ }
+ s->gb_frame = 0;
+ s->time_frame = av_gettime() * s->frame_rate / s->frame_rate_base;
+
+ /* start to grab the first frame */
+ s->gb_buf.frame = s->gb_frame % s->gb_buffers.frames;
+ s->gb_buf.height = height;
+ s->gb_buf.width = width;
+ s->gb_buf.format = pict.palette;
+
+ ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
+ if (ret < 0) {
+ if (errno != EAGAIN) {
+ fail1:
+ av_log(s1, AV_LOG_ERROR, "Fatal: grab device does not support suitable format\n");
+ } else {
+ av_log(s1, AV_LOG_ERROR,"Fatal: grab device does not receive any video signal\n");
+ }
+ goto fail;
+ }
+ for (j = 1; j < s->gb_buffers.frames; j++) {
+ s->gb_buf.frame = j;
+ ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
+ }
+ s->frame_format = s->gb_buf.format;
+ s->use_mmap = 1;
+ }
+
+ switch(s->frame_format) {
+ case VIDEO_PALETTE_YUV420P:
+ frame_size = (width * height * 3) / 2;
+ st->codec->pix_fmt = PIX_FMT_YUV420P;
+ break;
+ case VIDEO_PALETTE_YUV422:
+ frame_size = width * height * 2;
+ st->codec->pix_fmt = PIX_FMT_YUYV422;
+ break;
+ case VIDEO_PALETTE_RGB24:
+ frame_size = width * height * 3;
+ st->codec->pix_fmt = PIX_FMT_BGR24; /* NOTE: v4l uses BGR24, not RGB24 ! */
+ break;
+ case VIDEO_PALETTE_GREY:
+ frame_size = width * height * 1;
+ st->codec->pix_fmt = PIX_FMT_GRAY8;
+ break;
+ default:
+ goto fail;
+ }
+ s->fd = video_fd;
+ s->frame_size = frame_size;
+
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ st->codec->codec_id = CODEC_ID_RAWVIDEO;
+ st->codec->width = width;
+ st->codec->height = height;
+ st->codec->time_base.den = frame_rate;
+ st->codec->time_base.num = frame_rate_base;
+ st->codec->bit_rate = frame_size * 1/av_q2d(st->codec->time_base) * 8;
+
+ return 0;
+ fail:
+ if (video_fd >= 0)
+ close(video_fd);
+ av_free(st);
+ return AVERROR_IO;
+}
+
+static int v4l_mm_read_picture(VideoData *s, uint8_t *buf)
+{
+ uint8_t *ptr;
+
+ while (ioctl(s->fd, VIDIOCSYNC, &s->gb_frame) < 0 &&
+ (errno == EAGAIN || errno == EINTR));
+
+ ptr = s->video_buf + s->gb_buffers.offsets[s->gb_frame];
+ memcpy(buf, ptr, s->frame_size);
+
+ /* Setup to capture the next frame */
+ s->gb_buf.frame = s->gb_frame;
+ if (ioctl(s->fd, VIDIOCMCAPTURE, &s->gb_buf) < 0) {
+ if (errno == EAGAIN)
+ av_log(NULL, AV_LOG_ERROR, "Cannot Sync\n");
+ else
+ perror("VIDIOCMCAPTURE");
+ return AVERROR_IO;
+ }
+
+ /* This is now the grabbing frame */
+ s->gb_frame = (s->gb_frame + 1) % s->gb_buffers.frames;
+
+ return s->frame_size;
+}
+
+static int grab_read_packet(AVFormatContext *s1, AVPacket *pkt)
+{
+ VideoData *s = s1->priv_data;
+ int64_t curtime, delay;
+ struct timespec ts;
+
+ /* Calculate the time of the next frame */
+ s->time_frame += INT64_C(1000000);
+
+ /* wait based on the frame rate */
+ for(;;) {
+ curtime = av_gettime();
+ delay = s->time_frame * s->frame_rate_base / s->frame_rate - curtime;
+ if (delay <= 0) {
+ if (delay < INT64_C(-1000000) * s->frame_rate_base / s->frame_rate) {
+ /* printf("grabbing is %d frames late (dropping)\n", (int) -(delay / 16666)); */
+ s->time_frame += INT64_C(1000000);
+ }
+ break;
+ }
+ ts.tv_sec = delay / 1000000;
+ ts.tv_nsec = (delay % 1000000) * 1000;
+ nanosleep(&ts, NULL);
+ }
+
+ if (av_new_packet(pkt, s->frame_size) < 0)
+ return AVERROR_IO;
+
+ pkt->pts = curtime;
+
+ /* read one frame */
+ if (s->aiw_enabled) {
+ return aiw_read_picture(s, pkt->data);
+ } else if (s->use_mmap) {
+ return v4l_mm_read_picture(s, pkt->data);
+ } else {
+ if (read(s->fd, pkt->data, pkt->size) != pkt->size)
+ return AVERROR_IO;
+ return s->frame_size;
+ }
+}
+
+static int grab_read_close(AVFormatContext *s1)
+{
+ VideoData *s = s1->priv_data;
+
+ if (s->aiw_enabled)
+ aiw_close(s);
+
+ if (s->use_mmap)
+ munmap(s->video_buf, s->gb_buffers.size);
+
+ /* mute audio. we must force it because the BTTV driver does not
+ return its state correctly */
+ s->audio_saved.flags |= VIDEO_AUDIO_MUTE;
+ ioctl(s->fd, VIDIOCSAUDIO, &s->audio_saved);
+
+ close(s->fd);
+ return 0;
+}
+
+AVInputFormat video_grab_device_demuxer = {
+ "video4linux",
+ "video grab",
+ sizeof(VideoData),
+ NULL,
+ grab_read_header,
+ grab_read_packet,
+ grab_read_close,
+ .flags = AVFMT_NOFILE,
+};
+
+/* All in Wonder specific stuff */
+/* XXX: remove and merge in libavcodec/imgconvert.c */
+
+static int aiw_init(VideoData *s)
+{
+ int width, height;
+
+ width = s->width;
+ height = s->height;
+
+ if ((width == s->video_cap.maxwidth && height == s->video_cap.maxheight) ||
+ (width == s->video_cap.maxwidth && height == s->video_cap.maxheight*2) ||
+ (width == s->video_cap.maxwidth/2 && height == s->video_cap.maxheight)) {
+
+ s->deint=0;
+ s->halfw=0;
+ if (height == s->video_cap.maxheight*2) s->deint=1;
+ if (width == s->video_cap.maxwidth/2) s->halfw=1;
+ } else {
+ av_log(NULL, AV_LOG_ERROR, "\nIncorrect Grab Size Supplied - Supported Sizes Are:\n");
+ av_log(NULL, AV_LOG_ERROR, " %dx%d %dx%d %dx%d\n\n",
+ s->video_cap.maxwidth,s->video_cap.maxheight,
+ s->video_cap.maxwidth,s->video_cap.maxheight*2,
+ s->video_cap.maxwidth/2,s->video_cap.maxheight);
+ goto fail;
+ }
+
+ if (s->halfw == 0) {
+ s->src_mem = av_malloc(s->width*2);
+ } else {
+ s->src_mem = av_malloc(s->width*4);
+ }
+ if (!s->src_mem) goto fail;
+
+ s->lum_m4_mem = av_malloc(s->width);
+ if (!s->lum_m4_mem)
+ goto fail;
+ return 0;
+ fail:
+ av_freep(&s->src_mem);
+ av_freep(&s->lum_m4_mem);
+ return -1;
+}
+
+#ifdef HAVE_MMX
+#include "libavcodec/i386/mmx.h"
+
+#define LINE_WITH_UV \
+ movq_m2r(ptr[0],mm0); \
+ movq_m2r(ptr[8],mm1); \
+ movq_r2r(mm0, mm4); \
+ punpcklbw_r2r(mm1,mm0); \
+ punpckhbw_r2r(mm1,mm4); \
+ movq_r2r(mm0,mm5); \
+ punpcklbw_r2r(mm4,mm0); \
+ punpckhbw_r2r(mm4,mm5); \
+ movq_r2r(mm0,mm1); \
+ punpcklbw_r2r(mm5,mm1); \
+ movq_r2m(mm1,lum[0]); \
+ movq_m2r(ptr[16],mm2); \
+ movq_m2r(ptr[24],mm1); \
+ movq_r2r(mm2,mm4); \
+ punpcklbw_r2r(mm1,mm2); \
+ punpckhbw_r2r(mm1,mm4); \
+ movq_r2r(mm2,mm3); \
+ punpcklbw_r2r(mm4,mm2); \
+ punpckhbw_r2r(mm4,mm3); \
+ movq_r2r(mm2,mm1); \
+ punpcklbw_r2r(mm3,mm1); \
+ movq_r2m(mm1,lum[8]); \
+ punpckhdq_r2r(mm2,mm0); \
+ punpckhdq_r2r(mm3,mm5); \
+ movq_r2m(mm0,cb[0]); \
+ movq_r2m(mm5,cr[0]);
+
+#define LINE_NO_UV \
+ movq_m2r(ptr[0],mm0);\
+ movq_m2r(ptr[8],mm1);\
+ movq_r2r(mm0, mm4);\
+ punpcklbw_r2r(mm1,mm0); \
+ punpckhbw_r2r(mm1,mm4);\
+ movq_r2r(mm0,mm5);\
+ punpcklbw_r2r(mm4,mm0);\
+ punpckhbw_r2r(mm4,mm5);\
+ movq_r2r(mm0,mm1);\
+ punpcklbw_r2r(mm5,mm1);\
+ movq_r2m(mm1,lum[0]);\
+ movq_m2r(ptr[16],mm2);\
+ movq_m2r(ptr[24],mm1);\
+ movq_r2r(mm2,mm4);\
+ punpcklbw_r2r(mm1,mm2);\
+ punpckhbw_r2r(mm1,mm4);\
+ movq_r2r(mm2,mm3);\
+ punpcklbw_r2r(mm4,mm2);\
+ punpckhbw_r2r(mm4,mm3);\
+ movq_r2r(mm2,mm1);\
+ punpcklbw_r2r(mm3,mm1);\
+ movq_r2m(mm1,lum[8]);
+
+#define LINE_WITHUV_AVG \
+ movq_m2r(ptr[0], mm0);\
+ movq_m2r(ptr[8], mm1);\
+ movq_r2r(mm0, mm4);\
+ punpcklbw_r2r(mm1,mm0);\
+ punpckhbw_r2r(mm1,mm4);\
+ movq_r2r(mm0,mm5);\
+ punpcklbw_r2r(mm4,mm0);\
+ punpckhbw_r2r(mm4,mm5);\
+ movq_r2r(mm0,mm1);\
+ movq_r2r(mm5,mm2);\
+ punpcklbw_r2r(mm7,mm1);\
+ punpcklbw_r2r(mm7,mm2);\
+ paddw_r2r(mm6,mm1);\
+ paddw_r2r(mm2,mm1);\
+ psraw_i2r(1,mm1);\
+ packuswb_r2r(mm7,mm1);\
+ movd_r2m(mm1,lum[0]);\
+ movq_m2r(ptr[16],mm2);\
+ movq_m2r(ptr[24],mm1);\
+ movq_r2r(mm2,mm4);\
+ punpcklbw_r2r(mm1,mm2);\
+ punpckhbw_r2r(mm1,mm4);\
+ movq_r2r(mm2,mm3);\
+ punpcklbw_r2r(mm4,mm2);\
+ punpckhbw_r2r(mm4,mm3);\
+ movq_r2r(mm2,mm1);\
+ movq_r2r(mm3,mm4);\
+ punpcklbw_r2r(mm7,mm1);\
+ punpcklbw_r2r(mm7,mm4);\
+ paddw_r2r(mm6,mm1);\
+ paddw_r2r(mm4,mm1);\
+ psraw_i2r(1,mm1);\
+ packuswb_r2r(mm7,mm1);\
+ movd_r2m(mm1,lum[4]);\
+ punpckhbw_r2r(mm7,mm0);\
+ punpckhbw_r2r(mm7,mm2);\
+ paddw_r2r(mm6,mm0);\
+ paddw_r2r(mm2,mm0);\
+ psraw_i2r(1,mm0);\
+ packuswb_r2r(mm7,mm0);\
+ punpckhbw_r2r(mm7,mm5);\
+ punpckhbw_r2r(mm7,mm3);\
+ paddw_r2r(mm6,mm5);\
+ paddw_r2r(mm3,mm5);\
+ psraw_i2r(1,mm5);\
+ packuswb_r2r(mm7,mm5);\
+ movd_r2m(mm0,cb[0]);\
+ movd_r2m(mm5,cr[0]);
+
+#define LINE_NOUV_AVG \
+ movq_m2r(ptr[0],mm0);\
+ movq_m2r(ptr[8],mm1);\
+ pand_r2r(mm5,mm0);\
+ pand_r2r(mm5,mm1);\
+ pmaddwd_r2r(mm6,mm0);\
+ pmaddwd_r2r(mm6,mm1);\
+ packssdw_r2r(mm1,mm0);\
+ paddw_r2r(mm6,mm0);\
+ psraw_i2r(1,mm0);\
+ movq_m2r(ptr[16],mm2);\
+ movq_m2r(ptr[24],mm3);\
+ pand_r2r(mm5,mm2);\
+ pand_r2r(mm5,mm3);\
+ pmaddwd_r2r(mm6,mm2);\
+ pmaddwd_r2r(mm6,mm3);\
+ packssdw_r2r(mm3,mm2);\
+ paddw_r2r(mm6,mm2);\
+ psraw_i2r(1,mm2);\
+ packuswb_r2r(mm2,mm0);\
+ movq_r2m(mm0,lum[0]);
+
+#define DEINT_LINE_LUM(ptroff) \
+ movd_m2r(lum_m4[(ptroff)],mm0);\
+ movd_m2r(lum_m3[(ptroff)],mm1);\
+ movd_m2r(lum_m2[(ptroff)],mm2);\
+ movd_m2r(lum_m1[(ptroff)],mm3);\
+ movd_m2r(lum[(ptroff)],mm4);\
+ punpcklbw_r2r(mm7,mm0);\
+ movd_r2m(mm2,lum_m4[(ptroff)]);\
+ punpcklbw_r2r(mm7,mm1);\
+ punpcklbw_r2r(mm7,mm2);\
+ punpcklbw_r2r(mm7,mm3);\
+ punpcklbw_r2r(mm7,mm4);\
+ psllw_i2r(2,mm1);\
+ psllw_i2r(1,mm2);\
+ paddw_r2r(mm6,mm1);\
+ psllw_i2r(2,mm3);\
+ paddw_r2r(mm2,mm1);\
+ paddw_r2r(mm4,mm0);\
+ paddw_r2r(mm3,mm1);\
+ psubusw_r2r(mm0,mm1);\
+ psrlw_i2r(3,mm1);\
+ packuswb_r2r(mm7,mm1);\
+ movd_r2m(mm1,lum_m2[(ptroff)]);
+
+#else
+#include "libavcodec/dsputil.h"
+
+#define LINE_WITH_UV \
+ lum[0]=ptr[0];lum[1]=ptr[2];lum[2]=ptr[4];lum[3]=ptr[6];\
+ cb[0]=ptr[1];cb[1]=ptr[5];\
+ cr[0]=ptr[3];cr[1]=ptr[7];\
+ lum[4]=ptr[8];lum[5]=ptr[10];lum[6]=ptr[12];lum[7]=ptr[14];\
+ cb[2]=ptr[9];cb[3]=ptr[13];\
+ cr[2]=ptr[11];cr[3]=ptr[15];\
+ lum[8]=ptr[16];lum[9]=ptr[18];lum[10]=ptr[20];lum[11]=ptr[22];\
+ cb[4]=ptr[17];cb[5]=ptr[21];\
+ cr[4]=ptr[19];cr[5]=ptr[23];\
+ lum[12]=ptr[24];lum[13]=ptr[26];lum[14]=ptr[28];lum[15]=ptr[30];\
+ cb[6]=ptr[25];cb[7]=ptr[29];\
+ cr[6]=ptr[27];cr[7]=ptr[31];
+
+#define LINE_NO_UV \
+ lum[0]=ptr[0];lum[1]=ptr[2];lum[2]=ptr[4];lum[3]=ptr[6];\
+ lum[4]=ptr[8];lum[5]=ptr[10];lum[6]=ptr[12];lum[7]=ptr[14];\
+ lum[8]=ptr[16];lum[9]=ptr[18];lum[10]=ptr[20];lum[11]=ptr[22];\
+ lum[12]=ptr[24];lum[13]=ptr[26];lum[14]=ptr[28];lum[15]=ptr[30];
+
+#define LINE_WITHUV_AVG \
+ sum=(ptr[0]+ptr[2]+1) >> 1;lum[0]=sum; \
+ sum=(ptr[4]+ptr[6]+1) >> 1;lum[1]=sum; \
+ sum=(ptr[1]+ptr[5]+1) >> 1;cb[0]=sum; \
+ sum=(ptr[3]+ptr[7]+1) >> 1;cr[0]=sum; \
+ sum=(ptr[8]+ptr[10]+1) >> 1;lum[2]=sum; \
+ sum=(ptr[12]+ptr[14]+1) >> 1;lum[3]=sum; \
+ sum=(ptr[9]+ptr[13]+1) >> 1;cb[1]=sum; \
+ sum=(ptr[11]+ptr[15]+1) >> 1;cr[1]=sum; \
+ sum=(ptr[16]+ptr[18]+1) >> 1;lum[4]=sum; \
+ sum=(ptr[20]+ptr[22]+1) >> 1;lum[5]=sum; \
+ sum=(ptr[17]+ptr[21]+1) >> 1;cb[2]=sum; \
+ sum=(ptr[19]+ptr[23]+1) >> 1;cr[2]=sum; \
+ sum=(ptr[24]+ptr[26]+1) >> 1;lum[6]=sum; \
+ sum=(ptr[28]+ptr[30]+1) >> 1;lum[7]=sum; \
+ sum=(ptr[25]+ptr[29]+1) >> 1;cb[3]=sum; \
+ sum=(ptr[27]+ptr[31]+1) >> 1;cr[3]=sum;
+
+#define LINE_NOUV_AVG \
+ sum=(ptr[0]+ptr[2]+1) >> 1;lum[0]=sum; \
+ sum=(ptr[4]+ptr[6]+1) >> 1;lum[1]=sum; \
+ sum=(ptr[8]+ptr[10]+1) >> 1;lum[2]=sum; \
+ sum=(ptr[12]+ptr[14]+1) >> 1;lum[3]=sum; \
+ sum=(ptr[16]+ptr[18]+1) >> 1;lum[4]=sum; \
+ sum=(ptr[20]+ptr[22]+1) >> 1;lum[5]=sum; \
+ sum=(ptr[24]+ptr[26]+1) >> 1;lum[6]=sum; \
+ sum=(ptr[28]+ptr[30]+1) >> 1;lum[7]=sum;
+
+#define DEINT_LINE_LUM(ptroff) \
+ sum=(-lum_m4[(ptroff)]+(lum_m3[(ptroff)]<<2)+(lum_m2[(ptroff)]<<1)+(lum_m1[(ptroff)]<<2)-lum[(ptroff)]); \
+ lum_m4[(ptroff)]=lum_m2[(ptroff)];\
+ lum_m2[(ptroff)]=cm[(sum+4)>>3];\
+ sum=(-lum_m4[(ptroff)+1]+(lum_m3[(ptroff)+1]<<2)+(lum_m2[(ptroff)+1]<<1)+(lum_m1[(ptroff)+1]<<2)-lum[(ptroff)+1]); \
+ lum_m4[(ptroff)+1]=lum_m2[(ptroff)+1];\
+ lum_m2[(ptroff)+1]=cm[(sum+4)>>3];\
+ sum=(-lum_m4[(ptroff)+2]+(lum_m3[(ptroff)+2]<<2)+(lum_m2[(ptroff)+2]<<1)+(lum_m1[(ptroff)+2]<<2)-lum[(ptroff)+2]); \
+ lum_m4[(ptroff)+2]=lum_m2[(ptroff)+2];\
+ lum_m2[(ptroff)+2]=cm[(sum+4)>>3];\
+ sum=(-lum_m4[(ptroff)+3]+(lum_m3[(ptroff)+3]<<2)+(lum_m2[(ptroff)+3]<<1)+(lum_m1[(ptroff)+3]<<2)-lum[(ptroff)+3]); \
+ lum_m4[(ptroff)+3]=lum_m2[(ptroff)+3];\
+ lum_m2[(ptroff)+3]=cm[(sum+4)>>3];
+
+#endif
+
+
+/* Read two fields separately. */
+static int aiw_read_picture(VideoData *s, uint8_t *data)
+{
+ uint8_t *ptr, *lum, *cb, *cr;
+ int h;
+#ifndef HAVE_MMX
+ int sum;
+#endif
+ uint8_t* src = s->src_mem;
+ uint8_t *ptrend = &src[s->width*2];
+ lum=data;
+ cb=&lum[s->width*s->height];
+ cr=&cb[(s->width*s->height)/4];
+ if (s->deint == 0 && s->halfw == 0) {
+ while (read(s->fd,src,s->width*2) < 0) {
+ usleep(100);
+ }
+ for (h = 0; h < s->height-2; h+=2) {
+ for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
+ LINE_WITH_UV
+ }
+ read(s->fd,src,s->width*2);
+ for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16) {
+ LINE_NO_UV
+ }
+ read(s->fd,src,s->width*2);
+ }
+ /*
+ * Do last two lines
+ */
+ for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
+ LINE_WITH_UV
+ }
+ read(s->fd,src,s->width*2);
+ for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16) {
+ LINE_NO_UV
+ }
+ /* drop second field */
+ while (read(s->fd,src,s->width*2) < 0) {
+ usleep(100);
+ }
+ for (h = 0; h < s->height - 1; h++) {
+ read(s->fd,src,s->width*2);
+ }
+ } else if (s->halfw == 1) {
+#ifdef HAVE_MMX
+ mmx_t rounder;
+ mmx_t masker;
+ rounder.uw[0]=1;
+ rounder.uw[1]=1;
+ rounder.uw[2]=1;
+ rounder.uw[3]=1;
+ masker.ub[0]=0xff;
+ masker.ub[1]=0;
+ masker.ub[2]=0xff;
+ masker.ub[3]=0;
+ masker.ub[4]=0xff;
+ masker.ub[5]=0;
+ masker.ub[6]=0xff;
+ masker.ub[7]=0;
+ pxor_r2r(mm7,mm7);
+ movq_m2r(rounder,mm6);
+#endif
+ while (read(s->fd,src,s->width*4) < 0) {
+ usleep(100);
+ }
+ ptrend = &src[s->width*4];
+ for (h = 0; h < s->height-2; h+=2) {
+ for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8, cb+=4, cr+=4) {
+ LINE_WITHUV_AVG
+ }
+ read(s->fd,src,s->width*4);
+#ifdef HAVE_MMX
+ movq_m2r(masker,mm5);
+#endif
+ for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8) {
+ LINE_NOUV_AVG
+ }
+ read(s->fd,src,s->width*4);
+ }
+ /*
+ * Do last two lines
+ */
+ for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8, cb+=4, cr+=4) {
+ LINE_WITHUV_AVG
+ }
+ read(s->fd,src,s->width*4);
+#ifdef HAVE_MMX
+ movq_m2r(masker,mm5);
+#endif
+ for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8) {
+ LINE_NOUV_AVG
+ }
+ /* drop second field */
+ while (read(s->fd,src,s->width*4) < 0) {
+ usleep(100);
+ }
+ for (h = 0; h < s->height - 1; h++) {
+ read(s->fd,src,s->width*4);
+ }
+ } else {
+ uint8_t *lum_m1, *lum_m2, *lum_m3, *lum_m4;
+#ifdef HAVE_MMX
+ mmx_t rounder;
+ rounder.uw[0]=4;
+ rounder.uw[1]=4;
+ rounder.uw[2]=4;
+ rounder.uw[3]=4;
+ movq_m2r(rounder,mm6);
+ pxor_r2r(mm7,mm7);
+#else
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+#endif
+
+ /* read two fields and deinterlace them */
+ while (read(s->fd,src,s->width*2) < 0) {
+ usleep(100);
+ }
+ for (h = 0; h < (s->height/2)-2; h+=2) {
+ for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
+ LINE_WITH_UV
+ }
+ read(s->fd,src,s->width*2);
+ /* skip a luminance line - will be filled in later */
+ lum += s->width;
+ for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
+ LINE_WITH_UV
+ }
+ /* skip a luminance line - will be filled in later */
+ lum += s->width;
+ read(s->fd,src,s->width*2);
+ }
+ /*
+ * Do last two lines
+ */
+ for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
+ LINE_WITH_UV
+ }
+ /* skip a luminance line - will be filled in later */
+ lum += s->width;
+ read(s->fd,src,s->width*2);
+ for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
+ LINE_WITH_UV
+ }
+ /*
+ *
+ * SECOND FIELD
+ *
+ */
+ lum=&data[s->width];
+ while (read(s->fd,src,s->width*2) < 0) {
+ usleep(10);
+ }
+ /* First (and last) two lines not interlaced */
+ for (h = 0; h < 2; h++) {
+ for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16) {
+ LINE_NO_UV
+ }
+ read(s->fd,src,s->width*2);
+ /* skip a luminance line */
+ lum += s->width;
+ }
+ lum_m1=&lum[-s->width];
+ lum_m2=&lum_m1[-s->width];
+ lum_m3=&lum_m2[-s->width];
+ memmove(s->lum_m4_mem,&lum_m3[-s->width],s->width);
+ for (; h < (s->height/2)-1; h++) {
+ lum_m4=s->lum_m4_mem;
+ for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16,lum_m1+=16,lum_m2+=16,lum_m3+=16,lum_m4+=16) {
+ LINE_NO_UV
+
+ DEINT_LINE_LUM(0)
+ DEINT_LINE_LUM(4)
+ DEINT_LINE_LUM(8)
+ DEINT_LINE_LUM(12)
+ }
+ read(s->fd,src,s->width*2);
+ /* skip a luminance line */
+ lum += s->width;
+ lum_m1 += s->width;
+ lum_m2 += s->width;
+ lum_m3 += s->width;
+ // lum_m4 += s->width;
+ }
+ /*
+ * Do last line
+ */
+ lum_m4=s->lum_m4_mem;
+ for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, lum_m1+=16, lum_m2+=16, lum_m3+=16, lum_m4+=16) {
+ LINE_NO_UV
+
+ DEINT_LINE_LUM(0)
+ DEINT_LINE_LUM(4)
+ DEINT_LINE_LUM(8)
+ DEINT_LINE_LUM(12)
+ }
+ }
+#ifdef HAVE_MMX
+ emms();
+#endif
+ return s->frame_size;
+}
+
+static int aiw_close(VideoData *s)
+{
+ av_freep(&s->lum_m4_mem);
+ av_freep(&s->src_mem);
+ return 0;
+}
diff --git a/contrib/ffmpeg/libavformat/grab_bktr.c b/contrib/ffmpeg/libavformat/grab_bktr.c
new file mode 100644
index 000000000..100653db7
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/grab_bktr.c
@@ -0,0 +1,320 @@
+/*
+ * *BSD video grab interface
+ * Copyright (c) 2002 Steve O'Hara-Smith
+ * based on
+ * Linux video grab interface
+ * Copyright (c) 2000,2001 Gerard Lantau.
+ * and
+ * simple_grab.c Copyright (c) 1999 Roger Hardiman
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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"
+#if defined (HAVE_DEV_BKTR_IOCTL_METEOR_H) && defined (HAVE_DEV_BKTR_IOCTL_BT848_H)
+# include <dev/bktr/ioctl_meteor.h>
+# include <dev/bktr/ioctl_bt848.h>
+#elif defined (HAVE_MACHINE_IOCTL_METEOR_H) && defined (HAVE_MACHINE_IOCTL_BT848_H)
+# include <machine/ioctl_meteor.h>
+# include <machine/ioctl_bt848.h>
+#elif defined (HAVE_DEV_VIDEO_METEOR_IOCTL_METEOR_H) && defined (HAVE_DEV_VIDEO_METEOR_IOCTL_BT848_H)
+# include <dev/video/meteor/ioctl_meteor.h>
+# include <dev/video/bktr/ioctl_bt848.h>
+#elif HAVE_DEV_IC_BT8XX_H
+# include <dev/ic/bt8xx.h>
+#endif
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/time.h>
+#include <signal.h>
+
+typedef struct {
+ int video_fd;
+ int tuner_fd;
+ int width, height;
+ int frame_rate;
+ int frame_rate_base;
+ u_int64_t per_frame;
+} VideoData;
+
+
+#define PAL 1
+#define PALBDGHI 1
+#define NTSC 2
+#define NTSCM 2
+#define SECAM 3
+#define PALN 4
+#define PALM 5
+#define NTSCJ 6
+
+/* PAL is 768 x 576. NTSC is 640 x 480 */
+#define PAL_HEIGHT 576
+#define SECAM_HEIGHT 576
+#define NTSC_HEIGHT 480
+
+#ifndef VIDEO_FORMAT
+#define VIDEO_FORMAT NTSC
+#endif
+
+static int bktr_dev[] = { METEOR_DEV0, METEOR_DEV1, METEOR_DEV2,
+ METEOR_DEV3, METEOR_DEV_SVIDEO };
+
+uint8_t *video_buf;
+size_t video_buf_size;
+u_int64_t last_frame_time;
+volatile sig_atomic_t nsignals;
+
+
+static void catchsignal(int signal)
+{
+ nsignals++;
+ return;
+}
+
+static int bktr_init(const char *video_device, int width, int height,
+ int format, int *video_fd, int *tuner_fd, int idev, double frequency)
+{
+ struct meteor_geomet geo;
+ int h_max;
+ long ioctl_frequency;
+ char *arg;
+ int c;
+ struct sigaction act, old;
+
+ if (idev < 0 || idev > 4)
+ {
+ arg = getenv ("BKTR_DEV");
+ if (arg)
+ idev = atoi (arg);
+ if (idev < 0 || idev > 4)
+ idev = 1;
+ }
+
+ if (format < 1 || format > 6)
+ {
+ arg = getenv ("BKTR_FORMAT");
+ if (arg)
+ format = atoi (arg);
+ if (format < 1 || format > 6)
+ format = VIDEO_FORMAT;
+ }
+
+ if (frequency <= 0)
+ {
+ arg = getenv ("BKTR_FREQUENCY");
+ if (arg)
+ frequency = atof (arg);
+ if (frequency <= 0)
+ frequency = 0.0;
+ }
+
+ memset(&act, 0, sizeof(act));
+ sigemptyset(&act.sa_mask);
+ act.sa_handler = catchsignal;
+ sigaction(SIGUSR1, &act, &old);
+
+ *tuner_fd = open("/dev/tuner0", O_RDONLY);
+ if (*tuner_fd < 0)
+ perror("Warning: Tuner not opened, continuing");
+
+ *video_fd = open(video_device, O_RDONLY);
+ if (*video_fd < 0) {
+ perror(video_device);
+ return -1;
+ }
+
+ geo.rows = height;
+ geo.columns = width;
+ geo.frames = 1;
+ geo.oformat = METEOR_GEO_YUV_422 | METEOR_GEO_YUV_12;
+
+ switch (format) {
+ case PAL: h_max = PAL_HEIGHT; c = BT848_IFORM_F_PALBDGHI; break;
+ case PALN: h_max = PAL_HEIGHT; c = BT848_IFORM_F_PALN; break;
+ case PALM: h_max = PAL_HEIGHT; c = BT848_IFORM_F_PALM; break;
+ case SECAM: h_max = SECAM_HEIGHT; c = BT848_IFORM_F_SECAM; break;
+ case NTSC: h_max = NTSC_HEIGHT; c = BT848_IFORM_F_NTSCM; break;
+ case NTSCJ: h_max = NTSC_HEIGHT; c = BT848_IFORM_F_NTSCJ; break;
+ default: h_max = PAL_HEIGHT; c = BT848_IFORM_F_PALBDGHI; break;
+ }
+
+ if (height <= h_max / 2)
+ geo.oformat |= METEOR_GEO_EVEN_ONLY;
+
+ if (ioctl(*video_fd, METEORSETGEO, &geo) < 0) {
+ perror("METEORSETGEO");
+ return -1;
+ }
+
+ if (ioctl(*video_fd, BT848SFMT, &c) < 0) {
+ perror("BT848SFMT");
+ return -1;
+ }
+
+ c = bktr_dev[idev];
+ if (ioctl(*video_fd, METEORSINPUT, &c) < 0) {
+ perror("METEORSINPUT");
+ return -1;
+ }
+
+ video_buf_size = width * height * 12 / 8;
+
+ video_buf = (uint8_t *)mmap((caddr_t)0, video_buf_size,
+ PROT_READ, MAP_SHARED, *video_fd, (off_t)0);
+ if (video_buf == MAP_FAILED) {
+ perror("mmap");
+ return -1;
+ }
+
+ if (frequency != 0.0) {
+ ioctl_frequency = (unsigned long)(frequency*16);
+ if (ioctl(*tuner_fd, TVTUNER_SETFREQ, &ioctl_frequency) < 0)
+ perror("TVTUNER_SETFREQ");
+ }
+
+ c = AUDIO_UNMUTE;
+ if (ioctl(*tuner_fd, BT848_SAUDIO, &c) < 0)
+ perror("TVTUNER_SAUDIO");
+
+ c = METEOR_CAP_CONTINOUS;
+ ioctl(*video_fd, METEORCAPTUR, &c);
+
+ c = SIGUSR1;
+ ioctl(*video_fd, METEORSSIGNAL, &c);
+
+ return 0;
+}
+
+static void bktr_getframe(u_int64_t per_frame)
+{
+ u_int64_t curtime;
+
+ curtime = av_gettime();
+ if (!last_frame_time
+ || ((last_frame_time + per_frame) > curtime)) {
+ if (!usleep(last_frame_time + per_frame + per_frame / 8 - curtime)) {
+ if (!nsignals)
+ av_log(NULL, AV_LOG_INFO,
+ "SLEPT NO signals - %d microseconds late\n",
+ (int)(av_gettime() - last_frame_time - per_frame));
+ }
+ }
+ nsignals = 0;
+ last_frame_time = curtime;
+}
+
+
+/* note: we support only one picture read at a time */
+static int grab_read_packet(AVFormatContext *s1, AVPacket *pkt)
+{
+ VideoData *s = s1->priv_data;
+
+ if (av_new_packet(pkt, video_buf_size) < 0)
+ return AVERROR(EIO);
+
+ bktr_getframe(s->per_frame);
+
+ pkt->pts = av_gettime();
+ memcpy(pkt->data, video_buf, video_buf_size);
+
+ return video_buf_size;
+}
+
+static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
+{
+ VideoData *s = s1->priv_data;
+ AVStream *st;
+ int width, height;
+ int frame_rate;
+ int frame_rate_base;
+ int format = -1;
+
+ if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0)
+ return -1;
+
+ width = ap->width;
+ height = ap->height;
+ frame_rate = ap->time_base.den;
+ frame_rate_base = ap->time_base.num;
+
+ st = av_new_stream(s1, 0);
+ if (!st)
+ return AVERROR(ENOMEM);
+ av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in use */
+
+ s->width = width;
+ s->height = height;
+ s->frame_rate = frame_rate;
+ s->frame_rate_base = frame_rate_base;
+ s->per_frame = ((u_int64_t)1000000 * s->frame_rate_base) / s->frame_rate;
+
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ st->codec->pix_fmt = PIX_FMT_YUV420P;
+ st->codec->codec_id = CODEC_ID_RAWVIDEO;
+ st->codec->width = width;
+ st->codec->height = height;
+ st->codec->time_base.den = frame_rate;
+ st->codec->time_base.num = frame_rate_base;
+
+ if (ap->standard) {
+ if (!strcasecmp(ap->standard, "pal"))
+ format = PAL;
+ else if (!strcasecmp(ap->standard, "secam"))
+ format = SECAM;
+ else if (!strcasecmp(ap->standard, "ntsc"))
+ format = NTSC;
+ }
+
+ if (bktr_init(s1->filename, width, height, format,
+ &(s->video_fd), &(s->tuner_fd), -1, 0.0) < 0)
+ return AVERROR(EIO);
+
+ nsignals = 0;
+ last_frame_time = 0;
+
+ return 0;
+}
+
+static int grab_read_close(AVFormatContext *s1)
+{
+ VideoData *s = s1->priv_data;
+ int c;
+
+ c = METEOR_CAP_STOP_CONT;
+ ioctl(s->video_fd, METEORCAPTUR, &c);
+ close(s->video_fd);
+
+ c = AUDIO_MUTE;
+ ioctl(s->tuner_fd, BT848_SAUDIO, &c);
+ close(s->tuner_fd);
+
+ munmap((caddr_t)video_buf, video_buf_size);
+
+ return 0;
+}
+
+AVInputFormat video_grab_device_demuxer = {
+ "bktr",
+ "video grab",
+ sizeof(VideoData),
+ NULL,
+ grab_read_header,
+ grab_read_packet,
+ grab_read_close,
+ .flags = AVFMT_NOFILE,
+};
diff --git a/contrib/ffmpeg/libavformat/gxf.c b/contrib/ffmpeg/libavformat/gxf.c
new file mode 100644
index 000000000..ba2463ead
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/gxf.c
@@ -0,0 +1,524 @@
+/*
+ * GXF demuxer.
+ * Copyright (c) 2006 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 "avformat.h"
+#include "common.h"
+
+typedef enum {
+ PKT_MAP = 0xbc,
+ PKT_MEDIA = 0xbf,
+ PKT_EOS = 0xfb,
+ PKT_FLT = 0xfc,
+ PKT_UMF = 0xfd
+} pkt_type_t;
+
+typedef enum {
+ MAT_NAME = 0x40,
+ MAT_FIRST_FIELD = 0x41,
+ MAT_LAST_FIELD = 0x42,
+ MAT_MARK_IN = 0x43,
+ MAT_MARK_OUT = 0x44,
+ MAT_SIZE = 0x45
+} mat_tag_t;
+
+typedef enum {
+ TRACK_NAME = 0x4c,
+ TRACK_AUX = 0x4d,
+ TRACK_VER = 0x4e,
+ TRACK_MPG_AUX = 0x4f,
+ TRACK_FPS = 0x50,
+ TRACK_LINES = 0x51,
+ TRACK_FPF = 0x52
+} track_tag_t;
+
+typedef struct {
+ int64_t first_field;
+ int64_t last_field;
+ AVRational frames_per_second;
+ int32_t fields_per_frame;
+} st_info_t;
+
+/**
+ * \brief parses a packet header, extracting type and length
+ * \param pb ByteIOContext to read header from
+ * \param type detected packet type is stored here
+ * \param length detected packet length, excluding header is stored here
+ * \return 0 if header not found or contains invalid data, 1 otherwise
+ */
+static int parse_packet_header(ByteIOContext *pb, pkt_type_t *type, int *length) {
+ if (get_be32(pb))
+ return 0;
+ if (get_byte(pb) != 1)
+ return 0;
+ *type = get_byte(pb);
+ *length = get_be32(pb);
+ if ((*length >> 24) || *length < 16)
+ return 0;
+ *length -= 16;
+ if (get_be32(pb))
+ return 0;
+ if (get_byte(pb) != 0xe1)
+ return 0;
+ if (get_byte(pb) != 0xe2)
+ return 0;
+ return 1;
+}
+
+/**
+ * \brief check if file starts with a PKT_MAP header
+ */
+static int gxf_probe(AVProbeData *p) {
+ static const uint8_t startcode[] = {0, 0, 0, 0, 1, 0xbc}; // start with map packet
+ static const uint8_t endcode[] = {0, 0, 0, 0, 0xe1, 0xe2};
+ if (p->buf_size < 16)
+ return 0;
+ if (!memcmp(p->buf, startcode, sizeof(startcode)) &&
+ !memcmp(&p->buf[16 - sizeof(endcode)], endcode, sizeof(endcode)))
+ return AVPROBE_SCORE_MAX;
+ return 0;
+}
+
+/**
+ * \brief gets the stream index for the track with the specified id, creates new
+ * stream if not found
+ * \param stream id of stream to find / add
+ * \param format stream format identifier
+ */
+static int get_sindex(AVFormatContext *s, int id, int format) {
+ int i;
+ AVStream *st = NULL;
+ for (i = 0; i < s->nb_streams; i++) {
+ if (s->streams[i]->id == id)
+ return i;
+ }
+ st = av_new_stream(s, id);
+ switch (format) {
+ case 3:
+ case 4:
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ st->codec->codec_id = CODEC_ID_MJPEG;
+ break;
+ case 13:
+ case 15:
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ st->codec->codec_id = CODEC_ID_DVVIDEO;
+ break;
+ case 14:
+ case 16:
+ st->codec->codec_type = CODEC_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_id = CODEC_ID_MPEG2VIDEO;
+ st->need_parsing = 2; // get keyframe flag etc.
+ break;
+ case 22:
+ case 23:
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ st->codec->codec_id = CODEC_ID_MPEG1VIDEO;
+ st->need_parsing = 2; // get keyframe flag etc.
+ break;
+ case 9:
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_id = CODEC_ID_PCM_S24LE;
+ st->codec->channels = 1;
+ st->codec->sample_rate = 48000;
+ st->codec->bit_rate = 3 * 1 * 48000 * 8;
+ st->codec->block_align = 3 * 1;
+ st->codec->bits_per_sample = 24;
+ break;
+ case 10:
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_id = CODEC_ID_PCM_S16LE;
+ st->codec->channels = 1;
+ st->codec->sample_rate = 48000;
+ st->codec->bit_rate = 2 * 1 * 48000 * 8;
+ st->codec->block_align = 2 * 1;
+ st->codec->bits_per_sample = 16;
+ break;
+ case 17:
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_id = CODEC_ID_AC3;
+ st->codec->channels = 2;
+ st->codec->sample_rate = 48000;
+ break;
+ // timecode tracks:
+ case 7:
+ case 8:
+ case 24:
+ st->codec->codec_type = CODEC_TYPE_DATA;
+ st->codec->codec_id = CODEC_ID_NONE;
+ break;
+ default:
+ st->codec->codec_type = CODEC_TYPE_UNKNOWN;
+ st->codec->codec_id = CODEC_ID_NONE;
+ break;
+ }
+ return s->nb_streams - 1;
+}
+
+/**
+ * \brief filters out interesting tags from material information.
+ * \param len lenght of tag section, will be adjusted to contain remaining bytes
+ * \param si struct to store collected information into
+ */
+static void gxf_material_tags(ByteIOContext *pb, int *len, st_info_t *si) {
+ si->first_field = AV_NOPTS_VALUE;
+ si->last_field = AV_NOPTS_VALUE;
+ while (*len >= 2) {
+ mat_tag_t tag = get_byte(pb);
+ int tlen = get_byte(pb);
+ *len -= 2;
+ if (tlen > *len)
+ return;
+ *len -= tlen;
+ if (tlen == 4) {
+ uint32_t value = get_be32(pb);
+ if (tag == MAT_FIRST_FIELD)
+ si->first_field = value;
+ else if (tag == MAT_LAST_FIELD)
+ si->last_field = value;
+ } else
+ url_fskip(pb, tlen);
+ }
+}
+
+/**
+ * \brief convert fps tag value to AVRational fps
+ * \param fps fps value from tag
+ * \return fps as AVRational, or 0 / 0 if unknown
+ */
+static AVRational fps_tag2avr(int32_t fps) {
+ extern const AVRational ff_frame_rate_tab[];
+ if (fps < 1 || fps > 9) fps = 9;
+ return ff_frame_rate_tab[9 - fps]; // values have opposite order
+}
+
+/**
+ * \brief convert UMF attributes flags to AVRational fps
+ * \param fps fps value from flags
+ * \return fps as AVRational, or 0 / 0 if unknown
+ */
+static AVRational fps_umf2avr(uint32_t flags) {
+ static const AVRational map[] = {{50, 1}, {60000, 1001}, {24, 1},
+ {25, 1}, {30000, 1001}};
+ int idx = av_log2((flags & 0x7c0) >> 6);
+ return map[idx];
+}
+
+/**
+ * \brief filters out interesting tags from track information.
+ * \param len length of tag section, will be adjusted to contain remaining bytes
+ * \param si struct to store collected information into
+ */
+static void gxf_track_tags(ByteIOContext *pb, int *len, st_info_t *si) {
+ si->frames_per_second = (AVRational){0, 0};
+ si->fields_per_frame = 0;
+ while (*len >= 2) {
+ track_tag_t tag = get_byte(pb);
+ int tlen = get_byte(pb);
+ *len -= 2;
+ if (tlen > *len)
+ return;
+ *len -= tlen;
+ if (tlen == 4) {
+ uint32_t value = get_be32(pb);
+ if (tag == TRACK_FPS)
+ si->frames_per_second = fps_tag2avr(value);
+ else if (tag == TRACK_FPF && (value == 1 || value == 2))
+ si->fields_per_frame = value;
+ } else
+ url_fskip(pb, tlen);
+ }
+}
+
+/**
+ * \brief read index from FLT packet into stream 0 av_index
+ */
+static void gxf_read_index(AVFormatContext *s, int pkt_len) {
+ ByteIOContext *pb = &s->pb;
+ AVStream *st = s->streams[0];
+ uint32_t fields_per_map = get_le32(pb);
+ uint32_t map_cnt = get_le32(pb);
+ int i;
+ pkt_len -= 8;
+ if (map_cnt > 1000) {
+ av_log(s, AV_LOG_ERROR, "GXF: too many index entries %u (%x)\n", map_cnt, map_cnt);
+ map_cnt = 1000;
+ }
+ if (pkt_len < 4 * map_cnt) {
+ av_log(s, AV_LOG_ERROR, "GXF: invalid index length\n");
+ url_fskip(pb, pkt_len);
+ return;
+ }
+ pkt_len -= 4 * map_cnt;
+ av_add_index_entry(st, 0, 0, 0, 0, 0);
+ for (i = 0; i < map_cnt; i++)
+ av_add_index_entry(st, (uint64_t)get_le32(pb) * 1024,
+ i * (uint64_t)fields_per_map + 1, 0, 0, 0);
+ url_fskip(pb, pkt_len);
+}
+
+static int gxf_header(AVFormatContext *s, AVFormatParameters *ap) {
+ ByteIOContext *pb = &s->pb;
+ pkt_type_t pkt_type;
+ int map_len;
+ int len;
+ AVRational main_timebase = {0, 0};
+ st_info_t si;
+ int i;
+ if (!parse_packet_header(pb, &pkt_type, &map_len) || pkt_type != PKT_MAP) {
+ av_log(s, AV_LOG_ERROR, "GXF: map packet not found\n");
+ return 0;
+ }
+ map_len -= 2;
+ if (get_byte(pb) != 0x0e0 || get_byte(pb) != 0xff) {
+ av_log(s, AV_LOG_ERROR, "GXF: unknown version or invalid map preamble\n");
+ return 0;
+ }
+ map_len -= 2;
+ len = get_be16(pb); // length of material data section
+ if (len > map_len) {
+ av_log(s, AV_LOG_ERROR, "GXF: material data longer than map data\n");
+ return 0;
+ }
+ map_len -= len;
+ gxf_material_tags(pb, &len, &si);
+ url_fskip(pb, len);
+ map_len -= 2;
+ len = get_be16(pb); // length of track description
+ if (len > map_len) {
+ av_log(s, AV_LOG_ERROR, "GXF: track description longer than map data\n");
+ return 0;
+ }
+ map_len -= len;
+ while (len > 0) {
+ int track_type, track_id, track_len;
+ AVStream *st;
+ int idx;
+ len -= 4;
+ track_type = get_byte(pb);
+ track_id = get_byte(pb);
+ track_len = get_be16(pb);
+ len -= track_len;
+ gxf_track_tags(pb, &track_len, &si);
+ url_fskip(pb, track_len);
+ if (!(track_type & 0x80)) {
+ av_log(s, AV_LOG_ERROR, "GXF: invalid track type %x\n", track_type);
+ continue;
+ }
+ track_type &= 0x7f;
+ if ((track_id & 0xc0) != 0xc0) {
+ av_log(s, AV_LOG_ERROR, "GXF: invalid track id %x\n", track_id);
+ continue;
+ }
+ track_id &= 0x3f;
+ idx = get_sindex(s, track_id, track_type);
+ if (idx < 0) continue;
+ st = s->streams[idx];
+ if (!main_timebase.num || !main_timebase.den) {
+ main_timebase.num = si.frames_per_second.den;
+ main_timebase.den = si.frames_per_second.num * si.fields_per_frame;
+ }
+ st->start_time = si.first_field;
+ if (si.first_field != AV_NOPTS_VALUE && si.last_field != AV_NOPTS_VALUE)
+ st->duration = si.last_field - si.first_field;
+ }
+ if (len < 0)
+ av_log(s, AV_LOG_ERROR, "GXF: invalid track description length specified\n");
+ if (map_len)
+ url_fskip(pb, map_len);
+ if (!parse_packet_header(pb, &pkt_type, &len)) {
+ av_log(s, AV_LOG_ERROR, "GXF: sync lost in header\n");
+ return -1;
+ }
+ if (pkt_type == PKT_FLT) {
+ gxf_read_index(s, len);
+ if (!parse_packet_header(pb, &pkt_type, &len)) {
+ av_log(s, AV_LOG_ERROR, "GXF: sync lost in header\n");
+ return -1;
+ }
+ }
+ if (pkt_type == PKT_UMF) {
+ if (len >= 0x39) {
+ AVRational fps;
+ len -= 0x39;
+ url_fskip(pb, 5); // preamble
+ url_fskip(pb, 0x30); // payload description
+ fps = fps_umf2avr(get_le32(pb));
+ 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;
+ }
+ } else
+ av_log(s, AV_LOG_INFO, "GXF: UMF packet too short\n");
+ } else
+ av_log(s, AV_LOG_INFO, "GXF: UMF packet missing\n");
+ url_fskip(pb, len);
+ if (!main_timebase.num || !main_timebase.den)
+ main_timebase = (AVRational){1, 50}; // set some arbitrary fallback
+ 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);
+ }
+ return 0;
+}
+
+#define READ_ONE() \
+ { \
+ if (!max_interval-- || url_feof(pb)) \
+ goto out; \
+ tmp = tmp << 8 | get_byte(pb); \
+ }
+
+/**
+ * \brief resync the stream on the next media packet with specified properties
+ * \param max_interval how many bytes to search for matching packet at most
+ * \param track track id the media packet must belong to, -1 for any
+ * \param timestamp minimum timestamp (== field number) the packet must have, -1 for any
+ * \return timestamp of packet found
+ */
+static int64_t gxf_resync_media(AVFormatContext *s, uint64_t max_interval, int track, int timestamp) {
+ uint32_t tmp;
+ uint64_t last_pos;
+ uint64_t last_found_pos = 0;
+ int cur_track;
+ int64_t cur_timestamp = AV_NOPTS_VALUE;
+ int len;
+ ByteIOContext *pb = &s->pb;
+ pkt_type_t type;
+ tmp = get_be32(pb);
+start:
+ while (tmp)
+ READ_ONE();
+ READ_ONE();
+ if (tmp != 1)
+ goto start;
+ last_pos = url_ftell(pb);
+ url_fseek(pb, -5, SEEK_CUR);
+ if (!parse_packet_header(pb, &type, &len) || type != PKT_MEDIA) {
+ url_fseek(pb, last_pos, SEEK_SET);
+ goto start;
+ }
+ get_byte(pb);
+ cur_track = get_byte(pb);
+ cur_timestamp = get_be32(pb);
+ last_found_pos = url_ftell(pb) - 16 - 6;
+ if ((track >= 0 && track != cur_track) || (timestamp >= 0 && timestamp > cur_timestamp)) {
+ url_fseek(pb, last_pos, SEEK_SET);
+ goto start;
+ }
+out:
+ if (last_found_pos)
+ url_fseek(pb, last_found_pos, SEEK_SET);
+ return cur_timestamp;
+}
+
+static int gxf_packet(AVFormatContext *s, AVPacket *pkt) {
+ ByteIOContext *pb = &s->pb;
+ pkt_type_t pkt_type;
+ int pkt_len;
+ while (!url_feof(pb)) {
+ int track_type, track_id, ret;
+ int field_nr;
+ if (!parse_packet_header(pb, &pkt_type, &pkt_len)) {
+ if (!url_feof(pb))
+ av_log(s, AV_LOG_ERROR, "GXF: sync lost\n");
+ return -1;
+ }
+ if (pkt_type == PKT_FLT) {
+ gxf_read_index(s, pkt_len);
+ continue;
+ }
+ if (pkt_type != PKT_MEDIA) {
+ url_fskip(pb, pkt_len);
+ continue;
+ }
+ if (pkt_len < 16) {
+ av_log(s, AV_LOG_ERROR, "GXF: invalid media packet length\n");
+ continue;
+ }
+ pkt_len -= 16;
+ track_type = get_byte(pb);
+ track_id = get_byte(pb);
+ field_nr = get_be32(pb);
+ get_be32(pb); // field information
+ get_be32(pb); // "timeline" field number
+ get_byte(pb); // flags
+ get_byte(pb); // reserved
+ // NOTE: there is also data length information in the
+ // field information, it might be better to take this into account
+ // as well.
+ ret = av_get_packet(pb, pkt, pkt_len);
+ pkt->stream_index = get_sindex(s, track_id, track_type);
+ pkt->dts = field_nr;
+ return ret;
+ }
+ return AVERROR_IO;
+}
+
+static int gxf_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) {
+ uint64_t pos;
+ uint64_t maxlen = 100 * 1024 * 1024;
+ AVStream *st = s->streams[0];
+ int64_t start_time = s->streams[stream_index]->start_time;
+ int64_t found;
+ int idx;
+ if (timestamp < start_time) timestamp = start_time;
+ idx = av_index_search_timestamp(st, timestamp - start_time,
+ AVSEEK_FLAG_ANY | AVSEEK_FLAG_BACKWARD);
+ if (idx < 0)
+ return -1;
+ pos = st->index_entries[idx].pos;
+ if (idx < st->nb_index_entries - 2)
+ maxlen = st->index_entries[idx + 2].pos - pos;
+ maxlen = FFMAX(maxlen, 200 * 1024);
+ url_fseek(&s->pb, pos, SEEK_SET);
+ found = gxf_resync_media(s, maxlen, -1, timestamp);
+ if (FFABS(found - timestamp) > 4)
+ return -1;
+ return 0;
+}
+
+static int64_t gxf_read_timestamp(AVFormatContext *s, int stream_index,
+ int64_t *pos, int64_t pos_limit) {
+ ByteIOContext *pb = &s->pb;
+ int64_t res;
+ url_fseek(pb, *pos, SEEK_SET);
+ res = gxf_resync_media(s, pos_limit - *pos, -1, -1);
+ *pos = url_ftell(pb);
+ return res;
+}
+
+AVInputFormat gxf_demuxer = {
+ "gxf",
+ "GXF format",
+ 0,
+ gxf_probe,
+ gxf_header,
+ gxf_packet,
+ NULL,
+ gxf_seek,
+ gxf_read_timestamp,
+};
diff --git a/contrib/ffmpeg/libavformat/gxf.h b/contrib/ffmpeg/libavformat/gxf.h
new file mode 100644
index 000000000..0e2a31ca4
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/gxf.h
@@ -0,0 +1,34 @@
+/*
+ * GXF demuxer
+ * copyright (c) 2006 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
+ */
+
+#ifndef FFMPEG_GXF_H
+#define FFMPEG_GXF_H
+
+/* gxf.c */
+typedef enum {
+ PKT_MAP = 0xbc,
+ PKT_MEDIA = 0xbf,
+ PKT_EOS = 0xfb,
+ PKT_FLT = 0xfc,
+ PKT_UMF = 0xfd
+} pkt_type_t;
+
+#endif /* FFMPEG_GXF_H */
diff --git a/contrib/ffmpeg/libavformat/gxfenc.c b/contrib/ffmpeg/libavformat/gxfenc.c
new file mode 100644
index 000000000..39b9ed3e1
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/gxfenc.c
@@ -0,0 +1,828 @@
+/*
+ * GXF muxer.
+ * Copyright (c) 2006 SmartJog S.A., Baptiste Coudurier <baptiste dot coudurier at smartjog dot com>.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avformat.h"
+#include "gxf.h"
+#include "riff.h"
+#include "fifo.h"
+
+#define GXF_AUDIO_PACKET_SIZE 65536
+
+typedef struct GXFStreamContext {
+ AVCodecContext *codec;
+ AVFifoBuffer audio_buffer;
+ uint32_t track_type;
+ uint32_t sample_size;
+ uint32_t sample_rate;
+ uint16_t media_type;
+ uint16_t media_info;
+ uint8_t index;
+ int frame_rate_index;
+ int lines_index;
+ int fields;
+ int iframes;
+ int pframes;
+ int bframes;
+ int p_per_gop;
+ int b_per_gop;
+ int first_gop_closed;
+ int64_t current_dts;
+ int dts_delay;
+} GXFStreamContext;
+
+typedef struct GXFContext {
+ uint32_t nb_frames;
+ uint32_t material_flags;
+ uint16_t audio_tracks;
+ uint16_t mpeg_tracks;
+ int64_t creation_time;
+ uint32_t umf_start_offset;
+ uint32_t umf_track_offset;
+ uint32_t umf_media_offset;
+ uint32_t umf_user_data_offset;
+ uint32_t umf_user_data_size;
+ uint32_t umf_length;
+ uint16_t umf_track_size;
+ uint16_t umf_media_size;
+ int audio_written;
+ int sample_rate;
+ int flags;
+ AVFormatContext *fc;
+ GXFStreamContext streams[48];
+} GXFContext;
+
+typedef struct GXF_Lines {
+ int height;
+ int index;
+} GXF_Lines;
+
+
+/* FIXME check if it is relevant */
+static const GXF_Lines gxf_lines_tab[] = {
+ { 480, 1 }, /* NTSC */
+ { 512, 1 }, /* NTSC + VBI */
+ { 576, 2 }, /* PAL */
+ { 608, 2 }, /* PAL + VBI */
+ { 1080, 4 },
+ { 720, 6 },
+};
+
+static const AVCodecTag gxf_media_types[] = {
+ { CODEC_ID_MJPEG , 3 }, /* NTSC */
+ { CODEC_ID_MJPEG , 4 }, /* PAL */
+ { CODEC_ID_PCM_S24LE , 9 },
+ { CODEC_ID_PCM_S16LE , 10 },
+ { CODEC_ID_MPEG2VIDEO, 11 }, /* NTSC */
+ { CODEC_ID_MPEG2VIDEO, 12 }, /* PAL */
+ { CODEC_ID_DVVIDEO , 13 }, /* NTSC */
+ { CODEC_ID_DVVIDEO , 14 }, /* PAL */
+ { CODEC_ID_DVVIDEO , 15 }, /* 50M NTSC */
+ { CODEC_ID_DVVIDEO , 16 }, /* 50M PAL */
+ { CODEC_ID_AC3 , 17 },
+ //{ CODEC_ID_NONE, , 18 }, /* Non compressed 24 bit audio */
+ { CODEC_ID_MPEG2VIDEO, 20 }, /* MPEG HD */
+ { CODEC_ID_MPEG1VIDEO, 22 }, /* NTSC */
+ { CODEC_ID_MPEG1VIDEO, 23 }, /* PAL */
+ { 0, 0 },
+};
+
+#define SERVER_PATH "/space/"
+#define ES_NAME_PATTERN "ES."
+
+static int gxf_find_lines_index(GXFStreamContext *ctx)
+{
+ int i;
+
+ for (i = 0; i < 6; ++i) {
+ if (ctx->codec->height == gxf_lines_tab[i].height) {
+ ctx->lines_index = gxf_lines_tab[i].index;
+ return 0;
+ }
+ }
+ return -1;
+}
+
+static void gxf_write_padding(ByteIOContext *pb, offset_t to_pad)
+{
+ for (; to_pad > 0; to_pad--) {
+ put_byte(pb, 0);
+ }
+}
+
+static offset_t updatePacketSize(ByteIOContext *pb, offset_t pos)
+{
+ offset_t curpos;
+ int size;
+
+ size = url_ftell(pb) - pos;
+ if (size % 4) {
+ gxf_write_padding(pb, 4 - size % 4);
+ size = url_ftell(pb) - pos;
+ }
+ curpos = url_ftell(pb);
+ url_fseek(pb, pos + 6, SEEK_SET);
+ put_be32(pb, size);
+ url_fseek(pb, curpos, SEEK_SET);
+ return curpos - pos;
+}
+
+static offset_t updateSize(ByteIOContext *pb, offset_t pos)
+{
+ offset_t curpos;
+
+ curpos = url_ftell(pb);
+ url_fseek(pb, pos, SEEK_SET);
+ put_be16(pb, curpos - pos - 2);
+ url_fseek(pb, curpos, SEEK_SET);
+ return curpos - pos;
+}
+
+static void gxf_write_packet_header(ByteIOContext *pb, pkt_type_t type)
+{
+ put_be32(pb, 0); /* packet leader for synchro */
+ put_byte(pb, 1);
+ put_byte(pb, type); /* map packet */
+ put_be32(pb, 0); /* size */
+ put_be32(pb, 0); /* reserved */
+ put_byte(pb, 0xE1); /* trailer 1 */
+ put_byte(pb, 0xE2); /* trailer 2 */
+}
+
+static int gxf_write_mpeg_auxiliary(ByteIOContext *pb, GXFStreamContext *ctx)
+{
+ char buffer[1024];
+ int size;
+
+ if (ctx->iframes) {
+ ctx->p_per_gop = ctx->pframes / ctx->iframes;
+ if (ctx->pframes % ctx->iframes)
+ ctx->p_per_gop++;
+ if (ctx->pframes)
+ ctx->b_per_gop = ctx->bframes / ctx->pframes;
+ if (ctx->p_per_gop > 9)
+ ctx->p_per_gop = 9; /* ensure value won't take more than one char */
+ if (ctx->b_per_gop > 9)
+ ctx->b_per_gop = 9; /* ensure value won't take more than one char */
+ }
+ size = snprintf(buffer, 1024, "Ver 1\nBr %.6f\nIpg 1\nPpi %d\nBpiop %d\n"
+ "Pix 0\nCf %d\nCg %d\nSl 7\nnl16 %d\nVi 1\nf1 1\n",
+ (float)ctx->codec->bit_rate, ctx->p_per_gop, ctx->b_per_gop,
+ ctx->codec->pix_fmt == PIX_FMT_YUV422P ? 2 : 1, ctx->first_gop_closed == 1,
+ ctx->codec->height / 16);
+ put_byte(pb, 0x4F);
+ put_byte(pb, size + 1);
+ put_buffer(pb, (uint8_t *)buffer, size + 1);
+ return size + 3;
+}
+
+static int gxf_write_timecode_auxiliary(ByteIOContext *pb, GXFStreamContext *ctx)
+{
+ /* FIXME implement that */
+ put_byte(pb, 0); /* fields */
+ put_byte(pb, 0); /* seconds */
+ put_byte(pb, 0); /* minutes */
+ put_byte(pb, 0); /* flags + hours */
+ /* reserved */
+ put_be32(pb, 0);
+ return 8;
+}
+
+static int gxf_write_track_description(ByteIOContext *pb, GXFStreamContext *stream)
+{
+ offset_t pos;
+
+ /* track description section */
+ put_byte(pb, stream->media_type + 0x80);
+ put_byte(pb, stream->index + 0xC0);
+
+ pos = url_ftell(pb);
+ put_be16(pb, 0); /* size */
+
+ /* media file name */
+ put_byte(pb, 0x4C);
+ put_byte(pb, strlen(ES_NAME_PATTERN) + 3);
+ put_tag(pb, ES_NAME_PATTERN);
+ put_be16(pb, stream->media_info);
+ put_byte(pb, 0);
+
+ if (stream->codec->codec_id != CODEC_ID_MPEG2VIDEO) {
+ /* auxiliary information */
+ put_byte(pb, 0x4D);
+ put_byte(pb, 8);
+ if (stream->codec->codec_id == CODEC_ID_NONE)
+ gxf_write_timecode_auxiliary(pb, stream);
+ else
+ put_le64(pb, 0);
+ }
+
+ /* file system version */
+ put_byte(pb, 0x4E);
+ put_byte(pb, 4);
+ put_be32(pb, 0);
+
+ if (stream->codec->codec_id == CODEC_ID_MPEG2VIDEO)
+ gxf_write_mpeg_auxiliary(pb, stream);
+
+ /* frame rate */
+ put_byte(pb, 0x50);
+ put_byte(pb, 4);
+ put_be32(pb, stream->frame_rate_index);
+
+ /* lines per frame */
+ put_byte(pb, 0x51);
+ put_byte(pb, 4);
+ put_be32(pb, stream->lines_index);
+
+ /* fields per frame */
+ put_byte(pb, 0x52);
+ put_byte(pb, 4);
+ put_be32(pb, stream->fields);
+
+ return updateSize(pb, pos);
+}
+
+static int gxf_write_material_data_section(ByteIOContext *pb, GXFContext *ctx)
+{
+ offset_t pos;
+ const char *filename = strrchr(ctx->fc->filename, '/');
+
+ pos = url_ftell(pb);
+ put_be16(pb, 0); /* size */
+
+ /* name */
+ if (filename)
+ filename++;
+ else
+ filename = ctx->fc->filename;
+ put_byte(pb, 0x40);
+ put_byte(pb, strlen(SERVER_PATH) + strlen(filename) + 1);
+ put_tag(pb, SERVER_PATH);
+ put_tag(pb, filename);
+ put_byte(pb, 0);
+
+ /* first field */
+ put_byte(pb, 0x41);
+ put_byte(pb, 4);
+ put_be32(pb, 0);
+
+ /* last field */
+ put_byte(pb, 0x42);
+ put_byte(pb, 4);
+ put_be32(pb, ctx->nb_frames);
+
+ /* reserved */
+ put_byte(pb, 0x43);
+ put_byte(pb, 4);
+ put_be32(pb, 0);
+
+ put_byte(pb, 0x44);
+ put_byte(pb, 4);
+ put_be32(pb, ctx->nb_frames);
+
+ /* estimated size */
+ put_byte(pb, 0x45);
+ put_byte(pb, 4);
+ put_be32(pb, url_fsize(pb) / 1024);
+
+ return updateSize(pb, pos);
+}
+
+static int gxf_write_track_description_section(ByteIOContext *pb, GXFContext *ctx)
+{
+ offset_t pos;
+ int i;
+
+ pos = url_ftell(pb);
+ put_be16(pb, 0); /* size */
+ for (i = 0; i < ctx->fc->nb_streams; ++i)
+ gxf_write_track_description(pb, &ctx->streams[i]);
+ return updateSize(pb, pos);
+}
+
+static int gxf_write_map_packet(ByteIOContext *pb, GXFContext *ctx)
+{
+ offset_t pos = url_ftell(pb);
+
+ gxf_write_packet_header(pb, PKT_MAP);
+
+ /* preamble */
+ put_byte(pb, 0xE0); /* version */
+ put_byte(pb, 0xFF); /* reserved */
+
+ gxf_write_material_data_section(pb, ctx);
+ gxf_write_track_description_section(pb, ctx);
+
+ return updatePacketSize(pb, pos);
+}
+
+#if 0
+static int gxf_write_flt_packet(ByteIOContext *pb, GXFContext *ctx)
+{
+ offset_t pos = url_ftell(pb);
+ int i;
+
+ gxf_write_packet_header(pb, PKT_FLT);
+
+ put_le32(pb, 1000); /* number of fields */
+ put_le32(pb, 0); /* number of active flt entries */
+
+ for (i = 0; i < 1000; ++i) {
+ put_le32(pb, 0);
+ }
+ return updatePacketSize(pb, pos);
+}
+#endif
+
+static int gxf_write_umf_material_description(ByteIOContext *pb, GXFContext *ctx)
+{
+ put_le32(pb, ctx->flags);
+ put_le32(pb, ctx->nb_frames); /* length of the longest track */
+ put_le32(pb, ctx->nb_frames); /* length of the shortest track */
+ put_le32(pb, 0); /* mark in */
+ put_le32(pb, ctx->nb_frames); /* mark out */
+ put_le32(pb, 0); /* timecode mark in */
+ put_le32(pb, ctx->nb_frames); /* timecode mark out */
+ put_le64(pb, ctx->fc->timestamp); /* modification time */
+ put_le64(pb, ctx->fc->timestamp); /* creation time */
+ put_le16(pb, 0); /* reserved */
+ put_le16(pb, 0); /* reserved */
+ put_le16(pb, ctx->audio_tracks);
+ put_le16(pb, 0); /* timecode track count */
+ put_le16(pb, 0); /* reserved */
+ put_le16(pb, ctx->mpeg_tracks);
+ return 48;
+}
+
+static int gxf_write_umf_payload(ByteIOContext *pb, GXFContext *ctx)
+{
+ put_le32(pb, ctx->umf_length); /* total length of the umf data */
+ put_le32(pb, 3); /* version */
+ put_le32(pb, ctx->fc->nb_streams);
+ put_le32(pb, ctx->umf_track_offset); /* umf track section offset */
+ put_le32(pb, ctx->umf_track_size);
+ put_le32(pb, ctx->fc->nb_streams);
+ put_le32(pb, ctx->umf_media_offset);
+ put_le32(pb, ctx->umf_media_size);
+ put_le32(pb, ctx->umf_user_data_offset); /* user data offset */
+ put_le32(pb, ctx->umf_user_data_size); /* user data size */
+ put_le32(pb, 0); /* reserved */
+ put_le32(pb, 0); /* reserved */
+ return 48;
+}
+
+static int gxf_write_umf_track_description(ByteIOContext *pb, GXFContext *ctx)
+{
+ offset_t pos = url_ftell(pb);
+ int tracks[255]={0};
+ int i;
+
+ ctx->umf_track_offset = pos - ctx->umf_start_offset;
+ for (i = 0; i < ctx->fc->nb_streams; ++i) {
+ AVStream *st = ctx->fc->streams[i];
+ GXFStreamContext *sc = &ctx->streams[i];
+ int id = 0;
+
+ switch (st->codec->codec_id) {
+ case CODEC_ID_MPEG1VIDEO: id= 'L'; break;
+ case CODEC_ID_MPEG2VIDEO: id= 'M'; break;
+ case CODEC_ID_PCM_S16LE: id= 'A'; break;
+ case CODEC_ID_DVVIDEO: id= sc->track_type == 6 ? 'E' : 'D'; break;
+ case CODEC_ID_MJPEG: id= 'V'; break;
+ default: break;
+ }
+ sc->media_info= id << 8;
+ /* FIXME first 10 audio tracks are 0 to 9 next 22 are A to V */
+ sc->media_info |= '0' + (tracks[id]++);
+ put_le16(pb, sc->media_info);
+ put_le16(pb, 1);
+ }
+ return url_ftell(pb) - pos;
+}
+
+static int gxf_write_umf_media_mpeg(ByteIOContext *pb, GXFStreamContext *stream)
+{
+ if (stream->codec->pix_fmt == PIX_FMT_YUV422P)
+ put_le32(pb, 2);
+ else
+ put_le32(pb, 1); /* default to 420 */
+ put_le32(pb, stream->first_gop_closed == 1); /* closed = 1, open = 0, unknown = 255 */
+ put_le32(pb, 3); /* top = 1, bottom = 2, frame = 3, unknown = 0 */
+ put_le32(pb, 1); /* I picture per GOP */
+ put_le32(pb, stream->p_per_gop);
+ put_le32(pb, stream->b_per_gop);
+ if (stream->codec->codec_id == CODEC_ID_MPEG2VIDEO)
+ put_le32(pb, 2);
+ else if (stream->codec->codec_id == CODEC_ID_MPEG1VIDEO)
+ put_le32(pb, 1);
+ else
+ put_le32(pb, 0);
+ put_le32(pb, 0); /* reserved */
+ return 32;
+}
+
+static int gxf_write_umf_media_timecode(ByteIOContext *pb, GXFStreamContext *track)
+{
+ /* FIXME implement */
+ put_be32(pb, 0); /* drop frame flag */
+ put_be32(pb, 0); /* reserved */
+ put_be32(pb, 0); /* reserved */
+ put_be32(pb, 0); /* reserved */
+ put_be32(pb, 0); /* reserved */
+ put_be32(pb, 0); /* reserved */
+ put_be32(pb, 0); /* reserved */
+ put_be32(pb, 0); /* reserved */
+ return 32;
+}
+
+static int gxf_write_umf_media_dv(ByteIOContext *pb, GXFStreamContext *track)
+{
+ int i;
+
+ for (i = 0; i < 8; i++) {
+ put_be32(pb, 0);
+ }
+ return 32;
+}
+
+static int gxf_write_umf_media_audio(ByteIOContext *pb, GXFStreamContext *track)
+{
+ put_le64(pb, av_dbl2int(1)); /* sound level to begin to */
+ put_le64(pb, av_dbl2int(1)); /* sound level to begin to */
+ put_le32(pb, 0); /* number of fields over which to ramp up sound level */
+ put_le32(pb, 0); /* number of fields over which to ramp down sound level */
+ put_le32(pb, 0); /* reserved */
+ put_le32(pb, 0); /* reserved */
+ return 32;
+}
+
+#if 0
+static int gxf_write_umf_media_mjpeg(ByteIOContext *pb, GXFStreamContext *track)
+{
+ put_be64(pb, 0); /* FIXME FLOAT max chroma quant level */
+ put_be64(pb, 0); /* FIXME FLOAT max luma quant level */
+ put_be64(pb, 0); /* FIXME FLOAT min chroma quant level */
+ put_be64(pb, 0); /* FIXME FLOAT min luma quant level */
+ return 32;
+}
+#endif
+
+static int gxf_write_umf_media_description(ByteIOContext *pb, GXFContext *ctx)
+{
+ offset_t pos;
+ int i;
+
+ pos = url_ftell(pb);
+ ctx->umf_media_offset = pos - ctx->umf_start_offset;
+ for (i = 0; i < ctx->fc->nb_streams; ++i) {
+ GXFStreamContext *sc = &ctx->streams[i];
+ char buffer[88];
+ offset_t startpos, curpos;
+ int path_size = strlen(ES_NAME_PATTERN);
+
+ memset(buffer, 0, 88);
+ startpos = url_ftell(pb);
+ put_le16(pb, 0); /* length */
+ put_le16(pb, sc->media_info);
+ put_le16(pb, 0); /* reserved */
+ put_le16(pb, 0); /* reserved */
+ put_le32(pb, ctx->nb_frames);
+ put_le32(pb, 0); /* attributes rw, ro */
+ put_le32(pb, 0); /* mark in */
+ put_le32(pb, ctx->nb_frames); /* mark out */
+ strncpy(buffer, ES_NAME_PATTERN, path_size);
+ put_buffer(pb, (uint8_t *)buffer, path_size);
+ put_be16(pb, sc->media_info);
+ put_buffer(pb, (uint8_t *)buffer + path_size + 2, 88 - path_size - 2);
+ put_le32(pb, sc->track_type);
+ put_le32(pb, sc->sample_rate);
+ put_le32(pb, sc->sample_size);
+ put_le32(pb, 0); /* reserved */
+ switch (sc->codec->codec_id) {
+ case CODEC_ID_MPEG2VIDEO:
+ gxf_write_umf_media_mpeg(pb, sc);
+ break;
+ case CODEC_ID_PCM_S16LE:
+ gxf_write_umf_media_audio(pb, sc);
+ break;
+ case CODEC_ID_DVVIDEO:
+ gxf_write_umf_media_dv(pb, sc);
+ break;
+ default:
+ gxf_write_umf_media_timecode(pb, sc); /* 8 0bytes */
+ }
+ curpos = url_ftell(pb);
+ url_fseek(pb, startpos, SEEK_SET);
+ put_le16(pb, curpos - startpos);
+ url_fseek(pb, curpos, SEEK_SET);
+ }
+ return url_ftell(pb) - pos;
+}
+
+static int gxf_write_umf_user_data(ByteIOContext *pb, GXFContext *ctx)
+{
+ offset_t pos = url_ftell(pb);
+ ctx->umf_user_data_offset = pos - ctx->umf_start_offset;
+ put_le32(pb, 20);
+ put_le32(pb, 0);
+ put_le16(pb, 0);
+ put_le16(pb, 0);
+ put_le32(pb, 0);
+ put_byte(pb, 0);
+ put_byte(pb, 0);
+ put_byte(pb, 0);
+ put_byte(pb, 0);
+ return 20;
+}
+
+static int gxf_write_umf_packet(ByteIOContext *pb, GXFContext *ctx)
+{
+ offset_t pos = url_ftell(pb);
+
+ gxf_write_packet_header(pb, PKT_UMF);
+
+ /* preamble */
+ put_byte(pb, 3); /* first and last (only) packet */
+ put_be32(pb, ctx->umf_length); /* data length */
+
+ ctx->umf_start_offset = url_ftell(pb);
+ gxf_write_umf_payload(pb, ctx);
+ gxf_write_umf_material_description(pb, ctx);
+ ctx->umf_track_size = gxf_write_umf_track_description(pb, ctx);
+ ctx->umf_media_size = gxf_write_umf_media_description(pb, ctx);
+ ctx->umf_user_data_size = gxf_write_umf_user_data(pb, ctx);
+ ctx->umf_length = url_ftell(pb) - ctx->umf_start_offset;
+ return updatePacketSize(pb, pos);
+}
+
+#define GXF_NODELAY -5000
+
+static int gxf_write_header(AVFormatContext *s)
+{
+ ByteIOContext *pb = &s->pb;
+ GXFContext *gxf = s->priv_data;
+ int i;
+
+ gxf->fc = s;
+ gxf->flags |= 0x00080000; /* material is simple clip */
+ for (i = 0; i < s->nb_streams; ++i) {
+ AVStream *st = s->streams[i];
+ GXFStreamContext *sc = &gxf->streams[i];
+
+ sc->codec = st->codec;
+ sc->index = i;
+ sc->media_type = codec_get_tag(gxf_media_types, sc->codec->codec_id);
+ if (st->codec->codec_type == CODEC_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;
+ }
+ if (st->codec->sample_rate != 48000) {
+ av_log(s, AV_LOG_ERROR, "only 48000hz sampling rate is allowed\n");
+ return -1;
+ }
+ if (st->codec->channels != 1) {
+ av_log(s, AV_LOG_ERROR, "only mono tracks are allowed\n");
+ return -1;
+ }
+ sc->track_type = 2;
+ sc->sample_rate = st->codec->sample_rate;
+ av_set_pts_info(st, 64, 1, sc->sample_rate);
+ sc->sample_size = 16;
+ sc->frame_rate_index = -2;
+ sc->lines_index = -2;
+ sc->fields = -2;
+ gxf->audio_tracks++;
+ gxf->flags |= 0x04000000; /* audio is 16 bit pcm */
+ av_fifo_init(&sc->audio_buffer, 3*GXF_AUDIO_PACKET_SIZE);
+ } else if (sc->codec->codec_type == CODEC_TYPE_VIDEO) {
+ /* FIXME check from time_base ? */
+ if (sc->codec->height == 480 || sc->codec->height == 512) { /* NTSC or NTSC+VBI */
+ sc->frame_rate_index = 5;
+ sc->sample_rate = 60;
+ gxf->flags |= 0x00000080;
+ } else { /* assume PAL */
+ sc->frame_rate_index = 6;
+ sc->media_type++;
+ sc->sample_rate = 50;
+ gxf->flags |= 0x00000040;
+ }
+ gxf->sample_rate = sc->sample_rate;
+ av_set_pts_info(st, 64, 1, st->codec->time_base.den);
+ sc->dts_delay = GXF_NODELAY;
+ if (gxf_find_lines_index(sc) < 0)
+ sc->lines_index = -1;
+ sc->sample_size = st->codec->bit_rate;
+ sc->fields = 2; /* interlaced */
+ switch (sc->codec->codec_id) {
+ case CODEC_ID_MPEG2VIDEO:
+ sc->first_gop_closed = -1;
+ sc->track_type = 4;
+ gxf->mpeg_tracks++;
+ gxf->flags |= 0x00008000;
+ break;
+ case CODEC_ID_DVVIDEO:
+ if (sc->codec->pix_fmt == PIX_FMT_YUV422P) {
+ sc->media_type += 2;
+ sc->track_type = 6;
+ gxf->flags |= 0x00002000;
+ } else {
+ sc->track_type = 5;
+ gxf->flags |= 0x00001000;
+ }
+ break;
+ default:
+ av_log(s, AV_LOG_ERROR, "video codec not supported\n");
+ return -1;
+ }
+ }
+ }
+ gxf_write_map_packet(pb, gxf);
+ //gxf_write_flt_packet(pb, gxf);
+ gxf_write_umf_packet(pb, gxf);
+ put_flush_packet(pb);
+ return 0;
+}
+
+static int gxf_write_eos_packet(ByteIOContext *pb, GXFContext *ctx)
+{
+ offset_t pos = url_ftell(pb);
+
+ gxf_write_packet_header(pb, PKT_EOS);
+ return updatePacketSize(pb, pos);
+}
+
+static int gxf_write_trailer(AVFormatContext *s)
+{
+ ByteIOContext *pb = &s->pb;
+ GXFContext *gxf = s->priv_data;
+ offset_t end;
+ int i;
+
+ for (i = 0; i < s->nb_streams; ++i) {
+ if (s->streams[i]->codec->codec_type == CODEC_TYPE_AUDIO) {
+ av_fifo_free(&gxf->streams[i].audio_buffer);
+ }
+ if (s->streams[i]->codec->frame_number > gxf->nb_frames)
+ gxf->nb_frames = 2 * s->streams[i]->codec->frame_number;
+ }
+
+ gxf_write_eos_packet(pb, gxf);
+ end = url_ftell(pb);
+ url_fseek(pb, 0, SEEK_SET);
+ /* overwrite map and umf packets with new values */
+ gxf_write_map_packet(pb, gxf);
+ //gxf_write_flt_packet(pb, gxf);
+ gxf_write_umf_packet(pb, gxf);
+ url_fseek(pb, end, SEEK_SET);
+ return 0;
+}
+
+static int gxf_parse_mpeg_frame(GXFStreamContext *sc, const uint8_t *buf, int size)
+{
+ uint32_t c=-1;
+ int i;
+ for(i=0; i<size-4 && c!=0x100; i++){
+ c = (c<<8) + buf[i];
+ if(c == 0x1B8 && sc->first_gop_closed == -1) /* GOP start code */
+ sc->first_gop_closed= (buf[i+4]>>6)&1;
+ }
+ return (buf[i+1]>>3)&7;
+}
+
+static int gxf_write_media_preamble(ByteIOContext *pb, GXFContext *ctx, AVPacket *pkt, int size)
+{
+ GXFStreamContext *sc = &ctx->streams[pkt->stream_index];
+ int64_t dts = av_rescale(pkt->dts, ctx->sample_rate, sc->codec->time_base.den);
+
+ put_byte(pb, sc->media_type);
+ put_byte(pb, sc->index);
+ put_be32(pb, dts);
+ if (sc->codec->codec_type == CODEC_TYPE_AUDIO) {
+ put_be16(pb, 0);
+ put_be16(pb, size / 2);
+ } else if (sc->codec->codec_id == CODEC_ID_MPEG2VIDEO) {
+ int frame_type = gxf_parse_mpeg_frame(sc, pkt->data, pkt->size);
+ if (frame_type == FF_I_TYPE) {
+ put_byte(pb, 0x0d);
+ sc->iframes++;
+ } else if (frame_type == FF_B_TYPE) {
+ put_byte(pb, 0x0f);
+ sc->bframes++;
+ } else {
+ put_byte(pb, 0x0e);
+ sc->pframes++;
+ }
+ put_be24(pb, size);
+ } else if (sc->codec->codec_id == CODEC_ID_DVVIDEO) {
+ put_byte(pb, size / 4096);
+ put_be24(pb, 0);
+ } else
+ put_be32(pb, size);
+ put_be32(pb, dts);
+ put_byte(pb, 1); /* flags */
+ put_byte(pb, 0); /* reserved */
+ return 16;
+}
+
+static int gxf_write_media_packet(ByteIOContext *pb, GXFContext *ctx, AVPacket *pkt)
+{
+ GXFStreamContext *sc = &ctx->streams[pkt->stream_index];
+ offset_t pos = url_ftell(pb);
+ int padding = 0;
+
+ gxf_write_packet_header(pb, PKT_MEDIA);
+ if (sc->codec->codec_id == CODEC_ID_MPEG2VIDEO && pkt->size % 4) /* MPEG-2 frames must be padded */
+ padding = 4 - pkt->size % 4;
+ else if (sc->codec->codec_type == CODEC_TYPE_AUDIO)
+ padding = GXF_AUDIO_PACKET_SIZE - pkt->size;
+ gxf_write_media_preamble(pb, ctx, pkt, pkt->size + padding);
+ put_buffer(pb, pkt->data, pkt->size);
+ gxf_write_padding(pb, padding);
+ return updatePacketSize(pb, pos);
+}
+
+static int gxf_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ GXFContext *gxf = s->priv_data;
+
+ gxf_write_media_packet(&s->pb, gxf, pkt);
+ put_flush_packet(&s->pb);
+ return 0;
+}
+
+static int gxf_new_audio_packet(GXFContext *gxf, GXFStreamContext *sc, AVPacket *pkt, int flush)
+{
+ int size = flush ? av_fifo_size(&sc->audio_buffer) : GXF_AUDIO_PACKET_SIZE;
+
+ if (!size)
+ return 0;
+ av_new_packet(pkt, size);
+ av_fifo_read(&sc->audio_buffer, pkt->data, size);
+ pkt->stream_index = sc->index;
+ pkt->dts = sc->current_dts;
+ sc->current_dts += size / 2; /* we only support 16 bit pcm mono for now */
+ return size;
+}
+
+static int gxf_interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush)
+{
+ GXFContext *gxf = s->priv_data;
+ AVPacket new_pkt;
+ int i;
+
+ for (i = 0; i < s->nb_streams; i++) {
+ AVStream *st = s->streams[i];
+ GXFStreamContext *sc = &gxf->streams[i];
+ if (st->codec->codec_type == CODEC_TYPE_AUDIO) {
+ if (pkt && pkt->stream_index == i) {
+ av_fifo_write(&sc->audio_buffer, pkt->data, pkt->size);
+ pkt = NULL;
+ }
+ if (flush || av_fifo_size(&sc->audio_buffer) >= GXF_AUDIO_PACKET_SIZE) {
+ if (!pkt && gxf_new_audio_packet(gxf, sc, &new_pkt, flush) > 0) {
+ pkt = &new_pkt;
+ break; /* add pkt right now into list */
+ }
+ }
+ } else if (pkt && pkt->stream_index == i) {
+ if (sc->dts_delay == GXF_NODELAY) /* adjust dts if needed */
+ sc->dts_delay = pkt->dts;
+ pkt->dts -= sc->dts_delay;
+ }
+ }
+ return av_interleave_packet_per_dts(s, out, pkt, flush);
+}
+
+AVOutputFormat gxf_muxer = {
+ "gxf",
+ "GXF format",
+ NULL,
+ "gxf",
+ sizeof(GXFContext),
+ CODEC_ID_PCM_S16LE,
+ CODEC_ID_MPEG2VIDEO,
+ gxf_write_header,
+ gxf_write_packet,
+ gxf_write_trailer,
+ 0,
+ NULL,
+ gxf_interleave_packet,
+};
diff --git a/contrib/ffmpeg/libavformat/http.c b/contrib/ffmpeg/libavformat/http.c
new file mode 100644
index 000000000..e057d6efe
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/http.c
@@ -0,0 +1,354 @@
+/*
+ * HTTP protocol for ffmpeg client
+ * Copyright (c) 2000, 2001 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 "avformat.h"
+#include <unistd.h>
+#include "network.h"
+
+#include "base64.h"
+
+/* XXX: POST protocol is not completly implemented because ffmpeg use
+ only a subset of it */
+
+//#define DEBUG
+
+/* used for protocol handling */
+#define BUFFER_SIZE 1024
+#define URL_SIZE 4096
+#define MAX_REDIRECTS 8
+
+typedef struct {
+ URLContext *hd;
+ unsigned char buffer[BUFFER_SIZE], *buf_ptr, *buf_end;
+ int line_count;
+ int http_code;
+ offset_t off, filesize;
+ char location[URL_SIZE];
+} HTTPContext;
+
+static int http_connect(URLContext *h, const char *path, const char *hoststr,
+ const char *auth, int *new_location);
+static int http_write(URLContext *h, uint8_t *buf, int size);
+
+
+/* return non zero if error */
+static int http_open_cnx(URLContext *h)
+{
+ const char *path, *proxy_path;
+ char hostname[1024], hoststr[1024];
+ char auth[1024];
+ char path1[1024];
+ char buf[1024];
+ int port, use_proxy, err, location_changed = 0, redirects = 0;
+ HTTPContext *s = h->priv_data;
+ URLContext *hd = NULL;
+
+ proxy_path = getenv("http_proxy");
+ use_proxy = (proxy_path != NULL) && !getenv("no_proxy") &&
+ strstart(proxy_path, "http://", NULL);
+
+ /* 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 {
+ pstrcpy(hoststr, sizeof(hoststr), hostname);
+ }
+
+ if (use_proxy) {
+ url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port,
+ NULL, 0, proxy_path);
+ path = s->location;
+ } else {
+ if (path1[0] == '\0')
+ path = "/";
+ else
+ path = path1;
+ }
+ if (port < 0)
+ port = 80;
+
+ snprintf(buf, sizeof(buf), "tcp://%s:%d", hostname, port);
+ err = url_open(&hd, buf, URL_RDWR);
+ if (err < 0)
+ goto fail;
+
+ s->hd = hd;
+ if (http_connect(h, path, hoststr, auth, &location_changed) < 0)
+ goto fail;
+ if ((s->http_code == 302 || s->http_code == 303) && location_changed == 1) {
+ /* url moved, get next */
+ url_close(hd);
+ if (redirects++ >= MAX_REDIRECTS)
+ return AVERROR_IO;
+ location_changed = 0;
+ goto redo;
+ }
+ return 0;
+ fail:
+ if (hd)
+ url_close(hd);
+ return AVERROR_IO;
+}
+
+static int http_open(URLContext *h, const char *uri, int flags)
+{
+ HTTPContext *s;
+ int ret;
+
+ h->is_streamed = 1;
+
+ s = av_malloc(sizeof(HTTPContext));
+ if (!s) {
+ return AVERROR(ENOMEM);
+ }
+ h->priv_data = s;
+ s->filesize = -1;
+ s->off = 0;
+ pstrcpy (s->location, URL_SIZE, uri);
+
+ ret = http_open_cnx(h);
+ if (ret != 0)
+ av_free (s);
+ return ret;
+}
+static int http_getc(HTTPContext *s)
+{
+ int len;
+ if (s->buf_ptr >= s->buf_end) {
+ len = url_read(s->hd, s->buffer, BUFFER_SIZE);
+ if (len < 0) {
+ return AVERROR_IO;
+ } else if (len == 0) {
+ return -1;
+ } else {
+ s->buf_ptr = s->buffer;
+ s->buf_end = s->buffer + len;
+ }
+ }
+ return *s->buf_ptr++;
+}
+
+static int process_line(URLContext *h, char *line, int line_count,
+ int *new_location)
+{
+ HTTPContext *s = h->priv_data;
+ char *tag, *p;
+
+ /* end of header */
+ if (line[0] == '\0')
+ return 0;
+
+ p = line;
+ if (line_count == 0) {
+ while (!isspace(*p) && *p != '\0')
+ p++;
+ while (isspace(*p))
+ p++;
+ s->http_code = strtol(p, NULL, 10);
+#ifdef DEBUG
+ printf("http_code=%d\n", s->http_code);
+#endif
+ /* error codes are 4xx and 5xx */
+ if (s->http_code >= 400 && s->http_code < 600)
+ return -1;
+ } else {
+ while (*p != '\0' && *p != ':')
+ p++;
+ if (*p != ':')
+ return 1;
+
+ *p = '\0';
+ tag = line;
+ p++;
+ while (isspace(*p))
+ p++;
+ if (!strcmp(tag, "Location")) {
+ strcpy(s->location, p);
+ *new_location = 1;
+ } else if (!strcmp (tag, "Content-Length") && s->filesize == -1) {
+ s->filesize = atoll(p);
+ } else if (!strcmp (tag, "Content-Range")) {
+ /* "bytes $from-$to/$document_size" */
+ const char *slash;
+ if (!strncmp (p, "bytes ", 6)) {
+ p += 6;
+ s->off = atoll(p);
+ if ((slash = strchr(p, '/')) && strlen(slash) > 0)
+ s->filesize = atoll(slash+1);
+ }
+ h->is_streamed = 0; /* we _can_ in fact seek */
+ }
+ }
+ return 1;
+}
+
+static int http_connect(URLContext *h, const char *path, const char *hoststr,
+ const char *auth, int *new_location)
+{
+ HTTPContext *s = h->priv_data;
+ int post, err, ch;
+ char line[1024], *q;
+ char *auth_b64;
+ int auth_b64_len = strlen(auth)* 4 / 3 + 12;
+ offset_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, (uint8_t *)auth, strlen(auth));
+ 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"
+ "Connection: close\r\n"
+ "\r\n",
+ post ? "POST" : "GET",
+ path,
+ LIBAVFORMAT_IDENT,
+ s->off,
+ hoststr,
+ auth_b64);
+
+ av_freep(&auth_b64);
+ if (http_write(h, s->buffer, strlen(s->buffer)) < 0)
+ return AVERROR_IO;
+
+ /* init input buffer */
+ s->buf_ptr = s->buffer;
+ s->buf_end = s->buffer;
+ s->line_count = 0;
+ s->off = 0;
+ s->filesize = -1;
+ if (post) {
+ sleep(1);
+ return 0;
+ }
+
+ /* wait for header */
+ q = line;
+ for(;;) {
+ ch = http_getc(s);
+ if (ch < 0)
+ return AVERROR_IO;
+ if (ch == '\n') {
+ /* process line */
+ if (q > line && q[-1] == '\r')
+ q--;
+ *q = '\0';
+#ifdef DEBUG
+ printf("header='%s'\n", line);
+#endif
+ err = process_line(h, line, s->line_count, new_location);
+ if (err < 0)
+ return err;
+ if (err == 0)
+ break;
+ s->line_count++;
+ q = line;
+ } else {
+ if ((q - line) < sizeof(line) - 1)
+ *q++ = ch;
+ }
+ }
+
+ return (off == s->off) ? 0 : -1;
+}
+
+
+static int http_read(URLContext *h, uint8_t *buf, int size)
+{
+ HTTPContext *s = h->priv_data;
+ int len;
+
+ /* read bytes from input buffer first */
+ len = s->buf_end - s->buf_ptr;
+ if (len > 0) {
+ if (len > size)
+ len = size;
+ memcpy(buf, s->buf_ptr, len);
+ s->buf_ptr += len;
+ } else {
+ len = url_read(s->hd, buf, size);
+ }
+ if (len > 0)
+ s->off += len;
+ return len;
+}
+
+/* used only when posting data */
+static int http_write(URLContext *h, uint8_t *buf, int size)
+{
+ HTTPContext *s = h->priv_data;
+ return url_write(s->hd, buf, size);
+}
+
+static int http_close(URLContext *h)
+{
+ HTTPContext *s = h->priv_data;
+ url_close(s->hd);
+ av_free(s);
+ return 0;
+}
+
+static offset_t http_seek(URLContext *h, offset_t off, int whence)
+{
+ HTTPContext *s = h->priv_data;
+ URLContext *old_hd = s->hd;
+ offset_t old_off = s->off;
+
+ if (whence == AVSEEK_SIZE)
+ return s->filesize;
+ else if ((s->filesize == -1 && whence == SEEK_END) || h->is_streamed)
+ return -1;
+
+ /* we save the old context in case the seek fails */
+ s->hd = NULL;
+ if (whence == SEEK_CUR)
+ off += s->off;
+ else if (whence == SEEK_END)
+ off += s->filesize;
+ s->off = off;
+
+ /* if it fails, continue on old connection */
+ if (http_open_cnx(h) < 0) {
+ s->hd = old_hd;
+ s->off = old_off;
+ return -1;
+ }
+ url_close(old_hd);
+ return off;
+}
+
+URLProtocol http_protocol = {
+ "http",
+ http_open,
+ http_read,
+ http_write,
+ http_seek,
+ http_close,
+};
diff --git a/contrib/ffmpeg/libavformat/idcin.c b/contrib/ffmpeg/libavformat/idcin.c
new file mode 100644
index 000000000..e2c92f3b4
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/idcin.c
@@ -0,0 +1,301 @@
+/*
+ * Id Quake II CIN File Demuxer
+ * Copyright (c) 2003 The ffmpeg Project
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file idcin.c
+ * 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/
+ *
+ * CIN is a somewhat quirky and ill-defined format. Here are some notes
+ * for anyone trying to understand the technical details of this format:
+ *
+ * The format has no definite file signature. This is problematic for a
+ * general-purpose media player that wants to automatically detect file
+ * types. However, a CIN file does start with 5 32-bit numbers that
+ * specify audio and video parameters. This demuxer gets around the lack
+ * of file signature by performing sanity checks on those parameters.
+ * Probabalistically, this is a reasonable solution since the number of
+ * valid combinations of the 5 parameters is a very small subset of the
+ * total 160-bit number space.
+ *
+ * Refer to the function idcin_probe() for the precise A/V parameters
+ * that this demuxer allows.
+ *
+ * Next, each audio and video frame has a duration of 1/14 sec. If the
+ * audio sample rate is a multiple of the common frequency 22050 Hz it will
+ * divide evenly by 14. However, if the sample rate is 11025 Hz:
+ * 11025 (samples/sec) / 14 (frames/sec) = 787.5 (samples/frame)
+ * The way the CIN stores audio in this case is by storing 787 sample
+ * frames in the first audio frame and 788 sample frames in the second
+ * audio frame. Therefore, the total number of bytes in an audio frame
+ * is given as:
+ * audio frame #0: 787 * (bytes/sample) * (# channels) bytes in frame
+ * audio frame #1: 788 * (bytes/sample) * (# channels) bytes in frame
+ * audio frame #2: 787 * (bytes/sample) * (# channels) bytes in frame
+ * audio frame #3: 788 * (bytes/sample) * (# channels) bytes in frame
+ *
+ * Finally, not all Id CIN creation tools agree on the resolution of the
+ * color palette, apparently. Some creation tools specify red, green, and
+ * blue palette components in terms of 6-bit VGA color DAC values which
+ * range from 0..63. Other tools specify the RGB components as full 8-bit
+ * values that range from 0..255. Since there are no markers in the file to
+ * differentiate between the two variants, this demuxer uses the following
+ * heuristic:
+ * - load the 768 palette bytes from disk
+ * - assume that they will need to be shifted left by 2 bits to
+ * transform them from 6-bit values to 8-bit values
+ * - scan through all 768 palette bytes
+ * - if any bytes exceed 63, do not shift the bytes at all before
+ * transmitting them to the video decoder
+ */
+
+#include "avformat.h"
+
+#define HUFFMAN_TABLE_SIZE (64 * 1024)
+#define FRAME_PTS_INC (90000 / 14)
+
+typedef struct IdcinDemuxContext {
+ int video_stream_index;
+ int audio_stream_index;
+ int audio_chunk_size1;
+ int audio_chunk_size2;
+
+ /* demux state variables */
+ int current_audio_chunk;
+ int next_chunk_is_video;
+ int audio_present;
+
+ int64_t pts;
+
+ AVPaletteControl palctrl;
+} IdcinDemuxContext;
+
+static int idcin_probe(AVProbeData *p)
+{
+ unsigned int number;
+
+ /*
+ * This is what you could call a "probabilistic" file check: Id CIN
+ * files don't have a definite file signature. In lieu of such a marker,
+ * perform sanity checks on the 5 32-bit header fields:
+ * width, height: greater than 0, less than or equal to 1024
+ * audio sample rate: greater than or equal to 8000, less than or
+ * equal to 48000, or 0 for no audio
+ * audio sample width (bytes/sample): 0 for no audio, or 1 or 2
+ * audio channels: 0 for no audio, or 1 or 2
+ */
+
+ /* cannot proceed without 20 bytes */
+ if (p->buf_size < 20)
+ return 0;
+
+ /* check the video width */
+ number = AV_RL32(&p->buf[0]);
+ if ((number == 0) || (number > 1024))
+ return 0;
+
+ /* check the video height */
+ number = AV_RL32(&p->buf[4]);
+ if ((number == 0) || (number > 1024))
+ return 0;
+
+ /* check the audio sample rate */
+ number = AV_RL32(&p->buf[8]);
+ if ((number != 0) && ((number < 8000) | (number > 48000)))
+ return 0;
+
+ /* check the audio bytes/sample */
+ number = AV_RL32(&p->buf[12]);
+ if (number > 2)
+ return 0;
+
+ /* check the audio channels */
+ number = AV_RL32(&p->buf[16]);
+ if (number > 2)
+ return 0;
+
+ /* return half certainly since this check is a bit sketchy */
+ return AVPROBE_SCORE_MAX / 2;
+}
+
+static int idcin_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ ByteIOContext *pb = &s->pb;
+ IdcinDemuxContext *idcin = (IdcinDemuxContext *)s->priv_data;
+ AVStream *st;
+ unsigned int width, height;
+ unsigned int sample_rate, bytes_per_sample, channels;
+
+ /* get the 5 header parameters */
+ width = get_le32(pb);
+ height = get_le32(pb);
+ sample_rate = get_le32(pb);
+ bytes_per_sample = get_le32(pb);
+ channels = get_le32(pb);
+
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+ av_set_pts_info(st, 33, 1, 90000);
+ idcin->video_stream_index = st->index;
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ st->codec->codec_id = CODEC_ID_IDCIN;
+ st->codec->codec_tag = 0; /* no fourcc */
+ st->codec->width = width;
+ st->codec->height = height;
+
+ /* load up the Huffman tables into extradata */
+ st->codec->extradata_size = HUFFMAN_TABLE_SIZE;
+ st->codec->extradata = av_malloc(HUFFMAN_TABLE_SIZE);
+ if (get_buffer(pb, st->codec->extradata, HUFFMAN_TABLE_SIZE) !=
+ HUFFMAN_TABLE_SIZE)
+ return AVERROR_IO;
+ /* save a reference in order to transport the palette */
+ st->codec->palctrl = &idcin->palctrl;
+
+ /* if sample rate is 0, assume no audio */
+ if (sample_rate) {
+ idcin->audio_present = 1;
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+ av_set_pts_info(st, 33, 1, 90000);
+ idcin->audio_stream_index = st->index;
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_tag = 1;
+ st->codec->channels = channels;
+ st->codec->sample_rate = sample_rate;
+ st->codec->bits_per_sample = bytes_per_sample * 8;
+ st->codec->bit_rate = sample_rate * bytes_per_sample * 8 * channels;
+ st->codec->block_align = bytes_per_sample * channels;
+ if (bytes_per_sample == 1)
+ st->codec->codec_id = CODEC_ID_PCM_U8;
+ else
+ st->codec->codec_id = CODEC_ID_PCM_S16LE;
+
+ if (sample_rate % 14 != 0) {
+ idcin->audio_chunk_size1 = (sample_rate / 14) *
+ bytes_per_sample * channels;
+ idcin->audio_chunk_size2 = (sample_rate / 14 + 1) *
+ bytes_per_sample * channels;
+ } else {
+ idcin->audio_chunk_size1 = idcin->audio_chunk_size2 =
+ (sample_rate / 14) * bytes_per_sample * channels;
+ }
+ idcin->current_audio_chunk = 0;
+ } else
+ idcin->audio_present = 1;
+
+ idcin->next_chunk_is_video = 1;
+ idcin->pts = 0;
+
+ return 0;
+}
+
+static int idcin_read_packet(AVFormatContext *s,
+ AVPacket *pkt)
+{
+ int ret;
+ unsigned int command;
+ unsigned int chunk_size;
+ IdcinDemuxContext *idcin = (IdcinDemuxContext *)s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ int i;
+ int palette_scale;
+ unsigned char r, g, b;
+ unsigned char palette_buffer[768];
+
+ if (url_feof(&s->pb))
+ return AVERROR_IO;
+
+ if (idcin->next_chunk_is_video) {
+ command = get_le32(pb);
+ if (command == 2) {
+ return AVERROR_IO;
+ } else if (command == 1) {
+ /* trigger a palette change */
+ idcin->palctrl.palette_changed = 1;
+ if (get_buffer(pb, palette_buffer, 768) != 768)
+ return AVERROR_IO;
+ /* scale the palette as necessary */
+ palette_scale = 2;
+ for (i = 0; i < 768; i++)
+ if (palette_buffer[i] > 63) {
+ palette_scale = 0;
+ break;
+ }
+
+ for (i = 0; i < 256; i++) {
+ r = palette_buffer[i * 3 ] << palette_scale;
+ g = palette_buffer[i * 3 + 1] << palette_scale;
+ b = palette_buffer[i * 3 + 2] << palette_scale;
+ idcin->palctrl.palette[i] = (r << 16) | (g << 8) | (b);
+ }
+ }
+
+ chunk_size = get_le32(pb);
+ /* skip the number of decoded bytes (always equal to width * height) */
+ url_fseek(pb, 4, SEEK_CUR);
+ chunk_size -= 4;
+ ret= av_get_packet(pb, pkt, chunk_size);
+ if (ret != chunk_size)
+ return AVERROR_IO;
+ pkt->stream_index = idcin->video_stream_index;
+ pkt->pts = idcin->pts;
+ } else {
+ /* send out the audio chunk */
+ if (idcin->current_audio_chunk)
+ chunk_size = idcin->audio_chunk_size2;
+ else
+ chunk_size = idcin->audio_chunk_size1;
+ ret= av_get_packet(pb, pkt, chunk_size);
+ if (ret != chunk_size)
+ return AVERROR_IO;
+ pkt->stream_index = idcin->audio_stream_index;
+ pkt->pts = idcin->pts;
+
+ idcin->current_audio_chunk ^= 1;
+ idcin->pts += FRAME_PTS_INC;
+ }
+
+ if (idcin->audio_present)
+ idcin->next_chunk_is_video ^= 1;
+
+ return ret;
+}
+
+static int idcin_read_close(AVFormatContext *s)
+{
+
+ return 0;
+}
+
+AVInputFormat idcin_demuxer = {
+ "idcin",
+ "Id CIN format",
+ sizeof(IdcinDemuxContext),
+ idcin_probe,
+ idcin_read_header,
+ idcin_read_packet,
+ idcin_read_close,
+};
diff --git a/contrib/ffmpeg/libavformat/idroq.c b/contrib/ffmpeg/libavformat/idroq.c
new file mode 100644
index 000000000..b8ee176ab
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/idroq.c
@@ -0,0 +1,291 @@
+/*
+ * Id RoQ (.roq) File Demuxer
+ * Copyright (c) 2003 The ffmpeg Project
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file idroq.c
+ * Id RoQ format file demuxer
+ * by Mike Melanson (melanson@pcisys.net)
+ * for more information on the .roq file format, visit:
+ * http://www.csse.monash.edu.au/~timf/
+ */
+
+#include "avformat.h"
+
+#define RoQ_MAGIC_NUMBER 0x1084
+#define RoQ_CHUNK_PREAMBLE_SIZE 8
+#define RoQ_AUDIO_SAMPLE_RATE 22050
+#define RoQ_CHUNKS_TO_SCAN 30
+
+#define RoQ_INFO 0x1001
+#define RoQ_QUAD_CODEBOOK 0x1002
+#define RoQ_QUAD_VQ 0x1011
+#define RoQ_SOUND_MONO 0x1020
+#define RoQ_SOUND_STEREO 0x1021
+
+typedef struct RoqDemuxContext {
+
+ int width;
+ int height;
+ int audio_channels;
+ int framerate;
+ int frame_pts_inc;
+
+ int video_stream_index;
+ int audio_stream_index;
+
+ int64_t video_pts;
+ unsigned int audio_frame_count;
+
+} RoqDemuxContext;
+
+static int roq_probe(AVProbeData *p)
+{
+ if (p->buf_size < 6)
+ return 0;
+
+ if ((AV_RL16(&p->buf[0]) != RoQ_MAGIC_NUMBER) ||
+ (AV_RL32(&p->buf[2]) != 0xFFFFFFFF))
+ return 0;
+
+ return AVPROBE_SCORE_MAX;
+}
+
+static int roq_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ RoqDemuxContext *roq = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ AVStream *st;
+ unsigned char preamble[RoQ_CHUNK_PREAMBLE_SIZE];
+ int i;
+ unsigned int chunk_size;
+ unsigned int chunk_type;
+
+ /* get the main header */
+ if (get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) !=
+ RoQ_CHUNK_PREAMBLE_SIZE)
+ return AVERROR_IO;
+ roq->framerate = AV_RL16(&preamble[6]);
+ roq->frame_pts_inc = 90000 / roq->framerate;
+
+ /* init private context parameters */
+ roq->width = roq->height = roq->audio_channels = roq->video_pts =
+ roq->audio_frame_count = 0;
+
+ /* scan the first n chunks searching for A/V parameters */
+ for (i = 0; i < RoQ_CHUNKS_TO_SCAN; i++) {
+ if (get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) !=
+ RoQ_CHUNK_PREAMBLE_SIZE)
+ return AVERROR_IO;
+
+ chunk_type = AV_RL16(&preamble[0]);
+ chunk_size = AV_RL32(&preamble[2]);
+
+ switch (chunk_type) {
+
+ case RoQ_INFO:
+ /* fetch the width and height; reuse the preamble bytes */
+ if (get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) !=
+ RoQ_CHUNK_PREAMBLE_SIZE)
+ return AVERROR_IO;
+ roq->width = AV_RL16(&preamble[0]);
+ roq->height = AV_RL16(&preamble[2]);
+ break;
+
+ case RoQ_QUAD_CODEBOOK:
+ case RoQ_QUAD_VQ:
+ /* ignore during this scan */
+ url_fseek(pb, chunk_size, SEEK_CUR);
+ break;
+
+ case RoQ_SOUND_MONO:
+ roq->audio_channels = 1;
+ url_fseek(pb, chunk_size, SEEK_CUR);
+ break;
+
+ case RoQ_SOUND_STEREO:
+ roq->audio_channels = 2;
+ url_fseek(pb, chunk_size, SEEK_CUR);
+ break;
+
+ default:
+ av_log(s, AV_LOG_ERROR, " unknown RoQ chunk type (%04X)\n", AV_RL16(&preamble[0]));
+ return AVERROR_INVALIDDATA;
+ break;
+ }
+
+ /* if all necessary parameters have been gathered, exit early */
+ if ((roq->width && roq->height) && roq->audio_channels)
+ break;
+ }
+
+ /* seek back to the first chunk */
+ url_fseek(pb, RoQ_CHUNK_PREAMBLE_SIZE, SEEK_SET);
+
+ /* initialize the decoders */
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+ /* set the pts reference (1 pts = 1/90000) */
+ av_set_pts_info(st, 33, 1, 90000);
+ roq->video_stream_index = st->index;
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ st->codec->codec_id = CODEC_ID_ROQ;
+ st->codec->codec_tag = 0; /* no fourcc */
+ st->codec->width = roq->width;
+ st->codec->height = roq->height;
+
+ if (roq->audio_channels) {
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+ av_set_pts_info(st, 33, 1, 90000);
+ roq->audio_stream_index = st->index;
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_id = CODEC_ID_ROQ_DPCM;
+ st->codec->codec_tag = 0; /* no tag */
+ st->codec->channels = roq->audio_channels;
+ st->codec->sample_rate = RoQ_AUDIO_SAMPLE_RATE;
+ st->codec->bits_per_sample = 16;
+ st->codec->bit_rate = st->codec->channels * st->codec->sample_rate *
+ st->codec->bits_per_sample;
+ st->codec->block_align = st->codec->channels * st->codec->bits_per_sample;
+ }
+
+ return 0;
+}
+
+static int roq_read_packet(AVFormatContext *s,
+ AVPacket *pkt)
+{
+ RoqDemuxContext *roq = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ int ret = 0;
+ unsigned int chunk_size;
+ unsigned int chunk_type;
+ unsigned int codebook_size;
+ unsigned char preamble[RoQ_CHUNK_PREAMBLE_SIZE];
+ int packet_read = 0;
+ offset_t codebook_offset;
+
+ while (!packet_read) {
+
+ if (url_feof(&s->pb))
+ return AVERROR_IO;
+
+ /* get the next chunk preamble */
+ if ((ret = get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE)) !=
+ RoQ_CHUNK_PREAMBLE_SIZE)
+ return AVERROR_IO;
+
+ chunk_type = AV_RL16(&preamble[0]);
+ chunk_size = AV_RL32(&preamble[2]);
+ if(chunk_size > INT_MAX)
+ return AVERROR_INVALIDDATA;
+
+ switch (chunk_type) {
+
+ case RoQ_INFO:
+ /* don't care about this chunk anymore */
+ url_fseek(pb, RoQ_CHUNK_PREAMBLE_SIZE, SEEK_CUR);
+ break;
+
+ case RoQ_QUAD_CODEBOOK:
+ /* packet needs to contain both this codebook and next VQ chunk */
+ codebook_offset = url_ftell(pb) - RoQ_CHUNK_PREAMBLE_SIZE;
+ codebook_size = chunk_size;
+ url_fseek(pb, codebook_size, SEEK_CUR);
+ if (get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) !=
+ RoQ_CHUNK_PREAMBLE_SIZE)
+ return AVERROR_IO;
+ chunk_size = AV_RL32(&preamble[2]) + RoQ_CHUNK_PREAMBLE_SIZE * 2 +
+ codebook_size;
+
+ /* rewind */
+ url_fseek(pb, codebook_offset, SEEK_SET);
+
+ /* load up the packet */
+ ret= av_get_packet(pb, pkt, chunk_size);
+ if (ret != chunk_size)
+ return AVERROR_IO;
+ pkt->stream_index = roq->video_stream_index;
+ pkt->pts = roq->video_pts;
+
+ roq->video_pts += roq->frame_pts_inc;
+ packet_read = 1;
+ break;
+
+ case RoQ_SOUND_MONO:
+ case RoQ_SOUND_STEREO:
+ case RoQ_QUAD_VQ:
+ /* load up the packet */
+ if (av_new_packet(pkt, chunk_size + RoQ_CHUNK_PREAMBLE_SIZE))
+ return AVERROR_IO;
+ /* copy over preamble */
+ memcpy(pkt->data, preamble, RoQ_CHUNK_PREAMBLE_SIZE);
+
+ if (chunk_type == RoQ_QUAD_VQ) {
+ pkt->stream_index = roq->video_stream_index;
+ pkt->pts = roq->video_pts;
+ roq->video_pts += roq->frame_pts_inc;
+ } else {
+ pkt->stream_index = roq->audio_stream_index;
+ pkt->pts = roq->audio_frame_count;
+ pkt->pts *= 90000;
+ pkt->pts /= RoQ_AUDIO_SAMPLE_RATE;
+ roq->audio_frame_count += (chunk_size / roq->audio_channels);
+ }
+
+ pkt->pos= url_ftell(pb);
+ ret = get_buffer(pb, pkt->data + RoQ_CHUNK_PREAMBLE_SIZE,
+ chunk_size);
+ if (ret != chunk_size)
+ ret = AVERROR_IO;
+
+ packet_read = 1;
+ break;
+
+ default:
+ av_log(s, AV_LOG_ERROR, " unknown RoQ chunk (%04X)\n", chunk_type);
+ return AVERROR_INVALIDDATA;
+ break;
+ }
+ }
+
+ return ret;
+}
+
+static int roq_read_close(AVFormatContext *s)
+{
+// RoqDemuxContext *roq = (RoqDemuxContext *)s->priv_data;
+
+ return 0;
+}
+
+AVInputFormat roq_demuxer = {
+ "RoQ",
+ "Id RoQ format",
+ sizeof(RoqDemuxContext),
+ roq_probe,
+ roq_read_header,
+ roq_read_packet,
+ roq_read_close,
+};
diff --git a/contrib/ffmpeg/libavformat/img2.c b/contrib/ffmpeg/libavformat/img2.c
new file mode 100644
index 000000000..fa67ee742
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/img2.c
@@ -0,0 +1,428 @@
+/*
+ * Image format
+ * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
+ * Copyright (c) 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
+ */
+#include "avformat.h"
+
+typedef struct {
+ int img_first;
+ int img_last;
+ int img_number;
+ int img_count;
+ int is_pipe;
+ char path[1024];
+} VideoData;
+
+typedef struct {
+ enum CodecID id;
+ const char *str;
+} IdStrMap;
+
+static const IdStrMap img_tags[] = {
+ { CODEC_ID_MJPEG , "jpeg"},
+ { CODEC_ID_MJPEG , "jpg"},
+ { CODEC_ID_LJPEG , "ljpg"},
+ { CODEC_ID_PNG , "png"},
+ { CODEC_ID_PPM , "ppm"},
+ { CODEC_ID_PGM , "pgm"},
+ { CODEC_ID_PGMYUV , "pgmyuv"},
+ { CODEC_ID_PBM , "pbm"},
+ { CODEC_ID_PAM , "pam"},
+ { CODEC_ID_MPEG1VIDEO, "mpg1-img"},
+ { CODEC_ID_MPEG2VIDEO, "mpg2-img"},
+ { CODEC_ID_MPEG4 , "mpg4-img"},
+ { CODEC_ID_FFV1 , "ffv1-img"},
+ { CODEC_ID_RAWVIDEO , "y"},
+ { CODEC_ID_BMP , "bmp"},
+ { CODEC_ID_GIF , "gif"},
+ { CODEC_ID_TARGA , "tga"},
+ { CODEC_ID_TIFF , "tiff"},
+ {0, NULL}
+};
+
+static int sizes[][2] = {
+ { 640, 480 },
+ { 720, 480 },
+ { 720, 576 },
+ { 352, 288 },
+ { 352, 240 },
+ { 160, 128 },
+ { 512, 384 },
+ { 640, 352 },
+ { 640, 240 },
+};
+
+static int infer_size(int *width_ptr, int *height_ptr, int size)
+{
+ int i;
+
+ for(i=0;i<sizeof(sizes)/sizeof(sizes[0]);i++) {
+ if ((sizes[i][0] * sizes[i][1]) == size) {
+ *width_ptr = sizes[i][0];
+ *height_ptr = sizes[i][1];
+ return 0;
+ }
+ }
+ return -1;
+}
+static enum CodecID av_str2id(const IdStrMap *tags, const char *str)
+{
+ str= strrchr(str, '.');
+ if(!str) return CODEC_ID_NONE;
+ str++;
+
+ while (tags->id) {
+ int i;
+ for(i=0; toupper(tags->str[i]) == toupper(str[i]); i++){
+ if(tags->str[i]==0 && str[i]==0)
+ return tags->id;
+ }
+
+ tags++;
+ }
+ return CODEC_ID_NONE;
+}
+
+/* return -1 if no image found */
+static int find_image_range(int *pfirst_index, int *plast_index,
+ const char *path)
+{
+ char buf[1024];
+ int range, last_index, range1, first_index;
+
+ /* find the first image */
+ for(first_index = 0; first_index < 5; first_index++) {
+ if (av_get_frame_filename(buf, sizeof(buf), path, first_index) < 0){
+ *pfirst_index =
+ *plast_index = 1;
+ return 0;
+ }
+ if (url_exist(buf))
+ break;
+ }
+ if (first_index == 5)
+ goto fail;
+
+ /* find the last image */
+ last_index = first_index;
+ for(;;) {
+ range = 0;
+ for(;;) {
+ if (!range)
+ range1 = 1;
+ else
+ range1 = 2 * range;
+ if (av_get_frame_filename(buf, sizeof(buf), path,
+ last_index + range1) < 0)
+ goto fail;
+ if (!url_exist(buf))
+ break;
+ range = range1;
+ /* just in case... */
+ if (range >= (1 << 30))
+ goto fail;
+ }
+ /* we are sure than image last_index + range exists */
+ if (!range)
+ break;
+ last_index += range;
+ }
+ *pfirst_index = first_index;
+ *plast_index = last_index;
+ return 0;
+ fail:
+ return -1;
+}
+
+
+static int image_probe(AVProbeData *p)
+{
+ if (p->filename && av_str2id(img_tags, p->filename)) {
+ if (av_filename_number_test(p->filename))
+ return AVPROBE_SCORE_MAX;
+ else
+ return AVPROBE_SCORE_MAX/2;
+ }
+ return 0;
+}
+
+enum CodecID av_guess_image2_codec(const char *filename){
+ return av_str2id(img_tags, filename);
+}
+
+static int img_read_header(AVFormatContext *s1, AVFormatParameters *ap)
+{
+ VideoData *s = s1->priv_data;
+ int first_index, last_index;
+ AVStream *st;
+
+ s1->ctx_flags |= AVFMTCTX_NOHEADER;
+
+ st = av_new_stream(s1, 0);
+ if (!st) {
+ return AVERROR(ENOMEM);
+ }
+
+ pstrcpy(s->path, sizeof(s->path), s1->filename);
+ s->img_number = 0;
+ s->img_count = 0;
+
+ /* find format */
+ if (s1->iformat->flags & AVFMT_NOFILE)
+ s->is_pipe = 0;
+ else{
+ s->is_pipe = 1;
+ st->need_parsing= 1;
+ }
+
+ if (!ap->time_base.num) {
+ av_set_pts_info(st, 60, 1, 25);
+ } else {
+ av_set_pts_info(st, 60, ap->time_base.num, ap->time_base.den);
+ }
+
+ if(ap->width && ap->height){
+ st->codec->width = ap->width;
+ st->codec->height= ap->height;
+ }
+
+ if (!s->is_pipe) {
+ if (find_image_range(&first_index, &last_index, s->path) < 0)
+ return AVERROR_IO;
+ s->img_first = first_index;
+ s->img_last = last_index;
+ s->img_number = first_index;
+ /* compute duration */
+ st->start_time = 0;
+ 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;
+ }else{
+ st->codec->codec_type = CODEC_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)
+ st->codec->pix_fmt = ap->pix_fmt;
+
+ return 0;
+}
+
+static int img_read_packet(AVFormatContext *s1, AVPacket *pkt)
+{
+ VideoData *s = s1->priv_data;
+ char filename[1024];
+ int i;
+ int size[3]={0}, ret[3]={0};
+ ByteIOContext f1[3], *f[3]= {&f1[0], &f1[1], &f1[2]};
+ AVCodecContext *codec= s1->streams[0]->codec;
+
+ if (!s->is_pipe) {
+ /* loop over input */
+ if (s1->loop_input && s->img_number > s->img_last) {
+ s->img_number = s->img_first;
+ }
+ if (av_get_frame_filename(filename, sizeof(filename),
+ s->path, s->img_number)<0 && s->img_number > 1)
+ return AVERROR_IO;
+ for(i=0; i<3; i++){
+ if (url_fopen(f[i], filename, URL_RDONLY) < 0)
+ return AVERROR_IO;
+ size[i]= url_fsize(f[i]);
+
+ if(codec->codec_id != CODEC_ID_RAWVIDEO)
+ break;
+ filename[ strlen(filename) - 1 ]= 'U' + i;
+ }
+
+ if(codec->codec_id == CODEC_ID_RAWVIDEO && !codec->width)
+ infer_size(&codec->width, &codec->height, size[0]);
+ } else {
+ f[0] = &s1->pb;
+ if (url_feof(f[0]))
+ return AVERROR_IO;
+ size[0]= 4096;
+ }
+
+ av_new_packet(pkt, size[0] + size[1] + size[2]);
+ pkt->stream_index = 0;
+ pkt->flags |= PKT_FLAG_KEY;
+
+ pkt->size= 0;
+ for(i=0; i<3; i++){
+ if(size[i]){
+ ret[i]= get_buffer(f[i], pkt->data + pkt->size, size[i]);
+ if (!s->is_pipe)
+ url_fclose(f[i]);
+ if(ret[i]>0)
+ pkt->size += ret[i];
+ }
+ }
+
+ if (ret[0] <= 0 || ret[1]<0 || ret[2]<0) {
+ av_free_packet(pkt);
+ return AVERROR_IO; /* signal EOF */
+ } else {
+ s->img_count++;
+ s->img_number++;
+ return 0;
+ }
+}
+
+static int img_read_close(AVFormatContext *s1)
+{
+ return 0;
+}
+
+#ifdef CONFIG_MUXERS
+/******************************************************/
+/* image output */
+
+static int img_write_header(AVFormatContext *s)
+{
+ VideoData *img = s->priv_data;
+
+ img->img_number = 1;
+ pstrcpy(img->path, sizeof(img->path), s->filename);
+
+ /* find format */
+ if (s->oformat->flags & AVFMT_NOFILE)
+ img->is_pipe = 0;
+ else
+ img->is_pipe = 1;
+
+ return 0;
+}
+
+static int img_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ VideoData *img = s->priv_data;
+ ByteIOContext pb1[3], *pb[3]= {&pb1[0], &pb1[1], &pb1[2]};
+ char filename[1024];
+ AVCodecContext *codec= s->streams[ pkt->stream_index ]->codec;
+ int i;
+
+ if (!img->is_pipe) {
+ if (av_get_frame_filename(filename, sizeof(filename),
+ img->path, img->img_number) < 0 && img->img_number>1)
+ return AVERROR_IO;
+ for(i=0; i<3; i++){
+ if (url_fopen(pb[i], filename, URL_WRONLY) < 0)
+ return AVERROR_IO;
+
+ if(codec->codec_id != CODEC_ID_RAWVIDEO)
+ break;
+ filename[ strlen(filename) - 1 ]= 'U' + i;
+ }
+ } else {
+ pb[0] = &s->pb;
+ }
+
+ if(codec->codec_id == CODEC_ID_RAWVIDEO){
+ int ysize = codec->width * codec->height;
+ put_buffer(pb[0], pkt->data , ysize);
+ put_buffer(pb[1], pkt->data + ysize, (pkt->size - ysize)/2);
+ put_buffer(pb[2], pkt->data + ysize +(pkt->size - ysize)/2, (pkt->size - ysize)/2);
+ put_flush_packet(pb[1]);
+ put_flush_packet(pb[2]);
+ url_fclose(pb[1]);
+ url_fclose(pb[2]);
+ }else{
+ put_buffer(pb[0], pkt->data, pkt->size);
+ }
+ put_flush_packet(pb[0]);
+ if (!img->is_pipe) {
+ url_fclose(pb[0]);
+ }
+
+ img->img_number++;
+ return 0;
+}
+
+static int img_write_trailer(AVFormatContext *s)
+{
+ return 0;
+}
+
+#endif /* CONFIG_MUXERS */
+
+/* input */
+#ifdef CONFIG_IMAGE2_DEMUXER
+AVInputFormat image2_demuxer = {
+ "image2",
+ "image2 sequence",
+ sizeof(VideoData),
+ image_probe,
+ img_read_header,
+ img_read_packet,
+ img_read_close,
+ NULL,
+ NULL,
+ AVFMT_NOFILE,
+};
+#endif
+#ifdef CONFIG_IMAGE2PIPE_DEMUXER
+AVInputFormat image2pipe_demuxer = {
+ "image2pipe",
+ "piped image2 sequence",
+ sizeof(VideoData),
+ NULL, /* no probe */
+ img_read_header,
+ img_read_packet,
+ img_read_close,
+ NULL,
+};
+#endif
+
+/* output */
+#ifdef CONFIG_IMAGE2_MUXER
+AVOutputFormat image2_muxer = {
+ "image2",
+ "image2 sequence",
+ "",
+ "",
+ sizeof(VideoData),
+ CODEC_ID_NONE,
+ CODEC_ID_MJPEG,
+ img_write_header,
+ img_write_packet,
+ img_write_trailer,
+ AVFMT_NOFILE,
+};
+#endif
+#ifdef CONFIG_IMAGE2PIPE_MUXER
+AVOutputFormat image2pipe_muxer = {
+ "image2pipe",
+ "piped image2 sequence",
+ "",
+ "",
+ sizeof(VideoData),
+ CODEC_ID_NONE,
+ CODEC_ID_MJPEG,
+ img_write_header,
+ img_write_packet,
+ img_write_trailer,
+};
+#endif
diff --git a/contrib/ffmpeg/libavformat/ipmovie.c b/contrib/ffmpeg/libavformat/ipmovie.c
new file mode 100644
index 000000000..975bfd36b
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/ipmovie.c
@@ -0,0 +1,627 @@
+/*
+ * Interplay MVE File Demuxer
+ * Copyright (c) 2003 The ffmpeg Project
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file ipmovie.c
+ * Interplay MVE file demuxer
+ * by Mike Melanson (melanson@pcisys.net)
+ * For more information regarding the Interplay MVE file format, visit:
+ * http://www.pcisys.net/~melanson/codecs/
+ * The aforementioned site also contains a command line utility for parsing
+ * IP MVE files so that you can get a good idea of the typical structure of
+ * such files. This demuxer is not the best example to use if you are trying
+ * to write your own as it uses a rather roundabout approach for splitting
+ * up and sending out the chunks.
+ */
+
+#include "avformat.h"
+
+/* debugging support: #define DEBUG_IPMOVIE as non-zero to see extremely
+ * verbose information about the demux process */
+#define DEBUG_IPMOVIE 0
+
+#if DEBUG_IPMOVIE
+#define debug_ipmovie printf
+#else
+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
+
+#define CHUNK_INIT_AUDIO 0x0000
+#define CHUNK_AUDIO_ONLY 0x0001
+#define CHUNK_INIT_VIDEO 0x0002
+#define CHUNK_VIDEO 0x0003
+#define CHUNK_SHUTDOWN 0x0004
+#define CHUNK_END 0x0005
+/* these last types are used internally */
+#define CHUNK_DONE 0xFFFC
+#define CHUNK_NOMEM 0xFFFD
+#define CHUNK_EOF 0xFFFE
+#define CHUNK_BAD 0xFFFF
+
+#define OPCODE_END_OF_STREAM 0x00
+#define OPCODE_END_OF_CHUNK 0x01
+#define OPCODE_CREATE_TIMER 0x02
+#define OPCODE_INIT_AUDIO_BUFFERS 0x03
+#define OPCODE_START_STOP_AUDIO 0x04
+#define OPCODE_INIT_VIDEO_BUFFERS 0x05
+#define OPCODE_UNKNOWN_06 0x06
+#define OPCODE_SEND_BUFFER 0x07
+#define OPCODE_AUDIO_FRAME 0x08
+#define OPCODE_SILENCE_FRAME 0x09
+#define OPCODE_INIT_VIDEO_MODE 0x0A
+#define OPCODE_CREATE_GRADIENT 0x0B
+#define OPCODE_SET_PALETTE 0x0C
+#define OPCODE_SET_PALETTE_COMPRESSED 0x0D
+#define OPCODE_UNKNOWN_0E 0x0E
+#define OPCODE_SET_DECODING_MAP 0x0F
+#define OPCODE_UNKNOWN_10 0x10
+#define OPCODE_VIDEO_DATA 0x11
+#define OPCODE_UNKNOWN_12 0x12
+#define OPCODE_UNKNOWN_13 0x13
+#define OPCODE_UNKNOWN_14 0x14
+#define OPCODE_UNKNOWN_15 0x15
+
+#define PALETTE_COUNT 256
+
+typedef struct IPMVEContext {
+
+ unsigned char *buf;
+ int buf_size;
+
+ float fps;
+ int frame_pts_inc;
+
+ unsigned int video_width;
+ unsigned int video_height;
+ int64_t video_pts;
+
+ unsigned int audio_bits;
+ unsigned int audio_channels;
+ unsigned int audio_sample_rate;
+ unsigned int audio_type;
+ unsigned int audio_frame_count;
+
+ int video_stream_index;
+ int audio_stream_index;
+
+ offset_t audio_chunk_offset;
+ int audio_chunk_size;
+ offset_t video_chunk_offset;
+ int video_chunk_size;
+ offset_t decode_map_chunk_offset;
+ int decode_map_chunk_size;
+
+ offset_t next_chunk_offset;
+
+ AVPaletteControl palette_control;
+
+} IPMVEContext;
+
+static int load_ipmovie_packet(IPMVEContext *s, ByteIOContext *pb,
+ AVPacket *pkt) {
+
+ int chunk_type;
+ int64_t audio_pts = 0;
+
+ if (s->audio_chunk_offset) {
+
+ /* adjust for PCM audio by skipping chunk header */
+ if (s->audio_type != CODEC_ID_INTERPLAY_DPCM) {
+ s->audio_chunk_offset += 6;
+ s->audio_chunk_size -= 6;
+ }
+
+ url_fseek(pb, s->audio_chunk_offset, SEEK_SET);
+ s->audio_chunk_offset = 0;
+
+ /* figure out the audio pts */
+ audio_pts = 90000;
+ audio_pts *= s->audio_frame_count;
+ audio_pts /= s->audio_sample_rate;
+
+ if (s->audio_chunk_size != av_get_packet(pb, pkt, s->audio_chunk_size))
+ return CHUNK_EOF;
+
+ pkt->stream_index = s->audio_stream_index;
+ pkt->pts = audio_pts;
+
+ /* audio frame maintenance */
+ if (s->audio_type != CODEC_ID_INTERPLAY_DPCM)
+ s->audio_frame_count +=
+ (s->audio_chunk_size / s->audio_channels / (s->audio_bits / 8));
+ else
+ s->audio_frame_count +=
+ (s->audio_chunk_size - 6) / s->audio_channels;
+
+ debug_ipmovie("sending audio frame with pts %"PRId64" (%d audio frames)\n",
+ audio_pts, s->audio_frame_count);
+
+ chunk_type = CHUNK_VIDEO;
+
+ } else if (s->decode_map_chunk_offset) {
+
+ /* send both the decode map and the video data together */
+
+ if (av_new_packet(pkt, s->decode_map_chunk_size + s->video_chunk_size))
+ return CHUNK_NOMEM;
+
+ pkt->pos= s->decode_map_chunk_offset;
+ url_fseek(pb, s->decode_map_chunk_offset, SEEK_SET);
+ s->decode_map_chunk_offset = 0;
+
+ if (get_buffer(pb, pkt->data, s->decode_map_chunk_size) !=
+ s->decode_map_chunk_size) {
+ av_free_packet(pkt);
+ return CHUNK_EOF;
+ }
+
+ url_fseek(pb, s->video_chunk_offset, SEEK_SET);
+ s->video_chunk_offset = 0;
+
+ if (get_buffer(pb, pkt->data + s->decode_map_chunk_size,
+ s->video_chunk_size) != s->video_chunk_size) {
+ av_free_packet(pkt);
+ return CHUNK_EOF;
+ }
+
+ pkt->stream_index = s->video_stream_index;
+ pkt->pts = s->video_pts;
+
+ debug_ipmovie("sending video frame with pts %"PRId64"\n",
+ pkt->pts);
+
+ s->video_pts += s->frame_pts_inc;
+
+ chunk_type = CHUNK_VIDEO;
+
+ } else {
+
+ url_fseek(pb, s->next_chunk_offset, SEEK_SET);
+ chunk_type = CHUNK_DONE;
+
+ }
+
+ return chunk_type;
+}
+
+/* This function loads and processes a single chunk in an IP movie file.
+ * It returns the type of chunk that was processed. */
+static int process_ipmovie_chunk(IPMVEContext *s, ByteIOContext *pb,
+ AVPacket *pkt)
+{
+ unsigned char chunk_preamble[CHUNK_PREAMBLE_SIZE];
+ int chunk_type;
+ int chunk_size;
+ unsigned char opcode_preamble[OPCODE_PREAMBLE_SIZE];
+ unsigned char opcode_type;
+ unsigned char opcode_version;
+ int opcode_size;
+ unsigned char scratch[1024];
+ int i, j;
+ int first_color, last_color;
+ int audio_flags;
+ unsigned char r, g, b;
+
+ /* see if there are any pending packets */
+ chunk_type = load_ipmovie_packet(s, pb, pkt);
+ if (chunk_type != CHUNK_DONE)
+ return chunk_type;
+
+ /* read the next chunk, wherever the file happens to be pointing */
+ if (url_feof(pb))
+ return CHUNK_EOF;
+ if (get_buffer(pb, chunk_preamble, CHUNK_PREAMBLE_SIZE) !=
+ CHUNK_PREAMBLE_SIZE)
+ return CHUNK_BAD;
+ chunk_size = AV_RL16(&chunk_preamble[0]);
+ chunk_type = AV_RL16(&chunk_preamble[2]);
+
+ debug_ipmovie("chunk type 0x%04X, 0x%04X bytes: ", chunk_type, chunk_size);
+
+ switch (chunk_type) {
+
+ case CHUNK_INIT_AUDIO:
+ debug_ipmovie("initialize audio\n");
+ break;
+
+ case CHUNK_AUDIO_ONLY:
+ debug_ipmovie("audio only\n");
+ break;
+
+ case CHUNK_INIT_VIDEO:
+ debug_ipmovie("initialize video\n");
+ break;
+
+ case CHUNK_VIDEO:
+ debug_ipmovie("video (and audio)\n");
+ break;
+
+ case CHUNK_SHUTDOWN:
+ debug_ipmovie("shutdown\n");
+ break;
+
+ case CHUNK_END:
+ debug_ipmovie("end\n");
+ break;
+
+ default:
+ debug_ipmovie("invalid chunk\n");
+ chunk_type = CHUNK_BAD;
+ break;
+
+ }
+
+ while ((chunk_size > 0) && (chunk_type != CHUNK_BAD)) {
+
+ /* read the next chunk, wherever the file happens to be pointing */
+ if (url_feof(pb)) {
+ chunk_type = CHUNK_EOF;
+ break;
+ }
+ if (get_buffer(pb, opcode_preamble, CHUNK_PREAMBLE_SIZE) !=
+ CHUNK_PREAMBLE_SIZE) {
+ chunk_type = CHUNK_BAD;
+ break;
+ }
+
+ opcode_size = AV_RL16(&opcode_preamble[0]);
+ opcode_type = opcode_preamble[2];
+ opcode_version = opcode_preamble[3];
+
+ chunk_size -= OPCODE_PREAMBLE_SIZE;
+ chunk_size -= opcode_size;
+ if (chunk_size < 0) {
+ debug_ipmovie("chunk_size countdown just went negative\n");
+ chunk_type = CHUNK_BAD;
+ break;
+ }
+
+ debug_ipmovie(" opcode type %02X, version %d, 0x%04X bytes: ",
+ opcode_type, opcode_version, opcode_size);
+ switch (opcode_type) {
+
+ case OPCODE_END_OF_STREAM:
+ debug_ipmovie("end of stream\n");
+ url_fseek(pb, opcode_size, SEEK_CUR);
+ break;
+
+ case OPCODE_END_OF_CHUNK:
+ debug_ipmovie("end of chunk\n");
+ url_fseek(pb, opcode_size, SEEK_CUR);
+ break;
+
+ case OPCODE_CREATE_TIMER:
+ debug_ipmovie("create timer\n");
+ if ((opcode_version > 0) || (opcode_size > 6)) {
+ debug_ipmovie("bad create_timer opcode\n");
+ chunk_type = CHUNK_BAD;
+ break;
+ }
+ if (get_buffer(pb, scratch, opcode_size) !=
+ opcode_size) {
+ chunk_type = CHUNK_BAD;
+ break;
+ }
+ s->fps = 1000000.0 / (AV_RL32(&scratch[0]) * AV_RL16(&scratch[4]));
+ s->frame_pts_inc = 90000 / s->fps;
+ debug_ipmovie(" %.2f frames/second (timer div = %d, subdiv = %d)\n",
+ s->fps, AV_RL32(&scratch[0]), AV_RL16(&scratch[4]));
+ break;
+
+ case OPCODE_INIT_AUDIO_BUFFERS:
+ debug_ipmovie("initialize audio buffers\n");
+ if ((opcode_version > 1) || (opcode_size > 10)) {
+ debug_ipmovie("bad init_audio_buffers opcode\n");
+ chunk_type = CHUNK_BAD;
+ break;
+ }
+ if (get_buffer(pb, scratch, opcode_size) !=
+ opcode_size) {
+ chunk_type = CHUNK_BAD;
+ break;
+ }
+ s->audio_sample_rate = AV_RL16(&scratch[4]);
+ audio_flags = AV_RL16(&scratch[2]);
+ /* bit 0 of the flags: 0 = mono, 1 = stereo */
+ s->audio_channels = (audio_flags & 1) + 1;
+ /* bit 1 of the flags: 0 = 8 bit, 1 = 16 bit */
+ s->audio_bits = (((audio_flags >> 1) & 1) + 1) * 8;
+ /* bit 2 indicates compressed audio in version 1 opcode */
+ if ((opcode_version == 1) && (audio_flags & 0x4))
+ s->audio_type = CODEC_ID_INTERPLAY_DPCM;
+ else if (s->audio_bits == 16)
+ s->audio_type = CODEC_ID_PCM_S16LE;
+ else
+ s->audio_type = CODEC_ID_PCM_U8;
+ debug_ipmovie("audio: %d bits, %d Hz, %s, %s format\n",
+ s->audio_bits,
+ s->audio_sample_rate,
+ (s->audio_channels == 2) ? "stereo" : "mono",
+ (s->audio_type == CODEC_ID_INTERPLAY_DPCM) ?
+ "Interplay audio" : "PCM");
+ break;
+
+ case OPCODE_START_STOP_AUDIO:
+ debug_ipmovie("start/stop audio\n");
+ url_fseek(pb, opcode_size, SEEK_CUR);
+ break;
+
+ case OPCODE_INIT_VIDEO_BUFFERS:
+ debug_ipmovie("initialize video buffers\n");
+ if ((opcode_version > 2) || (opcode_size > 8)) {
+ debug_ipmovie("bad init_video_buffers opcode\n");
+ chunk_type = CHUNK_BAD;
+ break;
+ }
+ if (get_buffer(pb, scratch, opcode_size) !=
+ opcode_size) {
+ chunk_type = CHUNK_BAD;
+ break;
+ }
+ s->video_width = AV_RL16(&scratch[0]) * 8;
+ s->video_height = AV_RL16(&scratch[2]) * 8;
+ debug_ipmovie("video resolution: %d x %d\n",
+ s->video_width, s->video_height);
+ break;
+
+ case OPCODE_UNKNOWN_06:
+ case OPCODE_UNKNOWN_0E:
+ case OPCODE_UNKNOWN_10:
+ case OPCODE_UNKNOWN_12:
+ case OPCODE_UNKNOWN_13:
+ case OPCODE_UNKNOWN_14:
+ case OPCODE_UNKNOWN_15:
+ debug_ipmovie("unknown (but documented) opcode %02X\n", opcode_type);
+ url_fseek(pb, opcode_size, SEEK_CUR);
+ break;
+
+ case OPCODE_SEND_BUFFER:
+ debug_ipmovie("send buffer\n");
+ url_fseek(pb, opcode_size, SEEK_CUR);
+ break;
+
+ case OPCODE_AUDIO_FRAME:
+ debug_ipmovie("audio frame\n");
+
+ /* log position and move on for now */
+ s->audio_chunk_offset = url_ftell(pb);
+ s->audio_chunk_size = opcode_size;
+ url_fseek(pb, opcode_size, SEEK_CUR);
+ break;
+
+ case OPCODE_SILENCE_FRAME:
+ debug_ipmovie("silence frame\n");
+ url_fseek(pb, opcode_size, SEEK_CUR);
+ break;
+
+ case OPCODE_INIT_VIDEO_MODE:
+ debug_ipmovie("initialize video mode\n");
+ url_fseek(pb, opcode_size, SEEK_CUR);
+ break;
+
+ case OPCODE_CREATE_GRADIENT:
+ debug_ipmovie("create gradient\n");
+ url_fseek(pb, opcode_size, SEEK_CUR);
+ break;
+
+ case OPCODE_SET_PALETTE:
+ debug_ipmovie("set palette\n");
+ /* check for the logical maximum palette size
+ * (3 * 256 + 4 bytes) */
+ if (opcode_size > 0x304) {
+ debug_ipmovie("demux_ipmovie: set_palette opcode too large\n");
+ chunk_type = CHUNK_BAD;
+ break;
+ }
+ if (get_buffer(pb, scratch, opcode_size) != opcode_size) {
+ chunk_type = CHUNK_BAD;
+ break;
+ }
+
+ /* load the palette into internal data structure */
+ first_color = AV_RL16(&scratch[0]);
+ last_color = first_color + AV_RL16(&scratch[2]) - 1;
+ /* sanity check (since they are 16 bit values) */
+ if ((first_color > 0xFF) || (last_color > 0xFF)) {
+ debug_ipmovie("demux_ipmovie: set_palette indices out of range (%d -> %d)\n",
+ first_color, last_color);
+ chunk_type = CHUNK_BAD;
+ break;
+ }
+ j = 4; /* offset of first palette data */
+ for (i = first_color; i <= last_color; i++) {
+ /* the palette is stored as a 6-bit VGA palette, thus each
+ * component is shifted up to a 8-bit range */
+ r = scratch[j++] * 4;
+ g = scratch[j++] * 4;
+ b = scratch[j++] * 4;
+ s->palette_control.palette[i] = (r << 16) | (g << 8) | (b);
+ }
+ /* indicate a palette change */
+ s->palette_control.palette_changed = 1;
+ break;
+
+ case OPCODE_SET_PALETTE_COMPRESSED:
+ debug_ipmovie("set palette compressed\n");
+ url_fseek(pb, opcode_size, SEEK_CUR);
+ break;
+
+ case OPCODE_SET_DECODING_MAP:
+ debug_ipmovie("set decoding map\n");
+
+ /* log position and move on for now */
+ s->decode_map_chunk_offset = url_ftell(pb);
+ s->decode_map_chunk_size = opcode_size;
+ url_fseek(pb, opcode_size, SEEK_CUR);
+ break;
+
+ case OPCODE_VIDEO_DATA:
+ debug_ipmovie("set video data\n");
+
+ /* log position and move on for now */
+ s->video_chunk_offset = url_ftell(pb);
+ s->video_chunk_size = opcode_size;
+ url_fseek(pb, opcode_size, SEEK_CUR);
+ break;
+
+ default:
+ debug_ipmovie("*** unknown opcode type\n");
+ chunk_type = CHUNK_BAD;
+ break;
+
+ }
+ }
+
+ /* make a note of where the stream is sitting */
+ s->next_chunk_offset = url_ftell(pb);
+
+ /* dispatch the first of any pending packets */
+ if ((chunk_type == CHUNK_VIDEO) || (chunk_type == CHUNK_AUDIO_ONLY))
+ chunk_type = load_ipmovie_packet(s, pb, pkt);
+
+ return chunk_type;
+}
+
+static int ipmovie_probe(AVProbeData *p)
+{
+ if (p->buf_size < IPMOVIE_SIGNATURE_SIZE)
+ return 0;
+ if (strncmp(p->buf, IPMOVIE_SIGNATURE, IPMOVIE_SIGNATURE_SIZE) != 0)
+ return 0;
+
+ return AVPROBE_SCORE_MAX;
+}
+
+static int ipmovie_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ IPMVEContext *ipmovie = (IPMVEContext *)s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ AVPacket pkt;
+ AVStream *st;
+ unsigned char chunk_preamble[CHUNK_PREAMBLE_SIZE];
+ int chunk_type;
+
+ /* 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;
+
+ /* process the first chunk which should be CHUNK_INIT_VIDEO */
+ if (process_ipmovie_chunk(ipmovie, pb, &pkt) != CHUNK_INIT_VIDEO)
+ return AVERROR_INVALIDDATA;
+
+ /* peek ahead to the next chunk-- if it is an init audio chunk, process
+ * it; if it is the first video chunk, this is a silent file */
+ if (get_buffer(pb, chunk_preamble, CHUNK_PREAMBLE_SIZE) !=
+ CHUNK_PREAMBLE_SIZE)
+ return AVERROR_IO;
+ chunk_type = AV_RL16(&chunk_preamble[2]);
+ url_fseek(pb, -CHUNK_PREAMBLE_SIZE, SEEK_CUR);
+
+ if (chunk_type == CHUNK_VIDEO)
+ ipmovie->audio_type = 0; /* no audio */
+ else if (process_ipmovie_chunk(ipmovie, pb, &pkt) != CHUNK_INIT_AUDIO)
+ return AVERROR_INVALIDDATA;
+
+ /* initialize the stream decoders */
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+ av_set_pts_info(st, 33, 1, 90000);
+ ipmovie->video_stream_index = st->index;
+ st->codec->codec_type = CODEC_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;
+
+ /* palette considerations */
+ st->codec->palctrl = &ipmovie->palette_control;
+
+ if (ipmovie->audio_type) {
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+ av_set_pts_info(st, 33, 1, 90000);
+ ipmovie->audio_stream_index = st->index;
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_id = ipmovie->audio_type;
+ st->codec->codec_tag = 0; /* no tag */
+ st->codec->channels = ipmovie->audio_channels;
+ st->codec->sample_rate = ipmovie->audio_sample_rate;
+ st->codec->bits_per_sample = ipmovie->audio_bits;
+ st->codec->bit_rate = st->codec->channels * st->codec->sample_rate *
+ st->codec->bits_per_sample;
+ if (st->codec->codec_id == CODEC_ID_INTERPLAY_DPCM)
+ st->codec->bit_rate /= 2;
+ st->codec->block_align = st->codec->channels * st->codec->bits_per_sample;
+ }
+
+ return 0;
+}
+
+static int ipmovie_read_packet(AVFormatContext *s,
+ AVPacket *pkt)
+{
+ IPMVEContext *ipmovie = (IPMVEContext *)s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ int ret;
+
+ ret = process_ipmovie_chunk(ipmovie, pb, pkt);
+ if (ret == CHUNK_BAD)
+ ret = AVERROR_INVALIDDATA;
+ else if (ret == CHUNK_EOF)
+ ret = AVERROR_IO;
+ else if (ret == CHUNK_NOMEM)
+ ret = AVERROR_NOMEM;
+ else if (ret == CHUNK_VIDEO)
+ ret = 0;
+ else
+ ret = -1;
+
+ return ret;
+}
+
+static int ipmovie_read_close(AVFormatContext *s)
+{
+// IPMVEContext *ipmovie = (IPMVEContext *)s->priv_data;
+
+ return 0;
+}
+
+AVInputFormat ipmovie_demuxer = {
+ "ipmovie",
+ "Interplay MVE format",
+ sizeof(IPMVEContext),
+ ipmovie_probe,
+ ipmovie_read_header,
+ ipmovie_read_packet,
+ ipmovie_read_close,
+};
diff --git a/contrib/ffmpeg/libavformat/isom.c b/contrib/ffmpeg/libavformat/isom.c
new file mode 100644
index 000000000..f913bc0a9
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/isom.c
@@ -0,0 +1,247 @@
+/*
+ * ISO Media common code
+ * Copyright (c) 2001 Fabrice Bellard.
+ * Copyright (c) 2002 Francois Revol <revol@free.fr>
+ * Copyright (c) 2006 Baptiste Coudurier <baptiste.coudurier@free.fr>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avformat.h"
+#include "riff.h"
+#include "isom.h"
+
+/* http://www.mp4ra.org */
+const AVCodecTag ff_mp4_obj_type[] = {
+ { CODEC_ID_MPEG4 , 32 },
+ { CODEC_ID_H264 , 33 },
+ { CODEC_ID_AAC , 64 },
+ { CODEC_ID_MPEG2VIDEO, 96 }, /* MPEG2 Simple */
+ { CODEC_ID_MPEG2VIDEO, 97 }, /* MPEG2 Main */
+ { CODEC_ID_MPEG2VIDEO, 98 }, /* MPEG2 SNR */
+ { CODEC_ID_MPEG2VIDEO, 99 }, /* MPEG2 Spatial */
+ { CODEC_ID_MPEG2VIDEO, 100 }, /* MPEG2 High */
+ { CODEC_ID_MPEG2VIDEO, 101 }, /* MPEG2 422 */
+ { CODEC_ID_AAC , 102 }, /* MPEG2 AAC Main */
+ { CODEC_ID_AAC , 103 }, /* MPEG2 AAC Low */
+ { CODEC_ID_AAC , 104 }, /* MPEG2 AAC SSR */
+ { CODEC_ID_MP3 , 105 }, /* 13818-3 */
+ { CODEC_ID_MPEG1VIDEO, 106 }, /* 11172-2 */
+ { CODEC_ID_MP3 , 107 }, /* 11172-3 */
+ { CODEC_ID_MJPEG , 108 }, /* 10918-1 */
+ { CODEC_ID_PNG , 109 },
+ { CODEC_ID_JPEG2000 , 110 }, /* 15444-1 */
+ { CODEC_ID_VC1 , 163 },
+ { CODEC_ID_VORBIS , 221 },
+ { CODEC_ID_PCM_S16LE , 224 },
+ { CODEC_ID_QCELP , 225 },
+ { CODEC_ID_AC3 , 226 },
+ { CODEC_ID_PCM_ALAW , 227 },
+ { CODEC_ID_PCM_MULAW , 228 },
+ { CODEC_ID_PCM_S16BE , 230 },
+ { CODEC_ID_H263 , 242 },
+ { CODEC_ID_H261 , 243 },
+ { 0, 0 },
+};
+
+const AVCodecTag codec_movvideo_tags[] = {
+/* { CODEC_ID_, MKTAG('I', 'V', '5', '0') }, *//* Indeo 5.0 */
+
+ { CODEC_ID_RAWVIDEO, MKTAG('r', 'a', 'w', ' ') }, /* Uncompressed RGB */
+/* { 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_MJPEG, MKTAG('j', 'p', 'e', 'g') }, /* PhotoJPEG */
+ { CODEC_ID_MJPEG, MKTAG('m', 'j', 'p', 'a') }, /* Motion-JPEG (format A) */
+ { CODEC_ID_MJPEG, MKTAG('A', 'V', 'D', 'J') }, /* MJPEG with alpha-channel (AVID JFIF meridien compressed) */
+/* { CODEC_ID_MJPEG, MKTAG('A', 'V', 'R', 'n') }, *//* MJPEG with alpha-channel (AVID ABVB/Truevision NuVista) */
+ { CODEC_ID_MJPEGB, MKTAG('m', 'j', 'p', 'b') }, /* Motion-JPEG (format B) */
+
+ { CODEC_ID_SVQ1, MKTAG('S', 'V', 'Q', '1') }, /* Sorenson Video v1 */
+ { CODEC_ID_SVQ1, MKTAG('s', 'v', 'q', '1') }, /* Sorenson Video v1 */
+ { CODEC_ID_SVQ1, MKTAG('s', 'v', 'q', 'i') }, /* Sorenson Video v1 (from QT specs)*/
+ { CODEC_ID_SVQ3, MKTAG('S', 'V', 'Q', '3') }, /* Sorenson Video v3 */
+
+ { CODEC_ID_MPEG4, MKTAG('m', 'p', '4', 'v') },
+ { CODEC_ID_MPEG4, MKTAG('D', 'I', 'V', 'X') }, /* OpenDiVX *//* sample files at http://heroinewarrior.com/xmovie.php3 use this tag */
+ { CODEC_ID_MPEG4, MKTAG('X', 'V', 'I', 'D') },
+ { CODEC_ID_MPEG4, MKTAG('3', 'I', 'V', '2') }, /* experimental: 3IVX files before ivx D4 4.5.1 */
+
+ { CODEC_ID_H263, MKTAG('h', '2', '6', '3') }, /* H263 */
+ { CODEC_ID_H263, MKTAG('s', '2', '6', '3') }, /* H263 ?? works */
+
+ { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'c', 'p') }, /* DV PAL */
+ { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'c', ' ') }, /* DV NTSC */
+ { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'p', 'p') }, /* DVCPRO PAL produced by FCP */
+ { CODEC_ID_DVVIDEO, MKTAG('d', 'v', '5', 'p') }, /* DVCPRO50 PAL produced by FCP */
+ { CODEC_ID_DVVIDEO, MKTAG('d', 'v', '5', 'n') }, /* DVCPRO50 NTSC produced by FCP */
+ { CODEC_ID_DVVIDEO, MKTAG('A', 'V', 'd', 'v') }, /* AVID DV */
+ //{ CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'h', '5') }, /* DVCPRO HD 50i produced by FCP */
+ //{ CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'h', '6') }, /* DVCPRO HD 60i produced by FCP */
+
+ { CODEC_ID_VP3, MKTAG('V', 'P', '3', '1') }, /* On2 VP3 */
+ { CODEC_ID_RPZA, MKTAG('r', 'p', 'z', 'a') }, /* Apple Video (RPZA) */
+ { CODEC_ID_CINEPAK, MKTAG('c', 'v', 'i', 'd') }, /* Cinepak */
+ { CODEC_ID_8BPS, MKTAG('8', 'B', 'P', 'S') }, /* Planar RGB (8BPS) */
+ { CODEC_ID_SMC, MKTAG('s', 'm', 'c', ' ') }, /* Apple Graphics (SMC) */
+ { CODEC_ID_QTRLE, MKTAG('r', 'l', 'e', ' ') }, /* Apple Animation (RLE) */
+ { CODEC_ID_MSRLE, MKTAG('W', 'R', 'L', 'E') },
+ { CODEC_ID_QDRAW, MKTAG('q', 'd', 'r', 'w') }, /* QuickDraw */
+
+ { CODEC_ID_H264, MKTAG('a', 'v', 'c', '1') }, /* AVC-1/H.264 */
+
+ { CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'e', 'g') }, /* MPEG */
+ { CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '1') }, /* HDV 720p30 */
+ { CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '2') }, /* MPEG2 produced by Sony HD camera */
+ { CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '3') }, /* HDV produced by FCP */
+ { CODEC_ID_MPEG2VIDEO, MKTAG('m', 'x', '5', 'n') }, /* MPEG2 IMX NTSC 525/60 50mb/s produced by FCP */
+ { CODEC_ID_MPEG2VIDEO, MKTAG('m', 'x', '5', 'p') }, /* MPEG2 IMX PAL 625/50 50mb/s produced by FCP */
+ { CODEC_ID_MPEG2VIDEO, MKTAG('m', 'x', '3', 'n') }, /* MPEG2 IMX NTSC 525/60 30mb/s produced by FCP */
+ { CODEC_ID_MPEG2VIDEO, MKTAG('m', 'x', '3', 'p') }, /* MPEG2 IMX PAL 625/50 30mb/s produced by FCP */
+ { CODEC_ID_MPEG2VIDEO, MKTAG('A', 'V', 'm', 'p') }, /* AVID IMX PAL */
+
+ //{ CODEC_ID_JPEG2000, MKTAG('m', 'j', 'p', '2') }, /* JPEG 2000 produced by FCP */
+
+ { CODEC_ID_TARGA, MKTAG('t', 'g', 'a', ' ') }, /* Truevision Targa */
+ { CODEC_ID_TIFF, MKTAG('t', 'i', 'f', 'f') }, /* TIFF embedded in MOV */
+ { CODEC_ID_GIF, MKTAG('g', 'i', 'f', ' ') }, /* embedded gif files as frames (usually one "click to play movie" frame) */
+ { CODEC_ID_PNG, MKTAG('p', 'n', 'g', ' ') },
+
+ { CODEC_ID_VC1, MKTAG('v', 'c', '-', '1') }, /* SMPTE RP 2025 */
+
+ { CODEC_ID_DNXHD, MKTAG('A', 'V', 'd', 'n') }, /* AVID DNxHD */
+
+ { CODEC_ID_NONE, 0 },
+};
+
+const AVCodecTag codec_movaudio_tags[] = {
+ { CODEC_ID_PCM_S32BE, MKTAG('i', 'n', '3', '2') },
+ { CODEC_ID_PCM_S32LE, MKTAG('i', 'n', '3', '2') },
+ { CODEC_ID_PCM_S24BE, MKTAG('i', 'n', '2', '4') },
+ { CODEC_ID_PCM_S24LE, MKTAG('i', 'n', '2', '4') },
+ { CODEC_ID_PCM_S16BE, MKTAG('t', 'w', 'o', 's') }, /* 16 bits */
+ { CODEC_ID_PCM_S16BE, MKTAG('N', 'O', 'N', 'E') }, /* uncompressed */
+ { CODEC_ID_PCM_S16LE, MKTAG('s', 'o', 'w', 't') }, /* */
+ { CODEC_ID_PCM_S16LE, MKTAG('l', 'p', 'c', 'm') },
+ { CODEC_ID_PCM_S8, MKTAG('s', 'o', 'w', 't') },
+ { CODEC_ID_PCM_U8, MKTAG('r', 'a', 'w', ' ') }, /* 8 bits unsigned */
+ { CODEC_ID_PCM_MULAW, MKTAG('u', 'l', 'a', 'w') }, /* */
+ { CODEC_ID_PCM_ALAW, MKTAG('a', 'l', 'a', 'w') }, /* */
+
+ { CODEC_ID_ADPCM_IMA_QT, MKTAG('i', 'm', 'a', '4') }, /* IMA-4 ADPCM */
+ { CODEC_ID_ADPCM_MS, MKTAG('m', 's', 0x00, 0x02) }, /* MS ADPCM */
+
+ { CODEC_ID_MACE3, MKTAG('M', 'A', 'C', '3') }, /* Macintosh Audio Compression and Expansion 3:1 */
+ { CODEC_ID_MACE6, MKTAG('M', 'A', 'C', '6') }, /* Macintosh Audio Compression and Expansion 6:1 */
+
+ { CODEC_ID_MP3, MKTAG('.', 'm', 'p', '3') }, /* MPEG layer 3 */ /* sample files at http://www.3ivx.com/showcase.html use this tag */
+ { CODEC_ID_MP3, 0x6D730055 }, /* MPEG layer 3 */
+ { CODEC_ID_MP3, MKTAG('m', 's', 0x00, 0x55) }, /* MPEG layer 3 *//* XXX: check endianness */
+
+/* { CODEC_ID_OGG_VORBIS, MKTAG('O', 'g', 'g', 'S') }, *//* sample files at http://heroinewarrior.com/xmovie.php3 use this tag */
+
+ { CODEC_ID_AAC, MKTAG('m', 'p', '4', 'a') }, /* MPEG-4 AAC */
+
+ { CODEC_ID_AMR_NB, MKTAG('s', 'a', 'm', 'r') }, /* AMR-NB 3gp */
+ { CODEC_ID_AMR_WB, MKTAG('s', 'a', 'w', 'b') }, /* AMR-WB 3gp */
+
+ { CODEC_ID_AC3, MKTAG('m', 's', 0x20, 0x00) }, /* Dolby AC-3 */
+
+ { CODEC_ID_ALAC, MKTAG('a', 'l', 'a', 'c') }, /* Apple Lossless */
+ { CODEC_ID_QDM2, MKTAG('Q', 'D', 'M', '2') }, /* QDM2 */
+
+ { CODEC_ID_DVAUDIO, MKTAG('v', 'd', 'v', 'a') },
+ { CODEC_ID_DVAUDIO, MKTAG('d', 'v', 'c', 'a') },
+
+ { CODEC_ID_NONE, 0 },
+};
+
+/* map numeric codes from mdhd atom to ISO 639 */
+/* 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 *mov_mdhd_language_map[] = {
+ /* 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",
+ "slv", "yid", "sr ", "mac", "bul", "ukr", "bel", "uzb", "kaz", "aze",
+ /*?*/
+ "aze", "arm", "geo", "mol", "kir", "tgk", "tuk", "mon", NULL, "pus",
+ "kur", "kas", "snd", "tib", "nep", "san", "mar", "ben", "asm", "guj",
+ "pa ", "ori", "mal", "kan", "tam", "tel", NULL, "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,
+ /* 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",
+ "cat", "lat", "que", "grn", "aym", "tat", "uig", "dzo", "jav"
+};
+
+int ff_mov_iso639_to_lang(const char *lang, int mp4)
+{
+ int i, code = 0;
+
+ /* old way, only for QT? */
+ for (i = 0; !mp4 && (i < (sizeof(mov_mdhd_language_map)/sizeof(char *))); i++) {
+ if (mov_mdhd_language_map[i] && !strcmp(lang, mov_mdhd_language_map[i]))
+ return i;
+ }
+ /* XXX:can we do that in mov too? */
+ if (!mp4)
+ return 0;
+ /* handle undefined as such */
+ if (lang[0] == '\0')
+ lang = "und";
+ /* 5bit ascii */
+ for (i = 0; i < 3; i++) {
+ unsigned char c = (unsigned char)lang[i];
+ if (c < 0x60)
+ return 0;
+ if (c > 0x60 + 0x1f)
+ return 0;
+ code <<= 5;
+ code |= (c - 0x60);
+ }
+ return code;
+}
+
+int ff_mov_lang_to_iso639(int code, char *to)
+{
+ int i;
+ /* is it the mangled iso code? */
+ /* see http://www.geocities.com/xhelmboyx/quicktime/formats/mp4-layout.txt */
+ if (code > 138) {
+ for (i = 2; i >= 0; i--) {
+ to[i] = 0x60 + (code & 0x1f);
+ code >>= 5;
+ }
+ return 1;
+ }
+ /* old fashion apple lang code */
+ if (code >= (sizeof(mov_mdhd_language_map)/sizeof(char *)))
+ return 0;
+ if (!mov_mdhd_language_map[code])
+ return 0;
+ strncpy(to, mov_mdhd_language_map[code], 4);
+ return 1;
+}
diff --git a/contrib/ffmpeg/libavformat/isom.h b/contrib/ffmpeg/libavformat/isom.h
new file mode 100644
index 000000000..efcb1fc42
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/isom.h
@@ -0,0 +1,40 @@
+/*
+ * ISO Media common code
+ * copyright (c) 2001 Fabrice Bellard.
+ * copyright (c) 2002 Francois Revol <revol@free.fr>
+ * copyright (c) 2006 Baptiste Coudurier <baptiste.coudurier@free.fr>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef FFMPEG_ISOM_H
+#define FFMPEG_ISOM_H
+
+/* isom.c */
+extern const AVCodecTag ff_mp4_obj_type[];
+extern const AVCodecTag codec_movvideo_tags[];
+extern const AVCodecTag codec_movaudio_tags[];
+
+int ff_mov_iso639_to_lang(const char *lang, int mp4);
+int ff_mov_lang_to_iso639(int code, char *to);
+
+typedef struct Time2Sample{
+ int count;
+ int duration;
+}Time2Sample;
+
+#endif /* FFMPEG_ISOM_H */
diff --git a/contrib/ffmpeg/libavformat/libnut.c b/contrib/ffmpeg/libavformat/libnut.c
new file mode 100644
index 000000000..0f7b879a9
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/libnut.c
@@ -0,0 +1,310 @@
+/*
+ * NUT (de)muxing via libnut
+ * copyright (c) 2006 Oded Shimon <ods15@ods15.dyndns.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file libnut.c
+ * NUT demuxing and muxing via libnut.
+ * @author Oded Shimon <ods15@ods15.dyndns.org>
+ */
+
+#include "avformat.h"
+#include "riff.h"
+#include <libnut.h>
+
+#define ID_STRING "nut/multimedia container"
+#define ID_LENGTH (strlen(ID_STRING) + 1)
+
+typedef struct {
+ nut_context_t * nut;
+ nut_stream_header_t * s;
+} NUTContext;
+
+static const AVCodecTag nut_tags[] = {
+ { CODEC_ID_MPEG4, MKTAG('m', 'p', '4', 'v') },
+ { CODEC_ID_MP3, MKTAG('m', 'p', '3', ' ') },
+ { CODEC_ID_VORBIS, MKTAG('v', 'r', 'b', 's') },
+ { 0, 0 },
+};
+
+#ifdef CONFIG_MUXERS
+static int av_write(void * h, size_t len, const uint8_t * buf) {
+ ByteIOContext * bc = h;
+ put_buffer(bc, buf, len);
+ //put_flush_packet(bc);
+ return len;
+}
+
+static int nut_write_header(AVFormatContext * avf) {
+ NUTContext * priv = avf->priv_data;
+ ByteIOContext * bc = &avf->pb;
+ nut_muxer_opts_t mopts = {
+ .output = {
+ .priv = bc,
+ .write = av_write,
+ },
+ .alloc = { av_malloc, av_realloc, av_free },
+ .write_index = 1,
+ .realtime_stream = 0,
+ .max_distance = 32768,
+ .fti = NULL,
+ };
+ nut_stream_header_t * s;
+ int i;
+
+ priv->s = s = av_mallocz((avf->nb_streams + 1) * sizeof*s);
+
+ for (i = 0; i < avf->nb_streams; i++) {
+ AVCodecContext * codec = avf->streams[i]->codec;
+ int j;
+ int fourcc = 0;
+ int num, denom, ssize;
+
+ s[i].type = codec->codec_type == CODEC_TYPE_VIDEO ? NUT_VIDEO_CLASS : NUT_AUDIO_CLASS;
+
+ if (codec->codec_tag) fourcc = codec->codec_tag;
+ else fourcc = codec_get_tag(nut_tags, codec->codec_id);
+
+ if (!fourcc) {
+ if (codec->codec_type == CODEC_TYPE_VIDEO) fourcc = codec_get_tag(codec_bmp_tags, codec->codec_id);
+ if (codec->codec_type == CODEC_TYPE_AUDIO) fourcc = codec_get_tag(codec_wav_tags, codec->codec_id);
+ }
+
+ s[i].fourcc_len = 4;
+ s[i].fourcc = av_malloc(s[i].fourcc_len);
+ for (j = 0; j < s[i].fourcc_len; j++) s[i].fourcc[j] = (fourcc >> (j*8)) & 0xFF;
+
+ ff_parse_specific_params(codec, &num, &ssize, &denom);
+ av_set_pts_info(avf->streams[i], 60, denom, num);
+
+ s[i].time_base.num = denom;
+ s[i].time_base.den = num;
+
+ s[i].fixed_fps = 0;
+ s[i].decode_delay = codec->has_b_frames;
+ s[i].codec_specific_len = codec->extradata_size;
+ s[i].codec_specific = codec->extradata;
+
+ if (codec->codec_type == CODEC_TYPE_VIDEO) {
+ s[i].width = codec->width;
+ s[i].height = codec->height;
+ s[i].sample_width = 0;
+ s[i].sample_height = 0;
+ s[i].colorspace_type = 0;
+ } else {
+ s[i].samplerate_num = codec->sample_rate;
+ s[i].samplerate_denom = 1;
+ s[i].channel_count = codec->channels;
+ }
+ }
+
+ s[avf->nb_streams].type = -1;
+ priv->nut = nut_muxer_init(&mopts, s, NULL);
+
+ return 0;
+}
+
+static int nut_write_packet(AVFormatContext * avf, AVPacket * pkt) {
+ NUTContext * priv = avf->priv_data;
+ nut_packet_t p;
+
+ 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.next_pts = 0;
+
+ nut_write_frame_reorder(priv->nut, &p, pkt->data);
+
+ return 0;
+}
+
+static int nut_write_trailer(AVFormatContext * avf) {
+ ByteIOContext * bc = &avf->pb;
+ NUTContext * priv = avf->priv_data;
+ int i;
+
+ nut_muxer_uninit_reorder(priv->nut);
+ put_flush_packet(bc);
+
+ for(i = 0; priv->s[i].type != -1; i++ ) av_freep(&priv->s[i].fourcc);
+ av_freep(&priv->s);
+
+ return 0;
+}
+
+AVOutputFormat libnut_muxer = {
+ "nut",
+ "nut format",
+ "video/x-nut",
+ "nut",
+ sizeof(NUTContext),
+ CODEC_ID_VORBIS,
+ CODEC_ID_MPEG4,
+ nut_write_header,
+ nut_write_packet,
+ nut_write_trailer,
+ .flags = AVFMT_GLOBALHEADER,
+};
+#endif //CONFIG_MUXERS
+
+static int nut_probe(AVProbeData *p) {
+ if (p->buf_size >= ID_LENGTH && !memcmp(p->buf, ID_STRING, ID_LENGTH)) return AVPROBE_SCORE_MAX;
+
+ return 0;
+}
+
+static size_t av_read(void * h, size_t len, uint8_t * buf) {
+ ByteIOContext * bc = h;
+ return get_buffer(bc, buf, len);
+}
+
+static off_t av_seek(void * h, long long pos, int whence) {
+ ByteIOContext * bc = h;
+ if (whence == SEEK_END) {
+ pos = url_fsize(bc) + pos;
+ whence = SEEK_SET;
+ }
+ return url_fseek(bc, pos, whence);
+}
+
+static int nut_read_header(AVFormatContext * avf, AVFormatParameters * ap) {
+ NUTContext * priv = avf->priv_data;
+ ByteIOContext * bc = &avf->pb;
+ nut_demuxer_opts_t dopts = {
+ .input = {
+ .priv = bc,
+ .seek = av_seek,
+ .read = av_read,
+ .eof = NULL,
+ .file_pos = 0,
+ },
+ .alloc = { av_malloc, av_realloc, av_free },
+ .read_index = 1,
+ .cache_syncpoints = 1,
+ };
+ nut_context_t * nut = priv->nut = nut_demuxer_init(&dopts);
+ nut_stream_header_t * s;
+ int ret, i;
+
+ if ((ret = nut_read_headers(nut, &s, NULL))) {
+ av_log(avf, AV_LOG_ERROR, " NUT error: %s\n", nut_error(ret));
+ nut_demuxer_uninit(nut);
+ return -1;
+ }
+
+ priv->s = s;
+
+ for (i = 0; s[i].type != -1 && i < 2; i++) {
+ AVStream * st = av_new_stream(avf, i);
+ int j;
+
+ for (j = 0; j < s[i].fourcc_len && j < 8; j++) st->codec->codec_tag |= s[i].fourcc[j]<<(j*8);
+
+ st->codec->has_b_frames = s[i].decode_delay;
+
+ st->codec->extradata_size = s[i].codec_specific_len;
+ if (st->codec->extradata_size) {
+ st->codec->extradata = av_mallocz(st->codec->extradata_size);
+ memcpy(st->codec->extradata, s[i].codec_specific, st->codec->extradata_size);
+ }
+
+ av_set_pts_info(avf->streams[i], 60, s[i].time_base.num, s[i].time_base.den);
+ st->start_time = 0;
+ st->duration = s[i].max_pts;
+
+ st->codec->codec_id = codec_get_id(nut_tags, st->codec->codec_tag);
+
+ switch(s[i].type) {
+ case NUT_AUDIO_CLASS:
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ if (st->codec->codec_id == CODEC_ID_NONE) st->codec->codec_id = codec_get_id(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;
+ if (st->codec->codec_id == CODEC_ID_NONE) st->codec->codec_id = codec_get_id(codec_bmp_tags, st->codec->codec_tag);
+
+ st->codec->width = s[i].width;
+ st->codec->height = s[i].height;
+ st->codec->sample_aspect_ratio.num = s[i].sample_width;
+ st->codec->sample_aspect_ratio.den = s[i].sample_height;
+ break;
+ }
+ if (st->codec->codec_id == CODEC_ID_NONE) av_log(avf, AV_LOG_ERROR, "Unknown codec?!\n");
+ }
+
+ return 0;
+}
+
+static int nut_read_packet(AVFormatContext * avf, AVPacket * pkt) {
+ NUTContext * priv = avf->priv_data;
+ nut_packet_t pd;
+ int ret;
+
+ ret = nut_read_next_packet(priv->nut, &pd);
+
+ if (ret || av_new_packet(pkt, pd.len) < 0) {
+ if (ret != NUT_ERR_EOF)
+ av_log(avf, AV_LOG_ERROR, " NUT error: %s\n", nut_error(ret));
+ return -1;
+ }
+
+ if (pd.flags & NUT_FLAG_KEY) pkt->flags |= PKT_FLAG_KEY;
+ pkt->pts = pd.pts;
+ pkt->stream_index = pd.stream;
+ pkt->pos = url_ftell(&avf->pb);
+
+ ret = nut_read_frame(priv->nut, &pd.len, pkt->data);
+
+ return ret;
+}
+
+static int nut_read_seek(AVFormatContext * avf, int stream_index, int64_t target_ts, int flags) {
+ NUTContext * priv = avf->priv_data;
+ int active_streams[] = { stream_index, -1 };
+ double time_pos = target_ts * priv->s[stream_index].time_base.num / (double)priv->s[stream_index].time_base.den;
+
+ if (nut_seek(priv->nut, time_pos, 2*!(flags & AVSEEK_FLAG_BACKWARD), active_streams)) return -1;
+
+ return 0;
+}
+
+static int nut_read_close(AVFormatContext *s) {
+ NUTContext * priv = s->priv_data;
+
+ nut_demuxer_uninit(priv->nut);
+
+ return 0;
+}
+
+AVInputFormat libnut_demuxer = {
+ "nut",
+ "nut format",
+ sizeof(NUTContext),
+ nut_probe,
+ nut_read_header,
+ nut_read_packet,
+ nut_read_close,
+ nut_read_seek,
+ .extensions = "nut",
+};
diff --git a/contrib/ffmpeg/libavformat/matroska.c b/contrib/ffmpeg/libavformat/matroska.c
new file mode 100644
index 000000000..591530490
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/matroska.c
@@ -0,0 +1,2850 @@
+/*
+ * Matroska file demuxer (no muxer yet)
+ * Copyright (c) 2003-2004 The ffmpeg Project
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file matroska.c
+ * Matroska file demuxer
+ * by Ronald Bultje <rbultje@ronald.bitfreak.net>
+ * with a little help from Moritz Bunkus <moritz@bunkus.org>
+ * Specs available on the matroska project page:
+ * http://www.matroska.org/.
+ */
+
+#include "avformat.h"
+/* For codec_get_id(). */
+#include "riff.h"
+#include "intfloat_readwrite.h"
+
+/* EBML version supported */
+#define EBML_VERSION 1
+
+/* top-level master-IDs */
+#define EBML_ID_HEADER 0x1A45DFA3
+
+/* IDs in the HEADER master */
+#define EBML_ID_EBMLVERSION 0x4286
+#define EBML_ID_EBMLREADVERSION 0x42F7
+#define EBML_ID_EBMLMAXIDLENGTH 0x42F2
+#define EBML_ID_EBMLMAXSIZELENGTH 0x42F3
+#define EBML_ID_DOCTYPE 0x4282
+#define EBML_ID_DOCTYPEVERSION 0x4287
+#define EBML_ID_DOCTYPEREADVERSION 0x4285
+
+/* general EBML types */
+#define EBML_ID_VOID 0xEC
+
+/*
+ * Matroska element IDs. max. 32-bit.
+ */
+
+/* toplevel segment */
+#define MATROSKA_ID_SEGMENT 0x18538067
+
+/* matroska top-level master IDs */
+#define MATROSKA_ID_INFO 0x1549A966
+#define MATROSKA_ID_TRACKS 0x1654AE6B
+#define MATROSKA_ID_CUES 0x1C53BB6B
+#define MATROSKA_ID_TAGS 0x1254C367
+#define MATROSKA_ID_SEEKHEAD 0x114D9B74
+#define MATROSKA_ID_CLUSTER 0x1F43B675
+
+/* IDs in the info master */
+#define MATROSKA_ID_TIMECODESCALE 0x2AD7B1
+#define MATROSKA_ID_DURATION 0x4489
+#define MATROSKA_ID_TITLE 0x7BA9
+#define MATROSKA_ID_WRITINGAPP 0x5741
+#define MATROSKA_ID_MUXINGAPP 0x4D80
+#define MATROSKA_ID_DATEUTC 0x4461
+
+/* ID in the tracks master */
+#define MATROSKA_ID_TRACKENTRY 0xAE
+
+/* IDs in the trackentry master */
+#define MATROSKA_ID_TRACKNUMBER 0xD7
+#define MATROSKA_ID_TRACKUID 0x73C5
+#define MATROSKA_ID_TRACKTYPE 0x83
+#define MATROSKA_ID_TRACKAUDIO 0xE1
+#define MATROSKA_ID_TRACKVIDEO 0xE0
+#define MATROSKA_ID_CODECID 0x86
+#define MATROSKA_ID_CODECPRIVATE 0x63A2
+#define MATROSKA_ID_CODECNAME 0x258688
+#define MATROSKA_ID_CODECINFOURL 0x3B4040
+#define MATROSKA_ID_CODECDOWNLOADURL 0x26B240
+#define MATROSKA_ID_TRACKNAME 0x536E
+#define MATROSKA_ID_TRACKLANGUAGE 0x22B59C
+#define MATROSKA_ID_TRACKFLAGENABLED 0xB9
+#define MATROSKA_ID_TRACKFLAGDEFAULT 0x88
+#define MATROSKA_ID_TRACKFLAGLACING 0x9C
+#define MATROSKA_ID_TRACKMINCACHE 0x6DE7
+#define MATROSKA_ID_TRACKMAXCACHE 0x6DF8
+#define MATROSKA_ID_TRACKDEFAULTDURATION 0x23E383
+
+/* IDs in the trackvideo master */
+#define MATROSKA_ID_VIDEOFRAMERATE 0x2383E3
+#define MATROSKA_ID_VIDEODISPLAYWIDTH 0x54B0
+#define MATROSKA_ID_VIDEODISPLAYHEIGHT 0x54BA
+#define MATROSKA_ID_VIDEOPIXELWIDTH 0xB0
+#define MATROSKA_ID_VIDEOPIXELHEIGHT 0xBA
+#define MATROSKA_ID_VIDEOFLAGINTERLACED 0x9A
+#define MATROSKA_ID_VIDEOSTEREOMODE 0x53B9
+#define MATROSKA_ID_VIDEOASPECTRATIO 0x54B3
+#define MATROSKA_ID_VIDEOCOLOURSPACE 0x2EB524
+
+/* IDs in the trackaudio master */
+#define MATROSKA_ID_AUDIOSAMPLINGFREQ 0xB5
+#define MATROSKA_ID_AUDIOOUTSAMPLINGFREQ 0x78B5
+
+#define MATROSKA_ID_AUDIOBITDEPTH 0x6264
+#define MATROSKA_ID_AUDIOCHANNELS 0x9F
+
+/* ID in the cues master */
+#define MATROSKA_ID_POINTENTRY 0xBB
+
+/* IDs in the pointentry master */
+#define MATROSKA_ID_CUETIME 0xB3
+#define MATROSKA_ID_CUETRACKPOSITION 0xB7
+
+/* IDs in the cuetrackposition master */
+#define MATROSKA_ID_CUETRACK 0xF7
+#define MATROSKA_ID_CUECLUSTERPOSITION 0xF1
+
+/* IDs in the tags master */
+/* TODO */
+
+/* IDs in the seekhead master */
+#define MATROSKA_ID_SEEKENTRY 0x4DBB
+
+/* IDs in the seekpoint master */
+#define MATROSKA_ID_SEEKID 0x53AB
+#define MATROSKA_ID_SEEKPOSITION 0x53AC
+
+/* IDs in the cluster master */
+#define MATROSKA_ID_CLUSTERTIMECODE 0xE7
+#define MATROSKA_ID_BLOCKGROUP 0xA0
+#define MATROSKA_ID_SIMPLEBLOCK 0xA3
+
+/* IDs in the blockgroup master */
+#define MATROSKA_ID_BLOCK 0xA1
+#define MATROSKA_ID_BLOCKDURATION 0x9B
+#define MATROSKA_ID_BLOCKREFERENCE 0xFB
+
+typedef enum {
+ MATROSKA_TRACK_TYPE_VIDEO = 0x1,
+ MATROSKA_TRACK_TYPE_AUDIO = 0x2,
+ MATROSKA_TRACK_TYPE_COMPLEX = 0x3,
+ MATROSKA_TRACK_TYPE_LOGO = 0x10,
+ MATROSKA_TRACK_TYPE_SUBTITLE = 0x11,
+ MATROSKA_TRACK_TYPE_CONTROL = 0x20,
+} MatroskaTrackType;
+
+typedef enum {
+ MATROSKA_EYE_MODE_MONO = 0x0,
+ MATROSKA_EYE_MODE_RIGHT = 0x1,
+ MATROSKA_EYE_MODE_LEFT = 0x2,
+ MATROSKA_EYE_MODE_BOTH = 0x3,
+} MatroskaEyeMode;
+
+typedef enum {
+ MATROSKA_ASPECT_RATIO_MODE_FREE = 0x0,
+ MATROSKA_ASPECT_RATIO_MODE_KEEP = 0x1,
+ MATROSKA_ASPECT_RATIO_MODE_FIXED = 0x2,
+} MatroskaAspectRatioMode;
+
+/*
+ * These aren't in any way "matroska-form" things,
+ * it's just something I use in the muxer/demuxer.
+ */
+
+typedef enum {
+ MATROSKA_TRACK_ENABLED = (1<<0),
+ MATROSKA_TRACK_DEFAULT = (1<<1),
+ MATROSKA_TRACK_LACING = (1<<2),
+ MATROSKA_TRACK_REAL_V = (1<<4),
+ MATROSKA_TRACK_REORDER = (1<<8),
+ MATROSKA_TRACK_SHIFT = (1<<16)
+} MatroskaTrackFlags;
+
+typedef enum {
+ MATROSKA_VIDEOTRACK_INTERLACED = (MATROSKA_TRACK_SHIFT<<0)
+} MatroskaVideoTrackFlags;
+
+/*
+ * Matroska Codec IDs. Strings.
+ */
+
+typedef struct CodecTags{
+ const char *str;
+ enum CodecID id;
+}CodecTags;
+
+#define MATROSKA_CODEC_ID_VIDEO_VFW_FOURCC "V_MS/VFW/FOURCC"
+#define MATROSKA_CODEC_ID_AUDIO_ACM "A_MS/ACM"
+
+static CodecTags codec_tags[]={
+// {"V_MS/VFW/FOURCC" , CODEC_ID_NONE},
+ {"V_UNCOMPRESSED" , CODEC_ID_RAWVIDEO},
+ {"V_MPEG4/ISO/SP" , CODEC_ID_MPEG4},
+ {"V_MPEG4/ISO/ASP" , CODEC_ID_MPEG4},
+ {"V_MPEG4/ISO/AP" , CODEC_ID_MPEG4},
+ {"V_MPEG4/ISO/AVC" , CODEC_ID_H264},
+ {"V_MPEG4/MS/V3" , CODEC_ID_MSMPEG4V3},
+ {"V_MPEG1" , CODEC_ID_MPEG1VIDEO},
+ {"V_MPEG2" , CODEC_ID_MPEG2VIDEO},
+ {"V_MJPEG" , CODEC_ID_MJPEG},
+ {"V_REAL/RV10" , CODEC_ID_RV10},
+ {"V_REAL/RV20" , CODEC_ID_RV20},
+ {"V_REAL/RV30" , CODEC_ID_RV30},
+ {"V_REAL/RV40" , CODEC_ID_RV40},
+ {"V_THEORA" , CODEC_ID_THEORA},
+/* TODO: Real/Quicktime */
+
+// {"A_MS/ACM" , CODEC_ID_NONE},
+ {"A_MPEG/L1" , CODEC_ID_MP3},
+ {"A_MPEG/L2" , CODEC_ID_MP3},
+ {"A_MPEG/L3" , CODEC_ID_MP3},
+ {"A_PCM/INT/BIG" , CODEC_ID_PCM_U16BE},
+ {"A_PCM/INT/LIT" , CODEC_ID_PCM_U16LE},
+// {"A_PCM/FLOAT/IEEE" , CODEC_ID_NONE},
+ {"A_AC3" , CODEC_ID_AC3},
+ {"A_DTS" , CODEC_ID_DTS},
+ {"A_VORBIS" , CODEC_ID_VORBIS},
+ {"A_AAC" , CODEC_ID_AAC},
+ {"A_FLAC" , CODEC_ID_FLAC},
+ {"A_WAVPACK4" , CODEC_ID_WAVPACK},
+ {"A_TTA1" , CODEC_ID_TTA},
+ {NULL , CODEC_ID_NONE}
+/* TODO: AC3-9/10 (?), Real, Musepack, Quicktime */
+};
+
+/* max. depth in the EBML tree structure */
+#define EBML_MAX_DEPTH 16
+
+typedef struct Track {
+ MatroskaTrackType type;
+
+ /* Unique track number and track ID. stream_index is the index that
+ * the calling app uses for this track. */
+ uint32_t num,
+ uid,
+ stream_index;
+
+ char *name,
+ *language;
+
+ char *codec_id,
+ *codec_name;
+
+ unsigned char *codec_priv;
+ int codec_priv_size;
+
+ uint64_t default_duration;
+ MatroskaTrackFlags flags;
+} MatroskaTrack;
+
+typedef struct MatroskaVideoTrack {
+ MatroskaTrack track;
+
+ int pixel_width,
+ pixel_height,
+ display_width,
+ display_height;
+
+ uint32_t fourcc;
+
+ MatroskaAspectRatioMode ar_mode;
+ MatroskaEyeMode eye_mode;
+
+ //..
+} MatroskaVideoTrack;
+
+typedef struct MatroskaAudioTrack {
+ MatroskaTrack track;
+
+ int channels,
+ bitdepth,
+ internal_samplerate,
+ samplerate;
+ //..
+} MatroskaAudioTrack;
+
+typedef struct MatroskaSubtitleTrack {
+ MatroskaTrack track;
+
+ //..
+} MatroskaSubtitleTrack;
+
+#define MAX_TRACK_SIZE (FFMAX(FFMAX(sizeof(MatroskaVideoTrack), \
+ sizeof(MatroskaAudioTrack)), \
+ sizeof(MatroskaSubtitleTrack)))
+
+typedef struct MatroskaLevel {
+ uint64_t start, length;
+} MatroskaLevel;
+
+typedef struct MatroskaDemuxIndex {
+ uint64_t pos; /* of the corresponding *cluster*! */
+ uint16_t track; /* reference to 'num' */
+ uint64_t time; /* in nanoseconds */
+} MatroskaDemuxIndex;
+
+typedef struct MatroskaDemuxContext {
+ AVFormatContext *ctx;
+
+ /* ebml stuff */
+ int num_levels;
+ MatroskaLevel levels[EBML_MAX_DEPTH];
+ int level_up;
+
+ /* matroska stuff */
+ char *writing_app,
+ *muxing_app;
+ int64_t created;
+
+ /* timescale in the file */
+ int64_t time_scale;
+
+ /* position (time, ns) */
+ int64_t pos;
+
+ /* num_streams is the number of streams that av_new_stream() was called
+ * for ( = that are available to the calling program). */
+ int num_tracks, num_streams;
+ MatroskaTrack *tracks[MAX_STREAMS];
+
+ /* cache for ID peeking */
+ uint32_t peek_id;
+
+ /* byte position of the segment inside the stream */
+ offset_t segment_start;
+
+ /* The packet queue. */
+ AVPacket **packets;
+ int num_packets;
+ /* Second packet queue used to reorder pts of some video track. */
+ AVPacket **packets_reorder;
+ int num_packets_reorder;
+ uint64_t reorder_max_pts;
+
+ /* have we already parse metadata/cues/clusters? */
+ int metadata_parsed,
+ index_parsed,
+ done;
+
+ /* The index for seeking. */
+ int num_indexes;
+ MatroskaDemuxIndex *index;
+} MatroskaDemuxContext;
+
+/*
+ * The first few functions handle EBML file parsing. The rest
+ * is the document interpretation. Matroska really just is a
+ * EBML file.
+ */
+
+/*
+ * Return: the amount of levels in the hierarchy that the
+ * current element lies higher than the previous one.
+ * The opposite isn't done - that's auto-done using master
+ * element reading.
+ */
+
+static int
+ebml_read_element_level_up (MatroskaDemuxContext *matroska)
+{
+ ByteIOContext *pb = &matroska->ctx->pb;
+ offset_t pos = url_ftell(pb);
+ int num = 0;
+
+ while (matroska->num_levels > 0) {
+ MatroskaLevel *level = &matroska->levels[matroska->num_levels - 1];
+
+ if (pos >= level->start + level->length) {
+ matroska->num_levels--;
+ num++;
+ } else {
+ break;
+ }
+ }
+
+ return num;
+}
+
+/*
+ * Read: an "EBML number", which is defined as a variable-length
+ * array of bytes. The first byte indicates the length by giving a
+ * number of 0-bits followed by a one. The position of the first
+ * "one" bit inside the first byte indicates the length of this
+ * number.
+ * Returns: num. of bytes read. < 0 on error.
+ */
+
+static int
+ebml_read_num (MatroskaDemuxContext *matroska,
+ int max_size,
+ uint64_t *number)
+{
+ ByteIOContext *pb = &matroska->ctx->pb;
+ int len_mask = 0x80, read = 1, n = 1;
+ int64_t total = 0;
+
+ /* the first byte tells us the length in bytes - get_byte() can normally
+ * return 0, but since that's not a valid first ebmlID byte, we can
+ * use it safely here to catch EOS. */
+ if (!(total = get_byte(pb))) {
+ /* we might encounter EOS here */
+ if (!url_feof(pb)) {
+ offset_t pos = url_ftell(pb);
+ av_log(matroska->ctx, AV_LOG_ERROR,
+ "Read error at pos. %"PRIu64" (0x%"PRIx64")\n",
+ pos, pos);
+ }
+ return AVERROR_IO; /* EOS or actual I/O error */
+ }
+
+ /* get the length of the EBML number */
+ while (read <= max_size && !(total & len_mask)) {
+ read++;
+ len_mask >>= 1;
+ }
+ if (read > max_size) {
+ offset_t pos = url_ftell(pb) - 1;
+ av_log(matroska->ctx, AV_LOG_ERROR,
+ "Invalid EBML number size tag 0x%02x at pos %"PRIu64" (0x%"PRIx64")\n",
+ (uint8_t) total, pos, pos);
+ return AVERROR_INVALIDDATA;
+ }
+
+ /* read out length */
+ total &= ~len_mask;
+ while (n++ < read)
+ total = (total << 8) | get_byte(pb);
+
+ *number = total;
+
+ return read;
+}
+
+/*
+ * Read: the element content data ID.
+ * Return: the number of bytes read or < 0 on error.
+ */
+
+static int
+ebml_read_element_id (MatroskaDemuxContext *matroska,
+ uint32_t *id,
+ int *level_up)
+{
+ int read;
+ uint64_t total;
+
+ /* if we re-call this, use our cached ID */
+ if (matroska->peek_id != 0) {
+ if (level_up)
+ *level_up = 0;
+ *id = matroska->peek_id;
+ return 0;
+ }
+
+ /* read out the "EBML number", include tag in ID */
+ if ((read = ebml_read_num(matroska, 4, &total)) < 0)
+ return read;
+ *id = matroska->peek_id = total | (1 << (read * 7));
+
+ /* level tracking */
+ if (level_up)
+ *level_up = ebml_read_element_level_up(matroska);
+
+ return read;
+}
+
+/*
+ * Read: element content length.
+ * Return: the number of bytes read or < 0 on error.
+ */
+
+static int
+ebml_read_element_length (MatroskaDemuxContext *matroska,
+ uint64_t *length)
+{
+ /* clear cache since we're now beyond that data point */
+ matroska->peek_id = 0;
+
+ /* read out the "EBML number", include tag in ID */
+ return ebml_read_num(matroska, 8, length);
+}
+
+/*
+ * Return: the ID of the next element, or 0 on error.
+ * Level_up contains the amount of levels that this
+ * next element lies higher than the previous one.
+ */
+
+static uint32_t
+ebml_peek_id (MatroskaDemuxContext *matroska,
+ int *level_up)
+{
+ uint32_t id;
+
+ assert(level_up != NULL);
+
+ if (ebml_read_element_id(matroska, &id, level_up) < 0)
+ return 0;
+
+ return id;
+}
+
+/*
+ * Seek to a given offset.
+ * 0 is success, -1 is failure.
+ */
+
+static int
+ebml_read_seek (MatroskaDemuxContext *matroska,
+ offset_t offset)
+{
+ ByteIOContext *pb = &matroska->ctx->pb;
+
+ /* clear ID cache, if any */
+ matroska->peek_id = 0;
+
+ return (url_fseek(pb, offset, SEEK_SET) == offset) ? 0 : -1;
+}
+
+/*
+ * Skip the next element.
+ * 0 is success, -1 is failure.
+ */
+
+static int
+ebml_read_skip (MatroskaDemuxContext *matroska)
+{
+ ByteIOContext *pb = &matroska->ctx->pb;
+ uint32_t id;
+ uint64_t length;
+ int res;
+
+ if ((res = ebml_read_element_id(matroska, &id, NULL)) < 0 ||
+ (res = ebml_read_element_length(matroska, &length)) < 0)
+ return res;
+
+ url_fskip(pb, length);
+
+ return 0;
+}
+
+/*
+ * Read the next element as an unsigned int.
+ * 0 is success, < 0 is failure.
+ */
+
+static int
+ebml_read_uint (MatroskaDemuxContext *matroska,
+ uint32_t *id,
+ uint64_t *num)
+{
+ ByteIOContext *pb = &matroska->ctx->pb;
+ int n = 0, size, res;
+ uint64_t rlength;
+
+ if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 ||
+ (res = ebml_read_element_length(matroska, &rlength)) < 0)
+ return res;
+ size = rlength;
+ if (size < 1 || size > 8) {
+ offset_t pos = url_ftell(pb);
+ av_log(matroska->ctx, AV_LOG_ERROR,
+ "Invalid uint element size %d at position %"PRId64" (0x%"PRIx64")\n",
+ size, pos, pos);
+ return AVERROR_INVALIDDATA;
+ }
+
+ /* big-endian ordening; build up number */
+ *num = 0;
+ while (n++ < size)
+ *num = (*num << 8) | get_byte(pb);
+
+ return 0;
+}
+
+/*
+ * Read the next element as a signed int.
+ * 0 is success, < 0 is failure.
+ */
+
+static int
+ebml_read_sint (MatroskaDemuxContext *matroska,
+ uint32_t *id,
+ int64_t *num)
+{
+ ByteIOContext *pb = &matroska->ctx->pb;
+ int size, n = 1, negative = 0, res;
+ uint64_t rlength;
+
+ if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 ||
+ (res = ebml_read_element_length(matroska, &rlength)) < 0)
+ return res;
+ size = rlength;
+ if (size < 1 || size > 8) {
+ offset_t pos = url_ftell(pb);
+ av_log(matroska->ctx, AV_LOG_ERROR,
+ "Invalid sint element size %d at position %"PRId64" (0x%"PRIx64")\n",
+ size, pos, pos);
+ return AVERROR_INVALIDDATA;
+ }
+ if ((*num = get_byte(pb)) & 0x80) {
+ negative = 1;
+ *num &= ~0x80;
+ }
+ while (n++ < size)
+ *num = (*num << 8) | get_byte(pb);
+
+ /* make signed */
+ if (negative)
+ *num = *num - (1LL << ((8 * size) - 1));
+
+ return 0;
+}
+
+/*
+ * Read the next element as a float.
+ * 0 is success, < 0 is failure.
+ */
+
+static int
+ebml_read_float (MatroskaDemuxContext *matroska,
+ uint32_t *id,
+ double *num)
+{
+ ByteIOContext *pb = &matroska->ctx->pb;
+ int size, res;
+ uint64_t rlength;
+
+ if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 ||
+ (res = ebml_read_element_length(matroska, &rlength)) < 0)
+ return res;
+ size = rlength;
+
+ if (size == 4) {
+ *num= av_int2flt(get_be32(pb));
+ } else if(size==8){
+ *num= av_int2dbl(get_be64(pb));
+ } else{
+ offset_t pos = url_ftell(pb);
+ av_log(matroska->ctx, AV_LOG_ERROR,
+ "Invalid float element size %d at position %"PRIu64" (0x%"PRIx64")\n",
+ size, pos, pos);
+ return AVERROR_INVALIDDATA;
+ }
+
+ return 0;
+}
+
+/*
+ * Read the next element as an ASCII string.
+ * 0 is success, < 0 is failure.
+ */
+
+static int
+ebml_read_ascii (MatroskaDemuxContext *matroska,
+ uint32_t *id,
+ char **str)
+{
+ ByteIOContext *pb = &matroska->ctx->pb;
+ int size, res;
+ uint64_t rlength;
+
+ if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 ||
+ (res = ebml_read_element_length(matroska, &rlength)) < 0)
+ return res;
+ size = rlength;
+
+ /* ebml strings are usually not 0-terminated, so we allocate one
+ * byte more, read the string and NULL-terminate it ourselves. */
+ if (size < 0 || !(*str = av_malloc(size + 1))) {
+ av_log(matroska->ctx, AV_LOG_ERROR, "Memory allocation failed\n");
+ return AVERROR_NOMEM;
+ }
+ if (get_buffer(pb, (uint8_t *) *str, size) != size) {
+ offset_t pos = url_ftell(pb);
+ av_log(matroska->ctx, AV_LOG_ERROR,
+ "Read error at pos. %"PRIu64" (0x%"PRIx64")\n", pos, pos);
+ return AVERROR_IO;
+ }
+ (*str)[size] = '\0';
+
+ return 0;
+}
+
+/*
+ * Read the next element as a UTF-8 string.
+ * 0 is success, < 0 is failure.
+ */
+
+static int
+ebml_read_utf8 (MatroskaDemuxContext *matroska,
+ uint32_t *id,
+ char **str)
+{
+ return ebml_read_ascii(matroska, id, str);
+}
+
+/*
+ * Read the next element as a date (nanoseconds since 1/1/2000).
+ * 0 is success, < 0 is failure.
+ */
+
+static int
+ebml_read_date (MatroskaDemuxContext *matroska,
+ uint32_t *id,
+ int64_t *date)
+{
+ return ebml_read_sint(matroska, id, date);
+}
+
+/*
+ * Read the next element, but only the header. The contents
+ * are supposed to be sub-elements which can be read separately.
+ * 0 is success, < 0 is failure.
+ */
+
+static int
+ebml_read_master (MatroskaDemuxContext *matroska,
+ uint32_t *id)
+{
+ ByteIOContext *pb = &matroska->ctx->pb;
+ uint64_t length;
+ MatroskaLevel *level;
+ int res;
+
+ if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 ||
+ (res = ebml_read_element_length(matroska, &length)) < 0)
+ return res;
+
+ /* protect... (Heaven forbids that the '>' is true) */
+ if (matroska->num_levels >= EBML_MAX_DEPTH) {
+ av_log(matroska->ctx, AV_LOG_ERROR,
+ "File moves beyond max. allowed depth (%d)\n", EBML_MAX_DEPTH);
+ return AVERROR_NOTSUPP;
+ }
+
+ /* remember level */
+ level = &matroska->levels[matroska->num_levels++];
+ level->start = url_ftell(pb);
+ level->length = length;
+
+ return 0;
+}
+
+/*
+ * Read the next element as binary data.
+ * 0 is success, < 0 is failure.
+ */
+
+static int
+ebml_read_binary (MatroskaDemuxContext *matroska,
+ uint32_t *id,
+ uint8_t **binary,
+ int *size)
+{
+ ByteIOContext *pb = &matroska->ctx->pb;
+ uint64_t rlength;
+ int res;
+
+ if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 ||
+ (res = ebml_read_element_length(matroska, &rlength)) < 0)
+ return res;
+ *size = rlength;
+
+ if (!(*binary = av_malloc(*size))) {
+ av_log(matroska->ctx, AV_LOG_ERROR,
+ "Memory allocation error\n");
+ return AVERROR_NOMEM;
+ }
+
+ if (get_buffer(pb, *binary, *size) != *size) {
+ offset_t pos = url_ftell(pb);
+ av_log(matroska->ctx, AV_LOG_ERROR,
+ "Read error at pos. %"PRIu64" (0x%"PRIx64")\n", pos, pos);
+ return AVERROR_IO;
+ }
+
+ return 0;
+}
+
+/*
+ * Read signed/unsigned "EBML" numbers.
+ * Return: number of bytes processed, < 0 on error.
+ * XXX: use ebml_read_num().
+ */
+
+static int
+matroska_ebmlnum_uint (uint8_t *data,
+ uint32_t size,
+ uint64_t *num)
+{
+ int len_mask = 0x80, read = 1, n = 1, num_ffs = 0;
+ uint64_t total;
+
+ if (size <= 0)
+ return AVERROR_INVALIDDATA;
+
+ total = data[0];
+ while (read <= 8 && !(total & len_mask)) {
+ read++;
+ len_mask >>= 1;
+ }
+ if (read > 8)
+ return AVERROR_INVALIDDATA;
+
+ if ((total &= (len_mask - 1)) == len_mask - 1)
+ num_ffs++;
+ if (size < read)
+ return AVERROR_INVALIDDATA;
+ while (n < read) {
+ if (data[n] == 0xff)
+ num_ffs++;
+ total = (total << 8) | data[n];
+ n++;
+ }
+
+ if (read == num_ffs)
+ *num = (uint64_t)-1;
+ else
+ *num = total;
+
+ return read;
+}
+
+/*
+ * Same as above, but signed.
+ */
+
+static int
+matroska_ebmlnum_sint (uint8_t *data,
+ uint32_t size,
+ int64_t *num)
+{
+ uint64_t unum;
+ int res;
+
+ /* read as unsigned number first */
+ if ((res = matroska_ebmlnum_uint(data, size, &unum)) < 0)
+ return res;
+
+ /* make signed (weird way) */
+ if (unum == (uint64_t)-1)
+ *num = INT64_MAX;
+ else
+ *num = unum - ((1LL << ((7 * res) - 1)) - 1);
+
+ return res;
+}
+
+/*
+ * Read an EBML header.
+ * 0 is success, < 0 is failure.
+ */
+
+static int
+ebml_read_header (MatroskaDemuxContext *matroska,
+ char **doctype,
+ int *version)
+{
+ uint32_t id;
+ int level_up, res = 0;
+
+ /* default init */
+ if (doctype)
+ *doctype = NULL;
+ if (version)
+ *version = 1;
+
+ if (!(id = ebml_peek_id(matroska, &level_up)) ||
+ level_up != 0 || id != EBML_ID_HEADER) {
+ av_log(matroska->ctx, AV_LOG_ERROR,
+ "This is not an EBML file (id=0x%x/0x%x)\n", id, EBML_ID_HEADER);
+ return AVERROR_INVALIDDATA;
+ }
+ if ((res = ebml_read_master(matroska, &id)) < 0)
+ return res;
+
+ while (res == 0) {
+ if (!(id = ebml_peek_id(matroska, &level_up)))
+ return AVERROR_IO;
+
+ /* end-of-header */
+ if (level_up)
+ break;
+
+ switch (id) {
+ /* is our read version uptodate? */
+ case EBML_ID_EBMLREADVERSION: {
+ uint64_t num;
+
+ if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
+ return res;
+ if (num > EBML_VERSION) {
+ av_log(matroska->ctx, AV_LOG_ERROR,
+ "EBML version %"PRIu64" (> %d) is not supported\n",
+ num, EBML_VERSION);
+ return AVERROR_INVALIDDATA;
+ }
+ break;
+ }
+
+ /* we only handle 8 byte lengths at max */
+ case EBML_ID_EBMLMAXSIZELENGTH: {
+ uint64_t num;
+
+ if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
+ return res;
+ if (num > sizeof(uint64_t)) {
+ av_log(matroska->ctx, AV_LOG_ERROR,
+ "Integers of size %"PRIu64" (> %zd) not supported\n",
+ num, sizeof(uint64_t));
+ return AVERROR_INVALIDDATA;
+ }
+ break;
+ }
+
+ /* we handle 4 byte IDs at max */
+ case EBML_ID_EBMLMAXIDLENGTH: {
+ uint64_t num;
+
+ if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
+ return res;
+ if (num > sizeof(uint32_t)) {
+ av_log(matroska->ctx, AV_LOG_ERROR,
+ "IDs of size %"PRIu64" (> %zu) not supported\n",
+ num, sizeof(uint32_t));
+ return AVERROR_INVALIDDATA;
+ }
+ break;
+ }
+
+ case EBML_ID_DOCTYPE: {
+ char *text;
+
+ if ((res = ebml_read_ascii(matroska, &id, &text)) < 0)
+ return res;
+ if (doctype) {
+ if (*doctype)
+ av_free(*doctype);
+ *doctype = text;
+ } else
+ av_free(text);
+ break;
+ }
+
+ case EBML_ID_DOCTYPEREADVERSION: {
+ uint64_t num;
+
+ if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
+ return res;
+ if (version)
+ *version = num;
+ break;
+ }
+
+ default:
+ av_log(matroska->ctx, AV_LOG_INFO,
+ "Unknown data type 0x%x in EBML header", id);
+ /* pass-through */
+
+ case EBML_ID_VOID:
+ /* we ignore these two, as they don't tell us anything we
+ * care about */
+ case EBML_ID_EBMLVERSION:
+ case EBML_ID_DOCTYPEVERSION:
+ res = ebml_read_skip (matroska);
+ break;
+ }
+ }
+
+ return 0;
+}
+
+/*
+ * Put one packet in an application-supplied AVPacket struct.
+ * Returns 0 on success or -1 on failure.
+ */
+
+static int
+matroska_deliver_packet (MatroskaDemuxContext *matroska,
+ AVPacket *pkt)
+{
+ if (matroska->num_packets > 0) {
+ memcpy(pkt, matroska->packets[0], sizeof(AVPacket));
+ av_free(matroska->packets[0]);
+ if (matroska->num_packets > 1) {
+ memmove(&matroska->packets[0], &matroska->packets[1],
+ (matroska->num_packets - 1) * sizeof(AVPacket *));
+ matroska->packets =
+ av_realloc(matroska->packets, (matroska->num_packets - 1) *
+ sizeof(AVPacket *));
+ } else {
+ av_freep(&matroska->packets);
+ }
+ matroska->num_packets--;
+ return 0;
+ }
+
+ return -1;
+}
+
+/*
+ * Put a packet into our internal queue. Will be delivered to the
+ * user/application during the next get_packet() call.
+ */
+
+static void
+matroska_queue_packet (MatroskaDemuxContext *matroska,
+ AVPacket *pkt)
+{
+ matroska->packets =
+ av_realloc(matroska->packets, (matroska->num_packets + 1) *
+ sizeof(AVPacket *));
+ matroska->packets[matroska->num_packets] = pkt;
+ matroska->num_packets++;
+}
+
+/*
+ * Put a packet into our internal reordering queue. Will be moved to the
+ * main packet queue when enough packets are available to reorder pts.
+ */
+
+static void
+matroska_queue_packet_reordered (MatroskaDemuxContext *matroska,
+ AVPacket *pkt,
+ int is_bframe)
+{
+ if (matroska->num_packets_reorder && !is_bframe
+ && pkt->pts > matroska->reorder_max_pts) {
+ /* reorder pts */
+ int i, j, k = 1;
+ for (j=matroska->num_packets_reorder-1; j && k; j--) {
+ k = 0;
+ for (i=0; i<j; i++) {
+ if (matroska->packets_reorder[i]->pts > matroska->packets_reorder[i+1]->pts) {
+ FFSWAP(uint64_t, matroska->packets_reorder[i]->pts, matroska->packets_reorder[i+1]->pts);
+ k = 1;
+ }
+ }
+ }
+ /* then really queue the packets */
+ for (i=0; i<matroska->num_packets_reorder; i++)
+ matroska_queue_packet (matroska, matroska->packets_reorder[i]);
+ matroska->num_packets_reorder = 0;
+ }
+ matroska->packets_reorder =
+ av_realloc(matroska->packets_reorder,
+ (matroska->num_packets_reorder + 1) * sizeof(AVPacket *));
+ matroska->packets_reorder[matroska->num_packets_reorder++] = pkt;
+ if (pkt->pts > matroska->reorder_max_pts)
+ matroska->reorder_max_pts = pkt->pts;
+}
+
+
+/*
+ * Autodetecting...
+ */
+
+static int
+matroska_probe (AVProbeData *p)
+{
+ uint64_t total = 0;
+ int len_mask = 0x80, size = 1, n = 1;
+ uint8_t probe_data[] = { 'm', 'a', 't', 'r', 'o', 's', 'k', 'a' };
+
+ if (p->buf_size < 5)
+ return 0;
+
+ /* ebml header? */
+ if ((p->buf[0] << 24 | p->buf[1] << 16 |
+ p->buf[2] << 8 | p->buf[3]) != EBML_ID_HEADER)
+ return 0;
+
+ /* length of header */
+ total = p->buf[4];
+ while (size <= 8 && !(total & len_mask)) {
+ size++;
+ len_mask >>= 1;
+ }
+ if (size > 8)
+ return 0;
+ total &= (len_mask - 1);
+ while (n < size)
+ total = (total << 8) | p->buf[4 + n++];
+
+ /* does the probe data contain the whole header? */
+ if (p->buf_size < 4 + size + total)
+ return 0;
+
+ /* the header must contain the document type 'matroska'. 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); n++)
+ if (!memcmp (&p->buf[n], probe_data, sizeof(probe_data)))
+ return AVPROBE_SCORE_MAX;
+
+ return 0;
+}
+
+/*
+ * From here on, it's all XML-style DTD stuff... Needs no comments.
+ */
+
+static int
+matroska_parse_info (MatroskaDemuxContext *matroska)
+{
+ int res = 0;
+ uint32_t id;
+
+ av_log(matroska->ctx, AV_LOG_DEBUG, "Parsing info...\n");
+
+ while (res == 0) {
+ if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
+ res = AVERROR_IO;
+ break;
+ } else if (matroska->level_up) {
+ matroska->level_up--;
+ break;
+ }
+
+ switch (id) {
+ /* cluster timecode */
+ case MATROSKA_ID_TIMECODESCALE: {
+ uint64_t num;
+ if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
+ break;
+ matroska->time_scale = num;
+ break;
+ }
+
+ case MATROSKA_ID_DURATION: {
+ double num;
+ if ((res = ebml_read_float(matroska, &id, &num)) < 0)
+ break;
+ matroska->ctx->duration = num * matroska->time_scale * 1000 / AV_TIME_BASE;
+ break;
+ }
+
+ case MATROSKA_ID_TITLE: {
+ char *text;
+ if ((res = ebml_read_utf8(matroska, &id, &text)) < 0)
+ break;
+ strncpy(matroska->ctx->title, text,
+ sizeof(matroska->ctx->title)-1);
+ av_free(text);
+ break;
+ }
+
+ case MATROSKA_ID_WRITINGAPP: {
+ char *text;
+ if ((res = ebml_read_utf8(matroska, &id, &text)) < 0)
+ break;
+ matroska->writing_app = text;
+ break;
+ }
+
+ case MATROSKA_ID_MUXINGAPP: {
+ char *text;
+ if ((res = ebml_read_utf8(matroska, &id, &text)) < 0)
+ break;
+ matroska->muxing_app = text;
+ break;
+ }
+
+ case MATROSKA_ID_DATEUTC: {
+ int64_t time;
+ if ((res = ebml_read_date(matroska, &id, &time)) < 0)
+ break;
+ matroska->created = time;
+ break;
+ }
+
+ default:
+ av_log(matroska->ctx, AV_LOG_INFO,
+ "Unknown entry 0x%x in info header\n", id);
+ /* fall-through */
+
+ case EBML_ID_VOID:
+ res = ebml_read_skip(matroska);
+ break;
+ }
+
+ if (matroska->level_up) {
+ matroska->level_up--;
+ break;
+ }
+ }
+
+ return res;
+}
+
+static int
+matroska_add_stream (MatroskaDemuxContext *matroska)
+{
+ int res = 0;
+ uint32_t id;
+ MatroskaTrack *track;
+
+ av_log(matroska->ctx, AV_LOG_DEBUG, "parsing track, adding stream..,\n");
+
+ /* Allocate a generic track. As soon as we know its type we'll realloc. */
+ track = av_mallocz(MAX_TRACK_SIZE);
+ matroska->num_tracks++;
+
+ /* start with the master */
+ if ((res = ebml_read_master(matroska, &id)) < 0)
+ return res;
+
+ /* try reading the trackentry headers */
+ while (res == 0) {
+ if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
+ res = AVERROR_IO;
+ break;
+ } else if (matroska->level_up > 0) {
+ matroska->level_up--;
+ break;
+ }
+
+ switch (id) {
+ /* track number (unique stream ID) */
+ case MATROSKA_ID_TRACKNUMBER: {
+ uint64_t num;
+ if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
+ break;
+ track->num = num;
+ break;
+ }
+
+ /* track UID (unique identifier) */
+ case MATROSKA_ID_TRACKUID: {
+ uint64_t num;
+ if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
+ break;
+ track->uid = num;
+ break;
+ }
+
+ /* track type (video, audio, combined, subtitle, etc.) */
+ case MATROSKA_ID_TRACKTYPE: {
+ uint64_t num;
+ if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
+ break;
+ if (track->type && track->type != num) {
+ av_log(matroska->ctx, AV_LOG_INFO,
+ "More than one tracktype in an entry - skip\n");
+ break;
+ }
+ track->type = num;
+
+ switch (track->type) {
+ case MATROSKA_TRACK_TYPE_VIDEO:
+ case MATROSKA_TRACK_TYPE_AUDIO:
+ case MATROSKA_TRACK_TYPE_SUBTITLE:
+ break;
+ case MATROSKA_TRACK_TYPE_COMPLEX:
+ case MATROSKA_TRACK_TYPE_LOGO:
+ case MATROSKA_TRACK_TYPE_CONTROL:
+ default:
+ av_log(matroska->ctx, AV_LOG_INFO,
+ "Unknown or unsupported track type 0x%x\n",
+ track->type);
+ track->type = 0;
+ break;
+ }
+ matroska->tracks[matroska->num_tracks - 1] = track;
+ break;
+ }
+
+ /* tracktype specific stuff for video */
+ case MATROSKA_ID_TRACKVIDEO: {
+ MatroskaVideoTrack *videotrack;
+ if (!track->type)
+ track->type = MATROSKA_TRACK_TYPE_VIDEO;
+ if (track->type != MATROSKA_TRACK_TYPE_VIDEO) {
+ av_log(matroska->ctx, AV_LOG_INFO,
+ "video data in non-video track - ignoring\n");
+ res = AVERROR_INVALIDDATA;
+ break;
+ } else if ((res = ebml_read_master(matroska, &id)) < 0)
+ break;
+ videotrack = (MatroskaVideoTrack *)track;
+
+ while (res == 0) {
+ if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
+ res = AVERROR_IO;
+ break;
+ } else if (matroska->level_up > 0) {
+ matroska->level_up--;
+ break;
+ }
+
+ switch (id) {
+ /* fixme, this should be one-up, but I get it here */
+ case MATROSKA_ID_TRACKDEFAULTDURATION: {
+ uint64_t num;
+ if ((res = ebml_read_uint (matroska, &id,
+ &num)) < 0)
+ break;
+ track->default_duration = num/matroska->time_scale;
+ break;
+ }
+
+ /* video framerate */
+ case MATROSKA_ID_VIDEOFRAMERATE: {
+ double num;
+ if ((res = ebml_read_float(matroska, &id,
+ &num)) < 0)
+ break;
+ track->default_duration = 1000000000/(matroska->time_scale*num);
+ break;
+ }
+
+ /* width of the size to display the video at */
+ case MATROSKA_ID_VIDEODISPLAYWIDTH: {
+ uint64_t num;
+ if ((res = ebml_read_uint(matroska, &id,
+ &num)) < 0)
+ break;
+ videotrack->display_width = num;
+ break;
+ }
+
+ /* height of the size to display the video at */
+ case MATROSKA_ID_VIDEODISPLAYHEIGHT: {
+ uint64_t num;
+ if ((res = ebml_read_uint(matroska, &id,
+ &num)) < 0)
+ break;
+ videotrack->display_height = num;
+ break;
+ }
+
+ /* width of the video in the file */
+ case MATROSKA_ID_VIDEOPIXELWIDTH: {
+ uint64_t num;
+ if ((res = ebml_read_uint(matroska, &id,
+ &num)) < 0)
+ break;
+ videotrack->pixel_width = num;
+ break;
+ }
+
+ /* height of the video in the file */
+ case MATROSKA_ID_VIDEOPIXELHEIGHT: {
+ uint64_t num;
+ if ((res = ebml_read_uint(matroska, &id,
+ &num)) < 0)
+ break;
+ videotrack->pixel_height = num;
+ break;
+ }
+
+ /* whether the video is interlaced */
+ case MATROSKA_ID_VIDEOFLAGINTERLACED: {
+ uint64_t num;
+ if ((res = ebml_read_uint(matroska, &id,
+ &num)) < 0)
+ break;
+ if (num)
+ track->flags |=
+ MATROSKA_VIDEOTRACK_INTERLACED;
+ else
+ track->flags &=
+ ~MATROSKA_VIDEOTRACK_INTERLACED;
+ break;
+ }
+
+ /* stereo mode (whether the video has two streams,
+ * where one is for the left eye and the other for
+ * the right eye, which creates a 3D-like
+ * effect) */
+ case MATROSKA_ID_VIDEOSTEREOMODE: {
+ uint64_t num;
+ if ((res = ebml_read_uint(matroska, &id,
+ &num)) < 0)
+ break;
+ if (num != MATROSKA_EYE_MODE_MONO &&
+ num != MATROSKA_EYE_MODE_LEFT &&
+ num != MATROSKA_EYE_MODE_RIGHT &&
+ num != MATROSKA_EYE_MODE_BOTH) {
+ av_log(matroska->ctx, AV_LOG_INFO,
+ "Ignoring unknown eye mode 0x%x\n",
+ (uint32_t) num);
+ break;
+ }
+ videotrack->eye_mode = num;
+ break;
+ }
+
+ /* aspect ratio behaviour */
+ case MATROSKA_ID_VIDEOASPECTRATIO: {
+ uint64_t num;
+ if ((res = ebml_read_uint(matroska, &id,
+ &num)) < 0)
+ break;
+ if (num != MATROSKA_ASPECT_RATIO_MODE_FREE &&
+ num != MATROSKA_ASPECT_RATIO_MODE_KEEP &&
+ num != MATROSKA_ASPECT_RATIO_MODE_FIXED) {
+ av_log(matroska->ctx, AV_LOG_INFO,
+ "Ignoring unknown aspect ratio 0x%x\n",
+ (uint32_t) num);
+ break;
+ }
+ videotrack->ar_mode = num;
+ break;
+ }
+
+ /* colourspace (only matters for raw video)
+ * fourcc */
+ case MATROSKA_ID_VIDEOCOLOURSPACE: {
+ uint64_t num;
+ if ((res = ebml_read_uint(matroska, &id,
+ &num)) < 0)
+ break;
+ videotrack->fourcc = num;
+ break;
+ }
+
+ default:
+ av_log(matroska->ctx, AV_LOG_INFO,
+ "Unknown video track header entry "
+ "0x%x - ignoring\n", id);
+ /* pass-through */
+
+ case EBML_ID_VOID:
+ res = ebml_read_skip(matroska);
+ break;
+ }
+
+ if (matroska->level_up) {
+ matroska->level_up--;
+ break;
+ }
+ }
+ break;
+ }
+
+ /* tracktype specific stuff for audio */
+ case MATROSKA_ID_TRACKAUDIO: {
+ MatroskaAudioTrack *audiotrack;
+ if (!track->type)
+ track->type = MATROSKA_TRACK_TYPE_AUDIO;
+ if (track->type != MATROSKA_TRACK_TYPE_AUDIO) {
+ av_log(matroska->ctx, AV_LOG_INFO,
+ "audio data in non-audio track - ignoring\n");
+ res = AVERROR_INVALIDDATA;
+ break;
+ } else if ((res = ebml_read_master(matroska, &id)) < 0)
+ break;
+ audiotrack = (MatroskaAudioTrack *)track;
+ audiotrack->channels = 1;
+ audiotrack->samplerate = 8000;
+
+ while (res == 0) {
+ if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
+ res = AVERROR_IO;
+ break;
+ } else if (matroska->level_up > 0) {
+ matroska->level_up--;
+ break;
+ }
+
+ switch (id) {
+ /* samplerate */
+ case MATROSKA_ID_AUDIOSAMPLINGFREQ: {
+ double num;
+ if ((res = ebml_read_float(matroska, &id,
+ &num)) < 0)
+ break;
+ audiotrack->internal_samplerate =
+ audiotrack->samplerate = num;
+ break;
+ }
+
+ case MATROSKA_ID_AUDIOOUTSAMPLINGFREQ: {
+ double num;
+ if ((res = ebml_read_float(matroska, &id,
+ &num)) < 0)
+ break;
+ audiotrack->samplerate = num;
+ break;
+ }
+
+ /* bitdepth */
+ case MATROSKA_ID_AUDIOBITDEPTH: {
+ uint64_t num;
+ if ((res = ebml_read_uint(matroska, &id,
+ &num)) < 0)
+ break;
+ audiotrack->bitdepth = num;
+ break;
+ }
+
+ /* channels */
+ case MATROSKA_ID_AUDIOCHANNELS: {
+ uint64_t num;
+ if ((res = ebml_read_uint(matroska, &id,
+ &num)) < 0)
+ break;
+ audiotrack->channels = num;
+ break;
+ }
+
+ default:
+ av_log(matroska->ctx, AV_LOG_INFO,
+ "Unknown audio track header entry "
+ "0x%x - ignoring\n", id);
+ /* pass-through */
+
+ case EBML_ID_VOID:
+ res = ebml_read_skip(matroska);
+ break;
+ }
+
+ if (matroska->level_up) {
+ matroska->level_up--;
+ break;
+ }
+ }
+ break;
+ }
+
+ /* codec identifier */
+ case MATROSKA_ID_CODECID: {
+ char *text;
+ if ((res = ebml_read_ascii(matroska, &id, &text)) < 0)
+ break;
+ track->codec_id = text;
+ break;
+ }
+
+ /* codec private data */
+ case MATROSKA_ID_CODECPRIVATE: {
+ uint8_t *data;
+ int size;
+ if ((res = ebml_read_binary(matroska, &id, &data, &size) < 0))
+ break;
+ track->codec_priv = data;
+ track->codec_priv_size = size;
+ break;
+ }
+
+ /* name of the codec */
+ case MATROSKA_ID_CODECNAME: {
+ char *text;
+ if ((res = ebml_read_utf8(matroska, &id, &text)) < 0)
+ break;
+ track->codec_name = text;
+ break;
+ }
+
+ /* name of this track */
+ case MATROSKA_ID_TRACKNAME: {
+ char *text;
+ if ((res = ebml_read_utf8(matroska, &id, &text)) < 0)
+ break;
+ track->name = text;
+ break;
+ }
+
+ /* language (matters for audio/subtitles, mostly) */
+ case MATROSKA_ID_TRACKLANGUAGE: {
+ char *text;
+ if ((res = ebml_read_utf8(matroska, &id, &text)) < 0)
+ break;
+ track->language = text;
+ break;
+ }
+
+ /* whether this is actually used */
+ case MATROSKA_ID_TRACKFLAGENABLED: {
+ uint64_t num;
+ if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
+ break;
+ if (num)
+ track->flags |= MATROSKA_TRACK_ENABLED;
+ else
+ track->flags &= ~MATROSKA_TRACK_ENABLED;
+ break;
+ }
+
+ /* whether it's the default for this track type */
+ case MATROSKA_ID_TRACKFLAGDEFAULT: {
+ uint64_t num;
+ if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
+ break;
+ if (num)
+ track->flags |= MATROSKA_TRACK_DEFAULT;
+ else
+ track->flags &= ~MATROSKA_TRACK_DEFAULT;
+ break;
+ }
+
+ /* lacing (like MPEG, where blocks don't end/start on frame
+ * boundaries) */
+ case MATROSKA_ID_TRACKFLAGLACING: {
+ uint64_t num;
+ if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
+ break;
+ if (num)
+ track->flags |= MATROSKA_TRACK_LACING;
+ else
+ track->flags &= ~MATROSKA_TRACK_LACING;
+ break;
+ }
+
+ /* default length (in time) of one data block in this track */
+ case MATROSKA_ID_TRACKDEFAULTDURATION: {
+ uint64_t num;
+ if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
+ break;
+ track->default_duration = num / matroska->time_scale;
+ break;
+ }
+
+ default:
+ av_log(matroska->ctx, AV_LOG_INFO,
+ "Unknown track header entry 0x%x - ignoring\n", id);
+ /* pass-through */
+
+ case EBML_ID_VOID:
+ /* we ignore these because they're nothing useful. */
+ case MATROSKA_ID_CODECINFOURL:
+ case MATROSKA_ID_CODECDOWNLOADURL:
+ case MATROSKA_ID_TRACKMINCACHE:
+ case MATROSKA_ID_TRACKMAXCACHE:
+ res = ebml_read_skip(matroska);
+ break;
+ }
+
+ if (matroska->level_up) {
+ matroska->level_up--;
+ break;
+ }
+ }
+
+ return res;
+}
+
+static int
+matroska_parse_tracks (MatroskaDemuxContext *matroska)
+{
+ int res = 0;
+ uint32_t id;
+
+ av_log(matroska->ctx, AV_LOG_DEBUG, "parsing tracks...\n");
+
+ while (res == 0) {
+ if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
+ res = AVERROR_IO;
+ break;
+ } else if (matroska->level_up) {
+ matroska->level_up--;
+ break;
+ }
+
+ switch (id) {
+ /* one track within the "all-tracks" header */
+ case MATROSKA_ID_TRACKENTRY:
+ res = matroska_add_stream(matroska);
+ break;
+
+ default:
+ av_log(matroska->ctx, AV_LOG_INFO,
+ "Unknown entry 0x%x in track header\n", id);
+ /* fall-through */
+
+ case EBML_ID_VOID:
+ res = ebml_read_skip(matroska);
+ break;
+ }
+
+ if (matroska->level_up) {
+ matroska->level_up--;
+ break;
+ }
+ }
+
+ return res;
+}
+
+static int
+matroska_parse_index (MatroskaDemuxContext *matroska)
+{
+ int res = 0;
+ uint32_t id;
+ MatroskaDemuxIndex idx;
+
+ av_log(matroska->ctx, AV_LOG_DEBUG, "parsing index...\n");
+
+ while (res == 0) {
+ if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
+ res = AVERROR_IO;
+ break;
+ } else if (matroska->level_up) {
+ matroska->level_up--;
+ break;
+ }
+
+ switch (id) {
+ /* one single index entry ('point') */
+ case MATROSKA_ID_POINTENTRY:
+ if ((res = ebml_read_master(matroska, &id)) < 0)
+ break;
+
+ /* in the end, we hope to fill one entry with a
+ * timestamp, a file position and a tracknum */
+ idx.pos = (uint64_t) -1;
+ idx.time = (uint64_t) -1;
+ idx.track = (uint16_t) -1;
+
+ while (res == 0) {
+ if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
+ res = AVERROR_IO;
+ break;
+ } else if (matroska->level_up) {
+ matroska->level_up--;
+ break;
+ }
+
+ switch (id) {
+ /* one single index entry ('point') */
+ case MATROSKA_ID_CUETIME: {
+ uint64_t time;
+ if ((res = ebml_read_uint(matroska, &id,
+ &time)) < 0)
+ break;
+ idx.time = time * matroska->time_scale;
+ break;
+ }
+
+ /* position in the file + track to which it
+ * belongs */
+ case MATROSKA_ID_CUETRACKPOSITION:
+ if ((res = ebml_read_master(matroska, &id)) < 0)
+ break;
+
+ while (res == 0) {
+ if (!(id = ebml_peek_id (matroska,
+ &matroska->level_up))) {
+ res = AVERROR_IO;
+ break;
+ } else if (matroska->level_up) {
+ matroska->level_up--;
+ break;
+ }
+
+ switch (id) {
+ /* track number */
+ case MATROSKA_ID_CUETRACK: {
+ uint64_t num;
+ if ((res = ebml_read_uint(matroska,
+ &id, &num)) < 0)
+ break;
+ idx.track = num;
+ break;
+ }
+
+ /* position in file */
+ case MATROSKA_ID_CUECLUSTERPOSITION: {
+ uint64_t num;
+ if ((res = ebml_read_uint(matroska,
+ &id, &num)) < 0)
+ break;
+ idx.pos = num;
+ break;
+ }
+
+ default:
+ av_log(matroska->ctx, AV_LOG_INFO,
+ "Unknown entry 0x%x in "
+ "CuesTrackPositions\n", id);
+ /* fall-through */
+
+ case EBML_ID_VOID:
+ res = ebml_read_skip(matroska);
+ break;
+ }
+
+ if (matroska->level_up) {
+ matroska->level_up--;
+ break;
+ }
+ }
+
+ break;
+
+ default:
+ av_log(matroska->ctx, AV_LOG_INFO,
+ "Unknown entry 0x%x in cuespoint "
+ "index\n", id);
+ /* fall-through */
+
+ case EBML_ID_VOID:
+ res = ebml_read_skip(matroska);
+ break;
+ }
+
+ if (matroska->level_up) {
+ matroska->level_up--;
+ break;
+ }
+ }
+
+ /* so let's see if we got what we wanted */
+ if (idx.pos != (uint64_t) -1 &&
+ idx.time != (uint64_t) -1 &&
+ idx.track != (uint16_t) -1) {
+ if (matroska->num_indexes % 32 == 0) {
+ /* re-allocate bigger index */
+ matroska->index =
+ av_realloc(matroska->index,
+ (matroska->num_indexes + 32) *
+ sizeof(MatroskaDemuxIndex));
+ }
+ matroska->index[matroska->num_indexes] = idx;
+ matroska->num_indexes++;
+ }
+ break;
+
+ default:
+ av_log(matroska->ctx, AV_LOG_INFO,
+ "Unknown entry 0x%x in cues header\n", id);
+ /* fall-through */
+
+ case EBML_ID_VOID:
+ res = ebml_read_skip(matroska);
+ break;
+ }
+
+ if (matroska->level_up) {
+ matroska->level_up--;
+ break;
+ }
+ }
+
+ return res;
+}
+
+static int
+matroska_parse_metadata (MatroskaDemuxContext *matroska)
+{
+ int res = 0;
+ uint32_t id;
+
+ while (res == 0) {
+ if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
+ res = AVERROR_IO;
+ break;
+ } else if (matroska->level_up) {
+ matroska->level_up--;
+ break;
+ }
+
+ switch (id) {
+ /* Hm, this is unsupported... */
+ default:
+ av_log(matroska->ctx, AV_LOG_INFO,
+ "Unknown entry 0x%x in metadata header\n", id);
+ /* fall-through */
+
+ case EBML_ID_VOID:
+ res = ebml_read_skip(matroska);
+ break;
+ }
+
+ if (matroska->level_up) {
+ matroska->level_up--;
+ break;
+ }
+ }
+
+ return res;
+}
+
+static int
+matroska_parse_seekhead (MatroskaDemuxContext *matroska)
+{
+ int res = 0;
+ uint32_t id;
+
+ av_log(matroska->ctx, AV_LOG_DEBUG, "parsing seekhead...\n");
+
+ while (res == 0) {
+ if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
+ res = AVERROR_IO;
+ break;
+ } else if (matroska->level_up) {
+ matroska->level_up--;
+ break;
+ }
+
+ switch (id) {
+ case MATROSKA_ID_SEEKENTRY: {
+ uint32_t seek_id = 0, peek_id_cache = 0;
+ uint64_t seek_pos = (uint64_t) -1, t;
+
+ if ((res = ebml_read_master(matroska, &id)) < 0)
+ break;
+
+ while (res == 0) {
+ if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
+ res = AVERROR_IO;
+ break;
+ } else if (matroska->level_up) {
+ matroska->level_up--;
+ break;
+ }
+
+ switch (id) {
+ case MATROSKA_ID_SEEKID:
+ res = ebml_read_uint(matroska, &id, &t);
+ seek_id = t;
+ break;
+
+ case MATROSKA_ID_SEEKPOSITION:
+ res = ebml_read_uint(matroska, &id, &seek_pos);
+ break;
+
+ default:
+ av_log(matroska->ctx, AV_LOG_INFO,
+ "Unknown seekhead ID 0x%x\n", id);
+ /* fall-through */
+
+ case EBML_ID_VOID:
+ res = ebml_read_skip(matroska);
+ break;
+ }
+
+ if (matroska->level_up) {
+ matroska->level_up--;
+ break;
+ }
+ }
+
+ if (!seek_id || seek_pos == (uint64_t) -1) {
+ av_log(matroska->ctx, AV_LOG_INFO,
+ "Incomplete seekhead entry (0x%x/%"PRIu64")\n",
+ seek_id, seek_pos);
+ break;
+ }
+
+ switch (seek_id) {
+ case MATROSKA_ID_CUES:
+ case MATROSKA_ID_TAGS: {
+ uint32_t level_up = matroska->level_up;
+ offset_t before_pos;
+ uint64_t length;
+ MatroskaLevel level;
+
+ /* remember the peeked ID and the current position */
+ peek_id_cache = matroska->peek_id;
+ before_pos = url_ftell(&matroska->ctx->pb);
+
+ /* seek */
+ if ((res = ebml_read_seek(matroska, seek_pos +
+ matroska->segment_start)) < 0)
+ return res;
+
+ /* we don't want to lose our seekhead level, so we add
+ * a dummy. This is a crude hack. */
+ if (matroska->num_levels == EBML_MAX_DEPTH) {
+ av_log(matroska->ctx, AV_LOG_INFO,
+ "Max EBML element depth (%d) reached, "
+ "cannot parse further.\n", EBML_MAX_DEPTH);
+ return AVERROR_UNKNOWN;
+ }
+
+ level.start = 0;
+ level.length = (uint64_t)-1;
+ matroska->levels[matroska->num_levels] = level;
+ matroska->num_levels++;
+
+ /* check ID */
+ if (!(id = ebml_peek_id (matroska,
+ &matroska->level_up)))
+ goto finish;
+ if (id != seek_id) {
+ av_log(matroska->ctx, AV_LOG_INFO,
+ "We looked for ID=0x%x but got "
+ "ID=0x%x (pos=%"PRIu64")",
+ seek_id, id, seek_pos +
+ matroska->segment_start);
+ goto finish;
+ }
+
+ /* read master + parse */
+ if ((res = ebml_read_master(matroska, &id)) < 0)
+ goto finish;
+ switch (id) {
+ case MATROSKA_ID_CUES:
+ if (!(res = matroska_parse_index(matroska)) ||
+ url_feof(&matroska->ctx->pb)) {
+ matroska->index_parsed = 1;
+ res = 0;
+ }
+ break;
+ case MATROSKA_ID_TAGS:
+ if (!(res = matroska_parse_metadata(matroska)) ||
+ url_feof(&matroska->ctx->pb)) {
+ matroska->metadata_parsed = 1;
+ res = 0;
+ }
+ break;
+ }
+
+ finish:
+ /* remove dummy level */
+ while (matroska->num_levels) {
+ matroska->num_levels--;
+ length =
+ matroska->levels[matroska->num_levels].length;
+ if (length == (uint64_t)-1)
+ break;
+ }
+
+ /* seek back */
+ if ((res = ebml_read_seek(matroska, before_pos)) < 0)
+ return res;
+ matroska->peek_id = peek_id_cache;
+ matroska->level_up = level_up;
+ break;
+ }
+
+ default:
+ av_log(matroska->ctx, AV_LOG_INFO,
+ "Ignoring seekhead entry for ID=0x%x\n",
+ seek_id);
+ break;
+ }
+
+ break;
+ }
+
+ default:
+ av_log(matroska->ctx, AV_LOG_INFO,
+ "Unknown seekhead ID 0x%x\n", id);
+ /* fall-through */
+
+ case EBML_ID_VOID:
+ res = ebml_read_skip(matroska);
+ break;
+ }
+
+ if (matroska->level_up) {
+ matroska->level_up--;
+ break;
+ }
+ }
+
+ return res;
+}
+
+#define ARRAY_SIZE(x) (sizeof(x)/sizeof(*x))
+
+static int
+matroska_aac_profile (char *codec_id)
+{
+ static const char *aac_profiles[] = {
+ "MAIN", "LC", "SSR"
+ };
+ int profile;
+
+ for (profile=0; profile<ARRAY_SIZE(aac_profiles); profile++)
+ if (strstr(codec_id, aac_profiles[profile]))
+ break;
+ return profile + 1;
+}
+
+static int
+matroska_aac_sri (int samplerate)
+{
+ static const int aac_sample_rates[] = {
+ 96000, 88200, 64000, 48000, 44100, 32000,
+ 24000, 22050, 16000, 12000, 11025, 8000,
+ };
+ int sri;
+
+ for (sri=0; sri<ARRAY_SIZE(aac_sample_rates); sri++)
+ if (aac_sample_rates[sri] == samplerate)
+ break;
+ return sri;
+}
+
+static int
+matroska_read_header (AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ MatroskaDemuxContext *matroska = s->priv_data;
+ char *doctype;
+ int version, last_level, res = 0;
+ uint32_t id;
+
+ matroska->ctx = s;
+
+ /* First read the EBML header. */
+ doctype = NULL;
+ if ((res = ebml_read_header(matroska, &doctype, &version)) < 0)
+ return res;
+ if ((doctype == NULL) || strcmp(doctype, "matroska")) {
+ av_log(matroska->ctx, AV_LOG_ERROR,
+ "Wrong EBML doctype ('%s' != 'matroska').\n",
+ doctype ? doctype : "(none)");
+ if (doctype)
+ av_free(doctype);
+ return AVERROR_NOFMT;
+ }
+ av_free(doctype);
+ if (version > 2) {
+ av_log(matroska->ctx, AV_LOG_ERROR,
+ "Matroska demuxer version 2 too old for file version %d\n",
+ version);
+ return AVERROR_NOFMT;
+ }
+
+ /* The next thing is a segment. */
+ while (1) {
+ if (!(id = ebml_peek_id(matroska, &last_level)))
+ return AVERROR_IO;
+ if (id == MATROSKA_ID_SEGMENT)
+ break;
+
+ /* oi! */
+ av_log(matroska->ctx, AV_LOG_INFO,
+ "Expected a Segment ID (0x%x), but received 0x%x!\n",
+ MATROSKA_ID_SEGMENT, id);
+ if ((res = ebml_read_skip(matroska)) < 0)
+ return res;
+ }
+
+ /* We now have a Matroska segment.
+ * Seeks are from the beginning of the segment,
+ * after the segment ID/length. */
+ if ((res = ebml_read_master(matroska, &id)) < 0)
+ return res;
+ matroska->segment_start = url_ftell(&s->pb);
+
+ matroska->time_scale = 1000000;
+ /* we've found our segment, start reading the different contents in here */
+ while (res == 0) {
+ if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
+ res = AVERROR_IO;
+ break;
+ } else if (matroska->level_up) {
+ matroska->level_up--;
+ break;
+ }
+
+ switch (id) {
+ /* stream info */
+ case MATROSKA_ID_INFO: {
+ if ((res = ebml_read_master(matroska, &id)) < 0)
+ break;
+ res = matroska_parse_info(matroska);
+ break;
+ }
+
+ /* track info headers */
+ case MATROSKA_ID_TRACKS: {
+ if ((res = ebml_read_master(matroska, &id)) < 0)
+ break;
+ res = matroska_parse_tracks(matroska);
+ break;
+ }
+
+ /* stream index */
+ case MATROSKA_ID_CUES: {
+ if (!matroska->index_parsed) {
+ if ((res = ebml_read_master(matroska, &id)) < 0)
+ break;
+ res = matroska_parse_index(matroska);
+ } else
+ res = ebml_read_skip(matroska);
+ break;
+ }
+
+ /* metadata */
+ case MATROSKA_ID_TAGS: {
+ if (!matroska->metadata_parsed) {
+ if ((res = ebml_read_master(matroska, &id)) < 0)
+ break;
+ res = matroska_parse_metadata(matroska);
+ } else
+ res = ebml_read_skip(matroska);
+ break;
+ }
+
+ /* file index (if seekable, seek to Cues/Tags to parse it) */
+ case MATROSKA_ID_SEEKHEAD: {
+ if ((res = ebml_read_master(matroska, &id)) < 0)
+ break;
+ res = matroska_parse_seekhead(matroska);
+ break;
+ }
+
+ case MATROSKA_ID_CLUSTER: {
+ /* Do not read the master - this will be done in the next
+ * call to matroska_read_packet. */
+ res = 1;
+ break;
+ }
+
+ default:
+ av_log(matroska->ctx, AV_LOG_INFO,
+ "Unknown matroska file header ID 0x%x\n", id);
+ /* fall-through */
+
+ case EBML_ID_VOID:
+ res = ebml_read_skip(matroska);
+ break;
+ }
+
+ if (matroska->level_up) {
+ matroska->level_up--;
+ break;
+ }
+ }
+
+ /* Have we found a cluster? */
+ if (ebml_peek_id(matroska, NULL) == MATROSKA_ID_CLUSTER) {
+ int i, j;
+ MatroskaTrack *track;
+ AVStream *st;
+
+ for (i = 0; i < matroska->num_tracks; i++) {
+ enum CodecID codec_id = CODEC_ID_NONE;
+ uint8_t *extradata = NULL;
+ int extradata_size = 0;
+ int extradata_offset = 0;
+ track = matroska->tracks[i];
+
+ /* libavformat does not really support subtitles.
+ * Also apply some sanity checks. */
+ if ((track->type == MATROSKA_TRACK_TYPE_SUBTITLE) ||
+ (track->codec_id == NULL))
+ continue;
+
+ for(j=0; codec_tags[j].str; j++){
+ if(!strncmp(codec_tags[j].str, track->codec_id,
+ strlen(codec_tags[j].str))){
+ codec_id= codec_tags[j].id;
+ break;
+ }
+ }
+
+ /* Set the FourCC from the CodecID. */
+ /* This is the MS compatibility mode which stores a
+ * BITMAPINFOHEADER in the CodecPrivate. */
+ if (!strcmp(track->codec_id,
+ MATROSKA_CODEC_ID_VIDEO_VFW_FOURCC) &&
+ (track->codec_priv_size >= 40) &&
+ (track->codec_priv != NULL)) {
+ unsigned char *p;
+
+ /* Offset of biCompression. Stored in LE. */
+ p = (unsigned char *)track->codec_priv + 16;
+ ((MatroskaVideoTrack *)track)->fourcc = (p[3] << 24) |
+ (p[2] << 16) | (p[1] << 8) | p[0];
+ codec_id = codec_get_id(codec_bmp_tags, ((MatroskaVideoTrack *)track)->fourcc);
+
+ }
+
+ /* This is the MS compatibility mode which stores a
+ * WAVEFORMATEX in the CodecPrivate. */
+ else if (!strcmp(track->codec_id,
+ MATROSKA_CODEC_ID_AUDIO_ACM) &&
+ (track->codec_priv_size >= 18) &&
+ (track->codec_priv != NULL)) {
+ unsigned char *p;
+ uint16_t tag;
+
+ /* Offset of wFormatTag. Stored in LE. */
+ p = (unsigned char *)track->codec_priv;
+ tag = (p[1] << 8) | p[0];
+ codec_id = codec_get_id(codec_wav_tags, tag);
+
+ }
+
+ else if (codec_id == CODEC_ID_AAC && !track->codec_priv_size) {
+ MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *) track;
+ int profile = matroska_aac_profile(track->codec_id);
+ int sri = matroska_aac_sri(audiotrack->internal_samplerate);
+ extradata = av_malloc(5);
+ if (extradata == NULL)
+ return AVERROR_NOMEM;
+ extradata[0] = (profile << 3) | ((sri&0x0E) >> 1);
+ extradata[1] = ((sri&0x01) << 7) | (audiotrack->channels<<3);
+ if (strstr(track->codec_id, "SBR")) {
+ sri = matroska_aac_sri(audiotrack->samplerate);
+ extradata[2] = 0x56;
+ extradata[3] = 0xE5;
+ extradata[4] = 0x80 | (sri<<3);
+ extradata_size = 5;
+ } else {
+ extradata_size = 2;
+ }
+ track->default_duration = 1024*1000 / audiotrack->internal_samplerate;
+ }
+
+ else if (codec_id == CODEC_ID_TTA) {
+ MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *) track;
+ ByteIOContext b;
+ extradata_size = 30;
+ extradata = av_mallocz(extradata_size);
+ if (extradata == NULL)
+ return AVERROR_NOMEM;
+ init_put_byte(&b, extradata, extradata_size, 1,
+ NULL, NULL, NULL, NULL);
+ put_buffer(&b, (uint8_t *) "TTA1", 4);
+ put_le16(&b, 1);
+ put_le16(&b, audiotrack->channels);
+ put_le16(&b, audiotrack->bitdepth);
+ put_le32(&b, audiotrack->samplerate);
+ put_le32(&b, matroska->ctx->duration * audiotrack->samplerate);
+ }
+
+ 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;
+ track->flags |= MATROSKA_TRACK_REAL_V;
+ }
+
+ if (codec_id == CODEC_ID_NONE) {
+ av_log(matroska->ctx, AV_LOG_INFO,
+ "Unknown/unsupported CodecID %s.\n",
+ track->codec_id);
+ }
+
+ track->stream_index = matroska->num_streams;
+
+ matroska->num_streams++;
+ st = av_new_stream(s, track->stream_index);
+ if (st == NULL)
+ return AVERROR_NOMEM;
+ av_set_pts_info(st, 64, matroska->time_scale, 1000*1000*1000); /* 64 bit pts in ns */
+
+ st->codec->codec_id = codec_id;
+
+ if (track->default_duration)
+ av_reduce(&st->codec->time_base.num, &st->codec->time_base.den,
+ track->default_duration, 1000, 30000);
+
+ if(extradata){
+ st->codec->extradata = extradata;
+ st->codec->extradata_size = extradata_size;
+ } else if(track->codec_priv && track->codec_priv_size > 0){
+ st->codec->extradata = av_malloc(track->codec_priv_size);
+ if(st->codec->extradata == NULL)
+ return AVERROR_NOMEM;
+ st->codec->extradata_size = track->codec_priv_size;
+ memcpy(st->codec->extradata,track->codec_priv+extradata_offset,
+ track->codec_priv_size);
+ }
+
+ if (track->type == MATROSKA_TRACK_TYPE_VIDEO) {
+ MatroskaVideoTrack *videotrack = (MatroskaVideoTrack *)track;
+
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ st->codec->codec_tag = videotrack->fourcc;
+ st->codec->width = videotrack->pixel_width;
+ st->codec->height = videotrack->pixel_height;
+ if (videotrack->display_width == 0)
+ videotrack->display_width= videotrack->pixel_width;
+ if (videotrack->display_height == 0)
+ videotrack->display_height= videotrack->pixel_height;
+ av_reduce(&st->codec->sample_aspect_ratio.num,
+ &st->codec->sample_aspect_ratio.den,
+ st->codec->height * videotrack->display_width,
+ st->codec-> width * videotrack->display_height,
+ 255);
+ st->need_parsing = 2;
+ } else if (track->type == MATROSKA_TRACK_TYPE_AUDIO) {
+ MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *)track;
+
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->sample_rate = audiotrack->samplerate;
+ st->codec->channels = audiotrack->channels;
+ } else if (track->type == MATROSKA_TRACK_TYPE_SUBTITLE) {
+ st->codec->codec_type = CODEC_TYPE_SUBTITLE;
+ }
+
+ /* What do we do with private data? E.g. for Vorbis. */
+ }
+ res = 0;
+ }
+
+ return res;
+}
+
+static int
+matroska_find_track_by_num (MatroskaDemuxContext *matroska,
+ int num)
+{
+ int i;
+
+ for (i = 0; i < matroska->num_tracks; i++)
+ if (matroska->tracks[i]->num == num)
+ return i;
+
+ return -1;
+}
+
+static inline int
+rv_offset(uint8_t *data, int slice, int slices)
+{
+ return AV_RL32(data+8*slice+4) + 8*slices;
+}
+
+static int
+matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, int size,
+ int64_t pos, uint64_t cluster_time, uint64_t duration,
+ int is_keyframe, int is_bframe)
+{
+ int res = 0;
+ int track;
+ AVPacket *pkt;
+ uint8_t *origdata = data;
+ int16_t block_time;
+ uint32_t *lace_size = NULL;
+ int n, flags, laces = 0;
+ uint64_t num;
+
+ /* first byte(s): tracknum */
+ if ((n = matroska_ebmlnum_uint(data, size, &num)) < 0) {
+ av_log(matroska->ctx, AV_LOG_ERROR, "EBML block data error\n");
+ av_free(origdata);
+ return res;
+ }
+ data += n;
+ size -= n;
+
+ /* fetch track from num */
+ track = matroska_find_track_by_num(matroska, num);
+ if (size <= 3 || track < 0 || track >= matroska->num_tracks) {
+ av_log(matroska->ctx, AV_LOG_INFO,
+ "Invalid stream %d or size %u\n", track, size);
+ av_free(origdata);
+ return res;
+ }
+ if(matroska->ctx->streams[ matroska->tracks[track]->stream_index ]->discard >= AVDISCARD_ALL){
+ av_free(origdata);
+ return res;
+ }
+ if (duration == AV_NOPTS_VALUE)
+ duration = matroska->tracks[track]->default_duration;
+
+ /* block_time (relative to cluster time) */
+ block_time = (data[0] << 8) | data[1];
+ data += 2;
+ size -= 2;
+ flags = *data;
+ data += 1;
+ size -= 1;
+ if (is_keyframe == -1)
+ is_keyframe = flags & 1 ? PKT_FLAG_KEY : 0;
+ switch ((flags & 0x06) >> 1) {
+ case 0x0: /* no lacing */
+ laces = 1;
+ lace_size = av_mallocz(sizeof(int));
+ lace_size[0] = size;
+ break;
+
+ case 0x1: /* xiph lacing */
+ case 0x2: /* fixed-size lacing */
+ case 0x3: /* EBML lacing */
+ if (size == 0) {
+ res = -1;
+ break;
+ }
+ laces = (*data) + 1;
+ data += 1;
+ size -= 1;
+ lace_size = av_mallocz(laces * sizeof(int));
+
+ switch ((flags & 0x06) >> 1) {
+ case 0x1: /* xiph lacing */ {
+ uint8_t temp;
+ uint32_t total = 0;
+ for (n = 0; res == 0 && n < laces - 1; n++) {
+ while (1) {
+ if (size == 0) {
+ res = -1;
+ break;
+ }
+ temp = *data;
+ lace_size[n] += temp;
+ data += 1;
+ size -= 1;
+ if (temp != 0xff)
+ break;
+ }
+ total += lace_size[n];
+ }
+ lace_size[n] = size - total;
+ break;
+ }
+
+ case 0x2: /* fixed-size lacing */
+ for (n = 0; n < laces; n++)
+ lace_size[n] = size / laces;
+ break;
+
+ case 0x3: /* EBML lacing */ {
+ uint32_t total;
+ n = matroska_ebmlnum_uint(data, size, &num);
+ if (n < 0) {
+ av_log(matroska->ctx, AV_LOG_INFO,
+ "EBML block data error\n");
+ break;
+ }
+ data += n;
+ size -= n;
+ total = lace_size[0] = num;
+ for (n = 1; res == 0 && n < laces - 1; n++) {
+ int64_t snum;
+ int r;
+ r = matroska_ebmlnum_sint (data, size, &snum);
+ if (r < 0) {
+ av_log(matroska->ctx, AV_LOG_INFO,
+ "EBML block data error\n");
+ break;
+ }
+ data += r;
+ size -= r;
+ lace_size[n] = lace_size[n - 1] + snum;
+ total += lace_size[n];
+ }
+ lace_size[n] = size - total;
+ break;
+ }
+ }
+ break;
+ }
+
+ if (res == 0) {
+ int real_v = matroska->tracks[track]->flags & MATROSKA_TRACK_REAL_V;
+ uint64_t timecode = AV_NOPTS_VALUE;
+
+ if (cluster_time != (uint64_t)-1 && cluster_time + block_time >= 0)
+ timecode = cluster_time + block_time;
+
+ for (n = 0; n < laces; n++) {
+ int slice, slices = 1;
+
+ if (real_v) {
+ slices = *data++ + 1;
+ lace_size[n]--;
+ }
+
+ for (slice=0; slice<slices; slice++) {
+ int slice_size, slice_offset = 0;
+ if (real_v)
+ slice_offset = rv_offset(data, slice, slices);
+ if (slice+1 == slices)
+ slice_size = lace_size[n] - slice_offset;
+ else
+ slice_size = rv_offset(data, slice+1, slices) - slice_offset;
+ pkt = av_mallocz(sizeof(AVPacket));
+ /* XXX: prevent data copy... */
+ if (av_new_packet(pkt, slice_size) < 0) {
+ res = AVERROR_NOMEM;
+ n = laces-1;
+ break;
+ }
+ memcpy (pkt->data, data+slice_offset, slice_size);
+
+ if (n == 0)
+ pkt->flags = is_keyframe;
+ pkt->stream_index = matroska->tracks[track]->stream_index;
+
+ pkt->pts = timecode;
+ pkt->pos = pos;
+ pkt->duration = duration;
+
+ if (matroska->tracks[track]->flags & MATROSKA_TRACK_REORDER)
+ matroska_queue_packet_reordered(matroska, pkt, is_bframe);
+ else
+ matroska_queue_packet(matroska, pkt);
+
+ if (timecode != AV_NOPTS_VALUE)
+ timecode = duration ? timecode + duration : AV_NOPTS_VALUE;
+ }
+ data += lace_size[n];
+ }
+ }
+
+ av_free(lace_size);
+ av_free(origdata);
+ return res;
+}
+
+static int
+matroska_parse_blockgroup (MatroskaDemuxContext *matroska,
+ uint64_t cluster_time)
+{
+ int res = 0;
+ uint32_t id;
+ int is_bframe = 0;
+ int is_keyframe = PKT_FLAG_KEY, last_num_packets = matroska->num_packets;
+ uint64_t duration = AV_NOPTS_VALUE;
+ uint8_t *data;
+ int size = 0;
+ int64_t pos = 0;
+
+ av_log(matroska->ctx, AV_LOG_DEBUG, "parsing blockgroup...\n");
+
+ while (res == 0) {
+ if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
+ res = AVERROR_IO;
+ break;
+ } else if (matroska->level_up) {
+ matroska->level_up--;
+ break;
+ }
+
+ switch (id) {
+ /* one block inside the group. Note, block parsing is one
+ * of the harder things, so this code is a bit complicated.
+ * See http://www.matroska.org/ for documentation. */
+ case MATROSKA_ID_BLOCK: {
+ pos = url_ftell(&matroska->ctx->pb);
+ res = ebml_read_binary(matroska, &id, &data, &size);
+ break;
+ }
+
+ case MATROSKA_ID_BLOCKDURATION: {
+ if ((res = ebml_read_uint(matroska, &id, &duration)) < 0)
+ break;
+ duration /= matroska->time_scale;
+ break;
+ }
+
+ case MATROSKA_ID_BLOCKREFERENCE: {
+ int64_t num;
+ /* We've found a reference, so not even the first frame in
+ * the lace is a key frame. */
+ is_keyframe = 0;
+ if (last_num_packets != matroska->num_packets)
+ matroska->packets[last_num_packets]->flags = 0;
+ if ((res = ebml_read_sint(matroska, &id, &num)) < 0)
+ break;
+ if (num > 0)
+ is_bframe = 1;
+ break;
+ }
+
+ default:
+ av_log(matroska->ctx, AV_LOG_INFO,
+ "Unknown entry 0x%x in blockgroup data\n", id);
+ /* fall-through */
+
+ case EBML_ID_VOID:
+ res = ebml_read_skip(matroska);
+ break;
+ }
+
+ if (matroska->level_up) {
+ matroska->level_up--;
+ break;
+ }
+ }
+
+ if (res)
+ return res;
+
+ if (size > 0)
+ res = matroska_parse_block(matroska, data, size, pos, cluster_time,
+ duration, is_keyframe, is_bframe);
+
+ return res;
+}
+
+static int
+matroska_parse_cluster (MatroskaDemuxContext *matroska)
+{
+ int res = 0;
+ uint32_t id;
+ uint64_t cluster_time = 0;
+ uint8_t *data;
+ int64_t pos;
+ int size;
+
+ av_log(matroska->ctx, AV_LOG_DEBUG,
+ "parsing cluster at %"PRId64"\n", url_ftell(&matroska->ctx->pb));
+
+ while (res == 0) {
+ if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
+ res = AVERROR_IO;
+ break;
+ } else if (matroska->level_up) {
+ matroska->level_up--;
+ break;
+ }
+
+ switch (id) {
+ /* cluster timecode */
+ case MATROSKA_ID_CLUSTERTIMECODE: {
+ uint64_t num;
+ if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
+ break;
+ cluster_time = num;
+ break;
+ }
+
+ /* a group of blocks inside a cluster */
+ case MATROSKA_ID_BLOCKGROUP:
+ if ((res = ebml_read_master(matroska, &id)) < 0)
+ break;
+ res = matroska_parse_blockgroup(matroska, cluster_time);
+ break;
+
+ case MATROSKA_ID_SIMPLEBLOCK:
+ pos = url_ftell(&matroska->ctx->pb);
+ res = ebml_read_binary(matroska, &id, &data, &size);
+ if (res == 0)
+ res = matroska_parse_block(matroska, data, size, pos,
+ cluster_time, AV_NOPTS_VALUE,
+ -1, 0);
+ break;
+
+ default:
+ av_log(matroska->ctx, AV_LOG_INFO,
+ "Unknown entry 0x%x in cluster data\n", id);
+ /* fall-through */
+
+ case EBML_ID_VOID:
+ res = ebml_read_skip(matroska);
+ break;
+ }
+
+ if (matroska->level_up) {
+ matroska->level_up--;
+ break;
+ }
+ }
+
+ return res;
+}
+
+static int
+matroska_read_packet (AVFormatContext *s,
+ AVPacket *pkt)
+{
+ MatroskaDemuxContext *matroska = s->priv_data;
+ int res = 0;
+ uint32_t id;
+
+ /* Read stream until we have a packet queued. */
+ while (matroska_deliver_packet(matroska, pkt)) {
+
+ /* Have we already reached the end? */
+ if (matroska->done)
+ return AVERROR_IO;
+
+ while (res == 0) {
+ if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
+ return AVERROR_IO;
+ } else if (matroska->level_up) {
+ matroska->level_up--;
+ break;
+ }
+
+ switch (id) {
+ case MATROSKA_ID_CLUSTER:
+ if ((res = ebml_read_master(matroska, &id)) < 0)
+ break;
+ if ((res = matroska_parse_cluster(matroska)) == 0)
+ res = 1; /* Parsed one cluster, let's get out. */
+ break;
+
+ default:
+ case EBML_ID_VOID:
+ res = ebml_read_skip(matroska);
+ break;
+ }
+
+ if (matroska->level_up) {
+ matroska->level_up--;
+ break;
+ }
+ }
+
+ if (res == -1)
+ matroska->done = 1;
+ }
+
+ return 0;
+}
+
+static int
+matroska_read_close (AVFormatContext *s)
+{
+ MatroskaDemuxContext *matroska = s->priv_data;
+ int n = 0;
+
+ av_free(matroska->writing_app);
+ av_free(matroska->muxing_app);
+ av_free(matroska->index);
+
+ if (matroska->packets != NULL) {
+ for (n = 0; n < matroska->num_packets; n++) {
+ av_free_packet(matroska->packets[n]);
+ av_free(matroska->packets[n]);
+ }
+ av_free(matroska->packets);
+ }
+ if (matroska->packets_reorder) {
+ for (n = 0; n < matroska->num_packets_reorder; n++) {
+ av_free_packet(matroska->packets_reorder[n]);
+ av_free(matroska->packets_reorder[n]);
+ }
+ av_free(matroska->packets_reorder);
+ }
+
+ for (n = 0; n < matroska->num_tracks; n++) {
+ MatroskaTrack *track = matroska->tracks[n];
+ av_free(track->codec_id);
+ av_free(track->codec_name);
+ av_free(track->codec_priv);
+ av_free(track->name);
+ av_free(track->language);
+
+ av_free(track);
+ }
+
+ return 0;
+}
+
+AVInputFormat matroska_demuxer = {
+ "matroska",
+ "Matroska file format",
+ sizeof(MatroskaDemuxContext),
+ matroska_probe,
+ matroska_read_header,
+ matroska_read_packet,
+ matroska_read_close,
+};
diff --git a/contrib/ffmpeg/libavformat/mm.c b/contrib/ffmpeg/libavformat/mm.c
new file mode 100644
index 000000000..443b70929
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/mm.c
@@ -0,0 +1,212 @@
+/*
+ * American Laser Games MM Format Demuxer
+ * Copyright (c) 2006 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 St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file mm.c
+ * American Laser Games MM Format Demuxer
+ * by Peter Ross (suxen_drol at hotmail dot com)
+ *
+ * The MM format was used by IBM-PC ports of ALG's "arcade shooter" games,
+ * including Mad Dog McCree and Crime Patrol.
+ *
+ * Technical details here:
+ * http://wiki.multimedia.cx/index.php?title=American_Laser_Games_MM
+ */
+
+#include "avformat.h"
+
+#define MM_PREAMBLE_SIZE 6
+
+#define MM_TYPE_HEADER 0x0
+#define MM_TYPE_INTER 0x5
+#define MM_TYPE_INTRA 0x8
+#define MM_TYPE_INTRA_HH 0xc
+#define MM_TYPE_INTER_HH 0xd
+#define MM_TYPE_INTRA_HHV 0xe
+#define MM_TYPE_INTER_HHV 0xf
+#define MM_TYPE_AUDIO 0x15
+#define MM_TYPE_PALETTE 0x31
+
+#define MM_HEADER_LEN_V 0x16 /* video only */
+#define MM_HEADER_LEN_AV 0x18 /* video + audio */
+
+#define MM_PALETTE_COUNT 128
+#define MM_PALETTE_SIZE (MM_PALETTE_COUNT*3)
+
+typedef struct {
+ AVPaletteControl palette_control;
+ unsigned int audio_pts, video_pts;
+} MmDemuxContext;
+
+static int mm_probe(AVProbeData *p)
+{
+ /* the first chunk is always the header */
+ if (p->buf_size < MM_PREAMBLE_SIZE)
+ return 0;
+ 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)
+ 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,
+ AVFormatParameters *ap)
+{
+ MmDemuxContext *mm = (MmDemuxContext *)s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ AVStream *st;
+
+ unsigned int type, length;
+ unsigned int frame_rate, width, height;
+
+ type = get_le16(pb);
+ length = get_le32(pb);
+
+ if (type != MM_TYPE_HEADER)
+ return AVERROR_INVALIDDATA;
+
+ /* read header */
+ get_le16(pb); /* total number of chunks */
+ frame_rate = get_le16(pb);
+ get_le16(pb); /* ibm-pc video bios mode */
+ width = get_le16(pb);
+ height = get_le16(pb);
+ url_fseek(pb, length - 10, SEEK_CUR); /* unknown data */
+
+ /* video stream */
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ st->codec->codec_id = CODEC_ID_MMVIDEO;
+ st->codec->codec_tag = 0; /* no fourcc */
+ st->codec->width = width;
+ st->codec->height = height;
+ st->codec->palctrl = &mm->palette_control;
+ av_set_pts_info(st, 64, 1, frame_rate);
+
+ /* audio stream */
+ if (length == MM_HEADER_LEN_AV) {
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_tag = 0; /* no fourcc */
+ st->codec->codec_id = CODEC_ID_PCM_U8;
+ st->codec->channels = 1;
+ st->codec->sample_rate = 8000;
+ av_set_pts_info(st, 64, 1, 8000); /* 8000 hz */
+ }
+
+ mm->palette_control.palette_changed = 0;
+ mm->audio_pts = 0;
+ mm->video_pts = 0;
+ return 0;
+}
+
+static int mm_read_packet(AVFormatContext *s,
+ AVPacket *pkt)
+{
+ MmDemuxContext *mm = (MmDemuxContext *)s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ unsigned char preamble[MM_PREAMBLE_SIZE];
+ unsigned char pal[MM_PALETTE_SIZE];
+ unsigned int type, length;
+ int i;
+
+ while(1) {
+
+ if (get_buffer(pb, preamble, MM_PREAMBLE_SIZE) != MM_PREAMBLE_SIZE) {
+ return AVERROR_IO;
+ }
+
+ type = AV_RL16(&preamble[0]);
+ length = AV_RL16(&preamble[2]);
+
+ switch(type) {
+ case MM_TYPE_PALETTE :
+ url_fseek(pb, 4, SEEK_CUR); /* unknown data */
+ if (get_buffer(pb, pal, MM_PALETTE_SIZE) != MM_PALETTE_SIZE)
+ return AVERROR_IO;
+ url_fseek(pb, length - (4 + MM_PALETTE_SIZE), SEEK_CUR);
+
+ for (i=0; i<MM_PALETTE_COUNT; i++) {
+ int r = pal[i*3 + 0];
+ int g = pal[i*3 + 1];
+ int b = pal[i*3 + 2];
+ mm->palette_control.palette[i] = (r << 16) | (g << 8) | (b);
+ /* repeat palette, where each components is multiplied by four */
+ mm->palette_control.palette[i+128] = (r << 18) | (g << 10) | (b<<2);
+ }
+ mm->palette_control.palette_changed = 1;
+ break;
+
+ case MM_TYPE_INTER :
+ case MM_TYPE_INTRA :
+ case MM_TYPE_INTRA_HH :
+ case MM_TYPE_INTER_HH :
+ case MM_TYPE_INTRA_HHV :
+ case MM_TYPE_INTER_HHV :
+ /* output preamble + data */
+ if (av_new_packet(pkt, length + MM_PREAMBLE_SIZE))
+ return AVERROR_NOMEM;
+ memcpy(pkt->data, preamble, MM_PREAMBLE_SIZE);
+ if (get_buffer(pb, pkt->data + MM_PREAMBLE_SIZE, length) != length)
+ return AVERROR_IO;
+ pkt->size = length + MM_PREAMBLE_SIZE;
+ pkt->stream_index = 0;
+ pkt->pts = mm->video_pts++;
+ return 0;
+
+ case MM_TYPE_AUDIO :
+ if (av_get_packet(&s->pb, pkt, length)<0)
+ return AVERROR_NOMEM;
+ pkt->size = length;
+ pkt->stream_index = 1;
+ pkt->pts = mm->audio_pts++;
+ return 0;
+
+ default :
+ av_log(NULL, AV_LOG_INFO, "mm: unknown chunk type 0x%x\n", type);
+ url_fseek(pb, length, SEEK_CUR);
+ }
+ }
+
+ return 0;
+}
+
+static int mm_read_close(AVFormatContext *s)
+{
+ return 0;
+}
+
+AVInputFormat mm_demuxer = {
+ "mm",
+ "American Laser Games MM format",
+ sizeof(MmDemuxContext),
+ mm_probe,
+ mm_read_header,
+ mm_read_packet,
+ mm_read_close,
+};
diff --git a/contrib/ffmpeg/libavformat/mmf.c b/contrib/ffmpeg/libavformat/mmf.c
new file mode 100644
index 000000000..40b1a497c
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/mmf.c
@@ -0,0 +1,331 @@
+/*
+ * Yamaha SMAF format
+ * Copyright (c) 2005 Vidar Madsen
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 "allformats.h"
+#include "riff.h"
+
+typedef struct {
+ offset_t atrpos, atsqpos, awapos;
+ offset_t data_size;
+} MMFContext;
+
+static int mmf_rates[] = { 4000, 8000, 11025, 22050, 44100 };
+
+static int mmf_rate_code(int rate)
+{
+ int i;
+ for(i = 0; i < 5; i++)
+ if(mmf_rates[i] == rate)
+ return i;
+ return -1;
+}
+
+static int mmf_rate(int code)
+{
+ if((code < 0) || (code > 4))
+ return -1;
+ return mmf_rates[code];
+}
+
+#ifdef CONFIG_MUXERS
+/* Copy of end_tag() from avienc.c, but for big-endian chunk size */
+static void end_tag_be(ByteIOContext *pb, offset_t start)
+{
+ offset_t pos;
+
+ pos = url_ftell(pb);
+ url_fseek(pb, start - 4, SEEK_SET);
+ put_be32(pb, (uint32_t)(pos - start));
+ url_fseek(pb, pos, SEEK_SET);
+}
+
+static int mmf_write_header(AVFormatContext *s)
+{
+ MMFContext *mmf = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ offset_t pos;
+ int rate;
+
+ rate = mmf_rate_code(s->streams[0]->codec->sample_rate);
+ if(rate < 0) {
+ av_log(s, AV_LOG_ERROR, "Unsupported sample rate %d\n", s->streams[0]->codec->sample_rate);
+ return -1;
+ }
+
+ put_tag(pb, "MMMD");
+ put_be32(pb, 0);
+ pos = start_tag(pb, "CNTI");
+ put_byte(pb, 0); /* class */
+ put_byte(pb, 0); /* type */
+ put_byte(pb, 0); /* code type */
+ put_byte(pb, 0); /* status */
+ put_byte(pb, 0); /* counts */
+ put_tag(pb, "VN:libavcodec,"); /* metadata ("ST:songtitle,VN:version,...") */
+ end_tag_be(pb, pos);
+
+ put_buffer(pb, "ATR\x00", 4);
+ put_be32(pb, 0);
+ mmf->atrpos = url_ftell(pb);
+ put_byte(pb, 0); /* format type */
+ put_byte(pb, 0); /* sequence type */
+ put_byte(pb, (0 << 7) | (1 << 4) | rate); /* (channel << 7) | (format << 4) | rate */
+ put_byte(pb, 0); /* wave base bit */
+ put_byte(pb, 2); /* time base d */
+ put_byte(pb, 2); /* time base g */
+
+ put_tag(pb, "Atsq");
+ put_be32(pb, 16);
+ mmf->atsqpos = url_ftell(pb);
+ /* Will be filled on close */
+ put_buffer(pb, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 16);
+
+ mmf->awapos = start_tag(pb, "Awa\x01");
+
+ av_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate);
+
+ put_flush_packet(pb);
+
+ return 0;
+}
+
+static int mmf_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ ByteIOContext *pb = &s->pb;
+ put_buffer(pb, pkt->data, pkt->size);
+ return 0;
+}
+
+/* Write a variable-length symbol */
+static void put_varlength(ByteIOContext *pb, int val)
+{
+ if(val < 128)
+ put_byte(pb, val);
+ else {
+ val -= 128;
+ put_byte(pb, 0x80 | val >> 7);
+ put_byte(pb, 0x7f & val);
+ }
+}
+
+static int mmf_write_trailer(AVFormatContext *s)
+{
+ ByteIOContext *pb = &s->pb;
+ MMFContext *mmf = s->priv_data;
+ offset_t pos, size;
+ int gatetime;
+
+ if (!url_is_streamed(&s->pb)) {
+ /* Fill in length fields */
+ end_tag_be(pb, mmf->awapos);
+ end_tag_be(pb, mmf->atrpos);
+ end_tag_be(pb, 8);
+
+ pos = url_ftell(pb);
+ size = pos - mmf->awapos;
+
+ /* Fill Atsq chunk */
+ url_fseek(pb, mmf->atsqpos, SEEK_SET);
+
+ /* "play wav" */
+ put_byte(pb, 0); /* start time */
+ put_byte(pb, 1); /* (channel << 6) | wavenum */
+ gatetime = size * 500 / s->streams[0]->codec->sample_rate;
+ put_varlength(pb, gatetime); /* duration */
+
+ /* "nop" */
+ put_varlength(pb, gatetime); /* start time */
+ put_buffer(pb, "\xff\x00", 2); /* nop */
+
+ /* "end of sequence" */
+ put_buffer(pb, "\x00\x00\x00\x00", 4);
+
+ url_fseek(pb, pos, SEEK_SET);
+
+ put_flush_packet(pb);
+ }
+ return 0;
+}
+#endif //CONFIG_MUXERS
+
+static int mmf_probe(AVProbeData *p)
+{
+ /* check file header */
+ if (p->buf_size <= 32)
+ return 0;
+ if (p->buf[0] == 'M' && p->buf[1] == 'M' &&
+ p->buf[2] == 'M' && p->buf[3] == 'D' &&
+ p->buf[8] == 'C' && p->buf[9] == 'N' &&
+ p->buf[10] == 'T' && p->buf[11] == 'I')
+ return AVPROBE_SCORE_MAX;
+ else
+ return 0;
+}
+
+/* mmf input */
+static int mmf_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ MMFContext *mmf = s->priv_data;
+ unsigned int tag;
+ ByteIOContext *pb = &s->pb;
+ AVStream *st;
+ offset_t file_size, size;
+ int rate, params;
+
+ tag = get_le32(pb);
+ if (tag != MKTAG('M', 'M', 'M', 'D'))
+ return -1;
+ file_size = get_be32(pb);
+
+ /* Skip some unused chunks that may or may not be present */
+ for(;; url_fseek(pb, size, SEEK_CUR)) {
+ tag = get_le32(pb);
+ size = get_be32(pb);
+ if(tag == MKTAG('C','N','T','I')) continue;
+ if(tag == MKTAG('O','P','D','A')) continue;
+ break;
+ }
+
+ /* Tag = "ATRx", where "x" = track number */
+ if ((tag & 0xffffff) == MKTAG('M', 'T', 'R', 0)) {
+ av_log(s, AV_LOG_ERROR, "MIDI like format found, unsupported\n");
+ return -1;
+ }
+ if ((tag & 0xffffff) != MKTAG('A', 'T', 'R', 0)) {
+ av_log(s, AV_LOG_ERROR, "Unsupported SMAF chunk %08x\n", tag);
+ return -1;
+ }
+
+ get_byte(pb); /* format type */
+ get_byte(pb); /* sequence type */
+ params = get_byte(pb); /* (channel << 7) | (format << 4) | rate */
+ rate = mmf_rate(params & 0x0f);
+ if(rate < 0) {
+ av_log(s, AV_LOG_ERROR, "Invalid sample rate\n");
+ return -1;
+ }
+ get_byte(pb); /* wave base bit */
+ get_byte(pb); /* time base d */
+ get_byte(pb); /* time base g */
+
+ /* Skip some unused chunks that may or may not be present */
+ for(;; url_fseek(pb, size, SEEK_CUR)) {
+ tag = get_le32(pb);
+ size = get_be32(pb);
+ if(tag == MKTAG('A','t','s','q')) continue;
+ if(tag == MKTAG('A','s','p','I')) continue;
+ break;
+ }
+
+ /* Make sure it's followed by an Awa chunk, aka wave data */
+ if ((tag & 0xffffff) != MKTAG('A', 'w', 'a', 0)) {
+ av_log(s, AV_LOG_ERROR, "Unexpected SMAF chunk %08x\n", tag);
+ return -1;
+ }
+ mmf->data_size = size;
+
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_id = CODEC_ID_ADPCM_YAMAHA;
+ st->codec->sample_rate = rate;
+ st->codec->channels = 1;
+ st->codec->bits_per_sample = 4;
+ st->codec->bit_rate = st->codec->sample_rate * st->codec->bits_per_sample;
+
+ av_set_pts_info(st, 64, 1, st->codec->sample_rate);
+
+ return 0;
+}
+
+#define MAX_SIZE 4096
+
+static int mmf_read_packet(AVFormatContext *s,
+ AVPacket *pkt)
+{
+ MMFContext *mmf = s->priv_data;
+ AVStream *st;
+ int ret, size;
+
+ if (url_feof(&s->pb))
+ return AVERROR_IO;
+ st = s->streams[0];
+
+ size = MAX_SIZE;
+ if(size > mmf->data_size)
+ size = mmf->data_size;
+
+ if(!size)
+ return AVERROR_IO;
+
+ if (av_new_packet(pkt, size))
+ return AVERROR_IO;
+ pkt->stream_index = 0;
+
+ ret = get_buffer(&s->pb, pkt->data, pkt->size);
+ if (ret < 0)
+ av_free_packet(pkt);
+
+ mmf->data_size -= ret;
+
+ pkt->size = ret;
+ return ret;
+}
+
+static int mmf_read_close(AVFormatContext *s)
+{
+ return 0;
+}
+
+static int mmf_read_seek(AVFormatContext *s,
+ int stream_index, int64_t timestamp, int flags)
+{
+ return pcm_read_seek(s, stream_index, timestamp, flags);
+}
+
+#ifdef CONFIG_MMF_DEMUXER
+AVInputFormat mmf_demuxer = {
+ "mmf",
+ "mmf format",
+ sizeof(MMFContext),
+ mmf_probe,
+ mmf_read_header,
+ mmf_read_packet,
+ mmf_read_close,
+ mmf_read_seek,
+};
+#endif
+#ifdef CONFIG_MMF_MUXER
+AVOutputFormat mmf_muxer = {
+ "mmf",
+ "mmf format",
+ "application/vnd.smaf",
+ "mmf",
+ sizeof(MMFContext),
+ CODEC_ID_ADPCM_YAMAHA,
+ CODEC_ID_NONE,
+ mmf_write_header,
+ mmf_write_packet,
+ mmf_write_trailer,
+};
+#endif
diff --git a/contrib/ffmpeg/libavformat/mov.c b/contrib/ffmpeg/libavformat/mov.c
new file mode 100644
index 000000000..e9b577576
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/mov.c
@@ -0,0 +1,1696 @@
+/*
+ * MOV demuxer
+ * Copyright (c) 2001 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 <limits.h>
+
+//#define DEBUG
+
+#include "avformat.h"
+#include "riff.h"
+#include "isom.h"
+#include "dv.h"
+
+#ifdef CONFIG_ZLIB
+#include <zlib.h>
+#endif
+
+/*
+ * First version by Francois Revol revol@free.fr
+ * Seek function by Gael Chardon gael.dev@4now.net
+ *
+ * Features and limitations:
+ * - reads most of the QT files I have (at least the structure),
+ * the exceptions are .mov with zlib compressed headers ('cmov' section). It shouldn't be hard to implement.
+ * FIXED, Francois Revol, 07/17/2002
+ * - ffmpeg has nearly none of the usual QuickTime codecs,
+ * although I succesfully dumped raw and mp3 audio tracks off .mov files.
+ * Sample QuickTime files with mp3 audio can be found at: http://www.3ivx.com/showcase.html
+ * - .mp4 parsing is still hazardous, although the format really is QuickTime with some minor changes
+ * (to make .mov parser crash maybe ?), despite what they say in the MPEG FAQ at
+ * http://mpeg.telecomitalialab.com/faq.htm
+ * - the code is quite ugly... maybe I won't do it recursive next time :-)
+ * - seek is not supported with files that contain edit list
+ *
+ * Funny I didn't know about http://sourceforge.net/projects/qt-ffmpeg/
+ * when coding this :) (it's a writer anyway)
+ *
+ * Reference documents:
+ * http://www.geocities.com/xhelmboyx/quicktime/formats/qtm-layout.txt
+ * Apple:
+ * http://developer.apple.com/documentation/QuickTime/QTFF/
+ * http://developer.apple.com/documentation/QuickTime/QTFF/qtff.pdf
+ * QuickTime is a trademark of Apple (AFAIK :))
+ */
+
+#include "qtpalette.h"
+
+
+#undef NDEBUG
+#include <assert.h>
+
+/* the QuickTime file format is quite convoluted...
+ * it has lots of index tables, each indexing something in another one...
+ * Here we just use what is needed to read the chunks
+ */
+
+typedef struct MOV_sample_to_chunk_tbl {
+ long first;
+ long count;
+ long id;
+} MOV_sample_to_chunk_tbl;
+
+typedef struct {
+ uint32_t type;
+ int64_t offset;
+ int64_t size; /* total size (excluding the size and type fields) */
+} MOV_atom_t;
+
+typedef struct {
+ int seed;
+ int flags;
+ int size;
+ void* clrs;
+} MOV_ctab_t;
+
+typedef struct MOV_mdat_atom_s {
+ offset_t offset;
+ int64_t size;
+} MOV_mdat_atom_t;
+
+typedef struct {
+ uint8_t version;
+ uint32_t flags; // 24bit
+
+ /* 0x03 ESDescrTag */
+ uint16_t es_id;
+#define MP4ODescrTag 0x01
+#define MP4IODescrTag 0x02
+#define MP4ESDescrTag 0x03
+#define MP4DecConfigDescrTag 0x04
+#define MP4DecSpecificDescrTag 0x05
+#define MP4SLConfigDescrTag 0x06
+#define MP4ContentIdDescrTag 0x07
+#define MP4SupplContentIdDescrTag 0x08
+#define MP4IPIPtrDescrTag 0x09
+#define MP4IPMPPtrDescrTag 0x0A
+#define MP4IPMPDescrTag 0x0B
+#define MP4RegistrationDescrTag 0x0D
+#define MP4ESIDIncDescrTag 0x0E
+#define MP4ESIDRefDescrTag 0x0F
+#define MP4FileIODescrTag 0x10
+#define MP4FileODescrTag 0x11
+#define MP4ExtProfileLevelDescrTag 0x13
+#define MP4ExtDescrTagsStart 0x80
+#define MP4ExtDescrTagsEnd 0xFE
+ uint8_t stream_priority;
+
+ /* 0x04 DecConfigDescrTag */
+ uint8_t object_type_id;
+ uint8_t stream_type;
+ /* XXX: really streamType is
+ * only 6bit, followed by:
+ * 1bit upStream
+ * 1bit reserved
+ */
+ uint32_t buffer_size_db; // 24
+ uint32_t max_bitrate;
+ uint32_t avg_bitrate;
+
+ /* 0x05 DecSpecificDescrTag */
+ uint8_t decoder_cfg_len;
+ uint8_t *decoder_cfg;
+
+ /* 0x06 SLConfigDescrTag */
+ uint8_t sl_config_len;
+ uint8_t *sl_config;
+} MOV_esds_t;
+
+struct MOVParseTableEntry;
+
+typedef struct MOVStreamContext {
+ int ffindex; /* the ffmpeg stream id */
+ long next_chunk;
+ unsigned int chunk_count;
+ int64_t *chunk_offsets;
+ unsigned int stts_count;
+ Time2Sample *stts_data;
+ unsigned int ctts_count;
+ Time2Sample *ctts_data;
+ unsigned int edit_count; /* number of 'edit' (elst atom) */
+ unsigned int sample_to_chunk_sz;
+ MOV_sample_to_chunk_tbl *sample_to_chunk;
+ int sample_to_ctime_index;
+ int sample_to_ctime_sample;
+ unsigned int sample_size;
+ unsigned int sample_count;
+ long *sample_sizes;
+ unsigned int keyframe_count;
+ long *keyframes;
+ int time_scale;
+ int time_rate;
+ long current_sample;
+ MOV_esds_t esds;
+ unsigned int bytes_per_frame;
+ unsigned int samples_per_frame;
+ int dv_audio_container;
+} MOVStreamContext;
+
+typedef struct MOVContext {
+ AVFormatContext *fc;
+ int time_scale;
+ int64_t duration; /* duration of the longest track */
+ int found_moov; /* when both 'moov' and 'mdat' sections has been found */
+ int found_mdat; /* we suppose we have enough data to read the file */
+ int64_t mdat_offset;
+ int total_streams;
+ MOVStreamContext *streams[MAX_STREAMS];
+
+ int ctab_size;
+ MOV_ctab_t **ctab; /* color tables */
+ const struct MOVParseTableEntry *parse_table; /* could be eventually used to change the table */
+ /* NOTE: for recursion save to/ restore from local variable! */
+
+ AVPaletteControl palette_control;
+ MOV_mdat_atom_t *mdat_list;
+ int mdat_count;
+ DVDemuxContext *dv_demux;
+ AVFormatContext *dv_fctx;
+ int isom; /* 1 if file is ISO Media (mp4/3gp) */
+} MOVContext;
+
+
+/* XXX: it's the first time I make a recursive parser I think... sorry if it's ugly :P */
+
+/* those functions parse an atom */
+/* return code:
+ 1: found what I wanted, exit
+ 0: continue to parse next atom
+ -1: error occured, exit
+ */
+typedef int (*mov_parse_function)(MOVContext *ctx, ByteIOContext *pb, MOV_atom_t atom);
+
+/* links atom IDs to parse functions */
+typedef struct MOVParseTableEntry {
+ uint32_t type;
+ mov_parse_function func;
+} MOVParseTableEntry;
+
+static int mov_read_default(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
+{
+ int64_t total_size = 0;
+ MOV_atom_t a;
+ int i;
+ int err = 0;
+
+ a.offset = atom.offset;
+
+ if (atom.size < 0)
+ atom.size = 0x7fffffffffffffffLL;
+ while(((total_size + 8) < atom.size) && !url_feof(pb) && !err) {
+ a.size = atom.size;
+ a.type=0L;
+ if(atom.size >= 8) {
+ a.size = get_be32(pb);
+ 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) {
+ a.size = atom.size - total_size;
+ if (a.size <= 8)
+ break;
+ }
+ a.size -= 8;
+ if(a.size < 0 || a.size > atom.size - total_size)
+ break;
+
+ for (i = 0; c->parse_table[i].type != 0L
+ && c->parse_table[i].type != a.type; i++)
+ /* empty */;
+
+ if (c->parse_table[i].type == 0) { /* skip leaf atoms data */
+ url_fskip(pb, a.size);
+ } else {
+ offset_t start_pos = url_ftell(pb);
+ int64_t left;
+ err = (c->parse_table[i].func)(c, pb, a);
+ 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) {
+ url_fskip(pb, atom.size - total_size);
+ }
+
+ return err;
+}
+
+static int mov_read_ctab(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
+{
+#if 1
+ url_fskip(pb, atom.size); // for now
+#else
+ VERY VERY BROKEN, NEVER execute this, needs rewrite
+ unsigned int len;
+ MOV_ctab_t *t;
+ c->ctab = av_realloc(c->ctab, ++c->ctab_size);
+ t = c->ctab[c->ctab_size];
+ t->seed = get_be32(pb);
+ t->flags = get_be16(pb);
+ t->size = get_be16(pb) + 1;
+ len = 2 * t->size * 4;
+ if (len > 0) {
+ t->clrs = av_malloc(len); // 16bit A R G B
+ if (t->clrs)
+ get_buffer(pb, t->clrs, len);
+ }
+#endif
+
+ return 0;
+}
+
+static int mov_read_hdlr(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
+{
+ AVStream *st = c->fc->streams[c->fc->nb_streams-1];
+ uint32_t type;
+ uint32_t ctype;
+
+ get_byte(pb); /* version */
+ get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
+
+ /* component type */
+ ctype = get_le32(pb);
+ type = get_le32(pb); /* component subtype */
+
+ dprintf(c->fc, "ctype= %c%c%c%c (0x%08lx)\n", *((char *)&ctype), ((char *)&ctype)[1], ((char *)&ctype)[2], ((char *)&ctype)[3], (long) ctype);
+ dprintf(c->fc, "stype= %c%c%c%c\n", *((char *)&type), ((char *)&type)[1], ((char *)&type)[2], ((char *)&type)[3]);
+ if(!ctype)
+ c->isom = 1;
+ if(type == MKTAG('v', 'i', 'd', 'e'))
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ else if(type == MKTAG('s', 'o', 'u', 'n'))
+ st->codec->codec_type = CODEC_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_id = CODEC_ID_DVD_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 mov_mp4_read_descr_len(ByteIOContext *pb)
+{
+ int len = 0;
+ int count = 4;
+ while (count--) {
+ int c = get_byte(pb);
+ len = (len << 7) | (c & 0x7f);
+ if (!(c & 0x80))
+ break;
+ }
+ return len;
+}
+
+static int mov_mp4_read_descr(MOVContext *c, ByteIOContext *pb, int *tag)
+{
+ int len;
+ *tag = get_byte(pb);
+ len = mov_mp4_read_descr_len(pb);
+ dprintf(c->fc, "MPEG4 description: tag=0x%02x len=%d\n", *tag, len);
+ return len;
+}
+
+static int mov_read_esds(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
+{
+ AVStream *st = c->fc->streams[c->fc->nb_streams-1];
+ MOVStreamContext *sc = (MOVStreamContext *)st->priv_data;
+ int tag, len;
+
+ /* Well, broken but suffisant for some MP4 streams */
+ get_be32(pb); /* version + flags */
+ len = mov_mp4_read_descr(c, pb, &tag);
+ if (tag == MP4ESDescrTag) {
+ get_be16(pb); /* ID */
+ get_byte(pb); /* priority */
+ } else
+ get_be16(pb); /* ID */
+
+ len = mov_mp4_read_descr(c, pb, &tag);
+ if (tag == MP4DecConfigDescrTag) {
+ sc->esds.object_type_id = get_byte(pb);
+ sc->esds.stream_type = get_byte(pb);
+ sc->esds.buffer_size_db = get_be24(pb);
+ sc->esds.max_bitrate = get_be32(pb);
+ sc->esds.avg_bitrate = get_be32(pb);
+
+ st->codec->codec_id= codec_get_id(ff_mp4_obj_type, sc->esds.object_type_id);
+ dprintf(c->fc, "esds object type id %d\n", sc->esds.object_type_id);
+ len = mov_mp4_read_descr(c, pb, &tag);
+ if (tag == MP4DecSpecificDescrTag) {
+ dprintf(c->fc, "Specific MPEG4 header len=%d\n", len);
+ st->codec->extradata = av_mallocz(len + FF_INPUT_BUFFER_PADDING_SIZE);
+ if (st->codec->extradata) {
+ get_buffer(pb, st->codec->extradata, len);
+ st->codec->extradata_size = len;
+ /* from mplayer */
+ if ((*st->codec->extradata >> 3) == 29) {
+ st->codec->codec_id = CODEC_ID_MP3ON4;
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+/* this atom contains actual media data */
+static int mov_read_mdat(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
+{
+ if(atom.size == 0) /* wrong one (MP4) */
+ return 0;
+ c->mdat_list = av_realloc(c->mdat_list, (c->mdat_count + 1) * sizeof(*c->mdat_list));
+ c->mdat_list[c->mdat_count].offset = atom.offset;
+ c->mdat_list[c->mdat_count].size = atom.size;
+ c->mdat_count++;
+ c->found_mdat=1;
+ c->mdat_offset = atom.offset;
+ if(c->found_moov)
+ return 1; /* found both, just go */
+ url_fskip(pb, atom.size);
+ return 0; /* now go for moov */
+}
+
+static int mov_read_ftyp(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
+{
+ uint32_t type = get_le32(pb);
+
+ if (type != MKTAG('q','t',' ',' '))
+ 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);
+ return 0;
+}
+
+/* this atom should contain all header atoms */
+static int mov_read_moov(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
+{
+ int err;
+
+ err = mov_read_default(c, pb, atom);
+ /* we parsed the 'moov' atom, we can terminate the parsing as soon as we find the 'mdat' */
+ /* so we don't parse the whole file if over a network */
+ c->found_moov=1;
+ if(c->found_mdat)
+ return 1; /* found both, just go */
+ return 0; /* now go for mdat */
+}
+
+
+static int mov_read_mdhd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
+{
+ AVStream *st = c->fc->streams[c->fc->nb_streams-1];
+ MOVStreamContext *sc = (MOVStreamContext *)st->priv_data;
+ int version = get_byte(pb);
+ int lang;
+
+ if (version > 1)
+ return 1; /* unsupported */
+
+ get_byte(pb); get_byte(pb);
+ get_byte(pb); /* flags */
+
+ if (version == 1) {
+ get_be64(pb);
+ get_be64(pb);
+ } else {
+ get_be32(pb); /* creation time */
+ get_be32(pb); /* modification time */
+ }
+
+ sc->time_scale = get_be32(pb);
+ st->duration = (version == 1) ? get_be64(pb) : get_be32(pb); /* duration */
+
+ lang = get_be16(pb); /* language */
+ ff_mov_lang_to_iso639(lang, st->language);
+ get_be16(pb); /* quality */
+
+ return 0;
+}
+
+static int mov_read_mvhd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
+{
+ int version = get_byte(pb); /* version */
+ get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
+
+ if (version == 1) {
+ get_be64(pb);
+ get_be64(pb);
+ } else {
+ get_be32(pb); /* creation time */
+ get_be32(pb); /* modification time */
+ }
+ c->time_scale = get_be32(pb); /* time scale */
+#ifdef DEBUG
+ av_log(NULL, AV_LOG_DEBUG, "time scale = %i\n", c->time_scale);
+#endif
+ c->duration = (version == 1) ? get_be64(pb) : get_be32(pb); /* duration */
+ get_be32(pb); /* preferred scale */
+
+ get_be16(pb); /* preferred volume */
+
+ url_fskip(pb, 10); /* reserved */
+
+ url_fskip(pb, 36); /* display matrix */
+
+ get_be32(pb); /* preview time */
+ get_be32(pb); /* preview duration */
+ get_be32(pb); /* poster time */
+ get_be32(pb); /* selection time */
+ get_be32(pb); /* selection duration */
+ get_be32(pb); /* current time */
+ get_be32(pb); /* next track ID */
+
+ return 0;
+}
+
+static int mov_read_smi(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
+{
+ AVStream *st = c->fc->streams[c->fc->nb_streams-1];
+
+ if((uint64_t)atom.size > (1<<30))
+ return -1;
+
+ // currently SVQ3 decoder expect full STSD header - so let's fake it
+ // this should be fixed and just SMI header should be passed
+ av_free(st->codec->extradata);
+ st->codec->extradata_size = 0x5a + atom.size;
+ st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
+
+ if (st->codec->extradata) {
+ memcpy(st->codec->extradata, "SVQ3", 4); // fake
+ get_buffer(pb, st->codec->extradata + 0x5a, atom.size);
+ dprintf(c->fc, "Reading SMI %"PRId64" %s\n", atom.size, st->codec->extradata + 0x5a);
+ } else
+ url_fskip(pb, atom.size);
+
+ return 0;
+}
+
+static int mov_read_enda(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
+{
+ AVStream *st = c->fc->streams[c->fc->nb_streams-1];
+ int little_endian = get_be16(pb);
+
+ if (little_endian) {
+ switch (st->codec->codec_id) {
+ case CODEC_ID_PCM_S24BE:
+ st->codec->codec_id = CODEC_ID_PCM_S24LE;
+ break;
+ case CODEC_ID_PCM_S32BE:
+ st->codec->codec_id = CODEC_ID_PCM_S32LE;
+ break;
+ default:
+ break;
+ }
+ }
+ return 0;
+}
+
+/* FIXME modify qdm2/svq3/h264 decoders to take full atom as extradata */
+static int mov_read_extradata(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
+{
+ AVStream *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_size = atom.size + 8;
+ st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ if (st->codec->extradata) {
+ AV_WL32(st->codec->extradata + 4, atom.type);
+ get_buffer(pb, st->codec->extradata + 8, atom.size);
+ } else
+ url_fskip(pb, atom.size);
+ return 0;
+}
+
+static int mov_read_wave(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
+{
+ AVStream *st = c->fc->streams[c->fc->nb_streams-1];
+
+ if((uint64_t)atom.size > (1<<30))
+ return -1;
+
+ if (st->codec->codec_id == CODEC_ID_QDM2) {
+ // pass all frma atom to codec, needed at least for QDM2
+ av_free(st->codec->extradata);
+ st->codec->extradata_size = atom.size;
+ st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
+
+ if (st->codec->extradata) {
+ get_buffer(pb, st->codec->extradata, atom.size);
+ } else
+ url_fskip(pb, atom.size);
+ } else if (atom.size > 8) { /* to read frma, esds atoms */
+ mov_read_default(c, pb, atom);
+ } else
+ url_fskip(pb, atom.size);
+ return 0;
+}
+
+static int mov_read_avcC(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
+{
+ AVStream *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_size = atom.size;
+ st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
+
+ if (st->codec->extradata) {
+ get_buffer(pb, st->codec->extradata, atom.size);
+ } else
+ url_fskip(pb, atom.size);
+
+ return 0;
+}
+
+static int mov_read_stco(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
+{
+ AVStream *st = c->fc->streams[c->fc->nb_streams-1];
+ MOVStreamContext *sc = (MOVStreamContext *)st->priv_data;
+ unsigned int i, entries;
+
+ get_byte(pb); /* version */
+ get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
+
+ entries = get_be32(pb);
+
+ if(entries >= UINT_MAX/sizeof(int64_t))
+ return -1;
+
+ sc->chunk_count = entries;
+ sc->chunk_offsets = av_malloc(entries * sizeof(int64_t));
+ if (!sc->chunk_offsets)
+ return -1;
+ if (atom.type == MKTAG('s', 't', 'c', 'o')) {
+ for(i=0; i<entries; i++) {
+ sc->chunk_offsets[i] = get_be32(pb);
+ }
+ } else if (atom.type == MKTAG('c', 'o', '6', '4')) {
+ for(i=0; i<entries; i++) {
+ sc->chunk_offsets[i] = get_be64(pb);
+ }
+ } else
+ return -1;
+
+ return 0;
+}
+
+static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
+{
+ AVStream *st = c->fc->streams[c->fc->nb_streams-1];
+ MOVStreamContext *sc = (MOVStreamContext *)st->priv_data;
+ int entries, frames_per_sample;
+ uint32_t format;
+ uint8_t codec_name[32];
+
+ /* for palette traversal */
+ int color_depth;
+ int color_start;
+ int color_count;
+ int color_end;
+ int color_index;
+ int color_dec;
+ int color_greyscale;
+ unsigned char *color_table;
+ int j;
+ unsigned char r, g, b;
+
+ get_byte(pb); /* version */
+ get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
+
+ entries = get_be32(pb);
+
+ while(entries--) { //Parsing Sample description table
+ enum CodecID id;
+ MOV_atom_t a = { 0, 0, 0 };
+ offset_t start_pos = url_ftell(pb);
+ int size = get_be32(pb); /* size */
+ format = get_le32(pb); /* data format */
+
+ get_be32(pb); /* reserved */
+ get_be16(pb); /* reserved */
+ get_be16(pb); /* index */
+
+ if (st->codec->codec_tag) {
+ /* multiple fourcc, just skip for now */
+ url_fskip(pb, size - (url_ftell(pb) - start_pos));
+ continue;
+ }
+
+ st->codec->codec_tag = format;
+ id = codec_get_id(codec_movaudio_tags, format);
+ 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 */
+ format && format != MKTAG('m', 'p', '4', 's')) { /* skip old asf mpeg4 tag */
+ id = codec_get_id(codec_movvideo_tags, format);
+ if (id <= 0)
+ id = codec_get_id(codec_bmp_tags, format);
+ if (id > 0)
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ }
+
+ dprintf(c->fc, "size=%d 4CC= %c%c%c%c codec_type=%d\n",
+ size,
+ (format >> 0) & 0xff, (format >> 8) & 0xff, (format >> 16) & 0xff, (format >> 24) & 0xff,
+ st->codec->codec_type);
+
+ if(st->codec->codec_type==CODEC_TYPE_VIDEO) {
+ st->codec->codec_id = id;
+ get_be16(pb); /* version */
+ get_be16(pb); /* revision level */
+ get_be32(pb); /* vendor */
+ get_be32(pb); /* temporal quality */
+ get_be32(pb); /* spacial quality */
+
+ st->codec->width = get_be16(pb); /* width */
+ st->codec->height = get_be16(pb); /* height */
+
+ get_be32(pb); /* horiz resolution */
+ get_be32(pb); /* vert resolution */
+ get_be32(pb); /* data size, always 0 */
+ frames_per_sample = get_be16(pb); /* frames per samples */
+#ifdef DEBUG
+ av_log(NULL, AV_LOG_DEBUG, "frames/samples = %d\n", frames_per_sample);
+#endif
+ get_buffer(pb, codec_name, 32); /* codec name, pascal string (FIXME: true for mp4?) */
+ if (codec_name[0] <= 31) {
+ memcpy(st->codec->codec_name, &codec_name[1],codec_name[0]);
+ st->codec->codec_name[codec_name[0]] = 0;
+ }
+
+ st->codec->bits_per_sample = get_be16(pb); /* depth */
+ st->codec->color_table_id = get_be16(pb); /* colortable id */
+
+ /* figure out the palette situation */
+ color_depth = st->codec->bits_per_sample & 0x1F;
+ color_greyscale = st->codec->bits_per_sample & 0x20;
+
+ /* if the depth is 2, 4, or 8 bpp, file is palettized */
+ if ((color_depth == 2) || (color_depth == 4) ||
+ (color_depth == 8)) {
+
+ if (color_greyscale) {
+
+ /* compute the greyscale palette */
+ color_count = 1 << color_depth;
+ color_index = 255;
+ color_dec = 256 / (color_count - 1);
+ for (j = 0; j < color_count; j++) {
+ r = g = b = color_index;
+ c->palette_control.palette[j] =
+ (r << 16) | (g << 8) | (b);
+ color_index -= color_dec;
+ if (color_index < 0)
+ color_index = 0;
+ }
+
+ } else if (st->codec->color_table_id & 0x08) {
+
+ /* if flag bit 3 is set, use the default palette */
+ color_count = 1 << color_depth;
+ if (color_depth == 2)
+ color_table = ff_qt_default_palette_4;
+ else if (color_depth == 4)
+ color_table = ff_qt_default_palette_16;
+ else
+ color_table = ff_qt_default_palette_256;
+
+ for (j = 0; j < color_count; j++) {
+ r = color_table[j * 4 + 0];
+ g = color_table[j * 4 + 1];
+ b = color_table[j * 4 + 2];
+ c->palette_control.palette[j] =
+ (r << 16) | (g << 8) | (b);
+ }
+
+ } else {
+
+ /* load the palette from the file */
+ color_start = get_be32(pb);
+ color_count = get_be16(pb);
+ color_end = get_be16(pb);
+ for (j = color_start; j <= color_end; j++) {
+ /* each R, G, or B component is 16 bits;
+ * only use the top 8 bits; skip alpha bytes
+ * up front */
+ get_byte(pb);
+ get_byte(pb);
+ r = get_byte(pb);
+ get_byte(pb);
+ g = get_byte(pb);
+ get_byte(pb);
+ b = get_byte(pb);
+ get_byte(pb);
+ c->palette_control.palette[j] =
+ (r << 16) | (g << 8) | (b);
+ }
+ }
+
+ st->codec->palctrl = &c->palette_control;
+ st->codec->palctrl->palette_changed = 1;
+ } else
+ st->codec->palctrl = NULL;
+ } else if(st->codec->codec_type==CODEC_TYPE_AUDIO) {
+ int bits_per_sample;
+ uint16_t version = get_be16(pb);
+
+ st->codec->codec_id = id;
+ get_be16(pb); /* revision level */
+ get_be32(pb); /* vendor */
+
+ st->codec->channels = get_be16(pb); /* channel count */
+ dprintf(c->fc, "audio channels %d\n", st->codec->channels);
+ st->codec->bits_per_sample = get_be16(pb); /* sample size */
+ /* do we need to force to 16 for AMR ? */
+
+ /* handle specific s8 codec */
+ get_be16(pb); /* compression id = 0*/
+ get_be16(pb); /* packet size = 0 */
+
+ st->codec->sample_rate = ((get_be32(pb) >> 16));
+
+ switch (st->codec->codec_id) {
+ case CODEC_ID_PCM_S8:
+ case CODEC_ID_PCM_U8:
+ if (st->codec->bits_per_sample == 16)
+ st->codec->codec_id = CODEC_ID_PCM_S16BE;
+ break;
+ case CODEC_ID_PCM_S16LE:
+ case CODEC_ID_PCM_S16BE:
+ if (st->codec->bits_per_sample == 8)
+ st->codec->codec_id = CODEC_ID_PCM_S8;
+ else if (st->codec->bits_per_sample == 24)
+ st->codec->codec_id = CODEC_ID_PCM_S24BE;
+ break;
+ default:
+ break;
+ }
+
+ //Read QT version 1 fields. In version 0 theese dont exist
+ dprintf(c->fc, "version =%d, isom =%d\n",version,c->isom);
+ if(!c->isom) {
+ if(version==1) {
+ sc->samples_per_frame = get_be32(pb);
+ get_be32(pb); /* bytes per packet */
+ sc->bytes_per_frame = get_be32(pb);
+ get_be32(pb); /* bytes per sample */
+ } else if(version==2) {
+ get_be32(pb); /* sizeof struct only */
+ st->codec->sample_rate = av_int2dbl(get_be64(pb)); /* float 64 */
+ st->codec->channels = get_be32(pb);
+ get_be32(pb); /* always 0x7F000000 */
+ get_be32(pb); /* bits per channel if sound is uncompressed */
+ get_be32(pb); /* lcpm format specific flag */
+ get_be32(pb); /* bytes per audio packet if constant */
+ get_be32(pb); /* lpcm frames per audio packet if constant */
+ }
+ }
+
+ bits_per_sample = av_get_bits_per_sample(st->codec->codec_id);
+ if (bits_per_sample) {
+ st->codec->bits_per_sample = bits_per_sample;
+ sc->sample_size = (bits_per_sample >> 3) * st->codec->channels;
+ }
+ } else {
+ /* other codec type, just skip (rtp, mp4s, tmcd ...) */
+ url_fskip(pb, size - (url_ftell(pb) - start_pos));
+ }
+ /* this will read extra atoms at the end (wave, alac, damr, avcC, SMI ...) */
+ a.size = size - (url_ftell(pb) - start_pos);
+ if (a.size > 8)
+ mov_read_default(c, pb, a);
+ else if (a.size > 0)
+ url_fskip(pb, a.size);
+ }
+
+ if(st->codec->codec_type==CODEC_TYPE_AUDIO && st->codec->sample_rate==0 && sc->time_scale>1) {
+ st->codec->sample_rate= sc->time_scale;
+ }
+
+ /* special codec parameters handling */
+ switch (st->codec->codec_id) {
+#ifdef CONFIG_H261_DECODER
+ case CODEC_ID_H261:
+#endif
+#ifdef CONFIG_H263_DECODER
+ case CODEC_ID_H263:
+#endif
+#ifdef CONFIG_MPEG4_DECODER
+ case CODEC_ID_MPEG4:
+#endif
+ st->codec->width= 0; /* let decoder init width/height */
+ st->codec->height= 0;
+ break;
+#ifdef CONFIG_LIBFAAD
+ case CODEC_ID_AAC:
+#endif
+#ifdef CONFIG_VORBIS_DECODER
+ case CODEC_ID_VORBIS:
+#endif
+ case CODEC_ID_MP3ON4:
+ st->codec->sample_rate= 0; /* let decoder init parameters properly */
+ break;
+#ifdef CONFIG_DV_DEMUXER
+ case CODEC_ID_DVAUDIO:
+ c->dv_fctx = av_alloc_format_context();
+ c->dv_demux = dv_init_demux(c->dv_fctx);
+ if (!c->dv_demux) {
+ av_log(c->fc, AV_LOG_ERROR, "dv demux context init error\n");
+ return -1;
+ }
+ sc->dv_audio_container = 1;
+ st->codec->codec_id = CODEC_ID_PCM_S16LE;
+ break;
+#endif
+ /* no ifdef since parameters are always those */
+ case CODEC_ID_AMR_WB:
+ st->codec->sample_rate= 16000;
+ st->codec->channels= 1; /* really needed */
+ break;
+ case CODEC_ID_AMR_NB:
+ st->codec->sample_rate= 8000;
+ st->codec->channels= 1; /* really needed */
+ break;
+ case CODEC_ID_MP2:
+ case CODEC_ID_MP3:
+ st->codec->codec_type = CODEC_TYPE_AUDIO; /* force type after stsd for m1a hdlr */
+ st->need_parsing = 1;
+ break;
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+static int mov_read_stsc(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
+{
+ AVStream *st = c->fc->streams[c->fc->nb_streams-1];
+ MOVStreamContext *sc = (MOVStreamContext *)st->priv_data;
+ unsigned int i, entries;
+
+ get_byte(pb); /* version */
+ get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
+
+ entries = get_be32(pb);
+
+ if(entries >= UINT_MAX / sizeof(MOV_sample_to_chunk_tbl))
+ return -1;
+
+#ifdef DEBUG
+av_log(NULL, AV_LOG_DEBUG, "track[%i].stsc.entries = %i\n", c->fc->nb_streams-1, entries);
+#endif
+ sc->sample_to_chunk_sz = entries;
+ sc->sample_to_chunk = av_malloc(entries * sizeof(MOV_sample_to_chunk_tbl));
+ if (!sc->sample_to_chunk)
+ return -1;
+ for(i=0; i<entries; i++) {
+ sc->sample_to_chunk[i].first = get_be32(pb);
+ sc->sample_to_chunk[i].count = get_be32(pb);
+ sc->sample_to_chunk[i].id = get_be32(pb);
+ }
+ return 0;
+}
+
+static int mov_read_stss(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
+{
+ AVStream *st = c->fc->streams[c->fc->nb_streams-1];
+ MOVStreamContext *sc = (MOVStreamContext *)st->priv_data;
+ unsigned int i, entries;
+
+ get_byte(pb); /* version */
+ get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
+
+ entries = get_be32(pb);
+
+ if(entries >= UINT_MAX / sizeof(long))
+ return -1;
+
+ sc->keyframe_count = entries;
+#ifdef DEBUG
+ av_log(NULL, AV_LOG_DEBUG, "keyframe_count = %d\n", sc->keyframe_count);
+#endif
+ sc->keyframes = av_malloc(entries * sizeof(long));
+ if (!sc->keyframes)
+ return -1;
+ for(i=0; i<entries; i++) {
+ sc->keyframes[i] = get_be32(pb);
+#ifdef DEBUG
+/* av_log(NULL, AV_LOG_DEBUG, "keyframes[]=%ld\n", sc->keyframes[i]); */
+#endif
+ }
+ return 0;
+}
+
+static int mov_read_stsz(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
+{
+ AVStream *st = c->fc->streams[c->fc->nb_streams-1];
+ MOVStreamContext *sc = (MOVStreamContext *)st->priv_data;
+ unsigned int i, entries, sample_size;
+
+ get_byte(pb); /* version */
+ get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
+
+ sample_size = get_be32(pb);
+ if (!sc->sample_size) /* do not overwrite value computed in stsd */
+ sc->sample_size = sample_size;
+ entries = get_be32(pb);
+ if(entries >= UINT_MAX / sizeof(long))
+ return -1;
+
+ sc->sample_count = entries;
+ if (sample_size)
+ return 0;
+
+#ifdef DEBUG
+ av_log(NULL, AV_LOG_DEBUG, "sample_size = %d sample_count = %d\n", sc->sample_size, sc->sample_count);
+#endif
+ sc->sample_sizes = av_malloc(entries * sizeof(long));
+ if (!sc->sample_sizes)
+ return -1;
+ for(i=0; i<entries; i++) {
+ sc->sample_sizes[i] = get_be32(pb);
+#ifdef DEBUG
+ av_log(NULL, AV_LOG_DEBUG, "sample_sizes[]=%ld\n", sc->sample_sizes[i]);
+#endif
+ }
+ return 0;
+}
+
+static int mov_read_stts(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
+{
+ AVStream *st = c->fc->streams[c->fc->nb_streams-1];
+ MOVStreamContext *sc = (MOVStreamContext *)st->priv_data;
+ unsigned int i, entries;
+ int64_t duration=0;
+ int64_t total_sample_count=0;
+
+ get_byte(pb); /* version */
+ get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
+ entries = get_be32(pb);
+ if(entries >= UINT_MAX / sizeof(Time2Sample))
+ return -1;
+
+ sc->stts_count = entries;
+ sc->stts_data = av_malloc(entries * sizeof(Time2Sample));
+
+#ifdef DEBUG
+av_log(NULL, AV_LOG_DEBUG, "track[%i].stts.entries = %i\n", c->fc->nb_streams-1, entries);
+#endif
+
+ sc->time_rate=0;
+
+ for(i=0; i<entries; i++) {
+ int sample_duration;
+ int sample_count;
+
+ sample_count=get_be32(pb);
+ sample_duration = get_be32(pb);
+ sc->stts_data[i].count= sample_count;
+ sc->stts_data[i].duration= sample_duration;
+
+ sc->time_rate= ff_gcd(sc->time_rate, sample_duration);
+
+ dprintf(c->fc, "sample_count=%d, sample_duration=%d\n",sample_count,sample_duration);
+
+ duration+=(int64_t)sample_duration*sample_count;
+ total_sample_count+=sample_count;
+ }
+
+ st->nb_frames= total_sample_count;
+ if(duration)
+ st->duration= duration;
+ return 0;
+}
+
+static int mov_read_ctts(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
+{
+ AVStream *st = c->fc->streams[c->fc->nb_streams-1];
+ MOVStreamContext *sc = (MOVStreamContext *)st->priv_data;
+ unsigned int i, entries;
+
+ get_byte(pb); /* version */
+ get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
+ entries = get_be32(pb);
+ if(entries >= UINT_MAX / sizeof(Time2Sample))
+ return -1;
+
+ sc->ctts_count = entries;
+ sc->ctts_data = av_malloc(entries * sizeof(Time2Sample));
+
+ dprintf(c->fc, "track[%i].ctts.entries = %i\n", c->fc->nb_streams-1, entries);
+
+ for(i=0; i<entries; i++) {
+ int count =get_be32(pb);
+ int duration =get_be32(pb);
+
+ if (duration < 0) {
+ av_log(c->fc, AV_LOG_ERROR, "negative ctts, ignoring\n");
+ sc->ctts_count = 0;
+ url_fskip(pb, 8 * (entries - i - 1));
+ break;
+ }
+ sc->ctts_data[i].count = count;
+ sc->ctts_data[i].duration= duration;
+
+ sc->time_rate= ff_gcd(sc->time_rate, duration);
+ }
+ return 0;
+}
+
+static int mov_read_trak(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
+{
+ AVStream *st;
+ MOVStreamContext *sc;
+
+ st = av_new_stream(c->fc, c->fc->nb_streams);
+ if (!st) return -2;
+ sc = av_mallocz(sizeof(MOVStreamContext));
+ if (!sc) {
+ av_free(st);
+ return -1;
+ }
+
+ st->priv_data = sc;
+ st->codec->codec_type = CODEC_TYPE_DATA;
+ st->start_time = 0; /* XXX: check */
+ c->streams[c->fc->nb_streams-1] = sc;
+
+ return mov_read_default(c, pb, atom);
+}
+
+static int mov_read_tkhd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
+{
+ AVStream *st = c->fc->streams[c->fc->nb_streams-1];
+ int version = get_byte(pb);
+
+ get_byte(pb); get_byte(pb);
+ get_byte(pb); /* flags */
+ /*
+ MOV_TRACK_ENABLED 0x0001
+ MOV_TRACK_IN_MOVIE 0x0002
+ MOV_TRACK_IN_PREVIEW 0x0004
+ MOV_TRACK_IN_POSTER 0x0008
+ */
+
+ if (version == 1) {
+ get_be64(pb);
+ get_be64(pb);
+ } else {
+ get_be32(pb); /* creation time */
+ get_be32(pb); /* modification time */
+ }
+ st->id = (int)get_be32(pb); /* track id (NOT 0 !)*/
+ get_be32(pb); /* reserved */
+ st->start_time = 0; /* check */
+ (version == 1) ? get_be64(pb) : get_be32(pb); /* highlevel (considering edits) duration in movie timebase */
+ get_be32(pb); /* reserved */
+ get_be32(pb); /* reserved */
+
+ get_be16(pb); /* layer */
+ get_be16(pb); /* alternate group */
+ get_be16(pb); /* volume */
+ get_be16(pb); /* reserved */
+
+ url_fskip(pb, 36); /* display matrix */
+
+ /* those are fixed-point */
+ get_be32(pb); /* track width */
+ get_be32(pb); /* track height */
+
+ return 0;
+}
+
+/* this atom should be null (from specs), but some buggy files put the 'moov' atom inside it... */
+/* like the files created with Adobe Premiere 5.0, for samples see */
+/* http://graphics.tudelft.nl/~wouter/publications/soundtests/ */
+static int mov_read_wide(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
+{
+ int err;
+
+ if (atom.size < 8)
+ return 0; /* continue */
+ if (get_be32(pb) != 0) { /* 0 sized mdat atom... use the 'wide' atom size */
+ url_fskip(pb, atom.size - 4);
+ 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);
+ return 0;
+ }
+ err = mov_read_mdat(c, pb, atom);
+ return err;
+}
+
+static int mov_read_cmov(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
+{
+#ifdef CONFIG_ZLIB
+ ByteIOContext ctx;
+ uint8_t *cmov_data;
+ uint8_t *moov_data; /* uncompressed data */
+ long cmov_len, moov_len;
+ int ret;
+
+ get_be32(pb); /* dcom atom */
+ if (get_le32(pb) != MKTAG( 'd', 'c', 'o', 'm' ))
+ return -1;
+ if (get_le32(pb) != MKTAG( 'z', 'l', 'i', 'b' )) {
+ av_log(NULL, AV_LOG_ERROR, "unknown compression for cmov atom !");
+ return -1;
+ }
+ get_be32(pb); /* cmvd atom */
+ if (get_le32(pb) != MKTAG( 'c', 'm', 'v', 'd' ))
+ return -1;
+ moov_len = get_be32(pb); /* uncompressed size */
+ cmov_len = atom.size - 6 * 4;
+
+ cmov_data = av_malloc(cmov_len);
+ if (!cmov_data)
+ return -1;
+ moov_data = av_malloc(moov_len);
+ if (!moov_data) {
+ av_free(cmov_data);
+ return -1;
+ }
+ get_buffer(pb, cmov_data, cmov_len);
+ if(uncompress (moov_data, (uLongf *) &moov_len, (const Bytef *)cmov_data, cmov_len) != Z_OK)
+ return -1;
+ if(init_put_byte(&ctx, moov_data, moov_len, 0, NULL, NULL, NULL, NULL) != 0)
+ return -1;
+ 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); }
+#endif
+ ret = mov_read_default(c, &ctx, atom);
+ av_free(moov_data);
+ av_free(cmov_data);
+ return ret;
+#else
+ av_log(c->fc, AV_LOG_ERROR, "this file requires zlib support compiled in\n");
+ return -1;
+#endif
+}
+
+/* edit list atom */
+static int mov_read_elst(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
+{
+ int i, edit_count;
+
+ get_byte(pb); /* version */
+ get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
+ edit_count= c->streams[c->fc->nb_streams-1]->edit_count = get_be32(pb); /* entries */
+
+ for(i=0; i<edit_count; i++){
+ get_be32(pb); /* Track duration */
+ get_be32(pb); /* Media time */
+ get_be32(pb); /* Media rate */
+ }
+ dprintf(c->fc, "track[%i].edit_count = %i\n", c->fc->nb_streams-1, c->streams[c->fc->nb_streams-1]->edit_count);
+ return 0;
+}
+
+static const MOVParseTableEntry mov_default_parse_table[] = {
+/* mp4 atoms */
+{ MKTAG( 'c', 'o', '6', '4' ), mov_read_stco },
+{ MKTAG( 'c', 't', 't', 's' ), mov_read_ctts }, /* composition time to sample */
+{ MKTAG( 'e', 'd', 't', 's' ), mov_read_default },
+{ MKTAG( 'e', 'l', 's', 't' ), mov_read_elst },
+{ MKTAG( 'e', 'n', 'd', 'a' ), mov_read_enda },
+{ MKTAG( 'f', 'i', 'e', 'l' ), mov_read_extradata },
+{ MKTAG( 'f', 't', 'y', 'p' ), mov_read_ftyp },
+{ MKTAG( 'h', 'd', 'l', 'r' ), mov_read_hdlr },
+{ MKTAG( 'j', 'p', '2', 'h' ), mov_read_extradata },
+{ MKTAG( 'm', 'd', 'a', 't' ), mov_read_mdat },
+{ MKTAG( 'm', 'd', 'h', 'd' ), mov_read_mdhd },
+{ MKTAG( 'm', 'd', 'i', 'a' ), mov_read_default },
+{ MKTAG( 'm', 'i', 'n', 'f' ), mov_read_default },
+{ MKTAG( 'm', 'o', 'o', 'v' ), mov_read_moov },
+{ MKTAG( 'm', 'v', 'h', 'd' ), mov_read_mvhd },
+{ MKTAG( 'S', 'M', 'I', ' ' ), mov_read_smi }, /* Sorenson extension ??? */
+{ MKTAG( 'a', 'l', 'a', 'c' ), mov_read_extradata }, /* alac specific atom */
+{ MKTAG( 'a', 'v', 'c', 'C' ), mov_read_avcC },
+{ MKTAG( 's', 't', 'b', 'l' ), mov_read_default },
+{ MKTAG( 's', 't', 'c', 'o' ), mov_read_stco },
+{ 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 */
+{ MKTAG( 's', 't', 's', 'z' ), mov_read_stsz }, /* sample size */
+{ MKTAG( 's', 't', 't', 's' ), mov_read_stts },
+{ MKTAG( 't', 'k', 'h', 'd' ), mov_read_tkhd }, /* track header */
+{ MKTAG( 't', 'r', 'a', 'k' ), mov_read_trak },
+{ MKTAG( 'w', 'a', 'v', 'e' ), mov_read_wave },
+{ MKTAG( 'c', 't', 'a', 'b' ), mov_read_ctab },
+{ MKTAG( 'e', 's', 'd', 's' ), mov_read_esds },
+{ MKTAG( 'w', 'i', 'd', 'e' ), mov_read_wide }, /* place holder */
+{ MKTAG( 'c', 'm', 'o', 'v' ), mov_read_cmov },
+{ 0L, NULL }
+};
+
+static void mov_free_stream_context(MOVStreamContext *sc)
+{
+ if(sc) {
+ av_freep(&sc->ctts_data);
+ av_freep(&sc);
+ }
+}
+
+/* XXX: is it sufficient ? */
+static int mov_probe(AVProbeData *p)
+{
+ unsigned int offset;
+ uint32_t tag;
+ int score = 0;
+
+ /* check file header */
+ if (p->buf_size <= 12)
+ return 0;
+ offset = 0;
+ for(;;) {
+ /* ignore invalid offset */
+ if ((offset + 8) > (unsigned int)p->buf_size)
+ return score;
+ tag = AV_RL32(p->buf + offset + 4);
+ switch(tag) {
+ /* check for obvious tags */
+ case MKTAG( 'j', 'P', ' ', ' ' ): /* jpeg 2000 signature */
+ case MKTAG( 'm', 'o', 'o', 'v' ):
+ case MKTAG( 'm', 'd', 'a', 't' ):
+ case MKTAG( 'p', 'n', 'o', 't' ): /* detect movs with preview pics like ew.mov and april.mov */
+ case MKTAG( 'u', 'd', 't', 'a' ): /* Packet Video PVAuthor adds this and a lot of more junk */
+ return AVPROBE_SCORE_MAX;
+ /* those are more common words, so rate then a bit less */
+ case MKTAG( 'w', 'i', 'd', 'e' ):
+ case MKTAG( 'f', 'r', 'e', 'e' ):
+ case MKTAG( 'j', 'u', 'n', 'k' ):
+ case MKTAG( 'p', 'i', 'c', 't' ):
+ return AVPROBE_SCORE_MAX - 5;
+ case MKTAG( 'f', 't', 'y', 'p' ):
+ case MKTAG( 's', 'k', 'i', 'p' ):
+ case MKTAG( 'u', 'u', 'i', 'd' ):
+ offset = AV_RB32(p->buf+offset) + offset;
+ /* if we only find those cause probedata is too small at least rate them */
+ score = AVPROBE_SCORE_MAX - 50;
+ break;
+ default:
+ /* unrecognized tag */
+ return score;
+ }
+ }
+ return score;
+}
+
+static void mov_build_index(MOVContext *mov, AVStream *st)
+{
+ MOVStreamContext *sc = st->priv_data;
+ offset_t current_offset;
+ int64_t current_dts = 0;
+ unsigned int stts_index = 0;
+ unsigned int stsc_index = 0;
+ unsigned int stss_index = 0;
+ unsigned int i, j, k;
+
+ if (sc->sample_sizes || st->codec->codec_type == CODEC_TYPE_VIDEO || sc->dv_audio_container) {
+ unsigned int current_sample = 0;
+ unsigned int stts_sample = 0;
+ unsigned int keyframe, sample_size;
+ unsigned int distance = 0;
+
+ st->nb_frames = sc->sample_count;
+ for (i = 0; i < sc->chunk_count; i++) {
+ current_offset = sc->chunk_offsets[i];
+ if (stsc_index + 1 < sc->sample_to_chunk_sz && i + 1 == sc->sample_to_chunk[stsc_index + 1].first)
+ stsc_index++;
+ for (j = 0; j < sc->sample_to_chunk[stsc_index].count; j++) {
+ if (current_sample >= sc->sample_count) {
+ av_log(mov->fc, AV_LOG_ERROR, "wrong sample count\n");
+ goto out;
+ }
+ keyframe = !sc->keyframe_count || current_sample + 1 == sc->keyframes[stss_index];
+ if (keyframe) {
+ distance = 0;
+ if (stss_index + 1 < sc->keyframe_count)
+ stss_index++;
+ }
+ sample_size = sc->sample_size > 0 ? sc->sample_size : sc->sample_sizes[current_sample];
+ 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);
+ av_add_index_entry(st, current_offset, current_dts, sample_size, distance, keyframe ? AVINDEX_KEYFRAME : 0);
+ current_offset += sample_size;
+ assert(sc->stts_data[stts_index].duration % sc->time_rate == 0);
+ current_dts += sc->stts_data[stts_index].duration / sc->time_rate;
+ distance++;
+ stts_sample++;
+ current_sample++;
+ if (stts_index + 1 < sc->stts_count && stts_sample == sc->stts_data[stts_index].count) {
+ stts_sample = 0;
+ stts_index++;
+ }
+ }
+ }
+ } else { /* read whole chunk */
+ unsigned int chunk_samples, chunk_size, chunk_duration;
+
+ for (i = 0; i < sc->chunk_count; i++) {
+ current_offset = sc->chunk_offsets[i];
+ if (stsc_index + 1 < sc->sample_to_chunk_sz && i + 1 == sc->sample_to_chunk[stsc_index + 1].first)
+ stsc_index++;
+ chunk_samples = sc->sample_to_chunk[stsc_index].count;
+ /* get chunk size */
+ if (sc->sample_size > 1 || st->codec->codec_id == CODEC_ID_PCM_U8 || st->codec->codec_id == CODEC_ID_PCM_S8)
+ chunk_size = chunk_samples * sc->sample_size;
+ else if (sc->samples_per_frame > 0 && (chunk_samples * sc->bytes_per_frame % sc->samples_per_frame == 0))
+ chunk_size = chunk_samples * sc->bytes_per_frame / sc->samples_per_frame;
+ else { /* workaround to find nearest next chunk offset */
+ chunk_size = INT_MAX;
+ for (j = 0; j < mov->total_streams; j++) {
+ MOVStreamContext *msc = mov->streams[j];
+
+ for (k = msc->next_chunk; k < msc->chunk_count; k++) {
+ if (msc->chunk_offsets[k] > current_offset && msc->chunk_offsets[k] - current_offset < chunk_size) {
+ chunk_size = msc->chunk_offsets[k] - current_offset;
+ msc->next_chunk = k;
+ break;
+ }
+ }
+ }
+ /* check for last chunk */
+ if (chunk_size == INT_MAX)
+ for (j = 0; j < mov->mdat_count; j++) {
+ dprintf(mov->fc, "mdat %d, offset %"PRIx64", size %"PRId64", current offset %"PRIx64"\n",
+ j, mov->mdat_list[j].offset, mov->mdat_list[j].size, current_offset);
+ if (mov->mdat_list[j].offset <= current_offset && mov->mdat_list[j].offset + mov->mdat_list[j].size > current_offset)
+ chunk_size = mov->mdat_list[j].offset + mov->mdat_list[j].size - current_offset;
+ }
+ assert(chunk_size != INT_MAX);
+ for (j = 0; j < mov->total_streams; j++) {
+ mov->streams[j]->next_chunk = 0;
+ }
+ }
+ av_add_index_entry(st, current_offset, current_dts, chunk_size, 0, AVINDEX_KEYFRAME);
+ /* get chunk duration */
+ chunk_duration = 0;
+ while (chunk_samples > 0) {
+ if (chunk_samples < sc->stts_data[stts_index].count) {
+ chunk_duration += sc->stts_data[stts_index].duration * chunk_samples;
+ sc->stts_data[stts_index].count -= chunk_samples;
+ break;
+ } else {
+ chunk_duration += sc->stts_data[stts_index].duration * chunk_samples;
+ chunk_samples -= sc->stts_data[stts_index].count;
+ if (stts_index + 1 < sc->stts_count) {
+ stts_index++;
+ }
+ }
+ }
+ dprintf(mov->fc, "AVIndex stream %d, chunk %d, offset %"PRIx64", dts %"PRId64", size %d, duration %d\n",
+ st->index, i, current_offset, current_dts, chunk_size, chunk_duration);
+ assert(chunk_duration % sc->time_rate == 0);
+ current_dts += chunk_duration / sc->time_rate;
+ }
+ }
+ out:
+ /* adjust sample count to avindex entries */
+ sc->sample_count = st->nb_index_entries;
+}
+
+static int mov_read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+ MOVContext *mov = (MOVContext *) s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ int i, err;
+ MOV_atom_t atom = { 0, 0, 0 };
+
+ mov->fc = s;
+ mov->parse_table = mov_default_parse_table;
+
+ if(!url_is_streamed(pb)) /* .mov and .mp4 aren't streamable anyway (only progressive download if moov is before mdat) */
+ atom.size = url_fsize(pb);
+ else
+ atom.size = 0x7FFFFFFFFFFFFFFFLL;
+
+ /* check MOV header */
+ err = mov_read_default(mov, pb, atom);
+ if (err<0 || (!mov->found_moov && !mov->found_mdat)) {
+ av_log(s, AV_LOG_ERROR, "mov: header not found !!! (err:%d, moov:%d, mdat:%d) pos:%"PRId64"\n",
+ err, mov->found_moov, mov->found_mdat, url_ftell(pb));
+ return -1;
+ }
+ dprintf(mov->fc, "on_parse_exit_offset=%d\n", (int) url_ftell(pb));
+
+ /* some cleanup : make sure we are on the mdat atom */
+ if(!url_is_streamed(pb) && (url_ftell(pb) != mov->mdat_offset))
+ url_fseek(pb, mov->mdat_offset, SEEK_SET);
+
+ mov->total_streams = s->nb_streams;
+
+ for(i=0; i<mov->total_streams; i++) {
+ MOVStreamContext *sc = mov->streams[i];
+ AVStream *st = s->streams[i];
+ /* sanity checks */
+ if(!sc->stts_count || !sc->chunk_count || !sc->sample_to_chunk_sz ||
+ (!sc->sample_size && !sc->sample_count)){
+ av_log(s, AV_LOG_ERROR, "missing mandatory atoms, broken header\n");
+ sc->sample_count = 0; //ignore track
+ continue;
+ }
+ if(!sc->time_rate)
+ sc->time_rate=1;
+ if(!sc->time_scale)
+ sc->time_scale= mov->time_scale;
+ av_set_pts_info(st, 64, sc->time_rate, sc->time_scale);
+
+ if (st->codec->codec_type == CODEC_TYPE_AUDIO && sc->stts_count == 1)
+ st->codec->frame_size = sc->stts_data[0].duration;
+
+ if(st->duration != AV_NOPTS_VALUE){
+ assert(st->duration % sc->time_rate == 0);
+ st->duration /= sc->time_rate;
+ }
+ sc->ffindex = i;
+ mov_build_index(mov, st);
+ }
+
+ for(i=0; i<mov->total_streams; i++) {
+ /* dont need those anymore */
+ av_freep(&mov->streams[i]->chunk_offsets);
+ av_freep(&mov->streams[i]->sample_to_chunk);
+ av_freep(&mov->streams[i]->sample_sizes);
+ av_freep(&mov->streams[i]->keyframes);
+ av_freep(&mov->streams[i]->stts_data);
+ }
+ av_freep(&mov->mdat_list);
+ return 0;
+}
+
+static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ MOVContext *mov = s->priv_data;
+ MOVStreamContext *sc = 0;
+ AVIndexEntry *sample = 0;
+ int64_t best_dts = INT64_MAX;
+ int i;
+
+ for (i = 0; i < mov->total_streams; i++) {
+ MOVStreamContext *msc = mov->streams[i];
+
+ if (s->streams[i]->discard != AVDISCARD_ALL && msc->current_sample < msc->sample_count) {
+ AVIndexEntry *current_sample = &s->streams[i]->index_entries[msc->current_sample];
+ int64_t dts = av_rescale(current_sample->timestamp * (int64_t)msc->time_rate, AV_TIME_BASE, msc->time_scale);
+
+ dprintf(s, "stream %d, sample %ld, dts %"PRId64"\n", i, msc->current_sample, dts);
+ if (dts < best_dts) {
+ sample = current_sample;
+ best_dts = dts;
+ sc = msc;
+ }
+ }
+ }
+ if (!sample)
+ return -1;
+ /* must be done just before reading, to avoid infinite loop on sample */
+ sc->current_sample++;
+ if (sample->pos >= url_fsize(&s->pb)) {
+ av_log(mov->fc, AV_LOG_ERROR, "stream %d, offset 0x%"PRIx64": partial file\n", sc->ffindex, sample->pos);
+ return -1;
+ }
+#ifdef CONFIG_DV_DEMUXER
+ if (sc->dv_audio_container) {
+ dv_get_packet(mov->dv_demux, pkt);
+ dprintf(s, "dv audio pkt size %d\n", pkt->size);
+ } else {
+#endif
+ url_fseek(&s->pb, sample->pos, SEEK_SET);
+ av_get_packet(&s->pb, pkt, sample->size);
+#ifdef CONFIG_DV_DEMUXER
+ if (mov->dv_demux) {
+ void *pkt_destruct_func = pkt->destruct;
+ dv_produce_packet(mov->dv_demux, pkt, pkt->data, pkt->size);
+ pkt->destruct = pkt_destruct_func;
+ }
+ }
+#endif
+ pkt->stream_index = sc->ffindex;
+ pkt->dts = sample->timestamp;
+ if (sc->ctts_data) {
+ assert(sc->ctts_data[sc->sample_to_ctime_index].duration % sc->time_rate == 0);
+ pkt->pts = pkt->dts + sc->ctts_data[sc->sample_to_ctime_index].duration / sc->time_rate;
+ /* update ctts context */
+ sc->sample_to_ctime_sample++;
+ if (sc->sample_to_ctime_index < sc->ctts_count && sc->ctts_data[sc->sample_to_ctime_index].count == sc->sample_to_ctime_sample) {
+ sc->sample_to_ctime_index++;
+ sc->sample_to_ctime_sample = 0;
+ }
+ } else {
+ pkt->pts = pkt->dts;
+ }
+ pkt->flags |= sample->flags & AVINDEX_KEYFRAME ? 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)
+{
+ 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);
+ if (sample < 0) /* not sure what to do */
+ return -1;
+ sc->current_sample = sample;
+ dprintf(st->codec, "stream %d, found sample %ld\n", st->index, sc->current_sample);
+ /* adjust ctts index */
+ if (sc->ctts_data) {
+ time_sample = 0;
+ for (i = 0; i < sc->ctts_count; i++) {
+ time_sample += sc->ctts_data[i].count;
+ if (time_sample >= sc->current_sample) {
+ sc->sample_to_ctime_index = i;
+ sc->sample_to_ctime_sample = time_sample - sc->current_sample;
+ break;
+ }
+ }
+ }
+ return sample;
+}
+
+static int mov_read_seek(AVFormatContext *s, int stream_index, int64_t sample_time, int flags)
+{
+ AVStream *st;
+ int64_t seek_timestamp, timestamp;
+ int sample;
+ int i;
+
+ if (stream_index >= s->nb_streams)
+ return -1;
+
+ st = s->streams[stream_index];
+ sample = mov_seek_stream(st, sample_time, flags);
+ if (sample < 0)
+ return -1;
+
+ /* adjust seek timestamp to found sample timestamp */
+ seek_timestamp = st->index_entries[sample].timestamp;
+
+ for (i = 0; i < s->nb_streams; i++) {
+ st = s->streams[i];
+ if (stream_index == i || st->discard == AVDISCARD_ALL)
+ continue;
+
+ timestamp = av_rescale_q(seek_timestamp, s->streams[stream_index]->time_base, st->time_base);
+ mov_seek_stream(st, timestamp, flags);
+ }
+ return 0;
+}
+
+static int mov_read_close(AVFormatContext *s)
+{
+ int i;
+ MOVContext *mov = (MOVContext *) s->priv_data;
+ for(i=0; i<mov->total_streams; i++)
+ mov_free_stream_context(mov->streams[i]);
+ /* free color tabs */
+ for(i=0; i<mov->ctab_size; i++)
+ av_freep(&mov->ctab[i]);
+ if(mov->dv_demux){
+ for(i=0; i<mov->dv_fctx->nb_streams; i++){
+ av_freep(&mov->dv_fctx->streams[i]->codec);
+ av_freep(&mov->dv_fctx->streams[i]);
+ }
+ av_freep(&mov->dv_fctx);
+ av_freep(&mov->dv_demux);
+ }
+ av_freep(&mov->ctab);
+ return 0;
+}
+
+AVInputFormat mov_demuxer = {
+ "mov,mp4,m4a,3gp,3g2,mj2",
+ "QuickTime/MPEG4/Motion JPEG 2000 format",
+ sizeof(MOVContext),
+ mov_probe,
+ mov_read_header,
+ mov_read_packet,
+ mov_read_close,
+ mov_read_seek,
+};
diff --git a/contrib/ffmpeg/libavformat/movenc.c b/contrib/ffmpeg/libavformat/movenc.c
new file mode 100644
index 000000000..e93416914
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/movenc.c
@@ -0,0 +1,1689 @@
+/*
+ * MOV, 3GP, MP4 muxer
+ * Copyright (c) 2003 Thomas Raivio.
+ * Copyright (c) 2004 Gildas Bazin <gbazin at videolan dot org>.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include "avformat.h"
+#include "riff.h"
+#include "avio.h"
+#include "isom.h"
+
+#undef NDEBUG
+#include <assert.h>
+
+#define MOV_INDEX_CLUSTER_SIZE 16384
+#define globalTimescale 1000
+
+#define MODE_MP4 0
+#define MODE_MOV 1
+#define MODE_3GP 2
+#define MODE_PSP 3 // 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 4
+
+typedef struct MOVIentry {
+ unsigned int flags, size;
+ uint64_t pos;
+ unsigned int samplesInChunk;
+ char key_frame;
+ unsigned int entries;
+ int64_t cts;
+ int64_t dts;
+} MOVIentry;
+
+typedef struct MOVIndex {
+ int mode;
+ int entry;
+ long timescale;
+ long time;
+ int64_t trackDuration;
+ long sampleCount;
+ long sampleSize;
+ int hasKeyframes;
+ int hasBframes;
+ int language;
+ int trackID;
+ int tag;
+ AVCodecContext *enc;
+
+ int vosLen;
+ uint8_t *vosData;
+ MOVIentry *cluster;
+ int audio_vbr;
+} MOVTrack;
+
+typedef struct MOVContext {
+ int mode;
+ int64_t time;
+ int nb_streams;
+ offset_t mdat_pos;
+ uint64_t mdat_size;
+ long timescale;
+ MOVTrack tracks[MAX_STREAMS];
+} MOVContext;
+
+//FIXME supprt 64bit varaint with wide placeholders
+static offset_t updateSize (ByteIOContext *pb, offset_t pos)
+{
+ offset_t curpos = url_ftell(pb);
+ url_fseek(pb, pos, SEEK_SET);
+ put_be32(pb, curpos - pos); /* rewrite size */
+ url_fseek(pb, curpos, SEEK_SET);
+
+ return curpos - pos;
+}
+
+/* Chunk offset atom */
+static int mov_write_stco_tag(ByteIOContext *pb, MOVTrack* track)
+{
+ int i;
+ int mode64 = 0; // use 32 bit size variant if possible
+ offset_t pos = url_ftell(pb);
+ put_be32(pb, 0); /* size */
+ if (pos > UINT32_MAX) {
+ mode64 = 1;
+ put_tag(pb, "co64");
+ } else
+ put_tag(pb, "stco");
+ put_be32(pb, 0); /* version & flags */
+ put_be32(pb, track->entry); /* entry count */
+ for (i=0; i<track->entry; i++) {
+ if(mode64 == 1)
+ put_be64(pb, track->cluster[i].pos);
+ else
+ put_be32(pb, track->cluster[i].pos);
+ }
+ return updateSize (pb, pos);
+}
+
+/* Sample size atom */
+static int mov_write_stsz_tag(ByteIOContext *pb, MOVTrack* track)
+{
+ int equalChunks = 1;
+ int i, j, entries = 0, tst = -1, oldtst = -1;
+
+ offset_t pos = url_ftell(pb);
+ put_be32(pb, 0); /* size */
+ put_tag(pb, "stsz");
+ put_be32(pb, 0); /* version & flags */
+
+ for (i=0; i<track->entry; i++) {
+ tst = track->cluster[i].size/track->cluster[i].entries;
+ if(oldtst != -1 && tst != oldtst) {
+ equalChunks = 0;
+ }
+ oldtst = tst;
+ entries += track->cluster[i].entries;
+ }
+ if (equalChunks) {
+ int sSize = track->cluster[0].size/track->cluster[0].entries;
+ put_be32(pb, sSize); // sample size
+ put_be32(pb, entries); // sample count
+ }
+ else {
+ put_be32(pb, 0); // sample size
+ put_be32(pb, entries); // sample count
+ for (i=0; i<track->entry; i++) {
+ for ( j=0; j<track->cluster[i].entries; j++) {
+ put_be32(pb, track->cluster[i].size /
+ track->cluster[i].entries);
+ }
+ }
+ }
+ return updateSize (pb, pos);
+}
+
+/* Sample to chunk atom */
+static int mov_write_stsc_tag(ByteIOContext *pb, MOVTrack* track)
+{
+ int index = 0, oldval = -1, i;
+ offset_t entryPos, curpos;
+
+ offset_t pos = url_ftell(pb);
+ put_be32(pb, 0); /* size */
+ put_tag(pb, "stsc");
+ put_be32(pb, 0); // version & flags
+ entryPos = url_ftell(pb);
+ put_be32(pb, track->entry); // entry count
+ for (i=0; i<track->entry; i++) {
+ if(oldval != track->cluster[i].samplesInChunk)
+ {
+ put_be32(pb, i+1); // first chunk
+ put_be32(pb, track->cluster[i].samplesInChunk); // samples per chunk
+ put_be32(pb, 0x1); // sample description index
+ oldval = track->cluster[i].samplesInChunk;
+ index++;
+ }
+ }
+ curpos = url_ftell(pb);
+ url_fseek(pb, entryPos, SEEK_SET);
+ put_be32(pb, index); // rewrite size
+ url_fseek(pb, curpos, SEEK_SET);
+
+ return updateSize (pb, pos);
+}
+
+/* Sync sample atom */
+static int mov_write_stss_tag(ByteIOContext *pb, MOVTrack* track)
+{
+ offset_t curpos, entryPos;
+ int i, index = 0;
+ offset_t pos = url_ftell(pb);
+ put_be32(pb, 0); // size
+ put_tag(pb, "stss");
+ put_be32(pb, 0); // version & flags
+ entryPos = url_ftell(pb);
+ put_be32(pb, track->entry); // entry count
+ for (i=0; i<track->entry; i++) {
+ if(track->cluster[i].key_frame == 1) {
+ put_be32(pb, i+1);
+ index++;
+ }
+ }
+ curpos = url_ftell(pb);
+ url_fseek(pb, entryPos, SEEK_SET);
+ put_be32(pb, index); // rewrite size
+ url_fseek(pb, curpos, SEEK_SET);
+ return updateSize (pb, pos);
+}
+
+static int mov_write_amr_tag(ByteIOContext *pb, MOVTrack *track)
+{
+ put_be32(pb, 0x11); /* size */
+ if (track->mode == MODE_MOV) put_tag(pb, "samr");
+ else put_tag(pb, "damr");
+ put_tag(pb, "FFMP");
+ put_byte(pb, 0); /* decoder version */
+
+ put_be16(pb, 0x81FF); /* Mode set (all modes for AMR_NB) */
+ put_byte(pb, 0x00); /* Mode change period (no restriction) */
+ put_byte(pb, 0x01); /* Frames per sample */
+ return 0x11;
+}
+
+static int mov_write_enda_tag(ByteIOContext *pb)
+{
+ put_be32(pb, 10);
+ put_tag(pb, "enda");
+ put_be16(pb, 1); /* little endian */
+ return 10;
+}
+
+static unsigned int descrLength(unsigned int len)
+{
+ int i;
+ for(i=1; len>>(7*i); i++);
+ return len + 1 + i;
+}
+
+static void putDescr(ByteIOContext *pb, int tag, unsigned int size)
+{
+ int i= descrLength(size) - size - 2;
+ put_byte(pb, tag);
+ for(; i>0; i--)
+ put_byte(pb, (size>>(7*i)) | 0x80);
+ put_byte(pb, size & 0x7F);
+}
+
+static int mov_write_esds_tag(ByteIOContext *pb, MOVTrack* track) // Basic
+{
+ offset_t pos = url_ftell(pb);
+ int decoderSpecificInfoLen = track->vosLen ? descrLength(track->vosLen):0;
+
+ put_be32(pb, 0); // size
+ put_tag(pb, "esds");
+ put_be32(pb, 0); // Version
+
+ // ES descriptor
+ putDescr(pb, 0x03, 3 + descrLength(13 + decoderSpecificInfoLen) +
+ descrLength(1));
+ put_be16(pb, track->trackID);
+ put_byte(pb, 0x00); // flags (= no flags)
+
+ // DecoderConfig descriptor
+ putDescr(pb, 0x04, 13 + decoderSpecificInfoLen);
+
+ // Object type indication
+ put_byte(pb, codec_get_tag(ff_mp4_obj_type, track->enc->codec_id));
+
+ // 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)
+ put_byte(pb, 0x15); // flags (= Audiostream)
+ else
+ put_byte(pb, 0x11); // flags (= Visualstream)
+
+ put_byte(pb, track->enc->rc_buffer_size>>(3+16)); // Buffersize DB (24 bits)
+ put_be16(pb, (track->enc->rc_buffer_size>>3)&0xFFFF); // Buffersize DB
+
+ put_be32(pb, FFMAX(track->enc->bit_rate, track->enc->rc_max_rate)); // maxbitrate (FIXME should be max rate in any 1 sec window)
+ if(track->enc->rc_max_rate != track->enc->rc_min_rate || track->enc->rc_min_rate==0)
+ put_be32(pb, 0); // vbr
+ else
+ put_be32(pb, track->enc->rc_max_rate); // avg bitrate
+
+ if (track->vosLen)
+ {
+ // DecoderSpecific info descriptor
+ putDescr(pb, 0x05, track->vosLen);
+ put_buffer(pb, track->vosData, track->vosLen);
+ }
+
+
+ // SL descriptor
+ putDescr(pb, 0x06, 1);
+ put_byte(pb, 0x02);
+ return updateSize (pb, pos);
+}
+
+static int mov_write_wave_tag(ByteIOContext *pb, MOVTrack* track)
+{
+ offset_t pos = url_ftell(pb);
+
+ put_be32(pb, 0); /* size */
+ put_tag(pb, "wave");
+
+ put_be32(pb, 12); /* size */
+ put_tag(pb, "frma");
+ put_le32(pb, track->tag);
+
+ if (track->enc->codec_id == CODEC_ID_AAC) {
+ /* useless atom needed by mplayer, ipod, not needed by quicktime */
+ put_be32(pb, 12); /* size */
+ 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) {
+ mov_write_enda_tag(pb);
+ } else if (track->enc->codec_id == CODEC_ID_AMR_NB) {
+ mov_write_amr_tag(pb, track);
+ }
+
+ put_be32(pb, 8); /* size */
+ put_be32(pb, 0); /* null tag */
+
+ return updateSize (pb, pos);
+}
+
+static int mov_write_audio_tag(ByteIOContext *pb, MOVTrack* track)
+{
+ offset_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);
+
+ put_be32(pb, 0); /* size */
+ put_le32(pb, track->tag); // store it byteswapped
+ put_be32(pb, 0); /* Reserved */
+ put_be16(pb, 0); /* Reserved */
+ put_be16(pb, 1); /* Data-reference index, XXX == 1 */
+
+ /* SoundDescription */
+ put_be16(pb, version); /* Version */
+ 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);
+ 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 */
+
+ if(version == 1) { /* SoundDescription V1 extended info */
+ put_be32(pb, track->enc->frame_size); /* Samples per packet */
+ put_be32(pb, track->sampleSize / track->enc->channels); /* Bytes per packet */
+ put_be32(pb, track->sampleSize); /* Bytes per frame */
+ put_be32(pb, 2); /* Bytes per sample */
+ }
+
+ if(track->mode == MODE_MOV &&
+ (track->enc->codec_id == CODEC_ID_AAC ||
+ track->enc->codec_id == CODEC_ID_AMR_NB ||
+ track->enc->codec_id == CODEC_ID_PCM_S24LE ||
+ track->enc->codec_id == CODEC_ID_PCM_S32LE))
+ mov_write_wave_tag(pb, track);
+ else if(track->enc->codec_id == CODEC_ID_AAC)
+ mov_write_esds_tag(pb, track);
+ else if(track->enc->codec_id == CODEC_ID_AMR_NB)
+ mov_write_amr_tag(pb, track);
+
+ return updateSize (pb, pos);
+}
+
+static int mov_write_d263_tag(ByteIOContext *pb)
+{
+ put_be32(pb, 0xf); /* size */
+ put_tag(pb, "d263");
+ put_tag(pb, "FFMP");
+ put_byte(pb, 0); /* decoder version */
+ /* FIXME use AVCodecContext level/profile, when encoder will set values */
+ put_byte(pb, 0xa); /* level */
+ put_byte(pb, 0); /* profile */
+ return 0xf;
+}
+
+/* TODO: No idea about these values */
+static int mov_write_svq3_tag(ByteIOContext *pb)
+{
+ put_be32(pb, 0x15);
+ put_tag(pb, "SMI ");
+ put_tag(pb, "SEQH");
+ put_be32(pb, 0x5);
+ put_be32(pb, 0xe2c0211d);
+ put_be32(pb, 0xc0000000);
+ put_byte(pb, 0);
+ return 0x15;
+}
+
+static uint8_t *avc_find_startcode( uint8_t *p, uint8_t *end )
+{
+ uint8_t *a = p + 4 - ((int)p & 3);
+
+ for( end -= 3; p < a && p < end; p++ ) {
+ if( p[0] == 0 && p[1] == 0 && p[2] == 1 )
+ return p;
+ }
+
+ for( end -= 3; p < end; p += 4 ) {
+ uint32_t x = *(uint32_t*)p;
+// if( (x - 0x01000100) & (~x) & 0x80008000 ) // little endian
+// if( (x - 0x00010001) & (~x) & 0x00800080 ) // big endian
+ 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[3] == 0 ) {
+ if( p[2] == 0 && p[4] == 1 )
+ return p+1;
+ if( p[4] == 0 && p[5] == 1 )
+ return p+2;
+ }
+ }
+ }
+
+ for( end += 3; p < end; p++ ) {
+ if( p[0] == 0 && p[1] == 0 && p[2] == 1 )
+ return p;
+ }
+
+ return end + 3;
+}
+
+static void avc_parse_nal_units(uint8_t **buf, int *size)
+{
+ ByteIOContext pb;
+ uint8_t *p = *buf;
+ uint8_t *end = p + *size;
+ uint8_t *nal_start, *nal_end;
+
+ url_open_dyn_buf(&pb);
+ nal_start = avc_find_startcode(p, end);
+ while (nal_start < end) {
+ while(!*(nal_start++));
+ nal_end = avc_find_startcode(nal_start, end);
+ put_be32(&pb, nal_end - nal_start);
+ put_buffer(&pb, nal_start, nal_end - nal_start);
+ nal_start = nal_end;
+ }
+ av_freep(buf);
+ *size = url_close_dyn_buf(&pb, buf);
+}
+
+static int mov_write_avcc_tag(ByteIOContext *pb, MOVTrack *track)
+{
+ offset_t pos = url_ftell(pb);
+
+ put_be32(pb, 0);
+ put_tag(pb, "avcC");
+ if (track->vosLen > 6) {
+ /* check for h264 start code */
+ if (AV_RB32(track->vosData) == 0x00000001) {
+ uint8_t *buf, *end;
+ uint32_t sps_size=0, pps_size=0;
+ uint8_t *sps=0, *pps=0;
+
+ avc_parse_nal_units(&track->vosData, &track->vosLen);
+ buf = track->vosData;
+ end = track->vosData + track->vosLen;
+
+ /* look for sps and pps */
+ while (buf < end) {
+ unsigned int size;
+ uint8_t nal_type;
+ size = AV_RB32(buf);
+ nal_type = buf[4] & 0x1f;
+ if (nal_type == 7) { /* SPS */
+ sps = buf + 4;
+ sps_size = size;
+ } else if (nal_type == 8) { /* PPS */
+ pps = buf + 4;
+ pps_size = size;
+ }
+ buf += size + 4;
+ }
+ assert(sps);
+ assert(pps);
+
+ put_byte(pb, 1); /* version */
+ put_byte(pb, sps[1]); /* profile */
+ put_byte(pb, sps[2]); /* profile compat */
+ put_byte(pb, sps[3]); /* level */
+ put_byte(pb, 0xff); /* 6 bits reserved (111111) + 2 bits nal size length - 1 (11) */
+ put_byte(pb, 0xe1); /* 3 bits reserved (111) + 5 bits number of sps (00001) */
+
+ put_be16(pb, sps_size);
+ put_buffer(pb, sps, sps_size);
+ put_byte(pb, 1); /* number of pps */
+ put_be16(pb, pps_size);
+ put_buffer(pb, pps, pps_size);
+ } else {
+ put_buffer(pb, track->vosData, track->vosLen);
+ }
+ }
+ return updateSize(pb, pos);
+}
+
+static int mov_find_video_codec_tag(AVFormatContext *s, MOVTrack *track)
+{
+ int tag = track->enc->codec_tag;
+ if (!tag) {
+ if (track->enc->codec_id == CODEC_ID_DVVIDEO) {
+ if (track->enc->height == 480) { /* NTSC */
+ if (track->enc->pix_fmt == PIX_FMT_YUV422P)
+ tag = MKTAG('d', 'v', '5', 'n');
+ else
+ tag = MKTAG('d', 'v', 'c', ' ');
+ } else { /* assume PAL */
+ if (track->enc->pix_fmt == PIX_FMT_YUV422P)
+ tag = MKTAG('d', 'v', '5', 'p');
+ else if (track->enc->pix_fmt == PIX_FMT_YUV420P)
+ tag = MKTAG('d', 'v', 'c', 'p');
+ else
+ tag = MKTAG('d', 'v', 'p', 'p');
+ }
+ } else if (track->enc->codec_id == CODEC_ID_H263) {
+ if (track->mode == MODE_MOV)
+ tag = MKTAG('h', '2', '6', '3');
+ else
+ tag = MKTAG('s', '2', '6', '3');
+ } else {
+ tag = codec_get_tag(codec_movvideo_tags, track->enc->codec_id);
+ }
+ }
+ // if no mac fcc found, try with Microsoft tags
+ if (!tag) {
+ tag = codec_get_tag(codec_bmp_tags, track->enc->codec_id);
+ if (tag) {
+ av_log(s, AV_LOG_INFO, "Warning, using MS style video codec tag, the file may be unplayable!\n");
+ }
+ }
+ assert(tag);
+ return tag;
+}
+
+static int mov_find_audio_codec_tag(AVFormatContext *s, MOVTrack *track)
+{
+ int tag = track->enc->codec_tag;
+ if (!tag) {
+ tag = codec_get_tag(codec_movaudio_tags, track->enc->codec_id);
+ }
+ // if no mac fcc found, try with Microsoft tags
+ if (!tag) {
+ int ms_tag = codec_get_tag(codec_wav_tags, track->enc->codec_id);
+ if (ms_tag) {
+ tag = MKTAG('m', 's', ((ms_tag >> 8) & 0xff), (ms_tag & 0xff));
+ av_log(s, AV_LOG_INFO, "Warning, using MS style audio codec tag, the file may be unplayable!\n");
+ }
+ }
+ assert(tag);
+ return tag;
+}
+
+static int mov_write_video_tag(ByteIOContext *pb, MOVTrack* track)
+{
+ offset_t pos = url_ftell(pb);
+ char compressor_name[32];
+
+ put_be32(pb, 0); /* size */
+ put_le32(pb, track->tag); // store it byteswapped
+ put_be32(pb, 0); /* Reserved */
+ put_be16(pb, 0); /* Reserved */
+ put_be16(pb, 1); /* Data-reference index */
+
+ put_be16(pb, 0); /* Codec stream version */
+ put_be16(pb, 0); /* Codec stream revision (=0) */
+ if (track->mode == MODE_MOV) {
+ put_tag(pb, "FFMP"); /* Vendor */
+ if(track->enc->codec_id == CODEC_ID_RAWVIDEO) {
+ put_be32(pb, 0); /* Temporal Quality */
+ put_be32(pb, 0x400); /* Spatial Quality = lossless*/
+ } else {
+ put_be32(pb, 0x200); /* Temporal Quality = normal */
+ put_be32(pb, 0x200); /* Spatial Quality = normal */
+ }
+ } else {
+ put_be32(pb, 0); /* Reserved */
+ put_be32(pb, 0); /* Reserved */
+ put_be32(pb, 0); /* Reserved */
+ }
+ put_be16(pb, track->enc->width); /* Video width */
+ put_be16(pb, track->enc->height); /* Video height */
+ put_be32(pb, 0x00480000); /* Horizontal resolution 72dpi */
+ put_be32(pb, 0x00480000); /* Vertical resolution 72dpi */
+ put_be32(pb, 0); /* Data size (= 0) */
+ put_be16(pb, 1); /* Frame count (= 1) */
+
+ memset(compressor_name,0,32);
+ /* FIXME not sure, ISO 14496-1 draft where it shall be set to 0 */
+ if (track->mode == MODE_MOV && track->enc->codec && track->enc->codec->name)
+ strncpy(compressor_name,track->enc->codec->name,31);
+ put_byte(pb, strlen(compressor_name));
+ put_buffer(pb, compressor_name, 31);
+
+ put_be16(pb, 0x18); /* Reserved */
+ put_be16(pb, 0xffff); /* Reserved */
+ if(track->enc->codec_id == CODEC_ID_MPEG4)
+ mov_write_esds_tag(pb, track);
+ else if(track->enc->codec_id == CODEC_ID_H263)
+ mov_write_d263_tag(pb);
+ else if(track->enc->codec_id == CODEC_ID_SVQ3)
+ mov_write_svq3_tag(pb);
+ else if(track->enc->codec_id == CODEC_ID_H264)
+ mov_write_avcc_tag(pb, track);
+
+ return updateSize (pb, pos);
+}
+
+static int mov_write_stsd_tag(ByteIOContext *pb, MOVTrack* track)
+{
+ offset_t pos = url_ftell(pb);
+ put_be32(pb, 0); /* size */
+ put_tag(pb, "stsd");
+ put_be32(pb, 0); /* version & flags */
+ put_be32(pb, 1); /* entry count */
+ if (track->enc->codec_type == CODEC_TYPE_VIDEO)
+ mov_write_video_tag(pb, track);
+ else if (track->enc->codec_type == CODEC_TYPE_AUDIO)
+ mov_write_audio_tag(pb, track);
+ return updateSize(pb, pos);
+}
+
+static int mov_write_ctts_tag(ByteIOContext *pb, MOVTrack* track)
+{
+ Time2Sample *ctts_entries;
+ uint32_t entries = 0;
+ uint32_t atom_size;
+ int i;
+
+ ctts_entries = av_malloc((track->entry + 1) * sizeof(*ctts_entries)); /* worst case */
+ ctts_entries[0].count = 1;
+ ctts_entries[0].duration = track->cluster[0].cts;
+ for (i=1; i<track->entry; i++) {
+ if (track->cluster[i].cts == ctts_entries[entries].duration) {
+ ctts_entries[entries].count++; /* compress */
+ } else {
+ entries++;
+ ctts_entries[entries].duration = track->cluster[i].cts;
+ ctts_entries[entries].count = 1;
+ }
+ }
+ entries++; /* last one */
+ atom_size = 16 + (entries * 8);
+ put_be32(pb, atom_size); /* size */
+ put_tag(pb, "ctts");
+ put_be32(pb, 0); /* version & flags */
+ put_be32(pb, entries); /* entry count */
+ for (i=0; i<entries; i++) {
+ put_be32(pb, ctts_entries[i].count);
+ put_be32(pb, ctts_entries[i].duration);
+ }
+ av_free(ctts_entries);
+ return atom_size;
+}
+
+/* Time to sample atom */
+static int mov_write_stts_tag(ByteIOContext *pb, MOVTrack* track)
+{
+ Time2Sample *stts_entries;
+ uint32_t entries = -1;
+ uint32_t atom_size;
+ int i;
+
+ if (track->enc->codec_type == CODEC_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;
+ entries = 1;
+ } else {
+ stts_entries = av_malloc(track->entry * sizeof(*stts_entries)); /* worst case */
+ for (i=0; i<track->entry; i++) {
+ int64_t duration = i + 1 == track->entry ?
+ track->trackDuration - track->cluster[i].dts + track->cluster[0].dts : /* readjusting */
+ track->cluster[i+1].dts - track->cluster[i].dts;
+ if (i && duration == stts_entries[entries].duration) {
+ stts_entries[entries].count++; /* compress */
+ } else {
+ entries++;
+ stts_entries[entries].duration = duration;
+ stts_entries[entries].count = 1;
+ }
+ }
+ entries++; /* last one */
+ }
+ atom_size = 16 + (entries * 8);
+ put_be32(pb, atom_size); /* size */
+ put_tag(pb, "stts");
+ put_be32(pb, 0); /* version & flags */
+ put_be32(pb, entries); /* entry count */
+ for (i=0; i<entries; i++) {
+ put_be32(pb, stts_entries[i].count);
+ put_be32(pb, stts_entries[i].duration);
+ }
+ av_free(stts_entries);
+ return atom_size;
+}
+
+static int mov_write_dref_tag(ByteIOContext *pb)
+{
+ put_be32(pb, 28); /* size */
+ put_tag(pb, "dref");
+ put_be32(pb, 0); /* version & flags */
+ put_be32(pb, 1); /* entry count */
+
+ put_be32(pb, 0xc); /* size */
+ put_tag(pb, "url ");
+ put_be32(pb, 1); /* version & flags */
+
+ return 28;
+}
+
+static int mov_write_stbl_tag(ByteIOContext *pb, MOVTrack* track)
+{
+ offset_t pos = url_ftell(pb);
+ put_be32(pb, 0); /* size */
+ put_tag(pb, "stbl");
+ mov_write_stsd_tag(pb, track);
+ mov_write_stts_tag(pb, track);
+ if (track->enc->codec_type == CODEC_TYPE_VIDEO &&
+ track->hasKeyframes < track->entry)
+ mov_write_stss_tag(pb, track);
+ if (track->enc->codec_type == CODEC_TYPE_VIDEO &&
+ track->hasBframes)
+ mov_write_ctts_tag(pb, track);
+ mov_write_stsc_tag(pb, track);
+ mov_write_stsz_tag(pb, track);
+ mov_write_stco_tag(pb, track);
+ return updateSize(pb, pos);
+}
+
+static int mov_write_dinf_tag(ByteIOContext *pb)
+{
+ offset_t pos = url_ftell(pb);
+ put_be32(pb, 0); /* size */
+ put_tag(pb, "dinf");
+ mov_write_dref_tag(pb);
+ return updateSize(pb, pos);
+}
+
+static int mov_write_smhd_tag(ByteIOContext *pb)
+{
+ put_be32(pb, 16); /* size */
+ put_tag(pb, "smhd");
+ put_be32(pb, 0); /* version & flags */
+ put_be16(pb, 0); /* reserved (balance, normally = 0) */
+ put_be16(pb, 0); /* reserved */
+ return 16;
+}
+
+static int mov_write_vmhd_tag(ByteIOContext *pb)
+{
+ put_be32(pb, 0x14); /* size (always 0x14) */
+ put_tag(pb, "vmhd");
+ put_be32(pb, 0x01); /* version & flags */
+ put_be64(pb, 0); /* reserved (graphics mode = copy) */
+ return 0x14;
+}
+
+static int mov_write_hdlr_tag(ByteIOContext *pb, MOVTrack* track)
+{
+ const char *descr, *hdlr, *hdlr_type;
+ offset_t pos = url_ftell(pb);
+
+ if (!track) { /* no media --> data handler */
+ hdlr = "dhlr";
+ hdlr_type = "url ";
+ descr = "DataHandler";
+ } else {
+ hdlr = (track->mode == MODE_MOV) ? "mhlr" : "\0\0\0\0";
+ if (track->enc->codec_type == CODEC_TYPE_VIDEO) {
+ hdlr_type = "vide";
+ descr = "VideoHandler";
+ } else {
+ hdlr_type = "soun";
+ descr = "SoundHandler";
+ }
+ }
+
+ put_be32(pb, 0); /* size */
+ put_tag(pb, "hdlr");
+ put_be32(pb, 0); /* Version & flags */
+ put_buffer(pb, hdlr, 4); /* handler */
+ put_tag(pb, hdlr_type); /* handler type */
+ put_be32(pb ,0); /* reserved */
+ put_be32(pb ,0); /* reserved */
+ put_be32(pb ,0); /* reserved */
+ put_byte(pb, strlen(descr)); /* string counter */
+ put_buffer(pb, descr, strlen(descr)); /* handler description */
+ return updateSize(pb, pos);
+}
+
+static int mov_write_minf_tag(ByteIOContext *pb, MOVTrack* track)
+{
+ offset_t pos = url_ftell(pb);
+ put_be32(pb, 0); /* size */
+ put_tag(pb, "minf");
+ if(track->enc->codec_type == CODEC_TYPE_VIDEO)
+ mov_write_vmhd_tag(pb);
+ else
+ mov_write_smhd_tag(pb);
+ if (track->mode == MODE_MOV) /* FIXME: Why do it for MODE_MOV only ? */
+ mov_write_hdlr_tag(pb, NULL);
+ mov_write_dinf_tag(pb);
+ mov_write_stbl_tag(pb, track);
+ return updateSize(pb, pos);
+}
+
+static int mov_write_mdhd_tag(ByteIOContext *pb, MOVTrack* track)
+{
+ int version = track->trackDuration < INT32_MAX ? 0 : 1;
+
+ (version == 1) ? put_be32(pb, 44) : put_be32(pb, 32); /* size */
+ put_tag(pb, "mdhd");
+ put_byte(pb, version);
+ put_be24(pb, 0); /* flags */
+ if (version == 1) {
+ put_be64(pb, track->time);
+ put_be64(pb, track->time);
+ } else {
+ put_be32(pb, track->time); /* creation time */
+ put_be32(pb, track->time); /* modification time */
+ }
+ put_be32(pb, track->timescale); /* time scale (sample rate for audio) */
+ (version == 1) ? put_be64(pb, track->trackDuration) : put_be32(pb, track->trackDuration); /* duration */
+ put_be16(pb, track->language); /* language */
+ put_be16(pb, 0); /* reserved (quality) */
+ return 32;
+}
+
+static int mov_write_mdia_tag(ByteIOContext *pb, MOVTrack* track)
+{
+ offset_t pos = url_ftell(pb);
+ put_be32(pb, 0); /* size */
+ put_tag(pb, "mdia");
+ mov_write_mdhd_tag(pb, track);
+ mov_write_hdlr_tag(pb, track);
+ mov_write_minf_tag(pb, track);
+ return updateSize(pb, pos);
+}
+
+static int mov_write_tkhd_tag(ByteIOContext *pb, MOVTrack* track)
+{
+ int64_t duration = av_rescale_rnd(track->trackDuration, globalTimescale, track->timescale, AV_ROUND_UP);
+ int version = duration < INT32_MAX ? 0 : 1;
+
+ (version == 1) ? put_be32(pb, 104) : put_be32(pb, 92); /* size */
+ put_tag(pb, "tkhd");
+ put_byte(pb, version);
+ put_be24(pb, 0xf); /* flags (track enabled) */
+ if (version == 1) {
+ put_be64(pb, track->time);
+ put_be64(pb, track->time);
+ } else {
+ put_be32(pb, track->time); /* creation time */
+ put_be32(pb, track->time); /* modification time */
+ }
+ put_be32(pb, track->trackID); /* track-id */
+ put_be32(pb, 0); /* reserved */
+ (version == 1) ? put_be64(pb, duration) : put_be32(pb, duration);
+
+ put_be32(pb, 0); /* reserved */
+ 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)
+ put_be16(pb, 0x0100);
+ else
+ put_be16(pb, 0);
+ put_be16(pb, 0); /* reserved */
+
+ /* Matrix structure */
+ put_be32(pb, 0x00010000); /* reserved */
+ put_be32(pb, 0x0); /* reserved */
+ put_be32(pb, 0x0); /* reserved */
+ put_be32(pb, 0x0); /* reserved */
+ put_be32(pb, 0x00010000); /* reserved */
+ put_be32(pb, 0x0); /* reserved */
+ put_be32(pb, 0x0); /* reserved */
+ put_be32(pb, 0x0); /* reserved */
+ put_be32(pb, 0x40000000); /* reserved */
+
+ /* Track width and height, for visual only */
+ if(track->enc->codec_type == CODEC_TYPE_VIDEO) {
+ double sample_aspect_ratio = av_q2d(track->enc->sample_aspect_ratio);
+ if( !sample_aspect_ratio ) sample_aspect_ratio = 1;
+ put_be32(pb, sample_aspect_ratio * track->enc->width*0x10000);
+ put_be32(pb, track->enc->height*0x10000);
+ }
+ else {
+ put_be32(pb, 0);
+ put_be32(pb, 0);
+ }
+ return 0x5c;
+}
+
+// This box seems important for the psp playback ... without it the movie seems to hang
+static int mov_write_edts_tag(ByteIOContext *pb, MOVTrack *track)
+{
+ put_be32(pb, 0x24); /* size */
+ put_tag(pb, "edts");
+ put_be32(pb, 0x1c); /* size */
+ put_tag(pb, "elst");
+ 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 */
+
+ put_be32(pb, track->cluster[0].cts); /* first pts is cts since dts is 0 */
+ put_be32(pb, 0x00010000);
+ return 0x24;
+}
+
+// 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)
+{
+ put_be32(pb, 0x34); /* size ... reports as 28 in mp4box! */
+ put_tag(pb, "uuid");
+ put_tag(pb, "USMT");
+ put_be32(pb, 0x21d24fce);
+ put_be32(pb, 0xbb88695c);
+ put_be32(pb, 0xfac9c740);
+ put_be32(pb, 0x1c); // another size here!
+ put_tag(pb, "MTDT");
+ put_be32(pb, 0x00010012);
+ put_be32(pb, 0x0a);
+ put_be32(pb, 0x55c40000);
+ put_be32(pb, 0x1);
+ put_be32(pb, 0x0);
+ return 0x34;
+}
+
+static int mov_write_trak_tag(ByteIOContext *pb, MOVTrack* track)
+{
+ offset_t pos = url_ftell(pb);
+ put_be32(pb, 0); /* size */
+ put_tag(pb, "trak");
+ mov_write_tkhd_tag(pb, track);
+ if (track->mode == MODE_PSP || track->hasBframes)
+ mov_write_edts_tag(pb, track); // PSP Movies require edts box
+ mov_write_mdia_tag(pb, track);
+ if (track->mode == MODE_PSP)
+ mov_write_uuid_tag_psp(pb,track); // PSP Movies require this uuid box
+ return updateSize(pb, pos);
+}
+
+#if 0
+/* TODO: Not sorted out, but not necessary either */
+static int mov_write_iods_tag(ByteIOContext *pb, MOVContext *mov)
+{
+ put_be32(pb, 0x15); /* size */
+ put_tag(pb, "iods");
+ put_be32(pb, 0); /* version & flags */
+ put_be16(pb, 0x1007);
+ put_byte(pb, 0);
+ put_be16(pb, 0x4fff);
+ put_be16(pb, 0xfffe);
+ put_be16(pb, 0x01ff);
+ return 0x15;
+}
+#endif
+
+static int mov_write_mvhd_tag(ByteIOContext *pb, MOVContext *mov)
+{
+ int maxTrackID = 1, i;
+ int64_t maxTrackLenTemp, maxTrackLen = 0;
+ int version;
+
+ for (i=0; i<mov->nb_streams; i++) {
+ if(mov->tracks[i].entry > 0) {
+ maxTrackLenTemp = av_rescale_rnd(mov->tracks[i].trackDuration, globalTimescale, mov->tracks[i].timescale, AV_ROUND_UP);
+ if(maxTrackLen < maxTrackLenTemp)
+ maxTrackLen = maxTrackLenTemp;
+ if(maxTrackID < mov->tracks[i].trackID)
+ maxTrackID = mov->tracks[i].trackID;
+ }
+ }
+
+ version = maxTrackLen < UINT32_MAX ? 0 : 1;
+ (version == 1) ? put_be32(pb, 120) : put_be32(pb, 108); /* size */
+ put_tag(pb, "mvhd");
+ put_byte(pb, version);
+ put_be24(pb, 0); /* flags */
+ if (version == 1) {
+ put_be64(pb, mov->time);
+ put_be64(pb, mov->time);
+ } else {
+ put_be32(pb, mov->time); /* creation time */
+ put_be32(pb, mov->time); /* modification time */
+ }
+ put_be32(pb, mov->timescale); /* 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 */
+ put_be16(pb, 0x0100); /* reserved (preferred volume) 1.0 = normal */
+ put_be16(pb, 0); /* reserved */
+ put_be32(pb, 0); /* reserved */
+ put_be32(pb, 0); /* reserved */
+
+ /* Matrix structure */
+ put_be32(pb, 0x00010000); /* reserved */
+ put_be32(pb, 0x0); /* reserved */
+ put_be32(pb, 0x0); /* reserved */
+ put_be32(pb, 0x0); /* reserved */
+ put_be32(pb, 0x00010000); /* reserved */
+ put_be32(pb, 0x0); /* reserved */
+ put_be32(pb, 0x0); /* reserved */
+ put_be32(pb, 0x0); /* reserved */
+ put_be32(pb, 0x40000000); /* reserved */
+
+ put_be32(pb, 0); /* reserved (preview time) */
+ put_be32(pb, 0); /* reserved (preview duration) */
+ put_be32(pb, 0); /* reserved (poster time) */
+ put_be32(pb, 0); /* reserved (selection time) */
+ put_be32(pb, 0); /* reserved (selection duration) */
+ put_be32(pb, 0); /* reserved (current time) */
+ put_be32(pb, maxTrackID+1); /* Next track id */
+ return 0x6c;
+}
+
+static int mov_write_itunes_hdlr_tag(ByteIOContext *pb, MOVContext* mov,
+ AVFormatContext *s)
+{
+ offset_t pos = url_ftell(pb);
+ put_be32(pb, 0); /* size */
+ put_tag(pb, "hdlr");
+ put_be32(pb, 0);
+ put_be32(pb, 0);
+ put_tag(pb, "mdir");
+ put_tag(pb, "appl");
+ put_be32(pb, 0);
+ put_be32(pb, 0);
+ put_be16(pb, 0);
+ return updateSize(pb, pos);
+}
+
+/* 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 long_style)
+{
+ if(long_style){
+ offset_t pos = url_ftell(pb);
+ put_be32(pb, 0); /* size */
+ put_tag(pb, "data");
+ put_be32(pb, 1);
+ put_be32(pb, 0);
+ put_buffer(pb, data, strlen(data));
+ return updateSize(pb, pos);
+ }else{
+ put_be16(pb, strlen(data)); /* string length */
+ put_be16(pb, 0);
+ put_buffer(pb, data, strlen(data));
+ return strlen(data) + 4;
+ }
+}
+
+static int mov_write_string_tag(ByteIOContext *pb, const char *name, const char *value, int long_style){
+ int size = 0;
+ if ( value && value[0] ) {
+ offset_t pos = url_ftell(pb);
+ put_be32(pb, 0); /* size */
+ put_tag(pb, name);
+ mov_write_string_data_tag(pb, value, long_style);
+ size= updateSize(pb, pos);
+ }
+ return size;
+}
+
+/* iTunes year */
+static int mov_write_day_tag(ByteIOContext *pb, int year, int long_style)
+{
+ if(year){
+ char year_str[5];
+ snprintf(year_str, sizeof(year_str), "%04d", year);
+ return mov_write_string_tag(pb, "\251day", year_str, long_style);
+ }else
+ return 0;
+}
+
+/* iTunes track number */
+static int mov_write_trkn_tag(ByteIOContext *pb, MOVContext* mov,
+ AVFormatContext *s)
+{
+ int size = 0;
+ if ( s->track ) {
+ offset_t pos = url_ftell(pb);
+ put_be32(pb, 0); /* size */
+ put_tag(pb, "trkn");
+ {
+ offset_t pos = url_ftell(pb);
+ put_be32(pb, 0); /* size */
+ put_tag(pb, "data");
+ put_be32(pb, 0); // 8 bytes empty
+ put_be32(pb, 0);
+ put_be16(pb, 0); // empty
+ put_be16(pb, s->track); // track number
+ put_be16(pb, 0); // total track number
+ put_be16(pb, 0); // empty
+ updateSize(pb, pos);
+ }
+ size = updateSize(pb, pos);
+ }
+ return size;
+}
+
+/* iTunes meta data list */
+static int mov_write_ilst_tag(ByteIOContext *pb, MOVContext* mov,
+ AVFormatContext *s)
+{
+ offset_t pos = url_ftell(pb);
+ put_be32(pb, 0); /* size */
+ put_tag(pb, "ilst");
+ mov_write_string_tag(pb, "\251nam", s->title , 1);
+ mov_write_string_tag(pb, "\251ART", s->author , 1);
+ mov_write_string_tag(pb, "\251wrt", s->author , 1);
+ mov_write_string_tag(pb, "\251alb", s->album , 1);
+ mov_write_day_tag(pb, s->year ,1);
+ if(mov->tracks[0].enc && !(mov->tracks[0].enc->flags & CODEC_FLAG_BITEXACT))
+ mov_write_string_tag(pb, "\251too", LIBAVFORMAT_IDENT, 1);
+ mov_write_string_tag(pb, "\251cmt", s->comment , 1);
+ mov_write_string_tag(pb, "\251gen", s->genre , 1);
+ mov_write_trkn_tag(pb, mov, s);
+ return updateSize(pb, pos);
+}
+
+/* iTunes meta data tag */
+static int mov_write_meta_tag(ByteIOContext *pb, MOVContext* mov,
+ AVFormatContext *s)
+{
+ int size = 0;
+
+ // only save meta tag if required
+ if ( s->title[0] || s->author[0] || s->album[0] || s->year ||
+ s->comment[0] || s->genre[0] || s->track ) {
+ offset_t pos = url_ftell(pb);
+ put_be32(pb, 0); /* size */
+ put_tag(pb, "meta");
+ put_be32(pb, 0);
+ mov_write_itunes_hdlr_tag(pb, mov, s);
+ mov_write_ilst_tag(pb, mov, s);
+ size = updateSize(pb, pos);
+ }
+ return size;
+}
+
+static int mov_write_udta_tag(ByteIOContext *pb, MOVContext* mov,
+ AVFormatContext *s)
+{
+ offset_t pos = url_ftell(pb);
+ int i;
+
+ put_be32(pb, 0); /* size */
+ put_tag(pb, "udta");
+
+ /* iTunes meta data */
+ mov_write_meta_tag(pb, mov, s);
+
+ if(mov->mode == MODE_MOV){ // the title field breaks gtkpod with mp4 and my suspicion is that stuff isnt valid in mp4
+ /* Requirements */
+ for (i=0; i<mov->nb_streams; i++) {
+ if(mov->tracks[i].entry <= 0) continue;
+ if (mov->tracks[i].enc->codec_id == CODEC_ID_AAC ||
+ mov->tracks[i].enc->codec_id == CODEC_ID_MPEG4) {
+ mov_write_string_tag(pb, "\251req", "QuickTime 6.0 or greater", 0);
+ break;
+ }
+ }
+
+ mov_write_string_tag(pb, "\251nam", s->title , 0);
+ mov_write_string_tag(pb, "\251aut", s->author , 0);
+ mov_write_string_tag(pb, "\251alb", s->album , 0);
+ mov_write_day_tag(pb, s->year, 0);
+ if(mov->tracks[0].enc && !(mov->tracks[0].enc->flags & CODEC_FLAG_BITEXACT))
+ mov_write_string_tag(pb, "\251enc", LIBAVFORMAT_IDENT, 0);
+ mov_write_string_tag(pb, "\251des", s->comment , 0);
+ mov_write_string_tag(pb, "\251gen", s->genre , 0);
+ }
+
+ return updateSize(pb, pos);
+}
+
+static int utf8len(uint8_t *b){
+ int len=0;
+ int val;
+ while(*b){
+ GET_UTF8(val, *b++, return -1;)
+ len++;
+ }
+ return len;
+}
+
+static int ascii_to_wc (ByteIOContext *pb, uint8_t *b)
+{
+ int val;
+ while(*b){
+ GET_UTF8(val, *b++, return -1;)
+ put_be16(pb, val);
+ }
+ put_be16(pb, 0x00);
+ return 0;
+}
+
+static uint16_t language_code (const char *str)
+{
+ return ((((str[0]-0x60) & 0x1F)<<10) + (((str[1]-0x60) & 0x1F)<<5) + ((str[2]-0x60) & 0x1F));
+}
+
+static int mov_write_uuidusmt_tag (ByteIOContext *pb, AVFormatContext *s)
+{
+ size_t len, size;
+ offset_t pos, curpos;
+
+ size = 0;
+ if (s->title[0]) {
+ pos = url_ftell(pb);
+ put_be32(pb, 0); /* size placeholder*/
+ put_tag(pb, "uuid");
+ put_tag(pb, "USMT");
+ put_be32(pb, 0x21d24fce ); /* 96 bit UUID */
+ put_be32(pb, 0xbb88695c );
+ put_be32(pb, 0xfac9c740 );
+ size += 24;
+
+ put_be32(pb, 0); /* size placeholder*/
+ put_tag(pb, "MTDT");
+ put_be16(pb, 4);
+ size += 10;
+
+ // ?
+ put_be16(pb, 0x0C); /* size */
+ put_be32(pb, 0x0B); /* type */
+ put_be16(pb, language_code("und")); /* language */
+ put_be16(pb, 0x0); /* ? */
+ put_be16(pb, 0x021C); /* data */
+ size += 12;
+
+ // Encoder
+ len = utf8len(LIBAVCODEC_IDENT)+1;
+ if(len<=0)
+ goto not_utf8;
+ put_be16(pb, len*2+10); /* size */
+ put_be32(pb, 0x04); /* type */
+ put_be16(pb, language_code("eng")); /* language */
+ put_be16(pb, 0x01); /* ? */
+ ascii_to_wc(pb, LIBAVCODEC_IDENT);
+ size += len*2+10;
+
+ // Title
+ len = utf8len(s->title)+1;
+ if(len<=0)
+ goto not_utf8;
+ put_be16(pb, len*2+10); /* size */
+ put_be32(pb, 0x01); /* type */
+ put_be16(pb, language_code("eng")); /* language */
+ put_be16(pb, 0x01); /* ? */
+ ascii_to_wc (pb, s->title);
+ size += len*2+10;
+
+ // Date
+// snprintf(dt,32,"%04d/%02d/%02d %02d:%02d:%02d",t_st->tm_year+1900,t_st->tm_mon+1,t_st->tm_mday,t_st->tm_hour,t_st->tm_min,t_st->tm_sec);
+ len = utf8len("2006/04/01 11:11:11")+1;
+ if(len<=0)
+ goto not_utf8;
+ put_be16(pb, len*2+10); /* size */
+ put_be32(pb, 0x03); /* type */
+ put_be16(pb, language_code("und")); /* language */
+ put_be16(pb, 0x01); /* ? */
+ ascii_to_wc (pb, "2006/04/01 11:11:11");
+ size += len*2+10;
+
+ // size
+ curpos = url_ftell(pb);
+ url_fseek(pb, pos, SEEK_SET);
+ put_be32(pb, size);
+ url_fseek(pb, pos+24, SEEK_SET);
+ put_be32(pb, size-24);
+ url_fseek(pb, curpos, SEEK_SET);
+ }
+
+ return size;
+not_utf8:
+ av_log(s, AV_LOG_ERROR, "not utf8\n");
+ return -1;
+}
+
+static int mov_write_moov_tag(ByteIOContext *pb, MOVContext *mov,
+ AVFormatContext *s)
+{
+ int i;
+ offset_t pos = url_ftell(pb);
+ put_be32(pb, 0); /* size placeholder*/
+ put_tag(pb, "moov");
+ mov->timescale = globalTimescale;
+
+ for (i=0; i<mov->nb_streams; i++) {
+ if(mov->tracks[i].entry <= 0) continue;
+
+ mov->tracks[i].time = mov->time;
+ mov->tracks[i].trackID = i+1;
+ }
+
+ mov_write_mvhd_tag(pb, mov);
+ //mov_write_iods_tag(pb, mov);
+ for (i=0; i<mov->nb_streams; i++) {
+ if(mov->tracks[i].entry > 0) {
+ mov_write_trak_tag(pb, &(mov->tracks[i]));
+ }
+ }
+
+ if (mov->mode == MODE_PSP)
+ mov_write_uuidusmt_tag(pb, s);
+ else
+ mov_write_udta_tag(pb, mov, s);
+
+ return updateSize(pb, pos);
+}
+
+static int mov_write_mdat_tag(ByteIOContext *pb, MOVContext* mov)
+{
+ put_be32(pb, 8); // placeholder for extended size field (64 bit)
+ put_tag(pb, mov->mode == MODE_MOV ? "wide" : "free");
+
+ mov->mdat_pos = url_ftell(pb);
+ put_be32(pb, 0); /* size placeholder*/
+ put_tag(pb, "mdat");
+ return 0;
+}
+
+/* TODO: This needs to be more general */
+static void mov_write_ftyp_tag (ByteIOContext *pb, AVFormatContext *s)
+{
+ MOVContext *mov = s->priv_data;
+
+ put_be32(pb, 0x14 ); /* size */
+ put_tag(pb, "ftyp");
+
+ if ( mov->mode == MODE_3GP )
+ put_tag(pb, "3gp4");
+ else if ( mov->mode == MODE_3G2 )
+ put_tag(pb, "3g2a");
+ else if ( mov->mode == MODE_PSP )
+ put_tag(pb, "MSNV");
+ else if ( mov->mode == MODE_MP4 )
+ put_tag(pb, "isom");
+ else
+ put_tag(pb, "qt ");
+
+ put_be32(pb, 0x200 );
+
+ if ( mov->mode == MODE_3GP )
+ put_tag(pb, "3gp4");
+ else if ( mov->mode == MODE_3G2 )
+ put_tag(pb, "3g2a");
+ else if ( mov->mode == MODE_PSP )
+ put_tag(pb, "MSNV");
+ else if ( mov->mode == MODE_MP4 )
+ put_tag(pb, "mp41");
+ else
+ put_tag(pb, "qt ");
+}
+
+static void mov_write_uuidprof_tag(ByteIOContext *pb, AVFormatContext *s)
+{
+ AVCodecContext *VideoCodec = s->streams[0]->codec;
+ AVCodecContext *AudioCodec = s->streams[1]->codec;
+ int AudioRate = AudioCodec->sample_rate;
+ int FrameRate = ((VideoCodec->time_base.den) * (0x10000))/ (VideoCodec->time_base.num);
+ int audio_kbitrate= AudioCodec->bit_rate / 1000;
+ int video_kbitrate= FFMIN(VideoCodec->bit_rate / 1000, 800 - audio_kbitrate);
+
+ put_be32(pb, 0x94 ); /* size */
+ put_tag(pb, "uuid");
+ put_tag(pb, "PROF");
+
+ put_be32(pb, 0x21d24fce ); /* 96 bit UUID */
+ put_be32(pb, 0xbb88695c );
+ put_be32(pb, 0xfac9c740 );
+
+ put_be32(pb, 0x0 ); /* ? */
+ put_be32(pb, 0x3 ); /* 3 sections ? */
+
+ put_be32(pb, 0x14 ); /* size */
+ put_tag(pb, "FPRF");
+ put_be32(pb, 0x0 ); /* ? */
+ put_be32(pb, 0x0 ); /* ? */
+ put_be32(pb, 0x0 ); /* ? */
+
+ put_be32(pb, 0x2c ); /* size */
+ put_tag(pb, "APRF"); /* audio */
+ put_be32(pb, 0x0 );
+ put_be32(pb, 0x2 ); /* TrackID */
+ put_tag(pb, "mp4a");
+ put_be32(pb, 0x20f );
+ put_be32(pb, 0x0 );
+ put_be32(pb, audio_kbitrate);
+ put_be32(pb, audio_kbitrate);
+ put_be32(pb, AudioRate );
+ put_be32(pb, AudioCodec->channels );
+
+ put_be32(pb, 0x34 ); /* size */
+ put_tag(pb, "VPRF"); /* video */
+ put_be32(pb, 0x0 );
+ put_be32(pb, 0x1 ); /* TrackID */
+ if (VideoCodec->codec_id == CODEC_ID_H264) {
+ put_tag(pb, "avc1");
+ put_be16(pb, 0x014D );
+ put_be16(pb, 0x0015 );
+ } else {
+ put_tag(pb, "mp4v");
+ put_be16(pb, 0x0000 );
+ put_be16(pb, 0x0103 );
+ }
+ put_be32(pb, 0x0 );
+ put_be32(pb, video_kbitrate);
+ put_be32(pb, video_kbitrate);
+ put_be32(pb, FrameRate);
+ put_be32(pb, FrameRate);
+ put_be16(pb, VideoCodec->width);
+ put_be16(pb, VideoCodec->height);
+ put_be32(pb, 0x010001); /* ? */
+}
+
+static int mov_write_header(AVFormatContext *s)
+{
+ ByteIOContext *pb = &s->pb;
+ MOVContext *mov = s->priv_data;
+ int i;
+
+ /* 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_3G2;
+ else if (!strcmp("mov", s->oformat->name)) mov->mode = MODE_MOV;
+ else if (!strcmp("psp", s->oformat->name)) mov->mode = MODE_PSP;
+
+ 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);
+ }
+ }
+
+ for(i=0; i<s->nb_streams; i++){
+ AVStream *st= s->streams[i];
+ MOVTrack *track= &mov->tracks[i];
+
+ track->enc = st->codec;
+ track->language = ff_mov_iso639_to_lang(st->language, mov->mode != MODE_MOV);
+ track->mode = mov->mode;
+ if(st->codec->codec_type == CODEC_TYPE_VIDEO){
+ track->tag = mov_find_video_codec_tag(s, track);
+ track->timescale = st->codec->time_base.den;
+ av_set_pts_info(st, 64, 1, st->codec->time_base.den);
+ }else if(st->codec->codec_type == CODEC_TYPE_AUDIO){
+ track->tag = mov_find_audio_codec_tag(s, track);
+ track->timescale = st->codec->sample_rate;
+ av_set_pts_info(st, 64, 1, st->codec->sample_rate);
+ if(!st->codec->frame_size){
+ av_log(s, AV_LOG_ERROR, "track %d: codec frame size is not set\n", i);
+ return -1;
+ }else if(st->codec->frame_size > 1){ /* assume compressed audio */
+ track->audio_vbr = 1;
+ }else{
+ track->sampleSize = (av_get_bits_per_sample(st->codec->codec_id) >> 3) * st->codec->channels;
+ }
+ }
+ }
+
+ 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;
+}
+
+static int mov_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ MOVContext *mov = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ MOVTrack *trk = &mov->tracks[pkt->stream_index];
+ AVCodecContext *enc = trk->enc;
+ unsigned int samplesInChunk = 0;
+ int size= pkt->size;
+
+ if (url_is_streamed(&s->pb)) return 0; /* Can't handle that */
+ if (!size) return 0; /* Discard 0 sized packets */
+
+ if (enc->codec_id == CODEC_ID_AMR_NB) {
+ /* We must find out how many AMR blocks there are in one packet */
+ static uint16_t packed_size[16] =
+ {13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 0};
+ int len = 0;
+
+ while (len < size && samplesInChunk < 100) {
+ len += packed_size[(pkt->data[len] >> 3) & 0x0F];
+ samplesInChunk++;
+ }
+ if(samplesInChunk > 1){
+ av_log(s, AV_LOG_ERROR, "fatal error, input is not a single packet, inplement a AVParser for it\n");
+ return -1;
+ }
+ } else if (trk->sampleSize)
+ samplesInChunk = size/trk->sampleSize;
+ else
+ samplesInChunk = 1;
+
+ /* copy extradata if it exists */
+ if (trk->vosLen == 0 && enc->extradata_size > 0) {
+ trk->vosLen = enc->extradata_size;
+ trk->vosData = av_malloc(trk->vosLen);
+ memcpy(trk->vosData, enc->extradata, trk->vosLen);
+ }
+
+ if (enc->codec_id == CODEC_ID_H264 && trk->vosLen > 0 && *(uint8_t *)trk->vosData != 1) {
+ /* from x264 or from bytestream h264 */
+ /* nal reformating needed */
+ avc_parse_nal_units(&pkt->data, &pkt->size);
+ assert(pkt->size);
+ size = pkt->size;
+ }
+
+ if (!(trk->entry % MOV_INDEX_CLUSTER_SIZE)) {
+ trk->cluster = av_realloc(trk->cluster, (trk->entry + MOV_INDEX_CLUSTER_SIZE) * sizeof(*trk->cluster));
+ if (!trk->cluster)
+ return -1;
+ }
+
+ trk->cluster[trk->entry].pos = url_ftell(pb);
+ trk->cluster[trk->entry].samplesInChunk = samplesInChunk;
+ trk->cluster[trk->entry].size = size;
+ trk->cluster[trk->entry].entries = samplesInChunk;
+ trk->cluster[trk->entry].dts = pkt->dts;
+ trk->trackDuration = pkt->dts - trk->cluster[0].dts + pkt->duration;
+
+ if(enc->codec_type == CODEC_TYPE_VIDEO) {
+ if (pkt->dts != pkt->pts)
+ trk->hasBframes = 1;
+ trk->cluster[trk->entry].cts = pkt->pts - pkt->dts;
+ trk->cluster[trk->entry].key_frame = !!(pkt->flags & PKT_FLAG_KEY);
+ if(trk->cluster[trk->entry].key_frame)
+ trk->hasKeyframes++;
+ }
+ trk->entry++;
+ trk->sampleCount += samplesInChunk;
+ mov->mdat_size += size;
+
+ put_buffer(pb, pkt->data, size);
+
+ put_flush_packet(pb);
+ return 0;
+}
+
+static int mov_write_trailer(AVFormatContext *s)
+{
+ MOVContext *mov = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ int res = 0;
+ int i;
+
+ offset_t moov_pos = url_ftell(pb);
+
+ /* Write size of mdat tag */
+ if (mov->mdat_size+8 <= UINT32_MAX) {
+ url_fseek(pb, mov->mdat_pos, SEEK_SET);
+ put_be32(pb, mov->mdat_size+8);
+ } else {
+ /* overwrite 'wide' placeholder atom */
+ url_fseek(pb, mov->mdat_pos - 8, SEEK_SET);
+ put_be32(pb, 1); /* special value: real atom size will be 64 bit value after tag field */
+ put_tag(pb, "mdat");
+ put_be64(pb, mov->mdat_size+16);
+ }
+ url_fseek(pb, moov_pos, SEEK_SET);
+
+ mov_write_moov_tag(pb, mov, s);
+
+ for (i=0; i<mov->nb_streams; i++) {
+ av_freep(&mov->tracks[i].cluster);
+
+ if( mov->tracks[i].vosLen ) av_free( mov->tracks[i].vosData );
+
+ }
+
+ put_flush_packet(pb);
+
+ return res;
+}
+
+#ifdef CONFIG_MOV_MUXER
+AVOutputFormat mov_muxer = {
+ "mov",
+ "mov format",
+ NULL,
+ "mov",
+ sizeof(MOVContext),
+ CODEC_ID_AAC,
+ CODEC_ID_MPEG4,
+ mov_write_header,
+ mov_write_packet,
+ mov_write_trailer,
+ .flags = AVFMT_GLOBALHEADER,
+};
+#endif
+#ifdef CONFIG_TGP_MUXER
+AVOutputFormat tgp_muxer = {
+ "3gp",
+ "3gp format",
+ NULL,
+ "3gp",
+ sizeof(MOVContext),
+ CODEC_ID_AMR_NB,
+ CODEC_ID_H263,
+ mov_write_header,
+ mov_write_packet,
+ mov_write_trailer,
+ .flags = AVFMT_GLOBALHEADER,
+};
+#endif
+#ifdef CONFIG_MP4_MUXER
+AVOutputFormat mp4_muxer = {
+ "mp4",
+ "mp4 format",
+ "application/mp4",
+ "mp4,m4a",
+ sizeof(MOVContext),
+ CODEC_ID_AAC,
+ CODEC_ID_MPEG4,
+ mov_write_header,
+ mov_write_packet,
+ mov_write_trailer,
+ .flags = AVFMT_GLOBALHEADER,
+};
+#endif
+#ifdef CONFIG_PSP_MUXER
+AVOutputFormat psp_muxer = {
+ "psp",
+ "psp mp4 format",
+ NULL,
+ "mp4,psp",
+ sizeof(MOVContext),
+ CODEC_ID_AAC,
+ CODEC_ID_MPEG4,
+ mov_write_header,
+ mov_write_packet,
+ mov_write_trailer,
+ .flags = AVFMT_GLOBALHEADER,
+};
+#endif
+#ifdef CONFIG_TG2_MUXER
+AVOutputFormat tg2_muxer = {
+ "3g2",
+ "3gp2 format",
+ NULL,
+ "3g2",
+ sizeof(MOVContext),
+ CODEC_ID_AMR_NB,
+ CODEC_ID_H263,
+ mov_write_header,
+ mov_write_packet,
+ mov_write_trailer,
+ .flags = AVFMT_GLOBALHEADER,
+};
+#endif
diff --git a/contrib/ffmpeg/libavformat/mp3.c b/contrib/ffmpeg/libavformat/mp3.c
new file mode 100644
index 000000000..e86ea14c8
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/mp3.c
@@ -0,0 +1,431 @@
+/*
+ * MP3 muxer and demuxer
+ * Copyright (c) 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 "avformat.h"
+#include "mpegaudio.h"
+
+#define ID3_HEADER_SIZE 10
+#define ID3_TAG_SIZE 128
+
+#define ID3_GENRE_MAX 125
+
+static const char *id3_genre_str[ID3_GENRE_MAX + 1] = {
+ [0] = "Blues",
+ [1] = "Classic Rock",
+ [2] = "Country",
+ [3] = "Dance",
+ [4] = "Disco",
+ [5] = "Funk",
+ [6] = "Grunge",
+ [7] = "Hip-Hop",
+ [8] = "Jazz",
+ [9] = "Metal",
+ [10] = "New Age",
+ [11] = "Oldies",
+ [12] = "Other",
+ [13] = "Pop",
+ [14] = "R&B",
+ [15] = "Rap",
+ [16] = "Reggae",
+ [17] = "Rock",
+ [18] = "Techno",
+ [19] = "Industrial",
+ [20] = "Alternative",
+ [21] = "Ska",
+ [22] = "Death Metal",
+ [23] = "Pranks",
+ [24] = "Soundtrack",
+ [25] = "Euro-Techno",
+ [26] = "Ambient",
+ [27] = "Trip-Hop",
+ [28] = "Vocal",
+ [29] = "Jazz+Funk",
+ [30] = "Fusion",
+ [31] = "Trance",
+ [32] = "Classical",
+ [33] = "Instrumental",
+ [34] = "Acid",
+ [35] = "House",
+ [36] = "Game",
+ [37] = "Sound Clip",
+ [38] = "Gospel",
+ [39] = "Noise",
+ [40] = "AlternRock",
+ [41] = "Bass",
+ [42] = "Soul",
+ [43] = "Punk",
+ [44] = "Space",
+ [45] = "Meditative",
+ [46] = "Instrumental Pop",
+ [47] = "Instrumental Rock",
+ [48] = "Ethnic",
+ [49] = "Gothic",
+ [50] = "Darkwave",
+ [51] = "Techno-Industrial",
+ [52] = "Electronic",
+ [53] = "Pop-Folk",
+ [54] = "Eurodance",
+ [55] = "Dream",
+ [56] = "Southern Rock",
+ [57] = "Comedy",
+ [58] = "Cult",
+ [59] = "Gangsta",
+ [60] = "Top 40",
+ [61] = "Christian Rap",
+ [62] = "Pop/Funk",
+ [63] = "Jungle",
+ [64] = "Native American",
+ [65] = "Cabaret",
+ [66] = "New Wave",
+ [67] = "Psychadelic",
+ [68] = "Rave",
+ [69] = "Showtunes",
+ [70] = "Trailer",
+ [71] = "Lo-Fi",
+ [72] = "Tribal",
+ [73] = "Acid Punk",
+ [74] = "Acid Jazz",
+ [75] = "Polka",
+ [76] = "Retro",
+ [77] = "Musical",
+ [78] = "Rock & Roll",
+ [79] = "Hard Rock",
+ [80] = "Folk",
+ [81] = "Folk-Rock",
+ [82] = "National Folk",
+ [83] = "Swing",
+ [84] = "Fast Fusion",
+ [85] = "Bebob",
+ [86] = "Latin",
+ [87] = "Revival",
+ [88] = "Celtic",
+ [89] = "Bluegrass",
+ [90] = "Avantgarde",
+ [91] = "Gothic Rock",
+ [92] = "Progressive Rock",
+ [93] = "Psychedelic Rock",
+ [94] = "Symphonic Rock",
+ [95] = "Slow Rock",
+ [96] = "Big Band",
+ [97] = "Chorus",
+ [98] = "Easy Listening",
+ [99] = "Acoustic",
+ [100] = "Humour",
+ [101] = "Speech",
+ [102] = "Chanson",
+ [103] = "Opera",
+ [104] = "Chamber Music",
+ [105] = "Sonata",
+ [106] = "Symphony",
+ [107] = "Booty Bass",
+ [108] = "Primus",
+ [109] = "Porn Groove",
+ [110] = "Satire",
+ [111] = "Slow Jam",
+ [112] = "Club",
+ [113] = "Tango",
+ [114] = "Samba",
+ [115] = "Folklore",
+ [116] = "Ballad",
+ [117] = "Power Ballad",
+ [118] = "Rhythmic Soul",
+ [119] = "Freestyle",
+ [120] = "Duet",
+ [121] = "Punk Rock",
+ [122] = "Drum Solo",
+ [123] = "A capella",
+ [124] = "Euro-House",
+ [125] = "Dance Hall",
+};
+
+/* buf must be ID3_HEADER_SIZE byte long */
+static int id3_match(const uint8_t *buf)
+{
+ return (buf[0] == 'I' &&
+ buf[1] == 'D' &&
+ buf[2] == '3' &&
+ buf[3] != 0xff &&
+ buf[4] != 0xff &&
+ (buf[6] & 0x80) == 0 &&
+ (buf[7] & 0x80) == 0 &&
+ (buf[8] & 0x80) == 0 &&
+ (buf[9] & 0x80) == 0);
+}
+
+static void id3_get_string(char *str, int str_size,
+ const uint8_t *buf, int buf_size)
+{
+ int i, c;
+ char *q;
+
+ q = str;
+ for(i = 0; i < buf_size; i++) {
+ c = buf[i];
+ if (c == '\0')
+ break;
+ if ((q - str) >= str_size - 1)
+ break;
+ *q++ = c;
+ }
+ *q = '\0';
+}
+
+/* 'buf' must be ID3_TAG_SIZE byte long */
+static int id3_parse_tag(AVFormatContext *s, const uint8_t *buf)
+{
+ char str[5];
+ int genre;
+
+ if (!(buf[0] == 'T' &&
+ buf[1] == 'A' &&
+ buf[2] == 'G'))
+ return -1;
+ id3_get_string(s->title, sizeof(s->title), buf + 3, 30);
+ id3_get_string(s->author, sizeof(s->author), buf + 33, 30);
+ id3_get_string(s->album, sizeof(s->album), buf + 63, 30);
+ id3_get_string(str, sizeof(str), buf + 93, 4);
+ s->year = atoi(str);
+ id3_get_string(s->comment, sizeof(s->comment), buf + 97, 30);
+ if (buf[125] == 0 && buf[126] != 0)
+ s->track = buf[126];
+ genre = buf[127];
+ if (genre <= ID3_GENRE_MAX)
+ pstrcpy(s->genre, sizeof(s->genre), id3_genre_str[genre]);
+ return 0;
+}
+
+static void id3_create_tag(AVFormatContext *s, uint8_t *buf)
+{
+ int v, i;
+
+ memset(buf, 0, ID3_TAG_SIZE); /* fail safe */
+ buf[0] = 'T';
+ buf[1] = 'A';
+ buf[2] = 'G';
+ strncpy(buf + 3, s->title, 30);
+ strncpy(buf + 33, s->author, 30);
+ strncpy(buf + 63, s->album, 30);
+ v = s->year;
+ if (v > 0) {
+ for(i = 0;i < 4; i++) {
+ buf[96 - i] = '0' + (v % 10);
+ v = v / 10;
+ }
+ }
+ strncpy(buf + 97, s->comment, 30);
+ if (s->track != 0) {
+ buf[125] = 0;
+ buf[126] = s->track;
+ }
+ for(i = 0; i <= ID3_GENRE_MAX; i++) {
+ if (!strcasecmp(s->genre, id3_genre_str[i])) {
+ buf[127] = i;
+ break;
+ }
+ }
+}
+
+/* mp3 read */
+
+static int mp3_read_probe(AVProbeData *p)
+{
+ int max_frames, first_frames;
+ int fsize, frames, sample_rate;
+ uint32_t header;
+ uint8_t *buf, *buf2, *end;
+ AVCodecContext avctx;
+
+ if(p->buf_size < ID3_HEADER_SIZE)
+ return 0;
+
+ if(id3_match(p->buf))
+ return AVPROBE_SCORE_MAX/2+1; // this must be less then mpeg-ps because some retards put id3 tage before mpeg-ps files
+
+ max_frames = 0;
+ buf = p->buf;
+ end = buf + FFMIN(4096, p->buf_size - sizeof(uint32_t));
+
+ for(; buf < end; buf++) {
+ buf2 = buf;
+
+ for(frames = 0; buf2 < end; frames++) {
+ header = (buf2[0] << 24) | (buf2[1] << 16) | (buf2[2] << 8) | buf2[3];
+ fsize = mpa_decode_header(&avctx, header, &sample_rate);
+ if(fsize < 0)
+ break;
+ buf2 += fsize;
+ }
+ max_frames = FFMAX(max_frames, frames);
+ if(buf == p->buf)
+ first_frames= frames;
+ }
+ if (first_frames>=3) return AVPROBE_SCORE_MAX/2+1;
+ else if(max_frames>=3) return AVPROBE_SCORE_MAX/4;
+ else if(max_frames>=1) return 1;
+ else return 0;
+}
+
+static int mp3_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ AVStream *st;
+ uint8_t buf[ID3_TAG_SIZE];
+ int len, ret, filesize;
+
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_id = CODEC_ID_MP3;
+ st->need_parsing = 1;
+
+ /* try to get the TAG */
+ if (!url_is_streamed(&s->pb)) {
+ /* XXX: change that */
+ filesize = url_fsize(&s->pb);
+ if (filesize > 128) {
+ url_fseek(&s->pb, filesize - 128, SEEK_SET);
+ ret = get_buffer(&s->pb, buf, ID3_TAG_SIZE);
+ if (ret == ID3_TAG_SIZE) {
+ id3_parse_tag(s, buf);
+ }
+ url_fseek(&s->pb, 0, SEEK_SET);
+ }
+ }
+
+ /* if ID3 header found, skip it */
+ ret = get_buffer(&s->pb, buf, ID3_HEADER_SIZE);
+ if (ret != ID3_HEADER_SIZE)
+ return -1;
+ if (id3_match(buf)) {
+ /* skip ID3 header */
+ len = ((buf[6] & 0x7f) << 21) |
+ ((buf[7] & 0x7f) << 14) |
+ ((buf[8] & 0x7f) << 7) |
+ (buf[9] & 0x7f);
+ url_fskip(&s->pb, len);
+ } else {
+ url_fseek(&s->pb, 0, SEEK_SET);
+ }
+
+ /* the parameters will be extracted from the compressed bitstream */
+ return 0;
+}
+
+#define MP3_PACKET_SIZE 1024
+
+static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ int ret, size;
+ // AVStream *st = s->streams[0];
+
+ size= MP3_PACKET_SIZE;
+
+ ret= av_get_packet(&s->pb, pkt, size);
+
+ pkt->stream_index = 0;
+ if (ret <= 0) {
+ return AVERROR_IO;
+ }
+ /* note: we need to modify the packet size here to handle the last
+ packet */
+ pkt->size = ret;
+ return ret;
+}
+
+static int mp3_read_close(AVFormatContext *s)
+{
+ return 0;
+}
+
+#ifdef CONFIG_MUXERS
+/* simple formats */
+static int mp3_write_header(struct AVFormatContext *s)
+{
+ return 0;
+}
+
+static int mp3_write_packet(struct AVFormatContext *s, AVPacket *pkt)
+{
+ put_buffer(&s->pb, pkt->data, pkt->size);
+ put_flush_packet(&s->pb);
+ return 0;
+}
+
+static int mp3_write_trailer(struct AVFormatContext *s)
+{
+ uint8_t buf[ID3_TAG_SIZE];
+
+ /* write the id3 header */
+ if (s->title[0] != '\0') {
+ id3_create_tag(s, buf);
+ put_buffer(&s->pb, buf, ID3_TAG_SIZE);
+ put_flush_packet(&s->pb);
+ }
+ return 0;
+}
+#endif //CONFIG_MUXERS
+
+#ifdef CONFIG_MP3_DEMUXER
+AVInputFormat mp3_demuxer = {
+ "mp3",
+ "MPEG audio",
+ 0,
+ mp3_read_probe,
+ mp3_read_header,
+ mp3_read_packet,
+ mp3_read_close,
+ .flags= AVFMT_GENERIC_INDEX,
+ .extensions = "mp2,mp3,m2a", /* XXX: use probe */
+};
+#endif
+#ifdef CONFIG_MP2_MUXER
+AVOutputFormat mp2_muxer = {
+ "mp2",
+ "MPEG audio layer 2",
+ "audio/x-mpeg",
+#ifdef CONFIG_LIBMP3LAME
+ "mp2,m2a",
+#else
+ "mp2,mp3,m2a",
+#endif
+ 0,
+ CODEC_ID_MP2,
+ 0,
+ mp3_write_header,
+ mp3_write_packet,
+ mp3_write_trailer,
+};
+#endif
+#ifdef CONFIG_MP3_MUXER
+AVOutputFormat mp3_muxer = {
+ "mp3",
+ "MPEG audio layer 3",
+ "audio/x-mpeg",
+ "mp3",
+ 0,
+ CODEC_ID_MP3,
+ 0,
+ mp3_write_header,
+ mp3_write_packet,
+ mp3_write_trailer,
+};
+#endif
diff --git a/contrib/ffmpeg/libavformat/mpc.c b/contrib/ffmpeg/libavformat/mpc.c
new file mode 100644
index 000000000..a28efb16d
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/mpc.c
@@ -0,0 +1,231 @@
+/*
+ * Musepack demuxer
+ * Copyright (c) 2006 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 St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include "avformat.h"
+#include "bitstream.h"
+
+#define MPC_FRAMESIZE 1152
+#define DELAY_FRAMES 32
+
+static const int mpc_rate[4] = { 44100, 48000, 37800, 32000 };
+typedef struct {
+ int64_t pos;
+ int size, skip;
+}MPCFrame;
+
+typedef struct {
+ int ver;
+ uint32_t curframe, lastframe;
+ uint32_t fcount;
+ MPCFrame *frames;
+ int curbits;
+ int frames_noted;
+} MPCContext;
+
+static int mpc_probe(AVProbeData *p)
+{
+ const uint8_t *d = p->buf;
+ if (p->buf_size < 32)
+ return 0;
+ if (d[0] == 'M' && d[1] == 'P' && d[2] == '+' && (d[3] == 0x17 || d[3] == 0x7))
+ return AVPROBE_SCORE_MAX;
+ if (d[0] == 'I' && d[1] == 'D' && d[2] == '3')
+ return AVPROBE_SCORE_MAX / 2;
+ return 0;
+}
+
+static int mpc_read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+ MPCContext *c = s->priv_data;
+ AVStream *st;
+ int t;
+
+ t = get_le24(&s->pb);
+ if(t != MKTAG('M', 'P', '+', 0)){
+ if(t != MKTAG('I', 'D', '3', 0)){
+ av_log(s, AV_LOG_ERROR, "Not a Musepack file\n");
+ return -1;
+ }
+ /* skip ID3 tags and try again */
+ url_fskip(&s->pb, 3);
+ t = get_byte(&s->pb) << 21;
+ t |= get_byte(&s->pb) << 14;
+ t |= get_byte(&s->pb) << 7;
+ t |= get_byte(&s->pb);
+ av_log(s, AV_LOG_DEBUG, "Skipping %d(%X) bytes of ID3 data\n", t, t);
+ url_fskip(&s->pb, t);
+ if(get_le24(&s->pb) != MKTAG('M', 'P', '+', 0)){
+ av_log(s, AV_LOG_ERROR, "Not a Musepack file\n");
+ return -1;
+ }
+ }
+ c->ver = get_byte(&s->pb);
+ if(c->ver != 0x07 && c->ver != 0x17){
+ av_log(s, AV_LOG_ERROR, "Can demux Musepack SV7, got version %02X\n", c->ver);
+ return -1;
+ }
+ c->fcount = get_le32(&s->pb);
+ if((int64_t)c->fcount * sizeof(MPCFrame) >= UINT_MAX){
+ av_log(s, AV_LOG_ERROR, "Too many frames, seeking is not possible\n");
+ return -1;
+ }
+ c->frames = av_malloc(c->fcount * sizeof(MPCFrame));
+ c->curframe = 0;
+ c->lastframe = -1;
+ c->curbits = 8;
+ c->frames_noted = 0;
+
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_id = CODEC_ID_MUSEPACK7;
+ st->codec->channels = 2;
+ st->codec->bits_per_sample = 16;
+
+ st->codec->extradata_size = 16;
+ st->codec->extradata = av_mallocz(st->codec->extradata_size+FF_INPUT_BUFFER_PADDING_SIZE);
+ get_buffer(&s->pb, st->codec->extradata, 16);
+ 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;
+
+ return 0;
+}
+
+static int mpc_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ MPCContext *c = s->priv_data;
+ int ret, size, size2, curbits, cur = c->curframe;
+ int64_t tmp, pos;
+
+ if (c->curframe >= c->fcount)
+ return -1;
+
+ if(c->curframe != c->lastframe + 1){
+ url_fseek(&s->pb, c->frames[c->curframe].pos, SEEK_SET);
+ c->curbits = c->frames[c->curframe].skip;
+ }
+ c->lastframe = c->curframe;
+ c->curframe++;
+ curbits = c->curbits;
+ pos = url_ftell(&s->pb);
+ tmp = get_le32(&s->pb);
+ if(curbits <= 12){
+ size2 = (tmp >> (12 - curbits)) & 0xFFFFF;
+ }else{
+ tmp = (tmp << 32) | get_le32(&s->pb);
+ size2 = (tmp >> (44 - curbits)) & 0xFFFFF;
+ }
+ curbits += 20;
+ url_fseek(&s->pb, pos, SEEK_SET);
+
+ size = ((size2 + curbits + 31) & ~31) >> 3;
+ if(cur == c->frames_noted){
+ c->frames[cur].pos = pos;
+ c->frames[cur].size = size;
+ c->frames[cur].skip = curbits - 20;
+ av_add_index_entry(s->streams[0], cur, cur, size, 0, AVINDEX_KEYFRAME);
+ c->frames_noted++;
+ }
+ c->curbits = (curbits + size2) & 0x1F;
+
+ if (av_new_packet(pkt, size) < 0)
+ return AVERROR_IO;
+
+ pkt->data[0] = curbits;
+ pkt->data[1] = (c->curframe > c->fcount);
+
+ pkt->stream_index = 0;
+ pkt->pts = cur;
+ ret = get_buffer(&s->pb, pkt->data + 4, size);
+ if(c->curbits)
+ url_fseek(&s->pb, -4, SEEK_CUR);
+ if(ret < size){
+ av_free_packet(pkt);
+ return AVERROR_IO;
+ }
+ pkt->size = ret + 4;
+
+ return 0;
+}
+
+static int mpc_read_close(AVFormatContext *s)
+{
+ MPCContext *c = s->priv_data;
+
+ av_freep(&c->frames);
+ return 0;
+}
+
+/**
+ * Seek to the given position
+ * If position is unknown but is within the limits of file
+ * then packets are skipped unless desired position is reached
+ *
+ * Also this function makes use of the fact that timestamp == frameno
+ */
+static int mpc_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
+{
+ AVStream *st = s->streams[stream_index];
+ MPCContext *c = s->priv_data;
+ AVPacket pkt1, *pkt = &pkt1;
+ int ret;
+ int index = av_index_search_timestamp(st, timestamp - DELAY_FRAMES, flags);
+ uint32_t lastframe;
+
+ /* if found, seek there */
+ if (index >= 0){
+ c->curframe = st->index_entries[index].pos;
+ return 0;
+ }
+ /* if timestamp is out of bounds, return error */
+ if(timestamp < 0 || timestamp >= c->fcount)
+ return -1;
+ timestamp -= DELAY_FRAMES;
+ /* seek to the furthest known position and read packets until
+ we reach desired position */
+ lastframe = c->curframe;
+ if(c->frames_noted) c->curframe = c->frames_noted - 1;
+ while(c->curframe < timestamp){
+ ret = av_read_frame(s, pkt);
+ if (ret < 0){
+ c->curframe = lastframe;
+ return -1;
+ }
+ av_free_packet(pkt);
+ }
+ return 0;
+}
+
+
+AVInputFormat mpc_demuxer = {
+ "mpc",
+ "musepack",
+ sizeof(MPCContext),
+ mpc_probe,
+ mpc_read_header,
+ mpc_read_packet,
+ mpc_read_close,
+ mpc_read_seek,
+ .extensions = "mpc",
+};
diff --git a/contrib/ffmpeg/libavformat/mpeg.c b/contrib/ffmpeg/libavformat/mpeg.c
new file mode 100644
index 000000000..ae47fa60a
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/mpeg.c
@@ -0,0 +1,1853 @@
+/*
+ * MPEG1/2 muxer and demuxer
+ * Copyright (c) 2000, 2001, 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
+ */
+#include "avformat.h"
+#include "bitstream.h"
+#include "fifo.h"
+
+#define MAX_PAYLOAD_SIZE 4096
+//#define DEBUG_SEEK
+
+#undef NDEBUG
+#include <assert.h>
+
+typedef struct PacketDesc {
+ int64_t pts;
+ int64_t dts;
+ int size;
+ int unwritten_size;
+ int flags;
+ struct PacketDesc *next;
+} PacketDesc;
+
+typedef struct {
+ AVFifoBuffer fifo;
+ uint8_t id;
+ int max_buffer_size; /* in bytes */
+ int buffer_index;
+ PacketDesc *predecode_packet;
+ PacketDesc *premux_packet;
+ PacketDesc **next_packet;
+ int packet_number;
+ uint8_t lpcm_header[3];
+ int lpcm_align;
+ int bytes_to_iframe;
+ int align_iframe;
+ int64_t vobu_start_pts;
+} StreamInfo;
+
+typedef struct {
+ int packet_size; /* required packet size */
+ int packet_number;
+ int pack_header_freq; /* frequency (in packets^-1) at which we send pack headers */
+ int system_header_freq;
+ int system_header_size;
+ int mux_rate; /* bitrate in units of 50 bytes/s */
+ /* stream info */
+ int audio_bound;
+ int video_bound;
+ int is_mpeg2;
+ int is_vcd;
+ int is_svcd;
+ int is_dvd;
+ int64_t last_scr; /* current system clock */
+
+ double vcd_padding_bitrate; //FIXME floats
+ int64_t vcd_padding_bytes_written;
+
+} MpegMuxContext;
+
+#define PACK_START_CODE ((unsigned int)0x000001ba)
+#define SYSTEM_HEADER_START_CODE ((unsigned int)0x000001bb)
+#define SEQUENCE_END_CODE ((unsigned int)0x000001b7)
+#define PACKET_START_CODE_MASK ((unsigned int)0xffffff00)
+#define PACKET_START_CODE_PREFIX ((unsigned int)0x00000100)
+#define ISO_11172_END_CODE ((unsigned int)0x000001b9)
+
+/* mpeg2 */
+#define PROGRAM_STREAM_MAP 0x1bc
+#define PRIVATE_STREAM_1 0x1bd
+#define PADDING_STREAM 0x1be
+#define PRIVATE_STREAM_2 0x1bf
+
+
+#define AUDIO_ID 0xc0
+#define VIDEO_ID 0xe0
+#define AC3_ID 0x80
+#define DTS_ID 0x8a
+#define LPCM_ID 0xa0
+#define SUB_ID 0x20
+
+#define STREAM_TYPE_VIDEO_MPEG1 0x01
+#define STREAM_TYPE_VIDEO_MPEG2 0x02
+#define STREAM_TYPE_AUDIO_MPEG1 0x03
+#define STREAM_TYPE_AUDIO_MPEG2 0x04
+#define STREAM_TYPE_PRIVATE_SECTION 0x05
+#define STREAM_TYPE_PRIVATE_DATA 0x06
+#define STREAM_TYPE_AUDIO_AAC 0x0f
+#define STREAM_TYPE_VIDEO_MPEG4 0x10
+#define STREAM_TYPE_VIDEO_H264 0x1b
+
+#define STREAM_TYPE_AUDIO_AC3 0x81
+#define STREAM_TYPE_AUDIO_DTS 0x8a
+
+static const int lpcm_freq_tab[4] = { 48000, 96000, 44100, 32000 };
+
+#ifdef CONFIG_MUXERS
+AVOutputFormat mpeg1system_muxer;
+AVOutputFormat mpeg1vcd_muxer;
+AVOutputFormat mpeg2vob_muxer;
+AVOutputFormat mpeg2svcd_muxer;
+AVOutputFormat mpeg2dvd_muxer;
+
+static int put_pack_header(AVFormatContext *ctx,
+ uint8_t *buf, int64_t timestamp)
+{
+ MpegMuxContext *s = ctx->priv_data;
+ PutBitContext pb;
+
+ init_put_bits(&pb, buf, 128);
+
+ put_bits(&pb, 32, PACK_START_CODE);
+ if (s->is_mpeg2) {
+ put_bits(&pb, 2, 0x1);
+ } else {
+ put_bits(&pb, 4, 0x2);
+ }
+ put_bits(&pb, 3, (uint32_t)((timestamp >> 30) & 0x07));
+ put_bits(&pb, 1, 1);
+ put_bits(&pb, 15, (uint32_t)((timestamp >> 15) & 0x7fff));
+ put_bits(&pb, 1, 1);
+ put_bits(&pb, 15, (uint32_t)((timestamp) & 0x7fff));
+ put_bits(&pb, 1, 1);
+ if (s->is_mpeg2) {
+ /* clock extension */
+ put_bits(&pb, 9, 0);
+ }
+ put_bits(&pb, 1, 1);
+ put_bits(&pb, 22, s->mux_rate);
+ put_bits(&pb, 1, 1);
+ if (s->is_mpeg2) {
+ put_bits(&pb, 1, 1);
+ put_bits(&pb, 5, 0x1f); /* reserved */
+ put_bits(&pb, 3, 0); /* stuffing length */
+ }
+ flush_put_bits(&pb);
+ return pbBufPtr(&pb) - pb.buf;
+}
+
+static int put_system_header(AVFormatContext *ctx, uint8_t *buf,int only_for_stream_id)
+{
+ MpegMuxContext *s = ctx->priv_data;
+ int size, i, private_stream_coded, id;
+ PutBitContext pb;
+
+ init_put_bits(&pb, buf, 128);
+
+ put_bits(&pb, 32, SYSTEM_HEADER_START_CODE);
+ put_bits(&pb, 16, 0);
+ put_bits(&pb, 1, 1);
+
+ put_bits(&pb, 22, s->mux_rate); /* maximum bit rate of the multiplexed stream */
+ put_bits(&pb, 1, 1); /* marker */
+ if (s->is_vcd && only_for_stream_id==VIDEO_ID) {
+ /* This header applies only to the video stream (see VCD standard p. IV-7)*/
+ put_bits(&pb, 6, 0);
+ } else
+ put_bits(&pb, 6, s->audio_bound);
+
+ if (s->is_vcd) {
+ /* see VCD standard, p. IV-7*/
+ put_bits(&pb, 1, 0);
+ put_bits(&pb, 1, 1);
+ } else {
+ put_bits(&pb, 1, 0); /* variable bitrate*/
+ put_bits(&pb, 1, 0); /* non constrainted bit stream */
+ }
+
+ if (s->is_vcd || s->is_dvd) {
+ /* see VCD standard p IV-7 */
+ put_bits(&pb, 1, 1); /* audio locked */
+ put_bits(&pb, 1, 1); /* video locked */
+ } else {
+ put_bits(&pb, 1, 0); /* audio locked */
+ put_bits(&pb, 1, 0); /* video locked */
+ }
+
+ put_bits(&pb, 1, 1); /* marker */
+
+ if (s->is_vcd && only_for_stream_id==AUDIO_ID) {
+ /* This header applies only to the audio stream (see VCD standard p. IV-7)*/
+ put_bits(&pb, 5, 0);
+ } else
+ put_bits(&pb, 5, s->video_bound);
+
+ if (s->is_dvd) {
+ put_bits(&pb, 1, 0); /* packet_rate_restriction_flag */
+ put_bits(&pb, 7, 0x7f); /* reserved byte */
+ } else
+ put_bits(&pb, 8, 0xff); /* reserved byte */
+
+ /* DVD-Video Stream_bound entries
+ id (0xB9) video, maximum P-STD for stream 0xE0. (P-STD_buffer_bound_scale = 1)
+ id (0xB8) audio, maximum P-STD for any MPEG audio (0xC0 to 0xC7) streams. If there are none set to 4096 (32x128). (P-STD_buffer_bound_scale = 0)
+ id (0xBD) private stream 1 (audio other than MPEG and subpictures). (P-STD_buffer_bound_scale = 1)
+ id (0xBF) private stream 2, NAV packs, set to 2x1024. */
+ if (s->is_dvd) {
+
+ int P_STD_max_video = 0;
+ int P_STD_max_mpeg_audio = 0;
+ int P_STD_max_mpeg_PS1 = 0;
+
+ for(i=0;i<ctx->nb_streams;i++) {
+ StreamInfo *stream = ctx->streams[i]->priv_data;
+
+ id = stream->id;
+ if (id == 0xbd && stream->max_buffer_size > P_STD_max_mpeg_PS1) {
+ P_STD_max_mpeg_PS1 = stream->max_buffer_size;
+ } else if (id >= 0xc0 && id <= 0xc7 && stream->max_buffer_size > P_STD_max_mpeg_audio) {
+ P_STD_max_mpeg_audio = stream->max_buffer_size;
+ } else if (id == 0xe0 && stream->max_buffer_size > P_STD_max_video) {
+ P_STD_max_video = stream->max_buffer_size;
+ }
+ }
+
+ /* video */
+ put_bits(&pb, 8, 0xb9); /* stream ID */
+ put_bits(&pb, 2, 3);
+ put_bits(&pb, 1, 1);
+ put_bits(&pb, 13, P_STD_max_video / 1024);
+
+ /* audio */
+ if (P_STD_max_mpeg_audio == 0)
+ P_STD_max_mpeg_audio = 4096;
+ put_bits(&pb, 8, 0xb8); /* stream ID */
+ put_bits(&pb, 2, 3);
+ put_bits(&pb, 1, 0);
+ put_bits(&pb, 13, P_STD_max_mpeg_audio / 128);
+
+ /* private stream 1 */
+ put_bits(&pb, 8, 0xbd); /* stream ID */
+ put_bits(&pb, 2, 3);
+ put_bits(&pb, 1, 0);
+ put_bits(&pb, 13, P_STD_max_mpeg_PS1 / 128);
+
+ /* private stream 2 */
+ put_bits(&pb, 8, 0xbf); /* stream ID */
+ put_bits(&pb, 2, 3);
+ put_bits(&pb, 1, 1);
+ put_bits(&pb, 13, 2);
+ }
+ else {
+ /* audio stream info */
+ private_stream_coded = 0;
+ for(i=0;i<ctx->nb_streams;i++) {
+ StreamInfo *stream = ctx->streams[i]->priv_data;
+
+
+ /* For VCDs, only include the stream info for the stream
+ that the pack which contains this system belongs to.
+ (see VCD standard p. IV-7) */
+ if ( !s->is_vcd || stream->id==only_for_stream_id
+ || only_for_stream_id==0) {
+
+ id = stream->id;
+ if (id < 0xc0) {
+ /* special case for private streams (AC3 use that) */
+ if (private_stream_coded)
+ continue;
+ private_stream_coded = 1;
+ id = 0xbd;
+ }
+ put_bits(&pb, 8, id); /* stream ID */
+ put_bits(&pb, 2, 3);
+ if (id < 0xe0) {
+ /* audio */
+ put_bits(&pb, 1, 0);
+ put_bits(&pb, 13, stream->max_buffer_size / 128);
+ } else {
+ /* video */
+ put_bits(&pb, 1, 1);
+ put_bits(&pb, 13, stream->max_buffer_size / 1024);
+ }
+ }
+ }
+ }
+
+ flush_put_bits(&pb);
+ size = pbBufPtr(&pb) - pb.buf;
+ /* patch packet size */
+ buf[4] = (size - 6) >> 8;
+ buf[5] = (size - 6) & 0xff;
+
+ return size;
+}
+
+static int get_system_header_size(AVFormatContext *ctx)
+{
+ int buf_index, i, private_stream_coded;
+ StreamInfo *stream;
+ MpegMuxContext *s = ctx->priv_data;
+
+ if (s->is_dvd)
+ return 18; // DVD-Video system headers are 18 bytes fixed length.
+
+ buf_index = 12;
+ private_stream_coded = 0;
+ for(i=0;i<ctx->nb_streams;i++) {
+ stream = ctx->streams[i]->priv_data;
+ if (stream->id < 0xc0) {
+ if (private_stream_coded)
+ continue;
+ private_stream_coded = 1;
+ }
+ buf_index += 3;
+ }
+ return buf_index;
+}
+
+static int mpeg_mux_init(AVFormatContext *ctx)
+{
+ MpegMuxContext *s = ctx->priv_data;
+ int bitrate, i, mpa_id, mpv_id, mps_id, ac3_id, dts_id, lpcm_id, j;
+ AVStream *st;
+ StreamInfo *stream;
+ int audio_bitrate;
+ int video_bitrate;
+
+ s->packet_number = 0;
+ s->is_vcd = (ctx->oformat == &mpeg1vcd_muxer);
+ s->is_svcd = (ctx->oformat == &mpeg2svcd_muxer);
+ s->is_mpeg2 = (ctx->oformat == &mpeg2vob_muxer || ctx->oformat == &mpeg2svcd_muxer || ctx->oformat == &mpeg2dvd_muxer);
+ s->is_dvd = (ctx->oformat == &mpeg2dvd_muxer);
+
+ if(ctx->packet_size)
+ s->packet_size = ctx->packet_size;
+ else
+ s->packet_size = 2048;
+
+ s->vcd_padding_bytes_written = 0;
+ s->vcd_padding_bitrate=0;
+
+ s->audio_bound = 0;
+ s->video_bound = 0;
+ mpa_id = AUDIO_ID;
+ ac3_id = AC3_ID;
+ dts_id = DTS_ID;
+ mpv_id = VIDEO_ID;
+ mps_id = SUB_ID;
+ lpcm_id = LPCM_ID;
+ for(i=0;i<ctx->nb_streams;i++) {
+ st = ctx->streams[i];
+ stream = av_mallocz(sizeof(StreamInfo));
+ if (!stream)
+ goto fail;
+ st->priv_data = stream;
+
+ av_set_pts_info(st, 64, 1, 90000);
+
+ switch(st->codec->codec_type) {
+ case CODEC_TYPE_AUDIO:
+ if (st->codec->codec_id == CODEC_ID_AC3) {
+ stream->id = ac3_id++;
+ } else if (st->codec->codec_id == CODEC_ID_DTS) {
+ stream->id = dts_id++;
+ } else if (st->codec->codec_id == CODEC_ID_PCM_S16BE) {
+ stream->id = lpcm_id++;
+ for(j = 0; j < 4; j++) {
+ if (lpcm_freq_tab[j] == st->codec->sample_rate)
+ break;
+ }
+ if (j == 4)
+ goto fail;
+ if (st->codec->channels > 8)
+ return -1;
+ stream->lpcm_header[0] = 0x0c;
+ stream->lpcm_header[1] = (st->codec->channels - 1) | (j << 4);
+ stream->lpcm_header[2] = 0x80;
+ stream->lpcm_align = st->codec->channels * 2;
+ } else {
+ stream->id = mpa_id++;
+ }
+
+ /* This value HAS to be used for VCD (see VCD standard, p. IV-7).
+ Right now it is also used for everything else.*/
+ stream->max_buffer_size = 4 * 1024;
+ s->audio_bound++;
+ break;
+ case CODEC_TYPE_VIDEO:
+ stream->id = mpv_id++;
+ if (st->codec->rc_buffer_size)
+ stream->max_buffer_size = 6*1024 + st->codec->rc_buffer_size/8;
+ else
+ stream->max_buffer_size = 230*1024; //FIXME this is probably too small as default
+#if 0
+ /* see VCD standard, p. IV-7*/
+ stream->max_buffer_size = 46 * 1024;
+ else
+ /* This value HAS to be used for SVCD (see SVCD standard, p. 26 V.2.3.2).
+ Right now it is also used for everything else.*/
+ stream->max_buffer_size = 230 * 1024;
+#endif
+ s->video_bound++;
+ break;
+ case CODEC_TYPE_SUBTITLE:
+ stream->id = mps_id++;
+ stream->max_buffer_size = 16 * 1024;
+ break;
+ default:
+ return -1;
+ }
+ av_fifo_init(&stream->fifo, 16);
+ }
+ bitrate = 0;
+ audio_bitrate = 0;
+ video_bitrate = 0;
+ for(i=0;i<ctx->nb_streams;i++) {
+ int codec_rate;
+ st = ctx->streams[i];
+ stream = (StreamInfo*) st->priv_data;
+
+ if(st->codec->rc_max_rate || stream->id==VIDEO_ID)
+ codec_rate= st->codec->rc_max_rate;
+ else
+ codec_rate= st->codec->bit_rate;
+
+ if(!codec_rate)
+ codec_rate= (1<<21)*8*50/ctx->nb_streams;
+
+ bitrate += codec_rate;
+
+ if (stream->id==AUDIO_ID)
+ audio_bitrate += codec_rate;
+ else if (stream->id==VIDEO_ID)
+ video_bitrate += codec_rate;
+ }
+
+ if(ctx->mux_rate){
+ s->mux_rate= (ctx->mux_rate + (8 * 50) - 1) / (8 * 50);
+ } else {
+ /* we increase slightly the bitrate to take into account the
+ headers. XXX: compute it exactly */
+ bitrate += bitrate*5/100;
+ bitrate += 10000;
+ s->mux_rate = (bitrate + (8 * 50) - 1) / (8 * 50);
+ }
+
+ if (s->is_vcd) {
+ double overhead_rate;
+
+ /* The VCD standard mandates that the mux_rate field is 3528
+ (see standard p. IV-6).
+ The value is actually "wrong", i.e. if you calculate
+ it using the normal formula and the 75 sectors per second transfer
+ rate you get a different value because the real pack size is 2324,
+ not 2352. But the standard explicitly specifies that the mux_rate
+ field in the header must have this value.*/
+// s->mux_rate=2352 * 75 / 50; /* = 3528*/
+
+ /* The VCD standard states that the muxed stream must be
+ exactly 75 packs / second (the data rate of a single speed cdrom).
+ Since the video bitrate (probably 1150000 bits/sec) will be below
+ the theoretical maximum we have to add some padding packets
+ to make up for the lower data rate.
+ (cf. VCD standard p. IV-6 )*/
+
+ /* Add the header overhead to the data rate.
+ 2279 data bytes per audio pack, 2294 data bytes per video pack*/
+ overhead_rate = ((audio_bitrate / 8.0) / 2279) * (2324 - 2279);
+ overhead_rate += ((video_bitrate / 8.0) / 2294) * (2324 - 2294);
+ overhead_rate *= 8;
+
+ /* Add padding so that the full bitrate is 2324*75 bytes/sec */
+ s->vcd_padding_bitrate = 2324 * 75 * 8 - (bitrate + overhead_rate);
+ }
+
+ if (s->is_vcd || s->is_mpeg2)
+ /* every packet */
+ s->pack_header_freq = 1;
+ else
+ /* every 2 seconds */
+ s->pack_header_freq = 2 * bitrate / s->packet_size / 8;
+
+ /* the above seems to make pack_header_freq zero sometimes */
+ if (s->pack_header_freq == 0)
+ s->pack_header_freq = 1;
+
+ if (s->is_mpeg2)
+ /* every 200 packets. Need to look at the spec. */
+ s->system_header_freq = s->pack_header_freq * 40;
+ else if (s->is_vcd)
+ /* the standard mandates that there are only two system headers
+ in the whole file: one in the first packet of each stream.
+ (see standard p. IV-7 and IV-8) */
+ s->system_header_freq = 0x7fffffff;
+ else
+ s->system_header_freq = s->pack_header_freq * 5;
+
+ for(i=0;i<ctx->nb_streams;i++) {
+ stream = ctx->streams[i]->priv_data;
+ stream->packet_number = 0;
+ }
+ s->system_header_size = get_system_header_size(ctx);
+ s->last_scr = 0;
+ return 0;
+ fail:
+ for(i=0;i<ctx->nb_streams;i++) {
+ av_free(ctx->streams[i]->priv_data);
+ }
+ return AVERROR(ENOMEM);
+}
+
+static inline void put_timestamp(ByteIOContext *pb, int id, int64_t timestamp)
+{
+ put_byte(pb,
+ (id << 4) |
+ (((timestamp >> 30) & 0x07) << 1) |
+ 1);
+ put_be16(pb, (uint16_t)((((timestamp >> 15) & 0x7fff) << 1) | 1));
+ put_be16(pb, (uint16_t)((((timestamp) & 0x7fff) << 1) | 1));
+}
+
+
+/* return the number of padding bytes that should be inserted into
+ the multiplexed stream.*/
+static int get_vcd_padding_size(AVFormatContext *ctx, int64_t pts)
+{
+ MpegMuxContext *s = ctx->priv_data;
+ int pad_bytes = 0;
+
+ if (s->vcd_padding_bitrate > 0 && pts!=AV_NOPTS_VALUE)
+ {
+ int64_t full_pad_bytes;
+
+ full_pad_bytes = (int64_t)((s->vcd_padding_bitrate * (pts / 90000.0)) / 8.0); //FIXME this is wrong
+ pad_bytes = (int) (full_pad_bytes - s->vcd_padding_bytes_written);
+
+ if (pad_bytes<0)
+ /* might happen if we have already padded to a later timestamp. This
+ can occur if another stream has already advanced further.*/
+ pad_bytes=0;
+ }
+
+ return pad_bytes;
+}
+
+
+#if 0 /* unused, remove? */
+/* return the exact available payload size for the next packet for
+ stream 'stream_index'. 'pts' and 'dts' are only used to know if
+ timestamps are needed in the packet header. */
+static int get_packet_payload_size(AVFormatContext *ctx, int stream_index,
+ int64_t pts, int64_t dts)
+{
+ MpegMuxContext *s = ctx->priv_data;
+ int buf_index;
+ StreamInfo *stream;
+
+ stream = ctx->streams[stream_index]->priv_data;
+
+ buf_index = 0;
+ if (((s->packet_number % s->pack_header_freq) == 0)) {
+ /* pack header size */
+ if (s->is_mpeg2)
+ buf_index += 14;
+ else
+ buf_index += 12;
+
+ if (s->is_vcd) {
+ /* there is exactly one system header for each stream in a VCD MPEG,
+ One in the very first video packet and one in the very first
+ audio packet (see VCD standard p. IV-7 and IV-8).*/
+
+ if (stream->packet_number==0)
+ /* The system headers refer only to the stream they occur in,
+ so they have a constant size.*/
+ buf_index += 15;
+
+ } else {
+ if ((s->packet_number % s->system_header_freq) == 0)
+ buf_index += s->system_header_size;
+ }
+ }
+
+ if ((s->is_vcd && stream->packet_number==0)
+ || (s->is_svcd && s->packet_number==0))
+ /* the first pack of each stream contains only the pack header,
+ the system header and some padding (see VCD standard p. IV-6)
+ Add the padding size, so that the actual payload becomes 0.*/
+ buf_index += s->packet_size - buf_index;
+ else {
+ /* packet header size */
+ buf_index += 6;
+ if (s->is_mpeg2) {
+ buf_index += 3;
+ if (stream->packet_number==0)
+ buf_index += 3; /* PES extension */
+ buf_index += 1; /* obligatory stuffing byte */
+ }
+ if (pts != AV_NOPTS_VALUE) {
+ if (dts != pts)
+ buf_index += 5 + 5;
+ else
+ buf_index += 5;
+
+ } else {
+ if (!s->is_mpeg2)
+ buf_index++;
+ }
+
+ if (stream->id < 0xc0) {
+ /* AC3/LPCM private data header */
+ buf_index += 4;
+ if (stream->id >= 0xa0) {
+ int n;
+ buf_index += 3;
+ /* NOTE: we round the payload size to an integer number of
+ LPCM samples */
+ n = (s->packet_size - buf_index) % stream->lpcm_align;
+ if (n)
+ buf_index += (stream->lpcm_align - n);
+ }
+ }
+
+ if (s->is_vcd && stream->id == AUDIO_ID)
+ /* The VCD standard demands that 20 zero bytes follow
+ each audio packet (see standard p. IV-8).*/
+ buf_index+=20;
+ }
+ return s->packet_size - buf_index;
+}
+#endif
+
+/* Write an MPEG padding packet header. */
+static void put_padding_packet(AVFormatContext *ctx, ByteIOContext *pb,int packet_bytes)
+{
+ MpegMuxContext *s = ctx->priv_data;
+ int i;
+
+ put_be32(pb, PADDING_STREAM);
+ put_be16(pb, packet_bytes - 6);
+ if (!s->is_mpeg2) {
+ put_byte(pb, 0x0f);
+ packet_bytes -= 7;
+ } else
+ packet_bytes -= 6;
+
+ for(i=0;i<packet_bytes;i++)
+ put_byte(pb, 0xff);
+}
+
+static int get_nb_frames(AVFormatContext *ctx, StreamInfo *stream, int len){
+ int nb_frames=0;
+ PacketDesc *pkt_desc= stream->premux_packet;
+
+ while(len>0){
+ if(pkt_desc->size == pkt_desc->unwritten_size)
+ nb_frames++;
+ len -= pkt_desc->unwritten_size;
+ pkt_desc= pkt_desc->next;
+ }
+
+ return nb_frames;
+}
+
+/* flush the packet on stream stream_index */
+static int flush_packet(AVFormatContext *ctx, int stream_index,
+ int64_t pts, int64_t dts, int64_t scr, int trailer_size)
+{
+ MpegMuxContext *s = ctx->priv_data;
+ StreamInfo *stream = ctx->streams[stream_index]->priv_data;
+ uint8_t *buf_ptr;
+ int size, payload_size, startcode, id, stuffing_size, i, header_len;
+ int packet_size;
+ uint8_t buffer[128];
+ int zero_trail_bytes = 0;
+ int pad_packet_bytes = 0;
+ int pes_flags;
+ int general_pack = 0; /*"general" pack without data specific to one stream?*/
+ int nb_frames;
+
+ id = stream->id;
+
+#if 0
+ printf("packet ID=%2x PTS=%0.3f\n",
+ id, pts / 90000.0);
+#endif
+
+ buf_ptr = buffer;
+
+ if ((s->packet_number % s->pack_header_freq) == 0 || s->last_scr != scr) {
+ /* output pack and systems header if needed */
+ size = put_pack_header(ctx, buf_ptr, scr);
+ buf_ptr += size;
+ s->last_scr= scr;
+
+ if (s->is_vcd) {
+ /* there is exactly one system header for each stream in a VCD MPEG,
+ One in the very first video packet and one in the very first
+ audio packet (see VCD standard p. IV-7 and IV-8).*/
+
+ if (stream->packet_number==0) {
+ size = put_system_header(ctx, buf_ptr, id);
+ buf_ptr += size;
+ }
+ } else if (s->is_dvd) {
+ if (stream->align_iframe || s->packet_number == 0){
+ int PES_bytes_to_fill = s->packet_size - size - 10;
+
+ if (pts != AV_NOPTS_VALUE) {
+ if (dts != pts)
+ PES_bytes_to_fill -= 5 + 5;
+ else
+ PES_bytes_to_fill -= 5;
+ }
+
+ if (stream->bytes_to_iframe == 0 || s->packet_number == 0) {
+ size = put_system_header(ctx, buf_ptr, 0);
+ buf_ptr += size;
+ size = buf_ptr - buffer;
+ put_buffer(&ctx->pb, buffer, size);
+
+ put_be32(&ctx->pb, PRIVATE_STREAM_2);
+ put_be16(&ctx->pb, 0x03d4); // length
+ put_byte(&ctx->pb, 0x00); // substream ID, 00=PCI
+ for (i = 0; i < 979; i++)
+ put_byte(&ctx->pb, 0x00);
+
+ put_be32(&ctx->pb, PRIVATE_STREAM_2);
+ put_be16(&ctx->pb, 0x03fa); // length
+ put_byte(&ctx->pb, 0x01); // substream ID, 01=DSI
+ for (i = 0; i < 1017; i++)
+ put_byte(&ctx->pb, 0x00);
+
+ memset(buffer, 0, 128);
+ buf_ptr = buffer;
+ s->packet_number++;
+ stream->align_iframe = 0;
+ scr += s->packet_size*90000LL / (s->mux_rate*50LL); //FIXME rounding and first few bytes of each packet
+ size = put_pack_header(ctx, buf_ptr, scr);
+ s->last_scr= scr;
+ buf_ptr += size;
+ /* GOP Start */
+ } else if (stream->bytes_to_iframe < PES_bytes_to_fill) {
+ pad_packet_bytes = PES_bytes_to_fill - stream->bytes_to_iframe;
+ }
+ }
+ } else {
+ if ((s->packet_number % s->system_header_freq) == 0) {
+ size = put_system_header(ctx, buf_ptr, 0);
+ buf_ptr += size;
+ }
+ }
+ }
+ size = buf_ptr - buffer;
+ put_buffer(&ctx->pb, buffer, size);
+
+ packet_size = s->packet_size - size;
+
+ if (s->is_vcd && id == AUDIO_ID)
+ /* The VCD standard demands that 20 zero bytes follow
+ each audio pack (see standard p. IV-8).*/
+ zero_trail_bytes += 20;
+
+ if ((s->is_vcd && stream->packet_number==0)
+ || (s->is_svcd && s->packet_number==0)) {
+ /* for VCD the first pack of each stream contains only the pack header,
+ the system header and lots of padding (see VCD standard p. IV-6).
+ In the case of an audio pack, 20 zero bytes are also added at
+ the end.*/
+ /* For SVCD we fill the very first pack to increase compatibility with
+ some DVD players. Not mandated by the standard.*/
+ if (s->is_svcd)
+ general_pack = 1; /* the system header refers to both streams and no stream data*/
+ pad_packet_bytes = packet_size - zero_trail_bytes;
+ }
+
+ packet_size -= pad_packet_bytes + zero_trail_bytes;
+
+ if (packet_size > 0) {
+
+ /* packet header size */
+ packet_size -= 6;
+
+ /* packet header */
+ if (s->is_mpeg2) {
+ header_len = 3;
+ if (stream->packet_number==0)
+ header_len += 3; /* PES extension */
+ header_len += 1; /* obligatory stuffing byte */
+ } else {
+ header_len = 0;
+ }
+ if (pts != AV_NOPTS_VALUE) {
+ if (dts != pts)
+ header_len += 5 + 5;
+ else
+ header_len += 5;
+ } else {
+ if (!s->is_mpeg2)
+ header_len++;
+ }
+
+ payload_size = packet_size - header_len;
+ if (id < 0xc0) {
+ startcode = PRIVATE_STREAM_1;
+ payload_size -= 1;
+ if (id >= 0x40) {
+ payload_size -= 3;
+ if (id >= 0xa0)
+ payload_size -= 3;
+ }
+ } else {
+ startcode = 0x100 + id;
+ }
+
+ stuffing_size = payload_size - av_fifo_size(&stream->fifo);
+
+ // first byte doesnt fit -> reset pts/dts + stuffing
+ if(payload_size <= trailer_size && pts != AV_NOPTS_VALUE){
+ int timestamp_len=0;
+ if(dts != pts)
+ timestamp_len += 5;
+ if(pts != AV_NOPTS_VALUE)
+ timestamp_len += s->is_mpeg2 ? 5 : 4;
+ pts=dts= AV_NOPTS_VALUE;
+ header_len -= timestamp_len;
+ if (s->is_dvd && stream->align_iframe) {
+ pad_packet_bytes += timestamp_len;
+ packet_size -= timestamp_len;
+ } else {
+ payload_size += timestamp_len;
+ }
+ stuffing_size += timestamp_len;
+ if(payload_size > trailer_size)
+ stuffing_size += payload_size - trailer_size;
+ }
+
+ if (pad_packet_bytes > 0 && pad_packet_bytes <= 7) { // can't use padding, so use stuffing
+ packet_size += pad_packet_bytes;
+ payload_size += pad_packet_bytes; // undo the previous adjustment
+ if (stuffing_size < 0) {
+ stuffing_size = pad_packet_bytes;
+ } else {
+ stuffing_size += pad_packet_bytes;
+ }
+ pad_packet_bytes = 0;
+ }
+
+ if (stuffing_size < 0)
+ stuffing_size = 0;
+ if (stuffing_size > 16) { /*<=16 for MPEG-1, <=32 for MPEG-2*/
+ pad_packet_bytes += stuffing_size;
+ packet_size -= stuffing_size;
+ payload_size -= stuffing_size;
+ stuffing_size = 0;
+ }
+
+ nb_frames= get_nb_frames(ctx, stream, payload_size - stuffing_size);
+
+ put_be32(&ctx->pb, startcode);
+
+ put_be16(&ctx->pb, packet_size);
+
+ if (!s->is_mpeg2)
+ for(i=0;i<stuffing_size;i++)
+ put_byte(&ctx->pb, 0xff);
+
+ if (s->is_mpeg2) {
+ put_byte(&ctx->pb, 0x80); /* mpeg2 id */
+
+ pes_flags=0;
+
+ if (pts != AV_NOPTS_VALUE) {
+ pes_flags |= 0x80;
+ if (dts != pts)
+ pes_flags |= 0x40;
+ }
+
+ /* Both the MPEG-2 and the SVCD standards demand that the
+ P-STD_buffer_size field be included in the first packet of
+ every stream. (see SVCD standard p. 26 V.2.3.1 and V.2.3.2
+ and MPEG-2 standard 2.7.7) */
+ if (stream->packet_number == 0)
+ pes_flags |= 0x01;
+
+ put_byte(&ctx->pb, pes_flags); /* flags */
+ put_byte(&ctx->pb, header_len - 3 + stuffing_size);
+
+ if (pes_flags & 0x80) /*write pts*/
+ put_timestamp(&ctx->pb, (pes_flags & 0x40) ? 0x03 : 0x02, pts);
+ if (pes_flags & 0x40) /*write dts*/
+ put_timestamp(&ctx->pb, 0x01, dts);
+
+ if (pes_flags & 0x01) { /*write pes extension*/
+ put_byte(&ctx->pb, 0x10); /* flags */
+
+ /* P-STD buffer info */
+ if (id == AUDIO_ID)
+ put_be16(&ctx->pb, 0x4000 | stream->max_buffer_size/128);
+ else
+ put_be16(&ctx->pb, 0x6000 | stream->max_buffer_size/1024);
+ }
+
+ } else {
+ if (pts != AV_NOPTS_VALUE) {
+ if (dts != pts) {
+ put_timestamp(&ctx->pb, 0x03, pts);
+ put_timestamp(&ctx->pb, 0x01, dts);
+ } else {
+ put_timestamp(&ctx->pb, 0x02, pts);
+ }
+ } else {
+ put_byte(&ctx->pb, 0x0f);
+ }
+ }
+
+ if (s->is_mpeg2) {
+ /* special stuffing byte that is always written
+ to prevent accidental generation of start codes. */
+ put_byte(&ctx->pb, 0xff);
+
+ for(i=0;i<stuffing_size;i++)
+ put_byte(&ctx->pb, 0xff);
+ }
+
+ if (startcode == PRIVATE_STREAM_1) {
+ put_byte(&ctx->pb, id);
+ if (id >= 0xa0) {
+ /* LPCM (XXX: check nb_frames) */
+ put_byte(&ctx->pb, 7);
+ put_be16(&ctx->pb, 4); /* skip 3 header bytes */
+ put_byte(&ctx->pb, stream->lpcm_header[0]);
+ put_byte(&ctx->pb, stream->lpcm_header[1]);
+ put_byte(&ctx->pb, stream->lpcm_header[2]);
+ } else if (id >= 0x40) {
+ /* AC3 */
+ put_byte(&ctx->pb, nb_frames);
+ put_be16(&ctx->pb, trailer_size+1);
+ }
+ }
+
+ /* output data */
+ if(av_fifo_generic_read(&stream->fifo, payload_size - stuffing_size, &put_buffer, &ctx->pb) < 0)
+ return -1;
+ stream->bytes_to_iframe -= payload_size - stuffing_size;
+ }else{
+ payload_size=
+ stuffing_size= 0;
+ }
+
+ if (pad_packet_bytes > 0)
+ put_padding_packet(ctx,&ctx->pb, pad_packet_bytes);
+
+ for(i=0;i<zero_trail_bytes;i++)
+ put_byte(&ctx->pb, 0x00);
+
+ put_flush_packet(&ctx->pb);
+
+ s->packet_number++;
+
+ /* only increase the stream packet number if this pack actually contains
+ something that is specific to this stream! I.e. a dedicated header
+ or some data.*/
+ if (!general_pack)
+ stream->packet_number++;
+
+ return payload_size - stuffing_size;
+}
+
+static void put_vcd_padding_sector(AVFormatContext *ctx)
+{
+ /* There are two ways to do this padding: writing a sector/pack
+ of 0 values, or writing an MPEG padding pack. Both seem to
+ work with most decoders, BUT the VCD standard only allows a 0-sector
+ (see standard p. IV-4, IV-5).
+ So a 0-sector it is...*/
+
+ MpegMuxContext *s = ctx->priv_data;
+ int i;
+
+ for(i=0;i<s->packet_size;i++)
+ put_byte(&ctx->pb, 0);
+
+ s->vcd_padding_bytes_written += s->packet_size;
+
+ put_flush_packet(&ctx->pb);
+
+ /* increasing the packet number is correct. The SCR of the following packs
+ is calculated from the packet_number and it has to include the padding
+ sector (it represents the sector index, not the MPEG pack index)
+ (see VCD standard p. IV-6)*/
+ s->packet_number++;
+}
+
+#if 0 /* unused, remove? */
+static int64_t get_vcd_scr(AVFormatContext *ctx,int stream_index,int64_t pts)
+{
+ MpegMuxContext *s = ctx->priv_data;
+ int64_t scr;
+
+ /* Since the data delivery rate is constant, SCR is computed
+ using the formula C + i * 1200 where C is the start constant
+ and i is the pack index.
+ It is recommended that SCR 0 is at the beginning of the VCD front
+ margin (a sequence of empty Form 2 sectors on the CD).
+ It is recommended that the front margin is 30 sectors long, so
+ we use C = 30*1200 = 36000
+ (Note that even if the front margin is not 30 sectors the file
+ will still be correct according to the standard. It just won't have
+ the "recommended" value).*/
+ scr = 36000 + s->packet_number * 1200;
+
+ return scr;
+}
+#endif
+
+static int remove_decoded_packets(AVFormatContext *ctx, int64_t scr){
+// MpegMuxContext *s = ctx->priv_data;
+ int i;
+
+ for(i=0; i<ctx->nb_streams; i++){
+ AVStream *st = ctx->streams[i];
+ StreamInfo *stream = st->priv_data;
+ PacketDesc *pkt_desc= stream->predecode_packet;
+
+ while(pkt_desc && scr > pkt_desc->dts){ //FIXME > vs >=
+ if(stream->buffer_index < pkt_desc->size ||
+ stream->predecode_packet == stream->premux_packet){
+ av_log(ctx, AV_LOG_ERROR, "buffer underflow\n");
+ break;
+ }
+ stream->buffer_index -= pkt_desc->size;
+
+ stream->predecode_packet= pkt_desc->next;
+ av_freep(&pkt_desc);
+ }
+ }
+
+ return 0;
+}
+
+static int output_packet(AVFormatContext *ctx, int flush){
+ MpegMuxContext *s = ctx->priv_data;
+ AVStream *st;
+ StreamInfo *stream;
+ int i, avail_space, es_size, trailer_size;
+ int best_i= -1;
+ int best_score= INT_MIN;
+ int ignore_constraints=0;
+ int64_t scr= s->last_scr;
+ PacketDesc *timestamp_packet;
+ const int64_t max_delay= av_rescale(ctx->max_delay, 90000, AV_TIME_BASE);
+
+retry:
+ for(i=0; i<ctx->nb_streams; i++){
+ AVStream *st = ctx->streams[i];
+ StreamInfo *stream = st->priv_data;
+ const int avail_data= av_fifo_size(&stream->fifo);
+ const int space= stream->max_buffer_size - stream->buffer_index;
+ int rel_space= 1024*space / stream->max_buffer_size;
+ PacketDesc *next_pkt= stream->premux_packet;
+
+ /* 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)
+ return 0;
+ if(avail_data==0)
+ continue;
+ assert(avail_data>0);
+
+ if(space < s->packet_size && !ignore_constraints)
+ continue;
+
+ if(next_pkt && next_pkt->dts - scr > max_delay)
+ continue;
+
+ if(rel_space > best_score){
+ best_score= rel_space;
+ best_i = i;
+ avail_space= space;
+ }
+ }
+
+ if(best_i < 0){
+ int64_t best_dts= INT64_MAX;
+
+ for(i=0; i<ctx->nb_streams; i++){
+ AVStream *st = ctx->streams[i];
+ StreamInfo *stream = st->priv_data;
+ PacketDesc *pkt_desc= stream->predecode_packet;
+ if(pkt_desc && pkt_desc->dts < best_dts)
+ best_dts= pkt_desc->dts;
+ }
+
+#if 0
+ av_log(ctx, AV_LOG_DEBUG, "bumping scr, scr:%f, dts:%f\n",
+ scr/90000.0, best_dts/90000.0);
+#endif
+ if(best_dts == INT64_MAX)
+ return 0;
+
+ if(scr >= best_dts+1 && !ignore_constraints){
+ av_log(ctx, AV_LOG_ERROR, "packet too large, ignoring buffer limits to mux it\n");
+ ignore_constraints= 1;
+ }
+ scr= FFMAX(best_dts+1, scr);
+ if(remove_decoded_packets(ctx, scr) < 0)
+ return -1;
+ goto retry;
+ }
+
+ assert(best_i >= 0);
+
+ st = ctx->streams[best_i];
+ stream = st->priv_data;
+
+ assert(av_fifo_size(&stream->fifo) > 0);
+
+ assert(avail_space >= s->packet_size || ignore_constraints);
+
+ timestamp_packet= stream->premux_packet;
+ if(timestamp_packet->unwritten_size == timestamp_packet->size){
+ trailer_size= 0;
+ }else{
+ trailer_size= timestamp_packet->unwritten_size;
+ timestamp_packet= timestamp_packet->next;
+ }
+
+ if(timestamp_packet){
+//av_log(ctx, AV_LOG_DEBUG, "dts:%f pts:%f scr:%f stream:%d\n", timestamp_packet->dts/90000.0, timestamp_packet->pts/90000.0, scr/90000.0, best_i);
+ es_size= flush_packet(ctx, best_i, timestamp_packet->pts, timestamp_packet->dts, scr, trailer_size);
+ }else{
+ assert(av_fifo_size(&stream->fifo) == trailer_size);
+ es_size= flush_packet(ctx, best_i, AV_NOPTS_VALUE, AV_NOPTS_VALUE, scr, trailer_size);
+ }
+
+ if (s->is_vcd) {
+ /* Write one or more padding sectors, if necessary, to reach
+ the constant overall bitrate.*/
+ int vcd_pad_bytes;
+
+ while((vcd_pad_bytes = get_vcd_padding_size(ctx,stream->premux_packet->pts) ) >= s->packet_size){ //FIXME pts cannot be correct here
+ put_vcd_padding_sector(ctx);
+ s->last_scr += s->packet_size*90000LL / (s->mux_rate*50LL); //FIXME rounding and first few bytes of each packet
+ }
+ }
+
+ stream->buffer_index += es_size;
+ s->last_scr += s->packet_size*90000LL / (s->mux_rate*50LL); //FIXME rounding and first few bytes of each packet
+
+ while(stream->premux_packet && stream->premux_packet->unwritten_size <= es_size){
+ es_size -= stream->premux_packet->unwritten_size;
+ stream->premux_packet= stream->premux_packet->next;
+ }
+ if(es_size)
+ stream->premux_packet->unwritten_size -= es_size;
+
+ if(remove_decoded_packets(ctx, s->last_scr) < 0)
+ return -1;
+
+ return 1;
+}
+
+static int mpeg_mux_write_packet(AVFormatContext *ctx, AVPacket *pkt)
+{
+ MpegMuxContext *s = ctx->priv_data;
+ int stream_index= pkt->stream_index;
+ int size= pkt->size;
+ uint8_t *buf= pkt->data;
+ AVStream *st = ctx->streams[stream_index];
+ StreamInfo *stream = st->priv_data;
+ 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);
+
+ pts= pkt->pts;
+ dts= pkt->dts;
+
+ if(pts != AV_NOPTS_VALUE) pts += preload;
+ if(dts != AV_NOPTS_VALUE) dts += preload;
+
+//av_log(ctx, AV_LOG_DEBUG, "dts:%f pts:%f flags:%d stream:%d nopts:%d\n", dts/90000.0, pts/90000.0, pkt->flags, pkt->stream_index, pts != AV_NOPTS_VALUE);
+ if (!stream->premux_packet)
+ stream->next_packet = &stream->premux_packet;
+ *stream->next_packet=
+ pkt_desc= av_mallocz(sizeof(PacketDesc));
+ pkt_desc->pts= pts;
+ pkt_desc->dts= dts;
+ pkt_desc->unwritten_size=
+ pkt_desc->size= size;
+ if(!stream->predecode_packet)
+ stream->predecode_packet= pkt_desc;
+ stream->next_packet= &pkt_desc->next;
+
+ av_fifo_realloc(&stream->fifo, av_fifo_size(&stream->fifo) + size + 1);
+
+ if (s->is_dvd){
+ if (is_iframe && (s->packet_number == 0 || (pts - stream->vobu_start_pts >= 36000))) { // min VOBU length 0.4 seconds (mpucoder)
+ stream->bytes_to_iframe = av_fifo_size(&stream->fifo);
+ stream->align_iframe = 1;
+ stream->vobu_start_pts = pts;
+ } else {
+ stream->align_iframe = 0;
+ }
+ }
+
+ av_fifo_write(&stream->fifo, buf, size);
+
+ for(;;){
+ int ret= output_packet(ctx, 0);
+ if(ret<=0)
+ return ret;
+ }
+}
+
+static int mpeg_mux_end(AVFormatContext *ctx)
+{
+// MpegMuxContext *s = ctx->priv_data;
+ StreamInfo *stream;
+ int i;
+
+ for(;;){
+ int ret= output_packet(ctx, 1);
+ if(ret<0)
+ return ret;
+ else if(ret==0)
+ break;
+ }
+
+ /* End header according to MPEG1 systems standard. We do not write
+ it as it is usually not needed by decoders and because it
+ complicates MPEG stream concatenation. */
+ //put_be32(&ctx->pb, ISO_11172_END_CODE);
+ //put_flush_packet(&ctx->pb);
+
+ for(i=0;i<ctx->nb_streams;i++) {
+ stream = ctx->streams[i]->priv_data;
+
+ assert(av_fifo_size(&stream->fifo) == 0);
+ av_fifo_free(&stream->fifo);
+ }
+ return 0;
+}
+#endif //CONFIG_MUXERS
+
+/*********************************************/
+/* demux code */
+
+#define MAX_SYNC_SIZE 100000
+
+static int cdxa_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] == 'C' && p->buf[9] == 'D' &&
+ p->buf[10] == 'X' && p->buf[11] == 'A')
+ return AVPROBE_SCORE_MAX;
+ else
+ return 0;
+}
+
+static int mpegps_probe(AVProbeData *p)
+{
+ uint32_t code= -1;
+ int sys=0, pspack=0, priv1=0, vid=0, audio=0;
+ int i;
+ int score=0;
+
+ score = cdxa_probe(p);
+ if (score > 0) return score;
+
+ /* Search for MPEG stream */
+ for(i=0; i<p->buf_size; i++){
+ code = (code<<8) + p->buf[i];
+ if ((code & 0xffffff00) == 0x100) {
+ if(code == SYSTEM_HEADER_START_CODE) sys++;
+ else if(code == PRIVATE_STREAM_1) priv1++;
+ else if(code == PACK_START_CODE) pspack++;
+ else if((code & 0xf0) == VIDEO_ID) vid++;
+ else if((code & 0xe0) == AUDIO_ID) audio++;
+ }
+ }
+
+ if(vid || audio) /* invalid VDR files nd short PES streams */
+ score= AVPROBE_SCORE_MAX/4;
+
+//av_log(NULL, AV_LOG_ERROR, "%d %d %d %d %d\n", sys, priv1, pspack,vid, audio);
+ if(sys && sys*9 <= pspack*10)
+ return AVPROBE_SCORE_MAX/2+2; // +1 for .mpg
+ if((priv1 || vid || audio) && (priv1+vid+audio)*9 <= pspack*10)
+ return AVPROBE_SCORE_MAX/2+2; // +1 for .mpg
+ if((!!vid ^ !!audio) && (audio+vid > 1) && !sys && !pspack) /* PES stream */
+ return AVPROBE_SCORE_MAX/2+2;
+
+ //02-Penguin.flac has sys:0 priv1:0 pspack:0 vid:0 audio:1
+ return score;
+}
+
+
+typedef struct MpegDemuxContext {
+ int32_t header_state;
+ unsigned char psm_es_type[256];
+} MpegDemuxContext;
+
+static int mpegps_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ MpegDemuxContext *m = s->priv_data;
+ m->header_state = 0xff;
+ s->ctx_flags |= AVFMTCTX_NOHEADER;
+
+ /* no need to do more */
+ return 0;
+}
+
+static int64_t get_pts(ByteIOContext *pb, int c)
+{
+ int64_t pts;
+ int val;
+
+ if (c < 0)
+ c = get_byte(pb);
+ pts = (int64_t)((c >> 1) & 0x07) << 30;
+ val = get_be16(pb);
+ pts |= (int64_t)(val >> 1) << 15;
+ val = get_be16(pb);
+ pts |= (int64_t)(val >> 1);
+ return pts;
+}
+
+static int find_next_start_code(ByteIOContext *pb, int *size_ptr,
+ int32_t *header_state)
+{
+ unsigned int state, v;
+ int val, n;
+
+ state = *header_state;
+ n = *size_ptr;
+ while (n > 0) {
+ if (url_feof(pb))
+ break;
+ v = get_byte(pb);
+ n--;
+ if (state == 0x000001) {
+ state = ((state << 8) | v) & 0xffffff;
+ val = state;
+ goto found;
+ }
+ state = ((state << 8) | v) & 0xffffff;
+ }
+ val = -1;
+ found:
+ *header_state = state;
+ *size_ptr = n;
+ return val;
+}
+
+#if 0 /* unused, remove? */
+/* XXX: optimize */
+static int find_prev_start_code(ByteIOContext *pb, int *size_ptr)
+{
+ int64_t pos, pos_start;
+ int max_size, start_code;
+
+ max_size = *size_ptr;
+ pos_start = url_ftell(pb);
+
+ /* in order to go faster, we fill the buffer */
+ pos = pos_start - 16386;
+ if (pos < 0)
+ pos = 0;
+ url_fseek(pb, pos, SEEK_SET);
+ get_byte(pb);
+
+ pos = pos_start;
+ for(;;) {
+ pos--;
+ if (pos < 0 || (pos_start - pos) >= max_size) {
+ start_code = -1;
+ goto the_end;
+ }
+ url_fseek(pb, pos, SEEK_SET);
+ start_code = get_be32(pb);
+ if ((start_code & 0xffffff00) == 0x100)
+ break;
+ }
+ the_end:
+ *size_ptr = pos_start - pos;
+ return start_code;
+}
+#endif
+
+/**
+ * Extracts stream types from a program stream map
+ * According to ISO/IEC 13818-1 ('MPEG-2 Systems') table 2-35
+ *
+ * @return number of bytes occupied by PSM in the bitstream
+ */
+static long mpegps_psm_parse(MpegDemuxContext *m, ByteIOContext *pb)
+{
+ int psm_length, ps_info_length, es_map_length;
+
+ psm_length = get_be16(pb);
+ get_byte(pb);
+ get_byte(pb);
+ ps_info_length = get_be16(pb);
+
+ /* skip program_stream_info */
+ url_fskip(pb, ps_info_length);
+ es_map_length = get_be16(pb);
+
+ /* at least one es available? */
+ while (es_map_length >= 4){
+ unsigned char type = get_byte(pb);
+ unsigned char es_id = get_byte(pb);
+ uint16_t es_info_length = get_be16(pb);
+ /* remember mapping from stream id to stream type */
+ m->psm_es_type[es_id] = type;
+ /* skip program_stream_info */
+ url_fskip(pb, es_info_length);
+ es_map_length -= 4 + es_info_length;
+ }
+ get_be32(pb); /* crc32 */
+ return 2 + psm_length;
+}
+
+/* read the next PES header. Return its position in ppos
+ (if not NULL), and its start code, pts and dts.
+ */
+static int mpegps_read_pes_header(AVFormatContext *s,
+ int64_t *ppos, int *pstart_code,
+ int64_t *ppts, int64_t *pdts)
+{
+ MpegDemuxContext *m = s->priv_data;
+ int len, size, startcode, c, flags, header_len;
+ int pes_ext, ext2_len, id_ext, skip;
+ int64_t pts, dts;
+ int64_t last_sync= url_ftell(&s->pb);
+
+ error_redo:
+ url_fseek(&s->pb, last_sync, SEEK_SET);
+ redo:
+ /* next start code (should be immediately after) */
+ m->header_state = 0xff;
+ size = MAX_SYNC_SIZE;
+ 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_IO;
+ if (startcode == PACK_START_CODE)
+ goto redo;
+ if (startcode == SYSTEM_HEADER_START_CODE)
+ goto redo;
+ if (startcode == PADDING_STREAM ||
+ startcode == PRIVATE_STREAM_2) {
+ /* skip them */
+ len = get_be16(&s->pb);
+ url_fskip(&s->pb, len);
+ goto redo;
+ }
+ if (startcode == PROGRAM_STREAM_MAP) {
+ mpegps_psm_parse(m, &s->pb);
+ goto redo;
+ }
+
+ /* find matching stream */
+ if (!((startcode >= 0x1c0 && startcode <= 0x1df) ||
+ (startcode >= 0x1e0 && startcode <= 0x1ef) ||
+ (startcode == 0x1bd) || (startcode == 0x1fd)))
+ goto redo;
+ if (ppos) {
+ *ppos = url_ftell(&s->pb) - 4;
+ }
+ len = get_be16(&s->pb);
+ pts =
+ dts = AV_NOPTS_VALUE;
+ /* stuffing */
+ for(;;) {
+ if (len < 1)
+ goto error_redo;
+ c = get_byte(&s->pb);
+ len--;
+ /* XXX: for mpeg1, should test only bit 7 */
+ if (c != 0xff)
+ break;
+ }
+ if ((c & 0xc0) == 0x40) {
+ /* buffer scale & size */
+ get_byte(&s->pb);
+ c = get_byte(&s->pb);
+ len -= 2;
+ }
+ if ((c & 0xe0) == 0x20) {
+ dts = pts = get_pts(&s->pb, c);
+ len -= 4;
+ if (c & 0x10){
+ dts = get_pts(&s->pb, -1);
+ len -= 5;
+ }
+ } else if ((c & 0xc0) == 0x80) {
+ /* mpeg 2 PES */
+#if 0 /* some streams have this field set for no apparent reason */
+ if ((c & 0x30) != 0) {
+ /* Encrypted multiplex not handled */
+ goto redo;
+ }
+#endif
+ flags = get_byte(&s->pb);
+ header_len = get_byte(&s->pb);
+ len -= 2;
+ if (header_len > len)
+ goto error_redo;
+ len -= header_len;
+ if (flags & 0x80) {
+ dts = pts = get_pts(&s->pb, -1);
+ header_len -= 5;
+ if (flags & 0x40) {
+ dts = get_pts(&s->pb, -1);
+ header_len -= 5;
+ }
+ }
+ if (flags & 0x01) { /* PES extension */
+ pes_ext = get_byte(&s->pb);
+ header_len--;
+ if (pes_ext & 0x40) { /* pack header - should be zero in PS */
+ goto error_redo;
+ }
+ /* Skip PES private data, program packet sequence counter and P-STD buffer */
+ skip = (pes_ext >> 4) & 0xb;
+ skip += skip & 0x9;
+ url_fskip(&s->pb, skip);
+ header_len -= skip;
+
+ if (pes_ext & 0x01) { /* PES extension 2 */
+ ext2_len = get_byte(&s->pb);
+ header_len--;
+ if ((ext2_len & 0x7f) > 0) {
+ id_ext = get_byte(&s->pb);
+ if ((id_ext & 0x80) == 0)
+ startcode = ((startcode & 0xff) << 8) | id_ext;
+ header_len--;
+ }
+ }
+ }
+ if(header_len < 0)
+ goto error_redo;
+ url_fskip(&s->pb, header_len);
+ }
+ else if( c!= 0xf )
+ goto redo;
+
+ if (startcode == PRIVATE_STREAM_1 && !m->psm_es_type[startcode & 0xff]) {
+ startcode = get_byte(&s->pb);
+ len--;
+ if (startcode >= 0x80 && startcode <= 0xcf) {
+ /* audio: skip header */
+ get_byte(&s->pb);
+ get_byte(&s->pb);
+ get_byte(&s->pb);
+ len -= 3;
+ if (startcode >= 0xb0 && startcode <= 0xbf) {
+ /* MLP/TrueHD audio has a 4-byte header */
+ get_byte(&s->pb);
+ len--;
+ }
+ }
+ }
+ if(len<0)
+ goto error_redo;
+ if(dts != AV_NOPTS_VALUE && ppos){
+ int i;
+ for(i=0; i<s->nb_streams; i++){
+ if(startcode == s->streams[i]->id) {
+ av_add_index_entry(s->streams[i], *ppos, dts, 0, 0, AVINDEX_KEYFRAME /* FIXME keyframe? */);
+ }
+ }
+ }
+
+ *pstart_code = startcode;
+ *ppts = pts;
+ *pdts = dts;
+ return len;
+}
+
+static int mpegps_read_packet(AVFormatContext *s,
+ AVPacket *pkt)
+{
+ MpegDemuxContext *m = s->priv_data;
+ AVStream *st;
+ int len, startcode, i, type, codec_id = 0, es_type;
+ int64_t pts, dts, dummy_pos; //dummy_pos is needed for the index building to work
+
+ redo:
+ len = mpegps_read_pes_header(s, &dummy_pos, &startcode, &pts, &dts);
+ if (len < 0)
+ return len;
+
+ /* now find stream */
+ for(i=0;i<s->nb_streams;i++) {
+ st = s->streams[i];
+ if (st->id == startcode)
+ goto found;
+ }
+
+ es_type = m->psm_es_type[startcode & 0xff];
+ if(es_type > 0){
+ if(es_type == STREAM_TYPE_VIDEO_MPEG1){
+ codec_id = CODEC_ID_MPEG2VIDEO;
+ type = CODEC_TYPE_VIDEO;
+ } else if(es_type == STREAM_TYPE_VIDEO_MPEG2){
+ codec_id = CODEC_ID_MPEG2VIDEO;
+ type = CODEC_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;
+ } else if(es_type == STREAM_TYPE_AUDIO_AAC){
+ codec_id = CODEC_ID_AAC;
+ type = CODEC_TYPE_AUDIO;
+ } else if(es_type == STREAM_TYPE_VIDEO_MPEG4){
+ codec_id = CODEC_ID_MPEG4;
+ type = CODEC_TYPE_VIDEO;
+ } else if(es_type == STREAM_TYPE_VIDEO_H264){
+ codec_id = CODEC_ID_H264;
+ type = CODEC_TYPE_VIDEO;
+ } else if(es_type == STREAM_TYPE_AUDIO_AC3){
+ codec_id = CODEC_ID_AC3;
+ type = CODEC_TYPE_AUDIO;
+ } else {
+ goto skip;
+ }
+ } else if (startcode >= 0x1e0 && startcode <= 0x1ef) {
+ static const unsigned char avs_seqh[4] = { 0, 0, 1, 0xb0 };
+ unsigned char buf[8];
+ get_buffer(&s->pb, buf, 8);
+ url_fseek(&s->pb, -8, SEEK_CUR);
+ if(!memcmp(buf, avs_seqh, 4) && (buf[6] != 0 || buf[7] != 1))
+ codec_id = CODEC_ID_CAVS;
+ else
+ codec_id = CODEC_ID_MPEG2VIDEO;
+ type = CODEC_TYPE_VIDEO;
+ } else if (startcode >= 0x1c0 && startcode <= 0x1df) {
+ type = CODEC_TYPE_AUDIO;
+ codec_id = CODEC_ID_MP2;
+ } else if (startcode >= 0x80 && startcode <= 0x87) {
+ type = CODEC_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;
+ codec_id = CODEC_ID_DTS;
+ } else if (startcode >= 0xa0 && startcode <= 0xaf) {
+ type = CODEC_TYPE_AUDIO;
+ codec_id = CODEC_ID_PCM_S16BE;
+ } else if (startcode >= 0xb0 && startcode <= 0xbf) {
+ type = CODEC_TYPE_AUDIO;
+ codec_id = CODEC_ID_MLP;
+ } else if (startcode >= 0xc0 && startcode <= 0xcf) {
+ /* Used for both AC-3 and E-AC-3 in EVOB files */
+ type = CODEC_TYPE_AUDIO;
+ codec_id = CODEC_ID_AC3;
+ } else if (startcode >= 0x20 && startcode <= 0x3f) {
+ type = CODEC_TYPE_SUBTITLE;
+ codec_id = CODEC_ID_DVD_SUBTITLE;
+ } else if (startcode >= 0xfd55 && startcode <= 0xfd5f) {
+ type = CODEC_TYPE_VIDEO;
+ codec_id = CODEC_ID_VC1;
+ } else {
+ skip:
+ /* skip packet */
+ url_fskip(&s->pb, len);
+ goto redo;
+ }
+ /* no stream found: add a new stream */
+ st = av_new_stream(s, startcode);
+ if (!st)
+ goto skip;
+ st->codec->codec_type = type;
+ st->codec->codec_id = codec_id;
+ if (codec_id != CODEC_ID_PCM_S16BE)
+ st->need_parsing = 1;
+ found:
+ if(st->discard >= AVDISCARD_ALL)
+ goto skip;
+ if (startcode >= 0xa0 && startcode <= 0xaf) {
+ int b1, freq;
+
+ /* for LPCM, we just skip the header and consider it is raw
+ audio data */
+ if (len <= 3)
+ goto skip;
+ get_byte(&s->pb); /* emphasis (1), muse(1), reserved(1), frame number(5) */
+ b1 = get_byte(&s->pb); /* quant (2), freq(2), reserved(1), channels(3) */
+ get_byte(&s->pb); /* dynamic range control (0x80 = off) */
+ len -= 3;
+ freq = (b1 >> 4) & 3;
+ st->codec->sample_rate = lpcm_freq_tab[freq];
+ st->codec->channels = 1 + (b1 & 7);
+ st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * 2;
+ }
+ av_new_packet(pkt, len);
+ get_buffer(&s->pb, pkt->data, pkt->size);
+ pkt->pts = pts;
+ pkt->dts = dts;
+ pkt->stream_index = st->index;
+#if 0
+ av_log(s, AV_LOG_DEBUG, "%d: pts=%0.3f dts=%0.3f size=%d\n",
+ pkt->stream_index, pkt->pts / 90000.0, pkt->dts / 90000.0, pkt->size);
+#endif
+
+ return 0;
+}
+
+static int mpegps_read_close(AVFormatContext *s)
+{
+ return 0;
+}
+
+static int64_t mpegps_read_dts(AVFormatContext *s, int stream_index,
+ int64_t *ppos, int64_t pos_limit)
+{
+ int len, startcode;
+ int64_t pos, pts, dts;
+
+ pos = *ppos;
+#ifdef DEBUG_SEEK
+ printf("read_dts: pos=0x%"PRIx64" next=%d -> ", pos, find_next);
+#endif
+ url_fseek(&s->pb, pos, SEEK_SET);
+ for(;;) {
+ len = mpegps_read_pes_header(s, &pos, &startcode, &pts, &dts);
+ if (len < 0) {
+#ifdef DEBUG_SEEK
+ printf("none (ret=%d)\n", len);
+#endif
+ return AV_NOPTS_VALUE;
+ }
+ if (startcode == s->streams[stream_index]->id &&
+ dts != AV_NOPTS_VALUE) {
+ break;
+ }
+ url_fskip(&s->pb, len);
+ }
+#ifdef DEBUG_SEEK
+ printf("pos=0x%"PRIx64" dts=0x%"PRIx64" %0.3f\n", pos, dts, dts / 90000.0);
+#endif
+ *ppos = pos;
+ return dts;
+}
+
+#ifdef CONFIG_MPEG1SYSTEM_MUXER
+AVOutputFormat mpeg1system_muxer = {
+ "mpeg",
+ "MPEG1 System format",
+ "video/mpeg",
+ "mpg,mpeg",
+ sizeof(MpegMuxContext),
+ CODEC_ID_MP2,
+ CODEC_ID_MPEG1VIDEO,
+ mpeg_mux_init,
+ mpeg_mux_write_packet,
+ mpeg_mux_end,
+};
+#endif
+#ifdef CONFIG_MPEG1VCD_MUXER
+AVOutputFormat mpeg1vcd_muxer = {
+ "vcd",
+ "MPEG1 System format (VCD)",
+ "video/mpeg",
+ NULL,
+ sizeof(MpegMuxContext),
+ CODEC_ID_MP2,
+ CODEC_ID_MPEG1VIDEO,
+ mpeg_mux_init,
+ mpeg_mux_write_packet,
+ mpeg_mux_end,
+};
+#endif
+#ifdef CONFIG_MPEG2VOB_MUXER
+AVOutputFormat mpeg2vob_muxer = {
+ "vob",
+ "MPEG2 PS format (VOB)",
+ "video/mpeg",
+ "vob",
+ sizeof(MpegMuxContext),
+ CODEC_ID_MP2,
+ CODEC_ID_MPEG2VIDEO,
+ mpeg_mux_init,
+ mpeg_mux_write_packet,
+ mpeg_mux_end,
+};
+#endif
+
+/* Same as mpeg2vob_mux except that the pack size is 2324 */
+#ifdef CONFIG_MPEG2SVCD_MUXER
+AVOutputFormat mpeg2svcd_muxer = {
+ "svcd",
+ "MPEG2 PS format (VOB)",
+ "video/mpeg",
+ "vob",
+ sizeof(MpegMuxContext),
+ CODEC_ID_MP2,
+ CODEC_ID_MPEG2VIDEO,
+ mpeg_mux_init,
+ mpeg_mux_write_packet,
+ mpeg_mux_end,
+};
+#endif
+
+/* Same as mpeg2vob_mux except the 'is_dvd' flag is set to produce NAV pkts */
+#ifdef CONFIG_MPEG2DVD_MUXER
+AVOutputFormat mpeg2dvd_muxer = {
+ "dvd",
+ "MPEG2 PS format (DVD VOB)",
+ "video/mpeg",
+ "dvd",
+ sizeof(MpegMuxContext),
+ CODEC_ID_MP2,
+ CODEC_ID_MPEG2VIDEO,
+ mpeg_mux_init,
+ mpeg_mux_write_packet,
+ mpeg_mux_end,
+};
+#endif
+
+#ifdef CONFIG_MPEGPS_DEMUXER
+AVInputFormat mpegps_demuxer = {
+ "mpeg",
+ "MPEG PS format",
+ sizeof(MpegDemuxContext),
+ mpegps_probe,
+ mpegps_read_header,
+ mpegps_read_packet,
+ mpegps_read_close,
+ NULL, //mpegps_read_seek,
+ mpegps_read_dts,
+ .flags = AVFMT_SHOW_IDS,
+};
+#endif
diff --git a/contrib/ffmpeg/libavformat/mpegts.c b/contrib/ffmpeg/libavformat/mpegts.c
new file mode 100644
index 000000000..c466710ee
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/mpegts.c
@@ -0,0 +1,1552 @@
+/*
+ * MPEG2 transport stream (aka DVB) demuxer
+ * 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 "avformat.h"
+#include "crc.h"
+#include "mpegts.h"
+
+//#define DEBUG_SI
+//#define DEBUG_SEEK
+
+/* 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
+
+typedef struct PESContext PESContext;
+
+static PESContext* add_pes_stream(MpegTSContext *ts, int pid, int stream_type);
+static AVStream* new_pes_av_stream(PESContext *pes, uint32_t code);
+
+enum MpegTSFilterType {
+ MPEGTS_PES,
+ MPEGTS_SECTION,
+};
+
+typedef void PESCallback(void *opaque, const uint8_t *buf, int len, int is_start);
+
+typedef struct MpegTSPESFilter {
+ PESCallback *pes_cb;
+ void *opaque;
+} MpegTSPESFilter;
+
+typedef void SectionCallback(void *opaque, const uint8_t *buf, int len);
+
+typedef void SetServiceCallback(void *opaque, int ret);
+
+typedef struct MpegTSSectionFilter {
+ int section_index;
+ int section_h_size;
+ uint8_t *section_buf;
+ int check_crc:1;
+ int end_of_section_reached:1;
+ SectionCallback *section_cb;
+ void *opaque;
+} MpegTSSectionFilter;
+
+typedef struct MpegTSFilter {
+ int pid;
+ int last_cc; /* last cc code (-1 if first packet) */
+ enum MpegTSFilterType type;
+ union {
+ MpegTSPESFilter pes_filter;
+ MpegTSSectionFilter section_filter;
+ } u;
+} MpegTSFilter;
+
+typedef struct MpegTSService {
+ int running:1;
+ int sid; /**< MPEG Program Number of stream */
+ char *provider_name; /**< DVB Network name, "" if not DVB stream */
+ char *name; /**< DVB Service name, "MPEG Program [sid]" if not DVB stream*/
+} MpegTSService;
+
+struct MpegTSContext {
+ /* user data */
+ AVFormatContext *stream;
+ /** raw packet size, including FEC if present */
+ int raw_packet_size;
+ /** if true, all pids are analyzed to find streams */
+ int auto_guess;
+ int set_service_ret;
+
+ /** force raw MPEG2 transport stream output, if possible */
+ int mpeg2ts_raw;
+ /** compute exact PCR for each transport stream packet */
+ int mpeg2ts_compute_pcr;
+
+ int64_t cur_pcr; /**< used to estimate the exact PCR */
+ int pcr_incr; /**< used to estimate the exact PCR */
+ int pcr_pid; /**< used to estimate the exact PCR */
+
+ /* data needed to handle file based ts */
+ /** stop parsing loop */
+ int stop_parse;
+ /** packet containing Audio/Video data */
+ AVPacket *pkt;
+
+ /******************************************/
+ /* private mpegts data */
+ /* scan context */
+ MpegTSFilter *sdt_filter;
+ /** number of PMTs in the last PAT seen */
+ int nb_services;
+ /** list of PMTs in the last PAT seen */
+ MpegTSService **services;
+
+ /* set service context (XXX: allocated it ?) */
+ SetServiceCallback *set_service_cb;
+ void *set_service_opaque;
+ /** filter for the PAT */
+ MpegTSFilter *pat_filter;
+ /** filter for the PMT for the MPEG program number specified by req_sid */
+ MpegTSFilter *pmt_filter;
+ /** MPEG program number of stream we want to decode */
+ int req_sid;
+
+ /** filters for various streams specified by PMT + for the PAT and PMT */
+ MpegTSFilter *pids[NB_PID_MAX];
+};
+
+/**
+ * Assembles PES packets out of TS packets, and then calls the "section_cb"
+ * function when they are complete.
+ */
+static void write_section_data(AVFormatContext *s, MpegTSFilter *tss1,
+ const uint8_t *buf, int buf_size, int is_start)
+{
+ MpegTSSectionFilter *tss = &tss1->u.section_filter;
+ int len;
+
+ if (is_start) {
+ memcpy(tss->section_buf, buf, buf_size);
+ tss->section_index = buf_size;
+ tss->section_h_size = -1;
+ tss->end_of_section_reached = 0;
+ } else {
+ if (tss->end_of_section_reached)
+ return;
+ len = 4096 - tss->section_index;
+ if (buf_size < len)
+ len = buf_size;
+ memcpy(tss->section_buf + tss->section_index, buf, len);
+ tss->section_index += len;
+ }
+
+ /* compute section length if possible */
+ if (tss->section_h_size == -1 && tss->section_index >= 3) {
+ len = (((tss->section_buf[1] & 0xf) << 8) | tss->section_buf[2]) + 3;
+ if (len > 4096)
+ return;
+ tss->section_h_size = len;
+ }
+
+ if (tss->section_h_size != -1 && tss->section_index >= tss->section_h_size) {
+ tss->end_of_section_reached = 1;
+ if (!tss->check_crc ||
+ av_crc(av_crc04C11DB7, -1, tss->section_buf, tss->section_h_size) == 0)
+ tss->section_cb(tss->opaque, tss->section_buf, tss->section_h_size);
+ }
+}
+
+static MpegTSFilter *mpegts_open_section_filter(MpegTSContext *ts, unsigned int pid,
+ SectionCallback *section_cb, void *opaque,
+ int check_crc)
+
+{
+ MpegTSFilter *filter;
+ MpegTSSectionFilter *sec;
+
+#ifdef DEBUG_SI
+ av_log(ts->stream, AV_LOG_DEBUG, "Filter: pid=0x%x\n", pid);
+#endif
+ if (pid >= NB_PID_MAX || ts->pids[pid])
+ return NULL;
+ filter = av_mallocz(sizeof(MpegTSFilter));
+ if (!filter)
+ return NULL;
+ ts->pids[pid] = filter;
+ filter->type = MPEGTS_SECTION;
+ filter->pid = pid;
+ filter->last_cc = -1;
+ sec = &filter->u.section_filter;
+ sec->section_cb = section_cb;
+ sec->opaque = opaque;
+ sec->section_buf = av_malloc(MAX_SECTION_SIZE);
+ sec->check_crc = check_crc;
+ if (!sec->section_buf) {
+ av_free(filter);
+ return NULL;
+ }
+ return filter;
+}
+
+static MpegTSFilter *mpegts_open_pes_filter(MpegTSContext *ts, unsigned int pid,
+ PESCallback *pes_cb,
+ void *opaque)
+{
+ MpegTSFilter *filter;
+ MpegTSPESFilter *pes;
+
+ if (pid >= NB_PID_MAX || ts->pids[pid])
+ return NULL;
+ filter = av_mallocz(sizeof(MpegTSFilter));
+ if (!filter)
+ return NULL;
+ ts->pids[pid] = filter;
+ filter->type = MPEGTS_PES;
+ filter->pid = pid;
+ filter->last_cc = -1;
+ pes = &filter->u.pes_filter;
+ pes->pes_cb = pes_cb;
+ pes->opaque = opaque;
+ return filter;
+}
+
+static void mpegts_close_filter(MpegTSContext *ts, MpegTSFilter *filter)
+{
+ int pid;
+
+ pid = filter->pid;
+ if (filter->type == MPEGTS_SECTION)
+ av_freep(&filter->u.section_filter.section_buf);
+ else if (filter->type == MPEGTS_PES)
+ av_freep(&filter->u.pes_filter.opaque);
+
+ av_free(filter);
+ ts->pids[pid] = NULL;
+}
+
+static int analyze(const uint8_t *buf, int size, int packet_size, int *index){
+ int stat[packet_size];
+ int i;
+ int x=0;
+ int best_score=0;
+
+ memset(stat, 0, packet_size*sizeof(int));
+
+ for(x=i=0; i<size; i++){
+ if(buf[i] == 0x47){
+ stat[x]++;
+ if(stat[x] > best_score){
+ best_score= stat[x];
+ if(index) *index= x;
+ }
+ }
+
+ x++;
+ if(x == packet_size) x= 0;
+ }
+
+ return best_score;
+}
+
+/* autodetect fec presence. Must have at least 1024 bytes */
+static int get_packet_size(const uint8_t *buf, int size)
+{
+ int score, fec_score, dvhs_score;
+
+ if (size < (TS_FEC_PACKET_SIZE * 5 + 1))
+ return -1;
+
+ score = analyze(buf, size, TS_PACKET_SIZE, NULL);
+ dvhs_score = analyze(buf, size, TS_DVHS_PACKET_SIZE, NULL);
+ fec_score= analyze(buf, size, TS_FEC_PACKET_SIZE, NULL);
+// av_log(NULL, AV_LOG_DEBUG, "score: %d, dvhs_score: %d, fec_score: %d \n", score, dvhs_score, fec_score);
+
+ if (score > fec_score && score > dvhs_score) return TS_PACKET_SIZE;
+ else if(dvhs_score > score && dvhs_score > fec_score) return TS_DVHS_PACKET_SIZE;
+ else if(score < fec_score && dvhs_score < fec_score) return TS_FEC_PACKET_SIZE;
+ else return -1;
+}
+
+typedef struct SectionHeader {
+ uint8_t tid;
+ uint16_t id;
+ uint8_t version;
+ uint8_t sec_num;
+ uint8_t last_sec_num;
+} SectionHeader;
+
+static inline int get8(const uint8_t **pp, const uint8_t *p_end)
+{
+ const uint8_t *p;
+ int c;
+
+ p = *pp;
+ if (p >= p_end)
+ return -1;
+ c = *p++;
+ *pp = p;
+ return c;
+}
+
+static inline int get16(const uint8_t **pp, const uint8_t *p_end)
+{
+ const uint8_t *p;
+ int c;
+
+ p = *pp;
+ if ((p + 1) >= p_end)
+ return -1;
+ c = (p[0] << 8) | p[1];
+ p += 2;
+ *pp = p;
+ return c;
+}
+
+/* read and allocate a DVB string preceeded by its length */
+static char *getstr8(const uint8_t **pp, const uint8_t *p_end)
+{
+ int len;
+ const uint8_t *p;
+ char *str;
+
+ p = *pp;
+ len = get8(&p, p_end);
+ if (len < 0)
+ return NULL;
+ if ((p + len) > p_end)
+ return NULL;
+ str = av_malloc(len + 1);
+ if (!str)
+ return NULL;
+ memcpy(str, p, len);
+ str[len] = '\0';
+ p += len;
+ *pp = p;
+ return str;
+}
+
+static int parse_section_header(SectionHeader *h,
+ const uint8_t **pp, const uint8_t *p_end)
+{
+ int val;
+
+ val = get8(pp, p_end);
+ if (val < 0)
+ return -1;
+ h->tid = val;
+ *pp += 2;
+ val = get16(pp, p_end);
+ if (val < 0)
+ return -1;
+ h->id = val;
+ val = get8(pp, p_end);
+ if (val < 0)
+ return -1;
+ h->version = (val >> 1) & 0x1f;
+ val = get8(pp, p_end);
+ if (val < 0)
+ return -1;
+ h->sec_num = val;
+ val = get8(pp, p_end);
+ if (val < 0)
+ return -1;
+ h->last_sec_num = val;
+ return 0;
+}
+
+static MpegTSService *new_service(MpegTSContext *ts, int sid,
+ char *provider_name, char *name)
+{
+ MpegTSService *service;
+
+#ifdef DEBUG_SI
+ av_log(ts->stream, AV_LOG_DEBUG, "new_service: "
+ "sid=0x%04x provider='%s' name='%s'\n",
+ sid, provider_name, name);
+#endif
+
+ service = av_mallocz(sizeof(MpegTSService));
+ if (!service)
+ return NULL;
+ service->sid = sid;
+ service->provider_name = provider_name;
+ service->name = name;
+ dynarray_add(&ts->services, &ts->nb_services, service);
+ return service;
+}
+
+static void pmt_cb(void *opaque, const uint8_t *section, int section_len)
+{
+ MpegTSContext *ts = opaque;
+ SectionHeader h1, *h = &h1;
+ PESContext *pes;
+ AVStream *st;
+ const uint8_t *p, *p_end, *desc_list_end, *desc_end;
+ int program_info_length, pcr_pid, pid, stream_type;
+ int desc_list_len, desc_len, desc_tag;
+ int comp_page = 0, anc_page = 0; /* initialize to kill warnings */
+ char language[4];
+
+#ifdef DEBUG_SI
+ av_log(ts->stream, AV_LOG_DEBUG, "PMT: len %i\n", section_len);
+ av_hex_dump_log(ts->stream, AV_LOG_DEBUG, (uint8_t *)section, section_len);
+#endif
+ p_end = section + section_len - 4;
+ p = section;
+ if (parse_section_header(h, &p, p_end) < 0)
+ return;
+#ifdef DEBUG_SI
+ av_log(ts->stream, AV_LOG_DEBUG, "sid=0x%x sec_num=%d/%d\n",
+ h->id, h->sec_num, h->last_sec_num);
+#endif
+ if (h->tid != PMT_TID || (ts->req_sid >= 0 && h->id != ts->req_sid) )
+ return;
+
+ pcr_pid = get16(&p, p_end) & 0x1fff;
+ if (pcr_pid < 0)
+ return;
+ ts->pcr_pid = pcr_pid;
+#ifdef DEBUG_SI
+ av_log(ts->stream, AV_LOG_DEBUG, "pcr_pid=0x%x\n", pcr_pid);
+#endif
+ program_info_length = get16(&p, p_end) & 0xfff;
+ if (program_info_length < 0)
+ return;
+ p += program_info_length;
+ if (p >= p_end)
+ return;
+ for(;;) {
+ language[0] = 0;
+ st = 0;
+ stream_type = get8(&p, p_end);
+ if (stream_type < 0)
+ break;
+ pid = get16(&p, p_end) & 0x1fff;
+ if (pid < 0)
+ break;
+ desc_list_len = get16(&p, p_end) & 0xfff;
+ if (desc_list_len < 0)
+ break;
+ desc_list_end = p + desc_list_len;
+ if (desc_list_end > p_end)
+ break;
+ for(;;) {
+ desc_tag = get8(&p, desc_list_end);
+ if (desc_tag < 0)
+ break;
+ if (stream_type == STREAM_TYPE_PRIVATE_DATA) {
+ if((desc_tag == 0x6A) || (desc_tag == 0x7A)) {
+ /*assume DVB AC-3 Audio*/
+ stream_type = STREAM_TYPE_AUDIO_AC3;
+ } else if(desc_tag == 0x7B) {
+ /* DVB DTS audio */
+ stream_type = STREAM_TYPE_AUDIO_DTS;
+ }
+ }
+ desc_len = get8(&p, desc_list_end);
+ desc_end = p + desc_len;
+ if (desc_end > desc_list_end)
+ break;
+#ifdef DEBUG_SI
+ av_log(ts->stream, AV_LOG_DEBUG, "tag: 0x%02x len=%d\n",
+ desc_tag, desc_len);
+#endif
+ switch(desc_tag) {
+ case DVB_SUBT_DESCID:
+ if (stream_type == STREAM_TYPE_PRIVATE_DATA)
+ stream_type = STREAM_TYPE_SUBTITLE_DVB;
+
+ language[0] = get8(&p, desc_end);
+ language[1] = get8(&p, desc_end);
+ language[2] = get8(&p, desc_end);
+ language[3] = 0;
+ get8(&p, desc_end);
+ comp_page = get16(&p, desc_end);
+ anc_page = get16(&p, desc_end);
+
+ 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;
+ break;
+ default:
+ break;
+ }
+ p = desc_end;
+ }
+ p = desc_list_end;
+
+#ifdef DEBUG_SI
+ av_log(ts->stream, AV_LOG_DEBUG, "stream_type=%d pid=0x%x\n",
+ stream_type, pid);
+#endif
+
+ /* now create ffmpeg stream */
+ switch(stream_type) {
+ case STREAM_TYPE_AUDIO_MPEG1:
+ case STREAM_TYPE_AUDIO_MPEG2:
+ case STREAM_TYPE_VIDEO_MPEG1:
+ case STREAM_TYPE_VIDEO_MPEG2:
+ case STREAM_TYPE_VIDEO_MPEG4:
+ case STREAM_TYPE_VIDEO_H264:
+ case STREAM_TYPE_VIDEO_VC1:
+ case STREAM_TYPE_AUDIO_AAC:
+ case STREAM_TYPE_AUDIO_AC3:
+ case STREAM_TYPE_AUDIO_DTS:
+ case STREAM_TYPE_SUBTITLE_DVB:
+ pes = add_pes_stream(ts, pid, stream_type);
+ if (pes)
+ st = new_pes_av_stream(pes, 0);
+ break;
+ default:
+ /* we ignore the other streams */
+ break;
+ }
+
+ if (st) {
+ if (language[0] != 0) {
+ st->language[0] = language[0];
+ st->language[1] = language[1];
+ st->language[2] = language[2];
+ st->language[3] = language[3];
+ }
+
+ if (stream_type == STREAM_TYPE_SUBTITLE_DVB) {
+ st->codec->sub_id = (anc_page << 16) | comp_page;
+ }
+ }
+ }
+ /* all parameters are there */
+ ts->set_service_cb(ts->set_service_opaque, 0);
+ mpegts_close_filter(ts, ts->pmt_filter);
+ ts->pmt_filter = NULL;
+}
+
+static void pat_cb(void *opaque, const uint8_t *section, int section_len)
+{
+ MpegTSContext *ts = opaque;
+ SectionHeader h1, *h = &h1;
+ const uint8_t *p, *p_end;
+ int sid, pmt_pid;
+
+#ifdef DEBUG_SI
+ av_log(ts->stream, AV_LOG_DEBUG, "PAT:\n");
+ av_hex_dump_log(ts->stream, AV_LOG_DEBUG, (uint8_t *)section, section_len);
+#endif
+ p_end = section + section_len - 4;
+ p = section;
+ if (parse_section_header(h, &p, p_end) < 0)
+ return;
+ if (h->tid != PAT_TID)
+ return;
+
+ for(;;) {
+ sid = get16(&p, p_end);
+ if (sid < 0)
+ break;
+ pmt_pid = get16(&p, p_end) & 0x1fff;
+ if (pmt_pid < 0)
+ break;
+#ifdef DEBUG_SI
+ av_log(ts->stream, AV_LOG_DEBUG, "sid=0x%x pid=0x%x\n", sid, pmt_pid);
+#endif
+ if (sid == 0x0000) {
+ /* NIT info */
+ } else {
+ if (ts->req_sid == sid) {
+ ts->pmt_filter = mpegts_open_section_filter(ts, pmt_pid,
+ pmt_cb, ts, 1);
+ goto found;
+ }
+ }
+ }
+ /* not found */
+ ts->set_service_cb(ts->set_service_opaque, -1);
+
+ found:
+ mpegts_close_filter(ts, ts->pat_filter);
+ ts->pat_filter = NULL;
+}
+
+/* add all services found in the PAT */
+static void pat_scan_cb(void *opaque, const uint8_t *section, int section_len)
+{
+ MpegTSContext *ts = opaque;
+ SectionHeader h1, *h = &h1;
+ const uint8_t *p, *p_end;
+ int sid, pmt_pid;
+ char *provider_name, *name;
+ char buf[256];
+
+#ifdef DEBUG_SI
+ av_log(ts->stream, AV_LOG_DEBUG, "PAT:\n");
+ av_hex_dump_log(ts->stream, AV_LOG_DEBUG, (uint8_t *)section, section_len);
+#endif
+ p_end = section + section_len - 4;
+ p = section;
+ if (parse_section_header(h, &p, p_end) < 0)
+ return;
+ if (h->tid != PAT_TID)
+ return;
+
+ for(;;) {
+ sid = get16(&p, p_end);
+ if (sid < 0)
+ break;
+ pmt_pid = get16(&p, p_end) & 0x1fff;
+ if (pmt_pid < 0)
+ break;
+#ifdef DEBUG_SI
+ av_log(ts->stream, AV_LOG_DEBUG, "sid=0x%x pid=0x%x\n", sid, pmt_pid);
+#endif
+ if (sid == 0x0000) {
+ /* NIT info */
+ } else {
+ /* add the service with a dummy name */
+ snprintf(buf, sizeof(buf), "Service %x\n", sid);
+ name = av_strdup(buf);
+ provider_name = av_strdup("");
+ if (name && provider_name) {
+ new_service(ts, sid, provider_name, name);
+ } else {
+ av_freep(&name);
+ av_freep(&provider_name);
+ }
+ }
+ }
+ ts->stop_parse = 1;
+
+ /* remove filter */
+ mpegts_close_filter(ts, ts->pat_filter);
+ ts->pat_filter = NULL;
+}
+
+static void mpegts_set_service(MpegTSContext *ts, int sid,
+ SetServiceCallback *set_service_cb, void *opaque)
+{
+ ts->set_service_cb = set_service_cb;
+ ts->set_service_opaque = opaque;
+ ts->req_sid = sid;
+ ts->pat_filter = mpegts_open_section_filter(ts, PAT_PID,
+ pat_cb, ts, 1);
+}
+
+static void sdt_cb(void *opaque, const uint8_t *section, int section_len)
+{
+ MpegTSContext *ts = opaque;
+ SectionHeader h1, *h = &h1;
+ const uint8_t *p, *p_end, *desc_list_end, *desc_end;
+ int onid, val, sid, desc_list_len, desc_tag, desc_len, service_type;
+ char *name, *provider_name;
+
+#ifdef DEBUG_SI
+ av_log(ts->stream, AV_LOG_DEBUG, "SDT:\n");
+ av_hex_dump_log(ts->stream, AV_LOG_DEBUG, (uint8_t *)section, section_len);
+#endif
+
+ p_end = section + section_len - 4;
+ p = section;
+ if (parse_section_header(h, &p, p_end) < 0)
+ return;
+ if (h->tid != SDT_TID)
+ return;
+ onid = get16(&p, p_end);
+ if (onid < 0)
+ return;
+ val = get8(&p, p_end);
+ if (val < 0)
+ return;
+ for(;;) {
+ sid = get16(&p, p_end);
+ if (sid < 0)
+ break;
+ val = get8(&p, p_end);
+ if (val < 0)
+ break;
+ desc_list_len = get16(&p, p_end) & 0xfff;
+ if (desc_list_len < 0)
+ break;
+ desc_list_end = p + desc_list_len;
+ if (desc_list_end > p_end)
+ break;
+ for(;;) {
+ desc_tag = get8(&p, desc_list_end);
+ if (desc_tag < 0)
+ break;
+ desc_len = get8(&p, desc_list_end);
+ desc_end = p + desc_len;
+ if (desc_end > desc_list_end)
+ break;
+#ifdef DEBUG_SI
+ av_log(ts->stream, AV_LOG_DEBUG, "tag: 0x%02x len=%d\n",
+ desc_tag, desc_len);
+#endif
+ switch(desc_tag) {
+ case 0x48:
+ service_type = get8(&p, p_end);
+ if (service_type < 0)
+ break;
+ provider_name = getstr8(&p, p_end);
+ if (!provider_name)
+ break;
+ name = getstr8(&p, p_end);
+ if (!name)
+ break;
+ new_service(ts, sid, provider_name, name);
+ break;
+ default:
+ break;
+ }
+ p = desc_end;
+ }
+ p = desc_list_end;
+ }
+ ts->stop_parse = 1;
+
+ /* remove filter */
+ mpegts_close_filter(ts, ts->sdt_filter);
+ ts->sdt_filter = NULL;
+}
+
+/* scan services in a transport stream by looking at the SDT */
+static void mpegts_scan_sdt(MpegTSContext *ts)
+{
+ ts->sdt_filter = mpegts_open_section_filter(ts, SDT_PID,
+ sdt_cb, ts, 1);
+}
+
+/* scan services in a transport stream by looking at the PAT (better
+ than nothing !) */
+static void mpegts_scan_pat(MpegTSContext *ts)
+{
+ ts->pat_filter = mpegts_open_section_filter(ts, PAT_PID,
+ pat_scan_cb, ts, 1);
+}
+
+/* TS stream handling */
+
+enum MpegTSState {
+ MPEGTS_HEADER = 0,
+ MPEGTS_PESHEADER_FILL,
+ MPEGTS_PAYLOAD,
+ MPEGTS_SKIP,
+};
+
+/* enough for PES header + length */
+#define PES_START_SIZE 9
+#define MAX_PES_HEADER_SIZE (9 + 255)
+
+struct PESContext {
+ int pid;
+ int stream_type;
+ MpegTSContext *ts;
+ AVFormatContext *stream;
+ AVStream *st;
+ enum MpegTSState state;
+ /* used to get the format */
+ int data_index;
+ int total_size;
+ int pes_header_size;
+ int64_t pts, dts;
+ uint8_t header[MAX_PES_HEADER_SIZE];
+};
+
+static int64_t get_pts(const uint8_t *p)
+{
+ int64_t pts;
+ int val;
+
+ pts = (int64_t)((p[0] >> 1) & 0x07) << 30;
+ val = (p[1] << 8) | p[2];
+ pts |= (int64_t)(val >> 1) << 15;
+ val = (p[3] << 8) | p[4];
+ pts |= (int64_t)(val >> 1);
+ return pts;
+}
+
+/* return non zero if a packet could be constructed */
+static void mpegts_push_data(void *opaque,
+ const uint8_t *buf, int buf_size, int is_start)
+{
+ PESContext *pes = opaque;
+ MpegTSContext *ts = pes->ts;
+ const uint8_t *p;
+ int len, code;
+
+ if (is_start) {
+ pes->state = MPEGTS_HEADER;
+ pes->data_index = 0;
+ }
+ 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;
+ if (!((code >= 0x1c0 && code <= 0x1df) ||
+ (code >= 0x1e0 && code <= 0x1ef) ||
+ (code == 0x1bd) || (code == 0x1fd)))
+ goto skip;
+ if (!pes->st) {
+ /* allocate stream */
+ new_pes_av_stream(pes, code);
+ }
+ pes->state = MPEGTS_PESHEADER_FILL;
+ pes->total_size = (pes->header[4] << 8) | pes->header[5];
+ /* NOTE: a zero total size means the PES size is
+ unbounded */
+ if (pes->total_size)
+ pes->total_size += 6;
+ pes->pes_header_size = pes->header[8] + 9;
+ } else {
+ /* otherwise, it should be a table */
+ /* skip packet */
+ skip:
+ pes->state = MPEGTS_SKIP;
+ continue;
+ }
+ }
+ break;
+ /**********************************************/
+ /* PES packing parsing */
+ case MPEGTS_PESHEADER_FILL:
+ len = pes->pes_header_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->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->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;
+ }
+ break;
+ case MPEGTS_PAYLOAD:
+ if (pes->total_size) {
+ len = pes->total_size - pes->data_index;
+ if (len > buf_size)
+ len = buf_size;
+ } else {
+ len = buf_size;
+ }
+ if (len > 0) {
+ AVPacket *pkt = ts->pkt;
+ if (pes->st && av_new_packet(pkt, len) == 0) {
+ memcpy(pkt->data, p, len);
+ pkt->stream_index = pes->st->index;
+ pkt->pts = pes->pts;
+ pkt->dts = pes->dts;
+ /* reset pts values */
+ pes->pts = AV_NOPTS_VALUE;
+ pes->dts = AV_NOPTS_VALUE;
+ ts->stop_parse = 1;
+ return;
+ }
+ }
+ buf_size = 0;
+ break;
+ case MPEGTS_SKIP:
+ buf_size = 0;
+ break;
+ }
+ }
+}
+
+static AVStream* new_pes_av_stream(PESContext *pes, uint32_t code)
+{
+ AVStream *st;
+ int codec_type, codec_id;
+
+ switch(pes->stream_type){
+ case STREAM_TYPE_AUDIO_MPEG1:
+ case STREAM_TYPE_AUDIO_MPEG2:
+ codec_type = CODEC_TYPE_AUDIO;
+ codec_id = CODEC_ID_MP3;
+ break;
+ case STREAM_TYPE_VIDEO_MPEG1:
+ case STREAM_TYPE_VIDEO_MPEG2:
+ codec_type = CODEC_TYPE_VIDEO;
+ codec_id = CODEC_ID_MPEG2VIDEO;
+ break;
+ case STREAM_TYPE_VIDEO_MPEG4:
+ codec_type = CODEC_TYPE_VIDEO;
+ codec_id = CODEC_ID_MPEG4;
+ break;
+ case STREAM_TYPE_VIDEO_H264:
+ codec_type = CODEC_TYPE_VIDEO;
+ codec_id = CODEC_ID_H264;
+ break;
+ case STREAM_TYPE_VIDEO_VC1:
+ codec_type = CODEC_TYPE_VIDEO;
+ codec_id = CODEC_ID_VC1;
+ break;
+ case STREAM_TYPE_AUDIO_AAC:
+ codec_type = CODEC_TYPE_AUDIO;
+ codec_id = CODEC_ID_AAC;
+ break;
+ case STREAM_TYPE_AUDIO_AC3:
+ codec_type = CODEC_TYPE_AUDIO;
+ codec_id = CODEC_ID_AC3;
+ break;
+ case STREAM_TYPE_AUDIO_DTS:
+ codec_type = CODEC_TYPE_AUDIO;
+ codec_id = CODEC_ID_DTS;
+ break;
+ case STREAM_TYPE_SUBTITLE_DVB:
+ codec_type = CODEC_TYPE_SUBTITLE;
+ codec_id = CODEC_ID_DVB_SUBTITLE;
+ break;
+ default:
+ if (code >= 0x1c0 && code <= 0x1df) {
+ codec_type = CODEC_TYPE_AUDIO;
+ codec_id = CODEC_ID_MP2;
+ } else if (code == 0x1bd) {
+ codec_type = CODEC_TYPE_AUDIO;
+ codec_id = CODEC_ID_AC3;
+ } else {
+ codec_type = CODEC_TYPE_VIDEO;
+ codec_id = CODEC_ID_MPEG1VIDEO;
+ }
+ break;
+ }
+ st = av_new_stream(pes->stream, pes->pid);
+ if (st) {
+ av_set_pts_info(st, 33, 1, 90000);
+ st->priv_data = pes;
+ st->codec->codec_type = codec_type;
+ st->codec->codec_id = codec_id;
+ st->need_parsing = 1;
+ pes->st = st;
+ }
+ return st;
+}
+
+
+static PESContext *add_pes_stream(MpegTSContext *ts, int 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->stream_type = stream_type;
+ 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 void handle_packet(MpegTSContext *ts, const uint8_t *packet)
+{
+ AVFormatContext *s = ts->stream;
+ MpegTSFilter *tss;
+ int len, pid, cc, cc_ok, afc, is_start;
+ const uint8_t *p, *p_end;
+
+ pid = ((packet[1] & 0x1f) << 8) | packet[2];
+ is_start = packet[1] & 0x40;
+ tss = ts->pids[pid];
+ if (ts->auto_guess && tss == NULL && is_start) {
+ add_pes_stream(ts, pid, 0);
+ tss = ts->pids[pid];
+ }
+ if (!tss)
+ return;
+
+ /* continuity check (currently not used) */
+ cc = (packet[3] & 0xf);
+ cc_ok = (tss->last_cc < 0) || ((((tss->last_cc + 1) & 0x0f) == cc));
+ tss->last_cc = cc;
+
+ /* skip adaptation field */
+ afc = (packet[3] >> 4) & 3;
+ p = packet + 4;
+ if (afc == 0) /* reserved value */
+ return;
+ if (afc == 2) /* adaptation field only */
+ return;
+ if (afc == 3) {
+ /* skip adapation field */
+ p += p[0] + 1;
+ }
+ /* if past the end of packet, ignore */
+ p_end = packet + TS_PACKET_SIZE;
+ if (p >= p_end)
+ return;
+
+ if (tss->type == MPEGTS_SECTION) {
+ if (is_start) {
+ /* pointer field present */
+ len = *p++;
+ if (p + len > p_end)
+ return;
+ if (len && cc_ok) {
+ /* write remaining section bytes */
+ write_section_data(s, tss,
+ p, len, 0);
+ /* check whether filter has been closed */
+ if (!ts->pids[pid])
+ return;
+ }
+ p += len;
+ if (p < p_end) {
+ write_section_data(s, tss,
+ p, p_end - p, 1);
+ }
+ } else {
+ if (cc_ok) {
+ write_section_data(s, tss,
+ p, p_end - p, 0);
+ }
+ }
+ } else {
+ tss->u.pes_filter.pes_cb(tss->u.pes_filter.opaque,
+ p, p_end - p, is_start);
+ }
+}
+
+/* XXX: try to find a better synchro over several packets (use
+ get_packet_size() ?) */
+static int mpegts_resync(ByteIOContext *pb)
+{
+ int c, i;
+
+ for(i = 0;i < MAX_RESYNC_SIZE; i++) {
+ c = url_fgetc(pb);
+ if (c < 0)
+ return -1;
+ if (c == 0x47) {
+ url_fseek(pb, -1, SEEK_CUR);
+ return 0;
+ }
+ }
+ /* 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)
+{
+ int skip, len;
+
+ for(;;) {
+ len = get_buffer(pb, buf, TS_PACKET_SIZE);
+ if (len != TS_PACKET_SIZE)
+ return AVERROR_IO;
+ /* check paquet sync byte */
+ 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;
+ else
+ continue;
+ } else {
+ skip = raw_packet_size - TS_PACKET_SIZE;
+ if (skip > 0)
+ url_fskip(pb, skip);
+ break;
+ }
+ }
+ return 0;
+}
+
+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;
+
+ ts->stop_parse = 0;
+ packet_num = 0;
+ for(;;) {
+ if (ts->stop_parse)
+ break;
+ packet_num++;
+ if (nb_packets != 0 && packet_num >= nb_packets)
+ break;
+ ret = read_packet(pb, packet, ts->raw_packet_size);
+ if (ret != 0)
+ return ret;
+ handle_packet(ts, packet);
+ }
+ return 0;
+}
+
+static int mpegts_probe(AVProbeData *p)
+{
+#if 1
+ const int size= p->buf_size;
+ int score, fec_score, dvhs_score;
+#define CHECK_COUNT 10
+
+ if (size < (TS_FEC_PACKET_SIZE * CHECK_COUNT))
+ return -1;
+
+ score = analyze(p->buf, TS_PACKET_SIZE *CHECK_COUNT, TS_PACKET_SIZE, NULL);
+ dvhs_score = analyze(p->buf, TS_DVHS_PACKET_SIZE *CHECK_COUNT, TS_DVHS_PACKET_SIZE, NULL);
+ fec_score= analyze(p->buf, TS_FEC_PACKET_SIZE*CHECK_COUNT, TS_FEC_PACKET_SIZE, NULL);
+// av_log(NULL, AV_LOG_DEBUG, "score: %d, dvhs_score: %d, fec_score: %d \n", score, dvhs_score, fec_score);
+
+// we need a clear definition for the returned score otherwise things will become messy sooner or later
+ if (score > fec_score && score > dvhs_score && score > 6) return AVPROBE_SCORE_MAX + score - CHECK_COUNT;
+ else if(dvhs_score > score && dvhs_score > fec_score && dvhs_score > 6) return AVPROBE_SCORE_MAX + dvhs_score - CHECK_COUNT;
+ else if( fec_score > 6) return AVPROBE_SCORE_MAX + fec_score - CHECK_COUNT;
+ else return -1;
+#else
+ /* only use the extension for safer guess */
+ if (match_ext(p->filename, "ts"))
+ return AVPROBE_SCORE_MAX;
+ else
+ return 0;
+#endif
+}
+
+static void set_service_cb(void *opaque, int ret)
+{
+ MpegTSContext *ts = opaque;
+ ts->set_service_ret = ret;
+ ts->stop_parse = 1;
+}
+
+/* return the 90 kHz PCR and the extension for the 27 MHz PCR. return
+ (-1) if not available */
+static int parse_pcr(int64_t *ppcr_high, int *ppcr_low,
+ const uint8_t *packet)
+{
+ int afc, len, flags;
+ const uint8_t *p;
+ unsigned int v;
+
+ afc = (packet[3] >> 4) & 3;
+ if (afc <= 1)
+ return -1;
+ p = packet + 4;
+ len = p[0];
+ p++;
+ if (len == 0)
+ return -1;
+ flags = *p++;
+ len--;
+ if (!(flags & 0x10))
+ return -1;
+ if (len < 6)
+ return -1;
+ v = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
+ *ppcr_high = ((int64_t)v << 1) | (p[4] >> 7);
+ *ppcr_low = ((p[4] & 1) << 8) | p[5];
+ return 0;
+}
+
+static int mpegts_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ MpegTSContext *ts = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ uint8_t buf[1024];
+ int len, sid, i;
+ int64_t pos;
+ MpegTSService *service;
+
+ if (ap) {
+ ts->mpeg2ts_raw = ap->mpeg2ts_raw;
+ ts->mpeg2ts_compute_pcr = ap->mpeg2ts_compute_pcr;
+ }
+
+ /* read the first 1024 bytes to get packet size */
+ pos = url_ftell(pb);
+ len = get_buffer(pb, buf, sizeof(buf));
+ if (len != sizeof(buf))
+ goto fail;
+ ts->raw_packet_size = get_packet_size(buf, sizeof(buf));
+ if (ts->raw_packet_size <= 0)
+ goto fail;
+ ts->stream = s;
+ ts->auto_guess = 0;
+
+goto_auto_guess:
+ if (!ts->mpeg2ts_raw) {
+ /* normal demux */
+
+ if (!ts->auto_guess) {
+ ts->set_service_ret = -1;
+
+ /* first do a scaning to get all the services */
+ url_fseek(pb, pos, SEEK_SET);
+ mpegts_scan_sdt(ts);
+
+ handle_packets(ts, s->probesize);
+
+ if (ts->nb_services <= 0) {
+ /* no SDT found, we try to look at the PAT */
+
+ /* First remove the SDT filters from each PID */
+ int i;
+ for (i=0; i < NB_PID_MAX; i++) {
+ if (ts->pids[i])
+ mpegts_close_filter(ts, ts->pids[i]);
+ }
+ url_fseek(pb, pos, SEEK_SET);
+ mpegts_scan_pat(ts);
+
+ handle_packets(ts, s->probesize);
+ }
+
+ if (ts->nb_services <= 0) {
+ /* raw transport stream */
+ ts->auto_guess = 1;
+ s->ctx_flags |= AVFMTCTX_NOHEADER;
+ goto do_pcr;
+ }
+
+ /* tune to first service found */
+ for(i=0; i<ts->nb_services && ts->set_service_ret; i++){
+ service = ts->services[i];
+ sid = service->sid;
+#ifdef DEBUG_SI
+ av_log(ts->stream, AV_LOG_DEBUG, "tuning to '%s'\n", service->name);
+#endif
+
+ /* now find the info for the first service if we found any,
+ otherwise try to filter all PATs */
+
+ url_fseek(pb, pos, SEEK_SET);
+ mpegts_set_service(ts, sid, set_service_cb, ts);
+
+ handle_packets(ts, s->probesize);
+ }
+ /* if could not find service, exit */
+
+ if (ts->set_service_ret != 0) {
+ if(ts->auto_guess)
+ return -1;
+ else {
+ //let's retry with auto_guess set
+ ts->auto_guess = 1;
+ goto goto_auto_guess;
+ }
+ }
+
+#ifdef DEBUG_SI
+ av_log(ts->stream, AV_LOG_DEBUG, "tuning done\n");
+#endif
+ }
+ s->ctx_flags |= AVFMTCTX_NOHEADER;
+ } else {
+ AVStream *st;
+ int pcr_pid, pid, nb_packets, nb_pcrs, ret, pcr_l;
+ int64_t pcrs[2], pcr_h;
+ int packet_count[2];
+ uint8_t packet[TS_PACKET_SIZE];
+
+ /* only read packets */
+
+ do_pcr:
+ st = av_new_stream(s, 0);
+ if (!st)
+ goto fail;
+ av_set_pts_info(st, 60, 1, 27000000);
+ st->codec->codec_type = CODEC_TYPE_DATA;
+ st->codec->codec_id = CODEC_ID_MPEG2TS;
+
+ /* we iterate until we find two PCRs to estimate the bitrate */
+ pcr_pid = -1;
+ nb_pcrs = 0;
+ nb_packets = 0;
+ for(;;) {
+ ret = read_packet(&s->pb, packet, ts->raw_packet_size);
+ if (ret < 0)
+ return -1;
+ pid = ((packet[1] & 0x1f) << 8) | packet[2];
+ if ((pcr_pid == -1 || pcr_pid == pid) &&
+ parse_pcr(&pcr_h, &pcr_l, packet) == 0) {
+ pcr_pid = pid;
+ packet_count[nb_pcrs] = nb_packets;
+ pcrs[nb_pcrs] = pcr_h * 300 + pcr_l;
+ nb_pcrs++;
+ if (nb_pcrs >= 2)
+ break;
+ }
+ nb_packets++;
+ }
+ ts->pcr_pid = pcr_pid;
+
+ /* NOTE1: the bitrate is computed without the FEC */
+ /* NOTE2: it is only the bitrate of the start of the stream */
+ ts->pcr_incr = (pcrs[1] - pcrs[0]) / (packet_count[1] - packet_count[0]);
+ ts->cur_pcr = pcrs[0] - ts->pcr_incr * packet_count[0];
+ s->bit_rate = (TS_PACKET_SIZE * 8) * 27e6 / ts->pcr_incr;
+ st->codec->bit_rate = s->bit_rate;
+ st->start_time = ts->cur_pcr;
+#if 0
+ av_log(ts->stream, AV_LOG_DEBUG, "start=%0.3f pcr=%0.3f incr=%d\n",
+ st->start_time / 1000000.0, pcrs[0] / 27e6, ts->pcr_incr);
+#endif
+ }
+
+ url_fseek(pb, pos, SEEK_SET);
+ return 0;
+ fail:
+ return -1;
+}
+
+#define MAX_PACKET_READAHEAD ((128 * 1024) / 188)
+
+static int mpegts_raw_read_packet(AVFormatContext *s,
+ AVPacket *pkt)
+{
+ MpegTSContext *ts = s->priv_data;
+ int ret, i;
+ int64_t pcr_h, next_pcr_h, pos;
+ int pcr_l, next_pcr_l;
+ uint8_t pcr_buf[12];
+
+ 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);
+ if (ret < 0) {
+ av_free_packet(pkt);
+ return ret;
+ }
+ if (ts->mpeg2ts_compute_pcr) {
+ /* compute exact PCR for each packet */
+ if (parse_pcr(&pcr_h, &pcr_l, pkt->data) == 0) {
+ /* we read the next PCR (XXX: optimize it by using a bigger buffer */
+ pos = url_ftell(&s->pb);
+ for(i = 0; i < MAX_PACKET_READAHEAD; i++) {
+ url_fseek(&s->pb, pos + i * ts->raw_packet_size, SEEK_SET);
+ get_buffer(&s->pb, pcr_buf, 12);
+ if (parse_pcr(&next_pcr_h, &next_pcr_l, pcr_buf) == 0) {
+ /* XXX: not precise enough */
+ ts->pcr_incr = ((next_pcr_h - pcr_h) * 300 + (next_pcr_l - pcr_l)) /
+ (i + 1);
+ break;
+ }
+ }
+ url_fseek(&s->pb, pos, SEEK_SET);
+ /* no next PCR found: we use previous increment */
+ ts->cur_pcr = pcr_h * 300 + pcr_l;
+ }
+ pkt->pts = ts->cur_pcr;
+ pkt->duration = ts->pcr_incr;
+ ts->cur_pcr += ts->pcr_incr;
+ }
+ pkt->stream_index = 0;
+ return 0;
+}
+
+static int mpegts_read_packet(AVFormatContext *s,
+ AVPacket *pkt)
+{
+ MpegTSContext *ts = s->priv_data;
+
+ if (!ts->mpeg2ts_raw) {
+ ts->pkt = pkt;
+ return handle_packets(ts, 0);
+ } else {
+ return mpegts_raw_read_packet(s, pkt);
+ }
+}
+
+static int mpegts_read_close(AVFormatContext *s)
+{
+ MpegTSContext *ts = s->priv_data;
+ int i;
+ for(i=0;i<NB_PID_MAX;i++)
+ if (ts->pids[i]) mpegts_close_filter(ts, ts->pids[i]);
+
+ for(i = 0; i < ts->nb_services; i++){
+ av_free(ts->services[i]->provider_name);
+ av_free(ts->services[i]->name);
+ av_free(ts->services[i]);
+ }
+ av_freep(&ts->services);
+
+ return 0;
+}
+
+static int64_t mpegts_get_pcr(AVFormatContext *s, int stream_index,
+ int64_t *ppos, int64_t pos_limit)
+{
+ MpegTSContext *ts = s->priv_data;
+ int64_t pos, timestamp;
+ uint8_t buf[TS_PACKET_SIZE];
+ int pcr_l, pid;
+ const int find_next= 1;
+ pos = ((*ppos + ts->raw_packet_size - 1) / ts->raw_packet_size) * ts->raw_packet_size;
+ if (find_next) {
+ for(;;) {
+ url_fseek(&s->pb, pos, SEEK_SET);
+ if (get_buffer(&s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE)
+ return AV_NOPTS_VALUE;
+ pid = ((buf[1] & 0x1f) << 8) | buf[2];
+ if (pid == ts->pcr_pid &&
+ parse_pcr(&timestamp, &pcr_l, buf) == 0) {
+ break;
+ }
+ pos += ts->raw_packet_size;
+ }
+ } else {
+ for(;;) {
+ pos -= ts->raw_packet_size;
+ if (pos < 0)
+ return AV_NOPTS_VALUE;
+ url_fseek(&s->pb, pos, SEEK_SET);
+ if (get_buffer(&s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE)
+ return AV_NOPTS_VALUE;
+ pid = ((buf[1] & 0x1f) << 8) | buf[2];
+ if (pid == ts->pcr_pid &&
+ parse_pcr(&timestamp, &pcr_l, buf) == 0) {
+ break;
+ }
+ }
+ }
+ *ppos = pos;
+
+ return timestamp;
+}
+
+static int read_seek(AVFormatContext *s, int stream_index, int64_t target_ts, int flags){
+ MpegTSContext *ts = s->priv_data;
+ uint8_t buf[TS_PACKET_SIZE];
+ int64_t pos;
+
+ if(av_seek_frame_binary(s, stream_index, target_ts, flags) < 0)
+ return -1;
+
+ pos= url_ftell(&s->pb);
+
+ for(;;) {
+ url_fseek(&s->pb, pos, SEEK_SET);
+ if (get_buffer(&s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE)
+ return -1;
+// pid = ((buf[1] & 0x1f) << 8) | buf[2];
+ if(buf[1] & 0x40) break;
+ pos += ts->raw_packet_size;
+ }
+ url_fseek(&s->pb, pos, SEEK_SET);
+
+ return 0;
+}
+
+/**************************************************************/
+/* parsing functions - called from other demuxers such as RTP */
+
+MpegTSContext *mpegts_parse_open(AVFormatContext *s)
+{
+ MpegTSContext *ts;
+
+ ts = av_mallocz(sizeof(MpegTSContext));
+ if (!ts)
+ return NULL;
+ /* no stream case, currently used by RTP */
+ ts->raw_packet_size = TS_PACKET_SIZE;
+ ts->stream = s;
+ ts->auto_guess = 1;
+ return ts;
+}
+
+/* return the consumed length if a packet was output, or -1 if no
+ packet is output */
+int mpegts_parse_packet(MpegTSContext *ts, AVPacket *pkt,
+ const uint8_t *buf, int len)
+{
+ int len1;
+
+ len1 = len;
+ ts->pkt = pkt;
+ ts->stop_parse = 0;
+ for(;;) {
+ if (ts->stop_parse)
+ break;
+ if (len < TS_PACKET_SIZE)
+ return -1;
+ if (buf[0] != 0x47) {
+ buf++;
+ len--;
+ } else {
+ handle_packet(ts, buf);
+ buf += TS_PACKET_SIZE;
+ len -= TS_PACKET_SIZE;
+ }
+ }
+ return len1 - len;
+}
+
+void mpegts_parse_close(MpegTSContext *ts)
+{
+ int i;
+
+ for(i=0;i<NB_PID_MAX;i++)
+ av_free(ts->pids[i]);
+ av_free(ts);
+}
+
+AVInputFormat mpegts_demuxer = {
+ "mpegts",
+ "MPEG2 transport stream format",
+ sizeof(MpegTSContext),
+ mpegts_probe,
+ mpegts_read_header,
+ mpegts_read_packet,
+ mpegts_read_close,
+ read_seek,
+ mpegts_get_pcr,
+ .flags = AVFMT_SHOW_IDS,
+};
diff --git a/contrib/ffmpeg/libavformat/mpegts.h b/contrib/ffmpeg/libavformat/mpegts.h
new file mode 100644
index 000000000..771becbd4
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/mpegts.h
@@ -0,0 +1,63 @@
+/*
+ * MPEG2 transport stream defines
+ * Copyright (c) 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
+ */
+
+#define TS_FEC_PACKET_SIZE 204
+#define TS_DVHS_PACKET_SIZE 192
+#define TS_PACKET_SIZE 188
+#define NB_PID_MAX 8192
+#define MAX_SECTION_SIZE 4096
+
+/* pids */
+#define PAT_PID 0x0000
+#define SDT_PID 0x0011
+
+/* table ids */
+#define PAT_TID 0x00
+#define PMT_TID 0x02
+#define SDT_TID 0x42
+
+/* descriptor ids */
+#define DVB_SUBT_DESCID 0x59
+
+#define STREAM_TYPE_VIDEO_MPEG1 0x01
+#define STREAM_TYPE_VIDEO_MPEG2 0x02
+#define STREAM_TYPE_AUDIO_MPEG1 0x03
+#define STREAM_TYPE_AUDIO_MPEG2 0x04
+#define STREAM_TYPE_PRIVATE_SECTION 0x05
+#define STREAM_TYPE_PRIVATE_DATA 0x06
+#define STREAM_TYPE_AUDIO_AAC 0x0f
+#define STREAM_TYPE_VIDEO_MPEG4 0x10
+#define STREAM_TYPE_VIDEO_H264 0x1b
+#define STREAM_TYPE_VIDEO_VC1 0xea
+
+#define STREAM_TYPE_AUDIO_AC3 0x81
+#define STREAM_TYPE_AUDIO_DTS 0x8a
+
+#define STREAM_TYPE_SUBTITLE_DVB 0x100
+
+extern AVOutputFormat mpegts_muxer;
+
+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);
diff --git a/contrib/ffmpeg/libavformat/mpegtsenc.c b/contrib/ffmpeg/libavformat/mpegtsenc.c
new file mode 100644
index 000000000..c521b68b8
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/mpegtsenc.c
@@ -0,0 +1,695 @@
+/*
+ * MPEG2 transport stream (aka DVB) muxer
+ * Copyright (c) 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 "avformat.h"
+#include "crc.h"
+#include "mpegts.h"
+
+/* write DVB SI sections */
+
+/*********************************************/
+/* mpegts section writer */
+
+typedef struct MpegTSSection {
+ int pid;
+ int cc;
+ void (*write_packet)(struct MpegTSSection *s, const uint8_t *packet);
+ void *opaque;
+} MpegTSSection;
+
+/* NOTE: 4 bytes must be left at the end for the crc32 */
+static void mpegts_write_section(MpegTSSection *s, uint8_t *buf, int len)
+{
+ unsigned int crc;
+ unsigned char packet[TS_PACKET_SIZE];
+ const unsigned char *buf_ptr;
+ unsigned char *q;
+ int first, b, len1, left;
+
+ crc = bswap_32(av_crc(av_crc04C11DB7, -1, buf, len - 4));
+ buf[len - 4] = (crc >> 24) & 0xff;
+ buf[len - 3] = (crc >> 16) & 0xff;
+ buf[len - 2] = (crc >> 8) & 0xff;
+ buf[len - 1] = (crc) & 0xff;
+
+ /* send each packet */
+ buf_ptr = buf;
+ while (len > 0) {
+ first = (buf == buf_ptr);
+ q = packet;
+ *q++ = 0x47;
+ b = (s->pid >> 8);
+ if (first)
+ b |= 0x40;
+ *q++ = b;
+ *q++ = s->pid;
+ s->cc = (s->cc + 1) & 0xf;
+ *q++ = 0x10 | s->cc;
+ if (first)
+ *q++ = 0; /* 0 offset */
+ len1 = TS_PACKET_SIZE - (q - packet);
+ if (len1 > len)
+ len1 = len;
+ memcpy(q, buf_ptr, len1);
+ q += len1;
+ /* add known padding data */
+ left = TS_PACKET_SIZE - (q - packet);
+ if (left > 0)
+ memset(q, 0xff, left);
+
+ s->write_packet(s, packet);
+
+ buf_ptr += len1;
+ len -= len1;
+ }
+}
+
+static inline void put16(uint8_t **q_ptr, int val)
+{
+ uint8_t *q;
+ q = *q_ptr;
+ *q++ = val >> 8;
+ *q++ = val;
+ *q_ptr = q;
+}
+
+static int mpegts_write_section1(MpegTSSection *s, int tid, int id,
+ int version, int sec_num, int last_sec_num,
+ uint8_t *buf, int len)
+{
+ uint8_t section[1024], *q;
+ unsigned int tot_len;
+
+ tot_len = 3 + 5 + len + 4;
+ /* check if not too big */
+ if (tot_len > 1024)
+ return -1;
+
+ q = section;
+ *q++ = tid;
+ put16(&q, 0xb000 | (len + 5 + 4)); /* 5 byte header + 4 byte CRC */
+ put16(&q, id);
+ *q++ = 0xc1 | (version << 1); /* current_next_indicator = 1 */
+ *q++ = sec_num;
+ *q++ = last_sec_num;
+ memcpy(q, buf, len);
+
+ mpegts_write_section(s, section, tot_len);
+ return 0;
+}
+
+/*********************************************/
+/* mpegts writer */
+
+#define DEFAULT_PMT_START_PID 0x1000
+#define DEFAULT_START_PID 0x0100
+#define DEFAULT_PROVIDER_NAME "FFmpeg"
+#define DEFAULT_SERVICE_NAME "Service01"
+
+/* default network id, transport stream and service identifiers */
+#define DEFAULT_ONID 0x0001
+#define DEFAULT_TSID 0x0001
+#define DEFAULT_SID 0x0001
+
+/* a PES packet header is generated every DEFAULT_PES_HEADER_FREQ packets */
+#define DEFAULT_PES_HEADER_FREQ 16
+#define DEFAULT_PES_PAYLOAD_SIZE ((DEFAULT_PES_HEADER_FREQ - 1) * 184 + 170)
+
+/* we retransmit the SI info at this rate */
+#define SDT_RETRANS_TIME 500
+#define PAT_RETRANS_TIME 100
+#define PCR_RETRANS_TIME 20
+
+typedef struct MpegTSWriteStream {
+ struct MpegTSService *service;
+ int pid; /* stream associated pid */
+ int cc;
+ int payload_index;
+ int64_t payload_pts;
+ int64_t payload_dts;
+ uint8_t payload[DEFAULT_PES_PAYLOAD_SIZE];
+} MpegTSWriteStream;
+
+typedef struct MpegTSService {
+ MpegTSSection pmt; /* MPEG2 pmt table context */
+ int sid; /* service ID */
+ char *name;
+ char *provider_name;
+ int pcr_pid;
+ int pcr_packet_count;
+ int pcr_packet_freq;
+} MpegTSService;
+
+typedef struct MpegTSWrite {
+ MpegTSSection pat; /* MPEG2 pat table */
+ MpegTSSection sdt; /* MPEG2 sdt table context */
+ MpegTSService **services;
+ int sdt_packet_count;
+ int sdt_packet_freq;
+ int pat_packet_count;
+ int pat_packet_freq;
+ int nb_services;
+ int onid;
+ int tsid;
+} MpegTSWrite;
+
+static void mpegts_write_pat(AVFormatContext *s)
+{
+ MpegTSWrite *ts = s->priv_data;
+ MpegTSService *service;
+ uint8_t data[1012], *q;
+ int i;
+
+ q = data;
+ for(i = 0; i < ts->nb_services; i++) {
+ service = ts->services[i];
+ put16(&q, service->sid);
+ put16(&q, 0xe000 | service->pmt.pid);
+ }
+ mpegts_write_section1(&ts->pat, PAT_TID, ts->tsid, 0, 0, 0,
+ data, q - data);
+}
+
+static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
+{
+ // MpegTSWrite *ts = s->priv_data;
+ uint8_t data[1012], *q, *desc_length_ptr, *program_info_length_ptr;
+ int val, stream_type, i;
+
+ q = data;
+ put16(&q, 0xe000 | service->pcr_pid);
+
+ program_info_length_ptr = q;
+ q += 2; /* patched after */
+
+ /* put program info here */
+
+ val = 0xf000 | (q - program_info_length_ptr - 2);
+ program_info_length_ptr[0] = val >> 8;
+ program_info_length_ptr[1] = val;
+
+ for(i = 0; i < s->nb_streams; i++) {
+ AVStream *st = s->streams[i];
+ MpegTSWriteStream *ts_st = st->priv_data;
+ switch(st->codec->codec_id) {
+ case CODEC_ID_MPEG1VIDEO:
+ case CODEC_ID_MPEG2VIDEO:
+ stream_type = STREAM_TYPE_VIDEO_MPEG2;
+ break;
+ case CODEC_ID_MPEG4:
+ stream_type = STREAM_TYPE_VIDEO_MPEG4;
+ break;
+ case CODEC_ID_H264:
+ stream_type = STREAM_TYPE_VIDEO_H264;
+ break;
+ case CODEC_ID_MP2:
+ case CODEC_ID_MP3:
+ stream_type = STREAM_TYPE_AUDIO_MPEG1;
+ break;
+ case CODEC_ID_AAC:
+ stream_type = STREAM_TYPE_AUDIO_AAC;
+ break;
+ case CODEC_ID_AC3:
+ stream_type = STREAM_TYPE_AUDIO_AC3;
+ break;
+ default:
+ stream_type = STREAM_TYPE_PRIVATE_DATA;
+ break;
+ }
+ *q++ = stream_type;
+ put16(&q, 0xe000 | ts_st->pid);
+ desc_length_ptr = q;
+ q += 2; /* patched after */
+
+ /* write optional descriptors here */
+ switch(st->codec->codec_type) {
+ case CODEC_TYPE_AUDIO:
+ if (strlen(st->language) == 3) {
+ *q++ = 0x0a; /* ISO 639 language descriptor */
+ *q++ = 4;
+ *q++ = st->language[0];
+ *q++ = st->language[1];
+ *q++ = st->language[2];
+ *q++ = 0; /* undefined type */
+ }
+ break;
+ case CODEC_TYPE_SUBTITLE:
+ {
+ const char *language;
+ language = st->language;
+ if (strlen(language) != 3)
+ language = "eng";
+ *q++ = 0x59;
+ *q++ = 8;
+ *q++ = language[0];
+ *q++ = language[1];
+ *q++ = language[2];
+ *q++ = 0x10; /* normal subtitles (0x20 = if hearing pb) */
+ put16(&q, 1); /* page id */
+ put16(&q, 1); /* ancillary page id */
+ }
+ break;
+ }
+
+ val = 0xf000 | (q - desc_length_ptr - 2);
+ desc_length_ptr[0] = val >> 8;
+ desc_length_ptr[1] = val;
+ }
+ mpegts_write_section1(&service->pmt, PMT_TID, service->sid, 0, 0, 0,
+ data, q - data);
+}
+
+/* NOTE: str == NULL is accepted for an empty string */
+static void putstr8(uint8_t **q_ptr, const char *str)
+{
+ uint8_t *q;
+ int len;
+
+ q = *q_ptr;
+ if (!str)
+ len = 0;
+ else
+ len = strlen(str);
+ *q++ = len;
+ memcpy(q, str, len);
+ q += len;
+ *q_ptr = q;
+}
+
+static void mpegts_write_sdt(AVFormatContext *s)
+{
+ MpegTSWrite *ts = s->priv_data;
+ MpegTSService *service;
+ uint8_t data[1012], *q, *desc_list_len_ptr, *desc_len_ptr;
+ int i, running_status, free_ca_mode, val;
+
+ q = data;
+ put16(&q, ts->onid);
+ *q++ = 0xff;
+ for(i = 0; i < ts->nb_services; i++) {
+ service = ts->services[i];
+ put16(&q, service->sid);
+ *q++ = 0xfc | 0x00; /* currently no EIT info */
+ desc_list_len_ptr = q;
+ q += 2;
+ running_status = 4; /* running */
+ free_ca_mode = 0;
+
+ /* write only one descriptor for the service name and provider */
+ *q++ = 0x48;
+ desc_len_ptr = q;
+ q++;
+ *q++ = 0x01; /* digital television service */
+ putstr8(&q, service->provider_name);
+ putstr8(&q, service->name);
+ desc_len_ptr[0] = q - desc_len_ptr - 1;
+
+ /* fill descriptor length */
+ val = (running_status << 13) | (free_ca_mode << 12) |
+ (q - desc_list_len_ptr - 2);
+ desc_list_len_ptr[0] = val >> 8;
+ desc_list_len_ptr[1] = val;
+ }
+ mpegts_write_section1(&ts->sdt, SDT_TID, ts->tsid, 0, 0, 0,
+ data, q - data);
+}
+
+static MpegTSService *mpegts_add_service(MpegTSWrite *ts,
+ int sid,
+ const char *provider_name,
+ const char *name)
+{
+ MpegTSService *service;
+
+ service = av_mallocz(sizeof(MpegTSService));
+ if (!service)
+ return NULL;
+ service->pmt.pid = DEFAULT_PMT_START_PID + ts->nb_services - 1;
+ service->sid = sid;
+ service->provider_name = av_strdup(provider_name);
+ service->name = av_strdup(name);
+ service->pcr_pid = 0x1fff;
+ dynarray_add(&ts->services, &ts->nb_services, service);
+ return service;
+}
+
+static void section_write_packet(MpegTSSection *s, const uint8_t *packet)
+{
+ AVFormatContext *ctx = s->opaque;
+ put_buffer(&ctx->pb, packet, TS_PACKET_SIZE);
+}
+
+static int mpegts_write_header(AVFormatContext *s)
+{
+ MpegTSWrite *ts = s->priv_data;
+ MpegTSWriteStream *ts_st;
+ MpegTSService *service;
+ AVStream *st;
+ int i, total_bit_rate;
+ const char *service_name;
+
+ ts->tsid = DEFAULT_TSID;
+ ts->onid = DEFAULT_ONID;
+ /* allocate a single DVB service */
+ service_name = s->title;
+ if (service_name[0] == '\0')
+ service_name = DEFAULT_SERVICE_NAME;
+ service = mpegts_add_service(ts, DEFAULT_SID,
+ DEFAULT_PROVIDER_NAME, service_name);
+ service->pmt.write_packet = section_write_packet;
+ service->pmt.opaque = s;
+
+ ts->pat.pid = PAT_PID;
+ ts->pat.cc = 0;
+ ts->pat.write_packet = section_write_packet;
+ ts->pat.opaque = s;
+
+ ts->sdt.pid = SDT_PID;
+ ts->sdt.cc = 0;
+ 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));
+ if (!ts_st)
+ goto fail;
+ st->priv_data = ts_st;
+ ts_st->service = service;
+ ts_st->pid = DEFAULT_START_PID + i;
+ ts_st->payload_pts = AV_NOPTS_VALUE;
+ ts_st->payload_dts = AV_NOPTS_VALUE;
+ /* update PCR pid by using the first video stream */
+ if (st->codec->codec_type == CODEC_TYPE_VIDEO &&
+ service->pcr_pid == 0x1fff)
+ service->pcr_pid = ts_st->pid;
+ total_bit_rate += st->codec->bit_rate;
+ }
+
+ /* 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;
+ service->pcr_pid = ts_st->pid;
+ }
+
+ if (total_bit_rate <= 8 * 1024)
+ total_bit_rate = 8 * 1024;
+ service->pcr_packet_freq = (total_bit_rate * PCR_RETRANS_TIME) /
+ (TS_PACKET_SIZE * 8 * 1000);
+ ts->sdt_packet_freq = (total_bit_rate * SDT_RETRANS_TIME) /
+ (TS_PACKET_SIZE * 8 * 1000);
+ ts->pat_packet_freq = (total_bit_rate * PAT_RETRANS_TIME) /
+ (TS_PACKET_SIZE * 8 * 1000);
+#if 0
+ printf("%d %d %d\n",
+ total_bit_rate, ts->sdt_packet_freq, ts->pat_packet_freq);
+#endif
+
+ /* write info at the start of the file, so that it will be fast to
+ find them */
+ mpegts_write_sdt(s);
+ mpegts_write_pat(s);
+ for(i = 0; i < ts->nb_services; i++) {
+ mpegts_write_pmt(s, ts->services[i]);
+ }
+ put_flush_packet(&s->pb);
+
+ return 0;
+
+ fail:
+ for(i = 0;i < s->nb_streams; i++) {
+ st = s->streams[i];
+ av_free(st->priv_data);
+ }
+ return -1;
+}
+
+/* send SDT, PAT and PMT tables regulary */
+static void retransmit_si_info(AVFormatContext *s)
+{
+ MpegTSWrite *ts = s->priv_data;
+ int i;
+
+ if (++ts->sdt_packet_count == ts->sdt_packet_freq) {
+ ts->sdt_packet_count = 0;
+ mpegts_write_sdt(s);
+ }
+ if (++ts->pat_packet_count == ts->pat_packet_freq) {
+ ts->pat_packet_count = 0;
+ mpegts_write_pat(s);
+ for(i = 0; i < ts->nb_services; i++) {
+ mpegts_write_pmt(s, ts->services[i]);
+ }
+ }
+}
+
+static void write_pts(uint8_t *q, int fourbits, int64_t pts)
+{
+ int val;
+
+ val = fourbits << 4 | (((pts >> 30) & 0x07) << 1) | 1;
+ *q++ = val;
+ val = (((pts >> 15) & 0x7fff) << 1) | 1;
+ *q++ = val >> 8;
+ *q++ = val;
+ val = (((pts) & 0x7fff) << 1) | 1;
+ *q++ = val >> 8;
+ *q++ = val;
+}
+
+/* NOTE: pes_data contains all the PES packet */
+static void mpegts_write_pes(AVFormatContext *s, AVStream *st,
+ const uint8_t *payload, int payload_size,
+ int64_t pts, int64_t dts)
+{
+ MpegTSWriteStream *ts_st = st->priv_data;
+ uint8_t buf[TS_PACKET_SIZE];
+ uint8_t *q;
+ int val, is_start, len, header_len, write_pcr, private_code, flags;
+ int afc_len, stuffing_len;
+ int64_t pcr = -1; /* avoid warning */
+
+ is_start = 1;
+ while (payload_size > 0) {
+ retransmit_si_info(s);
+
+ write_pcr = 0;
+ if (ts_st->pid == ts_st->service->pcr_pid) {
+ ts_st->service->pcr_packet_count++;
+ if (ts_st->service->pcr_packet_count >=
+ ts_st->service->pcr_packet_freq) {
+ ts_st->service->pcr_packet_count = 0;
+ write_pcr = 1;
+ /* XXX: this is incorrect, but at least we have a PCR
+ value */
+ pcr = pts;
+ }
+ }
+
+ /* prepare packet header */
+ q = buf;
+ *q++ = 0x47;
+ val = (ts_st->pid >> 8);
+ if (is_start)
+ 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;
+ if (write_pcr) {
+ *q++ = 7; /* AFC length */
+ *q++ = 0x10; /* flags: PCR present */
+ *q++ = pcr >> 25;
+ *q++ = pcr >> 17;
+ *q++ = pcr >> 9;
+ *q++ = pcr >> 1;
+ *q++ = (pcr & 1) << 7;
+ *q++ = 0;
+ }
+ if (is_start) {
+ /* write PES header */
+ *q++ = 0x00;
+ *q++ = 0x00;
+ *q++ = 0x01;
+ private_code = 0;
+ if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
+ *q++ = 0xe0;
+ } else if (st->codec->codec_type == CODEC_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) {
+ private_code = 0x20;
+ }
+ }
+ header_len = 0;
+ flags = 0;
+ if (pts != AV_NOPTS_VALUE) {
+ header_len += 5;
+ flags |= 0x80;
+ }
+ if (dts != AV_NOPTS_VALUE) {
+ header_len += 5;
+ flags |= 0x40;
+ }
+ len = payload_size + header_len + 3;
+ if (private_code != 0)
+ len++;
+ *q++ = len >> 8;
+ *q++ = len;
+ val = 0x80;
+ /* data alignment indicator is required for subtitle data */
+ if (st->codec->codec_type == CODEC_TYPE_SUBTITLE)
+ val |= 0x04;
+ *q++ = val;
+ *q++ = flags;
+ *q++ = header_len;
+ if (pts != AV_NOPTS_VALUE) {
+ write_pts(q, flags >> 6, pts);
+ q += 5;
+ }
+ if (dts != AV_NOPTS_VALUE) {
+ write_pts(q, 1, dts);
+ q += 5;
+ }
+ if (private_code != 0)
+ *q++ = private_code;
+ is_start = 0;
+ }
+ /* header size */
+ header_len = q - buf;
+ /* data len */
+ len = TS_PACKET_SIZE - header_len;
+ if (len > payload_size)
+ len = payload_size;
+ stuffing_len = TS_PACKET_SIZE - header_len - len;
+ if (stuffing_len > 0) {
+ /* add stuffing with AFC */
+ if (buf[3] & 0x20) {
+ /* stuffing already present: increase its size */
+ afc_len = buf[4] + 1;
+ memmove(buf + 4 + afc_len + stuffing_len,
+ buf + 4 + afc_len,
+ header_len - (4 + afc_len));
+ buf[4] += stuffing_len;
+ memset(buf + 4 + afc_len, 0xff, stuffing_len);
+ } else {
+ /* add stuffing */
+ memmove(buf + 4 + stuffing_len, buf + 4, header_len - 4);
+ buf[3] |= 0x20;
+ buf[4] = stuffing_len - 1;
+ if (stuffing_len >= 2) {
+ buf[5] = 0x00;
+ memset(buf + 6, 0xff, stuffing_len - 2);
+ }
+ }
+ }
+ memcpy(buf + TS_PACKET_SIZE - len, payload, len);
+ payload += len;
+ payload_size -= len;
+ put_buffer(&s->pb, buf, TS_PACKET_SIZE);
+ }
+ put_flush_packet(&s->pb);
+}
+
+static int mpegts_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ AVStream *st = s->streams[pkt->stream_index];
+ int size= pkt->size;
+ uint8_t *buf= pkt->data;
+ MpegTSWriteStream *ts_st = st->priv_data;
+ int len, max_payload_size;
+
+ if (st->codec->codec_type == CODEC_TYPE_SUBTITLE) {
+ /* for subtitle, a single PES packet must be generated */
+ mpegts_write_pes(s, st, buf, size, pkt->pts, AV_NOPTS_VALUE);
+ return 0;
+ }
+
+ max_payload_size = DEFAULT_PES_PAYLOAD_SIZE;
+ while (size > 0) {
+ len = max_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_pts == AV_NOPTS_VALUE)
+ ts_st->payload_pts = pkt->pts;
+ if (ts_st->payload_dts == AV_NOPTS_VALUE)
+ ts_st->payload_dts = pkt->dts;
+ if (ts_st->payload_index >= max_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;
+ }
+ }
+ return 0;
+}
+
+static int mpegts_write_end(AVFormatContext *s)
+{
+ MpegTSWrite *ts = s->priv_data;
+ MpegTSWriteStream *ts_st;
+ MpegTSService *service;
+ AVStream *st;
+ int i;
+
+ /* flush current packets */
+ for(i = 0; i < s->nb_streams; i++) {
+ st = s->streams[i];
+ ts_st = st->priv_data;
+ if (ts_st->payload_index > 0) {
+ mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_index,
+ ts_st->payload_pts, ts_st->payload_dts);
+ }
+ }
+ put_flush_packet(&s->pb);
+
+ for(i = 0; i < ts->nb_services; i++) {
+ service = ts->services[i];
+ av_freep(&service->provider_name);
+ av_freep(&service->name);
+ av_free(service);
+ }
+ av_free(ts->services);
+
+ return 0;
+}
+
+AVOutputFormat mpegts_muxer = {
+ "mpegts",
+ "MPEG2 transport stream format",
+ "video/x-mpegts",
+ "ts",
+ sizeof(MpegTSWrite),
+ CODEC_ID_MP2,
+ CODEC_ID_MPEG2VIDEO,
+ mpegts_write_header,
+ mpegts_write_packet,
+ mpegts_write_end,
+};
diff --git a/contrib/ffmpeg/libavformat/mpjpeg.c b/contrib/ffmpeg/libavformat/mpjpeg.c
new file mode 100644
index 000000000..937917313
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/mpjpeg.c
@@ -0,0 +1,67 @@
+/*
+ * Multipart JPEG format
+ * Copyright (c) 2000, 2001, 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 "avformat.h"
+
+/* Multipart JPEG */
+
+#define BOUNDARY_TAG "ffserver"
+
+static int mpjpeg_write_header(AVFormatContext *s)
+{
+ uint8_t buf1[256];
+
+ snprintf(buf1, sizeof(buf1), "--%s\n", BOUNDARY_TAG);
+ put_buffer(&s->pb, buf1, strlen(buf1));
+ put_flush_packet(&s->pb);
+ return 0;
+}
+
+static int mpjpeg_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ uint8_t buf1[256];
+
+ snprintf(buf1, sizeof(buf1), "Content-type: image/jpeg\n\n");
+ put_buffer(&s->pb, buf1, strlen(buf1));
+ put_buffer(&s->pb, pkt->data, pkt->size);
+
+ snprintf(buf1, sizeof(buf1), "\n--%s\n", BOUNDARY_TAG);
+ put_buffer(&s->pb, buf1, strlen(buf1));
+ put_flush_packet(&s->pb);
+ return 0;
+}
+
+static int mpjpeg_write_trailer(AVFormatContext *s)
+{
+ return 0;
+}
+
+AVOutputFormat mpjpeg_muxer = {
+ "mpjpeg",
+ "Mime multipart JPEG format",
+ "multipart/x-mixed-replace;boundary=" BOUNDARY_TAG,
+ "mjpg",
+ 0,
+ CODEC_ID_NONE,
+ CODEC_ID_MJPEG,
+ mpjpeg_write_header,
+ mpjpeg_write_packet,
+ mpjpeg_write_trailer,
+};
diff --git a/contrib/ffmpeg/libavformat/mtv.c b/contrib/ffmpeg/libavformat/mtv.c
new file mode 100644
index 000000000..7a68ea97f
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/mtv.c
@@ -0,0 +1,187 @@
+/*
+ * mtv demuxer
+ * Copyright (c) 2006 Reynaldo H. Verdejo Pinochet
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 mtv.c
+ * MTV demuxer.
+ */
+
+#include "avformat.h"
+#include "bswap.h"
+
+#define MTV_ASUBCHUNK_DATA_SIZE 500
+#define MTV_HEADER_SIZE 512
+#define MTV_AUDIO_PADDING_SIZE 12
+#define AUDIO_SAMPLING_RATE 44100
+#define VIDEO_SID 0
+#define AUDIO_SID 1
+
+typedef struct MTVDemuxContext {
+
+ 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 img_colorfmt; ///< frame colorfmt rgb 565/555
+ unsigned int img_bpp; ///< frame bits per pixel
+ unsigned int img_width; //
+ unsigned int img_height; //
+ unsigned int img_segment_size; ///< size of image segment
+ unsigned int video_fps; //
+ unsigned int audio_subsegments; ///< audio subsegments on one segment
+
+ uint8_t audio_packet_count;
+
+} MTVDemuxContext;
+
+static int mtv_probe(AVProbeData *p)
+{
+ if(p->buf_size < 3)
+ return 0;
+
+ /* Magic is 'AMV' */
+
+ if(*(p->buf) != 'A' || *(p->buf+1) != 'M' || *(p->buf+2) != 'V')
+ return 0;
+
+ return AVPROBE_SCORE_MAX;
+}
+
+static int mtv_read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+ MTVDemuxContext *mtv = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ AVStream *st;
+
+
+ url_fskip(pb, 3);
+ mtv->file_size = get_le32(pb);
+ mtv->segments = get_le32(pb);
+ url_fskip(pb, 32);
+ mtv->audio_identifier = get_le24(pb);
+ mtv->audio_br = get_le16(pb);
+ mtv->img_colorfmt = get_le24(pb);
+ mtv->img_bpp = get_byte(pb);
+ mtv->img_width = get_le16(pb);
+ mtv->img_height = get_le16(pb);
+ mtv->img_segment_size = get_le16(pb);
+ url_fskip(pb, 4);
+ mtv->audio_subsegments = get_le16(pb);
+ mtv->video_fps = (mtv->audio_br / 4) / mtv->audio_subsegments;
+
+ /* FIXME Add sanity check here */
+
+ /* first packet is allways audio*/
+
+ mtv->audio_packet_count = 1;
+
+ /* all systems go! init decoders */
+
+ /* video - raw rgb565 */
+
+ st = av_new_stream(s, VIDEO_SID);
+ if(!st)
+ return AVERROR_NOMEM;
+
+ av_set_pts_info(st, 64, 1, mtv->video_fps);
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ st->codec->codec_id = CODEC_ID_RAWVIDEO;
+ st->codec->codec_tag = MKTAG('R', 'G', 'B', mtv->img_bpp);
+ st->codec->width = mtv->img_width;
+ st->codec->height = mtv->img_height;
+ st->codec->bits_per_sample = mtv->img_bpp;
+ st->codec->sample_rate = mtv->video_fps;
+
+ /* audio - mp3 */
+
+ st = av_new_stream(s, AUDIO_SID);
+ if(!st)
+ return AVERROR_NOMEM;
+
+ av_set_pts_info(st, 64, 1, AUDIO_SAMPLING_RATE);
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_id = CODEC_ID_MP3;
+ st->codec->bit_rate = mtv->audio_br;
+ st->need_parsing=1;
+
+ /* Jump over header */
+
+ if(url_fseek(pb, MTV_HEADER_SIZE, SEEK_SET) != MTV_HEADER_SIZE)
+ return AVERROR_IO;
+
+ return(0);
+
+}
+
+static int mtv_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ MTVDemuxContext *mtv = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ int ret;
+#ifndef WORDS_BIGENDIAN
+ int i;
+#endif
+
+ ret = 0;
+
+ if(mtv->audio_subsegments >= mtv->audio_packet_count)
+ {
+ 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_IO;
+
+ mtv->audio_packet_count++;
+ pkt->stream_index = AUDIO_SID;
+
+ }else
+ {
+ ret = av_get_packet(pb, pkt, mtv->img_segment_size);
+ if(ret != mtv->img_segment_size)
+ return AVERROR_IO;
+
+#ifndef WORDS_BIGENDIAN
+
+ /* pkt->data is GGGRRRR BBBBBGGG
+ * and we need RRRRRGGG GGGBBBBB
+ * for PIX_FMT_RGB565 so here we
+ * just swap bytes as they come
+ */
+
+ for(i=0;i<mtv->img_segment_size/2;i++)
+ *((uint16_t *)pkt->data+i) = bswap_16(*((uint16_t *)pkt->data+i));
+#endif
+ mtv->audio_packet_count = 1;
+ pkt->stream_index = VIDEO_SID;
+ }
+
+ return(ret);
+}
+
+AVInputFormat mtv_demuxer = {
+ "MTV",
+ "MTV format",
+ sizeof(MTVDemuxContext),
+ mtv_probe,
+ mtv_read_header,
+ mtv_read_packet,
+};
diff --git a/contrib/ffmpeg/libavformat/mxf.c b/contrib/ffmpeg/libavformat/mxf.c
new file mode 100644
index 000000000..677e023f0
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/mxf.c
@@ -0,0 +1,1024 @@
+/*
+ * MXF demuxer.
+ * Copyright (c) 2006 SmartJog S.A., Baptiste Coudurier <baptiste dot coudurier at smartjog dot com>.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*
+ * References
+ * SMPTE 336M KLV Data Encoding Protocol Using Key-Length-Value
+ * SMPTE 377M MXF File Format Specifications
+ * SMPTE 378M Operational Pattern 1a
+ * SMPTE 379M MXF Generic Container
+ * SMPTE 381M Mapping MPEG Streams into the MXF Generic Container
+ * SMPTE 382M Mapping AES3 and Broadcast Wave Audio into the MXF Generic Container
+ * SMPTE 383M Mapping DV-DIF Data to the MXF Generic Container
+ *
+ * Principle
+ * Search for Track numbers which will identify essence element KLV packets.
+ * Search for SourcePackage which define tracks which contains Track numbers.
+ * Material Package contains tracks with reference to SourcePackage tracks.
+ * Search for Descriptors (Picture, Sound) which contains codec info and parameters.
+ * Assign Descriptors to correct Tracks.
+ *
+ * Metadata reading functions read Local Tags, get InstanceUID(0x3C0A) then add MetaDataSet to MXFContext.
+ * Metadata parsing resolves Strong References to objects.
+ *
+ * Simple demuxer, only OP1A supported and some files might not work at all.
+ * Only tracks with associated descriptors will be decoded. "Highly Desirable" SMPTE 377M D.1
+ */
+
+//#define DEBUG
+
+#include "avformat.h"
+#include "aes.h"
+
+typedef uint8_t UID[16];
+
+enum MXFMetadataSetType {
+ AnyType,
+ MaterialPackage,
+ SourcePackage,
+ SourceClip,
+ TimecodeComponent,
+ Sequence,
+ MultipleDescriptor,
+ Descriptor,
+ Track,
+ EssenceContainerData,
+ CryptoContext,
+};
+
+typedef struct MXFCryptoContext {
+ UID uid;
+ enum MXFMetadataSetType type;
+ UID context_uid;
+ UID source_container_ul;
+} MXFCryptoContext;
+
+typedef struct MXFStructuralComponent {
+ UID uid;
+ enum MXFMetadataSetType type;
+ UID source_package_uid;
+ UID data_definition_ul;
+ int64_t duration;
+ int64_t start_position;
+ int source_track_id;
+} MXFStructuralComponent;
+
+typedef struct MXFSequence {
+ UID uid;
+ enum MXFMetadataSetType type;
+ UID data_definition_ul;
+ UID *structural_components_refs;
+ int structural_components_count;
+ int64_t duration;
+} MXFSequence;
+
+typedef struct MXFTrack {
+ UID uid;
+ enum MXFMetadataSetType type;
+ MXFSequence *sequence; /* mandatory, and only one */
+ UID sequence_ref;
+ int track_id;
+ uint8_t track_number[4];
+ AVRational edit_rate;
+} MXFTrack;
+
+typedef struct MXFDescriptor {
+ UID uid;
+ enum MXFMetadataSetType type;
+ UID essence_container_ul;
+ UID essence_codec_ul;
+ AVRational sample_rate;
+ AVRational aspect_ratio;
+ int width;
+ int height;
+ int channels;
+ int bits_per_sample;
+ UID *sub_descriptors_refs;
+ int sub_descriptors_count;
+ int linked_track_id;
+ uint8_t *extradata;
+ int extradata_size;
+} MXFDescriptor;
+
+typedef struct MXFPackage {
+ UID uid;
+ enum MXFMetadataSetType type;
+ UID package_uid;
+ UID *tracks_refs;
+ int tracks_count;
+ MXFDescriptor *descriptor; /* only one */
+ UID descriptor_ref;
+} MXFPackage;
+
+typedef struct MXFEssenceContainerData {
+ UID uid;
+ enum MXFMetadataSetType type;
+ UID linked_package_uid;
+} MXFEssenceContainerData;
+
+typedef struct {
+ UID uid;
+ enum MXFMetadataSetType type;
+} MXFMetadataSet;
+
+typedef struct MXFContext {
+ UID *packages_refs;
+ int packages_count;
+ MXFMetadataSet **metadata_sets;
+ int metadata_sets_count;
+ const uint8_t *sync_key;
+ AVFormatContext *fc;
+ struct AVAES *aesc;
+} MXFContext;
+
+typedef struct KLVPacket {
+ UID key;
+ offset_t offset;
+ uint64_t length;
+} KLVPacket;
+
+enum MXFWrappingScheme {
+ Frame,
+ Clip,
+};
+
+typedef struct MXFCodecUL {
+ UID uid;
+ enum CodecID id;
+ enum MXFWrappingScheme wrapping;
+} MXFCodecUL;
+
+typedef struct MXFDataDefinitionUL {
+ UID uid;
+ enum CodecType type;
+} MXFDataDefinitionUL;
+
+typedef struct MXFMetadataReadTableEntry {
+ const UID key;
+ int (*read)();
+ int ctx_size;
+ enum MXFMetadataSetType type;
+} MXFMetadataReadTableEntry;
+
+/* partial keys to match */
+static const uint8_t mxf_header_partition_pack_key[] = { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x02 };
+static const uint8_t mxf_essence_element_key[] = { 0x06,0x0e,0x2b,0x34,0x01,0x02,0x01,0x01,0x0d,0x01,0x03,0x01 };
+/* complete keys to match */
+static const uint8_t mxf_encrypted_triplet_key[] = { 0x06,0x0e,0x2b,0x34,0x02,0x04,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x7e,0x01,0x00 };
+static const uint8_t mxf_encrypted_essence_container[] = { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x0b,0x01,0x00 };
+
+#define IS_KLV_KEY(x, y) (!memcmp(x, y, sizeof(y)))
+
+#define PRINT_KEY(pc, s, x) dprintf(pc, "%s %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n", s, \
+ (x)[0], (x)[1], (x)[2], (x)[3], (x)[4], (x)[5], (x)[6], (x)[7], (x)[8], (x)[9], (x)[10], (x)[11], (x)[12], (x)[13], (x)[14], (x)[15])
+
+static int64_t klv_decode_ber_length(ByteIOContext *pb)
+{
+ uint64_t size = get_byte(pb);
+ if (size & 0x80) { /* long form */
+ int bytes_num = size & 0x7f;
+ /* SMPTE 379M 5.3.4 guarantee that bytes_num must not exceed 8 bytes */
+ if (bytes_num > 8)
+ return -1;
+ size = 0;
+ while (bytes_num--)
+ size = size << 8 | get_byte(pb);
+ }
+ return size;
+}
+
+static int klv_read_packet(KLVPacket *klv, ByteIOContext *pb)
+{
+ klv->offset = url_ftell(pb);
+ get_buffer(pb, klv->key, 16);
+ klv->length = klv_decode_ber_length(pb);
+ return klv->length == -1 ? -1 : 0;
+}
+
+static int mxf_get_stream_index(AVFormatContext *s, KLVPacket *klv)
+{
+ int i;
+
+ for (i = 0; i < s->nb_streams; i++) {
+ MXFTrack *track = s->streams[i]->priv_data;
+ /* SMPTE 379M 7.3 */
+ if (!memcmp(klv->key + sizeof(mxf_essence_element_key), track->track_number, sizeof(track->track_number)))
+ return i;
+ }
+ /* return 0 if only one stream, for OP Atom files with 0 as track number */
+ return s->nb_streams == 1 ? 0 : -1;
+}
+
+/* XXX: use AVBitStreamFilter */
+static int mxf_get_d10_aes3_packet(ByteIOContext *pb, AVStream *st, AVPacket *pkt, int64_t length)
+{
+ uint8_t buffer[61444];
+ uint8_t *buf_ptr, *end_ptr, *data_ptr;
+
+ if (length > 61444) /* worst case PAL 1920 samples 8 channels */
+ return -1;
+ get_buffer(pb, buffer, length);
+ av_new_packet(pkt, length);
+ data_ptr = pkt->data;
+ end_ptr = buffer + length;
+ buf_ptr = buffer + 4; /* skip SMPTE 331M header */
+ for (; buf_ptr < end_ptr; buf_ptr += 4) {
+ if (st->codec->bits_per_sample == 24) {
+ data_ptr[0] = (buf_ptr[2] >> 4) | ((buf_ptr[3] & 0x0f) << 4);
+ data_ptr[1] = (buf_ptr[1] >> 4) | ((buf_ptr[2] & 0x0f) << 4);
+ data_ptr[2] = (buf_ptr[0] >> 4) | ((buf_ptr[1] & 0x0f) << 4);
+ data_ptr += 3;
+ } else {
+ data_ptr[0] = (buf_ptr[2] >> 4) | ((buf_ptr[3] & 0x0f) << 4);
+ data_ptr[1] = (buf_ptr[1] >> 4) | ((buf_ptr[2] & 0x0f) << 4);
+ data_ptr += 2;
+ }
+ }
+ pkt->size = data_ptr - pkt->data;
+ return 0;
+}
+
+static int mxf_decrypt_triplet(AVFormatContext *s, AVPacket *pkt, KLVPacket *klv)
+{
+ static const uint8_t checkv[16] = {0x43, 0x48, 0x55, 0x4b, 0x43, 0x48, 0x55, 0x4b, 0x43, 0x48, 0x55, 0x4b, 0x43, 0x48, 0x55, 0x4b};
+ MXFContext *mxf = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ offset_t end = url_ftell(pb) + klv->length;
+ uint64_t size;
+ uint64_t orig_size;
+ uint64_t plaintext_size;
+ uint8_t ivec[16];
+ uint8_t tmpbuf[16];
+ int index;
+
+ if (!mxf->aesc && s->key && s->keylen == 16) {
+ mxf->aesc = av_malloc(av_aes_size);
+ av_aes_init(mxf->aesc, s->key, 128, 1);
+ }
+ // crypto context
+ url_fskip(pb, klv_decode_ber_length(pb));
+ // plaintext offset
+ klv_decode_ber_length(pb);
+ plaintext_size = get_be64(pb);
+ // source klv key
+ klv_decode_ber_length(pb);
+ get_buffer(pb, klv->key, 16);
+ if (!IS_KLV_KEY(klv, mxf_essence_element_key)) goto err_out;
+ index = mxf_get_stream_index(s, klv);
+ if (index < 0) goto err_out;
+ // source size
+ klv_decode_ber_length(pb);
+ orig_size = get_be64(pb);
+ if (orig_size < plaintext_size) goto err_out;
+ // enc. code
+ size = klv_decode_ber_length(pb);
+ if (size < 32 || size - 32 < orig_size) goto err_out;
+ get_buffer(pb, ivec, 16);
+ get_buffer(pb, tmpbuf, 16);
+ if (mxf->aesc)
+ av_aes_crypt(mxf->aesc, tmpbuf, tmpbuf, 1, ivec, 1);
+ if (memcmp(tmpbuf, checkv, 16))
+ av_log(s, AV_LOG_ERROR, "probably incorrect decryption key\n");
+ size -= 32;
+ av_get_packet(pb, pkt, size);
+ size -= plaintext_size;
+ if (mxf->aesc)
+ av_aes_crypt(mxf->aesc, &pkt->data[plaintext_size],
+ &pkt->data[plaintext_size], size >> 4, ivec, 1);
+ pkt->size = orig_size;
+ pkt->stream_index = index;
+ url_fskip(pb, end - url_ftell(pb));
+ return 0;
+
+err_out:
+ url_fskip(pb, end - url_ftell(pb));
+ return -1;
+}
+
+static int mxf_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ MXFContext *mxf = s->priv_data;
+ KLVPacket klv;
+
+ while (!url_feof(&s->pb)) {
+ if (klv_read_packet(&klv, &s->pb) < 0) {
+ av_log(s, AV_LOG_ERROR, "error reading KLV packet\n");
+ return -1;
+ }
+#ifdef DEBUG
+ PRINT_KEY(s, "read packet", klv.key);
+#endif
+ if (IS_KLV_KEY(klv.key, mxf_encrypted_triplet_key)) {
+ int res = mxf_decrypt_triplet(s, pkt, &klv);
+ mxf->sync_key = mxf_encrypted_triplet_key;
+ if (res < 0) {
+ av_log(s, AV_LOG_ERROR, "invalid encoded triplet\n");
+ return -1;
+ }
+ return 0;
+ }
+ if (IS_KLV_KEY(klv.key, mxf_essence_element_key)) {
+ int index = mxf_get_stream_index(s, &klv);
+ if (index < 0) {
+ av_log(s, AV_LOG_ERROR, "error getting stream index\n");
+ url_fskip(&s->pb, klv.length);
+ return -1;
+ }
+ /* check for 8 channels AES3 element */
+ if (klv.key[12] == 0x06 && klv.key[13] == 0x01 && klv.key[14] == 0x10) {
+ if (mxf_get_d10_aes3_packet(&s->pb, s->streams[index], pkt, klv.length) < 0) {
+ av_log(s, AV_LOG_ERROR, "error reading D-10 aes3 frame\n");
+ return -1;
+ }
+ } else
+ av_get_packet(&s->pb, pkt, klv.length);
+ pkt->stream_index = index;
+ return 0;
+ } else
+ url_fskip(&s->pb, klv.length);
+ }
+ return AVERROR_IO;
+}
+
+static int mxf_add_metadata_set(MXFContext *mxf, void *metadata_set)
+{
+ mxf->metadata_sets = av_realloc(mxf->metadata_sets, (mxf->metadata_sets_count + 1) * sizeof(*mxf->metadata_sets));
+ mxf->metadata_sets[mxf->metadata_sets_count] = metadata_set;
+ mxf->metadata_sets_count++;
+ return 0;
+}
+
+static int mxf_read_metadata_cryptographic_context(MXFCryptoContext *cryptocontext, ByteIOContext *pb, int tag)
+{
+ switch(tag) {
+ case 0xFFFE:
+ get_buffer(pb, cryptocontext->context_uid, 16);
+ break;
+ case 0xFFFD:
+ get_buffer(pb, cryptocontext->source_container_ul, 16);
+ break;
+ }
+ return 0;
+}
+
+static int mxf_read_metadata_content_storage(MXFContext *mxf, ByteIOContext *pb, int tag)
+{
+ switch (tag) {
+ case 0x1901:
+ mxf->packages_count = get_be32(pb);
+ if (mxf->packages_count >= UINT_MAX / sizeof(UID))
+ return -1;
+ mxf->packages_refs = av_malloc(mxf->packages_count * sizeof(UID));
+ url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */
+ get_buffer(pb, (uint8_t *)mxf->packages_refs, mxf->packages_count * sizeof(UID));
+ break;
+ }
+ return 0;
+}
+
+static int mxf_read_metadata_source_clip(MXFStructuralComponent *source_clip, ByteIOContext *pb, int tag)
+{
+ switch(tag) {
+ case 0x0202:
+ source_clip->duration = get_be64(pb);
+ break;
+ case 0x1201:
+ source_clip->start_position = get_be64(pb);
+ break;
+ case 0x1101:
+ /* UMID, only get last 16 bytes */
+ url_fskip(pb, 16);
+ get_buffer(pb, source_clip->source_package_uid, 16);
+ break;
+ case 0x1102:
+ source_clip->source_track_id = get_be32(pb);
+ break;
+ }
+ return 0;
+}
+
+static int mxf_read_metadata_material_package(MXFPackage *package, ByteIOContext *pb, int tag)
+{
+ switch(tag) {
+ case 0x4403:
+ package->tracks_count = get_be32(pb);
+ if (package->tracks_count >= UINT_MAX / sizeof(UID))
+ return -1;
+ package->tracks_refs = av_malloc(package->tracks_count * sizeof(UID));
+ url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */
+ get_buffer(pb, (uint8_t *)package->tracks_refs, package->tracks_count * sizeof(UID));
+ break;
+ }
+ return 0;
+}
+
+static int mxf_read_metadata_track(MXFTrack *track, ByteIOContext *pb, int tag)
+{
+ switch(tag) {
+ case 0x4801:
+ track->track_id = get_be32(pb);
+ break;
+ case 0x4804:
+ get_buffer(pb, track->track_number, 4);
+ break;
+ case 0x4B01:
+ track->edit_rate.den = get_be32(pb);
+ track->edit_rate.num = get_be32(pb);
+ break;
+ case 0x4803:
+ get_buffer(pb, track->sequence_ref, 16);
+ break;
+ }
+ return 0;
+}
+
+static int mxf_read_metadata_sequence(MXFSequence *sequence, ByteIOContext *pb, int tag)
+{
+ switch(tag) {
+ case 0x0202:
+ sequence->duration = get_be64(pb);
+ break;
+ case 0x0201:
+ get_buffer(pb, sequence->data_definition_ul, 16);
+ break;
+ case 0x1001:
+ sequence->structural_components_count = get_be32(pb);
+ if (sequence->structural_components_count >= UINT_MAX / sizeof(UID))
+ return -1;
+ sequence->structural_components_refs = av_malloc(sequence->structural_components_count * sizeof(UID));
+ url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */
+ get_buffer(pb, (uint8_t *)sequence->structural_components_refs, sequence->structural_components_count * sizeof(UID));
+ break;
+ }
+ return 0;
+}
+
+static int mxf_read_metadata_source_package(MXFPackage *package, ByteIOContext *pb, int tag)
+{
+ switch(tag) {
+ case 0x4403:
+ package->tracks_count = get_be32(pb);
+ if (package->tracks_count >= UINT_MAX / sizeof(UID))
+ return -1;
+ package->tracks_refs = av_malloc(package->tracks_count * sizeof(UID));
+ url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */
+ get_buffer(pb, (uint8_t *)package->tracks_refs, package->tracks_count * sizeof(UID));
+ break;
+ case 0x4401:
+ /* UMID, only get last 16 bytes */
+ url_fskip(pb, 16);
+ get_buffer(pb, package->package_uid, 16);
+ break;
+ case 0x4701:
+ get_buffer(pb, package->descriptor_ref, 16);
+ break;
+ }
+ return 0;
+}
+
+static void mxf_read_metadata_pixel_layout(ByteIOContext *pb, MXFDescriptor *descriptor)
+{
+ int code;
+
+ do {
+ code = get_byte(pb);
+ dprintf(NULL, "pixel layout: code 0x%x\n", code);
+ switch (code) {
+ case 0x52: /* R */
+ descriptor->bits_per_sample += get_byte(pb);
+ break;
+ case 0x47: /* G */
+ descriptor->bits_per_sample += get_byte(pb);
+ break;
+ case 0x42: /* B */
+ descriptor->bits_per_sample += get_byte(pb);
+ break;
+ default:
+ get_byte(pb);
+ }
+ } while (code != 0); /* SMPTE 377M E.2.46 */
+}
+
+static int mxf_read_metadata_generic_descriptor(MXFDescriptor *descriptor, ByteIOContext *pb, int tag, int size)
+{
+ switch(tag) {
+ case 0x3F01:
+ descriptor->sub_descriptors_count = get_be32(pb);
+ if (descriptor->sub_descriptors_count >= UINT_MAX / sizeof(UID))
+ return -1;
+ descriptor->sub_descriptors_refs = av_malloc(descriptor->sub_descriptors_count * sizeof(UID));
+ url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */
+ get_buffer(pb, (uint8_t *)descriptor->sub_descriptors_refs, descriptor->sub_descriptors_count * sizeof(UID));
+ break;
+ case 0x3004:
+ get_buffer(pb, descriptor->essence_container_ul, 16);
+ break;
+ case 0x3006:
+ descriptor->linked_track_id = get_be32(pb);
+ break;
+ case 0x3201: /* PictureEssenceCoding */
+ get_buffer(pb, descriptor->essence_codec_ul, 16);
+ break;
+ case 0x3203:
+ descriptor->width = get_be32(pb);
+ break;
+ case 0x3202:
+ descriptor->height = get_be32(pb);
+ break;
+ case 0x320E:
+ descriptor->aspect_ratio.num = get_be32(pb);
+ descriptor->aspect_ratio.den = get_be32(pb);
+ break;
+ case 0x3D03:
+ descriptor->sample_rate.num = get_be32(pb);
+ descriptor->sample_rate.den = get_be32(pb);
+ break;
+ case 0x3D06: /* SoundEssenceCompression */
+ get_buffer(pb, descriptor->essence_codec_ul, 16);
+ break;
+ case 0x3D07:
+ descriptor->channels = get_be32(pb);
+ break;
+ case 0x3D01:
+ descriptor->bits_per_sample = get_be32(pb);
+ break;
+ case 0x3401:
+ mxf_read_metadata_pixel_layout(pb, descriptor);
+ break;
+ case 0x8201: /* Private tag used by SONY C0023S01.mxf */
+ descriptor->extradata = av_malloc(size);
+ descriptor->extradata_size = size;
+ get_buffer(pb, descriptor->extradata, size);
+ break;
+ }
+ return 0;
+}
+
+/* SMPTE RP224 http://www.smpte-ra.org/mdd/index.html */
+static const MXFDataDefinitionUL mxf_data_definition_uls[] = {
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x01,0x03,0x02,0x02,0x01,0x00,0x00,0x00 }, CODEC_TYPE_VIDEO },
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x01,0x03,0x02,0x02,0x02,0x00,0x00,0x00 }, CODEC_TYPE_AUDIO },
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x05,0x01,0x03,0x02,0x02,0x02,0x02,0x00,0x00 }, CODEC_TYPE_AUDIO },
+ { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, CODEC_TYPE_DATA },
+};
+
+static const MXFCodecUL mxf_codec_uls[] = {
+ /* PictureEssenceCoding */
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x02,0x02,0x00 }, CODEC_ID_MPEG2VIDEO, Frame }, /* 422P@ML I-Frame */
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x04,0x02,0x00 }, CODEC_ID_MPEG2VIDEO, Frame }, /* 422P@HL I-Frame */
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x04,0x03,0x00 }, CODEC_ID_MPEG2VIDEO, Frame }, /* 422P@HL Long GoP */
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x01,0x11,0x00 }, CODEC_ID_MPEG2VIDEO, Frame }, /* MP@ML Long GoP */
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x02,0x03,0x00 }, CODEC_ID_MPEG2VIDEO, Frame }, /* 422P@ML Long GoP */
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x03,0x03,0x00 }, CODEC_ID_MPEG2VIDEO, Frame }, /* MP@HL Long GoP */
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x20,0x02,0x03 }, CODEC_ID_MPEG4, Frame }, /* XDCAM proxy_pal030926.mxf */
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x20,0x02,0x04 }, CODEC_ID_MPEG4, Frame }, /* XDCAM Proxy C0023S01.mxf */
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x05 }, CODEC_ID_MPEG2VIDEO, Frame }, /* D-10 30Mbps PAL */
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x01 }, CODEC_ID_MPEG2VIDEO, Frame }, /* D-10 50Mbps PAL */
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x04,0x00 }, CODEC_ID_DVVIDEO, Frame }, /* DVCPRO50 PAL */
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x02,0x00 }, CODEC_ID_DVVIDEO, Frame }, /* DVCPRO25 PAL */
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x01,0x02,0x00 }, CODEC_ID_DVVIDEO, Frame }, /* DV25 IEC PAL */
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x07,0x04,0x01,0x02,0x02,0x03,0x01,0x01,0x00 }, CODEC_ID_JPEG2000, Frame }, /* JPEG2000 Codestream */
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x01,0x7F,0x00,0x00,0x00 }, CODEC_ID_RAWVIDEO, Frame }, /* Uncompressed */
+ /* SoundEssenceCompression */
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 }, CODEC_ID_PCM_S16LE, Frame }, /* Uncompressed */
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x7F,0x00,0x00,0x00 }, CODEC_ID_PCM_S16LE, Frame },
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x07,0x04,0x02,0x02,0x01,0x7E,0x00,0x00,0x00 }, CODEC_ID_PCM_S16BE, Frame }, /* From Omneon MXF file */
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x02,0x03,0x01,0x01,0x00 }, CODEC_ID_PCM_ALAW, Frame },
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x04,0x04,0x02,0x02,0x02,0x03,0x01,0x01,0x00 }, CODEC_ID_PCM_ALAW, Frame }, /* XDCAM Proxy C0023S01.mxf */
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x02,0x03,0x02,0x01,0x00 }, CODEC_ID_AC3, Frame },
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x02,0x03,0x02,0x05,0x00 }, CODEC_ID_MP2, Frame }, /* MP2 or MP3 */
+ //{ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x02,0x03,0x02,0x1C,0x00 }, CODEC_ID_DOLBY_E, Frame }, /* Dolby-E */
+ { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, CODEC_ID_NONE, Frame },
+};
+
+static const MXFCodecUL mxf_picture_essence_container_uls[] = {
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0x60,0x01 }, CODEC_ID_MPEG2VIDEO, Frame }, /* MPEG-ES Frame wrapped */
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0xe0,0x02 }, CODEC_ID_MPEG2VIDEO, Clip }, /* MPEG-ES Clip wrapped, 0xe0 MPV stream id */
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x04,0x61,0x07 }, CODEC_ID_MPEG2VIDEO, Clip }, /* MPEG-ES Custom wrapped, 0x61 ??? stream id */
+ { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, CODEC_ID_NONE, Frame },
+};
+
+static const MXFCodecUL mxf_sound_essence_container_uls[] = {
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x06,0x01,0x00 }, CODEC_ID_PCM_S16LE, Frame }, /* BWF Frame wrapped */
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x06,0x03,0x00 }, CODEC_ID_PCM_S16LE, Frame }, /* AES Frame wrapped */
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0x40,0x01 }, CODEC_ID_MP2, Frame }, /* MPEG-ES Frame wrapped, 0x40 ??? stream id */
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0xc0,0x01 }, CODEC_ID_MP2, Frame }, /* MPEG-ES Frame wrapped, 0xc0 MPA stream id */
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0xc0,0x02 }, CODEC_ID_MP2, Clip }, /* MPEG-ES Clip wrapped, 0xc0 MPA stream id */
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x05,0x01 }, CODEC_ID_PCM_S16BE, Frame }, /* D-10 Mapping 30Mbps PAL Extended Template */
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x01,0x01 }, CODEC_ID_PCM_S16BE, Frame }, /* D-10 Mapping 50Mbps PAL Extended Template */
+ { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, CODEC_ID_NONE, Frame },
+};
+
+static const MXFCodecUL *mxf_get_codec_ul(const MXFCodecUL *uls, UID *uid)
+{
+ while (uls->id != CODEC_ID_NONE) {
+ if(!memcmp(uls->uid, *uid, 16))
+ break;
+ uls++;
+ }
+ return uls;
+}
+
+static enum CodecType mxf_get_codec_type(const MXFDataDefinitionUL *uls, UID *uid)
+{
+ while (uls->type != CODEC_TYPE_DATA) {
+ if(!memcmp(uls->uid, *uid, 16))
+ break;
+ uls++;
+ }
+ return uls->type;
+}
+
+static void *mxf_resolve_strong_ref(MXFContext *mxf, UID *strong_ref, enum MXFMetadataSetType type)
+{
+ int i;
+
+ if (!strong_ref)
+ return NULL;
+ for (i = 0; i < mxf->metadata_sets_count; i++) {
+ if (!memcmp(*strong_ref, mxf->metadata_sets[i]->uid, 16) &&
+ (type == AnyType || mxf->metadata_sets[i]->type == type)) {
+ return mxf->metadata_sets[i];
+ }
+ }
+ return NULL;
+}
+
+static int mxf_parse_structural_metadata(MXFContext *mxf)
+{
+ MXFPackage *material_package = NULL;
+ MXFPackage *temp_package = NULL;
+ int i, j, k;
+
+ dprintf(mxf->fc, "metadata sets count %d\n", mxf->metadata_sets_count);
+ /* TODO: handle multiple material packages (OP3x) */
+ for (i = 0; i < mxf->packages_count; i++) {
+ material_package = mxf_resolve_strong_ref(mxf, &mxf->packages_refs[i], MaterialPackage);
+ if (material_package) break;
+ }
+ if (!material_package) {
+ av_log(mxf->fc, AV_LOG_ERROR, "no material package found\n");
+ return -1;
+ }
+
+ for (i = 0; i < material_package->tracks_count; i++) {
+ MXFPackage *source_package = NULL;
+ MXFTrack *material_track = NULL;
+ MXFTrack *source_track = NULL;
+ MXFTrack *temp_track = NULL;
+ MXFDescriptor *descriptor = NULL;
+ MXFStructuralComponent *component = NULL;
+ UID *essence_container_ul = NULL;
+ const MXFCodecUL *codec_ul = NULL;
+ const MXFCodecUL *container_ul = NULL;
+ AVStream *st;
+
+ if (!(material_track = mxf_resolve_strong_ref(mxf, &material_package->tracks_refs[i], Track))) {
+ av_log(mxf->fc, AV_LOG_ERROR, "could not resolve material track strong ref\n");
+ continue;
+ }
+
+ 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;
+ }
+
+ /* TODO: handle multiple source clips */
+ for (j = 0; j < material_track->sequence->structural_components_count; j++) {
+ /* TODO: handle timecode component */
+ component = mxf_resolve_strong_ref(mxf, &material_track->sequence->structural_components_refs[j], SourceClip);
+ if (!component)
+ continue;
+
+ for (k = 0; k < mxf->packages_count; k++) {
+ temp_package = mxf_resolve_strong_ref(mxf, &mxf->packages_refs[k], SourcePackage);
+ if (!temp_package)
+ continue;
+ if (!memcmp(temp_package->package_uid, component->source_package_uid, 16)) {
+ source_package = temp_package;
+ break;
+ }
+ }
+ if (!source_package) {
+ av_log(mxf->fc, AV_LOG_ERROR, "material track %d: no corresponding source package found\n", material_track->track_id);
+ break;
+ }
+ for (k = 0; k < source_package->tracks_count; k++) {
+ if (!(temp_track = mxf_resolve_strong_ref(mxf, &source_package->tracks_refs[k], Track))) {
+ av_log(mxf->fc, AV_LOG_ERROR, "could not resolve source track strong ref\n");
+ return -1;
+ }
+ if (temp_track->track_id == component->source_track_id) {
+ source_track = temp_track;
+ break;
+ }
+ }
+ if (!source_track) {
+ av_log(mxf->fc, AV_LOG_ERROR, "material track %d: no corresponding source track found\n", material_track->track_id);
+ break;
+ }
+ }
+ if (!source_track)
+ continue;
+
+ st = av_new_stream(mxf->fc, source_track->track_id);
+ st->priv_data = source_track;
+ st->duration = component->duration;
+ if (st->duration == -1)
+ st->duration = AV_NOPTS_VALUE;
+ st->start_time = component->start_position;
+ av_set_pts_info(st, 64, material_track->edit_rate.num, material_track->edit_rate.den);
+
+ if (!(source_track->sequence = mxf_resolve_strong_ref(mxf, &source_track->sequence_ref, Sequence))) {
+ av_log(mxf->fc, AV_LOG_ERROR, "could not resolve source track sequence strong ref\n");
+ return -1;
+ }
+
+#ifdef DEBUG
+ PRINT_KEY(mxf->fc, "data definition ul", source_track->sequence->data_definition_ul);
+#endif
+ st->codec->codec_type = mxf_get_codec_type(mxf_data_definition_uls, &source_track->sequence->data_definition_ul);
+
+ source_package->descriptor = mxf_resolve_strong_ref(mxf, &source_package->descriptor_ref, AnyType);
+ if (source_package->descriptor) {
+ if (source_package->descriptor->type == MultipleDescriptor) {
+ for (j = 0; j < source_package->descriptor->sub_descriptors_count; j++) {
+ MXFDescriptor *sub_descriptor = mxf_resolve_strong_ref(mxf, &source_package->descriptor->sub_descriptors_refs[j], Descriptor);
+
+ if (!sub_descriptor) {
+ av_log(mxf->fc, AV_LOG_ERROR, "could not resolve sub descriptor strong ref\n");
+ continue;
+ }
+ if (sub_descriptor->linked_track_id == source_track->track_id) {
+ descriptor = sub_descriptor;
+ break;
+ }
+ }
+ } else if (source_package->descriptor->type == Descriptor)
+ descriptor = source_package->descriptor;
+ }
+ if (!descriptor) {
+ av_log(mxf->fc, AV_LOG_INFO, "source track %d: stream %d, no descriptor found\n", source_track->track_id, st->index);
+ continue;
+ }
+#ifdef DEBUG
+ PRINT_KEY(mxf->fc, "essence codec ul", descriptor->essence_codec_ul);
+ PRINT_KEY(mxf->fc, "essence container ul", descriptor->essence_container_ul);
+#endif
+ essence_container_ul = &descriptor->essence_container_ul;
+ /* HACK: replacing the original key with mxf_encrypted_essence_container
+ * is not allowed according to s429-6, try to find correct information anyway */
+ if (IS_KLV_KEY(essence_container_ul, mxf_encrypted_essence_container)) {
+ av_log(mxf->fc, AV_LOG_INFO, "broken encrypted mxf file\n");
+ for (k = 0; k < mxf->metadata_sets_count; k++) {
+ MXFMetadataSet *metadata = mxf->metadata_sets[k];
+ if (metadata->type == CryptoContext) {
+ essence_container_ul = &((MXFCryptoContext *)metadata)->source_container_ul;
+ break;
+ }
+ }
+ }
+ /* TODO: drop PictureEssenceCoding and SoundEssenceCompression, only check EssenceContainer */
+ codec_ul = mxf_get_codec_ul(mxf_codec_uls, &descriptor->essence_codec_ul);
+ st->codec->codec_id = codec_ul->id;
+ if (descriptor->extradata) {
+ st->codec->extradata = descriptor->extradata;
+ st->codec->extradata_size = descriptor->extradata_size;
+ }
+ if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
+ container_ul = mxf_get_codec_ul(mxf_picture_essence_container_uls, essence_container_ul);
+ if (st->codec->codec_id == CODEC_ID_NONE)
+ st->codec->codec_id = container_ul->id;
+ st->codec->width = descriptor->width;
+ st->codec->height = descriptor->height;
+ st->codec->bits_per_sample = descriptor->bits_per_sample; /* Uncompressed */
+ st->need_parsing = 2; /* only parse headers */
+ } else if (st->codec->codec_type == CODEC_TYPE_AUDIO) {
+ container_ul = mxf_get_codec_ul(mxf_sound_essence_container_uls, essence_container_ul);
+ if (st->codec->codec_id == CODEC_ID_NONE)
+ st->codec->codec_id = container_ul->id;
+ st->codec->channels = descriptor->channels;
+ st->codec->bits_per_sample = descriptor->bits_per_sample;
+ st->codec->sample_rate = descriptor->sample_rate.num / descriptor->sample_rate.den;
+ /* TODO: implement CODEC_ID_RAWAUDIO */
+ if (st->codec->codec_id == CODEC_ID_PCM_S16LE) {
+ if (descriptor->bits_per_sample == 24)
+ st->codec->codec_id = CODEC_ID_PCM_S24LE;
+ else if (descriptor->bits_per_sample == 32)
+ st->codec->codec_id = CODEC_ID_PCM_S32LE;
+ } else if (st->codec->codec_id == CODEC_ID_PCM_S16BE) {
+ if (descriptor->bits_per_sample == 24)
+ st->codec->codec_id = CODEC_ID_PCM_S24BE;
+ else if (descriptor->bits_per_sample == 32)
+ st->codec->codec_id = CODEC_ID_PCM_S32BE;
+ if (descriptor->essence_container_ul[13] == 0x01) /* D-10 Mapping */
+ st->codec->channels = 8; /* force channels to 8 */
+ } else if (st->codec->codec_id == CODEC_ID_MP2) {
+ st->need_parsing = 1;
+ }
+ }
+ if (container_ul && container_ul->wrapping == Clip) {
+ dprintf(mxf->fc, "stream %d: clip wrapped essence\n", st->index);
+ st->need_parsing = 1;
+ }
+ }
+ return 0;
+}
+
+static const MXFMetadataReadTableEntry mxf_metadata_read_table[] = {
+ { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x18,0x00 }, mxf_read_metadata_content_storage, 0, AnyType },
+ { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x37,0x00 }, mxf_read_metadata_source_package, sizeof(MXFPackage), SourcePackage },
+ { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x36,0x00 }, mxf_read_metadata_material_package, sizeof(MXFPackage), MaterialPackage },
+ { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x0F,0x00 }, mxf_read_metadata_sequence, sizeof(MXFSequence), Sequence },
+ { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x11,0x00 }, mxf_read_metadata_source_clip, sizeof(MXFStructuralComponent), SourceClip },
+ { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x44,0x00 }, mxf_read_metadata_generic_descriptor, sizeof(MXFDescriptor), MultipleDescriptor },
+ { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x42,0x00 }, mxf_read_metadata_generic_descriptor, sizeof(MXFDescriptor), Descriptor }, /* Generic Sound */
+ { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x28,0x00 }, mxf_read_metadata_generic_descriptor, sizeof(MXFDescriptor), Descriptor }, /* CDCI */
+ { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x29,0x00 }, mxf_read_metadata_generic_descriptor, sizeof(MXFDescriptor), Descriptor }, /* RGBA */
+ { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x51,0x00 }, mxf_read_metadata_generic_descriptor, sizeof(MXFDescriptor), Descriptor }, /* MPEG 2 Video */
+ { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x48,0x00 }, mxf_read_metadata_generic_descriptor, sizeof(MXFDescriptor), Descriptor }, /* Wave */
+ { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x47,0x00 }, mxf_read_metadata_generic_descriptor, sizeof(MXFDescriptor), Descriptor }, /* AES3 */
+ { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x3A,0x00 }, mxf_read_metadata_track, sizeof(MXFTrack), Track }, /* Static Track */
+ { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x3B,0x00 }, mxf_read_metadata_track, sizeof(MXFTrack), Track }, /* Generic Track */
+ { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x04,0x01,0x02,0x02,0x00,0x00 }, mxf_read_metadata_cryptographic_context, sizeof(MXFCryptoContext), CryptoContext },
+ { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, NULL, 0, AnyType },
+};
+
+static int mxf_read_sync(ByteIOContext *pb, const uint8_t *key, unsigned size)
+{
+ int i, b;
+ for (i = 0; i < size && !url_feof(pb); i++) {
+ b = get_byte(pb);
+ if (b == key[0])
+ i = 0;
+ else if (b != key[i])
+ i = -1;
+ }
+ return i == size;
+}
+
+static int mxf_read_local_tags(MXFContext *mxf, KLVPacket *klv, int (*read_child)(), int ctx_size, enum MXFMetadataSetType type)
+{
+ ByteIOContext *pb = &mxf->fc->pb;
+ MXFMetadataSet *ctx = ctx_size ? av_mallocz(ctx_size) : mxf;
+ uint64_t klv_end= url_ftell(pb) + klv->length;
+
+ while (url_ftell(pb) + 4 < klv_end) {
+ int tag = get_be16(pb);
+ int size = get_be16(pb); /* KLV specified by 0x53 */
+ uint64_t next= url_ftell(pb) + size;
+
+ if (!size) { /* ignore empty tag, needed for some files with empty UMID tag */
+ av_log(mxf->fc, AV_LOG_ERROR, "local tag 0x%04X with 0 size\n", tag);
+ continue;
+ }
+ if(ctx_size && tag == 0x3C0A)
+ get_buffer(pb, ctx->uid, 16);
+ else
+ read_child(ctx, pb, tag, size);
+
+ url_fseek(pb, next, SEEK_SET);
+ }
+ if (ctx_size) ctx->type = type;
+ return ctx_size ? mxf_add_metadata_set(mxf, ctx) : 0;
+}
+
+static int mxf_read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+ MXFContext *mxf = s->priv_data;
+ KLVPacket klv;
+
+ mxf->sync_key = mxf_essence_element_key;
+ if (!mxf_read_sync(&s->pb, mxf_header_partition_pack_key, 14)) {
+ av_log(s, AV_LOG_ERROR, "could not find header partition pack key\n");
+ return -1;
+ }
+ url_fseek(&s->pb, -14, SEEK_CUR);
+ mxf->fc = s;
+ while (!url_feof(&s->pb)) {
+ const MXFMetadataReadTableEntry *metadata;
+
+ if (klv_read_packet(&klv, &s->pb) < 0) {
+ av_log(s, AV_LOG_ERROR, "error reading KLV packet\n");
+ return -1;
+ }
+#ifdef DEBUG
+ PRINT_KEY(s, "read header", klv.key);
+#endif
+ if (IS_KLV_KEY(klv.key, mxf_encrypted_triplet_key) ||
+ IS_KLV_KEY(klv.key, mxf_essence_element_key)) {
+ /* FIXME avoid seek */
+ url_fseek(&s->pb, klv.offset, SEEK_SET);
+ break;
+ }
+
+ for (metadata = mxf_metadata_read_table; metadata->read; metadata++) {
+ if (IS_KLV_KEY(klv.key, metadata->key)) {
+ if (mxf_read_local_tags(mxf, &klv, metadata->read, metadata->ctx_size, metadata->type) < 0) {
+ av_log(s, AV_LOG_ERROR, "error reading header metadata\n");
+ return -1;
+ }
+ break;
+ }
+ }
+ if (!metadata->read)
+ url_fskip(&s->pb, klv.length);
+ }
+ return mxf_parse_structural_metadata(mxf);
+}
+
+static int mxf_read_close(AVFormatContext *s)
+{
+ MXFContext *mxf = s->priv_data;
+ int i;
+
+ av_freep(&mxf->packages_refs);
+ for (i = 0; i < mxf->metadata_sets_count; i++) {
+ switch (mxf->metadata_sets[i]->type) {
+ case MultipleDescriptor:
+ av_freep(&((MXFDescriptor *)mxf->metadata_sets[i])->sub_descriptors_refs);
+ break;
+ case Sequence:
+ av_freep(&((MXFSequence *)mxf->metadata_sets[i])->structural_components_refs);
+ break;
+ case SourcePackage:
+ case MaterialPackage:
+ av_freep(&((MXFPackage *)mxf->metadata_sets[i])->tracks_refs);
+ break;
+ default:
+ break;
+ }
+ av_freep(&mxf->metadata_sets[i]);
+ }
+ av_freep(&mxf->metadata_sets);
+ av_freep(&mxf->aesc);
+ return 0;
+}
+
+static int mxf_probe(AVProbeData *p) {
+ uint8_t *bufp = p->buf;
+ uint8_t *end = p->buf + p->buf_size;
+
+ if (p->buf_size < sizeof(mxf_header_partition_pack_key))
+ return 0;
+
+ /* Must skip Run-In Sequence and search for MXF header partition pack key SMPTE 377M 5.5 */
+ end -= sizeof(mxf_header_partition_pack_key);
+ for (; bufp < end; bufp++) {
+ if (IS_KLV_KEY(bufp, mxf_header_partition_pack_key))
+ return AVPROBE_SCORE_MAX;
+ }
+ return 0;
+}
+
+/* rudimentary binary seek */
+/* XXX: use MXF Index */
+static int mxf_read_seek(AVFormatContext *s, int stream_index, int64_t sample_time, int flags)
+{
+ MXFContext *mxf = s->priv_data;
+ AVStream *st = s->streams[stream_index];
+ int64_t seconds;
+
+ if (!s->bit_rate)
+ return -1;
+ if (sample_time < 0)
+ sample_time = 0;
+ seconds = av_rescale(sample_time, st->time_base.num, st->time_base.den);
+ url_fseek(&s->pb, (s->bit_rate * seconds) >> 3, SEEK_SET);
+ if (!mxf_read_sync(&s->pb, mxf->sync_key, 12))
+ return -1;
+
+ /* found KLV key */
+ url_fseek(&s->pb, -12, SEEK_CUR);
+ av_update_cur_dts(s, st, sample_time);
+ return 0;
+}
+
+AVInputFormat mxf_demuxer = {
+ "mxf",
+ "MXF format",
+ sizeof(MXFContext),
+ mxf_probe,
+ mxf_read_header,
+ mxf_read_packet,
+ mxf_read_close,
+ mxf_read_seek,
+};
diff --git a/contrib/ffmpeg/libavformat/network.h b/contrib/ffmpeg/libavformat/network.h
new file mode 100644
index 000000000..3aa8ba836
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/network.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2007 The FFmpeg Project.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef NETWORK_H
+#define NETWORK_H
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#include <netdb.h>
+
+#if !defined(HAVE_INET_ATON)
+/* in os_support.c */
+int inet_aton (const char * str, struct in_addr * add);
+#endif
+
+#endif
diff --git a/contrib/ffmpeg/libavformat/nsvdec.c b/contrib/ffmpeg/libavformat/nsvdec.c
new file mode 100644
index 000000000..2753edbd9
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/nsvdec.c
@@ -0,0 +1,765 @@
+/*
+ * NSV demuxer
+ * Copyright (c) 2004 The FFmpeg Project.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include "avformat.h"
+#include "riff.h"
+
+//#define DEBUG
+//#define DEBUG_DUMP_INDEX // XXX dumbdriving-271.nsv breaks with it commented!!
+//#define DEBUG_SEEK
+#define CHECK_SUBSEQUENT_NSVS
+//#define DISABLE_AUDIO
+
+/* max bytes to crawl for trying to resync
+ * stupid streaming servers don't start at chunk boundaries...
+ */
+#define NSV_MAX_RESYNC (500*1024)
+#define NSV_MAX_RESYNC_TRIES 300
+
+/*
+ * First version by Francois Revol - revol@free.fr
+ * References:
+ * (1) http://www.multimedia.cx/nsv-format.txt
+ * seems someone came to the same conclusions as me, and updated it:
+ * (2) http://www.stud.ktu.lt/~vitslav/nsv/nsv-format.txt
+ * http://www.stud.ktu.lt/~vitslav/nsv/
+ * official docs
+ * (3) http://ultravox.aol.com/NSVFormat.rtf
+ * Sample files:
+ * (S1) http://www.nullsoft.com/nsv/samples/
+ * http://www.nullsoft.com/nsv/samples/faster.nsv
+ * http://streamripper.sourceforge.net/openbb/read.php?TID=492&page=4
+ */
+
+/*
+ * notes on the header (Francois Revol):
+ *
+ * It is followed by strings, then a table, but nothing tells
+ * where the table begins according to (1). After checking faster.nsv,
+ * I believe NVSf[16-19] gives the size of the strings data
+ * (that is the offset of the data table after the header).
+ * After checking all samples from (S1) all confirms this.
+ *
+ * Then, about NSVf[12-15], faster.nsf has 179700. When veiwing it in VLC,
+ * I noticed there was about 1 NVSs chunk/s, so I ran
+ * strings faster.nsv | grep NSVs | wc -l
+ * which gave me 180. That leads me to think that NSVf[12-15] might be the
+ * file length in milliseconds.
+ * Let's try that:
+ * for f in *.nsv; do HTIME="$(od -t x4 "$f" | head -1 | sed 's/.* //')"; echo "'$f' $((0x$HTIME))s = $((0x$HTIME/1000/60)):$((0x$HTIME/1000%60))"; done
+ * except for nstrailer (which doesn't have an NSVf header), it repports correct time.
+ *
+ * nsvtrailer.nsv (S1) does not have any NSVf header, only NSVs chunks,
+ * so the header seems to not be mandatory. (for streaming).
+ *
+ * index slice duration check (excepts nsvtrailer.nsv):
+ * for f in [^n]*.nsv; do DUR="$(ffmpeg -i "$f" 2>/dev/null | grep 'NSVf duration' | cut -d ' ' -f 4)"; IC="$(ffmpeg -i "$f" 2>/dev/null | grep 'INDEX ENTRIES' | cut -d ' ' -f 2)"; echo "duration $DUR, slite time $(($DUR/$IC))"; done
+ */
+
+/*
+ * TODO:
+ * - handle timestamps !!!
+ * - use index
+ * - mime-type in probe()
+ * - seek
+ */
+
+#ifdef DEBUG
+#define PRINT(_v) printf _v
+#else
+#define PRINT(_v)
+#endif
+
+#if 0
+struct NSVf_header {
+ uint32_t chunk_tag; /* 'NSVf' */
+ uint32_t chunk_size;
+ uint32_t file_size; /* max 4GB ??? noone learns anything it seems :^) */
+ uint32_t file_length; //unknown1; /* what about MSB of file_size ? */
+ uint32_t info_strings_size; /* size of the info strings */ //unknown2;
+ uint32_t table_entries;
+ uint32_t table_entries_used; /* the left ones should be -1 */
+};
+
+struct NSVs_header {
+ uint32_t chunk_tag; /* 'NSVs' */
+ uint32_t v4cc; /* or 'NONE' */
+ uint32_t a4cc; /* or 'NONE' */
+ uint16_t vwidth; /* assert(vwidth%16==0) */
+ uint16_t vheight; /* assert(vheight%16==0) */
+ uint8_t framerate; /* value = (framerate&0x80)?frtable[frameratex0x7f]:framerate */
+ uint16_t unknown;
+};
+
+struct nsv_avchunk_header {
+ uint8_t vchunk_size_lsb;
+ uint16_t vchunk_size_msb; /* value = (vchunk_size_msb << 4) | (vchunk_size_lsb >> 4) */
+ uint16_t achunk_size;
+};
+
+struct nsv_pcm_header {
+ uint8_t bits_per_sample;
+ uint8_t channel_count;
+ uint16_t sample_rate;
+};
+#endif
+
+/* variation from avi.h */
+/*typedef struct CodecTag {
+ int id;
+ unsigned int tag;
+} CodecTag;*/
+
+/* tags */
+
+#define T_NSVF MKTAG('N', 'S', 'V', 'f') /* file header */
+#define T_NSVS MKTAG('N', 'S', 'V', 's') /* chunk header */
+#define T_TOC2 MKTAG('T', 'O', 'C', '2') /* extra index marker */
+#define T_NONE MKTAG('N', 'O', 'N', 'E') /* null a/v 4CC */
+#define T_SUBT MKTAG('S', 'U', 'B', 'T') /* subtitle aux data */
+#define T_ASYN MKTAG('A', 'S', 'Y', 'N') /* async a/v aux marker */
+#define T_KEYF MKTAG('K', 'E', 'Y', 'F') /* video keyframe aux marker (addition) */
+
+#define TB_NSVF MKBETAG('N', 'S', 'V', 'f')
+#define TB_NSVS MKBETAG('N', 'S', 'V', 's')
+
+/* hardcoded stream indices */
+#define NSV_ST_VIDEO 0
+#define NSV_ST_AUDIO 1
+#define NSV_ST_SUBT 2
+
+enum NSVStatus {
+ NSV_UNSYNC,
+ NSV_FOUND_NSVF,
+ NSV_HAS_READ_NSVF,
+ NSV_FOUND_NSVS,
+ NSV_HAS_READ_NSVS,
+ NSV_FOUND_BEEF,
+ NSV_GOT_VIDEO,
+ NSV_GOT_AUDIO,
+};
+
+typedef struct NSVStream {
+ int frame_offset; /* current frame (video) or byte (audio) counter
+ (used to compute the pts) */
+ int scale;
+ int rate;
+ int sample_size; /* audio only data */
+ int start;
+
+ int new_frame_offset; /* temporary storage (used during seek) */
+ int cum_len; /* temporary storage (used during seek) */
+} NSVStream;
+
+typedef struct {
+ int base_offset;
+ int NSVf_end;
+ uint32_t *nsvf_index_data;
+ int index_entries;
+ enum NSVStatus state;
+ AVPacket ahead[2]; /* [v, a] if .data is !NULL there is something */
+ /* cached */
+ int64_t duration;
+ uint32_t vtag, atag;
+ uint16_t vwidth, vheight;
+ int16_t avsync;
+ //DVDemuxContext* dv_demux;
+} NSVContext;
+
+static const AVCodecTag nsv_codec_video_tags[] = {
+ { CODEC_ID_VP3, MKTAG('V', 'P', '3', ' ') },
+ { CODEC_ID_VP3, MKTAG('V', 'P', '3', '0') },
+ { CODEC_ID_VP3, MKTAG('V', 'P', '3', '1') },
+ { CODEC_ID_VP5, MKTAG('V', 'P', '5', ' ') },
+ { CODEC_ID_VP5, MKTAG('V', 'P', '5', '0') },
+ { CODEC_ID_VP6, MKTAG('V', 'P', '6', ' ') },
+ { 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_VP4, MKTAG('V', 'P', '4', ' ') },
+ { CODEC_ID_VP4, MKTAG('V', 'P', '4', '0') },
+*/
+ { CODEC_ID_XVID, MKTAG('X', 'V', 'I', 'D') }, /* cf sample xvid decoder from nsv_codec_sdk.zip */
+ { CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', '3') },
+ { 0, 0 },
+};
+
+static const AVCodecTag nsv_codec_audio_tags[] = {
+ { CODEC_ID_MP3, MKTAG('M', 'P', '3', ' ') },
+ { CODEC_ID_AAC, MKTAG('A', 'A', 'C', ' ') },
+ { CODEC_ID_AAC, MKTAG('A', 'A', 'C', 'P') }, /* _CUTTED__MUXED_2 Heads - Out Of The City.nsv */
+ { CODEC_ID_PCM_U16LE, MKTAG('P', 'C', 'M', ' ') },
+ { 0, 0 },
+};
+
+//static int nsv_load_index(AVFormatContext *s);
+static int nsv_read_chunk(AVFormatContext *s, int fill_header);
+
+#ifdef DEBUG
+static void print_tag(const char *str, unsigned int tag, int size)
+{
+ printf("%s: tag=%c%c%c%c\n",
+ str, tag & 0xff,
+ (tag >> 8) & 0xff,
+ (tag >> 16) & 0xff,
+ (tag >> 24) & 0xff);
+}
+#endif
+
+/* try to find something we recognize, and set the state accordingly */
+static int nsv_resync(AVFormatContext *s)
+{
+ NSVContext *nsv = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ uint32_t v = 0;
+ int i;
+
+ PRINT(("%s(), offset = %"PRId64", state = %d\n", __FUNCTION__, url_ftell(pb), nsv->state));
+
+ //nsv->state = NSV_UNSYNC;
+
+ for (i = 0; i < NSV_MAX_RESYNC; i++) {
+ if (url_feof(pb)) {
+ PRINT(("NSV EOF\n"));
+ nsv->state = NSV_UNSYNC;
+ return -1;
+ }
+ v <<= 8;
+ v |= get_byte(pb);
+/*
+ if (i < 8) {
+ PRINT(("NSV resync: [%d] = %02x\n", i, v & 0x0FF));
+ }
+*/
+
+ if ((v & 0x0000ffff) == 0xefbe) { /* BEEF */
+ PRINT(("NSV resynced on BEEF after %d bytes\n", i+1));
+ nsv->state = NSV_FOUND_BEEF;
+ return 0;
+ }
+ /* we read as big endian, thus the MK*BE* */
+ if (v == TB_NSVF) { /* NSVf */
+ PRINT(("NSV resynced on NSVf after %d bytes\n", i+1));
+ nsv->state = NSV_FOUND_NSVF;
+ return 0;
+ }
+ if (v == MKBETAG('N', 'S', 'V', 's')) { /* NSVs */
+ PRINT(("NSV resynced on NSVs after %d bytes\n", i+1));
+ nsv->state = NSV_FOUND_NSVS;
+ return 0;
+ }
+
+ }
+ PRINT(("NSV sync lost\n"));
+ return -1;
+}
+
+static int nsv_parse_NSVf_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+ NSVContext *nsv = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ unsigned int file_size, size;
+ int64_t duration;
+ int strings_size;
+ int table_entries;
+ int table_entries_used;
+
+ PRINT(("%s()\n", __FUNCTION__));
+
+ nsv->state = NSV_UNSYNC; /* in case we fail */
+
+ size = get_le32(pb);
+ if (size < 28)
+ return -1;
+ nsv->NSVf_end = size;
+
+ //s->file_size = (uint32_t)get_le32(pb);
+ file_size = (uint32_t)get_le32(pb);
+ PRINT(("NSV NSVf chunk_size %u\n", size));
+ PRINT(("NSV NSVf file_size %u\n", file_size));
+
+ nsv->duration = duration = get_le32(pb); /* in ms */
+ PRINT(("NSV NSVf duration %"PRId64" ms\n", duration));
+ // XXX: store it in AVStreams
+
+ strings_size = get_le32(pb);
+ table_entries = get_le32(pb);
+ table_entries_used = get_le32(pb);
+ PRINT(("NSV NSVf info-strings size: %d, table entries: %d, bis %d\n",
+ strings_size, table_entries, table_entries_used));
+ if (url_feof(pb))
+ return -1;
+
+ PRINT(("NSV got header; filepos %"PRId64"\n", url_ftell(pb)));
+
+ if (strings_size > 0) {
+ char *strings; /* last byte will be '\0' to play safe with str*() */
+ char *p, *endp;
+ char *token, *value;
+ char quote;
+
+ p = strings = av_mallocz(strings_size + 1);
+ endp = strings + strings_size;
+ get_buffer(pb, strings, strings_size);
+ while (p < endp) {
+ while (*p == ' ')
+ p++; /* strip out spaces */
+ if (p >= endp-2)
+ break;
+ token = p;
+ p = strchr(p, '=');
+ if (!p || p >= endp-2)
+ break;
+ *p++ = '\0';
+ quote = *p++;
+ value = p;
+ p = strchr(p, quote);
+ if (!p || p >= endp)
+ break;
+ *p++ = '\0';
+ PRINT(("NSV NSVf INFO: %s='%s'\n", token, value));
+ if (!strcmp(token, "ASPECT")) {
+ /* don't care */
+ } else if (!strcmp(token, "CREATOR") || !strcmp(token, "Author")) {
+ strncpy(s->author, value, 512-1);
+ } else if (!strcmp(token, "Copyright")) {
+ strncpy(s->copyright, value, 512-1);
+ } else if (!strcmp(token, "TITLE") || !strcmp(token, "Title")) {
+ strncpy(s->title, value, 512-1);
+ }
+ }
+ av_free(strings);
+ }
+ if (url_feof(pb))
+ return -1;
+
+ PRINT(("NSV got infos; filepos %"PRId64"\n", url_ftell(pb)));
+
+ if (table_entries_used > 0) {
+ nsv->index_entries = table_entries_used;
+ if((unsigned)table_entries >= UINT_MAX / sizeof(uint32_t))
+ return -1;
+ nsv->nsvf_index_data = av_malloc(table_entries * sizeof(uint32_t));
+#warning "FIXME: Byteswap buffer as needed"
+ get_buffer(pb, (unsigned char *)nsv->nsvf_index_data, table_entries * sizeof(uint32_t));
+ }
+
+ PRINT(("NSV got index; filepos %"PRId64"\n", url_ftell(pb)));
+
+#ifdef DEBUG_DUMP_INDEX
+#define V(v) ((v<0x20 || v > 127)?'.':v)
+ /* dump index */
+ PRINT(("NSV %d INDEX ENTRIES:\n", table_entries));
+ PRINT(("NSV [dataoffset][fileoffset]\n", table_entries));
+ for (i = 0; i < table_entries; i++) {
+ unsigned char b[8];
+ url_fseek(pb, size + nsv->nsvf_index_data[i], SEEK_SET);
+ get_buffer(pb, b, 8);
+ PRINT(("NSV [0x%08lx][0x%08lx]: %02x %02x %02x %02x %02x %02x %02x %02x"
+ "%c%c%c%c%c%c%c%c\n",
+ nsv->nsvf_index_data[i], size + nsv->nsvf_index_data[i],
+ b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7],
+ V(b[0]), V(b[1]), V(b[2]), V(b[3]), V(b[4]), V(b[5]), V(b[6]), V(b[7]) ));
+ }
+ //url_fseek(pb, size, SEEK_SET); /* go back to end of header */
+#undef V
+#endif
+
+ url_fseek(pb, nsv->base_offset + size, SEEK_SET); /* required for dumbdriving-271.nsv (2 extra bytes) */
+
+ if (url_feof(pb))
+ return -1;
+ nsv->state = NSV_HAS_READ_NSVF;
+ return 0;
+}
+
+static int nsv_parse_NSVs_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+ NSVContext *nsv = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ uint32_t vtag, atag;
+ uint16_t vwidth, vheight;
+ AVRational framerate;
+ int i;
+ AVStream *st;
+ NSVStream *nst;
+ PRINT(("%s()\n", __FUNCTION__));
+
+ vtag = get_le32(pb);
+ atag = get_le32(pb);
+ vwidth = get_le16(pb);
+ vheight = get_le16(pb);
+ i = get_byte(pb);
+
+ PRINT(("NSV NSVs framerate code %2x\n", i));
+ if(i&0x80) { /* odd way of giving native framerates from docs */
+ int t=(i & 0x7F)>>2;
+ if(t<16) framerate = (AVRational){1, t+1};
+ else framerate = (AVRational){t-15, 1};
+
+ if(i&1){
+ framerate.num *= 1000;
+ framerate.den *= 1001;
+ }
+
+ if((i&3)==3) framerate.num *= 24;
+ else if((i&3)==2) framerate.num *= 25;
+ else framerate.num *= 30;
+ }
+ else
+ framerate= (AVRational){i, 1};
+
+ nsv->avsync = get_le16(pb);
+#ifdef DEBUG
+ print_tag("NSV NSVs vtag", vtag, 0);
+ print_tag("NSV NSVs atag", atag, 0);
+ PRINT(("NSV NSVs vsize %dx%d\n", vwidth, vheight));
+#endif
+
+ /* XXX change to ap != NULL ? */
+ if (s->nb_streams == 0) { /* streams not yet published, let's do that */
+ nsv->vtag = vtag;
+ nsv->atag = atag;
+ nsv->vwidth = vwidth;
+ nsv->vheight = vwidth;
+ if (vtag != T_NONE) {
+ st = av_new_stream(s, NSV_ST_VIDEO);
+ if (!st)
+ goto fail;
+
+ nst = av_mallocz(sizeof(NSVStream));
+ if (!nst)
+ goto fail;
+ st->priv_data = nst;
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ st->codec->codec_tag = vtag;
+ st->codec->codec_id = codec_get_id(nsv_codec_video_tags, vtag);
+ st->codec->width = vwidth;
+ st->codec->height = vheight;
+ st->codec->bits_per_sample = 24; /* depth XXX */
+
+ av_set_pts_info(st, 64, framerate.den, framerate.num);
+ st->start_time = 0;
+ st->duration = av_rescale(nsv->duration, framerate.num, 1000*framerate.den);
+ }
+ if (atag != T_NONE) {
+#ifndef DISABLE_AUDIO
+ st = av_new_stream(s, NSV_ST_AUDIO);
+ if (!st)
+ goto fail;
+
+ nst = av_mallocz(sizeof(NSVStream));
+ if (!nst)
+ goto fail;
+ st->priv_data = nst;
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_tag = atag;
+ st->codec->codec_id = codec_get_id(nsv_codec_audio_tags, atag);
+
+ st->need_parsing = 1; /* for PCM we will read a chunk later and put correct info */
+
+ /* set timebase to common denominator of ms and framerate */
+ av_set_pts_info(st, 64, 1, framerate.num*1000);
+ st->start_time = 0;
+ st->duration = (int64_t)nsv->duration * framerate.num;
+#endif
+ }
+#ifdef CHECK_SUBSEQUENT_NSVS
+ } else {
+ if (nsv->vtag != vtag || nsv->atag != atag || nsv->vwidth != vwidth || nsv->vheight != vwidth) {
+ PRINT(("NSV NSVs header values differ from the first one!!!\n"));
+ //return -1;
+ }
+#endif /* CHECK_SUBSEQUENT_NSVS */
+ }
+
+ nsv->state = NSV_HAS_READ_NSVS;
+ return 0;
+fail:
+ /* XXX */
+ nsv->state = NSV_UNSYNC;
+ return -1;
+}
+
+static int nsv_read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+ NSVContext *nsv = s->priv_data;
+ int i, err;
+
+ PRINT(("%s()\n", __FUNCTION__));
+ PRINT(("filename '%s'\n", s->filename));
+
+ nsv->state = NSV_UNSYNC;
+ nsv->ahead[0].data = nsv->ahead[1].data = NULL;
+
+ for (i = 0; i < NSV_MAX_RESYNC_TRIES; i++) {
+ if (nsv_resync(s) < 0)
+ return -1;
+ if (nsv->state == NSV_FOUND_NSVF)
+ err = nsv_parse_NSVf_header(s, ap);
+ /* we need the first NSVs also... */
+ if (nsv->state == NSV_FOUND_NSVS) {
+ err = nsv_parse_NSVs_header(s, ap);
+ break; /* we just want the first one */
+ }
+ }
+ if (s->nb_streams < 1) /* no luck so far */
+ return -1;
+ /* now read the first chunk, so we can attempt to decode more info */
+ err = nsv_read_chunk(s, 1);
+
+ PRINT(("parsed header\n"));
+ return 0;
+}
+
+static int nsv_read_chunk(AVFormatContext *s, int fill_header)
+{
+ NSVContext *nsv = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ AVStream *st[2] = {NULL, NULL};
+ NSVStream *nst;
+ AVPacket *pkt;
+ int i, err = 0;
+ uint8_t auxcount; /* number of aux metadata, also 4 bits of vsize */
+ uint32_t vsize;
+ uint16_t asize;
+ uint16_t auxsize;
+ uint32_t auxtag;
+
+ PRINT(("%s(%d)\n", __FUNCTION__, fill_header));
+
+ if (nsv->ahead[0].data || nsv->ahead[1].data)
+ return 0; //-1; /* hey! eat what you've in your plate first! */
+
+null_chunk_retry:
+ if (url_feof(pb))
+ return -1;
+
+ for (i = 0; i < NSV_MAX_RESYNC_TRIES && nsv->state < NSV_FOUND_NSVS && !err; i++)
+ err = nsv_resync(s);
+ if (err < 0)
+ return err;
+ if (nsv->state == NSV_FOUND_NSVS)
+ err = nsv_parse_NSVs_header(s, NULL);
+ if (err < 0)
+ return err;
+ if (nsv->state != NSV_HAS_READ_NSVS && nsv->state != NSV_FOUND_BEEF)
+ return -1;
+
+ auxcount = get_byte(pb);
+ vsize = get_le16(pb);
+ asize = get_le16(pb);
+ vsize = (vsize << 4) | (auxcount >> 4);
+ auxcount &= 0x0f;
+ PRINT(("NSV CHUNK %d aux, %u bytes video, %d bytes audio\n", auxcount, vsize, asize));
+ /* skip aux stuff */
+ for (i = 0; i < auxcount; i++) {
+ auxsize = get_le16(pb);
+ auxtag = get_le32(pb);
+ PRINT(("NSV aux data: '%c%c%c%c', %d bytes\n",
+ (auxtag & 0x0ff),
+ ((auxtag >> 8) & 0x0ff),
+ ((auxtag >> 16) & 0x0ff),
+ ((auxtag >> 24) & 0x0ff),
+ auxsize));
+ url_fskip(pb, auxsize);
+ vsize -= auxsize + sizeof(uint16_t) + sizeof(uint32_t); /* that's becoming braindead */
+ }
+
+ if (url_feof(pb))
+ return -1;
+ if (!vsize && !asize) {
+ nsv->state = NSV_UNSYNC;
+ goto null_chunk_retry;
+ }
+
+ /* map back streams to v,a */
+ if (s->streams[0])
+ st[s->streams[0]->id] = s->streams[0];
+ if (s->streams[1])
+ st[s->streams[1]->id] = s->streams[1];
+
+ if (vsize/* && st[NSV_ST_VIDEO]*/) {
+ nst = st[NSV_ST_VIDEO]->priv_data;
+ pkt = &nsv->ahead[NSV_ST_VIDEO];
+ 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 */
+/*
+ for (i = 0; i < MIN(8, vsize); i++)
+ PRINT(("NSV video: [%d] = %02x\n", i, pkt->data[i]));
+*/
+ }
+ ((NSVStream*)st[NSV_ST_VIDEO]->priv_data)->frame_offset++;
+
+ if (asize/*st[NSV_ST_AUDIO]*/) {
+ nst = st[NSV_ST_AUDIO]->priv_data;
+ pkt = &nsv->ahead[NSV_ST_AUDIO];
+ /* read raw audio specific header on the first audio chunk... */
+ /* on ALL audio chunks ?? seems so! */
+ if (asize && st[NSV_ST_AUDIO]->codec->codec_tag == MKTAG('P', 'C', 'M', ' ')/* && fill_header*/) {
+ uint8_t bps;
+ uint8_t channels;
+ uint16_t samplerate;
+ bps = get_byte(pb);
+ channels = get_byte(pb);
+ samplerate = get_le16(pb);
+ asize-=4;
+ PRINT(("NSV RAWAUDIO: bps %d, nchan %d, srate %d\n", bps, channels, samplerate));
+ if (fill_header) {
+ st[NSV_ST_AUDIO]->need_parsing = 0; /* we know everything */
+ if (bps != 16) {
+ PRINT(("NSV AUDIO bit/sample != 16 (%d)!!!\n", bps));
+ }
+ bps /= channels; // ???
+ if (bps == 8)
+ st[NSV_ST_AUDIO]->codec->codec_id = CODEC_ID_PCM_U8;
+ samplerate /= 4;/* UGH ??? XXX */
+ channels = 1;
+ st[NSV_ST_AUDIO]->codec->channels = channels;
+ st[NSV_ST_AUDIO]->codec->sample_rate = samplerate;
+ PRINT(("NSV RAWAUDIO: bps %d, nchan %d, srate %d\n", bps, channels, samplerate));
+ }
+ }
+ 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 */
+ 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);
+ pkt->dts *= (int64_t)1000 * st[NSV_ST_VIDEO]->time_base.num;
+ pkt->dts += (int64_t)nsv->avsync * st[NSV_ST_VIDEO]->time_base.den;
+ PRINT(("NSV AUDIO: sync:%d, dts:%"PRId64, nsv->avsync, pkt->dts));
+ }
+ nst->frame_offset++;
+ }
+
+ nsv->state = NSV_UNSYNC;
+ return 0;
+}
+
+
+static int nsv_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ NSVContext *nsv = s->priv_data;
+ int i, err = 0;
+
+ PRINT(("%s()\n", __FUNCTION__));
+
+ /* in case we don't already have something to eat ... */
+ if (nsv->ahead[0].data == NULL && nsv->ahead[1].data == NULL)
+ err = nsv_read_chunk(s, 0);
+ if (err < 0)
+ return err;
+
+ /* now pick one of the plates */
+ for (i = 0; i < 2; i++) {
+ if (nsv->ahead[i].data) {
+ PRINT(("%s: using cached packet[%d]\n", __FUNCTION__, i));
+ /* avoid the cost of new_packet + memcpy(->data) */
+ memcpy(pkt, &nsv->ahead[i], sizeof(AVPacket));
+ nsv->ahead[i].data = NULL; /* we ate that one */
+ return pkt->size;
+ }
+ }
+
+ /* this restaurant is not approvisionned :^] */
+ return -1;
+}
+
+static int nsv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
+{
+#if 0
+ NSVContext *avi = s->priv_data;
+ AVStream *st;
+ NSVStream *ast;
+ int frame_number, i;
+ int64_t pos;
+#endif
+
+ return -1;
+}
+
+static int nsv_read_close(AVFormatContext *s)
+{
+/* int i; */
+ NSVContext *nsv = s->priv_data;
+
+ if (nsv->index_entries)
+ av_free(nsv->nsvf_index_data);
+
+#if 0
+
+ for(i=0;i<s->nb_streams;i++) {
+ AVStream *st = s->streams[i];
+ NSVStream *ast = st->priv_data;
+ if(ast){
+ av_free(ast->index_entries);
+ av_free(ast);
+ }
+ av_free(st->codec->palctrl);
+ }
+
+#endif
+ return 0;
+}
+
+static int nsv_probe(AVProbeData *p)
+{
+ int i;
+// PRINT(("nsv_probe(), buf_size %d\n", p->buf_size));
+ /* check file header */
+ if (p->buf_size <= 32)
+ return 0;
+ if (p->buf[0] == 'N' && p->buf[1] == 'S' &&
+ p->buf[2] == 'V' && p->buf[3] == 'f')
+ return AVPROBE_SCORE_MAX;
+ /* streamed files might not have any header */
+ if (p->buf[0] == 'N' && p->buf[1] == 'S' &&
+ p->buf[2] == 'V' && p->buf[3] == 's')
+ return AVPROBE_SCORE_MAX;
+ /* XXX: do streamed files always start at chunk boundary ?? */
+ /* or do we need to search NSVs in the byte stream ? */
+ /* seems the servers don't bother starting clean chunks... */
+ /* sometimes even the first header is at 9KB or something :^) */
+ for (i = 1; i < p->buf_size - 3; i++) {
+ if (p->buf[i+0] == 'N' && p->buf[i+1] == 'S' &&
+ p->buf[i+2] == 'V' && p->buf[i+3] == 's')
+ return AVPROBE_SCORE_MAX-20;
+ }
+ /* so we'll have more luck on extension... */
+ if (match_ext(p->filename, "nsv"))
+ return AVPROBE_SCORE_MAX-20;
+ /* FIXME: add mime-type check */
+ return 0;
+}
+
+AVInputFormat nsv_demuxer = {
+ "nsv",
+ "NullSoft Video format",
+ sizeof(NSVContext),
+ nsv_probe,
+ nsv_read_header,
+ nsv_read_packet,
+ nsv_read_close,
+ nsv_read_seek,
+};
diff --git a/contrib/ffmpeg/libavformat/nut.c b/contrib/ffmpeg/libavformat/nut.c
new file mode 100644
index 000000000..995149951
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/nut.c
@@ -0,0 +1,1457 @@
+/*
+ * "NUT" Container Format muxer and demuxer (DRAFT-200403??)
+ * Copyright (c) 2003 Alex Beregszaszi
+ * Copyright (c) 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
+ *
+ *
+ * Visit the official site at http://www.nut.hu/
+ *
+ */
+
+/*
+ * TODO:
+ * - index writing
+ * - index packet reading support
+*/
+
+//#define DEBUG 1
+
+#include <limits.h>
+#include "avformat.h"
+#include "mpegaudio.h"
+#include "riff.h"
+#include "adler32.h"
+
+#undef NDEBUG
+#include <assert.h>
+
+//#define TRACE
+
+//from /dev/random
+
+#define MAIN_STARTCODE (0x7A561F5F04ADULL + (((uint64_t)('N'<<8) + 'M')<<48))
+#define STREAM_STARTCODE (0x11405BF2F9DBULL + (((uint64_t)('N'<<8) + 'S')<<48))
+#define KEYFRAME_STARTCODE (0xE4ADEECA4569ULL + (((uint64_t)('N'<<8) + 'K')<<48))
+#define INDEX_STARTCODE (0xDD672F23E64EULL + (((uint64_t)('N'<<8) + 'X')<<48))
+#define INFO_STARTCODE (0xAB68B596BA78ULL + (((uint64_t)('N'<<8) + 'I')<<48))
+
+#define ID_STRING "nut/multimedia container\0"
+
+#define MAX_DISTANCE (1024*16-1)
+#define MAX_SHORT_DISTANCE (1024*4-1)
+
+#define FLAG_DATA_SIZE 1
+#define FLAG_KEY_FRAME 2
+#define FLAG_INVALID 4
+
+typedef struct {
+ uint8_t flags;
+ uint8_t stream_id_plus1;
+ uint16_t size_mul;
+ uint16_t size_lsb;
+ int16_t timestamp_delta;
+ uint8_t reserved_count;
+} FrameCode;
+
+typedef struct {
+ int last_key_frame;
+ int msb_timestamp_shift;
+ int rate_num;
+ int rate_den;
+ int64_t last_pts;
+ int64_t last_sync_pos; ///<pos of last 1/2 type frame
+ int decode_delay;
+} StreamContext;
+
+typedef struct {
+ AVFormatContext *avf;
+ int written_packet_size;
+ int64_t packet_start[3]; //0-> startcode less, 1-> short startcode 2-> long startcodes
+ FrameCode frame_code[256];
+ unsigned int stream_count;
+ uint64_t next_startcode; ///< stores the next startcode if it has alraedy been parsed but the stream isnt seekable
+ StreamContext *stream;
+ int max_distance;
+ int max_short_distance;
+ int rate_num;
+ int rate_den;
+ int short_startcode;
+} NUTContext;
+
+static char *info_table[][2]={
+ {NULL , NULL }, // end
+ {NULL , NULL },
+ {NULL , "UTF8"},
+ {NULL , "v"},
+ {NULL , "s"},
+ {"StreamId" , "v"},
+ {"SegmentId" , "v"},
+ {"StartTimestamp" , "v"},
+ {"EndTimestamp" , "v"},
+ {"Author" , "UTF8"},
+ {"Title" , "UTF8"},
+ {"Description" , "UTF8"},
+ {"Copyright" , "UTF8"},
+ {"Encoder" , "UTF8"},
+ {"Keyword" , "UTF8"},
+ {"Cover" , "JPEG"},
+ {"Cover" , "PNG"},
+};
+
+static void update(NUTContext *nut, int stream_index, int64_t frame_start, int frame_type, int frame_code, int key_frame, int size, int64_t pts){
+ StreamContext *stream= &nut->stream[stream_index];
+
+ stream->last_key_frame= key_frame;
+ nut->packet_start[ frame_type ]= frame_start;
+ stream->last_pts= pts;
+}
+
+static void reset(AVFormatContext *s, int64_t global_ts){
+ NUTContext *nut = s->priv_data;
+ int i;
+
+ for(i=0; i<s->nb_streams; i++){
+ StreamContext *stream= &nut->stream[i];
+
+ stream->last_key_frame= 1;
+
+ stream->last_pts= av_rescale(global_ts, stream->rate_num*(int64_t)nut->rate_den, stream->rate_den*(int64_t)nut->rate_num);
+ }
+}
+
+static void build_frame_code(AVFormatContext *s){
+ NUTContext *nut = s->priv_data;
+ int key_frame, index, pred, stream_id;
+ int start=0;
+ int end= 255;
+ int keyframe_0_esc= s->nb_streams > 2;
+ int pred_table[10];
+
+ if(keyframe_0_esc){
+ /* keyframe = 0 escape */
+ FrameCode *ft= &nut->frame_code[start];
+ ft->flags= FLAG_DATA_SIZE;
+ ft->stream_id_plus1= 0;
+ ft->size_mul=1;
+ ft->timestamp_delta=0;
+ start++;
+ }
+
+ for(stream_id= 0; stream_id<s->nb_streams; stream_id++){
+ 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 intra_only= /*codec->intra_only || */is_audio;
+ int pred_count;
+
+ for(key_frame=0; key_frame<2; key_frame++){
+ if(intra_only && keyframe_0_esc && key_frame==0)
+ continue;
+
+ {
+ FrameCode *ft= &nut->frame_code[start2];
+ ft->flags= FLAG_KEY_FRAME*key_frame;
+ ft->flags|= FLAG_DATA_SIZE;
+ ft->stream_id_plus1= stream_id + 1;
+ ft->size_mul=1;
+ ft->timestamp_delta=0;
+ start2++;
+ }
+ }
+
+ key_frame= intra_only;
+#if 1
+ if(is_audio){
+ int frame_bytes= codec->frame_size*(int64_t)codec->bit_rate / (8*codec->sample_rate);
+ int pts;
+ for(pts=0; pts<2; pts++){
+ for(pred=0; pred<2; pred++){
+ FrameCode *ft= &nut->frame_code[start2];
+ ft->flags= FLAG_KEY_FRAME*key_frame;
+ ft->stream_id_plus1= stream_id + 1;
+ ft->size_mul=frame_bytes + 2;
+ ft->size_lsb=frame_bytes + pred;
+ ft->timestamp_delta=pts;
+ start2++;
+ }
+ }
+ }else{
+ FrameCode *ft= &nut->frame_code[start2];
+ ft->flags= FLAG_KEY_FRAME | FLAG_DATA_SIZE;
+ ft->stream_id_plus1= stream_id + 1;
+ ft->size_mul=1;
+ ft->timestamp_delta=1;
+ start2++;
+ }
+#endif
+
+ if(codec->has_b_frames){
+ pred_count=5;
+ pred_table[0]=-2;
+ pred_table[1]=-1;
+ pred_table[2]=1;
+ pred_table[3]=3;
+ pred_table[4]=4;
+ }else if(codec->codec_id == CODEC_ID_VORBIS){
+ pred_count=3;
+ pred_table[0]=2;
+ pred_table[1]=9;
+ pred_table[2]=16;
+ }else{
+ pred_count=1;
+ pred_table[0]=1;
+ }
+
+ for(pred=0; pred<pred_count; pred++){
+ int start3= start2 + (end2-start2)*pred / pred_count;
+ int end3 = start2 + (end2-start2)*(pred+1) / pred_count;
+
+ for(index=start3; index<end3; index++){
+ FrameCode *ft= &nut->frame_code[index];
+ ft->flags= FLAG_KEY_FRAME*key_frame;
+ ft->flags|= FLAG_DATA_SIZE;
+ ft->stream_id_plus1= stream_id + 1;
+//FIXME use single byte size and pred from last
+ ft->size_mul= end3-start3;
+ ft->size_lsb= index - start3;
+ ft->timestamp_delta= pred_table[pred];
+ }
+ }
+ }
+ memmove(&nut->frame_code['N'+1], &nut->frame_code['N'], sizeof(FrameCode)*(255-'N'));
+ nut->frame_code['N'].flags= FLAG_INVALID;
+}
+
+static uint64_t get_v(ByteIOContext *bc)
+{
+ uint64_t val = 0;
+
+ for(;;)
+ {
+ int tmp = get_byte(bc);
+
+ if (tmp&0x80)
+ val= (val<<7) + tmp - 0x80;
+ else{
+//av_log(NULL, AV_LOG_DEBUG, "get_v()= %"PRId64"\n", (val<<7) + tmp);
+ return (val<<7) + tmp;
+ }
+ }
+ return -1;
+}
+
+static int get_str(ByteIOContext *bc, char *string, unsigned int maxlen){
+ unsigned int len= get_v(bc);
+
+ if(len && maxlen)
+ get_buffer(bc, string, FFMIN(len, maxlen));
+ while(len > maxlen){
+ get_byte(bc);
+ len--;
+ }
+
+ if(maxlen)
+ string[FFMIN(len, maxlen-1)]= 0;
+
+ if(maxlen == len)
+ return -1;
+ else
+ return 0;
+}
+
+static int64_t get_s(ByteIOContext *bc){
+ int64_t v = get_v(bc) + 1;
+
+ if (v&1) return -(v>>1);
+ else return (v>>1);
+}
+
+static uint64_t get_vb(ByteIOContext *bc){
+ uint64_t val=0;
+ unsigned int i= get_v(bc);
+
+ if(i>8)
+ return UINT64_MAX;
+
+ while(i--)
+ val = (val<<8) + get_byte(bc);
+
+//av_log(NULL, AV_LOG_DEBUG, "get_vb()= %"PRId64"\n", val);
+ return val;
+}
+
+#ifdef TRACE
+static inline uint64_t get_v_trace(ByteIOContext *bc, char *file, char *func, int line){
+ uint64_t v= get_v(bc);
+
+ printf("get_v %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line);
+ return v;
+}
+
+static inline int64_t get_s_trace(ByteIOContext *bc, char *file, char *func, int line){
+ int64_t v= get_s(bc);
+
+ printf("get_s %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line);
+ return v;
+}
+
+static inline uint64_t get_vb_trace(ByteIOContext *bc, char *file, char *func, int line){
+ uint64_t v= get_vb(bc);
+
+ printf("get_vb %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line);
+ return v;
+}
+#define get_v(bc) get_v_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
+#define get_s(bc) get_s_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
+#define get_vb(bc) get_vb_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
+#endif
+
+
+static int get_packetheader(NUTContext *nut, ByteIOContext *bc, int calculate_checksum)
+{
+ int64_t start, size;
+ start= url_ftell(bc) - 8;
+
+ size= get_v(bc);
+
+ init_checksum(bc, calculate_checksum ? av_adler32_update : NULL, 1);
+
+ nut->packet_start[2] = start;
+ nut->written_packet_size= size;
+
+ return size;
+}
+
+static int check_checksum(ByteIOContext *bc){
+ unsigned long checksum= get_checksum(bc);
+ return checksum != get_be32(bc);
+}
+
+/**
+ *
+ */
+static int get_length(uint64_t val){
+ int i;
+
+ for (i=7; val>>i; i+=7);
+
+ return i;
+}
+
+static uint64_t find_any_startcode(ByteIOContext *bc, int64_t pos){
+ uint64_t state=0;
+
+ if(pos >= 0)
+ url_fseek(bc, pos, SEEK_SET); //note, this may fail if the stream isnt seekable, but that shouldnt matter, as in this case we simply start where we are currently
+
+ while(!url_feof(bc)){
+ state= (state<<8) | get_byte(bc);
+ if((state>>56) != 'N')
+ continue;
+ switch(state){
+ case MAIN_STARTCODE:
+ case STREAM_STARTCODE:
+ case KEYFRAME_STARTCODE:
+ case INFO_STARTCODE:
+ case INDEX_STARTCODE:
+ return state;
+ }
+ }
+
+ return 0;
+}
+
+/**
+ * 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
+ */
+static int64_t find_startcode(ByteIOContext *bc, uint64_t code, int64_t pos){
+ for(;;){
+ uint64_t startcode= find_any_startcode(bc, pos);
+ if(startcode == code)
+ return url_ftell(bc) - 8;
+ else if(startcode == 0)
+ return -1;
+ pos=-1;
+ }
+}
+
+static int64_t lsb2full(StreamContext *stream, int64_t lsb){
+ int64_t mask = (1<<stream->msb_timestamp_shift)-1;
+ int64_t delta= stream->last_pts - mask/2;
+ return ((lsb - delta)&mask) + delta;
+}
+
+#ifdef CONFIG_MUXERS
+
+static void put_v(ByteIOContext *bc, uint64_t val)
+{
+ int i;
+
+//av_log(NULL, AV_LOG_DEBUG, "put_v()= %"PRId64"\n", val);
+ val &= 0x7FFFFFFFFFFFFFFFULL; // FIXME can only encode upto 63 bits currently
+ i= get_length(val);
+
+ for (i-=7; i>0; i-=7){
+ put_byte(bc, 0x80 | (val>>i));
+ }
+
+ put_byte(bc, val&0x7f);
+}
+
+/**
+ * stores a string as vb.
+ */
+static void put_str(ByteIOContext *bc, const char *string){
+ int len= strlen(string);
+
+ put_v(bc, len);
+ put_buffer(bc, string, len);
+}
+
+static void put_s(ByteIOContext *bc, int64_t val){
+ if (val<=0) put_v(bc, -2*val );
+ else put_v(bc, 2*val-1);
+}
+
+static void put_vb(ByteIOContext *bc, uint64_t val){
+ int i;
+
+ for (i=8; val>>i; i+=8);
+
+ put_v(bc, i>>3);
+ for(i-=8; i>=0; i-=8)
+ put_byte(bc, (val>>i)&0xFF);
+}
+
+#ifdef TRACE
+static inline void put_v_trace(ByteIOContext *bc, uint64_t v, char *file, char *func, int line){
+ printf("get_v %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line);
+
+ put_v(bc, v);
+}
+
+static inline void put_s_trace(ByteIOContext *bc, int64_t v, char *file, char *func, int line){
+ printf("get_s %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line);
+
+ put_s(bc, v);
+}
+
+static inline void put_vb_trace(ByteIOContext *bc, uint64_t v, char *file, char *func, int line){
+ printf("get_vb %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line);
+
+ put_vb(bc, v);
+}
+#define put_v(bc, v) put_v_trace(bc, v, __FILE__, __PRETTY_FUNCTION__, __LINE__)
+#define put_s(bc, v) put_s_trace(bc, v, __FILE__, __PRETTY_FUNCTION__, __LINE__)
+#define put_vb(bc, v) put_vb_trace(bc, v, __FILE__, __PRETTY_FUNCTION__, __LINE__)
+#endif
+
+static int put_packetheader(NUTContext *nut, ByteIOContext *bc, int max_size, int calculate_checksum)
+{
+ put_flush_packet(bc);
+ nut->packet_start[2]= url_ftell(bc) - 8;
+ nut->written_packet_size = max_size;
+
+ /* packet header */
+ put_v(bc, nut->written_packet_size); /* forward ptr */
+
+ if(calculate_checksum)
+ init_checksum(bc, av_adler32_update, 1);
+
+ return 0;
+}
+
+/**
+ *
+ * must not be called more then once per packet
+ */
+static int update_packetheader(NUTContext *nut, ByteIOContext *bc, int additional_size, int calculate_checksum){
+ int64_t start= nut->packet_start[2];
+ int64_t cur= url_ftell(bc);
+ int size= cur - start - get_length(nut->written_packet_size)/7 - 8;
+
+ if(calculate_checksum)
+ size += 4;
+
+ if(size != nut->written_packet_size){
+ int i;
+
+ assert( size <= nut->written_packet_size );
+
+ url_fseek(bc, start + 8, SEEK_SET);
+ for(i=get_length(size); i < get_length(nut->written_packet_size); i+=7)
+ put_byte(bc, 0x80);
+ put_v(bc, size);
+
+ url_fseek(bc, cur, SEEK_SET);
+ nut->written_packet_size= size; //FIXME may fail if multiple updates with differing sizes, as get_length may differ
+
+ if(calculate_checksum)
+ put_be32(bc, get_checksum(bc));
+ }
+
+ return 0;
+}
+
+static int nut_write_header(AVFormatContext *s)
+{
+ NUTContext *nut = s->priv_data;
+ ByteIOContext *bc = &s->pb;
+ AVCodecContext *codec;
+ int i, j, tmp_time, tmp_flags,tmp_stream, tmp_mul, tmp_size, tmp_fields;
+
+ if (strcmp(s->filename, "./data/b-libav.nut")) {
+ av_log(s, AV_LOG_ERROR, " libavformat NUT is non-compliant and disabled\n");
+ return -1;
+ }
+
+ nut->avf= s;
+
+ nut->stream =
+ av_mallocz(sizeof(StreamContext)*s->nb_streams);
+
+
+ put_buffer(bc, ID_STRING, strlen(ID_STRING));
+ put_byte(bc, 0);
+ nut->packet_start[2]= url_ftell(bc);
+
+ /* main header */
+ put_be64(bc, MAIN_STARTCODE);
+ put_packetheader(nut, bc, 120+5*256, 1);
+ put_v(bc, 2); /* version */
+ put_v(bc, s->nb_streams);
+ put_v(bc, MAX_DISTANCE);
+ put_v(bc, MAX_SHORT_DISTANCE);
+
+ put_v(bc, nut->rate_num=1);
+ put_v(bc, nut->rate_den=2);
+ put_v(bc, nut->short_startcode=0x4EFE79);
+
+ build_frame_code(s);
+ assert(nut->frame_code['N'].flags == FLAG_INVALID);
+
+ tmp_time= tmp_flags= tmp_stream= tmp_mul= tmp_size= /*tmp_res=*/ INT_MAX;
+ for(i=0; i<256;){
+ tmp_fields=0;
+ tmp_size= 0;
+ if(tmp_time != nut->frame_code[i].timestamp_delta) tmp_fields=1;
+ if(tmp_mul != nut->frame_code[i].size_mul ) tmp_fields=2;
+ if(tmp_stream != nut->frame_code[i].stream_id_plus1) tmp_fields=3;
+ if(tmp_size != nut->frame_code[i].size_lsb ) tmp_fields=4;
+// if(tmp_res != nut->frame_code[i].res ) tmp_fields=5;
+
+ tmp_time = nut->frame_code[i].timestamp_delta;
+ tmp_flags = nut->frame_code[i].flags;
+ tmp_stream= nut->frame_code[i].stream_id_plus1;
+ tmp_mul = nut->frame_code[i].size_mul;
+ tmp_size = nut->frame_code[i].size_lsb;
+// tmp_res = nut->frame_code[i].res;
+
+ for(j=0; i<256; j++,i++){
+ if(nut->frame_code[i].timestamp_delta != tmp_time ) break;
+ if(nut->frame_code[i].flags != tmp_flags ) break;
+ if(nut->frame_code[i].stream_id_plus1 != tmp_stream) break;
+ if(nut->frame_code[i].size_mul != tmp_mul ) break;
+ if(nut->frame_code[i].size_lsb != tmp_size+j) break;
+// if(nut->frame_code[i].res != tmp_res ) break;
+ }
+ if(j != tmp_mul - tmp_size) tmp_fields=6;
+
+ put_v(bc, tmp_flags);
+ put_v(bc, tmp_fields);
+ if(tmp_fields>0) put_s(bc, tmp_time);
+ if(tmp_fields>1) put_v(bc, tmp_mul);
+ if(tmp_fields>2) put_v(bc, tmp_stream);
+ if(tmp_fields>3) put_v(bc, tmp_size);
+ if(tmp_fields>4) put_v(bc, 0 /*tmp_res*/);
+ if(tmp_fields>5) put_v(bc, j);
+ }
+
+ update_packetheader(nut, bc, 0, 1);
+
+ /* stream headers */
+ for (i = 0; i < s->nb_streams; i++)
+ {
+ int nom, denom, ssize;
+
+ codec = s->streams[i]->codec;
+
+ put_be64(bc, STREAM_STARTCODE);
+ put_packetheader(nut, bc, 120 + codec->extradata_size, 1);
+ put_v(bc, i /*s->streams[i]->index*/);
+ 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_TEXT : put_v(bc, 2); break;
+ case CODEC_TYPE_DATA : put_v(bc, 3); break;
+ default: return -1;
+ }
+ if (codec->codec_tag)
+ put_vb(bc, codec->codec_tag);
+ else if (codec->codec_type == CODEC_TYPE_VIDEO)
+ {
+ put_vb(bc, codec_get_bmp_tag(codec->codec_id));
+ }
+ else if (codec->codec_type == CODEC_TYPE_AUDIO)
+ {
+ put_vb(bc, codec_get_wav_tag(codec->codec_id));
+ }
+ else
+ put_vb(bc, 0);
+
+ ff_parse_specific_params(codec, &nom, &ssize, &denom);
+
+ nut->stream[i].rate_num= nom;
+ nut->stream[i].rate_den= denom;
+ av_set_pts_info(s->streams[i], 60, denom, nom);
+
+ put_v(bc, codec->bit_rate);
+ put_vb(bc, 0); /* no language code */
+ put_v(bc, nom);
+ put_v(bc, denom);
+ if(nom / denom < 1000)
+ nut->stream[i].msb_timestamp_shift = 7;
+ else
+ nut->stream[i].msb_timestamp_shift = 14;
+ put_v(bc, nut->stream[i].msb_timestamp_shift);
+ put_v(bc, codec->has_b_frames);
+ put_byte(bc, 0); /* flags: 0x1 - fixed_fps, 0x2 - index_present */
+
+ if(codec->extradata_size){
+ put_v(bc, 1);
+ put_v(bc, codec->extradata_size);
+ put_buffer(bc, codec->extradata, codec->extradata_size);
+ }
+ put_v(bc, 0); /* end of codec specific headers */
+
+ switch(codec->codec_type)
+ {
+ case CODEC_TYPE_AUDIO:
+ put_v(bc, codec->sample_rate);
+ put_v(bc, 1);
+ put_v(bc, codec->channels);
+ break;
+ case CODEC_TYPE_VIDEO:
+ put_v(bc, codec->width);
+ put_v(bc, codec->height);
+ put_v(bc, codec->sample_aspect_ratio.num);
+ put_v(bc, codec->sample_aspect_ratio.den);
+ put_v(bc, 0); /* csp type -- unknown */
+ break;
+ default:
+ break;
+ }
+ update_packetheader(nut, bc, 0, 1);
+ }
+
+ /* info header */
+ put_be64(bc, INFO_STARTCODE);
+ put_packetheader(nut, bc, 30+strlen(s->author)+strlen(s->title)+
+ strlen(s->comment)+strlen(s->copyright)+strlen(LIBAVFORMAT_IDENT), 1);
+ if (s->author[0])
+ {
+ put_v(bc, 9); /* type */
+ put_str(bc, s->author);
+ }
+ if (s->title[0])
+ {
+ put_v(bc, 10); /* type */
+ put_str(bc, s->title);
+ }
+ if (s->comment[0])
+ {
+ put_v(bc, 11); /* type */
+ put_str(bc, s->comment);
+ }
+ if (s->copyright[0])
+ {
+ put_v(bc, 12); /* type */
+ put_str(bc, s->copyright);
+ }
+ /* encoder */
+ if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)){
+ put_v(bc, 13); /* type */
+ put_str(bc, LIBAVFORMAT_IDENT);
+ }
+
+ put_v(bc, 0); /* eof info */
+ update_packetheader(nut, bc, 0, 1);
+
+ put_flush_packet(bc);
+
+ return 0;
+}
+
+static int nut_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ NUTContext *nut = s->priv_data;
+ StreamContext *stream= &nut->stream[pkt->stream_index];
+ ByteIOContext *bc = &s->pb;
+ int key_frame = 0, full_pts=0;
+ AVCodecContext *enc;
+ int64_t coded_pts;
+ int frame_type, best_length, frame_code, flags, i, size_mul, size_lsb, time_delta;
+ const int64_t frame_start= url_ftell(bc);
+ int64_t pts= pkt->pts;
+ int size= pkt->size;
+ int stream_index= pkt->stream_index;
+
+ enc = s->streams[stream_index]->codec;
+ key_frame = !!(pkt->flags & PKT_FLAG_KEY);
+
+ frame_type=0;
+ if(frame_start + size + 20 - FFMAX(nut->packet_start[1], nut->packet_start[2]) > MAX_DISTANCE)
+ frame_type=2;
+ if(key_frame && !stream->last_key_frame)
+ frame_type=2;
+
+ if(frame_type>1){
+ int64_t global_ts= av_rescale(pts, stream->rate_den*(int64_t)nut->rate_num, stream->rate_num*(int64_t)nut->rate_den);
+ reset(s, global_ts);
+ put_be64(bc, KEYFRAME_STARTCODE);
+ put_v(bc, global_ts);
+ }
+ assert(stream->last_pts != AV_NOPTS_VALUE);
+ coded_pts = pts & ((1<<stream->msb_timestamp_shift)-1);
+ if(lsb2full(stream, coded_pts) != pts)
+ full_pts=1;
+
+ if(full_pts)
+ coded_pts= pts + (1<<stream->msb_timestamp_shift);
+
+ best_length=INT_MAX;
+ frame_code= -1;
+ for(i=0; i<256; i++){
+ int stream_id_plus1= nut->frame_code[i].stream_id_plus1;
+ int fc_key_frame;
+ int length=0;
+ size_mul= nut->frame_code[i].size_mul;
+ size_lsb= nut->frame_code[i].size_lsb;
+ time_delta= nut->frame_code[i].timestamp_delta;
+ flags= nut->frame_code[i].flags;
+
+ assert(size_mul > size_lsb);
+
+ if(stream_id_plus1 == 0) length+= get_length(stream_index);
+ else if(stream_id_plus1 - 1 != stream_index)
+ continue;
+ fc_key_frame= !!(flags & FLAG_KEY_FRAME);
+
+ assert(key_frame==0 || key_frame==1);
+ if(fc_key_frame != key_frame)
+ continue;
+
+ if(flags & FLAG_DATA_SIZE){
+ if(size % size_mul != size_lsb)
+ continue;
+ length += get_length(size / size_mul);
+ }else if(size != size_lsb)
+ continue;
+
+ if(full_pts && time_delta)
+ continue;
+
+ if(!time_delta){
+ length += get_length(coded_pts);
+ }else{
+ if(time_delta != pts - stream->last_pts)
+ continue;
+ }
+
+ if(length < best_length){
+ best_length= length;
+ frame_code=i;
+ }
+// av_log(s, AV_LOG_DEBUG, "%d %d %d %d %d %d %d %d %d %d\n", key_frame, frame_type, full_pts, size, stream_index, flags, size_mul, size_lsb, stream_id_plus1, length);
+ }
+
+ assert(frame_code != -1);
+ flags= nut->frame_code[frame_code].flags;
+ size_mul= nut->frame_code[frame_code].size_mul;
+ size_lsb= nut->frame_code[frame_code].size_lsb;
+ time_delta= nut->frame_code[frame_code].timestamp_delta;
+#ifdef TRACE
+ best_length /= 7;
+ best_length ++; //frame_code
+ if(frame_type==2){
+ best_length += 8; // startcode
+ }
+ av_log(s, AV_LOG_DEBUG, "kf:%d ft:%d pt:%d fc:%2X len:%2d size:%d stream:%d flag:%d mul:%d lsb:%d s+1:%d pts_delta:%d pts:%"PRId64" fs:%"PRId64"\n", key_frame, frame_type, full_pts ? 1 : 0, frame_code, best_length, size, stream_index, flags, size_mul, size_lsb, nut->frame_code[frame_code].stream_id_plus1,(int)(pts - stream->last_pts), pts, frame_start);
+// av_log(s, AV_LOG_DEBUG, "%d %d %d\n", stream->lru_pts_delta[0], stream->lru_pts_delta[1], stream->lru_pts_delta[2]);
+#endif
+
+ assert(frame_type != 1); //short startcode not implemented yet
+ put_byte(bc, frame_code);
+
+ if(nut->frame_code[frame_code].stream_id_plus1 == 0)
+ put_v(bc, stream_index);
+ if (!time_delta){
+ put_v(bc, coded_pts);
+ }
+ if(flags & FLAG_DATA_SIZE)
+ put_v(bc, size / size_mul);
+ else
+ assert(size == size_lsb);
+ if(size > MAX_DISTANCE){
+ assert(frame_type > 1);
+ }
+
+ put_buffer(bc, pkt->data, size);
+
+ update(nut, stream_index, frame_start, frame_type, frame_code, key_frame, size, pts);
+
+ return 0;
+}
+
+static int nut_write_trailer(AVFormatContext *s)
+{
+ NUTContext *nut = s->priv_data;
+ ByteIOContext *bc = &s->pb;
+
+#if 0
+ int i;
+
+ /* WRITE INDEX */
+
+ for (i = 0; s->nb_streams; i++)
+ {
+ put_be64(bc, INDEX_STARTCODE);
+ put_packetheader(nut, bc, 64, 1);
+ put_v(bc, s->streams[i]->id);
+ put_v(bc, ...);
+ update_packetheader(nut, bc, 0, 1);
+ }
+#endif
+
+ put_flush_packet(bc);
+
+ av_freep(&nut->stream);
+
+ return 0;
+}
+#endif //CONFIG_MUXERS
+
+static int nut_probe(AVProbeData *p)
+{
+ int i;
+ uint64_t code= 0xff;
+
+ for (i = 0; i < p->buf_size; i++) {
+ code = (code << 8) | p->buf[i];
+ if (code == MAIN_STARTCODE)
+ return AVPROBE_SCORE_MAX;
+ }
+ return 0;
+}
+
+static int decode_main_header(NUTContext *nut){
+ AVFormatContext *s= nut->avf;
+ ByteIOContext *bc = &s->pb;
+ uint64_t tmp;
+ int i, j, tmp_stream, tmp_mul, tmp_time, tmp_size, count, tmp_res;
+
+ get_packetheader(nut, bc, 1);
+
+ tmp = get_v(bc);
+ if (tmp != 2){
+ av_log(s, AV_LOG_ERROR, "bad version (%"PRId64")\n", tmp);
+ return -1;
+ }
+
+ nut->stream_count = get_v(bc);
+ if(nut->stream_count > MAX_STREAMS){
+ av_log(s, AV_LOG_ERROR, "too many streams\n");
+ return -1;
+ }
+ nut->max_distance = get_v(bc);
+ nut->max_short_distance = get_v(bc);
+ nut->rate_num= get_v(bc);
+ nut->rate_den= get_v(bc);
+ nut->short_startcode= get_v(bc);
+ if(nut->short_startcode>>16 != 'N'){
+ av_log(s, AV_LOG_ERROR, "invalid short startcode %X\n", nut->short_startcode);
+ return -1;
+ }
+
+ for(i=0; i<256;){
+ int tmp_flags = get_v(bc);
+ int tmp_fields= get_v(bc);
+ if(tmp_fields>0) tmp_time = get_s(bc);
+ if(tmp_fields>1) tmp_mul = get_v(bc);
+ if(tmp_fields>2) tmp_stream= get_v(bc);
+ if(tmp_fields>3) tmp_size = get_v(bc);
+ else tmp_size = 0;
+ if(tmp_fields>4) tmp_res = get_v(bc);
+ else tmp_res = 0;
+ if(tmp_fields>5) count = get_v(bc);
+ else count = tmp_mul - tmp_size;
+
+ while(tmp_fields-- > 6)
+ get_v(bc);
+
+ if(count == 0 || i+count > 256){
+ av_log(s, AV_LOG_ERROR, "illegal count %d at %d\n", count, i);
+ return -1;
+ }
+ if(tmp_stream > nut->stream_count + 1){
+ av_log(s, AV_LOG_ERROR, "illegal stream number\n");
+ return -1;
+ }
+
+ for(j=0; j<count; j++,i++){
+ nut->frame_code[i].flags = tmp_flags ;
+ nut->frame_code[i].timestamp_delta = tmp_time ;
+ nut->frame_code[i].stream_id_plus1 = tmp_stream;
+ nut->frame_code[i].size_mul = tmp_mul ;
+ nut->frame_code[i].size_lsb = tmp_size+j;
+ nut->frame_code[i].reserved_count = tmp_res ;
+ }
+ }
+ if(nut->frame_code['N'].flags != FLAG_INVALID){
+ av_log(s, AV_LOG_ERROR, "illegal frame_code table\n");
+ return -1;
+ }
+
+ if(check_checksum(bc)){
+ av_log(s, AV_LOG_ERROR, "Main header checksum mismatch\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+static int decode_stream_header(NUTContext *nut){
+ AVFormatContext *s= nut->avf;
+ ByteIOContext *bc = &s->pb;
+ int class, nom, denom, stream_id;
+ uint64_t tmp;
+ AVStream *st;
+
+ get_packetheader(nut, bc, 1);
+ stream_id= get_v(bc);
+ if(stream_id >= nut->stream_count || s->streams[stream_id])
+ return -1;
+
+ st = av_new_stream(s, stream_id);
+ if (!st)
+ return AVERROR_NOMEM;
+
+ class = get_v(bc);
+ tmp = get_vb(bc);
+ st->codec->codec_tag= tmp;
+ switch(class)
+ {
+ case 0:
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ st->codec->codec_id = codec_get_bmp_id(tmp);
+ if (st->codec->codec_id == CODEC_ID_NONE)
+ av_log(s, AV_LOG_ERROR, "Unknown codec?!\n");
+ break;
+ case 1:
+ case 32: //compatibility
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_id = codec_get_wav_id(tmp);
+ if (st->codec->codec_id == CODEC_ID_NONE)
+ av_log(s, AV_LOG_ERROR, "Unknown codec?!\n");
+ break;
+ case 2:
+// st->codec->codec_type = CODEC_TYPE_TEXT;
+// break;
+ case 3:
+ st->codec->codec_type = CODEC_TYPE_DATA;
+ break;
+ default:
+ av_log(s, AV_LOG_ERROR, "Unknown stream class (%d)\n", class);
+ return -1;
+ }
+ s->bit_rate += get_v(bc);
+ get_vb(bc); /* language code */
+ nom = get_v(bc);
+ denom = get_v(bc);
+ nut->stream[stream_id].msb_timestamp_shift = get_v(bc);
+ st->codec->has_b_frames=
+ nut->stream[stream_id].decode_delay= get_v(bc);
+ get_byte(bc); /* flags */
+
+ /* codec specific data headers */
+ while(get_v(bc) != 0){
+ st->codec->extradata_size= get_v(bc);
+ if((unsigned)st->codec->extradata_size > (1<<30))
+ return -1;
+ st->codec->extradata= av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ get_buffer(bc, st->codec->extradata, st->codec->extradata_size);
+// url_fskip(bc, get_v(bc));
+ }
+
+ if (st->codec->codec_type == CODEC_TYPE_VIDEO) /* VIDEO */
+ {
+ st->codec->width = get_v(bc);
+ st->codec->height = get_v(bc);
+ st->codec->sample_aspect_ratio.num= get_v(bc);
+ st->codec->sample_aspect_ratio.den= get_v(bc);
+ get_v(bc); /* csp type */
+ }
+ if (st->codec->codec_type == CODEC_TYPE_AUDIO) /* AUDIO */
+ {
+ st->codec->sample_rate = get_v(bc);
+ get_v(bc); // samplerate_den
+ st->codec->channels = get_v(bc);
+ }
+ if(check_checksum(bc)){
+ av_log(s, AV_LOG_ERROR, "Stream header %d checksum mismatch\n", stream_id);
+ return -1;
+ }
+ av_set_pts_info(s->streams[stream_id], 60, denom, nom);
+ nut->stream[stream_id].rate_num= nom;
+ nut->stream[stream_id].rate_den= denom;
+ return 0;
+}
+
+static int decode_info_header(NUTContext *nut){
+ AVFormatContext *s= nut->avf;
+ ByteIOContext *bc = &s->pb;
+
+ get_packetheader(nut, bc, 1);
+
+ for(;;){
+ int id= get_v(bc);
+ char *name, *type, custom_name[256], custom_type[256];
+
+ if(!id)
+ break;
+ else if(id >= sizeof(info_table)/sizeof(info_table[0])){
+ av_log(s, AV_LOG_ERROR, "info id is too large %d %zd\n", id, sizeof(info_table)/sizeof(info_table[0]));
+ return -1;
+ }
+
+ type= info_table[id][1];
+ name= info_table[id][0];
+//av_log(s, AV_LOG_DEBUG, "%d %s %s\n", id, type, name);
+
+ if(!type){
+ get_str(bc, custom_type, sizeof(custom_type));
+ type= custom_type;
+ }
+ if(!name){
+ get_str(bc, custom_name, sizeof(custom_name));
+ name= custom_name;
+ }
+
+ if(!strcmp(type, "v")){
+ get_v(bc);
+ }else{
+ if(!strcmp(name, "Author"))
+ get_str(bc, s->author, sizeof(s->author));
+ else if(!strcmp(name, "Title"))
+ get_str(bc, s->title, sizeof(s->title));
+ else if(!strcmp(name, "Copyright"))
+ get_str(bc, s->copyright, sizeof(s->copyright));
+ else if(!strcmp(name, "Description"))
+ get_str(bc, s->comment, sizeof(s->comment));
+ else
+ get_str(bc, NULL, 0);
+ }
+ }
+ if(check_checksum(bc)){
+ av_log(s, AV_LOG_ERROR, "Info header checksum mismatch\n");
+ return -1;
+ }
+ return 0;
+}
+
+static int nut_read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+ NUTContext *nut = s->priv_data;
+ ByteIOContext *bc = &s->pb;
+ int64_t pos;
+ int inited_stream_count;
+
+ nut->avf= s;
+
+ /* main header */
+ pos=0;
+ for(;;){
+ pos= find_startcode(bc, MAIN_STARTCODE, pos)+1;
+ if (pos<0){
+ av_log(s, AV_LOG_ERROR, "no main startcode found\n");
+ return -1;
+ }
+ if(decode_main_header(nut) >= 0)
+ break;
+ }
+
+
+ s->bit_rate = 0;
+
+ nut->stream = av_malloc(sizeof(StreamContext)*nut->stream_count);
+
+ /* stream headers */
+ pos=0;
+ for(inited_stream_count=0; inited_stream_count < nut->stream_count;){
+ pos= find_startcode(bc, STREAM_STARTCODE, pos)+1;
+ if (pos<0+1){
+ av_log(s, AV_LOG_ERROR, "not all stream headers found\n");
+ return -1;
+ }
+ if(decode_stream_header(nut) >= 0)
+ inited_stream_count++;
+ }
+
+ /* info headers */
+ pos=0;
+ for(;;){
+ uint64_t startcode= find_any_startcode(bc, pos);
+ pos= url_ftell(bc);
+
+ if(startcode==0){
+ av_log(s, AV_LOG_ERROR, "EOF before video frames\n");
+ return -1;
+ }else if(startcode == KEYFRAME_STARTCODE){
+ nut->next_startcode= startcode;
+ break;
+ }else if(startcode != INFO_STARTCODE){
+ continue;
+ }
+
+ decode_info_header(nut);
+ }
+
+ return 0;
+}
+
+static int decode_frame_header(NUTContext *nut, int *key_frame_ret, int64_t *pts_ret, int *stream_id_ret, int frame_code, int frame_type, int64_t frame_start){
+ AVFormatContext *s= nut->avf;
+ StreamContext *stream;
+ ByteIOContext *bc = &s->pb;
+ int size, flags, size_mul, size_lsb, stream_id, time_delta;
+ int64_t pts = 0;
+
+ if(frame_type < 2 && frame_start - nut->packet_start[2] > nut->max_distance){
+ av_log(s, AV_LOG_ERROR, "last frame must have been damaged\n");
+ return -1;
+ }
+
+ if(frame_type)
+ nut->packet_start[ frame_type ]= frame_start; //otherwise 1 goto 1 may happen
+
+ flags= nut->frame_code[frame_code].flags;
+ size_mul= nut->frame_code[frame_code].size_mul;
+ size_lsb= nut->frame_code[frame_code].size_lsb;
+ stream_id= nut->frame_code[frame_code].stream_id_plus1 - 1;
+ time_delta= nut->frame_code[frame_code].timestamp_delta;
+
+ if(stream_id==-1)
+ stream_id= get_v(bc);
+ if(stream_id >= s->nb_streams){
+ av_log(s, AV_LOG_ERROR, "illegal stream_id\n");
+ return -1;
+ }
+ stream= &nut->stream[stream_id];
+
+// av_log(s, AV_LOG_DEBUG, "ft:%d ppts:%d %d %d\n", frame_type, stream->lru_pts_delta[0], stream->lru_pts_delta[1], stream->lru_pts_delta[2]);
+
+ *key_frame_ret= !!(flags & FLAG_KEY_FRAME);
+
+ if(!time_delta){
+ int64_t mask = (1<<stream->msb_timestamp_shift)-1;
+ pts= get_v(bc);
+ if(pts > mask){
+ pts -= mask+1;
+ }else{
+ if(stream->last_pts == AV_NOPTS_VALUE){
+ av_log(s, AV_LOG_ERROR, "no reference pts available\n");
+ return -1;
+ }
+ pts= lsb2full(stream, pts);
+ }
+ }else{
+ if(stream->last_pts == AV_NOPTS_VALUE){
+ av_log(s, AV_LOG_ERROR, "no reference pts available\n");
+ return -1;
+ }
+ pts= stream->last_pts + time_delta;
+ }
+
+ if(*key_frame_ret){
+// av_log(s, AV_LOG_DEBUG, "stream:%d start:%"PRId64" pts:%"PRId64" length:%"PRId64"\n",stream_id, frame_start, av_pts, frame_start - nut->stream[stream_id].last_sync_pos);
+ av_add_index_entry(
+ s->streams[stream_id],
+ frame_start,
+ pts,
+ 0,
+ frame_start - nut->stream[stream_id].last_sync_pos,
+ AVINDEX_KEYFRAME);
+ nut->stream[stream_id].last_sync_pos= frame_start;
+// assert(nut->packet_start == frame_start);
+ }
+
+ assert(size_mul > size_lsb);
+ size= size_lsb;
+ if(flags & FLAG_DATA_SIZE)
+ size+= size_mul*get_v(bc);
+
+#ifdef TRACE
+av_log(s, AV_LOG_DEBUG, "fs:%"PRId64" fc:%d ft:%d kf:%d pts:%"PRId64" size:%d mul:%d lsb:%d flags:%d delta:%d\n", frame_start, frame_code, frame_type, *key_frame_ret, pts, size, size_mul, size_lsb, flags, time_delta);
+#endif
+
+ if(frame_type==0 && url_ftell(bc) - nut->packet_start[2] + size > nut->max_distance){
+ av_log(s, AV_LOG_ERROR, "frame size too large\n");
+ return -1;
+ }
+
+ *stream_id_ret = stream_id;
+ *pts_ret = pts;
+
+ update(nut, stream_id, frame_start, frame_type, frame_code, *key_frame_ret, size, pts);
+
+ return size;
+}
+
+static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code, int frame_type, int64_t frame_start){
+ AVFormatContext *s= nut->avf;
+ ByteIOContext *bc = &s->pb;
+ int size, stream_id, key_frame, discard;
+ int64_t pts, last_IP_pts;
+
+ size= decode_frame_header(nut, &key_frame, &pts, &stream_id, frame_code, frame_type, frame_start);
+ if(size < 0)
+ return -1;
+
+ discard= s->streams[ stream_id ]->discard;
+ last_IP_pts= s->streams[ stream_id ]->last_IP_pts;
+ if( (discard >= AVDISCARD_NONKEY && !key_frame)
+ ||(discard >= AVDISCARD_BIDIR && last_IP_pts != AV_NOPTS_VALUE && last_IP_pts > pts)
+ || discard >= AVDISCARD_ALL){
+ url_fskip(bc, size);
+ return 1;
+ }
+
+ av_get_packet(bc, pkt, size);
+ pkt->stream_index = stream_id;
+ if (key_frame)
+ pkt->flags |= PKT_FLAG_KEY;
+ pkt->pts = pts;
+
+ return 0;
+}
+
+static int nut_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ NUTContext *nut = s->priv_data;
+ ByteIOContext *bc = &s->pb;
+ int i, frame_code=0, ret;
+
+ for(;;){
+ int64_t pos= url_ftell(bc);
+ int frame_type= 0;
+ uint64_t tmp= nut->next_startcode;
+ nut->next_startcode=0;
+
+ if (url_feof(bc))
+ return -1;
+
+ if(tmp){
+ pos-=8;
+ }else{
+ frame_code = get_byte(bc);
+ if(frame_code == 'N'){
+ tmp= frame_code;
+ for(i=1; i<8; i++)
+ tmp = (tmp<<8) + get_byte(bc);
+ }
+ }
+ switch(tmp){
+ case MAIN_STARTCODE:
+ case STREAM_STARTCODE:
+ case INDEX_STARTCODE:
+ get_packetheader(nut, bc, 0);
+ assert(nut->packet_start[2] == pos);
+ url_fseek(bc, nut->written_packet_size, SEEK_CUR);
+ break;
+ case INFO_STARTCODE:
+ if(decode_info_header(nut)<0)
+ goto resync;
+ break;
+ case KEYFRAME_STARTCODE:
+ frame_type = 2;
+ reset(s, get_v(bc));
+ frame_code = get_byte(bc);
+ case 0:
+ ret= decode_frame(nut, pkt, frame_code, frame_type, pos);
+ if(ret==0)
+ return 0;
+ else if(ret==1) //ok but discard packet
+ break;
+ default:
+resync:
+av_log(s, AV_LOG_DEBUG, "syncing from %"PRId64"\n", nut->packet_start[2]+1);
+ tmp= find_any_startcode(bc, nut->packet_start[2]+1);
+ if(tmp==0)
+ return -1;
+av_log(s, AV_LOG_DEBUG, "sync\n");
+ nut->next_startcode= tmp;
+ }
+ }
+}
+
+static int64_t nut_read_timestamp(AVFormatContext *s, int stream_index, int64_t *pos_arg, int64_t pos_limit){
+ NUTContext *nut = s->priv_data;
+ StreamContext *stream;
+ ByteIOContext *bc = &s->pb;
+ int64_t pos, pts;
+ uint64_t code;
+ int frame_code,step, stream_id, i,size, key_frame;
+av_log(s, AV_LOG_DEBUG, "read_timestamp(X,%d,%"PRId64",%"PRId64")\n", stream_index, *pos_arg, pos_limit);
+
+ if(*pos_arg < 0)
+ return AV_NOPTS_VALUE;
+
+ pos= *pos_arg;
+ step= FFMIN(16*1024, pos);
+ do{
+ pos-= step;
+ code= find_any_startcode(bc, pos);
+
+ if(code && url_ftell(bc) - 8 <= *pos_arg)
+ break;
+ step= FFMIN(2*step, pos);
+ }while(step);
+
+ if(!code) //nothing found, not even after pos_arg
+ return AV_NOPTS_VALUE;
+
+ url_fseek(bc, -8, SEEK_CUR);
+ for(i=0; i<s->nb_streams; i++)
+ nut->stream[i].last_sync_pos= url_ftell(bc);
+
+ for(;;){
+ int frame_type=0;
+ int64_t pos= url_ftell(bc);
+ uint64_t tmp=0;
+
+ if(pos > pos_limit || url_feof(bc))
+ return AV_NOPTS_VALUE;
+
+ frame_code = get_byte(bc);
+ if(frame_code == 'N'){
+ tmp= frame_code;
+ for(i=1; i<8; i++)
+ tmp = (tmp<<8) + get_byte(bc);
+ }
+//av_log(s, AV_LOG_DEBUG, "before switch %"PRIX64" at=%"PRId64"\n", tmp, pos);
+
+ switch(tmp){
+ case MAIN_STARTCODE:
+ case STREAM_STARTCODE:
+ case INDEX_STARTCODE:
+ case INFO_STARTCODE:
+ get_packetheader(nut, bc, 0);
+ assert(nut->packet_start[2]==pos);
+ url_fseek(bc, nut->written_packet_size, SEEK_CUR);
+ break;
+ case KEYFRAME_STARTCODE:
+ frame_type=2;
+ reset(s, get_v(bc));
+ frame_code = get_byte(bc);
+ case 0:
+ size= decode_frame_header(nut, &key_frame, &pts, &stream_id, frame_code, frame_type, pos);
+ if(size < 0)
+ goto resync;
+
+ stream= &nut->stream[stream_id];
+ if(stream_id != stream_index || !key_frame || pos < *pos_arg){
+ url_fseek(bc, size, SEEK_CUR);
+ break;
+ }
+
+ *pos_arg= pos;
+ return pts;
+ default:
+resync:
+av_log(s, AV_LOG_DEBUG, "syncing from %"PRId64"\n", nut->packet_start[2]+1);
+ if(!find_any_startcode(bc, nut->packet_start[2]+1))
+ return AV_NOPTS_VALUE;
+
+ url_fseek(bc, -8, SEEK_CUR);
+ }
+ }
+ return AV_NOPTS_VALUE;
+}
+
+static int nut_read_seek(AVFormatContext *s, int stream_index, int64_t target_ts, int flags){
+// NUTContext *nut = s->priv_data;
+ int64_t pos;
+
+ if(av_seek_frame_binary(s, stream_index, target_ts, flags) < 0)
+ return -1;
+
+ pos= url_ftell(&s->pb);
+ nut_read_timestamp(s, stream_index, &pos, pos-1);
+
+ return 0;
+}
+
+static int nut_read_close(AVFormatContext *s)
+{
+ NUTContext *nut = s->priv_data;
+
+ av_freep(&nut->stream);
+
+ return 0;
+}
+
+#ifdef CONFIG_NUT_DEMUXER
+AVInputFormat nut_demuxer = {
+ "nut",
+ "nut format",
+ sizeof(NUTContext),
+ nut_probe,
+ nut_read_header,
+ nut_read_packet,
+ nut_read_close,
+ nut_read_seek,
+ nut_read_timestamp,
+ .extensions = "nut",
+};
+#endif
+#ifdef CONFIG_NUT_MUXER
+AVOutputFormat nut_muxer = {
+ "nut",
+ "nut format",
+ "video/x-nut",
+ "nut",
+ sizeof(NUTContext),
+#ifdef CONFIG_LIBVORBIS
+ CODEC_ID_VORBIS,
+#elif defined(CONFIG_LIBMP3LAME)
+ CODEC_ID_MP3,
+#else
+ CODEC_ID_MP2, /* AC3 needs liba52 decoder */
+#endif
+ CODEC_ID_MPEG4,
+ nut_write_header,
+ nut_write_packet,
+ nut_write_trailer,
+ .flags = AVFMT_GLOBALHEADER,
+};
+#endif
diff --git a/contrib/ffmpeg/libavformat/nut.h b/contrib/ffmpeg/libavformat/nut.h
new file mode 100644
index 000000000..82bbf6f17
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/nut.h
@@ -0,0 +1,97 @@
+/*
+ * "NUT" Container Format (de)muxer
+ * 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
+ *
+ */
+
+//#include <limits.h>
+#include "avformat.h"
+#include "crc.h"
+//#include "mpegaudio.h"
+#include "riff.h"
+//#include "adler32.h"
+
+#define MAIN_STARTCODE (0x7A561F5F04ADULL + (((uint64_t)('N'<<8) + 'M')<<48))
+#define STREAM_STARTCODE (0x11405BF2F9DBULL + (((uint64_t)('N'<<8) + 'S')<<48))
+#define SYNCPOINT_STARTCODE (0xE4ADEECA4569ULL + (((uint64_t)('N'<<8) + 'K')<<48))
+#define INDEX_STARTCODE (0xDD672F23E64EULL + (((uint64_t)('N'<<8) + 'X')<<48))
+#define INFO_STARTCODE (0xAB68B596BA78ULL + (((uint64_t)('N'<<8) + 'I')<<48))
+
+#define ID_STRING "nut/multimedia container\0"
+
+#define MAX_DISTANCE (1024*32-1)
+
+typedef enum{
+ FLAG_KEY = 1, ///<if set, frame is keyframe
+ FLAG_EOR = 2, ///<if set, stream has no relevance on presentation. (EOR)
+ FLAG_CODED_PTS = 8, ///<if set, coded_pts is in the frame header
+ FLAG_STREAM_ID = 16, ///<if set, stream_id is coded in the frame header
+ FLAG_SIZE_MSB = 32, ///<if set, data_size_msb is at frame header, otherwise data_size_msb is 0
+ FLAG_CHECKSUM = 64, ///<if set then the frame header contains a checksum
+ FLAG_RESERVED = 128, ///<if set, reserved_count is coded in the frame header
+ FLAG_CODED =4096, ///<if set, coded_flags are stored in the frame header.
+ FLAG_INVALID =8192, ///<if set, frame_code is invalid.
+}flag_t;
+
+typedef struct {
+ uint64_t pos;
+ uint64_t back_ptr;
+// uint64_t global_key_pts;
+ int64_t ts;
+} syncpoint_t;
+
+typedef struct {
+ uint16_t flags;
+ uint8_t stream_id;
+ uint16_t size_mul;
+ uint16_t size_lsb;
+ int16_t pts_delta;
+ uint8_t reserved_count;
+} FrameCode; // maybe s/FrameCode/framecode_t/ or change all to java style but dont mix
+
+typedef struct {
+ int last_flags;
+ int skip_until_key_frame;
+ int64_t last_pts;
+ int time_base_id;
+ AVRational time_base;
+ int msb_pts_shift;
+ int max_pts_distance;
+ int decode_delay; //FIXME duplicate of has_b_frames
+} StreamContext;// maybe s/StreamContext/streamcontext_t/
+
+typedef struct {
+ AVFormatContext *avf;
+// int written_packet_size;
+// int64_t packet_start[3]; //0-> startcode less, 1-> short startcode 2-> long startcodes
+ FrameCode frame_code[256];
+ uint64_t next_startcode; ///< stores the next startcode if it has alraedy been parsed but the stream isnt seekable
+ StreamContext *stream;
+ unsigned int max_distance;
+ unsigned int time_base_count;
+ int64_t last_syncpoint_pos;
+ AVRational *time_base;
+ struct AVTreeNode *syncpoints;
+} NUTContext;
+
+
+//FIXME move to a common spot, like crc.c/h
+static unsigned long av_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len){
+ return av_crc(av_crc04C11DB7, checksum, buf, len);
+}
diff --git a/contrib/ffmpeg/libavformat/nutdec.c b/contrib/ffmpeg/libavformat/nutdec.c
new file mode 100644
index 000000000..c0f331c27
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/nutdec.c
@@ -0,0 +1,885 @@
+/*
+ * "NUT" Container Format demuxer
+ * Copyright (c) 2004-2006 Michael Niedermayer
+ * Copyright (c) 2003 Alex Beregszaszi
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include "tree.h"
+#include "nut.h"
+
+#undef NDEBUG
+#include <assert.h>
+
+static uint64_t get_v(ByteIOContext *bc){
+ uint64_t val = 0;
+ int tmp;
+
+ do{
+ tmp = get_byte(bc);
+ val= (val<<7) + (tmp&127);
+ }while(tmp&128);
+ return val;
+}
+
+static int get_str(ByteIOContext *bc, char *string, unsigned int maxlen){
+ unsigned int len= get_v(bc);
+
+ if(len && maxlen)
+ get_buffer(bc, string, FFMIN(len, maxlen));
+ while(len > maxlen){
+ get_byte(bc);
+ len--;
+ }
+
+ if(maxlen)
+ string[FFMIN(len, maxlen-1)]= 0;
+
+ if(maxlen == len)
+ return -1;
+ else
+ return 0;
+}
+
+static int64_t get_s(ByteIOContext *bc){
+ int64_t v = get_v(bc) + 1;
+
+ if (v&1) return -(v>>1);
+ else return (v>>1);
+}
+
+static uint64_t get_fourcc(ByteIOContext *bc){
+ unsigned int len= get_v(bc);
+
+ if (len==2) return get_le16(bc);
+ else if(len==4) return get_le32(bc);
+ else return -1;
+}
+
+#ifdef TRACE
+static inline uint64_t get_v_trace(ByteIOContext *bc, char *file, char *func, int line){
+ uint64_t v= get_v(bc);
+
+ printf("get_v %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line);
+ return v;
+}
+
+static inline int64_t get_s_trace(ByteIOContext *bc, char *file, char *func, int line){
+ int64_t v= get_s(bc);
+
+ printf("get_s %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line);
+ return v;
+}
+
+static inline uint64_t get_vb_trace(ByteIOContext *bc, char *file, char *func, int line){
+ uint64_t v= get_vb(bc);
+
+ printf("get_vb %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line);
+ return v;
+}
+#define get_v(bc) get_v_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
+#define get_s(bc) get_s_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
+#define get_vb(bc) get_vb_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
+#endif
+
+static int get_packetheader(NUTContext *nut, ByteIOContext *bc, int calculate_checksum)
+{
+ int64_t start, size;
+// start= url_ftell(bc) - 8;
+
+ size= get_v(bc);
+ if(size > 4096)
+ get_be32(bc); //FIXME check this
+
+ init_checksum(bc, calculate_checksum ? av_crc04C11DB7_update : NULL, 0);
+
+// nut->packet_start[2] = start;
+// nut->written_packet_size= size;
+
+ return size;
+}
+
+static uint64_t find_any_startcode(ByteIOContext *bc, int64_t pos){
+ uint64_t state=0;
+
+ if(pos >= 0)
+ url_fseek(bc, pos, SEEK_SET); //note, this may fail if the stream isnt seekable, but that shouldnt matter, as in this case we simply start where we are currently
+
+ while(!url_feof(bc)){
+ state= (state<<8) | get_byte(bc);
+ if((state>>56) != 'N')
+ continue;
+ switch(state){
+ case MAIN_STARTCODE:
+ case STREAM_STARTCODE:
+ case SYNCPOINT_STARTCODE:
+ case INFO_STARTCODE:
+ case INDEX_STARTCODE:
+ return state;
+ }
+ }
+
+ return 0;
+}
+
+/**
+ * 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
+ */
+static int64_t find_startcode(ByteIOContext *bc, uint64_t code, int64_t pos){
+ for(;;){
+ uint64_t startcode= find_any_startcode(bc, pos);
+ if(startcode == code)
+ return url_ftell(bc) - 8;
+ else if(startcode == 0)
+ return -1;
+ pos=-1;
+ }
+}
+
+static int64_t lsb2full(StreamContext *stream, int64_t lsb){
+ int64_t mask = (1<<stream->msb_pts_shift)-1;
+ int64_t delta= stream->last_pts - mask/2;
+ return ((lsb - delta)&mask) + delta;
+}
+
+static int nut_probe(AVProbeData *p){
+ int i;
+ uint64_t code= 0;
+
+ for (i = 0; i < p->buf_size; i++) {
+ code = (code << 8) | p->buf[i];
+ if (code == MAIN_STARTCODE)
+ return AVPROBE_SCORE_MAX;
+ }
+ return 0;
+}
+
+#define GET_V(dst, check) \
+ tmp= get_v(bc);\
+ if(!(check)){\
+ av_log(s, AV_LOG_ERROR, "Error " #dst " is (%"PRId64")\n", tmp);\
+ return -1;\
+ }\
+ dst= tmp;
+
+static int skip_reserved(ByteIOContext *bc, int64_t pos){
+ pos -= url_ftell(bc);
+ if(pos<0){
+ url_fseek(bc, pos, SEEK_CUR);
+ return -1;
+ }else{
+ while(pos--)
+ get_byte(bc);
+ return 0;
+ }
+}
+
+static int decode_main_header(NUTContext *nut){
+ AVFormatContext *s= nut->avf;
+ ByteIOContext *bc = &s->pb;
+ uint64_t tmp, end;
+ unsigned int stream_count;
+ int i, j, tmp_stream, tmp_mul, tmp_pts, tmp_size, count, tmp_res;
+
+ end= get_packetheader(nut, bc, 1);
+ end += url_ftell(bc);
+
+ GET_V(tmp , tmp >=2 && tmp <= 3)
+ GET_V(stream_count , tmp > 0 && tmp <=MAX_STREAMS)
+
+ nut->max_distance = get_v(bc);
+ if(nut->max_distance > 65536){
+ av_log(s, AV_LOG_DEBUG, "max_distance %d\n", nut->max_distance);
+ nut->max_distance= 65536;
+ }
+
+ GET_V(nut->time_base_count, tmp>0 && tmp<INT_MAX / sizeof(AVRational))
+ nut->time_base= av_malloc(nut->time_base_count * sizeof(AVRational));
+
+ for(i=0; i<nut->time_base_count; i++){
+ GET_V(nut->time_base[i].num, tmp>0 && tmp<(1ULL<<31))
+ GET_V(nut->time_base[i].den, tmp>0 && tmp<(1ULL<<31))
+ if(ff_gcd(nut->time_base[i].num, nut->time_base[i].den) != 1){
+ av_log(s, AV_LOG_ERROR, "time base invalid\n");
+ return -1;
+ }
+ }
+ tmp_pts=0;
+ tmp_mul=1;
+ tmp_stream=0;
+ for(i=0; i<256;){
+ int tmp_flags = get_v(bc);
+ int tmp_fields= get_v(bc);
+ if(tmp_fields>0) tmp_pts = get_s(bc);
+ if(tmp_fields>1) tmp_mul = get_v(bc);
+ if(tmp_fields>2) tmp_stream= get_v(bc);
+ if(tmp_fields>3) tmp_size = get_v(bc);
+ else tmp_size = 0;
+ if(tmp_fields>4) tmp_res = get_v(bc);
+ else tmp_res = 0;
+ if(tmp_fields>5) count = get_v(bc);
+ else count = tmp_mul - tmp_size;
+
+ while(tmp_fields-- > 6)
+ get_v(bc);
+
+ if(count == 0 || i+count > 256){
+ av_log(s, AV_LOG_ERROR, "illegal count %d at %d\n", count, i);
+ return -1;
+ }
+ if(tmp_stream >= stream_count){
+ av_log(s, AV_LOG_ERROR, "illegal stream number\n");
+ return -1;
+ }
+
+ for(j=0; j<count; j++,i++){
+ if (i == 'N') {
+ nut->frame_code[i].flags= FLAG_INVALID;
+ j--;
+ continue;
+ }
+ nut->frame_code[i].flags = tmp_flags ;
+ nut->frame_code[i].pts_delta = tmp_pts ;
+ nut->frame_code[i].stream_id = tmp_stream;
+ nut->frame_code[i].size_mul = tmp_mul ;
+ nut->frame_code[i].size_lsb = tmp_size+j;
+ nut->frame_code[i].reserved_count = tmp_res ;
+ }
+ }
+ assert(nut->frame_code['N'].flags == FLAG_INVALID);
+
+ if(skip_reserved(bc, end) || get_checksum(bc)){
+ av_log(s, AV_LOG_ERROR, "Main header checksum mismatch\n");
+ return -1;
+ }
+
+ nut->stream = av_mallocz(sizeof(StreamContext)*stream_count);
+ for(i=0; i<stream_count; i++){
+ av_new_stream(s, i);
+ }
+
+ return 0;
+}
+
+static int decode_stream_header(NUTContext *nut){
+ AVFormatContext *s= nut->avf;
+ ByteIOContext *bc = &s->pb;
+ StreamContext *stc;
+ int class, stream_id;
+ uint64_t tmp, end;
+ AVStream *st;
+
+ end= get_packetheader(nut, bc, 1);
+ end += url_ftell(bc);
+
+ GET_V(stream_id, tmp < s->nb_streams && !nut->stream[tmp].time_base.num);
+ stc= &nut->stream[stream_id];
+
+ st = s->streams[stream_id];
+ if (!st)
+ return AVERROR_NOMEM;
+
+ class = get_v(bc);
+ tmp = get_fourcc(bc);
+ st->codec->codec_tag= tmp;
+ switch(class)
+ {
+ case 0:
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ st->codec->codec_id = codec_get_bmp_id(tmp);
+ if (st->codec->codec_id == CODEC_ID_NONE)
+ av_log(s, AV_LOG_ERROR, "Unknown codec?!\n");
+ break;
+ case 1:
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_id = codec_get_wav_id(tmp);
+ if (st->codec->codec_id == CODEC_ID_NONE)
+ av_log(s, AV_LOG_ERROR, "Unknown codec?!\n");
+ break;
+ case 2:
+// st->codec->codec_type = CODEC_TYPE_TEXT;
+// break;
+ case 3:
+ st->codec->codec_type = CODEC_TYPE_DATA;
+ break;
+ default:
+ av_log(s, AV_LOG_ERROR, "Unknown stream class (%d)\n", class);
+ return -1;
+ }
+ GET_V(stc->time_base_id , tmp < nut->time_base_count);
+ GET_V(stc->msb_pts_shift , tmp < 16);
+ stc->max_pts_distance= get_v(bc);
+ GET_V(stc->decode_delay , tmp < 1000); //sanity limit, raise this if moors law is true
+ st->codec->has_b_frames= stc->decode_delay;
+ get_v(bc); //stream flags
+
+ GET_V(st->codec->extradata_size, tmp < (1<<30));
+ if(st->codec->extradata_size){
+ st->codec->extradata= av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ get_buffer(bc, st->codec->extradata, st->codec->extradata_size);
+ }
+
+ if (st->codec->codec_type == CODEC_TYPE_VIDEO){
+ GET_V(st->codec->width , tmp > 0)
+ GET_V(st->codec->height, tmp > 0)
+ st->codec->sample_aspect_ratio.num= get_v(bc);
+ st->codec->sample_aspect_ratio.den= get_v(bc);
+ if((!st->codec->sample_aspect_ratio.num) != (!st->codec->sample_aspect_ratio.den)){
+ av_log(s, AV_LOG_ERROR, "invalid aspect ratio\n");
+ return -1;
+ }
+ get_v(bc); /* csp type */
+ }else if (st->codec->codec_type == CODEC_TYPE_AUDIO){
+ GET_V(st->codec->sample_rate , tmp > 0)
+ tmp= get_v(bc); // samplerate_den
+ if(tmp > st->codec->sample_rate){
+ av_log(s, AV_LOG_ERROR, "bleh, libnut muxed this ;)\n");
+ st->codec->sample_rate= tmp;
+ }
+ GET_V(st->codec->channels, tmp > 0)
+ }
+ if(skip_reserved(bc, end) || get_checksum(bc)){
+ av_log(s, AV_LOG_ERROR, "Stream header %d checksum mismatch\n", stream_id);
+ return -1;
+ }
+ stc->time_base= nut->time_base[stc->time_base_id];
+ av_set_pts_info(s->streams[stream_id], 63, stc->time_base.num, stc->time_base.den);
+ return 0;
+}
+
+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;
+ int chapter_id, i;
+ int64_t value, end;
+ char name[256], str_value[1024], type_str[256], *type= type_str;
+
+ end= get_packetheader(nut, bc, 1);
+ end += url_ftell(bc);
+
+ GET_V(stream_id_plus1, tmp <= s->nb_streams)
+ chapter_id = get_s(bc);
+ chapter_start= get_v(bc);
+ chapter_len = get_v(bc);
+ count = get_v(bc);
+ for(i=0; i<count; i++){
+ get_str(bc, name, sizeof(name));
+ value= get_s(bc);
+ if(value == -1){
+ type= "UTF-8";
+ get_str(bc, str_value, sizeof(str_value));
+ }else if(value == -2){
+ get_str(bc, type, sizeof(type));
+ get_str(bc, str_value, sizeof(str_value));
+ }else if(value == -3){
+ type= "s";
+ value= get_s(bc);
+ }else if(value == -4){
+ type= "t";
+ value= get_v(bc);
+ }else if(value < -4){
+ type= "r";
+ get_s(bc);
+ }else{
+ type= "v";
+ }
+
+ if(chapter_id==0 && !strcmp(type, "UTF-8")){
+ if (!strcmp(name, "Author"))
+ pstrcpy(s->author , sizeof(s->author) , str_value);
+ else if(!strcmp(name, "Title"))
+ pstrcpy(s->title , sizeof(s->title) , str_value);
+ else if(!strcmp(name, "Copyright"))
+ pstrcpy(s->copyright, sizeof(s->copyright), str_value);
+ else if(!strcmp(name, "Description"))
+ pstrcpy(s->comment , sizeof(s->comment) , str_value);
+ }
+ }
+
+ if(skip_reserved(bc, end) || get_checksum(bc)){
+ av_log(s, AV_LOG_ERROR, "Info header checksum mismatch\n");
+ return -1;
+ }
+ return 0;
+}
+
+int sp_pos_cmp(syncpoint_t *a, syncpoint_t *b){
+ return (a->pos - b->pos>>32) - (b->pos - a->pos>>32);
+}
+
+int sp_pts_cmp(syncpoint_t *a, syncpoint_t *b){
+ return (a->ts - b->ts>>32) - (b->ts - a->ts>>32);
+}
+
+static void add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts){
+ syncpoint_t *sp2, *sp= av_mallocz(sizeof(syncpoint_t));
+
+ sp->pos= pos;
+ sp->back_ptr= back_ptr;
+ sp->ts= ts;
+ sp2= av_tree_insert(&nut->syncpoints, sp, sp_pos_cmp);
+ if(sp2 && sp2 != sp)
+ av_free(sp);
+}
+
+static int decode_syncpoint(NUTContext *nut, int64_t *ts, int64_t *back_ptr){
+ AVFormatContext *s= nut->avf;
+ ByteIOContext *bc = &s->pb;
+ int64_t end, tmp;
+ int i;
+ AVRational time_base;
+
+ nut->last_syncpoint_pos= url_ftell(bc)-8;
+
+ end= get_packetheader(nut, bc, 1);
+ end += url_ftell(bc);
+
+ tmp= get_v(bc);
+ *back_ptr= nut->last_syncpoint_pos - 16*get_v(bc);
+ if(*back_ptr < 0)
+ return -1;
+
+ time_base= nut->time_base[tmp % nut->time_base_count];
+ for(i=0; i<s->nb_streams; i++){
+ nut->stream[i].last_pts= av_rescale_rnd(
+ tmp / nut->time_base_count,
+ time_base.num * (int64_t)nut->stream[i].time_base.den,
+ time_base.den * (int64_t)nut->stream[i].time_base.num,
+ AV_ROUND_DOWN);
+ //last_key_frame ?
+ }
+ //FIXME put this in a reset func maybe
+
+ if(skip_reserved(bc, end) || get_checksum(bc)){
+ av_log(s, AV_LOG_ERROR, "sync point checksum mismatch\n");
+ return -1;
+ }
+
+ *ts= tmp / s->nb_streams * av_q2d(nut->time_base[tmp % s->nb_streams])*AV_TIME_BASE;
+ add_sp(nut, nut->last_syncpoint_pos, *back_ptr, *ts);
+
+ return 0;
+}
+
+static int find_and_decode_index(NUTContext *nut){
+ AVFormatContext *s= nut->avf;
+ ByteIOContext *bc = &s->pb;
+ uint64_t tmp, end;
+ int i, j, syncpoint_count;
+ int64_t filesize= url_fsize(bc);
+ int64_t *syncpoints;
+ int8_t *has_keyframe;
+
+ url_fseek(bc, filesize-12, SEEK_SET);
+ url_fseek(bc, filesize-get_be64(bc), SEEK_SET);
+ if(get_be64(bc) != INDEX_STARTCODE){
+ av_log(s, AV_LOG_ERROR, "no index at the end\n");
+ return -1;
+ }
+
+ end= get_packetheader(nut, bc, 1);
+ end += url_ftell(bc);
+
+ get_v(bc); //max_pts
+ GET_V(syncpoint_count, tmp < INT_MAX/8 && tmp > 0)
+ syncpoints= av_malloc(sizeof(int64_t)*syncpoint_count);
+ has_keyframe= av_malloc(sizeof(int8_t)*(syncpoint_count+1));
+ for(i=0; i<syncpoint_count; i++){
+ GET_V(syncpoints[i], tmp>0)
+ if(i)
+ syncpoints[i] += syncpoints[i-1];
+ }
+
+ for(i=0; i<s->nb_streams; i++){
+ int64_t last_pts= -1;
+ for(j=0; j<syncpoint_count;){
+ uint64_t x= get_v(bc);
+ int type= x&1;
+ int n= j;
+ x>>=1;
+ if(type){
+ int flag= x&1;
+ x>>=1;
+ if(n+x >= syncpoint_count + 1){
+ av_log(s, AV_LOG_ERROR, "index overflow A\n");
+ return -1;
+ }
+ while(x--)
+ has_keyframe[n++]= flag;
+ has_keyframe[n++]= !flag;
+ }else{
+ while(x != 1){
+ if(n>=syncpoint_count + 1){
+ av_log(s, AV_LOG_ERROR, "index overflow B\n");
+ return -1;
+ }
+ has_keyframe[n++]= x&1;
+ x>>=1;
+ }
+ }
+ if(has_keyframe[0]){
+ av_log(s, AV_LOG_ERROR, "keyframe before first syncpoint in index\n");
+ return -1;
+ }
+ assert(n<=syncpoint_count+1);
+ for(; j<n; j++){
+ if(has_keyframe[j]){
+ uint64_t B, A= get_v(bc);
+ if(!A){
+ A= get_v(bc);
+ B= get_v(bc);
+ //eor_pts[j][i] = last_pts + A + B
+ }else
+ B= 0;
+ av_add_index_entry(
+ s->streams[i],
+ 16*syncpoints[j-1],
+ last_pts + A,
+ 0,
+ 0,
+ AVINDEX_KEYFRAME);
+ last_pts += A + B;
+ }
+ }
+ }
+ }
+
+ if(skip_reserved(bc, end) || get_checksum(bc)){
+ av_log(s, AV_LOG_ERROR, "Index checksum mismatch\n");
+ return -1;
+ }
+ return 0;
+}
+
+static int nut_read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+ NUTContext *nut = s->priv_data;
+ ByteIOContext *bc = &s->pb;
+ int64_t pos;
+ int inited_stream_count;
+
+ nut->avf= s;
+
+ /* main header */
+ pos=0;
+ do{
+ pos= find_startcode(bc, MAIN_STARTCODE, pos)+1;
+ if (pos<0+1){
+ av_log(s, AV_LOG_ERROR, "no main startcode found\n");
+ return -1;
+ }
+ }while(decode_main_header(nut) < 0);
+
+ /* stream headers */
+ pos=0;
+ for(inited_stream_count=0; inited_stream_count < s->nb_streams;){
+ pos= find_startcode(bc, STREAM_STARTCODE, pos)+1;
+ if (pos<0+1){
+ av_log(s, AV_LOG_ERROR, "not all stream headers found\n");
+ return -1;
+ }
+ if(decode_stream_header(nut) >= 0)
+ inited_stream_count++;
+ }
+
+ /* info headers */
+ pos=0;
+ for(;;){
+ uint64_t startcode= find_any_startcode(bc, pos);
+ pos= url_ftell(bc);
+
+ if(startcode==0){
+ av_log(s, AV_LOG_ERROR, "EOF before video frames\n");
+ return -1;
+ }else if(startcode == SYNCPOINT_STARTCODE){
+ nut->next_startcode= startcode;
+ break;
+ }else if(startcode != INFO_STARTCODE){
+ continue;
+ }
+
+ decode_info_header(nut);
+ }
+
+ s->data_offset= pos-8;
+
+ if(!url_is_streamed(bc)){
+ int64_t orig_pos= url_ftell(bc);
+ find_and_decode_index(nut);
+ url_fseek(bc, orig_pos, SEEK_SET);
+ }
+ assert(nut->next_startcode == SYNCPOINT_STARTCODE);
+
+ return 0;
+}
+
+static int decode_frame_header(NUTContext *nut, int64_t *pts, int *stream_id, int frame_code){
+ AVFormatContext *s= nut->avf;
+ ByteIOContext *bc = &s->pb;
+ StreamContext *stc;
+ int size, flags, size_mul, pts_delta, i, reserved_count;
+ uint64_t tmp;
+
+ if(url_ftell(bc) > nut->last_syncpoint_pos + nut->max_distance){
+ av_log(s, AV_LOG_ERROR, "last frame must have been damaged %Ld > %Ld + %d\n", url_ftell(bc), nut->last_syncpoint_pos, nut->max_distance);
+ return -1;
+ }
+
+ flags = nut->frame_code[frame_code].flags;
+ size_mul = nut->frame_code[frame_code].size_mul;
+ size = nut->frame_code[frame_code].size_lsb;
+ *stream_id = nut->frame_code[frame_code].stream_id;
+ pts_delta = nut->frame_code[frame_code].pts_delta;
+ reserved_count = nut->frame_code[frame_code].reserved_count;
+
+ if(flags & FLAG_INVALID)
+ return -1;
+ if(flags & FLAG_CODED)
+ flags ^= get_v(bc);
+ if(flags & FLAG_STREAM_ID){
+ GET_V(*stream_id, tmp < s->nb_streams)
+ }
+ stc= &nut->stream[*stream_id];
+ if(flags&FLAG_CODED_PTS){
+ int coded_pts= get_v(bc);
+//FIXME check last_pts validity?
+ if(coded_pts < (1<<stc->msb_pts_shift)){
+ *pts=lsb2full(stc, coded_pts);
+ }else
+ *pts=coded_pts - (1<<stc->msb_pts_shift);
+ }else
+ *pts= stc->last_pts + pts_delta;
+ if(flags&FLAG_SIZE_MSB){
+ size += size_mul*get_v(bc);
+ }
+ if(flags&FLAG_RESERVED)
+ reserved_count= get_v(bc);
+ for(i=0; i<reserved_count; i++)
+ get_v(bc);
+ if(flags&FLAG_CHECKSUM){
+ get_be32(bc); //FIXME check this
+ }else if(size > 2*nut->max_distance || FFABS(stc->last_pts - *pts) > stc->max_pts_distance){
+ av_log(s, AV_LOG_ERROR, "frame size > 2max_distance and no checksum\n");
+ return -1;
+ }
+
+ stc->last_pts= *pts;
+ stc->last_flags= flags;
+
+ return size;
+}
+
+static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code){
+ AVFormatContext *s= nut->avf;
+ ByteIOContext *bc = &s->pb;
+ int size, stream_id, discard;
+ int64_t pts, last_IP_pts;
+ StreamContext *stc;
+
+ size= decode_frame_header(nut, &pts, &stream_id, frame_code);
+ if(size < 0)
+ return -1;
+
+ stc= &nut->stream[stream_id];
+
+ if (stc->last_flags & FLAG_KEY)
+ stc->skip_until_key_frame=0;
+
+ discard= s->streams[ stream_id ]->discard;
+ last_IP_pts= s->streams[ stream_id ]->last_IP_pts;
+ if( (discard >= AVDISCARD_NONKEY && !(stc->last_flags & FLAG_KEY))
+ ||(discard >= AVDISCARD_BIDIR && last_IP_pts != AV_NOPTS_VALUE && last_IP_pts > pts)
+ || discard >= AVDISCARD_ALL
+ || stc->skip_until_key_frame){
+ url_fskip(bc, size);
+ return 1;
+ }
+
+ av_get_packet(bc, pkt, size);
+ pkt->stream_index = stream_id;
+ if (stc->last_flags & FLAG_KEY)
+ pkt->flags |= PKT_FLAG_KEY;
+ pkt->pts = pts;
+
+ return 0;
+}
+
+static int nut_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ NUTContext *nut = s->priv_data;
+ ByteIOContext *bc = &s->pb;
+ int i, frame_code=0, ret, skip;
+ int64_t ts, back_ptr;
+
+ for(;;){
+ int64_t pos= url_ftell(bc);
+ uint64_t tmp= nut->next_startcode;
+ nut->next_startcode=0;
+
+ if(tmp){
+ pos-=8;
+ }else{
+ frame_code = get_byte(bc);
+ if(url_feof(bc))
+ return -1;
+ if(frame_code == 'N'){
+ tmp= frame_code;
+ for(i=1; i<8; i++)
+ tmp = (tmp<<8) + get_byte(bc);
+ }
+ }
+ switch(tmp){
+ case MAIN_STARTCODE:
+ case STREAM_STARTCODE:
+ case INDEX_STARTCODE:
+ skip= get_packetheader(nut, bc, 0);
+ url_fseek(bc, skip, SEEK_CUR);
+ break;
+ case INFO_STARTCODE:
+ if(decode_info_header(nut)<0)
+ goto resync;
+ break;
+ case SYNCPOINT_STARTCODE:
+ if(decode_syncpoint(nut, &ts, &back_ptr)<0)
+ goto resync;
+ frame_code = get_byte(bc);
+ case 0:
+ ret= decode_frame(nut, pkt, frame_code);
+ if(ret==0)
+ return 0;
+ else if(ret==1) //ok but discard packet
+ break;
+ default:
+resync:
+av_log(s, AV_LOG_DEBUG, "syncing from %"PRId64"\n", pos);
+ tmp= find_any_startcode(bc, nut->last_syncpoint_pos+1);
+ if(tmp==0)
+ return -1;
+av_log(s, AV_LOG_DEBUG, "sync\n");
+ nut->next_startcode= tmp;
+ }
+ }
+}
+
+static int64_t nut_read_timestamp(AVFormatContext *s, int stream_index, int64_t *pos_arg, int64_t pos_limit){
+ NUTContext *nut = s->priv_data;
+ ByteIOContext *bc = &s->pb;
+ int64_t pos, pts, back_ptr;
+av_log(s, AV_LOG_DEBUG, "read_timestamp(X,%d,%"PRId64",%"PRId64")\n", stream_index, *pos_arg, pos_limit);
+
+ pos= *pos_arg;
+resync:
+ do{
+ pos= find_startcode(bc, SYNCPOINT_STARTCODE, pos)+1;
+ if(pos < 1){
+ assert(nut->next_startcode == 0);
+ av_log(s, AV_LOG_ERROR, "read_timestamp failed\n");
+ return AV_NOPTS_VALUE;
+ }
+ }while(decode_syncpoint(nut, &pts, &back_ptr) < 0);
+ *pos_arg = pos-1;
+ assert(nut->last_syncpoint_pos == *pos_arg);
+
+ av_log(s, AV_LOG_DEBUG, "return %Ld %Ld\n", pts,back_ptr );
+ if (stream_index == -1) return pts;
+ else if(stream_index == -2) return back_ptr;
+
+assert(0);
+}
+
+static int read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flags){
+ NUTContext *nut = s->priv_data;
+ AVStream *st= s->streams[stream_index];
+ syncpoint_t dummy={.ts= pts*av_q2d(st->time_base)*AV_TIME_BASE};
+ syncpoint_t nopts_sp= {.ts= AV_NOPTS_VALUE, .back_ptr= AV_NOPTS_VALUE};
+ syncpoint_t *sp, *next_node[2]= {&nopts_sp, &nopts_sp};
+ int64_t pos, pos2, ts;
+ int i;
+
+ if(st->index_entries){
+ int index= av_index_search_timestamp(st, pts, flags);
+ if(index<0)
+ return -1;
+
+ pos2= st->index_entries[index].pos;
+ ts = st->index_entries[index].timestamp;
+ }else{
+ av_tree_find(nut->syncpoints, &dummy, sp_pts_cmp, next_node);
+ av_log(s, AV_LOG_DEBUG, "%Ld-%Ld %Ld-%Ld\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,
+ next_node[0]->ts , next_node[1]->ts, AVSEEK_FLAG_BACKWARD, &ts, nut_read_timestamp);
+
+ if(!(flags & AVSEEK_FLAG_BACKWARD)){
+ dummy.pos= pos+16;
+ next_node[1]= &nopts_sp;
+ av_tree_find(nut->syncpoints, &dummy, sp_pos_cmp, 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)
+ pos= pos2;
+ //FIXME dir but i think it doesnt matter
+ }
+ dummy.pos= pos;
+ sp= av_tree_find(nut->syncpoints, &dummy, sp_pos_cmp, NULL);
+
+ assert(sp);
+ pos2= sp->back_ptr - 15;
+ }
+ av_log(NULL, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", pos2);
+ pos= find_startcode(&s->pb, SYNCPOINT_STARTCODE, pos2);
+ url_fseek(&s->pb, pos, SEEK_SET);
+ av_log(NULL, AV_LOG_DEBUG, "SP: %"PRId64"\n", pos);
+ if(pos2 > pos || pos2 + 15 < pos){
+ av_log(NULL, AV_LOG_ERROR, "no syncpoint at backptr pos\n");
+ }
+ for(i=0; i<s->nb_streams; i++)
+ nut->stream[i].skip_until_key_frame=1;
+
+ return 0;
+}
+
+static int nut_read_close(AVFormatContext *s)
+{
+ NUTContext *nut = s->priv_data;
+
+ av_freep(&nut->time_base);
+ av_freep(&nut->stream);
+
+ return 0;
+}
+
+#ifdef CONFIG_NUT_DEMUXER
+AVInputFormat nut_demuxer = {
+ "nut",
+ "nut format",
+ sizeof(NUTContext),
+ nut_probe,
+ nut_read_header,
+ nut_read_packet,
+ nut_read_close,
+ read_seek,
+ .extensions = "nut",
+};
+#endif
diff --git a/contrib/ffmpeg/libavformat/nuv.c b/contrib/ffmpeg/libavformat/nuv.c
new file mode 100644
index 000000000..7e04222ee
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/nuv.c
@@ -0,0 +1,241 @@
+/*
+ * NuppelVideo demuxer.
+ * Copyright (c) 2006 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 "avformat.h"
+#include "riff.h"
+
+typedef struct {
+ int v_id;
+ int a_id;
+} NUVContext;
+
+typedef enum {
+ NUV_VIDEO = 'V',
+ NUV_EXTRADATA = 'D',
+ NUV_AUDIO = 'A',
+ NUV_SEEKP = 'R',
+ NUV_MYTHEXT = 'X'
+} frametype_t;
+
+static int nuv_probe(AVProbeData *p) {
+ if (p->buf_size < 12)
+ return 0;
+ if (!memcmp(p->buf, "NuppelVideo", 12))
+ return AVPROBE_SCORE_MAX;
+ if (!memcmp(p->buf, "MythTVVideo", 12))
+ return AVPROBE_SCORE_MAX;
+ return 0;
+}
+
+//! little macro to sanitize packet size
+#define PKTSIZE(s) (s & 0xffffff)
+
+/**
+ * \brief read until we found all data needed for decoding
+ * \param vst video stream of which to change parameters
+ * \param ast video stream of which to change parameters
+ * \param myth set if this is a MythTVVideo format file
+ * \return 1 if all required codec data was found
+ */
+static int get_codec_data(ByteIOContext *pb, AVStream *vst,
+ AVStream *ast, int myth) {
+ frametype_t frametype;
+ if (!vst && !myth)
+ return 1; // no codec data needed
+ while (!url_feof(pb)) {
+ int size, subtype;
+ frametype = get_byte(pb);
+ switch (frametype) {
+ case NUV_EXTRADATA:
+ subtype = get_byte(pb);
+ url_fskip(pb, 6);
+ size = PKTSIZE(get_le32(pb));
+ if (vst && subtype == 'R') {
+ vst->codec->extradata_size = size;
+ vst->codec->extradata = av_malloc(size);
+ get_buffer(pb, vst->codec->extradata, size);
+ size = 0;
+ if (!myth)
+ return 1;
+ }
+ break;
+ case NUV_MYTHEXT:
+ url_fskip(pb, 7);
+ size = PKTSIZE(get_le32(pb));
+ if (size != 128 * 4)
+ break;
+ get_le32(pb); // version
+ if (vst) {
+ vst->codec->codec_tag = get_le32(pb);
+ vst->codec->codec_id =
+ codec_get_id(codec_bmp_tags, vst->codec->codec_tag);
+ } else
+ url_fskip(pb, 4);
+
+ if (ast) {
+ ast->codec->codec_tag = get_le32(pb);
+ ast->codec->sample_rate = get_le32(pb);
+ ast->codec->bits_per_sample = get_le32(pb);
+ ast->codec->channels = get_le32(pb);
+ ast->codec->codec_id =
+ wav_codec_get_id(ast->codec->codec_tag,
+ ast->codec->bits_per_sample);
+ } else
+ url_fskip(pb, 4 * 4);
+
+ size -= 6 * 4;
+ url_fskip(pb, size);
+ return 1;
+ case NUV_SEEKP:
+ size = 11;
+ break;
+ default:
+ url_fskip(pb, 7);
+ size = PKTSIZE(get_le32(pb));
+ break;
+ }
+ url_fskip(pb, size);
+ }
+ return 0;
+}
+
+static int nuv_header(AVFormatContext *s, AVFormatParameters *ap) {
+ NUVContext *ctx = (NUVContext *)s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ char id_string[12], version_string[5];
+ double aspect, fps;
+ int is_mythtv, width, height, v_packs, a_packs;
+ int stream_nr = 0;
+ AVStream *vst = NULL, *ast = NULL;
+ get_buffer(pb, id_string, 12);
+ is_mythtv = !memcmp(id_string, "MythTVVideo", 12);
+ get_buffer(pb, version_string, 5);
+ url_fskip(pb, 3); // padding
+ width = get_le32(pb);
+ height = get_le32(pb);
+ get_le32(pb); // unused, "desiredwidth"
+ get_le32(pb); // unused, "desiredheight"
+ get_byte(pb); // 'P' == progressive, 'I' == interlaced
+ url_fskip(pb, 3); // padding
+ aspect = av_int2dbl(get_le64(pb));
+ fps = av_int2dbl(get_le64(pb));
+
+ // number of packets per stream type, -1 means unknown, e.g. streaming
+ v_packs = get_le32(pb);
+ a_packs = get_le32(pb);
+ get_le32(pb); // text
+
+ get_le32(pb); // keyframe distance (?)
+
+ if (v_packs) {
+ ctx->v_id = stream_nr++;
+ vst = av_new_stream(s, ctx->v_id);
+ vst->codec->codec_type = CODEC_TYPE_VIDEO;
+ vst->codec->codec_id = CODEC_ID_NUV;
+ vst->codec->codec_tag = MKTAG('R', 'J', 'P', 'G');
+ vst->codec->width = width;
+ vst->codec->height = height;
+ vst->codec->bits_per_sample = 10;
+ vst->codec->sample_aspect_ratio = av_d2q(aspect, 10000);
+ vst->r_frame_rate = av_d2q(fps, 60000);
+ av_set_pts_info(vst, 32, 1, 1000);
+ } else
+ ctx->v_id = -1;
+
+ if (a_packs) {
+ ctx->a_id = stream_nr++;
+ ast = av_new_stream(s, ctx->a_id);
+ ast->codec->codec_type = CODEC_TYPE_AUDIO;
+ ast->codec->codec_id = CODEC_ID_PCM_S16LE;
+ ast->codec->channels = 2;
+ ast->codec->sample_rate = 44100;
+ ast->codec->bit_rate = 2 * 2 * 44100 * 8;
+ ast->codec->block_align = 2 * 2;
+ ast->codec->bits_per_sample = 16;
+ av_set_pts_info(ast, 32, 1, 1000);
+ } else
+ ctx->a_id = -1;
+
+ get_codec_data(pb, vst, ast, is_mythtv);
+ return 0;
+}
+
+#define HDRSIZE 12
+
+static int nuv_packet(AVFormatContext *s, AVPacket *pkt) {
+ NUVContext *ctx = (NUVContext *)s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ uint8_t hdr[HDRSIZE];
+ frametype_t frametype;
+ int ret, size;
+ while (!url_feof(pb)) {
+ ret = get_buffer(pb, hdr, HDRSIZE);
+ if (ret <= 0)
+ return ret ? ret : -1;
+ frametype = hdr[0];
+ size = PKTSIZE(AV_RL32(&hdr[8]));
+ switch (frametype) {
+ case NUV_VIDEO:
+ case NUV_EXTRADATA:
+ if (ctx->v_id < 0) {
+ av_log(s, AV_LOG_ERROR, "Video packet in file without video stream!\n");
+ url_fskip(pb, size);
+ break;
+ }
+ ret = av_new_packet(pkt, HDRSIZE + size);
+ if (ret < 0)
+ return ret;
+ pkt->pos = url_ftell(pb);
+ pkt->pts = AV_RL32(&hdr[4]);
+ pkt->stream_index = ctx->v_id;
+ memcpy(pkt->data, hdr, HDRSIZE);
+ ret = get_buffer(pb, pkt->data + HDRSIZE, size);
+ return ret;
+ case NUV_AUDIO:
+ if (ctx->a_id < 0) {
+ av_log(s, AV_LOG_ERROR, "Audio packet in file without audio stream!\n");
+ url_fskip(pb, size);
+ break;
+ }
+ ret = av_get_packet(pb, pkt, size);
+ pkt->pts = AV_RL32(&hdr[4]);
+ pkt->stream_index = ctx->a_id;
+ return ret;
+ case NUV_SEEKP:
+ // contains no data, size value is invalid
+ break;
+ default:
+ url_fskip(pb, size);
+ break;
+ }
+ }
+ return AVERROR_IO;
+}
+
+AVInputFormat nuv_demuxer = {
+ "nuv",
+ "NuppelVideo format",
+ sizeof(NUVContext),
+ nuv_probe,
+ nuv_header,
+ nuv_packet,
+ NULL,
+ NULL,
+};
diff --git a/contrib/ffmpeg/libavformat/ogg.c b/contrib/ffmpeg/libavformat/ogg.c
new file mode 100644
index 000000000..c98bb2273
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/ogg.c
@@ -0,0 +1,283 @@
+/*
+ * Ogg bitstream support
+ * Mark Hills <mark@pogo.org.uk>
+ *
+ * Uses libogg, but requires libvorbisenc to construct correct headers
+ * when containing Vorbis stream -- currently the only format supported
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 <stdio.h>
+
+#include <ogg/ogg.h>
+
+#include "avformat.h"
+
+#undef NDEBUG
+#include <assert.h>
+
+#define DECODER_BUFFER_SIZE 4096
+
+
+typedef struct OggContext {
+ /* output */
+ ogg_stream_state os ;
+ int header_handled ;
+ ogg_packet op;
+
+ /* input */
+ ogg_sync_state oy ;
+} OggContext ;
+
+
+#ifdef CONFIG_MUXERS
+static int ogg_write_header(AVFormatContext *avfcontext)
+{
+ OggContext *context = avfcontext->priv_data;
+ ogg_packet *op= &context->op;
+ int n;
+
+ ogg_stream_init(&context->os, 31415);
+
+ for(n = 0 ; n < avfcontext->nb_streams ; n++) {
+ AVCodecContext *codec = avfcontext->streams[n]->codec;
+ uint8_t *headers = codec->extradata;
+ int headers_len = codec->extradata_size;
+ uint8_t *header_start[3];
+ int header_len[3];
+ int i, j;
+
+ av_set_pts_info(avfcontext->streams[n], 60, 1, AV_TIME_BASE);
+
+ for(j=1,i=0;i<2;++i, ++j) {
+ header_len[i]=0;
+ while(j<headers_len && headers[j]==0xff) {
+ header_len[i]+=0xff;
+ ++j;
+ }
+ header_len[i]+=headers[j];
+ }
+ header_len[2]=headers_len-header_len[0]-header_len[1]-j;
+ headers+=j;
+ header_start[0] = headers;
+ header_start[1] = header_start[0] + header_len[0];
+ header_start[2] = header_start[1] + header_len[1];
+
+ for(i=0; i < 3; ++i){
+ op->bytes = header_len[i];
+
+ op->packet= header_start[i];
+ op->b_o_s= op->packetno==0;
+
+ ogg_stream_packetin(&context->os, op);
+
+ op->packetno++; //FIXME multiple streams
+ }
+
+ context->header_handled = 0 ;
+ }
+
+ return 0 ;
+}
+
+static int ogg_write_packet(AVFormatContext *avfcontext, AVPacket *pkt)
+{
+ OggContext *context = avfcontext->priv_data ;
+ AVCodecContext *avctx= avfcontext->streams[pkt->stream_index]->codec;
+ ogg_packet *op= &context->op;
+ ogg_page og ;
+ int64_t pts;
+
+ pts= av_rescale(pkt->pts, avctx->sample_rate, AV_TIME_BASE);
+
+// av_log(avfcontext, AV_LOG_DEBUG, "M%d\n", size);
+
+ /* flush header packets so audio starts on a new page */
+
+ if(!context->header_handled) {
+ while(ogg_stream_flush(&context->os, &og)) {
+ put_buffer(&avfcontext->pb, og.header, og.header_len) ;
+ put_buffer(&avfcontext->pb, og.body, og.body_len) ;
+ put_flush_packet(&avfcontext->pb);
+ }
+ context->header_handled = 1 ;
+ }
+
+ op->packet = (uint8_t*) pkt->data;
+ op->bytes = pkt->size;
+ op->b_o_s = op->packetno == 0;
+ op->granulepos= pts;
+
+ /* correct the fields in the packet -- essential for streaming */
+
+ ogg_stream_packetin(&context->os, op);
+
+ while(ogg_stream_pageout(&context->os, &og)) {
+ put_buffer(&avfcontext->pb, og.header, og.header_len);
+ put_buffer(&avfcontext->pb, og.body, og.body_len);
+ put_flush_packet(&avfcontext->pb);
+ }
+ op->packetno++;
+
+ return 0;
+}
+
+
+static int ogg_write_trailer(AVFormatContext *avfcontext) {
+ OggContext *context = avfcontext->priv_data ;
+ ogg_page og ;
+
+ while(ogg_stream_flush(&context->os, &og)) {
+ put_buffer(&avfcontext->pb, og.header, og.header_len) ;
+ put_buffer(&avfcontext->pb, og.body, og.body_len) ;
+ put_flush_packet(&avfcontext->pb);
+ }
+
+ ogg_stream_clear(&context->os) ;
+ return 0 ;
+}
+
+
+AVOutputFormat ogg_muxer = {
+ "ogg",
+ "Ogg format",
+ "application/ogg",
+ "ogg",
+ sizeof(OggContext),
+ CODEC_ID_VORBIS,
+ 0,
+ ogg_write_header,
+ ogg_write_packet,
+ ogg_write_trailer,
+} ;
+#endif //CONFIG_MUXERS
+
+#if 0
+static int next_packet(AVFormatContext *avfcontext, ogg_packet *op) {
+ OggContext *context = avfcontext->priv_data ;
+ ogg_page og ;
+ char *buf ;
+
+ while(ogg_stream_packetout(&context->os, op) != 1) {
+
+ /* while no pages are available, read in more data to the sync */
+ while(ogg_sync_pageout(&context->oy, &og) != 1) {
+ buf = ogg_sync_buffer(&context->oy, DECODER_BUFFER_SIZE) ;
+ if(get_buffer(&avfcontext->pb, buf, DECODER_BUFFER_SIZE) <= 0)
+ return 1 ;
+ ogg_sync_wrote(&context->oy, DECODER_BUFFER_SIZE) ;
+ }
+
+ /* got a page. Feed it into the stream and get the packet */
+ if(ogg_stream_pagein(&context->os, &og) != 0)
+ return 1 ;
+ }
+
+ return 0 ;
+}
+
+
+static int ogg_read_header(AVFormatContext *avfcontext, AVFormatParameters *ap)
+{
+ OggContext *context = avfcontext->priv_data;
+ ogg_packet op ;
+ char *buf ;
+ ogg_page og ;
+ AVStream *ast ;
+ AVCodecContext *codec;
+ uint8_t *p;
+ int i;
+
+ ogg_sync_init(&context->oy) ;
+ buf = ogg_sync_buffer(&context->oy, DECODER_BUFFER_SIZE) ;
+
+ if(get_buffer(&avfcontext->pb, buf, DECODER_BUFFER_SIZE) <= 0)
+ return AVERROR_IO ;
+
+ ogg_sync_wrote(&context->oy, DECODER_BUFFER_SIZE) ;
+ ogg_sync_pageout(&context->oy, &og) ;
+ ogg_stream_init(&context->os, ogg_page_serialno(&og)) ;
+ ogg_stream_pagein(&context->os, &og) ;
+
+ /* currently only one vorbis stream supported */
+
+ ast = av_new_stream(avfcontext, 0) ;
+ if(!ast)
+ return AVERROR_NOMEM ;
+ av_set_pts_info(ast, 60, 1, AV_TIME_BASE);
+
+ codec= &ast->codec;
+ codec->codec_type = CODEC_TYPE_AUDIO;
+ codec->codec_id = CODEC_ID_VORBIS;
+ for(i=0; i<3; i++){
+ if(next_packet(avfcontext, &op)){
+ return -1;
+ }
+ if(op.bytes >= (1<<16) || op.bytes < 0)
+ return -1;
+ codec->extradata_size+= 2 + op.bytes;
+ codec->extradata= av_realloc(codec->extradata, codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ memset(codec->extradata + codec->extradata_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+ p= codec->extradata + codec->extradata_size - 2 - op.bytes;
+ *(p++)= op.bytes>>8;
+ *(p++)= op.bytes&0xFF;
+ memcpy(p, op.packet, op.bytes);
+ }
+
+ return 0 ;
+}
+
+
+static int ogg_read_packet(AVFormatContext *avfcontext, AVPacket *pkt) {
+ ogg_packet op ;
+
+ if(next_packet(avfcontext, &op))
+ return AVERROR_IO ;
+ if(av_new_packet(pkt, op.bytes) < 0)
+ return AVERROR_IO ;
+ pkt->stream_index = 0 ;
+ memcpy(pkt->data, op.packet, op.bytes);
+ if(avfcontext->streams[0]->codec.sample_rate && op.granulepos!=-1)
+ pkt->pts= av_rescale(op.granulepos, AV_TIME_BASE, avfcontext->streams[0]->codec.sample_rate);
+// printf("%"PRId64" %d %d\n", pkt->pts, (int)op.granulepos, avfcontext->streams[0]->codec.sample_rate);
+
+ return op.bytes;
+}
+
+
+static int ogg_read_close(AVFormatContext *avfcontext) {
+ OggContext *context = avfcontext->priv_data ;
+
+ ogg_stream_clear(&context->os) ;
+ ogg_sync_clear(&context->oy) ;
+
+ return 0 ;
+}
+
+
+static AVInputFormat ogg_iformat = {
+ "ogg",
+ "Ogg Vorbis",
+ sizeof(OggContext),
+ NULL,
+ ogg_read_header,
+ ogg_read_packet,
+ ogg_read_close,
+ .extensions = "ogg",
+} ;
+#endif
diff --git a/contrib/ffmpeg/libavformat/ogg2.c b/contrib/ffmpeg/libavformat/ogg2.c
new file mode 100644
index 000000000..8ca7b2d13
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/ogg2.c
@@ -0,0 +1,700 @@
+/*
+ * Ogg bitstream support
+ * Luca Barbato <lu_zero@gentoo.org>
+ * Based on tcvp implementation
+ *
+ */
+
+/**
+ Copyright (C) 2005 Michael Ahlberg, Måns Rullgård
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the "Software"), to deal in the Software without
+ restriction, including without limitation the rights to use, copy,
+ modify, merge, publish, distribute, sublicense, and/or sell copies
+ of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+**/
+
+
+#include <stdio.h>
+#include "ogg2.h"
+#include "avformat.h"
+
+#define MAX_PAGE_SIZE 65307
+#define DECODER_BUFFER_SIZE MAX_PAGE_SIZE
+
+static ogg_codec_t *ogg_codecs[] = {
+ &vorbis_codec,
+ &theora_codec,
+ &flac_codec,
+ &ogm_video_codec,
+ &ogm_audio_codec,
+ &ogm_old_codec,
+ NULL
+};
+
+#if 0 // CONFIG_MUXERS
+static int
+ogg_write_header (AVFormatContext * avfcontext)
+{
+}
+
+static int
+ogg_write_packet (AVFormatContext * avfcontext, AVPacket * pkt)
+{
+}
+
+
+static int
+ogg_write_trailer (AVFormatContext * avfcontext)
+{
+}
+
+
+AVOutputFormat ogg_muxer = {
+ "ogg",
+ "Ogg format",
+ "application/ogg",
+ "ogg",
+ sizeof (OggContext),
+ CODEC_ID_VORBIS,
+ 0,
+ ogg_write_header,
+ ogg_write_packet,
+ ogg_write_trailer,
+};
+#endif //CONFIG_MUXERS
+
+//FIXME We could avoid some structure duplication
+static int
+ogg_save (AVFormatContext * s)
+{
+ ogg_t *ogg = s->priv_data;
+ ogg_state_t *ost =
+ av_malloc(sizeof (*ost) + (ogg->nstreams-1) * sizeof (*ogg->streams));
+ int i;
+ ost->pos = url_ftell (&s->pb);;
+ ost->curidx = ogg->curidx;
+ ost->next = ogg->state;
+ ost->nstreams = ogg->nstreams;
+ memcpy(ost->streams, ogg->streams, ogg->nstreams * sizeof(*ogg->streams));
+
+ for (i = 0; i < ogg->nstreams; i++){
+ ogg_stream_t *os = ogg->streams + i;
+ os->buf = av_malloc (os->bufsize);
+ memset (os->buf, 0, os->bufsize);
+ memcpy (os->buf, ost->streams[i].buf, os->bufpos);
+ }
+
+ ogg->state = ost;
+
+ return 0;
+}
+
+static int
+ogg_restore (AVFormatContext * s, int discard)
+{
+ ogg_t *ogg = s->priv_data;
+ ByteIOContext *bc = &s->pb;
+ ogg_state_t *ost = ogg->state;
+ int i;
+
+ if (!ost)
+ return 0;
+
+ ogg->state = ost->next;
+
+ if (!discard){
+ for (i = 0; i < ogg->nstreams; i++)
+ av_free (ogg->streams[i].buf);
+
+ url_fseek (bc, ost->pos, SEEK_SET);
+ ogg->curidx = ost->curidx;
+ ogg->nstreams = ost->nstreams;
+ memcpy(ogg->streams, ost->streams,
+ ost->nstreams * sizeof(*ogg->streams));
+ }
+
+ av_free (ost);
+
+ return 0;
+}
+
+static int
+ogg_reset (ogg_t * ogg)
+{
+ int i;
+
+ for (i = 0; i < ogg->nstreams; i++){
+ ogg_stream_t *os = ogg->streams + i;
+ os->bufpos = 0;
+ os->pstart = 0;
+ os->psize = 0;
+ os->granule = -1;
+ os->lastgp = -1;
+ os->nsegs = 0;
+ os->segp = 0;
+ }
+
+ ogg->curidx = -1;
+
+ return 0;
+}
+
+static ogg_codec_t *
+ogg_find_codec (uint8_t * buf, int size)
+{
+ int i;
+
+ for (i = 0; ogg_codecs[i]; i++)
+ if (size >= ogg_codecs[i]->magicsize &&
+ !memcmp (buf, ogg_codecs[i]->magic, ogg_codecs[i]->magicsize))
+ return ogg_codecs[i];
+
+ return NULL;
+}
+
+static int
+ogg_find_stream (ogg_t * 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)
+{
+
+ ogg_t *ogg = s->priv_data;
+ int idx = ogg->nstreams++;
+ AVStream *st;
+ ogg_stream_t *os;
+
+ ogg->streams = av_realloc (ogg->streams,
+ ogg->nstreams * sizeof (*ogg->streams));
+ memset (ogg->streams + idx, 0, sizeof (*ogg->streams));
+ os = ogg->streams + idx;
+ os->serial = serial;
+ os->bufsize = DECODER_BUFFER_SIZE;
+ os->buf = av_malloc(os->bufsize);
+ os->header = -1;
+
+ st = av_new_stream (s, idx);
+ if (!st)
+ return AVERROR_NOMEM;
+
+ av_set_pts_info(st, 64, 1, 1000000);
+
+ return idx;
+}
+
+static int
+ogg_new_buf(ogg_t *ogg, int idx)
+{
+ ogg_stream_t *os = ogg->streams + idx;
+ uint8_t *nb = av_malloc(os->bufsize);
+ int size = os->bufpos - os->pstart;
+ if(os->buf){
+ memcpy(nb, os->buf + os->pstart, size);
+ av_free(os->buf);
+ }
+ os->buf = nb;
+ os->bufpos = size;
+ os->pstart = 0;
+
+ return 0;
+}
+
+static int
+ogg_read_page (AVFormatContext * s, int *str)
+{
+ ByteIOContext *bc = &s->pb;
+ ogg_t *ogg = s->priv_data;
+ ogg_stream_t *os;
+ int i = 0;
+ int flags, nsegs;
+ uint64_t gp;
+ uint32_t serial;
+ uint32_t seq;
+ uint32_t crc;
+ int size, idx;
+ uint8_t sync[4];
+ int sp = 0;
+
+ if (get_buffer (bc, sync, 4) < 4)
+ return -1;
+
+ do{
+ int c;
+
+ if (sync[sp & 3] == 'O' &&
+ sync[(sp + 1) & 3] == 'g' &&
+ sync[(sp + 2) & 3] == 'g' && sync[(sp + 3) & 3] == 'S')
+ break;
+
+ c = url_fgetc (bc);
+ if (c < 0)
+ return -1;
+ sync[sp++ & 3] = c;
+ }while (i++ < MAX_PAGE_SIZE);
+
+ if (i >= MAX_PAGE_SIZE){
+ av_log (s, AV_LOG_INFO, "ogg, can't find sync word\n");
+ return -1;
+ }
+
+ if (url_fgetc (bc) != 0) /* version */
+ return -1;
+
+ flags = url_fgetc (bc);
+ gp = get_le64 (bc);
+ serial = get_le32 (bc);
+ seq = get_le32 (bc);
+ crc = get_le32 (bc);
+ nsegs = url_fgetc (bc);
+
+ idx = ogg_find_stream (ogg, serial);
+ if (idx < 0){
+ idx = ogg_new_stream (s, serial);
+ if (idx < 0)
+ return -1;
+ }
+
+ os = ogg->streams + idx;
+
+ if(os->psize > 0)
+ ogg_new_buf(ogg, idx);
+
+ if (get_buffer (bc, os->segments, nsegs) < nsegs)
+ return -1;
+
+ os->nsegs = nsegs;
+ os->segp = 0;
+
+ size = 0;
+ for (i = 0; i < nsegs; i++)
+ size += os->segments[i];
+
+ if (flags & OGG_FLAG_CONT){
+ if (!os->psize){
+ while (os->segp < os->nsegs){
+ int seg = os->segments[os->segp++];
+ os->pstart += seg;
+ if (seg < 255)
+ break;
+ }
+ }
+ }else{
+ os->psize = 0;
+ }
+
+ if (os->bufsize - os->bufpos < size){
+ uint8_t *nb = av_malloc (os->bufsize *= 2);
+ memcpy (nb, os->buf, os->bufpos);
+ av_free (os->buf);
+ os->buf = nb;
+ }
+
+ 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;
+
+ if (str)
+ *str = idx;
+
+ return 0;
+}
+
+static int
+ogg_packet (AVFormatContext * s, int *str, int *dstart, int *dsize)
+{
+ ogg_t *ogg = s->priv_data;
+ int idx;
+ ogg_stream_t *os;
+ int complete = 0;
+ int segp = 0, psize = 0;
+
+#if 0
+ av_log (s, AV_LOG_DEBUG, "ogg_packet: curidx=%i\n", ogg->curidx);
+#endif
+
+ do{
+ idx = ogg->curidx;
+
+ while (idx < 0){
+ if (ogg_read_page (s, &idx) < 0)
+ return -1;
+ }
+
+ os = ogg->streams + idx;
+
+#if 0
+ av_log (s, AV_LOG_DEBUG,
+ "ogg_packet: idx=%d pstart=%d psize=%d segp=%d nsegs=%d\n",
+ idx, os->pstart, os->psize, os->segp, os->nsegs);
+#endif
+
+ if (!os->codec){
+ if (os->header < 0){
+ os->codec = ogg_find_codec (os->buf, os->bufpos);
+ if (!os->codec){
+ os->header = 0;
+ return 0;
+ }
+ }else{
+ return 0;
+ }
+ }
+
+ segp = os->segp;
+ psize = os->psize;
+
+ while (os->segp < os->nsegs){
+ int ss = os->segments[os->segp++];
+ os->psize += ss;
+ if (ss < 255){
+ complete = 1;
+ break;
+ }
+ }
+
+ if (!complete && os->segp == os->nsegs){
+ ogg->curidx = -1;
+ }
+ }while (!complete);
+
+#if 0
+ av_log (s, AV_LOG_DEBUG,
+ "ogg_packet: idx %i, frame size %i, start %i\n",
+ idx, os->psize, os->pstart);
+#endif
+
+ ogg->curidx = idx;
+
+ if (os->header < 0){
+ int hdr = os->codec->header (s, idx);
+ if (!hdr){
+ os->header = os->seq;
+ os->segp = segp;
+ os->psize = psize;
+ ogg->headers = 1;
+ }else{
+ os->pstart += os->psize;
+ os->psize = 0;
+ }
+ }
+
+ if (os->header > -1 && os->seq > os->header){
+ if (os->codec && os->codec->packet)
+ os->codec->packet (s, idx);
+ if (str)
+ *str = idx;
+ if (dstart)
+ *dstart = os->pstart;
+ if (dsize)
+ *dsize = os->psize;
+ os->pstart += os->psize;
+ os->psize = 0;
+ }
+
+ os->seq++;
+ if (os->segp == os->nsegs)
+ ogg->curidx = -1;
+
+ return 0;
+}
+
+static int
+ogg_get_headers (AVFormatContext * s)
+{
+ ogg_t *ogg = s->priv_data;
+
+ do{
+ if (ogg_packet (s, NULL, NULL, NULL) < 0)
+ return -1;
+ }while (!ogg->headers);
+
+#if 0
+ av_log (s, AV_LOG_DEBUG, "found headers\n");
+#endif
+
+ return 0;
+}
+
+static uint64_t
+ogg_gptopts (AVFormatContext * s, int i, uint64_t gp)
+{
+ ogg_t *ogg = s->priv_data;
+ ogg_stream_t *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)
+{
+ ogg_t *ogg = s->priv_data;
+ int idx = -1, i;
+ offset_t size, end;
+
+ if(s->pb.is_streamed)
+ return 0;
+
+// already set
+ if (s->duration != AV_NOPTS_VALUE)
+ return 0;
+
+ size = url_fsize(&s->pb);
+ if(size < 0)
+ return 0;
+ end = size > MAX_PAGE_SIZE? size - MAX_PAGE_SIZE: size;
+
+ ogg_save (s);
+ url_fseek (&s->pb, end, SEEK_SET);
+
+ while (!ogg_read_page (s, &i)){
+ if (ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0 &&
+ ogg->streams[i].codec)
+ idx = i;
+ }
+
+ if (idx != -1){
+ s->streams[idx]->duration =
+ ogg_gptopts (s, idx, ogg->streams[idx].granule);
+ }
+
+ ogg->size = size;
+ ogg_restore (s, 0);
+ ogg_save (s);
+ while (!ogg_read_page (s, &i)) {
+ if (i == idx && ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0)
+ break;
+ }
+ if (i == idx) {
+ s->streams[idx]->start_time = ogg_gptopts (s, idx, ogg->streams[idx].granule);
+ s->streams[idx]->duration -= s->streams[idx]->start_time;
+ }
+ ogg_restore (s, 0);
+
+ return 0;
+}
+
+
+static int
+ogg_read_header (AVFormatContext * s, AVFormatParameters * ap)
+{
+ ogg_t *ogg = s->priv_data;
+ ogg->curidx = -1;
+ //linear headers seek from start
+ if (ogg_get_headers (s) < 0){
+ return -1;
+ }
+
+ //linear granulepos seek from end
+ ogg_get_length (s);
+
+ //fill the extradata in the per codec callbacks
+ return 0;
+}
+
+
+static int
+ogg_read_packet (AVFormatContext * s, AVPacket * pkt)
+{
+ ogg_t *ogg;
+ ogg_stream_t *os;
+ int idx = -1;
+ int pstart, psize;
+
+ //Get an ogg packet
+ do{
+ if (ogg_packet (s, &idx, &pstart, &psize) < 0)
+ return AVERROR_IO;
+ }while (idx < 0 || !s->streams[idx]);
+
+ ogg = s->priv_data;
+ os = ogg->streams + idx;
+
+ //Alloc a pkt
+ if (av_new_packet (pkt, psize) < 0)
+ return AVERROR_IO;
+ 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;
+ }
+
+ return psize;
+}
+
+
+static int
+ogg_read_close (AVFormatContext * s)
+{
+ ogg_t *ogg = s->priv_data;
+ int i;
+
+ for (i = 0; i < ogg->nstreams; i++){
+ av_free (ogg->streams[i].buf);
+ av_free (ogg->streams[i].private);
+ }
+ av_free (ogg->streams);
+ return 0;
+}
+
+
+static int
+ogg_read_seek (AVFormatContext * s, int stream_index, int64_t target_ts,
+ int flags)
+{
+ AVStream *st = s->streams[stream_index];
+ ogg_t *ogg = s->priv_data;
+ ByteIOContext *bc = &s->pb;
+ uint64_t min = 0, max = ogg->size;
+ uint64_t tmin = st->start_time, tmax = st->start_time + st->duration;
+ int64_t pts = AV_NOPTS_VALUE;
+
+ ogg_save (s);
+
+ if ((uint64_t)target_ts < tmin || target_ts < 0)
+ target_ts = tmin;
+ while (min <= max && tmin < tmax){
+ uint64_t p = min + (max - min) * (target_ts - tmin) / (tmax - tmin);
+ int i = -1;
+
+ url_fseek (bc, p, SEEK_SET);
+
+ while (!ogg_read_page (s, &i)){
+ if (i == stream_index && ogg->streams[i].granule != 0 &&
+ ogg->streams[i].granule != -1)
+ break;
+ }
+
+ if (i == -1)
+ break;
+
+ pts = ogg_gptopts (s, i, ogg->streams[i].granule);
+ p = url_ftell (bc);
+
+ if (FFABS (pts - target_ts) * st->time_base.num < st->time_base.den)
+ break;
+
+ if (pts > target_ts){
+ if (max == p && tmax == pts) {
+ // probably our tmin is wrong, causing us to always end up too late in the file
+ tmin = (target_ts + tmin + 1) / 2;
+ if (tmin == target_ts) {
+ url_fseek(bc, min, SEEK_SET);
+ break;
+ }
+ }
+ max = p;
+ tmax = pts;
+ }else{
+ if (min == p && tmin == pts) {
+ // probably our tmax is wrong, causing us to always end up too early in the file
+ tmax = (target_ts + tmax) / 2;
+ if (tmax == target_ts) {
+ url_fseek(bc, max, SEEK_SET);
+ break;
+ }
+ }
+ min = p;
+ tmin = pts;
+ }
+ }
+
+ if (FFABS (pts - target_ts) * st->time_base.num < st->time_base.den){
+ ogg_restore (s, 1);
+ ogg_reset (ogg);
+ }else{
+ ogg_restore (s, 0);
+ pts = AV_NOPTS_VALUE;
+ }
+
+ av_update_cur_dts(s, st, pts);
+ return 0;
+
+#if 0
+ //later...
+ int64_t pos;
+ if (av_seek_frame_binary (s, stream_index, target_ts, flags) < 0)
+ return -1;
+ pos = url_ftell (&s->pb);
+ ogg_read_timestamp (s, stream_index, &pos, pos - 1);
+#endif
+
+}
+
+#if 0
+static int64_t
+ogg_read_timestamp (AVFormatContext * s, int stream_index, int64_t * pos_arg,
+ int64_t pos_limit)
+{
+ ogg_t *ogg = s->priv_data;
+ ByteIOContext *bc = &s->pb;
+ int64_t pos, pts;
+
+ if (*pos_arg < 0)
+ return AV_NOPTS_VALUE;
+
+ pos = *pos_arg;
+}
+#endif
+
+static int ogg_probe(AVProbeData *p)
+{
+ if (p->buf_size < 6)
+ return 0;
+ if (p->buf[0] == 'O' && p->buf[1] == 'g' &&
+ p->buf[2] == 'g' && p->buf[3] == 'S' &&
+ p->buf[4] == 0x0 && p->buf[5] <= 0x7 )
+ return AVPROBE_SCORE_MAX;
+ else
+ return 0;
+}
+
+AVInputFormat ogg_demuxer = {
+ "ogg",
+ "Ogg",
+ sizeof (ogg_t),
+ ogg_probe,
+ ogg_read_header,
+ ogg_read_packet,
+ ogg_read_close,
+ ogg_read_seek,
+// ogg_read_timestamp,
+ .extensions = "ogg",
+};
diff --git a/contrib/ffmpeg/libavformat/ogg2.h b/contrib/ffmpeg/libavformat/ogg2.h
new file mode 100644
index 000000000..6b7c6b22e
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/ogg2.h
@@ -0,0 +1,86 @@
+/**
+ Copyright (C) 2005 Michael Ahlberg, Måns Rullgård
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the "Software"), to deal in the Software without
+ restriction, including without limitation the rights to use, copy,
+ modify, merge, publish, distribute, sublicense, and/or sell copies
+ of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+**/
+
+#ifndef OGG_H
+#define OGG_H
+
+#include "avformat.h"
+
+typedef struct ogg_codec {
+ int8_t *magic;
+ uint8_t magicsize;
+ int8_t *name;
+ int (*header)(AVFormatContext *, int);
+ int (*packet)(AVFormatContext *, int);
+ uint64_t (*gptopts)(AVFormatContext *, int, uint64_t);
+} ogg_codec_t;
+
+typedef struct ogg_stream {
+ uint8_t *buf;
+ unsigned int bufsize;
+ unsigned int bufpos;
+ unsigned int pstart;
+ unsigned int psize;
+ uint32_t serial;
+ uint32_t seq;
+ uint64_t granule, lastgp;
+ int flags;
+ ogg_codec_t *codec;
+ int header;
+ int nsegs, segp;
+ uint8_t segments[255];
+ void *private;
+} ogg_stream_t;
+
+typedef struct ogg_state {
+ uint64_t pos;
+ int curidx;
+ struct ogg_state *next;
+ int nstreams;
+ ogg_stream_t streams[1];
+} ogg_state_t;
+
+typedef struct ogg {
+ ogg_stream_t *streams;
+ int nstreams;
+ int headers;
+ int curidx;
+ uint64_t size;
+ ogg_state_t *state;
+} ogg_t;
+
+#define OGG_FLAG_CONT 1
+#define OGG_FLAG_BOS 2
+#define OGG_FLAG_EOS 4
+
+extern ogg_codec_t vorbis_codec;
+extern ogg_codec_t theora_codec;
+extern ogg_codec_t flac_codec;
+extern ogg_codec_t ogm_video_codec;
+extern ogg_codec_t ogm_audio_codec;
+extern ogg_codec_t ogm_old_codec;
+
+extern int vorbis_comment(AVFormatContext *ms, uint8_t *buf, int size);
+
+#endif
diff --git a/contrib/ffmpeg/libavformat/oggparseflac.c b/contrib/ffmpeg/libavformat/oggparseflac.c
new file mode 100644
index 000000000..8960088d8
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/oggparseflac.c
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2005 Matthieu CASTET
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 <stdlib.h>
+#include "avformat.h"
+#include "bitstream.h"
+#include "ogg2.h"
+
+#define FLAC_STREAMINFO_SIZE 0x22
+
+static int
+flac_header (AVFormatContext * s, int idx)
+{
+ ogg_t *ogg = s->priv_data;
+ ogg_stream_t *os = ogg->streams + idx;
+ AVStream *st = s->streams[idx];
+ GetBitContext gb;
+ int mdt;
+
+ if (os->buf[os->pstart] == 0xff)
+ return 0;
+
+ init_get_bits(&gb, os->buf + os->pstart, os->psize*8);
+ get_bits(&gb, 1); /* metadata_last */
+ mdt = get_bits(&gb, 7);
+
+ if (mdt == 0x7f) {
+ skip_bits(&gb, 4*8); /* "FLAC" */
+ if(get_bits(&gb, 8) != 1) /* unsupported major version */
+ return -1;
+ skip_bits(&gb, 8 + 16); /* minor version + header count */
+ skip_bits(&gb, 4*8); /* "fLaC" */
+
+ /* METADATA_BLOCK_HEADER */
+ if (get_bits(&gb, 32) != FLAC_STREAMINFO_SIZE)
+ return -1;
+
+ skip_bits(&gb, 16*2+24*2);
+
+ st->codec->sample_rate = get_bits_long(&gb, 20);
+ st->codec->channels = get_bits(&gb, 3) + 1;
+
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_id = CODEC_ID_FLAC;
+
+ st->codec->extradata =
+ av_malloc(FLAC_STREAMINFO_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
+ memcpy (st->codec->extradata, os->buf + os->pstart + 5 + 4 + 4 + 4,
+ FLAC_STREAMINFO_SIZE);
+ st->codec->extradata_size = FLAC_STREAMINFO_SIZE;
+
+ st->time_base.num = 1;
+ st->time_base.den = st->codec->sample_rate;
+ } else if (mdt == 4) {
+ vorbis_comment (s, os->buf + os->pstart + 4, os->psize - 4);
+ }
+
+ return 1;
+}
+
+ogg_codec_t flac_codec = {
+ .magic = "\177FLAC",
+ .magicsize = 5,
+ .header = flac_header
+};
diff --git a/contrib/ffmpeg/libavformat/oggparseogm.c b/contrib/ffmpeg/libavformat/oggparseogm.c
new file mode 100644
index 000000000..8788e5d41
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/oggparseogm.c
@@ -0,0 +1,166 @@
+/**
+ Copyright (C) 2005 Michael Ahlberg, Måns Rullgård
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the "Software"), to deal in the Software without
+ restriction, including without limitation the rights to use, copy,
+ modify, merge, publish, distribute, sublicense, and/or sell copies
+ of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+**/
+
+#include <stdlib.h>
+#include "avformat.h"
+#include "bitstream.h"
+#include "bswap.h"
+#include "ogg2.h"
+#include "riff.h"
+
+static int
+ogm_header(AVFormatContext *s, int idx)
+{
+ ogg_t *ogg = s->priv_data;
+ ogg_stream_t *os = ogg->streams + idx;
+ AVStream *st = s->streams[idx];
+ uint8_t *p = os->buf + os->pstart;
+ uint64_t time_unit;
+ uint64_t spu;
+ uint32_t default_len;
+
+ if(!(*p & 1))
+ return 0;
+ if(*p != 1)
+ return 1;
+
+ p++;
+
+ if(*p == 'v'){
+ int tag;
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ p += 8;
+ tag = le2me_32(unaligned32(p));
+ st->codec->codec_id = codec_get_bmp_id(tag);
+ st->codec->codec_tag = tag;
+ } else {
+ int cid;
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ p += 8;
+ p[4] = 0;
+ cid = strtol(p, NULL, 16);
+ st->codec->codec_id = codec_get_wav_id(cid);
+ }
+
+ p += 4;
+ p += 4; /* useless size field */
+
+ time_unit = le2me_64(unaligned64(p));
+ p += 8;
+ spu = le2me_64(unaligned64(p));
+ p += 8;
+ default_len = le2me_32(unaligned32(p));
+ p += 4;
+
+ p += 8; /* buffersize + bits_per_sample */
+
+ if(st->codec->codec_type == CODEC_TYPE_VIDEO){
+ st->codec->width = le2me_32(unaligned32(p));
+ p += 4;
+ st->codec->height = le2me_32(unaligned32(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 = le2me_16(unaligned16(p));
+ p += 2;
+ p += 2; /* block_align */
+ st->codec->bit_rate = le2me_32(unaligned32(p)) * 8;
+ st->codec->sample_rate = spu * 10000000 / time_unit;
+ st->time_base.num = 1;
+ st->time_base.den = st->codec->sample_rate;
+ }
+
+ return 1;
+}
+
+static int
+ogm_dshow_header(AVFormatContext *s, int idx)
+{
+ ogg_t *ogg = s->priv_data;
+ ogg_stream_t *os = ogg->streams + idx;
+ AVStream *st = s->streams[idx];
+ uint8_t *p = os->buf + os->pstart;
+ uint32_t t;
+
+ if(!(*p & 1))
+ return 0;
+ if(*p != 1)
+ return 1;
+
+ t = le2me_32(unaligned32(p + 96));
+
+ if(t == 0x05589f80){
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ st->codec->codec_id = codec_get_bmp_id(le2me_32(unaligned32(p + 68)));
+ st->codec->time_base.den = 10000000;
+ st->codec->time_base.num = le2me_64(unaligned64(p + 164));
+ st->codec->width = le2me_32(unaligned32(p + 176));
+ st->codec->height = le2me_32(unaligned32(p + 180));
+ } else if(t == 0x05589f81){
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_id = codec_get_wav_id(le2me_16(unaligned16(p+124)));
+ st->codec->channels = le2me_16(unaligned16(p + 126));
+ st->codec->sample_rate = le2me_32(unaligned32(p + 128));
+ st->codec->bit_rate = le2me_32(unaligned32(p + 132)) * 8;
+ }
+
+ return 1;
+}
+
+static int
+ogm_packet(AVFormatContext *s, int idx)
+{
+ ogg_t *ogg = s->priv_data;
+ ogg_stream_t *os = ogg->streams + idx;
+ uint8_t *p = os->buf + os->pstart;
+ int lb;
+
+ lb = ((*p & 2) << 1) | ((*p >> 6) & 3);
+ os->pstart += lb + 1;
+ os->psize -= lb + 1;
+
+ return 0;
+}
+
+ogg_codec_t ogm_video_codec = {
+ .magic = "\001video",
+ .magicsize = 6,
+ .header = ogm_header,
+ .packet = ogm_packet
+};
+
+ogg_codec_t ogm_audio_codec = {
+ .magic = "\001audio",
+ .magicsize = 6,
+ .header = ogm_header,
+ .packet = ogm_packet
+};
+
+ogg_codec_t ogm_old_codec = {
+ .magic = "\001Direct Show Samples embedded in Ogg",
+ .magicsize = 35,
+ .header = ogm_dshow_header,
+ .packet = ogm_packet
+};
diff --git a/contrib/ffmpeg/libavformat/oggparsetheora.c b/contrib/ffmpeg/libavformat/oggparsetheora.c
new file mode 100644
index 000000000..9052bbbea
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/oggparsetheora.c
@@ -0,0 +1,129 @@
+/**
+ Copyright (C) 2005 Matthieu CASTET, Alex Beregszaszi
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the "Software"), to deal in the Software without
+ restriction, including without limitation the rights to use, copy,
+ modify, merge, publish, distribute, sublicense, and/or sell copies
+ of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+**/
+
+#include <stdlib.h>
+#include "avformat.h"
+#include "bitstream.h"
+#include "bswap.h"
+#include "ogg2.h"
+
+typedef struct theora_params {
+ int gpshift;
+ int gpmask;
+} theora_params_t;
+
+static int
+theora_header (AVFormatContext * s, int idx)
+{
+ ogg_t *ogg = s->priv_data;
+ ogg_stream_t *os = ogg->streams + idx;
+ AVStream *st = s->streams[idx];
+ theora_params_t *thp = os->private;
+ int cds = st->codec->extradata_size + os->psize + 2;
+ uint8_t *cdp;
+
+ if(!(os->buf[os->pstart] & 0x80))
+ return 0;
+
+ if(!thp){
+ thp = av_mallocz(sizeof(*thp));
+ os->private = thp;
+ }
+
+ if (os->buf[os->pstart] == 0x80) {
+ GetBitContext gb;
+ int version;
+
+ init_get_bits(&gb, os->buf + os->pstart, os->psize*8);
+
+ skip_bits(&gb, 7*8); /* 0x80"theora" */
+
+ version = get_bits(&gb, 8) << 16;
+ version |= get_bits(&gb, 8) << 8;
+ version |= get_bits(&gb, 8);
+
+ if (version < 0x030100)
+ {
+ av_log(s, AV_LOG_ERROR,
+ "Too old or unsupported Theora (%x)\n", version);
+ return -1;
+ }
+
+ st->codec->width = get_bits(&gb, 16) << 4;
+ st->codec->height = get_bits(&gb, 16) << 4;
+
+ if (version >= 0x030400)
+ skip_bits(&gb, 164);
+ else if (version >= 0x030200)
+ skip_bits(&gb, 64);
+ st->codec->time_base.den = get_bits(&gb, 32);
+ st->codec->time_base.num = get_bits(&gb, 32);
+ st->time_base = st->codec->time_base;
+
+ st->codec->sample_aspect_ratio.num = get_bits(&gb, 24);
+ st->codec->sample_aspect_ratio.den = get_bits(&gb, 24);
+
+ if (version >= 0x030200)
+ skip_bits(&gb, 38);
+ if (version >= 0x304000)
+ skip_bits(&gb, 2);
+
+ thp->gpshift = get_bits(&gb, 5);
+ thp->gpmask = (1 << thp->gpshift) - 1;
+
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ st->codec->codec_id = CODEC_ID_THEORA;
+
+ } else if (os->buf[os->pstart] == 0x83) {
+ vorbis_comment (s, os->buf + os->pstart + 7, os->psize - 8);
+ }
+
+ st->codec->extradata = av_realloc (st->codec->extradata, cds);
+ cdp = st->codec->extradata + st->codec->extradata_size;
+ *cdp++ = os->psize >> 8;
+ *cdp++ = os->psize & 0xff;
+ memcpy (cdp, os->buf + os->pstart, os->psize);
+ st->codec->extradata_size = cds;
+
+ return 1;
+}
+
+static uint64_t
+theora_gptopts(AVFormatContext *ctx, int idx, uint64_t gp)
+{
+ ogg_t *ogg = ctx->priv_data;
+ ogg_stream_t *os = ogg->streams + idx;
+ theora_params_t *thp = os->private;
+ uint64_t iframe = gp >> thp->gpshift;
+ uint64_t pframe = gp & thp->gpmask;
+
+ return iframe + pframe;
+}
+
+ogg_codec_t theora_codec = {
+ .magic = "\200theora",
+ .magicsize = 7,
+ .header = theora_header,
+ .gptopts = theora_gptopts
+};
diff --git a/contrib/ffmpeg/libavformat/oggparsevorbis.c b/contrib/ffmpeg/libavformat/oggparsevorbis.c
new file mode 100644
index 000000000..5de221cb4
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/oggparsevorbis.c
@@ -0,0 +1,205 @@
+/**
+ Copyright (C) 2005 Michael Ahlberg, Måns Rullgård
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the "Software"), to deal in the Software without
+ restriction, including without limitation the rights to use, copy,
+ modify, merge, publish, distribute, sublicense, and/or sell copies
+ of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+**/
+
+#include <stdlib.h>
+#include "avformat.h"
+#include "bitstream.h"
+#include "bswap.h"
+#include "ogg2.h"
+
+extern int
+vorbis_comment (AVFormatContext * as, uint8_t *buf, int size)
+{
+ char *p = buf;
+ int s, n, j;
+
+ if (size < 4)
+ return -1;
+
+ s = le2me_32 (unaligned32 (p));
+ p += 4;
+ size -= 4;
+
+ if (size < s + 4)
+ return -1;
+
+ p += s;
+ size -= s;
+
+ n = le2me_32 (unaligned32 (p));
+ p += 4;
+ size -= 4;
+
+ while (size >= 4){
+ char *t, *v;
+ int tl, vl;
+
+ s = le2me_32 (unaligned32 (p));
+ p += 4;
+ size -= 4;
+
+ if (size < s)
+ break;
+
+ t = p;
+ p += s;
+ size -= s;
+ n--;
+
+ v = memchr (t, '=', s);
+ if (!v)
+ continue;
+
+ tl = v - t;
+ vl = s - tl - 1;
+ v++;
+
+ if (tl && vl){
+ char tt[tl + 1];
+ char ct[vl + 1];
+
+ for (j = 0; j < tl; j++)
+ tt[j] = toupper (t[j]);
+ tt[tl] = 0;
+
+ memcpy (ct, v, vl);
+ ct[vl] = 0;
+
+ // took from Vorbis_I_spec
+ if (!strcmp (tt, "AUTHOR"))
+ strncpy (as->author, ct, FFMIN(sizeof (as->author), vl));
+ else if (!strcmp (tt, "TITLE"))
+ strncpy (as->title, ct, FFMIN(sizeof (as->title), vl));
+ else if (!strcmp (tt, "COPYRIGHT"))
+ strncpy (as->copyright, ct, FFMIN(sizeof (as->copyright), vl));
+ else if (!strcmp (tt, "DESCRIPTION"))
+ strncpy (as->comment, ct, FFMIN(sizeof (as->comment), vl));
+ else if (!strcmp (tt, "GENRE"))
+ strncpy (as->genre, ct, FFMIN(sizeof (as->genre), vl));
+ else if (!strcmp (tt, "TRACKNUMBER"))
+ as->track = atoi (ct);
+ //Too bored to add others for today
+ }
+ }
+
+ if (size > 0)
+ av_log (as, AV_LOG_INFO, "%i bytes of comment header remain\n", size);
+ if (n > 0)
+ av_log (as, AV_LOG_INFO,
+ "truncated comment header, %i comments not found\n", n);
+
+ return 0;
+}
+
+
+/** Parse the vorbis header
+ * Vorbis Identification header from Vorbis_I_spec.html#vorbis-spec-codec
+ * [vorbis_version] = read 32 bits as unsigned integer | Not used
+ * [audio_channels] = read 8 bit integer as unsigned | Used
+ * [audio_sample_rate] = read 32 bits as unsigned integer | Used
+ * [bitrate_maximum] = read 32 bits as signed integer | Not used yet
+ * [bitrate_nominal] = read 32 bits as signed integer | Not used yet
+ * [bitrate_minimum] = read 32 bits as signed integer | Used as bitrate
+ * [blocksize_0] = read 4 bits as unsigned integer | Not Used
+ * [blocksize_1] = read 4 bits as unsigned integer | Not Used
+ * [framing_flag] = read one bit | Not Used
+ * */
+
+typedef struct {
+ unsigned int len[3];
+ unsigned char *packet[3];
+} oggvorbis_private_t;
+
+
+static unsigned int
+fixup_vorbis_headers(AVFormatContext * as, oggvorbis_private_t *priv,
+ void **buf)
+{
+ int i,offset, len;
+ unsigned char *ptr;
+
+ len = priv->len[0] + priv->len[1] + priv->len[2];
+ ptr = *buf = av_mallocz(len + len/255 + 64);
+
+ ptr[0] = 2;
+ offset = 1;
+ offset += av_xiphlacing(&ptr[offset], priv->len[0]);
+ offset += av_xiphlacing(&ptr[offset], priv->len[1]);
+ for(i = 0; i < 3; i++) {
+ memcpy(&ptr[offset], priv->packet[i], priv->len[i]);
+ offset += priv->len[i];
+ }
+ *buf = av_realloc(*buf, offset);
+ return offset;
+}
+
+
+static int
+vorbis_header (AVFormatContext * s, int idx)
+{
+ ogg_t *ogg = s->priv_data;
+ ogg_stream_t *os = ogg->streams + idx;
+ AVStream *st = s->streams[idx];
+ oggvorbis_private_t *priv;
+
+ if (os->seq > 2)
+ return 0;
+
+ if(os->seq == 0) {
+ os->private = av_mallocz(sizeof(oggvorbis_private_t));
+ if(!os->private)
+ return 0;
+ }
+
+ 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);
+ if (os->buf[os->pstart] == 1) {
+ uint8_t *p = os->buf + os->pstart + 11; //skip up to the audio channels
+ st->codec->channels = *p++;
+ st->codec->sample_rate = le2me_32 (unaligned32 (p));
+ p += 8; //skip maximum and and nominal bitrate
+ st->codec->bit_rate = le2me_32 (unaligned32 (p)); //Minimum bitrate
+
+ st->codec->codec_type = CODEC_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) {
+ vorbis_comment (s, 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;
+}
+
+ogg_codec_t vorbis_codec = {
+ .magic = "\001vorbis",
+ .magicsize = 7,
+ .header = vorbis_header
+};
diff --git a/contrib/ffmpeg/libavformat/os_support.c b/contrib/ffmpeg/libavformat/os_support.c
new file mode 100644
index 000000000..7a4be8fa7
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/os_support.c
@@ -0,0 +1,167 @@
+/*
+ * Various utilities for ffmpeg system
+ * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
+ * copyright (c) 2002 Francois Revol
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 "avformat.h"
+#if defined(CONFIG_WINCE)
+/* Skip includes on WinCE. */
+#elif defined(__MINGW32__)
+#include <sys/types.h>
+#include <sys/timeb.h>
+#elif defined(CONFIG_OS2)
+#include <string.h>
+#include <sys/time.h>
+#else
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/time.h>
+#endif
+#include <time.h>
+
+#ifndef HAVE_SYS_POLL_H
+#if defined(__MINGW32__)
+#include <winsock2.h>
+#else
+#include <sys/select.h>
+#endif
+#endif
+
+/**
+ * gets the current time in micro seconds.
+ */
+int64_t av_gettime(void)
+{
+#if defined(CONFIG_WINCE)
+ return timeGetTime() * INT64_C(1000);
+#elif defined(__MINGW32__)
+ struct timeb tb;
+ _ftime(&tb);
+ return ((int64_t)tb.time * INT64_C(1000) + (int64_t)tb.millitm) * INT64_C(1000);
+#else
+ struct timeval tv;
+ gettimeofday(&tv,NULL);
+ return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
+#endif
+}
+
+#if !defined(CONFIG_WINCE) && !defined(HAVE_LOCALTIME_R)
+struct tm *localtime_r(const time_t *t, struct tm *tp)
+{
+ struct tm *l;
+
+ l = localtime(t);
+ if (!l)
+ return 0;
+ *tp = *l;
+ return tp;
+}
+#endif /* !defined(CONFIG_WINCE) && !defined(HAVE_LOCALTIME_R) */
+
+#if !defined(HAVE_INET_ATON) && defined(CONFIG_NETWORK)
+#include <stdlib.h>
+#include <strings.h>
+#include "network.h"
+
+int inet_aton (const char * str, struct in_addr * add)
+{
+ const char * pch = str;
+ unsigned int add1 = 0, add2 = 0, add3 = 0, add4 = 0;
+
+ add1 = atoi(pch);
+ pch = strpbrk(pch,".");
+ if (pch == 0 || ++pch == 0) goto done;
+ add2 = atoi(pch);
+ pch = strpbrk(pch,".");
+ if (pch == 0 || ++pch == 0) goto done;
+ add3 = atoi(pch);
+ pch = strpbrk(pch,".");
+ if (pch == 0 || ++pch == 0) goto done;
+ add4 = atoi(pch);
+
+done:
+ add->s_addr=(add4<<24)+(add3<<16)+(add2<<8)+add1;
+
+ return 1;
+}
+#endif /* !defined(HAVE_INET_ATON) && defined(CONFIG_NETWORK) */
+
+#ifdef CONFIG_FFSERVER
+#ifndef HAVE_SYS_POLL_H
+int poll(struct pollfd *fds, nfds_t numfds, int timeout)
+{
+ fd_set read_set;
+ fd_set write_set;
+ fd_set exception_set;
+ nfds_t i;
+ int n;
+ int rc;
+
+ FD_ZERO(&read_set);
+ FD_ZERO(&write_set);
+ FD_ZERO(&exception_set);
+
+ n = -1;
+ for(i = 0; i < numfds; i++) {
+ if (fds[i].fd < 0)
+ continue;
+ if (fds[i].fd >= FD_SETSIZE) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (fds[i].events & POLLIN) FD_SET(fds[i].fd, &read_set);
+ if (fds[i].events & POLLOUT) FD_SET(fds[i].fd, &write_set);
+ if (fds[i].events & POLLERR) FD_SET(fds[i].fd, &exception_set);
+
+ if (fds[i].fd > n)
+ n = fds[i].fd;
+ };
+
+ if (n == -1)
+ /* Hey!? Nothing to poll, in fact!!! */
+ return 0;
+
+ if (timeout < 0)
+ rc = select(n+1, &read_set, &write_set, &exception_set, NULL);
+ else {
+ struct timeval tv;
+
+ tv.tv_sec = timeout / 1000;
+ tv.tv_usec = 1000 * (timeout % 1000);
+ rc = select(n+1, &read_set, &write_set, &exception_set, &tv);
+ };
+
+ if (rc < 0)
+ return rc;
+
+ for(i = 0; i < (nfds_t) n; i++) {
+ fds[i].revents = 0;
+
+ if (FD_ISSET(fds[i].fd, &read_set)) fds[i].revents |= POLLIN;
+ if (FD_ISSET(fds[i].fd, &write_set)) fds[i].revents |= POLLOUT;
+ if (FD_ISSET(fds[i].fd, &exception_set)) fds[i].revents |= POLLERR;
+ };
+
+ return rc;
+}
+#endif /* HAVE_SYS_POLL_H */
+#endif /* CONFIG_FFSERVER */
+
diff --git a/contrib/ffmpeg/libavformat/os_support.h b/contrib/ffmpeg/libavformat/os_support.h
new file mode 100644
index 000000000..424d6dabd
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/os_support.h
@@ -0,0 +1,111 @@
+/*
+ * various utilities for ffmpeg system
+ * copyright (c) 2000, 2001, 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
+ */
+
+#ifndef _OS_SUPPORT_H
+#define _OS_SUPPORT_H
+
+/**
+ * @file os_support.h
+ * miscellaneous OS support macros and functions.
+ *
+ * - socklen_t typedef (BeOS, Innotek libc)
+ * - usleep() (Win32, BeOS, OS/2)
+ * - lseek() (Win32)
+ * - floatf() (OS/2)
+ * - strcasecmp() (OS/2)
+ * - closesocket()
+ * - poll() (BeOS, MinGW)
+ */
+
+#if defined(__BEOS__) || defined(__INNOTEK_LIBC__)
+typedef int socklen_t;
+#endif
+
+#ifdef __MINGW32__
+__declspec(dllimport) void __stdcall Sleep(unsigned long dwMilliseconds);
+// # include <windows.h>
+# define usleep(t) Sleep((t) / 1000)
+# include <fcntl.h>
+# define lseek(f,p,w) _lseeki64((f), (p), (w))
+# define HAVE_CLOSESOCKET 1
+#endif
+
+#ifdef __BEOS__
+# include <sys/socket.h>
+# include <netinet/in.h>
+ /* not net_server ? */
+# if IPPROTO_TCP != 6
+# define HAVE_CLOSESOCKET 1
+# endif
+# include <BeBuild.h>
+ /* R5 didn't have usleep, fake it. Haiku and Zeta has it now. */
+# if B_BEOS_VERSION <= B_BEOS_VERSION_5
+# include <OS.h>
+ /* doesn't set errno but that's enough */
+# define usleep(t) snooze((bigtime_t)(t))
+# endif
+# ifndef SA_RESTART
+# warning SA_RESTART not implemented; ffserver might misbehave.
+# define SA_RESTART 0
+# endif
+#endif
+
+#if defined(CONFIG_OS2)
+#include <stdlib.h>
+static inline int usleep(unsigned int t) { return _sleep2(t / 1000); }
+static inline int strcasecmp(const char* s1, const char* s2) { return stricmp(s1,s2); }
+#endif
+
+/* most of the time closing a socket is just closing an fd */
+#if HAVE_CLOSESOCKET != 1
+#define closesocket close
+#endif
+
+#ifdef CONFIG_FFSERVER
+#ifndef HAVE_SYS_POLL_H
+typedef unsigned long nfds_t;
+
+struct pollfd {
+ int fd;
+ short events; /* events to look for */
+ short revents; /* events that occured */
+};
+
+/* events & revents */
+#define POLLIN 0x0001 /* any readable data available */
+#define POLLOUT 0x0002 /* file descriptor is writeable */
+#define POLLRDNORM POLLIN
+#define POLLWRNORM POLLOUT
+#define POLLRDBAND 0x0008 /* priority readable data */
+#define POLLWRBAND 0x0010 /* priority data can be written */
+#define POLLPRI 0x0020 /* high priority readable data */
+
+/* revents only */
+#define POLLERR 0x0004 /* errors pending */
+#define POLLHUP 0x0080 /* disconnected */
+#define POLLNVAL 0x1000 /* invalid file descriptor */
+
+
+extern int poll(struct pollfd *fds, nfds_t numfds, int timeout);
+#endif /* HAVE_SYS_POLL_H */
+#endif /* CONFIG_FFSERVER */
+
+#endif /* _OS_SUPPORT_H */
diff --git a/contrib/ffmpeg/libavformat/psxstr.c b/contrib/ffmpeg/libavformat/psxstr.c
new file mode 100644
index 000000000..2f1a3dc73
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/psxstr.c
@@ -0,0 +1,364 @@
+/*
+ * Sony Playstation (PSX) STR File Demuxer
+ * Copyright (c) 2003 The ffmpeg Project
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file psxstr.c
+ * PSX STR file demuxer
+ * by Mike Melanson (melanson@pcisys.net)
+ * This module handles streams that have been ripped from Sony Playstation
+ * CD games. This demuxer can handle either raw STR files (which are just
+ * concatenations of raw compact disc sectors) or STR files with 0x2C-byte
+ * RIFF headers, followed by CD sectors.
+ */
+
+#include "avformat.h"
+
+//#define PRINTSTUFF
+
+#define RIFF_TAG MKTAG('R', 'I', 'F', 'F')
+#define CDXA_TAG MKTAG('C', 'D', 'X', 'A')
+
+#define RAW_CD_SECTOR_SIZE 2352
+#define RAW_CD_SECTOR_DATA_SIZE 2304
+#define VIDEO_DATA_CHUNK_SIZE 0x7E0
+#define VIDEO_DATA_HEADER_SIZE 0x38
+#define RIFF_HEADER_SIZE 0x2C
+
+#define CDXA_TYPE_MASK 0x0E
+#define CDXA_TYPE_DATA 0x08
+#define CDXA_TYPE_AUDIO 0x04
+#define CDXA_TYPE_VIDEO 0x02
+
+#define STR_MAGIC (0x80010160)
+
+typedef struct StrChannel {
+
+ int type;
+#define STR_AUDIO 0
+#define STR_VIDEO 1
+
+ /* video parameters */
+ int width;
+ int height;
+ int video_stream_index;
+
+ /* audio parameters */
+ int sample_rate;
+ int channels;
+ int bits;
+ int audio_stream_index;
+} StrChannel;
+
+typedef struct StrDemuxContext {
+
+ /* a STR file can contain up to 32 channels of data */
+ StrChannel channels[32];
+
+ /* only decode the first audio and video channels encountered */
+ int video_channel;
+ int audio_channel;
+
+ int64_t pts;
+
+ unsigned char *video_chunk;
+ AVPacket tmp_pkt;
+} StrDemuxContext;
+
+static const char sync_header[12] = {0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00};
+
+static int str_probe(AVProbeData *p)
+{
+ int start;
+
+ /* need at least 0x38 bytes to validate */
+ if (p->buf_size < 0x38)
+ return 0;
+
+ if ((AV_RL32(&p->buf[0]) == RIFF_TAG) &&
+ (AV_RL32(&p->buf[8]) == CDXA_TAG)) {
+
+ /* RIFF header seen; skip 0x2C bytes */
+ start = RIFF_HEADER_SIZE;
+ } else
+ start = 0;
+
+ /* look for CD sync header (00, 0xFF x 10, 00) */
+ if (memcmp(p->buf+start,sync_header,sizeof(sync_header)))
+ return 0;
+
+ /* MPEG files (like those ripped from VCDs) can also look like this;
+ * only return half certainty */
+ return 50;
+}
+
+#if 0
+static void dump(unsigned char *buf,size_t len)
+{
+ int i;
+ for(i=0;i<len;i++) {
+ if ((i&15)==0) av_log(NULL, AV_LOG_DEBUG, "%04x ",i);
+ av_log(NULL, AV_LOG_DEBUG, "%02x ",buf[i]);
+ if ((i&15)==15) av_log(NULL, AV_LOG_DEBUG, "\n");
+ }
+ av_log(NULL, AV_LOG_DEBUG, "\n");
+}
+#endif
+
+static int str_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ ByteIOContext *pb = &s->pb;
+ StrDemuxContext *str = (StrDemuxContext *)s->priv_data;
+ AVStream *st;
+ unsigned char sector[RAW_CD_SECTOR_SIZE];
+ int start;
+ int i;
+ int channel;
+
+ /* initialize context members */
+ str->pts = 0;
+ str->audio_channel = -1; /* assume to audio or video */
+ str->video_channel = -1;
+ str->video_chunk = NULL;
+
+
+ /* skip over any RIFF header */
+ if (get_buffer(pb, sector, RIFF_HEADER_SIZE) != RIFF_HEADER_SIZE)
+ return AVERROR_IO;
+ if (AV_RL32(&sector[0]) == RIFF_TAG)
+ start = RIFF_HEADER_SIZE;
+ else
+ start = 0;
+
+ url_fseek(pb, start, SEEK_SET);
+
+ /* check through the first 32 sectors for individual channels */
+ for (i = 0; i < 32; i++) {
+ if (get_buffer(pb, sector, RAW_CD_SECTOR_SIZE) != RAW_CD_SECTOR_SIZE)
+ return AVERROR_IO;
+
+//printf("%02x %02x %02x %02x\n",sector[0x10],sector[0x11],sector[0x12],sector[0x13]);
+
+ channel = sector[0x11];
+ if (channel >= 32)
+ return AVERROR_INVALIDDATA;
+
+ switch (sector[0x12] & CDXA_TYPE_MASK) {
+
+ case CDXA_TYPE_DATA:
+ case CDXA_TYPE_VIDEO:
+ /* check if this channel gets to be the dominant video channel */
+ if (str->video_channel == -1) {
+ /* qualify the magic number */
+ if (AV_RL32(&sector[0x18]) != STR_MAGIC)
+ break;
+ str->video_channel = channel;
+ str->channels[channel].type = STR_VIDEO;
+ str->channels[channel].width = AV_RL16(&sector[0x28]);
+ str->channels[channel].height = AV_RL16(&sector[0x2A]);
+
+ /* allocate a new AVStream */
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+ av_set_pts_info(st, 64, 1, 15);
+
+ str->channels[channel].video_stream_index = st->index;
+
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ st->codec->codec_id = CODEC_ID_MDEC;
+ st->codec->codec_tag = 0; /* no fourcc */
+ st->codec->width = str->channels[channel].width;
+ st->codec->height = str->channels[channel].height;
+ }
+ break;
+
+ case CDXA_TYPE_AUDIO:
+ /* check if this channel gets to be the dominant audio channel */
+ if (str->audio_channel == -1) {
+ int fmt;
+ str->audio_channel = channel;
+ str->channels[channel].type = STR_AUDIO;
+ str->channels[channel].channels =
+ (sector[0x13] & 0x01) ? 2 : 1;
+ str->channels[channel].sample_rate =
+ (sector[0x13] & 0x04) ? 18900 : 37800;
+ str->channels[channel].bits =
+ (sector[0x13] & 0x10) ? 8 : 4;
+
+ /* allocate a new AVStream */
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+ av_set_pts_info(st, 64, 128, str->channels[channel].sample_rate);
+
+ str->channels[channel].audio_stream_index = st->index;
+
+ fmt = sector[0x13];
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_id = CODEC_ID_ADPCM_XA;
+ st->codec->codec_tag = 0; /* no fourcc */
+ st->codec->channels = (fmt&1)?2:1;
+ st->codec->sample_rate = (fmt&4)?18900:37800;
+ // st->codec->bit_rate = 0; //FIXME;
+ st->codec->block_align = 128;
+ }
+ break;
+
+ default:
+ /* ignore */
+ break;
+ }
+ }
+
+if (str->video_channel != -1)
+ av_log (s, AV_LOG_DEBUG, " video channel = %d, %d x %d %d\n", str->video_channel,
+ str->channels[str->video_channel].width,
+ str->channels[str->video_channel].height,str->channels[str->video_channel].video_stream_index);
+if (str->audio_channel != -1)
+ av_log (s, AV_LOG_DEBUG, " audio channel = %d, %d Hz, %d channels, %d bits/sample %d\n",
+ str->audio_channel,
+ str->channels[str->audio_channel].sample_rate,
+ str->channels[str->audio_channel].channels,
+ str->channels[str->audio_channel].bits,str->channels[str->audio_channel].audio_stream_index);
+
+ /* back to the start */
+ url_fseek(pb, start, SEEK_SET);
+
+ return 0;
+}
+
+static int str_read_packet(AVFormatContext *s,
+ AVPacket *ret_pkt)
+{
+ ByteIOContext *pb = &s->pb;
+ StrDemuxContext *str = (StrDemuxContext *)s->priv_data;
+ unsigned char sector[RAW_CD_SECTOR_SIZE];
+ int channel;
+ int packet_read = 0;
+ int ret = 0;
+ AVPacket *pkt;
+
+ while (!packet_read) {
+
+ if (get_buffer(pb, sector, RAW_CD_SECTOR_SIZE) != RAW_CD_SECTOR_SIZE)
+ return AVERROR_IO;
+
+ channel = sector[0x11];
+ if (channel >= 32)
+ return AVERROR_INVALIDDATA;
+
+ switch (sector[0x12] & CDXA_TYPE_MASK) {
+
+ case CDXA_TYPE_DATA:
+ case CDXA_TYPE_VIDEO:
+ /* check if this the video channel we care about */
+ if (channel == str->video_channel) {
+
+ int current_sector = AV_RL16(&sector[0x1C]);
+ int sector_count = AV_RL16(&sector[0x1E]);
+ int frame_size = AV_RL32(&sector[0x24]);
+ int bytes_to_copy;
+// printf("%d %d %d\n",current_sector,sector_count,frame_size);
+ /* if this is the first sector of the frame, allocate a pkt */
+ pkt = &str->tmp_pkt;
+ if (current_sector == 0) {
+ if (av_new_packet(pkt, frame_size))
+ return AVERROR_IO;
+
+ pkt->pos= url_ftell(pb) - RAW_CD_SECTOR_SIZE;
+ pkt->stream_index =
+ str->channels[channel].video_stream_index;
+ // pkt->pts = str->pts;
+
+ /* if there is no audio, adjust the pts after every video
+ * frame; assume 15 fps */
+ if (str->audio_channel != -1)
+ str->pts += (90000 / 15);
+ }
+
+ /* load all the constituent chunks in the video packet */
+ bytes_to_copy = frame_size - current_sector*VIDEO_DATA_CHUNK_SIZE;
+ if (bytes_to_copy>0) {
+ if (bytes_to_copy>VIDEO_DATA_CHUNK_SIZE) bytes_to_copy=VIDEO_DATA_CHUNK_SIZE;
+ memcpy(pkt->data + current_sector*VIDEO_DATA_CHUNK_SIZE,
+ sector + VIDEO_DATA_HEADER_SIZE, bytes_to_copy);
+ }
+ if (current_sector == sector_count-1) {
+ *ret_pkt = *pkt;
+ return 0;
+ }
+
+ }
+ break;
+
+ case CDXA_TYPE_AUDIO:
+#ifdef PRINTSTUFF
+printf (" dropping audio sector\n");
+#endif
+#if 1
+ /* check if this the video channel we care about */
+ if (channel == str->audio_channel) {
+ pkt = ret_pkt;
+ if (av_new_packet(pkt, 2304))
+ return AVERROR_IO;
+ memcpy(pkt->data,sector+24,2304);
+
+ pkt->stream_index =
+ str->channels[channel].audio_stream_index;
+ //pkt->pts = str->pts;
+ return 0;
+ }
+#endif
+ break;
+ default:
+ /* drop the sector and move on */
+#ifdef PRINTSTUFF
+printf (" dropping other sector\n");
+#endif
+ break;
+ }
+
+ if (url_feof(pb))
+ return AVERROR_IO;
+ }
+
+ return ret;
+}
+
+static int str_read_close(AVFormatContext *s)
+{
+ StrDemuxContext *str = (StrDemuxContext *)s->priv_data;
+
+ av_free(str->video_chunk);
+
+ return 0;
+}
+
+AVInputFormat str_demuxer = {
+ "psxstr",
+ "Sony Playstation STR format",
+ sizeof(StrDemuxContext),
+ str_probe,
+ str_read_header,
+ str_read_packet,
+ str_read_close,
+};
diff --git a/contrib/ffmpeg/libavformat/qtpalette.h b/contrib/ffmpeg/libavformat/qtpalette.h
new file mode 100644
index 000000000..183600fde
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/qtpalette.h
@@ -0,0 +1,311 @@
+/*
+ * Default Palettes for Quicktime Files
+ * Automatically generated from a utility derived from XAnim:
+ * http://xanim.va.pubnix.com/home.html
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 QTPALETTE_H
+#define QTPALETTE_H
+
+unsigned char ff_qt_default_palette_4[4 * 4] = {
+ 0x93, 0x65, 0x5E, 0x00,
+ 0xFF, 0xFF, 0xFF, 0x00,
+ 0xDF, 0xD0, 0xAB, 0x00,
+ 0x00, 0x00, 0x00, 0x00
+};
+
+unsigned char ff_qt_default_palette_16[16 * 4] = {
+ 0xFF, 0xFB, 0xFF, 0x00,
+ 0xEF, 0xD9, 0xBB, 0x00,
+ 0xE8, 0xC9, 0xB1, 0x00,
+ 0x93, 0x65, 0x5E, 0x00,
+ 0xFC, 0xDE, 0xE8, 0x00,
+ 0x9D, 0x88, 0x91, 0x00,
+ 0xFF, 0xFF, 0xFF, 0x00,
+ 0xFF, 0xFF, 0xFF, 0x00,
+ 0xFF, 0xFF, 0xFF, 0x00,
+ 0x47, 0x48, 0x37, 0x00,
+ 0x7A, 0x5E, 0x55, 0x00,
+ 0xDF, 0xD0, 0xAB, 0x00,
+ 0xFF, 0xFB, 0xF9, 0x00,
+ 0xE8, 0xCA, 0xC5, 0x00,
+ 0x8A, 0x7C, 0x77, 0x00,
+ 0x00, 0x00, 0x00, 0x00
+};
+
+unsigned char ff_qt_default_palette_256[256 * 4] = {
+ /* 0, 0x00 */ 0xFF, 0xFF, 0xFF, 0x00,
+ /* 1, 0x01 */ 0xFF, 0xFF, 0xCC, 0x00,
+ /* 2, 0x02 */ 0xFF, 0xFF, 0x99, 0x00,
+ /* 3, 0x03 */ 0xFF, 0xFF, 0x66, 0x00,
+ /* 4, 0x04 */ 0xFF, 0xFF, 0x33, 0x00,
+ /* 5, 0x05 */ 0xFF, 0xFF, 0x00, 0x00,
+ /* 6, 0x06 */ 0xFF, 0xCC, 0xFF, 0x00,
+ /* 7, 0x07 */ 0xFF, 0xCC, 0xCC, 0x00,
+ /* 8, 0x08 */ 0xFF, 0xCC, 0x99, 0x00,
+ /* 9, 0x09 */ 0xFF, 0xCC, 0x66, 0x00,
+ /* 10, 0x0A */ 0xFF, 0xCC, 0x33, 0x00,
+ /* 11, 0x0B */ 0xFF, 0xCC, 0x00, 0x00,
+ /* 12, 0x0C */ 0xFF, 0x99, 0xFF, 0x00,
+ /* 13, 0x0D */ 0xFF, 0x99, 0xCC, 0x00,
+ /* 14, 0x0E */ 0xFF, 0x99, 0x99, 0x00,
+ /* 15, 0x0F */ 0xFF, 0x99, 0x66, 0x00,
+ /* 16, 0x10 */ 0xFF, 0x99, 0x33, 0x00,
+ /* 17, 0x11 */ 0xFF, 0x99, 0x00, 0x00,
+ /* 18, 0x12 */ 0xFF, 0x66, 0xFF, 0x00,
+ /* 19, 0x13 */ 0xFF, 0x66, 0xCC, 0x00,
+ /* 20, 0x14 */ 0xFF, 0x66, 0x99, 0x00,
+ /* 21, 0x15 */ 0xFF, 0x66, 0x66, 0x00,
+ /* 22, 0x16 */ 0xFF, 0x66, 0x33, 0x00,
+ /* 23, 0x17 */ 0xFF, 0x66, 0x00, 0x00,
+ /* 24, 0x18 */ 0xFF, 0x33, 0xFF, 0x00,
+ /* 25, 0x19 */ 0xFF, 0x33, 0xCC, 0x00,
+ /* 26, 0x1A */ 0xFF, 0x33, 0x99, 0x00,
+ /* 27, 0x1B */ 0xFF, 0x33, 0x66, 0x00,
+ /* 28, 0x1C */ 0xFF, 0x33, 0x33, 0x00,
+ /* 29, 0x1D */ 0xFF, 0x33, 0x00, 0x00,
+ /* 30, 0x1E */ 0xFF, 0x00, 0xFF, 0x00,
+ /* 31, 0x1F */ 0xFF, 0x00, 0xCC, 0x00,
+ /* 32, 0x20 */ 0xFF, 0x00, 0x99, 0x00,
+ /* 33, 0x21 */ 0xFF, 0x00, 0x66, 0x00,
+ /* 34, 0x22 */ 0xFF, 0x00, 0x33, 0x00,
+ /* 35, 0x23 */ 0xFF, 0x00, 0x00, 0x00,
+ /* 36, 0x24 */ 0xCC, 0xFF, 0xFF, 0x00,
+ /* 37, 0x25 */ 0xCC, 0xFF, 0xCC, 0x00,
+ /* 38, 0x26 */ 0xCC, 0xFF, 0x99, 0x00,
+ /* 39, 0x27 */ 0xCC, 0xFF, 0x66, 0x00,
+ /* 40, 0x28 */ 0xCC, 0xFF, 0x33, 0x00,
+ /* 41, 0x29 */ 0xCC, 0xFF, 0x00, 0x00,
+ /* 42, 0x2A */ 0xCC, 0xCC, 0xFF, 0x00,
+ /* 43, 0x2B */ 0xCC, 0xCC, 0xCC, 0x00,
+ /* 44, 0x2C */ 0xCC, 0xCC, 0x99, 0x00,
+ /* 45, 0x2D */ 0xCC, 0xCC, 0x66, 0x00,
+ /* 46, 0x2E */ 0xCC, 0xCC, 0x33, 0x00,
+ /* 47, 0x2F */ 0xCC, 0xCC, 0x00, 0x00,
+ /* 48, 0x30 */ 0xCC, 0x99, 0xFF, 0x00,
+ /* 49, 0x31 */ 0xCC, 0x99, 0xCC, 0x00,
+ /* 50, 0x32 */ 0xCC, 0x99, 0x99, 0x00,
+ /* 51, 0x33 */ 0xCC, 0x99, 0x66, 0x00,
+ /* 52, 0x34 */ 0xCC, 0x99, 0x33, 0x00,
+ /* 53, 0x35 */ 0xCC, 0x99, 0x00, 0x00,
+ /* 54, 0x36 */ 0xCC, 0x66, 0xFF, 0x00,
+ /* 55, 0x37 */ 0xCC, 0x66, 0xCC, 0x00,
+ /* 56, 0x38 */ 0xCC, 0x66, 0x99, 0x00,
+ /* 57, 0x39 */ 0xCC, 0x66, 0x66, 0x00,
+ /* 58, 0x3A */ 0xCC, 0x66, 0x33, 0x00,
+ /* 59, 0x3B */ 0xCC, 0x66, 0x00, 0x00,
+ /* 60, 0x3C */ 0xCC, 0x33, 0xFF, 0x00,
+ /* 61, 0x3D */ 0xCC, 0x33, 0xCC, 0x00,
+ /* 62, 0x3E */ 0xCC, 0x33, 0x99, 0x00,
+ /* 63, 0x3F */ 0xCC, 0x33, 0x66, 0x00,
+ /* 64, 0x40 */ 0xCC, 0x33, 0x33, 0x00,
+ /* 65, 0x41 */ 0xCC, 0x33, 0x00, 0x00,
+ /* 66, 0x42 */ 0xCC, 0x00, 0xFF, 0x00,
+ /* 67, 0x43 */ 0xCC, 0x00, 0xCC, 0x00,
+ /* 68, 0x44 */ 0xCC, 0x00, 0x99, 0x00,
+ /* 69, 0x45 */ 0xCC, 0x00, 0x66, 0x00,
+ /* 70, 0x46 */ 0xCC, 0x00, 0x33, 0x00,
+ /* 71, 0x47 */ 0xCC, 0x00, 0x00, 0x00,
+ /* 72, 0x48 */ 0x99, 0xFF, 0xFF, 0x00,
+ /* 73, 0x49 */ 0x99, 0xFF, 0xCC, 0x00,
+ /* 74, 0x4A */ 0x99, 0xFF, 0x99, 0x00,
+ /* 75, 0x4B */ 0x99, 0xFF, 0x66, 0x00,
+ /* 76, 0x4C */ 0x99, 0xFF, 0x33, 0x00,
+ /* 77, 0x4D */ 0x99, 0xFF, 0x00, 0x00,
+ /* 78, 0x4E */ 0x99, 0xCC, 0xFF, 0x00,
+ /* 79, 0x4F */ 0x99, 0xCC, 0xCC, 0x00,
+ /* 80, 0x50 */ 0x99, 0xCC, 0x99, 0x00,
+ /* 81, 0x51 */ 0x99, 0xCC, 0x66, 0x00,
+ /* 82, 0x52 */ 0x99, 0xCC, 0x33, 0x00,
+ /* 83, 0x53 */ 0x99, 0xCC, 0x00, 0x00,
+ /* 84, 0x54 */ 0x99, 0x99, 0xFF, 0x00,
+ /* 85, 0x55 */ 0x99, 0x99, 0xCC, 0x00,
+ /* 86, 0x56 */ 0x99, 0x99, 0x99, 0x00,
+ /* 87, 0x57 */ 0x99, 0x99, 0x66, 0x00,
+ /* 88, 0x58 */ 0x99, 0x99, 0x33, 0x00,
+ /* 89, 0x59 */ 0x99, 0x99, 0x00, 0x00,
+ /* 90, 0x5A */ 0x99, 0x66, 0xFF, 0x00,
+ /* 91, 0x5B */ 0x99, 0x66, 0xCC, 0x00,
+ /* 92, 0x5C */ 0x99, 0x66, 0x99, 0x00,
+ /* 93, 0x5D */ 0x99, 0x66, 0x66, 0x00,
+ /* 94, 0x5E */ 0x99, 0x66, 0x33, 0x00,
+ /* 95, 0x5F */ 0x99, 0x66, 0x00, 0x00,
+ /* 96, 0x60 */ 0x99, 0x33, 0xFF, 0x00,
+ /* 97, 0x61 */ 0x99, 0x33, 0xCC, 0x00,
+ /* 98, 0x62 */ 0x99, 0x33, 0x99, 0x00,
+ /* 99, 0x63 */ 0x99, 0x33, 0x66, 0x00,
+ /* 100, 0x64 */ 0x99, 0x33, 0x33, 0x00,
+ /* 101, 0x65 */ 0x99, 0x33, 0x00, 0x00,
+ /* 102, 0x66 */ 0x99, 0x00, 0xFF, 0x00,
+ /* 103, 0x67 */ 0x99, 0x00, 0xCC, 0x00,
+ /* 104, 0x68 */ 0x99, 0x00, 0x99, 0x00,
+ /* 105, 0x69 */ 0x99, 0x00, 0x66, 0x00,
+ /* 106, 0x6A */ 0x99, 0x00, 0x33, 0x00,
+ /* 107, 0x6B */ 0x99, 0x00, 0x00, 0x00,
+ /* 108, 0x6C */ 0x66, 0xFF, 0xFF, 0x00,
+ /* 109, 0x6D */ 0x66, 0xFF, 0xCC, 0x00,
+ /* 110, 0x6E */ 0x66, 0xFF, 0x99, 0x00,
+ /* 111, 0x6F */ 0x66, 0xFF, 0x66, 0x00,
+ /* 112, 0x70 */ 0x66, 0xFF, 0x33, 0x00,
+ /* 113, 0x71 */ 0x66, 0xFF, 0x00, 0x00,
+ /* 114, 0x72 */ 0x66, 0xCC, 0xFF, 0x00,
+ /* 115, 0x73 */ 0x66, 0xCC, 0xCC, 0x00,
+ /* 116, 0x74 */ 0x66, 0xCC, 0x99, 0x00,
+ /* 117, 0x75 */ 0x66, 0xCC, 0x66, 0x00,
+ /* 118, 0x76 */ 0x66, 0xCC, 0x33, 0x00,
+ /* 119, 0x77 */ 0x66, 0xCC, 0x00, 0x00,
+ /* 120, 0x78 */ 0x66, 0x99, 0xFF, 0x00,
+ /* 121, 0x79 */ 0x66, 0x99, 0xCC, 0x00,
+ /* 122, 0x7A */ 0x66, 0x99, 0x99, 0x00,
+ /* 123, 0x7B */ 0x66, 0x99, 0x66, 0x00,
+ /* 124, 0x7C */ 0x66, 0x99, 0x33, 0x00,
+ /* 125, 0x7D */ 0x66, 0x99, 0x00, 0x00,
+ /* 126, 0x7E */ 0x66, 0x66, 0xFF, 0x00,
+ /* 127, 0x7F */ 0x66, 0x66, 0xCC, 0x00,
+ /* 128, 0x80 */ 0x66, 0x66, 0x99, 0x00,
+ /* 129, 0x81 */ 0x66, 0x66, 0x66, 0x00,
+ /* 130, 0x82 */ 0x66, 0x66, 0x33, 0x00,
+ /* 131, 0x83 */ 0x66, 0x66, 0x00, 0x00,
+ /* 132, 0x84 */ 0x66, 0x33, 0xFF, 0x00,
+ /* 133, 0x85 */ 0x66, 0x33, 0xCC, 0x00,
+ /* 134, 0x86 */ 0x66, 0x33, 0x99, 0x00,
+ /* 135, 0x87 */ 0x66, 0x33, 0x66, 0x00,
+ /* 136, 0x88 */ 0x66, 0x33, 0x33, 0x00,
+ /* 137, 0x89 */ 0x66, 0x33, 0x00, 0x00,
+ /* 138, 0x8A */ 0x66, 0x00, 0xFF, 0x00,
+ /* 139, 0x8B */ 0x66, 0x00, 0xCC, 0x00,
+ /* 140, 0x8C */ 0x66, 0x00, 0x99, 0x00,
+ /* 141, 0x8D */ 0x66, 0x00, 0x66, 0x00,
+ /* 142, 0x8E */ 0x66, 0x00, 0x33, 0x00,
+ /* 143, 0x8F */ 0x66, 0x00, 0x00, 0x00,
+ /* 144, 0x90 */ 0x33, 0xFF, 0xFF, 0x00,
+ /* 145, 0x91 */ 0x33, 0xFF, 0xCC, 0x00,
+ /* 146, 0x92 */ 0x33, 0xFF, 0x99, 0x00,
+ /* 147, 0x93 */ 0x33, 0xFF, 0x66, 0x00,
+ /* 148, 0x94 */ 0x33, 0xFF, 0x33, 0x00,
+ /* 149, 0x95 */ 0x33, 0xFF, 0x00, 0x00,
+ /* 150, 0x96 */ 0x33, 0xCC, 0xFF, 0x00,
+ /* 151, 0x97 */ 0x33, 0xCC, 0xCC, 0x00,
+ /* 152, 0x98 */ 0x33, 0xCC, 0x99, 0x00,
+ /* 153, 0x99 */ 0x33, 0xCC, 0x66, 0x00,
+ /* 154, 0x9A */ 0x33, 0xCC, 0x33, 0x00,
+ /* 155, 0x9B */ 0x33, 0xCC, 0x00, 0x00,
+ /* 156, 0x9C */ 0x33, 0x99, 0xFF, 0x00,
+ /* 157, 0x9D */ 0x33, 0x99, 0xCC, 0x00,
+ /* 158, 0x9E */ 0x33, 0x99, 0x99, 0x00,
+ /* 159, 0x9F */ 0x33, 0x99, 0x66, 0x00,
+ /* 160, 0xA0 */ 0x33, 0x99, 0x33, 0x00,
+ /* 161, 0xA1 */ 0x33, 0x99, 0x00, 0x00,
+ /* 162, 0xA2 */ 0x33, 0x66, 0xFF, 0x00,
+ /* 163, 0xA3 */ 0x33, 0x66, 0xCC, 0x00,
+ /* 164, 0xA4 */ 0x33, 0x66, 0x99, 0x00,
+ /* 165, 0xA5 */ 0x33, 0x66, 0x66, 0x00,
+ /* 166, 0xA6 */ 0x33, 0x66, 0x33, 0x00,
+ /* 167, 0xA7 */ 0x33, 0x66, 0x00, 0x00,
+ /* 168, 0xA8 */ 0x33, 0x33, 0xFF, 0x00,
+ /* 169, 0xA9 */ 0x33, 0x33, 0xCC, 0x00,
+ /* 170, 0xAA */ 0x33, 0x33, 0x99, 0x00,
+ /* 171, 0xAB */ 0x33, 0x33, 0x66, 0x00,
+ /* 172, 0xAC */ 0x33, 0x33, 0x33, 0x00,
+ /* 173, 0xAD */ 0x33, 0x33, 0x00, 0x00,
+ /* 174, 0xAE */ 0x33, 0x00, 0xFF, 0x00,
+ /* 175, 0xAF */ 0x33, 0x00, 0xCC, 0x00,
+ /* 176, 0xB0 */ 0x33, 0x00, 0x99, 0x00,
+ /* 177, 0xB1 */ 0x33, 0x00, 0x66, 0x00,
+ /* 178, 0xB2 */ 0x33, 0x00, 0x33, 0x00,
+ /* 179, 0xB3 */ 0x33, 0x00, 0x00, 0x00,
+ /* 180, 0xB4 */ 0x00, 0xFF, 0xFF, 0x00,
+ /* 181, 0xB5 */ 0x00, 0xFF, 0xCC, 0x00,
+ /* 182, 0xB6 */ 0x00, 0xFF, 0x99, 0x00,
+ /* 183, 0xB7 */ 0x00, 0xFF, 0x66, 0x00,
+ /* 184, 0xB8 */ 0x00, 0xFF, 0x33, 0x00,
+ /* 185, 0xB9 */ 0x00, 0xFF, 0x00, 0x00,
+ /* 186, 0xBA */ 0x00, 0xCC, 0xFF, 0x00,
+ /* 187, 0xBB */ 0x00, 0xCC, 0xCC, 0x00,
+ /* 188, 0xBC */ 0x00, 0xCC, 0x99, 0x00,
+ /* 189, 0xBD */ 0x00, 0xCC, 0x66, 0x00,
+ /* 190, 0xBE */ 0x00, 0xCC, 0x33, 0x00,
+ /* 191, 0xBF */ 0x00, 0xCC, 0x00, 0x00,
+ /* 192, 0xC0 */ 0x00, 0x99, 0xFF, 0x00,
+ /* 193, 0xC1 */ 0x00, 0x99, 0xCC, 0x00,
+ /* 194, 0xC2 */ 0x00, 0x99, 0x99, 0x00,
+ /* 195, 0xC3 */ 0x00, 0x99, 0x66, 0x00,
+ /* 196, 0xC4 */ 0x00, 0x99, 0x33, 0x00,
+ /* 197, 0xC5 */ 0x00, 0x99, 0x00, 0x00,
+ /* 198, 0xC6 */ 0x00, 0x66, 0xFF, 0x00,
+ /* 199, 0xC7 */ 0x00, 0x66, 0xCC, 0x00,
+ /* 200, 0xC8 */ 0x00, 0x66, 0x99, 0x00,
+ /* 201, 0xC9 */ 0x00, 0x66, 0x66, 0x00,
+ /* 202, 0xCA */ 0x00, 0x66, 0x33, 0x00,
+ /* 203, 0xCB */ 0x00, 0x66, 0x00, 0x00,
+ /* 204, 0xCC */ 0x00, 0x33, 0xFF, 0x00,
+ /* 205, 0xCD */ 0x00, 0x33, 0xCC, 0x00,
+ /* 206, 0xCE */ 0x00, 0x33, 0x99, 0x00,
+ /* 207, 0xCF */ 0x00, 0x33, 0x66, 0x00,
+ /* 208, 0xD0 */ 0x00, 0x33, 0x33, 0x00,
+ /* 209, 0xD1 */ 0x00, 0x33, 0x00, 0x00,
+ /* 210, 0xD2 */ 0x00, 0x00, 0xFF, 0x00,
+ /* 211, 0xD3 */ 0x00, 0x00, 0xCC, 0x00,
+ /* 212, 0xD4 */ 0x00, 0x00, 0x99, 0x00,
+ /* 213, 0xD5 */ 0x00, 0x00, 0x66, 0x00,
+ /* 214, 0xD6 */ 0x00, 0x00, 0x33, 0x00,
+ /* 215, 0xD7 */ 0xEE, 0x00, 0x00, 0x00,
+ /* 216, 0xD8 */ 0xDD, 0x00, 0x00, 0x00,
+ /* 217, 0xD9 */ 0xBB, 0x00, 0x00, 0x00,
+ /* 218, 0xDA */ 0xAA, 0x00, 0x00, 0x00,
+ /* 219, 0xDB */ 0x88, 0x00, 0x00, 0x00,
+ /* 220, 0xDC */ 0x77, 0x00, 0x00, 0x00,
+ /* 221, 0xDD */ 0x55, 0x00, 0x00, 0x00,
+ /* 222, 0xDE */ 0x44, 0x00, 0x00, 0x00,
+ /* 223, 0xDF */ 0x22, 0x00, 0x00, 0x00,
+ /* 224, 0xE0 */ 0x11, 0x00, 0x00, 0x00,
+ /* 225, 0xE1 */ 0x00, 0xEE, 0x00, 0x00,
+ /* 226, 0xE2 */ 0x00, 0xDD, 0x00, 0x00,
+ /* 227, 0xE3 */ 0x00, 0xBB, 0x00, 0x00,
+ /* 228, 0xE4 */ 0x00, 0xAA, 0x00, 0x00,
+ /* 229, 0xE5 */ 0x00, 0x88, 0x00, 0x00,
+ /* 230, 0xE6 */ 0x00, 0x77, 0x00, 0x00,
+ /* 231, 0xE7 */ 0x00, 0x55, 0x00, 0x00,
+ /* 232, 0xE8 */ 0x00, 0x44, 0x00, 0x00,
+ /* 233, 0xE9 */ 0x00, 0x22, 0x00, 0x00,
+ /* 234, 0xEA */ 0x00, 0x11, 0x00, 0x00,
+ /* 235, 0xEB */ 0x00, 0x00, 0xEE, 0x00,
+ /* 236, 0xEC */ 0x00, 0x00, 0xDD, 0x00,
+ /* 237, 0xED */ 0x00, 0x00, 0xBB, 0x00,
+ /* 238, 0xEE */ 0x00, 0x00, 0xAA, 0x00,
+ /* 239, 0xEF */ 0x00, 0x00, 0x88, 0x00,
+ /* 240, 0xF0 */ 0x00, 0x00, 0x77, 0x00,
+ /* 241, 0xF1 */ 0x00, 0x00, 0x55, 0x00,
+ /* 242, 0xF2 */ 0x00, 0x00, 0x44, 0x00,
+ /* 243, 0xF3 */ 0x00, 0x00, 0x22, 0x00,
+ /* 244, 0xF4 */ 0x00, 0x00, 0x11, 0x00,
+ /* 245, 0xF5 */ 0xEE, 0xEE, 0xEE, 0x00,
+ /* 246, 0xF6 */ 0xDD, 0xDD, 0xDD, 0x00,
+ /* 247, 0xF7 */ 0xBB, 0xBB, 0xBB, 0x00,
+ /* 248, 0xF8 */ 0xAA, 0xAA, 0xAA, 0x00,
+ /* 249, 0xF9 */ 0x88, 0x88, 0x88, 0x00,
+ /* 250, 0xFA */ 0x77, 0x77, 0x77, 0x00,
+ /* 251, 0xFB */ 0x55, 0x55, 0x55, 0x00,
+ /* 252, 0xFC */ 0x44, 0x44, 0x44, 0x00,
+ /* 253, 0xFD */ 0x22, 0x22, 0x22, 0x00,
+ /* 254, 0xFE */ 0x11, 0x11, 0x11, 0x00,
+ /* 255, 0xFF */ 0x00, 0x00, 0x00, 0x00
+};
+
+#endif
diff --git a/contrib/ffmpeg/libavformat/raw.c b/contrib/ffmpeg/libavformat/raw.c
new file mode 100644
index 000000000..73a20379a
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/raw.c
@@ -0,0 +1,901 @@
+/*
+ * RAW muxer and demuxer
+ * Copyright (c) 2001 Fabrice Bellard.
+ * Copyright (c) 2005 Alex Beregszaszi
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include "avformat.h"
+#include "ac3.h"
+
+#ifdef CONFIG_MUXERS
+/* simple formats */
+static int raw_write_header(struct AVFormatContext *s)
+{
+ return 0;
+}
+
+static int flac_write_header(struct AVFormatContext *s)
+{
+ static const uint8_t header[8] = {
+ 0x66, 0x4C, 0x61, 0x43, 0x80, 0x00, 0x00, 0x22
+ };
+ uint8_t *streaminfo = s->streams[0]->codec->extradata;
+ int len = s->streams[0]->codec->extradata_size;
+ if(streaminfo != NULL && len > 0) {
+ put_buffer(&s->pb, header, 8);
+ put_buffer(&s->pb, streaminfo, len);
+ }
+ return 0;
+}
+
+static int raw_write_packet(struct AVFormatContext *s, AVPacket *pkt)
+{
+ put_buffer(&s->pb, pkt->data, pkt->size);
+ put_flush_packet(&s->pb);
+ return 0;
+}
+
+static int raw_write_trailer(struct AVFormatContext *s)
+{
+ return 0;
+}
+#endif //CONFIG_MUXERS
+
+/* raw input */
+static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+ AVStream *st;
+ int id;
+
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+
+ id = s->iformat->value;
+ if (id == CODEC_ID_RAWVIDEO) {
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ } else {
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ }
+ st->codec->codec_id = id;
+
+ switch(st->codec->codec_type) {
+ case CODEC_TYPE_AUDIO:
+ st->codec->sample_rate = ap->sample_rate;
+ st->codec->channels = ap->channels;
+ av_set_pts_info(st, 64, 1, st->codec->sample_rate);
+ break;
+ case CODEC_TYPE_VIDEO:
+ av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
+ st->codec->width = ap->width;
+ st->codec->height = ap->height;
+ st->codec->pix_fmt = ap->pix_fmt;
+ if(st->codec->pix_fmt == PIX_FMT_NONE)
+ st->codec->pix_fmt= PIX_FMT_YUV420P;
+ break;
+ default:
+ return -1;
+ }
+ return 0;
+}
+
+#define RAW_PACKET_SIZE 1024
+
+static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ int ret, size;
+ // AVStream *st = s->streams[0];
+
+ size= RAW_PACKET_SIZE;
+
+ ret= av_get_packet(&s->pb, pkt, size);
+
+ pkt->stream_index = 0;
+ if (ret <= 0) {
+ return AVERROR_IO;
+ }
+ /* note: we need to modify the packet size here to handle the last
+ packet */
+ pkt->size = ret;
+ return ret;
+}
+
+static int raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ int ret, size;
+
+ size = RAW_PACKET_SIZE;
+
+ if (av_new_packet(pkt, size) < 0)
+ return AVERROR_IO;
+
+ pkt->pos= url_ftell(&s->pb);
+ pkt->stream_index = 0;
+ ret = get_partial_buffer(&s->pb, pkt->data, size);
+ if (ret <= 0) {
+ av_free_packet(pkt);
+ return AVERROR_IO;
+ }
+ pkt->size = ret;
+ return ret;
+}
+
+// http://www.artificis.hu/files/texts/ingenient.txt
+static int ingenient_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ int ret, size, w, h, unk1, unk2;
+
+ if (get_le32(&s->pb) != MKTAG('M', 'J', 'P', 'G'))
+ return AVERROR_IO; // FIXME
+
+ size = get_le32(&s->pb);
+
+ w = get_le16(&s->pb);
+ h = get_le16(&s->pb);
+
+ url_fskip(&s->pb, 8); // zero + size (padded?)
+ url_fskip(&s->pb, 2);
+ unk1 = get_le16(&s->pb);
+ unk2 = get_le16(&s->pb);
+ url_fskip(&s->pb, 22); // ascii timestamp
+
+ av_log(NULL, AV_LOG_DEBUG, "Ingenient packet: size=%d, width=%d, height=%d, unk1=%d unk2=%d\n",
+ size, w, h, unk1, unk2);
+
+ if (av_new_packet(pkt, size) < 0)
+ return AVERROR_IO;
+
+ pkt->pos = url_ftell(&s->pb);
+ pkt->stream_index = 0;
+ ret = get_buffer(&s->pb, pkt->data, size);
+ if (ret <= 0) {
+ av_free_packet(pkt);
+ return AVERROR_IO;
+ }
+ pkt->size = ret;
+ return ret;
+}
+
+static int raw_read_close(AVFormatContext *s)
+{
+ return 0;
+}
+
+int pcm_read_seek(AVFormatContext *s,
+ int stream_index, int64_t timestamp, int flags)
+{
+ AVStream *st;
+ int block_align, byte_rate;
+ int64_t pos;
+
+ st = s->streams[0];
+
+ block_align = st->codec->block_align ? st->codec->block_align :
+ (av_get_bits_per_sample(st->codec->codec_id) * st->codec->channels) >> 3;
+ byte_rate = st->codec->bit_rate ? st->codec->bit_rate >> 3 :
+ block_align * st->codec->sample_rate;
+
+ if (block_align <= 0 || byte_rate <= 0)
+ return -1;
+
+ /* compute the position by aligning it to block_align */
+ pos = av_rescale_rnd(timestamp * byte_rate,
+ st->time_base.num,
+ st->time_base.den * (int64_t)block_align,
+ (flags & AVSEEK_FLAG_BACKWARD) ? AV_ROUND_DOWN : AV_ROUND_UP);
+ pos *= block_align;
+
+ /* recompute exact position */
+ st->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num);
+ url_fseek(&s->pb, pos + s->data_offset, SEEK_SET);
+ return 0;
+}
+
+/* ac3 read */
+static int ac3_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ AVStream *st;
+
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_id = CODEC_ID_AC3;
+ st->need_parsing = 1;
+ /* the parameters will be extracted from the compressed bitstream */
+ return 0;
+}
+
+static int shorten_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ AVStream *st;
+
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_id = CODEC_ID_SHORTEN;
+ st->need_parsing = 1;
+ /* the parameters will be extracted from the compressed bitstream */
+ return 0;
+}
+
+/* flac read */
+static int flac_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ AVStream *st;
+
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_id = CODEC_ID_FLAC;
+ st->need_parsing = 1;
+ /* the parameters will be extracted from the compressed bitstream */
+ return 0;
+}
+
+/* dts read */
+static int dts_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ AVStream *st;
+
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_id = CODEC_ID_DTS;
+ st->need_parsing = 1;
+ /* the parameters will be extracted from the compressed bitstream */
+ return 0;
+}
+
+/* aac read */
+static int aac_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ AVStream *st;
+
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_id = CODEC_ID_AAC;
+ st->need_parsing = 1;
+ /* the parameters will be extracted from the compressed bitstream */
+ return 0;
+}
+
+/* mpeg1/h263 input */
+static int video_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ AVStream *st;
+
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ st->codec->codec_id = s->iformat->value;
+ st->need_parsing = 1;
+
+ /* for mjpeg, specify frame rate */
+ /* for mpeg4 specify it too (most mpeg4 streams dont have the fixed_vop_rate set ...)*/
+ if (ap->time_base.num) {
+ av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
+ } else if ( st->codec->codec_id == CODEC_ID_MJPEG ||
+ st->codec->codec_id == CODEC_ID_MPEG4 ||
+ st->codec->codec_id == CODEC_ID_H264) {
+ av_set_pts_info(st, 64, 1, 25);
+ }
+
+ return 0;
+}
+
+#define SEQ_START_CODE 0x000001b3
+#define GOP_START_CODE 0x000001b8
+#define PICTURE_START_CODE 0x00000100
+#define SLICE_START_CODE 0x00000101
+#define PACK_START_CODE 0x000001ba
+#define VIDEO_ID 0x000001e0
+#define AUDIO_ID 0x000001c0
+
+static int mpegvideo_probe(AVProbeData *p)
+{
+ uint32_t code= -1;
+ int pic=0, seq=0, slice=0, pspack=0, pes=0;
+ int i;
+
+ for(i=0; i<p->buf_size; i++){
+ code = (code<<8) + p->buf[i];
+ if ((code & 0xffffff00) == 0x100) {
+ switch(code){
+ case SEQ_START_CODE: seq++; break;
+ case PICTURE_START_CODE: pic++; break;
+ case SLICE_START_CODE: slice++; break;
+ case PACK_START_CODE: pspack++; break;
+ }
+ if ((code & 0x1f0) == VIDEO_ID) pes++;
+ else if((code & 0x1e0) == AUDIO_ID) pes++;
+ }
+ }
+ if(seq && seq*9<=pic*10 && pic*9<=slice*10 && !pspack && !pes)
+ return AVPROBE_SCORE_MAX/2+1; // +1 for .mpg
+ return 0;
+}
+
+#define VIDEO_OBJECT_START_CODE 0x00000100
+#define VIDEO_OBJECT_LAYER_START_CODE 0x00000120
+#define VISUAL_OBJECT_START_CODE 0x000001b5
+#define VOP_START_CODE 0x000001b6
+
+static int mpeg4video_probe(AVProbeData *probe_packet)
+{
+ uint32_t temp_buffer= -1;
+ int VO=0, VOL=0, VOP = 0, VISO = 0;
+ int i;
+
+ for(i=0; i<probe_packet->buf_size; i++){
+ temp_buffer = (temp_buffer<<8) + probe_packet->buf[i];
+ if ((temp_buffer & 0xffffff00) == 0x100) {
+ switch(temp_buffer){
+ case VOP_START_CODE: VOP++; break;
+ case VISUAL_OBJECT_START_CODE: VISO++; break;
+ }
+ switch(temp_buffer & 0xfffffff0){
+ case VIDEO_OBJECT_START_CODE: VO++; break;
+ case VIDEO_OBJECT_LAYER_START_CODE: VOL++; break;
+ }
+ }
+ }
+
+ if ( VOP >= VISO && VOP >= VOL && VO >= VOL && VOL > 0)
+ return AVPROBE_SCORE_MAX/2;
+ return 0;
+}
+
+static int h263_probe(AVProbeData *p)
+{
+ int code;
+ const uint8_t *d;
+
+ if (p->buf_size < 6)
+ return 0;
+ d = p->buf;
+ code = (d[0] << 14) | (d[1] << 6) | (d[2] >> 2);
+ if (code == 0x20) {
+ return 50;
+ }
+ return 0;
+}
+
+static int h261_probe(AVProbeData *p)
+{
+ int code;
+ const uint8_t *d;
+
+ if (p->buf_size < 6)
+ return 0;
+ d = p->buf;
+ code = (d[0] << 12) | (d[1] << 4) | (d[2] >> 4);
+ if (code == 0x10) {
+ return 50;
+ }
+ return 0;
+}
+
+static int ac3_probe(AVProbeData *p)
+{
+ int max_frames, first_frames, frames;
+ uint8_t *buf, *buf2, *end;
+ AC3HeaderInfo hdr;
+
+ if(p->buf_size < 7)
+ return 0;
+
+ max_frames = 0;
+ buf = p->buf;
+ end = buf + FFMIN(4096, p->buf_size - 7);
+
+ for(; buf < end; buf++) {
+ buf2 = buf;
+
+ for(frames = 0; buf2 < end; frames++) {
+ if(ff_ac3_parse_header(buf2, &hdr) < 0)
+ break;
+ buf2 += hdr.frame_size;
+ }
+ max_frames = FFMAX(max_frames, frames);
+ if(buf == p->buf)
+ first_frames = frames;
+ }
+ if (first_frames>=3) return AVPROBE_SCORE_MAX * 3 / 4;
+ else if(max_frames>=3) return AVPROBE_SCORE_MAX / 2;
+ else if(max_frames>=1) return 1;
+ else return 0;
+}
+
+AVInputFormat shorten_demuxer = {
+ "shn",
+ "raw shorten",
+ 0,
+ NULL,
+ shorten_read_header,
+ raw_read_partial_packet,
+ raw_read_close,
+ .flags= AVFMT_GENERIC_INDEX,
+ .extensions = "shn",
+};
+
+AVInputFormat flac_demuxer = {
+ "flac",
+ "raw flac",
+ 0,
+ NULL,
+ flac_read_header,
+ raw_read_partial_packet,
+ raw_read_close,
+ .flags= AVFMT_GENERIC_INDEX,
+ .extensions = "flac",
+};
+
+#ifdef CONFIG_MUXERS
+AVOutputFormat flac_muxer = {
+ "flac",
+ "raw flac",
+ "audio/x-flac",
+ "flac",
+ 0,
+ CODEC_ID_FLAC,
+ 0,
+ flac_write_header,
+ raw_write_packet,
+ raw_write_trailer,
+ .flags= AVFMT_NOTIMESTAMPS,
+};
+#endif //CONFIG_MUXERS
+
+AVInputFormat ac3_demuxer = {
+ "ac3",
+ "raw ac3",
+ 0,
+ ac3_probe,
+ ac3_read_header,
+ raw_read_partial_packet,
+ raw_read_close,
+ .flags= AVFMT_GENERIC_INDEX,
+ .extensions = "ac3",
+};
+
+#ifdef CONFIG_MUXERS
+AVOutputFormat ac3_muxer = {
+ "ac3",
+ "raw ac3",
+ "audio/x-ac3",
+ "ac3",
+ 0,
+ CODEC_ID_AC3,
+ 0,
+ raw_write_header,
+ raw_write_packet,
+ raw_write_trailer,
+ .flags= AVFMT_NOTIMESTAMPS,
+};
+#endif //CONFIG_MUXERS
+
+AVInputFormat dts_demuxer = {
+ "dts",
+ "raw dts",
+ 0,
+ NULL,
+ dts_read_header,
+ raw_read_partial_packet,
+ raw_read_close,
+ .flags= AVFMT_GENERIC_INDEX,
+ .extensions = "dts",
+};
+
+AVInputFormat aac_demuxer = {
+ "aac",
+ "ADTS AAC",
+ 0,
+ NULL,
+ aac_read_header,
+ raw_read_partial_packet,
+ raw_read_close,
+ .flags= AVFMT_GENERIC_INDEX,
+ .extensions = "aac",
+};
+
+AVInputFormat h261_demuxer = {
+ "h261",
+ "raw h261",
+ 0,
+ h261_probe,
+ video_read_header,
+ raw_read_partial_packet,
+ raw_read_close,
+ .flags= AVFMT_GENERIC_INDEX,
+ .extensions = "h261",
+ .value = CODEC_ID_H261,
+};
+
+#ifdef CONFIG_MUXERS
+AVOutputFormat h261_muxer = {
+ "h261",
+ "raw h261",
+ "video/x-h261",
+ "h261",
+ 0,
+ 0,
+ CODEC_ID_H261,
+ raw_write_header,
+ raw_write_packet,
+ raw_write_trailer,
+ .flags= AVFMT_NOTIMESTAMPS,
+};
+#endif //CONFIG_MUXERS
+
+AVInputFormat h263_demuxer = {
+ "h263",
+ "raw h263",
+ 0,
+ h263_probe,
+ video_read_header,
+ raw_read_partial_packet,
+ raw_read_close,
+ .flags= AVFMT_GENERIC_INDEX,
+// .extensions = "h263", //FIXME remove after writing mpeg4_probe
+ .value = CODEC_ID_H263,
+};
+
+#ifdef CONFIG_MUXERS
+AVOutputFormat h263_muxer = {
+ "h263",
+ "raw h263",
+ "video/x-h263",
+ "h263",
+ 0,
+ 0,
+ CODEC_ID_H263,
+ raw_write_header,
+ raw_write_packet,
+ raw_write_trailer,
+ .flags= AVFMT_NOTIMESTAMPS,
+};
+#endif //CONFIG_MUXERS
+
+AVInputFormat m4v_demuxer = {
+ "m4v",
+ "raw MPEG4 video format",
+ 0,
+ mpeg4video_probe, /** probing for mpeg4 data */
+ video_read_header,
+ raw_read_partial_packet,
+ raw_read_close,
+ .flags= AVFMT_GENERIC_INDEX,
+ .extensions = "m4v", //FIXME remove after writing mpeg4_probe
+ .value = CODEC_ID_MPEG4,
+};
+
+#ifdef CONFIG_MUXERS
+AVOutputFormat m4v_muxer = {
+ "m4v",
+ "raw MPEG4 video format",
+ NULL,
+ "m4v",
+ 0,
+ CODEC_ID_NONE,
+ CODEC_ID_MPEG4,
+ raw_write_header,
+ raw_write_packet,
+ raw_write_trailer,
+ .flags= AVFMT_NOTIMESTAMPS,
+};
+#endif //CONFIG_MUXERS
+
+AVInputFormat h264_demuxer = {
+ "h264",
+ "raw H264 video format",
+ 0,
+ NULL /*mpegvideo_probe*/,
+ video_read_header,
+ raw_read_partial_packet,
+ raw_read_close,
+ .flags= AVFMT_GENERIC_INDEX,
+ .extensions = "h26l,h264,264", //FIXME remove after writing mpeg4_probe
+ .value = CODEC_ID_H264,
+};
+
+#ifdef CONFIG_MUXERS
+AVOutputFormat h264_muxer = {
+ "h264",
+ "raw H264 video format",
+ NULL,
+ "h264",
+ 0,
+ CODEC_ID_NONE,
+ CODEC_ID_H264,
+ raw_write_header,
+ raw_write_packet,
+ raw_write_trailer,
+ .flags= AVFMT_NOTIMESTAMPS,
+};
+#endif //CONFIG_MUXERS
+
+AVInputFormat mpegvideo_demuxer = {
+ "mpegvideo",
+ "MPEG video",
+ 0,
+ mpegvideo_probe,
+ video_read_header,
+ raw_read_partial_packet,
+ raw_read_close,
+ .flags= AVFMT_GENERIC_INDEX,
+ .value = CODEC_ID_MPEG1VIDEO,
+};
+
+#ifdef CONFIG_MUXERS
+AVOutputFormat mpeg1video_muxer = {
+ "mpeg1video",
+ "MPEG video",
+ "video/x-mpeg",
+ "mpg,mpeg,m1v",
+ 0,
+ 0,
+ CODEC_ID_MPEG1VIDEO,
+ raw_write_header,
+ raw_write_packet,
+ raw_write_trailer,
+ .flags= AVFMT_NOTIMESTAMPS,
+};
+#endif //CONFIG_MUXERS
+
+#ifdef CONFIG_MUXERS
+AVOutputFormat mpeg2video_muxer = {
+ "mpeg2video",
+ "MPEG2 video",
+ NULL,
+ "m2v",
+ 0,
+ 0,
+ CODEC_ID_MPEG2VIDEO,
+ raw_write_header,
+ raw_write_packet,
+ raw_write_trailer,
+ .flags= AVFMT_NOTIMESTAMPS,
+};
+#endif //CONFIG_MUXERS
+
+AVInputFormat mjpeg_demuxer = {
+ "mjpeg",
+ "MJPEG video",
+ 0,
+ NULL,
+ video_read_header,
+ raw_read_partial_packet,
+ raw_read_close,
+ .flags= AVFMT_GENERIC_INDEX,
+ .extensions = "mjpg,mjpeg",
+ .value = CODEC_ID_MJPEG,
+};
+
+AVInputFormat ingenient_demuxer = {
+ "ingenient",
+ "Ingenient MJPEG",
+ 0,
+ NULL,
+ video_read_header,
+ ingenient_read_packet,
+ raw_read_close,
+ .flags= AVFMT_GENERIC_INDEX,
+ .extensions = "cgi", // FIXME
+ .value = CODEC_ID_MJPEG,
+};
+
+#ifdef CONFIG_MUXERS
+AVOutputFormat mjpeg_muxer = {
+ "mjpeg",
+ "MJPEG video",
+ "video/x-mjpeg",
+ "mjpg,mjpeg",
+ 0,
+ 0,
+ CODEC_ID_MJPEG,
+ raw_write_header,
+ raw_write_packet,
+ raw_write_trailer,
+ .flags= AVFMT_NOTIMESTAMPS,
+};
+#endif //CONFIG_MUXERS
+
+AVInputFormat vc1_demuxer = {
+ "vc1",
+ "raw vc1",
+ 0,
+ NULL /* vc1_probe */,
+ video_read_header,
+ raw_read_partial_packet,
+ raw_read_close,
+ .extensions = "vc1",
+ .value = CODEC_ID_VC1,
+};
+
+/* pcm formats */
+
+#define PCMINPUTDEF(name, long_name, ext, codec) \
+AVInputFormat pcm_ ## name ## _demuxer = {\
+ #name,\
+ long_name,\
+ 0,\
+ NULL,\
+ raw_read_header,\
+ raw_read_packet,\
+ raw_read_close,\
+ pcm_read_seek,\
+ .flags= AVFMT_GENERIC_INDEX,\
+ .extensions = ext,\
+ .value = codec,\
+};
+
+#define PCMOUTPUTDEF(name, long_name, ext, codec) \
+AVOutputFormat pcm_ ## name ## _muxer = {\
+ #name,\
+ long_name,\
+ NULL,\
+ ext,\
+ 0,\
+ codec,\
+ 0,\
+ raw_write_header,\
+ raw_write_packet,\
+ raw_write_trailer,\
+ .flags= AVFMT_NOTIMESTAMPS,\
+};
+
+
+#if !defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
+#define PCMDEF(name, long_name, ext, codec) \
+ PCMINPUTDEF(name, long_name, ext, codec)
+#elif defined(CONFIG_MUXERS) && !defined(CONFIG_DEMUXERS)
+#define PCMDEF(name, long_name, ext, codec) \
+ PCMOUTPUTDEF(name, long_name, ext, codec)
+#elif defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
+#define PCMDEF(name, long_name, ext, codec) \
+ PCMINPUTDEF(name, long_name, ext, codec)\
+ PCMOUTPUTDEF(name, long_name, ext, codec)
+#else
+#define PCMDEF(name, long_name, ext, codec)
+#endif
+
+#ifdef WORDS_BIGENDIAN
+#define BE_DEF(s) s
+#define LE_DEF(s) NULL
+#else
+#define BE_DEF(s) NULL
+#define LE_DEF(s) s
+#endif
+
+
+PCMDEF(s16le, "pcm signed 16 bit little endian format",
+ LE_DEF("sw"), CODEC_ID_PCM_S16LE)
+
+PCMDEF(s16be, "pcm signed 16 bit big endian format",
+ BE_DEF("sw"), CODEC_ID_PCM_S16BE)
+
+PCMDEF(u16le, "pcm unsigned 16 bit little endian format",
+ LE_DEF("uw"), CODEC_ID_PCM_U16LE)
+
+PCMDEF(u16be, "pcm unsigned 16 bit big endian format",
+ BE_DEF("uw"), CODEC_ID_PCM_U16BE)
+
+PCMDEF(s8, "pcm signed 8 bit format",
+ "sb", CODEC_ID_PCM_S8)
+
+PCMDEF(u8, "pcm unsigned 8 bit format",
+ "ub", CODEC_ID_PCM_U8)
+
+PCMDEF(mulaw, "pcm mu law format",
+ "ul", CODEC_ID_PCM_MULAW)
+
+PCMDEF(alaw, "pcm A law format",
+ "al", CODEC_ID_PCM_ALAW)
+
+static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ int packet_size, ret, width, height;
+ AVStream *st = s->streams[0];
+
+ width = st->codec->width;
+ height = st->codec->height;
+
+ packet_size = avpicture_get_size(st->codec->pix_fmt, width, height);
+ if (packet_size < 0)
+ return -1;
+
+ ret= av_get_packet(&s->pb, pkt, packet_size);
+
+ pkt->stream_index = 0;
+ if (ret != packet_size) {
+ return AVERROR_IO;
+ } else {
+ return 0;
+ }
+}
+
+AVInputFormat rawvideo_demuxer = {
+ "rawvideo",
+ "raw video format",
+ 0,
+ NULL,
+ raw_read_header,
+ rawvideo_read_packet,
+ raw_read_close,
+ .flags= AVFMT_GENERIC_INDEX,
+ .extensions = "yuv,cif,qcif",
+ .value = CODEC_ID_RAWVIDEO,
+};
+
+#ifdef CONFIG_MUXERS
+AVOutputFormat rawvideo_muxer = {
+ "rawvideo",
+ "raw video format",
+ NULL,
+ "yuv",
+ 0,
+ CODEC_ID_NONE,
+ CODEC_ID_RAWVIDEO,
+ raw_write_header,
+ raw_write_packet,
+ raw_write_trailer,
+ .flags= AVFMT_NOTIMESTAMPS,
+};
+#endif //CONFIG_MUXERS
+
+#ifdef CONFIG_MUXERS
+static int null_write_packet(struct AVFormatContext *s, AVPacket *pkt)
+{
+ return 0;
+}
+
+AVOutputFormat null_muxer = {
+ "null",
+ "null video format",
+ NULL,
+ NULL,
+ 0,
+#ifdef WORDS_BIGENDIAN
+ CODEC_ID_PCM_S16BE,
+#else
+ CODEC_ID_PCM_S16LE,
+#endif
+ CODEC_ID_RAWVIDEO,
+ raw_write_header,
+ null_write_packet,
+ raw_write_trailer,
+ .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE | AVFMT_NOTIMESTAMPS,
+};
+#endif //CONFIG_MUXERS
diff --git a/contrib/ffmpeg/libavformat/riff.c b/contrib/ffmpeg/libavformat/riff.c
new file mode 100644
index 000000000..4a5553fa4
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/riff.c
@@ -0,0 +1,500 @@
+/*
+ * RIFF codec tags
+ * Copyright (c) 2000 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 "avformat.h"
+#include "avcodec.h"
+#include "riff.h"
+#include "allformats.h" // for asf_muxer
+
+/* Note: when encoding, the first matching tag is used, so order is
+ important if multiple tags possible for a given codec. */
+const AVCodecTag codec_bmp_tags[] = {
+ { CODEC_ID_H264, MKTAG('H', '2', '6', '4') },
+ { CODEC_ID_H264, MKTAG('h', '2', '6', '4') },
+ { CODEC_ID_H264, MKTAG('X', '2', '6', '4') },
+ { CODEC_ID_H264, MKTAG('x', '2', '6', '4') },
+ { CODEC_ID_H264, MKTAG('a', 'v', 'c', '1') },
+ { CODEC_ID_H264, MKTAG('V', 'S', 'S', 'H') },
+
+ { CODEC_ID_H263, MKTAG('H', '2', '6', '3') },
+ { CODEC_ID_H263P, MKTAG('H', '2', '6', '3') },
+ { CODEC_ID_H263I, MKTAG('I', '2', '6', '3') }, /* intel h263 */
+ { CODEC_ID_H261, MKTAG('H', '2', '6', '1') },
+
+ /* added based on MPlayer */
+ { CODEC_ID_H263P, MKTAG('U', '2', '6', '3') },
+ { CODEC_ID_H263P, MKTAG('v', 'i', 'v', '1') },
+
+ { CODEC_ID_MPEG4, MKTAG('F', 'M', 'P', '4') },
+ { CODEC_ID_MPEG4, MKTAG('D', 'I', 'V', 'X') },
+ { CODEC_ID_MPEG4, MKTAG('D', 'X', '5', '0') },
+ { CODEC_ID_MPEG4, MKTAG('X', 'V', 'I', 'D') },
+ { CODEC_ID_MPEG4, MKTAG('M', 'P', '4', 'S') },
+ { CODEC_ID_MPEG4, MKTAG('M', '4', 'S', '2') },
+ { CODEC_ID_MPEG4, MKTAG(0x04, 0, 0, 0) }, /* some broken avi use this */
+
+ /* added based on MPlayer */
+ { CODEC_ID_MPEG4, MKTAG('D', 'I', 'V', '1') },
+ { CODEC_ID_MPEG4, MKTAG('B', 'L', 'Z', '0') },
+ { CODEC_ID_MPEG4, MKTAG('m', 'p', '4', 'v') },
+ { CODEC_ID_MPEG4, MKTAG('U', 'M', 'P', '4') },
+ { CODEC_ID_MPEG4, MKTAG('W', 'V', '1', 'F') },
+ { CODEC_ID_MPEG4, MKTAG('S', 'E', 'D', 'G') },
+
+ { CODEC_ID_MPEG4, MKTAG('R', 'M', 'P', '4') },
+
+ { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '3') }, /* default signature when using MSMPEG4 */
+ { CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', '4', '3') },
+
+ /* added based on MPlayer */
+ { CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', 'G', '3') },
+ { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '5') },
+ { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '6') },
+ { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '4') },
+ { CODEC_ID_MSMPEG4V3, MKTAG('A', 'P', '4', '1') },
+ { CODEC_ID_MSMPEG4V3, MKTAG('C', 'O', 'L', '1') },
+ { CODEC_ID_MSMPEG4V3, MKTAG('C', 'O', 'L', '0') },
+
+ { CODEC_ID_MSMPEG4V2, MKTAG('M', 'P', '4', '2') },
+
+ /* added based on MPlayer */
+ { CODEC_ID_MSMPEG4V2, MKTAG('D', 'I', 'V', '2') },
+
+ { CODEC_ID_MSMPEG4V1, MKTAG('M', 'P', 'G', '4') },
+
+ { CODEC_ID_WMV1, MKTAG('W', 'M', 'V', '1') },
+
+ /* added based on MPlayer */
+ { CODEC_ID_WMV2, MKTAG('W', 'M', 'V', '2') },
+ { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 's', 'd') },
+ { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'h', 'd') },
+ { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 's', 'l') },
+ { CODEC_ID_DVVIDEO, MKTAG('d', 'v', '2', '5') },
+ { CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'g', '1') },
+ { CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'g', '2') },
+ { CODEC_ID_MPEG2VIDEO, MKTAG('m', 'p', 'g', '2') },
+ { CODEC_ID_MPEG2VIDEO, MKTAG('M', 'P', 'E', 'G') },
+ { CODEC_ID_MPEG1VIDEO, MKTAG('P', 'I', 'M', '1') },
+ { CODEC_ID_MPEG1VIDEO, MKTAG('V', 'C', 'R', '2') },
+ { CODEC_ID_MPEG1VIDEO, 0x10000001 },
+ { CODEC_ID_MPEG2VIDEO, 0x10000002 },
+ { CODEC_ID_MPEG2VIDEO, MKTAG('D', 'V', 'R', ' ') },
+ { CODEC_ID_MJPEG, MKTAG('M', 'J', 'P', 'G') },
+ { CODEC_ID_MJPEG, MKTAG('L', 'J', 'P', 'G') },
+ { CODEC_ID_LJPEG, MKTAG('L', 'J', 'P', 'G') },
+ { CODEC_ID_MJPEG, MKTAG('J', 'P', 'G', 'L') }, /* Pegasus lossless JPEG */
+ { CODEC_ID_MJPEG, MKTAG('M', 'J', 'L', 'S') }, /* JPEG-LS custom FOURCC for avi - decoder */
+ { CODEC_ID_MJPEG, MKTAG('j', 'p', 'e', 'g') },
+ { CODEC_ID_MJPEG, MKTAG('I', 'J', 'P', 'G') },
+ { CODEC_ID_MJPEG, MKTAG('A', 'V', 'R', 'n') },
+ { CODEC_ID_JPEGLS, MKTAG('M', 'J', 'L', 'S') }, /* JPEG-LS custom FOURCC for avi - encoder */
+ { CODEC_ID_HUFFYUV, MKTAG('H', 'F', 'Y', 'U') },
+ { CODEC_ID_FFVHUFF, MKTAG('F', 'F', 'V', 'H') },
+ { CODEC_ID_CYUV, MKTAG('C', 'Y', 'U', 'V') },
+ { CODEC_ID_RAWVIDEO, 0 },
+ { 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('Y', 'V', '1', '2') },
+ { CODEC_ID_RAWVIDEO, MKTAG('U', 'Y', 'V', 'Y') },
+ { CODEC_ID_RAWVIDEO, MKTAG('I', 'Y', 'U', 'V') },
+ { CODEC_ID_RAWVIDEO, MKTAG('Y', '8', '0', '0') },
+ { CODEC_ID_INDEO3, MKTAG('I', 'V', '3', '1') },
+ { CODEC_ID_INDEO3, MKTAG('I', 'V', '3', '2') },
+ { CODEC_ID_VP3, MKTAG('V', 'P', '3', '1') },
+ { CODEC_ID_VP3, MKTAG('V', 'P', '3', '0') },
+ { CODEC_ID_VP5, MKTAG('V', 'P', '5', '0') },
+ { 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_ASV1, MKTAG('A', 'S', 'V', '1') },
+ { CODEC_ID_ASV2, MKTAG('A', 'S', 'V', '2') },
+ { CODEC_ID_VCR1, MKTAG('V', 'C', 'R', '1') },
+ { CODEC_ID_FFV1, MKTAG('F', 'F', 'V', '1') },
+ { CODEC_ID_XAN_WC4, MKTAG('X', 'x', 'a', 'n') },
+ { CODEC_ID_MSRLE, MKTAG('m', 'r', 'l', 'e') },
+ { CODEC_ID_MSRLE, MKTAG(0x1, 0x0, 0x0, 0x0) },
+ { CODEC_ID_MSVIDEO1, MKTAG('M', 'S', 'V', 'C') },
+ { CODEC_ID_MSVIDEO1, MKTAG('m', 's', 'v', 'c') },
+ { CODEC_ID_MSVIDEO1, MKTAG('C', 'R', 'A', 'M') },
+ { CODEC_ID_MSVIDEO1, MKTAG('c', 'r', 'a', 'm') },
+ { CODEC_ID_MSVIDEO1, MKTAG('W', 'H', 'A', 'M') },
+ { CODEC_ID_MSVIDEO1, MKTAG('w', 'h', 'a', 'm') },
+ { CODEC_ID_CINEPAK, MKTAG('c', 'v', 'i', 'd') },
+ { CODEC_ID_TRUEMOTION1, MKTAG('D', 'U', 'C', 'K') },
+ { CODEC_ID_MSZH, MKTAG('M', 'S', 'Z', 'H') },
+ { CODEC_ID_ZLIB, MKTAG('Z', 'L', 'I', 'B') },
+ { CODEC_ID_SNOW, MKTAG('S', 'N', 'O', 'W') },
+ { 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') },
+ { CODEC_ID_VIXL, MKTAG('V', 'I', 'X', 'L') },
+ { CODEC_ID_QPEG, MKTAG('Q', 'P', 'E', 'G') },
+ { CODEC_ID_QPEG, MKTAG('Q', '1', '.', '0') },
+ { CODEC_ID_QPEG, MKTAG('Q', '1', '.', '1') },
+ { CODEC_ID_WMV3, MKTAG('W', 'M', 'V', '3') },
+ { CODEC_ID_VC1, MKTAG('W', 'V', 'C', '1') },
+ { CODEC_ID_VC1, MKTAG('W', 'M', 'V', 'A') },
+ { CODEC_ID_LOCO, MKTAG('L', 'O', 'C', 'O') },
+ { CODEC_ID_WNV1, MKTAG('W', 'N', 'V', '1') },
+ { CODEC_ID_AASC, MKTAG('A', 'A', 'S', 'C') },
+ { CODEC_ID_INDEO2, MKTAG('R', 'T', '2', '1') },
+ { CODEC_ID_FRAPS, MKTAG('F', 'P', 'S', '1') },
+ { CODEC_ID_THEORA, MKTAG('t', 'h', 'e', 'o') },
+ { CODEC_ID_TRUEMOTION2, MKTAG('T', 'M', '2', '0') },
+ { CODEC_ID_CSCD, MKTAG('C', 'S', 'C', 'D') },
+ { CODEC_ID_ZMBV, MKTAG('Z', 'M', 'B', 'V') },
+ { CODEC_ID_KMVC, MKTAG('K', 'M', 'V', 'C') },
+ { CODEC_ID_CAVS, MKTAG('C', 'A', 'V', 'S') },
+ { CODEC_ID_JPEG2000, MKTAG('M', 'J', '2', 'C') },
+ { CODEC_ID_VMNC, MKTAG('V', 'M', 'n', 'c') },
+ { CODEC_ID_TARGA, MKTAG('t', 'g', 'a', ' ') },
+ { CODEC_ID_NONE, 0 },
+};
+
+const AVCodecTag codec_wav_tags[] = {
+ { CODEC_ID_MP2, 0x50 },
+ { CODEC_ID_MP3, 0x55 },
+ { CODEC_ID_AC3, 0x2000 },
+ { CODEC_ID_DTS, 0x2001 },
+ { CODEC_ID_PCM_S16LE, 0x01 },
+ { CODEC_ID_PCM_U8, 0x01 }, /* must come after s16le in this list */
+ { CODEC_ID_PCM_S24LE, 0x01 },
+ { CODEC_ID_PCM_S32LE, 0x01 },
+ { CODEC_ID_PCM_ALAW, 0x06 },
+ { CODEC_ID_PCM_MULAW, 0x07 },
+ { CODEC_ID_ADPCM_MS, 0x02 },
+ { CODEC_ID_ADPCM_IMA_WAV, 0x11 },
+ { CODEC_ID_ADPCM_YAMAHA, 0x20 },
+ { CODEC_ID_ADPCM_G726, 0x45 },
+ { CODEC_ID_ADPCM_IMA_DK4, 0x61 }, /* rogue format number */
+ { CODEC_ID_ADPCM_IMA_DK3, 0x62 }, /* rogue format number */
+ { CODEC_ID_WMAV1, 0x160 },
+ { CODEC_ID_WMAV2, 0x161 },
+ { CODEC_ID_AAC, 0x706d },
+ { CODEC_ID_AAC, 0xff },
+ { CODEC_ID_VORBIS, ('V'<<8)+'o' }, //HACK/FIXME, does vorbis in WAV/AVI have an (in)official id?
+ { CODEC_ID_SONIC, 0x2048 },
+ { CODEC_ID_SONIC_LS, 0x2048 },
+ { CODEC_ID_ADPCM_CT, 0x200 },
+ { CODEC_ID_ADPCM_SWF, ('S'<<8)+'F' },
+ { CODEC_ID_TRUESPEECH, 0x22 },
+ { CODEC_ID_FLAC, 0xF1AC },
+ { CODEC_ID_IMC, 0x401 },
+ { CODEC_ID_GSM_MS, 0x31 },
+
+ /* FIXME: All of the IDs below are not 16 bit and thus illegal. */
+ // for NuppelVideo (nuv.c)
+ { 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 },
+};
+
+unsigned int codec_get_tag(const AVCodecTag *tags, int id)
+{
+ while (tags->id != CODEC_ID_NONE) {
+ if (tags->id == id)
+ return tags->tag;
+ tags++;
+ }
+ return 0;
+}
+
+enum CodecID codec_get_id(const AVCodecTag *tags, unsigned int tag)
+{
+ while (tags->id != CODEC_ID_NONE) {
+ if( toupper((tag >> 0)&0xFF) == toupper((tags->tag >> 0)&0xFF)
+ && toupper((tag >> 8)&0xFF) == toupper((tags->tag >> 8)&0xFF)
+ && toupper((tag >>16)&0xFF) == toupper((tags->tag >>16)&0xFF)
+ && toupper((tag >>24)&0xFF) == toupper((tags->tag >>24)&0xFF))
+ return tags->id;
+ tags++;
+ }
+ return CODEC_ID_NONE;
+}
+
+unsigned int av_codec_get_tag(const AVCodecTag *tags[4], enum CodecID id)
+{
+ int i;
+ for(i=0; tags && tags[i]; i++){
+ int tag= codec_get_tag(tags[i], id);
+ if(tag) return tag;
+ }
+ return 0;
+}
+
+enum CodecID av_codec_get_id(const AVCodecTag *tags[4], unsigned int tag)
+{
+ int i;
+ for(i=0; tags && tags[i]; i++){
+ enum CodecID id= codec_get_id(tags[i], tag);
+ if(id!=CODEC_ID_NONE) return id;
+ }
+ return CODEC_ID_NONE;
+}
+
+unsigned int codec_get_bmp_tag(int id)
+{
+ return codec_get_tag(codec_bmp_tags, id);
+}
+
+unsigned int codec_get_wav_tag(int id)
+{
+ return codec_get_tag(codec_wav_tags, id);
+}
+
+enum CodecID codec_get_bmp_id(unsigned int tag)
+{
+ return codec_get_id(codec_bmp_tags, tag);
+}
+
+enum CodecID codec_get_wav_id(unsigned int tag)
+{
+ return codec_get_id(codec_wav_tags, tag);
+}
+
+#ifdef CONFIG_MUXERS
+offset_t start_tag(ByteIOContext *pb, const char *tag)
+{
+ put_tag(pb, tag);
+ put_le32(pb, 0);
+ return url_ftell(pb);
+}
+
+void end_tag(ByteIOContext *pb, offset_t start)
+{
+ offset_t pos;
+
+ pos = url_ftell(pb);
+ url_fseek(pb, start - 4, SEEK_SET);
+ put_le32(pb, (uint32_t)(pos - start));
+ url_fseek(pb, pos, SEEK_SET);
+}
+
+/* WAVEFORMATEX header */
+/* returns the size or -1 on error */
+int put_wav_header(ByteIOContext *pb, AVCodecContext *enc)
+{
+ int bps, blkalign, bytespersec;
+ int hdrsize = 18;
+
+ if(!enc->codec_tag || enc->codec_tag > 0xffff)
+ return -1;
+
+ put_le16(pb, enc->codec_tag);
+ put_le16(pb, enc->channels);
+ put_le32(pb, enc->sample_rate);
+ if (enc->codec_id == CODEC_ID_PCM_U8 ||
+ enc->codec_id == CODEC_ID_PCM_ALAW ||
+ enc->codec_id == CODEC_ID_PCM_MULAW) {
+ bps = 8;
+ } else 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) { //
+ bps = 4;
+ } else if (enc->codec_id == CODEC_ID_PCM_S24LE) {
+ bps = 24;
+ } else if (enc->codec_id == CODEC_ID_PCM_S32LE) {
+ bps = 32;
+ } else {
+ bps = 16;
+ }
+ if(bps != enc->bits_per_sample && enc->bits_per_sample){
+ av_log(enc, AV_LOG_WARNING, "requested bits_per_sample (%d) and actually stored (%d) differ\n", enc->bits_per_sample, bps);
+ }
+
+ if (enc->codec_id == CODEC_ID_MP2 || enc->codec_id == CODEC_ID_MP3 || enc->codec_id == CODEC_ID_GSM_MS) {
+ blkalign = enc->frame_size; //this is wrong, but seems many demuxers dont work if this is set correctly
+ //blkalign = 144 * enc->bit_rate/enc->sample_rate;
+ } else if (enc->codec_id == CODEC_ID_ADPCM_G726) { //
+ blkalign = 1;
+ } else if (enc->block_align != 0) { /* specified by the codec */
+ blkalign = enc->block_align;
+ } else
+ blkalign = enc->channels*bps >> 3;
+ if (enc->codec_id == CODEC_ID_PCM_U8 ||
+ enc->codec_id == CODEC_ID_PCM_S24LE ||
+ enc->codec_id == CODEC_ID_PCM_S32LE ||
+ enc->codec_id == CODEC_ID_PCM_S16LE) {
+ bytespersec = enc->sample_rate * blkalign;
+ } else {
+ bytespersec = enc->bit_rate / 8;
+ }
+ put_le32(pb, bytespersec); /* bytes per second */
+ put_le16(pb, blkalign); /* block align */
+ put_le16(pb, bps); /* bits per sample */
+ if (enc->codec_id == CODEC_ID_MP3) {
+ put_le16(pb, 12); /* wav_extra_size */
+ hdrsize += 12;
+ put_le16(pb, 1); /* wID */
+ put_le32(pb, 2); /* fdwFlags */
+ put_le16(pb, 1152); /* nBlockSize */
+ put_le16(pb, 1); /* nFramesPerBlock */
+ put_le16(pb, 1393); /* nCodecDelay */
+ } else if (enc->codec_id == CODEC_ID_MP2) {
+ put_le16(pb, 22); /* wav_extra_size */
+ hdrsize += 22;
+ put_le16(pb, 2); /* fwHeadLayer */
+ put_le32(pb, enc->bit_rate); /* dwHeadBitrate */
+ put_le16(pb, enc->channels == 2 ? 1 : 8); /* fwHeadMode */
+ put_le16(pb, 0); /* fwHeadModeExt */
+ put_le16(pb, 1); /* wHeadEmphasis */
+ put_le16(pb, 16); /* fwHeadFlags */
+ put_le32(pb, 0); /* dwPTSLow */
+ put_le32(pb, 0); /* dwPTSHigh */
+ } else if (enc->codec_id == CODEC_ID_GSM_MS) {
+ put_le16(pb, 2); /* wav_extra_size */
+ hdrsize += 2;
+ put_le16(pb, enc->frame_size); /* wSamplesPerBlock */
+ } else if (enc->codec_id == CODEC_ID_ADPCM_IMA_WAV) {
+ put_le16(pb, 2); /* wav_extra_size */
+ hdrsize += 2;
+ put_le16(pb, enc->frame_size); /* wSamplesPerBlock */
+ } else if(enc->extradata_size){
+ put_le16(pb, enc->extradata_size);
+ put_buffer(pb, enc->extradata, enc->extradata_size);
+ hdrsize += enc->extradata_size;
+ if(hdrsize&1){
+ hdrsize++;
+ put_byte(pb, 0);
+ }
+ } else {
+ hdrsize -= 2;
+ }
+
+ return hdrsize;
+}
+
+/* BITMAPINFOHEADER header */
+void put_bmp_header(ByteIOContext *pb, AVCodecContext *enc, const AVCodecTag *tags, int for_asf)
+{
+ put_le32(pb, 40 + enc->extradata_size); /* size */
+ put_le32(pb, enc->width);
+ put_le32(pb, enc->height);
+ put_le16(pb, 1); /* planes */
+
+ put_le16(pb, enc->bits_per_sample ? enc->bits_per_sample : 24); /* depth */
+ /* compression type */
+ put_le32(pb, enc->codec_tag);
+ put_le32(pb, enc->width * enc->height * 3);
+ put_le32(pb, 0);
+ put_le32(pb, 0);
+ put_le32(pb, 0);
+ put_le32(pb, 0);
+
+ put_buffer(pb, enc->extradata, enc->extradata_size);
+
+ if (enc->extradata_size & 1)
+ put_byte(pb, 0);
+}
+#endif //CONFIG_MUXERS
+
+#ifdef CONFIG_DEMUXERS
+/* We could be given one of the three possible structures here:
+ * WAVEFORMAT, PCMWAVEFORMAT or WAVEFORMATEX. Each structure
+ * is an expansion of the previous one with the fields added
+ * at the bottom. PCMWAVEFORMAT adds 'WORD wBitsPerSample' and
+ * WAVEFORMATEX adds 'WORD cbSize' and basically makes itself
+ * an openended structure.
+ */
+void get_wav_header(ByteIOContext *pb, AVCodecContext *codec, int size)
+{
+ int id;
+
+ id = get_le16(pb);
+ codec->codec_type = CODEC_TYPE_AUDIO;
+ codec->codec_tag = id;
+ codec->channels = get_le16(pb);
+ codec->sample_rate = get_le32(pb);
+ codec->bit_rate = get_le32(pb) * 8;
+ codec->block_align = get_le16(pb);
+ if (size == 14) { /* We're dealing with plain vanilla WAVEFORMAT */
+ codec->bits_per_sample = 8;
+ }else
+ codec->bits_per_sample = get_le16(pb);
+ if (size >= 18) { /* We're obviously dealing with WAVEFORMATEX */
+ int cbSize = get_le16(pb); /* cbSize */
+ size -= 18;
+ cbSize = FFMIN(size, cbSize);
+ if (cbSize >= 22 && id == 0xfffe) { /* WAVEFORMATEXTENSIBLE */
+ codec->bits_per_sample = get_le16(pb);
+ get_le32(pb); /* dwChannelMask */
+ id = get_le32(pb); /* 4 first bytes of GUID */
+ url_fskip(pb, 12); /* skip end of GUID */
+ cbSize -= 22;
+ size -= 22;
+ }
+ codec->extradata_size = cbSize;
+ if (cbSize > 0) {
+ codec->extradata = av_mallocz(codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ get_buffer(pb, codec->extradata, codec->extradata_size);
+ size -= cbSize;
+ }
+
+ /* It is possible for the chunk to contain garbage at the end */
+ if (size > 0)
+ url_fskip(pb, size);
+ }
+ codec->codec_id = wav_codec_get_id(id, codec->bits_per_sample);
+}
+
+
+int wav_codec_get_id(unsigned int tag, int bps)
+{
+ int id;
+ id = codec_get_id(codec_wav_tags, tag);
+ if (id <= 0)
+ return id;
+ /* handle specific u8 codec */
+ if (id == CODEC_ID_PCM_S16LE && bps == 8)
+ id = CODEC_ID_PCM_U8;
+ if (id == CODEC_ID_PCM_S16LE && bps == 24)
+ id = CODEC_ID_PCM_S24LE;
+ if (id == CODEC_ID_PCM_S16LE && bps == 32)
+ id = CODEC_ID_PCM_S32LE;
+ return id;
+}
+#endif // CONFIG_DEMUXERS
+
+void ff_parse_specific_params(AVCodecContext *stream, int *au_rate, int *au_ssize, int *au_scale)
+{
+ int gcd;
+
+ *au_ssize= stream->block_align;
+ 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){
+ *au_scale= stream->time_base.num;
+ *au_rate = stream->time_base.den;
+ }else{
+ *au_scale= stream->block_align ? stream->block_align*8 : 8;
+ *au_rate = stream->bit_rate;
+ }
+ gcd= ff_gcd(*au_scale, *au_rate);
+ *au_scale /= gcd;
+ *au_rate /= gcd;
+}
diff --git a/contrib/ffmpeg/libavformat/riff.h b/contrib/ffmpeg/libavformat/riff.h
new file mode 100644
index 000000000..45c72dde6
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/riff.h
@@ -0,0 +1,55 @@
+/*
+ * RIFF codec tags
+ * copyright (c) 2000 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 riff.h
+ * internal header for RIFF based (de)muxers
+ * do NOT include this in end user applications
+ */
+
+#ifndef FF_RIFF_H
+#define FF_RIFF_H
+
+offset_t start_tag(ByteIOContext *pb, const char *tag);
+void end_tag(ByteIOContext *pb, offset_t start);
+
+typedef struct AVCodecTag {
+ int id;
+ unsigned int tag;
+} AVCodecTag;
+
+void put_bmp_header(ByteIOContext *pb, AVCodecContext *enc, const AVCodecTag *tags, int for_asf);
+int put_wav_header(ByteIOContext *pb, AVCodecContext *enc);
+int wav_codec_get_id(unsigned int tag, int bps);
+void get_wav_header(ByteIOContext *pb, AVCodecContext *codec, int size);
+
+extern const AVCodecTag codec_bmp_tags[];
+extern const AVCodecTag codec_wav_tags[];
+
+unsigned int codec_get_tag(const AVCodecTag *tags, int id);
+enum CodecID codec_get_id(const AVCodecTag *tags, unsigned int tag);
+unsigned int codec_get_bmp_tag(int id) attribute_deprecated; //use av_codec_get_tag
+unsigned int codec_get_wav_tag(int id) attribute_deprecated; //use av_codec_get_tag
+enum CodecID codec_get_bmp_id(unsigned int tag) attribute_deprecated; //use av_codec_get_id
+enum CodecID codec_get_wav_id(unsigned int tag) attribute_deprecated; //use av_codec_get_id
+void ff_parse_specific_params(AVCodecContext *stream, int *au_rate, int *au_ssize, int *au_scale);
+
+#endif
diff --git a/contrib/ffmpeg/libavformat/rm.c b/contrib/ffmpeg/libavformat/rm.c
new file mode 100644
index 000000000..ad2f5ff27
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/rm.c
@@ -0,0 +1,1147 @@
+/*
+ * "Real" compatible muxer and demuxer.
+ * Copyright (c) 2000, 2001 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 "avformat.h"
+
+/* in ms */
+#define BUFFER_DURATION 0
+
+typedef struct {
+ int nb_packets;
+ int packet_total_size;
+ int packet_max_size;
+ /* codec related output */
+ int bit_rate;
+ float frame_rate;
+ int nb_frames; /* current frame number */
+ int total_frames; /* total number of frames */
+ int num;
+ AVCodecContext *enc;
+} StreamInfo;
+
+typedef struct {
+ StreamInfo streams[2];
+ StreamInfo *audio_stream, *video_stream;
+ int data_pos; /* position of the data after the header */
+ int nb_packets;
+ int old_format;
+ int current_stream;
+ int remaining_len;
+ /// Audio descrambling matrix parameters
+ uint8_t *audiobuf; ///< place to store reordered audio data
+ int64_t audiotimestamp; ///< Audio packet timestamp
+ int sub_packet_cnt; // Subpacket counter, used while reading
+ int sub_packet_size, sub_packet_h, coded_framesize; ///< Descrambling parameters from container
+ int audio_stream_num; ///< Stream number for audio packets
+ int audio_pkt_cnt; ///< Output packet counter
+ int audio_framesize; /// Audio frame size from container
+ int sub_packet_lengths[16]; /// Length of each aac subpacket
+} RMContext;
+
+#ifdef CONFIG_MUXERS
+static void put_str(ByteIOContext *s, const char *tag)
+{
+ put_be16(s,strlen(tag));
+ while (*tag) {
+ put_byte(s, *tag++);
+ }
+}
+
+static void put_str8(ByteIOContext *s, const char *tag)
+{
+ put_byte(s, strlen(tag));
+ while (*tag) {
+ put_byte(s, *tag++);
+ }
+}
+
+static void rv10_write_header(AVFormatContext *ctx,
+ int data_size, int index_pos)
+{
+ RMContext *rm = ctx->priv_data;
+ ByteIOContext *s = &ctx->pb;
+ StreamInfo *stream;
+ unsigned char *data_offset_ptr, *start_ptr;
+ const char *desc, *mimetype;
+ int nb_packets, packet_total_size, packet_max_size, size, packet_avg_size, i;
+ int bit_rate, v, duration, flags, data_pos;
+
+ start_ptr = s->buf_ptr;
+
+ put_tag(s, ".RMF");
+ put_be32(s,18); /* header size */
+ put_be16(s,0);
+ put_be32(s,0);
+ put_be32(s,4 + ctx->nb_streams); /* num headers */
+
+ put_tag(s,"PROP");
+ put_be32(s, 50);
+ put_be16(s, 0);
+ packet_max_size = 0;
+ packet_total_size = 0;
+ nb_packets = 0;
+ bit_rate = 0;
+ duration = 0;
+ for(i=0;i<ctx->nb_streams;i++) {
+ StreamInfo *stream = &rm->streams[i];
+ bit_rate += stream->bit_rate;
+ if (stream->packet_max_size > packet_max_size)
+ packet_max_size = stream->packet_max_size;
+ nb_packets += stream->nb_packets;
+ packet_total_size += stream->packet_total_size;
+ /* select maximum duration */
+ v = (int) (1000.0 * (float)stream->total_frames / stream->frame_rate);
+ if (v > duration)
+ duration = v;
+ }
+ put_be32(s, bit_rate); /* max bit rate */
+ put_be32(s, bit_rate); /* avg bit rate */
+ put_be32(s, packet_max_size); /* max packet size */
+ if (nb_packets > 0)
+ packet_avg_size = packet_total_size / nb_packets;
+ else
+ packet_avg_size = 0;
+ put_be32(s, packet_avg_size); /* avg packet size */
+ put_be32(s, nb_packets); /* num packets */
+ put_be32(s, duration); /* duration */
+ put_be32(s, BUFFER_DURATION); /* preroll */
+ put_be32(s, index_pos); /* index offset */
+ /* computation of data the data offset */
+ data_offset_ptr = s->buf_ptr;
+ put_be32(s, 0); /* data offset : will be patched after */
+ put_be16(s, ctx->nb_streams); /* num streams */
+ flags = 1 | 2; /* save allowed & perfect play */
+ if (url_is_streamed(s))
+ flags |= 4; /* live broadcast */
+ put_be16(s, flags);
+
+ /* comments */
+
+ put_tag(s,"CONT");
+ size = strlen(ctx->title) + strlen(ctx->author) + strlen(ctx->copyright) +
+ strlen(ctx->comment) + 4 * 2 + 10;
+ put_be32(s,size);
+ put_be16(s,0);
+ put_str(s, ctx->title);
+ put_str(s, ctx->author);
+ put_str(s, ctx->copyright);
+ put_str(s, ctx->comment);
+
+ for(i=0;i<ctx->nb_streams;i++) {
+ int codec_data_size;
+
+ stream = &rm->streams[i];
+
+ if (stream->enc->codec_type == CODEC_TYPE_AUDIO) {
+ desc = "The Audio Stream";
+ mimetype = "audio/x-pn-realaudio";
+ codec_data_size = 73;
+ } else {
+ desc = "The Video Stream";
+ mimetype = "video/x-pn-realvideo";
+ codec_data_size = 34;
+ }
+
+ put_tag(s,"MDPR");
+ size = 10 + 9 * 4 + strlen(desc) + strlen(mimetype) + codec_data_size;
+ put_be32(s, size);
+ put_be16(s, 0);
+
+ put_be16(s, i); /* stream number */
+ put_be32(s, stream->bit_rate); /* max bit rate */
+ put_be32(s, stream->bit_rate); /* avg bit rate */
+ put_be32(s, stream->packet_max_size); /* max packet size */
+ if (stream->nb_packets > 0)
+ packet_avg_size = stream->packet_total_size /
+ stream->nb_packets;
+ else
+ packet_avg_size = 0;
+ put_be32(s, packet_avg_size); /* avg packet size */
+ put_be32(s, 0); /* start time */
+ put_be32(s, BUFFER_DURATION); /* preroll */
+ /* duration */
+ if (url_is_streamed(s) || !stream->total_frames)
+ put_be32(s, (int)(3600 * 1000));
+ else
+ put_be32(s, (int)(stream->total_frames * 1000 / stream->frame_rate));
+ put_str8(s, desc);
+ put_str8(s, mimetype);
+ put_be32(s, codec_data_size);
+
+ if (stream->enc->codec_type == CODEC_TYPE_AUDIO) {
+ int coded_frame_size, fscode, sample_rate;
+ sample_rate = stream->enc->sample_rate;
+ coded_frame_size = (stream->enc->bit_rate *
+ stream->enc->frame_size) / (8 * sample_rate);
+ /* audio codec info */
+ put_tag(s, ".ra");
+ put_byte(s, 0xfd);
+ put_be32(s, 0x00040000); /* version */
+ put_tag(s, ".ra4");
+ put_be32(s, 0x01b53530); /* stream length */
+ put_be16(s, 4); /* unknown */
+ put_be32(s, 0x39); /* header size */
+
+ switch(sample_rate) {
+ case 48000:
+ case 24000:
+ case 12000:
+ fscode = 1;
+ break;
+ default:
+ case 44100:
+ case 22050:
+ case 11025:
+ fscode = 2;
+ break;
+ case 32000:
+ case 16000:
+ case 8000:
+ fscode = 3;
+ }
+ put_be16(s, fscode); /* codec additional info, for AC3, seems
+ to be a frequency code */
+ /* special hack to compensate rounding errors... */
+ if (coded_frame_size == 557)
+ coded_frame_size--;
+ put_be32(s, coded_frame_size); /* frame length */
+ put_be32(s, 0x51540); /* unknown */
+ put_be32(s, 0x249f0); /* unknown */
+ put_be32(s, 0x249f0); /* unknown */
+ put_be16(s, 0x01);
+ /* frame length : seems to be very important */
+ put_be16(s, coded_frame_size);
+ put_be32(s, 0); /* unknown */
+ put_be16(s, stream->enc->sample_rate); /* sample rate */
+ put_be32(s, 0x10); /* unknown */
+ put_be16(s, stream->enc->channels);
+ put_str8(s, "Int0"); /* codec name */
+ put_str8(s, "dnet"); /* codec name */
+ put_be16(s, 0); /* title length */
+ put_be16(s, 0); /* author length */
+ put_be16(s, 0); /* copyright length */
+ put_byte(s, 0); /* end of header */
+ } else {
+ /* video codec info */
+ put_be32(s,34); /* size */
+ if(stream->enc->codec_id == CODEC_ID_RV10)
+ put_tag(s,"VIDORV10");
+ else
+ put_tag(s,"VIDORV20");
+ put_be16(s, stream->enc->width);
+ put_be16(s, stream->enc->height);
+ put_be16(s, (int) stream->frame_rate); /* frames per seconds ? */
+ put_be32(s,0); /* unknown meaning */
+ put_be16(s, (int) stream->frame_rate); /* unknown meaning */
+ put_be32(s,0); /* unknown meaning */
+ put_be16(s, 8); /* unknown meaning */
+ /* Seems to be the codec version: only use basic H263. The next
+ versions seems to add a diffential DC coding as in
+ MPEG... nothing new under the sun */
+ if(stream->enc->codec_id == CODEC_ID_RV10)
+ put_be32(s,0x10000000);
+ else
+ put_be32(s,0x20103001);
+ //put_be32(s,0x10003000);
+ }
+ }
+
+ /* patch data offset field */
+ data_pos = s->buf_ptr - start_ptr;
+ rm->data_pos = data_pos;
+ data_offset_ptr[0] = data_pos >> 24;
+ data_offset_ptr[1] = data_pos >> 16;
+ data_offset_ptr[2] = data_pos >> 8;
+ data_offset_ptr[3] = data_pos;
+
+ /* data stream */
+ put_tag(s,"DATA");
+ put_be32(s,data_size + 10 + 8);
+ put_be16(s,0);
+
+ put_be32(s, nb_packets); /* number of packets */
+ put_be32(s,0); /* next data header */
+}
+
+static void write_packet_header(AVFormatContext *ctx, StreamInfo *stream,
+ int length, int key_frame)
+{
+ int timestamp;
+ ByteIOContext *s = &ctx->pb;
+
+ stream->nb_packets++;
+ stream->packet_total_size += length;
+ if (length > stream->packet_max_size)
+ stream->packet_max_size = length;
+
+ put_be16(s,0); /* version */
+ put_be16(s,length + 12);
+ put_be16(s, stream->num); /* stream number */
+ timestamp = (1000 * (float)stream->nb_frames) / stream->frame_rate;
+ put_be32(s, timestamp); /* timestamp */
+ put_byte(s, 0); /* reserved */
+ put_byte(s, key_frame ? 2 : 0); /* flags */
+}
+
+static int rm_write_header(AVFormatContext *s)
+{
+ RMContext *rm = s->priv_data;
+ StreamInfo *stream;
+ int n;
+ AVCodecContext *codec;
+
+ for(n=0;n<s->nb_streams;n++) {
+ s->streams[n]->id = n;
+ codec = s->streams[n]->codec;
+ stream = &rm->streams[n];
+ memset(stream, 0, sizeof(StreamInfo));
+ stream->num = n;
+ stream->bit_rate = codec->bit_rate;
+ stream->enc = codec;
+
+ switch(codec->codec_type) {
+ case CODEC_TYPE_AUDIO:
+ rm->audio_stream = stream;
+ stream->frame_rate = (float)codec->sample_rate / (float)codec->frame_size;
+ /* XXX: dummy values */
+ stream->packet_max_size = 1024;
+ stream->nb_packets = 0;
+ stream->total_frames = stream->nb_packets;
+ break;
+ case CODEC_TYPE_VIDEO:
+ rm->video_stream = stream;
+ stream->frame_rate = (float)codec->time_base.den / (float)codec->time_base.num;
+ /* XXX: dummy values */
+ stream->packet_max_size = 4096;
+ stream->nb_packets = 0;
+ stream->total_frames = stream->nb_packets;
+ break;
+ default:
+ return -1;
+ }
+ }
+
+ rv10_write_header(s, 0, 0);
+ put_flush_packet(&s->pb);
+ return 0;
+}
+
+static int rm_write_audio(AVFormatContext *s, const uint8_t *buf, int size, int flags)
+{
+ uint8_t *buf1;
+ RMContext *rm = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ StreamInfo *stream = rm->audio_stream;
+ int i;
+
+ /* XXX: suppress this malloc */
+ buf1= (uint8_t*) av_malloc( size * sizeof(uint8_t) );
+
+ write_packet_header(s, stream, size, !!(flags & PKT_FLAG_KEY));
+
+ /* for AC3, the words seems to be reversed */
+ for(i=0;i<size;i+=2) {
+ buf1[i] = buf[i+1];
+ buf1[i+1] = buf[i];
+ }
+ put_buffer(pb, buf1, size);
+ put_flush_packet(pb);
+ stream->nb_frames++;
+ av_free(buf1);
+ return 0;
+}
+
+static int rm_write_video(AVFormatContext *s, const uint8_t *buf, int size, int flags)
+{
+ RMContext *rm = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ StreamInfo *stream = rm->video_stream;
+ int key_frame = !!(flags & PKT_FLAG_KEY);
+
+ /* XXX: this is incorrect: should be a parameter */
+
+ /* Well, I spent some time finding the meaning of these bits. I am
+ not sure I understood everything, but it works !! */
+#if 1
+ write_packet_header(s, stream, size + 7, key_frame);
+ /* bit 7: '1' if final packet of a frame converted in several packets */
+ put_byte(pb, 0x81);
+ /* bit 7: '1' if I frame. bits 6..0 : sequence number in current
+ frame starting from 1 */
+ if (key_frame) {
+ put_byte(pb, 0x81);
+ } else {
+ put_byte(pb, 0x01);
+ }
+ put_be16(pb, 0x4000 + (size)); /* total frame size */
+ put_be16(pb, 0x4000 + (size)); /* offset from the start or the end */
+#else
+ /* full frame */
+ write_packet_header(s, size + 6);
+ put_byte(pb, 0xc0);
+ put_be16(pb, 0x4000 + size); /* total frame size */
+ put_be16(pb, 0x4000 + packet_number * 126); /* position in stream */
+#endif
+ put_byte(pb, stream->nb_frames & 0xff);
+
+ put_buffer(pb, buf, size);
+ put_flush_packet(pb);
+
+ stream->nb_frames++;
+ return 0;
+}
+
+static int rm_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ if (s->streams[pkt->stream_index]->codec->codec_type ==
+ CODEC_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);
+}
+
+static int rm_write_trailer(AVFormatContext *s)
+{
+ RMContext *rm = s->priv_data;
+ int data_size, index_pos, i;
+ ByteIOContext *pb = &s->pb;
+
+ if (!url_is_streamed(&s->pb)) {
+ /* end of file: finish to write header */
+ index_pos = url_fseek(pb, 0, SEEK_CUR);
+ data_size = index_pos - rm->data_pos;
+
+ /* index */
+ put_tag(pb, "INDX");
+ put_be32(pb, 10 + 10 * s->nb_streams);
+ put_be16(pb, 0);
+
+ for(i=0;i<s->nb_streams;i++) {
+ put_be32(pb, 0); /* zero indices */
+ put_be16(pb, i); /* stream number */
+ put_be32(pb, 0); /* next index */
+ }
+ /* undocumented end header */
+ put_be32(pb, 0);
+ put_be32(pb, 0);
+
+ url_fseek(pb, 0, SEEK_SET);
+ for(i=0;i<s->nb_streams;i++)
+ rm->streams[i].total_frames = rm->streams[i].nb_frames;
+ rv10_write_header(s, data_size, index_pos);
+ } else {
+ /* undocumented end header */
+ put_be32(pb, 0);
+ put_be32(pb, 0);
+ }
+ put_flush_packet(pb);
+ return 0;
+}
+#endif //CONFIG_MUXERS
+
+/***************************************************/
+
+static void get_str(ByteIOContext *pb, char *buf, int buf_size)
+{
+ int len, i;
+ char *q;
+
+ len = get_be16(pb);
+ q = buf;
+ for(i=0;i<len;i++) {
+ if (i < buf_size - 1)
+ *q++ = get_byte(pb);
+ }
+ *q = '\0';
+}
+
+static void get_str8(ByteIOContext *pb, char *buf, int buf_size)
+{
+ int len, i;
+ char *q;
+
+ len = get_byte(pb);
+ q = buf;
+ for(i=0;i<len;i++) {
+ if (i < buf_size - 1)
+ *q++ = get_byte(pb);
+ }
+ *q = '\0';
+}
+
+static int rm_read_audio_stream_info(AVFormatContext *s, AVStream *st,
+ int read_all)
+{
+ RMContext *rm = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ char buf[256];
+ uint32_t version;
+ int i;
+
+ /* ra type header */
+ version = get_be32(pb); /* version */
+ if (((version >> 16) & 0xff) == 3) {
+ int64_t startpos = url_ftell(pb);
+ /* very old version */
+ for(i = 0; i < 14; i++)
+ get_byte(pb);
+ get_str8(pb, s->title, sizeof(s->title));
+ get_str8(pb, s->author, sizeof(s->author));
+ get_str8(pb, s->copyright, sizeof(s->copyright));
+ get_str8(pb, s->comment, sizeof(s->comment));
+ if ((startpos + (version & 0xffff)) >= 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));
+ st->codec->sample_rate = 8000;
+ st->codec->channels = 1;
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_id = CODEC_ID_RA_144;
+ } else {
+ int flavor, sub_packet_h, coded_framesize, sub_packet_size;
+ /* old version (4) */
+ get_be32(pb); /* .ra4 */
+ get_be32(pb); /* data size */
+ get_be16(pb); /* version2 */
+ get_be32(pb); /* header size */
+ flavor= get_be16(pb); /* add codec info / flavor */
+ rm->coded_framesize = coded_framesize = get_be32(pb); /* coded frame size */
+ get_be32(pb); /* ??? */
+ get_be32(pb); /* ??? */
+ get_be32(pb); /* ??? */
+ rm->sub_packet_h = sub_packet_h = get_be16(pb); /* 1 */
+ st->codec->block_align= get_be16(pb); /* frame size */
+ rm->sub_packet_size = sub_packet_size = get_be16(pb); /* sub packet size */
+ get_be16(pb); /* ??? */
+ if (((version >> 16) & 0xff) == 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) {
+ get_be32(pb);
+ buf[0] = get_byte(pb);
+ buf[1] = get_byte(pb);
+ buf[2] = get_byte(pb);
+ buf[3] = get_byte(pb);
+ buf[4] = 0;
+ } else {
+ 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;
+ } else if (!strcmp(buf, "28_8")) {
+ st->codec->codec_id = CODEC_ID_RA_288;
+ st->codec->extradata_size= 0;
+ rm->audio_framesize = st->codec->block_align;
+ st->codec->block_align = coded_framesize;
+
+ if(rm->audio_framesize >= UINT_MAX / sub_packet_h){
+ av_log(s, AV_LOG_ERROR, "rm->audio_framesize * sub_packet_h too large\n");
+ return -1;
+ }
+
+ rm->audiobuf = av_malloc(rm->audio_framesize * sub_packet_h);
+ } else if (!strcmp(buf, "cook")) {
+ int codecdata_length, i;
+ get_be16(pb); get_byte(pb);
+ if (((version >> 16) & 0xff) == 5)
+ get_byte(pb);
+ codecdata_length = get_be32(pb);
+ if(codecdata_length + FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)codecdata_length){
+ av_log(s, AV_LOG_ERROR, "codecdata_length too large\n");
+ return -1;
+ }
+
+ st->codec->codec_id = CODEC_ID_COOK;
+ st->codec->extradata_size= codecdata_length;
+ st->codec->extradata= av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ for(i = 0; i < codecdata_length; i++)
+ ((uint8_t*)st->codec->extradata)[i] = get_byte(pb);
+ rm->audio_framesize = st->codec->block_align;
+ st->codec->block_align = rm->sub_packet_size;
+
+ if(rm->audio_framesize >= UINT_MAX / sub_packet_h){
+ av_log(s, AV_LOG_ERROR, "rm->audio_framesize * sub_packet_h too large\n");
+ return -1;
+ }
+
+ rm->audiobuf = av_malloc(rm->audio_framesize * sub_packet_h);
+ } else if (!strcmp(buf, "raac") || !strcmp(buf, "racp")) {
+ int codecdata_length, i;
+ get_be16(pb); get_byte(pb);
+ if (((version >> 16) & 0xff) == 5)
+ get_byte(pb);
+ st->codec->codec_id = CODEC_ID_AAC;
+ codecdata_length = get_be32(pb);
+ if(codecdata_length + FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)codecdata_length){
+ av_log(s, AV_LOG_ERROR, "codecdata_length too large\n");
+ 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);
+ for(i = 0; i < st->codec->extradata_size; i++)
+ ((uint8_t*)st->codec->extradata)[i] = get_byte(pb);
+ }
+ } else {
+ st->codec->codec_id = CODEC_ID_NONE;
+ pstrcpy(st->codec->codec_name, sizeof(st->codec->codec_name),
+ buf);
+ }
+ if (read_all) {
+ get_byte(pb);
+ get_byte(pb);
+ get_byte(pb);
+
+ get_str8(pb, s->title, sizeof(s->title));
+ get_str8(pb, s->author, sizeof(s->author));
+ get_str8(pb, s->copyright, sizeof(s->copyright));
+ get_str8(pb, s->comment, sizeof(s->comment));
+ }
+ }
+ return 0;
+}
+
+static int rm_read_header_old(AVFormatContext *s, AVFormatParameters *ap)
+{
+ RMContext *rm = s->priv_data;
+ AVStream *st;
+
+ rm->old_format = 1;
+ st = av_new_stream(s, 0);
+ if (!st)
+ return -1;
+ return rm_read_audio_stream_info(s, st, 1);
+}
+
+static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+ RMContext *rm = s->priv_data;
+ AVStream *st;
+ ByteIOContext *pb = &s->pb;
+ unsigned int tag, v;
+ int tag_size, size, codec_data_size, i;
+ int64_t codec_pos;
+ unsigned int start_time, duration;
+ char buf[128];
+ int flags = 0;
+
+ tag = get_le32(pb);
+ if (tag == MKTAG('.', 'r', 'a', 0xfd)) {
+ /* very old .ra format */
+ return rm_read_header_old(s, ap);
+ } else if (tag != MKTAG('.', 'R', 'M', 'F')) {
+ return AVERROR_IO;
+ }
+
+ get_be32(pb); /* header size */
+ get_be16(pb);
+ get_be32(pb);
+ get_be32(pb); /* number of headers */
+
+ for(;;) {
+ if (url_feof(pb))
+ goto fail;
+ tag = get_le32(pb);
+ tag_size = get_be32(pb);
+ get_be16(pb);
+#if 0
+ printf("tag=%c%c%c%c (%08x) size=%d\n",
+ (tag) & 0xff,
+ (tag >> 8) & 0xff,
+ (tag >> 16) & 0xff,
+ (tag >> 24) & 0xff,
+ tag,
+ tag_size);
+#endif
+ if (tag_size < 10 && tag != MKTAG('D', 'A', 'T', 'A'))
+ goto fail;
+ switch(tag) {
+ case MKTAG('P', 'R', 'O', 'P'):
+ /* file header */
+ get_be32(pb); /* max bit rate */
+ get_be32(pb); /* avg bit rate */
+ get_be32(pb); /* max packet size */
+ get_be32(pb); /* avg packet size */
+ get_be32(pb); /* nb packets */
+ get_be32(pb); /* duration */
+ get_be32(pb); /* preroll */
+ get_be32(pb); /* index offset */
+ get_be32(pb); /* data offset */
+ get_be16(pb); /* nb streams */
+ flags = get_be16(pb); /* flags */
+ break;
+ case MKTAG('C', 'O', 'N', 'T'):
+ get_str(pb, s->title, sizeof(s->title));
+ get_str(pb, s->author, sizeof(s->author));
+ get_str(pb, s->copyright, sizeof(s->copyright));
+ get_str(pb, s->comment, sizeof(s->comment));
+ break;
+ case MKTAG('M', 'D', 'P', 'R'):
+ st = av_new_stream(s, 0);
+ if (!st)
+ goto fail;
+ st->id = get_be16(pb);
+ get_be32(pb); /* max bit rate */
+ st->codec->bit_rate = get_be32(pb); /* bit rate */
+ get_be32(pb); /* max packet size */
+ get_be32(pb); /* avg packet size */
+ start_time = get_be32(pb); /* start time */
+ get_be32(pb); /* preroll */
+ duration = get_be32(pb); /* duration */
+ st->start_time = start_time;
+ st->duration = duration;
+ get_str8(pb, buf, sizeof(buf)); /* desc */
+ get_str8(pb, buf, sizeof(buf)); /* mimetype */
+ codec_data_size = get_be32(pb);
+ codec_pos = url_ftell(pb);
+ st->codec->codec_type = CODEC_TYPE_DATA;
+ av_set_pts_info(st, 64, 1, 1000);
+
+ v = get_be32(pb);
+ if (v == MKTAG(0xfd, 'a', 'r', '.')) {
+ /* ra type header */
+ if (rm_read_audio_stream_info(s, st, 0))
+ return -1;
+ } else {
+ int fps, fps2;
+ if (get_le32(pb) != MKTAG('V', 'I', 'D', 'O')) {
+ fail1:
+ av_log(st->codec, AV_LOG_ERROR, "Unsupported video codec\n");
+ goto skip;
+ }
+ st->codec->codec_tag = get_le32(pb);
+// av_log(NULL, 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'))
+ 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;
+ 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);
+ get_buffer(pb, st->codec->extradata, st->codec->extradata_size);
+
+// av_log(NULL, 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){
+ 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;
+ }
+ }
+skip:
+ /* skip codec info */
+ size = url_ftell(pb) - codec_pos;
+ url_fskip(pb, codec_data_size - size);
+ break;
+ case MKTAG('D', 'A', 'T', 'A'):
+ goto header_end;
+ default:
+ /* unknown tag: skip it */
+ url_fskip(pb, tag_size - 10);
+ break;
+ }
+ }
+ header_end:
+ rm->nb_packets = get_be32(pb); /* number of packets */
+ if (!rm->nb_packets && (flags & 4))
+ rm->nb_packets = 3600 * 25;
+ get_be32(pb); /* next data header */
+ return 0;
+
+ fail:
+ for(i=0;i<s->nb_streams;i++) {
+ av_free(s->streams[i]);
+ }
+ return AVERROR_IO;
+}
+
+static int get_num(ByteIOContext *pb, int *len)
+{
+ int n, n1;
+
+ n = get_be16(pb);
+ (*len)-=2;
+ if (n >= 0x4000) {
+ return n - 0x4000;
+ } else {
+ n1 = get_be16(pb);
+ (*len)-=2;
+ return (n << 16) | n1;
+ }
+}
+
+/* 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){
+ RMContext *rm = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ int len, num, res, i;
+ AVStream *st;
+ uint32_t state=0xFFFFFFFF;
+
+ while(!url_feof(pb)){
+ *pos= url_ftell(pb);
+ if(rm->remaining_len > 0){
+ num= rm->current_stream;
+ len= rm->remaining_len;
+ *timestamp = AV_NOPTS_VALUE;
+ *flags= 0;
+ }else{
+ state= (state<<8) + get_byte(pb);
+
+ if(state == MKBETAG('I', 'N', 'D', 'X')){
+ len = get_be16(pb) - 6;
+ if(len<0)
+ continue;
+ goto skip;
+ }
+
+ if(state > (unsigned)0xFFFF || state < 12)
+ continue;
+ len=state;
+ state= 0xFFFFFFFF;
+
+ num = get_be16(pb);
+ *timestamp = get_be32(pb);
+ res= get_byte(pb); /* reserved */
+ *flags = get_byte(pb); /* flags */
+
+
+ len -= 12;
+ }
+ for(i=0;i<s->nb_streams;i++) {
+ st = s->streams[i];
+ if (num == st->id)
+ break;
+ }
+ if (i == s->nb_streams) {
+skip:
+ /* skip packet if unknown number */
+ url_fskip(pb, len);
+ rm->remaining_len -= len;
+ continue;
+ }
+ *stream_index= i;
+
+ return len;
+ }
+ return -1;
+}
+
+static int rm_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ RMContext *rm = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ AVStream *st;
+ int i, len, tmp, j;
+ int64_t timestamp, pos;
+ uint8_t *ptr;
+ int flags;
+
+ if (rm->audio_pkt_cnt) {
+ // If there are queued audio packet return them first
+ st = s->streams[rm->audio_stream_num];
+ if (st->codec->codec_id == CODEC_ID_AAC)
+ av_get_packet(pb, pkt, rm->sub_packet_lengths[rm->sub_packet_cnt - rm->audio_pkt_cnt]);
+ else {
+ av_new_packet(pkt, st->codec->block_align);
+ memcpy(pkt->data, rm->audiobuf + st->codec->block_align *
+ (rm->sub_packet_h * rm->audio_framesize / st->codec->block_align - rm->audio_pkt_cnt),
+ st->codec->block_align);
+ }
+ rm->audio_pkt_cnt--;
+ pkt->flags = 0;
+ pkt->stream_index = rm->audio_stream_num;
+ } else if (rm->old_format) {
+ st = s->streams[0];
+ if (st->codec->codec_id == CODEC_ID_RA_288) {
+ int x, y;
+
+ for (y = 0; y < rm->sub_packet_h; y++)
+ for (x = 0; x < rm->sub_packet_h/2; x++)
+ if (get_buffer(pb, rm->audiobuf+x*2*rm->audio_framesize+y*rm->coded_framesize, rm->coded_framesize) <= 0)
+ return AVERROR_IO;
+ rm->audio_stream_num = 0;
+ rm->audio_pkt_cnt = rm->sub_packet_h * rm->audio_framesize / st->codec->block_align - 1;
+ // Release first audio packet
+ av_new_packet(pkt, st->codec->block_align);
+ memcpy(pkt->data, rm->audiobuf, st->codec->block_align);
+ pkt->flags |= PKT_FLAG_KEY; // Mark first packet as keyframe
+ pkt->stream_index = 0;
+ } else {
+ /* just read raw bytes */
+ len = RAW_PACKET_SIZE;
+ len= av_get_packet(pb, pkt, len);
+ pkt->stream_index = 0;
+ if (len <= 0) {
+ return AVERROR_IO;
+ }
+ pkt->size = len;
+ }
+ } else {
+ int seq=1;
+resync:
+ len=sync(s, &timestamp, &flags, &i, &pos);
+ if(len<0)
+ return AVERROR_IO;
+ st = s->streams[i];
+
+ if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
+ int h, pic_num, len2, pos;
+
+ h= get_byte(pb); len--;
+ if(!(h & 0x40)){
+ seq = get_byte(pb); len--;
+ }
+
+ if((h & 0xc0) == 0x40){
+ len2= pos= 0;
+ }else{
+ len2 = get_num(pb, &len);
+ pos = get_num(pb, &len);
+ }
+ /* picture number */
+ pic_num= get_byte(pb); len--;
+ rm->remaining_len= len;
+ rm->current_stream= st->id;
+
+// av_log(NULL, AV_LOG_DEBUG, "%X len:%d pos:%d len2:%d pic_num:%d\n",h, len, pos, len2, pic_num);
+ if(len2 && len2<len)
+ len=len2;
+ rm->remaining_len-= len;
+ av_get_packet(pb, pkt, len);
+
+ } else if (st->codec->codec_type == CODEC_TYPE_AUDIO) {
+ if ((st->codec->codec_id == CODEC_ID_RA_288) ||
+ (st->codec->codec_id == CODEC_ID_COOK)) {
+ int x;
+ int sps = rm->sub_packet_size;
+ int cfs = rm->coded_framesize;
+ int h = rm->sub_packet_h;
+ int y = rm->sub_packet_cnt;
+ int w = rm->audio_framesize;
+
+ if (flags & 2)
+ y = rm->sub_packet_cnt = 0;
+ if (!y)
+ rm->audiotimestamp = timestamp;
+
+ switch(st->codec->codec_id) {
+ case CODEC_ID_RA_288:
+ for (x = 0; x < h/2; x++)
+ get_buffer(pb, rm->audiobuf+x*2*w+y*cfs, cfs);
+ break;
+ case CODEC_ID_COOK:
+ for (x = 0; x < w/sps; x++)
+ get_buffer(pb, rm->audiobuf+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), sps);
+ break;
+ }
+
+ if (++(rm->sub_packet_cnt) < h)
+ goto resync;
+ else {
+ rm->sub_packet_cnt = 0;
+ rm->audio_stream_num = i;
+ rm->audio_pkt_cnt = h * w / st->codec->block_align - 1;
+ // Release first audio packet
+ av_new_packet(pkt, st->codec->block_align);
+ memcpy(pkt->data, rm->audiobuf, st->codec->block_align);
+ timestamp = rm->audiotimestamp;
+ flags = 2; // Mark first packet as keyframe
+ }
+ } else if (st->codec->codec_id == CODEC_ID_AAC) {
+ int x;
+ rm->audio_stream_num = i;
+ rm->sub_packet_cnt = (get_be16(pb) & 0xf0) >> 4;
+ if (rm->sub_packet_cnt) {
+ for (x = 0; x < rm->sub_packet_cnt; x++)
+ rm->sub_packet_lengths[x] = get_be16(pb);
+ // Release first audio packet
+ rm->audio_pkt_cnt = rm->sub_packet_cnt - 1;
+ av_get_packet(pb, pkt, rm->sub_packet_lengths[0]);
+ flags = 2; // Mark first packet as keyframe
+ }
+ } else
+ av_get_packet(pb, pkt, len);
+
+ } else
+ av_get_packet(pb, pkt, len);
+
+ if( (st->discard >= AVDISCARD_NONKEY && !(flags&2))
+ || st->discard >= AVDISCARD_ALL){
+ av_free_packet(pkt);
+ goto resync;
+ }
+
+ pkt->stream_index = i;
+
+#if 0
+ if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
+ if(st->codec->codec_id == CODEC_ID_RV20){
+ int seq= 128*(pkt->data[2]&0x7F) + (pkt->data[3]>>1);
+ av_log(NULL, AV_LOG_DEBUG, "%d %"PRId64" %d\n", timestamp, timestamp*512LL/25, seq);
+
+ seq |= (timestamp&~0x3FFF);
+ if(seq - timestamp > 0x2000) seq -= 0x4000;
+ if(seq - timestamp < -0x2000) seq += 0x4000;
+ }
+ }
+#endif
+ pkt->pts= timestamp;
+ if(flags&2){
+ pkt->flags |= PKT_FLAG_KEY;
+ if((seq&0x7F) == 1)
+ av_add_index_entry(st, pos, timestamp, 0, 0, AVINDEX_KEYFRAME);
+ }
+ }
+
+ /* for AC3, needs to swap bytes */
+ if (st->codec->codec_id == CODEC_ID_AC3) {
+ ptr = pkt->data;
+ for(j=0;j<len;j+=2) {
+ tmp = ptr[0];
+ ptr[0] = ptr[1];
+ ptr[1] = tmp;
+ ptr += 2;
+ }
+ }
+ return 0;
+}
+
+static int rm_read_close(AVFormatContext *s)
+{
+ RMContext *rm = s->priv_data;
+
+ av_free(rm->audiobuf);
+ return 0;
+}
+
+static int rm_probe(AVProbeData *p)
+{
+ /* check file header */
+ if (p->buf_size <= 32)
+ return 0;
+ if ((p->buf[0] == '.' && p->buf[1] == 'R' &&
+ p->buf[2] == 'M' && p->buf[3] == 'F' &&
+ p->buf[4] == 0 && p->buf[5] == 0) ||
+ (p->buf[0] == '.' && p->buf[1] == 'r' &&
+ p->buf[2] == 'a' && p->buf[3] == 0xfd))
+ return AVPROBE_SCORE_MAX;
+ else
+ return 0;
+}
+
+static int64_t rm_read_dts(AVFormatContext *s, int stream_index,
+ int64_t *ppos, int64_t pos_limit)
+{
+ RMContext *rm = s->priv_data;
+ int64_t pos, dts;
+ int stream_index2, flags, len, h;
+
+ pos = *ppos;
+
+ if(rm->old_format)
+ return AV_NOPTS_VALUE;
+
+ url_fseek(&s->pb, pos, SEEK_SET);
+ rm->remaining_len=0;
+ for(;;){
+ int seq=1;
+ AVStream *st;
+
+ len=sync(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) {
+ h= get_byte(&s->pb); len--;
+ if(!(h & 0x40)){
+ seq = get_byte(&s->pb); len--;
+ }
+ }
+
+ if((flags&2) && (seq&0x7F) == 1){
+// av_log(s, AV_LOG_DEBUG, "%d %d-%d %"PRId64" %d\n", flags, stream_index2, stream_index, dts, seq);
+ av_add_index_entry(st, pos, dts, 0, 0, AVINDEX_KEYFRAME);
+ if(stream_index2 == stream_index)
+ break;
+ }
+
+ url_fskip(&s->pb, len);
+ }
+ *ppos = pos;
+ return dts;
+}
+
+#ifdef CONFIG_RM_DEMUXER
+AVInputFormat rm_demuxer = {
+ "rm",
+ "rm format",
+ sizeof(RMContext),
+ rm_probe,
+ rm_read_header,
+ rm_read_packet,
+ rm_read_close,
+ NULL,
+ rm_read_dts,
+};
+#endif
+#ifdef CONFIG_RM_MUXER
+AVOutputFormat rm_muxer = {
+ "rm",
+ "rm format",
+ "application/vnd.rn-realmedia",
+ "rm,ra",
+ sizeof(RMContext),
+ CODEC_ID_AC3,
+ CODEC_ID_RV10,
+ rm_write_header,
+ rm_write_packet,
+ rm_write_trailer,
+};
+#endif
diff --git a/contrib/ffmpeg/libavformat/rtp.c b/contrib/ffmpeg/libavformat/rtp.c
new file mode 100644
index 000000000..493a89cf3
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/rtp.c
@@ -0,0 +1,1085 @@
+/*
+ * RTP input/output format
+ * 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
+ */
+#include "avformat.h"
+#include "mpegts.h"
+#include "bitstream.h"
+
+#include <unistd.h>
+#include "network.h"
+
+#include "rtp_internal.h"
+#include "rtp_h264.h"
+
+//#define DEBUG
+
+
+/* TODO: - add RTCP statistics reporting (should be optional).
+
+ - add support for h263/mpeg4 packetized output : IDEA: send a
+ buffer to 'rtp_write_packet' contains all the packets for ONE
+ frame. Each packet should have a four byte header containing
+ the length in big endian format (same trick as
+ 'url_open_dyn_packet_buf')
+*/
+
+/* from http://www.iana.org/assignments/rtp-parameters last updated 05 January 2005 */
+AVRtpPayloadType_t AVRtpPayloadTypes[]=
+{
+ {0, "PCMU", CODEC_TYPE_AUDIO, CODEC_ID_PCM_MULAW, 8000, 1},
+ {1, "Reserved", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {2, "Reserved", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -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, 90000, -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},
+ {19, "reserved", CODEC_TYPE_AUDIO, CODEC_ID_NONE, -1, -1},
+ {20, "unassigned", CODEC_TYPE_AUDIO, CODEC_ID_NONE, -1, -1},
+ {21, "unassigned", CODEC_TYPE_AUDIO, CODEC_ID_NONE, -1, -1},
+ {22, "unassigned", CODEC_TYPE_AUDIO, CODEC_ID_NONE, -1, -1},
+ {23, "unassigned", CODEC_TYPE_AUDIO, CODEC_ID_NONE, -1, -1},
+ {24, "unassigned", CODEC_TYPE_VIDEO, CODEC_ID_NONE, -1, -1},
+ {25, "CelB", CODEC_TYPE_VIDEO, CODEC_ID_NONE, 90000, -1},
+ {26, "JPEG", CODEC_TYPE_VIDEO, CODEC_ID_MJPEG, 90000, -1},
+ {27, "unassigned", CODEC_TYPE_VIDEO, CODEC_ID_NONE, -1, -1},
+ {28, "nv", CODEC_TYPE_VIDEO, CODEC_ID_NONE, 90000, -1},
+ {29, "unassigned", CODEC_TYPE_VIDEO, CODEC_ID_NONE, -1, -1},
+ {30, "unassigned", CODEC_TYPE_VIDEO, CODEC_ID_NONE, -1, -1},
+ {31, "H261", CODEC_TYPE_VIDEO, CODEC_ID_H261, 90000, -1},
+ {32, "MPV", CODEC_TYPE_VIDEO, CODEC_ID_MPEG1VIDEO, 90000, -1},
+ {33, "MP2T", CODEC_TYPE_DATA, CODEC_ID_MPEG2TS, 90000, -1},
+ {34, "H263", CODEC_TYPE_VIDEO, CODEC_ID_H263, 90000, -1},
+ {35, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {36, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {37, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {38, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {39, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {40, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {41, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {42, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {43, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {44, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {45, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {46, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {47, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {48, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {49, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {50, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {51, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {52, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {53, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {54, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {55, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {56, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {57, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {58, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {59, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {60, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {61, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {62, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {63, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {64, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {65, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {66, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {67, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {68, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {69, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {70, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {71, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {72, "reserved for RTCP conflict avoidance", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {73, "reserved for RTCP conflict avoidance", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {74, "reserved for RTCP conflict avoidance", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {75, "reserved for RTCP conflict avoidance", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {76, "reserved for RTCP conflict avoidance", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {77, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {78, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {79, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {80, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {81, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {82, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {83, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {84, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {85, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {86, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {87, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {88, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {89, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {90, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {91, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {92, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {93, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {94, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {95, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {96, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {97, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {98, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {99, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {100, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {101, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {102, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {103, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {104, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {105, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {106, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {107, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {108, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {109, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {110, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {111, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {112, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {113, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {114, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {115, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {116, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {117, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {118, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {119, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {120, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {121, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {122, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {123, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {124, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {125, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {126, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {127, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1},
+ {-1, "", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}
+};
+
+/* 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 void register_dynamic_payload_handler(RTPDynamicProtocolHandler *handler)
+{
+ handler->next= RTPFirstDynamicPayloadHandler;
+ RTPFirstDynamicPayloadHandler= handler;
+}
+
+void av_register_rtp_dynamic_payload_handlers()
+{
+ register_dynamic_payload_handler(&mp4v_es_handler);
+ register_dynamic_payload_handler(&mpeg4_generic_handler);
+ register_dynamic_payload_handler(&ff_h264_dynamic_handler);
+}
+
+int rtp_get_codec_info(AVCodecContext *codec, int payload_type)
+{
+ if (AVRtpPayloadTypes[payload_type].codec_id != CODEC_ID_NONE) {
+ codec->codec_type = AVRtpPayloadTypes[payload_type].codec_type;
+ codec->codec_id = AVRtpPayloadTypes[payload_type].codec_id;
+ if (AVRtpPayloadTypes[payload_type].audio_channels > 0)
+ codec->channels = AVRtpPayloadTypes[payload_type].audio_channels;
+ if (AVRtpPayloadTypes[payload_type].clock_rate > 0)
+ codec->sample_rate = AVRtpPayloadTypes[payload_type].clock_rate;
+ return 0;
+ }
+ return -1;
+}
+
+int rtp_get_payload_type(AVCodecContext *codec)
+{
+ int i, payload_type;
+
+ /* compute the payload type */
+ for (payload_type = -1, i = 0; AVRtpPayloadTypes[i].pt >= 0; ++i)
+ if (AVRtpPayloadTypes[i].codec_id == codec->codec_id) {
+ if (codec->codec_id == CODEC_ID_PCM_S16BE)
+ if (codec->channels != AVRtpPayloadTypes[i].audio_channels)
+ continue;
+ payload_type = AVRtpPayloadTypes[i].pt;
+ }
+ return payload_type;
+}
+
+static inline uint32_t decode_be32(const uint8_t *p)
+{
+ return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
+}
+
+static inline uint64_t decode_be64(const uint8_t *p)
+{
+ return ((uint64_t)decode_be32(p) << 32) | decode_be32(p + 4);
+}
+
+static int rtcp_parse_packet(RTPDemuxContext *s, const unsigned char *buf, int len)
+{
+ if (buf[1] != 200)
+ return -1;
+ s->last_rtcp_ntp_time = decode_be64(buf + 8);
+ if (s->first_rtcp_ntp_time == AV_NOPTS_VALUE)
+ s->first_rtcp_ntp_time = s->last_rtcp_ntp_time;
+ s->last_rtcp_timestamp = decode_be32(buf + 16);
+ return 0;
+}
+
+#define RTP_SEQ_MOD (1<<16)
+
+/**
+* called on parse open packet
+*/
+static void rtp_init_statistics(RTPStatistics *s, uint16_t base_sequence) // called on parse open packet.
+{
+ memset(s, 0, sizeof(RTPStatistics));
+ s->max_seq= base_sequence;
+ s->probation= 1;
+}
+
+/**
+* called whenever there is a large jump in sequence numbers, or when they get out of probation...
+*/
+static void rtp_init_sequence(RTPStatistics *s, uint16_t seq)
+{
+ s->max_seq= seq;
+ s->cycles= 0;
+ s->base_seq= seq -1;
+ s->bad_seq= RTP_SEQ_MOD + 1;
+ s->received= 0;
+ s->expected_prior= 0;
+ s->received_prior= 0;
+ s->jitter= 0;
+ s->transit= 0;
+}
+
+/**
+* returns 1 if we should handle this packet.
+*/
+static int rtp_valid_packet_in_sequence(RTPStatistics *s, uint16_t seq)
+{
+ uint16_t udelta= seq - s->max_seq;
+ const int MAX_DROPOUT= 3000;
+ const int MAX_MISORDER = 100;
+ const int MIN_SEQUENTIAL = 2;
+
+ /* source not valid until MIN_SEQUENTIAL packets with sequence seq. numbers have been received */
+ if(s->probation)
+ {
+ if(seq==s->max_seq + 1) {
+ s->probation--;
+ s->max_seq= seq;
+ if(s->probation==0) {
+ rtp_init_sequence(s, seq);
+ s->received++;
+ return 1;
+ }
+ } else {
+ s->probation= MIN_SEQUENTIAL - 1;
+ s->max_seq = seq;
+ }
+ } else if (udelta < MAX_DROPOUT) {
+ // in order, with permissible gap
+ if(seq < s->max_seq) {
+ //sequence number wrapped; count antother 64k cycles
+ s->cycles += RTP_SEQ_MOD;
+ }
+ s->max_seq= seq;
+ } else if (udelta <= RTP_SEQ_MOD - MAX_MISORDER) {
+ // sequence made a large jump...
+ if(seq==s->bad_seq) {
+ // two sequential packets-- assume that the other side restarted without telling us; just resync.
+ rtp_init_sequence(s, seq);
+ } else {
+ s->bad_seq= (seq + 1) & (RTP_SEQ_MOD-1);
+ return 0;
+ }
+ } else {
+ // duplicate or reordered packet...
+ }
+ s->received++;
+ return 1;
+}
+
+#if 0
+/**
+* This function is currently unused; without a valid local ntp time, I don't see how we could calculate the
+* difference between the arrival and sent timestamp. As a result, the jitter and transit statistics values
+* never change. I left this in in case someone else can see a way. (rdm)
+*/
+static void rtcp_update_jitter(RTPStatistics *s, uint32_t sent_timestamp, uint32_t arrival_timestamp)
+{
+ uint32_t transit= arrival_timestamp - sent_timestamp;
+ int d;
+ s->transit= transit;
+ d= FFABS(transit - s->transit);
+ s->jitter += d - ((s->jitter + 8)>>4);
+}
+#endif
+
+int rtp_check_and_send_back_rr(RTPDemuxContext *s, int count)
+{
+ ByteIOContext pb;
+ uint8_t *buf;
+ int len;
+ int rtcp_bytes;
+ RTPStatistics *stats= &s->statistics;
+ uint32_t lost;
+ uint32_t extended_max;
+ uint32_t expected_interval;
+ uint32_t received_interval;
+ uint32_t lost_interval;
+ uint32_t expected;
+ uint32_t fraction;
+ uint64_t ntp_time= s->last_rtcp_ntp_time; // TODO: Get local ntp time?
+
+ if (!s->rtp_ctx || (count < 1))
+ return -1;
+
+ /* TODO: I think this is way too often; RFC 1889 has algorithm for this */
+ /* XXX: mpeg pts hardcoded. RTCP send every 0.5 seconds */
+ s->octet_count += count;
+ rtcp_bytes = ((s->octet_count - s->last_octet_count) * RTCP_TX_RATIO_NUM) /
+ RTCP_TX_RATIO_DEN;
+ rtcp_bytes /= 50; // mmu_man: that's enough for me... VLC sends much less btw !?
+ if (rtcp_bytes < 28)
+ return -1;
+ s->last_octet_count = s->octet_count;
+
+ if (url_open_dyn_buf(&pb) < 0)
+ return -1;
+
+ // Receiver Report
+ put_byte(&pb, (RTP_VERSION << 6) + 1); /* 1 report block */
+ put_byte(&pb, 201);
+ put_be16(&pb, 7); /* length in words - 1 */
+ put_be32(&pb, s->ssrc); // our own SSRC
+ put_be32(&pb, s->ssrc); // XXX: should be the server's here!
+ // some placeholders we should really fill...
+ // RFC 1889/p64
+ extended_max= stats->cycles + stats->max_seq;
+ expected= extended_max - stats->base_seq + 1;
+ lost= expected - stats->received;
+ lost= FFMIN(lost, 0xffffff); // clamp it since it's only 24 bits...
+ expected_interval= expected - stats->expected_prior;
+ stats->expected_prior= expected;
+ received_interval= stats->received - stats->received_prior;
+ stats->received_prior= stats->received;
+ lost_interval= expected_interval - received_interval;
+ if (expected_interval==0 || lost_interval<=0) fraction= 0;
+ else fraction = (lost_interval<<8)/expected_interval;
+
+ fraction= (fraction<<24) | lost;
+
+ put_be32(&pb, fraction); /* 8 bits of fraction, 24 bits of total packets lost */
+ put_be32(&pb, extended_max); /* max sequence received */
+ put_be32(&pb, stats->jitter>>4); /* jitter */
+
+ if(s->last_rtcp_ntp_time==AV_NOPTS_VALUE)
+ {
+ put_be32(&pb, 0); /* last SR timestamp */
+ put_be32(&pb, 0); /* delay since last SR */
+ } else {
+ uint32_t middle_32_bits= s->last_rtcp_ntp_time>>16; // this is valid, right? do we need to handle 64 bit values special?
+ uint32_t delay_since_last= ntp_time - s->last_rtcp_ntp_time;
+
+ put_be32(&pb, middle_32_bits); /* last SR timestamp */
+ put_be32(&pb, delay_since_last); /* delay since last SR */
+ }
+
+ // CNAME
+ put_byte(&pb, (RTP_VERSION << 6) + 1); /* 1 report block */
+ put_byte(&pb, 202);
+ len = strlen(s->hostname);
+ put_be16(&pb, (6 + len + 3) / 4); /* length in words - 1 */
+ put_be32(&pb, s->ssrc);
+ put_byte(&pb, 0x01);
+ put_byte(&pb, len);
+ put_buffer(&pb, s->hostname, len);
+ // padding
+ for (len = (6 + len) % 4; len % 4; len++) {
+ put_byte(&pb, 0);
+ }
+
+ put_flush_packet(&pb);
+ len = url_close_dyn_buf(&pb, &buf);
+ if ((len > 0) && buf) {
+ int result;
+#if defined(DEBUG)
+ printf("sending %d bytes of RR\n", len);
+#endif
+ result= url_write(s->rtp_ctx, buf, len);
+#if defined(DEBUG)
+ printf("result from url_write: %d\n", result);
+#endif
+ av_free(buf);
+ }
+ return 0;
+}
+
+/**
+ * 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
+ * rtp demux (otherwise CODEC_ID_MPEG2TS packets are returned)
+ * TODO: change this to not take rtp_payload data, and use the new dynamic payload system.
+ */
+RTPDemuxContext *rtp_parse_open(AVFormatContext *s1, AVStream *st, URLContext *rtpc, int payload_type, rtp_payload_data_t *rtp_payload_data)
+{
+ RTPDemuxContext *s;
+
+ s = av_mallocz(sizeof(RTPDemuxContext));
+ if (!s)
+ return NULL;
+ s->payload_type = payload_type;
+ s->last_rtcp_ntp_time = AV_NOPTS_VALUE;
+ s->first_rtcp_ntp_time = AV_NOPTS_VALUE;
+ s->ic = s1;
+ s->st = st;
+ s->rtp_payload_data = rtp_payload_data;
+ rtp_init_statistics(&s->statistics, 0); // do we know the initial sequence from sdp?
+ if (!strcmp(AVRtpPayloadTypes[payload_type].enc_name, "MP2T")) {
+ s->ts = mpegts_parse_open(s->ic);
+ if (s->ts == NULL) {
+ av_free(s);
+ return NULL;
+ }
+ } else {
+ switch(st->codec->codec_id) {
+ case CODEC_ID_MPEG1VIDEO:
+ case CODEC_ID_MPEG2VIDEO:
+ case CODEC_ID_MP2:
+ case CODEC_ID_MP3:
+ case CODEC_ID_MPEG4:
+ case CODEC_ID_H264:
+ st->need_parsing = 1;
+ break;
+ default:
+ break;
+ }
+ }
+ // needed to send back RTCP RR in RTSP sessions
+ s->rtp_ctx = rtpc;
+ gethostname(s->hostname, sizeof(s->hostname));
+ return s;
+}
+
+static int rtp_parse_mp4_au(RTPDemuxContext *s, const uint8_t *buf)
+{
+ int au_headers_length, au_header_size, i;
+ GetBitContext getbitcontext;
+ rtp_payload_data_t *infos;
+
+ infos = s->rtp_payload_data;
+
+ if (infos == NULL)
+ return -1;
+
+ /* decode the first 2 bytes where are stored the AUHeader sections
+ length in bits */
+ au_headers_length = AV_RB16(buf);
+
+ if (au_headers_length > RTP_MAX_PACKET_LENGTH)
+ return -1;
+
+ infos->au_headers_length_bytes = (au_headers_length + 7) / 8;
+
+ /* skip AU headers length section (2 bytes) */
+ buf += 2;
+
+ init_get_bits(&getbitcontext, buf, infos->au_headers_length_bytes * 8);
+
+ /* XXX: Wrong if optionnal additional sections are present (cts, dts etc...) */
+ au_header_size = infos->sizelength + infos->indexlength;
+ if (au_header_size <= 0 || (au_headers_length % au_header_size != 0))
+ return -1;
+
+ infos->nb_au_headers = au_headers_length / au_header_size;
+ infos->au_headers = av_malloc(sizeof(struct AUHeaders) * 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 doesnt behave correctly when sending each AU one by one
+ but does when sending the whole as one big packet... */
+ infos->au_headers[0].size = 0;
+ infos->au_headers[0].index = 0;
+ for (i = 0; i < infos->nb_au_headers; ++i) {
+ infos->au_headers[0].size += get_bits_long(&getbitcontext, infos->sizelength);
+ infos->au_headers[0].index = get_bits_long(&getbitcontext, infos->indexlength);
+ }
+
+ infos->nb_au_headers = 1;
+
+ return 0;
+}
+
+/**
+ * This was the second switch in rtp_parse packet. Normalizes time, if required, sets stream_index, etc.
+ */
+static void finalize_packet(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestamp)
+{
+ switch(s->st->codec->codec_id) {
+ case CODEC_ID_MP2:
+ case CODEC_ID_MPEG1VIDEO:
+ if (s->last_rtcp_ntp_time != AV_NOPTS_VALUE) {
+ int64_t addend;
+
+ int delta_timestamp;
+ /* XXX: is it really necessary to unify the timestamp base ? */
+ /* compute pts from timestamp with received ntp_time */
+ delta_timestamp = timestamp - s->last_rtcp_timestamp;
+ /* convert to 90 kHz without overflow */
+ addend = (s->last_rtcp_ntp_time - s->first_rtcp_ntp_time) >> 14;
+ addend = (addend * 5625) >> 14;
+ pkt->pts = addend + delta_timestamp;
+ }
+ break;
+ case CODEC_ID_AAC:
+ case CODEC_ID_H264:
+ case CODEC_ID_MPEG4:
+ pkt->pts = timestamp;
+ break;
+ default:
+ /* no timestamp info yet */
+ break;
+ }
+ pkt->stream_index = s->st->index;
+}
+
+/**
+ * Parse an RTP or RTCP packet directly sent as a buffer.
+ * @param s RTP parse context.
+ * @param pkt returned packet
+ * @param buf input buffer or NULL to read the next packets
+ * @param len buffer len
+ * @return 0 if a packet is returned, 1 if a packet is returned and more can follow
+ * (use buf as NULL to read the next). -1 if no packet (error or no more packet).
+ */
+int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt,
+ const uint8_t *buf, int len)
+{
+ unsigned int ssrc, h;
+ int payload_type, seq, ret;
+ AVStream *st;
+ uint32_t timestamp;
+ int rv= 0;
+
+ if (!buf) {
+ /* return the next packets, if any */
+ if(s->st && s->parse_packet) {
+ timestamp= 0; ///< Should not be used if buf is NULL, but should be set to the timestamp of the packet returned....
+ rv= s->parse_packet(s, pkt, &timestamp, NULL, 0);
+ finalize_packet(s, pkt, timestamp);
+ return rv;
+ } else {
+ // 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,
+ s->read_buf_size - s->read_buf_index);
+ if (ret < 0)
+ return -1;
+ s->read_buf_index += ret;
+ if (s->read_buf_index < s->read_buf_size)
+ return 1;
+ else
+ return 0;
+ }
+ }
+
+ if (len < 12)
+ return -1;
+
+ if ((buf[0] & 0xc0) != (RTP_VERSION << 6))
+ return -1;
+ if (buf[1] >= 200 && buf[1] <= 204) {
+ rtcp_parse_packet(s, buf, len);
+ return -1;
+ }
+ payload_type = buf[1] & 0x7f;
+ seq = (buf[2] << 8) | buf[3];
+ timestamp = decode_be32(buf + 4);
+ ssrc = decode_be32(buf + 8);
+ /* store the ssrc in the RTPDemuxContext */
+ s->ssrc = ssrc;
+
+ /* NOTE: we can handle only one payload type */
+ if (s->payload_type != payload_type)
+ return -1;
+
+ st = s->st;
+ // only do something with this if all the rtp checks pass...
+ if(!rtp_valid_packet_in_sequence(&s->statistics, seq))
+ {
+ av_log(st?st->codec:NULL, AV_LOG_ERROR, "RTP: PT=%02x: bad cseq %04x expected=%04x\n",
+ payload_type, seq, ((s->seq + 1) & 0xffff));
+ return -1;
+ }
+
+ s->seq = seq;
+ len -= 12;
+ buf += 12;
+
+ if (!st) {
+ /* specific MPEG2TS demux support */
+ ret = mpegts_parse_packet(s->ts, pkt, buf, len);
+ if (ret < 0)
+ return -1;
+ if (ret < len) {
+ s->read_buf_size = len - ret;
+ memcpy(s->buf, buf + ret, s->read_buf_size);
+ s->read_buf_index = 0;
+ return 1;
+ }
+ } else {
+ // 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:
+ /* better than nothing: skip mpeg audio RTP header */
+ if (len <= 4)
+ return -1;
+ h = decode_be32(buf);
+ len -= 4;
+ buf += 4;
+ av_new_packet(pkt, len);
+ memcpy(pkt->data, buf, len);
+ break;
+ case CODEC_ID_MPEG1VIDEO:
+ /* better than nothing: skip mpeg video RTP header */
+ if (len <= 4)
+ return -1;
+ h = decode_be32(buf);
+ buf += 4;
+ len -= 4;
+ if (h & (1 << 26)) {
+ /* mpeg2 */
+ if (len <= 4)
+ return -1;
+ buf += 4;
+ len -= 4;
+ }
+ av_new_packet(pkt, len);
+ memcpy(pkt->data, buf, len);
+ break;
+ // moved from below, verbatim. this is because this section handles packets, and the lower switch handles
+ // timestamps.
+ // TODO: Put this into a dynamic packet handler...
+ case CODEC_ID_AAC:
+ if (rtp_parse_mp4_au(s, buf))
+ return -1;
+ {
+ rtp_payload_data_t *infos = s->rtp_payload_data;
+ if (infos == NULL)
+ return -1;
+ buf += infos->au_headers_length_bytes + 2;
+ len -= infos->au_headers_length_bytes + 2;
+
+ /* XXX: Fixme we only handle the case where rtp_parse_mp4_au define
+ one au_header */
+ av_new_packet(pkt, infos->au_headers[0].size);
+ memcpy(pkt->data, buf, infos->au_headers[0].size);
+ buf += infos->au_headers[0].size;
+ len -= infos->au_headers[0].size;
+ }
+ s->read_buf_size = len;
+ s->buf_ptr = buf;
+ rv= 0;
+ break;
+ default:
+ if(s->parse_packet) {
+ rv= s->parse_packet(s, pkt, &timestamp, buf, len);
+ } else {
+ av_new_packet(pkt, len);
+ memcpy(pkt->data, buf, len);
+ }
+ break;
+ }
+
+ // now perform timestamp things....
+ finalize_packet(s, pkt, timestamp);
+ }
+ return rv;
+}
+
+void rtp_parse_close(RTPDemuxContext *s)
+{
+ // TODO: fold this into the protocol specific data fields.
+ if (!strcmp(AVRtpPayloadTypes[s->payload_type].enc_name, "MP2T")) {
+ mpegts_parse_close(s->ts);
+ }
+ av_free(s);
+}
+
+/* rtp output */
+
+static int rtp_write_header(AVFormatContext *s1)
+{
+ RTPDemuxContext *s = s1->priv_data;
+ int payload_type, max_packet_size, n;
+ AVStream *st;
+
+ if (s1->nb_streams != 1)
+ return -1;
+ st = s1->streams[0];
+
+ payload_type = rtp_get_payload_type(st->codec);
+ if (payload_type < 0)
+ payload_type = RTP_PT_PRIVATE; /* private payload type */
+ s->payload_type = payload_type;
+
+// following 2 FIXMies could be set based on the current time, theres normaly no info leak, as rtp will likely be transmitted immedeatly
+ s->base_timestamp = 0; /* FIXME: was random(), what should this be? */
+ s->timestamp = s->base_timestamp;
+ s->ssrc = 0; /* FIXME: was random(), what should this be? */
+ s->first_packet = 1;
+
+ max_packet_size = url_fget_max_packet_size(&s1->pb);
+ if (max_packet_size <= 12)
+ return AVERROR_IO;
+ s->max_payload_size = max_packet_size - 12;
+
+ switch(st->codec->codec_id) {
+ case CODEC_ID_MP2:
+ case CODEC_ID_MP3:
+ s->buf_ptr = s->buf + 4;
+ s->cur_timestamp = 0;
+ break;
+ case CODEC_ID_MPEG1VIDEO:
+ s->cur_timestamp = 0;
+ break;
+ case CODEC_ID_MPEG2TS:
+ n = s->max_payload_size / TS_PACKET_SIZE;
+ if (n < 1)
+ n = 1;
+ s->max_payload_size = n * TS_PACKET_SIZE;
+ s->buf_ptr = s->buf;
+ break;
+ default:
+ s->buf_ptr = s->buf;
+ break;
+ }
+
+ return 0;
+}
+
+/* send an rtcp sender report packet */
+static void rtcp_send_sr(AVFormatContext *s1, int64_t ntp_time)
+{
+ RTPDemuxContext *s = s1->priv_data;
+#if defined(DEBUG)
+ printf("RTCP: %02x %"PRIx64" %x\n", s->payload_type, ntp_time, s->timestamp);
+#endif
+ put_byte(&s1->pb, (RTP_VERSION << 6));
+ put_byte(&s1->pb, 200);
+ put_be16(&s1->pb, 6); /* length in words - 1 */
+ put_be32(&s1->pb, s->ssrc);
+ put_be64(&s1->pb, ntp_time);
+ put_be32(&s1->pb, s->timestamp);
+ put_be32(&s1->pb, s->packet_count);
+ put_be32(&s1->pb, s->octet_count);
+ put_flush_packet(&s1->pb);
+}
+
+/* send an rtp packet. sequence number is incremented, but the caller
+ must update the timestamp itself */
+static void rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m)
+{
+ RTPDemuxContext *s = s1->priv_data;
+
+#ifdef DEBUG
+ printf("rtp_send_data size=%d\n", len);
+#endif
+
+ /* build the RTP header */
+ put_byte(&s1->pb, (RTP_VERSION << 6));
+ put_byte(&s1->pb, (s->payload_type & 0x7f) | ((m & 0x01) << 7));
+ put_be16(&s1->pb, s->seq);
+ put_be32(&s1->pb, s->timestamp);
+ put_be32(&s1->pb, s->ssrc);
+
+ put_buffer(&s1->pb, buf1, len);
+ put_flush_packet(&s1->pb);
+
+ s->seq++;
+ s->octet_count += len;
+ s->packet_count++;
+}
+
+/* send an integer number of samples and compute time stamp and fill
+ the rtp send buffer before sending. */
+static void rtp_send_samples(AVFormatContext *s1,
+ const uint8_t *buf1, int size, int sample_size)
+{
+ RTPDemuxContext *s = s1->priv_data;
+ int len, max_packet_size, n;
+
+ max_packet_size = (s->max_payload_size / sample_size) * sample_size;
+ /* not needed, but who nows */
+ if ((size % sample_size) != 0)
+ av_abort();
+ while (size > 0) {
+ len = (max_packet_size - (s->buf_ptr - s->buf));
+ if (len > size)
+ len = size;
+
+ /* copy data */
+ memcpy(s->buf_ptr, buf1, len);
+ s->buf_ptr += len;
+ buf1 += len;
+ size -= len;
+ n = (s->buf_ptr - s->buf);
+ /* if buffer full, then send it */
+ if (n >= max_packet_size) {
+ rtp_send_data(s1, s->buf, n, 0);
+ s->buf_ptr = s->buf;
+ /* update timestamp */
+ s->timestamp += n / sample_size;
+ }
+ }
+}
+
+/* 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)
+{
+ RTPDemuxContext *s = s1->priv_data;
+ AVStream *st = s1->streams[0];
+ int len, count, max_packet_size;
+
+ max_packet_size = s->max_payload_size;
+
+ /* test if we must flush because not enough space */
+ len = (s->buf_ptr - s->buf);
+ if ((len + size) > max_packet_size) {
+ if (len > 4) {
+ rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0);
+ s->buf_ptr = s->buf + 4;
+ /* 90 KHz time stamp */
+ s->timestamp = s->base_timestamp +
+ (s->cur_timestamp * 90000LL) / st->codec->sample_rate;
+ }
+ }
+
+ /* add the packet */
+ if (size > max_packet_size) {
+ /* big packet: fragment */
+ count = 0;
+ while (size > 0) {
+ len = max_packet_size - 4;
+ if (len > size)
+ len = size;
+ /* build fragmented packet */
+ s->buf[0] = 0;
+ s->buf[1] = 0;
+ s->buf[2] = count >> 8;
+ s->buf[3] = count;
+ memcpy(s->buf + 4, buf1, len);
+ rtp_send_data(s1, s->buf, len + 4, 0);
+ size -= len;
+ buf1 += len;
+ count += len;
+ }
+ } else {
+ if (s->buf_ptr == s->buf + 4) {
+ /* no fragmentation possible */
+ s->buf[0] = 0;
+ s->buf[1] = 0;
+ s->buf[2] = 0;
+ s->buf[3] = 0;
+ }
+ memcpy(s->buf_ptr, buf1, size);
+ s->buf_ptr += size;
+ }
+ s->cur_timestamp += st->codec->frame_size;
+}
+
+/* NOTE: a single frame must be passed with sequence header if
+ needed. XXX: use slices. */
+static void rtp_send_mpegvideo(AVFormatContext *s1,
+ const uint8_t *buf1, int size)
+{
+ RTPDemuxContext *s = s1->priv_data;
+ AVStream *st = s1->streams[0];
+ int len, h, max_packet_size;
+ uint8_t *q;
+
+ max_packet_size = s->max_payload_size;
+
+ while (size > 0) {
+ /* XXX: more correct headers */
+ h = 0;
+ if (st->codec->sub_id == 2)
+ h |= 1 << 26; /* mpeg 2 indicator */
+ q = s->buf;
+ *q++ = h >> 24;
+ *q++ = h >> 16;
+ *q++ = h >> 8;
+ *q++ = h;
+
+ if (st->codec->sub_id == 2) {
+ h = 0;
+ *q++ = h >> 24;
+ *q++ = h >> 16;
+ *q++ = h >> 8;
+ *q++ = h;
+ }
+
+ len = max_packet_size - (q - s->buf);
+ if (len > size)
+ len = size;
+
+ memcpy(q, buf1, len);
+ q += len;
+
+ /* 90 KHz time stamp */
+ s->timestamp = s->base_timestamp +
+ av_rescale((int64_t)s->cur_timestamp * st->codec->time_base.num, 90000, st->codec->time_base.den); //FIXME pass timestamps
+ rtp_send_data(s1, s->buf, q - s->buf, (len == size));
+
+ buf1 += len;
+ size -= len;
+ }
+ s->cur_timestamp++;
+}
+
+static void rtp_send_raw(AVFormatContext *s1,
+ const uint8_t *buf1, int size)
+{
+ RTPDemuxContext *s = s1->priv_data;
+ AVStream *st = s1->streams[0];
+ int len, max_packet_size;
+
+ max_packet_size = s->max_payload_size;
+
+ while (size > 0) {
+ len = max_packet_size;
+ if (len > size)
+ len = size;
+
+ /* 90 KHz time stamp */
+ s->timestamp = s->base_timestamp +
+ av_rescale((int64_t)s->cur_timestamp * st->codec->time_base.num, 90000, st->codec->time_base.den); //FIXME pass timestamps
+ rtp_send_data(s1, buf1, len, (len == size));
+
+ buf1 += len;
+ size -= len;
+ }
+ s->cur_timestamp++;
+}
+
+/* NOTE: size is assumed to be an integer multiple of TS_PACKET_SIZE */
+static void rtp_send_mpegts_raw(AVFormatContext *s1,
+ const uint8_t *buf1, int size)
+{
+ RTPDemuxContext *s = s1->priv_data;
+ int len, out_len;
+
+ while (size >= TS_PACKET_SIZE) {
+ len = s->max_payload_size - (s->buf_ptr - s->buf);
+ if (len > size)
+ len = size;
+ memcpy(s->buf_ptr, buf1, len);
+ buf1 += len;
+ size -= len;
+ s->buf_ptr += len;
+
+ out_len = s->buf_ptr - s->buf;
+ if (out_len >= s->max_payload_size) {
+ rtp_send_data(s1, s->buf, out_len, 0);
+ s->buf_ptr = s->buf;
+ }
+ }
+}
+
+/* write an RTP packet. 'buf1' must contain a single specific frame. */
+static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt)
+{
+ RTPDemuxContext *s = s1->priv_data;
+ AVStream *st = s1->streams[0];
+ int rtcp_bytes;
+ int64_t ntp_time;
+ int size= pkt->size;
+ uint8_t *buf1= pkt->data;
+
+#ifdef DEBUG
+ printf("%d: write len=%d\n", pkt->stream_index, size);
+#endif
+
+ /* XXX: mpeg pts hardcoded. RTCP send every 0.5 seconds */
+ rtcp_bytes = ((s->octet_count - s->last_octet_count) * RTCP_TX_RATIO_NUM) /
+ RTCP_TX_RATIO_DEN;
+ if (s->first_packet || rtcp_bytes >= 28) {
+ /* compute NTP time */
+ /* XXX: 90 kHz timestamp hardcoded */
+ ntp_time = (pkt->pts << 28) / 5625;
+ rtcp_send_sr(s1, ntp_time);
+ s->last_octet_count = s->octet_count;
+ s->first_packet = 0;
+ }
+
+ switch(st->codec->codec_id) {
+ case CODEC_ID_PCM_MULAW:
+ 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);
+ 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);
+ break;
+ case CODEC_ID_MP2:
+ case CODEC_ID_MP3:
+ rtp_send_mpegaudio(s1, buf1, size);
+ break;
+ case CODEC_ID_MPEG1VIDEO:
+ rtp_send_mpegvideo(s1, buf1, size);
+ break;
+ case CODEC_ID_MPEG2TS:
+ rtp_send_mpegts_raw(s1, buf1, size);
+ break;
+ default:
+ /* better than nothing : send the codec raw data */
+ rtp_send_raw(s1, buf1, size);
+ break;
+ }
+ return 0;
+}
+
+static int rtp_write_trailer(AVFormatContext *s1)
+{
+ // RTPDemuxContext *s = s1->priv_data;
+ return 0;
+}
+
+AVOutputFormat rtp_muxer = {
+ "rtp",
+ "RTP output format",
+ NULL,
+ NULL,
+ sizeof(RTPDemuxContext),
+ CODEC_ID_PCM_MULAW,
+ CODEC_ID_NONE,
+ rtp_write_header,
+ rtp_write_packet,
+ rtp_write_trailer,
+};
diff --git a/contrib/ffmpeg/libavformat/rtp.h b/contrib/ffmpeg/libavformat/rtp.h
new file mode 100644
index 000000000..fec763051
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/rtp.h
@@ -0,0 +1,127 @@
+/*
+ * RTP definitions
+ * 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
+ */
+#ifndef RTP_H
+#define RTP_H
+
+#define RTP_MIN_PACKET_LENGTH 12
+#define RTP_MAX_PACKET_LENGTH 1500 /* XXX: suppress this define */
+
+int rtp_init(void);
+int rtp_get_codec_info(AVCodecContext *codec, int payload_type);
+
+/** return < 0 if unknown payload type */
+int rtp_get_payload_type(AVCodecContext *codec);
+
+typedef struct RTPDemuxContext RTPDemuxContext;
+typedef struct rtp_payload_data_s rtp_payload_data_s;
+RTPDemuxContext *rtp_parse_open(AVFormatContext *s1, AVStream *st, URLContext *rtpc, int payload_type, rtp_payload_data_s *rtp_payload_data);
+int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt,
+ const uint8_t *buf, int len);
+void rtp_parse_close(RTPDemuxContext *s);
+
+extern AVOutputFormat rtp_muxer;
+extern AVInputFormat rtp_demuxer;
+
+int rtp_get_local_port(URLContext *h);
+int rtp_set_remote_url(URLContext *h, const char *uri);
+void rtp_get_file_handles(URLContext *h, int *prtp_fd, int *prtcp_fd);
+
+/**
+ * some rtp servers assume client is dead if they don't hear from them...
+ * so we send a Receiver Report to the provided ByteIO context
+ * (we don't have access to the rtcp handle from here)
+ */
+int rtp_check_and_send_back_rr(RTPDemuxContext *s, int count);
+
+extern URLProtocol rtp_protocol;
+
+#define RTP_PT_PRIVATE 96
+#define RTP_VERSION 2
+#define RTP_MAX_SDES 256 /**< maximum text length for SDES */
+
+/* RTCP paquets use 0.5 % of the bandwidth */
+#define RTCP_TX_RATIO_NUM 5
+#define RTCP_TX_RATIO_DEN 1000
+
+/** Structure listing useful vars to parse RTP packet payload*/
+typedef struct rtp_payload_data_s
+{
+ int sizelength;
+ int indexlength;
+ int indexdeltalength;
+ int profile_level_id;
+ int streamtype;
+ int objecttype;
+ char *mode;
+
+ /** mpeg 4 AU headers */
+ struct AUHeaders {
+ int size;
+ int index;
+ int cts_flag;
+ int cts;
+ int dts_flag;
+ int dts;
+ int rap_flag;
+ int streamstate;
+ } *au_headers;
+ int nb_au_headers;
+ int au_headers_length_bytes;
+ int cur_au_index;
+} rtp_payload_data_t;
+
+typedef struct AVRtpPayloadType_s
+{
+ int pt;
+ const char enc_name[50]; /* XXX: why 50 ? */
+ enum CodecType codec_type;
+ enum CodecID codec_id;
+ int clock_rate;
+ int audio_channels;
+} AVRtpPayloadType_t;
+
+#if 0
+typedef enum {
+ RTCP_SR = 200,
+ RTCP_RR = 201,
+ RTCP_SDES = 202,
+ RTCP_BYE = 203,
+ RTCP_APP = 204
+} rtcp_type_t;
+
+typedef enum {
+ RTCP_SDES_END = 0,
+ RTCP_SDES_CNAME = 1,
+ RTCP_SDES_NAME = 2,
+ RTCP_SDES_EMAIL = 3,
+ RTCP_SDES_PHONE = 4,
+ RTCP_SDES_LOC = 5,
+ RTCP_SDES_TOOL = 6,
+ RTCP_SDES_NOTE = 7,
+ RTCP_SDES_PRIV = 8,
+ RTCP_SDES_IMG = 9,
+ RTCP_SDES_DOOR = 10,
+ RTCP_SDES_SOURCE = 11
+} rtcp_sdes_type_t;
+#endif
+
+extern AVRtpPayloadType_t AVRtpPayloadTypes[];
+#endif /* RTP_H */
diff --git a/contrib/ffmpeg/libavformat/rtp_h264.c b/contrib/ffmpeg/libavformat/rtp_h264.c
new file mode 100644
index 000000000..d38e8780d
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/rtp_h264.c
@@ -0,0 +1,413 @@
+/*
+ * 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 rtp_h264.c
+ * @brief H.264 / RTP Code (RFC3984)
+ * @author Ryan Martell <rdm4@martellventures.com>
+ *
+ * @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 "avformat.h"
+#include "mpegts.h"
+#include "bitstream.h"
+
+#include <unistd.h>
+#include "network.h"
+#include <assert.h>
+
+#include "rtp_internal.h"
+#include "rtp_h264.h"
+#include "base64.h"
+
+/**
+ RTP/H264 specific private data.
+*/
+typedef struct h264_rtp_extra_data {
+ 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
+} h264_rtp_extra_data;
+
+#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,
+ h264_rtp_extra_data * 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(NULL, AV_LOG_DEBUG, "H.264/RTP Packetization Mode: %d\n", atoi(attr));
+ h264_data->packetization_mode = atoi(attr);
+ /*
+ 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(stream, AV_LOG_ERROR,
+ "H.264/RTP 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(NULL, AV_LOG_DEBUG,
+ "H.264/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);
+ 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);
+
+ codec->extradata= dest;
+ codec->extradata_size+= sizeof(start_sequence)+packet_size;
+ } else {
+ av_log(NULL, AV_LOG_ERROR, "H.264/RTP Unable to allocate memory for extradata!");
+ }
+ }
+ }
+ av_log(NULL, AV_LOG_DEBUG, "H.264/RTP 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(RTPDemuxContext * s,
+ AVPacket * pkt,
+ uint32_t * timestamp,
+ const uint8_t * buf,
+ int len)
+{
+#ifdef DEBUG
+ h264_rtp_extra_data *data = s->dynamic_protocol_context;
+#endif
+ uint8_t nal = buf[0];
+ uint8_t type = (nal & 0x1f);
+ int result= 0;
+ uint8_t start_sequence[]= {0, 0, 1};
+
+ assert(data);
+ assert(data->cookie == MAGIC_COOKIE);
+ 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(NULL, 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(NULL, 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(NULL, 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 & 0x80) >> 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 & 0x1f);
+
+ // skip the fu_header...
+ buf++;
+ len--;
+
+#ifdef DEBUG
+ if (start_bit)
+ data->packet_types_received[nal_type & 0x1f]++;
+#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(NULL, AV_LOG_ERROR, "Undefined type (%d)", type);
+ result= -1;
+ break;
+ }
+
+ return result;
+}
+
+/* ---------------- public code */
+static void *h264_new_extradata()
+{
+ h264_rtp_extra_data *data =
+ av_mallocz(sizeof(h264_rtp_extra_data) +
+ FF_INPUT_BUFFER_PADDING_SIZE);
+
+ if (data) {
+ data->cookie = MAGIC_COOKIE;
+ }
+
+ return data;
+}
+
+static void h264_free_extradata(void *d)
+{
+ h264_rtp_extra_data *data = (h264_rtp_extra_data *) d;
+#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(AVStream * stream, void *data,
+ const char *line)
+{
+ AVCodecContext *codec = stream->codec;
+ h264_rtp_extra_data *h264_data = (h264_rtp_extra_data *) data;
+ const char *p = line;
+
+ assert(h264_data->cookie == MAGIC_COOKIE);
+
+ if (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 != '-' && (buf1 - dst) < 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 (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 (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 (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 = {
+ "H264",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_H264,
+ parse_h264_sdp_line,
+ h264_new_extradata,
+ h264_free_extradata,
+ h264_handle_packet
+};
diff --git a/contrib/ffmpeg/libavformat/rtp_h264.h b/contrib/ffmpeg/libavformat/rtp_h264.h
new file mode 100644
index 000000000..19508574d
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/rtp_h264.h
@@ -0,0 +1,26 @@
+/*
+ * 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 RTP_H264_H
+#define RTP_H264_H
+
+extern RTPDynamicProtocolHandler ff_h264_dynamic_handler;
+#endif /* RTP_H264_H */
diff --git a/contrib/ffmpeg/libavformat/rtp_internal.h b/contrib/ffmpeg/libavformat/rtp_internal.h
new file mode 100644
index 000000000..3edcf49c8
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/rtp_internal.h
@@ -0,0 +1,110 @@
+/*
+ * RTP definitions
+ * Copyright (c) 2006 Ryan Martell <rdm4@martellventures.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+// this is a bit of a misnomer, because rtp & rtsp internal structures and prototypes are in here.
+#ifndef RTP_INTERNAL_H
+#define RTP_INTERNAL_H
+
+// these statistics are used for rtcp receiver reports...
+typedef struct {
+ uint16_t max_seq; ///< highest sequence number seen
+ uint32_t cycles; ///< shifted count of sequence number cycles
+ uint32_t base_seq; ///< base sequence number
+ uint32_t bad_seq; ///< last bad sequence number + 1
+ int probation; ///< sequence packets till source is valid
+ int received; ///< packets received
+ int expected_prior; ///< packets expected in last interval
+ int received_prior; ///< packets received in last interval
+ uint32_t transit; ///< relative transit time for previous packet
+ uint32_t jitter; ///< estimated jitter.
+} RTPStatistics;
+
+
+typedef int (*DynamicPayloadPacketHandlerProc) (struct RTPDemuxContext * s,
+ AVPacket * pkt,
+ uint32_t *timestamp,
+ const uint8_t * buf,
+ int len);
+
+typedef struct RTPDynamicProtocolHandler_s {
+ // fields from AVRtpDynamicPayloadType_s
+ const char enc_name[50]; /* XXX: still why 50 ? ;-) */
+ enum CodecType codec_type;
+ enum CodecID codec_id;
+
+ // may be null
+ int (*parse_sdp_a_line) (AVStream * stream,
+ void *protocol_data,
+ const char *line); ///< Parse the a= line from the sdp field
+ void *(*open) (); ///< allocate any data needed by the rtp parsing for this dynamic data.
+ void (*close)(void *protocol_data); ///< free any data needed by the rtp parsing for this dynamic data.
+ DynamicPayloadPacketHandlerProc parse_packet; ///< parse handler for this dynamic packet.
+
+ struct RTPDynamicProtocolHandler_s *next;
+} RTPDynamicProtocolHandler;
+
+// moved out of rtp.c, because the h264 decoder needs to know about this structure..
+struct RTPDemuxContext {
+ AVFormatContext *ic;
+ AVStream *st;
+ int payload_type;
+ uint32_t ssrc;
+ uint16_t seq;
+ uint32_t timestamp;
+ uint32_t base_timestamp;
+ uint32_t cur_timestamp;
+ int max_payload_size;
+ struct MpegTSContext *ts; /* only used for MP2T payloads */
+ int read_buf_index;
+ int read_buf_size;
+ /* used to send back RTCP RR */
+ URLContext *rtp_ctx;
+ char hostname[256];
+
+ RTPStatistics statistics; ///< Statistics for this stream (used by RTCP receiver reports)
+
+ /* rtcp sender statistics receive */
+ int64_t last_rtcp_ntp_time; // TODO: move into statistics
+ int64_t first_rtcp_ntp_time; // TODO: move into statistics
+ uint32_t last_rtcp_timestamp; // TODO: move into statistics
+
+ /* rtcp sender statistics */
+ unsigned int packet_count; // TODO: move into statistics (outgoing)
+ unsigned int octet_count; // TODO: move into statistics (outgoing)
+ unsigned int last_octet_count; // TODO: move into statistics (outgoing)
+ int first_packet;
+ /* buffer for output */
+ uint8_t buf[RTP_MAX_PACKET_LENGTH];
+ uint8_t *buf_ptr;
+
+ /* special infos for au headers parsing */
+ rtp_payload_data_t *rtp_payload_data; // TODO: Move into dynamic payload handlers
+
+ /* dynamic payload stuff */
+ DynamicPayloadPacketHandlerProc parse_packet; ///< This is also copied from the dynamic protocol handler structure
+ void *dynamic_protocol_context; ///< This is a copy from the values setup from the sdp parsing, in rtsp.c don't free me.
+};
+
+extern RTPDynamicProtocolHandler *RTPFirstDynamicPayloadHandler;
+
+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.
+#endif /* RTP_INTERNAL_H */
+
diff --git a/contrib/ffmpeg/libavformat/rtpproto.c b/contrib/ffmpeg/libavformat/rtpproto.c
new file mode 100644
index 000000000..4d32e667d
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/rtpproto.c
@@ -0,0 +1,295 @@
+/*
+ * RTP network protocol
+ * 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
+ */
+#include "avformat.h"
+
+#include <unistd.h>
+#include <stdarg.h>
+#include "network.h"
+#include <fcntl.h>
+
+#define RTP_TX_BUF_SIZE (64 * 1024)
+#define RTP_RX_BUF_SIZE (128 * 1024)
+
+typedef struct RTPContext {
+ URLContext *rtp_hd, *rtcp_hd;
+ int rtp_fd, rtcp_fd;
+} RTPContext;
+
+/**
+ * If no filename is given to av_open_input_file because you want to
+ * get the local port first, then you must call this function to set
+ * the remote server address.
+ *
+ * @param s1 media file context
+ * @param uri of the remote server
+ * @return zero if no error.
+ */
+int rtp_set_remote_url(URLContext *h, const char *uri)
+{
+ RTPContext *s = h->priv_data;
+ char hostname[256];
+ int port;
+
+ char buf[1024];
+ char path[1024];
+
+ 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);
+ udp_set_remote_url(s->rtp_hd, buf);
+
+ snprintf(buf, sizeof(buf), "udp://%s:%d%s", hostname, port + 1, path);
+ udp_set_remote_url(s->rtcp_hd, buf);
+ return 0;
+}
+
+
+/* add option to url of the form:
+ "http://host:port/path?option1=val1&option2=val2... */
+static void url_add_option(char *buf, int buf_size, const char *fmt, ...)
+{
+ char buf1[1024];
+ va_list ap;
+
+ va_start(ap, fmt);
+ if (strchr(buf, '?'))
+ pstrcat(buf, buf_size, "&");
+ else
+ pstrcat(buf, buf_size, "?");
+ vsnprintf(buf1, sizeof(buf1), fmt, ap);
+ pstrcat(buf, buf_size, buf1);
+ va_end(ap);
+}
+
+static void build_udp_url(char *buf, int buf_size,
+ const char *hostname, int port,
+ int local_port, int multicast, int ttl)
+{
+ snprintf(buf, buf_size, "udp://%s:%d", hostname, port);
+ if (local_port >= 0)
+ url_add_option(buf, buf_size, "localport=%d", local_port);
+ if (multicast)
+ url_add_option(buf, buf_size, "multicast=1");
+ if (ttl >= 0)
+ url_add_option(buf, buf_size, "ttl=%d", ttl);
+}
+
+/*
+ * url syntax: rtp://host:port[?option=val...]
+ * option: 'multicast=1' : enable multicast
+ * 'ttl=n' : set the ttl value (for multicast only)
+ * 'localport=n' : set the local port to n
+ *
+ */
+static int rtp_open(URLContext *h, const char *uri, int flags)
+{
+ RTPContext *s;
+ int port, is_output, is_multicast, ttl, local_port;
+ char hostname[256];
+ char buf[1024];
+ char path[1024];
+ const char *p;
+
+ is_output = (flags & URL_WRONLY);
+
+ s = av_mallocz(sizeof(RTPContext));
+ if (!s)
+ return AVERROR(ENOMEM);
+ h->priv_data = s;
+
+ url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port,
+ path, sizeof(path), uri);
+ /* extract parameters */
+ is_multicast = 0;
+ ttl = -1;
+ local_port = -1;
+ p = strchr(uri, '?');
+ if (p) {
+ is_multicast = find_info_tag(buf, sizeof(buf), "multicast", p);
+ if (find_info_tag(buf, sizeof(buf), "ttl", p)) {
+ ttl = strtol(buf, NULL, 10);
+ }
+ if (find_info_tag(buf, sizeof(buf), "localport", p)) {
+ local_port = strtol(buf, NULL, 10);
+ }
+ }
+
+ build_udp_url(buf, sizeof(buf),
+ hostname, port, local_port, is_multicast, ttl);
+ 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 connexion if the port is not even */
+
+ /* well, should suppress localport in path */
+
+ build_udp_url(buf, sizeof(buf),
+ hostname, port + 1, local_port + 1, is_multicast, ttl);
+ if (url_open(&s->rtcp_hd, buf, flags) < 0)
+ goto fail;
+
+ /* just to ease handle access. XXX: need to suppress direct handle
+ access */
+ s->rtp_fd = udp_get_file_handle(s->rtp_hd);
+ s->rtcp_fd = udp_get_file_handle(s->rtcp_hd);
+
+ h->max_packet_size = url_get_max_packet_size(s->rtp_hd);
+ h->is_streamed = 1;
+ return 0;
+
+ fail:
+ if (s->rtp_hd)
+ url_close(s->rtp_hd);
+ if (s->rtcp_hd)
+ url_close(s->rtcp_hd);
+ av_free(s);
+ return AVERROR_IO;
+}
+
+static int rtp_read(URLContext *h, uint8_t *buf, int size)
+{
+ RTPContext *s = h->priv_data;
+ struct sockaddr_in from;
+ socklen_t from_len;
+ int len, fd_max, n;
+ fd_set rfds;
+#if 0
+ for(;;) {
+ from_len = sizeof(from);
+ len = recvfrom (s->rtp_fd, buf, size, 0,
+ (struct sockaddr *)&from, &from_len);
+ if (len < 0) {
+ if (errno == EAGAIN || errno == EINTR)
+ continue;
+ return AVERROR_IO;
+ }
+ break;
+ }
+#else
+ for(;;) {
+ /* build fdset to listen to RTP and RTCP packets */
+ FD_ZERO(&rfds);
+ fd_max = s->rtp_fd;
+ FD_SET(s->rtp_fd, &rfds);
+ 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);
+ if (n > 0) {
+ /* first try RTCP */
+ if (FD_ISSET(s->rtcp_fd, &rfds)) {
+ from_len = sizeof(from);
+ len = recvfrom (s->rtcp_fd, buf, size, 0,
+ (struct sockaddr *)&from, &from_len);
+ if (len < 0) {
+ if (errno == EAGAIN || errno == EINTR)
+ continue;
+ return AVERROR_IO;
+ }
+ break;
+ }
+ /* then RTP */
+ if (FD_ISSET(s->rtp_fd, &rfds)) {
+ from_len = sizeof(from);
+ len = recvfrom (s->rtp_fd, buf, size, 0,
+ (struct sockaddr *)&from, &from_len);
+ if (len < 0) {
+ if (errno == EAGAIN || errno == EINTR)
+ continue;
+ return AVERROR_IO;
+ }
+ break;
+ }
+ }
+ }
+#endif
+ return len;
+}
+
+static int rtp_write(URLContext *h, uint8_t *buf, int size)
+{
+ RTPContext *s = h->priv_data;
+ int ret;
+ URLContext *hd;
+
+ if (buf[1] >= 200 && buf[1] <= 204) {
+ /* RTCP payload type */
+ hd = s->rtcp_hd;
+ } else {
+ /* RTP payload type */
+ hd = s->rtp_hd;
+ }
+
+ ret = url_write(hd, buf, size);
+#if 0
+ {
+ struct timespec ts;
+ ts.tv_sec = 0;
+ ts.tv_nsec = 10 * 1000000;
+ nanosleep(&ts, NULL);
+ }
+#endif
+ return ret;
+}
+
+static int rtp_close(URLContext *h)
+{
+ RTPContext *s = h->priv_data;
+
+ url_close(s->rtp_hd);
+ url_close(s->rtcp_hd);
+ av_free(s);
+ return 0;
+}
+
+/**
+ * Return the local port used by the RTP connexion
+ * @param s1 media file context
+ * @return the local port number
+ */
+int rtp_get_local_port(URLContext *h)
+{
+ RTPContext *s = h->priv_data;
+ return udp_get_local_port(s->rtp_hd);
+}
+
+/**
+ * Return the rtp and rtcp file handles for select() usage to wait for several RTP
+ * streams at the same time.
+ * @param h media file context
+ */
+void rtp_get_file_handles(URLContext *h, int *prtp_fd, int *prtcp_fd)
+{
+ RTPContext *s = h->priv_data;
+
+ *prtp_fd = s->rtp_fd;
+ *prtcp_fd = s->rtcp_fd;
+}
+
+URLProtocol rtp_protocol = {
+ "rtp",
+ rtp_open,
+ rtp_read,
+ rtp_write,
+ NULL, /* seek */
+ rtp_close,
+};
diff --git a/contrib/ffmpeg/libavformat/rtsp.c b/contrib/ffmpeg/libavformat/rtsp.c
new file mode 100644
index 000000000..7d4c6bf78
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/rtsp.c
@@ -0,0 +1,1486 @@
+/*
+ * RTSP/SDP client
+ * 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
+ */
+#include "avformat.h"
+
+#include <sys/time.h>
+#include <unistd.h> /* for select() prototype */
+#include "network.h"
+
+#include "rtp_internal.h"
+
+//#define DEBUG
+//#define DEBUG_RTP_TCP
+
+enum RTSPClientState {
+ RTSP_STATE_IDLE,
+ RTSP_STATE_PLAYING,
+ RTSP_STATE_PAUSED,
+};
+
+typedef struct RTSPState {
+ URLContext *rtsp_hd; /* RTSP TCP connexion handle */
+ int nb_rtsp_streams;
+ struct RTSPStream **rtsp_streams;
+
+ enum RTSPClientState state;
+ int64_t seek_timestamp;
+
+ /* XXX: currently we use unbuffered input */
+ // ByteIOContext rtsp_gb;
+ int seq; /* RTSP command sequence number */
+ char session_id[512];
+ enum RTSPProtocol protocol;
+ char last_reply[2048]; /* XXX: allocate ? */
+ RTPDemuxContext *cur_rtp;
+} RTSPState;
+
+typedef struct RTSPStream {
+ URLContext *rtp_handle; /* RTP stream handle */
+ RTPDemuxContext *rtp_ctx; /* RTP parse context */
+
+ int stream_index; /* corresponding stream index, if any. -1 if none (MPEG2TS case) */
+ int interleaved_min, interleaved_max; /* interleave ids, if TCP transport */
+ char control_url[1024]; /* url for this stream (from SDP) */
+
+ int sdp_port; /* port (from SDP content - not used in RTSP) */
+ struct in_addr sdp_ip; /* IP address (from SDP content - not used in RTSP) */
+ int sdp_ttl; /* IP TTL (from SDP content - not used in RTSP) */
+ int sdp_payload_type; /* payload type - only used in SDP */
+ rtp_payload_data_t rtp_payload_data; /* rtp payload parsing infos from SDP */
+
+ RTPDynamicProtocolHandler *dynamic_handler; ///< Only valid if it's a dynamic protocol. (This is the handler structure)
+ void *dynamic_protocol_context; ///< Only valid if it's a dynamic protocol. (This is any private data associated with the dynamic protocol)
+} RTSPStream;
+
+static int rtsp_read_play(AVFormatContext *s);
+
+/* XXX: currently, the only way to change the protocols consists in
+ changing this variable */
+
+int rtsp_default_protocols = (1 << RTSP_PROTOCOL_RTP_UDP);
+
+FFRTSPCallback *ff_rtsp_callback = NULL;
+
+static int rtsp_probe(AVProbeData *p)
+{
+ if (strstart(p->filename, "rtsp:", NULL))
+ return AVPROBE_SCORE_MAX;
+ return 0;
+}
+
+static int redir_isspace(int c)
+{
+ return (c == ' ' || c == '\t' || c == '\n' || c == '\r');
+}
+
+static void skip_spaces(const char **pp)
+{
+ const char *p;
+ p = *pp;
+ while (redir_isspace(*p))
+ p++;
+ *pp = p;
+}
+
+static void get_word_sep(char *buf, int buf_size, const char *sep,
+ const char **pp)
+{
+ const char *p;
+ char *q;
+
+ p = *pp;
+ if (*p == '/')
+ p++;
+ skip_spaces(&p);
+ q = buf;
+ while (!strchr(sep, *p) && *p != '\0') {
+ if ((q - buf) < buf_size - 1)
+ *q++ = *p;
+ p++;
+ }
+ if (buf_size > 0)
+ *q = '\0';
+ *pp = p;
+}
+
+static void get_word(char *buf, int buf_size, const char **pp)
+{
+ const char *p;
+ char *q;
+
+ p = *pp;
+ skip_spaces(&p);
+ q = buf;
+ while (!redir_isspace(*p) && *p != '\0') {
+ if ((q - buf) < buf_size - 1)
+ *q++ = *p;
+ p++;
+ }
+ if (buf_size > 0)
+ *q = '\0';
+ *pp = p;
+}
+
+/* parse the rtpmap description: <codec_name>/<clock_rate>[/<other
+ params>] */
+static int sdp_parse_rtpmap(AVCodecContext *codec, RTSPStream *rtsp_st, int payload_type, const char *p)
+{
+ char buf[256];
+ int i;
+ AVCodec *c;
+ 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);
+ if (payload_type >= RTP_PT_PRIVATE) {
+ RTPDynamicProtocolHandler *handler= RTPFirstDynamicPayloadHandler;
+ while(handler) {
+ if (!strcmp(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) */
+ /* search into AVRtpPayloadTypes[] */
+ for (i = 0; AVRtpPayloadTypes[i].pt >= 0; ++i)
+ if (!strcmp(buf, AVRtpPayloadTypes[i].enc_name) && (codec->codec_type == AVRtpPayloadTypes[i].codec_type)){
+ codec->codec_id = AVRtpPayloadTypes[i].codec_id;
+ break;
+ }
+ }
+
+ c = avcodec_find_decoder(codec->codec_id);
+ if (c && c->name)
+ c_name = c->name;
+ else
+ c_name = (char *)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;
+ }
+ return 0;
+ }
+
+ return -1;
+}
+
+/* return the length and optionnaly the data */
+static int hex_to_data(uint8_t *data, const char *p)
+{
+ int c, len, v;
+
+ len = 0;
+ v = 1;
+ for(;;) {
+ skip_spaces(&p);
+ if (p == '\0')
+ break;
+ c = toupper((unsigned char)*p++);
+ if (c >= '0' && c <= '9')
+ c = c - '0';
+ else if (c >= 'A' && c <= 'F')
+ c = c - 'A' + 10;
+ else
+ break;
+ v = (v << 4) | c;
+ if (v & 0x100) {
+ if (data)
+ data[len] = v;
+ len++;
+ v = 1;
+ }
+ }
+ return len;
+}
+
+static void sdp_parse_fmtp_config(AVCodecContext *codec, 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);
+ 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 attrname_map
+{
+ const char *str;
+ uint16_t type;
+ uint32_t offset;
+} attrname_map_t;
+
+/* All known fmtp parmeters and the corresping RTPAttrTypeEnum */
+#define ATTR_NAME_TYPE_INT 0
+#define ATTR_NAME_TYPE_STR 1
+static attrname_map_t attr_names[]=
+{
+ {"SizeLength", ATTR_NAME_TYPE_INT, offsetof(rtp_payload_data_t, sizelength)},
+ {"IndexLength", ATTR_NAME_TYPE_INT, offsetof(rtp_payload_data_t, indexlength)},
+ {"IndexDeltaLength", ATTR_NAME_TYPE_INT, offsetof(rtp_payload_data_t, indexdeltalength)},
+ {"profile-level-id", ATTR_NAME_TYPE_INT, offsetof(rtp_payload_data_t, profile_level_id)},
+ {"StreamType", ATTR_NAME_TYPE_INT, offsetof(rtp_payload_data_t, streamtype)},
+ {"mode", ATTR_NAME_TYPE_STR, offsetof(rtp_payload_data_t, 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)
+{
+ skip_spaces(p);
+ if(**p)
+ {
+ get_word_sep(attr, attr_size, "=", p);
+ if (**p == '=')
+ (*p)++;
+ get_word_sep(value, value_size, ";", p);
+ if (**p == ';')
+ (*p)++;
+ return 1;
+ }
+ return 0;
+}
+
+/* parse a SDP line and save stream attributes */
+static void sdp_parse_fmtp(AVStream *st, const char *p)
+{
+ char attr[256];
+ char value[4096];
+ int i;
+
+ RTSPStream *rtsp_st = st->priv_data;
+ AVCodecContext *codec = st->codec;
+ rtp_payload_data_t *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 */
+ sdp_parse_fmtp_config(codec, 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);
+ }
+ }
+ }
+}
+
+/** 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.
+ */
+static void rtsp_parse_range_npt(const char *p, int64_t *start, int64_t *end)
+{
+ char buf[256];
+
+ skip_spaces(&p);
+ if (!stristart(p, "npt=", &p))
+ return;
+
+ *start = AV_NOPTS_VALUE;
+ *end = AV_NOPTS_VALUE;
+
+ get_word_sep(buf, sizeof(buf), "-", &p);
+ *start = parse_date(buf, 1);
+ if (*p == '-') {
+ p++;
+ get_word_sep(buf, sizeof(buf), "-", &p);
+ *end = parse_date(buf, 1);
+ }
+// av_log(NULL, AV_LOG_DEBUG, "Range Start: %lld\n", *start);
+// av_log(NULL, AV_LOG_DEBUG, "Range End: %lld\n", *end);
+}
+
+typedef struct SDPParseState {
+ /* SDP only */
+ struct in_addr default_ip;
+ int default_ttl;
+} SDPParseState;
+
+static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1,
+ int letter, const char *buf)
+{
+ RTSPState *rt = s->priv_data;
+ char buf1[64], st_type[64];
+ const char *p;
+ int codec_type, payload_type, i;
+ AVStream *st;
+ RTSPStream *rtsp_st;
+ struct in_addr sdp_ip;
+ int ttl;
+
+#ifdef DEBUG
+ printf("sdp: %c='%s'\n", letter, buf);
+#endif
+
+ p = buf;
+ switch(letter) {
+ case 'c':
+ get_word(buf1, sizeof(buf1), &p);
+ if (strcmp(buf1, "IN") != 0)
+ return;
+ get_word(buf1, sizeof(buf1), &p);
+ if (strcmp(buf1, "IP4") != 0)
+ return;
+ get_word_sep(buf1, sizeof(buf1), "/", &p);
+ if (inet_aton(buf1, &sdp_ip) == 0)
+ return;
+ ttl = 16;
+ if (*p == '/') {
+ p++;
+ get_word_sep(buf1, sizeof(buf1), "/", &p);
+ ttl = atoi(buf1);
+ }
+ if (s->nb_streams == 0) {
+ s1->default_ip = sdp_ip;
+ s1->default_ttl = ttl;
+ } else {
+ st = s->streams[s->nb_streams - 1];
+ rtsp_st = st->priv_data;
+ rtsp_st->sdp_ip = sdp_ip;
+ rtsp_st->sdp_ttl = ttl;
+ }
+ break;
+ case 's':
+ pstrcpy(s->title, sizeof(s->title), p);
+ break;
+ case 'i':
+ if (s->nb_streams == 0) {
+ pstrcpy(s->comment, sizeof(s->comment), p);
+ break;
+ }
+ break;
+ case 'm':
+ /* new stream */
+ get_word(st_type, sizeof(st_type), &p);
+ if (!strcmp(st_type, "audio")) {
+ codec_type = CODEC_TYPE_AUDIO;
+ } else if (!strcmp(st_type, "video")) {
+ codec_type = CODEC_TYPE_VIDEO;
+ } else {
+ return;
+ }
+ rtsp_st = av_mallocz(sizeof(RTSPStream));
+ if (!rtsp_st)
+ return;
+ rtsp_st->stream_index = -1;
+ dynarray_add(&rt->rtsp_streams, &rt->nb_rtsp_streams, rtsp_st);
+
+ rtsp_st->sdp_ip = s1->default_ip;
+ rtsp_st->sdp_ttl = s1->default_ttl;
+
+ get_word(buf1, sizeof(buf1), &p); /* port */
+ rtsp_st->sdp_port = atoi(buf1);
+
+ get_word(buf1, sizeof(buf1), &p); /* protocol (ignored) */
+
+ /* XXX: handle list of formats */
+ get_word(buf1, sizeof(buf1), &p); /* format list */
+ rtsp_st->sdp_payload_type = atoi(buf1);
+
+ if (!strcmp(AVRtpPayloadTypes[rtsp_st->sdp_payload_type].enc_name, "MP2T")) {
+ /* no corresponding stream */
+ } else {
+ st = av_new_stream(s, 0);
+ if (!st)
+ return;
+ st->priv_data = rtsp_st;
+ rtsp_st->stream_index = st->index;
+ st->codec->codec_type = codec_type;
+ if (rtsp_st->sdp_payload_type < RTP_PT_PRIVATE) {
+ /* if standard payload type, we can find the codec right now */
+ rtp_get_codec_info(st->codec, rtsp_st->sdp_payload_type);
+ }
+ }
+ /* put a default control url */
+ pstrcpy(rtsp_st->control_url, sizeof(rtsp_st->control_url), s->filename);
+ break;
+ case 'a':
+ if (strstart(p, "control:", &p) && s->nb_streams > 0) {
+ 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);
+ if (proto[0] == '\0') {
+ /* relative control URL */
+ pstrcat(rtsp_st->control_url, sizeof(rtsp_st->control_url), "/");
+ pstrcat(rtsp_st->control_url, sizeof(rtsp_st->control_url), p);
+ } else {
+ pstrcpy(rtsp_st->control_url, sizeof(rtsp_st->control_url), p);
+ }
+ } else if (strstart(p, "rtpmap:", &p)) {
+ /* NOTE: rtpmap is only supported AFTER the 'm=' tag */
+ get_word(buf1, sizeof(buf1), &p);
+ payload_type = atoi(buf1);
+ 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) {
+ sdp_parse_rtpmap(st->codec, rtsp_st, payload_type, p);
+ }
+ }
+ } else if (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];
+ 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(st, rtsp_st->dynamic_protocol_context, buf)) {
+ sdp_parse_fmtp(st, p);
+ }
+ } else {
+ sdp_parse_fmtp(st, p);
+ }
+ }
+ }
+ } else if(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];
+ 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(st, rtsp_st->dynamic_protocol_context, buf);
+ }
+ }
+ }
+ } else if(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)
+ }
+ break;
+ }
+}
+
+static int sdp_parse(AVFormatContext *s, const char *content)
+{
+ const char *p;
+ int letter;
+ char buf[1024], *q;
+ SDPParseState sdp_parse_state, *s1 = &sdp_parse_state;
+
+ memset(s1, 0, sizeof(SDPParseState));
+ p = content;
+ for(;;) {
+ skip_spaces(&p);
+ letter = *p;
+ if (letter == '\0')
+ break;
+ p++;
+ if (*p != '=')
+ goto next_line;
+ p++;
+ /* get the content */
+ q = buf;
+ while (*p != '\n' && *p != '\r' && *p != '\0') {
+ if ((q - buf) < sizeof(buf) - 1)
+ *q++ = *p;
+ p++;
+ }
+ *q = '\0';
+ sdp_parse_line(s, s1, letter, buf);
+ next_line:
+ while (*p != '\n' && *p != '\0')
+ p++;
+ if (*p == '\n')
+ p++;
+ }
+ return 0;
+}
+
+static void rtsp_parse_range(int *min_ptr, int *max_ptr, const char **pp)
+{
+ const char *p;
+ int v;
+
+ p = *pp;
+ skip_spaces(&p);
+ v = strtol(p, (char **)&p, 10);
+ if (*p == '-') {
+ p++;
+ *min_ptr = v;
+ v = strtol(p, (char **)&p, 10);
+ *max_ptr = v;
+ } else {
+ *min_ptr = v;
+ *max_ptr = v;
+ }
+ *pp = p;
+}
+
+/* XXX: only one transport specification is parsed */
+static void rtsp_parse_transport(RTSPHeader *reply, const char *p)
+{
+ char transport_protocol[16];
+ char profile[16];
+ char lower_transport[16];
+ char parameter[16];
+ RTSPTransportField *th;
+ char buf[256];
+
+ reply->nb_transports = 0;
+
+ for(;;) {
+ skip_spaces(&p);
+ if (*p == '\0')
+ break;
+
+ th = &reply->transports[reply->nb_transports];
+
+ get_word_sep(transport_protocol, sizeof(transport_protocol),
+ "/", &p);
+ if (*p == '/')
+ p++;
+ get_word_sep(profile, sizeof(profile), "/;,", &p);
+ lower_transport[0] = '\0';
+ if (*p == '/') {
+ p++;
+ get_word_sep(lower_transport, sizeof(lower_transport),
+ ";,", &p);
+ }
+ if (!strcasecmp(lower_transport, "TCP"))
+ th->protocol = RTSP_PROTOCOL_RTP_TCP;
+ else
+ th->protocol = RTSP_PROTOCOL_RTP_UDP;
+
+ if (*p == ';')
+ p++;
+ /* get each parameter */
+ while (*p != '\0' && *p != ',') {
+ get_word_sep(parameter, sizeof(parameter), "=;,", &p);
+ if (!strcmp(parameter, "port")) {
+ if (*p == '=') {
+ p++;
+ rtsp_parse_range(&th->port_min, &th->port_max, &p);
+ }
+ } else if (!strcmp(parameter, "client_port")) {
+ if (*p == '=') {
+ p++;
+ rtsp_parse_range(&th->client_port_min,
+ &th->client_port_max, &p);
+ }
+ } else if (!strcmp(parameter, "server_port")) {
+ if (*p == '=') {
+ p++;
+ rtsp_parse_range(&th->server_port_min,
+ &th->server_port_max, &p);
+ }
+ } else if (!strcmp(parameter, "interleaved")) {
+ if (*p == '=') {
+ p++;
+ rtsp_parse_range(&th->interleaved_min,
+ &th->interleaved_max, &p);
+ }
+ } else if (!strcmp(parameter, "multicast")) {
+ if (th->protocol == RTSP_PROTOCOL_RTP_UDP)
+ th->protocol = RTSP_PROTOCOL_RTP_UDP_MULTICAST;
+ } else if (!strcmp(parameter, "ttl")) {
+ if (*p == '=') {
+ p++;
+ th->ttl = strtol(p, (char **)&p, 10);
+ }
+ } else if (!strcmp(parameter, "destination")) {
+ struct in_addr ipaddr;
+
+ if (*p == '=') {
+ p++;
+ get_word_sep(buf, sizeof(buf), ";,", &p);
+ if (inet_aton(buf, &ipaddr))
+ th->destination = ntohl(ipaddr.s_addr);
+ }
+ }
+ while (*p != ';' && *p != '\0' && *p != ',')
+ p++;
+ if (*p == ';')
+ p++;
+ }
+ if (*p == ',')
+ p++;
+
+ reply->nb_transports++;
+ }
+}
+
+void rtsp_parse_line(RTSPHeader *reply, const char *buf)
+{
+ const char *p;
+
+ /* NOTE: we do case independent match for broken servers */
+ p = buf;
+ if (stristart(p, "Session:", &p)) {
+ get_word_sep(reply->session_id, sizeof(reply->session_id), ";", &p);
+ } else if (stristart(p, "Content-Length:", &p)) {
+ reply->content_length = strtol(p, NULL, 10);
+ } else if (stristart(p, "Transport:", &p)) {
+ rtsp_parse_transport(reply, p);
+ } else if (stristart(p, "CSeq:", &p)) {
+ reply->seq = strtol(p, NULL, 10);
+ } else if (stristart(p, "Range:", &p)) {
+ rtsp_parse_range_npt(p, &reply->range_start, &reply->range_end);
+ }
+}
+
+static int url_readbuf(URLContext *h, unsigned char *buf, int size)
+{
+ int ret, len;
+
+ len = 0;
+ while (len < size) {
+ ret = url_read(h, buf+len, size-len);
+ if (ret < 1)
+ return ret;
+ len += ret;
+ }
+ return len;
+}
+
+/* skip a RTP/TCP interleaved packet */
+static void rtsp_skip_packet(AVFormatContext *s)
+{
+ RTSPState *rt = s->priv_data;
+ int ret, len, len1;
+ uint8_t buf[1024];
+
+ ret = url_readbuf(rt->rtsp_hd, buf, 3);
+ if (ret != 3)
+ return;
+ len = (buf[1] << 8) | buf[2];
+#ifdef DEBUG
+ printf("skipping RTP packet len=%d\n", len);
+#endif
+ /* skip payload */
+ while (len > 0) {
+ len1 = len;
+ if (len1 > sizeof(buf))
+ len1 = sizeof(buf);
+ ret = url_readbuf(rt->rtsp_hd, buf, len1);
+ if (ret != len1)
+ return;
+ len -= len1;
+ }
+}
+
+static void rtsp_send_cmd(AVFormatContext *s,
+ const char *cmd, RTSPHeader *reply,
+ unsigned char **content_ptr)
+{
+ RTSPState *rt = s->priv_data;
+ char buf[4096], buf1[1024], *q;
+ unsigned char ch;
+ const char *p;
+ int content_length, line_count;
+ unsigned char *content = NULL;
+
+ memset(reply, 0, sizeof(RTSPHeader));
+
+ rt->seq++;
+ pstrcpy(buf, sizeof(buf), cmd);
+ snprintf(buf1, sizeof(buf1), "CSeq: %d\r\n", rt->seq);
+ pstrcat(buf, sizeof(buf), buf1);
+ if (rt->session_id[0] != '\0' && !strstr(cmd, "\nIf-Match:")) {
+ snprintf(buf1, sizeof(buf1), "Session: %s\r\n", rt->session_id);
+ pstrcat(buf, sizeof(buf), buf1);
+ }
+ pstrcat(buf, sizeof(buf), "\r\n");
+#ifdef DEBUG
+ printf("Sending:\n%s--\n", buf);
+#endif
+ url_write(rt->rtsp_hd, buf, strlen(buf));
+
+ /* parse reply (XXX: use buffers) */
+ line_count = 0;
+ rt->last_reply[0] = '\0';
+ for(;;) {
+ q = buf;
+ for(;;) {
+ if (url_readbuf(rt->rtsp_hd, &ch, 1) != 1)
+ break;
+ if (ch == '\n')
+ break;
+ if (ch == '$') {
+ /* XXX: only parse it if first char on line ? */
+ rtsp_skip_packet(s);
+ } else if (ch != '\r') {
+ if ((q - buf) < sizeof(buf) - 1)
+ *q++ = ch;
+ }
+ }
+ *q = '\0';
+#ifdef DEBUG
+ printf("line='%s'\n", buf);
+#endif
+ /* test if last line */
+ if (buf[0] == '\0')
+ break;
+ p = buf;
+ if (line_count == 0) {
+ /* get reply code */
+ get_word(buf1, sizeof(buf1), &p);
+ get_word(buf1, sizeof(buf1), &p);
+ reply->status_code = atoi(buf1);
+ } else {
+ rtsp_parse_line(reply, p);
+ pstrcat(rt->last_reply, sizeof(rt->last_reply), p);
+ pstrcat(rt->last_reply, sizeof(rt->last_reply), "\n");
+ }
+ line_count++;
+ }
+
+ if (rt->session_id[0] == '\0' && reply->session_id[0] != '\0')
+ pstrcpy(rt->session_id, sizeof(rt->session_id), reply->session_id);
+
+ content_length = reply->content_length;
+ if (content_length > 0) {
+ /* leave some room for a trailing '\0' (useful for simple parsing) */
+ content = av_malloc(content_length + 1);
+ (void)url_readbuf(rt->rtsp_hd, content, content_length);
+ content[content_length] = '\0';
+ }
+ if (content_ptr)
+ *content_ptr = content;
+}
+
+
+void rtsp_set_callback(FFRTSPCallback *rtsp_cb)
+{
+ ff_rtsp_callback = rtsp_cb;
+}
+
+
+/* close and free RTSP streams */
+static void rtsp_close_streams(RTSPState *rt)
+{
+ 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->rtp_ctx)
+ rtp_parse_close(rtsp_st->rtp_ctx);
+ 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(rtsp_st);
+ }
+ av_free(rt->rtsp_streams);
+}
+
+static int rtsp_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ RTSPState *rt = s->priv_data;
+ char host[1024], path[1024], tcpname[1024], cmd[2048];
+ URLContext *rtsp_hd;
+ int port, i, j, ret, err;
+ RTSPHeader reply1, *reply = &reply1;
+ unsigned char *content = NULL;
+ RTSPStream *rtsp_st;
+ int protocol_mask;
+ AVStream *st;
+
+ /* extract hostname and port */
+ url_split(NULL, 0, NULL, 0,
+ host, sizeof(host), &port, path, sizeof(path), s->filename);
+ if (port < 0)
+ port = RTSP_DEFAULT_PORT;
+
+ /* open the tcp connexion */
+ snprintf(tcpname, sizeof(tcpname), "tcp://%s:%d", host, port);
+ if (url_open(&rtsp_hd, tcpname, URL_RDWR) < 0)
+ return AVERROR_IO;
+ rt->rtsp_hd = rtsp_hd;
+ rt->seq = 0;
+
+ /* describe the stream */
+ snprintf(cmd, sizeof(cmd),
+ "DESCRIBE %s RTSP/1.0\r\n"
+ "Accept: application/sdp\r\n",
+ s->filename);
+ rtsp_send_cmd(s, cmd, reply, &content);
+ if (!content) {
+ err = AVERROR_INVALIDDATA;
+ 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;
+ }
+
+ protocol_mask = rtsp_default_protocols;
+
+ /* for each stream, make the setup request */
+ /* XXX: we assume the same server is used for the control of each
+ RTSP stream */
+
+ for(j = RTSP_RTP_PORT_MIN, i = 0; i < rt->nb_rtsp_streams; ++i) {
+ char transport[2048];
+
+ rtsp_st = rt->rtsp_streams[i];
+
+ /* compute available transports */
+ transport[0] = '\0';
+
+ /* RTP/UDP */
+ if (protocol_mask & (1 << RTSP_PROTOCOL_RTP_UDP)) {
+ char buf[256];
+
+ /* first try in specified port range */
+ if (RTSP_RTP_PORT_MIN != 0) {
+ while(j <= RTSP_RTP_PORT_MAX) {
+ snprintf(buf, sizeof(buf), "rtp://?localport=%d", j);
+ if (url_open(&rtsp_st->rtp_handle, buf, URL_RDWR) == 0) {
+ j += 2; /* we will use two port by rtp stream (rtp and rtcp) */
+ goto rtp_opened;
+ }
+ }
+ }
+
+/* then try on any port
+** if (url_open(&rtsp_st->rtp_handle, "rtp://", URL_RDONLY) < 0) {
+** err = AVERROR_INVALIDDATA;
+** goto fail;
+** }
+*/
+
+ rtp_opened:
+ port = rtp_get_local_port(rtsp_st->rtp_handle);
+ if (transport[0] != '\0')
+ pstrcat(transport, sizeof(transport), ",");
+ snprintf(transport + strlen(transport), sizeof(transport) - strlen(transport) - 1,
+ "RTP/AVP/UDP;unicast;client_port=%d-%d",
+ port, port + 1);
+ }
+
+ /* RTP/TCP */
+ else if (protocol_mask & (1 << RTSP_PROTOCOL_RTP_TCP)) {
+ if (transport[0] != '\0')
+ pstrcat(transport, sizeof(transport), ",");
+ snprintf(transport + strlen(transport), sizeof(transport) - strlen(transport) - 1,
+ "RTP/AVP/TCP");
+ }
+
+ else if (protocol_mask & (1 << RTSP_PROTOCOL_RTP_UDP_MULTICAST)) {
+ if (transport[0] != '\0')
+ pstrcat(transport, sizeof(transport), ",");
+ snprintf(transport + strlen(transport),
+ sizeof(transport) - strlen(transport) - 1,
+ "RTP/AVP/UDP;multicast");
+ }
+ snprintf(cmd, sizeof(cmd),
+ "SETUP %s RTSP/1.0\r\n"
+ "Transport: %s\r\n",
+ rtsp_st->control_url, transport);
+ rtsp_send_cmd(s, cmd, reply, NULL);
+ if (reply->status_code != RTSP_STATUS_OK ||
+ reply->nb_transports != 1) {
+ err = AVERROR_INVALIDDATA;
+ goto fail;
+ }
+
+ /* XXX: same protocol for all streams is required */
+ if (i > 0) {
+ if (reply->transports[0].protocol != rt->protocol) {
+ err = AVERROR_INVALIDDATA;
+ goto fail;
+ }
+ } else {
+ rt->protocol = reply->transports[0].protocol;
+ }
+
+ /* close RTP connection if not choosen */
+ if (reply->transports[0].protocol != RTSP_PROTOCOL_RTP_UDP &&
+ (protocol_mask & (1 << RTSP_PROTOCOL_RTP_UDP))) {
+ url_close(rtsp_st->rtp_handle);
+ rtsp_st->rtp_handle = NULL;
+ }
+
+ switch(reply->transports[0].protocol) {
+ case RTSP_PROTOCOL_RTP_TCP:
+ rtsp_st->interleaved_min = reply->transports[0].interleaved_min;
+ rtsp_st->interleaved_max = reply->transports[0].interleaved_max;
+ break;
+
+ case RTSP_PROTOCOL_RTP_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 (rtp_set_remote_url(rtsp_st->rtp_handle, url) < 0) {
+ err = AVERROR_INVALIDDATA;
+ goto fail;
+ }
+ }
+ break;
+ case RTSP_PROTOCOL_RTP_UDP_MULTICAST:
+ {
+ char url[1024];
+ int ttl;
+
+ ttl = reply->transports[0].ttl;
+ if (!ttl)
+ ttl = 16;
+ snprintf(url, sizeof(url), "rtp://%s:%d?multicast=1&ttl=%d",
+ host,
+ reply->transports[0].server_port_min,
+ ttl);
+ if (url_open(&rtsp_st->rtp_handle, url, URL_RDWR) < 0) {
+ err = AVERROR_INVALIDDATA;
+ goto fail;
+ }
+ }
+ break;
+ }
+ /* open the RTP context */
+ st = NULL;
+ if (rtsp_st->stream_index >= 0)
+ st = s->streams[rtsp_st->stream_index];
+ if (!st)
+ s->ctx_flags |= AVFMTCTX_NOHEADER;
+ rtsp_st->rtp_ctx = rtp_parse_open(s, st, rtsp_st->rtp_handle, rtsp_st->sdp_payload_type, &rtsp_st->rtp_payload_data);
+
+ if (!rtsp_st->rtp_ctx) {
+ err = AVERROR_NOMEM;
+ goto fail;
+ } else {
+ if(rtsp_st->dynamic_handler) {
+ rtsp_st->rtp_ctx->dynamic_protocol_context= rtsp_st->dynamic_protocol_context;
+ rtsp_st->rtp_ctx->parse_packet= rtsp_st->dynamic_handler->parse_packet;
+ }
+ }
+ }
+
+ /* use callback if available to extend setup */
+ if (ff_rtsp_callback) {
+ if (ff_rtsp_callback(RTSP_ACTION_CLIENT_SETUP, rt->session_id,
+ NULL, 0, rt->last_reply) < 0) {
+ err = AVERROR_INVALIDDATA;
+ goto fail;
+ }
+ }
+
+
+ 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;
+ }
+ }
+ return 0;
+ fail:
+ rtsp_close_streams(rt);
+ av_freep(&content);
+ url_close(rt->rtsp_hd);
+ return err;
+}
+
+static int tcp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
+ uint8_t *buf, int buf_size)
+{
+ RTSPState *rt = s->priv_data;
+ int id, len, i, ret;
+ RTSPStream *rtsp_st;
+
+#ifdef DEBUG_RTP_TCP
+ printf("tcp_read_packet:\n");
+#endif
+ redo:
+ for(;;) {
+ ret = url_readbuf(rt->rtsp_hd, buf, 1);
+#ifdef DEBUG_RTP_TCP
+ printf("ret=%d c=%02x [%c]\n", ret, buf[0], buf[0]);
+#endif
+ if (ret != 1)
+ return -1;
+ if (buf[0] == '$')
+ break;
+ }
+ ret = url_readbuf(rt->rtsp_hd, buf, 3);
+ if (ret != 3)
+ return -1;
+ id = buf[0];
+ len = (buf[1] << 8) | buf[2];
+#ifdef DEBUG_RTP_TCP
+ printf("id=%d len=%d\n", id, len);
+#endif
+ if (len > buf_size || len < 12)
+ goto redo;
+ /* get the data */
+ ret = url_readbuf(rt->rtsp_hd, buf, len);
+ if (ret != len)
+ return -1;
+
+ /* find the matching stream */
+ 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:
+ *prtsp_st = rtsp_st;
+ return len;
+}
+
+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 fd1, fd2, fd_max, n, i, ret;
+ struct timeval tv;
+
+ for(;;) {
+ if (url_interrupt_cb())
+ return -1;
+ FD_ZERO(&rfds);
+ fd_max = -1;
+ for(i = 0; i < rt->nb_rtsp_streams; i++) {
+ rtsp_st = rt->rtsp_streams[i];
+ /* currently, we cannot probe RTCP handle because of blocking restrictions */
+ rtp_get_file_handles(rtsp_st->rtp_handle, &fd1, &fd2);
+ if (fd1 > fd_max)
+ fd_max = fd1;
+ FD_SET(fd1, &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];
+ rtp_get_file_handles(rtsp_st->rtp_handle, &fd1, &fd2);
+ if (FD_ISSET(fd1, &rfds)) {
+ ret = url_read(rtsp_st->rtp_handle, buf, buf_size);
+ if (ret > 0) {
+ *prtsp_st = rtsp_st;
+ return ret;
+ }
+ }
+ }
+ }
+ }
+}
+
+static int rtsp_read_packet(AVFormatContext *s,
+ AVPacket *pkt)
+{
+ RTSPState *rt = s->priv_data;
+ RTSPStream *rtsp_st;
+ int ret, len;
+ uint8_t buf[RTP_MAX_PACKET_LENGTH];
+
+ /* get next frames from the same RTP packet */
+ if (rt->cur_rtp) {
+ ret = rtp_parse_packet(rt->cur_rtp, pkt, NULL, 0);
+ if (ret == 0) {
+ rt->cur_rtp = NULL;
+ return 0;
+ } else if (ret == 1) {
+ return 0;
+ } else {
+ rt->cur_rtp = NULL;
+ }
+ }
+
+ /* read next RTP packet */
+ redo:
+ switch(rt->protocol) {
+ default:
+ case RTSP_PROTOCOL_RTP_TCP:
+ len = tcp_read_packet(s, &rtsp_st, buf, sizeof(buf));
+ break;
+ case RTSP_PROTOCOL_RTP_UDP:
+ case RTSP_PROTOCOL_RTP_UDP_MULTICAST:
+ len = udp_read_packet(s, &rtsp_st, buf, sizeof(buf));
+ if (rtsp_st->rtp_ctx)
+ rtp_check_and_send_back_rr(rtsp_st->rtp_ctx, len);
+ break;
+ }
+ if (len < 0)
+ return AVERROR_IO;
+ ret = rtp_parse_packet(rtsp_st->rtp_ctx, pkt, buf, len);
+ if (ret < 0)
+ goto redo;
+ if (ret == 1) {
+ /* more packets may follow, so we save the RTP context */
+ rt->cur_rtp = rtsp_st->rtp_ctx;
+ }
+ return 0;
+}
+
+static int rtsp_read_play(AVFormatContext *s)
+{
+ RTSPState *rt = s->priv_data;
+ RTSPHeader reply1, *reply = &reply1;
+ char cmd[1024];
+
+ av_log(s, AV_LOG_DEBUG, "hello state=%d\n", rt->state);
+
+ 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;
+ } else {
+ rt->state = RTSP_STATE_PLAYING;
+ return 0;
+ }
+}
+
+/* pause the stream */
+static int rtsp_read_pause(AVFormatContext *s)
+{
+ RTSPState *rt = s->priv_data;
+ RTSPHeader reply1, *reply = &reply1;
+ char cmd[1024];
+
+ rt = s->priv_data;
+
+ if (rt->state != RTSP_STATE_PLAYING)
+ return 0;
+
+ snprintf(cmd, sizeof(cmd),
+ "PAUSE %s RTSP/1.0\r\n",
+ s->filename);
+ rtsp_send_cmd(s, cmd, reply, NULL);
+ if (reply->status_code != RTSP_STATUS_OK) {
+ return -1;
+ } else {
+ rt->state = RTSP_STATE_PAUSED;
+ return 0;
+ }
+}
+
+static int rtsp_read_seek(AVFormatContext *s, int stream_index,
+ int64_t timestamp, int flags)
+{
+ RTSPState *rt = s->priv_data;
+
+ rt->seek_timestamp = timestamp;
+ switch(rt->state) {
+ default:
+ case RTSP_STATE_IDLE:
+ break;
+ case RTSP_STATE_PLAYING:
+ if (rtsp_read_play(s) != 0)
+ return -1;
+ break;
+ case RTSP_STATE_PAUSED:
+ rt->state = RTSP_STATE_IDLE;
+ break;
+ }
+ return 0;
+}
+
+static int rtsp_read_close(AVFormatContext *s)
+{
+ RTSPState *rt = s->priv_data;
+ RTSPHeader reply1, *reply = &reply1;
+ char cmd[1024];
+
+#if 0
+ /* NOTE: it is valid to flush the buffer here */
+ if (rt->protocol == RTSP_PROTOCOL_RTP_TCP) {
+ 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);
+
+ if (ff_rtsp_callback) {
+ ff_rtsp_callback(RTSP_ACTION_CLIENT_TEARDOWN, rt->session_id,
+ NULL, 0, NULL);
+ }
+
+ rtsp_close_streams(rt);
+ url_close(rt->rtsp_hd);
+ return 0;
+}
+
+AVInputFormat rtsp_demuxer = {
+ "rtsp",
+ "RTSP input format",
+ sizeof(RTSPState),
+ rtsp_probe,
+ rtsp_read_header,
+ rtsp_read_packet,
+ rtsp_read_close,
+ rtsp_read_seek,
+ .flags = AVFMT_NOFILE,
+ .read_play = rtsp_read_play,
+ .read_pause = rtsp_read_pause,
+};
+
+static int sdp_probe(AVProbeData *p1)
+{
+ const char *p = p1->buf, *p_end = p1->buf + p1->buf_size;
+
+ /* we look for a line beginning "c=IN IP4" */
+ while (p < p_end && *p != '\0') {
+ if (p + sizeof("c=IN IP4") - 1 < p_end && strstart(p, "c=IN IP4", NULL))
+ return AVPROBE_SCORE_MAX / 2;
+
+ while(p < p_end - 1 && *p != '\n') p++;
+ if (++p >= p_end)
+ break;
+ if (*p == '\r')
+ p++;
+ }
+ return 0;
+}
+
+#define SDP_MAX_SIZE 8192
+
+static int sdp_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ RTSPState *rt = s->priv_data;
+ RTSPStream *rtsp_st;
+ int size, i, err;
+ char *content;
+ char url[1024];
+ AVStream *st;
+
+ /* read the whole sdp file */
+ /* XXX: better loading */
+ content = av_malloc(SDP_MAX_SIZE);
+ size = get_buffer(&s->pb, content, SDP_MAX_SIZE - 1);
+ if (size <= 0) {
+ av_free(content);
+ return AVERROR_INVALIDDATA;
+ }
+ content[size] ='\0';
+
+ sdp_parse(s, content);
+ av_free(content);
+
+ /* open each RTP stream */
+ for(i=0;i<rt->nb_rtsp_streams;i++) {
+ rtsp_st = rt->rtsp_streams[i];
+
+ snprintf(url, sizeof(url), "rtp://%s:%d?multicast=1&ttl=%d",
+ inet_ntoa(rtsp_st->sdp_ip),
+ rtsp_st->sdp_port,
+ rtsp_st->sdp_ttl);
+ if (url_open(&rtsp_st->rtp_handle, url, URL_RDWR) < 0) {
+ err = AVERROR_INVALIDDATA;
+ goto fail;
+ }
+ /* open the RTP context */
+ st = NULL;
+ if (rtsp_st->stream_index >= 0)
+ st = s->streams[rtsp_st->stream_index];
+ if (!st)
+ s->ctx_flags |= AVFMTCTX_NOHEADER;
+ rtsp_st->rtp_ctx = rtp_parse_open(s, st, rtsp_st->rtp_handle, rtsp_st->sdp_payload_type, &rtsp_st->rtp_payload_data);
+ if (!rtsp_st->rtp_ctx) {
+ err = AVERROR_NOMEM;
+ goto fail;
+ } else {
+ if(rtsp_st->dynamic_handler) {
+ rtsp_st->rtp_ctx->dynamic_protocol_context= rtsp_st->dynamic_protocol_context;
+ rtsp_st->rtp_ctx->parse_packet= rtsp_st->dynamic_handler->parse_packet;
+ }
+ }
+ }
+ return 0;
+ fail:
+ rtsp_close_streams(rt);
+ 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);
+ return 0;
+}
+
+#ifdef CONFIG_SDP_DEMUXER
+AVInputFormat sdp_demuxer = {
+ "sdp",
+ "SDP",
+ sizeof(RTSPState),
+ sdp_probe,
+ sdp_read_header,
+ sdp_read_packet,
+ sdp_read_close,
+};
+#endif
+
+/* dummy redirector format (used directly in av_open_input_file now) */
+static int redir_probe(AVProbeData *pd)
+{
+ const char *p;
+ p = pd->buf;
+ while (redir_isspace(*p))
+ p++;
+ if (strstart(p, "http://", NULL) ||
+ strstart(p, "rtsp://", NULL))
+ return AVPROBE_SCORE_MAX;
+ return 0;
+}
+
+/* called from utils.c */
+int redir_open(AVFormatContext **ic_ptr, ByteIOContext *f)
+{
+ char buf[4096], *q;
+ int c;
+ AVFormatContext *ic = NULL;
+
+ /* 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;
+ }
+ *ic_ptr = ic;
+ if (!ic)
+ return AVERROR_IO;
+ else
+ return 0;
+}
+
+AVInputFormat redir_demuxer = {
+ "redir",
+ "Redirector format",
+ 0,
+ redir_probe,
+ NULL,
+ NULL,
+ NULL,
+};
diff --git a/contrib/ffmpeg/libavformat/rtsp.h b/contrib/ffmpeg/libavformat/rtsp.h
new file mode 100644
index 000000000..481e2ba49
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/rtsp.h
@@ -0,0 +1,94 @@
+/*
+ * RTSP definitions
+ * 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
+ */
+#ifndef RTSP_H
+#define RTSP_H
+
+#include "rtspcodes.h"
+
+enum RTSPProtocol {
+ RTSP_PROTOCOL_RTP_UDP = 0,
+ RTSP_PROTOCOL_RTP_TCP = 1,
+ RTSP_PROTOCOL_RTP_UDP_MULTICAST = 2,
+};
+
+#define RTSP_DEFAULT_PORT 554
+#define RTSP_MAX_TRANSPORTS 8
+#define RTSP_TCP_MAX_PACKET_SIZE 1472
+#define RTSP_DEFAULT_NB_AUDIO_CHANNELS 2
+#define RTSP_DEFAULT_AUDIO_SAMPLERATE 44100
+#define RTSP_RTP_PORT_MIN 5000
+#define RTSP_RTP_PORT_MAX 10000
+
+typedef struct RTSPTransportField {
+ int interleaved_min, interleaved_max; /**< interleave ids, if TCP transport */
+ int port_min, port_max; /**< RTP ports */
+ int client_port_min, client_port_max; /**< RTP ports */
+ int server_port_min, server_port_max; /**< RTP ports */
+ int ttl; /**< ttl value */
+ uint32_t destination; /**< destination IP address */
+ enum RTSPProtocol protocol;
+} RTSPTransportField;
+
+typedef struct RTSPHeader {
+ int content_length;
+ enum RTSPStatusCode status_code; /**< response code from server */
+ int nb_transports;
+ /** in AV_TIME_BASE unit, AV_NOPTS_VALUE if not used */
+ int64_t range_start, range_end;
+ RTSPTransportField transports[RTSP_MAX_TRANSPORTS];
+ int seq; /**< sequence number */
+ char session_id[512];
+} RTSPHeader;
+
+/** the callback can be used to extend the connection setup/teardown step */
+enum RTSPCallbackAction {
+ RTSP_ACTION_SERVER_SETUP,
+ RTSP_ACTION_SERVER_TEARDOWN,
+ RTSP_ACTION_CLIENT_SETUP,
+ RTSP_ACTION_CLIENT_TEARDOWN,
+};
+
+typedef struct RTSPActionServerSetup {
+ uint32_t ipaddr;
+ char transport_option[512];
+} RTSPActionServerSetup;
+
+typedef int FFRTSPCallback(enum RTSPCallbackAction action,
+ const char *session_id,
+ char *buf, int buf_size,
+ void *arg);
+
+/** useful for modules: set RTSP callback function */
+void rtsp_set_callback(FFRTSPCallback *rtsp_cb);
+
+int rtsp_init(void);
+void rtsp_parse_line(RTSPHeader *reply, const char *buf);
+
+extern int rtsp_default_protocols;
+extern int rtsp_rtp_port_min;
+extern int rtsp_rtp_port_max;
+extern FFRTSPCallback *ff_rtsp_callback;
+extern AVInputFormat rtsp_demuxer;
+
+int rtsp_pause(AVFormatContext *s);
+int rtsp_resume(AVFormatContext *s);
+
+#endif /* RTSP_H */
diff --git a/contrib/ffmpeg/libavformat/rtspcodes.h b/contrib/ffmpeg/libavformat/rtspcodes.h
new file mode 100644
index 000000000..74cfb5d5b
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/rtspcodes.h
@@ -0,0 +1,36 @@
+/*
+ * RTSP definitions
+ * 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
+ */
+
+/** RTSP handling */
+enum RTSPStatusCode {
+RTSP_STATUS_OK =200, /**< OK */
+RTSP_STATUS_METHOD =405, /**< Method Not Allowed */
+RTSP_STATUS_BANDWIDTH =453, /**< Not Enough Bandwidth */
+RTSP_STATUS_SESSION =454, /**< Session Not Found */
+RTSP_STATUS_STATE =455, /**< Method Not Valid in This State */
+RTSP_STATUS_AGGREGATE =459, /**< Aggregate operation not allowed */
+RTSP_STATUS_ONLY_AGGREGATE =460, /**< Only aggregate operation allowed */
+RTSP_STATUS_TRANSPORT =461, /**< Unsupported transport */
+RTSP_STATUS_INTERNAL =500, /**< Internal Server Error */
+RTSP_STATUS_SERVICE =503, /**< Service Unavailable */
+RTSP_STATUS_VERSION =505, /**< RTSP Version not supported */
+};
+
diff --git a/contrib/ffmpeg/libavformat/segafilm.c b/contrib/ffmpeg/libavformat/segafilm.c
new file mode 100644
index 000000000..b5375ccf7
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/segafilm.c
@@ -0,0 +1,295 @@
+/*
+ * Sega FILM Format (CPK) Demuxer
+ * Copyright (c) 2003 The ffmpeg Project
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file segafilm.c
+ * Sega FILM (.cpk) file demuxer
+ * by Mike Melanson (melanson@pcisys.net)
+ * For more information regarding the Sega FILM file format, visit:
+ * http://www.pcisys.net/~melanson/codecs/
+ */
+
+#include "avformat.h"
+
+#define FILM_TAG MKBETAG('F', 'I', 'L', 'M')
+#define FDSC_TAG MKBETAG('F', 'D', 'S', 'C')
+#define STAB_TAG MKBETAG('S', 'T', 'A', 'B')
+#define CVID_TAG MKBETAG('c', 'v', 'i', 'd')
+
+typedef struct {
+ int stream;
+ offset_t sample_offset;
+ unsigned int sample_size;
+ int64_t pts;
+ int keyframe;
+} film_sample_t;
+
+typedef struct FilmDemuxContext {
+ int video_stream_index;
+ int audio_stream_index;
+
+ unsigned int audio_type;
+ unsigned int audio_samplerate;
+ unsigned int audio_bits;
+ unsigned int audio_channels;
+
+ unsigned int video_type;
+ unsigned int sample_count;
+ film_sample_t *sample_table;
+ unsigned int current_sample;
+
+ unsigned int base_clock;
+ unsigned int version;
+
+ /* buffer used for interleaving stereo PCM data */
+ unsigned char *stereo_buffer;
+ int stereo_buffer_size;
+} FilmDemuxContext;
+
+static int film_probe(AVProbeData *p)
+{
+ if (p->buf_size < 4)
+ return 0;
+
+ if (AV_RB32(&p->buf[0]) != FILM_TAG)
+ return 0;
+
+ return AVPROBE_SCORE_MAX;
+}
+
+static int film_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ FilmDemuxContext *film = (FilmDemuxContext *)s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ AVStream *st;
+ unsigned char scratch[256];
+ int i;
+ unsigned int data_offset;
+ unsigned int audio_frame_counter;
+
+ film->sample_table = NULL;
+ film->stereo_buffer = NULL;
+ film->stereo_buffer_size = 0;
+
+ /* load the main FILM header */
+ if (get_buffer(pb, scratch, 16) != 16)
+ return AVERROR_IO;
+ data_offset = AV_RB32(&scratch[4]);
+ film->version = AV_RB32(&scratch[8]);
+
+ /* load the FDSC chunk */
+ if (film->version == 0) {
+ /* special case for Lemmings .film files; 20-byte header */
+ if (get_buffer(pb, scratch, 20) != 20)
+ return AVERROR_IO;
+ /* make some assumptions about the audio parameters */
+ film->audio_type = CODEC_ID_PCM_S8;
+ film->audio_samplerate = 22050;
+ film->audio_channels = 1;
+ film->audio_bits = 8;
+ } else {
+ /* normal Saturn .cpk files; 32-byte header */
+ if (get_buffer(pb, scratch, 32) != 32)
+ return AVERROR_IO;
+ film->audio_samplerate = AV_RB16(&scratch[24]);;
+ film->audio_channels = scratch[21];
+ film->audio_bits = scratch[22];
+ if (film->audio_bits == 8)
+ film->audio_type = CODEC_ID_PCM_S8;
+ else if (film->audio_bits == 16)
+ film->audio_type = CODEC_ID_PCM_S16BE;
+ else
+ film->audio_type = 0;
+ }
+
+ if (AV_RB32(&scratch[0]) != FDSC_TAG)
+ return AVERROR_INVALIDDATA;
+
+ if (AV_RB32(&scratch[8]) == CVID_TAG) {
+ film->video_type = CODEC_ID_CINEPAK;
+ } else
+ film->video_type = 0;
+
+ /* initialize the decoder streams */
+ if (film->video_type) {
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+ film->video_stream_index = st->index;
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ st->codec->codec_id = film->video_type;
+ st->codec->codec_tag = 0; /* no fourcc */
+ st->codec->width = AV_RB32(&scratch[16]);
+ st->codec->height = AV_RB32(&scratch[12]);
+ }
+
+ if (film->audio_type) {
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+ film->audio_stream_index = st->index;
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_id = film->audio_type;
+ st->codec->codec_tag = 1;
+ st->codec->channels = film->audio_channels;
+ st->codec->bits_per_sample = film->audio_bits;
+ st->codec->sample_rate = film->audio_samplerate;
+ st->codec->bit_rate = st->codec->channels * st->codec->sample_rate *
+ st->codec->bits_per_sample;
+ st->codec->block_align = st->codec->channels *
+ st->codec->bits_per_sample / 8;
+ }
+
+ /* load the sample table */
+ if (get_buffer(pb, scratch, 16) != 16)
+ return AVERROR_IO;
+ if (AV_RB32(&scratch[0]) != STAB_TAG)
+ return AVERROR_INVALIDDATA;
+ film->base_clock = AV_RB32(&scratch[8]);
+ film->sample_count = AV_RB32(&scratch[12]);
+ if(film->sample_count >= UINT_MAX / sizeof(film_sample_t))
+ return -1;
+ film->sample_table = av_malloc(film->sample_count * sizeof(film_sample_t));
+
+ for(i=0; i<s->nb_streams; i++)
+ av_set_pts_info(s->streams[i], 33, 1, film->base_clock);
+
+ audio_frame_counter = 0;
+ for (i = 0; i < film->sample_count; i++) {
+ /* load the next sample record and transfer it to an internal struct */
+ if (get_buffer(pb, scratch, 16) != 16) {
+ av_free(film->sample_table);
+ return AVERROR_IO;
+ }
+ film->sample_table[i].sample_offset =
+ data_offset + AV_RB32(&scratch[0]);
+ film->sample_table[i].sample_size = AV_RB32(&scratch[4]);
+ if (AV_RB32(&scratch[8]) == 0xFFFFFFFF) {
+ film->sample_table[i].stream = film->audio_stream_index;
+ film->sample_table[i].pts = audio_frame_counter;
+ film->sample_table[i].pts *= film->base_clock;
+ film->sample_table[i].pts /= film->audio_samplerate;
+
+ audio_frame_counter += (film->sample_table[i].sample_size /
+ (film->audio_channels * film->audio_bits / 8));
+ } else {
+ film->sample_table[i].stream = film->video_stream_index;
+ film->sample_table[i].pts = AV_RB32(&scratch[8]) & 0x7FFFFFFF;
+ film->sample_table[i].keyframe = (scratch[8] & 0x80) ? 0 : 1;
+ }
+ }
+
+ film->current_sample = 0;
+
+ return 0;
+}
+
+static int film_read_packet(AVFormatContext *s,
+ AVPacket *pkt)
+{
+ FilmDemuxContext *film = (FilmDemuxContext *)s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ film_sample_t *sample;
+ int ret = 0;
+ int i;
+ int left, right;
+
+ if (film->current_sample >= film->sample_count)
+ return AVERROR_IO;
+
+ sample = &film->sample_table[film->current_sample];
+
+ /* position the stream (will probably be there anyway) */
+ url_fseek(pb, sample->sample_offset, SEEK_SET);
+
+ /* do a special song and dance when loading FILM Cinepak chunks */
+ if ((sample->stream == film->video_stream_index) &&
+ (film->video_type == CODEC_ID_CINEPAK)) {
+ pkt->pos= url_ftell(pb);
+ if (av_new_packet(pkt, sample->sample_size))
+ return AVERROR_NOMEM;
+ get_buffer(pb, pkt->data, sample->sample_size);
+ } else if ((sample->stream == film->audio_stream_index) &&
+ (film->audio_channels == 2)) {
+ /* stereo PCM needs to be interleaved */
+
+ if (av_new_packet(pkt, sample->sample_size))
+ return AVERROR_NOMEM;
+
+ /* make sure the interleave buffer is large enough */
+ if (sample->sample_size > film->stereo_buffer_size) {
+ av_free(film->stereo_buffer);
+ film->stereo_buffer_size = sample->sample_size;
+ film->stereo_buffer = av_malloc(film->stereo_buffer_size);
+ }
+
+ pkt->pos= url_ftell(pb);
+ ret = get_buffer(pb, film->stereo_buffer, sample->sample_size);
+ if (ret != sample->sample_size)
+ ret = AVERROR_IO;
+
+ left = 0;
+ right = sample->sample_size / 2;
+ for (i = 0; i < sample->sample_size; ) {
+ if (film->audio_bits == 8) {
+ pkt->data[i++] = film->stereo_buffer[left++];
+ pkt->data[i++] = film->stereo_buffer[right++];
+ } else {
+ pkt->data[i++] = film->stereo_buffer[left++];
+ pkt->data[i++] = film->stereo_buffer[left++];
+ pkt->data[i++] = film->stereo_buffer[right++];
+ pkt->data[i++] = film->stereo_buffer[right++];
+ }
+ }
+ } else {
+ ret= av_get_packet(pb, pkt, sample->sample_size);
+ if (ret != sample->sample_size)
+ ret = AVERROR_IO;
+ }
+
+ pkt->stream_index = sample->stream;
+ pkt->pts = sample->pts;
+
+ film->current_sample++;
+
+ return ret;
+}
+
+static int film_read_close(AVFormatContext *s)
+{
+ FilmDemuxContext *film = (FilmDemuxContext *)s->priv_data;
+
+ av_free(film->sample_table);
+ av_free(film->stereo_buffer);
+
+ return 0;
+}
+
+AVInputFormat segafilm_demuxer = {
+ "film_cpk",
+ "Sega FILM/CPK format",
+ sizeof(FilmDemuxContext),
+ film_probe,
+ film_read_header,
+ film_read_packet,
+ film_read_close,
+};
diff --git a/contrib/ffmpeg/libavformat/sierravmd.c b/contrib/ffmpeg/libavformat/sierravmd.c
new file mode 100644
index 000000000..3e1c8597d
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/sierravmd.c
@@ -0,0 +1,302 @@
+/*
+ * Sierra VMD Format Demuxer
+ * Copyright (c) 2004 The ffmpeg Project
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file sierravmd.c
+ * Sierra VMD file demuxer
+ * by Vladimir "VAG" Gneushev (vagsoft at mail.ru)
+ * for more information on the Sierra VMD file format, visit:
+ * http://www.pcisys.net/~melanson/codecs/
+ */
+
+#include "avformat.h"
+
+#define VMD_HEADER_SIZE 0x0330
+#define BYTES_PER_FRAME_RECORD 16
+
+typedef struct {
+ int stream_index;
+ offset_t frame_offset;
+ unsigned int frame_size;
+ int64_t pts;
+ int keyframe;
+ unsigned char frame_record[BYTES_PER_FRAME_RECORD];
+} vmd_frame_t;
+
+typedef struct VmdDemuxContext {
+ int video_stream_index;
+ int audio_stream_index;
+
+ unsigned int frame_count;
+ unsigned int frames_per_block;
+ vmd_frame_t *frame_table;
+ unsigned int current_frame;
+
+ int sample_rate;
+ int64_t audio_sample_counter;
+ int skiphdr;
+
+ unsigned char vmd_header[VMD_HEADER_SIZE];
+} VmdDemuxContext;
+
+static int vmd_probe(AVProbeData *p)
+{
+ if (p->buf_size < 2)
+ 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;
+
+ /* only return half certainty since this check is a bit sketchy */
+ return AVPROBE_SCORE_MAX / 2;
+}
+
+static int vmd_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ VmdDemuxContext *vmd = (VmdDemuxContext *)s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ AVStream *st, *vst;
+ unsigned int toc_offset;
+ unsigned char *raw_frame_table;
+ int raw_frame_table_size;
+ offset_t current_offset;
+ int i, j;
+ unsigned int total_frames;
+ int64_t pts_inc = 1;
+ int64_t current_video_pts = 0, current_audio_pts = 0;
+ unsigned char chunk[BYTES_PER_FRAME_RECORD];
+ int num, den;
+ int sound_buffers;
+
+ /* fetch the main header, including the 2 header length bytes */
+ url_fseek(pb, 0, SEEK_SET);
+ if (get_buffer(pb, vmd->vmd_header, VMD_HEADER_SIZE) != VMD_HEADER_SIZE)
+ return AVERROR_IO;
+
+ /* start up the decoders */
+ vst = av_new_stream(s, 0);
+ if (!vst)
+ return AVERROR_NOMEM;
+ av_set_pts_info(vst, 33, 1, 10);
+ vmd->video_stream_index = vst->index;
+ vst->codec->codec_type = CODEC_TYPE_VIDEO;
+ vst->codec->codec_id = CODEC_ID_VMDVIDEO;
+ vst->codec->codec_tag = 0; /* no fourcc */
+ vst->codec->width = AV_RL16(&vmd->vmd_header[12]);
+ vst->codec->height = AV_RL16(&vmd->vmd_header[14]);
+ vst->codec->extradata_size = VMD_HEADER_SIZE;
+ vst->codec->extradata = av_mallocz(VMD_HEADER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
+ memcpy(vst->codec->extradata, vmd->vmd_header, VMD_HEADER_SIZE);
+
+ /* if sample rate is 0, assume no audio */
+ vmd->sample_rate = AV_RL16(&vmd->vmd_header[804]);
+ if (vmd->sample_rate) {
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+ vmd->audio_stream_index = st->index;
+ st->codec->codec_type = CODEC_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;
+ st->codec->sample_rate = vmd->sample_rate;
+ st->codec->block_align = AV_RL16(&vmd->vmd_header[806]);
+ if (st->codec->block_align & 0x8000) {
+ st->codec->bits_per_sample = 16;
+ st->codec->block_align = -(st->codec->block_align - 0x10000);
+ } else {
+ st->codec->bits_per_sample = 8;
+ }
+ st->codec->bit_rate = st->codec->sample_rate *
+ st->codec->bits_per_sample * st->codec->channels;
+
+ /* calculate pts */
+ num = st->codec->block_align;
+ den = st->codec->sample_rate * st->codec->channels;
+ av_reduce(&den, &num, den, num, (1UL<<31)-1);
+ av_set_pts_info(vst, 33, num, den);
+ av_set_pts_info(st, 33, num, den);
+ pts_inc = num;
+ }
+
+ toc_offset = AV_RL32(&vmd->vmd_header[812]);
+ vmd->frame_count = AV_RL16(&vmd->vmd_header[6]);
+ vmd->frames_per_block = AV_RL16(&vmd->vmd_header[18]);
+ url_fseek(pb, toc_offset, SEEK_SET);
+
+ raw_frame_table = NULL;
+ vmd->frame_table = NULL;
+ sound_buffers = AV_RL16(&vmd->vmd_header[808]);
+ raw_frame_table_size = vmd->frame_count * 6;
+ raw_frame_table = av_malloc(raw_frame_table_size);
+ if(vmd->frame_count * vmd->frames_per_block >= UINT_MAX / sizeof(vmd_frame_t)){
+ av_log(s, AV_LOG_ERROR, "vmd->frame_count * vmd->frames_per_block too large\n");
+ return -1;
+ }
+ vmd->frame_table = av_malloc((vmd->frame_count * vmd->frames_per_block + sound_buffers) * sizeof(vmd_frame_t));
+ if (!raw_frame_table || !vmd->frame_table) {
+ av_free(raw_frame_table);
+ av_free(vmd->frame_table);
+ return AVERROR_NOMEM;
+ }
+ if (get_buffer(pb, raw_frame_table, raw_frame_table_size) !=
+ raw_frame_table_size) {
+ av_free(raw_frame_table);
+ av_free(vmd->frame_table);
+ return AVERROR_IO;
+ }
+
+ total_frames = 0;
+ for (i = 0; i < vmd->frame_count; i++) {
+
+ current_offset = AV_RL32(&raw_frame_table[6 * i + 2]);
+
+ /* handle each entry in index block */
+ for (j = 0; j < vmd->frames_per_block; j++) {
+ int type;
+ uint32_t size;
+
+ get_buffer(pb, chunk, BYTES_PER_FRAME_RECORD);
+ type = chunk[0];
+ size = AV_RL32(&chunk[2]);
+ if(!size)
+ continue;
+ switch(type) {
+ case 1: /* Audio Chunk */
+ /* first audio chunk contains several audio buffers */
+ if(current_audio_pts){
+ vmd->frame_table[total_frames].frame_offset = current_offset;
+ vmd->frame_table[total_frames].stream_index = vmd->audio_stream_index;
+ vmd->frame_table[total_frames].frame_size = size;
+ memcpy(vmd->frame_table[total_frames].frame_record, chunk, BYTES_PER_FRAME_RECORD);
+ vmd->frame_table[total_frames].pts = current_audio_pts;
+ total_frames++;
+ current_audio_pts += pts_inc;
+ }else{
+ uint32_t flags;
+ int k;
+ int noff;
+ int64_t pos;
+
+ pos = url_ftell(pb);
+ url_fseek(pb, current_offset, SEEK_SET);
+ flags = get_le32(pb);
+ noff = 4;
+ url_fseek(pb, pos, SEEK_SET);
+ av_log(s, AV_LOG_DEBUG, "Sound mapping = %08X (%i bufs)\n", flags, sound_buffers);
+ for(k = 0; k < sound_buffers - 1; k++){
+ if(flags & 1) { /* silent block */
+ vmd->frame_table[total_frames].frame_size = 0;
+ }else{
+ vmd->frame_table[total_frames].frame_size = st->codec->block_align + (st->codec->block_align & 1);
+ }
+ noff += vmd->frame_table[total_frames].frame_size;
+ vmd->frame_table[total_frames].frame_offset = current_offset + noff;
+ vmd->frame_table[total_frames].stream_index = vmd->audio_stream_index;
+ memcpy(vmd->frame_table[total_frames].frame_record, chunk, BYTES_PER_FRAME_RECORD);
+ vmd->frame_table[total_frames].pts = current_audio_pts;
+ total_frames++;
+ current_audio_pts += pts_inc;
+ flags >>= 1;
+ }
+ }
+ break;
+ case 2: /* Video Chunk */
+ vmd->frame_table[total_frames].frame_offset = current_offset;
+ vmd->frame_table[total_frames].stream_index = vmd->video_stream_index;
+ vmd->frame_table[total_frames].frame_size = size;
+ memcpy(vmd->frame_table[total_frames].frame_record, chunk, BYTES_PER_FRAME_RECORD);
+ vmd->frame_table[total_frames].pts = current_video_pts;
+ total_frames++;
+ break;
+ }
+ current_offset += size;
+ }
+ current_video_pts += pts_inc;
+ }
+
+ av_free(raw_frame_table);
+
+ vmd->current_frame = 0;
+ vmd->frame_count = total_frames;
+
+ return 0;
+}
+
+static int vmd_read_packet(AVFormatContext *s,
+ AVPacket *pkt)
+{
+ VmdDemuxContext *vmd = (VmdDemuxContext *)s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ int ret = 0;
+ vmd_frame_t *frame;
+
+ if (vmd->current_frame >= vmd->frame_count)
+ return AVERROR_IO;
+
+ frame = &vmd->frame_table[vmd->current_frame];
+ /* position the stream (will probably be there already) */
+ url_fseek(pb, frame->frame_offset, SEEK_SET);
+
+ if (av_new_packet(pkt, frame->frame_size + BYTES_PER_FRAME_RECORD))
+ return AVERROR_NOMEM;
+ pkt->pos= url_ftell(pb);
+ memcpy(pkt->data, frame->frame_record, BYTES_PER_FRAME_RECORD);
+ ret = get_buffer(pb, pkt->data + BYTES_PER_FRAME_RECORD,
+ frame->frame_size);
+
+ if (ret != frame->frame_size) {
+ av_free_packet(pkt);
+ ret = AVERROR_IO;
+ }
+ pkt->stream_index = frame->stream_index;
+ pkt->pts = frame->pts;
+ av_log(NULL, AV_LOG_INFO, " dispatching %s frame with %d bytes and pts %"PRId64"\n",
+ (frame->frame_record[0] == 0x02) ? "video" : "audio",
+ frame->frame_size + BYTES_PER_FRAME_RECORD,
+ pkt->pts);
+
+ vmd->current_frame++;
+
+ return ret;
+}
+
+static int vmd_read_close(AVFormatContext *s)
+{
+ VmdDemuxContext *vmd = (VmdDemuxContext *)s->priv_data;
+
+ av_free(vmd->frame_table);
+
+ return 0;
+}
+
+AVInputFormat vmd_demuxer = {
+ "vmd",
+ "Sierra VMD format",
+ sizeof(VmdDemuxContext),
+ vmd_probe,
+ vmd_read_header,
+ vmd_read_packet,
+ vmd_read_close,
+};
diff --git a/contrib/ffmpeg/libavformat/smacker.c b/contrib/ffmpeg/libavformat/smacker.c
new file mode 100644
index 000000000..04fde3d03
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/smacker.c
@@ -0,0 +1,345 @@
+/*
+ * Smacker demuxer
+ * Copyright (c) 2006 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
+ */
+
+/*
+ * Based on http://wiki.multimedia.cx/index.php?title=Smacker
+ */
+
+#include "avformat.h"
+#include "riff.h"
+#include "bswap.h"
+
+#define SMACKER_PAL 0x01
+
+enum SAudFlags {
+ SMK_AUD_PACKED = 0x80000000,
+ SMK_AUD_16BITS = 0x20000000,
+ SMK_AUD_STEREO = 0x10000000,
+ SMK_AUD_BINKAUD = 0x08000000,
+ SMK_AUD_USEDCT = 0x04000000
+};
+
+typedef struct SmackerContext {
+ /* Smacker file header */
+ uint32_t magic;
+ uint32_t width, height;
+ uint32_t frames;
+ int pts_inc;
+ uint32_t flags;
+ uint32_t audio[7];
+ uint32_t treesize;
+ uint32_t mmap_size, mclr_size, full_size, type_size;
+ uint32_t rates[7];
+ uint32_t pad;
+ /* frame info */
+ uint32_t *frm_size;
+ uint8_t *frm_flags;
+ /* internal variables */
+ int cur_frame;
+ int is_ver4;
+ int64_t cur_pts;
+ /* current frame for demuxing */
+ uint8_t pal[768];
+ int indexes[7];
+ int videoindex;
+ uint8_t *bufs[7];
+ int buf_sizes[7];
+ int stream_id[7];
+ int curstream;
+ offset_t nextpos;
+ int64_t aud_pts[7];
+} SmackerContext;
+
+typedef struct SmackerFrame {
+ int64_t pts;
+ int stream;
+} SmackerFrame;
+
+/* palette used in Smacker */
+static const uint8_t smk_pal[64] = {
+ 0x00, 0x04, 0x08, 0x0C, 0x10, 0x14, 0x18, 0x1C,
+ 0x20, 0x24, 0x28, 0x2C, 0x30, 0x34, 0x38, 0x3C,
+ 0x41, 0x45, 0x49, 0x4D, 0x51, 0x55, 0x59, 0x5D,
+ 0x61, 0x65, 0x69, 0x6D, 0x71, 0x75, 0x79, 0x7D,
+ 0x82, 0x86, 0x8A, 0x8E, 0x92, 0x96, 0x9A, 0x9E,
+ 0xA2, 0xA6, 0xAA, 0xAE, 0xB2, 0xB6, 0xBA, 0xBE,
+ 0xC3, 0xC7, 0xCB, 0xCF, 0xD3, 0xD7, 0xDB, 0xDF,
+ 0xE3, 0xE7, 0xEB, 0xEF, 0xF3, 0xF7, 0xFB, 0xFF
+};
+
+
+static int smacker_probe(AVProbeData *p)
+{
+ if (p->buf_size < 4)
+ return 0;
+ if(p->buf[0] == 'S' && p->buf[1] == 'M' && p->buf[2] == 'K'
+ && (p->buf[3] == '2' || p->buf[3] == '4'))
+ return AVPROBE_SCORE_MAX;
+ else
+ return 0;
+}
+
+static int smacker_read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+ ByteIOContext *pb = &s->pb;
+ SmackerContext *smk = (SmackerContext *)s->priv_data;
+ AVStream *st, *ast[7];
+ int i, ret;
+ int tbase;
+
+ /* read and check header */
+ smk->magic = get_le32(pb);
+ if (smk->magic != MKTAG('S', 'M', 'K', '2') && smk->magic != MKTAG('S', 'M', 'K', '4'))
+ return -1;
+ smk->width = get_le32(pb);
+ smk->height = get_le32(pb);
+ smk->frames = get_le32(pb);
+ smk->pts_inc = (int32_t)get_le32(pb);
+ smk->flags = get_le32(pb);
+ for(i = 0; i < 7; i++)
+ smk->audio[i] = get_le32(pb);
+ smk->treesize = get_le32(pb);
+
+ if(smk->treesize >= UINT_MAX/4){ // smk->treesize + 16 must not overflow (this check is probably redundant)
+ av_log(s, AV_LOG_ERROR, "treesize too large\n");
+ return -1;
+ }
+
+//FIXME remove extradata "rebuilding"
+ smk->mmap_size = get_le32(pb);
+ smk->mclr_size = get_le32(pb);
+ smk->full_size = get_le32(pb);
+ smk->type_size = get_le32(pb);
+ for(i = 0; i < 7; i++)
+ smk->rates[i] = get_le32(pb);
+ smk->pad = get_le32(pb);
+ /* setup data */
+ if(smk->frames > 0xFFFFFF) {
+ av_log(s, AV_LOG_ERROR, "Too many frames: %i\n", smk->frames);
+ return -1;
+ }
+ smk->frm_size = av_malloc(smk->frames * 4);
+ smk->frm_flags = av_malloc(smk->frames);
+
+ smk->is_ver4 = (smk->magic != MKTAG('S', 'M', 'K', '2'));
+
+ /* read frame info */
+ for(i = 0; i < smk->frames; i++) {
+ smk->frm_size[i] = get_le32(pb);
+ }
+ for(i = 0; i < smk->frames; i++) {
+ smk->frm_flags[i] = get_byte(pb);
+ }
+
+ /* init video codec */
+ st = av_new_stream(s, 0);
+ if (!st)
+ return -1;
+ smk->videoindex = st->index;
+ 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_id = CODEC_ID_SMACKVIDEO;
+ st->codec->codec_tag = smk->magic;
+ /* Smacker uses 100000 as internal timebase */
+ if(smk->pts_inc < 0)
+ smk->pts_inc = -smk->pts_inc;
+ else
+ smk->pts_inc *= 100;
+ 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);
+ /* 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)){
+ 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->channels = (smk->rates[i] & SMK_AUD_STEREO) ? 2 : 1;
+ ast[i]->codec->sample_rate = smk->rates[i] & 0xFFFFFF;
+ ast[i]->codec->bits_per_sample = (smk->rates[i] & SMK_AUD_16BITS) ? 16 : 8;
+ if(ast[i]->codec->bits_per_sample == 16 && ast[i]->codec->codec_id == CODEC_ID_PCM_U8)
+ ast[i]->codec->codec_id = CODEC_ID_PCM_S16LE;
+ av_set_pts_info(ast[i], 64, 1, ast[i]->codec->sample_rate
+ * ast[i]->codec->channels * ast[i]->codec->bits_per_sample / 8);
+ }
+ }
+
+
+ /* load trees to extradata, they will be unpacked by decoder */
+ st->codec->extradata = av_malloc(smk->treesize + 16);
+ st->codec->extradata_size = smk->treesize + 16;
+ if(!st->codec->extradata){
+ av_log(s, AV_LOG_ERROR, "Cannot allocate %i bytes of extradata\n", smk->treesize + 16);
+ av_free(smk->frm_size);
+ av_free(smk->frm_flags);
+ return -1;
+ }
+ ret = get_buffer(pb, st->codec->extradata + 16, st->codec->extradata_size - 16);
+ if(ret != st->codec->extradata_size - 16){
+ av_free(smk->frm_size);
+ av_free(smk->frm_flags);
+ return AVERROR_IO;
+ }
+ ((int32_t*)st->codec->extradata)[0] = le2me_32(smk->mmap_size);
+ ((int32_t*)st->codec->extradata)[1] = le2me_32(smk->mclr_size);
+ ((int32_t*)st->codec->extradata)[2] = le2me_32(smk->full_size);
+ ((int32_t*)st->codec->extradata)[3] = le2me_32(smk->type_size);
+
+ smk->curstream = -1;
+ smk->nextpos = url_ftell(pb);
+
+ return 0;
+}
+
+
+static int smacker_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ SmackerContext *smk = (SmackerContext *)s->priv_data;
+ int flags;
+ int ret;
+ int i;
+ int frame_size = 0;
+ int palchange = 0;
+ int pos;
+
+ if (url_feof(&s->pb) || smk->cur_frame >= smk->frames)
+ return AVERROR(EIO);
+
+ /* if we demuxed all streams, pass another frame */
+ if(smk->curstream < 0) {
+ url_fseek(&s->pb, smk->nextpos, 0);
+ frame_size = smk->frm_size[smk->cur_frame] & (~3);
+ flags = smk->frm_flags[smk->cur_frame];
+ /* handle palette change event */
+ pos = url_ftell(&s->pb);
+ if(flags & SMACKER_PAL){
+ int size, sz, t, off, j, pos;
+ uint8_t *pal = smk->pal;
+ uint8_t oldpal[768];
+
+ memcpy(oldpal, pal, 768);
+ size = get_byte(&s->pb);
+ size = size * 4 - 1;
+ frame_size -= size;
+ frame_size--;
+ sz = 0;
+ pos = url_ftell(&s->pb) + size;
+ while(sz < 256){
+ t = get_byte(&s->pb);
+ if(t & 0x80){ /* skip palette entries */
+ sz += (t & 0x7F) + 1;
+ pal += ((t & 0x7F) + 1) * 3;
+ } else if(t & 0x40){ /* copy with offset */
+ off = get_byte(&s->pb) * 3;
+ j = (t & 0x3F) + 1;
+ while(j-- && sz < 256) {
+ *pal++ = oldpal[off + 0];
+ *pal++ = oldpal[off + 1];
+ *pal++ = oldpal[off + 2];
+ sz++;
+ off += 3;
+ }
+ } else { /* new entries */
+ *pal++ = smk_pal[t];
+ *pal++ = smk_pal[get_byte(&s->pb) & 0x3F];
+ *pal++ = smk_pal[get_byte(&s->pb) & 0x3F];
+ sz++;
+ }
+ }
+ url_fseek(&s->pb, pos, 0);
+ palchange |= 1;
+ }
+ flags >>= 1;
+ smk->curstream = -1;
+ /* if audio chunks are present, put them to stack and retrieve later */
+ for(i = 0; i < 7; i++) {
+ if(flags & 1) {
+ int size;
+ size = get_le32(&s->pb) - 4;
+ frame_size -= size;
+ frame_size -= 4;
+ smk->curstream++;
+ smk->bufs[smk->curstream] = av_realloc(smk->bufs[smk->curstream], size);
+ smk->buf_sizes[smk->curstream] = size;
+ ret = get_buffer(&s->pb, smk->bufs[smk->curstream], size);
+ if(ret != size)
+ return AVERROR_IO;
+ smk->stream_id[smk->curstream] = smk->indexes[i];
+ }
+ flags >>= 1;
+ }
+ if (av_new_packet(pkt, frame_size + 768))
+ return AVERROR_NOMEM;
+ if(smk->frm_size[smk->cur_frame] & 1)
+ palchange |= 2;
+ pkt->data[0] = palchange;
+ memcpy(pkt->data + 1, smk->pal, 768);
+ ret = get_buffer(&s->pb, pkt->data + 769, frame_size);
+ if(ret != frame_size)
+ return AVERROR_IO;
+ pkt->stream_index = smk->videoindex;
+ pkt->size = ret + 769;
+ smk->cur_frame++;
+ smk->nextpos = url_ftell(&s->pb);
+ } else {
+ if (av_new_packet(pkt, smk->buf_sizes[smk->curstream]))
+ return AVERROR_NOMEM;
+ memcpy(pkt->data, smk->bufs[smk->curstream], smk->buf_sizes[smk->curstream]);
+ pkt->size = smk->buf_sizes[smk->curstream];
+ pkt->stream_index = smk->stream_id[smk->curstream];
+ pkt->pts = smk->aud_pts[smk->curstream];
+ smk->aud_pts[smk->curstream] += AV_RL32(pkt->data);
+ smk->curstream--;
+ }
+
+ return 0;
+}
+
+static int smacker_read_close(AVFormatContext *s)
+{
+ SmackerContext *smk = (SmackerContext *)s->priv_data;
+ int i;
+
+ for(i = 0; i < 7; i++)
+ if(smk->bufs[i])
+ av_free(smk->bufs[i]);
+ if(smk->frm_size)
+ av_free(smk->frm_size);
+ if(smk->frm_flags)
+ av_free(smk->frm_flags);
+
+ return 0;
+}
+
+AVInputFormat smacker_demuxer = {
+ "smk",
+ "Smacker Video",
+ sizeof(SmackerContext),
+ smacker_probe,
+ smacker_read_header,
+ smacker_read_packet,
+ smacker_read_close,
+};
diff --git a/contrib/ffmpeg/libavformat/sol.c b/contrib/ffmpeg/libavformat/sol.c
new file mode 100644
index 000000000..951ec6eb9
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/sol.c
@@ -0,0 +1,160 @@
+/*
+ * Sierra SOL demuxer
+ * Copyright 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
+ */
+
+/*
+ * Based on documents from Game Audio Player and own research
+ */
+
+#include "avformat.h"
+#include "allformats.h"
+#include "riff.h"
+#include "bswap.h"
+
+/* if we don't know the size in advance */
+#define AU_UNKNOWN_SIZE ((uint32_t)(~0))
+
+static int sol_probe(AVProbeData *p)
+{
+ /* check file header */
+ uint16_t magic;
+ if (p->buf_size <= 14)
+ return 0;
+ magic=le2me_16(*((uint16_t*)p->buf));
+ if ((magic == 0x0B8D || magic == 0x0C0D || magic == 0x0C8D) &&
+ p->buf[2] == 'S' && p->buf[3] == 'O' &&
+ p->buf[4] == 'L' && p->buf[5] == 0)
+ return AVPROBE_SCORE_MAX;
+ else
+ return 0;
+}
+
+#define SOL_DPCM 1
+#define SOL_16BIT 4
+#define SOL_STEREO 16
+
+static int sol_codec_id(int magic, int type)
+{
+ if (magic == 0x0B8D)
+ {
+ if (type & SOL_DPCM) return CODEC_ID_SOL_DPCM;
+ else return CODEC_ID_PCM_U8;
+ }
+ if (type & SOL_DPCM)
+ {
+ if (type & SOL_16BIT) return CODEC_ID_SOL_DPCM;
+ else if (magic == 0x0C8D) return CODEC_ID_SOL_DPCM;
+ else return CODEC_ID_SOL_DPCM;
+ }
+ if (type & SOL_16BIT) return CODEC_ID_PCM_S16LE;
+ return CODEC_ID_PCM_U8;
+}
+
+static int sol_codec_type(int magic, int type)
+{
+ if (magic == 0x0B8D) return 1;//SOL_DPCM_OLD;
+ if (type & SOL_DPCM)
+ {
+ if (type & SOL_16BIT) return 3;//SOL_DPCM_NEW16;
+ else if (magic == 0x0C8D) return 1;//SOL_DPCM_OLD;
+ else return 2;//SOL_DPCM_NEW8;
+ }
+ return -1;
+}
+
+static int sol_channels(int magic, int type)
+{
+ if (magic == 0x0B8D || !(type & SOL_STEREO)) return 1;
+ return 2;
+}
+
+static int sol_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ int size;
+ unsigned int magic,tag;
+ ByteIOContext *pb = &s->pb;
+ unsigned int id, codec, channels, rate, type;
+ AVStream *st;
+
+ /* check ".snd" header */
+ magic = get_le16(pb);
+ tag = get_le32(pb);
+ if (tag != MKTAG('S', 'O', 'L', 0))
+ return -1;
+ rate = get_le16(pb);
+ type = get_byte(pb);
+ size = get_le32(pb);
+ if (magic != 0x0B8D)
+ get_byte(pb); /* newer SOLs contain padding byte */
+
+ codec = sol_codec_id(magic, type);
+ channels = sol_channels(magic, type);
+
+ if (codec == CODEC_ID_SOL_DPCM)
+ id = sol_codec_type(magic, type);
+ else id = 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_tag = id;
+ st->codec->codec_id = codec;
+ st->codec->channels = channels;
+ st->codec->sample_rate = rate;
+ av_set_pts_info(st, 64, 1, rate);
+ return 0;
+}
+
+#define MAX_SIZE 4096
+
+static int sol_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);
+ pkt->stream_index = 0;
+
+ /* note: we need to modify the packet size here to handle the last
+ packet */
+ pkt->size = ret;
+ return 0;
+}
+
+static int sol_read_close(AVFormatContext *s)
+{
+ return 0;
+}
+
+AVInputFormat sol_demuxer = {
+ "sol",
+ "Sierra SOL Format",
+ 0,
+ sol_probe,
+ sol_read_header,
+ sol_read_packet,
+ sol_read_close,
+ pcm_read_seek,
+};
diff --git a/contrib/ffmpeg/libavformat/swf.c b/contrib/ffmpeg/libavformat/swf.c
new file mode 100644
index 000000000..7d889af7d
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/swf.c
@@ -0,0 +1,797 @@
+/*
+ * Flash Compatible Streaming Format
+ * Copyright (c) 2000 Fabrice Bellard.
+ * Copyright (c) 2003 Tinic Uro.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 "bitstream.h"
+#include "riff.h" /* for CodecTag */
+
+/* should have a generic way to indicate probable size */
+#define DUMMY_FILE_SIZE (100 * 1024 * 1024)
+#define DUMMY_DURATION 600 /* in seconds */
+
+#define TAG_END 0
+#define TAG_SHOWFRAME 1
+#define TAG_DEFINESHAPE 2
+#define TAG_FREECHARACTER 3
+#define TAG_PLACEOBJECT 4
+#define TAG_REMOVEOBJECT 5
+#define TAG_STREAMHEAD 18
+#define TAG_STREAMBLOCK 19
+#define TAG_JPEG2 21
+#define TAG_PLACEOBJECT2 26
+#define TAG_STREAMHEAD2 45
+#define TAG_VIDEOSTREAM 60
+#define TAG_VIDEOFRAME 61
+
+#define TAG_LONG 0x100
+
+/* flags for shape definition */
+#define FLAG_MOVETO 0x01
+#define FLAG_SETFILL0 0x02
+#define FLAG_SETFILL1 0x04
+
+#define AUDIO_FIFO_SIZE 65536
+
+/* character id used */
+#define BITMAP_ID 0
+#define VIDEO_ID 0
+#define SHAPE_ID 1
+
+#undef NDEBUG
+#include <assert.h>
+
+typedef struct {
+ int audio_stream_index;
+ offset_t duration_pos;
+ offset_t tag_pos;
+
+ int samples_per_frame;
+ int sound_samples;
+ int swf_frame_number;
+ int video_frame_number;
+ int frame_rate;
+ int tag;
+
+ uint8_t audio_fifo[AUDIO_FIFO_SIZE];
+ int audio_in_pos;
+
+ int video_type;
+ int audio_type;
+} SWFContext;
+
+static const AVCodecTag swf_codec_tags[] = {
+ {CODEC_ID_FLV1, 0x02},
+ {CODEC_ID_VP6F, 0x04},
+ {0, 0},
+};
+
+static const AVCodecTag swf_audio_codec_tags[] = {
+ {CODEC_ID_PCM_S16LE, 0x00},
+ {CODEC_ID_ADPCM_SWF, 0x01},
+ {CODEC_ID_MP3, 0x02},
+ {CODEC_ID_PCM_S16LE, 0x03},
+ //{CODEC_ID_NELLYMOSER, 0x06},
+ {0, 0},
+};
+
+#ifdef CONFIG_MUXERS
+static void put_swf_tag(AVFormatContext *s, int tag)
+{
+ SWFContext *swf = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+
+ swf->tag_pos = url_ftell(pb);
+ swf->tag = tag;
+ /* reserve some room for the tag */
+ if (tag & TAG_LONG) {
+ put_le16(pb, 0);
+ put_le32(pb, 0);
+ } else {
+ put_le16(pb, 0);
+ }
+}
+
+static void put_swf_end_tag(AVFormatContext *s)
+{
+ SWFContext *swf = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ offset_t pos;
+ int tag_len, tag;
+
+ pos = url_ftell(pb);
+ tag_len = pos - swf->tag_pos - 2;
+ tag = swf->tag;
+ url_fseek(pb, swf->tag_pos, SEEK_SET);
+ if (tag & TAG_LONG) {
+ tag &= ~TAG_LONG;
+ put_le16(pb, (tag << 6) | 0x3f);
+ put_le32(pb, tag_len - 4);
+ } else {
+ assert(tag_len < 0x3f);
+ put_le16(pb, (tag << 6) | tag_len);
+ }
+ url_fseek(pb, pos, SEEK_SET);
+}
+
+static inline void max_nbits(int *nbits_ptr, int val)
+{
+ int n;
+
+ if (val == 0)
+ return;
+ val = abs(val);
+ n = 1;
+ while (val != 0) {
+ n++;
+ val >>= 1;
+ }
+ if (n > *nbits_ptr)
+ *nbits_ptr = n;
+}
+
+static void put_swf_rect(ByteIOContext *pb,
+ int xmin, int xmax, int ymin, int ymax)
+{
+ PutBitContext p;
+ uint8_t buf[256];
+ int nbits, mask;
+
+ init_put_bits(&p, buf, sizeof(buf));
+
+ nbits = 0;
+ max_nbits(&nbits, xmin);
+ max_nbits(&nbits, xmax);
+ max_nbits(&nbits, ymin);
+ max_nbits(&nbits, ymax);
+ mask = (1 << nbits) - 1;
+
+ /* rectangle info */
+ put_bits(&p, 5, nbits);
+ put_bits(&p, nbits, xmin & mask);
+ put_bits(&p, nbits, xmax & mask);
+ put_bits(&p, nbits, ymin & mask);
+ put_bits(&p, nbits, ymax & mask);
+
+ flush_put_bits(&p);
+ put_buffer(pb, buf, pbBufPtr(&p) - p.buf);
+}
+
+static void put_swf_line_edge(PutBitContext *pb, int dx, int dy)
+{
+ int nbits, mask;
+
+ put_bits(pb, 1, 1); /* edge */
+ put_bits(pb, 1, 1); /* line select */
+ nbits = 2;
+ max_nbits(&nbits, dx);
+ max_nbits(&nbits, dy);
+
+ mask = (1 << nbits) - 1;
+ put_bits(pb, 4, nbits - 2); /* 16 bits precision */
+ if (dx == 0) {
+ put_bits(pb, 1, 0);
+ put_bits(pb, 1, 1);
+ put_bits(pb, nbits, dy & mask);
+ } else if (dy == 0) {
+ put_bits(pb, 1, 0);
+ put_bits(pb, 1, 0);
+ put_bits(pb, nbits, dx & mask);
+ } else {
+ put_bits(pb, 1, 1);
+ put_bits(pb, nbits, dx & mask);
+ put_bits(pb, nbits, dy & mask);
+ }
+}
+
+#define FRAC_BITS 16
+
+/* put matrix */
+static void put_swf_matrix(ByteIOContext *pb,
+ int a, int b, int c, int d, int tx, int ty)
+{
+ PutBitContext p;
+ uint8_t buf[256];
+ int nbits;
+
+ init_put_bits(&p, buf, sizeof(buf));
+
+ put_bits(&p, 1, 1); /* a, d present */
+ nbits = 1;
+ max_nbits(&nbits, a);
+ max_nbits(&nbits, d);
+ put_bits(&p, 5, nbits); /* nb bits */
+ put_bits(&p, nbits, a);
+ put_bits(&p, nbits, d);
+
+ put_bits(&p, 1, 1); /* b, c present */
+ nbits = 1;
+ max_nbits(&nbits, c);
+ max_nbits(&nbits, b);
+ put_bits(&p, 5, nbits); /* nb bits */
+ put_bits(&p, nbits, c);
+ put_bits(&p, nbits, b);
+
+ nbits = 1;
+ max_nbits(&nbits, tx);
+ max_nbits(&nbits, ty);
+ put_bits(&p, 5, nbits); /* nb bits */
+ put_bits(&p, nbits, tx);
+ put_bits(&p, nbits, ty);
+
+ flush_put_bits(&p);
+ put_buffer(pb, buf, pbBufPtr(&p) - p.buf);
+}
+
+/* */
+static int swf_write_header(AVFormatContext *s)
+{
+ SWFContext *swf = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ AVCodecContext *enc, *audio_enc, *video_enc;
+ PutBitContext p;
+ uint8_t buf1[256];
+ int i, width, height, rate, rate_base;
+
+ swf->audio_in_pos = 0;
+ swf->sound_samples = 0;
+ swf->swf_frame_number = 0;
+ swf->video_frame_number = 0;
+
+ video_enc = NULL;
+ audio_enc = NULL;
+ for(i=0;i<s->nb_streams;i++) {
+ enc = s->streams[i]->codec;
+ if (enc->codec_type == CODEC_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");
+ return -1;
+ }
+ audio_enc = enc;
+ } else {
+ av_log(s, AV_LOG_ERROR, "SWF muxer only supports MP3\n");
+ return -1;
+ }
+ } else {
+ if ( enc->codec_id == CODEC_ID_VP6F ||
+ enc->codec_id == CODEC_ID_FLV1 ||
+ enc->codec_id == CODEC_ID_MJPEG ) {
+ video_enc = enc;
+ } else {
+ av_log(s, AV_LOG_ERROR, "SWF muxer only supports VP6, FLV1 and MJPEG\n");
+ return -1;
+ }
+ }
+ }
+
+ if (!video_enc) {
+ /* currenty, cannot work correctly if audio only */
+ swf->video_type = 0;
+ width = 320;
+ height = 200;
+ rate = 10;
+ rate_base= 1;
+ } else {
+ swf->video_type = video_enc->codec_id;
+ width = video_enc->width;
+ height = video_enc->height;
+ rate = video_enc->time_base.den;
+ rate_base = video_enc->time_base.num;
+ }
+
+ if (!audio_enc ) {
+ swf->audio_type = 0;
+ swf->samples_per_frame = ( 44100. * rate_base ) / rate;
+ } else {
+ swf->audio_type = audio_enc->codec_id;
+ swf->samples_per_frame = ( ( audio_enc->sample_rate ) * rate_base ) / rate;
+ }
+
+ put_tag(pb, "FWS");
+ if ( video_enc && video_enc->codec_id == CODEC_ID_VP6F ) {
+ put_byte(pb, 8); /* version (version 8 and above support VP6 codec) */
+ } else if ( video_enc && video_enc->codec_id == CODEC_ID_FLV1 ) {
+ put_byte(pb, 6); /* version (version 6 and above support FLV1 codec) */
+ } else {
+ put_byte(pb, 4); /* version (should use 4 for mpeg audio support) */
+ }
+ put_le32(pb, DUMMY_FILE_SIZE); /* dummy size
+ (will be patched if not streamed) */
+
+ put_swf_rect(pb, 0, width * 20, 0, height * 20);
+ put_le16(pb, (rate * 256) / rate_base); /* frame rate */
+ swf->duration_pos = url_ftell(pb);
+ put_le16(pb, (uint16_t)(DUMMY_DURATION * (int64_t)rate / rate_base)); /* frame count */
+
+ /* define a shape with the jpeg inside */
+ if ( video_enc && (video_enc->codec_id == CODEC_ID_VP6F ||
+ video_enc->codec_id == CODEC_ID_FLV1 )) {
+ } else if ( video_enc && video_enc->codec_id == CODEC_ID_MJPEG ) {
+ put_swf_tag(s, TAG_DEFINESHAPE);
+
+ put_le16(pb, SHAPE_ID); /* ID of shape */
+ /* bounding rectangle */
+ put_swf_rect(pb, 0, width, 0, height);
+ /* style info */
+ put_byte(pb, 1); /* one fill style */
+ put_byte(pb, 0x41); /* clipped bitmap fill */
+ put_le16(pb, BITMAP_ID); /* bitmap ID */
+ /* position of the bitmap */
+ put_swf_matrix(pb, (int)(1.0 * (1 << FRAC_BITS)), 0,
+ 0, (int)(1.0 * (1 << FRAC_BITS)), 0, 0);
+ put_byte(pb, 0); /* no line style */
+
+ /* shape drawing */
+ init_put_bits(&p, buf1, sizeof(buf1));
+ put_bits(&p, 4, 1); /* one fill bit */
+ put_bits(&p, 4, 0); /* zero line bit */
+
+ put_bits(&p, 1, 0); /* not an edge */
+ put_bits(&p, 5, FLAG_MOVETO | FLAG_SETFILL0);
+ put_bits(&p, 5, 1); /* nbits */
+ put_bits(&p, 1, 0); /* X */
+ put_bits(&p, 1, 0); /* Y */
+ put_bits(&p, 1, 1); /* set fill style 1 */
+
+ /* draw the rectangle ! */
+ put_swf_line_edge(&p, width, 0);
+ put_swf_line_edge(&p, 0, height);
+ put_swf_line_edge(&p, -width, 0);
+ put_swf_line_edge(&p, 0, -height);
+
+ /* end of shape */
+ put_bits(&p, 1, 0); /* not an edge */
+ put_bits(&p, 5, 0);
+
+ flush_put_bits(&p);
+ put_buffer(pb, buf1, pbBufPtr(&p) - p.buf);
+
+ put_swf_end_tag(s);
+ }
+
+ if (audio_enc && audio_enc->codec_id == CODEC_ID_MP3 ) {
+ int v;
+
+ /* start sound */
+ put_swf_tag(s, TAG_STREAMHEAD2);
+
+ v = 0;
+ switch(audio_enc->sample_rate) {
+ case 11025:
+ v |= 1 << 2;
+ break;
+ case 22050:
+ v |= 2 << 2;
+ break;
+ case 44100:
+ v |= 3 << 2;
+ break;
+ default:
+ /* not supported */
+ av_log(s, AV_LOG_ERROR, "swf doesnt support that sample rate, choose from (44100, 22050, 11025)\n");
+ return -1;
+ }
+ v |= 0x02; /* 16 bit playback */
+ if (audio_enc->channels == 2)
+ v |= 0x01; /* stereo playback */
+ put_byte(&s->pb, v);
+ v |= 0x20; /* mp3 compressed */
+ put_byte(&s->pb, v);
+ put_le16(&s->pb, swf->samples_per_frame); /* avg samples per frame */
+ put_le16(&s->pb, 0);
+
+ put_swf_end_tag(s);
+ }
+
+ put_flush_packet(&s->pb);
+ return 0;
+}
+
+static int swf_write_video(AVFormatContext *s,
+ AVCodecContext *enc, const uint8_t *buf, int size)
+{
+ SWFContext *swf = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+
+ /* Flash Player limit */
+ if ( swf->swf_frame_number == 16000 ) {
+ av_log(enc, AV_LOG_INFO, "warning: Flash Player limit of 16000 frames reached\n");
+ }
+
+ if ( swf->video_type == CODEC_ID_VP6F ||
+ swf->video_type == CODEC_ID_FLV1 ) {
+ if ( swf->video_frame_number == 0 ) {
+ /* create a new video object */
+ put_swf_tag(s, TAG_VIDEOSTREAM);
+ put_le16(pb, VIDEO_ID);
+ put_le16(pb, 15000 ); /* hard flash player limit */
+ put_le16(pb, enc->width);
+ put_le16(pb, enc->height);
+ put_byte(pb, 0);
+ put_byte(pb,codec_get_tag(swf_codec_tags,swf->video_type));
+ put_swf_end_tag(s);
+
+ /* place the video object for the first time */
+ put_swf_tag(s, TAG_PLACEOBJECT2);
+ put_byte(pb, 0x36);
+ put_le16(pb, 1);
+ put_le16(pb, VIDEO_ID);
+ put_swf_matrix(pb, 1 << FRAC_BITS, 0, 0, 1 << FRAC_BITS, 0, 0);
+ put_le16(pb, swf->video_frame_number );
+ put_byte(pb, 'v');
+ put_byte(pb, 'i');
+ put_byte(pb, 'd');
+ put_byte(pb, 'e');
+ put_byte(pb, 'o');
+ put_byte(pb, 0x00);
+ put_swf_end_tag(s);
+ } else {
+ /* mark the character for update */
+ put_swf_tag(s, TAG_PLACEOBJECT2);
+ put_byte(pb, 0x11);
+ put_le16(pb, 1);
+ put_le16(pb, swf->video_frame_number );
+ put_swf_end_tag(s);
+ }
+
+ /* set video frame data */
+ put_swf_tag(s, TAG_VIDEOFRAME | TAG_LONG);
+ put_le16(pb, VIDEO_ID);
+ put_le16(pb, swf->video_frame_number++ );
+ put_buffer(pb, buf, size);
+ put_swf_end_tag(s);
+ } else if ( swf->video_type == CODEC_ID_MJPEG ) {
+ if (swf->swf_frame_number > 0) {
+ /* remove the shape */
+ put_swf_tag(s, TAG_REMOVEOBJECT);
+ put_le16(pb, SHAPE_ID); /* shape ID */
+ put_le16(pb, 1); /* depth */
+ put_swf_end_tag(s);
+
+ /* free the bitmap */
+ put_swf_tag(s, TAG_FREECHARACTER);
+ put_le16(pb, BITMAP_ID);
+ put_swf_end_tag(s);
+ }
+
+ put_swf_tag(s, TAG_JPEG2 | TAG_LONG);
+
+ put_le16(pb, BITMAP_ID); /* ID of the image */
+
+ /* a dummy jpeg header seems to be required */
+ put_byte(pb, 0xff);
+ put_byte(pb, 0xd8);
+ put_byte(pb, 0xff);
+ put_byte(pb, 0xd9);
+ /* write the jpeg image */
+ put_buffer(pb, buf, size);
+
+ put_swf_end_tag(s);
+
+ /* draw the shape */
+
+ put_swf_tag(s, TAG_PLACEOBJECT);
+ put_le16(pb, SHAPE_ID); /* shape ID */
+ put_le16(pb, 1); /* depth */
+ put_swf_matrix(pb, 20 << FRAC_BITS, 0, 0, 20 << FRAC_BITS, 0, 0);
+ put_swf_end_tag(s);
+ } else {
+ /* invalid codec */
+ }
+
+ swf->swf_frame_number ++;
+
+ /* streaming sound always should be placed just before showframe tags */
+ if (swf->audio_type && swf->audio_in_pos) {
+ put_swf_tag(s, TAG_STREAMBLOCK | TAG_LONG);
+ put_le16(pb, swf->sound_samples);
+ put_le16(pb, 0); // seek samples
+ put_buffer(pb, swf->audio_fifo, swf->audio_in_pos);
+ put_swf_end_tag(s);
+
+ /* update FIFO */
+ swf->sound_samples = 0;
+ swf->audio_in_pos = 0;
+ }
+
+ /* output the frame */
+ put_swf_tag(s, TAG_SHOWFRAME);
+ put_swf_end_tag(s);
+
+ put_flush_packet(&s->pb);
+
+ return 0;
+}
+
+static int swf_write_audio(AVFormatContext *s,
+ AVCodecContext *enc, const uint8_t *buf, int size)
+{
+ SWFContext *swf = s->priv_data;
+
+ /* Flash Player limit */
+ if ( swf->swf_frame_number == 16000 ) {
+ av_log(enc, AV_LOG_INFO, "warning: Flash Player limit of 16000 frames reached\n");
+ }
+
+ if (swf->audio_in_pos + size >= AUDIO_FIFO_SIZE) {
+ av_log(s, AV_LOG_ERROR, "audio fifo too small to mux audio essence\n");
+ return -1;
+ }
+
+ memcpy(swf->audio_fifo + swf->audio_in_pos, buf, size);
+ swf->audio_in_pos += size;
+ swf->sound_samples += enc->frame_size;
+
+ /* if audio only stream make sure we add swf frames */
+ if ( swf->video_type == 0 ) {
+ swf_write_video(s, enc, 0, 0);
+ }
+
+ return 0;
+}
+
+static int swf_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ AVCodecContext *codec = s->streams[pkt->stream_index]->codec;
+ if (codec->codec_type == CODEC_TYPE_AUDIO)
+ return swf_write_audio(s, codec, pkt->data, pkt->size);
+ else
+ return swf_write_video(s, codec, pkt->data, pkt->size);
+}
+
+static int swf_write_trailer(AVFormatContext *s)
+{
+ SWFContext *swf = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ AVCodecContext *enc, *video_enc;
+ int file_size, i;
+
+ video_enc = NULL;
+ for(i=0;i<s->nb_streams;i++) {
+ enc = s->streams[i]->codec;
+ if (enc->codec_type == CODEC_TYPE_VIDEO)
+ video_enc = enc;
+ }
+
+ put_swf_tag(s, TAG_END);
+ put_swf_end_tag(s);
+
+ put_flush_packet(&s->pb);
+
+ /* patch file size and number of frames if not streamed */
+ if (!url_is_streamed(&s->pb) && video_enc) {
+ file_size = url_ftell(pb);
+ url_fseek(pb, 4, SEEK_SET);
+ put_le32(pb, file_size);
+ url_fseek(pb, swf->duration_pos, SEEK_SET);
+ put_le16(pb, video_enc->frame_number);
+ url_fseek(pb, file_size, SEEK_SET);
+ }
+ return 0;
+}
+#endif //CONFIG_MUXERS
+
+/*********************************************/
+/* Extract FLV encoded frame and MP3 from swf
+ Note that the detection of the real frame
+ is inaccurate at this point as it can be
+ quite tricky to determine, you almost certainly
+ will get a bad audio/video sync */
+
+static int get_swf_tag(ByteIOContext *pb, int *len_ptr)
+{
+ int tag, len;
+
+ if (url_feof(pb))
+ return -1;
+
+ tag = get_le16(pb);
+ len = tag & 0x3f;
+ tag = tag >> 6;
+ if (len == 0x3f) {
+ len = get_le32(pb);
+ }
+// av_log(NULL, AV_LOG_DEBUG, "Tag: %d - Len: %d\n", tag, len);
+ *len_ptr = len;
+ return tag;
+}
+
+
+static int swf_probe(AVProbeData *p)
+{
+ /* check file header */
+ if (p->buf_size <= 16)
+ return 0;
+ if ((p->buf[0] == 'F' || p->buf[0] == 'C') && p->buf[1] == 'W' &&
+ p->buf[2] == 'S')
+ return AVPROBE_SCORE_MAX;
+ else
+ return 0;
+}
+
+static int swf_read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+ SWFContext *swf = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ int nbits, len, tag, v;
+ offset_t frame_offset = -1;
+ AVStream *ast = 0;
+ AVStream *vst = 0;
+
+ tag = get_be32(pb) & 0xffffff00;
+
+ if (tag == MKBETAG('C', 'W', 'S', 0))
+ {
+ av_log(s, AV_LOG_ERROR, "Compressed SWF format not supported\n");
+ return AVERROR_IO;
+ }
+ if (tag != MKBETAG('F', 'W', 'S', 0))
+ return AVERROR_IO;
+ get_le32(pb);
+ /* skip rectangle size */
+ nbits = get_byte(pb) >> 3;
+ len = (4 * nbits - 3 + 7) / 8;
+ url_fskip(pb, len);
+ swf->frame_rate = get_le16(pb); /* 8.8 fixed */
+ get_le16(pb); /* frame count */
+
+ swf->samples_per_frame = 0;
+
+ for(;;) {
+ offset_t tag_offset = url_ftell(pb);
+ tag = get_swf_tag(pb, &len);
+ if (tag < 0 || tag == TAG_VIDEOFRAME || tag == TAG_STREAMBLOCK) {
+ url_fseek(pb, frame_offset == -1 ? tag_offset : frame_offset, SEEK_SET);
+ break;
+ }
+ if ( tag == TAG_VIDEOSTREAM && !vst) {
+ int ch_id = get_le16(pb);
+ get_le16(pb);
+ get_le16(pb);
+ get_le16(pb);
+ get_byte(pb);
+ /* Check for FLV1 */
+ vst = av_new_stream(s, ch_id);
+ vst->codec->codec_type = CODEC_TYPE_VIDEO;
+ vst->codec->codec_id = codec_get_id(swf_codec_tags, get_byte(pb));
+ } else if ( ( tag == TAG_STREAMHEAD || tag == TAG_STREAMHEAD2 ) && !ast) {
+ /* streaming found */
+ int sample_rate_code;
+ get_byte(pb);
+ v = get_byte(pb);
+ swf->samples_per_frame = get_le16(pb);
+ ast = av_new_stream(s, -1); /* -1 to avoid clash with video stream ch_id */
+ swf->audio_stream_index = ast->index;
+ ast->codec->channels = 1 + (v&1);
+ ast->codec->codec_type = CODEC_TYPE_AUDIO;
+ ast->codec->codec_id = codec_get_id(swf_audio_codec_tags, (v>>4) & 15);
+ ast->need_parsing = 1;
+ sample_rate_code= (v>>2) & 3;
+ if (!sample_rate_code)
+ return AVERROR_IO;
+ ast->codec->sample_rate = 11025 << (sample_rate_code-1);
+ av_set_pts_info(ast, 64, 1, ast->codec->sample_rate);
+ if (len > 4)
+ url_fskip(pb,len-4);
+
+ } else if (tag == TAG_JPEG2 && !vst) {
+ vst = av_new_stream(s, -2); /* -2 to avoid clash with video stream and audio stream */
+ vst->codec->codec_type = CODEC_TYPE_VIDEO;
+ vst->codec->codec_id = CODEC_ID_MJPEG;
+ url_fskip(pb, len);
+ frame_offset = tag_offset;
+ } else {
+ url_fskip(pb, len);
+ }
+ }
+ if (vst)
+ av_set_pts_info(vst, 64, 256, swf->frame_rate);
+ return 0;
+}
+
+static int swf_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ SWFContext *swf = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ AVStream *st = 0;
+ int tag, len, i, frame;
+
+ for(;;) {
+ tag = get_swf_tag(pb, &len);
+ if (tag < 0)
+ return AVERROR_IO;
+ if (tag == TAG_VIDEOFRAME) {
+ int ch_id = get_le16(pb);
+ len -= 2;
+ for( i=0; i<s->nb_streams; i++ ) {
+ st = s->streams[i];
+ if (st->codec->codec_type == CODEC_TYPE_VIDEO && st->id == ch_id) {
+ frame = get_le16(pb);
+ av_get_packet(pb, pkt, len-2);
+ pkt->pts = frame;
+ pkt->stream_index = st->index;
+ return pkt->size;
+ }
+ }
+ } else if (tag == TAG_STREAMBLOCK) {
+ st = s->streams[swf->audio_stream_index];
+ if (st->codec->codec_id == CODEC_ID_MP3) {
+ url_fskip(pb, 4);
+ av_get_packet(pb, pkt, len-4);
+ } else { // ADPCM, PCM
+ av_get_packet(pb, pkt, len);
+ }
+ pkt->stream_index = st->index;
+ return pkt->size;
+ } else if (tag == TAG_JPEG2) {
+ for (i=0; i<s->nb_streams; i++) {
+ st = s->streams[i];
+ if (st->id == -2) {
+ get_le16(pb); /* BITMAP_ID */
+ av_new_packet(pkt, len-2);
+ get_buffer(pb, pkt->data, 4);
+ if (AV_RB32(pkt->data) == 0xffd8ffd9) {
+ /* old SWF files containing SOI/EOI as data start */
+ pkt->size -= 4;
+ get_buffer(pb, pkt->data, pkt->size);
+ } else {
+ get_buffer(pb, pkt->data + 4, pkt->size - 4);
+ }
+ pkt->stream_index = st->index;
+ return pkt->size;
+ }
+ }
+ }
+ url_fskip(pb, len);
+ }
+ return 0;
+}
+
+static int swf_read_close(AVFormatContext *s)
+{
+ return 0;
+}
+
+#ifdef CONFIG_SWF_DEMUXER
+AVInputFormat swf_demuxer = {
+ "swf",
+ "Flash format",
+ sizeof(SWFContext),
+ swf_probe,
+ swf_read_header,
+ swf_read_packet,
+ swf_read_close,
+};
+#endif
+#ifdef CONFIG_SWF_MUXER
+AVOutputFormat swf_muxer = {
+ "swf",
+ "Flash format",
+ "application/x-shockwave-flash",
+ "swf",
+ sizeof(SWFContext),
+ CODEC_ID_MP3,
+ CODEC_ID_FLV1,
+ swf_write_header,
+ swf_write_packet,
+ swf_write_trailer,
+};
+#endif
diff --git a/contrib/ffmpeg/libavformat/tcp.c b/contrib/ffmpeg/libavformat/tcp.c
new file mode 100644
index 000000000..a5539be4c
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/tcp.c
@@ -0,0 +1,200 @@
+/*
+ * TCP protocol
+ * 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
+ */
+#include "avformat.h"
+#include <unistd.h>
+#include "network.h"
+#include <sys/time.h>
+#include <fcntl.h>
+
+typedef struct TCPContext {
+ int fd;
+} TCPContext;
+
+/* resolve host with also IP address parsing */
+int resolve_host(struct in_addr *sin_addr, const char *hostname)
+{
+ struct hostent *hp;
+
+ if ((inet_aton(hostname, sin_addr)) == 0) {
+ hp = gethostbyname(hostname);
+ if (!hp)
+ return -1;
+ memcpy (sin_addr, hp->h_addr, sizeof(struct in_addr));
+ }
+ return 0;
+}
+
+/* return non zero if error */
+static int tcp_open(URLContext *h, const char *uri, int flags)
+{
+ struct sockaddr_in dest_addr;
+ char hostname[1024], *q;
+ int port, fd = -1;
+ TCPContext *s = NULL;
+ fd_set wfds;
+ int fd_max, ret;
+ struct timeval tv;
+ socklen_t optlen;
+ char proto[1024],path[1024],tmp[1024]; // PETR: protocol and path strings
+
+ url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname),
+ &port, path, sizeof(path), uri); // PETR: use url_split
+ if (strcmp(proto,"tcp")) goto fail; // PETR: check protocol
+ if ((q = strchr(hostname,'@'))) { strcpy(tmp,q+1); strcpy(hostname,tmp); } // PETR: take only the part after '@' for tcp protocol
+
+ s = av_malloc(sizeof(TCPContext));
+ if (!s)
+ return AVERROR(ENOMEM);
+ h->priv_data = s;
+
+ if (port <= 0 || port >= 65536)
+ goto fail;
+
+ dest_addr.sin_family = AF_INET;
+ dest_addr.sin_port = htons(port);
+ if (resolve_host(&dest_addr.sin_addr, hostname) < 0)
+ goto fail;
+
+ fd = socket(AF_INET, SOCK_STREAM, 0);
+ if (fd < 0)
+ goto fail;
+ fcntl(fd, F_SETFL, O_NONBLOCK);
+
+ redo:
+ ret = connect(fd, (struct sockaddr *)&dest_addr,
+ sizeof(dest_addr));
+ if (ret < 0) {
+ if (errno == EINTR)
+ goto redo;
+ if (errno != EINPROGRESS)
+ goto fail;
+
+ /* wait until we are connected or until abort */
+ for(;;) {
+ if (url_interrupt_cb()) {
+ ret = AVERROR(EINTR);
+ goto fail1;
+ }
+ fd_max = fd;
+ FD_ZERO(&wfds);
+ FD_SET(fd, &wfds);
+ tv.tv_sec = 0;
+ tv.tv_usec = 100 * 1000;
+ ret = select(fd_max + 1, NULL, &wfds, NULL, &tv);
+ if (ret > 0 && FD_ISSET(fd, &wfds))
+ break;
+ }
+
+ /* test error */
+ optlen = sizeof(ret);
+ getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen);
+ if (ret != 0)
+ goto fail;
+ }
+ s->fd = fd;
+ return 0;
+
+ fail:
+ ret = AVERROR_IO;
+ fail1:
+ if (fd >= 0)
+ closesocket(fd);
+ av_free(s);
+ return ret;
+}
+
+static int tcp_read(URLContext *h, uint8_t *buf, int size)
+{
+ TCPContext *s = h->priv_data;
+ int len, fd_max, ret;
+ fd_set rfds;
+ struct timeval tv;
+
+ for (;;) {
+ if (url_interrupt_cb())
+ return AVERROR(EINTR);
+ fd_max = s->fd;
+ FD_ZERO(&rfds);
+ FD_SET(s->fd, &rfds);
+ tv.tv_sec = 0;
+ tv.tv_usec = 100 * 1000;
+ ret = select(fd_max + 1, &rfds, NULL, NULL, &tv);
+ if (ret > 0 && FD_ISSET(s->fd, &rfds)) {
+ len = recv(s->fd, buf, size, 0);
+ if (len < 0) {
+ if (errno != EINTR && errno != EAGAIN)
+ return AVERROR(errno);
+ } else return len;
+ } else if (ret < 0) {
+ return -1;
+ }
+ }
+}
+
+static int tcp_write(URLContext *h, uint8_t *buf, int size)
+{
+ TCPContext *s = h->priv_data;
+ int ret, size1, fd_max, len;
+ fd_set wfds;
+ struct timeval tv;
+
+ size1 = size;
+ while (size > 0) {
+ if (url_interrupt_cb())
+ return AVERROR(EINTR);
+ fd_max = s->fd;
+ FD_ZERO(&wfds);
+ FD_SET(s->fd, &wfds);
+ tv.tv_sec = 0;
+ tv.tv_usec = 100 * 1000;
+ ret = select(fd_max + 1, NULL, &wfds, NULL, &tv);
+ if (ret > 0 && FD_ISSET(s->fd, &wfds)) {
+ len = send(s->fd, buf, size, 0);
+ if (len < 0) {
+ if (errno != EINTR && errno != EAGAIN)
+ return AVERROR(errno);
+ continue;
+ }
+ size -= len;
+ buf += len;
+ } else if (ret < 0) {
+ return -1;
+ }
+ }
+ return size1 - size;
+}
+
+static int tcp_close(URLContext *h)
+{
+ TCPContext *s = h->priv_data;
+ closesocket(s->fd);
+ av_free(s);
+ return 0;
+}
+
+URLProtocol tcp_protocol = {
+ "tcp",
+ tcp_open,
+ tcp_read,
+ tcp_write,
+ NULL, /* seek */
+ tcp_close,
+};
diff --git a/contrib/ffmpeg/libavformat/thp.c b/contrib/ffmpeg/libavformat/thp.c
new file mode 100644
index 000000000..d0d80428c
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/thp.c
@@ -0,0 +1,170 @@
+/*
+ * THP Demuxer
+ * Copyright (c) 2007 Marco Gerards.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 "allformats.h"
+
+typedef struct ThpDemuxContext {
+ int version;
+ int first_frame;
+ int first_framesz;
+ int last_frame;
+ int compoff;
+ int framecnt;
+ AVRational fps;
+ int frame;
+ int next_frame;
+ int next_framesz;
+ int video_stream_index;
+ int compcount;
+ unsigned char components[16];
+ AVStream* vst;
+ int has_audio;
+} ThpDemuxContext;
+
+
+static int thp_probe(AVProbeData *p)
+{
+ /* check file header */
+ if (p->buf_size < 4)
+ return 0;
+
+ if (AV_RL32(p->buf) == MKTAG('T', 'H', 'P', '\0'))
+ return AVPROBE_SCORE_MAX;
+ else
+ return 0;
+}
+
+static int thp_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ ThpDemuxContext *thp = s->priv_data;
+ AVStream *st;
+ ByteIOContext *pb = &s->pb;
+ int i;
+
+ /* Read the file header. */
+
+ get_be32(pb); /* Skip Magic. */
+ thp->version = get_be32(pb);
+
+ get_be32(pb); /* Max buf size. */
+ get_be32(pb); /* Max samples. */
+
+ thp->fps = av_d2q(av_int2flt(get_be32(pb)), INT_MAX);
+ thp->framecnt = get_be32(pb);
+ thp->first_framesz = get_be32(pb);
+ get_be32(pb); /* Data size. */
+
+ thp->compoff = get_be32(pb);
+ get_be32(pb); /* offsetDataOffset. */
+ thp->first_frame = get_be32(pb);
+ thp->last_frame = get_be32(pb);
+
+ thp->next_framesz = thp->first_framesz;
+ thp->next_frame = thp->first_frame;
+
+ /* Read the component structure. */
+ url_fseek (pb, thp->compoff, SEEK_SET);
+ thp->compcount = get_be32(pb);
+
+ /* Read the list of component types. */
+ get_buffer(pb, thp->components, 16);
+
+ for (i = 0; i < thp->compcount; i++) {
+ if (thp->components[i] == 0) {
+ if (thp->vst != 0)
+ break;
+
+ /* Video component. */
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+
+ /* 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_id = CODEC_ID_THP;
+ st->codec->codec_tag = 0; /* no fourcc */
+ st->codec->width = get_be32(pb);
+ st->codec->height = get_be32(pb);
+ st->codec->sample_rate = av_q2d(thp->fps);
+ thp->vst = st;
+ thp->video_stream_index = st->index;
+
+ if (thp->version == 0x11000)
+ get_be32(pb); /* Unknown. */
+ }
+ else if (thp->components[i] == 1) {
+ /* XXX: Required for audio playback. */
+ thp->has_audio = 1;
+ }
+ }
+
+ return 0;
+}
+
+static int thp_read_packet(AVFormatContext *s,
+ AVPacket *pkt)
+{
+ ThpDemuxContext *thp = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ int size;
+ int ret;
+
+ /* Terminate when last frame is reached. */
+ if (thp->frame >= thp->framecnt)
+ return AVERROR_IO;
+
+ url_fseek(pb, thp->next_frame, SEEK_SET);
+
+ /* Locate the next frame and read out its size. */
+ thp->next_frame += thp->next_framesz;
+ thp->next_framesz = get_be32(pb);
+
+ get_be32(pb); /* Previous total size. */
+ size = get_be32(pb); /* Total size of this frame. */
+
+ if (thp->has_audio)
+ get_be32(pb); /* Audio size. */
+
+ ret = av_get_packet(pb, pkt, size);
+ if (ret != size) {
+ av_free_packet(pkt);
+ return AVERROR_IO;
+ }
+
+ pkt->stream_index = thp->video_stream_index;
+ thp->frame++;
+
+ return 0;
+}
+
+AVInputFormat thp_demuxer = {
+ "thp",
+ "THP",
+ sizeof(ThpDemuxContext),
+ thp_probe,
+ thp_read_header,
+ thp_read_packet
+};
diff --git a/contrib/ffmpeg/libavformat/tiertexseq.c b/contrib/ffmpeg/libavformat/tiertexseq.c
new file mode 100644
index 000000000..8f565824a
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/tiertexseq.c
@@ -0,0 +1,313 @@
+/*
+ * Tiertex Limited SEQ File Demuxer
+ * Copyright (c) 2006 Gregory Montoir (cyx@users.sourceforge.net)
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 tiertexseq.c
+ * Tiertex Limited SEQ file demuxer
+ */
+
+#include "avformat.h"
+
+#define SEQ_FRAME_SIZE 6144
+#define SEQ_FRAME_W 256
+#define SEQ_FRAME_H 128
+#define SEQ_NUM_FRAME_BUFFERS 30
+#define SEQ_AUDIO_BUFFER_SIZE 882
+#define SEQ_SAMPLE_RATE 22050
+#define SEQ_FRAME_RATE 25
+
+
+typedef struct TiertexSeqFrameBuffer {
+ int fill_size;
+ int data_size;
+ unsigned char *data;
+} TiertexSeqFrameBuffer;
+
+typedef struct SeqDemuxContext {
+ int audio_stream_index;
+ int video_stream_index;
+ int current_frame_pts;
+ int current_frame_offs;
+ TiertexSeqFrameBuffer frame_buffers[SEQ_NUM_FRAME_BUFFERS];
+ int frame_buffers_count;
+ unsigned int current_audio_data_size;
+ unsigned int current_audio_data_offs;
+ unsigned int current_pal_data_size;
+ unsigned int current_pal_data_offs;
+ unsigned int current_video_data_size;
+ unsigned char *current_video_data_ptr;
+ int audio_buffer_full;
+} SeqDemuxContext;
+
+
+static int seq_probe(AVProbeData *p)
+{
+ int i;
+
+ if (p->buf_size < 258)
+ return 0;
+
+ /* there's no real header in a .seq file, the only thing they have in common */
+ /* is the first 256 bytes of the file which are always filled with 0 */
+ for (i = 0; i < 256; i++)
+ if (p->buf[i] != 0)
+ return 0;
+
+ if(p->buf[256]==0 && p->buf[257]==0)
+ return 0;
+
+ /* only one fourth of the score since the previous check is too naive */
+ return AVPROBE_SCORE_MAX / 4;
+}
+
+static int seq_init_frame_buffers(SeqDemuxContext *seq, ByteIOContext *pb)
+{
+ int i, sz;
+ TiertexSeqFrameBuffer *seq_buffer;
+
+ url_fseek(pb, 256, SEEK_SET);
+
+ for (i = 0; i < SEQ_NUM_FRAME_BUFFERS; i++) {
+ sz = get_le16(pb);
+ if (sz == 0)
+ break;
+ else {
+ seq_buffer = &seq->frame_buffers[i];
+ seq_buffer->fill_size = 0;
+ seq_buffer->data_size = sz;
+ seq_buffer->data = av_malloc(sz);
+ if (!seq_buffer->data)
+ return AVERROR_NOMEM;
+ }
+ }
+ seq->frame_buffers_count = i;
+ return 0;
+}
+
+static int seq_fill_buffer(SeqDemuxContext *seq, ByteIOContext *pb, int buffer_num, unsigned int data_offs, int data_size)
+{
+ TiertexSeqFrameBuffer *seq_buffer;
+
+ if (buffer_num >= SEQ_NUM_FRAME_BUFFERS)
+ return AVERROR_INVALIDDATA;
+
+ seq_buffer = &seq->frame_buffers[buffer_num];
+ if (seq_buffer->fill_size + data_size > seq_buffer->data_size)
+ return AVERROR_INVALIDDATA;
+
+ url_fseek(pb, seq->current_frame_offs + data_offs, SEEK_SET);
+ if (get_buffer(pb, seq_buffer->data + seq_buffer->fill_size, data_size) != data_size)
+ return AVERROR_IO;
+
+ seq_buffer->fill_size += data_size;
+ return 0;
+}
+
+static int seq_parse_frame_data(SeqDemuxContext *seq, ByteIOContext *pb)
+{
+ unsigned int offset_table[4], buffer_num[4];
+ TiertexSeqFrameBuffer *seq_buffer;
+ int i, e, err;
+
+ seq->current_frame_offs += SEQ_FRAME_SIZE;
+ url_fseek(pb, seq->current_frame_offs, SEEK_SET);
+
+ /* sound data */
+ seq->current_audio_data_offs = get_le16(pb);
+ if (seq->current_audio_data_offs != 0) {
+ seq->current_audio_data_size = SEQ_AUDIO_BUFFER_SIZE * 2;
+ } else {
+ seq->current_audio_data_size = 0;
+ }
+
+ /* palette data */
+ seq->current_pal_data_offs = get_le16(pb);
+ if (seq->current_pal_data_offs != 0) {
+ seq->current_pal_data_size = 768;
+ } else {
+ seq->current_pal_data_size = 0;
+ }
+
+ /* video data */
+ for (i = 0; i < 4; i++)
+ buffer_num[i] = get_byte(pb);
+
+ for (i = 0; i < 4; i++)
+ offset_table[i] = get_le16(pb);
+
+ for (i = 0; i < 3; i++) {
+ if (offset_table[i] != 0) {
+ for (e = i + 1; e < 4 && offset_table[e] == 0; e++);
+ err = seq_fill_buffer(seq, pb, buffer_num[1 + i],
+ offset_table[i],
+ offset_table[e] - offset_table[i]);
+ if (err != 0)
+ return err;
+ }
+ }
+
+ if (buffer_num[0] != 255) {
+ if (buffer_num[0] >= SEQ_NUM_FRAME_BUFFERS)
+ return AVERROR_INVALIDDATA;
+
+ seq_buffer = &seq->frame_buffers[buffer_num[0]];
+ seq->current_video_data_size = seq_buffer->fill_size;
+ seq->current_video_data_ptr = seq_buffer->data;
+ seq_buffer->fill_size = 0;
+ } else {
+ seq->current_video_data_size = 0;
+ seq->current_video_data_ptr = 0;
+ }
+
+ return 0;
+}
+
+static int seq_read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+ int i, rc;
+ SeqDemuxContext *seq = (SeqDemuxContext *)s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ AVStream *st;
+
+ /* init internal buffers */
+ rc = seq_init_frame_buffers(seq, pb);
+ if (rc)
+ return rc;
+
+ seq->current_frame_offs = 0;
+
+ /* preload (no audio data, just buffer operations related data) */
+ for (i = 1; i <= 100; i++) {
+ rc = seq_parse_frame_data(seq, pb);
+ if (rc)
+ return rc;
+ }
+
+ seq->current_frame_pts = 0;
+
+ seq->audio_buffer_full = 0;
+
+ /* initialize the video decoder stream */
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+
+ 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_id = CODEC_ID_TIERTEXSEQVIDEO;
+ st->codec->codec_tag = 0; /* no fourcc */
+ st->codec->width = SEQ_FRAME_W;
+ st->codec->height = SEQ_FRAME_H;
+
+ /* initialize the audio decoder stream */
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+
+ 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_id = CODEC_ID_PCM_S16BE;
+ st->codec->codec_tag = 0; /* no tag */
+ st->codec->channels = 1;
+ st->codec->sample_rate = SEQ_SAMPLE_RATE;
+ st->codec->bits_per_sample = 16;
+ st->codec->bit_rate = st->codec->sample_rate * st->codec->bits_per_sample * st->codec->channels;
+ st->codec->block_align = st->codec->channels * st->codec->bits_per_sample;
+
+ return 0;
+}
+
+static int seq_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ int rc;
+ SeqDemuxContext *seq = (SeqDemuxContext *)s->priv_data;
+ ByteIOContext *pb = &s->pb;
+
+ if (!seq->audio_buffer_full) {
+ rc = seq_parse_frame_data(seq, pb);
+ if (rc)
+ return rc;
+
+ /* video packet */
+ if (seq->current_pal_data_size + seq->current_video_data_size != 0) {
+ if (av_new_packet(pkt, 1 + seq->current_pal_data_size + seq->current_video_data_size))
+ return AVERROR_NOMEM;
+
+ pkt->data[0] = 0;
+ if (seq->current_pal_data_size != 0) {
+ pkt->data[0] |= 1;
+ url_fseek(pb, seq->current_frame_offs + seq->current_pal_data_offs, SEEK_SET);
+ if (get_buffer(pb, &pkt->data[1], seq->current_pal_data_size) != seq->current_pal_data_size)
+ return AVERROR_IO;
+ }
+ if (seq->current_video_data_size != 0) {
+ pkt->data[0] |= 2;
+ memcpy(&pkt->data[1 + seq->current_pal_data_size],
+ seq->current_video_data_ptr,
+ seq->current_video_data_size);
+ }
+ pkt->stream_index = seq->video_stream_index;
+ pkt->pts = seq->current_frame_pts;
+
+ /* sound buffer will be processed on next read_packet() call */
+ seq->audio_buffer_full = 1;
+ return 0;
+ }
+ }
+
+ /* audio packet */
+ if (seq->current_audio_data_offs == 0) /* end of data reached */
+ return AVERROR_IO;
+
+ url_fseek(pb, seq->current_frame_offs + seq->current_audio_data_offs, SEEK_SET);
+ rc = av_get_packet(pb, pkt, seq->current_audio_data_size);
+ if (rc < 0)
+ return rc;
+
+ pkt->stream_index = seq->audio_stream_index;
+ pkt->pts = seq->current_frame_pts++;
+
+ seq->audio_buffer_full = 0;
+ return 0;
+}
+
+static int seq_read_close(AVFormatContext *s)
+{
+ int i;
+ SeqDemuxContext *seq = (SeqDemuxContext *)s->priv_data;
+
+ for (i = 0; i < SEQ_NUM_FRAME_BUFFERS; i++)
+ av_free(seq->frame_buffers[i].data);
+
+ return 0;
+}
+
+AVInputFormat tiertexseq_demuxer = {
+ "tiertexseq",
+ "Tiertex Limited SEQ format",
+ sizeof(SeqDemuxContext),
+ seq_probe,
+ seq_read_header,
+ seq_read_packet,
+ seq_read_close,
+};
diff --git a/contrib/ffmpeg/libavformat/tta.c b/contrib/ffmpeg/libavformat/tta.c
new file mode 100644
index 000000000..a3709437e
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/tta.c
@@ -0,0 +1,150 @@
+/*
+ * TTA demuxer
+ * Copyright (c) 2006 Alex Beregszaszi
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include "avformat.h"
+#include "bitstream.h"
+
+typedef struct {
+ int totalframes, currentframe;
+ uint32_t *seektable;
+} TTAContext;
+
+static int tta_probe(AVProbeData *p)
+{
+ const uint8_t *d = p->buf;
+ if (p->buf_size < 4)
+ return 0;
+ if (d[0] == 'T' && d[1] == 'T' && d[2] == 'A' && d[3] == '1')
+ return 80;
+ return 0;
+}
+
+static int tta_read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+ TTAContext *c = s->priv_data;
+ AVStream *st;
+ int i, channels, bps, samplerate, datalen, framelen;
+
+ if (get_le32(&s->pb) != ff_get_fourcc("TTA1"))
+ return -1; // not tta file
+
+ url_fskip(&s->pb, 2); // FIXME: flags
+ channels = get_le16(&s->pb);
+ bps = get_le16(&s->pb);
+ samplerate = get_le32(&s->pb);
+ if(samplerate <= 0 || samplerate > 1000000){
+ av_log(s, AV_LOG_ERROR, "nonsense samplerate\n");
+ return -1;
+ }
+
+ datalen = get_le32(&s->pb);
+ if(datalen < 0){
+ av_log(s, AV_LOG_ERROR, "nonsense datalen\n");
+ return -1;
+ }
+
+ url_fskip(&s->pb, 4); // header crc
+
+ framelen = samplerate*256/245;
+ c->totalframes = datalen / framelen + ((datalen % framelen) ? 1 : 0);
+ c->currentframe = 0;
+
+ if(c->totalframes >= UINT_MAX/sizeof(uint32_t)){
+ av_log(s, AV_LOG_ERROR, "totalframes too large\n");
+ return -1;
+ }
+ c->seektable = av_mallocz(sizeof(uint32_t)*c->totalframes);
+ if (!c->seektable)
+ return AVERROR_NOMEM;
+
+ for (i = 0; i < c->totalframes; i++)
+ c->seektable[i] = get_le32(&s->pb);
+ url_fskip(&s->pb, 4); // seektable crc
+
+ st = av_new_stream(s, 0);
+// av_set_pts_info(st, 32, 1, 1000);
+ if (!st)
+ return AVERROR_NOMEM;
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_id = CODEC_ID_TTA;
+ st->codec->channels = channels;
+ st->codec->sample_rate = samplerate;
+ st->codec->bits_per_sample = bps;
+
+ st->codec->extradata_size = url_ftell(&s->pb);
+ 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);
+ get_buffer(&s->pb, st->codec->extradata, st->codec->extradata_size);
+
+ return 0;
+}
+
+static int tta_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ TTAContext *c = s->priv_data;
+ int ret, size;
+
+ // FIXME!
+ if (c->currentframe > c->totalframes)
+ size = 0;
+ else
+ size = c->seektable[c->currentframe];
+
+ c->currentframe++;
+
+ if (av_new_packet(pkt, size) < 0)
+ return AVERROR_IO;
+
+ pkt->pos = url_ftell(&s->pb);
+ pkt->stream_index = 0;
+ ret = get_buffer(&s->pb, pkt->data, size);
+ if (ret <= 0) {
+ av_free_packet(pkt);
+ return AVERROR_IO;
+ }
+ pkt->size = ret;
+// av_log(s, AV_LOG_INFO, "TTA packet #%d desired size: %d read size: %d at pos %d\n",
+// c->currentframe, size, ret, pkt->pos);
+ return 0; //ret;
+}
+
+static int tta_read_close(AVFormatContext *s)
+{
+ TTAContext *c = s->priv_data;
+ if (c->seektable)
+ av_free(c->seektable);
+ return 0;
+}
+
+AVInputFormat tta_demuxer = {
+ "tta",
+ "true-audio",
+ sizeof(TTAContext),
+ tta_probe,
+ tta_read_header,
+ tta_read_packet,
+ tta_read_close,
+ .extensions = "tta",
+};
diff --git a/contrib/ffmpeg/libavformat/udp.c b/contrib/ffmpeg/libavformat/udp.c
new file mode 100644
index 000000000..bbf8ca2ec
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/udp.c
@@ -0,0 +1,492 @@
+/*
+ * UDP prototype streaming system
+ * Copyright (c) 2000, 2001, 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
+ */
+#include "avformat.h"
+#include <unistd.h>
+#include "network.h"
+
+#ifndef IPV6_ADD_MEMBERSHIP
+#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
+#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
+#endif
+
+typedef struct {
+ int udp_fd;
+ int ttl;
+ int is_multicast;
+ int local_port;
+ int reuse_socket;
+#ifndef CONFIG_IPV6
+ struct ip_mreq mreq;
+ struct sockaddr_in dest_addr;
+#else
+ struct sockaddr_storage dest_addr;
+ size_t dest_addr_len;
+#endif
+} UDPContext;
+
+#define UDP_TX_BUF_SIZE 32768
+
+#ifdef CONFIG_IPV6
+
+static int udp_ipv6_is_multicast_address(const struct sockaddr *addr) {
+ if (addr->sa_family == AF_INET)
+ return IN_MULTICAST(ntohl(((struct sockaddr_in *)addr)->sin_addr.s_addr));
+ if (addr->sa_family == AF_INET6)
+ return IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6 *)addr)->sin6_addr);
+ return -1;
+}
+
+static int udp_ipv6_set_multicast_ttl(int sockfd, int mcastTTL, struct sockaddr *addr) {
+ if (addr->sa_family == AF_INET) {
+ if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, &mcastTTL, sizeof(mcastTTL)) < 0) {
+ perror("setsockopt(IP_MULTICAST_TTL)");
+ return -1;
+ }
+ }
+ if (addr->sa_family == AF_INET6) {
+ if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &mcastTTL, sizeof(mcastTTL)) < 0) {
+ perror("setsockopt(IPV6_MULTICAST_HOPS)");
+ return -1;
+ }
+ }
+ return 0;
+}
+
+static int udp_ipv6_join_multicast_group(int sockfd, struct sockaddr *addr) {
+ struct ip_mreq mreq;
+ struct ipv6_mreq mreq6;
+ if (addr->sa_family == AF_INET) {
+ mreq.imr_multiaddr.s_addr = ((struct sockaddr_in *)addr)->sin_addr.s_addr;
+ mreq.imr_interface.s_addr= INADDR_ANY;
+ if (setsockopt(sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const void *)&mreq, sizeof(mreq)) < 0) {
+ perror("setsockopt(IP_ADD_MEMBERSHIP)");
+ return -1;
+ }
+ }
+ if (addr->sa_family == AF_INET6) {
+ memcpy(&mreq6.ipv6mr_multiaddr, &(((struct sockaddr_in6 *)addr)->sin6_addr), sizeof(struct in6_addr));
+ mreq6.ipv6mr_interface= 0;
+ if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq6, sizeof(mreq6)) < 0) {
+ perror("setsockopt(IPV6_ADD_MEMBERSHIP)");
+ return -1;
+ }
+ }
+ return 0;
+}
+
+static int udp_ipv6_leave_multicast_group(int sockfd, struct sockaddr *addr) {
+ struct ip_mreq mreq;
+ struct ipv6_mreq mreq6;
+ if (addr->sa_family == AF_INET) {
+ mreq.imr_multiaddr.s_addr = ((struct sockaddr_in *)addr)->sin_addr.s_addr;
+ mreq.imr_interface.s_addr= INADDR_ANY;
+ if (setsockopt(sockfd, IPPROTO_IP, IP_DROP_MEMBERSHIP, (const void *)&mreq, sizeof(mreq)) < 0) {
+ perror("setsockopt(IP_DROP_MEMBERSHIP)");
+ return -1;
+ }
+ }
+ if (addr->sa_family == AF_INET6) {
+ memcpy(&mreq6.ipv6mr_multiaddr, &(((struct sockaddr_in6 *)addr)->sin6_addr), sizeof(struct in6_addr));
+ mreq6.ipv6mr_interface= 0;
+ if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, &mreq6, sizeof(mreq6)) < 0) {
+ perror("setsockopt(IPV6_DROP_MEMBERSHIP)");
+ return -1;
+ }
+ }
+ return 0;
+}
+
+static struct addrinfo* udp_ipv6_resolve_host(const char *hostname, int port, int type, int family, int flags) {
+ struct addrinfo hints, *res = 0;
+ int error;
+ char sport[16];
+ const char *node = 0, *service = 0;
+
+ if (port > 0) {
+ snprintf(sport, sizeof(sport), "%d", port);
+ service = sport;
+ }
+ if ((hostname) && (hostname[0] != '\0') && (hostname[0] != '?')) {
+ node = hostname;
+ }
+ if ((node) || (service)) {
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_socktype = type;
+ 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));
+ }
+ }
+ return res;
+}
+
+static int udp_ipv6_set_remote_url(URLContext *h, const char *uri) {
+ UDPContext *s = h->priv_data;
+ char hostname[256];
+ int port;
+ struct addrinfo *res0;
+ url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri);
+ res0 = udp_ipv6_resolve_host(hostname, port, SOCK_DGRAM, AF_UNSPEC, 0);
+ if (res0 == 0) return AVERROR_IO;
+ memcpy(&s->dest_addr, res0->ai_addr, res0->ai_addrlen);
+ s->dest_addr_len = res0->ai_addrlen;
+ freeaddrinfo(res0);
+ return 0;
+}
+
+static int udp_ipv6_set_local(URLContext *h) {
+ UDPContext *s = h->priv_data;
+ int udp_fd = -1;
+ struct sockaddr_storage clientaddr;
+ socklen_t addrlen;
+ char sbuf[NI_MAXSERV];
+ char hbuf[NI_MAXHOST];
+ struct addrinfo *res0 = NULL, *res = NULL;
+
+ if (s->local_port != 0) {
+ res0 = udp_ipv6_resolve_host(0, s->local_port, SOCK_DGRAM, AF_UNSPEC, AI_PASSIVE);
+ if (res0 == 0)
+ goto fail;
+ for (res = res0; res; res=res->ai_next) {
+ udp_fd = socket(res->ai_family, SOCK_DGRAM, 0);
+ if (udp_fd > 0) break;
+ perror("socket");
+ }
+ } else {
+ udp_fd = socket(s->dest_addr.ss_family, SOCK_DGRAM, 0);
+ if (udp_fd < 0)
+ perror("socket");
+ }
+
+ if (udp_fd < 0)
+ goto fail;
+
+ if (s->local_port != 0) {
+ if (bind(udp_fd, res0->ai_addr, res0->ai_addrlen) < 0) {
+ perror("bind");
+ goto fail;
+ }
+ freeaddrinfo(res0);
+ res0 = NULL;
+ }
+
+ addrlen = sizeof(clientaddr);
+ if (getsockname(udp_fd, (struct sockaddr *)&clientaddr, &addrlen) < 0) {
+ perror("getsockname");
+ goto fail;
+ }
+
+ if (getnameinfo((struct sockaddr *)&clientaddr, addrlen, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV) != 0) {
+ perror("getnameinfo");
+ goto fail;
+ }
+
+ s->local_port = strtol(sbuf, NULL, 10);
+
+ return udp_fd;
+
+ fail:
+ if (udp_fd >= 0)
+ closesocket(udp_fd);
+ if(res0)
+ freeaddrinfo(res0);
+ return -1;
+}
+
+#endif
+
+
+/**
+ * If no filename is given to av_open_input_file because you want to
+ * get the local port first, then you must call this function to set
+ * the remote server address.
+ *
+ * url syntax: udp://host:port[?option=val...]
+ * option: 'multicast=1' : enable multicast
+ * 'ttl=n' : set the ttl value (for multicast only)
+ * 'localport=n' : set the local port
+ * 'pkt_size=n' : set max packet size
+ * 'reuse=1' : enable reusing the socket
+ *
+ * @param s1 media file context
+ * @param uri of the remote server
+ * @return zero if no error.
+ */
+int udp_set_remote_url(URLContext *h, const char *uri)
+{
+#ifdef CONFIG_IPV6
+ return udp_ipv6_set_remote_url(h, uri);
+#else
+ UDPContext *s = h->priv_data;
+ char hostname[256];
+ int port;
+
+ url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri);
+
+ /* set the destination address */
+ if (resolve_host(&s->dest_addr.sin_addr, hostname) < 0)
+ return AVERROR_IO;
+ s->dest_addr.sin_family = AF_INET;
+ s->dest_addr.sin_port = htons(port);
+ return 0;
+#endif
+}
+
+/**
+ * Return the local port used by the UDP connexion
+ * @param s1 media file context
+ * @return the local port number
+ */
+int udp_get_local_port(URLContext *h)
+{
+ UDPContext *s = h->priv_data;
+ return s->local_port;
+}
+
+/**
+ * Return the udp file handle for select() usage to wait for several RTP
+ * streams at the same time.
+ * @param h media file context
+ */
+int udp_get_file_handle(URLContext *h)
+{
+ UDPContext *s = h->priv_data;
+ return s->udp_fd;
+}
+
+/* put it in UDP context */
+/* return non zero if error */
+static int udp_open(URLContext *h, const char *uri, int flags)
+{
+ char hostname[1024];
+ int port, udp_fd = -1, tmp;
+ UDPContext *s = NULL;
+ int is_output;
+ const char *p;
+ char buf[256];
+#ifndef CONFIG_IPV6
+ struct sockaddr_in my_addr, my_addr1;
+ int len;
+#endif
+
+ h->is_streamed = 1;
+ h->max_packet_size = 1472;
+
+ is_output = (flags & URL_WRONLY);
+
+ s = av_malloc(sizeof(UDPContext));
+ if (!s)
+ return AVERROR(ENOMEM);
+
+ h->priv_data = s;
+ s->ttl = 16;
+ s->is_multicast = 0;
+ s->local_port = 0;
+ s->reuse_socket = 0;
+ p = strchr(uri, '?');
+ if (p) {
+ s->is_multicast = find_info_tag(buf, sizeof(buf), "multicast", p);
+ s->reuse_socket = find_info_tag(buf, sizeof(buf), "reuse", p);
+ if (find_info_tag(buf, sizeof(buf), "ttl", p)) {
+ s->ttl = strtol(buf, NULL, 10);
+ }
+ if (find_info_tag(buf, sizeof(buf), "localport", p)) {
+ s->local_port = strtol(buf, NULL, 10);
+ }
+ if (find_info_tag(buf, sizeof(buf), "pkt_size", p)) {
+ h->max_packet_size = strtol(buf, NULL, 10);
+ }
+ }
+
+ /* fill the dest addr */
+ url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri);
+
+ /* XXX: fix url_split */
+ if (hostname[0] == '\0' || hostname[0] == '?') {
+ /* only accepts null hostname if input */
+ if (s->is_multicast || (flags & URL_WRONLY))
+ goto fail;
+ } else {
+ udp_set_remote_url(h, uri);
+ }
+
+#ifndef CONFIG_IPV6
+ udp_fd = socket(AF_INET, SOCK_DGRAM, 0);
+ if (udp_fd < 0)
+ goto fail;
+
+ my_addr.sin_family = AF_INET;
+ my_addr.sin_addr.s_addr = htonl (INADDR_ANY);
+ if (s->is_multicast && !(h->flags & URL_WRONLY)) {
+ /* special case: the bind must be done on the multicast address port */
+ my_addr.sin_port = s->dest_addr.sin_port;
+ } else {
+ my_addr.sin_port = htons(s->local_port);
+ }
+
+ if (s->reuse_socket)
+ if (setsockopt (udp_fd, SOL_SOCKET, SO_REUSEADDR, &(s->reuse_socket), sizeof(s->reuse_socket)) != 0)
+ goto fail;
+
+ /* the bind is needed to give a port to the socket now */
+ if (bind(udp_fd,(struct sockaddr *)&my_addr, sizeof(my_addr)) < 0)
+ goto fail;
+
+ len = sizeof(my_addr1);
+ getsockname(udp_fd, (struct sockaddr *)&my_addr1, &len);
+ s->local_port = ntohs(my_addr1.sin_port);
+
+#ifdef IP_MULTICAST_TTL
+ if (s->is_multicast) {
+ if (h->flags & URL_WRONLY) {
+ /* output */
+ if (setsockopt(udp_fd, IPPROTO_IP, IP_MULTICAST_TTL,
+ &s->ttl, sizeof(s->ttl)) < 0) {
+ perror("IP_MULTICAST_TTL");
+ goto fail;
+ }
+ } else {
+ /* input */
+ memset(&s->mreq, 0, sizeof(s->mreq));
+ s->mreq.imr_multiaddr = s->dest_addr.sin_addr;
+ s->mreq.imr_interface.s_addr = htonl (INADDR_ANY);
+ if (setsockopt(udp_fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
+ &s->mreq, sizeof(s->mreq)) < 0) {
+ perror("rtp: IP_ADD_MEMBERSHIP");
+ goto fail;
+ }
+ }
+ }
+#endif
+#else
+ if (s->is_multicast && !(h->flags & URL_WRONLY))
+ s->local_port = port;
+ udp_fd = udp_ipv6_set_local(h);
+ if (udp_fd < 0)
+ goto fail;
+ if (s->is_multicast) {
+ if (h->flags & URL_WRONLY) {
+ if (udp_ipv6_set_multicast_ttl(udp_fd, s->ttl, (struct sockaddr *)&s->dest_addr) < 0)
+ goto fail;
+ } else {
+ if (udp_ipv6_join_multicast_group(udp_fd, (struct sockaddr *)&s->dest_addr) < 0)
+ goto fail;
+ }
+ }
+#endif
+
+ if (is_output) {
+ /* limit the tx buf size to limit latency */
+ tmp = UDP_TX_BUF_SIZE;
+ if (setsockopt(udp_fd, SOL_SOCKET, SO_SNDBUF, &tmp, sizeof(tmp)) < 0) {
+ perror("setsockopt sndbuf");
+ goto fail;
+ }
+ }
+
+ s->udp_fd = udp_fd;
+ return 0;
+ fail:
+ if (udp_fd >= 0)
+ closesocket(udp_fd);
+ av_free(s);
+ return AVERROR_IO;
+}
+
+static int udp_read(URLContext *h, uint8_t *buf, int size)
+{
+ UDPContext *s = h->priv_data;
+#ifndef CONFIG_IPV6
+ struct sockaddr_in from;
+#else
+ struct sockaddr_storage from;
+#endif
+ socklen_t from_len;
+ int len;
+
+ for(;;) {
+ from_len = sizeof(from);
+ len = recvfrom (s->udp_fd, buf, size, 0,
+ (struct sockaddr *)&from, &from_len);
+ if (len < 0) {
+ if (errno != EAGAIN && errno != EINTR)
+ return AVERROR_IO;
+ } else {
+ break;
+ }
+ }
+ return len;
+}
+
+static int udp_write(URLContext *h, uint8_t *buf, int size)
+{
+ UDPContext *s = h->priv_data;
+ int ret;
+
+ for(;;) {
+ ret = sendto (s->udp_fd, buf, size, 0,
+ (struct sockaddr *) &s->dest_addr,
+#ifndef CONFIG_IPV6
+ sizeof (s->dest_addr));
+#else
+ s->dest_addr_len);
+#endif
+ if (ret < 0) {
+ if (errno != EINTR && errno != EAGAIN)
+ return AVERROR_IO;
+ } else {
+ break;
+ }
+ }
+ return size;
+}
+
+static int udp_close(URLContext *h)
+{
+ UDPContext *s = h->priv_data;
+
+#ifndef CONFIG_IPV6
+#ifdef IP_DROP_MEMBERSHIP
+ if (s->is_multicast && !(h->flags & URL_WRONLY)) {
+ if (setsockopt(s->udp_fd, IPPROTO_IP, IP_DROP_MEMBERSHIP,
+ &s->mreq, sizeof(s->mreq)) < 0) {
+ perror("IP_DROP_MEMBERSHIP");
+ }
+ }
+#endif
+#else
+ if (s->is_multicast && !(h->flags & URL_WRONLY))
+ udp_ipv6_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr);
+#endif
+ closesocket(s->udp_fd);
+ av_free(s);
+ return 0;
+}
+
+URLProtocol udp_protocol = {
+ "udp",
+ udp_open,
+ udp_read,
+ udp_write,
+ NULL, /* seek */
+ udp_close,
+};
diff --git a/contrib/ffmpeg/libavformat/utils.c b/contrib/ffmpeg/libavformat/utils.c
new file mode 100644
index 000000000..36cb269b5
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/utils.c
@@ -0,0 +1,2888 @@
+/*
+ * Various utilities for ffmpeg system
+ * Copyright (c) 2000, 2001, 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
+ */
+#include "avformat.h"
+#include "allformats.h"
+#include "opt.h"
+
+#undef NDEBUG
+#include <assert.h>
+
+/**
+ * @file libavformat/utils.c
+ * Various utility functions for using ffmpeg library.
+ */
+
+static void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den);
+static void av_frac_add(AVFrac *f, int64_t incr);
+
+/** head of registered input format linked list. */
+AVInputFormat *first_iformat = NULL;
+/** head of registered output format linked list. */
+AVOutputFormat *first_oformat = NULL;
+
+void av_register_input_format(AVInputFormat *format)
+{
+ AVInputFormat **p;
+ p = &first_iformat;
+ while (*p != NULL) p = &(*p)->next;
+ *p = format;
+ format->next = NULL;
+}
+
+void av_register_output_format(AVOutputFormat *format)
+{
+ AVOutputFormat **p;
+ p = &first_oformat;
+ while (*p != NULL) p = &(*p)->next;
+ *p = format;
+ format->next = NULL;
+}
+
+int match_ext(const char *filename, const char *extensions)
+{
+ const char *ext, *p;
+ char ext1[32], *q;
+
+ if(!filename)
+ return 0;
+
+ ext = strrchr(filename, '.');
+ if (ext) {
+ ext++;
+ p = extensions;
+ for(;;) {
+ q = ext1;
+ while (*p != '\0' && *p != ',' && q-ext1<sizeof(ext1)-1)
+ *q++ = *p++;
+ *q = '\0';
+ if (!strcasecmp(ext1, ext))
+ return 1;
+ if (*p == '\0')
+ break;
+ p++;
+ }
+ }
+ return 0;
+}
+
+AVOutputFormat *guess_format(const char *short_name, const char *filename,
+ const char *mime_type)
+{
+ AVOutputFormat *fmt, *fmt_found;
+ int score_max, score;
+
+ /* specific test for image sequences */
+#ifdef CONFIG_IMAGE2_MUXER
+ if (!short_name && filename &&
+ av_filename_number_test(filename) &&
+ av_guess_image2_codec(filename) != CODEC_ID_NONE) {
+ return guess_format("image2", NULL, NULL);
+ }
+#endif
+ /* find the proper file type */
+ fmt_found = NULL;
+ score_max = 0;
+ fmt = first_oformat;
+ while (fmt != NULL) {
+ score = 0;
+ if (fmt->name && short_name && !strcmp(fmt->name, short_name))
+ score += 100;
+ if (fmt->mime_type && mime_type && !strcmp(fmt->mime_type, mime_type))
+ score += 10;
+ if (filename && fmt->extensions &&
+ match_ext(filename, fmt->extensions)) {
+ score += 5;
+ }
+ if (score > score_max) {
+ score_max = score;
+ fmt_found = fmt;
+ }
+ fmt = fmt->next;
+ }
+ return fmt_found;
+}
+
+AVOutputFormat *guess_stream_format(const char *short_name, const char *filename,
+ const char *mime_type)
+{
+ AVOutputFormat *fmt = 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);
+
+ if (stream_fmt)
+ fmt = stream_fmt;
+ }
+
+ return fmt;
+}
+
+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){
+ enum CodecID codec_id= CODEC_ID_NONE;
+
+#ifdef CONFIG_IMAGE2_MUXER
+ if(!strcmp(fmt->name, "image2") || !strcmp(fmt->name, "image2pipe")){
+ codec_id= av_guess_image2_codec(filename);
+ }
+#endif
+ if(codec_id == CODEC_ID_NONE)
+ codec_id= fmt->video_codec;
+ return codec_id;
+ }else if(type == CODEC_TYPE_AUDIO)
+ return fmt->audio_codec;
+ else
+ return CODEC_ID_NONE;
+}
+
+AVInputFormat *av_find_input_format(const char *short_name)
+{
+ AVInputFormat *fmt;
+ for(fmt = first_iformat; fmt != NULL; fmt = fmt->next) {
+ if (!strcmp(fmt->name, short_name))
+ return fmt;
+ }
+ return NULL;
+}
+
+/* memory handling */
+
+void av_destruct_packet(AVPacket *pkt)
+{
+ av_free(pkt->data);
+ pkt->data = NULL; pkt->size = 0;
+}
+
+int av_new_packet(AVPacket *pkt, int size)
+{
+ uint8_t *data;
+ if((unsigned)size > (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE)
+ return AVERROR_NOMEM;
+ data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
+ if (!data)
+ return AVERROR_NOMEM;
+ memset(data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+
+ av_init_packet(pkt);
+ pkt->data = data;
+ pkt->size = size;
+ pkt->destruct = av_destruct_packet;
+ return 0;
+}
+
+int av_get_packet(ByteIOContext *s, AVPacket *pkt, int size)
+{
+ int ret= av_new_packet(pkt, size);
+
+ if(ret<0)
+ return ret;
+
+ pkt->pos= url_ftell(s);
+
+ ret= get_buffer(s, pkt->data, size);
+ if(ret<=0)
+ av_free_packet(pkt);
+ else
+ pkt->size= ret;
+
+ return ret;
+}
+
+int av_dup_packet(AVPacket *pkt)
+{
+ if (pkt->destruct != av_destruct_packet) {
+ uint8_t *data;
+ /* we duplicate the packet and don't forget to put the padding
+ again */
+ if((unsigned)pkt->size > (unsigned)pkt->size + FF_INPUT_BUFFER_PADDING_SIZE)
+ return AVERROR_NOMEM;
+ data = av_malloc(pkt->size + FF_INPUT_BUFFER_PADDING_SIZE);
+ if (!data) {
+ return AVERROR_NOMEM;
+ }
+ memcpy(data, pkt->data, pkt->size);
+ memset(data + pkt->size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+ pkt->data = data;
+ pkt->destruct = av_destruct_packet;
+ }
+ return 0;
+}
+
+int av_filename_number_test(const char *filename)
+{
+ char buf[1024];
+ 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 *fmt1, *fmt;
+ int score;
+
+ fmt = NULL;
+ for(fmt1 = first_iformat; fmt1 != NULL; fmt1 = fmt1->next) {
+ if (!is_opened == !(fmt1->flags & AVFMT_NOFILE))
+ continue;
+ score = 0;
+ if (fmt1->read_probe) {
+ score = fmt1->read_probe(pd);
+ } else if (fmt1->extensions) {
+ if (match_ext(pd->filename, fmt1->extensions)) {
+ score = 50;
+ }
+ }
+ if (score > *score_max) {
+ *score_max = score;
+ fmt = fmt1;
+ }
+ }
+ return fmt;
+}
+
+AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened){
+ int score=0;
+ return av_probe_input_format2(pd, is_opened, &score);
+}
+
+/************************************************************/
+/* input media file */
+
+/**
+ * Open a media file from an IO stream. 'fmt' must be specified.
+ */
+static const char* format_to_name(void* ptr)
+{
+ AVFormatContext* fc = (AVFormatContext*) ptr;
+ if(fc->iformat) return fc->iformat->name;
+ else if(fc->oformat) return fc->oformat->name;
+ else return "NULL";
+}
+
+#define OFFSET(x) offsetof(AVFormatContext,x)
+#define DEFAULT 0 //should be NAN but it doesnt work as its not a constant in glibc as required by ANSI/ISO C
+//these names are too long to be readable
+#define E AV_OPT_FLAG_ENCODING_PARAM
+#define D AV_OPT_FLAG_DECODING_PARAM
+
+static const AVOption options[]={
+{"probesize", NULL, OFFSET(probesize), FF_OPT_TYPE_INT, 32000, 32, INT_MAX, D}, /* 32000 from mpegts.c: 1.0 second at 24Mbit/s */
+{"muxrate", "set mux rate", OFFSET(mux_rate), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, E},
+{"packetsize", "set packet size", OFFSET(packet_size), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, E},
+{"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"},
+{"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},
+{"analyzeduration", NULL, OFFSET(max_analyze_duration), FF_OPT_TYPE_INT, 3*AV_TIME_BASE, 0, INT_MAX, D},
+{NULL},
+};
+
+#undef E
+#undef D
+#undef DEFAULT
+
+static const AVClass av_format_context_class = { "AVFormatContext", format_to_name, options };
+
+static void avformat_get_context_defaults(AVFormatContext *s)
+{
+ memset(s, 0, sizeof(AVFormatContext));
+
+ s->av_class = &av_format_context_class;
+
+ av_opt_set_defaults(s);
+}
+
+AVFormatContext *av_alloc_format_context(void)
+{
+ AVFormatContext *ic;
+ ic = av_malloc(sizeof(AVFormatContext));
+ if (!ic) return ic;
+ avformat_get_context_defaults(ic);
+ ic->av_class = &av_format_context_class;
+ return ic;
+}
+
+int av_open_input_stream(AVFormatContext **ic_ptr,
+ ByteIOContext *pb, const char *filename,
+ AVInputFormat *fmt, AVFormatParameters *ap)
+{
+ int err;
+ AVFormatContext *ic;
+ AVFormatParameters default_ap;
+
+ if(!ap){
+ ap=&default_ap;
+ memset(ap, 0, sizeof(default_ap));
+ }
+
+ if(!ap->prealloced_context)
+ ic = av_alloc_format_context();
+ else
+ ic = *ic_ptr;
+ if (!ic) {
+ err = AVERROR_NOMEM;
+ goto fail;
+ }
+ ic->iformat = fmt;
+ if (pb)
+ ic->pb = *pb;
+ ic->duration = AV_NOPTS_VALUE;
+ ic->start_time = AV_NOPTS_VALUE;
+ pstrcpy(ic->filename, sizeof(ic->filename), filename);
+
+ /* allocate private data */
+ if (fmt->priv_data_size > 0) {
+ ic->priv_data = av_mallocz(fmt->priv_data_size);
+ if (!ic->priv_data) {
+ err = AVERROR_NOMEM;
+ goto fail;
+ }
+ } else {
+ ic->priv_data = NULL;
+ }
+
+ err = ic->iformat->read_header(ic, ap);
+ if (err < 0)
+ goto fail;
+
+ if (pb && !ic->data_offset)
+ ic->data_offset = url_ftell(&ic->pb);
+
+ *ic_ptr = ic;
+ return 0;
+ fail:
+ if (ic) {
+ av_freep(&ic->priv_data);
+ }
+ av_free(ic);
+ *ic_ptr = NULL;
+ return err;
+}
+
+/** Size of probe buffer, for guessing file type from file contents. */
+#define PROBE_BUF_MIN 2048
+#define PROBE_BUF_MAX (1<<20)
+
+int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
+ AVInputFormat *fmt,
+ int buf_size,
+ AVFormatParameters *ap)
+{
+ int err, must_open_file, file_opened, probe_size;
+ AVProbeData probe_data, *pd = &probe_data;
+ ByteIOContext pb1, *pb = &pb1;
+
+ file_opened = 0;
+ pd->filename = "";
+ if (filename)
+ pd->filename = filename;
+ pd->buf = NULL;
+ pd->buf_size = 0;
+
+ if (!fmt) {
+ /* guess format if no file can be opened */
+ fmt = av_probe_input_format(pd, 0);
+ }
+
+ /* do not open file if the format does not need it. XXX: specific
+ hack needed to handle RTSP/TCP */
+ must_open_file = 1;
+ if (fmt && (fmt->flags & AVFMT_NOFILE)) {
+ must_open_file = 0;
+ pb= NULL; //FIXME this or memset(pb, 0, sizeof(ByteIOContext)); otherwise its uninitalized
+ }
+
+ if (!fmt || must_open_file) {
+ /* if no file needed do not try to open one */
+ if (url_fopen(pb, filename, URL_RDONLY) < 0) {
+ err = AVERROR_IO;
+ goto fail;
+ }
+ file_opened = 1;
+ 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);
+ pd->buf_size = get_buffer(pb, pd->buf, probe_size);
+ if (url_fseek(pb, 0, SEEK_SET) < 0) {
+ url_fclose(pb);
+ if (url_fopen(pb, filename, URL_RDONLY) < 0) {
+ file_opened = 0;
+ err = AVERROR_IO;
+ goto fail;
+ }
+ }
+ /* guess file format */
+ fmt = av_probe_input_format2(pd, 1, &score);
+ }
+ av_freep(&pd->buf);
+ }
+
+ /* if still no format found, error */
+ if (!fmt) {
+ err = AVERROR_NOFMT;
+ goto fail;
+ }
+
+ /* XXX: suppress this hack for redirectors */
+#ifdef CONFIG_NETWORK
+ if (fmt == &redir_demuxer) {
+ err = redir_open(ic_ptr, pb);
+ url_fclose(pb);
+ return err;
+ }
+#endif
+
+ /* check filename in case of an image number is expected */
+ if (fmt->flags & AVFMT_NEEDNUMBER) {
+ if (!av_filename_number_test(filename)) {
+ err = AVERROR_NUMEXPECTED;
+ goto fail;
+ }
+ }
+ err = av_open_input_stream(ic_ptr, pb, filename, fmt, ap);
+ if (err)
+ goto fail;
+ return 0;
+ fail:
+ av_freep(&pd->buf);
+ if (file_opened)
+ url_fclose(pb);
+ *ic_ptr = NULL;
+ return err;
+
+}
+
+/*******************************************************/
+
+int av_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ return s->iformat->read_packet(s, pkt);
+}
+
+/**********************************************************/
+
+/**
+ * Get the number of samples of an audio frame. Return (-1) if error.
+ */
+static int get_audio_frame_size(AVCodecContext *enc, int size)
+{
+ int frame_size;
+
+ if (enc->frame_size <= 1) {
+ int bits_per_sample = av_get_bits_per_sample(enc->codec_id);
+
+ if (bits_per_sample) {
+ if (enc->channels == 0)
+ return -1;
+ frame_size = (size << 3) / (bits_per_sample * enc->channels);
+ } else {
+ /* used for example by ADPCM codecs */
+ if (enc->bit_rate == 0)
+ return -1;
+ frame_size = (size * 8 * enc->sample_rate) / enc->bit_rate;
+ }
+ } else {
+ frame_size = enc->frame_size;
+ }
+ return frame_size;
+}
+
+
+/**
+ * Return the frame duration in seconds, return 0 if not available.
+ */
+static void compute_frame_duration(int *pnum, int *pden, AVStream *st,
+ AVCodecParserContext *pc, AVPacket *pkt)
+{
+ int frame_size;
+
+ *pnum = 0;
+ *pden = 0;
+ switch(st->codec->codec_type) {
+ case CODEC_TYPE_VIDEO:
+ if(st->time_base.num*1000LL > st->time_base.den){
+ *pnum = st->time_base.num;
+ *pden = st->time_base.den;
+ }else if(st->codec->time_base.num*1000LL > st->codec->time_base.den){
+ *pnum = st->codec->time_base.num;
+ *pden = st->codec->time_base.den;
+ if (pc && pc->repeat_pict) {
+ *pden *= 2;
+ *pnum = (*pnum) * (2 + pc->repeat_pict);
+ }
+ }
+ break;
+ case CODEC_TYPE_AUDIO:
+ frame_size = get_audio_frame_size(st->codec, pkt->size);
+ if (frame_size < 0)
+ break;
+ *pnum = frame_size;
+ *pden = st->codec->sample_rate;
+ break;
+ default:
+ break;
+ }
+}
+
+static int is_intra_only(AVCodecContext *enc){
+ if(enc->codec_type == CODEC_TYPE_AUDIO){
+ return 1;
+ }else if(enc->codec_type == CODEC_TYPE_VIDEO){
+ switch(enc->codec_id){
+ case CODEC_ID_MJPEG:
+ case CODEC_ID_MJPEGB:
+ case CODEC_ID_LJPEG:
+ case CODEC_ID_RAWVIDEO:
+ case CODEC_ID_DVVIDEO:
+ case CODEC_ID_HUFFYUV:
+ case CODEC_ID_FFVHUFF:
+ case CODEC_ID_ASV1:
+ case CODEC_ID_ASV2:
+ case CODEC_ID_VCR1:
+ return 1;
+ default: break;
+ }
+ }
+ return 0;
+}
+
+static int64_t lsb2full(int64_t lsb, int64_t last_ts, int lsb_bits){
+ int64_t mask = lsb_bits < 64 ? (1LL<<lsb_bits)-1 : -1LL;
+ int64_t delta= last_ts - mask/2;
+ return ((lsb - delta)&mask) + delta;
+}
+
+static void compute_pkt_fields(AVFormatContext *s, AVStream *st,
+ AVCodecParserContext *pc, AVPacket *pkt)
+{
+ int num, den, presentation_delayed, delay, i;
+ /* handle wrapping */
+ if(st->cur_dts != AV_NOPTS_VALUE){
+ if(pkt->pts != AV_NOPTS_VALUE)
+ pkt->pts= lsb2full(pkt->pts, st->cur_dts, st->pts_wrap_bits);
+ if(pkt->dts != AV_NOPTS_VALUE)
+ pkt->dts= lsb2full(pkt->dts, st->cur_dts, st->pts_wrap_bits);
+ }
+
+ 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);
+ }
+ }
+
+ if(is_intra_only(st->codec))
+ pkt->flags |= PKT_FLAG_KEY;
+
+ /* do we have a video B frame ? */
+ delay= st->codec->has_b_frames;
+ presentation_delayed = 0;
+ /* XXX: need has_b_frame, but cannot get it if the codec is
+ not initialized */
+ if (delay &&
+ pc && pc->pict_type != FF_B_TYPE)
+ presentation_delayed = 1;
+ /* this may be redundant, but it shouldnt hurt */
+ if(pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE && pkt->pts > pkt->dts)
+ presentation_delayed = 1;
+
+ if(st->cur_dts == AV_NOPTS_VALUE){
+ st->cur_dts = -delay * pkt->duration;
+ }
+
+// av_log(NULL, AV_LOG_DEBUG, "IN delayed:%d pts:%"PRId64", dts:%"PRId64" cur_dts:%"PRId64" st:%d pc:%p\n", presentation_delayed, pkt->pts, pkt->dts, st->cur_dts, pkt->stream_index, pc);
+ /* interpolate PTS and DTS if they are not present */
+ if(delay <=1){
+ if (presentation_delayed) {
+ /* DTS = decompression time stamp */
+ /* PTS = presentation time stamp */
+ if (pkt->dts == AV_NOPTS_VALUE)
+ pkt->dts = st->last_IP_pts;
+ if (pkt->dts == AV_NOPTS_VALUE)
+ pkt->dts = st->cur_dts;
+
+ /* this is tricky: the dts must be incremented by the duration
+ of the frame we are displaying, i.e. the last I or P frame */
+ if (st->last_IP_duration == 0)
+ st->last_IP_duration = pkt->duration;
+ st->cur_dts = pkt->dts + st->last_IP_duration;
+ st->last_IP_duration = pkt->duration;
+ st->last_IP_pts= pkt->pts;
+ /* cannot compute PTS if not present (we can compute it only
+ by knowing the futur */
+ } else if(pkt->pts != AV_NOPTS_VALUE || pkt->dts != AV_NOPTS_VALUE || pkt->duration){
+ if(pkt->pts != AV_NOPTS_VALUE && pkt->duration){
+ int64_t old_diff= FFABS(st->cur_dts - pkt->duration - pkt->pts);
+ int64_t new_diff= FFABS(st->cur_dts - pkt->pts);
+ if(old_diff < new_diff && old_diff < (pkt->duration>>3)){
+ pkt->pts += pkt->duration;
+ // av_log(NULL, AV_LOG_DEBUG, "id:%d old:%"PRId64" new:%"PRId64" dur:%d cur:%"PRId64" size:%d\n", pkt->stream_index, old_diff, new_diff, pkt->duration, st->cur_dts, pkt->size);
+ }
+ }
+
+ /* presentation is not delayed : PTS and DTS are the same */
+ if(pkt->pts == AV_NOPTS_VALUE)
+ pkt->pts = pkt->dts;
+ if(pkt->pts == AV_NOPTS_VALUE)
+ pkt->pts = st->cur_dts;
+ pkt->dts = pkt->pts;
+ st->cur_dts = pkt->pts + pkt->duration;
+ }
+ }
+
+ if(pkt->pts != AV_NOPTS_VALUE){
+ st->pts_buffer[0]= pkt->pts;
+ for(i=1; i<delay+1 && st->pts_buffer[i] == AV_NOPTS_VALUE; i++)
+ st->pts_buffer[i]= (i-delay-1) * pkt->duration;
+ for(i=0; i<delay && st->pts_buffer[i] > st->pts_buffer[i+1]; i++)
+ FFSWAP(int64_t, st->pts_buffer[i], st->pts_buffer[i+1]);
+ if(pkt->dts == AV_NOPTS_VALUE)
+ pkt->dts= st->pts_buffer[0];
+ if(pkt->dts > st->cur_dts)
+ st->cur_dts = pkt->dts;
+ }
+
+// av_log(NULL, AV_LOG_ERROR, "OUTdelayed:%d/%d pts:%"PRId64", dts:%"PRId64" cur_dts:%"PRId64"\n", presentation_delayed, delay, pkt->pts, pkt->dts, st->cur_dts);
+
+ /* update flags */
+ if (pc) {
+ pkt->flags = 0;
+ /* key frame computation */
+ if (pc->pict_type == FF_I_TYPE)
+ pkt->flags |= PKT_FLAG_KEY;
+ }
+}
+
+void av_destruct_packet_nofree(AVPacket *pkt)
+{
+ pkt->data = NULL; pkt->size = 0;
+}
+
+static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt)
+{
+ AVStream *st;
+ int len, ret, i;
+
+ for(;;) {
+ /* select current input stream component */
+ st = s->cur_st;
+ if (st) {
+ if (!st->need_parsing || !st->parser) {
+ /* no parsing needed: we just output the packet as is */
+ /* raw data support */
+ *pkt = s->cur_pkt;
+ compute_pkt_fields(s, st, NULL, pkt);
+ s->cur_st = NULL;
+ break;
+ } else if (s->cur_len > 0 && st->discard < AVDISCARD_ALL) {
+ len = av_parser_parse(st->parser, st->codec, &pkt->data, &pkt->size,
+ s->cur_ptr, s->cur_len,
+ s->cur_pkt.pts, s->cur_pkt.dts);
+ s->cur_pkt.pts = AV_NOPTS_VALUE;
+ s->cur_pkt.dts = AV_NOPTS_VALUE;
+ /* increment read pointer */
+ s->cur_ptr += len;
+ s->cur_len -= len;
+
+ /* return packet if any */
+ if (pkt->size) {
+ got_packet:
+ pkt->duration = 0;
+ pkt->stream_index = st->index;
+ pkt->pts = st->parser->pts;
+ pkt->dts = st->parser->dts;
+ pkt->destruct = av_destruct_packet_nofree;
+ compute_pkt_fields(s, st, st->parser, pkt);
+
+ if((s->iformat->flags & AVFMT_GENERIC_INDEX) && pkt->flags & PKT_FLAG_KEY){
+ av_add_index_entry(st, st->parser->frame_offset, pkt->dts,
+ 0, 0, AVINDEX_KEYFRAME);
+ }
+
+ break;
+ }
+ } else {
+ /* free packet */
+ av_free_packet(&s->cur_pkt);
+ s->cur_st = NULL;
+ }
+ } else {
+ /* read next packet */
+ ret = av_read_packet(s, &s->cur_pkt);
+ if (ret < 0) {
+ if (ret == AVERROR(EAGAIN))
+ return ret;
+ /* return the last frames, if any */
+ for(i = 0; i < s->nb_streams; i++) {
+ st = s->streams[i];
+ if (st->parser && st->need_parsing) {
+ av_parser_parse(st->parser, st->codec,
+ &pkt->data, &pkt->size,
+ NULL, 0,
+ AV_NOPTS_VALUE, AV_NOPTS_VALUE);
+ if (pkt->size)
+ goto got_packet;
+ }
+ }
+ /* no more packets: really terminates parsing */
+ return ret;
+ }
+
+ st = s->streams[s->cur_pkt.stream_index];
+ if(st->codec->debug & FF_DEBUG_PTS)
+ av_log(s, AV_LOG_DEBUG, "av_read_packet stream=%d, pts=%"PRId64", dts=%"PRId64", size=%d\n",
+ s->cur_pkt.stream_index,
+ s->cur_pkt.pts,
+ s->cur_pkt.dts,
+ s->cur_pkt.size);
+
+ s->cur_st = st;
+ s->cur_ptr = s->cur_pkt.data;
+ s->cur_len = s->cur_pkt.size;
+ if (st->need_parsing && !st->parser) {
+ st->parser = av_parser_init(st->codec->codec_id);
+ if (!st->parser) {
+ /* no parser available : just output the raw packets */
+ st->need_parsing = 0;
+ }else if(st->need_parsing == 2){
+ st->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES;
+ }
+ if(st->parser && (s->iformat->flags & AVFMT_GENERIC_INDEX)){
+ st->parser->last_frame_offset=
+ st->parser->cur_offset= s->cur_pkt.pos;
+ }
+ }
+ }
+ }
+ if(st->codec->debug & FF_DEBUG_PTS)
+ av_log(s, AV_LOG_DEBUG, "av_read_frame_internal stream=%d, pts=%"PRId64", dts=%"PRId64", size=%d\n",
+ pkt->stream_index,
+ pkt->pts,
+ pkt->dts,
+ pkt->size);
+
+ return 0;
+}
+
+int av_read_frame(AVFormatContext *s, AVPacket *pkt)
+{
+ AVPacketList *pktl;
+ int eof=0;
+ const int genpts= s->flags & AVFMT_FLAG_GENPTS;
+
+ for(;;){
+ pktl = s->packet_buffer;
+ if (pktl) {
+ AVPacket *next_pkt= &pktl->pkt;
+
+ if(genpts && next_pkt->dts != AV_NOPTS_VALUE){
+ while(pktl && next_pkt->pts == AV_NOPTS_VALUE){
+ if( pktl->pkt.stream_index == next_pkt->stream_index
+ && next_pkt->dts < pktl->pkt.dts
+ && pktl->pkt.pts != pktl->pkt.dts //not b frame
+ /*&& pktl->pkt.dts != AV_NOPTS_VALUE*/){
+ next_pkt->pts= pktl->pkt.dts;
+ }
+ pktl= pktl->next;
+ }
+ pktl = s->packet_buffer;
+ }
+
+ if( next_pkt->pts != AV_NOPTS_VALUE
+ || next_pkt->dts == AV_NOPTS_VALUE
+ || !genpts || eof){
+ /* read packet from packet buffer, if there is data */
+ *pkt = *next_pkt;
+ s->packet_buffer = pktl->next;
+ av_free(pktl);
+ return 0;
+ }
+ }
+ if(genpts){
+ AVPacketList **plast_pktl= &s->packet_buffer;
+ int ret= av_read_frame_internal(s, pkt);
+ if(ret<0){
+ if(pktl && ret != AVERROR(EAGAIN)){
+ eof=1;
+ continue;
+ }else
+ return ret;
+ }
+
+ /* duplicate the packet */
+ if (av_dup_packet(pkt) < 0)
+ return AVERROR_NOMEM;
+
+ while(*plast_pktl) plast_pktl= &(*plast_pktl)->next; //FIXME maybe maintain pointer to the last?
+
+ pktl = av_mallocz(sizeof(AVPacketList));
+ if (!pktl)
+ return AVERROR_NOMEM;
+
+ /* add the packet in the buffered packet list */
+ *plast_pktl = pktl;
+ pktl->pkt= *pkt;
+ }else{
+ assert(!s->packet_buffer);
+ return av_read_frame_internal(s, pkt);
+ }
+ }
+}
+
+/* XXX: suppress the packet queue */
+static void flush_packet_queue(AVFormatContext *s)
+{
+ AVPacketList *pktl;
+
+ for(;;) {
+ pktl = s->packet_buffer;
+ if (!pktl)
+ break;
+ s->packet_buffer = pktl->next;
+ av_free_packet(&pktl->pkt);
+ av_free(pktl);
+ }
+}
+
+/*******************************************************/
+/* seek support */
+
+int av_find_default_stream_index(AVFormatContext *s)
+{
+ int i;
+ AVStream *st;
+
+ if (s->nb_streams <= 0)
+ return -1;
+ for(i = 0; i < s->nb_streams; i++) {
+ st = s->streams[i];
+ if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
+ return i;
+ }
+ }
+ return 0;
+}
+
+/**
+ * Flush the frame reader.
+ */
+static void av_read_frame_flush(AVFormatContext *s)
+{
+ AVStream *st;
+ int i;
+
+ flush_packet_queue(s);
+
+ /* free previous packet */
+ if (s->cur_st) {
+ if (s->cur_st->parser)
+ av_free_packet(&s->cur_pkt);
+ s->cur_st = NULL;
+ }
+ /* fail safe */
+ s->cur_ptr = NULL;
+ s->cur_len = 0;
+
+ /* for each stream, reset read state */
+ for(i = 0; i < s->nb_streams; i++) {
+ st = s->streams[i];
+
+ if (st->parser) {
+ av_parser_close(st->parser);
+ st->parser = NULL;
+ }
+ st->last_IP_pts = AV_NOPTS_VALUE;
+ st->cur_dts = AV_NOPTS_VALUE; /* we set the current DTS to an unspecified origin */
+ }
+}
+
+void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp){
+ int i;
+
+ for(i = 0; i < s->nb_streams; i++) {
+ AVStream *st = s->streams[i];
+
+ st->cur_dts = av_rescale(timestamp,
+ st->time_base.den * (int64_t)ref_st->time_base.num,
+ st->time_base.num * (int64_t)ref_st->time_base.den);
+ }
+}
+
+int av_add_index_entry(AVStream *st,
+ int64_t pos, int64_t timestamp, int size, int distance, int flags)
+{
+ AVIndexEntry *entries, *ie;
+ int index;
+
+ if((unsigned)st->nb_index_entries + 1 >= UINT_MAX / sizeof(AVIndexEntry))
+ return -1;
+
+ entries = av_fast_realloc(st->index_entries,
+ &st->index_entries_allocated_size,
+ (st->nb_index_entries + 1) *
+ sizeof(AVIndexEntry));
+ if(!entries)
+ return -1;
+
+ st->index_entries= entries;
+
+ index= av_index_search_timestamp(st, timestamp, AVSEEK_FLAG_ANY);
+
+ if(index<0){
+ index= st->nb_index_entries++;
+ ie= &entries[index];
+ assert(index==0 || ie[-1].timestamp < timestamp);
+ }else{
+ ie= &entries[index];
+ if(ie->timestamp != timestamp){
+ if(ie->timestamp <= timestamp)
+ return -1;
+ memmove(entries + index + 1, entries + index, sizeof(AVIndexEntry)*(st->nb_index_entries - index));
+ st->nb_index_entries++;
+ }else if(ie->pos == pos && distance < ie->min_distance) //dont reduce the distance
+ distance= ie->min_distance;
+ }
+
+ ie->pos = pos;
+ ie->timestamp = timestamp;
+ ie->min_distance= distance;
+ ie->size= size;
+ ie->flags = flags;
+
+ return index;
+}
+
+/**
+ * build an index for raw streams using a parser.
+ */
+static void av_build_index_raw(AVFormatContext *s)
+{
+ AVPacket pkt1, *pkt = &pkt1;
+ int ret;
+ AVStream *st;
+
+ st = s->streams[0];
+ av_read_frame_flush(s);
+ url_fseek(&s->pb, s->data_offset, SEEK_SET);
+
+ for(;;) {
+ ret = av_read_frame(s, pkt);
+ if (ret < 0)
+ break;
+ if (pkt->stream_index == 0 && st->parser &&
+ (pkt->flags & PKT_FLAG_KEY)) {
+ av_add_index_entry(st, st->parser->frame_offset, pkt->dts,
+ 0, 0, AVINDEX_KEYFRAME);
+ }
+ av_free_packet(pkt);
+ }
+}
+
+/**
+ * Returns TRUE if we deal with a raw stream.
+ *
+ * Raw codec data and parsing needed.
+ */
+static int is_raw_stream(AVFormatContext *s)
+{
+ AVStream *st;
+
+ if (s->nb_streams != 1)
+ return 0;
+ st = s->streams[0];
+ if (!st->need_parsing)
+ return 0;
+ return 1;
+}
+
+int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp,
+ int flags)
+{
+ AVIndexEntry *entries= st->index_entries;
+ int nb_entries= st->nb_index_entries;
+ int a, b, m;
+ int64_t timestamp;
+
+ a = - 1;
+ b = nb_entries;
+
+ while (b - a > 1) {
+ m = (a + b) >> 1;
+ timestamp = entries[m].timestamp;
+ if(timestamp >= wanted_timestamp)
+ b = m;
+ if(timestamp <= wanted_timestamp)
+ a = m;
+ }
+ m= (flags & AVSEEK_FLAG_BACKWARD) ? a : b;
+
+ if(!(flags & AVSEEK_FLAG_ANY)){
+ while(m>=0 && m<nb_entries && !(entries[m].flags & AVINDEX_KEYFRAME)){
+ m += (flags & AVSEEK_FLAG_BACKWARD) ? -1 : 1;
+ }
+ }
+
+ if(m == nb_entries)
+ return -1;
+ return m;
+}
+
+#define DEBUG_SEEK
+
+int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags){
+ AVInputFormat *avif= s->iformat;
+ int64_t pos_min, pos_max, pos, pos_limit;
+ int64_t ts_min, ts_max, ts;
+ int index;
+ AVStream *st;
+
+ if (stream_index < 0)
+ return -1;
+
+#ifdef DEBUG_SEEK
+ av_log(s, AV_LOG_DEBUG, "read_seek: %d %"PRId64"\n", stream_index, target_ts);
+#endif
+
+ ts_max=
+ ts_min= AV_NOPTS_VALUE;
+ pos_limit= -1; //gcc falsely says it may be uninitalized
+
+ st= s->streams[stream_index];
+ if(st->index_entries){
+ AVIndexEntry *e;
+
+ index= av_index_search_timestamp(st, target_ts, flags | AVSEEK_FLAG_BACKWARD); //FIXME whole func must be checked for non keyframe entries in index case, especially read_timestamp()
+ index= FFMAX(index, 0);
+ e= &st->index_entries[index];
+
+ if(e->timestamp <= target_ts || e->pos == e->min_distance){
+ pos_min= e->pos;
+ ts_min= e->timestamp;
+#ifdef DEBUG_SEEK
+ av_log(s, AV_LOG_DEBUG, "using cached pos_min=0x%"PRIx64" dts_min=%"PRId64"\n",
+ pos_min,ts_min);
+#endif
+ }else{
+ assert(index==0);
+ }
+
+ index= av_index_search_timestamp(st, target_ts, flags & ~AVSEEK_FLAG_BACKWARD);
+ assert(index < st->nb_index_entries);
+ if(index >= 0){
+ e= &st->index_entries[index];
+ assert(e->timestamp >= target_ts);
+ pos_max= e->pos;
+ ts_max= e->timestamp;
+ pos_limit= pos_max - e->min_distance;
+#ifdef DEBUG_SEEK
+ av_log(s, AV_LOG_DEBUG, "using cached pos_max=0x%"PRIx64" pos_limit=0x%"PRIx64" dts_max=%"PRId64"\n",
+ pos_max,pos_limit, ts_max);
+#endif
+ }
+ }
+
+ pos= av_gen_search(s, stream_index, target_ts, pos_min, pos_max, pos_limit, ts_min, ts_max, flags, &ts, avif->read_timestamp);
+ if(pos<0)
+ return -1;
+
+ /* do the seek */
+ url_fseek(&s->pb, pos, SEEK_SET);
+
+ av_update_cur_dts(s, st, ts);
+
+ return 0;
+}
+
+int64_t av_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, int64_t pos_min, int64_t pos_max, int64_t pos_limit, int64_t ts_min, int64_t ts_max, int flags, int64_t *ts_ret, int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t )){
+ int64_t pos, ts;
+ int64_t start_pos, filesize;
+ int no_change;
+
+#ifdef DEBUG_SEEK
+ av_log(s, AV_LOG_DEBUG, "gen_seek: %d %"PRId64"\n", stream_index, target_ts);
+#endif
+
+ if(ts_min == AV_NOPTS_VALUE){
+ pos_min = s->data_offset;
+ ts_min = read_timestamp(s, stream_index, &pos_min, INT64_MAX);
+ if (ts_min == AV_NOPTS_VALUE)
+ return -1;
+ }
+
+ if(ts_max == AV_NOPTS_VALUE){
+ int step= 1024;
+ filesize = url_fsize(&s->pb);
+ pos_max = filesize - 1;
+ do{
+ pos_max -= step;
+ ts_max = read_timestamp(s, stream_index, &pos_max, pos_max + step);
+ step += step;
+ }while(ts_max == AV_NOPTS_VALUE && pos_max >= step);
+ if (ts_max == AV_NOPTS_VALUE)
+ return -1;
+
+ for(;;){
+ int64_t tmp_pos= pos_max + 1;
+ int64_t tmp_ts= read_timestamp(s, stream_index, &tmp_pos, INT64_MAX);
+ if(tmp_ts == AV_NOPTS_VALUE)
+ break;
+ ts_max= tmp_ts;
+ pos_max= tmp_pos;
+ if(tmp_pos >= filesize)
+ break;
+ }
+ pos_limit= pos_max;
+ }
+
+ if(ts_min > ts_max){
+ return -1;
+ }else if(ts_min == ts_max){
+ pos_limit= pos_min;
+ }
+
+ no_change=0;
+ while (pos_min < pos_limit) {
+#ifdef DEBUG_SEEK
+ av_log(s, AV_LOG_DEBUG, "pos_min=0x%"PRIx64" pos_max=0x%"PRIx64" dts_min=%"PRId64" dts_max=%"PRId64"\n",
+ pos_min, pos_max,
+ ts_min, ts_max);
+#endif
+ assert(pos_limit <= pos_max);
+
+ if(no_change==0){
+ int64_t approximate_keyframe_distance= pos_max - pos_limit;
+ // interpolate position (better than dichotomy)
+ pos = av_rescale(target_ts - ts_min, pos_max - pos_min, ts_max - ts_min)
+ + pos_min - approximate_keyframe_distance;
+ }else if(no_change==1){
+ // bisection, if interpolation failed to change min or max pos last time
+ pos = (pos_min + pos_limit)>>1;
+ }else{
+ // linear search if bisection failed, can only happen if there are very few or no keframes between min/max
+ pos=pos_min;
+ }
+ if(pos <= pos_min)
+ pos= pos_min + 1;
+ else if(pos > pos_limit)
+ pos= pos_limit;
+ start_pos= pos;
+
+ ts = read_timestamp(s, stream_index, &pos, INT64_MAX); //may pass pos_limit instead of -1
+ if(pos == pos_max)
+ no_change++;
+ else
+ no_change=0;
+#ifdef DEBUG_SEEK
+av_log(s, AV_LOG_DEBUG, "%"PRId64" %"PRId64" %"PRId64" / %"PRId64" %"PRId64" %"PRId64" target:%"PRId64" limit:%"PRId64" start:%"PRId64" noc:%d\n", pos_min, pos, pos_max, ts_min, ts, ts_max, target_ts, pos_limit, start_pos, no_change);
+#endif
+ assert(ts != AV_NOPTS_VALUE);
+ if (target_ts <= ts) {
+ pos_limit = start_pos - 1;
+ pos_max = pos;
+ ts_max = ts;
+ }
+ if (target_ts >= ts) {
+ pos_min = pos;
+ ts_min = ts;
+ }
+ }
+
+ pos = (flags & AVSEEK_FLAG_BACKWARD) ? pos_min : pos_max;
+ ts = (flags & AVSEEK_FLAG_BACKWARD) ? ts_min : ts_max;
+#ifdef DEBUG_SEEK
+ pos_min = pos;
+ ts_min = read_timestamp(s, stream_index, &pos_min, INT64_MAX);
+ pos_min++;
+ ts_max = read_timestamp(s, stream_index, &pos_min, INT64_MAX);
+ av_log(s, AV_LOG_DEBUG, "pos=0x%"PRIx64" %"PRId64"<=%"PRId64"<=%"PRId64"\n",
+ pos, ts_min, target_ts, ts_max);
+#endif
+ *ts_ret= ts;
+ return pos;
+}
+
+static int av_seek_frame_byte(AVFormatContext *s, int stream_index, int64_t pos, int flags){
+ int64_t pos_min, pos_max;
+#if 0
+ AVStream *st;
+
+ if (stream_index < 0)
+ return -1;
+
+ st= s->streams[stream_index];
+#endif
+
+ pos_min = s->data_offset;
+ pos_max = url_fsize(&s->pb) - 1;
+
+ if (pos < pos_min) pos= pos_min;
+ else if(pos > pos_max) pos= pos_max;
+
+ url_fseek(&s->pb, pos, SEEK_SET);
+
+#if 0
+ av_update_cur_dts(s, st, ts);
+#endif
+ return 0;
+}
+
+static int av_seek_frame_generic(AVFormatContext *s,
+ int stream_index, int64_t timestamp, int flags)
+{
+ int index;
+ AVStream *st;
+ AVIndexEntry *ie;
+
+ st = s->streams[stream_index];
+
+ index = av_index_search_timestamp(st, timestamp, flags);
+
+ if(index < 0){
+ int i;
+ AVPacket pkt;
+
+ if(st->index_entries && st->nb_index_entries){
+ ie= &st->index_entries[st->nb_index_entries-1];
+ url_fseek(&s->pb, ie->pos, SEEK_SET);
+ av_update_cur_dts(s, st, ie->timestamp);
+ }else
+ url_fseek(&s->pb, 0, SEEK_SET);
+
+ for(i=0;; i++) {
+ int ret = av_read_frame(s, &pkt);
+ if(ret<0)
+ break;
+ av_free_packet(&pkt);
+ if(stream_index == pkt.stream_index){
+ if((pkt.flags & PKT_FLAG_KEY) && pkt.dts > timestamp)
+ break;
+ }
+ }
+ index = av_index_search_timestamp(st, timestamp, flags);
+ }
+ if (index < 0)
+ return -1;
+
+ av_read_frame_flush(s);
+ if (s->iformat->read_seek){
+ if(s->iformat->read_seek(s, stream_index, timestamp, flags) >= 0)
+ return 0;
+ }
+ ie = &st->index_entries[index];
+ url_fseek(&s->pb, ie->pos, SEEK_SET);
+
+ av_update_cur_dts(s, st, ie->timestamp);
+
+ return 0;
+}
+
+int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
+{
+ int ret;
+ AVStream *st;
+
+ av_read_frame_flush(s);
+
+ if(flags & AVSEEK_FLAG_BYTE)
+ return av_seek_frame_byte(s, stream_index, timestamp, flags);
+
+ if(stream_index < 0){
+ stream_index= av_find_default_stream_index(s);
+ if(stream_index < 0)
+ return -1;
+
+ st= s->streams[stream_index];
+ /* timestamp for default must be expressed in AV_TIME_BASE units */
+ timestamp = av_rescale(timestamp, st->time_base.den, AV_TIME_BASE * (int64_t)st->time_base.num);
+ }
+ st= s->streams[stream_index];
+
+ /* first, we try the format specific seek */
+ if (s->iformat->read_seek)
+ ret = s->iformat->read_seek(s, stream_index, timestamp, flags);
+ else
+ ret = -1;
+ if (ret >= 0) {
+ return 0;
+ }
+
+ if(s->iformat->read_timestamp)
+ return av_seek_frame_binary(s, stream_index, timestamp, flags);
+ else
+ return av_seek_frame_generic(s, stream_index, timestamp, flags);
+}
+
+/*******************************************************/
+
+/**
+ * Returns TRUE if the stream has accurate timings in any stream.
+ *
+ * @return TRUE if the stream has accurate timings for at least one component.
+ */
+static int av_has_timings(AVFormatContext *ic)
+{
+ int i;
+ AVStream *st;
+
+ for(i = 0;i < ic->nb_streams; i++) {
+ st = ic->streams[i];
+ if (st->start_time != AV_NOPTS_VALUE &&
+ st->duration != AV_NOPTS_VALUE)
+ return 1;
+ }
+ return 0;
+}
+
+/**
+ * Estimate the stream timings from the one of each components.
+ *
+ * Also computes the global bitrate if possible.
+ */
+static void av_update_stream_timings(AVFormatContext *ic)
+{
+ int64_t start_time, start_time1, end_time, end_time1;
+ int i;
+ AVStream *st;
+
+ start_time = INT64_MAX;
+ end_time = INT64_MIN;
+ for(i = 0;i < ic->nb_streams; i++) {
+ st = ic->streams[i];
+ if (st->start_time != AV_NOPTS_VALUE) {
+ start_time1= av_rescale_q(st->start_time, st->time_base, AV_TIME_BASE_Q);
+ if (start_time1 < start_time)
+ start_time = start_time1;
+ if (st->duration != AV_NOPTS_VALUE) {
+ end_time1 = start_time1
+ + av_rescale_q(st->duration, st->time_base, AV_TIME_BASE_Q);
+ if (end_time1 > end_time)
+ end_time = end_time1;
+ }
+ }
+ }
+ if (start_time != INT64_MAX) {
+ ic->start_time = start_time;
+ if (end_time != INT64_MIN) {
+ ic->duration = end_time - start_time;
+ if (ic->file_size > 0) {
+ /* compute the bit rate */
+ ic->bit_rate = (double)ic->file_size * 8.0 * AV_TIME_BASE /
+ (double)ic->duration;
+ }
+ }
+ }
+
+}
+
+static void fill_all_stream_timings(AVFormatContext *ic)
+{
+ int i;
+ AVStream *st;
+
+ av_update_stream_timings(ic);
+ for(i = 0;i < ic->nb_streams; i++) {
+ st = ic->streams[i];
+ if (st->start_time == AV_NOPTS_VALUE) {
+ if(ic->start_time != AV_NOPTS_VALUE)
+ st->start_time = av_rescale_q(ic->start_time, AV_TIME_BASE_Q, st->time_base);
+ if(ic->duration != AV_NOPTS_VALUE)
+ st->duration = av_rescale_q(ic->duration, AV_TIME_BASE_Q, st->time_base);
+ }
+ }
+}
+
+static void av_estimate_timings_from_bit_rate(AVFormatContext *ic)
+{
+ int64_t filesize, duration;
+ int bit_rate, i;
+ AVStream *st;
+
+ /* if bit_rate is already set, we believe it */
+ if (ic->bit_rate == 0) {
+ bit_rate = 0;
+ for(i=0;i<ic->nb_streams;i++) {
+ st = ic->streams[i];
+ bit_rate += st->codec->bit_rate;
+ }
+ ic->bit_rate = bit_rate;
+ }
+
+ /* if duration is already set, we believe it */
+ if (ic->duration == AV_NOPTS_VALUE &&
+ ic->bit_rate != 0 &&
+ ic->file_size != 0) {
+ filesize = ic->file_size;
+ if (filesize > 0) {
+ for(i = 0; i < ic->nb_streams; i++) {
+ st = ic->streams[i];
+ duration= av_rescale(8*filesize, st->time_base.den, ic->bit_rate*(int64_t)st->time_base.num);
+ if (st->start_time == AV_NOPTS_VALUE ||
+ st->duration == AV_NOPTS_VALUE) {
+ st->start_time = 0;
+ st->duration = duration;
+ }
+ }
+ }
+ }
+}
+
+#define DURATION_MAX_READ_SIZE 250000
+
+/* only usable for MPEG-PS streams */
+static void av_estimate_timings_from_pts(AVFormatContext *ic, offset_t old_offset)
+{
+ AVPacket pkt1, *pkt = &pkt1;
+ AVStream *st;
+ int read_size, i, ret;
+ int64_t end_time;
+ int64_t filesize, offset, duration;
+
+ av_read_frame_flush(ic);
+
+ /* 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;
+
+ ret = av_read_packet(ic, pkt);
+ 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;
+ if (offset < 0)
+ offset = 0;
+
+ url_fseek(&ic->pb, offset, 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->duration == AV_NOPTS_VALUE)
+ break;
+ }
+ if (i == ic->nb_streams)
+ break;
+
+ ret = av_read_packet(ic, pkt);
+ if (ret != 0)
+ break;
+ read_size += pkt->size;
+ st = ic->streams[pkt->stream_index];
+ if (pkt->pts != AV_NOPTS_VALUE) {
+ end_time = pkt->pts;
+ duration = end_time - st->start_time;
+ if (duration > 0) {
+ if (st->duration == AV_NOPTS_VALUE ||
+ st->duration < duration)
+ st->duration = duration;
+ }
+ }
+ av_free_packet(pkt);
+ }
+
+ fill_all_stream_timings(ic);
+
+ url_fseek(&ic->pb, old_offset, SEEK_SET);
+}
+
+static void av_estimate_timings(AVFormatContext *ic, offset_t old_offset)
+{
+ int64_t file_size;
+
+ /* get the file size, if possible */
+ if (ic->iformat->flags & AVFMT_NOFILE) {
+ file_size = 0;
+ } else {
+ file_size = url_fsize(&ic->pb);
+ if (file_size < 0)
+ file_size = 0;
+ }
+ ic->file_size = file_size;
+
+ if ((!strcmp(ic->iformat->name, "mpeg") ||
+ !strcmp(ic->iformat->name, "mpegts")) &&
+ file_size && !ic->pb.is_streamed) {
+ /* get accurate estimate from the PTSes */
+ av_estimate_timings_from_pts(ic, old_offset);
+ } else if (av_has_timings(ic)) {
+ /* at least one components has timings - we use them for all
+ the components */
+ fill_all_stream_timings(ic);
+ } else {
+ /* less precise: use bit rate info */
+ av_estimate_timings_from_bit_rate(ic);
+ }
+ av_update_stream_timings(ic);
+
+#if 0
+ {
+ int i;
+ AVStream *st;
+ for(i = 0;i < ic->nb_streams; i++) {
+ st = ic->streams[i];
+ printf("%d: start_time: %0.3f duration: %0.3f\n",
+ i, (double)st->start_time / AV_TIME_BASE,
+ (double)st->duration / AV_TIME_BASE);
+ }
+ printf("stream: start_time: %0.3f duration: %0.3f bitrate=%d kb/s\n",
+ (double)ic->start_time / AV_TIME_BASE,
+ (double)ic->duration / AV_TIME_BASE,
+ ic->bit_rate / 1000);
+ }
+#endif
+}
+
+static int has_codec_parameters(AVCodecContext *enc)
+{
+ int val;
+ switch(enc->codec_type) {
+ case CODEC_TYPE_AUDIO:
+ val = enc->sample_rate;
+ break;
+ case CODEC_TYPE_VIDEO:
+ val = enc->width && enc->pix_fmt != PIX_FMT_NONE;
+ break;
+ default:
+ val = 1;
+ break;
+ }
+ return (val != 0);
+}
+
+static int try_decode_frame(AVStream *st, const uint8_t *data, int size)
+{
+ int16_t *samples;
+ AVCodec *codec;
+ int got_picture, data_size, ret=0;
+ AVFrame picture;
+
+ if(!st->codec->codec){
+ codec = avcodec_find_decoder(st->codec->codec_id);
+ if (!codec)
+ return -1;
+ ret = avcodec_open(st->codec, codec);
+ if (ret < 0)
+ return ret;
+ }
+
+ if(!has_codec_parameters(st->codec)){
+ switch(st->codec->codec_type) {
+ case CODEC_TYPE_VIDEO:
+ ret = avcodec_decode_video(st->codec, &picture,
+ &got_picture, (uint8_t *)data, size);
+ break;
+ case CODEC_TYPE_AUDIO:
+ data_size = FFMAX(size, AVCODEC_MAX_AUDIO_FRAME_SIZE);
+ samples = av_malloc(data_size);
+ if (!samples)
+ goto fail;
+ ret = avcodec_decode_audio2(st->codec, samples,
+ &data_size, (uint8_t *)data, size);
+ av_free(samples);
+ break;
+ default:
+ break;
+ }
+ }
+ fail:
+ return ret;
+}
+
+/* absolute maximum size we read until we abort */
+#define MAX_READ_SIZE 5000000
+
+#define MAX_STD_TIMEBASES (60*12+5)
+static int get_std_framerate(int i){
+ if(i<60*12) return i*1001;
+ else return ((int[]){24,30,60,12,15})[i-60*12]*1000*12;
+}
+
+int av_find_stream_info(AVFormatContext *ic)
+{
+ int i, count, ret, read_size, j;
+ AVStream *st;
+ AVPacket pkt1, *pkt;
+ AVPacketList *pktl=NULL, **ppktl;
+ int64_t last_dts[MAX_STREAMS];
+ int duration_count[MAX_STREAMS]={0};
+ double (*duration_error)[MAX_STD_TIMEBASES];
+ offset_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_NOMEM;
+
+ for(i=0;i<ic->nb_streams;i++) {
+ st = ic->streams[i];
+ if(st->codec->codec_type == CODEC_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) {
+ st->parser = av_parser_init(st->codec->codec_id);
+ if(st->need_parsing == 2 && st->parser){
+ st->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES;
+ }
+ }
+ }
+
+ for(i=0;i<MAX_STREAMS;i++){
+ last_dts[i]= AV_NOPTS_VALUE;
+ }
+
+ count = 0;
+ read_size = 0;
+ ppktl = &ic->packet_buffer;
+ for(;;) {
+ /* check if one codec still needs to be handled */
+ for(i=0;i<ic->nb_streams;i++) {
+ st = ic->streams[i];
+ if (!has_codec_parameters(st->codec))
+ break;
+ /* variable fps and no guess at the real fps */
+ if( (st->codec->time_base.den >= 101LL*st->codec->time_base.num || st->codec->codec_id == CODEC_ID_MPEG2VIDEO)
+ && duration_count[i]<20 && st->codec->codec_type == CODEC_TYPE_VIDEO)
+ break;
+ if(st->parser && st->parser->parser->split && !st->codec->extradata)
+ break;
+ }
+ if (i == ic->nb_streams) {
+ /* NOTE: if the format has no header, then we need to read
+ some packets to get most of the streams, so we cannot
+ stop here */
+ if (!(ic->ctx_flags & AVFMTCTX_NOHEADER)) {
+ /* if we found the info for all the codecs, we can stop */
+ ret = count;
+ break;
+ }
+ }
+ /* we did not get all the codec info, but we read too much data */
+ if (read_size >= MAX_READ_SIZE) {
+ ret = count;
+ break;
+ }
+
+ /* NOTE: a new stream can be added there if no header in file
+ (AVFMTCTX_NOHEADER) */
+ ret = av_read_frame_internal(ic, &pkt1);
+ if (ret < 0) {
+ /* EOF or error */
+ ret = -1; /* we could not have all the codec parameters before EOF */
+ for(i=0;i<ic->nb_streams;i++) {
+ st = ic->streams[i];
+ 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);
+ } else {
+ ret = 0;
+ }
+ }
+ break;
+ }
+
+ pktl = av_mallocz(sizeof(AVPacketList));
+ if (!pktl) {
+ ret = AVERROR_NOMEM;
+ break;
+ }
+
+ /* add the packet in the buffered packet list */
+ *ppktl = pktl;
+ ppktl = &pktl->next;
+
+ pkt = &pktl->pkt;
+ *pkt = pkt1;
+
+ /* duplicate the packet */
+ if (av_dup_packet(pkt) < 0) {
+ ret = AVERROR_NOMEM;
+ break;
+ }
+
+ read_size += pkt->size;
+
+ st = ic->streams[pkt->stream_index];
+ if(codec_info_nb_frames[st->index]>1)
+ codec_info_duration[st->index] += pkt->duration;
+ if (pkt->duration != 0)
+ codec_info_nb_frames[st->index]++;
+
+ {
+ int index= pkt->stream_index;
+ int64_t last= last_dts[index];
+ int64_t duration= pkt->dts - last;
+
+ if(pkt->dts != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && duration>0){
+ double dur= duration * av_q2d(st->time_base);
+
+// if(st->codec->codec_type == CODEC_TYPE_VIDEO)
+// av_log(NULL, AV_LOG_ERROR, "%f\n", dur);
+ if(duration_count[index] < 2)
+ memset(duration_error, 0, MAX_STREAMS * sizeof(*duration_error));
+ for(i=1; i<MAX_STD_TIMEBASES; i++){
+ int framerate= get_std_framerate(i);
+ int ticks= lrintf(dur*framerate/(1001*12));
+ double error= dur - ticks*1001*12/(double)framerate;
+ duration_error[index][i] += error*error;
+ }
+ duration_count[index]++;
+ }
+ if(last == AV_NOPTS_VALUE || duration_count[index]<=1)
+ last_dts[pkt->stream_index]= pkt->dts;
+ }
+ if(st->parser && st->parser->parser->split && !st->codec->extradata){
+ int i= st->parser->parser->split(st->codec, pkt->data, pkt->size);
+ if(i){
+ st->codec->extradata_size= i;
+ st->codec->extradata= av_malloc(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ memcpy(st->codec->extradata, pkt->data, st->codec->extradata_size);
+ memset(st->codec->extradata + i, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+ }
+ }
+
+ /* if still no information, we try to open the codec and to
+ decompress the frame. We try to avoid that in most cases as
+ it takes longer and uses more memory. For MPEG4, 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))*/)
+ try_decode_frame(st, pkt->data, pkt->size);
+
+ if (av_rescale_q(codec_info_duration[st->index], st->time_base, AV_TIME_BASE_Q) >= ic->max_analyze_duration) {
+ break;
+ }
+ count++;
+ }
+
+ // close codecs which where opened in try_decode_frame()
+ for(i=0;i<ic->nb_streams;i++) {
+ st = ic->streams[i];
+ if(st->codec->codec)
+ avcodec_close(st->codec);
+ }
+ for(i=0;i<ic->nb_streams;i++) {
+ st = ic->streams[i];
+ if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
+ if(st->codec->codec_id == CODEC_ID_RAWVIDEO && !st->codec->codec_tag && !st->codec->bits_per_sample)
+ st->codec->codec_tag= avcodec_pix_fmt_to_codec_tag(st->codec->pix_fmt);
+
+ if(duration_count[i]
+ && (st->codec->time_base.num*101LL <= st->codec->time_base.den || st->codec->codec_id == CODEC_ID_MPEG2VIDEO) /*&&
+ //FIXME we should not special case mpeg2, but this needs testing with non mpeg2 ...
+ st->time_base.num*duration_sum[i]/duration_count[i]*101LL > st->time_base.den*/){
+ double best_error= 2*av_q2d(st->time_base);
+ best_error= best_error*best_error*duration_count[i]*1000*12*30;
+
+ for(j=1; j<MAX_STD_TIMEBASES; j++){
+ double error= duration_error[i][j] * get_std_framerate(j);
+// if(st->codec->codec_type == CODEC_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;
+ av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, get_std_framerate(j), 12*1001, INT_MAX);
+ }
+ }
+ }
+
+ if (!st->r_frame_rate.num){
+ if( st->codec->time_base.den * (int64_t)st->time_base.num
+ <= st->codec->time_base.num * (int64_t)st->time_base.den){
+ st->r_frame_rate.num = st->codec->time_base.den;
+ st->r_frame_rate.den = st->codec->time_base.num;
+ }else{
+ st->r_frame_rate.num = st->time_base.den;
+ st->r_frame_rate.den = st->time_base.num;
+ }
+ }
+ }else if(st->codec->codec_type == CODEC_TYPE_AUDIO) {
+ if(!st->codec->bits_per_sample)
+ st->codec->bits_per_sample= av_get_bits_per_sample(st->codec->codec_id);
+ }
+ }
+
+ av_estimate_timings(ic, old_offset);
+#if 0
+ /* correct DTS for b frame streams with no timestamps */
+ for(i=0;i<ic->nb_streams;i++) {
+ st = ic->streams[i];
+ if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
+ if(b-frames){
+ ppktl = &ic->packet_buffer;
+ while(ppkt1){
+ if(ppkt1->stream_index != i)
+ continue;
+ if(ppkt1->pkt->dts < 0)
+ break;
+ if(ppkt1->pkt->pts != AV_NOPTS_VALUE)
+ break;
+ ppkt1->pkt->dts -= delta;
+ ppkt1= ppkt1->next;
+ }
+ if(ppkt1)
+ continue;
+ st->cur_dts -= delta;
+ }
+ }
+ }
+#endif
+
+ av_free(duration_error);
+
+ return ret;
+}
+
+/*******************************************************/
+
+int av_read_play(AVFormatContext *s)
+{
+ if (!s->iformat->read_play)
+ return AVERROR_NOTSUPP;
+ return s->iformat->read_play(s);
+}
+
+int av_read_pause(AVFormatContext *s)
+{
+ if (!s->iformat->read_pause)
+ return AVERROR_NOTSUPP;
+ return s->iformat->read_pause(s);
+}
+
+void av_close_input_file(AVFormatContext *s)
+{
+ int i, must_open_file;
+ AVStream *st;
+
+ /* free previous packet */
+ if (s->cur_st && s->cur_st->parser)
+ av_free_packet(&s->cur_pkt);
+
+ if (s->iformat->read_close)
+ s->iformat->read_close(s);
+ for(i=0;i<s->nb_streams;i++) {
+ /* free all data in a stream component */
+ st = s->streams[i];
+ if (st->parser) {
+ av_parser_close(st->parser);
+ }
+ av_free(st->index_entries);
+ av_free(st->codec->extradata);
+ av_free(st->codec);
+ av_free(st);
+ }
+ flush_packet_queue(s);
+ must_open_file = 1;
+ if (s->iformat->flags & AVFMT_NOFILE) {
+ must_open_file = 0;
+ }
+ if (must_open_file) {
+ url_fclose(&s->pb);
+ }
+ av_freep(&s->priv_data);
+ av_free(s);
+}
+
+AVStream *av_new_stream(AVFormatContext *s, int id)
+{
+ AVStream *st;
+ int i;
+
+ if (s->nb_streams >= MAX_STREAMS)
+ return NULL;
+
+ st = av_mallocz(sizeof(AVStream));
+ if (!st)
+ return NULL;
+
+ st->codec= avcodec_alloc_context();
+ if (s->iformat) {
+ /* no default bitrate if decoding */
+ st->codec->bit_rate = 0;
+ }
+ st->index = s->nb_streams;
+ st->id = id;
+ st->start_time = AV_NOPTS_VALUE;
+ st->duration = AV_NOPTS_VALUE;
+ st->cur_dts = AV_NOPTS_VALUE;
+
+ /* default pts settings is MPEG like */
+ av_set_pts_info(st, 33, 1, 90000);
+ st->last_IP_pts = AV_NOPTS_VALUE;
+ for(i=0; i<MAX_REORDER_DELAY+1; i++)
+ st->pts_buffer[i]= AV_NOPTS_VALUE;
+
+ s->streams[s->nb_streams++] = st;
+ return st;
+}
+
+/************************************************************/
+/* output media file */
+
+int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap)
+{
+ int ret;
+
+ if (s->oformat->priv_data_size > 0) {
+ s->priv_data = av_mallocz(s->oformat->priv_data_size);
+ if (!s->priv_data)
+ return AVERROR_NOMEM;
+ } else
+ s->priv_data = NULL;
+
+ if (s->oformat->set_parameters) {
+ ret = s->oformat->set_parameters(s, ap);
+ if (ret < 0)
+ return ret;
+ }
+ return 0;
+}
+
+int av_write_header(AVFormatContext *s)
+{
+ int ret, i;
+ AVStream *st;
+
+ // some sanity checks
+ for(i=0;i<s->nb_streams;i++) {
+ st = s->streams[i];
+
+ switch (st->codec->codec_type) {
+ case CODEC_TYPE_AUDIO:
+ if(st->codec->sample_rate<=0){
+ av_log(s, AV_LOG_ERROR, "sample rate not set\n");
+ return -1;
+ }
+ break;
+ case CODEC_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){
+ av_log(s, AV_LOG_ERROR, "dimensions not set\n");
+ return -1;
+ }
+ break;
+ }
+
+ if(s->oformat->codec_tag){
+ if(st->codec->codec_tag){
+ //FIXME
+ //check that tag + id is in the table
+ //if neither is in the table -> ok
+ //if tag is in the table with another id -> FAIL
+ //if id is in the table with another tag -> FAIL unless strict < ?
+ }else
+ st->codec->codec_tag= av_codec_get_tag(s->oformat->codec_tag, st->codec->codec_id);
+ }
+ }
+
+ if (!s->priv_data && s->oformat->priv_data_size > 0) {
+ s->priv_data = av_mallocz(s->oformat->priv_data_size);
+ if (!s->priv_data)
+ return AVERROR_NOMEM;
+ }
+
+ if(s->oformat->write_header){
+ ret = s->oformat->write_header(s);
+ if (ret < 0)
+ return ret;
+ }
+
+ /* init PTS generation */
+ for(i=0;i<s->nb_streams;i++) {
+ int64_t den = AV_NOPTS_VALUE;
+ st = s->streams[i];
+
+ switch (st->codec->codec_type) {
+ case CODEC_TYPE_AUDIO:
+ den = (int64_t)st->time_base.num * st->codec->sample_rate;
+ break;
+ case CODEC_TYPE_VIDEO:
+ den = (int64_t)st->time_base.num * st->codec->time_base.den;
+ break;
+ default:
+ break;
+ }
+ if (den != AV_NOPTS_VALUE) {
+ if (den <= 0)
+ return AVERROR_INVALIDDATA;
+ av_frac_init(&st->pts, 0, 0, den);
+ }
+ }
+ return 0;
+}
+
+//FIXME merge with compute_pkt_fields
+static int compute_pkt_fields2(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);
+
+/* if(pkt->pts == AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE)
+ return -1;*/
+
+ /* duration field */
+ if (pkt->duration == 0) {
+ compute_frame_duration(&num, &den, st, NULL, pkt);
+ if (den && num) {
+ pkt->duration = av_rescale(1, num * (int64_t)st->time_base.den, den * (int64_t)st->time_base.num);
+ }
+ }
+
+ //XXX/FIXME this is a temporary hack until all encoders output pts
+ if((pkt->pts == 0 || pkt->pts == AV_NOPTS_VALUE) && pkt->dts == AV_NOPTS_VALUE && !delay){
+ pkt->dts=
+// pkt->pts= st->cur_dts;
+ pkt->pts= st->pts.val;
+ }
+
+ //calculate dts from pts
+ if(pkt->pts != AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE){
+ st->pts_buffer[0]= pkt->pts;
+ for(i=1; i<delay+1 && st->pts_buffer[i] == AV_NOPTS_VALUE; i++)
+ st->pts_buffer[i]= (i-delay-1) * pkt->duration;
+ for(i=0; i<delay && st->pts_buffer[i] > st->pts_buffer[i+1]; i++)
+ FFSWAP(int64_t, st->pts_buffer[i], st->pts_buffer[i+1]);
+
+ pkt->dts= st->pts_buffer[0];
+ }
+
+ if(st->cur_dts && st->cur_dts != AV_NOPTS_VALUE && st->cur_dts >= pkt->dts){
+ av_log(NULL, AV_LOG_ERROR, "error, non monotone timestamps %"PRId64" >= %"PRId64" st:%d\n", st->cur_dts, pkt->dts, st->index);
+ return -1;
+ }
+ if(pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE && pkt->pts < pkt->dts){
+ av_log(NULL, AV_LOG_ERROR, "error, pts < dts (%"PRId64" < %"PRId64")\n",
+ pkt->pts, pkt->dts);
+ return -1;
+ }
+
+// av_log(NULL, 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:
+ frame_size = get_audio_frame_size(st->codec, pkt->size);
+
+ /* HACK/FIXME, we skip the initial 0-size packets as they are most likely equal to the encoder delay,
+ but it would be better if we had the real timestamps from the encoder */
+ if (frame_size >= 0 && (pkt->size || st->pts.num!=st->pts.den>>1 || st->pts.val)) {
+ av_frac_add(&st->pts, (int64_t)st->time_base.den * frame_size);
+ }
+ break;
+ case CODEC_TYPE_VIDEO:
+ av_frac_add(&st->pts, (int64_t)st->time_base.den * st->codec->time_base.num);
+ break;
+ default:
+ break;
+ }
+ return 0;
+}
+
+static void truncate_ts(AVStream *st, AVPacket *pkt){
+ int64_t pts_mask = (2LL << (st->pts_wrap_bits-1)) - 1;
+
+// if(pkt->dts < 0)
+// pkt->dts= 0; //this happens for low_delay=0 and b frames, FIXME, needs further invstigation about what we should do here
+
+ if (pkt->pts != AV_NOPTS_VALUE)
+ pkt->pts &= pts_mask;
+ if (pkt->dts != AV_NOPTS_VALUE)
+ pkt->dts &= pts_mask;
+}
+
+int av_write_frame(AVFormatContext *s, AVPacket *pkt)
+{
+ int ret;
+
+ ret=compute_pkt_fields2(s->streams[pkt->stream_index], pkt);
+ if(ret<0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
+ return ret;
+
+ truncate_ts(s->streams[pkt->stream_index], pkt);
+
+ ret= s->oformat->write_packet(s, pkt);
+ if(!ret)
+ ret= url_ferror(&s->pb);
+ return ret;
+}
+
+int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush){
+ AVPacketList *pktl, **next_point, *this_pktl;
+ int stream_count=0;
+ int streams[MAX_STREAMS];
+
+ if(pkt){
+ AVStream *st= s->streams[ pkt->stream_index];
+
+// assert(pkt->destruct != av_destruct_packet); //FIXME
+
+ this_pktl = av_mallocz(sizeof(AVPacketList));
+ this_pktl->pkt= *pkt;
+ if(pkt->destruct == av_destruct_packet)
+ pkt->destruct= NULL; // non shared -> must keep original from being freed
+ else
+ av_dup_packet(&this_pktl->pkt); //shared -> must dup
+
+ next_point = &s->packet_buffer;
+ while(*next_point){
+ AVStream *st2= s->streams[ (*next_point)->pkt.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((*next_point)->pkt.dts * left > pkt->dts * right) //FIXME this can overflow
+ break;
+ next_point= &(*next_point)->next;
+ }
+ this_pktl->next= *next_point;
+ *next_point= this_pktl;
+ }
+
+ 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;
+ }
+
+ if(s->nb_streams == stream_count || (flush && stream_count)){
+ pktl= s->packet_buffer;
+ *out= pktl->pkt;
+
+ s->packet_buffer= pktl->next;
+ av_freep(&pktl);
+ return 1;
+ }else{
+ av_init_packet(out);
+ return 0;
+ }
+}
+
+/**
+ * Interleaves a AVPacket correctly so it can be muxed.
+ * @param out the interleaved packet will be output here
+ * @param in the input packet
+ * @param flush 1 if no further packets are available as input and all
+ * remaining packets should be output
+ * @return 1 if a packet was output, 0 if no packet could be output,
+ * < 0 if an error occured
+ */
+static int av_interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *in, int flush){
+ if(s->oformat->interleave_packet)
+ return s->oformat->interleave_packet(s, out, in, flush);
+ else
+ return av_interleave_packet_per_dts(s, out, in, flush);
+}
+
+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)
+ 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))
+ return -1;
+
+ if(pkt->dts == AV_NOPTS_VALUE)
+ return -1;
+
+ for(;;){
+ AVPacket opkt;
+ int ret= av_interleave_packet(s, &opkt, pkt, 0);
+ if(ret<=0) //FIXME cleanup needed for ret<0 ?
+ return ret;
+
+ truncate_ts(s->streams[opkt.stream_index], &opkt);
+ ret= s->oformat->write_packet(s, &opkt);
+
+ av_free_packet(&opkt);
+ pkt= NULL;
+
+ if(ret<0)
+ return ret;
+ if(url_ferror(&s->pb))
+ return url_ferror(&s->pb);
+ }
+}
+
+int av_write_trailer(AVFormatContext *s)
+{
+ int ret, i;
+
+ for(;;){
+ AVPacket pkt;
+ ret= av_interleave_packet(s, &pkt, NULL, 1);
+ if(ret<0) //FIXME cleanup needed for ret<0 ?
+ goto fail;
+ if(!ret)
+ break;
+
+ truncate_ts(s->streams[pkt.stream_index], &pkt);
+ ret= s->oformat->write_packet(s, &pkt);
+
+ av_free_packet(&pkt);
+
+ if(ret<0)
+ goto fail;
+ if(url_ferror(&s->pb))
+ goto fail;
+ }
+
+ if(s->oformat->write_trailer)
+ ret = s->oformat->write_trailer(s);
+fail:
+ if(ret == 0)
+ ret=url_ferror(&s->pb);
+ for(i=0;i<s->nb_streams;i++)
+ av_freep(&s->streams[i]->priv_data);
+ av_freep(&s->priv_data);
+ return ret;
+}
+
+/* "user interface" functions */
+
+void dump_format(AVFormatContext *ic,
+ int index,
+ const char *url,
+ int is_output)
+{
+ int i, flags;
+ char buf[256];
+
+ 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);
+ if (!is_output) {
+ av_log(NULL, AV_LOG_INFO, " Duration: ");
+ if (ic->duration != AV_NOPTS_VALUE) {
+ int hours, mins, secs, us;
+ secs = ic->duration / AV_TIME_BASE;
+ us = ic->duration % AV_TIME_BASE;
+ mins = secs / 60;
+ secs %= 60;
+ hours = mins / 60;
+ mins %= 60;
+ av_log(NULL, AV_LOG_INFO, "%02d:%02d:%02d.%01d", hours, mins, secs,
+ (10 * us) / AV_TIME_BASE);
+ } else {
+ av_log(NULL, AV_LOG_INFO, "N/A");
+ }
+ if (ic->start_time != AV_NOPTS_VALUE) {
+ int secs, us;
+ av_log(NULL, AV_LOG_INFO, ", start: ");
+ secs = ic->start_time / AV_TIME_BASE;
+ us = ic->start_time % AV_TIME_BASE;
+ av_log(NULL, AV_LOG_INFO, "%d.%06d",
+ secs, (int)av_rescale(us, 1000000, AV_TIME_BASE));
+ }
+ av_log(NULL, AV_LOG_INFO, ", bitrate: ");
+ if (ic->bit_rate) {
+ av_log(NULL, AV_LOG_INFO,"%d kb/s", ic->bit_rate / 1000);
+ } else {
+ av_log(NULL, AV_LOG_INFO, "N/A");
+ }
+ av_log(NULL, AV_LOG_INFO, "\n");
+ }
+ for(i=0;i<ic->nb_streams;i++) {
+ AVStream *st = ic->streams[i];
+ int g= ff_gcd(st->time_base.num, st->time_base.den);
+ avcodec_string(buf, sizeof(buf), st->codec, is_output);
+ av_log(NULL, AV_LOG_INFO, " Stream #%d.%d", index, i);
+ /* the pid is an important information, so we display it */
+ /* XXX: add a generic system */
+ if (is_output)
+ flags = ic->oformat->flags;
+ else
+ flags = ic->iformat->flags;
+ if (flags & AVFMT_SHOW_IDS) {
+ av_log(NULL, AV_LOG_INFO, "[0x%x]", st->id);
+ }
+ if (strlen(st->language) > 0) {
+ av_log(NULL, AV_LOG_INFO, "(%s)", st->language);
+ }
+ av_log(NULL, AV_LOG_DEBUG, ", %d/%d", st->time_base.num/g, st->time_base.den/g);
+ av_log(NULL, AV_LOG_INFO, ": %s", buf);
+ if(st->codec->codec_type == CODEC_TYPE_VIDEO){
+ if(st->r_frame_rate.den && st->r_frame_rate.num)
+ av_log(NULL, AV_LOG_INFO, ", %5.2f fps(r)", av_q2d(st->r_frame_rate));
+/* else if(st->time_base.den && st->time_base.num)
+ av_log(NULL, AV_LOG_INFO, ", %5.2f fps(m)", 1/av_q2d(st->time_base));*/
+ else
+ av_log(NULL, AV_LOG_INFO, ", %5.2f fps(c)", 1/av_q2d(st->codec->time_base));
+ }
+ av_log(NULL, AV_LOG_INFO, "\n");
+ }
+}
+
+typedef struct {
+ const char *abv;
+ int width, height;
+ int frame_rate, frame_rate_base;
+} AbvEntry;
+
+static AbvEntry frame_abvs[] = {
+ { "ntsc", 720, 480, 30000, 1001 },
+ { "pal", 720, 576, 25, 1 },
+ { "qntsc", 352, 240, 30000, 1001 }, /* VCD compliant ntsc */
+ { "qpal", 352, 288, 25, 1 }, /* VCD compliant pal */
+ { "sntsc", 640, 480, 30000, 1001 }, /* square pixel ntsc */
+ { "spal", 768, 576, 25, 1 }, /* square pixel pal */
+ { "film", 352, 240, 24, 1 },
+ { "ntsc-film", 352, 240, 24000, 1001 },
+ { "sqcif", 128, 96, 0, 0 },
+ { "qcif", 176, 144, 0, 0 },
+ { "cif", 352, 288, 0, 0 },
+ { "4cif", 704, 576, 0, 0 },
+};
+
+int parse_image_size(int *width_ptr, int *height_ptr, const char *str)
+{
+ int i;
+ int n = sizeof(frame_abvs) / sizeof(AbvEntry);
+ const char *p;
+ int frame_width = 0, frame_height = 0;
+
+ for(i=0;i<n;i++) {
+ if (!strcmp(frame_abvs[i].abv, str)) {
+ frame_width = frame_abvs[i].width;
+ frame_height = frame_abvs[i].height;
+ break;
+ }
+ }
+ if (i == n) {
+ p = str;
+ frame_width = strtol(p, (char **)&p, 10);
+ if (*p)
+ p++;
+ frame_height = strtol(p, (char **)&p, 10);
+ }
+ if (frame_width <= 0 || frame_height <= 0)
+ return -1;
+ *width_ptr = frame_width;
+ *height_ptr = frame_height;
+ return 0;
+}
+
+int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg)
+{
+ int i;
+ char* cp;
+
+ /* First, we check our abbreviation table */
+ for (i = 0; i < sizeof(frame_abvs)/sizeof(*frame_abvs); ++i)
+ if (!strcmp(frame_abvs[i].abv, arg)) {
+ *frame_rate = frame_abvs[i].frame_rate;
+ *frame_rate_base = frame_abvs[i].frame_rate_base;
+ return 0;
+ }
+
+ /* Then, we try to parse it as fraction */
+ cp = strchr(arg, '/');
+ if (!cp)
+ cp = strchr(arg, ':');
+ if (cp) {
+ char* cpp;
+ *frame_rate = strtol(arg, &cpp, 10);
+ if (cpp != arg || cpp == cp)
+ *frame_rate_base = strtol(cp+1, &cpp, 10);
+ else
+ *frame_rate = 0;
+ }
+ else {
+ /* Finally we give up and parse it as double */
+ AVRational time_base = av_d2q(strtod(arg, 0), DEFAULT_FRAME_RATE_BASE);
+ *frame_rate_base = time_base.den;
+ *frame_rate = time_base.num;
+ }
+ if (!*frame_rate || !*frame_rate_base)
+ return -1;
+ else
+ return 0;
+}
+
+#ifndef CONFIG_WINCE
+int64_t parse_date(const char *datestr, int duration)
+{
+ const char *p;
+ int64_t t;
+ struct tm dt;
+ int i;
+ static const char *date_fmt[] = {
+ "%Y-%m-%d",
+ "%Y%m%d",
+ };
+ static const char *time_fmt[] = {
+ "%H:%M:%S",
+ "%H%M%S",
+ };
+ const char *q;
+ int is_utc, len;
+ char lastch;
+ int negative = 0;
+
+#undef time
+ time_t now = time(0);
+
+ len = strlen(datestr);
+ if (len > 0)
+ lastch = datestr[len - 1];
+ else
+ lastch = '\0';
+ is_utc = (lastch == 'z' || lastch == 'Z');
+
+ memset(&dt, 0, sizeof(dt));
+
+ p = datestr;
+ q = NULL;
+ if (!duration) {
+ for (i = 0; i < sizeof(date_fmt) / sizeof(date_fmt[0]); i++) {
+ q = small_strptime(p, date_fmt[i], &dt);
+ if (q) {
+ break;
+ }
+ }
+
+ if (!q) {
+ if (is_utc) {
+ dt = *gmtime(&now);
+ } else {
+ dt = *localtime(&now);
+ }
+ dt.tm_hour = dt.tm_min = dt.tm_sec = 0;
+ } else {
+ p = q;
+ }
+
+ if (*p == 'T' || *p == 't' || *p == ' ')
+ p++;
+
+ for (i = 0; i < sizeof(time_fmt) / sizeof(time_fmt[0]); i++) {
+ q = small_strptime(p, time_fmt[i], &dt);
+ if (q) {
+ break;
+ }
+ }
+ } else {
+ if (p[0] == '-') {
+ negative = 1;
+ ++p;
+ }
+ q = small_strptime(p, time_fmt[0], &dt);
+ if (!q) {
+ dt.tm_sec = strtol(p, (char **)&q, 10);
+ dt.tm_min = 0;
+ dt.tm_hour = 0;
+ }
+ }
+
+ /* Now we have all the fields that we can get */
+ if (!q) {
+ if (duration)
+ return 0;
+ else
+ return now * INT64_C(1000000);
+ }
+
+ if (duration) {
+ t = dt.tm_hour * 3600 + dt.tm_min * 60 + dt.tm_sec;
+ } else {
+ dt.tm_isdst = -1; /* unknown */
+ if (is_utc) {
+ t = mktimegm(&dt);
+ } else {
+ t = mktime(&dt);
+ }
+ }
+
+ t *= 1000000;
+
+ if (*q == '.') {
+ int val, n;
+ q++;
+ for (val = 0, n = 100000; n >= 1; n /= 10, q++) {
+ if (!isdigit(*q))
+ break;
+ val += n * (*q - '0');
+ }
+ t += val;
+ }
+ return negative ? -t : t;
+}
+#endif /* CONFIG_WINCE */
+
+int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info)
+{
+ const char *p;
+ char tag[128], *q;
+
+ p = info;
+ if (*p == '?')
+ p++;
+ for(;;) {
+ q = tag;
+ while (*p != '\0' && *p != '=' && *p != '&') {
+ if ((q - tag) < sizeof(tag) - 1)
+ *q++ = *p;
+ p++;
+ }
+ *q = '\0';
+ q = arg;
+ if (*p == '=') {
+ p++;
+ while (*p != '&' && *p != '\0') {
+ if ((q - arg) < arg_size - 1) {
+ if (*p == '+')
+ *q++ = ' ';
+ else
+ *q++ = *p;
+ }
+ p++;
+ }
+ *q = '\0';
+ }
+ if (!strcmp(tag, tag1))
+ return 1;
+ if (*p != '&')
+ break;
+ p++;
+ }
+ return 0;
+}
+
+int av_get_frame_filename(char *buf, int buf_size,
+ const char *path, int number)
+{
+ const char *p;
+ char *q, buf1[20], c;
+ int nd, len, percentd_found;
+
+ q = buf;
+ p = path;
+ percentd_found = 0;
+ for(;;) {
+ c = *p++;
+ if (c == '\0')
+ break;
+ if (c == '%') {
+ do {
+ nd = 0;
+ while (isdigit(*p)) {
+ nd = nd * 10 + *p++ - '0';
+ }
+ c = *p++;
+ } while (isdigit(c));
+
+ switch(c) {
+ case '%':
+ goto addchar;
+ case 'd':
+ if (percentd_found)
+ goto fail;
+ percentd_found = 1;
+ snprintf(buf1, sizeof(buf1), "%0*d", nd, number);
+ len = strlen(buf1);
+ if ((q - buf + len) > buf_size - 1)
+ goto fail;
+ memcpy(q, buf1, len);
+ q += len;
+ break;
+ default:
+ goto fail;
+ }
+ } else {
+ addchar:
+ if ((q - buf) < buf_size - 1)
+ *q++ = c;
+ }
+ }
+ if (!percentd_found)
+ goto fail;
+ *q = '\0';
+ return 0;
+ fail:
+ *q = '\0';
+ return -1;
+}
+
+static void hex_dump_internal(void *avcl, FILE *f, int level, uint8_t *buf, int size)
+{
+ int len, i, j, c;
+#define PRINT(...) do { if (!f) av_log(avcl, level, __VA_ARGS__); else fprintf(f, __VA_ARGS__); } while(0)
+
+ for(i=0;i<size;i+=16) {
+ len = size - i;
+ if (len > 16)
+ len = 16;
+ PRINT("%08x ", i);
+ for(j=0;j<16;j++) {
+ if (j < len)
+ PRINT(" %02x", buf[i+j]);
+ else
+ PRINT(" ");
+ }
+ PRINT(" ");
+ for(j=0;j<len;j++) {
+ c = buf[i+j];
+ if (c < ' ' || c > '~')
+ c = '.';
+ PRINT("%c", c);
+ }
+ PRINT("\n");
+ }
+#undef PRINT
+}
+
+void av_hex_dump(FILE *f, uint8_t *buf, int size)
+{
+ hex_dump_internal(NULL, f, 0, buf, size);
+}
+
+void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size)
+{
+ hex_dump_internal(avcl, NULL, level, buf, size);
+}
+
+ //FIXME needs to know the time_base
+static void pkt_dump_internal(void *avcl, FILE *f, int level, AVPacket *pkt, int dump_payload)
+{
+#define PRINT(...) do { if (!f) av_log(avcl, level, __VA_ARGS__); else fprintf(f, __VA_ARGS__); } while(0)
+ PRINT("stream #%d:\n", pkt->stream_index);
+ PRINT(" keyframe=%d\n", ((pkt->flags & 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=");
+ if (pkt->dts == AV_NOPTS_VALUE)
+ PRINT("N/A");
+ else
+ PRINT("%0.3f", (double)pkt->dts / AV_TIME_BASE);
+ /* PTS may be not known if B frames are present */
+ PRINT(" pts=");
+ if (pkt->pts == AV_NOPTS_VALUE)
+ PRINT("N/A");
+ else
+ PRINT("%0.3f", (double)pkt->pts / AV_TIME_BASE);
+ PRINT("\n");
+ PRINT(" size=%d\n", pkt->size);
+#undef PRINT
+ if (dump_payload)
+ av_hex_dump(f, pkt->data, pkt->size);
+}
+
+void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload)
+{
+ pkt_dump_internal(NULL, f, 0, pkt, dump_payload);
+}
+
+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)
+{
+ const char *p;
+ char *q;
+ int port;
+
+ port = -1;
+
+ p = url;
+ q = proto;
+ while (*p != ':' && *p != '\0') {
+ if ((q - proto) < proto_size - 1)
+ *q++ = *p;
+ p++;
+ }
+ if (proto_size > 0)
+ *q = '\0';
+ if (authorization_size > 0)
+ authorization[0] = '\0';
+ if (*p == '\0') {
+ if (proto_size > 0)
+ proto[0] = '\0';
+ if (hostname_size > 0)
+ hostname[0] = '\0';
+ p = url;
+ } else {
+ char *at,*slash; // PETR: position of '@' character and '/' character
+
+ p++;
+ if (*p == '/')
+ p++;
+ if (*p == '/')
+ p++;
+ at = strchr(p,'@'); // PETR: get the position of '@'
+ slash = strchr(p,'/'); // PETR: get position of '/' - end of hostname
+ if (at && slash && at > slash) at = NULL; // PETR: not interested in '@' behind '/'
+
+ q = at ? authorization : hostname; // PETR: if '@' exists starting with auth.
+
+ while ((at || *p != ':') && *p != '/' && *p != '?' && *p != '\0') { // PETR:
+ if (*p == '@') { // PETR: passed '@'
+ if (authorization_size > 0)
+ *q = '\0';
+ q = hostname;
+ at = NULL;
+ } else if (!at) { // PETR: hostname
+ if ((q - hostname) < hostname_size - 1)
+ *q++ = *p;
+ } else {
+ if ((q - authorization) < authorization_size - 1)
+ *q++ = *p;
+ }
+ p++;
+ }
+ if (hostname_size > 0)
+ *q = '\0';
+ if (*p == ':') {
+ p++;
+ port = strtoul(p, (char **)&p, 10);
+ }
+ }
+ if (port_ptr)
+ *port_ptr = port;
+ pstrcpy(path, path_size, p);
+}
+
+void av_set_pts_info(AVStream *s, int pts_wrap_bits,
+ int pts_num, int pts_den)
+{
+ s->pts_wrap_bits = pts_wrap_bits;
+ s->time_base.num = pts_num;
+ s->time_base.den = pts_den;
+}
+
+/* fraction handling */
+
+/**
+ * f = val + (num / den) + 0.5.
+ *
+ * 'num' is normalized so that it is such as 0 <= num < den.
+ *
+ * @param f fractional number
+ * @param val integer value
+ * @param num must be >= 0
+ * @param den must be >= 1
+ */
+static void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den)
+{
+ num += (den >> 1);
+ if (num >= den) {
+ val += num / den;
+ num = num % den;
+ }
+ f->val = val;
+ f->num = num;
+ f->den = den;
+}
+
+/**
+ * Fractionnal addition to f: f = f + (incr / f->den).
+ *
+ * @param f fractional number
+ * @param incr increment, can be positive or negative
+ */
+static void av_frac_add(AVFrac *f, int64_t incr)
+{
+ int64_t num, den;
+
+ num = f->num + incr;
+ den = f->den;
+ if (num < 0) {
+ f->val += num / den;
+ num = num % den;
+ if (num < 0) {
+ num += den;
+ f->val--;
+ }
+ } else if (num >= den) {
+ f->val += num / den;
+ num = num % den;
+ }
+ f->num = num;
+}
diff --git a/contrib/ffmpeg/libavformat/v4l2.c b/contrib/ffmpeg/libavformat/v4l2.c
new file mode 100644
index 000000000..aeaac3347
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/v4l2.c
@@ -0,0 +1,631 @@
+/*
+ * Video4Linux2 grab interface
+ * Copyright (c) 2000,2001 Fabrice Bellard.
+ * Copyright (c) 2006 Luca Abeni.
+ *
+ * Part of this file is based on the V4L2 video capture example
+ * (http://v4l2spec.bytesex.org/v4l2spec/capture.c)
+ *
+ * Thanks to Michael Niedermayer for providing the mapping between
+ * V4L2_PIX_FMT_* and PIX_FMT_*
+ *
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 <unistd.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/time.h>
+#include <asm/types.h>
+#include <linux/videodev2.h>
+#include <time.h>
+
+static const int desired_video_buffers = 256;
+
+enum io_method {
+ io_read,
+ io_mmap,
+ io_userptr
+};
+
+struct video_data {
+ int fd;
+ int frame_format; /* V4L2_PIX_FMT_* */
+ enum io_method io_method;
+ int width, height;
+ int frame_rate;
+ int frame_rate_base;
+ int frame_size;
+ int top_field_first;
+
+ int buffers;
+ void **buf_start;
+ unsigned int *buf_len;
+};
+
+struct buff_data {
+ int index;
+ int fd;
+};
+
+struct fmt_map {
+ enum PixelFormat ff_fmt;
+ int32_t v4l2_fmt;
+};
+
+static struct fmt_map fmt_conversion_table[] = {
+ {
+ .ff_fmt = PIX_FMT_YUV420P,
+ .v4l2_fmt = V4L2_PIX_FMT_YUV420,
+ },
+ {
+ .ff_fmt = PIX_FMT_YUV422P,
+ .v4l2_fmt = V4L2_PIX_FMT_YUV422P,
+ },
+ {
+ .ff_fmt = PIX_FMT_YUYV422,
+ .v4l2_fmt = V4L2_PIX_FMT_YUYV,
+ },
+ {
+ .ff_fmt = PIX_FMT_UYVY422,
+ .v4l2_fmt = V4L2_PIX_FMT_UYVY,
+ },
+ {
+ .ff_fmt = PIX_FMT_YUV411P,
+ .v4l2_fmt = V4L2_PIX_FMT_YUV411P,
+ },
+ {
+ .ff_fmt = PIX_FMT_YUV410P,
+ .v4l2_fmt = V4L2_PIX_FMT_YUV410,
+ },
+ {
+ .ff_fmt = PIX_FMT_BGR24,
+ .v4l2_fmt = V4L2_PIX_FMT_BGR24,
+ },
+ {
+ .ff_fmt = PIX_FMT_RGB24,
+ .v4l2_fmt = V4L2_PIX_FMT_RGB24,
+ },
+ /*
+ {
+ .ff_fmt = PIX_FMT_RGB32,
+ .v4l2_fmt = V4L2_PIX_FMT_BGR32,
+ },
+ */
+ {
+ .ff_fmt = PIX_FMT_GRAY8,
+ .v4l2_fmt = V4L2_PIX_FMT_GREY,
+ },
+};
+
+static int device_open(AVFormatContext *ctx, uint32_t *capabilities)
+{
+ struct v4l2_capability cap;
+ int fd;
+ int res;
+
+ fd = open(ctx->filename, O_RDWR /*| O_NONBLOCK*/, 0);
+ if (fd < 0) {
+ av_log(ctx, AV_LOG_ERROR, "Cannot open video device %s : %s\n",
+ ctx->filename, strerror(errno));
+
+ return -1;
+ }
+
+ res = ioctl(fd, VIDIOC_QUERYCAP, &cap);
+ // ENOIOCTLCMD definition only availble on __KERNEL__
+ if (res < 0 && errno == 515)
+ {
+ av_log(ctx, AV_LOG_ERROR, "QUERYCAP not implemented, probably V4L device but not supporting V4L2\n");
+ close(fd);
+
+ return -1;
+ }
+ if (res < 0) {
+ av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYCAP): %s\n",
+ strerror(errno));
+ close(fd);
+
+ return -1;
+ }
+ if ((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == 0) {
+ av_log(ctx, AV_LOG_ERROR, "Not a video capture device\n");
+ close(fd);
+
+ return -1;
+ }
+ *capabilities = cap.capabilities;
+
+ return fd;
+}
+
+static int device_init(AVFormatContext *ctx, int *width, int *height, int pix_fmt)
+{
+ struct video_data *s = ctx->priv_data;
+ int fd = s->fd;
+ struct v4l2_format fmt;
+ int res;
+
+ memset(&fmt, 0, sizeof(struct v4l2_format));
+ fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ fmt.fmt.pix.width = *width;
+ fmt.fmt.pix.height = *height;
+ fmt.fmt.pix.pixelformat = pix_fmt;
+ fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
+ res = ioctl(fd, VIDIOC_S_FMT, &fmt);
+ if ((*width != fmt.fmt.pix.width) || (*height != fmt.fmt.pix.height)) {
+ av_log(ctx, AV_LOG_INFO, "The V4L2 driver changed the video from %dx%d to %dx%d\n", *width, *height, fmt.fmt.pix.width, fmt.fmt.pix.height);
+ *width = fmt.fmt.pix.width;
+ *height = fmt.fmt.pix.height;
+ }
+
+ return res;
+}
+
+static int first_field(int fd)
+{
+ int res;
+ v4l2_std_id std;
+
+ res = ioctl(fd, VIDIOC_G_STD, &std);
+ if (res < 0) {
+ return 0;
+ }
+ if (std & V4L2_STD_NTSC) {
+ return 0;
+ }
+
+ return 1;
+}
+
+static uint32_t fmt_ff2v4l(enum PixelFormat pix_fmt)
+{
+ int i;
+
+ for (i = 0; i < sizeof(fmt_conversion_table) / sizeof(struct fmt_map); i++) {
+ if (fmt_conversion_table[i].ff_fmt == pix_fmt) {
+ return fmt_conversion_table[i].v4l2_fmt;
+ }
+ }
+
+ return 0;
+}
+
+static enum PixelFormat fmt_v4l2ff(uint32_t pix_fmt)
+{
+ int i;
+
+ for (i = 0; i < sizeof(fmt_conversion_table) / sizeof(struct fmt_map); i++) {
+ if (fmt_conversion_table[i].v4l2_fmt == pix_fmt) {
+ return fmt_conversion_table[i].ff_fmt;
+ }
+ }
+
+ return -1;
+}
+
+static int mmap_init(AVFormatContext *ctx)
+{
+ struct video_data *s = ctx->priv_data;
+ struct v4l2_requestbuffers req;
+ int i, res;
+
+ memset(&req, 0, sizeof(struct v4l2_requestbuffers));
+ req.count = desired_video_buffers;
+ req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ req.memory = V4L2_MEMORY_MMAP;
+ res = ioctl (s->fd, VIDIOC_REQBUFS, &req);
+ if (res < 0) {
+ if (errno == EINVAL) {
+ av_log(ctx, AV_LOG_ERROR, "Device does not support mmap\n");
+ } else {
+ av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_REQBUFS)\n");
+ }
+
+ return -1;
+ }
+
+ if (req.count < 2) {
+ av_log(ctx, AV_LOG_ERROR, "Insufficient buffer memory\n");
+
+ return -1;
+ }
+ s->buffers = req.count;
+ s->buf_start = av_malloc(sizeof(void *) * s->buffers);
+ if (s->buf_start == NULL) {
+ av_log(ctx, AV_LOG_ERROR, "Cannot allocate buffer pointers\n");
+
+ return -1;
+ }
+ s->buf_len = av_malloc(sizeof(unsigned int) * s->buffers);
+ if (s->buf_len == NULL) {
+ av_log(ctx, AV_LOG_ERROR, "Cannot allocate buffer sizes\n");
+ av_free(s->buf_start);
+
+ return -1;
+ }
+
+ for (i = 0; i < req.count; i++) {
+ struct v4l2_buffer buf;
+
+ memset(&buf, 0, sizeof(struct v4l2_buffer));
+ buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ buf.memory = V4L2_MEMORY_MMAP;
+ buf.index = i;
+ res = ioctl (s->fd, VIDIOC_QUERYBUF, &buf);
+ if (res < 0) {
+ av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYBUF)\n");
+
+ return -1;
+ }
+
+ s->buf_len[i] = buf.length;
+ if (s->buf_len[i] < s->frame_size) {
+ av_log(ctx, AV_LOG_ERROR, "Buffer len [%d] = %d != %d\n", i, s->buf_len[i], s->frame_size);
+
+ return -1;
+ }
+ s->buf_start[i] = mmap (NULL, buf.length,
+ PROT_READ | PROT_WRITE, MAP_SHARED, s->fd, buf.m.offset);
+ if (s->buf_start[i] == MAP_FAILED) {
+ av_log(ctx, AV_LOG_ERROR, "mmap: %s\n", strerror(errno));
+
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+static int read_init(AVFormatContext *ctx)
+{
+ return -1;
+}
+
+static void mmap_release_buffer(AVPacket *pkt)
+{
+ struct v4l2_buffer buf;
+ int res, fd;
+ struct buff_data *buf_descriptor = pkt->priv;
+
+ memset(&buf, 0, sizeof(struct v4l2_buffer));
+ buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ buf.memory = V4L2_MEMORY_MMAP;
+ buf.index = buf_descriptor->index;
+ fd = buf_descriptor->fd;
+ av_free(buf_descriptor);
+
+ res = ioctl (fd, VIDIOC_QBUF, &buf);
+ if (res < 0) {
+ av_log(NULL, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF)\n");
+ }
+ pkt->data = NULL;
+ pkt->size = 0;
+}
+
+static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt)
+{
+ struct video_data *s = ctx->priv_data;
+ struct v4l2_buffer buf;
+ struct buff_data *buf_descriptor;
+ int res;
+
+ memset(&buf, 0, sizeof(struct v4l2_buffer));
+ buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ buf.memory = V4L2_MEMORY_MMAP;
+
+ /* FIXME: Some special treatment might be needed in case of loss of signal... */
+ while ((res = ioctl(s->fd, VIDIOC_DQBUF, &buf)) < 0 &&
+ ((errno == EAGAIN) || (errno == EINTR)));
+ if (res < 0) {
+ av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_DQBUF): %s\n", strerror(errno));
+
+ return -1;
+ }
+ assert (buf.index < s->buffers);
+ if (buf.bytesused != s->frame_size) {
+ av_log(ctx, AV_LOG_ERROR, "The v4l2 frame is %d bytes, but %d bytes are expected\n", buf.bytesused, s->frame_size);
+
+ return -1;
+ }
+
+ /* Image is at s->buff_start[buf.index] */
+ pkt->data= s->buf_start[buf.index];
+ pkt->size = buf.bytesused;
+ pkt->pts = buf.timestamp.tv_sec * INT64_C(1000000) + buf.timestamp.tv_usec;
+ pkt->destruct = mmap_release_buffer;
+ buf_descriptor = av_malloc(sizeof(struct buff_data));
+ if (buf_descriptor == NULL) {
+ /* Something went wrong... Since av_malloc() failed, we cannot even
+ * allocate a buffer for memcopying into it
+ */
+ av_log(ctx, AV_LOG_ERROR, "Failed to allocate a buffer descriptor\n");
+ res = ioctl (s->fd, VIDIOC_QBUF, &buf);
+
+ return -1;
+ }
+ buf_descriptor->fd = s->fd;
+ buf_descriptor->index = buf.index;
+ pkt->priv = buf_descriptor;
+
+ return s->buf_len[buf.index];
+}
+
+static int read_frame(AVFormatContext *ctx, AVPacket *pkt)
+{
+ return -1;
+}
+
+static int mmap_start(AVFormatContext *ctx)
+{
+ struct video_data *s = ctx->priv_data;
+ enum v4l2_buf_type type;
+ int i, res;
+
+ for (i = 0; i < s->buffers; i++) {
+ struct v4l2_buffer buf;
+
+ memset(&buf, 0, sizeof(struct v4l2_buffer));
+ buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ buf.memory = V4L2_MEMORY_MMAP;
+ buf.index = i;
+
+ res = ioctl (s->fd, VIDIOC_QBUF, &buf);
+ if (res < 0) {
+ av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF): %s\n", strerror(errno));
+
+ return -1;
+ }
+ }
+
+ type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ res = ioctl (s->fd, VIDIOC_STREAMON, &type);
+ if (res < 0) {
+ av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_STREAMON): %s\n", strerror(errno));
+
+ return -1;
+ }
+
+ return 0;
+}
+
+static void mmap_close(struct video_data *s)
+{
+ enum v4l2_buf_type type;
+ int i;
+
+ type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ /* We do not check for the result, because we could
+ * not do anything about it anyway...
+ */
+ ioctl(s->fd, VIDIOC_STREAMOFF, &type);
+ for (i = 0; i < s->buffers; i++) {
+ munmap(s->buf_start[i], s->buf_len[i]);
+ }
+ av_free(s->buf_start);
+ av_free(s->buf_len);
+}
+
+static int v4l2_set_parameters( AVFormatContext *s1, AVFormatParameters *ap )
+{
+ struct video_data *s = s1->priv_data;
+ struct v4l2_input input;
+ struct v4l2_standard standard;
+ int i;
+
+ /* set tv video input */
+ memset (&input, 0, sizeof (input));
+ input.index = ap->channel;
+ if(ioctl (s->fd, VIDIOC_ENUMINPUT, &input) < 0) {
+ av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl enum input failed:\n");
+ return AVERROR_IO;
+ }
+
+ av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set input_id: %d, input: %s\n",
+ ap->channel, input.name);
+ if(ioctl (s->fd, VIDIOC_S_INPUT, &input.index) < 0 ) {
+ av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl set input(%d) failed\n",
+ ap->channel);
+ return AVERROR_IO;
+ }
+
+ av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set standard: %s\n",
+ ap->standard );
+ /* set tv standard */
+ memset (&standard, 0, sizeof (standard));
+ for(i=0;;i++) {
+ standard.index = i;
+ if (ioctl(s->fd, VIDIOC_ENUMSTD, &standard) < 0) {
+ av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl set standard(%s) failed\n",
+ ap->standard);
+ return AVERROR_IO;
+ }
+
+ if(!strcasecmp(standard.name, ap->standard)) {
+ break;
+ }
+ }
+
+ av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set standard: %s, id: %"PRIu64"\n",
+ ap->standard, standard.id);
+ if (ioctl(s->fd, VIDIOC_S_STD, &standard.id) < 0) {
+ av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl set standard(%s) failed\n",
+ ap->standard);
+ return AVERROR_IO;
+ }
+
+ return 0;
+}
+
+static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap)
+{
+ struct video_data *s = s1->priv_data;
+ AVStream *st;
+ int width, height;
+ int res, frame_rate, frame_rate_base;
+ uint32_t desired_format, capabilities;
+
+ if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) {
+ av_log(s1, AV_LOG_ERROR, "Missing/Wrong parameters\n");
+
+ return -1;
+ }
+
+ width = ap->width;
+ height = ap->height;
+ frame_rate = ap->time_base.den;
+ frame_rate_base = ap->time_base.num;
+
+ if((unsigned)width > 32767 || (unsigned)height > 32767) {
+ av_log(s1, AV_LOG_ERROR, "Wrong size %dx%d\n", width, height);
+
+ return -1;
+ }
+
+ st = av_new_stream(s1, 0);
+ if (!st) {
+ return AVERROR(ENOMEM);
+ }
+ av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
+
+ s->width = width;
+ s->height = height;
+ s->frame_rate = frame_rate;
+ s->frame_rate_base = frame_rate_base;
+
+ capabilities = 0;
+ s->fd = device_open(s1, &capabilities);
+ if (s->fd < 0) {
+ av_free(st);
+
+ return AVERROR_IO;
+ }
+ av_log(s1, AV_LOG_INFO, "[%d]Capabilities: %x\n", s->fd, capabilities);
+
+ desired_format = fmt_ff2v4l(ap->pix_fmt);
+ if (desired_format == 0 || (device_init(s1, &width, &height, desired_format) < 0)) {
+ int i, done;
+
+ done = 0; i = 0;
+ while (!done) {
+ desired_format = fmt_conversion_table[i].v4l2_fmt;
+ if (device_init(s1, &width, &height, desired_format) < 0) {
+ desired_format = 0;
+ i++;
+ } else {
+ done = 1;
+ }
+ if (i == sizeof(fmt_conversion_table) / sizeof(struct fmt_map)) {
+ done = 1;
+ }
+ }
+ }
+ if (desired_format == 0) {
+ av_log(s1, AV_LOG_ERROR, "Cannot find a proper format.\n");
+ close(s->fd);
+ av_free(st);
+
+ return AVERROR_IO;
+ }
+ s->frame_format = desired_format;
+
+ if( v4l2_set_parameters( s1, ap ) < 0 )
+ return AVERROR_IO;
+
+ st->codec->pix_fmt = fmt_v4l2ff(desired_format);
+ s->frame_size = avpicture_get_size(st->codec->pix_fmt, width, height);
+ if (capabilities & V4L2_CAP_STREAMING) {
+ s->io_method = io_mmap;
+ res = mmap_init(s1);
+ if (res == 0) {
+ res = mmap_start(s1);
+ }
+ } else {
+ s->io_method = io_read;
+ res = read_init(s1);
+ }
+ if (res < 0) {
+ close(s->fd);
+ av_free(st);
+
+ return AVERROR_IO;
+ }
+ s->top_field_first = first_field(s->fd);
+
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ st->codec->codec_id = CODEC_ID_RAWVIDEO;
+ st->codec->width = width;
+ st->codec->height = height;
+ st->codec->time_base.den = frame_rate;
+ st->codec->time_base.num = frame_rate_base;
+ st->codec->bit_rate = s->frame_size * 1/av_q2d(st->codec->time_base) * 8;
+
+ return 0;
+}
+
+static int v4l2_read_packet(AVFormatContext *s1, AVPacket *pkt)
+{
+ struct video_data *s = s1->priv_data;
+ int res;
+
+ if (s->io_method == io_mmap) {
+ av_init_packet(pkt);
+ res = mmap_read_frame(s1, pkt);
+ } else if (s->io_method == io_read) {
+ if (av_new_packet(pkt, s->frame_size) < 0)
+ return AVERROR_IO;
+
+ res = read_frame(s1, pkt);
+ } else {
+ return AVERROR_IO;
+ }
+ if (res < 0) {
+ return AVERROR_IO;
+ }
+
+ if (s1->streams[0]->codec->coded_frame) {
+ s1->streams[0]->codec->coded_frame->interlaced_frame = 1;
+ s1->streams[0]->codec->coded_frame->top_field_first = s->top_field_first;
+ }
+
+ return s->frame_size;
+}
+
+static int v4l2_read_close(AVFormatContext *s1)
+{
+ struct video_data *s = s1->priv_data;
+
+ if (s->io_method == io_mmap) {
+ mmap_close(s);
+ }
+
+ close(s->fd);
+ return 0;
+}
+
+AVInputFormat v4l2_demuxer = {
+ "video4linux2",
+ "video grab",
+ sizeof(struct video_data),
+ NULL,
+ v4l2_read_header,
+ v4l2_read_packet,
+ v4l2_read_close,
+ .flags = AVFMT_NOFILE,
+};
diff --git a/contrib/ffmpeg/libavformat/voc.c b/contrib/ffmpeg/libavformat/voc.c
new file mode 100644
index 000000000..97b73d163
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/voc.c
@@ -0,0 +1,36 @@
+/*
+ * Creative Voice File common data.
+ * Copyright (c) 2006 Aurelien Jacobs <aurel@gnuage.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "voc.h"
+
+const unsigned char voc_magic[21] = "Creative Voice File\x1A";
+
+const AVCodecTag voc_codec_tags[] = {
+ {CODEC_ID_PCM_U8, 0x00},
+ {CODEC_ID_ADPCM_SBPRO_4, 0x01},
+ {CODEC_ID_ADPCM_SBPRO_3, 0x02},
+ {CODEC_ID_ADPCM_SBPRO_2, 0x03},
+ {CODEC_ID_PCM_S16LE, 0x04},
+ {CODEC_ID_PCM_ALAW, 0x06},
+ {CODEC_ID_PCM_MULAW, 0x07},
+ {CODEC_ID_ADPCM_CT, 0x0200},
+ {0, 0},
+};
diff --git a/contrib/ffmpeg/libavformat/voc.h b/contrib/ffmpeg/libavformat/voc.h
new file mode 100644
index 000000000..9b2bb8cce
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/voc.h
@@ -0,0 +1,51 @@
+/*
+ * Creative Voice File demuxer.
+ * Copyright (c) 2006 Aurelien Jacobs <aurel@gnuage.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef VOC_H
+#define VOC_H
+
+#include "avformat.h"
+#include "riff.h" /* for CodecTag */
+
+typedef struct voc_dec_context {
+ int remaining_size;
+} voc_dec_context_t;
+
+typedef enum voc_type {
+ VOC_TYPE_EOF = 0x00,
+ VOC_TYPE_VOICE_DATA = 0x01,
+ VOC_TYPE_VOICE_DATA_CONT = 0x02,
+ VOC_TYPE_SILENCE = 0x03,
+ VOC_TYPE_MARKER = 0x04,
+ VOC_TYPE_ASCII = 0x05,
+ VOC_TYPE_REPETITION_START = 0x06,
+ VOC_TYPE_REPETITION_END = 0x07,
+ VOC_TYPE_EXTENDED = 0x08,
+ VOC_TYPE_NEW_VOICE_DATA = 0x09,
+} voc_type_t;
+
+extern const unsigned char voc_magic[21];
+extern const AVCodecTag voc_codec_tags[];
+
+int voc_get_packet(AVFormatContext *s, AVPacket *pkt,
+ AVStream *st, int max_size);
+
+#endif
diff --git a/contrib/ffmpeg/libavformat/vocdec.c b/contrib/ffmpeg/libavformat/vocdec.c
new file mode 100644
index 000000000..85d304dff
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/vocdec.c
@@ -0,0 +1,155 @@
+/*
+ * Creative Voice File demuxer.
+ * Copyright (c) 2006 Aurelien Jacobs <aurel@gnuage.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "voc.h"
+
+
+
+
+static int voc_probe(AVProbeData *p)
+{
+ int version, check;
+
+ if (p->buf_size < 26)
+ return 0;
+ if (memcmp(p->buf, voc_magic, sizeof(voc_magic) - 1))
+ return 0;
+ version = p->buf[22] | (p->buf[23] << 8);
+ check = p->buf[24] | (p->buf[25] << 8);
+ if (~version + 0x1234 != check)
+ return 10;
+
+ return AVPROBE_SCORE_MAX;
+}
+
+static int voc_read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+ voc_dec_context_t *voc = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ int header_size;
+ AVStream *st;
+
+ url_fskip(pb, 20);
+ header_size = get_le16(pb) - 22;
+ if (header_size != 4) {
+ av_log(s, AV_LOG_ERROR, "unknown header size: %d\n", header_size);
+ return AVERROR_NOTSUPP;
+ }
+ url_fskip(pb, header_size);
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+
+ voc->remaining_size = 0;
+ return 0;
+}
+
+int
+voc_get_packet(AVFormatContext *s, AVPacket *pkt, AVStream *st, int max_size)
+{
+ voc_dec_context_t *voc = s->priv_data;
+ AVCodecContext *dec = st->codec;
+ ByteIOContext *pb = &s->pb;
+ voc_type_t type;
+ int size;
+ int sample_rate = 0;
+ int channels = 1;
+
+ while (!voc->remaining_size) {
+ type = get_byte(pb);
+ if (type == VOC_TYPE_EOF)
+ return AVERROR_IO;
+ voc->remaining_size = get_le24(pb);
+ max_size -= 4;
+
+ switch (type) {
+ case VOC_TYPE_VOICE_DATA:
+ dec->sample_rate = 1000000 / (256 - get_byte(pb));
+ if (sample_rate)
+ dec->sample_rate = sample_rate;
+ dec->channels = channels;
+ dec->codec_id = codec_get_id(voc_codec_tags, get_byte(pb));
+ dec->bits_per_sample = av_get_bits_per_sample(dec->codec_id);
+ voc->remaining_size -= 2;
+ max_size -= 2;
+ channels = 1;
+ break;
+
+ case VOC_TYPE_VOICE_DATA_CONT:
+ break;
+
+ case VOC_TYPE_EXTENDED:
+ sample_rate = get_le16(pb);
+ get_byte(pb);
+ channels = get_byte(pb) + 1;
+ sample_rate = 256000000 / (channels * (65536 - sample_rate));
+ voc->remaining_size = 0;
+ max_size -= 4;
+ break;
+
+ case VOC_TYPE_NEW_VOICE_DATA:
+ dec->sample_rate = get_le32(pb);
+ dec->bits_per_sample = get_byte(pb);
+ dec->channels = get_byte(pb);
+ dec->codec_id = codec_get_id(voc_codec_tags, get_le16(pb));
+ url_fskip(pb, 4);
+ voc->remaining_size -= 12;
+ max_size -= 12;
+ break;
+
+ default:
+ url_fskip(pb, voc->remaining_size);
+ max_size -= voc->remaining_size;
+ voc->remaining_size = 0;
+ break;
+ }
+ }
+
+ dec->bit_rate = dec->sample_rate * dec->bits_per_sample;
+
+ if (max_size <= 0)
+ max_size = 2048;
+ size = FFMIN(voc->remaining_size, max_size);
+ voc->remaining_size -= size;
+ return av_get_packet(pb, pkt, size);
+}
+
+static int voc_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ return voc_get_packet(s, pkt, s->streams[0], 0);
+}
+
+static int voc_read_close(AVFormatContext *s)
+{
+ return 0;
+}
+
+AVInputFormat voc_demuxer = {
+ "voc",
+ "Creative Voice File format",
+ sizeof(voc_dec_context_t),
+ voc_probe,
+ voc_read_header,
+ voc_read_packet,
+ voc_read_close,
+ .codec_tag=(const AVCodecTag*[]){voc_codec_tags, 0},
+};
diff --git a/contrib/ffmpeg/libavformat/vocenc.c b/contrib/ffmpeg/libavformat/vocenc.c
new file mode 100644
index 000000000..6a07c92dd
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/vocenc.c
@@ -0,0 +1,103 @@
+/*
+ * Creative Voice File muxer.
+ * Copyright (c) 2006 Aurelien Jacobs <aurel@gnuage.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "voc.h"
+
+
+typedef struct voc_enc_context {
+ int param_written;
+} voc_enc_context_t;
+
+static int voc_write_header(AVFormatContext *s)
+{
+ ByteIOContext *pb = &s->pb;
+ const int header_size = 26;
+ const int version = 0x0114;
+
+ if (s->nb_streams != 1
+ || s->streams[0]->codec->codec_type != CODEC_TYPE_AUDIO)
+ return AVERROR_NOTSUPP;
+
+ put_buffer(pb, voc_magic, sizeof(voc_magic) - 1);
+ put_le16(pb, header_size);
+ put_le16(pb, version);
+ put_le16(pb, ~version + 0x1234);
+
+ return 0;
+}
+
+static int voc_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ voc_enc_context_t *voc = s->priv_data;
+ AVCodecContext *enc = s->streams[0]->codec;
+ ByteIOContext *pb = &s->pb;
+
+ if (!voc->param_written) {
+ if (enc->codec_tag > 0xFF) {
+ put_byte(pb, VOC_TYPE_NEW_VOICE_DATA);
+ put_le24(pb, pkt->size + 12);
+ put_le32(pb, enc->sample_rate);
+ put_byte(pb, enc->bits_per_sample);
+ put_byte(pb, enc->channels);
+ put_le16(pb, enc->codec_tag);
+ put_le32(pb, 0);
+ } else {
+ if (s->streams[0]->codec->channels > 1) {
+ put_byte(pb, VOC_TYPE_EXTENDED);
+ put_le24(pb, 4);
+ put_le16(pb, 65536-256000000/(enc->sample_rate*enc->channels));
+ put_byte(pb, enc->codec_tag);
+ put_byte(pb, enc->channels - 1);
+ }
+ put_byte(pb, VOC_TYPE_VOICE_DATA);
+ put_le24(pb, pkt->size + 2);
+ put_byte(pb, 256 - 1000000 / enc->sample_rate);
+ put_byte(pb, enc->codec_tag);
+ }
+ voc->param_written = 1;
+ } else {
+ put_byte(pb, VOC_TYPE_VOICE_DATA_CONT);
+ put_le24(pb, pkt->size);
+ }
+
+ put_buffer(pb, pkt->data, pkt->size);
+ return 0;
+}
+
+static int voc_write_trailer(AVFormatContext *s)
+{
+ put_byte(&s->pb, 0);
+ return 0;
+}
+
+AVOutputFormat voc_muxer = {
+ "voc",
+ "Creative Voice File format",
+ "audio/x-voc",
+ "voc",
+ sizeof(voc_enc_context_t),
+ CODEC_ID_PCM_U8,
+ CODEC_ID_NONE,
+ voc_write_header,
+ voc_write_packet,
+ voc_write_trailer,
+ .codec_tag=(const AVCodecTag*[]){voc_codec_tags, 0},
+};
diff --git a/contrib/ffmpeg/libavformat/wav.c b/contrib/ffmpeg/libavformat/wav.c
new file mode 100644
index 000000000..0699bec70
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/wav.c
@@ -0,0 +1,285 @@
+/*
+ * WAV muxer and demuxer
+ * Copyright (c) 2001, 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
+ */
+#include "avformat.h"
+#include "allformats.h"
+#include "riff.h"
+
+typedef struct {
+ offset_t data;
+ offset_t data_end;
+ int64_t minpts;
+ int64_t maxpts;
+ int last_duration;
+} WAVContext;
+
+#ifdef CONFIG_MUXERS
+static int wav_write_header(AVFormatContext *s)
+{
+ WAVContext *wav = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ offset_t fmt, fact;
+
+ put_tag(pb, "RIFF");
+ put_le32(pb, 0); /* file length */
+ put_tag(pb, "WAVE");
+
+ /* format header */
+ fmt = start_tag(pb, "fmt ");
+ if (put_wav_header(pb, s->streams[0]->codec) < 0) {
+ av_free(wav);
+ return -1;
+ }
+ end_tag(pb, fmt);
+
+ if(s->streams[0]->codec->codec_tag != 0x01 /* hence for all other than PCM */
+ && !url_is_streamed(&s->pb)) {
+ fact = start_tag(pb, "fact");
+ put_le32(pb, 0);
+ end_tag(pb, fact);
+ }
+
+ av_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate);
+ wav->maxpts = wav->last_duration = 0;
+ wav->minpts = INT64_MAX;
+
+ /* data header */
+ wav->data = start_tag(pb, "data");
+
+ put_flush_packet(pb);
+
+ return 0;
+}
+
+static int wav_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ ByteIOContext *pb = &s->pb;
+ WAVContext *wav = s->priv_data;
+ put_buffer(pb, pkt->data, pkt->size);
+ if(pkt->pts != AV_NOPTS_VALUE) {
+ wav->minpts = FFMIN(wav->minpts, pkt->pts);
+ wav->maxpts = FFMAX(wav->maxpts, pkt->pts);
+ wav->last_duration = pkt->duration;
+ } else
+ av_log(s, AV_LOG_ERROR, "wav_write_packet: NOPTS\n");
+ return 0;
+}
+
+static int wav_write_trailer(AVFormatContext *s)
+{
+ ByteIOContext *pb = &s->pb;
+ WAVContext *wav = s->priv_data;
+ offset_t file_size;
+
+ if (!url_is_streamed(&s->pb)) {
+ end_tag(pb, wav->data);
+
+ /* update file size */
+ file_size = url_ftell(pb);
+ url_fseek(pb, 4, SEEK_SET);
+ put_le32(pb, (uint32_t)(file_size - 8));
+ url_fseek(pb, file_size, SEEK_SET);
+
+ put_flush_packet(pb);
+
+ if(s->streams[0]->codec->codec_tag != 0x01) {
+ /* Update num_samps in fact chunk */
+ int number_of_samples;
+ number_of_samples = av_rescale(wav->maxpts - wav->minpts + wav->last_duration,
+ s->streams[0]->codec->sample_rate * (int64_t)s->streams[0]->time_base.num,
+ s->streams[0]->time_base.den);
+ url_fseek(pb, wav->data-12, SEEK_SET);
+ put_le32(pb, number_of_samples);
+ url_fseek(pb, file_size, SEEK_SET);
+ put_flush_packet(pb);
+ }
+ }
+ return 0;
+}
+#endif //CONFIG_MUXERS
+
+/* return the size of the found tag */
+/* XXX: > 2GB ? */
+static int find_tag(ByteIOContext *pb, uint32_t tag1)
+{
+ unsigned int tag;
+ int size;
+
+ for(;;) {
+ if (url_feof(pb))
+ return -1;
+ tag = get_le32(pb);
+ size = get_le32(pb);
+ if (tag == tag1)
+ break;
+ url_fseek(pb, size, SEEK_CUR);
+ }
+ if (size < 0)
+ size = 0x7fffffff;
+ return size;
+}
+
+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')
+ return AVPROBE_SCORE_MAX;
+ else
+ return 0;
+}
+
+/* wav input */
+static int wav_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ int size;
+ unsigned int tag;
+ ByteIOContext *pb = &s->pb;
+ AVStream *st;
+ WAVContext *wav = s->priv_data;
+
+ /* check RIFF header */
+ tag = get_le32(pb);
+
+ if (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;
+
+ /* parse fmt header */
+ size = find_tag(pb, MKTAG('f', 'm', 't', ' '));
+ if (size < 0)
+ return -1;
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+
+ get_wav_header(pb, st->codec, size);
+ st->need_parsing = 1;
+
+ av_set_pts_info(st, 64, 1, st->codec->sample_rate);
+
+ size = find_tag(pb, MKTAG('d', 'a', 't', 'a'));
+ if (size < 0)
+ return -1;
+ wav->data_end= url_ftell(pb) + size;
+ return 0;
+}
+
+#define MAX_SIZE 4096
+
+static int wav_read_packet(AVFormatContext *s,
+ AVPacket *pkt)
+{
+ int ret, size, left;
+ AVStream *st;
+ WAVContext *wav = s->priv_data;
+
+ if (url_feof(&s->pb))
+ return AVERROR_IO;
+ st = s->streams[0];
+
+ left= wav->data_end - url_ftell(&s->pb);
+ if(left <= 0){
+ left = find_tag(&(s->pb), MKTAG('d', 'a', 't', 'a'));
+ if (left < 0) {
+ return AVERROR_IO;
+ }
+ 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_IO;
+ 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_close(AVFormatContext *s)
+{
+ return 0;
+}
+
+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);
+}
+
+#ifdef CONFIG_WAV_DEMUXER
+AVInputFormat wav_demuxer = {
+ "wav",
+ "wav format",
+ sizeof(WAVContext),
+ wav_probe,
+ wav_read_header,
+ wav_read_packet,
+ wav_read_close,
+ wav_read_seek,
+ .flags= AVFMT_GENERIC_INDEX,
+ .codec_tag= (const AVCodecTag*[]){codec_wav_tags, 0},
+};
+#endif
+#ifdef CONFIG_WAV_MUXER
+AVOutputFormat wav_muxer = {
+ "wav",
+ "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*[]){codec_wav_tags, 0},
+};
+#endif
diff --git a/contrib/ffmpeg/libavformat/wc3movie.c b/contrib/ffmpeg/libavformat/wc3movie.c
new file mode 100644
index 000000000..3e58a1bba
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/wc3movie.c
@@ -0,0 +1,394 @@
+/*
+ * Wing Commander III Movie (.mve) File Demuxer
+ * Copyright (c) 2003 The ffmpeg Project
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file wc3movie.c
+ * Wing Commander III Movie file demuxer
+ * by Mike Melanson (melanson@pcisys.net)
+ * for more information on the WC3 .mve file format, visit:
+ * http://www.pcisys.net/~melanson/codecs/
+ */
+
+#include "avformat.h"
+
+#define WC3_PREAMBLE_SIZE 8
+
+#define FORM_TAG MKTAG('F', 'O', 'R', 'M')
+#define MOVE_TAG MKTAG('M', 'O', 'V', 'E')
+#define _PC__TAG MKTAG('_', 'P', 'C', '_')
+#define SOND_TAG MKTAG('S', 'O', 'N', 'D')
+#define BNAM_TAG MKTAG('B', 'N', 'A', 'M')
+#define SIZE_TAG MKTAG('S', 'I', 'Z', 'E')
+#define PALT_TAG MKTAG('P', 'A', 'L', 'T')
+#define INDX_TAG MKTAG('I', 'N', 'D', 'X')
+#define BRCH_TAG MKTAG('B', 'R', 'C', 'H')
+#define SHOT_TAG MKTAG('S', 'H', 'O', 'T')
+#define VGA__TAG MKTAG('V', 'G', 'A', ' ')
+#define TEXT_TAG MKTAG('T', 'E', 'X', 'T')
+#define AUDI_TAG MKTAG('A', 'U', 'D', 'I')
+
+/* video resolution unless otherwise specified */
+#define WC3_DEFAULT_WIDTH 320
+#define WC3_DEFAULT_HEIGHT 165
+
+/* always use the same PCM audio parameters */
+#define WC3_SAMPLE_RATE 22050
+#define WC3_AUDIO_CHANNELS 1
+#define WC3_AUDIO_BITS 16
+
+/* nice, constant framerate */
+#define WC3_FRAME_PTS_INC (90000 / 15)
+
+#define PALETTE_SIZE (256 * 3)
+#define PALETTE_COUNT 256
+
+typedef struct Wc3DemuxContext {
+ int width;
+ int height;
+ unsigned char *palettes;
+ int palette_count;
+ int64_t pts;
+ int video_stream_index;
+ int audio_stream_index;
+
+ AVPaletteControl palette_control;
+
+} Wc3DemuxContext;
+
+/* bizarre palette lookup table */
+static const unsigned char wc3_pal_lookup[] = {
+ 0x00, 0x03, 0x05, 0x07, 0x09, 0x0B, 0x0D, 0x0E,
+ 0x10, 0x12, 0x13, 0x15, 0x16, 0x18, 0x19, 0x1A,
+ 0x1C, 0x1D, 0x1F, 0x20, 0x21, 0x23, 0x24, 0x25,
+ 0x27, 0x28, 0x29, 0x2A, 0x2C, 0x2D, 0x2E, 0x2F,
+ 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x38, 0x39,
+ 0x3A, 0x3B, 0x3C, 0x3D, 0x3F, 0x40, 0x41, 0x42,
+ 0x43, 0x44, 0x45, 0x46, 0x48, 0x49, 0x4A, 0x4B,
+ 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53,
+ 0x54, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C,
+ 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64,
+ 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C,
+ 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74,
+ 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C,
+ 0x7D, 0x7D, 0x7E, 0x7F, 0x80, 0x81, 0x82, 0x83,
+ 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B,
+ 0x8C, 0x8D, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92,
+ 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x99,
+ 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, 0xA0, 0xA1,
+ 0xA2, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8,
+ 0xA9, 0xAA, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
+ 0xB0, 0xB1, 0xB2, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6,
+ 0xB7, 0xB8, 0xB9, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD,
+ 0xBE, 0xBF, 0xBF, 0xC0, 0xC1, 0xC2, 0xC3, 0xC4,
+ 0xC5, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB,
+ 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD0, 0xD1,
+ 0xD2, 0xD3, 0xD4, 0xD5, 0xD5, 0xD6, 0xD7, 0xD8,
+ 0xD9, 0xDA, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
+ 0xDF, 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE4, 0xE5,
+ 0xE6, 0xE7, 0xE8, 0xE9, 0xE9, 0xEA, 0xEB, 0xEC,
+ 0xED, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF1, 0xF2,
+ 0xF3, 0xF4, 0xF5, 0xF6, 0xF6, 0xF7, 0xF8, 0xF9,
+ 0xFA, 0xFA, 0xFB, 0xFC, 0xFD, 0xFD, 0xFD, 0xFD
+};
+
+
+static int wc3_probe(AVProbeData *p)
+{
+ if (p->buf_size < 12)
+ return 0;
+
+ if ((AV_RL32(&p->buf[0]) != FORM_TAG) ||
+ (AV_RL32(&p->buf[8]) != MOVE_TAG))
+ return 0;
+
+ return AVPROBE_SCORE_MAX;
+}
+
+static int wc3_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ Wc3DemuxContext *wc3 = (Wc3DemuxContext *)s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ unsigned int fourcc_tag;
+ unsigned int size;
+ AVStream *st;
+ unsigned char preamble[WC3_PREAMBLE_SIZE];
+ int ret = 0;
+ int current_palette = 0;
+ int bytes_to_read;
+ int i;
+ unsigned char rotate;
+
+ /* default context members */
+ wc3->width = WC3_DEFAULT_WIDTH;
+ wc3->height = WC3_DEFAULT_HEIGHT;
+ wc3->palettes = NULL;
+ wc3->palette_count = 0;
+ wc3->pts = 0;
+ wc3->video_stream_index = wc3->audio_stream_index = 0;
+
+ /* skip the first 3 32-bit numbers */
+ url_fseek(pb, 12, SEEK_CUR);
+
+ /* traverse through the chunks and load the header information before
+ * the first BRCH tag */
+ if ((ret = get_buffer(pb, preamble, WC3_PREAMBLE_SIZE)) !=
+ WC3_PREAMBLE_SIZE)
+ return AVERROR_IO;
+ fourcc_tag = AV_RL32(&preamble[0]);
+ size = (AV_RB32(&preamble[4]) + 1) & (~1);
+
+ do {
+ switch (fourcc_tag) {
+
+ case SOND_TAG:
+ case INDX_TAG:
+ /* SOND unknown, INDX unnecessary; ignore both */
+ url_fseek(pb, size, SEEK_CUR);
+ break;
+
+ case _PC__TAG:
+ /* need the number of palettes */
+ url_fseek(pb, 8, SEEK_CUR);
+ if ((ret = get_buffer(pb, preamble, 4)) != 4)
+ return AVERROR_IO;
+ wc3->palette_count = AV_RL32(&preamble[0]);
+ if((unsigned)wc3->palette_count >= UINT_MAX / PALETTE_SIZE){
+ wc3->palette_count= 0;
+ return -1;
+ }
+ wc3->palettes = av_malloc(wc3->palette_count * PALETTE_SIZE);
+ break;
+
+ 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, s->title, bytes_to_read)) != bytes_to_read)
+ return AVERROR_IO;
+ break;
+
+ case SIZE_TAG:
+ /* video resolution override */
+ if ((ret = get_buffer(pb, preamble, WC3_PREAMBLE_SIZE)) !=
+ WC3_PREAMBLE_SIZE)
+ return AVERROR_IO;
+ wc3->width = AV_RL32(&preamble[0]);
+ wc3->height = AV_RL32(&preamble[4]);
+ break;
+
+ case PALT_TAG:
+ /* one of several palettes */
+ if ((unsigned)current_palette >= wc3->palette_count)
+ return AVERROR_INVALIDDATA;
+ if ((ret = get_buffer(pb,
+ &wc3->palettes[current_palette * PALETTE_SIZE],
+ PALETTE_SIZE)) != PALETTE_SIZE)
+ return AVERROR_IO;
+
+ /* transform the current palette in place */
+ for (i = current_palette * PALETTE_SIZE;
+ i < (current_palette + 1) * PALETTE_SIZE; i++) {
+ /* rotate each palette component left by 2 and use the result
+ * as an index into the color component table */
+ rotate = ((wc3->palettes[i] << 2) & 0xFF) |
+ ((wc3->palettes[i] >> 6) & 0xFF);
+ wc3->palettes[i] = wc3_pal_lookup[rotate];
+ }
+ current_palette++;
+ break;
+
+ default:
+ av_log(s, AV_LOG_ERROR, " unrecognized WC3 chunk: %c%c%c%c (0x%02X%02X%02X%02X)\n",
+ preamble[0], preamble[1], preamble[2], preamble[3],
+ preamble[0], preamble[1], preamble[2], preamble[3]);
+ return AVERROR_INVALIDDATA;
+ break;
+ }
+
+ if ((ret = get_buffer(pb, preamble, WC3_PREAMBLE_SIZE)) !=
+ WC3_PREAMBLE_SIZE)
+ return AVERROR_IO;
+ fourcc_tag = AV_RL32(&preamble[0]);
+ /* chunk sizes are 16-bit aligned */
+ size = (AV_RB32(&preamble[4]) + 1) & (~1);
+
+ } while (fourcc_tag != BRCH_TAG);
+
+ /* initialize the decoder streams */
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+ av_set_pts_info(st, 33, 1, 90000);
+ wc3->video_stream_index = st->index;
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ st->codec->codec_id = CODEC_ID_XAN_WC3;
+ st->codec->codec_tag = 0; /* no fourcc */
+ st->codec->width = wc3->width;
+ st->codec->height = wc3->height;
+
+ /* palette considerations */
+ st->codec->palctrl = &wc3->palette_control;
+
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+ av_set_pts_info(st, 33, 1, 90000);
+ wc3->audio_stream_index = st->index;
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_id = CODEC_ID_PCM_S16LE;
+ st->codec->codec_tag = 1;
+ st->codec->channels = WC3_AUDIO_CHANNELS;
+ st->codec->bits_per_sample = WC3_AUDIO_BITS;
+ st->codec->sample_rate = WC3_SAMPLE_RATE;
+ st->codec->bit_rate = st->codec->channels * st->codec->sample_rate *
+ st->codec->bits_per_sample;
+ st->codec->block_align = WC3_AUDIO_BITS * WC3_AUDIO_CHANNELS;
+
+ return 0;
+}
+
+static int wc3_read_packet(AVFormatContext *s,
+ AVPacket *pkt)
+{
+ Wc3DemuxContext *wc3 = (Wc3DemuxContext *)s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ unsigned int fourcc_tag;
+ unsigned int size;
+ int packet_read = 0;
+ int ret = 0;
+ unsigned char preamble[WC3_PREAMBLE_SIZE];
+ unsigned char text[1024];
+ unsigned int palette_number;
+ int i;
+ unsigned char r, g, b;
+ int base_palette_index;
+
+ while (!packet_read) {
+
+ /* get the next chunk preamble */
+ if ((ret = get_buffer(pb, preamble, WC3_PREAMBLE_SIZE)) !=
+ WC3_PREAMBLE_SIZE)
+ ret = AVERROR_IO;
+
+ fourcc_tag = AV_RL32(&preamble[0]);
+ /* chunk sizes are 16-bit aligned */
+ size = (AV_RB32(&preamble[4]) + 1) & (~1);
+
+ switch (fourcc_tag) {
+
+ case BRCH_TAG:
+ /* no-op */
+ break;
+
+ case SHOT_TAG:
+ /* load up new palette */
+ if ((ret = get_buffer(pb, preamble, 4)) != 4)
+ return AVERROR_IO;
+ palette_number = AV_RL32(&preamble[0]);
+ if (palette_number >= wc3->palette_count)
+ return AVERROR_INVALIDDATA;
+ base_palette_index = palette_number * PALETTE_COUNT * 3;
+ for (i = 0; i < PALETTE_COUNT; i++) {
+ r = wc3->palettes[base_palette_index + i * 3 + 0];
+ g = wc3->palettes[base_palette_index + i * 3 + 1];
+ b = wc3->palettes[base_palette_index + i * 3 + 2];
+ wc3->palette_control.palette[i] = (r << 16) | (g << 8) | (b);
+ }
+ wc3->palette_control.palette_changed = 1;
+ break;
+
+ case VGA__TAG:
+ /* send out video chunk */
+ ret= av_get_packet(pb, pkt, size);
+ pkt->stream_index = wc3->video_stream_index;
+ pkt->pts = wc3->pts;
+ if (ret != size)
+ ret = AVERROR_IO;
+ packet_read = 1;
+ break;
+
+ case TEXT_TAG:
+ /* subtitle chunk */
+#if 0
+ url_fseek(pb, size, SEEK_CUR);
+#else
+ if ((unsigned)size > sizeof(text) || (ret = get_buffer(pb, text, size)) != size)
+ ret = AVERROR_IO;
+ else {
+ int i = 0;
+ av_log (s, AV_LOG_DEBUG, "Subtitle time!\n");
+ av_log (s, AV_LOG_DEBUG, " inglish: %s\n", &text[i + 1]);
+ i += text[i] + 1;
+ av_log (s, AV_LOG_DEBUG, " doytsch: %s\n", &text[i + 1]);
+ i += text[i] + 1;
+ av_log (s, AV_LOG_DEBUG, " fronsay: %s\n", &text[i + 1]);
+ }
+#endif
+ break;
+
+ case AUDI_TAG:
+ /* send out audio chunk */
+ ret= av_get_packet(pb, pkt, size);
+ pkt->stream_index = wc3->audio_stream_index;
+ pkt->pts = wc3->pts;
+ if (ret != size)
+ ret = AVERROR_IO;
+
+ /* time to advance pts */
+ wc3->pts += WC3_FRAME_PTS_INC;
+
+ packet_read = 1;
+ break;
+
+ default:
+ av_log (s, AV_LOG_ERROR, " unrecognized WC3 chunk: %c%c%c%c (0x%02X%02X%02X%02X)\n",
+ preamble[0], preamble[1], preamble[2], preamble[3],
+ preamble[0], preamble[1], preamble[2], preamble[3]);
+ ret = AVERROR_INVALIDDATA;
+ packet_read = 1;
+ break;
+ }
+ }
+
+ return ret;
+}
+
+static int wc3_read_close(AVFormatContext *s)
+{
+ Wc3DemuxContext *wc3 = (Wc3DemuxContext *)s->priv_data;
+
+ av_free(wc3->palettes);
+
+ return 0;
+}
+
+AVInputFormat wc3_demuxer = {
+ "wc3movie",
+ "Wing Commander III movie format",
+ sizeof(Wc3DemuxContext),
+ wc3_probe,
+ wc3_read_header,
+ wc3_read_packet,
+ wc3_read_close,
+};
diff --git a/contrib/ffmpeg/libavformat/westwood.c b/contrib/ffmpeg/libavformat/westwood.c
new file mode 100644
index 000000000..bed2f0d14
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/westwood.c
@@ -0,0 +1,400 @@
+/*
+ * Westwood Studios Multimedia Formats Demuxer (VQA, AUD)
+ * Copyright (c) 2003 The ffmpeg Project
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file westwood.c
+ * Westwood Studios VQA & AUD file demuxers
+ * by Mike Melanson (melanson@pcisys.net)
+ * for more information on the Westwood file formats, visit:
+ * http://www.pcisys.net/~melanson/codecs/
+ * http://www.geocities.com/SiliconValley/8682/aud3.txt
+ *
+ * Implementation note: There is no definite file signature for AUD files.
+ * The demuxer uses a probabilistic strategy for content detection. This
+ * entails performing sanity checks on certain header values in order to
+ * qualify a file. Refer to wsaud_probe() for the precise parameters.
+ */
+
+#include "avformat.h"
+
+#define AUD_HEADER_SIZE 12
+#define AUD_CHUNK_PREAMBLE_SIZE 8
+#define AUD_CHUNK_SIGNATURE 0x0000DEAF
+
+#define FORM_TAG MKBETAG('F', 'O', 'R', 'M')
+#define WVQA_TAG MKBETAG('W', 'V', 'Q', 'A')
+#define VQHD_TAG MKBETAG('V', 'Q', 'H', 'D')
+#define FINF_TAG MKBETAG('F', 'I', 'N', 'F')
+#define SND0_TAG MKBETAG('S', 'N', 'D', '0')
+#define SND1_TAG MKBETAG('S', 'N', 'D', '1')
+#define SND2_TAG MKBETAG('S', 'N', 'D', '2')
+#define VQFR_TAG MKBETAG('V', 'Q', 'F', 'R')
+
+/* don't know what these tags are for, but acknowledge their existence */
+#define CINF_TAG MKBETAG('C', 'I', 'N', 'F')
+#define CINH_TAG MKBETAG('C', 'I', 'N', 'H')
+#define CIND_TAG MKBETAG('C', 'I', 'N', 'D')
+#define PINF_TAG MKBETAG('P', 'I', 'N', 'F')
+#define PINH_TAG MKBETAG('P', 'I', 'N', 'H')
+#define PIND_TAG MKBETAG('P', 'I', 'N', 'D')
+#define CMDS_TAG MKBETAG('C', 'M', 'D', 'S')
+
+#define VQA_HEADER_SIZE 0x2A
+#define VQA_FRAMERATE 15
+#define VQA_VIDEO_PTS_INC (90000 / VQA_FRAMERATE)
+#define VQA_PREAMBLE_SIZE 8
+
+typedef struct WsAudDemuxContext {
+ int audio_samplerate;
+ int audio_channels;
+ int audio_bits;
+ int audio_type;
+ int audio_stream_index;
+ int64_t audio_frame_counter;
+} WsAudDemuxContext;
+
+typedef struct WsVqaDemuxContext {
+ int audio_samplerate;
+ int audio_channels;
+ int audio_bits;
+
+ int audio_stream_index;
+ int video_stream_index;
+
+ int64_t audio_frame_counter;
+ int64_t video_pts;
+} WsVqaDemuxContext;
+
+static int wsaud_probe(AVProbeData *p)
+{
+ int field;
+
+ /* Probabilistic content detection strategy: There is no file signature
+ * so perform sanity checks on various header parameters:
+ * 8000 <= sample rate (16 bits) <= 48000 ==> 40001 acceptable numbers
+ * compression type (8 bits) = 1 or 99 ==> 2 acceptable numbers
+ * There is a total of 24 bits. The number space contains 2^24 =
+ * 16777216 numbers. There are 40001 * 2 = 80002 acceptable combinations
+ * of numbers. There is a 80002/16777216 = 0.48% chance of a false
+ * positive.
+ */
+
+ if (p->buf_size < AUD_HEADER_SIZE)
+ return 0;
+
+ /* check sample rate */
+ field = AV_RL16(&p->buf[0]);
+ if ((field < 8000) || (field > 48000))
+ return 0;
+
+ /* note: only check for WS IMA (type 99) right now since there is no
+ * support for type 1 */
+ if (p->buf[11] != 99)
+ return 0;
+
+ /* return 1/2 certainty since this file check is a little sketchy */
+ return AVPROBE_SCORE_MAX / 2;
+}
+
+static int wsaud_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ WsAudDemuxContext *wsaud = (WsAudDemuxContext *)s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ AVStream *st;
+ unsigned char header[AUD_HEADER_SIZE];
+
+ if (get_buffer(pb, header, AUD_HEADER_SIZE) != AUD_HEADER_SIZE)
+ return AVERROR_IO;
+ wsaud->audio_samplerate = AV_RL16(&header[0]);
+ if (header[11] == 99)
+ wsaud->audio_type = CODEC_ID_ADPCM_IMA_WS;
+ else
+ return AVERROR_INVALIDDATA;
+
+ /* flag 0 indicates stereo */
+ wsaud->audio_channels = (header[10] & 0x1) + 1;
+ /* flag 1 indicates 16 bit audio */
+ wsaud->audio_bits = (((header[10] & 0x2) >> 1) + 1) * 8;
+
+ /* initialize the audio decoder stream */
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+ av_set_pts_info(st, 33, 1, wsaud->audio_samplerate);
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_id = wsaud->audio_type;
+ st->codec->codec_tag = 0; /* no tag */
+ st->codec->channels = wsaud->audio_channels;
+ st->codec->sample_rate = wsaud->audio_samplerate;
+ st->codec->bits_per_sample = wsaud->audio_bits;
+ st->codec->bit_rate = st->codec->channels * st->codec->sample_rate *
+ st->codec->bits_per_sample / 4;
+ st->codec->block_align = st->codec->channels * st->codec->bits_per_sample;
+
+ wsaud->audio_stream_index = st->index;
+ wsaud->audio_frame_counter = 0;
+
+ return 0;
+}
+
+static int wsaud_read_packet(AVFormatContext *s,
+ AVPacket *pkt)
+{
+ WsAudDemuxContext *wsaud = (WsAudDemuxContext *)s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ unsigned char preamble[AUD_CHUNK_PREAMBLE_SIZE];
+ unsigned int chunk_size;
+ int ret = 0;
+
+ if (get_buffer(pb, preamble, AUD_CHUNK_PREAMBLE_SIZE) !=
+ AUD_CHUNK_PREAMBLE_SIZE)
+ return AVERROR_IO;
+
+ /* validate the chunk */
+ if (AV_RL32(&preamble[4]) != AUD_CHUNK_SIGNATURE)
+ return AVERROR_INVALIDDATA;
+
+ chunk_size = AV_RL16(&preamble[0]);
+ ret= av_get_packet(pb, pkt, chunk_size);
+ if (ret != chunk_size)
+ return AVERROR_IO;
+ pkt->stream_index = wsaud->audio_stream_index;
+ pkt->pts = wsaud->audio_frame_counter;
+ pkt->pts /= wsaud->audio_samplerate;
+
+ /* 2 samples/byte, 1 or 2 samples per frame depending on stereo */
+ wsaud->audio_frame_counter += (chunk_size * 2) / wsaud->audio_channels;
+
+ return ret;
+}
+
+static int wsaud_read_close(AVFormatContext *s)
+{
+// WsAudDemuxContext *wsaud = (WsAudDemuxContext *)s->priv_data;
+
+ return 0;
+}
+
+
+static int wsvqa_probe(AVProbeData *p)
+{
+ /* need 12 bytes to qualify */
+ if (p->buf_size < 12)
+ return 0;
+
+ /* check for the VQA signatures */
+ if ((AV_RB32(&p->buf[0]) != FORM_TAG) ||
+ (AV_RB32(&p->buf[8]) != WVQA_TAG))
+ return 0;
+
+ return AVPROBE_SCORE_MAX;
+}
+
+static int wsvqa_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ WsVqaDemuxContext *wsvqa = (WsVqaDemuxContext *)s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ AVStream *st;
+ unsigned char *header;
+ unsigned char scratch[VQA_PREAMBLE_SIZE];
+ unsigned int chunk_tag;
+ unsigned int chunk_size;
+
+ /* initialize the video decoder stream */
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+ 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_id = CODEC_ID_WS_VQA;
+ st->codec->codec_tag = 0; /* no fourcc */
+
+ /* skip to the start of the VQA header */
+ url_fseek(pb, 20, SEEK_SET);
+
+ /* the VQA header needs to go to the decoder */
+ st->codec->extradata_size = VQA_HEADER_SIZE;
+ st->codec->extradata = av_mallocz(VQA_HEADER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
+ header = (unsigned char *)st->codec->extradata;
+ if (get_buffer(pb, st->codec->extradata, VQA_HEADER_SIZE) !=
+ VQA_HEADER_SIZE) {
+ av_free(st->codec->extradata);
+ return AVERROR_IO;
+ }
+ st->codec->width = AV_RL16(&header[6]);
+ st->codec->height = AV_RL16(&header[8]);
+
+ /* initialize the audio decoder stream for VQA v1 or nonzero samplerate */
+ if (AV_RL16(&header[24]) || (AV_RL16(&header[0]) == 1 && AV_RL16(&header[2]) == 1)) {
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+ av_set_pts_info(st, 33, 1, VQA_FRAMERATE);
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ if (AV_RL16(&header[0]) == 1)
+ st->codec->codec_id = CODEC_ID_WESTWOOD_SND1;
+ else
+ st->codec->codec_id = CODEC_ID_ADPCM_IMA_WS;
+ st->codec->codec_tag = 0; /* no tag */
+ st->codec->sample_rate = AV_RL16(&header[24]);
+ if (!st->codec->sample_rate)
+ st->codec->sample_rate = 22050;
+ st->codec->channels = header[26];
+ if (!st->codec->channels)
+ st->codec->channels = 1;
+ st->codec->bits_per_sample = 16;
+ st->codec->bit_rate = st->codec->channels * st->codec->sample_rate *
+ st->codec->bits_per_sample / 4;
+ st->codec->block_align = st->codec->channels * st->codec->bits_per_sample;
+
+ wsvqa->audio_stream_index = st->index;
+ wsvqa->audio_samplerate = st->codec->sample_rate;
+ wsvqa->audio_channels = st->codec->channels;
+ wsvqa->audio_frame_counter = 0;
+ }
+
+ /* there are 0 or more chunks before the FINF chunk; iterate until
+ * FINF has been skipped and the file will be ready to be demuxed */
+ do {
+ if (get_buffer(pb, scratch, VQA_PREAMBLE_SIZE) != VQA_PREAMBLE_SIZE) {
+ av_free(st->codec->extradata);
+ return AVERROR_IO;
+ }
+ chunk_tag = AV_RB32(&scratch[0]);
+ chunk_size = AV_RB32(&scratch[4]);
+
+ /* catch any unknown header tags, for curiousity */
+ switch (chunk_tag) {
+ case CINF_TAG:
+ case CINH_TAG:
+ case CIND_TAG:
+ case PINF_TAG:
+ case PINH_TAG:
+ case PIND_TAG:
+ case FINF_TAG:
+ case CMDS_TAG:
+ break;
+
+ default:
+ av_log (s, AV_LOG_ERROR, " note: unknown chunk seen (%c%c%c%c)\n",
+ scratch[0], scratch[1],
+ scratch[2], scratch[3]);
+ break;
+ }
+
+ url_fseek(pb, chunk_size, SEEK_CUR);
+ } while (chunk_tag != FINF_TAG);
+
+ wsvqa->video_pts = wsvqa->audio_frame_counter = 0;
+
+ return 0;
+}
+
+static int wsvqa_read_packet(AVFormatContext *s,
+ AVPacket *pkt)
+{
+ WsVqaDemuxContext *wsvqa = (WsVqaDemuxContext *)s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ int ret = -1;
+ unsigned char preamble[VQA_PREAMBLE_SIZE];
+ unsigned int chunk_type;
+ unsigned int chunk_size;
+ int skip_byte;
+
+ while (get_buffer(pb, preamble, VQA_PREAMBLE_SIZE) == VQA_PREAMBLE_SIZE) {
+ chunk_type = AV_RB32(&preamble[0]);
+ chunk_size = AV_RB32(&preamble[4]);
+ skip_byte = chunk_size & 0x01;
+
+ if ((chunk_type == SND1_TAG) || (chunk_type == SND2_TAG) || (chunk_type == VQFR_TAG)) {
+
+ if (av_new_packet(pkt, chunk_size))
+ return AVERROR_IO;
+ ret = get_buffer(pb, pkt->data, chunk_size);
+ if (ret != chunk_size) {
+ av_free_packet(pkt);
+ return AVERROR_IO;
+ }
+
+ if (chunk_type == SND2_TAG) {
+ pkt->stream_index = wsvqa->audio_stream_index;
+ /* 2 samples/byte, 1 or 2 samples per frame depending on stereo */
+ wsvqa->audio_frame_counter += (chunk_size * 2) / wsvqa->audio_channels;
+ } else if(chunk_type == SND1_TAG) {
+ pkt->stream_index = wsvqa->audio_stream_index;
+ /* unpacked size is stored in header */
+ wsvqa->audio_frame_counter += AV_RL16(pkt->data) / wsvqa->audio_channels;
+ } else {
+ pkt->stream_index = wsvqa->video_stream_index;
+ wsvqa->video_pts += VQA_VIDEO_PTS_INC;
+ }
+ /* stay on 16-bit alignment */
+ if (skip_byte)
+ url_fseek(pb, 1, SEEK_CUR);
+
+ return ret;
+ } else {
+ switch(chunk_type){
+ case CMDS_TAG:
+ case SND0_TAG:
+ break;
+ default:
+ av_log(s, AV_LOG_INFO, "Skipping unknown chunk 0x%08X\n", chunk_type);
+ }
+ url_fseek(pb, chunk_size + skip_byte, SEEK_CUR);
+ }
+ }
+
+ return ret;
+}
+
+static int wsvqa_read_close(AVFormatContext *s)
+{
+// WsVqaDemuxContext *wsvqa = (WsVqaDemuxContext *)s->priv_data;
+
+ return 0;
+}
+
+#ifdef CONFIG_WSAUD_DEMUXER
+AVInputFormat wsaud_demuxer = {
+ "wsaud",
+ "Westwood Studios audio format",
+ sizeof(WsAudDemuxContext),
+ wsaud_probe,
+ wsaud_read_header,
+ wsaud_read_packet,
+ wsaud_read_close,
+};
+#endif
+#ifdef CONFIG_WSVQA_DEMUXER
+AVInputFormat wsvqa_demuxer = {
+ "wsvqa",
+ "Westwood Studios VQA format",
+ sizeof(WsVqaDemuxContext),
+ wsvqa_probe,
+ wsvqa_read_header,
+ wsvqa_read_packet,
+ wsvqa_read_close,
+};
+#endif
diff --git a/contrib/ffmpeg/libavformat/wv.c b/contrib/ffmpeg/libavformat/wv.c
new file mode 100644
index 000000000..ed1eefeea
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/wv.c
@@ -0,0 +1,241 @@
+/*
+ * WavPack demuxer
+ * Copyright (c) 2006 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 "avformat.h"
+#include "allformats.h"
+#include "bswap.h"
+
+// specs say that maximum block size is 1Mb
+#define WV_BLOCK_LIMIT 1047576
+
+#define WV_EXTRA_SIZE 12
+
+enum WV_FLAGS{
+ WV_MONO = 0x0004,
+ WV_HYBRID = 0x0008,
+ WV_JOINT = 0x0010,
+ WV_CROSSD = 0x0020,
+ WV_HSHAPE = 0x0040,
+ WV_FLOAT = 0x0080,
+ WV_INT32 = 0x0100,
+ WV_HBR = 0x0200,
+ WV_HBAL = 0x0400,
+ WV_MCINIT = 0x0800,
+ WV_MCEND = 0x1000,
+};
+
+static const int wv_rates[16] = {
+ 6000, 8000, 9600, 11025, 12000, 16000, 22050, 24000,
+ 32000, 44100, 48000, 64000, 88200, 96000, 192000, -1
+};
+
+typedef struct{
+ uint32_t blksize, flags;
+ int rate, chan, bpp;
+ uint32_t samples, soff;
+ int block_parsed;
+ uint8_t extra[WV_EXTRA_SIZE];
+ int64_t pos;
+}WVContext;
+
+static int wv_probe(AVProbeData *p)
+{
+ /* check file header */
+ if (p->buf_size <= 32)
+ return 0;
+ if (p->buf[0] == 'w' && p->buf[1] == 'v' &&
+ p->buf[2] == 'p' && p->buf[3] == 'k')
+ return AVPROBE_SCORE_MAX;
+ else
+ return 0;
+}
+
+static int wv_read_block_header(AVFormatContext *ctx, ByteIOContext *pb)
+{
+ WVContext *wc = ctx->priv_data;
+ uint32_t tag, ver;
+ int size;
+ int rate, bpp, chan;
+
+ wc->pos = url_ftell(pb);
+ tag = get_le32(pb);
+ if (tag != MKTAG('w', 'v', 'p', 'k'))
+ return -1;
+ size = get_le32(pb);
+ if(size < 24 || size > WV_BLOCK_LIMIT){
+ av_log(ctx, AV_LOG_ERROR, "Incorrect block size %i\n", size);
+ return -1;
+ }
+ wc->blksize = size;
+ ver = get_le16(pb);
+ if(ver < 0x402 || ver > 0x40F){
+ av_log(ctx, AV_LOG_ERROR, "Unsupported version %03X\n", ver);
+ return -1;
+ }
+ get_byte(pb); // track no
+ get_byte(pb); // track sub index
+ wc->samples = get_le32(pb); // total samples in file
+ wc->soff = get_le32(pb); // offset in samples of current block
+ get_buffer(pb, wc->extra, WV_EXTRA_SIZE);
+ wc->flags = AV_RL32(wc->extra + 4);
+ //parse flags
+ if(wc->flags & WV_FLOAT){
+ av_log(ctx, AV_LOG_ERROR, "Floating point data is not supported\n");
+ return -1;
+ }
+ if(wc->flags & WV_HYBRID){
+ av_log(ctx, AV_LOG_ERROR, "Hybrid coding mode is not supported\n");
+ return -1;
+ }
+ if(wc->flags & WV_INT32){
+ av_log(ctx, AV_LOG_ERROR, "Integer point data is not supported\n");
+ return -1;
+ }
+
+ 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(!wc->bpp) wc->bpp = bpp;
+ if(!wc->chan) wc->chan = chan;
+ if(!wc->rate) wc->rate = rate;
+
+ if(wc->flags && bpp != wc->bpp){
+ av_log(ctx, AV_LOG_ERROR, "Bits per sample differ, this block: %i, header block: %i\n", bpp, wc->bpp);
+ return -1;
+ }
+ if(wc->flags && chan != wc->chan){
+ 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){
+ av_log(ctx, AV_LOG_ERROR, "Sampling rate differ, this block: %i, header block: %i\n", rate, wc->rate);
+ return -1;
+ }
+ wc->blksize = size - 24;
+ return 0;
+}
+
+static int wv_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ ByteIOContext *pb = &s->pb;
+ WVContext *wc = s->priv_data;
+ AVStream *st;
+
+ 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_id = CODEC_ID_WAVPACK;
+ st->codec->channels = wc->chan;
+ st->codec->sample_rate = wc->rate;
+ st->codec->bits_per_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;
+ return 0;
+}
+
+static int wv_read_packet(AVFormatContext *s,
+ AVPacket *pkt)
+{
+ WVContext *wc = s->priv_data;
+ int ret;
+
+ if (url_feof(&s->pb))
+ return AVERROR(EIO);
+ if(wc->block_parsed){
+ if(wv_read_block_header(s, &s->pb) < 0)
+ return -1;
+ }
+
+ if(av_new_packet(pkt, wc->blksize + WV_EXTRA_SIZE) < 0)
+ return AVERROR_NOMEM;
+ memcpy(pkt->data, wc->extra, WV_EXTRA_SIZE);
+ ret = get_buffer(&s->pb, pkt->data + WV_EXTRA_SIZE, wc->blksize);
+ if(ret != wc->blksize){
+ av_free_packet(pkt);
+ return AVERROR_IO;
+ }
+ pkt->stream_index = 0;
+ wc->block_parsed = 1;
+ pkt->size = ret + WV_EXTRA_SIZE;
+ pkt->pts = wc->soff;
+ av_add_index_entry(s->streams[0], wc->pos, pkt->pts, 0, 0, AVINDEX_KEYFRAME);
+ return 0;
+}
+
+static int wv_read_close(AVFormatContext *s)
+{
+ return 0;
+}
+
+static int wv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
+{
+ AVStream *st = s->streams[stream_index];
+ WVContext *wc = s->priv_data;
+ AVPacket pkt1, *pkt = &pkt1;
+ int ret;
+ int index = av_index_search_timestamp(st, timestamp, flags);
+ int64_t pos, pts;
+
+ /* if found, seek there */
+ if (index >= 0){
+ wc->block_parsed = 1;
+ url_fseek(&s->pb, st->index_entries[index].pos, SEEK_SET);
+ return 0;
+ }
+ /* if timestamp is out of bounds, return error */
+ if(timestamp < 0 || timestamp >= s->duration)
+ return -1;
+
+ pos = url_ftell(&s->pb);
+ do{
+ ret = av_read_frame(s, pkt);
+ if (ret < 0){
+ url_fseek(&s->pb, pos, SEEK_SET);
+ return -1;
+ }
+ pts = pkt->pts;
+ av_free_packet(pkt);
+ }while(pts < timestamp);
+ return 0;
+}
+
+AVInputFormat wv_demuxer = {
+ "wv",
+ "WavPack",
+ sizeof(WVContext),
+ wv_probe,
+ wv_read_header,
+ wv_read_packet,
+ wv_read_close,
+ wv_read_seek,
+};
diff --git a/contrib/ffmpeg/libavformat/x11grab.c b/contrib/ffmpeg/libavformat/x11grab.c
new file mode 100644
index 000000000..8916d799a
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/x11grab.c
@@ -0,0 +1,529 @@
+/*
+ * X11 video grab interface
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg integration:
+ * Copyright (C) 2006 Clemens Fruhwirth <clemens@endorphin.org>
+ * Edouard Gomez <ed.gomez@free.fr>
+ *
+ * This file contains code from grab.c:
+ * Copyright (c) 2000-2001 Fabrice Bellard
+ *
+ * This file contains code from the xvidcap project:
+ * Copyright (C) 1997-1998 Rasca, Berlin
+ * 2003-2004 Karl H. Beckers, Frankfurt
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/**
+ * @file x11grab.c
+ * X11 frame device demuxer by Clemens Fruhwirth <clemens@endorphin.org>
+ * and Edouard Gomez <ed.gomez@free.fr>.
+ */
+
+#include "avformat.h"
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/time.h>
+#define _LINUX_TIME_H 1
+#include <time.h>
+#include <X11/X.h>
+#include <X11/Xlib.h>
+#include <X11/Xlibint.h>
+#include <X11/Xproto.h>
+#include <X11/Xutil.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <X11/extensions/XShm.h>
+
+/**
+ * X11 Device Demuxer context
+ */
+typedef struct x11_grab_s
+{
+ int frame_size; /**< Size in bytes of a grabbed frame */
+ AVRational time_base; /**< Time base */
+ int64_t time_frame; /**< Current time */
+
+ int height; /**< Height of the grab frame */
+ int width; /**< Width of the grab frame */
+ int x_off; /**< Horizontal top-left corner coordinate */
+ int y_off; /**< Vertical top-left corner coordinate */
+
+ Display *dpy; /**< X11 display from which x11grab grabs frames */
+ XImage *image; /**< X11 image holding the grab */
+ int use_shm; /**< !0 when using XShm extension */
+ XShmSegmentInfo shminfo; /**< When using XShm, keeps track of XShm infos */
+ int mouse_warning_shown;
+} x11_grab_t;
+
+/**
+ * Initializes the x11 grab device demuxer (public device demuxer API).
+ *
+ * @param s1 Context from avformat core
+ * @param ap Parameters from avformat core
+ * @return <ul>
+ * <li>ENOMEM no memory left</li>
+ * <li>AVERROR_IO other failure case</li>
+ * <li>0 success</li>
+ * </ul>
+ */
+static int
+x11grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
+{
+ x11_grab_t *x11grab = s1->priv_data;
+ Display *dpy;
+ AVStream *st = NULL;
+ int input_pixfmt;
+ XImage *image;
+ int x_off = 0;
+ int y_off = 0;
+ int use_shm;
+ char *param, *offset;
+
+ param = av_strdup(s1->filename);
+ offset = strchr(param, '+');
+ if (offset) {
+ sscanf(offset, "%d,%d", &x_off, &y_off);
+ *offset= 0;
+ }
+
+ av_log(s1, AV_LOG_INFO, "device: %s -> display: %s x: %d y: %d width: %d height: %d\n", s1->filename, param, x_off, y_off, ap->width, ap->height);
+
+ dpy = XOpenDisplay(param);
+ if(!dpy) {
+ av_log(s1, AV_LOG_ERROR, "Could not open X display.\n");
+ return AVERROR_IO;
+ }
+
+ if (!ap || ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) {
+ av_log(s1, AV_LOG_ERROR, "AVParameters don't have any video size. Use -s.\n");
+ return AVERROR_IO;
+ }
+
+ st = av_new_stream(s1, 0);
+ if (!st) {
+ return AVERROR(ENOMEM);
+ }
+ av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
+
+ use_shm = XShmQueryExtension(dpy);
+ av_log(s1, AV_LOG_INFO, "shared memory extension %s found\n", use_shm ? "" : "not");
+
+ if(use_shm) {
+ int scr = XDefaultScreen(dpy);
+ image = XShmCreateImage(dpy,
+ DefaultVisual(dpy, scr),
+ DefaultDepth(dpy, scr),
+ ZPixmap,
+ NULL,
+ &x11grab->shminfo,
+ ap->width, ap->height);
+ x11grab->shminfo.shmid = shmget(IPC_PRIVATE,
+ image->bytes_per_line * image->height,
+ IPC_CREAT|0777);
+ if (x11grab->shminfo.shmid == -1) {
+ av_log(s1, AV_LOG_ERROR, "Fatal: Can't get shared memory!\n");
+ return AVERROR(ENOMEM);
+ }
+ x11grab->shminfo.shmaddr = image->data = shmat(x11grab->shminfo.shmid, 0, 0);
+ x11grab->shminfo.readOnly = False;
+
+ if (!XShmAttach(dpy, &x11grab->shminfo)) {
+ av_log(s1, AV_LOG_ERROR, "Fatal: Failed to attach shared memory!\n");
+ /* needs some better error subroutine :) */
+ return AVERROR_IO;
+ }
+ } else {
+ image = XGetImage(dpy, RootWindow(dpy, DefaultScreen(dpy)),
+ x_off,y_off,
+ ap->width,ap->height,
+ AllPlanes, ZPixmap);
+ }
+
+ switch (image->bits_per_pixel) {
+ case 8:
+ av_log (s1, AV_LOG_DEBUG, "8 bit palette\n");
+ input_pixfmt = PIX_FMT_PAL8;
+ break;
+ case 16:
+ if ( image->red_mask == 0xf800 &&
+ image->green_mask == 0x07e0 &&
+ image->blue_mask == 0x001f ) {
+ av_log (s1, AV_LOG_DEBUG, "16 bit RGB565\n");
+ input_pixfmt = PIX_FMT_RGB565;
+ } else if (image->red_mask == 0x7c00 &&
+ image->green_mask == 0x03e0 &&
+ image->blue_mask == 0x001f ) {
+ av_log(s1, AV_LOG_DEBUG, "16 bit RGB555\n");
+ input_pixfmt = PIX_FMT_RGB555;
+ } else {
+ av_log(s1, AV_LOG_ERROR, "RGB ordering at image depth %i not supported ... aborting\n", image->bits_per_pixel);
+ av_log(s1, AV_LOG_ERROR, "color masks: r 0x%.6lx g 0x%.6lx b 0x%.6lx\n", image->red_mask, image->green_mask, image->blue_mask);
+ return AVERROR_IO;
+ }
+ break;
+ case 24:
+ if ( image->red_mask == 0xff0000 &&
+ image->green_mask == 0x00ff00 &&
+ image->blue_mask == 0x0000ff ) {
+ input_pixfmt = PIX_FMT_BGR24;
+ } else if ( image->red_mask == 0x0000ff &&
+ image->green_mask == 0x00ff00 &&
+ image->blue_mask == 0xff0000 ) {
+ input_pixfmt = PIX_FMT_RGB24;
+ } else {
+ av_log(s1, AV_LOG_ERROR,"rgb ordering at image depth %i not supported ... aborting\n", image->bits_per_pixel);
+ av_log(s1, AV_LOG_ERROR, "color masks: r 0x%.6lx g 0x%.6lx b 0x%.6lx\n", image->red_mask, image->green_mask, image->blue_mask);
+ return AVERROR_IO;
+ }
+ break;
+ case 32:
+#if 0
+ GetColorInfo (image, &c_info);
+ if ( c_info.alpha_mask == 0xff000000 && image->green_mask == 0x0000ff00) {
+ /* byte order is relevant here, not endianness
+ * endianness is handled by avcodec, but atm no such thing
+ * as having ABGR, instead of ARGB in a word. Since we
+ * need this for Solaris/SPARC, but need to do the conversion
+ * for every frame we do it outside of this loop, cf. below
+ * this matches both ARGB32 and ABGR32 */
+ input_pixfmt = PIX_FMT_ARGB32;
+ } else {
+ av_log(s1, AV_LOG_ERROR,"image depth %i not supported ... aborting\n", image->bits_per_pixel);
+ return AVERROR_IO;
+ }
+#endif
+ input_pixfmt = PIX_FMT_RGB32;
+ break;
+ default:
+ av_log(s1, AV_LOG_ERROR, "image depth %i not supported ... aborting\n", image->bits_per_pixel);
+ return -1;
+ }
+
+ x11grab->frame_size = ap->width * ap->height * image->bits_per_pixel/8;
+ x11grab->dpy = dpy;
+ x11grab->width = ap->width;
+ x11grab->height = ap->height;
+ x11grab->time_base = ap->time_base;
+ x11grab->time_frame = av_gettime() / av_q2d(ap->time_base);
+ x11grab->x_off = x_off;
+ x11grab->y_off = y_off;
+ x11grab->image = image;
+ x11grab->use_shm = use_shm;
+ x11grab->mouse_warning_shown = 0;
+
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ st->codec->codec_id = CODEC_ID_RAWVIDEO;
+ st->codec->width = ap->width;
+ st->codec->height = ap->height;
+ st->codec->pix_fmt = input_pixfmt;
+ st->codec->time_base = ap->time_base;
+ st->codec->bit_rate = x11grab->frame_size * 1/av_q2d(ap->time_base) * 8;
+
+ return 0;
+}
+
+/**
+ * Get pointer coordinates from X11.
+ *
+ * @param x Integer where horizontal coordinate will be returned
+ * @param y Integer where vertical coordinate will be returned
+ * @param dpy X11 display from where pointer coordinates are retrieved
+ * @param s1 Context used for logging errors if necessary
+ */
+static void
+get_pointer_coordinates(int *x, int *y, Display *dpy, AVFormatContext *s1)
+{
+ Window mrootwindow, childwindow;
+ int dummy;
+
+ mrootwindow = DefaultRootWindow(dpy);
+
+ if (XQueryPointer(dpy, mrootwindow, &mrootwindow, &childwindow,
+ x, y, &dummy, &dummy, (unsigned int*)&dummy)) {
+ } else {
+ x11_grab_t *s = s1->priv_data;
+ if (!s->mouse_warning_shown) {
+ av_log(s1, AV_LOG_INFO, "couldn't find mouse pointer\n");
+ s->mouse_warning_shown = 1;
+ }
+ *x = -1;
+ *y = -1;
+ }
+}
+
+/**
+ * Mouse painting helper function that applies an 'and' and 'or' mask pair to
+ * '*dst' pixel. It actually draws a mouse pointer pixel to grabbed frame.
+ *
+ * @param dst Destination pixel
+ * @param and Part of the mask that must be applied using a bitwise 'and'
+ * operator
+ * @param or Part of the mask that must be applied using a bitwise 'or'
+ * operator
+ * @param bits_per_pixel Bits per pixel used in the grabbed image
+ */
+static void inline
+apply_masks(uint8_t *dst, int and, int or, int bits_per_pixel)
+{
+ switch (bits_per_pixel) {
+ case 32:
+ *(uint32_t*)dst = (*(uint32_t*)dst & and) | or;
+ break;
+ case 16:
+ *(uint16_t*)dst = (*(uint16_t*)dst & and) | or;
+ break;
+ case 8:
+ *dst = !!or;
+ break;
+ }
+}
+
+/**
+ * Paints a mouse pointer in an X11 image.
+ *
+ * @param image Image where to paint the mouse pointer
+ * @param s context used to retrieve original grabbing rectangle
+ * coordinates
+ * @param x Mouse pointer coordinate
+ * @param y Mouse pointer coordinate
+ */
+static void
+paint_mouse_pointer(XImage *image, x11_grab_t *s, int x, int y)
+{
+ /* 16x20x1bpp bitmap for the black channel of the mouse pointer */
+ static const uint16_t const mousePointerBlack[] =
+ {
+ 0x0000, 0x0003, 0x0005, 0x0009, 0x0011,
+ 0x0021, 0x0041, 0x0081, 0x0101, 0x0201,
+ 0x03c1, 0x0049, 0x0095, 0x0093, 0x0120,
+ 0x0120, 0x0240, 0x0240, 0x0380, 0x0000
+ };
+
+ /* 16x20x1bpp bitmap for the white channel of the mouse pointer */
+ static const uint16_t const mousePointerWhite[] =
+ {
+ 0x0000, 0x0000, 0x0002, 0x0006, 0x000e,
+ 0x001e, 0x003e, 0x007e, 0x00fe, 0x01fe,
+ 0x003e, 0x0036, 0x0062, 0x0060, 0x00c0,
+ 0x00c0, 0x0180, 0x0180, 0x0000, 0x0000
+ };
+
+ int x_off = s->x_off;
+ int y_off = s->y_off;
+ int width = s->width;
+ int height = s->height;
+
+ if ( x - x_off >= 0 && x < width + x_off
+ && y - y_off >= 0 && y < height + y_off) {
+ uint8_t *im_data = (uint8_t*)image->data;
+ int bytes_per_pixel;
+ int line;
+ int masks;
+
+ /* Select correct masks and pixel size */
+ if (image->bits_per_pixel == 8) {
+ masks = 1;
+ } else {
+ masks = (image->red_mask|image->green_mask|image->blue_mask);
+ }
+ bytes_per_pixel = image->bits_per_pixel>>3;
+
+ /* Shift to right line */
+ im_data += image->bytes_per_line * (y - y_off);
+ /* Shift to right pixel in the line */
+ im_data += bytes_per_pixel * (x - x_off);
+
+ /* Draw the cursor - proper loop */
+ for (line = 0; line < FFMIN(20, (y_off + height) - y); line++) {
+ uint8_t *cursor = im_data;
+ int column;
+ uint16_t bm_b;
+ uint16_t bm_w;
+
+ bm_b = mousePointerBlack[line];
+ bm_w = mousePointerWhite[line];
+
+ for (column = 0; column < FFMIN(16, (x_off + width) - x); column++) {
+ apply_masks(cursor, ~(masks*(bm_b&1)), masks*(bm_w&1),
+ image->bits_per_pixel);
+ cursor += bytes_per_pixel;
+ bm_b >>= 1;
+ bm_w >>= 1;
+ }
+ im_data += image->bytes_per_line;
+ }
+ }
+}
+
+
+/**
+ * Reads new data in the image structure.
+ *
+ * @param dpy X11 display to grab from
+ * @param d
+ * @param image Image where the grab will be put
+ * @param x Top-Left grabbing rectangle horizontal coordinate
+ * @param y Top-Left grabbing rectangle vertical coordinate
+ * @return 0 if error, !0 if successful
+ */
+static int
+xget_zpixmap(Display *dpy, Drawable d, XImage *image, int x, int y)
+{
+ xGetImageReply rep;
+ xGetImageReq *req;
+ long nbytes;
+
+ if (!image) {
+ return 0;
+ }
+
+ LockDisplay(dpy);
+ GetReq(GetImage, req);
+
+ /* First set up the standard stuff in the request */
+ req->drawable = d;
+ req->x = x;
+ req->y = y;
+ req->width = image->width;
+ req->height = image->height;
+ req->planeMask = (unsigned int)AllPlanes;
+ req->format = ZPixmap;
+
+ if (!_XReply(dpy, (xReply *)&rep, 0, xFalse) || !rep.length) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 0;
+ }
+
+ nbytes = (long)rep.length << 2;
+ _XReadPad(dpy, image->data, nbytes);
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 1;
+}
+
+/**
+ * Grabs a frame from x11 (public device demuxer API).
+ *
+ * @param s1 Context from avformat core
+ * @param pkt Packet holding the brabbed frame
+ * @return frame size in bytes
+ */
+static int
+x11grab_read_packet(AVFormatContext *s1, AVPacket *pkt)
+{
+ x11_grab_t *s = s1->priv_data;
+ Display *dpy = s->dpy;
+ XImage *image = s->image;
+ int x_off = s->x_off;
+ int y_off = s->y_off;
+
+ int64_t curtime, delay;
+ struct timespec ts;
+
+ /* Calculate the time of the next frame */
+ s->time_frame += INT64_C(1000000);
+
+ /* wait based on the frame rate */
+ for(;;) {
+ curtime = av_gettime();
+ delay = s->time_frame * av_q2d(s->time_base) - curtime;
+ if (delay <= 0) {
+ if (delay < INT64_C(-1000000) * av_q2d(s->time_base)) {
+ s->time_frame += INT64_C(1000000);
+ }
+ break;
+ }
+ ts.tv_sec = delay / 1000000;
+ ts.tv_nsec = (delay % 1000000) * 1000;
+ nanosleep(&ts, NULL);
+ }
+
+ if (av_new_packet(pkt, s->frame_size) < 0) {
+ return AVERROR_IO;
+ }
+
+ pkt->pts = curtime;
+
+ if(s->use_shm) {
+ if (!XShmGetImage(dpy, RootWindow(dpy, DefaultScreen(dpy)), image, x_off, y_off, AllPlanes)) {
+ av_log (s1, AV_LOG_INFO, "XShmGetImage() failed\n");
+ }
+ } else {
+ if (!xget_zpixmap(dpy, RootWindow(dpy, DefaultScreen(dpy)), image, x_off, y_off)) {
+ av_log (s1, AV_LOG_INFO, "XGetZPixmap() failed\n");
+ }
+ }
+
+ {
+ int pointer_x, pointer_y;
+ get_pointer_coordinates(&pointer_x, &pointer_y, dpy, s1);
+ paint_mouse_pointer(image, s, pointer_x, pointer_y);
+ }
+
+
+ /* XXX: avoid memcpy */
+ memcpy(pkt->data, image->data, s->frame_size);
+ return s->frame_size;
+}
+
+/**
+ * Closes x11 frame grabber (public device demuxer API).
+ *
+ * @param s1 Context from avformat core
+ * @return 0 success, !0 failure
+ */
+static int
+x11grab_read_close(AVFormatContext *s1)
+{
+ x11_grab_t *x11grab = s1->priv_data;
+
+ /* Detach cleanly from shared mem */
+ if (x11grab->use_shm) {
+ XShmDetach(x11grab->dpy, &x11grab->shminfo);
+ shmdt(x11grab->shminfo.shmaddr);
+ shmctl(x11grab->shminfo.shmid, IPC_RMID, NULL);
+ }
+
+ /* Destroy X11 image */
+ if (x11grab->image) {
+ XDestroyImage(x11grab->image);
+ x11grab->image = NULL;
+ }
+
+ /* Free X11 display */
+ XCloseDisplay(x11grab->dpy);
+ return 0;
+}
+
+/** x11 grabber device demuxer declaration */
+AVInputFormat x11_grab_device_demuxer =
+{
+ "x11grab",
+ "X11grab",
+ sizeof(x11_grab_t),
+ NULL,
+ x11grab_read_header,
+ x11grab_read_packet,
+ x11grab_read_close,
+ .flags = AVFMT_NOFILE,
+};
diff --git a/contrib/ffmpeg/libavformat/yuv4mpeg.c b/contrib/ffmpeg/libavformat/yuv4mpeg.c
new file mode 100644
index 000000000..70214ae00
--- /dev/null
+++ b/contrib/ffmpeg/libavformat/yuv4mpeg.c
@@ -0,0 +1,408 @@
+/*
+ * YUV4MPEG format
+ * Copyright (c) 2001, 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 "avformat.h"
+
+#define Y4M_MAGIC "YUV4MPEG2"
+#define Y4M_FRAME_MAGIC "FRAME"
+#define Y4M_LINE_MAX 256
+
+struct frame_attributes {
+ int interlaced_frame;
+ int top_field_first;
+};
+
+static int yuv4_generate_header(AVFormatContext *s, char* buf)
+{
+ AVStream *st;
+ int width, height;
+ int raten, rated, aspectn, aspectd, n;
+ char inter;
+ const char *colorspace = "";
+
+ st = s->streams[0];
+ width = st->codec->width;
+ height = st->codec->height;
+
+ av_reduce(&raten, &rated, st->codec->time_base.den, st->codec->time_base.num, (1UL<<31)-1);
+
+ aspectn = st->codec->sample_aspect_ratio.num;
+ aspectd = st->codec->sample_aspect_ratio.den;
+
+ if ( aspectn == 0 && aspectd == 1 ) aspectd = 0; // 0:0 means unknown
+
+ inter = 'p'; /* progressive is the default */
+ if (st->codec->coded_frame && st->codec->coded_frame->interlaced_frame) {
+ inter = st->codec->coded_frame->top_field_first ? 't' : 'b';
+ }
+
+ switch(st->codec->pix_fmt) {
+ case PIX_FMT_GRAY8:
+ colorspace = " Cmono";
+ break;
+ case PIX_FMT_YUV411P:
+ colorspace = " C411 XYSCSS=411";
+ break;
+ case PIX_FMT_YUV420P:
+ colorspace = (st->codec->codec_id == CODEC_ID_DVVIDEO)?" C420paldv XYSCSS=420PALDV":" C420mpeg2 XYSCSS=420MPEG2";
+ break;
+ case PIX_FMT_YUV422P:
+ colorspace = " C422 XYSCSS=422";
+ break;
+ case PIX_FMT_YUV444P:
+ colorspace = " C444 XYSCSS=444";
+ break;
+ }
+
+ /* construct stream header, if this is the first frame */
+ n = snprintf(buf, Y4M_LINE_MAX, "%s W%d H%d F%d:%d I%c A%d:%d%s\n",
+ Y4M_MAGIC,
+ width,
+ height,
+ raten, rated,
+ inter,
+ aspectn, aspectd,
+ colorspace);
+
+ return n;
+}
+
+static int yuv4_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ AVStream *st = s->streams[pkt->stream_index];
+ ByteIOContext *pb = &s->pb;
+ AVPicture *picture;
+ int* first_pkt = s->priv_data;
+ int width, height, h_chroma_shift, v_chroma_shift;
+ int i, m;
+ char buf2[Y4M_LINE_MAX+1];
+ char buf1[20];
+ uint8_t *ptr, *ptr1, *ptr2;
+
+ picture = (AVPicture *)pkt->data;
+
+ /* for the first packet we have to output the header as well */
+ if (*first_pkt) {
+ *first_pkt = 0;
+ if (yuv4_generate_header(s, buf2) < 0) {
+ av_log(s, AV_LOG_ERROR, "Error. YUV4MPEG stream header write failed.\n");
+ return AVERROR_IO;
+ } else {
+ put_buffer(pb, buf2, strlen(buf2));
+ }
+ }
+
+ /* construct frame header */
+
+ m = snprintf(buf1, sizeof(buf1), "%s\n", Y4M_FRAME_MAGIC);
+ put_buffer(pb, buf1, strlen(buf1));
+
+ width = st->codec->width;
+ height = st->codec->height;
+
+ ptr = picture->data[0];
+ for(i=0;i<height;i++) {
+ put_buffer(pb, ptr, width);
+ ptr += picture->linesize[0];
+ }
+
+ if (st->codec->pix_fmt != PIX_FMT_GRAY8){
+ // Adjust for smaller Cb and Cr planes
+ avcodec_get_chroma_sub_sample(st->codec->pix_fmt, &h_chroma_shift, &v_chroma_shift);
+ width >>= h_chroma_shift;
+ height >>= v_chroma_shift;
+
+ ptr1 = picture->data[1];
+ ptr2 = picture->data[2];
+ for(i=0;i<height;i++) { /* Cb */
+ put_buffer(pb, ptr1, width);
+ ptr1 += picture->linesize[1];
+ }
+ for(i=0;i<height;i++) { /* Cr */
+ put_buffer(pb, ptr2, width);
+ ptr2 += picture->linesize[2];
+ }
+ }
+ put_flush_packet(pb);
+ return 0;
+}
+
+static int yuv4_write_header(AVFormatContext *s)
+{
+ int* first_pkt = s->priv_data;
+
+ if (s->nb_streams != 1)
+ return AVERROR_IO;
+
+ if (s->streams[0]->codec->pix_fmt == PIX_FMT_YUV411P) {
+ av_log(s, AV_LOG_ERROR, "Warning: generating rarely used 4:1:1 YUV stream, some mjpegtools might not work.\n");
+ }
+ else if ((s->streams[0]->codec->pix_fmt != PIX_FMT_YUV420P) &&
+ (s->streams[0]->codec->pix_fmt != PIX_FMT_YUV422P) &&
+ (s->streams[0]->codec->pix_fmt != PIX_FMT_GRAY8) &&
+ (s->streams[0]->codec->pix_fmt != PIX_FMT_YUV444P)) {
+ av_log(s, AV_LOG_ERROR, "ERROR: yuv4mpeg only handles yuv444p, yuv422p, yuv420p, yuv411p and gray pixel formats. Use -pix_fmt to select one.\n");
+ return AVERROR_IO;
+ }
+
+ *first_pkt = 1;
+ return 0;
+}
+
+static int yuv4_write_trailer(AVFormatContext *s)
+{
+ return 0;
+}
+
+#ifdef CONFIG_YUV4MPEGPIPE_MUXER
+AVOutputFormat yuv4mpegpipe_muxer = {
+ "yuv4mpegpipe",
+ "YUV4MPEG pipe format",
+ "",
+ "y4m",
+ sizeof(int),
+ CODEC_ID_NONE,
+ CODEC_ID_RAWVIDEO,
+ yuv4_write_header,
+ yuv4_write_packet,
+ yuv4_write_trailer,
+ .flags = AVFMT_RAWPICTURE,
+};
+#endif
+
+/* Header size increased to allow room for optional flags */
+#define MAX_YUV4_HEADER 80
+#define MAX_FRAME_HEADER 80
+
+static int yuv4_read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+ char header[MAX_YUV4_HEADER+10]; // Include headroom for the longest option
+ char *tokstart,*tokend,*header_end;
+ int i;
+ ByteIOContext *pb = &s->pb;
+ int width=-1, height=-1, raten=0, rated=0, aspectn=0, aspectd=0;
+ enum PixelFormat pix_fmt=PIX_FMT_NONE,alt_pix_fmt=PIX_FMT_NONE;
+ AVStream *st;
+ struct frame_attributes *s1 = s->priv_data;
+
+ for (i=0; i<MAX_YUV4_HEADER; i++) {
+ header[i] = get_byte(pb);
+ if (header[i] == '\n') {
+ header[i+1] = 0x20; // Add a space after last option. Makes parsing "444" vs "444alpha" easier.
+ header[i+2] = 0;
+ break;
+ }
+ }
+ if (i == MAX_YUV4_HEADER) return -1;
+ if (strncmp(header, Y4M_MAGIC, strlen(Y4M_MAGIC))) return -1;
+
+ s1->interlaced_frame = 0;
+ s1->top_field_first = 0;
+ header_end = &header[i+1]; // Include space
+ for(tokstart = &header[strlen(Y4M_MAGIC) + 1]; tokstart < header_end; tokstart++) {
+ if (*tokstart==0x20) continue;
+ switch (*tokstart++) {
+ case 'W': // Width. Required.
+ width = strtol(tokstart, &tokend, 10);
+ tokstart=tokend;
+ break;
+ case 'H': // Height. Required.
+ height = strtol(tokstart, &tokend, 10);
+ tokstart=tokend;
+ break;
+ case 'C': // Color space
+ if (strncmp("420jpeg",tokstart,7)==0)
+ pix_fmt = PIX_FMT_YUV420P;
+ else if (strncmp("420mpeg2",tokstart,8)==0)
+ pix_fmt = PIX_FMT_YUV420P;
+ else if (strncmp("420paldv", tokstart, 8)==0)
+ pix_fmt = PIX_FMT_YUV420P;
+ else if (strncmp("411", tokstart, 3)==0)
+ pix_fmt = PIX_FMT_YUV411P;
+ else if (strncmp("422", tokstart, 3)==0)
+ pix_fmt = PIX_FMT_YUV422P;
+ else if (strncmp("444alpha", tokstart, 8)==0) {
+ av_log(s, AV_LOG_ERROR, "Cannot handle 4:4:4:4 YUV4MPEG stream.\n");
+ return -1;
+ } else if (strncmp("444", tokstart, 3)==0)
+ pix_fmt = PIX_FMT_YUV444P;
+ else if (strncmp("mono",tokstart, 4)==0) {
+ pix_fmt = PIX_FMT_GRAY8;
+ } else {
+ av_log(s, AV_LOG_ERROR, "YUV4MPEG stream contains an unknown pixel format.\n");
+ return -1;
+ }
+ while(tokstart<header_end&&*tokstart!=0x20) tokstart++;
+ break;
+ case 'I': // Interlace type
+ switch (*tokstart++){
+ case '?':
+ break;
+ case 'p':
+ s1->interlaced_frame=0;
+ break;
+ case 't':
+ s1->interlaced_frame=1;
+ s1->top_field_first=1;
+ break;
+ case 'b':
+ s1->interlaced_frame=1;
+ s1->top_field_first=0;
+ break;
+ case 'm':
+ av_log(s, AV_LOG_ERROR, "YUV4MPEG stream contains mixed interlaced and non-interlaced frames.\n");
+ return -1;
+ default:
+ av_log(s, AV_LOG_ERROR, "YUV4MPEG has invalid header.\n");
+ return -1;
+ }
+ break;
+ case 'F': // Frame rate
+ sscanf(tokstart,"%d:%d",&raten,&rated); // 0:0 if unknown
+ while(tokstart<header_end&&*tokstart!=0x20) tokstart++;
+ break;
+ case 'A': // Pixel aspect
+ sscanf(tokstart,"%d:%d",&aspectn,&aspectd); // 0:0 if unknown
+ while(tokstart<header_end&&*tokstart!=0x20) tokstart++;
+ break;
+ case 'X': // Vendor extensions
+ if (strncmp("YSCSS=",tokstart,6)==0) {
+ // Older nonstandard pixel format representation
+ tokstart+=6;
+ if (strncmp("420JPEG",tokstart,7)==0)
+ alt_pix_fmt=PIX_FMT_YUV420P;
+ else if (strncmp("420MPEG2",tokstart,8)==0)
+ alt_pix_fmt=PIX_FMT_YUV420P;
+ else if (strncmp("420PALDV",tokstart,8)==0)
+ alt_pix_fmt=PIX_FMT_YUV420P;
+ else if (strncmp("411",tokstart,3)==0)
+ alt_pix_fmt=PIX_FMT_YUV411P;
+ else if (strncmp("422",tokstart,3)==0)
+ alt_pix_fmt=PIX_FMT_YUV422P;
+ else if (strncmp("444",tokstart,3)==0)
+ alt_pix_fmt=PIX_FMT_YUV444P;
+ }
+ while(tokstart<header_end&&*tokstart!=0x20) tokstart++;
+ break;
+ }
+ }
+
+ if ((width == -1) || (height == -1)) {
+ av_log(s, AV_LOG_ERROR, "YUV4MPEG has invalid header.\n");
+ return -1;
+ }
+
+ if (pix_fmt == PIX_FMT_NONE) {
+ if (alt_pix_fmt == PIX_FMT_NONE)
+ pix_fmt = PIX_FMT_YUV420P;
+ else
+ pix_fmt = alt_pix_fmt;
+ }
+
+ if (raten == 0 && rated == 0) {
+ // Frame rate unknown
+ raten = 25;
+ rated = 1;
+ }
+
+ if (aspectn == 0 && aspectd == 0) {
+ // Pixel aspect unknown
+ aspectd = 1;
+ }
+
+ st = av_new_stream(s, 0);
+ st = s->streams[0];
+ st->codec->width = width;
+ st->codec->height = height;
+ 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_id = CODEC_ID_RAWVIDEO;
+ st->codec->sample_aspect_ratio= (AVRational){aspectn, aspectd};
+
+ return 0;
+}
+
+static int yuv4_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ int i;
+ char header[MAX_FRAME_HEADER+1];
+ int packet_size, width, height;
+ AVStream *st = s->streams[0];
+ struct frame_attributes *s1 = s->priv_data;
+
+ for (i=0; i<MAX_FRAME_HEADER; i++) {
+ header[i] = get_byte(&s->pb);
+ if (header[i] == '\n') {
+ header[i+1] = 0;
+ break;
+ }
+ }
+ if (i == MAX_FRAME_HEADER) return -1;
+ if (strncmp(header, Y4M_FRAME_MAGIC, strlen(Y4M_FRAME_MAGIC))) return -1;
+
+ width = st->codec->width;
+ height = st->codec->height;
+
+ packet_size = avpicture_get_size(st->codec->pix_fmt, width, height);
+ if (packet_size < 0)
+ return -1;
+
+ if (av_get_packet(&s->pb, pkt, packet_size) != packet_size)
+ return AVERROR_IO;
+
+ if (s->streams[0]->codec->coded_frame) {
+ s->streams[0]->codec->coded_frame->interlaced_frame = s1->interlaced_frame;
+ s->streams[0]->codec->coded_frame->top_field_first = s1->top_field_first;
+ }
+
+ pkt->stream_index = 0;
+ return 0;
+}
+
+static int yuv4_read_close(AVFormatContext *s)
+{
+ return 0;
+}
+
+static int yuv4_probe(AVProbeData *pd)
+{
+ /* check file header */
+ if (pd->buf_size <= sizeof(Y4M_MAGIC))
+ return 0;
+ if (strncmp(pd->buf, Y4M_MAGIC, sizeof(Y4M_MAGIC)-1)==0)
+ return AVPROBE_SCORE_MAX;
+ else
+ return 0;
+}
+
+#ifdef CONFIG_YUV4MPEGPIPE_DEMUXER
+AVInputFormat yuv4mpegpipe_demuxer = {
+ "yuv4mpegpipe",
+ "YUV4MPEG pipe format",
+ sizeof(struct frame_attributes),
+ yuv4_probe,
+ yuv4_read_header,
+ yuv4_read_packet,
+ yuv4_read_close,
+ .extensions = "y4m"
+};
+#endif
diff --git a/contrib/ffmpeg/libavutil/Makefile b/contrib/ffmpeg/libavutil/Makefile
new file mode 100644
index 000000000..a760401ab
--- /dev/null
+++ b/contrib/ffmpeg/libavutil/Makefile
@@ -0,0 +1,27 @@
+include ../config.mak
+
+OBJS= mathematics.o \
+ rational.o \
+ intfloat_readwrite.o \
+ crc.o \
+ md5.o \
+ lls.o \
+ adler32.o \
+ log.o \
+ mem.o \
+ fifo.o \
+ tree.o \
+ lzo.o \
+ random.o \
+ aes.o \
+ base64.o \
+
+HEADERS = avutil.h common.h mathematics.h integer.h rational.h \
+ intfloat_readwrite.h md5.h adler32.h log.h fifo.h lzo.h \
+ random.h mem.h base64.h
+
+NAME=avutil
+LIBVERSION=$(LAVUVERSION)
+LIBMAJOR=$(LAVUMAJOR)
+
+include ../common.mak
diff --git a/src/libffmpeg/libavutil/adler32.c b/contrib/ffmpeg/libavutil/adler32.c
index 50d57470b..50d57470b 100644
--- a/src/libffmpeg/libavutil/adler32.c
+++ b/contrib/ffmpeg/libavutil/adler32.c
diff --git a/src/libffmpeg/libavutil/adler32.h b/contrib/ffmpeg/libavutil/adler32.h
index f56d416fb..f56d416fb 100644
--- a/src/libffmpeg/libavutil/adler32.h
+++ b/contrib/ffmpeg/libavutil/adler32.h
diff --git a/contrib/ffmpeg/libavutil/aes.c b/contrib/ffmpeg/libavutil/aes.c
new file mode 100644
index 000000000..55ae0d4f3
--- /dev/null
+++ b/contrib/ffmpeg/libavutil/aes.c
@@ -0,0 +1,239 @@
+/*
+ * copyright (c) 2007 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * some optimization ideas from aes128.c by Reimar Doeffinger
+ */
+
+#include "common.h"
+#include "aes.h"
+
+typedef struct AVAES{
+ uint8_t round_key[15][4][4];
+ uint8_t state[2][4][4];
+ int rounds;
+}AVAES;
+
+const int av_aes_size= sizeof(AVAES);
+
+static const uint8_t rcon[10] = {
+ 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36
+};
+
+static uint8_t sbox[256];
+static uint8_t inv_sbox[256];
+#ifdef CONFIG_SMALL
+static uint32_t enc_multbl[1][256];
+static uint32_t dec_multbl[1][256];
+#else
+static uint32_t enc_multbl[4][256];
+static uint32_t dec_multbl[4][256];
+#endif
+
+static inline void addkey(uint64_t dst[2], uint64_t src[2], uint64_t round_key[2]){
+ dst[0] = src[0] ^ round_key[0];
+ dst[1] = src[1] ^ round_key[1];
+}
+
+static void subshift(uint8_t s0[2][16], int s, uint8_t *box){
+ uint8_t (*s1)[16]= s0[0] - s;
+ uint8_t (*s3)[16]= s0[0] + s;
+ s0[0][0]=box[s0[1][ 0]]; s0[0][ 4]=box[s0[1][ 4]]; s0[0][ 8]=box[s0[1][ 8]]; s0[0][12]=box[s0[1][12]];
+ s1[0][3]=box[s1[1][ 7]]; s1[0][ 7]=box[s1[1][11]]; s1[0][11]=box[s1[1][15]]; s1[0][15]=box[s1[1][ 3]];
+ s0[0][2]=box[s0[1][10]]; s0[0][10]=box[s0[1][ 2]]; s0[0][ 6]=box[s0[1][14]]; s0[0][14]=box[s0[1][ 6]];
+ s3[0][1]=box[s3[1][13]]; s3[0][13]=box[s3[1][ 9]]; s3[0][ 9]=box[s3[1][ 5]]; s3[0][ 5]=box[s3[1][ 1]];
+}
+
+static inline int mix_core(uint32_t multbl[4][256], int a, int b, int c, int d){
+#ifdef CONFIG_SMALL
+#define ROT(x,s) ((x<<s)|(x>>(32-s)))
+ return multbl[0][a] ^ ROT(multbl[0][b], 8) ^ ROT(multbl[0][c], 16) ^ ROT(multbl[0][d], 24);
+#else
+ return multbl[0][a] ^ multbl[1][b] ^ multbl[2][c] ^ multbl[3][d];
+#endif
+}
+
+static inline void mix(uint8_t state[2][4][4], uint32_t multbl[4][256], int s1, int s3){
+ ((uint32_t *)(state))[0] = mix_core(multbl, state[1][0][0], state[1][s1 ][1], state[1][2][2], state[1][s3 ][3]);
+ ((uint32_t *)(state))[1] = mix_core(multbl, state[1][1][0], state[1][s3-1][1], state[1][3][2], state[1][s1-1][3]);
+ ((uint32_t *)(state))[2] = mix_core(multbl, state[1][2][0], state[1][s3 ][1], state[1][0][2], state[1][s1 ][3]);
+ ((uint32_t *)(state))[3] = mix_core(multbl, state[1][3][0], state[1][s1-1][1], state[1][1][2], state[1][s3-1][3]);
+}
+
+static inline void crypt(AVAES *a, int s, uint8_t *sbox, uint32_t *multbl){
+ int r;
+
+ for(r=a->rounds-1; r>0; r--){
+ mix(a->state, multbl, 3-s, 1+s);
+ addkey(a->state[1], a->state[0], a->round_key[r]);
+ }
+ subshift(a->state[0][0], s, sbox);
+}
+
+void av_aes_crypt(AVAES *a, uint8_t *dst, uint8_t *src, int count, uint8_t *iv, int decrypt){
+ while(count--){
+ addkey(a->state[1], src, a->round_key[a->rounds]);
+ if(decrypt) {
+ crypt(a, 0, inv_sbox, dec_multbl);
+ if(iv){
+ addkey(a->state[0], a->state[0], iv);
+ memcpy(iv, src, 16);
+ }
+ addkey(dst, a->state[0], a->round_key[0]);
+ }else{
+ if(iv) addkey(a->state[1], a->state[1], iv);
+ crypt(a, 2, sbox, enc_multbl);
+ addkey(dst, a->state[0], a->round_key[0]);
+ if(iv) memcpy(iv, dst, 16);
+ }
+ src+=16;
+ dst+=16;
+ }
+}
+
+static void init_multbl2(uint8_t tbl[1024], int c[4], uint8_t *log8, uint8_t *alog8, uint8_t *sbox){
+ int i, j;
+ for(i=0; i<1024; i++){
+ int x= sbox[i>>2];
+ if(x) tbl[i]= alog8[ log8[x] + log8[c[i&3]] ];
+ }
+#ifndef CONFIG_SMALL
+ for(j=256; j<1024; j++)
+ for(i=0; i<4; i++)
+ tbl[4*j+i]= tbl[4*j + ((i-1)&3) - 1024];
+#endif
+}
+
+// this is based on the reference AES code by Paulo Barreto and Vincent Rijmen
+int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt) {
+ int i, j, t, rconpointer = 0;
+ uint8_t tk[8][4];
+ int KC= key_bits>>5;
+ int rounds= KC + 6;
+ uint8_t log8[256];
+ uint8_t alog8[512];
+
+ if(!enc_multbl[4][1023]){
+ j=1;
+ for(i=0; i<255; i++){
+ alog8[i]=
+ alog8[i+255]= j;
+ log8[j]= i;
+ j^= j+j;
+ if(j>255) j^= 0x11B;
+ }
+ for(i=0; i<256; i++){
+ j= i ? alog8[255-log8[i]] : 0;
+ j ^= (j<<1) ^ (j<<2) ^ (j<<3) ^ (j<<4);
+ j = (j ^ (j>>8) ^ 99) & 255;
+ inv_sbox[j]= i;
+ sbox [i]= j;
+ }
+ init_multbl2(dec_multbl[0], (int[4]){0xe, 0x9, 0xd, 0xb}, log8, alog8, inv_sbox);
+ init_multbl2(enc_multbl[0], (int[4]){0x2, 0x1, 0x1, 0x3}, log8, alog8, sbox);
+ }
+
+ if(key_bits!=128 && key_bits!=192 && key_bits!=256)
+ return -1;
+
+ a->rounds= rounds;
+
+ memcpy(tk, key, KC*4);
+
+ for(t= 0; t < (rounds+1)*16;) {
+ memcpy(a->round_key[0][0]+t, tk, KC*4);
+ t+= KC*4;
+
+ for(i = 0; i < 4; i++)
+ tk[0][i] ^= sbox[tk[KC-1][(i+1)&3]];
+ tk[0][0] ^= rcon[rconpointer++];
+
+ for(j = 1; j < KC; j++){
+ if(KC != 8 || j != KC>>1)
+ for(i = 0; i < 4; i++) tk[j][i] ^= tk[j-1][i];
+ else
+ for(i = 0; i < 4; i++) tk[j][i] ^= sbox[tk[j-1][i]];
+ }
+ }
+
+ if(decrypt){
+ for(i=1; i<rounds; i++){
+ uint8_t tmp[3][16];
+ memcpy(tmp[2], a->round_key[i][0], 16);
+ subshift(tmp[1], 0, sbox);
+ mix(tmp, dec_multbl, 1, 3);
+ memcpy(a->round_key[i][0], tmp[0], 16);
+ }
+ }else{
+ for(i=0; i<(rounds+1)>>1; i++){
+ for(j=0; j<16; j++)
+ FFSWAP(int, a->round_key[i][0][j], a->round_key[rounds-i][0][j]);
+ }
+ }
+
+ return 0;
+}
+
+#ifdef TEST
+#include "log.h"
+
+int main(){
+ int i,j;
+ AVAES ae, ad, b;
+ uint8_t rkey[2][16]= {
+ {0},
+ {0x10, 0xa5, 0x88, 0x69, 0xd7, 0x4b, 0xe5, 0xa3, 0x74, 0xcf, 0x86, 0x7c, 0xfb, 0x47, 0x38, 0x59}};
+ uint8_t pt[16], rpt[2][16]= {
+ {0x6a, 0x84, 0x86, 0x7c, 0xd7, 0x7e, 0x12, 0xad, 0x07, 0xea, 0x1b, 0xe8, 0x95, 0xc5, 0x3f, 0xa3},
+ {0}};
+ uint8_t rct[2][16]= {
+ {0x73, 0x22, 0x81, 0xc0, 0xa0, 0xaa, 0xb8, 0xf7, 0xa5, 0x4a, 0x0c, 0x67, 0xa0, 0xc4, 0x5e, 0xcf},
+ {0x6d, 0x25, 0x1e, 0x69, 0x44, 0xb0, 0x51, 0xe0, 0x4e, 0xaa, 0x6f, 0xb4, 0xdb, 0xf7, 0x84, 0x65}};
+ uint8_t temp[16];
+
+ av_aes_init(&ae, "PI=3.141592654..", 128, 0);
+ av_aes_init(&ad, "PI=3.141592654..", 128, 1);
+ av_log_level= AV_LOG_DEBUG;
+
+ for(i=0; i<2; i++){
+ av_aes_init(&b, rkey[i], 128, 1);
+ av_aes_crypt(&b, temp, rct[i], 1, NULL, 1);
+ for(j=0; j<16; j++)
+ if(rpt[i][j] != temp[j])
+ av_log(NULL, AV_LOG_ERROR, "%d %02X %02X\n", j, rpt[i][j], temp[j]);
+ }
+
+ for(i=0; i<10000; i++){
+ for(j=0; j<16; j++){
+ pt[j]= random();
+ }
+{START_TIMER
+ av_aes_crypt(&ae, temp, pt, 1, NULL, 0);
+ if(!(i&(i-1)))
+ av_log(NULL, AV_LOG_ERROR, "%02X %02X %02X %02X\n", temp[0], temp[5], temp[10], temp[15]);
+ av_aes_crypt(&ad, temp, temp, 1, NULL, 1);
+STOP_TIMER("aes")}
+ for(j=0; j<16; j++){
+ if(pt[j] != temp[j]){
+ av_log(NULL, AV_LOG_ERROR, "%d %d %02X %02X\n", i,j, pt[j], temp[j]);
+ }
+ }
+ }
+ return 0;
+}
+#endif
diff --git a/contrib/ffmpeg/libavutil/aes.h b/contrib/ffmpeg/libavutil/aes.h
new file mode 100644
index 000000000..34ba0a2fa
--- /dev/null
+++ b/contrib/ffmpeg/libavutil/aes.h
@@ -0,0 +1,45 @@
+/*
+ * copyright (c) 2007 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AES_H
+#define AES_H
+
+extern const int av_aes_size;
+
+struct AVAES;
+
+/**
+ * initalizes a AVAES context
+ * @param key_bits 128, 192 or 256
+ * @param decrypt 0 for encryption, 1 for decryption
+ */
+int av_aes_init(struct AVAES *a, const uint8_t *key, int key_bits, int decrypt);
+
+/**
+ * encrypts / decrypts.
+ * @param count number of 16 byte blocks
+ * @param dst destination array, can be equal to src
+ * @param src source array, can be equal to dst
+ * @param iv initalization vector for CBC mode, if NULL then ECB will be used
+ * @param decrypt 0 for encryption, 1 for decryption
+ */
+void av_aes_crypt(struct AVAES *a, uint8_t *dst, uint8_t *src, int count, uint8_t *iv, int decrypt);
+
+#endif /* AES_H */
diff --git a/contrib/ffmpeg/libavutil/avutil.h b/contrib/ffmpeg/libavutil/avutil.h
new file mode 100644
index 000000000..32bc40bfb
--- /dev/null
+++ b/contrib/ffmpeg/libavutil/avutil.h
@@ -0,0 +1,137 @@
+/*
+ * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_H
+#define AVUTIL_H
+
+/**
+ * @file avutil.h
+ * external api header.
+ */
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define AV_STRINGIFY(s) AV_TOSTRING(s)
+#define AV_TOSTRING(s) #s
+
+#define LIBAVUTIL_VERSION_INT ((49<<16)+(4<<8)+0)
+#define LIBAVUTIL_VERSION 49.4.0
+#define LIBAVUTIL_BUILD LIBAVUTIL_VERSION_INT
+
+#define LIBAVUTIL_IDENT "Lavu" AV_STRINGIFY(LIBAVUTIL_VERSION)
+
+
+#include "common.h"
+#include "mathematics.h"
+#include "rational.h"
+#include "integer.h"
+#include "intfloat_readwrite.h"
+#include "log.h"
+
+/**
+ * Pixel format. Notes:
+ *
+ * PIX_FMT_RGB32 is handled in an endian-specific manner. A RGBA
+ * color is put together as:
+ * (A << 24) | (R << 16) | (G << 8) | B
+ * This is stored as BGRA on little endian CPU architectures and ARGB on
+ * big endian CPUs.
+ *
+ * When the pixel format is palettized RGB (PIX_FMT_PAL8), the palettized
+ * image data is stored in AVFrame.data[0]. The palette is transported in
+ * AVFrame.data[1] and, is 1024 bytes long (256 4-byte entries) and is
+ * formatted the same as in PIX_FMT_RGB32 described above (i.e., it is
+ * also endian-specific). Note also that the individual RGB palette
+ * components stored in AVFrame.data[1] should be in the range 0..255.
+ * This is important as many custom PAL8 video codecs that were designed
+ * to run on the IBM VGA graphics adapter use 6-bit palette components.
+ */
+enum PixelFormat {
+ PIX_FMT_NONE= -1,
+ PIX_FMT_YUV420P, ///< Planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
+ PIX_FMT_YUYV422, ///< Packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
+ PIX_FMT_RGB24, ///< Packed RGB 8:8:8, 24bpp, RGBRGB...
+ PIX_FMT_BGR24, ///< Packed RGB 8:8:8, 24bpp, BGRBGR...
+ PIX_FMT_YUV422P, ///< Planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
+ PIX_FMT_YUV444P, ///< Planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
+ PIX_FMT_RGB32, ///< Packed RGB 8:8:8, 32bpp, (msb)8A 8R 8G 8B(lsb), in cpu endianness
+ PIX_FMT_YUV410P, ///< Planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
+ PIX_FMT_YUV411P, ///< Planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
+ PIX_FMT_RGB565, ///< Packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), in cpu endianness
+ PIX_FMT_RGB555, ///< Packed RGB 5:5:5, 16bpp, (msb)1A 5R 5G 5B(lsb), in cpu endianness most significant bit to 0
+ PIX_FMT_GRAY8, ///< Y , 8bpp
+ PIX_FMT_MONOWHITE, ///< Y , 1bpp, 1 is white
+ PIX_FMT_MONOBLACK, ///< Y , 1bpp, 0 is black
+ PIX_FMT_PAL8, ///< 8 bit with PIX_FMT_RGB32 palette
+ PIX_FMT_YUVJ420P, ///< Planar YUV 4:2:0, 12bpp, full scale (jpeg)
+ PIX_FMT_YUVJ422P, ///< Planar YUV 4:2:2, 16bpp, full scale (jpeg)
+ PIX_FMT_YUVJ444P, ///< Planar YUV 4:4:4, 24bpp, full scale (jpeg)
+ PIX_FMT_XVMC_MPEG2_MC,///< XVideo Motion Acceleration via common packet passing(xvmc_render.h)
+ PIX_FMT_XVMC_MPEG2_IDCT,
+ PIX_FMT_UYVY422, ///< Packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
+ PIX_FMT_UYYVYY411, ///< Packed YUV 4:1:1, 12bpp, Cb Y0 Y1 Cr Y2 Y3
+ PIX_FMT_BGR32, ///< Packed RGB 8:8:8, 32bpp, (msb)8A 8B 8G 8R(lsb), in cpu endianness
+ PIX_FMT_BGR565, ///< Packed RGB 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), in cpu endianness
+ PIX_FMT_BGR555, ///< Packed RGB 5:5:5, 16bpp, (msb)1A 5B 5G 5R(lsb), in cpu endianness most significant bit to 1
+ PIX_FMT_BGR8, ///< Packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
+ PIX_FMT_BGR4, ///< Packed RGB 1:2:1, 4bpp, (msb)1B 2G 1R(lsb)
+ PIX_FMT_BGR4_BYTE, ///< Packed RGB 1:2:1, 8bpp, (msb)1B 2G 1R(lsb)
+ PIX_FMT_RGB8, ///< Packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb)
+ PIX_FMT_RGB4, ///< Packed RGB 1:2:1, 4bpp, (msb)2R 3G 3B(lsb)
+ PIX_FMT_RGB4_BYTE, ///< Packed RGB 1:2:1, 8bpp, (msb)2R 3G 3B(lsb)
+ PIX_FMT_NV12, ///< Planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 for UV
+ PIX_FMT_NV21, ///< as above, but U and V bytes are swapped
+
+ PIX_FMT_RGB32_1, ///< Packed RGB 8:8:8, 32bpp, (msb)8R 8G 8B 8A(lsb), in cpu endianness
+ PIX_FMT_BGR32_1, ///< Packed RGB 8:8:8, 32bpp, (msb)8B 8G 8R 8A(lsb), in cpu endianness
+
+ PIX_FMT_GRAY16BE, ///< Y , 16bpp, big-endian
+ PIX_FMT_GRAY16LE, ///< Y , 16bpp, little-endian
+ PIX_FMT_NB, ///< number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of formats might differ between versions
+};
+
+#ifdef WORDS_BIGENDIAN
+#define PIX_FMT_RGBA PIX_FMT_RGB32_1
+#define PIX_FMT_BGRA PIX_FMT_BGR32_1
+#define PIX_FMT_ARGB PIX_FMT_RGB32
+#define PIX_FMT_ABGR PIX_FMT_BGR32
+#define PIX_FMT_GRAY16 PIX_FMT_GRAY16BE
+#else
+#define PIX_FMT_RGBA PIX_FMT_BGR32
+#define PIX_FMT_BGRA PIX_FMT_RGB32
+#define PIX_FMT_ARGB PIX_FMT_BGR32_1
+#define PIX_FMT_ABGR PIX_FMT_RGB32_1
+#define PIX_FMT_GRAY16 PIX_FMT_GRAY16LE
+#endif
+
+#if LIBAVUTIL_VERSION_INT < (50<<16)
+#define PIX_FMT_UYVY411 PIX_FMT_UYYVYY411
+#define PIX_FMT_RGBA32 PIX_FMT_RGB32
+#define PIX_FMT_YUV422 PIX_FMT_YUYV422
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* AVUTIL_H */
diff --git a/contrib/ffmpeg/libavutil/base64.c b/contrib/ffmpeg/libavutil/base64.c
new file mode 100644
index 000000000..bee800c82
--- /dev/null
+++ b/contrib/ffmpeg/libavutil/base64.c
@@ -0,0 +1,230 @@
+/*
+ * Base64.c
+ * Copyright (c) 2006 Ryan Martell. (rdm4@martellventures.com)
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+* @file base64.c
+ * @brief Base64 Encode/Decode
+ * @author Ryan Martell <rdm4@martellventures.com> (with lots of Michael)
+ */
+
+#include "common.h"
+#include "base64.h"
+
+/* ---------------- private code */
+static uint8_t map2[] =
+{
+ 0x3e, 0xff, 0xff, 0xff, 0x3f, 0x34, 0x35, 0x36,
+ 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x01,
+ 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
+ 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11,
+ 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1a, 0x1b,
+ 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
+ 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
+ 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33
+};
+
+int av_base64_decode(uint8_t * out, const char *in, int out_length)
+{
+ int i, v;
+ uint8_t *dst = out;
+
+ v = 0;
+ for (i = 0; in[i] && in[i] != '='; i++) {
+ unsigned int index= in[i]-43;
+ if (index>=(sizeof(map2)/sizeof(map2[0])) || map2[index] == 0xff)
+ return -1;
+ v = (v << 6) + map2[index];
+ if (i & 3) {
+ if (dst - out < out_length) {
+ *dst++ = v >> (6 - 2 * (i & 3));
+ }
+ }
+ }
+
+ return (dst - out);
+}
+
+/*****************************************************************************
+* b64_encode: stolen from VLC's http.c
+* simplified by michael
+* fixed edge cases and made it work from data (vs. strings) by ryan.
+*****************************************************************************/
+
+char *av_base64_encode(char * buf, int buf_len, uint8_t * src, int len)
+{
+ static const char b64[] =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+ char *ret, *dst;
+ unsigned i_bits = 0;
+ int i_shift = 0;
+ int bytes_remaining = len;
+
+ if (len >= UINT_MAX / 4 ||
+ buf_len < len * 4 / 3 + 12)
+ return NULL;
+ ret = dst = buf;
+ if (len) { // special edge case, what should we really do here?
+ while (bytes_remaining) {
+ i_bits = (i_bits << 8) + *src++;
+ bytes_remaining--;
+ i_shift += 8;
+
+ do {
+ *dst++ = b64[(i_bits << 6 >> i_shift) & 0x3f];
+ i_shift -= 6;
+ } while (i_shift > 6 || (bytes_remaining == 0 && i_shift > 0));
+ }
+ while ((dst - ret) & 3)
+ *dst++ = '=';
+ }
+ *dst = '\0';
+
+ return ret;
+}
+
+// #define TEST_BASE64
+
+#ifdef TEST_BASE64
+#include "avutil.h"
+
+int b64test()
+{
+ int numerr = 0;
+ int len;
+ int numtest = 1;
+ uint8_t decode[1000];
+ struct test {
+ void *data;
+ int len;
+ const char *result;
+ } *t, tests[] = {
+ {
+ "", 0, ""}, {
+ "1", 1, "MQ=="}, {
+ "22", 2, "MjI="}, {
+ "333", 3, "MzMz"}, {
+ "4444", 4, "NDQ0NA=="}, {
+ "55555", 5, "NTU1NTU="}, {
+ "abc:def", 7, "YWJjOmRlZg=="}, {
+ NULL}
+ };
+ for (t = tests; t->data; t++) {
+ char *str;
+
+ av_log(NULL, AV_LOG_ERROR, "Encoding %s...\n", (char *) t->data);
+ str = av_base64_encode(t->data, t->len);
+ if (str) {
+ av_log(NULL, AV_LOG_ERROR, "Encoded to %s...\n", str);
+ if (strcmp(str, t->result) != 0) {
+ av_log(NULL, AV_LOG_ERROR, "failed test %d: %s != %s\n",
+ numtest, str, t->result);
+ numerr++;
+ }
+ av_free(str);
+ }
+
+ av_log(NULL, AV_LOG_ERROR, "Done encoding, about to decode...\n");
+ len = av_base64_decode(decode, t->result, sizeof(decode));
+ if (len != t->len) {
+ av_log(NULL, AV_LOG_ERROR, "failed test %d: len %d != %d\n",
+ numtest, len, t->len);
+ numerr++;
+ } else if (memcmp(decode, t->data, t->len) != 0) {
+ av_log(NULL, AV_LOG_ERROR, "failed test %d: data\n", numtest);
+ numerr++;
+ } else {
+ av_log(NULL, AV_LOG_ERROR, "Decoded to %s\n",
+ (char *) t->data);
+ }
+ numtest++;
+ }
+
+#undef srand
+#undef rand
+
+ {
+ int test_count;
+ srand(123141); // time(NULL));
+ for (test_count = 0; test_count < 100; test_count++) {
+ int size = rand() % 1024;
+ int ii;
+ uint8_t *data;
+ char *encoded_result;
+
+ av_log(NULL, AV_LOG_ERROR, "Test %d: Size %d bytes...",
+ test_count, size);
+ data = (uint8_t *) av_malloc(size);
+ for (ii = 0; ii < size; ii++) {
+ data[ii] = rand() % 255;
+ }
+
+ encoded_result = av_base64_encode(data, size);
+ if (encoded_result) {
+ int decode_buffer_size = size + 10; // try without 10 as well
+ uint8_t *decode_buffer = av_malloc(decode_buffer_size);
+ if (decode_buffer) {
+ int decoded_size =
+ av_base64_decode(decode_buffer, encoded_result,
+ decode_buffer_size);
+
+ if (decoded_size != size) {
+ av_log(NULL, AV_LOG_ERROR,
+ "Decoded/Encoded size mismatch (%d != %d)\n",
+ decoded_size, size);
+ } else {
+ if (memcmp(decode_buffer, data, decoded_size) == 0) {
+ av_log(NULL, AV_LOG_ERROR, "Passed!\n");
+ } else {
+ av_log(NULL, AV_LOG_ERROR,
+ "Failed (Data differs)!\n");
+ }
+ }
+ av_free(decode_buffer);
+ }
+
+ av_free(encoded_result);
+ }
+ }
+ }
+
+ // these are invalid strings, that it currently decodes (which it probably shouldn't?)
+ {
+ uint8_t str[32];
+ if (av_base64_decode(str, "M=M=", sizeof(str)) != -1) {
+ av_log(NULL, AV_LOG_ERROR,
+ "failed test %d: successful decode of `M=M='\n",
+ numtest++);
+ numerr++;
+ }
+ if (av_base64_decode(str, "MQ===", sizeof(str)) != -1) {
+ av_log(NULL, AV_LOG_ERROR,
+ "failed test %d: successful decode of `MQ==='\n",
+ numtest++);
+ numerr++;
+ }
+ }
+
+ return numerr;
+}
+#endif
+
diff --git a/contrib/ffmpeg/libavutil/base64.h b/contrib/ffmpeg/libavutil/base64.h
new file mode 100644
index 000000000..3d905313c
--- /dev/null
+++ b/contrib/ffmpeg/libavutil/base64.h
@@ -0,0 +1,34 @@
+/*
+ * Base64.c
+ * Copyright (c) 2006 Ryan Martell. (rdm4@martellventures.com)
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * decodes base64
+ * param order as strncpy()
+ */
+int av_base64_decode(uint8_t * out, const char *in, int out_length);
+
+/**
+ * encodes base64
+ * @param src data, not a string
+ * @param buf output string
+ */
+char *av_base64_encode(char * buf, int buf_len, uint8_t * src, int len);
+
diff --git a/src/libffmpeg/libavutil/bswap.h b/contrib/ffmpeg/libavutil/bswap.h
index 03d613db2..03d613db2 100644
--- a/src/libffmpeg/libavutil/bswap.h
+++ b/contrib/ffmpeg/libavutil/bswap.h
diff --git a/contrib/ffmpeg/libavutil/common.h b/contrib/ffmpeg/libavutil/common.h
new file mode 100644
index 000000000..9ec5c7c78
--- /dev/null
+++ b/contrib/ffmpeg/libavutil/common.h
@@ -0,0 +1,326 @@
+/*
+ * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file common.h
+ * common internal and external api header.
+ */
+
+#ifndef COMMON_H
+#define COMMON_H
+
+#include <inttypes.h>
+
+#ifdef HAVE_AV_CONFIG_H
+/* only include the following when compiling package */
+# include "config.h"
+
+# include <stdlib.h>
+# include <stdio.h>
+# include <string.h>
+# include <ctype.h>
+# include <limits.h>
+# include <errno.h>
+# include <math.h>
+#endif /* HAVE_AV_CONFIG_H */
+
+#ifndef av_always_inline
+#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
+# define av_always_inline __attribute__((always_inline)) inline
+# define av_noinline __attribute__((noinline))
+#else
+# define av_always_inline inline
+# define av_noinline
+#endif
+#endif
+
+#ifdef HAVE_AV_CONFIG_H
+# include "internal.h"
+#endif /* HAVE_AV_CONFIG_H */
+
+#ifndef attribute_deprecated
+#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
+# define attribute_deprecated __attribute__((deprecated))
+#else
+# define attribute_deprecated
+#endif
+#endif
+
+#include "mem.h"
+
+//rounded divison & shift
+#define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b))
+/* assume b>0 */
+#define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))
+#define FFABS(a) ((a) >= 0 ? (a) : (-(a)))
+#define FFSIGN(a) ((a) > 0 ? 1 : -1)
+
+#define FFMAX(a,b) ((a) > (b) ? (a) : (b))
+#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
+
+#define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0)
+
+/* misc math functions */
+extern const uint8_t ff_log2_tab[256];
+
+static inline int av_log2(unsigned int v)
+{
+ int n;
+
+ n = 0;
+ if (v & 0xffff0000) {
+ v >>= 16;
+ n += 16;
+ }
+ if (v & 0xff00) {
+ v >>= 8;
+ n += 8;
+ }
+ n += ff_log2_tab[v];
+
+ return n;
+}
+
+static inline int av_log2_16bit(unsigned int v)
+{
+ int n;
+
+ n = 0;
+ if (v & 0xff00) {
+ v >>= 8;
+ n += 8;
+ }
+ n += ff_log2_tab[v];
+
+ return n;
+}
+
+/* median of 3 */
+static inline int mid_pred(int a, int b, int c)
+{
+#ifdef HAVE_CMOV
+ int i=b;
+ asm volatile(
+ "cmp %2, %1 \n\t"
+ "cmovg %1, %0 \n\t"
+ "cmovg %2, %1 \n\t"
+ "cmp %3, %1 \n\t"
+ "cmovl %3, %1 \n\t"
+ "cmp %1, %0 \n\t"
+ "cmovg %1, %0 \n\t"
+ :"+&r"(i), "+&r"(a)
+ :"r"(b), "r"(c)
+ );
+ return i;
+#elif 0
+ int t= (a-b)&((a-b)>>31);
+ a-=t;
+ b+=t;
+ b-= (b-c)&((b-c)>>31);
+ b+= (a-b)&((a-b)>>31);
+
+ return b;
+#else
+ if(a>b){
+ if(c>b){
+ if(c>a) b=a;
+ else b=c;
+ }
+ }else{
+ if(b>c){
+ if(c>a) b=c;
+ else b=a;
+ }
+ }
+ return b;
+#endif
+}
+
+/**
+ * clip a signed integer value into the amin-amax range
+ * @param a value to clip
+ * @param amin minimum value of the clip range
+ * @param amax maximum value of the clip range
+ * @return clipped value
+ */
+static inline int av_clip(int a, int amin, int amax)
+{
+ if (a < amin) return amin;
+ else if (a > amax) return amax;
+ else return a;
+}
+
+/**
+ * clip a signed integer value into the 0-255 range
+ * @param a value to clip
+ * @return clipped value
+ */
+static inline uint8_t av_clip_uint8(int a)
+{
+ if (a&(~255)) return (-a)>>31;
+ else return a;
+}
+
+/* math */
+int64_t ff_gcd(int64_t a, int64_t b);
+
+/**
+ * converts fourcc string to int
+ */
+static inline int ff_get_fourcc(const char *s){
+#ifdef HAVE_AV_CONFIG_H
+ assert( strlen(s)==4 );
+#endif
+
+ return (s[0]) + (s[1]<<8) + (s[2]<<16) + (s[3]<<24);
+}
+
+#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))
+
+/*!
+ * \def GET_UTF8(val, GET_BYTE, ERROR)
+ * converts a utf-8 character (up to 4 bytes long) 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_BYTE gets utf-8 encoded bytes from any proper source. It can be
+ * a function or a statement whose return value or evaluated value is of type
+ * uint8_t. It will be executed up to 4 times for values in the valid utf-8 range,
+ * and up to 7 times in the general case.
+ * \param ERROR action that should be taken when an invalid utf-8 byte 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_UTF8(val, GET_BYTE, ERROR)\
+ val= GET_BYTE;\
+ {\
+ int ones= 7 - av_log2(val ^ 255);\
+ if(ones==1)\
+ ERROR\
+ val&= 127>>ones;\
+ while(--ones > 0){\
+ int tmp= GET_BYTE - 128;\
+ if(tmp>>6)\
+ ERROR\
+ val= (val<<6) + tmp;\
+ }\
+ }
+
+/*!
+ * \def PUT_UTF8(val, tmp, PUT_BYTE)
+ * converts a 32-bit unicode character to its utf-8 encoded form (up to 4 bytes long).
+ * \param val is an input only argument and should be of type uint32_t. It holds
+ * a ucs4 encoded unicode character that is to be converted to utf-8. If
+ * val is given as a function it's executed only once.
+ * \param tmp is a temporary variable and should be of type uint8_t. It
+ * represents an intermediate value during conversion that is to be
+ * outputted by PUT_BYTE.
+ * \param PUT_BYTE writes the converted utf-8 bytes to any proper destination.
+ * 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 up to 4 times for values in the valid utf-8 range and up to
+ * 7 times in the general case, depending on the length of the converted
+ * unicode character.
+ */
+#define PUT_UTF8(val, tmp, PUT_BYTE)\
+ {\
+ int bytes, shift;\
+ uint32_t in = val;\
+ if (in < 0x80) {\
+ tmp = in;\
+ PUT_BYTE\
+ } else {\
+ bytes = (av_log2(in) + 4) / 5;\
+ shift = (bytes - 1) * 6;\
+ tmp = (256 - (256 >> bytes)) | (in >> shift);\
+ PUT_BYTE\
+ while (shift >= 6) {\
+ shift -= 6;\
+ tmp = 0x80 | ((in >> shift) & 0x3f);\
+ PUT_BYTE\
+ }\
+ }\
+ }
+
+#if defined(ARCH_X86) || defined(ARCH_POWERPC)
+#if defined(ARCH_X86_64)
+static inline uint64_t read_time(void)
+{
+ uint64_t a, d;
+ asm volatile( "rdtsc\n\t"
+ : "=a" (a), "=d" (d)
+ );
+ return (d << 32) | (a & 0xffffffff);
+}
+#elif defined(ARCH_X86_32)
+static inline long long read_time(void)
+{
+ long long l;
+ asm volatile( "rdtsc\n\t"
+ : "=A" (l)
+ );
+ return l;
+}
+#else //FIXME check ppc64
+static inline uint64_t read_time(void)
+{
+ uint32_t tbu, tbl, temp;
+
+ /* from section 2.2.1 of the 32-bit PowerPC PEM */
+ __asm__ __volatile__(
+ "1:\n"
+ "mftbu %2\n"
+ "mftb %0\n"
+ "mftbu %1\n"
+ "cmpw %2,%1\n"
+ "bne 1b\n"
+ : "=r"(tbl), "=r"(tbu), "=r"(temp)
+ :
+ : "cc");
+
+ return (((uint64_t)tbu)<<32) | (uint64_t)tbl;
+}
+#endif
+
+#define START_TIMER \
+uint64_t tend;\
+uint64_t tstart= read_time();\
+
+#define STOP_TIMER(id) \
+tend= read_time();\
+{\
+ static uint64_t tsum=0;\
+ static int tcount=0;\
+ static int tskip_count=0;\
+ if(tcount<2 || tend - tstart < FFMAX(8*tsum/tcount, 2000)){\
+ tsum+= tend - tstart;\
+ tcount++;\
+ }else\
+ tskip_count++;\
+ if(((tcount+tskip_count)&(tcount+tskip_count-1))==0){\
+ av_log(NULL, AV_LOG_DEBUG, "%"PRIu64" dezicycles in %s, %d runs, %d skips\n", tsum*10/tcount, id, tcount, tskip_count);\
+ }\
+}
+#else
+#define START_TIMER
+#define STOP_TIMER(id) {}
+#endif
+
+#endif /* COMMON_H */
diff --git a/contrib/ffmpeg/libavutil/crc.c b/contrib/ffmpeg/libavutil/crc.c
new file mode 100644
index 000000000..02fb860b8
--- /dev/null
+++ b/contrib/ffmpeg/libavutil/crc.c
@@ -0,0 +1,111 @@
+/*
+ * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "common.h"
+#include "crc.h"
+
+#if LIBAVUTIL_VERSION_INT < (50<<16)
+AVCRC *av_crcEDB88320;
+AVCRC *av_crc04C11DB7;
+AVCRC *av_crc8005 ;
+AVCRC *av_crc07 ;
+#else
+AVCRC av_crcEDB88320[257];
+AVCRC av_crc04C11DB7[257];
+AVCRC av_crc8005 [257];
+AVCRC av_crc07 [257];
+#endif
+
+/**
+ * Inits a crc table.
+ * @param ctx must be an array of sizeof(AVCRC)*257 or sizeof(AVCRC)*1024
+ * @param cts_size size of ctx in bytes
+ * @return <0 on failure
+ */
+int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size){
+ int i, j;
+ uint32_t c;
+
+ if (bits < 8 || bits > 32 || poly >= (1LL<<bits))
+ return -1;
+ if (ctx_size != sizeof(AVCRC)*257 && ctx_size != sizeof(AVCRC)*1024)
+ return -1;
+
+ for (i = 0; i < 256; i++) {
+ if (le) {
+ for (c = i, j = 0; j < 8; j++)
+ c = (c>>1)^(poly & (-(c&1)));
+ ctx[i] = c;
+ } else {
+ for (c = i << 24, j = 0; j < 8; j++)
+ c = (c<<1) ^ ((poly<<(32-bits)) & (((int32_t)c)>>31) );
+ ctx[i] = bswap_32(c);
+ }
+ }
+ ctx[256]=1;
+#ifndef CONFIG_SMALL
+ if(ctx_size >= sizeof(AVCRC)*1024)
+ for (i = 0; i < 256; i++)
+ for(j=0; j<3; j++)
+ ctx[256*(j+1) + i]= (ctx[256*j + i]>>8) ^ ctx[ ctx[256*j + i]&0xFF ];
+#endif
+
+ return 0;
+}
+
+uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length){
+ const uint8_t *end= buffer+length;
+
+#ifndef CONFIG_SMALL
+ if(!ctx[256])
+ while(buffer<end-3){
+ crc ^= le2me_32(*(uint32_t*)buffer); buffer+=4;
+ crc = ctx[3*256 + ( crc &0xFF)]
+ ^ctx[2*256 + ((crc>>8 )&0xFF)]
+ ^ctx[1*256 + ((crc>>16)&0xFF)]
+ ^ctx[0*256 + ((crc>>24) )];
+ }
+#endif
+ while(buffer<end)
+ crc = ctx[((uint8_t)crc) ^ *buffer++] ^ (crc >> 8);
+
+ return crc;
+}
+
+#ifdef TEST
+#undef printf
+main(){
+ uint8_t buf[1999];
+ int i;
+ int p[4][4]={{1, 32, 0xedb88320L, 0x3D5CDD04},
+ {0, 32, 0x04c11db7L, 0xC0F5BAE0},
+ {0, 16, 0x8005 , 0x1FBB },
+ {0, 8, 0x07 , 0xE3 },};
+ AVCRC ctx[1 ? 1024:257];
+
+ for(i=0; i<sizeof(buf); i++)
+ buf[i]= i+i*i;
+
+ for(i=0; i<4; i++){
+ av_crc_init(ctx, p[i][0], p[i][1], p[i][2], sizeof(ctx));
+ printf("crc %08X =%X\n", p[i][2], av_crc(ctx, 0, buf, sizeof(buf)));
+ }
+}
+#endif
diff --git a/contrib/ffmpeg/libavutil/crc.h b/contrib/ffmpeg/libavutil/crc.h
new file mode 100644
index 000000000..1f6431992
--- /dev/null
+++ b/contrib/ffmpeg/libavutil/crc.h
@@ -0,0 +1,42 @@
+/*
+ * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef CRC_H
+#define CRC_H
+
+typedef uint32_t AVCRC;
+
+#if LIBAVUTIL_VERSION_INT < (50<<16)
+extern AVCRC *av_crcEDB88320;
+extern AVCRC *av_crc04C11DB7;
+extern AVCRC *av_crc8005 ;
+extern AVCRC *av_crc07 ;
+#else
+extern AVCRC av_crcEDB88320[];
+extern AVCRC av_crc04C11DB7[];
+extern AVCRC av_crc8005 [];
+extern AVCRC av_crc07 [];
+#endif
+
+int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size);
+uint32_t av_crc(const AVCRC *ctx, uint32_t start_crc, const uint8_t *buffer, size_t length);
+
+#endif /* CRC_H */
+
diff --git a/contrib/ffmpeg/libavutil/fifo.c b/contrib/ffmpeg/libavutil/fifo.c
new file mode 100644
index 000000000..8ac3a0cb5
--- /dev/null
+++ b/contrib/ffmpeg/libavutil/fifo.c
@@ -0,0 +1,114 @@
+/*
+ * A very simple circular buffer FIFO implementation
+ * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
+ * Copyright (c) 2006 Roman Shaposhnik
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 "common.h"
+#include "fifo.h"
+
+int av_fifo_init(AVFifoBuffer *f, int size)
+{
+ f->wptr = f->rptr =
+ f->buffer = av_malloc(size);
+ f->end = f->buffer + size;
+ if (!f->buffer)
+ return -1;
+ return 0;
+}
+
+void av_fifo_free(AVFifoBuffer *f)
+{
+ av_free(f->buffer);
+}
+
+int av_fifo_size(AVFifoBuffer *f)
+{
+ int size = f->wptr - f->rptr;
+ if (size < 0)
+ size += f->end - f->buffer;
+ return size;
+}
+
+/**
+ * Get data from the fifo (returns -1 if not enough data).
+ */
+int av_fifo_read(AVFifoBuffer *f, uint8_t *buf, int buf_size)
+{
+ return av_fifo_generic_read(f, buf_size, NULL, buf);
+}
+
+/**
+ * Resizes a FIFO.
+ */
+void av_fifo_realloc(AVFifoBuffer *f, unsigned int new_size) {
+ unsigned int old_size= f->end - f->buffer;
+
+ if(old_size < new_size){
+ int len= av_fifo_size(f);
+ AVFifoBuffer f2;
+
+ av_fifo_init(&f2, new_size);
+ av_fifo_read(f, f2.buffer, len);
+ f2.wptr += len;
+ av_free(f->buffer);
+ *f= f2;
+ }
+}
+
+void av_fifo_write(AVFifoBuffer *f, const uint8_t *buf, int size)
+{
+ do {
+ int len = FFMIN(f->end - f->wptr, size);
+ memcpy(f->wptr, buf, len);
+ f->wptr += len;
+ if (f->wptr >= f->end)
+ f->wptr = f->buffer;
+ buf += len;
+ size -= len;
+ } while (size > 0);
+}
+
+
+/** get data from the fifo (return -1 if not enough data) */
+int av_fifo_generic_read(AVFifoBuffer *f, int buf_size, void (*func)(void*, void*, int), void* dest)
+{
+ int size = av_fifo_size(f);
+
+ if (size < buf_size)
+ return -1;
+ do {
+ int len = FFMIN(f->end - f->rptr, buf_size);
+ if(func) func(dest, f->rptr, len);
+ else{
+ memcpy(dest, f->rptr, len);
+ dest = (uint8_t*)dest + len;
+ }
+ av_fifo_drain(f, len);
+ buf_size -= len;
+ } while (buf_size > 0);
+ return 0;
+}
+
+/** discard data from the fifo */
+void av_fifo_drain(AVFifoBuffer *f, int size)
+{
+ f->rptr += size;
+ if (f->rptr >= f->end)
+ f->rptr -= f->end - f->buffer;
+}
diff --git a/contrib/ffmpeg/libavutil/fifo.h b/contrib/ffmpeg/libavutil/fifo.h
new file mode 100644
index 000000000..e1e85293d
--- /dev/null
+++ b/contrib/ffmpeg/libavutil/fifo.h
@@ -0,0 +1,100 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 fifo.h
+ * A very simple circular buffer FIFO implementation.
+ */
+
+#ifndef FIFO_H
+#define FIFO_H
+
+typedef struct AVFifoBuffer {
+ uint8_t *buffer;
+ uint8_t *rptr, *wptr, *end;
+} AVFifoBuffer;
+
+/**
+ * Initializes an AVFifoBuffer.
+ * @param *f AVFifoBuffer to initialize
+ * @param size of FIFO
+ * @return <0 for failure >=0 otherwise
+ */
+int av_fifo_init(AVFifoBuffer *f, int size);
+
+/**
+ * Frees an AVFifoBuffer.
+ * @param *f AVFifoBuffer to free
+ */
+void av_fifo_free(AVFifoBuffer *f);
+
+/**
+ * Returns the amount of data in bytes in the AVFifoBuffer, that is the
+ * amount of data you can read from it.
+ * @param *f AVFifoBuffer to read from
+ * @return size
+ */
+int av_fifo_size(AVFifoBuffer *f);
+
+/**
+ * Reads data from an AVFifoBuffer.
+ * @param *f AVFifoBuffer to read from
+ * @param *buf data destination
+ * @param buf_size number of bytes to read
+ */
+int av_fifo_read(AVFifoBuffer *f, uint8_t *buf, int buf_size);
+
+/**
+ * Feeds data from an AVFifoBuffer to a user supplied callback.
+ * @param *f AVFifoBuffer to read from
+ * @param buf_size number of bytes to read
+ * @param *func generic read function
+ * @param *dest data destination
+ */
+int av_fifo_generic_read(AVFifoBuffer *f, int buf_size, void (*func)(void*, void*, int), void* dest);
+
+/**
+ * Writes data into an AVFifoBuffer.
+ * @param *f AVFifoBuffer to write to
+ * @param *buf data source
+ * @param size data size
+ */
+void av_fifo_write(AVFifoBuffer *f, const uint8_t *buf, int size);
+
+/**
+ * Resizes an AVFifoBuffer.
+ * @param *f AVFifoBuffer to resize
+ * @param size new AVFifoBuffer size in bytes
+ */
+void av_fifo_realloc(AVFifoBuffer *f, unsigned int size);
+
+/**
+ * Reads and discards the specified amount of data from an AVFifoBuffer.
+ * @param *f AVFifoBuffer to read from
+ * @param size amount of data to read in bytes
+ */
+void av_fifo_drain(AVFifoBuffer *f, int size);
+
+static inline uint8_t av_fifo_peek(AVFifoBuffer *f, int offs)
+{
+ uint8_t *ptr = f->rptr + offs;
+ if (ptr >= f->end)
+ ptr -= f->end - f->buffer;
+ return *ptr;
+}
+#endif /* FIFO_H */
diff --git a/contrib/ffmpeg/libavutil/integer.c b/contrib/ffmpeg/libavutil/integer.c
new file mode 100644
index 000000000..3269a366a
--- /dev/null
+++ b/contrib/ffmpeg/libavutil/integer.c
@@ -0,0 +1,197 @@
+/*
+ * arbitrary precision integers
+ * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * @file integer.c
+ * arbitrary precision integers.
+ * @author Michael Niedermayer <michaelni@gmx.at>
+ */
+
+#include "common.h"
+#include "integer.h"
+
+AVInteger av_add_i(AVInteger a, AVInteger b){
+ int i, carry=0;
+
+ for(i=0; i<AV_INTEGER_SIZE; i++){
+ carry= (carry>>16) + a.v[i] + b.v[i];
+ a.v[i]= carry;
+ }
+ return a;
+}
+
+AVInteger av_sub_i(AVInteger a, AVInteger b){
+ int i, carry=0;
+
+ for(i=0; i<AV_INTEGER_SIZE; i++){
+ carry= (carry>>16) + a.v[i] - b.v[i];
+ a.v[i]= carry;
+ }
+ return a;
+}
+
+int av_log2_i(AVInteger a){
+ int i;
+
+ for(i=AV_INTEGER_SIZE-1; i>=0; i--){
+ if(a.v[i])
+ return av_log2_16bit(a.v[i]) + 16*i;
+ }
+ return -1;
+}
+
+AVInteger av_mul_i(AVInteger a, AVInteger b){
+ AVInteger out;
+ int i, j;
+ int na= (av_log2_i(a)+16) >> 4;
+ int nb= (av_log2_i(b)+16) >> 4;
+
+ memset(&out, 0, sizeof(out));
+
+ for(i=0; i<na; i++){
+ unsigned int carry=0;
+
+ if(a.v[i])
+ for(j=i; j<AV_INTEGER_SIZE && j-i<=nb; j++){
+ carry= (carry>>16) + out.v[j] + a.v[i]*b.v[j-i];
+ out.v[j]= carry;
+ }
+ }
+
+ return out;
+}
+
+int av_cmp_i(AVInteger a, AVInteger b){
+ int i;
+ int v= (int16_t)a.v[AV_INTEGER_SIZE-1] - (int16_t)b.v[AV_INTEGER_SIZE-1];
+ if(v) return (v>>16)|1;
+
+ for(i=AV_INTEGER_SIZE-2; i>=0; i--){
+ int v= a.v[i] - b.v[i];
+ if(v) return (v>>16)|1;
+ }
+ return 0;
+}
+
+AVInteger av_shr_i(AVInteger a, int s){
+ AVInteger out;
+ int i;
+
+ for(i=0; i<AV_INTEGER_SIZE; i++){
+ int index= i + (s>>4);
+ unsigned int v=0;
+ if(index+1<AV_INTEGER_SIZE && index+1>=0) v = a.v[index+1]<<16;
+ if(index <AV_INTEGER_SIZE && index >=0) v+= a.v[index ];
+ out.v[i]= v >> (s&15);
+ }
+ return out;
+}
+
+AVInteger av_mod_i(AVInteger *quot, AVInteger a, AVInteger b){
+ int i= av_log2_i(a) - av_log2_i(b);
+ AVInteger quot_temp;
+ if(!quot) quot = &quot_temp;
+
+ assert((int16_t)a[AV_INTEGER_SIZE-1] >= 0 && (int16_t)b[AV_INTEGER_SIZE-1] >= 0);
+ assert(av_log2(b)>=0);
+
+ if(i > 0)
+ b= av_shr_i(b, -i);
+
+ memset(quot, 0, sizeof(AVInteger));
+
+ while(i-- >= 0){
+ *quot= av_shr_i(*quot, -1);
+ if(av_cmp_i(a, b) >= 0){
+ a= av_sub_i(a, b);
+ quot->v[0] += 1;
+ }
+ b= av_shr_i(b, 1);
+ }
+ return a;
+}
+
+AVInteger av_div_i(AVInteger a, AVInteger b){
+ AVInteger quot;
+ av_mod_i(&quot, a, b);
+ return quot;
+}
+
+AVInteger av_int2i(int64_t a){
+ AVInteger out;
+ int i;
+
+ for(i=0; i<AV_INTEGER_SIZE; i++){
+ out.v[i]= a;
+ a>>=16;
+ }
+ return out;
+}
+
+int64_t av_i2int(AVInteger a){
+ int i;
+ int64_t out=(int8_t)a.v[AV_INTEGER_SIZE-1];
+
+ for(i= AV_INTEGER_SIZE-2; i>=0; i--){
+ out = (out<<16) + a.v[i];
+ }
+ return out;
+}
+
+#if 0
+#undef NDEBUG
+#include <assert.h>
+
+const uint8_t ff_log2_tab[256]={
+ 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
+ 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+ 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
+ 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
+ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
+ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
+ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
+ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
+};
+
+main(){
+ int64_t a,b;
+
+ for(a=7; a<256*256*256; a+=13215){
+ for(b=3; b<256*256*256; b+=27118){
+ AVInteger ai= av_int2i(a);
+ AVInteger bi= av_int2i(b);
+
+ assert(av_i2int(ai) == a);
+ assert(av_i2int(bi) == b);
+ assert(av_i2int(av_add_i(ai,bi)) == a+b);
+ assert(av_i2int(av_sub_i(ai,bi)) == a-b);
+ assert(av_i2int(av_mul_i(ai,bi)) == a*b);
+ assert(av_i2int(av_shr_i(ai, 9)) == a>>9);
+ assert(av_i2int(av_shr_i(ai,-9)) == a<<9);
+ assert(av_i2int(av_shr_i(ai, 17)) == a>>17);
+ assert(av_i2int(av_shr_i(ai,-17)) == a<<17);
+ assert(av_log2_i(ai) == av_log2(a));
+ assert(av_i2int(av_div_i(ai,bi)) == a/b);
+ }
+ }
+}
+#endif
diff --git a/contrib/ffmpeg/libavutil/integer.h b/contrib/ffmpeg/libavutil/integer.h
new file mode 100644
index 000000000..2a4d70316
--- /dev/null
+++ b/contrib/ffmpeg/libavutil/integer.h
@@ -0,0 +1,82 @@
+/*
+ * arbitrary precision integers
+ * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * @file integer.h
+ * arbitrary precision integers
+ * @author Michael Niedermayer <michaelni@gmx.at>
+ */
+
+#ifndef INTEGER_H
+#define INTEGER_H
+
+#define AV_INTEGER_SIZE 8
+
+typedef struct AVInteger{
+ uint16_t v[AV_INTEGER_SIZE];
+} AVInteger;
+
+AVInteger av_add_i(AVInteger a, AVInteger b);
+AVInteger av_sub_i(AVInteger a, AVInteger b);
+
+/**
+ * returns the rounded down value of the logarithm of base 2 of the given AVInteger.
+ * this is simply the index of the most significant bit which is 1. Or 0 of all bits are 0
+ */
+int av_log2_i(AVInteger a);
+AVInteger av_mul_i(AVInteger a, AVInteger b);
+
+/**
+ * returns 0 if a==b, 1 if a>b and -1 if a<b.
+ */
+int av_cmp_i(AVInteger a, AVInteger b);
+
+/**
+ * bitwise shift.
+ * @param s the number of bits by which the value should be shifted right, may be negative for shifting left
+ */
+AVInteger av_shr_i(AVInteger a, int s);
+
+/**
+ * returns a % b.
+ * @param quot a/b will be stored here
+ */
+AVInteger av_mod_i(AVInteger *quot, AVInteger a, AVInteger b);
+
+/**
+ * returns a/b.
+ */
+AVInteger av_div_i(AVInteger a, AVInteger b);
+
+/**
+ * converts the given int64_t to an AVInteger.
+ */
+AVInteger av_int2i(int64_t a);
+
+/**
+ * converts the given AVInteger to an int64_t.
+ * if the AVInteger is too large to fit into an int64_t,
+ * then only the least significant 64bit will be used
+ */
+int64_t av_i2int(AVInteger a);
+
+#endif // INTEGER_H
diff --git a/contrib/ffmpeg/libavutil/internal.h b/contrib/ffmpeg/libavutil/internal.h
new file mode 100644
index 000000000..eefbfa1e4
--- /dev/null
+++ b/contrib/ffmpeg/libavutil/internal.h
@@ -0,0 +1,293 @@
+/*
+ * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file internal.h
+ * common internal api header.
+ */
+
+#ifndef INTERNAL_H
+#define INTERNAL_H
+
+#ifndef attribute_used
+#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
+# define attribute_used __attribute__((used))
+#else
+# define attribute_used
+#endif
+#endif
+
+#ifndef attribute_unused
+#if defined(__GNUC__)
+# define attribute_unused __attribute__((unused))
+#else
+# define attribute_unused
+#endif
+#endif
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
+#ifndef INT16_MIN
+#define INT16_MIN (-0x7fff-1)
+#endif
+
+#ifndef INT16_MAX
+#define INT16_MAX 0x7fff
+#endif
+
+#ifndef INT32_MIN
+#define INT32_MIN (-0x7fffffff-1)
+#endif
+
+#ifndef INT32_MAX
+#define INT32_MAX 0x7fffffff
+#endif
+
+#ifndef UINT32_MAX
+#define UINT32_MAX 0xffffffff
+#endif
+
+#ifndef INT64_MIN
+#define INT64_MIN (-0x7fffffffffffffffLL-1)
+#endif
+
+#ifndef INT64_MAX
+#define INT64_MAX INT64_C(9223372036854775807)
+#endif
+
+#ifndef UINT64_MAX
+#define UINT64_MAX UINT64_C(0xFFFFFFFFFFFFFFFF)
+#endif
+
+#ifndef INT_BIT
+# if INT_MAX != 2147483647
+# define INT_BIT 64
+# else
+# define INT_BIT 32
+# endif
+#endif
+
+#if ( defined(__PIC__) || defined(__pic__) ) && ! defined(PIC)
+# define PIC
+#endif
+
+#include "intreadwrite.h"
+#include "bswap.h"
+
+#include <stddef.h>
+#ifndef offsetof
+# define offsetof(T,F) ((unsigned int)((char *)&((T *)0)->F))
+#endif
+
+#ifdef __MINGW32__
+# ifdef _DEBUG
+# define DEBUG
+# endif
+
+# define snprintf _snprintf
+# define vsnprintf _vsnprintf
+
+# ifdef CONFIG_WINCE
+# define perror(a)
+# define abort()
+# endif
+
+/* __MINGW32__ end */
+#elif defined (CONFIG_OS2)
+/* OS/2 EMX */
+
+# include <float.h>
+
+#endif /* !__MINGW32__ && CONFIG_OS2 */
+
+#ifdef USE_FASTMEMCPY
+# include "libvo/fastmemcpy.h"
+#endif
+
+// Use rip-relative addressing if compiling PIC code on x86-64.
+#if defined(__MINGW32__) || defined(__CYGWIN__) || \
+ defined(__OS2__) || (defined (__OpenBSD__) && !defined(__ELF__))
+# if defined(ARCH_X86_64) && defined(PIC)
+# define MANGLE(a) "_" #a"(%%rip)"
+# else
+# define MANGLE(a) "_" #a
+# endif
+#else
+# if defined(ARCH_X86_64) && defined(PIC)
+# define MANGLE(a) #a"(%%rip)"
+# elif defined(CONFIG_DARWIN)
+# define MANGLE(a) "_" #a
+# else
+# define MANGLE(a) #a
+# endif
+#endif
+
+/* debug stuff */
+
+#if !defined(DEBUG) && !defined(NDEBUG)
+# define NDEBUG
+#endif
+#include <assert.h>
+
+/* dprintf macros */
+#ifdef DEBUG
+# define dprintf(pctx, ...) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__)
+#else
+# define dprintf(pctx, ...)
+#endif
+
+#define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0)
+
+/* math */
+
+extern const uint32_t ff_inverse[256];
+
+#if defined(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 defined(ARCH_ARMV4L)
+# define FASTDIV(a,b) \
+ ({\
+ int ret,dmy;\
+ asm volatile(\
+ "umull %1, %0, %2, %3"\
+ :"=&r"(ret),"=&r"(dmy)\
+ :"r"(a),"r"(ff_inverse[b])\
+ );\
+ ret;\
+ })
+#elif defined(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[128];
+
+static inline int ff_sqrt(int a)
+{
+ int ret=0;
+ int s;
+ int ret_sq=0;
+
+ if(a<128) return ff_sqrt_tab[a];
+
+ for(s=15; s>=0; s--){
+ int b= ret_sq + (1<<(s*2)) + (ret<<s)*2;
+ if(b<=a){
+ ret_sq=b;
+ ret+= 1<<s;
+ }
+ }
+ return ret;
+}
+
+#if defined(ARCH_X86)
+#define MASK_ABS(mask, level)\
+ asm volatile(\
+ "cdq \n\t"\
+ "xorl %1, %0 \n\t"\
+ "subl %1, %0 \n\t"\
+ : "+a" (level), "=&d" (mask)\
+ );
+#else
+#define MASK_ABS(mask, level)\
+ mask= level>>31;\
+ level= (level^mask)-mask;
+#endif
+
+#ifdef 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);\
+}
+#endif
+
+/* avoid usage of various functions */
+#define malloc please_use_av_malloc
+#define free please_use_av_free
+#define realloc please_use_av_realloc
+#define time time_is_forbidden_due_to_security_issues
+#define rand rand_is_forbidden_due_to_state_trashing
+#define srand srand_is_forbidden_due_to_state_trashing
+#define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf
+#define strcat strcat_is_forbidden_due_to_security_issues_use_pstrcat
+#define exit exit_is_forbidden
+#if !(defined(LIBAVFORMAT_BUILD) || defined(_FRAMEHOOK_H))
+#define printf please_use_av_log
+#define fprintf please_use_av_log
+#endif
+
+#define CHECKED_ALLOCZ(p, size)\
+{\
+ p= av_mallocz(size);\
+ if(p==NULL && (size)!=0){\
+ perror("malloc");\
+ goto fail;\
+ }\
+}
+
+#ifndef HAVE_LRINTF
+/* XXX: add ISOC specific test to avoid specific BSD testing. */
+/* better than nothing implementation. */
+/* btw, rintf() is existing on fbsd too -- alex */
+static av_always_inline long int lrintf(float x)
+{
+#ifdef __MINGW32__
+# ifdef ARCH_X86_32
+ int32_t i;
+ asm volatile(
+ "fistpl %0\n\t"
+ : "=m" (i) : "t" (x) : "st"
+ );
+ return i;
+# else
+ /* XXX: incorrect, but make it compile */
+ return (int)(x + (x < 0 ? -0.5 : 0.5));
+# endif /* ARCH_X86_32 */
+#else
+ return (int)(rint(x));
+#endif /* __MINGW32__ */
+}
+#endif /* HAVE_LRINTF */
+
+#endif /* INTERNAL_H */
diff --git a/contrib/ffmpeg/libavutil/intfloat_readwrite.c b/contrib/ffmpeg/libavutil/intfloat_readwrite.c
new file mode 100644
index 000000000..261cf76c3
--- /dev/null
+++ b/contrib/ffmpeg/libavutil/intfloat_readwrite.c
@@ -0,0 +1,97 @@
+/*
+ * portable IEEE float/double read/write functions
+ *
+ * Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file intfloat_readwrite.c
+ * Portable IEEE float/double read/write functions.
+ */
+
+#include "common.h"
+#include "intfloat_readwrite.h"
+
+double av_int2dbl(int64_t v){
+ if(v+v > 0xFFEULL<<52)
+ return 0.0/0.0;
+ return ldexp(((v&((1LL<<52)-1)) + (1LL<<52)) * (v>>63|1), (v>>52&0x7FF)-1075);
+}
+
+float av_int2flt(int32_t v){
+ if(v+v > 0xFF000000U)
+ return 0.0/0.0;
+ return ldexp(((v&0x7FFFFF) + (1<<23)) * (v>>31|1), (v>>23&0xFF)-150);
+}
+
+double av_ext2dbl(const AVExtFloat ext){
+ uint64_t m = 0;
+ int e, i;
+
+ for (i = 0; i < 8; i++)
+ m = (m<<8) + ext.mantissa[i];
+ e = (((int)ext.exponent[0]&0x7f)<<8) | ext.exponent[1];
+ if (e == 0x7fff && m)
+ return 0.0/0.0;
+ e -= 16383 + 63; /* In IEEE 80 bits, the whole (i.e. 1.xxxx)
+ * mantissa bit is written as opposed to the
+ * single and double precision formats */
+ if (ext.exponent[0]&0x80)
+ m= -m;
+ return ldexp(m, e);
+}
+
+int64_t av_dbl2int(double d){
+ int e;
+ if ( !d) return 0;
+ else if(d-d) return 0x7FF0000000000000LL + ((int64_t)(d<0)<<63) + (d!=d);
+ d= frexp(d, &e);
+ return (int64_t)(d<0)<<63 | (e+1022LL)<<52 | (int64_t)((fabs(d)-0.5)*(1LL<<53));
+}
+
+int32_t av_flt2int(float d){
+ int e;
+ if ( !d) return 0;
+ else if(d-d) return 0x7F800000 + ((d<0)<<31) + (d!=d);
+ d= frexp(d, &e);
+ return (d<0)<<31 | (e+126)<<23 | (int64_t)((fabs(d)-0.5)*(1<<24));
+}
+
+AVExtFloat av_dbl2ext(double d){
+ struct AVExtFloat ext= {{0}};
+ int e, i; double f; uint64_t m;
+
+ f = fabs(frexp(d, &e));
+ if (f >= 0.5 && f < 1) {
+ e += 16382;
+ ext.exponent[0] = e>>8;
+ ext.exponent[1] = e;
+ m = (uint64_t)ldexp(f, 64);
+ for (i=0; i < 8; i++)
+ ext.mantissa[i] = m>>(56-(i<<3));
+ } else if (f != 0.0) {
+ ext.exponent[0] = 0x7f; ext.exponent[1] = 0xff;
+ if (f != 1/0.0)
+ ext.mantissa[0] = ~0;
+ }
+ if (d < 0)
+ ext.exponent[0] |= 0x80;
+ return ext;
+}
+
diff --git a/src/libffmpeg/libavutil/intfloat_readwrite.h b/contrib/ffmpeg/libavutil/intfloat_readwrite.h
index c535b64c8..c535b64c8 100644
--- a/src/libffmpeg/libavutil/intfloat_readwrite.h
+++ b/contrib/ffmpeg/libavutil/intfloat_readwrite.h
diff --git a/contrib/ffmpeg/libavutil/intreadwrite.h b/contrib/ffmpeg/libavutil/intreadwrite.h
new file mode 100644
index 000000000..7225f0b67
--- /dev/null
+++ b/contrib/ffmpeg/libavutil/intreadwrite.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 INTREADWRITE_H
+#define INTREADWRITE_H
+
+#ifdef __GNUC__
+
+struct unaligned_64 { uint64_t l; } __attribute__((packed));
+struct unaligned_32 { uint32_t l; } __attribute__((packed));
+struct unaligned_16 { uint16_t l; } __attribute__((packed));
+
+#define LD16(a) (((const struct unaligned_16 *) (a))->l)
+#define LD32(a) (((const struct unaligned_32 *) (a))->l)
+#define LD64(a) (((const struct unaligned_64 *) (a))->l)
+
+#define ST16(a, b) (((struct unaligned_16 *) (a))->l) = (b)
+#define ST32(a, b) (((struct unaligned_32 *) (a))->l) = (b)
+
+#else /* __GNUC__ */
+
+#define LD16(a) (*((uint16_t*)(a)))
+#define LD32(a) (*((uint32_t*)(a)))
+#define LD64(a) (*((uint64_t*)(a)))
+
+#define ST16(a, b) *((uint16_t*)(a)) = (b)
+#define ST32(a, b) *((uint32_t*)(a)) = (b)
+
+#endif /* !__GNUC__ */
+
+/* endian macros */
+#define AV_RB8(x) (((uint8_t*)(x))[0])
+#define AV_WB8(p, d) { ((uint8_t*)(p))[0] = (d); }
+
+#define AV_RB16(x) ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1])
+#define AV_WB16(p, d) { \
+ ((uint8_t*)(p))[1] = (d); \
+ ((uint8_t*)(p))[0] = (d)>>8; }
+
+#define AV_RB24(x) ((((uint8_t*)(x))[0] << 16) | \
+ (((uint8_t*)(x))[1] << 8) | \
+ ((uint8_t*)(x))[2])
+#define AV_WB24(p, d) { \
+ ((uint8_t*)(p))[2] = (d); \
+ ((uint8_t*)(p))[1] = (d)>>8; \
+ ((uint8_t*)(p))[0] = (d)>>16; }
+
+#define AV_RB32(x) ((((uint8_t*)(x))[0] << 24) | \
+ (((uint8_t*)(x))[1] << 16) | \
+ (((uint8_t*)(x))[2] << 8) | \
+ ((uint8_t*)(x))[3])
+#define AV_WB32(p, d) { \
+ ((uint8_t*)(p))[3] = (d); \
+ ((uint8_t*)(p))[2] = (d)>>8; \
+ ((uint8_t*)(p))[1] = (d)>>16; \
+ ((uint8_t*)(p))[0] = (d)>>24; }
+
+#define AV_RL8(x) AV_RB8(x)
+#define AV_WL8(p, d) AV_WB8(p, d)
+
+#define AV_RL16(x) ((((uint8_t*)(x))[1] << 8) | ((uint8_t*)(x))[0])
+#define AV_WL16(p, d) { \
+ ((uint8_t*)(p))[0] = (d); \
+ ((uint8_t*)(p))[1] = (d)>>8; }
+
+#define AV_RL24(x) ((((uint8_t*)(x))[2] << 16) | \
+ (((uint8_t*)(x))[1] << 8) | \
+ ((uint8_t*)(x))[0])
+#define AV_WL24(p, d) { \
+ ((uint8_t*)(p))[0] = (d); \
+ ((uint8_t*)(p))[1] = (d)>>8; \
+ ((uint8_t*)(p))[2] = (d)>>16; }
+
+#define AV_RL32(x) ((((uint8_t*)(x))[3] << 24) | \
+ (((uint8_t*)(x))[2] << 16) | \
+ (((uint8_t*)(x))[1] << 8) | \
+ ((uint8_t*)(x))[0])
+#define AV_WL32(p, d) { \
+ ((uint8_t*)(p))[0] = (d); \
+ ((uint8_t*)(p))[1] = (d)>>8; \
+ ((uint8_t*)(p))[2] = (d)>>16; \
+ ((uint8_t*)(p))[3] = (d)>>24; }
+
+#endif /* INTREADWRITE_H */
diff --git a/src/libffmpeg/libavutil/lls.c b/contrib/ffmpeg/libavutil/lls.c
index aa9467dce..aa9467dce 100644
--- a/src/libffmpeg/libavutil/lls.c
+++ b/contrib/ffmpeg/libavutil/lls.c
diff --git a/src/libffmpeg/libavutil/lls.h b/contrib/ffmpeg/libavutil/lls.h
index 59ad2e958..59ad2e958 100644
--- a/src/libffmpeg/libavutil/lls.h
+++ b/contrib/ffmpeg/libavutil/lls.h
diff --git a/src/libffmpeg/libavutil/log.c b/contrib/ffmpeg/libavutil/log.c
index 4fd503d0d..4fd503d0d 100644
--- a/src/libffmpeg/libavutil/log.c
+++ b/contrib/ffmpeg/libavutil/log.c
diff --git a/contrib/ffmpeg/libavutil/log.h b/contrib/ffmpeg/libavutil/log.h
new file mode 100644
index 000000000..fa88f5fb2
--- /dev/null
+++ b/contrib/ffmpeg/libavutil/log.h
@@ -0,0 +1,116 @@
+/*
+ * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef LOG_H
+#define LOG_H
+
+#include <stdarg.h>
+
+/**
+ * Used by av_log
+ */
+typedef struct AVCLASS AVClass;
+struct AVCLASS {
+ const char* class_name;
+ const char* (*item_name)(void*); /* actually passing a pointer to an AVCodecContext
+ or AVFormatContext, which begin with an AVClass.
+ Needed because av_log is in libavcodec and has no visibility
+ of AVIn/OutputFormat */
+ const struct AVOption *option;
+};
+
+/* av_log API */
+
+#if LIBAVUTIL_VERSION_INT < (50<<16)
+#define AV_LOG_QUIET -1
+#define AV_LOG_FATAL 0
+#define AV_LOG_ERROR 0
+#define AV_LOG_WARNING 1
+#define AV_LOG_INFO 1
+#define AV_LOG_VERBOSE 1
+#define AV_LOG_DEBUG 2
+#else
+#define AV_LOG_QUIET -8
+
+/**
+ * something went really wrong and we will crash now
+ */
+#define AV_LOG_PANIC 0
+
+/**
+ * something went wrong and recovery is not possible
+ * like no header in a format which depends on it or a combination
+ * of parameters which are not allowed
+ */
+#define AV_LOG_FATAL 8
+
+/**
+ * something went wrong and cannot losslessly be recovered
+ * but not all future data is affected
+ */
+#define AV_LOG_ERROR 16
+
+/**
+ * something somehow does not look correct / something which may or may not
+ * lead to some problems like use of -vstrict -2
+ */
+#define AV_LOG_WARNING 24
+
+#define AV_LOG_INFO 32
+#define AV_LOG_VERBOSE 40
+
+/**
+ * stuff which is only useful for libav* developers
+ */
+#define AV_LOG_DEBUG 48
+#endif
+extern int av_log_level;
+
+/**
+ * Send the specified message to the log if the level is less than or equal to
+ * the current av_log_level. By default, all logging messages are sent to
+ * stderr. This behavior can be altered by setting a different av_vlog callback
+ * function.
+ *
+ * @param avcl A pointer to an arbitrary struct of which the first field is a
+ * pointer to an AVClass struct.
+ * @param level The importance level of the message, lower values signifying
+ * higher importance.
+ * @param fmt The format string (printf-compatible) that specifies how
+ * subsequent arguments are converted to output.
+ * @see av_vlog
+ */
+#ifdef __GNUC__
+extern void av_log(void*, int level, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 3, 4)));
+#else
+extern void av_log(void*, int level, const char *fmt, ...);
+#endif
+
+#if LIBAVUTIL_VERSION_INT < (50<<16)
+extern void av_vlog(void*, int level, const char *fmt, va_list);
+extern int av_log_get_level(void);
+extern void av_log_set_level(int);
+extern void av_log_set_callback(void (*)(void*, int, const char*, va_list));
+extern void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl);
+#else
+extern void (*av_vlog)(void*, int, const char*, va_list);
+#endif
+
+#endif /* LOG_H */
diff --git a/contrib/ffmpeg/libavutil/lzo.c b/contrib/ffmpeg/libavutil/lzo.c
new file mode 100644
index 000000000..d3849a743
--- /dev/null
+++ b/contrib/ffmpeg/libavutil/lzo.c
@@ -0,0 +1,273 @@
+/*
+ * LZO 1x decompression
+ * Copyright (c) 2006 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 "common.h"
+//! avoid e.g. MPlayers fast_memcpy, it slows things down here
+#undef memcpy
+#include <string.h>
+#include "lzo.h"
+
+//! define if we may write up to 12 bytes beyond the output buffer
+#define OUTBUF_PADDED 1
+//! define if we may read up to 8 bytes beyond the input buffer
+#define INBUF_PADDED 1
+typedef struct LZOContext {
+ uint8_t *in, *in_end;
+ uint8_t *out_start, *out, *out_end;
+ int error;
+} LZOContext;
+
+/**
+ * \brief read one byte from input buffer, avoiding overrun
+ * \return byte read
+ */
+static inline int get_byte(LZOContext *c) {
+ if (c->in < c->in_end)
+ return *c->in++;
+ c->error |= LZO_INPUT_DEPLETED;
+ return 1;
+}
+
+#ifdef INBUF_PADDED
+#define GETB(c) (*(c).in++)
+#else
+#define GETB(c) get_byte(&(c))
+#endif
+
+/**
+ * \brief decode a length value in the coding used by lzo
+ * \param x previous byte value
+ * \param mask bits used from x
+ * \return decoded length value
+ */
+static inline int get_len(LZOContext *c, int x, int mask) {
+ int cnt = x & mask;
+ if (!cnt) {
+ while (!(x = get_byte(c))) cnt += 255;
+ cnt += mask + x;
+ }
+ return cnt;
+}
+
+//#define UNALIGNED_LOADSTORE
+#define BUILTIN_MEMCPY
+#ifdef UNALIGNED_LOADSTORE
+#define COPY2(d, s) *(uint16_t *)(d) = *(uint16_t *)(s);
+#define COPY4(d, s) *(uint32_t *)(d) = *(uint32_t *)(s);
+#elif defined(BUILTIN_MEMCPY)
+#define COPY2(d, s) memcpy(d, s, 2);
+#define COPY4(d, s) memcpy(d, s, 4);
+#else
+#define COPY2(d, s) (d)[0] = (s)[0]; (d)[1] = (s)[1];
+#define COPY4(d, s) (d)[0] = (s)[0]; (d)[1] = (s)[1]; (d)[2] = (s)[2]; (d)[3] = (s)[3];
+#endif
+
+/**
+ * \brief copy bytes from input to output buffer with checking
+ * \param cnt number of bytes to copy, must be >= 0
+ */
+static inline void copy(LZOContext *c, int cnt) {
+ register uint8_t *src = c->in;
+ register uint8_t *dst = c->out;
+ if (cnt > c->in_end - src) {
+ cnt = FFMAX(c->in_end - src, 0);
+ c->error |= LZO_INPUT_DEPLETED;
+ }
+ if (cnt > c->out_end - dst) {
+ cnt = FFMAX(c->out_end - dst, 0);
+ c->error |= LZO_OUTPUT_FULL;
+ }
+#if defined(INBUF_PADDED) && defined(OUTBUF_PADDED)
+ COPY4(dst, src);
+ src += 4;
+ dst += 4;
+ cnt -= 4;
+ if (cnt > 0)
+#endif
+ memcpy(dst, src, cnt);
+ c->in = src + cnt;
+ c->out = dst + cnt;
+}
+
+/**
+ * \brief copy previously decoded bytes to current position
+ * \param back how many bytes back we start
+ * \param cnt number of bytes to copy, must be >= 0
+ *
+ * cnt > back is valid, this will copy the bytes we just copied,
+ * thus creating a repeating pattern with a period length of back.
+ */
+static inline void copy_backptr(LZOContext *c, int back, int cnt) {
+ register uint8_t *src = &c->out[-back];
+ register uint8_t *dst = c->out;
+ if (src < c->out_start || src > dst) {
+ c->error |= LZO_INVALID_BACKPTR;
+ return;
+ }
+ if (cnt > c->out_end - dst) {
+ cnt = FFMAX(c->out_end - dst, 0);
+ c->error |= LZO_OUTPUT_FULL;
+ }
+ if (back == 1) {
+ memset(dst, *src, cnt);
+ dst += cnt;
+ } else {
+#ifdef OUTBUF_PADDED
+ COPY2(dst, src);
+ COPY2(dst + 2, src + 2);
+ src += 4;
+ dst += 4;
+ cnt -= 4;
+ if (cnt > 0) {
+ COPY2(dst, src);
+ COPY2(dst + 2, src + 2);
+ COPY2(dst + 4, src + 4);
+ COPY2(dst + 6, src + 6);
+ src += 8;
+ dst += 8;
+ cnt -= 8;
+ }
+#endif
+ if (cnt > 0) {
+ int blocklen = back;
+ while (cnt > blocklen) {
+ memcpy(dst, src, blocklen);
+ dst += blocklen;
+ cnt -= blocklen;
+ blocklen <<= 1;
+ }
+ memcpy(dst, src, cnt);
+ }
+ dst += cnt;
+ }
+ c->out = dst;
+}
+
+/**
+ * \brief decode LZO 1x compressed data
+ * \param out output buffer
+ * \param outlen size of output buffer, number of bytes left are returned here
+ * \param in input buffer
+ * \param inlen size of input buffer, number of bytes left are returned here
+ * \return 0 on success, otherwise error flags, see lzo.h
+ *
+ * make sure all buffers are appropriately padded, in must provide
+ * LZO_INPUT_PADDING, out must provide LZO_OUTPUT_PADDING additional bytes
+ */
+int lzo1x_decode(void *out, int *outlen, void *in, int *inlen) {
+ int state= 0;
+ int x;
+ LZOContext c;
+ c.in = in;
+ c.in_end = (uint8_t *)in + *inlen;
+ c.out = c.out_start = out;
+ c.out_end = (uint8_t *)out + * outlen;
+ c.error = 0;
+ x = GETB(c);
+ if (x > 17) {
+ copy(&c, x - 17);
+ x = GETB(c);
+ if (x < 16) c.error |= LZO_ERROR;
+ }
+ if (c.in > c.in_end)
+ c.error |= LZO_INPUT_DEPLETED;
+ while (!c.error) {
+ int cnt, back;
+ if (x > 15) {
+ if (x > 63) {
+ cnt = (x >> 5) - 1;
+ back = (GETB(c) << 3) + ((x >> 2) & 7) + 1;
+ } else if (x > 31) {
+ cnt = get_len(&c, x, 31);
+ x = GETB(c);
+ back = (GETB(c) << 6) + (x >> 2) + 1;
+ } else {
+ cnt = get_len(&c, x, 7);
+ back = (1 << 14) + ((x & 8) << 11);
+ x = GETB(c);
+ back += (GETB(c) << 6) + (x >> 2);
+ if (back == (1 << 14)) {
+ if (cnt != 1)
+ c.error |= LZO_ERROR;
+ break;
+ }
+ }
+ } else if(!state){
+ cnt = get_len(&c, x, 15);
+ copy(&c, cnt + 3);
+ x = GETB(c);
+ if (x > 15)
+ continue;
+ cnt = 1;
+ back = (1 << 11) + (GETB(c) << 2) + (x >> 2) + 1;
+ } else {
+ cnt = 0;
+ back = (GETB(c) << 2) + (x >> 2) + 1;
+ }
+ copy_backptr(&c, back, cnt + 2);
+ state=
+ cnt = x & 3;
+ copy(&c, cnt);
+ x = GETB(c);
+ }
+ *inlen = c.in_end - c.in;
+ if (c.in > c.in_end)
+ *inlen = 0;
+ *outlen = c.out_end - c.out;
+ return c.error;
+}
+
+#ifdef TEST
+#include <stdio.h>
+#include <lzo/lzo1x.h>
+#include "log.h"
+#define MAXSZ (10*1024*1024)
+int main(int argc, char *argv[]) {
+ FILE *in = fopen(argv[1], "rb");
+ uint8_t *orig = av_malloc(MAXSZ + 16);
+ uint8_t *comp = av_malloc(2*MAXSZ + 16);
+ uint8_t *decomp = av_malloc(MAXSZ + 16);
+ size_t s = fread(orig, 1, MAXSZ, in);
+ lzo_uint clen = 0;
+ long tmp[LZO1X_MEM_COMPRESS];
+ int inlen, outlen;
+ int i;
+ av_log_level = AV_LOG_DEBUG;
+ lzo1x_999_compress(orig, s, comp, &clen, tmp);
+ for (i = 0; i < 300; i++) {
+START_TIMER
+ inlen = clen; outlen = MAXSZ;
+#ifdef LIBLZO
+ if (lzo1x_decompress_safe(comp, inlen, decomp, &outlen, NULL))
+#elif defined(LIBLZO_UNSAFE)
+ if (lzo1x_decompress(comp, inlen, decomp, &outlen, NULL))
+#else
+ if (lzo1x_decode(decomp, &outlen, comp, &inlen))
+#endif
+ av_log(NULL, AV_LOG_ERROR, "decompression error\n");
+STOP_TIMER("lzod")
+ }
+ if (memcmp(orig, decomp, s))
+ av_log(NULL, AV_LOG_ERROR, "decompression incorrect\n");
+ else
+ av_log(NULL, AV_LOG_ERROR, "decompression ok\n");
+ return 0;
+}
+#endif
diff --git a/src/libffmpeg/libavcodec/lzo.h b/contrib/ffmpeg/libavutil/lzo.h
index 5b3d98f40..5b3d98f40 100644
--- a/src/libffmpeg/libavcodec/lzo.h
+++ b/contrib/ffmpeg/libavutil/lzo.h
diff --git a/src/libffmpeg/libavutil/mathematics.c b/contrib/ffmpeg/libavutil/mathematics.c
index 4be027d9d..4be027d9d 100644
--- a/src/libffmpeg/libavutil/mathematics.c
+++ b/contrib/ffmpeg/libavutil/mathematics.c
diff --git a/src/libffmpeg/libavutil/mathematics.h b/contrib/ffmpeg/libavutil/mathematics.h
index 0b74b254b..0b74b254b 100644
--- a/src/libffmpeg/libavutil/mathematics.h
+++ b/contrib/ffmpeg/libavutil/mathematics.h
diff --git a/contrib/ffmpeg/libavutil/md5.c b/contrib/ffmpeg/libavutil/md5.c
new file mode 100644
index 000000000..f71703124
--- /dev/null
+++ b/contrib/ffmpeg/libavutil/md5.c
@@ -0,0 +1,180 @@
+/*
+ * Copyright (C) 2006 Michael Niedermayer (michaelni@gmx.at)
+ * Copyright (C) 2003-2005 by Christopher R. Hertel (crh@ubiqx.mn.org)
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * References:
+ * IETF RFC 1321: The MD5 Message-Digest Algorithm
+ * Ron Rivest. IETF, April, 1992
+ *
+ * based on http://ubiqx.org/libcifs/source/Auth/MD5.c
+ * from Christopher R. Hertel (crh@ubiqx.mn.org)
+ * simplified, cleaned and IMO redundant comments removed by michael
+ *
+ * if you use gcc, then version 4.1 or later and -fomit-frame-pointer is
+ * strongly recommended
+ */
+
+#include "common.h"
+#include <string.h>
+#include "md5.h"
+
+typedef struct AVMD5{
+ uint64_t len;
+ uint8_t block[64];
+ uint32_t ABCD[4];
+} AVMD5;
+
+const int av_md5_size= sizeof(AVMD5);
+
+static const uint8_t S[4][4] = {
+ { 7, 12, 17, 22 }, /* Round 1 */
+ { 5, 9, 14, 20 }, /* Round 2 */
+ { 4, 11, 16, 23 }, /* Round 3 */
+ { 6, 10, 15, 21 } /* Round 4 */
+};
+
+static const uint32_t T[64] = { // T[i]= fabs(sin(i+1)<<32)
+ 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, /* Round 1 */
+ 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
+ 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
+ 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
+
+ 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, /* Round 2 */
+ 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,
+ 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
+ 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
+
+ 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, /* Round 3 */
+ 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
+ 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05,
+ 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
+
+ 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, /* Round 4 */
+ 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
+ 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
+ 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391,
+};
+
+#define CORE(i, a, b, c, d) \
+ t = S[i>>4][i&3];\
+ a += T[i];\
+\
+ if(i<32){\
+ if(i<16) a += (d ^ (b&(c^d))) + X[ i &15 ];\
+ else a += (c ^ (d&(c^b))) + X[ (1+5*i)&15 ];\
+ }else{\
+ if(i<48) a += (b^c^d) + X[ (5+3*i)&15 ];\
+ else a += (c^(b|~d)) + X[ ( 7*i)&15 ];\
+ }\
+ a = b + (( a << t ) | ( a >> (32 - t) ));
+
+static void body(uint32_t ABCD[4], uint32_t X[16]){
+
+ int t;
+ int i attribute_unused;
+ unsigned int a= ABCD[3];
+ unsigned int b= ABCD[2];
+ unsigned int c= ABCD[1];
+ unsigned int d= ABCD[0];
+
+#ifdef WORDS_BIGENDIAN
+ for(i=0; i<16; i++)
+ X[i]= bswap_32(X[i]);
+#endif
+
+#ifdef CONFIG_SMALL
+ for( i = 0; i < 64; i++ ){
+ CORE(i,a,b,c,d)
+ t=d; d=c; c=b; b=a; a=t;
+ }
+#else
+#define CORE2(i) CORE(i,a,b,c,d) CORE((i+1),d,a,b,c) CORE((i+2),c,d,a,b) CORE((i+3),b,c,d,a)
+#define CORE4(i) CORE2(i) CORE2((i+4)) CORE2((i+8)) CORE2((i+12))
+CORE4(0) CORE4(16) CORE4(32) CORE4(48)
+#endif
+
+ ABCD[0] += d;
+ ABCD[1] += c;
+ ABCD[2] += b;
+ ABCD[3] += a;
+}
+
+void av_md5_init(AVMD5 *ctx){
+ ctx->len = 0;
+
+ ctx->ABCD[0] = 0x10325476;
+ ctx->ABCD[1] = 0x98badcfe;
+ ctx->ABCD[2] = 0xefcdab89;
+ ctx->ABCD[3] = 0x67452301;
+}
+
+void av_md5_update(AVMD5 *ctx, const uint8_t *src, const int len){
+ int i, j;
+
+ j= ctx->len & 63;
+ ctx->len += len;
+
+ for( i = 0; i < len; i++ ){
+ ctx->block[j++] = src[i];
+ if( 64 == j ){
+ body(ctx->ABCD, (uint32_t*) ctx->block);
+ j = 0;
+ }
+ }
+}
+
+void av_md5_final(AVMD5 *ctx, uint8_t *dst){
+ int i;
+ uint64_t finalcount= le2me_64(ctx->len<<3);
+
+ av_md5_update(ctx, "\200", 1);
+ while((ctx->len & 63)<56)
+ av_md5_update(ctx, "", 1);
+
+ av_md5_update(ctx, &finalcount, 8);
+
+ for(i=0; i<4; i++)
+ ((uint32_t*)dst)[i]= le2me_32(ctx->ABCD[3-i]);
+}
+
+void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len){
+ AVMD5 ctx[1];
+
+ av_md5_init(ctx);
+ av_md5_update(ctx, src, len);
+ av_md5_final(ctx, dst);
+}
+
+#ifdef TEST
+#include <stdio.h>
+#undef printf
+main(){
+ uint64_t md5val;
+ int i;
+ uint8_t in[1000];
+
+ for(i=0; i<1000; i++) in[i]= i*i;
+ av_md5_sum( (uint8_t*)&md5val, in, 1000); printf("%"PRId64"\n", md5val);
+ av_md5_sum( (uint8_t*)&md5val, in, 63); printf("%"PRId64"\n", md5val);
+ av_md5_sum( (uint8_t*)&md5val, in, 64); printf("%"PRId64"\n", md5val);
+ av_md5_sum( (uint8_t*)&md5val, in, 65); printf("%"PRId64"\n", md5val);
+ for(i=0; i<1000; i++) in[i]= i % 127;
+ av_md5_sum( (uint8_t*)&md5val, in, 999); printf("%"PRId64"\n", md5val);
+}
+#endif
diff --git a/src/libffmpeg/libavutil/md5.h b/contrib/ffmpeg/libavutil/md5.h
index 8d1b4b5fe..8d1b4b5fe 100644
--- a/src/libffmpeg/libavutil/md5.h
+++ b/contrib/ffmpeg/libavutil/md5.h
diff --git a/contrib/ffmpeg/libavutil/mem.c b/contrib/ffmpeg/libavutil/mem.c
new file mode 100644
index 000000000..a91ac4a07
--- /dev/null
+++ b/contrib/ffmpeg/libavutil/mem.c
@@ -0,0 +1,152 @@
+/*
+ * default memory allocator for libavutil
+ * 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 mem.c
+ * default memory allocator for libavutil.
+ */
+
+#include "common.h"
+
+/* here we can use OS dependent allocation functions */
+#undef malloc
+#undef free
+#undef realloc
+
+#ifdef HAVE_MALLOC_H
+#include <malloc.h>
+#endif
+
+/* 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 */
+
+void *av_malloc(unsigned int size)
+{
+ void *ptr;
+#ifdef CONFIG_MEMALIGN_HACK
+ long diff;
+#endif
+
+ /* let's disallow possible ambiguous cases */
+ if(size > (INT_MAX-16) )
+ return NULL;
+
+#ifdef CONFIG_MEMALIGN_HACK
+ ptr = malloc(size+16);
+ if(!ptr)
+ return ptr;
+ diff= ((-(long)ptr - 1)&15) + 1;
+ ptr += diff;
+ ((char*)ptr)[-1]= diff;
+#elif defined (HAVE_MEMALIGN)
+ ptr = memalign(16,size);
+ /* Why 64?
+ Indeed, we should align it:
+ on 4 for 386
+ on 16 for 486
+ on 32 for 586, PPro - k6-III
+ on 64 for K7 (maybe for P3 too).
+ Because L1 and L2 caches are aligned on those values.
+ But I don't want to code such logic here!
+ */
+ /* Why 16?
+ because some cpus need alignment, for example SSE2 on P4, & most RISC cpus
+ it will just trigger an exception and the unaligned load will be done in the
+ exception handler or it will just segfault (SSE2 on P4)
+ Why not larger? because i didnt see a difference in benchmarks ...
+ */
+ /* benchmarks with p3
+ memalign(64)+1 3071,3051,3032
+ memalign(64)+2 3051,3032,3041
+ memalign(64)+4 2911,2896,2915
+ memalign(64)+8 2545,2554,2550
+ memalign(64)+16 2543,2572,2563
+ memalign(64)+32 2546,2545,2571
+ memalign(64)+64 2570,2533,2558
+
+ btw, malloc seems to do 8 byte alignment by default here
+ */
+#else
+ ptr = malloc(size);
+#endif
+ return ptr;
+}
+
+void *av_realloc(void *ptr, unsigned int size)
+{
+#ifdef CONFIG_MEMALIGN_HACK
+ int diff;
+#endif
+
+ /* let's disallow possible ambiguous cases */
+ if(size > (INT_MAX-16) )
+ return NULL;
+
+#ifdef CONFIG_MEMALIGN_HACK
+ //FIXME this isn't aligned correctly, though it probably isn't needed
+ if(!ptr) return av_malloc(size);
+ diff= ((char*)ptr)[-1];
+ return realloc(ptr - diff, size + diff) + diff;
+#else
+ return realloc(ptr, size);
+#endif
+}
+
+void av_free(void *ptr)
+{
+ /* XXX: this test should not be needed on most libcs */
+ if (ptr)
+#ifdef CONFIG_MEMALIGN_HACK
+ free(ptr - ((char*)ptr)[-1]);
+#else
+ free(ptr);
+#endif
+}
+
+void av_freep(void *arg)
+{
+ void **ptr= (void**)arg;
+ av_free(*ptr);
+ *ptr = NULL;
+}
+
+void *av_mallocz(unsigned int size)
+{
+ void *ptr;
+
+ ptr = av_malloc(size);
+ if (ptr)
+ memset(ptr, 0, size);
+ return ptr;
+}
+
+char *av_strdup(const char *s)
+{
+ char *ptr;
+ int len;
+ len = strlen(s) + 1;
+ ptr = av_malloc(len);
+ if (ptr)
+ memcpy(ptr, s, len);
+ return ptr;
+}
+
diff --git a/contrib/ffmpeg/libavutil/mem.h b/contrib/ffmpeg/libavutil/mem.h
new file mode 100644
index 000000000..4ebdad8f5
--- /dev/null
+++ b/contrib/ffmpeg/libavutil/mem.h
@@ -0,0 +1,65 @@
+/*
+ * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file mem.h
+ * Memory handling functions.
+ */
+
+#ifndef AV_MEM_H
+#define AV_MEM_H
+
+#ifdef __GNUC__
+ #define DECLARE_ALIGNED(n,t,v) t v __attribute__ ((aligned (n)))
+#else
+ #define DECLARE_ALIGNED(n,t,v) __declspec(align(n)) t v
+#endif
+
+/**
+ * Memory allocation of size byte with alignment suitable for all
+ * memory accesses (including vectors if available on the
+ * CPU). av_malloc(0) must return a non NULL pointer.
+ */
+void *av_malloc(unsigned int size);
+
+/**
+ * av_realloc semantics (same as glibc): if ptr is NULL and size > 0,
+ * identical to malloc(size). If size is zero, it is identical to
+ * free(ptr) and NULL is returned.
+ */
+void *av_realloc(void *ptr, unsigned int size);
+
+/**
+ * Free memory which has been allocated with av_malloc(z)() or av_realloc().
+ * NOTE: ptr = NULL is explicetly allowed
+ * Note2: it is recommended that you use av_freep() instead
+ */
+void av_free(void *ptr);
+
+void *av_mallocz(unsigned int size);
+char *av_strdup(const char *s);
+
+/**
+ * Frees memory and sets the pointer to NULL.
+ * @param ptr pointer to the pointer which should be freed
+ */
+void av_freep(void *ptr);
+
+#endif /* AV_MEM_H */
diff --git a/contrib/ffmpeg/libavutil/random.c b/contrib/ffmpeg/libavutil/random.c
new file mode 100644
index 000000000..c3e71e699
--- /dev/null
+++ b/contrib/ffmpeg/libavutil/random.c
@@ -0,0 +1,104 @@
+/*
+ * Mersenne Twister Random Algorithm
+ * Copyright (c) 2006 Ryan Martell.
+ * Based on A C-program for MT19937, with initialization improved 2002/1/26. Coded by
+ * Takuji Nishimura and Makoto Matsumoto.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+/**
+see http://en.wikipedia.org/wiki/Mersenne_twister for an explanation of this algorithm.
+*/
+#include <stdio.h>
+#include "random.h"
+
+//#define DEBUG
+
+#ifdef DEBUG
+#include "common.h"
+#include "log.h"
+#endif
+
+
+/* Period parameters */
+#define M 397
+#define A 0x9908b0df /* constant vector a */
+#define UPPER_MASK 0x80000000 /* most significant w-r bits */
+#define LOWER_MASK 0x7fffffff /* least significant r bits */
+
+/** initializes mt[AV_RANDOM_N] with a seed */
+void av_init_random(unsigned int seed, AVRandomState *state)
+{
+ int index;
+
+ /*
+ This differs from the wikipedia article. Source is from the Makoto
+ Makoto Matsumoto and Takuji Nishimura code, with the following comment:
+ */
+ /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
+ /* In the previous versions, MSBs of the seed affect */
+ /* only MSBs of the array mt[]. */
+ state->mt[0] = seed & 0xffffffff;
+ for (index = 1; index < AV_RANDOM_N; index++) {
+ unsigned int prev= state->mt[index - 1];
+ state->mt[index] = (1812433253UL * (prev ^ (prev>>30)) + index) & 0xffffffff;
+ }
+ state->index= index; // will cause it to generate untempered numbers the first iteration
+}
+
+/** generate AV_RANDOM_N words at one time (which will then be tempered later) (av_random calls this; you shouldn't) */
+void av_random_generate_untempered_numbers(AVRandomState *state)
+{
+ int kk;
+ unsigned int y;
+
+ for (kk = 0; kk < AV_RANDOM_N - M; kk++) {
+ y = (state->mt[kk] & UPPER_MASK) | (state->mt[kk + 1] & LOWER_MASK);
+ state->mt[kk] = state->mt[kk + M] ^ (y >> 1) ^ ((y&1)*A);
+ }
+ for (; kk < AV_RANDOM_N - 1; kk++) {
+ y = (state->mt[kk] & UPPER_MASK) | (state->mt[kk + 1] & LOWER_MASK);
+ state->mt[kk] = state->mt[kk + (M - AV_RANDOM_N)] ^ (y >> 1) ^ ((y&1)*A);
+ }
+ y = (state->mt[AV_RANDOM_N - 1] & UPPER_MASK) | (state->mt[0] & LOWER_MASK);
+ state->mt[AV_RANDOM_N - 1] = state->mt[M - 1] ^ (y >> 1) ^ ((y&1)*A);
+ state->index = 0;
+}
+
+#ifdef DEBUG
+void av_benchmark_random(void)
+{
+ int x=0;
+ int i, j;
+ AVRandomState state;
+
+ av_init_random(0xdeadbeef, &state);
+ for (j = 0; j < 100; j++) {
+ START_TIMER;
+ x+= av_random(&state);
+ STOP_TIMER("first call to av_random");
+ for (i = 1; i < AV_RANDOM_N; i++) {
+ START_TIMER;
+ x+= av_random(&state);
+ STOP_TIMER("AV_RANDOM_N calls of av_random");
+ }
+ }
+ av_log(NULL, AV_LOG_ERROR, "final value:%X\n", x);
+}
+#endif
diff --git a/contrib/ffmpeg/libavutil/random.h b/contrib/ffmpeg/libavutil/random.h
new file mode 100644
index 000000000..d9d08a5de
--- /dev/null
+++ b/contrib/ffmpeg/libavutil/random.h
@@ -0,0 +1,69 @@
+/*
+ * Mersenne Twister Random Algorithm
+ * Copyright (c) 2006 Ryan Martell.
+ * Based on A C-program for MT19937, with initialization improved 2002/1/26. Coded by
+ * Takuji Nishimura and Makoto Matsumoto.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 AV_RANDOM_H
+#define AV_RANDOM_H
+
+#define AV_RANDOM_N 624
+
+typedef struct {
+ unsigned int mt[AV_RANDOM_N]; ///< the array for the state vector
+ int index; ///< current untempered value we use as the base.
+} AVRandomState;
+
+
+void av_init_random(unsigned int seed, AVRandomState *state); ///< to be inlined, the struct must be visible, so it doesn't make sense to try and keep it opaque with malloc/free like calls
+void av_random_generate_untempered_numbers(AVRandomState *state); ///< Regenerate the untempered numbers (must be done every 624 iterations, or it will loop)
+
+/** generates a random number on [0,0xffffffff]-interval */
+static inline unsigned int av_random(AVRandomState *state)
+{
+ unsigned int y;
+
+ // regenerate the untempered numbers if we should...
+ if (state->index >= AV_RANDOM_N)
+ av_random_generate_untempered_numbers(state);
+
+ // grab one...
+ y = state->mt[state->index++];
+
+ /* Now temper (Mersenne Twister coefficients) The coefficients for MT19937 are.. */
+ y ^= (y >> 11);
+ y ^= (y << 7) & 0x9d2c5680;
+ y ^= (y << 15) & 0xefc60000;
+ y ^= (y >> 18);
+
+ return y;
+}
+
+/** return random in range [0-1] as double */
+static inline double av_random_real1(AVRandomState *state)
+{
+ /* divided by 2^32-1 */
+ return av_random(state) * (1.0 / 4294967296.0);
+}
+
+// only available if DEBUG is defined in the .c file
+void av_benchmark_random(void);
+#endif // AV_RANDOM_H
+
diff --git a/contrib/ffmpeg/libavutil/rational.c b/contrib/ffmpeg/libavutil/rational.c
new file mode 100644
index 000000000..ac0c9d371
--- /dev/null
+++ b/contrib/ffmpeg/libavutil/rational.c
@@ -0,0 +1,104 @@
+/*
+ * Rational numbers
+ * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * @file rational.c
+ * Rational numbers
+ * @author Michael Niedermayer <michaelni@gmx.at>
+ */
+
+//#include <math.h>
+#include <limits.h>
+
+#include "common.h"
+#include "mathematics.h"
+#include "rational.h"
+
+int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max){
+ AVRational a0={0,1}, a1={1,0};
+ int sign= (nom<0) ^ (den<0);
+ int64_t gcd= ff_gcd(FFABS(nom), FFABS(den));
+
+ if(gcd){
+ nom = FFABS(nom)/gcd;
+ den = FFABS(den)/gcd;
+ }
+ if(nom<=max && den<=max){
+ a1= (AVRational){nom, den};
+ den=0;
+ }
+
+ while(den){
+ uint64_t x = nom / den;
+ int64_t next_den= nom - den*x;
+ int64_t a2n= x*a1.num + a0.num;
+ int64_t a2d= x*a1.den + a0.den;
+
+ if(a2n > max || a2d > max){
+ if(a1.num) x= (max - a0.num) / a1.num;
+ if(a1.den) x= FFMIN(x, (max - a0.den) / a1.den);
+
+ if (den*(2*x*a1.den + a0.den) > nom*a1.den)
+ a1 = (AVRational){x*a1.num + a0.num, x*a1.den + a0.den};
+ break;
+ }
+
+ a0= a1;
+ a1= (AVRational){a2n, a2d};
+ nom= den;
+ den= next_den;
+ }
+ assert(ff_gcd(a1.num, a1.den) <= 1U);
+
+ *dst_nom = sign ? -a1.num : a1.num;
+ *dst_den = a1.den;
+
+ return den==0;
+}
+
+AVRational av_mul_q(AVRational b, AVRational c){
+ av_reduce(&b.num, &b.den, b.num * (int64_t)c.num, b.den * (int64_t)c.den, INT_MAX);
+ return b;
+}
+
+AVRational av_div_q(AVRational b, AVRational c){
+ return av_mul_q(b, (AVRational){c.den, c.num});
+}
+
+AVRational av_add_q(AVRational b, AVRational c){
+ av_reduce(&b.num, &b.den, b.num * (int64_t)c.den + c.num * (int64_t)b.den, b.den * (int64_t)c.den, INT_MAX);
+ return b;
+}
+
+AVRational av_sub_q(AVRational b, AVRational c){
+ return av_add_q(b, (AVRational){-c.num, c.den});
+}
+
+AVRational av_d2q(double d, int max){
+ AVRational a;
+#define LOG2 0.69314718055994530941723212145817656807550013436025
+ int exponent= FFMAX( (int)(log(fabs(d) + 1e-20)/LOG2), 0);
+ int64_t den= 1LL << (61 - exponent);
+ av_reduce(&a.num, &a.den, (int64_t)(d * den + 0.5), den, max);
+
+ return a;
+}
diff --git a/contrib/ffmpeg/libavutil/rational.h b/contrib/ffmpeg/libavutil/rational.h
new file mode 100644
index 000000000..63c0b150f
--- /dev/null
+++ b/contrib/ffmpeg/libavutil/rational.h
@@ -0,0 +1,114 @@
+/*
+ * Rational numbers
+ * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * @file rational.h
+ * Rational numbers.
+ * @author Michael Niedermayer <michaelni@gmx.at>
+ */
+
+#ifndef RATIONAL_H
+#define RATIONAL_H
+
+/**
+ * Rational number num/den.
+ */
+typedef struct AVRational{
+ int num; ///< numerator
+ int den; ///< denominator
+} AVRational;
+
+/**
+ * Compare two rationals.
+ * @param a first rational
+ * @param b second rational
+ * @return 0 if a==b, 1 if a>b and -1 if a<b.
+ */
+static inline int av_cmp_q(AVRational a, AVRational b){
+ const int64_t tmp= a.num * (int64_t)b.den - b.num * (int64_t)a.den;
+
+ if(tmp) return (tmp>>63)|1;
+ else return 0;
+}
+
+/**
+ * Rational to double conversion.
+ * @param a rational to convert
+ * @return (double) a
+ */
+static inline double av_q2d(AVRational a){
+ return a.num / (double) a.den;
+}
+
+/**
+ * Reduce a fraction.
+ * This is useful for framerate calculations.
+ * @param dst_nom destination numerator
+ * @param dst_den destination denominator
+ * @param nom source numerator
+ * @param den source denominator
+ * @param max the maximum allowed for dst_nom & dst_den
+ * @return 1 if exact, 0 otherwise
+ */
+int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max);
+
+/**
+ * Multiplies two rationals.
+ * @param b first rational.
+ * @param c second rational.
+ * @return b*c.
+ */
+AVRational av_mul_q(AVRational b, AVRational c);
+
+/**
+ * Divides one rational by another.
+ * @param b first rational.
+ * @param c second rational.
+ * @return b/c.
+ */
+AVRational av_div_q(AVRational b, AVRational c);
+
+/**
+ * Adds two rationals.
+ * @param b first rational.
+ * @param c second rational.
+ * @return b+c.
+ */
+AVRational av_add_q(AVRational b, AVRational c);
+
+/**
+ * Subtracts one rational from another.
+ * @param b first rational.
+ * @param c second rational.
+ * returns b-c.
+ */
+AVRational av_sub_q(AVRational b, AVRational c);
+
+/**
+ * Converts a double precision floating point number to a rational.
+ * @param d double to convert
+ * @param max the maximum allowed numerator and denominator
+ * @return (AVRational) d.
+ */
+AVRational av_d2q(double d, int max);
+
+#endif // RATIONAL_H
diff --git a/contrib/ffmpeg/libavutil/sha1.c b/contrib/ffmpeg/libavutil/sha1.c
new file mode 100644
index 000000000..6c10791f4
--- /dev/null
+++ b/contrib/ffmpeg/libavutil/sha1.c
@@ -0,0 +1,160 @@
+// SHA-1 code Copyright 2007 Michael Nidermayer <michaelni@gmx.at>
+// license LGPL
+// based on public domain SHA-1 code by Steve Reid <steve@edmweb.com>
+
+#include "common.h"
+#include "sha1.h"
+
+typedef struct AVSHA1 {
+ uint64_t count;
+ uint8_t buffer[64];
+ uint32_t state[5];
+} AVSHA1;
+
+#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
+
+/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
+#define blk0(i) (block[i] = be2me_32(((uint32_t*)buffer)[i]))
+#define blk(i) (block[i] = rol(block[i-3]^block[i-8]^block[i-14]^block[i-16],1))
+
+#define R0(v,w,x,y,z,i) z+=((w&(x^y))^y) +blk0(i)+0x5A827999+rol(v,5);w=rol(w,30);
+#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y) +blk (i)+0x5A827999+rol(v,5);w=rol(w,30);
+#define R2(v,w,x,y,z,i) z+=( w^x ^y) +blk (i)+0x6ED9EBA1+rol(v,5);w=rol(w,30);
+#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk (i)+0x8F1BBCDC+rol(v,5);w=rol(w,30);
+#define R4(v,w,x,y,z,i) z+=( w^x ^y) +blk (i)+0xCA62C1D6+rol(v,5);w=rol(w,30);
+
+/* Hash a single 512-bit block. This is the core of the algorithm. */
+
+static void transform(uint32_t state[5], uint8_t buffer[64]){
+ uint32_t block[80];
+ unsigned int i, a, b, c, d, e;
+
+ a = state[0];
+ b = state[1];
+ c = state[2];
+ d = state[3];
+ e = state[4];
+#ifdef CONFIG_SMALL
+ for(i=0; i<80; i++){
+ int t;
+ if(i<16) t= be2me_32(((uint32_t*)buffer)[i]);
+ else t= rol(block[i-3]^block[i-8]^block[i-14]^block[i-16],1);
+ block[i]= t;
+ t+= e+rol(a,5);
+ if(i<40){
+ if(i<20) t+= ((b&(c^d))^d) +0x5A827999;
+ else t+= ( b^c ^d) +0x6ED9EBA1;
+ }else{
+ if(i<60) t+= (((b|c)&d)|(b&c))+0x8F1BBCDC;
+ else t+= ( b^c ^d) +0xCA62C1D6;
+ }
+ e= d;
+ d= c;
+ c= rol(b,30);
+ b= a;
+ a= t;
+ }
+#else
+ for(i=0; i<15; i+=5){
+ R0(a,b,c,d,e,0+i); R0(e,a,b,c,d,1+i); R0(d,e,a,b,c,2+i); R0(c,d,e,a,b,3+i); R0(b,c,d,e,a,4+i);
+ }
+ R0(a,b,c,d,e,15); R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
+ for(i=20; i<40; i+=5){
+ R2(a,b,c,d,e,0+i); R2(e,a,b,c,d,1+i); R2(d,e,a,b,c,2+i); R2(c,d,e,a,b,3+i); R2(b,c,d,e,a,4+i);
+ }
+ for(; i<60; i+=5){
+ R3(a,b,c,d,e,0+i); R3(e,a,b,c,d,1+i); R3(d,e,a,b,c,2+i); R3(c,d,e,a,b,3+i); R3(b,c,d,e,a,4+i);
+ }
+ for(; i<80; i+=5){
+ R4(a,b,c,d,e,0+i); R4(e,a,b,c,d,1+i); R4(d,e,a,b,c,2+i); R4(c,d,e,a,b,3+i); R4(b,c,d,e,a,4+i);
+ }
+#endif
+ state[0] += a;
+ state[1] += b;
+ state[2] += c;
+ state[3] += d;
+ state[4] += e;
+}
+
+void av_sha1_init(AVSHA1* ctx){
+ ctx->state[0] = 0x67452301;
+ ctx->state[1] = 0xEFCDAB89;
+ ctx->state[2] = 0x98BADCFE;
+ ctx->state[3] = 0x10325476;
+ ctx->state[4] = 0xC3D2E1F0;
+ ctx->count = 0;
+}
+
+void av_sha1_update(AVSHA1* ctx, uint8_t* data, unsigned int len){
+ unsigned int i, j;
+
+ j = ctx->count & 63;
+ ctx->count += len;
+#ifdef CONFIG_SMALL
+ for( i = 0; i < len; i++ ){
+ ctx->buffer[ j++ ] = data[i];
+ if( 64 == j ){
+ transform(ctx->state, ctx->buffer);
+ j = 0;
+ }
+ }
+#else
+ if ((j + len) > 63) {
+ memcpy(&ctx->buffer[j], data, (i = 64-j));
+ transform(ctx->state, ctx->buffer);
+ for ( ; i + 63 < len; i += 64) {
+ transform(ctx->state, &data[i]);
+ }
+ j=0;
+ }
+ else i = 0;
+ memcpy(&ctx->buffer[j], &data[i], len - i);
+#endif
+}
+
+void av_sha1_final(AVSHA1* ctx, uint8_t digest[20]){
+ int i;
+ uint64_t finalcount= be2me_64(ctx->count<<3);
+
+ av_sha1_update(ctx, "\200", 1);
+ while ((ctx->count & 63) != 56) {
+ av_sha1_update(ctx, "", 1);
+ }
+ av_sha1_update(ctx, &finalcount, 8); /* Should cause a transform() */
+ for(i=0; i<5; i++)
+ ((uint32_t*)digest)[i]= be2me_32(ctx->state[i]);
+}
+
+// use the following to test
+// gcc -DTEST -DHAVE_AV_CONFIG_H -I.. sha1.c -O2 -W -Wall -o sha1 && time ./sha1
+#ifdef TEST
+#include <stdio.h>
+#undef printf
+
+int main(){
+ int i, k;
+ AVSHA1 ctx;
+ unsigned char digest[20];
+
+ for(k=0; k<3; k++){
+ av_sha1_init(&ctx);
+ if(k==0)
+ av_sha1_update(&ctx, "abc", 3);
+ else if(k==1)
+ av_sha1_update(&ctx, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56);
+ else
+ for(i=0; i<1000*1000; i++)
+ av_sha1_update(&ctx, "a", 1);
+ av_sha1_final(&ctx, digest);
+ for (i = 0; i < 20; i++)
+ printf("%02X", digest[i]);
+ putchar('\n');
+ }
+ //Test Vectors (from FIPS PUB 180-1)
+ printf("A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D\n"
+ "84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1\n"
+ "34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F\n");
+
+ return 0;
+}
+#endif
diff --git a/contrib/ffmpeg/libavutil/sha1.h b/contrib/ffmpeg/libavutil/sha1.h
new file mode 100644
index 000000000..8739cbde9
--- /dev/null
+++ b/contrib/ffmpeg/libavutil/sha1.h
@@ -0,0 +1,11 @@
+#ifndef AV_SHA1_H
+#define AV_SHA1_H
+
+extern const int av_sha1_size;
+
+struct AVSHA1;
+
+void av_sha1_init(struct AVSHA1* context);
+void av_sha1_update(struct AVSHA1* context, uint8_t* data, unsigned int len);
+void av_sha1_final(struct AVSHA1* context, uint8_t digest[20]);
+#endif
diff --git a/contrib/ffmpeg/libavutil/softfloat.c b/contrib/ffmpeg/libavutil/softfloat.c
new file mode 100644
index 000000000..f12fd17a0
--- /dev/null
+++ b/contrib/ffmpeg/libavutil/softfloat.c
@@ -0,0 +1,72 @@
+/*
+ * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <inttypes.h>
+#include <stdio.h>
+#include <assert.h>
+#include "softfloat.h"
+#include "common.h"
+#include "log.h"
+
+#undef printf
+
+int main(){
+ SoftFloat one= av_int2sf(1, 0);
+ SoftFloat sf1, sf2;
+ double d1, d2;
+ int i, j;
+av_log_level = AV_LOG_DEBUG;
+
+ d1= 1;
+ for(i= 0; i<10; i++){
+ d1= 1/(d1+1);
+ }
+ printf("test1 double=%d\n", (int)(d1 * (1<<24)));
+
+ sf1= one;
+ for(i= 0; i<10; i++){
+ sf1= av_div_sf(one, av_normalize_sf(av_add_sf(one, sf1)));
+ }
+ printf("test1 sf =%d\n", av_sf2int(sf1, 24));
+
+
+ for(i= 0; i<100; i++){
+ START_TIMER
+ d1= i;
+ d2= i/100.0;
+ for(j= 0; j<1000; j++){
+ d1= (d1+1)*d2;
+ }
+ STOP_TIMER("float add mul")
+ }
+ printf("test2 double=%d\n", (int)(d1 * (1<<24)));
+
+ for(i= 0; i<100; i++){
+ START_TIMER
+ sf1= av_int2sf(i, 0);
+ sf2= av_div_sf(av_int2sf(i, 2), av_int2sf(200, 3));
+ for(j= 0; j<1000; j++){
+ sf1= av_mul_sf(av_add_sf(sf1, one),sf2);
+ }
+ STOP_TIMER("softfloat add mul")
+ }
+ printf("test2 sf =%d (%d %d)\n", av_sf2int(sf1, 24), sf1.exp, sf1.mant);
+ return 0;
+}
diff --git a/contrib/ffmpeg/libavutil/softfloat.h b/contrib/ffmpeg/libavutil/softfloat.h
new file mode 100644
index 000000000..5bb2c1cbc
--- /dev/null
+++ b/contrib/ffmpeg/libavutil/softfloat.h
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#define MIN_EXP -126
+#define MAX_EXP 126
+#define ONE_BITS 29
+
+typedef struct SoftFloat{
+ int32_t exp;
+ int32_t mant;
+}SoftFloat;
+
+static SoftFloat av_normalize_sf(SoftFloat a){
+ if(a.mant){
+#if 1
+ while((a.mant + 0x20000000U)<0x40000000U){
+ a.mant += a.mant;
+ a.exp -= 1;
+ }
+#else
+ int s=ONE_BITS + 1 - av_log2(a.mant ^ (a.mant<<1));
+ a.exp -= s;
+ a.mant <<= s;
+#endif
+ if(a.exp < MIN_EXP){
+ a.exp = MIN_EXP;
+ a.mant= 0;
+ }
+ }else{
+ a.exp= MIN_EXP;
+ }
+ return a;
+}
+
+static inline SoftFloat av_normalize1_sf(SoftFloat a){
+#if 1
+ if(a.mant + 0x40000000 < 0){
+ a.exp++;
+ a.mant>>=1;
+ }
+ return a;
+#elif 1
+ int t= a.mant + 0x40000000 < 0;
+ return (SoftFloat){a.exp+t, a.mant>>t};
+#else
+ int t= (a.mant + 0x40000000U)>>31;
+ return (SoftFloat){a.exp+t, a.mant>>t};
+#endif
+}
+
+/**
+ *
+ * @return will not be more denormalized then a+b, so if either input is
+ * normalized then the output wont be worse then the other input
+ * if both are normalized then the output will be normalized
+ */
+static inline SoftFloat av_mul_sf(SoftFloat a, SoftFloat b){
+ a.exp += b.exp;
+ a.mant = (a.mant * (int64_t)b.mant) >> ONE_BITS;
+ return av_normalize1_sf(a);
+}
+
+/**
+ *
+ * b has to be normalized and not zero
+ * @return will not be more denormalized then a
+ */
+static SoftFloat av_div_sf(SoftFloat a, SoftFloat b){
+ a.exp -= b.exp+1;
+ a.mant = ((int64_t)a.mant<<(ONE_BITS+1)) / b.mant;
+ return av_normalize1_sf(a);
+}
+
+static inline int av_cmp_sf(SoftFloat a, SoftFloat b){
+ int t= a.exp - b.exp;
+ if(t<0) return (a.mant >> (-t)) - b.mant ;
+ else return a.mant - (b.mant >> t);
+}
+
+static inline SoftFloat av_add_sf(SoftFloat a, SoftFloat b){
+ int t= a.exp - b.exp;
+ if(t<0) return av_normalize1_sf((SoftFloat){b.exp, b.mant + (a.mant >> (-t))});
+ else return av_normalize1_sf((SoftFloat){a.exp, a.mant + (b.mant >> t )});
+}
+
+static inline SoftFloat av_sub_sf(SoftFloat a, SoftFloat b){
+ return av_add_sf(a, (SoftFloat){b.exp, -b.mant});
+}
+
+//FIXME sqrt, log, exp, pow, sin, cos
+
+static inline SoftFloat av_int2sf(int v, int frac_bits){
+ return av_normalize_sf((SoftFloat){ONE_BITS-frac_bits, v});
+}
+
+/**
+ *
+ * rounding is to -inf
+ */
+static inline int av_sf2int(SoftFloat v, int frac_bits){
+ v.exp += frac_bits - ONE_BITS;
+ if(v.exp >= 0) return v.mant << v.exp ;
+ else return v.mant >>(-v.exp);
+}
diff --git a/contrib/ffmpeg/libavutil/tree.c b/contrib/ffmpeg/libavutil/tree.c
new file mode 100644
index 000000000..c929e4819
--- /dev/null
+++ b/contrib/ffmpeg/libavutil/tree.c
@@ -0,0 +1,151 @@
+/*
+ * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "common.h"
+#include "log.h"
+#include "tree.h"
+
+typedef struct AVTreeNode{
+ struct AVTreeNode *child[2];
+ void *elem;
+ int state;
+}AVTreeNode;
+
+void *av_tree_find(const AVTreeNode *t, void *key, int (*cmp)(void *key, const void *b), void *next[2]){
+ if(t){
+ unsigned int v= cmp(t->elem, key);
+ if(v){
+ if(next) next[(v>>31)^1]= t->elem;
+ return av_tree_find(t->child[v>>31], key, cmp, next);
+ }else{
+ return t->elem;
+ }
+ }
+ return NULL;
+}
+
+void *av_tree_insert(AVTreeNode **tp, void *key, int (*cmp)(void *key, const void *b)){
+ AVTreeNode *t= *tp;
+ if(t){
+ unsigned int v= cmp(t->elem, key);
+ if(v){
+ int i= v>>31;
+ AVTreeNode **child= &t->child[i];
+ void *ret= av_tree_insert(child, key, cmp);
+ if(!ret){
+ t->state -= ((int)v>>31)|1;
+ if(!(t->state&1)){
+ if(t->state){
+ if((*child)->state*2 == t->state){
+ *tp= *child;
+ *child= (*child)->child[i^1];
+ (*tp)->child[i^1]= t;
+ t->state= 0;
+ }else{
+ *tp= (*child)->child[i^1];
+ (*child)->child[i^1]= (*tp)->child[i];
+ (*tp)->child[i]= *child;
+ *child= (*tp)->child[i^1];
+ (*tp)->child[i^1]= t;
+
+ i= (*tp)->state > 0;
+ (*tp)->child[i ]->state= 0;
+ (*tp)->child[i^1]->state= -(*tp)->state;
+ }
+ (*tp)->state=0;
+ }
+ return key;
+ }
+ }
+ return ret;
+ }else{
+ return t->elem;
+ }
+ }else{
+ *tp= av_mallocz(sizeof(AVTreeNode));
+ (*tp)->elem= key;
+ return NULL;
+ }
+}
+
+void av_tree_destroy(AVTreeNode *t){
+ av_tree_destroy(t->child[0]);
+ av_tree_destroy(t->child[1]);
+ av_free(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);
+}
+#endif
+
+#ifdef TEST
+
+static int check(AVTreeNode *t){
+ if(t){
+ int left= check(t->child[0]);
+ int right= check(t->child[1]);
+
+ if(left>999 || right>999)
+ return 1000;
+ if(right - left != t->state)
+ return 1000;
+ if(t->state>1 || t->state<-1)
+ return 1000;
+ return FFMAX(left, right)+1;
+ }
+ return 0;
+}
+
+static void print(AVTreeNode *t, int depth){
+ int i;
+ for(i=0; i<depth*4; i++) av_log(NULL, AV_LOG_ERROR, " ");
+ if(t){
+ av_log(NULL, AV_LOG_ERROR, "Node %p %2d %4d\n", t, t->state, t->elem);
+ print(t->child[0], depth+1);
+ print(t->child[1], depth+1);
+ }else
+ av_log(NULL, AV_LOG_ERROR, "NULL\n");
+}
+
+int cmp(const void *a, const void *b){
+ return a-b;
+}
+
+int main(){
+ int i,j,k;
+ AVTreeNode *root= NULL;
+
+ for(i=0; i<10000; i++){
+ int j= (random()%863294);
+ if(check(root) > 999){
+ av_log(NULL, AV_LOG_ERROR, "FATAL error %d\n", i);
+ print(root, 0);
+ return -1;
+ }
+ av_log(NULL, AV_LOG_ERROR, "inserting %4d\n", j);
+ av_tree_insert(&root, (void*)(j+1), cmp);
+ }
+ return 0;
+}
+#endif
diff --git a/contrib/ffmpeg/libavutil/tree.h b/contrib/ffmpeg/libavutil/tree.h
new file mode 100644
index 000000000..be1735858
--- /dev/null
+++ b/contrib/ffmpeg/libavutil/tree.h
@@ -0,0 +1,58 @@
+/*
+ * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file tree.h
+ * A tree container.
+ * @author Michael Niedermayer <michaelni@gmx.at>
+ */
+
+#ifndef TREE_H
+#define TREE_H
+
+struct AVTreeNode;
+
+/**
+ * Finds an element.
+ * @param root a pointer to the root node of the tree
+ * @param next If next is not NULL then next[0] will contain the previous
+ * element and next[1] the next element if either does not exist
+ * then the corresponding entry in next is unchanged.
+ * @return An element with cmp(key, elem)==0 or NULL if no such element exists in
+ * the tree.
+ */
+void *av_tree_find(const struct AVTreeNode *root, void *key, int (*cmp)(void *key, const void *b), void *next[2]);
+
+/**
+ * Finds a element for which cmp(key, elem)==0, if no such element is found key
+ * is inserted into the tree.
+ * @param rootp A pointer to a pointer to the root node of the tree. Note that
+ * the root node can change during insertions, this is required
+ * to keep the tree balanced.
+ *
+ * @return If no insertion happened, the found element.
+ * If an insertion happened, then either key or NULL will be returned.
+ * Which one it is depends on the tree state and the implementation. You
+ * should make no assumptions that it's one or the other in the code.
+ */
+void *av_tree_insert(struct AVTreeNode **rootp, void *key, int (*cmp)(void *key, const void *b));
+void av_tree_destroy(struct AVTreeNode *t);
+
+#endif /* TREE_H */
diff --git a/contrib/ffmpeg/libavutil/x86_cpu.h b/contrib/ffmpeg/libavutil/x86_cpu.h
new file mode 100644
index 000000000..67d4cd9aa
--- /dev/null
+++ b/contrib/ffmpeg/libavutil/x86_cpu.h
@@ -0,0 +1,64 @@
+/*
+ * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_X86CPU_H
+#define AVUTIL_X86CPU_H
+
+#ifdef ARCH_X86_64
+# define REG_a "rax"
+# define REG_b "rbx"
+# define REG_c "rcx"
+# define REG_d "rdx"
+# define REG_D "rdi"
+# define REG_S "rsi"
+# define PTR_SIZE "8"
+
+# define REG_SP "rsp"
+# define REG_BP "rbp"
+# define REGBP rbp
+# define REGa rax
+# define REGb rbx
+# define REGc rcx
+# define REGSP rsp
+
+#else
+
+# define REG_a "eax"
+# define REG_b "ebx"
+# define REG_c "ecx"
+# define REG_d "edx"
+# define REG_D "edi"
+# define REG_S "esi"
+# define PTR_SIZE "4"
+
+# define REG_SP "esp"
+# define REG_BP "ebp"
+# define REGBP ebp
+# define REGa eax
+# define REGb ebx
+# define REGc ecx
+# define REGSP esp
+#endif
+
+#if defined(ARCH_X86_64) || (defined(ARCH_X86_32) && defined(CONFIG_EBX_AVAILABLE) && defined(CONFIG_EBP_AVAILABLE))
+# define CONFIG_7REGS 1
+#endif
+
+#endif /* AVUTIL_X86CPU_H */
diff --git a/contrib/ffmpeg/libpostproc/Makefile b/contrib/ffmpeg/libpostproc/Makefile
new file mode 100644
index 000000000..d30b4a18d
--- /dev/null
+++ b/contrib/ffmpeg/libpostproc/Makefile
@@ -0,0 +1,24 @@
+
+include ../config.mak
+
+# Overload incdir, postproc include files go in a different directory.
+incdir=$(prefix)/include/postproc
+
+EXTRALIBS := -L$(BUILD_ROOT)/libavutil -lavutil$(BUILDSUF) $(EXTRALIBS)
+
+NAME=postproc
+LIBVERSION=$(SPPVERSION)
+LIBMAJOR=$(SPPMAJOR)
+
+STATIC_OBJS=postprocess.o
+SHARED_OBJS=postprocess_pic.o
+
+HEADERS = postprocess.h
+
+include ../common.mak
+
+depend dep: postprocess.c
+
+postprocess_pic.o: postprocess.c
+ $(CC) -c $(CFLAGS) -fomit-frame-pointer -fPIC -DPIC -o $@ $<
+
diff --git a/contrib/ffmpeg/libpostproc/mangle.h b/contrib/ffmpeg/libpostproc/mangle.h
new file mode 100644
index 000000000..3521fa9bb
--- /dev/null
+++ b/contrib/ffmpeg/libpostproc/mangle.h
@@ -0,0 +1,47 @@
+/*
+ * mangle.h - This file has some CPP macros to deal with different symbol
+ * mangling across binary formats.
+ *
+ * (c)2002 by Felix Buenemann <atmosfear at users.sourceforge.net>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __MANGLE_H
+#define __MANGLE_H
+
+/* Feel free to add more to the list, eg. a.out IMO */
+/* Use rip-relative addressing if compiling PIC code on x86-64. */
+#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__OS2__) || \
+ (defined(__OpenBSD__) && !defined(__ELF__))
+#if defined(ARCH_X86_64) && defined(PIC)
+#define MANGLE(a) "_" #a"(%%rip)"
+#else
+#define MANGLE(a) "_" #a
+#endif
+#else
+#if defined(ARCH_X86_64) && defined(PIC)
+#define MANGLE(a) #a"(%%rip)"
+#elif defined(CONFIG_DARWIN)
+#define MANGLE(a) "_" #a
+#else
+#define MANGLE(a) #a
+#endif
+#endif
+
+#endif /* !__MANGLE_H */
+
diff --git a/contrib/ffmpeg/libpostproc/postprocess.c b/contrib/ffmpeg/libpostproc/postprocess.c
new file mode 100644
index 000000000..f68c8a723
--- /dev/null
+++ b/contrib/ffmpeg/libpostproc/postprocess.c
@@ -0,0 +1,1144 @@
+/*
+ * Copyright (C) 2001-2003 Michael Niedermayer (michaelni@gmx.at)
+ *
+ * AltiVec optimizations (C) 2004 Romain Dolbeau <romain@dolbeau.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file postprocess.c
+ * postprocessing.
+ */
+
+/*
+ C MMX MMX2 3DNow AltiVec
+isVertDC Ec Ec Ec
+isVertMinMaxOk Ec Ec Ec
+doVertLowPass E e e Ec
+doVertDefFilter Ec Ec e e Ec
+isHorizDC Ec Ec Ec
+isHorizMinMaxOk a E Ec
+doHorizLowPass E e e Ec
+doHorizDefFilter Ec Ec e e Ec
+do_a_deblock Ec E Ec E
+deRing E e e* Ecp
+Vertical RKAlgo1 E a a
+Horizontal RKAlgo1 a a
+Vertical X1# a E E
+Horizontal X1# a E E
+LinIpolDeinterlace e E E*
+CubicIpolDeinterlace a e e*
+LinBlendDeinterlace e E E*
+MedianDeinterlace# E Ec Ec
+TempDeNoiser# E e e Ec
+
+* i dont have a 3dnow CPU -> its untested, but noone said it doesnt work so it seems to work
+# more or less selfinvented filters so the exactness isnt too meaningfull
+E = Exact implementation
+e = allmost exact implementation (slightly different rounding,...)
+a = alternative / approximate impl
+c = checked against the other implementations (-vo md5)
+p = partially optimized, still some work to do
+*/
+
+/*
+TODO:
+reduce the time wasted on the mem transfer
+unroll stuff if instructions depend too much on the prior one
+move YScale thing to the end instead of fixing QP
+write a faster and higher quality deblocking filter :)
+make the mainloop more flexible (variable number of blocks at once
+ (the if/else stuff per block is slowing things down)
+compare the quality & speed of all filters
+split this huge file
+optimize c versions
+try to unroll inner for(x=0 ... loop to avoid these damn if(x ... checks
+...
+*/
+
+//Changelog: use the Subversion log
+
+#include "config.h"
+#include "avutil.h"
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef HAVE_MALLOC_H
+#include <malloc.h>
+#endif
+//#undef HAVE_MMX2
+//#define HAVE_3DNOW
+//#undef HAVE_MMX
+//#undef ARCH_X86
+//#define DEBUG_BRIGHTNESS
+#ifdef USE_FASTMEMCPY
+#include "libvo/fastmemcpy.h"
+#endif
+#include "postprocess.h"
+#include "postprocess_internal.h"
+
+#include "mangle.h" //FIXME should be supressed
+
+#ifdef HAVE_ALTIVEC_H
+#include <altivec.h>
+#endif
+
+#define GET_MODE_BUFFER_SIZE 500
+#define OPTIONS_ARRAY_SIZE 10
+#define BLOCK_SIZE 8
+#define TEMP_STRIDE 8
+//#define NUM_BLOCKS_AT_ONCE 16 //not used yet
+
+#if defined(ARCH_X86)
+static uint64_t __attribute__((aligned(8))) attribute_used w05= 0x0005000500050005LL;
+static uint64_t __attribute__((aligned(8))) attribute_used w04= 0x0004000400040004LL;
+static uint64_t __attribute__((aligned(8))) attribute_used w20= 0x0020002000200020LL;
+static uint64_t __attribute__((aligned(8))) attribute_used b00= 0x0000000000000000LL;
+static uint64_t __attribute__((aligned(8))) attribute_used b01= 0x0101010101010101LL;
+static uint64_t __attribute__((aligned(8))) attribute_used b02= 0x0202020202020202LL;
+static uint64_t __attribute__((aligned(8))) attribute_used b08= 0x0808080808080808LL;
+static uint64_t __attribute__((aligned(8))) attribute_used b80= 0x8080808080808080LL;
+#endif
+
+static uint8_t clip_table[3*256];
+static uint8_t * const clip_tab= clip_table + 256;
+
+static const int attribute_used deringThreshold= 20;
+
+
+static struct PPFilter filters[]=
+{
+ {"hb", "hdeblock", 1, 1, 3, H_DEBLOCK},
+ {"vb", "vdeblock", 1, 2, 4, V_DEBLOCK},
+/* {"hr", "rkhdeblock", 1, 1, 3, H_RK1_FILTER},
+ {"vr", "rkvdeblock", 1, 2, 4, V_RK1_FILTER},*/
+ {"h1", "x1hdeblock", 1, 1, 3, H_X1_FILTER},
+ {"v1", "x1vdeblock", 1, 2, 4, V_X1_FILTER},
+ {"ha", "ahdeblock", 1, 1, 3, H_A_DEBLOCK},
+ {"va", "avdeblock", 1, 2, 4, V_A_DEBLOCK},
+ {"dr", "dering", 1, 5, 6, DERING},
+ {"al", "autolevels", 0, 1, 2, LEVEL_FIX},
+ {"lb", "linblenddeint", 1, 1, 4, LINEAR_BLEND_DEINT_FILTER},
+ {"li", "linipoldeint", 1, 1, 4, LINEAR_IPOL_DEINT_FILTER},
+ {"ci", "cubicipoldeint", 1, 1, 4, CUBIC_IPOL_DEINT_FILTER},
+ {"md", "mediandeint", 1, 1, 4, MEDIAN_DEINT_FILTER},
+ {"fd", "ffmpegdeint", 1, 1, 4, FFMPEG_DEINT_FILTER},
+ {"l5", "lowpass5", 1, 1, 4, LOWPASS5_DEINT_FILTER},
+ {"tn", "tmpnoise", 1, 7, 8, TEMP_NOISE_FILTER},
+ {"fq", "forcequant", 1, 0, 0, FORCE_QUANT},
+ {NULL, NULL,0,0,0,0} //End Marker
+};
+
+static const char *replaceTable[]=
+{
+ "default", "hdeblock:a,vdeblock:a,dering:a",
+ "de", "hdeblock:a,vdeblock:a,dering:a",
+ "fast", "x1hdeblock:a,x1vdeblock:a,dering:a",
+ "fa", "x1hdeblock:a,x1vdeblock:a,dering:a",
+ "ac", "ha:a:128:7,va:a,dering:a",
+ NULL //End Marker
+};
+
+
+#if defined(ARCH_X86)
+static inline void prefetchnta(void *p)
+{
+ asm volatile( "prefetchnta (%0)\n\t"
+ : : "r" (p)
+ );
+}
+
+static inline void prefetcht0(void *p)
+{
+ asm volatile( "prefetcht0 (%0)\n\t"
+ : : "r" (p)
+ );
+}
+
+static inline void prefetcht1(void *p)
+{
+ asm volatile( "prefetcht1 (%0)\n\t"
+ : : "r" (p)
+ );
+}
+
+static inline void prefetcht2(void *p)
+{
+ asm volatile( "prefetcht2 (%0)\n\t"
+ : : "r" (p)
+ );
+}
+#endif
+
+// The horizontal Functions exist only in C cuz the MMX code is faster with vertical filters and transposing
+
+/**
+ * Check if the given 8x8 Block is mostly "flat"
+ */
+static inline int isHorizDC_C(uint8_t src[], int stride, PPContext *c)
+{
+ int numEq= 0;
+ int y;
+ const int dcOffset= ((c->nonBQP*c->ppMode.baseDcDiff)>>8) + 1;
+ const int dcThreshold= dcOffset*2 + 1;
+
+ for(y=0; y<BLOCK_SIZE; y++)
+ {
+ if(((unsigned)(src[0] - src[1] + dcOffset)) < dcThreshold) numEq++;
+ if(((unsigned)(src[1] - src[2] + dcOffset)) < dcThreshold) numEq++;
+ if(((unsigned)(src[2] - src[3] + dcOffset)) < dcThreshold) numEq++;
+ if(((unsigned)(src[3] - src[4] + dcOffset)) < dcThreshold) numEq++;
+ if(((unsigned)(src[4] - src[5] + dcOffset)) < dcThreshold) numEq++;
+ if(((unsigned)(src[5] - src[6] + dcOffset)) < dcThreshold) numEq++;
+ if(((unsigned)(src[6] - src[7] + dcOffset)) < dcThreshold) numEq++;
+ src+= stride;
+ }
+ return numEq > c->ppMode.flatnessThreshold;
+}
+
+/**
+ * Check if the middle 8x8 Block in the given 8x16 block is flat
+ */
+static inline int isVertDC_C(uint8_t src[], int stride, PPContext *c){
+ int numEq= 0;
+ int y;
+ const int dcOffset= ((c->nonBQP*c->ppMode.baseDcDiff)>>8) + 1;
+ const int dcThreshold= dcOffset*2 + 1;
+
+ src+= stride*4; // src points to begin of the 8x8 Block
+ for(y=0; y<BLOCK_SIZE-1; y++)
+ {
+ if(((unsigned)(src[0] - src[0+stride] + dcOffset)) < dcThreshold) numEq++;
+ if(((unsigned)(src[1] - src[1+stride] + dcOffset)) < dcThreshold) numEq++;
+ if(((unsigned)(src[2] - src[2+stride] + dcOffset)) < dcThreshold) numEq++;
+ if(((unsigned)(src[3] - src[3+stride] + dcOffset)) < dcThreshold) numEq++;
+ if(((unsigned)(src[4] - src[4+stride] + dcOffset)) < dcThreshold) numEq++;
+ if(((unsigned)(src[5] - src[5+stride] + dcOffset)) < dcThreshold) numEq++;
+ if(((unsigned)(src[6] - src[6+stride] + dcOffset)) < dcThreshold) numEq++;
+ if(((unsigned)(src[7] - src[7+stride] + dcOffset)) < dcThreshold) numEq++;
+ src+= stride;
+ }
+ return numEq > c->ppMode.flatnessThreshold;
+}
+
+static inline int isHorizMinMaxOk_C(uint8_t src[], int stride, int QP)
+{
+ int i;
+#if 1
+ for(i=0; i<2; i++){
+ if((unsigned)(src[0] - src[5] + 2*QP) > 4*QP) return 0;
+ src += stride;
+ if((unsigned)(src[2] - src[7] + 2*QP) > 4*QP) return 0;
+ src += stride;
+ if((unsigned)(src[4] - src[1] + 2*QP) > 4*QP) return 0;
+ src += stride;
+ if((unsigned)(src[6] - src[3] + 2*QP) > 4*QP) return 0;
+ src += stride;
+ }
+#else
+ for(i=0; i<8; i++){
+ if((unsigned)(src[0] - src[7] + 2*QP) > 4*QP) return 0;
+ src += stride;
+ }
+#endif
+ return 1;
+}
+
+static inline int isVertMinMaxOk_C(uint8_t src[], int stride, int QP)
+{
+#if 1
+#if 1
+ int x;
+ src+= stride*4;
+ for(x=0; x<BLOCK_SIZE; x+=4)
+ {
+ if((unsigned)(src[ x + 0*stride] - src[ x + 5*stride] + 2*QP) > 4*QP) return 0;
+ if((unsigned)(src[1+x + 2*stride] - src[1+x + 7*stride] + 2*QP) > 4*QP) return 0;
+ if((unsigned)(src[2+x + 4*stride] - src[2+x + 1*stride] + 2*QP) > 4*QP) return 0;
+ if((unsigned)(src[3+x + 6*stride] - src[3+x + 3*stride] + 2*QP) > 4*QP) return 0;
+ }
+#else
+ int x;
+ src+= stride*3;
+ for(x=0; x<BLOCK_SIZE; x++)
+ {
+ if((unsigned)(src[x + stride] - src[x + (stride<<3)] + 2*QP) > 4*QP) return 0;
+ }
+#endif
+ return 1;
+#else
+ int x;
+ src+= stride*4;
+ for(x=0; x<BLOCK_SIZE; x++)
+ {
+ int min=255;
+ int max=0;
+ int y;
+ for(y=0; y<8; y++){
+ int v= src[x + y*stride];
+ if(v>max) max=v;
+ if(v<min) min=v;
+ }
+ if(max-min > 2*QP) return 0;
+ }
+ return 1;
+#endif
+}
+
+static inline int horizClassify_C(uint8_t src[], int stride, PPContext *c){
+ if( isHorizDC_C(src, stride, c) ){
+ if( isHorizMinMaxOk_C(src, stride, c->QP) )
+ return 1;
+ else
+ return 0;
+ }else{
+ return 2;
+ }
+}
+
+static inline int vertClassify_C(uint8_t src[], int stride, PPContext *c){
+ if( isVertDC_C(src, stride, c) ){
+ if( isVertMinMaxOk_C(src, stride, c->QP) )
+ return 1;
+ else
+ return 0;
+ }else{
+ return 2;
+ }
+}
+
+static inline void doHorizDefFilter_C(uint8_t dst[], int stride, PPContext *c)
+{
+ int y;
+ for(y=0; y<BLOCK_SIZE; y++)
+ {
+ const int middleEnergy= 5*(dst[4] - dst[3]) + 2*(dst[2] - dst[5]);
+
+ if(FFABS(middleEnergy) < 8*c->QP)
+ {
+ const int q=(dst[3] - dst[4])/2;
+ const int leftEnergy= 5*(dst[2] - dst[1]) + 2*(dst[0] - dst[3]);
+ const int rightEnergy= 5*(dst[6] - dst[5]) + 2*(dst[4] - dst[7]);
+
+ int d= FFABS(middleEnergy) - FFMIN( FFABS(leftEnergy), FFABS(rightEnergy) );
+ d= FFMAX(d, 0);
+
+ d= (5*d + 32) >> 6;
+ d*= FFSIGN(-middleEnergy);
+
+ if(q>0)
+ {
+ d= d<0 ? 0 : d;
+ d= d>q ? q : d;
+ }
+ else
+ {
+ d= d>0 ? 0 : d;
+ d= d<q ? q : d;
+ }
+
+ dst[3]-= d;
+ dst[4]+= d;
+ }
+ dst+= stride;
+ }
+}
+
+/**
+ * Do a horizontal low pass filter on the 10x8 block (dst points to middle 8x8 Block)
+ * using the 9-Tap Filter (1,1,2,2,4,2,2,1,1)/16 (C version)
+ */
+static inline void doHorizLowPass_C(uint8_t dst[], int stride, PPContext *c)
+{
+ int y;
+ for(y=0; y<BLOCK_SIZE; y++)
+ {
+ const int first= FFABS(dst[-1] - dst[0]) < c->QP ? dst[-1] : dst[0];
+ const int last= FFABS(dst[8] - dst[7]) < c->QP ? dst[8] : dst[7];
+
+ int sums[10];
+ sums[0] = 4*first + dst[0] + dst[1] + dst[2] + 4;
+ sums[1] = sums[0] - first + dst[3];
+ sums[2] = sums[1] - first + dst[4];
+ sums[3] = sums[2] - first + dst[5];
+ sums[4] = sums[3] - first + dst[6];
+ sums[5] = sums[4] - dst[0] + dst[7];
+ sums[6] = sums[5] - dst[1] + last;
+ sums[7] = sums[6] - dst[2] + last;
+ sums[8] = sums[7] - dst[3] + last;
+ sums[9] = sums[8] - dst[4] + last;
+
+ dst[0]= (sums[0] + sums[2] + 2*dst[0])>>4;
+ dst[1]= (sums[1] + sums[3] + 2*dst[1])>>4;
+ dst[2]= (sums[2] + sums[4] + 2*dst[2])>>4;
+ dst[3]= (sums[3] + sums[5] + 2*dst[3])>>4;
+ dst[4]= (sums[4] + sums[6] + 2*dst[4])>>4;
+ dst[5]= (sums[5] + sums[7] + 2*dst[5])>>4;
+ dst[6]= (sums[6] + sums[8] + 2*dst[6])>>4;
+ dst[7]= (sums[7] + sums[9] + 2*dst[7])>>4;
+
+ dst+= stride;
+ }
+}
+
+/**
+ * Experimental Filter 1 (Horizontal)
+ * will not damage linear gradients
+ * Flat blocks should look like they where passed through the (1,1,2,2,4,2,2,1,1) 9-Tap filter
+ * can only smooth blocks at the expected locations (it cant smooth them if they did move)
+ * MMX2 version does correct clipping C version doesnt
+ * not identical with the vertical one
+ */
+static inline void horizX1Filter(uint8_t *src, int stride, int QP)
+{
+ int y;
+ static uint64_t *lut= NULL;
+ if(lut==NULL)
+ {
+ int i;
+ lut = av_malloc(256*8);
+ for(i=0; i<256; i++)
+ {
+ int v= i < 128 ? 2*i : 2*(i-256);
+/*
+//Simulate 112242211 9-Tap filter
+ uint64_t a= (v/16) & 0xFF;
+ uint64_t b= (v/8) & 0xFF;
+ uint64_t c= (v/4) & 0xFF;
+ uint64_t d= (3*v/8) & 0xFF;
+*/
+//Simulate piecewise linear interpolation
+ uint64_t a= (v/16) & 0xFF;
+ uint64_t b= (v*3/16) & 0xFF;
+ uint64_t c= (v*5/16) & 0xFF;
+ uint64_t d= (7*v/16) & 0xFF;
+ uint64_t A= (0x100 - a)&0xFF;
+ uint64_t B= (0x100 - b)&0xFF;
+ uint64_t C= (0x100 - c)&0xFF;
+ uint64_t D= (0x100 - c)&0xFF;
+
+ lut[i] = (a<<56) | (b<<48) | (c<<40) | (d<<32) |
+ (D<<24) | (C<<16) | (B<<8) | (A);
+ //lut[i] = (v<<32) | (v<<24);
+ }
+ }
+
+ for(y=0; y<BLOCK_SIZE; y++)
+ {
+ int a= src[1] - src[2];
+ int b= src[3] - src[4];
+ int c= src[5] - src[6];
+
+ int d= FFMAX(FFABS(b) - (FFABS(a) + FFABS(c))/2, 0);
+
+ if(d < QP)
+ {
+ int v = d * FFSIGN(-b);
+
+ src[1] +=v/8;
+ src[2] +=v/4;
+ src[3] +=3*v/8;
+ src[4] -=3*v/8;
+ src[5] -=v/4;
+ src[6] -=v/8;
+
+ }
+ src+=stride;
+ }
+}
+
+/**
+ * accurate deblock filter
+ */
+static av_always_inline void do_a_deblock_C(uint8_t *src, int step, int stride, PPContext *c){
+ int y;
+ const int QP= c->QP;
+ const int dcOffset= ((c->nonBQP*c->ppMode.baseDcDiff)>>8) + 1;
+ const int dcThreshold= dcOffset*2 + 1;
+//START_TIMER
+ src+= step*4; // src points to begin of the 8x8 Block
+ for(y=0; y<8; y++){
+ int numEq= 0;
+
+ if(((unsigned)(src[-1*step] - src[0*step] + dcOffset)) < dcThreshold) numEq++;
+ if(((unsigned)(src[ 0*step] - src[1*step] + dcOffset)) < dcThreshold) numEq++;
+ if(((unsigned)(src[ 1*step] - src[2*step] + dcOffset)) < dcThreshold) numEq++;
+ if(((unsigned)(src[ 2*step] - src[3*step] + dcOffset)) < dcThreshold) numEq++;
+ if(((unsigned)(src[ 3*step] - src[4*step] + dcOffset)) < dcThreshold) numEq++;
+ if(((unsigned)(src[ 4*step] - src[5*step] + dcOffset)) < dcThreshold) numEq++;
+ if(((unsigned)(src[ 5*step] - src[6*step] + dcOffset)) < dcThreshold) numEq++;
+ if(((unsigned)(src[ 6*step] - src[7*step] + dcOffset)) < dcThreshold) numEq++;
+ if(((unsigned)(src[ 7*step] - src[8*step] + dcOffset)) < dcThreshold) numEq++;
+ if(numEq > c->ppMode.flatnessThreshold){
+ int min, max, x;
+
+ if(src[0] > src[step]){
+ max= src[0];
+ min= src[step];
+ }else{
+ max= src[step];
+ min= src[0];
+ }
+ for(x=2; x<8; x+=2){
+ if(src[x*step] > src[(x+1)*step]){
+ if(src[x *step] > max) max= src[ x *step];
+ if(src[(x+1)*step] < min) min= src[(x+1)*step];
+ }else{
+ if(src[(x+1)*step] > max) max= src[(x+1)*step];
+ if(src[ x *step] < min) min= src[ x *step];
+ }
+ }
+ if(max-min < 2*QP){
+ const int first= FFABS(src[-1*step] - src[0]) < QP ? src[-1*step] : src[0];
+ const int last= FFABS(src[8*step] - src[7*step]) < QP ? src[8*step] : src[7*step];
+
+ int sums[10];
+ sums[0] = 4*first + src[0*step] + src[1*step] + src[2*step] + 4;
+ sums[1] = sums[0] - first + src[3*step];
+ sums[2] = sums[1] - first + src[4*step];
+ sums[3] = sums[2] - first + src[5*step];
+ sums[4] = sums[3] - first + src[6*step];
+ sums[5] = sums[4] - src[0*step] + src[7*step];
+ sums[6] = sums[5] - src[1*step] + last;
+ sums[7] = sums[6] - src[2*step] + last;
+ sums[8] = sums[7] - src[3*step] + last;
+ sums[9] = sums[8] - src[4*step] + last;
+
+ src[0*step]= (sums[0] + sums[2] + 2*src[0*step])>>4;
+ src[1*step]= (sums[1] + sums[3] + 2*src[1*step])>>4;
+ src[2*step]= (sums[2] + sums[4] + 2*src[2*step])>>4;
+ src[3*step]= (sums[3] + sums[5] + 2*src[3*step])>>4;
+ src[4*step]= (sums[4] + sums[6] + 2*src[4*step])>>4;
+ src[5*step]= (sums[5] + sums[7] + 2*src[5*step])>>4;
+ src[6*step]= (sums[6] + sums[8] + 2*src[6*step])>>4;
+ src[7*step]= (sums[7] + sums[9] + 2*src[7*step])>>4;
+ }
+ }else{
+ const int middleEnergy= 5*(src[4*step] - src[3*step]) + 2*(src[2*step] - src[5*step]);
+
+ if(FFABS(middleEnergy) < 8*QP)
+ {
+ const int q=(src[3*step] - src[4*step])/2;
+ const int leftEnergy= 5*(src[2*step] - src[1*step]) + 2*(src[0*step] - src[3*step]);
+ const int rightEnergy= 5*(src[6*step] - src[5*step]) + 2*(src[4*step] - src[7*step]);
+
+ int d= FFABS(middleEnergy) - FFMIN( FFABS(leftEnergy), FFABS(rightEnergy) );
+ d= FFMAX(d, 0);
+
+ d= (5*d + 32) >> 6;
+ d*= FFSIGN(-middleEnergy);
+
+ if(q>0)
+ {
+ d= d<0 ? 0 : d;
+ d= d>q ? q : d;
+ }
+ else
+ {
+ d= d>0 ? 0 : d;
+ d= d<q ? q : d;
+ }
+
+ src[3*step]-= d;
+ src[4*step]+= d;
+ }
+ }
+
+ src += stride;
+ }
+/*if(step==16){
+ STOP_TIMER("step16")
+}else{
+ STOP_TIMER("stepX")
+}*/
+}
+
+//Note: we have C, MMX, MMX2, 3DNOW version there is no 3DNOW+MMX2 one
+//Plain C versions
+#if !defined (HAVE_MMX) || defined (RUNTIME_CPUDETECT)
+#define COMPILE_C
+#endif
+
+#ifdef ARCH_POWERPC
+#ifdef HAVE_ALTIVEC
+#define COMPILE_ALTIVEC
+#endif //HAVE_ALTIVEC
+#endif //ARCH_POWERPC
+
+#if defined(ARCH_X86)
+
+#if (defined (HAVE_MMX) && !defined (HAVE_3DNOW) && !defined (HAVE_MMX2)) || defined (RUNTIME_CPUDETECT)
+#define COMPILE_MMX
+#endif
+
+#if defined (HAVE_MMX2) || defined (RUNTIME_CPUDETECT)
+#define COMPILE_MMX2
+#endif
+
+#if (defined (HAVE_3DNOW) && !defined (HAVE_MMX2)) || defined (RUNTIME_CPUDETECT)
+#define COMPILE_3DNOW
+#endif
+#endif /* defined(ARCH_X86) */
+
+#undef HAVE_MMX
+#undef HAVE_MMX2
+#undef HAVE_3DNOW
+#undef HAVE_ALTIVEC
+
+#ifdef COMPILE_C
+#undef HAVE_MMX
+#undef HAVE_MMX2
+#undef HAVE_3DNOW
+#define RENAME(a) a ## _C
+#include "postprocess_template.c"
+#endif
+
+#ifdef ARCH_POWERPC
+#ifdef COMPILE_ALTIVEC
+#undef RENAME
+#define HAVE_ALTIVEC
+#define RENAME(a) a ## _altivec
+#include "postprocess_altivec_template.c"
+#include "postprocess_template.c"
+#endif
+#endif //ARCH_POWERPC
+
+//MMX versions
+#ifdef COMPILE_MMX
+#undef RENAME
+#define HAVE_MMX
+#undef HAVE_MMX2
+#undef HAVE_3DNOW
+#define RENAME(a) a ## _MMX
+#include "postprocess_template.c"
+#endif
+
+//MMX2 versions
+#ifdef COMPILE_MMX2
+#undef RENAME
+#define HAVE_MMX
+#define HAVE_MMX2
+#undef HAVE_3DNOW
+#define RENAME(a) a ## _MMX2
+#include "postprocess_template.c"
+#endif
+
+//3DNOW versions
+#ifdef COMPILE_3DNOW
+#undef RENAME
+#define HAVE_MMX
+#undef HAVE_MMX2
+#define HAVE_3DNOW
+#define RENAME(a) a ## _3DNow
+#include "postprocess_template.c"
+#endif
+
+// minor note: the HAVE_xyz is messed up after that line so dont use it
+
+static inline void postProcess(uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height,
+ QP_STORE_T QPs[], int QPStride, int isColor, pp_mode_t *vm, pp_context_t *vc)
+{
+ PPContext *c= (PPContext *)vc;
+ PPMode *ppMode= (PPMode *)vm;
+ c->ppMode= *ppMode; //FIXME
+
+ // useing ifs here as they are faster than function pointers allthough the
+ // difference wouldnt be messureable here but its much better because
+ // someone might exchange the cpu whithout restarting mplayer ;)
+#ifdef RUNTIME_CPUDETECT
+#if defined(ARCH_X86)
+ // ordered per speed fasterst first
+ if(c->cpuCaps & PP_CPU_CAPS_MMX2)
+ postProcess_MMX2(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
+ else if(c->cpuCaps & PP_CPU_CAPS_3DNOW)
+ postProcess_3DNow(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
+ else if(c->cpuCaps & PP_CPU_CAPS_MMX)
+ postProcess_MMX(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
+ else
+ postProcess_C(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
+#else
+#ifdef ARCH_POWERPC
+#ifdef HAVE_ALTIVEC
+ if(c->cpuCaps & PP_CPU_CAPS_ALTIVEC)
+ postProcess_altivec(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
+ else
+#endif
+#endif
+ postProcess_C(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
+#endif
+#else //RUNTIME_CPUDETECT
+#ifdef HAVE_MMX2
+ postProcess_MMX2(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
+#elif defined (HAVE_3DNOW)
+ postProcess_3DNow(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
+#elif defined (HAVE_MMX)
+ postProcess_MMX(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
+#elif defined (HAVE_ALTIVEC)
+ postProcess_altivec(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
+#else
+ postProcess_C(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
+#endif
+#endif //!RUNTIME_CPUDETECT
+}
+
+//static void postProcess(uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height,
+// QP_STORE_T QPs[], int QPStride, int isColor, struct PPMode *ppMode);
+
+/* -pp Command line Help
+*/
+char *pp_help=
+"Available postprocessing filters:\n"
+"Filters Options\n"
+"short long name short long option Description\n"
+"* * a autoq CPU power dependent enabler\n"
+" c chrom chrominance filtering enabled\n"
+" y nochrom chrominance filtering disabled\n"
+" n noluma luma filtering disabled\n"
+"hb hdeblock (2 threshold) horizontal deblocking filter\n"
+" 1. difference factor: default=32, higher -> more deblocking\n"
+" 2. flatness threshold: default=39, lower -> more deblocking\n"
+" the h & v deblocking filters share these\n"
+" so you can't set different thresholds for h / v\n"
+"vb vdeblock (2 threshold) vertical deblocking filter\n"
+"ha hadeblock (2 threshold) horizontal deblocking filter\n"
+"va vadeblock (2 threshold) vertical deblocking filter\n"
+"h1 x1hdeblock experimental h deblock filter 1\n"
+"v1 x1vdeblock experimental v deblock filter 1\n"
+"dr dering deringing filter\n"
+"al autolevels automatic brightness / contrast\n"
+" f fullyrange stretch luminance to (0..255)\n"
+"lb linblenddeint linear blend deinterlacer\n"
+"li linipoldeint linear interpolating deinterlace\n"
+"ci cubicipoldeint cubic interpolating deinterlacer\n"
+"md mediandeint median deinterlacer\n"
+"fd ffmpegdeint ffmpeg deinterlacer\n"
+"l5 lowpass5 FIR lowpass deinterlacer\n"
+"de default hb:a,vb:a,dr:a\n"
+"fa fast h1:a,v1:a,dr:a\n"
+"ac ha:a:128:7,va:a,dr:a\n"
+"tn tmpnoise (3 threshold) temporal noise reducer\n"
+" 1. <= 2. <= 3. larger -> stronger filtering\n"
+"fq forceQuant <quantizer> force quantizer\n"
+"Usage:\n"
+"<filterName>[:<option>[:<option>...]][[,|/][-]<filterName>[:<option>...]]...\n"
+"long form example:\n"
+"vdeblock:autoq/hdeblock:autoq/linblenddeint default,-vdeblock\n"
+"short form example:\n"
+"vb:a/hb:a/lb de,-vb\n"
+"more examples:\n"
+"tn:64:128:256\n"
+"\n"
+;
+
+pp_mode_t *pp_get_mode_by_name_and_quality(char *name, int quality)
+{
+ char temp[GET_MODE_BUFFER_SIZE];
+ char *p= temp;
+ const char *filterDelimiters= ",/";
+ const char *optionDelimiters= ":";
+ struct PPMode *ppMode;
+ char *filterToken;
+
+ ppMode= av_malloc(sizeof(PPMode));
+
+ ppMode->lumMode= 0;
+ ppMode->chromMode= 0;
+ ppMode->maxTmpNoise[0]= 700;
+ ppMode->maxTmpNoise[1]= 1500;
+ ppMode->maxTmpNoise[2]= 3000;
+ ppMode->maxAllowedY= 234;
+ ppMode->minAllowedY= 16;
+ ppMode->baseDcDiff= 256/8;
+ ppMode->flatnessThreshold= 56-16-1;
+ ppMode->maxClippedThreshold= 0.01;
+ ppMode->error=0;
+
+ strncpy(temp, name, GET_MODE_BUFFER_SIZE);
+
+ av_log(NULL, AV_LOG_DEBUG, "pp: %s\n", name);
+
+ for(;;){
+ char *filterName;
+ int q= 1000000; //PP_QUALITY_MAX;
+ int chrom=-1;
+ int luma=-1;
+ char *option;
+ char *options[OPTIONS_ARRAY_SIZE];
+ int i;
+ int filterNameOk=0;
+ int numOfUnknownOptions=0;
+ int enable=1; //does the user want us to enabled or disabled the filter
+
+ filterToken= strtok(p, filterDelimiters);
+ if(filterToken == NULL) break;
+ p+= strlen(filterToken) + 1; // p points to next filterToken
+ filterName= strtok(filterToken, optionDelimiters);
+ av_log(NULL, AV_LOG_DEBUG, "pp: %s::%s\n", filterToken, filterName);
+
+ if(*filterName == '-')
+ {
+ enable=0;
+ filterName++;
+ }
+
+ for(;;){ //for all options
+ option= strtok(NULL, optionDelimiters);
+ if(option == NULL) break;
+
+ av_log(NULL, AV_LOG_DEBUG, "pp: option: %s\n", option);
+ if(!strcmp("autoq", option) || !strcmp("a", option)) q= quality;
+ else if(!strcmp("nochrom", option) || !strcmp("y", option)) chrom=0;
+ else if(!strcmp("chrom", option) || !strcmp("c", option)) chrom=1;
+ else if(!strcmp("noluma", option) || !strcmp("n", option)) luma=0;
+ else
+ {
+ options[numOfUnknownOptions] = option;
+ numOfUnknownOptions++;
+ }
+ if(numOfUnknownOptions >= OPTIONS_ARRAY_SIZE-1) break;
+ }
+ options[numOfUnknownOptions] = NULL;
+
+ /* replace stuff from the replace Table */
+ for(i=0; replaceTable[2*i]!=NULL; i++)
+ {
+ if(!strcmp(replaceTable[2*i], filterName))
+ {
+ int newlen= strlen(replaceTable[2*i + 1]);
+ int plen;
+ int spaceLeft;
+
+ if(p==NULL) p= temp, *p=0; //last filter
+ else p--, *p=','; //not last filter
+
+ plen= strlen(p);
+ spaceLeft= p - temp + plen;
+ if(spaceLeft + newlen >= GET_MODE_BUFFER_SIZE)
+ {
+ ppMode->error++;
+ break;
+ }
+ memmove(p + newlen, p, plen+1);
+ memcpy(p, replaceTable[2*i + 1], newlen);
+ filterNameOk=1;
+ }
+ }
+
+ for(i=0; filters[i].shortName!=NULL; i++)
+ {
+ if( !strcmp(filters[i].longName, filterName)
+ || !strcmp(filters[i].shortName, filterName))
+ {
+ ppMode->lumMode &= ~filters[i].mask;
+ ppMode->chromMode &= ~filters[i].mask;
+
+ filterNameOk=1;
+ if(!enable) break; // user wants to disable it
+
+ if(q >= filters[i].minLumQuality && luma)
+ ppMode->lumMode|= filters[i].mask;
+ if(chrom==1 || (chrom==-1 && filters[i].chromDefault))
+ if(q >= filters[i].minChromQuality)
+ ppMode->chromMode|= filters[i].mask;
+
+ if(filters[i].mask == LEVEL_FIX)
+ {
+ int o;
+ ppMode->minAllowedY= 16;
+ ppMode->maxAllowedY= 234;
+ for(o=0; options[o]!=NULL; o++)
+ {
+ if( !strcmp(options[o],"fullyrange")
+ ||!strcmp(options[o],"f"))
+ {
+ ppMode->minAllowedY= 0;
+ ppMode->maxAllowedY= 255;
+ numOfUnknownOptions--;
+ }
+ }
+ }
+ else if(filters[i].mask == TEMP_NOISE_FILTER)
+ {
+ int o;
+ int numOfNoises=0;
+
+ for(o=0; options[o]!=NULL; o++)
+ {
+ char *tail;
+ ppMode->maxTmpNoise[numOfNoises]=
+ strtol(options[o], &tail, 0);
+ if(tail!=options[o])
+ {
+ numOfNoises++;
+ numOfUnknownOptions--;
+ if(numOfNoises >= 3) break;
+ }
+ }
+ }
+ else if(filters[i].mask == V_DEBLOCK || filters[i].mask == H_DEBLOCK
+ || filters[i].mask == V_A_DEBLOCK || filters[i].mask == H_A_DEBLOCK)
+ {
+ int o;
+
+ for(o=0; options[o]!=NULL && o<2; o++)
+ {
+ char *tail;
+ int val= strtol(options[o], &tail, 0);
+ if(tail==options[o]) break;
+
+ numOfUnknownOptions--;
+ if(o==0) ppMode->baseDcDiff= val;
+ else ppMode->flatnessThreshold= val;
+ }
+ }
+ else if(filters[i].mask == FORCE_QUANT)
+ {
+ int o;
+ ppMode->forcedQuant= 15;
+
+ for(o=0; options[o]!=NULL && o<1; o++)
+ {
+ char *tail;
+ int val= strtol(options[o], &tail, 0);
+ if(tail==options[o]) break;
+
+ numOfUnknownOptions--;
+ ppMode->forcedQuant= val;
+ }
+ }
+ }
+ }
+ if(!filterNameOk) ppMode->error++;
+ ppMode->error += numOfUnknownOptions;
+ }
+
+ av_log(NULL, AV_LOG_DEBUG, "pp: lumMode=%X, chromMode=%X\n", ppMode->lumMode, ppMode->chromMode);
+ if(ppMode->error)
+ {
+ av_log(NULL, AV_LOG_ERROR, "%d errors in postprocess string \"%s\"\n", ppMode->error, name);
+ av_free(ppMode);
+ return NULL;
+ }
+ return ppMode;
+}
+
+void pp_free_mode(pp_mode_t *mode){
+ av_free(mode);
+}
+
+static void reallocAlign(void **p, int alignment, int size){
+ av_free(*p);
+ *p= av_mallocz(size);
+}
+
+static void reallocBuffers(PPContext *c, int width, int height, int stride, int qpStride){
+ int mbWidth = (width+15)>>4;
+ int mbHeight= (height+15)>>4;
+ int i;
+
+ c->stride= stride;
+ c->qpStride= qpStride;
+
+ reallocAlign((void **)&c->tempDst, 8, stride*24);
+ reallocAlign((void **)&c->tempSrc, 8, stride*24);
+ reallocAlign((void **)&c->tempBlocks, 8, 2*16*8);
+ reallocAlign((void **)&c->yHistogram, 8, 256*sizeof(uint64_t));
+ for(i=0; i<256; i++)
+ c->yHistogram[i]= width*height/64*15/256;
+
+ for(i=0; i<3; i++)
+ {
+ //Note:the +17*1024 is just there so i dont have to worry about r/w over te end
+ reallocAlign((void **)&c->tempBlured[i], 8, stride*mbHeight*16 + 17*1024);
+ reallocAlign((void **)&c->tempBluredPast[i], 8, 256*((height+7)&(~7))/2 + 17*1024);//FIXME size
+ }
+
+ reallocAlign((void **)&c->deintTemp, 8, 2*width+32);
+ reallocAlign((void **)&c->nonBQPTable, 8, qpStride*mbHeight*sizeof(QP_STORE_T));
+ reallocAlign((void **)&c->stdQPTable, 8, qpStride*mbHeight*sizeof(QP_STORE_T));
+ reallocAlign((void **)&c->forcedQPTable, 8, mbWidth*sizeof(QP_STORE_T));
+}
+
+static void global_init(void){
+ int i;
+ memset(clip_table, 0, 256);
+ for(i=256; i<512; i++)
+ clip_table[i]= i;
+ memset(clip_table+512, 0, 256);
+}
+
+static const char * context_to_name(void * ptr) {
+ return "postproc";
+}
+
+static AVClass av_codec_context_class = { "Postproc", context_to_name, NULL };
+
+pp_context_t *pp_get_context(int width, int height, int cpuCaps){
+ PPContext *c= av_malloc(sizeof(PPContext));
+ int stride= (width+15)&(~15); //assumed / will realloc if needed
+ int qpStride= (width+15)/16 + 2; //assumed / will realloc if needed
+
+ global_init();
+
+ memset(c, 0, sizeof(PPContext));
+ c->av_class = &av_codec_context_class;
+ c->cpuCaps= cpuCaps;
+ if(cpuCaps&PP_FORMAT){
+ c->hChromaSubSample= cpuCaps&0x3;
+ c->vChromaSubSample= (cpuCaps>>4)&0x3;
+ }else{
+ c->hChromaSubSample= 1;
+ c->vChromaSubSample= 1;
+ }
+
+ reallocBuffers(c, width, height, stride, qpStride);
+
+ c->frameNum=-1;
+
+ return c;
+}
+
+void pp_free_context(void *vc){
+ PPContext *c = (PPContext*)vc;
+ int i;
+
+ for(i=0; i<3; i++) av_free(c->tempBlured[i]);
+ for(i=0; i<3; i++) av_free(c->tempBluredPast[i]);
+
+ av_free(c->tempBlocks);
+ av_free(c->yHistogram);
+ av_free(c->tempDst);
+ av_free(c->tempSrc);
+ av_free(c->deintTemp);
+ av_free(c->stdQPTable);
+ av_free(c->nonBQPTable);
+ av_free(c->forcedQPTable);
+
+ memset(c, 0, sizeof(PPContext));
+
+ av_free(c);
+}
+
+void pp_postprocess(uint8_t * src[3], int srcStride[3],
+ uint8_t * dst[3], int dstStride[3],
+ int width, int height,
+ QP_STORE_T *QP_store, int QPStride,
+ pp_mode_t *vm, void *vc, int pict_type)
+{
+ int mbWidth = (width+15)>>4;
+ int mbHeight= (height+15)>>4;
+ PPMode *mode = (PPMode*)vm;
+ PPContext *c = (PPContext*)vc;
+ int minStride= FFMAX(FFABS(srcStride[0]), FFABS(dstStride[0]));
+ int absQPStride = FFABS(QPStride);
+
+ // c->stride and c->QPStride are always positive
+ if(c->stride < minStride || c->qpStride < absQPStride)
+ reallocBuffers(c, width, height,
+ FFMAX(minStride, c->stride),
+ FFMAX(c->qpStride, absQPStride));
+
+ if(QP_store==NULL || (mode->lumMode & FORCE_QUANT))
+ {
+ int i;
+ QP_store= c->forcedQPTable;
+ absQPStride = QPStride = 0;
+ if(mode->lumMode & FORCE_QUANT)
+ for(i=0; i<mbWidth; i++) QP_store[i]= mode->forcedQuant;
+ else
+ for(i=0; i<mbWidth; i++) QP_store[i]= 1;
+ }
+
+ if(pict_type & PP_PICT_TYPE_QP2){
+ int i;
+ const int count= mbHeight * absQPStride;
+ for(i=0; i<(count>>2); i++){
+ ((uint32_t*)c->stdQPTable)[i] = (((uint32_t*)QP_store)[i]>>1) & 0x7F7F7F7F;
+ }
+ for(i<<=2; i<count; i++){
+ c->stdQPTable[i] = QP_store[i]>>1;
+ }
+ QP_store= c->stdQPTable;
+ QPStride= absQPStride;
+ }
+
+if(0){
+int x,y;
+for(y=0; y<mbHeight; y++){
+ for(x=0; x<mbWidth; x++){
+ av_log(c, AV_LOG_INFO, "%2d ", QP_store[x + y*QPStride]);
+ }
+ av_log(c, AV_LOG_INFO, "\n");
+}
+ av_log(c, AV_LOG_INFO, "\n");
+}
+
+ if((pict_type&7)!=3)
+ {
+ if (QPStride >= 0) {
+ int i;
+ const int count= mbHeight * QPStride;
+ for(i=0; i<(count>>2); i++){
+ ((uint32_t*)c->nonBQPTable)[i] = ((uint32_t*)QP_store)[i] & 0x3F3F3F3F;
+ }
+ for(i<<=2; i<count; i++){
+ c->nonBQPTable[i] = QP_store[i] & 0x3F;
+ }
+ } else {
+ int i,j;
+ for(i=0; i<mbHeight; i++) {
+ for(j=0; j<absQPStride; j++) {
+ c->nonBQPTable[i*absQPStride+j] = QP_store[i*QPStride+j] & 0x3F;
+ }
+ }
+ }
+ }
+
+ av_log(c, AV_LOG_DEBUG, "using npp filters 0x%X/0x%X\n",
+ mode->lumMode, mode->chromMode);
+
+ postProcess(src[0], srcStride[0], dst[0], dstStride[0],
+ width, height, QP_store, QPStride, 0, mode, c);
+
+ width = (width )>>c->hChromaSubSample;
+ height = (height)>>c->vChromaSubSample;
+
+ if(mode->chromMode)
+ {
+ postProcess(src[1], srcStride[1], dst[1], dstStride[1],
+ width, height, QP_store, QPStride, 1, mode, c);
+ postProcess(src[2], srcStride[2], dst[2], dstStride[2],
+ width, height, QP_store, QPStride, 2, mode, c);
+ }
+ else if(srcStride[1] == dstStride[1] && srcStride[2] == dstStride[2])
+ {
+ linecpy(dst[1], src[1], height, srcStride[1]);
+ linecpy(dst[2], src[2], height, srcStride[2]);
+ }
+ else
+ {
+ int y;
+ for(y=0; y<height; y++)
+ {
+ memcpy(&(dst[1][y*dstStride[1]]), &(src[1][y*srcStride[1]]), width);
+ memcpy(&(dst[2][y*dstStride[2]]), &(src[2][y*srcStride[2]]), width);
+ }
+ }
+}
+
diff --git a/contrib/ffmpeg/libpostproc/postprocess.h b/contrib/ffmpeg/libpostproc/postprocess.h
new file mode 100644
index 000000000..eed92ba6d
--- /dev/null
+++ b/contrib/ffmpeg/libpostproc/postprocess.h
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2001-2003 Michael Niedermayer (michaelni@gmx.at)
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef NEWPOSTPROCESS_H
+#define NEWPOSTPROCESS_H
+
+/**
+ * @file postprocess.h
+ * @brief
+ * external api for the pp stuff
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define LIBPOSTPROC_VERSION_INT ((51<<16)+(1<<8)+0)
+#define LIBPOSTPROC_VERSION 51.1.0
+#define LIBPOSTPROC_BUILD LIBPOSTPROC_VERSION_INT
+
+#define LIBPOSTPROC_IDENT "postproc" AV_STRINGIFY(LIBPOSTPROC_VERSION)
+
+#define PP_QUALITY_MAX 6
+
+#define QP_STORE_T int8_t
+
+typedef void pp_context_t;
+typedef void pp_mode_t;
+
+extern char *pp_help; ///< a simple help text
+
+void pp_postprocess(uint8_t * src[3], int srcStride[3],
+ uint8_t * dst[3], int dstStride[3],
+ int horizontalSize, int verticalSize,
+ QP_STORE_T *QP_store, int QP_stride,
+ pp_mode_t *mode, pp_context_t *ppContext, int pict_type);
+
+
+/**
+ * returns a pp_mode_t or NULL if an error occured
+ * name is the string after "-pp" on the command line
+ * quality is a number from 0 to PP_QUALITY_MAX
+ */
+pp_mode_t *pp_get_mode_by_name_and_quality(char *name, int quality);
+void pp_free_mode(pp_mode_t *mode);
+
+pp_context_t *pp_get_context(int width, int height, int flags);
+void pp_free_context(pp_context_t *ppContext);
+
+#define PP_CPU_CAPS_MMX 0x80000000
+#define PP_CPU_CAPS_MMX2 0x20000000
+#define PP_CPU_CAPS_3DNOW 0x40000000
+#define PP_CPU_CAPS_ALTIVEC 0x10000000
+
+#define PP_FORMAT 0x00000008
+#define PP_FORMAT_420 (0x00000011|PP_FORMAT)
+#define PP_FORMAT_422 (0x00000001|PP_FORMAT)
+#define PP_FORMAT_411 (0x00000002|PP_FORMAT)
+#define PP_FORMAT_444 (0x00000000|PP_FORMAT)
+
+#define PP_PICT_TYPE_QP2 0x00000010 ///< MPEG2 style QScale
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/contrib/ffmpeg/libpostproc/postprocess_altivec_template.c b/contrib/ffmpeg/libpostproc/postprocess_altivec_template.c
new file mode 100644
index 000000000..6a76c0eb7
--- /dev/null
+++ b/contrib/ffmpeg/libpostproc/postprocess_altivec_template.c
@@ -0,0 +1,1192 @@
+/*
+ * AltiVec optimizations (C) 2004 Romain Dolbeau <romain@dolbeau.org>
+ *
+ * based on code by Copyright (C) 2001-2003 Michael Niedermayer (michaelni@gmx.at)
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avutil.h"
+
+#ifdef CONFIG_DARWIN
+#define AVV(x...) (x)
+#else
+#define AVV(x...) {x}
+#endif
+
+#define ALTIVEC_TRANSPOSE_8x8_SHORT(src_a,src_b,src_c,src_d,src_e,src_f,src_g,src_h) \
+ do { \
+ __typeof__(src_a) tempA1, tempB1, tempC1, tempD1; \
+ __typeof__(src_a) tempE1, tempF1, tempG1, tempH1; \
+ __typeof__(src_a) tempA2, tempB2, tempC2, tempD2; \
+ __typeof__(src_a) tempE2, tempF2, tempG2, tempH2; \
+ tempA1 = vec_mergeh (src_a, src_e); \
+ tempB1 = vec_mergel (src_a, src_e); \
+ tempC1 = vec_mergeh (src_b, src_f); \
+ tempD1 = vec_mergel (src_b, src_f); \
+ tempE1 = vec_mergeh (src_c, src_g); \
+ tempF1 = vec_mergel (src_c, src_g); \
+ tempG1 = vec_mergeh (src_d, src_h); \
+ tempH1 = vec_mergel (src_d, src_h); \
+ tempA2 = vec_mergeh (tempA1, tempE1); \
+ tempB2 = vec_mergel (tempA1, tempE1); \
+ tempC2 = vec_mergeh (tempB1, tempF1); \
+ tempD2 = vec_mergel (tempB1, tempF1); \
+ tempE2 = vec_mergeh (tempC1, tempG1); \
+ tempF2 = vec_mergel (tempC1, tempG1); \
+ tempG2 = vec_mergeh (tempD1, tempH1); \
+ tempH2 = vec_mergel (tempD1, tempH1); \
+ src_a = vec_mergeh (tempA2, tempE2); \
+ src_b = vec_mergel (tempA2, tempE2); \
+ src_c = vec_mergeh (tempB2, tempF2); \
+ src_d = vec_mergel (tempB2, tempF2); \
+ src_e = vec_mergeh (tempC2, tempG2); \
+ src_f = vec_mergel (tempC2, tempG2); \
+ src_g = vec_mergeh (tempD2, tempH2); \
+ src_h = vec_mergel (tempD2, tempH2); \
+ } while (0)
+
+
+static inline int vertClassify_altivec(uint8_t src[], int stride, PPContext *c) {
+ /*
+ this code makes no assumption on src or stride.
+ One could remove the recomputation of the perm
+ vector by assuming (stride % 16) == 0, unfortunately
+ this is not always true.
+ */
+ DECLARE_ALIGNED(16, short, data[8]);
+ int numEq;
+ uint8_t *src2 = src;
+ vector signed short v_dcOffset;
+ vector signed short v2QP;
+ vector unsigned short v4QP;
+ vector unsigned short v_dcThreshold;
+ const int properStride = (stride % 16);
+ const int srcAlign = ((unsigned long)src2 % 16);
+ const int two_vectors = ((srcAlign > 8) || properStride) ? 1 : 0;
+ const vector signed int zero = vec_splat_s32(0);
+ const vector signed short mask = vec_splat_s16(1);
+ vector signed int v_numEq = vec_splat_s32(0);
+
+ data[0] = ((c->nonBQP*c->ppMode.baseDcDiff)>>8) + 1;
+ data[1] = data[0] * 2 + 1;
+ data[2] = c->QP * 2;
+ data[3] = c->QP * 4;
+ vector signed short v_data = vec_ld(0, data);
+ v_dcOffset = vec_splat(v_data, 0);
+ v_dcThreshold = (vector unsigned short)vec_splat(v_data, 1);
+ v2QP = vec_splat(v_data, 2);
+ v4QP = (vector unsigned short)vec_splat(v_data, 3);
+
+ src2 += stride * 4;
+
+ vector signed short v_srcAss0, v_srcAss1, v_srcAss2, v_srcAss3, v_srcAss4, v_srcAss5, v_srcAss6, v_srcAss7;
+
+#define LOAD_LINE(i) \
+ register int j##i = i * stride; \
+ vector unsigned char perm##i = vec_lvsl(j##i, src2); \
+ const vector unsigned char v_srcA1##i = vec_ld(j##i, src2); \
+ vector unsigned char v_srcA2##i; \
+ if (two_vectors) \
+ v_srcA2##i = vec_ld(j##i + 16, src2); \
+ const vector unsigned char v_srcA##i = \
+ vec_perm(v_srcA1##i, v_srcA2##i, perm##i); \
+ v_srcAss##i = \
+ (vector signed short)vec_mergeh((vector signed char)zero, \
+ (vector signed char)v_srcA##i)
+
+#define LOAD_LINE_ALIGNED(i) \
+ register int j##i = i * stride; \
+ const vector unsigned char v_srcA##i = vec_ld(j##i, src2); \
+ v_srcAss##i = \
+ (vector signed short)vec_mergeh((vector signed char)zero, \
+ (vector signed char)v_srcA##i)
+
+ // special casing the aligned case is worthwhile, as all call from
+ // the (transposed) horizontable deblocks will be aligned, i naddition
+ // to the naturraly aligned vertical deblocks.
+ if (properStride && srcAlign) {
+ LOAD_LINE_ALIGNED(0);
+ LOAD_LINE_ALIGNED(1);
+ LOAD_LINE_ALIGNED(2);
+ LOAD_LINE_ALIGNED(3);
+ LOAD_LINE_ALIGNED(4);
+ LOAD_LINE_ALIGNED(5);
+ LOAD_LINE_ALIGNED(6);
+ LOAD_LINE_ALIGNED(7);
+ } else {
+ LOAD_LINE(0);
+ LOAD_LINE(1);
+ LOAD_LINE(2);
+ LOAD_LINE(3);
+ LOAD_LINE(4);
+ LOAD_LINE(5);
+ LOAD_LINE(6);
+ LOAD_LINE(7);
+ }
+#undef LOAD_LINE
+#undef LOAD_LINE_ALIGNED
+
+#define ITER(i, j) \
+ const vector signed short v_diff##i = \
+ vec_sub(v_srcAss##i, v_srcAss##j); \
+ const vector signed short v_sum##i = \
+ vec_add(v_diff##i, v_dcOffset); \
+ const vector signed short v_comp##i = \
+ (vector signed short)vec_cmplt((vector unsigned short)v_sum##i, \
+ v_dcThreshold); \
+ const vector signed short v_part##i = vec_and(mask, v_comp##i); \
+ v_numEq = vec_sum4s(v_part##i, v_numEq);
+
+ ITER(0, 1);
+ ITER(1, 2);
+ ITER(2, 3);
+ ITER(3, 4);
+ ITER(4, 5);
+ ITER(5, 6);
+ ITER(6, 7);
+#undef ITER
+
+ v_numEq = vec_sums(v_numEq, zero);
+
+ v_numEq = vec_splat(v_numEq, 3);
+ vec_ste(v_numEq, 0, &numEq);
+
+ if (numEq > c->ppMode.flatnessThreshold)
+ {
+ const vector unsigned char mmoP1 = (const vector unsigned char)
+ AVV(0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f,
+ 0x00, 0x01, 0x12, 0x13, 0x08, 0x09, 0x1A, 0x1B);
+ const vector unsigned char mmoP2 = (const vector unsigned char)
+ AVV(0x04, 0x05, 0x16, 0x17, 0x0C, 0x0D, 0x1E, 0x1F,
+ 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f);
+ const vector unsigned char mmoP = (const vector unsigned char)
+ vec_lvsl(8, (unsigned char*)0);
+
+ vector signed short mmoL1 = vec_perm(v_srcAss0, v_srcAss2, mmoP1);
+ vector signed short mmoL2 = vec_perm(v_srcAss4, v_srcAss6, mmoP2);
+ vector signed short mmoL = vec_perm(mmoL1, mmoL2, mmoP);
+ vector signed short mmoR1 = vec_perm(v_srcAss5, v_srcAss7, mmoP1);
+ vector signed short mmoR2 = vec_perm(v_srcAss1, v_srcAss3, mmoP2);
+ vector signed short mmoR = vec_perm(mmoR1, mmoR2, mmoP);
+ vector signed short mmoDiff = vec_sub(mmoL, mmoR);
+ vector unsigned short mmoSum = (vector unsigned short)vec_add(mmoDiff, v2QP);
+
+ if (vec_any_gt(mmoSum, v4QP))
+ return 0;
+ else
+ return 1;
+ }
+ else return 2;
+}
+
+static inline void doVertLowPass_altivec(uint8_t *src, int stride, PPContext *c) {
+ /*
+ this code makes no assumption on src or stride.
+ One could remove the recomputation of the perm
+ vector by assuming (stride % 16) == 0, unfortunately
+ this is not always true. Quite a lot of load/stores
+ can be removed by assuming proper alignement of
+ src & stride :-(
+ */
+ uint8_t *src2 = src;
+ const vector signed int zero = vec_splat_s32(0);
+ const int properStride = (stride % 16);
+ const int srcAlign = ((unsigned long)src2 % 16);
+ DECLARE_ALIGNED(16, short, qp[8]);
+ qp[0] = c->QP;
+ vector signed short vqp = vec_ld(0, qp);
+ vqp = vec_splat(vqp, 0);
+
+ src2 += stride*3;
+
+ vector signed short vb0, vb1, vb2, vb3, vb4, vb5, vb6, vb7, vb8, vb9;
+ vector unsigned char vbA0, vbA1, vbA2, vbA3, vbA4, vbA5, vbA6, vbA7, vbA8, vbA9;
+ vector unsigned char vbB0, vbB1, vbB2, vbB3, vbB4, vbB5, vbB6, vbB7, vbB8, vbB9;
+ vector unsigned char vbT0, vbT1, vbT2, vbT3, vbT4, vbT5, vbT6, vbT7, vbT8, vbT9;
+
+#define LOAD_LINE(i) \
+ const vector unsigned char perml##i = \
+ vec_lvsl(i * stride, src2); \
+ vbA##i = vec_ld(i * stride, src2); \
+ vbB##i = vec_ld(i * stride + 16, src2); \
+ vbT##i = vec_perm(vbA##i, vbB##i, perml##i); \
+ vb##i = \
+ (vector signed short)vec_mergeh((vector unsigned char)zero, \
+ (vector unsigned char)vbT##i)
+
+#define LOAD_LINE_ALIGNED(i) \
+ register int j##i = i * stride; \
+ vbT##i = vec_ld(j##i, src2); \
+ vb##i = \
+ (vector signed short)vec_mergeh((vector signed char)zero, \
+ (vector signed char)vbT##i)
+
+ // special casing the aligned case is worthwhile, as all call from
+ // the (transposed) horizontable deblocks will be aligned, in addition
+ // to the naturraly aligned vertical deblocks.
+ if (properStride && srcAlign) {
+ LOAD_LINE_ALIGNED(0);
+ LOAD_LINE_ALIGNED(1);
+ LOAD_LINE_ALIGNED(2);
+ LOAD_LINE_ALIGNED(3);
+ LOAD_LINE_ALIGNED(4);
+ LOAD_LINE_ALIGNED(5);
+ LOAD_LINE_ALIGNED(6);
+ LOAD_LINE_ALIGNED(7);
+ LOAD_LINE_ALIGNED(8);
+ LOAD_LINE_ALIGNED(9);
+ } else {
+ LOAD_LINE(0);
+ LOAD_LINE(1);
+ LOAD_LINE(2);
+ LOAD_LINE(3);
+ LOAD_LINE(4);
+ LOAD_LINE(5);
+ LOAD_LINE(6);
+ LOAD_LINE(7);
+ LOAD_LINE(8);
+ LOAD_LINE(9);
+ }
+#undef LOAD_LINE
+#undef LOAD_LINE_ALIGNED
+
+ const vector unsigned short v_2 = vec_splat_u16(2);
+ const vector unsigned short v_4 = vec_splat_u16(4);
+
+ const vector signed short v_diff01 = vec_sub(vb0, vb1);
+ const vector unsigned short v_cmp01 =
+ (const vector unsigned short) vec_cmplt(vec_abs(v_diff01), vqp);
+ const vector signed short v_first = vec_sel(vb1, vb0, v_cmp01);
+ const vector signed short v_diff89 = vec_sub(vb8, vb9);
+ const vector unsigned short v_cmp89 =
+ (const vector unsigned short) vec_cmplt(vec_abs(v_diff89), vqp);
+ const vector signed short v_last = vec_sel(vb8, vb9, v_cmp89);
+
+ const vector signed short temp01 = vec_mladd(v_first, (vector signed short)v_4, vb1);
+ const vector signed short temp02 = vec_add(vb2, vb3);
+ const vector signed short temp03 = vec_add(temp01, (vector signed short)v_4);
+ const vector signed short v_sumsB0 = vec_add(temp02, temp03);
+
+ const vector signed short temp11 = vec_sub(v_sumsB0, v_first);
+ const vector signed short v_sumsB1 = vec_add(temp11, vb4);
+
+ const vector signed short temp21 = vec_sub(v_sumsB1, v_first);
+ const vector signed short v_sumsB2 = vec_add(temp21, vb5);
+
+ const vector signed short temp31 = vec_sub(v_sumsB2, v_first);
+ const vector signed short v_sumsB3 = vec_add(temp31, vb6);
+
+ const vector signed short temp41 = vec_sub(v_sumsB3, v_first);
+ const vector signed short v_sumsB4 = vec_add(temp41, vb7);
+
+ const vector signed short temp51 = vec_sub(v_sumsB4, vb1);
+ const vector signed short v_sumsB5 = vec_add(temp51, vb8);
+
+ const vector signed short temp61 = vec_sub(v_sumsB5, vb2);
+ const vector signed short v_sumsB6 = vec_add(temp61, v_last);
+
+ const vector signed short temp71 = vec_sub(v_sumsB6, vb3);
+ const vector signed short v_sumsB7 = vec_add(temp71, v_last);
+
+ const vector signed short temp81 = vec_sub(v_sumsB7, vb4);
+ const vector signed short v_sumsB8 = vec_add(temp81, v_last);
+
+ const vector signed short temp91 = vec_sub(v_sumsB8, vb5);
+ const vector signed short v_sumsB9 = vec_add(temp91, v_last);
+
+#define COMPUTE_VR(i, j, k) \
+ const vector signed short temps1##i = \
+ vec_add(v_sumsB##i, v_sumsB##k); \
+ const vector signed short temps2##i = \
+ vec_mladd(vb##j, (vector signed short)v_2, temps1##i); \
+ const vector signed short vr##j = vec_sra(temps2##i, v_4)
+
+ COMPUTE_VR(0, 1, 2);
+ COMPUTE_VR(1, 2, 3);
+ COMPUTE_VR(2, 3, 4);
+ COMPUTE_VR(3, 4, 5);
+ COMPUTE_VR(4, 5, 6);
+ COMPUTE_VR(5, 6, 7);
+ COMPUTE_VR(6, 7, 8);
+ COMPUTE_VR(7, 8, 9);
+
+ const vector signed char neg1 = vec_splat_s8(-1);
+ const vector unsigned char permHH = (const vector unsigned char)AVV(0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F);
+
+#define PACK_AND_STORE(i) \
+ const vector unsigned char perms##i = \
+ vec_lvsr(i * stride, src2); \
+ const vector unsigned char vf##i = \
+ vec_packsu(vr##i, (vector signed short)zero); \
+ const vector unsigned char vg##i = \
+ vec_perm(vf##i, vbT##i, permHH); \
+ const vector unsigned char mask##i = \
+ vec_perm((vector unsigned char)zero, (vector unsigned char)neg1, perms##i); \
+ const vector unsigned char vg2##i = \
+ vec_perm(vg##i, vg##i, perms##i); \
+ const vector unsigned char svA##i = \
+ vec_sel(vbA##i, vg2##i, mask##i); \
+ const vector unsigned char svB##i = \
+ vec_sel(vg2##i, vbB##i, mask##i); \
+ vec_st(svA##i, i * stride, src2); \
+ vec_st(svB##i, i * stride + 16, src2)
+
+#define PACK_AND_STORE_ALIGNED(i) \
+ const vector unsigned char vf##i = \
+ vec_packsu(vr##i, (vector signed short)zero); \
+ const vector unsigned char vg##i = \
+ vec_perm(vf##i, vbT##i, permHH); \
+ vec_st(vg##i, i * stride, src2)
+
+ // special casing the aligned case is worthwhile, as all call from
+ // the (transposed) horizontable deblocks will be aligned, in addition
+ // to the naturraly aligned vertical deblocks.
+ if (properStride && srcAlign) {
+ PACK_AND_STORE_ALIGNED(1);
+ PACK_AND_STORE_ALIGNED(2);
+ PACK_AND_STORE_ALIGNED(3);
+ PACK_AND_STORE_ALIGNED(4);
+ PACK_AND_STORE_ALIGNED(5);
+ PACK_AND_STORE_ALIGNED(6);
+ PACK_AND_STORE_ALIGNED(7);
+ PACK_AND_STORE_ALIGNED(8);
+ } else {
+ PACK_AND_STORE(1);
+ PACK_AND_STORE(2);
+ PACK_AND_STORE(3);
+ PACK_AND_STORE(4);
+ PACK_AND_STORE(5);
+ PACK_AND_STORE(6);
+ PACK_AND_STORE(7);
+ PACK_AND_STORE(8);
+ }
+#undef PACK_AND_STORE
+#undef PACK_AND_STORE_ALIGNED
+}
+
+
+
+static inline void doVertDefFilter_altivec(uint8_t src[], int stride, PPContext *c) {
+ /*
+ this code makes no assumption on src or stride.
+ One could remove the recomputation of the perm
+ vector by assuming (stride % 16) == 0, unfortunately
+ this is not always true. Quite a lot of load/stores
+ can be removed by assuming proper alignement of
+ src & stride :-(
+ */
+ uint8_t *src2 = src;
+ const vector signed int zero = vec_splat_s32(0);
+ DECLARE_ALIGNED(16, short, qp[8]);
+ qp[0] = 8*c->QP;
+ vector signed short vqp = vec_ld(0, qp);
+ vqp = vec_splat(vqp, 0);
+
+#define LOAD_LINE(i) \
+ const vector unsigned char perm##i = \
+ vec_lvsl(i * stride, src2); \
+ const vector unsigned char vbA##i = \
+ vec_ld(i * stride, src2); \
+ const vector unsigned char vbB##i = \
+ vec_ld(i * stride + 16, src2); \
+ const vector unsigned char vbT##i = \
+ vec_perm(vbA##i, vbB##i, perm##i); \
+ const vector signed short vb##i = \
+ (vector signed short)vec_mergeh((vector unsigned char)zero, \
+ (vector unsigned char)vbT##i)
+
+ src2 += stride*3;
+
+ LOAD_LINE(1);
+ LOAD_LINE(2);
+ LOAD_LINE(3);
+ LOAD_LINE(4);
+ LOAD_LINE(5);
+ LOAD_LINE(6);
+ LOAD_LINE(7);
+ LOAD_LINE(8);
+#undef LOAD_LINE
+
+ const vector signed short v_1 = vec_splat_s16(1);
+ const vector signed short v_2 = vec_splat_s16(2);
+ const vector signed short v_5 = vec_splat_s16(5);
+ const vector signed short v_32 = vec_sl(v_1,
+ (vector unsigned short)v_5);
+ /* middle energy */
+ const vector signed short l3minusl6 = vec_sub(vb3, vb6);
+ const vector signed short l5minusl4 = vec_sub(vb5, vb4);
+ const vector signed short twotimes_l3minusl6 = vec_mladd(v_2, l3minusl6, (vector signed short)zero);
+ const vector signed short mE = vec_mladd(v_5, l5minusl4, twotimes_l3minusl6);
+ const vector signed short absmE = vec_abs(mE);
+ /* left & right energy */
+ const vector signed short l1minusl4 = vec_sub(vb1, vb4);
+ const vector signed short l3minusl2 = vec_sub(vb3, vb2);
+ const vector signed short l5minusl8 = vec_sub(vb5, vb8);
+ const vector signed short l7minusl6 = vec_sub(vb7, vb6);
+ const vector signed short twotimes_l1minusl4 = vec_mladd(v_2, l1minusl4, (vector signed short)zero);
+ const vector signed short twotimes_l5minusl8 = vec_mladd(v_2, l5minusl8, (vector signed short)zero);
+ const vector signed short lE = vec_mladd(v_5, l3minusl2, twotimes_l1minusl4);
+ const vector signed short rE = vec_mladd(v_5, l7minusl6, twotimes_l5minusl8);
+ /* d */
+ const vector signed short ddiff = vec_sub(absmE,
+ vec_min(vec_abs(lE),
+ vec_abs(rE)));
+ const vector signed short ddiffclamp = vec_max(ddiff, (vector signed short)zero);
+ const vector signed short dtimes64 = vec_mladd(v_5, ddiffclamp, v_32);
+ const vector signed short d = vec_sra(dtimes64, vec_splat_u16(6));
+ const vector signed short minusd = vec_sub((vector signed short)zero, d);
+ const vector signed short finald = vec_sel(minusd,
+ d,
+ vec_cmpgt(vec_sub((vector signed short)zero, mE),
+ (vector signed short)zero));
+ /* q */
+ const vector signed short qtimes2 = vec_sub(vb4, vb5);
+ /* for a shift right to behave like /2, we need to add one
+ to all negative integer */
+ const vector signed short rounddown = vec_sel((vector signed short)zero,
+ v_1,
+ vec_cmplt(qtimes2, (vector signed short)zero));
+ const vector signed short q = vec_sra(vec_add(qtimes2, rounddown), vec_splat_u16(1));
+ /* clamp */
+ const vector signed short dclamp_P1 = vec_max((vector signed short)zero, finald);
+ const vector signed short dclamp_P = vec_min(dclamp_P1, q);
+ const vector signed short dclamp_N1 = vec_min((vector signed short)zero, finald);
+ const vector signed short dclamp_N = vec_max(dclamp_N1, q);
+
+ const vector signed short dclampedfinal = vec_sel(dclamp_N,
+ dclamp_P,
+ vec_cmpgt(q, (vector signed short)zero));
+ const vector signed short dornotd = vec_sel((vector signed short)zero,
+ dclampedfinal,
+ vec_cmplt(absmE, vqp));
+ /* add/substract to l4 and l5 */
+ const vector signed short vb4minusd = vec_sub(vb4, dornotd);
+ const vector signed short vb5plusd = vec_add(vb5, dornotd);
+ /* finally, stores */
+ const vector unsigned char st4 = vec_packsu(vb4minusd, (vector signed short)zero);
+ const vector unsigned char st5 = vec_packsu(vb5plusd, (vector signed short)zero);
+
+ const vector signed char neg1 = vec_splat_s8(-1);
+ const vector unsigned char permHH = (const vector unsigned char)AVV(0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F);
+
+#define STORE(i) \
+ const vector unsigned char perms##i = \
+ vec_lvsr(i * stride, src2); \
+ const vector unsigned char vg##i = \
+ vec_perm(st##i, vbT##i, permHH); \
+ const vector unsigned char mask##i = \
+ vec_perm((vector unsigned char)zero, (vector unsigned char)neg1, perms##i); \
+ const vector unsigned char vg2##i = \
+ vec_perm(vg##i, vg##i, perms##i); \
+ const vector unsigned char svA##i = \
+ vec_sel(vbA##i, vg2##i, mask##i); \
+ const vector unsigned char svB##i = \
+ vec_sel(vg2##i, vbB##i, mask##i); \
+ vec_st(svA##i, i * stride, src2); \
+ vec_st(svB##i, i * stride + 16, src2)
+
+ STORE(4);
+ STORE(5);
+}
+
+static inline void dering_altivec(uint8_t src[], int stride, PPContext *c) {
+ /*
+ this code makes no assumption on src or stride.
+ One could remove the recomputation of the perm
+ vector by assuming (stride % 16) == 0, unfortunately
+ this is not always true. Quite a lot of load/stores
+ can be removed by assuming proper alignement of
+ src & stride :-(
+ */
+ uint8_t *srcCopy = src;
+ DECLARE_ALIGNED(16, uint8_t, dt[16]);
+ const vector signed int zero = vec_splat_s32(0);
+ vector unsigned char v_dt;
+ dt[0] = deringThreshold;
+ v_dt = vec_splat(vec_ld(0, dt), 0);
+
+#define LOAD_LINE(i) \
+ const vector unsigned char perm##i = \
+ vec_lvsl(i * stride, srcCopy); \
+ vector unsigned char sA##i = vec_ld(i * stride, srcCopy); \
+ vector unsigned char sB##i = vec_ld(i * stride + 16, srcCopy); \
+ vector unsigned char src##i = vec_perm(sA##i, sB##i, perm##i)
+
+ LOAD_LINE(0);
+ LOAD_LINE(1);
+ LOAD_LINE(2);
+ LOAD_LINE(3);
+ LOAD_LINE(4);
+ LOAD_LINE(5);
+ LOAD_LINE(6);
+ LOAD_LINE(7);
+ LOAD_LINE(8);
+ LOAD_LINE(9);
+#undef LOAD_LINE
+
+ vector unsigned char v_avg;
+ {
+ const vector unsigned char trunc_perm = (vector unsigned char)
+ AVV(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
+ 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18);
+ const vector unsigned char trunc_src12 = vec_perm(src1, src2, trunc_perm);
+ const vector unsigned char trunc_src34 = vec_perm(src3, src4, trunc_perm);
+ const vector unsigned char trunc_src56 = vec_perm(src5, src6, trunc_perm);
+ const vector unsigned char trunc_src78 = vec_perm(src7, src8, trunc_perm);
+
+#define EXTRACT(op) do { \
+ const vector unsigned char s##op##_1 = vec_##op(trunc_src12, trunc_src34); \
+ const vector unsigned char s##op##_2 = vec_##op(trunc_src56, trunc_src78); \
+ const vector unsigned char s##op##_6 = vec_##op(s##op##_1, s##op##_2); \
+ const vector unsigned char s##op##_8h = vec_mergeh(s##op##_6, s##op##_6); \
+ const vector unsigned char s##op##_8l = vec_mergel(s##op##_6, s##op##_6); \
+ const vector unsigned char s##op##_9 = vec_##op(s##op##_8h, s##op##_8l); \
+ const vector unsigned char s##op##_9h = vec_mergeh(s##op##_9, s##op##_9); \
+ const vector unsigned char s##op##_9l = vec_mergel(s##op##_9, s##op##_9); \
+ const vector unsigned char s##op##_10 = vec_##op(s##op##_9h, s##op##_9l); \
+ const vector unsigned char s##op##_10h = vec_mergeh(s##op##_10, s##op##_10); \
+ const vector unsigned char s##op##_10l = vec_mergel(s##op##_10, s##op##_10); \
+ const vector unsigned char s##op##_11 = vec_##op(s##op##_10h, s##op##_10l); \
+ const vector unsigned char s##op##_11h = vec_mergeh(s##op##_11, s##op##_11); \
+ const vector unsigned char s##op##_11l = vec_mergel(s##op##_11, s##op##_11); \
+ v_##op = vec_##op(s##op##_11h, s##op##_11l); } while (0)
+
+ vector unsigned char v_min;
+ vector unsigned char v_max;
+ EXTRACT(min);
+ EXTRACT(max);
+#undef EXTRACT
+
+ if (vec_all_lt(vec_sub(v_max, v_min), v_dt))
+ return;
+
+ v_avg = vec_avg(v_min, v_max);
+ }
+
+ DECLARE_ALIGNED(16, signed int, S[8]);
+ {
+ const vector unsigned short mask1 = (vector unsigned short)
+ AVV(0x0001, 0x0002, 0x0004, 0x0008,
+ 0x0010, 0x0020, 0x0040, 0x0080);
+ const vector unsigned short mask2 = (vector unsigned short)
+ AVV(0x0100, 0x0200, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000);
+
+ const vector unsigned int vuint32_16 = vec_sl(vec_splat_u32(1), vec_splat_u32(4));
+ const vector unsigned int vuint32_1 = vec_splat_u32(1);
+
+#define COMPARE(i) \
+ vector signed int sum##i; \
+ do { \
+ const vector unsigned char cmp##i = \
+ (vector unsigned char)vec_cmpgt(src##i, v_avg); \
+ const vector unsigned short cmpHi##i = \
+ (vector unsigned short)vec_mergeh(cmp##i, cmp##i); \
+ const vector unsigned short cmpLi##i = \
+ (vector unsigned short)vec_mergel(cmp##i, cmp##i); \
+ const vector signed short cmpHf##i = \
+ (vector signed short)vec_and(cmpHi##i, mask1); \
+ const vector signed short cmpLf##i = \
+ (vector signed short)vec_and(cmpLi##i, mask2); \
+ const vector signed int sump##i = vec_sum4s(cmpHf##i, zero); \
+ const vector signed int sumq##i = vec_sum4s(cmpLf##i, sump##i); \
+ sum##i = vec_sums(sumq##i, zero); } while (0)
+
+ COMPARE(0);
+ COMPARE(1);
+ COMPARE(2);
+ COMPARE(3);
+ COMPARE(4);
+ COMPARE(5);
+ COMPARE(6);
+ COMPARE(7);
+ COMPARE(8);
+ COMPARE(9);
+#undef COMPARE
+
+ vector signed int sumA2;
+ vector signed int sumB2;
+ {
+ const vector signed int sump02 = vec_mergel(sum0, sum2);
+ const vector signed int sump13 = vec_mergel(sum1, sum3);
+ const vector signed int sumA = vec_mergel(sump02, sump13);
+
+ const vector signed int sump46 = vec_mergel(sum4, sum6);
+ const vector signed int sump57 = vec_mergel(sum5, sum7);
+ const vector signed int sumB = vec_mergel(sump46, sump57);
+
+ const vector signed int sump8A = vec_mergel(sum8, zero);
+ const vector signed int sump9B = vec_mergel(sum9, zero);
+ const vector signed int sumC = vec_mergel(sump8A, sump9B);
+
+ const vector signed int tA = vec_sl(vec_nor(zero, sumA), vuint32_16);
+ const vector signed int tB = vec_sl(vec_nor(zero, sumB), vuint32_16);
+ const vector signed int tC = vec_sl(vec_nor(zero, sumC), vuint32_16);
+ const vector signed int t2A = vec_or(sumA, tA);
+ const vector signed int t2B = vec_or(sumB, tB);
+ const vector signed int t2C = vec_or(sumC, tC);
+ const vector signed int t3A = vec_and(vec_sra(t2A, vuint32_1),
+ vec_sl(t2A, vuint32_1));
+ const vector signed int t3B = vec_and(vec_sra(t2B, vuint32_1),
+ vec_sl(t2B, vuint32_1));
+ const vector signed int t3C = vec_and(vec_sra(t2C, vuint32_1),
+ vec_sl(t2C, vuint32_1));
+ const vector signed int yA = vec_and(t2A, t3A);
+ const vector signed int yB = vec_and(t2B, t3B);
+ const vector signed int yC = vec_and(t2C, t3C);
+
+ const vector unsigned char strangeperm1 = vec_lvsl(4, (unsigned char*)0);
+ const vector unsigned char strangeperm2 = vec_lvsl(8, (unsigned char*)0);
+ const vector signed int sumAd4 = vec_perm(yA, yB, strangeperm1);
+ const vector signed int sumAd8 = vec_perm(yA, yB, strangeperm2);
+ const vector signed int sumBd4 = vec_perm(yB, yC, strangeperm1);
+ const vector signed int sumBd8 = vec_perm(yB, yC, strangeperm2);
+ const vector signed int sumAp = vec_and(yA,
+ vec_and(sumAd4,sumAd8));
+ const vector signed int sumBp = vec_and(yB,
+ vec_and(sumBd4,sumBd8));
+ sumA2 = vec_or(sumAp,
+ vec_sra(sumAp,
+ vuint32_16));
+ sumB2 = vec_or(sumBp,
+ vec_sra(sumBp,
+ vuint32_16));
+ }
+ vec_st(sumA2, 0, S);
+ vec_st(sumB2, 16, S);
+ }
+
+ /* I'm not sure the following is actually faster
+ than straight, unvectorized C code :-( */
+
+ DECLARE_ALIGNED(16, int, tQP2[4]);
+ tQP2[0]= c->QP/2 + 1;
+ vector signed int vQP2 = vec_ld(0, tQP2);
+ vQP2 = vec_splat(vQP2, 0);
+ const vector signed int vsint32_8 = vec_splat_s32(8);
+ const vector unsigned int vuint32_4 = vec_splat_u32(4);
+
+ const vector unsigned char permA1 = (vector unsigned char)
+ AVV(0x00, 0x01, 0x02, 0x10, 0x11, 0x12, 0x1F, 0x1F,
+ 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F);
+ const vector unsigned char permA2 = (vector unsigned char)
+ AVV(0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x10, 0x11,
+ 0x12, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F);
+ const vector unsigned char permA1inc = (vector unsigned char)
+ AVV(0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
+ const vector unsigned char permA2inc = (vector unsigned char)
+ AVV(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
+ const vector unsigned char magic = (vector unsigned char)
+ AVV(0x01, 0x02, 0x01, 0x02, 0x04, 0x02, 0x01, 0x02,
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
+ const vector unsigned char extractPerm = (vector unsigned char)
+ AVV(0x10, 0x10, 0x10, 0x01, 0x10, 0x10, 0x10, 0x01,
+ 0x10, 0x10, 0x10, 0x01, 0x10, 0x10, 0x10, 0x01);
+ const vector unsigned char extractPermInc = (vector unsigned char)
+ AVV(0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
+ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01);
+ const vector unsigned char identity = vec_lvsl(0,(unsigned char *)0);
+ const vector unsigned char tenRight = (vector unsigned char)
+ AVV(0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
+ const vector unsigned char eightLeft = (vector unsigned char)
+ AVV(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08);
+
+
+#define F_INIT(i) \
+ vector unsigned char tenRightM##i = tenRight; \
+ vector unsigned char permA1M##i = permA1; \
+ vector unsigned char permA2M##i = permA2; \
+ vector unsigned char extractPermM##i = extractPerm
+
+#define F2(i, j, k, l) \
+ if (S[i] & (1 << (l+1))) { \
+ const vector unsigned char a_##j##_A##l = \
+ vec_perm(src##i, src##j, permA1M##i); \
+ const vector unsigned char a_##j##_B##l = \
+ vec_perm(a_##j##_A##l, src##k, permA2M##i); \
+ const vector signed int a_##j##_sump##l = \
+ (vector signed int)vec_msum(a_##j##_B##l, magic, \
+ (vector unsigned int)zero); \
+ vector signed int F_##j##_##l = \
+ vec_sr(vec_sums(a_##j##_sump##l, vsint32_8), vuint32_4); \
+ F_##j##_##l = vec_splat(F_##j##_##l, 3); \
+ const vector signed int p_##j##_##l = \
+ (vector signed int)vec_perm(src##j, \
+ (vector unsigned char)zero, \
+ extractPermM##i); \
+ const vector signed int sum_##j##_##l = vec_add( p_##j##_##l, vQP2);\
+ const vector signed int diff_##j##_##l = vec_sub( p_##j##_##l, vQP2);\
+ vector signed int newpm_##j##_##l; \
+ if (vec_all_lt(sum_##j##_##l, F_##j##_##l)) \
+ newpm_##j##_##l = sum_##j##_##l; \
+ else if (vec_all_gt(diff_##j##_##l, F_##j##_##l)) \
+ newpm_##j##_##l = diff_##j##_##l; \
+ else newpm_##j##_##l = F_##j##_##l; \
+ const vector unsigned char newpm2_##j##_##l = \
+ vec_splat((vector unsigned char)newpm_##j##_##l, 15); \
+ const vector unsigned char mask##j##l = vec_add(identity, \
+ tenRightM##i); \
+ src##j = vec_perm(src##j, newpm2_##j##_##l, mask##j##l); \
+ } \
+ permA1M##i = vec_add(permA1M##i, permA1inc); \
+ permA2M##i = vec_add(permA2M##i, permA2inc); \
+ tenRightM##i = vec_sro(tenRightM##i, eightLeft); \
+ extractPermM##i = vec_add(extractPermM##i, extractPermInc)
+
+#define ITER(i, j, k) \
+ F_INIT(i); \
+ F2(i, j, k, 0); \
+ F2(i, j, k, 1); \
+ F2(i, j, k, 2); \
+ F2(i, j, k, 3); \
+ F2(i, j, k, 4); \
+ F2(i, j, k, 5); \
+ F2(i, j, k, 6); \
+ F2(i, j, k, 7)
+
+ ITER(0, 1, 2);
+ ITER(1, 2, 3);
+ ITER(2, 3, 4);
+ ITER(3, 4, 5);
+ ITER(4, 5, 6);
+ ITER(5, 6, 7);
+ ITER(6, 7, 8);
+ ITER(7, 8, 9);
+
+ const vector signed char neg1 = vec_splat_s8(-1);
+
+#define STORE_LINE(i) \
+ const vector unsigned char permST##i = \
+ vec_lvsr(i * stride, srcCopy); \
+ const vector unsigned char maskST##i = \
+ vec_perm((vector unsigned char)zero, \
+ (vector unsigned char)neg1, permST##i); \
+ src##i = vec_perm(src##i ,src##i, permST##i); \
+ sA##i= vec_sel(sA##i, src##i, maskST##i); \
+ sB##i= vec_sel(src##i, sB##i, maskST##i); \
+ vec_st(sA##i, i * stride, srcCopy); \
+ vec_st(sB##i, i * stride + 16, srcCopy)
+
+ STORE_LINE(1);
+ STORE_LINE(2);
+ STORE_LINE(3);
+ STORE_LINE(4);
+ STORE_LINE(5);
+ STORE_LINE(6);
+ STORE_LINE(7);
+ STORE_LINE(8);
+
+#undef STORE_LINE
+#undef ITER
+#undef F2
+}
+
+#define doHorizLowPass_altivec(a...) doHorizLowPass_C(a)
+#define doHorizDefFilter_altivec(a...) doHorizDefFilter_C(a)
+#define do_a_deblock_altivec(a...) do_a_deblock_C(a)
+
+static inline void RENAME(tempNoiseReducer)(uint8_t *src, int stride,
+ uint8_t *tempBlured, uint32_t *tempBluredPast, int *maxNoise)
+{
+ const vector signed int zero = vec_splat_s32(0);
+ const vector signed short vsint16_1 = vec_splat_s16(1);
+ vector signed int v_dp = zero;
+ vector signed int v_sysdp = zero;
+ int d, sysd, i;
+
+ tempBluredPast[127]= maxNoise[0];
+ tempBluredPast[128]= maxNoise[1];
+ tempBluredPast[129]= maxNoise[2];
+
+#define LOAD_LINE(src, i) \
+ register int j##src##i = i * stride; \
+ vector unsigned char perm##src##i = vec_lvsl(j##src##i, src); \
+ const vector unsigned char v_##src##A1##i = vec_ld(j##src##i, src); \
+ const vector unsigned char v_##src##A2##i = vec_ld(j##src##i + 16, src); \
+ const vector unsigned char v_##src##A##i = \
+ vec_perm(v_##src##A1##i, v_##src##A2##i, perm##src##i); \
+ vector signed short v_##src##Ass##i = \
+ (vector signed short)vec_mergeh((vector signed char)zero, \
+ (vector signed char)v_##src##A##i)
+
+ LOAD_LINE(src, 0);
+ LOAD_LINE(src, 1);
+ LOAD_LINE(src, 2);
+ LOAD_LINE(src, 3);
+ LOAD_LINE(src, 4);
+ LOAD_LINE(src, 5);
+ LOAD_LINE(src, 6);
+ LOAD_LINE(src, 7);
+
+ LOAD_LINE(tempBlured, 0);
+ LOAD_LINE(tempBlured, 1);
+ LOAD_LINE(tempBlured, 2);
+ LOAD_LINE(tempBlured, 3);
+ LOAD_LINE(tempBlured, 4);
+ LOAD_LINE(tempBlured, 5);
+ LOAD_LINE(tempBlured, 6);
+ LOAD_LINE(tempBlured, 7);
+#undef LOAD_LINE
+
+#define ACCUMULATE_DIFFS(i) \
+ vector signed short v_d##i = vec_sub(v_tempBluredAss##i, \
+ v_srcAss##i); \
+ v_dp = vec_msums(v_d##i, v_d##i, v_dp); \
+ v_sysdp = vec_msums(v_d##i, vsint16_1, v_sysdp)
+
+ ACCUMULATE_DIFFS(0);
+ ACCUMULATE_DIFFS(1);
+ ACCUMULATE_DIFFS(2);
+ ACCUMULATE_DIFFS(3);
+ ACCUMULATE_DIFFS(4);
+ ACCUMULATE_DIFFS(5);
+ ACCUMULATE_DIFFS(6);
+ ACCUMULATE_DIFFS(7);
+#undef ACCUMULATE_DIFFS
+
+ v_dp = vec_sums(v_dp, zero);
+ v_sysdp = vec_sums(v_sysdp, zero);
+
+ v_dp = vec_splat(v_dp, 3);
+ v_sysdp = vec_splat(v_sysdp, 3);
+
+ vec_ste(v_dp, 0, &d);
+ vec_ste(v_sysdp, 0, &sysd);
+
+ i = d;
+ d = (4*d
+ +(*(tempBluredPast-256))
+ +(*(tempBluredPast-1))+ (*(tempBluredPast+1))
+ +(*(tempBluredPast+256))
+ +4)>>3;
+
+ *tempBluredPast=i;
+
+ if (d > maxNoise[1]) {
+ if (d < maxNoise[2]) {
+#define OP(i) v_tempBluredAss##i = vec_avg(v_tempBluredAss##i, v_srcAss##i);
+
+ OP(0);
+ OP(1);
+ OP(2);
+ OP(3);
+ OP(4);
+ OP(5);
+ OP(6);
+ OP(7);
+#undef OP
+ } else {
+#define OP(i) v_tempBluredAss##i = v_srcAss##i;
+
+ OP(0);
+ OP(1);
+ OP(2);
+ OP(3);
+ OP(4);
+ OP(5);
+ OP(6);
+ OP(7);
+#undef OP
+ }
+ } else {
+ if (d < maxNoise[0]) {
+ const vector signed short vsint16_7 = vec_splat_s16(7);
+ const vector signed short vsint16_4 = vec_splat_s16(4);
+ const vector unsigned short vuint16_3 = vec_splat_u16(3);
+
+#define OP(i) \
+ const vector signed short v_temp##i = \
+ vec_mladd(v_tempBluredAss##i, \
+ vsint16_7, v_srcAss##i); \
+ const vector signed short v_temp2##i = \
+ vec_add(v_temp##i, vsint16_4); \
+ v_tempBluredAss##i = vec_sr(v_temp2##i, vuint16_3)
+
+ OP(0);
+ OP(1);
+ OP(2);
+ OP(3);
+ OP(4);
+ OP(5);
+ OP(6);
+ OP(7);
+#undef OP
+ } else {
+ const vector signed short vsint16_3 = vec_splat_s16(3);
+ const vector signed short vsint16_2 = vec_splat_s16(2);
+
+#define OP(i) \
+ const vector signed short v_temp##i = \
+ vec_mladd(v_tempBluredAss##i, \
+ vsint16_3, v_srcAss##i); \
+ const vector signed short v_temp2##i = \
+ vec_add(v_temp##i, vsint16_2); \
+ v_tempBluredAss##i = vec_sr(v_temp2##i, (vector unsigned short)vsint16_2)
+
+ OP(0);
+ OP(1);
+ OP(2);
+ OP(3);
+ OP(4);
+ OP(5);
+ OP(6);
+ OP(7);
+#undef OP
+ }
+ }
+
+ const vector signed char neg1 = vec_splat_s8(-1);
+ const vector unsigned char permHH = (const vector unsigned char)AVV(0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F);
+
+#define PACK_AND_STORE(src, i) \
+ const vector unsigned char perms##src##i = \
+ vec_lvsr(i * stride, src); \
+ const vector unsigned char vf##src##i = \
+ vec_packsu(v_tempBluredAss##i, (vector signed short)zero); \
+ const vector unsigned char vg##src##i = \
+ vec_perm(vf##src##i, v_##src##A##i, permHH); \
+ const vector unsigned char mask##src##i = \
+ vec_perm((vector unsigned char)zero, (vector unsigned char)neg1, perms##src##i); \
+ const vector unsigned char vg2##src##i = \
+ vec_perm(vg##src##i, vg##src##i, perms##src##i); \
+ const vector unsigned char svA##src##i = \
+ vec_sel(v_##src##A1##i, vg2##src##i, mask##src##i); \
+ const vector unsigned char svB##src##i = \
+ vec_sel(vg2##src##i, v_##src##A2##i, mask##src##i); \
+ vec_st(svA##src##i, i * stride, src); \
+ vec_st(svB##src##i, i * stride + 16, src)
+
+ PACK_AND_STORE(src, 0);
+ PACK_AND_STORE(src, 1);
+ PACK_AND_STORE(src, 2);
+ PACK_AND_STORE(src, 3);
+ PACK_AND_STORE(src, 4);
+ PACK_AND_STORE(src, 5);
+ PACK_AND_STORE(src, 6);
+ PACK_AND_STORE(src, 7);
+ PACK_AND_STORE(tempBlured, 0);
+ PACK_AND_STORE(tempBlured, 1);
+ PACK_AND_STORE(tempBlured, 2);
+ PACK_AND_STORE(tempBlured, 3);
+ PACK_AND_STORE(tempBlured, 4);
+ PACK_AND_STORE(tempBlured, 5);
+ PACK_AND_STORE(tempBlured, 6);
+ PACK_AND_STORE(tempBlured, 7);
+#undef PACK_AND_STORE
+}
+
+static inline void transpose_16x8_char_toPackedAlign_altivec(unsigned char* dst, unsigned char* src, int stride) {
+ const vector unsigned char zero = vec_splat_u8(0);
+
+#define LOAD_DOUBLE_LINE(i, j) \
+ vector unsigned char perm1##i = vec_lvsl(i * stride, src); \
+ vector unsigned char perm2##i = vec_lvsl(j * stride, src); \
+ vector unsigned char srcA##i = vec_ld(i * stride, src); \
+ vector unsigned char srcB##i = vec_ld(i * stride + 16, src); \
+ vector unsigned char srcC##i = vec_ld(j * stride, src); \
+ vector unsigned char srcD##i = vec_ld(j * stride+ 16, src); \
+ vector unsigned char src##i = vec_perm(srcA##i, srcB##i, perm1##i); \
+ vector unsigned char src##j = vec_perm(srcC##i, srcD##i, perm2##i)
+
+ LOAD_DOUBLE_LINE(0, 1);
+ LOAD_DOUBLE_LINE(2, 3);
+ LOAD_DOUBLE_LINE(4, 5);
+ LOAD_DOUBLE_LINE(6, 7);
+#undef LOAD_DOUBLE_LINE
+
+ vector unsigned char tempA = vec_mergeh(src0, zero);
+ vector unsigned char tempB = vec_mergel(src0, zero);
+ vector unsigned char tempC = vec_mergeh(src1, zero);
+ vector unsigned char tempD = vec_mergel(src1, zero);
+ vector unsigned char tempE = vec_mergeh(src2, zero);
+ vector unsigned char tempF = vec_mergel(src2, zero);
+ vector unsigned char tempG = vec_mergeh(src3, zero);
+ vector unsigned char tempH = vec_mergel(src3, zero);
+ vector unsigned char tempI = vec_mergeh(src4, zero);
+ vector unsigned char tempJ = vec_mergel(src4, zero);
+ vector unsigned char tempK = vec_mergeh(src5, zero);
+ vector unsigned char tempL = vec_mergel(src5, zero);
+ vector unsigned char tempM = vec_mergeh(src6, zero);
+ vector unsigned char tempN = vec_mergel(src6, zero);
+ vector unsigned char tempO = vec_mergeh(src7, zero);
+ vector unsigned char tempP = vec_mergel(src7, zero);
+
+ vector unsigned char temp0 = vec_mergeh(tempA, tempI);
+ vector unsigned char temp1 = vec_mergel(tempA, tempI);
+ vector unsigned char temp2 = vec_mergeh(tempB, tempJ);
+ vector unsigned char temp3 = vec_mergel(tempB, tempJ);
+ vector unsigned char temp4 = vec_mergeh(tempC, tempK);
+ vector unsigned char temp5 = vec_mergel(tempC, tempK);
+ vector unsigned char temp6 = vec_mergeh(tempD, tempL);
+ vector unsigned char temp7 = vec_mergel(tempD, tempL);
+ vector unsigned char temp8 = vec_mergeh(tempE, tempM);
+ vector unsigned char temp9 = vec_mergel(tempE, tempM);
+ vector unsigned char temp10 = vec_mergeh(tempF, tempN);
+ vector unsigned char temp11 = vec_mergel(tempF, tempN);
+ vector unsigned char temp12 = vec_mergeh(tempG, tempO);
+ vector unsigned char temp13 = vec_mergel(tempG, tempO);
+ vector unsigned char temp14 = vec_mergeh(tempH, tempP);
+ vector unsigned char temp15 = vec_mergel(tempH, tempP);
+
+ tempA = vec_mergeh(temp0, temp8);
+ tempB = vec_mergel(temp0, temp8);
+ tempC = vec_mergeh(temp1, temp9);
+ tempD = vec_mergel(temp1, temp9);
+ tempE = vec_mergeh(temp2, temp10);
+ tempF = vec_mergel(temp2, temp10);
+ tempG = vec_mergeh(temp3, temp11);
+ tempH = vec_mergel(temp3, temp11);
+ tempI = vec_mergeh(temp4, temp12);
+ tempJ = vec_mergel(temp4, temp12);
+ tempK = vec_mergeh(temp5, temp13);
+ tempL = vec_mergel(temp5, temp13);
+ tempM = vec_mergeh(temp6, temp14);
+ tempN = vec_mergel(temp6, temp14);
+ tempO = vec_mergeh(temp7, temp15);
+ tempP = vec_mergel(temp7, temp15);
+
+ temp0 = vec_mergeh(tempA, tempI);
+ temp1 = vec_mergel(tempA, tempI);
+ temp2 = vec_mergeh(tempB, tempJ);
+ temp3 = vec_mergel(tempB, tempJ);
+ temp4 = vec_mergeh(tempC, tempK);
+ temp5 = vec_mergel(tempC, tempK);
+ temp6 = vec_mergeh(tempD, tempL);
+ temp7 = vec_mergel(tempD, tempL);
+ temp8 = vec_mergeh(tempE, tempM);
+ temp9 = vec_mergel(tempE, tempM);
+ temp10 = vec_mergeh(tempF, tempN);
+ temp11 = vec_mergel(tempF, tempN);
+ temp12 = vec_mergeh(tempG, tempO);
+ temp13 = vec_mergel(tempG, tempO);
+ temp14 = vec_mergeh(tempH, tempP);
+ temp15 = vec_mergel(tempH, tempP);
+
+ vec_st(temp0, 0, dst);
+ vec_st(temp1, 16, dst);
+ vec_st(temp2, 32, dst);
+ vec_st(temp3, 48, dst);
+ vec_st(temp4, 64, dst);
+ vec_st(temp5, 80, dst);
+ vec_st(temp6, 96, dst);
+ vec_st(temp7, 112, dst);
+ vec_st(temp8, 128, dst);
+ vec_st(temp9, 144, dst);
+ vec_st(temp10, 160, dst);
+ vec_st(temp11, 176, dst);
+ vec_st(temp12, 192, dst);
+ vec_st(temp13, 208, dst);
+ vec_st(temp14, 224, dst);
+ vec_st(temp15, 240, dst);
+}
+
+static inline void transpose_8x16_char_fromPackedAlign_altivec(unsigned char* dst, unsigned char* src, int stride) {
+ const vector unsigned char zero = vec_splat_u8(0);
+
+#define LOAD_DOUBLE_LINE(i, j) \
+ vector unsigned char src##i = vec_ld(i * 16, src); \
+ vector unsigned char src##j = vec_ld(j * 16, src)
+
+ LOAD_DOUBLE_LINE(0, 1);
+ LOAD_DOUBLE_LINE(2, 3);
+ LOAD_DOUBLE_LINE(4, 5);
+ LOAD_DOUBLE_LINE(6, 7);
+ LOAD_DOUBLE_LINE(8, 9);
+ LOAD_DOUBLE_LINE(10, 11);
+ LOAD_DOUBLE_LINE(12, 13);
+ LOAD_DOUBLE_LINE(14, 15);
+#undef LOAD_DOUBLE_LINE
+
+ vector unsigned char tempA = vec_mergeh(src0, src8);
+ vector unsigned char tempB;
+ vector unsigned char tempC = vec_mergeh(src1, src9);
+ vector unsigned char tempD;
+ vector unsigned char tempE = vec_mergeh(src2, src10);
+ vector unsigned char tempG = vec_mergeh(src3, src11);
+ vector unsigned char tempI = vec_mergeh(src4, src12);
+ vector unsigned char tempJ;
+ vector unsigned char tempK = vec_mergeh(src5, src13);
+ vector unsigned char tempL;
+ vector unsigned char tempM = vec_mergeh(src6, src14);
+ vector unsigned char tempO = vec_mergeh(src7, src15);
+
+ vector unsigned char temp0 = vec_mergeh(tempA, tempI);
+ vector unsigned char temp1 = vec_mergel(tempA, tempI);
+ vector unsigned char temp2;
+ vector unsigned char temp3;
+ vector unsigned char temp4 = vec_mergeh(tempC, tempK);
+ vector unsigned char temp5 = vec_mergel(tempC, tempK);
+ vector unsigned char temp6;
+ vector unsigned char temp7;
+ vector unsigned char temp8 = vec_mergeh(tempE, tempM);
+ vector unsigned char temp9 = vec_mergel(tempE, tempM);
+ vector unsigned char temp12 = vec_mergeh(tempG, tempO);
+ vector unsigned char temp13 = vec_mergel(tempG, tempO);
+
+ tempA = vec_mergeh(temp0, temp8);
+ tempB = vec_mergel(temp0, temp8);
+ tempC = vec_mergeh(temp1, temp9);
+ tempD = vec_mergel(temp1, temp9);
+ tempI = vec_mergeh(temp4, temp12);
+ tempJ = vec_mergel(temp4, temp12);
+ tempK = vec_mergeh(temp5, temp13);
+ tempL = vec_mergel(temp5, temp13);
+
+ temp0 = vec_mergeh(tempA, tempI);
+ temp1 = vec_mergel(tempA, tempI);
+ temp2 = vec_mergeh(tempB, tempJ);
+ temp3 = vec_mergel(tempB, tempJ);
+ temp4 = vec_mergeh(tempC, tempK);
+ temp5 = vec_mergel(tempC, tempK);
+ temp6 = vec_mergeh(tempD, tempL);
+ temp7 = vec_mergel(tempD, tempL);
+
+
+ const vector signed char neg1 = vec_splat_s8(-1);
+#define STORE_DOUBLE_LINE(i, j) \
+ vector unsigned char dstA##i = vec_ld(i * stride, dst); \
+ vector unsigned char dstB##i = vec_ld(i * stride + 16, dst); \
+ vector unsigned char dstA##j = vec_ld(j * stride, dst); \
+ vector unsigned char dstB##j = vec_ld(j * stride+ 16, dst); \
+ vector unsigned char align##i = vec_lvsr(i * stride, dst); \
+ vector unsigned char align##j = vec_lvsr(j * stride, dst); \
+ vector unsigned char mask##i = vec_perm(zero, (vector unsigned char)neg1, align##i); \
+ vector unsigned char mask##j = vec_perm(zero, (vector unsigned char)neg1, align##j); \
+ vector unsigned char dstR##i = vec_perm(temp##i, temp##i, align##i); \
+ vector unsigned char dstR##j = vec_perm(temp##j, temp##j, align##j); \
+ vector unsigned char dstAF##i = vec_sel(dstA##i, dstR##i, mask##i); \
+ vector unsigned char dstBF##i = vec_sel(dstR##i, dstB##i, mask##i); \
+ vector unsigned char dstAF##j = vec_sel(dstA##j, dstR##j, mask##j); \
+ vector unsigned char dstBF##j = vec_sel(dstR##j, dstB##j, mask##j); \
+ vec_st(dstAF##i, i * stride, dst); \
+ vec_st(dstBF##i, i * stride + 16, dst); \
+ vec_st(dstAF##j, j * stride, dst); \
+ vec_st(dstBF##j, j * stride + 16, dst)
+
+ STORE_DOUBLE_LINE(0,1);
+ STORE_DOUBLE_LINE(2,3);
+ STORE_DOUBLE_LINE(4,5);
+ STORE_DOUBLE_LINE(6,7);
+}
diff --git a/contrib/ffmpeg/libpostproc/postprocess_internal.h b/contrib/ffmpeg/libpostproc/postprocess_internal.h
new file mode 100644
index 000000000..537d728c0
--- /dev/null
+++ b/contrib/ffmpeg/libpostproc/postprocess_internal.h
@@ -0,0 +1,183 @@
+/*
+ * Copyright (C) 2001-2002 Michael Niedermayer (michaelni@gmx.at)
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file postprocess_internal.h
+ * internal api header.
+ */
+
+#include "avutil.h"
+
+#define V_DEBLOCK 0x01
+#define H_DEBLOCK 0x02
+#define DERING 0x04
+#define LEVEL_FIX 0x08 ///< Brightness & Contrast
+
+#define LUM_V_DEBLOCK V_DEBLOCK // 1
+#define LUM_H_DEBLOCK H_DEBLOCK // 2
+#define CHROM_V_DEBLOCK (V_DEBLOCK<<4) // 16
+#define CHROM_H_DEBLOCK (H_DEBLOCK<<4) // 32
+#define LUM_DERING DERING // 4
+#define CHROM_DERING (DERING<<4) // 64
+#define LUM_LEVEL_FIX LEVEL_FIX // 8
+#define CHROM_LEVEL_FIX (LEVEL_FIX<<4) // 128 (not implemented yet)
+
+// Experimental vertical filters
+#define V_X1_FILTER 0x0200 // 512
+#define V_A_DEBLOCK 0x0400
+
+// Experimental horizontal filters
+#define H_X1_FILTER 0x2000 // 8192
+#define H_A_DEBLOCK 0x4000
+
+/// select between full y range (255-0) or standart one (234-16)
+#define FULL_Y_RANGE 0x8000 // 32768
+
+//Deinterlacing Filters
+#define LINEAR_IPOL_DEINT_FILTER 0x10000 // 65536
+#define LINEAR_BLEND_DEINT_FILTER 0x20000 // 131072
+#define CUBIC_BLEND_DEINT_FILTER 0x8000 // (not implemented yet)
+#define CUBIC_IPOL_DEINT_FILTER 0x40000 // 262144
+#define MEDIAN_DEINT_FILTER 0x80000 // 524288
+#define FFMPEG_DEINT_FILTER 0x400000
+#define LOWPASS5_DEINT_FILTER 0x800000
+
+#define TEMP_NOISE_FILTER 0x100000
+#define FORCE_QUANT 0x200000
+
+#if ( defined(__PIC__) || defined(__pic__) ) && ! defined(PIC)
+# define PIC
+#endif
+
+//use if u want a faster postprocessing code
+//cant differentiate between chroma & luma filters (both on or both off)
+//obviosly the -pp option at the commandline has no effect except turning the here selected
+//filters on
+//#define COMPILE_TIME_MODE 0x77
+
+#if 1
+static inline int CLIP(int a){
+ if(a&256) return ((a)>>31)^(-1);
+ else return a;
+}
+//#define CLIP(a) (((a)&256) ? ((a)>>31)^(-1) : (a))
+#elif 0
+#define CLIP(a) clip_tab[a]
+#else
+#define CLIP(a) (a)
+#endif
+/**
+ * Postprocessng filter.
+ */
+struct PPFilter{
+ const char *shortName;
+ const char *longName;
+ int chromDefault; ///< is chrominance filtering on by default if this filter is manually activated
+ int minLumQuality; ///< minimum quality to turn luminance filtering on
+ int minChromQuality; ///< minimum quality to turn chrominance filtering on
+ int mask; ///< Bitmask to turn this filter on
+};
+
+/**
+ * Postprocessng mode.
+ */
+typedef struct PPMode{
+ int lumMode; ///< acivates filters for luminance
+ int chromMode; ///< acivates filters for chrominance
+ int error; ///< non zero on error
+
+ int minAllowedY; ///< for brigtness correction
+ int maxAllowedY; ///< for brihtness correction
+ float maxClippedThreshold; ///< amount of "black" u r willing to loose to get a brightness corrected picture
+
+ int maxTmpNoise[3]; ///< for Temporal Noise Reducing filter (Maximal sum of abs differences)
+
+ int baseDcDiff;
+ int flatnessThreshold;
+
+ int forcedQuant; ///< quantizer if FORCE_QUANT is used
+} PPMode;
+
+/**
+ * postprocess context.
+ */
+typedef struct PPContext{
+ /**
+ * info on struct for av_log
+ */
+ AVClass *av_class;
+
+ uint8_t *tempBlocks; ///<used for the horizontal code
+
+ /**
+ * luma histogram.
+ * we need 64bit here otherwise we'll going to have a problem
+ * after watching a black picture for 5 hours
+ */
+ uint64_t *yHistogram;
+
+ DECLARE_ALIGNED(8, uint64_t, packedYOffset);
+ DECLARE_ALIGNED(8, uint64_t, packedYScale);
+
+ /** Temporal noise reducing buffers */
+ uint8_t *tempBlured[3];
+ int32_t *tempBluredPast[3];
+
+ /** Temporary buffers for handling the last row(s) */
+ uint8_t *tempDst;
+ uint8_t *tempSrc;
+
+ uint8_t *deintTemp;
+
+ DECLARE_ALIGNED(8, uint64_t, pQPb);
+ DECLARE_ALIGNED(8, uint64_t, pQPb2);
+
+ DECLARE_ALIGNED(8, uint64_t, mmxDcOffset[64]);
+ DECLARE_ALIGNED(8, uint64_t, mmxDcThreshold[64]);
+
+ QP_STORE_T *stdQPTable; ///< used to fix MPEG2 style qscale
+ QP_STORE_T *nonBQPTable;
+ QP_STORE_T *forcedQPTable;
+
+ int QP;
+ int nonBQP;
+
+ int frameNum;
+
+ int cpuCaps;
+
+ int qpStride; ///<size of qp buffers (needed to realloc them if needed)
+ int stride; ///<size of some buffers (needed to realloc them if needed)
+
+ int hChromaSubSample;
+ int vChromaSubSample;
+
+ PPMode ppMode;
+} PPContext;
+
+
+static inline void linecpy(void *dest, void *src, int lines, int stride)
+{
+ if (stride > 0) {
+ memcpy(dest, src, lines*stride);
+ } else {
+ memcpy(dest+(lines-1)*stride, src+(lines-1)*stride, -lines*stride);
+ }
+}
diff --git a/contrib/ffmpeg/libpostproc/postprocess_template.c b/contrib/ffmpeg/libpostproc/postprocess_template.c
new file mode 100644
index 000000000..f084130a6
--- /dev/null
+++ b/contrib/ffmpeg/libpostproc/postprocess_template.c
@@ -0,0 +1,3843 @@
+/*
+ * Copyright (C) 2001-2002 Michael Niedermayer (michaelni@gmx.at)
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+/**
+ * @file postprocess_template.c
+ * mmx/mmx2/3dnow postprocess code.
+ */
+
+
+#ifdef ARCH_X86_64
+# define REGa rax
+# define REGc rcx
+# define REGd rdx
+# define REG_a "rax"
+# define REG_c "rcx"
+# define REG_d "rdx"
+# define REG_SP "rsp"
+# define ALIGN_MASK "$0xFFFFFFFFFFFFFFF8"
+#else
+# define REGa eax
+# define REGc ecx
+# define REGd edx
+# define REG_a "eax"
+# define REG_c "ecx"
+# define REG_d "edx"
+# define REG_SP "esp"
+# define ALIGN_MASK "$0xFFFFFFF8"
+#endif
+
+
+#undef PAVGB
+#undef PMINUB
+#undef PMAXUB
+
+#ifdef HAVE_MMX2
+#define REAL_PAVGB(a,b) "pavgb " #a ", " #b " \n\t"
+#elif defined (HAVE_3DNOW)
+#define REAL_PAVGB(a,b) "pavgusb " #a ", " #b " \n\t"
+#endif
+#define PAVGB(a,b) REAL_PAVGB(a,b)
+
+#ifdef HAVE_MMX2
+#define PMINUB(a,b,t) "pminub " #a ", " #b " \n\t"
+#elif defined (HAVE_MMX)
+#define PMINUB(b,a,t) \
+ "movq " #a ", " #t " \n\t"\
+ "psubusb " #b ", " #t " \n\t"\
+ "psubb " #t ", " #a " \n\t"
+#endif
+
+#ifdef HAVE_MMX2
+#define PMAXUB(a,b) "pmaxub " #a ", " #b " \n\t"
+#elif defined (HAVE_MMX)
+#define PMAXUB(a,b) \
+ "psubusb " #a ", " #b " \n\t"\
+ "paddb " #a ", " #b " \n\t"
+#endif
+
+//FIXME? |255-0| = 1 (shouldnt be a problem ...)
+#ifdef HAVE_MMX
+/**
+ * Check if the middle 8x8 Block in the given 8x16 block is flat
+ */
+static inline int RENAME(vertClassify)(uint8_t src[], int stride, PPContext *c){
+ int numEq= 0, dcOk;
+ src+= stride*4; // src points to begin of the 8x8 Block
+asm volatile(
+ "movq %0, %%mm7 \n\t"
+ "movq %1, %%mm6 \n\t"
+ : : "m" (c->mmxDcOffset[c->nonBQP]), "m" (c->mmxDcThreshold[c->nonBQP])
+ );
+
+asm volatile(
+ "lea (%2, %3), %%"REG_a" \n\t"
+// 0 1 2 3 4 5 6 7 8 9
+// %1 eax eax+%2 eax+2%2 %1+4%2 ecx ecx+%2 ecx+2%2 %1+8%2 ecx+4%2
+
+ "movq (%2), %%mm0 \n\t"
+ "movq (%%"REG_a"), %%mm1 \n\t"
+ "movq %%mm0, %%mm3 \n\t"
+ "movq %%mm0, %%mm4 \n\t"
+ PMAXUB(%%mm1, %%mm4)
+ PMINUB(%%mm1, %%mm3, %%mm5)
+ "psubb %%mm1, %%mm0 \n\t" // mm0 = differnece
+ "paddb %%mm7, %%mm0 \n\t"
+ "pcmpgtb %%mm6, %%mm0 \n\t"
+
+ "movq (%%"REG_a",%3), %%mm2 \n\t"
+ PMAXUB(%%mm2, %%mm4)
+ PMINUB(%%mm2, %%mm3, %%mm5)
+ "psubb %%mm2, %%mm1 \n\t"
+ "paddb %%mm7, %%mm1 \n\t"
+ "pcmpgtb %%mm6, %%mm1 \n\t"
+ "paddb %%mm1, %%mm0 \n\t"
+
+ "movq (%%"REG_a", %3, 2), %%mm1 \n\t"
+ PMAXUB(%%mm1, %%mm4)
+ PMINUB(%%mm1, %%mm3, %%mm5)
+ "psubb %%mm1, %%mm2 \n\t"
+ "paddb %%mm7, %%mm2 \n\t"
+ "pcmpgtb %%mm6, %%mm2 \n\t"
+ "paddb %%mm2, %%mm0 \n\t"
+
+ "lea (%%"REG_a", %3, 4), %%"REG_a" \n\t"
+
+ "movq (%2, %3, 4), %%mm2 \n\t"
+ PMAXUB(%%mm2, %%mm4)
+ PMINUB(%%mm2, %%mm3, %%mm5)
+ "psubb %%mm2, %%mm1 \n\t"
+ "paddb %%mm7, %%mm1 \n\t"
+ "pcmpgtb %%mm6, %%mm1 \n\t"
+ "paddb %%mm1, %%mm0 \n\t"
+
+ "movq (%%"REG_a"), %%mm1 \n\t"
+ PMAXUB(%%mm1, %%mm4)
+ PMINUB(%%mm1, %%mm3, %%mm5)
+ "psubb %%mm1, %%mm2 \n\t"
+ "paddb %%mm7, %%mm2 \n\t"
+ "pcmpgtb %%mm6, %%mm2 \n\t"
+ "paddb %%mm2, %%mm0 \n\t"
+
+ "movq (%%"REG_a", %3), %%mm2 \n\t"
+ PMAXUB(%%mm2, %%mm4)
+ PMINUB(%%mm2, %%mm3, %%mm5)
+ "psubb %%mm2, %%mm1 \n\t"
+ "paddb %%mm7, %%mm1 \n\t"
+ "pcmpgtb %%mm6, %%mm1 \n\t"
+ "paddb %%mm1, %%mm0 \n\t"
+
+ "movq (%%"REG_a", %3, 2), %%mm1 \n\t"
+ PMAXUB(%%mm1, %%mm4)
+ PMINUB(%%mm1, %%mm3, %%mm5)
+ "psubb %%mm1, %%mm2 \n\t"
+ "paddb %%mm7, %%mm2 \n\t"
+ "pcmpgtb %%mm6, %%mm2 \n\t"
+ "paddb %%mm2, %%mm0 \n\t"
+ "psubusb %%mm3, %%mm4 \n\t"
+
+ " \n\t"
+#ifdef HAVE_MMX2
+ "pxor %%mm7, %%mm7 \n\t"
+ "psadbw %%mm7, %%mm0 \n\t"
+#else
+ "movq %%mm0, %%mm1 \n\t"
+ "psrlw $8, %%mm0 \n\t"
+ "paddb %%mm1, %%mm0 \n\t"
+ "movq %%mm0, %%mm1 \n\t"
+ "psrlq $16, %%mm0 \n\t"
+ "paddb %%mm1, %%mm0 \n\t"
+ "movq %%mm0, %%mm1 \n\t"
+ "psrlq $32, %%mm0 \n\t"
+ "paddb %%mm1, %%mm0 \n\t"
+#endif
+ "movq %4, %%mm7 \n\t" // QP,..., QP
+ "paddusb %%mm7, %%mm7 \n\t" // 2QP ... 2QP
+ "psubusb %%mm7, %%mm4 \n\t" // Diff <= 2QP -> 0
+ "packssdw %%mm4, %%mm4 \n\t"
+ "movd %%mm0, %0 \n\t"
+ "movd %%mm4, %1 \n\t"
+
+ : "=r" (numEq), "=r" (dcOk)
+ : "r" (src), "r" ((long)stride), "m" (c->pQPb)
+ : "%"REG_a
+ );
+
+ numEq= (-numEq) &0xFF;
+ if(numEq > c->ppMode.flatnessThreshold){
+ if(dcOk) return 0;
+ else return 1;
+ }else{
+ return 2;
+ }
+}
+#endif //HAVE_MMX
+
+/**
+ * Do a vertical low pass filter on the 8x16 block (only write to the 8x8 block in the middle)
+ * using the 9-Tap Filter (1,1,2,2,4,2,2,1,1)/16
+ */
+#ifndef HAVE_ALTIVEC
+static inline void RENAME(doVertLowPass)(uint8_t *src, int stride, PPContext *c)
+{
+#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+ src+= stride*3;
+ asm volatile( //"movv %0 %1 %2\n\t"
+ "movq %2, %%mm0 \n\t" // QP,..., QP
+ "pxor %%mm4, %%mm4 \n\t"
+
+ "movq (%0), %%mm6 \n\t"
+ "movq (%0, %1), %%mm5 \n\t"
+ "movq %%mm5, %%mm1 \n\t"
+ "movq %%mm6, %%mm2 \n\t"
+ "psubusb %%mm6, %%mm5 \n\t"
+ "psubusb %%mm1, %%mm2 \n\t"
+ "por %%mm5, %%mm2 \n\t" // ABS Diff of lines
+ "psubusb %%mm0, %%mm2 \n\t" // diff <= QP -> 0
+ "pcmpeqb %%mm4, %%mm2 \n\t" // diff <= QP -> FF
+
+ "pand %%mm2, %%mm6 \n\t"
+ "pandn %%mm1, %%mm2 \n\t"
+ "por %%mm2, %%mm6 \n\t"// First Line to Filter
+
+ "movq (%0, %1, 8), %%mm5 \n\t"
+ "lea (%0, %1, 4), %%"REG_a" \n\t"
+ "lea (%0, %1, 8), %%"REG_c" \n\t"
+ "sub %1, %%"REG_c" \n\t"
+ "add %1, %0 \n\t" // %0 points to line 1 not 0
+ "movq (%0, %1, 8), %%mm7 \n\t"
+ "movq %%mm5, %%mm1 \n\t"
+ "movq %%mm7, %%mm2 \n\t"
+ "psubusb %%mm7, %%mm5 \n\t"
+ "psubusb %%mm1, %%mm2 \n\t"
+ "por %%mm5, %%mm2 \n\t" // ABS Diff of lines
+ "psubusb %%mm0, %%mm2 \n\t" // diff <= QP -> 0
+ "pcmpeqb %%mm4, %%mm2 \n\t" // diff <= QP -> FF
+
+ "pand %%mm2, %%mm7 \n\t"
+ "pandn %%mm1, %%mm2 \n\t"
+ "por %%mm2, %%mm7 \n\t" // First Line to Filter
+
+
+ // 1 2 3 4 5 6 7 8
+ // %0 %0+%1 %0+2%1 eax %0+4%1 eax+2%1 ecx eax+4%1
+ // 6 4 2 2 1 1
+ // 6 4 4 2
+ // 6 8 2
+
+ "movq (%0, %1), %%mm0 \n\t" // 1
+ "movq %%mm0, %%mm1 \n\t" // 1
+ PAVGB(%%mm6, %%mm0) //1 1 /2
+ PAVGB(%%mm6, %%mm0) //3 1 /4
+
+ "movq (%0, %1, 4), %%mm2 \n\t" // 1
+ "movq %%mm2, %%mm5 \n\t" // 1
+ PAVGB((%%REGa), %%mm2) // 11 /2
+ PAVGB((%0, %1, 2), %%mm2) // 211 /4
+ "movq %%mm2, %%mm3 \n\t" // 211 /4
+ "movq (%0), %%mm4 \n\t" // 1
+ PAVGB(%%mm4, %%mm3) // 4 211 /8
+ PAVGB(%%mm0, %%mm3) //642211 /16
+ "movq %%mm3, (%0) \n\t" // X
+ // mm1=2 mm2=3(211) mm4=1 mm5=5 mm6=0 mm7=9
+ "movq %%mm1, %%mm0 \n\t" // 1
+ PAVGB(%%mm6, %%mm0) //1 1 /2
+ "movq %%mm4, %%mm3 \n\t" // 1
+ PAVGB((%0,%1,2), %%mm3) // 1 1 /2
+ PAVGB((%%REGa,%1,2), %%mm5) // 11 /2
+ PAVGB((%%REGa), %%mm5) // 211 /4
+ PAVGB(%%mm5, %%mm3) // 2 2211 /8
+ PAVGB(%%mm0, %%mm3) //4242211 /16
+ "movq %%mm3, (%0,%1) \n\t" // X
+ // mm1=2 mm2=3(211) mm4=1 mm5=4(211) mm6=0 mm7=9
+ PAVGB(%%mm4, %%mm6) //11 /2
+ "movq (%%"REG_c"), %%mm0 \n\t" // 1
+ PAVGB((%%REGa, %1, 2), %%mm0) // 11/2
+ "movq %%mm0, %%mm3 \n\t" // 11/2
+ PAVGB(%%mm1, %%mm0) // 2 11/4
+ PAVGB(%%mm6, %%mm0) //222 11/8
+ PAVGB(%%mm2, %%mm0) //22242211/16
+ "movq (%0, %1, 2), %%mm2 \n\t" // 1
+ "movq %%mm0, (%0, %1, 2) \n\t" // X
+ // mm1=2 mm2=3 mm3=6(11) mm4=1 mm5=4(211) mm6=0(11) mm7=9
+ "movq (%%"REG_a", %1, 4), %%mm0 \n\t" // 1
+ PAVGB((%%REGc), %%mm0) // 11 /2
+ PAVGB(%%mm0, %%mm6) //11 11 /4
+ PAVGB(%%mm1, %%mm4) // 11 /2
+ PAVGB(%%mm2, %%mm1) // 11 /2
+ PAVGB(%%mm1, %%mm6) //1122 11 /8
+ PAVGB(%%mm5, %%mm6) //112242211 /16
+ "movq (%%"REG_a"), %%mm5 \n\t" // 1
+ "movq %%mm6, (%%"REG_a") \n\t" // X
+ // mm0=7(11) mm1=2(11) mm2=3 mm3=6(11) mm4=1(11) mm5=4 mm7=9
+ "movq (%%"REG_a", %1, 4), %%mm6 \n\t" // 1
+ PAVGB(%%mm7, %%mm6) // 11 /2
+ PAVGB(%%mm4, %%mm6) // 11 11 /4
+ PAVGB(%%mm3, %%mm6) // 11 2211 /8
+ PAVGB(%%mm5, %%mm2) // 11 /2
+ "movq (%0, %1, 4), %%mm4 \n\t" // 1
+ PAVGB(%%mm4, %%mm2) // 112 /4
+ PAVGB(%%mm2, %%mm6) // 112242211 /16
+ "movq %%mm6, (%0, %1, 4) \n\t" // X
+ // mm0=7(11) mm1=2(11) mm2=3(112) mm3=6(11) mm4=5 mm5=4 mm7=9
+ PAVGB(%%mm7, %%mm1) // 11 2 /4
+ PAVGB(%%mm4, %%mm5) // 11 /2
+ PAVGB(%%mm5, %%mm0) // 11 11 /4
+ "movq (%%"REG_a", %1, 2), %%mm6 \n\t" // 1
+ PAVGB(%%mm6, %%mm1) // 11 4 2 /8
+ PAVGB(%%mm0, %%mm1) // 11224222 /16
+ "movq %%mm1, (%%"REG_a", %1, 2) \n\t" // X
+ // mm2=3(112) mm3=6(11) mm4=5 mm5=4(11) mm6=6 mm7=9
+ PAVGB((%%REGc), %%mm2) // 112 4 /8
+ "movq (%%"REG_a", %1, 4), %%mm0 \n\t" // 1
+ PAVGB(%%mm0, %%mm6) // 1 1 /2
+ PAVGB(%%mm7, %%mm6) // 1 12 /4
+ PAVGB(%%mm2, %%mm6) // 1122424 /4
+ "movq %%mm6, (%%"REG_c") \n\t" // X
+ // mm0=8 mm3=6(11) mm4=5 mm5=4(11) mm7=9
+ PAVGB(%%mm7, %%mm5) // 11 2 /4
+ PAVGB(%%mm7, %%mm5) // 11 6 /8
+
+ PAVGB(%%mm3, %%mm0) // 112 /4
+ PAVGB(%%mm0, %%mm5) // 112246 /16
+ "movq %%mm5, (%%"REG_a", %1, 4) \n\t" // X
+ "sub %1, %0 \n\t"
+
+ :
+ : "r" (src), "r" ((long)stride), "m" (c->pQPb)
+ : "%"REG_a, "%"REG_c
+ );
+#else //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+ const int l1= stride;
+ const int l2= stride + l1;
+ const int l3= stride + l2;
+ const int l4= stride + l3;
+ const int l5= stride + l4;
+ const int l6= stride + l5;
+ const int l7= stride + l6;
+ const int l8= stride + l7;
+ const int l9= stride + l8;
+ int x;
+ src+= stride*3;
+ for(x=0; x<BLOCK_SIZE; x++)
+ {
+ const int first= FFABS(src[0] - src[l1]) < c->QP ? src[0] : src[l1];
+ const int last= FFABS(src[l8] - src[l9]) < c->QP ? src[l9] : src[l8];
+
+ int sums[10];
+ sums[0] = 4*first + src[l1] + src[l2] + src[l3] + 4;
+ sums[1] = sums[0] - first + src[l4];
+ sums[2] = sums[1] - first + src[l5];
+ sums[3] = sums[2] - first + src[l6];
+ sums[4] = sums[3] - first + src[l7];
+ sums[5] = sums[4] - src[l1] + src[l8];
+ sums[6] = sums[5] - src[l2] + last;
+ sums[7] = sums[6] - src[l3] + last;
+ sums[8] = sums[7] - src[l4] + last;
+ sums[9] = sums[8] - src[l5] + last;
+
+ src[l1]= (sums[0] + sums[2] + 2*src[l1])>>4;
+ src[l2]= (sums[1] + sums[3] + 2*src[l2])>>4;
+ src[l3]= (sums[2] + sums[4] + 2*src[l3])>>4;
+ src[l4]= (sums[3] + sums[5] + 2*src[l4])>>4;
+ src[l5]= (sums[4] + sums[6] + 2*src[l5])>>4;
+ src[l6]= (sums[5] + sums[7] + 2*src[l6])>>4;
+ src[l7]= (sums[6] + sums[8] + 2*src[l7])>>4;
+ src[l8]= (sums[7] + sums[9] + 2*src[l8])>>4;
+
+ src++;
+ }
+#endif //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+}
+#endif //HAVE_ALTIVEC
+
+#if 0
+/**
+ * Experimental implementation of the filter (Algorithm 1) described in a paper from Ramkishor & Karandikar
+ * values are correctly clipped (MMX2)
+ * values are wraparound (C)
+ * conclusion: its fast, but introduces ugly horizontal patterns if there is a continious gradient
+ 0 8 16 24
+ x = 8
+ x/2 = 4
+ x/8 = 1
+ 1 12 12 23
+ */
+static inline void RENAME(vertRK1Filter)(uint8_t *src, int stride, int QP)
+{
+#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+ src+= stride*3;
+// FIXME rounding
+ asm volatile(
+ "pxor %%mm7, %%mm7 \n\t" // 0
+ "movq "MANGLE(b80)", %%mm6 \n\t" // MIN_SIGNED_BYTE
+ "leal (%0, %1), %%"REG_a" \n\t"
+ "leal (%%"REG_a", %1, 4), %%"REG_c" \n\t"
+// 0 1 2 3 4 5 6 7 8 9
+// %0 eax eax+%1 eax+2%1 %0+4%1 ecx ecx+%1 ecx+2%1 %0+8%1 ecx+4%1
+ "movq "MANGLE(pQPb)", %%mm0 \n\t" // QP,..., QP
+ "movq %%mm0, %%mm1 \n\t" // QP,..., QP
+ "paddusb "MANGLE(b02)", %%mm0 \n\t"
+ "psrlw $2, %%mm0 \n\t"
+ "pand "MANGLE(b3F)", %%mm0 \n\t" // QP/4,..., QP/4
+ "paddusb %%mm1, %%mm0 \n\t" // QP*1.25 ...
+ "movq (%0, %1, 4), %%mm2 \n\t" // line 4
+ "movq (%%"REG_c"), %%mm3 \n\t" // line 5
+ "movq %%mm2, %%mm4 \n\t" // line 4
+ "pcmpeqb %%mm5, %%mm5 \n\t" // -1
+ "pxor %%mm2, %%mm5 \n\t" // -line 4 - 1
+ PAVGB(%%mm3, %%mm5)
+ "paddb %%mm6, %%mm5 \n\t" // (l5-l4)/2
+ "psubusb %%mm3, %%mm4 \n\t"
+ "psubusb %%mm2, %%mm3 \n\t"
+ "por %%mm3, %%mm4 \n\t" // |l4 - l5|
+ "psubusb %%mm0, %%mm4 \n\t"
+ "pcmpeqb %%mm7, %%mm4 \n\t"
+ "pand %%mm4, %%mm5 \n\t" // d/2
+
+// "paddb %%mm6, %%mm2 \n\t" // line 4 + 0x80
+ "paddb %%mm5, %%mm2 \n\t"
+// "psubb %%mm6, %%mm2 \n\t"
+ "movq %%mm2, (%0,%1, 4) \n\t"
+
+ "movq (%%"REG_c"), %%mm2 \n\t"
+// "paddb %%mm6, %%mm2 \n\t" // line 5 + 0x80
+ "psubb %%mm5, %%mm2 \n\t"
+// "psubb %%mm6, %%mm2 \n\t"
+ "movq %%mm2, (%%"REG_c") \n\t"
+
+ "paddb %%mm6, %%mm5 \n\t"
+ "psrlw $2, %%mm5 \n\t"
+ "pand "MANGLE(b3F)", %%mm5 \n\t"
+ "psubb "MANGLE(b20)", %%mm5 \n\t" // (l5-l4)/8
+
+ "movq (%%"REG_a", %1, 2), %%mm2 \n\t"
+ "paddb %%mm6, %%mm2 \n\t" // line 3 + 0x80
+ "paddsb %%mm5, %%mm2 \n\t"
+ "psubb %%mm6, %%mm2 \n\t"
+ "movq %%mm2, (%%"REG_a", %1, 2) \n\t"
+
+ "movq (%%"REG_c", %1), %%mm2 \n\t"
+ "paddb %%mm6, %%mm2 \n\t" // line 6 + 0x80
+ "psubsb %%mm5, %%mm2 \n\t"
+ "psubb %%mm6, %%mm2 \n\t"
+ "movq %%mm2, (%%"REG_c", %1) \n\t"
+
+ :
+ : "r" (src), "r" ((long)stride)
+ : "%"REG_a, "%"REG_c
+ );
+#else //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+ const int l1= stride;
+ const int l2= stride + l1;
+ const int l3= stride + l2;
+ const int l4= stride + l3;
+ const int l5= stride + l4;
+ const int l6= stride + l5;
+// const int l7= stride + l6;
+// const int l8= stride + l7;
+// const int l9= stride + l8;
+ int x;
+ const int QP15= QP + (QP>>2);
+ src+= stride*3;
+ for(x=0; x<BLOCK_SIZE; x++)
+ {
+ const int v = (src[x+l5] - src[x+l4]);
+ if(FFABS(v) < QP15)
+ {
+ src[x+l3] +=v>>3;
+ src[x+l4] +=v>>1;
+ src[x+l5] -=v>>1;
+ src[x+l6] -=v>>3;
+
+ }
+ }
+
+#endif //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+}
+#endif //0
+
+/**
+ * Experimental Filter 1
+ * will not damage linear gradients
+ * Flat blocks should look like they where passed through the (1,1,2,2,4,2,2,1,1) 9-Tap filter
+ * can only smooth blocks at the expected locations (it cant smooth them if they did move)
+ * MMX2 version does correct clipping C version doesnt
+ */
+static inline void RENAME(vertX1Filter)(uint8_t *src, int stride, PPContext *co)
+{
+#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+ src+= stride*3;
+
+ asm volatile(
+ "pxor %%mm7, %%mm7 \n\t" // 0
+ "lea (%0, %1), %%"REG_a" \n\t"
+ "lea (%%"REG_a", %1, 4), %%"REG_c" \n\t"
+// 0 1 2 3 4 5 6 7 8 9
+// %0 eax eax+%1 eax+2%1 %0+4%1 ecx ecx+%1 ecx+2%1 %0+8%1 ecx+4%1
+ "movq (%%"REG_a", %1, 2), %%mm0 \n\t" // line 3
+ "movq (%0, %1, 4), %%mm1 \n\t" // line 4
+ "movq %%mm1, %%mm2 \n\t" // line 4
+ "psubusb %%mm0, %%mm1 \n\t"
+ "psubusb %%mm2, %%mm0 \n\t"
+ "por %%mm1, %%mm0 \n\t" // |l2 - l3|
+ "movq (%%"REG_c"), %%mm3 \n\t" // line 5
+ "movq (%%"REG_c", %1), %%mm4 \n\t" // line 6
+ "movq %%mm3, %%mm5 \n\t" // line 5
+ "psubusb %%mm4, %%mm3 \n\t"
+ "psubusb %%mm5, %%mm4 \n\t"
+ "por %%mm4, %%mm3 \n\t" // |l5 - l6|
+ PAVGB(%%mm3, %%mm0) // (|l2 - l3| + |l5 - l6|)/2
+ "movq %%mm2, %%mm1 \n\t" // line 4
+ "psubusb %%mm5, %%mm2 \n\t"
+ "movq %%mm2, %%mm4 \n\t"
+ "pcmpeqb %%mm7, %%mm2 \n\t" // (l4 - l5) <= 0 ? -1 : 0
+ "psubusb %%mm1, %%mm5 \n\t"
+ "por %%mm5, %%mm4 \n\t" // |l4 - l5|
+ "psubusb %%mm0, %%mm4 \n\t" //d = MAX(0, |l4-l5| - (|l2-l3| + |l5-l6|)/2)
+ "movq %%mm4, %%mm3 \n\t" // d
+ "movq %2, %%mm0 \n\t"
+ "paddusb %%mm0, %%mm0 \n\t"
+ "psubusb %%mm0, %%mm4 \n\t"
+ "pcmpeqb %%mm7, %%mm4 \n\t" // d <= QP ? -1 : 0
+ "psubusb "MANGLE(b01)", %%mm3 \n\t"
+ "pand %%mm4, %%mm3 \n\t" // d <= QP ? d : 0
+
+ PAVGB(%%mm7, %%mm3) // d/2
+ "movq %%mm3, %%mm1 \n\t" // d/2
+ PAVGB(%%mm7, %%mm3) // d/4
+ PAVGB(%%mm1, %%mm3) // 3*d/8
+
+ "movq (%0, %1, 4), %%mm0 \n\t" // line 4
+ "pxor %%mm2, %%mm0 \n\t" //(l4 - l5) <= 0 ? -l4-1 : l4
+ "psubusb %%mm3, %%mm0 \n\t"
+ "pxor %%mm2, %%mm0 \n\t"
+ "movq %%mm0, (%0, %1, 4) \n\t" // line 4
+
+ "movq (%%"REG_c"), %%mm0 \n\t" // line 5
+ "pxor %%mm2, %%mm0 \n\t" //(l4 - l5) <= 0 ? -l5-1 : l5
+ "paddusb %%mm3, %%mm0 \n\t"
+ "pxor %%mm2, %%mm0 \n\t"
+ "movq %%mm0, (%%"REG_c") \n\t" // line 5
+
+ PAVGB(%%mm7, %%mm1) // d/4
+
+ "movq (%%"REG_a", %1, 2), %%mm0 \n\t" // line 3
+ "pxor %%mm2, %%mm0 \n\t" //(l4 - l5) <= 0 ? -l4-1 : l4
+ "psubusb %%mm1, %%mm0 \n\t"
+ "pxor %%mm2, %%mm0 \n\t"
+ "movq %%mm0, (%%"REG_a", %1, 2) \n\t" // line 3
+
+ "movq (%%"REG_c", %1), %%mm0 \n\t" // line 6
+ "pxor %%mm2, %%mm0 \n\t" //(l4 - l5) <= 0 ? -l5-1 : l5
+ "paddusb %%mm1, %%mm0 \n\t"
+ "pxor %%mm2, %%mm0 \n\t"
+ "movq %%mm0, (%%"REG_c", %1) \n\t" // line 6
+
+ PAVGB(%%mm7, %%mm1) // d/8
+
+ "movq (%%"REG_a", %1), %%mm0 \n\t" // line 2
+ "pxor %%mm2, %%mm0 \n\t" //(l4 - l5) <= 0 ? -l2-1 : l2
+ "psubusb %%mm1, %%mm0 \n\t"
+ "pxor %%mm2, %%mm0 \n\t"
+ "movq %%mm0, (%%"REG_a", %1) \n\t" // line 2
+
+ "movq (%%"REG_c", %1, 2), %%mm0 \n\t" // line 7
+ "pxor %%mm2, %%mm0 \n\t" //(l4 - l5) <= 0 ? -l7-1 : l7
+ "paddusb %%mm1, %%mm0 \n\t"
+ "pxor %%mm2, %%mm0 \n\t"
+ "movq %%mm0, (%%"REG_c", %1, 2) \n\t" // line 7
+
+ :
+ : "r" (src), "r" ((long)stride), "m" (co->pQPb)
+ : "%"REG_a, "%"REG_c
+ );
+#else //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+
+ const int l1= stride;
+ const int l2= stride + l1;
+ const int l3= stride + l2;
+ const int l4= stride + l3;
+ const int l5= stride + l4;
+ const int l6= stride + l5;
+ const int l7= stride + l6;
+// const int l8= stride + l7;
+// const int l9= stride + l8;
+ int x;
+
+ src+= stride*3;
+ for(x=0; x<BLOCK_SIZE; x++)
+ {
+ int a= src[l3] - src[l4];
+ int b= src[l4] - src[l5];
+ int c= src[l5] - src[l6];
+
+ int d= FFABS(b) - ((FFABS(a) + FFABS(c))>>1);
+ d= FFMAX(d, 0);
+
+ if(d < co->QP*2)
+ {
+ int v = d * FFSIGN(-b);
+
+ src[l2] +=v>>3;
+ src[l3] +=v>>2;
+ src[l4] +=(3*v)>>3;
+ src[l5] -=(3*v)>>3;
+ src[l6] -=v>>2;
+ src[l7] -=v>>3;
+
+ }
+ src++;
+ }
+#endif //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+}
+
+#ifndef HAVE_ALTIVEC
+static inline void RENAME(doVertDefFilter)(uint8_t src[], int stride, PPContext *c)
+{
+#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+/*
+ uint8_t tmp[16];
+ const int l1= stride;
+ const int l2= stride + l1;
+ const int l3= stride + l2;
+ const int l4= (int)tmp - (int)src - stride*3;
+ const int l5= (int)tmp - (int)src - stride*3 + 8;
+ const int l6= stride*3 + l3;
+ const int l7= stride + l6;
+ const int l8= stride + l7;
+
+ memcpy(tmp, src+stride*7, 8);
+ memcpy(tmp+8, src+stride*8, 8);
+*/
+ src+= stride*4;
+ asm volatile(
+
+#if 0 //sligtly more accurate and slightly slower
+ "pxor %%mm7, %%mm7 \n\t" // 0
+ "lea (%0, %1), %%"REG_a" \n\t"
+ "lea (%%"REG_a", %1, 4), %%"REG_c" \n\t"
+// 0 1 2 3 4 5 6 7
+// %0 %0+%1 %0+2%1 eax+2%1 %0+4%1 eax+4%1 ecx+%1 ecx+2%1
+// %0 eax eax+%1 eax+2%1 %0+4%1 ecx ecx+%1 ecx+2%1
+
+
+ "movq (%0, %1, 2), %%mm0 \n\t" // l2
+ "movq (%0), %%mm1 \n\t" // l0
+ "movq %%mm0, %%mm2 \n\t" // l2
+ PAVGB(%%mm7, %%mm0) // ~l2/2
+ PAVGB(%%mm1, %%mm0) // ~(l2 + 2l0)/4
+ PAVGB(%%mm2, %%mm0) // ~(5l2 + 2l0)/8
+
+ "movq (%%"REG_a"), %%mm1 \n\t" // l1
+ "movq (%%"REG_a", %1, 2), %%mm3 \n\t" // l3
+ "movq %%mm1, %%mm4 \n\t" // l1
+ PAVGB(%%mm7, %%mm1) // ~l1/2
+ PAVGB(%%mm3, %%mm1) // ~(l1 + 2l3)/4
+ PAVGB(%%mm4, %%mm1) // ~(5l1 + 2l3)/8
+
+ "movq %%mm0, %%mm4 \n\t" // ~(5l2 + 2l0)/8
+ "psubusb %%mm1, %%mm0 \n\t"
+ "psubusb %%mm4, %%mm1 \n\t"
+ "por %%mm0, %%mm1 \n\t" // ~|2l0 - 5l1 + 5l2 - 2l3|/8
+// mm1= |lenergy|, mm2= l2, mm3= l3, mm7=0
+
+ "movq (%0, %1, 4), %%mm0 \n\t" // l4
+ "movq %%mm0, %%mm4 \n\t" // l4
+ PAVGB(%%mm7, %%mm0) // ~l4/2
+ PAVGB(%%mm2, %%mm0) // ~(l4 + 2l2)/4
+ PAVGB(%%mm4, %%mm0) // ~(5l4 + 2l2)/8
+
+ "movq (%%"REG_c"), %%mm2 \n\t" // l5
+ "movq %%mm3, %%mm5 \n\t" // l3
+ PAVGB(%%mm7, %%mm3) // ~l3/2
+ PAVGB(%%mm2, %%mm3) // ~(l3 + 2l5)/4
+ PAVGB(%%mm5, %%mm3) // ~(5l3 + 2l5)/8
+
+ "movq %%mm0, %%mm6 \n\t" // ~(5l4 + 2l2)/8
+ "psubusb %%mm3, %%mm0 \n\t"
+ "psubusb %%mm6, %%mm3 \n\t"
+ "por %%mm0, %%mm3 \n\t" // ~|2l2 - 5l3 + 5l4 - 2l5|/8
+ "pcmpeqb %%mm7, %%mm0 \n\t" // SIGN(2l2 - 5l3 + 5l4 - 2l5)
+// mm0= SIGN(menergy), mm1= |lenergy|, mm2= l5, mm3= |menergy|, mm4=l4, mm5= l3, mm7=0
+
+ "movq (%%"REG_c", %1), %%mm6 \n\t" // l6
+ "movq %%mm6, %%mm5 \n\t" // l6
+ PAVGB(%%mm7, %%mm6) // ~l6/2
+ PAVGB(%%mm4, %%mm6) // ~(l6 + 2l4)/4
+ PAVGB(%%mm5, %%mm6) // ~(5l6 + 2l4)/8
+
+ "movq (%%"REG_c", %1, 2), %%mm5 \n\t" // l7
+ "movq %%mm2, %%mm4 \n\t" // l5
+ PAVGB(%%mm7, %%mm2) // ~l5/2
+ PAVGB(%%mm5, %%mm2) // ~(l5 + 2l7)/4
+ PAVGB(%%mm4, %%mm2) // ~(5l5 + 2l7)/8
+
+ "movq %%mm6, %%mm4 \n\t" // ~(5l6 + 2l4)/8
+ "psubusb %%mm2, %%mm6 \n\t"
+ "psubusb %%mm4, %%mm2 \n\t"
+ "por %%mm6, %%mm2 \n\t" // ~|2l4 - 5l5 + 5l6 - 2l7|/8
+// mm0= SIGN(menergy), mm1= |lenergy|/8, mm2= |renergy|/8, mm3= |menergy|/8, mm7=0
+
+
+ PMINUB(%%mm2, %%mm1, %%mm4) // MIN(|lenergy|,|renergy|)/8
+ "movq %2, %%mm4 \n\t" // QP //FIXME QP+1 ?
+ "paddusb "MANGLE(b01)", %%mm4 \n\t"
+ "pcmpgtb %%mm3, %%mm4 \n\t" // |menergy|/8 < QP
+ "psubusb %%mm1, %%mm3 \n\t" // d=|menergy|/8-MIN(|lenergy|,|renergy|)/8
+ "pand %%mm4, %%mm3 \n\t"
+
+ "movq %%mm3, %%mm1 \n\t"
+// "psubusb "MANGLE(b01)", %%mm3 \n\t"
+ PAVGB(%%mm7, %%mm3)
+ PAVGB(%%mm7, %%mm3)
+ "paddusb %%mm1, %%mm3 \n\t"
+// "paddusb "MANGLE(b01)", %%mm3 \n\t"
+
+ "movq (%%"REG_a", %1, 2), %%mm6 \n\t" //l3
+ "movq (%0, %1, 4), %%mm5 \n\t" //l4
+ "movq (%0, %1, 4), %%mm4 \n\t" //l4
+ "psubusb %%mm6, %%mm5 \n\t"
+ "psubusb %%mm4, %%mm6 \n\t"
+ "por %%mm6, %%mm5 \n\t" // |l3-l4|
+ "pcmpeqb %%mm7, %%mm6 \n\t" // SIGN(l3-l4)
+ "pxor %%mm6, %%mm0 \n\t"
+ "pand %%mm0, %%mm3 \n\t"
+ PMINUB(%%mm5, %%mm3, %%mm0)
+
+ "psubusb "MANGLE(b01)", %%mm3 \n\t"
+ PAVGB(%%mm7, %%mm3)
+
+ "movq (%%"REG_a", %1, 2), %%mm0 \n\t"
+ "movq (%0, %1, 4), %%mm2 \n\t"
+ "pxor %%mm6, %%mm0 \n\t"
+ "pxor %%mm6, %%mm2 \n\t"
+ "psubb %%mm3, %%mm0 \n\t"
+ "paddb %%mm3, %%mm2 \n\t"
+ "pxor %%mm6, %%mm0 \n\t"
+ "pxor %%mm6, %%mm2 \n\t"
+ "movq %%mm0, (%%"REG_a", %1, 2) \n\t"
+ "movq %%mm2, (%0, %1, 4) \n\t"
+#endif //0
+
+ "lea (%0, %1), %%"REG_a" \n\t"
+ "pcmpeqb %%mm6, %%mm6 \n\t" // -1
+// 0 1 2 3 4 5 6 7
+// %0 %0+%1 %0+2%1 eax+2%1 %0+4%1 eax+4%1 ecx+%1 ecx+2%1
+// %0 eax eax+%1 eax+2%1 %0+4%1 ecx ecx+%1 ecx+2%1
+
+
+ "movq (%%"REG_a", %1, 2), %%mm1 \n\t" // l3
+ "movq (%0, %1, 4), %%mm0 \n\t" // l4
+ "pxor %%mm6, %%mm1 \n\t" // -l3-1
+ PAVGB(%%mm1, %%mm0) // -q+128 = (l4-l3+256)/2
+// mm1=-l3-1, mm0=128-q
+
+ "movq (%%"REG_a", %1, 4), %%mm2 \n\t" // l5
+ "movq (%%"REG_a", %1), %%mm3 \n\t" // l2
+ "pxor %%mm6, %%mm2 \n\t" // -l5-1
+ "movq %%mm2, %%mm5 \n\t" // -l5-1
+ "movq "MANGLE(b80)", %%mm4 \n\t" // 128
+ "lea (%%"REG_a", %1, 4), %%"REG_c" \n\t"
+ PAVGB(%%mm3, %%mm2) // (l2-l5+256)/2
+ PAVGB(%%mm0, %%mm4) // ~(l4-l3)/4 + 128
+ PAVGB(%%mm2, %%mm4) // ~(l2-l5)/4 +(l4-l3)/8 + 128
+ PAVGB(%%mm0, %%mm4) // ~(l2-l5)/8 +5(l4-l3)/16 + 128
+// mm1=-l3-1, mm0=128-q, mm3=l2, mm4=menergy/16 + 128, mm5= -l5-1
+
+ "movq (%%"REG_a"), %%mm2 \n\t" // l1
+ "pxor %%mm6, %%mm2 \n\t" // -l1-1
+ PAVGB(%%mm3, %%mm2) // (l2-l1+256)/2
+ PAVGB((%0), %%mm1) // (l0-l3+256)/2
+ "movq "MANGLE(b80)", %%mm3 \n\t" // 128
+ PAVGB(%%mm2, %%mm3) // ~(l2-l1)/4 + 128
+ PAVGB(%%mm1, %%mm3) // ~(l0-l3)/4 +(l2-l1)/8 + 128
+ PAVGB(%%mm2, %%mm3) // ~(l0-l3)/8 +5(l2-l1)/16 + 128
+// mm0=128-q, mm3=lenergy/16 + 128, mm4= menergy/16 + 128, mm5= -l5-1
+
+ PAVGB((%%REGc, %1), %%mm5) // (l6-l5+256)/2
+ "movq (%%"REG_c", %1, 2), %%mm1 \n\t" // l7
+ "pxor %%mm6, %%mm1 \n\t" // -l7-1
+ PAVGB((%0, %1, 4), %%mm1) // (l4-l7+256)/2
+ "movq "MANGLE(b80)", %%mm2 \n\t" // 128
+ PAVGB(%%mm5, %%mm2) // ~(l6-l5)/4 + 128
+ PAVGB(%%mm1, %%mm2) // ~(l4-l7)/4 +(l6-l5)/8 + 128
+ PAVGB(%%mm5, %%mm2) // ~(l4-l7)/8 +5(l6-l5)/16 + 128
+// mm0=128-q, mm2=renergy/16 + 128, mm3=lenergy/16 + 128, mm4= menergy/16 + 128
+
+ "movq "MANGLE(b00)", %%mm1 \n\t" // 0
+ "movq "MANGLE(b00)", %%mm5 \n\t" // 0
+ "psubb %%mm2, %%mm1 \n\t" // 128 - renergy/16
+ "psubb %%mm3, %%mm5 \n\t" // 128 - lenergy/16
+ PMAXUB(%%mm1, %%mm2) // 128 + |renergy/16|
+ PMAXUB(%%mm5, %%mm3) // 128 + |lenergy/16|
+ PMINUB(%%mm2, %%mm3, %%mm1) // 128 + MIN(|lenergy|,|renergy|)/16
+
+// mm0=128-q, mm3=128 + MIN(|lenergy|,|renergy|)/16, mm4= menergy/16 + 128
+
+ "movq "MANGLE(b00)", %%mm7 \n\t" // 0
+ "movq %2, %%mm2 \n\t" // QP
+ PAVGB(%%mm6, %%mm2) // 128 + QP/2
+ "psubb %%mm6, %%mm2 \n\t"
+
+ "movq %%mm4, %%mm1 \n\t"
+ "pcmpgtb %%mm7, %%mm1 \n\t" // SIGN(menergy)
+ "pxor %%mm1, %%mm4 \n\t"
+ "psubb %%mm1, %%mm4 \n\t" // 128 + |menergy|/16
+ "pcmpgtb %%mm4, %%mm2 \n\t" // |menergy|/16 < QP/2
+ "psubusb %%mm3, %%mm4 \n\t" //d=|menergy|/16 - MIN(|lenergy|,|renergy|)/16
+// mm0=128-q, mm1= SIGN(menergy), mm2= |menergy|/16 < QP/2, mm4= d/16
+
+ "movq %%mm4, %%mm3 \n\t" // d
+ "psubusb "MANGLE(b01)", %%mm4 \n\t"
+ PAVGB(%%mm7, %%mm4) // d/32
+ PAVGB(%%mm7, %%mm4) // (d + 32)/64
+ "paddb %%mm3, %%mm4 \n\t" // 5d/64
+ "pand %%mm2, %%mm4 \n\t"
+
+ "movq "MANGLE(b80)", %%mm5 \n\t" // 128
+ "psubb %%mm0, %%mm5 \n\t" // q
+ "paddsb %%mm6, %%mm5 \n\t" // fix bad rounding
+ "pcmpgtb %%mm5, %%mm7 \n\t" // SIGN(q)
+ "pxor %%mm7, %%mm5 \n\t"
+
+ PMINUB(%%mm5, %%mm4, %%mm3) // MIN(|q|, 5d/64)
+ "pxor %%mm1, %%mm7 \n\t" // SIGN(d*q)
+
+ "pand %%mm7, %%mm4 \n\t"
+ "movq (%%"REG_a", %1, 2), %%mm0 \n\t"
+ "movq (%0, %1, 4), %%mm2 \n\t"
+ "pxor %%mm1, %%mm0 \n\t"
+ "pxor %%mm1, %%mm2 \n\t"
+ "paddb %%mm4, %%mm0 \n\t"
+ "psubb %%mm4, %%mm2 \n\t"
+ "pxor %%mm1, %%mm0 \n\t"
+ "pxor %%mm1, %%mm2 \n\t"
+ "movq %%mm0, (%%"REG_a", %1, 2) \n\t"
+ "movq %%mm2, (%0, %1, 4) \n\t"
+
+ :
+ : "r" (src), "r" ((long)stride), "m" (c->pQPb)
+ : "%"REG_a, "%"REG_c
+ );
+
+/*
+ {
+ int x;
+ src-= stride;
+ for(x=0; x<BLOCK_SIZE; x++)
+ {
+ const int middleEnergy= 5*(src[l5] - src[l4]) + 2*(src[l3] - src[l6]);
+ if(FFABS(middleEnergy)< 8*QP)
+ {
+ const int q=(src[l4] - src[l5])/2;
+ const int leftEnergy= 5*(src[l3] - src[l2]) + 2*(src[l1] - src[l4]);
+ const int rightEnergy= 5*(src[l7] - src[l6]) + 2*(src[l5] - src[l8]);
+
+ int d= FFABS(middleEnergy) - FFMIN( FFABS(leftEnergy), FFABS(rightEnergy) );
+ d= FFMAX(d, 0);
+
+ d= (5*d + 32) >> 6;
+ d*= FFSIGN(-middleEnergy);
+
+ if(q>0)
+ {
+ d= d<0 ? 0 : d;
+ d= d>q ? q : d;
+ }
+ else
+ {
+ d= d>0 ? 0 : d;
+ d= d<q ? q : d;
+ }
+
+ src[l4]-= d;
+ src[l5]+= d;
+ }
+ src++;
+ }
+src-=8;
+ for(x=0; x<8; x++)
+ {
+ int y;
+ for(y=4; y<6; y++)
+ {
+ int d= src[x+y*stride] - tmp[x+(y-4)*8];
+ int ad= FFABS(d);
+ static int max=0;
+ static int sum=0;
+ static int num=0;
+ static int bias=0;
+
+ if(max<ad) max=ad;
+ sum+= ad>3 ? 1 : 0;
+ if(ad>3)
+ {
+ src[0] = src[7] = src[stride*7] = src[(stride+1)*7]=255;
+ }
+ if(y==4) bias+=d;
+ num++;
+ if(num%1000000 == 0)
+ {
+ av_log(c, AV_LOG_INFO, " %d %d %d %d\n", num, sum, max, bias);
+ }
+ }
+ }
+}
+*/
+#elif defined (HAVE_MMX)
+ src+= stride*4;
+ asm volatile(
+ "pxor %%mm7, %%mm7 \n\t"
+ "lea -40(%%"REG_SP"), %%"REG_c" \n\t" // make space for 4 8-byte vars
+ "and "ALIGN_MASK", %%"REG_c" \n\t" // align
+// 0 1 2 3 4 5 6 7
+// %0 %0+%1 %0+2%1 eax+2%1 %0+4%1 eax+4%1 edx+%1 edx+2%1
+// %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1
+
+ "movq (%0), %%mm0 \n\t"
+ "movq %%mm0, %%mm1 \n\t"
+ "punpcklbw %%mm7, %%mm0 \n\t" // low part of line 0
+ "punpckhbw %%mm7, %%mm1 \n\t" // high part of line 0
+
+ "movq (%0, %1), %%mm2 \n\t"
+ "lea (%0, %1, 2), %%"REG_a" \n\t"
+ "movq %%mm2, %%mm3 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t" // low part of line 1
+ "punpckhbw %%mm7, %%mm3 \n\t" // high part of line 1
+
+ "movq (%%"REG_a"), %%mm4 \n\t"
+ "movq %%mm4, %%mm5 \n\t"
+ "punpcklbw %%mm7, %%mm4 \n\t" // low part of line 2
+ "punpckhbw %%mm7, %%mm5 \n\t" // high part of line 2
+
+ "paddw %%mm0, %%mm0 \n\t" // 2L0
+ "paddw %%mm1, %%mm1 \n\t" // 2H0
+ "psubw %%mm4, %%mm2 \n\t" // L1 - L2
+ "psubw %%mm5, %%mm3 \n\t" // H1 - H2
+ "psubw %%mm2, %%mm0 \n\t" // 2L0 - L1 + L2
+ "psubw %%mm3, %%mm1 \n\t" // 2H0 - H1 + H2
+
+ "psllw $2, %%mm2 \n\t" // 4L1 - 4L2
+ "psllw $2, %%mm3 \n\t" // 4H1 - 4H2
+ "psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2
+ "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2
+
+ "movq (%%"REG_a", %1), %%mm2 \n\t"
+ "movq %%mm2, %%mm3 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t" // L3
+ "punpckhbw %%mm7, %%mm3 \n\t" // H3
+
+ "psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2 - L3
+ "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2 - H3
+ "psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2 - 2L3
+ "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2 - 2H3
+ "movq %%mm0, (%%"REG_c") \n\t" // 2L0 - 5L1 + 5L2 - 2L3
+ "movq %%mm1, 8(%%"REG_c") \n\t" // 2H0 - 5H1 + 5H2 - 2H3
+
+ "movq (%%"REG_a", %1, 2), %%mm0 \n\t"
+ "movq %%mm0, %%mm1 \n\t"
+ "punpcklbw %%mm7, %%mm0 \n\t" // L4
+ "punpckhbw %%mm7, %%mm1 \n\t" // H4
+
+ "psubw %%mm0, %%mm2 \n\t" // L3 - L4
+ "psubw %%mm1, %%mm3 \n\t" // H3 - H4
+ "movq %%mm2, 16(%%"REG_c") \n\t" // L3 - L4
+ "movq %%mm3, 24(%%"REG_c") \n\t" // H3 - H4
+ "paddw %%mm4, %%mm4 \n\t" // 2L2
+ "paddw %%mm5, %%mm5 \n\t" // 2H2
+ "psubw %%mm2, %%mm4 \n\t" // 2L2 - L3 + L4
+ "psubw %%mm3, %%mm5 \n\t" // 2H2 - H3 + H4
+
+ "lea (%%"REG_a", %1), %0 \n\t"
+ "psllw $2, %%mm2 \n\t" // 4L3 - 4L4
+ "psllw $2, %%mm3 \n\t" // 4H3 - 4H4
+ "psubw %%mm2, %%mm4 \n\t" // 2L2 - 5L3 + 5L4
+ "psubw %%mm3, %%mm5 \n\t" // 2H2 - 5H3 + 5H4
+//50 opcodes so far
+ "movq (%0, %1, 2), %%mm2 \n\t"
+ "movq %%mm2, %%mm3 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t" // L5
+ "punpckhbw %%mm7, %%mm3 \n\t" // H5
+ "psubw %%mm2, %%mm4 \n\t" // 2L2 - 5L3 + 5L4 - L5
+ "psubw %%mm3, %%mm5 \n\t" // 2H2 - 5H3 + 5H4 - H5
+ "psubw %%mm2, %%mm4 \n\t" // 2L2 - 5L3 + 5L4 - 2L5
+ "psubw %%mm3, %%mm5 \n\t" // 2H2 - 5H3 + 5H4 - 2H5
+
+ "movq (%%"REG_a", %1, 4), %%mm6 \n\t"
+ "punpcklbw %%mm7, %%mm6 \n\t" // L6
+ "psubw %%mm6, %%mm2 \n\t" // L5 - L6
+ "movq (%%"REG_a", %1, 4), %%mm6 \n\t"
+ "punpckhbw %%mm7, %%mm6 \n\t" // H6
+ "psubw %%mm6, %%mm3 \n\t" // H5 - H6
+
+ "paddw %%mm0, %%mm0 \n\t" // 2L4
+ "paddw %%mm1, %%mm1 \n\t" // 2H4
+ "psubw %%mm2, %%mm0 \n\t" // 2L4 - L5 + L6
+ "psubw %%mm3, %%mm1 \n\t" // 2H4 - H5 + H6
+
+ "psllw $2, %%mm2 \n\t" // 4L5 - 4L6
+ "psllw $2, %%mm3 \n\t" // 4H5 - 4H6
+ "psubw %%mm2, %%mm0 \n\t" // 2L4 - 5L5 + 5L6
+ "psubw %%mm3, %%mm1 \n\t" // 2H4 - 5H5 + 5H6
+
+ "movq (%0, %1, 4), %%mm2 \n\t"
+ "movq %%mm2, %%mm3 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t" // L7
+ "punpckhbw %%mm7, %%mm3 \n\t" // H7
+
+ "paddw %%mm2, %%mm2 \n\t" // 2L7
+ "paddw %%mm3, %%mm3 \n\t" // 2H7
+ "psubw %%mm2, %%mm0 \n\t" // 2L4 - 5L5 + 5L6 - 2L7
+ "psubw %%mm3, %%mm1 \n\t" // 2H4 - 5H5 + 5H6 - 2H7
+
+ "movq (%%"REG_c"), %%mm2 \n\t" // 2L0 - 5L1 + 5L2 - 2L3
+ "movq 8(%%"REG_c"), %%mm3 \n\t" // 2H0 - 5H1 + 5H2 - 2H3
+
+#ifdef HAVE_MMX2
+ "movq %%mm7, %%mm6 \n\t" // 0
+ "psubw %%mm0, %%mm6 \n\t"
+ "pmaxsw %%mm6, %%mm0 \n\t" // |2L4 - 5L5 + 5L6 - 2L7|
+ "movq %%mm7, %%mm6 \n\t" // 0
+ "psubw %%mm1, %%mm6 \n\t"
+ "pmaxsw %%mm6, %%mm1 \n\t" // |2H4 - 5H5 + 5H6 - 2H7|
+ "movq %%mm7, %%mm6 \n\t" // 0
+ "psubw %%mm2, %%mm6 \n\t"
+ "pmaxsw %%mm6, %%mm2 \n\t" // |2L0 - 5L1 + 5L2 - 2L3|
+ "movq %%mm7, %%mm6 \n\t" // 0
+ "psubw %%mm3, %%mm6 \n\t"
+ "pmaxsw %%mm6, %%mm3 \n\t" // |2H0 - 5H1 + 5H2 - 2H3|
+#else
+ "movq %%mm7, %%mm6 \n\t" // 0
+ "pcmpgtw %%mm0, %%mm6 \n\t"
+ "pxor %%mm6, %%mm0 \n\t"
+ "psubw %%mm6, %%mm0 \n\t" // |2L4 - 5L5 + 5L6 - 2L7|
+ "movq %%mm7, %%mm6 \n\t" // 0
+ "pcmpgtw %%mm1, %%mm6 \n\t"
+ "pxor %%mm6, %%mm1 \n\t"
+ "psubw %%mm6, %%mm1 \n\t" // |2H4 - 5H5 + 5H6 - 2H7|
+ "movq %%mm7, %%mm6 \n\t" // 0
+ "pcmpgtw %%mm2, %%mm6 \n\t"
+ "pxor %%mm6, %%mm2 \n\t"
+ "psubw %%mm6, %%mm2 \n\t" // |2L0 - 5L1 + 5L2 - 2L3|
+ "movq %%mm7, %%mm6 \n\t" // 0
+ "pcmpgtw %%mm3, %%mm6 \n\t"
+ "pxor %%mm6, %%mm3 \n\t"
+ "psubw %%mm6, %%mm3 \n\t" // |2H0 - 5H1 + 5H2 - 2H3|
+#endif
+
+#ifdef HAVE_MMX2
+ "pminsw %%mm2, %%mm0 \n\t"
+ "pminsw %%mm3, %%mm1 \n\t"
+#else
+ "movq %%mm0, %%mm6 \n\t"
+ "psubusw %%mm2, %%mm6 \n\t"
+ "psubw %%mm6, %%mm0 \n\t"
+ "movq %%mm1, %%mm6 \n\t"
+ "psubusw %%mm3, %%mm6 \n\t"
+ "psubw %%mm6, %%mm1 \n\t"
+#endif
+
+ "movd %2, %%mm2 \n\t" // QP
+ "punpcklbw %%mm7, %%mm2 \n\t"
+
+ "movq %%mm7, %%mm6 \n\t" // 0
+ "pcmpgtw %%mm4, %%mm6 \n\t" // sign(2L2 - 5L3 + 5L4 - 2L5)
+ "pxor %%mm6, %%mm4 \n\t"
+ "psubw %%mm6, %%mm4 \n\t" // |2L2 - 5L3 + 5L4 - 2L5|
+ "pcmpgtw %%mm5, %%mm7 \n\t" // sign(2H2 - 5H3 + 5H4 - 2H5)
+ "pxor %%mm7, %%mm5 \n\t"
+ "psubw %%mm7, %%mm5 \n\t" // |2H2 - 5H3 + 5H4 - 2H5|
+// 100 opcodes
+ "psllw $3, %%mm2 \n\t" // 8QP
+ "movq %%mm2, %%mm3 \n\t" // 8QP
+ "pcmpgtw %%mm4, %%mm2 \n\t"
+ "pcmpgtw %%mm5, %%mm3 \n\t"
+ "pand %%mm2, %%mm4 \n\t"
+ "pand %%mm3, %%mm5 \n\t"
+
+
+ "psubusw %%mm0, %%mm4 \n\t" // hd
+ "psubusw %%mm1, %%mm5 \n\t" // ld
+
+
+ "movq "MANGLE(w05)", %%mm2 \n\t" // 5
+ "pmullw %%mm2, %%mm4 \n\t"
+ "pmullw %%mm2, %%mm5 \n\t"
+ "movq "MANGLE(w20)", %%mm2 \n\t" // 32
+ "paddw %%mm2, %%mm4 \n\t"
+ "paddw %%mm2, %%mm5 \n\t"
+ "psrlw $6, %%mm4 \n\t"
+ "psrlw $6, %%mm5 \n\t"
+
+ "movq 16(%%"REG_c"), %%mm0 \n\t" // L3 - L4
+ "movq 24(%%"REG_c"), %%mm1 \n\t" // H3 - H4
+
+ "pxor %%mm2, %%mm2 \n\t"
+ "pxor %%mm3, %%mm3 \n\t"
+
+ "pcmpgtw %%mm0, %%mm2 \n\t" // sign (L3-L4)
+ "pcmpgtw %%mm1, %%mm3 \n\t" // sign (H3-H4)
+ "pxor %%mm2, %%mm0 \n\t"
+ "pxor %%mm3, %%mm1 \n\t"
+ "psubw %%mm2, %%mm0 \n\t" // |L3-L4|
+ "psubw %%mm3, %%mm1 \n\t" // |H3-H4|
+ "psrlw $1, %%mm0 \n\t" // |L3 - L4|/2
+ "psrlw $1, %%mm1 \n\t" // |H3 - H4|/2
+
+ "pxor %%mm6, %%mm2 \n\t"
+ "pxor %%mm7, %%mm3 \n\t"
+ "pand %%mm2, %%mm4 \n\t"
+ "pand %%mm3, %%mm5 \n\t"
+
+#ifdef HAVE_MMX2
+ "pminsw %%mm0, %%mm4 \n\t"
+ "pminsw %%mm1, %%mm5 \n\t"
+#else
+ "movq %%mm4, %%mm2 \n\t"
+ "psubusw %%mm0, %%mm2 \n\t"
+ "psubw %%mm2, %%mm4 \n\t"
+ "movq %%mm5, %%mm2 \n\t"
+ "psubusw %%mm1, %%mm2 \n\t"
+ "psubw %%mm2, %%mm5 \n\t"
+#endif
+ "pxor %%mm6, %%mm4 \n\t"
+ "pxor %%mm7, %%mm5 \n\t"
+ "psubw %%mm6, %%mm4 \n\t"
+ "psubw %%mm7, %%mm5 \n\t"
+ "packsswb %%mm5, %%mm4 \n\t"
+ "movq (%0), %%mm0 \n\t"
+ "paddb %%mm4, %%mm0 \n\t"
+ "movq %%mm0, (%0) \n\t"
+ "movq (%0, %1), %%mm0 \n\t"
+ "psubb %%mm4, %%mm0 \n\t"
+ "movq %%mm0, (%0, %1) \n\t"
+
+ : "+r" (src)
+ : "r" ((long)stride), "m" (c->pQPb)
+ : "%"REG_a, "%"REG_c
+ );
+#else //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+ const int l1= stride;
+ const int l2= stride + l1;
+ const int l3= stride + l2;
+ const int l4= stride + l3;
+ const int l5= stride + l4;
+ const int l6= stride + l5;
+ const int l7= stride + l6;
+ const int l8= stride + l7;
+// const int l9= stride + l8;
+ int x;
+ src+= stride*3;
+ for(x=0; x<BLOCK_SIZE; x++)
+ {
+ const int middleEnergy= 5*(src[l5] - src[l4]) + 2*(src[l3] - src[l6]);
+ if(FFABS(middleEnergy) < 8*c->QP)
+ {
+ const int q=(src[l4] - src[l5])/2;
+ const int leftEnergy= 5*(src[l3] - src[l2]) + 2*(src[l1] - src[l4]);
+ const int rightEnergy= 5*(src[l7] - src[l6]) + 2*(src[l5] - src[l8]);
+
+ int d= FFABS(middleEnergy) - FFMIN( FFABS(leftEnergy), FFABS(rightEnergy) );
+ d= FFMAX(d, 0);
+
+ d= (5*d + 32) >> 6;
+ d*= FFSIGN(-middleEnergy);
+
+ if(q>0)
+ {
+ d= d<0 ? 0 : d;
+ d= d>q ? q : d;
+ }
+ else
+ {
+ d= d>0 ? 0 : d;
+ d= d<q ? q : d;
+ }
+
+ src[l4]-= d;
+ src[l5]+= d;
+ }
+ src++;
+ }
+#endif //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+}
+#endif //HAVE_ALTIVEC
+
+#ifndef HAVE_ALTIVEC
+static inline void RENAME(dering)(uint8_t src[], int stride, PPContext *c)
+{
+#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+ asm volatile(
+ "pxor %%mm6, %%mm6 \n\t"
+ "pcmpeqb %%mm7, %%mm7 \n\t"
+ "movq %2, %%mm0 \n\t"
+ "punpcklbw %%mm6, %%mm0 \n\t"
+ "psrlw $1, %%mm0 \n\t"
+ "psubw %%mm7, %%mm0 \n\t"
+ "packuswb %%mm0, %%mm0 \n\t"
+ "movq %%mm0, %3 \n\t"
+
+ "lea (%0, %1), %%"REG_a" \n\t"
+ "lea (%%"REG_a", %1, 4), %%"REG_d" \n\t"
+
+// 0 1 2 3 4 5 6 7 8 9
+// %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1
+
+#undef FIND_MIN_MAX
+#ifdef HAVE_MMX2
+#define REAL_FIND_MIN_MAX(addr)\
+ "movq " #addr ", %%mm0 \n\t"\
+ "pminub %%mm0, %%mm7 \n\t"\
+ "pmaxub %%mm0, %%mm6 \n\t"
+#else
+#define REAL_FIND_MIN_MAX(addr)\
+ "movq " #addr ", %%mm0 \n\t"\
+ "movq %%mm7, %%mm1 \n\t"\
+ "psubusb %%mm0, %%mm6 \n\t"\
+ "paddb %%mm0, %%mm6 \n\t"\
+ "psubusb %%mm0, %%mm1 \n\t"\
+ "psubb %%mm1, %%mm7 \n\t"
+#endif
+#define FIND_MIN_MAX(addr) REAL_FIND_MIN_MAX(addr)
+
+FIND_MIN_MAX((%%REGa))
+FIND_MIN_MAX((%%REGa, %1))
+FIND_MIN_MAX((%%REGa, %1, 2))
+FIND_MIN_MAX((%0, %1, 4))
+FIND_MIN_MAX((%%REGd))
+FIND_MIN_MAX((%%REGd, %1))
+FIND_MIN_MAX((%%REGd, %1, 2))
+FIND_MIN_MAX((%0, %1, 8))
+
+ "movq %%mm7, %%mm4 \n\t"
+ "psrlq $8, %%mm7 \n\t"
+#ifdef HAVE_MMX2
+ "pminub %%mm4, %%mm7 \n\t" // min of pixels
+ "pshufw $0xF9, %%mm7, %%mm4 \n\t"
+ "pminub %%mm4, %%mm7 \n\t" // min of pixels
+ "pshufw $0xFE, %%mm7, %%mm4 \n\t"
+ "pminub %%mm4, %%mm7 \n\t"
+#else
+ "movq %%mm7, %%mm1 \n\t"
+ "psubusb %%mm4, %%mm1 \n\t"
+ "psubb %%mm1, %%mm7 \n\t"
+ "movq %%mm7, %%mm4 \n\t"
+ "psrlq $16, %%mm7 \n\t"
+ "movq %%mm7, %%mm1 \n\t"
+ "psubusb %%mm4, %%mm1 \n\t"
+ "psubb %%mm1, %%mm7 \n\t"
+ "movq %%mm7, %%mm4 \n\t"
+ "psrlq $32, %%mm7 \n\t"
+ "movq %%mm7, %%mm1 \n\t"
+ "psubusb %%mm4, %%mm1 \n\t"
+ "psubb %%mm1, %%mm7 \n\t"
+#endif
+
+
+ "movq %%mm6, %%mm4 \n\t"
+ "psrlq $8, %%mm6 \n\t"
+#ifdef HAVE_MMX2
+ "pmaxub %%mm4, %%mm6 \n\t" // max of pixels
+ "pshufw $0xF9, %%mm6, %%mm4 \n\t"
+ "pmaxub %%mm4, %%mm6 \n\t"
+ "pshufw $0xFE, %%mm6, %%mm4 \n\t"
+ "pmaxub %%mm4, %%mm6 \n\t"
+#else
+ "psubusb %%mm4, %%mm6 \n\t"
+ "paddb %%mm4, %%mm6 \n\t"
+ "movq %%mm6, %%mm4 \n\t"
+ "psrlq $16, %%mm6 \n\t"
+ "psubusb %%mm4, %%mm6 \n\t"
+ "paddb %%mm4, %%mm6 \n\t"
+ "movq %%mm6, %%mm4 \n\t"
+ "psrlq $32, %%mm6 \n\t"
+ "psubusb %%mm4, %%mm6 \n\t"
+ "paddb %%mm4, %%mm6 \n\t"
+#endif
+ "movq %%mm6, %%mm0 \n\t" // max
+ "psubb %%mm7, %%mm6 \n\t" // max - min
+ "movd %%mm6, %%ecx \n\t"
+ "cmpb "MANGLE(deringThreshold)", %%cl \n\t"
+ " jb 1f \n\t"
+ "lea -24(%%"REG_SP"), %%"REG_c" \n\t"
+ "and "ALIGN_MASK", %%"REG_c" \n\t"
+ PAVGB(%%mm0, %%mm7) // a=(max + min)/2
+ "punpcklbw %%mm7, %%mm7 \n\t"
+ "punpcklbw %%mm7, %%mm7 \n\t"
+ "punpcklbw %%mm7, %%mm7 \n\t"
+ "movq %%mm7, (%%"REG_c") \n\t"
+
+ "movq (%0), %%mm0 \n\t" // L10
+ "movq %%mm0, %%mm1 \n\t" // L10
+ "movq %%mm0, %%mm2 \n\t" // L10
+ "psllq $8, %%mm1 \n\t"
+ "psrlq $8, %%mm2 \n\t"
+ "movd -4(%0), %%mm3 \n\t"
+ "movd 8(%0), %%mm4 \n\t"
+ "psrlq $24, %%mm3 \n\t"
+ "psllq $56, %%mm4 \n\t"
+ "por %%mm3, %%mm1 \n\t" // L00
+ "por %%mm4, %%mm2 \n\t" // L20
+ "movq %%mm1, %%mm3 \n\t" // L00
+ PAVGB(%%mm2, %%mm1) // (L20 + L00)/2
+ PAVGB(%%mm0, %%mm1) // (L20 + L00 + 2L10)/4
+ "psubusb %%mm7, %%mm0 \n\t"
+ "psubusb %%mm7, %%mm2 \n\t"
+ "psubusb %%mm7, %%mm3 \n\t"
+ "pcmpeqb "MANGLE(b00)", %%mm0 \n\t" // L10 > a ? 0 : -1
+ "pcmpeqb "MANGLE(b00)", %%mm2 \n\t" // L20 > a ? 0 : -1
+ "pcmpeqb "MANGLE(b00)", %%mm3 \n\t" // L00 > a ? 0 : -1
+ "paddb %%mm2, %%mm0 \n\t"
+ "paddb %%mm3, %%mm0 \n\t"
+
+ "movq (%%"REG_a"), %%mm2 \n\t" // L11
+ "movq %%mm2, %%mm3 \n\t" // L11
+ "movq %%mm2, %%mm4 \n\t" // L11
+ "psllq $8, %%mm3 \n\t"
+ "psrlq $8, %%mm4 \n\t"
+ "movd -4(%%"REG_a"), %%mm5 \n\t"
+ "movd 8(%%"REG_a"), %%mm6 \n\t"
+ "psrlq $24, %%mm5 \n\t"
+ "psllq $56, %%mm6 \n\t"
+ "por %%mm5, %%mm3 \n\t" // L01
+ "por %%mm6, %%mm4 \n\t" // L21
+ "movq %%mm3, %%mm5 \n\t" // L01
+ PAVGB(%%mm4, %%mm3) // (L21 + L01)/2
+ PAVGB(%%mm2, %%mm3) // (L21 + L01 + 2L11)/4
+ "psubusb %%mm7, %%mm2 \n\t"
+ "psubusb %%mm7, %%mm4 \n\t"
+ "psubusb %%mm7, %%mm5 \n\t"
+ "pcmpeqb "MANGLE(b00)", %%mm2 \n\t" // L11 > a ? 0 : -1
+ "pcmpeqb "MANGLE(b00)", %%mm4 \n\t" // L21 > a ? 0 : -1
+ "pcmpeqb "MANGLE(b00)", %%mm5 \n\t" // L01 > a ? 0 : -1
+ "paddb %%mm4, %%mm2 \n\t"
+ "paddb %%mm5, %%mm2 \n\t"
+// 0, 2, 3, 1
+#define REAL_DERING_CORE(dst,src,ppsx,psx,sx,pplx,plx,lx,t0,t1) \
+ "movq " #src ", " #sx " \n\t" /* src[0] */\
+ "movq " #sx ", " #lx " \n\t" /* src[0] */\
+ "movq " #sx ", " #t0 " \n\t" /* src[0] */\
+ "psllq $8, " #lx " \n\t"\
+ "psrlq $8, " #t0 " \n\t"\
+ "movd -4" #src ", " #t1 " \n\t"\
+ "psrlq $24, " #t1 " \n\t"\
+ "por " #t1 ", " #lx " \n\t" /* src[-1] */\
+ "movd 8" #src ", " #t1 " \n\t"\
+ "psllq $56, " #t1 " \n\t"\
+ "por " #t1 ", " #t0 " \n\t" /* src[+1] */\
+ "movq " #lx ", " #t1 " \n\t" /* src[-1] */\
+ PAVGB(t0, lx) /* (src[-1] + src[+1])/2 */\
+ PAVGB(sx, lx) /* (src[-1] + 2src[0] + src[+1])/4 */\
+ PAVGB(lx, pplx) \
+ "movq " #lx ", 8(%%"REG_c") \n\t"\
+ "movq (%%"REG_c"), " #lx " \n\t"\
+ "psubusb " #lx ", " #t1 " \n\t"\
+ "psubusb " #lx ", " #t0 " \n\t"\
+ "psubusb " #lx ", " #sx " \n\t"\
+ "movq "MANGLE(b00)", " #lx " \n\t"\
+ "pcmpeqb " #lx ", " #t1 " \n\t" /* src[-1] > a ? 0 : -1*/\
+ "pcmpeqb " #lx ", " #t0 " \n\t" /* src[+1] > a ? 0 : -1*/\
+ "pcmpeqb " #lx ", " #sx " \n\t" /* src[0] > a ? 0 : -1*/\
+ "paddb " #t1 ", " #t0 " \n\t"\
+ "paddb " #t0 ", " #sx " \n\t"\
+\
+ PAVGB(plx, pplx) /* filtered */\
+ "movq " #dst ", " #t0 " \n\t" /* dst */\
+ "movq " #t0 ", " #t1 " \n\t" /* dst */\
+ "psubusb %3, " #t0 " \n\t"\
+ "paddusb %3, " #t1 " \n\t"\
+ PMAXUB(t0, pplx)\
+ PMINUB(t1, pplx, t0)\
+ "paddb " #sx ", " #ppsx " \n\t"\
+ "paddb " #psx ", " #ppsx " \n\t"\
+ "#paddb "MANGLE(b02)", " #ppsx " \n\t"\
+ "pand "MANGLE(b08)", " #ppsx " \n\t"\
+ "pcmpeqb " #lx ", " #ppsx " \n\t"\
+ "pand " #ppsx ", " #pplx " \n\t"\
+ "pandn " #dst ", " #ppsx " \n\t"\
+ "por " #pplx ", " #ppsx " \n\t"\
+ "movq " #ppsx ", " #dst " \n\t"\
+ "movq 8(%%"REG_c"), " #lx " \n\t"
+
+#define DERING_CORE(dst,src,ppsx,psx,sx,pplx,plx,lx,t0,t1) \
+ REAL_DERING_CORE(dst,src,ppsx,psx,sx,pplx,plx,lx,t0,t1)
+/*
+0000000
+1111111
+
+1111110
+1111101
+1111100
+1111011
+1111010
+1111001
+
+1111000
+1110111
+
+*/
+//DERING_CORE(dst ,src ,ppsx ,psx ,sx ,pplx ,plx ,lx ,t0 ,t1)
+DERING_CORE((%%REGa) ,(%%REGa, %1) ,%%mm0,%%mm2,%%mm4,%%mm1,%%mm3,%%mm5,%%mm6,%%mm7)
+DERING_CORE((%%REGa, %1) ,(%%REGa, %1, 2),%%mm2,%%mm4,%%mm0,%%mm3,%%mm5,%%mm1,%%mm6,%%mm7)
+DERING_CORE((%%REGa, %1, 2),(%0, %1, 4) ,%%mm4,%%mm0,%%mm2,%%mm5,%%mm1,%%mm3,%%mm6,%%mm7)
+DERING_CORE((%0, %1, 4) ,(%%REGd) ,%%mm0,%%mm2,%%mm4,%%mm1,%%mm3,%%mm5,%%mm6,%%mm7)
+DERING_CORE((%%REGd) ,(%%REGd, %1) ,%%mm2,%%mm4,%%mm0,%%mm3,%%mm5,%%mm1,%%mm6,%%mm7)
+DERING_CORE((%%REGd, %1) ,(%%REGd, %1, 2),%%mm4,%%mm0,%%mm2,%%mm5,%%mm1,%%mm3,%%mm6,%%mm7)
+DERING_CORE((%%REGd, %1, 2),(%0, %1, 8) ,%%mm0,%%mm2,%%mm4,%%mm1,%%mm3,%%mm5,%%mm6,%%mm7)
+DERING_CORE((%0, %1, 8) ,(%%REGd, %1, 4),%%mm2,%%mm4,%%mm0,%%mm3,%%mm5,%%mm1,%%mm6,%%mm7)
+
+ "1: \n\t"
+ : : "r" (src), "r" ((long)stride), "m" (c->pQPb), "m"(c->pQPb2)
+ : "%"REG_a, "%"REG_d, "%"REG_c
+ );
+#else //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+ int y;
+ int min=255;
+ int max=0;
+ int avg;
+ uint8_t *p;
+ int s[10];
+ const int QP2= c->QP/2 + 1;
+
+ for(y=1; y<9; y++)
+ {
+ int x;
+ p= src + stride*y;
+ for(x=1; x<9; x++)
+ {
+ p++;
+ if(*p > max) max= *p;
+ if(*p < min) min= *p;
+ }
+ }
+ avg= (min + max + 1)>>1;
+
+ if(max - min <deringThreshold) return;
+
+ for(y=0; y<10; y++)
+ {
+ int t = 0;
+
+ if(src[stride*y + 0] > avg) t+= 1;
+ if(src[stride*y + 1] > avg) t+= 2;
+ if(src[stride*y + 2] > avg) t+= 4;
+ if(src[stride*y + 3] > avg) t+= 8;
+ if(src[stride*y + 4] > avg) t+= 16;
+ if(src[stride*y + 5] > avg) t+= 32;
+ if(src[stride*y + 6] > avg) t+= 64;
+ if(src[stride*y + 7] > avg) t+= 128;
+ if(src[stride*y + 8] > avg) t+= 256;
+ if(src[stride*y + 9] > avg) t+= 512;
+
+ t |= (~t)<<16;
+ t &= (t<<1) & (t>>1);
+ s[y] = t;
+ }
+
+ for(y=1; y<9; y++)
+ {
+ int t = s[y-1] & s[y] & s[y+1];
+ t|= t>>16;
+ s[y-1]= t;
+ }
+
+ for(y=1; y<9; y++)
+ {
+ int x;
+ int t = s[y-1];
+
+ p= src + stride*y;
+ for(x=1; x<9; x++)
+ {
+ p++;
+ if(t & (1<<x))
+ {
+ int f= (*(p-stride-1)) + 2*(*(p-stride)) + (*(p-stride+1))
+ +2*(*(p -1)) + 4*(*p ) + 2*(*(p +1))
+ +(*(p+stride-1)) + 2*(*(p+stride)) + (*(p+stride+1));
+ f= (f + 8)>>4;
+
+#ifdef DEBUG_DERING_THRESHOLD
+ asm volatile("emms\n\t":);
+ {
+ static long long numPixels=0;
+ if(x!=1 && x!=8 && y!=1 && y!=8) numPixels++;
+// if((max-min)<20 || (max-min)*QP<200)
+// if((max-min)*QP < 500)
+// if(max-min<QP/2)
+ if(max-min < 20)
+ {
+ static int numSkiped=0;
+ static int errorSum=0;
+ static int worstQP=0;
+ static int worstRange=0;
+ static int worstDiff=0;
+ int diff= (f - *p);
+ int absDiff= FFABS(diff);
+ int error= diff*diff;
+
+ if(x==1 || x==8 || y==1 || y==8) continue;
+
+ numSkiped++;
+ if(absDiff > worstDiff)
+ {
+ worstDiff= absDiff;
+ worstQP= QP;
+ worstRange= max-min;
+ }
+ errorSum+= error;
+
+ if(1024LL*1024LL*1024LL % numSkiped == 0)
+ {
+ av_log(c, AV_LOG_INFO, "sum:%1.3f, skip:%d, wQP:%d, "
+ "wRange:%d, wDiff:%d, relSkip:%1.3f\n",
+ (float)errorSum/numSkiped, numSkiped, worstQP, worstRange,
+ worstDiff, (float)numSkiped/numPixels);
+ }
+ }
+ }
+#endif
+ if (*p + QP2 < f) *p= *p + QP2;
+ else if(*p - QP2 > f) *p= *p - QP2;
+ else *p=f;
+ }
+ }
+ }
+#ifdef DEBUG_DERING_THRESHOLD
+ if(max-min < 20)
+ {
+ for(y=1; y<9; y++)
+ {
+ int x;
+ int t = 0;
+ p= src + stride*y;
+ for(x=1; x<9; x++)
+ {
+ p++;
+ *p = FFMIN(*p + 20, 255);
+ }
+ }
+// src[0] = src[7]=src[stride*7]=src[stride*7 + 7]=255;
+ }
+#endif
+#endif //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+}
+#endif //HAVE_ALTIVEC
+
+/**
+ * Deinterlaces the given block by linearly interpolating every second line.
+ * will be called for every 8x8 block and can read & write from line 4-15
+ * lines 0-3 have been passed through the deblock / dering filters allready, but can be read too
+ * lines 4-12 will be read into the deblocking filter and should be deinterlaced
+ */
+static inline void RENAME(deInterlaceInterpolateLinear)(uint8_t src[], int stride)
+{
+#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+ src+= 4*stride;
+ asm volatile(
+ "lea (%0, %1), %%"REG_a" \n\t"
+ "lea (%%"REG_a", %1, 4), %%"REG_c" \n\t"
+// 0 1 2 3 4 5 6 7 8 9
+// %0 eax eax+%1 eax+2%1 %0+4%1 ecx ecx+%1 ecx+2%1 %0+8%1 ecx+4%1
+
+ "movq (%0), %%mm0 \n\t"
+ "movq (%%"REG_a", %1), %%mm1 \n\t"
+ PAVGB(%%mm1, %%mm0)
+ "movq %%mm0, (%%"REG_a") \n\t"
+ "movq (%0, %1, 4), %%mm0 \n\t"
+ PAVGB(%%mm0, %%mm1)
+ "movq %%mm1, (%%"REG_a", %1, 2) \n\t"
+ "movq (%%"REG_c", %1), %%mm1 \n\t"
+ PAVGB(%%mm1, %%mm0)
+ "movq %%mm0, (%%"REG_c") \n\t"
+ "movq (%0, %1, 8), %%mm0 \n\t"
+ PAVGB(%%mm0, %%mm1)
+ "movq %%mm1, (%%"REG_c", %1, 2) \n\t"
+
+ : : "r" (src), "r" ((long)stride)
+ : "%"REG_a, "%"REG_c
+ );
+#else
+ int a, b, x;
+ src+= 4*stride;
+
+ for(x=0; x<2; x++){
+ a= *(uint32_t*)&src[stride*0];
+ b= *(uint32_t*)&src[stride*2];
+ *(uint32_t*)&src[stride*1]= (a|b) - (((a^b)&0xFEFEFEFEUL)>>1);
+ a= *(uint32_t*)&src[stride*4];
+ *(uint32_t*)&src[stride*3]= (a|b) - (((a^b)&0xFEFEFEFEUL)>>1);
+ b= *(uint32_t*)&src[stride*6];
+ *(uint32_t*)&src[stride*5]= (a|b) - (((a^b)&0xFEFEFEFEUL)>>1);
+ a= *(uint32_t*)&src[stride*8];
+ *(uint32_t*)&src[stride*7]= (a|b) - (((a^b)&0xFEFEFEFEUL)>>1);
+ src += 4;
+ }
+#endif
+}
+
+/**
+ * Deinterlaces the given block by cubic interpolating every second line.
+ * will be called for every 8x8 block and can read & write from line 4-15
+ * lines 0-3 have been passed through the deblock / dering filters allready, but can be read too
+ * lines 4-12 will be read into the deblocking filter and should be deinterlaced
+ * this filter will read lines 3-15 and write 7-13
+ */
+static inline void RENAME(deInterlaceInterpolateCubic)(uint8_t src[], int stride)
+{
+#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+ src+= stride*3;
+ asm volatile(
+ "lea (%0, %1), %%"REG_a" \n\t"
+ "lea (%%"REG_a", %1, 4), %%"REG_d" \n\t"
+ "lea (%%"REG_d", %1, 4), %%"REG_c" \n\t"
+ "add %1, %%"REG_c" \n\t"
+ "pxor %%mm7, %%mm7 \n\t"
+// 0 1 2 3 4 5 6 7 8 9 10
+// %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1 ecx
+
+#define REAL_DEINT_CUBIC(a,b,c,d,e)\
+ "movq " #a ", %%mm0 \n\t"\
+ "movq " #b ", %%mm1 \n\t"\
+ "movq " #d ", %%mm2 \n\t"\
+ "movq " #e ", %%mm3 \n\t"\
+ PAVGB(%%mm2, %%mm1) /* (b+d) /2 */\
+ PAVGB(%%mm3, %%mm0) /* a(a+e) /2 */\
+ "movq %%mm0, %%mm2 \n\t"\
+ "punpcklbw %%mm7, %%mm0 \n\t"\
+ "punpckhbw %%mm7, %%mm2 \n\t"\
+ "movq %%mm1, %%mm3 \n\t"\
+ "punpcklbw %%mm7, %%mm1 \n\t"\
+ "punpckhbw %%mm7, %%mm3 \n\t"\
+ "psubw %%mm1, %%mm0 \n\t" /* L(a+e - (b+d))/2 */\
+ "psubw %%mm3, %%mm2 \n\t" /* H(a+e - (b+d))/2 */\
+ "psraw $3, %%mm0 \n\t" /* L(a+e - (b+d))/16 */\
+ "psraw $3, %%mm2 \n\t" /* H(a+e - (b+d))/16 */\
+ "psubw %%mm0, %%mm1 \n\t" /* L(9b + 9d - a - e)/16 */\
+ "psubw %%mm2, %%mm3 \n\t" /* H(9b + 9d - a - e)/16 */\
+ "packuswb %%mm3, %%mm1 \n\t"\
+ "movq %%mm1, " #c " \n\t"
+#define DEINT_CUBIC(a,b,c,d,e) REAL_DEINT_CUBIC(a,b,c,d,e)
+
+DEINT_CUBIC((%0) , (%%REGa, %1), (%%REGa, %1, 2), (%0, %1, 4) , (%%REGd, %1))
+DEINT_CUBIC((%%REGa, %1), (%0, %1, 4) , (%%REGd) , (%%REGd, %1), (%0, %1, 8))
+DEINT_CUBIC((%0, %1, 4) , (%%REGd, %1), (%%REGd, %1, 2), (%0, %1, 8) , (%%REGc))
+DEINT_CUBIC((%%REGd, %1), (%0, %1, 8) , (%%REGd, %1, 4), (%%REGc) , (%%REGc, %1, 2))
+
+ : : "r" (src), "r" ((long)stride)
+ : "%"REG_a, "%"REG_d, "%"REG_c
+ );
+#else //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+ int x;
+ src+= stride*3;
+ for(x=0; x<8; x++)
+ {
+ src[stride*3] = CLIP((-src[0] + 9*src[stride*2] + 9*src[stride*4] - src[stride*6])>>4);
+ src[stride*5] = CLIP((-src[stride*2] + 9*src[stride*4] + 9*src[stride*6] - src[stride*8])>>4);
+ src[stride*7] = CLIP((-src[stride*4] + 9*src[stride*6] + 9*src[stride*8] - src[stride*10])>>4);
+ src[stride*9] = CLIP((-src[stride*6] + 9*src[stride*8] + 9*src[stride*10] - src[stride*12])>>4);
+ src++;
+ }
+#endif //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+}
+
+/**
+ * Deinterlaces the given block by filtering every second line with a (-1 4 2 4 -1) filter.
+ * will be called for every 8x8 block and can read & write from line 4-15
+ * lines 0-3 have been passed through the deblock / dering filters allready, but can be read too
+ * lines 4-12 will be read into the deblocking filter and should be deinterlaced
+ * this filter will read lines 4-13 and write 5-11
+ */
+static inline void RENAME(deInterlaceFF)(uint8_t src[], int stride, uint8_t *tmp)
+{
+#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+ src+= stride*4;
+ asm volatile(
+ "lea (%0, %1), %%"REG_a" \n\t"
+ "lea (%%"REG_a", %1, 4), %%"REG_d" \n\t"
+ "pxor %%mm7, %%mm7 \n\t"
+ "movq (%2), %%mm0 \n\t"
+// 0 1 2 3 4 5 6 7 8 9 10
+// %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1 ecx
+
+#define REAL_DEINT_FF(a,b,c,d)\
+ "movq " #a ", %%mm1 \n\t"\
+ "movq " #b ", %%mm2 \n\t"\
+ "movq " #c ", %%mm3 \n\t"\
+ "movq " #d ", %%mm4 \n\t"\
+ PAVGB(%%mm3, %%mm1) \
+ PAVGB(%%mm4, %%mm0) \
+ "movq %%mm0, %%mm3 \n\t"\
+ "punpcklbw %%mm7, %%mm0 \n\t"\
+ "punpckhbw %%mm7, %%mm3 \n\t"\
+ "movq %%mm1, %%mm4 \n\t"\
+ "punpcklbw %%mm7, %%mm1 \n\t"\
+ "punpckhbw %%mm7, %%mm4 \n\t"\
+ "psllw $2, %%mm1 \n\t"\
+ "psllw $2, %%mm4 \n\t"\
+ "psubw %%mm0, %%mm1 \n\t"\
+ "psubw %%mm3, %%mm4 \n\t"\
+ "movq %%mm2, %%mm5 \n\t"\
+ "movq %%mm2, %%mm0 \n\t"\
+ "punpcklbw %%mm7, %%mm2 \n\t"\
+ "punpckhbw %%mm7, %%mm5 \n\t"\
+ "paddw %%mm2, %%mm1 \n\t"\
+ "paddw %%mm5, %%mm4 \n\t"\
+ "psraw $2, %%mm1 \n\t"\
+ "psraw $2, %%mm4 \n\t"\
+ "packuswb %%mm4, %%mm1 \n\t"\
+ "movq %%mm1, " #b " \n\t"\
+
+#define DEINT_FF(a,b,c,d) REAL_DEINT_FF(a,b,c,d)
+
+DEINT_FF((%0) , (%%REGa) , (%%REGa, %1), (%%REGa, %1, 2))
+DEINT_FF((%%REGa, %1), (%%REGa, %1, 2), (%0, %1, 4) , (%%REGd) )
+DEINT_FF((%0, %1, 4) , (%%REGd) , (%%REGd, %1), (%%REGd, %1, 2))
+DEINT_FF((%%REGd, %1), (%%REGd, %1, 2), (%0, %1, 8) , (%%REGd, %1, 4))
+
+ "movq %%mm0, (%2) \n\t"
+ : : "r" (src), "r" ((long)stride), "r"(tmp)
+ : "%"REG_a, "%"REG_d
+ );
+#else //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+ int x;
+ src+= stride*4;
+ for(x=0; x<8; x++)
+ {
+ int t1= tmp[x];
+ int t2= src[stride*1];
+
+ src[stride*1]= CLIP((-t1 + 4*src[stride*0] + 2*t2 + 4*src[stride*2] - src[stride*3] + 4)>>3);
+ t1= src[stride*4];
+ src[stride*3]= CLIP((-t2 + 4*src[stride*2] + 2*t1 + 4*src[stride*4] - src[stride*5] + 4)>>3);
+ t2= src[stride*6];
+ src[stride*5]= CLIP((-t1 + 4*src[stride*4] + 2*t2 + 4*src[stride*6] - src[stride*7] + 4)>>3);
+ t1= src[stride*8];
+ src[stride*7]= CLIP((-t2 + 4*src[stride*6] + 2*t1 + 4*src[stride*8] - src[stride*9] + 4)>>3);
+ tmp[x]= t1;
+
+ src++;
+ }
+#endif //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+}
+
+/**
+ * Deinterlaces the given block by filtering every line with a (-1 2 6 2 -1) filter.
+ * will be called for every 8x8 block and can read & write from line 4-15
+ * lines 0-3 have been passed through the deblock / dering filters allready, but can be read too
+ * lines 4-12 will be read into the deblocking filter and should be deinterlaced
+ * this filter will read lines 4-13 and write 4-11
+ */
+static inline void RENAME(deInterlaceL5)(uint8_t src[], int stride, uint8_t *tmp, uint8_t *tmp2)
+{
+#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+ src+= stride*4;
+ asm volatile(
+ "lea (%0, %1), %%"REG_a" \n\t"
+ "lea (%%"REG_a", %1, 4), %%"REG_d" \n\t"
+ "pxor %%mm7, %%mm7 \n\t"
+ "movq (%2), %%mm0 \n\t"
+ "movq (%3), %%mm1 \n\t"
+// 0 1 2 3 4 5 6 7 8 9 10
+// %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1 ecx
+
+#define REAL_DEINT_L5(t1,t2,a,b,c)\
+ "movq " #a ", %%mm2 \n\t"\
+ "movq " #b ", %%mm3 \n\t"\
+ "movq " #c ", %%mm4 \n\t"\
+ PAVGB(t2, %%mm3) \
+ PAVGB(t1, %%mm4) \
+ "movq %%mm2, %%mm5 \n\t"\
+ "movq %%mm2, " #t1 " \n\t"\
+ "punpcklbw %%mm7, %%mm2 \n\t"\
+ "punpckhbw %%mm7, %%mm5 \n\t"\
+ "movq %%mm2, %%mm6 \n\t"\
+ "paddw %%mm2, %%mm2 \n\t"\
+ "paddw %%mm6, %%mm2 \n\t"\
+ "movq %%mm5, %%mm6 \n\t"\
+ "paddw %%mm5, %%mm5 \n\t"\
+ "paddw %%mm6, %%mm5 \n\t"\
+ "movq %%mm3, %%mm6 \n\t"\
+ "punpcklbw %%mm7, %%mm3 \n\t"\
+ "punpckhbw %%mm7, %%mm6 \n\t"\
+ "paddw %%mm3, %%mm3 \n\t"\
+ "paddw %%mm6, %%mm6 \n\t"\
+ "paddw %%mm3, %%mm2 \n\t"\
+ "paddw %%mm6, %%mm5 \n\t"\
+ "movq %%mm4, %%mm6 \n\t"\
+ "punpcklbw %%mm7, %%mm4 \n\t"\
+ "punpckhbw %%mm7, %%mm6 \n\t"\
+ "psubw %%mm4, %%mm2 \n\t"\
+ "psubw %%mm6, %%mm5 \n\t"\
+ "psraw $2, %%mm2 \n\t"\
+ "psraw $2, %%mm5 \n\t"\
+ "packuswb %%mm5, %%mm2 \n\t"\
+ "movq %%mm2, " #a " \n\t"\
+
+#define DEINT_L5(t1,t2,a,b,c) REAL_DEINT_L5(t1,t2,a,b,c)
+
+DEINT_L5(%%mm0, %%mm1, (%0) , (%%REGa) , (%%REGa, %1) )
+DEINT_L5(%%mm1, %%mm0, (%%REGa) , (%%REGa, %1) , (%%REGa, %1, 2))
+DEINT_L5(%%mm0, %%mm1, (%%REGa, %1) , (%%REGa, %1, 2), (%0, %1, 4) )
+DEINT_L5(%%mm1, %%mm0, (%%REGa, %1, 2), (%0, %1, 4) , (%%REGd) )
+DEINT_L5(%%mm0, %%mm1, (%0, %1, 4) , (%%REGd) , (%%REGd, %1) )
+DEINT_L5(%%mm1, %%mm0, (%%REGd) , (%%REGd, %1) , (%%REGd, %1, 2))
+DEINT_L5(%%mm0, %%mm1, (%%REGd, %1) , (%%REGd, %1, 2), (%0, %1, 8) )
+DEINT_L5(%%mm1, %%mm0, (%%REGd, %1, 2), (%0, %1, 8) , (%%REGd, %1, 4))
+
+ "movq %%mm0, (%2) \n\t"
+ "movq %%mm1, (%3) \n\t"
+ : : "r" (src), "r" ((long)stride), "r"(tmp), "r"(tmp2)
+ : "%"REG_a, "%"REG_d
+ );
+#else //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+ int x;
+ src+= stride*4;
+ for(x=0; x<8; x++)
+ {
+ int t1= tmp[x];
+ int t2= tmp2[x];
+ int t3= src[0];
+
+ src[stride*0]= CLIP((-(t1 + src[stride*2]) + 2*(t2 + src[stride*1]) + 6*t3 + 4)>>3);
+ t1= src[stride*1];
+ src[stride*1]= CLIP((-(t2 + src[stride*3]) + 2*(t3 + src[stride*2]) + 6*t1 + 4)>>3);
+ t2= src[stride*2];
+ src[stride*2]= CLIP((-(t3 + src[stride*4]) + 2*(t1 + src[stride*3]) + 6*t2 + 4)>>3);
+ t3= src[stride*3];
+ src[stride*3]= CLIP((-(t1 + src[stride*5]) + 2*(t2 + src[stride*4]) + 6*t3 + 4)>>3);
+ t1= src[stride*4];
+ src[stride*4]= CLIP((-(t2 + src[stride*6]) + 2*(t3 + src[stride*5]) + 6*t1 + 4)>>3);
+ t2= src[stride*5];
+ src[stride*5]= CLIP((-(t3 + src[stride*7]) + 2*(t1 + src[stride*6]) + 6*t2 + 4)>>3);
+ t3= src[stride*6];
+ src[stride*6]= CLIP((-(t1 + src[stride*8]) + 2*(t2 + src[stride*7]) + 6*t3 + 4)>>3);
+ t1= src[stride*7];
+ src[stride*7]= CLIP((-(t2 + src[stride*9]) + 2*(t3 + src[stride*8]) + 6*t1 + 4)>>3);
+
+ tmp[x]= t3;
+ tmp2[x]= t1;
+
+ src++;
+ }
+#endif //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+}
+
+/**
+ * Deinterlaces the given block by filtering all lines with a (1 2 1) filter.
+ * will be called for every 8x8 block and can read & write from line 4-15
+ * lines 0-3 have been passed through the deblock / dering filters allready, but can be read too
+ * lines 4-12 will be read into the deblocking filter and should be deinterlaced
+ * this filter will read lines 4-13 and write 4-11
+ */
+static inline void RENAME(deInterlaceBlendLinear)(uint8_t src[], int stride, uint8_t *tmp)
+{
+#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+ src+= 4*stride;
+ asm volatile(
+ "lea (%0, %1), %%"REG_a" \n\t"
+ "lea (%%"REG_a", %1, 4), %%"REG_d" \n\t"
+// 0 1 2 3 4 5 6 7 8 9
+// %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1
+
+ "movq (%2), %%mm0 \n\t" // L0
+ "movq (%%"REG_a"), %%mm1 \n\t" // L2
+ PAVGB(%%mm1, %%mm0) // L0+L2
+ "movq (%0), %%mm2 \n\t" // L1
+ PAVGB(%%mm2, %%mm0)
+ "movq %%mm0, (%0) \n\t"
+ "movq (%%"REG_a", %1), %%mm0 \n\t" // L3
+ PAVGB(%%mm0, %%mm2) // L1+L3
+ PAVGB(%%mm1, %%mm2) // 2L2 + L1 + L3
+ "movq %%mm2, (%%"REG_a") \n\t"
+ "movq (%%"REG_a", %1, 2), %%mm2 \n\t" // L4
+ PAVGB(%%mm2, %%mm1) // L2+L4
+ PAVGB(%%mm0, %%mm1) // 2L3 + L2 + L4
+ "movq %%mm1, (%%"REG_a", %1) \n\t"
+ "movq (%0, %1, 4), %%mm1 \n\t" // L5
+ PAVGB(%%mm1, %%mm0) // L3+L5
+ PAVGB(%%mm2, %%mm0) // 2L4 + L3 + L5
+ "movq %%mm0, (%%"REG_a", %1, 2) \n\t"
+ "movq (%%"REG_d"), %%mm0 \n\t" // L6
+ PAVGB(%%mm0, %%mm2) // L4+L6
+ PAVGB(%%mm1, %%mm2) // 2L5 + L4 + L6
+ "movq %%mm2, (%0, %1, 4) \n\t"
+ "movq (%%"REG_d", %1), %%mm2 \n\t" // L7
+ PAVGB(%%mm2, %%mm1) // L5+L7
+ PAVGB(%%mm0, %%mm1) // 2L6 + L5 + L7
+ "movq %%mm1, (%%"REG_d") \n\t"
+ "movq (%%"REG_d", %1, 2), %%mm1 \n\t" // L8
+ PAVGB(%%mm1, %%mm0) // L6+L8
+ PAVGB(%%mm2, %%mm0) // 2L7 + L6 + L8
+ "movq %%mm0, (%%"REG_d", %1) \n\t"
+ "movq (%0, %1, 8), %%mm0 \n\t" // L9
+ PAVGB(%%mm0, %%mm2) // L7+L9
+ PAVGB(%%mm1, %%mm2) // 2L8 + L7 + L9
+ "movq %%mm2, (%%"REG_d", %1, 2) \n\t"
+ "movq %%mm1, (%2) \n\t"
+
+ : : "r" (src), "r" ((long)stride), "r" (tmp)
+ : "%"REG_a, "%"REG_d
+ );
+#else //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+ int a, b, c, x;
+ src+= 4*stride;
+
+ for(x=0; x<2; x++){
+ a= *(uint32_t*)&tmp[stride*0];
+ b= *(uint32_t*)&src[stride*0];
+ c= *(uint32_t*)&src[stride*1];
+ a= (a&c) + (((a^c)&0xFEFEFEFEUL)>>1);
+ *(uint32_t*)&src[stride*0]= (a|b) - (((a^b)&0xFEFEFEFEUL)>>1);
+
+ a= *(uint32_t*)&src[stride*2];
+ b= (a&b) + (((a^b)&0xFEFEFEFEUL)>>1);
+ *(uint32_t*)&src[stride*1]= (c|b) - (((c^b)&0xFEFEFEFEUL)>>1);
+
+ b= *(uint32_t*)&src[stride*3];
+ c= (b&c) + (((b^c)&0xFEFEFEFEUL)>>1);
+ *(uint32_t*)&src[stride*2]= (c|a) - (((c^a)&0xFEFEFEFEUL)>>1);
+
+ c= *(uint32_t*)&src[stride*4];
+ a= (a&c) + (((a^c)&0xFEFEFEFEUL)>>1);
+ *(uint32_t*)&src[stride*3]= (a|b) - (((a^b)&0xFEFEFEFEUL)>>1);
+
+ a= *(uint32_t*)&src[stride*5];
+ b= (a&b) + (((a^b)&0xFEFEFEFEUL)>>1);
+ *(uint32_t*)&src[stride*4]= (c|b) - (((c^b)&0xFEFEFEFEUL)>>1);
+
+ b= *(uint32_t*)&src[stride*6];
+ c= (b&c) + (((b^c)&0xFEFEFEFEUL)>>1);
+ *(uint32_t*)&src[stride*5]= (c|a) - (((c^a)&0xFEFEFEFEUL)>>1);
+
+ c= *(uint32_t*)&src[stride*7];
+ a= (a&c) + (((a^c)&0xFEFEFEFEUL)>>1);
+ *(uint32_t*)&src[stride*6]= (a|b) - (((a^b)&0xFEFEFEFEUL)>>1);
+
+ a= *(uint32_t*)&src[stride*8];
+ b= (a&b) + (((a^b)&0xFEFEFEFEUL)>>1);
+ *(uint32_t*)&src[stride*7]= (c|b) - (((c^b)&0xFEFEFEFEUL)>>1);
+
+ *(uint32_t*)&tmp[stride*0]= c;
+ src += 4;
+ tmp += 4;
+ }
+#endif //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+}
+
+/**
+ * Deinterlaces the given block by applying a median filter to every second line.
+ * will be called for every 8x8 block and can read & write from line 4-15,
+ * lines 0-3 have been passed through the deblock / dering filters allready, but can be read too
+ * lines 4-12 will be read into the deblocking filter and should be deinterlaced
+ */
+static inline void RENAME(deInterlaceMedian)(uint8_t src[], int stride)
+{
+#ifdef HAVE_MMX
+ src+= 4*stride;
+#ifdef HAVE_MMX2
+ asm volatile(
+ "lea (%0, %1), %%"REG_a" \n\t"
+ "lea (%%"REG_a", %1, 4), %%"REG_d" \n\t"
+// 0 1 2 3 4 5 6 7 8 9
+// %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1
+
+ "movq (%0), %%mm0 \n\t" //
+ "movq (%%"REG_a", %1), %%mm2 \n\t" //
+ "movq (%%"REG_a"), %%mm1 \n\t" //
+ "movq %%mm0, %%mm3 \n\t"
+ "pmaxub %%mm1, %%mm0 \n\t" //
+ "pminub %%mm3, %%mm1 \n\t" //
+ "pmaxub %%mm2, %%mm1 \n\t" //
+ "pminub %%mm1, %%mm0 \n\t"
+ "movq %%mm0, (%%"REG_a") \n\t"
+
+ "movq (%0, %1, 4), %%mm0 \n\t" //
+ "movq (%%"REG_a", %1, 2), %%mm1 \n\t" //
+ "movq %%mm2, %%mm3 \n\t"
+ "pmaxub %%mm1, %%mm2 \n\t" //
+ "pminub %%mm3, %%mm1 \n\t" //
+ "pmaxub %%mm0, %%mm1 \n\t" //
+ "pminub %%mm1, %%mm2 \n\t"
+ "movq %%mm2, (%%"REG_a", %1, 2) \n\t"
+
+ "movq (%%"REG_d"), %%mm2 \n\t" //
+ "movq (%%"REG_d", %1), %%mm1 \n\t" //
+ "movq %%mm2, %%mm3 \n\t"
+ "pmaxub %%mm0, %%mm2 \n\t" //
+ "pminub %%mm3, %%mm0 \n\t" //
+ "pmaxub %%mm1, %%mm0 \n\t" //
+ "pminub %%mm0, %%mm2 \n\t"
+ "movq %%mm2, (%%"REG_d") \n\t"
+
+ "movq (%%"REG_d", %1, 2), %%mm2 \n\t" //
+ "movq (%0, %1, 8), %%mm0 \n\t" //
+ "movq %%mm2, %%mm3 \n\t"
+ "pmaxub %%mm0, %%mm2 \n\t" //
+ "pminub %%mm3, %%mm0 \n\t" //
+ "pmaxub %%mm1, %%mm0 \n\t" //
+ "pminub %%mm0, %%mm2 \n\t"
+ "movq %%mm2, (%%"REG_d", %1, 2) \n\t"
+
+
+ : : "r" (src), "r" ((long)stride)
+ : "%"REG_a, "%"REG_d
+ );
+
+#else // MMX without MMX2
+ asm volatile(
+ "lea (%0, %1), %%"REG_a" \n\t"
+ "lea (%%"REG_a", %1, 4), %%"REG_d" \n\t"
+// 0 1 2 3 4 5 6 7 8 9
+// %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1
+ "pxor %%mm7, %%mm7 \n\t"
+
+#define REAL_MEDIAN(a,b,c)\
+ "movq " #a ", %%mm0 \n\t"\
+ "movq " #b ", %%mm2 \n\t"\
+ "movq " #c ", %%mm1 \n\t"\
+ "movq %%mm0, %%mm3 \n\t"\
+ "movq %%mm1, %%mm4 \n\t"\
+ "movq %%mm2, %%mm5 \n\t"\
+ "psubusb %%mm1, %%mm3 \n\t"\
+ "psubusb %%mm2, %%mm4 \n\t"\
+ "psubusb %%mm0, %%mm5 \n\t"\
+ "pcmpeqb %%mm7, %%mm3 \n\t"\
+ "pcmpeqb %%mm7, %%mm4 \n\t"\
+ "pcmpeqb %%mm7, %%mm5 \n\t"\
+ "movq %%mm3, %%mm6 \n\t"\
+ "pxor %%mm4, %%mm3 \n\t"\
+ "pxor %%mm5, %%mm4 \n\t"\
+ "pxor %%mm6, %%mm5 \n\t"\
+ "por %%mm3, %%mm1 \n\t"\
+ "por %%mm4, %%mm2 \n\t"\
+ "por %%mm5, %%mm0 \n\t"\
+ "pand %%mm2, %%mm0 \n\t"\
+ "pand %%mm1, %%mm0 \n\t"\
+ "movq %%mm0, " #b " \n\t"
+#define MEDIAN(a,b,c) REAL_MEDIAN(a,b,c)
+
+MEDIAN((%0) , (%%REGa) , (%%REGa, %1))
+MEDIAN((%%REGa, %1), (%%REGa, %1, 2), (%0, %1, 4))
+MEDIAN((%0, %1, 4) , (%%REGd) , (%%REGd, %1))
+MEDIAN((%%REGd, %1), (%%REGd, %1, 2), (%0, %1, 8))
+
+ : : "r" (src), "r" ((long)stride)
+ : "%"REG_a, "%"REG_d
+ );
+#endif //HAVE_MMX2
+#else //HAVE_MMX
+ int x, y;
+ src+= 4*stride;
+ // FIXME - there should be a way to do a few columns in parallel like w/mmx
+ for(x=0; x<8; x++)
+ {
+ uint8_t *colsrc = src;
+ for (y=0; y<4; y++)
+ {
+ int a, b, c, d, e, f;
+ a = colsrc[0 ];
+ b = colsrc[stride ];
+ c = colsrc[stride*2];
+ d = (a-b)>>31;
+ e = (b-c)>>31;
+ f = (c-a)>>31;
+ colsrc[stride ] = (a|(d^f)) & (b|(d^e)) & (c|(e^f));
+ colsrc += stride*2;
+ }
+ src++;
+ }
+#endif //HAVE_MMX
+}
+
+#ifdef HAVE_MMX
+/**
+ * transposes and shift the given 8x8 Block into dst1 and dst2
+ */
+static inline void RENAME(transpose1)(uint8_t *dst1, uint8_t *dst2, uint8_t *src, int srcStride)
+{
+ asm(
+ "lea (%0, %1), %%"REG_a" \n\t"
+// 0 1 2 3 4 5 6 7 8 9
+// %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1
+ "movq (%0), %%mm0 \n\t" // 12345678
+ "movq (%%"REG_a"), %%mm1 \n\t" // abcdefgh
+ "movq %%mm0, %%mm2 \n\t" // 12345678
+ "punpcklbw %%mm1, %%mm0 \n\t" // 1a2b3c4d
+ "punpckhbw %%mm1, %%mm2 \n\t" // 5e6f7g8h
+
+ "movq (%%"REG_a", %1), %%mm1 \n\t"
+ "movq (%%"REG_a", %1, 2), %%mm3 \n\t"
+ "movq %%mm1, %%mm4 \n\t"
+ "punpcklbw %%mm3, %%mm1 \n\t"
+ "punpckhbw %%mm3, %%mm4 \n\t"
+
+ "movq %%mm0, %%mm3 \n\t"
+ "punpcklwd %%mm1, %%mm0 \n\t"
+ "punpckhwd %%mm1, %%mm3 \n\t"
+ "movq %%mm2, %%mm1 \n\t"
+ "punpcklwd %%mm4, %%mm2 \n\t"
+ "punpckhwd %%mm4, %%mm1 \n\t"
+
+ "movd %%mm0, 128(%2) \n\t"
+ "psrlq $32, %%mm0 \n\t"
+ "movd %%mm0, 144(%2) \n\t"
+ "movd %%mm3, 160(%2) \n\t"
+ "psrlq $32, %%mm3 \n\t"
+ "movd %%mm3, 176(%2) \n\t"
+ "movd %%mm3, 48(%3) \n\t"
+ "movd %%mm2, 192(%2) \n\t"
+ "movd %%mm2, 64(%3) \n\t"
+ "psrlq $32, %%mm2 \n\t"
+ "movd %%mm2, 80(%3) \n\t"
+ "movd %%mm1, 96(%3) \n\t"
+ "psrlq $32, %%mm1 \n\t"
+ "movd %%mm1, 112(%3) \n\t"
+
+ "lea (%%"REG_a", %1, 4), %%"REG_a" \n\t"
+
+ "movq (%0, %1, 4), %%mm0 \n\t" // 12345678
+ "movq (%%"REG_a"), %%mm1 \n\t" // abcdefgh
+ "movq %%mm0, %%mm2 \n\t" // 12345678
+ "punpcklbw %%mm1, %%mm0 \n\t" // 1a2b3c4d
+ "punpckhbw %%mm1, %%mm2 \n\t" // 5e6f7g8h
+
+ "movq (%%"REG_a", %1), %%mm1 \n\t"
+ "movq (%%"REG_a", %1, 2), %%mm3 \n\t"
+ "movq %%mm1, %%mm4 \n\t"
+ "punpcklbw %%mm3, %%mm1 \n\t"
+ "punpckhbw %%mm3, %%mm4 \n\t"
+
+ "movq %%mm0, %%mm3 \n\t"
+ "punpcklwd %%mm1, %%mm0 \n\t"
+ "punpckhwd %%mm1, %%mm3 \n\t"
+ "movq %%mm2, %%mm1 \n\t"
+ "punpcklwd %%mm4, %%mm2 \n\t"
+ "punpckhwd %%mm4, %%mm1 \n\t"
+
+ "movd %%mm0, 132(%2) \n\t"
+ "psrlq $32, %%mm0 \n\t"
+ "movd %%mm0, 148(%2) \n\t"
+ "movd %%mm3, 164(%2) \n\t"
+ "psrlq $32, %%mm3 \n\t"
+ "movd %%mm3, 180(%2) \n\t"
+ "movd %%mm3, 52(%3) \n\t"
+ "movd %%mm2, 196(%2) \n\t"
+ "movd %%mm2, 68(%3) \n\t"
+ "psrlq $32, %%mm2 \n\t"
+ "movd %%mm2, 84(%3) \n\t"
+ "movd %%mm1, 100(%3) \n\t"
+ "psrlq $32, %%mm1 \n\t"
+ "movd %%mm1, 116(%3) \n\t"
+
+
+ :: "r" (src), "r" ((long)srcStride), "r" (dst1), "r" (dst2)
+ : "%"REG_a
+ );
+}
+
+/**
+ * transposes the given 8x8 block
+ */
+static inline void RENAME(transpose2)(uint8_t *dst, int dstStride, uint8_t *src)
+{
+ asm(
+ "lea (%0, %1), %%"REG_a" \n\t"
+ "lea (%%"REG_a",%1,4), %%"REG_d" \n\t"
+// 0 1 2 3 4 5 6 7 8 9
+// %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1
+ "movq (%2), %%mm0 \n\t" // 12345678
+ "movq 16(%2), %%mm1 \n\t" // abcdefgh
+ "movq %%mm0, %%mm2 \n\t" // 12345678
+ "punpcklbw %%mm1, %%mm0 \n\t" // 1a2b3c4d
+ "punpckhbw %%mm1, %%mm2 \n\t" // 5e6f7g8h
+
+ "movq 32(%2), %%mm1 \n\t"
+ "movq 48(%2), %%mm3 \n\t"
+ "movq %%mm1, %%mm4 \n\t"
+ "punpcklbw %%mm3, %%mm1 \n\t"
+ "punpckhbw %%mm3, %%mm4 \n\t"
+
+ "movq %%mm0, %%mm3 \n\t"
+ "punpcklwd %%mm1, %%mm0 \n\t"
+ "punpckhwd %%mm1, %%mm3 \n\t"
+ "movq %%mm2, %%mm1 \n\t"
+ "punpcklwd %%mm4, %%mm2 \n\t"
+ "punpckhwd %%mm4, %%mm1 \n\t"
+
+ "movd %%mm0, (%0) \n\t"
+ "psrlq $32, %%mm0 \n\t"
+ "movd %%mm0, (%%"REG_a") \n\t"
+ "movd %%mm3, (%%"REG_a", %1) \n\t"
+ "psrlq $32, %%mm3 \n\t"
+ "movd %%mm3, (%%"REG_a", %1, 2) \n\t"
+ "movd %%mm2, (%0, %1, 4) \n\t"
+ "psrlq $32, %%mm2 \n\t"
+ "movd %%mm2, (%%"REG_d") \n\t"
+ "movd %%mm1, (%%"REG_d", %1) \n\t"
+ "psrlq $32, %%mm1 \n\t"
+ "movd %%mm1, (%%"REG_d", %1, 2) \n\t"
+
+
+ "movq 64(%2), %%mm0 \n\t" // 12345678
+ "movq 80(%2), %%mm1 \n\t" // abcdefgh
+ "movq %%mm0, %%mm2 \n\t" // 12345678
+ "punpcklbw %%mm1, %%mm0 \n\t" // 1a2b3c4d
+ "punpckhbw %%mm1, %%mm2 \n\t" // 5e6f7g8h
+
+ "movq 96(%2), %%mm1 \n\t"
+ "movq 112(%2), %%mm3 \n\t"
+ "movq %%mm1, %%mm4 \n\t"
+ "punpcklbw %%mm3, %%mm1 \n\t"
+ "punpckhbw %%mm3, %%mm4 \n\t"
+
+ "movq %%mm0, %%mm3 \n\t"
+ "punpcklwd %%mm1, %%mm0 \n\t"
+ "punpckhwd %%mm1, %%mm3 \n\t"
+ "movq %%mm2, %%mm1 \n\t"
+ "punpcklwd %%mm4, %%mm2 \n\t"
+ "punpckhwd %%mm4, %%mm1 \n\t"
+
+ "movd %%mm0, 4(%0) \n\t"
+ "psrlq $32, %%mm0 \n\t"
+ "movd %%mm0, 4(%%"REG_a") \n\t"
+ "movd %%mm3, 4(%%"REG_a", %1) \n\t"
+ "psrlq $32, %%mm3 \n\t"
+ "movd %%mm3, 4(%%"REG_a", %1, 2) \n\t"
+ "movd %%mm2, 4(%0, %1, 4) \n\t"
+ "psrlq $32, %%mm2 \n\t"
+ "movd %%mm2, 4(%%"REG_d") \n\t"
+ "movd %%mm1, 4(%%"REG_d", %1) \n\t"
+ "psrlq $32, %%mm1 \n\t"
+ "movd %%mm1, 4(%%"REG_d", %1, 2) \n\t"
+
+ :: "r" (dst), "r" ((long)dstStride), "r" (src)
+ : "%"REG_a, "%"REG_d
+ );
+}
+#endif //HAVE_MMX
+//static long test=0;
+
+#ifndef HAVE_ALTIVEC
+static inline void RENAME(tempNoiseReducer)(uint8_t *src, int stride,
+ uint8_t *tempBlured, uint32_t *tempBluredPast, int *maxNoise)
+{
+ // to save a register (FIXME do this outside of the loops)
+ tempBluredPast[127]= maxNoise[0];
+ tempBluredPast[128]= maxNoise[1];
+ tempBluredPast[129]= maxNoise[2];
+
+#define FAST_L2_DIFF
+//#define L1_DIFF //u should change the thresholds too if u try that one
+#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+ asm volatile(
+ "lea (%2, %2, 2), %%"REG_a" \n\t" // 3*stride
+ "lea (%2, %2, 4), %%"REG_d" \n\t" // 5*stride
+ "lea (%%"REG_d", %2, 2), %%"REG_c" \n\t" // 7*stride
+// 0 1 2 3 4 5 6 7 8 9
+// %x %x+%2 %x+2%2 %x+eax %x+4%2 %x+edx %x+2eax %x+ecx %x+8%2
+//FIXME reorder?
+#ifdef L1_DIFF //needs mmx2
+ "movq (%0), %%mm0 \n\t" // L0
+ "psadbw (%1), %%mm0 \n\t" // |L0-R0|
+ "movq (%0, %2), %%mm1 \n\t" // L1
+ "psadbw (%1, %2), %%mm1 \n\t" // |L1-R1|
+ "movq (%0, %2, 2), %%mm2 \n\t" // L2
+ "psadbw (%1, %2, 2), %%mm2 \n\t" // |L2-R2|
+ "movq (%0, %%"REG_a"), %%mm3 \n\t" // L3
+ "psadbw (%1, %%"REG_a"), %%mm3 \n\t" // |L3-R3|
+
+ "movq (%0, %2, 4), %%mm4 \n\t" // L4
+ "paddw %%mm1, %%mm0 \n\t"
+ "psadbw (%1, %2, 4), %%mm4 \n\t" // |L4-R4|
+ "movq (%0, %%"REG_d"), %%mm5 \n\t" // L5
+ "paddw %%mm2, %%mm0 \n\t"
+ "psadbw (%1, %%"REG_d"), %%mm5 \n\t" // |L5-R5|
+ "movq (%0, %%"REG_a", 2), %%mm6 \n\t" // L6
+ "paddw %%mm3, %%mm0 \n\t"
+ "psadbw (%1, %%"REG_a", 2), %%mm6 \n\t" // |L6-R6|
+ "movq (%0, %%"REG_c"), %%mm7 \n\t" // L7
+ "paddw %%mm4, %%mm0 \n\t"
+ "psadbw (%1, %%"REG_c"), %%mm7 \n\t" // |L7-R7|
+ "paddw %%mm5, %%mm6 \n\t"
+ "paddw %%mm7, %%mm6 \n\t"
+ "paddw %%mm6, %%mm0 \n\t"
+#else //L1_DIFF
+#if defined (FAST_L2_DIFF)
+ "pcmpeqb %%mm7, %%mm7 \n\t"
+ "movq "MANGLE(b80)", %%mm6 \n\t"
+ "pxor %%mm0, %%mm0 \n\t"
+#define REAL_L2_DIFF_CORE(a, b)\
+ "movq " #a ", %%mm5 \n\t"\
+ "movq " #b ", %%mm2 \n\t"\
+ "pxor %%mm7, %%mm2 \n\t"\
+ PAVGB(%%mm2, %%mm5)\
+ "paddb %%mm6, %%mm5 \n\t"\
+ "movq %%mm5, %%mm2 \n\t"\
+ "psllw $8, %%mm5 \n\t"\
+ "pmaddwd %%mm5, %%mm5 \n\t"\
+ "pmaddwd %%mm2, %%mm2 \n\t"\
+ "paddd %%mm2, %%mm5 \n\t"\
+ "psrld $14, %%mm5 \n\t"\
+ "paddd %%mm5, %%mm0 \n\t"
+
+#else //defined (FAST_L2_DIFF)
+ "pxor %%mm7, %%mm7 \n\t"
+ "pxor %%mm0, %%mm0 \n\t"
+#define REAL_L2_DIFF_CORE(a, b)\
+ "movq " #a ", %%mm5 \n\t"\
+ "movq " #b ", %%mm2 \n\t"\
+ "movq %%mm5, %%mm1 \n\t"\
+ "movq %%mm2, %%mm3 \n\t"\
+ "punpcklbw %%mm7, %%mm5 \n\t"\
+ "punpckhbw %%mm7, %%mm1 \n\t"\
+ "punpcklbw %%mm7, %%mm2 \n\t"\
+ "punpckhbw %%mm7, %%mm3 \n\t"\
+ "psubw %%mm2, %%mm5 \n\t"\
+ "psubw %%mm3, %%mm1 \n\t"\
+ "pmaddwd %%mm5, %%mm5 \n\t"\
+ "pmaddwd %%mm1, %%mm1 \n\t"\
+ "paddd %%mm1, %%mm5 \n\t"\
+ "paddd %%mm5, %%mm0 \n\t"
+
+#endif //defined (FAST_L2_DIFF)
+
+#define L2_DIFF_CORE(a, b) REAL_L2_DIFF_CORE(a, b)
+
+L2_DIFF_CORE((%0) , (%1))
+L2_DIFF_CORE((%0, %2) , (%1, %2))
+L2_DIFF_CORE((%0, %2, 2) , (%1, %2, 2))
+L2_DIFF_CORE((%0, %%REGa) , (%1, %%REGa))
+L2_DIFF_CORE((%0, %2, 4) , (%1, %2, 4))
+L2_DIFF_CORE((%0, %%REGd) , (%1, %%REGd))
+L2_DIFF_CORE((%0, %%REGa,2), (%1, %%REGa,2))
+L2_DIFF_CORE((%0, %%REGc) , (%1, %%REGc))
+
+#endif //L1_DIFF
+
+ "movq %%mm0, %%mm4 \n\t"
+ "psrlq $32, %%mm0 \n\t"
+ "paddd %%mm0, %%mm4 \n\t"
+ "movd %%mm4, %%ecx \n\t"
+ "shll $2, %%ecx \n\t"
+ "mov %3, %%"REG_d" \n\t"
+ "addl -4(%%"REG_d"), %%ecx \n\t"
+ "addl 4(%%"REG_d"), %%ecx \n\t"
+ "addl -1024(%%"REG_d"), %%ecx \n\t"
+ "addl $4, %%ecx \n\t"
+ "addl 1024(%%"REG_d"), %%ecx \n\t"
+ "shrl $3, %%ecx \n\t"
+ "movl %%ecx, (%%"REG_d") \n\t"
+
+// "mov %3, %%"REG_c" \n\t"
+// "mov %%"REG_c", test \n\t"
+// "jmp 4f \n\t"
+ "cmpl 512(%%"REG_d"), %%ecx \n\t"
+ " jb 2f \n\t"
+ "cmpl 516(%%"REG_d"), %%ecx \n\t"
+ " jb 1f \n\t"
+
+ "lea (%%"REG_a", %2, 2), %%"REG_d" \n\t" // 5*stride
+ "lea (%%"REG_d", %2, 2), %%"REG_c" \n\t" // 7*stride
+ "movq (%0), %%mm0 \n\t" // L0
+ "movq (%0, %2), %%mm1 \n\t" // L1
+ "movq (%0, %2, 2), %%mm2 \n\t" // L2
+ "movq (%0, %%"REG_a"), %%mm3 \n\t" // L3
+ "movq (%0, %2, 4), %%mm4 \n\t" // L4
+ "movq (%0, %%"REG_d"), %%mm5 \n\t" // L5
+ "movq (%0, %%"REG_a", 2), %%mm6 \n\t" // L6
+ "movq (%0, %%"REG_c"), %%mm7 \n\t" // L7
+ "movq %%mm0, (%1) \n\t" // L0
+ "movq %%mm1, (%1, %2) \n\t" // L1
+ "movq %%mm2, (%1, %2, 2) \n\t" // L2
+ "movq %%mm3, (%1, %%"REG_a") \n\t" // L3
+ "movq %%mm4, (%1, %2, 4) \n\t" // L4
+ "movq %%mm5, (%1, %%"REG_d") \n\t" // L5
+ "movq %%mm6, (%1, %%"REG_a", 2) \n\t" // L6
+ "movq %%mm7, (%1, %%"REG_c") \n\t" // L7
+ "jmp 4f \n\t"
+
+ "1: \n\t"
+ "lea (%%"REG_a", %2, 2), %%"REG_d" \n\t" // 5*stride
+ "lea (%%"REG_d", %2, 2), %%"REG_c" \n\t" // 7*stride
+ "movq (%0), %%mm0 \n\t" // L0
+ PAVGB((%1), %%mm0) // L0
+ "movq (%0, %2), %%mm1 \n\t" // L1
+ PAVGB((%1, %2), %%mm1) // L1
+ "movq (%0, %2, 2), %%mm2 \n\t" // L2
+ PAVGB((%1, %2, 2), %%mm2) // L2
+ "movq (%0, %%"REG_a"), %%mm3 \n\t" // L3
+ PAVGB((%1, %%REGa), %%mm3) // L3
+ "movq (%0, %2, 4), %%mm4 \n\t" // L4
+ PAVGB((%1, %2, 4), %%mm4) // L4
+ "movq (%0, %%"REG_d"), %%mm5 \n\t" // L5
+ PAVGB((%1, %%REGd), %%mm5) // L5
+ "movq (%0, %%"REG_a", 2), %%mm6 \n\t" // L6
+ PAVGB((%1, %%REGa, 2), %%mm6) // L6
+ "movq (%0, %%"REG_c"), %%mm7 \n\t" // L7
+ PAVGB((%1, %%REGc), %%mm7) // L7
+ "movq %%mm0, (%1) \n\t" // R0
+ "movq %%mm1, (%1, %2) \n\t" // R1
+ "movq %%mm2, (%1, %2, 2) \n\t" // R2
+ "movq %%mm3, (%1, %%"REG_a") \n\t" // R3
+ "movq %%mm4, (%1, %2, 4) \n\t" // R4
+ "movq %%mm5, (%1, %%"REG_d") \n\t" // R5
+ "movq %%mm6, (%1, %%"REG_a", 2) \n\t" // R6
+ "movq %%mm7, (%1, %%"REG_c") \n\t" // R7
+ "movq %%mm0, (%0) \n\t" // L0
+ "movq %%mm1, (%0, %2) \n\t" // L1
+ "movq %%mm2, (%0, %2, 2) \n\t" // L2
+ "movq %%mm3, (%0, %%"REG_a") \n\t" // L3
+ "movq %%mm4, (%0, %2, 4) \n\t" // L4
+ "movq %%mm5, (%0, %%"REG_d") \n\t" // L5
+ "movq %%mm6, (%0, %%"REG_a", 2) \n\t" // L6
+ "movq %%mm7, (%0, %%"REG_c") \n\t" // L7
+ "jmp 4f \n\t"
+
+ "2: \n\t"
+ "cmpl 508(%%"REG_d"), %%ecx \n\t"
+ " jb 3f \n\t"
+
+ "lea (%%"REG_a", %2, 2), %%"REG_d" \n\t" // 5*stride
+ "lea (%%"REG_d", %2, 2), %%"REG_c" \n\t" // 7*stride
+ "movq (%0), %%mm0 \n\t" // L0
+ "movq (%0, %2), %%mm1 \n\t" // L1
+ "movq (%0, %2, 2), %%mm2 \n\t" // L2
+ "movq (%0, %%"REG_a"), %%mm3 \n\t" // L3
+ "movq (%1), %%mm4 \n\t" // R0
+ "movq (%1, %2), %%mm5 \n\t" // R1
+ "movq (%1, %2, 2), %%mm6 \n\t" // R2
+ "movq (%1, %%"REG_a"), %%mm7 \n\t" // R3
+ PAVGB(%%mm4, %%mm0)
+ PAVGB(%%mm5, %%mm1)
+ PAVGB(%%mm6, %%mm2)
+ PAVGB(%%mm7, %%mm3)
+ PAVGB(%%mm4, %%mm0)
+ PAVGB(%%mm5, %%mm1)
+ PAVGB(%%mm6, %%mm2)
+ PAVGB(%%mm7, %%mm3)
+ "movq %%mm0, (%1) \n\t" // R0
+ "movq %%mm1, (%1, %2) \n\t" // R1
+ "movq %%mm2, (%1, %2, 2) \n\t" // R2
+ "movq %%mm3, (%1, %%"REG_a") \n\t" // R3
+ "movq %%mm0, (%0) \n\t" // L0
+ "movq %%mm1, (%0, %2) \n\t" // L1
+ "movq %%mm2, (%0, %2, 2) \n\t" // L2
+ "movq %%mm3, (%0, %%"REG_a") \n\t" // L3
+
+ "movq (%0, %2, 4), %%mm0 \n\t" // L4
+ "movq (%0, %%"REG_d"), %%mm1 \n\t" // L5
+ "movq (%0, %%"REG_a", 2), %%mm2 \n\t" // L6
+ "movq (%0, %%"REG_c"), %%mm3 \n\t" // L7
+ "movq (%1, %2, 4), %%mm4 \n\t" // R4
+ "movq (%1, %%"REG_d"), %%mm5 \n\t" // R5
+ "movq (%1, %%"REG_a", 2), %%mm6 \n\t" // R6
+ "movq (%1, %%"REG_c"), %%mm7 \n\t" // R7
+ PAVGB(%%mm4, %%mm0)
+ PAVGB(%%mm5, %%mm1)
+ PAVGB(%%mm6, %%mm2)
+ PAVGB(%%mm7, %%mm3)
+ PAVGB(%%mm4, %%mm0)
+ PAVGB(%%mm5, %%mm1)
+ PAVGB(%%mm6, %%mm2)
+ PAVGB(%%mm7, %%mm3)
+ "movq %%mm0, (%1, %2, 4) \n\t" // R4
+ "movq %%mm1, (%1, %%"REG_d") \n\t" // R5
+ "movq %%mm2, (%1, %%"REG_a", 2) \n\t" // R6
+ "movq %%mm3, (%1, %%"REG_c") \n\t" // R7
+ "movq %%mm0, (%0, %2, 4) \n\t" // L4
+ "movq %%mm1, (%0, %%"REG_d") \n\t" // L5
+ "movq %%mm2, (%0, %%"REG_a", 2) \n\t" // L6
+ "movq %%mm3, (%0, %%"REG_c") \n\t" // L7
+ "jmp 4f \n\t"
+
+ "3: \n\t"
+ "lea (%%"REG_a", %2, 2), %%"REG_d" \n\t" // 5*stride
+ "lea (%%"REG_d", %2, 2), %%"REG_c" \n\t" // 7*stride
+ "movq (%0), %%mm0 \n\t" // L0
+ "movq (%0, %2), %%mm1 \n\t" // L1
+ "movq (%0, %2, 2), %%mm2 \n\t" // L2
+ "movq (%0, %%"REG_a"), %%mm3 \n\t" // L3
+ "movq (%1), %%mm4 \n\t" // R0
+ "movq (%1, %2), %%mm5 \n\t" // R1
+ "movq (%1, %2, 2), %%mm6 \n\t" // R2
+ "movq (%1, %%"REG_a"), %%mm7 \n\t" // R3
+ PAVGB(%%mm4, %%mm0)
+ PAVGB(%%mm5, %%mm1)
+ PAVGB(%%mm6, %%mm2)
+ PAVGB(%%mm7, %%mm3)
+ PAVGB(%%mm4, %%mm0)
+ PAVGB(%%mm5, %%mm1)
+ PAVGB(%%mm6, %%mm2)
+ PAVGB(%%mm7, %%mm3)
+ PAVGB(%%mm4, %%mm0)
+ PAVGB(%%mm5, %%mm1)
+ PAVGB(%%mm6, %%mm2)
+ PAVGB(%%mm7, %%mm3)
+ "movq %%mm0, (%1) \n\t" // R0
+ "movq %%mm1, (%1, %2) \n\t" // R1
+ "movq %%mm2, (%1, %2, 2) \n\t" // R2
+ "movq %%mm3, (%1, %%"REG_a") \n\t" // R3
+ "movq %%mm0, (%0) \n\t" // L0
+ "movq %%mm1, (%0, %2) \n\t" // L1
+ "movq %%mm2, (%0, %2, 2) \n\t" // L2
+ "movq %%mm3, (%0, %%"REG_a") \n\t" // L3
+
+ "movq (%0, %2, 4), %%mm0 \n\t" // L4
+ "movq (%0, %%"REG_d"), %%mm1 \n\t" // L5
+ "movq (%0, %%"REG_a", 2), %%mm2 \n\t" // L6
+ "movq (%0, %%"REG_c"), %%mm3 \n\t" // L7
+ "movq (%1, %2, 4), %%mm4 \n\t" // R4
+ "movq (%1, %%"REG_d"), %%mm5 \n\t" // R5
+ "movq (%1, %%"REG_a", 2), %%mm6 \n\t" // R6
+ "movq (%1, %%"REG_c"), %%mm7 \n\t" // R7
+ PAVGB(%%mm4, %%mm0)
+ PAVGB(%%mm5, %%mm1)
+ PAVGB(%%mm6, %%mm2)
+ PAVGB(%%mm7, %%mm3)
+ PAVGB(%%mm4, %%mm0)
+ PAVGB(%%mm5, %%mm1)
+ PAVGB(%%mm6, %%mm2)
+ PAVGB(%%mm7, %%mm3)
+ PAVGB(%%mm4, %%mm0)
+ PAVGB(%%mm5, %%mm1)
+ PAVGB(%%mm6, %%mm2)
+ PAVGB(%%mm7, %%mm3)
+ "movq %%mm0, (%1, %2, 4) \n\t" // R4
+ "movq %%mm1, (%1, %%"REG_d") \n\t" // R5
+ "movq %%mm2, (%1, %%"REG_a", 2) \n\t" // R6
+ "movq %%mm3, (%1, %%"REG_c") \n\t" // R7
+ "movq %%mm0, (%0, %2, 4) \n\t" // L4
+ "movq %%mm1, (%0, %%"REG_d") \n\t" // L5
+ "movq %%mm2, (%0, %%"REG_a", 2) \n\t" // L6
+ "movq %%mm3, (%0, %%"REG_c") \n\t" // L7
+
+ "4: \n\t"
+
+ :: "r" (src), "r" (tempBlured), "r"((long)stride), "m" (tempBluredPast)
+ : "%"REG_a, "%"REG_d, "%"REG_c, "memory"
+ );
+#else //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+{
+ int y;
+ int d=0;
+// int sysd=0;
+ int i;
+
+ for(y=0; y<8; y++)
+ {
+ int x;
+ for(x=0; x<8; x++)
+ {
+ int ref= tempBlured[ x + y*stride ];
+ int cur= src[ x + y*stride ];
+ int d1=ref - cur;
+// if(x==0 || x==7) d1+= d1>>1;
+// if(y==0 || y==7) d1+= d1>>1;
+// d+= FFABS(d1);
+ d+= d1*d1;
+// sysd+= d1;
+ }
+ }
+ i=d;
+ d= (
+ 4*d
+ +(*(tempBluredPast-256))
+ +(*(tempBluredPast-1))+ (*(tempBluredPast+1))
+ +(*(tempBluredPast+256))
+ +4)>>3;
+ *tempBluredPast=i;
+// ((*tempBluredPast)*3 + d + 2)>>2;
+
+/*
+Switch between
+ 1 0 0 0 0 0 0 (0)
+64 32 16 8 4 2 1 (1)
+64 48 36 27 20 15 11 (33) (approx)
+64 56 49 43 37 33 29 (200) (approx)
+*/
+ if(d > maxNoise[1])
+ {
+ if(d < maxNoise[2])
+ {
+ for(y=0; y<8; y++)
+ {
+ int x;
+ for(x=0; x<8; x++)
+ {
+ int ref= tempBlured[ x + y*stride ];
+ int cur= src[ x + y*stride ];
+ tempBlured[ x + y*stride ]=
+ src[ x + y*stride ]=
+ (ref + cur + 1)>>1;
+ }
+ }
+ }
+ else
+ {
+ for(y=0; y<8; y++)
+ {
+ int x;
+ for(x=0; x<8; x++)
+ {
+ tempBlured[ x + y*stride ]= src[ x + y*stride ];
+ }
+ }
+ }
+ }
+ else
+ {
+ if(d < maxNoise[0])
+ {
+ for(y=0; y<8; y++)
+ {
+ int x;
+ for(x=0; x<8; x++)
+ {
+ int ref= tempBlured[ x + y*stride ];
+ int cur= src[ x + y*stride ];
+ tempBlured[ x + y*stride ]=
+ src[ x + y*stride ]=
+ (ref*7 + cur + 4)>>3;
+ }
+ }
+ }
+ else
+ {
+ for(y=0; y<8; y++)
+ {
+ int x;
+ for(x=0; x<8; x++)
+ {
+ int ref= tempBlured[ x + y*stride ];
+ int cur= src[ x + y*stride ];
+ tempBlured[ x + y*stride ]=
+ src[ x + y*stride ]=
+ (ref*3 + cur + 2)>>2;
+ }
+ }
+ }
+ }
+}
+#endif //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+}
+#endif //HAVE_ALTIVEC
+
+#ifdef HAVE_MMX
+/**
+ * accurate deblock filter
+ */
+static av_always_inline void RENAME(do_a_deblock)(uint8_t *src, int step, int stride, PPContext *c){
+ int64_t dc_mask, eq_mask, both_masks;
+ int64_t sums[10*8*2];
+ src+= step*3; // src points to begin of the 8x8 Block
+//START_TIMER
+asm volatile(
+ "movq %0, %%mm7 \n\t"
+ "movq %1, %%mm6 \n\t"
+ : : "m" (c->mmxDcOffset[c->nonBQP]), "m" (c->mmxDcThreshold[c->nonBQP])
+ );
+
+asm volatile(
+ "lea (%2, %3), %%"REG_a" \n\t"
+// 0 1 2 3 4 5 6 7 8 9
+// %1 eax eax+%2 eax+2%2 %1+4%2 ecx ecx+%2 ecx+2%2 %1+8%2 ecx+4%2
+
+ "movq (%2), %%mm0 \n\t"
+ "movq (%%"REG_a"), %%mm1 \n\t"
+ "movq %%mm1, %%mm3 \n\t"
+ "movq %%mm1, %%mm4 \n\t"
+ "psubb %%mm1, %%mm0 \n\t" // mm0 = differnece
+ "paddb %%mm7, %%mm0 \n\t"
+ "pcmpgtb %%mm6, %%mm0 \n\t"
+
+ "movq (%%"REG_a",%3), %%mm2 \n\t"
+ PMAXUB(%%mm2, %%mm4)
+ PMINUB(%%mm2, %%mm3, %%mm5)
+ "psubb %%mm2, %%mm1 \n\t"
+ "paddb %%mm7, %%mm1 \n\t"
+ "pcmpgtb %%mm6, %%mm1 \n\t"
+ "paddb %%mm1, %%mm0 \n\t"
+
+ "movq (%%"REG_a", %3, 2), %%mm1 \n\t"
+ PMAXUB(%%mm1, %%mm4)
+ PMINUB(%%mm1, %%mm3, %%mm5)
+ "psubb %%mm1, %%mm2 \n\t"
+ "paddb %%mm7, %%mm2 \n\t"
+ "pcmpgtb %%mm6, %%mm2 \n\t"
+ "paddb %%mm2, %%mm0 \n\t"
+
+ "lea (%%"REG_a", %3, 4), %%"REG_a" \n\t"
+
+ "movq (%2, %3, 4), %%mm2 \n\t"
+ PMAXUB(%%mm2, %%mm4)
+ PMINUB(%%mm2, %%mm3, %%mm5)
+ "psubb %%mm2, %%mm1 \n\t"
+ "paddb %%mm7, %%mm1 \n\t"
+ "pcmpgtb %%mm6, %%mm1 \n\t"
+ "paddb %%mm1, %%mm0 \n\t"
+
+ "movq (%%"REG_a"), %%mm1 \n\t"
+ PMAXUB(%%mm1, %%mm4)
+ PMINUB(%%mm1, %%mm3, %%mm5)
+ "psubb %%mm1, %%mm2 \n\t"
+ "paddb %%mm7, %%mm2 \n\t"
+ "pcmpgtb %%mm6, %%mm2 \n\t"
+ "paddb %%mm2, %%mm0 \n\t"
+
+ "movq (%%"REG_a", %3), %%mm2 \n\t"
+ PMAXUB(%%mm2, %%mm4)
+ PMINUB(%%mm2, %%mm3, %%mm5)
+ "psubb %%mm2, %%mm1 \n\t"
+ "paddb %%mm7, %%mm1 \n\t"
+ "pcmpgtb %%mm6, %%mm1 \n\t"
+ "paddb %%mm1, %%mm0 \n\t"
+
+ "movq (%%"REG_a", %3, 2), %%mm1 \n\t"
+ PMAXUB(%%mm1, %%mm4)
+ PMINUB(%%mm1, %%mm3, %%mm5)
+ "psubb %%mm1, %%mm2 \n\t"
+ "paddb %%mm7, %%mm2 \n\t"
+ "pcmpgtb %%mm6, %%mm2 \n\t"
+ "paddb %%mm2, %%mm0 \n\t"
+
+ "movq (%2, %3, 8), %%mm2 \n\t"
+ PMAXUB(%%mm2, %%mm4)
+ PMINUB(%%mm2, %%mm3, %%mm5)
+ "psubb %%mm2, %%mm1 \n\t"
+ "paddb %%mm7, %%mm1 \n\t"
+ "pcmpgtb %%mm6, %%mm1 \n\t"
+ "paddb %%mm1, %%mm0 \n\t"
+
+ "movq (%%"REG_a", %3, 4), %%mm1 \n\t"
+ "psubb %%mm1, %%mm2 \n\t"
+ "paddb %%mm7, %%mm2 \n\t"
+ "pcmpgtb %%mm6, %%mm2 \n\t"
+ "paddb %%mm2, %%mm0 \n\t"
+ "psubusb %%mm3, %%mm4 \n\t"
+
+ "pxor %%mm6, %%mm6 \n\t"
+ "movq %4, %%mm7 \n\t" // QP,..., QP
+ "paddusb %%mm7, %%mm7 \n\t" // 2QP ... 2QP
+ "psubusb %%mm4, %%mm7 \n\t" // Diff >=2QP -> 0
+ "pcmpeqb %%mm6, %%mm7 \n\t" // Diff < 2QP -> 0
+ "pcmpeqb %%mm6, %%mm7 \n\t" // Diff < 2QP -> 0
+ "movq %%mm7, %1 \n\t"
+
+ "movq %5, %%mm7 \n\t"
+ "punpcklbw %%mm7, %%mm7 \n\t"
+ "punpcklbw %%mm7, %%mm7 \n\t"
+ "punpcklbw %%mm7, %%mm7 \n\t"
+ "psubb %%mm0, %%mm6 \n\t"
+ "pcmpgtb %%mm7, %%mm6 \n\t"
+ "movq %%mm6, %0 \n\t"
+
+ : "=m" (eq_mask), "=m" (dc_mask)
+ : "r" (src), "r" ((long)step), "m" (c->pQPb), "m"(c->ppMode.flatnessThreshold)
+ : "%"REG_a
+ );
+
+ both_masks = dc_mask & eq_mask;
+
+ if(both_masks){
+ long offset= -8*step;
+ int64_t *temp_sums= sums;
+
+ asm volatile(
+ "movq %2, %%mm0 \n\t" // QP,..., QP
+ "pxor %%mm4, %%mm4 \n\t"
+
+ "movq (%0), %%mm6 \n\t"
+ "movq (%0, %1), %%mm5 \n\t"
+ "movq %%mm5, %%mm1 \n\t"
+ "movq %%mm6, %%mm2 \n\t"
+ "psubusb %%mm6, %%mm5 \n\t"
+ "psubusb %%mm1, %%mm2 \n\t"
+ "por %%mm5, %%mm2 \n\t" // ABS Diff of lines
+ "psubusb %%mm2, %%mm0 \n\t" // diff >= QP -> 0
+ "pcmpeqb %%mm4, %%mm0 \n\t" // diff >= QP -> FF
+
+ "pxor %%mm6, %%mm1 \n\t"
+ "pand %%mm0, %%mm1 \n\t"
+ "pxor %%mm1, %%mm6 \n\t"
+ // 0:QP 6:First
+
+ "movq (%0, %1, 8), %%mm5 \n\t"
+ "add %1, %0 \n\t" // %0 points to line 1 not 0
+ "movq (%0, %1, 8), %%mm7 \n\t"
+ "movq %%mm5, %%mm1 \n\t"
+ "movq %%mm7, %%mm2 \n\t"
+ "psubusb %%mm7, %%mm5 \n\t"
+ "psubusb %%mm1, %%mm2 \n\t"
+ "por %%mm5, %%mm2 \n\t" // ABS Diff of lines
+ "movq %2, %%mm0 \n\t" // QP,..., QP
+ "psubusb %%mm2, %%mm0 \n\t" // diff >= QP -> 0
+ "pcmpeqb %%mm4, %%mm0 \n\t" // diff >= QP -> FF
+
+ "pxor %%mm7, %%mm1 \n\t"
+ "pand %%mm0, %%mm1 \n\t"
+ "pxor %%mm1, %%mm7 \n\t"
+
+ "movq %%mm6, %%mm5 \n\t"
+ "punpckhbw %%mm4, %%mm6 \n\t"
+ "punpcklbw %%mm4, %%mm5 \n\t"
+ // 4:0 5/6:First 7:Last
+
+ "movq %%mm5, %%mm0 \n\t"
+ "movq %%mm6, %%mm1 \n\t"
+ "psllw $2, %%mm0 \n\t"
+ "psllw $2, %%mm1 \n\t"
+ "paddw "MANGLE(w04)", %%mm0 \n\t"
+ "paddw "MANGLE(w04)", %%mm1 \n\t"
+
+#define NEXT\
+ "movq (%0), %%mm2 \n\t"\
+ "movq (%0), %%mm3 \n\t"\
+ "add %1, %0 \n\t"\
+ "punpcklbw %%mm4, %%mm2 \n\t"\
+ "punpckhbw %%mm4, %%mm3 \n\t"\
+ "paddw %%mm2, %%mm0 \n\t"\
+ "paddw %%mm3, %%mm1 \n\t"
+
+#define PREV\
+ "movq (%0), %%mm2 \n\t"\
+ "movq (%0), %%mm3 \n\t"\
+ "add %1, %0 \n\t"\
+ "punpcklbw %%mm4, %%mm2 \n\t"\
+ "punpckhbw %%mm4, %%mm3 \n\t"\
+ "psubw %%mm2, %%mm0 \n\t"\
+ "psubw %%mm3, %%mm1 \n\t"
+
+
+ NEXT //0
+ NEXT //1
+ NEXT //2
+ "movq %%mm0, (%3) \n\t"
+ "movq %%mm1, 8(%3) \n\t"
+
+ NEXT //3
+ "psubw %%mm5, %%mm0 \n\t"
+ "psubw %%mm6, %%mm1 \n\t"
+ "movq %%mm0, 16(%3) \n\t"
+ "movq %%mm1, 24(%3) \n\t"
+
+ NEXT //4
+ "psubw %%mm5, %%mm0 \n\t"
+ "psubw %%mm6, %%mm1 \n\t"
+ "movq %%mm0, 32(%3) \n\t"
+ "movq %%mm1, 40(%3) \n\t"
+
+ NEXT //5
+ "psubw %%mm5, %%mm0 \n\t"
+ "psubw %%mm6, %%mm1 \n\t"
+ "movq %%mm0, 48(%3) \n\t"
+ "movq %%mm1, 56(%3) \n\t"
+
+ NEXT //6
+ "psubw %%mm5, %%mm0 \n\t"
+ "psubw %%mm6, %%mm1 \n\t"
+ "movq %%mm0, 64(%3) \n\t"
+ "movq %%mm1, 72(%3) \n\t"
+
+ "movq %%mm7, %%mm6 \n\t"
+ "punpckhbw %%mm4, %%mm7 \n\t"
+ "punpcklbw %%mm4, %%mm6 \n\t"
+
+ NEXT //7
+ "mov %4, %0 \n\t"
+ "add %1, %0 \n\t"
+ PREV //0
+ "movq %%mm0, 80(%3) \n\t"
+ "movq %%mm1, 88(%3) \n\t"
+
+ PREV //1
+ "paddw %%mm6, %%mm0 \n\t"
+ "paddw %%mm7, %%mm1 \n\t"
+ "movq %%mm0, 96(%3) \n\t"
+ "movq %%mm1, 104(%3) \n\t"
+
+ PREV //2
+ "paddw %%mm6, %%mm0 \n\t"
+ "paddw %%mm7, %%mm1 \n\t"
+ "movq %%mm0, 112(%3) \n\t"
+ "movq %%mm1, 120(%3) \n\t"
+
+ PREV //3
+ "paddw %%mm6, %%mm0 \n\t"
+ "paddw %%mm7, %%mm1 \n\t"
+ "movq %%mm0, 128(%3) \n\t"
+ "movq %%mm1, 136(%3) \n\t"
+
+ PREV //4
+ "paddw %%mm6, %%mm0 \n\t"
+ "paddw %%mm7, %%mm1 \n\t"
+ "movq %%mm0, 144(%3) \n\t"
+ "movq %%mm1, 152(%3) \n\t"
+
+ "mov %4, %0 \n\t" //FIXME
+
+ : "+&r"(src)
+ : "r" ((long)step), "m" (c->pQPb), "r"(sums), "g"(src)
+ );
+
+ src+= step; // src points to begin of the 8x8 Block
+
+ asm volatile(
+ "movq %4, %%mm6 \n\t"
+ "pcmpeqb %%mm5, %%mm5 \n\t"
+ "pxor %%mm6, %%mm5 \n\t"
+ "pxor %%mm7, %%mm7 \n\t"
+
+ "1: \n\t"
+ "movq (%1), %%mm0 \n\t"
+ "movq 8(%1), %%mm1 \n\t"
+ "paddw 32(%1), %%mm0 \n\t"
+ "paddw 40(%1), %%mm1 \n\t"
+ "movq (%0, %3), %%mm2 \n\t"
+ "movq %%mm2, %%mm3 \n\t"
+ "movq %%mm2, %%mm4 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t"
+ "punpckhbw %%mm7, %%mm3 \n\t"
+ "paddw %%mm2, %%mm0 \n\t"
+ "paddw %%mm3, %%mm1 \n\t"
+ "paddw %%mm2, %%mm0 \n\t"
+ "paddw %%mm3, %%mm1 \n\t"
+ "psrlw $4, %%mm0 \n\t"
+ "psrlw $4, %%mm1 \n\t"
+ "packuswb %%mm1, %%mm0 \n\t"
+ "pand %%mm6, %%mm0 \n\t"
+ "pand %%mm5, %%mm4 \n\t"
+ "por %%mm4, %%mm0 \n\t"
+ "movq %%mm0, (%0, %3) \n\t"
+ "add $16, %1 \n\t"
+ "add %2, %0 \n\t"
+ " js 1b \n\t"
+
+ : "+r"(offset), "+r"(temp_sums)
+ : "r" ((long)step), "r"(src - offset), "m"(both_masks)
+ );
+ }else
+ src+= step; // src points to begin of the 8x8 Block
+
+ if(eq_mask != -1LL){
+ uint8_t *temp_src= src;
+ asm volatile(
+ "pxor %%mm7, %%mm7 \n\t"
+ "lea -40(%%"REG_SP"), %%"REG_c" \n\t" // make space for 4 8-byte vars
+ "and "ALIGN_MASK", %%"REG_c" \n\t" // align
+// 0 1 2 3 4 5 6 7 8 9
+// %0 eax eax+%1 eax+2%1 %0+4%1 ecx ecx+%1 ecx+2%1 %1+8%1 ecx+4%1
+
+ "movq (%0), %%mm0 \n\t"
+ "movq %%mm0, %%mm1 \n\t"
+ "punpcklbw %%mm7, %%mm0 \n\t" // low part of line 0
+ "punpckhbw %%mm7, %%mm1 \n\t" // high part of line 0
+
+ "movq (%0, %1), %%mm2 \n\t"
+ "lea (%0, %1, 2), %%"REG_a" \n\t"
+ "movq %%mm2, %%mm3 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t" // low part of line 1
+ "punpckhbw %%mm7, %%mm3 \n\t" // high part of line 1
+
+ "movq (%%"REG_a"), %%mm4 \n\t"
+ "movq %%mm4, %%mm5 \n\t"
+ "punpcklbw %%mm7, %%mm4 \n\t" // low part of line 2
+ "punpckhbw %%mm7, %%mm5 \n\t" // high part of line 2
+
+ "paddw %%mm0, %%mm0 \n\t" // 2L0
+ "paddw %%mm1, %%mm1 \n\t" // 2H0
+ "psubw %%mm4, %%mm2 \n\t" // L1 - L2
+ "psubw %%mm5, %%mm3 \n\t" // H1 - H2
+ "psubw %%mm2, %%mm0 \n\t" // 2L0 - L1 + L2
+ "psubw %%mm3, %%mm1 \n\t" // 2H0 - H1 + H2
+
+ "psllw $2, %%mm2 \n\t" // 4L1 - 4L2
+ "psllw $2, %%mm3 \n\t" // 4H1 - 4H2
+ "psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2
+ "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2
+
+ "movq (%%"REG_a", %1), %%mm2 \n\t"
+ "movq %%mm2, %%mm3 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t" // L3
+ "punpckhbw %%mm7, %%mm3 \n\t" // H3
+
+ "psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2 - L3
+ "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2 - H3
+ "psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2 - 2L3
+ "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2 - 2H3
+ "movq %%mm0, (%%"REG_c") \n\t" // 2L0 - 5L1 + 5L2 - 2L3
+ "movq %%mm1, 8(%%"REG_c") \n\t" // 2H0 - 5H1 + 5H2 - 2H3
+
+ "movq (%%"REG_a", %1, 2), %%mm0 \n\t"
+ "movq %%mm0, %%mm1 \n\t"
+ "punpcklbw %%mm7, %%mm0 \n\t" // L4
+ "punpckhbw %%mm7, %%mm1 \n\t" // H4
+
+ "psubw %%mm0, %%mm2 \n\t" // L3 - L4
+ "psubw %%mm1, %%mm3 \n\t" // H3 - H4
+ "movq %%mm2, 16(%%"REG_c") \n\t" // L3 - L4
+ "movq %%mm3, 24(%%"REG_c") \n\t" // H3 - H4
+ "paddw %%mm4, %%mm4 \n\t" // 2L2
+ "paddw %%mm5, %%mm5 \n\t" // 2H2
+ "psubw %%mm2, %%mm4 \n\t" // 2L2 - L3 + L4
+ "psubw %%mm3, %%mm5 \n\t" // 2H2 - H3 + H4
+
+ "lea (%%"REG_a", %1), %0 \n\t"
+ "psllw $2, %%mm2 \n\t" // 4L3 - 4L4
+ "psllw $2, %%mm3 \n\t" // 4H3 - 4H4
+ "psubw %%mm2, %%mm4 \n\t" // 2L2 - 5L3 + 5L4
+ "psubw %%mm3, %%mm5 \n\t" // 2H2 - 5H3 + 5H4
+//50 opcodes so far
+ "movq (%0, %1, 2), %%mm2 \n\t"
+ "movq %%mm2, %%mm3 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t" // L5
+ "punpckhbw %%mm7, %%mm3 \n\t" // H5
+ "psubw %%mm2, %%mm4 \n\t" // 2L2 - 5L3 + 5L4 - L5
+ "psubw %%mm3, %%mm5 \n\t" // 2H2 - 5H3 + 5H4 - H5
+ "psubw %%mm2, %%mm4 \n\t" // 2L2 - 5L3 + 5L4 - 2L5
+ "psubw %%mm3, %%mm5 \n\t" // 2H2 - 5H3 + 5H4 - 2H5
+
+ "movq (%%"REG_a", %1, 4), %%mm6 \n\t"
+ "punpcklbw %%mm7, %%mm6 \n\t" // L6
+ "psubw %%mm6, %%mm2 \n\t" // L5 - L6
+ "movq (%%"REG_a", %1, 4), %%mm6 \n\t"
+ "punpckhbw %%mm7, %%mm6 \n\t" // H6
+ "psubw %%mm6, %%mm3 \n\t" // H5 - H6
+
+ "paddw %%mm0, %%mm0 \n\t" // 2L4
+ "paddw %%mm1, %%mm1 \n\t" // 2H4
+ "psubw %%mm2, %%mm0 \n\t" // 2L4 - L5 + L6
+ "psubw %%mm3, %%mm1 \n\t" // 2H4 - H5 + H6
+
+ "psllw $2, %%mm2 \n\t" // 4L5 - 4L6
+ "psllw $2, %%mm3 \n\t" // 4H5 - 4H6
+ "psubw %%mm2, %%mm0 \n\t" // 2L4 - 5L5 + 5L6
+ "psubw %%mm3, %%mm1 \n\t" // 2H4 - 5H5 + 5H6
+
+ "movq (%0, %1, 4), %%mm2 \n\t"
+ "movq %%mm2, %%mm3 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t" // L7
+ "punpckhbw %%mm7, %%mm3 \n\t" // H7
+
+ "paddw %%mm2, %%mm2 \n\t" // 2L7
+ "paddw %%mm3, %%mm3 \n\t" // 2H7
+ "psubw %%mm2, %%mm0 \n\t" // 2L4 - 5L5 + 5L6 - 2L7
+ "psubw %%mm3, %%mm1 \n\t" // 2H4 - 5H5 + 5H6 - 2H7
+
+ "movq (%%"REG_c"), %%mm2 \n\t" // 2L0 - 5L1 + 5L2 - 2L3
+ "movq 8(%%"REG_c"), %%mm3 \n\t" // 2H0 - 5H1 + 5H2 - 2H3
+
+#ifdef HAVE_MMX2
+ "movq %%mm7, %%mm6 \n\t" // 0
+ "psubw %%mm0, %%mm6 \n\t"
+ "pmaxsw %%mm6, %%mm0 \n\t" // |2L4 - 5L5 + 5L6 - 2L7|
+ "movq %%mm7, %%mm6 \n\t" // 0
+ "psubw %%mm1, %%mm6 \n\t"
+ "pmaxsw %%mm6, %%mm1 \n\t" // |2H4 - 5H5 + 5H6 - 2H7|
+ "movq %%mm7, %%mm6 \n\t" // 0
+ "psubw %%mm2, %%mm6 \n\t"
+ "pmaxsw %%mm6, %%mm2 \n\t" // |2L0 - 5L1 + 5L2 - 2L3|
+ "movq %%mm7, %%mm6 \n\t" // 0
+ "psubw %%mm3, %%mm6 \n\t"
+ "pmaxsw %%mm6, %%mm3 \n\t" // |2H0 - 5H1 + 5H2 - 2H3|
+#else
+ "movq %%mm7, %%mm6 \n\t" // 0
+ "pcmpgtw %%mm0, %%mm6 \n\t"
+ "pxor %%mm6, %%mm0 \n\t"
+ "psubw %%mm6, %%mm0 \n\t" // |2L4 - 5L5 + 5L6 - 2L7|
+ "movq %%mm7, %%mm6 \n\t" // 0
+ "pcmpgtw %%mm1, %%mm6 \n\t"
+ "pxor %%mm6, %%mm1 \n\t"
+ "psubw %%mm6, %%mm1 \n\t" // |2H4 - 5H5 + 5H6 - 2H7|
+ "movq %%mm7, %%mm6 \n\t" // 0
+ "pcmpgtw %%mm2, %%mm6 \n\t"
+ "pxor %%mm6, %%mm2 \n\t"
+ "psubw %%mm6, %%mm2 \n\t" // |2L0 - 5L1 + 5L2 - 2L3|
+ "movq %%mm7, %%mm6 \n\t" // 0
+ "pcmpgtw %%mm3, %%mm6 \n\t"
+ "pxor %%mm6, %%mm3 \n\t"
+ "psubw %%mm6, %%mm3 \n\t" // |2H0 - 5H1 + 5H2 - 2H3|
+#endif
+
+#ifdef HAVE_MMX2
+ "pminsw %%mm2, %%mm0 \n\t"
+ "pminsw %%mm3, %%mm1 \n\t"
+#else
+ "movq %%mm0, %%mm6 \n\t"
+ "psubusw %%mm2, %%mm6 \n\t"
+ "psubw %%mm6, %%mm0 \n\t"
+ "movq %%mm1, %%mm6 \n\t"
+ "psubusw %%mm3, %%mm6 \n\t"
+ "psubw %%mm6, %%mm1 \n\t"
+#endif
+
+ "movd %2, %%mm2 \n\t" // QP
+ "punpcklbw %%mm7, %%mm2 \n\t"
+
+ "movq %%mm7, %%mm6 \n\t" // 0
+ "pcmpgtw %%mm4, %%mm6 \n\t" // sign(2L2 - 5L3 + 5L4 - 2L5)
+ "pxor %%mm6, %%mm4 \n\t"
+ "psubw %%mm6, %%mm4 \n\t" // |2L2 - 5L3 + 5L4 - 2L5|
+ "pcmpgtw %%mm5, %%mm7 \n\t" // sign(2H2 - 5H3 + 5H4 - 2H5)
+ "pxor %%mm7, %%mm5 \n\t"
+ "psubw %%mm7, %%mm5 \n\t" // |2H2 - 5H3 + 5H4 - 2H5|
+// 100 opcodes
+ "psllw $3, %%mm2 \n\t" // 8QP
+ "movq %%mm2, %%mm3 \n\t" // 8QP
+ "pcmpgtw %%mm4, %%mm2 \n\t"
+ "pcmpgtw %%mm5, %%mm3 \n\t"
+ "pand %%mm2, %%mm4 \n\t"
+ "pand %%mm3, %%mm5 \n\t"
+
+
+ "psubusw %%mm0, %%mm4 \n\t" // hd
+ "psubusw %%mm1, %%mm5 \n\t" // ld
+
+
+ "movq "MANGLE(w05)", %%mm2 \n\t" // 5
+ "pmullw %%mm2, %%mm4 \n\t"
+ "pmullw %%mm2, %%mm5 \n\t"
+ "movq "MANGLE(w20)", %%mm2 \n\t" // 32
+ "paddw %%mm2, %%mm4 \n\t"
+ "paddw %%mm2, %%mm5 \n\t"
+ "psrlw $6, %%mm4 \n\t"
+ "psrlw $6, %%mm5 \n\t"
+
+ "movq 16(%%"REG_c"), %%mm0 \n\t" // L3 - L4
+ "movq 24(%%"REG_c"), %%mm1 \n\t" // H3 - H4
+
+ "pxor %%mm2, %%mm2 \n\t"
+ "pxor %%mm3, %%mm3 \n\t"
+
+ "pcmpgtw %%mm0, %%mm2 \n\t" // sign (L3-L4)
+ "pcmpgtw %%mm1, %%mm3 \n\t" // sign (H3-H4)
+ "pxor %%mm2, %%mm0 \n\t"
+ "pxor %%mm3, %%mm1 \n\t"
+ "psubw %%mm2, %%mm0 \n\t" // |L3-L4|
+ "psubw %%mm3, %%mm1 \n\t" // |H3-H4|
+ "psrlw $1, %%mm0 \n\t" // |L3 - L4|/2
+ "psrlw $1, %%mm1 \n\t" // |H3 - H4|/2
+
+ "pxor %%mm6, %%mm2 \n\t"
+ "pxor %%mm7, %%mm3 \n\t"
+ "pand %%mm2, %%mm4 \n\t"
+ "pand %%mm3, %%mm5 \n\t"
+
+#ifdef HAVE_MMX2
+ "pminsw %%mm0, %%mm4 \n\t"
+ "pminsw %%mm1, %%mm5 \n\t"
+#else
+ "movq %%mm4, %%mm2 \n\t"
+ "psubusw %%mm0, %%mm2 \n\t"
+ "psubw %%mm2, %%mm4 \n\t"
+ "movq %%mm5, %%mm2 \n\t"
+ "psubusw %%mm1, %%mm2 \n\t"
+ "psubw %%mm2, %%mm5 \n\t"
+#endif
+ "pxor %%mm6, %%mm4 \n\t"
+ "pxor %%mm7, %%mm5 \n\t"
+ "psubw %%mm6, %%mm4 \n\t"
+ "psubw %%mm7, %%mm5 \n\t"
+ "packsswb %%mm5, %%mm4 \n\t"
+ "movq %3, %%mm1 \n\t"
+ "pandn %%mm4, %%mm1 \n\t"
+ "movq (%0), %%mm0 \n\t"
+ "paddb %%mm1, %%mm0 \n\t"
+ "movq %%mm0, (%0) \n\t"
+ "movq (%0, %1), %%mm0 \n\t"
+ "psubb %%mm1, %%mm0 \n\t"
+ "movq %%mm0, (%0, %1) \n\t"
+
+ : "+r" (temp_src)
+ : "r" ((long)step), "m" (c->pQPb), "m"(eq_mask)
+ : "%"REG_a, "%"REG_c
+ );
+ }
+/*if(step==16){
+ STOP_TIMER("step16")
+}else{
+ STOP_TIMER("stepX")
+}*/
+}
+#endif //HAVE_MMX
+
+static void RENAME(postProcess)(uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height,
+ QP_STORE_T QPs[], int QPStride, int isColor, PPContext *c);
+
+/**
+ * Copies a block from src to dst and fixes the blacklevel
+ * levelFix == 0 -> dont touch the brighness & contrast
+ */
+#undef SCALED_CPY
+
+static inline void RENAME(blockCopy)(uint8_t dst[], int dstStride, uint8_t src[], int srcStride,
+ int levelFix, int64_t *packedOffsetAndScale)
+{
+#ifndef HAVE_MMX
+ int i;
+#endif
+ if(levelFix)
+ {
+#ifdef HAVE_MMX
+ asm volatile(
+ "movq (%%"REG_a"), %%mm2 \n\t" // packedYOffset
+ "movq 8(%%"REG_a"), %%mm3 \n\t" // packedYScale
+ "lea (%2,%4), %%"REG_a" \n\t"
+ "lea (%3,%5), %%"REG_d" \n\t"
+ "pxor %%mm4, %%mm4 \n\t"
+#ifdef HAVE_MMX2
+#define REAL_SCALED_CPY(src1, src2, dst1, dst2) \
+ "movq " #src1 ", %%mm0 \n\t"\
+ "movq " #src1 ", %%mm5 \n\t"\
+ "movq " #src2 ", %%mm1 \n\t"\
+ "movq " #src2 ", %%mm6 \n\t"\
+ "punpcklbw %%mm0, %%mm0 \n\t"\
+ "punpckhbw %%mm5, %%mm5 \n\t"\
+ "punpcklbw %%mm1, %%mm1 \n\t"\
+ "punpckhbw %%mm6, %%mm6 \n\t"\
+ "pmulhuw %%mm3, %%mm0 \n\t"\
+ "pmulhuw %%mm3, %%mm5 \n\t"\
+ "pmulhuw %%mm3, %%mm1 \n\t"\
+ "pmulhuw %%mm3, %%mm6 \n\t"\
+ "psubw %%mm2, %%mm0 \n\t"\
+ "psubw %%mm2, %%mm5 \n\t"\
+ "psubw %%mm2, %%mm1 \n\t"\
+ "psubw %%mm2, %%mm6 \n\t"\
+ "packuswb %%mm5, %%mm0 \n\t"\
+ "packuswb %%mm6, %%mm1 \n\t"\
+ "movq %%mm0, " #dst1 " \n\t"\
+ "movq %%mm1, " #dst2 " \n\t"\
+
+#else //HAVE_MMX2
+#define REAL_SCALED_CPY(src1, src2, dst1, dst2) \
+ "movq " #src1 ", %%mm0 \n\t"\
+ "movq " #src1 ", %%mm5 \n\t"\
+ "punpcklbw %%mm4, %%mm0 \n\t"\
+ "punpckhbw %%mm4, %%mm5 \n\t"\
+ "psubw %%mm2, %%mm0 \n\t"\
+ "psubw %%mm2, %%mm5 \n\t"\
+ "movq " #src2 ", %%mm1 \n\t"\
+ "psllw $6, %%mm0 \n\t"\
+ "psllw $6, %%mm5 \n\t"\
+ "pmulhw %%mm3, %%mm0 \n\t"\
+ "movq " #src2 ", %%mm6 \n\t"\
+ "pmulhw %%mm3, %%mm5 \n\t"\
+ "punpcklbw %%mm4, %%mm1 \n\t"\
+ "punpckhbw %%mm4, %%mm6 \n\t"\
+ "psubw %%mm2, %%mm1 \n\t"\
+ "psubw %%mm2, %%mm6 \n\t"\
+ "psllw $6, %%mm1 \n\t"\
+ "psllw $6, %%mm6 \n\t"\
+ "pmulhw %%mm3, %%mm1 \n\t"\
+ "pmulhw %%mm3, %%mm6 \n\t"\
+ "packuswb %%mm5, %%mm0 \n\t"\
+ "packuswb %%mm6, %%mm1 \n\t"\
+ "movq %%mm0, " #dst1 " \n\t"\
+ "movq %%mm1, " #dst2 " \n\t"\
+
+#endif //HAVE_MMX2
+#define SCALED_CPY(src1, src2, dst1, dst2)\
+ REAL_SCALED_CPY(src1, src2, dst1, dst2)
+
+SCALED_CPY((%2) , (%2, %4) , (%3) , (%3, %5))
+SCALED_CPY((%2, %4, 2), (%%REGa, %4, 2), (%3, %5, 2), (%%REGd, %5, 2))
+SCALED_CPY((%2, %4, 4), (%%REGa, %4, 4), (%3, %5, 4), (%%REGd, %5, 4))
+ "lea (%%"REG_a",%4,4), %%"REG_a" \n\t"
+ "lea (%%"REG_d",%5,4), %%"REG_d" \n\t"
+SCALED_CPY((%%REGa, %4), (%%REGa, %4, 2), (%%REGd, %5), (%%REGd, %5, 2))
+
+
+ : "=&a" (packedOffsetAndScale)
+ : "0" (packedOffsetAndScale),
+ "r"(src),
+ "r"(dst),
+ "r" ((long)srcStride),
+ "r" ((long)dstStride)
+ : "%"REG_d
+ );
+#else //HAVE_MMX
+ for(i=0; i<8; i++)
+ memcpy( &(dst[dstStride*i]),
+ &(src[srcStride*i]), BLOCK_SIZE);
+#endif //HAVE_MMX
+ }
+ else
+ {
+#ifdef HAVE_MMX
+ asm volatile(
+ "lea (%0,%2), %%"REG_a" \n\t"
+ "lea (%1,%3), %%"REG_d" \n\t"
+
+#define REAL_SIMPLE_CPY(src1, src2, dst1, dst2) \
+ "movq " #src1 ", %%mm0 \n\t"\
+ "movq " #src2 ", %%mm1 \n\t"\
+ "movq %%mm0, " #dst1 " \n\t"\
+ "movq %%mm1, " #dst2 " \n\t"\
+
+#define SIMPLE_CPY(src1, src2, dst1, dst2)\
+ REAL_SIMPLE_CPY(src1, src2, dst1, dst2)
+
+SIMPLE_CPY((%0) , (%0, %2) , (%1) , (%1, %3))
+SIMPLE_CPY((%0, %2, 2), (%%REGa, %2, 2), (%1, %3, 2), (%%REGd, %3, 2))
+SIMPLE_CPY((%0, %2, 4), (%%REGa, %2, 4), (%1, %3, 4), (%%REGd, %3, 4))
+ "lea (%%"REG_a",%2,4), %%"REG_a" \n\t"
+ "lea (%%"REG_d",%3,4), %%"REG_d" \n\t"
+SIMPLE_CPY((%%REGa, %2), (%%REGa, %2, 2), (%%REGd, %3), (%%REGd, %3, 2))
+
+ : : "r" (src),
+ "r" (dst),
+ "r" ((long)srcStride),
+ "r" ((long)dstStride)
+ : "%"REG_a, "%"REG_d
+ );
+#else //HAVE_MMX
+ for(i=0; i<8; i++)
+ memcpy( &(dst[dstStride*i]),
+ &(src[srcStride*i]), BLOCK_SIZE);
+#endif //HAVE_MMX
+ }
+}
+
+/**
+ * Duplicates the given 8 src pixels ? times upward
+ */
+static inline void RENAME(duplicate)(uint8_t src[], int stride)
+{
+#ifdef HAVE_MMX
+ asm volatile(
+ "movq (%0), %%mm0 \n\t"
+ "add %1, %0 \n\t"
+ "movq %%mm0, (%0) \n\t"
+ "movq %%mm0, (%0, %1) \n\t"
+ "movq %%mm0, (%0, %1, 2) \n\t"
+ : "+r" (src)
+ : "r" ((long)-stride)
+ );
+#else
+ int i;
+ uint8_t *p=src;
+ for(i=0; i<3; i++)
+ {
+ p-= stride;
+ memcpy(p, src, 8);
+ }
+#endif
+}
+
+/**
+ * Filters array of bytes (Y or U or V values)
+ */
+static void RENAME(postProcess)(uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height,
+ QP_STORE_T QPs[], int QPStride, int isColor, PPContext *c2)
+{
+ PPContext __attribute__((aligned(8))) c= *c2; //copy to stack for faster access
+ int x,y;
+#ifdef COMPILE_TIME_MODE
+ const int mode= COMPILE_TIME_MODE;
+#else
+ const int mode= isColor ? c.ppMode.chromMode : c.ppMode.lumMode;
+#endif
+ int black=0, white=255; // blackest black and whitest white in the picture
+ int QPCorrecture= 256*256;
+
+ int copyAhead;
+#ifdef HAVE_MMX
+ int i;
+#endif
+
+ const int qpHShift= isColor ? 4-c.hChromaSubSample : 4;
+ const int qpVShift= isColor ? 4-c.vChromaSubSample : 4;
+
+ //FIXME remove
+ uint64_t * const yHistogram= c.yHistogram;
+ uint8_t * const tempSrc= srcStride > 0 ? c.tempSrc : c.tempSrc - 23*srcStride;
+ uint8_t * const tempDst= dstStride > 0 ? c.tempDst : c.tempDst - 23*dstStride;
+ //const int mbWidth= isColor ? (width+7)>>3 : (width+15)>>4;
+
+#ifdef HAVE_MMX
+ for(i=0; i<57; i++){
+ int offset= ((i*c.ppMode.baseDcDiff)>>8) + 1;
+ int threshold= offset*2 + 1;
+ c.mmxDcOffset[i]= 0x7F - offset;
+ c.mmxDcThreshold[i]= 0x7F - threshold;
+ c.mmxDcOffset[i]*= 0x0101010101010101LL;
+ c.mmxDcThreshold[i]*= 0x0101010101010101LL;
+ }
+#endif
+
+ if(mode & CUBIC_IPOL_DEINT_FILTER) copyAhead=16;
+ else if( (mode & LINEAR_BLEND_DEINT_FILTER)
+ || (mode & FFMPEG_DEINT_FILTER)
+ || (mode & LOWPASS5_DEINT_FILTER)) copyAhead=14;
+ else if( (mode & V_DEBLOCK)
+ || (mode & LINEAR_IPOL_DEINT_FILTER)
+ || (mode & MEDIAN_DEINT_FILTER)
+ || (mode & V_A_DEBLOCK)) copyAhead=13;
+ else if(mode & V_X1_FILTER) copyAhead=11;
+// else if(mode & V_RK1_FILTER) copyAhead=10;
+ else if(mode & DERING) copyAhead=9;
+ else copyAhead=8;
+
+ copyAhead-= 8;
+
+ if(!isColor)
+ {
+ uint64_t sum= 0;
+ int i;
+ uint64_t maxClipped;
+ uint64_t clipped;
+ double scale;
+
+ c.frameNum++;
+ // first frame is fscked so we ignore it
+ if(c.frameNum == 1) yHistogram[0]= width*height/64*15/256;
+
+ for(i=0; i<256; i++)
+ {
+ sum+= yHistogram[i];
+ }
+
+ /* we allways get a completly black picture first */
+ maxClipped= (uint64_t)(sum * c.ppMode.maxClippedThreshold);
+
+ clipped= sum;
+ for(black=255; black>0; black--)
+ {
+ if(clipped < maxClipped) break;
+ clipped-= yHistogram[black];
+ }
+
+ clipped= sum;
+ for(white=0; white<256; white++)
+ {
+ if(clipped < maxClipped) break;
+ clipped-= yHistogram[white];
+ }
+
+ scale= (double)(c.ppMode.maxAllowedY - c.ppMode.minAllowedY) / (double)(white-black);
+
+#ifdef HAVE_MMX2
+ c.packedYScale= (uint16_t)(scale*256.0 + 0.5);
+ c.packedYOffset= (((black*c.packedYScale)>>8) - c.ppMode.minAllowedY) & 0xFFFF;
+#else
+ c.packedYScale= (uint16_t)(scale*1024.0 + 0.5);
+ c.packedYOffset= (black - c.ppMode.minAllowedY) & 0xFFFF;
+#endif
+
+ c.packedYOffset|= c.packedYOffset<<32;
+ c.packedYOffset|= c.packedYOffset<<16;
+
+ c.packedYScale|= c.packedYScale<<32;
+ c.packedYScale|= c.packedYScale<<16;
+
+ if(mode & LEVEL_FIX) QPCorrecture= (int)(scale*256*256 + 0.5);
+ else QPCorrecture= 256*256;
+ }
+ else
+ {
+ c.packedYScale= 0x0100010001000100LL;
+ c.packedYOffset= 0;
+ QPCorrecture= 256*256;
+ }
+
+ /* copy & deinterlace first row of blocks */
+ y=-BLOCK_SIZE;
+ {
+ uint8_t *srcBlock= &(src[y*srcStride]);
+ uint8_t *dstBlock= tempDst + dstStride;
+
+ // From this point on it is guaranteed that we can read and write 16 lines downward
+ // finish 1 block before the next otherwise we might have a problem
+ // with the L1 Cache of the P4 ... or only a few blocks at a time or soemthing
+ for(x=0; x<width; x+=BLOCK_SIZE)
+ {
+
+#ifdef HAVE_MMX2
+/*
+ prefetchnta(srcBlock + (((x>>2)&6) + 5)*srcStride + 32);
+ prefetchnta(srcBlock + (((x>>2)&6) + 6)*srcStride + 32);
+ prefetcht0(dstBlock + (((x>>2)&6) + 5)*dstStride + 32);
+ prefetcht0(dstBlock + (((x>>2)&6) + 6)*dstStride + 32);
+*/
+
+ asm(
+ "mov %4, %%"REG_a" \n\t"
+ "shr $2, %%"REG_a" \n\t"
+ "and $6, %%"REG_a" \n\t"
+ "add %5, %%"REG_a" \n\t"
+ "mov %%"REG_a", %%"REG_d" \n\t"
+ "imul %1, %%"REG_a" \n\t"
+ "imul %3, %%"REG_d" \n\t"
+ "prefetchnta 32(%%"REG_a", %0) \n\t"
+ "prefetcht0 32(%%"REG_d", %2) \n\t"
+ "add %1, %%"REG_a" \n\t"
+ "add %3, %%"REG_d" \n\t"
+ "prefetchnta 32(%%"REG_a", %0) \n\t"
+ "prefetcht0 32(%%"REG_d", %2) \n\t"
+ :: "r" (srcBlock), "r" ((long)srcStride), "r" (dstBlock), "r" ((long)dstStride),
+ "g" ((long)x), "g" ((long)copyAhead)
+ : "%"REG_a, "%"REG_d
+ );
+
+#elif defined(HAVE_3DNOW)
+//FIXME check if this is faster on an 3dnow chip or if its faster without the prefetch or ...
+/* prefetch(srcBlock + (((x>>3)&3) + 5)*srcStride + 32);
+ prefetch(srcBlock + (((x>>3)&3) + 9)*srcStride + 32);
+ prefetchw(dstBlock + (((x>>3)&3) + 5)*dstStride + 32);
+ prefetchw(dstBlock + (((x>>3)&3) + 9)*dstStride + 32);
+*/
+#endif
+
+ RENAME(blockCopy)(dstBlock + dstStride*8, dstStride,
+ srcBlock + srcStride*8, srcStride, mode & LEVEL_FIX, &c.packedYOffset);
+
+ RENAME(duplicate)(dstBlock + dstStride*8, dstStride);
+
+ if(mode & LINEAR_IPOL_DEINT_FILTER)
+ RENAME(deInterlaceInterpolateLinear)(dstBlock, dstStride);
+ else if(mode & LINEAR_BLEND_DEINT_FILTER)
+ RENAME(deInterlaceBlendLinear)(dstBlock, dstStride, c.deintTemp + x);
+ else if(mode & MEDIAN_DEINT_FILTER)
+ RENAME(deInterlaceMedian)(dstBlock, dstStride);
+ else if(mode & CUBIC_IPOL_DEINT_FILTER)
+ RENAME(deInterlaceInterpolateCubic)(dstBlock, dstStride);
+ else if(mode & FFMPEG_DEINT_FILTER)
+ RENAME(deInterlaceFF)(dstBlock, dstStride, c.deintTemp + x);
+ else if(mode & LOWPASS5_DEINT_FILTER)
+ RENAME(deInterlaceL5)(dstBlock, dstStride, c.deintTemp + x, c.deintTemp + width + x);
+/* else if(mode & CUBIC_BLEND_DEINT_FILTER)
+ RENAME(deInterlaceBlendCubic)(dstBlock, dstStride);
+*/
+ dstBlock+=8;
+ srcBlock+=8;
+ }
+ if(width==FFABS(dstStride))
+ linecpy(dst, tempDst + 9*dstStride, copyAhead, dstStride);
+ else
+ {
+ int i;
+ for(i=0; i<copyAhead; i++)
+ {
+ memcpy(dst + i*dstStride, tempDst + (9+i)*dstStride, width);
+ }
+ }
+ }
+
+ for(y=0; y<height; y+=BLOCK_SIZE)
+ {
+ //1% speedup if these are here instead of the inner loop
+ uint8_t *srcBlock= &(src[y*srcStride]);
+ uint8_t *dstBlock= &(dst[y*dstStride]);
+#ifdef HAVE_MMX
+ uint8_t *tempBlock1= c.tempBlocks;
+ uint8_t *tempBlock2= c.tempBlocks + 8;
+#endif
+ int8_t *QPptr= &QPs[(y>>qpVShift)*QPStride];
+ int8_t *nonBQPptr= &c.nonBQPTable[(y>>qpVShift)*FFABS(QPStride)];
+ int QP=0;
+ /* can we mess with a 8x16 block from srcBlock/dstBlock downwards and 1 line upwards
+ if not than use a temporary buffer */
+ if(y+15 >= height)
+ {
+ int i;
+ /* copy from line (copyAhead) to (copyAhead+7) of src, these will be copied with
+ blockcopy to dst later */
+ linecpy(tempSrc + srcStride*copyAhead, srcBlock + srcStride*copyAhead,
+ FFMAX(height-y-copyAhead, 0), srcStride);
+
+ /* duplicate last line of src to fill the void upto line (copyAhead+7) */
+ for(i=FFMAX(height-y, 8); i<copyAhead+8; i++)
+ memcpy(tempSrc + srcStride*i, src + srcStride*(height-1), FFABS(srcStride));
+
+ /* copy up to (copyAhead+1) lines of dst (line -1 to (copyAhead-1))*/
+ linecpy(tempDst, dstBlock - dstStride, FFMIN(height-y+1, copyAhead+1), dstStride);
+
+ /* duplicate last line of dst to fill the void upto line (copyAhead) */
+ for(i=height-y+1; i<=copyAhead; i++)
+ memcpy(tempDst + dstStride*i, dst + dstStride*(height-1), FFABS(dstStride));
+
+ dstBlock= tempDst + dstStride;
+ srcBlock= tempSrc;
+ }
+
+ // From this point on it is guaranteed that we can read and write 16 lines downward
+ // finish 1 block before the next otherwise we might have a problem
+ // with the L1 Cache of the P4 ... or only a few blocks at a time or soemthing
+ for(x=0; x<width; x+=BLOCK_SIZE)
+ {
+ const int stride= dstStride;
+#ifdef HAVE_MMX
+ uint8_t *tmpXchg;
+#endif
+ if(isColor)
+ {
+ QP= QPptr[x>>qpHShift];
+ c.nonBQP= nonBQPptr[x>>qpHShift];
+ }
+ else
+ {
+ QP= QPptr[x>>4];
+ QP= (QP* QPCorrecture + 256*128)>>16;
+ c.nonBQP= nonBQPptr[x>>4];
+ c.nonBQP= (c.nonBQP* QPCorrecture + 256*128)>>16;
+ yHistogram[ srcBlock[srcStride*12 + 4] ]++;
+ }
+ c.QP= QP;
+#ifdef HAVE_MMX
+ asm volatile(
+ "movd %1, %%mm7 \n\t"
+ "packuswb %%mm7, %%mm7 \n\t" // 0, 0, 0, QP, 0, 0, 0, QP
+ "packuswb %%mm7, %%mm7 \n\t" // 0,QP, 0, QP, 0,QP, 0, QP
+ "packuswb %%mm7, %%mm7 \n\t" // QP,..., QP
+ "movq %%mm7, %0 \n\t"
+ : "=m" (c.pQPb)
+ : "r" (QP)
+ );
+#endif
+
+
+#ifdef HAVE_MMX2
+/*
+ prefetchnta(srcBlock + (((x>>2)&6) + 5)*srcStride + 32);
+ prefetchnta(srcBlock + (((x>>2)&6) + 6)*srcStride + 32);
+ prefetcht0(dstBlock + (((x>>2)&6) + 5)*dstStride + 32);
+ prefetcht0(dstBlock + (((x>>2)&6) + 6)*dstStride + 32);
+*/
+
+ asm(
+ "mov %4, %%"REG_a" \n\t"
+ "shr $2, %%"REG_a" \n\t"
+ "and $6, %%"REG_a" \n\t"
+ "add %5, %%"REG_a" \n\t"
+ "mov %%"REG_a", %%"REG_d" \n\t"
+ "imul %1, %%"REG_a" \n\t"
+ "imul %3, %%"REG_d" \n\t"
+ "prefetchnta 32(%%"REG_a", %0) \n\t"
+ "prefetcht0 32(%%"REG_d", %2) \n\t"
+ "add %1, %%"REG_a" \n\t"
+ "add %3, %%"REG_d" \n\t"
+ "prefetchnta 32(%%"REG_a", %0) \n\t"
+ "prefetcht0 32(%%"REG_d", %2) \n\t"
+ :: "r" (srcBlock), "r" ((long)srcStride), "r" (dstBlock), "r" ((long)dstStride),
+ "g" ((long)x), "g" ((long)copyAhead)
+ : "%"REG_a, "%"REG_d
+ );
+
+#elif defined(HAVE_3DNOW)
+//FIXME check if this is faster on an 3dnow chip or if its faster without the prefetch or ...
+/* prefetch(srcBlock + (((x>>3)&3) + 5)*srcStride + 32);
+ prefetch(srcBlock + (((x>>3)&3) + 9)*srcStride + 32);
+ prefetchw(dstBlock + (((x>>3)&3) + 5)*dstStride + 32);
+ prefetchw(dstBlock + (((x>>3)&3) + 9)*dstStride + 32);
+*/
+#endif
+
+ RENAME(blockCopy)(dstBlock + dstStride*copyAhead, dstStride,
+ srcBlock + srcStride*copyAhead, srcStride, mode & LEVEL_FIX, &c.packedYOffset);
+
+ if(mode & LINEAR_IPOL_DEINT_FILTER)
+ RENAME(deInterlaceInterpolateLinear)(dstBlock, dstStride);
+ else if(mode & LINEAR_BLEND_DEINT_FILTER)
+ RENAME(deInterlaceBlendLinear)(dstBlock, dstStride, c.deintTemp + x);
+ else if(mode & MEDIAN_DEINT_FILTER)
+ RENAME(deInterlaceMedian)(dstBlock, dstStride);
+ else if(mode & CUBIC_IPOL_DEINT_FILTER)
+ RENAME(deInterlaceInterpolateCubic)(dstBlock, dstStride);
+ else if(mode & FFMPEG_DEINT_FILTER)
+ RENAME(deInterlaceFF)(dstBlock, dstStride, c.deintTemp + x);
+ else if(mode & LOWPASS5_DEINT_FILTER)
+ RENAME(deInterlaceL5)(dstBlock, dstStride, c.deintTemp + x, c.deintTemp + width + x);
+/* else if(mode & CUBIC_BLEND_DEINT_FILTER)
+ RENAME(deInterlaceBlendCubic)(dstBlock, dstStride);
+*/
+
+ /* only deblock if we have 2 blocks */
+ if(y + 8 < height)
+ {
+ if(mode & V_X1_FILTER)
+ RENAME(vertX1Filter)(dstBlock, stride, &c);
+ else if(mode & V_DEBLOCK)
+ {
+ const int t= RENAME(vertClassify)(dstBlock, stride, &c);
+
+ if(t==1)
+ RENAME(doVertLowPass)(dstBlock, stride, &c);
+ else if(t==2)
+ RENAME(doVertDefFilter)(dstBlock, stride, &c);
+ }else if(mode & V_A_DEBLOCK){
+ RENAME(do_a_deblock)(dstBlock, stride, 1, &c);
+ }
+ }
+
+#ifdef HAVE_MMX
+ RENAME(transpose1)(tempBlock1, tempBlock2, dstBlock, dstStride);
+#endif
+ /* check if we have a previous block to deblock it with dstBlock */
+ if(x - 8 >= 0)
+ {
+#ifdef HAVE_MMX
+ if(mode & H_X1_FILTER)
+ RENAME(vertX1Filter)(tempBlock1, 16, &c);
+ else if(mode & H_DEBLOCK)
+ {
+//START_TIMER
+ const int t= RENAME(vertClassify)(tempBlock1, 16, &c);
+//STOP_TIMER("dc & minmax")
+ if(t==1)
+ RENAME(doVertLowPass)(tempBlock1, 16, &c);
+ else if(t==2)
+ RENAME(doVertDefFilter)(tempBlock1, 16, &c);
+ }else if(mode & H_A_DEBLOCK){
+ RENAME(do_a_deblock)(tempBlock1, 16, 1, &c);
+ }
+
+ RENAME(transpose2)(dstBlock-4, dstStride, tempBlock1 + 4*16);
+
+#else
+ if(mode & H_X1_FILTER)
+ horizX1Filter(dstBlock-4, stride, QP);
+ else if(mode & H_DEBLOCK)
+ {
+#ifdef HAVE_ALTIVEC
+ unsigned char __attribute__ ((aligned(16))) tempBlock[272];
+ transpose_16x8_char_toPackedAlign_altivec(tempBlock, dstBlock - (4 + 1), stride);
+
+ const int t=vertClassify_altivec(tempBlock-48, 16, &c);
+ if(t==1) {
+ doVertLowPass_altivec(tempBlock-48, 16, &c);
+ transpose_8x16_char_fromPackedAlign_altivec(dstBlock - (4 + 1), tempBlock, stride);
+ }
+ else if(t==2) {
+ doVertDefFilter_altivec(tempBlock-48, 16, &c);
+ transpose_8x16_char_fromPackedAlign_altivec(dstBlock - (4 + 1), tempBlock, stride);
+ }
+#else
+ const int t= RENAME(horizClassify)(dstBlock-4, stride, &c);
+
+ if(t==1)
+ RENAME(doHorizLowPass)(dstBlock-4, stride, &c);
+ else if(t==2)
+ RENAME(doHorizDefFilter)(dstBlock-4, stride, &c);
+#endif
+ }else if(mode & H_A_DEBLOCK){
+ RENAME(do_a_deblock)(dstBlock-8, 1, stride, &c);
+ }
+#endif //HAVE_MMX
+ if(mode & DERING)
+ {
+ //FIXME filter first line
+ if(y>0) RENAME(dering)(dstBlock - stride - 8, stride, &c);
+ }
+
+ if(mode & TEMP_NOISE_FILTER)
+ {
+ RENAME(tempNoiseReducer)(dstBlock-8, stride,
+ c.tempBlured[isColor] + y*dstStride + x,
+ c.tempBluredPast[isColor] + (y>>3)*256 + (x>>3),
+ c.ppMode.maxTmpNoise);
+ }
+ }
+
+ dstBlock+=8;
+ srcBlock+=8;
+
+#ifdef HAVE_MMX
+ tmpXchg= tempBlock1;
+ tempBlock1= tempBlock2;
+ tempBlock2 = tmpXchg;
+#endif
+ }
+
+ if(mode & DERING)
+ {
+ if(y > 0) RENAME(dering)(dstBlock - dstStride - 8, dstStride, &c);
+ }
+
+ if((mode & TEMP_NOISE_FILTER))
+ {
+ RENAME(tempNoiseReducer)(dstBlock-8, dstStride,
+ c.tempBlured[isColor] + y*dstStride + x,
+ c.tempBluredPast[isColor] + (y>>3)*256 + (x>>3),
+ c.ppMode.maxTmpNoise);
+ }
+
+ /* did we use a tmp buffer for the last lines*/
+ if(y+15 >= height)
+ {
+ uint8_t *dstBlock= &(dst[y*dstStride]);
+ if(width==FFABS(dstStride))
+ linecpy(dstBlock, tempDst + dstStride, height-y, dstStride);
+ else
+ {
+ int i;
+ for(i=0; i<height-y; i++)
+ {
+ memcpy(dstBlock + i*dstStride, tempDst + (i+1)*dstStride, width);
+ }
+ }
+ }
+/*
+ for(x=0; x<width; x+=32)
+ {
+ volatile int i;
+ i+= + dstBlock[x + 7*dstStride] + dstBlock[x + 8*dstStride]
+ + dstBlock[x + 9*dstStride] + dstBlock[x +10*dstStride]
+ + dstBlock[x +11*dstStride] + dstBlock[x +12*dstStride];
+// + dstBlock[x +13*dstStride]
+// + dstBlock[x +14*dstStride] + dstBlock[x +15*dstStride];
+ }*/
+ }
+#ifdef HAVE_3DNOW
+ asm volatile("femms");
+#elif defined (HAVE_MMX)
+ asm volatile("emms");
+#endif
+
+#ifdef DEBUG_BRIGHTNESS
+ if(!isColor)
+ {
+ int max=1;
+ int i;
+ for(i=0; i<256; i++)
+ if(yHistogram[i] > max) max=yHistogram[i];
+
+ for(i=1; i<256; i++)
+ {
+ int x;
+ int start=yHistogram[i-1]/(max/256+1);
+ int end=yHistogram[i]/(max/256+1);
+ int inc= end > start ? 1 : -1;
+ for(x=start; x!=end+inc; x+=inc)
+ dst[ i*dstStride + x]+=128;
+ }
+
+ for(i=0; i<100; i+=2)
+ {
+ dst[ (white)*dstStride + i]+=128;
+ dst[ (black)*dstStride + i]+=128;
+ }
+
+ }
+#endif
+
+ *c2= c; //copy local context back
+
+}
diff --git a/contrib/ffmpeg/libswscale/Makefile b/contrib/ffmpeg/libswscale/Makefile
new file mode 100644
index 000000000..a1c25a76a
--- /dev/null
+++ b/contrib/ffmpeg/libswscale/Makefile
@@ -0,0 +1,24 @@
+
+include ../config.mak
+
+NAME=swscale
+LIBVERSION=$(SWSVERSION)
+LIBMAJOR=$(SWSMAJOR)
+
+EXTRALIBS := -L$(BUILD_ROOT)/libavutil -lavutil$(BUILDSUF) $(EXTRALIBS)
+
+OBJS= swscale.o rgb2rgb.o
+
+OBJS-$(TARGET_ALTIVEC) += yuv2rgb_altivec.o
+OBJS-$(CONFIG_GPL) += yuv2rgb.o
+
+HEADERS = swscale.h rgb2rgb.h
+
+include ../common.mak
+
+cs_test: cs_test.o $(LIB)
+
+swscale-example: swscale-example.o $(LIB) -lm
+
+clean::
+ rm -f cs_test swscale-example
diff --git a/contrib/ffmpeg/libswscale/cs_test.c b/contrib/ffmpeg/libswscale/cs_test.c
new file mode 100644
index 000000000..cd0100618
--- /dev/null
+++ b/contrib/ffmpeg/libswscale/cs_test.c
@@ -0,0 +1,303 @@
+/*
+ * Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdio.h>
+#include <string.h> /* for memset() */
+#include <unistd.h>
+#include <stdlib.h>
+#include <inttypes.h>
+
+#include "swscale.h"
+#include "rgb2rgb.h"
+
+#define SIZE 1000
+#define srcByte 0x55
+#define dstByte 0xBB
+
+
+static int cpu_caps;
+
+static char *args_parse(int argc, char *argv[])
+{
+ int o;
+
+ while ((o = getopt(argc, argv, "m23")) != -1) {
+ switch (o) {
+ case 'm':
+ cpu_caps |= SWS_CPU_CAPS_MMX;
+ break;
+ case '2':
+ cpu_caps |= SWS_CPU_CAPS_MMX2;
+ break;
+ case '3':
+ cpu_caps |= SWS_CPU_CAPS_3DNOW;
+ break;
+ default:
+ av_log(NULL, AV_LOG_ERROR, "Unknown option %c\n", o);
+ }
+ }
+
+ return argv[optind];
+}
+
+int main(int argc, char **argv)
+{
+ int i, funcNum;
+ uint8_t *srcBuffer= (uint8_t*)av_malloc(SIZE);
+ uint8_t *dstBuffer= (uint8_t*)av_malloc(SIZE);
+ int failedNum=0;
+ int passedNum=0;
+
+ av_log(NULL, AV_LOG_INFO, "memory corruption test ...\n");
+ args_parse(argc, argv);
+ av_log(NULL, AV_LOG_INFO, "CPU capabilities forced to %x\n", cpu_caps);
+ sws_rgb2rgb_init(cpu_caps);
+
+ for(funcNum=0; funcNum<100; funcNum++){
+ int width;
+ int failed=0;
+ int srcBpp=0;
+ int dstBpp=0;
+
+ av_log(NULL, AV_LOG_INFO,".");
+ memset(srcBuffer, srcByte, SIZE);
+
+ for(width=32; width<64; width++){
+ int dstOffset;
+ for(dstOffset=128; dstOffset<196; dstOffset+=4){
+ int srcOffset;
+ memset(dstBuffer, dstByte, SIZE);
+
+ for(srcOffset=128; srcOffset<196; srcOffset+=4){
+ uint8_t *src= srcBuffer+srcOffset;
+ uint8_t *dst= dstBuffer+dstOffset;
+ char *name=NULL;
+
+ if(failed) break; //don't fill the screen with shit ...
+
+ switch(funcNum){
+ case 0:
+ srcBpp=2;
+ dstBpp=2;
+ name="rgb15to16";
+ rgb15to16(src, dst, width*srcBpp);
+ break;
+ case 1:
+ srcBpp=2;
+ dstBpp=3;
+ name="rgb15to24";
+ rgb15to24(src, dst, width*srcBpp);
+ break;
+ case 2:
+ srcBpp=2;
+ dstBpp=4;
+ name="rgb15to32";
+ rgb15to32(src, dst, width*srcBpp);
+ break;
+ case 3:
+ srcBpp=2;
+ dstBpp=3;
+ name="rgb16to24";
+ rgb16to24(src, dst, width*srcBpp);
+ break;
+ case 4:
+ srcBpp=2;
+ dstBpp=4;
+ name="rgb16to32";
+ rgb16to32(src, dst, width*srcBpp);
+ break;
+ case 5:
+ srcBpp=3;
+ dstBpp=2;
+ name="rgb24to15";
+ rgb24to15(src, dst, width*srcBpp);
+ break;
+ case 6:
+ srcBpp=3;
+ dstBpp=2;
+ name="rgb24to16";
+ rgb24to16(src, dst, width*srcBpp);
+ break;
+ case 7:
+ srcBpp=3;
+ dstBpp=4;
+ name="rgb24to32";
+ rgb24to32(src, dst, width*srcBpp);
+ break;
+ case 8:
+ srcBpp=4;
+ dstBpp=2;
+ name="rgb32to15";
+ //((*s++) << TGA_SHIFT32) | TGA_ALPHA32;
+ rgb32to15(src, dst, width*srcBpp);
+ break;
+ case 9:
+ srcBpp=4;
+ dstBpp=2;
+ name="rgb32to16";
+ rgb32to16(src, dst, width*srcBpp);
+ break;
+ case 10:
+ srcBpp=4;
+ dstBpp=3;
+ name="rgb32to24";
+ rgb32to24(src, dst, width*srcBpp);
+ break;
+ case 11:
+ srcBpp=2;
+ dstBpp=2;
+ name="rgb16to15";
+ rgb16to15(src, dst, width*srcBpp);
+ break;
+
+ case 14:
+ srcBpp=2;
+ dstBpp=2;
+ name="rgb15tobgr15";
+ rgb15tobgr15(src, dst, width*srcBpp);
+ break;
+ case 15:
+ srcBpp=2;
+ dstBpp=2;
+ name="rgb15tobgr16";
+ rgb15tobgr16(src, dst, width*srcBpp);
+ break;
+ case 16:
+ srcBpp=2;
+ dstBpp=3;
+ name="rgb15tobgr24";
+ rgb15tobgr24(src, dst, width*srcBpp);
+ break;
+ case 17:
+ srcBpp=2;
+ dstBpp=4;
+ name="rgb15tobgr32";
+ rgb15tobgr32(src, dst, width*srcBpp);
+ break;
+ case 18:
+ srcBpp=2;
+ dstBpp=2;
+ name="rgb16tobgr15";
+ rgb16tobgr15(src, dst, width*srcBpp);
+ break;
+ case 19:
+ srcBpp=2;
+ dstBpp=2;
+ name="rgb16tobgr16";
+ rgb16tobgr16(src, dst, width*srcBpp);
+ break;
+ case 20:
+ srcBpp=2;
+ dstBpp=3;
+ name="rgb16tobgr24";
+ rgb16tobgr24(src, dst, width*srcBpp);
+ break;
+ case 21:
+ srcBpp=2;
+ dstBpp=4;
+ name="rgb16tobgr32";
+ rgb16tobgr32(src, dst, width*srcBpp);
+ break;
+ case 22:
+ srcBpp=3;
+ dstBpp=2;
+ name="rgb24tobgr15";
+ rgb24tobgr15(src, dst, width*srcBpp);
+ break;
+ case 23:
+ srcBpp=3;
+ dstBpp=2;
+ name="rgb24tobgr16";
+ rgb24tobgr16(src, dst, width*srcBpp);
+ break;
+ case 24:
+ srcBpp=3;
+ dstBpp=3;
+ name="rgb24tobgr24";
+ rgb24tobgr24(src, dst, width*srcBpp);
+ break;
+ case 25:
+ srcBpp=3;
+ dstBpp=4;
+ name="rgb24tobgr32";
+ rgb24tobgr32(src, dst, width*srcBpp);
+ break;
+ case 26:
+ srcBpp=4;
+ dstBpp=2;
+ name="rgb32tobgr15";
+ rgb32tobgr15(src, dst, width*srcBpp);
+ break;
+ case 27:
+ srcBpp=4;
+ dstBpp=2;
+ name="rgb32tobgr16";
+ rgb32tobgr16(src, dst, width*srcBpp);
+ break;
+ case 28:
+ srcBpp=4;
+ dstBpp=3;
+ name="rgb32tobgr24";
+ rgb32tobgr24(src, dst, width*srcBpp);
+ break;
+ case 29:
+ srcBpp=4;
+ dstBpp=4;
+ name="rgb32tobgr32";
+ rgb32tobgr32(src, dst, width*srcBpp);
+ break;
+
+ }
+ if(!srcBpp) break;
+
+ for(i=0; i<SIZE; i++){
+ if(srcBuffer[i]!=srcByte){
+ av_log(NULL, AV_LOG_INFO, "src damaged at %d w:%d src:%d dst:%d %s\n",
+ i, width, srcOffset, dstOffset, name);
+ failed=1;
+ break;
+ }
+ }
+ for(i=0; i<dstOffset; i++){
+ if(dstBuffer[i]!=dstByte){
+ av_log(NULL, AV_LOG_INFO, "dst damaged at %d w:%d src:%d dst:%d %s\n",
+ i, width, srcOffset, dstOffset, name);
+ failed=1;
+ break;
+ }
+ }
+ for(i=dstOffset + width*dstBpp; i<SIZE; i++){
+ if(dstBuffer[i]!=dstByte){
+ av_log(NULL, AV_LOG_INFO, "dst damaged at %d w:%d src:%d dst:%d %s\n",
+ i, width, srcOffset, dstOffset, name);
+ failed=1;
+ break;
+ }
+ }
+ }
+ }
+ }
+ if(failed) failedNum++;
+ else if(srcBpp) passedNum++;
+ }
+
+ av_log(NULL, AV_LOG_INFO, "%d converters passed, %d converters randomly overwrote memory\n", passedNum, failedNum);
+ return failedNum;
+}
diff --git a/contrib/ffmpeg/libswscale/rgb2rgb.c b/contrib/ffmpeg/libswscale/rgb2rgb.c
new file mode 100644
index 000000000..a938abfc9
--- /dev/null
+++ b/contrib/ffmpeg/libswscale/rgb2rgb.c
@@ -0,0 +1,665 @@
+/*
+ *
+ * rgb2rgb.c, Software RGB to RGB convertor
+ * pluralize by Software PAL8 to RGB convertor
+ * Software YUV to YUV convertor
+ * Software YUV to RGB convertor
+ * Written by Nick Kurshev.
+ * palette & YUV & runtime CPU stuff by Michael (michaelni@gmx.at)
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * the C code (not assembly, mmx, ...) of this file can be used
+ * under the LGPL license too
+ */
+#include <inttypes.h>
+#include "config.h"
+#include "rgb2rgb.h"
+#include "swscale.h"
+#include "swscale_internal.h"
+#include "x86_cpu.h"
+#include "bswap.h"
+#ifdef USE_FASTMEMCPY
+#include "libvo/fastmemcpy.h"
+#endif
+
+#define FAST_BGR2YV12 // use 7 bit coeffs instead of 15bit
+
+void (*rgb24to32)(const uint8_t *src,uint8_t *dst,long src_size);
+void (*rgb24to16)(const uint8_t *src,uint8_t *dst,long src_size);
+void (*rgb24to15)(const uint8_t *src,uint8_t *dst,long src_size);
+void (*rgb32to24)(const uint8_t *src,uint8_t *dst,long src_size);
+void (*rgb32to16)(const uint8_t *src,uint8_t *dst,long src_size);
+void (*rgb32to15)(const uint8_t *src,uint8_t *dst,long src_size);
+void (*rgb15to16)(const uint8_t *src,uint8_t *dst,long src_size);
+void (*rgb15to24)(const uint8_t *src,uint8_t *dst,long src_size);
+void (*rgb15to32)(const uint8_t *src,uint8_t *dst,long src_size);
+void (*rgb16to15)(const uint8_t *src,uint8_t *dst,long src_size);
+void (*rgb16to24)(const uint8_t *src,uint8_t *dst,long src_size);
+void (*rgb16to32)(const uint8_t *src,uint8_t *dst,long src_size);
+//void (*rgb24tobgr32)(const uint8_t *src, uint8_t *dst, long src_size);
+void (*rgb24tobgr24)(const uint8_t *src, uint8_t *dst, long src_size);
+void (*rgb24tobgr16)(const uint8_t *src, uint8_t *dst, long src_size);
+void (*rgb24tobgr15)(const uint8_t *src, uint8_t *dst, long src_size);
+void (*rgb32tobgr32)(const uint8_t *src, uint8_t *dst, long src_size);
+//void (*rgb32tobgr24)(const uint8_t *src, uint8_t *dst, long src_size);
+void (*rgb32tobgr16)(const uint8_t *src, uint8_t *dst, long src_size);
+void (*rgb32tobgr15)(const uint8_t *src, uint8_t *dst, long src_size);
+
+void (*yv12toyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
+ long width, long height,
+ long lumStride, long chromStride, long dstStride);
+void (*yv12touyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
+ long width, long height,
+ long lumStride, long chromStride, long dstStride);
+void (*yuv422ptoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
+ long width, long height,
+ long lumStride, long chromStride, long dstStride);
+void (*yuy2toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
+ long width, long height,
+ long lumStride, long chromStride, long srcStride);
+void (*rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
+ long width, long height,
+ 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,
+ long width, long height, long src1Stride,
+ long src2Stride, long dstStride);
+void (*vu9_to_vu12)(const uint8_t *src1, const uint8_t *src2,
+ uint8_t *dst1, uint8_t *dst2,
+ long width, long height,
+ long srcStride1, long srcStride2,
+ long dstStride1, long dstStride2);
+void (*yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2, const uint8_t *src3,
+ uint8_t *dst,
+ long width, long height,
+ long srcStride1, long srcStride2,
+ long srcStride3, long dstStride);
+
+#if defined(ARCH_X86) && defined(CONFIG_GPL)
+static const uint64_t mmx_null __attribute__((aligned(8))) = 0x0000000000000000ULL;
+static const uint64_t mmx_one __attribute__((aligned(8))) = 0xFFFFFFFFFFFFFFFFULL;
+static const uint64_t mask32b attribute_used __attribute__((aligned(8))) = 0x000000FF000000FFULL;
+static const uint64_t mask32g attribute_used __attribute__((aligned(8))) = 0x0000FF000000FF00ULL;
+static const uint64_t mask32r attribute_used __attribute__((aligned(8))) = 0x00FF000000FF0000ULL;
+static const uint64_t mask32 __attribute__((aligned(8))) = 0x00FFFFFF00FFFFFFULL;
+static const uint64_t mask3216br __attribute__((aligned(8)))=0x00F800F800F800F8ULL;
+static const uint64_t mask3216g __attribute__((aligned(8)))=0x0000FC000000FC00ULL;
+static const uint64_t mask3215g __attribute__((aligned(8)))=0x0000F8000000F800ULL;
+static const uint64_t mul3216 __attribute__((aligned(8))) = 0x2000000420000004ULL;
+static const uint64_t mul3215 __attribute__((aligned(8))) = 0x2000000820000008ULL;
+static const uint64_t mask24b attribute_used __attribute__((aligned(8))) = 0x00FF0000FF0000FFULL;
+static const uint64_t mask24g attribute_used __attribute__((aligned(8))) = 0xFF0000FF0000FF00ULL;
+static const uint64_t mask24r attribute_used __attribute__((aligned(8))) = 0x0000FF0000FF0000ULL;
+static const uint64_t mask24l __attribute__((aligned(8))) = 0x0000000000FFFFFFULL;
+static const uint64_t mask24h __attribute__((aligned(8))) = 0x0000FFFFFF000000ULL;
+static const uint64_t mask24hh __attribute__((aligned(8))) = 0xffff000000000000ULL;
+static const uint64_t mask24hhh __attribute__((aligned(8))) = 0xffffffff00000000ULL;
+static const uint64_t mask24hhhh __attribute__((aligned(8))) = 0xffffffffffff0000ULL;
+static const uint64_t mask15b __attribute__((aligned(8))) = 0x001F001F001F001FULL; /* 00000000 00011111 xxB */
+static const uint64_t mask15rg __attribute__((aligned(8))) = 0x7FE07FE07FE07FE0ULL; /* 01111111 11100000 RGx */
+static const uint64_t mask15s __attribute__((aligned(8))) = 0xFFE0FFE0FFE0FFE0ULL;
+static const uint64_t mask15g __attribute__((aligned(8))) = 0x03E003E003E003E0ULL;
+static const uint64_t mask15r __attribute__((aligned(8))) = 0x7C007C007C007C00ULL;
+#define mask16b mask15b
+static const uint64_t mask16g __attribute__((aligned(8))) = 0x07E007E007E007E0ULL;
+static const uint64_t mask16r __attribute__((aligned(8))) = 0xF800F800F800F800ULL;
+static const uint64_t red_16mask __attribute__((aligned(8))) = 0x0000f8000000f800ULL;
+static const uint64_t green_16mask __attribute__((aligned(8)))= 0x000007e0000007e0ULL;
+static const uint64_t blue_16mask __attribute__((aligned(8))) = 0x0000001f0000001fULL;
+static const uint64_t red_15mask __attribute__((aligned(8))) = 0x00007c000000f800ULL;
+static const uint64_t green_15mask __attribute__((aligned(8)))= 0x000003e0000007e0ULL;
+static const uint64_t blue_15mask __attribute__((aligned(8))) = 0x0000001f0000001fULL;
+
+#ifdef FAST_BGR2YV12
+static const uint64_t bgr2YCoeff attribute_used __attribute__((aligned(8))) = 0x000000210041000DULL;
+static const uint64_t bgr2UCoeff attribute_used __attribute__((aligned(8))) = 0x0000FFEEFFDC0038ULL;
+static const uint64_t bgr2VCoeff attribute_used __attribute__((aligned(8))) = 0x00000038FFD2FFF8ULL;
+#else
+static const uint64_t bgr2YCoeff attribute_used __attribute__((aligned(8))) = 0x000020E540830C8BULL;
+static const uint64_t bgr2UCoeff attribute_used __attribute__((aligned(8))) = 0x0000ED0FDAC23831ULL;
+static const uint64_t bgr2VCoeff attribute_used __attribute__((aligned(8))) = 0x00003831D0E6F6EAULL;
+#endif
+static const uint64_t bgr2YOffset attribute_used __attribute__((aligned(8))) = 0x1010101010101010ULL;
+static const uint64_t bgr2UVOffset attribute_used __attribute__((aligned(8)))= 0x8080808080808080ULL;
+static const uint64_t w1111 attribute_used __attribute__((aligned(8))) = 0x0001000100010001ULL;
+
+#if 0
+static volatile uint64_t __attribute__((aligned(8))) b5Dither;
+static volatile uint64_t __attribute__((aligned(8))) g5Dither;
+static volatile uint64_t __attribute__((aligned(8))) g6Dither;
+static volatile uint64_t __attribute__((aligned(8))) r5Dither;
+
+static uint64_t __attribute__((aligned(8))) dither4[2]={
+ 0x0103010301030103LL,
+ 0x0200020002000200LL,};
+
+static uint64_t __attribute__((aligned(8))) dither8[2]={
+ 0x0602060206020602LL,
+ 0x0004000400040004LL,};
+#endif
+#endif /* defined(ARCH_X86) */
+
+#define RGB2YUV_SHIFT 8
+#define BY ((int)( 0.098*(1<<RGB2YUV_SHIFT)+0.5))
+#define BV ((int)(-0.071*(1<<RGB2YUV_SHIFT)+0.5))
+#define BU ((int)( 0.439*(1<<RGB2YUV_SHIFT)+0.5))
+#define GY ((int)( 0.504*(1<<RGB2YUV_SHIFT)+0.5))
+#define GV ((int)(-0.368*(1<<RGB2YUV_SHIFT)+0.5))
+#define GU ((int)(-0.291*(1<<RGB2YUV_SHIFT)+0.5))
+#define RY ((int)( 0.257*(1<<RGB2YUV_SHIFT)+0.5))
+#define RV ((int)( 0.439*(1<<RGB2YUV_SHIFT)+0.5))
+#define RU ((int)(-0.148*(1<<RGB2YUV_SHIFT)+0.5))
+
+//Note: we have C, MMX, MMX2, 3DNOW version therse no 3DNOW+MMX2 one
+//Plain C versions
+#undef HAVE_MMX
+#undef HAVE_MMX2
+#undef HAVE_3DNOW
+#undef HAVE_SSE2
+#define RENAME(a) a ## _C
+#include "rgb2rgb_template.c"
+
+#if defined(ARCH_X86) && defined(CONFIG_GPL)
+
+//MMX versions
+#undef RENAME
+#define HAVE_MMX
+#undef HAVE_MMX2
+#undef HAVE_3DNOW
+#undef HAVE_SSE2
+#define RENAME(a) a ## _MMX
+#include "rgb2rgb_template.c"
+
+//MMX2 versions
+#undef RENAME
+#define HAVE_MMX
+#define HAVE_MMX2
+#undef HAVE_3DNOW
+#undef HAVE_SSE2
+#define RENAME(a) a ## _MMX2
+#include "rgb2rgb_template.c"
+
+//3DNOW versions
+#undef RENAME
+#define HAVE_MMX
+#undef HAVE_MMX2
+#define HAVE_3DNOW
+#undef HAVE_SSE2
+#define RENAME(a) a ## _3DNOW
+#include "rgb2rgb_template.c"
+
+#endif //ARCH_X86 || ARCH_X86_64
+
+/*
+ rgb15->rgb16 Original by Strepto/Astral
+ ported to gcc & bugfixed : A'rpi
+ MMX2, 3DNOW optimization by Nick Kurshev
+ 32bit c version, and and&add trick by Michael Niedermayer
+*/
+
+void sws_rgb2rgb_init(int flags){
+#if (defined(HAVE_MMX2) || defined(HAVE_3DNOW) || defined(HAVE_MMX)) && defined(CONFIG_GPL)
+ if(flags & SWS_CPU_CAPS_MMX2){
+ rgb15to16= rgb15to16_MMX2;
+ rgb15to24= rgb15to24_MMX2;
+ rgb15to32= rgb15to32_MMX2;
+ rgb16to24= rgb16to24_MMX2;
+ rgb16to32= rgb16to32_MMX2;
+ rgb16to15= rgb16to15_MMX2;
+ rgb24to16= rgb24to16_MMX2;
+ rgb24to15= rgb24to15_MMX2;
+ rgb24to32= rgb24to32_MMX2;
+ rgb32to16= rgb32to16_MMX2;
+ rgb32to15= rgb32to15_MMX2;
+ rgb32to24= rgb32to24_MMX2;
+ rgb24tobgr15= rgb24tobgr15_MMX2;
+ rgb24tobgr16= rgb24tobgr16_MMX2;
+ rgb24tobgr24= rgb24tobgr24_MMX2;
+ rgb32tobgr32= rgb32tobgr32_MMX2;
+ rgb32tobgr16= rgb32tobgr16_MMX2;
+ rgb32tobgr15= rgb32tobgr15_MMX2;
+ yv12toyuy2= yv12toyuy2_MMX2;
+ yv12touyvy= yv12touyvy_MMX2;
+ yuv422ptoyuy2= yuv422ptoyuy2_MMX2;
+ yuy2toyv12= yuy2toyv12_MMX2;
+// uyvytoyv12= uyvytoyv12_MMX2;
+// yvu9toyv12= yvu9toyv12_MMX2;
+ planar2x= planar2x_MMX2;
+ rgb24toyv12= rgb24toyv12_MMX2;
+ interleaveBytes= interleaveBytes_MMX2;
+ vu9_to_vu12= vu9_to_vu12_MMX2;
+ yvu9_to_yuy2= yvu9_to_yuy2_MMX2;
+ }else if(flags & SWS_CPU_CAPS_3DNOW){
+ rgb15to16= rgb15to16_3DNOW;
+ rgb15to24= rgb15to24_3DNOW;
+ rgb15to32= rgb15to32_3DNOW;
+ rgb16to24= rgb16to24_3DNOW;
+ rgb16to32= rgb16to32_3DNOW;
+ rgb16to15= rgb16to15_3DNOW;
+ rgb24to16= rgb24to16_3DNOW;
+ rgb24to15= rgb24to15_3DNOW;
+ rgb24to32= rgb24to32_3DNOW;
+ rgb32to16= rgb32to16_3DNOW;
+ rgb32to15= rgb32to15_3DNOW;
+ rgb32to24= rgb32to24_3DNOW;
+ rgb24tobgr15= rgb24tobgr15_3DNOW;
+ rgb24tobgr16= rgb24tobgr16_3DNOW;
+ rgb24tobgr24= rgb24tobgr24_3DNOW;
+ rgb32tobgr32= rgb32tobgr32_3DNOW;
+ rgb32tobgr16= rgb32tobgr16_3DNOW;
+ rgb32tobgr15= rgb32tobgr15_3DNOW;
+ yv12toyuy2= yv12toyuy2_3DNOW;
+ yv12touyvy= yv12touyvy_3DNOW;
+ yuv422ptoyuy2= yuv422ptoyuy2_3DNOW;
+ yuy2toyv12= yuy2toyv12_3DNOW;
+// uyvytoyv12= uyvytoyv12_3DNOW;
+// yvu9toyv12= yvu9toyv12_3DNOW;
+ planar2x= planar2x_3DNOW;
+ rgb24toyv12= rgb24toyv12_3DNOW;
+ interleaveBytes= interleaveBytes_3DNOW;
+ vu9_to_vu12= vu9_to_vu12_3DNOW;
+ yvu9_to_yuy2= yvu9_to_yuy2_3DNOW;
+ }else if(flags & SWS_CPU_CAPS_MMX){
+ rgb15to16= rgb15to16_MMX;
+ rgb15to24= rgb15to24_MMX;
+ rgb15to32= rgb15to32_MMX;
+ rgb16to24= rgb16to24_MMX;
+ rgb16to32= rgb16to32_MMX;
+ rgb16to15= rgb16to15_MMX;
+ rgb24to16= rgb24to16_MMX;
+ rgb24to15= rgb24to15_MMX;
+ rgb24to32= rgb24to32_MMX;
+ rgb32to16= rgb32to16_MMX;
+ rgb32to15= rgb32to15_MMX;
+ rgb32to24= rgb32to24_MMX;
+ rgb24tobgr15= rgb24tobgr15_MMX;
+ rgb24tobgr16= rgb24tobgr16_MMX;
+ rgb24tobgr24= rgb24tobgr24_MMX;
+ rgb32tobgr32= rgb32tobgr32_MMX;
+ rgb32tobgr16= rgb32tobgr16_MMX;
+ rgb32tobgr15= rgb32tobgr15_MMX;
+ yv12toyuy2= yv12toyuy2_MMX;
+ yv12touyvy= yv12touyvy_MMX;
+ yuv422ptoyuy2= yuv422ptoyuy2_MMX;
+ yuy2toyv12= yuy2toyv12_MMX;
+// uyvytoyv12= uyvytoyv12_MMX;
+// yvu9toyv12= yvu9toyv12_MMX;
+ planar2x= planar2x_MMX;
+ rgb24toyv12= rgb24toyv12_MMX;
+ interleaveBytes= interleaveBytes_MMX;
+ vu9_to_vu12= vu9_to_vu12_MMX;
+ yvu9_to_yuy2= yvu9_to_yuy2_MMX;
+ }else
+#endif /* defined(HAVE_MMX2) || defined(HAVE_3DNOW) || defined(HAVE_MMX) */
+ {
+ rgb15to16= rgb15to16_C;
+ rgb15to24= rgb15to24_C;
+ rgb15to32= rgb15to32_C;
+ rgb16to24= rgb16to24_C;
+ rgb16to32= rgb16to32_C;
+ rgb16to15= rgb16to15_C;
+ rgb24to16= rgb24to16_C;
+ rgb24to15= rgb24to15_C;
+ rgb24to32= rgb24to32_C;
+ rgb32to16= rgb32to16_C;
+ rgb32to15= rgb32to15_C;
+ rgb32to24= rgb32to24_C;
+ rgb24tobgr15= rgb24tobgr15_C;
+ rgb24tobgr16= rgb24tobgr16_C;
+ rgb24tobgr24= rgb24tobgr24_C;
+ rgb32tobgr32= rgb32tobgr32_C;
+ rgb32tobgr16= rgb32tobgr16_C;
+ rgb32tobgr15= rgb32tobgr15_C;
+ yv12toyuy2= yv12toyuy2_C;
+ yv12touyvy= yv12touyvy_C;
+ yuv422ptoyuy2= yuv422ptoyuy2_C;
+ yuy2toyv12= yuy2toyv12_C;
+// uyvytoyv12= uyvytoyv12_C;
+// yvu9toyv12= yvu9toyv12_C;
+ planar2x= planar2x_C;
+ rgb24toyv12= rgb24toyv12_C;
+ interleaveBytes= interleaveBytes_C;
+ vu9_to_vu12= vu9_to_vu12_C;
+ yvu9_to_yuy2= yvu9_to_yuy2_C;
+ }
+}
+
+/**
+ * Palette is assumed to contain BGR32.
+ */
+void palette8torgb32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
+{
+ long i;
+
+/*
+ for(i=0; i<num_pixels; i++)
+ ((unsigned *)dst)[i] = ((unsigned *)palette)[ src[i] ];
+*/
+
+ for(i=0; i<num_pixels; i++)
+ {
+ #ifdef WORDS_BIGENDIAN
+ dst[3]= palette[ src[i]*4+2 ];
+ dst[2]= palette[ src[i]*4+1 ];
+ dst[1]= palette[ src[i]*4+0 ];
+ #else
+ //FIXME slow?
+ dst[0]= palette[ src[i]*4+2 ];
+ dst[1]= palette[ src[i]*4+1 ];
+ dst[2]= palette[ src[i]*4+0 ];
+ //dst[3]= 0; /* do we need this cleansing? */
+ #endif
+ dst+= 4;
+ }
+}
+
+void palette8tobgr32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
+{
+ long i;
+ for(i=0; i<num_pixels; i++)
+ {
+ #ifdef WORDS_BIGENDIAN
+ dst[3]= palette[ src[i]*4+0 ];
+ dst[2]= palette[ src[i]*4+1 ];
+ dst[1]= palette[ src[i]*4+2 ];
+ #else
+ //FIXME slow?
+ dst[0]= palette[ src[i]*4+0 ];
+ dst[1]= palette[ src[i]*4+1 ];
+ dst[2]= palette[ src[i]*4+2 ];
+ //dst[3]= 0; /* do we need this cleansing? */
+ #endif
+
+ dst+= 4;
+ }
+}
+
+/**
+ * Palette is assumed to contain BGR32.
+ */
+void palette8torgb24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
+{
+ long i;
+/*
+ writes 1 byte o much and might cause alignment issues on some architectures?
+ for(i=0; i<num_pixels; i++)
+ ((unsigned *)(&dst[i*3])) = ((unsigned *)palette)[ src[i] ];
+*/
+ for(i=0; i<num_pixels; i++)
+ {
+ //FIXME slow?
+ dst[0]= palette[ src[i]*4+2 ];
+ dst[1]= palette[ src[i]*4+1 ];
+ dst[2]= palette[ src[i]*4+0 ];
+ dst+= 3;
+ }
+}
+
+void palette8tobgr24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
+{
+ long i;
+/*
+ writes 1 byte o much and might cause alignment issues on some architectures?
+ for(i=0; i<num_pixels; i++)
+ ((unsigned *)(&dst[i*3])) = ((unsigned *)palette)[ src[i] ];
+*/
+ for(i=0; i<num_pixels; i++)
+ {
+ //FIXME slow?
+ dst[0]= palette[ src[i]*4+0 ];
+ dst[1]= palette[ src[i]*4+1 ];
+ dst[2]= palette[ src[i]*4+2 ];
+ dst+= 3;
+ }
+}
+
+/**
+ * Palette is assumed to contain bgr16, see rgb32to16 to convert the palette
+ */
+void palette8torgb16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
+{
+ long i;
+ for(i=0; i<num_pixels; i++)
+ ((uint16_t *)dst)[i] = ((uint16_t *)palette)[ src[i] ];
+}
+void palette8tobgr16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
+{
+ long i;
+ for(i=0; i<num_pixels; i++)
+ ((uint16_t *)dst)[i] = bswap_16(((uint16_t *)palette)[ src[i] ]);
+}
+
+/**
+ * Palette is assumed to contain BGR15, see rgb32to15 to convert the palette.
+ */
+void palette8torgb15(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
+{
+ long i;
+ for(i=0; i<num_pixels; i++)
+ ((uint16_t *)dst)[i] = ((uint16_t *)palette)[ src[i] ];
+}
+void palette8tobgr15(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
+{
+ long i;
+ for(i=0; i<num_pixels; i++)
+ ((uint16_t *)dst)[i] = bswap_16(((uint16_t *)palette)[ src[i] ]);
+}
+
+void rgb32tobgr24(const uint8_t *src, uint8_t *dst, long src_size)
+{
+ long i;
+ long num_pixels = src_size >> 2;
+ for(i=0; i<num_pixels; i++)
+ {
+ #ifdef WORDS_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
+ }
+}
+
+void rgb24tobgr32(const uint8_t *src, uint8_t *dst, long src_size)
+{
+ long i;
+ for(i=0; 3*i<src_size; i++)
+ {
+ #ifdef WORDS_BIGENDIAN
+ /* RGB24 (= R,G,B) -> BGR32 (= A,R,G,B) */
+ dst[4*i + 0] = 0;
+ 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] = 0;
+ #endif
+ }
+}
+
+void rgb16tobgr32(const uint8_t *src, uint8_t *dst, long src_size)
+{
+ const uint16_t *end;
+ uint8_t *d = (uint8_t *)dst;
+ const uint16_t *s = (uint16_t *)src;
+ end = s + src_size/2;
+ while(s < end)
+ {
+ register uint16_t bgr;
+ bgr = *s++;
+ #ifdef WORDS_BIGENDIAN
+ *d++ = 0;
+ *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++ = 0;
+ #endif
+ }
+}
+
+void rgb16tobgr24(const uint8_t *src, uint8_t *dst, long src_size)
+{
+ const uint16_t *end;
+ uint8_t *d = (uint8_t *)dst;
+ const uint16_t *s = (const uint16_t *)src;
+ end = s + src_size/2;
+ while(s < end)
+ {
+ register uint16_t bgr;
+ bgr = *s++;
+ *d++ = (bgr&0xF800)>>8;
+ *d++ = (bgr&0x7E0)>>3;
+ *d++ = (bgr&0x1F)<<3;
+ }
+}
+
+void rgb16tobgr16(const uint8_t *src, uint8_t *dst, long src_size)
+{
+ long i;
+ long num_pixels = src_size >> 1;
+
+ for(i=0; i<num_pixels; i++)
+ {
+ unsigned b,g,r;
+ register uint16_t rgb;
+ rgb = src[2*i];
+ r = rgb&0x1F;
+ g = (rgb&0x7E0)>>5;
+ b = (rgb&0xF800)>>11;
+ dst[2*i] = (b&0x1F) | ((g&0x3F)<<5) | ((r&0x1F)<<11);
+ }
+}
+
+void rgb16tobgr15(const uint8_t *src, uint8_t *dst, long src_size)
+{
+ long i;
+ long num_pixels = src_size >> 1;
+
+ for(i=0; i<num_pixels; i++)
+ {
+ unsigned b,g,r;
+ register uint16_t rgb;
+ rgb = src[2*i];
+ r = rgb&0x1F;
+ g = (rgb&0x7E0)>>5;
+ b = (rgb&0xF800)>>11;
+ dst[2*i] = (b&0x1F) | ((g&0x1F)<<5) | ((r&0x1F)<<10);
+ }
+}
+
+void rgb15tobgr32(const uint8_t *src, uint8_t *dst, long src_size)
+{
+ const uint16_t *end;
+ uint8_t *d = (uint8_t *)dst;
+ const uint16_t *s = (const uint16_t *)src;
+ end = s + src_size/2;
+ while(s < end)
+ {
+ register uint16_t bgr;
+ bgr = *s++;
+ #ifdef WORDS_BIGENDIAN
+ *d++ = 0;
+ *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++ = 0;
+ #endif
+ }
+}
+
+void rgb15tobgr24(const uint8_t *src, uint8_t *dst, long src_size)
+{
+ const uint16_t *end;
+ uint8_t *d = (uint8_t *)dst;
+ const uint16_t *s = (uint16_t *)src;
+ end = s + src_size/2;
+ while(s < end)
+ {
+ register uint16_t bgr;
+ bgr = *s++;
+ *d++ = (bgr&0x7C00)>>7;
+ *d++ = (bgr&0x3E0)>>2;
+ *d++ = (bgr&0x1F)<<3;
+ }
+}
+
+void rgb15tobgr16(const uint8_t *src, uint8_t *dst, long src_size)
+{
+ long i;
+ long num_pixels = src_size >> 1;
+
+ for(i=0; i<num_pixels; i++)
+ {
+ unsigned b,g,r;
+ register uint16_t rgb;
+ rgb = src[2*i];
+ r = rgb&0x1F;
+ g = (rgb&0x3E0)>>5;
+ b = (rgb&0x7C00)>>10;
+ dst[2*i] = (b&0x1F) | ((g&0x3F)<<5) | ((r&0x1F)<<11);
+ }
+}
+
+void rgb15tobgr15(const uint8_t *src, uint8_t *dst, long src_size)
+{
+ long i;
+ long num_pixels = src_size >> 1;
+
+ for(i=0; i<num_pixels; i++)
+ {
+ unsigned b,g,r;
+ register uint16_t rgb;
+ rgb = src[2*i];
+ r = rgb&0x1F;
+ g = (rgb&0x3E0)>>5;
+ b = (rgb&0x7C00)>>10;
+ dst[2*i] = (b&0x1F) | ((g&0x1F)<<5) | ((r&0x1F)<<10);
+ }
+}
+
+void rgb8tobgr8(const uint8_t *src, uint8_t *dst, long src_size)
+{
+ long i;
+ long num_pixels = src_size;
+ for(i=0; i<num_pixels; i++)
+ {
+ unsigned b,g,r;
+ register uint8_t rgb;
+ rgb = src[i];
+ r = (rgb&0x07);
+ g = (rgb&0x38)>>3;
+ b = (rgb&0xC0)>>6;
+ dst[i] = ((b<<1)&0x07) | ((g&0x07)<<3) | ((r&0x03)<<6);
+ }
+}
diff --git a/contrib/ffmpeg/libswscale/rgb2rgb.h b/contrib/ffmpeg/libswscale/rgb2rgb.h
new file mode 100644
index 000000000..4b5cc0a69
--- /dev/null
+++ b/contrib/ffmpeg/libswscale/rgb2rgb.h
@@ -0,0 +1,147 @@
+/*
+ *
+ * rgb2rgb.h, Software RGB to RGB convertor
+ * pluralize by Software PAL8 to RGB convertor
+ * Software YUV to YUV convertor
+ * Software YUV to RGB convertor
+ * Written by Nick Kurshev.
+ * palette & YUV & runtime CPU stuff by Michael (michaelni@gmx.at)
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef RGB2RGB_INCLUDED
+#define RGB2RGB_INCLUDED
+
+// Note: do not fix the dependence on stdio.h
+
+/* A full collection of rgb to rgb(bgr) convertors */
+extern void (*rgb24to32)(const uint8_t *src,uint8_t *dst,long src_size);
+extern void (*rgb24to16)(const uint8_t *src,uint8_t *dst,long src_size);
+extern void (*rgb24to15)(const uint8_t *src,uint8_t *dst,long src_size);
+extern void (*rgb32to24)(const uint8_t *src,uint8_t *dst,long src_size);
+extern void (*rgb32to16)(const uint8_t *src,uint8_t *dst,long src_size);
+extern void (*rgb32to15)(const uint8_t *src,uint8_t *dst,long src_size);
+extern void (*rgb15to16)(const uint8_t *src,uint8_t *dst,long src_size);
+extern void (*rgb15to24)(const uint8_t *src,uint8_t *dst,long src_size);
+extern void (*rgb15to32)(const uint8_t *src,uint8_t *dst,long src_size);
+extern void (*rgb16to15)(const uint8_t *src,uint8_t *dst,long src_size);
+extern void (*rgb16to24)(const uint8_t *src,uint8_t *dst,long src_size);
+extern void (*rgb16to32)(const uint8_t *src,uint8_t *dst,long src_size);
+extern void (*rgb24tobgr24)(const uint8_t *src, uint8_t *dst, long src_size);
+extern void (*rgb24tobgr16)(const uint8_t *src, uint8_t *dst, long src_size);
+extern void (*rgb24tobgr15)(const uint8_t *src, uint8_t *dst, long src_size);
+extern void (*rgb32tobgr32)(const uint8_t *src, uint8_t *dst, long src_size);
+extern void (*rgb32tobgr16)(const uint8_t *src, uint8_t *dst, long src_size);
+extern void (*rgb32tobgr15)(const uint8_t *src, uint8_t *dst, long src_size);
+
+extern void rgb24tobgr32(const uint8_t *src, uint8_t *dst, long src_size);
+extern void rgb32tobgr24(const uint8_t *src, uint8_t *dst, long src_size);
+extern void rgb16tobgr32(const uint8_t *src, uint8_t *dst, long src_size);
+extern void rgb16tobgr24(const uint8_t *src, uint8_t *dst, long src_size);
+extern void rgb16tobgr16(const uint8_t *src, uint8_t *dst, long src_size);
+extern void rgb16tobgr15(const uint8_t *src, uint8_t *dst, long src_size);
+extern void rgb15tobgr32(const uint8_t *src, uint8_t *dst, long src_size);
+extern void rgb15tobgr24(const uint8_t *src, uint8_t *dst, long src_size);
+extern void rgb15tobgr16(const uint8_t *src, uint8_t *dst, long src_size);
+extern void rgb15tobgr15(const uint8_t *src, uint8_t *dst, long src_size);
+extern void rgb8tobgr8(const uint8_t *src, uint8_t *dst, long src_size);
+
+
+extern void palette8torgb32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
+extern void palette8tobgr32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
+extern void palette8torgb24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
+extern void palette8tobgr24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
+extern void palette8torgb16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
+extern void palette8tobgr16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
+extern void palette8torgb15(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
+extern void palette8tobgr15(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
+
+/**
+ *
+ * height should be a multiple of 2 and width should be a multiple of 16 (if this is a
+ * problem for anyone then tell me, and ill fix it)
+ * chrominance data is only taken from every secound line others are ignored FIXME write HQ version
+ */
+//void uyvytoyv12(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
+
+/**
+ *
+ * height should be a multiple of 2 and width should be a multiple of 16 (if this is a
+ * problem for anyone then tell me, and ill fix it)
+ */
+extern void (*yv12toyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
+ long width, long height,
+ long lumStride, long chromStride, long dstStride);
+
+/**
+ *
+ * width should be a multiple of 16
+ */
+extern void (*yuv422ptoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
+ long width, long height,
+ long lumStride, long chromStride, long dstStride);
+
+/**
+ *
+ * height should be a multiple of 2 and width should be a multiple of 16 (if this is a
+ * problem for anyone then tell me, and ill fix it)
+ */
+extern void (*yuy2toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
+ long width, long height,
+ long lumStride, long chromStride, long srcStride);
+
+/**
+ *
+ * height should be a multiple of 2 and width should be a multiple of 16 (if this is a
+ * problem for anyone then tell me, and ill fix it)
+ */
+extern void (*yv12touyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
+ long width, long height,
+ long lumStride, long chromStride, long dstStride);
+
+/**
+ *
+ * height should be a multiple of 2 and width should be a multiple of 2 (if this is a
+ * problem for anyone then tell me, and ill fix it)
+ * chrominance data is only taken from every secound line others are ignored FIXME write HQ version
+ */
+extern void (*rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
+ long width, long height,
+ long lumStride, long chromStride, long srcStride);
+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,
+ long width, long height, long src1Stride,
+ long src2Stride, long dstStride);
+
+extern void (*vu9_to_vu12)(const uint8_t *src1, const uint8_t *src2,
+ uint8_t *dst1, uint8_t *dst2,
+ long width, long height,
+ long srcStride1, long srcStride2,
+ long dstStride1, long dstStride2);
+
+extern void (*yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2, const uint8_t *src3,
+ uint8_t *dst,
+ long width, long height,
+ long srcStride1, long srcStride2,
+ long srcStride3, long dstStride);
+
+void sws_rgb2rgb_init(int flags);
+
+#endif
diff --git a/contrib/ffmpeg/libswscale/rgb2rgb_template.c b/contrib/ffmpeg/libswscale/rgb2rgb_template.c
new file mode 100644
index 000000000..d9511c955
--- /dev/null
+++ b/contrib/ffmpeg/libswscale/rgb2rgb_template.c
@@ -0,0 +1,2688 @@
+/*
+ *
+ * rgb2rgb.c, Software RGB to RGB convertor
+ * pluralize by Software PAL8 to RGB convertor
+ * Software YUV to YUV convertor
+ * Software YUV to RGB convertor
+ * Written by Nick Kurshev.
+ * palette & YUV & runtime CPU stuff by Michael (michaelni@gmx.at)
+ * lot of big-endian byteorder fixes by Alex Beregszaszi
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * the C code (not assembly, mmx, ...) of this file can be used
+ * under the LGPL license too
+ */
+
+#include <stddef.h>
+#include <inttypes.h> /* for __WORDSIZE */
+
+#ifndef __WORDSIZE
+// #warning You have misconfigured system and probably will lose performance!
+#define __WORDSIZE MP_WORDSIZE
+#endif
+
+#undef PREFETCH
+#undef MOVNTQ
+#undef EMMS
+#undef SFENCE
+#undef MMREG_SIZE
+#undef PREFETCHW
+#undef PAVGB
+
+#ifdef HAVE_SSE2
+#define MMREG_SIZE 16
+#else
+#define MMREG_SIZE 8
+#endif
+
+#ifdef HAVE_3DNOW
+#define PREFETCH "prefetch"
+#define PREFETCHW "prefetchw"
+#define PAVGB "pavgusb"
+#elif defined ( HAVE_MMX2 )
+#define PREFETCH "prefetchnta"
+#define PREFETCHW "prefetcht0"
+#define PAVGB "pavgb"
+#else
+#ifdef __APPLE__
+#define PREFETCH "#"
+#define PREFETCHW "#"
+#else
+#define PREFETCH " # nop"
+#define PREFETCHW " # nop"
+#endif
+#endif
+
+#ifdef HAVE_3DNOW
+/* On K6 femms is faster of emms. On K7 femms is directly mapped on emms. */
+#define EMMS "femms"
+#else
+#define EMMS "emms"
+#endif
+
+#ifdef HAVE_MMX2
+#define MOVNTQ "movntq"
+#define SFENCE "sfence"
+#else
+#define MOVNTQ "movq"
+#define SFENCE " # nop"
+#endif
+
+static inline void RENAME(rgb24to32)(const uint8_t *src,uint8_t *dst,long src_size)
+{
+ uint8_t *dest = dst;
+ const uint8_t *s = src;
+ const uint8_t *end;
+#ifdef HAVE_MMX
+ const uint8_t *mm_end;
+#endif
+ end = s + src_size;
+#ifdef HAVE_MMX
+ __asm __volatile(PREFETCH" %0"::"m"(*s):"memory");
+ mm_end = end - 23;
+ __asm __volatile("movq %0, %%mm7"::"m"(mask32):"memory");
+ while(s < mm_end)
+ {
+ __asm __volatile(
+ PREFETCH" 32%1\n\t"
+ "movd %1, %%mm0\n\t"
+ "punpckldq 3%1, %%mm0\n\t"
+ "movd 6%1, %%mm1\n\t"
+ "punpckldq 9%1, %%mm1\n\t"
+ "movd 12%1, %%mm2\n\t"
+ "punpckldq 15%1, %%mm2\n\t"
+ "movd 18%1, %%mm3\n\t"
+ "punpckldq 21%1, %%mm3\n\t"
+ "pand %%mm7, %%mm0\n\t"
+ "pand %%mm7, %%mm1\n\t"
+ "pand %%mm7, %%mm2\n\t"
+ "pand %%mm7, %%mm3\n\t"
+ MOVNTQ" %%mm0, %0\n\t"
+ MOVNTQ" %%mm1, 8%0\n\t"
+ MOVNTQ" %%mm2, 16%0\n\t"
+ MOVNTQ" %%mm3, 24%0"
+ :"=m"(*dest)
+ :"m"(*s)
+ :"memory");
+ dest += 32;
+ s += 24;
+ }
+ __asm __volatile(SFENCE:::"memory");
+ __asm __volatile(EMMS:::"memory");
+#endif
+ while(s < end)
+ {
+#ifdef WORDS_BIGENDIAN
+ /* RGB24 (= R,G,B) -> RGB32 (= A,B,G,R) */
+ *dest++ = 0;
+ *dest++ = s[2];
+ *dest++ = s[1];
+ *dest++ = s[0];
+ s+=3;
+#else
+ *dest++ = *s++;
+ *dest++ = *s++;
+ *dest++ = *s++;
+ *dest++ = 0;
+#endif
+ }
+}
+
+static inline void RENAME(rgb32to24)(const uint8_t *src,uint8_t *dst,long src_size)
+{
+ uint8_t *dest = dst;
+ const uint8_t *s = src;
+ const uint8_t *end;
+#ifdef HAVE_MMX
+ const uint8_t *mm_end;
+#endif
+ end = s + src_size;
+#ifdef HAVE_MMX
+ __asm __volatile(PREFETCH" %0"::"m"(*s):"memory");
+ mm_end = end - 31;
+ while(s < mm_end)
+ {
+ __asm __volatile(
+ PREFETCH" 32%1\n\t"
+ "movq %1, %%mm0\n\t"
+ "movq 8%1, %%mm1\n\t"
+ "movq 16%1, %%mm4\n\t"
+ "movq 24%1, %%mm5\n\t"
+ "movq %%mm0, %%mm2\n\t"
+ "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"
+ :"=m"(*dest)
+ :"m"(*s),"m"(mask24l),
+ "m"(mask24h),"m"(mask24hh),"m"(mask24hhh),"m"(mask24hhhh)
+ :"memory");
+ dest += 24;
+ s += 32;
+ }
+ __asm __volatile(SFENCE:::"memory");
+ __asm __volatile(EMMS:::"memory");
+#endif
+ while(s < end)
+ {
+#ifdef WORDS_BIGENDIAN
+ /* RGB32 (= A,B,G,R) -> RGB24 (= R,G,B) */
+ s++;
+ dest[2] = *s++;
+ dest[1] = *s++;
+ dest[0] = *s++;
+ dest += 3;
+#else
+ *dest++ = *s++;
+ *dest++ = *s++;
+ *dest++ = *s++;
+ s++;
+#endif
+ }
+}
+
+/*
+ Original by Strepto/Astral
+ ported to gcc & bugfixed : A'rpi
+ MMX2, 3DNOW optimization by Nick Kurshev
+ 32bit c version, and and&add trick by Michael Niedermayer
+*/
+static inline void RENAME(rgb15to16)(const uint8_t *src,uint8_t *dst,long src_size)
+{
+ register const uint8_t* s=src;
+ register uint8_t* d=dst;
+ register const uint8_t *end;
+ const uint8_t *mm_end;
+ end = s + src_size;
+#ifdef HAVE_MMX
+ __asm __volatile(PREFETCH" %0"::"m"(*s));
+ __asm __volatile("movq %0, %%mm4"::"m"(mask15s));
+ mm_end = end - 15;
+ while(s<mm_end)
+ {
+ __asm __volatile(
+ PREFETCH" 32%1\n\t"
+ "movq %1, %%mm0\n\t"
+ "movq 8%1, %%mm2\n\t"
+ "movq %%mm0, %%mm1\n\t"
+ "movq %%mm2, %%mm3\n\t"
+ "pand %%mm4, %%mm0\n\t"
+ "pand %%mm4, %%mm2\n\t"
+ "paddw %%mm1, %%mm0\n\t"
+ "paddw %%mm3, %%mm2\n\t"
+ MOVNTQ" %%mm0, %0\n\t"
+ MOVNTQ" %%mm2, 8%0"
+ :"=m"(*d)
+ :"m"(*s)
+ );
+ d+=16;
+ s+=16;
+ }
+ __asm __volatile(SFENCE:::"memory");
+ __asm __volatile(EMMS:::"memory");
+#endif
+ mm_end = end - 3;
+ while(s < mm_end)
+ {
+ register unsigned x= *((uint32_t *)s);
+ *((uint32_t *)d) = (x&0x7FFF7FFF) + (x&0x7FE07FE0);
+ d+=4;
+ s+=4;
+ }
+ if(s < end)
+ {
+ register unsigned short x= *((uint16_t *)s);
+ *((uint16_t *)d) = (x&0x7FFF) + (x&0x7FE0);
+ }
+}
+
+static inline void RENAME(rgb16to15)(const uint8_t *src,uint8_t *dst,long src_size)
+{
+ register const uint8_t* s=src;
+ register uint8_t* d=dst;
+ register const uint8_t *end;
+ const uint8_t *mm_end;
+ end = s + src_size;
+#ifdef HAVE_MMX
+ __asm __volatile(PREFETCH" %0"::"m"(*s));
+ __asm __volatile("movq %0, %%mm7"::"m"(mask15rg));
+ __asm __volatile("movq %0, %%mm6"::"m"(mask15b));
+ mm_end = end - 15;
+ while(s<mm_end)
+ {
+ __asm __volatile(
+ PREFETCH" 32%1\n\t"
+ "movq %1, %%mm0\n\t"
+ "movq 8%1, %%mm2\n\t"
+ "movq %%mm0, %%mm1\n\t"
+ "movq %%mm2, %%mm3\n\t"
+ "psrlq $1, %%mm0\n\t"
+ "psrlq $1, %%mm2\n\t"
+ "pand %%mm7, %%mm0\n\t"
+ "pand %%mm7, %%mm2\n\t"
+ "pand %%mm6, %%mm1\n\t"
+ "pand %%mm6, %%mm3\n\t"
+ "por %%mm1, %%mm0\n\t"
+ "por %%mm3, %%mm2\n\t"
+ MOVNTQ" %%mm0, %0\n\t"
+ MOVNTQ" %%mm2, 8%0"
+ :"=m"(*d)
+ :"m"(*s)
+ );
+ d+=16;
+ s+=16;
+ }
+ __asm __volatile(SFENCE:::"memory");
+ __asm __volatile(EMMS:::"memory");
+#endif
+ mm_end = end - 3;
+ while(s < mm_end)
+ {
+ register uint32_t x= *((uint32_t *)s);
+ *((uint32_t *)d) = ((x>>1)&0x7FE07FE0) | (x&0x001F001F);
+ s+=4;
+ d+=4;
+ }
+ if(s < end)
+ {
+ register uint16_t x= *((uint16_t *)s);
+ *((uint16_t *)d) = ((x>>1)&0x7FE0) | (x&0x001F);
+ s+=2;
+ d+=2;
+ }
+}
+
+static inline void RENAME(rgb32to16)(const uint8_t *src, uint8_t *dst, long src_size)
+{
+ const uint8_t *s = src;
+ const uint8_t *end;
+#ifdef HAVE_MMX
+ const uint8_t *mm_end;
+#endif
+ uint16_t *d = (uint16_t *)dst;
+ end = s + src_size;
+#ifdef HAVE_MMX
+ mm_end = end - 15;
+#if 1 //is faster only if multiplies are reasonable fast (FIXME figure out on which cpus this is faster, on Athlon its slightly faster)
+ asm volatile(
+ "movq %3, %%mm5 \n\t"
+ "movq %4, %%mm6 \n\t"
+ "movq %5, %%mm7 \n\t"
+ ASMALIGN(4)
+ "1: \n\t"
+ PREFETCH" 32(%1) \n\t"
+ "movd (%1), %%mm0 \n\t"
+ "movd 4(%1), %%mm3 \n\t"
+ "punpckldq 8(%1), %%mm0 \n\t"
+ "punpckldq 12(%1), %%mm3 \n\t"
+ "movq %%mm0, %%mm1 \n\t"
+ "movq %%mm3, %%mm4 \n\t"
+ "pand %%mm6, %%mm0 \n\t"
+ "pand %%mm6, %%mm3 \n\t"
+ "pmaddwd %%mm7, %%mm0 \n\t"
+ "pmaddwd %%mm7, %%mm3 \n\t"
+ "pand %%mm5, %%mm1 \n\t"
+ "pand %%mm5, %%mm4 \n\t"
+ "por %%mm1, %%mm0 \n\t"
+ "por %%mm4, %%mm3 \n\t"
+ "psrld $5, %%mm0 \n\t"
+ "pslld $11, %%mm3 \n\t"
+ "por %%mm3, %%mm0 \n\t"
+ MOVNTQ" %%mm0, (%0) \n\t"
+ "add $16, %1 \n\t"
+ "add $8, %0 \n\t"
+ "cmp %2, %1 \n\t"
+ " jb 1b \n\t"
+ : "+r" (d), "+r"(s)
+ : "r" (mm_end), "m" (mask3216g), "m" (mask3216br), "m" (mul3216)
+ );
+#else
+ __asm __volatile(PREFETCH" %0"::"m"(*src):"memory");
+ __asm __volatile(
+ "movq %0, %%mm7\n\t"
+ "movq %1, %%mm6\n\t"
+ ::"m"(red_16mask),"m"(green_16mask));
+ while(s < mm_end)
+ {
+ __asm __volatile(
+ PREFETCH" 32%1\n\t"
+ "movd %1, %%mm0\n\t"
+ "movd 4%1, %%mm3\n\t"
+ "punpckldq 8%1, %%mm0\n\t"
+ "punpckldq 12%1, %%mm3\n\t"
+ "movq %%mm0, %%mm1\n\t"
+ "movq %%mm0, %%mm2\n\t"
+ "movq %%mm3, %%mm4\n\t"
+ "movq %%mm3, %%mm5\n\t"
+ "psrlq $3, %%mm0\n\t"
+ "psrlq $3, %%mm3\n\t"
+ "pand %2, %%mm0\n\t"
+ "pand %2, %%mm3\n\t"
+ "psrlq $5, %%mm1\n\t"
+ "psrlq $5, %%mm4\n\t"
+ "pand %%mm6, %%mm1\n\t"
+ "pand %%mm6, %%mm4\n\t"
+ "psrlq $8, %%mm2\n\t"
+ "psrlq $8, %%mm5\n\t"
+ "pand %%mm7, %%mm2\n\t"
+ "pand %%mm7, %%mm5\n\t"
+ "por %%mm1, %%mm0\n\t"
+ "por %%mm4, %%mm3\n\t"
+ "por %%mm2, %%mm0\n\t"
+ "por %%mm5, %%mm3\n\t"
+ "psllq $16, %%mm3\n\t"
+ "por %%mm3, %%mm0\n\t"
+ MOVNTQ" %%mm0, %0\n\t"
+ :"=m"(*d):"m"(*s),"m"(blue_16mask):"memory");
+ d += 4;
+ s += 16;
+ }
+#endif
+ __asm __volatile(SFENCE:::"memory");
+ __asm __volatile(EMMS:::"memory");
+#endif
+ while(s < end)
+ {
+ register int rgb = *(uint32_t*)s; s += 4;
+ *d++ = ((rgb&0xFF)>>3) + ((rgb&0xFC00)>>5) + ((rgb&0xF80000)>>8);
+ }
+}
+
+static inline void RENAME(rgb32tobgr16)(const uint8_t *src, uint8_t *dst, long src_size)
+{
+ const uint8_t *s = src;
+ const uint8_t *end;
+#ifdef HAVE_MMX
+ const uint8_t *mm_end;
+#endif
+ uint16_t *d = (uint16_t *)dst;
+ end = s + src_size;
+#ifdef HAVE_MMX
+ __asm __volatile(PREFETCH" %0"::"m"(*src):"memory");
+ __asm __volatile(
+ "movq %0, %%mm7\n\t"
+ "movq %1, %%mm6\n\t"
+ ::"m"(red_16mask),"m"(green_16mask));
+ mm_end = end - 15;
+ while(s < mm_end)
+ {
+ __asm __volatile(
+ PREFETCH" 32%1\n\t"
+ "movd %1, %%mm0\n\t"
+ "movd 4%1, %%mm3\n\t"
+ "punpckldq 8%1, %%mm0\n\t"
+ "punpckldq 12%1, %%mm3\n\t"
+ "movq %%mm0, %%mm1\n\t"
+ "movq %%mm0, %%mm2\n\t"
+ "movq %%mm3, %%mm4\n\t"
+ "movq %%mm3, %%mm5\n\t"
+ "psllq $8, %%mm0\n\t"
+ "psllq $8, %%mm3\n\t"
+ "pand %%mm7, %%mm0\n\t"
+ "pand %%mm7, %%mm3\n\t"
+ "psrlq $5, %%mm1\n\t"
+ "psrlq $5, %%mm4\n\t"
+ "pand %%mm6, %%mm1\n\t"
+ "pand %%mm6, %%mm4\n\t"
+ "psrlq $19, %%mm2\n\t"
+ "psrlq $19, %%mm5\n\t"
+ "pand %2, %%mm2\n\t"
+ "pand %2, %%mm5\n\t"
+ "por %%mm1, %%mm0\n\t"
+ "por %%mm4, %%mm3\n\t"
+ "por %%mm2, %%mm0\n\t"
+ "por %%mm5, %%mm3\n\t"
+ "psllq $16, %%mm3\n\t"
+ "por %%mm3, %%mm0\n\t"
+ MOVNTQ" %%mm0, %0\n\t"
+ :"=m"(*d):"m"(*s),"m"(blue_16mask):"memory");
+ d += 4;
+ s += 16;
+ }
+ __asm __volatile(SFENCE:::"memory");
+ __asm __volatile(EMMS:::"memory");
+#endif
+ while(s < end)
+ {
+ register int rgb = *(uint32_t*)s; s += 4;
+ *d++ = ((rgb&0xF8)<<8) + ((rgb&0xFC00)>>5) + ((rgb&0xF80000)>>19);
+ }
+}
+
+static inline void RENAME(rgb32to15)(const uint8_t *src, uint8_t *dst, long src_size)
+{
+ const uint8_t *s = src;
+ const uint8_t *end;
+#ifdef HAVE_MMX
+ const uint8_t *mm_end;
+#endif
+ uint16_t *d = (uint16_t *)dst;
+ end = s + src_size;
+#ifdef HAVE_MMX
+ mm_end = end - 15;
+#if 1 //is faster only if multiplies are reasonable fast (FIXME figure out on which cpus this is faster, on Athlon its slightly faster)
+ asm volatile(
+ "movq %3, %%mm5 \n\t"
+ "movq %4, %%mm6 \n\t"
+ "movq %5, %%mm7 \n\t"
+ ASMALIGN(4)
+ "1: \n\t"
+ PREFETCH" 32(%1) \n\t"
+ "movd (%1), %%mm0 \n\t"
+ "movd 4(%1), %%mm3 \n\t"
+ "punpckldq 8(%1), %%mm0 \n\t"
+ "punpckldq 12(%1), %%mm3 \n\t"
+ "movq %%mm0, %%mm1 \n\t"
+ "movq %%mm3, %%mm4 \n\t"
+ "pand %%mm6, %%mm0 \n\t"
+ "pand %%mm6, %%mm3 \n\t"
+ "pmaddwd %%mm7, %%mm0 \n\t"
+ "pmaddwd %%mm7, %%mm3 \n\t"
+ "pand %%mm5, %%mm1 \n\t"
+ "pand %%mm5, %%mm4 \n\t"
+ "por %%mm1, %%mm0 \n\t"
+ "por %%mm4, %%mm3 \n\t"
+ "psrld $6, %%mm0 \n\t"
+ "pslld $10, %%mm3 \n\t"
+ "por %%mm3, %%mm0 \n\t"
+ MOVNTQ" %%mm0, (%0) \n\t"
+ "add $16, %1 \n\t"
+ "add $8, %0 \n\t"
+ "cmp %2, %1 \n\t"
+ " jb 1b \n\t"
+ : "+r" (d), "+r"(s)
+ : "r" (mm_end), "m" (mask3215g), "m" (mask3216br), "m" (mul3215)
+ );
+#else
+ __asm __volatile(PREFETCH" %0"::"m"(*src):"memory");
+ __asm __volatile(
+ "movq %0, %%mm7\n\t"
+ "movq %1, %%mm6\n\t"
+ ::"m"(red_15mask),"m"(green_15mask));
+ while(s < mm_end)
+ {
+ __asm __volatile(
+ PREFETCH" 32%1\n\t"
+ "movd %1, %%mm0\n\t"
+ "movd 4%1, %%mm3\n\t"
+ "punpckldq 8%1, %%mm0\n\t"
+ "punpckldq 12%1, %%mm3\n\t"
+ "movq %%mm0, %%mm1\n\t"
+ "movq %%mm0, %%mm2\n\t"
+ "movq %%mm3, %%mm4\n\t"
+ "movq %%mm3, %%mm5\n\t"
+ "psrlq $3, %%mm0\n\t"
+ "psrlq $3, %%mm3\n\t"
+ "pand %2, %%mm0\n\t"
+ "pand %2, %%mm3\n\t"
+ "psrlq $6, %%mm1\n\t"
+ "psrlq $6, %%mm4\n\t"
+ "pand %%mm6, %%mm1\n\t"
+ "pand %%mm6, %%mm4\n\t"
+ "psrlq $9, %%mm2\n\t"
+ "psrlq $9, %%mm5\n\t"
+ "pand %%mm7, %%mm2\n\t"
+ "pand %%mm7, %%mm5\n\t"
+ "por %%mm1, %%mm0\n\t"
+ "por %%mm4, %%mm3\n\t"
+ "por %%mm2, %%mm0\n\t"
+ "por %%mm5, %%mm3\n\t"
+ "psllq $16, %%mm3\n\t"
+ "por %%mm3, %%mm0\n\t"
+ MOVNTQ" %%mm0, %0\n\t"
+ :"=m"(*d):"m"(*s),"m"(blue_15mask):"memory");
+ d += 4;
+ s += 16;
+ }
+#endif
+ __asm __volatile(SFENCE:::"memory");
+ __asm __volatile(EMMS:::"memory");
+#endif
+ while(s < end)
+ {
+ register int rgb = *(uint32_t*)s; s += 4;
+ *d++ = ((rgb&0xFF)>>3) + ((rgb&0xF800)>>6) + ((rgb&0xF80000)>>9);
+ }
+}
+
+static inline void RENAME(rgb32tobgr15)(const uint8_t *src, uint8_t *dst, long src_size)
+{
+ const uint8_t *s = src;
+ const uint8_t *end;
+#ifdef HAVE_MMX
+ const uint8_t *mm_end;
+#endif
+ uint16_t *d = (uint16_t *)dst;
+ end = s + src_size;
+#ifdef HAVE_MMX
+ __asm __volatile(PREFETCH" %0"::"m"(*src):"memory");
+ __asm __volatile(
+ "movq %0, %%mm7\n\t"
+ "movq %1, %%mm6\n\t"
+ ::"m"(red_15mask),"m"(green_15mask));
+ mm_end = end - 15;
+ while(s < mm_end)
+ {
+ __asm __volatile(
+ PREFETCH" 32%1\n\t"
+ "movd %1, %%mm0\n\t"
+ "movd 4%1, %%mm3\n\t"
+ "punpckldq 8%1, %%mm0\n\t"
+ "punpckldq 12%1, %%mm3\n\t"
+ "movq %%mm0, %%mm1\n\t"
+ "movq %%mm0, %%mm2\n\t"
+ "movq %%mm3, %%mm4\n\t"
+ "movq %%mm3, %%mm5\n\t"
+ "psllq $7, %%mm0\n\t"
+ "psllq $7, %%mm3\n\t"
+ "pand %%mm7, %%mm0\n\t"
+ "pand %%mm7, %%mm3\n\t"
+ "psrlq $6, %%mm1\n\t"
+ "psrlq $6, %%mm4\n\t"
+ "pand %%mm6, %%mm1\n\t"
+ "pand %%mm6, %%mm4\n\t"
+ "psrlq $19, %%mm2\n\t"
+ "psrlq $19, %%mm5\n\t"
+ "pand %2, %%mm2\n\t"
+ "pand %2, %%mm5\n\t"
+ "por %%mm1, %%mm0\n\t"
+ "por %%mm4, %%mm3\n\t"
+ "por %%mm2, %%mm0\n\t"
+ "por %%mm5, %%mm3\n\t"
+ "psllq $16, %%mm3\n\t"
+ "por %%mm3, %%mm0\n\t"
+ MOVNTQ" %%mm0, %0\n\t"
+ :"=m"(*d):"m"(*s),"m"(blue_15mask):"memory");
+ d += 4;
+ s += 16;
+ }
+ __asm __volatile(SFENCE:::"memory");
+ __asm __volatile(EMMS:::"memory");
+#endif
+ while(s < end)
+ {
+ register int rgb = *(uint32_t*)s; s += 4;
+ *d++ = ((rgb&0xF8)<<7) + ((rgb&0xF800)>>6) + ((rgb&0xF80000)>>19);
+ }
+}
+
+static inline void RENAME(rgb24to16)(const uint8_t *src, uint8_t *dst, long src_size)
+{
+ const uint8_t *s = src;
+ const uint8_t *end;
+#ifdef HAVE_MMX
+ const uint8_t *mm_end;
+#endif
+ uint16_t *d = (uint16_t *)dst;
+ end = s + src_size;
+#ifdef HAVE_MMX
+ __asm __volatile(PREFETCH" %0"::"m"(*src):"memory");
+ __asm __volatile(
+ "movq %0, %%mm7\n\t"
+ "movq %1, %%mm6\n\t"
+ ::"m"(red_16mask),"m"(green_16mask));
+ mm_end = end - 11;
+ while(s < mm_end)
+ {
+ __asm __volatile(
+ PREFETCH" 32%1\n\t"
+ "movd %1, %%mm0\n\t"
+ "movd 3%1, %%mm3\n\t"
+ "punpckldq 6%1, %%mm0\n\t"
+ "punpckldq 9%1, %%mm3\n\t"
+ "movq %%mm0, %%mm1\n\t"
+ "movq %%mm0, %%mm2\n\t"
+ "movq %%mm3, %%mm4\n\t"
+ "movq %%mm3, %%mm5\n\t"
+ "psrlq $3, %%mm0\n\t"
+ "psrlq $3, %%mm3\n\t"
+ "pand %2, %%mm0\n\t"
+ "pand %2, %%mm3\n\t"
+ "psrlq $5, %%mm1\n\t"
+ "psrlq $5, %%mm4\n\t"
+ "pand %%mm6, %%mm1\n\t"
+ "pand %%mm6, %%mm4\n\t"
+ "psrlq $8, %%mm2\n\t"
+ "psrlq $8, %%mm5\n\t"
+ "pand %%mm7, %%mm2\n\t"
+ "pand %%mm7, %%mm5\n\t"
+ "por %%mm1, %%mm0\n\t"
+ "por %%mm4, %%mm3\n\t"
+ "por %%mm2, %%mm0\n\t"
+ "por %%mm5, %%mm3\n\t"
+ "psllq $16, %%mm3\n\t"
+ "por %%mm3, %%mm0\n\t"
+ MOVNTQ" %%mm0, %0\n\t"
+ :"=m"(*d):"m"(*s),"m"(blue_16mask):"memory");
+ d += 4;
+ s += 12;
+ }
+ __asm __volatile(SFENCE:::"memory");
+ __asm __volatile(EMMS:::"memory");
+#endif
+ while(s < end)
+ {
+ const int b= *s++;
+ const int g= *s++;
+ const int r= *s++;
+ *d++ = (b>>3) | ((g&0xFC)<<3) | ((r&0xF8)<<8);
+ }
+}
+
+static inline void RENAME(rgb24tobgr16)(const uint8_t *src, uint8_t *dst, long src_size)
+{
+ const uint8_t *s = src;
+ const uint8_t *end;
+#ifdef HAVE_MMX
+ const uint8_t *mm_end;
+#endif
+ uint16_t *d = (uint16_t *)dst;
+ end = s + src_size;
+#ifdef HAVE_MMX
+ __asm __volatile(PREFETCH" %0"::"m"(*src):"memory");
+ __asm __volatile(
+ "movq %0, %%mm7\n\t"
+ "movq %1, %%mm6\n\t"
+ ::"m"(red_16mask),"m"(green_16mask));
+ mm_end = end - 15;
+ while(s < mm_end)
+ {
+ __asm __volatile(
+ PREFETCH" 32%1\n\t"
+ "movd %1, %%mm0\n\t"
+ "movd 3%1, %%mm3\n\t"
+ "punpckldq 6%1, %%mm0\n\t"
+ "punpckldq 9%1, %%mm3\n\t"
+ "movq %%mm0, %%mm1\n\t"
+ "movq %%mm0, %%mm2\n\t"
+ "movq %%mm3, %%mm4\n\t"
+ "movq %%mm3, %%mm5\n\t"
+ "psllq $8, %%mm0\n\t"
+ "psllq $8, %%mm3\n\t"
+ "pand %%mm7, %%mm0\n\t"
+ "pand %%mm7, %%mm3\n\t"
+ "psrlq $5, %%mm1\n\t"
+ "psrlq $5, %%mm4\n\t"
+ "pand %%mm6, %%mm1\n\t"
+ "pand %%mm6, %%mm4\n\t"
+ "psrlq $19, %%mm2\n\t"
+ "psrlq $19, %%mm5\n\t"
+ "pand %2, %%mm2\n\t"
+ "pand %2, %%mm5\n\t"
+ "por %%mm1, %%mm0\n\t"
+ "por %%mm4, %%mm3\n\t"
+ "por %%mm2, %%mm0\n\t"
+ "por %%mm5, %%mm3\n\t"
+ "psllq $16, %%mm3\n\t"
+ "por %%mm3, %%mm0\n\t"
+ MOVNTQ" %%mm0, %0\n\t"
+ :"=m"(*d):"m"(*s),"m"(blue_16mask):"memory");
+ d += 4;
+ s += 12;
+ }
+ __asm __volatile(SFENCE:::"memory");
+ __asm __volatile(EMMS:::"memory");
+#endif
+ while(s < end)
+ {
+ const int r= *s++;
+ const int g= *s++;
+ const int b= *s++;
+ *d++ = (b>>3) | ((g&0xFC)<<3) | ((r&0xF8)<<8);
+ }
+}
+
+static inline void RENAME(rgb24to15)(const uint8_t *src, uint8_t *dst, long src_size)
+{
+ const uint8_t *s = src;
+ const uint8_t *end;
+#ifdef HAVE_MMX
+ const uint8_t *mm_end;
+#endif
+ uint16_t *d = (uint16_t *)dst;
+ end = s + src_size;
+#ifdef HAVE_MMX
+ __asm __volatile(PREFETCH" %0"::"m"(*src):"memory");
+ __asm __volatile(
+ "movq %0, %%mm7\n\t"
+ "movq %1, %%mm6\n\t"
+ ::"m"(red_15mask),"m"(green_15mask));
+ mm_end = end - 11;
+ while(s < mm_end)
+ {
+ __asm __volatile(
+ PREFETCH" 32%1\n\t"
+ "movd %1, %%mm0\n\t"
+ "movd 3%1, %%mm3\n\t"
+ "punpckldq 6%1, %%mm0\n\t"
+ "punpckldq 9%1, %%mm3\n\t"
+ "movq %%mm0, %%mm1\n\t"
+ "movq %%mm0, %%mm2\n\t"
+ "movq %%mm3, %%mm4\n\t"
+ "movq %%mm3, %%mm5\n\t"
+ "psrlq $3, %%mm0\n\t"
+ "psrlq $3, %%mm3\n\t"
+ "pand %2, %%mm0\n\t"
+ "pand %2, %%mm3\n\t"
+ "psrlq $6, %%mm1\n\t"
+ "psrlq $6, %%mm4\n\t"
+ "pand %%mm6, %%mm1\n\t"
+ "pand %%mm6, %%mm4\n\t"
+ "psrlq $9, %%mm2\n\t"
+ "psrlq $9, %%mm5\n\t"
+ "pand %%mm7, %%mm2\n\t"
+ "pand %%mm7, %%mm5\n\t"
+ "por %%mm1, %%mm0\n\t"
+ "por %%mm4, %%mm3\n\t"
+ "por %%mm2, %%mm0\n\t"
+ "por %%mm5, %%mm3\n\t"
+ "psllq $16, %%mm3\n\t"
+ "por %%mm3, %%mm0\n\t"
+ MOVNTQ" %%mm0, %0\n\t"
+ :"=m"(*d):"m"(*s),"m"(blue_15mask):"memory");
+ d += 4;
+ s += 12;
+ }
+ __asm __volatile(SFENCE:::"memory");
+ __asm __volatile(EMMS:::"memory");
+#endif
+ while(s < end)
+ {
+ const int b= *s++;
+ const int g= *s++;
+ const int r= *s++;
+ *d++ = (b>>3) | ((g&0xF8)<<2) | ((r&0xF8)<<7);
+ }
+}
+
+static inline void RENAME(rgb24tobgr15)(const uint8_t *src, uint8_t *dst, long src_size)
+{
+ const uint8_t *s = src;
+ const uint8_t *end;
+#ifdef HAVE_MMX
+ const uint8_t *mm_end;
+#endif
+ uint16_t *d = (uint16_t *)dst;
+ end = s + src_size;
+#ifdef HAVE_MMX
+ __asm __volatile(PREFETCH" %0"::"m"(*src):"memory");
+ __asm __volatile(
+ "movq %0, %%mm7\n\t"
+ "movq %1, %%mm6\n\t"
+ ::"m"(red_15mask),"m"(green_15mask));
+ mm_end = end - 15;
+ while(s < mm_end)
+ {
+ __asm __volatile(
+ PREFETCH" 32%1\n\t"
+ "movd %1, %%mm0\n\t"
+ "movd 3%1, %%mm3\n\t"
+ "punpckldq 6%1, %%mm0\n\t"
+ "punpckldq 9%1, %%mm3\n\t"
+ "movq %%mm0, %%mm1\n\t"
+ "movq %%mm0, %%mm2\n\t"
+ "movq %%mm3, %%mm4\n\t"
+ "movq %%mm3, %%mm5\n\t"
+ "psllq $7, %%mm0\n\t"
+ "psllq $7, %%mm3\n\t"
+ "pand %%mm7, %%mm0\n\t"
+ "pand %%mm7, %%mm3\n\t"
+ "psrlq $6, %%mm1\n\t"
+ "psrlq $6, %%mm4\n\t"
+ "pand %%mm6, %%mm1\n\t"
+ "pand %%mm6, %%mm4\n\t"
+ "psrlq $19, %%mm2\n\t"
+ "psrlq $19, %%mm5\n\t"
+ "pand %2, %%mm2\n\t"
+ "pand %2, %%mm5\n\t"
+ "por %%mm1, %%mm0\n\t"
+ "por %%mm4, %%mm3\n\t"
+ "por %%mm2, %%mm0\n\t"
+ "por %%mm5, %%mm3\n\t"
+ "psllq $16, %%mm3\n\t"
+ "por %%mm3, %%mm0\n\t"
+ MOVNTQ" %%mm0, %0\n\t"
+ :"=m"(*d):"m"(*s),"m"(blue_15mask):"memory");
+ d += 4;
+ s += 12;
+ }
+ __asm __volatile(SFENCE:::"memory");
+ __asm __volatile(EMMS:::"memory");
+#endif
+ while(s < end)
+ {
+ const int r= *s++;
+ const int g= *s++;
+ const int b= *s++;
+ *d++ = (b>>3) | ((g&0xF8)<<2) | ((r&0xF8)<<7);
+ }
+}
+
+/*
+ I use here less accurate approximation by simply
+ left-shifting the input
+ value and filling the low order bits with
+ zeroes. This method improves png's
+ compression but this scheme cannot reproduce white exactly, since it does not
+ generate an all-ones maximum value; the net effect is to darken the
+ image slightly.
+
+ The better method should be "left bit replication":
+
+ 4 3 2 1 0
+ ---------
+ 1 1 0 1 1
+
+ 7 6 5 4 3 2 1 0
+ ----------------
+ 1 1 0 1 1 1 1 0
+ |=======| |===|
+ | Leftmost Bits Repeated to Fill Open Bits
+ |
+ Original Bits
+*/
+static inline void RENAME(rgb15to24)(const uint8_t *src, uint8_t *dst, long src_size)
+{
+ const uint16_t *end;
+#ifdef HAVE_MMX
+ const uint16_t *mm_end;
+#endif
+ uint8_t *d = (uint8_t *)dst;
+ const uint16_t *s = (uint16_t *)src;
+ end = s + src_size/2;
+#ifdef HAVE_MMX
+ __asm __volatile(PREFETCH" %0"::"m"(*s):"memory");
+ mm_end = end - 7;
+ while(s < mm_end)
+ {
+ __asm __volatile(
+ PREFETCH" 32%1\n\t"
+ "movq %1, %%mm0\n\t"
+ "movq %1, %%mm1\n\t"
+ "movq %1, %%mm2\n\t"
+ "pand %2, %%mm0\n\t"
+ "pand %3, %%mm1\n\t"
+ "pand %4, %%mm2\n\t"
+ "psllq $3, %%mm0\n\t"
+ "psrlq $2, %%mm1\n\t"
+ "psrlq $7, %%mm2\n\t"
+ "movq %%mm0, %%mm3\n\t"
+ "movq %%mm1, %%mm4\n\t"
+ "movq %%mm2, %%mm5\n\t"
+ "punpcklwd %5, %%mm0\n\t"
+ "punpcklwd %5, %%mm1\n\t"
+ "punpcklwd %5, %%mm2\n\t"
+ "punpckhwd %5, %%mm3\n\t"
+ "punpckhwd %5, %%mm4\n\t"
+ "punpckhwd %5, %%mm5\n\t"
+ "psllq $8, %%mm1\n\t"
+ "psllq $16, %%mm2\n\t"
+ "por %%mm1, %%mm0\n\t"
+ "por %%mm2, %%mm0\n\t"
+ "psllq $8, %%mm4\n\t"
+ "psllq $16, %%mm5\n\t"
+ "por %%mm4, %%mm3\n\t"
+ "por %%mm5, %%mm3\n\t"
+
+ "movq %%mm0, %%mm6\n\t"
+ "movq %%mm3, %%mm7\n\t"
+
+ "movq 8%1, %%mm0\n\t"
+ "movq 8%1, %%mm1\n\t"
+ "movq 8%1, %%mm2\n\t"
+ "pand %2, %%mm0\n\t"
+ "pand %3, %%mm1\n\t"
+ "pand %4, %%mm2\n\t"
+ "psllq $3, %%mm0\n\t"
+ "psrlq $2, %%mm1\n\t"
+ "psrlq $7, %%mm2\n\t"
+ "movq %%mm0, %%mm3\n\t"
+ "movq %%mm1, %%mm4\n\t"
+ "movq %%mm2, %%mm5\n\t"
+ "punpcklwd %5, %%mm0\n\t"
+ "punpcklwd %5, %%mm1\n\t"
+ "punpcklwd %5, %%mm2\n\t"
+ "punpckhwd %5, %%mm3\n\t"
+ "punpckhwd %5, %%mm4\n\t"
+ "punpckhwd %5, %%mm5\n\t"
+ "psllq $8, %%mm1\n\t"
+ "psllq $16, %%mm2\n\t"
+ "por %%mm1, %%mm0\n\t"
+ "por %%mm2, %%mm0\n\t"
+ "psllq $8, %%mm4\n\t"
+ "psllq $16, %%mm5\n\t"
+ "por %%mm4, %%mm3\n\t"
+ "por %%mm5, %%mm3\n\t"
+
+ :"=m"(*d)
+ :"m"(*s),"m"(mask15b),"m"(mask15g),"m"(mask15r), "m"(mmx_null)
+ :"memory");
+ /* Borrowed 32 to 24 */
+ __asm __volatile(
+ "movq %%mm0, %%mm4\n\t"
+ "movq %%mm3, %%mm5\n\t"
+ "movq %%mm6, %%mm0\n\t"
+ "movq %%mm7, %%mm1\n\t"
+
+ "movq %%mm4, %%mm6\n\t"
+ "movq %%mm5, %%mm7\n\t"
+ "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"
+
+ :"=m"(*d)
+ :"m"(*s),"m"(mask24l),"m"(mask24h),"m"(mask24hh),"m"(mask24hhh),"m"(mask24hhhh)
+ :"memory");
+ d += 24;
+ s += 8;
+ }
+ __asm __volatile(SFENCE:::"memory");
+ __asm __volatile(EMMS:::"memory");
+#endif
+ while(s < end)
+ {
+ register uint16_t bgr;
+ bgr = *s++;
+ *d++ = (bgr&0x1F)<<3;
+ *d++ = (bgr&0x3E0)>>2;
+ *d++ = (bgr&0x7C00)>>7;
+ }
+}
+
+static inline void RENAME(rgb16to24)(const uint8_t *src, uint8_t *dst, long src_size)
+{
+ const uint16_t *end;
+#ifdef HAVE_MMX
+ const uint16_t *mm_end;
+#endif
+ uint8_t *d = (uint8_t *)dst;
+ const uint16_t *s = (const uint16_t *)src;
+ end = s + src_size/2;
+#ifdef HAVE_MMX
+ __asm __volatile(PREFETCH" %0"::"m"(*s):"memory");
+ mm_end = end - 7;
+ while(s < mm_end)
+ {
+ __asm __volatile(
+ PREFETCH" 32%1\n\t"
+ "movq %1, %%mm0\n\t"
+ "movq %1, %%mm1\n\t"
+ "movq %1, %%mm2\n\t"
+ "pand %2, %%mm0\n\t"
+ "pand %3, %%mm1\n\t"
+ "pand %4, %%mm2\n\t"
+ "psllq $3, %%mm0\n\t"
+ "psrlq $3, %%mm1\n\t"
+ "psrlq $8, %%mm2\n\t"
+ "movq %%mm0, %%mm3\n\t"
+ "movq %%mm1, %%mm4\n\t"
+ "movq %%mm2, %%mm5\n\t"
+ "punpcklwd %5, %%mm0\n\t"
+ "punpcklwd %5, %%mm1\n\t"
+ "punpcklwd %5, %%mm2\n\t"
+ "punpckhwd %5, %%mm3\n\t"
+ "punpckhwd %5, %%mm4\n\t"
+ "punpckhwd %5, %%mm5\n\t"
+ "psllq $8, %%mm1\n\t"
+ "psllq $16, %%mm2\n\t"
+ "por %%mm1, %%mm0\n\t"
+ "por %%mm2, %%mm0\n\t"
+ "psllq $8, %%mm4\n\t"
+ "psllq $16, %%mm5\n\t"
+ "por %%mm4, %%mm3\n\t"
+ "por %%mm5, %%mm3\n\t"
+
+ "movq %%mm0, %%mm6\n\t"
+ "movq %%mm3, %%mm7\n\t"
+
+ "movq 8%1, %%mm0\n\t"
+ "movq 8%1, %%mm1\n\t"
+ "movq 8%1, %%mm2\n\t"
+ "pand %2, %%mm0\n\t"
+ "pand %3, %%mm1\n\t"
+ "pand %4, %%mm2\n\t"
+ "psllq $3, %%mm0\n\t"
+ "psrlq $3, %%mm1\n\t"
+ "psrlq $8, %%mm2\n\t"
+ "movq %%mm0, %%mm3\n\t"
+ "movq %%mm1, %%mm4\n\t"
+ "movq %%mm2, %%mm5\n\t"
+ "punpcklwd %5, %%mm0\n\t"
+ "punpcklwd %5, %%mm1\n\t"
+ "punpcklwd %5, %%mm2\n\t"
+ "punpckhwd %5, %%mm3\n\t"
+ "punpckhwd %5, %%mm4\n\t"
+ "punpckhwd %5, %%mm5\n\t"
+ "psllq $8, %%mm1\n\t"
+ "psllq $16, %%mm2\n\t"
+ "por %%mm1, %%mm0\n\t"
+ "por %%mm2, %%mm0\n\t"
+ "psllq $8, %%mm4\n\t"
+ "psllq $16, %%mm5\n\t"
+ "por %%mm4, %%mm3\n\t"
+ "por %%mm5, %%mm3\n\t"
+ :"=m"(*d)
+ :"m"(*s),"m"(mask16b),"m"(mask16g),"m"(mask16r),"m"(mmx_null)
+ :"memory");
+ /* Borrowed 32 to 24 */
+ __asm __volatile(
+ "movq %%mm0, %%mm4\n\t"
+ "movq %%mm3, %%mm5\n\t"
+ "movq %%mm6, %%mm0\n\t"
+ "movq %%mm7, %%mm1\n\t"
+
+ "movq %%mm4, %%mm6\n\t"
+ "movq %%mm5, %%mm7\n\t"
+ "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"
+
+ :"=m"(*d)
+ :"m"(*s),"m"(mask24l),"m"(mask24h),"m"(mask24hh),"m"(mask24hhh),"m"(mask24hhhh)
+ :"memory");
+ d += 24;
+ s += 8;
+ }
+ __asm __volatile(SFENCE:::"memory");
+ __asm __volatile(EMMS:::"memory");
+#endif
+ while(s < end)
+ {
+ register uint16_t bgr;
+ bgr = *s++;
+ *d++ = (bgr&0x1F)<<3;
+ *d++ = (bgr&0x7E0)>>3;
+ *d++ = (bgr&0xF800)>>8;
+ }
+}
+
+static inline void RENAME(rgb15to32)(const uint8_t *src, uint8_t *dst, long src_size)
+{
+ const uint16_t *end;
+#ifdef HAVE_MMX
+ const uint16_t *mm_end;
+#endif
+ uint8_t *d = (uint8_t *)dst;
+ const uint16_t *s = (const uint16_t *)src;
+ end = s + src_size/2;
+#ifdef HAVE_MMX
+ __asm __volatile(PREFETCH" %0"::"m"(*s):"memory");
+ __asm __volatile("pxor %%mm7,%%mm7\n\t":::"memory");
+ mm_end = end - 3;
+ while(s < mm_end)
+ {
+ __asm __volatile(
+ PREFETCH" 32%1\n\t"
+ "movq %1, %%mm0\n\t"
+ "movq %1, %%mm1\n\t"
+ "movq %1, %%mm2\n\t"
+ "pand %2, %%mm0\n\t"
+ "pand %3, %%mm1\n\t"
+ "pand %4, %%mm2\n\t"
+ "psllq $3, %%mm0\n\t"
+ "psrlq $2, %%mm1\n\t"
+ "psrlq $7, %%mm2\n\t"
+ "movq %%mm0, %%mm3\n\t"
+ "movq %%mm1, %%mm4\n\t"
+ "movq %%mm2, %%mm5\n\t"
+ "punpcklwd %%mm7, %%mm0\n\t"
+ "punpcklwd %%mm7, %%mm1\n\t"
+ "punpcklwd %%mm7, %%mm2\n\t"
+ "punpckhwd %%mm7, %%mm3\n\t"
+ "punpckhwd %%mm7, %%mm4\n\t"
+ "punpckhwd %%mm7, %%mm5\n\t"
+ "psllq $8, %%mm1\n\t"
+ "psllq $16, %%mm2\n\t"
+ "por %%mm1, %%mm0\n\t"
+ "por %%mm2, %%mm0\n\t"
+ "psllq $8, %%mm4\n\t"
+ "psllq $16, %%mm5\n\t"
+ "por %%mm4, %%mm3\n\t"
+ "por %%mm5, %%mm3\n\t"
+ MOVNTQ" %%mm0, %0\n\t"
+ MOVNTQ" %%mm3, 8%0\n\t"
+ :"=m"(*d)
+ :"m"(*s),"m"(mask15b),"m"(mask15g),"m"(mask15r)
+ :"memory");
+ d += 16;
+ s += 4;
+ }
+ __asm __volatile(SFENCE:::"memory");
+ __asm __volatile(EMMS:::"memory");
+#endif
+ while(s < end)
+ {
+#if 0 //slightly slower on athlon
+ int bgr= *s++;
+ *((uint32_t*)d)++ = ((bgr&0x1F)<<3) + ((bgr&0x3E0)<<6) + ((bgr&0x7C00)<<9);
+#else
+ register uint16_t bgr;
+ bgr = *s++;
+#ifdef WORDS_BIGENDIAN
+ *d++ = 0;
+ *d++ = (bgr&0x7C00)>>7;
+ *d++ = (bgr&0x3E0)>>2;
+ *d++ = (bgr&0x1F)<<3;
+#else
+ *d++ = (bgr&0x1F)<<3;
+ *d++ = (bgr&0x3E0)>>2;
+ *d++ = (bgr&0x7C00)>>7;
+ *d++ = 0;
+#endif
+
+#endif
+ }
+}
+
+static inline void RENAME(rgb16to32)(const uint8_t *src, uint8_t *dst, long src_size)
+{
+ const uint16_t *end;
+#ifdef HAVE_MMX
+ const uint16_t *mm_end;
+#endif
+ uint8_t *d = (uint8_t *)dst;
+ const uint16_t *s = (uint16_t *)src;
+ end = s + src_size/2;
+#ifdef HAVE_MMX
+ __asm __volatile(PREFETCH" %0"::"m"(*s):"memory");
+ __asm __volatile("pxor %%mm7,%%mm7\n\t":::"memory");
+ mm_end = end - 3;
+ while(s < mm_end)
+ {
+ __asm __volatile(
+ PREFETCH" 32%1\n\t"
+ "movq %1, %%mm0\n\t"
+ "movq %1, %%mm1\n\t"
+ "movq %1, %%mm2\n\t"
+ "pand %2, %%mm0\n\t"
+ "pand %3, %%mm1\n\t"
+ "pand %4, %%mm2\n\t"
+ "psllq $3, %%mm0\n\t"
+ "psrlq $3, %%mm1\n\t"
+ "psrlq $8, %%mm2\n\t"
+ "movq %%mm0, %%mm3\n\t"
+ "movq %%mm1, %%mm4\n\t"
+ "movq %%mm2, %%mm5\n\t"
+ "punpcklwd %%mm7, %%mm0\n\t"
+ "punpcklwd %%mm7, %%mm1\n\t"
+ "punpcklwd %%mm7, %%mm2\n\t"
+ "punpckhwd %%mm7, %%mm3\n\t"
+ "punpckhwd %%mm7, %%mm4\n\t"
+ "punpckhwd %%mm7, %%mm5\n\t"
+ "psllq $8, %%mm1\n\t"
+ "psllq $16, %%mm2\n\t"
+ "por %%mm1, %%mm0\n\t"
+ "por %%mm2, %%mm0\n\t"
+ "psllq $8, %%mm4\n\t"
+ "psllq $16, %%mm5\n\t"
+ "por %%mm4, %%mm3\n\t"
+ "por %%mm5, %%mm3\n\t"
+ MOVNTQ" %%mm0, %0\n\t"
+ MOVNTQ" %%mm3, 8%0\n\t"
+ :"=m"(*d)
+ :"m"(*s),"m"(mask16b),"m"(mask16g),"m"(mask16r)
+ :"memory");
+ d += 16;
+ s += 4;
+ }
+ __asm __volatile(SFENCE:::"memory");
+ __asm __volatile(EMMS:::"memory");
+#endif
+ while(s < end)
+ {
+ register uint16_t bgr;
+ bgr = *s++;
+#ifdef WORDS_BIGENDIAN
+ *d++ = 0;
+ *d++ = (bgr&0xF800)>>8;
+ *d++ = (bgr&0x7E0)>>3;
+ *d++ = (bgr&0x1F)<<3;
+#else
+ *d++ = (bgr&0x1F)<<3;
+ *d++ = (bgr&0x7E0)>>3;
+ *d++ = (bgr&0xF800)>>8;
+ *d++ = 0;
+#endif
+ }
+}
+
+static inline void RENAME(rgb32tobgr32)(const uint8_t *src, uint8_t *dst, long src_size)
+{
+#ifdef HAVE_MMX
+/* TODO: unroll this loop */
+ asm volatile (
+ "xor %%"REG_a", %%"REG_a" \n\t"
+ ASMALIGN(4)
+ "1: \n\t"
+ PREFETCH" 32(%0, %%"REG_a") \n\t"
+ "movq (%0, %%"REG_a"), %%mm0 \n\t"
+ "movq %%mm0, %%mm1 \n\t"
+ "movq %%mm0, %%mm2 \n\t"
+ "pslld $16, %%mm0 \n\t"
+ "psrld $16, %%mm1 \n\t"
+ "pand "MANGLE(mask32r)", %%mm0 \n\t"
+ "pand "MANGLE(mask32g)", %%mm2 \n\t"
+ "pand "MANGLE(mask32b)", %%mm1 \n\t"
+ "por %%mm0, %%mm2 \n\t"
+ "por %%mm1, %%mm2 \n\t"
+ MOVNTQ" %%mm2, (%1, %%"REG_a") \n\t"
+ "add $8, %%"REG_a" \n\t"
+ "cmp %2, %%"REG_a" \n\t"
+ " jb 1b \n\t"
+ :: "r" (src), "r"(dst), "r" (src_size-7)
+ : "%"REG_a
+ );
+
+ __asm __volatile(SFENCE:::"memory");
+ __asm __volatile(EMMS:::"memory");
+#else
+ unsigned i;
+ unsigned num_pixels = src_size >> 2;
+ for(i=0; i<num_pixels; i++)
+ {
+#ifdef WORDS_BIGENDIAN
+ dst[4*i + 1] = src[4*i + 3];
+ dst[4*i + 2] = src[4*i + 2];
+ dst[4*i + 3] = src[4*i + 1];
+#else
+ dst[4*i + 0] = src[4*i + 2];
+ dst[4*i + 1] = src[4*i + 1];
+ dst[4*i + 2] = src[4*i + 0];
+#endif
+ }
+#endif
+}
+
+static inline void RENAME(rgb24tobgr24)(const uint8_t *src, uint8_t *dst, long src_size)
+{
+ unsigned i;
+#ifdef HAVE_MMX
+ long mmx_size= 23 - src_size;
+ asm volatile (
+ "movq "MANGLE(mask24r)", %%mm5 \n\t"
+ "movq "MANGLE(mask24g)", %%mm6 \n\t"
+ "movq "MANGLE(mask24b)", %%mm7 \n\t"
+ ASMALIGN(4)
+ "1: \n\t"
+ PREFETCH" 32(%1, %%"REG_a") \n\t"
+ "movq (%1, %%"REG_a"), %%mm0 \n\t" // BGR BGR BG
+ "movq (%1, %%"REG_a"), %%mm1 \n\t" // BGR BGR BG
+ "movq 2(%1, %%"REG_a"), %%mm2 \n\t" // R BGR BGR B
+ "psllq $16, %%mm0 \n\t" // 00 BGR BGR
+ "pand %%mm5, %%mm0 \n\t"
+ "pand %%mm6, %%mm1 \n\t"
+ "pand %%mm7, %%mm2 \n\t"
+ "por %%mm0, %%mm1 \n\t"
+ "por %%mm2, %%mm1 \n\t"
+ "movq 6(%1, %%"REG_a"), %%mm0 \n\t" // BGR BGR BG
+ MOVNTQ" %%mm1, (%2, %%"REG_a")\n\t" // RGB RGB RG
+ "movq 8(%1, %%"REG_a"), %%mm1 \n\t" // R BGR BGR B
+ "movq 10(%1, %%"REG_a"), %%mm2 \n\t" // GR BGR BGR
+ "pand %%mm7, %%mm0 \n\t"
+ "pand %%mm5, %%mm1 \n\t"
+ "pand %%mm6, %%mm2 \n\t"
+ "por %%mm0, %%mm1 \n\t"
+ "por %%mm2, %%mm1 \n\t"
+ "movq 14(%1, %%"REG_a"), %%mm0 \n\t" // R BGR BGR B
+ MOVNTQ" %%mm1, 8(%2, %%"REG_a")\n\t" // B RGB RGB R
+ "movq 16(%1, %%"REG_a"), %%mm1 \n\t" // GR BGR BGR
+ "movq 18(%1, %%"REG_a"), %%mm2 \n\t" // BGR BGR BG
+ "pand %%mm6, %%mm0 \n\t"
+ "pand %%mm7, %%mm1 \n\t"
+ "pand %%mm5, %%mm2 \n\t"
+ "por %%mm0, %%mm1 \n\t"
+ "por %%mm2, %%mm1 \n\t"
+ MOVNTQ" %%mm1, 16(%2, %%"REG_a")\n\t"
+ "add $24, %%"REG_a" \n\t"
+ " js 1b \n\t"
+ : "+a" (mmx_size)
+ : "r" (src-mmx_size), "r"(dst-mmx_size)
+ );
+
+ __asm __volatile(SFENCE:::"memory");
+ __asm __volatile(EMMS:::"memory");
+
+ if(mmx_size==23) return; //finihsed, was multiple of 8
+
+ src+= src_size;
+ dst+= src_size;
+ src_size= 23-mmx_size;
+ src-= src_size;
+ dst-= src_size;
+#endif
+ for(i=0; i<src_size; i+=3)
+ {
+ register uint8_t x;
+ x = src[i + 2];
+ dst[i + 1] = src[i + 1];
+ dst[i + 2] = src[i + 0];
+ dst[i + 0] = x;
+ }
+}
+
+static inline void RENAME(yuvPlanartoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
+ long width, long height,
+ long lumStride, long chromStride, long dstStride, long vertLumPerChroma)
+{
+ long y;
+ const long chromWidth= width>>1;
+ for(y=0; y<height; y++)
+ {
+#ifdef HAVE_MMX
+//FIXME handle 2 lines a once (fewer prefetch, reuse some chrom, but very likely limited by mem anyway)
+ asm volatile(
+ "xor %%"REG_a", %%"REG_a" \n\t"
+ ASMALIGN(4)
+ "1: \n\t"
+ PREFETCH" 32(%1, %%"REG_a", 2) \n\t"
+ PREFETCH" 32(%2, %%"REG_a") \n\t"
+ PREFETCH" 32(%3, %%"REG_a") \n\t"
+ "movq (%2, %%"REG_a"), %%mm0 \n\t" // U(0)
+ "movq %%mm0, %%mm2 \n\t" // U(0)
+ "movq (%3, %%"REG_a"), %%mm1 \n\t" // V(0)
+ "punpcklbw %%mm1, %%mm0 \n\t" // UVUV UVUV(0)
+ "punpckhbw %%mm1, %%mm2 \n\t" // UVUV UVUV(8)
+
+ "movq (%1, %%"REG_a",2), %%mm3 \n\t" // Y(0)
+ "movq 8(%1, %%"REG_a",2), %%mm5 \n\t" // Y(8)
+ "movq %%mm3, %%mm4 \n\t" // Y(0)
+ "movq %%mm5, %%mm6 \n\t" // Y(8)
+ "punpcklbw %%mm0, %%mm3 \n\t" // YUYV YUYV(0)
+ "punpckhbw %%mm0, %%mm4 \n\t" // YUYV YUYV(4)
+ "punpcklbw %%mm2, %%mm5 \n\t" // YUYV YUYV(8)
+ "punpckhbw %%mm2, %%mm6 \n\t" // YUYV YUYV(12)
+
+ MOVNTQ" %%mm3, (%0, %%"REG_a", 4)\n\t"
+ MOVNTQ" %%mm4, 8(%0, %%"REG_a", 4)\n\t"
+ MOVNTQ" %%mm5, 16(%0, %%"REG_a", 4)\n\t"
+ MOVNTQ" %%mm6, 24(%0, %%"REG_a", 4)\n\t"
+
+ "add $8, %%"REG_a" \n\t"
+ "cmp %4, %%"REG_a" \n\t"
+ " jb 1b \n\t"
+ ::"r"(dst), "r"(ysrc), "r"(usrc), "r"(vsrc), "g" (chromWidth)
+ : "%"REG_a
+ );
+#else
+
+#if defined ARCH_ALPHA && defined HAVE_MVI
+#define pl2yuy2(n) \
+ y1 = yc[n]; \
+ y2 = yc2[n]; \
+ u = uc[n]; \
+ v = vc[n]; \
+ asm("unpkbw %1, %0" : "=r"(y1) : "r"(y1)); \
+ asm("unpkbw %1, %0" : "=r"(y2) : "r"(y2)); \
+ asm("unpkbl %1, %0" : "=r"(u) : "r"(u)); \
+ asm("unpkbl %1, %0" : "=r"(v) : "r"(v)); \
+ yuv1 = (u << 8) + (v << 24); \
+ yuv2 = yuv1 + y2; \
+ yuv1 += y1; \
+ qdst[n] = yuv1; \
+ qdst2[n] = yuv2;
+
+ int i;
+ uint64_t *qdst = (uint64_t *) dst;
+ uint64_t *qdst2 = (uint64_t *) (dst + dstStride);
+ const uint32_t *yc = (uint32_t *) ysrc;
+ const uint32_t *yc2 = (uint32_t *) (ysrc + lumStride);
+ const uint16_t *uc = (uint16_t*) usrc, *vc = (uint16_t*) vsrc;
+ for(i = 0; i < chromWidth; i += 8){
+ uint64_t y1, y2, yuv1, yuv2;
+ uint64_t u, v;
+ /* Prefetch */
+ asm("ldq $31,64(%0)" :: "r"(yc));
+ asm("ldq $31,64(%0)" :: "r"(yc2));
+ asm("ldq $31,64(%0)" :: "r"(uc));
+ asm("ldq $31,64(%0)" :: "r"(vc));
+
+ pl2yuy2(0);
+ pl2yuy2(1);
+ pl2yuy2(2);
+ pl2yuy2(3);
+
+ yc += 4;
+ yc2 += 4;
+ uc += 4;
+ vc += 4;
+ qdst += 4;
+ qdst2 += 4;
+ }
+ y++;
+ ysrc += lumStride;
+ dst += dstStride;
+
+#elif __WORDSIZE >= 64
+ int i;
+ uint64_t *ldst = (uint64_t *) dst;
+ const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc;
+ for(i = 0; i < chromWidth; i += 2){
+ uint64_t k, l;
+ k = yc[0] + (uc[0] << 8) +
+ (yc[1] << 16) + (vc[0] << 24);
+ l = yc[2] + (uc[1] << 8) +
+ (yc[3] << 16) + (vc[1] << 24);
+ *ldst++ = k + (l << 32);
+ yc += 4;
+ uc += 2;
+ vc += 2;
+ }
+
+#else
+ int i, *idst = (int32_t *) dst;
+ const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc;
+ for(i = 0; i < chromWidth; i++){
+#ifdef WORDS_BIGENDIAN
+ *idst++ = (yc[0] << 24)+ (uc[0] << 16) +
+ (yc[1] << 8) + (vc[0] << 0);
+#else
+ *idst++ = yc[0] + (uc[0] << 8) +
+ (yc[1] << 16) + (vc[0] << 24);
+#endif
+ yc += 2;
+ uc++;
+ vc++;
+ }
+#endif
+#endif
+ if((y&(vertLumPerChroma-1))==(vertLumPerChroma-1) )
+ {
+ usrc += chromStride;
+ vsrc += chromStride;
+ }
+ ysrc += lumStride;
+ dst += dstStride;
+ }
+#ifdef HAVE_MMX
+asm( EMMS" \n\t"
+ SFENCE" \n\t"
+ :::"memory");
+#endif
+}
+
+/**
+ *
+ * height should be a multiple of 2 and width should be a multiple of 16 (if this is a
+ * problem for anyone then tell me, and ill fix it)
+ */
+static inline void RENAME(yv12toyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
+ long width, long height,
+ long lumStride, long chromStride, long dstStride)
+{
+ //FIXME interpolate chroma
+ RENAME(yuvPlanartoyuy2)(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride, 2);
+}
+
+static inline void RENAME(yuvPlanartouyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
+ long width, long height,
+ long lumStride, long chromStride, long dstStride, long vertLumPerChroma)
+{
+ long y;
+ const long chromWidth= width>>1;
+ for(y=0; y<height; y++)
+ {
+#ifdef HAVE_MMX
+//FIXME handle 2 lines a once (fewer prefetch, reuse some chrom, but very likely limited by mem anyway)
+ asm volatile(
+ "xor %%"REG_a", %%"REG_a" \n\t"
+ ASMALIGN(4)
+ "1: \n\t"
+ PREFETCH" 32(%1, %%"REG_a", 2) \n\t"
+ PREFETCH" 32(%2, %%"REG_a") \n\t"
+ PREFETCH" 32(%3, %%"REG_a") \n\t"
+ "movq (%2, %%"REG_a"), %%mm0 \n\t" // U(0)
+ "movq %%mm0, %%mm2 \n\t" // U(0)
+ "movq (%3, %%"REG_a"), %%mm1 \n\t" // V(0)
+ "punpcklbw %%mm1, %%mm0 \n\t" // UVUV UVUV(0)
+ "punpckhbw %%mm1, %%mm2 \n\t" // UVUV UVUV(8)
+
+ "movq (%1, %%"REG_a",2), %%mm3 \n\t" // Y(0)
+ "movq 8(%1, %%"REG_a",2), %%mm5 \n\t" // Y(8)
+ "movq %%mm0, %%mm4 \n\t" // Y(0)
+ "movq %%mm2, %%mm6 \n\t" // Y(8)
+ "punpcklbw %%mm3, %%mm0 \n\t" // YUYV YUYV(0)
+ "punpckhbw %%mm3, %%mm4 \n\t" // YUYV YUYV(4)
+ "punpcklbw %%mm5, %%mm2 \n\t" // YUYV YUYV(8)
+ "punpckhbw %%mm5, %%mm6 \n\t" // YUYV YUYV(12)
+
+ MOVNTQ" %%mm0, (%0, %%"REG_a", 4)\n\t"
+ MOVNTQ" %%mm4, 8(%0, %%"REG_a", 4)\n\t"
+ MOVNTQ" %%mm2, 16(%0, %%"REG_a", 4)\n\t"
+ MOVNTQ" %%mm6, 24(%0, %%"REG_a", 4)\n\t"
+
+ "add $8, %%"REG_a" \n\t"
+ "cmp %4, %%"REG_a" \n\t"
+ " jb 1b \n\t"
+ ::"r"(dst), "r"(ysrc), "r"(usrc), "r"(vsrc), "g" (chromWidth)
+ : "%"REG_a
+ );
+#else
+//FIXME adapt the alpha asm code from yv12->yuy2
+
+#if __WORDSIZE >= 64
+ int i;
+ uint64_t *ldst = (uint64_t *) dst;
+ const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc;
+ for(i = 0; i < chromWidth; i += 2){
+ uint64_t k, l;
+ k = uc[0] + (yc[0] << 8) +
+ (vc[0] << 16) + (yc[1] << 24);
+ l = uc[1] + (yc[2] << 8) +
+ (vc[1] << 16) + (yc[3] << 24);
+ *ldst++ = k + (l << 32);
+ yc += 4;
+ uc += 2;
+ vc += 2;
+ }
+
+#else
+ int i, *idst = (int32_t *) dst;
+ const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc;
+ for(i = 0; i < chromWidth; i++){
+#ifdef WORDS_BIGENDIAN
+ *idst++ = (uc[0] << 24)+ (yc[0] << 16) +
+ (vc[0] << 8) + (yc[1] << 0);
+#else
+ *idst++ = uc[0] + (yc[0] << 8) +
+ (vc[0] << 16) + (yc[1] << 24);
+#endif
+ yc += 2;
+ uc++;
+ vc++;
+ }
+#endif
+#endif
+ if((y&(vertLumPerChroma-1))==(vertLumPerChroma-1) )
+ {
+ usrc += chromStride;
+ vsrc += chromStride;
+ }
+ ysrc += lumStride;
+ dst += dstStride;
+ }
+#ifdef HAVE_MMX
+asm( EMMS" \n\t"
+ SFENCE" \n\t"
+ :::"memory");
+#endif
+}
+
+/**
+ *
+ * height should be a multiple of 2 and width should be a multiple of 16 (if this is a
+ * problem for anyone then tell me, and ill fix it)
+ */
+static inline void RENAME(yv12touyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
+ long width, long height,
+ long lumStride, long chromStride, long dstStride)
+{
+ //FIXME interpolate chroma
+ RENAME(yuvPlanartouyvy)(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride, 2);
+}
+
+/**
+ *
+ * width should be a multiple of 16
+ */
+static inline void RENAME(yuv422ptoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
+ long width, long height,
+ long lumStride, long chromStride, long dstStride)
+{
+ RENAME(yuvPlanartoyuy2)(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride, 1);
+}
+
+/**
+ *
+ * height should be a multiple of 2 and width should be a multiple of 16 (if this is a
+ * problem for anyone then tell me, and ill fix it)
+ */
+static inline void RENAME(yuy2toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
+ long width, long height,
+ long lumStride, long chromStride, long srcStride)
+{
+ long y;
+ const long chromWidth= width>>1;
+ for(y=0; y<height; y+=2)
+ {
+#ifdef HAVE_MMX
+ asm volatile(
+ "xor %%"REG_a", %%"REG_a" \n\t"
+ "pcmpeqw %%mm7, %%mm7 \n\t"
+ "psrlw $8, %%mm7 \n\t" // FF,00,FF,00...
+ ASMALIGN(4)
+ "1: \n\t"
+ PREFETCH" 64(%0, %%"REG_a", 4) \n\t"
+ "movq (%0, %%"REG_a", 4), %%mm0 \n\t" // YUYV YUYV(0)
+ "movq 8(%0, %%"REG_a", 4), %%mm1\n\t" // YUYV YUYV(4)
+ "movq %%mm0, %%mm2 \n\t" // YUYV YUYV(0)
+ "movq %%mm1, %%mm3 \n\t" // YUYV YUYV(4)
+ "psrlw $8, %%mm0 \n\t" // U0V0 U0V0(0)
+ "psrlw $8, %%mm1 \n\t" // U0V0 U0V0(4)
+ "pand %%mm7, %%mm2 \n\t" // Y0Y0 Y0Y0(0)
+ "pand %%mm7, %%mm3 \n\t" // Y0Y0 Y0Y0(4)
+ "packuswb %%mm1, %%mm0 \n\t" // UVUV UVUV(0)
+ "packuswb %%mm3, %%mm2 \n\t" // YYYY YYYY(0)
+
+ MOVNTQ" %%mm2, (%1, %%"REG_a", 2)\n\t"
+
+ "movq 16(%0, %%"REG_a", 4), %%mm1\n\t" // YUYV YUYV(8)
+ "movq 24(%0, %%"REG_a", 4), %%mm2\n\t" // YUYV YUYV(12)
+ "movq %%mm1, %%mm3 \n\t" // YUYV YUYV(8)
+ "movq %%mm2, %%mm4 \n\t" // YUYV YUYV(12)
+ "psrlw $8, %%mm1 \n\t" // U0V0 U0V0(8)
+ "psrlw $8, %%mm2 \n\t" // U0V0 U0V0(12)
+ "pand %%mm7, %%mm3 \n\t" // Y0Y0 Y0Y0(8)
+ "pand %%mm7, %%mm4 \n\t" // Y0Y0 Y0Y0(12)
+ "packuswb %%mm2, %%mm1 \n\t" // UVUV UVUV(8)
+ "packuswb %%mm4, %%mm3 \n\t" // YYYY YYYY(8)
+
+ MOVNTQ" %%mm3, 8(%1, %%"REG_a", 2)\n\t"
+
+ "movq %%mm0, %%mm2 \n\t" // UVUV UVUV(0)
+ "movq %%mm1, %%mm3 \n\t" // UVUV UVUV(8)
+ "psrlw $8, %%mm0 \n\t" // V0V0 V0V0(0)
+ "psrlw $8, %%mm1 \n\t" // V0V0 V0V0(8)
+ "pand %%mm7, %%mm2 \n\t" // U0U0 U0U0(0)
+ "pand %%mm7, %%mm3 \n\t" // U0U0 U0U0(8)
+ "packuswb %%mm1, %%mm0 \n\t" // VVVV VVVV(0)
+ "packuswb %%mm3, %%mm2 \n\t" // UUUU UUUU(0)
+
+ MOVNTQ" %%mm0, (%3, %%"REG_a") \n\t"
+ MOVNTQ" %%mm2, (%2, %%"REG_a") \n\t"
+
+ "add $8, %%"REG_a" \n\t"
+ "cmp %4, %%"REG_a" \n\t"
+ " jb 1b \n\t"
+ ::"r"(src), "r"(ydst), "r"(udst), "r"(vdst), "g" (chromWidth)
+ : "memory", "%"REG_a
+ );
+
+ ydst += lumStride;
+ src += srcStride;
+
+ asm volatile(
+ "xor %%"REG_a", %%"REG_a" \n\t"
+ ASMALIGN(4)
+ "1: \n\t"
+ PREFETCH" 64(%0, %%"REG_a", 4) \n\t"
+ "movq (%0, %%"REG_a", 4), %%mm0 \n\t" // YUYV YUYV(0)
+ "movq 8(%0, %%"REG_a", 4), %%mm1\n\t" // YUYV YUYV(4)
+ "movq 16(%0, %%"REG_a", 4), %%mm2\n\t" // YUYV YUYV(8)
+ "movq 24(%0, %%"REG_a", 4), %%mm3\n\t" // YUYV YUYV(12)
+ "pand %%mm7, %%mm0 \n\t" // Y0Y0 Y0Y0(0)
+ "pand %%mm7, %%mm1 \n\t" // Y0Y0 Y0Y0(4)
+ "pand %%mm7, %%mm2 \n\t" // Y0Y0 Y0Y0(8)
+ "pand %%mm7, %%mm3 \n\t" // Y0Y0 Y0Y0(12)
+ "packuswb %%mm1, %%mm0 \n\t" // YYYY YYYY(0)
+ "packuswb %%mm3, %%mm2 \n\t" // YYYY YYYY(8)
+
+ MOVNTQ" %%mm0, (%1, %%"REG_a", 2)\n\t"
+ MOVNTQ" %%mm2, 8(%1, %%"REG_a", 2)\n\t"
+
+ "add $8, %%"REG_a" \n\t"
+ "cmp %4, %%"REG_a" \n\t"
+ " jb 1b \n\t"
+
+ ::"r"(src), "r"(ydst), "r"(udst), "r"(vdst), "g" (chromWidth)
+ : "memory", "%"REG_a
+ );
+#else
+ long i;
+ for(i=0; i<chromWidth; i++)
+ {
+ ydst[2*i+0] = src[4*i+0];
+ udst[i] = src[4*i+1];
+ ydst[2*i+1] = src[4*i+2];
+ vdst[i] = src[4*i+3];
+ }
+ ydst += lumStride;
+ src += srcStride;
+
+ for(i=0; i<chromWidth; i++)
+ {
+ ydst[2*i+0] = src[4*i+0];
+ ydst[2*i+1] = src[4*i+2];
+ }
+#endif
+ udst += chromStride;
+ vdst += chromStride;
+ ydst += lumStride;
+ src += srcStride;
+ }
+#ifdef HAVE_MMX
+asm volatile( EMMS" \n\t"
+ SFENCE" \n\t"
+ :::"memory");
+#endif
+}
+
+static inline void RENAME(yvu9toyv12)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc,
+ uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
+ long width, long height, long lumStride, long chromStride)
+{
+ /* Y Plane */
+ memcpy(ydst, ysrc, width*height);
+
+ /* XXX: implement upscaling for U,V */
+}
+
+static inline void RENAME(planar2x)(const uint8_t *src, uint8_t *dst, long srcWidth, long srcHeight, long srcStride, long dstStride)
+{
+ long x,y;
+
+ dst[0]= src[0];
+
+ // first line
+ for(x=0; x<srcWidth-1; x++){
+ dst[2*x+1]= (3*src[x] + src[x+1])>>2;
+ dst[2*x+2]= ( src[x] + 3*src[x+1])>>2;
+ }
+ dst[2*srcWidth-1]= src[srcWidth-1];
+
+ dst+= dstStride;
+
+ for(y=1; y<srcHeight; y++){
+#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+ const long mmxSize= srcWidth&~15;
+ asm volatile(
+ "mov %4, %%"REG_a" \n\t"
+ "1: \n\t"
+ "movq (%0, %%"REG_a"), %%mm0 \n\t"
+ "movq (%1, %%"REG_a"), %%mm1 \n\t"
+ "movq 1(%0, %%"REG_a"), %%mm2 \n\t"
+ "movq 1(%1, %%"REG_a"), %%mm3 \n\t"
+ "movq -1(%0, %%"REG_a"), %%mm4 \n\t"
+ "movq -1(%1, %%"REG_a"), %%mm5 \n\t"
+ PAVGB" %%mm0, %%mm5 \n\t"
+ PAVGB" %%mm0, %%mm3 \n\t"
+ PAVGB" %%mm0, %%mm5 \n\t"
+ PAVGB" %%mm0, %%mm3 \n\t"
+ PAVGB" %%mm1, %%mm4 \n\t"
+ PAVGB" %%mm1, %%mm2 \n\t"
+ PAVGB" %%mm1, %%mm4 \n\t"
+ PAVGB" %%mm1, %%mm2 \n\t"
+ "movq %%mm5, %%mm7 \n\t"
+ "movq %%mm4, %%mm6 \n\t"
+ "punpcklbw %%mm3, %%mm5 \n\t"
+ "punpckhbw %%mm3, %%mm7 \n\t"
+ "punpcklbw %%mm2, %%mm4 \n\t"
+ "punpckhbw %%mm2, %%mm6 \n\t"
+#if 1
+ MOVNTQ" %%mm5, (%2, %%"REG_a", 2)\n\t"
+ MOVNTQ" %%mm7, 8(%2, %%"REG_a", 2)\n\t"
+ MOVNTQ" %%mm4, (%3, %%"REG_a", 2)\n\t"
+ MOVNTQ" %%mm6, 8(%3, %%"REG_a", 2)\n\t"
+#else
+ "movq %%mm5, (%2, %%"REG_a", 2) \n\t"
+ "movq %%mm7, 8(%2, %%"REG_a", 2)\n\t"
+ "movq %%mm4, (%3, %%"REG_a", 2) \n\t"
+ "movq %%mm6, 8(%3, %%"REG_a", 2)\n\t"
+#endif
+ "add $8, %%"REG_a" \n\t"
+ " js 1b \n\t"
+ :: "r" (src + mmxSize ), "r" (src + srcStride + mmxSize ),
+ "r" (dst + mmxSize*2), "r" (dst + dstStride + mmxSize*2),
+ "g" (-mmxSize)
+ : "%"REG_a
+
+ );
+#else
+ const long mmxSize=1;
+#endif
+ dst[0 ]= (3*src[0] + src[srcStride])>>2;
+ dst[dstStride]= ( src[0] + 3*src[srcStride])>>2;
+
+ for(x=mmxSize-1; x<srcWidth-1; x++){
+ dst[2*x +1]= (3*src[x+0] + src[x+srcStride+1])>>2;
+ dst[2*x+dstStride+2]= ( src[x+0] + 3*src[x+srcStride+1])>>2;
+ dst[2*x+dstStride+1]= ( src[x+1] + 3*src[x+srcStride ])>>2;
+ dst[2*x +2]= (3*src[x+1] + src[x+srcStride ])>>2;
+ }
+ dst[srcWidth*2 -1 ]= (3*src[srcWidth-1] + src[srcWidth-1 + srcStride])>>2;
+ dst[srcWidth*2 -1 + dstStride]= ( src[srcWidth-1] + 3*src[srcWidth-1 + srcStride])>>2;
+
+ dst+=dstStride*2;
+ src+=srcStride;
+ }
+
+ // last line
+#if 1
+ dst[0]= src[0];
+
+ for(x=0; x<srcWidth-1; x++){
+ dst[2*x+1]= (3*src[x] + src[x+1])>>2;
+ dst[2*x+2]= ( src[x] + 3*src[x+1])>>2;
+ }
+ dst[2*srcWidth-1]= src[srcWidth-1];
+#else
+ for(x=0; x<srcWidth; x++){
+ dst[2*x+0]=
+ dst[2*x+1]= src[x];
+ }
+#endif
+
+#ifdef HAVE_MMX
+asm volatile( EMMS" \n\t"
+ SFENCE" \n\t"
+ :::"memory");
+#endif
+}
+
+/**
+ *
+ * height should be a multiple of 2 and width should be a multiple of 16 (if this is a
+ * problem for anyone then tell me, and ill fix it)
+ * chrominance data is only taken from every secound line others are ignored FIXME write HQ version
+ */
+static inline void RENAME(uyvytoyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
+ long width, long height,
+ long lumStride, long chromStride, long srcStride)
+{
+ long y;
+ const long chromWidth= width>>1;
+ for(y=0; y<height; y+=2)
+ {
+#ifdef HAVE_MMX
+ asm volatile(
+ "xorl %%eax, %%eax \n\t"
+ "pcmpeqw %%mm7, %%mm7 \n\t"
+ "psrlw $8, %%mm7 \n\t" // FF,00,FF,00...
+ ASMALIGN(4)
+ "1: \n\t"
+ PREFETCH" 64(%0, %%eax, 4) \n\t"
+ "movq (%0, %%eax, 4), %%mm0 \n\t" // UYVY UYVY(0)
+ "movq 8(%0, %%eax, 4), %%mm1 \n\t" // UYVY UYVY(4)
+ "movq %%mm0, %%mm2 \n\t" // UYVY UYVY(0)
+ "movq %%mm1, %%mm3 \n\t" // UYVY UYVY(4)
+ "pand %%mm7, %%mm0 \n\t" // U0V0 U0V0(0)
+ "pand %%mm7, %%mm1 \n\t" // U0V0 U0V0(4)
+ "psrlw $8, %%mm2 \n\t" // Y0Y0 Y0Y0(0)
+ "psrlw $8, %%mm3 \n\t" // Y0Y0 Y0Y0(4)
+ "packuswb %%mm1, %%mm0 \n\t" // UVUV UVUV(0)
+ "packuswb %%mm3, %%mm2 \n\t" // YYYY YYYY(0)
+
+ MOVNTQ" %%mm2, (%1, %%eax, 2) \n\t"
+
+ "movq 16(%0, %%eax, 4), %%mm1 \n\t" // UYVY UYVY(8)
+ "movq 24(%0, %%eax, 4), %%mm2 \n\t" // UYVY UYVY(12)
+ "movq %%mm1, %%mm3 \n\t" // UYVY UYVY(8)
+ "movq %%mm2, %%mm4 \n\t" // UYVY UYVY(12)
+ "pand %%mm7, %%mm1 \n\t" // U0V0 U0V0(8)
+ "pand %%mm7, %%mm2 \n\t" // U0V0 U0V0(12)
+ "psrlw $8, %%mm3 \n\t" // Y0Y0 Y0Y0(8)
+ "psrlw $8, %%mm4 \n\t" // Y0Y0 Y0Y0(12)
+ "packuswb %%mm2, %%mm1 \n\t" // UVUV UVUV(8)
+ "packuswb %%mm4, %%mm3 \n\t" // YYYY YYYY(8)
+
+ MOVNTQ" %%mm3, 8(%1, %%eax, 2) \n\t"
+
+ "movq %%mm0, %%mm2 \n\t" // UVUV UVUV(0)
+ "movq %%mm1, %%mm3 \n\t" // UVUV UVUV(8)
+ "psrlw $8, %%mm0 \n\t" // V0V0 V0V0(0)
+ "psrlw $8, %%mm1 \n\t" // V0V0 V0V0(8)
+ "pand %%mm7, %%mm2 \n\t" // U0U0 U0U0(0)
+ "pand %%mm7, %%mm3 \n\t" // U0U0 U0U0(8)
+ "packuswb %%mm1, %%mm0 \n\t" // VVVV VVVV(0)
+ "packuswb %%mm3, %%mm2 \n\t" // UUUU UUUU(0)
+
+ MOVNTQ" %%mm0, (%3, %%eax) \n\t"
+ MOVNTQ" %%mm2, (%2, %%eax) \n\t"
+
+ "addl $8, %%eax \n\t"
+ "cmpl %4, %%eax \n\t"
+ " jb 1b \n\t"
+ ::"r"(src), "r"(ydst), "r"(udst), "r"(vdst), "g" (chromWidth)
+ : "memory", "%eax"
+ );
+
+ ydst += lumStride;
+ src += srcStride;
+
+ asm volatile(
+ "xorl %%eax, %%eax \n\t"
+ ASMALIGN(4)
+ "1: \n\t"
+ PREFETCH" 64(%0, %%eax, 4) \n\t"
+ "movq (%0, %%eax, 4), %%mm0 \n\t" // YUYV YUYV(0)
+ "movq 8(%0, %%eax, 4), %%mm1 \n\t" // YUYV YUYV(4)
+ "movq 16(%0, %%eax, 4), %%mm2 \n\t" // YUYV YUYV(8)
+ "movq 24(%0, %%eax, 4), %%mm3 \n\t" // YUYV YUYV(12)
+ "psrlw $8, %%mm0 \n\t" // Y0Y0 Y0Y0(0)
+ "psrlw $8, %%mm1 \n\t" // Y0Y0 Y0Y0(4)
+ "psrlw $8, %%mm2 \n\t" // Y0Y0 Y0Y0(8)
+ "psrlw $8, %%mm3 \n\t" // Y0Y0 Y0Y0(12)
+ "packuswb %%mm1, %%mm0 \n\t" // YYYY YYYY(0)
+ "packuswb %%mm3, %%mm2 \n\t" // YYYY YYYY(8)
+
+ MOVNTQ" %%mm0, (%1, %%eax, 2) \n\t"
+ MOVNTQ" %%mm2, 8(%1, %%eax, 2) \n\t"
+
+ "addl $8, %%eax \n\t"
+ "cmpl %4, %%eax \n\t"
+ " jb 1b \n\t"
+
+ ::"r"(src), "r"(ydst), "r"(udst), "r"(vdst), "g" (chromWidth)
+ : "memory", "%eax"
+ );
+#else
+ long i;
+ for(i=0; i<chromWidth; i++)
+ {
+ udst[i] = src[4*i+0];
+ ydst[2*i+0] = src[4*i+1];
+ vdst[i] = src[4*i+2];
+ ydst[2*i+1] = src[4*i+3];
+ }
+ ydst += lumStride;
+ src += srcStride;
+
+ for(i=0; i<chromWidth; i++)
+ {
+ ydst[2*i+0] = src[4*i+1];
+ ydst[2*i+1] = src[4*i+3];
+ }
+#endif
+ udst += chromStride;
+ vdst += chromStride;
+ ydst += lumStride;
+ src += srcStride;
+ }
+#ifdef HAVE_MMX
+asm volatile( EMMS" \n\t"
+ SFENCE" \n\t"
+ :::"memory");
+#endif
+}
+
+/**
+ *
+ * height should be a multiple of 2 and width should be a multiple of 2 (if this is a
+ * problem for anyone then tell me, and ill fix it)
+ * chrominance data is only taken from every secound line others are ignored in the C version FIXME write HQ version
+ */
+static inline void RENAME(rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
+ long width, long height,
+ long lumStride, long chromStride, long srcStride)
+{
+ long y;
+ const long chromWidth= width>>1;
+#ifdef HAVE_MMX
+ for(y=0; y<height-2; y+=2)
+ {
+ long i;
+ for(i=0; i<2; i++)
+ {
+ asm volatile(
+ "mov %2, %%"REG_a" \n\t"
+ "movq "MANGLE(bgr2YCoeff)", %%mm6 \n\t"
+ "movq "MANGLE(w1111)", %%mm5 \n\t"
+ "pxor %%mm7, %%mm7 \n\t"
+ "lea (%%"REG_a", %%"REG_a", 2), %%"REG_d"\n\t"
+ ASMALIGN(4)
+ "1: \n\t"
+ PREFETCH" 64(%0, %%"REG_d") \n\t"
+ "movd (%0, %%"REG_d"), %%mm0 \n\t"
+ "movd 3(%0, %%"REG_d"), %%mm1 \n\t"
+ "punpcklbw %%mm7, %%mm0 \n\t"
+ "punpcklbw %%mm7, %%mm1 \n\t"
+ "movd 6(%0, %%"REG_d"), %%mm2 \n\t"
+ "movd 9(%0, %%"REG_d"), %%mm3 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t"
+ "punpcklbw %%mm7, %%mm3 \n\t"
+ "pmaddwd %%mm6, %%mm0 \n\t"
+ "pmaddwd %%mm6, %%mm1 \n\t"
+ "pmaddwd %%mm6, %%mm2 \n\t"
+ "pmaddwd %%mm6, %%mm3 \n\t"
+#ifndef FAST_BGR2YV12
+ "psrad $8, %%mm0 \n\t"
+ "psrad $8, %%mm1 \n\t"
+ "psrad $8, %%mm2 \n\t"
+ "psrad $8, %%mm3 \n\t"
+#endif
+ "packssdw %%mm1, %%mm0 \n\t"
+ "packssdw %%mm3, %%mm2 \n\t"
+ "pmaddwd %%mm5, %%mm0 \n\t"
+ "pmaddwd %%mm5, %%mm2 \n\t"
+ "packssdw %%mm2, %%mm0 \n\t"
+ "psraw $7, %%mm0 \n\t"
+
+ "movd 12(%0, %%"REG_d"), %%mm4 \n\t"
+ "movd 15(%0, %%"REG_d"), %%mm1 \n\t"
+ "punpcklbw %%mm7, %%mm4 \n\t"
+ "punpcklbw %%mm7, %%mm1 \n\t"
+ "movd 18(%0, %%"REG_d"), %%mm2 \n\t"
+ "movd 21(%0, %%"REG_d"), %%mm3 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t"
+ "punpcklbw %%mm7, %%mm3 \n\t"
+ "pmaddwd %%mm6, %%mm4 \n\t"
+ "pmaddwd %%mm6, %%mm1 \n\t"
+ "pmaddwd %%mm6, %%mm2 \n\t"
+ "pmaddwd %%mm6, %%mm3 \n\t"
+#ifndef FAST_BGR2YV12
+ "psrad $8, %%mm4 \n\t"
+ "psrad $8, %%mm1 \n\t"
+ "psrad $8, %%mm2 \n\t"
+ "psrad $8, %%mm3 \n\t"
+#endif
+ "packssdw %%mm1, %%mm4 \n\t"
+ "packssdw %%mm3, %%mm2 \n\t"
+ "pmaddwd %%mm5, %%mm4 \n\t"
+ "pmaddwd %%mm5, %%mm2 \n\t"
+ "add $24, %%"REG_d" \n\t"
+ "packssdw %%mm2, %%mm4 \n\t"
+ "psraw $7, %%mm4 \n\t"
+
+ "packuswb %%mm4, %%mm0 \n\t"
+ "paddusb "MANGLE(bgr2YOffset)", %%mm0 \n\t"
+
+ MOVNTQ" %%mm0, (%1, %%"REG_a") \n\t"
+ "add $8, %%"REG_a" \n\t"
+ " js 1b \n\t"
+ : : "r" (src+width*3), "r" (ydst+width), "g" (-width)
+ : "%"REG_a, "%"REG_d
+ );
+ ydst += lumStride;
+ src += srcStride;
+ }
+ src -= srcStride*2;
+ asm volatile(
+ "mov %4, %%"REG_a" \n\t"
+ "movq "MANGLE(w1111)", %%mm5 \n\t"
+ "movq "MANGLE(bgr2UCoeff)", %%mm6 \n\t"
+ "pxor %%mm7, %%mm7 \n\t"
+ "lea (%%"REG_a", %%"REG_a", 2), %%"REG_d"\n\t"
+ "add %%"REG_d", %%"REG_d" \n\t"
+ ASMALIGN(4)
+ "1: \n\t"
+ PREFETCH" 64(%0, %%"REG_d") \n\t"
+ PREFETCH" 64(%1, %%"REG_d") \n\t"
+#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+ "movq (%0, %%"REG_d"), %%mm0 \n\t"
+ "movq (%1, %%"REG_d"), %%mm1 \n\t"
+ "movq 6(%0, %%"REG_d"), %%mm2 \n\t"
+ "movq 6(%1, %%"REG_d"), %%mm3 \n\t"
+ PAVGB" %%mm1, %%mm0 \n\t"
+ PAVGB" %%mm3, %%mm2 \n\t"
+ "movq %%mm0, %%mm1 \n\t"
+ "movq %%mm2, %%mm3 \n\t"
+ "psrlq $24, %%mm0 \n\t"
+ "psrlq $24, %%mm2 \n\t"
+ PAVGB" %%mm1, %%mm0 \n\t"
+ PAVGB" %%mm3, %%mm2 \n\t"
+ "punpcklbw %%mm7, %%mm0 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t"
+#else
+ "movd (%0, %%"REG_d"), %%mm0 \n\t"
+ "movd (%1, %%"REG_d"), %%mm1 \n\t"
+ "movd 3(%0, %%"REG_d"), %%mm2 \n\t"
+ "movd 3(%1, %%"REG_d"), %%mm3 \n\t"
+ "punpcklbw %%mm7, %%mm0 \n\t"
+ "punpcklbw %%mm7, %%mm1 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t"
+ "punpcklbw %%mm7, %%mm3 \n\t"
+ "paddw %%mm1, %%mm0 \n\t"
+ "paddw %%mm3, %%mm2 \n\t"
+ "paddw %%mm2, %%mm0 \n\t"
+ "movd 6(%0, %%"REG_d"), %%mm4 \n\t"
+ "movd 6(%1, %%"REG_d"), %%mm1 \n\t"
+ "movd 9(%0, %%"REG_d"), %%mm2 \n\t"
+ "movd 9(%1, %%"REG_d"), %%mm3 \n\t"
+ "punpcklbw %%mm7, %%mm4 \n\t"
+ "punpcklbw %%mm7, %%mm1 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t"
+ "punpcklbw %%mm7, %%mm3 \n\t"
+ "paddw %%mm1, %%mm4 \n\t"
+ "paddw %%mm3, %%mm2 \n\t"
+ "paddw %%mm4, %%mm2 \n\t"
+ "psrlw $2, %%mm0 \n\t"
+ "psrlw $2, %%mm2 \n\t"
+#endif
+ "movq "MANGLE(bgr2VCoeff)", %%mm1 \n\t"
+ "movq "MANGLE(bgr2VCoeff)", %%mm3 \n\t"
+
+ "pmaddwd %%mm0, %%mm1 \n\t"
+ "pmaddwd %%mm2, %%mm3 \n\t"
+ "pmaddwd %%mm6, %%mm0 \n\t"
+ "pmaddwd %%mm6, %%mm2 \n\t"
+#ifndef FAST_BGR2YV12
+ "psrad $8, %%mm0 \n\t"
+ "psrad $8, %%mm1 \n\t"
+ "psrad $8, %%mm2 \n\t"
+ "psrad $8, %%mm3 \n\t"
+#endif
+ "packssdw %%mm2, %%mm0 \n\t"
+ "packssdw %%mm3, %%mm1 \n\t"
+ "pmaddwd %%mm5, %%mm0 \n\t"
+ "pmaddwd %%mm5, %%mm1 \n\t"
+ "packssdw %%mm1, %%mm0 \n\t" // V1 V0 U1 U0
+ "psraw $7, %%mm0 \n\t"
+
+#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+ "movq 12(%0, %%"REG_d"), %%mm4 \n\t"
+ "movq 12(%1, %%"REG_d"), %%mm1 \n\t"
+ "movq 18(%0, %%"REG_d"), %%mm2 \n\t"
+ "movq 18(%1, %%"REG_d"), %%mm3 \n\t"
+ PAVGB" %%mm1, %%mm4 \n\t"
+ PAVGB" %%mm3, %%mm2 \n\t"
+ "movq %%mm4, %%mm1 \n\t"
+ "movq %%mm2, %%mm3 \n\t"
+ "psrlq $24, %%mm4 \n\t"
+ "psrlq $24, %%mm2 \n\t"
+ PAVGB" %%mm1, %%mm4 \n\t"
+ PAVGB" %%mm3, %%mm2 \n\t"
+ "punpcklbw %%mm7, %%mm4 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t"
+#else
+ "movd 12(%0, %%"REG_d"), %%mm4 \n\t"
+ "movd 12(%1, %%"REG_d"), %%mm1 \n\t"
+ "movd 15(%0, %%"REG_d"), %%mm2 \n\t"
+ "movd 15(%1, %%"REG_d"), %%mm3 \n\t"
+ "punpcklbw %%mm7, %%mm4 \n\t"
+ "punpcklbw %%mm7, %%mm1 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t"
+ "punpcklbw %%mm7, %%mm3 \n\t"
+ "paddw %%mm1, %%mm4 \n\t"
+ "paddw %%mm3, %%mm2 \n\t"
+ "paddw %%mm2, %%mm4 \n\t"
+ "movd 18(%0, %%"REG_d"), %%mm5 \n\t"
+ "movd 18(%1, %%"REG_d"), %%mm1 \n\t"
+ "movd 21(%0, %%"REG_d"), %%mm2 \n\t"
+ "movd 21(%1, %%"REG_d"), %%mm3 \n\t"
+ "punpcklbw %%mm7, %%mm5 \n\t"
+ "punpcklbw %%mm7, %%mm1 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t"
+ "punpcklbw %%mm7, %%mm3 \n\t"
+ "paddw %%mm1, %%mm5 \n\t"
+ "paddw %%mm3, %%mm2 \n\t"
+ "paddw %%mm5, %%mm2 \n\t"
+ "movq "MANGLE(w1111)", %%mm5 \n\t"
+ "psrlw $2, %%mm4 \n\t"
+ "psrlw $2, %%mm2 \n\t"
+#endif
+ "movq "MANGLE(bgr2VCoeff)", %%mm1 \n\t"
+ "movq "MANGLE(bgr2VCoeff)", %%mm3 \n\t"
+
+ "pmaddwd %%mm4, %%mm1 \n\t"
+ "pmaddwd %%mm2, %%mm3 \n\t"
+ "pmaddwd %%mm6, %%mm4 \n\t"
+ "pmaddwd %%mm6, %%mm2 \n\t"
+#ifndef FAST_BGR2YV12
+ "psrad $8, %%mm4 \n\t"
+ "psrad $8, %%mm1 \n\t"
+ "psrad $8, %%mm2 \n\t"
+ "psrad $8, %%mm3 \n\t"
+#endif
+ "packssdw %%mm2, %%mm4 \n\t"
+ "packssdw %%mm3, %%mm1 \n\t"
+ "pmaddwd %%mm5, %%mm4 \n\t"
+ "pmaddwd %%mm5, %%mm1 \n\t"
+ "add $24, %%"REG_d" \n\t"
+ "packssdw %%mm1, %%mm4 \n\t" // V3 V2 U3 U2
+ "psraw $7, %%mm4 \n\t"
+
+ "movq %%mm0, %%mm1 \n\t"
+ "punpckldq %%mm4, %%mm0 \n\t"
+ "punpckhdq %%mm4, %%mm1 \n\t"
+ "packsswb %%mm1, %%mm0 \n\t"
+ "paddb "MANGLE(bgr2UVOffset)", %%mm0 \n\t"
+ "movd %%mm0, (%2, %%"REG_a") \n\t"
+ "punpckhdq %%mm0, %%mm0 \n\t"
+ "movd %%mm0, (%3, %%"REG_a") \n\t"
+ "add $4, %%"REG_a" \n\t"
+ " js 1b \n\t"
+ : : "r" (src+chromWidth*6), "r" (src+srcStride+chromWidth*6), "r" (udst+chromWidth), "r" (vdst+chromWidth), "g" (-chromWidth)
+ : "%"REG_a, "%"REG_d
+ );
+
+ udst += chromStride;
+ vdst += chromStride;
+ src += srcStride*2;
+ }
+
+ asm volatile( EMMS" \n\t"
+ SFENCE" \n\t"
+ :::"memory");
+#else
+ y=0;
+#endif
+ for(; y<height; y+=2)
+ {
+ long i;
+ for(i=0; i<chromWidth; i++)
+ {
+ unsigned int b= src[6*i+0];
+ unsigned int g= src[6*i+1];
+ unsigned int r= src[6*i+2];
+
+ unsigned int Y = ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16;
+ unsigned int V = ((RV*r + GV*g + BV*b)>>RGB2YUV_SHIFT) + 128;
+ unsigned int U = ((RU*r + GU*g + BU*b)>>RGB2YUV_SHIFT) + 128;
+
+ udst[i] = U;
+ vdst[i] = V;
+ ydst[2*i] = Y;
+
+ b= src[6*i+3];
+ g= src[6*i+4];
+ r= src[6*i+5];
+
+ Y = ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16;
+ ydst[2*i+1] = Y;
+ }
+ ydst += lumStride;
+ src += srcStride;
+
+ for(i=0; i<chromWidth; i++)
+ {
+ unsigned int b= src[6*i+0];
+ unsigned int g= src[6*i+1];
+ unsigned int r= src[6*i+2];
+
+ unsigned int Y = ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16;
+
+ ydst[2*i] = Y;
+
+ b= src[6*i+3];
+ g= src[6*i+4];
+ r= src[6*i+5];
+
+ Y = ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16;
+ ydst[2*i+1] = Y;
+ }
+ udst += chromStride;
+ vdst += chromStride;
+ ydst += lumStride;
+ src += srcStride;
+ }
+}
+
+void RENAME(interleaveBytes)(uint8_t *src1, uint8_t *src2, uint8_t *dest,
+ long width, long height, long src1Stride,
+ long src2Stride, long dstStride){
+ long h;
+
+ for(h=0; h < height; h++)
+ {
+ long w;
+
+#ifdef HAVE_MMX
+#ifdef HAVE_SSE2
+ asm(
+ "xor %%"REG_a", %%"REG_a" \n\t"
+ "1: \n\t"
+ PREFETCH" 64(%1, %%"REG_a") \n\t"
+ PREFETCH" 64(%2, %%"REG_a") \n\t"
+ "movdqa (%1, %%"REG_a"), %%xmm0 \n\t"
+ "movdqa (%1, %%"REG_a"), %%xmm1 \n\t"
+ "movdqa (%2, %%"REG_a"), %%xmm2 \n\t"
+ "punpcklbw %%xmm2, %%xmm0 \n\t"
+ "punpckhbw %%xmm2, %%xmm1 \n\t"
+ "movntdq %%xmm0, (%0, %%"REG_a", 2)\n\t"
+ "movntdq %%xmm1, 16(%0, %%"REG_a", 2)\n\t"
+ "add $16, %%"REG_a" \n\t"
+ "cmp %3, %%"REG_a" \n\t"
+ " jb 1b \n\t"
+ ::"r"(dest), "r"(src1), "r"(src2), "r" (width-15)
+ : "memory", "%"REG_a""
+ );
+#else
+ asm(
+ "xor %%"REG_a", %%"REG_a" \n\t"
+ "1: \n\t"
+ PREFETCH" 64(%1, %%"REG_a") \n\t"
+ PREFETCH" 64(%2, %%"REG_a") \n\t"
+ "movq (%1, %%"REG_a"), %%mm0 \n\t"
+ "movq 8(%1, %%"REG_a"), %%mm2 \n\t"
+ "movq %%mm0, %%mm1 \n\t"
+ "movq %%mm2, %%mm3 \n\t"
+ "movq (%2, %%"REG_a"), %%mm4 \n\t"
+ "movq 8(%2, %%"REG_a"), %%mm5 \n\t"
+ "punpcklbw %%mm4, %%mm0 \n\t"
+ "punpckhbw %%mm4, %%mm1 \n\t"
+ "punpcklbw %%mm5, %%mm2 \n\t"
+ "punpckhbw %%mm5, %%mm3 \n\t"
+ MOVNTQ" %%mm0, (%0, %%"REG_a", 2)\n\t"
+ MOVNTQ" %%mm1, 8(%0, %%"REG_a", 2)\n\t"
+ MOVNTQ" %%mm2, 16(%0, %%"REG_a", 2)\n\t"
+ MOVNTQ" %%mm3, 24(%0, %%"REG_a", 2)\n\t"
+ "add $16, %%"REG_a" \n\t"
+ "cmp %3, %%"REG_a" \n\t"
+ " jb 1b \n\t"
+ ::"r"(dest), "r"(src1), "r"(src2), "r" (width-15)
+ : "memory", "%"REG_a
+ );
+#endif
+ for(w= (width&(~15)); w < width; w++)
+ {
+ dest[2*w+0] = src1[w];
+ dest[2*w+1] = src2[w];
+ }
+#else
+ for(w=0; w < width; w++)
+ {
+ dest[2*w+0] = src1[w];
+ dest[2*w+1] = src2[w];
+ }
+#endif
+ dest += dstStride;
+ src1 += src1Stride;
+ src2 += src2Stride;
+ }
+#ifdef HAVE_MMX
+ asm(
+ EMMS" \n\t"
+ SFENCE" \n\t"
+ ::: "memory"
+ );
+#endif
+}
+
+static inline void RENAME(vu9_to_vu12)(const uint8_t *src1, const uint8_t *src2,
+ uint8_t *dst1, uint8_t *dst2,
+ long width, long height,
+ long srcStride1, long srcStride2,
+ long dstStride1, long dstStride2)
+{
+ long y,x,w,h;
+ w=width/2; h=height/2;
+#ifdef HAVE_MMX
+ asm volatile(
+ PREFETCH" %0\n\t"
+ PREFETCH" %1\n\t"
+ ::"m"(*(src1+srcStride1)),"m"(*(src2+srcStride2)):"memory");
+#endif
+ for(y=0;y<h;y++){
+ const uint8_t* s1=src1+srcStride1*(y>>1);
+ uint8_t* d=dst1+dstStride1*y;
+ x=0;
+#ifdef HAVE_MMX
+ for(;x<w-31;x+=32)
+ {
+ asm volatile(
+ PREFETCH" 32%1\n\t"
+ "movq %1, %%mm0\n\t"
+ "movq 8%1, %%mm2\n\t"
+ "movq 16%1, %%mm4\n\t"
+ "movq 24%1, %%mm6\n\t"
+ "movq %%mm0, %%mm1\n\t"
+ "movq %%mm2, %%mm3\n\t"
+ "movq %%mm4, %%mm5\n\t"
+ "movq %%mm6, %%mm7\n\t"
+ "punpcklbw %%mm0, %%mm0\n\t"
+ "punpckhbw %%mm1, %%mm1\n\t"
+ "punpcklbw %%mm2, %%mm2\n\t"
+ "punpckhbw %%mm3, %%mm3\n\t"
+ "punpcklbw %%mm4, %%mm4\n\t"
+ "punpckhbw %%mm5, %%mm5\n\t"
+ "punpcklbw %%mm6, %%mm6\n\t"
+ "punpckhbw %%mm7, %%mm7\n\t"
+ MOVNTQ" %%mm0, %0\n\t"
+ MOVNTQ" %%mm1, 8%0\n\t"
+ MOVNTQ" %%mm2, 16%0\n\t"
+ MOVNTQ" %%mm3, 24%0\n\t"
+ MOVNTQ" %%mm4, 32%0\n\t"
+ MOVNTQ" %%mm5, 40%0\n\t"
+ MOVNTQ" %%mm6, 48%0\n\t"
+ MOVNTQ" %%mm7, 56%0"
+ :"=m"(d[2*x])
+ :"m"(s1[x])
+ :"memory");
+ }
+#endif
+ for(;x<w;x++) d[2*x]=d[2*x+1]=s1[x];
+ }
+ for(y=0;y<h;y++){
+ const uint8_t* s2=src2+srcStride2*(y>>1);
+ uint8_t* d=dst2+dstStride2*y;
+ x=0;
+#ifdef HAVE_MMX
+ for(;x<w-31;x+=32)
+ {
+ asm volatile(
+ PREFETCH" 32%1\n\t"
+ "movq %1, %%mm0\n\t"
+ "movq 8%1, %%mm2\n\t"
+ "movq 16%1, %%mm4\n\t"
+ "movq 24%1, %%mm6\n\t"
+ "movq %%mm0, %%mm1\n\t"
+ "movq %%mm2, %%mm3\n\t"
+ "movq %%mm4, %%mm5\n\t"
+ "movq %%mm6, %%mm7\n\t"
+ "punpcklbw %%mm0, %%mm0\n\t"
+ "punpckhbw %%mm1, %%mm1\n\t"
+ "punpcklbw %%mm2, %%mm2\n\t"
+ "punpckhbw %%mm3, %%mm3\n\t"
+ "punpcklbw %%mm4, %%mm4\n\t"
+ "punpckhbw %%mm5, %%mm5\n\t"
+ "punpcklbw %%mm6, %%mm6\n\t"
+ "punpckhbw %%mm7, %%mm7\n\t"
+ MOVNTQ" %%mm0, %0\n\t"
+ MOVNTQ" %%mm1, 8%0\n\t"
+ MOVNTQ" %%mm2, 16%0\n\t"
+ MOVNTQ" %%mm3, 24%0\n\t"
+ MOVNTQ" %%mm4, 32%0\n\t"
+ MOVNTQ" %%mm5, 40%0\n\t"
+ MOVNTQ" %%mm6, 48%0\n\t"
+ MOVNTQ" %%mm7, 56%0"
+ :"=m"(d[2*x])
+ :"m"(s2[x])
+ :"memory");
+ }
+#endif
+ for(;x<w;x++) d[2*x]=d[2*x+1]=s2[x];
+ }
+#ifdef HAVE_MMX
+ asm(
+ EMMS" \n\t"
+ SFENCE" \n\t"
+ ::: "memory"
+ );
+#endif
+}
+
+static inline void RENAME(yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2, const uint8_t *src3,
+ uint8_t *dst,
+ long width, long height,
+ long srcStride1, long srcStride2,
+ long srcStride3, long dstStride)
+{
+ long y,x,w,h;
+ w=width/2; h=height;
+ for(y=0;y<h;y++){
+ const uint8_t* yp=src1+srcStride1*y;
+ const uint8_t* up=src2+srcStride2*(y>>2);
+ const uint8_t* vp=src3+srcStride3*(y>>2);
+ uint8_t* d=dst+dstStride*y;
+ x=0;
+#ifdef HAVE_MMX
+ for(;x<w-7;x+=8)
+ {
+ asm volatile(
+ PREFETCH" 32(%1, %0)\n\t"
+ PREFETCH" 32(%2, %0)\n\t"
+ PREFETCH" 32(%3, %0)\n\t"
+ "movq (%1, %0, 4), %%mm0\n\t" /* Y0Y1Y2Y3Y4Y5Y6Y7 */
+ "movq (%2, %0), %%mm1\n\t" /* U0U1U2U3U4U5U6U7 */
+ "movq (%3, %0), %%mm2\n\t" /* V0V1V2V3V4V5V6V7 */
+ "movq %%mm0, %%mm3\n\t" /* Y0Y1Y2Y3Y4Y5Y6Y7 */
+ "movq %%mm1, %%mm4\n\t" /* U0U1U2U3U4U5U6U7 */
+ "movq %%mm2, %%mm5\n\t" /* V0V1V2V3V4V5V6V7 */
+ "punpcklbw %%mm1, %%mm1\n\t" /* U0U0 U1U1 U2U2 U3U3 */
+ "punpcklbw %%mm2, %%mm2\n\t" /* V0V0 V1V1 V2V2 V3V3 */
+ "punpckhbw %%mm4, %%mm4\n\t" /* U4U4 U5U5 U6U6 U7U7 */
+ "punpckhbw %%mm5, %%mm5\n\t" /* V4V4 V5V5 V6V6 V7V7 */
+
+ "movq %%mm1, %%mm6\n\t"
+ "punpcklbw %%mm2, %%mm1\n\t" /* U0V0 U0V0 U1V1 U1V1*/
+ "punpcklbw %%mm1, %%mm0\n\t" /* Y0U0 Y1V0 Y2U0 Y3V0*/
+ "punpckhbw %%mm1, %%mm3\n\t" /* Y4U1 Y5V1 Y6U1 Y7V1*/
+ MOVNTQ" %%mm0, (%4, %0, 8)\n\t"
+ MOVNTQ" %%mm3, 8(%4, %0, 8)\n\t"
+
+ "punpckhbw %%mm2, %%mm6\n\t" /* U2V2 U2V2 U3V3 U3V3*/
+ "movq 8(%1, %0, 4), %%mm0\n\t"
+ "movq %%mm0, %%mm3\n\t"
+ "punpcklbw %%mm6, %%mm0\n\t" /* Y U2 Y V2 Y U2 Y V2*/
+ "punpckhbw %%mm6, %%mm3\n\t" /* Y U3 Y V3 Y U3 Y V3*/
+ MOVNTQ" %%mm0, 16(%4, %0, 8)\n\t"
+ MOVNTQ" %%mm3, 24(%4, %0, 8)\n\t"
+
+ "movq %%mm4, %%mm6\n\t"
+ "movq 16(%1, %0, 4), %%mm0\n\t"
+ "movq %%mm0, %%mm3\n\t"
+ "punpcklbw %%mm5, %%mm4\n\t"
+ "punpcklbw %%mm4, %%mm0\n\t" /* Y U4 Y V4 Y U4 Y V4*/
+ "punpckhbw %%mm4, %%mm3\n\t" /* Y U5 Y V5 Y U5 Y V5*/
+ MOVNTQ" %%mm0, 32(%4, %0, 8)\n\t"
+ MOVNTQ" %%mm3, 40(%4, %0, 8)\n\t"
+
+ "punpckhbw %%mm5, %%mm6\n\t"
+ "movq 24(%1, %0, 4), %%mm0\n\t"
+ "movq %%mm0, %%mm3\n\t"
+ "punpcklbw %%mm6, %%mm0\n\t" /* Y U6 Y V6 Y U6 Y V6*/
+ "punpckhbw %%mm6, %%mm3\n\t" /* Y U7 Y V7 Y U7 Y V7*/
+ MOVNTQ" %%mm0, 48(%4, %0, 8)\n\t"
+ MOVNTQ" %%mm3, 56(%4, %0, 8)\n\t"
+
+ : "+r" (x)
+ : "r"(yp), "r" (up), "r"(vp), "r"(d)
+ :"memory");
+ }
+#endif
+ for(; x<w; x++)
+ {
+ const long x2= x<<2;
+ d[8*x+0]=yp[x2];
+ d[8*x+1]=up[x];
+ d[8*x+2]=yp[x2+1];
+ d[8*x+3]=vp[x];
+ d[8*x+4]=yp[x2+2];
+ d[8*x+5]=up[x];
+ d[8*x+6]=yp[x2+3];
+ d[8*x+7]=vp[x];
+ }
+ }
+#ifdef HAVE_MMX
+ asm(
+ EMMS" \n\t"
+ SFENCE" \n\t"
+ ::: "memory"
+ );
+#endif
+}
diff --git a/contrib/ffmpeg/libswscale/swscale-example.c b/contrib/ffmpeg/libswscale/swscale-example.c
new file mode 100644
index 000000000..40f04c7d0
--- /dev/null
+++ b/contrib/ffmpeg/libswscale/swscale-example.c
@@ -0,0 +1,229 @@
+/*
+ * Copyright (C) 2003 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include <stdarg.h>
+
+#undef HAVE_AV_CONFIG_H
+#include "avutil.h"
+#include "swscale.h"
+#include "swscale_internal.h"
+#include "rgb2rgb.h"
+
+static uint64_t getSSD(uint8_t *src1, uint8_t *src2, int stride1, int stride2, int w, int h){
+ int x,y;
+ uint64_t ssd=0;
+
+//printf("%d %d\n", w, h);
+
+ for(y=0; y<h; y++){
+ for(x=0; x<w; x++){
+ int d= src1[x + y*stride1] - src2[x + y*stride2];
+ ssd+= d*d;
+//printf("%d", abs(src1[x + y*stride1] - src2[x + y*stride2])/26 );
+ }
+//printf("\n");
+ }
+ return ssd;
+}
+
+// test by ref -> src -> dst -> out & compare out against ref
+// ref & out are YV12
+static int doTest(uint8_t *ref[3], int refStride[3], int w, int h, int srcFormat, int dstFormat,
+ int srcW, int srcH, int dstW, int dstH, int flags){
+ uint8_t *src[3];
+ uint8_t *dst[3];
+ uint8_t *out[3];
+ int srcStride[3], dstStride[3];
+ int i;
+ uint64_t ssdY, ssdU, ssdV;
+ struct SwsContext *srcContext, *dstContext, *outContext;
+ int res;
+
+ res = 0;
+ for(i=0; i<3; i++){
+ // avoid stride % bpp != 0
+ if(srcFormat==PIX_FMT_RGB24 || srcFormat==PIX_FMT_BGR24)
+ srcStride[i]= srcW*3;
+ else
+ srcStride[i]= srcW*4;
+
+ if(dstFormat==PIX_FMT_RGB24 || dstFormat==PIX_FMT_BGR24)
+ dstStride[i]= dstW*3;
+ else
+ dstStride[i]= dstW*4;
+
+ src[i]= (uint8_t*) malloc(srcStride[i]*srcH);
+ dst[i]= (uint8_t*) malloc(dstStride[i]*dstH);
+ out[i]= (uint8_t*) malloc(refStride[i]*h);
+ if ((src[i] == NULL) || (dst[i] == NULL) || (out[i] == NULL)) {
+ perror("Malloc");
+ res = -1;
+
+ goto end;
+ }
+ }
+
+ dstContext = outContext = NULL;
+ srcContext= sws_getContext(w, h, PIX_FMT_YUV420P, srcW, srcH, srcFormat, flags, NULL, NULL, NULL);
+ if (srcContext == NULL) {
+ fprintf(stderr, "Failed to get %s ---> %s\n",
+ sws_format_name(PIX_FMT_YUV420P),
+ sws_format_name(srcFormat));
+ res = -1;
+
+ goto end;
+ }
+ dstContext= sws_getContext(srcW, srcH, srcFormat, dstW, dstH, dstFormat, flags, NULL, NULL, NULL);
+ if (dstContext == NULL) {
+ fprintf(stderr, "Failed to get %s ---> %s\n",
+ sws_format_name(srcFormat),
+ sws_format_name(dstFormat));
+ res = -1;
+
+ goto end;
+ }
+ outContext= sws_getContext(dstW, dstH, dstFormat, w, h, PIX_FMT_YUV420P, flags, NULL, NULL, NULL);
+ if (outContext == NULL) {
+ fprintf(stderr, "Failed to get %s ---> %s\n",
+ sws_format_name(dstFormat),
+ sws_format_name(PIX_FMT_YUV420P));
+ res = -1;
+
+ goto end;
+ }
+// printf("test %X %X %X -> %X %X %X\n", (int)ref[0], (int)ref[1], (int)ref[2],
+// (int)src[0], (int)src[1], (int)src[2]);
+
+ sws_scale(srcContext, ref, refStride, 0, h , src, srcStride);
+ sws_scale(dstContext, src, srcStride, 0, srcH, dst, dstStride);
+ sws_scale(outContext, dst, dstStride, 0, dstH, out, refStride);
+
+#if defined(ARCH_X86)
+ asm volatile ("emms\n\t");
+#endif
+
+ ssdY= getSSD(ref[0], out[0], refStride[0], refStride[0], w, h);
+ ssdU= getSSD(ref[1], out[1], refStride[1], refStride[1], (w+1)>>1, (h+1)>>1);
+ ssdV= getSSD(ref[2], out[2], refStride[2], refStride[2], (w+1)>>1, (h+1)>>1);
+
+ if(srcFormat == PIX_FMT_GRAY8 || dstFormat==PIX_FMT_GRAY8) ssdU=ssdV=0; //FIXME check that output is really gray
+
+ ssdY/= w*h;
+ ssdU/= w*h/4;
+ ssdV/= w*h/4;
+
+ if(ssdY>100 || ssdU>100 || ssdV>100){
+ printf(" %s %dx%d -> %s %4dx%4d flags=%2d SSD=%5lld,%5lld,%5lld\n",
+ sws_format_name(srcFormat), srcW, srcH,
+ sws_format_name(dstFormat), dstW, dstH,
+ flags,
+ ssdY, ssdU, ssdV);
+ }
+
+ end:
+
+ sws_freeContext(srcContext);
+ sws_freeContext(dstContext);
+ sws_freeContext(outContext);
+
+ for(i=0; i<3; i++){
+ free(src[i]);
+ free(dst[i]);
+ free(out[i]);
+ }
+
+ return res;
+}
+
+void fast_memcpy(void *a, void *b, int s){ //FIXME
+ memcpy(a, b, s);
+}
+
+static void selfTest(uint8_t *src[3], int stride[3], int w, int h){
+ enum PixelFormat srcFormat, dstFormat;
+ int srcW, srcH, dstW, dstH;
+ int flags;
+
+ for(srcFormat = 0; srcFormat < PIX_FMT_NB; srcFormat++) {
+ for(dstFormat = 0; dstFormat < PIX_FMT_NB; dstFormat++) {
+ printf("%s -> %s\n",
+ sws_format_name(srcFormat),
+ sws_format_name(dstFormat));
+
+ srcW= w;
+ srcH= h;
+ for(dstW=w - w/3; dstW<= 4*w/3; dstW+= w/3){
+ for(dstH=h - h/3; dstH<= 4*h/3; dstH+= h/3){
+ for(flags=1; flags<33; flags*=2) {
+ int res;
+
+ res = doTest(src, stride, w, h, srcFormat, dstFormat,
+ srcW, srcH, dstW, dstH, flags);
+ if (res < 0) {
+ dstW = 4 * w / 3;
+ dstH = 4 * h / 3;
+ flags = 33;
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+#define W 96
+#define H 96
+
+int main(int argc, char **argv){
+ uint8_t rgb_data[W*H*4];
+ uint8_t *rgb_src[3]= {rgb_data, NULL, NULL};
+ int rgb_stride[3]={4*W, 0, 0};
+ uint8_t data[3][W*H];
+ uint8_t *src[3]= {data[0], data[1], data[2]};
+ int stride[3]={W, W, W};
+ int x, y;
+ struct SwsContext *sws;
+
+ sws= sws_getContext(W/12, H/12, PIX_FMT_RGB32, W, H, PIX_FMT_YUV420P, 2, NULL, NULL, NULL);
+
+ for(y=0; y<H; y++){
+ for(x=0; x<W*4; x++){
+ rgb_data[ x + y*4*W]= random();
+ }
+ }
+#if defined(ARCH_X86)
+ sws_rgb2rgb_init(SWS_CPU_CAPS_MMX*0);
+#else
+ sws_rgb2rgb_init(0);
+#endif
+ sws_scale(sws, rgb_src, rgb_stride, 0, H , src, stride);
+
+#if defined(ARCH_X86)
+ asm volatile ("emms\n\t");
+#endif
+
+ selfTest(src, stride, W, H);
+
+ return 123;
+}
diff --git a/contrib/ffmpeg/libswscale/swscale.c b/contrib/ffmpeg/libswscale/swscale.c
new file mode 100644
index 000000000..f6a23425b
--- /dev/null
+++ b/contrib/ffmpeg/libswscale/swscale.c
@@ -0,0 +1,2868 @@
+/*
+ * Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * the C code (not assembly, mmx, ...) of this file can be used
+ * under the LGPL license too
+ */
+
+/*
+ supported Input formats: YV12, I420/IYUV, YUY2, UYVY, BGR32, BGR24, BGR16, BGR15, RGB32, RGB24, Y8/Y800, YVU9/IF09, PAL8
+ supported output formats: YV12, I420/IYUV, YUY2, UYVY, {BGR,RGB}{1,4,8,15,16,24,32}, Y8/Y800, YVU9/IF09
+ {BGR,RGB}{1,4,8,15,16} support dithering
+
+ unscaled special converters (YV12=I420=IYUV, Y800=Y8)
+ YV12 -> {BGR,RGB}{1,4,8,15,16,24,32}
+ x -> x
+ YUV9 -> YV12
+ YUV9/YV12 -> Y800
+ Y800 -> YUV9/YV12
+ BGR24 -> BGR32 & RGB24 -> RGB32
+ BGR32 -> BGR24 & RGB32 -> RGB24
+ BGR15 -> BGR16
+*/
+
+/*
+tested special converters (most are tested actually but i didnt write it down ...)
+ YV12 -> BGR16
+ YV12 -> YV12
+ BGR15 -> BGR16
+ BGR16 -> BGR16
+ YVU9 -> YV12
+
+untested special converters
+ YV12/I420 -> BGR15/BGR24/BGR32 (its the yuv2rgb stuff, so it should be ok)
+ YV12/I420 -> YV12/I420
+ YUY2/BGR15/BGR24/BGR32/RGB24/RGB32 -> same format
+ BGR24 -> BGR32 & RGB24 -> RGB32
+ BGR32 -> BGR24 & RGB32 -> RGB24
+ BGR24 -> YV12
+*/
+
+#include <inttypes.h>
+#include <string.h>
+#include <math.h>
+#include <stdio.h>
+#include <unistd.h>
+#include "config.h"
+#include <assert.h>
+#ifdef HAVE_SYS_MMAN_H
+#include <sys/mman.h>
+#if defined(MAP_ANON) && !defined(MAP_ANONYMOUS)
+#define MAP_ANONYMOUS MAP_ANON
+#endif
+#endif
+#include "swscale.h"
+#include "swscale_internal.h"
+#include "x86_cpu.h"
+#include "bswap.h"
+#include "rgb2rgb.h"
+#ifdef USE_FASTMEMCPY
+#include "libvo/fastmemcpy.h"
+#endif
+
+#undef MOVNTQ
+#undef PAVGB
+
+//#undef HAVE_MMX2
+//#define HAVE_3DNOW
+//#undef HAVE_MMX
+//#undef ARCH_X86
+//#define WORDS_BIGENDIAN
+#define DITHER1XBPP
+
+#define FAST_BGR2YV12 // use 7 bit coeffs instead of 15bit
+
+#define RET 0xC3 //near return opcode for X86
+
+#ifdef MP_DEBUG
+#define ASSERT(x) assert(x);
+#else
+#define ASSERT(x) ;
+#endif
+
+#ifdef M_PI
+#define PI M_PI
+#else
+#define PI 3.14159265358979323846
+#endif
+
+#define isSupportedIn(x) ((x)==PIX_FMT_YUV420P || (x)==PIX_FMT_YUYV422 || (x)==PIX_FMT_UYVY422\
+ || (x)==PIX_FMT_RGB32|| (x)==PIX_FMT_BGR24|| (x)==PIX_FMT_BGR565|| (x)==PIX_FMT_BGR555\
+ || (x)==PIX_FMT_BGR32|| (x)==PIX_FMT_RGB24|| (x)==PIX_FMT_RGB565|| (x)==PIX_FMT_RGB555\
+ || (x)==PIX_FMT_GRAY8 || (x)==PIX_FMT_YUV410P\
+ || (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)
+#define isSupportedOut(x) ((x)==PIX_FMT_YUV420P || (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)
+#define isPacked(x) ((x)==PIX_FMT_PAL8 || (x)==PIX_FMT_YUYV422 ||\
+ (x)==PIX_FMT_UYVY422 || isRGB(x) || isBGR(x))
+
+#define RGB2YUV_SHIFT 16
+#define BY ((int)( 0.098*(1<<RGB2YUV_SHIFT)+0.5))
+#define BV ((int)(-0.071*(1<<RGB2YUV_SHIFT)+0.5))
+#define BU ((int)( 0.439*(1<<RGB2YUV_SHIFT)+0.5))
+#define GY ((int)( 0.504*(1<<RGB2YUV_SHIFT)+0.5))
+#define GV ((int)(-0.368*(1<<RGB2YUV_SHIFT)+0.5))
+#define GU ((int)(-0.291*(1<<RGB2YUV_SHIFT)+0.5))
+#define RY ((int)( 0.257*(1<<RGB2YUV_SHIFT)+0.5))
+#define RV ((int)( 0.439*(1<<RGB2YUV_SHIFT)+0.5))
+#define RU ((int)(-0.148*(1<<RGB2YUV_SHIFT)+0.5))
+
+extern const int32_t Inverse_Table_6_9[8][4];
+
+/*
+NOTES
+Special versions: fast Y 1:1 scaling (no interpolation in y direction)
+
+TODO
+more intelligent missalignment avoidance for the horizontal scaler
+write special vertical cubic upscale version
+Optimize C code (yv12 / minmax)
+add support for packed pixel yuv input & output
+add support for Y8 output
+optimize bgr24 & bgr32
+add BGR4 output support
+write special BGR->BGR scaler
+*/
+
+#if defined(ARCH_X86) && defined (CONFIG_GPL)
+static uint64_t attribute_used __attribute__((aligned(8))) bF8= 0xF8F8F8F8F8F8F8F8LL;
+static uint64_t attribute_used __attribute__((aligned(8))) bFC= 0xFCFCFCFCFCFCFCFCLL;
+static uint64_t __attribute__((aligned(8))) w10= 0x0010001000100010LL;
+static uint64_t attribute_used __attribute__((aligned(8))) w02= 0x0002000200020002LL;
+static uint64_t attribute_used __attribute__((aligned(8))) bm00001111=0x00000000FFFFFFFFLL;
+static uint64_t attribute_used __attribute__((aligned(8))) bm00000111=0x0000000000FFFFFFLL;
+static uint64_t attribute_used __attribute__((aligned(8))) bm11111000=0xFFFFFFFFFF000000LL;
+static uint64_t attribute_used __attribute__((aligned(8))) bm01010101=0x00FF00FF00FF00FFLL;
+
+static volatile uint64_t attribute_used __attribute__((aligned(8))) b5Dither;
+static volatile uint64_t attribute_used __attribute__((aligned(8))) g5Dither;
+static volatile uint64_t attribute_used __attribute__((aligned(8))) g6Dither;
+static volatile uint64_t attribute_used __attribute__((aligned(8))) r5Dither;
+
+static uint64_t __attribute__((aligned(8))) dither4[2]={
+ 0x0103010301030103LL,
+ 0x0200020002000200LL,};
+
+static uint64_t __attribute__((aligned(8))) dither8[2]={
+ 0x0602060206020602LL,
+ 0x0004000400040004LL,};
+
+static uint64_t __attribute__((aligned(8))) b16Mask= 0x001F001F001F001FLL;
+static uint64_t attribute_used __attribute__((aligned(8))) g16Mask= 0x07E007E007E007E0LL;
+static uint64_t attribute_used __attribute__((aligned(8))) r16Mask= 0xF800F800F800F800LL;
+static uint64_t __attribute__((aligned(8))) b15Mask= 0x001F001F001F001FLL;
+static uint64_t attribute_used __attribute__((aligned(8))) g15Mask= 0x03E003E003E003E0LL;
+static uint64_t attribute_used __attribute__((aligned(8))) r15Mask= 0x7C007C007C007C00LL;
+
+static uint64_t attribute_used __attribute__((aligned(8))) M24A= 0x00FF0000FF0000FFLL;
+static uint64_t attribute_used __attribute__((aligned(8))) M24B= 0xFF0000FF0000FF00LL;
+static uint64_t attribute_used __attribute__((aligned(8))) M24C= 0x0000FF0000FF0000LL;
+
+#ifdef FAST_BGR2YV12
+static const uint64_t bgr2YCoeff attribute_used __attribute__((aligned(8))) = 0x000000210041000DULL;
+static const uint64_t bgr2UCoeff attribute_used __attribute__((aligned(8))) = 0x0000FFEEFFDC0038ULL;
+static const uint64_t bgr2VCoeff attribute_used __attribute__((aligned(8))) = 0x00000038FFD2FFF8ULL;
+#else
+static const uint64_t bgr2YCoeff attribute_used __attribute__((aligned(8))) = 0x000020E540830C8BULL;
+static const uint64_t bgr2UCoeff attribute_used __attribute__((aligned(8))) = 0x0000ED0FDAC23831ULL;
+static const uint64_t bgr2VCoeff attribute_used __attribute__((aligned(8))) = 0x00003831D0E6F6EAULL;
+#endif /* FAST_BGR2YV12 */
+static const uint64_t bgr2YOffset attribute_used __attribute__((aligned(8))) = 0x1010101010101010ULL;
+static const uint64_t bgr2UVOffset attribute_used __attribute__((aligned(8)))= 0x8080808080808080ULL;
+static const uint64_t w1111 attribute_used __attribute__((aligned(8))) = 0x0001000100010001ULL;
+#endif /* defined(ARCH_X86) */
+
+// clipping helper table for C implementations:
+static unsigned char clip_table[768];
+
+static SwsVector *sws_getConvVec(SwsVector *a, SwsVector *b);
+
+extern const uint8_t dither_2x2_4[2][8];
+extern const uint8_t dither_2x2_8[2][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];
+
+static const char * sws_context_to_name(void * ptr) {
+ return "swscaler";
+}
+
+static AVClass sws_context_class = { "SWScaler", sws_context_to_name, NULL };
+
+char *sws_format_name(enum PixelFormat format)
+{
+ switch (format) {
+ case PIX_FMT_YUV420P:
+ return "yuv420p";
+ 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_NV12:
+ return "nv12";
+ case PIX_FMT_NV21:
+ return "nv21";
+ default:
+ return "Unknown format";
+ }
+}
+
+#if defined(ARCH_X86) && defined (CONFIG_GPL)
+void in_asm_used_var_warning_killer()
+{
+ volatile int i= bF8+bFC+w10+
+ bm00001111+bm00000111+bm11111000+b16Mask+g16Mask+r16Mask+b15Mask+g15Mask+r15Mask+
+ M24A+M24B+M24C+w02 + b5Dither+g5Dither+r5Dither+g6Dither+dither4[0]+dither8[0]+bm01010101;
+ if(i) i=0;
+}
+#endif
+
+static inline void yuv2yuvXinC(int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize,
+ int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize,
+ uint8_t *dest, uint8_t *uDest, uint8_t *vDest, int dstW, int chrDstW)
+{
+ //FIXME Optimize (just quickly writen not opti..)
+ int i;
+ for(i=0; i<dstW; i++)
+ {
+ int val=1<<18;
+ int j;
+ for(j=0; j<lumFilterSize; j++)
+ val += lumSrc[j][i] * lumFilter[j];
+
+ dest[i]= av_clip_uint8(val>>19);
+ }
+
+ if(uDest != NULL)
+ for(i=0; i<chrDstW; i++)
+ {
+ int u=1<<18;
+ int v=1<<18;
+ int j;
+ for(j=0; j<chrFilterSize; j++)
+ {
+ u += chrSrc[j][i] * chrFilter[j];
+ v += chrSrc[j][i + 2048] * chrFilter[j];
+ }
+
+ uDest[i]= av_clip_uint8(u>>19);
+ vDest[i]= av_clip_uint8(v>>19);
+ }
+}
+
+static inline void yuv2nv12XinC(int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize,
+ int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize,
+ uint8_t *dest, uint8_t *uDest, int dstW, int chrDstW, int dstFormat)
+{
+ //FIXME Optimize (just quickly writen not opti..)
+ int i;
+ for(i=0; i<dstW; i++)
+ {
+ int val=1<<18;
+ int j;
+ for(j=0; j<lumFilterSize; j++)
+ val += lumSrc[j][i] * lumFilter[j];
+
+ dest[i]= av_clip_uint8(val>>19);
+ }
+
+ if(uDest == NULL)
+ return;
+
+ if(dstFormat == PIX_FMT_NV12)
+ for(i=0; i<chrDstW; i++)
+ {
+ int u=1<<18;
+ int v=1<<18;
+ int j;
+ for(j=0; j<chrFilterSize; j++)
+ {
+ u += chrSrc[j][i] * chrFilter[j];
+ v += chrSrc[j][i + 2048] * chrFilter[j];
+ }
+
+ uDest[2*i]= av_clip_uint8(u>>19);
+ uDest[2*i+1]= av_clip_uint8(v>>19);
+ }
+ else
+ for(i=0; i<chrDstW; i++)
+ {
+ int u=1<<18;
+ int v=1<<18;
+ int j;
+ for(j=0; j<chrFilterSize; j++)
+ {
+ u += chrSrc[j][i] * chrFilter[j];
+ v += chrSrc[j][i + 2048] * chrFilter[j];
+ }
+
+ uDest[2*i]= av_clip_uint8(v>>19);
+ uDest[2*i+1]= av_clip_uint8(u>>19);
+ }
+}
+
+#define YSCALE_YUV_2_PACKEDX_C(type) \
+ for(i=0; i<(dstW>>1); i++){\
+ int j;\
+ int Y1=1<<18;\
+ int Y2=1<<18;\
+ int U=1<<18;\
+ int V=1<<18;\
+ type attribute_unused *r, *b, *g;\
+ const int i2= 2*i;\
+ \
+ for(j=0; j<lumFilterSize; j++)\
+ {\
+ Y1 += lumSrc[j][i2] * lumFilter[j];\
+ Y2 += lumSrc[j][i2+1] * lumFilter[j];\
+ }\
+ for(j=0; j<chrFilterSize; j++)\
+ {\
+ U += chrSrc[j][i] * chrFilter[j];\
+ V += chrSrc[j][i+2048] * chrFilter[j];\
+ }\
+ Y1>>=19;\
+ Y2>>=19;\
+ U >>=19;\
+ V >>=19;\
+ if((Y1|Y2|U|V)&256)\
+ {\
+ if(Y1>255) Y1=255;\
+ else if(Y1<0)Y1=0;\
+ if(Y2>255) Y2=255;\
+ else if(Y2<0)Y2=0;\
+ if(U>255) U=255;\
+ else if(U<0) U=0;\
+ if(V>255) V=255;\
+ else if(V<0) V=0;\
+ }
+
+#define YSCALE_YUV_2_RGBX_C(type) \
+ YSCALE_YUV_2_PACKEDX_C(type)\
+ r = (type *)c->table_rV[V];\
+ g = (type *)(c->table_gU[U] + c->table_gV[V]);\
+ b = (type *)c->table_bU[U];\
+
+#define YSCALE_YUV_2_PACKED2_C \
+ for(i=0; i<(dstW>>1); i++){\
+ const int i2= 2*i;\
+ int Y1= (buf0[i2 ]*yalpha1+buf1[i2 ]*yalpha)>>19;\
+ int Y2= (buf0[i2+1]*yalpha1+buf1[i2+1]*yalpha)>>19;\
+ int U= (uvbuf0[i ]*uvalpha1+uvbuf1[i ]*uvalpha)>>19;\
+ int V= (uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19;\
+
+#define YSCALE_YUV_2_RGB2_C(type) \
+ YSCALE_YUV_2_PACKED2_C\
+ type *r, *b, *g;\
+ r = (type *)c->table_rV[V];\
+ g = (type *)(c->table_gU[U] + c->table_gV[V]);\
+ b = (type *)c->table_bU[U];\
+
+#define YSCALE_YUV_2_PACKED1_C \
+ for(i=0; i<(dstW>>1); i++){\
+ const int i2= 2*i;\
+ int Y1= buf0[i2 ]>>7;\
+ int Y2= buf0[i2+1]>>7;\
+ int U= (uvbuf1[i ])>>7;\
+ int V= (uvbuf1[i+2048])>>7;\
+
+#define YSCALE_YUV_2_RGB1_C(type) \
+ YSCALE_YUV_2_PACKED1_C\
+ type *r, *b, *g;\
+ r = (type *)c->table_rV[V];\
+ g = (type *)(c->table_gU[U] + c->table_gV[V]);\
+ b = (type *)c->table_bU[U];\
+
+#define YSCALE_YUV_2_PACKED1B_C \
+ for(i=0; i<(dstW>>1); i++){\
+ const int i2= 2*i;\
+ int Y1= buf0[i2 ]>>7;\
+ int Y2= buf0[i2+1]>>7;\
+ int U= (uvbuf0[i ] + uvbuf1[i ])>>8;\
+ int V= (uvbuf0[i+2048] + uvbuf1[i+2048])>>8;\
+
+#define YSCALE_YUV_2_RGB1B_C(type) \
+ YSCALE_YUV_2_PACKED1B_C\
+ type *r, *b, *g;\
+ r = (type *)c->table_rV[V];\
+ g = (type *)(c->table_gU[U] + c->table_gV[V]);\
+ b = (type *)c->table_bU[U];\
+
+#define YSCALE_YUV_2_ANYRGB_C(func, func2)\
+ switch(c->dstFormat)\
+ {\
+ case PIX_FMT_RGB32:\
+ case PIX_FMT_BGR32:\
+ func(uint32_t)\
+ ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1];\
+ ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2];\
+ } \
+ break;\
+ case PIX_FMT_RGB24:\
+ func(uint8_t)\
+ ((uint8_t*)dest)[0]= r[Y1];\
+ ((uint8_t*)dest)[1]= g[Y1];\
+ ((uint8_t*)dest)[2]= b[Y1];\
+ ((uint8_t*)dest)[3]= r[Y2];\
+ ((uint8_t*)dest)[4]= g[Y2];\
+ ((uint8_t*)dest)[5]= b[Y2];\
+ dest+=6;\
+ }\
+ break;\
+ case PIX_FMT_BGR24:\
+ func(uint8_t)\
+ ((uint8_t*)dest)[0]= b[Y1];\
+ ((uint8_t*)dest)[1]= g[Y1];\
+ ((uint8_t*)dest)[2]= r[Y1];\
+ ((uint8_t*)dest)[3]= b[Y2];\
+ ((uint8_t*)dest)[4]= g[Y2];\
+ ((uint8_t*)dest)[5]= r[Y2];\
+ dest+=6;\
+ }\
+ break;\
+ case PIX_FMT_RGB565:\
+ case PIX_FMT_BGR565:\
+ {\
+ const int dr1= dither_2x2_8[y&1 ][0];\
+ const int dg1= dither_2x2_4[y&1 ][0];\
+ const int db1= dither_2x2_8[(y&1)^1][0];\
+ const int dr2= dither_2x2_8[y&1 ][1];\
+ const int dg2= dither_2x2_4[y&1 ][1];\
+ const int db2= dither_2x2_8[(y&1)^1][1];\
+ func(uint16_t)\
+ ((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_RGB555:\
+ case PIX_FMT_BGR555:\
+ {\
+ const int dr1= dither_2x2_8[y&1 ][0];\
+ const int dg1= dither_2x2_8[y&1 ][1];\
+ const int db1= dither_2x2_8[(y&1)^1][0];\
+ const int dr2= dither_2x2_8[y&1 ][1];\
+ const int dg2= dither_2x2_8[y&1 ][0];\
+ const int db2= dither_2x2_8[(y&1)^1][1];\
+ func(uint16_t)\
+ ((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:\
+ {\
+ const uint8_t * const d64= dither_8x8_73[y&7];\
+ const uint8_t * const d32= dither_8x8_32[y&7];\
+ func(uint8_t)\
+ ((uint8_t*)dest)[i2+0]= r[Y1+d32[(i2+0)&7]] + g[Y1+d32[(i2+0)&7]] + b[Y1+d64[(i2+0)&7]];\
+ ((uint8_t*)dest)[i2+1]= r[Y2+d32[(i2+1)&7]] + g[Y2+d32[(i2+1)&7]] + b[Y2+d64[(i2+1)&7]];\
+ }\
+ }\
+ break;\
+ case PIX_FMT_RGB4:\
+ case PIX_FMT_BGR4:\
+ {\
+ const uint8_t * const d64= dither_8x8_73 [y&7];\
+ const uint8_t * const d128=dither_8x8_220[y&7];\
+ func(uint8_t)\
+ ((uint8_t*)dest)[i]= r[Y1+d128[(i2+0)&7]] + g[Y1+d64[(i2+0)&7]] + b[Y1+d128[(i2+0)&7]]\
+ + ((r[Y2+d128[(i2+1)&7]] + g[Y2+d64[(i2+1)&7]] + b[Y2+d128[(i2+1)&7]])<<4);\
+ }\
+ }\
+ break;\
+ case PIX_FMT_RGB4_BYTE:\
+ case PIX_FMT_BGR4_BYTE:\
+ {\
+ const uint8_t * const d64= dither_8x8_73 [y&7];\
+ const uint8_t * const d128=dither_8x8_220[y&7];\
+ func(uint8_t)\
+ ((uint8_t*)dest)[i2+0]= r[Y1+d128[(i2+0)&7]] + g[Y1+d64[(i2+0)&7]] + b[Y1+d128[(i2+0)&7]];\
+ ((uint8_t*)dest)[i2+1]= r[Y2+d128[(i2+1)&7]] + g[Y2+d64[(i2+1)&7]] + b[Y2+d128[(i2+1)&7]];\
+ }\
+ }\
+ break;\
+ case PIX_FMT_MONOBLACK:\
+ {\
+ const uint8_t * const d128=dither_8x8_220[y&7];\
+ uint8_t *g= c->table_gU[128] + c->table_gV[128];\
+ for(i=0; i<dstW-7; i+=8){\
+ int acc;\
+ acc = g[((buf0[i ]*yalpha1+buf1[i ]*yalpha)>>19) + d128[0]];\
+ acc+= acc + g[((buf0[i+1]*yalpha1+buf1[i+1]*yalpha)>>19) + d128[1]];\
+ acc+= acc + g[((buf0[i+2]*yalpha1+buf1[i+2]*yalpha)>>19) + d128[2]];\
+ acc+= acc + g[((buf0[i+3]*yalpha1+buf1[i+3]*yalpha)>>19) + d128[3]];\
+ acc+= acc + g[((buf0[i+4]*yalpha1+buf1[i+4]*yalpha)>>19) + d128[4]];\
+ acc+= acc + g[((buf0[i+5]*yalpha1+buf1[i+5]*yalpha)>>19) + d128[5]];\
+ acc+= acc + g[((buf0[i+6]*yalpha1+buf1[i+6]*yalpha)>>19) + d128[6]];\
+ acc+= acc + g[((buf0[i+7]*yalpha1+buf1[i+7]*yalpha)>>19) + d128[7]];\
+ ((uint8_t*)dest)[0]= acc;\
+ dest++;\
+ }\
+\
+/*\
+((uint8_t*)dest)-= dstW>>4;\
+{\
+ int acc=0;\
+ int left=0;\
+ static int top[1024];\
+ static int last_new[1024][1024];\
+ static int last_in3[1024][1024];\
+ static int drift[1024][1024];\
+ int topLeft=0;\
+ int shift=0;\
+ int count=0;\
+ const uint8_t * const d128=dither_8x8_220[y&7];\
+ int error_new=0;\
+ int error_in3=0;\
+ int f=0;\
+ \
+ for(i=dstW>>1; i<dstW; i++){\
+ int in= ((buf0[i ]*yalpha1+buf1[i ]*yalpha)>>19);\
+ int in2 = (76309 * (in - 16) + 32768) >> 16;\
+ int in3 = (in2 < 0) ? 0 : ((in2 > 255) ? 255 : in2);\
+ int old= (left*7 + topLeft + top[i]*5 + top[i+1]*3)/20 + in3\
+ + (last_new[y][i] - in3)*f/256;\
+ int new= old> 128 ? 255 : 0;\
+\
+ error_new+= FFABS(last_new[y][i] - new);\
+ error_in3+= FFABS(last_in3[y][i] - in3);\
+ f= error_new - error_in3*4;\
+ if(f<0) f=0;\
+ if(f>256) f=256;\
+\
+ topLeft= top[i];\
+ left= top[i]= old - new;\
+ last_new[y][i]= new;\
+ last_in3[y][i]= in3;\
+\
+ acc+= acc + (new&1);\
+ if((i&7)==6){\
+ ((uint8_t*)dest)[0]= acc;\
+ ((uint8_t*)dest)++;\
+ }\
+ }\
+}\
+*/\
+ }\
+ break;\
+ case PIX_FMT_YUYV422:\
+ func2\
+ ((uint8_t*)dest)[2*i2+0]= Y1;\
+ ((uint8_t*)dest)[2*i2+1]= U;\
+ ((uint8_t*)dest)[2*i2+2]= Y2;\
+ ((uint8_t*)dest)[2*i2+3]= V;\
+ } \
+ break;\
+ case PIX_FMT_UYVY422:\
+ func2\
+ ((uint8_t*)dest)[2*i2+0]= U;\
+ ((uint8_t*)dest)[2*i2+1]= Y1;\
+ ((uint8_t*)dest)[2*i2+2]= V;\
+ ((uint8_t*)dest)[2*i2+3]= Y2;\
+ } \
+ break;\
+ }\
+
+
+static inline void yuv2packedXinC(SwsContext *c, int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize,
+ int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize,
+ uint8_t *dest, int dstW, int y)
+{
+ int i;
+ switch(c->dstFormat)
+ {
+ case PIX_FMT_BGR32:
+ case PIX_FMT_RGB32:
+ YSCALE_YUV_2_RGBX_C(uint32_t)
+ ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1];
+ ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2];
+ }
+ break;
+ case PIX_FMT_RGB24:
+ YSCALE_YUV_2_RGBX_C(uint8_t)
+ ((uint8_t*)dest)[0]= r[Y1];
+ ((uint8_t*)dest)[1]= g[Y1];
+ ((uint8_t*)dest)[2]= b[Y1];
+ ((uint8_t*)dest)[3]= r[Y2];
+ ((uint8_t*)dest)[4]= g[Y2];
+ ((uint8_t*)dest)[5]= b[Y2];
+ dest+=6;
+ }
+ break;
+ case PIX_FMT_BGR24:
+ YSCALE_YUV_2_RGBX_C(uint8_t)
+ ((uint8_t*)dest)[0]= b[Y1];
+ ((uint8_t*)dest)[1]= g[Y1];
+ ((uint8_t*)dest)[2]= r[Y1];
+ ((uint8_t*)dest)[3]= b[Y2];
+ ((uint8_t*)dest)[4]= g[Y2];
+ ((uint8_t*)dest)[5]= r[Y2];
+ dest+=6;
+ }
+ break;
+ case PIX_FMT_RGB565:
+ case PIX_FMT_BGR565:
+ {
+ const int dr1= dither_2x2_8[y&1 ][0];
+ const int dg1= dither_2x2_4[y&1 ][0];
+ const int db1= dither_2x2_8[(y&1)^1][0];
+ const int dr2= dither_2x2_8[y&1 ][1];
+ const int dg2= dither_2x2_4[y&1 ][1];
+ const int db2= dither_2x2_8[(y&1)^1][1];
+ YSCALE_YUV_2_RGBX_C(uint16_t)
+ ((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_RGB555:
+ case PIX_FMT_BGR555:
+ {
+ const int dr1= dither_2x2_8[y&1 ][0];
+ const int dg1= dither_2x2_8[y&1 ][1];
+ const int db1= dither_2x2_8[(y&1)^1][0];
+ const int dr2= dither_2x2_8[y&1 ][1];
+ const int dg2= dither_2x2_8[y&1 ][0];
+ const int db2= dither_2x2_8[(y&1)^1][1];
+ YSCALE_YUV_2_RGBX_C(uint16_t)
+ ((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:
+ {
+ const uint8_t * const d64= dither_8x8_73[y&7];
+ const uint8_t * const d32= dither_8x8_32[y&7];
+ YSCALE_YUV_2_RGBX_C(uint8_t)
+ ((uint8_t*)dest)[i2+0]= r[Y1+d32[(i2+0)&7]] + g[Y1+d32[(i2+0)&7]] + b[Y1+d64[(i2+0)&7]];
+ ((uint8_t*)dest)[i2+1]= r[Y2+d32[(i2+1)&7]] + g[Y2+d32[(i2+1)&7]] + b[Y2+d64[(i2+1)&7]];
+ }
+ }
+ break;
+ case PIX_FMT_RGB4:
+ case PIX_FMT_BGR4:
+ {
+ const uint8_t * const d64= dither_8x8_73 [y&7];
+ const uint8_t * const d128=dither_8x8_220[y&7];
+ YSCALE_YUV_2_RGBX_C(uint8_t)
+ ((uint8_t*)dest)[i]= r[Y1+d128[(i2+0)&7]] + g[Y1+d64[(i2+0)&7]] + b[Y1+d128[(i2+0)&7]]
+ +((r[Y2+d128[(i2+1)&7]] + g[Y2+d64[(i2+1)&7]] + b[Y2+d128[(i2+1)&7]])<<4);
+ }
+ }
+ break;
+ case PIX_FMT_RGB4_BYTE:
+ case PIX_FMT_BGR4_BYTE:
+ {
+ const uint8_t * const d64= dither_8x8_73 [y&7];
+ const uint8_t * const d128=dither_8x8_220[y&7];
+ YSCALE_YUV_2_RGBX_C(uint8_t)
+ ((uint8_t*)dest)[i2+0]= r[Y1+d128[(i2+0)&7]] + g[Y1+d64[(i2+0)&7]] + b[Y1+d128[(i2+0)&7]];
+ ((uint8_t*)dest)[i2+1]= r[Y2+d128[(i2+1)&7]] + g[Y2+d64[(i2+1)&7]] + b[Y2+d128[(i2+1)&7]];
+ }
+ }
+ break;
+ case PIX_FMT_MONOBLACK:
+ {
+ const uint8_t * const d128=dither_8x8_220[y&7];
+ uint8_t *g= c->table_gU[128] + c->table_gV[128];
+ int acc=0;
+ for(i=0; i<dstW-1; i+=2){
+ int j;
+ int Y1=1<<18;
+ int Y2=1<<18;
+
+ for(j=0; j<lumFilterSize; j++)
+ {
+ Y1 += lumSrc[j][i] * lumFilter[j];
+ Y2 += lumSrc[j][i+1] * lumFilter[j];
+ }
+ Y1>>=19;
+ Y2>>=19;
+ if((Y1|Y2)&256)
+ {
+ if(Y1>255) Y1=255;
+ else if(Y1<0)Y1=0;
+ if(Y2>255) Y2=255;
+ else if(Y2<0)Y2=0;
+ }
+ acc+= acc + g[Y1+d128[(i+0)&7]];
+ acc+= acc + g[Y2+d128[(i+1)&7]];
+ if((i&7)==6){
+ ((uint8_t*)dest)[0]= acc;
+ dest++;
+ }
+ }
+ }
+ break;
+ case PIX_FMT_YUYV422:
+ YSCALE_YUV_2_PACKEDX_C(void)
+ ((uint8_t*)dest)[2*i2+0]= Y1;
+ ((uint8_t*)dest)[2*i2+1]= U;
+ ((uint8_t*)dest)[2*i2+2]= Y2;
+ ((uint8_t*)dest)[2*i2+3]= V;
+ }
+ break;
+ case PIX_FMT_UYVY422:
+ YSCALE_YUV_2_PACKEDX_C(void)
+ ((uint8_t*)dest)[2*i2+0]= U;
+ ((uint8_t*)dest)[2*i2+1]= Y1;
+ ((uint8_t*)dest)[2*i2+2]= V;
+ ((uint8_t*)dest)[2*i2+3]= Y2;
+ }
+ break;
+ }
+}
+
+
+//Note: we have C, X86, MMX, MMX2, 3DNOW version therse no 3DNOW+MMX2 one
+//Plain C versions
+#if !defined (HAVE_MMX) || defined (RUNTIME_CPUDETECT) || !defined(CONFIG_GPL)
+#define COMPILE_C
+#endif
+
+#ifdef ARCH_POWERPC
+#if (defined (HAVE_ALTIVEC) || defined (RUNTIME_CPUDETECT)) && defined (CONFIG_GPL)
+#define COMPILE_ALTIVEC
+#endif //HAVE_ALTIVEC
+#endif //ARCH_POWERPC
+
+#if defined(ARCH_X86)
+
+#if ((defined (HAVE_MMX) && !defined (HAVE_3DNOW) && !defined (HAVE_MMX2)) || defined (RUNTIME_CPUDETECT)) && defined (CONFIG_GPL)
+#define COMPILE_MMX
+#endif
+
+#if (defined (HAVE_MMX2) || defined (RUNTIME_CPUDETECT)) && defined (CONFIG_GPL)
+#define COMPILE_MMX2
+#endif
+
+#if ((defined (HAVE_3DNOW) && !defined (HAVE_MMX2)) || defined (RUNTIME_CPUDETECT)) && defined (CONFIG_GPL)
+#define COMPILE_3DNOW
+#endif
+#endif //ARCH_X86 || ARCH_X86_64
+
+#undef HAVE_MMX
+#undef HAVE_MMX2
+#undef HAVE_3DNOW
+
+#ifdef COMPILE_C
+#undef HAVE_MMX
+#undef HAVE_MMX2
+#undef HAVE_3DNOW
+#undef HAVE_ALTIVEC
+#define RENAME(a) a ## _C
+#include "swscale_template.c"
+#endif
+
+#ifdef ARCH_POWERPC
+#ifdef COMPILE_ALTIVEC
+#undef RENAME
+#define HAVE_ALTIVEC
+#define RENAME(a) a ## _altivec
+#include "swscale_template.c"
+#endif
+#endif //ARCH_POWERPC
+
+#if defined(ARCH_X86)
+
+//X86 versions
+/*
+#undef RENAME
+#undef HAVE_MMX
+#undef HAVE_MMX2
+#undef HAVE_3DNOW
+#define ARCH_X86
+#define RENAME(a) a ## _X86
+#include "swscale_template.c"
+*/
+//MMX versions
+#ifdef COMPILE_MMX
+#undef RENAME
+#define HAVE_MMX
+#undef HAVE_MMX2
+#undef HAVE_3DNOW
+#define RENAME(a) a ## _MMX
+#include "swscale_template.c"
+#endif
+
+//MMX2 versions
+#ifdef COMPILE_MMX2
+#undef RENAME
+#define HAVE_MMX
+#define HAVE_MMX2
+#undef HAVE_3DNOW
+#define RENAME(a) a ## _MMX2
+#include "swscale_template.c"
+#endif
+
+//3DNOW versions
+#ifdef COMPILE_3DNOW
+#undef RENAME
+#define HAVE_MMX
+#undef HAVE_MMX2
+#define HAVE_3DNOW
+#define RENAME(a) a ## _3DNow
+#include "swscale_template.c"
+#endif
+
+#endif //ARCH_X86 || ARCH_X86_64
+
+// minor note: the HAVE_xyz is messed up after that line so don't use it
+
+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;
+ double *filter=NULL;
+ double *filter2=NULL;
+#if defined(ARCH_X86)
+ if(flags & SWS_CPU_CAPS_MMX)
+ asm volatile("emms\n\t"::: "memory"); //FIXME this shouldnt be required but it IS (even for non mmx versions)
+#endif
+
+ // Note the +1 is for the MMXscaler 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_malloc(dstW*sizeof(double)*filterSize);
+ for(i=0; i<dstW*filterSize; i++) filter[i]=0;
+
+ for(i=0; i<dstW; i++)
+ {
+ filter[i*filterSize]=1;
+ (*filterPos)[i]=i;
+ }
+
+ }
+ else if(flags&SWS_POINT) // lame looking point sampling mode
+ {
+ int i;
+ int xDstInSrc;
+ filterSize= 1;
+ filter= av_malloc(dstW*sizeof(double)*filterSize);
+
+ xDstInSrc= xInc/2 - 0x8000;
+ for(i=0; i<dstW; i++)
+ {
+ int xx= (xDstInSrc - ((filterSize-1)<<15) + (1<<15))>>16;
+
+ (*filterPos)[i]= xx;
+ filter[i]= 1.0;
+ xDstInSrc+= xInc;
+ }
+ }
+ else if((xInc <= (1<<16) && (flags&SWS_AREA)) || (flags&SWS_FAST_BILINEAR)) // bilinear upscale
+ {
+ int i;
+ int xDstInSrc;
+ if (flags&SWS_BICUBIC) filterSize= 4;
+ else if(flags&SWS_X ) filterSize= 4;
+ else filterSize= 2; // SWS_BILINEAR / SWS_AREA
+ filter= av_malloc(dstW*sizeof(double)*filterSize);
+
+ xDstInSrc= xInc/2 - 0x8000;
+ for(i=0; i<dstW; i++)
+ {
+ int xx= (xDstInSrc - ((filterSize-1)<<15) + (1<<15))>>16;
+ int j;
+
+ (*filterPos)[i]= xx;
+ //Bilinear upscale / linear interpolate / Area averaging
+ for(j=0; j<filterSize; j++)
+ {
+ double d= FFABS((xx<<16) - xDstInSrc)/(double)(1<<16);
+ double coeff= 1.0 - d;
+ if(coeff<0) coeff=0;
+ filter[i*filterSize + j]= coeff;
+ xx++;
+ }
+ xDstInSrc+= xInc;
+ }
+ }
+ else
+ {
+ double xDstInSrc;
+ double sizeFactor, filterSizeInSrc;
+ const double xInc1= (double)xInc / (double)(1<<16);
+
+ if (flags&SWS_BICUBIC) sizeFactor= 4.0;
+ else if(flags&SWS_X) sizeFactor= 8.0;
+ else if(flags&SWS_AREA) sizeFactor= 1.0; //downscale only, for upscale it is bilinear
+ else if(flags&SWS_GAUSS) sizeFactor= 8.0; // infinite ;)
+ else if(flags&SWS_LANCZOS) sizeFactor= param[0] != SWS_PARAM_DEFAULT ? 2.0*param[0] : 6.0;
+ else if(flags&SWS_SINC) sizeFactor= 20.0; // infinite ;)
+ else if(flags&SWS_SPLINE) sizeFactor= 20.0; // infinite ;)
+ else if(flags&SWS_BILINEAR) sizeFactor= 2.0;
+ else {
+ sizeFactor= 0.0; //GCC warning killer
+ ASSERT(0)
+ }
+
+ if(xInc1 <= 1.0) filterSizeInSrc= sizeFactor; // upscale
+ else filterSizeInSrc= sizeFactor*srcW / (double)dstW;
+
+ filterSize= (int)ceil(1 + filterSizeInSrc); // will be reduced later if possible
+ if(filterSize > srcW-2) filterSize=srcW-2;
+
+ filter= av_malloc(dstW*sizeof(double)*filterSize);
+
+ xDstInSrc= xInc1 / 2.0 - 0.5;
+ for(i=0; i<dstW; i++)
+ {
+ int xx= (int)(xDstInSrc - (filterSize-1)*0.5 + 0.5);
+ int j;
+ (*filterPos)[i]= xx;
+ for(j=0; j<filterSize; j++)
+ {
+ double d= FFABS(xx - xDstInSrc)/filterSizeInSrc*sizeFactor;
+ double coeff;
+ if(flags & SWS_BICUBIC)
+ {
+ double B= param[0] != SWS_PARAM_DEFAULT ? param[0] : 0.0;
+ double C= param[1] != SWS_PARAM_DEFAULT ? param[1] : 0.6;
+
+ if(d<1.0)
+ coeff = (12-9*B-6*C)*d*d*d + (-18+12*B+6*C)*d*d + 6-2*B;
+ else if(d<2.0)
+ coeff = (-B-6*C)*d*d*d + (6*B+30*C)*d*d + (-12*B-48*C)*d +8*B+24*C;
+ else
+ coeff=0.0;
+ }
+/* 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;
+
+ if(d<1.0)
+ coeff = cos(d*PI);
+ else
+ coeff=-1.0;
+ if(coeff<0.0) coeff= -pow(-coeff, A);
+ else coeff= pow( coeff, A);
+ coeff= coeff*0.5 + 0.5;
+ }
+ else if(flags & SWS_AREA)
+ {
+ double srcPixelSize= 1.0/xInc1;
+ if(d + srcPixelSize/2 < 0.5) coeff= 1.0;
+ else if(d - srcPixelSize/2 < 0.5) coeff= (0.5-d)/srcPixelSize + 0.5;
+ else coeff=0.0;
+ }
+ else if(flags & SWS_GAUSS)
+ {
+ double p= param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0;
+ coeff = pow(2.0, - p*d*d);
+ }
+ else if(flags & SWS_SINC)
+ {
+ coeff = d ? sin(d*PI)/(d*PI) : 1.0;
+ }
+ else if(flags & SWS_LANCZOS)
+ {
+ double p= param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0;
+ coeff = d ? sin(d*PI)*sin(d*PI/p)/(d*d*PI*PI/p) : 1.0;
+ if(d>p) coeff=0;
+ }
+ else if(flags & SWS_BILINEAR)
+ {
+ coeff= 1.0 - d;
+ if(coeff<0) coeff=0;
+ }
+ else if(flags & SWS_SPLINE)
+ {
+ double p=-2.196152422706632;
+ coeff = getSplineCoeff(1.0, 0.0, p, -p-1.0, d);
+ }
+ else {
+ coeff= 0.0; //GCC warning killer
+ ASSERT(0)
+ }
+
+ filter[i*filterSize + j]= coeff;
+ xx++;
+ }
+ xDstInSrc+= xInc1;
+ }
+ }
+
+ /* 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_malloc(filter2Size*dstW*sizeof(double));
+
+ for(i=0; i<dstW; i++)
+ {
+ int j;
+ SwsVector scaleFilter;
+ SwsVector *outVec;
+
+ scaleFilter.coeff= filter + i*filterSize;
+ scaleFilter.length= filterSize;
+
+ if(srcFilter) outVec= sws_getConvVec(srcFilter, &scaleFilter);
+ else outVec= &scaleFilter;
+
+ ASSERT(outVec->length == filter2Size)
+ //FIXME dstFilter
+
+ for(j=0; j<outVec->length; j++)
+ {
+ filter2[i*filter2Size + j]= outVec->coeff[j];
+ }
+
+ (*filterPos)[i]+= (filterSize-1)/2 - (filter2Size-1)/2;
+
+ if(outVec != &scaleFilter) sws_freeVec(outVec);
+ }
+ av_free(filter); filter=NULL;
+
+ /* try to reduce the filter-size (step1 find size and shift left) */
+ // Assume its near normalized (*0.5 or *2.0 is ok but * 0.001 is not)
+ minFilterSize= 0;
+ for(i=dstW-1; i>=0; i--)
+ {
+ int min= filter2Size;
+ int j;
+ double cutOff=0.0;
+
+ /* get rid off near zero elements on the left by shifting left */
+ for(j=0; j<filter2Size; j++)
+ {
+ int k;
+ cutOff += FFABS(filter2[i*filter2Size]);
+
+ if(cutOff > SWS_MAX_REDUCE_CUTOFF) break;
+
+ /* preserve Monotonicity because the core can't handle the filter otherwise */
+ if(i<dstW-1 && (*filterPos)[i] >= (*filterPos)[i+1]) break;
+
+ // Move filter coeffs left
+ for(k=1; k<filter2Size; k++)
+ filter2[i*filter2Size + k - 1]= filter2[i*filter2Size + k];
+ filter2[i*filter2Size + k - 1]= 0.0;
+ (*filterPos)[i]++;
+ }
+
+ cutOff=0.0;
+ /* count near zeros on the right */
+ for(j=filter2Size-1; j>0; j--)
+ {
+ cutOff += FFABS(filter2[i*filter2Size + j]);
+
+ if(cutOff > SWS_MAX_REDUCE_CUTOFF) 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 filter.
+ // vectorizing is worth it only if you have
+ // 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(double));
+ if(filterSize >= MAX_FILTER_SIZE)
+ return -1;
+ *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<dstW; i++)
+ {
+ int j;
+
+ for(j=0; j<filterSize; j++)
+ {
+ if(j>=filter2Size) filter[i*filterSize + j]= 0.0;
+ else filter[i*filterSize + j]= filter2[i*filter2Size + j];
+ }
+ }
+ av_free(filter2); filter2=NULL;
+
+
+ //FIXME try to align filterpos if possible
+
+ //fix borders
+ for(i=0; i<dstW; i++)
+ {
+ int j;
+ if((*filterPos)[i] < 0)
+ {
+ // Move filter coeffs left to compensate for filterPos
+ for(j=1; j<filterSize; j++)
+ {
+ int left= FFMAX(j + (*filterPos)[i], 0);
+ filter[i*filterSize + left] += filter[i*filterSize + j];
+ filter[i*filterSize + j]=0;
+ }
+ (*filterPos)[i]= 0;
+ }
+
+ if((*filterPos)[i] + filterSize > srcW)
+ {
+ int shift= (*filterPos)[i] + filterSize - srcW;
+ // Move filter coeffs 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 MMXscaler 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<dstW; i++)
+ {
+ int j;
+ double error=0;
+ double sum=0;
+ double scale= one;
+
+ for(j=0; j<filterSize; j++)
+ {
+ sum+= filter[i*filterSize + j];
+ }
+ scale/= sum;
+ for(j=0; j<*outFilterSize; j++)
+ {
+ double v= filter[i*filterSize + j]*scale + error;
+ int intV= floor(v + 0.5);
+ (*outFilter)[i*(*outFilterSize) + j]= intV;
+ error = v - intV;
+ }
+ }
+
+ (*filterPos)[dstW]= (*filterPos)[dstW-1]; // the MMX scaler will read over the end
+ for(i=0; i<*outFilterSize; i++)
+ {
+ int j= dstW*(*outFilterSize);
+ (*outFilter)[j + i]= (*outFilter)[j + i - (*outFilterSize)];
+ }
+
+ av_free(filter);
+ return 0;
+}
+
+#ifdef COMPILE_MMX2
+static void initMMX2HScaler(int dstW, int xInc, uint8_t *funnyCode, int16_t *filter, int32_t *filterPos, int numSplits)
+{
+ uint8_t *fragmentA;
+ long imm8OfPShufW1A;
+ long imm8OfPShufW2A;
+ long fragmentLengthA;
+ uint8_t *fragmentB;
+ long imm8OfPShufW1B;
+ long imm8OfPShufW2B;
+ long fragmentLengthB;
+ int fragmentPos;
+
+ int xpos, i;
+
+ // create an optimized horizontal scaling routine
+
+ //code fragment
+
+ asm volatile(
+ "jmp 9f \n\t"
+ // Begin
+ "0: \n\t"
+ "movq (%%"REG_d", %%"REG_a"), %%mm3\n\t"
+ "movd (%%"REG_c", %%"REG_S"), %%mm0\n\t"
+ "movd 1(%%"REG_c", %%"REG_S"), %%mm1\n\t"
+ "punpcklbw %%mm7, %%mm1 \n\t"
+ "punpcklbw %%mm7, %%mm0 \n\t"
+ "pshufw $0xFF, %%mm1, %%mm1 \n\t"
+ "1: \n\t"
+ "pshufw $0xFF, %%mm0, %%mm0 \n\t"
+ "2: \n\t"
+ "psubw %%mm1, %%mm0 \n\t"
+ "movl 8(%%"REG_b", %%"REG_a"), %%esi\n\t"
+ "pmullw %%mm3, %%mm0 \n\t"
+ "psllw $7, %%mm1 \n\t"
+ "paddw %%mm1, %%mm0 \n\t"
+
+ "movq %%mm0, (%%"REG_D", %%"REG_a")\n\t"
+
+ "add $8, %%"REG_a" \n\t"
+ // End
+ "9: \n\t"
+// "int $3\n\t"
+ "lea 0b, %0 \n\t"
+ "lea 1b, %1 \n\t"
+ "lea 2b, %2 \n\t"
+ "dec %1 \n\t"
+ "dec %2 \n\t"
+ "sub %0, %1 \n\t"
+ "sub %0, %2 \n\t"
+ "lea 9b, %3 \n\t"
+ "sub %0, %3 \n\t"
+
+
+ :"=r" (fragmentA), "=r" (imm8OfPShufW1A), "=r" (imm8OfPShufW2A),
+ "=r" (fragmentLengthA)
+ );
+
+ asm volatile(
+ "jmp 9f \n\t"
+ // Begin
+ "0: \n\t"
+ "movq (%%"REG_d", %%"REG_a"), %%mm3\n\t"
+ "movd (%%"REG_c", %%"REG_S"), %%mm0\n\t"
+ "punpcklbw %%mm7, %%mm0 \n\t"
+ "pshufw $0xFF, %%mm0, %%mm1 \n\t"
+ "1: \n\t"
+ "pshufw $0xFF, %%mm0, %%mm0 \n\t"
+ "2: \n\t"
+ "psubw %%mm1, %%mm0 \n\t"
+ "movl 8(%%"REG_b", %%"REG_a"), %%esi\n\t"
+ "pmullw %%mm3, %%mm0 \n\t"
+ "psllw $7, %%mm1 \n\t"
+ "paddw %%mm1, %%mm0 \n\t"
+
+ "movq %%mm0, (%%"REG_D", %%"REG_a")\n\t"
+
+ "add $8, %%"REG_a" \n\t"
+ // End
+ "9: \n\t"
+// "int $3\n\t"
+ "lea 0b, %0 \n\t"
+ "lea 1b, %1 \n\t"
+ "lea 2b, %2 \n\t"
+ "dec %1 \n\t"
+ "dec %2 \n\t"
+ "sub %0, %1 \n\t"
+ "sub %0, %2 \n\t"
+ "lea 9b, %3 \n\t"
+ "sub %0, %3 \n\t"
+
+
+ :"=r" (fragmentB), "=r" (imm8OfPShufW1B), "=r" (imm8OfPShufW2B),
+ "=r" (fragmentLengthB)
+ );
+
+ xpos= 0; //lumXInc/2 - 0x8000; // difference between pixel centers
+ fragmentPos=0;
+
+ for(i=0; i<dstW/numSplits; i++)
+ {
+ int xx=xpos>>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;
+
+ 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;
+
+ if(d+1<4)
+ {
+ int maxShift= 3-(d+1);
+ int shift=0;
+
+ memcpy(funnyCode + fragmentPos, fragmentB, fragmentLengthB);
+
+ funnyCode[fragmentPos + imm8OfPShufW1B]=
+ (a+1) | ((b+1)<<2) | ((c+1)<<4) | ((d+1)<<6);
+ funnyCode[fragmentPos + imm8OfPShufW2B]=
+ a | (b<<2) | (c<<4) | (d<<6);
+
+ if(i+3>=dstW) shift=maxShift; //avoid overread
+ else if((filterPos[i/2]&3) <= maxShift) shift=filterPos[i/2]&3; //Align
+
+ if(shift && i>=shift)
+ {
+ funnyCode[fragmentPos + imm8OfPShufW1B]+= 0x55*shift;
+ funnyCode[fragmentPos + imm8OfPShufW2B]+= 0x55*shift;
+ filterPos[i/2]-=shift;
+ }
+
+ fragmentPos+= fragmentLengthB;
+ }
+ else
+ {
+ int maxShift= 3-d;
+ int shift=0;
+
+ memcpy(funnyCode + fragmentPos, fragmentA, fragmentLengthA);
+
+ funnyCode[fragmentPos + imm8OfPShufW1A]=
+ funnyCode[fragmentPos + imm8OfPShufW2A]=
+ a | (b<<2) | (c<<4) | (d<<6);
+
+ if(i+4>=dstW) shift=maxShift; //avoid overread
+ else if((filterPos[i/2]&3) <= maxShift) shift=filterPos[i/2]&3; //partial align
+
+ if(shift && i>=shift)
+ {
+ funnyCode[fragmentPos + imm8OfPShufW1A]+= 0x55*shift;
+ funnyCode[fragmentPos + imm8OfPShufW2A]+= 0x55*shift;
+ filterPos[i/2]-=shift;
+ }
+
+ fragmentPos+= fragmentLengthA;
+ }
+
+ funnyCode[fragmentPos]= RET;
+ }
+ xpos+=xInc;
+ }
+ filterPos[i/2]= xpos>>16; // needed to jump to the next part
+}
+#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(int flags){
+
+#if defined(RUNTIME_CPUDETECT) && defined (CONFIG_GPL)
+#if defined(ARCH_X86)
+ // ordered per speed fasterst first
+ if(flags & SWS_CPU_CAPS_MMX2)
+ return swScale_MMX2;
+ else if(flags & SWS_CPU_CAPS_3DNOW)
+ return swScale_3DNow;
+ else if(flags & SWS_CPU_CAPS_MMX)
+ return swScale_MMX;
+ else
+ return swScale_C;
+
+#else
+#ifdef ARCH_POWERPC
+ if(flags & SWS_CPU_CAPS_ALTIVEC)
+ return swScale_altivec;
+ else
+ return swScale_C;
+#endif
+ return swScale_C;
+#endif /* defined(ARCH_X86) */
+#else //RUNTIME_CPUDETECT
+#ifdef HAVE_MMX2
+ return swScale_MMX2;
+#elif defined (HAVE_3DNOW)
+ return swScale_3DNow;
+#elif defined (HAVE_MMX)
+ return swScale_MMX;
+#elif defined (HAVE_ALTIVEC)
+ return swScale_altivec;
+#else
+ return swScale_C;
+#endif
+#endif //!RUNTIME_CPUDETECT
+}
+
+static int PlanarToNV12Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+ int srcSliceH, uint8_t* dstParam[], int dstStride[]){
+ uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY;
+ /* Copy Y plane */
+ if(dstStride[0]==srcStride[0] && srcStride[0] > 0)
+ memcpy(dst, src[0], srcSliceH*dstStride[0]);
+ else
+ {
+ int i;
+ uint8_t *srcPtr= src[0];
+ uint8_t *dstPtr= dst;
+ for(i=0; i<srcSliceH; i++)
+ {
+ memcpy(dstPtr, srcPtr, c->srcW);
+ srcPtr+= srcStride[0];
+ dstPtr+= dstStride[0];
+ }
+ }
+ dst = dstParam[1] + dstStride[1]*srcSliceY/2;
+ if (c->dstFormat == PIX_FMT_NV12)
+ interleaveBytes( src[1],src[2],dst,c->srcW/2,srcSliceH/2,srcStride[1],srcStride[2],dstStride[0] );
+ else
+ interleaveBytes( src[2],src[1],dst,c->srcW/2,srcSliceH/2,srcStride[2],srcStride[1],dstStride[0] );
+
+ return srcSliceH;
+}
+
+static int PlanarToYuy2Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+ int srcSliceH, uint8_t* dstParam[], int dstStride[]){
+ uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY;
+
+ yv12toyuy2( src[0],src[1],src[2],dst,c->srcW,srcSliceH,srcStride[0],srcStride[1],dstStride[0] );
+
+ return srcSliceH;
+}
+
+static int PlanarToUyvyWrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+ int srcSliceH, uint8_t* dstParam[], int dstStride[]){
+ uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY;
+
+ yv12touyvy( src[0],src[1],src[2],dst,c->srcW,srcSliceH,srcStride[0],srcStride[1],dstStride[0] );
+
+ return srcSliceH;
+}
+
+/* {RGB,BGR}{15,16,24,32} -> {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[]){
+ const int srcFormat= c->srcFormat;
+ const int 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;
+ void (*conv)(const uint8_t *src, uint8_t *dst, long src_size)=NULL;
+
+ /* BGR -> BGR */
+ if( (isBGR(srcFormat) && isBGR(dstFormat))
+ || (isRGB(srcFormat) && isRGB(dstFormat))){
+ switch(srcId | (dstId<<4)){
+ case 0x34: conv= rgb16to15; break;
+ case 0x36: conv= rgb24to15; break;
+ case 0x38: conv= rgb32to15; break;
+ case 0x43: conv= rgb15to16; break;
+ case 0x46: conv= rgb24to16; break;
+ case 0x48: conv= rgb32to16; break;
+ case 0x63: conv= rgb15to24; break;
+ case 0x64: conv= rgb16to24; break;
+ case 0x68: conv= rgb32to24; break;
+ case 0x83: conv= rgb15to32; break;
+ case 0x84: conv= rgb16to32; break;
+ case 0x86: conv= rgb24to32; break;
+ default: av_log(c, AV_LOG_ERROR, "swScaler: 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))){
+ switch(srcId | (dstId<<4)){
+ case 0x33: conv= rgb15tobgr15; break;
+ case 0x34: conv= rgb16tobgr15; break;
+ case 0x36: conv= rgb24tobgr15; break;
+ case 0x38: conv= rgb32tobgr15; break;
+ case 0x43: conv= rgb15tobgr16; break;
+ case 0x44: conv= rgb16tobgr16; break;
+ case 0x46: conv= rgb24tobgr16; break;
+ case 0x48: conv= rgb32tobgr16; break;
+ case 0x63: conv= rgb15tobgr24; break;
+ case 0x64: conv= rgb16tobgr24; break;
+ case 0x66: conv= rgb24tobgr24; break;
+ case 0x68: conv= rgb32tobgr24; break;
+ 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, "swScaler: internal error %s -> %s converter\n",
+ sws_format_name(srcFormat), sws_format_name(dstFormat)); break;
+ }
+ }else{
+ av_log(c, AV_LOG_ERROR, "swScaler: internal error %s -> %s converter\n",
+ sws_format_name(srcFormat), sws_format_name(dstFormat));
+ }
+
+ if(dstStride[0]*srcBpp == srcStride[0]*dstBpp)
+ conv(src[0], dst[0] + dstStride[0]*srcSliceY, srcSliceH*srcStride[0]);
+ else
+ {
+ int i;
+ uint8_t *srcPtr= src[0];
+ uint8_t *dstPtr= dst[0] + dstStride[0]*srcSliceY;
+
+ for(i=0; i<srcSliceH; i++)
+ {
+ conv(srcPtr, dstPtr, c->srcW*srcBpp);
+ srcPtr+= srcStride[0];
+ dstPtr+= dstStride[0];
+ }
+ }
+ return srcSliceH;
+}
+
+static int bgr24toyv12Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+ int srcSliceH, uint8_t* dst[], int dstStride[]){
+
+ rgb24toyv12(
+ src[0],
+ dst[0]+ srcSliceY *dstStride[0],
+ dst[1]+(srcSliceY>>1)*dstStride[1],
+ dst[2]+(srcSliceY>>1)*dstStride[2],
+ c->srcW, srcSliceH,
+ dstStride[0], dstStride[1], srcStride[0]);
+ return srcSliceH;
+}
+
+static int yvu9toyv12Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+ int srcSliceH, uint8_t* dst[], int dstStride[]){
+ int i;
+
+ /* copy Y */
+ 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];
+ uint8_t *dstPtr= dst[0] + dstStride[0]*srcSliceY;
+
+ for(i=0; i<srcSliceH; i++)
+ {
+ memcpy(dstPtr, srcPtr, c->srcW);
+ srcPtr+= srcStride[0];
+ dstPtr+= dstStride[0];
+ }
+ }
+
+ if(c->dstFormat==PIX_FMT_YUV420P){
+ planar2x(src[1], dst[1], c->chrSrcW, c->chrSrcH, srcStride[1], dstStride[1]);
+ planar2x(src[2], dst[2], c->chrSrcW, c->chrSrcH, srcStride[2], dstStride[2]);
+ }else{
+ planar2x(src[1], dst[2], c->chrSrcW, c->chrSrcH, srcStride[1], dstStride[2]);
+ planar2x(src[2], dst[1], c->chrSrcW, c->chrSrcH, srcStride[2], dstStride[1]);
+ }
+ return srcSliceH;
+}
+
+/* unscaled copy like stuff (assumes nearly identical formats) */
+static int simpleCopy(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+ int srcSliceH, uint8_t* dst[], int dstStride[]){
+
+ if(isPacked(c->srcFormat))
+ {
+ if(dstStride[0]==srcStride[0] && srcStride[0] > 0)
+ memcpy(dst[0] + dstStride[0]*srcSliceY, src[0], srcSliceH*dstStride[0]);
+ else
+ {
+ int i;
+ uint8_t *srcPtr= src[0];
+ uint8_t *dstPtr= dst[0] + dstStride[0]*srcSliceY;
+ int length=0;
+
+ /* universal length finder */
+ while(length+c->srcW <= FFABS(dstStride[0])
+ && length+c->srcW <= FFABS(srcStride[0])) length+= c->srcW;
+ ASSERT(length!=0);
+
+ for(i=0; i<srcSliceH; i++)
+ {
+ memcpy(dstPtr, srcPtr, length);
+ srcPtr+= srcStride[0];
+ dstPtr+= dstStride[0];
+ }
+ }
+ }
+ else
+ { /* Planar YUV or gray */
+ int plane;
+ for(plane=0; plane<3; plane++)
+ {
+ int length= plane==0 ? c->srcW : -((-c->srcW )>>c->chrDstHSubSample);
+ int y= plane==0 ? srcSliceY: -((-srcSliceY)>>c->chrDstVSubSample);
+ int height= plane==0 ? srcSliceH: -((-srcSliceH)>>c->chrDstVSubSample);
+
+ if((isGray(c->srcFormat) || isGray(c->dstFormat)) && plane>0)
+ {
+ if(!isGray(c->dstFormat))
+ memset(dst[plane], 128, dstStride[plane]*height);
+ }
+ else
+ {
+ if(dstStride[plane]==srcStride[plane] && srcStride[plane] > 0)
+ memcpy(dst[plane] + dstStride[plane]*y, src[plane], height*dstStride[plane]);
+ else
+ {
+ int i;
+ uint8_t *srcPtr= src[plane];
+ uint8_t *dstPtr= dst[plane] + dstStride[plane]*y;
+ for(i=0; i<height; i++)
+ {
+ memcpy(dstPtr, srcPtr, length);
+ srcPtr+= srcStride[plane];
+ dstPtr+= dstStride[plane];
+ }
+ }
+ }
+ }
+ }
+ return srcSliceH;
+}
+
+static int gray16togray(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+ int srcSliceH, uint8_t* dst[], int dstStride[]){
+
+ int length= c->srcW;
+ int y= srcSliceY;
+ int height= srcSliceH;
+ int i, j;
+ uint8_t *srcPtr= src[0];
+ uint8_t *dstPtr= dst[0] + dstStride[0]*y;
+
+ if(!isGray(c->dstFormat)){
+ int height= -((-srcSliceH)>>c->chrDstVSubSample);
+ memset(dst[1], 128, dstStride[1]*height);
+ memset(dst[2], 128, dstStride[2]*height);
+ }
+ if(c->srcFormat == PIX_FMT_GRAY16LE) srcPtr++;
+ for(i=0; i<height; i++)
+ {
+ for(j=0; j<length; j++) dstPtr[j] = srcPtr[j<<1];
+ srcPtr+= srcStride[0];
+ dstPtr+= dstStride[0];
+ }
+ return srcSliceH;
+}
+
+static int graytogray16(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+ int srcSliceH, uint8_t* dst[], int dstStride[]){
+
+ int length= c->srcW;
+ int y= srcSliceY;
+ int height= srcSliceH;
+ int i, j;
+ uint8_t *srcPtr= src[0];
+ uint8_t *dstPtr= dst[0] + dstStride[0]*y;
+ for(i=0; i<height; i++)
+ {
+ for(j=0; j<length; j++)
+ {
+ dstPtr[j<<1] = srcPtr[j];
+ dstPtr[(j<<1)+1] = srcPtr[j];
+ }
+ srcPtr+= srcStride[0];
+ dstPtr+= dstStride[0];
+ }
+ return srcSliceH;
+}
+
+static int gray16swap(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+ int srcSliceH, uint8_t* dst[], int dstStride[]){
+
+ int length= c->srcW;
+ int y= srcSliceY;
+ int height= srcSliceH;
+ int i, j;
+ uint16_t *srcPtr= src[0];
+ uint16_t *dstPtr= dst[0] + dstStride[0]*y/2;
+ for(i=0; i<height; i++)
+ {
+ for(j=0; j<length; j++) dstPtr[j] = bswap_16(srcPtr[j]);
+ srcPtr+= srcStride[0]/2;
+ dstPtr+= dstStride[0]/2;
+ }
+ return srcSliceH;
+}
+
+
+static void getSubSampleFactors(int *h, int *v, int format){
+ switch(format){
+ case PIX_FMT_UYVY422:
+ case PIX_FMT_YUYV422:
+ *h=1;
+ *v=0;
+ break;
+ case PIX_FMT_YUV420P:
+ case PIX_FMT_GRAY16BE:
+ case PIX_FMT_GRAY16LE:
+ case PIX_FMT_GRAY8: //FIXME remove after different subsamplings are fully implemented
+ case PIX_FMT_NV12:
+ case PIX_FMT_NV21:
+ *h=1;
+ *v=1;
+ break;
+ case PIX_FMT_YUV410P:
+ *h=2;
+ *v=2;
+ break;
+ case PIX_FMT_YUV444P:
+ *h=0;
+ *v=0;
+ break;
+ case PIX_FMT_YUV422P:
+ *h=1;
+ *v=0;
+ break;
+ case PIX_FMT_YUV411P:
+ *h=2;
+ *v=0;
+ break;
+ default:
+ *h=0;
+ *v=0;
+ break;
+ }
+}
+
+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;
+}
+
+/**
+ * @param inv_table the yuv2rgb coeffs, normally Inverse_Table_6_9[x]
+ * @param fullRange if 1 then the luma range is 0..255 if 0 its 16..235
+ * @return -1 if not supported
+ */
+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;
+
+ if(isYUV(c->dstFormat) || isGray(c->dstFormat)) return -1;
+ 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;
+
+ 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;
+
+ yuv2rgb_c_init_tables(c, inv_table, srcRange, brightness, contrast, saturation);
+ //FIXME factorize
+
+#ifdef COMPILE_ALTIVEC
+ if (c->flags & SWS_CPU_CAPS_ALTIVEC)
+ yuv2rgb_altivec_init_tables (c, inv_table, brightness, contrast, saturation);
+#endif
+ return 0;
+}
+
+/**
+ * @return -1 if not supported
+ */
+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(int *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;
+ default:
+ return 0;
+ }
+}
+
+SwsContext *sws_getContext(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags,
+ SwsFilter *srcFilter, SwsFilter *dstFilter, double *param){
+
+ SwsContext *c;
+ int i;
+ int usesVFilter, usesHFilter;
+ int unscaled, needsDither;
+ int srcRange, dstRange;
+ SwsFilter dummyFilter= {NULL, NULL, NULL, NULL};
+#if defined(ARCH_X86)
+ if(flags & SWS_CPU_CAPS_MMX)
+ asm volatile("emms\n\t"::: "memory");
+#endif
+
+#if !defined(RUNTIME_CPUDETECT) || !defined (CONFIG_GPL) //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);
+#ifdef HAVE_MMX2
+ flags |= SWS_CPU_CAPS_MMX|SWS_CPU_CAPS_MMX2;
+#elif defined (HAVE_3DNOW)
+ flags |= SWS_CPU_CAPS_MMX|SWS_CPU_CAPS_3DNOW;
+#elif defined (HAVE_MMX)
+ flags |= SWS_CPU_CAPS_MMX;
+#elif defined (HAVE_ALTIVEC)
+ flags |= SWS_CPU_CAPS_ALTIVEC;
+#endif
+#endif /* RUNTIME_CPUDETECT */
+ if(clip_table[512] != 255) globalInit();
+ if(rgb15to16 == NULL) 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 format\n", sws_format_name(srcFormat));
+ return NULL;
+ }
+ if(!isSupportedOut(dstFormat))
+ {
+ av_log(NULL, AV_LOG_ERROR, "swScaler: %s is not supported as output format\n", sws_format_name(dstFormat));
+ 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(!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!=NULL && dstFilter->lumV->length>1) usesVFilter=1;
+ if(dstFilter->lumH!=NULL && dstFilter->lumH->length>1) usesHFilter=1;
+ if(dstFilter->chrV!=NULL && dstFilter->chrV->length>1) usesVFilter=1;
+ if(dstFilter->chrH!=NULL && dstFilter->chrH->length>1) usesHFilter=1;
+ if(srcFilter->lumV!=NULL && srcFilter->lumV->length>1) usesVFilter=1;
+ if(srcFilter->lumH!=NULL && srcFilter->lumH->length>1) usesHFilter=1;
+ if(srcFilter->chrV!=NULL && srcFilter->chrV->length>1) usesVFilter=1;
+ if(srcFilter->chrH!=NULL && srcFilter->chrH->length>1) usesHFilter=1;
+
+ getSubSampleFactors(&c->chrSrcHSubSample, &c->chrSrcVSubSample, srcFormat);
+ getSubSampleFactors(&c->chrDstHSubSample, &c->chrDstVSubSample, dstFormat);
+
+ // reuse chroma for 2 pixles 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 2. pixel for chroma calculation unless user wants full chroma
+ if((isBGR(srcFormat) || isRGB(srcFormat)) && !(flags&SWS_FULL_CHR_H_INP))
+ 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;
+ }
+
+ c->chrIntHSubSample= c->chrDstHSubSample;
+ c->chrIntVSubSample= c->chrSrcVSubSample;
+
+ // note the -((-x)>>y) is so that we allways 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, Inverse_Table_6_9[SWS_CS_DEFAULT], srcRange, Inverse_Table_6_9[SWS_CS_DEFAULT] /* FIXME*/, dstRange, 0, 1<<16, 1<<16);
+
+ /* unscaled special Cases */
+ if(unscaled && !usesHFilter && !usesVFilter)
+ {
+ /* yv12_to_nv12 */
+ if(srcFormat == PIX_FMT_YUV420P && (dstFormat == PIX_FMT_NV12 || dstFormat == PIX_FMT_NV21))
+ {
+ c->swScale= PlanarToNV12Wrapper;
+ }
+#ifdef CONFIG_GPL
+ /* yuv2bgr */
+ if((srcFormat==PIX_FMT_YUV420P || srcFormat==PIX_FMT_YUV422P) && (isBGR(dstFormat) || isRGB(dstFormat)))
+ {
+ c->swScale= yuv2rgb_get_func_ptr(c);
+ }
+#endif
+
+ if( srcFormat==PIX_FMT_YUV410P && dstFormat==PIX_FMT_YUV420P )
+ {
+ c->swScale= yvu9toyv12Wrapper;
+ }
+
+ /* bgr24toYV12 */
+ if(srcFormat==PIX_FMT_BGR24 && dstFormat==PIX_FMT_YUV420P)
+ c->swScale= bgr24toyv12Wrapper;
+
+ /* rgb/bgr -> rgb/bgr (no dither needed forms) */
+ if( (isBGR(srcFormat) || isRGB(srcFormat))
+ && (isBGR(dstFormat) || isRGB(dstFormat))
+ && !needsDither)
+ c->swScale= rgb2rgbWrapper;
+
+ /* LQ converters if -sws 0 or -sws 4*/
+ if(c->flags&(SWS_FAST_BILINEAR|SWS_POINT)){
+ /* rgb/bgr -> rgb/bgr (dither needed forms) */
+ if( (isBGR(srcFormat) || isRGB(srcFormat))
+ && (isBGR(dstFormat) || isRGB(dstFormat))
+ && needsDither)
+ c->swScale= rgb2rgbWrapper;
+
+ /* yv12_to_yuy2 */
+ if(srcFormat == PIX_FMT_YUV420P &&
+ (dstFormat == PIX_FMT_YUYV422 || dstFormat == PIX_FMT_UYVY422))
+ {
+ if (dstFormat == PIX_FMT_YUYV422)
+ c->swScale= PlanarToYuy2Wrapper;
+ else
+ c->swScale= PlanarToUyvyWrapper;
+ }
+ }
+
+#ifdef COMPILE_ALTIVEC
+ if ((c->flags & SWS_CPU_CAPS_ALTIVEC) &&
+ ((srcFormat == PIX_FMT_YUV420P &&
+ (dstFormat == PIX_FMT_YUYV422 || dstFormat == PIX_FMT_UYVY422)))) {
+ // unscaled YV12 -> packed YUV, we want speed
+ if (dstFormat == PIX_FMT_YUYV422)
+ c->swScale= yv12toyuy2_unscaled_altivec;
+ else
+ c->swScale= yv12touyvy_unscaled_altivec;
+ }
+#endif
+
+ /* simple copy */
+ if( srcFormat == dstFormat
+ || (isPlanarYUV(srcFormat) && isGray(dstFormat))
+ || (isPlanarYUV(dstFormat) && isGray(srcFormat))
+ )
+ {
+ c->swScale= simpleCopy;
+ }
+
+ /* gray16{le,be} conversions */
+ if(isGray16(srcFormat) && (isPlanarYUV(dstFormat) || (dstFormat == PIX_FMT_GRAY8)))
+ {
+ c->swScale= gray16togray;
+ }
+ if((isPlanarYUV(srcFormat) || (srcFormat == PIX_FMT_GRAY8)) && isGray16(dstFormat))
+ {
+ c->swScale= graytogray16;
+ }
+ if(srcFormat != dstFormat && isGray16(srcFormat) && isGray16(dstFormat))
+ {
+ c->swScale= gray16swap;
+ }
+
+ if(c->swScale){
+ if(flags&SWS_PRINT_INFO)
+ av_log(c, AV_LOG_INFO, "SwScaler: 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, "SwScaler: 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 noone shuld 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 x86asm 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);
+
+#define MAX_FUNNY_CODE_SIZE 10000
+#if defined(COMPILE_MMX2)
+// can't downscale !!!
+ if(c->canMMX2BeUsed && (flags & SWS_FAST_BILINEAR))
+ {
+#ifdef MAP_ANONYMOUS
+ c->funnyYCode = (uint8_t*)mmap(NULL, MAX_FUNNY_CODE_SIZE, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+ c->funnyUVCode = (uint8_t*)mmap(NULL, MAX_FUNNY_CODE_SIZE, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+#else
+ c->funnyYCode = av_malloc(MAX_FUNNY_CODE_SIZE);
+ c->funnyUVCode = av_malloc(MAX_FUNNY_CODE_SIZE);
+#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->funnyYCode , c->lumMmx2Filter, c->lumMmx2FilterPos, 8);
+ initMMX2HScaler(c->chrDstW, c->chrXInc, c->funnyUVCode, c->chrMmx2Filter, c->chrMmx2FilterPos, 4);
+ }
+#endif /* defined(COMPILE_MMX2) */
+ } // Init 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)-4,
+ (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)-4,
+ (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags,
+ srcFilter->chrV, dstFilter->chrV, c->param);
+
+#ifdef HAVE_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;i<c->vLumFilterSize*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;i<c->vChrFilterSize*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; i<dstH; i++)
+ {
+ int chrI= i*c->chrDstH / dstH;
+ int nextSlice= FFMAX(c->vLumFilterPos[i ] + c->vLumFilterSize - 1,
+ ((c->vChrFilterPos[chrI] + c->vChrFilterSize - 1)<<c->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*));
+ //Note we need at least one pixel more at the end because of the mmx code (just in case someone wanna replace the 4000/8000)
+ /* align at 16 bytes for AltiVec */
+ for(i=0; i<c->vLumBufSize; i++)
+ c->lumPixBuf[i]= c->lumPixBuf[i+c->vLumBufSize]= av_mallocz(4000);
+ for(i=0; i<c->vChrBufSize; i++)
+ c->chrPixBuf[i]= c->chrPixBuf[i+c->vChrBufSize]= av_malloc(8000);
+
+ //try to avoid drawing green stuff between the right end and the stride end
+ for(i=0; i<c->vChrBufSize; i++) memset(c->chrPixBuf[i], 64, 8000);
+
+ ASSERT(c->chrDstH <= dstH)
+
+ if(flags&SWS_PRINT_INFO)
+ {
+#ifdef DITHER1XBPP
+ char *dither= " dithered";
+#else
+ char *dither= "";
+#endif
+ if(flags&SWS_FAST_BILINEAR)
+ av_log(c, AV_LOG_INFO, "SwScaler: FAST_BILINEAR scaler, ");
+ else if(flags&SWS_BILINEAR)
+ av_log(c, AV_LOG_INFO, "SwScaler: BILINEAR scaler, ");
+ else if(flags&SWS_BICUBIC)
+ av_log(c, AV_LOG_INFO, "SwScaler: BICUBIC scaler, ");
+ else if(flags&SWS_X)
+ av_log(c, AV_LOG_INFO, "SwScaler: Experimental scaler, ");
+ else if(flags&SWS_POINT)
+ av_log(c, AV_LOG_INFO, "SwScaler: Nearest Neighbor / POINT scaler, ");
+ else if(flags&SWS_AREA)
+ av_log(c, AV_LOG_INFO, "SwScaler: Area Averageing scaler, ");
+ else if(flags&SWS_BICUBLIN)
+ av_log(c, AV_LOG_INFO, "SwScaler: luma BICUBIC / chroma BILINEAR scaler, ");
+ else if(flags&SWS_GAUSS)
+ av_log(c, AV_LOG_INFO, "SwScaler: Gaussian scaler, ");
+ else if(flags&SWS_SINC)
+ av_log(c, AV_LOG_INFO, "SwScaler: Sinc scaler, ");
+ else if(flags&SWS_LANCZOS)
+ av_log(c, AV_LOG_INFO, "SwScaler: Lanczos scaler, ");
+ else if(flags&SWS_SPLINE)
+ av_log(c, AV_LOG_INFO, "SwScaler: Bicubic spline scaler, ");
+ else
+ av_log(c, AV_LOG_INFO, "SwScaler: 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, "SwScaler: using FAST_BILINEAR MMX2 scaler for horizontal scaling\n");
+ else
+ {
+ if(c->hLumFilterSize==4)
+ av_log(c, AV_LOG_VERBOSE, "SwScaler: using 4-tap MMX scaler for horizontal luminance scaling\n");
+ else if(c->hLumFilterSize==8)
+ av_log(c, AV_LOG_VERBOSE, "SwScaler: using 8-tap MMX scaler for horizontal luminance scaling\n");
+ else
+ av_log(c, AV_LOG_VERBOSE, "SwScaler: using n-tap MMX scaler for horizontal luminance scaling\n");
+
+ if(c->hChrFilterSize==4)
+ av_log(c, AV_LOG_VERBOSE, "SwScaler: using 4-tap MMX scaler for horizontal chrominance scaling\n");
+ else if(c->hChrFilterSize==8)
+ av_log(c, AV_LOG_VERBOSE, "SwScaler: using 8-tap MMX scaler for horizontal chrominance scaling\n");
+ else
+ av_log(c, AV_LOG_VERBOSE, "SwScaler: using n-tap MMX scaler for horizontal chrominance scaling\n");
+ }
+ }
+ else
+ {
+#if defined(ARCH_X86)
+ av_log(c, AV_LOG_VERBOSE, "SwScaler: using X86-Asm scaler for horizontal scaling\n");
+#else
+ if(flags & SWS_FAST_BILINEAR)
+ av_log(c, AV_LOG_VERBOSE, "SwScaler: using FAST_BILINEAR C scaler for horizontal scaling\n");
+ else
+ av_log(c, AV_LOG_VERBOSE, "SwScaler: using C scaler for horizontal scaling\n");
+#endif
+ }
+ if(isPlanarYUV(dstFormat))
+ {
+ if(c->vLumFilterSize==1)
+ av_log(c, AV_LOG_VERBOSE, "SwScaler: 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, "SwScaler: 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, "SwScaler: using 1-tap %s \"scaler\" for vertical luminance scaling (BGR)\n"
+ "SwScaler: 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, "SwScaler: 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, "SwScaler: 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, "SwScaler: 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, "SwScaler: 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, "SwScaler: 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, "SwScaler: using %s YV12->BGR15 Converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C");
+
+ av_log(c, AV_LOG_VERBOSE, "SwScaler: %dx%d -> %dx%d\n", srcW, srcH, dstW, dstH);
+ }
+ if(flags & SWS_PRINT_INFO)
+ {
+ av_log(c, AV_LOG_DEBUG, "SwScaler: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, "SwScaler: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(flags);
+ return c;
+}
+
+/**
+ * swscale warper, 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[]){
+ if (c->sliceDir == 0 && srcSliceY != 0 && srcSliceY + srcSliceH != c->srcH) {
+ av_log(c, AV_LOG_ERROR, "swScaler: slices start in the middle!\n");
+ return 0;
+ }
+ if (c->sliceDir == 0) {
+ if (srcSliceY == 0) c->sliceDir = 1; else c->sliceDir = -1;
+ }
+
+ // copy strides, so they can safely be modified
+ if (c->sliceDir == 1) {
+ uint8_t* src2[4]= {src[0], src[1], src[2]};
+ // slices go from top to bottom
+ int srcStride2[4]= {srcStride[0], srcStride[1], srcStride[2]};
+ int dstStride2[4]= {dstStride[0], dstStride[1], dstStride[2]};
+ return c->swScale(c, src2, srcStride2, srcSliceY, srcSliceH, dst, dstStride2);
+ } else {
+ // slices go from bottom to top => we flip the image internally
+ uint8_t* src2[4]= {src[0] + (srcSliceH-1)*srcStride[0],
+ src[1] + ((srcSliceH>>c->chrSrcVSubSample)-1)*srcStride[1],
+ src[2] + ((srcSliceH>>c->chrSrcVSubSample)-1)*srcStride[2]
+ };
+ uint8_t* dst2[4]= {dst[0] + (c->dstH-1)*dstStride[0],
+ dst[1] + ((c->dstH>>c->chrDstVSubSample)-1)*dstStride[1],
+ dst[2] + ((c->dstH>>c->chrDstVSubSample)-1)*dstStride[2]};
+ int srcStride2[4]= {-srcStride[0], -srcStride[1], -srcStride[2]};
+ int dstStride2[4]= {-dstStride[0], -dstStride[1], -dstStride[2]};
+
+ return c->swScale(c, src2, srcStride2, c->srcH-srcSliceY-srcSliceH, srcSliceH, dst2, dstStride2);
+ }
+}
+
+/**
+ * swscale warper, so we don't need to export the SwsContext
+ */
+int sws_scale_ordered(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+ int srcSliceH, uint8_t* dst[], int dstStride[]){
+ return sws_scale(c, src, srcStride, srcSliceY, srcSliceH, dst, dstStride);
+}
+
+SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur,
+ float lumaSharpen, float chromaSharpen,
+ float chromaHShift, float chromaVShift,
+ int verbose)
+{
+ SwsFilter *filter= av_malloc(sizeof(SwsFilter));
+
+ 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_printVec(filter->chrH);
+ if(verbose) sws_printVec(filter->lumH);
+
+ return filter;
+}
+
+/**
+ * returns a normalized gaussian curve used to filter stuff
+ * quality=3 is high quality, lowwer is lowwer quality
+ */
+SwsVector *sws_getGaussianVec(double variance, double quality){
+ const int length= (int)(variance*quality + 0.5) | 1;
+ int i;
+ double *coeff= av_malloc(length*sizeof(double));
+ double middle= (length-1)*0.5;
+ SwsVector *vec= av_malloc(sizeof(SwsVector));
+
+ vec->coeff= coeff;
+ vec->length= length;
+
+ for(i=0; i<length; i++)
+ {
+ double dist= i-middle;
+ coeff[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;
+ double *coeff= av_malloc(length*sizeof(double));
+ SwsVector *vec= av_malloc(sizeof(SwsVector));
+
+ vec->coeff= coeff;
+ vec->length= length;
+
+ for(i=0; i<length; i++)
+ coeff[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; i<a->length; i++)
+ sum+= a->coeff[i];
+
+ return sum;
+}
+
+void sws_scaleVec(SwsVector *a, double scalar){
+ int i;
+
+ for(i=0; i<a->length; 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;
+ double *coeff= av_malloc(length*sizeof(double));
+ int i, j;
+ SwsVector *vec= av_malloc(sizeof(SwsVector));
+
+ vec->coeff= coeff;
+ vec->length= length;
+
+ for(i=0; i<length; i++) coeff[i]= 0.0;
+
+ for(i=0; i<a->length; i++)
+ {
+ for(j=0; j<b->length; j++)
+ {
+ 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);
+ double *coeff= av_malloc(length*sizeof(double));
+ int i;
+ SwsVector *vec= av_malloc(sizeof(SwsVector));
+
+ vec->coeff= coeff;
+ vec->length= length;
+
+ for(i=0; i<length; i++) coeff[i]= 0.0;
+
+ for(i=0; i<a->length; i++) coeff[i + (length-1)/2 - (a->length-1)/2]+= a->coeff[i];
+ for(i=0; i<b->length; i++) 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);
+ double *coeff= av_malloc(length*sizeof(double));
+ int i;
+ SwsVector *vec= av_malloc(sizeof(SwsVector));
+
+ vec->coeff= coeff;
+ vec->length= length;
+
+ for(i=0; i<length; i++) coeff[i]= 0.0;
+
+ for(i=0; i<a->length; i++) coeff[i + (length-1)/2 - (a->length-1)/2]+= a->coeff[i];
+ for(i=0; i<b->length; i++) 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;
+ double *coeff= av_malloc(length*sizeof(double));
+ int i;
+ SwsVector *vec= av_malloc(sizeof(SwsVector));
+
+ vec->coeff= coeff;
+ vec->length= length;
+
+ for(i=0; i<length; i++) coeff[i]= 0.0;
+
+ for(i=0; i<a->length; i++)
+ {
+ 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){
+ double *coeff= av_malloc(a->length*sizeof(double));
+ int i;
+ SwsVector *vec= av_malloc(sizeof(SwsVector));
+
+ vec->coeff= coeff;
+ vec->length= a->length;
+
+ for(i=0; i<a->length; i++) coeff[i]= a->coeff[i];
+
+ return vec;
+}
+
+void sws_printVec(SwsVector *a){
+ int i;
+ double max=0;
+ double min=0;
+ double range;
+
+ for(i=0; i<a->length; i++)
+ if(a->coeff[i]>max) max= a->coeff[i];
+
+ for(i=0; i<a->length; i++)
+ if(a->coeff[i]<min) min= a->coeff[i];
+
+ range= max - min;
+
+ for(i=0; i<a->length; i++)
+ {
+ int x= (int)((a->coeff[i]-min)*60.0/range +0.5);
+ av_log(NULL, AV_LOG_DEBUG, "%1.3f ", a->coeff[i]);
+ for(;x>0; x--) av_log(NULL, AV_LOG_DEBUG, " ");
+ av_log(NULL, AV_LOG_DEBUG, "|\n");
+ }
+}
+
+void sws_freeVec(SwsVector *a){
+ if(!a) return;
+ av_free(a->coeff);
+ a->coeff=NULL;
+ 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; i<c->vLumBufSize; i++)
+ {
+ av_free(c->lumPixBuf[i]);
+ c->lumPixBuf[i]=NULL;
+ }
+ av_free(c->lumPixBuf);
+ c->lumPixBuf=NULL;
+ }
+
+ if(c->chrPixBuf)
+ {
+ for(i=0; i<c->vChrBufSize; i++)
+ {
+ av_free(c->chrPixBuf[i]);
+ c->chrPixBuf[i]=NULL;
+ }
+ av_free(c->chrPixBuf);
+ c->chrPixBuf=NULL;
+ }
+
+ av_free(c->vLumFilter);
+ c->vLumFilter = NULL;
+ av_free(c->vChrFilter);
+ c->vChrFilter = NULL;
+ av_free(c->hLumFilter);
+ c->hLumFilter = NULL;
+ av_free(c->hChrFilter);
+ c->hChrFilter = NULL;
+#ifdef HAVE_ALTIVEC
+ av_free(c->vYCoeffsBank);
+ c->vYCoeffsBank = NULL;
+ av_free(c->vCCoeffsBank);
+ c->vCCoeffsBank = NULL;
+#endif
+
+ av_free(c->vLumFilterPos);
+ c->vLumFilterPos = NULL;
+ av_free(c->vChrFilterPos);
+ c->vChrFilterPos = NULL;
+ av_free(c->hLumFilterPos);
+ c->hLumFilterPos = NULL;
+ av_free(c->hChrFilterPos);
+ c->hChrFilterPos = NULL;
+
+#if defined(ARCH_X86) && defined(CONFIG_GPL)
+#ifdef MAP_ANONYMOUS
+ if(c->funnyYCode) munmap(c->funnyYCode, MAX_FUNNY_CODE_SIZE);
+ if(c->funnyUVCode) munmap(c->funnyUVCode, MAX_FUNNY_CODE_SIZE);
+#else
+ av_free(c->funnyYCode);
+ av_free(c->funnyUVCode);
+#endif
+ c->funnyYCode=NULL;
+ c->funnyUVCode=NULL;
+#endif /* defined(ARCH_X86) */
+
+ av_free(c->lumMmx2Filter);
+ c->lumMmx2Filter=NULL;
+ av_free(c->chrMmx2Filter);
+ c->chrMmx2Filter=NULL;
+ av_free(c->lumMmx2FilterPos);
+ c->lumMmx2FilterPos=NULL;
+ av_free(c->chrMmx2FilterPos);
+ c->chrMmx2FilterPos=NULL;
+ av_free(c->yuvTable);
+ c->yuvTable=NULL;
+
+ av_free(c);
+}
+
+/**
+ * Checks if context is valid or reallocs a new one instead.
+ * If context is NULL, just calls sws_getContext() to get a new one.
+ * Otherwise, checks if the parameters are the same already saved in context.
+ * If that is the case, returns the current context.
+ * Otherwise, frees context and gets a new one.
+ *
+ * Be warned that srcFilter, dstFilter are not checked, they are
+ * asumed to remain valid.
+ */
+struct SwsContext *sws_getCachedContext(struct SwsContext *context,
+ int srcW, int srcH, int srcFormat,
+ int dstW, int dstH, int dstFormat, int flags,
+ SwsFilter *srcFilter, SwsFilter *dstFilter, double *param)
+{
+ if (context != NULL) {
+ if ((context->srcW != srcW) || (context->srcH != srcH) ||
+ (context->srcFormat != srcFormat) ||
+ (context->dstW != dstW) || (context->dstH != dstH) ||
+ (context->dstFormat != dstFormat) || (context->flags != flags) ||
+ (context->param != param))
+ {
+ sws_freeContext(context);
+ context = NULL;
+ }
+ }
+ if (context == NULL) {
+ return sws_getContext(srcW, srcH, srcFormat,
+ dstW, dstH, dstFormat, flags,
+ srcFilter, dstFilter, param);
+ }
+ return context;
+}
+
diff --git a/contrib/ffmpeg/libswscale/swscale.h b/contrib/ffmpeg/libswscale/swscale.h
new file mode 100644
index 000000000..27d1aa3ef
--- /dev/null
+++ b/contrib/ffmpeg/libswscale/swscale.h
@@ -0,0 +1,148 @@
+/*
+ * Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef SWSCALE_H
+#define SWSCALE_H
+
+/**
+ * @file swscale.h
+ * @brief
+ * external api for the swscale stuff
+ */
+
+#include "avutil.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define AV_STRINGIFY(s) AV_TOSTRING(s)
+#define AV_TOSTRING(s) #s
+
+#define LIBSWSCALE_VERSION_INT ((0<<16)+(5<<8)+0)
+#define LIBSWSCALE_VERSION 0.5.0
+#define LIBSWSCALE_BUILD LIBSWSCALE_VERSION_INT
+
+#define LIBSWSCALE_IDENT "SwS" AV_STRINGIFY(LIBSWSCALE_VERSION)
+
+/* values for the flags, the stuff on the command line is different */
+#define SWS_FAST_BILINEAR 1
+#define SWS_BILINEAR 2
+#define SWS_BICUBIC 4
+#define SWS_X 8
+#define SWS_POINT 0x10
+#define SWS_AREA 0x20
+#define SWS_BICUBLIN 0x40
+#define SWS_GAUSS 0x80
+#define SWS_SINC 0x100
+#define SWS_LANCZOS 0x200
+#define SWS_SPLINE 0x400
+
+#define SWS_SRC_V_CHR_DROP_MASK 0x30000
+#define SWS_SRC_V_CHR_DROP_SHIFT 16
+
+#define SWS_PARAM_DEFAULT 123456
+
+#define SWS_PRINT_INFO 0x1000
+
+//the following 3 flags are not completly implemented
+//internal chrominace subsamling info
+#define SWS_FULL_CHR_H_INT 0x2000
+//input subsampling info
+#define SWS_FULL_CHR_H_INP 0x4000
+#define SWS_DIRECT_BGR 0x8000
+#define SWS_ACCURATE_RND 0x40000
+
+#define SWS_CPU_CAPS_MMX 0x80000000
+#define SWS_CPU_CAPS_MMX2 0x20000000
+#define SWS_CPU_CAPS_3DNOW 0x40000000
+#define SWS_CPU_CAPS_ALTIVEC 0x10000000
+
+#define SWS_MAX_REDUCE_CUTOFF 0.002
+
+#define SWS_CS_ITU709 1
+#define SWS_CS_FCC 4
+#define SWS_CS_ITU601 5
+#define SWS_CS_ITU624 5
+#define SWS_CS_SMPTE170M 5
+#define SWS_CS_SMPTE240M 7
+#define SWS_CS_DEFAULT 5
+
+
+
+// when used for filters they must have an odd number of elements
+// coeffs cannot be shared between vectors
+typedef struct {
+ double *coeff;
+ int length;
+} SwsVector;
+
+// vectors can be shared
+typedef struct {
+ SwsVector *lumH;
+ SwsVector *lumV;
+ SwsVector *chrH;
+ SwsVector *chrV;
+} SwsFilter;
+
+struct SwsContext;
+
+void sws_freeContext(struct SwsContext *swsContext);
+
+struct SwsContext *sws_getContext(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags,
+ SwsFilter *srcFilter, SwsFilter *dstFilter, double *param);
+int sws_scale(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY,
+ int srcSliceH, uint8_t* dst[], int dstStride[]);
+int sws_scale_ordered(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY,
+ int srcSliceH, uint8_t* dst[], int dstStride[]) attribute_deprecated;
+
+
+int sws_setColorspaceDetails(struct SwsContext *c, const int inv_table[4], int srcRange, const int table[4], int dstRange, int brightness, int contrast, int saturation);
+int sws_getColorspaceDetails(struct SwsContext *c, int **inv_table, int *srcRange, int **table, int *dstRange, int *brightness, int *contrast, int *saturation);
+SwsVector *sws_getGaussianVec(double variance, double quality);
+SwsVector *sws_getConstVec(double c, int length);
+SwsVector *sws_getIdentityVec(void);
+void sws_scaleVec(SwsVector *a, double scalar);
+void sws_normalizeVec(SwsVector *a, double height);
+void sws_convVec(SwsVector *a, SwsVector *b);
+void sws_addVec(SwsVector *a, SwsVector *b);
+void sws_subVec(SwsVector *a, SwsVector *b);
+void sws_shiftVec(SwsVector *a, int shift);
+SwsVector *sws_cloneVec(SwsVector *a);
+
+void sws_printVec(SwsVector *a);
+void sws_freeVec(SwsVector *a);
+
+SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur,
+ float lumaSarpen, float chromaSharpen,
+ float chromaHShift, float chromaVShift,
+ int verbose);
+void sws_freeFilter(SwsFilter *filter);
+
+struct SwsContext *sws_getCachedContext(struct SwsContext *context,
+ int srcW, int srcH, int srcFormat,
+ int dstW, int dstH, int dstFormat, int flags,
+ SwsFilter *srcFilter, SwsFilter *dstFilter, double *param);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/contrib/ffmpeg/libswscale/swscale_altivec_template.c b/contrib/ffmpeg/libswscale/swscale_altivec_template.c
new file mode 100644
index 000000000..251b38ca1
--- /dev/null
+++ b/contrib/ffmpeg/libswscale/swscale_altivec_template.c
@@ -0,0 +1,548 @@
+/*
+ * AltiVec-enhanced yuv2yuvX
+ *
+ * Copyright (C) 2004 Romain Dolbeau <romain@dolbeau.org>
+ * based on the equivalent C code in "postproc/swscale.c"
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifdef CONFIG_DARWIN
+#define AVV(x...) (x)
+#else
+#define AVV(x...) {x}
+#endif
+
+#define vzero vec_splat_s32(0)
+
+static inline void
+altivec_packIntArrayToCharArray(int *val, uint8_t* dest, int dstW) {
+ register int i;
+ vector unsigned int altivec_vectorShiftInt19 =
+ vec_add(vec_splat_u32(10),vec_splat_u32(9));
+ if ((unsigned long)dest % 16) {
+ /* badly aligned store, we force store alignement */
+ /* and will handle load misalignement on val w/ vec_perm */
+ vector unsigned char perm1;
+ vector signed int v1;
+ for (i = 0 ; (i < dstW) &&
+ (((unsigned long)dest + i) % 16) ; i++) {
+ int t = val[i] >> 19;
+ dest[i] = (t < 0) ? 0 : ((t > 255) ? 255 : t);
+ }
+ perm1 = vec_lvsl(i << 2, val);
+ v1 = vec_ld(i << 2, val);
+ for ( ; i < (dstW - 15); i+=16) {
+ int offset = i << 2;
+ vector signed int v2 = vec_ld(offset + 16, val);
+ vector signed int v3 = vec_ld(offset + 32, val);
+ vector signed int v4 = vec_ld(offset + 48, val);
+ vector signed int v5 = vec_ld(offset + 64, val);
+ vector signed int v12 = vec_perm(v1,v2,perm1);
+ vector signed int v23 = vec_perm(v2,v3,perm1);
+ vector signed int v34 = vec_perm(v3,v4,perm1);
+ vector signed int v45 = vec_perm(v4,v5,perm1);
+
+ vector signed int vA = vec_sra(v12, altivec_vectorShiftInt19);
+ vector signed int vB = vec_sra(v23, altivec_vectorShiftInt19);
+ vector signed int vC = vec_sra(v34, altivec_vectorShiftInt19);
+ vector signed int vD = vec_sra(v45, altivec_vectorShiftInt19);
+ vector unsigned short vs1 = vec_packsu(vA, vB);
+ vector unsigned short vs2 = vec_packsu(vC, vD);
+ vector unsigned char vf = vec_packsu(vs1, vs2);
+ vec_st(vf, i, dest);
+ v1 = v5;
+ }
+ } else { // dest is properly aligned, great
+ for (i = 0; i < (dstW - 15); i+=16) {
+ int offset = i << 2;
+ vector signed int v1 = vec_ld(offset, val);
+ vector signed int v2 = vec_ld(offset + 16, val);
+ vector signed int v3 = vec_ld(offset + 32, val);
+ vector signed int v4 = vec_ld(offset + 48, val);
+ vector signed int v5 = vec_sra(v1, altivec_vectorShiftInt19);
+ vector signed int v6 = vec_sra(v2, altivec_vectorShiftInt19);
+ vector signed int v7 = vec_sra(v3, altivec_vectorShiftInt19);
+ vector signed int v8 = vec_sra(v4, altivec_vectorShiftInt19);
+ vector unsigned short vs1 = vec_packsu(v5, v6);
+ vector unsigned short vs2 = vec_packsu(v7, v8);
+ vector unsigned char vf = vec_packsu(vs1, vs2);
+ vec_st(vf, i, dest);
+ }
+ }
+ for ( ; i < dstW ; i++) {
+ int t = val[i] >> 19;
+ dest[i] = (t < 0) ? 0 : ((t > 255) ? 255 : t);
+ }
+}
+
+static inline void
+yuv2yuvX_altivec_real(int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize,
+ int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize,
+ uint8_t *dest, uint8_t *uDest, uint8_t *vDest, int dstW, int chrDstW)
+{
+ const vector signed int vini = {(1 << 18), (1 << 18), (1 << 18), (1 << 18)};
+ register int i, j;
+ {
+ int __attribute__ ((aligned (16))) val[dstW];
+
+ for (i = 0; i < (dstW -7); i+=4) {
+ vec_st(vini, i << 2, val);
+ }
+ for (; i < dstW; i++) {
+ val[i] = (1 << 18);
+ }
+
+ for (j = 0; j < lumFilterSize; j++) {
+ vector signed short l1, vLumFilter = vec_ld(j << 1, lumFilter);
+ vector unsigned char perm, perm0 = vec_lvsl(j << 1, lumFilter);
+ vLumFilter = vec_perm(vLumFilter, vLumFilter, perm0);
+ vLumFilter = vec_splat(vLumFilter, 0); // lumFilter[j] is loaded 8 times in vLumFilter
+
+ perm = vec_lvsl(0, lumSrc[j]);
+ l1 = vec_ld(0, lumSrc[j]);
+
+ for (i = 0; i < (dstW - 7); i+=8) {
+ int offset = i << 2;
+ vector signed short l2 = vec_ld((i << 1) + 16, lumSrc[j]);
+
+ vector signed int v1 = vec_ld(offset, val);
+ vector signed int v2 = vec_ld(offset + 16, val);
+
+ vector signed short ls = vec_perm(l1, l2, perm); // lumSrc[j][i] ... lumSrc[j][i+7]
+
+ vector signed int i1 = vec_mule(vLumFilter, ls);
+ vector signed int i2 = vec_mulo(vLumFilter, ls);
+
+ vector signed int vf1 = vec_mergeh(i1, i2);
+ vector signed int vf2 = vec_mergel(i1, i2); // lumSrc[j][i] * lumFilter[j] ... lumSrc[j][i+7] * lumFilter[j]
+
+ vector signed int vo1 = vec_add(v1, vf1);
+ vector signed int vo2 = vec_add(v2, vf2);
+
+ vec_st(vo1, offset, val);
+ vec_st(vo2, offset + 16, val);
+
+ l1 = l2;
+ }
+ for ( ; i < dstW; i++) {
+ val[i] += lumSrc[j][i] * lumFilter[j];
+ }
+ }
+ altivec_packIntArrayToCharArray(val,dest,dstW);
+ }
+ if (uDest != 0) {
+ int __attribute__ ((aligned (16))) u[chrDstW];
+ int __attribute__ ((aligned (16))) v[chrDstW];
+
+ for (i = 0; i < (chrDstW -7); i+=4) {
+ vec_st(vini, i << 2, u);
+ vec_st(vini, i << 2, v);
+ }
+ for (; i < chrDstW; i++) {
+ u[i] = (1 << 18);
+ v[i] = (1 << 18);
+ }
+
+ for (j = 0; j < chrFilterSize; j++) {
+ vector signed short l1, l1_V, vChrFilter = vec_ld(j << 1, chrFilter);
+ vector unsigned char perm, perm0 = vec_lvsl(j << 1, chrFilter);
+ vChrFilter = vec_perm(vChrFilter, vChrFilter, perm0);
+ vChrFilter = vec_splat(vChrFilter, 0); // chrFilter[j] is loaded 8 times in vChrFilter
+
+ perm = vec_lvsl(0, chrSrc[j]);
+ l1 = vec_ld(0, chrSrc[j]);
+ l1_V = vec_ld(2048 << 1, chrSrc[j]);
+
+ for (i = 0; i < (chrDstW - 7); i+=8) {
+ int offset = i << 2;
+ vector signed short l2 = vec_ld((i << 1) + 16, chrSrc[j]);
+ vector signed short l2_V = vec_ld(((i + 2048) << 1) + 16, chrSrc[j]);
+
+ vector signed int v1 = vec_ld(offset, u);
+ vector signed int v2 = vec_ld(offset + 16, u);
+ vector signed int v1_V = vec_ld(offset, v);
+ vector signed int v2_V = vec_ld(offset + 16, v);
+
+ vector signed short ls = vec_perm(l1, l2, perm); // chrSrc[j][i] ... chrSrc[j][i+7]
+ vector signed short ls_V = vec_perm(l1_V, l2_V, perm); // chrSrc[j][i+2048] ... chrSrc[j][i+2055]
+
+ vector signed int i1 = vec_mule(vChrFilter, ls);
+ vector signed int i2 = vec_mulo(vChrFilter, ls);
+ vector signed int i1_V = vec_mule(vChrFilter, ls_V);
+ vector signed int i2_V = vec_mulo(vChrFilter, ls_V);
+
+ vector signed int vf1 = vec_mergeh(i1, i2);
+ vector signed int vf2 = vec_mergel(i1, i2); // chrSrc[j][i] * chrFilter[j] ... chrSrc[j][i+7] * chrFilter[j]
+ vector signed int vf1_V = vec_mergeh(i1_V, i2_V);
+ vector signed int vf2_V = vec_mergel(i1_V, i2_V); // chrSrc[j][i] * chrFilter[j] ... chrSrc[j][i+7] * chrFilter[j]
+
+ vector signed int vo1 = vec_add(v1, vf1);
+ vector signed int vo2 = vec_add(v2, vf2);
+ vector signed int vo1_V = vec_add(v1_V, vf1_V);
+ vector signed int vo2_V = vec_add(v2_V, vf2_V);
+
+ vec_st(vo1, offset, u);
+ vec_st(vo2, offset + 16, u);
+ vec_st(vo1_V, offset, v);
+ vec_st(vo2_V, offset + 16, v);
+
+ l1 = l2;
+ l1_V = l2_V;
+ }
+ for ( ; i < chrDstW; i++) {
+ u[i] += chrSrc[j][i] * chrFilter[j];
+ v[i] += chrSrc[j][i + 2048] * chrFilter[j];
+ }
+ }
+ altivec_packIntArrayToCharArray(u,uDest,chrDstW);
+ altivec_packIntArrayToCharArray(v,vDest,chrDstW);
+ }
+}
+
+static inline void hScale_altivec_real(int16_t *dst, int dstW, uint8_t *src, int srcW, int xInc, int16_t *filter, int16_t *filterPos, int filterSize) {
+ register int i;
+ int __attribute__ ((aligned (16))) tempo[4];
+
+ if (filterSize % 4) {
+ for(i=0; i<dstW; i++) {
+ register int j;
+ register int srcPos = filterPos[i];
+ register int val = 0;
+ for(j=0; j<filterSize; j++) {
+ val += ((int)src[srcPos + j])*filter[filterSize*i + j];
+ }
+ dst[i] = av_clip(val>>7, 0, (1<<15)-1);
+ }
+ }
+ else
+ switch (filterSize) {
+ case 4:
+ {
+ for(i=0; i<dstW; i++) {
+ register int srcPos = filterPos[i];
+
+ vector unsigned char src_v0 = vec_ld(srcPos, src);
+ vector unsigned char src_v1, src_vF;
+ vector signed short src_v, filter_v;
+ vector signed int val_vEven, val_s;
+ if ((((int)src + srcPos)% 16) > 12) {
+ src_v1 = vec_ld(srcPos + 16, src);
+ }
+ src_vF = vec_perm(src_v0, src_v1, vec_lvsl(srcPos, src));
+
+ src_v = // vec_unpackh sign-extends...
+ (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF));
+ // now put our elements in the even slots
+ src_v = vec_mergeh(src_v, (vector signed short)vzero);
+
+ filter_v = vec_ld(i << 3, filter);
+ // the 3 above is 2 (filterSize == 4) + 1 (sizeof(short) == 2)
+
+ // the neat trick : we only care for half the elements,
+ // high or low depending on (i<<3)%16 (it's 0 or 8 here),
+ // and we're going to use vec_mule, so we chose
+ // carefully how to "unpack" the elements into the even slots
+ if ((i << 3) % 16)
+ filter_v = vec_mergel(filter_v,(vector signed short)vzero);
+ else
+ filter_v = vec_mergeh(filter_v,(vector signed short)vzero);
+
+ val_vEven = vec_mule(src_v, filter_v);
+ val_s = vec_sums(val_vEven, vzero);
+ vec_st(val_s, 0, tempo);
+ dst[i] = av_clip(tempo[3]>>7, 0, (1<<15)-1);
+ }
+ }
+ break;
+
+ case 8:
+ {
+ for(i=0; i<dstW; i++) {
+ register int srcPos = filterPos[i];
+
+ vector unsigned char src_v0 = vec_ld(srcPos, src);
+ vector unsigned char src_v1, src_vF;
+ vector signed short src_v, filter_v;
+ vector signed int val_v, val_s;
+ if ((((int)src + srcPos)% 16) > 8) {
+ src_v1 = vec_ld(srcPos + 16, src);
+ }
+ src_vF = vec_perm(src_v0, src_v1, vec_lvsl(srcPos, src));
+
+ src_v = // vec_unpackh sign-extends...
+ (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF));
+ filter_v = vec_ld(i << 4, filter);
+ // the 4 above is 3 (filterSize == 8) + 1 (sizeof(short) == 2)
+
+ val_v = vec_msums(src_v, filter_v, (vector signed int)vzero);
+ val_s = vec_sums(val_v, vzero);
+ vec_st(val_s, 0, tempo);
+ dst[i] = av_clip(tempo[3]>>7, 0, (1<<15)-1);
+ }
+ }
+ break;
+
+ case 16:
+ {
+ for(i=0; i<dstW; i++) {
+ register int srcPos = filterPos[i];
+
+ vector unsigned char src_v0 = vec_ld(srcPos, src);
+ vector unsigned char src_v1 = vec_ld(srcPos + 16, src);
+ vector unsigned char src_vF = vec_perm(src_v0, src_v1, vec_lvsl(srcPos, src));
+
+ vector signed short src_vA = // vec_unpackh sign-extends...
+ (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF));
+ vector signed short src_vB = // vec_unpackh sign-extends...
+ (vector signed short)(vec_mergel((vector unsigned char)vzero, src_vF));
+
+ vector signed short filter_v0 = vec_ld(i << 5, filter);
+ vector signed short filter_v1 = vec_ld((i << 5) + 16, filter);
+ // the 5 above are 4 (filterSize == 16) + 1 (sizeof(short) == 2)
+
+ vector signed int val_acc = vec_msums(src_vA, filter_v0, (vector signed int)vzero);
+ vector signed int val_v = vec_msums(src_vB, filter_v1, val_acc);
+
+ vector signed int val_s = vec_sums(val_v, vzero);
+
+ vec_st(val_s, 0, tempo);
+ dst[i] = av_clip(tempo[3]>>7, 0, (1<<15)-1);
+ }
+ }
+ break;
+
+ default:
+ {
+ for(i=0; i<dstW; i++) {
+ register int j;
+ register int srcPos = filterPos[i];
+
+ vector signed int val_s, val_v = (vector signed int)vzero;
+ vector signed short filter_v0R = vec_ld(i * 2 * filterSize, filter);
+ vector unsigned char permF = vec_lvsl((i * 2 * filterSize), filter);
+
+ vector unsigned char src_v0 = vec_ld(srcPos, src);
+ vector unsigned char permS = vec_lvsl(srcPos, src);
+
+ for (j = 0 ; j < filterSize - 15; j += 16) {
+ vector unsigned char src_v1 = vec_ld(srcPos + j + 16, src);
+ vector unsigned char src_vF = vec_perm(src_v0, src_v1, permS);
+
+ vector signed short src_vA = // vec_unpackh sign-extends...
+ (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF));
+ vector signed short src_vB = // vec_unpackh sign-extends...
+ (vector signed short)(vec_mergel((vector unsigned char)vzero, src_vF));
+
+ vector signed short filter_v1R = vec_ld((i * 2 * filterSize) + (j * 2) + 16, filter);
+ vector signed short filter_v2R = vec_ld((i * 2 * filterSize) + (j * 2) + 32, filter);
+ vector signed short filter_v0 = vec_perm(filter_v0R, filter_v1R, permF);
+ vector signed short filter_v1 = vec_perm(filter_v1R, filter_v2R, permF);
+
+ vector signed int val_acc = vec_msums(src_vA, filter_v0, val_v);
+ val_v = vec_msums(src_vB, filter_v1, val_acc);
+
+ filter_v0R = filter_v2R;
+ src_v0 = src_v1;
+ }
+
+ if (j < (filterSize-7)) {
+ // loading src_v0 is useless, it's already done above
+ //vector unsigned char src_v0 = vec_ld(srcPos + j, src);
+ vector unsigned char src_v1, src_vF;
+ vector signed short src_v, filter_v1R, filter_v;
+ if ((((int)src + srcPos)% 16) > 8) {
+ src_v1 = vec_ld(srcPos + j + 16, src);
+ }
+ src_vF = vec_perm(src_v0, src_v1, permS);
+
+ src_v = // vec_unpackh sign-extends...
+ (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF));
+ // loading filter_v0R is useless, it's already done above
+ //vector signed short filter_v0R = vec_ld((i * 2 * filterSize) + j, filter);
+ filter_v1R = vec_ld((i * 2 * filterSize) + (j * 2) + 16, filter);
+ filter_v = vec_perm(filter_v0R, filter_v1R, permF);
+
+ val_v = vec_msums(src_v, filter_v, val_v);
+ }
+
+ val_s = vec_sums(val_v, vzero);
+
+ vec_st(val_s, 0, tempo);
+ dst[i] = av_clip(tempo[3]>>7, 0, (1<<15)-1);
+ }
+
+ }
+ }
+}
+
+static inline int yv12toyuy2_unscaled_altivec(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+ int srcSliceH, uint8_t* dstParam[], int dstStride_a[]) {
+ uint8_t *dst=dstParam[0] + dstStride_a[0]*srcSliceY;
+ // yv12toyuy2( src[0],src[1],src[2],dst,c->srcW,srcSliceH,srcStride[0],srcStride[1],dstStride[0] );
+ uint8_t *ysrc = src[0];
+ uint8_t *usrc = src[1];
+ uint8_t *vsrc = src[2];
+ const int width = c->srcW;
+ const int height = srcSliceH;
+ const int lumStride = srcStride[0];
+ const int chromStride = srcStride[1];
+ const int dstStride = dstStride_a[0];
+ const vector unsigned char yperm = vec_lvsl(0, ysrc);
+ const int vertLumPerChroma = 2;
+ register unsigned int y;
+
+ if(width&15){
+ yv12toyuy2( ysrc, usrc, vsrc, dst,c->srcW,srcSliceH, lumStride, chromStride, dstStride);
+ return srcSliceH;
+ }
+
+ /* this code assume:
+
+ 1) dst is 16 bytes-aligned
+ 2) dstStride is a multiple of 16
+ 3) width is a multiple of 16
+ 4) lum&chrom stride are multiple of 8
+ */
+
+ for(y=0; y<height; y++)
+ {
+ int i;
+ for (i = 0; i < width - 31; i+= 32) {
+ const unsigned int j = i >> 1;
+ vector unsigned char v_yA = vec_ld(i, ysrc);
+ vector unsigned char v_yB = vec_ld(i + 16, ysrc);
+ vector unsigned char v_yC = vec_ld(i + 32, ysrc);
+ vector unsigned char v_y1 = vec_perm(v_yA, v_yB, yperm);
+ vector unsigned char v_y2 = vec_perm(v_yB, v_yC, yperm);
+ vector unsigned char v_uA = vec_ld(j, usrc);
+ vector unsigned char v_uB = vec_ld(j + 16, usrc);
+ vector unsigned char v_u = vec_perm(v_uA, v_uB, vec_lvsl(j, usrc));
+ vector unsigned char v_vA = vec_ld(j, vsrc);
+ vector unsigned char v_vB = vec_ld(j + 16, vsrc);
+ vector unsigned char v_v = vec_perm(v_vA, v_vB, vec_lvsl(j, vsrc));
+ vector unsigned char v_uv_a = vec_mergeh(v_u, v_v);
+ vector unsigned char v_uv_b = vec_mergel(v_u, v_v);
+ vector unsigned char v_yuy2_0 = vec_mergeh(v_y1, v_uv_a);
+ vector unsigned char v_yuy2_1 = vec_mergel(v_y1, v_uv_a);
+ vector unsigned char v_yuy2_2 = vec_mergeh(v_y2, v_uv_b);
+ vector unsigned char v_yuy2_3 = vec_mergel(v_y2, v_uv_b);
+ vec_st(v_yuy2_0, (i << 1), dst);
+ vec_st(v_yuy2_1, (i << 1) + 16, dst);
+ vec_st(v_yuy2_2, (i << 1) + 32, dst);
+ vec_st(v_yuy2_3, (i << 1) + 48, dst);
+ }
+ if (i < width) {
+ const unsigned int j = i >> 1;
+ vector unsigned char v_y1 = vec_ld(i, ysrc);
+ vector unsigned char v_u = vec_ld(j, usrc);
+ vector unsigned char v_v = vec_ld(j, vsrc);
+ vector unsigned char v_uv_a = vec_mergeh(v_u, v_v);
+ vector unsigned char v_yuy2_0 = vec_mergeh(v_y1, v_uv_a);
+ vector unsigned char v_yuy2_1 = vec_mergel(v_y1, v_uv_a);
+ vec_st(v_yuy2_0, (i << 1), dst);
+ vec_st(v_yuy2_1, (i << 1) + 16, dst);
+ }
+ if((y&(vertLumPerChroma-1))==(vertLumPerChroma-1) )
+ {
+ usrc += chromStride;
+ vsrc += chromStride;
+ }
+ ysrc += lumStride;
+ dst += dstStride;
+ }
+
+ return srcSliceH;
+}
+
+static inline int yv12touyvy_unscaled_altivec(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+ int srcSliceH, uint8_t* dstParam[], int dstStride_a[]) {
+ uint8_t *dst=dstParam[0] + dstStride_a[0]*srcSliceY;
+ // yv12toyuy2( src[0],src[1],src[2],dst,c->srcW,srcSliceH,srcStride[0],srcStride[1],dstStride[0] );
+ uint8_t *ysrc = src[0];
+ uint8_t *usrc = src[1];
+ uint8_t *vsrc = src[2];
+ const int width = c->srcW;
+ const int height = srcSliceH;
+ const int lumStride = srcStride[0];
+ const int chromStride = srcStride[1];
+ const int dstStride = dstStride_a[0];
+ const int vertLumPerChroma = 2;
+ const vector unsigned char yperm = vec_lvsl(0, ysrc);
+ register unsigned int y;
+
+ if(width&15){
+ yv12touyvy( ysrc, usrc, vsrc, dst,c->srcW,srcSliceH, lumStride, chromStride, dstStride);
+ return srcSliceH;
+ }
+
+ /* this code assume:
+
+ 1) dst is 16 bytes-aligned
+ 2) dstStride is a multiple of 16
+ 3) width is a multiple of 16
+ 4) lum&chrom stride are multiple of 8
+ */
+
+ for(y=0; y<height; y++)
+ {
+ int i;
+ for (i = 0; i < width - 31; i+= 32) {
+ const unsigned int j = i >> 1;
+ vector unsigned char v_yA = vec_ld(i, ysrc);
+ vector unsigned char v_yB = vec_ld(i + 16, ysrc);
+ vector unsigned char v_yC = vec_ld(i + 32, ysrc);
+ vector unsigned char v_y1 = vec_perm(v_yA, v_yB, yperm);
+ vector unsigned char v_y2 = vec_perm(v_yB, v_yC, yperm);
+ vector unsigned char v_uA = vec_ld(j, usrc);
+ vector unsigned char v_uB = vec_ld(j + 16, usrc);
+ vector unsigned char v_u = vec_perm(v_uA, v_uB, vec_lvsl(j, usrc));
+ vector unsigned char v_vA = vec_ld(j, vsrc);
+ vector unsigned char v_vB = vec_ld(j + 16, vsrc);
+ vector unsigned char v_v = vec_perm(v_vA, v_vB, vec_lvsl(j, vsrc));
+ vector unsigned char v_uv_a = vec_mergeh(v_u, v_v);
+ vector unsigned char v_uv_b = vec_mergel(v_u, v_v);
+ vector unsigned char v_uyvy_0 = vec_mergeh(v_uv_a, v_y1);
+ vector unsigned char v_uyvy_1 = vec_mergel(v_uv_a, v_y1);
+ vector unsigned char v_uyvy_2 = vec_mergeh(v_uv_b, v_y2);
+ vector unsigned char v_uyvy_3 = vec_mergel(v_uv_b, v_y2);
+ vec_st(v_uyvy_0, (i << 1), dst);
+ vec_st(v_uyvy_1, (i << 1) + 16, dst);
+ vec_st(v_uyvy_2, (i << 1) + 32, dst);
+ vec_st(v_uyvy_3, (i << 1) + 48, dst);
+ }
+ if (i < width) {
+ const unsigned int j = i >> 1;
+ vector unsigned char v_y1 = vec_ld(i, ysrc);
+ vector unsigned char v_u = vec_ld(j, usrc);
+ vector unsigned char v_v = vec_ld(j, vsrc);
+ vector unsigned char v_uv_a = vec_mergeh(v_u, v_v);
+ vector unsigned char v_uyvy_0 = vec_mergeh(v_uv_a, v_y1);
+ vector unsigned char v_uyvy_1 = vec_mergel(v_uv_a, v_y1);
+ vec_st(v_uyvy_0, (i << 1), dst);
+ vec_st(v_uyvy_1, (i << 1) + 16, dst);
+ }
+ if((y&(vertLumPerChroma-1))==(vertLumPerChroma-1) )
+ {
+ usrc += chromStride;
+ vsrc += chromStride;
+ }
+ ysrc += lumStride;
+ dst += dstStride;
+ }
+ return srcSliceH;
+}
diff --git a/contrib/ffmpeg/libswscale/swscale_internal.h b/contrib/ffmpeg/libswscale/swscale_internal.h
new file mode 100644
index 000000000..5b62ea065
--- /dev/null
+++ b/contrib/ffmpeg/libswscale/swscale_internal.h
@@ -0,0 +1,224 @@
+/*
+ * Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef SWSCALE_INTERNAL_H
+#define SWSCALE_INTERNAL_H
+
+#ifdef HAVE_ALTIVEC_H
+#include <altivec.h>
+#endif
+
+#include "avutil.h"
+
+#ifdef CONFIG_DARWIN
+#define AVV(x...) (x)
+#else
+#define AVV(x...) {x}
+#endif
+
+#define MAX_FILTER_SIZE 256
+
+typedef int (*SwsFunc)(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY,
+ int srcSliceH, uint8_t* dst[], int dstStride[]);
+
+/* this struct should be aligned on at least 32-byte boundary */
+typedef struct SwsContext{
+ /**
+ * info on struct for av_log
+ */
+ AVClass *av_class;
+
+ /**
+ *
+ * Note the src,dst,srcStride,dstStride will be copied, in the sws_scale() warper so they can freely be modified here
+ */
+ SwsFunc swScale;
+ int srcW, srcH, dstH;
+ int chrSrcW, chrSrcH, chrDstW, chrDstH;
+ int lumXInc, chrXInc;
+ int lumYInc, chrYInc;
+ int dstFormat, srcFormat; ///< format 4:2:0 type is allways YV12
+ int origDstFormat, origSrcFormat; ///< format
+ int chrSrcHSubSample, chrSrcVSubSample;
+ int chrIntHSubSample, chrIntVSubSample;
+ int chrDstHSubSample, chrDstVSubSample;
+ int vChrDrop;
+ int sliceDir;
+ double param[2];
+
+ int16_t **lumPixBuf;
+ int16_t **chrPixBuf;
+ int16_t *hLumFilter;
+ int16_t *hLumFilterPos;
+ int16_t *hChrFilter;
+ int16_t *hChrFilterPos;
+ int16_t *vLumFilter;
+ int16_t *vLumFilterPos;
+ int16_t *vChrFilter;
+ int16_t *vChrFilterPos;
+
+ uint8_t formatConvBuffer[4000]; //FIXME dynamic alloc, 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;
+
+ uint8_t *funnyYCode;
+ uint8_t *funnyUVCode;
+ int32_t *lumMmx2FilterPos;
+ int32_t *chrMmx2FilterPos;
+ int16_t *lumMmx2Filter;
+ int16_t *chrMmx2Filter;
+
+ int canMMX2BeUsed;
+
+ int lastInLumBuf;
+ int lastInChrBuf;
+ int lumBufIndex;
+ int chrBufIndex;
+ int dstY;
+ int flags;
+ void * yuvTable; // pointer to the yuv->rgb table start so it can be freed()
+ uint8_t * table_rV[256];
+ uint8_t * table_gU[256];
+ int table_gV[256];
+ uint8_t * table_bU[256];
+
+ //Colorspace stuff
+ int contrast, brightness, saturation; // for sws_getColorspaceDetails
+ int srcColorspaceTable[4];
+ int dstColorspaceTable[4];
+ int srcRange, dstRange;
+
+#define RED_DITHER "0*8"
+#define GREEN_DITHER "1*8"
+#define BLUE_DITHER "2*8"
+#define Y_COEFF "3*8"
+#define VR_COEFF "4*8"
+#define UB_COEFF "5*8"
+#define VG_COEFF "6*8"
+#define UG_COEFF "7*8"
+#define Y_OFFSET "8*8"
+#define U_OFFSET "9*8"
+#define V_OFFSET "10*8"
+#define LUM_MMX_FILTER_OFFSET "11*8"
+#define CHR_MMX_FILTER_OFFSET "11*8+4*4*256"
+#define DSTW_OFFSET "11*8+4*4*256*2" //do not change, its hardcoded in the asm
+#define ESP_OFFSET "11*8+4*4*256*2+8"
+#define VROUNDER_OFFSET "11*8+4*4*256*2+16"
+#define U_TEMP "11*8+4*4*256*2+24"
+#define V_TEMP "11*8+4*4*256*2+32"
+
+ uint64_t redDither __attribute__((aligned(8)));
+ uint64_t greenDither __attribute__((aligned(8)));
+ uint64_t blueDither __attribute__((aligned(8)));
+
+ uint64_t yCoeff __attribute__((aligned(8)));
+ uint64_t vrCoeff __attribute__((aligned(8)));
+ uint64_t ubCoeff __attribute__((aligned(8)));
+ uint64_t vgCoeff __attribute__((aligned(8)));
+ uint64_t ugCoeff __attribute__((aligned(8)));
+ uint64_t yOffset __attribute__((aligned(8)));
+ uint64_t uOffset __attribute__((aligned(8)));
+ uint64_t vOffset __attribute__((aligned(8)));
+ int32_t lumMmxFilter[4*MAX_FILTER_SIZE];
+ int32_t chrMmxFilter[4*MAX_FILTER_SIZE];
+ int dstW;
+ uint64_t esp __attribute__((aligned(8)));
+ uint64_t vRounder __attribute__((aligned(8)));
+ uint64_t u_temp __attribute__((aligned(8)));
+ uint64_t v_temp __attribute__((aligned(8)));
+
+#ifdef 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;
+
+#endif
+
+} SwsContext;
+//FIXME check init (where 0)
+
+SwsFunc yuv2rgb_get_func_ptr (SwsContext *c);
+int yuv2rgb_c_init_tables (SwsContext *c, const int inv_table[4], int fullRange, int brightness, int contrast, int saturation);
+
+char *sws_format_name(int format);
+
+//FIXME replace this with something faster
+#define isPlanarYUV(x) ((x)==PIX_FMT_YUV410P || (x)==PIX_FMT_YUV420P \
+ || (x)==PIX_FMT_YUV411P || (x)==PIX_FMT_YUV422P \
+ || (x)==PIX_FMT_YUV444P || (x)==PIX_FMT_NV12 \
+ || (x)==PIX_FMT_NV21)
+#define isYUV(x) ((x)==PIX_FMT_UYVY422 || (x)==PIX_FMT_YUYV422 || isPlanarYUV(x))
+#define isGray(x) ((x)==PIX_FMT_GRAY8 || (x)==PIX_FMT_GRAY16BE || (x)==PIX_FMT_GRAY16LE)
+#define isGray16(x) ((x)==PIX_FMT_GRAY16BE || (x)==PIX_FMT_GRAY16LE)
+#define isRGB(x) ((x)==PIX_FMT_BGR32 || (x)==PIX_FMT_RGB24 \
+ || (x)==PIX_FMT_RGB565 || (x)==PIX_FMT_RGB555 \
+ || (x)==PIX_FMT_RGB8 || (x)==PIX_FMT_RGB4 || (x)==PIX_FMT_RGB4_BYTE \
+ || (x)==PIX_FMT_MONOBLACK)
+#define isBGR(x) ((x)==PIX_FMT_RGB32 || (x)==PIX_FMT_BGR24 \
+ || (x)==PIX_FMT_BGR565 || (x)==PIX_FMT_BGR555 \
+ || (x)==PIX_FMT_BGR8 || (x)==PIX_FMT_BGR4 || (x)==PIX_FMT_BGR4_BYTE \
+ || (x)==PIX_FMT_MONOBLACK)
+
+static inline int fmt_depth(int fmt)
+{
+ switch(fmt) {
+ 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:
+ return 1;
+ default:
+ return 0;
+ }
+}
+
+#endif
diff --git a/contrib/ffmpeg/libswscale/swscale_template.c b/contrib/ffmpeg/libswscale/swscale_template.c
new file mode 100644
index 000000000..ad46be127
--- /dev/null
+++ b/contrib/ffmpeg/libswscale/swscale_template.c
@@ -0,0 +1,3288 @@
+/*
+ * Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * the C code (not assembly, mmx, ...) of this file can be used
+ * under the LGPL license too
+ */
+
+#undef REAL_MOVNTQ
+#undef MOVNTQ
+#undef PAVGB
+#undef PREFETCH
+#undef PREFETCHW
+#undef EMMS
+#undef SFENCE
+
+#ifdef HAVE_3DNOW
+/* On K6 femms is faster of emms. On K7 femms is directly mapped on emms. */
+#define EMMS "femms"
+#else
+#define EMMS "emms"
+#endif
+
+#ifdef HAVE_3DNOW
+#define PREFETCH "prefetch"
+#define PREFETCHW "prefetchw"
+#elif defined ( HAVE_MMX2 )
+#define PREFETCH "prefetchnta"
+#define PREFETCHW "prefetcht0"
+#else
+#define PREFETCH " # nop"
+#define PREFETCHW " # nop"
+#endif
+
+#ifdef HAVE_MMX2
+#define SFENCE "sfence"
+#else
+#define SFENCE " # nop"
+#endif
+
+#ifdef HAVE_MMX2
+#define PAVGB(a,b) "pavgb " #a ", " #b " \n\t"
+#elif defined (HAVE_3DNOW)
+#define PAVGB(a,b) "pavgusb " #a ", " #b " \n\t"
+#endif
+
+#ifdef HAVE_MMX2
+#define REAL_MOVNTQ(a,b) "movntq " #a ", " #b " \n\t"
+#else
+#define REAL_MOVNTQ(a,b) "movq " #a ", " #b " \n\t"
+#endif
+#define MOVNTQ(a,b) REAL_MOVNTQ(a,b)
+
+#ifdef HAVE_ALTIVEC
+#include "swscale_altivec_template.c"
+#endif
+
+#define YSCALEYUV2YV12X(x, offset, dest, width) \
+ asm volatile(\
+ "xor %%"REG_a", %%"REG_a" \n\t"\
+ "movq "VROUNDER_OFFSET"(%0), %%mm3\n\t"\
+ "movq %%mm3, %%mm4 \n\t"\
+ "lea " offset "(%0), %%"REG_d" \n\t"\
+ "mov (%%"REG_d"), %%"REG_S" \n\t"\
+ ASMALIGN(4) /* FIXME Unroll? */\
+ "1: \n\t"\
+ "movq 8(%%"REG_d"), %%mm0 \n\t" /* filterCoeff */\
+ "movq " #x "(%%"REG_S", %%"REG_a", 2), %%mm2\n\t" /* srcData */\
+ "movq 8+" #x "(%%"REG_S", %%"REG_a", 2), %%mm5\n\t" /* srcData */\
+ "add $16, %%"REG_d" \n\t"\
+ "mov (%%"REG_d"), %%"REG_S" \n\t"\
+ "test %%"REG_S", %%"REG_S" \n\t"\
+ "pmulhw %%mm0, %%mm2 \n\t"\
+ "pmulhw %%mm0, %%mm5 \n\t"\
+ "paddw %%mm2, %%mm3 \n\t"\
+ "paddw %%mm5, %%mm4 \n\t"\
+ " jnz 1b \n\t"\
+ "psraw $3, %%mm3 \n\t"\
+ "psraw $3, %%mm4 \n\t"\
+ "packuswb %%mm4, %%mm3 \n\t"\
+ MOVNTQ(%%mm3, (%1, %%REGa))\
+ "add $8, %%"REG_a" \n\t"\
+ "cmp %2, %%"REG_a" \n\t"\
+ "movq "VROUNDER_OFFSET"(%0), %%mm3\n\t"\
+ "movq %%mm3, %%mm4 \n\t"\
+ "lea " offset "(%0), %%"REG_d" \n\t"\
+ "mov (%%"REG_d"), %%"REG_S" \n\t"\
+ "jb 1b \n\t"\
+ :: "r" (&c->redDither),\
+ "r" (dest), "g" (width)\
+ : "%"REG_a, "%"REG_d, "%"REG_S\
+ );
+
+#define YSCALEYUV2YV12X_ACCURATE(x, offset, dest, width) \
+ asm volatile(\
+ "lea " offset "(%0), %%"REG_d" \n\t"\
+ "xor %%"REG_a", %%"REG_a" \n\t"\
+ "pxor %%mm4, %%mm4 \n\t"\
+ "pxor %%mm5, %%mm5 \n\t"\
+ "pxor %%mm6, %%mm6 \n\t"\
+ "pxor %%mm7, %%mm7 \n\t"\
+ "mov (%%"REG_d"), %%"REG_S" \n\t"\
+ ASMALIGN(4) \
+ "1: \n\t"\
+ "movq " #x "(%%"REG_S", %%"REG_a", 2), %%mm0\n\t" /* srcData */\
+ "movq 8+" #x "(%%"REG_S", %%"REG_a", 2), %%mm2\n\t" /* srcData */\
+ "mov 4(%%"REG_d"), %%"REG_S" \n\t"\
+ "movq " #x "(%%"REG_S", %%"REG_a", 2), %%mm1\n\t" /* srcData */\
+ "movq %%mm0, %%mm3 \n\t"\
+ "punpcklwd %%mm1, %%mm0 \n\t"\
+ "punpckhwd %%mm1, %%mm3 \n\t"\
+ "movq 8(%%"REG_d"), %%mm1 \n\t" /* filterCoeff */\
+ "pmaddwd %%mm1, %%mm0 \n\t"\
+ "pmaddwd %%mm1, %%mm3 \n\t"\
+ "paddd %%mm0, %%mm4 \n\t"\
+ "paddd %%mm3, %%mm5 \n\t"\
+ "movq 8+" #x "(%%"REG_S", %%"REG_a", 2), %%mm3\n\t" /* srcData */\
+ "mov 16(%%"REG_d"), %%"REG_S" \n\t"\
+ "add $16, %%"REG_d" \n\t"\
+ "test %%"REG_S", %%"REG_S" \n\t"\
+ "movq %%mm2, %%mm0 \n\t"\
+ "punpcklwd %%mm3, %%mm2 \n\t"\
+ "punpckhwd %%mm3, %%mm0 \n\t"\
+ "pmaddwd %%mm1, %%mm2 \n\t"\
+ "pmaddwd %%mm1, %%mm0 \n\t"\
+ "paddd %%mm2, %%mm6 \n\t"\
+ "paddd %%mm0, %%mm7 \n\t"\
+ " jnz 1b \n\t"\
+ "psrad $16, %%mm4 \n\t"\
+ "psrad $16, %%mm5 \n\t"\
+ "psrad $16, %%mm6 \n\t"\
+ "psrad $16, %%mm7 \n\t"\
+ "movq "VROUNDER_OFFSET"(%0), %%mm0\n\t"\
+ "packssdw %%mm5, %%mm4 \n\t"\
+ "packssdw %%mm7, %%mm6 \n\t"\
+ "paddw %%mm0, %%mm4 \n\t"\
+ "paddw %%mm0, %%mm6 \n\t"\
+ "psraw $3, %%mm4 \n\t"\
+ "psraw $3, %%mm6 \n\t"\
+ "packuswb %%mm6, %%mm4 \n\t"\
+ MOVNTQ(%%mm4, (%1, %%REGa))\
+ "add $8, %%"REG_a" \n\t"\
+ "cmp %2, %%"REG_a" \n\t"\
+ "lea " offset "(%0), %%"REG_d" \n\t"\
+ "pxor %%mm4, %%mm4 \n\t"\
+ "pxor %%mm5, %%mm5 \n\t"\
+ "pxor %%mm6, %%mm6 \n\t"\
+ "pxor %%mm7, %%mm7 \n\t"\
+ "mov (%%"REG_d"), %%"REG_S" \n\t"\
+ "jb 1b \n\t"\
+ :: "r" (&c->redDither),\
+ "r" (dest), "g" (width)\
+ : "%"REG_a, "%"REG_d, "%"REG_S\
+ );
+
+#define YSCALEYUV2YV121 \
+ "mov %2, %%"REG_a" \n\t"\
+ ASMALIGN(4) /* FIXME Unroll? */\
+ "1: \n\t"\
+ "movq (%0, %%"REG_a", 2), %%mm0 \n\t"\
+ "movq 8(%0, %%"REG_a", 2), %%mm1\n\t"\
+ "psraw $7, %%mm0 \n\t"\
+ "psraw $7, %%mm1 \n\t"\
+ "packuswb %%mm1, %%mm0 \n\t"\
+ MOVNTQ(%%mm0, (%1, %%REGa))\
+ "add $8, %%"REG_a" \n\t"\
+ "jnc 1b \n\t"
+
+/*
+ :: "m" (-lumFilterSize), "m" (-chrFilterSize),
+ "m" (lumMmxFilter+lumFilterSize*4), "m" (chrMmxFilter+chrFilterSize*4),
+ "r" (dest), "m" (dstW),
+ "m" (lumSrc+lumFilterSize), "m" (chrSrc+chrFilterSize)
+ : "%eax", "%ebx", "%ecx", "%edx", "%esi"
+*/
+#define YSCALEYUV2PACKEDX \
+ asm volatile(\
+ "xor %%"REG_a", %%"REG_a" \n\t"\
+ ASMALIGN(4)\
+ "nop \n\t"\
+ "1: \n\t"\
+ "lea "CHR_MMX_FILTER_OFFSET"(%0), %%"REG_d"\n\t"\
+ "mov (%%"REG_d"), %%"REG_S" \n\t"\
+ "movq "VROUNDER_OFFSET"(%0), %%mm3\n\t"\
+ "movq %%mm3, %%mm4 \n\t"\
+ ASMALIGN(4)\
+ "2: \n\t"\
+ "movq 8(%%"REG_d"), %%mm0 \n\t" /* filterCoeff */\
+ "movq (%%"REG_S", %%"REG_a"), %%mm2 \n\t" /* UsrcData */\
+ "movq 4096(%%"REG_S", %%"REG_a"), %%mm5 \n\t" /* VsrcData */\
+ "add $16, %%"REG_d" \n\t"\
+ "mov (%%"REG_d"), %%"REG_S" \n\t"\
+ "pmulhw %%mm0, %%mm2 \n\t"\
+ "pmulhw %%mm0, %%mm5 \n\t"\
+ "paddw %%mm2, %%mm3 \n\t"\
+ "paddw %%mm5, %%mm4 \n\t"\
+ "test %%"REG_S", %%"REG_S" \n\t"\
+ " jnz 2b \n\t"\
+\
+ "lea "LUM_MMX_FILTER_OFFSET"(%0), %%"REG_d"\n\t"\
+ "mov (%%"REG_d"), %%"REG_S" \n\t"\
+ "movq "VROUNDER_OFFSET"(%0), %%mm1\n\t"\
+ "movq %%mm1, %%mm7 \n\t"\
+ ASMALIGN(4)\
+ "2: \n\t"\
+ "movq 8(%%"REG_d"), %%mm0 \n\t" /* filterCoeff */\
+ "movq (%%"REG_S", %%"REG_a", 2), %%mm2 \n\t" /* Y1srcData */\
+ "movq 8(%%"REG_S", %%"REG_a", 2), %%mm5 \n\t" /* Y2srcData */\
+ "add $16, %%"REG_d" \n\t"\
+ "mov (%%"REG_d"), %%"REG_S" \n\t"\
+ "pmulhw %%mm0, %%mm2 \n\t"\
+ "pmulhw %%mm0, %%mm5 \n\t"\
+ "paddw %%mm2, %%mm1 \n\t"\
+ "paddw %%mm5, %%mm7 \n\t"\
+ "test %%"REG_S", %%"REG_S" \n\t"\
+ " jnz 2b \n\t"\
+
+#define YSCALEYUV2PACKEDX_END\
+ :: "r" (&c->redDither), \
+ "m" (dummy), "m" (dummy), "m" (dummy),\
+ "r" (dest), "m" (dstW)\
+ : "%"REG_a, "%"REG_d, "%"REG_S\
+ );
+
+#define YSCALEYUV2PACKEDX_ACCURATE \
+ asm volatile(\
+ "xor %%"REG_a", %%"REG_a" \n\t"\
+ ASMALIGN(4)\
+ "nop \n\t"\
+ "1: \n\t"\
+ "lea "CHR_MMX_FILTER_OFFSET"(%0), %%"REG_d"\n\t"\
+ "mov (%%"REG_d"), %%"REG_S" \n\t"\
+ "pxor %%mm4, %%mm4 \n\t"\
+ "pxor %%mm5, %%mm5 \n\t"\
+ "pxor %%mm6, %%mm6 \n\t"\
+ "pxor %%mm7, %%mm7 \n\t"\
+ ASMALIGN(4)\
+ "2: \n\t"\
+ "movq (%%"REG_S", %%"REG_a"), %%mm0 \n\t" /* UsrcData */\
+ "movq 4096(%%"REG_S", %%"REG_a"), %%mm2 \n\t" /* VsrcData */\
+ "mov 4(%%"REG_d"), %%"REG_S" \n\t"\
+ "movq (%%"REG_S", %%"REG_a"), %%mm1 \n\t" /* UsrcData */\
+ "movq %%mm0, %%mm3 \n\t"\
+ "punpcklwd %%mm1, %%mm0 \n\t"\
+ "punpckhwd %%mm1, %%mm3 \n\t"\
+ "movq 8(%%"REG_d"), %%mm1 \n\t" /* filterCoeff */\
+ "pmaddwd %%mm1, %%mm0 \n\t"\
+ "pmaddwd %%mm1, %%mm3 \n\t"\
+ "paddd %%mm0, %%mm4 \n\t"\
+ "paddd %%mm3, %%mm5 \n\t"\
+ "movq 4096(%%"REG_S", %%"REG_a"), %%mm3 \n\t" /* VsrcData */\
+ "mov 16(%%"REG_d"), %%"REG_S" \n\t"\
+ "add $16, %%"REG_d" \n\t"\
+ "test %%"REG_S", %%"REG_S" \n\t"\
+ "movq %%mm2, %%mm0 \n\t"\
+ "punpcklwd %%mm3, %%mm2 \n\t"\
+ "punpckhwd %%mm3, %%mm0 \n\t"\
+ "pmaddwd %%mm1, %%mm2 \n\t"\
+ "pmaddwd %%mm1, %%mm0 \n\t"\
+ "paddd %%mm2, %%mm6 \n\t"\
+ "paddd %%mm0, %%mm7 \n\t"\
+ " jnz 2b \n\t"\
+ "psrad $16, %%mm4 \n\t"\
+ "psrad $16, %%mm5 \n\t"\
+ "psrad $16, %%mm6 \n\t"\
+ "psrad $16, %%mm7 \n\t"\
+ "movq "VROUNDER_OFFSET"(%0), %%mm0\n\t"\
+ "packssdw %%mm5, %%mm4 \n\t"\
+ "packssdw %%mm7, %%mm6 \n\t"\
+ "paddw %%mm0, %%mm4 \n\t"\
+ "paddw %%mm0, %%mm6 \n\t"\
+ "movq %%mm4, "U_TEMP"(%0) \n\t"\
+ "movq %%mm6, "V_TEMP"(%0) \n\t"\
+\
+ "lea "LUM_MMX_FILTER_OFFSET"(%0), %%"REG_d"\n\t"\
+ "mov (%%"REG_d"), %%"REG_S" \n\t"\
+ "pxor %%mm1, %%mm1 \n\t"\
+ "pxor %%mm5, %%mm5 \n\t"\
+ "pxor %%mm7, %%mm7 \n\t"\
+ "pxor %%mm6, %%mm6 \n\t"\
+ ASMALIGN(4)\
+ "2: \n\t"\
+ "movq (%%"REG_S", %%"REG_a", 2), %%mm0 \n\t" /* Y1srcData */\
+ "movq 8(%%"REG_S", %%"REG_a", 2), %%mm2 \n\t" /* Y2srcData */\
+ "mov 4(%%"REG_d"), %%"REG_S" \n\t"\
+ "movq (%%"REG_S", %%"REG_a", 2), %%mm4 \n\t" /* Y1srcData */\
+ "movq %%mm0, %%mm3 \n\t"\
+ "punpcklwd %%mm4, %%mm0 \n\t"\
+ "punpckhwd %%mm4, %%mm3 \n\t"\
+ "movq 8(%%"REG_d"), %%mm4 \n\t" /* filterCoeff */\
+ "pmaddwd %%mm4, %%mm0 \n\t"\
+ "pmaddwd %%mm4, %%mm3 \n\t"\
+ "paddd %%mm0, %%mm1 \n\t"\
+ "paddd %%mm3, %%mm5 \n\t"\
+ "movq 8(%%"REG_S", %%"REG_a", 2), %%mm3 \n\t" /* Y2srcData */\
+ "mov 16(%%"REG_d"), %%"REG_S" \n\t"\
+ "add $16, %%"REG_d" \n\t"\
+ "test %%"REG_S", %%"REG_S" \n\t"\
+ "movq %%mm2, %%mm0 \n\t"\
+ "punpcklwd %%mm3, %%mm2 \n\t"\
+ "punpckhwd %%mm3, %%mm0 \n\t"\
+ "pmaddwd %%mm4, %%mm2 \n\t"\
+ "pmaddwd %%mm4, %%mm0 \n\t"\
+ "paddd %%mm2, %%mm7 \n\t"\
+ "paddd %%mm0, %%mm6 \n\t"\
+ " jnz 2b \n\t"\
+ "psrad $16, %%mm1 \n\t"\
+ "psrad $16, %%mm5 \n\t"\
+ "psrad $16, %%mm7 \n\t"\
+ "psrad $16, %%mm6 \n\t"\
+ "movq "VROUNDER_OFFSET"(%0), %%mm0\n\t"\
+ "packssdw %%mm5, %%mm1 \n\t"\
+ "packssdw %%mm6, %%mm7 \n\t"\
+ "paddw %%mm0, %%mm1 \n\t"\
+ "paddw %%mm0, %%mm7 \n\t"\
+ "movq "U_TEMP"(%0), %%mm3 \n\t"\
+ "movq "V_TEMP"(%0), %%mm4 \n\t"\
+
+#define YSCALEYUV2RGBX \
+ "psubw "U_OFFSET"(%0), %%mm3 \n\t" /* (U-128)8*/\
+ "psubw "V_OFFSET"(%0), %%mm4 \n\t" /* (V-128)8*/\
+ "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\
+ "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\
+ "pmulhw "UG_COEFF"(%0), %%mm3 \n\t"\
+ "pmulhw "VG_COEFF"(%0), %%mm4 \n\t"\
+ /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\
+ "pmulhw "UB_COEFF"(%0), %%mm2 \n\t"\
+ "pmulhw "VR_COEFF"(%0), %%mm5 \n\t"\
+ "psubw "Y_OFFSET"(%0), %%mm1 \n\t" /* 8(Y-16)*/\
+ "psubw "Y_OFFSET"(%0), %%mm7 \n\t" /* 8(Y-16)*/\
+ "pmulhw "Y_COEFF"(%0), %%mm1 \n\t"\
+ "pmulhw "Y_COEFF"(%0), %%mm7 \n\t"\
+ /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\
+ "paddw %%mm3, %%mm4 \n\t"\
+ "movq %%mm2, %%mm0 \n\t"\
+ "movq %%mm5, %%mm6 \n\t"\
+ "movq %%mm4, %%mm3 \n\t"\
+ "punpcklwd %%mm2, %%mm2 \n\t"\
+ "punpcklwd %%mm5, %%mm5 \n\t"\
+ "punpcklwd %%mm4, %%mm4 \n\t"\
+ "paddw %%mm1, %%mm2 \n\t"\
+ "paddw %%mm1, %%mm5 \n\t"\
+ "paddw %%mm1, %%mm4 \n\t"\
+ "punpckhwd %%mm0, %%mm0 \n\t"\
+ "punpckhwd %%mm6, %%mm6 \n\t"\
+ "punpckhwd %%mm3, %%mm3 \n\t"\
+ "paddw %%mm7, %%mm0 \n\t"\
+ "paddw %%mm7, %%mm6 \n\t"\
+ "paddw %%mm7, %%mm3 \n\t"\
+ /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\
+ "packuswb %%mm0, %%mm2 \n\t"\
+ "packuswb %%mm6, %%mm5 \n\t"\
+ "packuswb %%mm3, %%mm4 \n\t"\
+ "pxor %%mm7, %%mm7 \n\t"
+#if 0
+#define FULL_YSCALEYUV2RGB \
+ "pxor %%mm7, %%mm7 \n\t"\
+ "movd %6, %%mm6 \n\t" /*yalpha1*/\
+ "punpcklwd %%mm6, %%mm6 \n\t"\
+ "punpcklwd %%mm6, %%mm6 \n\t"\
+ "movd %7, %%mm5 \n\t" /*uvalpha1*/\
+ "punpcklwd %%mm5, %%mm5 \n\t"\
+ "punpcklwd %%mm5, %%mm5 \n\t"\
+ "xor %%"REG_a", %%"REG_a" \n\t"\
+ ASMALIGN(4)\
+ "1: \n\t"\
+ "movq (%0, %%"REG_a", 2), %%mm0 \n\t" /*buf0[eax]*/\
+ "movq (%1, %%"REG_a", 2), %%mm1 \n\t" /*buf1[eax]*/\
+ "movq (%2, %%"REG_a",2), %%mm2 \n\t" /* uvbuf0[eax]*/\
+ "movq (%3, %%"REG_a",2), %%mm3 \n\t" /* uvbuf1[eax]*/\
+ "psubw %%mm1, %%mm0 \n\t" /* buf0[eax] - buf1[eax]*/\
+ "psubw %%mm3, %%mm2 \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\
+ "pmulhw %%mm6, %%mm0 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
+ "pmulhw %%mm5, %%mm2 \n\t" /* (uvbuf0[eax] - uvbuf1[eax])uvalpha1>>16*/\
+ "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
+ "movq 4096(%2, %%"REG_a",2), %%mm4 \n\t" /* uvbuf0[eax+2048]*/\
+ "psraw $4, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\
+ "paddw %%mm0, %%mm1 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
+ "movq 4096(%3, %%"REG_a",2), %%mm0 \n\t" /* uvbuf1[eax+2048]*/\
+ "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax]uvalpha1 - uvbuf1[eax](1-uvalpha1)*/\
+ "psubw %%mm0, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\
+ "psubw "MANGLE(w80)", %%mm1 \n\t" /* 8(Y-16)*/\
+ "psubw "MANGLE(w400)", %%mm3 \n\t" /* 8(U-128)*/\
+ "pmulhw "MANGLE(yCoeff)", %%mm1 \n\t"\
+\
+\
+ "pmulhw %%mm5, %%mm4 \n\t" /* (uvbuf0[eax+2048] - uvbuf1[eax+2048])uvalpha1>>16*/\
+ "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\
+ "pmulhw "MANGLE(ubCoeff)", %%mm3\n\t"\
+ "psraw $4, %%mm0 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\
+ "pmulhw "MANGLE(ugCoeff)", %%mm2\n\t"\
+ "paddw %%mm4, %%mm0 \n\t" /* uvbuf0[eax+2048]uvalpha1 - uvbuf1[eax+2048](1-uvalpha1)*/\
+ "psubw "MANGLE(w400)", %%mm0 \n\t" /* (V-128)8*/\
+\
+\
+ "movq %%mm0, %%mm4 \n\t" /* (V-128)8*/\
+ "pmulhw "MANGLE(vrCoeff)", %%mm0\n\t"\
+ "pmulhw "MANGLE(vgCoeff)", %%mm4\n\t"\
+ "paddw %%mm1, %%mm3 \n\t" /* B*/\
+ "paddw %%mm1, %%mm0 \n\t" /* R*/\
+ "packuswb %%mm3, %%mm3 \n\t"\
+\
+ "packuswb %%mm0, %%mm0 \n\t"\
+ "paddw %%mm4, %%mm2 \n\t"\
+ "paddw %%mm2, %%mm1 \n\t" /* G*/\
+\
+ "packuswb %%mm1, %%mm1 \n\t"
+#endif
+
+#define REAL_YSCALEYUV2PACKED(index, c) \
+ "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0\n\t"\
+ "movq "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm1\n\t"\
+ "psraw $3, %%mm0 \n\t"\
+ "psraw $3, %%mm1 \n\t"\
+ "movq %%mm0, "CHR_MMX_FILTER_OFFSET"+8("#c")\n\t"\
+ "movq %%mm1, "LUM_MMX_FILTER_OFFSET"+8("#c")\n\t"\
+ "xor "#index", "#index" \n\t"\
+ ASMALIGN(4)\
+ "1: \n\t"\
+ "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\
+ "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\
+ "movq 4096(%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\
+ "movq 4096(%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\
+ "psubw %%mm3, %%mm2 \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\
+ "psubw %%mm4, %%mm5 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\
+ "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0\n\t"\
+ "pmulhw %%mm0, %%mm2 \n\t" /* (uvbuf0[eax] - uvbuf1[eax])uvalpha1>>16*/\
+ "pmulhw %%mm0, %%mm5 \n\t" /* (uvbuf0[eax+2048] - uvbuf1[eax+2048])uvalpha1>>16*/\
+ "psraw $7, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\
+ "psraw $7, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\
+ "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax]uvalpha1 - uvbuf1[eax](1-uvalpha1)*/\
+ "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048]uvalpha1 - uvbuf1[eax+2048](1-uvalpha1)*/\
+ "movq (%0, "#index", 2), %%mm0 \n\t" /*buf0[eax]*/\
+ "movq (%1, "#index", 2), %%mm1 \n\t" /*buf1[eax]*/\
+ "movq 8(%0, "#index", 2), %%mm6 \n\t" /*buf0[eax]*/\
+ "movq 8(%1, "#index", 2), %%mm7 \n\t" /*buf1[eax]*/\
+ "psubw %%mm1, %%mm0 \n\t" /* buf0[eax] - buf1[eax]*/\
+ "psubw %%mm7, %%mm6 \n\t" /* buf0[eax] - buf1[eax]*/\
+ "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm0\n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
+ "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm6\n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
+ "psraw $7, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
+ "psraw $7, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
+ "paddw %%mm0, %%mm1 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
+ "paddw %%mm6, %%mm7 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
+
+#define YSCALEYUV2PACKED(index, c) REAL_YSCALEYUV2PACKED(index, c)
+
+#define REAL_YSCALEYUV2RGB(index, c) \
+ "xor "#index", "#index" \n\t"\
+ ASMALIGN(4)\
+ "1: \n\t"\
+ "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\
+ "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\
+ "movq 4096(%2, "#index"), %%mm5\n\t" /* uvbuf0[eax+2048]*/\
+ "movq 4096(%3, "#index"), %%mm4\n\t" /* uvbuf1[eax+2048]*/\
+ "psubw %%mm3, %%mm2 \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\
+ "psubw %%mm4, %%mm5 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\
+ "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0\n\t"\
+ "pmulhw %%mm0, %%mm2 \n\t" /* (uvbuf0[eax] - uvbuf1[eax])uvalpha1>>16*/\
+ "pmulhw %%mm0, %%mm5 \n\t" /* (uvbuf0[eax+2048] - uvbuf1[eax+2048])uvalpha1>>16*/\
+ "psraw $4, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\
+ "psraw $4, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\
+ "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax]uvalpha1 - uvbuf1[eax](1-uvalpha1)*/\
+ "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048]uvalpha1 - uvbuf1[eax+2048](1-uvalpha1)*/\
+ "psubw "U_OFFSET"("#c"), %%mm3 \n\t" /* (U-128)8*/\
+ "psubw "V_OFFSET"("#c"), %%mm4 \n\t" /* (V-128)8*/\
+ "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\
+ "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\
+ "pmulhw "UG_COEFF"("#c"), %%mm3\n\t"\
+ "pmulhw "VG_COEFF"("#c"), %%mm4\n\t"\
+ /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\
+ "movq (%0, "#index", 2), %%mm0 \n\t" /*buf0[eax]*/\
+ "movq (%1, "#index", 2), %%mm1 \n\t" /*buf1[eax]*/\
+ "movq 8(%0, "#index", 2), %%mm6\n\t" /*buf0[eax]*/\
+ "movq 8(%1, "#index", 2), %%mm7\n\t" /*buf1[eax]*/\
+ "psubw %%mm1, %%mm0 \n\t" /* buf0[eax] - buf1[eax]*/\
+ "psubw %%mm7, %%mm6 \n\t" /* buf0[eax] - buf1[eax]*/\
+ "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm0\n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
+ "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm6\n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
+ "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
+ "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
+ "paddw %%mm0, %%mm1 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
+ "paddw %%mm6, %%mm7 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
+ "pmulhw "UB_COEFF"("#c"), %%mm2\n\t"\
+ "pmulhw "VR_COEFF"("#c"), %%mm5\n\t"\
+ "psubw "Y_OFFSET"("#c"), %%mm1 \n\t" /* 8(Y-16)*/\
+ "psubw "Y_OFFSET"("#c"), %%mm7 \n\t" /* 8(Y-16)*/\
+ "pmulhw "Y_COEFF"("#c"), %%mm1 \n\t"\
+ "pmulhw "Y_COEFF"("#c"), %%mm7 \n\t"\
+ /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\
+ "paddw %%mm3, %%mm4 \n\t"\
+ "movq %%mm2, %%mm0 \n\t"\
+ "movq %%mm5, %%mm6 \n\t"\
+ "movq %%mm4, %%mm3 \n\t"\
+ "punpcklwd %%mm2, %%mm2 \n\t"\
+ "punpcklwd %%mm5, %%mm5 \n\t"\
+ "punpcklwd %%mm4, %%mm4 \n\t"\
+ "paddw %%mm1, %%mm2 \n\t"\
+ "paddw %%mm1, %%mm5 \n\t"\
+ "paddw %%mm1, %%mm4 \n\t"\
+ "punpckhwd %%mm0, %%mm0 \n\t"\
+ "punpckhwd %%mm6, %%mm6 \n\t"\
+ "punpckhwd %%mm3, %%mm3 \n\t"\
+ "paddw %%mm7, %%mm0 \n\t"\
+ "paddw %%mm7, %%mm6 \n\t"\
+ "paddw %%mm7, %%mm3 \n\t"\
+ /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\
+ "packuswb %%mm0, %%mm2 \n\t"\
+ "packuswb %%mm6, %%mm5 \n\t"\
+ "packuswb %%mm3, %%mm4 \n\t"\
+ "pxor %%mm7, %%mm7 \n\t"
+#define YSCALEYUV2RGB(index, c) REAL_YSCALEYUV2RGB(index, c)
+
+#define REAL_YSCALEYUV2PACKED1(index, c) \
+ "xor "#index", "#index" \n\t"\
+ ASMALIGN(4)\
+ "1: \n\t"\
+ "movq (%2, "#index"), %%mm3 \n\t" /* uvbuf0[eax]*/\
+ "movq 4096(%2, "#index"), %%mm4 \n\t" /* uvbuf0[eax+2048]*/\
+ "psraw $7, %%mm3 \n\t" \
+ "psraw $7, %%mm4 \n\t" \
+ "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\
+ "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\
+ "psraw $7, %%mm1 \n\t" \
+ "psraw $7, %%mm7 \n\t" \
+
+#define YSCALEYUV2PACKED1(index, c) REAL_YSCALEYUV2PACKED1(index, c)
+
+#define REAL_YSCALEYUV2RGB1(index, c) \
+ "xor "#index", "#index" \n\t"\
+ ASMALIGN(4)\
+ "1: \n\t"\
+ "movq (%2, "#index"), %%mm3 \n\t" /* uvbuf0[eax]*/\
+ "movq 4096(%2, "#index"), %%mm4 \n\t" /* uvbuf0[eax+2048]*/\
+ "psraw $4, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\
+ "psraw $4, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\
+ "psubw "U_OFFSET"("#c"), %%mm3 \n\t" /* (U-128)8*/\
+ "psubw "V_OFFSET"("#c"), %%mm4 \n\t" /* (V-128)8*/\
+ "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\
+ "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\
+ "pmulhw "UG_COEFF"("#c"), %%mm3\n\t"\
+ "pmulhw "VG_COEFF"("#c"), %%mm4\n\t"\
+ /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\
+ "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\
+ "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\
+ "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
+ "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
+ "pmulhw "UB_COEFF"("#c"), %%mm2\n\t"\
+ "pmulhw "VR_COEFF"("#c"), %%mm5\n\t"\
+ "psubw "Y_OFFSET"("#c"), %%mm1 \n\t" /* 8(Y-16)*/\
+ "psubw "Y_OFFSET"("#c"), %%mm7 \n\t" /* 8(Y-16)*/\
+ "pmulhw "Y_COEFF"("#c"), %%mm1 \n\t"\
+ "pmulhw "Y_COEFF"("#c"), %%mm7 \n\t"\
+ /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\
+ "paddw %%mm3, %%mm4 \n\t"\
+ "movq %%mm2, %%mm0 \n\t"\
+ "movq %%mm5, %%mm6 \n\t"\
+ "movq %%mm4, %%mm3 \n\t"\
+ "punpcklwd %%mm2, %%mm2 \n\t"\
+ "punpcklwd %%mm5, %%mm5 \n\t"\
+ "punpcklwd %%mm4, %%mm4 \n\t"\
+ "paddw %%mm1, %%mm2 \n\t"\
+ "paddw %%mm1, %%mm5 \n\t"\
+ "paddw %%mm1, %%mm4 \n\t"\
+ "punpckhwd %%mm0, %%mm0 \n\t"\
+ "punpckhwd %%mm6, %%mm6 \n\t"\
+ "punpckhwd %%mm3, %%mm3 \n\t"\
+ "paddw %%mm7, %%mm0 \n\t"\
+ "paddw %%mm7, %%mm6 \n\t"\
+ "paddw %%mm7, %%mm3 \n\t"\
+ /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\
+ "packuswb %%mm0, %%mm2 \n\t"\
+ "packuswb %%mm6, %%mm5 \n\t"\
+ "packuswb %%mm3, %%mm4 \n\t"\
+ "pxor %%mm7, %%mm7 \n\t"
+#define YSCALEYUV2RGB1(index, c) REAL_YSCALEYUV2RGB1(index, c)
+
+#define REAL_YSCALEYUV2PACKED1b(index, c) \
+ "xor "#index", "#index" \n\t"\
+ ASMALIGN(4)\
+ "1: \n\t"\
+ "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\
+ "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\
+ "movq 4096(%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\
+ "movq 4096(%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\
+ "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax] + uvbuf1[eax]*/\
+ "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048] + uvbuf1[eax+2048]*/\
+ "psrlw $8, %%mm3 \n\t" \
+ "psrlw $8, %%mm4 \n\t" \
+ "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\
+ "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\
+ "psraw $7, %%mm1 \n\t" \
+ "psraw $7, %%mm7 \n\t"
+#define YSCALEYUV2PACKED1b(index, c) REAL_YSCALEYUV2PACKED1b(index, c)
+
+// do vertical chrominance interpolation
+#define REAL_YSCALEYUV2RGB1b(index, c) \
+ "xor "#index", "#index" \n\t"\
+ ASMALIGN(4)\
+ "1: \n\t"\
+ "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\
+ "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\
+ "movq 4096(%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\
+ "movq 4096(%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\
+ "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax] + uvbuf1[eax]*/\
+ "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048] + uvbuf1[eax+2048]*/\
+ "psrlw $5, %%mm3 \n\t" /*FIXME might overflow*/\
+ "psrlw $5, %%mm4 \n\t" /*FIXME might overflow*/\
+ "psubw "U_OFFSET"("#c"), %%mm3 \n\t" /* (U-128)8*/\
+ "psubw "V_OFFSET"("#c"), %%mm4 \n\t" /* (V-128)8*/\
+ "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\
+ "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\
+ "pmulhw "UG_COEFF"("#c"), %%mm3\n\t"\
+ "pmulhw "VG_COEFF"("#c"), %%mm4\n\t"\
+ /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\
+ "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\
+ "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\
+ "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
+ "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
+ "pmulhw "UB_COEFF"("#c"), %%mm2\n\t"\
+ "pmulhw "VR_COEFF"("#c"), %%mm5\n\t"\
+ "psubw "Y_OFFSET"("#c"), %%mm1 \n\t" /* 8(Y-16)*/\
+ "psubw "Y_OFFSET"("#c"), %%mm7 \n\t" /* 8(Y-16)*/\
+ "pmulhw "Y_COEFF"("#c"), %%mm1 \n\t"\
+ "pmulhw "Y_COEFF"("#c"), %%mm7 \n\t"\
+ /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\
+ "paddw %%mm3, %%mm4 \n\t"\
+ "movq %%mm2, %%mm0 \n\t"\
+ "movq %%mm5, %%mm6 \n\t"\
+ "movq %%mm4, %%mm3 \n\t"\
+ "punpcklwd %%mm2, %%mm2 \n\t"\
+ "punpcklwd %%mm5, %%mm5 \n\t"\
+ "punpcklwd %%mm4, %%mm4 \n\t"\
+ "paddw %%mm1, %%mm2 \n\t"\
+ "paddw %%mm1, %%mm5 \n\t"\
+ "paddw %%mm1, %%mm4 \n\t"\
+ "punpckhwd %%mm0, %%mm0 \n\t"\
+ "punpckhwd %%mm6, %%mm6 \n\t"\
+ "punpckhwd %%mm3, %%mm3 \n\t"\
+ "paddw %%mm7, %%mm0 \n\t"\
+ "paddw %%mm7, %%mm6 \n\t"\
+ "paddw %%mm7, %%mm3 \n\t"\
+ /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\
+ "packuswb %%mm0, %%mm2 \n\t"\
+ "packuswb %%mm6, %%mm5 \n\t"\
+ "packuswb %%mm3, %%mm4 \n\t"\
+ "pxor %%mm7, %%mm7 \n\t"
+#define YSCALEYUV2RGB1b(index, c) REAL_YSCALEYUV2RGB1b(index, c)
+
+#define REAL_WRITEBGR32(dst, dstw, index) \
+ /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\
+ "movq %%mm2, %%mm1 \n\t" /* B */\
+ "movq %%mm5, %%mm6 \n\t" /* R */\
+ "punpcklbw %%mm4, %%mm2 \n\t" /* GBGBGBGB 0 */\
+ "punpcklbw %%mm7, %%mm5 \n\t" /* 0R0R0R0R 0 */\
+ "punpckhbw %%mm4, %%mm1 \n\t" /* GBGBGBGB 2 */\
+ "punpckhbw %%mm7, %%mm6 \n\t" /* 0R0R0R0R 2 */\
+ "movq %%mm2, %%mm0 \n\t" /* GBGBGBGB 0 */\
+ "movq %%mm1, %%mm3 \n\t" /* GBGBGBGB 2 */\
+ "punpcklwd %%mm5, %%mm0 \n\t" /* 0RGB0RGB 0 */\
+ "punpckhwd %%mm5, %%mm2 \n\t" /* 0RGB0RGB 1 */\
+ "punpcklwd %%mm6, %%mm1 \n\t" /* 0RGB0RGB 2 */\
+ "punpckhwd %%mm6, %%mm3 \n\t" /* 0RGB0RGB 3 */\
+\
+ MOVNTQ(%%mm0, (dst, index, 4))\
+ MOVNTQ(%%mm2, 8(dst, index, 4))\
+ MOVNTQ(%%mm1, 16(dst, index, 4))\
+ MOVNTQ(%%mm3, 24(dst, index, 4))\
+\
+ "add $8, "#index" \n\t"\
+ "cmp "#dstw", "#index" \n\t"\
+ " jb 1b \n\t"
+#define WRITEBGR32(dst, dstw, index) REAL_WRITEBGR32(dst, dstw, index)
+
+#define REAL_WRITEBGR16(dst, dstw, index) \
+ "pand "MANGLE(bF8)", %%mm2 \n\t" /* B */\
+ "pand "MANGLE(bFC)", %%mm4 \n\t" /* G */\
+ "pand "MANGLE(bF8)", %%mm5 \n\t" /* R */\
+ "psrlq $3, %%mm2 \n\t"\
+\
+ "movq %%mm2, %%mm1 \n\t"\
+ "movq %%mm4, %%mm3 \n\t"\
+\
+ "punpcklbw %%mm7, %%mm3 \n\t"\
+ "punpcklbw %%mm5, %%mm2 \n\t"\
+ "punpckhbw %%mm7, %%mm4 \n\t"\
+ "punpckhbw %%mm5, %%mm1 \n\t"\
+\
+ "psllq $3, %%mm3 \n\t"\
+ "psllq $3, %%mm4 \n\t"\
+\
+ "por %%mm3, %%mm2 \n\t"\
+ "por %%mm4, %%mm1 \n\t"\
+\
+ MOVNTQ(%%mm2, (dst, index, 2))\
+ MOVNTQ(%%mm1, 8(dst, index, 2))\
+\
+ "add $8, "#index" \n\t"\
+ "cmp "#dstw", "#index" \n\t"\
+ " jb 1b \n\t"
+#define WRITEBGR16(dst, dstw, index) REAL_WRITEBGR16(dst, dstw, index)
+
+#define REAL_WRITEBGR15(dst, dstw, index) \
+ "pand "MANGLE(bF8)", %%mm2 \n\t" /* B */\
+ "pand "MANGLE(bF8)", %%mm4 \n\t" /* G */\
+ "pand "MANGLE(bF8)", %%mm5 \n\t" /* R */\
+ "psrlq $3, %%mm2 \n\t"\
+ "psrlq $1, %%mm5 \n\t"\
+\
+ "movq %%mm2, %%mm1 \n\t"\
+ "movq %%mm4, %%mm3 \n\t"\
+\
+ "punpcklbw %%mm7, %%mm3 \n\t"\
+ "punpcklbw %%mm5, %%mm2 \n\t"\
+ "punpckhbw %%mm7, %%mm4 \n\t"\
+ "punpckhbw %%mm5, %%mm1 \n\t"\
+\
+ "psllq $2, %%mm3 \n\t"\
+ "psllq $2, %%mm4 \n\t"\
+\
+ "por %%mm3, %%mm2 \n\t"\
+ "por %%mm4, %%mm1 \n\t"\
+\
+ MOVNTQ(%%mm2, (dst, index, 2))\
+ MOVNTQ(%%mm1, 8(dst, index, 2))\
+\
+ "add $8, "#index" \n\t"\
+ "cmp "#dstw", "#index" \n\t"\
+ " jb 1b \n\t"
+#define WRITEBGR15(dst, dstw, index) REAL_WRITEBGR15(dst, dstw, index)
+
+#define WRITEBGR24OLD(dst, dstw, index) \
+ /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\
+ "movq %%mm2, %%mm1 \n\t" /* B */\
+ "movq %%mm5, %%mm6 \n\t" /* R */\
+ "punpcklbw %%mm4, %%mm2 \n\t" /* GBGBGBGB 0 */\
+ "punpcklbw %%mm7, %%mm5 \n\t" /* 0R0R0R0R 0 */\
+ "punpckhbw %%mm4, %%mm1 \n\t" /* GBGBGBGB 2 */\
+ "punpckhbw %%mm7, %%mm6 \n\t" /* 0R0R0R0R 2 */\
+ "movq %%mm2, %%mm0 \n\t" /* GBGBGBGB 0 */\
+ "movq %%mm1, %%mm3 \n\t" /* GBGBGBGB 2 */\
+ "punpcklwd %%mm5, %%mm0 \n\t" /* 0RGB0RGB 0 */\
+ "punpckhwd %%mm5, %%mm2 \n\t" /* 0RGB0RGB 1 */\
+ "punpcklwd %%mm6, %%mm1 \n\t" /* 0RGB0RGB 2 */\
+ "punpckhwd %%mm6, %%mm3 \n\t" /* 0RGB0RGB 3 */\
+\
+ "movq %%mm0, %%mm4 \n\t" /* 0RGB0RGB 0 */\
+ "psrlq $8, %%mm0 \n\t" /* 00RGB0RG 0 */\
+ "pand "MANGLE(bm00000111)", %%mm4\n\t" /* 00000RGB 0 */\
+ "pand "MANGLE(bm11111000)", %%mm0\n\t" /* 00RGB000 0.5 */\
+ "por %%mm4, %%mm0 \n\t" /* 00RGBRGB 0 */\
+ "movq %%mm2, %%mm4 \n\t" /* 0RGB0RGB 1 */\
+ "psllq $48, %%mm2 \n\t" /* GB000000 1 */\
+ "por %%mm2, %%mm0 \n\t" /* GBRGBRGB 0 */\
+\
+ "movq %%mm4, %%mm2 \n\t" /* 0RGB0RGB 1 */\
+ "psrld $16, %%mm4 \n\t" /* 000R000R 1 */\
+ "psrlq $24, %%mm2 \n\t" /* 0000RGB0 1.5 */\
+ "por %%mm4, %%mm2 \n\t" /* 000RRGBR 1 */\
+ "pand "MANGLE(bm00001111)", %%mm2\n\t" /* 0000RGBR 1 */\
+ "movq %%mm1, %%mm4 \n\t" /* 0RGB0RGB 2 */\
+ "psrlq $8, %%mm1 \n\t" /* 00RGB0RG 2 */\
+ "pand "MANGLE(bm00000111)", %%mm4\n\t" /* 00000RGB 2 */\
+ "pand "MANGLE(bm11111000)", %%mm1\n\t" /* 00RGB000 2.5 */\
+ "por %%mm4, %%mm1 \n\t" /* 00RGBRGB 2 */\
+ "movq %%mm1, %%mm4 \n\t" /* 00RGBRGB 2 */\
+ "psllq $32, %%mm1 \n\t" /* BRGB0000 2 */\
+ "por %%mm1, %%mm2 \n\t" /* BRGBRGBR 1 */\
+\
+ "psrlq $32, %%mm4 \n\t" /* 000000RG 2.5 */\
+ "movq %%mm3, %%mm5 \n\t" /* 0RGB0RGB 3 */\
+ "psrlq $8, %%mm3 \n\t" /* 00RGB0RG 3 */\
+ "pand "MANGLE(bm00000111)", %%mm5\n\t" /* 00000RGB 3 */\
+ "pand "MANGLE(bm11111000)", %%mm3\n\t" /* 00RGB000 3.5 */\
+ "por %%mm5, %%mm3 \n\t" /* 00RGBRGB 3 */\
+ "psllq $16, %%mm3 \n\t" /* RGBRGB00 3 */\
+ "por %%mm4, %%mm3 \n\t" /* RGBRGBRG 2.5 */\
+\
+ MOVNTQ(%%mm0, (dst))\
+ MOVNTQ(%%mm2, 8(dst))\
+ MOVNTQ(%%mm3, 16(dst))\
+ "add $24, "#dst" \n\t"\
+\
+ "add $8, "#index" \n\t"\
+ "cmp "#dstw", "#index" \n\t"\
+ " jb 1b \n\t"
+
+#define WRITEBGR24MMX(dst, dstw, index) \
+ /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\
+ "movq %%mm2, %%mm1 \n\t" /* B */\
+ "movq %%mm5, %%mm6 \n\t" /* R */\
+ "punpcklbw %%mm4, %%mm2 \n\t" /* GBGBGBGB 0 */\
+ "punpcklbw %%mm7, %%mm5 \n\t" /* 0R0R0R0R 0 */\
+ "punpckhbw %%mm4, %%mm1 \n\t" /* GBGBGBGB 2 */\
+ "punpckhbw %%mm7, %%mm6 \n\t" /* 0R0R0R0R 2 */\
+ "movq %%mm2, %%mm0 \n\t" /* GBGBGBGB 0 */\
+ "movq %%mm1, %%mm3 \n\t" /* GBGBGBGB 2 */\
+ "punpcklwd %%mm5, %%mm0 \n\t" /* 0RGB0RGB 0 */\
+ "punpckhwd %%mm5, %%mm2 \n\t" /* 0RGB0RGB 1 */\
+ "punpcklwd %%mm6, %%mm1 \n\t" /* 0RGB0RGB 2 */\
+ "punpckhwd %%mm6, %%mm3 \n\t" /* 0RGB0RGB 3 */\
+\
+ "movq %%mm0, %%mm4 \n\t" /* 0RGB0RGB 0 */\
+ "movq %%mm2, %%mm6 \n\t" /* 0RGB0RGB 1 */\
+ "movq %%mm1, %%mm5 \n\t" /* 0RGB0RGB 2 */\
+ "movq %%mm3, %%mm7 \n\t" /* 0RGB0RGB 3 */\
+\
+ "psllq $40, %%mm0 \n\t" /* RGB00000 0 */\
+ "psllq $40, %%mm2 \n\t" /* RGB00000 1 */\
+ "psllq $40, %%mm1 \n\t" /* RGB00000 2 */\
+ "psllq $40, %%mm3 \n\t" /* RGB00000 3 */\
+\
+ "punpckhdq %%mm4, %%mm0 \n\t" /* 0RGBRGB0 0 */\
+ "punpckhdq %%mm6, %%mm2 \n\t" /* 0RGBRGB0 1 */\
+ "punpckhdq %%mm5, %%mm1 \n\t" /* 0RGBRGB0 2 */\
+ "punpckhdq %%mm7, %%mm3 \n\t" /* 0RGBRGB0 3 */\
+\
+ "psrlq $8, %%mm0 \n\t" /* 00RGBRGB 0 */\
+ "movq %%mm2, %%mm6 \n\t" /* 0RGBRGB0 1 */\
+ "psllq $40, %%mm2 \n\t" /* GB000000 1 */\
+ "por %%mm2, %%mm0 \n\t" /* GBRGBRGB 0 */\
+ MOVNTQ(%%mm0, (dst))\
+\
+ "psrlq $24, %%mm6 \n\t" /* 0000RGBR 1 */\
+ "movq %%mm1, %%mm5 \n\t" /* 0RGBRGB0 2 */\
+ "psllq $24, %%mm1 \n\t" /* BRGB0000 2 */\
+ "por %%mm1, %%mm6 \n\t" /* BRGBRGBR 1 */\
+ MOVNTQ(%%mm6, 8(dst))\
+\
+ "psrlq $40, %%mm5 \n\t" /* 000000RG 2 */\
+ "psllq $8, %%mm3 \n\t" /* RGBRGB00 3 */\
+ "por %%mm3, %%mm5 \n\t" /* RGBRGBRG 2 */\
+ MOVNTQ(%%mm5, 16(dst))\
+\
+ "add $24, "#dst" \n\t"\
+\
+ "add $8, "#index" \n\t"\
+ "cmp "#dstw", "#index" \n\t"\
+ " jb 1b \n\t"
+
+#define WRITEBGR24MMX2(dst, dstw, index) \
+ /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\
+ "movq "MANGLE(M24A)", %%mm0 \n\t"\
+ "movq "MANGLE(M24C)", %%mm7 \n\t"\
+ "pshufw $0x50, %%mm2, %%mm1 \n\t" /* B3 B2 B3 B2 B1 B0 B1 B0 */\
+ "pshufw $0x50, %%mm4, %%mm3 \n\t" /* G3 G2 G3 G2 G1 G0 G1 G0 */\
+ "pshufw $0x00, %%mm5, %%mm6 \n\t" /* R1 R0 R1 R0 R1 R0 R1 R0 */\
+\
+ "pand %%mm0, %%mm1 \n\t" /* B2 B1 B0 */\
+ "pand %%mm0, %%mm3 \n\t" /* G2 G1 G0 */\
+ "pand %%mm7, %%mm6 \n\t" /* R1 R0 */\
+\
+ "psllq $8, %%mm3 \n\t" /* G2 G1 G0 */\
+ "por %%mm1, %%mm6 \n\t"\
+ "por %%mm3, %%mm6 \n\t"\
+ MOVNTQ(%%mm6, (dst))\
+\
+ "psrlq $8, %%mm4 \n\t" /* 00 G7 G6 G5 G4 G3 G2 G1 */\
+ "pshufw $0xA5, %%mm2, %%mm1 \n\t" /* B5 B4 B5 B4 B3 B2 B3 B2 */\
+ "pshufw $0x55, %%mm4, %%mm3 \n\t" /* G4 G3 G4 G3 G4 G3 G4 G3 */\
+ "pshufw $0xA5, %%mm5, %%mm6 \n\t" /* R5 R4 R5 R4 R3 R2 R3 R2 */\
+\
+ "pand "MANGLE(M24B)", %%mm1 \n\t" /* B5 B4 B3 */\
+ "pand %%mm7, %%mm3 \n\t" /* G4 G3 */\
+ "pand %%mm0, %%mm6 \n\t" /* R4 R3 R2 */\
+\
+ "por %%mm1, %%mm3 \n\t" /* B5 G4 B4 G3 B3 */\
+ "por %%mm3, %%mm6 \n\t"\
+ MOVNTQ(%%mm6, 8(dst))\
+\
+ "pshufw $0xFF, %%mm2, %%mm1 \n\t" /* B7 B6 B7 B6 B7 B6 B6 B7 */\
+ "pshufw $0xFA, %%mm4, %%mm3 \n\t" /* 00 G7 00 G7 G6 G5 G6 G5 */\
+ "pshufw $0xFA, %%mm5, %%mm6 \n\t" /* R7 R6 R7 R6 R5 R4 R5 R4 */\
+\
+ "pand %%mm7, %%mm1 \n\t" /* B7 B6 */\
+ "pand %%mm0, %%mm3 \n\t" /* G7 G6 G5 */\
+ "pand "MANGLE(M24B)", %%mm6 \n\t" /* R7 R6 R5 */\
+\
+ "por %%mm1, %%mm3 \n\t"\
+ "por %%mm3, %%mm6 \n\t"\
+ MOVNTQ(%%mm6, 16(dst))\
+\
+ "add $24, "#dst" \n\t"\
+\
+ "add $8, "#index" \n\t"\
+ "cmp "#dstw", "#index" \n\t"\
+ " jb 1b \n\t"
+
+#ifdef HAVE_MMX2
+#undef WRITEBGR24
+#define WRITEBGR24(dst, dstw, index) WRITEBGR24MMX2(dst, dstw, index)
+#else
+#undef WRITEBGR24
+#define WRITEBGR24(dst, dstw, index) WRITEBGR24MMX(dst, dstw, index)
+#endif
+
+#define REAL_WRITEYUY2(dst, dstw, index) \
+ "packuswb %%mm3, %%mm3 \n\t"\
+ "packuswb %%mm4, %%mm4 \n\t"\
+ "packuswb %%mm7, %%mm1 \n\t"\
+ "punpcklbw %%mm4, %%mm3 \n\t"\
+ "movq %%mm1, %%mm7 \n\t"\
+ "punpcklbw %%mm3, %%mm1 \n\t"\
+ "punpckhbw %%mm3, %%mm7 \n\t"\
+\
+ MOVNTQ(%%mm1, (dst, index, 2))\
+ MOVNTQ(%%mm7, 8(dst, index, 2))\
+\
+ "add $8, "#index" \n\t"\
+ "cmp "#dstw", "#index" \n\t"\
+ " jb 1b \n\t"
+#define WRITEYUY2(dst, dstw, index) REAL_WRITEYUY2(dst, dstw, index)
+
+
+static inline void RENAME(yuv2yuvX)(SwsContext *c, int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize,
+ int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize,
+ uint8_t *dest, uint8_t *uDest, uint8_t *vDest, long dstW, long chrDstW)
+{
+#ifdef HAVE_MMX
+ if(c->flags & SWS_ACCURATE_RND){
+ if(uDest){
+ YSCALEYUV2YV12X_ACCURATE( 0, CHR_MMX_FILTER_OFFSET, uDest, chrDstW)
+ YSCALEYUV2YV12X_ACCURATE(4096, CHR_MMX_FILTER_OFFSET, vDest, chrDstW)
+ }
+
+ YSCALEYUV2YV12X_ACCURATE(0, LUM_MMX_FILTER_OFFSET, dest, dstW)
+ }else{
+ if(uDest){
+ YSCALEYUV2YV12X( 0, CHR_MMX_FILTER_OFFSET, uDest, chrDstW)
+ YSCALEYUV2YV12X(4096, CHR_MMX_FILTER_OFFSET, vDest, chrDstW)
+ }
+
+ YSCALEYUV2YV12X(0, LUM_MMX_FILTER_OFFSET, dest, dstW)
+ }
+#else
+#ifdef HAVE_ALTIVEC
+yuv2yuvX_altivec_real(lumFilter, lumSrc, lumFilterSize,
+ chrFilter, chrSrc, chrFilterSize,
+ dest, uDest, vDest, dstW, chrDstW);
+#else //HAVE_ALTIVEC
+yuv2yuvXinC(lumFilter, lumSrc, lumFilterSize,
+ chrFilter, chrSrc, chrFilterSize,
+ dest, uDest, vDest, dstW, chrDstW);
+#endif //!HAVE_ALTIVEC
+#endif
+}
+
+static inline void RENAME(yuv2nv12X)(SwsContext *c, int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize,
+ int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize,
+ uint8_t *dest, uint8_t *uDest, int dstW, int chrDstW, int dstFormat)
+{
+yuv2nv12XinC(lumFilter, lumSrc, lumFilterSize,
+ chrFilter, chrSrc, chrFilterSize,
+ dest, uDest, dstW, chrDstW, dstFormat);
+}
+
+static inline void RENAME(yuv2yuv1)(int16_t *lumSrc, int16_t *chrSrc,
+ uint8_t *dest, uint8_t *uDest, uint8_t *vDest, long dstW, long chrDstW)
+{
+#ifdef HAVE_MMX
+ if(uDest != NULL)
+ {
+ asm volatile(
+ YSCALEYUV2YV121
+ :: "r" (chrSrc + chrDstW), "r" (uDest + chrDstW),
+ "g" (-chrDstW)
+ : "%"REG_a
+ );
+
+ asm volatile(
+ YSCALEYUV2YV121
+ :: "r" (chrSrc + 2048 + chrDstW), "r" (vDest + chrDstW),
+ "g" (-chrDstW)
+ : "%"REG_a
+ );
+ }
+
+ asm volatile(
+ YSCALEYUV2YV121
+ :: "r" (lumSrc + dstW), "r" (dest + dstW),
+ "g" (-dstW)
+ : "%"REG_a
+ );
+#else
+ int i;
+ for(i=0; i<dstW; i++)
+ {
+ int val= lumSrc[i]>>7;
+
+ if(val&256){
+ if(val<0) val=0;
+ else val=255;
+ }
+
+ dest[i]= val;
+ }
+
+ if(uDest != NULL)
+ for(i=0; i<chrDstW; i++)
+ {
+ int u=chrSrc[i]>>7;
+ int v=chrSrc[i + 2048]>>7;
+
+ if((u|v)&256){
+ if(u<0) u=0;
+ else if (u>255) u=255;
+ if(v<0) v=0;
+ else if (v>255) v=255;
+ }
+
+ uDest[i]= u;
+ vDest[i]= v;
+ }
+#endif
+}
+
+
+/**
+ * vertical scale YV12 to RGB
+ */
+static inline void RENAME(yuv2packedX)(SwsContext *c, int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize,
+ int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize,
+ uint8_t *dest, long dstW, long dstY)
+{
+#ifdef HAVE_MMX
+ long dummy=0;
+ if(c->flags & SWS_ACCURATE_RND){
+ switch(c->dstFormat){
+ case PIX_FMT_RGB32:
+ YSCALEYUV2PACKEDX_ACCURATE
+ YSCALEYUV2RGBX
+ WRITEBGR32(%4, %5, %%REGa)
+
+ YSCALEYUV2PACKEDX_END
+ return;
+ case PIX_FMT_BGR24:
+ YSCALEYUV2PACKEDX_ACCURATE
+ YSCALEYUV2RGBX
+ "lea (%%"REG_a", %%"REG_a", 2), %%"REG_c"\n\t" //FIXME optimize
+ "add %4, %%"REG_c" \n\t"
+ WRITEBGR24(%%REGc, %5, %%REGa)
+
+
+ :: "r" (&c->redDither),
+ "m" (dummy), "m" (dummy), "m" (dummy),
+ "r" (dest), "m" (dstW)
+ : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S
+ );
+ return;
+ case PIX_FMT_BGR555:
+ YSCALEYUV2PACKEDX_ACCURATE
+ YSCALEYUV2RGBX
+ /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
+#ifdef DITHER1XBPP
+ "paddusb "MANGLE(b5Dither)", %%mm2\n\t"
+ "paddusb "MANGLE(g5Dither)", %%mm4\n\t"
+ "paddusb "MANGLE(r5Dither)", %%mm5\n\t"
+#endif
+
+ WRITEBGR15(%4, %5, %%REGa)
+ YSCALEYUV2PACKEDX_END
+ return;
+ case PIX_FMT_BGR565:
+ YSCALEYUV2PACKEDX_ACCURATE
+ YSCALEYUV2RGBX
+ /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
+#ifdef DITHER1XBPP
+ "paddusb "MANGLE(b5Dither)", %%mm2\n\t"
+ "paddusb "MANGLE(g6Dither)", %%mm4\n\t"
+ "paddusb "MANGLE(r5Dither)", %%mm5\n\t"
+#endif
+
+ WRITEBGR16(%4, %5, %%REGa)
+ YSCALEYUV2PACKEDX_END
+ return;
+ case PIX_FMT_YUYV422:
+ YSCALEYUV2PACKEDX_ACCURATE
+ /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
+
+ "psraw $3, %%mm3 \n\t"
+ "psraw $3, %%mm4 \n\t"
+ "psraw $3, %%mm1 \n\t"
+ "psraw $3, %%mm7 \n\t"
+ WRITEYUY2(%4, %5, %%REGa)
+ YSCALEYUV2PACKEDX_END
+ return;
+ }
+ }else{
+ switch(c->dstFormat)
+ {
+ case PIX_FMT_RGB32:
+ YSCALEYUV2PACKEDX
+ YSCALEYUV2RGBX
+ WRITEBGR32(%4, %5, %%REGa)
+ YSCALEYUV2PACKEDX_END
+ return;
+ case PIX_FMT_BGR24:
+ YSCALEYUV2PACKEDX
+ YSCALEYUV2RGBX
+ "lea (%%"REG_a", %%"REG_a", 2), %%"REG_c"\n\t" //FIXME optimize
+ "add %4, %%"REG_c" \n\t"
+ WRITEBGR24(%%REGc, %5, %%REGa)
+
+ :: "r" (&c->redDither),
+ "m" (dummy), "m" (dummy), "m" (dummy),
+ "r" (dest), "m" (dstW)
+ : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S
+ );
+ return;
+ case PIX_FMT_BGR555:
+ YSCALEYUV2PACKEDX
+ YSCALEYUV2RGBX
+ /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
+#ifdef DITHER1XBPP
+ "paddusb "MANGLE(b5Dither)", %%mm2\n\t"
+ "paddusb "MANGLE(g5Dither)", %%mm4\n\t"
+ "paddusb "MANGLE(r5Dither)", %%mm5\n\t"
+#endif
+
+ WRITEBGR15(%4, %5, %%REGa)
+ YSCALEYUV2PACKEDX_END
+ return;
+ case PIX_FMT_BGR565:
+ YSCALEYUV2PACKEDX
+ YSCALEYUV2RGBX
+ /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
+#ifdef DITHER1XBPP
+ "paddusb "MANGLE(b5Dither)", %%mm2\n\t"
+ "paddusb "MANGLE(g6Dither)", %%mm4\n\t"
+ "paddusb "MANGLE(r5Dither)", %%mm5\n\t"
+#endif
+
+ WRITEBGR16(%4, %5, %%REGa)
+ YSCALEYUV2PACKEDX_END
+ return;
+ case PIX_FMT_YUYV422:
+ YSCALEYUV2PACKEDX
+ /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
+
+ "psraw $3, %%mm3 \n\t"
+ "psraw $3, %%mm4 \n\t"
+ "psraw $3, %%mm1 \n\t"
+ "psraw $3, %%mm7 \n\t"
+ WRITEYUY2(%4, %5, %%REGa)
+ YSCALEYUV2PACKEDX_END
+ return;
+ }
+ }
+#endif
+#ifdef HAVE_ALTIVEC
+ /* The following list of supported dstFormat values should
+ match what's found in the body of altivec_yuv2packedX() */
+ if(c->dstFormat==PIX_FMT_ABGR || c->dstFormat==PIX_FMT_BGRA ||
+ c->dstFormat==PIX_FMT_BGR24 || c->dstFormat==PIX_FMT_RGB24 ||
+ c->dstFormat==PIX_FMT_RGBA || c->dstFormat==PIX_FMT_ARGB)
+ altivec_yuv2packedX (c, lumFilter, lumSrc, lumFilterSize,
+ chrFilter, chrSrc, chrFilterSize,
+ dest, dstW, dstY);
+ else
+#endif
+ yuv2packedXinC(c, lumFilter, lumSrc, lumFilterSize,
+ chrFilter, chrSrc, chrFilterSize,
+ dest, dstW, dstY);
+}
+
+/**
+ * vertical bilinear scale YV12 to RGB
+ */
+static inline void RENAME(yuv2packed2)(SwsContext *c, uint16_t *buf0, uint16_t *buf1, uint16_t *uvbuf0, uint16_t *uvbuf1,
+ uint8_t *dest, int dstW, int yalpha, int uvalpha, int y)
+{
+ int yalpha1=yalpha^4095;
+ int uvalpha1=uvalpha^4095;
+ int i;
+
+#if 0 //isn't used
+ if(flags&SWS_FULL_CHR_H_INT)
+ {
+ switch(dstFormat)
+ {
+#ifdef HAVE_MMX
+ case PIX_FMT_RGB32:
+ asm volatile(
+
+
+FULL_YSCALEYUV2RGB
+ "punpcklbw %%mm1, %%mm3 \n\t" // BGBGBGBG
+ "punpcklbw %%mm7, %%mm0 \n\t" // R0R0R0R0
+
+ "movq %%mm3, %%mm1 \n\t"
+ "punpcklwd %%mm0, %%mm3 \n\t" // BGR0BGR0
+ "punpckhwd %%mm0, %%mm1 \n\t" // BGR0BGR0
+
+ MOVNTQ(%%mm3, (%4, %%REGa, 4))
+ MOVNTQ(%%mm1, 8(%4, %%REGa, 4))
+
+ "add $4, %%"REG_a" \n\t"
+ "cmp %5, %%"REG_a" \n\t"
+ " jb 1b \n\t"
+
+
+ :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" ((long)dstW),
+ "m" (yalpha1), "m" (uvalpha1)
+ : "%"REG_a
+ );
+ break;
+ case PIX_FMT_BGR24:
+ asm volatile(
+
+FULL_YSCALEYUV2RGB
+
+ // lsb ... msb
+ "punpcklbw %%mm1, %%mm3 \n\t" // BGBGBGBG
+ "punpcklbw %%mm7, %%mm0 \n\t" // R0R0R0R0
+
+ "movq %%mm3, %%mm1 \n\t"
+ "punpcklwd %%mm0, %%mm3 \n\t" // BGR0BGR0
+ "punpckhwd %%mm0, %%mm1 \n\t" // BGR0BGR0
+
+ "movq %%mm3, %%mm2 \n\t" // BGR0BGR0
+ "psrlq $8, %%mm3 \n\t" // GR0BGR00
+ "pand "MANGLE(bm00000111)", %%mm2\n\t" // BGR00000
+ "pand "MANGLE(bm11111000)", %%mm3\n\t" // 000BGR00
+ "por %%mm2, %%mm3 \n\t" // BGRBGR00
+ "movq %%mm1, %%mm2 \n\t"
+ "psllq $48, %%mm1 \n\t" // 000000BG
+ "por %%mm1, %%mm3 \n\t" // BGRBGRBG
+
+ "movq %%mm2, %%mm1 \n\t" // BGR0BGR0
+ "psrld $16, %%mm2 \n\t" // R000R000
+ "psrlq $24, %%mm1 \n\t" // 0BGR0000
+ "por %%mm2, %%mm1 \n\t" // RBGRR000
+
+ "mov %4, %%"REG_b" \n\t"
+ "add %%"REG_a", %%"REG_b" \n\t"
+
+#ifdef HAVE_MMX2
+ //FIXME Alignment
+ "movntq %%mm3, (%%"REG_b", %%"REG_a", 2)\n\t"
+ "movntq %%mm1, 8(%%"REG_b", %%"REG_a", 2)\n\t"
+#else
+ "movd %%mm3, (%%"REG_b", %%"REG_a", 2) \n\t"
+ "psrlq $32, %%mm3 \n\t"
+ "movd %%mm3, 4(%%"REG_b", %%"REG_a", 2) \n\t"
+ "movd %%mm1, 8(%%"REG_b", %%"REG_a", 2) \n\t"
+#endif
+ "add $4, %%"REG_a" \n\t"
+ "cmp %5, %%"REG_a" \n\t"
+ " jb 1b \n\t"
+
+ :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "m" (dest), "m" (dstW),
+ "m" (yalpha1), "m" (uvalpha1)
+ : "%"REG_a, "%"REG_b
+ );
+ break;
+ case PIX_FMT_BGR555:
+ asm volatile(
+
+FULL_YSCALEYUV2RGB
+#ifdef DITHER1XBPP
+ "paddusb "MANGLE(g5Dither)", %%mm1\n\t"
+ "paddusb "MANGLE(r5Dither)", %%mm0\n\t"
+ "paddusb "MANGLE(b5Dither)", %%mm3\n\t"
+#endif
+ "punpcklbw %%mm7, %%mm1 \n\t" // 0G0G0G0G
+ "punpcklbw %%mm7, %%mm3 \n\t" // 0B0B0B0B
+ "punpcklbw %%mm7, %%mm0 \n\t" // 0R0R0R0R
+
+ "psrlw $3, %%mm3 \n\t"
+ "psllw $2, %%mm1 \n\t"
+ "psllw $7, %%mm0 \n\t"
+ "pand "MANGLE(g15Mask)", %%mm1 \n\t"
+ "pand "MANGLE(r15Mask)", %%mm0 \n\t"
+
+ "por %%mm3, %%mm1 \n\t"
+ "por %%mm1, %%mm0 \n\t"
+
+ MOVNTQ(%%mm0, (%4, %%REGa, 2))
+
+ "add $4, %%"REG_a" \n\t"
+ "cmp %5, %%"REG_a" \n\t"
+ " jb 1b \n\t"
+
+ :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstW),
+ "m" (yalpha1), "m" (uvalpha1)
+ : "%"REG_a
+ );
+ break;
+ case PIX_FMT_BGR565:
+ asm volatile(
+
+FULL_YSCALEYUV2RGB
+#ifdef DITHER1XBPP
+ "paddusb "MANGLE(g6Dither)", %%mm1\n\t"
+ "paddusb "MANGLE(r5Dither)", %%mm0\n\t"
+ "paddusb "MANGLE(b5Dither)", %%mm3\n\t"
+#endif
+ "punpcklbw %%mm7, %%mm1 \n\t" // 0G0G0G0G
+ "punpcklbw %%mm7, %%mm3 \n\t" // 0B0B0B0B
+ "punpcklbw %%mm7, %%mm0 \n\t" // 0R0R0R0R
+
+ "psrlw $3, %%mm3 \n\t"
+ "psllw $3, %%mm1 \n\t"
+ "psllw $8, %%mm0 \n\t"
+ "pand "MANGLE(g16Mask)", %%mm1 \n\t"
+ "pand "MANGLE(r16Mask)", %%mm0 \n\t"
+
+ "por %%mm3, %%mm1 \n\t"
+ "por %%mm1, %%mm0 \n\t"
+
+ MOVNTQ(%%mm0, (%4, %%REGa, 2))
+
+ "add $4, %%"REG_a" \n\t"
+ "cmp %5, %%"REG_a" \n\t"
+ " jb 1b \n\t"
+
+ :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstW),
+ "m" (yalpha1), "m" (uvalpha1)
+ : "%"REG_a
+ );
+ break;
+#endif
+ case PIX_FMT_BGR32:
+#ifndef HAVE_MMX
+ case PIX_FMT_RGB32:
+#endif
+ if(dstFormat==PIX_FMT_RGB32)
+ {
+ int i;
+#ifdef WORDS_BIGENDIAN
+ dest++;
+#endif
+ for(i=0;i<dstW;i++){
+ // vertical linear interpolation && yuv2rgb in a single step:
+ int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)];
+ int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19);
+ int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19);
+ dest[0]=clip_table[((Y + yuvtab_40cf[U]) >>13)];
+ dest[1]=clip_table[((Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13)];
+ dest[2]=clip_table[((Y + yuvtab_3343[V]) >>13)];
+ dest+= 4;
+ }
+ }
+ else if(dstFormat==PIX_FMT_BGR24)
+ {
+ int i;
+ for(i=0;i<dstW;i++){
+ // vertical linear interpolation && yuv2rgb in a single step:
+ int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)];
+ int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19);
+ int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19);
+ dest[0]=clip_table[((Y + yuvtab_40cf[U]) >>13)];
+ dest[1]=clip_table[((Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13)];
+ dest[2]=clip_table[((Y + yuvtab_3343[V]) >>13)];
+ dest+= 3;
+ }
+ }
+ else if(dstFormat==PIX_FMT_BGR565)
+ {
+ int i;
+ for(i=0;i<dstW;i++){
+ // vertical linear interpolation && yuv2rgb in a single step:
+ int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)];
+ int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19);
+ int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19);
+
+ ((uint16_t*)dest)[i] =
+ clip_table16b[(Y + yuvtab_40cf[U]) >>13] |
+ clip_table16g[(Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13] |
+ clip_table16r[(Y + yuvtab_3343[V]) >>13];
+ }
+ }
+ else if(dstFormat==PIX_FMT_BGR555)
+ {
+ int i;
+ for(i=0;i<dstW;i++){
+ // vertical linear interpolation && yuv2rgb in a single step:
+ int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)];
+ int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19);
+ int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19);
+
+ ((uint16_t*)dest)[i] =
+ clip_table15b[(Y + yuvtab_40cf[U]) >>13] |
+ clip_table15g[(Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13] |
+ clip_table15r[(Y + yuvtab_3343[V]) >>13];
+ }
+ }
+ }//FULL_UV_IPOL
+ else
+ {
+#endif // if 0
+#ifdef HAVE_MMX
+ switch(c->dstFormat)
+ {
+//Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :(
+ case PIX_FMT_RGB32:
+ asm volatile(
+ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
+ "mov %4, %%"REG_b" \n\t"
+ "push %%"REG_BP" \n\t"
+ YSCALEYUV2RGB(%%REGBP, %5)
+ WRITEBGR32(%%REGb, 8280(%5), %%REGBP)
+ "pop %%"REG_BP" \n\t"
+ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
+
+ :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest),
+ "a" (&c->redDither)
+ );
+ return;
+ case PIX_FMT_BGR24:
+ asm volatile(
+ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
+ "mov %4, %%"REG_b" \n\t"
+ "push %%"REG_BP" \n\t"
+ YSCALEYUV2RGB(%%REGBP, %5)
+ WRITEBGR24(%%REGb, 8280(%5), %%REGBP)
+ "pop %%"REG_BP" \n\t"
+ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
+ :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest),
+ "a" (&c->redDither)
+ );
+ return;
+ case PIX_FMT_BGR555:
+ asm volatile(
+ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
+ "mov %4, %%"REG_b" \n\t"
+ "push %%"REG_BP" \n\t"
+ YSCALEYUV2RGB(%%REGBP, %5)
+ /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
+#ifdef DITHER1XBPP
+ "paddusb "MANGLE(b5Dither)", %%mm2\n\t"
+ "paddusb "MANGLE(g5Dither)", %%mm4\n\t"
+ "paddusb "MANGLE(r5Dither)", %%mm5\n\t"
+#endif
+
+ WRITEBGR15(%%REGb, 8280(%5), %%REGBP)
+ "pop %%"REG_BP" \n\t"
+ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
+
+ :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest),
+ "a" (&c->redDither)
+ );
+ return;
+ case PIX_FMT_BGR565:
+ asm volatile(
+ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
+ "mov %4, %%"REG_b" \n\t"
+ "push %%"REG_BP" \n\t"
+ YSCALEYUV2RGB(%%REGBP, %5)
+ /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
+#ifdef DITHER1XBPP
+ "paddusb "MANGLE(b5Dither)", %%mm2\n\t"
+ "paddusb "MANGLE(g6Dither)", %%mm4\n\t"
+ "paddusb "MANGLE(r5Dither)", %%mm5\n\t"
+#endif
+
+ WRITEBGR16(%%REGb, 8280(%5), %%REGBP)
+ "pop %%"REG_BP" \n\t"
+ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
+ :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest),
+ "a" (&c->redDither)
+ );
+ return;
+ case PIX_FMT_YUYV422:
+ asm volatile(
+ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
+ "mov %4, %%"REG_b" \n\t"
+ "push %%"REG_BP" \n\t"
+ YSCALEYUV2PACKED(%%REGBP, %5)
+ WRITEYUY2(%%REGb, 8280(%5), %%REGBP)
+ "pop %%"REG_BP" \n\t"
+ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
+ :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest),
+ "a" (&c->redDither)
+ );
+ return;
+ default: break;
+ }
+#endif //HAVE_MMX
+YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB2_C, YSCALE_YUV_2_PACKED2_C)
+}
+
+/**
+ * YV12 to RGB without scaling or interpolating
+ */
+static inline void RENAME(yuv2packed1)(SwsContext *c, uint16_t *buf0, uint16_t *uvbuf0, uint16_t *uvbuf1,
+ uint8_t *dest, int dstW, int uvalpha, int dstFormat, int flags, int y)
+{
+ const int yalpha1=0;
+ int i;
+
+ uint16_t *buf1= buf0; //FIXME needed for the rgb1/bgr1
+ const int yalpha= 4096; //FIXME ...
+
+ if(flags&SWS_FULL_CHR_H_INT)
+ {
+ RENAME(yuv2packed2)(c, buf0, buf0, uvbuf0, uvbuf1, dest, dstW, 0, uvalpha, y);
+ return;
+ }
+
+#ifdef HAVE_MMX
+ if( uvalpha < 2048 ) // note this is not correct (shifts chrominance by 0.5 pixels) but its a bit faster
+ {
+ switch(dstFormat)
+ {
+ case PIX_FMT_RGB32:
+ asm volatile(
+ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
+ "mov %4, %%"REG_b" \n\t"
+ "push %%"REG_BP" \n\t"
+ YSCALEYUV2RGB1(%%REGBP, %5)
+ WRITEBGR32(%%REGb, 8280(%5), %%REGBP)
+ "pop %%"REG_BP" \n\t"
+ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
+
+ :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest),
+ "a" (&c->redDither)
+ );
+ return;
+ case PIX_FMT_BGR24:
+ asm volatile(
+ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
+ "mov %4, %%"REG_b" \n\t"
+ "push %%"REG_BP" \n\t"
+ YSCALEYUV2RGB1(%%REGBP, %5)
+ WRITEBGR24(%%REGb, 8280(%5), %%REGBP)
+ "pop %%"REG_BP" \n\t"
+ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
+
+ :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest),
+ "a" (&c->redDither)
+ );
+ return;
+ case PIX_FMT_BGR555:
+ asm volatile(
+ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
+ "mov %4, %%"REG_b" \n\t"
+ "push %%"REG_BP" \n\t"
+ YSCALEYUV2RGB1(%%REGBP, %5)
+ /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
+#ifdef DITHER1XBPP
+ "paddusb "MANGLE(b5Dither)", %%mm2\n\t"
+ "paddusb "MANGLE(g5Dither)", %%mm4\n\t"
+ "paddusb "MANGLE(r5Dither)", %%mm5\n\t"
+#endif
+ WRITEBGR15(%%REGb, 8280(%5), %%REGBP)
+ "pop %%"REG_BP" \n\t"
+ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
+
+ :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest),
+ "a" (&c->redDither)
+ );
+ return;
+ case PIX_FMT_BGR565:
+ asm volatile(
+ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
+ "mov %4, %%"REG_b" \n\t"
+ "push %%"REG_BP" \n\t"
+ YSCALEYUV2RGB1(%%REGBP, %5)
+ /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
+#ifdef DITHER1XBPP
+ "paddusb "MANGLE(b5Dither)", %%mm2\n\t"
+ "paddusb "MANGLE(g6Dither)", %%mm4\n\t"
+ "paddusb "MANGLE(r5Dither)", %%mm5\n\t"
+#endif
+
+ WRITEBGR16(%%REGb, 8280(%5), %%REGBP)
+ "pop %%"REG_BP" \n\t"
+ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
+
+ :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest),
+ "a" (&c->redDither)
+ );
+ return;
+ case PIX_FMT_YUYV422:
+ asm volatile(
+ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
+ "mov %4, %%"REG_b" \n\t"
+ "push %%"REG_BP" \n\t"
+ YSCALEYUV2PACKED1(%%REGBP, %5)
+ WRITEYUY2(%%REGb, 8280(%5), %%REGBP)
+ "pop %%"REG_BP" \n\t"
+ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
+
+ :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest),
+ "a" (&c->redDither)
+ );
+ return;
+ }
+ }
+ else
+ {
+ switch(dstFormat)
+ {
+ case PIX_FMT_RGB32:
+ asm volatile(
+ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
+ "mov %4, %%"REG_b" \n\t"
+ "push %%"REG_BP" \n\t"
+ YSCALEYUV2RGB1b(%%REGBP, %5)
+ WRITEBGR32(%%REGb, 8280(%5), %%REGBP)
+ "pop %%"REG_BP" \n\t"
+ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
+
+ :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest),
+ "a" (&c->redDither)
+ );
+ return;
+ case PIX_FMT_BGR24:
+ asm volatile(
+ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
+ "mov %4, %%"REG_b" \n\t"
+ "push %%"REG_BP" \n\t"
+ YSCALEYUV2RGB1b(%%REGBP, %5)
+ WRITEBGR24(%%REGb, 8280(%5), %%REGBP)
+ "pop %%"REG_BP" \n\t"
+ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
+
+ :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest),
+ "a" (&c->redDither)
+ );
+ return;
+ case PIX_FMT_BGR555:
+ asm volatile(
+ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
+ "mov %4, %%"REG_b" \n\t"
+ "push %%"REG_BP" \n\t"
+ YSCALEYUV2RGB1b(%%REGBP, %5)
+ /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
+#ifdef DITHER1XBPP
+ "paddusb "MANGLE(b5Dither)", %%mm2\n\t"
+ "paddusb "MANGLE(g5Dither)", %%mm4\n\t"
+ "paddusb "MANGLE(r5Dither)", %%mm5\n\t"
+#endif
+ WRITEBGR15(%%REGb, 8280(%5), %%REGBP)
+ "pop %%"REG_BP" \n\t"
+ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
+
+ :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest),
+ "a" (&c->redDither)
+ );
+ return;
+ case PIX_FMT_BGR565:
+ asm volatile(
+ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
+ "mov %4, %%"REG_b" \n\t"
+ "push %%"REG_BP" \n\t"
+ YSCALEYUV2RGB1b(%%REGBP, %5)
+ /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
+#ifdef DITHER1XBPP
+ "paddusb "MANGLE(b5Dither)", %%mm2\n\t"
+ "paddusb "MANGLE(g6Dither)", %%mm4\n\t"
+ "paddusb "MANGLE(r5Dither)", %%mm5\n\t"
+#endif
+
+ WRITEBGR16(%%REGb, 8280(%5), %%REGBP)
+ "pop %%"REG_BP" \n\t"
+ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
+
+ :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest),
+ "a" (&c->redDither)
+ );
+ return;
+ case PIX_FMT_YUYV422:
+ asm volatile(
+ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
+ "mov %4, %%"REG_b" \n\t"
+ "push %%"REG_BP" \n\t"
+ YSCALEYUV2PACKED1b(%%REGBP, %5)
+ WRITEYUY2(%%REGb, 8280(%5), %%REGBP)
+ "pop %%"REG_BP" \n\t"
+ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t"
+
+ :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest),
+ "a" (&c->redDither)
+ );
+ return;
+ }
+ }
+#endif
+ if( uvalpha < 2048 )
+ {
+ YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB1_C, YSCALE_YUV_2_PACKED1_C)
+ }else{
+ YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB1B_C, YSCALE_YUV_2_PACKED1B_C)
+ }
+}
+
+//FIXME yuy2* can read upto 7 samples to much
+
+static inline void RENAME(yuy2ToY)(uint8_t *dst, uint8_t *src, long width)
+{
+#ifdef HAVE_MMX
+ asm volatile(
+ "movq "MANGLE(bm01010101)", %%mm2\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"
+ "pand %%mm2, %%mm0 \n\t"
+ "pand %%mm2, %%mm1 \n\t"
+ "packuswb %%mm1, %%mm0 \n\t"
+ "movq %%mm0, (%2, %%"REG_a") \n\t"
+ "add $8, %%"REG_a" \n\t"
+ " js 1b \n\t"
+ : : "g" (-width), "r" (src+width*2), "r" (dst+width)
+ : "%"REG_a
+ );
+#else
+ int i;
+ for(i=0; i<width; i++)
+ dst[i]= src[2*i];
+#endif
+}
+
+static inline void RENAME(yuy2ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, long width)
+{
+#ifdef HAVE_MMX
+ asm volatile(
+ "movq "MANGLE(bm01010101)", %%mm4\n\t"
+ "mov %0, %%"REG_a" \n\t"
+ "1: \n\t"
+ "movq (%1, %%"REG_a",4), %%mm0 \n\t"
+ "movq 8(%1, %%"REG_a",4), %%mm1 \n\t"
+ "psrlw $8, %%mm0 \n\t"
+ "psrlw $8, %%mm1 \n\t"
+ "packuswb %%mm1, %%mm0 \n\t"
+ "movq %%mm0, %%mm1 \n\t"
+ "psrlw $8, %%mm0 \n\t"
+ "pand %%mm4, %%mm1 \n\t"
+ "packuswb %%mm0, %%mm0 \n\t"
+ "packuswb %%mm1, %%mm1 \n\t"
+ "movd %%mm0, (%3, %%"REG_a") \n\t"
+ "movd %%mm1, (%2, %%"REG_a") \n\t"
+ "add $4, %%"REG_a" \n\t"
+ " js 1b \n\t"
+ : : "g" (-width), "r" (src1+width*4), "r" (dstU+width), "r" (dstV+width)
+ : "%"REG_a
+ );
+#else
+ int i;
+ for(i=0; i<width; i++)
+ {
+ dstU[i]= src1[4*i + 1];
+ dstV[i]= src1[4*i + 3];
+ }
+#endif
+ assert(src1 == src2);
+}
+
+//this is allmost identical to the previous, end exists only cuz yuy2ToY/UV)(dst, src+1, ...) would have 100% unaligned accesses
+static inline void RENAME(uyvyToY)(uint8_t *dst, uint8_t *src, long width)
+{
+#ifdef HAVE_MMX
+ asm volatile(
+ "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"
+ "psrlw $8, %%mm0 \n\t"
+ "psrlw $8, %%mm1 \n\t"
+ "packuswb %%mm1, %%mm0 \n\t"
+ "movq %%mm0, (%2, %%"REG_a") \n\t"
+ "add $8, %%"REG_a" \n\t"
+ " js 1b \n\t"
+ : : "g" (-width), "r" (src+width*2), "r" (dst+width)
+ : "%"REG_a
+ );
+#else
+ int i;
+ for(i=0; i<width; i++)
+ dst[i]= src[2*i+1];
+#endif
+}
+
+static inline void RENAME(uyvyToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, long width)
+{
+#ifdef HAVE_MMX
+ asm volatile(
+ "movq "MANGLE(bm01010101)", %%mm4\n\t"
+ "mov %0, %%"REG_a" \n\t"
+ "1: \n\t"
+ "movq (%1, %%"REG_a",4), %%mm0 \n\t"
+ "movq 8(%1, %%"REG_a",4), %%mm1 \n\t"
+ "pand %%mm4, %%mm0 \n\t"
+ "pand %%mm4, %%mm1 \n\t"
+ "packuswb %%mm1, %%mm0 \n\t"
+ "movq %%mm0, %%mm1 \n\t"
+ "psrlw $8, %%mm0 \n\t"
+ "pand %%mm4, %%mm1 \n\t"
+ "packuswb %%mm0, %%mm0 \n\t"
+ "packuswb %%mm1, %%mm1 \n\t"
+ "movd %%mm0, (%3, %%"REG_a") \n\t"
+ "movd %%mm1, (%2, %%"REG_a") \n\t"
+ "add $4, %%"REG_a" \n\t"
+ " js 1b \n\t"
+ : : "g" (-width), "r" (src1+width*4), "r" (dstU+width), "r" (dstV+width)
+ : "%"REG_a
+ );
+#else
+ int i;
+ for(i=0; i<width; i++)
+ {
+ dstU[i]= src1[4*i + 0];
+ dstV[i]= src1[4*i + 2];
+ }
+#endif
+ assert(src1 == src2);
+}
+
+static inline void RENAME(bgr32ToY)(uint8_t *dst, uint8_t *src, int width)
+{
+ int i;
+ for(i=0; i<width; i++)
+ {
+ int b= ((uint32_t*)src)[i]&0xFF;
+ int g= (((uint32_t*)src)[i]>>8)&0xFF;
+ int r= (((uint32_t*)src)[i]>>16)&0xFF;
+
+ dst[i]= ((RY*r + GY*g + BY*b + (33<<(RGB2YUV_SHIFT-1)) )>>RGB2YUV_SHIFT);
+ }
+}
+
+static inline void RENAME(bgr32ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, int width)
+{
+ int i;
+ assert(src1 == src2);
+ for(i=0; i<width; i++)
+ {
+ const int a= ((uint32_t*)src1)[2*i+0];
+ const int e= ((uint32_t*)src1)[2*i+1];
+ const int l= (a&0xFF00FF) + (e&0xFF00FF);
+ const int h= (a&0x00FF00) + (e&0x00FF00);
+ const int b= l&0x3FF;
+ const int g= h>>8;
+ const int r= l>>16;
+
+ dstU[i]= ((RU*r + GU*g + BU*b)>>(RGB2YUV_SHIFT+1)) + 128;
+ dstV[i]= ((RV*r + GV*g + BV*b)>>(RGB2YUV_SHIFT+1)) + 128;
+ }
+}
+
+static inline void RENAME(bgr24ToY)(uint8_t *dst, uint8_t *src, long width)
+{
+#ifdef HAVE_MMX
+ asm volatile(
+ "mov %2, %%"REG_a" \n\t"
+ "movq "MANGLE(bgr2YCoeff)", %%mm6 \n\t"
+ "movq "MANGLE(w1111)", %%mm5 \n\t"
+ "pxor %%mm7, %%mm7 \n\t"
+ "lea (%%"REG_a", %%"REG_a", 2), %%"REG_d"\n\t"
+ ASMALIGN(4)
+ "1: \n\t"
+ PREFETCH" 64(%0, %%"REG_d") \n\t"
+ "movd (%0, %%"REG_d"), %%mm0 \n\t"
+ "movd 3(%0, %%"REG_d"), %%mm1 \n\t"
+ "punpcklbw %%mm7, %%mm0 \n\t"
+ "punpcklbw %%mm7, %%mm1 \n\t"
+ "movd 6(%0, %%"REG_d"), %%mm2 \n\t"
+ "movd 9(%0, %%"REG_d"), %%mm3 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t"
+ "punpcklbw %%mm7, %%mm3 \n\t"
+ "pmaddwd %%mm6, %%mm0 \n\t"
+ "pmaddwd %%mm6, %%mm1 \n\t"
+ "pmaddwd %%mm6, %%mm2 \n\t"
+ "pmaddwd %%mm6, %%mm3 \n\t"
+#ifndef FAST_BGR2YV12
+ "psrad $8, %%mm0 \n\t"
+ "psrad $8, %%mm1 \n\t"
+ "psrad $8, %%mm2 \n\t"
+ "psrad $8, %%mm3 \n\t"
+#endif
+ "packssdw %%mm1, %%mm0 \n\t"
+ "packssdw %%mm3, %%mm2 \n\t"
+ "pmaddwd %%mm5, %%mm0 \n\t"
+ "pmaddwd %%mm5, %%mm2 \n\t"
+ "packssdw %%mm2, %%mm0 \n\t"
+ "psraw $7, %%mm0 \n\t"
+
+ "movd 12(%0, %%"REG_d"), %%mm4 \n\t"
+ "movd 15(%0, %%"REG_d"), %%mm1 \n\t"
+ "punpcklbw %%mm7, %%mm4 \n\t"
+ "punpcklbw %%mm7, %%mm1 \n\t"
+ "movd 18(%0, %%"REG_d"), %%mm2 \n\t"
+ "movd 21(%0, %%"REG_d"), %%mm3 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t"
+ "punpcklbw %%mm7, %%mm3 \n\t"
+ "pmaddwd %%mm6, %%mm4 \n\t"
+ "pmaddwd %%mm6, %%mm1 \n\t"
+ "pmaddwd %%mm6, %%mm2 \n\t"
+ "pmaddwd %%mm6, %%mm3 \n\t"
+#ifndef FAST_BGR2YV12
+ "psrad $8, %%mm4 \n\t"
+ "psrad $8, %%mm1 \n\t"
+ "psrad $8, %%mm2 \n\t"
+ "psrad $8, %%mm3 \n\t"
+#endif
+ "packssdw %%mm1, %%mm4 \n\t"
+ "packssdw %%mm3, %%mm2 \n\t"
+ "pmaddwd %%mm5, %%mm4 \n\t"
+ "pmaddwd %%mm5, %%mm2 \n\t"
+ "add $24, %%"REG_d" \n\t"
+ "packssdw %%mm2, %%mm4 \n\t"
+ "psraw $7, %%mm4 \n\t"
+
+ "packuswb %%mm4, %%mm0 \n\t"
+ "paddusb "MANGLE(bgr2YOffset)", %%mm0 \n\t"
+
+ "movq %%mm0, (%1, %%"REG_a") \n\t"
+ "add $8, %%"REG_a" \n\t"
+ " js 1b \n\t"
+ : : "r" (src+width*3), "r" (dst+width), "g" (-width)
+ : "%"REG_a, "%"REG_d
+ );
+#else
+ int i;
+ for(i=0; i<width; i++)
+ {
+ int b= src[i*3+0];
+ int g= src[i*3+1];
+ int r= src[i*3+2];
+
+ dst[i]= ((RY*r + GY*g + BY*b + (33<<(RGB2YUV_SHIFT-1)) )>>RGB2YUV_SHIFT);
+ }
+#endif
+}
+
+static inline void RENAME(bgr24ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, long width)
+{
+#ifdef HAVE_MMX
+ asm volatile(
+ "mov %3, %%"REG_a" \n\t"
+ "movq "MANGLE(w1111)", %%mm5 \n\t"
+ "movq "MANGLE(bgr2UCoeff)", %%mm6 \n\t"
+ "pxor %%mm7, %%mm7 \n\t"
+ "lea (%%"REG_a", %%"REG_a", 2), %%"REG_d" \n\t"
+ "add %%"REG_d", %%"REG_d" \n\t"
+ ASMALIGN(4)
+ "1: \n\t"
+ PREFETCH" 64(%0, %%"REG_d") \n\t"
+#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+ "movq (%0, %%"REG_d"), %%mm0 \n\t"
+ "movq 6(%0, %%"REG_d"), %%mm2 \n\t"
+ "movq %%mm0, %%mm1 \n\t"
+ "movq %%mm2, %%mm3 \n\t"
+ "psrlq $24, %%mm0 \n\t"
+ "psrlq $24, %%mm2 \n\t"
+ PAVGB(%%mm1, %%mm0)
+ PAVGB(%%mm3, %%mm2)
+ "punpcklbw %%mm7, %%mm0 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t"
+#else
+ "movd (%0, %%"REG_d"), %%mm0 \n\t"
+ "movd 3(%0, %%"REG_d"), %%mm2 \n\t"
+ "punpcklbw %%mm7, %%mm0 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t"
+ "paddw %%mm2, %%mm0 \n\t"
+ "movd 6(%0, %%"REG_d"), %%mm4 \n\t"
+ "movd 9(%0, %%"REG_d"), %%mm2 \n\t"
+ "punpcklbw %%mm7, %%mm4 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t"
+ "paddw %%mm4, %%mm2 \n\t"
+ "psrlw $1, %%mm0 \n\t"
+ "psrlw $1, %%mm2 \n\t"
+#endif
+ "movq "MANGLE(bgr2VCoeff)", %%mm1 \n\t"
+ "movq "MANGLE(bgr2VCoeff)", %%mm3 \n\t"
+
+ "pmaddwd %%mm0, %%mm1 \n\t"
+ "pmaddwd %%mm2, %%mm3 \n\t"
+ "pmaddwd %%mm6, %%mm0 \n\t"
+ "pmaddwd %%mm6, %%mm2 \n\t"
+#ifndef FAST_BGR2YV12
+ "psrad $8, %%mm0 \n\t"
+ "psrad $8, %%mm1 \n\t"
+ "psrad $8, %%mm2 \n\t"
+ "psrad $8, %%mm3 \n\t"
+#endif
+ "packssdw %%mm2, %%mm0 \n\t"
+ "packssdw %%mm3, %%mm1 \n\t"
+ "pmaddwd %%mm5, %%mm0 \n\t"
+ "pmaddwd %%mm5, %%mm1 \n\t"
+ "packssdw %%mm1, %%mm0 \n\t" // V1 V0 U1 U0
+ "psraw $7, %%mm0 \n\t"
+
+#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
+ "movq 12(%0, %%"REG_d"), %%mm4 \n\t"
+ "movq 18(%0, %%"REG_d"), %%mm2 \n\t"
+ "movq %%mm4, %%mm1 \n\t"
+ "movq %%mm2, %%mm3 \n\t"
+ "psrlq $24, %%mm4 \n\t"
+ "psrlq $24, %%mm2 \n\t"
+ PAVGB(%%mm1, %%mm4)
+ PAVGB(%%mm3, %%mm2)
+ "punpcklbw %%mm7, %%mm4 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t"
+#else
+ "movd 12(%0, %%"REG_d"), %%mm4 \n\t"
+ "movd 15(%0, %%"REG_d"), %%mm2 \n\t"
+ "punpcklbw %%mm7, %%mm4 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t"
+ "paddw %%mm2, %%mm4 \n\t"
+ "movd 18(%0, %%"REG_d"), %%mm5 \n\t"
+ "movd 21(%0, %%"REG_d"), %%mm2 \n\t"
+ "punpcklbw %%mm7, %%mm5 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t"
+ "paddw %%mm5, %%mm2 \n\t"
+ "movq "MANGLE(w1111)", %%mm5 \n\t"
+ "psrlw $2, %%mm4 \n\t"
+ "psrlw $2, %%mm2 \n\t"
+#endif
+ "movq "MANGLE(bgr2VCoeff)", %%mm1 \n\t"
+ "movq "MANGLE(bgr2VCoeff)", %%mm3 \n\t"
+
+ "pmaddwd %%mm4, %%mm1 \n\t"
+ "pmaddwd %%mm2, %%mm3 \n\t"
+ "pmaddwd %%mm6, %%mm4 \n\t"
+ "pmaddwd %%mm6, %%mm2 \n\t"
+#ifndef FAST_BGR2YV12
+ "psrad $8, %%mm4 \n\t"
+ "psrad $8, %%mm1 \n\t"
+ "psrad $8, %%mm2 \n\t"
+ "psrad $8, %%mm3 \n\t"
+#endif
+ "packssdw %%mm2, %%mm4 \n\t"
+ "packssdw %%mm3, %%mm1 \n\t"
+ "pmaddwd %%mm5, %%mm4 \n\t"
+ "pmaddwd %%mm5, %%mm1 \n\t"
+ "add $24, %%"REG_d" \n\t"
+ "packssdw %%mm1, %%mm4 \n\t" // V3 V2 U3 U2
+ "psraw $7, %%mm4 \n\t"
+
+ "movq %%mm0, %%mm1 \n\t"
+ "punpckldq %%mm4, %%mm0 \n\t"
+ "punpckhdq %%mm4, %%mm1 \n\t"
+ "packsswb %%mm1, %%mm0 \n\t"
+ "paddb "MANGLE(bgr2UVOffset)", %%mm0 \n\t"
+
+ "movd %%mm0, (%1, %%"REG_a") \n\t"
+ "punpckhdq %%mm0, %%mm0 \n\t"
+ "movd %%mm0, (%2, %%"REG_a") \n\t"
+ "add $4, %%"REG_a" \n\t"
+ " js 1b \n\t"
+ : : "r" (src1+width*6), "r" (dstU+width), "r" (dstV+width), "g" (-width)
+ : "%"REG_a, "%"REG_d
+ );
+#else
+ int i;
+ for(i=0; i<width; i++)
+ {
+ int b= src1[6*i + 0] + src1[6*i + 3];
+ int g= src1[6*i + 1] + src1[6*i + 4];
+ int r= src1[6*i + 2] + src1[6*i + 5];
+
+ dstU[i]= ((RU*r + GU*g + BU*b)>>(RGB2YUV_SHIFT+1)) + 128;
+ dstV[i]= ((RV*r + GV*g + BV*b)>>(RGB2YUV_SHIFT+1)) + 128;
+ }
+#endif
+ assert(src1 == src2);
+}
+
+static inline void RENAME(bgr16ToY)(uint8_t *dst, uint8_t *src, int width)
+{
+ int i;
+ for(i=0; i<width; i++)
+ {
+ int d= ((uint16_t*)src)[i];
+ int b= d&0x1F;
+ int g= (d>>5)&0x3F;
+ int r= (d>>11)&0x1F;
+
+ dst[i]= ((2*RY*r + GY*g + 2*BY*b)>>(RGB2YUV_SHIFT-2)) + 16;
+ }
+}
+
+static inline void RENAME(bgr16ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, int width)
+{
+ int i;
+ assert(src1==src2);
+ for(i=0; i<width; i++)
+ {
+ int d0= ((uint32_t*)src1)[i];
+
+ int dl= (d0&0x07E0F81F);
+ int dh= ((d0>>5)&0x07C0F83F);
+
+ int dh2= (dh>>11) + (dh<<21);
+ int d= dh2 + dl;
+
+ int b= d&0x7F;
+ int r= (d>>11)&0x7F;
+ int g= d>>21;
+ dstU[i]= ((2*RU*r + GU*g + 2*BU*b)>>(RGB2YUV_SHIFT+1-2)) + 128;
+ dstV[i]= ((2*RV*r + GV*g + 2*BV*b)>>(RGB2YUV_SHIFT+1-2)) + 128;
+ }
+}
+
+static inline void RENAME(bgr15ToY)(uint8_t *dst, uint8_t *src, int width)
+{
+ int i;
+ for(i=0; i<width; i++)
+ {
+ int d= ((uint16_t*)src)[i];
+ int b= d&0x1F;
+ int g= (d>>5)&0x1F;
+ int r= (d>>10)&0x1F;
+
+ dst[i]= ((RY*r + GY*g + BY*b)>>(RGB2YUV_SHIFT-3)) + 16;
+ }
+}
+
+static inline void RENAME(bgr15ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, int width)
+{
+ int i;
+ assert(src1==src2);
+ for(i=0; i<width; i++)
+ {
+ int d0= ((uint32_t*)src1)[i];
+
+ int dl= (d0&0x03E07C1F);
+ int dh= ((d0>>5)&0x03E0F81F);
+
+ int dh2= (dh>>11) + (dh<<21);
+ int d= dh2 + dl;
+
+ int b= d&0x7F;
+ int r= (d>>10)&0x7F;
+ int g= d>>21;
+ dstU[i]= ((RU*r + GU*g + BU*b)>>(RGB2YUV_SHIFT+1-3)) + 128;
+ dstV[i]= ((RV*r + GV*g + BV*b)>>(RGB2YUV_SHIFT+1-3)) + 128;
+ }
+}
+
+
+static inline void RENAME(rgb32ToY)(uint8_t *dst, uint8_t *src, int width)
+{
+ int i;
+ for(i=0; i<width; i++)
+ {
+ int r= ((uint32_t*)src)[i]&0xFF;
+ int g= (((uint32_t*)src)[i]>>8)&0xFF;
+ int b= (((uint32_t*)src)[i]>>16)&0xFF;
+
+ dst[i]= ((RY*r + GY*g + BY*b + (33<<(RGB2YUV_SHIFT-1)) )>>RGB2YUV_SHIFT);
+ }
+}
+
+static inline void RENAME(rgb32ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, int width)
+{
+ int i;
+ assert(src1==src2);
+ for(i=0; i<width; i++)
+ {
+ const int a= ((uint32_t*)src1)[2*i+0];
+ const int e= ((uint32_t*)src1)[2*i+1];
+ const int l= (a&0xFF00FF) + (e&0xFF00FF);
+ const int h= (a&0x00FF00) + (e&0x00FF00);
+ const int r= l&0x3FF;
+ const int g= h>>8;
+ const int b= l>>16;
+
+ dstU[i]= ((RU*r + GU*g + BU*b)>>(RGB2YUV_SHIFT+1)) + 128;
+ dstV[i]= ((RV*r + GV*g + BV*b)>>(RGB2YUV_SHIFT+1)) + 128;
+ }
+}
+
+static inline void RENAME(rgb24ToY)(uint8_t *dst, uint8_t *src, int width)
+{
+ int i;
+ for(i=0; i<width; i++)
+ {
+ int r= src[i*3+0];
+ int g= src[i*3+1];
+ int b= src[i*3+2];
+
+ dst[i]= ((RY*r + GY*g + BY*b + (33<<(RGB2YUV_SHIFT-1)) )>>RGB2YUV_SHIFT);
+ }
+}
+
+static inline void RENAME(rgb24ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, int width)
+{
+ int i;
+ assert(src1==src2);
+ for(i=0; i<width; i++)
+ {
+ int r= src1[6*i + 0] + src1[6*i + 3];
+ int g= src1[6*i + 1] + src1[6*i + 4];
+ int b= src1[6*i + 2] + src1[6*i + 5];
+
+ dstU[i]= ((RU*r + GU*g + BU*b)>>(RGB2YUV_SHIFT+1)) + 128;
+ dstV[i]= ((RV*r + GV*g + BV*b)>>(RGB2YUV_SHIFT+1)) + 128;
+ }
+}
+
+static inline void RENAME(rgb16ToY)(uint8_t *dst, uint8_t *src, int width)
+{
+ int i;
+ for(i=0; i<width; i++)
+ {
+ int d= ((uint16_t*)src)[i];
+ int r= d&0x1F;
+ int g= (d>>5)&0x3F;
+ int b= (d>>11)&0x1F;
+
+ dst[i]= ((2*RY*r + GY*g + 2*BY*b)>>(RGB2YUV_SHIFT-2)) + 16;
+ }
+}
+
+static inline void RENAME(rgb16ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, int width)
+{
+ int i;
+ assert(src1 == src2);
+ for(i=0; i<width; i++)
+ {
+ int d0= ((uint32_t*)src1)[i];
+
+ int dl= (d0&0x07E0F81F);
+ int dh= ((d0>>5)&0x07C0F83F);
+
+ int dh2= (dh>>11) + (dh<<21);
+ int d= dh2 + dl;
+
+ int r= d&0x7F;
+ int b= (d>>11)&0x7F;
+ int g= d>>21;
+ dstU[i]= ((2*RU*r + GU*g + 2*BU*b)>>(RGB2YUV_SHIFT+1-2)) + 128;
+ dstV[i]= ((2*RV*r + GV*g + 2*BV*b)>>(RGB2YUV_SHIFT+1-2)) + 128;
+ }
+}
+
+static inline void RENAME(rgb15ToY)(uint8_t *dst, uint8_t *src, int width)
+{
+ int i;
+ for(i=0; i<width; i++)
+ {
+ int d= ((uint16_t*)src)[i];
+ int r= d&0x1F;
+ int g= (d>>5)&0x1F;
+ int b= (d>>10)&0x1F;
+
+ dst[i]= ((RY*r + GY*g + BY*b)>>(RGB2YUV_SHIFT-3)) + 16;
+ }
+}
+
+static inline void RENAME(rgb15ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, int width)
+{
+ int i;
+ assert(src1 == src2);
+ for(i=0; i<width; i++)
+ {
+ int d0= ((uint32_t*)src1)[i];
+
+ int dl= (d0&0x03E07C1F);
+ int dh= ((d0>>5)&0x03E0F81F);
+
+ int dh2= (dh>>11) + (dh<<21);
+ int d= dh2 + dl;
+
+ int g= d&0x7F;
+ int r= (d>>10)&0x7F;
+ int b= d>>21;
+ dstU[i]= ((RU*r + GU*g + BU*b)>>(RGB2YUV_SHIFT+1-3)) + 128;
+ dstV[i]= ((RV*r + GV*g + BV*b)>>(RGB2YUV_SHIFT+1-3)) + 128;
+ }
+}
+
+static inline void RENAME(palToY)(uint8_t *dst, uint8_t *src, int width, uint32_t *pal)
+{
+ int i;
+ for(i=0; i<width; i++)
+ {
+ int d= src[i];
+ int b= pal[d] &0xFF;
+ int g=(pal[d]>>8 )&0xFF;
+ int r= pal[d]>>16;
+
+ dst[i]= ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16;
+ }
+}
+
+static inline void RENAME(palToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, int width, uint32_t *pal)
+{
+ int i;
+ assert(src1 == src2);
+ for(i=0; i<width; i++)
+ {
+ int d0= src1[2*i ];
+ int d1= src1[2*i+1];
+ int p = (pal[d0]&0xFF00FF) + (pal[d1]&0xFF00FF);
+ int g = (pal[d0]+pal[d1]-p)>>8;
+ int b= p&0x1FF;
+ int r= p>>16;
+
+ dstU[i]= ((RU*r + GU*g + BU*b)>>(RGB2YUV_SHIFT+1)) + 128;
+ dstV[i]= ((RV*r + GV*g + BV*b)>>(RGB2YUV_SHIFT+1)) + 128;
+ }
+}
+
+// Bilinear / Bicubic scaling
+static inline void RENAME(hScale)(int16_t *dst, int dstW, uint8_t *src, int srcW, int xInc,
+ int16_t *filter, int16_t *filterPos, long filterSize)
+{
+#ifdef HAVE_MMX
+ assert(filterSize % 4 == 0 && filterSize>0);
+ if(filterSize==4) // allways true for upscaling, sometimes for down too
+ {
+ long counter= -2*dstW;
+ filter-= counter*2;
+ filterPos-= counter/2;
+ dst-= counter/2;
+ asm volatile(
+#if defined(PIC)
+ "push %%"REG_b" \n\t"
+#endif
+ "pxor %%mm7, %%mm7 \n\t"
+ "movq "MANGLE(w02)", %%mm6 \n\t"
+ "push %%"REG_BP" \n\t" // we use 7 regs here ...
+ "mov %%"REG_a", %%"REG_BP" \n\t"
+ ASMALIGN(4)
+ "1: \n\t"
+ "movzwl (%2, %%"REG_BP"), %%eax \n\t"
+ "movzwl 2(%2, %%"REG_BP"), %%ebx\n\t"
+ "movq (%1, %%"REG_BP", 4), %%mm1\n\t"
+ "movq 8(%1, %%"REG_BP", 4), %%mm3\n\t"
+ "movd (%3, %%"REG_a"), %%mm0 \n\t"
+ "movd (%3, %%"REG_b"), %%mm2 \n\t"
+ "punpcklbw %%mm7, %%mm0 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t"
+ "pmaddwd %%mm1, %%mm0 \n\t"
+ "pmaddwd %%mm2, %%mm3 \n\t"
+ "psrad $8, %%mm0 \n\t"
+ "psrad $8, %%mm3 \n\t"
+ "packssdw %%mm3, %%mm0 \n\t"
+ "pmaddwd %%mm6, %%mm0 \n\t"
+ "packssdw %%mm0, %%mm0 \n\t"
+ "movd %%mm0, (%4, %%"REG_BP") \n\t"
+ "add $4, %%"REG_BP" \n\t"
+ " jnc 1b \n\t"
+
+ "pop %%"REG_BP" \n\t"
+#if defined(PIC)
+ "pop %%"REG_b" \n\t"
+#endif
+ : "+a" (counter)
+ : "c" (filter), "d" (filterPos), "S" (src), "D" (dst)
+#if !defined(PIC)
+ : "%"REG_b
+#endif
+ );
+ }
+ else if(filterSize==8)
+ {
+ long counter= -2*dstW;
+ filter-= counter*4;
+ filterPos-= counter/2;
+ dst-= counter/2;
+ asm volatile(
+#if defined(PIC)
+ "push %%"REG_b" \n\t"
+#endif
+ "pxor %%mm7, %%mm7 \n\t"
+ "movq "MANGLE(w02)", %%mm6 \n\t"
+ "push %%"REG_BP" \n\t" // we use 7 regs here ...
+ "mov %%"REG_a", %%"REG_BP" \n\t"
+ ASMALIGN(4)
+ "1: \n\t"
+ "movzwl (%2, %%"REG_BP"), %%eax \n\t"
+ "movzwl 2(%2, %%"REG_BP"), %%ebx\n\t"
+ "movq (%1, %%"REG_BP", 8), %%mm1\n\t"
+ "movq 16(%1, %%"REG_BP", 8), %%mm3\n\t"
+ "movd (%3, %%"REG_a"), %%mm0 \n\t"
+ "movd (%3, %%"REG_b"), %%mm2 \n\t"
+ "punpcklbw %%mm7, %%mm0 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t"
+ "pmaddwd %%mm1, %%mm0 \n\t"
+ "pmaddwd %%mm2, %%mm3 \n\t"
+
+ "movq 8(%1, %%"REG_BP", 8), %%mm1\n\t"
+ "movq 24(%1, %%"REG_BP", 8), %%mm5\n\t"
+ "movd 4(%3, %%"REG_a"), %%mm4 \n\t"
+ "movd 4(%3, %%"REG_b"), %%mm2 \n\t"
+ "punpcklbw %%mm7, %%mm4 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t"
+ "pmaddwd %%mm1, %%mm4 \n\t"
+ "pmaddwd %%mm2, %%mm5 \n\t"
+ "paddd %%mm4, %%mm0 \n\t"
+ "paddd %%mm5, %%mm3 \n\t"
+
+ "psrad $8, %%mm0 \n\t"
+ "psrad $8, %%mm3 \n\t"
+ "packssdw %%mm3, %%mm0 \n\t"
+ "pmaddwd %%mm6, %%mm0 \n\t"
+ "packssdw %%mm0, %%mm0 \n\t"
+ "movd %%mm0, (%4, %%"REG_BP") \n\t"
+ "add $4, %%"REG_BP" \n\t"
+ " jnc 1b \n\t"
+
+ "pop %%"REG_BP" \n\t"
+#if defined(PIC)
+ "pop %%"REG_b" \n\t"
+#endif
+ : "+a" (counter)
+ : "c" (filter), "d" (filterPos), "S" (src), "D" (dst)
+#if !defined(PIC)
+ : "%"REG_b
+#endif
+ );
+ }
+ else
+ {
+ uint8_t *offset = src+filterSize;
+ long counter= -2*dstW;
+// filter-= counter*filterSize/2;
+ filterPos-= counter/2;
+ dst-= counter/2;
+ asm volatile(
+ "pxor %%mm7, %%mm7 \n\t"
+ "movq "MANGLE(w02)", %%mm6 \n\t"
+ ASMALIGN(4)
+ "1: \n\t"
+ "mov %2, %%"REG_c" \n\t"
+ "movzwl (%%"REG_c", %0), %%eax \n\t"
+ "movzwl 2(%%"REG_c", %0), %%edx \n\t"
+ "mov %5, %%"REG_c" \n\t"
+ "pxor %%mm4, %%mm4 \n\t"
+ "pxor %%mm5, %%mm5 \n\t"
+ "2: \n\t"
+ "movq (%1), %%mm1 \n\t"
+ "movq (%1, %6), %%mm3 \n\t"
+ "movd (%%"REG_c", %%"REG_a"), %%mm0\n\t"
+ "movd (%%"REG_c", %%"REG_d"), %%mm2\n\t"
+ "punpcklbw %%mm7, %%mm0 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t"
+ "pmaddwd %%mm1, %%mm0 \n\t"
+ "pmaddwd %%mm2, %%mm3 \n\t"
+ "paddd %%mm3, %%mm5 \n\t"
+ "paddd %%mm0, %%mm4 \n\t"
+ "add $8, %1 \n\t"
+ "add $4, %%"REG_c" \n\t"
+ "cmp %4, %%"REG_c" \n\t"
+ " jb 2b \n\t"
+ "add %6, %1 \n\t"
+ "psrad $8, %%mm4 \n\t"
+ "psrad $8, %%mm5 \n\t"
+ "packssdw %%mm5, %%mm4 \n\t"
+ "pmaddwd %%mm6, %%mm4 \n\t"
+ "packssdw %%mm4, %%mm4 \n\t"
+ "mov %3, %%"REG_a" \n\t"
+ "movd %%mm4, (%%"REG_a", %0) \n\t"
+ "add $4, %0 \n\t"
+ " jnc 1b \n\t"
+
+ : "+r" (counter), "+r" (filter)
+ : "m" (filterPos), "m" (dst), "m"(offset),
+ "m" (src), "r" (filterSize*2)
+ : "%"REG_a, "%"REG_c, "%"REG_d
+ );
+ }
+#else
+#ifdef HAVE_ALTIVEC
+ hScale_altivec_real(dst, dstW, src, srcW, xInc, filter, filterPos, filterSize);
+#else
+ int i;
+ for(i=0; i<dstW; i++)
+ {
+ int j;
+ int srcPos= filterPos[i];
+ int val=0;
+// printf("filterPos: %d\n", filterPos[i]);
+ for(j=0; j<filterSize; j++)
+ {
+// printf("filter: %d, src: %d\n", filter[i], src[srcPos + j]);
+ val += ((int)src[srcPos + j])*filter[filterSize*i + j];
+ }
+// filter += hFilterSize;
+ dst[i] = av_clip(val>>7, 0, (1<<15)-1); // the cubic equation does overflow ...
+// dst[i] = val>>7;
+ }
+#endif
+#endif
+}
+ // *** horizontal scale Y line to temp buffer
+static inline void RENAME(hyscale)(uint16_t *dst, long dstWidth, uint8_t *src, int srcW, int xInc,
+ int flags, int canMMX2BeUsed, int16_t *hLumFilter,
+ int16_t *hLumFilterPos, int hLumFilterSize, void *funnyYCode,
+ int srcFormat, uint8_t *formatConvBuffer, int16_t *mmx2Filter,
+ int32_t *mmx2FilterPos, uint8_t *pal)
+{
+ if(srcFormat==PIX_FMT_YUYV422 || srcFormat==PIX_FMT_GRAY16BE)
+ {
+ RENAME(yuy2ToY)(formatConvBuffer, src, srcW);
+ src= formatConvBuffer;
+ }
+ else if(srcFormat==PIX_FMT_UYVY422 || srcFormat==PIX_FMT_GRAY16LE)
+ {
+ RENAME(uyvyToY)(formatConvBuffer, src, srcW);
+ src= formatConvBuffer;
+ }
+ else if(srcFormat==PIX_FMT_RGB32)
+ {
+ RENAME(bgr32ToY)(formatConvBuffer, src, srcW);
+ src= formatConvBuffer;
+ }
+ else if(srcFormat==PIX_FMT_BGR24)
+ {
+ RENAME(bgr24ToY)(formatConvBuffer, src, srcW);
+ src= formatConvBuffer;
+ }
+ else if(srcFormat==PIX_FMT_BGR565)
+ {
+ RENAME(bgr16ToY)(formatConvBuffer, src, srcW);
+ src= formatConvBuffer;
+ }
+ else if(srcFormat==PIX_FMT_BGR555)
+ {
+ RENAME(bgr15ToY)(formatConvBuffer, src, srcW);
+ src= formatConvBuffer;
+ }
+ else if(srcFormat==PIX_FMT_BGR32)
+ {
+ RENAME(rgb32ToY)(formatConvBuffer, src, srcW);
+ src= formatConvBuffer;
+ }
+ else if(srcFormat==PIX_FMT_RGB24)
+ {
+ RENAME(rgb24ToY)(formatConvBuffer, src, srcW);
+ src= formatConvBuffer;
+ }
+ else if(srcFormat==PIX_FMT_RGB565)
+ {
+ RENAME(rgb16ToY)(formatConvBuffer, src, srcW);
+ src= formatConvBuffer;
+ }
+ else if(srcFormat==PIX_FMT_RGB555)
+ {
+ RENAME(rgb15ToY)(formatConvBuffer, src, srcW);
+ src= formatConvBuffer;
+ }
+ else if(srcFormat==PIX_FMT_RGB8 || srcFormat==PIX_FMT_BGR8 || srcFormat==PIX_FMT_PAL8 || srcFormat==PIX_FMT_BGR4_BYTE || srcFormat==PIX_FMT_RGB4_BYTE)
+ {
+ RENAME(palToY)(formatConvBuffer, src, srcW, pal);
+ src= formatConvBuffer;
+ }
+
+#ifdef HAVE_MMX
+ // use the new MMX scaler if the mmx2 can't be used (its faster than the x86asm one)
+ if(!(flags&SWS_FAST_BILINEAR) || (!canMMX2BeUsed))
+#else
+ if(!(flags&SWS_FAST_BILINEAR))
+#endif
+ {
+ RENAME(hScale)(dst, dstWidth, src, srcW, xInc, hLumFilter, hLumFilterPos, hLumFilterSize);
+ }
+ else // Fast Bilinear upscale / crap downscale
+ {
+#if defined(ARCH_X86)
+#ifdef HAVE_MMX2
+ int i;
+#if defined(PIC)
+ uint64_t ebxsave __attribute__((aligned(8)));
+#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"
+
+#ifdef ARCH_X86_64
+
+#define FUNNY_Y_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 FUNNY_Y_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
+
+FUNNY_Y_CODE
+FUNNY_Y_CODE
+FUNNY_Y_CODE
+FUNNY_Y_CODE
+FUNNY_Y_CODE
+FUNNY_Y_CODE
+FUNNY_Y_CODE
+FUNNY_Y_CODE
+
+#if defined(PIC)
+ "mov %5, %%"REG_b" \n\t"
+#endif
+ :: "m" (src), "m" (dst), "m" (mmx2Filter), "m" (mmx2FilterPos),
+ "m" (funnyYCode)
+#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
+ long 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" // 2*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]
+ "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx]
+ "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha
+ "shll $16, %%edi \n\t"
+ "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha)
+ "mov %1, %%"REG_D" \n\t"
+ "shrl $9, %%esi \n\t"
+ "movw %%si, (%%"REG_D", %%"REG_a", 2)\n\t"
+ "addw %4, %%cx \n\t" //2*xalpha += xInc&0xFF
+ "adc %3, %%"REG_d" \n\t" //xx+= xInc>>8 + carry
+
+ "movzbl (%0, %%"REG_d"), %%edi \n\t" //src[xx]
+ "movzbl 1(%0, %%"REG_d"), %%esi \n\t" //src[xx+1]
+ "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx]
+ "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha
+ "shll $16, %%edi \n\t"
+ "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha)
+ "mov %1, %%"REG_D" \n\t"
+ "shrl $9, %%esi \n\t"
+ "movw %%si, 2(%%"REG_D", %%"REG_a", 2)\n\t"
+ "addw %4, %%cx \n\t" //2*xalpha += xInc&0xFF
+ "adc %3, %%"REG_d" \n\t" //xx+= xInc>>8 + 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"
+ );
+#ifdef HAVE_MMX2
+ } //if MMX2 can't be used
+#endif
+#else
+ int i;
+ unsigned int xpos=0;
+ for(i=0;i<dstWidth;i++)
+ {
+ register unsigned int xx=xpos>>16;
+ register unsigned int xalpha=(xpos&0xFFFF)>>9;
+ dst[i]= (src[xx]<<7) + (src[xx+1] - src[xx])*xalpha;
+ xpos+=xInc;
+ }
+#endif
+ }
+}
+
+inline static void RENAME(hcscale)(uint16_t *dst, long dstWidth, uint8_t *src1, uint8_t *src2,
+ int srcW, int xInc, int flags, int canMMX2BeUsed, int16_t *hChrFilter,
+ int16_t *hChrFilterPos, int hChrFilterSize, void *funnyUVCode,
+ int srcFormat, uint8_t *formatConvBuffer, int16_t *mmx2Filter,
+ int32_t *mmx2FilterPos, uint8_t *pal)
+{
+ if(srcFormat==PIX_FMT_YUYV422)
+ {
+ RENAME(yuy2ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
+ src1= formatConvBuffer;
+ src2= formatConvBuffer+2048;
+ }
+ else if(srcFormat==PIX_FMT_UYVY422)
+ {
+ RENAME(uyvyToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
+ src1= formatConvBuffer;
+ src2= formatConvBuffer+2048;
+ }
+ else if(srcFormat==PIX_FMT_RGB32)
+ {
+ RENAME(bgr32ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
+ src1= formatConvBuffer;
+ src2= formatConvBuffer+2048;
+ }
+ else if(srcFormat==PIX_FMT_BGR24)
+ {
+ RENAME(bgr24ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
+ src1= formatConvBuffer;
+ src2= formatConvBuffer+2048;
+ }
+ else if(srcFormat==PIX_FMT_BGR565)
+ {
+ RENAME(bgr16ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
+ src1= formatConvBuffer;
+ src2= formatConvBuffer+2048;
+ }
+ else if(srcFormat==PIX_FMT_BGR555)
+ {
+ RENAME(bgr15ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
+ src1= formatConvBuffer;
+ src2= formatConvBuffer+2048;
+ }
+ else if(srcFormat==PIX_FMT_BGR32)
+ {
+ RENAME(rgb32ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
+ src1= formatConvBuffer;
+ src2= formatConvBuffer+2048;
+ }
+ else if(srcFormat==PIX_FMT_RGB24)
+ {
+ RENAME(rgb24ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
+ src1= formatConvBuffer;
+ src2= formatConvBuffer+2048;
+ }
+ else if(srcFormat==PIX_FMT_RGB565)
+ {
+ RENAME(rgb16ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
+ src1= formatConvBuffer;
+ src2= formatConvBuffer+2048;
+ }
+ else if(srcFormat==PIX_FMT_RGB555)
+ {
+ RENAME(rgb15ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
+ src1= formatConvBuffer;
+ src2= formatConvBuffer+2048;
+ }
+ else if(isGray(srcFormat))
+ {
+ return;
+ }
+ else if(srcFormat==PIX_FMT_RGB8 || srcFormat==PIX_FMT_BGR8 || srcFormat==PIX_FMT_PAL8 || srcFormat==PIX_FMT_BGR4_BYTE || srcFormat==PIX_FMT_RGB4_BYTE)
+ {
+ RENAME(palToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW, pal);
+ src1= formatConvBuffer;
+ src2= formatConvBuffer+2048;
+ }
+
+#ifdef HAVE_MMX
+ // use the new MMX scaler if the mmx2 can't be used (its faster than the x86asm one)
+ if(!(flags&SWS_FAST_BILINEAR) || (!canMMX2BeUsed))
+#else
+ if(!(flags&SWS_FAST_BILINEAR))
+#endif
+ {
+ RENAME(hScale)(dst , dstWidth, src1, srcW, xInc, hChrFilter, hChrFilterPos, hChrFilterSize);
+ RENAME(hScale)(dst+2048, dstWidth, src2, srcW, xInc, hChrFilter, hChrFilterPos, hChrFilterSize);
+ }
+ else // Fast Bilinear upscale / crap downscale
+ {
+#if defined(ARCH_X86)
+#ifdef HAVE_MMX2
+ int i;
+#if defined(PIC)
+ uint64_t ebxsave __attribute__((aligned(8)));
+#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"
+
+#ifdef ARCH_X86_64
+
+#define FUNNY_UV_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 FUNNY_UV_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
+
+FUNNY_UV_CODE
+FUNNY_UV_CODE
+FUNNY_UV_CODE
+FUNNY_UV_CODE
+ "xor %%"REG_a", %%"REG_a" \n\t" // i
+ "mov %5, %%"REG_c" \n\t" // src
+ "mov %1, %%"REG_D" \n\t" // buf1
+ "add $4096, %%"REG_D" \n\t"
+ PREFETCH" (%%"REG_c") \n\t"
+ PREFETCH" 32(%%"REG_c") \n\t"
+ PREFETCH" 64(%%"REG_c") \n\t"
+
+FUNNY_UV_CODE
+FUNNY_UV_CODE
+FUNNY_UV_CODE
+FUNNY_UV_CODE
+
+#if defined(PIC)
+ "mov %6, %%"REG_b" \n\t"
+#endif
+ :: "m" (src1), "m" (dst), "m" (mmx2Filter), "m" (mmx2FilterPos),
+ "m" (funnyUVCode), "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+2048] = src2[srcW-1]*128;
+ }
+ }
+ else
+ {
+#endif
+ long xInc_shr16 = (long) (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" // 2*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]
+ "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx]
+ "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha
+ "shll $16, %%edi \n\t"
+ "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha)
+ "mov %1, %%"REG_D" \n\t"
+ "shrl $9, %%esi \n\t"
+ "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]
+ "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx]
+ "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha
+ "shll $16, %%edi \n\t"
+ "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha)
+ "mov %1, %%"REG_D" \n\t"
+ "shrl $9, %%esi \n\t"
+ "movw %%si, 4096(%%"REG_D", %%"REG_a", 2)\n\t"
+
+ "addw %4, %%cx \n\t" //2*xalpha += xInc&0xFF
+ "adc %3, %%"REG_d" \n\t" //xx+= xInc>>8 + 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 defined(ARCH_X86_64) && ((__GNUC__ > 3) || ( __GNUC__ == 3 && __GNUC_MINOR__ >= 4))
+ :: "m" (src1), "m" (dst), "g" ((long)dstWidth), "m" (xInc_shr16), "m" (xInc_mask),
+#else
+ :: "m" (src1), "m" (dst), "m" ((long)dstWidth), "m" (xInc_shr16), "m" (xInc_mask),
+#endif
+ "r" (src2)
+ : "%"REG_a, "%"REG_d, "%ecx", "%"REG_D, "%esi"
+ );
+#ifdef HAVE_MMX2
+ } //if MMX2 can't be used
+#endif
+#else
+ int i;
+ unsigned int xpos=0;
+ for(i=0;i<dstWidth;i++)
+ {
+ register unsigned int xx=xpos>>16;
+ register unsigned int xalpha=(xpos&0xFFFF)>>9;
+ dst[i]=(src1[xx]*(xalpha^127)+src1[xx+1]*xalpha);
+ dst[i+2048]=(src2[xx]*(xalpha^127)+src2[xx+1]*xalpha);
+/* slower
+ dst[i]= (src1[xx]<<7) + (src1[xx+1] - src1[xx])*xalpha;
+ dst[i+2048]=(src2[xx]<<7) + (src2[xx+1] - src2[xx])*xalpha;
+*/
+ xpos+=xInc;
+ }
+#endif
+ }
+}
+
+static int RENAME(swScale)(SwsContext *c, 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 */
+ const int srcW= c->srcW;
+ const int dstW= c->dstW;
+ const int dstH= c->dstH;
+ const int chrDstW= c->chrDstW;
+ 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 int flags= c->flags;
+ const int canMMX2BeUsed= c->canMMX2BeUsed;
+ int16_t *vLumFilterPos= c->vLumFilterPos;
+ int16_t *vChrFilterPos= c->vChrFilterPos;
+ int16_t *hLumFilterPos= c->hLumFilterPos;
+ int16_t *hChrFilterPos= c->hChrFilterPos;
+ int16_t *vLumFilter= c->vLumFilter;
+ int16_t *vChrFilter= c->vChrFilter;
+ int16_t *hLumFilter= c->hLumFilter;
+ int16_t *hChrFilter= c->hChrFilter;
+ int32_t *lumMmxFilter= c->lumMmxFilter;
+ int32_t *chrMmxFilter= c->chrMmxFilter;
+ const int vLumFilterSize= c->vLumFilterSize;
+ const int vChrFilterSize= c->vChrFilterSize;
+ const int hLumFilterSize= c->hLumFilterSize;
+ const int hChrFilterSize= c->hChrFilterSize;
+ int16_t **lumPixBuf= c->lumPixBuf;
+ int16_t **chrPixBuf= c->chrPixBuf;
+ const int vLumBufSize= c->vLumBufSize;
+ const int vChrBufSize= c->vChrBufSize;
+ uint8_t *funnyYCode= c->funnyYCode;
+ uint8_t *funnyUVCode= c->funnyUVCode;
+ uint8_t *formatConvBuffer= c->formatConvBuffer;
+ const int chrSrcSliceY= srcSliceY >> c->chrSrcVSubSample;
+ const int chrSrcSliceH= -((-srcSliceH) >> c->chrSrcVSubSample);
+ int lastDstY;
+ uint8_t *pal=NULL;
+
+ /* vars whch will change and which we need to storw back in the context */
+ int dstY= c->dstY;
+ int lumBufIndex= c->lumBufIndex;
+ int chrBufIndex= c->chrBufIndex;
+ int lastInLumBuf= c->lastInLumBuf;
+ int lastInChrBuf= c->lastInChrBuf;
+
+ if(isPacked(c->srcFormat)){
+ pal= src[1];
+ src[0]=
+ src[1]=
+ src[2]= src[0];
+ srcStride[0]=
+ srcStride[1]=
+ srcStride[2]= srcStride[0];
+ }
+ 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]);
+
+#if 0 //self test FIXME move to a vfilter or something
+{
+static volatile int i=0;
+i++;
+if(srcFormat==PIX_FMT_YUV420P && i==1 && srcSliceH>= c->srcH)
+ selfTest(src, srcStride, c->srcW, c->srcH);
+i--;
+}
+#endif
+
+//printf("sws Strides:%d %d %d -> %d %d %d\n", srcStride[0],srcStride[1],srcStride[2],
+//dstStride[0],dstStride[1],dstStride[2]);
+
+ if(dstStride[0]%8 !=0 || dstStride[1]%8 !=0 || dstStride[2]%8 !=0)
+ {
+ static int firstTime=1; //FIXME move this into the context perhaps
+ if(flags & SWS_PRINT_INFO && firstTime)
+ {
+ av_log(c, AV_LOG_WARNING, "SwScaler: Warning: dstStride is not aligned!\n"
+ "SwScaler: ->cannot do aligned memory acesses anymore\n");
+ firstTime=0;
+ }
+ }
+
+ /* Note the user might start scaling the picture in the middle so this will not get executed
+ this is not really intended but works currently, so ppl might do it */
+ if(srcSliceY ==0){
+ lumBufIndex=0;
+ chrBufIndex=0;
+ dstY=0;
+ lastInLumBuf= -1;
+ lastInChrBuf= -1;
+ }
+
+ lastDstY= dstY;
+
+ for(;dstY < dstH; dstY++){
+ unsigned char *dest =dst[0]+dstStride[0]*dstY;
+ const int chrDstY= dstY>>c->chrDstVSubSample;
+ unsigned char *uDest=dst[1]+dstStride[1]*chrDstY;
+ unsigned char *vDest=dst[2]+dstStride[2]*chrDstY;
+
+ const int firstLumSrcY= vLumFilterPos[dstY]; //First line needed as input
+ const int firstChrSrcY= vChrFilterPos[chrDstY]; //First line needed as input
+ const int lastLumSrcY= firstLumSrcY + vLumFilterSize -1; // Last line needed as input
+ const int lastChrSrcY= firstChrSrcY + vChrFilterSize -1; // Last line needed as input
+
+//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)
+
+ // Do we have enough lines in this slice to output the dstY line
+ if(lastLumSrcY < srcSliceY + srcSliceH && lastChrSrcY < -((-srcSliceY - srcSliceH)>>c->chrSrcVSubSample))
+ {
+ //Do horizontal scaling
+ while(lastInLumBuf < lastLumSrcY)
+ {
+ uint8_t *s= src[0]+(lastInLumBuf + 1 - srcSliceY)*srcStride[0];
+ 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)(lumPixBuf[ lumBufIndex ], dstW, s, srcW, lumXInc,
+ flags, canMMX2BeUsed, hLumFilter, hLumFilterPos, hLumFilterSize,
+ funnyYCode, c->srcFormat, formatConvBuffer,
+ c->lumMmx2Filter, c->lumMmx2FilterPos, pal);
+ lastInLumBuf++;
+ }
+ while(lastInChrBuf < lastChrSrcY)
+ {
+ uint8_t *src1= src[1]+(lastInChrBuf + 1 - chrSrcSliceY)*srcStride[1];
+ 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)))
+ RENAME(hcscale)(chrPixBuf[ chrBufIndex ], chrDstW, src1, src2, chrSrcW, chrXInc,
+ flags, canMMX2BeUsed, hChrFilter, hChrFilterPos, hChrFilterSize,
+ funnyUVCode, c->srcFormat, formatConvBuffer,
+ c->chrMmx2Filter, c->chrMmx2FilterPos, pal);
+ lastInChrBuf++;
+ }
+ //wrap buf index around to stay inside the ring buffer
+ if(lumBufIndex >= vLumBufSize ) lumBufIndex-= vLumBufSize;
+ if(chrBufIndex >= vChrBufSize ) chrBufIndex-= vChrBufSize;
+ }
+ else // not enough lines left in this slice -> load the rest in the buffer
+ {
+/* 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+1 < srcSliceY + srcSliceH)
+ {
+ uint8_t *s= src[0]+(lastInLumBuf + 1 - srcSliceY)*srcStride[0];
+ lumBufIndex++;
+ ASSERT(lumBufIndex < 2*vLumBufSize)
+ ASSERT(lastInLumBuf + 1 - srcSliceY < srcSliceH)
+ ASSERT(lastInLumBuf + 1 - srcSliceY >= 0)
+ RENAME(hyscale)(lumPixBuf[ lumBufIndex ], dstW, s, srcW, lumXInc,
+ flags, canMMX2BeUsed, hLumFilter, hLumFilterPos, hLumFilterSize,
+ funnyYCode, c->srcFormat, formatConvBuffer,
+ c->lumMmx2Filter, c->lumMmx2FilterPos, pal);
+ lastInLumBuf++;
+ }
+ while(lastInChrBuf+1 < (chrSrcSliceY + chrSrcSliceH))
+ {
+ uint8_t *src1= src[1]+(lastInChrBuf + 1 - chrSrcSliceY)*srcStride[1];
+ 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)
+
+ if(!(isGray(srcFormat) || isGray(dstFormat)))
+ RENAME(hcscale)(chrPixBuf[ chrBufIndex ], chrDstW, src1, src2, chrSrcW, chrXInc,
+ flags, canMMX2BeUsed, hChrFilter, hChrFilterPos, hChrFilterSize,
+ funnyUVCode, c->srcFormat, formatConvBuffer,
+ c->chrMmx2Filter, c->chrMmx2FilterPos, pal);
+ lastInChrBuf++;
+ }
+ //wrap buf index around to stay inside the ring buffer
+ if(lumBufIndex >= vLumBufSize ) lumBufIndex-= vLumBufSize;
+ if(chrBufIndex >= vChrBufSize ) chrBufIndex-= vChrBufSize;
+ break; //we can't output a dstY line so let's try with the next slice
+ }
+
+#ifdef HAVE_MMX
+ b5Dither= dither8[dstY&1];
+ g6Dither= dither4[dstY&1];
+ g5Dither= dither8[dstY&1];
+ r5Dither= dither8[(dstY+1)&1];
+#endif
+ if(dstY < dstH-2)
+ {
+ int16_t **lumSrcPtr= lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize;
+ int16_t **chrSrcPtr= chrPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize;
+#ifdef HAVE_MMX
+ int i;
+ if(flags & SWS_ACCURATE_RND){
+ for(i=0; i<vLumFilterSize; i+=2){
+ lumMmxFilter[2*i+0]= (int32_t)lumSrcPtr[i ];
+ lumMmxFilter[2*i+1]= (int32_t)lumSrcPtr[i+(vLumFilterSize>1)];
+ lumMmxFilter[2*i+2]=
+ lumMmxFilter[2*i+3]= vLumFilter[dstY*vLumFilterSize + i ]
+ + (vLumFilterSize>1 ? vLumFilter[dstY*vLumFilterSize + i + 1]<<16 : 0);
+ }
+ for(i=0; i<vChrFilterSize; i+=2){
+ chrMmxFilter[2*i+0]= (int32_t)chrSrcPtr[i ];
+ chrMmxFilter[2*i+1]= (int32_t)chrSrcPtr[i+(vChrFilterSize>1)];
+ chrMmxFilter[2*i+2]=
+ chrMmxFilter[2*i+3]= vChrFilter[chrDstY*vChrFilterSize + i ]
+ + (vChrFilterSize>1 ? vChrFilter[chrDstY*vChrFilterSize + i + 1]<<16 : 0);
+ }
+ }else{
+ for(i=0; i<vLumFilterSize; i++)
+ {
+ lumMmxFilter[4*i+0]= (int32_t)lumSrcPtr[i];
+ lumMmxFilter[4*i+1]= (uint64_t)lumSrcPtr[i] >> 32;
+ lumMmxFilter[4*i+2]=
+ lumMmxFilter[4*i+3]=
+ ((uint16_t)vLumFilter[dstY*vLumFilterSize + i])*0x10001;
+ }
+ for(i=0; i<vChrFilterSize; i++)
+ {
+ chrMmxFilter[4*i+0]= (int32_t)chrSrcPtr[i];
+ chrMmxFilter[4*i+1]= (uint64_t)chrSrcPtr[i] >> 32;
+ chrMmxFilter[4*i+2]=
+ chrMmxFilter[4*i+3]=
+ ((uint16_t)vChrFilter[chrDstY*vChrFilterSize + i])*0x10001;
+ }
+ }
+#endif
+ if(dstFormat == PIX_FMT_NV12 || dstFormat == PIX_FMT_NV21){
+ const int chrSkipMask= (1<<c->chrDstVSubSample)-1;
+ if(dstY&chrSkipMask) uDest= NULL; //FIXME split functions in lumi / chromi
+ RENAME(yuv2nv12X)(c,
+ vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize,
+ vChrFilter+chrDstY*vChrFilterSize, chrSrcPtr, vChrFilterSize,
+ dest, uDest, dstW, chrDstW, dstFormat);
+ }
+ else if(isPlanarYUV(dstFormat) || isGray(dstFormat)) //YV12 like
+ {
+ const int chrSkipMask= (1<<c->chrDstVSubSample)-1;
+ if((dstY&chrSkipMask) || isGray(dstFormat)) uDest=vDest= NULL; //FIXME split functions in lumi / chromi
+ if(vLumFilterSize == 1 && vChrFilterSize == 1) // Unscaled YV12
+ {
+ int16_t *lumBuf = lumPixBuf[0];
+ int16_t *chrBuf= chrPixBuf[0];
+ RENAME(yuv2yuv1)(lumBuf, chrBuf, dest, uDest, vDest, dstW, chrDstW);
+ }
+ else //General YV12
+ {
+ RENAME(yuv2yuvX)(c,
+ vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize,
+ vChrFilter+chrDstY*vChrFilterSize, chrSrcPtr, vChrFilterSize,
+ dest, uDest, vDest, dstW, chrDstW);
+ }
+ }
+ else
+ {
+ ASSERT(lumSrcPtr + vLumFilterSize - 1 < lumPixBuf + vLumBufSize*2);
+ ASSERT(chrSrcPtr + vChrFilterSize - 1 < chrPixBuf + vChrBufSize*2);
+ if(vLumFilterSize == 1 && vChrFilterSize == 2) //Unscaled RGB
+ {
+ int chrAlpha= vChrFilter[2*dstY+1];
+ RENAME(yuv2packed1)(c, *lumSrcPtr, *chrSrcPtr, *(chrSrcPtr+1),
+ dest, dstW, chrAlpha, dstFormat, flags, dstY);
+ }
+ else if(vLumFilterSize == 2 && vChrFilterSize == 2) //BiLinear Upscale RGB
+ {
+ int lumAlpha= vLumFilter[2*dstY+1];
+ int chrAlpha= vChrFilter[2*dstY+1];
+ lumMmxFilter[2]=
+ lumMmxFilter[3]= vLumFilter[2*dstY ]*0x10001;
+ chrMmxFilter[2]=
+ chrMmxFilter[3]= vChrFilter[2*chrDstY]*0x10001;
+ RENAME(yuv2packed2)(c, *lumSrcPtr, *(lumSrcPtr+1), *chrSrcPtr, *(chrSrcPtr+1),
+ dest, dstW, lumAlpha, chrAlpha, dstY);
+ }
+ else //General RGB
+ {
+ RENAME(yuv2packedX)(c,
+ vLumFilter+dstY*vLumFilterSize, lumSrcPtr, vLumFilterSize,
+ vChrFilter+dstY*vChrFilterSize, chrSrcPtr, vChrFilterSize,
+ dest, dstW, dstY);
+ }
+ }
+ }
+ else // hmm looks like we can't use MMX here without overwriting this array's tail
+ {
+ int16_t **lumSrcPtr= lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize;
+ int16_t **chrSrcPtr= chrPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize;
+ if(dstFormat == PIX_FMT_NV12 || dstFormat == PIX_FMT_NV21){
+ const int chrSkipMask= (1<<c->chrDstVSubSample)-1;
+ if(dstY&chrSkipMask) uDest= NULL; //FIXME split functions in lumi / chromi
+ yuv2nv12XinC(
+ vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize,
+ vChrFilter+chrDstY*vChrFilterSize, chrSrcPtr, vChrFilterSize,
+ dest, uDest, dstW, chrDstW, dstFormat);
+ }
+ else if(isPlanarYUV(dstFormat) || isGray(dstFormat)) //YV12
+ {
+ const int chrSkipMask= (1<<c->chrDstVSubSample)-1;
+ if((dstY&chrSkipMask) || isGray(dstFormat)) uDest=vDest= NULL; //FIXME split functions in lumi / chromi
+ yuv2yuvXinC(
+ vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize,
+ vChrFilter+chrDstY*vChrFilterSize, chrSrcPtr, vChrFilterSize,
+ dest, uDest, vDest, dstW, chrDstW);
+ }
+ else
+ {
+ ASSERT(lumSrcPtr + vLumFilterSize - 1 < lumPixBuf + vLumBufSize*2);
+ ASSERT(chrSrcPtr + vChrFilterSize - 1 < chrPixBuf + vChrBufSize*2);
+ yuv2packedXinC(c,
+ vLumFilter+dstY*vLumFilterSize, lumSrcPtr, vLumFilterSize,
+ vChrFilter+dstY*vChrFilterSize, chrSrcPtr, vChrFilterSize,
+ dest, dstW, dstY);
+ }
+ }
+ }
+
+#ifdef HAVE_MMX
+ __asm __volatile(SFENCE:::"memory");
+ __asm __volatile(EMMS:::"memory");
+#endif
+ /* store changed local vars back in the context */
+ c->dstY= dstY;
+ c->lumBufIndex= lumBufIndex;
+ c->chrBufIndex= chrBufIndex;
+ c->lastInLumBuf= lastInLumBuf;
+ c->lastInChrBuf= lastInChrBuf;
+
+ return dstY - lastDstY;
+}
diff --git a/contrib/ffmpeg/libswscale/yuv2rgb.c b/contrib/ffmpeg/libswscale/yuv2rgb.c
new file mode 100644
index 000000000..af7f86f40
--- /dev/null
+++ b/contrib/ffmpeg/libswscale/yuv2rgb.c
@@ -0,0 +1,851 @@
+/*
+ * yuv2rgb.c, Software YUV to RGB coverter
+ *
+ * Copyright (C) 1999, Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ * All Rights Reserved.
+ *
+ * Functions broken out from display_x11.c and several new modes
+ * added by Håkan Hjort <d95hjort@dtek.chalmers.se>
+ *
+ * 15 & 16 bpp support by Franck Sicard <Franck.Sicard@solsoft.fr>
+ *
+ * This file is part of mpeg2dec, a free MPEG-2 video decoder
+ *
+ * mpeg2dec 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, or (at your option)
+ * any later version.
+ *
+ * mpeg2dec is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with mpeg2dec; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * MMX/MMX2 Template stuff from Michael Niedermayer (michaelni@gmx.at) (needed for fast movntq support)
+ * 1,4,8bpp support by Michael Niedermayer (michaelni@gmx.at)
+ * context / deglobalize stuff by Michael Niedermayer
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include <assert.h>
+
+#include "config.h"
+#include "rgb2rgb.h"
+#include "swscale.h"
+#include "swscale_internal.h"
+
+#ifdef HAVE_MLIB
+#include "yuv2rgb_mlib.c"
+#endif
+
+#define DITHER1XBPP // only for mmx
+
+const uint8_t __attribute__((aligned(8))) dither_2x2_4[2][8]={
+{ 1, 3, 1, 3, 1, 3, 1, 3, },
+{ 2, 0, 2, 0, 2, 0, 2, 0, },
+};
+
+const uint8_t __attribute__((aligned(8))) dither_2x2_8[2][8]={
+{ 6, 2, 6, 2, 6, 2, 6, 2, },
+{ 0, 4, 0, 4, 0, 4, 0, 4, },
+};
+
+const uint8_t __attribute__((aligned(8))) 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, },
+{ 0, 24, 6, 30, 1, 25, 7, 31, },
+{ 16, 8, 22, 14, 17, 9, 23, 15, },
+{ 4, 28, 2, 26, 5, 29, 3, 27, },
+{ 20, 12, 18, 10, 21, 13, 19, 11, },
+{ 1, 25, 7, 31, 0, 24, 6, 30, },
+};
+
+#if 0
+const uint8_t __attribute__((aligned(8))) dither_8x8_64[8][8]={
+{ 0, 48, 12, 60, 3, 51, 15, 63, },
+{ 32, 16, 44, 28, 35, 19, 47, 31, },
+{ 8, 56, 4, 52, 11, 59, 7, 55, },
+{ 40, 24, 36, 20, 43, 27, 39, 23, },
+{ 2, 50, 14, 62, 1, 49, 13, 61, },
+{ 34, 18, 46, 30, 33, 17, 45, 29, },
+{ 10, 58, 6, 54, 9, 57, 5, 53, },
+{ 42, 26, 38, 22, 41, 25, 37, 21, },
+};
+#endif
+
+const uint8_t __attribute__((aligned(8))) 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, },
+{ 46, 27, 41, 23, 49, 31, 44, 26, },
+{ 2, 57, 16, 71, 1, 56, 15, 70, },
+{ 39, 21, 52, 34, 38, 19, 51, 33, },
+{ 11, 66, 7, 62, 10, 65, 6, 60, },
+{ 48, 30, 43, 25, 47, 29, 42, 24, },
+};
+
+#if 0
+const uint8_t __attribute__((aligned(8))) dither_8x8_128[8][8]={
+{ 68, 36, 92, 60, 66, 34, 90, 58, },
+{ 20, 116, 12, 108, 18, 114, 10, 106, },
+{ 84, 52, 76, 44, 82, 50, 74, 42, },
+{ 0, 96, 24, 120, 6, 102, 30, 126, },
+{ 64, 32, 88, 56, 70, 38, 94, 62, },
+{ 16, 112, 8, 104, 22, 118, 14, 110, },
+{ 80, 48, 72, 40, 86, 54, 78, 46, },
+{ 4, 100, 28, 124, 2, 98, 26, 122, },
+};
+#endif
+
+#if 1
+const uint8_t __attribute__((aligned(8))) 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, },
+{ 0, 165, 41, 206, 10, 175, 52, 217, },
+{110, 55, 151, 96, 120, 65, 162, 107, },
+{ 28, 193, 14, 179, 38, 203, 24, 189, },
+{138, 83, 124, 69, 148, 93, 134, 79, },
+{ 7, 172, 48, 213, 3, 168, 45, 210, },
+};
+#elif 1
+// tries to correct a gamma of 1.5
+const uint8_t __attribute__((aligned(8))) 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, },
+{109, 51, 93, 38, 121, 60, 105, 47, },
+{ 1, 152, 23, 210, 0, 147, 20, 205, },
+{ 85, 33, 134, 71, 81, 30, 130, 67, },
+{ 14, 190, 6, 171, 12, 185, 5, 166, },
+{117, 57, 101, 44, 113, 54, 97, 41, },
+};
+#elif 1
+// tries to correct a gamma of 2.0
+const uint8_t __attribute__((aligned(8))) 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, },
+{ 86, 31, 70, 21, 99, 39, 82, 28, },
+{ 0, 134, 11, 206, 0, 129, 9, 200, },
+{ 62, 17, 114, 48, 58, 16, 109, 45, },
+{ 5, 181, 2, 157, 4, 175, 1, 151, },
+{ 95, 36, 78, 26, 90, 34, 74, 24, },
+};
+#else
+// tries to correct a gamma of 2.5
+const uint8_t __attribute__((aligned(8))) 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, },
+{ 68, 19, 52, 12, 81, 25, 64, 17, },
+{ 0, 119, 5, 203, 0, 113, 4, 195, },
+{ 45, 9, 96, 33, 42, 8, 91, 30, },
+{ 2, 172, 1, 144, 2, 165, 0, 137, },
+{ 77, 23, 60, 15, 72, 21, 56, 14, },
+};
+#endif
+
+#ifdef HAVE_MMX
+
+/* hope these constant values are cache line aligned */
+static uint64_t attribute_used __attribute__((aligned(8))) mmx_00ffw = 0x00ff00ff00ff00ffULL;
+static uint64_t attribute_used __attribute__((aligned(8))) mmx_redmask = 0xf8f8f8f8f8f8f8f8ULL;
+static uint64_t attribute_used __attribute__((aligned(8))) mmx_grnmask = 0xfcfcfcfcfcfcfcfcULL;
+
+static uint64_t attribute_used __attribute__((aligned(8))) M24A= 0x00FF0000FF0000FFULL;
+static uint64_t attribute_used __attribute__((aligned(8))) M24B= 0xFF0000FF0000FF00ULL;
+static uint64_t attribute_used __attribute__((aligned(8))) M24C= 0x0000FF0000FF0000ULL;
+
+// the volatile is required because gcc otherwise optimizes some writes away not knowing that these
+// are read in the asm block
+static volatile uint64_t attribute_used __attribute__((aligned(8))) b5Dither;
+static volatile uint64_t attribute_used __attribute__((aligned(8))) g5Dither;
+static volatile uint64_t attribute_used __attribute__((aligned(8))) g6Dither;
+static volatile uint64_t attribute_used __attribute__((aligned(8))) r5Dither;
+
+static uint64_t __attribute__((aligned(8))) dither4[2]={
+ 0x0103010301030103LL,
+ 0x0200020002000200LL,};
+
+static uint64_t __attribute__((aligned(8))) dither8[2]={
+ 0x0602060206020602LL,
+ 0x0004000400040004LL,};
+
+#undef HAVE_MMX
+
+//MMX versions
+#undef RENAME
+#define HAVE_MMX
+#undef HAVE_MMX2
+#undef HAVE_3DNOW
+#define RENAME(a) a ## _MMX
+#include "yuv2rgb_template.c"
+
+//MMX2 versions
+#undef RENAME
+#define HAVE_MMX
+#define HAVE_MMX2
+#undef HAVE_3DNOW
+#define RENAME(a) a ## _MMX2
+#include "yuv2rgb_template.c"
+
+#endif /* defined(ARCH_X86) */
+
+const int32_t Inverse_Table_6_9[8][4] = {
+ {117504, 138453, 13954, 34903}, /* no sequence_display_extension */
+ {117504, 138453, 13954, 34903}, /* ITU-R Rec. 709 (1990) */
+ {104597, 132201, 25675, 53279}, /* unspecified */
+ {104597, 132201, 25675, 53279}, /* reserved */
+ {104448, 132798, 24759, 53109}, /* FCC */
+ {104597, 132201, 25675, 53279}, /* ITU-R Rec. 624-4 System B, G */
+ {104597, 132201, 25675, 53279}, /* SMPTE 170M */
+ {117579, 136230, 16907, 35559} /* SMPTE 240M (1987) */
+};
+
+#define RGB(i) \
+ U = pu[i]; \
+ V = pv[i]; \
+ r = (void *)c->table_rV[V]; \
+ g = (void *)(c->table_gU[U] + c->table_gV[V]); \
+ b = (void *)c->table_bU[U];
+
+#define DST1(i) \
+ Y = py_1[2*i]; \
+ dst_1[2*i] = r[Y] + g[Y] + b[Y]; \
+ Y = py_1[2*i+1]; \
+ dst_1[2*i+1] = r[Y] + g[Y] + b[Y];
+
+#define DST2(i) \
+ Y = py_2[2*i]; \
+ dst_2[2*i] = r[Y] + g[Y] + b[Y]; \
+ Y = py_2[2*i+1]; \
+ dst_2[2*i+1] = r[Y] + g[Y] + b[Y];
+
+#define DST1RGB(i) \
+ Y = py_1[2*i]; \
+ dst_1[6*i] = r[Y]; dst_1[6*i+1] = g[Y]; dst_1[6*i+2] = b[Y]; \
+ Y = py_1[2*i+1]; \
+ dst_1[6*i+3] = r[Y]; dst_1[6*i+4] = g[Y]; dst_1[6*i+5] = b[Y];
+
+#define DST2RGB(i) \
+ Y = py_2[2*i]; \
+ dst_2[6*i] = r[Y]; dst_2[6*i+1] = g[Y]; dst_2[6*i+2] = b[Y]; \
+ Y = py_2[2*i+1]; \
+ dst_2[6*i+3] = r[Y]; dst_2[6*i+4] = g[Y]; dst_2[6*i+5] = b[Y];
+
+#define DST1BGR(i) \
+ Y = py_1[2*i]; \
+ dst_1[6*i] = b[Y]; dst_1[6*i+1] = g[Y]; dst_1[6*i+2] = r[Y]; \
+ Y = py_1[2*i+1]; \
+ dst_1[6*i+3] = b[Y]; dst_1[6*i+4] = g[Y]; dst_1[6*i+5] = r[Y];
+
+#define DST2BGR(i) \
+ Y = py_2[2*i]; \
+ dst_2[6*i] = b[Y]; dst_2[6*i+1] = g[Y]; dst_2[6*i+2] = r[Y]; \
+ Y = py_2[2*i+1]; \
+ dst_2[6*i+3] = b[Y]; dst_2[6*i+4] = g[Y]; dst_2[6*i+5] = r[Y];
+
+#define PROLOG(func_name, dst_type) \
+static int func_name(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, \
+ int srcSliceH, uint8_t* dst[], int dstStride[]){\
+ int y;\
+\
+ if(c->srcFormat == PIX_FMT_YUV422P){\
+ srcStride[1] *= 2;\
+ srcStride[2] *= 2;\
+ }\
+ for(y=0; y<srcSliceH; y+=2){\
+ dst_type *dst_1= (dst_type*)(dst[0] + (y+srcSliceY )*dstStride[0]);\
+ dst_type *dst_2= (dst_type*)(dst[0] + (y+srcSliceY+1)*dstStride[0]);\
+ dst_type attribute_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];\
+ unsigned int h_size= c->dstW>>3;\
+ while (h_size--) {\
+ int attribute_unused U, V;\
+ int Y;\
+
+#define EPILOG(dst_delta)\
+ pu += 4;\
+ pv += 4;\
+ py_1 += 8;\
+ py_2 += 8;\
+ dst_1 += dst_delta;\
+ dst_2 += dst_delta;\
+ }\
+ }\
+ return srcSliceH;\
+}
+
+PROLOG(yuv2rgb_c_32, uint32_t)
+ RGB(0);
+ DST1(0);
+ DST2(0);
+
+ RGB(1);
+ DST2(1);
+ DST1(1);
+
+ RGB(2);
+ DST1(2);
+ DST2(2);
+
+ RGB(3);
+ DST2(3);
+ DST1(3);
+EPILOG(8)
+
+PROLOG(yuv2rgb_c_24_rgb, uint8_t)
+ RGB(0);
+ DST1RGB(0);
+ DST2RGB(0);
+
+ RGB(1);
+ DST2RGB(1);
+ DST1RGB(1);
+
+ RGB(2);
+ DST1RGB(2);
+ DST2RGB(2);
+
+ RGB(3);
+ DST2RGB(3);
+ DST1RGB(3);
+EPILOG(24)
+
+// only trivial mods from yuv2rgb_c_24_rgb
+PROLOG(yuv2rgb_c_24_bgr, uint8_t)
+ RGB(0);
+ DST1BGR(0);
+ DST2BGR(0);
+
+ RGB(1);
+ DST2BGR(1);
+ DST1BGR(1);
+
+ RGB(2);
+ DST1BGR(2);
+ DST2BGR(2);
+
+ RGB(3);
+ DST2BGR(3);
+ DST1BGR(3);
+EPILOG(24)
+
+// This is exactly the same code as yuv2rgb_c_32 except for the types of
+// r, g, b, dst_1, dst_2
+PROLOG(yuv2rgb_c_16, uint16_t)
+ RGB(0);
+ DST1(0);
+ DST2(0);
+
+ RGB(1);
+ DST2(1);
+ DST1(1);
+
+ RGB(2);
+ DST1(2);
+ DST2(2);
+
+ RGB(3);
+ DST2(3);
+ DST1(3);
+EPILOG(8)
+
+// This is exactly the same code as yuv2rgb_c_32 except for the types of
+// r, g, b, dst_1, dst_2
+PROLOG(yuv2rgb_c_8, uint8_t)
+ RGB(0);
+ DST1(0);
+ DST2(0);
+
+ RGB(1);
+ DST2(1);
+ DST1(1);
+
+ RGB(2);
+ DST1(2);
+ DST2(2);
+
+ RGB(3);
+ DST2(3);
+ DST1(3);
+EPILOG(8)
+
+// r, g, b, dst_1, dst_2
+PROLOG(yuv2rgb_c_8_ordered_dither, uint8_t)
+ const uint8_t *d32= dither_8x8_32[y&7];
+ const uint8_t *d64= dither_8x8_73[y&7];
+#define DST1bpp8(i,o) \
+ Y = py_1[2*i]; \
+ dst_1[2*i] = r[Y+d32[0+o]] + g[Y+d32[0+o]] + b[Y+d64[0+o]]; \
+ Y = py_1[2*i+1]; \
+ dst_1[2*i+1] = r[Y+d32[1+o]] + g[Y+d32[1+o]] + b[Y+d64[1+o]];
+
+#define DST2bpp8(i,o) \
+ Y = py_2[2*i]; \
+ dst_2[2*i] = r[Y+d32[8+o]] + g[Y+d32[8+o]] + b[Y+d64[8+o]]; \
+ Y = py_2[2*i+1]; \
+ dst_2[2*i+1] = r[Y+d32[9+o]] + g[Y+d32[9+o]] + b[Y+d64[9+o]];
+
+
+ RGB(0);
+ DST1bpp8(0,0);
+ DST2bpp8(0,0);
+
+ RGB(1);
+ DST2bpp8(1,2);
+ DST1bpp8(1,2);
+
+ RGB(2);
+ DST1bpp8(2,4);
+ DST2bpp8(2,4);
+
+ RGB(3);
+ DST2bpp8(3,6);
+ DST1bpp8(3,6);
+EPILOG(8)
+
+
+// This is exactly the same code as yuv2rgb_c_32 except for the types of
+// r, g, b, dst_1, dst_2
+PROLOG(yuv2rgb_c_4, uint8_t)
+ int acc;
+#define DST1_4(i) \
+ Y = py_1[2*i]; \
+ acc = r[Y] + g[Y] + b[Y]; \
+ Y = py_1[2*i+1]; \
+ acc |= (r[Y] + g[Y] + b[Y])<<4;\
+ dst_1[i] = acc;
+
+#define DST2_4(i) \
+ Y = py_2[2*i]; \
+ acc = r[Y] + g[Y] + b[Y]; \
+ Y = py_2[2*i+1]; \
+ acc |= (r[Y] + g[Y] + b[Y])<<4;\
+ dst_2[i] = acc;
+
+ RGB(0);
+ DST1_4(0);
+ DST2_4(0);
+
+ RGB(1);
+ DST2_4(1);
+ DST1_4(1);
+
+ RGB(2);
+ DST1_4(2);
+ DST2_4(2);
+
+ RGB(3);
+ DST2_4(3);
+ DST1_4(3);
+EPILOG(4)
+
+PROLOG(yuv2rgb_c_4_ordered_dither, uint8_t)
+ const uint8_t *d64= dither_8x8_73[y&7];
+ const uint8_t *d128=dither_8x8_220[y&7];
+ int acc;
+
+#define DST1bpp4(i,o) \
+ Y = py_1[2*i]; \
+ acc = r[Y+d128[0+o]] + g[Y+d64[0+o]] + b[Y+d128[0+o]]; \
+ Y = py_1[2*i+1]; \
+ acc |= (r[Y+d128[1+o]] + g[Y+d64[1+o]] + b[Y+d128[1+o]])<<4;\
+ dst_1[i]= acc;
+
+#define DST2bpp4(i,o) \
+ Y = py_2[2*i]; \
+ acc = r[Y+d128[8+o]] + g[Y+d64[8+o]] + b[Y+d128[8+o]]; \
+ Y = py_2[2*i+1]; \
+ acc |= (r[Y+d128[9+o]] + g[Y+d64[9+o]] + b[Y+d128[9+o]])<<4;\
+ dst_2[i]= acc;
+
+
+ RGB(0);
+ DST1bpp4(0,0);
+ DST2bpp4(0,0);
+
+ RGB(1);
+ DST2bpp4(1,2);
+ DST1bpp4(1,2);
+
+ RGB(2);
+ DST1bpp4(2,4);
+ DST2bpp4(2,4);
+
+ RGB(3);
+ DST2bpp4(3,6);
+ DST1bpp4(3,6);
+EPILOG(4)
+
+// This is exactly the same code as yuv2rgb_c_32 except for the types of
+// r, g, b, dst_1, dst_2
+PROLOG(yuv2rgb_c_4b, uint8_t)
+ RGB(0);
+ DST1(0);
+ DST2(0);
+
+ RGB(1);
+ DST2(1);
+ DST1(1);
+
+ RGB(2);
+ DST1(2);
+ DST2(2);
+
+ RGB(3);
+ DST2(3);
+ DST1(3);
+EPILOG(8)
+
+PROLOG(yuv2rgb_c_4b_ordered_dither, uint8_t)
+ const uint8_t *d64= dither_8x8_73[y&7];
+ const uint8_t *d128=dither_8x8_220[y&7];
+
+#define DST1bpp4b(i,o) \
+ Y = py_1[2*i]; \
+ dst_1[2*i] = r[Y+d128[0+o]] + g[Y+d64[0+o]] + b[Y+d128[0+o]]; \
+ Y = py_1[2*i+1]; \
+ dst_1[2*i+1] = r[Y+d128[1+o]] + g[Y+d64[1+o]] + b[Y+d128[1+o]];
+
+#define DST2bpp4b(i,o) \
+ Y = py_2[2*i]; \
+ dst_2[2*i] = r[Y+d128[8+o]] + g[Y+d64[8+o]] + b[Y+d128[8+o]]; \
+ Y = py_2[2*i+1]; \
+ dst_2[2*i+1] = r[Y+d128[9+o]] + g[Y+d64[9+o]] + b[Y+d128[9+o]];
+
+
+ RGB(0);
+ DST1bpp4b(0,0);
+ DST2bpp4b(0,0);
+
+ RGB(1);
+ DST2bpp4b(1,2);
+ DST1bpp4b(1,2);
+
+ RGB(2);
+ DST1bpp4b(2,4);
+ DST2bpp4b(2,4);
+
+ RGB(3);
+ DST2bpp4b(3,6);
+ DST1bpp4b(3,6);
+EPILOG(8)
+
+PROLOG(yuv2rgb_c_1_ordered_dither, uint8_t)
+ const uint8_t *d128=dither_8x8_220[y&7];
+ char out_1=0, out_2=0;
+ g= c->table_gU[128] + c->table_gV[128];
+
+#define DST1bpp1(i,o) \
+ Y = py_1[2*i]; \
+ out_1+= out_1 + g[Y+d128[0+o]]; \
+ Y = py_1[2*i+1]; \
+ out_1+= out_1 + g[Y+d128[1+o]];
+
+#define DST2bpp1(i,o) \
+ Y = py_2[2*i]; \
+ out_2+= out_2 + g[Y+d128[8+o]]; \
+ Y = py_2[2*i+1]; \
+ out_2+= out_2 + g[Y+d128[9+o]];
+
+ DST1bpp1(0,0);
+ DST2bpp1(0,0);
+
+ DST2bpp1(1,2);
+ DST1bpp1(1,2);
+
+ DST1bpp1(2,4);
+ DST2bpp1(2,4);
+
+ DST2bpp1(3,6);
+ DST1bpp1(3,6);
+
+ dst_1[0]= out_1;
+ dst_2[0]= out_2;
+EPILOG(1)
+
+SwsFunc yuv2rgb_get_func_ptr (SwsContext *c)
+{
+#if defined(HAVE_MMX2) || defined(HAVE_MMX)
+ if(c->flags & SWS_CPU_CAPS_MMX2){
+ switch(c->dstFormat){
+ case PIX_FMT_RGB32: return yuv420_rgb32_MMX2;
+ case PIX_FMT_BGR24: return yuv420_rgb24_MMX2;
+ case PIX_FMT_BGR565: return yuv420_rgb16_MMX2;
+ case PIX_FMT_BGR555: return yuv420_rgb15_MMX2;
+ }
+ }
+ if(c->flags & SWS_CPU_CAPS_MMX){
+ switch(c->dstFormat){
+ case PIX_FMT_RGB32: return yuv420_rgb32_MMX;
+ case PIX_FMT_BGR24: return yuv420_rgb24_MMX;
+ case PIX_FMT_BGR565: return yuv420_rgb16_MMX;
+ case PIX_FMT_BGR555: return yuv420_rgb15_MMX;
+ }
+ }
+#endif
+#ifdef HAVE_MLIB
+ {
+ SwsFunc t= yuv2rgb_init_mlib(c);
+ if(t) return t;
+ }
+#endif
+#ifdef HAVE_ALTIVEC
+ if (c->flags & SWS_CPU_CAPS_ALTIVEC)
+ {
+ SwsFunc t = yuv2rgb_init_altivec(c);
+ if(t) return t;
+ }
+#endif
+
+ av_log(c, AV_LOG_WARNING, "No accelerated colorspace conversion found\n");
+
+ switch(c->dstFormat){
+ case PIX_FMT_BGR32:
+ case PIX_FMT_RGB32: return yuv2rgb_c_32;
+ case PIX_FMT_RGB24: return yuv2rgb_c_24_rgb;
+ case PIX_FMT_BGR24: return yuv2rgb_c_24_bgr;
+ case PIX_FMT_RGB565:
+ case PIX_FMT_BGR565:
+ case PIX_FMT_RGB555:
+ case PIX_FMT_BGR555: return yuv2rgb_c_16;
+ case PIX_FMT_RGB8:
+ case PIX_FMT_BGR8: return yuv2rgb_c_8_ordered_dither;
+ case PIX_FMT_RGB4:
+ case PIX_FMT_BGR4: return yuv2rgb_c_4_ordered_dither;
+ case PIX_FMT_RGB4_BYTE:
+ case PIX_FMT_BGR4_BYTE: return yuv2rgb_c_4b_ordered_dither;
+ case PIX_FMT_MONOBLACK: return yuv2rgb_c_1_ordered_dither;
+ default:
+ assert(0);
+ }
+ return NULL;
+}
+
+static int div_round (int dividend, int divisor)
+{
+ if (dividend > 0)
+ return (dividend + (divisor>>1)) / divisor;
+ else
+ return -((-dividend + (divisor>>1)) / divisor);
+}
+
+int yuv2rgb_c_init_tables (SwsContext *c, const int inv_table[4], int fullRange, int brightness, int contrast, int saturation)
+{
+ const int isRgb = isBGR(c->dstFormat);
+ const int bpp = fmt_depth(c->dstFormat);
+ int i;
+ uint8_t table_Y[1024];
+ uint32_t *table_32 = 0;
+ uint16_t *table_16 = 0;
+ uint8_t *table_8 = 0;
+ uint8_t *table_332 = 0;
+ uint8_t *table_121 = 0;
+ uint8_t *table_1 = 0;
+ int entry_size = 0;
+ void *table_r = 0, *table_g = 0, *table_b = 0;
+ void *table_start;
+
+ 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;
+
+//printf("%lld %lld %lld %lld %lld\n", cy, crv, cbu, cgu, cgv);
+ if(!fullRange){
+ 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;
+//printf("%lld %lld %lld %lld %lld\n", cy, crv, cbu, cgu, cgv);
+ oy -= 256*brightness;
+
+ for (i = 0; i < 1024; i++) {
+ int j;
+
+ j= (cy*(((i - 384)<<16) - oy) + (1<<31))>>32;
+ j = (j < 0) ? 0 : ((j > 255) ? 255 : j);
+ table_Y[i] = j;
+ }
+
+ switch (bpp) {
+ case 32:
+ table_start= table_32 = av_malloc ((197 + 2*682 + 256 + 132) * sizeof (uint32_t));
+
+ entry_size = sizeof (uint32_t);
+ table_r = table_32 + 197;
+ table_b = table_32 + 197 + 685;
+ table_g = table_32 + 197 + 2*682;
+
+ for (i = -197; i < 256+197; i++)
+ ((uint32_t *)table_r)[i] = table_Y[i+384] << (isRgb ? 16 : 0);
+ for (i = -132; i < 256+132; i++)
+ ((uint32_t *)table_g)[i] = table_Y[i+384] << 8;
+ for (i = -232; i < 256+232; i++)
+ ((uint32_t *)table_b)[i] = table_Y[i+384] << (isRgb ? 0 : 16);
+ break;
+
+ case 24:
+ table_start= table_8 = av_malloc ((256 + 2*232) * sizeof (uint8_t));
+
+ entry_size = sizeof (uint8_t);
+ table_r = table_g = table_b = table_8 + 232;
+
+ for (i = -232; i < 256+232; i++)
+ ((uint8_t * )table_b)[i] = table_Y[i+384];
+ break;
+
+ case 15:
+ case 16:
+ table_start= table_16 = av_malloc ((197 + 2*682 + 256 + 132) * sizeof (uint16_t));
+
+ entry_size = sizeof (uint16_t);
+ table_r = table_16 + 197;
+ table_b = table_16 + 197 + 685;
+ table_g = table_16 + 197 + 2*682;
+
+ for (i = -197; i < 256+197; i++) {
+ int j = table_Y[i+384] >> 3;
+
+ if (isRgb)
+ j <<= ((bpp==16) ? 11 : 10);
+
+ ((uint16_t *)table_r)[i] = j;
+ }
+ for (i = -132; i < 256+132; i++) {
+ int j = table_Y[i+384] >> ((bpp==16) ? 2 : 3);
+
+ ((uint16_t *)table_g)[i] = j << 5;
+ }
+ for (i = -232; i < 256+232; i++) {
+ int j = table_Y[i+384] >> 3;
+
+ if (!isRgb)
+ j <<= ((bpp==16) ? 11 : 10);
+
+ ((uint16_t *)table_b)[i] = j;
+ }
+ break;
+
+ case 8:
+ table_start= table_332 = av_malloc ((197 + 2*682 + 256 + 132) * sizeof (uint8_t));
+
+ entry_size = sizeof (uint8_t);
+ table_r = table_332 + 197;
+ table_b = table_332 + 197 + 685;
+ table_g = table_332 + 197 + 2*682;
+
+ for (i = -197; i < 256+197; i++) {
+ int j = (table_Y[i+384 - 16] + 18)/36;
+
+ if (isRgb)
+ j <<= 5;
+
+ ((uint8_t *)table_r)[i] = j;
+ }
+ for (i = -132; i < 256+132; i++) {
+ int j = (table_Y[i+384 - 16] + 18)/36;
+
+ if (!isRgb)
+ j <<= 1;
+
+ ((uint8_t *)table_g)[i] = j << 2;
+ }
+ for (i = -232; i < 256+232; i++) {
+ int j = (table_Y[i+384 - 37] + 43)/85;
+
+ if (!isRgb)
+ j <<= 6;
+
+ ((uint8_t *)table_b)[i] = j;
+ }
+ break;
+ case 4:
+ case 4|128:
+ table_start= table_121 = av_malloc ((197 + 2*682 + 256 + 132) * sizeof (uint8_t));
+
+ entry_size = sizeof (uint8_t);
+ table_r = table_121 + 197;
+ table_b = table_121 + 197 + 685;
+ table_g = table_121 + 197 + 2*682;
+
+ for (i = -197; i < 256+197; i++) {
+ int j = table_Y[i+384 - 110] >> 7;
+
+ if (isRgb)
+ j <<= 3;
+
+ ((uint8_t *)table_r)[i] = j;
+ }
+ for (i = -132; i < 256+132; i++) {
+ int j = (table_Y[i+384 - 37]+ 43)/85;
+
+ ((uint8_t *)table_g)[i] = j << 1;
+ }
+ for (i = -232; i < 256+232; i++) {
+ int j =table_Y[i+384 - 110] >> 7;
+
+ if (!isRgb)
+ j <<= 3;
+
+ ((uint8_t *)table_b)[i] = j;
+ }
+ break;
+
+ case 1:
+ table_start= table_1 = av_malloc (256*2 * sizeof (uint8_t));
+
+ entry_size = sizeof (uint8_t);
+ table_g = table_1;
+ table_r = table_b = NULL;
+
+ for (i = 0; i < 256+256; i++) {
+ int j = table_Y[i + 384 - 110]>>7;
+
+ ((uint8_t *)table_g)[i] = j;
+ }
+ break;
+
+ default:
+ table_start= NULL;
+ av_log(c, AV_LOG_ERROR, "%ibpp not supported by yuv2rgb\n", bpp);
+ //free mem?
+ return -1;
+ }
+
+ for (i = 0; i < 256; i++) {
+ c->table_rV[i] = (uint8_t *)table_r + entry_size * div_round (crv * (i-128), 76309);
+ c->table_gU[i] = (uint8_t *)table_g + entry_size * div_round (cgu * (i-128), 76309);
+ c->table_gV[i] = entry_size * div_round (cgv * (i-128), 76309);
+ c->table_bU[i] = (uint8_t *)table_b + entry_size * div_round (cbu * (i-128), 76309);
+ }
+
+ av_free(c->yuvTable);
+ c->yuvTable= table_start;
+ return 0;
+}
diff --git a/contrib/ffmpeg/libswscale/yuv2rgb_altivec.c b/contrib/ffmpeg/libswscale/yuv2rgb_altivec.c
new file mode 100644
index 000000000..72e418e8d
--- /dev/null
+++ b/contrib/ffmpeg/libswscale/yuv2rgb_altivec.c
@@ -0,0 +1,963 @@
+/*
+ marc.hoffman@analog.com March 8, 2004
+
+ Altivec Acceleration for Color Space Conversion revision 0.2
+
+ convert I420 YV12 to RGB in various formats,
+ it rejects images that are not in 420 formats
+ it rejects images that don't have widths of multiples of 16
+ it rejects images that don't have heights of multiples of 2
+ reject defers to C simulation codes.
+
+ lots of optimizations to be done here
+
+ 1. need to fix saturation code, I just couldn't get it to fly with packs and adds.
+ so we currently use max min to clip
+
+ 2. the inefficient use of chroma loading needs a bit of brushing up
+
+ 3. analysis of pipeline stalls needs to be done, use shark to identify pipeline stalls
+
+
+ MODIFIED to calculate coeffs from currently selected color space.
+ MODIFIED core to be a macro which you spec the output format.
+ ADDED UYVY conversion which is never called due to some thing in SWSCALE.
+ CORRECTED algorithim selection to be strict on input formats.
+ ADDED runtime detection of altivec.
+
+ ADDED altivec_yuv2packedX vertical scl + RGB converter
+
+ March 27,2004
+ PERFORMANCE ANALYSIS
+
+ The C version use 25% of the processor or ~250Mips for D1 video rawvideo used as test
+ The ALTIVEC version uses 10% of the processor or ~100Mips for D1 video same sequence
+
+ 720*480*30 ~10MPS
+
+ so we have roughly 10clocks per pixel this is too high something has to be wrong.
+
+ OPTIMIZED clip codes to utilize vec_max and vec_packs removing the need for vec_min.
+
+ OPTIMIZED DST OUTPUT cache/dma controls. we are pretty much
+ guaranteed to have the input video frame it was just decompressed so
+ it probably resides in L1 caches. However we are creating the
+ output video stream this needs to use the DSTST instruction to
+ optimize for the cache. We couple this with the fact that we are
+ not going to be visiting the input buffer again so we mark it Least
+ Recently Used. This shaves 25% of the processor cycles off.
+
+ Now MEMCPY is the largest mips consumer in the system, probably due
+ to the inefficient X11 stuff.
+
+ GL libraries seem to be very slow on this machine 1.33Ghz PB running
+ Jaguar, this is not the case for my 1Ghz PB. I thought it might be
+ a versioning issues, however i have libGL.1.2.dylib for both
+ machines. ((We need to figure this out now))
+
+ GL2 libraries work now with patch for RGB32
+
+ NOTE quartz vo driver ARGB32_to_RGB24 consumes 30% of the processor
+
+ Integrated luma prescaling adjustment for saturation/contrast/brightness adjustment.
+*/
+
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include <assert.h>
+#include "config.h"
+#ifdef HAVE_MALLOC_H
+#include <malloc.h>
+#endif
+#include "rgb2rgb.h"
+#include "swscale.h"
+#include "swscale_internal.h"
+
+#undef PROFILE_THE_BEAST
+#undef INC_SCALING
+
+typedef unsigned char ubyte;
+typedef signed char sbyte;
+
+
+/* RGB interleaver, 16 planar pels 8-bit samples per channel in
+ homogeneous vector registers x0,x1,x2 are interleaved with the
+ following technique:
+
+ o0 = vec_mergeh (x0,x1);
+ o1 = vec_perm (o0, x2, perm_rgb_0);
+ o2 = vec_perm (o0, x2, perm_rgb_1);
+ o3 = vec_mergel (x0,x1);
+ o4 = vec_perm (o3,o2,perm_rgb_2);
+ o5 = vec_perm (o3,o2,perm_rgb_3);
+
+ perm_rgb_0: o0(RG).h v1(B) --> o1*
+ 0 1 2 3 4
+ rgbr|gbrg|brgb|rgbr
+ 0010 0100 1001 0010
+ 0102 3145 2673 894A
+
+ perm_rgb_1: o0(RG).h v1(B) --> o2
+ 0 1 2 3 4
+ gbrg|brgb|bbbb|bbbb
+ 0100 1001 1111 1111
+ B5CD 6EF7 89AB CDEF
+
+ perm_rgb_2: o3(RG).l o2(rgbB.l) --> o4*
+ 0 1 2 3 4
+ gbrg|brgb|rgbr|gbrg
+ 1111 1111 0010 0100
+ 89AB CDEF 0182 3945
+
+ perm_rgb_2: o3(RG).l o2(rgbB.l) ---> o5*
+ 0 1 2 3 4
+ brgb|rgbr|gbrg|brgb
+ 1001 0010 0100 1001
+ a67b 89cA BdCD eEFf
+
+*/
+static
+const vector unsigned char
+ perm_rgb_0 = (const vector unsigned char)AVV(0x00,0x01,0x10,0x02,0x03,0x11,0x04,0x05,
+ 0x12,0x06,0x07,0x13,0x08,0x09,0x14,0x0a),
+ perm_rgb_1 = (const vector unsigned char)AVV(0x0b,0x15,0x0c,0x0d,0x16,0x0e,0x0f,0x17,
+ 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f),
+ perm_rgb_2 = (const vector unsigned char)AVV(0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,
+ 0x00,0x01,0x18,0x02,0x03,0x19,0x04,0x05),
+ perm_rgb_3 = (const vector unsigned char)AVV(0x1a,0x06,0x07,0x1b,0x08,0x09,0x1c,0x0a,
+ 0x0b,0x1d,0x0c,0x0d,0x1e,0x0e,0x0f,0x1f);
+
+#define vec_merge3(x2,x1,x0,y0,y1,y2) \
+do { \
+ typeof(x0) o0,o2,o3; \
+ o0 = vec_mergeh (x0,x1); \
+ y0 = vec_perm (o0, x2, perm_rgb_0);\
+ o2 = vec_perm (o0, x2, perm_rgb_1);\
+ o3 = vec_mergel (x0,x1); \
+ y1 = vec_perm (o3,o2,perm_rgb_2); \
+ y2 = vec_perm (o3,o2,perm_rgb_3); \
+} while(0)
+
+#define vec_mstbgr24(x0,x1,x2,ptr) \
+do { \
+ typeof(x0) _0,_1,_2; \
+ vec_merge3 (x0,x1,x2,_0,_1,_2); \
+ vec_st (_0, 0, ptr++); \
+ vec_st (_1, 0, ptr++); \
+ vec_st (_2, 0, ptr++); \
+} while (0);
+
+#define vec_mstrgb24(x0,x1,x2,ptr) \
+do { \
+ typeof(x0) _0,_1,_2; \
+ vec_merge3 (x2,x1,x0,_0,_1,_2); \
+ vec_st (_0, 0, ptr++); \
+ vec_st (_1, 0, ptr++); \
+ vec_st (_2, 0, ptr++); \
+} while (0);
+
+/* pack the pixels in rgb0 format
+ msb R
+ lsb 0
+*/
+#define vec_mstrgb32(T,x0,x1,x2,x3,ptr) \
+do { \
+ T _0,_1,_2,_3; \
+ _0 = vec_mergeh (x0,x1); \
+ _1 = vec_mergeh (x2,x3); \
+ _2 = (T)vec_mergeh ((vector unsigned short)_0,(vector unsigned short)_1); \
+ _3 = (T)vec_mergel ((vector unsigned short)_0,(vector unsigned short)_1); \
+ vec_st (_2, 0*16, (T *)ptr); \
+ vec_st (_3, 1*16, (T *)ptr); \
+ _0 = vec_mergel (x0,x1); \
+ _1 = vec_mergel (x2,x3); \
+ _2 = (T)vec_mergeh ((vector unsigned short)_0,(vector unsigned short)_1); \
+ _3 = (T)vec_mergel ((vector unsigned short)_0,(vector unsigned short)_1); \
+ vec_st (_2, 2*16, (T *)ptr); \
+ vec_st (_3, 3*16, (T *)ptr); \
+ ptr += 4; \
+} while (0);
+
+/*
+
+ | 1 0 1.4021 | | Y |
+ | 1 -0.3441 -0.7142 |x| Cb|
+ | 1 1.7718 0 | | Cr|
+
+
+ Y: [-128 127]
+ Cb/Cr : [-128 127]
+
+ typical yuv conversion work on Y: 0-255 this version has been optimized for jpeg decode.
+
+*/
+
+
+
+
+#define vec_unh(x) \
+ (vector signed short) \
+ vec_perm(x,(typeof(x))AVV(0),\
+ (vector unsigned char)AVV(0x10,0x00,0x10,0x01,0x10,0x02,0x10,0x03,\
+ 0x10,0x04,0x10,0x05,0x10,0x06,0x10,0x07))
+#define vec_unl(x) \
+ (vector signed short) \
+ vec_perm(x,(typeof(x))AVV(0),\
+ (vector unsigned char)AVV(0x10,0x08,0x10,0x09,0x10,0x0A,0x10,0x0B,\
+ 0x10,0x0C,0x10,0x0D,0x10,0x0E,0x10,0x0F))
+
+#define vec_clip_s16(x) \
+ vec_max (vec_min (x, (vector signed short)AVV(235,235,235,235,235,235,235,235)),\
+ (vector signed short)AVV(16, 16, 16, 16, 16, 16, 16, 16 ))
+
+#define vec_packclp(x,y) \
+ (vector unsigned char)vec_packs \
+ ((vector unsigned short)vec_max (x,(vector signed short) AVV(0)), \
+ (vector unsigned short)vec_max (y,(vector signed short) AVV(0)))
+
+//#define out_pixels(a,b,c,ptr) vec_mstrgb32(typeof(a),((typeof (a))AVV(0)),a,a,a,ptr)
+
+
+static inline void cvtyuvtoRGB (SwsContext *c,
+ vector signed short Y, vector signed short U, vector signed short V,
+ vector signed short *R, vector signed short *G, vector signed short *B)
+{
+ vector signed short vx,ux,uvx;
+
+ Y = vec_mradds (Y, c->CY, c->OY);
+ U = vec_sub (U,(vector signed short)
+ vec_splat((vector signed short)AVV(128),0));
+ V = vec_sub (V,(vector signed short)
+ vec_splat((vector signed short)AVV(128),0));
+
+ // ux = (CBU*(u<<c->CSHIFT)+0x4000)>>15;
+ ux = vec_sl (U, c->CSHIFT);
+ *B = vec_mradds (ux, c->CBU, Y);
+
+ // vx = (CRV*(v<<c->CSHIFT)+0x4000)>>15;
+ vx = vec_sl (V, c->CSHIFT);
+ *R = vec_mradds (vx, c->CRV, Y);
+
+ // uvx = ((CGU*u) + (CGV*v))>>15;
+ uvx = vec_mradds (U, c->CGU, Y);
+ *G = vec_mradds (V, c->CGV, uvx);
+}
+
+
+/*
+ ------------------------------------------------------------------------------
+ CS converters
+ ------------------------------------------------------------------------------
+*/
+
+
+#define DEFCSP420_CVT(name,out_pixels) \
+static int altivec_##name (SwsContext *c, \
+ unsigned char **in, int *instrides, \
+ int srcSliceY, int srcSliceH, \
+ unsigned char **oplanes, int *outstrides) \
+{ \
+ int w = c->srcW; \
+ int h = srcSliceH; \
+ int i,j; \
+ int instrides_scl[3]; \
+ vector unsigned char y0,y1; \
+ \
+ vector signed char u,v; \
+ \
+ vector signed short Y0,Y1,Y2,Y3; \
+ vector signed short U,V; \
+ vector signed short vx,ux,uvx; \
+ vector signed short vx0,ux0,uvx0; \
+ vector signed short vx1,ux1,uvx1; \
+ vector signed short R0,G0,B0; \
+ vector signed short R1,G1,B1; \
+ vector unsigned char R,G,B; \
+ \
+ vector unsigned char *y1ivP, *y2ivP, *uivP, *vivP; \
+ vector unsigned char align_perm; \
+ \
+ vector signed short \
+ lCY = c->CY, \
+ lOY = c->OY, \
+ lCRV = c->CRV, \
+ lCBU = c->CBU, \
+ lCGU = c->CGU, \
+ lCGV = c->CGV; \
+ \
+ vector unsigned short lCSHIFT = c->CSHIFT; \
+ \
+ ubyte *y1i = in[0]; \
+ ubyte *y2i = in[0]+instrides[0]; \
+ ubyte *ui = in[1]; \
+ ubyte *vi = in[2]; \
+ \
+ vector unsigned char *oute \
+ = (vector unsigned char *) \
+ (oplanes[0]+srcSliceY*outstrides[0]); \
+ vector unsigned char *outo \
+ = (vector unsigned char *) \
+ (oplanes[0]+srcSliceY*outstrides[0]+outstrides[0]); \
+ \
+ \
+ instrides_scl[0] = instrides[0]*2-w; /* the loop moves y{1,2}i by w */ \
+ instrides_scl[1] = instrides[1]-w/2; /* the loop moves ui by w/2 */ \
+ instrides_scl[2] = instrides[2]-w/2; /* the loop moves vi by w/2 */ \
+ \
+ \
+ for (i=0;i<h/2;i++) { \
+ vec_dstst (outo, (0x02000002|(((w*3+32)/32)<<16)), 0); \
+ vec_dstst (oute, (0x02000002|(((w*3+32)/32)<<16)), 1); \
+ \
+ for (j=0;j<w/16;j++) { \
+ \
+ y1ivP = (vector unsigned char *)y1i; \
+ y2ivP = (vector unsigned char *)y2i; \
+ uivP = (vector unsigned char *)ui; \
+ vivP = (vector unsigned char *)vi; \
+ \
+ align_perm = vec_lvsl (0, y1i); \
+ y0 = (vector unsigned char)vec_perm (y1ivP[0], y1ivP[1], align_perm);\
+ \
+ align_perm = vec_lvsl (0, y2i); \
+ y1 = (vector unsigned char)vec_perm (y2ivP[0], y2ivP[1], align_perm);\
+ \
+ align_perm = vec_lvsl (0, ui); \
+ u = (vector signed char)vec_perm (uivP[0], uivP[1], align_perm); \
+ \
+ align_perm = vec_lvsl (0, vi); \
+ v = (vector signed char)vec_perm (vivP[0], vivP[1], align_perm); \
+ \
+ u = (vector signed char) \
+ vec_sub (u,(vector signed char) \
+ vec_splat((vector signed char)AVV(128),0));\
+ v = (vector signed char) \
+ vec_sub (v,(vector signed char) \
+ vec_splat((vector signed char)AVV(128),0));\
+ \
+ U = vec_unpackh (u); \
+ V = vec_unpackh (v); \
+ \
+ \
+ Y0 = vec_unh (y0); \
+ Y1 = vec_unl (y0); \
+ Y2 = vec_unh (y1); \
+ Y3 = vec_unl (y1); \
+ \
+ Y0 = vec_mradds (Y0, lCY, lOY); \
+ Y1 = vec_mradds (Y1, lCY, lOY); \
+ Y2 = vec_mradds (Y2, lCY, lOY); \
+ Y3 = vec_mradds (Y3, lCY, lOY); \
+ \
+ /* ux = (CBU*(u<<CSHIFT)+0x4000)>>15 */ \
+ ux = vec_sl (U, lCSHIFT); \
+ ux = vec_mradds (ux, lCBU, (vector signed short)AVV(0)); \
+ ux0 = vec_mergeh (ux,ux); \
+ ux1 = vec_mergel (ux,ux); \
+ \
+ /* vx = (CRV*(v<<CSHIFT)+0x4000)>>15; */ \
+ vx = vec_sl (V, lCSHIFT); \
+ vx = vec_mradds (vx, lCRV, (vector signed short)AVV(0)); \
+ vx0 = vec_mergeh (vx,vx); \
+ vx1 = vec_mergel (vx,vx); \
+ \
+ /* uvx = ((CGU*u) + (CGV*v))>>15 */ \
+ uvx = vec_mradds (U, lCGU, (vector signed short)AVV(0)); \
+ uvx = vec_mradds (V, lCGV, uvx); \
+ uvx0 = vec_mergeh (uvx,uvx); \
+ uvx1 = vec_mergel (uvx,uvx); \
+ \
+ R0 = vec_add (Y0,vx0); \
+ G0 = vec_add (Y0,uvx0); \
+ B0 = vec_add (Y0,ux0); \
+ R1 = vec_add (Y1,vx1); \
+ G1 = vec_add (Y1,uvx1); \
+ B1 = vec_add (Y1,ux1); \
+ \
+ R = vec_packclp (R0,R1); \
+ G = vec_packclp (G0,G1); \
+ B = vec_packclp (B0,B1); \
+ \
+ out_pixels(R,G,B,oute); \
+ \
+ R0 = vec_add (Y2,vx0); \
+ G0 = vec_add (Y2,uvx0); \
+ B0 = vec_add (Y2,ux0); \
+ R1 = vec_add (Y3,vx1); \
+ G1 = vec_add (Y3,uvx1); \
+ B1 = vec_add (Y3,ux1); \
+ R = vec_packclp (R0,R1); \
+ G = vec_packclp (G0,G1); \
+ B = vec_packclp (B0,B1); \
+ \
+ \
+ out_pixels(R,G,B,outo); \
+ \
+ y1i += 16; \
+ y2i += 16; \
+ ui += 8; \
+ vi += 8; \
+ \
+ } \
+ \
+ outo += (outstrides[0])>>4; \
+ oute += (outstrides[0])>>4; \
+ \
+ ui += instrides_scl[1]; \
+ vi += instrides_scl[2]; \
+ y1i += instrides_scl[0]; \
+ y2i += instrides_scl[0]; \
+ } \
+ return srcSliceH; \
+}
+
+
+#define out_abgr(a,b,c,ptr) vec_mstrgb32(typeof(a),((typeof (a))AVV(0)),c,b,a,ptr)
+#define out_bgra(a,b,c,ptr) vec_mstrgb32(typeof(a),c,b,a,((typeof (a))AVV(0)),ptr)
+#define out_rgba(a,b,c,ptr) vec_mstrgb32(typeof(a),a,b,c,((typeof (a))AVV(0)),ptr)
+#define out_argb(a,b,c,ptr) vec_mstrgb32(typeof(a),((typeof (a))AVV(0)),a,b,c,ptr)
+#define out_rgb24(a,b,c,ptr) vec_mstrgb24(a,b,c,ptr)
+#define out_bgr24(a,b,c,ptr) vec_mstbgr24(a,b,c,ptr)
+
+DEFCSP420_CVT (yuv2_abgr, out_abgr)
+#if 1
+DEFCSP420_CVT (yuv2_bgra, out_bgra)
+#else
+static int altivec_yuv2_bgra32 (SwsContext *c,
+ unsigned char **in, int *instrides,
+ int srcSliceY, int srcSliceH,
+ unsigned char **oplanes, int *outstrides)
+{
+ int w = c->srcW;
+ int h = srcSliceH;
+ int i,j;
+ int instrides_scl[3];
+ vector unsigned char y0,y1;
+
+ vector signed char u,v;
+
+ vector signed short Y0,Y1,Y2,Y3;
+ vector signed short U,V;
+ vector signed short vx,ux,uvx;
+ vector signed short vx0,ux0,uvx0;
+ vector signed short vx1,ux1,uvx1;
+ vector signed short R0,G0,B0;
+ vector signed short R1,G1,B1;
+ vector unsigned char R,G,B;
+
+ vector unsigned char *uivP, *vivP;
+ vector unsigned char align_perm;
+
+ vector signed short
+ lCY = c->CY,
+ lOY = c->OY,
+ lCRV = c->CRV,
+ lCBU = c->CBU,
+ lCGU = c->CGU,
+ lCGV = c->CGV;
+
+ vector unsigned short lCSHIFT = c->CSHIFT;
+
+ ubyte *y1i = in[0];
+ ubyte *y2i = in[0]+w;
+ ubyte *ui = in[1];
+ ubyte *vi = in[2];
+
+ vector unsigned char *oute
+ = (vector unsigned char *)
+ (oplanes[0]+srcSliceY*outstrides[0]);
+ vector unsigned char *outo
+ = (vector unsigned char *)
+ (oplanes[0]+srcSliceY*outstrides[0]+outstrides[0]);
+
+
+ instrides_scl[0] = instrides[0];
+ instrides_scl[1] = instrides[1]-w/2; /* the loop moves ui by w/2 */
+ instrides_scl[2] = instrides[2]-w/2; /* the loop moves vi by w/2 */
+
+
+ for (i=0;i<h/2;i++) {
+ vec_dstst (outo, (0x02000002|(((w*3+32)/32)<<16)), 0);
+ vec_dstst (oute, (0x02000002|(((w*3+32)/32)<<16)), 1);
+
+ for (j=0;j<w/16;j++) {
+
+ y0 = vec_ldl (0,y1i);
+ y1 = vec_ldl (0,y2i);
+ uivP = (vector unsigned char *)ui;
+ vivP = (vector unsigned char *)vi;
+
+ align_perm = vec_lvsl (0, ui);
+ u = (vector signed char)vec_perm (uivP[0], uivP[1], align_perm);
+
+ align_perm = vec_lvsl (0, vi);
+ v = (vector signed char)vec_perm (vivP[0], vivP[1], align_perm);
+ u = (vector signed char)
+ vec_sub (u,(vector signed char)
+ vec_splat((vector signed char)AVV(128),0));
+
+ v = (vector signed char)
+ vec_sub (v, (vector signed char)
+ vec_splat((vector signed char)AVV(128),0));
+
+ U = vec_unpackh (u);
+ V = vec_unpackh (v);
+
+
+ Y0 = vec_unh (y0);
+ Y1 = vec_unl (y0);
+ Y2 = vec_unh (y1);
+ Y3 = vec_unl (y1);
+
+ Y0 = vec_mradds (Y0, lCY, lOY);
+ Y1 = vec_mradds (Y1, lCY, lOY);
+ Y2 = vec_mradds (Y2, lCY, lOY);
+ Y3 = vec_mradds (Y3, lCY, lOY);
+
+ /* ux = (CBU*(u<<CSHIFT)+0x4000)>>15 */
+ ux = vec_sl (U, lCSHIFT);
+ ux = vec_mradds (ux, lCBU, (vector signed short)AVV(0));
+ ux0 = vec_mergeh (ux,ux);
+ ux1 = vec_mergel (ux,ux);
+
+ /* vx = (CRV*(v<<CSHIFT)+0x4000)>>15; */
+ vx = vec_sl (V, lCSHIFT);
+ vx = vec_mradds (vx, lCRV, (vector signed short)AVV(0));
+ vx0 = vec_mergeh (vx,vx);
+ vx1 = vec_mergel (vx,vx);
+ /* uvx = ((CGU*u) + (CGV*v))>>15 */
+ uvx = vec_mradds (U, lCGU, (vector signed short)AVV(0));
+ uvx = vec_mradds (V, lCGV, uvx);
+ uvx0 = vec_mergeh (uvx,uvx);
+ uvx1 = vec_mergel (uvx,uvx);
+ R0 = vec_add (Y0,vx0);
+ G0 = vec_add (Y0,uvx0);
+ B0 = vec_add (Y0,ux0);
+ R1 = vec_add (Y1,vx1);
+ G1 = vec_add (Y1,uvx1);
+ B1 = vec_add (Y1,ux1);
+ R = vec_packclp (R0,R1);
+ G = vec_packclp (G0,G1);
+ B = vec_packclp (B0,B1);
+
+ out_argb(R,G,B,oute);
+ R0 = vec_add (Y2,vx0);
+ G0 = vec_add (Y2,uvx0);
+ B0 = vec_add (Y2,ux0);
+ R1 = vec_add (Y3,vx1);
+ G1 = vec_add (Y3,uvx1);
+ B1 = vec_add (Y3,ux1);
+ R = vec_packclp (R0,R1);
+ G = vec_packclp (G0,G1);
+ B = vec_packclp (B0,B1);
+
+ out_argb(R,G,B,outo);
+ y1i += 16;
+ y2i += 16;
+ ui += 8;
+ vi += 8;
+
+ }
+
+ outo += (outstrides[0])>>4;
+ oute += (outstrides[0])>>4;
+
+ ui += instrides_scl[1];
+ vi += instrides_scl[2];
+ y1i += instrides_scl[0];
+ y2i += instrides_scl[0];
+ }
+ return srcSliceH;
+}
+
+#endif
+
+
+DEFCSP420_CVT (yuv2_rgba, out_rgba)
+DEFCSP420_CVT (yuv2_argb, out_argb)
+DEFCSP420_CVT (yuv2_rgb24, out_rgb24)
+DEFCSP420_CVT (yuv2_bgr24, out_bgr24)
+
+
+// uyvy|uyvy|uyvy|uyvy
+// 0123 4567 89ab cdef
+static
+const vector unsigned char
+ demux_u = (const vector unsigned char)AVV(0x10,0x00,0x10,0x00,
+ 0x10,0x04,0x10,0x04,
+ 0x10,0x08,0x10,0x08,
+ 0x10,0x0c,0x10,0x0c),
+ demux_v = (const vector unsigned char)AVV(0x10,0x02,0x10,0x02,
+ 0x10,0x06,0x10,0x06,
+ 0x10,0x0A,0x10,0x0A,
+ 0x10,0x0E,0x10,0x0E),
+ demux_y = (const vector unsigned char)AVV(0x10,0x01,0x10,0x03,
+ 0x10,0x05,0x10,0x07,
+ 0x10,0x09,0x10,0x0B,
+ 0x10,0x0D,0x10,0x0F);
+
+/*
+ this is so I can play live CCIR raw video
+*/
+static int altivec_uyvy_rgb32 (SwsContext *c,
+ unsigned char **in, int *instrides,
+ int srcSliceY, int srcSliceH,
+ unsigned char **oplanes, int *outstrides)
+{
+ int w = c->srcW;
+ int h = srcSliceH;
+ int i,j;
+ vector unsigned char uyvy;
+ vector signed short Y,U,V;
+ vector signed short R0,G0,B0,R1,G1,B1;
+ vector unsigned char R,G,B;
+ vector unsigned char *out;
+ ubyte *img;
+
+ img = in[0];
+ out = (vector unsigned char *)(oplanes[0]+srcSliceY*outstrides[0]);
+
+ for (i=0;i<h;i++) {
+ for (j=0;j<w/16;j++) {
+ uyvy = vec_ld (0, img);
+ U = (vector signed short)
+ vec_perm (uyvy, (vector unsigned char)AVV(0), demux_u);
+
+ V = (vector signed short)
+ vec_perm (uyvy, (vector unsigned char)AVV(0), demux_v);
+
+ Y = (vector signed short)
+ vec_perm (uyvy, (vector unsigned char)AVV(0), demux_y);
+
+ cvtyuvtoRGB (c, Y,U,V,&R0,&G0,&B0);
+
+ uyvy = vec_ld (16, img);
+ U = (vector signed short)
+ vec_perm (uyvy, (vector unsigned char)AVV(0), demux_u);
+
+ V = (vector signed short)
+ vec_perm (uyvy, (vector unsigned char)AVV(0), demux_v);
+
+ Y = (vector signed short)
+ vec_perm (uyvy, (vector unsigned char)AVV(0), demux_y);
+
+ cvtyuvtoRGB (c, Y,U,V,&R1,&G1,&B1);
+
+ R = vec_packclp (R0,R1);
+ G = vec_packclp (G0,G1);
+ B = vec_packclp (B0,B1);
+
+ // vec_mstbgr24 (R,G,B, out);
+ out_rgba (R,G,B,out);
+
+ img += 32;
+ }
+ }
+ return srcSliceH;
+}
+
+
+
+/* Ok currently the acceleration routine only supports
+ inputs of widths a multiple of 16
+ and heights a multiple 2
+
+ So we just fall back to the C codes for this.
+*/
+SwsFunc yuv2rgb_init_altivec (SwsContext *c)
+{
+ if (!(c->flags & SWS_CPU_CAPS_ALTIVEC))
+ return NULL;
+
+ /*
+ and this seems not to matter too much I tried a bunch of
+ videos with abnormal widths and mplayer crashes else where.
+ mplayer -vo x11 -rawvideo on:w=350:h=240 raw-350x240.eyuv
+ boom with X11 bad match.
+
+ */
+ if ((c->srcW & 0xf) != 0) return NULL;
+
+ switch (c->srcFormat) {
+ case PIX_FMT_YUV410P:
+ case PIX_FMT_YUV420P:
+ /*case IMGFMT_CLPL: ??? */
+ case PIX_FMT_GRAY8:
+ case PIX_FMT_NV12:
+ case PIX_FMT_NV21:
+ if ((c->srcH & 0x1) != 0)
+ return NULL;
+
+ switch(c->dstFormat){
+ case PIX_FMT_RGB24:
+ av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space RGB24\n");
+ return altivec_yuv2_rgb24;
+ case PIX_FMT_BGR24:
+ av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space BGR24\n");
+ return altivec_yuv2_bgr24;
+ case PIX_FMT_ARGB:
+ av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space ARGB\n");
+ return altivec_yuv2_argb;
+ case PIX_FMT_ABGR:
+ av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space ABGR\n");
+ return altivec_yuv2_abgr;
+ case PIX_FMT_RGBA:
+ av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space RGBA\n");
+ return altivec_yuv2_rgba;
+ case PIX_FMT_BGRA:
+ av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space BGRA\n");
+ return altivec_yuv2_bgra;
+ default: return NULL;
+ }
+ break;
+
+ case PIX_FMT_UYVY422:
+ switch(c->dstFormat){
+ case PIX_FMT_BGR32:
+ av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space UYVY -> RGB32\n");
+ return altivec_uyvy_rgb32;
+ default: return NULL;
+ }
+ break;
+
+ }
+ return NULL;
+}
+
+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;
+}
+
+void yuv2rgb_altivec_init_tables (SwsContext *c, const int inv_table[4],int brightness,int contrast, int saturation)
+{
+ union {
+ signed short tmp[8] __attribute__ ((aligned(16)));
+ vector signed short vec;
+ } buf;
+
+ buf.tmp[0] = ( (0xffffLL) * contrast>>8 )>>9; //cy
+ buf.tmp[1] = -256*brightness; //oy
+ buf.tmp[2] = (inv_table[0]>>3) *(contrast>>16)*(saturation>>16); //crv
+ buf.tmp[3] = (inv_table[1]>>3) *(contrast>>16)*(saturation>>16); //cbu
+ buf.tmp[4] = -((inv_table[2]>>1)*(contrast>>16)*(saturation>>16)); //cgu
+ buf.tmp[5] = -((inv_table[3]>>1)*(contrast>>16)*(saturation>>16)); //cgv
+
+
+ c->CSHIFT = (vector unsigned short)vec_splat_u16(2);
+ c->CY = vec_splat ((vector signed short)buf.vec, 0);
+ c->OY = vec_splat ((vector signed short)buf.vec, 1);
+ c->CRV = vec_splat ((vector signed short)buf.vec, 2);
+ c->CBU = vec_splat ((vector signed short)buf.vec, 3);
+ c->CGU = vec_splat ((vector signed short)buf.vec, 4);
+ c->CGV = vec_splat ((vector signed short)buf.vec, 5);
+#if 0
+{
+int i;
+char *v[6]={"cy","oy","crv","cbu","cgu","cgv"};
+for (i=0; i<6;i++)
+ printf("%s %d ", v[i],buf.tmp[i] );
+ printf("\n");
+}
+#endif
+ return;
+}
+
+
+void
+altivec_yuv2packedX (SwsContext *c,
+ int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize,
+ int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize,
+ uint8_t *dest, int dstW, int dstY)
+{
+ int i,j;
+ vector signed short X,X0,X1,Y0,U0,V0,Y1,U1,V1,U,V;
+ vector signed short R0,G0,B0,R1,G1,B1;
+
+ vector unsigned char R,G,B;
+ vector unsigned char *out,*nout;
+
+ vector signed short RND = vec_splat_s16(1<<3);
+ vector unsigned short SCL = vec_splat_u16(4);
+ unsigned long scratch[16] __attribute__ ((aligned (16)));
+
+ vector signed short *YCoeffs, *CCoeffs;
+
+ YCoeffs = c->vYCoeffsBank+dstY*lumFilterSize;
+ CCoeffs = c->vCCoeffsBank+dstY*chrFilterSize;
+
+ out = (vector unsigned char *)dest;
+
+ for(i=0; i<dstW; i+=16){
+ Y0 = RND;
+ Y1 = RND;
+ /* extract 16 coeffs from lumSrc */
+ for(j=0; j<lumFilterSize; j++) {
+ X0 = vec_ld (0, &lumSrc[j][i]);
+ X1 = vec_ld (16, &lumSrc[j][i]);
+ Y0 = vec_mradds (X0, YCoeffs[j], Y0);
+ Y1 = vec_mradds (X1, YCoeffs[j], Y1);
+ }
+
+ U = RND;
+ V = RND;
+ /* extract 8 coeffs from U,V */
+ for(j=0; j<chrFilterSize; j++) {
+ X = vec_ld (0, &chrSrc[j][i/2]);
+ U = vec_mradds (X, CCoeffs[j], U);
+ X = vec_ld (0, &chrSrc[j][i/2+2048]);
+ V = vec_mradds (X, CCoeffs[j], V);
+ }
+
+ /* scale and clip signals */
+ Y0 = vec_sra (Y0, SCL);
+ Y1 = vec_sra (Y1, SCL);
+ U = vec_sra (U, SCL);
+ V = vec_sra (V, SCL);
+
+ Y0 = vec_clip_s16 (Y0);
+ Y1 = vec_clip_s16 (Y1);
+ U = vec_clip_s16 (U);
+ V = vec_clip_s16 (V);
+
+ /* now we have
+ Y0= y0 y1 y2 y3 y4 y5 y6 y7 Y1= y8 y9 y10 y11 y12 y13 y14 y15
+ U= u0 u1 u2 u3 u4 u5 u6 u7 V= v0 v1 v2 v3 v4 v5 v6 v7
+
+ Y0= y0 y1 y2 y3 y4 y5 y6 y7 Y1= y8 y9 y10 y11 y12 y13 y14 y15
+ U0= u0 u0 u1 u1 u2 u2 u3 u3 U1= u4 u4 u5 u5 u6 u6 u7 u7
+ V0= v0 v0 v1 v1 v2 v2 v3 v3 V1= v4 v4 v5 v5 v6 v6 v7 v7
+ */
+
+ U0 = vec_mergeh (U,U);
+ V0 = vec_mergeh (V,V);
+
+ U1 = vec_mergel (U,U);
+ V1 = vec_mergel (V,V);
+
+ cvtyuvtoRGB (c, Y0,U0,V0,&R0,&G0,&B0);
+ cvtyuvtoRGB (c, Y1,U1,V1,&R1,&G1,&B1);
+
+ R = vec_packclp (R0,R1);
+ G = vec_packclp (G0,G1);
+ B = vec_packclp (B0,B1);
+
+ switch(c->dstFormat) {
+ case PIX_FMT_ABGR: out_abgr (R,G,B,out); break;
+ case PIX_FMT_BGRA: out_bgra (R,G,B,out); break;
+ case PIX_FMT_RGBA: out_rgba (R,G,B,out); break;
+ case PIX_FMT_ARGB: out_argb (R,G,B,out); break;
+ case PIX_FMT_RGB24: out_rgb24 (R,G,B,out); break;
+ case PIX_FMT_BGR24: out_bgr24 (R,G,B,out); break;
+ default:
+ {
+ /* If this is reached, the caller should have called yuv2packedXinC
+ instead. */
+ static int printed_error_message;
+ if(!printed_error_message) {
+ av_log(c, AV_LOG_ERROR, "altivec_yuv2packedX doesn't support %s output\n",
+ sws_format_name(c->dstFormat));
+ printed_error_message=1;
+ }
+ return;
+ }
+ }
+ }
+
+ if (i < dstW) {
+ i -= 16;
+
+ Y0 = RND;
+ Y1 = RND;
+ /* extract 16 coeffs from lumSrc */
+ for(j=0; j<lumFilterSize; j++) {
+ X0 = vec_ld (0, &lumSrc[j][i]);
+ X1 = vec_ld (16, &lumSrc[j][i]);
+ Y0 = vec_mradds (X0, YCoeffs[j], Y0);
+ Y1 = vec_mradds (X1, YCoeffs[j], Y1);
+ }
+
+ U = RND;
+ V = RND;
+ /* extract 8 coeffs from U,V */
+ for(j=0; j<chrFilterSize; j++) {
+ X = vec_ld (0, &chrSrc[j][i/2]);
+ U = vec_mradds (X, CCoeffs[j], U);
+ X = vec_ld (0, &chrSrc[j][i/2+2048]);
+ V = vec_mradds (X, CCoeffs[j], V);
+ }
+
+ /* scale and clip signals */
+ Y0 = vec_sra (Y0, SCL);
+ Y1 = vec_sra (Y1, SCL);
+ U = vec_sra (U, SCL);
+ V = vec_sra (V, SCL);
+
+ Y0 = vec_clip_s16 (Y0);
+ Y1 = vec_clip_s16 (Y1);
+ U = vec_clip_s16 (U);
+ V = vec_clip_s16 (V);
+
+ /* now we have
+ Y0= y0 y1 y2 y3 y4 y5 y6 y7 Y1= y8 y9 y10 y11 y12 y13 y14 y15
+ U= u0 u1 u2 u3 u4 u5 u6 u7 V= v0 v1 v2 v3 v4 v5 v6 v7
+
+ Y0= y0 y1 y2 y3 y4 y5 y6 y7 Y1= y8 y9 y10 y11 y12 y13 y14 y15
+ U0= u0 u0 u1 u1 u2 u2 u3 u3 U1= u4 u4 u5 u5 u6 u6 u7 u7
+ V0= v0 v0 v1 v1 v2 v2 v3 v3 V1= v4 v4 v5 v5 v6 v6 v7 v7
+ */
+
+ U0 = vec_mergeh (U,U);
+ V0 = vec_mergeh (V,V);
+
+ U1 = vec_mergel (U,U);
+ V1 = vec_mergel (V,V);
+
+ cvtyuvtoRGB (c, Y0,U0,V0,&R0,&G0,&B0);
+ cvtyuvtoRGB (c, Y1,U1,V1,&R1,&G1,&B1);
+
+ R = vec_packclp (R0,R1);
+ G = vec_packclp (G0,G1);
+ B = vec_packclp (B0,B1);
+
+ nout = (vector unsigned char *)scratch;
+ switch(c->dstFormat) {
+ case PIX_FMT_ABGR: out_abgr (R,G,B,nout); break;
+ case PIX_FMT_BGRA: out_bgra (R,G,B,nout); break;
+ case PIX_FMT_RGBA: out_rgba (R,G,B,nout); break;
+ case PIX_FMT_ARGB: out_argb (R,G,B,nout); break;
+ case PIX_FMT_RGB24: out_rgb24 (R,G,B,nout); break;
+ case PIX_FMT_BGR24: out_bgr24 (R,G,B,nout); break;
+ default:
+ /* Unreachable, I think. */
+ av_log(c, AV_LOG_ERROR, "altivec_yuv2packedX doesn't support %s output\n",
+ sws_format_name(c->dstFormat));
+ return;
+ }
+
+ memcpy (&((uint32_t*)dest)[i], scratch, (dstW-i)/4);
+ }
+
+}
diff --git a/contrib/ffmpeg/libswscale/yuv2rgb_init.c b/contrib/ffmpeg/libswscale/yuv2rgb_init.c
new file mode 100644
index 000000000..371dce5da
--- /dev/null
+++ b/contrib/ffmpeg/libswscale/yuv2rgb_init.c
@@ -0,0 +1,412 @@
+#include "avutil.h"
+#include "swscale.h"
+#include "swscale_internal.h"
+
+#define YTABLE_MIN 384
+
+/**
+ * YUV -> RGB conversion matrixes (inverse of table 6.9 in MPEG2 standard)
+ *
+ * An YUV -> RGB conversion matrix is in the form
+ * | 1 0 Rv |
+ * | 1 Gu Gv |
+ * | 1 Bu 0 |
+ *
+ * Inverse_Table_6_9 stores | Rv Bu Gv Gu | * 255/224*2^16.
+ * \arg Maximum Rv value: 117570
+ * \arg Maximum Bu value: 138420
+ * \arg Maximum Gv + Gu value: 25642 + 53281 = 78923
+ *
+ * These values are needed to allocate table_{r, g, b}. If you modify
+ * this table, please update allocate_tables() accordingly
+ */
+const int32_t Inverse_Table_6_9[8][4] = {
+ {0, 0, 0, 0}, /* no sequence_display_extension */
+ {117500, 138420, -13985, -34933}, /* ITU-R Rec. 709 (1990) */
+ {0, 0, 0, 0}, /* unspecified */
+ {0, 0, 0, 0}, /* reserved */
+ {104480, 132820, -24811, -53150}, /* FCC */
+ {104570, 132210, -25642, -53281}, /* ITU-R Rec. 624-4 System B, G */
+ {104570, 132210, -25642, -53281}, /* SMPTE 170M */
+ {117570, 136230, -16892, -35552} /* SMPTE 240M (1987) */
+};
+
+
+/**
+ * Dithering matrixes (these are bayer ordered dither matrixes
+ * with some manual changes by Michael)
+ */
+const uint8_t __attribute__((aligned(8))) dither_2x2_4[2][8]={
+{ 1, 3, 1, 3, 1, 3, 1, 3, },
+{ 2, 0, 2, 0, 2, 0, 2, 0, },
+};
+
+const uint8_t __attribute__((aligned(8))) dither_2x2_8[2][8]={
+{ 6, 2, 6, 2, 6, 2, 6, 2, },
+{ 0, 4, 0, 4, 0, 4, 0, 4, },
+};
+
+const uint8_t __attribute__((aligned(8))) 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, },
+{ 0, 24, 6, 30, 1, 25, 7, 31, },
+{ 16, 8, 22, 14, 17, 9, 23, 15, },
+{ 4, 28, 2, 26, 5, 29, 3, 27, },
+{ 20, 12, 18, 10, 21, 13, 19, 11, },
+{ 1, 25, 7, 31, 0, 24, 6, 30, },
+};
+
+#if 0
+const uint8_t __attribute__((aligned(8))) dither_8x8_64[8][8]={
+{ 0, 48, 12, 60, 3, 51, 15, 63, },
+{ 32, 16, 44, 28, 35, 19, 47, 31, },
+{ 8, 56, 4, 52, 11, 59, 7, 55, },
+{ 40, 24, 36, 20, 43, 27, 39, 23, },
+{ 2, 50, 14, 62, 1, 49, 13, 61, },
+{ 34, 18, 46, 30, 33, 17, 45, 29, },
+{ 10, 58, 6, 54, 9, 57, 5, 53, },
+{ 42, 26, 38, 22, 41, 25, 37, 21, },
+};
+#endif
+
+const uint8_t __attribute__((aligned(8))) 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, },
+{ 46, 27, 41, 23, 49, 31, 44, 26, },
+{ 2, 57, 16, 71, 1, 56, 15, 70, },
+{ 39, 21, 52, 34, 38, 19, 51, 33, },
+{ 11, 66, 7, 62, 10, 65, 6, 60, },
+{ 48, 30, 43, 25, 47, 29, 42, 24, },
+};
+
+#if 0
+const uint8_t __attribute__((aligned(8))) dither_8x8_128[8][8]={
+{ 68, 36, 92, 60, 66, 34, 90, 58, },
+{ 20, 116, 12, 108, 18, 114, 10, 106, },
+{ 84, 52, 76, 44, 82, 50, 74, 42, },
+{ 0, 96, 24, 120, 6, 102, 30, 126, },
+{ 64, 32, 88, 56, 70, 38, 94, 62, },
+{ 16, 112, 8, 104, 22, 118, 14, 110, },
+{ 80, 48, 72, 40, 86, 54, 78, 46, },
+{ 4, 100, 28, 124, 2, 98, 26, 122, },
+};
+#endif
+
+#if 1
+const uint8_t __attribute__((aligned(8))) 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, },
+{ 0, 165, 41, 206, 10, 175, 52, 217, },
+{110, 55, 151, 96, 120, 65, 162, 107, },
+{ 28, 193, 14, 179, 38, 203, 24, 189, },
+{138, 83, 124, 69, 148, 93, 134, 79, },
+{ 7, 172, 48, 213, 3, 168, 45, 210, },
+};
+#elif 1
+// tries to correct a gamma of 1.5
+const uint8_t __attribute__((aligned(8))) 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, },
+{109, 51, 93, 38, 121, 60, 105, 47, },
+{ 1, 152, 23, 210, 0, 147, 20, 205, },
+{ 85, 33, 134, 71, 81, 30, 130, 67, },
+{ 14, 190, 6, 171, 12, 185, 5, 166, },
+{117, 57, 101, 44, 113, 54, 97, 41, },
+};
+#elif 1
+// tries to correct a gamma of 2.0
+const uint8_t __attribute__((aligned(8))) 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, },
+{ 86, 31, 70, 21, 99, 39, 82, 28, },
+{ 0, 134, 11, 206, 0, 129, 9, 200, },
+{ 62, 17, 114, 48, 58, 16, 109, 45, },
+{ 5, 181, 2, 157, 4, 175, 1, 151, },
+{ 95, 36, 78, 26, 90, 34, 74, 24, },
+};
+#else
+// tries to correct a gamma of 2.5
+const uint8_t __attribute__((aligned(8))) 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, },
+{ 68, 19, 52, 12, 81, 25, 64, 17, },
+{ 0, 119, 5, 203, 0, 113, 4, 195, },
+{ 45, 9, 96, 33, 42, 8, 91, 30, },
+{ 2, 172, 1, 144, 2, 165, 0, 137, },
+{ 77, 23, 60, 15, 72, 21, 56, 14, },
+};
+#endif
+
+static int get_entry_size(int bpp)
+{
+ switch(bpp) {
+ case 32:
+ return 4;
+ case 16:
+ case 15:
+ return 2;
+ case 24:
+ case 8:
+ case 4:
+ case 1:
+ return 1;
+ default:
+ return -1;
+ }
+}
+
+/**
+ * Allocate table_r, table_g, and table_b
+ *
+ * For cache efficency reasons, these three tables are allocated
+ * together, so that they are contiguous in memory
+ *
+ * table_r is indexed in the range
+ * [-128 * 117570 / 76309, 255 + 127 * 117570 / 76309] =
+ * [-197.21, 451.67] ---> [-198, 452]
+ * table_b is indexed in the range
+ * [-128 * 138420 / 76309, 255 + 127 * 138420 / 76309] =
+ * [232.18, 485.37] ---> [-233, 486]
+ * table_g is indexed in the range
+ * [-128 * 78923 / 76309, 255 + 127 * 78923 / 76309] =
+ * [-132.38, 386.35] ---> [-133, 387]
+ *
+ * Please look at the comments after Inverse_Table_6_9 to see where these
+ * numbers are coming from.
+ */
+static void *allocate_tables(uint8_t **table_r, uint8_t **table_g, uint8_t **table_b, int bpp)
+{
+ uint8_t *table;
+ int entry_size;
+
+ entry_size = get_entry_size(bpp);
+
+ /* First allocate the memory... */
+ switch (bpp) {
+ case 32:
+ case 15:
+ case 16:
+ case 8:
+ case 4:
+ table = av_malloc((198 + 452 + 233 + 486 + 133 + 387) * entry_size);
+ break;
+ case 24:
+ table = av_malloc(256 + 2 * 233);
+ break;
+ case 1:
+ table = av_malloc (256 * 2);
+ break;
+ default:
+ table = NULL;
+ }
+ if (table == NULL) {
+ MSG_ERR("Cannot allocate memory for the YUV -> RGB tables!\n");
+
+ return NULL;
+ }
+
+ /* ...and then, assign the table_* value */
+ switch (bpp) {
+ case 32:
+ case 15:
+ case 16:
+ case 8:
+ case 4:
+ *table_r = table + 198 * entry_size;
+ *table_b = table + (198 + 452 + 133 + 387 + 233) * entry_size;
+ *table_g = table + (198 + 452 + 133) * entry_size;
+ break;
+ case 24:
+ *table_r = *table_g = *table_b = table + 233;
+ break;
+ case 1:
+ *table_g = table;
+ *table_r = *table_b = NULL;
+ break;
+ }
+
+ return table;
+}
+
+/**
+ * Initialize the table_rV, table_gU[i], table_gV, and table_bU fields
+ * in SwsContext
+ *
+ * @param inv_table the YUV -> RGB table (this is a line of Inverse_Table_6_9)
+ * @param fullRange 0->MPEG YUV space 1->JPEG YUV space
+*/
+int yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], int fullRange, int brightness, int contrast, int saturation)
+{
+ int i;
+ static uint8_t ytable[1024];
+ int64_t cy, oy;
+ int64_t crv, cbu, cgu, cgv;
+ int entry_size = 0;
+ uint8_t *table_r, *table_g, *table_b;
+ int value;
+
+ if ((inv_table[0] == 0) || (inv_table[1] == 0) || (inv_table[2] == 0) || (inv_table[3] == 0)) {
+ MSG_ERR("Invalid YUV ---> RGB table!\n");
+
+ return -1;
+ }
+ crv = inv_table[0];
+ cbu = inv_table[1];
+ cgu = inv_table[2];
+ cgv = inv_table[3];
+ if (fullRange) {
+ cy = 1 << 16;
+ oy = 0;
+ crv= (crv*224) / 255;
+ cbu= (cbu*224) / 255;
+ cgu= (cgu*224) / 255;
+ cgv= (cgv*224) / 255;
+ //FIXME maybe its cleaner if the tables where based on full range (*244/255)
+ } else {
+ cy = ((1 << 16) * 255) / 219;
+ oy= 16 << 16;
+ }
+
+ 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;
+
+ for (i = 0; i < 1024; i++) {
+ value = (cy*(((i - YTABLE_MIN)<<16) - oy) + (1<<31))>>32;
+ ytable[i] = av_clip_uint8(value);
+ }
+
+ entry_size = get_entry_size(fmt_depth(c->dstFormat));
+ av_free(c->yuvTable);
+ c->yuvTable = allocate_tables(&table_r, &table_g, &table_b, fmt_depth(c->dstFormat));
+ if (c->yuvTable == NULL) {
+ return -1;
+ }
+
+ switch (fmt_depth(c->dstFormat)) {
+ case 32:
+ for (i = -198; i < 256 + 197; i++) {
+ value = ytable[i + YTABLE_MIN];
+ if (isBGR(c->dstFormat)) {
+ value <<= 16;
+ }
+ ((uint32_t *)table_r)[i] = value;
+ }
+ for (i = -133; i < 256 + 132; i++) {
+ ((uint32_t *)table_g)[i] = ytable[i + YTABLE_MIN] << 8;
+ }
+ for (i = -233; i < 256 + 232; i++) {
+ value = ytable[i + YTABLE_MIN];
+ if (!isBGR(c->dstFormat)) {
+ value <<= 16;
+ }
+ ((uint32_t *)table_b)[i] = value;
+ }
+ break;
+
+ case 24:
+ for (i = -233; i < 256 + 232; i++) {
+ ((uint8_t * )table_b)[i] = ytable[i + YTABLE_MIN];
+ }
+ break;
+
+ case 15:
+ case 16:
+ for (i = -198; i < 256 + 197; i++) {
+ value = ytable[i + YTABLE_MIN] >> 3;
+ if (isBGR(c->dstFormat)) {
+ value <<= ((fmt_depth(c->dstFormat) == 16) ? 11 : 10);
+ }
+ ((uint16_t *)table_r)[i] = value;
+ }
+ for (i = -133; i < 256 + 132; i++) {
+ value = ytable[i + YTABLE_MIN];
+ value >>= ((fmt_depth(c->dstFormat) == 16) ? 2 : 3);
+ ((uint16_t *)table_g)[i] = value << 5;
+ }
+ for (i = -233; i < 256 + 232; i++) {
+ value = ytable[i + YTABLE_MIN] >> 3;
+ if (!isBGR(c->dstFormat)) {
+ value <<= ((fmt_depth(c->dstFormat) == 16) ? 11 : 10);
+ }
+ ((uint16_t *)table_b)[i] = value;
+ }
+ break;
+ case 8:
+ for (i = -198; i < 256 + 197; i++) {
+ value = (ytable[i + YTABLE_MIN - 16] + 18) / 36;
+ if (isBGR(c->dstFormat)) {
+ value <<= 5;
+ }
+ ((uint8_t *)table_r)[i] = value;
+ }
+ for (i = -133; i < 256 + 132; i++) {
+ value = (ytable[i + YTABLE_MIN - 16] + 18) / 36;
+ if (!isBGR(c->dstFormat)) {
+ value <<= 1;
+ }
+ ((uint8_t *)table_g)[i] = value << 2;
+ }
+ for (i = -233; i < 256 + 232; i++) {
+ value = (ytable[i + YTABLE_MIN - 37] + 43) / 85;
+ if (!isBGR(c->dstFormat)) {
+ value <<= 6;
+ }
+ ((uint8_t *)table_b)[i] = value;
+ }
+ break;
+ case 4:
+ for (i = -198; i < 256 + 197; i++) {
+ value = ytable[i + YTABLE_MIN - 110] >> 7;
+ if (isBGR(c->dstFormat)) {
+ value <<= 3;
+ }
+ ((uint8_t *)table_r)[i] = value;
+ }
+ for (i = -133; i < 256 + 132; i++) {
+ value = (ytable[i + YTABLE_MIN - 37]+ 43) / 85;
+ ((uint8_t *)table_g)[i] = value << 1;
+ }
+ for (i = -233; i < 256 + 232; i++) {
+ value = ytable[i + YTABLE_MIN - 110] >> 7;
+ if (!isBGR(c->dstFormat)) {
+ value <<= 3;
+ }
+ ((uint8_t *)table_b)[i] = value;
+ }
+ break;
+ case 1:
+ for (i = 0; i < 256 + 256; i++) {
+ value = ytable[i + YTABLE_MIN - 110] >> 7;
+ ((uint8_t *)table_g)[i] = value;
+ }
+ break;
+ default:
+ MSG_ERR("%ibpp not supported by yuv2rgb\n", fmt_depth(c->dstFormat));
+ av_free(c->yuvTable);
+ c->yuvTable = NULL;
+
+ return -1;
+ }
+
+ for (i = 0; i < 256; i++) {
+ c->table_rV[i] = table_r +
+ entry_size * ROUNDED_DIV(crv * (i - 128), 76309);
+ c->table_gU[i] = table_g +
+ entry_size * ROUNDED_DIV(cgu * (i - 128), 76309);
+ c->table_gV[i] = entry_size * ROUNDED_DIV(cgv * (i - 128), 76309);
+ c->table_bU[i] = table_b +
+ entry_size * ROUNDED_DIV(cbu * (i - 128), 76309);
+ }
+
+ return 0;
+}
diff --git a/contrib/ffmpeg/libswscale/yuv2rgb_mlib.c b/contrib/ffmpeg/libswscale/yuv2rgb_mlib.c
new file mode 100644
index 000000000..c99e019cd
--- /dev/null
+++ b/contrib/ffmpeg/libswscale/yuv2rgb_mlib.c
@@ -0,0 +1,86 @@
+/*
+ * yuv2rgb_mlib.c, Software YUV to RGB coverter using mediaLib
+ *
+ * Copyright (C) 2000, Håkan Hjort <d95hjort@dtek.chalmers.se>
+ * All Rights Reserved.
+ *
+ * This file is part of mpeg2dec, a free MPEG-2 video decoder
+ *
+ * mpeg2dec 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, or (at your option)
+ * any later version.
+ *
+ * mpeg2dec is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with mpeg2dec; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <mlib_types.h>
+#include <mlib_status.h>
+#include <mlib_sys.h>
+#include <mlib_video.h>
+#include <inttypes.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include "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 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/contrib/ffmpeg/libswscale/yuv2rgb_template.c b/contrib/ffmpeg/libswscale/yuv2rgb_template.c
new file mode 100644
index 000000000..28ee24add
--- /dev/null
+++ b/contrib/ffmpeg/libswscale/yuv2rgb_template.c
@@ -0,0 +1,540 @@
+
+/*
+ * yuv2rgb_mmx.c, Software YUV to RGB coverter with Intel MMX "technology"
+ *
+ * Copyright (C) 2000, Silicon Integrated System Corp.
+ * All Rights Reserved.
+ *
+ * Author: Olie Lho <ollie@sis.com.tw>
+ *
+ * This file is part of mpeg2dec, a free MPEG-2 video decoder
+ *
+ * mpeg2dec 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, or (at your option)
+ * any later version.
+ *
+ * mpeg2dec is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with mpeg2dec; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * 15,24 bpp and dithering from Michael Niedermayer (michaelni@gmx.at)
+ * MMX/MMX2 Template stuff from Michael Niedermayer (needed for fast movntq support)
+ * context / deglobalize stuff by Michael Niedermayer
+ */
+
+#undef MOVNTQ
+#undef EMMS
+#undef SFENCE
+
+#ifdef HAVE_3DNOW
+/* On K6 femms is faster of emms. On K7 femms is directly mapped on emms. */
+#define EMMS "femms"
+#else
+#define EMMS "emms"
+#endif
+
+#ifdef HAVE_MMX2
+#define MOVNTQ "movntq"
+#define SFENCE "sfence"
+#else
+#define MOVNTQ "movq"
+#define SFENCE "/nop"
+#endif
+
+#define YUV2RGB \
+ /* Do the multiply part of the conversion for even and odd pixels,
+ register usage:
+ mm0 -> Cblue, mm1 -> Cred, mm2 -> Cgreen even pixels,
+ mm3 -> Cblue, mm4 -> Cred, mm5 -> Cgreen odd pixels,
+ mm6 -> Y even, mm7 -> Y odd */\
+ /* convert the chroma part */\
+ "punpcklbw %%mm4, %%mm0;" /* scatter 4 Cb 00 u3 00 u2 00 u1 00 u0 */ \
+ "punpcklbw %%mm4, %%mm1;" /* scatter 4 Cr 00 v3 00 v2 00 v1 00 v0 */ \
+\
+ "psllw $3, %%mm0;" /* Promote precision */ \
+ "psllw $3, %%mm1;" /* Promote precision */ \
+\
+ "psubsw "U_OFFSET"(%4), %%mm0;" /* Cb -= 128 */ \
+ "psubsw "V_OFFSET"(%4), %%mm1;" /* Cr -= 128 */ \
+\
+ "movq %%mm0, %%mm2;" /* Copy 4 Cb 00 u3 00 u2 00 u1 00 u0 */ \
+ "movq %%mm1, %%mm3;" /* Copy 4 Cr 00 v3 00 v2 00 v1 00 v0 */ \
+\
+ "pmulhw "UG_COEFF"(%4), %%mm2;" /* Mul Cb with green coeff -> Cb green */ \
+ "pmulhw "VG_COEFF"(%4), %%mm3;" /* Mul Cr with green coeff -> Cr green */ \
+\
+ "pmulhw "UB_COEFF"(%4), %%mm0;" /* Mul Cb -> Cblue 00 b3 00 b2 00 b1 00 b0 */\
+ "pmulhw "VR_COEFF"(%4), %%mm1;" /* Mul Cr -> Cred 00 r3 00 r2 00 r1 00 r0 */\
+\
+ "paddsw %%mm3, %%mm2;" /* Cb green + Cr green -> Cgreen */\
+\
+ /* convert the luma part */\
+ "movq %%mm6, %%mm7;" /* Copy 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */\
+ "pand "MANGLE(mmx_00ffw)", %%mm6;" /* get Y even 00 Y6 00 Y4 00 Y2 00 Y0 */\
+\
+ "psrlw $8, %%mm7;" /* get Y odd 00 Y7 00 Y5 00 Y3 00 Y1 */\
+\
+ "psllw $3, %%mm6;" /* Promote precision */\
+ "psllw $3, %%mm7;" /* Promote precision */\
+\
+ "psubw "Y_OFFSET"(%4), %%mm6;" /* Y -= 16 */\
+ "psubw "Y_OFFSET"(%4), %%mm7;" /* Y -= 16 */\
+\
+ "pmulhw "Y_COEFF"(%4), %%mm6;" /* Mul 4 Y even 00 y6 00 y4 00 y2 00 y0 */\
+ "pmulhw "Y_COEFF"(%4), %%mm7;" /* Mul 4 Y odd 00 y7 00 y5 00 y3 00 y1 */\
+\
+ /* Do the addition part of the conversion for even and odd pixels,
+ register usage:
+ mm0 -> Cblue, mm1 -> Cred, mm2 -> Cgreen even pixels,
+ mm3 -> Cblue, mm4 -> Cred, mm5 -> Cgreen odd pixels,
+ mm6 -> Y even, mm7 -> Y odd */\
+ "movq %%mm0, %%mm3;" /* Copy Cblue */\
+ "movq %%mm1, %%mm4;" /* Copy Cred */\
+ "movq %%mm2, %%mm5;" /* Copy Cgreen */\
+\
+ "paddsw %%mm6, %%mm0;" /* Y even + Cblue 00 B6 00 B4 00 B2 00 B0 */\
+ "paddsw %%mm7, %%mm3;" /* Y odd + Cblue 00 B7 00 B5 00 B3 00 B1 */\
+\
+ "paddsw %%mm6, %%mm1;" /* Y even + Cred 00 R6 00 R4 00 R2 00 R0 */\
+ "paddsw %%mm7, %%mm4;" /* Y odd + Cred 00 R7 00 R5 00 R3 00 R1 */\
+\
+ "paddsw %%mm6, %%mm2;" /* Y even + Cgreen 00 G6 00 G4 00 G2 00 G0 */\
+ "paddsw %%mm7, %%mm5;" /* Y odd + Cgreen 00 G7 00 G5 00 G3 00 G1 */\
+\
+ /* Limit RGB even to 0..255 */\
+ "packuswb %%mm0, %%mm0;" /* B6 B4 B2 B0 B6 B4 B2 B0 */\
+ "packuswb %%mm1, %%mm1;" /* R6 R4 R2 R0 R6 R4 R2 R0 */\
+ "packuswb %%mm2, %%mm2;" /* G6 G4 G2 G0 G6 G4 G2 G0 */\
+\
+ /* Limit RGB odd to 0..255 */\
+ "packuswb %%mm3, %%mm3;" /* B7 B5 B3 B1 B7 B5 B3 B1 */\
+ "packuswb %%mm4, %%mm4;" /* R7 R5 R3 R1 R7 R5 R3 R1 */\
+ "packuswb %%mm5, %%mm5;" /* G7 G5 G3 G1 G7 G5 G3 G1 */\
+\
+ /* Interleave RGB even and odd */\
+ "punpcklbw %%mm3, %%mm0;" /* B7 B6 B5 B4 B3 B2 B1 B0 */\
+ "punpcklbw %%mm4, %%mm1;" /* R7 R6 R5 R4 R3 R2 R1 R0 */\
+ "punpcklbw %%mm5, %%mm2;" /* G7 G6 G5 G4 G3 G2 G1 G0 */\
+
+
+static inline int RENAME(yuv420_rgb16)(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+ int srcSliceH, uint8_t* dst[], int dstStride[]){
+ int y, h_size;
+
+ if(c->srcFormat == PIX_FMT_YUV422P){
+ srcStride[1] *= 2;
+ srcStride[2] *= 2;
+ }
+
+ h_size= (c->dstW+7)&~7;
+ if(h_size*2 > FFABS(dstStride[0])) h_size-=8;
+
+ __asm__ __volatile__ ("pxor %mm4, %mm4;" /* zero mm4 */ );
+//printf("%X %X %X %X %X %X %X %X %X %X\n", (int)&c->redDither, (int)&b5Dither, (int)src[0], (int)src[1], (int)src[2], (int)dst[0],
+//srcStride[0],srcStride[1],srcStride[2],dstStride[0]);
+ for (y= 0; y<srcSliceH; y++ ) {
+ uint8_t *_image = dst[0] + (y+srcSliceY)*dstStride[0];
+ uint8_t *_py = src[0] + y*srcStride[0];
+ uint8_t *_pu = src[1] + (y>>1)*srcStride[1];
+ uint8_t *_pv = src[2] + (y>>1)*srcStride[2];
+ long index= -h_size/2;
+
+ b5Dither= dither8[y&1];
+ g6Dither= dither4[y&1];
+ g5Dither= dither8[y&1];
+ r5Dither= dither8[(y+1)&1];
+ /* this mmx assembly code deals with SINGLE scan line at a time, it convert 8
+ pixels in each iteration */
+ __asm__ __volatile__ (
+ /* load data for start of next scan line */
+ "movd (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */
+ "movd (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */
+ "movq (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */
+// ".balign 16 \n\t"
+ "1: \n\t"
+/* no speed diference on my p3@500 with prefetch,
+ * if it is faster for anyone with -benchmark then tell me
+ PREFETCH" 64(%0) \n\t"
+ PREFETCH" 64(%1) \n\t"
+ PREFETCH" 64(%2) \n\t"
+*/
+YUV2RGB
+
+#ifdef DITHER1XBPP
+ "paddusb "MANGLE(b5Dither)", %%mm0;"
+ "paddusb "MANGLE(g6Dither)", %%mm2;"
+ "paddusb "MANGLE(r5Dither)", %%mm1;"
+#endif
+ /* mask unneeded bits off */
+ "pand "MANGLE(mmx_redmask)", %%mm0;" /* b7b6b5b4 b3_0_0_0 b7b6b5b4 b3_0_0_0 */
+ "pand "MANGLE(mmx_grnmask)", %%mm2;" /* g7g6g5g4 g3g2_0_0 g7g6g5g4 g3g2_0_0 */
+ "pand "MANGLE(mmx_redmask)", %%mm1;" /* r7r6r5r4 r3_0_0_0 r7r6r5r4 r3_0_0_0 */
+
+ "psrlw $3,%%mm0;" /* 0_0_0_b7 b6b5b4b3 0_0_0_b7 b6b5b4b3 */
+ "pxor %%mm4, %%mm4;" /* zero mm4 */
+
+ "movq %%mm0, %%mm5;" /* Copy B7-B0 */
+ "movq %%mm2, %%mm7;" /* Copy G7-G0 */
+
+ /* convert rgb24 plane to rgb16 pack for pixel 0-3 */
+ "punpcklbw %%mm4, %%mm2;" /* 0_0_0_0 0_0_0_0 g7g6g5g4 g3g2_0_0 */
+ "punpcklbw %%mm1, %%mm0;" /* r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3 */
+
+ "psllw $3, %%mm2;" /* 0_0_0_0 0_g7g6g5 g4g3g2_0 0_0_0_0 */
+ "por %%mm2, %%mm0;" /* r7r6r5r4 r3g7g6g5 g4g3g2b7 b6b5b4b3 */
+
+ "movq 8 (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */
+ MOVNTQ " %%mm0, (%1);" /* store pixel 0-3 */
+
+ /* convert rgb24 plane to rgb16 pack for pixel 0-3 */
+ "punpckhbw %%mm4, %%mm7;" /* 0_0_0_0 0_0_0_0 g7g6g5g4 g3g2_0_0 */
+ "punpckhbw %%mm1, %%mm5;" /* r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3 */
+
+ "psllw $3, %%mm7;" /* 0_0_0_0 0_g7g6g5 g4g3g2_0 0_0_0_0 */
+ "movd 4 (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */
+
+ "por %%mm7, %%mm5;" /* r7r6r5r4 r3g7g6g5 g4g3g2b7 b6b5b4b3 */
+ "movd 4 (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */
+
+ MOVNTQ " %%mm5, 8 (%1);" /* store pixel 4-7 */
+
+ "add $16, %1 \n\t"
+ "add $4, %0 \n\t"
+ " js 1b \n\t"
+
+ : "+r" (index), "+r" (_image)
+ : "r" (_pu - index), "r" (_pv - index), "r"(&c->redDither), "r" (_py - 2*index)
+ );
+ }
+
+ __asm__ __volatile__ (EMMS);
+
+ return srcSliceH;
+}
+
+static inline int RENAME(yuv420_rgb15)(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+ int srcSliceH, uint8_t* dst[], int dstStride[]){
+ int y, h_size;
+
+ if(c->srcFormat == PIX_FMT_YUV422P){
+ srcStride[1] *= 2;
+ srcStride[2] *= 2;
+ }
+
+ h_size= (c->dstW+7)&~7;
+ if(h_size*2 > FFABS(dstStride[0])) h_size-=8;
+
+ __asm__ __volatile__ ("pxor %mm4, %mm4;" /* zero mm4 */ );
+//printf("%X %X %X %X %X %X %X %X %X %X\n", (int)&c->redDither, (int)&b5Dither, (int)src[0], (int)src[1], (int)src[2], (int)dst[0],
+//srcStride[0],srcStride[1],srcStride[2],dstStride[0]);
+ for (y= 0; y<srcSliceH; y++ ) {
+ uint8_t *_image = dst[0] + (y+srcSliceY)*dstStride[0];
+ uint8_t *_py = src[0] + y*srcStride[0];
+ uint8_t *_pu = src[1] + (y>>1)*srcStride[1];
+ uint8_t *_pv = src[2] + (y>>1)*srcStride[2];
+ long index= -h_size/2;
+
+ b5Dither= dither8[y&1];
+ g6Dither= dither4[y&1];
+ g5Dither= dither8[y&1];
+ r5Dither= dither8[(y+1)&1];
+ /* this mmx assembly code deals with SINGLE scan line at a time, it convert 8
+ pixels in each iteration */
+ __asm__ __volatile__ (
+ /* load data for start of next scan line */
+ "movd (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */
+ "movd (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */
+ "movq (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */
+// ".balign 16 \n\t"
+ "1: \n\t"
+YUV2RGB
+
+#ifdef DITHER1XBPP
+ "paddusb "MANGLE(b5Dither)", %%mm0 \n\t"
+ "paddusb "MANGLE(g5Dither)", %%mm2 \n\t"
+ "paddusb "MANGLE(r5Dither)", %%mm1 \n\t"
+#endif
+
+ /* mask unneeded bits off */
+ "pand "MANGLE(mmx_redmask)", %%mm0;" /* b7b6b5b4 b3_0_0_0 b7b6b5b4 b3_0_0_0 */
+ "pand "MANGLE(mmx_redmask)", %%mm2;" /* g7g6g5g4 g3_0_0_0 g7g6g5g4 g3_0_0_0 */
+ "pand "MANGLE(mmx_redmask)", %%mm1;" /* r7r6r5r4 r3_0_0_0 r7r6r5r4 r3_0_0_0 */
+
+ "psrlw $3,%%mm0;" /* 0_0_0_b7 b6b5b4b3 0_0_0_b7 b6b5b4b3 */
+ "psrlw $1,%%mm1;" /* 0_r7r6r5 r4r3_0_0 0_r7r6r5 r4r3_0_0 */
+ "pxor %%mm4, %%mm4;" /* zero mm4 */
+
+ "movq %%mm0, %%mm5;" /* Copy B7-B0 */
+ "movq %%mm2, %%mm7;" /* Copy G7-G0 */
+
+ /* convert rgb24 plane to rgb16 pack for pixel 0-3 */
+ "punpcklbw %%mm4, %%mm2;" /* 0_0_0_0 0_0_0_0 g7g6g5g4 g3_0_0_0 */
+ "punpcklbw %%mm1, %%mm0;" /* r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3 */
+
+ "psllw $2, %%mm2;" /* 0_0_0_0 0_0_g7g6 g5g4g3_0 0_0_0_0 */
+ "por %%mm2, %%mm0;" /* 0_r7r6r5 r4r3g7g6 g5g4g3b7 b6b5b4b3 */
+
+ "movq 8 (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */
+ MOVNTQ " %%mm0, (%1);" /* store pixel 0-3 */
+
+ /* convert rgb24 plane to rgb16 pack for pixel 0-3 */
+ "punpckhbw %%mm4, %%mm7;" /* 0_0_0_0 0_0_0_0 0_g7g6g5 g4g3_0_0 */
+ "punpckhbw %%mm1, %%mm5;" /* r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3 */
+
+ "psllw $2, %%mm7;" /* 0_0_0_0 0_0_g7g6 g5g4g3_0 0_0_0_0 */
+ "movd 4 (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */
+
+ "por %%mm7, %%mm5;" /* 0_r7r6r5 r4r3g7g6 g5g4g3b7 b6b5b4b3 */
+ "movd 4 (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */
+
+ MOVNTQ " %%mm5, 8 (%1);" /* store pixel 4-7 */
+
+ "add $16, %1 \n\t"
+ "add $4, %0 \n\t"
+ " js 1b \n\t"
+ : "+r" (index), "+r" (_image)
+ : "r" (_pu - index), "r" (_pv - index), "r"(&c->redDither), "r" (_py - 2*index)
+ );
+ }
+
+ __asm__ __volatile__ (EMMS);
+ return srcSliceH;
+}
+
+static inline int RENAME(yuv420_rgb24)(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+ int srcSliceH, uint8_t* dst[], int dstStride[]){
+ int y, h_size;
+
+ if(c->srcFormat == PIX_FMT_YUV422P){
+ srcStride[1] *= 2;
+ srcStride[2] *= 2;
+ }
+
+ h_size= (c->dstW+7)&~7;
+ if(h_size*3 > FFABS(dstStride[0])) h_size-=8;
+
+ __asm__ __volatile__ ("pxor %mm4, %mm4;" /* zero mm4 */ );
+
+ for (y= 0; y<srcSliceH; y++ ) {
+ uint8_t *_image = dst[0] + (y+srcSliceY)*dstStride[0];
+ uint8_t *_py = src[0] + y*srcStride[0];
+ uint8_t *_pu = src[1] + (y>>1)*srcStride[1];
+ uint8_t *_pv = src[2] + (y>>1)*srcStride[2];
+ long index= -h_size/2;
+
+ /* this mmx assembly code deals with SINGLE scan line at a time, it convert 8
+ pixels in each iteration */
+ __asm__ __volatile__ (
+ /* load data for start of next scan line */
+ "movd (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */
+ "movd (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */
+ "movq (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */
+// ".balign 16 \n\t"
+ "1: \n\t"
+YUV2RGB
+ /* mm0=B, %%mm2=G, %%mm1=R */
+#ifdef HAVE_MMX2
+ "movq "MANGLE(M24A)", %%mm4 \n\t"
+ "movq "MANGLE(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 */
+
+ "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, %%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 */
+
+ "pand "MANGLE(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(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
+
+ "add $24, %1 \n\t"
+ "add $4, %0 \n\t"
+ " js 1b \n\t"
+
+ : "+r" (index), "+r" (_image)
+ : "r" (_pu - index), "r" (_pv - index), "r"(&c->redDither), "r" (_py - 2*index)
+ );
+ }
+
+ __asm__ __volatile__ (EMMS);
+ return srcSliceH;
+}
+
+static inline int RENAME(yuv420_rgb32)(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+ int srcSliceH, uint8_t* dst[], int dstStride[]){
+ int y, h_size;
+
+ if(c->srcFormat == PIX_FMT_YUV422P){
+ srcStride[1] *= 2;
+ srcStride[2] *= 2;
+ }
+
+ h_size= (c->dstW+7)&~7;
+ if(h_size*4 > FFABS(dstStride[0])) h_size-=8;
+
+ __asm__ __volatile__ ("pxor %mm4, %mm4;" /* zero mm4 */ );
+
+ for (y= 0; y<srcSliceH; y++ ) {
+ uint8_t *_image = dst[0] + (y+srcSliceY)*dstStride[0];
+ uint8_t *_py = src[0] + y*srcStride[0];
+ uint8_t *_pu = src[1] + (y>>1)*srcStride[1];
+ uint8_t *_pv = src[2] + (y>>1)*srcStride[2];
+ long index= -h_size/2;
+
+ /* this mmx assembly code deals with SINGLE scan line at a time, it convert 8
+ pixels in each iteration */
+ __asm__ __volatile__ (
+ /* load data for start of next scan line */
+ "movd (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */
+ "movd (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */
+ "movq (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */
+// ".balign 16 \n\t"
+ "1: \n\t"
+YUV2RGB
+ /* convert RGB plane to RGB packed format,
+ mm0 -> B, mm1 -> R, mm2 -> G, mm3 -> 0,
+ mm4 -> GB, mm5 -> AR pixel 4-7,
+ mm6 -> GB, mm7 -> AR pixel 0-3 */
+ "pxor %%mm3, %%mm3;" /* zero mm3 */
+
+ "movq %%mm0, %%mm6;" /* B7 B6 B5 B4 B3 B2 B1 B0 */
+ "movq %%mm1, %%mm7;" /* R7 R6 R5 R4 R3 R2 R1 R0 */
+
+ "movq %%mm0, %%mm4;" /* B7 B6 B5 B4 B3 B2 B1 B0 */
+ "movq %%mm1, %%mm5;" /* R7 R6 R5 R4 R3 R2 R1 R0 */
+
+ "punpcklbw %%mm2, %%mm6;" /* G3 B3 G2 B2 G1 B1 G0 B0 */
+ "punpcklbw %%mm3, %%mm7;" /* 00 R3 00 R2 00 R1 00 R0 */
+
+ "punpcklwd %%mm7, %%mm6;" /* 00 R1 B1 G1 00 R0 B0 G0 */
+ MOVNTQ " %%mm6, (%1);" /* Store ARGB1 ARGB0 */
+
+ "movq %%mm0, %%mm6;" /* B7 B6 B5 B4 B3 B2 B1 B0 */
+ "punpcklbw %%mm2, %%mm6;" /* G3 B3 G2 B2 G1 B1 G0 B0 */
+
+ "punpckhwd %%mm7, %%mm6;" /* 00 R3 G3 B3 00 R2 B3 G2 */
+ MOVNTQ " %%mm6, 8 (%1);" /* Store ARGB3 ARGB2 */
+
+ "punpckhbw %%mm2, %%mm4;" /* G7 B7 G6 B6 G5 B5 G4 B4 */
+ "punpckhbw %%mm3, %%mm5;" /* 00 R7 00 R6 00 R5 00 R4 */
+
+ "punpcklwd %%mm5, %%mm4;" /* 00 R5 B5 G5 00 R4 B4 G4 */
+ MOVNTQ " %%mm4, 16 (%1);" /* Store ARGB5 ARGB4 */
+
+ "movq %%mm0, %%mm4;" /* B7 B6 B5 B4 B3 B2 B1 B0 */
+ "punpckhbw %%mm2, %%mm4;" /* G7 B7 G6 B6 G5 B5 G4 B4 */
+
+ "punpckhwd %%mm5, %%mm4;" /* 00 R7 G7 B7 00 R6 B6 G6 */
+ MOVNTQ " %%mm4, 24 (%1);" /* Store ARGB7 ARGB6 */
+
+ "movd 4 (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */
+ "movd 4 (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */
+
+ "pxor %%mm4, %%mm4;" /* zero mm4 */
+ "movq 8 (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */
+
+ "add $32, %1 \n\t"
+ "add $4, %0 \n\t"
+ " js 1b \n\t"
+
+ : "+r" (index), "+r" (_image)
+ : "r" (_pu - index), "r" (_pv - index), "r"(&c->redDither), "r" (_py - 2*index)
+ );
+ }
+
+ __asm__ __volatile__ (EMMS);
+ return srcSliceH;
+}
diff --git a/contrib/ffmpeg/output_example.c b/contrib/ffmpeg/output_example.c
new file mode 100644
index 000000000..ca12b783f
--- /dev/null
+++ b/contrib/ffmpeg/output_example.c
@@ -0,0 +1,546 @@
+/*
+ * Libavformat API example: Output a media file in any supported
+ * libavformat format. The default codecs are used.
+ *
+ * Copyright (c) 2003 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
+#include "avformat.h"
+#include "swscale.h"
+
+/* 5 seconds stream duration */
+#define STREAM_DURATION 5.0
+#define STREAM_FRAME_RATE 25 /* 25 images/s */
+#define STREAM_NB_FRAMES ((int)(STREAM_DURATION * STREAM_FRAME_RATE))
+#define STREAM_PIX_FMT PIX_FMT_YUV420P /* default pix_fmt */
+
+static int sws_flags = SWS_BICUBIC;
+
+/**************************************************************/
+/* audio output */
+
+float t, tincr, tincr2;
+int16_t *samples;
+uint8_t *audio_outbuf;
+int audio_outbuf_size;
+int audio_input_frame_size;
+
+/*
+ * add an audio output stream
+ */
+static AVStream *add_audio_stream(AVFormatContext *oc, int codec_id)
+{
+ AVCodecContext *c;
+ AVStream *st;
+
+ st = av_new_stream(oc, 1);
+ if (!st) {
+ fprintf(stderr, "Could not alloc stream\n");
+ exit(1);
+ }
+
+ c = st->codec;
+ c->codec_id = codec_id;
+ c->codec_type = CODEC_TYPE_AUDIO;
+
+ /* put sample parameters */
+ c->bit_rate = 64000;
+ c->sample_rate = 44100;
+ c->channels = 2;
+ return st;
+}
+
+static void open_audio(AVFormatContext *oc, AVStream *st)
+{
+ AVCodecContext *c;
+ AVCodec *codec;
+
+ c = st->codec;
+
+ /* find the audio encoder */
+ codec = avcodec_find_encoder(c->codec_id);
+ if (!codec) {
+ fprintf(stderr, "codec not found\n");
+ exit(1);
+ }
+
+ /* open it */
+ if (avcodec_open(c, codec) < 0) {
+ fprintf(stderr, "could not open codec\n");
+ exit(1);
+ }
+
+ /* init signal generator */
+ t = 0;
+ tincr = 2 * M_PI * 110.0 / c->sample_rate;
+ /* increment frequency by 110 Hz per second */
+ tincr2 = 2 * M_PI * 110.0 / c->sample_rate / c->sample_rate;
+
+ audio_outbuf_size = 10000;
+ audio_outbuf = av_malloc(audio_outbuf_size);
+
+ /* ugly hack for PCM codecs (will be removed ASAP with new PCM
+ support to compute the input frame size in samples */
+ if (c->frame_size <= 1) {
+ audio_input_frame_size = audio_outbuf_size / c->channels;
+ switch(st->codec->codec_id) {
+ case CODEC_ID_PCM_S16LE:
+ case CODEC_ID_PCM_S16BE:
+ case CODEC_ID_PCM_U16LE:
+ case CODEC_ID_PCM_U16BE:
+ audio_input_frame_size >>= 1;
+ break;
+ default:
+ break;
+ }
+ } else {
+ audio_input_frame_size = c->frame_size;
+ }
+ samples = av_malloc(audio_input_frame_size * 2 * c->channels);
+}
+
+/* prepare a 16 bit dummy audio frame of 'frame_size' samples and
+ 'nb_channels' channels */
+static void get_audio_frame(int16_t *samples, int frame_size, int nb_channels)
+{
+ int j, i, v;
+ int16_t *q;
+
+ q = samples;
+ for(j=0;j<frame_size;j++) {
+ v = (int)(sin(t) * 10000);
+ for(i = 0; i < nb_channels; i++)
+ *q++ = v;
+ t += tincr;
+ tincr += tincr2;
+ }
+}
+
+static void write_audio_frame(AVFormatContext *oc, AVStream *st)
+{
+ AVCodecContext *c;
+ AVPacket pkt;
+ av_init_packet(&pkt);
+
+ c = st->codec;
+
+ get_audio_frame(samples, audio_input_frame_size, c->channels);
+
+ pkt.size= avcodec_encode_audio(c, audio_outbuf, audio_outbuf_size, samples);
+
+ pkt.pts= av_rescale_q(c->coded_frame->pts, c->time_base, st->time_base);
+ pkt.flags |= PKT_FLAG_KEY;
+ pkt.stream_index= st->index;
+ pkt.data= audio_outbuf;
+
+ /* write the compressed frame in the media file */
+ if (av_write_frame(oc, &pkt) != 0) {
+ fprintf(stderr, "Error while writing audio frame\n");
+ exit(1);
+ }
+}
+
+static void close_audio(AVFormatContext *oc, AVStream *st)
+{
+ avcodec_close(st->codec);
+
+ av_free(samples);
+ av_free(audio_outbuf);
+}
+
+/**************************************************************/
+/* video output */
+
+AVFrame *picture, *tmp_picture;
+uint8_t *video_outbuf;
+int frame_count, video_outbuf_size;
+
+/* add a video output stream */
+static AVStream *add_video_stream(AVFormatContext *oc, int codec_id)
+{
+ AVCodecContext *c;
+ AVStream *st;
+
+ st = av_new_stream(oc, 0);
+ if (!st) {
+ fprintf(stderr, "Could not alloc stream\n");
+ exit(1);
+ }
+
+ c = st->codec;
+ c->codec_id = codec_id;
+ c->codec_type = CODEC_TYPE_VIDEO;
+
+ /* put sample parameters */
+ c->bit_rate = 400000;
+ /* resolution must be a multiple of two */
+ c->width = 352;
+ c->height = 288;
+ /* time base: this is the fundamental unit of time (in seconds) in terms
+ of which frame timestamps are represented. for fixed-fps content,
+ timebase should be 1/framerate and timestamp increments should be
+ identically 1. */
+ c->time_base.den = STREAM_FRAME_RATE;
+ c->time_base.num = 1;
+ c->gop_size = 12; /* emit one intra frame every twelve frames at most */
+ c->pix_fmt = STREAM_PIX_FMT;
+ if (c->codec_id == CODEC_ID_MPEG2VIDEO) {
+ /* just for testing, we also add B frames */
+ c->max_b_frames = 2;
+ }
+ if (c->codec_id == CODEC_ID_MPEG1VIDEO){
+ /* needed to avoid using macroblocks in which some coeffs overflow
+ this doesnt happen with normal video, it just happens here as the
+ motion of the chroma plane doesnt match the luma plane */
+ c->mb_decision=2;
+ }
+ // some formats want stream headers to be separate
+ if(!strcmp(oc->oformat->name, "mp4") || !strcmp(oc->oformat->name, "mov") || !strcmp(oc->oformat->name, "3gp"))
+ c->flags |= CODEC_FLAG_GLOBAL_HEADER;
+
+ return st;
+}
+
+static AVFrame *alloc_picture(int pix_fmt, int width, int height)
+{
+ AVFrame *picture;
+ uint8_t *picture_buf;
+ int size;
+
+ picture = avcodec_alloc_frame();
+ if (!picture)
+ return NULL;
+ size = avpicture_get_size(pix_fmt, width, height);
+ picture_buf = av_malloc(size);
+ if (!picture_buf) {
+ av_free(picture);
+ return NULL;
+ }
+ avpicture_fill((AVPicture *)picture, picture_buf,
+ pix_fmt, width, height);
+ return picture;
+}
+
+static void open_video(AVFormatContext *oc, AVStream *st)
+{
+ AVCodec *codec;
+ AVCodecContext *c;
+
+ c = st->codec;
+
+ /* find the video encoder */
+ codec = avcodec_find_encoder(c->codec_id);
+ if (!codec) {
+ fprintf(stderr, "codec not found\n");
+ exit(1);
+ }
+
+ /* open the codec */
+ if (avcodec_open(c, codec) < 0) {
+ fprintf(stderr, "could not open codec\n");
+ exit(1);
+ }
+
+ video_outbuf = NULL;
+ if (!(oc->oformat->flags & AVFMT_RAWPICTURE)) {
+ /* allocate output buffer */
+ /* XXX: API change will be done */
+ /* buffers passed into lav* can be allocated any way you prefer,
+ as long as they're aligned enough for the architecture, and
+ they're freed appropriately (such as using av_free for buffers
+ allocated with av_malloc) */
+ video_outbuf_size = 200000;
+ video_outbuf = av_malloc(video_outbuf_size);
+ }
+
+ /* allocate the encoded raw picture */
+ picture = alloc_picture(c->pix_fmt, c->width, c->height);
+ if (!picture) {
+ fprintf(stderr, "Could not allocate picture\n");
+ exit(1);
+ }
+
+ /* if the output format is not YUV420P, then a temporary YUV420P
+ picture is needed too. It is then converted to the required
+ output format */
+ tmp_picture = NULL;
+ if (c->pix_fmt != PIX_FMT_YUV420P) {
+ tmp_picture = alloc_picture(PIX_FMT_YUV420P, c->width, c->height);
+ if (!tmp_picture) {
+ fprintf(stderr, "Could not allocate temporary picture\n");
+ exit(1);
+ }
+ }
+}
+
+/* prepare a dummy image */
+static void fill_yuv_image(AVFrame *pict, int frame_index, int width, int height)
+{
+ int x, y, i;
+
+ i = frame_index;
+
+ /* Y */
+ for(y=0;y<height;y++) {
+ for(x=0;x<width;x++) {
+ pict->data[0][y * pict->linesize[0] + x] = x + y + i * 3;
+ }
+ }
+
+ /* Cb and Cr */
+ for(y=0;y<height/2;y++) {
+ for(x=0;x<width/2;x++) {
+ pict->data[1][y * pict->linesize[1] + x] = 128 + y + i * 2;
+ pict->data[2][y * pict->linesize[2] + x] = 64 + x + i * 5;
+ }
+ }
+}
+
+static void write_video_frame(AVFormatContext *oc, AVStream *st)
+{
+ int out_size, ret;
+ AVCodecContext *c;
+ static struct SwsContext *img_convert_ctx;
+
+ c = st->codec;
+
+ if (frame_count >= STREAM_NB_FRAMES) {
+ /* no more frame to compress. The codec has a latency of a few
+ frames if using B frames, so we get the last frames by
+ passing the same picture again */
+ } else {
+ if (c->pix_fmt != PIX_FMT_YUV420P) {
+ /* as we only generate a YUV420P picture, we must convert it
+ to the codec pixel format if needed */
+ if (img_convert_ctx == NULL) {
+ img_convert_ctx = sws_getContext(c->width, c->height,
+ PIX_FMT_YUV420P,
+ c->width, c->height,
+ c->pix_fmt,
+ sws_flags, NULL, NULL, NULL);
+ if (img_convert_ctx == NULL) {
+ fprintf(stderr, "Cannot initialize the conversion context\n");
+ exit(1);
+ }
+ }
+ fill_yuv_image(tmp_picture, frame_count, c->width, c->height);
+ sws_scale(img_convert_ctx, tmp_picture->data, tmp_picture->linesize,
+ 0, c->height, picture->data, picture->linesize);
+ } else {
+ fill_yuv_image(picture, frame_count, c->width, c->height);
+ }
+ }
+
+
+ if (oc->oformat->flags & AVFMT_RAWPICTURE) {
+ /* raw video case. The API will change slightly in the near
+ futur for that */
+ AVPacket pkt;
+ av_init_packet(&pkt);
+
+ pkt.flags |= PKT_FLAG_KEY;
+ pkt.stream_index= st->index;
+ pkt.data= (uint8_t *)picture;
+ pkt.size= sizeof(AVPicture);
+
+ ret = av_write_frame(oc, &pkt);
+ } else {
+ /* encode the image */
+ out_size = avcodec_encode_video(c, video_outbuf, video_outbuf_size, picture);
+ /* if zero size, it means the image was buffered */
+ if (out_size > 0) {
+ AVPacket pkt;
+ av_init_packet(&pkt);
+
+ 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.stream_index= st->index;
+ pkt.data= video_outbuf;
+ pkt.size= out_size;
+
+ /* write the compressed frame in the media file */
+ ret = av_write_frame(oc, &pkt);
+ } else {
+ ret = 0;
+ }
+ }
+ if (ret != 0) {
+ fprintf(stderr, "Error while writing video frame\n");
+ exit(1);
+ }
+ frame_count++;
+}
+
+static void close_video(AVFormatContext *oc, AVStream *st)
+{
+ avcodec_close(st->codec);
+ av_free(picture->data[0]);
+ av_free(picture);
+ if (tmp_picture) {
+ av_free(tmp_picture->data[0]);
+ av_free(tmp_picture);
+ }
+ av_free(video_outbuf);
+}
+
+/**************************************************************/
+/* media file output */
+
+int main(int argc, char **argv)
+{
+ const char *filename;
+ AVOutputFormat *fmt;
+ AVFormatContext *oc;
+ AVStream *audio_st, *video_st;
+ double audio_pts, video_pts;
+ int i;
+
+ /* initialize libavcodec, and register all codecs and formats */
+ av_register_all();
+
+ if (argc != 2) {
+ printf("usage: %s output_file\n"
+ "API example program to output a media file with libavformat.\n"
+ "The output format is automatically guessed according to the file extension.\n"
+ "Raw images can also be output by using '%%d' in the filename\n"
+ "\n", argv[0]);
+ exit(1);
+ }
+
+ filename = argv[1];
+
+ /* auto detect the output format from the name. default is
+ mpeg. */
+ fmt = 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);
+ }
+ if (!fmt) {
+ fprintf(stderr, "Could not find suitable output format\n");
+ exit(1);
+ }
+
+ /* allocate the output media context */
+ oc = av_alloc_format_context();
+ if (!oc) {
+ fprintf(stderr, "Memory error\n");
+ exit(1);
+ }
+ oc->oformat = fmt;
+ snprintf(oc->filename, sizeof(oc->filename), "%s", filename);
+
+ /* add the audio and video streams using the default format codecs
+ and initialize the codecs */
+ video_st = NULL;
+ audio_st = NULL;
+ if (fmt->video_codec != CODEC_ID_NONE) {
+ video_st = add_video_stream(oc, fmt->video_codec);
+ }
+ if (fmt->audio_codec != CODEC_ID_NONE) {
+ audio_st = add_audio_stream(oc, fmt->audio_codec);
+ }
+
+ /* set the output parameters (must be done even if no
+ parameters). */
+ if (av_set_parameters(oc, NULL) < 0) {
+ fprintf(stderr, "Invalid output format parameters\n");
+ exit(1);
+ }
+
+ dump_format(oc, 0, filename, 1);
+
+ /* now that all the parameters are set, we can open the audio and
+ video codecs and allocate the necessary encode buffers */
+ if (video_st)
+ open_video(oc, video_st);
+ if (audio_st)
+ open_audio(oc, audio_st);
+
+ /* open the output file, if needed */
+ if (!(fmt->flags & AVFMT_NOFILE)) {
+ if (url_fopen(&oc->pb, filename, URL_WRONLY) < 0) {
+ fprintf(stderr, "Could not open '%s'\n", filename);
+ exit(1);
+ }
+ }
+
+ /* write the stream header, if any */
+ av_write_header(oc);
+
+ for(;;) {
+ /* compute current audio and video time */
+ if (audio_st)
+ audio_pts = (double)audio_st->pts.val * audio_st->time_base.num / audio_st->time_base.den;
+ else
+ audio_pts = 0.0;
+
+ if (video_st)
+ video_pts = (double)video_st->pts.val * video_st->time_base.num / video_st->time_base.den;
+ else
+ video_pts = 0.0;
+
+ if ((!audio_st || audio_pts >= STREAM_DURATION) &&
+ (!video_st || video_pts >= STREAM_DURATION))
+ break;
+
+ /* write interleaved audio and video frames */
+ if (!video_st || (video_st && audio_st && audio_pts < video_pts)) {
+ write_audio_frame(oc, audio_st);
+ } else {
+ write_video_frame(oc, video_st);
+ }
+ }
+
+ /* close each codec */
+ if (video_st)
+ close_video(oc, video_st);
+ if (audio_st)
+ close_audio(oc, audio_st);
+
+ /* write the trailer, if any */
+ av_write_trailer(oc);
+
+ /* free the streams */
+ for(i = 0; i < oc->nb_streams; i++) {
+ av_freep(&oc->streams[i]->codec);
+ av_freep(&oc->streams[i]);
+ }
+
+ if (!(fmt->flags & AVFMT_NOFILE)) {
+ /* close the output file */
+ url_fclose(&oc->pb);
+ }
+
+ /* free the stream */
+ av_free(oc);
+
+ return 0;
+}
diff --git a/contrib/ffmpeg/pktdumper.c b/contrib/ffmpeg/pktdumper.c
new file mode 100644
index 000000000..d43f46b45
--- /dev/null
+++ b/contrib/ffmpeg/pktdumper.c
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2005 Francois Revol
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 <limits.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#define PKTFILESUFF "_%08"PRId64"_%02d_%010"PRId64"_%06d_%c.bin"
+
+static int usage(int ret)
+{
+ fprintf(stderr, "dump (up to maxpkts) AVPackets as they are demuxed by libavformat.\n");
+ fprintf(stderr, "each packet is dumped in its own file named like `basename file.ext`_$PKTNUM_$STREAMINDEX_$STAMP_$SIZE_$FLAGS.bin\n");
+ fprintf(stderr, "pktdumper [-nw] file [maxpkts]\n");
+ fprintf(stderr, "-n\twrite No file at all, only demux.\n");
+ fprintf(stderr, "-w\tWait at end of processing instead of quitting.\n");
+ return ret;
+}
+
+int main(int argc, char **argv)
+{
+ char fntemplate[PATH_MAX];
+ char pktfilename[PATH_MAX];
+ AVFormatContext *fctx;
+ AVPacket pkt;
+ int64_t pktnum = 0;
+ int64_t maxpkts = 0;
+ int dontquit = 0;
+ int nowrite = 0;
+ int err;
+
+ if ((argc > 1) && !strncmp(argv[1], "-", 1)) {
+ if (strchr(argv[1], 'w'))
+ dontquit = 1;
+ if (strchr(argv[1], 'n'))
+ nowrite = 1;
+ argv++;
+ argc--;
+ }
+ if (argc < 2)
+ return usage(1);
+ if (argc > 2)
+ maxpkts = atoi(argv[2]);
+ strncpy(fntemplate, argv[1], PATH_MAX-1);
+ if (strrchr(argv[1], '/'))
+ strncpy(fntemplate, strrchr(argv[1], '/')+1, PATH_MAX-1);
+ if (strrchr(fntemplate, '.'))
+ *strrchr(fntemplate, '.') = '\0';
+ if (strchr(fntemplate, '%')) {
+ fprintf(stderr, "can't use filenames containing '%%'\n");
+ return usage(1);
+ }
+ if (strlen(fntemplate) + sizeof(PKTFILESUFF) >= PATH_MAX-1) {
+ fprintf(stderr, "filename too long\n");
+ return usage(1);
+ }
+ strcat(fntemplate, PKTFILESUFF);
+ printf("FNTEMPLATE: '%s'\n", fntemplate);
+
+ // register all file formats
+ av_register_all();
+
+ err = av_open_input_file(&fctx, argv[1], NULL, 0, NULL);
+ if (err < 0) {
+ fprintf(stderr, "av_open_input_file: error %d\n", err);
+ return 1;
+ }
+
+ err = av_find_stream_info(fctx);
+ if (err < 0) {
+ fprintf(stderr, "av_find_stream_info: error %d\n", err);
+ return 1;
+ }
+
+ av_init_packet(&pkt);
+
+ while ((err = av_read_frame(fctx, &pkt)) >= 0) {
+ int fd;
+ snprintf(pktfilename, PATH_MAX-1, fntemplate, pktnum, pkt.stream_index, pkt.pts, pkt.size, (pkt.flags & PKT_FLAG_KEY)?'K':'_');
+ printf(PKTFILESUFF"\n", pktnum, pkt.stream_index, pkt.pts, pkt.size, (pkt.flags & PKT_FLAG_KEY)?'K':'_');
+ //printf("open(\"%s\")\n", pktfilename);
+ if (!nowrite) {
+ fd = open(pktfilename, O_WRONLY|O_CREAT, 0644);
+ write(fd, pkt.data, pkt.size);
+ close(fd);
+ }
+ pktnum++;
+ if (maxpkts && (pktnum >= maxpkts))
+ break;
+ }
+
+ while (dontquit)
+ sleep(60);
+
+ return 0;
+}
diff --git a/contrib/ffmpeg/qt-faststart.c b/contrib/ffmpeg/qt-faststart.c
new file mode 100644
index 000000000..2cbf12b1d
--- /dev/null
+++ b/contrib/ffmpeg/qt-faststart.c
@@ -0,0 +1,311 @@
+/*
+ * qt-faststart.c, v0.1
+ * by Mike Melanson (melanson@pcisys.net)
+ * This file is placed in the public domain. Use the program however you
+ * see fit.
+ *
+ * This utility rearranges a Quicktime file such that the moov atom
+ * is in front of the data, thus facilitating network streaming.
+ *
+ * Compile this program using:
+ * make qt-faststart
+ * Invoke the program with:
+ * qt-faststart <infile.mov> <outfile.mov>
+ *
+ * Notes: Quicktime files can come in many configurations of top-level
+ * atoms. This utility stipulates that the very last atom in the file needs
+ * to be a moov atom. When given such a file, this utility will rearrange
+ * the top-level atoms by shifting the moov atom from the back of the file
+ * to the front, and patch the chunk offsets along the way. This utility
+ * presently only operates on uncompressed moov atoms.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <inttypes.h>
+
+#ifdef __MINGW32__
+#define fseeko(x,y,z) fseeko64(x,y,z)
+#define ftello(x) ftello64(x)
+#endif
+
+#define BE_16(x) ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1])
+#define BE_32(x) ((((uint8_t*)(x))[0] << 24) | \
+ (((uint8_t*)(x))[1] << 16) | \
+ (((uint8_t*)(x))[2] << 8) | \
+ ((uint8_t*)(x))[3])
+#define BE_64(x) (((uint64_t)(((uint8_t*)(x))[0]) << 56) | \
+ ((uint64_t)(((uint8_t*)(x))[1]) << 48) | \
+ ((uint64_t)(((uint8_t*)(x))[2]) << 40) | \
+ ((uint64_t)(((uint8_t*)(x))[3]) << 32) | \
+ ((uint64_t)(((uint8_t*)(x))[4]) << 24) | \
+ ((uint64_t)(((uint8_t*)(x))[5]) << 16) | \
+ ((uint64_t)(((uint8_t*)(x))[6]) << 8) | \
+ ((uint64_t)((uint8_t*)(x))[7]))
+
+#define BE_FOURCC( ch0, ch1, ch2, ch3 ) \
+ ( (uint32_t)(unsigned char)(ch3) | \
+ ( (uint32_t)(unsigned char)(ch2) << 8 ) | \
+ ( (uint32_t)(unsigned char)(ch1) << 16 ) | \
+ ( (uint32_t)(unsigned char)(ch0) << 24 ) )
+
+#define QT_ATOM BE_FOURCC
+/* top level atoms */
+#define FREE_ATOM QT_ATOM('f', 'r', 'e', 'e')
+#define JUNK_ATOM QT_ATOM('j', 'u', 'n', 'k')
+#define MDAT_ATOM QT_ATOM('m', 'd', 'a', 't')
+#define MOOV_ATOM QT_ATOM('m', 'o', 'o', 'v')
+#define PNOT_ATOM QT_ATOM('p', 'n', 'o', 't')
+#define SKIP_ATOM QT_ATOM('s', 'k', 'i', 'p')
+#define WIDE_ATOM QT_ATOM('w', 'i', 'd', 'e')
+#define PICT_ATOM QT_ATOM('P', 'I', 'C', 'T')
+#define FTYP_ATOM QT_ATOM('f', 't', 'y', 'p')
+
+#define CMOV_ATOM QT_ATOM('c', 'm', 'o', 'v')
+#define STCO_ATOM QT_ATOM('s', 't', 'c', 'o')
+#define CO64_ATOM QT_ATOM('c', 'o', '6', '4')
+
+#define ATOM_PREAMBLE_SIZE 8
+#define COPY_BUFFER_SIZE 1024
+
+int main(int argc, char *argv[])
+{
+ FILE *infile;
+ FILE *outfile;
+ unsigned char atom_bytes[ATOM_PREAMBLE_SIZE];
+ uint32_t atom_type = 0;
+ uint64_t atom_size = 0;
+ uint64_t last_offset;
+ unsigned char *moov_atom;
+ unsigned char *ftyp_atom = 0;
+ uint64_t moov_atom_size;
+ uint64_t ftyp_atom_size = 0;
+ uint64_t i, j;
+ uint32_t offset_count;
+ uint64_t current_offset;
+ uint64_t start_offset = 0;
+ unsigned char copy_buffer[COPY_BUFFER_SIZE];
+ int bytes_to_copy;
+
+ if (argc != 3) {
+ printf ("Usage: qt-faststart <infile.mov> <outfile.mov>\n");
+ return 0;
+ }
+
+ infile = fopen(argv[1], "rb");
+ if (!infile) {
+ perror(argv[1]);
+ return 1;
+ }
+
+ /* traverse through the atoms in the file to make sure that 'moov' is
+ * at the end */
+ while (!feof(infile)) {
+ if (fread(atom_bytes, ATOM_PREAMBLE_SIZE, 1, infile) != 1) {
+ break;
+ }
+ atom_size = (uint32_t)BE_32(&atom_bytes[0]);
+ atom_type = BE_32(&atom_bytes[4]);
+
+ if ((atom_type != FREE_ATOM) &&
+ (atom_type != JUNK_ATOM) &&
+ (atom_type != MDAT_ATOM) &&
+ (atom_type != MOOV_ATOM) &&
+ (atom_type != PNOT_ATOM) &&
+ (atom_type != SKIP_ATOM) &&
+ (atom_type != WIDE_ATOM) &&
+ (atom_type != PICT_ATOM) &&
+ (atom_type != FTYP_ATOM)) {
+ printf ("encountered non-QT top-level atom (is this a Quicktime file?)\n");
+ break;
+ }
+
+ /* keep ftyp atom */
+ if (atom_type == FTYP_ATOM) {
+ ftyp_atom_size = atom_size;
+ ftyp_atom = malloc(ftyp_atom_size);
+ if (!ftyp_atom) {
+ printf ("could not allocate 0x%llX byte for ftyp atom\n",
+ atom_size);
+ fclose(infile);
+ return 1;
+ }
+ fseeko(infile, -ATOM_PREAMBLE_SIZE, SEEK_CUR);
+ if (fread(ftyp_atom, atom_size, 1, infile) != 1) {
+ perror(argv[1]);
+ free(ftyp_atom);
+ fclose(infile);
+ return 1;
+ }
+ start_offset = ftello(infile);
+ continue;
+ }
+
+ /* 64-bit special case */
+ if (atom_size == 1) {
+ if (fread(atom_bytes, ATOM_PREAMBLE_SIZE, 1, infile) != 1) {
+ break;
+ }
+ atom_size = BE_64(&atom_bytes[0]);
+ fseeko(infile, atom_size - ATOM_PREAMBLE_SIZE * 2, SEEK_CUR);
+ } else {
+ fseeko(infile, atom_size - ATOM_PREAMBLE_SIZE, SEEK_CUR);
+ }
+ }
+
+ if (atom_type != MOOV_ATOM) {
+ printf ("last atom in file was not a moov atom\n");
+ fclose(infile);
+ return 0;
+ }
+
+ /* moov atom was, in fact, the last atom in the chunk; load the whole
+ * moov atom */
+ fseeko(infile, -atom_size, SEEK_END);
+ last_offset = ftello(infile);
+ moov_atom_size = atom_size;
+ moov_atom = malloc(moov_atom_size);
+ if (!moov_atom) {
+ printf ("could not allocate 0x%llX byte for moov atom\n",
+ atom_size);
+ fclose(infile);
+ return 1;
+ }
+ if (fread(moov_atom, atom_size, 1, infile) != 1) {
+ perror(argv[1]);
+ free(moov_atom);
+ fclose(infile);
+ return 1;
+ }
+
+ /* this utility does not support compressed atoms yet, so disqualify
+ * files with compressed QT atoms */
+ if (BE_32(&moov_atom[12]) == CMOV_ATOM) {
+ printf ("this utility does not support compressed moov atoms yet\n");
+ free(moov_atom);
+ fclose(infile);
+ return 1;
+ }
+
+ /* close; will be re-opened later */
+ fclose(infile);
+
+ /* crawl through the moov chunk in search of stco or co64 atoms */
+ for (i = 4; i < moov_atom_size - 4; i++) {
+ atom_type = BE_32(&moov_atom[i]);
+ if (atom_type == STCO_ATOM) {
+ printf (" patching stco atom...\n");
+ atom_size = BE_32(&moov_atom[i - 4]);
+ if (i + atom_size - 4 > moov_atom_size) {
+ printf (" bad atom size\n");
+ free(moov_atom);
+ return 1;
+ }
+ offset_count = BE_32(&moov_atom[i + 8]);
+ for (j = 0; j < offset_count; j++) {
+ current_offset = BE_32(&moov_atom[i + 12 + j * 4]);
+ current_offset += moov_atom_size;
+ moov_atom[i + 12 + j * 4 + 0] = (current_offset >> 24) & 0xFF;
+ moov_atom[i + 12 + j * 4 + 1] = (current_offset >> 16) & 0xFF;
+ moov_atom[i + 12 + j * 4 + 2] = (current_offset >> 8) & 0xFF;
+ moov_atom[i + 12 + j * 4 + 3] = (current_offset >> 0) & 0xFF;
+ }
+ i += atom_size - 4;
+ } else if (atom_type == CO64_ATOM) {
+ printf (" patching co64 atom...\n");
+ atom_size = BE_32(&moov_atom[i - 4]);
+ if (i + atom_size - 4 > moov_atom_size) {
+ printf (" bad atom size\n");
+ free(moov_atom);
+ return 1;
+ }
+ offset_count = BE_32(&moov_atom[i + 8]);
+ for (j = 0; j < offset_count; j++) {
+ current_offset = BE_64(&moov_atom[i + 12 + j * 8]);
+ current_offset += moov_atom_size;
+ moov_atom[i + 12 + j * 8 + 0] = (current_offset >> 56) & 0xFF;
+ moov_atom[i + 12 + j * 8 + 1] = (current_offset >> 48) & 0xFF;
+ moov_atom[i + 12 + j * 8 + 2] = (current_offset >> 40) & 0xFF;
+ moov_atom[i + 12 + j * 8 + 3] = (current_offset >> 32) & 0xFF;
+ moov_atom[i + 12 + j * 8 + 4] = (current_offset >> 24) & 0xFF;
+ moov_atom[i + 12 + j * 8 + 5] = (current_offset >> 16) & 0xFF;
+ moov_atom[i + 12 + j * 8 + 6] = (current_offset >> 8) & 0xFF;
+ moov_atom[i + 12 + j * 8 + 7] = (current_offset >> 0) & 0xFF;
+ }
+ i += atom_size - 4;
+ }
+ }
+
+ /* re-open the input file and open the output file */
+ infile = fopen(argv[1], "rb");
+ if (!infile) {
+ perror(argv[1]);
+ free(moov_atom);
+ return 1;
+ }
+
+ if (start_offset > 0) { /* seek after ftyp atom */
+ fseeko(infile, start_offset, SEEK_SET);
+ last_offset -= start_offset;
+ }
+
+ outfile = fopen(argv[2], "wb");
+ if (!outfile) {
+ perror(argv[2]);
+ fclose(outfile);
+ free(moov_atom);
+ return 1;
+ }
+
+ /* dump the same ftyp atom */
+ if (ftyp_atom_size > 0) {
+ printf (" writing ftyp atom...\n");
+ if (fwrite(ftyp_atom, ftyp_atom_size, 1, outfile) != 1) {
+ perror(argv[2]);
+ goto error_out;
+ }
+ }
+
+ /* dump the new moov atom */
+ printf (" writing moov atom...\n");
+ if (fwrite(moov_atom, moov_atom_size, 1, outfile) != 1) {
+ perror(argv[2]);
+ goto error_out;
+ }
+
+ /* copy the remainder of the infile, from offset 0 -> last_offset - 1 */
+ printf (" copying rest of file...\n");
+ while (last_offset) {
+ if (last_offset > COPY_BUFFER_SIZE)
+ bytes_to_copy = COPY_BUFFER_SIZE;
+ else
+ bytes_to_copy = last_offset;
+
+ if (fread(copy_buffer, bytes_to_copy, 1, infile) != 1) {
+ perror(argv[1]);
+ goto error_out;
+ }
+ if (fwrite(copy_buffer, bytes_to_copy, 1, outfile) != 1) {
+ perror(argv[2]);
+ goto error_out;
+ }
+
+ last_offset -= bytes_to_copy;
+ }
+
+ fclose(infile);
+ fclose(outfile);
+ free(moov_atom);
+ if (ftyp_atom_size > 0)
+ free(ftyp_atom);
+
+ return 0;
+
+error_out:
+ fclose(infile);
+ fclose(outfile);
+ free(moov_atom);
+ if (ftyp_atom_size > 0)
+ free(ftyp_atom);
+ return 1;
+}
diff --git a/contrib/ffmpeg/tests/Makefile b/contrib/ffmpeg/tests/Makefile
new file mode 100644
index 000000000..3417c687e
--- /dev/null
+++ b/contrib/ffmpeg/tests/Makefile
@@ -0,0 +1,114 @@
+#
+# Makefile for tests
+# (c) 2002 Fabrice Bellard
+#
+include ../config.mak
+
+VPATH=$(SRC_PATH_BARE)/tests
+SRC_DIR=$(SRC_PATH)/tests
+BUILD_DIR=$(BUILD_ROOT)/tests
+CFLAGS=-O2 -Wall -g
+
+REFFILE1=$(SRC_DIR)/ffmpeg.regression.ref
+REFFILE2=$(SRC_DIR)/rotozoom.regression.ref
+
+SERVER_REFFILE=$(SRC_DIR)/ffserver.regression.ref
+
+LIBAV_REFFILE=$(SRC_DIR)/libav.regression.ref
+
+SEEK_REFFILE=$(SRC_DIR)/seek.regression.ref
+
+all fulltest test: codectest libavtest
+
+test-server: vsynth1/00.pgm asynth1.sw
+ @echo
+ @echo "Unfortunately ffserver is broken and therefore its regression"
+ @echo "test fails randomly. Treat the results accordingly."
+ @echo
+ @$(SRC_DIR)/server-regression.sh $(SERVER_REFFILE) $(SRC_DIR)/test.conf
+
+# fast regression tests for all codecs
+codectest mpeg4 mpeg ac3 snow snowll: vsynth1/00.pgm vsynth2/00.pgm asynth1.sw tiny_psnr$(EXESUF)
+ @$(SRC_DIR)/regression.sh $@ $(REFFILE1) vsynth1
+ @$(SRC_DIR)/regression.sh $@ $(REFFILE2) vsynth2
+
+# fast regression for libav formats
+ifeq ($(CONFIG_GPL),yes)
+libavtest: vsynth1/00.pgm asynth1.sw
+ @$(SRC_DIR)/regression.sh $@ $(LIBAV_REFFILE) vsynth1
+else
+libavtest:
+ @echo
+ @echo "This test requires FFmpeg to be compiled with --enable-gpl."
+ @echo
+endif
+
+ifeq ($(CONFIG_SWSCALER),yes)
+test-server codectest mpeg4 mpeg ac3 snow snowll libavtest: swscale_error
+swscale_error:
+ @echo
+ @echo "This regression test is incompatible with --enable-swscaler."
+ @echo
+ @exit 1
+endif
+
+seektest: seek_test$(EXESUF)
+ @$(SRC_DIR)/seek_test.sh $(SEEK_REFFILE)
+
+# video generation
+
+vsynth1/00.pgm: videogen$(EXESUF)
+ @mkdir -p vsynth1
+ $(BUILD_DIR)/$< 'vsynth1/'
+
+vsynth2/00.pgm: rotozoom$(EXESUF)
+ @mkdir -p vsynth2
+ $(BUILD_DIR)/$< 'vsynth2/' $(SRC_DIR)/lena.pnm
+
+videogen$(EXESUF): videogen.c
+ $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $<
+
+rotozoom$(EXESUF): rotozoom.c
+ $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $<
+
+# audio generation
+
+asynth1.sw: audiogen$(EXESUF)
+ $(BUILD_DIR)/$< $@
+
+audiogen$(EXESUF): audiogen.c
+ $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $<
+
+tiny_psnr$(EXESUF): tiny_psnr.c
+ $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $<
+
+#FIXME cleanup shit below
+seek_test$(EXESUF): seek_test.c
+ $(CC) $(LDFLAGS) $(CFLAGS) -DHAVE_AV_CONFIG_H -I.. -I$(SRC_PATH)/libavformat/ -I$(SRC_PATH)/libavcodec/ -I$(SRC_PATH)/libavutil/ -o $@ $< $(SRC_PATH)/libavformat/libavformat.a $(SRC_PATH)/libavcodec/libavcodec.a $(SRC_PATH)/libavutil/libavutil.a $(EXTRALIBS)
+
+DSPDEPS = $(SRC_PATH)/libavcodec/i386/dsputil_mmx.c \
+ $(SRC_PATH)/libavcodec/i386/dsputil_mmx_avg.h \
+ $(SRC_PATH)/libavcodec/i386/dsputil_mmx_rnd.h \
+ $(SRC_PATH)/libavcodec/i386/fdct_mmx.c \
+ $(SRC_PATH)/libavcodec/i386/idct_mmx.c \
+ $(SRC_PATH)/libavcodec/i386/motion_est_mmx.c \
+ $(SRC_PATH)/libavcodec/i386/simple_idct_mmx.c \
+ $(SRC_PATH)/libavcodec/dsputil.c \
+ $(SRC_PATH)/libavcodec/dsputil.h \
+ $(SRC_PATH)/libavcodec/simple_idct.c
+
+DSPCFLAGS = -O4 -fomit-frame-pointer -DHAVE_AV_CONFIG_H -I.. \
+ -I$(SRC_PATH)/libavutil/ -I$(SRC_PATH)/libavcodec/i386 \
+ -I$(SRC_PATH)/libavcodec/ -lm
+
+dsptestpic: dsptest.c $(DSPDEPS)
+ $(CC) -fPIC -DPIC $(DSPCFLAGS) -o $@ $<
+dsptest: dsptest.c $(DSPDEPS)
+ $(CC) $(DSPCFLAGS) -o $@ $<
+
+distclean clean:
+ rm -rf vsynth1 vsynth2 data
+ rm -f asynth1.sw *~ audiogen$(EXESUF) videogen$(EXESUF) rotozoom$(EXESUF) tiny_psnr$(EXESUF)
+
+.PHONY: all fulltest test codectest libavtest test-server seektest
+.PHONY: mpeg4 mpeg ac3 snow snowll distclean clean
diff --git a/contrib/ffmpeg/tests/audiogen.c b/contrib/ffmpeg/tests/audiogen.c
new file mode 100644
index 000000000..68ae13586
--- /dev/null
+++ b/contrib/ffmpeg/tests/audiogen.c
@@ -0,0 +1,187 @@
+/*
+ * Generates a synthetic stereo sound
+ * NOTE: no floats are used to guaranty a bit exact output.
+ *
+ * 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
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#define NB_CHANNELS 2
+#define FE 44100
+
+static unsigned int myrnd(unsigned int *seed_ptr, int n)
+{
+ unsigned int seed, val;
+
+ seed = *seed_ptr;
+ seed = (seed * 314159) + 1;
+ if (n == 256) {
+ val = seed >> 24;
+ } else {
+ val = seed % n;
+ }
+ *seed_ptr = seed;
+ return val;
+}
+
+#define FRAC_BITS 16
+#define FRAC_ONE (1 << FRAC_BITS)
+
+#define COS_TABLE_BITS 7
+
+/* integer cosinus */
+static const unsigned short cos_table[(1 << COS_TABLE_BITS) + 2] = {
+ 0x8000, 0x7ffe, 0x7ff6, 0x7fea, 0x7fd9, 0x7fc2, 0x7fa7, 0x7f87,
+ 0x7f62, 0x7f38, 0x7f0a, 0x7ed6, 0x7e9d, 0x7e60, 0x7e1e, 0x7dd6,
+ 0x7d8a, 0x7d3a, 0x7ce4, 0x7c89, 0x7c2a, 0x7bc6, 0x7b5d, 0x7aef,
+ 0x7a7d, 0x7a06, 0x798a, 0x790a, 0x7885, 0x77fb, 0x776c, 0x76d9,
+ 0x7642, 0x75a6, 0x7505, 0x7460, 0x73b6, 0x7308, 0x7255, 0x719e,
+ 0x70e3, 0x7023, 0x6f5f, 0x6e97, 0x6dca, 0x6cf9, 0x6c24, 0x6b4b,
+ 0x6a6e, 0x698c, 0x68a7, 0x67bd, 0x66d0, 0x65de, 0x64e9, 0x63ef,
+ 0x62f2, 0x61f1, 0x60ec, 0x5fe4, 0x5ed7, 0x5dc8, 0x5cb4, 0x5b9d,
+ 0x5a82, 0x5964, 0x5843, 0x571e, 0x55f6, 0x54ca, 0x539b, 0x5269,
+ 0x5134, 0x4ffb, 0x4ec0, 0x4d81, 0x4c40, 0x4afb, 0x49b4, 0x486a,
+ 0x471d, 0x45cd, 0x447b, 0x4326, 0x41ce, 0x4074, 0x3f17, 0x3db8,
+ 0x3c57, 0x3af3, 0x398d, 0x3825, 0x36ba, 0x354e, 0x33df, 0x326e,
+ 0x30fc, 0x2f87, 0x2e11, 0x2c99, 0x2b1f, 0x29a4, 0x2827, 0x26a8,
+ 0x2528, 0x23a7, 0x2224, 0x209f, 0x1f1a, 0x1d93, 0x1c0c, 0x1a83,
+ 0x18f9, 0x176e, 0x15e2, 0x1455, 0x12c8, 0x113a, 0x0fab, 0x0e1c,
+ 0x0c8c, 0x0afb, 0x096b, 0x07d9, 0x0648, 0x04b6, 0x0324, 0x0192,
+ 0x0000, 0x0000,
+};
+
+#define CSHIFT (FRAC_BITS - COS_TABLE_BITS - 2)
+
+static int int_cos(int a)
+{
+ int neg, v, f;
+ const unsigned short *p;
+
+ a = a & (FRAC_ONE - 1); /* modulo 2 * pi */
+ if (a >= (FRAC_ONE / 2))
+ a = FRAC_ONE - a;
+ neg = 0;
+ if (a > (FRAC_ONE / 4)) {
+ neg = -1;
+ a = (FRAC_ONE / 2) - a;
+ }
+ p = cos_table + (a >> CSHIFT);
+ /* linear interpolation */
+ f = a & ((1 << CSHIFT) - 1);
+ v = p[0] + (((p[1] - p[0]) * f + (1 << (CSHIFT - 1))) >> CSHIFT);
+ v = (v ^ neg) - neg;
+ v = v << (FRAC_BITS - 15);
+ return v;
+}
+
+FILE *outfile;
+
+void put_sample(int v)
+{
+ fputc(v & 0xff, outfile);
+ fputc((v >> 8) & 0xff, outfile);
+}
+
+int main(int argc, char **argv)
+{
+ int i, a, v, j, f, amp, ampa;
+ unsigned int seed = 1;
+ int tabf1[NB_CHANNELS], tabf2[NB_CHANNELS];
+ int taba[NB_CHANNELS];
+
+ if (argc != 2) {
+ printf("usage: %s file\n"
+ "generate a test raw 16 bit stereo audio stream\n", argv[0]);
+ exit(1);
+ }
+
+ outfile = fopen(argv[1], "wb");
+ if (!outfile) {
+ perror(argv[1]);
+ return 1;
+ }
+
+ /* 1 second of single freq sinus at 1000 Hz */
+ a = 0;
+ for(i=0;i<1 * FE;i++) {
+ v = (int_cos(a) * 10000) >> FRAC_BITS;
+ for(j=0;j<NB_CHANNELS;j++)
+ put_sample(v);
+ a += (1000 * FRAC_ONE) / FE;
+ }
+
+ /* 1 second of varing frequency between 100 and 10000 Hz */
+ a = 0;
+ for(i=0;i<1 * FE;i++) {
+ v = (int_cos(a) * 10000) >> FRAC_BITS;
+ for(j=0;j<NB_CHANNELS;j++)
+ put_sample(v);
+ f = 100 + (((10000 - 100) * i) / FE);
+ a += (f * FRAC_ONE) / FE;
+ }
+
+ /* 0.5 second of low amplitude white noise */
+ for(i=0;i<FE / 2;i++) {
+ v = myrnd(&seed, 20000) - 10000;
+ for(j=0;j<NB_CHANNELS;j++)
+ put_sample(v);
+ }
+
+ /* 0.5 second of high amplitude white noise */
+ for(i=0;i<FE / 2;i++) {
+ v = myrnd(&seed, 65535) - 32768;
+ for(j=0;j<NB_CHANNELS;j++)
+ put_sample(v);
+ }
+
+ /* stereo : 2 unrelated ramps */
+ for(j=0;j<NB_CHANNELS;j++) {
+ taba[j] = 0;
+ tabf1[j] = 100 + myrnd(&seed, 5000);
+ tabf2[j] = 100 + myrnd(&seed, 5000);
+ }
+ for(i=0;i<1 * FE;i++) {
+ for(j=0;j<NB_CHANNELS;j++) {
+ v = (int_cos(taba[j]) * 10000) >> FRAC_BITS;
+ put_sample(v);
+ f = tabf1[j] + (((tabf2[j] - tabf1[j]) * i) / FE);
+ taba[j] += (f * FRAC_ONE) / FE;
+ }
+ }
+
+ /* stereo 500 Hz with varying volume */
+ a = 0;
+ ampa = 0;
+ for(i=0;i<2 * FE;i++) {
+ for(j=0;j<NB_CHANNELS;j++) {
+ amp = ((FRAC_ONE + int_cos(ampa)) * 5000) >> FRAC_BITS;
+ if (j & 1)
+ amp = 10000 - amp;
+ v = (int_cos(a) * amp) >> FRAC_BITS;
+ put_sample(v);
+ a += (500 * FRAC_ONE) / FE;
+ ampa += (2 * FRAC_ONE) / FE;
+ }
+ }
+
+ fclose(outfile);
+ return 0;
+}
diff --git a/contrib/ffmpeg/tests/dsptest.c b/contrib/ffmpeg/tests/dsptest.c
new file mode 100644
index 000000000..06a185202
--- /dev/null
+++ b/contrib/ffmpeg/tests/dsptest.c
@@ -0,0 +1,178 @@
+/*
+ * MMX optimized DSP utils
+ * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#define TESTCPU_MAIN
+#include "avcodec.h"
+#include "dsputil.h"
+#include "mpegvideo.h"
+#include "mpeg12data.h"
+#include "mpeg4data.h"
+#include "../libavcodec/i386/cputest.c"
+#include "../libavcodec/i386/dsputil_mmx.c"
+
+#include "../libavcodec/i386/fdct_mmx.c"
+#include "../libavcodec/i386/idct_mmx.c"
+#include "../libavcodec/i386/motion_est_mmx.c"
+#include "../libavcodec/i386/simple_idct_mmx.c"
+#include "../libavcodec/dsputil.c"
+#include "../libavcodec/simple_idct.c"
+#include "../libavcodec/jfdctfst.c"
+
+#undef TESTCPU_MAIN
+
+#define PAD 0x10000
+/*
+ * for testing speed of various routine - should be probably extended
+ * for a general purpose regression test later
+ *
+ * currently only for i386 - FIXME
+ */
+
+#define PIX_FUNC_C(a) \
+ { #a "_c", a ## _c, 0 }, \
+ { #a "_mmx", a ## _mmx, MM_MMX }, \
+ { #a "_mmx2", a ## _mmx2, MM_MMXEXT | PAD }
+
+#define PIX_FUNC(a) \
+ { #a "_mmx", a ## _mmx, MM_MMX }, \
+ { #a "_3dnow", a ## _3dnow, MM_3DNOW }, \
+ { #a "_mmx2", a ## _mmx2, MM_MMXEXT | PAD }
+
+#define PIX_FUNC_MMX(a) \
+ { #a "_mmx", a ## _mmx, MM_MMX | PAD }
+
+/*
+ PIX_FUNC_C(pix_abs16x16),
+ PIX_FUNC_C(pix_abs16x16_x2),
+ PIX_FUNC_C(pix_abs16x16_y2),
+ PIX_FUNC_C(pix_abs16x16_xy2),
+ PIX_FUNC_C(pix_abs8x8),
+ PIX_FUNC_C(pix_abs8x8_x2),
+ PIX_FUNC_C(pix_abs8x8_y2),
+ PIX_FUNC_C(pix_abs8x8_xy2),
+*/
+
+static const struct pix_func {
+ char* name;
+ op_pixels_func func;
+ int mm_flags;
+} pix_func[] = {
+
+ PIX_FUNC_MMX(put_pixels),
+ //PIX_FUNC_MMX(get_pixels),
+ //PIX_FUNC_MMX(put_pixels_clamped),
+#if 1
+ PIX_FUNC(put_pixels_x2),
+ PIX_FUNC(put_pixels_y2),
+ PIX_FUNC_MMX(put_pixels_xy2),
+
+ PIX_FUNC(put_no_rnd_pixels_x2),
+ PIX_FUNC(put_no_rnd_pixels_y2),
+ PIX_FUNC_MMX(put_no_rnd_pixels_xy2),
+
+ PIX_FUNC(avg_pixels),
+ PIX_FUNC(avg_pixels_x2),
+ PIX_FUNC(avg_pixels_y2),
+ PIX_FUNC(avg_pixels_xy2),
+
+ PIX_FUNC_MMX(avg_no_rnd_pixels),
+ PIX_FUNC_MMX(avg_no_rnd_pixels_x2),
+ PIX_FUNC_MMX(avg_no_rnd_pixels_y2),
+ PIX_FUNC_MMX(avg_no_rnd_pixels_xy2),
+#endif
+ { 0, 0 }
+};
+
+static inline long long rdtsc()
+{
+ long long l;
+ asm volatile( "rdtsc\n\t"
+ : "=A" (l)
+ );
+ return l;
+}
+
+static test_speed(int step)
+{
+ const struct pix_func* pix = pix_func;
+ const int linesize = 720;
+ char empty[32768];
+ char* bu =(char*)(((long)empty + 32) & ~0xf);
+
+ int sum = 0;
+
+ while (pix->name)
+ {
+ int i;
+ uint64_t te, ts;
+ op_pixels_func func = pix->func;
+ char* im = bu;
+
+ if (pix->mm_flags & mm_flags)
+ {
+ printf("%30s... ", pix->name);
+ fflush(stdout);
+ ts = rdtsc();
+ for(i=0; i<100000; i++){
+ func(im, im + 1000, linesize, 16);
+ im += step;
+ if (im > bu + 20000)
+ im = bu;
+ }
+ te = rdtsc();
+ emms();
+ printf("% 9d\n", (int)(te - ts));
+ sum += (te - ts) / 100000;
+ if (pix->mm_flags & PAD)
+ puts("");
+ }
+ pix++;
+ }
+
+ printf("Total sum: %d\n", sum);
+}
+
+int main(int argc, char* argv[])
+{
+ int step = 16;
+
+ if (argc > 1)
+ {
+ // something simple for now
+ if (argc > 2 && (strcmp("-s", argv[1]) == 0
+ || strcmp("-step", argv[1]) == 0))
+ step = atoi(argv[2]);
+ }
+
+ mm_flags = mm_support();
+ printf("%s: detected CPU flags:", argv[0]);
+ if (mm_flags & MM_MMX)
+ printf(" mmx");
+ if (mm_flags & MM_MMXEXT)
+ printf(" mmxext");
+ if (mm_flags & MM_3DNOW)
+ printf(" 3dnow");
+ if (mm_flags & MM_SSE)
+ printf(" sse");
+ if (mm_flags & MM_SSE2)
+ printf(" sse2");
+ printf("\n");
+
+ printf("Using step: %d\n", step);
+ test_speed(step);
+}
diff --git a/contrib/ffmpeg/tests/ffmpeg.regression.ref b/contrib/ffmpeg/tests/ffmpeg.regression.ref
new file mode 100644
index 000000000..ae5355406
--- /dev/null
+++ b/contrib/ffmpeg/tests/ffmpeg.regression.ref
@@ -0,0 +1,198 @@
+ffmpeg regression test
+dd4c189859399f7f251876be8e26e4f3 *./data/a-mpeg1.mpg
+722848 ./data/a-mpeg1.mpg
+78d202830e5ce5a67495ab14ebe6469e *./data/out.yuv
+stddev: 7.65 PSNR:30.44 bytes:7602176
+f3b008355f68394b6cad694f3488ea2b *./data/a-mpeg2.mpg
+736978 ./data/a-mpeg2.mpg
+9f364a477987c3b14412e303b94377ca *./data/out.yuv
+stddev: 7.68 PSNR:30.41 bytes:7602176
+1716f466ea82b4d90677868b2ce1f8e2 *./data/a-mpeg2ivlc-qprd.mpg
+708232 ./data/a-mpeg2ivlc-qprd.mpg
+40746946d5661606f7a649c62b6c4bee *./data/out.yuv
+stddev: 12.21 PSNR:26.38 bytes:7602176
+2566ea5760247a9485c8281cb52291a8 *./data/a-mpeg2.mpg
+735853 ./data/a-mpeg2.mpg
+55c22a09e4924977ee2cc4180078d3ae *./data/out.yuv
+stddev: 7.67 PSNR:30.42 bytes:7602176
+0093ab9141105dec8dc4452ba8f0ab6f *./data/a-mpeg2i.mpg
+749746 ./data/a-mpeg2i.mpg
+5189af71e6aa96cc2f6452e7f6b29287 *./data/out.yuv
+stddev: 7.68 PSNR:30.41 bytes:7602176
+69576facff13d45171e3a6c53b8018c4 *./data/a-mpeg2thread.mpg
+813459 ./data/a-mpeg2thread.mpg
+c0e8cbde76ff8377494fe6843fd03e11 *./data/out.yuv
+stddev: 7.63 PSNR:30.47 bytes:7602176
+17af99d1a7fc391242a809b0782263af *./data/a-mpeg2threadivlc.mpg
+803833 ./data/a-mpeg2threadivlc.mpg
+c0e8cbde76ff8377494fe6843fd03e11 *./data/out.yuv
+stddev: 7.63 PSNR:30.47 bytes:7602176
+c8d8b07b5fa97e0affb4a52d4d30a2b6 *./data/a-mpeg2reuse.mpg
+2102956 ./data/a-mpeg2reuse.mpg
+75d3dfc8133f0122cb9e272a21bc8c5c *./data/out.yuv
+stddev: 7.67 PSNR:30.42 bytes:7602176
+c83ae8d8f3e2b4506df58e6a2f7e3b2a *./data/a-msmpeg4v2.avi
+636512 ./data/a-msmpeg4v2.avi
+279c33c2f6f58b7eb3d2daaa87160cb5 *./data/out.yuv
+stddev: 8.00 PSNR:30.06 bytes:7602176
+f546e8d0ada1917bc470584477f83e0e *./data/a-msmpeg4.avi
+639406 ./data/a-msmpeg4.avi
+8692a2e9ddb8081c4f00cb1557e2388e *./data/out.yuv
+stddev: 8.00 PSNR:30.05 bytes:7602176
+44c11ce4aa20af1aa609f68e544e5479 *./data/a-wmv1.avi
+641448 ./data/a-wmv1.avi
+69454f78ca636e83a600834e5a90660e *./data/out.yuv
+stddev: 8.01 PSNR:30.04 bytes:7602176
+044b1b5bd5899d54a8fe09eac2181d8b *./data/a-wmv2.avi
+675342 ./data/a-wmv2.avi
+69454f78ca636e83a600834e5a90660e *./data/out.yuv
+stddev: 8.01 PSNR:30.04 bytes:7602176
+12d215719748b4cf1adeaca4e519ba6c *./data/a-h261.avi
+727616 ./data/a-h261.avi
+bb2e71de01899ade4f850c180f9b0258 *./data/out.yuv
+stddev: 9.13 PSNR:28.90 bytes:7602176
+66d36048d15c3b04bd7bfc08ab977fae *./data/a-h263.avi
+673694 ./data/a-h263.avi
+d507be4253a9c8211a3738c58ba28118 *./data/out.yuv
+stddev: 8.06 PSNR:29.99 bytes:7602176
+e9e884a7c6b77d1aeeb4cb56ac150f92 *./data/a-h263p.avi
+2389564 ./data/a-h263p.avi
+0bb16a352798c997cb36e167f4fa8f3c *./data/out.yuv
+stddev: 2.07 PSNR:41.77 bytes:7602176
+3ee2dd25f141d520f61e5c01d08bdef1 *./data/a-odivx.mp4
+550787 ./data/a-odivx.mp4
+a1c691f3be526ecbf3be3152d5bab88c *./data/out.yuv
+stddev: 7.99 PSNR:30.06 bytes:7602176
+6c58e5707afe056b072d2ce21b3b8e4f *./data/a-huffyuv.avi
+7933744 ./data/a-huffyuv.avi
+799d3db687f6cdd7a837ec156efc171f *./data/out.yuv
+stddev: 0.00 PSNR:99.99 bytes:7602176
+b27e911f1563455700c93e6ae39715ca *./data/a-mpeg4-rc.avi
+813988 ./data/a-mpeg4-rc.avi
+f57311745de96b6551c175679b138efc *./data/out.yuv
+stddev: 10.40 PSNR:27.78 bytes:7602176
+85e2456a673041d528b242d78318fb65 *./data/a-mpeg4-adv.avi
+600188 ./data/a-mpeg4-adv.avi
+60edc5a67271e425d0a2a52981895b81 *./data/out.yuv
+stddev: 10.25 PSNR:27.91 bytes:7602176
+d099307d14c1a4daa145618ca0522888 *./data/a-mpeg4-qprd.avi
+657996 ./data/a-mpeg4-qprd.avi
+8a52c562082bad78cabb40ffa292ceec *./data/out.yuv
+stddev: 12.12 PSNR:26.44 bytes:7602176
+9192b10ae298ba325d53abf7b5b91ba3 *./data/a-mpeg4-adap.avi
+400650 ./data/a-mpeg4-adap.avi
+0ce1d1fbebc9e9178e1a1d4a32a5804c *./data/out.yuv
+stddev: 14.66 PSNR:24.80 bytes:7602176
+41b27141442f773eca9ef3d48d8d555a *./data/a-mpeg4-Q.avi
+878264 ./data/a-mpeg4-Q.avi
+8995abbcc97ed4767fcbc0bf46accd01 *./data/out.yuv
+stddev: 5.61 PSNR:33.13 bytes:7602176
+5fff534f0b958547dfdb811d4f289931 *./data/a-mpeg4-thread.avi
+761170 ./data/a-mpeg4-thread.avi
+fe1d119938f8a26174b38eeaa18dff85 *./data/out.yuv
+stddev: 12.31 PSNR:26.31 bytes:7602176
+c1dae02bddd79790266bc0a9f7d6eb0e *./data/a-mpeg4-PSP.mp4
+406449 ./data/a-mpeg4-PSP.mp4
+7315281e07830456208dff61337c982b *./data/a-error-mpeg4-adv.avi
+731526 ./data/a-error-mpeg4-adv.avi
+6ce2c82a0a9cf67a6991694473e9a306 *./data/out.yuv
+stddev: 18.23 PSNR:22.90 bytes:7602176
+b699b2fd005571dda3f8d34cb0ce7aec *./data/a-mpeg4-nr.avi
+688676 ./data/a-mpeg4-nr.avi
+2c16e13b1367022d52b0e75d93a734ba *./data/out.yuv
+stddev: 7.02 PSNR:31.18 bytes:7602176
+225ab004f6ac16e5ade3b453f45b9d96 *./data/a-mpeg1b.mpg
+1026429 ./data/a-mpeg1b.mpg
+dd9a471c6b2d1004a90e42f34707becf *./data/out.yuv
+stddev: 6.34 PSNR:32.07 bytes:7602176
+2f9cb2ede35f7d12f6b518c50e20d81c *./data/a-mjpeg.avi
+1567580 ./data/a-mjpeg.avi
+18c3a76f984e717dd886d21fa04355f6 *./data/out.yuv
+stddev: 7.93 PSNR:30.13 bytes:7602176
+5a662e3833d900b56cca79ba5ed5ec06 *./data/a-ljpeg.avi
+6264498 ./data/a-ljpeg.avi
+799d3db687f6cdd7a837ec156efc171f *./data/out.yuv
+stddev: 0.00 PSNR:99.99 bytes:7602176
+dca9d700da7857217408c310c501b9bc *./data/a-jpegls.avi
+9086676 ./data/a-jpegls.avi
+0f8637e9b861230aff9894825af83720 *./data/out.yuv
+stddev: 2.84 PSNR:39.04 bytes:7602176
+7eee6367442884321e27d15a26bc032a *./data/a-rv10.rm
+667915 ./data/a-rv10.rm
+d507be4253a9c8211a3738c58ba28118 *./data/out.yuv
+stddev: 8.06 PSNR:29.99 bytes:7602176
+55c73229105f35cbb06ee0dda215df2f *./data/a-rv20.rm
+640856 ./data/a-rv20.rm
+297dc46da1a256c0a97158c036c30c7f *./data/out.yuv
+stddev: 8.26 PSNR:29.77 bytes:7602176
+d13292f4583618d1b7b525a9ee010dff *./data/a-asv1.avi
+1488864 ./data/a-asv1.avi
+925320b74c7dfda5dc8378dd879ae2c3 *./data/out.yuv
+stddev: 20.00 PSNR:22.10 bytes:7602176
+2e50b590f32bf98bde82dbfaf180007a *./data/a-asv2.avi
+1454536 ./data/a-asv2.avi
+0b310840a6d3970595983491687669df *./data/out.yuv
+stddev: 18.82 PSNR:22.63 bytes:7602176
+cbdb25fe5bb6a895baf9799b8ccb3038 *./data/a-flv.flv
+649040 ./data/a-flv.flv
+40281942d6ee254f7d3027b8593b19be *./data/out.yuv
+stddev: 8.06 PSNR:29.99 bytes:7602176
+f8f51fa737add17f7fecaefa118b57ed *./data/a-ffv1.avi
+2654678 ./data/a-ffv1.avi
+799d3db687f6cdd7a837ec156efc171f *./data/out.yuv
+stddev: 0.00 PSNR:99.99 bytes:7602176
+9078723c943de5d79490f54b99e6ea9e *./data/a-snow.avi
+156656 ./data/a-snow.avi
+f2932084b52e2ede167c9ba21eae0656 *./data/out.yuv
+stddev: 23.14 PSNR:20.83 bytes:7602176
+ba999e86070aa971376e7f317a022c37 *./data/a-snow53.avi
+3519486 ./data/a-snow53.avi
+799d3db687f6cdd7a837ec156efc171f *./data/out.yuv
+stddev: 0.00 PSNR:99.99 bytes:7602176
+c299f64c3e85b928c5bfe71629cee006 *./data/a-dv.dv
+7200000 ./data/a-dv.dv
+3b9ead854b912e43ead976e4e86aab3b *./data/out.yuv
+stddev: 8.91 PSNR:29.12 bytes:7602176
+70dc9a58345e603094dedcac71e2dcd2 *./data/a-dv.dv
+14400000 ./data/a-dv.dv
+d727da8c7ce387ebe68845a1be916ee3 *./data/out.yuv
+stddev: 8.50 PSNR:29.52 bytes:7602176
+6860534864cad0de4b1af9f987aaf9bf *./data/a-svq1.mov
+1365791 ./data/a-svq1.mov
+fb0a97094a89d6f379535f615783d00c *./data/out.yuv
+stddev: 10.98 PSNR:27.30 bytes:7602176
+21f8ff9f1daacd9133683bb4ea0f50a4 *./data/a-mp2.mp2
+95712 ./data/a-mp2.mp2
+83f8df5d5f84480566af548bb037fceb *./data/out.wav
+stddev:9330.70 PSNR:16.92 bytes:1054720
+stddev:4396.13 PSNR:23.46 bytes:1052672
+aefe11ab5067621a1c674859d6413891 *./data/a-ac3.rm
+98203 ./data/a-ac3.rm
+39878597b1d65cce473639a7d8c93b02 *./data/a-g726.wav
+24279 ./data/a-g726.wav
+888f2f016e608d044a1bacbca5497ed2 *./data/out.wav
+stddev:8368.02 PSNR:17.87 bytes:96256
+de3f0e1f50b19bd8572fdd3dee2e72c4 *./data/a-adpcm_ima.wav
+266300 ./data/a-adpcm_ima.wav
+60178d48204f5662d91776e36eddc82e *./data/out.wav
+stddev:11441.89 PSNR:15.15 bytes:1054720
+628d4789cf9ee16a756ac54b7fd8650d *./data/a-adpcm_ms.wav
+267320 ./data/a-adpcm_ms.wav
+91a84bb4f319a3a0bf0c0441b3d3a529 *./data/out.wav
+stddev:1050.18 PSNR:35.89 bytes:1054720
+ab11d9151644cbff27827b7e89f37aa9 *./data/a-adpcm_yam.wav
+264248 ./data/a-adpcm_yam.wav
+e92cec8c07913ffb91ad2b11f79cdc00 *./data/out.wav
+stddev:18312.68 PSNR:11.06 bytes:1056768
+c3382f03ce2efb5d475240d288a33898 *./data/a-flac.flac
+353368 ./data/a-flac.flac
+c4228df189aad9567a037727d0e763e4 *./data/out.wav
+stddev: 33.31 PSNR:65.87 bytes:1040384
+0c406c4e4586ca27064e28637b662631 *./data/a-wmav1.asf
+106004 ./data/a-wmav1.asf
+stddev:12251.50 PSNR:14.56 bytes:1056768
+stddev:2106.00 PSNR:29.85 bytes:1048576
+82442aaa5fdbd327769e4c4ad369147e *./data/a-wmav2.asf
+106044 ./data/a-wmav2.asf
+stddev:12255.92 PSNR:14.55 bytes:1056768
+stddev:2099.31 PSNR:29.88 bytes:1048576
diff --git a/contrib/ffmpeg/tests/ffserver.regression.ref b/contrib/ffmpeg/tests/ffserver.regression.ref
new file mode 100644
index 000000000..851a40d22
--- /dev/null
+++ b/contrib/ffmpeg/tests/ffserver.regression.ref
@@ -0,0 +1,10 @@
+b33ed697236149e1503b60ca9f645b6f ff-test_h.avi
+3c104d3664ed260be9117ed1273c6dcc ff-test_l.avi
+d976848a9e4d5d8fc2659e4841cdece5 ff-test.swf
+5dd7a3cbc430f2534cdfc68030e4d5f5 ff-test_h.asf
+1111699f36f2fe2240d3e5c73827df50 ff-test_l.asf
+0b4c970507eeb57381c92c3309f2d982 ff-test_h.rm
+daaaa2e170f48f8bd423c0c45ab632c7 ff-test_l.rm
+e0dc91430660c619e97b5c82e0f398fc ff-test.jpg
+0346739ee6ba2d3bbacb9814d00d7d2d ff-test_small.jpg
+77a905f865ca536b6b92b9beb96beb94 ff-test.mjpg
diff --git a/contrib/ffmpeg/tests/lena.pnm b/contrib/ffmpeg/tests/lena.pnm
new file mode 100644
index 000000000..700508c86
--- /dev/null
+++ b/contrib/ffmpeg/tests/lena.pnm
@@ -0,0 +1,109 @@
+P6
+# CREATOR: The GIMP's PNM Filter Version 1.0
+256 256
+255
+â‰}߈‚â†väˆ|âŠ{â†|à†rÞ„uÝ„nÞŠvß‚kÞ„jÜ„pà€gÝ‚tÞsà‚jà„râŠvæŠrèŽrè’wì—zè—yî•vê”xévè†tàwfØvvÊZa´P_¨@Tœ>\œ=Y¤EX¦GXªJZ®IZ²J\²NW±JV¯LV°OZ²LX²LX´NX²LV²NZ°NZ®JS´JT´OV¸SY¼TZÂXZÂTXÂZYÄ^ZÄ[\Ê`\Ê^\Ë\ZÌf_Îb^ÎebÌabËbbËkhÍffÎd`Ìb]Îb`Ê`^Êg_Ëd^Ëd`Ëa^ÎhaÎhjÑb^ÐebÐfaÐgfÒebÔe`ÒddÒfbÒgdÎheÎf`Ïd^ÐffÐjfÌfeÎfbÎjfÐgbÓidÑibÐicÎhjÒheÊghÊknÎhlÌffËe_ÇddÌf^Îe]ÍcbÊcbÈjhÍibÍdaÎddÎdbÒb\Ðe`ÑhbÒf`Ðg`ÐjdÑd\ÏfdÎ``ÎjjÒplÍgcÌd_ÈbbÒe`Êd`ÎfgÌb^Çb`Îe`È`eÎieÈbcÈc^Êb`ÌcbÈccÎabËadÈbbÇbdÈ^^ÉbcÄbaÀ\`Â[dÀZ`»Za´X_°T[±PX¨HV¶LP¾V\È`]ÑlbÔqlÖzlÙtÜ„pÞˆnÞŠrÚŽvÝ‚nÜzgÜ~jÚ€jÜlÞ€nÜ€rÞ‚rÝ€pÞ†xÞ‚n߀hÞ€jÜ~j߀eÞ€lÞfà}fÝ‚jÞhÜ€eÞ„hÜ„m܆nÝ‚jÞ†q݈qÝ„pÜ‚hØ„nä”nï¹…ôÈøÎ–øÐžúÔ£üÔœúÔŸôÈ⪀Ärj§M\¥HX¨PZ®OZµX\¹Z\¶Za¼^`ºac¼X\¼^^¾ZZ½^b»dhº[cº\aÃZ[À[^ÃZZÃZ^¾^^Ã]`Â_^Á`cÄ`bÀ^_Å^]¼V\Á`cÂ`bÄbhÁ``Æ[[ÂbbÄa`¿[]¼V\¼V\ºVZ¾\bÚ{væ’€è”zÒrdâ‰}߈‚â†väˆ|âŠ{â†|à†rÞ„uÝ„nÞŠvß‚kÞ„jÜ„pà€gÝ‚tÞsà‚jà„râŠvæŠrèŽrè’wì—zè—yî•vê”xévè†tàwfØvvÊZa´P_¨@Tœ>\œ=Y¤EX¦GXªJZ®IZ²J\²NW±JV¯LV°OZ²LX²LX´NX²LV²NZ°NZ®JS´JT´OV¸SY¼TZÂXZÂTXÂZYÄ^ZÄ[\Ê`\Ê^\Ë\ZÌf_Îb^ÎebÌabËbbËkhÍffÎd`Ìb]Îb`Ê`^Êg_Ëd^Ëd`Ëa^ÎhaÎhjÑb^ÐebÐfaÐgfÒebÔe`ÒddÒfbÒgdÎheÎf`Ïd^ÐffÐjfÌfeÎfbÎjfÐgbÓidÑibÐicÎhjÒheÊghÊknÎhlÌffËe_ÇddÌf^Îe]ÍcbÊcbÈjhÍibÍdaÎddÎdbÒb\Ðe`ÑhbÒf`Ðg`ÐjdÑd\ÏfdÎ``ÎjjÒplÍgcÌd_ÈbbÒe`Êd`ÎfgÌb^Çb`Îe`È`eÎieÈbcÈc^Êb`ÌcbÈccÎabËadÈbbÇbdÈ^^ÉbcÄbaÀ\`Â[dÀZ`»Za´X_°T[±PX¨HV¶LP¾V\È`]ÑlbÔqlÖzlÙtÜ„pÞˆnÞŠrÚŽvÝ‚nÜzgÜ~jÚ€jÜlÞ€nÜ€rÞ‚rÝ€pÞ†xÞ‚n߀hÞ€jÜ~j߀eÞ€lÞfà}fÝ‚jÞhÜ€eÞ„hÜ„m܆nÝ‚jÞ†q݈qÝ„pÜ‚hØ„nä”nï¹…ôÈøÎ–øÐžúÔ£üÔœúÔŸôÈ⪀Ärj§M\¥HX¨PZ®OZµX\¹Z\¶Za¼^`ºac¼X\¼^^¾ZZ½^b»dhº[cº\aÃZ[À[^ÃZZÃZ^¾^^Ã]`Â_^Á`cÄ`bÀ^_Å^]¼V\Á`cÂ`bÄbhÁ``Æ[[ÂbbÄa`¿[]¼V\¼V\ºVZ¾\bÚ{væ’€è”zÒrdâŠ|à†yâ†vä†xâˆvâ„vàƒnà‚oß„m߆p߀hàhÞ„oà€gÝ€tÞ‚nß‚lÞnáˆtæ‹qçrè“yë—zë—yî–vì”vêuç„oßwh×omÈX_´O^§AW>Yž<V¤BV¦FZªFY®JZ°JZ²KV±JT®JT°LX³IS²JV³LW±JT²LX²LW¯JR³KU²PW¸QX¼U[ÂWYÃVZÂZXÄ\ZÆ\]Ê][Ê^^Ë[[Êa^Ïc^ÎdbËddËa^ÌheËccÎfbÍc^Ía`Ëa`ÊfcÌd`Íb`Ìb_ÏieÎgjÐd_ÐgdÐhdÒidÓfaÔeaÓfbÒfbÒfbÏidÐd`Ïc_ÐecÐgbÎdbÏfcÐhbÐgaÒhaÑfbÏhdÎhfÒgaËgjÍhiÍjjËebÌb`ÉbaÌe^Ðd]ÎcaÌb`ÈfdÍjaÊb_ÌddÍc_Ña\ÍfbÐfaÐfaÏf^ÐgbÐe^Ðd`Îb_ÌhhÒjiÎhdÌdaÇbaÐd_Ìc_ÌccÍd_Éa`ÍdaÉacËhiÈ^`Èa^ÉccÊdeÉa`ÎbcËceÈ`bÇbdÈ``Ë`aÄ`aÁ\_Â[bÀ\`ºY`µW^³TZ°OY¨JVµJP½TXÇ_^ÏjbÔpl×ylÙ}rÝ‚rÞ‡uߊrÛŠs݃mÜ|jÝhÜ~kÜmÜ}kÜ~oÞ‚pÜ€mÝ‚pÞƒoà€h߀hÝjÞ~fÞ~lÞ€hß~iÞ€hÞ„iÜdÞƒhÞ‚i܆o܃jÝ„qÞ†nÞ„pÜiÙlâ‘oôÅ÷ΘùМúÔ¡üÔúÖžö˔求Êzm¨NX¥HXªLV®Q\³X]¸Y\¹Y\½\^½``¼Z]»]]¾\[¼^b¼`eº]a¸[`¿[\¿Y\ÃZYÄ\]¿_`Ä^]Ä^^À_aÄa`Á`_Ä^\½WZÂ_aÁ^aÅbdÄ_`Ç]ZÂbbÄ`^À\\¾U\¾V\¼Z\À_bØtlÞ…vÚ}l¶WZâ†xà†qâ†vä‚nâ‡vâ†tâ€eà}lànà€ià€há~gÞ‚kà€fß|jÞ‚kß„nÞ€gä„næŒrévì’tì–|ì–xí–yì’sënæ„gÞxiÔfbÈZ\µL[¨<UŸ7S›;T¢<S§>T¬@T°KZ°LY°FS±FQ²EP±IV®FR°GS±JV²HOµFN²IT°GO³KV¶LRºOR¼VXÀTXÄWYÆ\\È_ZÊ\VÉ^ZÊZUÌZXÍ_\Ðb\Îa[ÌecÏ`\Îb_ËcbÐa^Ë`aÏbbÑf`Ðd_Íc]Ìc`Ïb]Òc`Ïb\Òc\ÐfgÐfdÑfbÒf`Òb^ÕebÔe`Ód^Ôa[Ñf^Òb^ÐabÎcdÎc_Ñc^ÑfcÎfdÎdaÏedÎfdÐc^Ïb`ÌdhËknÌdfËmjÊbbÍgbÊb`Îd`Î`ZËc`ËjfÌieËbbÊe`Í^XÎd\Îd^ÎgdÓd^Îh`Íb`Ðe`Ïa]ÐfbÐd^ÐffÍedÐd`Îa\Ë_\Ç`cÌ`^ÉfhÌ^]Ëb`Éa`Êa_Ê_^ÅbeÎa\ÎabËcaÌbaÌabÉ`^ÊbdÌ_\È^^Æ^`Æ[]ÁZ^¼\f¼W^¹T[¶RZ²LT«KX¬EPºUXÄ\^Èe`ÓlgÔvnØ{nÛrÛ†pÞˆt߈tÞ„mÞ‚oÞ~gÞ}gÜoÜ|gÞ€nÜ€nÜiÝ‚nß‚là€fßißfßeÞ~cà€ià‚hÝ€j߀fÞ}dÞeÞ‚gÝ‚iÜ‚lÝ„mÜ„rÞ‚kÝ‚jÚiÛhè¢xñ¾Š÷ÊøÐšúÒ›ûÔžüÖžûÒ•òÉߞs¸d_£HX¦JW«P]²V]¸V[¼[]½TWº[^»Z]½ZZ¼`^ÀZ^¾`a¿\^º^bº_d½]^¾^\Âa[Á__Æ_[À`_Á^]Ã]\Â\^Å\ZÀ^^¿[`Ä^^Æ``Ç]bÇ\[ÄbdÇ`\Ä_`Á[\Å[]Å`cÅb`¹VZœET~,KfEà‚ià…páƒrâ‚nâ…tâƒrà„kã€lâ€kà„nà‚jâiÞnß~mÝ~hà‚lÞ~iâƒjå‰mçŽré“rì“wì”sì–rî•ní‘pêŒlå€dÞtfÔjaÉWZ¸NX¨=Rž:Q¢8N¤:O¦@R­DT®DR²DPµHSµFP²DN³LW¯GR²KR²HR²GO²HN²HR°JT³LU³PY´OX»QY»VZÃUWÅZ]ÃYWÅ]]Ê^YÈ^]Ê]XÈa^Ì]]Í`^Ê_[Ðd]Ìc_Ìb`Íb^Íd_Íd`Îa^Îb]Îb^Ìd^Íb\Ðb^Îf_ÐbaÏc`ÏfaÐgbÒfaÓh^ÒhaÓd^Ñb_ÒgbÏhaÒdbÎb`ÐkhÑedÏdaÐfbÐdbÍa`ÑefÏcaÐd`ÏbfÌ`_Ë`bÒdbÎb^ËgfÌbaË`\Í^\Í`]ÉfbÌgdËhcÎedÎ^VÎ_[Ìb\Ëe_ÎdcÐb^Óa]Ðc`Ðb[Ïb_Òb\ÎcaÐd^ÐfbÌecÏ`\Ða^Êb`Í`\ËbbÊ]]Ëb]Ë`^Ì`]Ê\\È^`Í^^É]^ÈbaÎa_Ê_\Ì`[Ëb`Ç[[É^]Ç]]È_^Æ\^¼Y_¼Ya¹TX¸PX·QS³LU¬HT±JU¼SYÂ]^ÎffÑql×xpÚ{nÜ‚qÞ„tߊuß…rß‚nÝ‚pÞ€jÝ~jÞƒká„lß‚iàjÞ„mßiàjá„kàƒgâ‚eßjßg߀jà‚jß}eÞjß‚jÞƒjÜ‚lÜlÝnÛmÜlÜkÚhÚ~mÞ‰n쮀õÂŒöÌ™øÐšûÓžúÓ›üÔ™øÍ’ë·~Єl¬U[¨LY¬NU¯S\¸SZ¹XZºZ]¼\^¼Z_»Z\º]^¾[^¼]a¾\aÀ\]¾X[ÀZ`Á\^Â^^Â`^Ä[XÄ_^ÁZ\Ã_[Ã\_Ä^ZÆ]\Ä]^Ä`\Æ`cÆ``Å`]Ã`_Æa]ÈbbÆbdÉ_^Ä_\°NTŒ/Id@\B\Aàƒlà†nä‚iázká…oâƒká‚lâƒkä‚nàná„kâiß~hàhâ‚làbà‚hâ„jæŠjèŽnê’oë“qì–sì•oî”nìhèŽmå}eÞo^Õf]É\[µKT¨;OŸ8Q8P¥<P©@S¬BR®@P°HS´CN³GQ´FP±GT±IO´IR´DM±GP³IQ°DO°JR´KS¶OV¸OS½QT»VZÀW[Â[_Ä]`Æ\^È[VÊ^ZÎ[WÌb\Ï^ZËb_Í_ZÌa^Î`\Ïa^Í_ZÊfdÐd^Ïd`Ðe_Î`]Ïc\ÎaZÐ`]Ðe]Ð`[ÐdbÒfbÐfbÓb^Ôb[ÒdaÓd`ÒebÔd^ÐcaÐ_\ÑbbÐfbÓb^Òd`Ôd_Ñ`]Îc^ÐfaÎbbÑc\Ïc`ËcbÐa^ÐfdÍdbÎb`Ìb`ÍcbÏ`\Îa^Ìa^Ï`^ÈfcÏb^ÌcZÌc]ÍbaÎb\ÍdaÏcaÐhdÏc]Íd`Ïa]Îa_Î`_Î`[Ïb_Íd_Ðd_Ìc^ÌbbÑaZÌ`]Ì`]Êa^ÊbfÌb]Í``Èa_Ì_^ÊaaÊ^]Ì`dÌd`Ì`_Ìa]Èa`ÈbaÈ`]Ä^_À\`¼V\¿YbºTZ·U`´NV²NX¯LY®HV±NX¾X^ÈegÐjfÖsoÚzrÜ~tß„vàˆuà†rá„oßlÞ‚pßjßläƒiá†lá„mâ†oájâƒlá„jáƒlßj߀ià‚jà€hà†jàkà~fà€gßlÚ}aÝnÚlÚƒlÚhÛ€fÚ‚gÚ|iØkä—tð¹„öÆ’ùΘúМûÔšþÖœûÓ˜õÆŒä¤uÀlc¬JR¬IU«LU²RX³SZ¼VXÀ\]½ZZºY^»^a¾ZZ¾]^½Y\º\]¼Y_½ZZ½XZ¾\\¿\\Ã^^½]b¿]^Ä^\Ä\\Á^\Æ\\Â^^Ä^_È^\Í_\É\\Æ^`ÈdcÎfbËhbÃ_]®HO…,Fe@\@ZAZBäƒnâ‚pâ‚kâƒná„nâƒjâ€hâƒlâ‚jà‚qâ…lâkà€j߀iájáhãƒjä‹qèŒnè’rç”pé“tê’të“kínêŽhç‹hâ~gÝp\Ôh]ÉVT²JRª?Qœ7N :O¢=O¨<N¬BR°DQ±IV±GR³LX±KV°MV±NV³FN°DO±IP²CL±FO±DOµJR¸RVºNW¾RRÁWVÃVZÁVYÄZ^ÄX[È\ZË\YÍ\XÌ]YÐ]VÎ[XÍ^XÑb`Ì``Ðb_Îd_ÐebÑd`Òc`Îb^ÏbaÎb`Ía\Ñc\Îd`Ï`\ÏbcÏgcÐb\Ôb^Ód^ÓgdÔg]Öc^Ôb\Ðb\ÐfcÑddÐd`Óc`Ób]Ô_]Ñd_Î`aÐdcÎ`cÒc_Òb_ÑeaÒe`ÑdaÎdcÐd`Îb^Ï`^Îb_Ð_\Íb^ÏcaÍc`Òc`Ì_[Î`ZÎebÐb]ÐhdÒhdÒhaÑddÏfbÎb`ÎebÏb^Îb]Îd`Íb_Îb^ÐfbÌdfÎa\Èb`Î_ZÍcaÌb`ÉbaË^]Ìb`Ì__Ëc`Æ^\È]^Ì`^Ê`_É_^Ë`^ÌddÈ__Ã]bÅ\`À\`ÀZ^¹V`µPZ´PX±SZ²PZ®IT©HW·S\Â_hÏkiÔqnÚvlÛ}tàmá‡vâˆsâ‡sà„má„mß…lÞ‚oã†ná‡lâˆmåˆoä‰kä†pâ„pâ…jã‚fà‚là‚jà…gà‚ká‚fÞ€hàhÞ~dÜ‚jÜ€jÜ~jÜ‚oÜ€fÚ€jÚ‚mØ|hÖ~kÜ„lê©|óÀ‹øÊ’ùЛûÔžüÕœüÖžúјð»ˆÖr´WY¨LX¨M[¯T\±TZºTX¼X]¼Y_¼X\¼\_½\]ÂZZ¾\^¾[]ÀZ\ÁX[¼^c½[[¿^aÀ[ZÃ]\ÂZYÄ\]Ã\\Â\\Ã[\Æa^Ê`[Ç\[Æ`aÇ^`È^^ÌhcÏgcÇ]Y²OV†,Gb$HY@X=Z@\>ä„pâ„nâ‚jã‚eß„nâƒhâ‚lâjã‚mâ‚jâ€gá€jà€gÞ€jáiâ„iåˆpåŽpçqè“rç“vé“rê’nênêŽmæŒoç„fä~hÝr^×bVÊX\¶NW¦>Rœ<Qž<R£<M§?O­FT±CN³FSµIRµJU±KT²JU´JR³HO²CP°IP²KP±BK°DM´JQ¶MV¹OV¾PQ¾TWÁTZÆVUÄ[aÅ^\Ê^\É\YÉ]YÍb[Ì^XÎ^YÌb^Î^ZÍ^\Îb]Îd`Ìc`Ða^Ðd\Ïb^Ða`Ða^Ï_\Óc\Îd`Ðc]Ñc_Ðb^Òb^ÒaZÓheÖb`Ôc]Òb`Ñb[ÐcbÒd`ÑdbÒfeÖc^Ò`\Ñ``ÏfdÏdeÒfdÐcbÐecÒa`Ïc_ÏddÏdaÐc`Ñc\Îd_Ðb^Òb\Îc`Ïd]ÍdaÌb`Ïc`Ï_ZÎc]Îe_Ïb[Ðd^ÓhaÓd_ÒgfÎddÏb]ÐgdÏb]Î`^ÎddÎd`Îb_ÎaaÌcbÎc`ÉbcÍa^Í`\Ê`\Ë_]Ì`^Ê_`Î`bÊbcÊ`aÌ`_Îb^Ìa`Ë``Ìe_ËadÈ^cÄ^bÆ^`Â\aÁX^¼WY¶R]·T]±Vc±N[­KY«JX²NZ¼VaÊehÖpkØvrÜ|qÝsÞ…tâŠpâˆráŠvãˆnàˆtá…rä‡täˆnåŠpæ‰påŒoè‡jã…ká„kâƒgá€lâ‚hà‚hàhâ~fâ‚fá‚fà‚hÝ~hÜ|jÜ|hÙ€kÙ€pÜ€lÚ€oØ‚pØ~jØyhä“qñ¶€øÄú͘úÒœüÕŸüÖüÕŸ÷ʓ簀È{i¬MX­MY­MU´NW¶OUºZ[¸T\·VZ¼\^½Y[¾ZYÂ`]À[[¿YX½\]¾Z\À\`¿\b¿Z^Ã\\Á]`Ã^]Ä_`Æ_^Â]^Æ^^Å^^Å`ZÊcdÍdcÌecÎk`ÄZ\¨EQ&Ea?\HZBZ<\B\Bã‚pà‚máƒmágâƒlä‚gâ‚oâ‚hâ€gã‚kâ‚jãjà~fÞ~mâ€jãŠtæŠnætè’påqç‘pêpêlêŽmêŽnç‰mæ„gà|gÝo\Ôf\ÈWY¶HR¦<LŸ7L 6J¢=O¨:J­FR²GQ°@L·KR´HO´HRµMV±HT²GT°FQ´JT²DM´DN±DKµEN·MP¼NQÀQUÁRSÅTSÇXVÈZ[Æ\bÇ]ZË\YË]ZÎ^ZÏ`\Ï_\Í_[ÌeaÌ`\Ða[Ðd\Îb^Óa[Òb^Òc^Ñb^ÎfaÒa^Ð`ZÐc_Óc`Òf_ÐfdÑd^Òc^ÑgeÒfbÔe`ÓkhÒegÒfcÔa]Òd^Ôf\ÔefÑd^Õa_Ò``ÒfcÐecÑcbÌa_ÐedÑgdÑffÐhdÒecÒb^ÒffÑebÑ`\Í_\Ï`ZÎf]Ñd_Ïc`ÌbaÌ`]Ðb]Ðc^Óf]ÒifÒfcÕjfÓe^ÐcaÐd`Îb\ÎebÎc^Ðc`Òa_Ðd\Íc`Î_\Ì`\ÏbaÎ`[Ì`_Ê`]Î^ZÌ[^Î_^Ì_^ÎbbÎaaÉbcÎ``ËbdÎ`^ÎbcËb`Æ_`À`bÃY\ÃZ]¾TX¿QV¹T[¶Zc´MX²OWªJ\®HW¹S^Á^hÐooÖvpØwpÜ}qÜ„wà…pá‰tâŽsâŠsâ†tã†lå†påŠpäŒuã‰lãŠqä‰qä†mâ„nâ…oâŠnâ†jáƒnà‚láfâgá}bàhÞ„rÝ|eÚjÚ|lÛ€mÚ}lØ~mÚ~hØ}i×{iÞ~hé¥{ô¿ˆúÊ‘úÑžûÓœüÖ¢üÖ ûÒœóÃŽážvºb`¦JX­LV¬NZ¶PWºX\»TZ¼V[½Z_ÀY\¾[[Ä[ZÀZ[¾[]À_\½[\¿_a¾]_¿^^ÂabÂ_bÂ\\ÀceÅa^Ê`[Éb^Ìb`Îb\Ðd`ÒhbÏfeÃ\[¦@Ly!B^>W>X<ZBY>[9_@âlà‚là„sâhâ„jâiä„hä†kä†kâ†mâiàƒpà€màlá…pä‰påråoænè‘qæ‘pèŽpèsç‰jèŽuèˆoä‚dâ{jÝreÖjeÆ^a¶Q\¦@Sœ8MŸ9L¤?P©@M®DM²CN±BN¶FP´GR´LT±IW´FP³HT°JT´FO±DN¯JS±DL¶KS¹NR»QW¼UZÁSWÀY_ÅXXÂY\ÈWZÆ^[Ê\\ÊYVÌ`]Í`\Ï^`Ð`[Ða_Ñ^\Ða\Òd\ÎdbÐc_Ðc]ÏfdÒd`ÑfcÐa^Ïb_ÎdaÒa]Ñb`Òc`Ô`[ÑaaÑdbÒfbÔd_Òd_Òf`Òc_Ôb^Òb^ÒdaÔc\Òb\ÓcaÒ^[ÐbcÓjiÒdbÔb^ÐdbÑcbÑabÎaaÎdbÑdaÓgeÏa`ÎdfÌbeÎ`bÌfbÌgbÍf`Ì_]Í_^Ðb]Ðd]ÐgaÑgfÐigÒjfÐgdÑdcÐfbÎdaÌfcÐd`Ðb_ÎgfÓfbÌ`^Ìa^Î\[Ía`ÎcdÌcbÎdeÍ_ZÌ`^Ì^bÍ_`Ì`\ÎbbÐcaÍadÌabÊ\ZÏ__ÊaaÃ^dÀbgÂ^d¿Z`¾VZ¾TY»S\¶P[³NX³NX®HV­FX³Q^¼[gËfgÓol×xqÛ~uÜ‚uâ…tã‰râŒxãˆväŠwãŠoã†oäŠqã‹räŽuæˆmåŒmå‹qã…jã„má…jã†oä†ná‚pâ‚hàkà€dá‚jÝlÝ~lÜ~jÚlÝ}jÙ€pØlÙnØ~iØzeØxf߉jð°øÅŠúΕûÓ ûÔžüÖŸýÖøÌ“íµ„Ð…l«NXªISªM\°NVµTZ·V^ºTZ¼X_¾Z\Ä\ZÀ_`¾\`Ä_[À``¾\]À]`¼^`¾bbÀ]^Â__Â^^Äb^ÆbdÌ^]Ìb`ÐfbÐg^ÒgdÒiaÄZ[¤>Lu$CZ<V@YBZC^D\?\>`;â‚jà‚oâ‚nâláƒlæ‚jâ…mä„kä…lãƒlà~nâ‚nànà‚ná†oãŒqætæ‘oèŒpæ‘ränæoåpåŠkæ‰lç‰oç‚dä|fÞqbÕhbÈ^^´V\¤BRž=O9N¥=J¨>J®BPµFP²FO³OWµIRµFN´KQ°HP°IQ®CO°DL±KP°EL³EK³FR·OX¼OV¼RU¿QPÄUUÃVVÆWVÆZYË\YÈZWÌ\VÈ\\Ì\XÍ_^Ìa[Í`^Ïa`Ña[ÎcbÌ`_Ð_]ÎefÐ_[Ðc`Ñb`ÎdaÒb`ÍdcÐbZÏabÑc`Ñd\Ða`Ña]Òc`Ôd`Ôc^Ð`ZÑaZÔc`Ò`_ÐbaÒbaÒd_ÐcbÐaaÑeeÔc`Ò`]Ò`]Ô_\ÒecÓfgÎbbÏa`ÎacÏbbÎb`ÌjfÌbbÎe`Îc`ÌcaÍbbÎ^\Í`ZÌb`Îa]ÌcaÑedÒghÐkmÑooÑefÎdeÎb^ÏfdÐb_Ìb`ÍbaÑfcÌ`ZÌa`Ì]_Ðb[Ì_`Ë`]Î``Ð`\Ê\]ÌZ[Ê``Ë`^Î^\Ï`^Ì``Í_^Ì_\Ï_^Ê^ZÊ^`Â\`À]h¿\dÀelÂV\ºPX¶T\³LZ²JX°NY®FT´OY¸V^ÌecÑok×ztÜznÜsß„pàŠvâŒyäŠvåvä‰pä†oá‰täŠxä‰rãnäˆrä‰pâˆoäƒlà„nâ‚pâ„oâ„râ€fá‚sà‚jÞƒpÝ}kÜ~nÜ~lÛjÜ€jÚoÙlØ}oÚ|kØ}lÚ{kÙyeæœt󻇸ɒúÏšúÓ ûÖ üؤüÓ˜õÆŒä¦w»jbªLT°R[®NU¸T[µPW¹X^»X\»X\¾Z\¼\`À`aÀZ^½[]¼\_¼`e¼Z^¿^`¾aeÂhjÄabÈabÊb_ÊfeÍedÑhgÒigÒlfÆ\]£?Nx#D[AR@ZFXFX@\CZB]?aAâƒqà‚lâ~iâ‚lâ„mä‚iäƒnä„mã†râƒlâƒnà„màjâ€iã„mæŠtç‘nå“tçtä‹nåŽlæpäŒpäŠlå†jä‰ræ‚hâ{hÚwhÖheÉ`d´OZ¥@Rœ8N;N¥?O«AK°AL±DN°GP²QX³DM´FO²DN²EL²HN²GN±HN±EL±IP²GN¶HPµLQ¹PT½NQ¿UU¿SVÄZYÂWXÅWVÉZXÌZVÎ\WÈ\\Ë`\Ð_]Î`[Îc^Ñb[Ð`YÎc_Î`\ÎccÎc_Ðc`Î`\Î`bÍb[Ð`^Íb`Ò`ZÒc_ÐdbÐb]Îb]Òc]ÒdbÓa^ÑcfÐ`]Òc]Ñ`[Îb_Ï^ZÔc^Ñ_ZÑb^ÒecÐ^^Ób^Òd`Ò\XÒ_[Ðb`Ñ^]Í]]Î`\Ïb^Ìa^Ð``Ð\[Ïb^Ðc]Íb^Ì``Ëc`Í^\Ì`\Î_YÍbbÑfdÑbbÏedÏfdÎffÍbbÐc`ËbcÍa`Îb`ËdbÐb`Ðb]Ìe`ËaaÌa_Î`[ÌddÌ[YÊ\_Ë]\Ë\]Í^ZÌ`^Ì^ZÌ`ZÍ\]Ð^\ÎZ\Ï\ZÏa_Ê`\Ë]]Â\`Â[`À[b¿Y]¾X`¾RV¶QZ°PZ²S\¯JW«JZ®O[¶P[Æ`dÐjiÖxpÚzvÜ€xÝ„tàˆyâ‰vãŠwãŠxä‡näŠrã‡máˆpá‡sátä‡näˆkâŠoá‰qàƒgà€mâ‚jâ‚jâ€hàmÝhÝlÝ~jÛ€lÜ|kÛ€jÚ}jÛ~lÛ|iØ{kØ~k×~lØveÔvfÜ„jì¬|õÉøÌ’ùÒ›ûÔžüÕžû×¢úҗf֌i³TW¬JS°PU´PZ´RV¹V[»Y\ºVX¼V\¾UXÀ\\À_]¾[^¾\]ÀWZ¾\`ÀZ\ÁadÂbcÃfiÆdhÇddÌedÎgdÒhiÓldÊ\[ >OnA_IV@XEZA\ LZ?]>\>b<c@â‚hßlànâƒtä†qä…jå…mä„lã‡mãlàƒrâ„oà‚qâ†päŠsçtçvæsæ’oårã‹qåŠsä‹rá„kåˆlæ‡læ„jã}dÞtcÖh\ÊZZ¸LT¦@Nž6I5H¥>Mª<I°=J¯BN¯JR¶JR´HP²HR³CO±JR³JP±FL´FK°EL²EM´HN¸LP¹MP¸PU¾LR¾QSÃWXÅZYÆZWÈWUÈZXÈYTÌ`\Ë_\Ï_[Ð`^ÍZVÌ^\Ìc]Ïc_Ò`[Îc_Ð^_Ð_ZÐb^Òb_Ì]^Î``Ð`^Î`^Ñ_\Ñ`YÎb`Ò`ZÐ^YÓd_ÔfdÖe`Ô_\Òa\Ó`YÒ`ZÐ``Ð`\Òb`ÐfhÑgfÓdaÒa_Òa\Ó^\Õ^WÒ_ZÑ]XÒZVÐ^[Ï^[ÐZWÒ]WÍ]^Ì\^Î^]Î]YÎ^ZÍ`ZÌ^[Î^ZÌ`]Ð\WÌ][ÐaaÍ`_Ïb`ÍdiÎdbÒcbÒb`ÎcaÍbaÑc_ÏcbÐd_Ï_\Î`\Î^\Î\ZÎ^ZÎb^Î`XÍ\[Í_\Í\YÌ\[Ì^^Ê_\Î_\Î^[Î\ZÌ[\Í\XÎ``Î`_É\[Æ\aÂ^dÂZbÂ_fÀV]ºQ\µNW²N[°NW®JV®L\±T`·YhÆafÎjlÔtrÛ{tÜ~xß…yà‰|â‹vâ‹xâ‰xãŒtäŽuâ†pá†ràˆrâ‰nâ‡lâˆnáˆkâˆoã…ißjàlà„jájá‚ißoà‚lÞ~hÜlÞ~mÚ€kÛ}kÜ}jÛlÚ}lÙ|jØ|i×zmÖxkÖydã–qòº†øÇ’úКúÔžûÖ¢ûØ¡üÖ÷ÊŽç°~Çw`¨JU­KS°OX±TW¶X^¼]]¿ZYÁ\]½Z]Á\ZÄ^ZÀ[]À\Y¿Z]¿ZZ½Y\¼]cÄbfÃ]_ÅcbÉdfÐdhÒifÒjgÈ\_¤<Nr#Gf4XWDV>W=X<Z=X:`;_?f?f@â€fß‚pâ‚oäjä„næ…mæ…iäƒiä…mâ†râ‚nâ„má„nåŠpærètérç‘sçræoå‰iä‡pâˆnàˆqä‡jæˆpæ‡nã~gàt^Ùg[ÉTQ´FL¨7FŸ8Lš0Gž6I¨<L¯BM°DN°HN¶EN´GPµHQ²LV°JT°IT°DN¯FP²FQ´DL¶GN¸KO¸LP¹JN¼QW¿STÁX\ÆYXÄUUÈZ\ÊZVÇ^\ÌXYÈabÍ^[Îb_Í^\Ë]aÌ^YÏ^_Ð`ZÍbcÍ^aÏ^ZÎ`^Ð``Î`eÏbcÑb_ÎcbÐaaÐc_Ñ`\Ò^XÏ\ZÐaZÏ_`Ó`_Ó`]Ôb^Ò^ZÑ]ZÑ`\ÒdbÑcdÐdlÕhfÒgfÒebÒ`aÕ^ZÒXXÑYVÑ[WÎZZÏZZÎZWÎ]WÎ\XÎ`\Ì`bÐ^[Í`[Ì\_Ê\ZÍ_\Ê`]É^]Ê^[ÈbaÌZXÎ`bÌ]^ÌbbÏfeÏcdÐcbÐaaÏdbÒddÎcbÌfcÌ_ZÌ_]Í^ZÌ^\Ì^[Ì__Ì^`Ê][ËabË^_Î]WË_`Î`^Ë^]Î`XÍ\\Î]ZÎb`Í^_É^]È^`Ä]^ÀY`Ã\_Ã^a¾^dÀR\¶MX¸NW´LS±JQ±JY¶P^¹WbÃ[fÑfjÖolÖutÜ€xà†xâ…{â‡zâŠuâ‰uáŠwäˆtâ‡sá†mà†qá‡pâ…mà†lá‡hãˆhâ‡kÞƒlâƒlß„ná‚jâƒkÞ„mßjÞ€lÜ~lÝmÛmÜlÞhØ€mÛ|jÙ}mÚ~kÖwhÖzlÕvhÜ€dê«zö‹ù͘úÒ™ûÕŸúØ¥üÛ üÔ™ò‰ڜw´\Z¬JP²NT³RW´V[¶ST¾ac¼^cÀ`aÄY^Â]^Â^^¿Z]¿\\¿V\Àab½^cÃ\\Á_bÆbbÎd`ÒheÐhhÊ^X¢=MsAYA\FYDS:U7Z<\8_=c9h=j>c9äƒpã„oä„mã„jä„hæ„nå…lå„hå…oã†oä…jã†rãˆuçŽoètç”rç”tä‘ræpåŒsã‡hã‡kâ„oà†qåŠhæŠnç†låcàsZØgZÊXR·JN§<Kž6Hœ3H£;I¨CN®?M¯DO²HS±DNµHP³IR²HN²LV²FN¬KV°FN±HP°EP´HM·KT¸KO¸KR½SVÀSRÂTWÆXUÄZ\ÆYXÈYXÈ\[É]ZÊ`ZÊ`ZÌ^WÌ]ZÍ]ZÌa\Ì^[Î_[Î_[Î\]Ìb]ÍabÎa_Ña`ÌchÎ]]ÎbbÐbaÐacÑabÒc]ÎacÐ`]Ð`]ÒddÕ^^Ô`aÒ\]Ð^^Ï__Ô^ZÔ^^ÑedÓfeÒhhÒgaÒadÑ[\ÎZXÑ\ZÍ[XÊZWËVUÎWRÍZZÎVWÎ]\ÌbdÎ^[ÍZYÈ\`Ë\XÌZ[ÊYYÌ^\Ì^^Ì\ZÎa^Ða_Ìb`Ì^^ÎbdÐ`^ÎbeÌbfÐb^ÐdcÏhfÐbbÍb^Ê\\Ð_]Ê^\Ì_bÍa^Ê`aË`aÌ^[Î\ZÍ_]Ì\XÉ]\Ì\ZÏ]\ÍZ]ÈZ]Îa`Ì^aÎ_\Ë]\Æ\_Ä^bÃU]ÄX^¾V^ÀYb¸OW¹QX¸NVµLU²LX¶Pa½XcÆaiÎfjÔprØwtÚ~wÞƒyß„và†xãˆ{âŠtâŠxâˆtà‰vá‡tá‡o߇tâ‰oà‚mâˆjä†kâ…jã†jâ„iàmâƒmâ‚qá‚nâ€lÞƒrß‚oÝ‚sÜ„rÞ€nÜ~lÜ~nÚ~hÚ~qÙ{h×xkØxi×xdÖvgâlô¸€øÇ‘úÑ›úÔŸúÖ üؤüØ¢øÐ”Él°IN¬MU²OU´TY½UW¼VX½ZZ¾[^¾^]Â\ZÀ[]¾]]ÂZZ¾[`½]]Á^aÆb`Ä^^ÉfdÌfdÏjdÂZ_¢9Kt>W=V:ZCXA[BW;^?^<b=d=g@a>f'Lä„jã…qä„pâ…må†mç„kåˆpä‡iä‡qä†näˆqåŒnåvèrçwé“rè’tèrçŽrçŠlä†jâ†nà‚rá†tçˆkèŠnèŠmè€fÞs^ØgXÊXU¶KP¦=KŸ:Nž4K¦<Kª@M¯BR°BL²FR¶LV²LVµNV±DN±LU²GM°EP²FO²IR±DP²IQ¶IR·JO¸KQ½NR¾TUÅTVÇWVÂ\_Æ[ZÊ[XÆ\ZÉ\ZËZVÌ_[Ì\YÍ`^Ì_]Ë`_Ì`\Î`^Ì]ZÎ^^Ì\\Ï`\Î_aÍ``ËbfÍadÏ``Î_cÓd_Ð_^Ñb]Òc`Ð`\Î``ÏcbÓ^`Òa^Ð`]Ò`_Ð_^Î^^ÏbfÑebÐdeÒa`ÑbbÒdcÎ`cÎ_\ÎYVÌZZËUUÍXVÌZVÊYWÌ\[ÌZ\Î\ZÍ`]Ì^^Ì]`Î\\Î\XÈ]^È[\Î\[Ê]\Ñ[XÏcaÌdgÌacÎ`^Íb`ÌbdÌefÍfhÌa`ÌdhÎ^[Ëa`Ç]`ÌbbË\[É\_Ìb^Ë``Ë_^Ìb^Î]\ÎZXÊ^aÌ_^Ê[ZË^^Î]`Í\`ËbaÐ^\Ï``Ë`aÊbdÇX]ÀT_ÁV^ÀV\¼V`¿TYºLWºNX´NZ°KZ´Oaº[jÆclÎilÓkjÕwxÛ|tÞ€và„xá‚tâ†sâ‹xá‡wâ†tß…và‚qá‡và„oãˆpã†iâ†gä„hâ„mä„jáƒlà€eánàqá„rá€há~kÞƒp݃rÞ„pß‚nÞ‚lÝ~lÜ€oÚzlÛjÚyjÖwgÖxjÔtf×|gì¥xöÀ‰úÊ”ûÒœùÕ¡úÙ§üÙ¤üמ÷Ë’ã§v¹d]®JP²OT´PXºUV¹VV¾XX¾V[Á^`À]`¾Y\¿ZZ¿\^À^]¿`bÅ[]Å``ÈcdËgbÍgcÄZV¢=Ks<X9W@[@\@\BZ=]?^>b=e<e<b:bAcEä‚gä„pä„näiå…lä…hä†jä‡lå‡pä‰væ†pçŒrèsé”té”ré”rè’ræ‘tèpæŠeä‡fâ‡lâ…pã…iæˆoèˆièˆjåcâv^ÜhVÌ[VºHN§<JŸ9J¡9K¦?Q¥?P¬AN°BN²DN³GQ´HS´KT²KT°NV²FO´CL°CL²EP®ENµHO·GP¶JSºNU½PVÂPQÂTUÆUVÆYZÄZ]É\\ÆVVÊ[[É\\Ë_\Í^ZÎb]ÊZ]Ð`\Î^\Ía`Ê_aÌ^ZÊ]`Ð]ZÎ`aÌ`^Î`aÑ`^Ð`aÔ``Ò`_ÐaaÐb]ÑbbÒb]ÓbcÏ_`Ï_^ÐaeÓehÑ`^Ñ^]Ò_\Ñ``Ò``ÒcdÏbbÓddÑ\ZÔ\YÓ`_Ð[XÎXVÍZXÉZVÈXYÈVWÌ[XÈVDÌ[YÍ]ZÉ]^ÊZ[Ì^[Í\\Ì\XÌZZÉ\YÆ\YÊ[^Ë_]ÍabÌ_`ÎbeÌ`aÌ]`ËabÍheÎbeÍcbÎ_`Í__Ê^]Í__Ë^^ÌaJÎabÍ^`É^^Ëa_Ï^\ÎZXÌ`\É`cÊ\`Í]\Ì[^Ì^]Í[]Í`]Ê``Ç]`É^_É[_ÆW_ÅX_ÄT`¼RX¸QH¶L]¸N[´HX¶JX¶LY¼Y]Ç^bÏelÒjjÔqnÙwsÝ|rÞ€rÞƒvá†xá†wâ‡tâ‰vß„wÞ†t߆s߆sá‰rá‰mà…râ‡oá…là„Vâ„oà‚pâƒkà„qãƒoà€jß„nÞ‚p߆nà‚n߃TÞƒrÞ€mÝnÛoÛ~qÙ~oØ|nØvmÕrOÒqe܃iï®löÄdùÎúÓ‚úØ—úÚžüÛ¡üÖ õƘښ³\~«Nw®Ni´PZ¼VV½WU¼UZ¿XZ¾[YÀ_[Á^[¿^\ÀaaÂ^^Â_`Èd`ÇgeÍg]Â[]¨CUw#R[NXNTG_DZ2]B\:`Hb?eBe;b<`<d@d >ä‡sâ…lá…nâƒkä…mä‰läŠnæˆpå‡räŠtåŒrèŽqè’uêré’qèrêoèpèkå‡jä†mã†mâ„lã†lèˆiæ‹lè†gä~eàr[ØfVÉVP´HM¨>Kš6L;M¥;K¨BP®BR°@M´IR´GP´HP²HQ²JQ¯FM²FN°IS²EK°CM²BM´CMµEO¸LTºOW½OUÂRRÄSVÄSUÆXXÉWTË[ZÈZVÈ]YÆ\\Ê[ZÌ\YÍ`]Ð__Í^]Ð][Ò`]Ï_]Í_XÏ`^ÐZZÑ]\ÎYZÎ^`Óa_ÎceÕb^Ò^`Ñ^\ÒZXÒ``ÎbdÏ`bÎa`Ñ`^Î^eÐ`eÐ``Ð^^Ð`_Ð^]Ð`aÕcgÓdaÒ``Ñ^`Î][Ñ[XÏZYÏWUÍXYÉ[\ÈXZÆX[ÊXVÊX[ËZ[È\^Ê^^Ìb`ÈXVÄ[ZÉWWÌYWÉYXÈ]\Ê[XÎ_^ÌabÊafË_aÍefÌbcËbfÍejËgfÊfjÌaaÎ^\ËbdÍ`_Ì`aËbaÏa_Ë\`Ð][Î^^É]\Í]ZË]`Î]\Ì]\Ê\XÍ[]Î`]Í]]Î^]Ê_`Æ`dË]^Æ[_ÉW^ÅW^ÁRY¿T^µP[·P[¹RZ´JX¹LYºQ^½VaÈYcÏbfÕhkÕqnÙwqÝ}tÜ}tßuà‚tÞ†vá…tâˆuÞ„vá„qà†oß„ná†kà†mà„náƒnáƒnà‚iá†mÝ…pà€ná„pà„pá†lßoàn߃mÞ€pàƒmà‚rßpÜ~oÚpÝ~pÜ~pØxjØzjÕtcÔtcÖveçžsô¿ŠúË—ùÒ úרúÚ«ûÛ¦ýÚ¥úΘ賆ÂvfªLU«JS±NX¶PW»QTºVY¿VX¾\]À^^ÄZX¿[\Â^aÄdhÇbbÍdbÏhgÅ]\¤?Pu>Z9W;V=Z=Z@a"LaBfFdCf;iAd<b@d@f>e<ä„wä†mä„oãˆlâ‹väŽrå‰nä‰næ‹yæpæsè’tè’oêrépê‘péjèŽnçŠfç†jäiâ…mâ†nã†kå†jç‡lè†læ|eÞp[ÙdTÌ[R¶HP¤<Hš5Hž4I¢9Hª@P®@O±CN¯DQ´FN°DO®FL°FN­HP®HN°EQ®EQ°CO²JU²IS·FP·LTºNTºQX¼PU¿X[ÂRVÇY[ÆVTÄVXÇXXÈ^YÅZ\ÉVXË^XÌ_`Î^YÎ][Ï\ZÎcdÎ_\Ñ\WÐ\ZÏYYÌ^^ÉX\Í^\Ð\\Î``Ñ\]Ð[ZÔ`_Ñ\VÐ^\Ì\_Ê^bÎ`_Ð_aÐckÏgkÒbdÑ`^Ò`]Ð^^Ò\\Ñ_^Ò`^Ò^]Ï]^ÍZ\Ñ\ZÑ[[ÍZXÎ[WÎ[WËYVÇYZÉ^`ËXTÊ_aÊ]XÌ]XÌ]VÆXTÈXUÂ\XÃXZÉVWÈ]ZÈZZÊ]]Ì`bÌ`cÎabÌ`aÍdcÌaeËfjÌccÊejÌabÍ``Ê]`Ê^`Í^^Ï`_Ï`^Ë`^Í]^Ì^`Ì][ÐZXÌZXËZZÐ^_Ï_aÐ[XÎ][Í\ZÐ\\Ê]_Î_cËXZÉWZËY]ÄV\ÃQZÂY`¼T]¹T\ºPV¸JT´JZ¶M[¾UcÆ[fÌblÓklÔmpÔtrÙzqÛ~uÞ€uß‚tÜ€t߃sá„tà„tÞ†rÞmÞ…oá„là‡rá†lß‚p߃oàoá‡q߃lÞ€oá…ráƒnâ‚làƒoàkàƒoß‚jÞ€pÞp߃qß~lÚ{pÛ{nÜ{oØzlÙ{kÖviÕtfÖrcÝfî­~øÆŽùИùÖ¤úئùÚ©üÛ«üÖ£öÅÜžy·^Y¨DO¯FQ´OT¸RX½SX½TYÀZ\À^^Â]_ÂbbÂ_cÌecÊfdÏfeÀVWœ:Js?X:W>V<Y>YC^D`FdDdCe>d@d?^>d=cAa<^;äˆvãˆnäˆoã‡gä‡råˆjå‡qåŠpæŒsæuê‘rêrèŽoêséoéŠjèŒfè‹kè‰eæ‡nâ„kä„jã‰rä‡oçˆlç‰næ„gä}gÝq]Öi]ÊXQ¶FK£6Fž0C›3G 8J§?N©BN°CP²DJµGM±KT°CK¯GN°FN°DL®GP°HN¯HQ²GP®BNµEPµKR¸NS¼QTÀSUÂSUÃSXÅZ\ÄVXÄVXÃVYÅW]Ç^^È]YÈ\]É\\Ë_ZÈ[WË]\Ï_]Ê^^Î\YÈ\ZÌVVÌ]]É`cÎ`^Ð^_Ï`_ÑabÑ^^ÐabÐ^ZËZYÍ`^Î`bÌ_aÑ^]Ò`cÐ`bÒ_aÏ`cÐ`^Ï\\Ó^\ÐbcÏ\[Ò]]Ô\[ÒZ[Ò[YÏZZÌZZÍ\]ÈYZÌTTÌ\^ÊXYËVVÊXXÊ[XËZZÇTSÉVTÉTXÆVVÅTWÂZ[ÅY[È\^Ê\ZÊ\\Ì`bË]`Ë_dÈbhÊbeÎehÎacËabÐ``Ë^^Ê^^Ì^_Ë^`Ï^aÑ``Ï`^ÏZ\Î^aÌ`_Í\ZÊ]_Ë^\Ê[^ÌZ\Ð]XÍ_`Î[XÏ[\Î]\Ì]bÌY^ÉZcÇV\ÄUXÀV_¼Wa¿Wd¸U`¹NVµJX¶HY¹KY¾R`Å]fÌchÒhk×pnÔwsØzsÚzqÜ~oÝ€uÜ€uÝ„tà„vß…xÞ†sß‚o܆tàƒjà‚oáƒhàƒpà‚pß‚láƒmá‚oà~jà~kâ‚jã†rá„oà„là€oÞƒsà€nßnÞ~mÞ~lÚzkÛzjÜzlÙyiÚwf×ufÖqbÕpaÕrbæ–pô¼„øË”úÔžùÙªúÚªüÛ¬üÜ©ûÒ™ñ¾ƒÎƒhªJR¦DO¯OX³PV·PT»RYÀUZºW`¾Y[À_dÃacÈdfÌhe¾W[>Nn@Y<X@U>Y?V=\Cb"Od'Pe#Kj%Ld$GdDb>d@b>_?^<`CåŠwâŠpåŠnä†päˆjæ‹päˆqæŒvètè’uè“véoèpé‰oèˆièŒkçŒfçˆkçˆjæ†lä†næ†må‡qçˆjéˆhè‰lç‚gä}fàp[ÖbVÈUP¸AJ¦:I™0Fœ2G£<N¦:K«BP±HR²JT²FP±AP³BL´EP°EP®DN¯EQ²EO°DN¯EN°GPµEMºFN¼NT¾PTÂQSÄVWÁX\ÃVVÅZ\ÄYXÆ\YÁ\^ÄWZÉ][ÉVTÆYZÎ]ZÍ]YÈ]^È\`È^`Ì[ZËZZÎZWÍZ^ÏYZÍ[]Ñ^`Ð\ZÔ^`Ñ^^Ñ_aÒ^ZÐ\ZÐbaÎ`bÐ^]Îa_Ð\]Ð`dÐ\^Ða`Ñ^\Ð\`Ñ^aÔ^^Ñ^aÒ\^Ó^bÐ\\Ð\\Ð^^Ð[[Í]aÊ\[ÌXYÎ[WÏZUÌYTÈTPÇTTÆWVÈWSÆWYÅYUÆVVÉVQÃXZÄVVÈXXÉWWË^\É``Ê]aËabÊefÍafÌbdÊbfÌ_^Ë]`Í_eÎ^]ÌZ[È^cË^`Î_`Í_^Î^`Î][ÌYXÎ^`Î_`Ì^^Ë^bË^ZÎ]XÌ\ZÍ][Ò^^Î]\Ê\^È[`ÈY_ÇUZÂTZ½R[¿S\¾S\¼R\¼PZ»OZ¹L\»NYÄT_ÆZdÎbdÐflÕopÕrnÙwsÚwoÚ|tÝvÝ€uÜxÞ‚vÝ‚tÞ†sß…sÞ‚oà…káƒlß‚oá€iÞ‚tà€ià‚làjà}iß~i߀lá‚pá…nâ‚rál߀jàlÞ~mÜ}nÝ~jÛzjÛziÛ{iÚvjÚubØtbÖtbÕp_Ön_Üdî­y÷ÈŽùÑ—øÖ¥ùÚªûÛ©ûÞªüפøÈå©z¾f[§EP®LR¯OX·MS¸QYºRZ¶T\¼Z_À\`ÅddÊd_Ã\\¥?Lt?Z=V=X@X>\>Z@^@d@fAdAa>b<`@`<a:_>_9Z>\>å†mäˆpå‰oæˆpä†käˆpäˆpçsé’yè”réxçˆjç‡lç†hèƒfè†cç„få‚eç‡jèˆnå‡räƒhæ‡oæ†oè†jçˆkç†låzfÜp\ØgXÇYU´EM¤7Kœ1H4I£:N¥<O«DT®DO²EP²DJ±HS¶HO±HS¯GO´LR°AL±JP®DO¯DM²IO¶FJ¹IP¼MR¼NQ¼RXÄUXÈXTÇYWÆTTÆTTÅZ_Æ\[Æ\[Ì]ZÌYXÉXXÌZYÎZZÌ\bÎ`_ÉYZÍZZÍ\\ÐYXÒ_^Ñ^bÎ`aÑ^bÐ^bÒ][Î\_Ñ\YÐ\bÎZYÒ`^Ó[ZÐ`]Ñ_`Ð^^Ð_bÒ`^Ò``Ò]^Ñ^]Ð__Ñ``Ð]\Ï\^Ò^^ÐZZÑ\ZÔcaÒ^\ÓZXÐ[WÐZXÏ[UÊWVÌZVÌXTÃXVÈURÆXUÄUVÄWTÃSRÅXRÂTR¾XWÆVUÈVWÉ\[Ç\]Ë^_Ê\`Í_bË_dÈadÎbeÍ^aÍ\^É\aË_`Ë^_Ê`eÌZ\Î`gÍbdÍehÎ[^Î\_ÏbfÍ^bÌ][Ê_bÍ\XÐ\YÎZZÏ]YÐ^]Ë_aÉYZÄY[ÈZ\ÈXZÄRWÂX]¾RV½S]ºQ\¸R]¶NY¶KX¸MZ¿R]ÄXdÎ\`ÑjjÒlj×qnÖtrØxpÙypÜzpÛ~sÜ€wÞ~pÜ„w߃tà…tßjß‚lá€jànàƒnÝ€rÞ‚lÜ€qß~gá€kà‚lß~lâ€nà~jâ‚nâ€qßmà~lÞ|jÞzfÛwfÛxkØvfÚtgØvjÙtbØsbÔqdÖq^×o\Ös_ä“oòº‡ùÌ”ùÕ¢øØ¦úÚ¬úÛ§üܧüÔ›ð¾…ÑŠl®MRªGP®LU±MV±OV´RY¸SYºZ]À]bÉheÁYY¤>Hw"A^>V<V=X>Y>]A_BaHg"If&KdCb@_DaD`B]?^<^:]>\;ä‰pä…käŠläˆlãˆläˆrä‹qè’uê–ué’vèŠmæ„hæ€eæ‚gæ€hæ‚bå€eä‚iç†gè‹dç‡må‡hã…nä†læŠnçˆlè…nå|fÞub×bWÉVS±DM£=L˜/E3F£=M§=N®AM­CP°DQ´EN´EO±GR²EQ²BN²HR²HO°FL®FP±FO²FPµHPºLR»IR¾PTÁU\ÅRVÆVVÆVXÈVXÆXYË\ZÈ^[ÈZYÊ\YÊ][Ì[ZÎ\XÌ\YÊ^`ËZYË\[ÎZ[Ê\^Î^\Ï^bÑ]]Ð`bÑblÐ[^Ò^^Î\_Ë[]ÍZXÎ_bÐc`Ô^^Ð`_Ó^_ÑbcÒ\_ÒabÑ[ZÓ^`ÐZ_Ò[YÐbbÑbbÒZZÒ^ZÐXYÏZYÒ[\Ò_\Î[\ÎZ^ÎX[ËZ^ÈXcÆdqÄhrȇÇuzņ‘Ày~Àv~¾jp¾kr¼[`½X^ÁWVÅWVÆXWÉ[XÃXZÈWZÇ^^Ç\_ÇZ_Ë[_ÈX\Í^aÍ^^É^`Ï^`Ì^cÍ]`Ð^aÌaeÎbcÍ`dÎ\\Ñ]]Ï]^Í\`Ì`cÎb^Ñ[UÐ^ZÌ]ZÎ]`Î]^Ç\^ÊZ^É]\ÈY_ÃS\¾T^½Q\»R\¸VaºPX¶JT·JZºLY¼P\ÅT`Ê^cÐhgÔlkÕnfÖvqÙtiØwpÚzrÚ}sÚ|vÝ|nÝ€uÞ‚tÞ‚rÞƒqßoÞ€l߀mà€mÜqÞlß‚pßjá€jâ‚kâ€iâià~hàoáià}hßzlÝzgÜzjÚwjÕuj×qdØwhØqeÚrcØtbÖrcØsbØp_ÖrdÜ{dì©xöÅŒùΘùÖ¤úÚ¨úÚ©ûܪýÙ£÷Ìæ­}ÀhZ¨FR­JT°KS²PX¸U\¹RZ¼^bÁb`¼X\£@Nv@[>X?W=X@X>\A_AdCa FeFg"IgFaEa@dAb>^9^<`;_>]<æ‹xä‰qåŠså†nä…låŠtçŒnê’uìréˆhæ†hå€hä|cæ}cäz_ãz[ç|bä€cçˆlèŠjçŒpç‰lä†qå‹uèˆlé‰pêƒbå~lát_Ùj^È\[²GS¥;K™3Jœ2H <R¦=N­>O®CL²FQµFN³HSµKT´LU°GN²FR²GQ²FM¯EN°FP³HN¹GN¸PW¹NU¾RY¾QYÄUTÌXUÅWXÈZYËVXËZXÉZVËYUÍ[ZÊ[YË\ZÐ]\Í[\Ì\`Ì^cË[\ÑZXÎ]aÏ^]Òa\Ð\\Ñ[^Ð`bÒ^bÔ`bÒ]]ÎZ]Ð\]Ï\^ÒljÒ_aÐ``ÒbbÒdmÏ]`Ô\`Ð]_ÒYYÑ_`Ñ[[Ó^\ÒhfÍ_eÒY\Ï\`ÌZ\ÎbnÈ_fÍz‚ÈpuÅuÂs{¿x…Å„‰ÊžÏ”‰Î šÔœ•Ρ¡Ðš’Ѩ£Ô¤”ͤ¢É œÀ€†Áu}¾[]ÁVYÂRTÅTTÂVVÁVZÆXZÈ\aÌZZÌZ_ÍZ]Í\^ÎY]Ê_bË]aÏbfÎbfÎ`hÎacÍ_dÍ_cÉY_Í[]Ë]aË\\ÑZZÐYZÌ__Î\^Í[ZÌZ]ÌY_ÇYYÅV\ÂT_ÀR[¼Q\½S[ºR^¼LV¹KT¸HT¹NY¸UaÆU_Ì`eÒgdÕklÔqnÖsmÕup×toÚulÙxrÚ{uÛzrÛxÝ€tÞ€o݃rßlÞ‚pÞ~jÞ~mÜnÝ}oÞ€lÞ€náiâgâ€lâ€ià|hà~ià|iß|hÞyhÞvfÚxfÚvhØwlØvdØvjØrc×tg×udÕpaÕvdÖsdÕqaØqbãpó¶ŠøÈ’ùÓœúצúÛªûܪýÛ©üÔœóĈזt°RW­W_®OX³SZ¹U]¼Y^¼_a¼VV˜8Jq B\:V?ZBZAY<Z@]@^BbDgGh"Fe#IcDfAcE`=]<]>]=\<^?\<æŠuäˆnå‰kæˆlä…nèŠmè’yê”sê–pé‰læ‚eå}eäw]âw^âu\ßxdâw]âjèŠnæ‰hæˆnå‡mä†pä†réŒrçŠpé„hæ}dàs_Üe\Í]Z¶HO¦<Mœ6Lœ2J 9K¨<L¬=O°@L°BQ²FR²FUµFQ±JX®FP³EM´HO´FM³CN²DL´FL¿FL¹PS¿PVÀNQÂLPÄQVÈUSÇYYÇVWÇYXÊYZÌ\[ÌZYÊ^[Ì[VÌ\YÏ^ZÌ]^Ì^^Ð\^Î^]ÐZZÒ\\Ñ^\Ó\\Ð^`ÑcdÒ\aÏ]^Ð^_Ï[_Ð^`Ó]_Ï^^Ë]_Ð]\ÐabÐb`Ò`bÒ\^Ò^\Ò^]Õ_[ÒX[ÒZZÐ]^Î\bÐirÍivÇr€Æq}Æ~‰Â}ŠÃ}‚¾|ˆÀ~ŠÈ‰ŒÊ––Í’ˆÏ”ϥΡ›Î£›ÎŸœÓ­Ñ¥˜Ö´¦Ù¨˜Ö°§Ú³¢Ó¤šÊ§¥È˜™Àv|¿`h¿WZ¾UX¾VY¿X^ÄV]Ê\_ÈZ`ÈZZÊ\^È]_Ê`dÉehÈdlÉagÌdiÌcdÌ`bÌ\^ÏaeÏZXÍ^^Ð]^Ï[^Î`_É[^Í\^Î^`ÌZ\ÇY^ÉUVÃX^ÁV\ÁNV¼OZ½NZ¼P[¶LX·IV·LX¸P]ÂX`Ì\cÐed×kjÖqjØsnÖqmÕtlÖxpØtl×{xÛzrÜ~pÜ~vÞ€pÞpÞqàqÜ{mÞ~nÞ~ná~kà}mÞjà€lâjägâ€gß{eá|hßzjÞ}fÝzhÝxdØwfÙtfÖvj×tdØvh×rb×paÙr`ÖscÖrbÖsdÕobÖubÚxeë¡wöÀŒøÍ˜úÔ¤úبûÚ¨üÜ©ýÚ§üÏ—ì´Êxa¯NU«KT¶UZ¹U\Â_\¼TVŸ@Nq@X :V<V>X:W>Z:`@`Ae!Ga@f$Id$Jb"Gd"FbE^>[:Z:\;a<^;`<`=æˆqæˆræ…nä†näˆtçŽqì”sì”uë‘qè†häbãt]ßt\Þp^ßn\ßqcáv`ä‚jç‹oèŽmå‹næ‰lçˆqæˆqèŠlè‹nê„iæhÞscÜgXÎZV´FL£:G™2Hœ6F£9I¨:G«>N¯?L°BR·FP²ER±IQ²DN¯DM¯EN³GP´HP¶HO´EN¸FK¾JO¾MNÁNVÁOTÂQVÇTVÈY]ÈWVÊXZÊVRÌWTÌ\YÌZTÎ`_ÍZTÌ\XÍ\YÊ[ZÊ_\Ì\ZÎ[\Ð\[ÑegÐ`bÑ_`Ò__Ò^`Ô^bÔ^^ÔacÒ\\Ò]aÑY^Î]`Ð^]Ò_`Ôa\Óf_Ô]\Ô\\Ó^\Ô\YÑZXÏZ\Ì[fÌivÄw†Ç{„É‚ˆÇ}€Æƒ‡Çƒ†ÀƒÂŠÂ‹Ê“Ò —̘͌”͘‘Ïž˜Õ¦šÔ­¨Ñ¨›Í£žÒ¦›Ò©ŸÐ§–Ѧ”Ò£˜Ö¯¢Û¶§Ú´£Ø³£Ï¥žÄ”—¼pz¼]f»U[¼NWÄWYÇUXÈZ[ÆY[ÆX^È^bÌ`dÈdjËahÌ_eÐ^bÎ`cÌ\_Ï^^ÍZ^ÎZYÎ\_Í\ZÏ\[Ñ[^Ë\^ÎXYËVWÅT_ÆVZÅS[¾W`½SX¾MW¼OZ¼MWµLY°J\·KV¸P\ÄV\Í_fÒfaÓmlÔrlÙtjØsjÖsj×umÕuqÙvlÜzmÚzrÜ{nÞ€sÜnÞ€q߀nÜ~nà€l߀p߀màkÞ|hà~oâ|gâ~gá€iàzfß|hàzhÝvfÞubÜwgÚudØrd×qg×sb×pfÖpfÖpaØpb×p^ÖpfÖn^Ön_×pbÖveß„nð°‚øÆ‘úКøÖ§úÚªüÜ­üàªþئøÉŽâ¡v¾c[²PXºX\¿]]ºXXœ=Lq>[;S:U<Y=Z<Z>Z?^?bDcCcBfCdBdEbA`EZ>X9Z:^8a8]7_=^;æ‡tæ„læ‡kçˆræŠmëpì’pê’lêŠmçhäx`àr\ÝlWÜiZÜm]ÝkYàw^ä‚gèŠlèŒhæoæ‡på‰lèŠoéŽsé‰iê†hå|dár\ÚfWÏWR¸EM¦8Gš2E˜3F 6K§<L©8L²BO°DN³GT´FQ±FL±IR­DR²KO³DM¶CLµGQ´GP·JP¾HN¼HPÁMTÃPRÅRVÉTSËVVÍXWÍZVÆUVÊWTÍZXÐZXÒ]YÐ]ZÏ\VÐYVÌYUÎZZÎ\]Î^\Ð_^Ò_\Ð]]Ô`]ÒZZÑ`aÖ__Ô^^Õ_\Ò`_Ð^aÐ]^Ñ^^Ï\[Ð]^Ò[ZÓ^XÓ]YÑ\`ÒZ\Ð[]Ð[aÌfrÆt‚Ãv€Æ~‚Æ}€Ê†ŠÃz‚¾s|Â|‚ÄzÃ|ƒÊŠŽÒ–ŽÎ™Ì›‘Θ’Ηϣ ÔªÕ§›Ô§˜Ð¥œÑ¬žÍš‘ʔ̟–ЪŸÕ¨”Ó©šÖ³¢×­œÝº©Þ¸¥Ø³¢Ð¥˜Â„ŠºdoºPWÀRXÂSZÃY_ÆX^È[^É\aÈ`dÉ\aÌ[`Ï]`Ð^`Ê\eÊ]cË]`É[]Î^_ÌW[ÎYYËZ^Î^^ÇX`ÆT[ÄVaÉUWÂSX¾T`ÀRX¾OX¸P^·QZ´JX²IV»IV¼MZ¿X`ÎbcÔgeÖnjØoiØxuØsnÕtqÕroØupÚwoÚwrÚxqÛ|wÜzsÝ‚rÞ}qÞ~nÞqß{lÞ{gÞ|là~jß{lß{ià|hÞzhá|hÞxjÝzfÞsdÝweÝscÜreÚtdØpeÖn`ØqeÖo`Öod×ocØp^ÔrdÔsc×scØn\ÕpcÔqdÖudç–qô»†úË’ùÓ¢úاûܬûß®þà®þÖžóÂÖrºYZ¾YZ½XY£GQuA\<R=U >X>V>X=[>Z>`@dDfDbCb>d@`>`@\@\@[>^<`9b:\8Z9]8è„hæˆoç†iêŒsèrìoì’rêŽnè‡håeàsXÞlYÛ`RÚ^RÚeZÛl]äu^ä…gèŠjê‹iç‹mèŠnè‰pé‰lìkèŠpê†eæ€jãrZÜjZÎVP¶FL¤6F—.Cš6I£5J§:K¨<L°?J¬AP±CPµFN²AM±BP¯FL±FN¯FP³EM¹IQ³CL¶EPºJN¼MT¿RZÄVZÃRUÊTWÌVTÌSUÍWVÉZXÌYYÍYXÐZ]Ð[\Ð\YÎ^ZÑZWÎZXÎZ[Ò^ZÏbaÑa`Ð`]Ñ\\Ñ\\Ñ\bÒ]\Ö^`ÔYYÔ\\ÑXYÓ^ZÏUVÑ\\Ð^^Ð^]Ñ^\Ô\\ÐY]Î[cÊanÉ_pÀfxÆy‚È}†¾qÀz„ƆɄŠÀz„½u~¾tyÇ‚…Æ‚ƒÈ‚„ÌŒŒÐ“ŠÉŒ†Ì””ИŒÐœ™Ô¢•УѮ¦Ð¦ Î¤ŸÎ¡šÌ¢Ð ’У™Ô° Ò¦“Ó¬ŸÖ±Ú³¤Ù°¤Ý¼ªß· à¸¢Òª¢Á|‚ºU^¿PVÃUZÂUZÈRWÅ\_Æ\bÈ^hÌZbÍ^dÌ\bËbjÊ[^Ë\cÈZ\Í^bÌ[aÆY`ÊZ\ÊW[ÉY`ÉSYÅX]ÅTYÀR^¿PX½R]ºO[¹QXºPX³JX¯IY·P\»NZÂZ`Ï``ÒhfÙlgÚshÛshÚtk×rlØsnØsnÚvnÜvnÙxtÚzsÛ~xÜ~uÞ~sÞq߀nà|lÛylÞ{nß}mÛ{lÜzfÜvfÝvfÝzfÞvdàxcÞubÜtcÜrbÜp`ÜvhÚsd×ndÖnbÙod×lbØn`ÖocÔse×od×pd×o`ÖnbÔrcÓkbØv`íªzøÄŒúИùبûÛ«ûܯþà¯þÞ¬ýҘÉuf¼\Z§DOz"D\@T?T>XAXD\D`@`DbCcFdEd Eb@b>d@^>W?X>\FbHb=`:_?^9\9`<é„mæ…lçˆpêŒqë“pí–qì‘lêŠhè€eäxZÜmUØcSÖXOÔ[RÕ`YÛo`â{bæƒfê‹léjèŽkê‹nç‹lêuëpëŒpé‡læ‚iâubÚfXÍZTµBI 6J–-F–.D¡4E£5Hª;H°?K¬>M®@L¯AM±DO²@L²DL²FO±ER°BN´FP´IRµIQ¸FO¼IS½MTÂTZÅOQÈTVÊSRËUVÈWVËYVÎUTÎ\\ÌXZÒ\]ÐWWÎZXÑYUÏ[YÎZYÍ`^ÎYZÒ[ZÒZZÒ^^ÑZ\Ï_`Ò]\Ò`cÏ\^Ó\[ÑXZÐYXÐXZÎ]]Ï^`ÊbnÍeoÍpÌpyÅjw¾`k¶dvÃtxË€Äv~¾zƒÅx~Å|~Év{ÇzxÆzzÅ‚ŠÈ‚Æx~Ç‚‡É…Ȇ…ƖʇƒÎ’ŒÍ“Ì•‘Ó Ò¤ŸÔ¨ Ñ¢™Ò¦–Ï¢šÒ©™ÕžÒª¡Ô¯š×§–Ó« ÚµžÝ´¤Ø´¥Ûº®âÀªá»¦Þ¶¦Ìžœ¹jr¼PYÀPU¾T\ÀX`Æ]gÉ[bÆ`iÉ`hÇ^fÌ\bÈZ_ÉZbÌ\`Ï\^ÈY`ÈZ^ÌVZÊX^ÆXZÆUXÂS[ÂRW¾NV½QZ½R\¼NU»R]¸JS´O[³HV·Q^»NVÆY_Ð^_Ôji×poÚndÚshÜvmÙukÙriØtmÙuoÛwoÚyqÙwqØ}xÙ{vÜ|uÝ|mÞ|qÞ}iÛylÝvjÞzgÜxhÜweÜvcÜubÝxcÛwfÜt`ÜthÛraÜrbÚtcÜp`ÙpeÙqcØk`ÖndØm`ÚkXØpbÖo]ÙpbÚp`Øo^Øo^ÖpbÕl^Ôl`á‰fó¶„úÌ•ùÖ®üÚ®ûܬýß®ÿà­ÿÝ©üÌ“ážy²MR~#CX<W@S>U=W;Z?Z@_CdBgCe?cEcAb@cAaBZ@Z?`F`B`B]:\>Z9Z;_<`:æˆoçŠmèpìoí–zì“mê‹mèƒlæzbàrXÚdTÐVKÍSOÎRN×dZÝvhâ~lä†gèŒlìŒléŽiêŽlè‹léŠlêŒnéŠné„hè}`ãvdÜh[ÌVPµCL¡4F—*B”/Fœ2EŸAX¨>M®@O©>M­>L°AN°BK°FS±@I¯CM²DL±?L³@JµJS´JPºFO¹JR¼OT¿NSÄQRÃTWÆTTÇTTÌVTÉXXÉX\ÊVWÊZ\ËZXÅZ\ÌXUÊW\ÇXTÍ]XÌ]^Ì\YÑ^\Î^^ÐZ\Ñ\_Ñ]^Ò]^Ò[ZÑZZÒX]ÍU]ÌalÉZkÍkxÎ~ŒÍ~ˆË~„¾rz¾fm¸Xe¼Ydºix¼hrÄnsÀpxÄrvÄx|ÅrwÈqwÅvzÈ‚ƒÊ}€É„‚ÉxzȂʆ†ÈŒÇˆŠÊ”ŽÎ˜–Ì™‘Ï”‘Í–Ò¤—ҜϗŽÑ¨œÖ§”ϜҬœÙ¨–Ó«¢Ú¸§Ø®žÖ²¦Üº¦Ý¶Ü¶¢Ü¼®Þ¼­à¼¦à¹¥Öµ¨¾~ˆ·T_¹NV¿V_½[dÃV_ÄY`Å^eÉ\dÇV\ÇV[ÆXcÉ[`ÉY^ÇX]ÍZ\ÌX\ÇW\ÃTZÀRX¿R\ÅQWÁNW¾MXÀOUºLV¶MYµGT²FT²IW¸MZ½OVÅR\Î]`ÓfdÖmlØrkÜvnÚulØulØtjØsmÚsmÝtpÙvpØzw×wuÙxsÝ|pÞ}rÝ}nß|nÞzhÝugÝwfÛtbÝxhÜxfÚsbÜr_ÜveÜteÞudÛucÚqdÛp^ÙrfÚpcØpbØpeØn`ØpfÖl\Ùm`Øl^Öl`ÚoaØo^Ùo`ÕsbÔmaÔl\Ùq\ìŸsùÄúÏŸûתûÜ­ýÞ±ÿß®ÿà¬ÿÚ ñ¼ˆ©HP\>RAV@U?XAZAZ?X>bAeDf>d@bBd@eBdD_C^D[@^>aD`>]=\A]?\:_:b9æ‡rèŠmë’xì”ní•vípê†jæ€fãzfÞiZÐXPÆJJ¾EJÇOLØ`XÞrbã|dæ†iêmê‘pêŒkìŽoèŠmémëˆkíŒjê†jèƒgät[Þk\Ð[PµDM¡6H–3G“.G˜5M;N 7J¦=L¨CSªFP­GT¬AL¬AK±AJ®DM­AL²DK±EM´FQ³IS³HR¸KSÁJUÀMSÂLQÆTZÅSTÇUUÆRUÆXZÈZ\ÌUTÉW[ËTXÎWUÌ\_ÎYWÊZZÌVUÍ\[Î[^ÏZXÒ]`ÐZ[Ò]^Ð^\Î[^ÐUXÒX\ÑTZÕelß›ŠÐy€Ñ„Ê}|Ãv{¾ow¾biÀbiÂ\c¾\i¹_n¸dlÀlwÀlvÀnsºfm¿kp¾jrËzxÇqwÅutÈ„È|{Ê…ˆË€~È„…ˆ‚Í“”Ò…Ï’’ÍžšÑ›Ê”ŽÌ˜—Ò¢‘Ô¤—Ò«¡Õ£‘Óž×´¥Ü®—Ö¬™Ø¸¨Ü±–ܰŸÚ·¨ßº¢âº¡Ý´¦Û»°ßÀ«ä¾¦ÝºªÇµguµR_¸Xc¼PXÂS[ÂR\ÀWZÂX_ÉYZÂV^ÅX^ÆX^ÇV\ÆV]ÆX^ÆX]ÄV]ÂT[ÂPTÁPXÂPVÀQWºNX´L\·LW³KU²DR°EQ´KX¼OXÉRWÎ`hÖedØpiÚriÜtnÜvnÚul×tiÙrjÚqjÚwjÜwmÛvnØsmÚvrÜ}qÜ|rÞzkÞ|nß~rÞzlÜtdÚqcÛtdÜqeÚpbÜrbÝr`ÜueÝtcÚvgÜqbÜr`ÜpbÙqeÙpb×pgÙo`Øl`ØpaÚp_Ûn_Øo_×pfÙrcÛo`Ørd×o_Õm^Õk^à}dò±‚ûÅ‘úÒ üبýݰþá³ÿä³ÿÞ£ò¾€‘.CM 8P>R=W?V@\@Z=\>dBhCc@bBbBdE`=]?Z=\B_@g#I_@^BW<^B`?_6d=f:çŠrèrë“pí˜vì’qêŠjç‚håx`ßp]Õ^OÄKM°@J´@JÈUPÖdXÞugä~fæ†dêtìlëŽmêŽjêmêŠlìŒmê‹oë†iè~hãvaÝf[ÎXS¶FO 6J”,D0F™2J›8LŸ6H£:L§=L¬=N©@Nª@Nª?K­AN¬AM¬BI²FM²CL°CL³FO¶EL¸JQ¹LV¼NXÁPVÄQVÄTVÄPRÅTYÆWYÃZ^ÆXZÅTSÍXXÊVUÌZZÏXVÉYZÎZVÐXXÎ[\Ñ[YÐZYÐZ\ÐXZÐXXÎY\ÐXXÎw‚Ïb`Í`dÇaeÈmqÆllÀgj½cj»^jÀbh½\g¼[j¼\h´`r¿gnÁnzÂlp¾nvºfr¹erÂhpÅw¼htÅrxÆy|Ê~}ʈˆÈ„ňŠÌŽŠÐ–ÍŽ†ÍŽ‡Ð˜É“Í ›Ðœ—Ц Ö¬Ñ–Ò²¤×²£Õ¬œÖ± Û¯”Ö¥–ײ¢Ý¸žÚ®™×±¥Ü¼­Þ¹£Ý¸ªÞ¼°àÁ±âÁªÞº¥Õ°¨½‚ˆ¯Xf¶NZ»NXÀPXÀV]ÄT\ÃSZÄT[Å[`ÆV]ÇW[ÆUXÇU_ÆWYÂV[ÀUZ¿TZÃOW¾MS¾PZ¶KW³JY´LW²FS²GU²@J·KW¾KUÇT^Ö^`ÖhfÜlbÜqhÞwjßvnÛtmÚthÙslÚsjÜtnØwrÚvoÚwrÚunÛvnÛ{uÝxkàylÞ}oß}qÜwhÚuiÛrbÚn`ÚnbÝraÝsbÜsbÛvfÚtcÜqaÛsgÚp`ÚrbÚufÚpeÙpcØodÙpbØpbØo^Úp_ØsbÚqaØthØqfÙl_×oaÕpfØsfè–sø¼ŠýОüتþÞ°þâ¶ÿâ¬ýÔÑ|_Z8P>Q=T>W>Z?\@_?bBfBeDdAdCeA`<[<Y>Z>`@d!Db?]<\=X;\9`;b:hAf=éŽmê”ví›sî—rëvê„då€dãw^ÚiXÌQK¶BF¤3C²9EÈRNÕbVÝsbä€fç‡hìŽnêŽhêmèŽléjëŒníŒnìŠmêŠnè}hãv\ÝfZÏWO¶CIž4G+BŽ-C–2F›0E¢4G¤:I¦?N¦?L¦@O¨=J¬CN¬AK¯DJ®CM­BL¯FS±FT·FN´HSµHN¸MV»FK»OVÁRYÇQRÄTWÄS[ÃVYÉSRÈUVÇRUÊZ[ÊWZÇ[]ÈZ\ËXWÊW[Í^_ËZ\ÑZZÎWYÎ[^ÏWUÐXYÎV\Ög_ìšrÊNMÀV[¾_d¿\d¼_c»`e¼X]»]g¼\e¹\f¾`n½^cºbl¾ms¼nvÁlp»ip¸doºhpÄptÀsxÂprÄpwÆtwÆ|~Â~…Át|Ë…†Ë„~Î’‹É…‚ĉŠÌ–’͌ӧ—Ó›ŒÐš–Õ¦˜Ù®ŸÙ± Ö²¥Ú°œÖ¥–Ô¯£Ú²˜Û²ŸÛµ¦Ú¶Þ°–Ú­¢Ú¸®à»¦àº¨Ü¸¬Ú»±Ü¾«â¾ªÛ·¢Ã–™´cm²LX³NX¸NW½NX¾T\ÁYd¼T]ÅU\ÄSXÃTYÅS[ÇSXÂTZ¾S]ÀTY¾Q\½NVÀOV»MX´P_·GT´LX±FS®FT¶FR¼LZÁS\Ï_aÖffÚnhÜtiàvjÞyoÜujÝtgÛsjÛsjÜqiØtnØrjØtnØsnÚupÙtnÚunÞ|kÞ|qÞyiÜxoÚpdÚpbØnaÚndÞo`Ûo^ÜpbÞqaÜvfÞp`ÜoaÙqdÚscÛrdÚpeÚo`Øk`ÛpbÙn^Øl_ØpaÚueÙrfÚse×tjÚrdÖpcÒqe×n`Üykï¤|ýÊ•þצÿß²ÿà­þÕ•ê¥p‚)AL :Q>Q 9U=X>YB^@dCgGfCcBdBhBb@[:Y<X<]@a@c@`BY=Y:\:]:c<g>c9\8ì’pë™xîœrî”mì‹kéƒiåxbßq`Õ`W¿JI¢:J–+B¯>FÇQOÖe\àtaæ~eèŒkéŽnìkêŽlëjçqè‰jì‰kêŠnê…hçzbãrYÞf[ÐVN¸FNœ2E-FŽ)C“.G™4HŸ8M¢>N¥;L«:Gª>L¨@K¯>K¬@M­CO«BQ¬EP®DO®EN²HT´BN¸GM·FR¸DNºNTÀNVÁPSÃQUÀRXÂVVÃQTÅPSÅTXÊ`cÊZ[ÈXXÌ\[ÉZ[ËZ^ÎZYÏVVÑZXÌZZÌZ[ÌXXÌQWÏXZåœ}Îo\ :T¶NY¼\cÀZbº`i¼X[À^e¸X`º`jº[eº\e¸Wb¾biÂjpÁflÃko¼eg¹fp¼jr¾lvÀnuÁkoÆs{Ànw¾x€ÄrtÅz‚Ɔ„ŃƒÄƒˆÈŒˆË‰‰Ò¥˜Ôž”Л•ΣšÔ¤™Ô¦šÖ°£Ø®šÕ£–Ø´¢Ú´£Ù¨”ر¤Û¸¤Þ®—תžØµ¤à¹ Ý¶£Üº­Þ¿°Þ¼¦à»­Ú»¬Ú¼®Úº¨Ýº¡Ô®¡¸t{­N[¯FT´IV´OZ¸U`ºPW¿NS¾RY¼RXÃR[ÁTZÂRXÀT\¾PYÁLV¼OY¸JU¹LY´LZ³KX¸HQ®FR°AQ³FVºNZÅW^Ñ_aÙjfÝmgÞtlâwlàxnàylÞxlÞtfØuqÙrmÖspØtlØqlØrm×pmÖpi×upÙunÞxpÞ{kÞ{nÚrbØphÚlbØn`ÝnaÜneÜp`ÞsdÞtbÛteÚpdØoaÚrfÚodØqaØpeÚo`ÚpbØohÙoaÚqeÙsgÙteÙp`ÚtdÙugÖrf×ufÖteØshâƒmù¾ˆÿÒžÿÛ¥ÿÒ–ï«xŸBHT=N>Q>T@T@V<\Bb?gCf Fd@f EgAhC`BX>Y=]?cBbA^@X:Z?[>`;d>k?d>T2I2ì“rî–wî•wìré…jæ}fâtdÚdVÊTR«<F—*B–*B¨;IÅRMÔbZÝo\ä|`èŒlêŒkì’jëqêŠlêjèŠmìŠlêŠlêƒiè|bâmYÝcUÏUQ¶CK4D)BŽ)B˜2F›6H :K =L¤@N¬<L©BPªCR«@N¬AO©DO«BP«DP¯GT°CL®DP´FN´HPµKT½LS»NU¾PUÁPSÄNP¿OUÅRTÄRRÄVZÄTVÆWYÇV[ÄVZËUWËZYÎZ^ÌVYÉ]_ÐZXÎZZÐZXÐXXÏ\\ÐXVâuXÂRT²IZ½PX¿V_ÄVYÃ^c»V`½Xb¾_iÁei½[h·Yd¸\dºdp¼dnÃilÀkr¸fq·fq½go¾jsÂouÆrvÁjnÄknÅpuÅxvÃx}ÄvyÆ€|ˆ‡Ì‰†Ð’†Ð“‹Ò¤ Ó¢Ó ›Õ¤˜Ö¤Ô¦šÔ¬ Ø¬˜ØªØ¯ Ø°šÞ°ŸÙª¢Ü¹§à´ŸÜ¯œÜ´§ß¸¡áº¢Þ¸¬Û¼²ß²ݼ¬Ú¶¦Ú½³Ü¾µâÁ¬Û¾¨Á–š¬Wc±DT´MX±JU¶GP¹JS·LW½QX¾OWÀQZ¾PXÀOXÂOU¼N[ºLU¶OZ´O]²HX¶JW´JV±HR­ET´GU¹NZÄP[Ò`eØjdßpiÞvnâzqâ{mÞzmßxqÞwlÚtjÙtnØrjÖro×mhÔtmÖnkÔokÔmfÚnhÛrlÝ{mÞzpÝsdÛtjÛpeÙndÜo`Þr`ÞraàsdÞugÜteÛpdÛr`ÛpfÜoaÜqaÛpd×nbØqhÚpgÙpdÚrjÛqhÝtfÚnbÛseÜtdÚukÚugÝxlÛxnßxjó¢~ÿÈ’ÿÌŒï§q£HNY?Q;T>V@U>V<[=\=dAa>d@cBfBgA`AZ@\A]@`BdA_AV=Z@[>\=bBi"Cg!DW9F3D3î•~î”pî“oìŒkç„hçx^ßlYÒZT¸FNš.>*C–0F¬?LÈRNÒc\Þp\ãyaç‰gìŽlì’jêrê‰nêŒiìqìŒné‹mæƒkæ{`álXÜfXÍVQ³EK›/D(CŽ(B“2J›8L¢4G¢;R¢@RªFW«HVªGY­HX©BP­GR¬COªAQ­EP¬DR¬IU³DR´KV·JT¸IT¼NRÁRXÄTY½JPÁMQÃSVÁSXÂUXÂUZÅVZÇUYÆUVÊUZËX[ÊXXÌ\[Ì[\ÐYXÎWZÑZ\ÒXYÏZVÐpg»NR»MU½RZ½KVÂV]ÂW_¿V]½V_½Za¾Z^¿_h¾\e¼\g¼\eÀdmÅlpÃnqÀks¾en¾ku¾jsÄovÆorÄirÃacºktÀt{¼krºjtÈ{Êyż…Њ…Í’ŠÓ—‰ÔšÓ¤—Ø¢ŽÑšÒ­ Ø¥‘Ï –Ó©£Û¯˜Ö£”Ô¦žØ¸«Þ¶£Ü±ŸÛ¸©ßº¥ß±žÛµªÞ¾¯á¾¥àº§Ý»¬ÛÀ²Ý¾¦Þ»ªÜ¼®ßúâóáÁ©Ë¡šªYg¦CUªBP¬HS¯HQ²JS¶JR¼MT¼PWÀRX»NX»PY¹NX¸NZ¶MV³K^´IVµJU³LX¯IY®AN²FTºJXÅR\ÑZ]Ùihßnfßwnâzräznãzjâynß|qÜyrÜwnÚrlØmiÔjlÕlkÔjhÓklÒgd×lhØoiÛwkÝylÝvhÝthÜpbÜpbÞp_ÞreÞofÜsfÞt`ÝtiÜpaÛo`ÙpiÚqbØpfÚpdØoeÛsiÜrcÛrgÜteÚpeßsdÝtgÛtjÜtjÜwiÚujÞznß}pà{nî’uù´}æŽi›<FX<W?WBW>V=X<Z>]>`<d<`@d@cCd?a@Y@ZBcFeDg@bB^EX<]A\@d>n(Jp,ObAI
+3?0R9î”zï”tïlì…eèfâr\×cWÄTS¨;H”.D(Aš3E°BJÃQSÕbXßp[ä|hé‡jênì’pë’têŽtêŽrê‹në‰lê†gé„jç{bàoZÙg\ÎTP²BI™-BŒ,BŒ(@”1E6JŸ:K¢>P¨?O©DV©DU§AR¨L^§DT®CNª>M­BN°@M¬EQ¬?N°EO²GR´KU·LXºKR¼PX¾NXÂTZ¾TZÀRUÃQYÂTWÆRTÈXYÆUXÄTTÍUVÊWWÌTXÌZZÐXXÑYXÍUVÎV[ÏSW×ppÕdWºMU»Q[ÂSVÀVX¾RW¼PW¶MVºSaÁU\¸Vb¿^dÁ\gÃbiÁ^bÀ`iÃjmÀ^a¾gn¿mpÁjrÆljÌmoÈnmÀeo¼enÁrzÈnrÉ|yÇrpÈ{€È~|Àw͆Ά‚ΖӘŠÐ‘ˆÔ£•Õ™ŽÓœÖ­¡Ø°Úª–Õ¨ ×´¦ß¸ŸÜ±¢Ú¶¨Ý¹¦Üµ¢Ûµ©ß»ªà¸¢à¹©Ü»®Ý¿®ß»¥Úº©Ù¹®ÚÀ´ÝÀ²àÁ³à·áõãÄ­Î¥š«bož>MŸBN¤>J¬BN®DNµIR³LW¸R[¹KR¹PW¸LX´JX°HW¶JV³L^¹PVµIU²ET±BR¯FV¸IXÁS\Ð^e×jjÞqnàvhã}nã|kã|mä~pàylßzoÞtlÚsjÙmfÔhdÑfdÍfiÎcfÐb_ÒbaÔieØpiÜxpÞymÞviÞrbÞobßp`ÞpeÝqeÞtgÞuiÞsdÞq_ÜpeÞpdÚp`ÛoeÝobÙrfÝqfÛshÛrcÛsgÜrdÞvfÞqbÜvhßxjÞyiÝxjÞwjãnålç„lÖo\’2C_AU?ZBVAV=Z@[?a?`=b@f>e>f@f;b>[<U;^Bg$JdC`>ZEV@Z>bEbCq)Ls.QfBT;D6K;E]ï•xî’rì‰nèƒlæxdÜl^ÏVS·DH1B“-D–*Bœ4F®BOÄVXÕdYÝn\æ€hè‰hìlî‘nèqìsêsê‹mî‹oêŠiè„iæxaâr\ÛbWÊVU°CK›,BŽ*D*@—2Gž6H¡:M¤@P¦=M¨BTªAO«DR¬GS¬CQ®GSªBR°DQ¬BQ«BO®DP±ER·HR´HR¶MV¸KT¼QY¾PWÂPVÂPZÁNTÀPUÂSWÆVUÌVZÈTVÇUVÊVUÈX[ËX\ÈZZÏXYÐYVÎWWÍW[Õf`é§~ÇPQ½MX¼SWÂPS¼OU¹MV¶KW»PW¼S]¾V]¼Y[¾ahÄfk¾[a¼`gÆhe¿_d¼]bÂgjÇlpÄjlÄopÆnp»jwÃkoÆuxÁmsÉppÄlsÂwzÃqxÀ{…˃„Åz|ȇʇɖ‘ÏŠÎŽŒÐŸš×¬™Ø ”Ö¨¡×°ŸÜ¨—Ú­¢Û³¤Ý¹¡Ý´£Û²§Üºªß¶¢Ýµ¨Þ¼±âÁ¯à·¢Þ¼¨Ü¼®Ûº¤Þ»©ß¼«Ü¾²Ü¾±Þ¶¢Ú´¨Ý¾µßƺҲ´¬~Œ©t¢Sbž<K¤@O«DQ´GR´O[·KV¸OX·JS¶JU²JX·HS³ETµJZ´DU¬DU¬BT¬CX¸KWÁN^Ñ^d×npßwsáznä|lå|lå‚sç€rã~oÞxpàwjÜxn×ohÕebÏbdÉ\`Å]dÈZ[Î\`Òbg×njÝrkÞzkÞvlßseÞpeÞn`ßrcâucâudàxjßwbÞl_ÜnbÜpbÜn^ÚodÜqfÛpfÜseÜtdÚshÜreÜtjÝzoÝtdÞvhÞxhàweàxjâzlã€pè€hØkb™7J`@X>V=V<Y=V:V9Y?aAg Ch!Cf?d<`=_:Z=X:^>dAgBdF\GZAYD]BfDh$Gr+Ng"EV:J5O;„:SËurîvìŒpê‡læ~fäq\Ù`TÃLN¦5G˜9M•2J“,D˜4H®CNÇUSÔdXÝq]æ{bèŠhëiìoìjì‘pënéŠrë‰kë‡iê„fæ|cát`ÚbUÉVR±@I›,DŽ*D*D˜1Fœ4F 3I¦@R§?L«GY¨@M¬>P¬@R¬@MªDR«CR­CO­DO®ER¯DO°FNµHPµJQ´LT³OTºMT¿NSÄSRÄT\ÀQTÁQVÃRVÆZ[ÄUVÆSVÄXZÈSXÊX\ÍVXËSVËWXÒ\\ÌYXÐTZßwpÜmUÁNUÂQP¾NSºIP¸JS·IP¸P]¿QV¾X`¾Y]¾T\Â]a¾X_¾ciÉbeÂ\aÀ_cÂflÂlnÂei¼hrÆchÌnnÍquÅpqÈprÃjl¿lxÃsz¾ekÇxzÌzÈ||Í~zÇ€|Í‘ˆË‚~Ëš’Ô¤”Ô™’Õ¦Ù­–تŸÚ©ŸÙ³ªÜ²œÚ¨Ú±¢Û¸¤á´œÛ°žÜ·¬ß¸§àºªÞ¸«Ý»°à¼§Þ¸¢Ö¶§Ø»¬Ú¸¥Ó¬¢Ñ°¯Ò½¼ØÅÇàÎÈæÔÍëÙÐæÛÐà×Ëξ¸«`hœ5H¦;M¬DQ±MZ¸IR±KW³LW³HP®DT±HTµGU±IV°FX«FXªBY³EV¸K\ÀS^ÒbdÖnmßsmá{på~nä€månæ€nâ~sá{nà|sÝxlØodÓd`Ì\_ÂV^¿PZÀTXÅT\Î`_ÖedÚpiÝulàxkßufßpdàrdßsgàrbâxgßvjßtdÞn^ÞneÝpcÝp`ÛpdÜpcÝrlÞrgÝrdÝqfÞreÞukÜqeÜrhÝuiàwiáxjâ{häoæoÞwh¸KPk@XAU@V?W=W<V:\>bDc?fBc@h@f<d:\>Y=^AeCe DfG]BXC\A\@`Dh!Fr2Sh$HS;J<N<y0Nºioà‰{êŒvê‡mèiäwdÜj\ÌVR´?G™.D˜3G›6I™1E/F¬AMÈTSÕbZßqbæ|cé…hëŽnìsì’pîpí‘uìnìŠhê†jè…dæ~dár]ÚfYÊTP°ENœ2F(D/F–2FŸ:L 5J¥?M§FT«H[¬BQ«@O«EQ«FQªBQ¬DT¬AP®FT°CO°DO°GR´GU·IPºNY»PX½TYÀU]ÁTWÂNTÀPRÂPV¿UXÀQXÊXYÈTUÆV]ÈV\ÉYZÎVZÊVXÌVXÒXXÒVXÒ\Väx^ÅUWÀSS¼LR¸JT·FO·LX¸KS»U_ÁW]¼X]½SX¼U\»PXÃbfÂZ\Âdl¾XbÀbgÅhm¾dlÃdh¿afÂgmËlnÁilÄnsÆln¾jrÉrpÂrxÂsxÇz|ÌzzÍywÍ€Ì|zË‹ˆÎ–Ò”ŽÒ—“׬–Ý©šØ¦›Ø´©Ý¶ Ü¬›×§œÛ·¢Ü±Û¨šÛ·§Üºªá·¦Ú®¤Ü¿³à¼¦Þ³¡Ú·©Ú·¨Ö­žÒ­©Ò¸¼ÚľäÎÃèÎÂêÐÃìÓÅìÓÇïÖÆòÝÏòàÑòàÉÒ´­ŸDV›4LŸ8J¨ER®FT®LV°HP®EP®CQ±CO°FU±GV¬FX¨FX©>T²GX³K\¼O`Ð_cØlhÞukâwlå{næ€pä~lç€pä|nãzkæ{lß|rÛriÕgbÌX^ÃPX´DN³JV¹IVÄTZÐ]^ØkjÛoiàwnàxnÞtißr`ÝrhàrcârdàteàsdÝpfÝn`ÝrhÞpcÜreÜpdÜodÞqfÝqeÝpdàobßtgßrbßvlàwkàwlãznâ~qæ€nä|gÂVVz'HXCU@X>X@V 8[AX<`@`>d@h@c=c<`8[:Z<]<d?jEb?_HVDX@^D^Bf$Kq.Py7Yf FO9Q@m'N¡YiÓ~täxë…fè†næycßn`Ô^W¿MO :K™.A˜2G˜3Hœ5Gž3H¬FRÉWTÖd^àtdå|fé‡gë‹iìlê‘nìŽnìpëŽmìŒjèŠmæ„læ|bàq]ÚaVÍRL°@K›5F*DŠ&B”2H4J¤8M¤<L§?Sª>Nª?P¬@O«?N­FR¬ER«@N®ER¯FR®DQ¯CO³ET³JPµLV¸MVºLSºNU¾QXÁRW¼PVÄPUÄV[ÄX\È[\ÊX_ÊVWÇ\bÊVZÆ\ZÈX^ÈTTËTWÐZ\ÐZ]ÔgbÐ[VÄQR¼KR¼HPºMXµKT¹NW½O[ÀT]À^^ºRX¼RX¼X_Æ]cÃ^dÃ\c½\d¿]bÂ^b¿em¼dl¼cjÀ[bÀjlÅdoÂlrÆhlÊqoÅjiÁisÃhlÂrv΂ÈllË|xÏ€}ËŠŠÎŒ‡É~‚ӟء֠”Ú°¢Þ²šÜ©žØ¦œÛ¶¨Û«šØ§œÙ²¨Ý¸¤Þ°žÝ´¤Û¸¬à¹¦Þ² Ù¯žÙ±£Øª›Ó°²Ô¿½àËÂåÏÃæÌÄè̾èÔÆæÎÅèÎÀçÑÆêÓÄîÖÆïÞÒôáÎïÚ¾»|’1Hš4K¡>M©CR¬GT®DQ®HV®CT¬FT¬FW­BS¬DT¥DV¤@V­DXµN\¾Q^Ï`cØgbÞsláwiå}nä~lä}kæ€kä}nå|nâ}qà|oÞrfÚg`ÌZY¼JP¬?J¤;M§;M³IXÅU^Óca×kmÞtpâxlàujàsdÝoaàpbào`àtcârdßpbÝpdÞncßqdÞodÞqhÞuiÝqgÜtiÜreÝrdÞrfàsbásháwháthâzlå€næzkÐ_Z.JZ>VET=X?X<\>^>`>c?f Da>e@f>b@]AX=Z=cBjBhC\AVAXBX=^B`Go-R|:[t5XdHW=o)K XhÅxzÛƒuä’wéˆvèhâtcÛdVÊQP­@K™.Fš0Hš4H™4Gš0Hž5H®CNÄTUÖd\àq`å|bê…fìŒkì’kênìqì‘rêjêtè‡pèƒkæz`Þm[ØaZÌOP³>Kœ0F+C+Fš2F 6I¤;L¨>Rª>L¬<O®GT­DT«DP­DP©CP«BP¬BN¬AO®DT®HQ²HS²ITµJRºNT¸OZÀOTÀNV¾RTÀRVÀPTÃRVÅSUÄXYÉVXÆTXÄZ`ÍWZÈWXÈTYÎYXÌXWÐ[\Ò\]Ñ]VÈQT»IN»LQ»NTºLU½NU¼T_¼U`ÀZbÀWa½RY¼[cÂ]`ÀX^¿[fÀ[^½Z`¾Z`¾_d¸T]Àcf¿`dÀhnÂckÆru¾bkÂlqÃbdÄnrÉhkÄlpÊrqÇprÉopÇimÐ~zÉzw͈„Ô•ˆÔ…Ó˜ŽÚ«—Ü® Ö¢œØ±žß³œÚª ×¬¢Þ¹«Þ­šÖ§žÚµ¨Ýº¢Û®™Ö§›Ò ˜Ò¨¡Ò´´ØÀ¼äÌÂçÏÂèÏĿɏåÌÀæÌ¿æÌºçÐÂçʼèͼéÒÃêÐÃîÙÉïÞÐðÞÈØÄ¸¤^l0Iš7J¢>N¨FS«BQ¬ES°ES­DP¦BS¨FVªDS¨BV£=U§BV´KZ»P\Î`dØjhÝrlâuhäzjåmä{iæ~lå|mâznä|oàzrÜskØljÏ_`¾NW¢8J•1H–2J¡6MºJXÊ[_ÒhiÜnjÝtkàvpßseÝrfàobâreàufár`ÝpbÛoaÝofÜrjÝpbÝndÞpfßqhÞvjÜrgÜshßshßsiâulâviãviåtæ€pÛmc¢<O`@T>T?U 8Z8Z8[;b>c>d@d@d@f=b>`@W<Y<b<i>i?`BU?ZBYB\AcFi(Or-Ts0Tn+P`?p&J›SdÀprÒ~wÙ‡vß‹uè|dãybßm^ÑZQ·EO 5J”.Dœ4K4I5H6J¢8H±DOÆTTÒbVßq_å|dè„fënì‘lì’lì‘pìŽnênëŒoéˆmédåz_àn[Ø`TÈMQ®MLž5J+E,F˜2HŸ6H¥8J¦?N§@N¬?QªBP¯@N¬BO¬CT¬@P®L[®HW«DR®FS®AN³HU²BO¶JRºNV¸OWÂQT¾TX¿QTÃQXÁRZÃVYÄSVÆX[ÊTXÊWVÆW]ÌVVÊZ[ÊVYÌ]XÌYYÏ[\ÖaXÉPRºHP¸MT¹IQ½KRºLT¼OTÂX`¿V`¾V`¹T`À]bÂ\cÀVZ¿Zb¿Zc¾]b·T^¿^]ºXb¼al¾`gÄfgÁgnÊjmÈlnÌroÈipÊvvÄcfÂprÇklÃqvÇrsÄjnËz|ÎvwÍ€Ò‹†Ï†…Õ™×›Ž×œŽÜ¯£ß®˜Ü©šÚ¬¡Þµ¦àº¥Ý°¤Ù²¦Ú´œÜ¦Ô¤–ΜšÏ¤¨Ñ²¶ÞÄ¿åÌÀæÎÂèʹæÌÀå˽äɾäÉ¿äÍÂäɼæÌºæÍÀäÅ»æÊµéÐÃéÓÈîÛÐïÛÍðßÄд­—BT”2F˜7LŸ<M¨>P¦>MªDR­@O¬@Q©DV©@Q¨AU¨?R­>T³KZ¿PYÍ]d×efÝnjàxläpä€mâ|kä{mãznã~pä|páxpÝqjÙleÍ_\¼NW™:J„%C€"AŒ(D¨@RÃTZÎceÕhiÛrlÞvjàujàtkàn`ârfàveàtiÞrgÛpdßqdÞrhÞn`ÝndÝrfàthàobÜpdÞqfÞsjàtjäxiâvmåylénßvi¹LPmCU=U9T :V 7[:]@b?d@f@fBc>f@c@`<X>W=_@d>iBbAZ=W@\?^B`Bg"Mq1Wv6[l)Pg%Jz1R˜Nc»mrÎxÏ}tÖ~uÕ†yèvaâr^ØaRÃLL¤7G›.Bœ6L¢5H¡:Lž9Jž1D¢;N®BLÅTVÔdXßo[ä{hçˆnëŽhîpìlìrëŽrëŒnêŽnêŠmè‚däzbàn[×bUÉTR°FMŸ6J‘-E2L˜3G:L¤8L¤:L¦<N©@Q®@M®CP®BN«BP¯FQ®JX°DQ°BQªAR®DQ²DN²HT¶JRµKR¼LS¾NUÀQTÁPQÆPOÅPUÇRTÃRVÄVZËVWÊUUÊVVËVWÊZ^ÌYXÌ\[ÌZ\Ð]YÇW\ºLT¸FP¶HR¸HNºPZ½RV¾T^¿X`¸MX½XaÂ`hÂY_¼X_¾[bÀZaºU\ºZa¼U]¸V^½^fÄbfÅghÄkoÄbbÆntÎttÆhnÌolËlnÇooÈilÄrvÉzyÇosÌwuÉkqÏ€|Ö†€Ò€€ÔŒƒÔ‘‹Ö˜‘Û£–ݪ™Øš”Ù®›Ýª“ܨšÚ¯ Þ·¢Ú­žÏŽ‡Ï–”Π¥Õ¸¹áÉÄäÌÃêÓÈèË»æÈ»åÃ®äÆµäɺå˾å̽ãǺäÈ»äÆ¹è̺æÏÂâÆ¹èʶéÓÇëÔÆîÛÎìÚÌêØ¿º”—”:N”-Fœ2F¡;L¢>O¥CU£@T§AS¦F[¢@R£?T¦:O©@T´IXÁPXÏ[_ÖfcÝokàznä~pä~mázmä|kä|lâ}oâ|qÞzsßqkÚlfÑbdºQWž7M~=q@x=ž4I·LWÊX\ÒfhØlmÞumàvmÞvgßriàocÞofáreßsiÜndÜmdßtlÝoeÞphÜpgàrhàpfÞnbÞodàpfäneæpfäxoê~lè|mÈc`†%@[:R 9U8X 6Y :Z:^=eBgCgChCdBgCaBY@T ;\Bd?hBa>\@Y@\B_Cf1Vh2Zm'Rr6Zp1Xn*Rx2T™Lc·lsÉ|xÐwÌzuÍzsÖ}râq^ÜfVÊTP°>Jœ2Iš2Eœ7K 8I¢8G¡4C2Dž7K®EOÃTVÖe[Ýscä{bæ†péŒnìŽlëoìŽqëŒlêqêqèŠkèeãy_Ýo\ÖbXÈRO°CMž5I‘,F’(C–2Gž3G¥:O¤;N§@P«;Q¬>M¬?R°FT«FR¯FS°HU­FU¯EO­CT°DO®ES¶KS¹KT¸LT¸KS»OVÁPVÀSUÄRUÁT[ÄQWÅVXÅW\ÈVVÌVXÊXXÍXXÈYYÈXXÍ\^Ò`\ÉRR»OXºJQ»JO¶LXºHP¼PUºS]ºNV½PXºU^ÆZ\ÁY_¹UZºQXÂ`g¼TX¼V`¶U_ºU`ÀW\ÃcgÅ^bÆgjÂ^gÂlpÊkmÊorËjiÇdjÌqsÊfjËnpÐtxÆmrÏrrËtvÎzÑwtÎ}wÒ†Ñ~|ד†Ø”†Õ“Ø£˜Þ©–Ù¡˜Ö¡”Ú³£Û¦ŽÒ•ŠÏ”’Ê•—Õ´´áÀ·æÍÄéÍÂèÌÁêʸåÈ¼ãÆºà¼áÅ´åʼãžãÈ»âÈ¿âÄ·âɼåǺèɹæÎ¼âƺå˹åÍÂêÐÃìßÒíÚÈäÓ»¸ˆ‹2G“0H›0FŸ9N <P£BS¢?T¢AT£@S BV¤>RªAS·GTÂPZÎZ\ØgdÜqnáznä~qå|lå~mç~kä{là|pâxnÜytßvkÚljÌaf¾V[ @R‚"Dh=p>Š$@¦;LÀQXÊ\aÖhgÜpiàuoàzoátjßpfàpfápdÞthÛqgÜogßpbÞqfÞpgÞqiÞrdàshÝn_àreàqfäqfæuiç{qé}jÜl_5FbAT8V?Y>Z;Z<`@dBjBgDdBfAf@`@\AU@Y>h Dj"Bd?\=X?YB^Aa#Je&Oh)Sl-Vt8az/Z~3Y–Pi³iuÈzxÍ~ЂzÈwsÇrqËulàfRÔ^N¼FJ¡7G˜2Hœ6HŸ8J¢6G¡:GŸ7E 6HŸ4E­EMÃQRÔ`ZÜq_äybèfêŠrëŽoënìŽnêpêŒlìŠnèŒlèƒbäycànZ×`UÊPL´DNž2G‘(B,E˜4Jœ;N¢<P¤?P¨ATª>Pª@S¬DV®GU©CN®HV±FPªDN­ER«CP­CR²HQ´IRºJP·JR¹LT»PUÀPSÀSUÂTXÃPTÄTXÇWVÈZ`ÈZZÉXZÈQTÌZ\ÈWZÉXYÐ^YÉXU¼JQ¶NX¸GN¼KQ¸OXµKWºQ[¾RY¶MZ¾[`Å\aÀRW»X_¸T_¼Z[¼W\²QZµQ^½Z`À^dÁ[\ÄdjÄc`¼X_ÇfjÆkoÇvsÆgfÂnpÍtrËlmÏrnÏqqÌuxÎvtÏrsÒ|xÏzzÌ|}ÌyvÏ|ÔŒ‰Ó†ˆÑ‰Ù¤–ܪ™ÚÙ¥–Û¬š×¡•Ì„~ƔϦ¯Ý¹±èȺæÈ¼ê˶åËÀãĵßļâ¼âȾäʸÞÀ¶æÈ´äÊÁâÈ¿ãǽáǺãµäȸàżãǹåÎÆãÐÇäÒÌèÔËíÝÑîßÔíØÂÜÆ¹¡[kŽ/E“1I—6Fš8Mœ7M>NCU¡?R¢@R <P¦?R®FU¼Q]Î]_×ddÛnláxoå~tå€tä€sæoå|jã{mãznà|sßxqÜolÓefÂV_¦AP„%Bd8^9y:˜1G³FSÃR[Ñ__ÚkhÞumÞuláwkàrcßpdàrfÞpeÜqfÛmcÞpgÞnhÞrjÜnfÞqnàrgÞpfÞuhàvpãwnçxnç~rÞscµBNk@VAb8\`0S^IZ<\=eCfAgAe@gBfBcB^@X@X>b@jBfB]AY>[@\?`=d$Lh%Nm+Vt4_u0\‚:`–Kh­fwÅvxÍ|zÐxÓƒwÂqn¾nl΂zØZNÈQN¬=H›1I›6I¡8L ?Nž8J¢:M5G9JŸ6G«>LÇTSÕ^XÞr`ã{gæ„hèŠrêŒpëoì’têŒnêŠlìŒnêŠgè…dåz`àlZÖ^SÈRR°@Hž6IŽ,G+F•8L›8L£<N¨?Q¨AQªAP©;N¬?L«DO¨@P­AM¯DQ«@P­@N¬BN®FS³HS´HN¶FQ¸IQ¸QY½PT¿PVÀSVÃRUÄRUÇTTÈUWÇUVÊTWÇ[\ÆVXÈWXÉYYÌZ^Î[S»MR¸JQºJO¹KR½MWÀRZ¼QZ¼PZ¼NX¾W_ÃW\¾V^½W`½V\¾U\·V^µN\¬M\µTb¿]eÆbcÂehÂaf¾ekÂhmÄhmËwtÌmnÌsrÌvrÆptÐwsËnpÎxxÔvuÏwvÐtkÈruÊsrÎqsÎvvÏ{vÓÖ’†ÛžŒÙ™‹Ú¡”Ü©—Õ–ŒÏŠƒÈƒ„Çž¦Ü¾¸âĸãĹæÀ±çŴ俵âÂ´ÞÆÁäÌÃæÐÄäȺâĺâIJ῰åïáĹâ¶àÁ·ßĻ߯ÂâÏÇäÎÄéÒÂèÐÊéÓÄêÔÈìÜÒïàÔìÜÒìÛÀͳ­—ASŠ-CŽ1G“0F˜6J–9L™8Mš;Pž;P¡<P¥@S®GXÃQ]Î]_×ihÞqlázmç~mæ€qä|lå}oå|lã}mã|qà|vàskÚppÑglÂZc¨BT‚$Ab9W;fB†,H¢DUµKVÈX`ÕgbÝojàtláwpàthÞpgàsjÞpgÝndÞqfÞocßncàrjÝohàrcàrjàqeâpdâulæukê}pærÍZV€ @Y@V@V;Z>Y;\>a<c>h>hAd>gBfA_>Z>X?a?n Bm$E]=Z@]D^D_@^Ab"Gh*Xl.Yv7b:_”Jg«at¼t|ÊywË~{ÐxÎ|xÀon΀wÔ‹ÌRP³DHŸ2F›2Fš7H¤>N¢>L£:I¢8H:Hž2Dž4H®AMÃQQÔc^Ýq\âxbæ€fåŠfëŒnì’sêqêŽsêuínêˆlçƒjä|dÜn`Õ`TÇOMµ@HŸ3GŽ+FŒ1J4O˜<P¢BR©AR§BP¯FS«AUªBN®BN¬AS¯DM®DSªCR±FR­CO®BQ³JT²HN·GN¸JP»MP¾QYÂPT¾RYÂUWÄRQÆTSÄUXÁTYÆVXÆV^ÈZ`ÎZ[ÍZZË]_¿TX¼TT¶KR·HQ¾NSÁSZºPZ·LW¼T`½R_¾W^»T^¼V]ÂTV¶JT´S\°HY³P\¹Ta¼Zc¼V_ÊehÂblÁfnÆabÇghÌlhËijÌrqÍgjÈtwÎvsÒrsÑwrÒ{zÎzvÍnlÀhoÎwtÈlmÍyyÓyvÏ{zׄ׈֒‡Ú©šÖ”„ÑŽ€Å€}½ŠÐ¤¨âÁ²åÇ¼æÆ¶åȹâ÷ửâÄ¸áÆ¿æË¼æÌÁæÅµãǽâÀ²ÞÁ¶Ý»²Ú¶¬Þ¼®àƾàùäʽèÒÆéÔÄçÎÂèɹåÌÀäɼå̾èÒÃêÔÅîÝÍîÚÆïÚÁ¸…†“@M†0F…,D3G3H˜7Kš8Lž7Kž6O¦?O¬HXÃRXÑ^[ØifÞphâxnå}pæ~pã}lä~täziâ~sâ€vá|rÞvnÚphÒb`ÀVZ¥<J‡%B_ 6P8`@v$F˜<U®GWÄV^Ñc`ÚjgÞpkávlávmàujàpeÞphÞldÞqfÞlbÞpißphßndÞqhàpjàqhâseåthèxiê|mÛmb£7F^;R:R :W?X<]@bAh@fAg@g?j!De@`:X<R 9^;fBpBfBV<[@^>aC_AaBfLi&Tr5b~8b•Pn¨bwÀv}É~|ÈÌzwÎ|sÂqrÊ{qÔ‹|Ø{¹CK¤9I™3Fš5N 6G¢:L¡:K¤;K¦9Lž6Fœ1DŸ8J¯=IÃPTÔbYÝnZâw`æƒièˆjéŒvêpësêuêŒrê‹nê‹uè‚lã~iÞn^Ôe`ÆRR²LT 2F)E4I–5K;O¤<M¨BQ¦?M«DP¬ET¨?O®AP¯AM¬@L®CQ®DP°BN¬HQ­FN²FS¯FM¶ER¸JRºPT¾OTÂQRÆX]ÂUWÀRTÃSVÉQVÆVXÈVXÈVZÈW\ÆZaÍbaÆYZ¼X_¼Q\¶PZ½U]¸IU¼RZ½NZºNX¼R\¾S\ÁX\¾U^¾SU¼OZ¹RV¶Xd¶V\¸Zg¿X\¼\iÂ`b¿\dÅklÁ_f¿hlÈeaÅotÊlhÄbdÊrsÎolÌtrÓtnÒyvÓzvÉloÄrxÊssÊosÌrrÐtwÏyyÖ‚{Ò€ƒÔ”ˆÚžŒÕ‘€ÈxzÀt|•ŸÙ¬£âøã¶ä´âµã÷ã¸àûäôæÉ»à½²åıßÀ¸à¸«Ý¼³Þ¼²áÈÀݸáúçʹäĸäÂ°åÆ±âÁ²à²ÝÅÀ߯ºàÊÂàÉ¿âÎÀäÐÆåÐÅèÔÈîÚÈÜÎŶŸª™`tŽ>O‰,B‹.BŽ0B™2Fž:G›4K¤:N®DQ¿RZÏ]^Øhbßoiâxkå}så~mä}qå~räylâ{pã~ràynßwnÞphÓdaÄY_¥<K†">c9UBWFg Gˆ3M¢BTºIUÊ\\ÖbbÚmhßtnâtnáufârbßnbÜndÝmbÜmfÞmeÝoiÞrlßqjãrhásjäxjèylêzläti¾NPq>Z?Q
+9V 8W;W=`BfDjEj"DfAe@dBb;^<Z<[?iBnBiA[=X=aE`BbDd Fj*Qf&Qg"Nu3]IjªdtºryÊ{|Ë~{Î{ÂxvÂutÊ~uЈyÖŽ}×’¨;Lš2F›6J›6J¡7H¤;K¢>P¤:G¢;N 9L 4Hž4G°DPÁOSÔ^UÚmZâyhæ‚féˆhë‹mêŽpéŒréŽtéŒrëˆlé†lç„käydÜj[Ö^VÄTS²DL7K*CŽ+B”+Eœ9L¡;Q¥@P©?R«BR©CRªBQ­DUª@O¬CNª@O¬BO°DO±AO³FPµFR±JO´JQµJS¹MU¾OZÅRVÄTYÀSUÃSVÄNQÆT[ÇVWÍXXÊV]ÊWYÌ_aÔe^ÂQV½NT¼LVÀQW¾TZ¼PV¸OWºLT¸RX½QW¾T[¸V^ÃT\ºOV¼Yc¾Xc½\d¾X`¼WdºZbÀYaÆeiÆfhÁbhÃjnÅ`fÀlrÎtrÇkoÌtrÌfmÂnsÒurÊjjÑvmÎnnÇsrÍnlÉinÎrrÐpmÎ|zÐxtÎvwÓƒÙ–‰ÔŠ|Ãpp·o~Ì¥¨ß²¢à»±å¹¦âÄ·àÀ¹ß¹«ãƺæÉ¼åȾ᾵⺬ßĻܾ»Û´¬Ú¿¼à¸¦ßøæÊºãŶིྶ޼±ÜÁºÞúàúà¸äÊ»ãÌÄäËÂåÎÂãÎÀæÎÀæÎÄèÒÅìÖÉðÚËîÞËÖÎÀ¬„“…4F‡-F‰)A’0F•3H–3H£:L®BOÁOZÐ\^ÖicÝolÞwkäpå~pã|lætä~lâ|nãzrß}vßztÜqlÔdaÃVX¥>M‡&Af:X=X@`<p82Hª?LÀTZÏ[]ÖgeÞoiâvlãtgâseàqdÞqdÞmcÜmfÞkaßnfßphàriárjátkæxlêzlèxhÑ^Z‰*FZ;S:T ;V ;W:\@gAl"HjDhAhBg>f?]<Z:W>d>qCjC`@W@[BbB`CcD`Ie"Jh$Rl(Sƒ;_¦[n¾rzÅzzÊ{z΀|΀vÁvxÅ|zÓŒ}Õ”€Õ}דš:N—4H7J <J¢8J£9J¢7H¢8J¤<Nž8NŸ5GŸ6H¬?MÂPOÐ^XÛpbâu`ç„jè†nëŒpèŽjéŒvèzèŒsìŒtèŠrè…mäzbÞpaÕbYÉRSµBMž5F’+C,D—0C7H¢9J¦=N¨@Q¨@R¬GS­CP«BN©DP¯EO­@M¬FP®AO°HV®IQ°DP²HN¹HO¸MS¼JS½MSÀPWÀTVÁRUÁSVÆV\ÆTVÆTZÇX[ÈTUÉW\×i`Í_\¼HT¼IR¼HR¼KTÁTZÂPT¸N\¸NU·NX¼NV¼QZ¼TZÁV\ºNX¿Xb¿W\ÄXZ¹XbÀX\»_hÃdmÆbcÁfnÆba¾`jÉnuÉfkÍorÐppÉfkÊnpÐpoÊt{ÏrpÍptÌllÌnmÀirÇlkÄlsÈrtÌoqÊxyÐ~{ÓŒˆÐ€{ÄimŒױ§á½®Ýµ¬â´ Ûº¶ß¶¨äƶ࿴弧æÄµå´àÀ¶Üº´à¼¯â¹ݼ´ãǶܶ¬Ý¼²Ý»±à¿­ßÄÀàļàļãŹæÈ»äƼâǼâȾäʾäËÄäʽäÍÂåÌÂçÍÂçÒÆèÔÈêÕÉñÚÈòÞÈàÖıŒ•¢FP$@‹)D/F”2Gž6K®BO¾MTÎX\×hdÞrkàznã~på~pã|nå~sã{mäykâ~sâu߃ÜlgÒdfÁRX¨@L‹'Dj<Z>U:W 9f9~;™4J²FVÈV]Óa`Úgeàthâtgàteârfán_ÝlbÛlbÞqgàpgàndáqiãtläulçxmê{kÝj`¦8Ib5T 8T 8T9Y<\<^<h@i@jDl HgBfBfA\?V;`?kDlA`>^?\D\=fFbCc I`Lb!Nm$R{9^Ri¼nxÆwxÆy|ÈxvÎyÈzxÄxzщ~×~Ö“€Ö‘€Ø‘~˜<Nš7Kž9L£<I¤<K¤:K¢<M£=K :L¡9Jœ6K 9L¬ANÁNMÐb\Úpbâvdæ‚jèˆpêrèŽxèŽté‘zéwêŒrèˆsèƒiäzdÜo`Õ_XÇTV´FN <O‘*DŽ(B–0FŸ2F£:K¦=M§<K®BP©@N®@N¬BS¬CQ­FR¬BO«DP­FQ±EO­@I±FR´EJ¸JN»LRÀLQÀNSÂTVÂTWÀVXÂWXÈTVÂVXÂUXÅUXÆWZÎd^ÔcYÁRU¸LT·PW²EQ·LW¿OTÃRW¼OXºRXºNV¾QU¶R\¼NW¸PY»TZ»U`¼RZÁWZ¿Yb½^fÈfgËhlÈgjÃ^dÅlsÍpoÌmpÐwwÐsrÈhqÏzwÏjlÌnnÌonÈkrÏpoÈfhÆlpÊhjÂbmÌrsÌprÌtnÇnnÀkqÄrp¿nxÉ’‘ܱ¨âº©â½®ß¼¬Ú¶²ã¼£Û½´à² á¸§Üº°ß·©Þ¹¬Þ»´Þ¼°ÞÀ¶äÁ®ß¼µßµ«Ü¾ºàÄ´âÈÁß¼±æÄ®åÌÃåǸáÈ¾äÆ»ãȾäʼãÊÁâȼäʺãÊÀäÌ»è̽åŰçϾèÏÀçÏÀêμíÔÃðàÊâÖ³}†}%A"=ˆ'@.Cœ6L¨?O½MVÌ`aÕfdÜocàxsä€rã}sä|oæ~pâzpâ|räzrå€pÞxrÞldÔb_ÀRWª@LŒ'Dl:^=W:W 4`;m:Ž)C¨<LºGSÌ`aØdcÞohàuiâtgàtfÝqeÜm`ÜlaÞkbàndßriâtjátkäyné|räsd¾PTr;Z>T:V<V<Z>`Af@j Bh@i@h=fBeDa<[@_AgAjBf H\>\>c"Gb@cBaD`I]Hb Nv3\˜Vn´lxÅyÇwxÃw|ÊzwÆxxÁxzÎ…~Ó}Ö”‚Ö”€×’ÕŽ}š4Jœ8H¡:L£<M£<N¤<K¢<K¡?JŸ<Jž;Pž6J >P¬BNÁUYÕaZÜo`âuaç‚næ†oè‰pèŽréŒuêŒvêŠrèŠpé‡oè‚jæzeÞpbØbXÅRT¯BM <R’*DŽ,H–/Fš8K <M¤?N¥?L¦AM¨>Q«>M®FU®IV´BL¯@M®BP¬BO®EM­DQ²DQ³EL·IPºLS·JQ½NV¿PVÂRXÂTWÄVZÆXYÁVY½RXÄPUÅ\_ÝŠuÊSTºHM±BP°EP®EP¶EPºNRÂRX¾V[¿RX¹KT¿SU¾OX¾TX¾U^»PV¹R\¼X_¸Vb¾X`Ã`_ÆhkÈadÁfrÈrrÎijÏuvÒwuÎnoÇrvÌljÌnpÏvwÌqyÅntÎurÉflÉmrÇlrÈlmÉhhÆmrËrlÆkn¼em½js¿|ˆÑš”ܦ–ᶡඦ࿴࿰ྰ߯¢ß¸¥Ü¸²Û±¦Þ¶£Ü¸°Ú´²àº®àº­Þ´§Ý¶²àÀµâÅ¾çÆ·á¾¶èÆ±äɾ߽¹èƲäÈÁåÊ¿ãÈ¾ãÆºâȼåʾáøãŸãÊ»ä̾ãʾâȼæÎ¾æÒÈäÏÄåÑÃæÎÁê×ÊðؼÜξ›Vjv:~"@Œ)A˜4H§>K»NVÎZYÓd`Ûngàyoãzlä~på|oäzmæ}päzrã|oã~uãwnÞnkÒdcÄTZªBNŒ-Hj<\8[9X6X5b 5v6+E°>JÆWZÒ][ÚfcÞnfàriàteÞndÝk_Ük`ÜjbßjaàtjárhãtlæznèygÑc\Œ(F^;V<V;\=Z>^<d=i>i>h@f@eBh"DcA^@[?dAh Fc<\;V:^?`Bc?h$IZB]H\Mp(T”NjµlxÇ{|Ê|ÆxvÃxyÂquÀsvÇ~xÒŠÖ”Ö”‚Õ“‚Õ’Ô~›6Kœ4J¡:K¢>P¢<L£;Kž>N¢@N¤=K :Lž:N ;L¬GSÀQWÒc\ÛlZávbä‚må†nè‹pæŠpæˆrèŠtéŽsè†hçŠrç„jå{fßp_×f`ÄRS°DOœ6L‘,G,F–/Fš5K¤:N¥<Nª>K¨<O«?L¬?L­CR¬FU®CPªDT¬@L¬@M¬BN®DO±FN´FN¶HPºKR»MT½PW¿MVÁPVÀV[ÂQVÄQU¿QUÀNVÂNWÞ„pèmÆNR´AMµDP·IU´DO·JQºNZ½MR½QY¾PT¼MT¼OU»QX¼QVºMW¶P\¹PZ¼W`Ä[^¿^hÄZ\Ã\fÄmuÌjmÇ`jËsrÒssÍsuÌrnÆ\`ÄnsÎqnÐptÌyzÏnqÐqsÊrrÂenÂioÀ^hºbnÅllº`j¾blºdrÍ•’Û²§Ú¨™Ú¢˜Þ­œá»°æ¼¤à¼¯Þ´¤Þº©Ý±¥ß¸¦Ø´²Ù°¨àº¦Ü³§Ú¦šÚ²ªÚ·²âÀ±âļåÄ·äÄºáÆ¼á¼´çÆ·ãÉÁÞÀ»æÆ²âõãÇ¿áÄ·ãʼå;ãȺæÈ¸åʼãÊ»äɼàÈÂáÆ¸çÒÅçÐÅèÑÃèÕÆéÚÒéÒÄîØ¸É®¨~*D~ ?‡#B”/D¤;H¹HRÌ[ZÔd]Üofàvlå{næ}nä}lä~oä~tä{rá}rá|wàvpÜomÓbdÄXY¨FRŠ,En=]<^<]>Z7[ 7f5~>›2F²DNËUSÖ`ZÚh`ÜobÞviÜraÞk^Ýj\Ük`àlbßreärhåwpæzmÜma¥>Ib:X>X<X=Z<X>`;iAj>hAgBi!EhAdC`@Z?^>gBfD`CY>^@dAfB`>_AVA_Kj%R…?a¬cwÇy}Î}È{|Ãrt»nv¿psÉ€ÒŒ}Ò€Ô’Õ‘~Õ”‚Ö“~Ö‘ <Jž8I¡:L£?L¢;L£>L¢9J 7I¢:JŸ9Jž7L 4F«CPÂSXÑ`WÜnbâzeå‚mä‡pç‹oêŽoèŠsè‹qè‰té‹tçŠræˆoå|iÝpcÔcbÆRS³EP<SŒ,I,G•3Jš5J¡8K£<L¢<LªAN¨DR«BO¬BP­CR«CN®FP¬CP®AO°BN®EM²DP¸FMµGO¶KR¹NSÀSYÃQTÄSX½RXÀPNÂTVÂORºPVÀTZê©„æƒbÂEL±=JºDN·KT³HV´NZºRZµLT»R[ºLVÁOT¾NWÀPXºMX¾T^¼U]ÄX^ÂV`Ã`fÆ^d¼YcÈbbÌ]cËjqÌjpÑotÒztÍgh¿ajÂlrÏleÅioÔurÌjsÍorÍloÃchÃmn¾`j¾`fÁ`bº`j´\f¿t~Ó–Ý ‹â¸§Ý¬¢Þ®žß°¤å´›à²¤ß¶ŸÜ±¦ß¶¨Þº«Ù­¬Þ¸ŸÛ²¨Ú¨›×°®Ù´¯à½±à¿µà½¶ä³âÄ»äÄ¹äÆºáÇÀãÀ±åÎÁàÃÀ⽫áÉÃåÉ¹áÆ½äȺäʼáǺáÈÀâȽßÄ·àĸÞĺÞĶàÊÂäÏÂæÔÈçÑÅéÚÎìÚÏëÞÊãÑ¿£ft˜;J„ BŽ*Bž8HµFOÊUVÔbZÝnfàvjä|lä~oã|mä€qä~qãztä~tàznßxoÜlgÓcdÇTV«CR+Er>^;\>^9\7[
+6^ 4m5‡"=Ÿ8F»IOÊVUÒ`XÕj`ÚqbÛpbÚj[Üj\Üh[ßn`ÞqdâtjåwlàvkÃRTt=V<V9U<Y=[=`Ed<j?f>h<gBfAf@cCZ>^BcBiDcBZA^DaCjBiF`@X@R=`Iƒ<d§`wÄy€Ð€€Ì}|ÈxzÁrqºnsÇ~|͆}ÔŒ{ÕÔ|ÖŽ|Ô~Ô“‚Ö‘}Ÿ>P¡<J¡:H¤<J¡<M 8L ;L¢>M¡<Jž6Hœ7Kœ7K§APÀOTÒaZÜpeâweå‚lç†néŠnæŒqèŽoêoéˆpéˆsé‹xçˆuä|iÞrdÔe`ÈVT²EQœ5MŽ,HŒ-K–1J˜7Mž4F¥;L¥<Lª?MªAO«AL¬BO¬FSªDS®FT°FS¬DQ®DO­DV²FR´LX¸NV¹NU¼KR¾PTÂMU½OVÀSX¼T\ºPX¸JU´K\Îmdô»ŠÚuY¸BK¯BL·EO´HU¯KW¶KV·JV¼LT¼NXºKU½PU¾RW¾PWÅZ\ÂZ^ÄVZÄY_ÃZ^ÀZbÅdeÇ^d¿alÇhlÍopÒppÓwnÈbcÃhpÆjiÈilÃhsÎtmÎjoÎqrÐmjÅflÆehÂahÄde¹Q`®Pd³ViÁ„ŽÖžšÝ™†Ü¯¤â°›àÀµà°¢á³¢Ü¦šÞ®—ܯ§ß¹£Ü¹¬Þ´¢Ý¯œÕ šÚ¶¬Ü¸µá»ªß¾·Ü¶¯à½­ãÀ³ß»°ãÁ±áżáÅ¼ãÆ´ßÀ»ä°ãÊÁÞÁ»äIJáŽáŸßżâĵàµàÀ¹ÞµÜÊÄÝÇÀáÊÀàǺåÌ»äÎÆæÒÆçÓÈèÔÄëÜÒîßÏëáÊÑĺžXft=Š'Cš2H¯HRÈZ^Ôd`Úmfßugãzlä|näzmä~rå}nâ~wä|rá|tÞxpÜniÔb`ÄSZ©DT.Jr?b>`<_:`:\ 5\ 5] 5l5‡$> :G³HNÂVXÌvyÒ“ÖŸ Ö£¤ÐŠÙi`ÛndÜ„}ãzjäwfÐcZŽ'D[=YAW;[@Z;`Bb@h?j$Ig?f=iEhDdB_C^Bd>fDeE\?\BbBhBi!Cb>X=P 9T@r*S›Ut¿t|Ñ}~Î}~Äx{Ápw¿prÈzuшÓŒ}Ռ֑|Ô‚ÔŽ|ÔŽ€ÕŽ|ÕŒ|¢<L¢@P ;L¢:H <Nž>O¢=J =Ož:Mž:Lš0Fœ4G§>P¿MPÒd_Üpdáxcähç‡nëŠmêŒrê‹oé‹séŠsêŠoéŠvçŠtä}iÞr`Ôc\ÇSV²FTš4N.JŽ+G”2Lœ6L¡7K¦>N¨>N¨:L©>K¬<J¬BP¬AO±FR°IV«BQ­DQ®ET¯GX²MZ²LY¶GQºLS¸PW½KRÁQZÂRVÀRV½LR¼LT¹IX¹Q]誊õ¯Íb`°?R²IU®HY²FSµFV¹GOºNWºHU¼PWºNTÀPTÂOR¾PUÅSVÄV]ÅYaÂR[¿[bÌaaÆ^gÄblÉioÊinÒsqÐhgÄfnÊklÌihÄhrÉnkÍlhÆlvÍruÍpuÅmrÈbg¶^lÂce²P`ªOd´`p̘”ݦ™Ü¨Ûª á¯•⯣㷜ޱ¨Þ¦œÛ¯¡Û¨œß¶žÝ°¤Þ¬™Ô ™Ó££Ü´¨à¾´ä¿²Þ¸²á¾®Þ¾¶Û·°à¶¦ß¿¸ÞÀ¸äĶãǾâÇ»âöÝÀ¸âÆ¹âÆ»àÄ»åÆ¶àÆºÞÁ¶Øµ¯ÚÀ·ßÄ½àÆ¼äÌ»äÎÁàÊÃâǸàɾâÍÄåÎÁäÐÅåÐÇêÖÆéÜÓîàÐîßÄ˰¬}"B~ C’0IªFTÈXXÐccÚldßxoäyhâxläyjâ}pà|qã{qä~tã}sà~wÜplÓ``ÄX[¨FUˆ+FpD`;]>a:_:[7\6X 5Z
+0g7+D¤UkÉ ¤àÀ¶æÏÄëÔÄîÒºàÄ´Ô žÜ¯²ã÷┌Ömd¢8Hb?V>U<Z>ZC]@^>fBh@g@gBdBg!Fi"Jf I^DcCf@b@^>ZAaDhEgAd?`=Y@T@h"LIj·n|Ì~|ÐzÈvvÄpt¼pxÄvvÌ„~ÔŒ„ÔŒyÕŽ~ÔŽ„ÓŒ}ÖŠzÔŠzÔŠ~ÖŒ{ž<NžAQ 9Kž:JŸ:Kœ8Mœ5G 9Jœ4Gœ4F3D3G§>M½OTÓ_ZÚnaàygæjç†oè‹nèŽsèˆpç‹sèˆoéˆqè‰tèˆräzcßpdØe`Æ\\²KVž8L,I-H˜0Hš2E¡:J¢<M¨<K§;K§>L°@L«BN¬CP¨@P«BP©BQ©>NªEV¯GX°N\³IT¸KS¸IP¸LS½JR¾OW¼NT¿NTÀLP¼KT¶FVÈ_^úÅ‘ïžwÏYW®>R²GT³HV±ER´GR¸HRºMX¹NXÀPX¾PX¾LSºJUµGV¹NZÄX^¾T_Å[_È\aÄ_cÍfaÊafËhlËfhÄejÉnnÍvsÐpoÉlkÎjeÇdkÅlpÏljÑqnÆ`c·P[º`j¿\b´Ve¯Pc¼u„Ô‘ÛŽÝ«¢Þ²¦àµ¢ß¤–⬔ڣœß«•ݳ©Ý³©Ü¹­Ù¡–וŒÖ—د¨ß² ßµ¬â·¦âº°à¾²Þº¶â»¬ßÁºÛ¸±â¼®âÁ¸ã¼¯ãƸà»ß¼ÞÀ¸ßÄ¿àÀ´à·޼´Ü½·ÞƹÝÇÁà¶áõáǼàÈ¿ãÈ»âÏÃàÊÂà²âÌ¿âÌÅå̾åÒÆæÓÇêÝÐìàÑï߯äÓ»CZy>‘2H­AQÄWXÔf`ÝndÝvpâyjâyjá{jä|nã|qä|mä}näxmá|tÞokÔcaÂZ_ªBPŠ0Jp?a<Z<_=\8Z:T
+2O 4N 8\Bœj~ؾºèÐÁîØÃìѹâÀªÞ»¯ÞºåÍÂíÑÂîÕÂæÖÀÄ–lBVARAVAX?\F[>cBi!DfAgBe?hBeDf$HbB^@fDdE^?_?^Ad@h Eb@\<V:\Fk$P‹Af²gzÈz~Ï~zÎzxÆvxÀpvÃxz΂Ò‰€Õ‚Ô~ÔŽ}ÓŠ~ÔŒ|ÓŠ~ÒyÒ‰zÖ‹{˜8J™<Lž:Jœ<Lž:Kœ;Lž9JŸ<J =Mœ9I›2Fš4F£>LºMPÏ\TØnháwhå€jçˆpéŒtèrçŠqé‹uç‹vç‰wç‰ré†mäzeào]×dXÈSS²CQ™9Nˆ$B‰(F–.G˜2H 7JŸ6K 8I¦;M§<L¨>Oª<M¨?O¦AM¤@R§>L¨DW©BS«DR¯HR°DP´HR¶GT¸LT¸LT½NU¼LT¼OTºJP¶BP°BXÛ“€ûÈ’é‹cÀPV¯>P²HX´ER´BRµJT¸JV¼LVÁRVÈTX»KVÁNVÀPX»MX¼R\¿X\ÂS\¿P_ÉaeÊajÈclÍhhÐnrÎknËgiÊdkÑssÌjiÇZ^ÃfnÎjhÐopÎkfÄ[^°Ub´\f»W]²Sc±\nÆz‚Ù›Ú¡–Ø™–୕㺪ᰜۨšÚš‹ØŽØ¢˜Þ±£Þ¸«Üª˜ÒžŸ×¨ Ü´¬à­™Ü²ªß²¢Ýº°à¸ªà»°âÀ³Þµ­á¼©ß½´àº®à¼«Ý¼´Þº¯â÷àļܽµÞ¼°Ù¹²Ø¼·àǽáǾãóæÊÀßȽ޽´áøàȼàÉÀâʾáÍÃÞÈÂáÊ¿äÍÂáËÄäÎÂåÐÄçÓÈìÞÔìÜÎêÛÀ²ˆx@Œ*C¥?NÂRVÑcaÚlißwnâzmâ{lå~lå~nã~lä~nä~qá|rà{sÝpnÑcb¾VZ¬ITŒ/Jn>\?\<\<W8U 8P 6L?XEŸ|ÝɼíÔÂìÒºæÀ¨Û²¥×¼¸àÊÃåÎÆìÖÈìØÏíÙÌîÓ¹Üijj,LLARDTBVB\C]AfAi"EfDbBh&Lg F`BbBbBcDfDdE_B]?`Dj"Fl(JaAW<P<^B~5Z¦_xÅxÏ€Ï~yÆv|ÂtzÃtv΂€Ò‰~Ô‘‚Ô•€Õ‹}ÕŒ~Ô}ÔŒ~Ó‰~Ò‰{Ô‰{ÔŠ{œCV›:Kœ:L;L8I6I¢6G 9H¤8Fž6H2Dœ4H¦:I½JOÒ`XÙh`âxfælæˆné‹téŠnê‹nè‹pæ‰xé‰mætè‡näzdàp`Öe\ÃTV®CRš/H†&BŽ)E“/H–3Jœ2Jž8J¢;L¦<O§<N¬AN§@N¨>L¨@L¨?N¦<Lª@P¬CO«DN¯HV±GV²HW´IR´HS·HQ¼NX¸KR»NR»FN°CV¸NYñ¼—ù¸~ã}eÄRV²BT¯@P´BO¸HR¸HU½KT¶M[½LQ½RXÂPTÀPYÆRVÀS\ÀU[ÂX^½YdÂZ\Æ]eËdcÌegÊ`dÏnmÐghÇclÇmkÉ\`Â]dÈjkÎljÐolÍhe¾[cµ]e¹X\­GXªI^¹j|ÏŒ‹Ø‘‹Ø–Þ¬ŸÞ¬žß¡Œà±£ÚœÙ¡”ؤšÖ ™Ú¤’Ù¢‘טפ¡Ý³¥ß²§ß®™Û®¦Ü¨˜Þ³¥ß¹¬àº°Þ¶¨à¸ªÝ»²Þ³ªâ¾¬Ú¸³Ü¸®à»°Ü¾¶Þ¼´ßº¬Ö´¯Øº¶Ý¾¹àÁ¸ãƺâȺáÄ»ä´âʾàǽÞÀ»áÄ´àȾßÊÃáȽâËÂàËÃßÈ¿ãÊ»áÌÄä;äÐÄêÖÊìßÒêßÊμ·…4N‡(C 9L¾OTÐ`\ÚjaÝtmßxlá|nå|læ~nå{jã{oåqâ|rß{rÛqjÔdb½RV§BNˆ(Dm=\;W9X8R 4M8J<f4Y°™¨à̽íÙÄèȰۮ˜Ö·±àÉÂåÑÈìÚÎïÞÐòßÎõâÑôäÕðàÐèÝÂi‚HBNBSAYBXAbBg"Hi@c?dAi Ff EbCbDaBb?f@a@[BaBbBh@dCaAV@V>p#NœQm¼t€Ï€„Ï}}ÊwyÇtwÄtxÈ~€Óˆ~Õ„Ö‘Ô’ÕŒ}Ñ€ÒŠ~Ô‹~ÓŠzÓˆ{ÔŒ|Ô‰xœ6I™:OŸ8Iž:L =M¤=L¢<L£>N¦=J ;Mž9KŸ1Fª<L½PTÎ`Z×j_àubäjè†méŒtêpëŒrêŠqêŠsê‰rèŠrç„læ|fÜqbÒ_XÇVU°BJ—.J‡&DŒ&E+E’0Gš4I :L¢:M¨=L¨BP­?J®@L®?M®BNª@RªAN¬CR¬@P­AP±FT°GS¶FR¸HRµJR¿KR¿NU»PUºJP¸KU²?UÈf^ûΚô©vænÊXY°DT®BR±HU²FV¸LU¾NV¶FS¶PWÂSZÄLPÂR\ÀQXÄWY¼SaÄ[_ÂR\ÄaiË`bÉ^dÎhiÎa]Æ\bÄhlÈc^¶O]¹`lÏmiÎiiÐkhÊbcÂZ_Æhg¿S\²L\®M^ÂnwØ“‡Ù›–Ûž•ޤ㯜ܗˆØ‰ÜžØ¢Öž˜Ø¤Ù«œÖ’‰Ñ“‘ל—Þ®›Ü¬¢à°žÙª Ý°žÜ´©Ú®¤ß¸¬à¸ªÜ´©Ý¼µà¸¬Üº±Ý²«ßº¬Ú´°Ü·¬Ú²£Ù°«×´²Ý¿¸âÅ¿âÁ¹à¹âÂ¸ãÆ»âźßÀ¸á¾¯âÇµßÆ»Ý¼²àÄ´àǼÞÈÀáȺßÈ¼ßÆ¼ÝúߟàÇ¿âËÄäÓÌêÜÒëÞÐáת‚‹‚&Cš4G½NQÒ^XØnhÚ|qßznâ~lä|hãnãpã~lä|mâ}qÞ|rÛskÑc_¾RT¤CMŠ,Eg:V:R9O8I9K?{Mm¬²æÏ¿ë־⼥ћ‘Òº¹åÏÂëÕÈìÙÉïÜÊïÛÊïÙÉòÚÌôßÍøæÒóæÌŬ­LFNDP@U@Y?^?bBfDgCiBh>`@^>^>b@c@bAX>[AcBh DfAfD[@ZAj$ODeµj|̃ӀyÍ||ÅuzÂvxÈ||І€Õ‹~ÔÖŽ€ÕŽÓŠ€ÕŽ|Ô‹‚ÒŒ€Ò‹~ÒŒ|Òˆ{Ò‰{Ÿ:Lœ:KŸ;K ;J£;G¢<L£<K¨>Q©?L¤8G ;K¡5F§?JÀOPÑ\XÚiXáveäfèˆréŠpêŽuêtéŽrépéŠqèˆpç„mæ~gÝpcØbYÊQQ­=I—2E‡&D‡'C(B’,Cš3G¡;L¦AL¦:Jª@M®@M«BP­BM­DR­BP°@M²@L®CQ¯@M°EO±HP´IS¹DN¼FNÀLPÀOS¾NU¹NW´GS´BXÓˆ|úÍ—ö©xáuaÄKR¯ER®?Q«BTµDP¶LVºDOµJVÀRVÆX`¼KTÀPUÂNZ½V\¿TZ·P`½`iË]bÎffÐhgÄXZ»VbÄda½PZªN]ÀdhÒigÒkiËghÉccÄadÄ]Y½QU´MZ¹P`È{}ØŽ‹ÙˆÞ¦–ݦœÞ¢–ݛؑ…Õ‹†×ˆ×š”Û´¨Û¡”Ô•’צ Ü¥—Û©œÜš‹Ù¨“ܪžÜ³¤Û¶®Þ­›Û·®ß³£Þ¸ªÚ­ªáµ¦Þº¸Þº¯Þ¹®Û²«Ü²¡Ö¬¦×®¥Ý¼·äÁ¶á¾¸äÁ³áÀ¶àÁ¶âÄ»âĻᾱàÀ´ÜÀ¶Þ»¯àÀ¯Û¾´Þ¾°ßǼâȾÞļÞĽàÈÀÝÈÂÜÈÂáÎÅáÉÂâËÁçÕÍéÞÕèÜËÖǼšQf˜.F¹HJÏ\X×jfÜnlà…zâ~uå~qç€jæ€oå~nä{nâzoßxnÜohÍcc½UY¤=K|=]5N8I 4I<RF“j†Ò¼èÐÀé̲֩•Ì•“ÚþåÒÄìÖÇíÕÅëÔÁìÓÃëÓÄëÒÅîØÈïÙËôàÎöèÌØÌÁ`(LLEOAV@^C`CcBeChCgDa?dA[@cAf@bC\>Z@\@dBf>fC_DZBdL„8\¬cxÆw€Ð€~Î~~ÇwzÁqvÆ{|І€ÔŠ€Ö‹€ÖŽ~Ö‹~Õ~Õ~ÓŒ~Ó‰zÓŠ~ÓŠ~Ò‰{ÔŠ|Óˆz >Rž:M¢=L <L¦:G¦<N¨;IªAN¨=N¦:H¢7H¤4E¬<J¸MSÎZUÚj_ávcåfèˆlëŽqêrìnéŽvêrërêŠpé„iå|fÞqaÕbXÆPO¯@L—.EŒ0HŠ-DŽ.E‘*B›5L:L¨>M¨@P¯BO°DOªBP®@J°DN°?J²BN²@M±DN®@N³DNµEP´GP·JS¸HO¿KQÀPU¼U[¸V_¶FQ´GXüÆŒñŸzÜo]¾HT¬=P¨BS¯FV³GS²FRºHO½LUÀOSÀVY¹FN¹LWÃ[`ÀJR¼VbÊ^_ËccÍfkÇaaÁXc¾`jÂY_¸Pc¸\gÅcgÐhkÏhbÊ`^À\fÆc`¾RT´PW³LX®I`ȂەˆÜœ‘Úš–ß§˜ÞŸ’Ø”ŽÚŠØ“ŽÔ’’Õ—–Ú¦”Ö…Õ’ŽÚ¦›á¯œÜ«ŸÛ¤’ל“Ùš”ßµ¨Þ²¬ß¹«Ø°«Ý¬˜Û°¤Ü¬£Ý¶¬Û¬«â¶¡Ú»³Þ´¤Ø¦¢×«¨Þ½µÞº´äº¨á½³á¿±Þ»´à¹§á¼°ä¶à¹޼µàÁ´à·޿´Ü¾¶Ü÷ÜÀ¼àźáÈ¿áÊÁ߯¾ßÌÄáÌÁàËÅâ˾áÈÀàÉÁåÐÇçÕÍèÙÌåÙÄÀ¢¦˜6L²CNÍ[VØiaÛtjàtã€ränçƒmæoæ‚oä~oá€rÞzpØlfÎc^¹NRœ<Jv:W 6H 6C<[(N¦‰ ÚƼéÒ¿äÄ­ÐœŠÆ›¡×¼éÓÅí×ÅìÒÁêпç;çÏÁéÓÃêÍ¿èÆ·ëÐÄòÛÈ÷æÑãÔÀxC`JDRCYA]B_@a@c>e@b@cA`<`<d<^:W:V=`Da@iGiDcC`I\Dv&PŸRnÂtÒƒ†ÑyÊzxÇvzÆwv̂ՊÔŠ}ÕŒ€Ö‹y׆{ÖŒ{Ô‹|ÕŒzÓ‹}ÔŠ€Ô‰xÒ‹{ÓŠyÖ‡x =P¢:N¢>L¤;K¥=L¨<L©?K¨>Iª>L©?K¦=L¤6Hª@L¼KRÎ]YÜiXãv`åfèŠlê’sêqêŽrê‘uërìŽnêsè‚jæ{dÜqdÖbYÄTT®EM—0F‹'@)B‘,D•0FŸ5H¢;N¤>N¬@L¬CP¯@M¬@M®CL²EN³BL±DM²BL°DJµDK²EP³EL·HP¼KTºOWÁLPÁNR¼NT¹Q]µHY¹OXô¾™ú¼…óžkÙoc¹AMª:L«@M¯FS®DS´JT¹JU¾PX¼PU´@L¬@P¿W[»MZ¿X^Ì\_ÊafÈ^`Ìb`À[bÀZ_¿OY¸VeÂ^fÑjmÍrpË^`ÂTZÃ`aÎfbÂU[¸PX¸LX´ViÎ~‚ÚŒƒÜš•ޟܧœÚ˜ˆØ…ÖŽ†×Õ–”Ü£šÚ–ŠÔ’Ú¥ŸÜ§Þž‘ܤ—ܦ’ئ›Ø£žÚ®¨à§•Þ¼´Ü®¡Þ¹«Ø®©Üª¢Ý§ Ú®£ß·¦Ù©©Ú¢–Ö£¤Û²ªâ¿¶ã¿µãÀµà¹²â¹¨Þ¼¶á½°Û´®Ý®£â»ªâøà´޾µà¶àúÝļÜĻ߯߯ÀãËÀàǼàŻ߯¶ÞŸÜüÞÅ¿ÝÇÁßÉ¿àÉÂâÍÆäÐÅèØÅÝμªev®BKÊYUÔhaÚulà|lã€mä~jç€oæ€jæ~læ€hß}oÞtcÖojÆZZ¶HJ—:Gg6J8F>o>a¶Ÿ¬ãÐÄìÒ¼Þº£Ê…Ê¢¨ÜÈÂéÓÆìÕÃëÓÀèϽçË»å̾è̾åɸáÅ¶áÆ½èÑÇïØÊöäÌçÛÅ„McKDP@ZAZB^Ab@b?fBbB`<`=`;b<\>V9]Ab?c>iAbB]EYCgHŽ@d¶j}Ђ„Ô‚~ÏzzËxxÆx{Ë~|ш׌‚ÖŠ|؇zÖˆyÔ‡|ÔŠ{ÕŠ}ÕˆzÓ‰~Ò†|Ô‰xÑŠ~ÒŠz׊y¤<J¤=L¥?N¨AN¦=LªAV¨BO¨?L¬@P¨?K¬BO¨=M¬@MÀQPÓ^VÝfYáu`ä‚hèˆkêpê’qêqê“xêrëqéŒnéˆiåmàt`Öe\ÃSS®EN˜4K*B.G‘-F›1F 8J¥:L£>N®>Mª>N®@O¯CO®CR²EM´AL²@L³@J²DP´ISµHS¸GP¹IO¼JQ¹JR¿MSÀOUÀPTµFR²@RÅ[YüМø¹†î•qà|aµHT¬:M­GT±DR´HW¸MW¸GS´HR¨>Q®GUÂNUÁU\ÄY`ÄX`Ê\_Í]`ÀT]Ä^fÃY`µN`»ZkÉ_cÈ`gÏhgÈdfÂ]gÈbfÏjdÂ`dºRWµGTºYeÔ‹‚ÞŠ…Ú‹†àžŠÜœÙ”ˆÖ“ŒÖŠ‚Ò„†Ù›’Û£˜×Œ†Ø—˜Ý¦žß§œÞªžÛ¡”Û›ŽÙŸ—ݪœß²ªß°œÚª¤Þ§˜×±¬Û©œÝ´­Û®¤Û´¨Ú¦žÚ ˜ÙÕ­¨Þ¸ªÝ³¬á¸¨â¾µà½´âÀ·à´¯à¶¦á¿´á¾®Üº´Ý²ªá¾®à¶ß¸߽°à¿µá³àÊÃàľ࿰޿±Ú¹«Ø¾·Ûľܯ¼ÝǾàŸÞÉÀàȾßÉÁàÊÂáÍÅäÒÉâÖÈ̶¶±htÇXXÖcXÝtfàyhã}hå~iæ‚læhä€jå~lâxeÛscÔhbÁRQªBIŒ-D]:]#JŽfʸ¸èÓÃèÌ´Û´¡È––ΰ´ßÈÁéÒÂêоêоèλèλäǹݻ­âŸáÄ·ãȺéÎÂêÔÈïÚÌõãÈèÜÄ‚K`JDR@\C\D`GdDdC`8\:\9]:d@`;[@]A_>eBfBd>Y<U>[F|*Rª\tÌ|‚Ñ„ˆÒ|Êz~Èt|Ê~шÔŒ‚׉׉|ÖŒ~Ö‡|Ô‹|Óˆ~Ò‹ÒˆyÔŠ~ч|Ô‡xÔ‡}ÓŠ~Ö‰y¨>M¨@N¦>Lª@K§BO«@J­DN®AK¯@L¬?K«>Kª=J­@L¼NRÑZXÚncát`å€jæŠnêŽnê’xêqê‘wépëlèlèˆpè‚gâveÙfYÆSW±FO4G0F’+E—0Fš4J¢8I¡>O§?L¬BO¯DN°AL­DP±BP±AL´CN´DN´BL±@L´EMºIPºFPºHM¹MS»MRÀMPÀPR¾MP¸JR³BUÑrhüΞøº‰ê’gÑ`V¼KS°@N²GR°@L´JT²GS²EN¤8Q­JXÀTb¾VZÄNYÆY\ÌabËTXÄZbÉ\]ÁR^»_jÀ^dÄR]Ä\fÎhgËdlÊrtÐnnÌghÆ`aºKR­DT¼ajÑxyÛ…wܛےŠÚŽ‚ÚˆzÔŠ†Ô‰„ؘ’ÖžžØ‡zÔ‡ƒØ–૜ݦकޣœÙ£œÕž™ÛªœÜªœß² Û¨£Þ¬œØ«¤Ú¤—دªÝ¦›Û²¦Ú£˜Ö˜‘ÒšžÚ¤ŸÞ¸¨Þ­¢ß±žÝ¶«ä»¬â¾¶â¼°Þ»°Üµ°à´¨ß¼²à¼¬Þ¼²Ý¶°â¿«â÷ÝÁµÜ¼¬Ý³¢Þº©Ö§˜Õ¶´Ú¾´Ûº´à´àÄ»áĹ߯»ÝÁ·àȼÞžàÈ»ßÉÂÞÈÁäÎÄãÒÏåÒÆÒÀ¾Éˆ‘ÖbYÞp\âzdå{bæ|aç€gæ~dä€já}fßwbÚugÒaW»PP 5D~&F†Ig¶œ§ÜÊÁêÒ¿â¾£Ôª™Î¢ØÀ½äÍÂìÔÃéÐÀè̽ç˼äÊ»äÆ¶ßÁ¶ÝºáÄ·áĶäË¿êÐÂì×ÊòÚÊõßÇåÙÁ€D]HBPB[C]EbHf"EfEa<_;`:`8]6Z8\=`>gBf<c<^:O 9M
+:fL–DcÃu‚Ò‚‚Ò€~Îx|Êw|ÈyxцԌ؎|֌։|Ö‰~ÕˆxÓŠ|Óˆ|ÒŠÒ‹ÓˆzІÓ„yÑ|Òˆ|Ô†|©@N§DO¬BL«>K¯@L°EP¯AL°?I°?G«<K®>Iª9G¯BJÂJOÒ`[ÜjXáufä€gçˆpêxëŒpêŽréxë’qëwípêŒtècâxhØh[ÆRRµCN¡3F’+E•.E™.D5G¤=K¦?L¨?N®CN¬CP´?J¶GN´EP³BMµDP·JO¶EO³AJ³DM¶HPºKS¾KR¹LR¾LRÀRTÃOT¾PV·FR³>Wà‘yûÊ÷½ˆâz`Ñ\T»IV«=L¨>L®@P¯DO²CR®@R·KWÀO]ÈVZÁMRÅ[^ÀOR¿TYÇa]ÆR[´HXÁZaÈW`ÅZeÄ_gÎ`bÍgnÌceÄZbÆ]`Ç`_¸HT¨<R¸eq؉|ØŒ„×€|ߌzÜœŠÔ}€ÓxvÒ}ÕššÚ “Ô„}ÒˆŠØ˜Ü•ÞšŒÞ¬›Ü¡œÜœ’Ü­ Ý®¦ÙŸ“Ú ™Ü¦œÞ°¤Û¨£Ú¦–ש¤Ü£šÚ°¥Ö˜’Ò”“Óšžß¦–ß´§Ü¶ªÜ®£Ü§ Þ¬›ß¶¬àµ¤Þº¯à¼´à»²Ýº²ßº¯Ýº³à¼¯Þ¾¸Ý·¬á¹âÅ·Û¹­Ñ–˓Դ´ß·Ý¶ÝÀ·Ý¿¹àÅ»ÝÁ¶ÝúݼÝÁ¶ÝļÞļÞøÜÃ¾ÞÆÂáÏÊãÏÊçÔÆÞÎÂÔŒÝjVâw^äydä{aå{eå}fã|eâydÝvbÕm^Ë[S°JUœD^¬y‰Ò¼»éÔÂæÄ®Û¶¢Ò¨ Ïª¦Û¾æÑÄèÏÂèξæÉ¹æÉ¶æÈ¹âĸÞĸ޿´à¶âĶäȼèÏÂêÒÆìÔËòÛÎôÞÅâÕ¿u9RLBTDZB\DbCgBe F_=d>`<b:`>]<bEcCjBhAc=T 8H8S@„5]³fxÏ{~ÓƒÎ}€Ëv|Èw{ÎÕŠƒ×‹~ØŒ€Ö‹~ÕˆÖ‡xÔ‡zÔ‡}Óˆ{Ó‡{Ô…xÔˆ{ÒŠzÔ†zφ{ІyÔ‡zªBPªAK®BP®DM®BL­BN­EP¬EOªBL°@L«<G¬>J°@HÄHKÒ\TÜjZáxiä€hæ‡tèrêqêsê‘tênísí‘pìŠlê€iâvdÕhcÆVT´CJ£2F‘*B”0E˜0Gœ5I 5F¤>Oª=K®@L­BN±BO³BL±BN¶CMµHR²HN´CN±AL³AH¶DM¸OV¹JM¾LP½OP¿LMÂPR¾QT¸ET¶CVꬖüÊ”ô²~Þq[ÊSO¹OT¬@M§=K©>O¬EN±GT¿LQÂNZ½IQ¾KVÂPV¹AJ±LY½][¿NW·IYÅ^bÎ\fÆXeÉ_dÎ]dÈ_cÈ[^¼R]»Y`Ä`^´MZ©F]¾fqÓ|wØ‚zÜŒ†ÙŽ€ÒvtÔyoÓƒƒÑxyш֒Í|ƒÔŽÞ ˜Üž–Ú˜‘ݘ“Üš’ܨګ§Ü¤˜Ý²¦Ø ˜Ø•ÚŸ’Ø£ Ú¬žØ¤¤Û§›Ú¦œ×“ŠÏ×¢žÛª¢Û¦šÜ¤“Ý´¥Û²«Ú°¦Ø§¢Þ²¢Ý´®à´§Þº¬ß»²Ý²«á¾°Þùܼ²à¼®ÞÀ¸àÀ´Þ·§Ôž”Ë’–Ò©¦Ý¶§Þ¼°ßÀ³ÝÁ»ÞÂ¹ßÆºÜÀºÞºàùÞúÝÀµÚ¾³Ø¼¶ÜÀ¶ÜÄ¾ÞÆÀàÌÄâÏÊçÒÁÞ¸Ü}nãv^äfädå|`ãyfâybßxbÚo[Òe]Ä^d¸sƒÎ¬°äÏÀèӻརմ¦×³¤Õ´²ÝÈÁåÐÂç;çͽæÊ¹âŶàĴ䯻ßÀµßÁ³á¸âÅ·äÇ»åȽæÎÄíÓÇìÖËñÙÍòÛÃÞͼf$DOET<ZB\@_?bB` Gd!He@b>_>^;^?eBb>h>f>_<P 4L
+:lL¤TrÄu~Ò„†Ò‚…Í|€ÈvÌ€€Ô‡|׋‚Ö‹ÖŒ|Ô‹‚Ô‡xÖŠ~Óˆ}І{Ó…|Òˆ}Ó†zÔ…|ц|Ô„zÒ„|Ð…{Ð…~«FRªDP©CM¬DM®FP±@J°BL­CN°BL®>G­@Q®;I´ALÅNOÖ\TÜk\ávdä€gè†lê‹rèŽrêpë”wê’mìŽtìnìŒkè‚jâydØi`ÊVTºIK 2F’)A”,E˜/C6J¢4H¥<Lª@N±EP­FR¯DR²DO²DO³EL²?L±HP´CK°?H¯@H¸BL¹HN¸GLºJP¸NT¾LO»PVºIQ°@Q±AQó¿“ýÉŒðžrÚfUÅSVÂRU¯ES¦<P±DQ°FUºHR»IP½HT²BP½LR¶BO³KUÄVYÁTZ¾V_ÆX^ÇT`ÈXbÎ]_ËbdÌafÊYZ»U^¿^c¿VZµNZ®M]ÄivØ|uÚ„×…Ù†|×…€ÓurÎpwÏusÖš”ÊzwÆlvÕŒ‚Ý˜àœ‘Ü›–Üœ“ß –Ú¦žØœ–Ü£ÖŸžÜ™Ú¦–Ø¡ŸÙš”Ú¨™Ú¡ŸÝ°¢Ø¦ Ó†ÍŒ’Ø’Þ²£Ü®¤ÛªŸÚ£šÜª Ý³¤Û´¤Û¬¤Þ¬¡ß¶§Ü²«ß°¢Þ·ªÜ°ªß¸­àÀ¸àºÞÀºàÀ²Þ¸ªÎŽˆÎ”‘ر¦Ú¹ªÙµ®Ù¸³Ü¾´ÞÁ·ß¾¶ÞÁ¸ßÁ´àºß·ÜÀ·ÝÀºÛ¿·Ø¾ºÚ¹°Û¾´ÚÁ»ÝùÞÈÂáÉÀäζܡšãu`æ~`å{bã{câu\ßyfÜveÖmdÒ„Ô¬®ßɽëÒ½æÁ¥Û² Ø´¤Öª ×»¶àÉÀçпæÍ¼å˺äɹãķ߸ãŸáÁ´ÝÁµá÷âÄ·âĸäÊ¿æÎÂèÑÈêÒÇíÕÌðÙËðܾӸ¨QDNCVF^E^C^B`B^@b@c@^7^9Z<[<b@f=e>`>Z<O
+9]BŽ9`ºfvЀӃ‚Ñ}|Éz}É|~ЃÖŒ€ØŽ~Ö‰|ÔŽ‚ÔŒyÕˆ}ׇ|Õˆ|Óˆ|Ô†zÑ‹|Ó‡~Òƒ|Ó†{Ò„zÑ…yÔ„yÒ„xªBTªCN°FQ°EO®CN­BO«CM¬AL°DO¬@N¯@N®BK¶GLËOLØ]SÞmXâwbâ{hæƒcèpéŽoì‘tì–sì”rí’vì“rí“tègâxgØf[ÈWT·FLž0D“.D˜-D›0Fš6H¤<L¥<K§>L°@M«AL±AN³FP²EM²EN¯@L³EL°DM°AN´@JµDK²DN¸HM½HLºJO¾MP¹KO³GQ®<R·LUö̦ù½ŒçŠfÖg^Ñb[ÀV[µFS®IU®AR´FRµIU¸>J®GX³AN¬<MºOSÄOSÀU`ÃTV»HU¾Q[Î^`Ë]fÍagÉXZ½KX¸TaÃZ^ÂS]¸T`´L\ÁkpÔpk×}Ü…xÙŠ€ÔspÐwvÔyxÓ…„Î|ÄgfËy|Öˆ‡ÚŠ…Ý”…ݘښ”Ü¢œÜ¢šÛŸ×˜‘Ô”•Ø”ˆÖš–Ø™˜Þ±¢Û®®Úž–Ú¥’Û“ˆÔ’‘Ò™›Ü§”Ú¥ Üž“ܬܮ¥Û¥žÛ©–Ú£›ÛžÝ²¡Û­¤Û œÝ§—Þ´¬Ü´°Ý¶²Ü¶°áÀ·â·áÀ¸Ù«¡Ò›”Ѧ¤Ö¬¤Ú´¨Ø²©Ý¹¬Û¼´Ü¾´Þ¼°Ü¼°Ü¼´Û¹­ß¿¸Ü½²Þ¾¶Ü¾·Ý¾·Û¾º×½·Ø¶­Ù¼¶Ö¼¹Ø¾¹ÝÈÂâʹ߾³ãxbå|bæ}dãxZßu_ÜpaÛvqØž¢àúêѾæÇ®Ü±–ض¦Ú´£Ô­¨ÚÃÀâÌ¿çξä˼ãȹâǶàõß¶à¶ßÀ²àĹàøâĸãÄ·âÊ¿æÍ½èÐÆêÐÃìÔÇìØÌðØÉðÚ¼À˜’KFPATA^F]B`B\=]@dAc>_<\=\>\:b>g=e>`@]>hA€.U¬YtÊz~ÒÒ€€Ï{{ÌwxÎ}Ö‡׋€ØŒ~ÖŠÕˆ~ÕŠ~Ôˆ|ÕˆwÔˆ~Ò…zÒˆ}Óˆ|ЇzЈ}Ò†zÒ…yσ{Ô…yÒ„x«CR¬FO¬BN¯?H®BL¯@L¬CP¬BL¬FT¬<J®BI±?G¼HJËNLÙ_Vßl^äxlá~lêˆfêpêlë“sî”rî–tí”tí”qípè†iãzgÛj\ÊXT´FL 3D•+@’*B™0Dœ9K¤?L¤9L¨@Q¬BOªDN­AN³EK°DN´@J²DO²EM²DP°BK²AI²EM´DM¸HNºIN»IN·GNºIO¯FRª<TÆb]üÒ ø¿‚àƒpÞr`Ð]VÈYY¶FR¶GR³HV³JZ°BP³DQ°?P©@R¶NX±>Q¼NV¼IR®@T¸R^ÆX^ÂT`ÆY^ÆRZºJX¼W`Æ\a¾S_ºR`ºUeÌsv×yrÕwvÚ{oØv×|sÏuuÐvvÔ‚Òˆ€ÀdiÈy~Õ‰ˆÚ…ٌՀژ‹Û¦¡Ú •ט֒ؓŽ×”Ô’•َܪœÛ¦ ß°œÙ¦£×‰…Òƒ„Ö™•ܬ¡Ü¡’Û’Ù¡›Úš’୘ܪ§Ü ”Û¤™Ø¤šØš’ݦ“ج¨Øž˜Û¦–߸®àº­ß´§ßª–ß°œØ¦ Ð˜•Ö¬¢Û³¨Þ¸©Ú² Ú²£Ø­œ×¯¦Û¸®Úµ¬ØºµÚ¼µÚ»¶Ý¶¨Ý¸°Û¶¬Ú´ªÛ¼´Ø¾¸Ø¼µÕµ³Ö²¤Õº²Ô´¯Ø¹±Û»Ýź݄yâz]âzbãxfÝxk؎ܲ®âʼæÍ¶á¶œÙ³žÚµ¢ÙªœØ·´áʼæÎ¾æÊ¸åǺáŹà´ßÁ¶ÞÀ¶àÀ´áÁ´àĹâÄ¸âÆºâÂ¶âÆºäÈ»çÌ¿èοêÏÂîÕÈîØÌðÚÅïܼ§v|KCRJX"I^H^E`AbAa@b>\:\<Y9Z<`?d?fBfFeEmJ~$M›HhÁn|Ñ|€Ñ€Ñz|Ïy|ÎzxÒ„Ö‰~׋ÖÖŒ€ÖŠ|Ö†Ôˆ}Õ†zÕŒzÔ‡{Õ‰yÓ†~Ò„{ц~І€Ò†}Ñ„zÐ…zÒ€z¬EN­BP¯BN³@J®@L¬@N«BO®BP±FO­@I®>I°@K»GJËNKÖ_WÞlZâ{hä„nè‹qëŒsì“mì–vî–rë”tî–}î–xì”vé‡jä{gÛiZÍXP²BL 2G’.F”.D—3I›;O¤<M¤<L«<K¯EO®@K¬@L¯DM¯BO±CN°CL²AL°;J±BI¯CN²FN²EK·JQ¼HO¹KO¶HN·FK®AO©7QÖ‚rüÑŸõ´~êkÝq\Ó_WÈ][´DN¸HP´HT²GU¹KX¼LW°HY¶ET´DU·LS¾PV´JYÀRYÈRXÉ[_ÃX_»O\¾Q\Ä^cÈ]dÅ\bÂU^¸PcÌsv×€€Ôwt×€{×stÕslÒrtÑvqÒˆÈoj¿bkËx~Ø‚ƒÙ†~Ùˆ†ÚˆÙ”‘Ö’ŽÙ™‰ÖœšÚ—Œ×—ŽÖ‘’Ù’‹Ù •×¢¤×Ž†Üª™ÛšŽÖ’‰Í€ˆÖ–ŽÛ¦™Û —Øœ—× šÙ›”Ù¤šÛŸšÞ¡Ø§¤Ú˜”Û­¢Ø£ ×˜’Ú©šÚ¯ªÚªžÜ´¥ÜŸ’֙ь֟›Ø¢œÚ¬£Ý´£Ø©–Ö¦Õ¤œÕ¬¨Ô®­Ö³ªØº²Øµ±Úº°Ý¾¸Ý»´Ø²°Ú®¥Úµ¬Ø´®Ù³¯×¸°×·´Ôµ²Ò¬¡Ô³­Ð²­Ó´®×¹²Ü²ۧ¦àqbßxd݆„Û°®à°èɴả޷¡à¼¨á´¤Ü±©ÚÁºå̾èÍ½åÆºâÆ¸á´ÜÁ¶ÞÀµß·ßµàµß·âŷ䯏âĸâĶãĸáÄ·äȹæÌÁèÐÅî×ÊîÙÍñÙÄìÚ¾‰RdOJRGXF^E`FbE`AaBb<Z<W 7^;`B`=eCc?dFp"Lz(P’8\±\tÎy‚Ò||ÒxyÎv{Ðx|Ï€~Ôˆ‚ք׈~׈€ÕŠ~Ô‹‚Õ~Ôˆ|Ôˆ{Ô†}Öˆ|Ö‰~ÒˆzІ|ц|уwÓ…xσ|Єzу{­BP¬FO¯BN³@J­CN¬DP®CN°AK¯EL±AI²@I²>J½CGÊPMÖ]VÝm]äzfå…lê‹nëŽmë’rï’pî–sì—wî•uî—~ï’rê‹pâ{fÜn^ÎUQµFL 6D‘+D“.C–3F?O¥@P¤8E©<K®@L¬DO«EP°BM¯@K±AJ±@L°BK±<I®@M­FR®BM²FN´FOºFOµFL¸GNµCJ¨;N¨:Oæœ~þΗ÷µémß~cÓh\Ê\X¾PU´BM²ES¬DS´IQ¶IX¸GRµFW¼R\µ@Q¹P\ÀLW¼ITÄY[ÄV\ºKX¿TbÈZbË_fÌ]bÀOX´K]ËjrÖxtÕxvÔ}~Ù‚zÖqoÏhhÒttÒ„ˆÎpg¿aiÍt~Ù~uÚŠ„ׄƒØ‚ƒØ“‹Ú™‹ÓƒƒÎ…ØŽ‚Ø”’Ø—Ú ”Ø™—ؗݦ•Ô›–Ó„wÓˆш†Ù¤“Ü –ÚšŒÚ ŒÙ£ Ú£™Ü¤šÚš”ÜžŽÚžÜšˆÙ¨ Ú–Û¨—ר©Ù¨¢Þ³ªÜ®¥Ý³¥Ô›•Ò™˜ØªŸÜ®£Û¬¥Û³§×¬¤ÏŸ Ö¤šÚ´­ÙµªÛº²Ø²®Ü½¶Ù¸²Ú¶¯ß¸§Ú¶«Ø¬£×ª¢Ù°¨Ù´¬Ù³°Ö¯¤Ö´°Ò±­Ð­«Ó®¦Ò¶´Ó¯ªÔ°±Ö·«Û¾ºÜ’Ûš˜à¿°èϹäªڪ‘Ú³žß±ß³ªãÀ·åǺæÉ¸æÉºäƸâŸàÄ·ÞÀ·ß¶àÀ³ß¸àÁ¶áÃ¹âÆ¼ãǼãŹáĸâ¶߿±ÞÁµæÊ¿æÍÂéÏÄîÖÌïÚÌòÜÄäÖ¿v6QKDVH\D`BbD^@`FbG^?]=X:^=c?c<dBdGjJt%Pƒ1W£PnÄrÓ}Ó|Íy}Êv}Í~|Є‚֊Ռ؋€×‰~ÓŠ€ÔŠ‚ÕˆÒ‡{Ôˆ~Ò…|ÒŠ}Ô†|Ô„xÐ…}Ñ…zÒ†xÒ‡xЂyц~Є{¯@N¬AL­CR³DN¯FP®AK«<I«CL®DP°?H±?J¶BHºHLÌQLÕ`UÜl\ä|dç‚fè‹nì‘qì•tî–oïští™vï—wî–zî’xê‡gäzdÞk\ÌWP¸HM¡4E‘,A+A–.Dœ5F¥6H§;H©?K®:H­AM®AN°FL°@J°BN²>I°?K¯>L¯DN®>L²AK³BL²DN¸FLµJP¸FL²BK©9O®<Pï¼™üΕö«vì˜jàxjÙhbÎZV¿LQ³HQ²ERºNS¶LSµFR­BR¶JVÀHQ½NXÅP[ÁT`¾S\ÇS\¿OYÁT\ÌY_Ì_jÈY[¿MW¶K^ÈktÖz|ÔrsÖ|zØ~xÔvqÒpnÐqnÑvrÊnjÀafÍpyÖ}xÔ{}Öxx؇ؖ“׊„Ò…ƒ×…Ôˆ‹Ô‹‹ÚŒˆÚ¢›Û¨¢Û¨œÖ”—Ø‘ˆØ–ŒÏ{Ô––Ú¢˜Üœ’Ý¡‘Øœ—Ö•’ÛœŠÚ¨žÜ¡”Ú›’Ø¡—ÜœŒÖ•–Üž‹Ù¨×œ˜Þ±£Üº³à²£Ü§™Ö¢Ø¥¡Ù§žØ¤›Ú¦›Ü«™Û´ªØ´­Ø³ªÖ¬©Ú°£Ø¶ªÚ·®Øµ®×²©Ú¸¯Ú±©Ú¦œØ¯¤Õª¨Øª§×­¨Ø°¬Ö°§Ôª¨Ô°§Ó­¤Ð«¨Î£ŸÒ¯«Ð¬¬Ô®©Ó±«Û¸¨Ý¹«ãÄ°çÆ­â¸¡Úµ¢Ü¹¦Ü·ªÛ»²âöæÉ¹çƶäÄ´ãÄ·âĶàÁµàÁ³ÞÀ´Þ¾®ß½²àÀ·àÀ¶ãÅ¸áÆ»äŹäµâĹ޼¬Ýº­àöæÌ½èËÀêÌÀî×ÊïÙÉòÝÁÛŲ\AL@V@Y<]?^>`Ad#EdD]@Y;Z8`>d>a?dIk$Pq$P1\–Imºf{Ñ{}Ö~~Òx{ÌwzÎy|Ï„‚Ò‰„ÖŒ}ØŒ~Ø~׊‚ÖŠÖŠÖŠ‚Ò‡‚Ó†~Óˆ€Ó†|ÔŠ|Ò†zцyÔ†xÒ†|Ò…{̆}ÒˆzÒ†}­FUªAM«BP­BN¬DPª:L«@M­BN­DP²AI³DK³BL·HMÅQRÐ^TÛl^äyaæ…gêŽlì’rî–mî•xî›vð˜rñ˜mî—rî’rìˆiä{gÜkZËRO·IOŸ5G“,B+@—0B4D¦8Fª=L«:H®=J¬<L®@M¬GQ­CR±@M®>J¬BL®@L­AM¯CM±@I²@L´DM¹IO¶DN¶BH²AL«8N¸FRöÍ©üÇó®xêŸ|ãx_ÞzcÏ\WÌ]XÀLUÅVR·KT´DPµFV°CR»JVÀKP¾JRÂPVÍRQÆOTÈX_ÇbdÉV_Ì]dÊ``¾P_²F[ÂhrÔuw×|wÔwwÔsqÒnnÒpnÔxvÒ|rÂad½_jÌpsÕxtÓuvÔ|Ô€ƒÓyÖ”ŒÎ|{Õ}yÖ…‚֊ْטؑڞ‘Ü¥˜Øž“Ôƒ‚Ò€ÖŽ‹à›‰Üª›Ü ”Ø“‹Üœ“Ûž“Ú˜–Ú—‹Û¤–Úœ”Ü –Ø›‘Ö˜’הڗۨܦ¤Ý¨›Ø¤ŸØ¥žÚ¨Ü©žÜª—Ü«œÜ­žÖ¤œÖ¦ŸÚ±©Ù²ªÚ¸²Ô¯©Ú²¥Ø¶¬Ù³¬Ø²®ÜªžÚ«œØ¨¦×›”Ô¤Ö«¤Ö¯«Õ°«Ô¤™Ò®ªÓªŸÔ­¥Î¤žÊš™ÈœšÎªªÒª¢×µ«à±俨߰’Þ­Þ½ªàºªÞ¸°áöåÊ»é̼æÈ·â³⽫àÀ¶à³ÞÁ¶ßÀ´à¿°ß¿±ß¾°à·àÃ·âÆ¸áøâÅ·äÆ¸àº®Û±£Ü¸®áúæÉ½æÊ¿êξïÖËñØÂïØ¸Â›L>O =X>[<_@]:cAb>[>\;Y<`Ab=f=gDdFbEn%RŠ:c¬[vÊt}Ö~Ò}|ÐwzÌvzÑ~~Ò‡Õ‰€ØŽ×€ÕŒÖŠÕŠÖˆ~Ô†Óˆ€Ó†Ô‡}Ó‰€Ô†{ш€Ñ‡|Ò†€Ñ†~Ò†}Ò…{Ò‡{Ó…z°FW«AOª>N¬CPªDQ°AN¬>Hª@M¬>J¬=I¯@L³?G·ENÂQNÍ\VÙn`äxcæ‚hèŽsí”sî–mï™sî›sî–yï–rî™zï‘qê‰näydÜhZÎUR¶INŸ3E“'@’)C˜.Ež6F¢8H¥=LªAL°?I²@M°=J¯AK«@M°>K¯AL¯BN®@M­>I°@J´CL³BJ·EM¾IN´FN·BH®FR¨6NºLQøÐ£þʼnô¨qñ¡nä|cÞqcØj^Ò`ZË\UÌVTÂNQ¼RX¸GR´HXºGR¸GV¼MU¼KV®>N¼QWÊTWÂTZÄ\cÈY\¼Va¶N[Ã`nÒqsÖvrÔz|ÕytÍlpËhlÒwwÔ‹„Ã_aÄhoÒuvÕÒzyÒzyÔ~|ÕŠˆÆsuÌpnÕ†}Òz~ØŒƒÙœÚžœÜš’דԉֆ{Ö‡„Ô…ˆÚŸ™Ü¡”ڈݘ„ÜœŽÜ–ŽÜ™ŽÞœÜ¦˜Ú›”چܢ—Ûž˜Úœ‘ØŸ—Ö–’Øœ™Ú”Ú¢—Õ œÙŸ˜Þ®¡Û°¨Ùª¢Ø£Ø¦šÖ¨¤×ž™×¦œÙ®¦Ø®¦Û¸°Õ´°Ô®¨Ú°¤Ø²¬Ø© Øª¤Õ¡£×œ’Ô  Ôœ™Õ¨£Ö­©Ö­©Ô©¨Ð¡•Ï ¢Ñ¢™É–—ÊÇ™›Ô±¥ßòäêݬ–×¥˜Ó¦žÛº¬à¼°Ý¼²âŹæÊ¼è̸æÇ¸äIJ۸¬Ü¼²àÀµÞ¿µàÀ±ßÁ¶ß»°Þ¾´à¿³âøß¸âÅ»ãĹ寏äÀ±Ù¨ž× “ܲ¥ß¾²äƼçȽêʽîÑÄîÔÀéÕº–^fKCR ;Z=[<]=^Db>dD\BX=Y=]<c<hAfB]<Z?u)TžMj¿o}Ó|Ö}{Ðy|ÐuxÌy|Ò€~ÕŠ‚Ö‹ƒ×ŽÖŒ}ÔŠ€Ö‹€Õ‰|׋‚֌Ԇ€Õ‡ÔŠ‚Óˆ‚ÕŠ€Ô‡|Ò‡ÔŠ}Ò†}Ó…~Ò‰~ÔŠzÔ†{§AQª=Kª@NªDPªDQ¬CP«?M©AL¬@M¯AJ­?J¬=H²CLÀMLÐ\RÛn\âwaå…eêŒnëpî˜qî•rî˜uî”rð—wï–vî’oê‰räv`ÝjZÌ[U·JM 4H”,C“+C™.FŸ3F¦;G¨?Iª@K®<K°AL´>J¯BN­?L°BJ²BN®@K­?L°CK°?J³@K²FN¶DN³CM´HN´DJ®BM¨7N¿TXùÔ­û¿…ô¬wéštÞs\Þzc×h_ÖjbÈQSÌjbÆTSÂMN¶CN¼HP¶CP½P[¸FR°HZ¶J\ÁSXÃYdÀT\ÄPTºP`´L`Âck×rxÓjlÖwyÕzuÎlqÒnpÌvwÑ€w¾Y^ºZfÐprÙ|tÖ|yØyvÔ‚~Ô†€ÒztÊgkÐprÒprÔ‡‚ÕØÜ¥ Ù™˜Ø”ˆÖ‹†ÎptÖŠ†Ý¤—Þ —Þ ”ÜšŠÕŠÛŒ{ÞŸ‘Üœ”ÜšÞ¢•ݧšÙ›–Û–’Ü ‘Úž•×›˜Ø™’ׄטŽÚ—•Ü›ŽÙ§žÝ¦šÛ¦˜Û£™ÚžÖ¨¡Ü¬¢Ùª¦×Ÿ›Ú¨–Ø®¨Ùµ­Ú¶­×²¬×¨¢Ù¢™Ù¦¢Ø©¤Ö®ªÓ¢£Ô›”Ó£ Ö˜•Ö«£Õ©¦Õ¨£Ï–Ì ŸÉŠ…Å‘”Í¢ Ý¿³ä®޳œÕž’Õ£˜Þ¹®Þº®à¾²àĹãǸçÇ¶åÆ¸ãÆ¶ã²ܺ±Ü¼³ÞÀ´àÀ¶àÁ´Þ¿´ß¿´à¾´ßÀ³á÷àÃºáÆ¼äÃ·åÆ¶äÆ¹×¥˜Ò–ŒÒ•ŽÛ¥”Úµ«æÆºäÄ¶æÆ¸îÑÁíѺáÉ´o,HQ@T<X:Z:\<`Ba>c$L_&LV;`>a;eDhDcDY@ZA„3\®cyÏ|~ÔƒÑz|Ìv|Ïz|Ѓ‚ÑŠ‚ÖŒ€×Š|ÖŒƒ×~Ö‰€×‹ƒÖŒ×‹~ÖŒ€ÕŠ‚Ô‡}Óˆ‚ÔŠ~Ô‹xÓ‰Ô‰|Ó‰|Ôˆ}Ò†}ÔŠzÕŒ{Ô†z¬<J¬DQªFT«?M«=Jª@M®?N¬@M¬@L­DP©?Lª@L³DLÄQPÏ\TÜn[âw_è…gìjî’nì—rî–uí™rí–uî–ví˜{ì‘tê‡kåzaÜl^ËXW´JS 7J˜,D’.G˜4J <O£:H¦=K¨:I®=J°CM²BL±DN±@J¬>G°BN°CJ®>I°DJ²>H°?L´FO¶DJ³GNµIO´DN¯@I¨7PÅ\Tù׫ü€ô¨zí•jâ•zÜoØpeÝr`ÓaX×]VÑZS»HN»HQ´JV¶DO³ET¶IYÂRXºGVÀ[bË\Y¹GR«AWµHXÈlsÔxuÖhjÔtpÖurÑkjÓsuÑrpЀr²T_»\hÐnlÖyvÔtrÓzvÕ€Õ|ЄÏopÍktÒxzÔ~ƒÑxyØŒzц‹Õ‡~Ùœ”Ò‚€Ñ}‚ÔŠŒÛ™’ߚݡڜ”Û”ˆÛ”ŠÕ݂ݞڞ˜Üœ’ޜߢ“Ú˜”ØŒˆÖ‚€Ö”ˆÙ£–֕ֈܖ‰Û ”ÚœŽÜ ”Ò֜ץ Ù¢˜ÜªžÚ¯¨Ø­¤ÚŸ–Ú« Ú±¬Ø¯¦×«¡×¥ ØŸš× žØ¦¢Ø¤¡Ù­¨×§¤Ö˜ŽÔ¡¢Õ˜ŒÔ¦žÔŸ˜ÌŽÆŽÇ––Û»°æÄ®á¹žÖª—׫žÙ¶ªÜ³«ßº±àÁ´æÆ¶æÆµäöä±ã±àÀ®Þ½±Ý¼±Þ¾±ÞÀ¶ÞÀ¶ß¿´ß½³ßÀµàÀ·à´ãĸáźâĹ䯹ãŶܰžÔ”ÑŠ‚ÓŒˆØ›ŽÝ¸©à¶¢Þ°Ÿä¼®íʼêήƕŒT<P>U@Z@]>`@_?^;]AZ?\>_;`9_=`C_H_Hn!LœJjÀn}Ô€Õ~}Ïy|Îv|ÎÒˆ„ÔŒ„ÖŒ~Ö‚Ö€Ù€Ö‹‚Öˆ׊‚ÔŒ…Ô‹Õ†yÔˆ|Ô‡|Ó‰|Ôˆ~Óˆ{Ò‡|Õ‡{ÓŒ{Òˆ{Óˆ}Ô†}Ô†z¬@L¨AJ¨AJ¨BQª>NªANª>L¬@M¬=I¯@K¬>I¬?H´GPÄNOÐ`XÞo`ãzbæ…nëlî–oì—uí–ví˜zí˜xì“tì–vî‘xê‡iä|jÞjZÎXW°FP 2H”.F”*E˜3IŸ9H¥>N«?L¨?L®@L°?M¬HS®BN¯BO­@L²?K°BJ®@J®AN±>H°CN¯BL´DM³AJµEK¶BI±AM£5Q½VTùÔ®ù¶~ô¦uî™lî‰géŠhàwaàr^ÞmXØj]ÌZ[ÁQTÆPO»IP¨2F¬BS¼MSµDP¿UZÇXYÄRXµHT°FXÆdjÕtsÔspÒmnÒfdÎnvÑmnÔ€tÆrr²P^»XfÐrpÕvuÙ{xÖz|ÑzwÓ‚|ÏvxÕ|{ÒryÒ|×…‡ÔŠ‚ÌrxÌnsÖ’ˆÎƒŠÑtpÎ}„Ú‘Œßž–Ýž’Û“ŽÙ‹ÚˆÚšŽÙ•ŒÛ”Ž×’‹ØŠ†Ü–ˆÚ –Ù–Ú‹€ØŽ‰×”ŽÖ‰ÓŠÚ€Ø˜ŽØœ•ؘÕ҈ГšÕ ™Ö™Øœ”Ø¤šØŸ™Û®£Ü®¦Úª¦Ö¡ž×§š×§Ÿ×¡šØ¢˜ÖžžÕ–“Ù§¤×¨¦Ö§¨Ø¥›Ò–šÔš‘ЉˆÐš–Ì’”È“’Ôªžä®æÀ¤Ú§Ù¬œÛ·¨Ý´¦Ýº¯à¸âĶä°å²âÀ²à¼®Þ¸¦Üº«Ý¹ªÜ½³Ý½°à¼°áÀ´ß¿µÞÀµÞ½²áõâ¸áÀ¶âÅ¸ãÆ»âȾä²âÀ±Õ›ŒÒ‹„͈ˆÐ‹‹Ö¤—Ø£–΀zØž–ḭêÄ®æÏ¸‹LWQ@T@]"J]C`A`@aB`A^@W=\8`<^9Z<^Cn&Vz0\Œ:_²cyÐy|Ó}ÒzxÏwzÏy|ЂƒÒˆ~Ö‹„׋،‚ØŒ‚ÕŠ׋|ØŠÔˆÔ†Ô‰}Ô‡~ÓŒ€Ñˆ}ÓŒ~ш~ÒŠ{Ôˆ|ӌҌӆ|Ó‡tÒ‰€Õ†x¬@JªBNª>JªES¥<K§@O¦BN©@J©@Jª>K¬?L±BL³BN¿NSÏa\Ýoaä€lç†hëlí•rë”uí“vì™pë•sí’vì•yìŽléˆkæz`Þk\Ì[V±GOœ6J’0F’.D˜.FŸ6H§>P¨>Oª>P®ER®DPª@Nª@N°BL°@L°@K®AL°@K¯@K°@L°EO°BJµBL´HP²@K²BL«?M¢7V¾`WúÔ¬úµpò®{ìfæ‰må€dÜ|jßpYØogÛdZØg]Ò\VÆNS±@NªBR¯<L¬:M»NTÃRV¾OW¿MV³GXÄjnÒjnÖnjÔnmÔnlÌdjÏjpÐwwÊzu¶R`¸VfÏjlÖpnÖyvÙxt×€{ÎwuËrrÍr{ÒttÕ„Ô…†ÎrrÌx}ÍzÑtÕ~zÕ~xÏvÚˆzÜ”à˜Þ›‘Ü•ŒØŽØ‰ÜŒ‡Û˜Ü”ŒÛ™’Ø–Ž×†„Ü€Ùœ‹Ø•Ù‹ƒÛ”‰Ù‹Ø•‰Ò–‘ØŽ†ÕˆÑ‚‚Ì…ˆÓÙ––Øž–Øž“Ùœ–Ø’Úš˜Ø˜Ú¯§Ù«¦Ô¥ Óž›ÕŸ˜Ö¢œÖž™Õœ™Ò–˜Ô”’×£ŸØ¬¢Ô žÏ™™Ê…~ʈɋŠÕ¢”ݺ¨ã½¢Ü¨ŽØª—Û²ŸÛ´¥Ü¹°Þ¾³âÇ·çÅ´ãÁ°á¾°á½¬Þ»ªÛµ¬Úµ«Ú´ªÛ¸°Ü»°Üº°àÀ´Þ¿³àÀµàÀ³Þ¿²à·âÀµâĹâùäÈ¼ãÆ¸äǺؤ”Ћ„ÍƒÑ’ŽØ¤—ؤ’ÀjhÆz€Ùž—೤æÃ¦Öµ¥^=TDR 8\C_"J` D`?b<_:Z:Z;b9d>\;\Bb Oy.Zˆ8d¦XrÈt€Ö|{Ó|}ÐvzÌvyÍ€‚Òˆ…Ò‹„Ô‹€×Œ€ÔŒ€ÖŠ€Ö„}֋׊ƒÖ‹‚ÖŠÓ‰ÒŠ€Òˆ{Ò‰‚ÒˆÒˆÒŠÔ‰|Ò‰€ÒŒ|Ô‡|Ò†yÔˆ}Ôˆ¬@L¨@K§;J¦>H£>L¨:L¥<I¥@J§>L§>Iª?L°@N°BOÅQRÓbZÜrbä{cè†fëŽpì’rë”uê“wì”té”sì“rê”vìoì†jæzcÝl\ÎXR±HPŸ8H”)D/H˜.Fž5J¥<K¦;Lª@N«?L«DQ®BN°@K¬@L¯BN¬>J®BM®AJ¬>H­@I±AH´DH´AJ³EN³AI°@Iª>MŸ4PÆl\úÌœõ±|ó¥lì–qëŽgç†héeÞobÛj\ØpfÛm_ÍXU¾FN³FS®@M¥8N²HQ¼LS»HP·EO²@TÇmrÔtqÒmjÎioÓifÐegÏlnÐppÊqo´P\¸ZjÈjnÓllÔllÖxt×€}ÐtsÐsrËloÑtrÔÎvpË~Ìx~ÖŠˆÖ…‚Õ{yÍjpÔ}{Û–Ö‚‰Ùˆ€Ü‰Ú‰‰ÝŠ‡Ü˜‘Û–˜ÙŒŠÚ’†Ø–ŒÜ’‡Ø“ŠØ‹…Ö†‡Ø‚|ß ’Ø”’ÙŒ†Ý‘‚Ù—ÕƒÊ~‚Ï‹ˆÑ•”Ô“Ö™’Ö•‘Ø””ÛŸ”ܞו”Ø—’Ô“”Ø¡–Û¬£Ø£œ×ž˜Ö“‘Ô™‘ÕÔžšÓ‘ÓšœÔ•–Õ££Òš˜ÅŽÅƒÎ”’Ù±¥åÀ«ÞªÖ¥–Ù­ŸÚª Þ²¨ÞÀ¶âȼæÄ´æÃ²ãÀ°äÀ­Ý¹­Ü¯¤Ú¸­Ýº­Ü¶ªÚµ¬Ýº°à»²Þ¾²àÁµàÁ¶áÁµßµàÀ¸âøâÀ¶ãȾäȽäǺäǵ⽭̇ˈˆÑŽ‰Ø£”Ø¥ÀkjÀnqÓ‹ŒÛ œß´¦èÑ´©v}P<P<U:X:]@d(K`$C^<[9X7^=h>c<\>_Fl#R~1\žIj¼o}Óz|Ô{Ôz{ÎvzËz}Є€×‰‚ÔŒƒÕŽÕŒ„ҀЎ‚Ö‡~ÔŒ€Õ‡}ÓˆÒŠ|ÔŠ~ҌՋ҆~ІÔˆzÒ‡yÒˆ}ÓÒ‹}ÔŠyІ{ÏŠ~Ò‡~«<G¬JT§=J¨@N¦>J¨BK©@L¨=J©>I©>L©@J­?L´DPÃSXÓ`[ßn^æ|dè†ièŽlërì–vë–rë–yë–tì–ví•xì’qêˆmæ|dßr`ÎYT¶FN 6H”*D“,F™0H¡8L¥>M¨=L¨BO©BP®BQ­AN¯@K­BN«;G¬>L®AJ¬@M®AN¯AJ°BJ±FQ°@I°AK¬@Jª?H¥8Kž2NÎziúΞú®jð xîškçŠoæ‚_Ýrfæ{^Ùm`ÜfYÖpfÑ[R¼JO¸GT­CT¶JU½JPºLWºET®EYÆdlÖrqÑpqÔkjÏjiÊY`ÍinÏtuÁaa±ZhºXeÆ`iÓqqÔwuÑqrÒrpÓtoÎrtÐnqÔvqÉryÈqjÂgrÐ|xØ„…ׂ~Ö‚ÎosÏ{ƒÔzzÜŠÙ‘ŠÒ‡ŒÓ{ׂz؇ŒÜŒƒÝ£”ے؆ƒÙŠ„Ø†€ØŠ‚Ù‘†ÚŠÖŽ‹Û†€Ý˜†Ù–ÒvqÌÑ‹‡Ò›–Ó‹ÖŠˆÖ”Ž×ŒƒÛ–ŽÖ—Ú”ŒÚœšÚ”ŒÙŒŠØš”ؔۘכ•Õ–˜ÖœšÓ’•ؘԜžÎ’Ҕˌ‘ΈÎȔبžã¼¦â±‘ÚšˆÕžÜ¯™Ü°¢Þ¾²áÁ²æÈ¸æÅ²å¯ßÀ¯Üº¬Ü¶ªÙ¹«Ü¸¬Üº¬Û¸¬Ü·«Üº®Ý¼±à¾´ßÀ´â³ßµ߿¶à¸àĸßøÞļâȼæÉ»æËºäɸ՘‰Ë†ƒÒ’ŒÚ¢–× ŽÂpnÀw}ʆˆØ™”ÜŸšã¶¤æÒ¼‚BTN <R<X;[<]AaA^A\=W<[<`@e@`<\AcLv.ZŠ7a¯_wË{~Ö„ÔyyÍvyÎx{Í€|Ó‰‚ÔŠÒ‹€ÖŽƒÔŠƒÕ‹†ÕŽ€Ôˆ~Óˆ€ÒˆÒ‰„ÒŠ€Ó‹Ћ„Ó‹}Ò‰}Òˆ~ш~Òˆ|Ñ…}ÒŠ~ÔˆxÒ†€Ðˆ€ÐŠ{Ô‰|¨>Kª@M¨?L¦=J¥>L¨>L¨>K§<I¦<J©>L®<Hª@Q³DPÆPRÒd\ân\æ|fç†jèlì”që–vì–tì“yí”rï”oî”tí”pêˆjäzcÞn`Ì]Y±GSŸ;P”-H“/I™2J¡7J¤:L¨=LªAN­@N¯>M®@K®@L®@K°<H°BN°@I®@M°BL³FN°DK²BK²@J°DK¬BK©<G¥8K¢1MÜ’súÄ‹óªzó©në™tëœmÜtjæˆdÚvoÜl\Î`\ÚpcÏ]YÊQUÂRW·MVµCR¸HQ¶BPºHWËilÔtvÔppÓnnÒhiÊfjÉehÌmkÂgj³O^ÃajÉcnÓtuÔsrÖpmÔ~}ÐkkÐjmÐppÐytÈhmÅimÉrvÒ~~ÑyzÓ~zÒpoÎhoÔ}~Ú‰…׌Ø€Úƒ~؆„Ó†ŠÔ€„Ú…~ÕŒŽÚŠÙ†Ï‚ˆÒ†”Õˆ‹ØŒÚŒ‡Ý’…ܘَ„ÒxÍyzÄw€Ôƒ×œ˜ÙŽ‚Ú’‡Ø”Ø™Öׇ„Û˜‘Ù”–Üœ‘Ù“’Ø““؈֕‘Ö‹ÔˆˆÖ‘ŒÖœ˜Ó—˜Ò‹Ô•ŽÒ“‘Ê€„ÉŠŽÇ‚ˆÔ”Žá´¢ä¶ŸÞ¤‹Ø ŽÜ©“Þ­Ÿà¹©äÀ­åİçª㿪ཨ๤۸ªÜ·¬Ú´¨Ú¹°Ü¸®Þº®Ü»°ß»­ß½¯ß¿µàÀ´à¸á¹áÁ¶à·âÄ·á·âÄ»âǼäÊÀçʼæÊºà¶¤Ì†ƒÌ†…Ôž–ØžŽÇwrÇ‚ԌՖ‘ÒŠŠÜ£œçֹ̳§V@P@T?Z@\<^?_@^=^&MU<[<aAcB]@^Gj#Sy+Z NoÀo~Ò‚„Õ~}ÐxzÌx}ÑyzЂӇƒÕ‰Ö~׌|ÔŒ‚Ô‰~Ôˆ~Óˆ}Ò†zÓ†{Ó†~Òˆ€Ó‹{Ó‰€Ò‡|Òˆ~Òˆ{Ї{ÒŒ|Ò‰{Ó‰|Ї|Óˆ}ІyÒ‡zÓ‡z¦BUªBM¨DS©=L¦8F©=J¨?J©@L¥<Mª>K«<I²BN¼JRÌUTÚaXánYä|dç‡kénì”pé”sê–ní“xì”tì˜rí’tí’uëˆnæzgÞqbÐ[V´JR¢4H’,CŽ.Fš1EŸ:K¤:L¨<Kª@O°AN«BL¬@O¬?M¬AM²@L¬AL­@J­<H«?L¬@G±@K¯@G°<I°BL®BL«:F¥5Fž/Lâž…ø¾…ø¶zñ¤{ô¯pëoéjÞv`éˆfÜtbßq\Ûj^Ûj\ÍUUÐZT¼LS¶JR°?O®DWÈegÊ`jÕjiÑlqÎfhÌglÊjpÎtt¿X^°TfÀUfÆ^dÒtpÕtrÔssÖuvÖwvÎnlÑmoÍvrÀ`gÁbnÌkqÔzyÕ~xЄÏpsÊgoÑ||Ù€؇€Ú„Ûˆ†Ô{~Ôx|ÚŒ‚Ø‘–Ñ~ƒÔ~ÐÎv‡Àsă™Ôˆ‘ØŽ”Ø“ƒÜƒØˆÐ€Å~‰ÑŽ×Ž‡×Š†Û‘„Ö’Ö‡†ÛŒ„Ø“ŽÚ’ŽØŽØŠˆØ”Œ×Š‰×“ÙŽŽÖ”˜Ô†ˆÕŽˆÑŽ’ҋҊҔЈŠÐ‹ŒËŒŽÅ‹ÌÚ¬œâ¸¢à®‘ÙŸÚ¡ˆÛ¨—Þ·¬ãÀ­ã¼©ã¼¦á¸Ÿá·žß²™Ù¬™Ø¬žÚ¶¦Ü´¨Û¶¬Þ»®ß»­Þ¼®Þ»­Ý¼¯ßÁ³à´âøâ÷âĸá¸à·á÷âĺâǺäË¿åʽæÌºãŶ΃ȅ…Ò–Ò˜ŽÇuyʇŠÔ—Ó‰~ÉvwÌ€†á´¥îÙ½¨tvLBO?V@XD^A^?_>]EU:^$KaBeBdB^E_Jk+X†8b³dtÏ}Ò€€Ò}|ÍuxÊvyЀщ„Ó‰‚ÔŒƒÕŒÕ‹€ÔˆÑŠ€Ò†~Ó„|Óˆ‚Ôˆ~Ôˆ|Ò‹„Ò‰}шÒ‡}Ò‹}Љ|ц}ÑŠyω|Ò†|ч|щ~χ}Ò‰Óˆx¨=K¦?J¨BR®BP­AN¬<J¨@N¨?M«@L¬@H³@M´@J¾GPÉTTÖbZàpaåzeæ…léŽpì“oì–uì—rì˜xë™xì˜pì˜tínëˆpæ|fÞshÐ]\¶NT¤:N“)B‘.C˜-C6J :K¥>L§>L©<M­BL­=L®=J¬@N¯9G®?J°@L²AJ®BN¬AN®?H°>I°BN±AM«>I©:D£2Gž0Iì°†ûÅŽö¸…ö¹yíœzð©|èpæ“pâ‚jä~_ÜdTáycÙo]Òf^ÅLN¼HP´<L©<NÈgf×mkÑhjÇXaÐjhÈfrËdjÍrrÂ_b´WeÀZfÄ]lÓtuÐlqÒllÓutÖzvÐhiÐuwÌipº[g½]lÌhqÓz}Ô€|ÐssÒ{uÈdmØyz׈ˆØˆ„Ö„Ú|ׄ‰Ö|Ð~ÐwŠÓ‹šÎ‰¢ÅŒ«¼…œ²ž¨v–¨j†¬by¯gx«Uh¹^aˆˆÔŠŠ×Š„ÚŽŠÛˆØŒ„ØØˆ„Ø‘ˆÖˆ‡Ô†…Û†Û–ŽØˆ×…Ö”“ÕŠˆ×’×ÔÒ„ŒÔ‘ŠÑ’—Í{΋ŽÊ„ŒÅˆÊ…ˆÖ¤™Þ³›ä¶ŸÛ˜†Ù “Þ²žÞ¬¤ß¸¤çñå¬ỨܴœÛ± Ø­žÔ­ŸÕ°£Ù±¨Üµ¨Þ¸¬ÝºªÜº­Þ»¬Þ½°à¾³ßÀ´à÷àĸãøâĹâøá¸ß¸áŹáÅ»ãɽæÊÀåÌ¿çк֪¡Æ‚‚Ñ–Ñ’†ÇzzÎŒ‡Íˆw¾ed²Ud¿mvÙ˜éÌ·åÒ½t0HJ<R@WAZA`FaB`D`"LZEc!Hi,PgDc@aH`Gt&X›JjÆqyÕ€~Ö~|Ñy~ÎwyÎ|yÓ…Òˆ~ÕŠ€×ˆ~Õ‰|Õˆ~Ó‰|Ó‡|Ôˆ}Ô†|ш{Ô…zÓ†|Óˆ~ÔŠ~Ô‰}Ó‡~Ò†{ш}чyÒˆzЊ{Ò‰~Òˆ}ÒŠÒˆ|Ó†|Ò…x¬>Kª@M¨@N¬BP¨AP©AM¦>P¨>J¯@J­BMµDL¸HRÄHNÏTTÚ`Xàm^åzcèˆiëŒrì”tì˜tì•vî–rì—vî“tì•pìmîˆlæ|fßqcÎa]°DKŸ5E‘*C'?–.Fœ4H ;L¤>O¨AQª<P«BO­BN«>M©>L¨<K«BO®BK®>J¬>J®CL°@I®@K¯>H°@H¬<H§:FŸ.Ež-Jé«úÆ’ü¾‚ò«xõ½†î”kí›pèŠiæißq\Ü~kánVâmÞhVÍb\¾DK¬3JÂSVÏbhÖjiÐhkÈenÄ[fÉjuÌom½\e³VfÁcjÄZfÓutÕqmÑkjÐllÒqrÒjgÎnrÉgi¿[lÅipÇfsËjrÔ€{Ð|ƒÎrpÀ_kÐkr×yxÛ‚€Ù„Ú‡…ÓyÈs~³^~´d}¯i‡®h„¸rŠÅx‡Æ‚ŽÈ|ˆ°b~½zÃxz±v†•U|+VÍ~€ÚŽ‚×ˆ„ÛŠ€ÚŒ…Ö†ƒÖ†Ò…‡Ó‹–ÛŠŒØŒÖˆ‰Ú‹ÖŽÔ„‚Ø…~Ò‰‹Ð„ŒÐ‹ŠÓ‹’ÔŒŒÏ„ˆÑŒÈ‚ŒÈyy˃̊‹Þ¬–羦ߠ‡ÙŒØžÛ­¥á¹§à¸­åº¢èÀ«á¼©Ü³ Ù²¤Ù³¤Ùµ¦Û²¢Úµ©Ü¸¬Ûº°Þ»°Ýº°Ü½­Þ¿²ß¾°àÀ´âÁ¶á¶âöâºâ¶ãĹáżàÃ¹ãÆ¹âÆ¼æË½æË¾æÌ¾åƸɈ„Ì“’Ћ€Æ€Æ|r³TS¢MXš>W°XfÅ{„â¶¬îØ¼Ì¬žT?K<P :X@ZDaDcD^A\DZ>bBl)LcDbFcNj!Q…2\²`vÏ}Ö‚~ÑxxÐyzÍz|Ђ~Óˆ~Ó‹ØŒ~׊Ԋ~Ôˆ€Õ‰~ÓˆÔ†{Ô†}Ò†|Ð…~ш€Ôˆ~Ô…{ч~Ó†{Ò‡yшzÓ†uш}ЉzχzЈ~Ð…|φ~цzÎ…}¬DQª>N¬BO¨@N¨<J¬@KªEP©AM®AL±@M·HL¸FPÂHNÌSUØbXào\åzaç†lêŽnì–rí”sì—rí˜tì–xî”pí—nî’pîŒmå~gÞo^Ï[S´DL¢6H‘'A(C•0F™4J¢7K¡<M¨DR«BP©=L¬?K¯<Gª;J®<HªBM®>J®?L°AM±<J±=J°CL´@G¯BL®<H§8Eœ/Gš+KꬂúÌ™÷¹…÷ÀŠò¡wðª~êŠhè˜lè€\åjä‚[à|mèzVÝzkÕZQ¶ES¸HVÇ]dÌ`aÇ^hË`fÌbfÇ`hÌqrÄag­N_¾\gÄ\fÏopØvrÔstÑkjÒnsÐloÑspÆfg¶VgÊdkËjmÍsyÌntÑmoÎwrÈ\jÓ{ÔzÖvyØ{yÓw}¿dvžDfŸP{¤\§Wv Ji—Eh”Ab¡Nm»gvÈm|¨QsÈ|…Ëx…Ð„Š·wƒ”Nzª^lËyÎÕŠŠÚŠ†Ø‡ÖŒ‹½u€²uŠÂzÍz€Î~„ØŽÖˆŽØŒÌyŒ¶i§ZxŒ7XłІ̇’Æv{Æ‹Är}Җഢ䰖ݠŠÖ—ŠÚ©¢Þ¶®á¹¬ä½­æ¾ªäº§ã¼©Ý¶¦Û±£Ú´¤Ú¸§Û·¬Ú·«Ú¸ªÛº°Ü¼±Ü¿µà¾³ÞÀ±à´߾³à³â·áÂ¸âÆ¸âĺàÄ·ãŸâÄ·âùäǺäȽçÍÀèÏÁæÊº× –ΌΈ€È‚v²ZW”:G”1IAT¢H^Áv†Ö¢£ìϾíÚ»—_bM
+8J
+6Q
+7Y;\?_<\@\<\?]@f@lB_@`I`Mr&TšLjÂny×|×|ÐvyÌv~Ï}ЄÓ‰‚Ԍ։€Ø‹Ö‰|ÖŠ~Õ‰|Ò†|Ò†zш|Ò‡|Ô…|ц}Ôˆ|Ò†|ц|ц}Ò‡{Є}ч~Ð…yÑŠ}Ј€Ð‰|Є}Ð…zÐ…uÍ…{¨BQªDR®?L¬CR¨>N«BP¨AS«AN¯BP¯BP¸CL½DNÃHPÊSV×d[àq^å{_è…fìoì”së”sì˜rì—sì–sî˜tî˜nï‘sîŒnäƒpßpaÓ]T¶HL6D‘+@Œ$?–+@œ9K£8L¥=JªBN®AL­?L«BP¬AK­DN±?I¬>J°DJ®@K°?K±<H¯CN²AG±>J°:Dª>J©<F0Dœ,I檈øÉüÆŒøªyö”ïšlæ˜tè‡`äŽnæ~WÞvhèƒ^à{dê{XÐ_`ÆPUÊZ_ÄU^Ç[aÉ^bÅ^iÊ]dÊns¼]`¬N]¼XdÀ\hÏjlÔptÒklÓpqÐhkÐehÐtr¾Z^¼XcÊhnÆamÊksÍrrÐ~‚ÇclÃ`lÐsvÕz~×€ƒÖ~…Ðq|·To”Cmª\{Ä~ŽÆn~ÅizºXp±[r§PnœKnˆ6^“>d–Oză”Ù’“ÛÔŒ¼wŒ›_”T‰’S…ŸZ~©Wx¶`sшڈӆŒÇŽ˜°z’žV~»pˆ¹kˆÆxЏŒ±—^¢pw5pf O°mʆ’ÂvŠÌxؤ–㳚঎؀ؖ‰Û¦žâ¶¡æÆ´æÂ²æÀªâ¸¥à¶¢àº¨Ü¹ªÜ¹ªÚ¶¬Û¸¨Ú·©Ù¹«Ú»±Üº¬Ü½µàÁµàÀµßÁ¶áÀ´à·áÁ·âøãĹâŸâ¶áĺâĸâĺãÄ·åȺæÊÁèοêоܮҕ‰Ì‡|¸h`œ;H‹3J–<Mœ<O¨L^¹anÖ›šçÆ»ñÖ¸Ùº¢f:M :P8T 9[:a@^<]?Y?\;c>f>h D_G^Kh N€3\®_vÉz‚Ó}|Ô}zÎx|ÐwyÑ‚~Ó‹„Ò‚Óˆ}Ô‰ÕŠ€Òˆ~ÕŒ|Ô‡|Ò‡Ôˆш‚ш€Ñ‡€Ñ†~ш~ц|Ї}Ñ„zЈ|цzшzЇ~Ï…yΆ}І}Є|Í‚zΈ|΃zªDN¨BP«>MªDQ©DQ©@O¨?M¬BM±BP­>N¶AJ»CHÆJPÑTQÜdXäpZæ{bé†kìlí–vë–uï–qîpí—vî–ní—vï’pí‹lè€fáp^Ó\R¶HNŸ4D'>,E•0D˜0Dž8H¢<J©>LªAQ©@O¬=M±@L®AN±>K°AK³BK±=KµBP²@J²@L¶@F²=H´>F«<F¨4?ž-C+Iå{ùÒ¢ö¶ˆøÃŽöªzòµ…ðžfç›uéƒ^Ûvdä}XÚpfè…bàp[ÜhYÊTWÀQYÂ\aÂT\¿P\Æ\fÈflÃ`d¬M`¶]h¼XdÎmr×rlÒniÒjhÎefÎnpËfj¼[b¸XdÄbjÊdiÈhnËjqÍnrÎmkÁ`lÎnrÔutÑzÓw~Ó{~Áh€«Rvºn‰Èo|Ín~¾]s¶Yu°Tq¢Ll›Ff—Df‹?ks&\N|À‰¤Ö” ÙŒ˜Ø–»l’¤hš¦lš f™œiš™e™†J8^–Jh®a{°b·p‰¡Vv“Lq‹Cjl$Nw6]h$WŠFd„FpQIw4VÅ…•̈‘ۦ㮛׎€Ô‰€×’ŽÙ§ Ü¶«á± ä¼¦ã¾¬â¼«Þ¶¦Ý¸¬à¼¬Üº®Úº®Üº¬Úº­Ø¶ªÚ¹°Ü»°Ü½°ÞÀ´ßÀµàÀ´ßÀ¶áÁ´á´á³á´ãÇ¼ãÆ·ãÁµâøãÅ·âøäźçÇ»éοæÇ°Þ©Î‚Ànc©QRŽ2E“:M—?NžBS¤BVµ\kцŠâ¶¬îѸéÔ¹LOO:N 9X?\=_>\;`<]9Y9Y:c?iCbA[B\In%R˜LjÁp~Ó}~Ñ~|Ðx{Ív|Ì|Ó†‚Ô‹‚ÖÔŒ‚Õ‹Ôˆ€ÕŒ~Õ‰~ԌԊ|Ô†|Ñ…|Óˆч~Ј‚Ñ…|ц~І~Ј~Є{ЄxЃ|φ€Î…|Ï„{Ά}Ð…z̓xЈxÏw®@N«DP®BMªBQ¨@N¨JV§@P¬CR®FS°GP¶FL¾HOÈOQÔYVÝf\âq^æ~fè…hìkí•tìšví–qî˜vî—tî—vî˜uï“tîŠféião[Ñ\V³HQž7J*E$?–,Cœ2F¡6H§=K¥>Mª<Jª?M¬>I¯FQ²FM°=M°?L®FS°>J²@J±AM±?I²?K¸?E²@F¬<G§9D /Cœ,Páš~÷ƘúÌšù°võ¾‘ù¯uòžhå‹nátOÑaVáw[Ül`ë”bÖbT¹KX»KVÀSZÁ^bÀT`ÄcfÂ_a§FX²RbÁXeÊhmÓplÔllÐhkÎjlÍlmÊfj¼V`¼[fÈflÌ`fÊflËjoÈfkÃflÅ^hÍltÒz}ÐjnÒtwÓz‚Áaw¬PrÂx‡Íz…Çlz¹\w›Fl›KnœMm‹<\0Sy(Ps&Qo"\Iz©¦Ìƒ–шš¼~§¢n¡¤r  \Š”R|V}@vr;tx=y†Wu9il.dn2`t0`n(Uq+W^NUHXLQAUDJH]"Q¾‡”㸪ܞ‘Ï‚{Õ‹‚Ô˜œÜ´¤ã¿¬ç¿¬ä¹¦ã¼­â¼ªÞ¶ªÛµ©Ý¹ªà½®Þ½­Û·©Ü¸ªÙ¸¬Ù·©Û¹®Ý½®ßº¯ßÀ´àÀ³ÞÀ·àÁ´áÀ³àÀ´âÀ²ãÅ·ãÆ¹âĶäŹâÅ½ãÆ½äĺåÈ»æÆ°ß¯–Ïw¼po¬NQ˜;G“6G”7Hœ8Gœ<N¥FZ°TfÈ‚Šà®¥êƲêÓ·¾‚T:L 9T:X<_B_=]<^BX8[8`8c>h@^?TD^Hƒ<a­_rÏy|Ò€Îx~Ëv|Ëvwу‚ÖŠÔŽ„Ô‹‚ÔŠ€×ŽƒÕ‰~ÓŒ‚ÕŠ|ÖŒ€Ó‡~Ò‡~Ò…|Ò†Òˆ€Òˆ}Ò‡Ò…~І~Ñ„zІ}ЇzІzÌ…~Є|ЈxÏ…|·{Î…{Ð…zÒ‚v°BQ¬BNªET®FPªEQ©BN¨DNªAN®BP´FPÀFJÄFNËKNÔTOÝh\äsYè~dé†iì“lí˜qî–qí—qíšwí–xñ—tì˜uï’rìkæ~gâp`Õ^VµLN4FŽ.FŒ&A•.F™1E 7K¨?L¤>K«@M©?N«BN°BP°BL°?J®BO±FP°=H°=J²?L°?J³BJ¸<F³=G®?H±:C¦3Eœ*KÕy]øÕ¬û¹€ø¿‹÷°xô¼—ø³nî›qìˆXÔlVÛeSËSPâ€`ÝhRºNY´JU¹LX¾R[Å\`Æ\`À[_¦BU®Nb½YgÈfqÒqnÎhjÐhhÏfeÒkjÊmn¸ZgÂdnÊ`dÀhqÈdnÎllÌkpÄcm¾ZbÌjsÐptÕutÐnuÊlyÁ^q§Rp´i„Ên}Ìq~¯\|˜Ah Nu¨UqœBe–Bg¤Pq P{ˆ;t„C†Ž^–œb“²lŽ©l•¤x¤h–P~v0gh*bd$Xh'et8tŽd–€N~b Xp6kk+b^LZEYER?SGSGK>JH\"Všn‹Ö®£Ù–ŠÉ}€Ï’•ذ±ß¼²ä¾­å½¨ã»ªâ¸¦á½­Þ¸§Þ¸¬ß¸©Þ¼©á¼ªÝ¹©ÜºªÚ´¦Ø¶ªÙ»°Üº­Þ»®ßÀ°ß¾²áÀ²àÀ²à´ྰྮ⽭åÇºåÆ¸äÅ¹æÆ½æÆ»åǺãÁ¬Úª’Çvd®XTžDM—>L™@O˜9J™:G›9H¢@P BW±Xd̃‰Ý§è·¤î̳ßìv/BY$IR=X=[Aa?a@\@\?V@a@h@g@aAX@O@bJ–IfÀoxÏ~Íz}ËvwÊsxÐ|{Óˆ„ÔŒ…ÔŽ‚ÓŽ…ÓƒÓŒ‚Ô‹€ÔŠ~ÔŠӌҋ~ÔŠ‚ъЇ‚цω‚Ò|̃|υΆ€Ï†~Ї~·}͆}Í„{Ì„|Î…{І|φ|Ò†zÒƒvª?P¬EP¬EQ®HQ­FP¬AO©DP©AP²DN³@KºHOÅIOÉJNÒVRÛf\àr^é~`êŠfì“pì“píšrï–rî•tï˜vî”tîšuî“qíŠlæ‚lârcÖ^R¹KQž0F&B‹)A”1Fš4Hž8N¢=N¥@P¦>L«CR¯AM¬>J®<J°BN°AP²BM²=J°BK³@L°@K´CMµAH²DK­>G­=E¥5Cž,IÀZNöΟúÉ–üµzô¾˜ü¾~ô³Œò¢jæ„eÛeVÊPLÑbTÒ^QÍc^¾UW¹T`»R]¸NZ¿U]Ädg«FR®Rc¹Q^Â_kÔjnÏhmÐhmÏfjÌhkÊfh¸U`Â^dÍdjÊflÎjqÂeoÊdkÉjqÆ`hÄdpÓnrÒrrÒlvÒntÆdt£Io±ZvËo|Ìn|´`€˜Rv®ZyÀhz²Qh¦Jx´fжj’¡^Žƒ8m|1i~Bt„D}‚>pšh—^…€9qv6kr4ke#Xh"`‡R†…X„k,Xi+bj,hm0dr5hWKRCN?K
+:RQONNQŒ`‘µ†ŒÛª“ÏŠ}¿xЗ޼µäðæÄ±åÀªä»ªà»®Þµ¦Þº¦Ü¶¨Þ¶©ß·§Þ¹¨Ü¹¬ß»«Ý¹¨Ù¶§Ú¸ªÛ¹©Ü¼¯Üº¯Þ¾±ß¾²Þ¾²âÀ°à½´àÁ´ß¸©â¿±çÉ»åÄ·æÇ¸çɼྤЕ{¯\VœEN™;J;I–<NCS˜<Lœ>Kž<M¢DR®Ta¸dqΉŠá©œæµ¢êÀ¥á¼ž“PTR;UBV:]@b@dC`=]B\DZ@^<hAf?\>SDQBr*S¨XnËwzÑ{xÍx{Èw~Ëx~ÒƒÔ‡Ö‘ˆÔ‹ÒŒ€ÔŽ„Ô‹~ÖŠƒÓŒƒÕŒ~ÔŒƒÒ‰ÒˆÓ‰~ÑŠ†Ï‰…χІ~Î…Í…€Ï…~΃~Ї~Ά{Ï…}ψ{І}Ï…|΂xÏ‚xÎ…xÑ„y¬CP®DN®ER¯HP°FN±BK¬BL¬=J®AM¶JR½HNÄFKÌLLÕWOÝcTàr`ç|`çŠnì•lì–rì”tí”tí—vî˜qð–pî—sî•sîŠlè€iãp^Ô`X¯GN 4F.D(B–2G›3F¡<J¦>L¥DQ­>J­?M«DK°BJ¯BJ®?I°DM²AL±@M­@K°BP¶?I²BK°<G±?L­<F­;E¨4Bž,F«9Kô˨ûÇøÅ“ü¾€÷·‹ýº{ð¦ví‘aÑ]WÌQR¿INÌqlÓk`ÄdlÄS[Ä[c¸S_»Z`°NX®MZ¾S_Æ[dÔlkÒkpÒhiÐgqÌhkÈdf¸Ze¼WaÆ\`ÉdnÎilÌjqËkqÄelÁXcÆ`kÒlmÒqtÏjoÑhoÉm{ªIl²a|ÂizÆewÀ[r¢Px¨Vy¿a¯V}¨W†œO€œXxƒ=h}7il"Vt*\u-\t+eƒFyXŒ†N†ŠTŽ~<y{2p€B‚ŠV‹y<ir2hyAxm.cb$Uk>fn1h\!MVDM>C 9B
+:HD{Dlͤ›Ü ŠÈurÃv|Íš¤Ý¬œâ¼¬æ½¤â¾­áº«â»¬ßºªß¹¨Ý·©Üº©Ý¸¦Ý¶©ß»«à»©Ý¸¨Ý¹­Ú¸ªØ·©Ü¹«Ü¶«Üº¯ß¾¯Ýº°Ü¼±àÀ´à÷ãŵãÂ°æÆ¹éʺèÊ·äéƋr£MNšBO“9L˜9L™9J–7Jœ<L AOœ=M¤BR¥I^®XjÄ|ً榖캜꿠¸s`s):V9V ;V9Z>bAb@c@_=^?[>_Dd=j?eCX@PBXEŒ?dºj|Ð}Ï|{ÍxzÉv|΀~Ó‰‚׎„Ø‘„ÖŽ€×Ž€Ó‹†ÔŒÔ…Ô‹ÔŒ‚Ô‹‚ÒŒΊъ€Ñ‡ƒÑ‡~Έ„ψш‚Ј€Ï‡‚΄~Ѓ{Ї}І|χ~΄{Î…~Ï…|΄|΄{уz°BR­DS°FR°GR®FQ®DP¬?K«>I®@M·FP¼DNÄFLÈMPÔXTÜeYàp`å~gèˆgì“lì–tê˜sì–pî•qî™qð–rí–víoìŒnèƒgãoWÐ_ZµGN 3F)CŒ,B—0H›/Dª:G«<K¨=M«<H®@N°BM¬@M®BN¬=J°DP´BM°AN°>I¯DR´>J²@J²=H®>G®<Hª:B¤:E ,E¤/Gíµ€ùÌ¢üÁöÀ”ü¼ö½’ò¥ræ‚dÚn[ÆKWÈY`݉zÒlnÚ{fÆW`Ê^_ÀY[¬N`§DT·UeÀZdÎgfÏfjÔnmÐjpËlpÃfl¶Yc¿\iÈ^bÈbhÌdhÇhpÇhpÆdjÄ_dÆ^fÎjmÐmrÕjnÐjtÄ[l­Ji®[yÂhyÄhxÈfx´T|N|®fޤ_˜T‚Ksv-Zk%RgNf RePhSlTx2m‹NŒ†O†’r£„EyR†Hz–iš~;nZ‹ŠX„]Lg(d\Vo@mwDyNCJ;OJD BMJŠ_|É¡™Ø–€º\d¾jvÓ¨¤á¼¨à°žà°šß°šÝµ¢Ü¸«à»­Ý¹¬Ü¶¦ß·¥Ý¶£Û²£Ýµ¤Û´¨Û¸¬Ý¸¦Ü¶ªÛ·¥Ø·¨Ø¹«Úº­Úº¯Ü»¯Ü¼±ÞÀ´â¾°â¸äÀ¯äÀ³æÇ¶æÆ²Ü´›³ji˜DT˜>NžBRš=N›>Oš9L—9I >M¥HW¬Vg±^o¿oyÒ†…à簤뾣èħ°tmZ7V>W<\<\>_BcAa>`=^<]AX8b>f=j AbEXDUJl&S¢SnÅt~Ó}xÐ|zÇu|Êy~Є„ÓŽ„׈ւՎ؎€ÓŽ‚Ò‡ƒÔ‹‚ÓŒ„ÔŒ‚Ò‹ƒÒŒ‚ÑŠ‚ÒŒ„҈ъ‡Î‡Òˆ‚ІƒÐ†€Ð…|Ï„}Ά}І~Ï„xÊ…~̆~Î…|Í„|χ€Ì…~Î…~³JT°IR°GQ³FN®HQ®BN¯>J­AK¯?L´DN¼FLÂHNÈJJÒWQÚdTás`äzbç†iètì•nî”rì”rì–rìšsï”tî—oî“rìŒlè‚gâp^ÖaX´FM¢6F1F,E–,Fš4E¢9J©=H§;K«=J¬>M°?I®@J®>J®BJ°@L¯DP°AL­;H°@H´BN±BI²;F¯<F¬<H°@H¦=Iœ6F™/MÚvúÉœøº‹û„ö¸‡üÆ~ñ§|ê…X×^XÔ`XÛwgØmjÖ|uÐ^^ÐspÄ^f²GV¬HXµM^¿T`ÍdhÐddÎlpÐhoÐhjÆfu¹P^¼]lÉ`mÆZ^ÊgnÍenÆhnÄgqÅ_hÅZfÒnrÓkmÐjlÓluÊap§Ffª\€»dzÃfyÌjwÄa~¦P|’KzˆHtu1^s.`~3ly0hv.`lQdLh"TjSt,dŒT’ˆJ{•pŸ‚Bs|>uj"T:lˆAv†O†’Xx0ev<{v=xXRlAer@tF >C
+<@@d,fn„Ö®—Ô†v´[fµfuÔ¢žâ¹ å¹œß®˜Ûª›Ù¬ Ø­ Ú¶¬Ý¸¨ÜµªÛ³¥Üµ¤Þ·¦Ù«œ×±¤Û·¨Ü¶§Ù´¨Û¶¨Ø³¨Ù»«Ú¸«Úº°Ü¼¶Û»°Ü»°ß¾±Ü¿¶Þ¿²à½²áÀ¯Ô«–º€x®p€§cxž@V >L¤APœ:L˜<Lš<M ATªMb¹hsÊvwÙ‡Þ‰|㙇訔鴖è¨͇g<VA]>[<_>`>eEd?fA^:^<X:]<dFj Cj'F`(PXL\N„;a·duÍz|Ò|xÍ|zÇtxÐ|Ò„Õ”†×’†Õ’†Ó„ÖÔ†ÔŒ~ÔŽ„ÑŒ…ÒŒ‚Ӏόъы€ÏˆÐ‰€ÎŠ…Ð‰‚͇ϊ€Ñˆ}Έ‚щ|ц{φy͇~ψ€Î†}Ά̓~͆‚Í€x²HX²IVµKX³DP¯GW®<K¯BN°BN²BJ²AR¸BJ¼FPÃIMÒYUÜbUàr^æzcç†nêrë”uê™vê—té–rì”rì˜pë•sî“pìŒnè‚gãr]Ô]T¶HN 8JŒ*DŒ(B“-D™4H¢<N¤<Nª>K«=I©AL©?J¬BJ¯>I­@K±DP°BM®BL®AJ­@L®DL°?N²<I²@H®AL°BH¨<G¤4Dš'G¿_NøÐ¬ûĆõ¸ú»ö²…õ®rä†jâ~\Ö\SÌdkÖwuÚvgÔ€{Ðe_Â[g¦DU³PcºO_È_dÒjnÏfgÍbfÍloÆbf¾YbºZfÆ`iÈ]fÆ^hÊckÌjnÅdk¿ZgÃUaÎnsÑuxÍhnÎkmÐbjÅ`t™7`¾i€Èj|Éhx¾TnžDo†7lp(^n&Zz3l…F}~;qq0^e MaHbJcNm Z‹L‚™b–X‹‰R€s2b]D`Sj(X‡Tt5h|6jIƒx=m^"RM EiDnb)ZB?< <YN©yˆÙ¡Ð~m·^n½v‚ר ã°–䶠߬“Ù¤”צ›Ö©ŸØ±¤ÛµªÛ³§Û³¢Ýµ§Ý´ŸÚ®ŸÚ²¡Û³¢Û²£Ü´©Ü´¨Ûµ§Ú¸«Ú·¬Ú¸¬Ù¹­Úº²Ý¼°Ý¼²à½²âÁ¶à¯ذ˜µ|u˜NhRm«vŠ®k|¬Vg¤BP¨BS¡>T£J^´ao¾ksЂ|܉|ß‹z唿—柎ꬔçÀ¤Ã“|m#>T <Z?^?^?`=fCeCiAb?^;[;Y=]8f?j"GbD`(T\%Tk(TŸRnÈt|Ò}{Ð}{Èz|Éx}Ò…€Õ„Ö“†Ø‚ÔƒÔŽ„ÖƒÔ†ÔŽƒÔ‹‚ÔŽ‚ÕŒ€ÒŒ€Ñ|ӌЌ„ÎŒˆÐŒ‡Ð‹„Ή‚Ά€Î‡‚Òˆ~Ï…|Ï…|Ð…~Έ}̆χ{ІzΆ~Í{Ì‚zÎ|±LZ´FPµJV°HU¯EP²FP³GS±BQ±BL±BN¸BI¼ELÆLNÒVQØf]àtaå|cç…dêŽpê”sê”mê”uì“së”oî”sì•qî’píŠlèeãs\ÕbX¸LSœ8IŽ,DŽ+F•0Cš2H 6D§:G¦<K§=J¨=L®?L¯?L®@M­<J®AK­@K°BK«@J¯CO®@K±FM¶>F¶BK®BK°BI¬>G¢:E›-E¨8Kñ‘ùƘú½€ó¯ˆø½ƒñ¬|ò¤mß}cÊmjÇ\ZÚ€uÓheÞyeÂhn¯HY®EVÀVbÆ_kÍnrÐfhÑhnÎjkÉen°O`´WhÄ\hÇboÄ^hÌ]eÉ`fÇfnÃ`h¼ZiÍ_hÒjqÐgjÒkmÒjlÏirÆhz>dÀh€Èfv©Mo‹>lv,`fRg!XŠJ‚‰Lzl'SdL_LbL\DfQ]L„;užj›œ]ˆ’Z~v2`]FX F`N‡[Fyl,eI|€LzXFJEHB|WŒqAƒHHg/Y®~†Üž‡Érl¼foɆŒÝ³®â·¢ãµžÞ¯œØ©›Ö¦ŸØ©œÙ±¥Ù±¦Ú±¡Ú°¢Ù²¢Ù±¢Ú±ŸÙ¯žÚ®šÙ¯ Ø³¢Ü´©Û¸©Ú²£Û¶©Ø¶¬Üº¬Üº®Üº¬à¾°ßÀ³Þ½¬Þº¢¿ŠzŽFX‚B_”Xv˜Vv«uвxŠ»ly´`o¾hoÉmjÒzà‹zâtæ‘wå“vá|æz蛄馒ìÀ¤Æ‘~g6T>X<^<^=_<fCdAc@h@d?\C[<W8`7j@l!Bg!HZH^I€3Z²duÎx{Ï|xÎ{|ÊsuÏzxԀד„Ö‘€Ö“‚Ö‚Ó“…ד€Ô’…ÖƒÔŽ…Ó„ÒˆÓ€ÒŒ‚ÑŒƒÐŠ‚Î‡‚ÓŠƒÐŒÍ†‚φ€Í†ƒÑˆ|̇€Ìˆ€Î†~͈€Ï‰~Ј€Î‡‚Ά}̃΂{Ê‚|¶LX²GS±FU¯DQ°JU°DT²ER¯@L±BM°AM·CKÀAIÉKNÐTP×b\Þq`ä}hæ„lëŽqì’ré–së–qê”tì˜pì’sî•pî”rìŒrçhâr`Ô`X¶JP8I*C)D‘.F™2H 4H¦<J¨<I¨@P¬?M­<K²AL®CM°BM±@K­BL¯AM®AK¬BN®>I¬<H®=J²@H²BL³DL¬BJ¥;H/Eœ,JÞlùÌ¡ö»Žûº}ò®‚ú¼ƒî vçœxà„iÌqp×i[Ú€sÍ\XÄ\^³LUºPbÆTaÔhkÒihÐilÐceÂ`j¸LY´L]Â]iÄ_jÉcgÉcmÊfj½ZhÅ]e¼Yd²UoÈnÈiuÊdrÑelÔhoÕr~Ên|§Fi»`v®Sl{0Zj$WdTw2i‹M|v6_^FXEZDdN`F\D`N\L‘Wˆ–W‡›Pt{2]^HdPbR‰W‘\Šo*`y;tz@q]IJ >RNI?€[f3g|<k½‡Ú–€Élh¶_jÌŠß²¨ä¼«á¶¡Þ®™Ø°£×¨šÔ¦ Õª Ø° Ø¬¡Ø¬›Ø«Ô©›Ø± Ú¬›ÙªŸÚ°£Ú±¢Ú°£Þ´£Ý´¢Ûµ¥Ü¶¦Ú¸®Ü¹¬Ý½³Þ¾´ãÀ®Ü¾¦ÀŽv‚>H|<\‰Hk†=`•Uq”Nk¦j†´xЀ„ÝŠ€åˆuæŠrèxæŽwæxå|蕂Ⓜ蚋쪔îĤԣŒj!<P;W;[;`>cAf Cj Db?dAe>_:aA]=a>d;j?a9W<VFdL—PmÀpzÑ|zÌzxÉ{€ÉsxÑ€|Õ’Ù’„ÕƒÖ’†Ö”ƒ×”Ö”†Õ’€ÔŽ‚ÕƒÖŽ€ÓŒ„ӈςы‚ÑŽ„ÑŠ€ÐŠ…Ð‰Ðˆ‚ψ€Í…Ή~·‚Í…|χχ~ÌŠ|͇~Î…z͈˃z΂|Ë{µLX°MX±IT°FS°FQ²HU²HT­AM°CP³EK¸BI¾FKÁKMÐTQØ`Xâp\æzdéˆgìŽjì˜tì–pë•së”sê–rì–vî–nï”níŒpébáp\×`V¸LPž8F)DŽ)D•/Fœ7I¢6J¦:N¦?N§=L©?M©=K®@L®BN®BL±DN°BJ®DP®BM®@J¯AL¬AK°=I°CL²BL²CN±CM§<H¢3Gœ.MÊq[÷Ò°úÀ€ö´ŠúÁ‰ô®~ú¼‡ê˜p߇|å™t×rhâŽsÇ^]«AL¶P_Ã`gËdkÑknÎfmÔljÈen°JV«F\ÀWdÉ[cÈ`hÅ_jÆ[kÇ`iÃ_l¼Vd¼Wb»ly´dpœMhB_ªF]ÉasÖpxÊjv¤Dd’Bbv*Uh0^g$Zx8h„Ami"Pb$R[IWAh#Ph"OU :]FaPz;qšlšx.Z~4_dH\Gh X‰W‘”g“‡D|@{R‰TEO>i4vF @QJ„XŒƒKoÆ‹†ÚsÂdf¼hqÌ’–Þ­–廤⼨ܮ™ÙªœÖ¦›Ö¤žÔ©¤Ö®¤Ø­¢×«šÕ¨šÒ§žÔªšÔ§šÖ¨š×­œÖ¬¢Ù¯¤Ú±¤Þ¶©Þ¸§Ü´§Þ¶¨Üº­Ý»°ß¼ªá¼¢Ì¤ŠŒIG‚<YaI};X l‡”Sx—Tp˜Rvaz²|Ó‡†à„æŠwåxçtç‘vçvå{阃è¡î³•ðÄ Ó£Šv(=R;V<V 8Z8b?b>d<jCdBdAfE`:^;]:^<e?g@^EVB^Os*T¬]qÎ{~ÑzxÌwzÉxzÎ{yÓŠ€×’Ø’„Õ”Ö’€Ô‚Ö”ƒÕ“„Ö‚ÔÕ‚ÕŽ‚҆ӂЊ€Ð‹‚ЊЉӋЋ‚ЊЈ‚͊ψΆ€ÌˆÎ‰‚̇͆̆€É„Î…~΄|Í„Ìz²JW´JR´IR²IR²FQ³FP®EQ®EP³DK³EL³AJ¼BIÁILÐVTÚbWáo_æybç†lênë–pê–tì–ví–xì–rï•qî”pî”pìˆlégâr_ÖbYºNR 8IŽ(@+F’-Fœ7L¢;L¢<M¤?O¨=Jª=Qª>J¯@K¯@L«?K¯BM¬@K¬>K¬=I¬>J®BM¬AL±@G¶CH³DL·EK°FP«@I§9Ež/I´FKîÁ’öÆŸüÇö²ùÄ‹ò¢tã‡p袄ærߌuØmUÄ^\¬ATÂZcÊ\cÎ`fÐinÐkmÎce¿Xb°Rbº_lÄ[dÊ^gÈafÀZh¸ZhÁblÂ\g¾U`ÎhoÕlpÖjlÍhp¸[sJl<c¦Eb¸VkšFeq(Tg%Xl-`{;ky0bm*[f"Xb ReLj%Su/^X<R ;\Fp)`†IvˆH{cGiMdOcP€FˆP€y4m]–Š^Šf&ZMGnF|nC{:>b6lª|¢Ë™”Ïzm¼_f¼cnÑ””߸­à²¢äº¥ß¹©Ö® Ö¦œÑ¤ Ø¨œØªžÔª¢Ù¬œÖ©šÖªšÔ¦—Ô§™Ó¨›ÒžÓ¨ž×±¥×´¦Û´¦Ý²¢Û±¤Ü³¡Ý¸ªÝº¬Þ¹£Ù¸ ¶‚jf;fD‘Mfˆ?jy,R­wƒ¢k†˜Tp¡d™Rr±t‡Ì†’Ú‰†âˆ}è’{è”|ê“vê—|êšï¦’î²–ð¿œÙ©Šv)BR9V?Y;^=^<a?f>c?e?c?c?d?`<[7_>`=g>d@]E^IdKA`¸juÍy}ÌyyÊtxËvzÒ‚|Ö„Ø’€×’…Ø•€Ö“„Ô‘€Ö”וƒÕ‘Ô‘ÕŽ‚ÕÓƒÔ‘ÓŽÓŽ‚ÎŒ„ÒŒƒÒŠÑ‰ƒÎ†„̈€Î‰€ÏŠω~Έ|ψ€Ìˆ‚Ά̆Ê„€Íˆ‚Í„{Í…|É‚´FP°JR³GS±IT°HU²DQ®DP¯BN´BO²AL°DMµFG¾FIÍOO×]Qân\æzcê‡hê’në•rëšqì’sí–zë“qî”uî–rî•uìŽsç‚nâr`Öe^¾KPž6H&BŠ$@’,F˜0HŸ:M¢8H¤;J¦>Lª?N¬;H¬=I­>Lª>L¯CL®CL­=L­>J¬>H¯@K¬>K°>K´EL¹EK¼FN¶DH±DN­>H¢9LŸ6NÎv[÷زùÂúÍ—õ´|ê âˆlì~å „äkÀ_]¨8H¶NYÏddÉdlÄ[fÌ`bÊfm½R_­CV»boÅ`kÄ]fÉbfÀVbºYf¼UfÅ[f¾WeÊckÑflÖnqÕlsÇjt¦Hf-N˜Fb‰6_x,X{:ft8kn+^y3i„?|p1el*^f S^Lm'VŠNƒ^CQ
+<R >bR~>vx;bx4b^DbGbJh$R‰N~t*b€Cy‡No1gP Go>x‹xªQLEHiÆ“ŸÊ{s®ZeºftИšá¸¦ç½§ä¸¥á³¡Ý´¥Ø¯¢Ôª¢Ó¦™Ô© Ö©œÓ¥›Ö«žÔ©›Ñ¥•Ò¡–Ò£šÓ¤˜Ñ¦œÐ¤˜Ö¯¡Ø´©Ø´«Ü¹­Ú¶§ß³¢à¶¥Ü¶Ÿ×©’´fY€.ElEf?FbžWn8a’Ld­}“š[x£m‚ž\{¦gz¾‚’Ð{àˆ{è“yê“xì˜yìž„í¢ˆò²”ê½–»rXo&:U6S 5X7]:a:a=f?d@d@hDf Dc Ba?_@\=`8b=e;b?Z@_Jp(QŸPl¼pzÊwxÉx|ÆpvÌyzÖˆ}ؔؔוƒÕ‘€×—‚Ö‚Ö‘‚ב€Ö“…Õ’„ÕƒÓԂ҃уԊьЉƒÑŠÐ‹ÎŠÍ‰†ÒŠƒÏŠ€Ð‰~І̊ƒÎˆ~Έ€Ì‡|Ë„‚͈Ë}Ì„{Ë‚~»NZ¶KT³KU³KZ³IU³HR®IT®BN±AL®AL­EN´AI¼DJÌPQÕ]VÞm[æzbéŠmëpí–që”vì’wí•sì˜uï•xî˜mî”uìˆhè‚jäp_ÚbY¿MNž4FŒ(CŠ&C‘/H›5H 6I¤:L¤>L¥>M«;I¬?K®<L®>H®<K¯<I¬:G°@HµBK®<H°?J°AJ±@J·FN·DK¸ELºIJ²FN²DJª>F¢3H¯BMì¶„úÔ¯ú„öƓ짆à„mè˜zìŸxä~Íe_®BTÇ^aÐgjÌdkËbhÆ^fÃ[d´N\¶TgÈ\eÊ^fÄ`lÀ\lÂYh½WjÂ[jÂZmÌ\lÓltÍclÈ]fÀUe¬Nd”@bt'Vm"Pv"S{4dq6dm(Z?q|;ko0`e&Xb PTD\IŒR…<iS<S@UAl(Y‹Hzq1_cFX@cHs'Xs)Vv,^aLm-]‚P‚ZNSKŽ«€bŽG Ej0lµˆ¡ª^r«\t¿lzÕ£ â´¨æº§ãº©à·¦Ý´¤Ú³¦×²¦Ö«ŸÔ¬ ÖªžÓ¨£Ñ«£Õ¬ŸÒ£›Ô£”Ñœ’У˜Ô¨žÔ©œÐ¦š×¯¢ÙµªØ·©Úµ©Ý´£Ü²¤Ý­žÚ¦œÕ“Œ±YfŽ2OŒ8Vˆ<^}.OJd–SlŠDlš_rªvŽœ\s¤iƒ˜Rq»|‰Ë€ˆÞ‚zæŽzë’|ë—‚î Šòºšç´ŠžTN\6W:V<T
+6Y:`9b;b<h<i Eg!Gh"Ci$Dc@`<^<\8_9e<e>aC\Fi"N‚4Xª^oÀrvÁnuÁpv¿ltÐ~|ׂ֓„Ø•†Ù”Õ”‚×”€×”ƒÔ•ƒÔ‘‚Ô€ÔƒÔ‘‚Õ’„Ó„ÓÔ€ÔŒÓЋ„Ò‹€ÏŠ€Ò‰€Ð‹ƒÎ‡„΋€ÏŠ~Έ~Έ€Í‰€Î‡ƒÌ…΃xÌ…€ËƒzÌ‚|΄}²HS´JT´JW±NX²MVµIR±GR­ES­@L¯AI²>H±>H¸CIÉPNÕ^SÝm^å{dè…lëpì•vê˜tí”yï–qì˜uíšuì—sï”qí‰lçiâubÖ`X¾JMž4G+D(B”0H—5G 0F¤8J¦<J¥<Mª>M¬AP®AO­@K°@L®>J°=I°>J°?N®<I²>I®@L°AL¶EO·FM¸HOµHL¶HN´CK¯DJ¨;H 2JÄaPöÆ”øÐ¥úÆŽó®€ç¦‰ç˜{쨂è¥{Ãg`¼cfÎ`aËagÈdlÌdoÃZg´Rb²TfÄ\fÌbgÍflÇalÃ`o¿Zq¾\r»UlÀ]xÎjxÍar¶Sp­Ss®Tr°Xr¨KlžHn‘<fˆ9gp&Xk$Y}6j‚Aoe%RYITBSC\Sz3l˜f‘t2\R :S ?YDo+]ŠIxr0^]?`BjLdDgNaNYIt?k~IO IX UŽ~®l6fˆKz–i˜Ro Oh§iŒÕ«ªå¸žä»¦â·¨Þ¶¨Ý¸¬Ú°¢×¯¥Õ¬¡Ó«žÐ§›Ñ¤šÕª¡Õ«žÔ­ Ñ¤˜Î˜ŽÎš“Ó§šÖ«¢Ó¨žÑ«¡Ô±¨×²§Õ°¦Ø²¦ØªÚ¥žå°§ê±¨è¢›Ø‚¬BUŒ-OŽ9P•Pt„<^ŒDb‹GeŠCgªt„¡f€ b}›Lm°l„ËŒÝè•‚í ˆð­”ñº’ᣉ8CX<W;Z;Y=[ 5_;c;i>f=c=jBfAk Dg=\<Z<Z<^=]:f>dD_Gj$Qt(S’Hd´hr¼ox¹ls¸jtÁptц‚Ø–‚×—…Ù’Ú”Õ’‚Ö’„Ô~Ô‚Ö‚ÓŽ€ÕŽÖƒÖ€Ô‘„Õ†ÖŽ€ÔÓ€ÒÒŒ…ÑŒ†ÑŽ†ÐŒ…Ћ‚ÑŠ‚ÐŒ~ЉЉ€ÎŠ~̈~ˈˆ‚Ά|Ì„}È~Ë‚|´N\´MR³LV´KU±EO±FR®HR°EO²CL®CP¯>H°>H·@EÇLLÔ\SÞjZãzhè…jëŽtìtì—xì–zî˜xî™vï˜vì—rî“rîoéhâs`ÖbXÀMQœ3HŒ)Cˆ(B.F™/Bœ5H¡:J£<M¦8I«BO©>OªBN®?L«?I®>L°BN°AN±?M®>J¯>N±BL¶DO¸DL·GL¸JP¹FL¹HL·FM±DN«?I£8L 5Rß•lúÒ¦øÄ’ò²ƒö·„彩ð®~Ú}o´=FÙybË^[ÆVZÈaiÆbp¾[g·ViÀXeÃ_hÈdq¿]w¿n‡»gŒ¼_ˆ·a‘¶V†°\†¼^Æb~Èa}Æ^oÃUg¡B[•=X›<b4^~.^t.d‚:nŠIt|@mb QUFQCS C_O‚<q˜h’dGQ<YCaMn*\v.Zq.[bHcFr$QbEbHaOUGzFz{;zTLuI†Œl£›`Žº”œlœ„6[®b~»‘¦â± äµ¢á¶¥Þµ¥Þ·§Û´ªÙ¬ Ö¬¡ÔªœÒ¤šÑ¨žÔ¨˜Ô¨›Öª Ô¥˜Ïž’Π™Ð¡œÑ«£Ô¯¦Ô¬¡Ñ«¢Õ±©Ô®¤Õª Û§žâ¦¢ç®ªé°ªé³¨æ«Ÿà‘ŠÉ]e¥>Pˆ2]‚4Tžb€–Rt“Lr–Sw `v¬z¥f~¤d‚¯k€Ç€ŒÜ‰‹î¤ò¶–ð¶‹Èv]€*>Z:X?X:X;^<a:e>i@h?f<d:gBe>h>f@^=]=`?^8b>e>dD`Hi$O4XŸWjºpu¼ns¯fr¯dpÄv|ÒŽ‚ו„Ø–†×—„Ö•‚Ó’„Ô‚ÔŽ„Õ‘~Ô‘€ÔŽƒÖƒØ‚×’Õ‘‚ÕŽÓ‘‚ÓŽ„ЌЃЂϊ‚ЈƒÐ‹Ï„ÑŽƒÐŒ~Јщ€Ì‰„ÍŠ‚˅̉€Î†~Ë…}ˇ€Î„~µKV´JT´LV²KW°FR²HT°EQ­CN®?N¯DM¬>G®<Jµ?FÃILÑ\UÜk\ät`èˆoì’pì•wë–tî–zí–yî•rîštðœtð”sïlè€hâtb×`T¿JR 6H*F‰(B’,D˜0D›4FŸ7J¤=L¨:L¨CR¨@N§?O¬>K¬<L¬?M°@L®<J®BK³CO®BO¬CO±EO¶EO·FL¼INÀHP¾LRºJP³JP²FJ¨8EŸ4N¼ONóÈž÷¾•ô·ˆó´‚ó°‚ñ¶ŠÍf`ÇghÙoaÆU[ÂPWÁ\d¾WaµNb½`lÇ`qÊ`jÈev¹]v¼^qºXl²Rl´^|²e†³^†¥U‚ŸQ{¦_ˆªR~ Bl~1]r%V‰6f{,[ˆ:j†:hŽDu‰H|p,\aN\KZFTFbOˆN€ŽU\CVCeH~Ev^A`HcHgRm!V€9m„>z€>z€>}p%c†XŽw8sk)lƒR‰†P¡_ƒ©l•˜]Ÿ`†Ê¦ËžªÞ°œâ°œÜ®¢Ý¯ Û´§Õ°¤Ø¬žÔ©žÓ§›Ò¦žÓ§žÑ¥žÔ§˜Ò¢•Ò •Ò¢–Ò¢šÔŸ•Ò¬¥Õ¬¤Õ¬¢Ñª¥Õ¬§Úª¥æ®¤éª ê¯¨ë´ªë¹®ê¹¬æ®¢â “×qr¼HUœ:N7^ˆ<T¢l„“Kf†?`€:Z¬pƒ©rˆ«pŠ®jƒÆ|Þ•’꧉ߑq§JIi9];Z>Y>Z>]<[8f>j>f>j!Fh@eAf@f>k?b<\;Z:b=`:f<f?^Ec"Lo)U?^­dp¸qr´iq®dn´kxÊ€}Ô“ŒÖ–ˆØ˜„Ö˜‡Ô”„ÔÖ€Ô’Ô’‚Ô’„ÔƒÖ‘ƒÖ’‚ÔŽÕŽƒÓŽÔÒŽ€ÐŽƒÐ‚ÑŒ„ЂҌ‚҃ы‚Ћ€ÏˆÏŠ‚Îˆ€Ê‹~ˈ€Ìˆ‚Ë…}̈Ì„zÌ„zÌ|¶LR´LX´NW´KS¯FT´CP¶FL±GP°DP¬@Kª>M«;E°:H¿JMÐ]YÝl[âzgç‡nêŒoë–xê˜tî”ví—vëšxï—vð˜wð–pðŽmè€hâvb×f[»LN 5FŒ&AŒ$?’+F—2Ež4F¡8H£9I¦;Lª>L©=J«?N¬@L¬<J®>J¯?I­BL­@M°>K°?L®@K¶EP¸EPºHQÀJRºLPºPT¼JP¶KO¸EK­BJ¤8K¤6Qè©„öز÷Á˜ôµ„ô´€ò»ŽÖxhÛu^Ì\[ÅY`¾S_½V]°IY°L_½YeÆajÄcqÂ^n¶Oe´Rb°I`Â]rÍbrÏ`pË\sÊbvÂj~§Xq’Fop%Yp%V|/dr&X„0aƒ0`‚9gŒFt|;km.Zd"PdLXJVGj$X|7j€Ani"Tf Rn(Sp2^[?^>aB^@` EaCi"Lf$N^FbJ|Auj)Zn,dyAt}A€†L‡¤z¨š^ŒÄš£ÆœÒ¢ Ûª–ܦ”ؤ˜Ö¬ŸØ°¢Ô¬ Ô¤šÑ”ÒžŽÒŸ˜Ñ¥Òž’Ñž“Ó¡“Ò¤šÓ¢šÒ¢™Ñ¡šÑ¤Ï¥ Ò¦¢Úª¤ä²¬è±ªê°¦ê±¨ì´©ë´­ï¶¯ï¼¯í¶¨ë°¡ãŒ„Ô^b²;J’7Ox-Xn,Hœa€„:[~8b€Aa®vŒªq‰¯p‰¾}ŽÖЉÐqn¶XX€)F[ :Z =X;ZAY>]>a>f9g=h>j@h>j@i Bj@h A^9Z9[;`=b=g>bA^Cf Ly/VšOg¶jq¸ow°fs®hsºmtΈ€Ö–†Ö™…Ô”„Õ—„Ô•†Ô”ƒÕƒÔ”†Ó‘€Ô€Ô“Ö’Ö‚Ô~ÓŽ€Ó‚Ó’ƒÒƒÒƒÒŽ„Ò„Ñ€ÓŽ€ÐƒÏŒ„Ί~Ћ‚Ћ|щ‚ω͈}΋€Í„~Ά{Ì„zÊ}É…‚µHT¶MVµLV³GS³FR´HP±DP°CL¯BP¬@K¨>J§<H®;E»JMÎ[XÚjZà{hå‚fèrê’uë—vìšqê—xì–yïšwî˜zð•sîqé‚kârbØcWÂOQ¢6FŒ&A‡%A‘+C•1D–2F :L¡6H¨?L­=L¯?K­>L«>N¬?L¬>L®:H¬>J­@N¯@K°@M²BL²BPºDM»HP½GN¾JR¾PV¼MVºJQ·HO²BI¥;N¤5Pá—zúÑ™úÒ¤öÀŒöº†ö´‹æ›rÐibÂXbÆ^dÂ^jµJ^¬DX¶Rh¿`pÈ^kÁ]l¹Wj·Sj¸QeÆfnÑfnÑboÄ[q®FgªH`Ìgs¾\sžDjw*So,Zo*]dPi!Un!Vz1d…Ap~7gq*\g!VZFXO`Pp-bl$Zx4k‚?v>rh#NZB]@^<]=^>_C_C\>Z=T=R@l-ar*ZˆFtz;nm/nzK„”]‹™l–±~¾Š‘Ô¡˜Ú¥œÖž•Õ¥žÕ¨žÕ«žÒ¢—Ξ”Λ”Í–’Ò¦žÑ —Ï ™Ò¢›Ô£›Ó¡•Ò ™Ï¢šÏ¤—Ìš“Ϥ¡á°¨ê¶©í·¬ë°¨ê²©ì°ªíµ«ìµ¬ì´ªî¶­ï¶©î´žèœŽÝnj¿FO£6K-LkOr0JNo‹@ct'R f}¬nˆ´x޼}É€„Âhm´QSŠ(BY<X 9X>V;Z=^<gAh@h>jAl DjCg@jBe?a=^:Z8Z6`<l<f>_@`Hp'S‰=_«dr»qt·lp­an±doÁtw͈‚Ö”„וƒÔ”ƒÕ˜„Õ”‚Ö“Õ’ƒÑ˜ƒÑ‚Ô’€Ò‘‚Ô’‚Ô“…Ó’€Õ€ÔŽ„Ô€Ô‚Ò„ÒŽƒÓƒÓŽƒÔ€ÒŽ€Ð‹ƒÑŠ~Ј}ЉЊ‚ψЈ|·~͆|ω{Ì‚{ʃ΄z¶IV²JR´HU´HO±HW´FP®FR°BN°BK®BMª=I¦7F¨;J¸IMÎXSÚj[ávcæ€héŽoì’uë–wí’tî”wê—xîšví˜xî˜tðnèmãtcÙbXÂNM4GŒ(BŠ&@”0G“,Dœ1F£<N¢:N¨:K­BO°AL­AM¬BP®BO­BPª@P¯?M°AMª>K¯@O¶CK²DN·HP´DN¼MTÁQS¼NT¼KQ¸LO¼KJ´DL£:N¦2Nß–€ùÓ®üΖøÈšø¼Žôµzä†`ÆX\ÄZ]ÄZcÆ\d¸Td´RkÄ\g¿\e½Ta¶Tj·RgÉ`pÐlpØhjÒafË\hÆ\m«He¡Og²Sc£?Z•5X.Wt,dh#PcL[K^Ln+Z{4gx.dq(^y4hp)\d!U^Jw4m^Ot8pT†ŒM~k$UW:[=^BZ>]>^B^HZ@T<SATBx6hœQx Liˆ:gx9}Žo¦£~œ¸“£Ì™“×›ŒØ£›Ö¤œÖ¦ Ö¯¤×­¡Ò¦œÐ–ҙ͗”ÏŸ–Ñ¡šÒ£œÓ¦œÔ¦šÑ–Ïš‘Ò£šÍ¡›Ë—˜Ô Ÿç­¨ì°¥ìµ«îº¯ë´¨ì¶­ìµ©ì¹®îµ®ì¶¬î¸¨ðº¦ï±¢ìžàvrÈMU°<JŒ.Kl!HTCu4RŽGe|.]ˆA`©pŒ³p‡¾‚’Ë…ŠÊps²NVv>`>T;X :X:]=b<hAlCi@h<lEl An&Gl$Hf@`<^=Y;[7\7e;b<ZDcLv*S˜Nhµgtºpt²jq²bk¸ktÈ~}Љ‚Ó’Õ”„Ö–‚Ö”„Ö“‚Õ•‚Ô–…Ô‘‚ÓƒÔ‘ÓÔ‘€Õ„Ô’Õ“}Ó„ÒŽ‚Ò‚Ó‘ƒÒ‰€ÒŒ†ÑŒ‡ÔŽ…Ñ…Ñ‹ƒÐŽ}ЈЊ~Ñ‹~ÑŠ~Ћ~ωΈ}Ά|Ά|̆~Ì‚~²L\²HR°HW´HT°FS°JS±HP®>I±@I®?K©:E¥7F¦<N¸LQÌZVÛh]âvbã‚qèŒjì•xë˜vì–vì™xîšzï˜xî˜yï˜xíoèläudØf^ÀPP¡4H(FŠ%E’-H–4I7M¢>N¢8K§BQ«>N¬@P¬?N®DR­EP®AN¬AN®?M²?L¬<L¯<K¯@NµAN¸FRºHO¿LTÃMU¿MT½PV¼MP¼FK²DM¬=M©3Nà’zûÔ¢ýÌ›ûПúÈŽñ¨sÊRNºFPÀX_Ä^i¸Vf»VfÃ\fÆ\d¶We¬E^¸NbÉanÔjqÔejÒdjÒcgÄap¸QdŸ;X’1L•7P|Ht"M‡Btq-[^EXBUBWFaKz7lu,\q/a{:f>qa QXHu3d^Kd$YŠRŠ™g”|:kV<\@]>^BZ@V9XBS<M 7P@l'U”Np®_tŽ/R˜Bg˜_š¬ˆ¬·{Õ¦Û¨˜Ú£–ب›Øª¢Ù°§Ù±¤ÖªŸÒ£˜Î˜ŽÍ‹Í˜”Κ’Òœ—Ó¦ Ó§žÑ ”ÊŠÊ’‰Í›–ј–á¤šê®¤ì¶§ìµ§ìº¯í¾¯ì¶«ë¶ªë´¨ì·¯ì·°ð»°î¶¨î¶«ï± ëž‘å‡|ÒX\´9G’,Ir C^AZ>ŠHb€4Z~5\§l„¯nˆ»u…΃Êtw¬HRl@\>X<\<Z>^=d;d;j Af@k!Ej>iAl#DiBd>_<`A[9\:b<g>_>ZAbJ‚=`©aq¼rv¼pv³kp¯fn¸tvȇ€ÑŒ€Ó€Ó‘‚Ö”€Ö“€Ö’Õ}Ô“‚Ó‘Õ“|Ó€Ò|Ö~ÔÔ‘Ô~Ö“ƒÔ’€Ô~Ó€Ô€ÓŽ‚ІЂы҆ҊƒÒŠ€ÑŽ‚Ò‹‚Òˆ}Њш}χ€Í‡Ì‚zÍzË€}¯KV²LV±ES±KX°JV´JS¯GQ­FS¬BL«BN¨;F£;G¨8H¶EMË[[Øhbãu`ç‚mèŒtê’vê“wê˜vì—wíšvï—vî˜xð–qîŒnè€låtfÙ`V¾MQ¤2F*D*E'B™4Hž7N£=P¦<MªAQ®BN®>N®AN°CQ®@N¯@O°CR¯@K±?M´AL³@M³BL¶FP·FQ¸HP¿MRÄRVÀSV¾PY½NS½LO¶JR¯<Mª4NߌrûÒ¨üТýÊŠ÷Ì›á}Z¶EN¹CMÂVZ¾V_ºT`¾YeÆ\d»\m²K^´NdÆ\kÒflÐdmÎelÐdhÁTfÂWdº^oƒ*Jd:mD\Bn.Yy4]dDWAZCWCYHYJx7f~>jl$Yv2b‚Bs^ NVJu4icRUKv=w’b“šil'Z^G[@Y?Y=V;P :N 6L?h!M¨c|¥ZtšKo›?b¼€šµˆ¤ª‚¤¾Š£Ø¬¡Ù§–Û§›Ø¬šÚ²§Ú³¨×°£Ô¨šÐ—’Ê’ŠÍŽ‡Ì”Ì™”ÏŸšÓ«£Ò¤žË——LjˆÏ’“Þ›ç£™è©œê®¡ì´¬ì¶¨î¸¨ï¼¯ï¹¬ì¹­íµ«í·¬ð¸«ð¼®ï½¯ò»­ï¸¨í¨œçŠ‚ÒZZ¸;Jž2JtA]>YBn!F†9\y.W›\r¶x‘»‚•Ê‚‰Çy‚.IeA^E]B^>]>_;e;j?l?k!DlEj Gp,Mm#Hl&Hc@^<]9_:`;f:c;Y<[Hk!L“Id¶jrÃvu·qs°fp¹kpÅ|}͆̅€Ð†|ÒÕ”€Ö”„Ö“‚Õ“€Ö•„Ö”‚Ó’Ò‘€ÐŽÒŽ€ÓŽ€Ô‚ÒƒÔ‚ÔÖ€Ô’ÒŽÒ‚ÐŒ„Ô‹‚ÒŽ‚ÒŠ„ЉЊ‚ÑŠ‚щ€ÐŠ‚ÑŒ€Ñˆ~·€Ò†zЇw΄~Ê€®HX±JV°KU¯LZ®JV®EP­FT®CP®AN­AK§?H¤;Hª:H¸JOËZZÙi^áwfæiè‹vê“|ì”tì—wì˜yí˜{î–yí”wî•yíŒpè„nâtcÙe[¾OP¡;I-H&@”*B—1E›5F¤@V¥<N«>N¬@N®CP°AQ°BR²DP°CR­@R°@L­>L°BN°BP±EQµHUºFN¹JR½JSÁLS¿NTÀNWÂNP¾JR»KN´@M¬8TÒr]úÖ³þÑ™ûÍ”ø¹‚ÉXN´DN¹FMºKS¼RX»P[»S^¾Te·J[ºRaÌ]cÌ\iÉZgÂOYËelÊVc¼Rf¾\n¶\n<^V@Z@hJ}=llI]@ZB[>X>\HXFd$R~9jx.ho%Xz9fr.bWIq:gh VQ B\RyCv¢wª‹Iƒ…Bx‚ExdQN
+8N:I
+8H ?^F¬lzÐ}z FfœJkÄ‚–ÙÀ…“škšºŽ¦Û°£Ö£–Ùª›Ù´§Ü¶«Þ¸¤Ø¨žÒ›’ϔʑŽÎ‰Ì“’КҨ ÔªžÒž”цێˆæ•è˜ê¦ê¨é°¢ì¶§ì²¢ì¶¨ð½®í»®îºªïº«ð¼°ñ¾±ò¿³ñ¿³ñÀ±ñ½®î°œê”ŠÙmj»ALŸ7JzBT=ZC^<…:Xx)TGf¼„˜Â‘Ï”Áuy&Fa@[>X@]:^>`?d:j<k>i@jAn%Fl"Dm#DkB^8^;]:]8b7d?_=\DbJ|2T£\m¼uvÀut·nq¶jpÁzyÉ‚|ʆzÉzÈ‚x͆ΊÒ~Õ‘ƒÔ•Õ•„Ô”„Ô”ƒÓ’„Ò€Ò’}ÓÒŽÕŽ€ÔŒ‚Ô’Ö’‚Õ’„Ô„Ôуҋ~Ò‹ϊЉ‚Ò‹~Ñ~΋€Ð‰~Ï‹~Έ€Íˆ€Ðˆz΄xЄ{Ì~z®DQ®HV²IU°FR®HR¬DO®DR°BN¯EN«ERª@K¨7F¨=HºIPÍ[X×i]àxhã‚pèxì’tì™wë–ví”sí›xî—xî˜wï”wívè‚jâ{nÚc\¼PY <M*EŽ">—/E˜1F5G¢<O¦:Kª>O®?N«BN²BN²AK²@N´EO°BP®@O°BO°AO²BPµEN¶EP·EMºKQ¹IRÀLTÂSXÇTXÃMP¾LR¿JQ¸DL±>RÀOTöÈœþÑžüÔœè›s¼FM¸KRºKQ²KWµLV»U\¶R[ºVd¹XgÉ`iÌ\aÍaiÊbg©BX¶Rg¸Od¶Pc®G_£C\‚7V[A^D7b„@i]>X<X<aE`?_EZFYHf"L|9np)Zo*Zn,\d"Vs<ml'[^O^Xk._ž~¨o)VbDd FZ?O:G 6G:X@§n|Ôx¾Td²Tkƈ–ܦšÚŽ‡ÎŒœm›ª‚¦Ð«¬Õ£¡ØœÝ¶«Ú¯ŸÜ¬ŸÒ¢›Ð˜–Ì’“É‘‘ÉÊ—”ЧžÖ®¡Ò™ŠÕ„€àˆ„å’‹è–æŸ•ê¨›ì­¤ì±¥ì¶¨ì´©í¹ªï¾²í½±îºªð¼°ð¿±òÀ²ôǹòǺôÅ´ôĶð¶£î á{xÆKP¬8IŠ&A^ :T?[Bu%H0^‚2Y»”‡–Жœ¼q}x D_<`>Y:b@_=b<e@f@i@h?j CiDp'Fo&Je=\:\8]7]8d9e>\=ZEj!PB\²iuÂxv¾qp·jq»ptÇ‚€Î‡~Ë…~Ê‚yÊyÌ„{ǃ}͆€Ï‰~ÑŠ€Ò‚Ô’ÐŽ€Ò€Ó€Õ|ÖŽ~Ó€ÒŽ€ÓŽ~Ô~Ô€Õ“€Ó€ÔŒ„ть€ÑŒƒÎŒ†ÑˆÐ‰Њ„ÑŠ~Ћ~ÒŒ{ψ~ψzЇ}Єy΃|Ìy®EP®HT°FT°IU®HT²GS°FQ®EQ«@K©DP©@N¨:I¤<NµJRÊ[\Ùj]áwbäƒmé‹sêtì–vì–wí–{ì˜zî›vì—yï™qî‘pæ„hãveÚf`ÃRV¢:OŽ,H‹(B’.H˜.DŸ4G¢?M¤=L¨>N­BO¬DQ®CO®CP³DR²DR²AM°EN°DP¯CR²BU¶DNµCOµ?M¹GRÄmuÂRUÁPUÄRUÀNTÆPRÄLQºIM²>O¶>Qì¬þÖ«üÓœÞj»PZ½LPÂSX¿S[¹OZ¼PX²FU´L`ÐhjÌbdÆXdÆT^¸T_’7Wƒ0QŒ9\‰0T}$L‚/Q‚3VkJ_G†Do{1^X<V=X>k!P_Aj"N\A\E\Bl)Ts/`h"Qg#Wm(^{<nj$Yf,^]Vc$V˜u›s.`V>S 8M 8K 5E5O>šZiÖŽxÀSa»SgΉ“߬žÛ”ˆÚ†ÕŽŒ©v™¥„©¸›«Ä–£Ôœ›Û´©Ô¤™Õ¨¢Ò›—Ñ›šÐœ•Ì–“Í••Ïœ˜Õ¦˜ÒŠÖ{zãˆäŽ„æ˜Šèè¦›ê¨œì²¦ì²¥î»°ì¶§ì¼¯ï¼¬î¼¯í¼¬ð»­ð¾±óöõôóÆ·ôdzõÇ´ò¾«ï¬šæ…{ÏV[´<H˜*Ai9P ;X<hAz.Rt&T©fzÆŠ—Øœ™¿z†v"HbCh@_?h>n?j"EeAfCh?hDl Do)Jl%Dl @b>^9]>_<c>g=c@W>\Fr(PVh¼u{Æzt¼np´dpÂ{v̈ЎΆʆ€Èƒ|Í„~Æ‚~É~È‚€Ì„€Î…~χ΋‚ÑŽ}ÐŒ€ÐŒ|Ô~ÒÓŒ€ÓŽ€Ó~Ó’‚Ò…Ó’†ÒŒ‚ÐЂԌ‚ушЋ€Ñ‰€Ðˆ~щ|Òˆ|Ї{Ñ…{І|Ï‚|΂|Í|µBQ°IT°IT±CN°HT°GS°DN®DL­DN«ANª>L§<I¦=JµHNÌXVÛjaávdä†qæ‹sê•tì–uì—wì˜tì™~í›vì˜zï—vð’nè‚nãvf×d\ÀPW¤<N-F*D’+B˜0F¢0E¡9I¢<Lª?Q«CQ¯FT²DR±ET±IX²DS±GR´AN±@R®CP°@N°@Lµ?P¶HXÈvpÞ„hÄJO¿MTÃSXÆOPÆONÀLP¾JM·FS²DZÔu^üܶûÓ Ùn[ÃOR½NVÃXYÄW\¸Q^°@R´L`ÊgiÎahÈ]gÎgp·Ul™Fh—Bb€2Y€5SŠ2Rh<u!Ez!F[D`FŽT„l$MVAU@^Jr*VaIgKYB_DfL\FbKi&UaQdSCw„C|‚J~aR]PVv„L}R;N 9L
+6I <M>NgÒ‰yÂaj³QeЃ’Ý¢–ÜšŽØ”‹Ø‘‰Ó”•­{˜³¤Ì¦¡¿— Ò©¨×¶¬×³¨Ö¦ŸÐ—”И˜Òœ–Μ˜Ò“Л”Ó…|Ùyzá‰†ä‡æ’‡å˜‘èŸ•ê¬žê¦šî²£í²¡î·©î¶§î»¬ðº®í¼®î»®ð¿°ñÄ´óĸóõóǺõÅ´öɸôÀ¬ñ°žê“ŠÙbd¾AJž,Dr?V@T:] :jE}+\ŠC`À„–Ò•˜ÃƒŠ†7Y`HdDZ>`Af>h=fBi BkEl"Jl"Fp(In'HiAaAZ<\8b<d?iAbAU@XCy2V¨cqÄxvÄspºlp¼otÈ‚~ÔŽ€ÒŽΉ~Ì„}Ê„{É„~Ê|Ê}È€~ÉzÈ‚~È€|Ê‚}Ë…|Ì„~ÎŒ|Ò‹}ÐŒ€ÓŒÒŒ‚ÐŽ‚Ò}ÑŽÐŽƒÑ‚ЅЋƒÐŒ‚Љ€ÑƒÐˆ~χ€Ò‰|Ò†zΈ{φц}Ò†‚Ά~̓΀|²HP´MR±IS¯LS®FS¯EP®EP«FQªBO§EQª>J¥:I©;H¶JPÌYVÙj`âtfäƒkèŽsê•vê–zì–xí™zí˜yí˜uì™uí–wí’pæ„kàtbØd]·QX¤?S,IŠ*F–.F™2F£6H¨<N¨AQ­DV®BR²CS°GS°IW´JTµDQ°FS²DN°@N°BN°@Q°BR¶@OÆZYÕo\ÂPTÄNRÄSXÀOTÄQWÆNQÂSXÃRX¼LQ·JW¾T`ñº‡ù×®Ù~nÄMPÄQSÃQVÅQS¾T`¸MZÆ]dÈX^Ë_cË^kÖetÑco¾R_³J`£Fb‘8ZkG^BbCX?V?eI‹P~dCU<ZCt0\j MbKdKYB`IhMYC^Fk&VaLbRt3f’R†—b’v2nbVl5\‘g”VCF4D
+9J?ˆE^ЊvÎgk½XgÎ}ˆÝ¨›Ý™ŠÝ¨žØœ•Ö’‘Ô™°š¹Œ¢ÕÑ —Ö¬¥Û¶«Ù¶«Ó¢šÐ˜’К–М’ΗŽÐ‘Õ}zÞzwâ~yæ‹„æˆæ’‹æœ•é¦šê°¢ê®£ì¯¢í´­îº¬îº©î¸¬ï¾°ï½°î¼®ð¾¯òŵòŹôÆ·õŸõɸöÇ·ôÀ±ô¶¦íœŽÞmmÆDLŸ.D:Z;M6V :aA€4`z-SÃŒ Ð“”Ä‚„‘@[bH`B^&M^@f@g@hBjCj#Eg Dm#Hq*Jn$Eh>c>Z9]:`:f;j=[=WAaFŒCa¸lqÅyvÀtx»hjÄzxω€Ò•€ÏΌ͉z̈~̆É…}ɆȃÈ…€È€zÈzÉ|ʆ€È‚|Ʉ˄}Ë„yË„|ψÐŒ€ÑŒ{ҎҀЄЂцЀϊƒÒ‰ÍŠ„Ïˆ|Љ{ψ~ІzÏ…|Ï…~Ï…z΂yÐÎ|t¶FR³HT±IS¯FR®EQ°>N°BL®BNªBL¨AP¦:H¤9K©BN¹HMÌXQØh[àtbäjèŒvë”vê”uìšvíšyìšvî—vìšwî›wîræ‚nâu`Öh^»TZ¢>TŒ1PŽ-L˜3O˜4NŸ7O¦?R¨AT²ET±CR°CQ³CP²FP²AQ²DP±BN²BN²@N±@L²DPµDN¸HQÃPSÁPWÂNV¿RYÄPWÈTVÅRVÅUZÂQVÄRTÃRV¼KT¶GZÜ|bùÜ®æ›ÇTSÃST¾OS¹FQÄV\Ñ\\Ê\aÅ_hÆV_ÍhrÊ^pÄU^®DX¨B]€!IkD`Ij$PeGP<VAZA…JtcHZDaJcH\Bj&S^C]FeHaLZFh#TdNVDj%U‚>x‚?zw3c„F€~:€‚C~¢Ž°r2^D6E ;{5UÇ€xÌi`»WjÅsޫᖇ࢔ި—Ù¦¡Ù¡šÖ¥¢±† ²ˆ Ï“ŒÔš’Û°¦Þ¾µÚ¸ªÒš–ј“њ̌΋Ø|zß{zâƒä†‚æ†å“‰æ’ˆèœ“ê¥™ë¬ í°¦î²¨ì²§íµ¨ï¹¨ï»­ð¾®ðÀ¯ð¾¬ñ½­ñòòŸôƵôƺöȶõȹõÅ´ôºªî£–âyqÅHP§4Fˆ!@`:J 8S ;YAz0Wu&T‰šÐ“•€ˆ™AXl H`F^DbDl FeAhBl$Hl En#Fq$Iq(Hl%DfA]<^=]=b:d<b>V>YDt*TŸ\pÀvwÆxu½pr¿knÈ}}ÒÖ”€Ô”‚ӀЌΊ}͈zÌ„|ǃ|ȃ|Æ‚|È‚}Å~}Â|Æ€|Æ‚{ƃyÆzÃ~{Ã|yÆ‚}È‚}Ê„|ω€ÎŒƒÐ„ÎŒ„ΌΉ‚Έ‚ψ|Ί~Έ}φ|φ}Í„|χ~΄|Ë‚{Ð~wÒ€yÑ}t´HR²JS±HS²HR®DP­>N¯AO¯EP©?J¦=K¦<J¦:J¨<HµHNÆXYÖdYàtcâiéwê‘zê–xì˜zìœyëœvì™yë˜uî—zî‘tæƒqâug×f^»RY¢<Q0M/N–4Pš<PŸ>P¤?P¦<OªAS­AN«FR¯DS°CR±DOµDN°DR±CO´DO²EQ³CQ´FT¹EPÂMRÂ\eÂMQ½NVÂQVÈXXÆTWÊSVÆTWÉRRÆR[ÄPQÂKTÉV\ñ½ˆì¬ÎXTÆXWÂNN¿GRÎdbÍ\aÈ\cÐdhÌctÉZdÅ\hª<R¡>R…(IdMaNq/`€<lU<P:RAWFw6ez8lr)Tj"TZDf$Pg"R\C`IfLaG`Hr0]dNU C^F‡K‰o._u-`n*^VH^F™|›m+`B:n&LÀvsÎqn»UbÀevס”ß—„ß—Œß£ŽÞ±¦Ü®£Ø¥¢Õ§¤°ƒ ®|’Í“˜Óž–ܵ­Ý¼²Ó¦›Ð”ώΓŽÑ‘ŒÛ{zá€}á~ãŠ†æˆæ”‰ç•蔎霎ë¦ëªœì³¦î´¤ìµ©í¶ªî¹­îºªð¿°ï¾°ïÀ°òÁ±ò´òĶôÅ·ôȶõȹöɺöȶôÁ«ï¬žä€{ÏTX´<J–$?j:P;Q<UAfE|,Z°j~Ж˜Æ…Ž¢Ldp#JZA[@dBlCh DeEf!Fj$FiCq#Fq(Fj!DfC_>^<c=d@e>aAX@`EŒC_´l{È{zÂut¹nr¿qsË„{Ñ”„Õ”ƒÒ’~Ò“ƒÑ’Ï’‚ÏÍŠ}ɉlj~Ȇ|ʈ{Ç…€È„~È„|Å„}Ã}€zÃ~}À~€}ÀzÂ|zÈ~{Æ„€Ê„~Ɇʇ„ÍŠ‚ΊƒÎ„~Ά}ʃ|ˆ{Í…{͆zÌ…z̈ЃzуzÑ{Ð}z¯EQ±IT±FQ¯FR«ES®CR°AL®CQª=J§<L¦;H¨6F¦3H´FKÆZ[Üf[àvfå‚lèŽvë”|êšwê™vìšxêœ|íšwí™zî–oìŽoæ„nàtgÕic½OT¤<PŽ+L.J”.L›<R :O¤>Q§>P«@R¬BP°ES²BO±ES³CO¶FO´FT±FT±FR²FQ´BP´EP·GQºIRÌ^\ÃMTÃUZÄPVËUXÉUXËUYÇWZÅYZÇTZÅPUÆQWÈT\à}`í¡vÐZRÅTX¼ERÐ_cÔb`ÔfkË`nÍbrÍhyÀex¶M_™6Qm@bI`Ra!P‚Jzw6gV ?T?ZDWDbH…Hrk NVD]Fz<ifL_DbEbIZEk*Zl&Sk$VZF`Jl.\YEz6j`JL =N
+@wQpŠRŽbF³nrÒvl¾U_ÃenÓ—›ÛŒ|݇ތܢ’ß²¤Ú­¤Ø°§Ï¨£®†œ¤l€ÍŸž×­¦Ü·­Öª Îš–ÍŒ†ÊŠŠ×†ß|zâ€ä†…ᆅäŽç“‘æ–é˜ŒèšŽèšŽê¢”ê¦ší²¢ì±¤î±¦ï¶©îºªí¸©ðÁ®ð¾°ð¿¯ò¾­ñ´òŵóƸóĶô˽ö˼öË»öÄ²ð³¤æ‰‚×ac·<K /DvBXBRAT<aD…5c—NcÒ——Ó––žK^n@\>`@bBhDgDh&Hj$IhBg!Dk#DmCg@c@^?]<`<g?d>X;XBiH™NhÀtwÇ{tÄtrºnpÂ{{΂֖€Ô–‚Ð’€Ò’Ñ’‚ÒŽ|Ђ̎~̃΄ˌ…̉€Ë‡ˇ€Ì†|ˇ~ɇ~Ç‚{Ä{¼€}Á~~¾x¾‚zÀ~¾~Á}~Â~Ç€~É~zÌ‚|Í„{̓|̆€Ì‚|Ë…{Í‚z͆Ï…{ЂwЂwÑ€wÐ}t²CP®GR±FP­BP«EP®DR«BN¬>M­BK¨@L¥<J¨6D¤:H·HPÊYTÚj^àvfæ|oèŒwë”|ê—uì™xë›sì™|î›tî˜wí–ríuå…pázmØg_ºOT¢8LŽ/I*J–0Jœ8P :P§@Q¥>O©ET®DR±CO°BR³FS±ER²JS´ES´BS²DR³DQ¶BR¸FR¹IU½IRÀQ[ÀSX¿QWÆNPÇPTÆRRÆPQÃQSÄSQÃORÆRSÊ\YÐc_È[MÔq]ÃMPÄTTÊUYÖa_ÔkuÓftÂi‰µc‰±_¨Sp’8ZpE`Gr.cXBS ?xExh"SVBj-aZA^HU =bFz2d`J{:kz2^\B[=bG]FWAv8hbEx4d^GYEVEf YIz`OH 8F<XHU…¨c€Õ‚m¾Yc¾ZgÎ’Þ’zÝŒ€ÚŠÛ‘ƒÜ¦”ܲ¥Ø¬¦Ù°§Ô¬§À”ž¦k†ÊŸ¤Ú´§×¬ Ð™”ËÍ……Øzà€‚à€„ãƒ„â‡„âŠˆæ’Žè•æ“è˜Œê™‘èž•ë –ê¦˜ì®¢í²¥íµªï¶ªð»ªë¸®ï¸©ï¼«ï½­ð¾­ñÁ²òôôƶòÆ·öɸöȸöÊ»öDzðº©ê–‹Ûji¾DO§:Iƒ'FZCTAS<Z@‚<bŽ>\ΕœÖ˜˜œFZm!Ep$I]>cCh"Gi Al"Cl"Dn&Jl%Hk)Ii"Eb>`?`@b@e@f@`<V=aLƒ>_¨dwÂxrÅtoÄop½pwÈ}yÐ’‚Ô”€Ò‘Ò҂уϒ‚ÐŽ΀Ж€Ó”Ñ~ЂЂΎ€ÌŒƒÎ†{ˈ}ʉ|Å„}¾€€¾}~¾}y¼{ă}¾}|À~~½{~À|~Á|ÁztÇ|xÊxË~yÊ…‚ÊzÊ…|Ά|ψ{Ï„|ЂxÏ€xÑ€v²CM²GT°BO°IU®FN¬DO¬EN®=I­@J©DR¨=N¦7G¥;K³EOÉYYØh\Þvjãpèxê—{ê˜|ì™zë›xëš{îžsívï˜uíqè„jäudØf\ºNP¤;L“,G,H—0H—4Kž6K¥=R£ARªFV¬BR±ET¬CS°HU²FT³HV¶GRµFQ³BP³BR·FS¶IRºGR¼KR¿NTÈRXÊRTÂSVÂPV¼PYÀNS¹LR·LV¶KTÀPTÔn\ÂVHž8H±MPÁTV¿FLÔcbÑYdÐdz¾eŽ«_Œ®g‡­^|›Ib†.RZBl2`o)\M @L <€R†m(Z`Mj,[T>aHXBVFi SƒJ~…FphI[>W9fMZB\AFxS@f Or/ddPaT[Ge‘h&TG5F6M=†De¸o{¸T`¸TaʓܞˆÚ†|ۊ׊ԎŠÖ›’Û°¤Ø±¬×­¦Ø®¤Î£¤º†’Ч¤Ô¨¡Ò”‘Д’ч„Ý~€á†…⌌ↆᅆâ‹äŒŠç’è–è–Žé˜’êšŽê ”êœ”ì£˜ë­ í¯ î´©î·ªðµ¤ì´§î¶£í·¨î»¬ð¼®ïÀ°ð¾®ó´óŵõƶöȼöȸóÁ´ð¼ªî¥–ßtpÂHQ­9H&D^?P 9R>Z@|.U‰2UÉ‹”×›˜§Ziw&LgF_>aDjBfDhFh"Gn(Ip(Hn%Fh F]>]:b?b<e?e>\?XDdN’Ni²kyÀxwÀqp½nrÆsp΃{Ô‘Ö‘~Ô’ƒÓŽÒŽ€ÒŽ€ÎŽÎ€Î~Ï‘€Ò”‚Ó“‚Ò‘„Ó“…Ò”„Ï~Ί|·͉~Ȇ„€Á€|Àz¿‚yÁƒ}Á~|¾}}¼~z¾}~Àzy¿y{Àyz¿zxÀ}zÃ|zÆ}zÊ„̇~É{Ë|ÐxÍxÏ€y°DR°HQ¯EO³EN¬CS®@P­CL«=J¬?L©BN¨>L¤6F¤:I²DMÈYYÚibÝzqâ†qæxè”|é”zë™|ëœxìšzí›~ìš{í—uî’rè„màtbÚb[ÀKN¥;M’.KŽ(E–.G›6MŸ5N¤<R¨?Q­BPªFT®FV®@P°FU±CQ´ERµEQ³DO´GS´DQ¸DQ´HR¸KR¾LQ¿KPÆQRÊQPËTUÌVWËSTÌWXÊRSÌVTÌSWÐ\XÊwtž9R¶V^΄oÒ„ÃLWËVdÂ^ƒ°`³m޲]t¾T`Æ]b¨F[wL^R…S„d RI
+@NB‚WŠz9ldQV@\O]En)^o$\ˆM}=fs*ZbEU :X?hPVD`A|@nT C_N…JƒfTZGo>nk0TR>RGH <t2V¶rx K\FaÉ€‡Û¡’ÛŒ€Ú‡Ø“„Ö‰ÓŒ‡ÓœÜ²§Ø´«Õ¬¢×±ªÓ§£Î¢Òª£Ð —Ï”ŠÔ„~Ü~‚á††ãŠŠãŒŠäŠŽâ‹ŠäŒææ”Žêœ“è™’ê˜’éœê›‘ë˜ëž–ì¨šî«ší°¤í·¦î¶©ë´¥î³£î·¨îº®ð¼ªî½¬ð¿²òÁ²óijôƶõȺ÷ǸöÆ´ô¯ð©•ázvÈKQ¬8IŽ$Ca<S :S>XCt*O€.VÀ|ŠÙžœ¯dv~,Pk&JeFi$Kp*Nh"Fm&Ji!Fl'Jn(Ik&Hf@]@_BbBa>e@a<Y@ZEr+SŸ[p¾uwÂtvºmn¸hnÆ{vщ~ÔzÔ~Õ’€Ñ’€Ò‘„ÐŽ‚σЎ|Б|Ò€Ó“‚Ó•„Ó–„Ó“„Ò–ŠÐ”†Ð„ÏŒ€ÎŒ~ʈ}Ç„~Â}À„}Ä€x‚~À~|¿|v¼}¼z|¼||¾{{½{|Â{~½xyÀ{{Á{yÄ}}È~zÇ€~Í~yÐv΂|Ì„}®?N±HQ°BK®AL©CS¯@L®CK°?J¬<I¬@L©<L¥8J¢:N²FRÊVYØlfÞwmãlçzé“xë–vì—xìšzí›xìœ{îœzï›xí’ræ„iáwdÚfYÁNO¢:K‘0LŒ)H•-H™3J :L£=P§?R¬ER­BR®BP­EU°IX°EV²DT°BP°DN´FR±BN·@N²HPºHPÃLQÂOUÄNSÄTTÆORÊTUÌTSÊUTÈWXËUSÍZbÒ[Vâ–rÀ\NÍZOàjRíœhÐff»Wuª^Œµg…Æbs¾TaÈ\d»Udz"G\Lk,f…XˆZ@K BSFX†ƒJ~V?R:[DZHr,\†Ft‚<gt0\g"JZ>V>Z@dL[Ig(Mp2[S >\F†U‡`LY>|FvWF]VRLaE¶rxÅ_a¥;S¿w€Ý«šÜ‘~ݘˆÜ Ø™ŽÔ†ÔŠƒÖ˜Û±¥×³ªÖ±©Ø²¬Òª¨Ó© Ñ¤˜Å|kÀTZÍ`iÔqwÛxyß~€á†‰â‹â‰ææ••癒Ꙓ꜔ꞔëœê›‘ëœì¢”죕쮞봤ﳡﶦ︦ð¼ªñ¾«ó¾«ñÀ°ôŲöȸôƸõÁ²ó¿«ð¬—â‚|ÆNVž,F}Bc9U :R:V?kGw"P¶xˆÙ£ ºq{…+N{,LdHn,Nm*Ne Ef Hk$Eo%Ho*GjCb>^>bBa@d?f!E^?TBe K†@d«bsÂrwÁrsºlqºnsÈ€|ÒŒ€Ò~Ó‘€ÒÒ‘Ò~Ò‘€Ð~ЀÎБzÑ’€Ò’‚Ó’Ó˜†Ò•†Ò‘‚Ò‘ÏŽÏŠÌ‹~ËŒ}Ȉ~Æ|ƒÀ„yÀ}½~¿}{¾||¿~|¾{}Áy{¾{|Â{{¾y}ºwy¼z|Á{~ÂyxÆwrÉ|wÊ{xÌ}v±GR¯CO¯FR¯DO«@M«BN®@L®@M±>L¬AM©=J¨;I¤8H¯EPÊUTÖjfÞqfäƒoæŒxç”|ê˜yì™|ìš|ìœzî›zî›vì—vìqè†qâvdÚdY¿NR¤:L’.L‹*H–0K›6PŸ8N <O¤@S«BQ°FR±FR°FT°DR¬>R°ER²CP¯DP®BQ³BNµGT¸HQºJRÀLSÂQTÇPPÇTWÉTRÈSZËUTÊSWÈR\Õ†‡ã®‰Ö„dÀbPb:n6t:(=¼Zn²j•³d„ÇcmÅV]»LUÂRVž9TdJm.lu;g|KxL
+=NHb"XŒcv8iP :Y@`Dk"Pp&OdDaDeJZ;V ;X@]A^DaHf'N_GT Bh.`‚Oƒ^Kg&Zw7id$YQCQ>¢\hÍ}n¨DY¸]lݰ¢àš„Ý“‚ܢܪ—Ô—‰Ð„~ÒÕ›—Û³«Ú¶²Ü¹´Ü´¬×³¡ÌŸ„¦PJ•*>¢:PµJ^ºQ`Å_lÍhsÐjp×ruÝ€âŒå“’藒뜕렕ë’ꙑ階똌ëšì¡‘î¢–ìªžî´£î¶¦ë´¢î°¡í®¢ì´¦ï¶¤ïº¥ð»¨ðºªñ¾©ôðôôôðò¾­ð³—ꛉÚvqºDL…@p=a<W 7T ;T?lFw'W¤f{Û¦Á|…Š2Rp Dk Im&Jf"Jh)Pi$Jl*Ns1Rr0Ph!@d?]=a@`@e?fCY@XFk"Q•Nk¹ntÀtu¿ps·hpÀrrÌ…|ÔŽ{Ó‚Ò~ÓŠ}ÑŽ~ÑŽÑ‹}ÑŽ}ÏŽxÎŽ~Ћ|Ð}ЀтВ‚Ð’€Ò“ƒÐ‘‚΋͉ÍŠ{ÌŠ~ʈ€ÉŠƆ}ąÆ~¾ƒ}À|¿€ƒÄ€~Á€À€~À}~¾{z¼yy¹z|º{¿{|ºy{¿xxÀuuÁuxÃvv¯@P²CN®BN®BP­DP­CQ±AN°BN°DN¬@M¬<J¥;I¦<J²DLÉXVØf_Þwoæ‚nèsê‘yí™xîš‚ìœ{îœ|ïš|îœxí–sì”pæ…láxfÙdXÀQS¤:MŽ0L‹-K”2M˜6OŸ3J :M£?R«AR¬@R°FU²GV­HU±HU°ES°DT°DQ®CT´FUµCN¶FN¹HRÀJQÂORÆSVÈSTÆSXÉVXÉVVËT[ÎY_õ¾›Þ‰i¦<A|;Q 9Q <S Ar&Q¼x”Р°×§©ÍVZ¶BQ«FT4LkEeR~?s{N‚g%UOFPKu7n–ršn0^Q 6`EZ<_DaF`G`Hf"OYAX?bJZD\Ah$Vt._k#VbOp.jy<ldRl0`XEL >H 9…D[Í}q¯LZ¯N^Ôœ“ࠆߖƒÝ¡ß®–Þ´ ÒŽ†Î…€ÎŠˆØ¨§Ü³ªÜº²Þº±Ú¸§Ê€¬HP¨BW«K^°KZ¯EW©@NªBV›6I¦?U³K_ÃVfÒmrÛ‚ƒãŠèš“ꢘ뜔ëšêš‘ìš’ê•Šëš‰ì£’ì¨—î° í²Ÿê²£ëªœí­ë°žî²£íµ£ð»ªòºªð¾©ô®ôÀ¬ð»¦î®˜ã’Övn¾RX3Jx@j:a8X 6S;V ?iD{.^’Jeݪ¦Æ€…žLedIhCv,Qj$Ii"HiEm'Hr-Jm%De=_>]>b?dCb@fGXBZFx/W Wq¾ptÁvx¹pv¸gpÆz{Њ|Õ~Õ|Ñ}ÓŒ|Њ}ЋxÒŒ~Ñ{Ï‹z΋|ÎŒ{ÏŒzÌŠ~ÐŽ~Òςю~Ñ’Ò‘~ÍŠzˆzʇ~ÍŒ|̉{ÊŠ~ljlj{LJ~Â…~ă€Â††Ä€À‚‡¿~|¸z}¼{|½zy¾x{¼wz»w|ºx¸x|¶sz»rr¯BO®FR­ET®BR®EP®CQ°ES°@L®BL®AOª<L¢=N¢6J²BLÈWZÙj_Þyjå‚oè‹të’xì˜xï™~íìœxïxíœ~ðš~îsç‡mã|gÙh[¾NS¢6K-KŒ+L’0M—6Nž4M¥BT§<O«@R­ES°HV°DR«BS±CQ°IT²GT²DPµEOµCL´ANµGP¸FQ¼KRÁUWÃPUÇQVÊRWÈW]É[_ÈZ`Ñccð¤~Ò†r’6KtBe>T =gE Lk¾™ì•uâ‹fÂRX•+Hˆ-Mƒ+NhSj*c{Bm‡^‘RCQJb#^€D~pq6`M7W?R<g"Um3]b*R\Fl/Yc LV>dGX=V@XAr,\†H€dKt<vd(Ti%[f)_OAJ@n*LÂyp¾`d¤G[ÌŒ’ÞœƒÜ™„Þ¢Þª˜àº¦Û®œÐ‡Ï…‚Ò•™Ú®¨Ù´®Úº°Ú¶¤ÌƒxÈ[bÎdjØtyØrv×rwÌhsÂ]j´Q^œ<S‡">‚$@†$>š4H±FXÍjo݂斋ê˜é™Šé•陎疉ꗌì›ìª›í¯žî²¢ê²£í¨œì«Ÿë­ î¯žî² òº¡ñ¸¤ð¸¢ð¸Ÿê­”߀Ìrm¸X]®JX£<LŽ(D~=w:d 4[ 8T<TBdEr$U„=ZÚ¥¢Ì‰‹«YkgH`Bj"Fu(Ho*Kj#Eo(Il#FeB` EaE]?_?e<g"CeA\C^C„:\¬dsÄts¾px¸kq¶luÌ|Ô~Ù’~ÖxÓ‰|ÓŒ{Њ~Њ|ÑŠ~Ћ}ÒˆyÐŒz͈}Ή€ÎŠ~ÎŒ}Ë‹‚̀Ύ‚ÐŽÍ̈}Ɇ}ɇ|ʇ~ÊŠzʈ|Ȉ~ȆzɉƇ‚ÇŠ…ņ„Ĉ„‚„ă¾}}¼|}½{|¾{z¸~¸wz»w|µrx²py¶pt¶GQ¯HV²DS°DQ±HP®DO®CN¬EQ²DO®@Jª>J¦<M¥9J°ANÉTT×g^àujãlèyì–xë™vî•vî›}î™{í}ïœ~î™ví‘xè„mâvcÛi\ÂRT¡9L-H0O–1N™8Pž9N¤:J¬=Pª@P¬DR²JV²ER±EQ°AN®@N¯@N®BP²@N´EP²ALµEN¼IR½IP½MSÁRV¿QVÉRTÈTYÊ`cÑnhØibÙlbß„m³XRvB`:N ;RF˜LoÆovÆ\a£:I¤CV€ GŒ8T*SgTz?w|BugOVL\PyB|:{xMp|GtM ;QAXKr8cl%U\"Kh6_m.Xt0^Z@`BS 8T;Q
+:VBt6f|>s~Q‰U<y9t[HJ?TBªclÒx°KZćஙܑ~݌ਛ߷¦Þ¼«Ò›ŒË€ÐŒÓ¦¢×¶®Û¼±Ö²¡ÉqhÊT\ÔfjÛsuà{xÝuzÛpnâ‚€à~€ØlpÇXcµJY6L“-E†$>‚ ;Ž)A«CUÒpr㊀摆瑇é‡è’Šé˜ëœŽí§•î­î® í®Ÿì©œíª í´¢î°¡í¬›ð²í¦ä˜Ðvg¶UT¥EN”4KŠ1M˜8S¦FX¨BVª?L¡1Dt:f;W=U>^?p%S~<Xؤ¦Î…Š´eto&KeIaBu1Rs-Kt&Gs+Ln$Cd?Y;`?^>_?d@h"GdD^DfL’Fb´p|Ãtv¸lu·hrÁtt΄|Ö|׎|ÖŽ|Ô‹~Ô‹|ÑŠ|щ|Њ€Ï‹|ЊzΊ|ψvψ|̈~΋~ÌŒ~ÍŒ‚ÎŒ€Î|Î}͈|ÌŠ€Ëˆyˆ~Ɉ|ˉ}Ȉ|Ê‹zȈ‚ʈ~ËŠƒÊ‹…lj†Å‡„Ä„ƒ¿‚€À‚‚»|€¼|~¼{·x|ºu}³ry³tz³nt²BM­BR°GP¯CS¬JV±KV­FQ®FP±BL¯@JªAP£5H¡8J°BMÈTWØbYàwhã{méˆsì”yî›xî”sî›|ì™xï›|ðœzðœzî”xç…läxeØh\ÁQR¢:N‘,I1N˜1Mš8NŸ:P¤BQ¨>Q¬AR°JX±GS²BQ²DQ²BP³CO¯AP­:I°BO²?I´GR³DM¶DM¹JRºGN¿JPÀOUÂO[ÐfiÚ{vátÜojÝneÚ}j§VemE‚:Vp0SJB’Pv¿cqÂbo›1QŒ6RŒ7Ty"IhMp-b„M„t7p]R\Uv@w„Mƒ^Qh3Z”hšV@TDV@p)XcHSBWGn1`ˆKxk#OV8T 6X8X:Z?_"Qm7VˆY‡YDh*UL7G6†>V΄vÊb`¿lxÜ« Þ—Ü—†Ü¤’ݲ ß¾­Ù³£ÐŒ„·†ÔŸœÚµ®Ü½®Ö¬”¾^YÄRWÐ\cÏ]`×kk×ijÑjqºH\×vtãƒ|ÝuuÍZbÎaa³?P®?P¦8J›2H•/Iš2KµGYÔhn㊄抆猆ê†éˆì–‹ì£˜í©œí°Ÿî°¡í«¢î©Ÿí¬ží¨™ë¢’ê¡Ö{t¹TV 8Mž=T¦Jb¦I\±UiºVcÍdjÂLN¸CJ¢4Bv=o=Y;T?[<t&V}/R֞ˇŒ°ar}.OdBbCu2PgDo"Jr(Kp(IeB\@`A`=dAfAfDdFdIp#PRn¾rx¿ts¶kp¹jnÇ}{ÔŠ|Õ{Ö~Ô‹~Ô‹|ÕŒ|Ò‰|ш~ÓˆzЊzЊ{ψ~ІzΉ{·{φxΊ|ÏŠ~ЋÐŒ{ÏŠ{ΉxΈẅxȇ}ʆyˉ~ˇ{Ê‹zËŠ€Çˆ‚ȉ€ÉŠ†È†…ȇ„Ç„‚Ã…„Ä„}¾‚…»€º~~¸x~¸uy²r{²qz°nz®AO­FT¯FT°FT°JV®FV®HR®BK°CM¬>G§:J¤6E¢4C¯CMÉVXØg\àv`ã€pêŠtì–xìšzï˜}ï˜wìšyïšwðzñ~í”tæ‡oâ|iØl`ÂTY§;L‘,H‹)G•2Kœ4J 8M¥>P¨AS°DS°DR±DQ®BQ²ER±AN³EO²BO²>K´FP²AK²AJ²CN¸DK¾JN¹GQ¸KU½LUÇTZÚxnÞuÞ€yÞzpßvlæ…lØ …¯nqÅ|~¿lz–Fd¦bƒ¾U`Ôjf¢=Rp(Il"D[Kk$_{7o`™x0hp&fp0h‡X†n1fK@ZH‹[ƒe%TVEYD}=n\BP=RCh(VŒR}t-[T:U 6Z 5`>\:V:Z?` Fr4fN
+8J:f!BÂ~y¾[`¶ZfÚ¦ Ý ‰Ü–‚Þ¡ß²žâºªà¾­Ù¦šÒ“ŒÓ–”Ú®¤ÝÀ­Îžˆ­JL¸BHÂJN¾FPºHM¾OPÁPNµKQ†<¬CKÔthÂP[¬=L¯BRµDYÂXi¸DT¼LZ¸AT¸EV¼DVÏ[bÞtvà~‚æz剃牂둉죗î¬ð²¢ï³¦ï¯ î«Ÿî®¡ì¥™æ“‡Ø~|ÂZd´Wf²N`¶U]¶R\ 8IŸ9G²HN±AI™0B–/CŽ(Bz =y'HZAU>[Cw,Xv,PÑšœÎŠŽ°_jB[a<b@r/Ph Dm(Hp)Gl"Bb?]>b?d>b@f?a@_Af J‚3YªbvÁsw¼ru¹gm¼kmÌ€zÔ‹|Ô|ÕŠ~Õ‰~Ôˆ{Ô†yÓŠzÒ†|ÒˆzшxÒˆv·χxЇxχ{ΉzΈ|ÏŒxÐŒ}ÑŒzÏŠwΉẅÿ|̆wˆ{ˆzʆ~Æ„~Ȉ€ÈŠ~ÌŒ€Í‹ÉŠ…ÉŒ‰Å†‚Ä‚~ƃ€Ä†Â…ƒ¿¸}~¸vzµu}³u~°oy°@T¬FR­ER®HW¯FR¯DS®BM¬AM®DNª<I¤<I 3G¢2D°?LÈXUØe`áugå€kèŒrí–xîœuîœxð™tð›zïœuîœvìš{ìvçˆvã~gÚndÅQU§<K’,EŽ(H–0G›3H 3I£@P¦?S­AN­BR²BR´EQ²BL±?K²BL°BK³@J´?H®;I³?J´BL³@K¶ET²N_¶Zt¾o{ÎpuÛtjÜ€rÞ‚xÞ€xÞ|pæhî–pãŠgá}à‰€¿Wa‡/Mƒ$D} @`A^2[]#Qh)f~;t^‘}>sdT|7vv3j‰[ˆg&XG>RCs<bv:lY@ZH€BrZ>R=R ?[L{AkˆP~YBV<Y=\8a:]<Y<S:V<XLL
+5¢YcÏxr®JXÐ⩌ږ…Þ›ˆà©˜âº¨äÁ³Ýº®ÖªžÖœ•Ú© Þ¾­É‘}œ7B¤6E§7B 3B¤;H‰$=†"=„#:~6o5z6”/:w9m6w;š4G¾Va²AVÐ\eËU\ÍQ\ÌR^ÑYaÙfmÞtwâ|æ‚~ç}êˆîŸ“ï°¢ñ¯œïµ¥ð²¤î®¡ï¬žë§–߆‚Ñno½`h·X\›5B…(=z8r7r:}>{@~"@‹'?‡ =ƒ,Dk8\;R :\B|1Yw&NÒ—˜Ë–¬Xh•G]hCaBt3Ol"Gp(Ll"Ef?a<`?`=`>`>d@^?U=eJ’Ib¸pw¿wzºquµhoÀvvÎ…zÕŽ~ÕzÕŒ~ÕŠzÒŠyÒ…zЇ}ц{ÓŠzÓ‰vÓ‡wІyЄyЄyЇ|Ј|ЈzΊzЉwΊzΊxІzˆyÎ…vÌ…zʆẍ}ÊŠ{dž€Ì‰|ȉɈ€Í‰È‰‚Ȇ„Å‚€Â€}Â~|ÀÁ€¾~º}¾z€¸v~¶w{±r~®@N«HR°DN¬DQ¯AP®DQ­@M¬DN®>H§AO¤8E¡8G›0E°>IÌVT×f^Þuhä|jéŒrê”wì™tïwîœvîŸyïœxí|í˜zì’tè†nâxdÚhZÆRS¦;J3L*D–*Bš2F 3I§9J¢=K±@O´DN²BL·DMµBJ´AJ´BL´<G°>L²?H²BL®<H²;G®=P´QdÂ{ŒÊŽÔ‹zÔqjÜwfàzhàrß|sâ{mâpÙxk·N^ÀT`Ãmu”<^^:T<K ;QHk8kt8s|:|ŠR‡–jšp&ak$]„G‰x4hŒ`d#VNDWDr4fq2a^MXB‚N~X?S ;P ;RH`RŽ_…M„`MS:X9b:_8V 5P 6G>L9w3Qˇ€¾Yc¿lvÞ³¦Ý—‚݋ޣ’â³£ãÀ±ß¾®Û²§Ú® Ûª™ß¼¦Ã…o+<”*B’&<ˆ <r:v:o:o:l:j8j8l<h8f<a5]
+3k7€;»UbÔjuÔ\fÖ[aÕXaÕ]dÙhpÝnpâvuä}zæ‚}ìŒ‡í “ð®¡ð²¥ð¶¬ñº©ð·¥ì®™ä–†Êkf;H'Br<m7p8l8k8j8l=n?p<v?$Ay"A`6]=Q <X<2ZsIГ’Ó˜š¬^n–F[z/NbAq,Nn(Jn#Gl%Df@`:`>c@^@d>fCYBR <bGžTi¿txÂtq¹mp¿klÇzuЈ|ÔŠ|ÔŒxÒŠ}Ò‹|Ó‰vÓ‡vЈzІ{Ñ‚vшwÓˆxч|Ò†xÒˆvχ{Їyω}ΉxЊ|ЋyЋxÎ…x̆vË…{ˈ|Ê„{ʇzɆ}Ç…{Ȇ~LJ€É†‚ʈ„ƈƒÇ…€Ã…€¾€À€¾|{¼z»}€»|€·z~¶wzµuz±s|¨>N¬DNªBN§>O¥DQ¨@Q«<K¨<M§<J¤=Kž4E™0F˜0G©8FÄOPÖdZÞtfäkèrì’uíšyðšvïžyìžxð|î›|ð™xìŽuèƒiäwdÚnaÃRR¤<L/J‹&A“-Dš2Hœ6E¤6H¢4F«@N¬>L²HQ¶BM´@H²>J®>J°@L­>K®@L®;I¬5Hª4N¯F^Å‚–ØšöLjáz^×l_Þvfàvfá{pâ~rá|rÙzwÀfr“B\lF‡<X€.PR <G @RMzG‚ŽXŽz3kz:pb—t1_€B€t1i~@~|By“oc"UMCUCu3fXAq/h[I‰W†[@TAR :O
+;R Dj,Z_ŽZŽm,_P
+5Y 5`9\;J9F <U=³opÅnf¹VdÚ© à ƒß”€Ü †Þ¨™á´¨â¶ݺªÝ²©Þ³¢Ý¶ŸÆwŽ*=† =†<w6n:n<k:l=i:g5c9d=k&KŠCY„9Rm?Z7Y9_ 6ƒ>¾KXÓfkÕ`eÔZbÖ\dÛdiÝklàrxãxuåë†í¢˜ð°Ÿó»­ó¼¯ó¿­ðº¥á ‹»[Z†(BjDd@eCk>~(F|(Do=h<j=oAl Bp>z<l8d8_7U:Y?v)SqFÌŠŽÕ˜ž­[n”H`v,Lo#Lp*Ln&Jl$DkAb<[<`=c<b?eAbCZATBr$Jª^lÄy{ÀspºntÅstΆ~ÕŽÔŒ|ÓŒxÒˆyÒˆzÒ†yÏ‚yчxЄzÏ„zÏ„vц{уvчyÒ‰y΄yÒƒzІyψzЇ|·|ψsÎ…{̇xÉ…y̆{̈zÊ„zȆ~È„~Ƀ|Ȇ†È…€È…€Ä„~Á~Á~}Á|¾||½~|¼{~½z|ºy}¶x{¸x}µv{´s{¨>L§=L¨AN¦<J¥>J¨@N¦:H¦;K¦:HŸ8Iœ6D•,B’+E¤5H½PTÕbWàrcä~féŽsì˜wí›xîštîšrîžvï›~îœtîšvìnè„häxbÙe\ÅRT§8JŽ(CŒ&C—(B2F¡6J¤:J¦:J¨?J«=J°>H±BN¯<I¯<I°>L­;H¯>Jª9G¥8G¦0H¡.NÏ„~í¸šòµˆøºtÒZQÙnbÞraàveâlälÈadÁox°^o‚-Mz-Sm@X@J DLEU‹^l'X^I†YŒd)SXOx<pBwz5vŠ_Ž”l”XJJ <XFn0`TFd$Ti&W‰^ˆf!KXE[>T:T=TCm4_V†Gty:pgOZ6U
+5J ;H
+:H]Í‚z«HWÎŒŽã²™Ý–‚à›ˆÜ¢“Þª–ྰàÀ´ß»®Þ³§Ü¼¦È{Ž*@”)B‡!>u7g9f;i7k:h:i;]=hCtJŽFf¿– Á–§ Xpt$E[ 7Z 6a:*GÊXXÕbdÔYbÙZ\ÜbjÞejánoâuwç}zꊄð²©õÀ­õµôŭ篖®PVj=aD\C^Lp!K2dœWv®k~—?Vk<^ 5f8m>p?n>c7h:a=V;^@{.WpFȆŠÙ¡ž­`rŽAYt'Jo Hv.Ps-Km"Eg@a<^<`>b<b=cC^>[E_Gˆ;Y¹jsËxvÄvu¾orÈ{{Ί|ÕŽyÔˆzÒŒ{Љ}Ò†xÒ‡zÒ„wÏ„yЃvÏ‚zцyЂyÏ„vЃuщЃzσyЈzЊ|Ά|΄|ΆzÏ…zÎ…yÍ„tΈ~Ά|Ì„|É…{Ç…|‚|Ń€Ä„Æ…€~À~Á||½||»z|ºy|´u}¶u{¹vz¸w|²t|µt|²qx§>M©EP¨BQ¦<L¨;J¦?O£:M¥:J¡:Hž5F˜0D“1E”)B£5DÀMNÖe[Þsbä€iéŽví™sî›{ï™xïxîœ|ïœ|ð|ïšvëtæ„lâvcÚfZÆSP§:HŽ*D‘(D˜,F¡4H¦5J¤<N¬>K­AN¯?K°?K²?M³=H°CL°<J°BK«;I¬8F¨5D¦3J¢0Oáv誘õ¹…à€hÌ^\×lcÞteâzfähØrk¢C_Êjpº]l|+Ox$KO >RIXNp>pˆVzk#VVF{Izs9aJ BNHv6lŽ_—‡F}‰YƒDpVHP>WG`FT>XHWF{Onx<h\D\AW:\>[AZ?bBW>b)Ls7abHT
+:K=a@Áxw¼]`³\n೥ܘ€ÞšÞ¦“Û¤—Ù¯§ãĸ࿳໧àÀ©Èš‚˜7E4D”*B|9g8a 7k?†2IvAs"BpDT 8d@0W…8TÖ®¯á¼ÀѨ®²~ƒ+Ns=˜;Z‘(GÀOTÐXbÎR[ÔV[Ü`gÝejànrßplå~{銃ð–ô¹ª÷Ǻö̵ðèÂoc|AbB`CZF\Jx*NªxŸŸ[sÈ¡¶fv‰*Id9b7j8n9jAd;d;_<T 6`@~-TgDÇ‚…Øž™°^t–BY‚8]q(My4Rp%Ho&EfBa;`<`;d @bB^>\@WBl"OPfÁryÊztÂtt¿pqË{ÓŠ|Ô‹zÕ‰|ÓˆzÓ‰zшyщw΂wЇzÒ…|уtÏ„zЂtЃxÏ…zΆ~ЄwЄwΆ~Ï‚x΄yІuΆ|ˆ~͆vÍ„vÌ„xˆ|Í„{ɃzÅ‚}Æ|Ä‚}Æ…€Â‚€»}€»|y¼zy¼yx¸vzµtz´w{µpv²t|¯t|®q{¬s|«px¬DNªBN©AO¥?P¦?L¨@O¦=N¥;K¢6Kœ4E™2E’,B‘'@¡8IÄPQÖf^Þr`ã‚kéŽrî›rîžxížxí™yîžvðŸxî wéšä„nâxbÚdZÆRP¥:L‘(C“)Aœ0E 2E¨;J©BP«>L°@K²BJ°BL¬@M­>L­BN²EL¯BK®?L­9H¨9D£4G!F¶[]ࡔݦ{Þ¨”ׂÖvpÝtlâxjàxiÐkmº[hÜ{hœ8Rc@dALE^TFzDr\FXGo2hp0Yd"XPKYRx:n”d™|;s†[ˆ~>o^KUBV@U>V=ZCSEk1S‹Y‡e"M`DT 9X>Z=^E\=U7YAVFR@^Rr(g–NfËvm¬EW֤㬒ܖ…Ý¢ŒÝ¬™Ù¯¤à¾²â·àÀ±âÀªÕ¬”¢FN¬AM 6F‰"?s;g8k:#B¡IY‹1P|/N‹>`lEt(HCeo(PÒ®½ä¿Ä潾ܰ°¿n~•&H¸LU¶@T¹@IÊRXÆLVÌT^×ZcÚdkÞghájpç{vìŠð§›õ½®úлôвۘ†¢>K‚(HgDz0NbCdCx+OŽ?d™TrÔ›¥Ë|…¢9Jv>a8g<g6i<b;b:bDX@d@~3\gDÀ„ŽÖœ¶n’4N‹Dfs*L;Wl"Fj!Dc>b:`>a>a;`=Z>Y@]I}0Rª^pÆvvÈttÁssÂstÏ„zԌ҉~Ó‰xÒ‡{Ôˆ|Ô‰yΆ€Í„|Í‚xÒ‚vÑ‚vσxÐ…vσyЀvÒ‚sÑ‚yЄyÏ‚vÍ‚w΂xÏ„|Ï€vÎ…{Ì„zÌ„wË„~Ì„zÈ€{ÆzÁ~Á~|Ä|Â{À~~¼}€¼z|¼y}¶z~¶v|±s{²ov²rx¯oxªovªlxªo{°vz°ANªAQªGT©=L¨CP«>J¦?M¡<K 8K›;K˜2B•,D&?¢4F¾OQÕbXßrcãnêŽtî˜vì›|ìžzíž|í yð¤ð {ïœ|ì”vè†rãu^ÙfYÈTR©>K–+B”*C›1G 2Fª>K®AN®AK¶DL¶CK³BLµFN±DN³GN°EP²@L±FP®@Lª<GŽ(BiB—MRÆ•›Š2O«^Tê°’ç­œâŠ|à€qÛzk´Q\‹,D‰/E^BP=RGWP~Gz‡HtfQSCm2ip-a`Pt8nZNaYzEz’^˜|9t•v |=mXCSBZD[BZCW<PAcL’dŽp(U[?Y?X:Z;`D\8X 5W9R7L@L >j(N¤^{™@Z¸l€Ú¥˜Ò‡‚É€ƒÍ’“צ¢Üº®á¶ÝÀ´Ü¼©×±š°Z^°GWÂR^³HV¤8L•2H{<l6‘&F¨HS«Xlz'J‚6V‹;V‡7WwJšbŽÜÇÏçÇÆêÅ¿éÀ·Û”®AZ¨6IÉR\¸:HÄHTÄJXÉP_ÓT`Ö^`Üdmßqt惀쒋ðªžöóøÎ¸îŬÊpn£<P§Rj|&KE`Ž=]‰6RŽA^{$N°r•Ú–Òzƒ«AN~ <h3`3b 2f8^:`9^9W=fB~3ZcFÀ|…×¢œÀx‚„2QGbz.Q„@\hDm$F`>\8a<bAeBc?^@ZBbEŒ?[´joÃxvÅtp¾npÃyzÍ„|ÏŒЉ|ÓŠzщ|Ї~ÒŠy΃zЄxÍ„v΄vÏ„uË‚wÏ€uÌ‚|уvÑ„zÒ„yІzσxÌ„vψzÏ„zЃtЂvÌ„xÍ€yÊ€vÃ~xÊ{Æ„|Ã~{Â|Ã~zÀ~{¾zz½{}»vxºx~¸uv´ps®nv°os®jrªmv¯py²z~»‚„ÆŒƒ¯FQ©CP©BQª@JªBN«@P¥BR¢8JŸ=Mœ8G”0B‘*BŒ%@ž4F¼MRÔb[Þsdãmèrì—xîžvïyîœwñ¢zî ðzí—xç‰oãv`ØdZÈSQ­?J–2H˜+Eš4F¢6Iª:J°@K°BL¸DL»FL³DK¸EK³JW³?M¸FSºJQ»YU—1B}9q:^?l@Ƭc{˜šç©”úÉ¢õҾꮎ°TTbGR>TCSAO BXKx<n~:hi Pe"\cWq0fi*bd!Up/am+gs0nˆ\”b™‚=y™zš€H~RDVA_H[Bd#MXBSA^D}BghF\=bEZ<X:a>^<W9P 6Q<PHVFœZnªUb˜H`Àš¦ÆŠƒÍ”’Ô ’ܰ¢à»­ßÀ³Þ¼±Ü¼©Ø²š²\_µN\ÂT\Í_dÈ\hÇYdºQX <Ov8=®EZ¹V^¡Rl}.RrHy*Xš^ŒË±ÅçÁÄíÁÀ첦áˆ~Í_kÂBTÐWVÆKVÈKSÎV`ËNZÑTcØ^fÙgnàpp傀씌ð¶©ö̾÷Һ輪½S`´M^Àlv¦Wyƒ4RB\‹B`€.X›Y…Π±Ü”Òq~ª;L€=m5j6j4h6\7^7Z;Y?o)Jz2ZeJ¹u„Ù š¾{ˆ€0T‡@b‚6Uƒ<ZhCfA`<bBb@`>i$Fc=\:Z>dC—Nd¼ryÅytÂut¾tyÊvÑŠyÒŒ|ÑŠ{ЈxÒ†yІ{Έ|Ì‚wÏ…vÌ€xÎ…z̓vÍ„{΄|΃wÏyЄw΀yÐ…xÐ…xÎx̓zÏ‚yÏ„xÏ‚vÌ‚w΄uÈ€zÅ}xÄ€zÆxÃ}yÁ€¾{{À~z¾x|¹sw¹t|´tx´r|±mt®oz­lt°rw²y}À„{ÈŠ‚Д…Øž‡®@N¬FQªCP­BNª@LªBN§@N¢9J¢;J›:K–2F‘*CŠ$@ž6F»LSÔ`Yàubã~nèŒrî–yížvïŸzð xðŸ{òŸ~ðž~îŸî•zè‡oâxfÚdZÊRP²>M›0Gš1H 4I¥8I¯>JµCL²EM¶GN¶JP½HO»IP»HNµEL±?Fž3<„)<l<2[z$P‡<_§_|И”Ë‚šç”ˆî¸£ùïÑôݯ´r`h!Lm0jM>R@M?TJs4nŠK„|;tq5nh(aZKl0jv7ny<s|:r€Dys/hŠb•ˆU’s0h–tžˆX_L_K[BV=cFZ<X;_=f#H]DbEfFY=\:\<`>Q8N :J 8RL„D\Âwx¢BVÀ†Ú¨šÕ‚zÜŸÚ¨•Þ·¬ß¼²Ü¿´Û»¨Ôª’¶ZV¾R_ÉVaËR\ÐVdÔhmÖjoÑcj¼Tf6R—2N³@TÀQgÂez´a¨Z„³u’Χ¯á¸ºå¿½îļæžÜmpÞsoÓ\gÌNWÒ_cÎPVÍNXÒU[Ó[dÖ[dÙ_hÝinä~똒ò¾´÷ÔÅõһ⮞¼P\¬<Pµ\hÂp‚¦`•Hv•M~¦lœÊ¢¶Ø «×’˜Îgp¦:L€>m9n;n6o=c>Y<`C_Br,Lu+RdL­cvÚ£Ÿ¿„‹‡8\†>`‚>^€;Vl&G`>`>_>];^=k>f>\>Z?n(M£Zf¾uxÂssÀqrÂtt˃ÒŽ~ЉzщzÒ‡wЇzцv΄|Î…w΄vË‚wЂx΂wÍ„z΃̅|ʃsÏ…x̃|Ï…x·{·wÊ…z̓y΃zÎxÊ‚zÌ‚sÉ€wÅ{Ç€xÆ|wÂ|y¼yy¼yzºxw¼wvºyx¶qv±qx²nv®lw¯tz»~{Ň|Ê€Ô–ƒØž„Û¢ˆà«‹¯DQ«EP®FPªAN¨BN©BN©@M¤8L¤8K:J•6G)@&A 2GÁPQÕcYàsbä€lêŒsë–uíœ|î uî¢yï¤|ð ñ ~ì—vê‰qã{jÚg[ÊWT°@N4I™5J¢3D¨8I­<J³AMºEN¿HP¾LT¼IRÀJR¿MP³]bp8^7b;tHžSl²k‹ÇØ~„䔊߫­áŸ’óɤʔk|<CXKYKH€SMVQh)l„P’šo¥ŒZ†{ApP>OCPDuB_L‚Byw6mr2lt8x‹j˜’g¦k(dœƒ°b|>rh"Ke$VR=[>T
+4V 8]A^@^Ag GdB`A^=^#C\>R6J 7K <e C¼ru´MX²]qÞ·¯Ûš‰Ú•ˆÜ¥—ܰ¡Þ¿´ÞÁ¶Û¾ªÑª”¬OQ½LVÊX^ÍZdÏ`eÒ[bÙkmÚrxØnsÕhlÅ^k·HX¯B[²D^ËSdÐdnÑt€Ø€‰Û‹‡Üœ›ã¤¡é¤Ÿæžœàž¥Ú…–Úq€Ð_rÒ_hÖ_bÔV\ÎQ\ÏQZÖZbÔ]eÙXbÞovå~€ìš•ò¹­øÕÇóÒÄડÅj|´Nm°LoÄXpÌs‡ÃtÉz”щבžÑ†Îpr¾HP‘*@n4{#@{">t<r?d?[Bc"K`Fw2Ks*RcK©dzÜž—Ę—Gb†;[ŒHcs$Fm"JcDZ:^AZ8b;h>b>Z8dC†8V®gtÀxwÀsuºnrÆ{ẍЌ‚χ|ΆyÒŠx͆x̓tÎ…yÌ„v̓xÆ~z̃z΃vΆ|ÏŒ‚ΓˆÌƒzÑ…w΂xЄzΆzˆ{ÌỹwÌ€vÌ€vÉ€wÊ~tÅ~yÃ|vÄyvÂ|x¿zx¼yz¸t{ºvy¼xxµst¶qx²nt´tx¼}}Æ{Г֘ۤˆÝ§‰àª„䮇粌°JV®IQ®DR­DR­IT¬FN¨>K¢9H 8Jœ1F˜0D”-D$>2D¿MPÔb\àsbä‚mèŽtê–wî™zðž{ï yñ¡€ñ¢|ò¢ñ {ðšwê‹pä{hÜk\ÈUR¯@M2F›1F£7H¬<I±>I´FP¶GQ»NR¾LR½OY¿KSË^P«XY\8\ 8ƒ*P¡JfÆ…ŒÍ‚ˆÃwŒÏyˆÌr‚Ίۥ¡¬ifb CY RTNVP{G|‡PŽˆPŠˆW„}Erl/Y|Gx_MJ @MC[N„X’UJ|H}v6pl,kv8x‡Y‹v«…G‰¡‡¯‡R~~Bwn1ar9hSAY@S:U<Y=]@^?a@]=`<`A[?Y 9O
+4J
+8N
+6—O]Érl¨>UË•–ଛړ„ÛŸŽÝ®Þ¹¬àöݿ«Ò®š¯LN·DNÊP\Ï_iÒ^hÔdmÕcnÙjqÜnuÝosÙpvÖkqÊ\hÊcrÎ[fºGXÆRd²>QÅ[lÒgpÈfiÊnlÄdkÒ~ˆØ‘œÛ—£Ü›œÞˆØnqÒW`ÒV_ÎVbÒZhÖXbØ\dÚ\fÜkqãzzé—’ð¶¯öÕÊôÖÊæ°ªÞ˜ÖŽÎ€ŒÌp~ÖvÍdpÈ]gÌnrÆpr¬JTŸ4F“&>€<t<—8JŠ-Av<t@eB\=e"HdEv0Mq#J^K¤\uØ•‘Ì“—žVn}3TD`u,Jp$F\>\>`?\<e<l#G`BbBy<X˜LcµjtÀux¾mnÁopÇ|wÑŠ{ЊχxшzчzΆ{Í‚yÍ„z΃xÊ€xÄz΂zÍ‚zΆzÏŒ„Ê’‹È„{̓ỹ}Í„zÌ…{̇zφz̃uÌ‚zÊ~tÄ}xÇ~uÇ|s¾wv½utÁyv¿xv¹tx¸pw´uz¶uy³tzµrw¹{|ȆwÓ“~מܥ„⨆⬅䯈它氆贉´CP®DP°HW®HU«BN¬DQ¥<N¢9I¤4Gœ4F–.B’(@$?œ0B½HLÕc\às_äqèŽoê˜xì›}ï}î¢|ï¦|ò¨|ó£~ñ¥}ð—yêtå~mÜhYÌXT±BL™/Fœ0F¡6F©>K°DL´DN»EKÀLR»KVÁKOÂFPÊXJ´hciA+K¶bvÊlyÚˆÌnƒ²j†®jŒ®cÀ~}ŸS`j&Vn-`e QZF\RaRf–^–n,d`\„V}IyRFRDTJ]I‚R‰`$ZwCtJTSn2nˆY]“‘[–™sŸDˆVŠŽrŸZCR<\AW?ZBX;\<_@^>[9_C`>V5T 4J
+5H <p)IÂwv¹JSµXcÚ®¢×‚Úœ‹Û¨—೥ྰÝÁ¯Õ²š¨IN¯<LÅJXÐZdÔblÕdtÚnrÙhpØnsÛpzÛptÛnvÚqzÙqvÚquÓcmÄTbÌZfµF^È`nËjvÀcyºYl¸\xÉ|‡ÒxÜ‚„ÞƒƒÚvxÒfsÌVdÐT`Ñ\jÔ`mÖX^ÖYfØXeÚjrãvyêï°ª÷ÓÈôØÊæ¶°Þ‘‘Þ~×tvØlnÑjm½Uh³Rj´Tl²Qa˜8X‰*H†&E—6N™3G4F”)?x7v:e:]7eBdD7Tp)O`P¤VrÖ””Мœ«d{~/TŽH`x+Ig>`@^>_?Z9h@hA]?dB„8S©]m¾tx¾rr¾mqÁvwË„|ÑÔŒ{ω~ΆyÏ…{ІyÏ„t΄{ʆ{΃xÆ„€ÈxÍsÍ‚wË„yË‚yÌ‚vÍ…zÈ€zË€x˃vÌ…|Ë‚{Ê‚zÊ€yÈ~xÂ{vÅ|tÄzvÀxr¼xzºts¹rs·sx´tt²q{¸rwºz}Ɉ~Ï’€Öž~Ü¥„à«â¬‡æ³†æ²†ç³ˆæ±†æ±Œç±ˆ³DR¯HR®GP®CN¤CQ©BP¢;Lž9L1Eš5G•0D)BŠ%>˜+@¼JNÓaXÞrdä€léŽpë•{ìœ|ðŸxï xñ¤|ñ¤ñ¤ó¤€ñš|ëŽxå|hßjZÎWP²CJœ.Dœ.E¡2D¥9F°>K´CM¸FL¼KQÀPS¿JPÀFP¾JWÊypªap´pÊr†¾d‰»tŠŒª^k‡8Xp,Sy4^…Gmv2^_JW>PAWLONh5g—{©•l­‰X˜šs§‡KŽ~KŒd"W^ TO FxCsg'bn2e†Xj,lh6l‚Nˆ„Pˆ–l¥™n©”k¢•|£d*NP>\H^JV<]AaBZ:`B`@]>_D^>X8N
+6D4S>¬foÉqk®FTË‚†Ö™„Ú•ŠÚ£•ڨݻ°àò׶§NM¢0B¿ANÊPYÔ\dÔbmÙguÜrzÜoxÚs|ßtzßx~ÛquÜlpÜppÝwwÚkrÖjqÚhkÑ_jÓcnÔjrÓkxÌjxÔx„Ø~†Ü‹Ú|‡ÚvØz‚Ôw}ÎYhÓVfÖ`j×bkÖ\dÖZcØVcÚ_nãx€êŠí²¬ôÏÅöÙËé¾´Þœ›ÚˆˆØ}€ÖoxÓdpÐ^jÏcpÈ\iÊ^i¾Qa¤>K¢4K¥>L©@J¢=I˜/?|8y8_ 6`8c<fBy-Ln(P_LžVrÕŽŒÖ¤£³m€€2V‡?\r$F^<d@\9[:\8q(Dd<Y<a>‹>[²jtÁrs½mn¸hpÇyu΋|ÑÒ‰zω|Í„yφz̓zÏ„zË€x̓wÌxȅʃyË„|Ì„xÌ€sÌ‚xÌ‚vÈ‚|É„vÊ‚{É‚|É‚vȃzÉ€uÇxÇxÀzvÂ~x¾yy»vu¼xy¸vw·ss¶tw¹ptµpy¾~}ÎŽ~Öš€Ü¦‚஄氄洂贅鵇泆贇賅氄粂®CQ©GTªDP¨CT¤@O¢>Ož9Iš5Iš2E–6F‘.C‹%A„:™.C¼FJÓ^WÜqfâ€rçwì–zí~îyï¢xñ¢|ô¢‚ñ¥€óžzñœ}ìnä~jÝm^ÏZS´AJž,D™,B 4H¦<H®=H²CJºFL¾HM¿HLÀGLÀFN¼DTÔ`U΀‡×w€Þ‘ÚÉpyªRm‚4^l3_j+X}8d„@dj'TRDRB^#YZJYN^Wn6h›}®šv°”hžŽhšS€d!Q\NMFh+[u6nf&aO…ŒS”{E}p4ir3k‹X’‹W…›{¬„R}|>tm-]h#RX<\<[<]>\:\;cB\?\;X<P6P <I :}8OÍ~r¾RW¿\bÛª›Ø”†Üž‹Û¬ Ü¶ªáıÛÀ¨¦TNž/G¸:JÅJVÏS[Ò[gØfoÛoyÞu|àz}ßz}Þwxáz}à{~ß|~ÞyzÞttÚnrÜrxÜouÜlpÚoxÛq{Üz~Ý}†à‚‹àˆà‰ŽÞ…݆މŽÖovÒ_iÖ_l×dnÙdmØ\gØWeØXdÛZhâr|èî°²óɼô×Ìëĺતޛœß‰ŠÞ€„ÙszÙlsÙhnÒ^gÏ[cÇV^ºHT¹FT¯HTµIO­BL 2@~8{ =_9b<f>hFs*Fn$N`PšRkÔŽŽÕ¡¤¶p„2T}2Rp$DeBg@`F[@_;o(A`;V;c@–I_ºpuÁqrºnp¼lmÉ~{щ~шxЊz·~Ë‚zχ~Їy˃|Ë€xÌ€z˃y̆zÌ‚w΀vËzÊyÇxÊ‚vÉ‚yÉxÌ‚xɃ|È„|È~zÇ{xÉ~uÇ{tÂyvÀxv¾zt½z|¾ttºrs¶rt²mx¸tz‚‚Ó—„Û¦„ᮈ䲅趈귃뵆궆洆泉貇賅籄鲇°DRªBP¦@N§<J =M8Iœ6F–4Fš2E’0CŒ)A„;w8%<µEKÒ`ZÜqdã~nçŠtê’vìšxí yð¢yð¢~ñ¤ñ¤‚ò¤„ñšyêŒpä~fÞmZÐZP²>Gœ.Dš/B¢6G¦8Fª<H´BL·DL¾HMÂJNÁGLÂGM¾ISÁNZÕkg׋ˆÏyƒºXo¯Xo–Iik'Tf"R}:iŠJxp/\^NNETKq8pdTn-fq2n‚I„„NvGxuCr‚Pk/^XDTBPDb Vp1fh&d^"YˆZ’a£ƒPŽ‹U“‚I…yDv…W„j0[M~`F`BZ@X>X;Y9[;Z<aB[BZCWDP>J @Z@¶opÉe^°FSÌ~†Þ¡Þ¥”ܫߵªâóÞÅ®­hX“&>°:GÀHRÈLVÐTYÔbl×blÚlsàv|àz|à|€Þ}ƒâ„ˆä…ˆå„‚ㄈâ…ßy„Þ|€ÞŠß|€Þƒˆá‡ˆàŠâŽã‘”ጎâ–ᆊàŽÝ„‡×ktÕ]kØckÛjrÜchÚXb×ZhÙYbÛYjáqx劌訪ñÉÂôØÌëĺ⮧⤡ߎ߄†Ü‚Ûx|ÚqwÕ`lÓ^fÏ^hÎVZÅPZ¼R^¾PY´JS¤8G„<|=c9h:f>p"Dv,Jn&N\M–NiÓ’×§¨´w„„7]~6Sr(Jb>f=Z<Y7c;f:Z9ZAl C¢We½tvÀqs¼nt¼qrÊ€zÏŠ~ÑŠ{φ~Έ{Љ{Í‚zÌ„xÌ‚zÍ‚xÊ‚yË„{ʃ{̓vÌ‚zʃxÌ„yÊyÉ€wÊ‚xÈ‚{ÉzÆyÄ‚}ÆxÆ|xÄ|tÄ{xÀxtÂyv¾wx¸yz·rv´nr³mpµqtƈ„Öœ‚᫊消鸈까빂븄鶄궂鵂貅貄è³è´†è³ƒªDT©=K¦9J£8Jž<N›6L™2F–-G–1F”/CŠ&<†;€:Ž$>®AKÑ_ZÝqdâ}hçŒvè•|뜀îŸ|ð¢ƒð¢|ò£€ò£~ð¤ð›wêŽsä}fàkZÎYP¯@Iž4Eœ*A¤2D¨9G²=G´@K¹HN½LT¼LP¼KP¿KT¾JX¾Vf¾]w¸^z¨Op®Ri¡Efy-bz?{ˆKQr1_\H_NUJ^MzBzq+f„J‰Ž[–a~@u\Wq5i‡R…f#TI ?ND^Tb[w@q|Aw\ \W V•r¥†²Œan,dt@zyAx—Œºn9_QBX@_B\>]AZ?Y:Z@\D^HZHUGNFPEŒEVÎzk²ETµXfÖœ•Þ Þ¬Ÿß²¢â¾¬àʰ´o‚!>§.Bº?LÆMSÍQ\ÓV^Ö^dÖfsÛiràuxâw{á~‚ä…懇厌懆勉甊䔑⌋䊈⌊㌌䖓◓ã”ã‘⌌ä’⊊áˆÞ||ØjrÙflÜopÛkpÙchÙ\dØ[aÚZfÚYgßov厎騪òÇ»óÖÌíÊÀä±§á¥ß˜—Þ‰ŠÜ€Ü|€ÚxyÖjsÖdlÔ^hÒY`ÊRbÃRa½L[´HU¦<M†:x>g:h>h>s#Dx&DkEXF’FdÑŽ—Þ¤ Á‚Ž„3Yv/Jp"Fb<g>X<Y9f:b:X8[:|+M­`h½qr½nl¹nsÄww͈~΋φ|Ј{ÒˆzÎ…{Í„z̃x΂vÌ‚zÈ{Ë‚{Æ€y̆xÈ„}˃yÉ‚xÇ~uÈxÌ‚yÈ€xÈ~xÄ~vÀ|Ã}yÇ}|Ä{wÀyvÁ{u¾zv»xt¶ss´pr°ovµrtƌؠ‚⫇赊꼌컈빇붃鴃êµê³‚沅贆贂粅괇¦<N¤;K¢:M 8Jœ5Lš4H–5I”.F”.F‘.EŠ"<„;:+C°?GÒ^XÜl`ã|kç‹tê’xìš|ïž~ðžyð |ó¥xò¢~ð¢‚ð˜vêŒpçeÝm\ÎZT±CK0D—-A 1A¦:H®<F²@L·DL¼HMºKT¾JR¼NZÀN_ÀVm¬P|¤L}¼n˜¾w  d¤žw´¨ˆ¸¡v¢„Jye$Ud S_QcXn*_ŠTŒv2jeœŒXŒŒSˆz7wt5r“g™{@pN>J@QFZKe&_ƒJ„•dšz@{l2nl4jwDvŽd Hb¡š¹Žfƒf$Rh&Mh!G`D^B^@]AX=X;ZDWFXHRDNGeD¾xsÃ_Z²JZË‹‘ÜŸŽà¨•ß´¢à¸ªßÁªÄš‡w=&B¬5E¿FRÈLSÑV]ÒW`ÔZbØhsÜgqßprâx~ä}}å慄摎懆æ‰è”Œè˜‘ä”äæŽŒå攎ç”㑎掓䔓â“⎎àƒÞyvÚltÛhoÜntÙfnÚ`bÙYdÖ\fÚY`ÙU^Þfr倅訨ðÁ»óÖËðÍÄæ±ªà¤šàž™ß܃†ÝzzÝtxÚknØdhØbhÒ]fÒW_ÈVcÆS[ºNU¨<L‰#=t<b=h<p Br>z-HoCW FŒ?`ÒŽ”Ü¥œÇˆŽˆ<]r&Fm A[6jB[A\:d=_<[<c@’?X·fk¾vt¾npºntÈ|xЊ„ÐvЊzφ|ψx΄x΃~Ë€vÌ€y˃{Ê„{É‚~ȃzʃzÊ‚zÊxÌ€xÇ€wȃyË~sÈ€{Æ~vÆ~xÃ|w¾|wÂxxÄyuÀyv¼uq¼us¶tr¶st±puµtvÆ‹|Ùž‚ã®‡éµ‰ì¼‰ì¾Šî¼Œí»‡ë¸†ê¶ê¶‚ê´è±„簀鲅鴂絆赌¢:I¢=L¡DQ:L™7J˜6L–5J’3F.C,C…#<:{>Ž(?­>JÐYVÙncâ€oèoì•|ëœzîwïžð ò£zñ¡xò ~ñ™uìŒoæ€iÜlZÊTP¯@Hž0C™,B¡3E¢;J¬;G³>F²>KºCT¿HX¼Qq¾\Œ¹n »x«°}´º‰ºÃ‰­»’¯žy˜Œ^~ƒVvz?ki)Yd!Rf%Tl-`e Ux;n„M„u6n‹_‘‹W€A{ŒX”’b„Fu[HL?R@O:ZJUN_T{Dt‡NŒ‰X’Œ\˜€MŒ~>x˜|¥œ°ˆ\‡n.Xš\}™Hc‹9Pƒ3TR<WB_BY;WAX@VDRCLBNF”RbÐ}p­EW¸XcØ¥£ÜŸ’ß´¢Ü´¨âĮҵ›t/B{:˜(B°:IÁKXÉO[ÐS\ÔYaÖ[b×alÜipßouãy~äxwåƒç„†çŽˆè‘Œç„è–ꙓ甋蜖Ꙕ旒甑å呑處晓æ—âŒà€€àxyÝruÛkqÞnuÚksÚcj×ZeÚ`iÚU]ÚV`ßbkä}‚袠ïÀ¼ôÕÌðÐÅé¸­à¡˜àš‘á˜ŽÞ‡†ÛxyÞptØjqÚfiÖen×_lÔXdÏXbÌU\ÂQR«DOˆ#BvAb?f@nBt!B~-Hh?U
+Bˆ:WÒŠÜž—È‹Ž’Fan!?e9V 2o#CV8_<h<_;\=f? Pa¼qwÂrsºnnÂnn̆|ÒŒ|Ћ}Јz͇{ˈ~̃|ΆyÍ„zÌ…€Î„Ê‚xÇ‚}̇zɃ}Ì‚zʆzǃ{Æ‚xÄxÀ|€|Ä|wÄ~|Ä}zÀ|yÀywÂwr¼vw½wsºrt¸rw´rv´rxƈÖœã­Šè¶‡í¼‹ð¾Œî½†ð¼‹î¹ˆë¸…ì·…ê´ê³‚鲄糅궈괅趉鸌ž7Lœ:MBU™7I•4H˜0H”0E”/F,D'?†$>}<w8Œ'>²HRÐ\XÚpbßjçŠoê”|ê›xîyðŸ|ð zò¢|ò¢€ò |ðš{ê‰næ~iÜkZÌYU°@Lš,Cœ*@ 1B 7Gª7H³?N°Dc¸Nt¿h’È„œÊzŽÅšºpŽÁpŽÈu´p‚|:V^!Sb'Zv=ph)X` Rh&Yi&Zh$Wm&Z~G€€B|x;sˆ^—z@zfŸ™nž„Ith*VWGYHT?P?XASEUKd*Yr3ot8l’_“˜kž•k•l6\NARJx2V´u€±huœPc„4UWFYE[>X?VBWDSBSFNF_ J¾}z½ba°P`Ç|†Ü¨“ட߷¨áÁ¬ÜǬ„GL]8<š.B¶<HÉMUÍOTÒT^ÕX^Ø[bÙdnÛilàptâwtâvxä~€ç„„挄蓊锎蕑ꞕç—è‘Žéœ•çš”è–æ›’痑阒皓敌äŠâ…ƒàxyÝsvÝv|ÞpuÜlrÜdoÜ^eÛ^fÜY^Û[dÜbnãw|皘ï¼ôÔÉðÎÆë»°á¡šà’Œá‹‰à‰†ß‚‚áutÜirÚbhÙ_n×ZiÕ\iÒ\hÌTZÄRY­?O‚DuBa>l Bt$Ds"C€0Hd>YG|-RЊۜšÌˆ¢\sm"AcCY8k>\;b<d<\8^;x)G¬[d¿vuÂqp¾mnÄvtц{Ð~Ћ~ψ}ΈyÊ„|̆y͈zÊ‚zÊ~È‚zÈ‚~Ê„zÇ€{È€{ɈȃyÊuÄ|xÆ~xÄ~xÁ}wÀ~xÆ~{À|xÄzuÁzxºvw»tt¹sv·pp´qvµptÂ{Öš~à¬‚èµˆê¹ˆî¼‹î¼„í»‰íº†í¹„ì¹†ì·ƒé¶ƒê´‡è³èµ„ë·Šê·Žé¸è»“™6K˜5N˜:P–6L“0G”,D•6N-F*C‰&?„'D{=x<‹'C­CMÍ\ZÙthß~lçrì•xëš}îœ{ïŸyðœzð zð¦€ð¢~ð–zêŒqä€iÜn`ËXQª>Hœ/C˜,Až0B¤6G«9L¶ET·atÂhtÇ\bÄQ^ÁXkµdˆ¬aаeLx†6hk$\m)a|:nv7hg#Ug'Yb Rf']j)b|?xu<ru7p‹Z—ŒX”–u«–l–’f‘aQXG]J\DZCWBYCVBUFYNl/Xx?v_Jh-H„CWT<D >[D‹<\¶ot·nu P_v*N\DTAY>Y@V@V@SBNDRIŽM`ÌzpµT]¸\dӟޢⴢ຤â̲¥zhO9g9‚<¢:J»DLÆQVÐUXÒV\ÔY`×^`Û_gÜfnàpxâorâyvä~~胂挈éŠè”Œê–꜔ꜘ隒階雔è˜çšç›êœ’薌玆懄ã€|â~|ßuxÞqsÞnsÞlrÜglÚ^aØ^dÙ[dØXbÛ`iãwæ™™ïÀ¶ôÒÊïÔÊëÀ´ä¢™Þ“ŠÞŒ‡ß‡„á‚‚ßwyÛkrÚepÚ`kÙZhÖZjÒZdÍX[ÄRW¬@M|?v@^Ao?nCu'Fƒ3Nd?VDy*NΆŒÔ”™Ì„„´sl=`8Z 4`6^7e:b<Y7[=…5Q¶djÄsrÂsqÀnpÈzvЊÒŽЉ~Љ}ψ}͇}̇~ψzÌ„zȃ|Ë„ˆ~ÉzÈ‚|Ë‚zÊ‚xÈzÉvÆ€|ÄxÃ}xÃ}wÂwÀ|{ÀzyÀ}z¾||¾xt·tv¶tx®nt²qu½xvÔ”âª€ç³…ë¸†í¹ƒíº‡îº„ì»…î¼…ì¹ì»ˆì¸ê¸êµ€ç¶‡è·ëºê½–êÀ–êÁœ–4J”3I’0H’0H0FŽ)C”.E‘/G‹*F†(D‚"=x;t?‡ @¯@HÎ^XÜndâ~mæŽpê–yîœ|î›zîž}ðŸ{ð¥~î }ðž|ï˜}êŒræzdßl_ËTS°DIž/D–*@š6G¥5H«=J±GV´MY¹HU¼MV¾N\ÃVeÂd|©Po•Fh>mˆH|‚>uƒAt~?rr1]s)ZiN_Vp-g‚H…WŒ_ \r6n—k¦™v¢‘bk)Xi1]n1f\I_HZ@Y@XDXCXB[HXIWEr.Rv:ncCˆ6IX<H <T<–E\´ep¼qwžRf”Lf^AUAT=T>R;XCN=J @j&JÀ}|¾ef¹TdÉ€ˆâ²¥á°Ÿß°œà¿§Â¡ŒX<Z<p<„!@¦8IÀGRÉRXÐR[ÒW^ÔV]ÕWZÚ_eÝikÞksãtsâyzãzyä~}凂针閎阉윓ꛓꞙꡚ蜒蚒界蚋ê•甈率åˆâ„}àywàtvàtvßttÞpqÜjnÚbgÙ`dÚVaØ^bÜ`gãwzçí¾¶ôÖÎñØÎëø⠚ޒ‹Þˆˆß††ß„€ßxyÜqvÚkqÜ`lÚ^m×ZfÖ\aÑY[ÆMR¦8Iu?tA[=p?hBv$@Š9Nc@Y At IȈ֔˜Àox¼…Œp?\:W 7^:n"Be<`8]<d:–EV¾mmÈynÅtpÀpqÍ„{ÑŽ~Ó~ÍŠxψxÌ„ẇzˈ̈zÊ„zË€xÊ‚~É‚zÉ€zÉ€zÊyËzÇ~yÅ|€|Ç€xÈ|xÄ}xÅ|yÀ~¾||Àzv¼z|ºuv¶rq³puµlr¹rtÌ€Þ¤€è±ƒë¸†î¸ƒí¸~ì¹„í¸„ì¹‚íº„ìºƒì·„ë¹†ê¹†è·ŠêºŠê»ì¿–ëÀ–ìœê ”2J0I1J‘.HŽ.FŽ,D*D‰*Bˆ+D†)B~#@x Aw@ˆ#@²?HÍ\XÙmdã{kæpè’vêš}îœyì ~î |ïŸ~ðŸ|ò€ï—}éŠpæxfßl^ËZU¯@Jš0F”.Dž4F¢8K¨@P¬@N°LW·KV¹LU¿N]ÆS]Ä_nž=`Š<jx4my6o…I‚ˆMˆy0`“Lz}1bdVr-h‡N„†^Žc*\\^zCš~±†Q†‚VŠd*cl8go2\`JV?Z@[A^J^FZE]FZFX@d&HZD_@ˆ8Mb:F9T?“CY±bq¸eu´€‚R^\BQ7P<R;O 6U>K ;K 8˜M]Étj·P]º\fÚ°®â°˜â¶§Ý´ ÖÀ§r9FM>Z@l>Š'B©<J¿KRÊNVÏRYÔXbØ[`×\cÙ`iÜ_cÞfkáqpârrârrä{yå…ƒé†è…ꔎì˜éœ–윔ꡒ顕è–瓊疌蓊蔅戀äƒ|â}zàxvßqràoqßtsÜlmÛfjÚ`cÖY]ØY`Ù_gÛblàpwå’’í¸®óÐËñÖÊìÈ½à¢˜ÞŠàŒ‹ß‰‡ß~ÞyxÛrtÜkrÝ`pÚ`qÖ[dÔ]bÏZ\ÀJPž2Fx@n@]<oAdBz#D‹9N`:X <sFÆ€ŠÖ“—ÂqzÊŒ†z&HZ8^=\:r&Dc:`<^6o>£PZÀnjÅspÂqnÇxvЈ{Ò€ÓŒ{Έzχu˃y·{Ì…|Ì…yˆ~Í‚zÊ€xÈvÌxÈ‚xÆzÄ~|Æ~zÈwÁ}yÇ€vÆ~uÂ}zÄzvÅ~w¾{{¼x{¼xx¼ut·rq±mp²hnÅ€yØœ{æ¯츄ðºƒí·„í·‚î¶„ì¹€íº‚ì¹„ì¹†í¹‰êºŠë»‹ì¿”ëÀ’íÅœìÄžéÅ ëÄ¢’2J2JŒ,F‹*CŠ(B‹*Eˆ'D†(C„'E„$@}>w?u:ˆ%C¯:DÏ\WÙojà~låˆxë”{ê–vì›{êŸ{ë›xïœ|îœ|ïšxð•zê‰oç~hàk\Í\X²AJš,A”.D›2DŸ8L¤9J¬ET²FRºFP¾GNÂMSÄMV¿P`Ž*Z‚=|™dœ˜n¤‘av/cŒ<l¡Rz4iz4jX„P}^(UVP][j.g‰j™a¢€Lzx?xc'Pe'U]HUDZ@dJ\E]FZ@ZFZEZEZ F^IX@y,Bj=J
+;t FœDY¬^pžJlȉÀwv‚7TL6N<L ;L
+5N :K9fBÀxj»^^·TbÆw}ß´¥à³¤â¼¬ÜȲžpmODSCdCo?ˆ#?ª:H¾GPÌTWÍRXÑSZØ\dÚ`fÚ^dÜafßioãnrânpâtuäzxå{vè€x艂ꌃ쓊êšêœ’êš“é¡é˜é•Žè—Šç’ˆæ‚åˆ|æ„uá{wßmpÝmpÜhlÞppÛhkÛfeØ]cÔUTÔ\aÙ\cÚdmÞt{䉌쭨óÎÆñ×ÍîËÀᣚޑ†àˆÞ„‚Þ‚Ýz~ÚrwÛmqÚdmØ^jØZgÓZbÌV]½LT‘+EzBa=a=i;d>{"B‰8Nb8Z
+=jEÄ‚†ÙœšÄv}Ì…Š?ZT:X
+6Z:t*Dd>]>b@€*F²adÅtkÆtnÂppʈ„Õ™ŒÓ“‚ÓŒyωzΈ|χy·zˉ|̃xÊ„}ËxÌ‚xÇ‚yÇ€wÅ~zÉ}|Å|zÃ{Ä€}Á|vÄ}wÂ~vÀyuÁ|xÀyw¼zw¼xuºtw¶op¶np´ko»tuÔ‘{⪂괂ﺂì¹î·‚ìº€ì¹ƒìºƒì¹‡í¼‰ëÀìÁ‘íÄ™ìÅœîÆœìÆ›êÆžêÅ¢Š-G‹,H‡.L‡,G†/Hˆ.H‡.I†(G~%D€&Cx>t:q:Š">¯:FÍ[[Ùroà|lå†té‘xê”|ì›xìšyë˜xí›|îœzíœxí•ué‹wç|dàlZÎZS¬?M˜*B’,I›3J¢>T©Hi¨?N°CN´FO¹JQÁJSÁK`°M{’J¥‡¶ŸyšX|w1f;ošU…ˆGzs-_]“‚Nzc%Y^&\e&^d&bXWqBt’v¨|Cv†UŽ\Pf'RgO]J`Dj$MYBXAY@V=ZBWC\#F€PvX;^5o =R>\=—CZ¢Zvš>a®PQÖ—Šºxyx2QO>H 8J9N 7Y=DPËre¶JR¾ZaÖ¤¤à±£å¾®äʶƫ”XBJ :UBlCr:‰#D¤8I»FRËNUÐUXÔX^×Y^Ú]cÜ_aÞgkághânpâtvåtwåzxäzv䀀戂猄êê—閎Ꙏ뚌ꗒèˆê’†êƒçŒ„æ‡{ä|âxtàsqÝknÚgnÝhjÜijÙbdÙZYÔVa×VYØ\cÚ`làruよêœñÈÁòØÎðÍÀá¥ ÞƒàˆƒÞ†ƒÛ||ÞuxÜzÚmtØfpØ_lÕ^iÒZ]ÈV\·DNŠ&Bp>X=e@i<iCx)Bˆ8L]8V
+?a>»x€Øš˜Æw‚Ë„‚ Vl^ER 9V:n$@eD[@h>“8N¼ihÂsjÃqnÀopÍ„~Õš†Ô•‚ÒˆxÒˆ{Їz͇y͆}Ì„y̆xÍ‚xˆ}Ê€tÉyÉ€|Ä~{Å~zÆxÄ{Ä}zÃ|wÁ{tÁyvÂ|xÅ{xÂ|x½{y¼xx¸sp¶pt´mp´oṗxÞ¢é°†í¸ƒï»ƒïº‚ï¶î¸îµ}íµì¸…í¸ƒìºˆì¼ìÀ‘ëÄ—ìÆ›ìÇžìÆîÆžíÅžìÄžêß-Hˆ/J†-L†,J‡*H‡.L†1O„'G~(H|'Hv Bo>l=„ =­>KÍYVÚpjá~mç†oé”têš|ìšyê˜{é—zì›|ìœxðxïnê…næxdàm]ÐYP«?L–,B'C–.L¦Jb¶iЬ@S®>N·GT¸F\ºTyÀq µ‡¨¦w’ƒLfn*XdUƒ>s¨qššT†s2dg˜€JqZOZQzH…l,fq0p_ a‚Yššz°‰P‡”qh(Z`!Nd"Pb"RcGl(QXBWDT<T>YET >^"Hr5LhCkAn<`@vKHc­r‚¸`dŽ)G°QUÒŒv¼|}`?J;P:R =^;¶ji½a_´LXÃnt⿵㾳æÄ²àʳCJI 9M <^>{%Ds='B¤5F¹AOÆJSÌPVÔX^Ø[`Ù[`Ý_`Übdàjnágoârtäxzåxxä~~æ}{悀狄쎅ꘊë”떎ꕌ閌鎉钉錆èŠå†zä|táxtßkiÚbhÙcgØbeØhjØ`dÕX^ÕX[ÕT[ØY^ÛckàjsညéœñļóÖÊñÒÄ㪧݇‚à†‚Ý„‚Ü~ÝsxÜszÛhrÛfmÖ`hÕ^hÑ\dÈTZ®@N‚ AdBX@h@jDnA|*DŠ:NY6T:a <´lvÖ’‘Èt}Ã~«^nj"FP :\<k>`BXBj< P`ÂohÆtlÃrnÅxpÐ~ÔzÓ{ÒŠwЉxÏŠuÏ…{Ì…zʈzÌ„xÊ‚}É{Ê€vÊ€wÈ€wÄ€|Ä}tÆ}vÃ|xÅ~zÃ{vÁ{uÀ|ÀzvÀxwÀ|w¼wyºuu¹tu´no°opÀ{sÖ–u䬂췂ﺀï¹}ï¸î¶}í¸î¶î·í¸‚캃뽎íÀ”îÄ–íÇ›îÊ¥íÊ£íÈ îÆìÚêÄžë Ž5Jˆ-Jˆ.Jˆ.Lˆ0L„0L,J€+J|'G{$Ev@l;l8„&D°CKÌZXØnhß|läˆrèŽyê–ì˜yê˜xé–zìŸîž|ðžwïqêˆnåyfÞk]ÎVV®@M–(B‘*G“'H«Pb°h‹ =X¬:Z¶Qx¿u£Å§»y¹l€Œ:bTBaUw2m¢e•º ŽEvˆ\yBj]SXVZ$]…^˜l<qi,th4n˜†»”qŸ‘\™„Z€€E|_JeOf.Vc Lj"NX@Q;O<O<SBX?r$C9Qˆ.Cˆ1Kf=€.Q4]œW~Í͆–7Rw"F½`\̃j{(LF4J
+9H<~8NÆxo¶U^´VaÔššæÀ¯æÅ³âȱ¯ƒnO:N :N
+;c@‚*Fs;‹<¦2E·@LÂJRËNVÒT\×]`×[`Ú`dÛ`dàcfàlnânoässäxxã~~å|惂ç‚}éˆçŽŠê”‹ê‹„è’‰ê”Šé‘‡è’‰é‚舀æ‡|â€yàxrÝhfÙabØbhØbfÙ`cØ^`Ö\`ÔRVÕRXÕX\Ù\fÜcoà‚‰éœ ð·óÓÉòÖÉè·´Þ‹ƒßŒ‰ß€}à{~ársÜpyÙjrØbjÖ`hÖ_hÒX\ÆSU¤5JxBZ=VAfDt$DmA€)A;R^ 8T >_Bª_lÑ“’Às~Æ„‡°gxn(HK
+7b>e@^=X>w*J­YaÄujÇrkÄpoÈ|uÑzÔŽzÔŽxÕŽ}ÒˆvÒŠyψz̈wΆz̆|΄{Ë„zÈ‚|Ç€}Æ‚|Æ~yÆxÄ~xÀ~|Ä}xÃzu¿zwÂ}wÀxu¿vu¾zw»uw»vx´su¶knºpr΋uà§{è¶íº‚ð»€îºð·|ï¶zî·~î·|ì·z뼃î¾íÂîÆ–îÇœïË îÌ¡îË¢ìÉ ìÆ˜ë–éšêÂ0JŒ1L‰/K†0N†5P…/N„1P‚(Hz"Fy#FsBl<h:€$B¬9FÌZZØofàziæ‡tê’yë–|ê˜zê–yë–yì™vîœ|ïœsî‘pèˆoçyeÜn^ÍXS­9H•)?‘*C”&F©>QÀwŠ«P³TwƆ¢ÅrŠ®Sx®d±f{&XbTz,e a¤l–ŠBjŒS‚z>ie#Z`"`\ Zt@€{H„ežq6u|T’‘qª‡Y•o¬u>l˜r¦d#Pd$Rd)P`Ff NV=P 8M8H 7V>jH=N«Zg:K‚&@b@7[’Hw¸qƒâ£˜ß¥‘®WdYD’7F¬jpkBC4@4S:²ii¾ib²Xd¾dhݯ¨åÁ°ãƮģŽZ4K
+6P 8N
+6i!A†0Hx:Œ!;¡1D¹DNÇFNÌOYÒX_ÖZbØ]`Û[cÜ]`àdjàdjàlqârxæwzå|~æ{vç~憃æ}熀掇æˆè„ꎂèˆèŽ„èˆè†å‚wä{tßvvÜihÚdd×^dØ_dÙadÔ[cÕY]ÓTZÒSZÔVZ×X`Üjmá~„蘒ﴮòÑÆôÛÎìźۂ{ß„Ý|ÝzzÞttÚpvÚmtØbo×]jÖ^fÐZ\¾HR›/Iq@T@Y@`Av"Cs'Gƒ-G<L]6P :^@£Ndё‚ŽÈ…ˆ´pwm%HH3`:]=[<Z:Š5P¸fhÇvoÈqlÂpnÍ„{ÔŒ{ÒŒxÒŽxшwчvÎ…xÏ„vÏ…x·yΆxÊ‚xÈ„zʃ{È‚xÆ‚zÄzÄ€zÁ€}ÄzÄ~x¿}yÁ|vÂ|v¿yv½vs»vt¹ww¸qr±pq¶lpÇ|tÚ˜|æ°~ì¸‚í¼ƒð¹‚î¸|í¶î¶}í¶„í¸íº…쿎îÂ—îÆ˜îÈ™ðÊ îË¢îË îÌ¢ìÇŸíÆ¡êÜêÃìàŽ1J‹1JŠ2J„-H„.L‚+K‚+H€(Fz&Dz @s=l;c7<ª<HÌ]ZØlbà~læ‰ré“ê”|ì—}ë˜|ë–wí˜vîœzî›xï”sêŠnèzfÝl\ÍWO¬<G’+@’(B’'Bš1L¹R_Æx„ºk‹´Z€§Lt§Rz¶_}°Zw‰/ep \Aj¨hŠOp9k€Kzv<l|T`!Yn4sIˆv@vŠhžj(eƒaœ‡^š‰\’žˆº{<q‘ršf#PYCZDb!Kc HX>S 8T>O:n FfP|*E©QY >PwB2`Fi¬^r³FU؞᪚½nr^<s:…8JO5D2D6v*CÄugºTXºXcË„äÁ´æÆ°Õ¾©p1BJ:R 9O
+9P =j<’9Rz:$> .B¶?KÈHLÊNVÔ\`ÖT\×Z_Ú\bÛbdÞdißdmàjmärväpqãzzävwå}ç…|æ€}æ|èƒ~æ†|挄è‰çŒ„åˆ€èŠæŠå‚|âyvßpoÚhf×b`Ö^cÖ]dÖ]`Õ[bÔV\ÐSYÒRXÔTZÖXcÛflày~æŒìª¨óÒÉöÞÒðÍÀÛ‰†Þ‡„Ú~|Ü{zÞsrÜrwÜhpØen×_kÔ\aËTW³FP-I^AV@`G_<v#Ev$Dƒ.E‡6K` 3R5]@™DZÑŠ‹Ì‹’É~€¶v{s+KI 6b@T:[?c@˜EV¿nlÈtmÈpjÄtpÑ„yÕŽzÒŒxÒwÒŠ{цtÐ{pφt·vΆtÌ„yË…{Ê‚wÌ„yÉ…{ÉzÄ~xÆ€xÄ‚}ÀxÆ|xÃ~zÂ|vÂyv½wuºvu¾zx½tt¶st²nrºrrÒŠxá§~ê´}ðºƒîºð¸‚î·î¸~칆켈îÓïÈ™ïÉìÊîÊœîËžîÉ¢îË ìÈ¡ìÈ¡íÆžëÄŸíÆ¥’0J2L4Jˆ,Lƒ0N‚(H„+H,J|'Dt=m;i9c9~7«9EËXZÙlaâ}måˆxç‘zé”yí™}íšxíœ}îšyîœyñšwï•sé‰lè~bßm[ÐTK­;H–*@“(@“+B˜1F¢?N®E\µPj®Y‡¥c“§c–¶g޹d„‡6fdR|9p’T…>qF€>x~F„c!Yt:xzB‚r3pŠh¢O‚p4t~Z—zC€fš¢·x4prJrg*\N<RAV@`E]?X>U?TA`El4d€>b6R‘8S†*Q²w~¶a`µSX+GŒ9B­h_’JW^:W4dDN 5K9R 8 S[Æl^ºWb¿clÞµ®èÆ®ÞĤ][K 7P<S9S
+:R 9n(F–AT€;Œ(@§2C³<IÂGLÌPUÐSZÔZ`Ú]`Ü\aÜ_dÞahàeiàjnälqãqvâutäwwäwuäzwæ~yå~{å|{åƒæˆçŠæ…å…€è†~ä€{â|uàrrÜmnØddÒZ\ÑY]ÔVZ×^bØdjÖU^ÖT\ÓV[ÑNV×ZbÚclàx}抌좞òÐÆöàÔñϿޒŠÝ‚~ÚÞy|ÞxyÚqyÙgoÖfnÔ^gÓ]cÃUZ§>L~AT<SB_>cCw(Gx'D„+Aƒ/Dd:Q4Y ;“9T̆‡ÍÈ||¼xx€8UV;\>R9Z<v&I¢S\ÃtoÉtlÆqmÊvlÒŠ~ÒzÒŠuЋxЇz͈x΂sÎ…t˃t΄vÌ‚ẋ|Ljzʆ€Ç‚wÇ€xÇ‚vÄxÆ‚xÂzÆ|tÂ~y¾}xÂ}x¾{v¼usºzvºss¸mo´mrÅ~vÛŸ|氄ñ¼ïºð¸|ï¶î¶~ï¸ƒì¸„í¾ŒíÃîÆœðÊžîÌžîÊîÈ›îÉžíÈœìÈ¢ìÉ¡íɤìÉ¦íÆ£íÇ¡’2OŽ2K‹0IŒ0JŠ.J‡0J‡0I‚.K| Bw@r<g:` 5y8¨8DÊXSÙj\à{måˆxêzê•í˜zí›|í™î›zðŸyò~ð•wëkç~bânZÐVP°@K”,D&B’,Eœ2G¤;T©Hj¶\|´Tt§Ot¸`}·f¦Xr'Yt*^‚@q}4j|:nŽWŽ‚Ho0et:u|D}n.rn2iq¢c%[e'_~X˜p3s‹g𣑷€>~d0T‚P†N?SA[FU>^FdF\ET?Y =e"F7as&H…/TŸG\Æwt¾HOž3Fy H‹Oi†C_aEP5W;]@F2Z<ŒBU»d_¶QV»ZaÍ‚„äÀ¨Òš~¼†{Y9J5K 5V 8U8T 9s*EšJ^:”%<£/B²;HÀENÊOSÌRZÔW]×[\Ú]`Û`bÜdfÝ^fàekâlqäqvãsråxyãxxâxväxzã{z倿‚|僂艂æ„~戅èƒ}â€zàxtÞssÛpn×`bÐRYÍNVØY`Ù`fÜdfÙ]`ØX_ÔW\ÓTZÖ^cÛdlàrwçŠêž™òËÄöáÖòÓ¾Þ—’ÜvrÜvuÞxxÞzzÛnpÖhnÖbjÒ[cÎZ^»T\›:Nd>Q>UB`A]@v"C}*Eƒ.G~(>j<U4\ <…-NÁ|†Î•Æ|€Å€˜Qf\<T:L:U9…2M³_bËxmÌwkÆsmÊ{vÒ|ÒzÑŠ|ψzΆx̆{ΆxÌ‚tË„tÌ‚yÌ~tÊtÊ‚{É‚{Ê‚uÉyÆ‚yÂ~ÆxÅvÅxÈ}rÂ}xÁzvÂxw¿vs½us¸pq¸mq·suÐxâ©ë·‚ñ¼„ñº‚ð¹~ðº€î¸|ðÃŽðÆ—ðË ðÊïÊïÊ™îÆ˜íÆ˜ìÈœìÈ¢ìÉ¢ìÊ¢ìÉ¢íÉ¥ìȨ“4I1JŽ2K.L‰0HŠ/Jˆ,E‚&B~=w;t:f6`
+2{7¨6BÊWTÙi]à}oèŠpê‘xë–yîš~ì˜~îšzîšyð~ñ |ò•víŒtæ~fßl[ÐWR¯AJ*AŒ"?–-L¥@^²\„¾d†¶Tm³G^ªMmµRq¹Ri™<ht%]-b†Asv,fƒI}–fšz7js6nt6ln-nc"a„]‘†XˆURh-nŽl¤q1s…_™žˆ¬ŽUŽ^ NŒf•WDQAZLb!Sl/X_CT9J 7^Bn&I~7a—O_™Slœ<TÆnYÈ„s¯dlBX‡=Po'FV:N 7X>K
+;Q>œh¼u|·fm¦P\ŸPfÀ|wʈ|À‹Œ°xn%JS 8O 6Z8W6W@u*BK]%<&=ž0C­:FÄKQÊORÑTZÔY]ÖYZÙX\Ú_bÞ`eággáhnánqämnáoqåxsãxväuuåzvã{zæ}~å~xä‚~ç|æ„~æ„~惀â|{àvsÞmlØmlÑSYÈFRÐQYÚ_eÜgiÜelÝgmÜhnØ`g×X]ÖY_ÙblÞlp芊ôÈ»ùáÓóÓ¿ß•ØtsÜuqÞvwÞtw×lr×djÔ^fÑ]cÈW^³N]…&CY@V@Z?aB\A{%B.H€+E€+Bf;T3[ ;r>»v~Í“•Ê…‡Ì„}¤\mg=R;K 9X<•GZ¼ikÏ{qËzpÊtlÏ€tÒzщw͈zÎ…xÍ…{Í…tÌ‚vÊvÈx̆wÊ€sÉũwÊ‚wÈ‚{ȇ|Æ‚xÄ‚~Ç€vÇwÄzÁ~vÀ…~Ã|v¾wv½vr¼rq³ll¶npÄzwÙ˜z鲂ò¾‚ðº€ð¸ð¸|ð¹€î¸‚(ïÀŽðÄ•ðÈîÊšîÊ îÈ™îÈ–îÅ”ìÆ›ìÇžìÈ êÈ¥ì̧ëʨêÈ¥ìȨ”6N’9O’2L1H‹0H‹.F‡,F†(@‚%@};v;f8` 4|9¦<HÍXVÚjaázmæ‹vê’|ë–~ì˜|ë›}횀ï{îž|òzñ–tìŒpædàmZÐVR²<J“,K”-V¦Fq»f‹Áe{´KZ°EZ¶IV®Pq¸Sr¹Pk‹8hz,`i'T†Ay‚;y”b“ŽZ‰z2hx;nh,^o3pZ Ut¥t;nPQe*bŽp£x8€vH{ ®“b–\Q|Y€j'^[Ll+[g%PX<^<l$IN
+4U=iH…6Nªj_ KMf=q%K’@T¥Sin"DT:P 3K
+2R 4T 9D:‚LfΔ‹Ø‡Ï‰Ä†‚·w„¸~ˆÌ§šÒœ…žKP[
+4O5R9\7T 7U <u.H Na’0CŒ!< 2E¶>HÃJSÌPWÑX^ÕSZÖ]bÚY^Ü\bÞ`càacàhlâlnâmpàmpãppäwvãwtäxuä€|ä~{ä€zä€yæzå…ã‚å‚~â~|ÞvoÞrwØpoÐV]ÉDMÔR[ÜchÞjkÞejßjjÞkjÞjmØZ\ÔQXØWXßlo熀ó¿°÷Ô»òζۇÚtqÜwuÛuxÝnrØipØdiÓ\eÑY`ÆX]¤BPfDR<T>X<_?a?u$A{)G~+D~&Be:Z 6^=f?´mxÒ”“Í…ŠÇ}~¨bln$CS:H 8Z<ŸPbÄrkÓyhÏyhÇsoÒ‡zÒŒxÎŒ}Έ}ψzψ|ΆwÌ‚vË‚yÊ‚uÈ‚wÊvÊ‚sÇxÈ€xÅ~yÆuă€Å~zÇ€vÆ‚xÄ~vÃ|tÂ|uÀ|xÀzyºss»sq´kq¼otΈxߢ|ì¶ð»„ò»~ð»‚ð¹zð¸…﹂jïÑðÈ—ðÉžïÈšîÉ›íÈšîÆšìÆ™ëÈšìÇíÊ¢ëÊ¥ëɧìË¥êÊ¦ëÆ§–=N’4K1H7L‹0F‹3H‡*B‡(A‚$?€ ;z ?k7e 6†"@©?JÍZVØj_àzlæŠré‘zê–zë–zꘀë–{ï™zîž|òŸyð—xìyämÞj[ÏZY´FX¢?a§Ol«Pj®HW¦?R©>P°AS¶DX°Tu¼Xt­Pv†6gq&Zf&[ŠC|‹N†Ž\ŒŒM}8ll-cXNh(f~T‘Œen.eXXUTˆb˜€C‡p3qœ¤¢°`ZvPsŽb‘SD`EZBY@g=‚4PN
+9L<WAl-TcFX8R<^FCf—Rh0LV8N8N5X:G8D3®„ŠÐ”’ØšŒ×•ڜघߨ“֠Ц[al:P
+6P
+4T6_5Y=X
+:x.JœL\’.D’#:¨4C¸<DÆKRÊOVÓWVÖY^ØZ_ÚW_Ü[dÞ^hàbfáklâflânrâkpärtävvãuwäuvâtwäz{ä~xã{}ä|æ~å‚|ä€zá~{ßvrÝrtÚmlÑT_ËFP×W`ÞccÝa^Ù^WÔVN×abÚ`]×\bÓP[ØOTÜagävsì˜ï¸¨ô®콬րvÚuuÜuuÜruÜprØmtÓirÒ_aÊ[[»QX‚&FX?V@RAXE`Ff@v@‚/Hv"?&Ab5b;\:Z >¦_pГ”Î’“Ãxz¨dpt$FU<H 9gA¨W`ÊzpÐ|fÍunÈztÓ‹~Ñ|΋|͈}̆vÍ„z̆xË„xÊ€vʆuÌ„zȃzÈ‚xdžyÆ„zÄ„~Æ€yÂvÈ„xÈwÆ€wÃ~wÁ~xÂ|w¾wx¼wv¾tp¸pr´mr¿tqÖ•€äª„î·|ð¼‡ñºð¸~ð¶~ð¶ðº‚ð¾ˆïÃïÄ”ðÆ˜ïÆ™íÈœîÇ îÆœìÉŸìÈŸëÈŸìȤëȤë̪ë˧ë˦êɨëȧ’2J’5L’/G‘0J/HŽ,CŽ-Eˆ*B„"?~!?{?t<n8Ž&A°ENÏ\]Úoià{læŠuéxê’|ë˜{ê˜~ì˜}îš~ðž~óœ~ò˜xìŽpç|dÞnbÐ\_´Jbž<\*L“,Hš3K¤9J«=P°DU¶DV´Mj¸UxŸPwˆ5a„*`v,b‡D}„D|›l”˜V†}6hi(`J
+Ej6l Š¶†Hj)]l/qVVW…N~>Š—v ² Âv3uh5]ž~§ZGXGZDu-Tj"@€4NN 4M;N<Z@g#Od![^M h‚¨w–c;P
+6Q8R<V9M 7E<\DȤ–Ö¡˜Ý¯Û¦›Þ®¤Ú¬œËž”UVb9S4Q1T
+4X5b=Z 8[ ;t+EœK]”5Nœ)>®8D´=HÅJLÊPQÓSTÖRT×WYÚZ\ÛZXÝ^aàfhàdhâfjâlpâlnæwsäqråvxäxuâ{xãyuäz|ä}zä€~ä€{ä‚zä€{â‚€àysàsrÛljÓblÐPYÜ^^ßbXÏWQˆ6t6š%9½>BÄCEÐRRÖTW×VZÞbdèŠ‡î¬¡ï»­à˜‰Ú}zÛvxÜuvÜttÜnrÙhoÕ^hÒ\`ÆZ^¦APe?T?WBT@ZGcFi>}%C…0Dt>(De8f8\ :X
+<œVpÓŒŒÎ’”Ânqµnvz0MS>VB|,J¸dgÌ~oÒ|nÌyjÊvÓŒ|Ò‹|Ήz͇|̇|̈{Ì„yÈwÈ‚xÈ‚{Ì€vÌ€vÉ‚xÈ€zÈ‚xÆ}wÄ{zÃ~z‚|Ç~tÂ|tÂzrÃ{sÂ}t»yx¾yx¼rpµpt²kpÈ}tÜ™~é¯ñ·ñ¼ò»~ð¹~ﻀñ¹ð½…ðÂðÆ•ïǘðÇ—îÅ™ìÆžîÇœìÈžíË ìÊ¡ìʤì̤ì̧ê˧ëÍ©ë˦ìÉ¥êÈ©“0J’0I‘/G-G.F‘.G’1GŠ)B†#>€"?€$>y:{;—/DºNVÒbaÝtlà~tæˆvévé–€ê˜|ì˜zíš~î™yï|ò}ï”{ìqç~hÞn`Ð]d¶FT—.G%A•.E5E¢:J«>M´BM¸DS¶Md§Qy˜?h…1\•6gz0d„Bx†H{±p‰”Iwv1hVHLM\’•m”l&`j2f|@‚Z'\vH}„Q~B’j ªš¶ŒOŒ`%S›„¬\KTDW?y5Nt$Du(Da?L
+7J 8L <T@n-^z1j¬wŒ®dldDV<YB^@R9E
+;F9ˆRi˄ז‹à¯˜ß®Ÿá·©Ú¶¨¨hnV2R
+4T4S 5V7]:c:_;Z
+9w*H¢Wdš9P¤+=°=JºAHÅFLÎMNÎSVÖRUØVXÛZ]Ü[`Ü\`àbdàdhájnápsãopåpoâxvävtåtvâuyäwwä~{ä€|æ€|ä{å€yä€}ã‚€àytâvqÞspÛflÓQZÖWZÜ\ZÉQV¨7P™.K°BT¶CR°7J¯6DÈHKÑRWÛ\\ávt袘謟àŠÞ‰ƒÜuwÜsvÚpuÙknÖinÒcjÒ`bÃVZ…(H\BVCYCTC`C`@mA‚(B‚(Du'A‚)Af8f7d:T;@ZІϔ’µgnºz€€2NQ:o F“;PÂniÐ}oÔykËvgÎvÔ‰|Њ{ΈzË…yÉ„wÊ„|É‚yË‚vÈ‚zÆ€zÊ€xÈ€xÉ„|Ç}È€vÆ€zÈwÃ~vÂ}xÆ{sÃ{tÆ}vÄsÀ{wÁxt¾xw¸ru¸pr¸psÑ„wá¢}í³|ñº‚ð¼ò»}ñ»ïº„ñ¼†ð¿ŽïÆ”ñǘïÇœïÉ›îÇìÈ¢îȤíʤìË¢íͧí̦í̦į̀ìͨíͪìˤëÈ£ìÉ¥/F‘5K’.F“-F’,D“.D‘*BŒ'A†&A†(B„&A‚$>‡#@¡7IÀSZÐhhÜyoá€rç‹uè‘zê•ë˜|ê”zì™ïœ}ðž€òñ˜{ìŽuèkák[Ò[Wµ@Hš.F’&B—2Iž9K¦<M¯BL³DPºJZ¸Mn°X~Ÿ>fŽ=fŠ3c{6g€>pw1g…Cnv1bj'`M Jq@{™w „P„i$`uF||G\ZxJ}‹`™yG|aœ›~¡Ÿv­l,dœ†¢j*YF
+8K 8^>aAYg®e`f>LAH<J>O@†T‘b€jFR :f Hf@j Ha Fl%F‚6Z©^d¿qtЄzØŽ€ß™„ߦŒ½yr)BP
+8W :Z<Y=]<_5c:[:\B|.J£Zh¡:Oœ*=´?JÂCHÌNQÎKPÔTY×UYÙTXÙZ\Û[`Ü]_àbhàbjâiiâmpâpráooãtsâuráooäxxãw{äzxä{xåzwæ€|äƒ|ãyäƒ~á}váusÞvtÝpsÔ]gÓRZÙUZØYZÚ[\Ø[^Ø^dÛ\[ÐPWÃKWÃFQÌR`ÖYhÜ|ˆæ©¢äŸ‘â„Þ„}Û{|ÛtyØnrÙipÓfpÔ^fË`d®FUiBZBYDWEQBbEbBo B…,Dƒ.Hv&B‚,Be5i8h<S=|-Nʈ‰Ò”‘¹px¾~~ˆ@WT?n#E§OZÊwmÑ|iÑ|iÊ{tÏ„zÒŒ|΋|Ίy͇v͆wʃwÌ‚wÍ‚xÌ‚tÈ‚}È‚zÆ…}È„|ÈwÂzÄ€xÈ€xÄzÄ~uÃvÀ|vÅ}rÁytÂytÀyt¼vt¸tt¶mq½tpÖŽwå¥{î·|ñ»ð»€ñºƒñº‚ðº‚ñ¿ŠñÃòÉ—òÇïÉœïÉœîÉ£ìÊ îÉŸîÈží̧ïΨî̧î̦į̂íÌ£îʤíÈ£ëȤìÈ©”,E4G,D”0D+B(AŽ+FŠ*E…!;‚"?†)Cˆ)C/Gª<OÃW^ÒlnÝwqâ‚tçŠvèŽxé’zé’{ê”{ì–zî˜|ïò¡‚òœyëvè}gÞqeÐ^V¶EMš.IŽ&A–0F8J¤:Fª@P±BQºI^º[x¸Sjœ@d2YjNv/_„Bwt1bw4`d"RN Gh,d˜l™†N{l*_y=wu:rq4mj(ltFx‹`•t5w‡^œ^Žª’¼„Hƒ–xš‚K}G9K;hG^>¼ijÜ‹t˜HVX6? 9E @WNŽ^„€@h\LH :€<\‡:\ PižOf¥Yp±q€§NR³[^½\`¶fnÏ­ªÈ°¥f$<P8P 9Z<d.Qj>^e&J`6b6[6^Hw-Jª`m£EY.@²:GÂHPÌJOÎPSÔRXÕVZØV[ÚYUÙ^eÞZ\ß_eÞbgßdjãlnánoâmnátràptâqsávuättä}~âuxå{xå€}å€|å€~ä€|äyâyvàxvàtpÝlnØfjÙ`k×UYÞX[àYZÝ^^Þ``×QXÔQ^ÔfxÕ…—ܨ嫤欞晎⋅܀Ý{{Úuy×nvÕhpÒbkÑcfÄX\ˆ/L\@XCZEVEVE`CdDnFŒ9L„2N|(B€*Df8k9`7V
+>qHŃˆÒ˜¼ls¿{~”G]^Dl$B·`fÑxiÒ{pÓwhÊ{oÒŠzÒ‹zΊzцtφzΆzÌ„{ɃwɃwËvÈ€yË€vÆ‚zÆ‚{ÈzÉ€yÆyÅvÀ||ÁxÂ{¿|sÁys¾{wÀzt¾|x»tq¸po¹nnÂztÚ”{讀ï¸~òºï»}ñº€ñ»‚ð¾‡ñÃñÄ–ñÊ›òÉŸðÈðÈžîÉ íÈŸîÈœîÊ îΣðͦíÍ©íË£íÍ£íÌ îÈ¡ìÉ¥ëÈ¥ìË­‘,FŒ3HŽ.D’,BŽ&>‘0C”.D*E‡#B‚&B†)B+B”5MªBRÅ\aÔopÜ|tà„yä‹vè’zèwê’xê’vë–zîš~ðšzð {ðš{ëvçfÞp`Ò[T¸BJ™1F“'A–1Fž5I¢:I«?M¯?P¸K]ºRfÄQcªRyjNRDj$X?sv4bn']`U\ Vf–„Ho` O`Uu:os2pn4m{G„|Qˆ†V|Bl¢B€œ~§”[”™y¤”i”RCN9fD^B­ZfØŒnÄ|f]:@
+:E 9uJql#Gr&Et*Sz3V”D[¢Ph¬Zr¼€ŽË¡™¶mbªNR¦DU°ZeÅ‹‘äв›[ZN>R?S:^:c@g$DbDf;b:Z9Z<{2K«ao BQž-C³:FÅHNËMQÐPVÒTW×TU×VZÙYXØZbÚXZÝ^dß`dàadâhjäklânoàmmàosâqrãtvärqåz|ãzxæ|{âzzã€zæ€yä‚å}xä}}á~|ÞzxßtvànpÝlqÚajÛ`lÜagÞkmß{xÚtyØoz㊌벩踭赥嫟旑⌇Ü{|ÜyxÙtx×pvÔhnÏejÍ_b²LXdBXDX>ZFVETCdGh Hp$F’?N.E4J€%@n9t$@^:\ >hA¼v}Ó™ºjt¸u}‘CYlE€.IÂllÎ{oÐykÓ|pÌ€pÑŒxЉz·x͈z͈|Ë„zÌw̃wË„yÈ‚zÆ‚{Ê€vÄ€{Â|Æ‚xƃzÅyÈ~vÄ€vÅ€uÁ|vÁ~yÃ~wÀzx¾xt¿vr·sr´rqµpmÈ}rÞ›zë²€òº€ñ¸}ðº„ò»~ñ¼†ñÁòÅ”ðÇ›ñÊœðÈšîÇœîÉ¢îÈŸìÈ›ïÉŸîÊ¡ïÌ¢îˤí̦ì̤íÏ¥ìÊ¥ìÊ£ìʧêˬìÌ®‘.H4KŽ.HŠ.E4K”0F‘0HŽ+A†)Bƒ&E‚$?Œ,F˜;R¬HZÆ^eÕrrß~vá„xæ‹zè{æ‘të“xë–{ì˜zð—~ï~òœ~ñš|îtè‚jápeÔ`Z·DO–1H,F”1IŸ5G¢:K¨<K±AQ´CV»MfÌh€Åqˆy$WUHe&U~=up&Zo,jh#bŠf›^‚f'VSL[Tt2lq1oh1j~K„‡a—„QˆŠZ‰ašr3vŠf‘œn¤™y¢œzžu8kUEgHfD‘D\¼hrªAJmFLC_,S`$LNGw0T›\v¡Um¥\{¯f€À†•Õ¦ŸÄ€žDV¢LZ°\r¼v‚ܼ¬¼•€ZEVG[HZH`AbFg$EhAfBd>\A^Dz1O¨`q¡GZŸ0F°>KÀHQÊLVÎTXÔT[ÖUX×XZÙSVÚYZÛ]bÞ`bÞbhàfiàhlâlmâljàloàpsàlpâosäwuäyzä{zä}|å€僂æ€~ã€}ã€|ã}zá|áyvàvvÞvtÝqtßklÝimßnpâ|zæœäž™à}}ç‹ê´¤é¶ªè³¦ä®¡æšŽà†Ü}|Úuz×ptÕkpÑblÌblÄ^e9SZH[IXBXET@WIaFr&Jo E˜FSz&A…:O{$@o<x(B`<\ <\ >¬ivÔ™¸kr¸u~>S(K˜ATÄrmÒzlÒxeÒwi΄qÒŒxшv͆y̆|̇z̈zË‚wÌ„zÍ„yÌxÈ€uÈzÉwÄ€xÆ€zÅ|ÅxÅ|wÈ}uÆ|xÆ€v¾|yÀ|v¿|uÀzt»xyµpn¶pp¹pnΆvâž|í±~òº~òºð¹~ñº~ð¼ˆðÂòÆ”ðÊ›ñÊñÊœîÊ ðÆ›ïÆšíÉžîÊžðÊžîÌžïͤí̤íÍ¥îÌ¥ì̦î̦ìͪíήîͲŽ3AŒ0Fˆ(@Œ*C.E‘.D‹*F)?†&@~;~=‹)?˜@T²JXÇ`iÓqsÞ{tá„våŠxèxé‘vê”xì”vî˜|ðœ}ðŸ‚ó ðšuêvékßs`Ñ`Z¶FN˜0D*D/H™8N¤>O¨@P­DV¶J`Æe„ÑyµWpz,`]Pj&]~Bzo*d€B‚Ž\’•lj.Z]RTOZSl,`q3hf+ep9pQ‰y?tŠXŠe˜{DŠ}S~œw«‡Y‰œ{¢ŽYŠn-ap*Yƒ5aƒ:]›F]’;\n'Sl(Pj&LG>TL{;d¶t„¶n†½~Í”™Ò¢˜Ò«žžHPDRš9W¼hlÓ¬¢Ë¯—l.EVDZF_!N`"JbHd$Jh%Iq'Hj"HfA`B\Gw0O¢Zl¢M`¤8L´@N¾ITÊPXÎW^ÔV\ÔW_×[^Ø\^Ú]`Û]`Þahágkàglâikâhgâfißlnßkrânrâsväyxäyzãzzãz|ä{zã~z倀ä€{ã~~ázxàyvß{zÝxxßurÞutÝppÞpoâ|wèˆê²¤ç´¨âŽç˜ê´¦è·®è´¦ç±¦ä—Žà…Üv~ÛqwÚsw×jvÔgkÌfl¸U`fBYEWHVGYHXFYFk*Kt&Mt%D˜@Pw&Bƒ1F{"Cp >u#DgD\?ZD VeÒ˜Œ¼w~¾x~‹>UŒ8R­W^ÊvlÒ|jÏuhÌ|nЂtÒŒ|φzΉ~͇zˇzʃvÊ‚yÆ‚{Ê‚zÌ‚vÄvÈ‚xÈ€zÈ‚zÆzÄ{wÄ~yÆ~xÆ€yÄ{ÄxÂ~vÀ~u¾wrÀvq½xs¶rsµnm»qpÒŠwä¤wïµ€ò»}ñ¹|ð¹‚ñ½‚ñÁŒïÆ’òÊ›ñÊœñËšðÈšïȘðÆ—ðǘîÈ›ðÉœïÊ ïÊžîË¢ì̤îΨî̧ìϨį́íαëÍ­îÌ®Š*Bˆ.BŠ&@Š+BŒ(BŽ'@Ž+CŒ*B„!={8=‰(B–8O°N^ÉdlÔrvÝ~tâ†{æŠyè‘|ê’yê”tì“}í•wðš~ð ~òž{ð˜zì‘rèjßq^Ï]W·DL˜3H*B”0Fš2F¤6J¬<P°<R¿ZtÐv‘·Zw P|{/_h&Yo)av2j„H›oœ†Ptl)Ta(UWFYRZNp0en0bm0ck.ft<un/f…V‹€R…}Iq6p“lœ„P„¢„¯˜cŽw4ju2c“KxŒ@m†<`„7Z]>Z@g HMCp*X³ŽÄ‰’Æ„ŒÍ•–С¢Õ°§º€w™=Mž?Pž@XµjnÔ»£v9@U9Y=[>]>b:d<c:h=w(Bn%Bb?`8\?mB¡Yj¢N`¨:N±@IÃIOÈKTÑTVÕSVÖYYØXYÚX[ÚWYÛ]`Ý_^ÞefßegàkkàlnàhmÞfißikãgjállårrävvãvwäxxâxxàvsäzyãyzâ~yà{zÝutÞxwÝwuÜtsÞttÞupßywâ€|皎캯柘ç—츮뻮긨賡㓈߂€Ùx}×ouÚsvØgrÔflÊaf’7NYCZHXHWAXCUBXDq(Ho#I|,F“:N{$?…1G~"Bx >w;d6V 8X <‘AYÌ’‰À‚‡»v|Œ;QžNaµ]^ÐxgÕ{hÒr\Î~qщwÑŠwχx̆yʇyÌ„|˃yÈ‚{È‚xÇ‚zÈ€zÇ‚xÇvÄ€xÃ~yÂ|tÂ|yÂ|tÀ}Â~xÂ~uÂ|xÀv¾|tÀxs¾zv¾xq¹sp¶onÀtnÖwè¦{î¸~ñº€ñ»|ð»€ñ¿‰ñÄðÈšòÊ™òÌŸñÉ™ñÈšðɘïÇ›ðÈ—îÉ›ðËŸîÊœîÊœî̦į̀îάîͨìΨîͪîίîÍ®íͰŠ,Dˆ,CŒ&@*B†)@ˆ(@Ž+@ˆ$>†;€=>‹'B—=Q®N\ÉbjÒptÝ|vá†xæŒvëwé”xê’uë’xì˜|îšyñ ò ð›zì’tæ„làr\Ñ`Y¸FJ˜1EŒ&?*?œ4G£5I¨<R¸PjÊy“·Xr²Ui¥Rtq Rp"Zr,d‚;vŸl“YƒVAZFkBf[Na"X\Np/id(Wv1lh(\w:vp.i|Bn‹a—g*at:|ˆb‘—fœŸ€ª™iŽƒ@vm$O©nˆŒ=Zh Gm@Z;O 6p E‡5VPk¼zÆ€ˆÉˆ‘Ò šØ¸«Ò®˜¤IK§IRœ;P¥P\ɤœ’]TO>U;Z=j>]<a9f6c7i;}-Fo?_;f<Y
+8o ?œQežK^¥GY®<JÀFLÈKQÏPUÔRVØVZÙXZÚ_^Ù\\ÜWZàacádeàccâhmâeeãhlàhkàloáiißlnâljãqqâtrâtuâvvâsuäytáy{ä€zàzvÜurÞstÜxvÚ{zÝwyÞzuá||刄飖îŶêÀ´æ§¢æ™ì»¬ì¿³ê¶¦ç­Ÿã•‹Þƒ‚ÖrwØrx×pvÔioÐhn¸ZdiCWBYD\EZC]CU@_Fu)Gp%I…/F’7J&A‚/E|=}'@o7f8Y 6V >ˆ=Zʇ~½}ƒ¹mtŽ>T¨Vf½c^ÔveÔ{gÔvaÏ~lЉxцwΆv̈zʇ|È„~É‚xÊuÇxÉ€vÆzÄ~zÇ€wŃyÄ|ÄxÂztÂ|vÂvÁxtÃ~wÂ}x¿}zÁ~v¾zpÀxq½wl¹rq¶lnÂsmØ’vè­xð¸zòºòº~ò¼„òÂŒñÈ–ðÌžòËœòÊ›ñÉ›ðÇ—ðÉðÉœðÊžîÉðËžîÈžíÊ í˦ìÍ­íΪìͨí̪îΪí̪ì̱îΰ‰+B‡(Bˆ(@‡(Bˆ%?†!<‰%<…&@‚"@}"A€$?Œ.F’4J«JYÃ]hÏpqÛ|và‚xæ‹séŽxç“wê•vì–tìš}ì˜~ïœyñžzòœzísè…kàtdÒ\T»CH™.FŒ%>”.Dš4J£0MªB^ÀmŒ¶\v°JbÀap¢NznUr"Z…>y“Uˆ—l”x;kTGbRd,Wp5li+_c(Wm.f]L}Brn,[h.bo.kq/d‹^c#`n3q‰]Žœl›b”bœdšŠFeÊŠt8aFV 7p#Dz+T<ZžMb¡I`¬dxƒŒÌ˜Ó¬¤Ö¹©°b^DQš:O BW¼ˆŒ®lVAR<`>e?n?fC`:l;c8n @~,Cz(Ed<c:\<j>˜L_HZ¦Qe¢1E¹GTÆJPÎPVÕTZÙV[Ú[`ÜYYÚ\aÜZ^à^`ßehàagâfjällãdhàfiàkkácdàjhâhjâikáppâssàstáqqârqàtqâ|xàrpÝxvÝrvÝvuÛxxÛ~}Þ~yâ‚~䎈馜ðǺìÂ´æ§æ”쯥íÀ¶ê¸¬ç®›ä”ŒÛz|×ntØqvÔkwÑktÊek›?XYDYBXCZDXAZAYEbFs&Lj$IŠ4IŽ4J€*E‚/Fr8y%Bq=e=Z9S ?ˆ@]Æ€zÄˆŠ´js’=VµcjÉj_ÓueÓwbÏznÎwΉxÌ„xΊ|ʇ|Ì‚yʇ|Ì…x̆uÉxÉ€vÉ„~Æ~xÆ€|ÄzÅ€zÄ}xÂ~yÆ}vÂ~yÃ}vÁ€wÂ~yÄ}vÂxnÂzp»tp³pr´ml´moÃwmÚ—xë®vñ¹‚ò»}ò»ñ¿‰òÆ‘òÈ”ñÌœóÊ—òÊ™òÉ™ñÈ›ðÊœðÊ¡ðÊžîÈœðÊíÉœìÊ£ì̪ìЭíÏ­ïͬį̂îͪíίìÍ­îα†*D„&C…&A…$B†$@‡%?„%?%A€>z <ƒ&>Œ+E‘7L¥G\À\jÎmtÙ|yàƒyæŠzèvé“{ë“uê—}í™zîœ}ìž„ñ }òžyî“pé„làtcÕ^S¸GI”,A#>’-D™1M¥;V¼g½h«H^¸FV¿dr›Hvk V5o„<p‡N€‹\†j'X^M`Qa#Vp2ff(\l2jh+^h.bt8fx7gd*Zh-bj.b}Ju{C|[V`$^Œ\Œžx«Ž[›t°x‘²\\R0U@X ?|1O®at¦`zœLf Pe¶p~ÈŽ˜ÎœœÖ»¬¾„tœDQœ:LŸ@WµkoÄ ŠX8N:R;o#@€*GdAb=]8n9f>n<{-F~,Fp?c:\ 7h:›O`›DS¤Lbž0Dµ<FÄJRÏJNÔVYÙTWØX[ÚZXÛ[_Û]`ß`_àdeàdháhlâlkãgfãiiàehàdeàfhàflßjnàioàkiÞosàppÞqrÞmnÞtsÞnlÜprÝqrÜrsÛttÞzzÞ||á‚€æŽé¨›íÁ±ìÇÁ毳騫îĽîÀ®ì¸¨è°£ä–“ÙtyÖjqÖjuÒjvÓkqÂ`jlEU@Y>XDb&JYFXDXAe"En$Gx)H…1IŠ2L€%?.Fs >v"?v!<b9Y 9U
+>~7U¾wzËŠŒ·kn—E_¶`gËmaÑsbÑwdÌ}qΆrΊyΆvІu͈xΈzÌ‚v̆xÉ€yÇsÆwÇwÀ{Æ~zÅ‚}Å~zÆ~yÈ€xÅ}xÄ}xÁ~|À}xÂ|yÄ|uÄ{pÀxtºup»rm²or³ljÆzpÞ˜vê°xñº€óº‚ô½‰òÄ‘óÈ”óËšòËšóËšñÉšðʘñʘðËžðËžðÊœîɘîÈšìÊžíΧíΩíЭíΫîÏ­íΫîήîέîϯîΰƒ,B| @{ >€ <#?‚)D…'B$D‚!B~ >„#Aˆ&@‘5M¦DWÂ]lÏntÚ~z߃xåŒ{è‘xè”yê–|ì—|îšî{î¡~ñ¢|ðœ{ì–vè‚iàs`Ó^VºJO”*DŽ%B’(G™/O´ZsÀn†¥CZ²ASºHV¹]t”>mp&Yr*_]H‰YŠ„Hy_Lc"T_Nn5fc&X_&Xn9rh,b{Fxw:p~@st5kh.do6kp7m|Ftz@~YWh,d”l’”c—–r¢„¤p0[@@IB}0V¶`rËsË–£¿•ª¸–È•£Û³¤Ø¸¨Ë‹œ>H¥JU CW²^gƤŸx?KPDO@R?„3F•:Pd@a@Z8l>e=l=x(E‡8Nr"@b6`<h:”G]™>P¢L^œ5J²8FÁEPÌJPÕOSÖVZÚY\ÜZZÚ][Ü[[ß\_ÞggâcaÞfjáffáhjáheÞekÞcdÞehàihÞlnÝlhÝefÜjlÜnlÞhjÚglÜonÛroÚprÝkrÝoqÜzzàxá…zä‚zæƒtå„tê“虇쳘뛎苋ꈈæšâ’ÒfnÏ_lÑdsÔlsÐjq¡DYZHVAV>[Ea&LXBZA_BbAu)Hz)H†4KŠ8P~&Bˆ0F€-Fx">€(>e7T
+5X>n)L»w|Г’²dj£Pc¼ieÎqaÔu_Òx`Ëzh΄sÏŠwЈv͈{̇zÌ…yÊ‚wÌ„zÊ„{Æ‚yÇ}xÆ€wƃzÈ…wÄ€}Ä€wÆ€xÄ€zÂysÆ}vÂ}xÅ}yÃ|uÂzsÃypÀwr¼wq»tr´nk³kpÈ{lÞœxì­|ðºò¾óŠòÅ’òÊœòΞòËœóÌ™òÉšñɘñËžðË ðÌ ðËžíÊ¡ïÊŸí˦ìͦîͬíÒ°îЭïϯíάïͪîϬîΪîά€(Ex?x>{:~"@‚#=‚&C‚$A‚$B~=„ ?‹,C’2I¦FWÃ`lÐpqÚ~{à‰xä‹zè’}ê•{ê–}ì•~ë˜zî›~ð¢ð €ñ{ì”wé…hàueÕZRºCK•-E‰&H‘*L¥B\Âs‰¨Ic§:M¯>S¸J]¼l„?ifO[L_#W‰Z„“a’d"Mb$T^ Qf*[f$XZSd+cg(dq;k‰T’€Au†J~z>wu<rp4li*aˆZ‡w;q]Sh0c|B~d™˜s›‘h—TTMA§Td¥Bd¬^~И¦â¾´ß¾¾ç°⼩Ҥ’ FI¦JRœ8P«OXÈ“¢qfO 9Q=S:V;„+B˜AJ^:b:Y6n<m:p>-D|,Fx"?`@b :l<–J^8IœIU•/D©3B¼?KÉKQÓTTØT[ÛZXÝ\ZÚ^[ÛYVÞ^\à^^Þ`_àbdáeeâjmàjnàfeàfgßffâjiÝccÚ`^Ú\ZÚ[ZÚ_\ÚdfÚgcÙopÚifÚomÜkgÜolÞjbßhfÞefÜ`aÜ^eÜ[bãjpâhpävxæz}ãoxãeuãhrÞtuÐjh¿L[Æ[fÒkvÒotÆenrCYFWCXA^D\D^D]FcBdDy-Jo(F‚0J‰6J„,B‰4L'Bv>}(Bg9T 5Y <hFºv̬Za®ZhÆkbÒudÖzfÔvcÍznφ{ΊyφyΉyˇzË„wÊvÈxÈzÄ}vÈ€tÄ|yÄ€xÇ„xÃ~|ÄyÄ‚z€xÀ}|Â}z¾~~¿||ÃzqÄzrÂxq¾wt¼to¹rq´lm²hkÊ~qßšzí±€ðº‚ñÁŠóÅ‘ñÈ™òÌŸòÌŸñËœñÊœñÈšðÊšóËðÊ ñÌ¡ðÌ îÊ¢ï̦îÍ£ìÏ«îΫíЬîЭîЮíЯîάîЭíÏ­ïÏ«s?r>v=t<v<z=&A‚$A~ :}<‚ <Š*A’4H¢DVÁ_jÓqsÚ€yß‹|åzꔀê˜}門뜀ïš}ðž~ð €ñž€ðž~ì’qèƒjàraÔ[Q¶DK)F‰!E›6X¹i„±Xq 6Oª8O±H^ÂbzÃsЉ4a^L[Ir4lb!M|Gsl)[b&Xa&Vj-]f*[^!TTT`!^s@v’k£‚E|‹Qƒ†Ny?rp4kh+hl1d‹\Žz;|j5m~PŒL€Žg †N‚‹V—_˜Öˆ¬k–¡hÌ¢ªÞ¶´êɾèűִ¤©ST©LT¤CR¢DY»{}Ħ˜Z<P?R;\=V<l8ˆ4F_;]9a:f;j<v%Ax%C|(A…+E^6^:g:šRd3H˜D[’,C¡1Fº<HÆGLÏNPÖRYÚ\\Û^_ÚXVÚXYÝYXÝ[Yß`]ß^_àcbâhlâloâliájiâldßrgØ[T·9@®6>ÀGHÊSMÑYSÕ]Z×`YÕ\YÔ[VÕWXÕQQÒOOÓPOÑPMÐKMÐLNÎHRÝRVßWXßf`ÙbaÀ>D´3@ÆDMÂNSµ>L¸FUÍadÙrtÏov¦J\]CVDXA[@dDXB\BZ>fAf@‚3JlBˆ2Fƒ,D€*@8K{%>k8z&@p=U 5\ 8cD°hvÍŒ¬Yj¹jsËodÔzg×xaÔ|iÊvnφxΈvΉv̈zÊ‚uÌ„zË…xÇ‚xÈ‚vǃzÇ€wÃ~zƃv€{Ä‚|€yÆ‚vÂzÄ{¾}wÀ~yÀ|uÃ|rÄ{rÃ|uÀzu½usµrq±kn´hhÍ‚uá tï°|ò½…ôÅŽóÈ•òÌŸò΢òËŸñÌ òÌðÌ¢ðÌžñÊ›ðÈšðÌ ðÊžïË¡îͤïͨíЬîЪìЮîѰîЯîÏ­îÏ®îϯîЭîÒ­pAp>s>vAv"?}#A‚&@€=}>=†%AŽ.F”:S¨K\ÂblÒvwÛ~|à†yåŽxê˜~ëš|ëœ}íœ~ðž~ï {îŸðœuì“vè„mào_ÑZR´DM”-K&O¹m‹½g~¡:T£0Lª:TÃe~ÑyŠ¿l‚ƒ0`bQo)\|<iVE\HbPg*Zb(Xl1cm-`d&[YZ]^wJ—{¦‘a“ŠTŒ‚J€ŒVŒ}@xs=va'`o6j^‘gšNƒf)^xM{n3jy0]µj‚³pˆ¯^uÉŠŠÜ²ºÞ»½ê˼ÞÁ®´xxœ=L«KT¢AX³clе¨…JPP =ZB^@cAT8c<.>kA] 5d9b8h:r @q ?|+Dˆ3Jc 3Z 6f8”H\ƒ(F•ER‘3H–*@´<FÂFMÌRRÓQRÔ][Ù_[ÙZWØ[[ÚXTÚ\^Ý^_âd`àgeãfhájiâlläojânhßneÑTR±:N®;K¨.>¥*=®0<³6>¼:@Á:BÄ@HÉHLÂ>F»;D·8C¬4A°/=¸4BÄ?HÕGO×LRÖRXÈER·?T²6TºDXÇWfÆQ^É\bÖlpÖuxÇinv$FW@UDY>`BeCZ>Z@bBfAt*Gz*Jm CŠ8L€*B‚0E‹6Hz">e 5€0Az)D[8]@^D£ZlÊŒ´htÄvzÐoaÔ|hØxbÖ|jÌ}qЊẏyÍ’€Ì†vÊ…wË…uʆwÊ„wʃvȃ{ÇxÄ€{Å€u‚|¿{À}xÄ~yÃwÃ~zÀ}w¾{xÃ|sÀ~yÃ|uÅ{s¼xu¸tpµnm®jl¸khÒ„qã¦xï³|ò¾ŠôÆôËœñΤóÍ òÍ ñÌœñÌžòËœðÊ›ñÉ›ïÊœðË¡ïÌ îÌ¢ð̦ïͧíάíάíÏ­îÒ¯îÓ­íЮïЮïѰïЮïάl@l?p>q?v?|>€&A~!A~=€ B„$@8O•:U¯L]Ä`jÑvvÜ~uâˆxåyì˜~ë™zì›~îœ{ññ¢zð¢|ïœ{ìqæ‚lÞnbÏ[Z³BU˜/T°\€Är†£BW.J£2L²LhÎrŒÈm„¯_z~,\bKu2ch#O[HR?d&Rh-Zc,Wl5ff$Yj0bh*j^ bwH€˜v¦–k„L…€H…†K‡‡O„ŒT€Dv;y…L}Ÿ|ž„I~e'\j3n]"\ƒ>n·h{ÎmkÚb`Þbfä¼¶ìØÑæÌ¾Ó¬›¢LR¦ESœ8Q´\hΩŸª~oSAXA`<b<^9T;`6s$>s >]=b<j<k=o ?n@v(Cƒ5Jj=a=d<’G\„*E‘=O6K“.C°6D¼@IÊNSÒRRÔUSÕ\Y×VTÙUUØXVÙ\]Ü]bàbeÞdbàadàejáspâppâqmànhÙ\^ÔV]ÖW^ÏR[ÈFVÅ>LÄ<LÊ@OÐDOÒLWÕN\ÔNXÐO]ÐP^ÌK_ÊN\ÌObÒLbÚUmß`vÚe|ÞjƒÚb}ÕVrÒ]nÔjqÒfhÙilÜrqÔnn¤DRZDVBRC\@aB^DU@W@f?gA|.HpBr?Œ6Jƒ0I‚+DŒ8Hz"Ah;{.F€1K[9\<\BšLaЈ„¹muÍ~|Ôq_Õ~rØxaÑ~mÍ}rщxЉxЈw·xÊ„wË…yÊ„zÈ…|ʃxÈ‚yȆ{€zÄ€v‚Â~yÁzÁƒ~‚|ÁyÀ{¾|xÄ}tÂ~vÂ}xÁ|u¼vs¸uq´on°kn¹nlÕ‹pæ§~ñ¸‚ôÄŽôʘôÍžòΡòΠñÌ ñÍŸòÌžñÊðÌ ðÊœðÌ ñÍ£ðΤîÍ¡ðΦî̦îÏ©ïÏ®îЬïÑ«ðÒ°îЫðϬðЬïϬðάh@kAp?q>v>y?} =|>|=z"B†,EŽ>U•AZ­QeÂeoÓsrÞ}sâˆxævé™zê›~í›}ìœ}îž{ð¢|ð£ð¡ïšzêqælÝqgÍVb³C`µgˆÇ|Œ¦B\“,Eš.L¨<X¿bÈqжYv§Rp‚7bj(Wj&Rs/^^K^MXA]NVJn7ig%]d(Ws8xY^uQ„¦–¼˜g™n0jzE€Lˆ~KŠ…P‚‰P‚‚Gw‚Hxn2a{Do~D~l:vL„¥`ŽÜ}{ån[Ýa_ÓVaÛŽƒïÚËÛ¼«´pq GT¨FX²WeГŒÉ¦’`$FQE^DdAd@Z>U=`:p"Br <^9a;j?r"Ao!BpBr"@€2Hm?^@e>‹CYz)FŠ6JŠ6L’1H§7I¶@JÇMQÏOOÎSUÔYUÕTRÖTWÖXXÖZ\ØZZÞ_aÜabÞffÞghßpoàsnàqnáonánnÞfdÞZZÚVWÛVXßU[ÞRbàNWáKVäSZäZiã_pæZpèm…åw”æ{šå„œè„¡ë“¬ì µë¤±ìž«èwÞ_{ÚbvÒrsÚtvÜnnÖpoÂ__mAV?XCVBb@fB[AXAZAgAh Dy%CjBw&C‹:L-E†.G5K}(Gh>z*@„6O_=_<\B’B[ÊŒŠÀw|Ð}yÕs`×qØwdÒnÌ€rÑ‹tʉyˈwÌ„wʃwʆ{ʇzÉ„wɆzʃxÌ„{ÅxÀwÃyÁ~vÂ~vÀ€x€vÀwÀ|xÁzÄ~vÁzyÂ~vÂzv¾vr¹vu³no°gi»mf׋vçª~ò¼‰óÅ’ôΞóΞñУòΠòÌŸðÌ ñÍ ðΡðÍ ðËžïΠíÍ£ïΧîÏ©îЪîÑ©íЮðЭîѯîЬïϬíΪîΪðΩïϨñͤj>iBp@r@u@z!A#B"@z={?‰*F8L™@V«K\ÁalÐsqÞ}vá…væ‹tê˜~ëšzìzìž{î î¡yð¤î¢}îœvèzäƒzÚpwÉWrÂh‡Æ|Œ¢EZŽ)D—,Eš0N®KhÊuµVtµOh¦JlŠ9fm)\f"P‰S‰k(U_ LN>XKSHvBzp*^b!S~J‡V\xX‡®œ¼“e’d+cd(d{I€†W’Š]•D€z<p|Cq[%_i-\VŒ‚PŒ’fž¥h•Õy‰äocÚb\ËP`ÎyâÌ„x¤FQ¬NVÁgiÚš€Ö®˜„FPSGZM]EbAb@Z<X;\8g:n6k=^8c<p >k:t!Bt">~+Ht@]<g?„:O|$A8Kˆ6I‡&@˜.A¬:HÀIMÉLPÌKRÐTVÐPRÔRVÓWZÔXYÖZ`ÚY[Ü\`Ü`aÜglánláppánnänlåtláhhÞ``Û\_ÙVUÜWZÞTWàVZàLWâNZæP\åZmçetêy„錎휘뚘ðŸ˜ï©¦ï°«í žænÜ`wÕhwÕvyÜxwØllÈjl5JX@WAT@ZDd>g?X<V:_;j=l=f<j@~-D‘@Sƒ(@‹0DŽ/Lv=o:~)A‰<Ob>`<]D>\ˌƆÐ|uÔxb×r×xdÑ€r̃sÌŠzÌŠz̉{ΊwÆ…yɉ|Ê…xÌ„wÌ…vʆ{È„xƃxÅ„wÃzăwÄ€vƒxÂyÄ~x½}zÂzÄvÁ|vÂ~v½zwºzv¶qn²oq­fn¾ojØŽtë®|ôÀõËšõΞôУñÎòΞòΠðÌœòΞñÍ¡ðΤðÍ¥ïΧðϧðÎ¥ïÏ­ñШîЬïѬðЫîШîÏ©ïϦîΤðͤðͤðÍŸñÊœhCkAl>r<s>y>z<| =w<w>‡/J“:Oš@U¬HXÁ^hÒrpÞ}t߇xäŒwé“{êšzì}ì }ì{ï¡zî¢ðŸ}î˜|é€â”Í|¡ÁlÃpˆ B[Š$B‹$B‘+Kœ:[¹`ÄxެIf±Ib–Dkw,V|2ks2`šzžp*WT<S@UI^%X‚N‡m+^f!YwFzf"ff”¬š¼•f–n1p] Zv=vt=w|Mfž„P‰z?wn6hg-b€@rJ‚žx¬ªp˜É|˜âkiÔU`ÊhsÔ¯²Ï°¦˜?P°W`Æjfä˜{Ø•~]TVCXJXB_DbDcB_<Z<^7^:k<k<_=`:j>p@r At#B},Dx(D`<c={+Cz"@Ž8Nˆ6L"?3J®<H»BKÄHKÉMPÎQUÊPVÎPRÐVXÐTYÖTYØYXØ\bÙY\ÚadÚlhàjjâmiätpäplánfßhfÝbdØY[×W\ØRUÚVZßU^âYaæR\çP\ê\nìjxên|îu‚í|…ìxƒîn€ípì{ŒçxŠÜ`vØk{ÖrvÜxyÜttÒnp¹W\d>U=V<V@Y>h?d<Y;W8`8g8w(Ba:h=€,A–BV„,F‘8JŠ5Jz$Bw$Bx$@‹@Rg:_>\FŠ>^É‹ŠÉ„‡ÏzwØ~hÖ†yØzaÑ€rËrÍŠvÌ‹w΋xÌŠxÊŠzÌŒzʈyȇzÊ…xÈ„wȆxɈyÄ‚wÄ{ăzÆ…yÄ€xÂ|wÀ~tÁ~yÂzÂ|wÁzwÂ~v¾ztºvt¹rn²kl­hk½mlÛ’x첄õÄõÌšöÒ¤ôПòУòΜóΠñË¢òΠò΢ñ΢ñШðЦðϨñϦðЦñѬðѨðШðϦïϤïËŸðËžîÍ¡ïÉšðÉ™îɘñÈ—m Dg?l>n>v:x9v9v:s:w<†,G“8L™?S¨DTÁ\cÒppÜ~vã†væxè•yé™}ì }íž}í |î¢}î¢|욈瑊匉à”Înx°NW'D…>Ž$F”/Q¬RtɘµRl­C`°OiŒ=dfOl&Z„U~”fŠf KZFZHRJd/`L…g"WA‚l8mt6u˜ƒ²¡„¬]Œ‘bž` \q9nzF…_%_xNw•j¥‡TŠŠSŠ~LŠŠZ–†Pˆ§‚°Ä„¢¼w–×t…ÉJ]Õå˸´pw®SaÐtkå‘r躓¬ihZHYKZG[F`Ed!Fg CbBZ>^<aBe@f>f@b@f>t)BlAn"By*Fw(Ec>cC}6Q„.JŒ9Kƒ0Hz!=‡*D 6I³BL»HRÂKOÇLPÉMMÊMRÐQTÏTVÓZZÖXYÔ_dØZaØ_fÛfgÞhiÞjhàloâpmâmlàieÜcbÛ`fÛ^[ØWVÖTWÕVZÚXZàYZâVYäT`è^pébxêbyëk‚êiìdzébzçcxâ`vØfzÔt|ÛvtÙ|xÒlnÈfhŽ4KXBXBVCSAZCdA^@`>]>h>f8r"Ad<k<‰.B’9T~&DŒ8M‰1J(C}'Ds>ŽDWe<b=^F‡>_ʈŠÎ‰‡Õ~tØ~n؆x×{fÍ‚tˆỷzÊŠw͉xˈxÈ…xȆxʉ{Ɇy̆wÊ…xɇxÆ„zĆxÄzÄ‚wĆ{Äz€xÀ}yÂ{¾|½~y¿~{Á|tÂ}uºvt²rr°nn¬dn¼njÜ’w÷Ê”öРöÒ£öѤóРóÏŸóΠñÍ òΠòШòÑ©òШïÒ¬ñЩñÑ©ðÒ¯ñÓ¬ñѨðΡðÌžîÌŸîÊ›îÈ™îÈ”ïÇ”ðÆ’îÆ–ðÇ”e>d:j:m9l:s<v:q:r=x;‹/F˜8K˜EZ¥@PÁZ`ÒnlÜypàƒrä‰sè’{ì~ë |îžî¡|ð¡{ï }ð¤€í›‚葃â‚|ÚtqËY[¬@J(@ˆ"E(M;\Âz“¿g¥Da°H^®Xx„:`cR`O•t˜’]€X?XDZMSOwF|xDwXPv:qv8xv<r§šÆ–hš{D}”zªEˆ|D€‹c–n3ne+duFo˜n¨ŒN‚’x­™pš‘T˜eŽÎªÁ€Çp“ÄJaÍ~ƒÖ¼»»iqÏwvärí¸—À{fn,NVL]"LXI[G^Gg"IdDb*L\D_FbEcH_Be!DhDe!Dj Du&En#Cw,Fz+Hh Ed>v-H‚0L3F2Hy"@…,D˜-A¬;H¸BJ»DLÂDIÇLOÈOTÊRYÌTUÏX\ÓXXÖabÖadÚbdÜddÜfkÚfjÞhlàijâkfàmjÜddÜbdÜ^_Ú_`ØYZÖ[`ÔXYØQTØQWÜQZáXZáZcá]hådvä]gã\jáWfÜVbØdsØuvÙxwÛsrÖttÌjj¦DMx#DT<XCVBX?_Cb?`Ah@`Bh=j@p"@e=m:ˆ4F‹8M'FŒ8H‡/E…0Gy >x:’FVi;d@`G‚;_Ȇ„ÏŽ‰Ð}m×€p؆tÔjÍ„sʉvËŠvÈ‹z̈u͉xȇzɆzˉ|Ë‹ÿwÈ…yÇ…zÇ„wÅ„xÄ…{ÃxÀƒzÄ‚v¿z½€x¾~x¼~yº|x¼yw¼vs¾zrµtt²qm°lm¨co¾liÝ•{îºõÊ”õÒ¦öÓ¨öÒ¢òÑ¢óΞòФòÏ¡òТñϦñÒ¬ôÓ«ñÓ®ñÒªòÒ¨ðѧñТðΠðÊ™ïȘîÈ–ïÆ”îÆ—ìÅ–îÇ—íÈ–îÆ–îÆšf&Lc<f<g<j:r=p;n;o>w;Ž3FžAM˜8L£=NÀV]ÒjfÚvoÞtä‡uè•xëœ}í¢~ìŸ}îŸð}ï¢|ð¡~ïœé’|ä€oÜqfÍ[T®@K’)D"H†$N©TnÄ€—¥Fi¨C\°Lb Nil"NcUo&Y~™‹TyQ =^HSHRKP‚j1^XP\!Vx=‚~F±¯Îœv§o1n|R„–q¨ˆVŽ’lœw=tg,bb$czP€–€³“r£ŒMv§oŽ|?k­xœ²_~¶z¥ÁUoŜ޽܂pì—xì¥Ø¦{v*KXNXJ\H\ L` LdDhAj!Ca@Z?`Bg!B`?_@`Bq!Cp$DhBt(Bn"@t(Bx&Ek?a@o$C3P|,C‡6Ls >|(DŒ'@¡1A°<F¸GO¾DN¾BFÂKSÇLQÉRVÍQXÏTXÕ[\Ø\]Ø\`ÚdfÚaeÚflÝfkÞjoßkmßgiÞimÜdfÜ`eÛ`_Û\\Ü^aÖZWÕXZÎTXÐQTÑMSÒNRÓQTÒOZÑLTÐP\ÒT`ÔhsÝ~Úz|ÜptÚrqÏqm¶MP…)AiBVBT>R<W>^?]>hBeDn"Cc<i;h;j;n<”DS‹2JŠ0H‹5H‡3D….Cw=x"@<Jq:d?`F€8[ÉÒŽÑ{lÙrØ‚vÒ}mʃwʉxÊŠxȈuȈẅzɆ|ʈ}ʇ|ɆẍzɇzɆzÌŠxɈzÄ…yÁƒ}À…|ƒyÀ„zÂxÁy¼}z½}v¼{xº|y¼xqµvt±on«ik§agºjiÙ–xöÍöÔ¨öÔ«öÒ¤ôУòУòТñТòЦòÒ¨òÔ¯ôÔ­ñÔ®òÓ«òЦðͤñÌœíɘîÈ–îÈ•íÈ—îÇ–îÈœíÉšîÈžîÊŸïË¡ðÊž`?b>f>k@h;h8j8f6k;z"@”<OžBPš>O¦>N¾V^ÐhbÚrnÜ|râƒté’|ëœìž{ì {ðž{ð¡{ñ¢~ð¤{ðš{èwå„pàqdÍ[Y±BL*E‚DŒ'P®Xrºu’ @^ªF`£Rj{7]\L^Ty2ct”€=bXAXFOJ\'X€I~g&X\TNPa&df²¨Èž€ª‚Gˆg5n™‚´b›‘nŸG‚q<zr6w~Z™mœ™x¥–cš–Ms}7j˜f”–Mx©d¾QgÔ©ªÛ­¬Úzræ›å®~ƒ8GVFVG[J\F[C^BeCj Al BdAW?]<k@]@bAa!GfCm BqBj@l @o?s#@l?dAjB|-Kv$C†:Rt#Cv#B‹,Ež,@¤6D±<Eº@F¹CH¾GL¿ELÈNSÌOTÐUXÔXZÖ\^Ø\_Ø_fØaiÚhmÝfjÜjlÝllÜhlÚgnÙbhÛdiÚ`dÙ^dÙ`dØ\cØbf×dgÖ^cÏ[bÌW`ÎZfÑ^jÔbgØirÛu|ß{zÝ|}Úp{ØhrÖpnÄlm€ >…*Cc@V>UBT?Z>aBcDdCl+Im$Cd @e>j>i>k>•GW3K‹.IŒ8HŽ<P€)Ex<z%BŽ<Ls=o"EgHz4WăˆÕ—ŽÓ}nÚ…zÕ€pÎ{n̆vʈxÌŠ{ËŒyȇ|ÌŒ|ɇzˉ~ˈ{Ȉ̈~ʈ{ÊŠ~ÌŠ{È‹LJ~ņzÀ†€Âƒ{À‚{¾z¾€w»~x½~wº{x»zv¼ztµro°onªhj£_e³hhÜ•vð¾÷ÏžõÖ«öÔ¨öÒ¤óТóÒ£óÑ¢òÑ£óѨòÓ¬òÓ¬ôÓ­óÓªóЧñΤïÌ›ðÊœíÉ–îɘïÊ›îËœïËžðÌ îË¡ðË¢ðÍ£ðÍ£òË¥bD`=f>h>f=i<h9f<j:„,FŸL\§GR¢FR­J\ÂX[ÐedÖqjÜznâ…tè’vêš|ìœ{î~ížzð|ð €ð¢‚îš~ê’xæ„pàtbÒ_X´CL)D‚EŒ#N®Xt¶p”¤<Z¥Bc:`y2Zi(WcUt4]b†h L\HUFGC`-\y@p^Kf)\WUR[˜¬«—½–{«™p¢t<„f“š{°–p ‰TŽ‚SŒlžLtBvl Ÿj–Dlh-b–mœ˜e˜—`–§V„Ö ¢Û¸½î¦ñ¿¡QTVIWJXEZF[BZD^Ah!FgAl Be BZB_Ah"EbDgD^DbDf"Fk BlDl Bp!@t"Br'Ch@d=x%CpB€3Jt'Cl?‚,B“+Až5C¥6D®<G¸CI»EN¾IOÆJTËRWÏU]Õ[cÕY^Ö\aØajÙ`cÚdjÛikÛflÛfkÞfnÚfiÙgiÚcjÚejÙglÙbjÙefÞmnÞqpÞrpßtyÝx|ßx|ãvxâw{ãzyá|Û|Þx|ÙhvÙqsÑol«JUc8€,E^DXAR>UBX@`B`BhBg Bj#D`?f;d8g=j<˜DTŽ4J1HŽ7FŒ7L‚)Az"<{">Ž:Fw%Dk8fGt,N„†Ô“ŠÖ~oØŠyÔ|oÌ|nË‹yÉ…xÍŠxÊ‹|ʉwʈ|ƇzȆzÉŠzɈ{ʈÊ„ż|ȇ}Ƈ|Ć|ÁƒÁ…zÁ‚|À‚|½€|¼x¼~{¹|v¸}zºzv¸xw´sq®kl¨gj¥bi²gjÛ—vðÀŽöÒ¡õÖªöÖªöÖ¥ôÒ£ôÑ£óѤòÔªôÔ¬òÒªôÓ¨ôÒ©ñФñÏ¢ðÌ ðËžîËœîÌ¡ðÌ¡ñÌ ïËžðÍ¡ðË¢ðͦðÍ£òΣòÌ£òÌ¡bBb@d<e<c;e:d6a:i<Ž5F©ITªLU¨FR²JWÅ[`ÎhfÖpkÝvkã‚tévë˜}ìœyìœ~ìž|î~ïž‚ð ~îš}èzå‡rÞtcÐ`Z¹CH’+G… DŠ$K¤Ff´hŽ«HgHmŒCf5\l&U~8gu3X}Ck^H\EPHLEh4ay=nWKi*[] ZY!_Žlª“¶‘q§ƒO‚—m¢|M€¡’½–q¢ˆWŠaŠ[Šh1guFƒ‡b”¨n–§Dbo&WŽbQw¡g”·e~྾ïÊ¿ö¾“Ât_m#HSETEYF\I\B\A]@hBlChBg@U>\@h Da=c@c@\@aChAm"Cl@p @t#Aq$@h<`<n <r?t$Ax+DhAv$@ˆ&@Ž%;¢4C§6D²AH¹DL¿FLÄIPÈKTÍU[ÕZ[ØVWÕ]aØbf×cfØikÚdkÚfjÛgmÜimÚimÚjpÞjmÜhpÜpqÜnrÜpsàvwà{}â€ç…‡çŒ†æˆ„æzå|å~{à‚ß|zÜu}ØrwØspÈnhy=a<„.FXCR=UAZBXB^B^Bm'Fh@o&G`<k>a9d@n>›LX5Jˆ-DŒ7JŽ7EŠ/C€(A„.D6F|'Bf<pLp"JăƒØš‹×†sØŽ~ÐxfÉqÌŠxËŠvÊŒzÊŒzÉŽyËŠ|Ĉ~Ć€ÆŠ€Ä†ȇ{Å„zǃzƇ}〯ˆ|¿„{Á…Á‚zÀ…€¾€y¾|»z¹||·|z¶xxµwt°qr¨jp¦inŸbl¬djÛ~ñÑöТõÖ¬õתöרôÔ¥ôÓ¤ôÒ¦óÓªôѤòÐ¥óСôУñЧñΤðÍ¡ïÌ£ð΢ðϦðÏ¥ò΢ñÌ¡òÍŸòÌ ðÌžòË òËœòÊœóÉb<^>^=d>c@c>a>b@rC˜;KªFP§HT©FS´JSÅ^eÑdbÖqhÛwjä„pê’xë˜|ì›îì›zîœ|ðž}ðž‚î—{ìwåqàsbÒ^V¸DO˜1Jˆ"Dˆ&L”;Z¨\€¬Qt¡Nl†3`v.\s-]ŒKt€>ev8b`JVELDNHr:fx;lQH`Pf"^Z[}W€œy£‚ZŽ€TŽŠ_–‰Srœ}°Œ\ŒŒ^’€N‡v;wp:tsBuœpœÀPv¾Eh k–r:d’Y„¤JiÓ–„êȱÀŠjh$G\IUGZI[J`!J^ H]G`De?l Dm Dd?W@`Aj"@_@f<l@^>\<`;j Bi>n<t!>t&Ai=b;l>v$Dn ?{,Bh=q;†+@€:!8˜0>¦<G®<D´CO¾FNÅJPÌNSÓWZÕ\_Õ]e×`b×cfØhfÚfnØgnÚglÛkkÚmpÛnpßoqßtwá|}ây{Þvxãvv䃃拉猆蒋鑎劂æƒ~â~}ß‚€Ý|~Üu~ØuvÔyq®RZ\ 7b:v#BVBVBVBVDVDbEi$Il"Bt,JfAf:j<a>gAo? S_‘7LŠ0F‘>QŠ1F…-G&@‡.F8N{(Ep>mKp H„†ÖšÖ‡zÚÌuiʆxʆyÊyÌ‹|ÉŒzÉŠ~ÉŒ€ÄŠȈ~ÇŠÃ…Æ„dž~Â…}ņ}Ċƈ|‚yÁƒ|Ä|¾‚º~z¸€¸}v¸{w¸|y´zx´wv±rr©lp¤ek£`l®imÞ¢ðÄ•öÓ§õ׬õÕ§öÖ¦ôÔ£ôУôТôТôÐ¥ò΢ò΢ôΠò΢ñΤòΤñϤò΢òΣòϧñÌ¥ñÊŸñÊšòÊñɘòÈœòÈ›ñÆ–ôÆš^:`;b:a<c@b@`>`Ft>•6H¨JT¬JS¦DR´LVÉ^_Ñd`×neÝ|tâ…qèvêœ{êšyꚀëžzížyîœ}ðžƒîœzêŽxæ„oÞraÐ[U·CJ—.F†BŽ*Hš7R¡LhHl¢Ji‡8fw/Zu5a€;aˆGmr2\`"OXJNFMFu@mx6gPIZNf"Vj)j~Pv˜qœQuB}„YŽŽdž‰]–•t¢’h¡’m Œ_˜†Tn9vl6n¡y¡°R~ÒLd±p˜r7bKx™Pv¶u†Ð¹¶t:RXJf FUDZB[E\A\CZC_;i$Eo'Fn<`AX<bAn"@`?b?l=c>]<`<f=n>l=n;r ?lAf<g<t"?o@s"=k=m>‡.A€";r6ƒ7ž-=¡2>®:B¶@HºBIÅJNÌRVÔVWØ`d×`cØacÖbfÙfjÛfkÚinÜorÚmtÜnpßtxàxxää…„á‚âƒæ„„å‰è”Œè‘‰çŽ…èŒå‡†äŠˆßˆ†Þ}~Üv|Ú||Ïun‹/IX>kAw$CTAUAXDTBbHb!Dm$FhAo%Ca;q$Bo!@b:l;x A O\“8P‹3I’@V:M€'C€'?ˆ.DŒ3Hv$B~&GkEr$LÂ…‰Ô•ÖˆtØ‚ÊtiÆ‚tLJxÍ‘|ÌŒxÉŽzȆ|ÊŒ~Ň|ȉ€Å‡|Ć{È„{Ć~Ń}Ȉ|Çzˆ~Ã…{‡}¾†|½‚~»€|·||¶}z·|vµ{y³xx´uv®tt©lp¤hpž`j²prଋòËžöÖ§öجöת÷Ö¦õÒ¢ôÑ¢óСòΡòϤòΠòÏ£ôЦòÒ¨óШóФòÏ£òΞòÍ ñËœòÊžðË òÉœñÈœðÈžñÈœóÇœñÆœóÔ_:]>]>`>_>]@]A\@t @—;L¦IQ­JR¨GT°GRÆ\^ÑhdØneÞxoã‡xé{꜂êžvì›|ìžwîî›|ïž}îšxëtè…qÞs_Ï\T´CL”+G‚B,H–4Q¢Nf–GhKiw&Rj)So*]h#R\ƒm0YZLa OUIOHr<ft2fQF]"T\Ts2r„M€dŽ‚XŠ`#Xb&`i3eˆa–h¨™{­—t°j‘fšQ’p8yžz¡£b–ÁHjÆ€žˆBfn5a•Ut£X`Ǭ¤i)Pw:U_LUIZH\H^G[D^H`@p-Lp$DnBb?X9d?m"B]?\<f>f@Y>`=`?f;k<p>k?r<j=h@q!Al>t%?t"Ah9€-Dƒ,Ao6p4€6&:ž0>¦<C²=B¼BHÇMPÍUZÔZ[ÓYdÖ^cÖbhÙdjØejÚlqÝsxÜsxÜqvàzyá}€ã†ƒåŽŒäŽŒæ‰ˆæ†ç‹ˆèˆæŠˆäˆ‡èŽäŽçŽ‹Þˆ„ÜxÜvxÖ}xÅgfj9W?v'BgBSBZFZEUF^F`Fn'Fk#@m @^<s*Ee<e>jAy$FŸVb•?P2L’DWŠ6G„(B…0G….Cˆ*Bv$@….JbBlI‰Œ×™Ö†~Ö‹€ÉykÈ„~ʇxËŽ~ÊŒ|ÈŒzÇŠzÆ…ă~ƆĆ~Ä|„À„}Àƒ~Ä|Æ{Ɔ{Áƒ{„zÁ{¿‚}¼|x¸}z¶{z¶zy´{x³vt³ss®qp©np hjŸ_m¹wvç´òÌŸöצõÙ®ö×§÷Ô¢ôÏšóΜóΠòΟóϤòΦòÒ¦ôѧóѤôÒ¥ôÏ¢òΠòËòÉ™ðÉšñǘñÇšñÆ™ñÇœðǘòÅžòÆšòÄ–ñÀ‘^=^<aBb@\<[<`B`Dt#D‘5H›<K BQ£CP¶HPÉ\[Òh`×leÞ|lã†qè“yì™ë›vëœwëšzîžyîžxï¡~ï›|ëpè†nár^Ò^X´EL’+D†"CŠ,J“7R G]¢Pp€0Vk"Nh#Rb!Tb&R—kŒj*XY!N`#OWLTNk4^t2cRJ^!RWQj,i^Š”j˜…X‹f&^Z S] \l5p„Z–u¨–s§†Z•”s¦’s«„X˜”h•ªnœºf“Âx–¯G`Fv…I`…@[l1Lh)Nz6QTLWI]Gl$F^D[D[F`Dq#Dr"Dr"CaBZ?dBq&D^>_E`>n>_;^<d=`>k @m?n>l:k?k@p$Bl<s"?t(Ch>z(Bƒ,Ar<d7g5u3†";š.<©0<°8DÁEJÊOTÎT\ÐZbÓ^aÒaiØcjÙfnÜhnÝmpÚrvØstßvzâyyä~}æä’åŽŠåŒŠè‹æŠŠåŠçŠˆè‘‘ç˜å”ŽÞ†„Ùv}ØzzÑzx´JQa?\>v%D^FWK^!JVJXJ_ J^Gn$Cr(Ef:`=j!<e<b>l=x#AžT_•=R5O’GZˆ2G…*D‹9H†0Fˆ.Hv&@‡/Kp"HjHƉٜ’؈|Ö†ÈxoÆ€wɉxÊ‹xʋɌ~ÈŠ{Ljz‚zÁ‚~Ć}Ć¿‡Á‡À…€¿ƒ}¾†~¿„Â…{Á…|½„}º‚€¶{º|z¶|{µzxµxx³zy¯vtªqq§nq¢ckŸcn½€x긎ôСöÚ©õÛ°öÖ¥÷ÒžóΙôÍ™ôΛòÎóФòТôÑ¥ôÒ¨ñѦóѧôΟò̘òÊ™òÆ–ñÅ–òÈ–ðÅ•ðÄ’òÓñÔôÁŒð¼‘í¶ˆêª‚^B\>`D`C[B\AY@[>mA‚.E˜:L¡BPªGRºPXÌabÔiaÙngß|nå†tç“xè™zêœ|뚀ìzížzîž|î |î›|ì’té†nâr`Ð^X²@K‘*F€ D‡(H’4N G^¤PbcG^GbLYRe.Z•_~€<dVJd$Pi)XVJo2`l*]RGZNSOTU]’œt¤’st2hZPl*jl8p{I„ˆYŽ‹d™’j£—z®–x­†Z“Œ_š›c–´tŸ´~“Lv–Dk‡Ia’N`^%No+N[#JX!KUE\FaD\EYBXDa@r @t@u$B^@V>eAx(C_@`B`Ai$FaA[@d@]:b>k Bn!Bh<l!>d=lAn#Ep =t'Df@r#?~+D„+Bh<a:a5s5‚9’(>¡0A²>HÂJLÈRVÌSZÎTZÐ\aÕ`i×bf×cmÛkkÜrtÛqvÜvtÞv|àvyä‚‚â‰„æ‰ˆææ’ç’‘æ‹åŒˆçŽŠäŽ‹â‹‡Ý€…Ørz×yvÆmlª@IY;[<s#HZHW"M^$LX$OX L]J_!Jo%At.Id;f?e>i@i<l@„,E¡Wb“>LŽ/G”CT„.Fƒ)@Ž6J‰/D0Gx"@ˆ3LjFgHȆ„Ö–ŠØ‡wׄÆ|tÅyÄ„uĆzÈŠyŇ|ň}Â…€Â‚}Á‡Ä„€Å…~†ƒÀ‡½…~ƒ|†~À…¾„|¿‚z¸~}»~y·|z´||²yw³xw¶xv±xt­rv¨nq§jk bl£dkÉŠzî¾óÒ¢öÛ­õÛ®öÕ¦÷ОôÍ›ô̘ôÏœòОôСôÒ£ôÒ¨ôÒ©ñЦôΡóËòÉšñÆ™òÆ“òÇ™óÔðÃ’ï¾Ží¹ˆìµ„ê«|äœz؇eÃgOa?\?]=\=[<Y=Z<\Bf@y$B“5FžDPªHTºTZËcdÒd^Úqià{ræ†tè’zê˜ë—xë–{ëœ|î›|ð~ð›~î’tç†ràuaÐ^Y¬ALˆ)Ex D{&GŽ3N¦[t€3Ub F\DWIj)[v>j€<]4^YKd&Sl(Vd"Rp.\h,ZSHUKUQJPR‚ ƒ²’sš‡P…_Vs9ro5q{D|‡WŽ€K†Žf Ša”œ†¶˜‚¶˜}°Ž^– s¢¸‚¦¾Ž¨x4cyAfŽMeŠIdZ"LRKT"LTJZJ\J\H\JYHd Jr&Hw+H~,HcAWBc>v(D]@^Dd CgBe D[@b@bA`?f?l!@j Bn%Ck%Dh>nBn!Co#DgBo"D‚.F†+By"Aj<e9f9n:|:Œ,Bœ.@«8@­<I²@KÀJMÅV\ÇU]È\fÉ\hÓbiÕgkÜjkÜprÝrxßvzâ}€à|~åˆ‰æŒˆæŒ‰è’Œä‡„ã†‚ä†‚à…„ß„„Ûz|Ör{ÐsrÆgd©@NZD\Ej$LY%OZ$N[&PW$O\$L_"L_ Is+Hr*HbDm'Ga@fBgChA„.JžQ]’?S‘;NARŠ5I†0F;NŒ8M3H~,HŠ8NmJl#LĈŒØ’…Ø‚xÒˆ}Äxp¼tp¸ur»|tÂ}sÀzÃ~wÃx‚{†‚¿~À†‚À„€Â„~Á„|Á€¿‚|„|Àƒ~¼|½€|µ}~¸}zµzw°yz´zx²uv³vw®ux¨no¦hlŸcl¤foÔ˜zïÃ’öÓ¢öÚ©öجõÕ¤÷ПôÍœôÍšôРóÐôÏŸõÑžôѤöТôΞôÍžôÉœñÈšòÆ—ôÅ•óÃ’ò¿”ﻋꯆäœpÙ†cÄfP¢FF€-@h;X<[@ZB^@^?X=W;YC`?p@Ž1FŸDP¦FR²IRÇ\_ÑfbÙukàvãŠxéxè˜|ê–{è˜~ꘀízî|îž{ï˜zì‘rè„pßq^Î[T®AK„&DiEƒ/T¬f„¦^„ˆ9a“V~WHNIp-ZŒJro,Tv0Xf"Mg%Se&Tk(Sl,Wc$RTFTHYRKRlDt¢Œ»˜w£^g(\n4er6pf*d€Dx`‘hž{F‡^ˆ™{«„TŽ’nª›t¨¯¸¾‡ª›gŸ£x¦¤iˆ¨n„h1VLHNFSFXJZF\H^F\DmB{&B.Fz&DX=X=g!Bx,E_A]A_>hAjA^@_=c>[<a?f>h@o"An BjCq(Fs&Er(FiDl D~+G‚+Dˆ,E|!>u>q>n:x<{7";† :„":‹&<–0@¡;I¨@KªMX¶TbÀZaË\cÏdjÕjnÔnwÚwzÞxyÞtzá~|㇆䉆劄ჂÞ{zßzxÞ|xÜ|zÕpuÐppÊkhÉ^S—0BX@ZB_FXJ\"MZLX$N`#Na!L]Jn,Jl!DcCiBbBa<gBo$H„.J O_“CZ’>R=S‹8M„/FŽ=P‘:N7I&@‹6Lo Kt)OÈׂֈ~΂x¹roµhf°ff¸lk¼rl»vn»uwÀzw¾z¾|{¼~¾„‚À„~„ˆƒÂ„~À…~¿‚~¾‚}½€|¾€y¶¶~~¸||´}|°yx°ux¯vw­su§nq¡dp `k­ouÞ¨ƒñÇ—õÔ¤÷Ù©öÖ¦öÓ£öÏžôÌ™õΜõÎôÎôÏŸöΞôΠõËŸõÌ›ôȘõÈšòÇ“òÂ’ð¼Šî´ˆëªâštÒ~h³ULˆ0?i8^<X@U>Y@[>`A]>Z<X:X>V>];q B†-DšBPœAO¤ANÁTVÑe_Úpc߀rã†rè’yé–|è˜~é—|ì˜xìš|ëœzðŸ„ð˜~êŒtã„lÚn_ÈTP¤<Iz H†7`ºšÓ°°¥Lm Ut±t‡UEOGc M~8`q0YfJl'Ph#Qa Np/Z]H\LWFSHWLMPa4e Œ¹~©Ÿ­ƒJ†€L‚z?ub$`p6m”h˜’w¢J„q;o…c–}S“o¢Ÿƒ³®’¶¢y¤ q¢­†¦·™·±«•fŠX)SQNRKUKXJ[JZG[Il E‡2L0Ix)EZAT>e<{-D_?`A\A_?hA^?`?d>]>c=dBf@n!Aq%Bo"Cp$Dr%Ds%Bo!Bh=p!@‚&A”6G‹-D~"=z@~#?Š/J.MŽ6O”5OŸ>[§H^®H`¯Lc²Kb³Qc¾UlÄ\lÌXhÑ_jÖdtÔdzÚuÜu~Ý|…ßz‚á‡â‹âŠŠà‚Šà~†à}‰Ý|ƒÖp|ÈhrÆipËlb½VUˆ4KYF\F[L\#NY'OY(SY La%M^"L^Go,Nj$Ff Dd@a@_@d=r$D€,HœN`“BV‘<P‘CR‰<R„4Lˆ4L8L6H}&DŠ0Kw*Px*PÌŽ‹×Ž{؉Èyr¯ff®`b«Z\¬\`´c`µjn´nn»ml·tu¼rr¶tx¸wx»~z¾~~¿|zÂ~z½‚¿…‚¼‚¸€‚¼€|º€}·|x´zz±yz¯uw®tvªuvªlp¤jqžcj `l¹xt䲋òʘõÖ§÷×£öÒ¢öÏœöÌ›ôÌšôÎõÍšôÍôÌ›õÌœôÊ™öÊšõÉ›ôÇ’óÂ’î¼î·‰æ¨~Þ’nÎvZªMJ€-Bc;Z<T 7U:Y;^>^@`=`A^>X>V<X9T<Z;q;‡-A—=G˜;Ož9J¼IRÎa\Ùqeß~oä‡yæxè–|ëš{é–véšwë™wêš}î™zî—{ê‹päjÚlbÃRP¢7S˜Agتܾ¬–JT|$XšRmŸc~TGMCUG~>gv4]aKj$Pj(Rf#Pm*S\H`JTFSETHNOb0`™|¨–n¢¥ˆ¨—jœt8dy9kf&b`!]~Hs—w›zC|n6t‹o¥o®t>x˜{§§Œµ ~¥‰Tˆq2[“Nm§†®‘´“ah0YNBM@RDVBZGZDlCŠ0H…4Hu(GT<R=h Cu$B^B_@]?^Be@c?\?b>c?_=e@`?g?m$Cj#Ei?o!Al!Am Ag=j<€'=‰,A‘-B0E˜1H¤?NµLZ·OZ¾Q`Æ\gÌajÒbkÐenÒptÐpvÏjmÌinÊlnÎpzÒnr×uyØuz܇܃Þ‰‚Þ„}ß„~Þ‰‚ß„Þ‹à“Šá•Žß”ˆÛ”Ž×•–ÕšžØœÃ–£av{A_e.MW#HY'PZ(NZ#NY$L[!H^"N^Gl#Dh"Fe D`>^BaA`=t%D|*F›LZ–HYŽ8M“FVŠ:T…2L‰8N‘:N0I}(B‚,H{+S~5WЖ‘ׇtÕˆÁmh¦X[¬bb¦RX¨V^¯ZX¯`f³ae°bb®fi¶on±hl²nt¶st¶tuµwx¹vu¾~xÃ|¾‚~»‚€º~yº}z¸}|´yx°x|®xv­svªqp¨mp hp`i¡_kƉ{ê¼õÏöÕ§øÕžöÏ™öË’öÌ–ó̘ð˘ôÌœóÊšöÊšõÊ–ôÈ”öÇ‘õÇ“óÁŽí¸ç¬†á~Ñ…o¶ZQ‹/@e;X;T:O:R<`<n<p>eCf DfBfA\=W=T:R<X;o<‚)=3CŒ0D’1E¶OTËdcØobÞ|sã…wæ“|è—|ê˜}ê˜|ê˜|ê–xé˜|î™}î™zèŽrã{eÖh`½Qb±UxР¯â¿¢GLˆNmr%TžftŒLaX KT MPD|<d{8an*Vi&Tl&Tt2`_H^Iq1]VIXIXJVQu>s™v¨’fŸ’hŸ€¬„N„u8fj.d[Ob%XwFswAƒZ˜žŽ·“qšv>|R‹žˆ³¨’ºšw£x@xb"Tu6`´”¨¾¢»¦ƒ¨f1aGCNFSFUE`Dn@.HŠ8Ks @T>T=o*Fy(B^@]@`>^>cCh?\>a>b>\<aAb>d Dg An"Bj<u&?j>f<f8c8t$=†,D’3D“6I¦AO¶KX»O^ÄZfÊ]`Ð`dÐ_fÓ``ÔcfÔlhÔihÓheÑjkÍljÔpn×jk×mrÜtwÜzwÝ}yÛ|Þ|{Ü{zÚ€€Û€xÚ‚~Û‚|Ý„‚Ýˆà“‰ä›‘æ§œè²é¸£á·¥Ð­¤²˜‡\{j9]R#IW$MUJY$M[E^EfBf BaAX@XCi!F`?s(F{(G—KY”G\‰7O‘FX:S…2LŒ5J;P’8L‡-F†,Hy&N‡:WÓ•Õ€jÖ†}¸ff¨QX´\\­Y\¨O\ªSW¨U]¯Z_®Z^­^c¬_hª[c¬bi©bg®fk¯jn®ln²ps·ss¸zzºzwºwv¶yz´z{´z{°xz±y}®ts¨or¥jq¢gnœaj¤dlÔ—ïÀ”öПøÔ¢÷ÒžõÊ”öÈ’öÊ—ôÊ•ò˘ôΜòÊ›ôÉ™òÈ”ôÈ”õÄ”òÂí¼Žç®Šß›|ÒŠu´e_Š8Hf:W>S@P:Z>e8w"=ƒ.F€*Di>i"Dl$Fd!Ed@^?Z>U:V 8l=z!=†/A…/F/E¯KQÌcb×lbÜ{må…vèzè–{ê–ê•~é˜|ê—|ìšì~î—{èŠrâzjÕklÊj€Û«®Ü°Œ’BH}0Ru&Pc K[xj*PL?MDNFw8^„Bhp,VdNl)Rn)R` M`Q~Dmd!Q] M[LXPp4j“k™•m Z’šxœœ~©|Fv^&UNK]#]‚WfŸ“x§Ÿ´€PwD|RˆŒe’ž¦”T|”iŠƒFzd P–_vÓ µ–«¢‚¬a0`MKSFVFbEs#Gƒ-GŽ:KmBXDXBt.Hx-I]C]CbF]B_@fB`@_=`>_>_@bBbBjBo#CkAl?r#Ce?d;f@m>‰-C”2GŸ:JµFSÀQXÊV^Ð`fÐ_dÐ^gÌY^Ë_cÏ`aÐbcÒfeÑedÌglÏihÓjoØmpØpqÛvuÜvtÚzyÙ|zÛwwÙyvØvtÙut×xtÙzwÛÛˆ‚ß”‡âŸŒâ¨–çµ¡è·¥ìº¤í½¦ì¾¨à¼¬À¢¥“k†n?aX,QW(PYH^HeEc E^BVBXB^DdEv.N‚1L—GU–Ja†2KŠ;PŒAZ†3M„0L:OŽ6N‹1H/Mw,U‹>[×™”Ö€n΀y¸bc©Zb°]e¶cd¬Zb¬V\ªYa¬R]®\bªX`¬V`ªYc¬Z`£Yd¨\b¦\g§ah©di¯hl­jp¯mp±pr¯pw°tv±uy¬sv°ux¬rs©or¤ktžfrœ`m¨dnØž€òÄ“öÏšöÒøÍ˜ôÆöÈ‘÷ÇòÇ–ôËœôÊšôÉšöÉ™õÈ—ôÃŽóÀ굌⦋ה|¿rj—DLoB\BS:W;a>k @})DŒ1GŠ4H‡/Hx,Hu*Jp(Hm%IhCfA`CV@W@f>{#?‚)A‚%=ˆ,B¦BLÄWXÔf^Üthå‚sæŽxè”}ê”|è–zè’|ê•|ê–}í™wì‘wè‰tâ~vÚ~Šß­¬Ó’u4Hx$H‡8[f"T|<_¯xˆVDLELCLDn*VˆDjv*TdLg&Ri'S^NeT|Ej~<he"S\M[Nf&`q>n‘j˜šr£†S…“m——w¨p7w`*fq9tƒP†˜w¤¡’¸k’h1jwJzF‚|FŠf”—p¤~Dn}@lt8v„Ii¬ˆ ¢jƒ¨Œ ¡‚¬T"MODVFf Es)P,H‘:LhEWCXDj%Fy/NfH\Fb D\CZ?cCh"G`B`>bCbDfD`@eAm#Fm&FjBl Ce@i Af<m>‰2G–7K¢:K·J\ÂT^Ê[`Ð]`Í_dÎZaÌ[`Ê]cË`gÎfjÒbcÏejÐhlÓknÖilÖgmÙnsÜqqÛvtÛvwØsrÚrtÔqqÔtuÖqxØrtØvuÝ{ÞŒ‡â™‹âŸŒãª˜æ´žçº¤èº£é¼¤ê¾¨íÀ¬î«⿭Ȫ¨œu‰sDg[,NV!G]G[H` HUCTCZCdFp(GŒ>W•IW˜Ob†5Pˆ=Sˆ<U/L†2I’=NŽ4N„+G…8Wx,V”H^Øž”×iËvr´be²bfºmoºhf·jj²[_°ag¯[^°Y]¬V\©U`¨T^¨T^¥P]¢T`ŸS^ V`¡W^¥T\¦^f¨^e§^g¤bm¨bi¬hm¨joªlo¨kp¤ip£fmžfnœ^j§dqÚ ~òÂŽöΘöКöÊõÅôÄõÈ‘ôÉ—õËœôÈ™óÊ›öʘôɘðÀŽí¸‹ê°‡ä¨†Ý–Èzj LTr=]9Z:_>gCr B+C0G’8MŽ5J†3I™NdBZ‚5L{,Ft%Dj>f>_@a?q>}$>{$>t<~"<–4F¾NRÐ`XÚtjãƒtèŽwé–zè”xê’{ê“|ê•wì“xí›yí“|玅䌎贞ٌr£EP€#Dx$I~0^t+V´‡šWaMBJ>J@K
+>\ H€;dy.YW@d%N_H^J`P~GkNys*[l)Zf%Sb$YUQm8fœx¦’a˜|Axm˜fŸ”o«˜t²˜w­¤”¶š†¨l3du>}s<x†Z€Jˆ~N‚”q—‹Vm.kh›£rž¸”¯£f‰w6]«šªh”RKTBcGnB~(EŠ0HaBRCUCr,H~1J`B\@bD[A\>^>i DaA_@bB_Ad=aB`>l"?l#Bk Cp@hChAf>k:*C’8N¨=K¾LVÂP[ËYZËX^Î\_ÐZ]ËZ^ÊZbÎZ_Ð^cÑbhÓdkÑjlÖhn×ijØklÚknÛpnÙrsÚqpÖkjÖrpÕllÖpp×rrØroÛ{xÞ€zà’„á–‰â¢ã¬•洞湣黢꾦뾤뾥êÀ¨ì¿¨ïÀ¨è¿ªÏ²©¤|u@\Z BR?Z>O:N>P;`=p!D‰=U‰8LšPb‚/J‡:T†8O‚/Kƒ.K’=P4K~&E~3Pr#JžQbÙšÔ~lÈtmµfi´lkÀqmºljÂql½ni¸ed¶fd³bh±^c°\`«U`¦Vb£PY£P[¥OW¢OWœLWšL[¡Q[¢Ua£X\ [hžX`œX` [b \d \i\e]j—Xc˜Uf§agÛ¡„òÀöË–öÌ’öÅŠôËóÄöÇ–ôɘôÊšôÊ›òÉ™õÊšóÈ›ðÀ’ë´Šä§„Ú“v¾fX–=Fq<Z7[5f=n>t"B€*E‹1G”8H’7L‘5J”?N¢kz cv›RdCW†5M}.Gv$Dj@jAz"@x:t<n6p8‰(@­BKÌWRÚoeâ‚pèxè“zè“yê–ë’tê”x薀ꗈꡞ갢朄à€lÆ[Z¤APˆ'I€,R˜Ko§rНnsi$ILBRBO?NBXCg$S:bn)Ux;fM :SB^Lr0[’R{|6fs1dj%Pr>lKENLˆd…qœ`Œs8ja)UtAiƒM|‘l’Ÿ®uFqo7vxF~‚P†x?x‰b—ˆ^–†YŠ[†P‰”f˜²ŒŸÅ–¢•Tn|7hvB^ª”¤o8cVAgBmB€)DŠ5K`@RBVCx-C‚1L_?^BbA\>\@Z<jCf>`>a@]?^?a?dGl$Hp&Ci Bs BkBj?g>f:~(DŒ5J¢<K¼MVÄY`ÁX_ÆV\ÏZ]ÎZ]Ì\^Í\aÏ[dÌ[fÐ`jÔjlÑhhÔfkÖgjØglÜjmÙlsØln×jr×moÙklÔnsÖpmØpoÚtqÚ|wÞ„}á’ƒâ˜Œä§æ®›è²œç¸¢é¸¡ê¼¤ê½¢ê¾¨ìÀ§íÀ«î¾¦ïÁªñĪîĭ̲¨ wf5TQ<L8K<M 6`:n@‡1Jˆ:O˜P`€(F‡;Pˆ8Qƒ1J‚,H9H‡*D€*Dz%Er$N¦XgÙ’Ò}pÈtrºlnºsn¾trºqnÁrlÄvrºke½jh¶hh³eh³dk®^e«Xb©Xb¦S^¢MW¢KUžJT IZœJU˜DTJVšOY•KX•LY–N^šLX U_žX^—R]GXŽDYžUbØ•yﻆöÉöÉ’öňõ‹öÅõȘóǘõÈ›ôɘôɘöÈ•óÆ–ï¾å¬ˆÚ–t¹f\„,A`<^<c>m>z&Ax&B~(D†*B‘8J”4G‘4J“9L–<N¦q€¦q€§k{ _n“I]Œ=P‚4Lv'Dv$B„,Fy<s9j8n9…&?¨>GÉTTÚncâ~næŒ{ê’zê’~ì”}ê˜zë–z蔂ç ð§Œìš|æˆtÛtgÌ^YªBTŠ,PMwª`lЩ£w(DT?M>L>L=O=VARFr-WŒPw‚ItG7L=[Nm&W“`ˆ†Drw2ew8exCrJ @J C^"TbŒx§•g›|JzCvv:pƒW‘p™^#Z€UŒƒVL††T‹ƒLŠg˜fŸŠ^’‹Y•a–f}°’­„Cj~:ct/e|Dež|Ÿe"MiChB€'D…/I`?T?U=y+C~-Ca>`@a@Z@\BY>iBg Bd@_B[A\?bBh BfAm$Dl"B{0Ip!Bl@g=b<q!>‰0F¤?JµHPÀPUÃRXÌXYÌY]ÊY\ÊV\Ì\dÐ[`Ñ_eÏ]dÐhkÑfgÚddØdiÙhjÚjlÙlnØinØouÖkn×km×om×rnØvvÛxuÞ}àˆ~ß•ˆâ Šä«æ¯—粖洜跚鶜ê»í¼¥ë¾¦í¿¦îÁ¨í¿¨ð¬òëóƯéȱÀ©ªWvR#CH<J <[<q&D€-IŠ<O–Ob},L†7L3L}.I~(D5H‚,Eƒ,Hy)Kr$O¬^kØŽƒÒzqÃvxÀvzÀzu½xt¾vpÀunÁzt¼rl¼qr·ooºlo¸jj´hn³fi°bkªYa¨Vc§U_£P\ LYHT›FT˜DR–JVHUAV‘HXšJW§W[§XZžRU?Q„0J–DVÑ‹töÈ’öÈŽöÄŒõÃŽôÇ”õËœôÊšôǘôÈ–òÆ”ò•걈ޗ|ÀufŠ5D]6`;pA€*D~,Bƒ+F€,E…0G3F“8I‘7J–8J•8L“7L©|„§u„¨t‡¦r} bpTf’AZˆ7N‚1Lˆ4K~(Dr=f>h;€(D¦>HÉTRÚncâ‚qç‹tè{é’wê’zì”yì”|ë|ìš~í•zë’rè…rßtbÊ\]¨C[˜Dd³gˆ»w}ÆŠ‚W?RCNAQAQ?TDR?WNi(V‡QuƒHpE 9H<PFh%Tp–‡Fsv2b†R}w@iTIOETHo4b[ƒa‡›v¨ˆTŽRˆ˜|¤„Th.mc-e‡b’ˆ[”ˆ[ŠY“v@nœ‡¶‘j¢’hšw¡£b‚¢iz¨ˆªu-X^JŽR„ vƒWbCgD‚(Ax(D^@R;Q;|5Ix-GbC`Cd!E[?\CW>f!IdDj'Ib!F`B]B`BgBdCi Eq%H|,Hz(Fo BjBc@r B‡4KŸDV²HR»NW¿NUÅQZÇY_ÌX\Î[_Î]dÓ`dÐ^`Æ_hÎaf×fgÚehÚkhÙjjÜnkÙjlØlmØmnÖjj×mnÙrrØppÛvtÝ}yÞ„yà‚á—‡ã‰ä§Žå®•尖沚篖粖è·ê¸Ÿê¹›ì½¤ï¾£ð¿¦ðÀ¥òÁ¦ñƬôȲòɮ׿®œ~”\-PJ:V<n"Br@†:K—NZx$F‚0J4N{*F~*D1G„(D‚0Ju Ep#M¶lwÖÐyq¿pnÀ|zÀ~zÁ~|¿xuÀzwÅyr¾wvºsr¸su¶rtºqr·noºmn´jl¯fk¯ah®^e¨Zb§Wb¡P\ŸL[˜FZ”JXBR?S“FV¤T^´ca±`XªWZ“CQ0L’>PÓsð½ŒöÈ’õÈŽöÆŒôÆöÊ™õÌ ôÉšôǘõÈ–òŕç¦zÜ’jÀhYŽ8Gg<b;s$B‚,F‹4J†2J…/H†6JŠ4L”7I”<L˜<K”6H”>P”9M¨zˆ¨v‡¨}‰¦y‡¦s¥hvŸWj—L\Ž@U@N…3F{#@d8e4€(@¤>HÈRR×ncâ‚qæ‹{èzç’yê’xë”wì”{ë–zë•|ì—{êŽwè„lÞrfÆZ^¹dºuŒ¯^u¿zzŒH]RFP?QBR<N>Q?ODv;r•U”Y†DsSIGDXU‰UˆŸvšu0`y7hHra%PXKQHi,`‡N|u2cd"XzJyŽ^–yŸ~Kpd(]k2iq6xh2fŒfšf–_“ˆH„”o¤Œ¸”hœ›tšœY‚”Lb™oyœ|¦ZN^ MŽLp¬†žm,UeD|&EnCYBS?W@‚1G~.Gd?cF_BbD^BXC\CfFh&Gh,L_A^C^BcAhDi"Do"E|,H‰4Jn"DfBbAo Bˆ6J•BU®HUÀRXÄQXÆRXÆVZÍY\Î\bÏ[`Ð^dÃZaÊahÕdhØhkÜikÚnpÚlnÜlnØkmØhhÙjnØde×mrÙstØttÜxvÞyÞ‡~à’„áš‹ã ‹ä¦’ä«”ç²šæ°•æ®™è±™è¸œé¶ éµœë»¤ì¾¤ï¾¤ð£ò©ðĬòÆ®òȰò˳åʱ°š¤m:ZQAfBeBx1M‘K\u(J}2N4Ny(F„0GŽ9L'D,GlDs%MÀ{€Ö†zÎwjÀqtÊ~yÈtÄ|wÁ~|Á~uÁzvÀxt»vu¼uvºtvºtw¹sv»rv¹or´jm°go®bj¬elª_f¨Ze¢R_¢T]›Tb”HV‘@TŸOY®XZ¾k`¿eYµSN”DR‚+I›FTÚ–wñ½ŠöÊ–öÊ•öÈ•õÉ”öΞ÷ΞöÌ›öÉšôÈ•ðđ窀؄e´UQ|$>_7a:u$Bˆ0EŽ6LŒ0F‰1I‹3H:O–;Lœ?Pš@N˜AM’7I•2G–7N¦x†¥t„¨}Šª‚’¬„ªy‡¦lw \l™K[–EUŠ7H}&@f8e9z=§<HÉVUØplá€tçŒ}ê{ë”xê•zè”zì–xì˜zî™~ï”zêŽqä€lÝmdÈ_eÒ‡–Ü¥¢šC]¨^tv.RPBPBQ?R>L9N 8H
+<VF‡Ip›d’p¢šb W’›lžiŒ|8`r.fn,^k.Zs:rPLf+c’a‹€Ald!Th(`ƒ^hr;bn5l^$[h2ft?up;uq@ra–”jŸ–e𣅲ž~«š­–ršžvœm'RaLˆg{ˆ`ŽMLm/a¡m{˜l_Ew"Fj!KXJUFTF6O|.JfFfHaHbE^BWD] He Hh$If$Ha"GaD^Ba>r%Fi%Hx%Gw$A‹5Hy%Df?hDmA‹9Lš?S­LYÂRTÃRZÊTYÈT[Ï[aÐ\aÍ[`ÆZ\ÆajÔad×diÛikÚnqÙpoÜmmÚlm×nmÚddÙfk×fgØoqÛrmÜvlÝxÞƒyàŠ~à‚á”ƒâ˜‰ä£‘ä¨’å®“å«–æ®æ²˜è²–é²–é´—ë¸›í» ï¾¤ïÀ¦ñÀ¤ñħòƬñÆ®óȰôʶìÌ®½¦¦t@^\>WAl$D‹BTp"Ft(Dy,Ht"B~(A‹4J(C„(DfAr#JÄ…†ÖnÊunÀuŏxÈzÆ}vÂ~xÄ~zÄ}vÀ|w¾xy¾yz¼wxºxwºux¸qu¸tv¹op´op³kp±in®cfª_h¨`i¤Zb WešSa™GW¢OV·\YÈjTÄk\µXP›BN‘2N¶^Zà£~òÄ‘öʘö̘÷˘õÌ›öΙøÎœô˘öÈ•ôÆ•ï¿Ý›r´\Wz$>\@Z9t!B;K”:H‘7F‹0FŒ0GŽ1H–;M?O CRŸDQš>L‘8K”2D˜8N¢n‚¤v†¨‹¬ˆ“°Š’®„¬|‡§m|¢`h›P^;K‚(@j=^ 7w @¤=IÈYV×njâ‚tè‘zê–}ëšyê–{ê–|ê•uë˜víœ{í˜vêŽnä€nÛkjÔ{ˆéƸԕ„=]‘@Z1Yd"RTBP>V>P7T?P@VCk)Ta!Jc%J|;`VvLlu1\n.[v8hc!Vb([k0fx@|”fŽŽTu^HTHo2b”y¢m-X^"Vf.ba$[]"\r>r€N†r<t€R†Œb’—n¢žx¤šw©šz¨Ÿ€­£«ƒDuH JvB_¶¢°|H{\Jƒ?f·›ªl(OlD`CRBRBRDz0G~,IhDfA`Cd H^FSD^Dh Cl)Jj&F`EbD^E`Dt&Hl!Fz&H},H˜:K’6FiAe=h>Œ8P–9N²P[ÃPSÆQWÍWZÍ^`ÐZ\ËZ^ÄTXÊZbÔgk×ik×gkÛdfÛikÙnlÙllÚlnÚlmØffÙhlØjmÚljÜtnÞzvß{à…{àŠ€áŽ€á‘†ã–†â ‹ä¢å©’娓檒谓殑貔級긜캞ì¸ð¿ ñÀ¢ðħóÄ«òȰóɱõʳô̵îδŭ¦DdT?j Dˆ:NjBo!?t%Bn C.Dˆ/H+By#D_?t#FÌ„„ÖuÇvq½toʃxÆxÆ‚xÂ}yÂ~xÂ|v¾{tÀzy¿|x»z|¼|z¹vvºsu¶su·su¶rr²ln°ko¯gm­ho§clªal¤`k¢_kŸR`¥X\ºbVÆkXÈjUµXQ¤DQ <PÎxeè³…ôÆ–öÎöΜöÍœöÍžôÎ÷ÏŸöÊšóÄŽòÁé±Î‚jœBP^=Z<p!D9Mœ>L–>N–8L“8K2I•9NŸDQ¤FR¨JUžCPš?N“:L’6Hž@O l~¢t‡©~Œ¬„”­Ž™®‰•¯ˆ“«|‰§nz¢`j”HV.Fl @\8y#B¤<HÄTW×nfãƒuçyé™|ì˜yêš|ê—}ë˜zì˜yíyî–zèŽrå~lÞnnæ“”öо¸nzTr;\`FdJ_J[EbJXCWF\Ei$Rv8_XGLEh'Rw5_n(Rk&Sb!N^Kf$Ss4gzDozChx;]e#PN BUP‹]‹™{¤XR\$Vd(\n6me)dd*c}L€‚PˆxA{zD|‹[v¦œv¦˜r ¥“¼ž‚šŸ{¢SQSJ´†º£½m*X‡F{žvPwh@Z@Q?TDSFv-Lw,HeDhB]E`E`GXG^GcDl(Ir(H^B`A`E]Gv.Jr*Hv Aˆ1K£?I©BKt#C`;_;†0H’4H¶S^ÄQVÉPWÎVXÏa]ÇU]ºO]ÆW_ÖadØfkØmlÙhjØdgÚflÚjkØihÛmjÚjhÙklÜjmØouÜqrÝwsÝ}xá€xà…~àŠ€â‹â‚ã•…ãœŒäžŒä£Žæ£æ§’ç¬æ¬—鯔貒굘춗췞ð¼¢ñ¾¢ð¤óèóÅ®óÆ®ôÊ´ô˶õιñϲĪ¥s;ZeE€4Ll#Fm"Fm#Fu'G…6M‡2H-Iy*J\G|.QÔŽ‡Õ|mÄxr»wxÇ€yÅ‚zƃÀ}z¿~|À}z½|w¿‚}¾zx¿}z¾yw»wx¼x|¹ww·tx¼vy¹ss±nr±lr°orªjt©jp¦hr¤ai¢\e«_Z¹gZÂhVÄjS¹[O«NR²NTÙqﺉöÈ•öΛöΘ÷Í™öΛöΛøÍôÈ”ðŠë¶á¡s¿n^ƒ*C\;k@ˆ0H›;L˜=L—?Q—:J”7M˜6JCS¨JR«LR«HRžAM˜<N–=P˜<P£FXœl€h|£r„¬‚¬‹–¬Ž˜®Œ–ª‚¬x‚©tz XaŒ<Ls ?a7z#@¢7FÆVX×ohâƒrçŽvéš|íœ~êšuì˜|ì—xìšyí{ì•vèŒpänßqs蜒îʬXr¼o}±xŽJ :S@P8\Bf Hh"KfJh$Nn(Sx3Xf#QPDr/Vx6\j#L^Hf$Qh(Tf&S`!JXDVCVI`!PRNXRV~ŽgŠm2jPH`(`p:kn6lj0jk7j‡ZŽK~xAuK›pœŸ«œs¢œ ŽbŒšwšˆVŒm-n–VrÌš”¡r”€Et@V°Œ¥c JXHTFVJWL|4Qv.Ok!Hh#Lc Jb$L^$KZ L^!Jd%Km(Lt.M_"Ib"M`$Nc!J€5Sy/Ls"J‰6R©FW­HU…0MbF]B~-J’9P¸ZfÈW\ÈT[ÊSZÅW^¶N\ÃW]ÔfmØafØceÚjnØfjØgmÚimÛmlÛnmÛhiÙhjÛifÛlhÛroÞvqÝxtÞ~váƒ{áŠ|߈|á€á‘‚┆⑃㜇垇ä¤ä Šå¤‹æ¯Žè®é®é´—쳕췘ð½ ðÀ¤òĦòƪñǰôɶóɵóλõѺîг¿ž p-Nl!<n=c>l;p!@-Dx"D„/H},LYE†4NÖ”‡ÒufÄwrÂwrÆ~xÅ‚{Æ‚s€xÀ€x¿}v½xrÀ~zÂzs¿zx¿{x¼y{½vv»wxºuw¸vv¹sv´rx±nr°mp¯lpªitªjq¥dl¥cj¬``µdYÃjVÇiUÄdP¶TPÂ_SáŸyð‘õÌ›öΙõКøÍœøÎšøÎœøÎóÈ’í¼‡æªxÕ‰e¯XSwAf@~(Dš>Pž=Lš<NžAQœ@Qš;K<N«LV¯TW°V]¨JVDR–=N•4J›@O¢AQ‰JdSjŸl~¦yˆª‚’°Š–°’°Œ˜´Š•°‚‡¥fm@Rr >b8| ; @LÅWZØneá€rè‘xê›zïš~íšìœ{ì{ìšzî }ìšyêpè„nàphÞ€zᵪ˜Ah˜HT¤fjJ=M>S@T;ZA[CX?^Ao2Xl%Ko+R]D]BZ!LXDZKw:h}>lf(P_ IS@PBQCp5^^"NPFZ SuBoˆV…b&[VLh*`d)\p6nk/ltBtŒ^–€F‚z<t—n›¡~«œt™s¡`”“j” x¡ŠMz–Y‰“Rl¦„žr8l]J¸£­v4ZRESHQERC€5Nt(Ij%Fl&HaA^@]DUDaBb"Hj#Fx,K^HbDa@`@s#Bz*Ew$F’6N´MR¹LPš8Hh;^<|(F‘6K´YdËXYÊPV¿M[¸T]É`cÖ^aØadØbiÚhkÝhiÙhiØlkÛjfÜijÜojÜhgÙnlÚllÛllÛqlßvrÞytá}râƒxâ‰}à‡zà‹€áŒ}ã‚㖆✊㚄äŠä‰å¦Žæ£Œé¦è§‹ê®‘쵕븚ð¼ ð¿ óèòìòÆ®ôɳôʶôͺõνôÒ¼îÒ²²ˆ•c?j;^5e:t;‚-Dt!B}%@r"D\C”@RÖ“„ÑrdÂtpÄ|tÆ‚{È„uÄxÀ€x¾~xÀ}u½ztÀ{wÀxt¾zvÀ{v¾xt½zx¼xx¹wz¹txµqt²rx·qs°nt±ot¨jr§mt©flªgl®fd½h^Är\ÇlSÅcO¿[RÐw_ꯂóÅöОöΜöÏøÏš÷М÷МøÍ™ðœ鵅à›tÉrXžDPx Dz(H9N CRœ>Q™8Lž>Nœ=Oš?R§HT´PY´TY°MT¢HTœCR˜=Nœ@Q¥GU¤JYm*L~:\—\rŸp…¦}Œ­Š˜¶™¢¶˜˜¼–˜µ…‰©pu—P^u!@`9v=£;GÆVXÚsjä„qè{ìœzîœ}ìœ~ëš}ëš{îž~ï¢|î˜yétékârhÚ‡Ê~‚¢Xx{/Qf AL=Q>V@Q;T>]@UA^Dr3\\@e#HeHTCUBQC\K…JxˆK}d!Mk-W\KKCQFr<_v8gLDNKf1c‡T‚GvYQ^$Tl2jo3fh,fn5s|Q‚ˆYy>v–k˜¡¨šn—˜pž|¯˜n›¦†ªŠEodƒq%Ux|ª…ª\O¾”“še‚L<N<OCR=€3Fr%Dn@p"Ad@`A^@TCb@aCq&Ht.K_D_=Z>\;r#@{*Dz$E™>P¾QUÂSV§EPr<b<r"D“9M²PbÊTVºER¾O[Ìbf×fdÖ^_×\\ÚfhÚhfÛhgÛilØheÙljÛghÚhiÜikÚghÛmpÜqpÜnlßtnÞxqÞzqâ~rá‡{â‡zâ…}àŠ~ã~ã‘䚆â‡âš„㜈枎ä§ç¦‹æ§Žè¬’ì´–ë¶˜í¸›ï¼›ï¾žñÁ§òĦòŬôȰôȲôÍ·õмõÑÀõÔ¾çͶ—dwi@Z8a8n8{'@n>r%Ch=[A¢J[ד†Îq`ÂvmÇ~vÅ€vÀtÅrÁ~uÀ€uÂ~w¿|uÃ}zÂxt¾xvÁ|v¼xz¼||¼wv¼yy¾ut·tt²rvµqt´rv¯mq«luªjt¬il®in´hfÄmZÌsXÌqUÆhSÄ`SØ„f﹄óÉ™÷Ñ öКöΜ÷К÷Θ÷Í›õÊšðĎ讀ւd¸XPŽ1J{(HŠ4MœAN¡CQ™:Mž=NŸ@NžBU¢FV¬PX²QY¯RX«LS£DTž@Oœ:P¡AQ HX¥KYZ<n'KˆKfšf|¤wˆ­Ž˜·œ¢»šž½š˜´‹¬xzž\dz.G] :t>Ÿ9HÆXYÜphäƒrèyìž~ðœîš|ëœ~ìž|î {ïž|홀ëwæ€jàvtâwÍš¥ª_p‚2Tk"LO>O=R>R>T;\AUCu<bh%LUD\#J^A^GTBSHf%UŒS~…EyXBx=dj$QOBNCd)RTWOPH_(Zz>tt;f}Cy_"Zh-bw:ps6ni4ih2f‚[‘€D|“i–ŽZƒ[Šb’Ÿ‚²x§² ¾¬yžª[r[Ie*J¿¨¯:p°€„º›L>N 8M:Q>{,Bn$Fm Ar%Ff?eB_@V@aCcCl$Fo$Ea"HbH]@Z:q#>x(B|$Bª@LÃUXÄRT°EJ|!:`:q$B’6G§L_¾GTÁMZÒ[aÚcbØcdÖ^aÖ^`ÛcfØefÛfmÚliÙkkÚlkÛgcÛkkÞhfÛjmÝnlÜllÝrnÞpnÞxrÞzsàzràuáˆxâ†yà‰|áŒ|äŽä“‚ãš„ãšˆãž‡æ¤ŠæŸŠè¥Žç®Žè¬Žê±–ê²“í¶™í¸–îº ñÀ¤ñÀ¨òìôưòǵó̶õ̺ôÑ¿öÔÂô׺պ²†<TX;_:m9u=h:r @iAaB´\eÖˆzÌl^¾wpÄxpÆ€vÄ~tÄ€vÆtÂ~qÃ|u¾|rÄ€uÁ~w½|vÀ{u¾{x¾{v½xwºxz¸xzºvy´rtµxy®ru®ns®kt¬ip®os®gj·jcÈpXÍpSÌrVÈpSÇjWà”mò½‡öΜøÔ¤öÑžöΞöМöΙ÷ИõȒâ¢zÉnX =K†,K‡/M”<N DS™>Rœ?R EV¡BR¦FW®OZ¶U\´W\­LVž@Pž@Pœ@R BT¥L\£J^ L\P 8\?z9[Zqžs…²”š·˜ ½ž¡¿œ·Ž®{ fm€1I[ 6n<˜7LÉXXÚvlå„té’|ëš~î|îŸ}îž|훀íž|î {íšzésè„fâsgât`Üž¥Wy‡@`v8]K;M<UBR<VAXAZEƒFl\DUFSDZ*Q]F\EVIm(X—aŒ…FuUBl2Vi#NQ7O @RD‚Jnt4iQJUK}J~h$Yw@l~Bf$^~L}~Gxq:t`(an<qI€h™|@t”_Ž˜k›d”{©´ž¹¬«LtN@HC‚Q`–^Ž£tɬ´M=J 8H 6R :x(An&Dk@z)Dd=d>\>V>]A_Gt3Ts+J`B`Be(L^9p>t<†$@²DNÅTVÈUTµJK‚%>` 7j=‰0J£H[ÃTZÎUUÖY[ÙacØedÕadÖchÚ]`ÙdhÜegÜfiÚljÜlfÛmlÜlhÝmhÛjjÚllÜmkÝmlßvtÞxsÞ|uà}và‚và„}à‡zà‰~âŠyãŽ~┃㔃㘄䙈䟉䢋ç¦åªŒè«ê±•ê²–ì¶–î¹Ÿí¼ ò¾¤ñÀ¦ðªòưñůòʶö͸õϼöÔÃõØÃïÖ¶½‘”\<X:d:r1Kb6q!?]>b@¾kkÌ‚vÆmbÁwqÄ}tÄ‚{Ä€tÄ}tÄ}uÃ}vÂ|r¾uÀvÀ{t½xrÀ|x½wt½xu¼yyºvu½vv¹ux¸tu¶uy³qs²ps®lt¯no¯ls°ge¹eaÅlZÍoXÎvXÐv[Ðw[ä¤uòÁŽõЛøÓ¡õΜøÏ›øÐö͘öË•õÈ“ì¼~Û”r´TNŽ.D‹.H”6L›=N@Q”:N FT£FU¥DS­JU¶TYµRZ®JTBPš<Ož>NžBR¨GU¨JW¦M`ŸJ_N 5V8fGBašk‚®Žœ¹ž£¾¢£Á¢¡º”–±†ˆ£ot6P[4d7“2FÄV[Úulå‚rè’yì›ìš~욀ì›|í |ì €íž{î™yítè†jàxfÔdb·Y\Ä“ ‘JYw0MG <R?VCSAXAZDo3[l)LWATAXFYJVBXB\Im)Y–g‹…K{PCg,Vp*RV?S@L @`LƒAns.fQDwDug#Zd*[†M€z>yw@s†Q‰…W‰Lˆj2lq=r‰\‘z>v™oœs£‰Xz¬°›¸§ˆ£ŒRz_"UD Cd&U£z®¨yˆØÃÂY@MEF?P<w*Cv&Cp>~/I`>b=_=Z=bB^Cq(Gx/L\BcF_C^:n?s=•2H¸LUÁRUÇSR±DJ"<^ 8d@Ž4N¨K^ÊPTÐRT×][Úbb×^\ÖaeØahÛcgÚb`ÛdbÝgcÛjeÛmkÛigÜkhÞlhÝmiÚmlÜprÞrlÞrqàvnàuqáyqà}ràuàˆ{à†zàŽ€âŽâ}㒄☄⛆䟌堊è§ä¤Žæ¬ç³˜é²‘뵘츙ð¾¤ñªòìòůñŰñ˸ó˸ôͺ÷ÒÀöÖÄõ×»äÊ´ˆE]X>b8j9a7n<W
+8f;ÅrpЀuÃk_ÄvpɃyÈtÆ~sÇ€sÃ}sÅ}rÃzo¿zpÃt¼zt¼wu½wv¼xvºwvºxv·uw»vuºvw¸ss¶tt´sv®os®ps®jm°gl±ed²a]Ãi\Ñ}fÚˆbÞ–là t곈òÄŽöРöÒžöМøÑžøÐœöÌ–öÊ•õƉé²|Ð}^¦DL‹/J•6Jœ;L >P˜9N™@T¦GR¦KZ®OW²RW²SX¬FR BP˜:N›8L =L£JY©IW¦J\ H\œLeJ5K 4^Bx6Y˜mƒ®Œ—ºŸ¤¼ £ÀŸž¼–š¶ˆŠ¤ov8NU
+4\ 3,@Ã[XØrdâƒrè}ëš{íŸyìŸxê™{ì™xîžð ~ñ{í’vë‡käxfÕdZ·P\Ì“z2R^CLAVDT@R<[!N^!Jj&O]EU?WBZGVBT>TA[Go,W›m”~BrQCf'Pz8^^EN 9M <QF_K„Dq|;qt?qn.dZOq2dz@yw<w‚R‡Š\ŒŒ^Š~Ji0fzDyt:te’£y¨Ÿ‚µœušª‘ª’d…bCh)VRFr&Z³Ž°¾‘¡ÖÄÂ` GI?G>P9€0Et!>w!>ƒ2GaAb@\BXA^D^ Gr)Ep"E\A_?_A_:l<p<š:H´CJ¾INÀRS³AHŒ)?`>i=–:P­FRÊTWÐRT×\YØ``ÖXXØ^`ÚfeÚcbØ__Ý`^ßgfÛdfÛlkÜlfÜmjÝlhÜlfÝlhÞtsÞuqàyvÝxtÞunàztàuß~tâ„xà†yá‰{àŠâ㔅㗆♇䜊䢎å£å¤åª’讔箘괕캠캜ᄂð¿©ðîòƱñÈ´òȵô˸ôνöÒ¿õÔÂõÖ¾óطÕ™[8\9f8^ 3a7R
+<t>ÎzqÒˆÁmgÄxmʃrÈ‚wÅ~rÈ|pÄ}pÆrÀ|qÀ{sÃ~s¾|x¼yw¼zw¾xwºyx¼us¶st·svºxu¶st´ss³ru«np«jn«hk°hg²_a¸hfÌxhÜŠqäžuê«xì´òÁŽõÉ—÷МöÒ øÒšøÐ›øÎ–øÌ–ôÆŒñ¿†ážlÄgP›:H—5Lž9N¢BPž@R8O¦BQªHU­KW²QX·TW´NV§DNž=O”8K›;M¡?N§JX¨KY¢LašJbL`L 6M<[Dq-T–ay®‹–¼Ÿ£¾£§À££Àž˜·Œ¦rtt(BP 4\9.@ÇWTÜtfâ„nçvꞀí¢zìŸzì{ìœ|í zðŸðš€í•têŠiæ{fÕc[ªKd¢Ub¨s‡TAM@YFUAR=ZCf(N_D^AYAYDUBUGYESCUK|<j ¢w;hQA]C|=^\CM:R?[LVJd&Vz>i‚Ftv:nYJr5mf-\Hƒ}FxŠ\Œ‚R‚~J}r9pvC{s6q…T…¦‡®¨´£~­¨Œ©¢„¨^KRCz8meR­†¦È¨¶Ìµ¸T:I ;B ;N <.DnBw&BŽAT\?c>[@[>`@b@q&Ai!B[A]@c#FfBp@~(D¤AN¾NN½JL¶>G²DH–0Ag7o;—<N¬HTËTXÑVYÚ]\×`]×XZ×[^ÚbdÚecÚedÝgdÜhdÜfdÛjkÛibÛigÝldÛlhÜnkÝsrÞvqàsmßphÞxràwqÞzqáuà€xÞ„wàˆ|áˆ{áŒ⒃䘊䘇䜉äŸåž‰ä©’æ©æ°–毕貕꺠컟ðªïÄ®òƱñDzòÍ·ò˹ò̺ôÐÁöÔÃôÖÄöØÀäʵ„<UY 8`9W
+4_4K4?Ñ€tÖ†s¿lhÇ|rÊ„rƃtÆrÉ€vÅ}sÄtÂzvÄ~uÂ}w¾}u¾xs¿xv¼vrºwtºro¹rr¹rs¸st±tx´pt²ru®lo¬fj¬hk²b^ºb`ÍshÞŽtê¢zí³„ð¸†ñ½ŠóÅ÷Ì™÷ÒžøÓŸøÒœ÷ÑœùΘõÈ•ôÆë³~׊a³ML›:Kœ=L¢>M¦BPž=P¡AN­GU¬IR²MT´SX´OTªJQœCT–=N˜>Nž?O§EO¨LW¥JWžF]™K`NbH
+6R@XBl(RŽYtª‡“º› Â£¤Â¤£½œ˜·ŽŸipo+HN :]9“2DÄWWÚteà‚së‘xì|ð¡€ì |ìŸ{îŸ}î¡zð ‚îŸvì–uë‹kå|hØha¸e~¬_p«hjPHWLZHRDUE`&N`"IXE_EXBX@VCZH[BRKXRW„¤¢x8cNAQ>}8\j(NN 9bKaMUA`(P\K[Eb%SVIu;mf&\{H}‚E~ƒR„~J|xE|n4kwB{r:uˆVŠ£|¤¥Š²w¡£‚¡¨ŽŸx>qK?_J^P¦~™Æ³½¶•ŸJ?K=KDTA‰8Jv&Fu$C’CU_EgA\D^HaAcDt(FfEY<Z<_>i;r=1H°FL»HK­?HºHN¾PS›0@f:l>š>O¨CRÊPVÕ[[ØaaØ_[Ù]^×\`ÛcdÜhbÚgdÞhdÞidÛfbÜf`ÜhaÜjdÜkeÜmgÛolÜliÝpnÞtnÝplÞsoßyrà~sà‚tà€x߃xá„zà†{á€â€â–‡â–‚âŒâšŽã¡å«“媓媒殕籖궛뻠ᆭðÁ«ñíòǰðŲñ̺òʸðÌ»óϽõÒÂõÔÆøÖÁò×·¼…ŠZ
+4\ 4S.\
+3O6ˆ.EÐ{lׄrÁqnÅ~vÈ‚sÈ‚tÆ„uÆ„uÄ|rÅ~pÈ€tÂ~rÃ{tÂ|r¾|x¾|r»utºyv¸ts¶ts¶tt¸tr²tr°np²nj¬lm®gi°ffµd^ÆofÜŽqé§òµ‡ô¼‡õ½‡öÁ’øÈ“ùМøÓ¢ùÒŸøÒžøÑ›ùÍ–öÈŒñ½‚ä¢oÊjR§@Jž8M >M¡?LŸ<M AM©ER­LV°LU¶RVºUV²LU¦DN™>P™;M>P¢DT¨GR¨M[¡HVšCZ›NbœPdI2L
+5V@j,WŽVo«‚¶”žÀ ¥Ä£¢¼œœ°Š‡ kpt-HL5[
+4’+@ÃXUØr_å„qê“uìž|ížzêžzëž}îœ{í¡xï¤}ñ €í–yêˆlåyhÛg^Ø”“¯epz?]NEa GR?Q@a#Od%QZDX:`BU>T>[F\DUBRIa%Zšsžœu˜v2XL>O=l+Mm(OR<i)Qf#KUDb.XWLO?ZO\Ph.[r4jj8j‚N†R‚‹^’|L~s?um4rg2nˆZ‘¢~¥žy©^‘¬Ž²Ÿt–_†YGNFZNŸwŽ¿°»†VhREI
+;I<]>Ž:Hr Bz'C†5I`<j D^A`<a@e>p*Hf(K[B\<b:n?u:–:H­>F²@J¼GPÈZZÅST6Fg<o;™BU¬HVÊRTØ]^Ø`_×\\Ú]\Ú``ÜhdÜfdÜdbàhdÝheÛhdÛb^ÜfaÛhbÝibÚieÝjgÜmjÜtpßqkÝroÞtlÞxrß{qà}tà~wà‚zà‚wâ‹}àŽˆâá“à—„ã—…ãœŒå¡‹ä¢ä¨–殗宗泖鵜깢Eð¾ªï«òÅ®ðIJðɸñ̹ð̼ñͼòÐÀóÓÂ÷ÖÃöØ»àÀ®u @X:P2X 4N8”?OÏzgÑ|lÄysÅsŃuÅrÄpƃxÄqÄ€pÄ~pÅ~pÀyoÀxt¹|x¼xt»xv¸tr³no¶pq·roµqs¯ru¯np®lqªhj¬ef®ef¹baÔ€q殃ò¾öÅ•ôÄ“ö¾‹÷ÂŽöÈøÒŸöÕ¤÷Ò øÒžúÑ›úÍ”öÅŠì±sÚ‹a¼VN¡<N¢<J >K£;IŸ:K§DN®JW°MV´RV¹UX¸UW«HS?N—@Sœ:MœAR¥JS¨IR¦JXžH\šI_žSgšQeI1K3O
+7bJŠRmª‚³¼ž¤Á¢¡¾Ÿœ±ˆŸmqv0JQ2^7Ž)>ÁTTÚrbå„lé‘vëœ{ì¢xíž|ì {êžxí ï£|ðŸzî—tìŠhæzcÝf]ØŽˆ¤^jn9ZN?bJTC]Gh)O^DWAV@Z?XBT<_IM 9L @NIyJ‡žp–œjŽu.ZNCQBYDa$LT>r4\cJYJZJ[$PTCXKWHZLt3ji0bw=v„Q„c’~H{l6ik4n`%f‡Sƒª³—nš•j›¦²’m”ž|¤“_’j)hd TªŒ¬««v;`’s¡J=H <b@Œ7It$F|,H~*DaAg>c=d?b>bBg?bG^$J_De>t"@"<™5GÀFNÄNQÊWZÌWVÇSR 8He 8w"BŸ?N´JUÌOPØ]\Ø`dÚ`cÛaaÛ`]ÜgdÝdeÜc`ÝhdÝedÝfeßd_ÜeeÛebÞfcÚfdÞlfÛsqÛrjÝrmÜtnÝrjÝwoÞ{rß|tÝ}vß‚xáƒwá‡}âŠ{ãàŽ‚à“†â˜‡âœˆåžŒä Žä¤Žæ­•å­˜æ±—ê·žê¸ î»¦îÀ­ðÄ®òűðɲðÈ·ñȶîͼð;òÑÁôÐÁöÕÄ÷Ö¾îÕµ¥fpP 6N5U3P5§LXÒwdÐvnÈ{qÄpÆ‚uÇ€tÄtÁxÄtÁ~tÄpÄ|p¿|vÀ|qºtq½zr¼wr¸tn¶tr¸qn´rp±or­ln­kp®moªln°kl°`bÃjbáž}ñ¾’÷ÌœøÏ ÷ÌšöÄ“öÄ‹õÉ”øÐöÔ ùÔžùÒŸ÷Ϙ÷Êò½€çŸjÏsX¬JI¡<I¢>J¡=L >M¡?O®DN°GPºSV¹TW¼TX·TZ¥ESš=P˜:N>N ER©NX¦MX L[šJ`šHZ™Mb•H^G0I 2L6^D„Jl¦{г‘¼ ¢Å£¤ÂŸœ¸Œ¤rvx1KP0\ 6†&?¾VWÛr\å†pì”vìž{ï {ëž}ì {ìž~î¤xï¦zòšwî’qì‰dçyaÛh\Î}u’HdR>PAdH\Id"N]BZAV:W<X?W@ZBXAJ =J D`*`œz§›f‡—f„q0XL>NAR=` H\Dr-S^AbJS=ZJVCa"QWHTHl,\b)Wj4ju@o˜pšˆZˆ^ R^![a&e…X‹¤ˆ®žz©¦„©¨­B|€Ll¢~¥I~™k¤¶¤Â¡w« |¥À±»\GK?d>„,Dk?x(Cr"Dj Bg@j"Di@`?c>h@b@^DdGhAu?’0E±GTÊRSÌXZÍY\ÎZWÆTR¢:Hg9~,G›<L³LTÐRTÖ`]Ø`_Ø`bÛhfÙdaØgiÞe_Üfdàe`Þd`ÛcbÜhfÛhfÜf`Ûf_Üh`ÛnhÜomÜpjÜqmÞphÝtnÞslàymÞ{tà}uÝ€vàƒ{à‹}áˆ{áŠàŽ€áŽ€ä™…âž‰ãœˆâ¢Žä¥‘æ­‘æ¬—å±–êµœé¶ í¼¥î«ðªðűðÉ´ðȵñʶðͼòͽñÎÀóοõÓÃø×Ãôض̜”T
+2D-M2R 3´Y\ÎreÐ{jÄzpÆŠ|ÈsÆ‚uÄ~vÂ~tÁ~tÁztÃtÄ{u¾{q¿yu½vq¾wo¹xtºxr¹sp¶qn´rt´qr®kn®jm­mu«ik¬ei´aeÊp`ê°ˆòÉœøÒ¥øÔ¦ùОøÈ•öÈ”÷Ì™úÒœøÕ¦ùÔ¢ùÓœøÐ–öÆŠí²tߊ`Â\O«BIªAJ¦;F :H 8H¥<L¬EP´KS·PU¼QSºRW­JTŸCS›<O˜9O AO¦JV¥KZ¨O]žJ^›Lb™Mb˜PcŽDZG 4I3N7[B‚@b¢t‡´”¾¡£Å¤¢ÁŸš¶¥tx9MT 2[ 3Œ"<ÀVXÜoYä†të’uî ~î¡{ìŸzì|î¢~î¡{ï¤zð xî˜qìŠhå|eÚh^ÊrlF_VF\Je"Lf$N`HR :YBS;[<X>XAYBO@MEd&XŽ_’Z‚‚Fg…IlbINAM?QD[Fj)Pp,TU9b HO 8O=VEh*T`"PP>k/^d&V]&\`$[‹d’g”g(df.htE‡‹c– z¦Ÿ{¦§‰²®’³ z¦ˆDq¦r—x5h¦ˆ²®•±lˆ’qz†_jQ@V>n"@}(Da?r!Bm!As'DeBf!Bl!Bd@h"Dd<c=`?f@z&F(F¡:HÄTRËSXÏZZÍZ\ÎWVÅTV›-Dk;†6LŸ@O¶LVÑTV×WR×][Ú]`ÜdcÚhdÛgaÝefÝicÞfbÞf`Üd^Þd\ÜecÜgbÜhdÜidÝhdÞljÜlhÞnjÜrkÝrpÞxtÞvoÞzsà€xà‚{á…zàƒxÞ‹}àˆߎ€â„㘇ãœä—‰ä¡ä¦äªå­˜æ¯šç´œç¶¡ë¹¥î¾ªí¾¬ðƳïIJðǵðȶð̼ñ̽ðÎÀñÏÃöÑÀ÷ÔÄöÙºãİr)EE9H4X 6¼_[ÍndÎwkÃxsÌŠ{Ä}pÆ‚y€sÃrÂzpÃ|pÃ{sÁ}u¼xtÁzr¾wp¼zs¼vp¹xs´ql²on¶sn´pn­mo¬kn­gh«de¯bd¶^_Ñ}iôÍ øÖ¨øÔ¦ùΚùÊ”öÌ™÷ΛøÓŸ÷Ô¤ùÔžùÑšøÌõ¿‚è nÖvU¼NI­DL°?F¤=H¡:H 7F§AN«DO´NV¶TWºTU²MT¦BP @R›>Nœ>R¡FQ¥NZ¥L\¡L\šMa˜Pf˜K_“J\‡:RH.J4M
+:\CDc t„´’›Á¢¤Æ¨¤Â¡œµ‘¥xy‡BTU 4\
+4†#;¾QRÜp_älë”vî›yíž{íŸ|îœ~îŸ|î¡î¡xð ~ì˜nëŠjå}iÙjfÃbbŒCdbOh%Rj&RZEXGS>X>X@Z<[>Y@VDRH^L’d‹|Fj^LƒNz~Bdg.XTEPCSF\!Kv4]k&LR8`GR<Q:[De(P`#RK
+=a)Rl.`a [j:p‡cœŒZŽŠ[’~L†TŽ‘f–¡x¢¢|¡¤z‚Knœw ¤z¦¨²²Ž´Ç®¶¡}[BG9K6f&Kk"@y(Bs @]@u"Bj>n$Bb?f Bf?a?l$Ad@b@bAoA€(B-F­DKÎWSÒZXÒ[ZÌXZÌTTÀLO&>g:‹<P >M¸KTÓXVÖXVØ\]Ú`_Úb[ÚebÜgdÞj`ßf^àgdÞh^ÜgcÜf_ÚheÚjgÝjdÝjhÜhcÝnlÞphßpjÝrlÜpjÜvpÜxnÞvmà~rà~uàwß…à„|á‰~âŒâŒ€â‘„㚌ä‹ã¡Œã¤å¦‘䮘沚浘踣뺦뽩íÀ®ïƱîÄ´ïÆ´ðÇ·ïʺðÉ»ï̼ñÏÀôοõÒÂöÕ¿ïвšYhA1H5a:ÀlgÎl]ËzjÄytÈŠ|ÄrÂ|rÂ~rÀ~vÀ~sÀ~t¿|tÀ{r¸xu»xvºxt»yrºzv¹us·wr²rs±rr²qq¯mm¬jm¬fg®fe²`a»b`ÖŒrñ¾ŒõΞ÷Õ¦ùÒžöÍ’öÈ“÷É‘øÏž÷Ô¢÷Ô¥øÑøÎ—öÇ‹ï²záŽ_ÌiT¹NP´IM°HO­BN¦@J¨?Jª@K°GP»RR½XT´MR®IU¢CR=N<O CS§KZ¦O]¤N\žL_˜IZ–DZ”E[ˆ<Qˆ=XF0J6H5[A|Ddžvˆ°˜¼Ÿ¢Â¥¥ÀŸž¶¦yy‰JY]8\ 3…$?¸PTÜqdæ„pê“vìŸxìœ{ìœzëžxêžsèwëxîwè‘vä‡rà~rÖplºZm”Lsl'Xg%Ne"PTAS?T>Y@W<X=Z>WGZLi*Zn2[j.PQHYJ”b†~<bn2XVBTARB`!Lw7[h#JT@XAU@P@YDf&Rf(WL A_(QAq_OTIf/`n4f‰]Ž”kž•s©–jœrŸ¦‡¨—i|6p‚Kršm›v¢²‘´º•«¦€¨†YŒ^&Z`'IBXX<x,BjBdBz&DfAn$Dk"Dk$BeCd<o"B`=c<e<}!@‡)@–4G¹GMÍXSÑ\ZÏZXÎXZÍ[[ÂPN…!<h8;N¢@QºKSÓZXØ_`Ú`\ÚbbÚ^\ÚdgÜgfÞfaßlfàkfßebÜdcßf`ÜfcÛe`ÜffÜhcÜieÝidÜjfÞjbÛliÚpmÞupÜumÝtlß|tß~và‚zßy߆~áˆ~àŒ€â‘„á”„ä•ˆä›Šâžä å¦”䭘江粚綞꺥뺨ëÀ¬îIJî²îÅ´ðƶðʹñ˽ð̺ñÍÀòϽôÑÃöÓ¾ô×µÇG0D5g9ÃigÐn^ÊwkÅ|vÈ„wƃv¾|vÀ~tÄ~p¾~t¾{p¼{s¾xm¼yv¾znºwp½zs¹xt·xr¶tq´st²st±pp¬ovªjl®lo¯fe´c`¾jhÛ’wñÀ÷М÷Ò øÍ“öÆŒ÷ÆŠö˘øÐŸúÕ¦øÔ¢ùÒøÍ’óÁê¢nØy[ÄaT¼RR·KL³EJ®GOªAIªCL«BM°HP»PQ¼RU¶QU­IR¢DRœ>Ož@P BR¥JX¥LZ¡L]žJ^–JZ•CV‘@Tˆ9R„5RH3F0L4W?w@b tˆ¯š¼¡Â¤¢¾  ¸”§z|Uac:^2„ =·NPÛodæ‚në’ví›|뜀痂æ˜~ä˜|ß”}â—‚åšä’{à…uÝ|rÒki¸fy§kk(UXFYJTCVDW@X>W@`HZFWHm3\€Fp]EUFTGbM…Ai~<d~>bVCWHTDc*Pd"Kf(QXCU>VFTC]Jj1ZXFZQi+V}Bpe%VTFUJZXm:njœœ®špž”d“Ÿ~¦–l—ŒU~}>hs:_zQp’s•’b°ŽŸ¾˜«£x¡ªv “Rz>nŽGfo&Hf Cj Bk F}0L‚9Pm>e@hAi>d;`<f<†(AŒ)@Ÿ5DÀIKÌZXÏZ[ÐYYÐW\ÏZX¾NR?j<•<N¨GTÃRRÖWR×[WÙb^Ùb]Ú_\ÚefÚjiàidßojájbÝhdÞe`ÞjcÛbYÜ`]Üb]ÜfbÝg`ÜjbÛlfÞndÜpgÛmhÞqjÞulßvrÞypÞ}uàxàƒxÞˆ~à†yÞ†zâŠ~áŽâ•„à”‡á–Žâ¢Œäª’ä«“å³˜æ²˜ç³Ÿêº¤ê½«êÀ­í³î²îųðƸðÉ·ð̺ò˺òÏ¿ò;óÏÃöÒÀöÔ¸Û¸©`<D6w:Æh^Îs`ÇzpÂ|sÆ„vĉ{¿|t½ztÁ|pÀ|t¼yo¿yr»zpºzt¸vt½xn¼wr¹wp¸zs¶ur´ts³ut¯lqªoq¬kp®gg°fe¹c_Æmcà–zòÃöÐ÷Óœ÷Ê–õÄöÄ÷Ê”ùÑ›ùÔ¦øÔ ùИöƈð¶yâŒ^ÎhUÂZTÄXTºLN²GOª=G¬AI§CMªIT¬FL¶PV·QR±PT¨DOž>Nœ;K>NŸHV¨MY¡I[¢Pc™EZ”JZ’BZŒ<T‰>Y…6RF/D2J:U>v9^šj}²—Àž¡Ã¤¤À¡º•¬~~U]]7[ 0‚#<·JNÚl]çƒlí’wîœ{ï~êœ|æ›~曀ãšå †èœ€è“qè†nâygÕlmÆr„®bl&Rd&MRBVBX?W@X>T<`B]DXBe*Ma#GUA]HZKYH‚Bk}?dv2W^HRD_#Lc&OWC`$J^EYHZEZHZGd*S^R^P|Bk}@qYJTHF BQNi5nf˜£„¬“f•™r§˜qš˜pœ†Fl†JuM
+7O :i0Kp1XX:h#A†?QŒG[†Rp o“¦lž\Œ¢sŸ˜_‰”Y{†>Vj@n @c>c;k>a;e>o>†(B™4I¨@NÇOQÐ\ZÏWYÒ[\Ò]bÒXV¶HM%FtA›?P«HTÆTZ×[V×]^Úc`Úd`Ûa`ÛabÜfeÞicÞljàjeÝhbÝidßgcÛdaÛc_Üb\Úc]ßf_ÞjeÛheÞohÝneÜmfÞnjßwrÞzsàymÞ~yà~và}xß„y߇{߆~⌀⒂┇ãˆà˜ˆá¡ã¨Žä©”存氚泠鸦軨꼫ìÀ¯íòî±ðÄ´ðƶñÊ·ð˼ñνðÍ¿ñÐÀõÑ¿öÒºè̯‡=WF:*DÇh]ÌtgÄ|sÀ{sÄ€rÄŠ|Ä~sÀ~v¾|r»{x½~t¿}tºws½xo¸wr½xs½xr»yr»zr·xt²sr¶ts®mn¬jnªgh­ge´hdºgdËnbå¡|õÄ“öϘøÑš÷ÈŽöÉöÄöÊ“øÒžøÕ¦úÒ¢ùÎ’ôˆé¥jÙyYÇ]TÄTPÅXV¹KN²JP¯BL¬CM§?K±DN³JNµPS²NR¬DL >Oš<K9HžBQ¢KY¤N\ L^šFY˜DX˜F[‘<SŠ>WD[‰AXJ 4H2G6R>n1U–dx°Ž•»šžÃ¥¥Ä¢Ÿ¿œ™®„„ŒS`c8\9‚"@¹NQÛk]æ…kê’yìš{ï›yìžyìž{럀ì|í¡|îœzë•tèŒkäzfÕwuÆm~˜Fjd"ObFXG[DW@] FX>ZA^BY>U@YBVD] Jc#LXEXFw7\r5^j)PbFYGg*S[HUC`$Gc"H[BY>S@Q@d&R^ RXH†Ott8fL<e,eLE\ Zo4s‡Z‡–lœ}Jvœ‚ª…P‡bŠœlœY~r0cN =`=|FmP>W<x1DI 8N;w/Ir/Jl%Kžcf–[o‘JaOsy/Qk Bd=f!FhA^=f=}'C.Ež6E´CLÎUTÏXZÐZ^Ð`bÎ_cÑ\^­;ItB~(Ež@R¯ESÎX\Øa`Ù]\Ûb\ØdfÚcbÚgfÜjfÞigÞkdßggßgbÞd`ÞjfÜfcÚbZÛc^Ûc]Üe`ÚgbÛgfÝkeÜohÛplÝohßsnÞtnÝzrÜzvÞzwà‚yà„vß‚xß„yáˆ{à€à“‚㑅ᙊࠊ⢌ã¤äª˜ç²›æ´¢è¶ èº¨é»«ì¿¯í³î¶ðĶðÆ´ñȹðɼï̾ñÍ¿ò̾óпõлñÒ®´pzF5‘8JÉi\ÍvbÃ|r¾|rÃqÆ‚s„xÀ|pÀ~rÂ{u½|u»zt¹xnºwrºzo¸xr¼xo»yt¸xt¶wt¶vrµur³rqªloªnm®lm²ki¼hbÌn`䤂ôÁ‹÷͘øÒöÈöÁ†öÄŽöÊ—øÖ£úÖ¤ùÑ™øÈŽñ¹|ä•bÔlUÆVSÀPRÀVX¸KP°HN¯HM£=HªCM±GL¶HJ¶KN­FP¥BL8I˜8Fœ9J¤FS¦LZ¤N^žO_–>T”CX”FY=RŽAYŽA[B]I5H2I
+8R?f%L’_uªˆ“¹šžÂ¤£Ã¤Ÿ»œ”«…†Ubf<_4‚%BºLPØl`ãnë’wì˜zîž|íìžvì |ì¡zí¢}íŸxë–qç‹oâzbÓoqÀsƒ—EhbH[A[@d"LZ=V@W=X>\HZCUBYH^"Le(PZFTFc Nq2Yj.Uc!KYD^"L\FXGXGg+Nh-TX@S;N=T>g%SOD\NƒPvr9kMJX$Pv@k,dt@zƒLhš‡[”dŽl …Q‹˜n›žtš–f“\E];„TvR7g>b;H?]@w,HfCYDp1Ja"Ht$GŒ?Mœ]fo&Hh>b;`<_>o@†*A–5F¢<J¼IMÍVXÌXYÎ\`Ð^aÐ`bÎ^[ <In?Ž4M¥FU´MUÔ``Ùb]Ú`[ÚbcÛcbÜggÜggÛlhßhdÞgbÞhdßlhÞjdÝifÜcaÛdbÜdaÜd`ÜfdÛkeÛieÛlhÛigÜlißmjÝrkÜupÜtqÝxsß|tÞ„{Þ„{Ý„z݇{Þ‹}à~á‘„â“áš†à™ˆâžˆä¦’å¬“ç²•ä³ç¶Ÿè¸¦èºªê¾®ìÀ³ïÆ·ïÅ´îÆ·ïȶðɺð̽ñÌ»ñÌ¿ò̼õоóҲРšM 6š>LÇbWÍxgÄ|uÁ€vÄ‚w‚sÁƒ{¼zwÂ|t¿zvÂ~tÀzsºxo»xrºzrºwq¹ytºwu¹xt·xu´vr²rr°oo­no­kl±lm¸lgÀeXÌobà˜sò¹„öÈ’øÍ÷ÇŠöÀ…øÃ‰÷Ì—ùÔ¢ûÔ ùÏ•õĈî²x܆bÐ\NÅWVÀTQ¼RS¸OU¶HN¬DN¢>J¦:G¬EP®EM°IP¤?L—6Jš8L˜<J¢CP©HU¨OZ¢M`›J^–BV˜I_”DW@XAXF^“H`P9L9L ;T>f$K[sª„‘µ’˜À ¤À¢œ¶š”¬†ƒ”Ydf<^:…'F¶LQØk`ãhê’tëšsëžzë yìŸyìž|ì xíŸzî yì™tê‹sàxeÖy|Äv†¦KkgHbEZAdHU=WBS@V@^HUAVFd$Pq/Vg)PVCXKXGj*Wd(Lf(Ng&M^ LR?UDTD]Hu<aUAQ=RB]Fa"NMBl2gt:jk5^s>yTPs@q|Bu?kL|}JvŒg”‰`”„XŠ}Iz‡Zœt¦€¢„Hy[>‡Y|T9d=P<Q>p&Bp<e%H[>u)Dh@m ?a?|-@r&D^@^;[9b:z$AŒ2Cœ6F¯BNÂJOÍVVÐ[ZÐ\^ÎbdÏ_]ÄTV”/DjB“:L¨LZ¼RXÖ_^Ø`aØ`^ÛggÜhfÞhfÝheÝfdÞleßlfàlhàngßmdÞhfÛfcÛdZÛfdÚc^ÛgdÝhbÜjbÝh_ÜmbÜndÝpfÞpmÜsnÝvrÞxoß}uÞ~wÞ€xà‚yÞ‡Þ‹àŽ}áâ‘‚à“€ßš‡âžŠä¦Žä¨‘å­’äµè´¢è·¥é»ªì¼­ê¾­î´îòíŵðÆ´ïȺïÊ¿òͼòÍ¿ðÌÀôξóжßÀ¬o E BLÉfZÌxiÆxÀ€vÂ…|¿‚yÀ€t¾}wÀ|pÀ|t½|vÂ~vºzr½{t½{v»xt»zv¼zx¸xqµwu²tr³sq®nm«mp°pp¶rn»leÄl]Êl`Ú†dê¨xñ¾ƒöÀ‚ö¿„õ¿€öÃŒøÎšúÖ¤úÔžöΕóˆë¨mÚ|XÊWSÂTRÂQT½NR´JN³LV§DM @M¤>J¬DL®JP <H•2E‘.Bš9M¡IW©KX¦L^ GXžJ\•BV”BZ—F\”E[•C\@Y‘Ea“H_L
+4L
+5K 8Q >b L‹Ul§Œµ”˜¾£ ½¡¹˜•¬‡†–_jm$Cd<„#B¶HNØj^âiéŽuê˜xìŸyëžxìœzìž{êž|ìŸzíœyì—rè‰gàtfÛ€}Ðz„´`ufEo&PV>`FQ>R>P ;VG]HUIu7b…@ek'L^CTBTDZIh*Sb#Md$Kb#G[F^JZFVJSGd)O`PO<UA^I^$TPF~Huj+``&V}Myn2jQFyT„NyM‡zH‰‹lœ–u¢ˆb“u<nd&]{Fq˜j }§}8bKp\ CdHL <T?r$@j @`;`;o$Dr(Dg>^>d>i#C_?]<^8j:€$=‘3G¤8H»HNÀJRÉW]ÍVVÍ^_Î^`Î]\¹NS#CnD™:N©IVÄUWÖ`]Øc`ÚbaÞjgÜkhÞifÜjiÝgißkeÝjgákfßkgÞhbÞiiÚecÜfbÜgfÙedÛfbÝkeÞg\Þf`ÝibÜlbÞlgÞtoÞtlÞupÛuoàwqà€tßtà‚uÞƒzà‰~ß‚à~â€ß‚à–†â›†â¥ä¦ä­”氚涢浢漪꽬齭ìÁ®îÂ³îÆ´ïŲðȸîɼñ̼ïʾð̾ò̽òϺìÌ®žVjªGOÍj]ÊzfÀ|t¾xmÀ„x¾z¼|x¼~t¿}w¿~t¼}y¾zuÀ€s¾~w¼|u¼|t½{u»zvºyt¶zv³vu³vt²rr®np´rl¶nm¿peÉo`Ëm\ÐsZ܇`è¤nê­rí®vî¶xõÃøÏúÖ¢ùÒš÷Ê‹ôÀ‚è i×rUÆTR¾PR¿LO»LO´FO®DK¦<I¢<J¥AN«HPªAJ˜6HŠ&@1FŸBR§LYªLY£HUŸJX™BTŽ@S“BV–BW”BX”D[‘Ha‘JaŽCXR<R>N:M 9[F„Jf¥}ˆ´”𽡤À¢ž¼š—®……šdlx0Jj>ˆ)DµFN×i_ã|dëuìš}ízìœzí~é|êŸ{ì }îž|ì”qê‰káxhØvvÚ‡„±WmkFˆ>d\BZAL>NBN@_Im&R~=ey:]c!CX>TAPDTGb(Tk(Qf*S^FYFVHh&R_$LZ#PRJZ$It8hRBbLXG`(\e.\m2[b%Wd$Zs:b‚R‚LLII‡pœœ–ÈŠb’—|±‡d’ˆ^ˆL~i.gd+dŒdž’f”˜n “_šzFp˜}¤N <[Dn AeD\Dh Bj Ap"B`>b@`>c>_>Z8a:p >‹1B–5D¨;E¿LPÅPTÊVXÌ[^Ð\ZÏZXÊVW®DNnC~,JBTªLXÌ\^Ø^]ØffÚgfßhfÞkiÞjgÝhfÝmiÞqpßifág`ßgbÞf^ßgaßf^ÜhdÜc`ÛibÚfaÙe`Þe]Ýf\ÝjdÞldÞnhÝpjÞupÞvpÞ{ußzsÞ}rÞ|tà‚xàƒx݆zàˆ|à‹~ጀâ’ᘄ☄➊㢎䬒䫖洠泠纩黨輮ëÀ±ïóîÄ·ðĵðʸðɼò˺ð̽ðË»òÌ¿ñλðΰ̌‘¸LNÐpcÊxf¹tj¬he¸rp¼wn¼wr¼zu¾{u¾~z¾w‚tÀ~x¼zº|x¼|t½|w»{vº|v´yw´wt´us°op±sqºrm¼tpÄthÈtfÌr\Ît_Ît\ÖZÞŽbà“fê­zöÆŽ÷ÑšùØ¢úЗ÷ÉŠò»}è—`ÒiVÆRP¾MN¸KQ´EM¯DM§>Lž9L£ALªHT¦@N>M’1GŠ.H”9N¤GTªT\¨LXŸHVžGY”?SŽ;T‘AS”F[”H\”BZ”H[H^†8OR:M 7M 9J
+9WB~Ddžuƒ°’˜ºŸ¾¢ž¼›–®‰‰žnu~:Pn?†&C²FLÖi\â€hé{ë˜tîœíšzê›}éžzéž{ìž~îžxì”pçˆnßxfÖprÜŽ‚²Zrs&MŒBb^JXCO?OD^ Nw8^{;^h$K[HSBSBTARDVHj-Zd Om-X^I\I`$Nk)Tm,Uc)RWIPCk,W`$N\HQJd*V‚R‚^GUD]Mc$R‚Zm4fOMS IoBdq?oˆbŽˆh–‹e“p8d\R]TxK|g£©Œµ¡v­¤Ž±ŒfN:^@k@^=T<n?c=d=]8b<`=[8]=_:f:z >Ž,D¢>H¶FPÄORÉTVÎVWÌ^^ÎYXÌY\ÄTZ—3Gh?Œ4J¤BQ½U\Ô]\ØadÙedÚfeÛgiÝnjÞmhÞjkßleàqmâmhàldÞhaÝjfÞieÞh_ÚhdÜc^ÙfdÚd\ÞdaÝf_Üd[ÝmeÜpjÞlkÞpkÝslÞsiÜwnÞxlÝ|sß}tà}sßuÞ„{Þ„vß‹|߉z߂ߖ‚àœˆáž‰â¨ã©ä¬”è°ç´¤è¸¦é»¨è¼®ê¾±î±îÅ·ðƸðɺðÌ¿ñʼð̼ïʼò̼ñÌ¿òϸ䶫ÂWXÒw^Åxa°e`¢Z[©cf«ff®ij´nj¹pk¸snÀxs¿~t¾~wÀy¿€w¹}wºxº~uº~v¸|y´{u·zt´tr¶ztÀsnÅxoÈxnÎykÏvfÐt\Éq^ÊiRÎsZÙ„dë®xøÈúÖ¢ûןûÒ“øÆ‰ð³qâŠ\ÎaRÁPPºNPµJO°>H¦BP¡9LŸ<N§BP©@L¢=L•4GŒ,D6J?R¨LX¨PX¥HZšCV”AV>RŽ>V@T•EX“F]’DY“Nb‰@R0JN:M 6L
+5NAR@zA`žx†°š¸œœµš·™–¬ˆ†žlr€;Pn>†&>µBJÖfYâ{bè‹të–vìšzë›vêœwêžwì{ìŸxíœ~ë–xèsâ{jÓfeÚ†z´ats'K‰?`b I[CUBUC\C`E_CWEWEXEV@ZHTF\ Jd"Nk+Xj+P_ LYIh,Ue#P_Ic"Ld!La!Ij*N]APCLDk6]}Fq\FPEYNl0c‡`ŽBzi/bUKWKVKWNtHr–}¡„X„[K\Rn0lrBs˜o—¶¥¼¨˜§_$JY<d<j?V>X;r!>e!C`>]<b<]8Z9`;e8j:ƒ(A‘.C§>J¿LPÂOTÊPRÍXXÎ^`ËYYÍXVºIM}@lD˜=R¨EQËZZØ_XÜdbÚbbÛghÞhgÜgfÞjfßkhàidápkàsnálfàhhÞhdâkbßldßlaÜhbÛfcÜdaÞgcÞkbÝfaÜlhÛmfÜllÜphÜsoÞwqÞwmÞxpÝysÞ{oß|rßuÝ‚wÝ…{݇~ߊ|àƒâ“€à›„áˆâ¢‰â¦ã¨ä°œæ´ å¸¤è¸¦è½ªê¿­îÀ±îĶðȸðȺðȼðÉ»ð̽ð;ñ̾ð̾òϺïÊ·ÒspÓv^¾iX¢OR–DQŸTZOU¡Y^¢\_ªfj®gf´nl¶qt»xu¾zv½|s¾{»z»€x¸|y¸}z¶|tµyu¸vs¼wpÄ|uÉ~rÌoÐ}hÐwfÐt^ÊtdÅk\ËviÖ†kì·„øÌ–úÙ£ûÖžûÏöÆì¦gÜ|ZÉ[NÄNL¹MP²HN«DP¤<Lž7L¤@NªFR£AO•1F1F1G˜<M CT¨LZ£IX H\™FV“A[<R‘@W”CZ–H[’DXŽDYCW„9Nv'?P:N6J5L;TA‚Fd¡x‡­•¶˜š¸œ£º™—®ˆŠns€<Ps#@†&@±BJÕdXß{iè‹pê–vì›zêxìœzëžxìyíŸ{îœyë•tìŠnå|bÔd_Ðtr®_vx,N5Xl%PZCS@R=X@]B[CZDVDT?TD[JXEk,X_Jl)S[L\!P`'Pz>ag*PRCYE\@c#I]AS@OAP?wBjb J`IUJXNx@ui˜Žg—i0^o6jZHX HLFSO‚`z•mœ[P\"RJ~€Gxr4^˜wŽˆVuO 9a=j>e>R7]8h<a:^8^;]5X8Y8e9g;o>‰*?˜6D±FKÂKNÅPTÊRRÊUXÌ\^ËY[ÉXX£9LiIx&F<L¼PVÓ`\Øa[ÚgcØfaÚigÜgfÝiiÝifÞhdßmhàniáncàpjájdàjbâlbàldàkbßjdÞe\Üg`ÜhbÜg^ÝldÝhaÛoiÞojÝojÞqjßxmÜvrßvjßypß{qà~uÝ|qÞ‚wà‡zàˆ}àŒzá}ß”á˜„á˜‡âž‡â¤Žäª’æ®šå²æ¶¡è¸¦è¼¬êÀ®ìÁ±ì´ïÅ·ðȼîÈ»òʼñÊ»ðͼñ̼ñ˽óϾóÑ´Ý—ÊlX§LN”@J†4H˜HS‘;F–DI˜KRžOT¤Y]©`d«ef®jh²ll·vv³trºyv·xs¶xt¶zx·~z¸|wºzrÁvmÆ{o΄tÒ„jÔ}gÑx_ÐvYËq[Éo\Ðt]Ýmñ¾ŽøÎšúØ¢üÕ™û̉ó¼|ç˜^ÖmTÅRL½KMµEN¨>Hœ:Jš6I<J©BL¦CN—8MŒ,BŠ-F–9MŸFX¤L]¢JY CT›DT–CW:P’@W–EW›Lb˜J]‘DVF\†:R},Em>N 5L 2M
+8M :WB|<]šk|®Œ–¼ ¡Å¦¢Á¢µ– qt€:Or$@ˆ(@´?GÒe\ß|fçŠrê˜zê–xìœzêœxìœ{ëž~ì¡zï yì–wëŠmè~bÖf]Èbd¤Vn~4V„>^p(PT>N?SA]Fa"IYDYGXCTBTC]Ja&Qe&Lb&Pj(SVIWLd,Ur5Xl+PVDT@S<ZF[CTAR@XDr9bTA^ Kj+^\Tj+`Œd•’g’‘h–\"Ki)TZNJ>VLf1To<Z_#WYM†V†[††G~Œ\y}BbU 7g9l@^9U>b<^8^9^@^6T 4X 6]7i=u&C~(C‘,@¦>HºNOÂORÇSSÈSTÊZXÌ]]ÎZT¾PO‡&@c>ˆ/I¢ANÊZ\×fdÚd`Úb[ÙcdÚfdÜhfÞkfÞkfÞnjàlfánlßmjÞpnàlhàjfàjcßngßgdàhbÝd\ÛhfÜhbÜcbÚgbÛicÚjbÝkfÜrkÞrhÜulÞxpßumà{pß|qß~rÞ|tÞxÞˆx݉|ߊzâ|ß’~à•‡à•„á˜‚ã¡ˆâ§Žä°—ä¯œæ²¢ç¶¢å¸¦é¾¯ìÁ´íŵðÆ·ðÈ·ïɼð;ð˽ñÎÁòÎÀñÎÂôÏ¿ôԺ亩·ZV‘6FŒ2D€'?Ž6C„,=‹8EŽ7G“DN˜DR›FPžOUŸR\¤^_§ad§bf¯jj°nn®pq°pr³ut¸ywº~{Ä‚w΂oчtщkÎz`ÈtXÇiQÈiTËnWÔ~bå¥zôÅúÒœüØ¡ûÒ’øÆ‚í²râŠXÏbSÀQM³FJ¤=I–1G“0F–5J¢>L¨DMž>KŽ.F‡(BŽ2H•:N¤N[¤IXœDTšDV™FZ”CT>X•BWšN`œOb•EZŽEZ‰>T€6Mt%@j @L 4L7J 2L
+6Y@o,P•f}¸˜œÂ¤¤Â§¥Á¥¡¸—–¦z|‹G[n!?~ ?®>GÓaUÞveä‡nç”sè—vèœ~êšyìž|êž}ì |ð |î˜uìkçcÛk^Æ`eŸPn€4Z„;^{3[N>N@ZAj%LZ@WAT@RDVGXHj(Qj*RVDd+Tb&PUKWJg(Oh&Jr.V]EXCXAT>R8]DQ>ZFYBWHa,ii0a…X–„NŽƒN„˜pžŸ†©m;p[Lj0\l0hVCe#L`!N\Jd%U‰b•r/Z‰Jt—b‹d CX;b<f8R :Z<c>Y<Y:Z7Y8U4Z6b:l;+DŠ,B˜6G´FNÄQQÇRPÇRSÈPTÌVTÉVSÇVT¤9Dd;r$G’:N®ITÔ`ZÖa^Øb\ÙebØffÚfdÜhgÞnlàmhÞohànjátiÝkgàgeàjeàndándàlbÞlgàiaÞe^ÜdYÜhbÛd\Üf`Üh_ÜlcÛieÞpdÝpfÞrhÞrgßvpÞypÞynÞ|sÞvÞuÞ„v߆x߉váŽzà’á”‚à–‚àš†âœŠâ¤Žå¯˜ä®—ä²æ³¢æ·©é¾¬ëÁ±ëĵïÅ¶íÆ¸ïʹñ̼ðʼò˼óÌ»ñÐÁôпöÓ¼ëʶ±UZ…,D4F…0J‹:L€)B‚+B„,@‹0@Š8J9F“@M“CN–DP˜MU˜JZœR\Ÿ[`Ÿ^d¤`j¨gj¯rs¹tpÄ|t͈vÒzÓŒpÎjÃv]¼eXÂjYÈlW؈eöË•üÕ¡ý× ûÎó¿~éžbÚuVÈYR´FL¥:F˜4EŽ,C2G˜8H¤BP¤@L—6H…&@Œ0F™>N¡HV£NcBT—BV˜CW”CY“AV’BX”D\›PbšOc”F]EY‚8Pz-Fl<n;L3H2H
+6L 8Q=h#O–j|µ”˜À žÄª¤Ä¦¡»›‘¨~~”Wcn<&@­=FÑ`WÞviå†pé“wê˜xê˜xêž{ëž|ì›zïž{ïžvî—xìŒnç~aÞodÃX^¤Uu†6[ƒ<^|6ZP>O>`FdAV@V@VBUCTFZHo0V\HSHl,V^MQJXNk,Vj(Mj)OaF`DY?R@WF\B_G\FSF_'LnErFDpBlˆZŒ|E|‘h¡‘jޡޏx>ua&Vf(Sj(br2az8fv2fEl „šZBf#Br4KbB`=d9]6R 5b@]:W8Z>\=W;W9]5i @q;ˆ0C‘1D£<H¾MNÆRRÊXUÆTRÈSUÉTTÇVT¸LPx;Z=„0NžCQÀVXÖ`]Ùd`Ú_ZÜhbÛa_ÙcdÜf_ÜjgÞjhàlfàleáoiàlfâgbÞjcàofájbßf_ßjeßgbÞe^Þh`Þg]Úe\Üf[ÜfaÜg[ÜleÜofÞmgßofÞrjßrjßvlÝvjß{lÞ|tÞ€tà‚uÞ†xà‡yàŒà‘€á”€ß˜†ä—†â˜†ä¢Žä¬’㬘属洢湪辯꾮ì´íÄ¸íÆºîÈ»ðʺïÊ¿ð;óÌÀñÏÂôÐÁöÒ»ñÒ¸¸rwˆ/G’;HŒ8H’>N‹2IŒ5J†3I†2H†6J„/E‰1D†5D†2E‡4D‰:HŠ>K‹COETIX–P]\f«fjºrlÆ~pЊpÓŠlÎ|bÍ‚hч]Ð`Í|_Ûjðº†øÐ›üÖ¤üÔ˜úÈ…í°và…XÐdN¸JK£<G–1D*A‹,B’4FžANŸ>M›9H.C‡,E”:N¡IY¤J] K]˜BT–AX•FV“@T’?S–GVšLbšRg–I`“H^ŠAW}0Lt*Cg=l:O:J7G 6F1L 9g"Ošl|´’À ¢Æ§ È§¢½œ—ªˆ…œblu">€&@¨>HÏ]WÜvdãˆpæ’tè—zêšvêœ{ìŸzêš|í¢|ð¡{íš{ëŒpè‚cÙk^¨?P¦b}‹:`ŠBcx3ZK <Q>bFX;RAV@R?RB\Km.Vi'OTFUGo0U\KRGXHi(Ri(On,Sc!Lh(ObFP=U@[D\D`K\JZCZHF ARHxF{v:vˆ[‹ašššŸ©Š_–] Rn5h…K€”^‡•[ƒj%Do#>U?X<X=f?h#CcBV6X;`;X:X9X9Y8W8Z=`8o;w <3Eš4DµDJÃRUÆVUÈWVÈRWÈYXÈTTÂPMŽ*@Y:e=”;LªO\Í^ZÛbZÚd`Úd]Úb`ÚdbÞegÝegÝjfÝlfàjdàieápiàjdÞhhÞjhßniànhàjbÞjaáhdßf`Ýg\ÜhaÚdZÛaXÛfaÚd\ÝkdÜmcÜkcÞrhÞmdßqgÝwkÞwlßynßzmÞ|nßt݆zÞ†wß‹zàŽyâ’à”á”â—„ã Šã¨ãª–实岤温軫꾯êÁ²ìÅ·ìĸîȺðɸïÊ»ð˼ñË¿òÌ¿õÑÀõмôԴЖ”†,FŽ9J–>M–BN˜DS“>N’6I6HŒ:L…0F„*A€,Av&By(Ax+Dz)Ay,Cv.Fx.Fz.FŠAP”NV©``¼l^Ær^Î|fÔŒgÝœpÝ–f؃^Õ„câ¢uôÃŽúÒýÖüЕöÀxèšdØuWÀSJ¦:B.B‚;};Œ'?–2Fš8F•2G3FŒ.H3IžFV¤N\¢JX“<P•>T”BV–EW’>T“>T˜DWLb˜Nd‘D[‘F[‡?V~2Hm!>k=k@W9R7P
+4R5R :f"K—hv²’™ÂžŸÇª¤Èª¤¾˜±‡žjtv&?|$>¦<HÎ_UÜwlä‰pæ’wé—vëyë›yêž{êœ{ì¢}ð¡íš|ì’oæ„jÌ[WŒ1N¥bxŒ>`„:[t-WN?\G\AS=V>S=R@YGv6`b!G` LTCTFr4]\LSH[Ln+Tf"Km-Tf'Qf'QaG[ET=d LVA^"K^!HVDN@OFXMQFzJ†€L†’gš‘q¨•ošŸ‚¨‹SŒg‰IxƒBpSu€Ft`FO<V;Z?e=h@\9S8\=]9T7U 6X6V5Z8X:d9r @‚'=š;D©=G»GJÄRQÇPLÉTPÇSRÆUSÆUN¦5<a6Z:,F¢CRÂV[ØbXÛb\Ûg]Üg`Ýb^ÚfdÜhdÜijÞigßjeßieàhfàkeàjbàljáofâneÞniÞjdàk_âf^áicÞjbÝgcÜf^ÝdZÛhbÚibÞj`Ük`ÜhbÜqlÝrlÞphÝslÞxpßwlÞyjà{oà~sÞvÞ„vÞ†zߌ|â~à“„à“…âœ‡âŸŽã¤Žä«—ä®˜ä¯æ¶£è¾«ê¼­é¿°ìŵìôìÇ»îÆ¹îÊ»ïÌ¿òʾñÌÁôÐÁõÏÂõԹ⺭“6M9JšBM˜GTœFSšDN™BQ˜BO–:J8J8J….D-Ew%An Am=h;d6`7c8j <w,B?JŸOR´VTÒ„nä®|çµ|áªp׉dÚŽdê­zøÆúÒ˜ýÔ–úˈð¸qãŽ`ÊaP«?E”/D}"@v>| <‘2J”6I’2F‹,D0H’:OšDS¤Qc¤P_›FY“AT’=S’=S’?V’@T“@TšHZ›Lb—Ob”I^DW„7Rs$?n ?i:h;`<^;b;hAhCp(Lšft²’–¿¡¢È«ªÉ¬¤Ä£·˜”Ÿkpy+E}'A¦@KÎ`[Ûwhãˆsæ’xè™xèzéxèœzéžxì¥}ï£zïš~î’pæ„fÀWY’9T¨i~…6Xp&LeKL>\ IT@R=XBS@[Hf$Lh&KXEb$OYDUDe*P[IQD_$Lo0Tc"Je%Mb#Kc"L\De$Jb"HXBP>R@^$Ib"KVG[HUENBUNxG|ˆV™}¢›„¹‰[šv‘\‰…Fz}Axp0^ŠSxt5bT;R:^<e?]8Z<X@aFXFU<]:T7T 6Z8Z6h9{&@‹-BŸ;I´DHÁKOÇPRÆPQÈUSÉTRÈVO¶AFt6V :k?–;N¶RXÓ^YÖ`YÙd_Ûg_ÚgaÝd`ÛfbÛhfÞhhÝkcÞhbÞhdßfbßjiÞjeßnlàkhàqkáicànhànfàj_ßk`ßi]ÝgcÜgbÞg^Ûd]Ûh`Ýj]Üh\Üg]ÜkdÜngÞocÜukÜ{nÞyoÞ{n߀pà€rÞ€rà„rÞ‡yÞˆ|à|á}à”⚃â ãŸŠâ¦‘⪓䭚峤繧軦꾮ìÁ²ëöìÄ¸íÆºîȸï̾ð˾ðÌÀòÏÃõоõзîͲª]h6H–DQ›IS¡NY¢LTžKTGSšAM•?O•<L‹4G‡,D(Cu'Bo@d<^<X9X:U7]<k ?:Q»ldá¦}î½„íº€æ®rÝ”cÝ’jïµ€øÉüЕüÐøÆ‚ìªfØzS²KH•/@†(@s<} B…(A0D’5HŠ2F†*DŽ6L›AQžHZ¤Sb P^™FV“>P“>R8PŒ=R’>T•BXœJZœPh•LbH[ˆ<Ry2Il"=p <h8g:i8~,C.B~,Dy(F|4Q˜]p³ŠŒÄ¤¡È¬§Ë°ªÈ«¢º›’žin~4I(D¨BLÍ\SÜviã„qæ“xê˜xéŸvêžvæšvèž|î£vð¢zîœzípã„h´MZ™@W¶t„=^j$KbJR>dHR?TEYDf$OdFWAYCWCc#LW>SEZHh&TTBh(Ti+Qc%Mc"Nc Ic"Lb"NZD]ER=SAN <R<l-P_EXAe&QVEXCRJp<oŽ`”£Ž±˜³‘qž“lœu8p†Nˆ˜`ˆ¡n‹~:fP<T;e>a<S7W7Y4X7U7U8T6P6X8Y9d=}$@‡*@•3Dª@J¼HKÈNNÆONÊSRËPNËXT¼LL:W;]<ˆ0H®JRÎ\ZÖ_VÖ`^Ûf_Ûf_ÛgbÝe`ÛhcÛeeÝfaÜhdÞifÝhcÝgeÞllßleàrlßlhâpjànháldàjaáifàj^àjdÝgaÜe]ßh_Üd]ÜhaÛngÛg`ÝjbÜjbÚnhÞjcÞpeÛujÝthÜxlß|nà|pÞvàƒqÞ‚x߆vÞŠzß|ᓀ㜄䞌⟊⨔⫖å®ä´¤æ¹¤ç¹«è¼ªêÁ°ëÃµìÆ·íÇºìÆºïʺð̽ð̽òÎÀôξôкòбĈ‰Ž9J”BQšKT R\¢NV£OU¢MVžKU˜GW–@P>P8J‡2F~1Ht <h@`<Z?R:L 5N:Y?<RÕŒp컇ôĆïÄ‚æ¤dÛ„[à™pô¾†úÍ’ýÒ’ý̈ô¼zã•^À[M˜5C€!?u@vA…&BŒ/F5FŽ2H‚&D„(G”:QžH\¦Rb¢N^—FY‘=SŒ8R‹8QŠ<Tˆ5LAW˜H]ŸSfžSh—MbDY…8Pu(Es'Bj<f=n;Š6IŽ>NŽ:Lˆ6N†9RˆB]—^r­„ˆÂŸœË®¤Ï²¤ÊªŸº™•¤rv…@R-C¨@IÌ\PÚteã‡ræ”uìœzèxéŸwêš|èž|ì¦yï§~í™vê”pß|b¹L]¡D[·p‚’Ffj"LZBWB]DVF^Jq2Zh%IY@VBT?XDa!I[IUHYFd$N^Il,V^ Kb'Mj(Sd&Pf(Nd LVBUESBS?YBR=T:f"P[Bv6`c JVBPDMFq9f”nž“q ›²˜|±†Rˆ‹Xˆ„>q—Rh›_ŠR?W?c?W:X<V:V7S8V7U9S;V>\8^:p<Œ0DŽ.Dž<I¶FJÄQRÆTSÇPRÆWXÈVN¿OO(;a7W9u>¤@NÉVUÔ`^Ö]S×e`Üe_Úc[Úc^Ýf_ÚmhÝgeÜjhÞhcÞjgàhaßjdàjfáicâohálfàplàngàojàldápfÞmdßh]Ýg_ÝiaÞi`ÜhbÜh`ÝicÜi^ÝjbÝj`Ýi^ÚkdÜpfÜrhÞtjÞrfßxjà€nÝs߃vÝ€xÞƒyàˆzàŒ|á‘~â—ƒã˜äš‰ä¤‘㤎䫘峢赦繩缮辭ëÀ´ëõìźíɽîǹîɼðË¿ñÎÀóÌ¿ôÏ¿õÓ¶Ú®¤”=M’>O˜JTŸJS¤P]¥PX¥RX¡PXLVœFS”FV>PŒ=P8O~.Fq"Ai D^8X<N=I :Q;š<Là›nóÀ‰÷ȃóÂzÞ—[܆^çªxô†üËŒü΋ùÄ€é¨nÎoP’0>€!:q>p>z#@…*DŒ/FŠ0D„,Hƒ+IŽ6O™DV¦N_¦Vf˜JZŒ:Q‰6N‡9R‰8OŠ8OŠ8M’>U›NbŸXmžVk•J`ˆ@W‚8Q|2Jx,Gp%Dj>l!A’BR‘DV‘?PŽ?QE\‘I`dw¬„Œ¾ž›Ê¬¤Ì°¨È¬žºŸª|yŽIW„4I¥COÌ\VÚvdâ†rå’uêšxèŸ|êž{ëœwéŸyð¦|ò§}ìžuê“rÜzf¸U_ Lb®ezCct,TQ>SAXBd#J`Ca DYBW@XBZA[DXB\DWE[G]H`%Li)OZFh+Um,Xi*Te&Lf$MR@UDR@P>ZG^GL>b"Gn+Uh*Rd K\KVHXLf,^p:eŒa“ ~¤«—³—t¦|D~€G{’j•Ž_X?^@[<V8V7V9U<T9U5R5Q 1Y6^6h6(>.A“.@¨>G¾LMÅRPÅTSÉRPÈWQÂOK%;[ 7Z=v%D9JÂPQÐ]VÖ^UØ^ZÙg_Úd[ÙdbÜd`ÞhaÝlaÝleÞidÜg`ÞhaßkháhcàieÝhgàpjàleÞlhßmgànhàmfàngÞj`àh_àjaÞnfÝh^Ýf^Þe\ÜiaÜi\ÜmbÜjaÚg_ÜkcÛpkÛpjßugÜsiÞxlÞ|pÝ~oÞ‚t߀tà‚zÞˆzàŠxâ“€à•ƒâ“‚â™…äžŠã¥Žå®šæ°žæ´¤çºªçºªç¾°ê³êÄ¶ìÆµëÅ·ìÈ»îȽï˾ñ̾òÌ¿óϾöѶèDZ£LX8N•CRœOW¢T\¢PX§RW¤PV MUFR™GV=NAR‰9Pƒ2J|1Kq&Ah"@]<T;O<X?<JÞ’iðº|øÄ~ð¾xâ›fã˜jì²zõÁƒùÆ…öÀ~í­qÑzV¢:Cv9t<l>y#B‚&@‹0F„&?'?‚)BŒ3MœCT¡Na¥Sa›L\>Tˆ:N†6N„1Jˆ5NŠ8N@V—G^ Ui¡]pœNd‘K_Œ@Vƒ6Q€5Pz)Fn#?k!@s'DŒ:PBP?PCX”K`—Vj¡n~®ŠŒ½Ÿ¡Åª¦É°«Ê®¢Â¢•ª‚€’Ta†0D«DNÊXQÛtcã†qç”xëœyêž|ì¡zëžzêž|ï¥~ð§ví pè—nÚzc¦L^¦Nh¬`s†@`u*SXB[GX=XCX?ZB[DX?VAX?]Ja%L` HXFWEV@XAZDYGi-Tm.X^!JZIf&Od)STBVBRDVBh&Na#NP=e$Lj,Ud&P\Mb"Rm/^b$Np0\j.\m8]ŠZ‚—xš’f˜Šaf3O[A\@_AYAT<Y@T;V<V8O 4N 5X7`@d8t =†+@”4Gž4C¸HJÁMOÉ[WÆTTÈQP½KEŠ#7T 3T
+4p >š9I¼JPÏ\WÒ\YÖ]ZØ_[×b\Úf]ÚfeÝb[ßhbÜhhÚjfÞhfÝjaÞheÝlgàjcàheÞhfßngßnfàlißkfàlcàohàpiàh]àkaàmfÞhbÞg^ÞedÛd]ÝjdÜiaÝmdÜndÙkdÜibÜmcÛsfßrgÞrgßziÜ|pÝ{nÞ|qß‚tÞ†yÞŠ|ÞŠzà~à‹xß’€ã˜…✌â¨ä§•䫚沢洣湧迭龴ê¶ìÄ¹ìÆ»íǺðÇ»ð˾ò̾òǶó˼öϼðβºtxŠ3D“BP›JTŸR\¤SY¨RW¥SZ¢OUŸKU˜DS–GU”CR8L‹9M…5Jx,Bt'Bf>`:^@jE˜:LÖ‚bí²zõÀ„ó¿î¶yí±xð¶uö¼~ò¸zê¥iÔ{Tž@Cx;j<g<o<|$B‚*Aˆ,D$Aƒ(CŠ1J”<P KY¤Pb›JW’AX†4N€0J‚2L…2K†2KŒ8R”FZMd XmžXr”OgG^‡;T…:T‚8Os*Go"Bk$Ar)Fˆ;RŽ@V“DW—K^—Sgž_p¦v„®‹Ž¼¢£Ã¬¦É¯§Ê¬£Ä£–­„ƒ–Zd‡3F¨CLËZOÙrbá‰zç’téšyêzêŸzìŸvë¢|î§yñ¤zïxì–mÚn—7O®\qªYl„@`d FR>_GT?YDYDX@ZD[@ZCX@ZCb%JbIWGZGYEUCTDc%Pd%Le'QVJVHp4\|>fVBZHVFL@g&Q|@j`LTDf%Js5f\LXLs>gu;raQw@svAp€Oq<l’fŽž„©v@gZ?\<[>U>T>\@T;V8U=N=R 7[:`5n9†,@ˆ,@—3B®BJ¶FOÅQPÈWRÇOK¶DHv9S
+7W<v#@Ÿ6F·FLÊVVÒYTÒZZÕ^XØa\×^YÚf_Úf_Ýd[ßjhÝgdÞlbßh`ÜhaÛebÜmfÞgfßhbÞgdßlgàqhàohàkdÞkfÞolàpkßmfálcàlgßneßiaàg_ÛfbÜlfÛibÜngÜjbÛohÝj`ÜleÝrfÝrjÜrjÜtfÞvjÞxpß|nßrÞ‚wá‰xàŠ~àà‰{àŽã—ƒäŠâ ˆâ£ä¨–䱠峥浦绫農ê²ëÄ·ìÄ·íɹîʾîʾð̾ðȹò̾õιóдա–’7G<H”BPœKT¢QV§V[¤TXŸPWŸNX™EM™HT–ET?RŽ?R†7J~1H}2Kv,Et"?v$C{'C“6LÐweê²€ôˆôÊõ†òº{î®jê¤jä’_ÎsY¤JM‚)Dl<g>k>u"A€)B*A"?~$B‰3K—?QJY¢L]žL`“BXŒ>R‚6L2L…/H„6L‰6O’@Y˜Lb Uj \qšPg’E`ŒH\†=U€4Nx.Jm$Cp"Dt0Lu.Kx-JŠ>P–L\œXhœ\m dv§t€¯†‹À¡¡Æ¨¤Ç«¥Å§ž¾ ˜­„€—\dˆ6G¢FPÉZWØsgà‡tår蚀êxéžzêŸzí¤~î§ð¦víœzë”sß‚i–6R°bv¥Un†;_ZBQB`HRAXGW@\FXAaJbJVB]Df$J_FS@VDTFUF`'Su5bj/Zj1]TD^!Ox>d|Ad[FSAZHKAf(Y~Ei|>g^L]LzBmZH`&\a0X}Jyf'`v>o—l˜”ld&Pp1]p@X‚Jud?Z@U?T>W;\<X:R9P7O 4V8b@c<z)HŒ0F4I¯CH·FK¶GIÀOJ´FFŠ&7]6N7`6‰-B¨>HµHNÅONÍXUÐZXÔ^Z×^XÙ`\Ùa[Ûe`Úh^Ûd^áj`Üj`ÞibÝh_ÝjcßjcÞhbÞieÞjdÞkgßldâniâkbâjbÞlgÞngáohßoeàlbàldàkdàmdÞhaÛjjÞk_ÚifÝndÚh^Üh`ÜfZÚl`ÜpfÝphÜreÜujÞwjÝvhÝ~qÞrÞ~uÞˆzàŠxà‹|à}à’‚â”‚á’„àœ†âžã¦–㭚䱣䲧座漮迲ëÂ´ëÆ¸íÆºïÇ»îʼï̼ïÊ»ðËÀõμôж侬žCRŠ:K“CRšJUžKQ£PX£PT¡PX¢LVšHV•FQ—MX”DT”FSŠ;P„8O…8J2J‚3J†6IŠ3N£GUÏ|lè´‚öÇ”øÌ–÷È’ò¸zæ iÙ|TÂbQ¢BJ‚*Du"@n;n@v&E‚.F„,B)B|"B†/F‘8OšFX Qb¢O_˜MZŽ?U„2M2M€.J…2L†4MŒ>VšNbŸTh£[nœRh–MeŽBZŒHZ‡=R~4Mt*Hr&Et,Gq*Jm Ak">„?W’J[Znœ^oœ^oœj{«„¼ ¿¥¥Å©¨Ä§ ½Ÿ”¬„€˜^iŒ<L£GPÇXRØrdà…oå–xèšyèšzêž|ëŸ{ì zî¦zî§{îyì“o߃hž:T£Wl YpˆBfR>N?YCTB`"N]Cd&NT?f&N_IWC^Db%Hg'NWEQ=SCTFb'P}8duAnk6`SJe&UvAf~Djr4\N@R@VG] I|Cnk,Sj,V_#Te+MwAu[ Jj+\`!Rw:nl0i‰T~¥‡©€Mzv4jTAwAhn'OU>Q;S<Y=\?S8P 4Q:M 3U 4^3n:ˆ1A–1?£=E²AH¯BGœ6@„6b6R:Z:x$B 9GµBL»JPÆQQÉSUÎ\WÓXRÔ]VØ`ZØaXØc^ÜdZÙfaÙf]Üg`ÚicÝf\ÞhdÞljànaÝleÞießifàjfâldàngßnfánbßtlàngàrjßpkàmhámfßofàofÝndÜlhÝliÜj`ßmcÞj`Üi_Ýk_Üi^ÜmeÞndÜqgÞwiÝuiÜvmÞylÞ|tÞoà‡{Þ‡zߊzá‹~â’â‘â’‡à›ŒâŠâ¢—㪘㮠Ⲣ涧湬農êÀ³ê¶ìŶîȾîʾïËÀî˽ï;óÏÀôϸêʯ¬^i‰7F’AO–HQšMYžMUNVŸNS¡T[›JU™IQ™JV’GZ–HV>P‹<Qˆ;TŒAR@P”=P–8K­KTÓ€pé°„÷È•ùÌ‘õÂ…è¤pÑyS±PK‘4D(@|">r<t@{&B|*C‚.E€&B'A‡,H’=RœGZ Q`ŸNa˜J]EW‡5L|-Iy*H~,G„5PŠ<Q“BZœPb¢Zl£ZkœNf–QdŽG]ŽFZ€6Ly1Jl @t%Fz0Kv1Ml$Bb<€4LŒG]—Vf–Vi‘Si”^t¢y…µ–š¿¤¡Äª¤Åª ¼ š¬‚˜Zf>L¦GRÅVP×rdá„mã“wèšzëž|êŸ|í }ì¡€ï¤ï£|ëžxî’kàˆn >X˜If˜Tny2TN@N>XCTD]"KX@b!JZBk'O`FT@XG]Fq2\b&OSAXFVDl.Yv0^yLuv7cTHb$Tu@j‚Lt~Aj`LRA]JV@€Fli)TQ>WJ]%Oh‘b%Vd&Y^Rq:it9u|Ax¡¡ŽaŽq5d\Ih.Vj.YR<N8WA[<T9R9R8Z=U:\5j4)?Ž1<”1?‰,=|<h6V@W9`:$@œ0A­@IµBG½KNÆSTËWXÎTTÐYYÒ\VÐecÖ`\Ö_\Öa\Ûh]Ùe^Ûd\Üg_Ûh`Üb^Þf`àleßkbÞheÝidàgcÞpiámdâlbàngápcàqdßtjàtfßrjáqißrjàphándÞmbßleÜljÛjdÞjbÞiaÜj^ÝlbÝi`Ýj]ÝpfÝpdÝugÝvhÛxlÞxlÝ~qÜ€uÞtÞ…x߈|áˆ|á’┃◈⚈⛌â£ã¦–䫚㲤䵧幭缰辯êĹëŸíÇ»ìË¿îËÂðʽïË¿òÎÂñνïί‡„†3E:G“HR•JT›LWšLTœPVŸNU™NW™HTšOZ”K]—MX“ETŽCVEV•FX˜HV™CQ—>Q«HUÒxf樄ñ¿Œð¿ˆèª{Ö^¨HJŽ4Gˆ4K~.F|(Fw!A€,Dƒ.E‡2H„.D‚*D….H”:QžK^¤Tc¤WjšN\‘CU†:L€2Hx(Fu(Gz&B‡4M‘BW—F\¢Vh YlŸVgšQg“MaŽH]„>Vy.Gl"Bq&Bz,Hx-Ht,Gh!BZ6o'C~9PˆDZ‰F[ŠKe“\t u„°“–À¤¢Ç«¦Èª¡¿¢™°ˆ„Ÿdn>I¢ENÅXQØp`ß‚nã’wêœvìœì |î£|í£xï¦zî§vëì”lä‰m±P`Œ7XD`n(OQ@TAU>YE] I[H_GT>m+Vf"JZBZHX@v<gTBVCYFVDj*Sn)TvLoq3\KAd&Vz:hŒZŽ„Lu€@n[JWFQGh,Q„KtK>THc&ZsHa`•b#QY Td(_uBx‰W––dŽ«—´‘_Œ\E^Fd+SS;P8U9Y>T=ZAX8[8^8f3i8i8e8^>S7W9[>j!D‚,Fœ;OªBPµDN¼HLÀNSÉTUÍUTÎ]^ÎXTÐXXÒZVÒ^ZÖ_YÖa\Ö^ZÚcaÚgaÙfeÜhaÛebÜjfàg^ÞjaÞjcÜfbÛfdÝkhßmfßlhÞldÞngàpdÞpjÞtràphásfàtlàsmÞnhßlhÝnfÝphßodÚjeÜhbÝldÞpfÞnbÜnfÛlbÞodÛphÜrgÞtfÜxlÝynÝzrÞ~sàuÞ„w߇{á†}á€â“ƒá–†âžŠâ‰â¡“⤔䬘䮜䳦䵥漯龰éÀ´ëÄ·ìȾìļîËÀíÊÀî̾ñÎÀò̹òήܮ¢9GŒ;HŽ@O’FO•JU˜LVšOXŸSZžR\›LW™R\›PZ–MZ’FZ“JY™M^ P\¤P`¤NX¢GU¨GTÈc\ÛuâpÞšnÌyZ§JJŒ8N‰8Nˆ:K†0Iƒ,D†0Fˆ/DŒ2Jˆ/F„*E…/J‘8P™FZŸRa¢[jMY“AQ‰9L‚2J~5Pz(Ct'F|-FŽ;O™M`Qf¥^m Zož\n˜Pg•NcŒFZ€7Mr(Dp&Fr,Fw*Ft(Fj!CgAW:f >p*H€<T‡D[‰HdVpžo°•¼¤ŸÄ¨£Æ¨ Á ˜±Š‡ kr–FS¦FRÄVRÙnaß‚mäŽvê™xìœzí ~ð¤zî¢~ñ¦ð¨~ïŸzî•sæŠn¼\fv'K}6\]BUDSBR>U>X?YE\J^Jk'Pg K\I\H\F|GsVEVDZHWId!Nd#PzNxk*XMG`$S‚E€Œ_ŠY†ŒT€j'TV"QTL^LŠUz`(VLHSEb$W‹a‚t7fn2f_!Ut>pb”^™šr‘¤z ‚Ft`L`&NR<P:V9S:T8\>]?\8^5[2U 5T6^<d:t(B†(@“/Bž6C¬9D¯<JºGNÂPTÊTVÎVZÎ^[ÐZWÑ\\Ñ_^Ò`_Ò]YÓ^ZÔ\V×`XÔb]Ød[ÖdbØ`ZÚjcÙgbÜf\àj`Þh`Þf]ÞfaÝjbÞiaÞifÞjeàidßlcàsißmgánfàqjßrlárißsoßojßnfÞnbàneÞmbÝodÜhbÜjcÝj_àp`ÞnbÜm`ÞndÛogÝrgÜtkÝvjÝzqß{nÜsà„wÞ†|߆~àˆxáŒ€â‘€à”…âž†â Žá¡‘â§—äªšâ¬œã²¢ä´¦æº¨è¼¬èÀ²éôíŶíɾí˾îÊ¿íÌÀðÎÀñξñз嬜HX†7HŠ<LŽ@N’IV•KX–MRRXŸR^žS\ V^›Q\˜K\–P]˜R^ Ra¨W]¬V\ªRZªLU®LV¼VWËl`Êp^ÀeZ¨JS’:LŠ4K‡2F‹.E4H’4G”:K‘4FŽ1B,Dƒ,G‰8N•DYL^žQbžT`“ET‰<J€,C{(Bx(Ft!@v(F†4PšK] RežYj¤]n¤^pžZn•MeNd†?X|0Hr)Dr(Cn"@r#@q$BhB_;Y@e>j @u1L€;T‚A\ˆJg›gx¬Š¸œÃ¦ Â¦Ÿ½ š³‰„¢lqšRW£KTÁXS×kZá€læ’xê™zê€í ~î¡|î¡€ñ¢ñ§ì€ëtç‰rÆddr!Ev5ZT@XFRCV@\)M\ATAZDb"Lh*Tb!L` Pd"O`K}Mub LVBYFZKd*Wn,Y~Nvc MOCZL|@v‡Tƒ_ŠZ†j0]PGKBt<rƒHiŠ[…L@G <j+`k.Z‹X„g*Xn.nd(X“i™Ž_‡yDt}KqZ‚zAm\EOBSDWJV IYHW:S3U4X4a3m:v"=…$9‘);›4@§4@«;E®;G»HQÀLRÆTTÊWXÏWSÎTUÑVUÐWVÓZYÒ^WÓ\UÓ^ZÒ\\Ö^VÔ_XÖ[T×c]Øe^Ø`ZÜc[ÚfcÝh^Üe_Üf`Þe]ÜgbßlgßkdàlfájeálcàmfàmfÝqlßrlàtpàtjátlÞnjßnhÞtmÞndÝsißnbÞrfÜldÞkbÜpfàlaÝodÞl`ÞncÚqhÜngÝshÝyhÞ{nÞxlÝ|qßuàƒu߃wà„xà‚â‹~áà˜ˆãŽâ¢ã§’䫘䮛ä°ä³£å¶¨åº«è¿²é¿²ì¶ìÄ·î˽î̾íÊ¿î̽ðÌÀòθì̯´muƒ4E†9JŠBPŒDR“KY•KQšNZ¡U^¡TZ W_œXfšP_šRažTa¥[f«^a¯ZZ²VW±SX´RX²OT´TV²TZ¦NW›CR’:O’=O“<N”:LšBRš<K—:I–6GŒ-A†*C‰.I“<R™H\œPb˜R_DVˆ=Qƒ0F.D},Cu$Bs#D|0K’ATŸQ` Vl Vh£`r¡^qœXo•UiŽIc„9T{0Is(Ep"Bm"An$Ck @c<aC^ Ad"Ae?m(Hz6T~=[‚Ab•by«†»Ÿ Æª¡Æ¬¥Ã¤š²‘‡¦stžW_¤LY¿WV×jZà€kåuê™zí}졀ñ¤€ñ¤~ì}é’tã‰p»[_t"Iu1W[H^HVFV>[F\FR=YAb Kk*Te%Qb%Qb"N_Mn:Zq5fTDQBVHc M{BdzCkXFPGSGv<h„Pˆ|Ht”j’zBrPCF Cb%WˆNx•jŒn-YC <MFr2ey@\ƒL}^$Nh,fS‚ŒX‡’c˜j4j†S|~Di]"KP?P<V"BT8P4R4W6`7k=t;…'@’/B›8H¢6E©CL¶HL¸FIÂMNÆPPÈTXÉVYÌVWÎWUÏXVÐZYÐZXÒZZÓ][Ôb\Ô`YÐ\WÖ^UÖYSÖ^ZØ^\Ød\Úd\ÚhaÜd^ÞfZÜc\Üb_ÝfbÛohÞofàj`ài`âldànfßibÞkhÜliÞqjßrlÞqjàpfÞrnÝnfàsjàpiÝqgßpdÞvjÞndßneÜocßl^ÞleÝldßrlÛohÝqdÞthÜviÝviÞvlßznàqÞƒsÞtÞ‡y߉~à€à‘ƒá’†á›‰àœŠá£â¥‘㪚㰜㰢䴤縩湮述ë·êÅ·îÊ»îʼìʼî˼ï̾ðκïÎ±É”Žƒ4K‚3H‡@OŒBS‘JT’KV˜OZžS]ŸV^ \bžWcœV`¡Xa§[f«^b°\]µVV²TX¶TW¼TW´NS¬LUªJR¢FSœAQ™>Qš@R¡HV£FR¦HTŸ>O–:M5I‹2G‹6J7P—BVœPe™J^H[ˆ8L„6N‚6Mƒ2H{*Fw,Fv&Fˆ;T˜J^¢Xl¢Zm¥bw£fxœYj–Tf‘Nb‡CZ|/Kv+Fo$Ck @l"Do"?gAb <bA\@f%Dh*Li%Cn,Mt3T{:Z’]t¯ˆ‘Á¦¤Ð´¬Ô¸®Î´¬Á¤–®} \e¥JSÀYX×l^â‚kæ’vìšyí ~ì î£~ð¨ò¦í¡|ç•tÐ|a”<PlIp.Ta.PY#MSAWDZ@ZDV@_"MaHh'R] J` Ne$Nb$T\ I}FxZGQARF]NyDjt4aQBQFQJv:k‹Y–g'X“j’’f’\MNERL„Hz•g‡„HmVF><XF‚Bpaˆh(\SJo8jˆV‰’a„T€p7cg+Ka"KM;R>U?T:W=]9h9l3t58•*: 5B©:F²BH¾OLÄNNÄOKÄPOÆNNÈTSÊXVÎYWÐZXÒ^\ÒZXÔ^\Ô][Õ^UÖ\VÕ\WÓ_W×]WÖ[YÖ`XÚgbÚb\Úd`ÞhhÜfZÞd^ÜdaÝf]Þf_Üjeßibàgbàh`àkeànfßjhÞnfßleßmhárißpjáskápiàpiàsjÞtlàpkßqlßwqÞrfÞpfßodÞreÞriÜncßphÛtlÝvkßvhÜxhÞvjÞ|rÝzpß}sÞ€rà‚uÞ…zߊ{âŒ⎀ᑄ╆♊á¢ã ’⣔⫝̸ᮛⰣ乨巪绮èÁ´ê¶íȸìÊ»ëÉ»ìǹî̽ð̸ñͱװ¡Œ3H€0D†=L‹CS’IT•MWšQZU]žY`Xb [d£]e§^hª_d¬]a¸`^»XV·TU¸VVºQT´NR¬IT¬KT¨HT¥FP¤DR¦GU¯NR°NX¯IR£BO—:LŽ2HŒ3J8O˜@TšF\•JZˆ7N„6L~2G}+B‚0C‚.C}2L|.H2K‘@TžN`¦\l£`l¨ap£`s˜Tf–TeŒFZ‚6Ox+El Bj @n>f>e:d:b8f6^=b BdBbAj(Jj)Nn-S”Yp´Ž“ж°ÜµßóÝÀ®Ö¹¦»•Ž£_f§T[ÀZXØn\á„lçríœ{îž|îŸ~ð¤‚ñ§ô§€ðŸâŒpªS^z,QdDh%N^C_JV@\ I[DUBVE_Hc%Pf%N\Jb Md$Mf(TXIoAao3cP@VH]K‹aŒ|@mTLUNTLzApŒ^“hY‚R}šwž}GxZ"PPEqGoŠVz„Oyr/^H?J>v0`zC_”h•VNPEr3e}Ju‘bl.dR>b$MP?T;ZAV@\>c8k8q0€!6”0?¥9A²?IºCG½NOÅMJÊPKÊRPÇNKÉQPÊSRÎWUÐ[VÐZUÑZYÓ\XÕ^XÖ_WÒZTÔa\×\SÖ^TÙaX×^XÖ^ZÚd\Ø`YÚf_Úc[Üe\ÜdZÜh`ÞfZÞg`Üi`Þiaßg]àf\ámdàj`àlcßlfÞmdàqkáphàpiàniàrqßrkàulÞqlÞskàqhßulßrhàrlßrdàncÞriÝpfÞwlÝrfÝthàvhàxgßxjßwkÝzpÞznÞpÞ…vÞ…zߌ{àŒ~㑀ᓃᖆàá ”â¤à¦âªšâ­žà® äµ¦æº¯ç½¯è¿±èÁ³ëÄ·ëÆºêɺëȽêǼì̼ñ͵âîšKZ|.G…;K‡BVŽDOšQYœR\žRYžXbVb [f¤`fªaf¬af´`^·YZºUU¹VU¸VV¸UX·QT´QV°JT«JR©DT¬FRµQV¼TV¸QU®HR£@Nš:N“6N˜=R•DV˜I`–I\ŒAZ†:L~,Dz*A|,D~.G~)>~6N4NŽ;NœPd¥\h§aq§s¤^nžZo–PeŒEY†?Uy1Hn)Gh$Ah @i>h"@f>f;f<v:Z>d"@bA_@h"Eg%Jo.W”av½•—Û¾¯áóâijß°޾¤Î©“­po§RZÁZVØjZà‚næpìšxìŸ{ïœ~ð¢€î¢€ð¤ð¤~ìž|â“y¼lpOlx'Pc KVCbFf&NZAZDQBYB`#PbHfKb"Ld"Nj(Qi-UZL\&IzGvL@TGb'T˜uz8bVEWOVH~EtŽbo'_w8hŸ}¢•j”b#LOBRFy@h‡T€_"J`#SI @j'Ou/^ˆXs€FxOBq0dn1cŠ[‰yJum6po4\T=P:V 7S6_6l6s2‚!7—0;¤7>°<@¹EG¾GGÀMHÃPNÊQJÊTLÈTNËRNÉSMÐWSÒXSÒ]UÐZVÒXPÓ^YÕZRÒXVÖ^XÕ^ZÕ`YÚcZØ`Y×^YÚ^XØaZÛaTÝd[ÜaXÝhaÜh`Þh`Þf]ÝdaÝh`ÞfZÞjgàhcáießkdàjaÞhgáogßqjàleápnárkàrsãtiàtkàpjàtfÞxoápjàvpßsjßreÞxqÞvlßtnÞtiÝtkÞznÞxjàylà|qß~kÞzpß}mà„và„táŠxâ|à‘‚à—…à“…á™‹à â¤“ᡎᩜ⬜ᮟ䴦漬溬龲èÀ´ëõêĶêÈ»ëÈ»ëʽìͺñ͹êʱ¯ox{.J„8H‰>JŒGUŒGPŒHT˜T]˜Tb›T`ŸZb¨bi­bf°ae´``¸ZYº[Y¼VQ¼TT¹UV¸RT·OU¸JP³LT²NV¸VYÁWXÀVV¶RY­LT¦AR@Q—=T™DZ˜F\—H^’K_„>Vƒ6J~.C}-F‚.I}0F}/H0I‹=SœM^£Wd«bn«du¨bpž\p˜VjŽJ`ŠBU4Lr)Fh#Cd>h">k%Cf:h;i<r >Œ2HY<`=`@`>d&GcHk*P˜bz̤œÛ½±ß³ãijàòݼ§Ó°’»ƒw¨PWÀ\\Õm`á€järìœvìœxìxï¡|îž{î£~ñ£|îŸ~é‘sÈnn³do‚3VcJYE\D`DXD_KPA_"Jb-Sf&PfMd Pi"Nn)Um+Tf"RTFzJpb PVLg-W˜r—s2^[JVJ\NˆQ|e•eR}4q„Uv ¦s4dPBSJh*WŠ\‚g,ac&Pe"TZA€:dn.T†NucTi)[p,`„T€G€†V„_‹ZDL 6N 2X 1c3u4ƒ#;’.<¥5=¬9?·DI¹HJÀGGÃNKÂJJÊPNÊTOÌSPÍVQËRPÐVOÑZUÔ`YÒ\UÐ\XÐ]VÔYRÑ[VÖ]V×a^Ø`XÚ_XÚb\Ø`[Ú^RØ_YÜ_VÜd\ÛaZÞd[Ýf^Ýf_Üb[Ûg_Þmfáj^Þhdàh`àkdàg^àlbàlhßplànjàniásnàoeàqiâulßriâtkàthàqkávjàwmÞthâujßxmßsjàslÞtfÞtgÞwlÞzlâyná~sà|sà{pßzoáƒzâ‡{á‹yâà‘€ß‘à’ᚆ⠊ឈ࢒䨖⭜à¯ä²¡ä¶¨äº­ç¾°çÀ´êĶêÄ·êȺìȺìʼìÊ»ñ˹îαʓ’}/J{4Lˆ>LHR’R[–MY—P\”NZ›Vc¡\b«^c¯ad²]`¶\^º][À[WÂXV¼UV¼UVºOQ¸OU½RS¼QS¿WYÈ[VÊ_XÂXWºOQ¬GR ?Pœ@U›DXœNb”F]ˆBZˆ@Y‚<Xˆ;Qƒ8Rƒ4J‚;P€-G†2H‹:P˜H\§Vh­cq¬hs¬fv¤cp›Uf•RiˆD]€;Rt*Fh @c;`6f9i<j)Fl<}+Fˆ0C™8IZ>[=b?`@d"EaEj'P˜\rΦœÚ¼¯ÜÀ°àñßÁ®Þ»¦Õ²˜Áˆ~¥R\¾ZXÖnbà‚kåŽuìœvìžwê xí¢|î {ï£|ñ¥€íšxß“xºYbžNbv-QbF^DWAX>ZAc JUH^H`#LdLk%Rh"Nr*Vz6\z5]r2\[Jd$Ms0`\OsDnŒ\‚q,XcJ[Nj"W„Fq`TB~?ut0dšz˜–d‘[KRIk/b_„‹X†XJe&Pf&Tr0T}<gf*Oh+XVGn/`~@k€I}s9q”fŠ^‰^!KT 4\ 4o3€7&9œ+;¨6>¯9B¸FHºDEÁGFÆPQÈPNÌOLÊWTÍUQÎUPÌWTÐXQÐXOÒ_WÒ]VÐZWÐ\XÔ^TÓ`[×`UØbXÖ]ZÙ`XÙb\ØbYÜ\TÛ^TÚh_Üd[ÝjdÝf`ÞeXÝc]Ý`XÜf`ÞjhÞjbÝgeÞmkÞkfßgdàicàngánjâpdârgâtjárgàsjàkiàrfásháqjßrhârfázpàwnâxiátgÞxlávhÞrfßuhÞxoÝzjà{lâ~lá}oà€rà~rà„wã…và‹}áŒ~à‹|ÝŠá’‚á–‡àžŽàšŠá£’ã©—ã¬á®ã²žæµ¨å¹§ç¼±è¾±êÁ´ëÂ·éÆ·ìÆ¸íʽíʺðʺïͲڲ¦‹:N4I„<KŠ?IBN”FO’NZ”O[šR\ž[b¨\`®^a´[\¸^^ÄaXÃa^Ã\VÀTRÀTS¿SPÁYWÇXTËUTÐ`WÐ`XÌ_XÃVS¸KR£GTž?Oš@V™DT–E\Š<X‚<V6Pƒ9OŠ<U„:P†:P†5K„2GŒ<Q˜H]£Xj¬bl¯mx¬kx«htž\m—Uh‹EZ€<Tt)Ei<f!A^8a>e>g=p&By(CŒ5HŸ?J¢<KU<\<^>^:c D^Fc&O‰OmË¢šÚ»²Þ¾²ÞÀ³Ý¿²Ú¸¦Ò®—À‡y§NXÀ\XØn_ß„nåtìšwëž{ì î |좀î£ñ¤}íŸvÞ‘w¤JWŠA^j"Gf$NdHR@P<_Bh%LP?g*V[Hh)Rn(Rg#Pp-Vs*Tx5Zx6b\JbMp0fj.^o’†HpbLg!T` QiR†Lub‹P@w8fv3fu<h“jŠ€FzXMf'U˜p—‹XzXDRCTDl(Q<^s0\f(SWIWFaL~Kym,b}?g—f…X|j$Ki<‚$<–->œ4B¢1?©7@®?F½GHÁHIÆMJÊQNÊSRÊPPÎTTÎXSÏXSÐWUÑ\SÓZRÐZXÑZXÐ^[Ò]TÖ]TÓ]TÕ^X×_TØ\UØ\XØaZ×`ZÛ^XÚ^VÛcXÜa\Üe[àe[Þi`Þf_à^WÞdZÝc[Þd\Þhhàh_àhdÞlfàjcÞnhàrgárfâpfßphßrjßrjÞkfàrlâsjàtoßsmârgáwlàxlàuhàtlàvhßyoßymàtgßxjÜ{pàwkßyoá€rá€tá€pá‚sâ…yáˆ|áŽ€àŽ„àŽá~ß“†á˜ŠàšŒàžŒâ¤•⪕⯟䱠崦帨帬翰꿰êÁ´éÄ¶íÆ¼íÈÀìÇ»ïʼðηæÄ®¥Vl„>Z‡?PˆDS‘HNŽ@JBM”JV™W`œW_¦Y`«X[´^_Âe_Ìg\É`VÆ[VÅ\WÆZTÆXTÄZWÎb[Ñh[ÖkXÑdYË]UÀTR±IR¡>NžBQ—>O’:P‡7Q{4Q4R‚6SŒBY>XŠ@Tˆ:Q†:P…4M”DUžK^©Zk²gp¯n|¬ktªguœ]kŽH^:Qv/Hg >a<_6`:`8c;j?u+F†4Jš@R¬FRªANR9^>`=\=` C[>`H†HfÄ™ŽÚ¼®Þ¾±Ü¾°Ü¾®Øº¦Ñ¬·zq¡S^Â`\Øl\á„mæŒnë–xì„ì¢zì¢|ð¤‚잀á–{¢JWFdh&Nj%LY>Q>P:d"Gi*PH8g(RV@r0Yr2[k"Mq*Vm&Nt-Xx4^f%ObS|@t|;h ˆ«r4Y`Fq.`VBd R‚Gm^ˆTHi(Tt4`p+d|Fk˜nœs2l\!N x|EhN=YFSJZDo*Xy:`e-Se"PTD_L}Lso.a`F‚Lzz7NR€z8’/D—1A›2>¨:D¨8@²@DºDF¾HKÃJJÆLNÈQRÏSRËWTÌVQÎXQÑZPÐXQÒZTÑbZÑa[ÐZWÒ]TÕ\TÔ\VÔ]WÖ\T×`\×b^Ùb\Öd]Û`TÛ^XÜ^Wß`YÞe^ÞibÞe_Üe]ß`XÞc\Ýd\ßb^ÞfdâhfàhdÞnháihàhbàojândârlÞnfÞpfÞnnâmcàrkárhàqhßrjàrhàvjàxiáypàwlßvhßxlÞxqáyißxlÞ{oÞztà{pà„rà„tà‚xâ€tà„tàˆ~ጂà†ßŒ„ß€à”ˆá”Šâ˜Œàœâ¦”᪘ᬘ峢䳤䷤䶨溰辰èÀ´ê´ìŹìÇÀîļðÊ»ð˵êÈ·Ân‚žR€’IhˆEZŽDRŽBPHT“HRšPWœRZœPY°bf½f^Çj]Ñh\Ïc\Ì`VÈ\XÎ]TÊ[TÈ`\Ðj^×l[ØkZÑfZÊXP¸RS¨BK˜<J˜<L6Lƒ/H1Lx2P|2P‰>ZŽ@]AXŽBZ†<V‡6QŒ<R—DV¤P_¬cn²fp®mvªjx¥dr–Vg†D[v+Fh#@f"D_<Z2_7`:k>v,N~8P–BV¨GT²DN·HQ \ No newline at end of file
diff --git a/contrib/ffmpeg/tests/libav.regression.ref b/contrib/ffmpeg/tests/libav.regression.ref
new file mode 100644
index 000000000..a498d6799
--- /dev/null
+++ b/contrib/ffmpeg/tests/libav.regression.ref
@@ -0,0 +1,113 @@
+ffmpeg regression test
+8a0536ccfe36f4fff408b3327d33e1dd *./data/b-libav.avi
+340344 ./data/b-libav.avi
+./data/b-libav.avi CRC=0x400c29e9
+786446e80ead936e5faa8f5908f19281 *./data/b-libav.asf
+339775 ./data/b-libav.asf
+./data/b-libav.asf CRC=0x74113749
+1ce78eeb6881ffe5b649a9b5105de919 *./data/b-libav.rm
+355405 ./data/b-libav.rm
+bdb7484c68db722f66ba1630cf79844c *./data/b-libav.mpg
+378880 ./data/b-libav.mpg
+./data/b-libav.mpg CRC=0x2b71a386
+322d59758fe9446147223a607d1699bc *./data/b-libav.ts
+471692 ./data/b-libav.ts
+./data/b-libav.ts CRC=0xcc4948e1
+d6fdeb9f7083cc827f9510c6c4517dc0 *./data/b-libav.swf
+335771 ./data/b-libav.swf
+./data/b-libav.swf CRC=0xe14e8847
+a1cd7fff97d5e4c83f0d18a22d51c552 *./data/b-libav.ffm
+380928 ./data/b-libav.ffm
+./data/b-libav.ffm CRC=0x01522b4a
+f8ad5bd78f4d012a8ce9570aa395ac54 *./data/b-libav.flv
+335833 ./data/b-libav.flv
+./data/b-libav.flv CRC=0xe14e8847
+16518706f425cb537362bfc1c58b8de5 *./data/b-libav.mov
+366923 ./data/b-libav.mov
+./data/b-libav.mov CRC=0x45079dca
+7820fa85ab86c62028d8dbda94589573 *./data/b-libav.dv
+3600000 ./data/b-libav.dv
+./data/b-libav.dv CRC=0xf517e829
+feb04ba3cf4f607d5527664eb69ec72e *./data/b-libav.gxf
+814640 ./data/b-libav.gxf
+./data/b-libav.gxf CRC=0xa376c09e
+9a9da315747599f7718cc9a9a09c21ff *./data/b-libav.pbm
+ 317075 ./data/b-libav.pbm
+./data/b-libav.pbm CRC=0xb92906cb
+6ea0e1faf08f6fcdb44db4a104361b57 *./data/b-libav.pgm
+2534775 ./data/b-libav.pgm
+./data/b-libav.pgm CRC=0xf4aa7c47
+0c5fe86621b7377705837f304d4ba1e9 *./data/b-libav.ppm
+7603575 ./data/b-libav.ppm
+./data/b-libav.ppm CRC=0xb2bb8e92
+88a98269295fbfce7816558ad84e1259 *./data/b-libav.gif
+2906382 ./data/b-libav.gif
+b977a4fedff90a79baf70c8e02986820 *./data/b-libav.y4m
+3801810 ./data/b-libav.y4m
+./data/b-libav%02d.pgm CRC=0x84c09106
+de216b43403f51e57e644fbf812568bf *./data/b-libav02.pgm
+./data/b-libav%02d.ppm CRC=0x25c06ecf
+86bbdb77afa289ff363120f8044f29df *./data/b-libav02.ppm
+./data/b-libav%02d.bmp CRC=0xf3a66ecf
+c3a9f333ddebff6eae3f4360bad2de29 *./data/b-libav02.bmp
+./data/b-libav%02d.tga CRC=0xf3a66ecf
+f558eef0740c4b247f1eb17e1dbf7adf *./data/b-libav02.tga
+./data/b-libav%02d.jpg CRC=0x62328baa
+5d6c53e5297c4485e26c25e37885376f *./data/b-libav02.jpg
+b0a8c8063d81921db5d7c8f50a1cc454 *./data/b-libav.wav
+ 89132 ./data/b-libav.wav
+./data/b-libav.wav CRC=0x2a09519c
+e2a6d6fae17394dfe87cb5bb8ae11837 *./data/b-libav.al
+ 44544 ./data/b-libav.al
+./data/b-libav.al CRC=0xefdf94c3
+4574d7e2c09e1e13663e61bd2889f12d *./data/b-libav.ul
+ 44544 ./data/b-libav.ul
+./data/b-libav.ul CRC=0x6064b2f8
+7a21ff174e3cca1702e0826c4ca0eccf *./data/b-libav.au
+ 89112 ./data/b-libav.au
+./data/b-libav.au CRC=0x2a09519c
+272b91d8fc31ed43b08246d182719751 *./data/b-libav.mmf
+ 22609 ./data/b-libav.mmf
+./data/b-libav.mmf CRC=0x03633476
+ae3a23a7ea13c92a2909445ca8144dcd *./data/b-libav.aif
+89142 ./data/b-libav.aif
+./data/b-libav.aif CRC=0x2a09519c
+8d117c49d6b210abe783d1b0b897cec7 *./data/b-libav.voc
+ 32768 ./data/b-libav.voc
+./data/b-libav.voc CRC=0x49972c8c
+ce356ce2708cb6033ab5d762da93cfd4 *./data/b-libav-yuv420p.yuv
+ 304128 ./data/b-libav-yuv420p.yuv
+ce356ce2708cb6033ab5d762da93cfd4 *./data/b-libav-yuv422p.yuv
+ 304128 ./data/b-libav-yuv422p.yuv
+ce356ce2708cb6033ab5d762da93cfd4 *./data/b-libav-yuv444p.yuv
+ 304128 ./data/b-libav-yuv444p.yuv
+ce356ce2708cb6033ab5d762da93cfd4 *./data/b-libav-yuyv422.yuv
+ 304128 ./data/b-libav-yuyv422.yuv
+545f61c353a8b4419808785cb4f0069d *./data/b-libav-yuv410p.yuv
+ 304128 ./data/b-libav-yuv410p.yuv
+d6c03f930018ff859bd43f52b92e9321 *./data/b-libav-yuv411p.yuv
+ 304128 ./data/b-libav-yuv411p.yuv
+14117c4d7956775a7bbceabfc38da808 *./data/b-libav-yuvj420p.yuv
+ 304128 ./data/b-libav-yuvj420p.yuv
+14117c4d7956775a7bbceabfc38da808 *./data/b-libav-yuvj422p.yuv
+ 304128 ./data/b-libav-yuvj422p.yuv
+14117c4d7956775a7bbceabfc38da808 *./data/b-libav-yuvj444p.yuv
+ 304128 ./data/b-libav-yuvj444p.yuv
+deb2f7ebe297df2c1fe264d19b34d2fb *./data/b-libav-rgb24.yuv
+ 304128 ./data/b-libav-rgb24.yuv
+deb2f7ebe297df2c1fe264d19b34d2fb *./data/b-libav-bgr24.yuv
+ 304128 ./data/b-libav-bgr24.yuv
+deb2f7ebe297df2c1fe264d19b34d2fb *./data/b-libav-rgb32.yuv
+ 304128 ./data/b-libav-rgb32.yuv
+5d395f62bff8ac475f743268c772ca3a *./data/b-libav-rgb565.yuv
+ 304128 ./data/b-libav-rgb565.yuv
+2ffd6871fcbfe9570454e8703ac8ea01 *./data/b-libav-rgb555.yuv
+ 304128 ./data/b-libav-rgb555.yuv
+0b62dcf9b57b294dbaa5d9e99b1ee192 *./data/b-libav-gray.yuv
+ 304128 ./data/b-libav-gray.yuv
+e197450dae2feba9e757b551e1e9145c *./data/b-libav-monow.yuv
+ 304128 ./data/b-libav-monow.yuv
+e197450dae2feba9e757b551e1e9145c *./data/b-libav-monob.yuv
+ 304128 ./data/b-libav-monob.yuv
+7a319375916cae4e691ecb74295e5d2a *./data/b-libav-pal8.yuv
+ 304128 ./data/b-libav-pal8.yuv
diff --git a/contrib/ffmpeg/tests/regression.sh b/contrib/ffmpeg/tests/regression.sh
new file mode 100755
index 000000000..c4c2f776b
--- /dev/null
+++ b/contrib/ffmpeg/tests/regression.sh
@@ -0,0 +1,722 @@
+#!/bin/sh
+#
+# automatic regression test for ffmpeg
+#
+#
+#set -x
+# Even in the 21st century some diffs do not support -u.
+diff -u "$0" "$0" > /dev/null 2>&1
+if [ $? -eq 0 ]; then
+ diff_cmd="diff -u"
+else
+ diff_cmd="diff"
+fi
+
+diff -w "$0" "$0" > /dev/null 2>&1
+if [ $? -eq 0 ]; then
+ diff_cmd="$diff_cmd -w"
+fi
+
+set -e
+
+datadir="./data"
+
+logfile="$datadir/ffmpeg.regression"
+outfile="$datadir/a-"
+
+# tests to run
+if [ "$1" = "mpeg4" ] ; then
+ do_mpeg4=y
+elif [ "$1" = "mpeg" ] ; then
+ do_mpeg=y
+ do_mpeg2=y
+elif [ "$1" = "ac3" ] ; then
+ do_ac3=y
+elif [ "$1" = "huffyuv" ] ; then
+ do_huffyuv=y
+elif [ "$1" = "mpeg2thread" ] ; then
+ do_mpeg2thread=y
+elif [ "$1" = "snow" ] ; then
+ do_snow=y
+elif [ "$1" = "snowll" ] ; then
+ do_snowll=y
+elif [ "$1" = "libavtest" ] ; then
+ do_libavtest=y
+ logfile="$datadir/libav.regression"
+ outfile="$datadir/b-"
+else
+ do_mpeg=y
+ do_mpeg2=y
+ do_mpeg2thread=y
+ do_msmpeg4v2=y
+ do_msmpeg4=y
+ do_wmv1=y
+ do_wmv2=y
+ do_h261=y
+ do_h263=y
+ do_h263p=y
+ do_mpeg4=y
+ do_mp4psp=y
+ do_huffyuv=y
+ do_mjpeg=y
+ do_ljpeg=y
+ do_jpegls=y
+ do_rv10=y
+ do_rv20=y
+ do_mp2=y
+ do_ac3=y
+ do_g726=y
+ do_adpcm_ima_wav=y
+ do_adpcm_ms=y
+ do_flac=y
+ do_wma=y
+ do_vorbis=y
+ do_rc=y
+ do_mpeg4adv=y
+ do_mpeg4thread=y
+ do_mpeg4nr=y
+ do_mpeg1b=y
+ do_asv1=y
+ do_asv2=y
+ do_flv=y
+ do_ffv1=y
+ do_error=y
+ do_svq1=y
+ do_snow=y
+ do_snowll=y
+ do_adpcm_yam=y
+ do_dv=y
+ do_dv50=y
+fi
+
+
+# various files
+ffmpeg="../ffmpeg_g"
+tiny_psnr="./tiny_psnr"
+reffile="$2"
+benchfile="$datadir/ffmpeg.bench"
+bench="$datadir/bench.tmp"
+bench2="$datadir/bench2.tmp"
+raw_src="$3/%02d.pgm"
+raw_dst="$datadir/out.yuv"
+raw_ref="$datadir/ref.yuv"
+pcm_src="asynth1.sw"
+pcm_dst="$datadir/out.wav"
+pcm_ref="$datadir/ref.wav"
+if [ X"`echo | md5sum 2> /dev/null`" != X ]; then
+ do_md5sum() { md5sum -b $1; }
+elif [ -x /sbin/md5 ]; then
+ do_md5sum() { /sbin/md5 -r $1 | sed 's# \**\./# *./#'; }
+else
+ do_md5sum() { echo No md5sum program found; }
+fi
+
+# create the data directory if it does not exist
+mkdir -p $datadir
+
+FFMPEG_OPTS="-y -flags +bitexact -dct fastint -idct simple"
+
+do_ffmpeg()
+{
+ f="$1"
+ shift
+ echo $ffmpeg $FFMPEG_OPTS $*
+ $ffmpeg $FFMPEG_OPTS -benchmark $* > $bench 2> /tmp/ffmpeg$$
+ egrep -v "^(Stream|Press|Input|Output|frame| Stream| Duration|video:)" /tmp/ffmpeg$$ || true
+ rm -f /tmp/ffmpeg$$
+ do_md5sum $f >> $logfile
+ if [ $f = $raw_dst ] ; then
+ $tiny_psnr $f $raw_ref >> $logfile
+ elif [ $f = $pcm_dst ] ; then
+ $tiny_psnr $f $pcm_ref 2 >> $logfile
+ else
+ wc -c $f >> $logfile
+ fi
+ expr "`cat $bench`" : '.*utime=\(.*s\)' > $bench2
+ echo `cat $bench2` $f >> $benchfile
+}
+
+do_ffmpeg_nomd5()
+{
+ f="$1"
+ shift
+ echo $ffmpeg $FFMPEG_OPTS $*
+ $ffmpeg $FFMPEG_OPTS -benchmark $* > $bench 2> /tmp/ffmpeg$$
+ egrep -v "^(Stream|Press|Input|Output|frame| Stream| Duration|video:)" /tmp/ffmpeg$$ || true
+ rm -f /tmp/ffmpeg$$
+ if [ $f = $raw_dst ] ; then
+ $tiny_psnr $f $raw_ref >> $logfile
+ elif [ $f = $pcm_dst ] ; then
+ $tiny_psnr $f $pcm_ref 2 >> $logfile
+ else
+ wc -c $f >> $logfile
+ fi
+ expr "`cat $bench`" : '.*utime=\(.*s\)' > $bench2
+ echo `cat $bench2` $f >> $benchfile
+}
+
+do_ffmpeg_crc()
+{
+ f="$1"
+ shift
+ echo $ffmpeg $FFMPEG_OPTS $* -f crc $datadir/ffmpeg.crc
+ $ffmpeg $FFMPEG_OPTS $* -f crc $datadir/ffmpeg.crc > /tmp/ffmpeg$$ 2>&1
+ egrep -v "^(Stream|Press|Input|Output|frame| Stream| Duration|video:|ffmpeg version| configuration| built)" /tmp/ffmpeg$$ || true
+ rm -f /tmp/ffmpeg$$
+ echo "$f `cat $datadir/ffmpeg.crc`" >> $logfile
+}
+
+do_ffmpeg_nocheck()
+{
+ f="$1"
+ shift
+ echo $ffmpeg $FFMPEG_OPTS $*
+ $ffmpeg $FFMPEG_OPTS -benchmark $* > $bench 2> /tmp/ffmpeg$$
+ egrep -v "^(Stream|Press|Input|Output|frame| Stream| Duration|video:)" /tmp/ffmpeg$$ || true
+ rm -f /tmp/ffmpeg$$
+ expr "`cat $bench`" : '.*utime=\(.*s\)' > $bench2
+ echo `cat $bench2` $f >> $benchfile
+}
+
+do_video_decoding()
+{
+ do_ffmpeg $raw_dst -y $1 -i $file -f rawvideo $2 $raw_dst
+}
+
+do_video_encoding()
+{
+ file=${outfile}$1
+ do_ffmpeg $file -y $2 -f $3 -i $raw_src $4 $file
+}
+
+do_audio_encoding()
+{
+ file=${outfile}$1
+ do_ffmpeg $file -y -ab 128k -ac 2 -f s16le -i $pcm_src $3 $file
+}
+
+do_audio_decoding()
+{
+ do_ffmpeg $pcm_dst -y -i $file -f wav $pcm_dst
+}
+
+do_libav()
+{
+ file=${outfile}libav.$1
+ do_ffmpeg $file -t 1 -y -qscale 10 -f pgmyuv -i $raw_src -f s16le -i $pcm_src $2 $file
+ do_ffmpeg_crc $file -i $file $3
+
+}
+
+do_streamed_images()
+{
+ file=${outfile}libav.$1
+ do_ffmpeg $file -t 1 -y -qscale 10 -f pgmyuv -i $raw_src -f image2pipe $file
+ do_ffmpeg_crc $file -f image2pipe -i $file
+}
+
+do_image_formats()
+{
+ file=${outfile}libav%02d.$1
+ $ffmpeg -t 0.5 -y -qscale 10 -f pgmyuv -i $raw_src $2 $3 $file
+ do_ffmpeg_crc $file $3 -i $file
+ do_md5sum ${outfile}libav02.$1 >> $logfile
+}
+
+do_audio_only()
+{
+ file=${outfile}libav.$1
+ do_ffmpeg $file -t 1 -y -qscale 10 -f s16le -i $pcm_src $file
+ do_ffmpeg_crc $file -i $file
+}
+
+echo "ffmpeg regression test" > $logfile
+echo "ffmpeg benchmarks" > $benchfile
+
+###################################
+# generate reference for quality check
+do_ffmpeg_nocheck $raw_ref -y -f pgmyuv -i $raw_src -an -f rawvideo $raw_ref
+do_ffmpeg_nocheck $pcm_ref -y -ab 128k -ac 2 -ar 44100 -f s16le -i $pcm_src -f wav $pcm_ref
+
+###################################
+if [ -n "$do_mpeg" ] ; then
+# mpeg1
+do_video_encoding mpeg1.mpg "-qscale 10" pgmyuv "-f mpeg1video"
+do_video_decoding
+fi
+
+###################################
+if [ -n "$do_mpeg2" ] ; then
+# mpeg2
+do_video_encoding mpeg2.mpg "-qscale 10" pgmyuv "-vcodec mpeg2video -f mpeg1video"
+do_video_decoding
+
+# mpeg2 encoding intra vlc qprd
+do_video_encoding mpeg2ivlc-qprd.mpg "-vb 500k -bf 2 -flags +trell+qprd+mv0 -flags2 +ivlc -cmp 2 -subcmp 2 -mbd rd" pgmyuv "-vcodec mpeg2video -f mpeg2video"
+
+# mpeg2 decoding
+do_video_decoding
+
+# mpeg2
+do_video_encoding mpeg2.mpg "-qscale 10" pgmyuv "-vcodec mpeg2video -idct int -dct int -f mpeg1video"
+do_video_decoding "-idct int"
+
+# mpeg2 encoding interlaced
+do_video_encoding mpeg2i.mpg "-qscale 10" pgmyuv "-vcodec mpeg2video -f mpeg1video -flags +ildct+ilme"
+
+# mpeg2 decoding
+do_video_decoding
+fi
+
+###################################
+if [ -n "$do_mpeg2thread" ] ; then
+# mpeg2 encoding interlaced
+do_video_encoding mpeg2thread.mpg "-qscale 10" pgmyuv "-vcodec mpeg2video -f mpeg1video -bf 2 -flags +ildct+ilme -threads 2"
+
+# mpeg2 decoding
+do_video_decoding
+
+# mpeg2 encoding interlaced using intra vlc
+do_video_encoding mpeg2threadivlc.mpg "-qscale 10" pgmyuv "-vcodec mpeg2video -f mpeg1video -bf 2 -flags +ildct+ilme -flags2 +ivlc -threads 2"
+
+# mpeg2 decoding
+do_video_decoding
+
+# mpeg2 encoding interlaced
+file=${outfile}mpeg2reuse.mpg
+do_ffmpeg $file -y -sameq -me_threshold 256 -mb_threshold 1024 -i ${outfile}mpeg2thread.mpg -vcodec mpeg2video -f mpeg1video -bf 2 -flags +ildct+ilme -threads 4 $file
+
+# mpeg2 decoding
+do_video_decoding
+fi
+
+###################################
+if [ -n "$do_msmpeg4v2" ] ; then
+# msmpeg4
+do_video_encoding msmpeg4v2.avi "-qscale 10" pgmyuv "-an -vcodec msmpeg4v2"
+do_video_decoding
+fi
+
+###################################
+if [ -n "$do_msmpeg4" ] ; then
+# msmpeg4
+do_video_encoding msmpeg4.avi "-qscale 10" pgmyuv "-an -vcodec msmpeg4"
+do_video_decoding
+fi
+
+###################################
+if [ -n "$do_wmv1" ] ; then
+# wmv1
+do_video_encoding wmv1.avi "-qscale 10" pgmyuv "-an -vcodec wmv1"
+do_video_decoding
+fi
+
+###################################
+if [ -n "$do_wmv2" ] ; then
+# wmv2
+do_video_encoding wmv2.avi "-qscale 10" pgmyuv "-an -vcodec wmv2"
+do_video_decoding
+fi
+
+###################################
+if [ -n "$do_h261" ] ; then
+# h261
+do_video_encoding h261.avi "-qscale 11" pgmyuv "-s 352x288 -an -vcodec h261"
+do_video_decoding
+fi
+
+###################################
+if [ -n "$do_h263" ] ; then
+# h263
+do_video_encoding h263.avi "-qscale 10" pgmyuv "-s 352x288 -an -vcodec h263"
+do_video_decoding
+fi
+
+###################################
+if [ -n "$do_h263p" ] ; then
+# h263p
+do_video_encoding h263p.avi "-qscale 2 -flags +umv+aiv+aic" pgmyuv "-s 352x288 -an -vcodec h263p -ps 300"
+do_video_decoding
+fi
+
+###################################
+if [ -n "$do_mpeg4" ] ; then
+# mpeg4
+do_video_encoding odivx.mp4 "-flags +mv4 -mbd bits -qscale 10" pgmyuv "-an -vcodec mpeg4"
+do_video_decoding
+fi
+
+###################################
+if [ -n "$do_huffyuv" ] ; then
+# huffyuv
+do_video_encoding huffyuv.avi "" pgmyuv "-an -vcodec huffyuv -pix_fmt yuv422p"
+do_video_decoding "" "-strict -2 -pix_fmt yuv420p"
+fi
+
+###################################
+if [ -n "$do_rc" ] ; then
+# mpeg4 rate control
+do_video_encoding mpeg4-rc.avi "-b 400k -bf 2" pgmyuv "-an -vcodec mpeg4"
+do_video_decoding
+fi
+
+###################################
+if [ -n "$do_mpeg4adv" ] ; then
+# mpeg4
+do_video_encoding mpeg4-adv.avi "-qscale 9 -flags +mv4+part+aic+trell -mbd bits -ps 200" pgmyuv "-an -vcodec mpeg4"
+do_video_decoding
+
+# mpeg4
+do_video_encoding mpeg4-qprd.avi "-b 450k -bf 2 -flags +mv4+trell+qprd+mv0 -cmp 2 -subcmp 2 -mbd rd" pgmyuv "-an -vcodec mpeg4"
+do_video_decoding
+
+# mpeg4
+do_video_encoding mpeg4-adap.avi "-b 550k -bf 2 -flags +mv4+trell+mv0 -cmp 1 -subcmp 2 -mbd rd -scplx_mask 0.3" pgmyuv "-an -vcodec mpeg4"
+do_video_decoding
+
+# mpeg4
+do_video_encoding mpeg4-Q.avi "-qscale 7 -flags +mv4+qpel -mbd 2 -bf 2 -cmp 1 -subcmp 2" pgmyuv "-an -vcodec mpeg4"
+do_video_decoding
+fi
+
+###################################
+if [ -n "$do_mpeg4thread" ] ; then
+# mpeg4
+do_video_encoding mpeg4-thread.avi "-b 500k -flags +mv4+part+aic+trell -mbd bits -ps 200 -bf 2" pgmyuv "-an -vcodec mpeg4 -threads 2"
+do_video_decoding
+fi
+
+###################################
+if [ -n "$do_mp4psp" ] ; then
+# mp4 PSP style
+do_video_encoding mpeg4-PSP.mp4 "-vb 768k -s 320x240" psp "-ar 24000 -ab 32k -i $raw_src"
+fi
+
+###################################
+if [ -n "$do_error" ] ; then
+# damaged mpeg4
+do_video_encoding error-mpeg4-adv.avi "-qscale 7 -flags +mv4+part+aic -mbd rd -ps 250 -error 10" pgmyuv "-an -vcodec mpeg4"
+do_video_decoding
+fi
+
+###################################
+if [ -n "$do_mpeg4nr" ] ; then
+# noise reduction
+do_video_encoding mpeg4-nr.avi "-qscale 8 -flags +mv4 -mbd rd -nr 200" pgmyuv "-an -vcodec mpeg4"
+do_video_decoding
+fi
+
+###################################
+if [ -n "$do_mpeg1b" ] ; then
+# mpeg1
+do_video_encoding mpeg1b.mpg "-qscale 8 -bf 3 -ps 200" pgmyuv "-an -vcodec mpeg1video -f mpeg1video"
+do_video_decoding
+fi
+
+###################################
+if [ -n "$do_mjpeg" ] ; then
+# mjpeg
+do_video_encoding mjpeg.avi "-qscale 10" pgmyuv "-an -vcodec mjpeg -pix_fmt yuvj420p"
+do_video_decoding "" "-pix_fmt yuv420p"
+fi
+
+###################################
+if [ -n "$do_ljpeg" ] ; then
+# ljpeg
+do_video_encoding ljpeg.avi "" pgmyuv "-an -vcodec ljpeg -strict -1"
+do_video_decoding
+fi
+
+###################################
+if [ -n "$do_jpegls" ] ; then
+# jpeg ls
+do_video_encoding jpegls.avi "" pgmyuv "-an -vcodec jpegls -vtag MJPG"
+do_video_decoding "" "-pix_fmt yuv420p"
+fi
+
+###################################
+if [ -n "$do_rv10" ] ; then
+# rv10 encoding
+do_video_encoding rv10.rm "-qscale 10" pgmyuv "-an"
+do_video_decoding
+fi
+
+###################################
+if [ -n "$do_rv20" ] ; then
+# rv20 encoding
+do_video_encoding rv20.rm "-qscale 10" pgmyuv "-vcodec rv20 -an"
+do_video_decoding
+fi
+
+###################################
+if [ -n "$do_asv1" ] ; then
+# asv1 encoding
+do_video_encoding asv1.avi "-qscale 10" pgmyuv "-an -vcodec asv1"
+do_video_decoding
+fi
+
+###################################
+if [ -n "$do_asv2" ] ; then
+# asv2 encoding
+do_video_encoding asv2.avi "-qscale 10" pgmyuv "-an -vcodec asv2"
+do_video_decoding
+fi
+
+###################################
+if [ -n "$do_flv" ] ; then
+# flv encoding
+do_video_encoding flv.flv "-qscale 10" pgmyuv "-an -vcodec flv"
+do_video_decoding
+fi
+
+###################################
+if [ -n "$do_ffv1" ] ; then
+# ffv1 encoding
+do_video_encoding ffv1.avi "-strict -2" pgmyuv "-an -vcodec ffv1"
+do_video_decoding
+fi
+
+###################################
+if [ -n "$do_snow" ] ; then
+# snow
+do_video_encoding snow.avi "-strict -2" pgmyuv "-an -vcodec snow -qscale 2 -flags +qpel -me iter -dia_size 2 -cmp 12 -subcmp 12 -s 128x64"
+do_video_decoding "" "-s 352x288"
+fi
+
+###################################
+if [ -n "$do_snowll" ] ; then
+# snow
+do_video_encoding snow53.avi "-strict -2" pgmyuv "-an -vcodec snow -qscale .001 -pred 1 -flags +mv4+qpel"
+do_video_decoding
+fi
+
+###################################
+if [ -n "$do_dv" ] ; then
+# dv
+do_video_encoding dv.dv "-dct int" pgmyuv "-s pal -an"
+do_video_decoding "" "-s cif"
+fi
+
+###################################
+if [ -n "$do_dv50" ] ; then
+# dv50
+do_video_encoding dv.dv "-dct int" pgmyuv "-s pal -pix_fmt yuv422p -an"
+do_video_decoding "" "-s cif -pix_fmt yuv420p"
+fi
+
+
+###################################
+if [ -n "$do_svq1" ] ; then
+# svq1
+do_video_encoding svq1.mov "" pgmyuv "-an -vcodec svq1 -qscale 3 -pix_fmt yuv410p"
+do_video_decoding "" "-pix_fmt yuv420p"
+fi
+
+###################################
+if [ -n "$do_mp2" ] ; then
+# mp2
+do_audio_encoding mp2.mp2 "-ar 44100"
+do_audio_decoding
+$tiny_psnr $pcm_dst $pcm_ref 2 1924 >> $logfile
+fi
+
+###################################
+if [ -n "$do_ac3" ] ; then
+# ac3
+do_audio_encoding ac3.rm "" -vn
+#do_audio_decoding
+fi
+
+###################################
+if [ -n "$do_g726" ] ; then
+# g726
+do_audio_encoding g726.wav "-ar 44100" "-ab 32k -ac 1 -ar 8000 -acodec g726"
+do_audio_decoding
+fi
+
+###################################
+if [ -n "$do_adpcm_ima_wav" ] ; then
+# adpcm ima
+do_audio_encoding adpcm_ima.wav "-ar 44100" "-acodec adpcm_ima_wav"
+do_audio_decoding
+fi
+
+###################################
+if [ -n "$do_adpcm_ms" ] ; then
+# adpcm ms
+do_audio_encoding adpcm_ms.wav "-ar 44100" "-acodec adpcm_ms"
+do_audio_decoding
+fi
+
+###################################
+if [ -n "$do_adpcm_yam" ] ; then
+# adpcm yamaha
+do_audio_encoding adpcm_yam.wav "-ar 44100" "-acodec adpcm_yamaha"
+do_audio_decoding
+fi
+
+###################################
+if [ -n "$do_flac" ] ; then
+# flac
+do_audio_encoding flac.flac "-ar 44100" "-acodec flac -compression_level 2"
+do_audio_decoding
+fi
+
+###################################
+if [ -n "$do_wma" ] ; then
+# wmav1
+do_audio_encoding wmav1.asf "-ar 44100" "-acodec wmav1"
+do_ffmpeg_nomd5 $pcm_dst -y -i $file -f wav $pcm_dst
+$tiny_psnr $pcm_dst $pcm_ref 2 8192 >> $logfile
+# wmav2
+do_audio_encoding wmav2.asf "-ar 44100" "-acodec wmav2"
+do_ffmpeg_nomd5 $pcm_dst -y -i $file -f wav $pcm_dst
+$tiny_psnr $pcm_dst $pcm_ref 2 8192 >> $logfile
+fi
+
+###################################
+#if [ -n "$do_vorbis" ] ; then
+# vorbis
+#disabled because its broken
+#do_audio_encoding vorbis.asf "-ar 44100" "-acodec vorbis"
+#do_audio_decoding
+#fi
+
+###################################
+# libavformat testing
+###################################
+
+if [ -n "$do_libavtest" ] ; then
+
+# avi
+do_libav avi
+
+# asf
+do_libav asf "-acodec mp2" "-r 25"
+
+# rm
+file=${outfile}libav.rm
+do_ffmpeg $file -t 1 -y -qscale 10 -f pgmyuv -i $raw_src -f s16le -i $pcm_src $file
+# broken
+#do_ffmpeg_crc $file -i $file
+
+# mpegps
+do_libav mpg
+
+# mpegts
+do_libav ts
+
+# swf
+do_libav swf -an
+
+# ffm
+do_libav ffm
+
+# flv
+do_libav flv -an
+
+# mov
+do_libav mov "-acodec pcm_alaw"
+
+# nut
+#do_libav nut "-acodec mp2"
+
+# dv
+do_libav dv "-ar 48000 -r 25 -s pal -ac 2"
+
+# gxf
+do_libav gxf "-ar 48000 -r 25 -s pal -ac 1"
+
+####################
+# streamed images
+# mjpeg
+#file=${outfile}libav.mjpeg
+#do_ffmpeg $file -t 1 -y -qscale 10 -f pgmyuv -i $raw_src $file
+#do_ffmpeg_crc $file -i $file
+
+# pbmpipe
+do_streamed_images pbm
+
+# pgmpipe
+do_streamed_images pgm
+
+# ppmpipe
+do_streamed_images ppm
+
+# gif
+file=${outfile}libav.gif
+do_ffmpeg $file -t 1 -y -qscale 10 -f pgmyuv -i $raw_src -pix_fmt rgb24 $file
+#do_ffmpeg_crc $file -i $file
+
+# yuv4mpeg
+file=${outfile}libav.y4m
+do_ffmpeg $file -t 1 -y -qscale 10 -f pgmyuv -i $raw_src $file
+#do_ffmpeg_crc $file -i $file
+
+####################
+# image formats
+# pgm
+do_image_formats pgm
+
+# ppm
+do_image_formats ppm
+
+# bmp
+do_image_formats bmp
+
+# tga
+do_image_formats tga
+
+# jpeg
+do_image_formats jpg "-flags +bitexact -dct fastint -idct simple -pix_fmt yuvj420p" "-f image2"
+
+####################
+# audio only
+
+# wav
+do_audio_only wav
+
+# alaw
+do_audio_only al
+
+# mulaw
+do_audio_only ul
+
+# au
+do_audio_only au
+
+# mmf
+do_audio_only mmf
+
+# aiff
+do_audio_only aif
+
+# voc
+do_audio_only voc
+
+####################
+# pix_fmt conversions
+conversions="yuv420p yuv422p yuv444p yuyv422 yuv410p yuv411p yuvj420p \
+ yuvj422p yuvj444p rgb24 bgr24 rgb32 rgb565 rgb555 gray monow \
+ monob pal8"
+for pix_fmt in $conversions ; do
+ file=${outfile}libav-${pix_fmt}.yuv
+ do_ffmpeg_nocheck $file -r 1 -t 1 -y -f pgmyuv -i $raw_src \
+ -f rawvideo -s 352x288 -pix_fmt $pix_fmt $raw_dst
+ do_ffmpeg $file -f rawvideo -s 352x288 -pix_fmt $pix_fmt -i $raw_dst \
+ -f rawvideo -s 352x288 -pix_fmt yuv444p $file
+done
+
+fi # [ -n "$do_libavtest" ]
+
+
+
+if $diff_cmd "$logfile" "$reffile" ; then
+ echo
+ echo Regression test succeeded.
+ exit 0
+else
+ echo
+ echo Regression test: Error.
+ exit 1
+fi
diff --git a/contrib/ffmpeg/tests/rotozoom.c b/contrib/ffmpeg/tests/rotozoom.c
new file mode 100644
index 000000000..52f5546a3
--- /dev/null
+++ b/contrib/ffmpeg/tests/rotozoom.c
@@ -0,0 +1,306 @@
+/*
+ * Generates a synthetic YUV video sequence suitable for codec testing.
+ *
+ * copyright (c) Sebastien Bechet <s.bechet@av7.net>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 <stdlib.h>
+#include <stdio.h>
+#include <inttypes.h>
+
+#define FIXP (1<<16)
+#define MY_PI 205887 //(M_PI*FIX)
+
+static int64_t int_pow(int64_t a, int p){
+ int64_t v= FIXP;
+
+ for(; p; p--){
+ v*= a;
+ v/= FIXP;
+ }
+
+ return v;
+}
+
+static int64_t int_sin(int64_t a){
+ if(a<0) a= MY_PI-a; // 0..inf
+ a %= 2*MY_PI; // 0..2PI
+
+ if(a>=MY_PI*3/2) a -= 2*MY_PI; // -PI/2 .. 3PI/2
+ if(a>=MY_PI/2 ) a = MY_PI - a; // -PI/2 .. PI/2
+
+ return a - int_pow(a, 3)/6 + int_pow(a, 5)/120 - int_pow(a, 7)/5040;
+}
+
+#define SCALEBITS 8
+#define ONE_HALF (1 << (SCALEBITS - 1))
+#define FIX(x) ((int) ((x) * (1L<<SCALEBITS) + 0.5))
+typedef unsigned char UINT8;
+
+static void rgb24_to_yuv420p(UINT8 *lum, UINT8 *cb, UINT8 *cr,
+ UINT8 *src, int width, int height)
+{
+ int wrap, wrap3, x, y;
+ int r, g, b, r1, g1, b1;
+ UINT8 *p;
+
+ wrap = width;
+ wrap3 = width * 3;
+ p = src;
+ for(y=0;y<height;y+=2) {
+ for(x=0;x<width;x+=2) {
+ r = p[0];
+ g = p[1];
+ b = p[2];
+ r1 = r;
+ g1 = g;
+ b1 = b;
+ lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g +
+ FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
+ r = p[3];
+ g = p[4];
+ b = p[5];
+ r1 += r;
+ g1 += g;
+ b1 += b;
+ lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g +
+ FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
+ p += wrap3;
+ lum += wrap;
+
+ r = p[0];
+ g = p[1];
+ b = p[2];
+ r1 += r;
+ g1 += g;
+ b1 += b;
+ lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g +
+ FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
+ r = p[3];
+ g = p[4];
+ b = p[5];
+ r1 += r;
+ g1 += g;
+ b1 += b;
+ lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g +
+ FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
+
+ cb[0] = ((- FIX(0.16874) * r1 - FIX(0.33126) * g1 +
+ FIX(0.50000) * b1 + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128;
+ cr[0] = ((FIX(0.50000) * r1 - FIX(0.41869) * g1 -
+ FIX(0.08131) * b1 + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128;
+
+ cb++;
+ cr++;
+ p += -wrap3 + 2 * 3;
+ lum += -wrap + 2;
+ }
+ p += wrap3;
+ lum += wrap;
+ }
+}
+
+/* cif format */
+#define DEFAULT_WIDTH 352
+#define DEFAULT_HEIGHT 288
+#define DEFAULT_NB_PICT 50
+
+void pgmyuv_save(const char *filename, int w, int h,
+ unsigned char *rgb_tab)
+{
+ FILE *f;
+ int i, h2, w2;
+ unsigned char *cb, *cr;
+ unsigned char *lum_tab, *cb_tab, *cr_tab;
+
+ lum_tab = malloc(w * h);
+ cb_tab = malloc((w * h) / 4);
+ cr_tab = malloc((w * h) / 4);
+
+ rgb24_to_yuv420p(lum_tab, cb_tab, cr_tab, rgb_tab, w, h);
+
+ f = fopen(filename,"wb");
+ fprintf(f, "P5\n%d %d\n%d\n", w, (h * 3) / 2, 255);
+ fwrite(lum_tab, 1, w * h, f);
+ h2 = h / 2;
+ w2 = w / 2;
+ cb = cb_tab;
+ cr = cr_tab;
+ for(i=0;i<h2;i++) {
+ fwrite(cb, 1, w2, f);
+ fwrite(cr, 1, w2, f);
+ cb += w2;
+ cr += w2;
+ }
+ fclose(f);
+
+ free(lum_tab);
+ free(cb_tab);
+ free(cr_tab);
+}
+
+unsigned char *rgb_tab;
+int width, height, wrap;
+
+void put_pixel(int x, int y, int r, int g, int b)
+{
+ unsigned char *p;
+
+ if (x < 0 || x >= width ||
+ y < 0 || y >= height)
+ return;
+
+ p = rgb_tab + y * wrap + x * 3;
+ p[0] = r;
+ p[1] = g;
+ p[2] = b;
+}
+
+unsigned char tab_r[256*256];
+unsigned char tab_g[256*256];
+unsigned char tab_b[256*256];
+
+int teta = 0;
+int h_cos [360];
+int h_sin [360];
+
+static int ipol(uint8_t *src, int x, int y){
+ int int_x= x>>16;
+ int int_y= y>>16;
+ int frac_x= x&0xFFFF;
+ int frac_y= y&0xFFFF;
+ int s00= src[ ( int_x &255) + 256*( int_y &255) ];
+ int s01= src[ ((int_x+1)&255) + 256*( int_y &255) ];
+ int s10= src[ ( int_x &255) + 256*((int_y+1)&255) ];
+ int s11= src[ ((int_x+1)&255) + 256*((int_y+1)&255) ];
+ int s0= (((1<<16) - frac_x)*s00 + frac_x*s01)>>8;
+ int s1= (((1<<16) - frac_x)*s10 + frac_x*s11)>>8;
+
+ return (((1<<16) - frac_y)*s0 + frac_y*s1)>>24;
+}
+
+void gen_image(int num, int w, int h)
+{
+ const int c = h_cos [teta];
+ const int s = h_sin [teta];
+
+ const int xi = -(w/2) * c;
+ const int yi = (w/2) * s;
+
+ const int xj = -(h/2) * s;
+ const int yj = -(h/2) * c;
+ int i,j;
+
+ int x,y;
+ int xprime = xj;
+ int yprime = yj;
+
+
+ for (j=0;j<h;j++) {
+
+ x = xprime + xi + FIXP*w/2;
+ xprime += s;
+
+ y = yprime + yi + FIXP*h/2;
+ yprime += c;
+
+ for ( i=0 ; i<w ; i++ ) {
+ x += c;
+ y -= s;
+#if 1
+ put_pixel(i, j, ipol(tab_r, x, y), ipol(tab_g, x, y), ipol(tab_b, x, y));
+#else
+ {
+ unsigned dep;
+ dep = ((x>>16)&255) + (((y>>16)&255)<<8);
+ put_pixel(i, j, tab_r[dep], tab_g[dep], tab_b[dep]);
+ }
+#endif
+ }
+ }
+ teta = (teta+1) % 360;
+}
+
+#define W 256
+#define H 256
+
+void init_demo(const char *filename) {
+ int i,j;
+ int h;
+ int radian;
+ char line[3 * W];
+
+ FILE *fichier;
+
+ fichier = fopen(filename,"rb");
+ if (!fichier) {
+ perror(filename);
+ exit(1);
+ }
+
+ fread(line, 1, 15, fichier);
+ for (i=0;i<H;i++) {
+ fread(line,1,3*W,fichier);
+ for (j=0;j<W;j++) {
+ tab_r[W*i+j] = line[3*j ];
+ tab_g[W*i+j] = line[3*j + 1];
+ tab_b[W*i+j] = line[3*j + 2];
+ }
+ }
+ fclose(fichier);
+
+ /* tables sin/cos */
+ for (i=0;i<360;i++) {
+ radian = 2*i*MY_PI/360;
+ h = 2*FIXP + int_sin (radian);
+ h_cos[i] = ( h * int_sin (radian + MY_PI/2) )/2/FIXP;
+ h_sin[i] = ( h * int_sin (radian ) )/2/FIXP;
+ }
+}
+
+int main(int argc, char **argv)
+{
+ int w, h, i;
+ char buf[1024];
+
+ if (argc != 3) {
+ printf("usage: %s directory/ image.pnm\n"
+ "generate a test video stream\n", argv[0]);
+ exit(1);
+ }
+
+ w = DEFAULT_WIDTH;
+ h = DEFAULT_HEIGHT;
+
+ rgb_tab = malloc(w * h * 3);
+ wrap = w * 3;
+ width = w;
+ height = h;
+
+ init_demo(argv[2]);
+
+ for(i=0;i<DEFAULT_NB_PICT;i++) {
+ snprintf(buf, sizeof(buf), "%s%02d.pgm", argv[1], i);
+ gen_image(i, w, h);
+ pgmyuv_save(buf, w, h, rgb_tab);
+ }
+
+ free(rgb_tab);
+ return 0;
+}
diff --git a/contrib/ffmpeg/tests/rotozoom.regression.ref b/contrib/ffmpeg/tests/rotozoom.regression.ref
new file mode 100644
index 000000000..94c4e1b72
--- /dev/null
+++ b/contrib/ffmpeg/tests/rotozoom.regression.ref
@@ -0,0 +1,198 @@
+ffmpeg regression test
+73ca6f1deab02d1d67a0e8495c026a9e *./data/a-mpeg1.mpg
+192783 ./data/a-mpeg1.mpg
+56147e94b12f08df7213e610e177823d *./data/out.yuv
+stddev: 4.95 PSNR:34.21 bytes:7602176
+2d55ce623a7be4e8136f80266e487678 *./data/a-mpeg2.mpg
+198667 ./data/a-mpeg2.mpg
+b7cae8a1f751b821cddcbe4d5dbc518c *./data/out.yuv
+stddev: 4.96 PSNR:34.19 bytes:7602176
+4dd6e884eeccfb5c0d9b5542349e3d62 *./data/a-mpeg2ivlc-qprd.mpg
+249692 ./data/a-mpeg2ivlc-qprd.mpg
+99214c2a75ece2a0bf4f5afebc0f8ed7 *./data/out.yuv
+stddev: 4.41 PSNR:35.22 bytes:7602176
+f979bcca866e6e4cad5dc6cb06e56cfb *./data/a-mpeg2.mpg
+198041 ./data/a-mpeg2.mpg
+f6d9bf24ff8676a7f6076c05cd2c81a3 *./data/out.yuv
+stddev: 4.97 PSNR:34.18 bytes:7602176
+f90197a8b6e62ae25f82625337f27240 *./data/a-mpeg2i.mpg
+204579 ./data/a-mpeg2i.mpg
+ea5057b60146c06d40449cdfc686bf13 *./data/out.yuv
+stddev: 4.98 PSNR:34.17 bytes:7602176
+c346717be44450e41d9d6e07f59d1490 *./data/a-mpeg2thread.mpg
+182959 ./data/a-mpeg2thread.mpg
+02b85a7f67ced2d146a5c4e8000712b6 *./data/out.yuv
+stddev: 4.75 PSNR:34.57 bytes:7602176
+ff30b3df75626398873ac4f30093a5ae *./data/a-mpeg2threadivlc.mpg
+182105 ./data/a-mpeg2threadivlc.mpg
+02b85a7f67ced2d146a5c4e8000712b6 *./data/out.yuv
+stddev: 4.75 PSNR:34.57 bytes:7602176
+3942f86a6aa6fe5aea586fedf210e33e *./data/a-mpeg2reuse.mpg
+394265 ./data/a-mpeg2reuse.mpg
+afbc483eaa769925259e6094cfda2c72 *./data/out.yuv
+stddev: 4.76 PSNR:34.56 bytes:7602176
+c09815e40a9d260628e1ebad8b2b3774 *./data/a-msmpeg4v2.avi
+129918 ./data/a-msmpeg4v2.avi
+8920194f8bf8f9cdd6c65b3df9e1a292 *./data/out.yuv
+stddev: 5.33 PSNR:33.58 bytes:7602176
+3069f95f2ffca1f20c8ea36e2625fabc *./data/a-msmpeg4.avi
+127680 ./data/a-msmpeg4.avi
+0e1c6e25c71c6a8fa8e506e3d97ca4c9 *./data/out.yuv
+stddev: 5.33 PSNR:33.58 bytes:7602176
+6896c9bdf765953d272c25e34795b934 *./data/a-wmv1.avi
+129548 ./data/a-wmv1.avi
+81eee429b665254d19a06607463c0b5e *./data/out.yuv
+stddev: 5.33 PSNR:33.59 bytes:7602176
+34b40c67036c8e09740f7acfe3d43df6 *./data/a-wmv2.avi
+129864 ./data/a-wmv2.avi
+81eee429b665254d19a06607463c0b5e *./data/out.yuv
+stddev: 5.33 PSNR:33.59 bytes:7602176
+dfd005d4c9030a0dc889c828a6408b9c *./data/a-h261.avi
+191086 ./data/a-h261.avi
+db7ceff174823b98834faa2320ca89ac *./data/out.yuv
+stddev: 6.38 PSNR:32.02 bytes:7602176
+9a368687ab34c48079f11a202839a6bc *./data/a-h263.avi
+160106 ./data/a-h263.avi
+61213b91b359697ebcefb9e0a53ac54a *./data/out.yuv
+stddev: 5.43 PSNR:33.41 bytes:7602176
+c7644d40e9f40bbd98e5a978f9f94bb4 *./data/a-h263p.avi
+868018 ./data/a-h263p.avi
+4b0ee791f280029dc03c528f76f195d4 *./data/out.yuv
+stddev: 1.91 PSNR:42.49 bytes:7602176
+f15f07988bfdb2851f88ebe3036b72d3 *./data/a-odivx.mp4
+119797 ./data/a-odivx.mp4
+90a3577850239083a9042bef33c50e85 *./data/out.yuv
+stddev: 5.34 PSNR:33.56 bytes:7602176
+a1323da0c8b437cd6961f8c90451880b *./data/a-huffyuv.avi
+6455232 ./data/a-huffyuv.avi
+dde5895817ad9d219f79a52d0bdfb001 *./data/out.yuv
+stddev: 0.00 PSNR:99.99 bytes:7602176
+968ca132d8cf46f84e657abcf8473b7c *./data/a-mpeg4-rc.avi
+227934 ./data/a-mpeg4-rc.avi
+895773fe8250c806a0d1592a6dd12401 *./data/out.yuv
+stddev: 4.24 PSNR:35.56 bytes:7602176
+9001cf571eb7f26fa5592bdec6538583 *./data/a-mpeg4-adv.avi
+173590 ./data/a-mpeg4-adv.avi
+699edf05648fdc42196b7bebef9be269 *./data/out.yuv
+stddev: 4.84 PSNR:34.41 bytes:7602176
+1e12bb209dae0ab4b64265b0a4262257 *./data/a-mpeg4-qprd.avi
+234048 ./data/a-mpeg4-qprd.avi
+1ec355ffb30d2adf302a550cf5812636 *./data/out.yuv
+stddev: 4.23 PSNR:35.58 bytes:7602176
+d581d6f4a331325905b8ffb05cd3bfd3 *./data/a-mpeg4-adap.avi
+204284 ./data/a-mpeg4-adap.avi
+c2c7f1c7844ab92d34247ccb70198c61 *./data/out.yuv
+stddev: 4.04 PSNR:35.99 bytes:7602176
+a5150067914ee1dee50f8fc8dcaee841 *./data/a-mpeg4-Q.avi
+165802 ./data/a-mpeg4-Q.avi
+4dcc71ad79bee90777cf5299044be362 *./data/out.yuv
+stddev: 4.00 PSNR:36.08 bytes:7602176
+8cd8940d7451925784536fe9b2f2a5e3 *./data/a-mpeg4-thread.avi
+254260 ./data/a-mpeg4-thread.avi
+d160a4224ea1af66c85178912f8d3a7c *./data/out.yuv
+stddev: 4.03 PSNR:36.01 bytes:7602176
+5b5b88ce610114e346a5df4f46995bb9 *./data/a-mpeg4-PSP.mp4
+325006 ./data/a-mpeg4-PSP.mp4
+90e65096aa9ebafa3fe3f44a5a47cdc4 *./data/a-error-mpeg4-adv.avi
+176588 ./data/a-error-mpeg4-adv.avi
+113defd3f8daf878e0b3fc03fafb4c09 *./data/out.yuv
+stddev: 9.02 PSNR:29.01 bytes:7602176
+c41187c99588fb7229ad330b2f80d28b *./data/a-mpeg4-nr.avi
+155044 ./data/a-mpeg4-nr.avi
+f7fc191308679f709405e62271f5c65f *./data/out.yuv
+stddev: 4.73 PSNR:34.62 bytes:7602176
+977f3caf286e8f36c6ab4c7464632f26 *./data/a-mpeg1b.mpg
+229806 ./data/a-mpeg1b.mpg
+f41c60846bfb8cb6dcf6071c846c82b4 *./data/out.yuv
+stddev: 4.13 PSNR:35.79 bytes:7602176
+b179402bba391073b5f5f9324a834061 *./data/a-mjpeg.avi
+703564 ./data/a-mjpeg.avi
+b1aa72cfb6f9cc3f525b27abc86a8f51 *./data/out.yuv
+stddev: 4.38 PSNR:35.28 bytes:7602176
+bc0d8c868c1a05db0ff03f41768f6c5e *./data/a-ljpeg.avi
+4766558 ./data/a-ljpeg.avi
+dde5895817ad9d219f79a52d0bdfb001 *./data/out.yuv
+stddev: 0.00 PSNR:99.99 bytes:7602176
+f67cd488dfd06c03ad1d6d94d81b80c8 *./data/a-jpegls.avi
+8334488 ./data/a-jpegls.avi
+a63d4e3ea1f0b0c0d44821da9e09b8f4 *./data/out.yuv
+stddev: 0.67 PSNR:51.57 bytes:7602176
+989a42671603dc1a7e6b156dccf0e820 *./data/a-rv10.rm
+154330 ./data/a-rv10.rm
+61213b91b359697ebcefb9e0a53ac54a *./data/out.yuv
+stddev: 5.43 PSNR:33.41 bytes:7602176
+1b1cbff8e78602de498b4314cb991e72 *./data/a-rv20.rm
+132754 ./data/a-rv20.rm
+c66afdcc0daac2f1b4167b9811968877 *./data/out.yuv
+stddev: 5.42 PSNR:33.44 bytes:7602176
+4eb34d2de25f67a2706456e999338fe9 *./data/a-asv1.avi
+832512 ./data/a-asv1.avi
+c96ff7fd17c52f99ddb7922a4cb9168f *./data/out.yuv
+stddev: 10.47 PSNR:27.72 bytes:7602176
+9649a4b68fb1107bad13e8a7574cc72d *./data/a-asv2.avi
+789072 ./data/a-asv2.avi
+74a78015b64b2cf8cb9da2e44f508a69 *./data/out.yuv
+stddev: 10.28 PSNR:27.88 bytes:7602176
+7163b470e93feb36b3f01e82168a3d31 *./data/a-flv.flv
+131360 ./data/a-flv.flv
+8999c8264fb0941561f64c4a736e9d88 *./data/out.yuv
+stddev: 5.33 PSNR:33.58 bytes:7602176
+d72b0960e162d4998b9acbabb07e99ab *./data/a-ffv1.avi
+3525804 ./data/a-ffv1.avi
+dde5895817ad9d219f79a52d0bdfb001 *./data/out.yuv
+stddev: 0.00 PSNR:99.99 bytes:7602176
+40a6e938ac2bd92ee12cd57925e86454 *./data/a-snow.avi
+68758 ./data/a-snow.avi
+1e356854142898c7c4aab4bfedadf235 *./data/out.yuv
+stddev: 10.86 PSNR:27.40 bytes:7602176
+3d0da6aeec9b80c6ee0ff4b747bdd0f0 *./data/a-snow53.avi
+2721980 ./data/a-snow53.avi
+dde5895817ad9d219f79a52d0bdfb001 *./data/out.yuv
+stddev: 0.00 PSNR:99.99 bytes:7602176
+54cdeaee32d1007666a1e487e739daf6 *./data/a-dv.dv
+7200000 ./data/a-dv.dv
+75bf724e37f667f36af50e2051846574 *./data/out.yuv
+stddev: 3.11 PSNR:38.24 bytes:7602176
+ac6741e4c79e9ed18f179c4124ede29c *./data/a-dv.dv
+14400000 ./data/a-dv.dv
+ad9907f4ef608f025f5fc38b4b067b37 *./data/out.yuv
+stddev: 3.11 PSNR:38.25 bytes:7602176
+7ba9292d663819a9a1d1cdecc6f1b079 *./data/a-svq1.mov
+768407 ./data/a-svq1.mov
+6bc10518bc387c3bdf117997713ee69a *./data/out.yuv
+stddev: 3.44 PSNR:37.39 bytes:7602176
+21f8ff9f1daacd9133683bb4ea0f50a4 *./data/a-mp2.mp2
+95712 ./data/a-mp2.mp2
+83f8df5d5f84480566af548bb037fceb *./data/out.wav
+stddev:9330.70 PSNR:16.92 bytes:1054720
+stddev:4396.13 PSNR:23.46 bytes:1052672
+aefe11ab5067621a1c674859d6413891 *./data/a-ac3.rm
+98203 ./data/a-ac3.rm
+39878597b1d65cce473639a7d8c93b02 *./data/a-g726.wav
+24279 ./data/a-g726.wav
+888f2f016e608d044a1bacbca5497ed2 *./data/out.wav
+stddev:8368.02 PSNR:17.87 bytes:96256
+de3f0e1f50b19bd8572fdd3dee2e72c4 *./data/a-adpcm_ima.wav
+266300 ./data/a-adpcm_ima.wav
+60178d48204f5662d91776e36eddc82e *./data/out.wav
+stddev:11441.89 PSNR:15.15 bytes:1054720
+628d4789cf9ee16a756ac54b7fd8650d *./data/a-adpcm_ms.wav
+267320 ./data/a-adpcm_ms.wav
+91a84bb4f319a3a0bf0c0441b3d3a529 *./data/out.wav
+stddev:1050.18 PSNR:35.89 bytes:1054720
+ab11d9151644cbff27827b7e89f37aa9 *./data/a-adpcm_yam.wav
+264248 ./data/a-adpcm_yam.wav
+e92cec8c07913ffb91ad2b11f79cdc00 *./data/out.wav
+stddev:18312.68 PSNR:11.06 bytes:1056768
+c3382f03ce2efb5d475240d288a33898 *./data/a-flac.flac
+353368 ./data/a-flac.flac
+c4228df189aad9567a037727d0e763e4 *./data/out.wav
+stddev: 33.31 PSNR:65.87 bytes:1040384
+0c406c4e4586ca27064e28637b662631 *./data/a-wmav1.asf
+106004 ./data/a-wmav1.asf
+stddev:12251.50 PSNR:14.56 bytes:1056768
+stddev:2106.00 PSNR:29.85 bytes:1048576
+82442aaa5fdbd327769e4c4ad369147e *./data/a-wmav2.asf
+106044 ./data/a-wmav2.asf
+stddev:12255.92 PSNR:14.55 bytes:1056768
+stddev:2099.31 PSNR:29.88 bytes:1048576
diff --git a/contrib/ffmpeg/tests/seek_test.c b/contrib/ffmpeg/tests/seek_test.c
new file mode 100644
index 000000000..e17409439
--- /dev/null
+++ b/contrib/ffmpeg/tests/seek_test.c
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2003 Fabrice Bellard
+ * 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
+ */
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "avformat.h"
+
+int main(int argc, char **argv)
+{
+ const char *filename;
+ AVFormatContext *ic;
+ int i, ret, stream_id;
+ int64_t timestamp;
+
+ /* initialize libavcodec, and register all codecs and formats */
+ av_register_all();
+
+ if (argc != 2) {
+ printf("usage: %s input_file\n"
+ "\n", argv[0]);
+ exit(1);
+ }
+
+ filename = argv[1];
+
+ /* allocate the media context */
+ ic = av_alloc_format_context();
+ if (!ic) {
+ fprintf(stderr, "Memory error\n");
+ exit(1);
+ }
+
+ ret = av_open_input_file(&ic, filename, NULL, 0, NULL);
+ if (ret < 0) {
+ fprintf(stderr, "cant open %s\n", filename);
+ exit(1);
+ }
+
+ ret = av_find_stream_info(ic);
+ if (ret < 0) {
+ fprintf(stderr, "%s: could not find codec parameters\n", filename);
+ exit(1);
+ }
+
+ for(i=0; ; i++){
+ AVPacket pkt;
+ AVStream *st;
+
+ memset(&pkt, 0, sizeof(pkt));
+ if(ret>=0){
+ ret= av_read_frame(ic, &pkt);
+ printf("ret:%2d", ret);
+ if(ret>=0){
+ st= ic->streams[pkt.stream_index];
+ printf(" st:%2d dts:%f pts:%f pos:%Ld size:%d flags:%d", pkt.stream_index, pkt.dts*av_q2d(st->time_base), pkt.pts*av_q2d(st->time_base), pkt.pos, pkt.size, pkt.flags);
+ }
+ printf("\n");
+ }
+
+ if(i>25) break;
+
+ stream_id= (i>>1)%(ic->nb_streams+1) - 1;
+ timestamp= (i*19362894167LL) % (4*AV_TIME_BASE) - AV_TIME_BASE;
+ if(stream_id>=0){
+ st= ic->streams[stream_id];
+ timestamp= av_rescale_q(timestamp, AV_TIME_BASE_Q, st->time_base);
+ }
+ ret = av_seek_frame(ic, stream_id, timestamp, (i&1)*AVSEEK_FLAG_BACKWARD);
+ printf("ret:%2d st:%2d ts:%f flags:%d\n", ret, stream_id, timestamp*(stream_id<0 ? 1.0/AV_TIME_BASE : av_q2d(st->time_base)), i&1);
+ }
+
+ return 0;
+}
diff --git a/contrib/ffmpeg/tests/seek_test.sh b/contrib/ffmpeg/tests/seek_test.sh
new file mode 100755
index 000000000..eeac747b1
--- /dev/null
+++ b/contrib/ffmpeg/tests/seek_test.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+#feel free to clean this up ive made no attempt to write this overly portable ...
+
+datadir="./data"
+
+logfile="$datadir/seek.regression"
+reffile="$1"
+
+list=`ls data/a-* data/b-* | sort`
+rm $logfile
+for i in $list ; do
+ echo ---------------- >>$logfile
+ echo $i >>$logfile
+ ./seek_test $i >> $logfile
+done
+
+if diff -u "$logfile" "$reffile" ; then
+ echo
+ echo Regression test succeeded.
+ exit 0
+else
+ echo
+ echo Regression test: Error.
+ exit 1
+fi
diff --git a/contrib/ffmpeg/tests/server-regression.sh b/contrib/ffmpeg/tests/server-regression.sh
new file mode 100755
index 000000000..1f561aa54
--- /dev/null
+++ b/contrib/ffmpeg/tests/server-regression.sh
@@ -0,0 +1,54 @@
+#!/bin/bash
+# Even in the 21st century some diffs are not supporting -u.
+diff -u $0 $0 > /dev/null 2>&1
+if [ $? -eq 0 ]; then
+ diff_cmd="diff -u"
+else
+ diff_cmd="diff"
+fi
+
+# Make sure that the data directory exists
+mkdir -p data
+
+#perl -e 'chomp($wd = `pwd`); print map { s!data/!!; "<Stream $_>\nFile $wd/data/$_\n</Stream>\n\n" } @ARGV' data/a* >> data/test.conf
+#perl -e 'chomp($wd = `pwd`); print map { s!data/!!; "<Stream $_.asf>\nFile $wd/data/$_\n</Stream>\n\n" } @ARGV' data/a* >> data/test.conf
+
+FILES=`sed -n 's/^[^#]*<Stream \(.*\)>.*/\1/p' test.conf | grep -v html`
+
+rm -f feed1.ffm
+../ffserver -d -f test.conf 2> /dev/null &
+FFSERVER_PID=$!
+sleep 2
+echo "Waiting for feeds to startup..."
+../ffmpeg -loop_input -flags +bitexact -dct fastint -idct simple -y -f pgmyuv -i vsynth1/%02d.pgm http://localhost:9999/feed1.ffm 2> /dev/null &
+FFMPEG_PID=$!
+sleep 5
+(
+ cd data || exit $?
+ rm -f ff-*;
+ WGET_OPTIONS="--user-agent=NSPlayer -q --proxy=off -e verbose=off -e server_response=off"
+ for file in $FILES; do
+ if [ `expr $file : "a-*"` != 0 ]; then
+ wget $WGET_OPTIONS --output-document=- http://localhost:9999/$file > ff-$file
+ else
+ wget $WGET_OPTIONS --output-document=- http://localhost:9999/$file?date=19700101T000000Z | dd bs=1 count=20000 > ff-$file 2>/dev/null
+ fi
+ MDFILES="$MDFILES ff-$file"
+ done
+ wait
+ # the status page is always different
+ md5sum $MDFILES > ffserver.regression
+)
+kill $FFMPEG_PID
+kill $FFSERVER_PID
+wait > /dev/null 2>&1
+rm -f feed1.ffm
+if $diff_cmd data/ffserver.regression "$1" ; then
+ echo
+ echo Server regression test succeeded.
+ exit 0
+else
+ echo
+ echo Server regression test: Error.
+ exit 1
+fi
diff --git a/contrib/ffmpeg/tests/test.conf b/contrib/ffmpeg/tests/test.conf
new file mode 100644
index 000000000..afd4c16fb
--- /dev/null
+++ b/contrib/ffmpeg/tests/test.conf
@@ -0,0 +1,307 @@
+#
+# This is a test configuration file. You can invoke it with
+# ../ffserver -f test.conf
+# when in the tests directory and once the vsynth1 subdirectory
+# has been populated. Then point your browser at http://whatever:9999/teststat.html
+# and you can look at the streams
+#
+
+#
+# Port on which the server is listening. You must select a different
+# port from your standard http web server if it is running on the same
+# computer.
+
+Port 9999
+RTSPPort 9990
+
+# Address on which the server is bound. Only useful if you have
+# several network interfaces.
+
+BindAddress 0.0.0.0
+
+# Number of simultaneous requests that can be handled. Since FFServer
+# is very fast, this limit is determined mainly by your Internet
+# connection speed.
+
+MaxClients 1000
+
+MaxBandwidth 100000
+
+# Access Log file (uses standard Apache log file format)
+# '-' is the standard output
+
+CustomLog -
+
+##################################################################
+# Definition of the live feeds. Each live feed contains one video
+# and/or audio sequence coming from an ffmpeg encoder or another
+# ffserver. This sequence may be encoded simultaneously with several
+# codecs at several resolutions.
+
+<Feed feed1.ffm>
+
+# You must use 'ffmpeg' to send a live feed to ffserver. In this
+# example, you can type:
+#
+# ffmpeg http://localhost:8090/feed1.ffm
+
+# ffserver can also do time shifting. It means that it can stream any
+# previously recorded live stream. The request should contain:
+# "http://xxxx?date=[YYYY-MM-DDT][[HH:]MM:]SS[.m...]".You must specify
+# a path where the feed is stored on disk. You also specify the
+# maximum size of the feed (100M bytes here). Default:
+# File=/tmp/feed_name.ffm FileMaxSize=5M
+
+File feed1.ffm
+FileMaxSize 100M
+
+# Fire up ffmpeg pointing at this stream
+
+#Launch ../../ffmpeg -loop_input -flags +bitexact -dct fastint -idct simple -y -f pgmyuv -i vsynth1/%02d.pgm
+
+ACL allow localhost
+</Feed>
+
+##################################################################
+# Now you can define each stream which will be generated from the
+# original audio and video stream. Each format has a filename (here
+# 'test128.mpg'). FFServer will send this stream when answering a
+# request containing this filename.
+
+<Stream test_h.avi>
+Feed feed1.ffm
+Format avi
+#
+BitExact
+DctFastint
+IdctSimple
+VideoFrameRate 10
+VideoSize 352x288
+VideoBitRate 100
+VideoGopSize 30
+NoAudio
+
+PreRoll 10
+StartSendOnKey
+MaxTime 100
+
+</Stream>
+
+<Stream test_l.avi>
+Feed feed1.ffm
+Format avi
+#
+BitExact
+DctFastint
+IdctSimple
+VideoFrameRate 2
+VideoSize 320x240
+VideoBitRate 40
+VideoGopSize 20
+NoAudio
+
+PreRoll 20
+StartSendOnKey
+MaxTime 100
+
+</Stream>
+
+#<Stream test_h.mpg>
+#Feed feed1.ffm
+#
+#VideoFrameRate 10
+#VideoSize 352x288
+#VideoBitRate 100
+#VideoGopSize 30
+#NoAudio
+
+#PreRoll 10
+#StartSendOnKey
+#MaxTime 100
+#
+#</Stream>
+#
+#<Stream test_l.mpg>
+#Feed feed1.ffm
+##
+#VideoFrameRate 2
+#VideoSize 320x240
+#VideoBitRate 40
+#VideoGopSize 20
+#NoAudio
+#
+#PreRoll 20
+#StartSendOnKey
+#MaxTime 100
+#
+#</Stream>
+#
+<Stream test.swf>
+Feed feed1.ffm
+#
+BitExact
+DctFastint
+IdctSimple
+Qscale 10
+VideoFrameRate 10
+VideoSize 352x288
+VideoBitRate 100
+VideoGopSize 30
+NoAudio
+
+PreRoll 10
+StartSendOnKey
+MaxTime 100
+
+</Stream>
+
+<Stream test_h.asf>
+Feed feed1.ffm
+Format asf
+#
+BitExact
+DctFastint
+IdctSimple
+Qscale 10
+VideoFrameRate 10
+VideoSize 320x240
+VideoBitRate 100
+VideoGopSize 30
+NoAudio
+
+PreRoll 10
+StartSendOnKey
+MaxTime 100
+
+Title "Test data stream"
+
+</Stream>
+
+<Stream test_l.asf>
+Feed feed1.ffm
+Format asf
+#
+BitExact
+DctFastint
+IdctSimple
+Qscale 10
+VideoFrameRate 2
+VideoSize 320x240
+VideoBitRate 40
+VideoGopSize 20
+NoAudio
+
+PreRoll 20
+StartSendOnKey
+MaxTime 100
+
+Title "Test data stream"
+
+</Stream>
+
+<Stream test_h.rm>
+
+Feed feed1.ffm
+Format rm
+
+BitExact
+DctFastint
+IdctSimple
+Qscale 10
+VideoBitRate 100
+VideoFrameRate 10
+VideoGopSize 30
+VideoSize 320x240
+NoAudio
+
+PreRoll 10
+StartSendOnKey
+MaxTime 100
+
+</Stream>
+
+<Stream test_l.rm>
+
+Feed feed1.ffm
+Format rm
+
+BitExact
+DctFastint
+IdctSimple
+Qscale 10
+VideoBitRate 40
+VideoFrameRate 2
+VideoGopSize 20
+VideoSize 320x240
+NoAudio
+
+PreRoll 20
+StartSendOnKey
+MaxTime 100
+
+</Stream>
+
+
+<Stream test.jpg>
+
+Feed feed1.ffm
+Format jpeg
+Strict -1
+
+BitExact
+DctFastint
+IdctSimple
+VideoFrameRate 1
+VideoSize 352x288
+NoAudio
+
+PreRoll 2
+
+</Stream>
+
+<Stream test_small.jpg>
+
+Feed feed1.ffm
+Format jpeg
+Strict -1
+
+BitExact
+DctFastint
+IdctSimple
+VideoFrameRate 1
+VideoSize 160x128
+NoAudio
+
+PreRoll 2
+
+</Stream>
+
+<Stream test.mjpg>
+
+Feed feed1.ffm
+Format mpjpeg
+Strict -1
+
+BitExact
+DctFastint
+IdctSimple
+VideoFrameRate 1
+VideoSize 320x240
+NoAudio
+StartSendOnKey
+
+PreRoll 1
+MaxTime 100
+
+</Stream>
+
+
+##################################################################
+# Special stream : server status
+
+<Stream teststat.html>
+
+Format status
+
+</Stream>
+
diff --git a/contrib/ffmpeg/tests/tiny_psnr.c b/contrib/ffmpeg/tests/tiny_psnr.c
new file mode 100644
index 000000000..d8bce2b7b
--- /dev/null
+++ b/contrib/ffmpeg/tests/tiny_psnr.c
@@ -0,0 +1,154 @@
+/*
+ * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include <assert.h>
+
+#define F 100
+#define SIZE 2048
+
+uint64_t exp16_table[21]={
+ 65537,
+ 65538,
+ 65540,
+ 65544,
+ 65552,
+ 65568,
+ 65600,
+ 65664,
+ 65793,
+ 66050,
+ 66568,
+ 67616,
+ 69763,
+ 74262,
+ 84150,
+ 108051,
+ 178145,
+ 484249,
+ 3578144,
+ 195360063,
+ 582360139072LL,
+};
+#if 1
+// 16.16 fixpoint exp()
+static unsigned int exp16(unsigned int a){
+ int i;
+ int out= 1<<16;
+
+ for(i=19;i>=0;i--){
+ if(a&(1<<i))
+ out= (out*exp16_table[i] + (1<<15))>>16;
+ }
+
+ return out;
+}
+// 16.16 fixpoint log()
+static int64_t log16(uint64_t a){
+ int i;
+ int out=0;
+
+ if(a < 1<<16)
+ return -log16((1LL<<32) / a);
+ a<<=16;
+
+ for(i=20;i>=0;i--){
+ int64_t b= exp16_table[i];
+ if(a<(b<<16)) continue;
+ out |= 1<<i;
+ a = ((a/b)<<16) + (((a%b)<<16) + b/2)/b;
+ }
+ return out;
+}
+
+#endif
+static uint64_t int_sqrt(uint64_t a)
+{
+ uint64_t ret=0;
+ int s;
+ uint64_t ret_sq=0;
+
+ for(s=31; s>=0; s--){
+ uint64_t b= ret_sq + (1ULL<<(s*2)) + (ret<<s)*2;
+ if(b<=a){
+ ret_sq=b;
+ ret+= 1ULL<<s;
+ }
+ }
+ return ret;
+}
+
+int main(int argc,char* argv[]){
+ int i, j;
+ uint64_t sse=0;
+ uint64_t dev;
+ FILE *f[2];
+ uint8_t buf[2][SIZE];
+ uint64_t psnr;
+ int len= argc<4 ? 1 : atoi(argv[3]);
+ int64_t max= (1<<(8*len))-1;
+ int shift= argc<5 ? 0 : atoi(argv[4]);
+ int skip_bytes = argc<6 ? 0 : atoi(argv[5]);
+
+ if(argc<3){
+ printf("tiny_psnr <file1> <file2> [<elem size> [<shift> [<skip bytes>]]]\n");
+ printf("for wav files use the following:\n");
+ printf("./tiny_psnr file1.wav file2.wav 2 0 44 to skip the header.\n");
+ return -1;
+ }
+
+ f[0]= fopen(argv[1], "rb");
+ f[1]= fopen(argv[2], "rb");
+ fseek(f[shift<0], shift < 0 ? -shift : shift, SEEK_SET);
+
+ fseek(f[0],skip_bytes,SEEK_CUR);
+ fseek(f[1],skip_bytes,SEEK_CUR);
+
+ for(i=0;;){
+ if( fread(buf[0], SIZE, 1, f[0]) != 1) break;
+ if( fread(buf[1], SIZE, 1, f[1]) != 1) break;
+
+ for(j=0; j<SIZE; i++,j++){
+ int64_t a= buf[0][j];
+ int64_t b= buf[1][j];
+ if(len==2){
+ a= (int16_t)(a | (buf[0][++j]<<8));
+ b= (int16_t)(b | (buf[1][ j]<<8));
+ }
+ sse += (a-b) * (a-b);
+ }
+ }
+
+ if(!i) i=1;
+ dev= int_sqrt( ((sse/i)*F*F) + (((sse%i)*F*F) + i/2)/i );
+ if(sse)
+ psnr= ((2*log16(max<<16) + log16(i) - log16(sse))*284619LL*F + (1<<31)) / (1LL<<32);
+ else
+ psnr= 100*F-1; //floating point free infinity :)
+
+ printf("stddev:%3d.%02d PSNR:%2d.%02d bytes:%d\n",
+ (int)(dev/F), (int)(dev%F),
+ (int)(psnr/F), (int)(psnr%F),
+ i*len);
+ return 0;
+}
+
+
diff --git a/contrib/ffmpeg/tests/videogen.c b/contrib/ffmpeg/tests/videogen.c
new file mode 100644
index 000000000..39d85a26a
--- /dev/null
+++ b/contrib/ffmpeg/tests/videogen.c
@@ -0,0 +1,297 @@
+/*
+ * Generates a synthetic YUV video sequence suitable for codec testing.
+ * NOTE: no floats are used to guaranty a bit exact output.
+ *
+ * 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
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#define SCALEBITS 8
+#define ONE_HALF (1 << (SCALEBITS - 1))
+#define FIX(x) ((int) ((x) * (1L<<SCALEBITS) + 0.5))
+typedef unsigned char uint8_t;
+
+static void rgb24_to_yuv420p(uint8_t *lum, uint8_t *cb, uint8_t *cr,
+ uint8_t *src, int width, int height)
+{
+ int wrap, wrap3, x, y;
+ int r, g, b, r1, g1, b1;
+ uint8_t *p;
+
+ wrap = width;
+ wrap3 = width * 3;
+ p = src;
+ for(y=0;y<height;y+=2) {
+ for(x=0;x<width;x+=2) {
+ r = p[0];
+ g = p[1];
+ b = p[2];
+ r1 = r;
+ g1 = g;
+ b1 = b;
+ lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g +
+ FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
+ r = p[3];
+ g = p[4];
+ b = p[5];
+ r1 += r;
+ g1 += g;
+ b1 += b;
+ lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g +
+ FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
+ p += wrap3;
+ lum += wrap;
+
+ r = p[0];
+ g = p[1];
+ b = p[2];
+ r1 += r;
+ g1 += g;
+ b1 += b;
+ lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g +
+ FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
+ r = p[3];
+ g = p[4];
+ b = p[5];
+ r1 += r;
+ g1 += g;
+ b1 += b;
+ lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g +
+ FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
+
+ cb[0] = ((- FIX(0.16874) * r1 - FIX(0.33126) * g1 +
+ FIX(0.50000) * b1 + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128;
+ cr[0] = ((FIX(0.50000) * r1 - FIX(0.41869) * g1 -
+ FIX(0.08131) * b1 + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128;
+
+ cb++;
+ cr++;
+ p += -wrap3 + 2 * 3;
+ lum += -wrap + 2;
+ }
+ p += wrap3;
+ lum += wrap;
+ }
+}
+
+/* cif format */
+#define DEFAULT_WIDTH 352
+#define DEFAULT_HEIGHT 288
+#define DEFAULT_NB_PICT 50 /* 2 seconds */
+
+void pgmyuv_save(const char *filename, int w, int h,
+ unsigned char *rgb_tab)
+{
+ FILE *f;
+ int i, h2, w2;
+ unsigned char *cb, *cr;
+ unsigned char *lum_tab, *cb_tab, *cr_tab;
+
+ lum_tab = malloc(w * h);
+ cb_tab = malloc((w * h) / 4);
+ cr_tab = malloc((w * h) / 4);
+
+ rgb24_to_yuv420p(lum_tab, cb_tab, cr_tab, rgb_tab, w, h);
+
+ f = fopen(filename,"wb");
+ fprintf(f, "P5\n%d %d\n%d\n", w, (h * 3) / 2, 255);
+ fwrite(lum_tab, 1, w * h, f);
+ h2 = h / 2;
+ w2 = w / 2;
+ cb = cb_tab;
+ cr = cr_tab;
+ for(i=0;i<h2;i++) {
+ fwrite(cb, 1, w2, f);
+ fwrite(cr, 1, w2, f);
+ cb += w2;
+ cr += w2;
+ }
+ fclose(f);
+
+ free(lum_tab);
+ free(cb_tab);
+ free(cr_tab);
+}
+
+unsigned char *rgb_tab;
+int width, height, wrap;
+
+void put_pixel(int x, int y, int r, int g, int b)
+{
+ unsigned char *p;
+
+ if (x < 0 || x >= width ||
+ y < 0 || y >= height)
+ return;
+
+ p = rgb_tab + y * wrap + x * 3;
+ p[0] = r;
+ p[1] = g;
+ p[2] = b;
+}
+
+static unsigned int myrnd(unsigned int *seed_ptr, int n)
+{
+ unsigned int seed, val;
+
+ seed = *seed_ptr;
+ seed = (seed * 314159) + 1;
+ if (n == 256) {
+ val = seed >> 24;
+ } else {
+ val = seed % n;
+ }
+ *seed_ptr = seed;
+ return val;
+}
+
+#define NOISE_X 10
+#define NOISE_Y 30
+#define NOISE_W 26
+
+#define FRAC_BITS 8
+#define FRAC_ONE (1 << FRAC_BITS)
+
+/* cosine approximate with 1-x^2 */
+int int_cos(int a)
+{
+ int v, neg;
+ a = a & (FRAC_ONE - 1);
+ if (a >= (FRAC_ONE / 2))
+ a = FRAC_ONE - a;
+ neg = 0;
+ if (a > (FRAC_ONE / 4)) {
+ neg = -1;
+ a = (FRAC_ONE / 2) - a;
+ }
+ v = FRAC_ONE - ((a * a) >> 4);
+ v = (v ^ neg) - neg;
+ return v;
+}
+
+#define NB_OBJS 10
+
+typedef struct VObj {
+ int x, y, w, h;
+ int r, g, b;
+} VObj;
+
+VObj objs[NB_OBJS];
+
+unsigned int seed = 1;
+
+void gen_image(int num, int w, int h)
+{
+ int r, g, b, x, y, i, dx, dy, x1, y1;
+ unsigned int seed1;
+
+ if (num == 0) {
+ for(i=0;i<NB_OBJS;i++) {
+ objs[i].x = myrnd(&seed, w);
+ objs[i].y = myrnd(&seed, h);
+ objs[i].w = myrnd(&seed, w / 4) + 10;
+ objs[i].h = myrnd(&seed, h / 4) + 10;
+ objs[i].r = myrnd(&seed, 256);
+ objs[i].g = myrnd(&seed, 256);
+ objs[i].b = myrnd(&seed, 256);
+ }
+ }
+
+ /* first a moving background with gradients */
+ /* test motion estimation */
+ dx = int_cos(num * FRAC_ONE / 50) * 35;
+ dy = int_cos(num * FRAC_ONE / 50 + FRAC_ONE / 10) * 30;
+ for(y=0;y<h;y++) {
+ for(x=0;x<w;x++) {
+ x1 = (x << FRAC_BITS) + dx;
+ y1 = (y << FRAC_BITS) + dx;
+ r = ((y1 * 7) >> FRAC_BITS) & 0xff;
+ g = (((x1 + y1) * 9) >> FRAC_BITS) & 0xff;
+ b = ((x1 * 5) >> FRAC_BITS) & 0xff;
+ put_pixel(x, y, r, g, b);
+ }
+ }
+
+ /* then some noise with very high intensity to test saturation */
+ seed1 = num;
+ for(y=0;y<NOISE_W;y++) {
+ for(x=0;x<NOISE_W;x++) {
+ r = myrnd(&seed1, 256);
+ g = myrnd(&seed1, 256);
+ b = myrnd(&seed1, 256);
+ put_pixel(x + NOISE_X, y + NOISE_Y, r, g, b);
+ }
+ }
+
+ /* then moving objects */
+ for(i=0;i<NB_OBJS;i++) {
+ VObj *p = &objs[i];
+ seed1 = i;
+ for(y=0;y<p->h;y++) {
+ for(x=0;x<p->w;x++) {
+ r = p->r;
+ g = p->g;
+ b = p->b;
+ /* add a per object noise */
+ r += myrnd(&seed1, 50);
+ g += myrnd(&seed1, 50);
+ b += myrnd(&seed1, 50);
+ put_pixel(x + p->x, y + p->y, r, g, b);
+ }
+ }
+ p->x += myrnd(&seed, 21) - 10;
+ p->y += myrnd(&seed, 21) - 10;
+ }
+}
+
+int main(int argc, char **argv)
+{
+ int w, h, i;
+ char buf[1024];
+
+ if (argc != 2) {
+ printf("usage: %s file\n"
+ "generate a test video stream\n", argv[0]);
+ exit(1);
+ }
+
+#if 0
+ for(i=0;i<256;i++)
+ printf("cos(%d)=%d\n", i, int_cos(i));
+#endif
+
+ w = DEFAULT_WIDTH;
+ h = DEFAULT_HEIGHT;
+
+ rgb_tab = malloc(w * h * 3);
+ wrap = w * 3;
+ width = w;
+ height = h;
+
+ for(i=0;i<DEFAULT_NB_PICT;i++) {
+ snprintf(buf, sizeof(buf), "%s%02d.pgm", argv[1], i);
+ gen_image(i, w, h);
+ pgmyuv_save(buf, w, h, rgb_tab);
+ }
+
+ free(rgb_tab);
+ return 0;
+}
diff --git a/contrib/ffmpeg/unwrap-diff b/contrib/ffmpeg/unwrap-diff
new file mode 100755
index 000000000..ccea99b7b
--- /dev/null
+++ b/contrib/ffmpeg/unwrap-diff
@@ -0,0 +1,2 @@
+#!/bin/sh
+tr '\n' '\001' | sed 's/\x01\x01/\x01 \x01/g' | sed 's/\x01\([^-+ @]\)/ \1/g' | tr '\001' '\n'
diff --git a/contrib/ffmpeg/version.sh b/contrib/ffmpeg/version.sh
new file mode 100755
index 000000000..c04822f46
--- /dev/null
+++ b/contrib/ffmpeg/version.sh
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+svn_revision=`cd "$1" && LC_ALL=C svn info 2> /dev/null | grep Revision | cut -d' ' -f2`
+test $svn_revision || svn_revision=`cd "$1" && grep revision .svn/entries | \
+ cut -d '"' -f2 2> /dev/null`
+test $svn_revision || svn_revision=UNKNOWN
+
+NEW_REVISION="#define FFMPEG_VERSION \"SVN-r$svn_revision\""
+OLD_REVISION=`cat version.h 2> /dev/null`
+
+# Update version.h only on revision changes to avoid spurious rebuilds
+if test "$NEW_REVISION" != "$OLD_REVISION"; then
+ echo "$NEW_REVISION" > version.h
+fi
diff --git a/contrib/ffmpeg/vhook/Makefile b/contrib/ffmpeg/vhook/Makefile
new file mode 100644
index 000000000..167b8bfb0
--- /dev/null
+++ b/contrib/ffmpeg/vhook/Makefile
@@ -0,0 +1,50 @@
+include ../config.mak
+
+VPATH=$(SRC_PATH_BARE)/vhook
+
+CFLAGS=-I$(BUILD_ROOT) -I$(SRC_PATH) -I$(SRC_PATH)/libavutil -I$(SRC_PATH)/libavcodec \
+ -I$(SRC_PATH)/libavformat -I$(SRC_PATH)/libswscale $(VHOOKCFLAGS) -DHAVE_AV_CONFIG_H
+LDFLAGS+= -g
+
+HOOKS=null$(SLIBSUF) fish$(SLIBSUF) ppm$(SLIBSUF) watermark$(SLIBSUF)
+ALLHOOKS=$(HOOKS) imlib2$(SLIBSUF) drawtext$(SLIBSUF)
+
+ifeq ($(HAVE_IMLIB2),yes)
+ HOOKS += imlib2$(SLIBSUF)
+ CFLAGS += `imlib2-config --cflags`
+ LIBS_imlib2$(SLIBSUF) = `imlib2-config --libs`
+endif
+
+ifeq ($(HAVE_FREETYPE2),yes)
+ HOOKS += drawtext$(SLIBSUF)
+ CFLAGS += `freetype-config --cflags`
+ LIBS_drawtext$(SLIBSUF) = `freetype-config --libs`
+endif
+
+SRCS := $(HOOKS:$(SLIBSUF)=.c)
+
+all: $(HOOKS)
+
+depend dep: $(SRCS)
+ $(CC) -MM $(CFLAGS) $^ 1>.depend
+
+install: $(HOOKS)
+ install -d "$(shlibdir)/vhook"
+ install -m 755 $(HOOKS) "$(shlibdir)/vhook"
+
+uninstall:
+ rm -f $(addprefix $(shlibdir)/vhook/,$(ALLHOOKS))
+ -rmdir "$(shlibdir)/vhook/"
+
+%$(SLIBSUF): %.o
+ $(CC) $(LDFLAGS) -o $@ $(VHOOKSHFLAGS) $< $(VHOOKLIBS) $(LIBS_$@)
+
+clean:
+ rm -f *.o *.d *~ *.a *.lib *.so *.dylib *.dll
+
+distclean: clean
+ rm -f .depend
+
+.PHONY: all depend dep clean distclean install* uninstall*
+
+-include .depend
diff --git a/contrib/ffmpeg/vhook/drawtext.c b/contrib/ffmpeg/vhook/drawtext.c
new file mode 100644
index 000000000..081847620
--- /dev/null
+++ b/contrib/ffmpeg/vhook/drawtext.c
@@ -0,0 +1,531 @@
+/*
+ * drawtext.c: print text over the screen
+ ******************************************************************************
+ * Options:
+ * -f <filename> font filename (MANDATORY!!!)
+ * -s <pixel_size> font size in pixels [default 16]
+ * -b print background
+ * -o outline glyphs (use the bg color)
+ * -x <pos> x position ( >= 0) [default 0]
+ * -y <pos> y position ( >= 0) [default 0]
+ * -t <text> text to print (will be passed to strftime())
+ * MANDATORY: will be used even when -T is used.
+ * in this case, -t will be used if some error
+ * occurs
+ * -T <filename> file with the text (re-read every frame)
+ * -c <#RRGGBB> foreground color ('internet' way) [default #ffffff]
+ * -C <#RRGGBB> background color ('internet' way) [default #000000]
+ *
+ ******************************************************************************
+ * Features:
+ * - True Type, Type1 and others via FreeType2 library
+ * - Font kerning (better output)
+ * - Line Wrap (if the text doesn't fit, the next char go to the next line)
+ * - Background box
+ * - Outline
+ ******************************************************************************
+ * Author: Gustavo Sverzut Barbieri <gsbarbieri@yahoo.com.br>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 MAXSIZE_TEXT 1024
+
+#include "framehook.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <stdarg.h>
+#include <string.h>
+#include <unistd.h>
+#undef time
+#include <sys/time.h>
+#include <time.h>
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+#include FT_GLYPH_H
+
+#define SCALEBITS 10
+#define ONE_HALF (1 << (SCALEBITS - 1))
+#define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5))
+
+#define RGB_TO_YUV(rgb_color, yuv_color) do { \
+ yuv_color[0] = (FIX(0.29900) * rgb_color[0] + FIX(0.58700) * rgb_color[1] + FIX(0.11400) * rgb_color[2] + ONE_HALF) >> SCALEBITS; \
+ yuv_color[2] = ((FIX(0.50000) * rgb_color[0] - FIX(0.41869) * rgb_color[1] - FIX(0.08131) * rgb_color[2] + ONE_HALF - 1) >> SCALEBITS) + 128; \
+ yuv_color[1] = ((- FIX(0.16874) * rgb_color[0] - FIX(0.33126) * rgb_color[1] + FIX(0.50000) * rgb_color[2] + ONE_HALF - 1) >> SCALEBITS) + 128; \
+} while (0)
+
+#define COPY_3(dst,src) { \
+ dst[0]=src[0]; \
+ dst[1]=src[1]; \
+ dst[2]=src[2]; \
+}
+
+
+
+#define SET_PIXEL(picture, yuv_color, x, y) { \
+ picture->data[0][ (x) + (y)*picture->linesize[0] ] = yuv_color[0]; \
+ picture->data[1][ ((x/2) + (y/2)*picture->linesize[1]) ] = yuv_color[1]; \
+ picture->data[2][ ((x/2) + (y/2)*picture->linesize[2]) ] = yuv_color[2]; \
+}
+
+#define GET_PIXEL(picture, yuv_color, x, y) { \
+ yuv_color[0] = picture->data[0][ (x) + (y)*picture->linesize[0] ]; \
+ yuv_color[1] = picture->data[1][ (x/2) + (y/2)*picture->linesize[1] ]; \
+ yuv_color[2] = picture->data[2][ (x/2) + (y/2)*picture->linesize[2] ]; \
+}
+
+
+typedef struct {
+ unsigned char *text;
+ char *file;
+ unsigned int x;
+ unsigned int y;
+ int bg;
+ int outline;
+ unsigned char bgcolor[3]; /* YUV */
+ unsigned char fgcolor[3]; /* YUV */
+ FT_Library library;
+ FT_Face face;
+ FT_Glyph glyphs[ 255 ];
+ FT_Bitmap bitmaps[ 255 ];
+ int advance[ 255 ];
+ int bitmap_left[ 255 ];
+ int bitmap_top[ 255 ];
+ unsigned int glyphs_index[ 255 ];
+ int text_height;
+ int baseline;
+ int use_kerning;
+} ContextInfo;
+
+
+void Release(void *ctx)
+{
+ if (ctx)
+ av_free(ctx);
+}
+
+
+static int ParseColor(char *text, unsigned char yuv_color[3])
+{
+ char tmp[3];
+ unsigned char rgb_color[3];
+ int i;
+
+ tmp[2] = '\0';
+
+ if ((!text) || (strlen(text) != 7) || (text[0] != '#') )
+ return -1;
+
+ for (i=0; i < 3; i++)
+ {
+ tmp[0] = text[i*2+1];
+ tmp[1] = text[i*2+2];
+
+ rgb_color[i] = strtol(tmp, NULL, 16);
+ }
+
+ RGB_TO_YUV(rgb_color, yuv_color);
+
+ return 0;
+}
+
+int Configure(void **ctxp, int argc, char *argv[])
+{
+ int c;
+ int error;
+ ContextInfo *ci=NULL;
+ char *font=NULL;
+ unsigned int size=16;
+ FT_BBox bbox;
+ int yMax, yMin;
+ *ctxp = av_mallocz(sizeof(ContextInfo));
+ ci = (ContextInfo *) *ctxp;
+
+ /* configure Context Info */
+ ci->text = NULL;
+ ci->file = NULL;
+ ci->x = ci->y = 0;
+ ci->fgcolor[0]=255;
+ ci->fgcolor[1]=128;
+ ci->fgcolor[2]=128;
+ ci->bgcolor[0]=0;
+ ci->fgcolor[1]=128;
+ ci->fgcolor[2]=128;
+ ci->bg = 0;
+ ci->outline = 0;
+ ci->text_height = 0;
+
+ optind = 0;
+ while ((c = getopt(argc, argv, "f:t:T:x:y:s:c:C:bo")) > 0) {
+ switch (c) {
+ case 'f':
+ font = optarg;
+ break;
+ case 't':
+ ci->text = av_strdup(optarg);
+ break;
+ case 'T':
+ ci->file = av_strdup(optarg);
+ break;
+ case 'x':
+ ci->x = (unsigned int) atoi(optarg);
+ break;
+ case 'y':
+ ci->y = (unsigned int) atoi(optarg);
+ break;
+ case 's':
+ size = (unsigned int) atoi(optarg);
+ break;
+ case 'c':
+ if (ParseColor(optarg, ci->fgcolor) == -1)
+ {
+ av_log(NULL, AV_LOG_ERROR, "Invalid foreground color: '%s'. You must specify the color in the internet way(packaged hex): #RRGGBB, ie: -c #ffffff (for white foreground)\n", optarg);
+ return -1;
+ }
+ break;
+ case 'C':
+ if (ParseColor(optarg, ci->bgcolor) == -1)
+ {
+ av_log(NULL, AV_LOG_ERROR, "Invalid foreground color: '%s'. You must specify the color in the internet way(packaged hex): #RRGGBB, ie: -c #ffffff (for white foreground)\n", optarg);
+ return -1;
+ }
+ break;
+ case 'b':
+ ci->bg=1;
+ break;
+ case 'o':
+ ci->outline=1;
+ break;
+ case '?':
+ av_log(NULL, AV_LOG_ERROR, "Unrecognized argument '%s'\n", argv[optind]);
+ return -1;
+ }
+ }
+
+ if (!ci->text)
+ {
+ av_log(NULL, AV_LOG_ERROR, "No text provided (-t text)\n");
+ return -1;
+ }
+
+ if (ci->file)
+ {
+ FILE *fp;
+ if ((fp=fopen(ci->file, "r")) == NULL)
+ {
+ av_log(NULL, AV_LOG_INFO, "WARNING: The file could not be opened. Using text provided with -t switch: %s", strerror(errno));
+ }
+ else
+ {
+ fclose(fp);
+ }
+ }
+
+ if (!font)
+ {
+ av_log(NULL, AV_LOG_ERROR, "No font file provided! (-f filename)\n");
+ return -1;
+ }
+
+ if ((error = FT_Init_FreeType(&(ci->library))) != 0)
+ {
+ av_log(NULL, AV_LOG_ERROR, "Could not load FreeType (error# %d).\n", error);
+ return -1;
+ }
+
+ if ((error = FT_New_Face( ci->library, font, 0, &(ci->face) )) != 0)
+ {
+ av_log(NULL, AV_LOG_ERROR, "Could not load face: %s (error# %d).\n", font, error);
+ return -1;
+ }
+
+ if ((error = FT_Set_Pixel_Sizes( ci->face, 0, size)) != 0)
+ {
+ av_log(NULL, AV_LOG_ERROR, "Could not set font size to %d pixels (error# %d).\n", size, error);
+ return -1;
+ }
+
+ ci->use_kerning = FT_HAS_KERNING(ci->face);
+
+ /* load and cache glyphs */
+ yMax = -32000;
+ yMin = 32000;
+ for (c=0; c < 256; c++)
+ {
+ /* Load char */
+ error = FT_Load_Char( ci->face, (unsigned char) c, FT_LOAD_RENDER | FT_LOAD_MONOCHROME );
+ if (error) continue; /* ignore errors */
+
+ /* Save bitmap */
+ ci->bitmaps[c] = ci->face->glyph->bitmap;
+ /* Save bitmap left */
+ ci->bitmap_left[c] = ci->face->glyph->bitmap_left;
+ /* Save bitmap top */
+ ci->bitmap_top[c] = ci->face->glyph->bitmap_top;
+
+ /* Save advance */
+ ci->advance[c] = ci->face->glyph->advance.x >> 6;
+
+ /* Save glyph */
+ error = FT_Get_Glyph( ci->face->glyph, &(ci->glyphs[c]) );
+ /* Save glyph index */
+ ci->glyphs_index[c] = FT_Get_Char_Index( ci->face, (unsigned char) c );
+
+ /* Measure text height to calculate text_height (or the maximum text height) */
+ FT_Glyph_Get_CBox( ci->glyphs[ c ], ft_glyph_bbox_pixels, &bbox );
+ if (bbox.yMax > yMax)
+ yMax = bbox.yMax;
+ if (bbox.yMin < yMin)
+ yMin = bbox.yMin;
+
+ }
+
+ ci->text_height = yMax - yMin;
+ ci->baseline = yMax;
+
+ return 0;
+}
+
+
+
+
+static inline void draw_glyph(AVPicture *picture, FT_Bitmap *bitmap, unsigned int x, unsigned int y, unsigned int width, unsigned int height, unsigned char yuv_fgcolor[3], unsigned char yuv_bgcolor[3], int outline)
+{
+ int r, c;
+ int spixel, dpixel[3], in_glyph=0;
+
+ if (bitmap->pixel_mode == ft_pixel_mode_mono)
+ {
+ in_glyph = 0;
+ for (r=0; (r < bitmap->rows) && (r+y < height); r++)
+ {
+ for (c=0; (c < bitmap->width) && (c+x < width); c++)
+ {
+ /* pixel in the picture (destination) */
+ GET_PIXEL(picture, dpixel, (c+x), (y+r));
+
+ /* pixel in the glyph bitmap (source) */
+ spixel = bitmap->buffer[r*bitmap->pitch +c/8] & (0x80>>(c%8));
+
+ if (spixel)
+ COPY_3(dpixel, yuv_fgcolor);
+
+ if (outline)
+ {
+ /* border detection: */
+ if ( (!in_glyph) && (spixel) )
+ /* left border detected */
+ {
+ in_glyph = 1;
+ /* draw left pixel border */
+ if (c-1 >= 0)
+ SET_PIXEL(picture, yuv_bgcolor, (c+x-1), (y+r));
+ }
+ else if ( (in_glyph) && (!spixel) )
+ /* right border detected */
+ {
+ in_glyph = 0;
+ /* 'draw' right pixel border */
+ COPY_3(dpixel, yuv_bgcolor);
+ }
+
+ if (in_glyph)
+ /* see if we have a top/bottom border */
+ {
+ /* top */
+ if ( (r-1 >= 0) && (! bitmap->buffer[(r-1)*bitmap->pitch +c/8] & (0x80>>(c%8))) )
+ /* we have a top border */
+ SET_PIXEL(picture, yuv_bgcolor, (c+x), (y+r-1));
+
+ /* bottom */
+ if ( (r+1 < height) && (! bitmap->buffer[(r+1)*bitmap->pitch +c/8] & (0x80>>(c%8))) )
+ /* we have a bottom border */
+ SET_PIXEL(picture, yuv_bgcolor, (c+x), (y+r+1));
+
+ }
+ }
+
+ SET_PIXEL(picture, dpixel, (c+x), (y+r));
+ }
+ }
+ }
+}
+
+
+static inline void draw_box(AVPicture *picture, unsigned int x, unsigned int y, unsigned int width, unsigned int height, unsigned char yuv_color[3])
+{
+ int i, j;
+
+ for (j = 0; (j < height); j++)
+ for (i = 0; (i < width); i++)
+ {
+ SET_PIXEL(picture, yuv_color, (i+x), (y+j));
+ }
+
+}
+
+
+
+
+void Process(void *ctx, AVPicture *picture, enum PixelFormat pix_fmt, int width, int height, int64_t pts)
+{
+ ContextInfo *ci = (ContextInfo *) ctx;
+ FT_Face face = ci->face;
+ FT_GlyphSlot slot = face->glyph;
+ unsigned char *text = ci->text;
+ unsigned char c;
+ int x = 0, y = 0, i=0, size=0;
+ unsigned char buff[MAXSIZE_TEXT];
+ unsigned char tbuff[MAXSIZE_TEXT];
+ time_t now = time(0);
+ int str_w, str_w_max;
+ FT_Vector pos[MAXSIZE_TEXT];
+ FT_Vector delta;
+
+ if (ci->file)
+ {
+ int fd = open(ci->file, O_RDONLY);
+
+ if (fd < 0)
+ {
+ text = ci->text;
+ av_log(NULL, AV_LOG_INFO, "WARNING: The file could not be opened. Using text provided with -t switch: %s", strerror(errno));
+ }
+ else
+ {
+ int l = read(fd, tbuff, sizeof(tbuff) - 1);
+
+ if (l >= 0)
+ {
+ tbuff[l] = 0;
+ text = tbuff;
+ }
+ else
+ {
+ text = ci->text;
+ av_log(NULL, AV_LOG_INFO, "WARNING: The file could not be read. Using text provided with -t switch: %s", strerror(errno));
+ }
+ close(fd);
+ }
+ }
+ else
+ {
+ text = ci->text;
+ }
+
+ strftime(buff, sizeof(buff), text, localtime(&now));
+
+ text = buff;
+
+ size = strlen(text);
+
+
+
+
+ /* measure string size and save glyphs position*/
+ str_w = str_w_max = 0;
+ x = ci->x;
+ y = ci->y;
+ for (i=0; i < size; i++)
+ {
+ c = text[i];
+
+ /* kerning */
+ if ( (ci->use_kerning) && (i > 0) && (ci->glyphs_index[c]) )
+ {
+ FT_Get_Kerning( ci->face,
+ ci->glyphs_index[ text[i-1] ],
+ ci->glyphs_index[c],
+ ft_kerning_default,
+ &delta );
+
+ x += delta.x >> 6;
+ }
+
+ if (( (x + ci->advance[ c ]) >= width ) || ( c == '\n' ))
+ {
+ str_w = width - ci->x - 1;
+
+ y += ci->text_height;
+ x = ci->x;
+ }
+
+
+ /* save position */
+ pos[i].x = x + ci->bitmap_left[c];
+ pos[i].y = y - ci->bitmap_top[c] + ci->baseline;
+
+
+ x += ci->advance[c];
+
+
+ if (str_w > str_w_max)
+ str_w_max = str_w;
+
+ }
+
+
+
+
+ if (ci->bg)
+ {
+ /* Check if it doesn't pass the limits */
+ if ( str_w_max + ci->x >= width )
+ str_w_max = width - ci->x - 1;
+ if ( y >= height )
+ y = height - 1 - 2*ci->y;
+
+ /* Draw Background */
+ draw_box( picture, ci->x, ci->y, str_w_max, y - ci->y, ci->bgcolor );
+ }
+
+
+
+ /* Draw Glyphs */
+ for (i=0; i < size; i++)
+ {
+ c = text[i];
+
+ if (
+ ( (c == '_') && (text == ci->text) ) || /* skip '_' (consider as space)
+ IF text was specified in cmd line
+ (which doesn't like neasted quotes) */
+ ( c == '\n' ) /* Skip new line char, just go to new line */
+ )
+ continue;
+
+ /* now, draw to our target surface */
+ draw_glyph( picture,
+ &(ci->bitmaps[ c ]),
+ pos[i].x,
+ pos[i].y,
+ width,
+ height,
+ ci->fgcolor,
+ ci->bgcolor,
+ ci->outline );
+
+ /* increment pen position */
+ x += slot->advance.x >> 6;
+ }
+
+
+}
+
diff --git a/contrib/ffmpeg/vhook/fish.c b/contrib/ffmpeg/vhook/fish.c
new file mode 100644
index 000000000..1571cf9b9
--- /dev/null
+++ b/contrib/ffmpeg/vhook/fish.c
@@ -0,0 +1,380 @@
+/*
+ * Fish Detector Hook
+ * Copyright (c) 2002 Philip Gladstone
+ *
+ * This file implements a fish detector. It is used to see when a
+ * goldfish passes in front of the camera. It does this by counting
+ * the number of input pixels that fall within a particular HSV
+ * range.
+ *
+ * It takes a multitude of arguments:
+ *
+ * -h <num>-<num> the range of H values that are fish
+ * -s <num>-<num> the range of S values that are fish
+ * -v <num>-<num> the range of V values that are fish
+ * -z zap all non-fish values to black
+ * -l <num> limit the number of saved files to <num>
+ * -i <num> only check frames every <num> seconds
+ * -t <num> the threshold for the amount of fish pixels (range 0-1)
+ * -d turn debugging on
+ * -D <directory> where to put the fish images
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 <stdlib.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdarg.h>
+#include <string.h>
+#include <time.h>
+#include <stdio.h>
+#include <dirent.h>
+
+#include "framehook.h"
+#include "dsputil.h"
+#include "avformat.h"
+#include "swscale.h"
+
+static int sws_flags = SWS_BICUBIC;
+
+#define SCALEBITS 10
+#define ONE_HALF (1 << (SCALEBITS - 1))
+#define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5))
+
+#define YUV_TO_RGB1_CCIR(cb1, cr1)\
+{\
+ cb = (cb1) - 128;\
+ cr = (cr1) - 128;\
+ r_add = FIX(1.40200*255.0/224.0) * cr + ONE_HALF;\
+ g_add = - FIX(0.34414*255.0/224.0) * cb - FIX(0.71414*255.0/224.0) * cr + \
+ ONE_HALF;\
+ b_add = FIX(1.77200*255.0/224.0) * cb + ONE_HALF;\
+}
+
+#define YUV_TO_RGB2_CCIR(r, g, b, y1)\
+{\
+ yt = ((y1) - 16) * FIX(255.0/219.0);\
+ r = cm[(yt + r_add) >> SCALEBITS];\
+ g = cm[(yt + g_add) >> SCALEBITS];\
+ b = cm[(yt + b_add) >> SCALEBITS];\
+}
+
+
+
+
+typedef struct {
+ int h; /* 0 .. 360 */
+ int s; /* 0 .. 255 */
+ int v; /* 0 .. 255 */
+} HSV;
+
+typedef struct {
+ int zapping;
+ int threshold;
+ HSV dark, bright;
+ char *dir;
+ int file_limit;
+ int debug;
+ int min_interval;
+ int64_t next_pts;
+ int inset;
+ int min_width;
+ struct SwsContext *toRGB_convert_ctx;
+} ContextInfo;
+
+static void dorange(const char *s, int *first, int *second, int maxval)
+{
+ sscanf(s, "%d-%d", first, second);
+ if (*first > maxval)
+ *first = maxval;
+ if (*second > maxval)
+ *second = maxval;
+}
+
+void Release(void *ctx)
+{
+ ContextInfo *ci;
+ ci = (ContextInfo *) ctx;
+
+ if (ctx) {
+ sws_freeContext(ci->toRGB_convert_ctx);
+ av_free(ctx);
+ }
+}
+
+int Configure(void **ctxp, int argc, char *argv[])
+{
+ ContextInfo *ci;
+ int c;
+
+ *ctxp = av_mallocz(sizeof(ContextInfo));
+ ci = (ContextInfo *) *ctxp;
+
+ optind = 0;
+
+ ci->dir = "/tmp";
+ ci->threshold = 100;
+ ci->file_limit = 100;
+ ci->min_interval = 1000000;
+ ci->inset = 10; /* Percent */
+
+ while ((c = getopt(argc, argv, "w:i:dh:s:v:zl:t:D:")) > 0) {
+ switch (c) {
+ case 'h':
+ dorange(optarg, &ci->dark.h, &ci->bright.h, 360);
+ break;
+ case 's':
+ dorange(optarg, &ci->dark.s, &ci->bright.s, 255);
+ break;
+ case 'v':
+ dorange(optarg, &ci->dark.v, &ci->bright.v, 255);
+ break;
+ case 'z':
+ ci->zapping = 1;
+ break;
+ case 'l':
+ ci->file_limit = atoi(optarg);
+ break;
+ case 'i':
+ ci->min_interval = 1000000 * atof(optarg);
+ break;
+ case 't':
+ ci->threshold = atof(optarg) * 1000;
+ if (ci->threshold > 1000 || ci->threshold < 0) {
+ fprintf(stderr, "Invalid threshold value '%s' (range is 0-1)\n", optarg);
+ return -1;
+ }
+ break;
+ case 'w':
+ ci->min_width = atoi(optarg);
+ break;
+ case 'd':
+ ci->debug++;
+ break;
+ case 'D':
+ ci->dir = av_strdup(optarg);
+ break;
+ default:
+ fprintf(stderr, "Unrecognized argument '%s'\n", argv[optind]);
+ return -1;
+ }
+ }
+
+ fprintf(stderr, "Fish detector configured:\n");
+ fprintf(stderr, " HSV range: %d,%d,%d - %d,%d,%d\n",
+ ci->dark.h,
+ ci->dark.s,
+ ci->dark.v,
+ ci->bright.h,
+ ci->bright.s,
+ ci->bright.v);
+ fprintf(stderr, " Threshold is %d%% pixels\n", ci->threshold / 10);
+
+
+ return 0;
+}
+
+static void get_hsv(HSV *hsv, int r, int g, int b)
+{
+ int i, v, x, f;
+
+ x = (r < g) ? r : g;
+ if (b < x)
+ x = b;
+ v = (r > g) ? r : g;
+ if (b > v)
+ v = b;
+
+ if (v == x) {
+ hsv->h = 0;
+ hsv->s = 0;
+ hsv->v = v;
+ return;
+ }
+
+ if (r == v) {
+ f = g - b;
+ i = 0;
+ } else if (g == v) {
+ f = b - r;
+ i = 2 * 60;
+ } else {
+ f = r - g;
+ i = 4 * 60;
+ }
+
+ hsv->h = i + (60 * f) / (v - x);
+ if (hsv->h < 0)
+ hsv->h += 360;
+
+ hsv->s = (255 * (v - x)) / v;
+ hsv->v = v;
+
+ return;
+}
+
+void Process(void *ctx, AVPicture *picture, enum PixelFormat pix_fmt, int width, int height, int64_t pts)
+{
+ ContextInfo *ci = (ContextInfo *) ctx;
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+ int rowsize = picture->linesize[0];
+
+#if 0
+ printf("pix_fmt = %d, width = %d, pts = %lld, ci->next_pts = %lld\n",
+ pix_fmt, width, pts, ci->next_pts);
+#endif
+
+ if (pts < ci->next_pts)
+ return;
+
+ if (width < ci->min_width)
+ return;
+
+ ci->next_pts = pts + 1000000;
+
+ if (pix_fmt == PIX_FMT_YUV420P) {
+ uint8_t *y, *u, *v;
+ int width2 = width >> 1;
+ int inrange = 0;
+ int pixcnt;
+ int h;
+ int h_start, h_end;
+ int w_start, w_end;
+
+ h_end = 2 * ((ci->inset * height) / 200);
+ h_start = height - h_end;
+
+ w_end = (ci->inset * width2) / 100;
+ w_start = width2 - w_end;
+
+ pixcnt = ((h_start - h_end) >> 1) * (w_start - w_end);
+
+ y = picture->data[0] + h_end * picture->linesize[0] + w_end * 2;
+ u = picture->data[1] + h_end * picture->linesize[1] / 2 + w_end;
+ v = picture->data[2] + h_end * picture->linesize[2] / 2 + w_end;
+
+ for (h = h_start; h > h_end; h -= 2) {
+ int w;
+
+ for (w = w_start; w > w_end; w--) {
+ unsigned int r,g,b;
+ HSV hsv;
+ int cb, cr, yt, r_add, g_add, b_add;
+
+ YUV_TO_RGB1_CCIR(u[0], v[0]);
+ YUV_TO_RGB2_CCIR(r, g, b, y[0]);
+
+ get_hsv(&hsv, r, g, b);
+
+ if (ci->debug > 1)
+ fprintf(stderr, "(%d,%d,%d) -> (%d,%d,%d)\n",
+ r,g,b,hsv.h,hsv.s,hsv.v);
+
+
+ if (hsv.h >= ci->dark.h && hsv.h <= ci->bright.h &&
+ hsv.s >= ci->dark.s && hsv.s <= ci->bright.s &&
+ hsv.v >= ci->dark.v && hsv.v <= ci->bright.v) {
+ inrange++;
+ } else if (ci->zapping) {
+ y[0] = y[1] = y[rowsize] = y[rowsize + 1] = 16;
+ u[0] = 128;
+ v[0] = 128;
+ }
+
+ y+= 2;
+ u++;
+ v++;
+ }
+
+ y += picture->linesize[0] * 2 - (w_start - w_end) * 2;
+ u += picture->linesize[1] - (w_start - w_end);
+ v += picture->linesize[2] - (w_start - w_end);
+ }
+
+ if (ci->debug)
+ fprintf(stderr, "Fish: Inrange=%d of %d = %d threshold\n", inrange, pixcnt, 1000 * inrange / pixcnt);
+
+ if (inrange * 1000 / pixcnt >= ci->threshold) {
+ /* Save to file */
+ int size;
+ char *buf;
+ AVPicture picture1;
+ static int frame_counter;
+ static int foundfile;
+
+ if ((frame_counter++ % 20) == 0) {
+ /* Check how many files we have */
+ DIR *d;
+
+ foundfile = 0;
+
+ d = opendir(ci->dir);
+ if (d) {
+ struct dirent *dent;
+
+ while ((dent = readdir(d))) {
+ if (strncmp("fishimg", dent->d_name, 7) == 0) {
+ if (strcmp(".ppm", dent->d_name + strlen(dent->d_name) - 4) == 0) {
+ foundfile++;
+ }
+ }
+ }
+ closedir(d);
+ }
+ }
+
+ if (foundfile < ci->file_limit) {
+ FILE *f;
+ char fname[256];
+
+ size = avpicture_get_size(PIX_FMT_RGB24, width, height);
+ buf = av_malloc(size);
+
+ avpicture_fill(&picture1, buf, PIX_FMT_RGB24, width, height);
+
+ // if we already got a SWS context, let's realloc if is not re-useable
+ ci->toRGB_convert_ctx = sws_getCachedContext(ci->toRGB_convert_ctx,
+ width, height, pix_fmt,
+ width, height, PIX_FMT_RGB24,
+ sws_flags, NULL, NULL, NULL);
+ if (ci->toRGB_convert_ctx == NULL) {
+ av_log(NULL, AV_LOG_ERROR,
+ "Cannot initialize the toRGB conversion context\n");
+ return;
+ }
+ // img_convert parameters are 2 first destination, then 4 source
+ // sws_scale parameters are context, 4 first source, then 2 destination
+ sws_scale(ci->toRGB_convert_ctx,
+ picture->data, picture->linesize, 0, height,
+ picture1.data, picture1.linesize);
+
+ /* Write out the PPM file */
+ snprintf(fname, sizeof(fname), "%s/fishimg%ld_%"PRId64".ppm", ci->dir, (long)(av_gettime() / 1000000), pts);
+ f = fopen(fname, "w");
+ if (f) {
+ fprintf(f, "P6 %d %d 255\n", width, height);
+ fwrite(buf, width * height * 3, 1, f);
+ fclose(f);
+ }
+
+ av_free(buf);
+ ci->next_pts = pts + ci->min_interval;
+ }
+ }
+ }
+}
+
diff --git a/contrib/ffmpeg/vhook/imlib2.c b/contrib/ffmpeg/vhook/imlib2.c
new file mode 100644
index 000000000..4e6ffb67c
--- /dev/null
+++ b/contrib/ffmpeg/vhook/imlib2.c
@@ -0,0 +1,449 @@
+/*
+ * imlib2 based hook
+ * Copyright (c) 2002 Philip Gladstone
+ *
+ * This module implements a text overlay for a video image. Currently it
+ * supports a fixed overlay or reading the text from a file. The string
+ * is passed through strftime so that it is easy to imprint the date and
+ * time onto the image.
+ *
+ * You may also overlay an image (even semi-transparent) like TV stations do.
+ * You may move either the text or the image around your video to create
+ * scrolling credits, for example.
+ *
+ * Text fonts are being looked for in FONTPATH
+ *
+ * Options:
+ *
+ * -c <color> The color of the text
+ * -F <fontname> The font face and size
+ * -t <text> The text
+ * -f <filename> The filename to read text from
+ * -x <expresion> X coordinate of text or image
+ * -y <expresion> Y coordinate of text or image
+ * -i <filename> The filename to read a image from
+ *
+ * Expresions are functions of:
+ * N // frame number (starting at zero)
+ * H // frame height
+ * W // frame width
+ * h // image height
+ * w // image width
+ * X // previous x
+ * Y // previous y
+ *
+
+ Examples:
+
+ FONTPATH="/cygdrive/c/WINDOWS/Fonts/"
+ FONTPATH="$FONTPATH:/usr/share/imlib2/data/fonts/"
+ FONTPATH="$FONTPATH:/usr/X11R6/lib/X11/fonts/TTF/"
+ export FONTPATH
+
+ ffmpeg -i input.avi -vhook \
+ 'vhook/imlib2.dll -x W*(0.5+0.25*sin(N/47*PI))-w/2 -y H*(0.5+0.50*cos(N/97*PI))-h/2 -i /usr/share/imlib2/data/images/bulb.png'
+ -acodec copy -sameq output.avi
+
+ ffmpeg -i input.avi -vhook \
+ 'vhook/imlib2.dll -c red -F Vera.ttf/20 -x 150+0.5*N -y 70+0.25*N -t Hello'
+ -acodec copy -sameq output.avi
+
+ * This module is very much intended as an example of what could be done.
+ *
+ * One caution is that this is an expensive process -- in particular the
+ * conversion of the image into RGB and back is time consuming. For some
+ * special cases -- e.g. painting black text -- it would be faster to paint
+ * the text into a bitmap and then combine it directly into the YUV
+ * image. However, this code is fast enough to handle 10 fps of 320x240 on a
+ * 900MHz Duron in maybe 15% of the CPU.
+
+ * See further statistics on Pentium4, 3GHz, FFMpeg is SVN-r6798
+ * Input movie is 20.2 seconds of PAL DV on AVI
+ * Output movie is DVD compliant VOB.
+ *
+ ffmpeg -i input.avi -target pal-dvd out.vob
+ # 13.516s just transcode
+ ffmpeg -i input.avi -vhook /usr/local/bin/vhook/null.dll -target pal-dvd out.vob
+ # 23.546s transcode and img_convert
+ ffmpeg -i input.avi -vhook \
+ 'vhook/imlib2.dll -c red -F Vera/20 -x 150-0.5*N -y 70+0.25*N -t Hello_person' \
+ -target pal-dvd out.vob
+ # 21.454s transcode, img_convert and move text around
+ ffmpeg -i input.avi -vhook \
+ 'vhook/imlib2.dll -x 150-0.5*N -y 70+0.25*N -i /usr/share/imlib2/data/images/bulb.png' \
+ -target pal-dvd out.vob
+ # 20.828s transcode, img_convert and move image around
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 "framehook.h"
+#include "swscale.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <stdarg.h>
+#include <string.h>
+#include <unistd.h>
+#undef time
+#include <sys/time.h>
+#include <time.h>
+#include <Imlib2.h>
+#include "eval.h"
+
+const char *const_names[]={
+ "PI",
+ "E",
+ "N", // frame number (starting at zero)
+ "H", // frame height
+ "W", // frame width
+ "h", // image height
+ "w", // image width
+ "X", // previous x
+ "Y", // previous y
+ NULL
+};
+
+static int sws_flags = SWS_BICUBIC;
+
+typedef struct {
+ int dummy;
+ Imlib_Font fn;
+ char *text;
+ char *file;
+ int r, g, b;
+ double x, y;
+ char *fileImage;
+ struct _CachedImage *cache;
+ Imlib_Image imageOverlaid;
+ AVEvalExpr *eval_x, *eval_y;
+ char *expr_x, *expr_y;
+ int frame_number;
+ int imageOverlaid_width, imageOverlaid_height;
+
+ // This vhook first converts frame to RGB ...
+ struct SwsContext *toRGB_convert_ctx;
+ // ... and then converts back frame from RGB to initial format
+ struct SwsContext *fromRGB_convert_ctx;
+} ContextInfo;
+
+typedef struct _CachedImage {
+ struct _CachedImage *next;
+ Imlib_Image image;
+ int width;
+ int height;
+} CachedImage;
+
+void Release(void *ctx)
+{
+ ContextInfo *ci;
+ ci = (ContextInfo *) ctx;
+
+ if (ci->cache) {
+ imlib_context_set_image(ci->cache->image);
+ imlib_free_image();
+ av_free(ci->cache);
+ }
+ if (ctx) {
+ if (ci->imageOverlaid) {
+ imlib_context_set_image(ci->imageOverlaid);
+ imlib_free_image();
+ }
+ ff_eval_free(ci->expr_x);
+ ff_eval_free(ci->expr_y);
+ sws_freeContext(ci->toRGB_convert_ctx);
+ sws_freeContext(ci->fromRGB_convert_ctx);
+ av_free(ctx);
+ }
+}
+
+int Configure(void **ctxp, int argc, char *argv[])
+{
+ int c;
+ ContextInfo *ci;
+ char *font = "LucidaSansDemiBold/16";
+ char *fp = getenv("FONTPATH");
+ char *color = 0;
+ FILE *f;
+ char *p;
+
+ *ctxp = av_mallocz(sizeof(ContextInfo));
+ ci = (ContextInfo *) *ctxp;
+
+ ci->x = 0.0;
+ ci->y = 0.0;
+ ci->expr_x = "0.0";
+ ci->expr_y = "0.0";
+
+ optind = 0;
+
+ /* Use ':' to split FONTPATH */
+ if (fp)
+ while (p = strchr(fp, ':')) {
+ *p = 0;
+ imlib_add_path_to_font_path(fp);
+ fp = p + 1;
+ }
+ if ((fp) && (*fp))
+ imlib_add_path_to_font_path(fp);
+
+
+ while ((c = getopt(argc, argv, "c:f:F:t:x:y:i:")) > 0) {
+ switch (c) {
+ case 'c':
+ color = optarg;
+ break;
+ case 'F':
+ font = optarg;
+ break;
+ case 't':
+ ci->text = av_strdup(optarg);
+ break;
+ case 'f':
+ ci->file = av_strdup(optarg);
+ break;
+ case 'x':
+ ci->expr_x = av_strdup(optarg);
+ break;
+ case 'y':
+ ci->expr_y = av_strdup(optarg);
+ break;
+ case 'i':
+ ci->fileImage = av_strdup(optarg);
+ break;
+ case '?':
+ fprintf(stderr, "Unrecognized argument '%s'\n", argv[optind]);
+ return -1;
+ }
+ }
+
+ if (ci->text || ci->file) {
+ ci->fn = imlib_load_font(font);
+ if (!ci->fn) {
+ fprintf(stderr, "Failed to load font '%s'\n", font);
+ return -1;
+ }
+ imlib_context_set_font(ci->fn);
+ imlib_context_set_direction(IMLIB_TEXT_TO_RIGHT);
+ }
+
+ if (color) {
+ char buff[256];
+ int done = 0;
+
+ f = fopen("/usr/share/X11/rgb.txt", "r");
+ if (!f)
+ f = fopen("/usr/lib/X11/rgb.txt", "r");
+ if (!f) {
+ fprintf(stderr, "Failed to find rgb.txt\n");
+ return -1;
+ }
+ while (fgets(buff, sizeof(buff), f)) {
+ int r, g, b;
+ char colname[80];
+
+ if (sscanf(buff, "%d %d %d %64s", &r, &g, &b, colname) == 4 &&
+ strcasecmp(colname, color) == 0) {
+ ci->r = r;
+ ci->g = g;
+ ci->b = b;
+ /* fprintf(stderr, "%s -> %d,%d,%d\n", colname, r, g, b); */
+ done = 1;
+ break;
+ }
+ }
+ fclose(f);
+ if (!done) {
+ fprintf(stderr, "Unable to find color '%s' in rgb.txt\n", color);
+ return -1;
+ }
+ }
+ imlib_context_set_color(ci->r, ci->g, ci->b, 255);
+
+ /* load the image (for example, credits for a movie) */
+ if (ci->fileImage) {
+ ci->imageOverlaid = imlib_load_image_immediately(ci->fileImage);
+ if (!(ci->imageOverlaid)){
+ av_log(NULL, AV_LOG_ERROR, "Couldn't load image '%s'\n", ci->fileImage);
+ return -1;
+ }
+ imlib_context_set_image(ci->imageOverlaid);
+ ci->imageOverlaid_width = imlib_image_get_width();
+ ci->imageOverlaid_height = imlib_image_get_height();
+ }
+
+ if (!(ci->eval_x = ff_parse(ci->expr_x, const_names, NULL, NULL, NULL, NULL, NULL))){
+ av_log(NULL, AV_LOG_ERROR, "Couldn't parse x expression '%s'\n", ci->expr_x);
+ return -1;
+ }
+
+ if (!(ci->eval_y = ff_parse(ci->expr_y, const_names, NULL, NULL, NULL, NULL, NULL))){
+ av_log(NULL, AV_LOG_ERROR, "Couldn't parse y expression '%s'\n", ci->expr_y);
+ return -1;
+ }
+
+ return 0;
+}
+
+static Imlib_Image get_cached_image(ContextInfo *ci, int width, int height)
+{
+ CachedImage *cache;
+
+ for (cache = ci->cache; cache; cache = cache->next) {
+ if (width == cache->width && height == cache->height)
+ return cache->image;
+ }
+
+ return NULL;
+}
+
+static void put_cached_image(ContextInfo *ci, Imlib_Image image, int width, int height)
+{
+ CachedImage *cache = av_mallocz(sizeof(*cache));
+
+ cache->image = image;
+ cache->width = width;
+ cache->height = height;
+ cache->next = ci->cache;
+ ci->cache = cache;
+}
+
+void Process(void *ctx, AVPicture *picture, enum PixelFormat pix_fmt, int width, int height, int64_t pts)
+{
+ ContextInfo *ci = (ContextInfo *) ctx;
+ AVPicture picture1;
+ Imlib_Image image;
+ DATA32 *data;
+
+ image = get_cached_image(ci, width, height);
+
+ if (!image) {
+ image = imlib_create_image(width, height);
+ put_cached_image(ci, image, width, height);
+ }
+
+ imlib_context_set_image(image);
+ data = imlib_image_get_data();
+
+ avpicture_fill(&picture1, (uint8_t *) data, PIX_FMT_RGB32, width, height);
+
+ // if we already got a SWS context, let's realloc if is not re-useable
+ ci->toRGB_convert_ctx = sws_getCachedContext(ci->toRGB_convert_ctx,
+ width, height, pix_fmt,
+ width, height, PIX_FMT_RGB32,
+ sws_flags, NULL, NULL, NULL);
+ if (ci->toRGB_convert_ctx == NULL) {
+ av_log(NULL, AV_LOG_ERROR,
+ "Cannot initialize the toRGB conversion context\n");
+ return;
+ }
+
+// img_convert parameters are 2 first destination, then 4 source
+// sws_scale parameters are context, 4 first source, then 2 destination
+ sws_scale(ci->toRGB_convert_ctx,
+ picture->data, picture->linesize, 0, height,
+ picture1.data, picture1.linesize);
+
+ imlib_image_set_has_alpha(0);
+
+ {
+ int wid, hig, h_a, v_a;
+ char buff[1000];
+ char tbuff[1000];
+ char *tbp = ci->text;
+ time_t now = time(0);
+ char *p, *q;
+ int y;
+
+ double const_values[]={
+ M_PI,
+ M_E,
+ ci->frame_number, // frame number (starting at zero)
+ height, // frame height
+ width, // frame width
+ ci->imageOverlaid_height, // image height
+ ci->imageOverlaid_width, // image width
+ ci->x, // previous x
+ ci->y, // previous y
+ 0
+ };
+
+ if (ci->file) {
+ int fd = open(ci->file, O_RDONLY);
+
+ if (fd < 0) {
+ tbp = "[File not found]";
+ } else {
+ int l = read(fd, tbuff, sizeof(tbuff) - 1);
+
+ if (l >= 0) {
+ tbuff[l] = 0;
+ tbp = tbuff;
+ } else {
+ tbp = "[I/O Error]";
+ }
+ close(fd);
+ }
+ }
+
+ if (tbp)
+ strftime(buff, sizeof(buff), tbp, localtime(&now));
+ else if (!(ci->imageOverlaid))
+ strftime(buff, sizeof(buff), "[No data]", localtime(&now));
+
+ ci->x = ff_parse_eval(ci->eval_x, const_values, ci);
+ ci->y = ff_parse_eval(ci->eval_y, const_values, ci);
+ y = ci->y;
+
+ if (!(ci->imageOverlaid))
+ for (p = buff; p; p = q) {
+ q = strchr(p, '\n');
+ if (q)
+ *q++ = 0;
+
+ imlib_text_draw_with_return_metrics(ci->x, y, p, &wid, &hig, &h_a, &v_a);
+ y += v_a;
+ }
+
+ if (ci->imageOverlaid) {
+ imlib_context_set_image(image);
+ imlib_blend_image_onto_image(ci->imageOverlaid, 0,
+ 0, 0, ci->imageOverlaid_width, ci->imageOverlaid_height,
+ ci->x, ci->y, ci->imageOverlaid_width, ci->imageOverlaid_height);
+ }
+
+ }
+
+ ci->fromRGB_convert_ctx = sws_getCachedContext(ci->fromRGB_convert_ctx,
+ width, height, PIX_FMT_RGB32,
+ width, height, pix_fmt,
+ sws_flags, NULL, NULL, NULL);
+ if (ci->fromRGB_convert_ctx == NULL) {
+ av_log(NULL, AV_LOG_ERROR,
+ "Cannot initialize the fromRGB conversion context\n");
+ return;
+ }
+// img_convert parameters are 2 first destination, then 4 source
+// sws_scale parameters are context, 4 first source, then 2 destination
+ sws_scale(ci->fromRGB_convert_ctx,
+ picture1.data, picture1.linesize, 0, height,
+ picture->data, picture->linesize);
+
+ ci->frame_number++;
+}
+
diff --git a/contrib/ffmpeg/vhook/null.c b/contrib/ffmpeg/vhook/null.c
new file mode 100644
index 000000000..c93308906
--- /dev/null
+++ b/contrib/ffmpeg/vhook/null.c
@@ -0,0 +1,116 @@
+/*
+ * Null Video Hook
+ * Copyright (c) 2002 Philip Gladstone
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 <stdio.h>
+
+#include "framehook.h"
+#include "swscale.h"
+
+static int sws_flags = SWS_BICUBIC;
+
+typedef struct {
+ int dummy;
+
+ // This vhook first converts frame to RGB ...
+ struct SwsContext *toRGB_convert_ctx;
+
+ // ... and later converts back frame from RGB to initial format
+ struct SwsContext *fromRGB_convert_ctx;
+
+} ContextInfo;
+
+void Release(void *ctx)
+{
+ ContextInfo *ci;
+ ci = (ContextInfo *) ctx;
+
+ if (ctx) {
+ sws_freeContext(ci->toRGB_convert_ctx);
+ sws_freeContext(ci->fromRGB_convert_ctx);
+ av_free(ctx);
+ }
+}
+
+int Configure(void **ctxp, int argc, char *argv[])
+{
+ fprintf(stderr, "Called with argc=%d\n", argc);
+
+ *ctxp = av_mallocz(sizeof(ContextInfo));
+ return 0;
+}
+
+void Process(void *ctx, AVPicture *picture, enum PixelFormat pix_fmt, int width, int height, int64_t pts)
+{
+ ContextInfo *ci = (ContextInfo *) ctx;
+ char *buf = 0;
+ AVPicture picture1;
+ AVPicture *pict = picture;
+
+ (void) ci;
+
+ if (pix_fmt != PIX_FMT_RGB24) {
+ int size;
+
+ size = avpicture_get_size(PIX_FMT_RGB24, width, height);
+ buf = av_malloc(size);
+
+ avpicture_fill(&picture1, buf, PIX_FMT_RGB24, width, height);
+
+ // if we already got a SWS context, let's realloc if is not re-useable
+ ci->toRGB_convert_ctx = sws_getCachedContext(ci->toRGB_convert_ctx,
+ width, height, pix_fmt,
+ width, height, PIX_FMT_RGB24,
+ sws_flags, NULL, NULL, NULL);
+ if (ci->toRGB_convert_ctx == NULL) {
+ av_log(NULL, AV_LOG_ERROR,
+ "Cannot initialize the toRGB conversion context\n");
+ return;
+ }
+// img_convert parameters are 2 first destination, then 4 source
+// sws_scale parameters are context, 4 first source, then 2 destination
+ sws_scale(ci->toRGB_convert_ctx,
+ picture->data, picture->linesize, 0, height,
+ picture1.data, picture1.linesize);
+
+ pict = &picture1;
+ }
+
+ /* Insert filter code here */
+
+ if (pix_fmt != PIX_FMT_RGB24) {
+ ci->fromRGB_convert_ctx = sws_getCachedContext(ci->fromRGB_convert_ctx,
+ width, height, PIX_FMT_RGB24,
+ width, height, pix_fmt,
+ sws_flags, NULL, NULL, NULL);
+ if (ci->fromRGB_convert_ctx == NULL) {
+ av_log(NULL, AV_LOG_ERROR,
+ "Cannot initialize the fromRGB conversion context\n");
+ return;
+ }
+// img_convert parameters are 2 first destination, then 4 source
+// sws_scale parameters are context, 4 first source, then 2 destination
+ sws_scale(ci->fromRGB_convert_ctx,
+ picture1.data, picture1.linesize, 0, height,
+ picture->data, picture->linesize);
+ }
+
+ av_free(buf);
+}
+
diff --git a/contrib/ffmpeg/vhook/ppm.c b/contrib/ffmpeg/vhook/ppm.c
new file mode 100644
index 000000000..9f618e55b
--- /dev/null
+++ b/contrib/ffmpeg/vhook/ppm.c
@@ -0,0 +1,367 @@
+/*
+ * PPM Video Hook
+ * Copyright (c) 2003 Charles Yates
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <ctype.h>
+#include "framehook.h"
+#include "avformat.h"
+#include "swscale.h"
+
+static int sws_flags = SWS_BICUBIC;
+
+/** Bi-directional pipe structure.
+*/
+
+typedef struct rwpipe
+{
+ int pid;
+ FILE *reader;
+ FILE *writer;
+}
+rwpipe;
+
+/** Create a bidirectional pipe for the given command.
+*/
+
+static rwpipe *rwpipe_open( int argc, char *argv[] )
+{
+ rwpipe *this = av_mallocz( sizeof( rwpipe ) );
+
+ if ( this != NULL )
+ {
+ int input[ 2 ];
+ int output[ 2 ];
+
+ pipe( input );
+ pipe( output );
+
+ this->pid = fork();
+
+ if ( this->pid == 0 )
+ {
+#define COMMAND_SIZE 10240
+ char *command = av_mallocz( COMMAND_SIZE );
+ int i;
+
+ strcpy( command, "" );
+ for ( i = 0; i < argc; i ++ )
+ {
+ pstrcat( command, COMMAND_SIZE, argv[ i ] );
+ pstrcat( command, COMMAND_SIZE, " " );
+ }
+
+ dup2( output[ 0 ], STDIN_FILENO );
+ dup2( input[ 1 ], STDOUT_FILENO );
+
+ close( input[ 0 ] );
+ close( input[ 1 ] );
+ close( output[ 0 ] );
+ close( output[ 1 ] );
+
+ execl("/bin/sh", "sh", "-c", command, (char*)NULL );
+ _exit( 255 );
+ }
+ else
+ {
+ close( input[ 1 ] );
+ close( output[ 0 ] );
+
+ this->reader = fdopen( input[ 0 ], "r" );
+ this->writer = fdopen( output[ 1 ], "w" );
+ }
+ }
+
+ return this;
+}
+
+/** Read data from the pipe.
+*/
+
+static FILE *rwpipe_reader( rwpipe *this )
+{
+ if ( this != NULL )
+ return this->reader;
+ else
+ return NULL;
+}
+
+/** Write data to the pipe.
+*/
+
+static FILE *rwpipe_writer( rwpipe *this )
+{
+ if ( this != NULL )
+ return this->writer;
+ else
+ return NULL;
+}
+
+/* Read a number from the pipe - assumes PNM style headers.
+*/
+
+static int rwpipe_read_number( rwpipe *rw )
+{
+ int value = 0;
+ int c = 0;
+ FILE *in = rwpipe_reader( rw );
+
+ do
+ {
+ c = fgetc( in );
+
+ while( c != EOF && !isdigit( c ) && c != '#' )
+ c = fgetc( in );
+
+ if ( c == '#' )
+ while( c != EOF && c != '\n' )
+ c = fgetc( in );
+ }
+ while ( c != EOF && !isdigit( c ) );
+
+ while( c != EOF && isdigit( c ) )
+ {
+ value = value * 10 + ( c - '0' );
+ c = fgetc( in );
+ }
+
+ return value;
+}
+
+/** Read a PPM P6 header.
+*/
+
+static int rwpipe_read_ppm_header( rwpipe *rw, int *width, int *height )
+{
+ char line[ 3 ];
+ FILE *in = rwpipe_reader( rw );
+ int max;
+
+ fgets( line, 3, in );
+ if ( !strncmp( line, "P6", 2 ) )
+ {
+ *width = rwpipe_read_number( rw );
+ *height = rwpipe_read_number( rw );
+ max = rwpipe_read_number( rw );
+ return max != 255 || *width <= 0 || *height <= 0;
+ }
+ return 1;
+}
+
+/** Close the pipe and process.
+*/
+
+static void rwpipe_close( rwpipe *this )
+{
+ if ( this != NULL )
+ {
+ fclose( this->reader );
+ fclose( this->writer );
+ waitpid( this->pid, NULL, 0 );
+ av_free( this );
+ }
+}
+
+/** Context info for this vhook - stores the pipe and image buffers.
+*/
+
+typedef struct
+{
+ rwpipe *rw;
+ int size1;
+ char *buf1;
+ int size2;
+ char *buf2;
+
+ // This vhook first converts frame to RGB ...
+ struct SwsContext *toRGB_convert_ctx;
+ // ... then processes it via a PPM command pipe ...
+ // ... and finally converts back frame from RGB to initial format
+ struct SwsContext *fromRGB_convert_ctx;
+}
+ContextInfo;
+
+/** Initialise the context info for this vhook.
+*/
+
+int Configure(void **ctxp, int argc, char *argv[])
+{
+ if ( argc > 1 )
+ {
+ *ctxp = av_mallocz(sizeof(ContextInfo));
+ if ( ctxp != NULL && argc > 1 )
+ {
+ ContextInfo *info = (ContextInfo *)*ctxp;
+ info->rw = rwpipe_open( argc - 1, &argv[ 1 ] );
+ return 0;
+ }
+ }
+ return 1;
+}
+
+/** Process a frame.
+*/
+
+void Process(void *ctx, AVPicture *picture, enum PixelFormat pix_fmt, int width, int height, int64_t pts)
+{
+ int err = 0;
+ ContextInfo *ci = (ContextInfo *) ctx;
+ AVPicture picture1;
+ AVPicture picture2;
+ AVPicture *pict = picture;
+ int out_width;
+ int out_height;
+ int i;
+ uint8_t *ptr = NULL;
+ FILE *in = rwpipe_reader( ci->rw );
+ FILE *out = rwpipe_writer( ci->rw );
+
+ /* Check that we have a pipe to talk to. */
+ if ( in == NULL || out == NULL )
+ err = 1;
+
+ /* Convert to RGB24 if necessary */
+ if ( !err && pix_fmt != PIX_FMT_RGB24 )
+ {
+ int size = avpicture_get_size(PIX_FMT_RGB24, width, height);
+
+ if ( size != ci->size1 )
+ {
+ av_free( ci->buf1 );
+ ci->buf1 = av_malloc(size);
+ ci->size1 = size;
+ err = ci->buf1 == NULL;
+ }
+
+ if ( !err )
+ {
+ avpicture_fill(&picture1, ci->buf1, PIX_FMT_RGB24, width, height);
+
+ // if we already got a SWS context, let's realloc if is not re-useable
+ ci->toRGB_convert_ctx = sws_getCachedContext(ci->toRGB_convert_ctx,
+ width, height, pix_fmt,
+ width, height, PIX_FMT_RGB24,
+ sws_flags, NULL, NULL, NULL);
+ if (ci->toRGB_convert_ctx == NULL) {
+ av_log(NULL, AV_LOG_ERROR,
+ "Cannot initialize the toRGB conversion context\n");
+ return;
+ }
+
+// img_convert parameters are 2 first destination, then 4 source
+// sws_scale parameters are context, 4 first source, then 2 destination
+ sws_scale(ci->toRGB_convert_ctx,
+ picture->data, picture->linesize, 0, height,
+ picture1.data, picture1.linesize);
+
+ pict = &picture1;
+ }
+ }
+
+ /* Write out the PPM */
+ if ( !err )
+ {
+ ptr = pict->data[ 0 ];
+ fprintf( out, "P6\n%d %d\n255\n", width, height );
+ for ( i = 0; !err && i < height; i ++ )
+ {
+ err = !fwrite( ptr, width * 3, 1, out );
+ ptr += pict->linesize[ 0 ];
+ }
+ if ( !err )
+ err = fflush( out );
+ }
+
+ /* Read the PPM returned. */
+ if ( !err && !rwpipe_read_ppm_header( ci->rw, &out_width, &out_height ) )
+ {
+ int size = avpicture_get_size(PIX_FMT_RGB24, out_width, out_height);
+
+ if ( size != ci->size2 )
+ {
+ av_free( ci->buf2 );
+ ci->buf2 = av_malloc(size);
+ ci->size2 = size;
+ err = ci->buf2 == NULL;
+ }
+
+ if ( !err )
+ {
+ avpicture_fill(&picture2, ci->buf2, PIX_FMT_RGB24, out_width, out_height);
+ ptr = picture2.data[ 0 ];
+ for ( i = 0; !err && i < out_height; i ++ )
+ {
+ err = !fread( ptr, out_width * 3, 1, in );
+ ptr += picture2.linesize[ 0 ];
+ }
+ }
+ }
+
+ /* Convert the returned PPM back to the input format */
+ if ( !err )
+ {
+ /* The out_width/out_height returned from the PPM
+ * filter won't necessarily be the same as width and height
+ * but it will be scaled anyway to width/height.
+ */
+ av_log(NULL, AV_LOG_DEBUG,
+ "PPM vhook: Input dimensions: %d x %d Output dimensions: %d x %d\n",
+ width, height, out_width, out_height);
+ ci->fromRGB_convert_ctx = sws_getCachedContext(ci->fromRGB_convert_ctx,
+ out_width, out_height, PIX_FMT_RGB24,
+ width, height, pix_fmt,
+ sws_flags, NULL, NULL, NULL);
+ if (ci->fromRGB_convert_ctx == NULL) {
+ av_log(NULL, AV_LOG_ERROR,
+ "Cannot initialize the fromRGB conversion context\n");
+ return;
+ }
+
+// img_convert parameters are 2 first destination, then 4 source
+// sws_scale parameters are context, 4 first source, then 2 destination
+ sws_scale(ci->fromRGB_convert_ctx,
+ picture2.data, picture2.linesize, 0, out_height,
+ picture->data, picture->linesize);
+ }
+}
+
+/** Clean up the effect.
+*/
+
+void Release(void *ctx)
+{
+ ContextInfo *ci;
+ ci = (ContextInfo *) ctx;
+
+ if (ctx)
+ {
+ rwpipe_close( ci->rw );
+ av_free( ci->buf1 );
+ av_free( ci->buf2 );
+ sws_freeContext(ci->toRGB_convert_ctx);
+ sws_freeContext(ci->fromRGB_convert_ctx);
+ av_free(ctx);
+ }
+}
+
diff --git a/contrib/ffmpeg/vhook/watermark.c b/contrib/ffmpeg/vhook/watermark.c
new file mode 100644
index 000000000..aa6fee63c
--- /dev/null
+++ b/contrib/ffmpeg/vhook/watermark.c
@@ -0,0 +1,661 @@
+/*
+ * Watermark Hook
+ * Copyright (c) 2005 Marcus Engene myfirstname(at)mylastname.se
+ *
+ * parameters for watermark:
+ * -m nbr = nbr is 0..1. 0 is the default mode, see below.
+ * -t nbr = nbr is six digit hex. Threshold.
+ * -f file = file is the watermark image filename. You must specify this!
+ *
+ * MODE 0:
+ * The watermark picture works like this (assuming color intensities 0..0xff):
+ * Per color do this:
+ * If mask color is 0x80, no change to the original frame.
+ * If mask color is < 0x80 the abs difference is subtracted from the frame. If
+ * result < 0, result = 0
+ * If mask color is > 0x80 the abs difference is added to the frame. If result
+ * > 0xff, result = 0xff
+ *
+ * You can override the 0x80 level with the -t flag. E.g. if threshold is
+ * 000000 the color value of watermark is added to the destination.
+ *
+ * This way a mask that is visible both in light pictures and in dark can be
+ * made (fex by using a picture generated by Gimp and the bump map tool).
+ *
+ * An example watermark file is at
+ * http://engene.se/ffmpeg_watermark.gif
+ *
+ * MODE 1:
+ * Per color do this:
+ * If mask color > threshold color then the watermark pixel is used.
+ *
+ * Example usage:
+ * ffmpeg -i infile -vhook '/path/watermark.so -f wm.gif' -an out.mov
+ * ffmpeg -i infile -vhook '/path/watermark.so -f wm.gif -m 1 -t 222222' -an out.mov
+ *
+ * Note that the entire vhook argument is encapsulated in ''. This
+ * way, arguments to the vhook won't be mixed up with those for ffmpeg.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General 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 <stdlib.h>
+//#include <fcntl.h>
+#include <unistd.h>
+#include <stdarg.h>
+
+#include "common.h"
+#include "avformat.h"
+
+#include "framehook.h"
+#include "cmdutils.h"
+#include "swscale.h"
+
+static int sws_flags = SWS_BICUBIC;
+
+typedef struct {
+ char filename[2000];
+ int x_size;
+ int y_size;
+
+ /* get_watermark_picture() variables */
+ AVFormatContext *pFormatCtx;
+ const char *p_ext;
+ int videoStream;
+ int frameFinished;
+ AVCodecContext *pCodecCtx;
+ AVCodec *pCodec;
+ AVFrame *pFrame;
+ AVPacket packet;
+ int numBytes;
+ uint8_t *buffer;
+ int i;
+ AVInputFormat *file_iformat;
+ AVStream *st;
+ int is_done;
+ AVFrame *pFrameRGB;
+ int thrR;
+ int thrG;
+ int thrB;
+ int mode;
+
+ // This vhook first converts frame to RGB ...
+ struct SwsContext *toRGB_convert_ctx;
+ // ... then converts a watermark and applies it to the RGB frame ...
+ struct SwsContext *watermark_convert_ctx;
+ // ... and finally converts back frame from RGB to initial format
+ struct SwsContext *fromRGB_convert_ctx;
+} ContextInfo;
+
+int get_watermark_picture(ContextInfo *ci, int cleanup);
+
+
+/****************************************************************************
+ *
+ ****************************************************************************/
+void Release(void *ctx)
+{
+ ContextInfo *ci;
+ ci = (ContextInfo *) ctx;
+
+ if (ci) {
+ get_watermark_picture(ci, 1);
+ sws_freeContext(ci->toRGB_convert_ctx);
+ sws_freeContext(ci->watermark_convert_ctx);
+ sws_freeContext(ci->fromRGB_convert_ctx);
+ }
+ av_free(ctx);
+}
+
+
+/****************************************************************************
+ *
+ ****************************************************************************/
+int Configure(void **ctxp, int argc, char *argv[])
+{
+ ContextInfo *ci;
+ int c;
+ int tmp = 0;
+
+ if (0 == (*ctxp = av_mallocz(sizeof(ContextInfo)))) return -1;
+ ci = (ContextInfo *) *ctxp;
+
+ optind = 1;
+
+ // Struct is mallocz:ed so no need to reset.
+ ci->thrR = 0x80;
+ ci->thrG = 0x80;
+ ci->thrB = 0x80;
+
+ while ((c = getopt(argc, argv, "f:m:t:")) > 0) {
+ switch (c) {
+ case 'f':
+ strncpy(ci->filename, optarg, 1999);
+ ci->filename[1999] = 0;
+ break;
+ case 'm':
+ ci->mode = atoi(optarg);
+ break;
+ case 't':
+ if (1 != sscanf(optarg, "%x", &tmp)) {
+ av_log(NULL, AV_LOG_ERROR, "Watermark: argument to -t must be a 6 digit hex number\n");
+ return -1;
+ }
+ ci->thrR = (tmp >> 16) & 0xff;
+ ci->thrG = (tmp >> 8) & 0xff;
+ ci->thrB = (tmp >> 0) & 0xff;
+ break;
+ default:
+ av_log(NULL, AV_LOG_ERROR, "Watermark: Unrecognized argument '%s'\n", argv[optind]);
+ return -1;
+ }
+ }
+
+ //
+ if (0 == ci->filename[0]) {
+ av_log(NULL, AV_LOG_ERROR, "Watermark: There is no filename specified.\n");
+ return -1;
+ }
+
+ av_register_all();
+ return get_watermark_picture(ci, 0);
+}
+
+
+/****************************************************************************
+ * For mode 0 (the original one)
+ ****************************************************************************/
+static void Process0(void *ctx,
+ AVPicture *picture,
+ enum PixelFormat pix_fmt,
+ int src_width,
+ int src_height,
+ int64_t pts)
+{
+ ContextInfo *ci = (ContextInfo *) ctx;
+ char *buf = 0;
+ AVPicture picture1;
+ AVPicture *pict = picture;
+
+ AVFrame *pFrameRGB;
+ int xm_size;
+ int ym_size;
+
+ int x;
+ int y;
+ int offs, offsm;
+ int mpoffs;
+ uint32_t *p_pixel = 0;
+ uint32_t pixel_meck;
+ uint32_t pixel;
+ uint32_t pixelm;
+ int tmp;
+ int thrR = ci->thrR;
+ int thrG = ci->thrG;
+ int thrB = ci->thrB;
+
+ if (pix_fmt != PIX_FMT_RGB32) {
+ int size;
+
+ size = avpicture_get_size(PIX_FMT_RGB32, src_width, src_height);
+ buf = av_malloc(size);
+
+ avpicture_fill(&picture1, buf, PIX_FMT_RGB32, src_width, src_height);
+
+ // if we already got a SWS context, let's realloc if is not re-useable
+ ci->toRGB_convert_ctx = sws_getCachedContext(ci->toRGB_convert_ctx,
+ src_width, src_height, pix_fmt,
+ src_width, src_height, PIX_FMT_RGB32,
+ sws_flags, NULL, NULL, NULL);
+ if (ci->toRGB_convert_ctx == NULL) {
+ av_log(NULL, AV_LOG_ERROR,
+ "Cannot initialize the toRGB conversion context\n");
+ return;
+ }
+
+// img_convert parameters are 2 first destination, then 4 source
+// sws_scale parameters are context, 4 first source, then 2 destination
+ sws_scale(ci->toRGB_convert_ctx,
+ picture->data, picture->linesize, 0, src_height,
+ picture1.data, picture1.linesize);
+
+ pict = &picture1;
+ }
+
+ /* Insert filter code here */ /* ok */
+
+ // Get me next frame
+ if (0 > get_watermark_picture(ci, 0)) {
+ return;
+ }
+ // These are the three original static variables in the ffmpeg hack.
+ pFrameRGB = ci->pFrameRGB;
+ xm_size = ci->x_size;
+ ym_size = ci->y_size;
+
+ // I'll do the *4 => <<2 crap later. Most compilers understand that anyway.
+ // According to avcodec.h PIX_FMT_RGB32 is handled in endian specific manner.
+ for (y=0; y<src_height; y++) {
+ offs = y * (src_width * 4);
+ offsm = (((y * ym_size) / src_height) * 4) * xm_size; // offsm first in maskline. byteoffs!
+ for (x=0; x<src_width; x++) {
+ mpoffs = offsm + (((x * xm_size) / src_width) * 4);
+ p_pixel = (uint32_t *)&((pFrameRGB->data[0])[mpoffs]);
+ pixelm = *p_pixel;
+ p_pixel = (uint32_t *)&((pict->data[0])[offs]);
+ pixel = *p_pixel;
+// pixelm = *((uint32_t *)&(pFrameRGB->data[mpoffs]));
+ pixel_meck = pixel & 0xff000000;
+
+ // R
+ tmp = (int)((pixel >> 16) & 0xff) + (int)((pixelm >> 16) & 0xff) - thrR;
+ if (tmp > 255) tmp = 255;
+ if (tmp < 0) tmp = 0;
+ pixel_meck |= (tmp << 16) & 0xff0000;
+ // G
+ tmp = (int)((pixel >> 8) & 0xff) + (int)((pixelm >> 8) & 0xff) - thrG;
+ if (tmp > 255) tmp = 255;
+ if (tmp < 0) tmp = 0;
+ pixel_meck |= (tmp << 8) & 0xff00;
+ // B
+ tmp = (int)((pixel >> 0) & 0xff) + (int)((pixelm >> 0) & 0xff) - thrB;
+ if (tmp > 255) tmp = 255;
+ if (tmp < 0) tmp = 0;
+ pixel_meck |= (tmp << 0) & 0xff;
+
+
+ // test:
+ //pixel_meck = pixel & 0xff000000;
+ //pixel_meck |= (pixelm & 0x00ffffff);
+
+ *p_pixel = pixel_meck;
+
+ offs += 4;
+ } // foreach X
+ } // foreach Y
+
+
+
+
+ if (pix_fmt != PIX_FMT_RGB32) {
+ ci->fromRGB_convert_ctx = sws_getCachedContext(ci->fromRGB_convert_ctx,
+ src_width, src_height, PIX_FMT_RGB32,
+ src_width, src_height, pix_fmt,
+ sws_flags, NULL, NULL, NULL);
+ if (ci->fromRGB_convert_ctx == NULL) {
+ av_log(NULL, AV_LOG_ERROR,
+ "Cannot initialize the fromRGB conversion context\n");
+ return;
+ }
+// img_convert parameters are 2 first destination, then 4 source
+// sws_scale parameters are context, 4 first source, then 2 destination
+ sws_scale(ci->fromRGB_convert_ctx,
+ picture1.data, picture1.linesize, 0, src_height,
+ picture->data, picture->linesize);
+ }
+
+ av_free(buf);
+}
+
+
+/****************************************************************************
+ * For mode 1 (the original one)
+ ****************************************************************************/
+static void Process1(void *ctx,
+ AVPicture *picture,
+ enum PixelFormat pix_fmt,
+ int src_width,
+ int src_height,
+ int64_t pts)
+{
+ ContextInfo *ci = (ContextInfo *) ctx;
+ char *buf = 0;
+ AVPicture picture1;
+ AVPicture *pict = picture;
+
+ AVFrame *pFrameRGB;
+ int xm_size;
+ int ym_size;
+
+ int x;
+ int y;
+ int offs, offsm;
+ int mpoffs;
+ uint32_t *p_pixel = 0;
+ uint32_t pixel;
+ uint32_t pixelm;
+
+ if (pix_fmt != PIX_FMT_RGB32) {
+ int size;
+
+ size = avpicture_get_size(PIX_FMT_RGB32, src_width, src_height);
+ buf = av_malloc(size);
+
+ avpicture_fill(&picture1, buf, PIX_FMT_RGB32, src_width, src_height);
+
+ // if we already got a SWS context, let's realloc if is not re-useable
+ ci->toRGB_convert_ctx = sws_getCachedContext(ci->toRGB_convert_ctx,
+ src_width, src_height, pix_fmt,
+ src_width, src_height, PIX_FMT_RGB32,
+ sws_flags, NULL, NULL, NULL);
+ if (ci->toRGB_convert_ctx == NULL) {
+ av_log(NULL, AV_LOG_ERROR,
+ "Cannot initialize the toRGB conversion context\n");
+ return;
+ }
+
+// img_convert parameters are 2 first destination, then 4 source
+// sws_scale parameters are context, 4 first source, then 2 destination
+ sws_scale(ci->toRGB_convert_ctx,
+ picture->data, picture->linesize, 0, src_height,
+ picture1.data, picture1.linesize);
+
+ pict = &picture1;
+ }
+
+ /* Insert filter code here */ /* ok */
+
+ // Get me next frame
+ if (0 > get_watermark_picture(ci, 0)) {
+ return;
+ }
+ // These are the three original static variables in the ffmpeg hack.
+ pFrameRGB = ci->pFrameRGB;
+ xm_size = ci->x_size;
+ ym_size = ci->y_size;
+
+ // I'll do the *4 => <<2 crap later. Most compilers understand that anyway.
+ // According to avcodec.h PIX_FMT_RGB32 is handled in endian specific manner.
+ for (y=0; y<src_height; y++) {
+ offs = y * (src_width * 4);
+ offsm = (((y * ym_size) / src_height) * 4) * xm_size; // offsm first in maskline. byteoffs!
+ for (x=0; x<src_width; x++) {
+ mpoffs = offsm + (((x * xm_size) / src_width) * 4);
+ p_pixel = (uint32_t *)&((pFrameRGB->data[0])[mpoffs]);
+ pixelm = *p_pixel; /* watermark pixel */
+ p_pixel = (uint32_t *)&((pict->data[0])[offs]);
+ pixel = *p_pixel;
+
+ if (((pixelm >> 16) & 0xff) > ci->thrR ||
+ ((pixelm >> 8) & 0xff) > ci->thrG ||
+ ((pixelm >> 0) & 0xff) > ci->thrB)
+ {
+ *p_pixel = pixelm;
+ } else {
+ *p_pixel = pixel;
+ }
+ offs += 4;
+ } // foreach X
+ } // foreach Y
+
+ if (pix_fmt != PIX_FMT_RGB32) {
+ ci->fromRGB_convert_ctx = sws_getCachedContext(ci->fromRGB_convert_ctx,
+ src_width, src_height, PIX_FMT_RGB32,
+ src_width, src_height, pix_fmt,
+ sws_flags, NULL, NULL, NULL);
+ if (ci->fromRGB_convert_ctx == NULL) {
+ av_log(NULL, AV_LOG_ERROR,
+ "Cannot initialize the fromRGB conversion context\n");
+ return;
+ }
+// img_convert parameters are 2 first destination, then 4 source
+// sws_scale parameters are context, 4 first source, then 2 destination
+ sws_scale(ci->fromRGB_convert_ctx,
+ picture1.data, picture1.linesize, 0, src_height,
+ picture->data, picture->linesize);
+ }
+
+ av_free(buf);
+}
+
+
+/****************************************************************************
+ * This is the function ffmpeg.c callbacks.
+ ****************************************************************************/
+void Process(void *ctx,
+ AVPicture *picture,
+ enum PixelFormat pix_fmt,
+ int src_width,
+ int src_height,
+ int64_t pts)
+{
+ ContextInfo *ci = (ContextInfo *) ctx;
+ if (1 == ci->mode) {
+ return Process1(ctx, picture, pix_fmt, src_width, src_height, pts);
+ } else {
+ return Process0(ctx, picture, pix_fmt, src_width, src_height, pts);
+ }
+}
+
+
+/****************************************************************************
+ * When cleanup == 0, we try to get the next frame. If no next frame, nothing
+ * is done.
+ *
+ * This code follows the example on
+ * http://www.inb.uni-luebeck.de/~boehme/using_libavcodec.html
+ *
+ * 0 = ok, -1 = error
+ ****************************************************************************/
+int get_watermark_picture(ContextInfo *ci, int cleanup)
+{
+ if (1 == ci->is_done && 0 == cleanup) return 0;
+
+ // Yes, *pFrameRGB arguments must be null the first time otherwise it's not good..
+ // This block is only executed the first time we enter this function.
+ if (0 == ci->pFrameRGB &&
+ 0 == cleanup)
+ {
+
+ /*
+ * The last three parameters specify the file format, buffer size and format
+ * parameters; by simply specifying NULL or 0 we ask libavformat to auto-detect
+ * the format and use a default buffer size. (Didn't work!)
+ */
+ if (av_open_input_file(&ci->pFormatCtx, ci->filename, NULL, 0, NULL) != 0) {
+
+ // Martin says this should not be necessary but it failed for me sending in
+ // NULL instead of file_iformat to av_open_input_file()
+ ci->i = strlen(ci->filename);
+ if (0 == ci->i) {
+ av_log(NULL, AV_LOG_ERROR, "get_watermark_picture() No filename to watermark vhook\n");
+ return -1;
+ }
+ while (ci->i > 0) {
+ if (ci->filename[ci->i] == '.') {
+ ci->i++;
+ break;
+ }
+ ci->i--;
+ }
+ ci->p_ext = &(ci->filename[ci->i]);
+ ci->file_iformat = av_find_input_format (ci->p_ext);
+ if (0 == ci->file_iformat) {
+ av_log(NULL, AV_LOG_INFO, "get_watermark_picture() attempt to use image2 for [%s]\n", ci->p_ext);
+ ci->file_iformat = av_find_input_format ("image2");
+ }
+ if (0 == ci->file_iformat) {
+ av_log(NULL, AV_LOG_ERROR, "get_watermark_picture() Really failed to find iformat [%s]\n", ci->p_ext);
+ return -1;
+ }
+ // now continues the Martin template.
+
+ if (av_open_input_file(&ci->pFormatCtx, ci->filename, ci->file_iformat, 0, NULL)!=0) {
+ av_log(NULL, AV_LOG_ERROR, "get_watermark_picture() Failed to open input file [%s]\n", ci->filename);
+ return -1;
+ }
+ }
+
+ /*
+ * This fills the streams field of the AVFormatContext with valid information.
+ */
+ if(av_find_stream_info(ci->pFormatCtx)<0) {
+ av_log(NULL, AV_LOG_ERROR, "get_watermark_picture() Failed to find stream info\n");
+ return -1;
+ }
+
+ /*
+ * As mentioned in the introduction, we'll handle only video streams, not audio
+ * streams. To make things nice and easy, we simply use the first video stream we
+ * find.
+ */
+ ci->videoStream=-1;
+ for(ci->i = 0; ci->i < ci->pFormatCtx->nb_streams; ci->i++)
+ if(ci->pFormatCtx->streams[ci->i]->codec->codec_type==CODEC_TYPE_VIDEO)
+ {
+ ci->videoStream = ci->i;
+ break;
+ }
+ if(ci->videoStream == -1) {
+ av_log(NULL, AV_LOG_ERROR, "get_watermark_picture() Failed to find any video stream\n");
+ return -1;
+ }
+
+ ci->st = ci->pFormatCtx->streams[ci->videoStream];
+ ci->x_size = ci->st->codec->width;
+ ci->y_size = ci->st->codec->height;
+
+ // Get a pointer to the codec context for the video stream
+ ci->pCodecCtx = ci->pFormatCtx->streams[ci->videoStream]->codec;
+
+
+ /*
+ * OK, so now we've got a pointer to the so-called codec context for our video
+ * stream, but we still have to find the actual codec and open it.
+ */
+ // Find the decoder for the video stream
+ ci->pCodec = avcodec_find_decoder(ci->pCodecCtx->codec_id);
+ if(ci->pCodec == NULL) {
+ av_log(NULL, AV_LOG_ERROR, "get_watermark_picture() Failed to find any codec\n");
+ return -1;
+ }
+
+ // Inform the codec that we can handle truncated bitstreams -- i.e.,
+ // bitstreams where frame boundaries can fall in the middle of packets
+ if (ci->pCodec->capabilities & CODEC_CAP_TRUNCATED)
+ ci->pCodecCtx->flags|=CODEC_FLAG_TRUNCATED;
+
+ // Open codec
+ if(avcodec_open(ci->pCodecCtx, ci->pCodec)<0) {
+ av_log(NULL, AV_LOG_ERROR, "get_watermark_picture() Failed to open codec\n");
+ return -1;
+ }
+
+ // Hack to correct wrong frame rates that seem to be generated by some
+ // codecs
+ if (ci->pCodecCtx->time_base.den>1000 && ci->pCodecCtx->time_base.num==1)
+ ci->pCodecCtx->time_base.num=1000;
+
+ /*
+ * Allocate a video frame to store the decoded images in.
+ */
+ ci->pFrame = avcodec_alloc_frame();
+
+
+ /*
+ * The RGB image pFrameRGB (of type AVFrame *) is allocated like this:
+ */
+ // Allocate an AVFrame structure
+ ci->pFrameRGB=avcodec_alloc_frame();
+ if(ci->pFrameRGB==NULL) {
+ av_log(NULL, AV_LOG_ERROR, "get_watermark_picture() Failed to alloc pFrameRGB\n");
+ return -1;
+ }
+
+ // Determine required buffer size and allocate buffer
+ ci->numBytes = avpicture_get_size(PIX_FMT_RGB32, ci->pCodecCtx->width,
+ ci->pCodecCtx->height);
+ ci->buffer = av_malloc(ci->numBytes);
+
+ // Assign appropriate parts of buffer to image planes in pFrameRGB
+ avpicture_fill((AVPicture *)ci->pFrameRGB, ci->buffer, PIX_FMT_RGB32,
+ ci->pCodecCtx->width, ci->pCodecCtx->height);
+ }
+ // TODO loop, pingpong etc?
+ if (0 == cleanup)
+ {
+// av_log(NULL, AV_LOG_DEBUG, "get_watermark_picture() Get a frame\n");
+ while(av_read_frame(ci->pFormatCtx, &ci->packet)>=0)
+ {
+ // Is this a packet from the video stream?
+ if(ci->packet.stream_index == ci->videoStream)
+ {
+ // Decode video frame
+ avcodec_decode_video(ci->pCodecCtx, ci->pFrame, &ci->frameFinished,
+ ci->packet.data, ci->packet.size);
+
+ // Did we get a video frame?
+ if(ci->frameFinished)
+ {
+ // Convert the image from its native format to RGB32
+ ci->watermark_convert_ctx =
+ sws_getCachedContext(ci->watermark_convert_ctx,
+ ci->pCodecCtx->width, ci->pCodecCtx->height, ci->pCodecCtx->pix_fmt,
+ ci->pCodecCtx->width, ci->pCodecCtx->height, PIX_FMT_RGB32,
+ sws_flags, NULL, NULL, NULL);
+ if (ci->watermark_convert_ctx == NULL) {
+ av_log(NULL, AV_LOG_ERROR,
+ "Cannot initialize the watermark conversion context\n");
+ return -1;
+ }
+// img_convert parameters are 2 first destination, then 4 source
+// sws_scale parameters are context, 4 first source, then 2 destination
+ sws_scale(ci->watermark_convert_ctx,
+ ci->pFrame->data, ci->pFrame->linesize, 0, ci->pCodecCtx->height,
+ ci->pFrameRGB->data, ci->pFrameRGB->linesize);
+
+ // Process the video frame (save to disk etc.)
+ //fprintf(stderr,"banan() New frame!\n");
+ //DoSomethingWithTheImage(ci->pFrameRGB);
+ return 0;
+ }
+ }
+
+ // Free the packet that was allocated by av_read_frame
+ av_free_packet(&ci->packet);
+ }
+ ci->is_done = 1;
+ return 0;
+ } // if 0 != cleanup
+
+ if (0 != cleanup)
+ {
+ // Free the RGB image
+ av_freep(&ci->buffer);
+ av_freep(&ci->pFrameRGB);
+
+ // Close the codec
+ if (0 != ci->pCodecCtx) {
+ avcodec_close(ci->pCodecCtx);
+ ci->pCodecCtx = 0;
+ }
+
+ // Close the video file
+ if (0 != ci->pFormatCtx) {
+ av_close_input_file(ci->pFormatCtx);
+ ci->pFormatCtx = 0;
+ }
+
+ ci->is_done = 0;
+ }
+ return 0;
+}
+
+
+void parse_arg_file(const char *filename)
+{
+}
diff --git a/contrib/gsm610/Makefile.am b/contrib/gsm610/Makefile.am
new file mode 100644
index 000000000..f2011dfd4
--- /dev/null
+++ b/contrib/gsm610/Makefile.am
@@ -0,0 +1,26 @@
+include $(top_srcdir)/misc/Makefile.common
+
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+AM_LDFLAGS = $(xineplug_ldflags)
+
+noinst_LTLIBRARIES = libgsm610.la
+
+libgsm610_la_SOURCES = \
+ add.c \
+ decode.c \
+ gsm_create.c \
+ gsm_decode.c \
+ gsm_destroy.c \
+ long_term.c \
+ lpc.c \
+ rpe.c \
+ short_term.c \
+ table.c
+
+
+noinst_HEADERS = \
+ gsm_config.h \
+ gsm.h \
+ private.h \
+ proto.h \
+ unproto.h
diff --git a/src/libxineadec/gsm610/add.c b/contrib/gsm610/add.c
index cd4b5dd3b..cd4b5dd3b 100644
--- a/src/libxineadec/gsm610/add.c
+++ b/contrib/gsm610/add.c
diff --git a/src/libxineadec/gsm610/decode.c b/contrib/gsm610/decode.c
index 66dcab665..66dcab665 100644
--- a/src/libxineadec/gsm610/decode.c
+++ b/contrib/gsm610/decode.c
diff --git a/src/libxineadec/gsm610/gsm.h b/contrib/gsm610/gsm.h
index 34ad8f7a5..34ad8f7a5 100644
--- a/src/libxineadec/gsm610/gsm.h
+++ b/contrib/gsm610/gsm.h
diff --git a/src/libxineadec/gsm610/gsm_config.h b/contrib/gsm610/gsm_config.h
index a40004221..a40004221 100644
--- a/src/libxineadec/gsm610/gsm_config.h
+++ b/contrib/gsm610/gsm_config.h
diff --git a/src/libxineadec/gsm610/gsm_create.c b/contrib/gsm610/gsm_create.c
index df80758f0..df80758f0 100644
--- a/src/libxineadec/gsm610/gsm_create.c
+++ b/contrib/gsm610/gsm_create.c
diff --git a/src/libxineadec/gsm610/gsm_decode.c b/contrib/gsm610/gsm_decode.c
index 849818c14..849818c14 100644
--- a/src/libxineadec/gsm610/gsm_decode.c
+++ b/contrib/gsm610/gsm_decode.c
diff --git a/src/libxineadec/gsm610/gsm_destroy.c b/contrib/gsm610/gsm_destroy.c
index 481a74660..481a74660 100644
--- a/src/libxineadec/gsm610/gsm_destroy.c
+++ b/contrib/gsm610/gsm_destroy.c
diff --git a/src/libxineadec/gsm610/long_term.c b/contrib/gsm610/long_term.c
index 625662e1f..625662e1f 100644
--- a/src/libxineadec/gsm610/long_term.c
+++ b/contrib/gsm610/long_term.c
diff --git a/src/libxineadec/gsm610/lpc.c b/contrib/gsm610/lpc.c
index 0f51fa55f..0f51fa55f 100644
--- a/src/libxineadec/gsm610/lpc.c
+++ b/contrib/gsm610/lpc.c
diff --git a/src/libxineadec/gsm610/private.h b/contrib/gsm610/private.h
index 33a5172b0..33a5172b0 100644
--- a/src/libxineadec/gsm610/private.h
+++ b/contrib/gsm610/private.h
diff --git a/src/libxineadec/gsm610/proto.h b/contrib/gsm610/proto.h
index a80ebf9e4..a80ebf9e4 100644
--- a/src/libxineadec/gsm610/proto.h
+++ b/contrib/gsm610/proto.h
diff --git a/src/libxineadec/gsm610/rpe.c b/contrib/gsm610/rpe.c
index 67d94d30e..67d94d30e 100644
--- a/src/libxineadec/gsm610/rpe.c
+++ b/contrib/gsm610/rpe.c
diff --git a/src/libxineadec/gsm610/short_term.c b/contrib/gsm610/short_term.c
index 8222b2caa..8222b2caa 100644
--- a/src/libxineadec/gsm610/short_term.c
+++ b/contrib/gsm610/short_term.c
diff --git a/src/libxineadec/gsm610/table.c b/contrib/gsm610/table.c
index 797685c07..797685c07 100644
--- a/src/libxineadec/gsm610/table.c
+++ b/contrib/gsm610/table.c
diff --git a/src/libxineadec/gsm610/unproto.h b/contrib/gsm610/unproto.h
index f49530c22..f49530c22 100644
--- a/src/libxineadec/gsm610/unproto.h
+++ b/contrib/gsm610/unproto.h
diff --git a/contrib/libdca/COPYING b/contrib/libdca/COPYING
new file mode 100644
index 000000000..d511905c1
--- /dev/null
+++ b/contrib/libdca/COPYING
@@ -0,0 +1,339 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.
diff --git a/contrib/libdca/Makefile.am b/contrib/libdca/Makefile.am
new file mode 100644
index 000000000..faab0dd14
--- /dev/null
+++ b/contrib/libdca/Makefile.am
@@ -0,0 +1,16 @@
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+
+EXTRA_DIST = COPYING
+
+if ENABLE_DTS
+if !WITH_EXTERNAL_LIBDTS
+noinst_LTLIBRARIES = libdca.la
+endif
+endif
+
+libdca_la_SOURCES = dca_internal.h tables.h tables_quantization.h \
+ tables_huffman.h tables_fir.h tables_adpcm.h tables_vq.h \
+ bitstream.h bitstream.c parse.c downmix.c \
+ include/dca.h include/dts.h
+libdca_la_LIBADD = -lm
+libdca_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/include
diff --git a/contrib/libdca/bitstream.c b/contrib/libdca/bitstream.c
new file mode 100644
index 000000000..b92714868
--- /dev/null
+++ b/contrib/libdca/bitstream.c
@@ -0,0 +1,112 @@
+/*
+ * bitstream.c
+ * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
+ * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
+ * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ *
+ * This file is part of libdca, a free DTS Coherent Acoustics stream decoder.
+ * See http://www.videolan.org/developers/libdca.html for updates.
+ *
+ * libdca 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.
+ *
+ * libdca is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include <inttypes.h>
+
+#include "dca.h"
+#include "dca_internal.h"
+#include "bitstream.h"
+
+#define BUFFER_SIZE 4096
+
+void dca_bitstream_init (dca_state_t * state, uint8_t * buf, int word_mode,
+ int bigendian_mode)
+{
+ intptr_t align;
+
+ align = (uintptr_t)buf & 3;
+ state->buffer_start = (uint32_t *) ((uintptr_t)buf - align);
+ state->bits_left = 0;
+ state->current_word = 0;
+ state->word_mode = word_mode;
+ state->bigendian_mode = bigendian_mode;
+ bitstream_get (state, align * 8);
+}
+#include<stdio.h>
+static inline void bitstream_fill_current (dca_state_t * state)
+{
+ uint32_t tmp;
+
+ tmp = *(state->buffer_start++);
+
+ if (state->bigendian_mode)
+ state->current_word = swab32 (tmp);
+ else
+ state->current_word = swable32 (tmp);
+
+ if (!state->word_mode)
+ {
+ state->current_word = (state->current_word & 0x00003FFF) |
+ ((state->current_word & 0x3FFF0000 ) >> 2);
+ }
+}
+
+/*
+ * The fast paths for _get is in the
+ * bitstream.h header file so it can be inlined.
+ *
+ * The "bottom half" of this routine is suffixed _bh
+ *
+ * -ah
+ */
+
+uint32_t dca_bitstream_get_bh (dca_state_t * state, uint32_t num_bits)
+{
+ uint32_t result;
+
+ num_bits -= state->bits_left;
+
+ result = ((state->current_word << (32 - state->bits_left)) >>
+ (32 - state->bits_left));
+
+ if ( !state->word_mode && num_bits > 28 ) {
+ bitstream_fill_current (state);
+ result = (result << 28) | state->current_word;
+ num_bits -= 28;
+ }
+
+ bitstream_fill_current (state);
+
+ if ( state->word_mode )
+ {
+ if (num_bits != 0)
+ result = (result << num_bits) |
+ (state->current_word >> (32 - num_bits));
+
+ state->bits_left = 32 - num_bits;
+ }
+ else
+ {
+ if (num_bits != 0)
+ result = (result << num_bits) |
+ (state->current_word >> (28 - num_bits));
+
+ state->bits_left = 28 - num_bits;
+ }
+
+ return result;
+}
diff --git a/contrib/libdca/bitstream.h b/contrib/libdca/bitstream.h
new file mode 100644
index 000000000..4bce80aab
--- /dev/null
+++ b/contrib/libdca/bitstream.h
@@ -0,0 +1,68 @@
+/*
+ * bitstream.h
+ * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
+ * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
+ * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ *
+ * This file is part of libdca, a free DTS Coherent Acoustics stream decoder.
+ * See http://www.videolan.org/developers/libdca.html for updates.
+ *
+ * libdca 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.
+ *
+ * libdca is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef WORDS_BIGENDIAN
+
+# define swab32(x) (x)
+
+#else
+
+# define swab32(x)\
+((((uint8_t*)&x)[0] << 24) | (((uint8_t*)&x)[1] << 16) | \
+ (((uint8_t*)&x)[2] << 8) | (((uint8_t*)&x)[3]))
+
+#endif
+
+#ifdef WORDS_BIGENDIAN
+
+# define swable32(x)\
+((((uint8_t*)&x)[0] << 16) | (((uint8_t*)&x)[1] << 24) | \
+ (((uint8_t*)&x)[2]) | (((uint8_t*)&x)[3] << 8))
+
+#else
+
+# define swable32(x)\
+((((uint32_t)x) >> 16) | (((uint32_t)x) << 16))
+
+#endif
+
+void dca_bitstream_init (dca_state_t * state, uint8_t * buf, int word_mode,
+ int endian_mode);
+uint32_t dca_bitstream_get_bh (dca_state_t * state, uint32_t num_bits);
+
+static inline uint32_t bitstream_get (dca_state_t * state, uint32_t num_bits)
+{
+ uint32_t result;
+
+ if (num_bits < state->bits_left) {
+ result = (state->current_word << (32 - state->bits_left))
+ >> (32 - num_bits);
+
+ state->bits_left -= num_bits;
+ return result;
+ }
+
+ return dca_bitstream_get_bh (state, num_bits);
+}
diff --git a/contrib/libdca/dca_internal.h b/contrib/libdca/dca_internal.h
new file mode 100644
index 000000000..2c43cf049
--- /dev/null
+++ b/contrib/libdca/dca_internal.h
@@ -0,0 +1,204 @@
+/*
+ * dca_internal.h
+ * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
+ * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
+ * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ *
+ * This file is part of libdca, a free DTS Coherent Acoustics stream decoder.
+ * See http://www.videolan.org/developers/libdca.html for updates.
+ *
+ * libdca 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.
+ *
+ * libdca is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#define DCA_SUBFRAMES_MAX (16)
+#define DCA_PRIM_CHANNELS_MAX (5)
+#define DCA_SUBBANDS (32)
+#define DCA_ABITS_MAX (32) /* Should be 28 */
+#define DCA_SUBSUBFAMES_MAX (4)
+#define DCA_LFE_MAX (3)
+
+struct dca_state_s {
+
+ /* Frame header */
+ int frame_type; /* type of the current frame */
+ int samples_deficit; /* deficit sample count */
+ int crc_present; /* crc is present in the bitstream */
+ int sample_blocks; /* number of PCM sample blocks */
+ int frame_size; /* primary frame byte size */
+ int amode; /* audio channels arrangement */
+ int sample_rate; /* audio sampling rate */
+ int bit_rate; /* transmission bit rate */
+
+ int downmix; /* embedded downmix enabled */
+ int dynrange; /* embedded dynamic range flag */
+ int timestamp; /* embedded time stamp flag */
+ int aux_data; /* auxiliary data flag */
+ int hdcd; /* source material is mastered in HDCD */
+ int ext_descr; /* extension audio descriptor flag */
+ int ext_coding; /* extended coding flag */
+ int aspf; /* audio sync word insertion flag */
+ int lfe; /* low frequency effects flag */
+ int predictor_history; /* predictor history flag */
+ int header_crc; /* header crc check bytes */
+ int multirate_inter; /* multirate interpolator switch */
+ int version; /* encoder software revision */
+ int copy_history; /* copy history */
+ int source_pcm_res; /* source pcm resolution */
+ int front_sum; /* front sum/difference flag */
+ int surround_sum; /* surround sum/difference flag */
+ int dialog_norm; /* dialog normalisation parameter */
+
+ /* Primary audio coding header */
+ int subframes; /* number of subframes */
+ int prim_channels; /* number of primary audio channels */
+ /* subband activity count */
+ int subband_activity[DCA_PRIM_CHANNELS_MAX];
+ /* high frequency vq start subband */
+ int vq_start_subband[DCA_PRIM_CHANNELS_MAX];
+ /* joint intensity coding index */
+ int joint_intensity[DCA_PRIM_CHANNELS_MAX];
+ /* transient mode code book */
+ int transient_huffman[DCA_PRIM_CHANNELS_MAX];
+ /* scale factor code book */
+ int scalefactor_huffman[DCA_PRIM_CHANNELS_MAX];
+ /* bit allocation quantizer select */
+ int bitalloc_huffman[DCA_PRIM_CHANNELS_MAX];
+ /* quantization index codebook select */
+ int quant_index_huffman[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX];
+ /* scale factor adjustment */
+ float scalefactor_adj[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX];
+
+ /* Primary audio coding side information */
+ int subsubframes; /* number of subsubframes */
+ int partial_samples; /* partial subsubframe samples count */
+ /* prediction mode (ADPCM used or not) */
+ int prediction_mode[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS];
+ /* prediction VQ coefs */
+ int prediction_vq[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS];
+ /* bit allocation index */
+ int bitalloc[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS];
+ /* transition mode (transients) */
+ int transition_mode[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS];
+ /* scale factors (2 if transient)*/
+ int scale_factor[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][2];
+ /* joint subband scale factors codebook */
+ int joint_huff[DCA_PRIM_CHANNELS_MAX];
+ /* joint subband scale factors */
+ int joint_scale_factor[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS];
+ /* stereo downmix coefficients */
+ int downmix_coef[DCA_PRIM_CHANNELS_MAX][2];
+ /* dynamic range coefficient */
+ int dynrange_coef;
+
+ /* VQ encoded high frequency subbands */
+ int high_freq_vq[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS];
+
+ /* Low frequency effect data */
+ double lfe_data[2*DCA_SUBSUBFAMES_MAX*DCA_LFE_MAX * 2 /*history*/];
+ int lfe_scale_factor;
+
+ /* Subband samples history (for ADPCM) */
+ double subband_samples_hist[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][4];
+ double subband_fir_hist[DCA_PRIM_CHANNELS_MAX][512];
+ double subband_fir_noidea[DCA_PRIM_CHANNELS_MAX][64];
+
+ /* Audio output */
+ level_t clev; /* centre channel mix level */
+ level_t slev; /* surround channels mix level */
+
+ int output; /* type of output */
+ level_t level; /* output level */
+ sample_t bias; /* output bias */
+
+ sample_t * samples; /* pointer to the internal audio samples buffer */
+ int downmixed;
+
+ int dynrnge; /* apply dynamic range */
+ level_t dynrng; /* dynamic range */
+ void * dynrngdata; /* dynamic range callback funtion and data */
+ level_t (* dynrngcall) (level_t range, void * dynrngdata);
+
+ /* Bitstream handling */
+ uint32_t * buffer_start;
+ uint32_t bits_left;
+ uint32_t current_word;
+ int word_mode; /* 16/14 bits word format (1 -> 16, 0 -> 14) */
+ int bigendian_mode; /* endianness (1 -> be, 0 -> le) */
+
+ /* Current position in DTS frame */
+ int current_subframe;
+ int current_subsubframe;
+
+ /* Pre-calculated cosine modulation coefs for the QMF */
+ double cos_mod[544];
+
+ /* Debug flag */
+ int debug_flag;
+};
+
+#define LEVEL_PLUS6DB 2.0
+#define LEVEL_PLUS3DB 1.4142135623730951
+#define LEVEL_3DB 0.7071067811865476
+#define LEVEL_45DB 0.5946035575013605
+#define LEVEL_6DB 0.5
+
+int dca_downmix_init (int input, int flags, level_t * level,
+ level_t clev, level_t slev);
+int dca_downmix_coeff (level_t * coeff, int acmod, int output, level_t level,
+ level_t clev, level_t slev);
+void dca_downmix (sample_t * samples, int acmod, int output, sample_t bias,
+ level_t clev, level_t slev);
+void dca_upmix (sample_t * samples, int acmod, int output);
+
+#define ROUND(x) ((int)((x) + ((x) > 0 ? 0.5 : -0.5)))
+
+#ifndef LIBDCA_FIXED
+
+typedef sample_t quantizer_t;
+#define SAMPLE(x) (x)
+#define LEVEL(x) (x)
+#define MUL(a,b) ((a) * (b))
+#define MUL_L(a,b) ((a) * (b))
+#define MUL_C(a,b) ((a) * (b))
+#define DIV(a,b) ((a) / (b))
+#define BIAS(x) ((x) + bias)
+
+#else /* LIBDCA_FIXED */
+
+typedef int16_t quantizer_t;
+#define SAMPLE(x) (sample_t)((x) * (1 << 30))
+#define LEVEL(x) (level_t)((x) * (1 << 26))
+
+#if 0
+#define MUL(a,b) ((int)(((int64_t)(a) * (b) + (1 << 29)) >> 30))
+#define MUL_L(a,b) ((int)(((int64_t)(a) * (b) + (1 << 25)) >> 26))
+#elif 1
+#define MUL(a,b) \
+({ int32_t _ta=(a), _tb=(b), _tc; \
+ _tc=(_ta & 0xffff)*(_tb >> 16)+(_ta >> 16)*(_tb & 0xffff); (int32_t)(((_tc >> 14))+ (((_ta >> 16)*(_tb >> 16)) << 2 )); })
+#define MUL_L(a,b) \
+({ int32_t _ta=(a), _tb=(b), _tc; \
+ _tc=(_ta & 0xffff)*(_tb >> 16)+(_ta >> 16)*(_tb & 0xffff); (int32_t)((_tc >> 10) + (((_ta >> 16)*(_tb >> 16)) << 6)); })
+#else
+#define MUL(a,b) (((a) >> 15) * ((b) >> 15))
+#define MUL_L(a,b) (((a) >> 13) * ((b) >> 13))
+#endif
+
+#define MUL_C(a,b) MUL_L (a, LEVEL (b))
+#define DIV(a,b) ((((int64_t)LEVEL (a)) << 26) / (b))
+#define BIAS(x) (x)
+
+#endif
diff --git a/contrib/libdca/downmix.c b/contrib/libdca/downmix.c
new file mode 100644
index 000000000..ff02127f4
--- /dev/null
+++ b/contrib/libdca/downmix.c
@@ -0,0 +1,694 @@
+/*
+ * downmix.c
+ * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
+ * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
+ * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ *
+ * This file is part of libdca, a free DTS Coherent Acoustics stream decoder.
+ * See http://www.videolan.org/developers/libdca.html for updates.
+ *
+ * libdca 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.
+ *
+ * libdca is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <inttypes.h>
+
+#include "dca.h"
+#include "dca_internal.h"
+
+#define CONVERT(acmod,output) (((output) << DCA_CHANNEL_BITS) + (acmod))
+
+int dca_downmix_init (int input, int flags, level_t * level,
+ level_t clev, level_t slev)
+{
+ static uint8_t table[11][10] = {
+ /* DCA_MONO */
+ {DCA_MONO, DCA_MONO, DCA_MONO, DCA_MONO,
+ DCA_MONO, DCA_MONO, DCA_MONO, DCA_MONO,
+ DCA_MONO, DCA_MONO},
+ /* DCA_CHANNEL */
+ {DCA_MONO, DCA_CHANNEL, DCA_STEREO, DCA_STEREO,
+ DCA_STEREO, DCA_STEREO, DCA_STEREO, DCA_STEREO,
+ DCA_STEREO, DCA_STEREO},
+ /* DCA_STEREO */
+ {DCA_MONO, DCA_CHANNEL, DCA_STEREO, DCA_STEREO,
+ DCA_STEREO, DCA_STEREO, DCA_STEREO, DCA_STEREO,
+ DCA_STEREO, DCA_STEREO},
+ /* DCA_STEREO_SUMDIFF */
+ {DCA_MONO, DCA_CHANNEL, DCA_STEREO, DCA_STEREO,
+ DCA_STEREO, DCA_STEREO, DCA_STEREO, DCA_STEREO,
+ DCA_STEREO, DCA_STEREO},
+ /* DCA_STEREO_TOTAL */
+ {DCA_MONO, DCA_CHANNEL, DCA_STEREO, DCA_STEREO,
+ DCA_STEREO, DCA_STEREO, DCA_STEREO, DCA_STEREO,
+ DCA_STEREO, DCA_STEREO},
+ /* DCA_3F */
+ {DCA_MONO, DCA_CHANNEL, DCA_STEREO, DCA_STEREO,
+ DCA_STEREO, DCA_3F, DCA_3F, DCA_3F,
+ DCA_3F, DCA_3F},
+ /* DCA_2F1R */
+ {DCA_MONO, DCA_CHANNEL, DCA_STEREO, DCA_STEREO,
+ DCA_STEREO, DCA_2F1R, DCA_2F1R, DCA_2F1R,
+ DCA_2F1R, DCA_2F1R},
+ /* DCA_3F1R */
+ {DCA_MONO, DCA_CHANNEL, DCA_STEREO, DCA_STEREO,
+ DCA_STEREO, DCA_3F, DCA_3F1R, DCA_3F1R,
+ DCA_3F1R, DCA_3F1R},
+ /* DCA_2F2R */
+ {DCA_MONO, DCA_CHANNEL, DCA_STEREO, DCA_STEREO,
+ DCA_STEREO, DCA_STEREO, DCA_2F2R, DCA_2F2R,
+ DCA_2F2R, DCA_2F2R},
+ /* DCA_3F2R */
+ {DCA_MONO, DCA_CHANNEL, DCA_STEREO, DCA_STEREO,
+ DCA_STEREO, DCA_3F, DCA_3F2R, DCA_3F2R,
+ DCA_3F2R, DCA_3F2R},
+ /* DCA_4F2R */
+ {DCA_MONO, DCA_CHANNEL, DCA_STEREO, DCA_STEREO,
+ DCA_STEREO, DCA_4F2R, DCA_4F2R, DCA_4F2R,
+ DCA_4F2R, DCA_4F2R},
+ };
+ int output;
+
+ output = flags & DCA_CHANNEL_MASK;
+
+ if (output > DCA_CHANNEL_MAX)
+ return -1;
+
+ output = table[output][input];
+
+ if (output == DCA_STEREO &&
+ (input == DCA_DOLBY || (input == DCA_3F && clev == LEVEL (LEVEL_3DB))))
+ output = DCA_DOLBY;
+
+ if (flags & DCA_ADJUST_LEVEL) {
+ level_t adjust;
+
+ switch (CONVERT (input & 7, output)) {
+
+ case CONVERT (DCA_3F, DCA_MONO):
+ adjust = DIV (LEVEL_3DB, LEVEL (1) + clev);
+ break;
+
+ case CONVERT (DCA_STEREO, DCA_MONO):
+ case CONVERT (DCA_2F2R, DCA_2F1R):
+ case CONVERT (DCA_3F2R, DCA_3F1R):
+ level_3db:
+ adjust = LEVEL (LEVEL_3DB);
+ break;
+
+ case CONVERT (DCA_3F2R, DCA_2F1R):
+ if (clev < LEVEL (LEVEL_PLUS3DB - 1))
+ goto level_3db;
+ /* break thru */
+ case CONVERT (DCA_3F, DCA_STEREO):
+ case CONVERT (DCA_3F1R, DCA_2F1R):
+ case CONVERT (DCA_3F1R, DCA_2F2R):
+ case CONVERT (DCA_3F2R, DCA_2F2R):
+ adjust = DIV (1, LEVEL (1) + clev);
+ break;
+
+ case CONVERT (DCA_2F1R, DCA_MONO):
+ adjust = DIV (LEVEL_PLUS3DB, LEVEL (2) + slev);
+ break;
+
+ case CONVERT (DCA_2F1R, DCA_STEREO):
+ case CONVERT (DCA_3F1R, DCA_3F):
+ adjust = DIV (1, LEVEL (1) + MUL_C (slev, LEVEL_3DB));
+ break;
+
+ case CONVERT (DCA_3F1R, DCA_MONO):
+ adjust = DIV (LEVEL_3DB, LEVEL (1) + clev + MUL_C (slev, 0.5));
+ break;
+
+ case CONVERT (DCA_3F1R, DCA_STEREO):
+ adjust = DIV (1, LEVEL (1) + clev + MUL_C (slev, LEVEL_3DB));
+ break;
+
+ case CONVERT (DCA_2F2R, DCA_MONO):
+ adjust = DIV (LEVEL_3DB, LEVEL (1) + slev);
+ break;
+
+ case CONVERT (DCA_2F2R, DCA_STEREO):
+ case CONVERT (DCA_3F2R, DCA_3F):
+ adjust = DIV (1, LEVEL (1) + slev);
+ break;
+
+ case CONVERT (DCA_3F2R, DCA_MONO):
+ adjust = DIV (LEVEL_3DB, LEVEL (1) + clev + slev);
+ break;
+
+ case CONVERT (DCA_3F2R, DCA_STEREO):
+ adjust = DIV (1, LEVEL (1) + clev + slev);
+ break;
+
+ case CONVERT (DCA_MONO, DCA_DOLBY):
+ adjust = LEVEL (LEVEL_PLUS3DB);
+ break;
+
+ case CONVERT (DCA_3F, DCA_DOLBY):
+ case CONVERT (DCA_2F1R, DCA_DOLBY):
+ adjust = LEVEL (1 / (1 + LEVEL_3DB));
+ break;
+
+ case CONVERT (DCA_3F1R, DCA_DOLBY):
+ case CONVERT (DCA_2F2R, DCA_DOLBY):
+ adjust = LEVEL (1 / (1 + 2 * LEVEL_3DB));
+ break;
+
+ case CONVERT (DCA_3F2R, DCA_DOLBY):
+ adjust = LEVEL (1 / (1 + 3 * LEVEL_3DB));
+ break;
+
+ default:
+ return output;
+ }
+
+ *level = MUL_L (*level, adjust);
+ }
+
+ return output;
+}
+
+int dca_downmix_coeff (level_t * coeff, int acmod, int output, level_t level,
+ level_t clev, level_t slev)
+{
+ level_t level_3db;
+
+ level_3db = MUL_C (level, LEVEL_3DB);
+
+ switch (CONVERT (acmod, output & DCA_CHANNEL_MASK)) {
+
+ case CONVERT (DCA_CHANNEL, DCA_CHANNEL):
+ case CONVERT (DCA_MONO, DCA_MONO):
+ case CONVERT (DCA_STEREO, DCA_STEREO):
+ case CONVERT (DCA_3F, DCA_3F):
+ case CONVERT (DCA_2F1R, DCA_2F1R):
+ case CONVERT (DCA_3F1R, DCA_3F1R):
+ case CONVERT (DCA_2F2R, DCA_2F2R):
+ case CONVERT (DCA_3F2R, DCA_3F2R):
+ case CONVERT (DCA_STEREO, DCA_DOLBY):
+ coeff[0] = coeff[1] = coeff[2] = coeff[3] = coeff[4] = level;
+ return 0;
+
+ case CONVERT (DCA_CHANNEL, DCA_MONO):
+ coeff[0] = coeff[1] = MUL_C (level, LEVEL_6DB);
+ return 3;
+
+ case CONVERT (DCA_STEREO, DCA_MONO):
+ coeff[0] = coeff[1] = level_3db;
+ return 3;
+
+ case CONVERT (DCA_3F, DCA_MONO):
+ coeff[0] = coeff[2] = level_3db;
+ coeff[1] = MUL_C (MUL_L (level_3db, clev), LEVEL_PLUS6DB);
+ return 7;
+
+ case CONVERT (DCA_2F1R, DCA_MONO):
+ coeff[0] = coeff[1] = level_3db;
+ coeff[2] = MUL_L (level_3db, slev);
+ return 7;
+
+ case CONVERT (DCA_2F2R, DCA_MONO):
+ coeff[0] = coeff[1] = level_3db;
+ coeff[2] = coeff[3] = MUL_L (level_3db, slev);
+ return 15;
+
+ case CONVERT (DCA_3F1R, DCA_MONO):
+ coeff[0] = coeff[2] = level_3db;
+ coeff[1] = MUL_C (MUL_L (level_3db, clev), LEVEL_PLUS6DB);
+ coeff[3] = MUL_L (level_3db, slev);
+ return 15;
+
+ case CONVERT (DCA_3F2R, DCA_MONO):
+ coeff[0] = coeff[2] = level_3db;
+ coeff[1] = MUL_C (MUL_L (level_3db, clev), LEVEL_PLUS6DB);
+ coeff[3] = coeff[4] = MUL_L (level_3db, slev);
+ return 31;
+
+ case CONVERT (DCA_MONO, DCA_DOLBY):
+ coeff[0] = level_3db;
+ return 0;
+
+ case CONVERT (DCA_3F, DCA_DOLBY):
+ coeff[0] = coeff[2] = coeff[3] = coeff[4] = level;
+ coeff[1] = level_3db;
+ return 7;
+
+ case CONVERT (DCA_3F, DCA_STEREO):
+ case CONVERT (DCA_3F1R, DCA_2F1R):
+ case CONVERT (DCA_3F2R, DCA_2F2R):
+ coeff[0] = coeff[2] = coeff[3] = coeff[4] = level;
+ coeff[1] = MUL_L (level, clev);
+ return 7;
+
+ case CONVERT (DCA_2F1R, DCA_DOLBY):
+ coeff[0] = coeff[1] = level;
+ coeff[2] = level_3db;
+ return 7;
+
+ case CONVERT (DCA_2F1R, DCA_STEREO):
+ coeff[0] = coeff[1] = level;
+ coeff[2] = MUL_L (level_3db, slev);
+ return 7;
+
+ case CONVERT (DCA_3F1R, DCA_DOLBY):
+ coeff[0] = coeff[2] = level;
+ coeff[1] = coeff[3] = level_3db;
+ return 15;
+
+ case CONVERT (DCA_3F1R, DCA_STEREO):
+ coeff[0] = coeff[2] = level;
+ coeff[1] = MUL_L (level, clev);
+ coeff[3] = MUL_L (level_3db, slev);
+ return 15;
+
+ case CONVERT (DCA_2F2R, DCA_DOLBY):
+ coeff[0] = coeff[1] = level;
+ coeff[2] = coeff[3] = level_3db;
+ return 15;
+
+ case CONVERT (DCA_2F2R, DCA_STEREO):
+ coeff[0] = coeff[1] = level;
+ coeff[2] = coeff[3] = MUL_L (level, slev);
+ return 15;
+
+ case CONVERT (DCA_3F2R, DCA_DOLBY):
+ coeff[0] = coeff[2] = level;
+ coeff[1] = coeff[3] = coeff[4] = level_3db;
+ return 31;
+
+ case CONVERT (DCA_3F2R, DCA_2F1R):
+ coeff[0] = coeff[2] = level;
+ coeff[1] = MUL_L (level, clev);
+ coeff[3] = coeff[4] = level_3db;
+ return 31;
+
+ case CONVERT (DCA_3F2R, DCA_STEREO):
+ coeff[0] = coeff[2] = level;
+ coeff[1] = MUL_L (level, clev);
+ coeff[3] = coeff[4] = MUL_L (level, slev);
+ return 31;
+
+ case CONVERT (DCA_3F1R, DCA_3F):
+ coeff[0] = coeff[1] = coeff[2] = level;
+ coeff[3] = MUL_L (level_3db, slev);
+ return 13;
+
+ case CONVERT (DCA_3F2R, DCA_3F):
+ coeff[0] = coeff[1] = coeff[2] = level;
+ coeff[3] = coeff[4] = MUL_L (level, slev);
+ return 29;
+
+ case CONVERT (DCA_2F2R, DCA_2F1R):
+ coeff[0] = coeff[1] = level;
+ coeff[2] = coeff[3] = level_3db;
+ return 12;
+
+ case CONVERT (DCA_3F2R, DCA_3F1R):
+ coeff[0] = coeff[1] = coeff[2] = level;
+ coeff[3] = coeff[4] = level_3db;
+ return 24;
+
+ case CONVERT (DCA_2F1R, DCA_2F2R):
+ coeff[0] = coeff[1] = level;
+ coeff[2] = level_3db;
+ return 0;
+
+ case CONVERT (DCA_3F1R, DCA_2F2R):
+ coeff[0] = coeff[2] = level;
+ coeff[1] = MUL_L (level, clev);
+ coeff[3] = level_3db;
+ return 7;
+
+ case CONVERT (DCA_3F1R, DCA_3F2R):
+ coeff[0] = coeff[1] = coeff[2] = level;
+ coeff[3] = level_3db;
+ return 0;
+ }
+
+ return -1; /* NOTREACHED */
+}
+
+static void mix2to1 (sample_t * dest, sample_t * src, sample_t bias)
+{
+ int i;
+
+ for (i = 0; i < 256; i++)
+ dest[i] += BIAS (src[i]);
+}
+
+static void mix3to1 (sample_t * samples, sample_t bias)
+{
+ int i;
+
+ for (i = 0; i < 256; i++)
+ samples[i] += BIAS (samples[i + 256] + samples[i + 512]);
+}
+
+static void mix4to1 (sample_t * samples, sample_t bias)
+{
+ int i;
+
+ for (i = 0; i < 256; i++)
+ samples[i] += BIAS (samples[i + 256] + samples[i + 512] +
+ samples[i + 768]);
+}
+
+static void mix5to1 (sample_t * samples, sample_t bias)
+{
+ int i;
+
+ for (i = 0; i < 256; i++)
+ samples[i] += BIAS (samples[i + 256] + samples[i + 512] +
+ samples[i + 768] + samples[i + 1024]);
+}
+
+static void mix3to2 (sample_t * samples, sample_t bias)
+{
+ int i;
+ sample_t common;
+
+ for (i = 0; i < 256; i++) {
+ common = BIAS (samples[i]);
+ samples[i] = samples[i + 256] + common;
+ samples[i + 256] = samples[i + 512] + common;
+ }
+}
+
+static void mix21to2 (sample_t * left, sample_t * right, sample_t bias)
+{
+ int i;
+ sample_t common;
+
+ for (i = 0; i < 256; i++) {
+ common = BIAS (right[i + 256]);
+ left[i] += common;
+ right[i] += common;
+ }
+}
+
+static void mix21toS (sample_t * samples, sample_t bias)
+{
+ int i;
+ sample_t surround;
+
+ for (i = 0; i < 256; i++) {
+ surround = samples[i + 512];
+ samples[i] += BIAS (-surround);
+ samples[i + 256] += BIAS (surround);
+ }
+}
+
+static void mix31to2 (sample_t * samples, sample_t bias)
+{
+ int i;
+ sample_t common;
+
+ for (i = 0; i < 256; i++) {
+ common = BIAS (samples[i] + samples[i + 768]);
+ samples[i] = samples[i + 256] + common;
+ samples[i + 256] = samples[i + 512] + common;
+ }
+}
+
+static void mix31toS (sample_t * samples, sample_t bias)
+{
+ int i;
+ sample_t common, surround;
+
+ for (i = 0; i < 256; i++) {
+ common = BIAS (samples[i]);
+ surround = samples[i + 768];
+ samples[i] = samples[i + 256] + common - surround;
+ samples[i + 256] = samples[i + 512] + common + surround;
+ }
+}
+
+static void mix22toS (sample_t * samples, sample_t bias)
+{
+ int i;
+ sample_t surround;
+
+ for (i = 0; i < 256; i++) {
+ surround = samples[i + 512] + samples[i + 768];
+ samples[i] += BIAS (-surround);
+ samples[i + 256] += BIAS (surround);
+ }
+}
+
+static void mix32to2 (sample_t * samples, sample_t bias)
+{
+ int i;
+ sample_t common;
+
+ for (i = 0; i < 256; i++) {
+ common = BIAS (samples[i]);
+ samples[i] = common + samples[i + 256] + samples[i + 768];
+ samples[i + 256] = common + samples[i + 512] + samples[i + 1024];
+ }
+}
+
+static void mix32toS (sample_t * samples, sample_t bias)
+{
+ int i;
+ sample_t common, surround;
+
+ for (i = 0; i < 256; i++) {
+ common = BIAS (samples[i]);
+ surround = samples[i + 768] + samples[i + 1024];
+ samples[i] = samples[i + 256] + common - surround;
+ samples[i + 256] = samples[i + 512] + common + surround;
+ }
+}
+
+static void move2to1 (sample_t * src, sample_t * dest, sample_t bias)
+{
+ int i;
+
+ for (i = 0; i < 256; i++)
+ dest[i] = BIAS (src[i] + src[i + 256]);
+}
+
+static void zero (sample_t * samples)
+{
+ int i;
+
+ for (i = 0; i < 256; i++)
+ samples[i] = 0;
+}
+
+void dca_downmix (sample_t * samples, int acmod, int output, sample_t bias,
+ level_t clev, level_t slev)
+{
+ (void)clev;
+
+ switch (CONVERT (acmod, output & DCA_CHANNEL_MASK)) {
+
+ case CONVERT (DCA_CHANNEL, DCA_MONO):
+ case CONVERT (DCA_STEREO, DCA_MONO):
+ mix_2to1:
+ mix2to1 (samples, samples + 256, bias);
+ break;
+
+ case CONVERT (DCA_2F1R, DCA_MONO):
+ if (slev == 0)
+ goto mix_2to1;
+ case CONVERT (DCA_3F, DCA_MONO):
+ mix_3to1:
+ mix3to1 (samples, bias);
+ break;
+
+ case CONVERT (DCA_3F1R, DCA_MONO):
+ if (slev == 0)
+ goto mix_3to1;
+ case CONVERT (DCA_2F2R, DCA_MONO):
+ if (slev == 0)
+ goto mix_2to1;
+ mix4to1 (samples, bias);
+ break;
+
+ case CONVERT (DCA_3F2R, DCA_MONO):
+ if (slev == 0)
+ goto mix_3to1;
+ mix5to1 (samples, bias);
+ break;
+
+ case CONVERT (DCA_MONO, DCA_DOLBY):
+ memcpy (samples + 256, samples, 256 * sizeof (sample_t));
+ break;
+
+ case CONVERT (DCA_3F, DCA_STEREO):
+ case CONVERT (DCA_3F, DCA_DOLBY):
+ mix_3to2:
+ mix3to2 (samples, bias);
+ break;
+
+ case CONVERT (DCA_2F1R, DCA_STEREO):
+ if (slev == 0)
+ break;
+ mix21to2 (samples, samples + 256, bias);
+ break;
+
+ case CONVERT (DCA_2F1R, DCA_DOLBY):
+ mix21toS (samples, bias);
+ break;
+
+ case CONVERT (DCA_3F1R, DCA_STEREO):
+ if (slev == 0)
+ goto mix_3to2;
+ mix31to2 (samples, bias);
+ break;
+
+ case CONVERT (DCA_3F1R, DCA_DOLBY):
+ mix31toS (samples, bias);
+ break;
+
+ case CONVERT (DCA_2F2R, DCA_STEREO):
+ if (slev == 0)
+ break;
+ mix2to1 (samples, samples + 512, bias);
+ mix2to1 (samples + 256, samples + 768, bias);
+ break;
+
+ case CONVERT (DCA_2F2R, DCA_DOLBY):
+ mix22toS (samples, bias);
+ break;
+
+ case CONVERT (DCA_3F2R, DCA_STEREO):
+ if (slev == 0)
+ goto mix_3to2;
+ mix32to2 (samples, bias);
+ break;
+
+ case CONVERT (DCA_3F2R, DCA_DOLBY):
+ mix32toS (samples, bias);
+ break;
+
+ case CONVERT (DCA_3F1R, DCA_3F):
+ if (slev == 0)
+ break;
+ mix21to2 (samples, samples + 512, bias);
+ break;
+
+ case CONVERT (DCA_3F2R, DCA_3F):
+ if (slev == 0)
+ break;
+ mix2to1 (samples, samples + 768, bias);
+ mix2to1 (samples + 512, samples + 1024, bias);
+ break;
+
+ case CONVERT (DCA_3F1R, DCA_2F1R):
+ mix3to2 (samples, bias);
+ memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
+ break;
+
+ case CONVERT (DCA_2F2R, DCA_2F1R):
+ mix2to1 (samples + 512, samples + 768, bias);
+ break;
+
+ case CONVERT (DCA_3F2R, DCA_2F1R):
+ mix3to2 (samples, bias);
+ move2to1 (samples + 768, samples + 512, bias);
+ break;
+
+ case CONVERT (DCA_3F2R, DCA_3F1R):
+ mix2to1 (samples + 768, samples + 1024, bias);
+ break;
+
+ case CONVERT (DCA_2F1R, DCA_2F2R):
+ memcpy (samples + 768, samples + 512, 256 * sizeof (sample_t));
+ break;
+
+ case CONVERT (DCA_3F1R, DCA_2F2R):
+ mix3to2 (samples, bias);
+ memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
+ break;
+
+ case CONVERT (DCA_3F2R, DCA_2F2R):
+ mix3to2 (samples, bias);
+ memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
+ memcpy (samples + 768, samples + 1024, 256 * sizeof (sample_t));
+ break;
+
+ case CONVERT (DCA_3F1R, DCA_3F2R):
+ memcpy (samples + 1024, samples + 768, 256 * sizeof (sample_t));
+ break;
+ }
+}
+
+void dca_upmix (sample_t * samples, int acmod, int output)
+{
+ switch (CONVERT (acmod, output & DCA_CHANNEL_MASK)) {
+
+ case CONVERT (DCA_3F2R, DCA_MONO):
+ zero (samples + 1024);
+ case CONVERT (DCA_3F1R, DCA_MONO):
+ case CONVERT (DCA_2F2R, DCA_MONO):
+ zero (samples + 768);
+ case CONVERT (DCA_3F, DCA_MONO):
+ case CONVERT (DCA_2F1R, DCA_MONO):
+ zero (samples + 512);
+ case CONVERT (DCA_CHANNEL, DCA_MONO):
+ case CONVERT (DCA_STEREO, DCA_MONO):
+ zero (samples + 256);
+ break;
+
+ case CONVERT (DCA_3F2R, DCA_STEREO):
+ case CONVERT (DCA_3F2R, DCA_DOLBY):
+ zero (samples + 1024);
+ case CONVERT (DCA_3F1R, DCA_STEREO):
+ case CONVERT (DCA_3F1R, DCA_DOLBY):
+ zero (samples + 768);
+ case CONVERT (DCA_3F, DCA_STEREO):
+ case CONVERT (DCA_3F, DCA_DOLBY):
+ mix_3to2:
+ memcpy (samples + 512, samples + 256, 256 * sizeof (sample_t));
+ zero (samples + 256);
+ break;
+
+ case CONVERT (DCA_2F2R, DCA_STEREO):
+ case CONVERT (DCA_2F2R, DCA_DOLBY):
+ zero (samples + 768);
+ case CONVERT (DCA_2F1R, DCA_STEREO):
+ case CONVERT (DCA_2F1R, DCA_DOLBY):
+ zero (samples + 512);
+ break;
+
+ case CONVERT (DCA_3F2R, DCA_3F):
+ zero (samples + 1024);
+ case CONVERT (DCA_3F1R, DCA_3F):
+ case CONVERT (DCA_2F2R, DCA_2F1R):
+ zero (samples + 768);
+ break;
+
+ case CONVERT (DCA_3F2R, DCA_3F1R):
+ zero (samples + 1024);
+ break;
+
+ case CONVERT (DCA_3F2R, DCA_2F1R):
+ zero (samples + 1024);
+ case CONVERT (DCA_3F1R, DCA_2F1R):
+ mix_31to21:
+ memcpy (samples + 768, samples + 512, 256 * sizeof (sample_t));
+ goto mix_3to2;
+
+ case CONVERT (DCA_3F2R, DCA_2F2R):
+ memcpy (samples + 1024, samples + 768, 256 * sizeof (sample_t));
+ goto mix_31to21;
+ }
+}
diff --git a/contrib/libdca/include/dca.h b/contrib/libdca/include/dca.h
new file mode 100644
index 000000000..00b837393
--- /dev/null
+++ b/contrib/libdca/include/dca.h
@@ -0,0 +1,86 @@
+/*
+ * dca.h
+ * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
+ *
+ * This file is part of libdca, a free DTS Coherent Acoustics stream decoder.
+ * See http://www.videolan.org/developers/libdca.html for updates.
+ *
+ * libdca 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.
+ *
+ * libdca is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef LIBDCA_DCA_H
+#define LIBDCA_DCA_H
+
+/* x86 accelerations */
+#define MM_ACCEL_X86_MMX 0x80000000
+#define MM_ACCEL_X86_3DNOW 0x40000000
+#define MM_ACCEL_X86_MMXEXT 0x20000000
+
+uint32_t mm_accel (void);
+
+#if defined(LIBDCA_FIXED)
+typedef int32_t sample_t;
+typedef int32_t level_t;
+#elif defined(LIBDCA_DOUBLE)
+typedef double sample_t;
+typedef double level_t;
+#else
+typedef float sample_t;
+typedef float level_t;
+#endif
+
+typedef struct dca_state_s dca_state_t;
+
+#define DCA_MONO 0
+#define DCA_CHANNEL 1
+#define DCA_STEREO 2
+#define DCA_STEREO_SUMDIFF 3
+#define DCA_STEREO_TOTAL 4
+#define DCA_3F 5
+#define DCA_2F1R 6
+#define DCA_3F1R 7
+#define DCA_2F2R 8
+#define DCA_3F2R 9
+#define DCA_4F2R 10
+
+#define DCA_DOLBY 101 /* FIXME */
+
+#define DCA_CHANNEL_MAX DCA_3F2R /* We don't handle anything above that */
+#define DCA_CHANNEL_BITS 6
+#define DCA_CHANNEL_MASK 0x3F
+
+#define DCA_LFE 0x80
+#define DCA_ADJUST_LEVEL 0x100
+
+dca_state_t * dca_init (uint32_t mm_accel);
+
+int dca_syncinfo (dca_state_t *state, uint8_t * buf, int * flags,
+ int * sample_rate, int * bit_rate, int *frame_length);
+
+int dca_frame (dca_state_t * state, uint8_t * buf, int * flags,
+ level_t * level, sample_t bias);
+
+void dca_dynrng (dca_state_t * state,
+ level_t (* call) (level_t, void *), void * data);
+
+int dca_blocks_num (dca_state_t * state);
+int dca_block (dca_state_t * state);
+
+sample_t * dca_samples (dca_state_t * state);
+
+void dca_free (dca_state_t * state);
+
+#endif /* LIBDCA_DCA_H */
diff --git a/contrib/libdca/include/dts.h b/contrib/libdca/include/dts.h
new file mode 100644
index 000000000..e6dc8b137
--- /dev/null
+++ b/contrib/libdca/include/dts.h
@@ -0,0 +1,55 @@
+/*
+ * dts.h
+ * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
+ *
+ * This file is part of libdca, a free DTS Coherent Acoustics stream decoder.
+ * See http://www.videolan.org/developers/libdca.html for updates.
+ *
+ * libdca 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.
+ *
+ * libdca is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef LIBDCA_COMPAT_H
+# define LIBDCA_COMPAT_H 1
+# include <dca.h>
+
+typedef struct dca_state_s dts_state_t;
+# define DTS_MONO DCA_MONO
+# define DTS_CHANNEL DCA_CHANNEL
+# define DTS_STEREO DCA_STEREO
+# define DTS_STEREO_SUMDIFF DCA_STEREO_SUMDIFF
+# define DTS_STEREO_TOTAL DCA_STEREO_TOTAL
+# define DTS_3F DCA_3F
+# define DTS_2F1R DCA_2F1R
+# define DTS_3F1R DCA_3F1R
+# define DTS_2F2R DCA_2F2R
+# define DTS_3F2R DCA_3F2R
+# define DTS_4F2R DCA_4F2R
+# define DTS_DOLBY DCA_DOLBY
+# define DTS_CHANNEL_MAX DCA_CHANNEL_MAX
+# define DTS_CHANNEL_BITS DCA_CHANNEL_BITS
+# define DTS_CHANNEL_MASK DCA_CHANNEL_MASK
+# define DTS_LFE DCA_LFE
+# define DTS_ADJUST_LEVEL DCA_ADJUST_LEVEL
+
+# define dts_init dca_init
+# define dts_syncinfo dca_syncinfo
+# define dts_frame dca_frame
+# define dts_dynrng dca_dynrng
+# define dts_blocks_num dca_blocks_num
+# define dts_block dca_block
+# define dts_samples dca_samples
+# define dts_free dca_free
+#endif
diff --git a/contrib/libdca/parse.c b/contrib/libdca/parse.c
new file mode 100644
index 000000000..5a0c95f17
--- /dev/null
+++ b/contrib/libdca/parse.c
@@ -0,0 +1,1292 @@
+/*
+ * parse.c
+ * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
+ *
+ * This file is part of libdca, a free DTS Coherent Acoustics stream decoder.
+ * See http://www.videolan.org/developers/libdca.html for updates.
+ *
+ * libdca 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.
+ *
+ * libdca is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include <math.h>
+
+#ifndef M_PI
+#define M_PI 3.1415926535897932384626433832795029
+#endif
+
+#include "dca.h"
+#include "dca_internal.h"
+#include "bitstream.h"
+
+#include "tables.h"
+#include "tables_huffman.h"
+#include "tables_quantization.h"
+#include "tables_adpcm.h"
+#include "tables_fir.h"
+#include "tables_vq.h"
+
+/* #define DEBUG */
+
+#if defined(HAVE_MEMALIGN) && !defined(__cplusplus)
+/* some systems have memalign() but no declaration for it */
+void * memalign (size_t align, size_t size);
+#else
+/* assume malloc alignment is sufficient */
+#define memalign(align,size) malloc (size)
+#endif
+
+static int decode_blockcode (int code, int levels, int *values);
+
+static void qmf_32_subbands (dca_state_t * state, int chans,
+ double samples_in[32][8], sample_t *samples_out,
+ double rScale, sample_t bias);
+
+static void lfe_interpolation_fir (int nDecimationSelect, int nNumDeciSample,
+ double *samples_in, sample_t *samples_out,
+ double rScale, sample_t bias );
+
+static void pre_calc_cosmod( dca_state_t * state );
+
+dca_state_t * dca_init (uint32_t mm_accel)
+{
+ dca_state_t * state;
+ int i;
+
+ (void)mm_accel;
+ state = (dca_state_t *) malloc (sizeof (dca_state_t));
+ if (state == NULL)
+ return NULL;
+
+ memset (state, 0, sizeof(dca_state_t));
+
+ state->samples = (sample_t *) memalign (16, 256 * 12 * sizeof (sample_t));
+ if (state->samples == NULL) {
+ free (state);
+ return NULL;
+ }
+
+ for (i = 0; i < 256 * 12; i++)
+ state->samples[i] = 0;
+
+ /* Pre-calculate cosine modulation coefficients */
+ pre_calc_cosmod( state );
+
+ state->downmixed = 1;
+
+ return state;
+}
+
+sample_t * dca_samples (dca_state_t * state)
+{
+ return state->samples;
+}
+
+int dca_blocks_num (dca_state_t * state)
+{
+ /* 8 samples per subsubframe and per subband */
+ return state->sample_blocks / 8;
+}
+
+static int syncinfo (dca_state_t * state, int * flags,
+ int * sample_rate, int * bit_rate, int * frame_length)
+{
+ int frame_size;
+
+ /* Sync code */
+ bitstream_get (state, 32);
+ /* Frame type */
+ bitstream_get (state, 1);
+ /* Samples deficit */
+ bitstream_get (state, 5);
+ /* CRC present */
+ bitstream_get (state, 1);
+
+ *frame_length = (bitstream_get (state, 7) + 1) * 32;
+ frame_size = bitstream_get (state, 14) + 1;
+ if (!state->word_mode) frame_size = frame_size * 8 / 14 * 2;
+
+ /* Audio channel arrangement */
+ *flags = bitstream_get (state, 6);
+ if (*flags > 63)
+ return 0;
+
+ *sample_rate = bitstream_get (state, 4);
+ if ((size_t)*sample_rate >= sizeof (dca_sample_rates) / sizeof (int))
+ return 0;
+ *sample_rate = dca_sample_rates[ *sample_rate ];
+ if (!*sample_rate) return 0;
+
+ *bit_rate = bitstream_get (state, 5);
+ if ((size_t)*bit_rate >= sizeof (dca_bit_rates) / sizeof (int))
+ return 0;
+ *bit_rate = dca_bit_rates[ *bit_rate ];
+ if (!*bit_rate) return 0;
+
+ /* LFE */
+ bitstream_get (state, 10);
+ if (bitstream_get (state, 2)) *flags |= DCA_LFE;
+
+ return frame_size;
+}
+
+int dca_syncinfo (dca_state_t * state, uint8_t * buf, int * flags,
+ int * sample_rate, int * bit_rate, int * frame_length)
+{
+ /*
+ * Look for sync code
+ */
+
+ /* 14 bits and little endian bitstream */
+ if (buf[0] == 0xff && buf[1] == 0x1f &&
+ buf[2] == 0x00 && buf[3] == 0xe8 &&
+ (buf[4] & 0xf0) == 0xf0 && buf[5] == 0x07)
+ {
+ int frame_size;
+ dca_bitstream_init (state, buf, 0, 0);
+ frame_size = syncinfo (state, flags, sample_rate,
+ bit_rate, frame_length);
+ return frame_size;
+ }
+
+ /* 14 bits and big endian bitstream */
+ if (buf[0] == 0x1f && buf[1] == 0xff &&
+ buf[2] == 0xe8 && buf[3] == 0x00 &&
+ buf[4] == 0x07 && (buf[5] & 0xf0) == 0xf0)
+ {
+ int frame_size;
+ dca_bitstream_init (state, buf, 0, 1);
+ frame_size = syncinfo (state, flags, sample_rate,
+ bit_rate, frame_length);
+ return frame_size;
+ }
+
+ /* 16 bits and little endian bitstream */
+ if (buf[0] == 0xfe && buf[1] == 0x7f &&
+ buf[2] == 0x01 && buf[3] == 0x80)
+ {
+ int frame_size;
+ dca_bitstream_init (state, buf, 1, 0);
+ frame_size = syncinfo (state, flags, sample_rate,
+ bit_rate, frame_length);
+ return frame_size;
+ }
+
+ /* 16 bits and big endian bitstream */
+ if (buf[0] == 0x7f && buf[1] == 0xfe &&
+ buf[2] == 0x80 && buf[3] == 0x01)
+ {
+ int frame_size;
+ dca_bitstream_init (state, buf, 1, 1);
+ frame_size = syncinfo (state, flags, sample_rate,
+ bit_rate, frame_length);
+ return frame_size;
+ }
+
+ return 0;
+}
+
+int dca_frame (dca_state_t * state, uint8_t * buf, int * flags,
+ level_t * level, sample_t bias)
+{
+ int i, j;
+ static float adj_table[] = { 1.0, 1.1250, 1.2500, 1.4375 };
+
+ dca_bitstream_init (state, buf, state->word_mode, state->bigendian_mode);
+
+ /* Sync code */
+ bitstream_get (state, 32);
+
+ /* Frame header */
+ state->frame_type = bitstream_get (state, 1);
+ state->samples_deficit = bitstream_get (state, 5) + 1;
+ state->crc_present = bitstream_get (state, 1);
+ state->sample_blocks = bitstream_get (state, 7) + 1;
+ state->frame_size = bitstream_get (state, 14) + 1;
+ state->amode = bitstream_get (state, 6);
+ state->sample_rate = bitstream_get (state, 4);
+ state->bit_rate = bitstream_get (state, 5);
+
+ state->downmix = bitstream_get (state, 1);
+ state->dynrange = bitstream_get (state, 1);
+ state->timestamp = bitstream_get (state, 1);
+ state->aux_data = bitstream_get (state, 1);
+ state->hdcd = bitstream_get (state, 1);
+ state->ext_descr = bitstream_get (state, 3);
+ state->ext_coding = bitstream_get (state, 1);
+ state->aspf = bitstream_get (state, 1);
+ state->lfe = bitstream_get (state, 2);
+ state->predictor_history = bitstream_get (state, 1);
+
+ /* TODO: check CRC */
+ if (state->crc_present) state->header_crc = bitstream_get (state, 16);
+
+ state->multirate_inter = bitstream_get (state, 1);
+ state->version = bitstream_get (state, 4);
+ state->copy_history = bitstream_get (state, 2);
+ state->source_pcm_res = bitstream_get (state, 3);
+ state->front_sum = bitstream_get (state, 1);
+ state->surround_sum = bitstream_get (state, 1);
+ state->dialog_norm = bitstream_get (state, 4);
+
+ /* FIME: channels mixing levels */
+ state->clev = state->slev = 1;
+ state->output = dca_downmix_init (state->amode, *flags, level,
+ state->clev, state->slev);
+ if (state->output < 0)
+ return 1;
+
+ if (state->lfe && (*flags & DCA_LFE))
+ state->output |= DCA_LFE;
+
+ *flags = state->output;
+
+ state->dynrng = state->level = MUL_C (*level, 2);
+ state->bias = bias;
+ state->dynrnge = 1;
+ state->dynrngcall = NULL;
+
+#ifdef DEBUG
+ fprintf (stderr, "frame type: %i\n", state->frame_type);
+ fprintf (stderr, "samples deficit: %i\n", state->samples_deficit);
+ fprintf (stderr, "crc present: %i\n", state->crc_present);
+ fprintf (stderr, "sample blocks: %i (%i samples)\n",
+ state->sample_blocks, state->sample_blocks * 32);
+ fprintf (stderr, "frame size: %i bytes\n", state->frame_size);
+ fprintf (stderr, "amode: %i (%i channels)\n",
+ state->amode, dca_channels[state->amode]);
+ fprintf (stderr, "sample rate: %i (%i Hz)\n",
+ state->sample_rate, dca_sample_rates[state->sample_rate]);
+ fprintf (stderr, "bit rate: %i (%i bits/s)\n",
+ state->bit_rate, dca_bit_rates[state->bit_rate]);
+ fprintf (stderr, "downmix: %i\n", state->downmix);
+ fprintf (stderr, "dynrange: %i\n", state->dynrange);
+ fprintf (stderr, "timestamp: %i\n", state->timestamp);
+ fprintf (stderr, "aux_data: %i\n", state->aux_data);
+ fprintf (stderr, "hdcd: %i\n", state->hdcd);
+ fprintf (stderr, "ext descr: %i\n", state->ext_descr);
+ fprintf (stderr, "ext coding: %i\n", state->ext_coding);
+ fprintf (stderr, "aspf: %i\n", state->aspf);
+ fprintf (stderr, "lfe: %i\n", state->lfe);
+ fprintf (stderr, "predictor history: %i\n", state->predictor_history);
+ fprintf (stderr, "header crc: %i\n", state->header_crc);
+ fprintf (stderr, "multirate inter: %i\n", state->multirate_inter);
+ fprintf (stderr, "version number: %i\n", state->version);
+ fprintf (stderr, "copy history: %i\n", state->copy_history);
+ fprintf (stderr, "source pcm resolution: %i (%i bits/sample)\n",
+ state->source_pcm_res,
+ dca_bits_per_sample[state->source_pcm_res]);
+ fprintf (stderr, "front sum: %i\n", state->front_sum);
+ fprintf (stderr, "surround sum: %i\n", state->surround_sum);
+ fprintf (stderr, "dialog norm: %i\n", state->dialog_norm);
+ fprintf (stderr, "\n");
+#endif
+
+ /* Primary audio coding header */
+ state->subframes = bitstream_get (state, 4) + 1;
+ state->prim_channels = bitstream_get (state, 3) + 1;
+
+#ifdef DEBUG
+ fprintf (stderr, "subframes: %i\n", state->subframes);
+ fprintf (stderr, "prim channels: %i\n", state->prim_channels);
+#endif
+
+ for (i = 0; i < state->prim_channels; i++)
+ {
+ state->subband_activity[i] = bitstream_get (state, 5) + 2;
+#ifdef DEBUG
+ fprintf (stderr, "subband activity: %i\n", state->subband_activity[i]);
+#endif
+ if (state->subband_activity[i] > DCA_SUBBANDS)
+ state->subband_activity[i] = DCA_SUBBANDS;
+ }
+ for (i = 0; i < state->prim_channels; i++)
+ {
+ state->vq_start_subband[i] = bitstream_get (state, 5) + 1;
+#ifdef DEBUG
+ fprintf (stderr, "vq start subband: %i\n", state->vq_start_subband[i]);
+#endif
+ if (state->vq_start_subband[i] > DCA_SUBBANDS)
+ state->vq_start_subband[i] = DCA_SUBBANDS;
+ }
+ for (i = 0; i < state->prim_channels; i++)
+ {
+ state->joint_intensity[i] = bitstream_get (state, 3);
+#ifdef DEBUG
+ fprintf (stderr, "joint intensity: %i\n", state->joint_intensity[i]);
+ if (state->joint_intensity[i]) {fprintf (stderr, "JOINTINTENSITY\n");}
+#endif
+ }
+ for (i = 0; i < state->prim_channels; i++)
+ {
+ state->transient_huffman[i] = bitstream_get (state, 2);
+#ifdef DEBUG
+ fprintf (stderr, "transient mode codebook: %i\n",
+ state->transient_huffman[i]);
+#endif
+ }
+ for (i = 0; i < state->prim_channels; i++)
+ {
+ state->scalefactor_huffman[i] = bitstream_get (state, 3);
+#ifdef DEBUG
+ fprintf (stderr, "scale factor codebook: %i\n",
+ state->scalefactor_huffman[i]);
+#endif
+ }
+ for (i = 0; i < state->prim_channels; i++)
+ {
+ state->bitalloc_huffman[i] = bitstream_get (state, 3);
+ /* if (state->bitalloc_huffman[i] == 7) bailout */
+#ifdef DEBUG
+ fprintf (stderr, "bit allocation quantizer: %i\n",
+ state->bitalloc_huffman[i]);
+#endif
+ }
+
+ /* Get codebooks quantization indexes */
+ for (i = 0; i < state->prim_channels; i++)
+ {
+ state->quant_index_huffman[i][0] = 0; /* Not transmitted */
+ state->quant_index_huffman[i][1] = bitstream_get (state, 1);
+ }
+ for (j = 2; j < 6; j++)
+ for (i = 0; i < state->prim_channels; i++)
+ state->quant_index_huffman[i][j] = bitstream_get (state, 2);
+ for (j = 6; j < 11; j++)
+ for (i = 0; i < state->prim_channels; i++)
+ state->quant_index_huffman[i][j] = bitstream_get (state, 3);
+ for (j = 11; j < 27; j++)
+ for (i = 0; i < state->prim_channels; i++)
+ state->quant_index_huffman[i][j] = 0; /* Not transmitted */
+
+#ifdef DEBUG
+ for (i = 0; i < state->prim_channels; i++)
+ {
+ fprintf( stderr, "quant index huff:" );
+ for (j = 0; j < 11; j++)
+ fprintf (stderr, " %i", state->quant_index_huffman[i][j]);
+ fprintf (stderr, "\n");
+ }
+#endif
+
+ /* Get scale factor adjustment */
+ for (j = 0; j < 11; j++)
+ {
+ for (i = 0; i < state->prim_channels; i++)
+ state->scalefactor_adj[i][j] = 1;
+ }
+ for (i = 0; i < state->prim_channels; i++)
+ {
+ if (state->quant_index_huffman[i][1] == 0)
+ {
+ /* Transmitted only if quant_index_huffman=0 (Huffman code used) */
+ state->scalefactor_adj[i][1] = adj_table[bitstream_get (state, 2)];
+ }
+ }
+ for (j = 2; j < 6; j++)
+ for (i = 0; i < state->prim_channels; i++)
+ if (state->quant_index_huffman[i][j] < 3)
+ {
+ /* Transmitted only if quant_index_huffman < 3 */
+ state->scalefactor_adj[i][j] =
+ adj_table[bitstream_get (state, 2)];
+ }
+ for (j = 6; j < 11; j++)
+ for (i = 0; i < state->prim_channels; i++)
+ if (state->quant_index_huffman[i][j] < 7)
+ {
+ /* Transmitted only if quant_index_huffman < 7 */
+ state->scalefactor_adj[i][j] =
+ adj_table[bitstream_get (state, 2)];
+ }
+
+#ifdef DEBUG
+ for (i = 0; i < state->prim_channels; i++)
+ {
+ fprintf (stderr, "scalefac adj:");
+ for (j = 0; j < 11; j++)
+ fprintf (stderr, " %1.3f", state->scalefactor_adj[i][j]);
+ fprintf (stderr, "\n");
+ }
+#endif
+
+ if (state->crc_present)
+ {
+ /* Audio header CRC check */
+ bitstream_get (state, 16);
+ }
+
+ state->current_subframe = 0;
+ state->current_subsubframe = 0;
+
+ return 0;
+}
+
+static int dca_subframe_header (dca_state_t * state)
+{
+ /* Primary audio coding side information */
+ int j, k;
+
+ /* Subsubframe count */
+ state->subsubframes = bitstream_get (state, 2) + 1;
+#ifdef DEBUG
+ fprintf (stderr, "subsubframes: %i\n", state->subsubframes);
+#endif
+
+ /* Partial subsubframe sample count */
+ state->partial_samples = bitstream_get (state, 3);
+#ifdef DEBUG
+ fprintf (stderr, "partial samples: %i\n", state->partial_samples);
+#endif
+
+ /* Get prediction mode for each subband */
+ for (j = 0; j < state->prim_channels; j++)
+ {
+ for (k = 0; k < state->subband_activity[j]; k++)
+ state->prediction_mode[j][k] = bitstream_get (state, 1);
+#ifdef DEBUG
+ fprintf (stderr, "prediction mode:");
+ for (k = 0; k < state->subband_activity[j]; k++)
+ fprintf (stderr, " %i", state->prediction_mode[j][k]);
+ fprintf (stderr, "\n");
+#endif
+ }
+
+ /* Get prediction codebook */
+ for (j = 0; j < state->prim_channels; j++)
+ {
+ for (k = 0; k < state->subband_activity[j]; k++)
+ {
+ if (state->prediction_mode[j][k] > 0)
+ {
+ /* (Prediction coefficient VQ address) */
+ state->prediction_vq[j][k] = bitstream_get (state, 12);
+#ifdef DEBUG
+ fprintf (stderr, "prediction coefs: %f, %f, %f, %f\n",
+ (double)adpcm_vb[state->prediction_vq[j][k]][0]/8192,
+ (double)adpcm_vb[state->prediction_vq[j][k]][1]/8192,
+ (double)adpcm_vb[state->prediction_vq[j][k]][2]/8192,
+ (double)adpcm_vb[state->prediction_vq[j][k]][3]/8192);
+#endif
+ }
+ }
+ }
+
+ /* Bit allocation index */
+ for (j = 0; j < state->prim_channels; j++)
+ {
+ for (k = 0; k < state->vq_start_subband[j]; k++)
+ {
+ if (state->bitalloc_huffman[j] == 6)
+ state->bitalloc[j][k] = bitstream_get (state, 5);
+ else if (state->bitalloc_huffman[j] == 5)
+ state->bitalloc[j][k] = bitstream_get (state, 4);
+ else
+ {
+ state->bitalloc[j][k] = InverseQ (state,
+ bitalloc_12[state->bitalloc_huffman[j]]);
+ }
+
+ if (state->bitalloc[j][k] > 26)
+ {
+ fprintf (stderr, "bitalloc index [%i][%i] too big (%i)\n",
+ j, k, state->bitalloc[j][k]);
+ return -1;
+ }
+ }
+
+#ifdef DEBUG
+ fprintf (stderr, "bitalloc index: ");
+ for (k = 0; k < state->vq_start_subband[j]; k++)
+ fprintf (stderr, "%2.2i ", state->bitalloc[j][k]);
+ fprintf (stderr, "\n");
+#endif
+ }
+
+ /* Transition mode */
+ for (j = 0; j < state->prim_channels; j++)
+ {
+ for (k = 0; k < state->subband_activity[j]; k++)
+ {
+ state->transition_mode[j][k] = 0;
+ if (state->subsubframes > 1 &&
+ k < state->vq_start_subband[j] &&
+ state->bitalloc[j][k] > 0)
+ {
+ state->transition_mode[j][k] = InverseQ (state,
+ tmode[state->transient_huffman[j]]);
+ }
+ }
+#ifdef DEBUG
+ fprintf (stderr, "Transition mode:");
+ for (k = 0; k < state->subband_activity[j]; k++)
+ fprintf (stderr, " %i", state->transition_mode[j][k]);
+ fprintf (stderr, "\n");
+#endif
+ }
+
+ /* Scale factors */
+ for (j = 0; j < state->prim_channels; j++)
+ {
+ int *scale_table;
+ int scale_sum;
+
+ for (k = 0; k < state->subband_activity[j]; k++)
+ {
+ state->scale_factor[j][k][0] = 0;
+ state->scale_factor[j][k][1] = 0;
+ }
+
+ if (state->scalefactor_huffman[j] == 6)
+ scale_table = scale_factor_quant7;
+ else
+ scale_table = scale_factor_quant6;
+
+ /* When huffman coded, only the difference is encoded */
+ scale_sum = 0;
+
+ for (k = 0; k < state->subband_activity[j]; k++)
+ {
+ if (k >= state->vq_start_subband[j] || state->bitalloc[j][k] > 0)
+ {
+ if (state->scalefactor_huffman[j] < 5)
+ {
+ /* huffman encoded */
+ scale_sum += InverseQ (state,
+ scales_129[state->scalefactor_huffman[j]]);
+ }
+ else if (state->scalefactor_huffman[j] == 5)
+ {
+ scale_sum = bitstream_get (state, 6);
+ }
+ else if (state->scalefactor_huffman[j] == 6)
+ {
+ scale_sum = bitstream_get (state, 7);
+ }
+
+ state->scale_factor[j][k][0] = scale_table[scale_sum];
+ }
+
+ if (k < state->vq_start_subband[j] && state->transition_mode[j][k])
+ {
+ /* Get second scale factor */
+ if (state->scalefactor_huffman[j] < 5)
+ {
+ /* huffman encoded */
+ scale_sum += InverseQ (state,
+ scales_129[state->scalefactor_huffman[j]]);
+ }
+ else if (state->scalefactor_huffman[j] == 5)
+ {
+ scale_sum = bitstream_get (state, 6);
+ }
+ else if (state->scalefactor_huffman[j] == 6)
+ {
+ scale_sum = bitstream_get (state, 7);
+ }
+
+ state->scale_factor[j][k][1] = scale_table[scale_sum];
+ }
+ }
+
+#ifdef DEBUG
+ fprintf (stderr, "Scale factor:");
+ for (k = 0; k < state->subband_activity[j]; k++)
+ {
+ if (k >= state->vq_start_subband[j] || state->bitalloc[j][k] > 0)
+ fprintf (stderr, " %i", state->scale_factor[j][k][0]);
+ if (k < state->vq_start_subband[j] && state->transition_mode[j][k])
+ fprintf (stderr, " %i(t)", state->scale_factor[j][k][1]);
+ }
+ fprintf (stderr, "\n");
+#endif
+ }
+
+ /* Joint subband scale factor codebook select */
+ for (j = 0; j < state->prim_channels; j++)
+ {
+ /* Transmitted only if joint subband coding enabled */
+ if (state->joint_intensity[j] > 0)
+ state->joint_huff[j] = bitstream_get (state, 3);
+ }
+
+ /* Scale factors for joint subband coding */
+ for (j = 0; j < state->prim_channels; j++)
+ {
+ int source_channel;
+
+ /* Transmitted only if joint subband coding enabled */
+ if (state->joint_intensity[j] > 0)
+ {
+ int scale = 0;
+ source_channel = state->joint_intensity[j] - 1;
+
+ /* When huffman coded, only the difference is encoded
+ * (is this valid as well for joint scales ???) */
+
+ for (k = state->subband_activity[j];
+ k < state->subband_activity[source_channel]; k++)
+ {
+ if (state->joint_huff[j] < 5)
+ {
+ /* huffman encoded */
+ scale = InverseQ (state,
+ scales_129[state->joint_huff[j]]);
+ }
+ else if (state->joint_huff[j] == 5)
+ {
+ scale = bitstream_get (state, 6);
+ }
+ else if (state->joint_huff[j] == 6)
+ {
+ scale = bitstream_get (state, 7);
+ }
+
+ scale += 64; /* bias */
+ state->joint_scale_factor[j][k] = scale;/*joint_scale_table[scale];*/
+ }
+
+ if (!state->debug_flag & 0x02)
+ {
+ fprintf (stderr, "Joint stereo coding not supported\n");
+ state->debug_flag |= 0x02;
+ }
+
+#ifdef DEBUG
+ fprintf (stderr, "Joint scale factor index:\n");
+ for (k = state->subband_activity[j];
+ k < state->subband_activity[source_channel]; k++)
+ fprintf (stderr, " %i", state->joint_scale_factor[j][k]);
+ fprintf (stderr, "\n");
+#endif
+ }
+ }
+
+ /* Stereo downmix coefficients */
+ if (state->prim_channels > 2 && state->downmix)
+ {
+ for (j = 0; j < state->prim_channels; j++)
+ {
+ state->downmix_coef[j][0] = bitstream_get (state, 7);
+ state->downmix_coef[j][1] = bitstream_get (state, 7);
+ }
+ }
+
+ /* Dynamic range coefficient */
+ if (state->dynrange) state->dynrange_coef = bitstream_get (state, 8);
+
+ /* Side information CRC check word */
+ if (state->crc_present)
+ {
+ bitstream_get (state, 16);
+ }
+
+ /*
+ * Primary audio data arrays
+ */
+
+ /* VQ encoded high frequency subbands */
+ for (j = 0; j < state->prim_channels; j++)
+ {
+ for (k = state->vq_start_subband[j];
+ k < state->subband_activity[j]; k++)
+ {
+ /* 1 vector -> 32 samples */
+ state->high_freq_vq[j][k] = bitstream_get (state, 10);
+
+#ifdef DEBUG
+ fprintf( stderr, "VQ index: %i\n", state->high_freq_vq[j][k] );
+#endif
+ }
+ }
+
+ /* Low frequency effect data */
+ if (state->lfe)
+ {
+ /* LFE samples */
+ int lfe_samples = 2 * state->lfe * state->subsubframes;
+ double lfe_scale;
+
+ for (j = lfe_samples; j < lfe_samples * 2; j++)
+ {
+ /* Signed 8 bits int */
+ state->lfe_data[j] =
+ (signed int)(signed char)bitstream_get (state, 8);
+ }
+
+ /* Scale factor index */
+ state->lfe_scale_factor =
+ scale_factor_quant7[bitstream_get (state, 8)];
+
+ /* Quantization step size * scale factor */
+ lfe_scale = 0.035 * state->lfe_scale_factor;
+
+ for (j = lfe_samples; j < lfe_samples * 2; j++)
+ state->lfe_data[j] *= lfe_scale;
+
+#ifdef DEBUG
+ fprintf (stderr, "LFE samples:\n");
+ for (j = lfe_samples; j < lfe_samples * 2; j++)
+ fprintf (stderr, " %f", state->lfe_data[j]);
+ fprintf (stderr, "\n");
+#endif
+
+ }
+
+ return 0;
+}
+
+static int dca_subsubframe (dca_state_t * state)
+{
+ int k, l;
+ int subsubframe = state->current_subsubframe;
+
+ double *quant_step_table;
+
+ /* FIXME */
+ double subband_samples[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][8];
+
+ /*
+ * Audio data
+ */
+
+ /* Select quantization step size table */
+ if (state->bit_rate == 0x1f)
+ quant_step_table = lossless_quant_d;
+ else
+ quant_step_table = lossy_quant_d;
+
+ for (k = 0; k < state->prim_channels; k++)
+ {
+ for (l = 0; l < state->vq_start_subband[k] ; l++)
+ {
+ int m;
+
+ /* Select the mid-tread linear quantizer */
+ int abits = state->bitalloc[k][l];
+
+ double quant_step_size = quant_step_table[abits];
+ double rscale;
+
+ /*
+ * Determine quantization index code book and its type
+ */
+
+ /* Select quantization index code book */
+ int sel = state->quant_index_huffman[k][abits];
+
+ /* Determine its type */
+ int q_type = 1; /* (Assume Huffman type by default) */
+ if (abits >= 11 || !bitalloc_select[abits][sel])
+ {
+ /* Not Huffman type */
+ if (abits <= 7) q_type = 3; /* Block code */
+ else q_type = 2; /* No further encoding */
+ }
+
+ if (abits == 0) q_type = 0; /* No bits allocated */
+
+ /*
+ * Extract bits from the bit stream
+ */
+ switch (q_type)
+ {
+ case 0: /* No bits allocated */
+ for (m=0; m<8; m++)
+ subband_samples[k][l][m] = 0;
+ break;
+
+ case 1: /* Huffman code */
+ for (m=0; m<8; m++)
+ subband_samples[k][l][m] =
+ InverseQ (state, bitalloc_select[abits][sel]);
+ break;
+
+ case 2: /* No further encoding */
+ for (m=0; m<8; m++)
+ {
+ /* Extract (signed) quantization index */
+ int q_index = bitstream_get (state, abits - 3);
+ if( q_index & (1 << (abits - 4)) )
+ {
+ q_index = (1 << (abits - 3)) - q_index;
+ q_index = -q_index;
+ }
+ subband_samples[k][l][m] = q_index;
+ }
+ break;
+
+ case 3: /* Block code */
+ {
+ int block_code1, block_code2, size, levels;
+ int block[8];
+
+ switch (abits)
+ {
+ case 1:
+ size = 7;
+ levels = 3;
+ break;
+ case 2:
+ size = 10;
+ levels = 5;
+ break;
+ case 3:
+ size = 12;
+ levels = 7;
+ break;
+ case 4:
+ size = 13;
+ levels = 9;
+ break;
+ case 5:
+ size = 15;
+ levels = 13;
+ break;
+ case 6:
+ size = 17;
+ levels = 17;
+ break;
+ case 7:
+ default:
+ size = 19;
+ levels = 25;
+ break;
+ }
+
+ block_code1 = bitstream_get (state, size);
+ /* Should test return value */
+ decode_blockcode (block_code1, levels, block);
+ block_code2 = bitstream_get (state, size);
+ decode_blockcode (block_code2, levels, &block[4]);
+ for (m=0; m<8; m++)
+ subband_samples[k][l][m] = block[m];
+
+ }
+ break;
+
+ default: /* Undefined */
+ fprintf (stderr, "Unknown quantization index codebook");
+ return -1;
+ }
+
+ /*
+ * Account for quantization step and scale factor
+ */
+
+ /* Deal with transients */
+ if (state->transition_mode[k][l] &&
+ subsubframe >= state->transition_mode[k][l])
+ rscale = quant_step_size * state->scale_factor[k][l][1];
+ else
+ rscale = quant_step_size * state->scale_factor[k][l][0];
+
+ /* Adjustment */
+ rscale *= state->scalefactor_adj[k][sel];
+ for (m=0; m<8; m++) subband_samples[k][l][m] *= rscale;
+
+ /*
+ * Inverse ADPCM if in prediction mode
+ */
+ if (state->prediction_mode[k][l])
+ {
+ int n;
+ for (m=0; m<8; m++)
+ {
+ for (n=1; n<=4; n++)
+ if (m-n >= 0)
+ subband_samples[k][l][m] +=
+ (adpcm_vb[state->prediction_vq[k][l]][n-1] *
+ subband_samples[k][l][m-n]/8192);
+ else if (state->predictor_history)
+ subband_samples[k][l][m] +=
+ (adpcm_vb[state->prediction_vq[k][l]][n-1] *
+ state->subband_samples_hist[k][l][m-n+4]/8192);
+ }
+ }
+ }
+
+ /*
+ * Decode VQ encoded high frequencies
+ */
+ for (l = state->vq_start_subband[k];
+ l < state->subband_activity[k]; l++)
+ {
+ /* 1 vector -> 32 samples but we only need the 8 samples
+ * for this subsubframe. */
+ int m;
+
+ if (!state->debug_flag & 0x01)
+ {
+ fprintf (stderr, "Stream with high frequencies VQ coding\n");
+ state->debug_flag |= 0x01;
+ }
+
+ for (m=0; m<8; m++)
+ {
+ subband_samples[k][l][m] =
+ high_freq_vq[state->high_freq_vq[k][l]][subsubframe*8+m]
+ * (double)state->scale_factor[k][l][0] / 16.0;
+ }
+ }
+ }
+
+ /* Check for DSYNC after subsubframe */
+ if (state->aspf || subsubframe == state->subsubframes - 1)
+ {
+ if (0xFFFF == bitstream_get (state, 16)) /* 0xFFFF */
+ {
+#ifdef DEBUG
+ fprintf( stderr, "Got subframe DSYNC\n" );
+#endif
+ }
+ else
+ {
+ fprintf( stderr, "Didn't get subframe DSYNC\n" );
+ }
+ }
+
+ /* Backup predictor history for adpcm */
+ for (k = 0; k < state->prim_channels; k++)
+ {
+ for (l = 0; l < state->vq_start_subband[k] ; l++)
+ {
+ int m;
+ for (m = 0; m < 4; m++)
+ state->subband_samples_hist[k][l][m] =
+ subband_samples[k][l][4+m];
+ }
+ }
+
+ /* 32 subbands QMF */
+ for (k = 0; k < state->prim_channels; k++)
+ {
+ /*static double pcm_to_float[8] =
+ {32768.0, 32768.0, 524288.0, 524288.0, 0, 8388608.0, 8388608.0};*/
+
+ qmf_32_subbands (state, k,
+ subband_samples[k],
+ &state->samples[256*k],
+ /*WTF ???*/ 32768.0*3/2/*pcm_to_float[state->source_pcm_res]*/,
+ 0/*state->bias*/);
+ }
+
+ /* Down/Up mixing */
+ if (state->prim_channels < dca_channels[state->output & DCA_CHANNEL_MASK])
+ {
+ dca_upmix (state->samples, state->amode, state->output);
+ } else
+ if (state->prim_channels > dca_channels[state->output & DCA_CHANNEL_MASK])
+ {
+ dca_downmix (state->samples, state->amode, state->output, state->bias,
+ state->clev, state->slev);
+ }
+
+ /* Generate LFE samples for this subsubframe FIXME!!! */
+ if (state->output & DCA_LFE)
+ {
+ int lfe_samples = 2 * state->lfe * state->subsubframes;
+ int i_channels = dca_channels[state->output & DCA_CHANNEL_MASK];
+
+ lfe_interpolation_fir (state->lfe, 2 * state->lfe,
+ state->lfe_data + lfe_samples +
+ 2 * state->lfe * subsubframe,
+ &state->samples[256*i_channels],
+ 8388608.0, state->bias);
+ /* Outputs 20bits pcm samples */
+ }
+
+ return 0;
+}
+
+static int dca_subframe_footer (dca_state_t * state)
+{
+ int aux_data_count = 0, i;
+ int lfe_samples;
+
+ /*
+ * Unpack optional information
+ */
+
+ /* Time code stamp */
+ if (state->timestamp) bitstream_get (state, 32);
+
+ /* Auxiliary data byte count */
+ if (state->aux_data) aux_data_count = bitstream_get (state, 6);
+
+ /* Auxiliary data bytes */
+ for(i = 0; i < aux_data_count; i++)
+ bitstream_get (state, 8);
+
+ /* Optional CRC check bytes */
+ if (state->crc_present && (state->downmix || state->dynrange))
+ bitstream_get (state, 16);
+
+ /* Backup LFE samples history */
+ lfe_samples = 2 * state->lfe * state->subsubframes;
+ for (i = 0; i < lfe_samples; i++)
+ {
+ state->lfe_data[i] = state->lfe_data[i+lfe_samples];
+ }
+
+#ifdef DEBUG
+ fprintf( stderr, "\n" );
+#endif
+
+ return 0;
+}
+
+int dca_block (dca_state_t * state)
+{
+ /* Sanity check */
+ if (state->current_subframe >= state->subframes)
+ {
+ fprintf (stderr, "check failed: %i>%i",
+ state->current_subframe, state->subframes);
+ return -1;
+ }
+
+ if (!state->current_subsubframe)
+ {
+#ifdef DEBUG
+ fprintf (stderr, "DSYNC dca_subframe_header\n");
+#endif
+ /* Read subframe header */
+ if (dca_subframe_header (state)) return -1;
+ }
+
+ /* Read subsubframe */
+#ifdef DEBUG
+ fprintf (stderr, "DSYNC dca_subsubframe\n");
+#endif
+ if (dca_subsubframe (state)) return -1;
+
+ /* Update state */
+ state->current_subsubframe++;
+ if (state->current_subsubframe >= state->subsubframes)
+ {
+ state->current_subsubframe = 0;
+ state->current_subframe++;
+ }
+ if (state->current_subframe >= state->subframes)
+ {
+#ifdef DEBUG
+ fprintf(stderr, "DSYNC dca_subframe_footer\n");
+#endif
+ /* Read subframe footer */
+ if (dca_subframe_footer (state)) return -1;
+ }
+
+ return 0;
+}
+
+/* Very compact version of the block code decoder that does not use table
+ * look-up but is slightly slower */
+int decode_blockcode( int code, int levels, int *values )
+{
+ int i;
+ int offset = (levels - 1) >> 1;
+
+ for (i = 0; i < 4; i++)
+ {
+ values[i] = (code % levels) - offset;
+ code /= levels;
+ }
+
+ if (code == 0)
+ return 1;
+ else
+ {
+ fprintf (stderr, "ERROR: block code look-up failed\n");
+ return 0;
+ }
+}
+
+static void pre_calc_cosmod( dca_state_t * state )
+{
+ int i, j, k;
+
+ for (j=0,k=0;k<16;k++)
+ for (i=0;i<16;i++)
+ state->cos_mod[j++] = cos((2*i+1)*(2*k+1)*M_PI/64);
+
+ for (k=0;k<16;k++)
+ for (i=0;i<16;i++)
+ state->cos_mod[j++] = cos((i)*(2*k+1)*M_PI/32);
+
+ for (k=0;k<16;k++)
+ state->cos_mod[j++] = 0.25/(2*cos((2*k+1)*M_PI/128));
+
+ for (k=0;k<16;k++)
+ state->cos_mod[j++] = -0.25/(2.0*sin((2*k+1)*M_PI/128));
+}
+
+static void qmf_32_subbands (dca_state_t * state, int chans,
+ double samples_in[32][8], sample_t *samples_out,
+ double scale, sample_t bias)
+{
+ double *prCoeff;
+ int i, j, k;
+ double raXin[32];
+
+ double *subband_fir_hist = state->subband_fir_hist[chans];
+ double *subband_fir_hist2 = state->subband_fir_noidea[chans];
+
+ int nChIndex = 0, NumSubband = 32, nStart = 0, nEnd = 8, nSubIndex;
+
+ /* Select filter */
+ if (!state->multirate_inter) /* Non-perfect reconstruction */
+ prCoeff = fir_32bands_nonperfect;
+ else /* Perfect reconstruction */
+ prCoeff = fir_32bands_perfect;
+
+ /* Reconstructed channel sample index */
+ for (nSubIndex=nStart; nSubIndex<nEnd; nSubIndex++)
+ {
+ double A[16], B[16], SUM[16], DIFF[16];
+
+ /* Load in one sample from each subband */
+ for (i=0; i<state->subband_activity[chans]; i++)
+ raXin[i] = samples_in[i][nSubIndex];
+
+ /* Clear inactive subbands */
+ for (i=state->subband_activity[chans]; i<NumSubband; i++)
+ raXin[i] = 0.0;
+
+ /* Multiply by cosine modulation coefficients and
+ * create temporary arrays SUM and DIFF */
+ for (j=0,k=0;k<16;k++)
+ {
+ A[k] = 0.0;
+ for (i=0;i<16;i++)
+ A[k]+=(raXin[2*i]+raXin[2*i+1])*state->cos_mod[j++];
+ }
+
+ for (k=0;k<16;k++)
+ {
+ B[k] = 0.0;
+ for (i=0;i<16;i++)
+ {
+ if(i>0) B[k]+=(raXin[2*i]+raXin[2*i-1])*state->cos_mod[j++];
+ else B[k]+=(raXin[2*i])*state->cos_mod[j++];
+ }
+ SUM[k]=A[k]+B[k];
+ DIFF[k]=A[k]-B[k];
+ }
+
+ /* Store history */
+ for (k=0;k<16;k++)
+ subband_fir_hist[k]=state->cos_mod[j++]*SUM[k];
+ for (k=0;k<16;k++)
+ subband_fir_hist[32-k-1]=state->cos_mod[j++]*DIFF[k];
+ /* Multiply by filter coefficients */
+ for (k=31,i=0;i<32;i++,k--)
+ for (j=0;j<512;j+=64)
+ subband_fir_hist2[i] += prCoeff[i+j]*
+ (subband_fir_hist[i+j] - subband_fir_hist[j+k]);
+ for (k=31,i=0;i<32;i++,k--)
+ for (j=0;j<512;j+=64)
+ subband_fir_hist2[32+i] += prCoeff[32+i+j]*
+ (-subband_fir_hist[i+j] - subband_fir_hist[j+k]);
+
+ /* Create 32 PCM output samples */
+ for (i=0;i<32;i++)
+ samples_out[nChIndex++] = subband_fir_hist2[i] / scale + bias;
+
+ /* Update working arrays */
+ for (i=511;i>=32;i--)
+ subband_fir_hist[i] = subband_fir_hist[i-32];
+ for (i=0;i<NumSubband;i++)
+ subband_fir_hist2[i] = subband_fir_hist2[i+32];
+ for (i=0;i<NumSubband;i++)
+ subband_fir_hist2[i+32] = 0.0;
+ }
+}
+
+static void lfe_interpolation_fir (int nDecimationSelect, int nNumDeciSample,
+ double *samples_in, sample_t *samples_out,
+ double scale, sample_t bias)
+{
+ /* samples_in: An array holding decimated samples.
+ * Samples in current subframe starts from samples_in[0],
+ * while samples_in[-1], samples_in[-2], ..., stores samples
+ * from last subframe as history.
+ *
+ * samples_out: An array holding interpolated samples
+ */
+
+ int nDeciFactor, k, J;
+ double *prCoeff;
+
+ int NumFIRCoef = 512; /* Number of FIR coefficients */
+ int nInterpIndex = 0; /* Index to the interpolated samples */
+ int nDeciIndex;
+
+ /* Select decimation filter */
+ if (nDecimationSelect==1)
+ {
+ /* 128 decimation */
+ nDeciFactor = 128;
+ /* Pointer to the FIR coefficients array */
+ prCoeff = lfe_fir_128;
+ } else {
+ /* 64 decimation */
+ nDeciFactor = 64;
+ prCoeff = lfe_fir_64;
+ }
+
+ /* Interpolation */
+ for (nDeciIndex=0; nDeciIndex<nNumDeciSample; nDeciIndex++)
+ {
+ /* One decimated sample generates nDeciFactor interpolated ones */
+ for (k=0; k<nDeciFactor; k++)
+ {
+ /* Clear accumulation */
+ double rTmp = 0.0;
+
+ /* Accumulate */
+ for (J=0; J<NumFIRCoef/nDeciFactor; J++)
+ rTmp += samples_in[nDeciIndex-J]*prCoeff[k+J*nDeciFactor];
+
+ /* Save interpolated samples */
+ samples_out[nInterpIndex++] = rTmp / scale + bias;
+ }
+ }
+}
+
+void dca_dynrng (dca_state_t * state,
+ level_t (* call) (level_t, void *), void * data)
+{
+ state->dynrange = 0;
+ if (call) {
+ state->dynrange = 1;
+ state->dynrngcall = call;
+ state->dynrngdata = data;
+ }
+}
+
+void dca_free (dca_state_t * state)
+{
+ free (state->samples);
+ free (state);
+}
diff --git a/contrib/libdca/tables.h b/contrib/libdca/tables.h
new file mode 100644
index 000000000..ca336cf29
--- /dev/null
+++ b/contrib/libdca/tables.h
@@ -0,0 +1,48 @@
+/*
+ * tables.h
+ * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
+ *
+ * This file is part of libdca, a free DTS Coherent Acoustics stream decoder.
+ * See http://www.videolan.org/developers/libdca.html for updates.
+ *
+ * libdca 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.
+ *
+ * libdca is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+static const int dca_sample_rates[] =
+{
+ 0, 8000, 16000, 32000, 0, 0, 11025, 22050, 44100, 0, 0,
+ 12000, 24000, 48000, 96000, 192000
+};
+
+static const int dca_bit_rates[] =
+{
+ 32000, 56000, 64000, 96000, 112000, 128000,
+ 192000, 224000, 256000, 320000, 384000,
+ 448000, 512000, 576000, 640000, 768000,
+ 896000, 1024000, 1152000, 1280000, 1344000,
+ 1408000, 1411200, 1472000, 1536000, 1920000,
+ 2048000, 3072000, 3840000, 1/*open*/, 2/*variable*/, 3/*lossless*/
+};
+
+static const uint8_t dca_channels[] =
+{
+ 1, 2, 2, 2, 2, 3, 3, 4, 4, 5, 6, 6, 6, 7, 8, 8
+};
+
+static const uint8_t dca_bits_per_sample[] =
+{
+ 16, 16, 20, 20, 0, 24, 24
+};
diff --git a/contrib/libdca/tables_adpcm.h b/contrib/libdca/tables_adpcm.h
new file mode 100644
index 000000000..c19378dab
--- /dev/null
+++ b/contrib/libdca/tables_adpcm.h
@@ -0,0 +1,4123 @@
+/*
+ * tables_adpcm.h
+ * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
+ *
+ * This file is part of libdca, a free DTS Coherent Acoustics stream decoder.
+ * See http://www.videolan.org/developers/libdca.html for updates.
+ *
+ * libdca 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.
+ *
+ * libdca is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/* 16bits signed fractional Q13 binary codes */
+static int16_t adpcm_vb[4096][4] =
+{
+ { 9928, -2618, -1093, -1263 },
+ { 11077, -2876, -1747, -308 },
+ { 10503, -1082, -1426, -1167 },
+ { 9337, -2403, -1495, 274 },
+ { 10698, -2529, -532, -1122 },
+ { 10368, -3974, -1264, -750 },
+ { 10070, -3667, 346, 863 },
+ { 10278, -3093, 311, -576 },
+ { 9894, -1330, -1428, -860 },
+ { 10544, -1923, -1058, -971 },
+ { 10996, -1632, -841, -1404 },
+ { 11832, -3465, 1658, -1990 },
+ { 10852, -688, -2658, -499 },
+ { 10546, -1749, -147, -1733 },
+ { 10801, -1004, -708, -1453 },
+ { 10588, -441, -2113, -952 },
+ { 10141, -3331, -582, -1432 },
+ { 9608, -2590, 383, 258 },
+ { 11422, -3265, 229, -1544 },
+ { 10460, -1338, -713, -1568 },
+ { 10306, -1721, -1660, -603 },
+ { 9580, -1812, -1235, -1061 },
+ { 11471, -2285, -1617, -607 },
+ { 10081, -2225, -1408, -868 },
+ { 10715, -2624, -1367, -704 },
+ { 10616, -1871, -2770, -35 },
+ { 9352, -2340, -1024, -1566 },
+ { 11065, -1458, -1926, -735 },
+ { 11334, -2056, -1041, -1144 },
+ { 9825, -2048, -794, -1536 },
+ { 11850, -2695, -1123, -867 },
+ { 10654, -2226, -1891, -373 },
+ { 10024, -1557, -808, -1069 },
+ { 11142, -1266, -3238, 128 },
+ { 11729, -3282, -514, -1011 },
+ { 11402, -2094, -2335, -189 },
+ { 10195, -3658, 181, -1875 },
+ { 11431, -2626, -404, -1377 },
+ { 11001, -3868, -619, -1077 },
+ { 10894, -2559, 274, -1758 },
+ { 9633, -1482, -2253, -773 },
+ { 11245, -3321, 830, -1972 },
+ { 9768, -2701, -199, -1859 },
+ { 10500, -2042, 525, -2043 },
+ { 11669, -4069, 293, -1468 },
+ { 9192, -1991, -583, -61 },
+ { 10057, -3220, -2015, -473 },
+ { 9497, -2315, -2490, -467 },
+ { 10455, -3069, -1194, -1007 },
+ { 9994, -1936, -60, -1225 },
+ { 9295, -2156, -1761, -1134 },
+ { 10085, -3748, -1026, 197 },
+ { 9334, -2360, 804, -351 },
+ { 11561, -2553, 1352, -2313 },
+ { 12837, -3998, 1195, -1958 },
+ { 10114, -1100, -2414, -394 },
+ { 9341, -2530, 315, 755 },
+ { 10131, -3164, 1411, -674 },
+ { 9535, -905, -1551, 579 },
+ { 11717, -1519, -3051, 91 },
+ { 9824, -2911, -2775, 192 },
+ { 9662, -2934, -561, 1450 },
+ { 11085, -3392, -1298, -659 },
+ { 8955, -2102, -1899, 703 },
+ { 8607, -1742, -4348, 814 },
+ { 7640, -2063, -3617, 52 },
+ { 7074, -826, -4325, 4375 },
+ { 7714, 584, -4238, 1927 },
+ { 6355, -952, -4912, 3127 },
+ { 7069, -660, -6413, 4087 },
+ { 8313, -132, -2964, -876 },
+ { 6952, -1422, -3962, -24 },
+ { 9299, -734, -3088, -263 },
+ { 9484, -574, -4513, 466 },
+ { 7246, -91, -3735, -704 },
+ { 8325, -1417, -3090, -530 },
+ { 6469, -1226, -4757, 829 },
+ { 6652, -368, -5682, 1393 },
+ { 7971, -1278, -2284, 1205 },
+ { 7229, -699, -3556, 1840 },
+ { 7994, 1284, -2729, 732 },
+ { 9005, -698, -4522, 2189 },
+ { 6963, 197, -2727, 380 },
+ { 8527, 135, -3991, -213 },
+ { 8840, 934, -3014, -567 },
+ { 10125, 418, -3284, -371 },
+ { 6367, 361, -2318, 2554 },
+ { 7892, 172, -5247, 4673 },
+ { 6674, 387, -5424, 4398 },
+ { 6240, 684, -4047, 1219 },
+ { 11170, -794, -5081, 1195 },
+ { 11765, -648, -6265, 2052 },
+ { 10845, -775, -3837, 366 },
+ { 12496, -689, -8260, 3562 },
+ { 7893, -1166, -4972, 988 },
+ { 8592, 1052, -5986, 3087 },
+ { 7277, 1874, -5685, 3579 },
+ { 6900, 2016, -4809, 3491 },
+ { 8530, -2405, -3250, 1986 },
+ { 9426, 494, -7067, 5038 },
+ { 10285, 564, -8210, 5370 },
+ { 8749, -2207, -3980, 2852 },
+ { 9653, -2686, -4300, 1400 },
+ { 9770, -2286, -5663, 4233 },
+ { 8490, -4, -7048, 4496 },
+ { 7697, -1209, -5328, 3183 },
+ { 6451, 801, -4324, -554 },
+ { 7387, 1806, -5265, 545 },
+ { 7450, -2302, -4445, 1418 },
+ { 8817, -1370, -5827, 2168 },
+ { 10324, -2406, -5629, 2579 },
+ { 8863, -2578, -3537, 467 },
+ { 6901, -1624, -3169, 3392 },
+ { 7846, 156, -6948, 3381 },
+ { 7928, -1115, -5972, 4816 },
+ { 6089, -599, -4368, -320 },
+ { 7833, 1246, -3960, -621 },
+ { 8931, 2521, -6768, 2052 },
+ { 8900, 1944, -4126, 40 },
+ { 7661, -34, -2855, 2480 },
+ { 5873, 474, -3262, 3712 },
+ { 7535, -234, -4699, 216 },
+ { 5856, 143, -5142, 73 },
+ { 8944, -106, -5874, 3663 },
+ { 7134, 426, -5879, 2895 },
+ { 10199, 1011, -4762, 369 },
+ { 8454, 264, -5971, 1291 },
+ { 7822, -2449, -4333, 4540 },
+ { 6200, -2758, -2632, 1497 },
+ { 6070, -4315, -2699, 414 },
+ { 7047, -3739, -3210, 1060 },
+ { 5675, -3801, -2717, -407 },
+ { 4789, -4063, -2628, -744 },
+ { 4023, -3366, -3133, -726 },
+ { 4296, -2407, -3381, -513 },
+ { 4388, -2931, -2820, 1512 },
+ { 4559, -4233, -1941, 1976 },
+ { 6702, -3208, -1755, 1680 },
+ { 4416, -3521, -1052, 2984 },
+ { 7154, -4266, -1203, 3732 },
+ { 3625, -4242, -3244, 1395 },
+ { 6518, -2856, -1304, 2887 },
+ { 6170, -1949, -3014, 3973 },
+ { 5189, -2451, -4020, 3477 },
+ { 6218, -2988, -1921, 3844 },
+ { 4827, -3688, -1928, 3343 },
+ { 6668, -3991, -2805, 3095 },
+ { 5297, -3115, -3684, 2390 },
+ { 5354, -4614, -2662, 1504 },
+ { 4196, -3091, -4147, 1135 },
+ { 3540, -2893, -4007, 100 },
+ { 5569, -1602, -4007, 1909 },
+ { 4341, -2091, -4272, 252 },
+ { 5559, -2878, -3832, 498 },
+ { 4548, -4479, -2898, -27 },
+ { 5176, -2494, -4635, 1476 },
+ { 3294, -3485, -3738, 716 },
+ { 4920, -1229, -4195, -365 },
+ { 3257, -3518, -3349, 2862 },
+ { 5286, -1948, -3485, -778 },
+ { 6502, -3051, -152, 2854 },
+ { 5864, -4192, -1076, 3451 },
+ { 4656, -3122, -3448, 179 },
+ { 5907, -754, -1596, 3116 },
+ { 7229, -3680, -1590, 2892 },
+ { 5107, -3888, -3364, 806 },
+ { 6764, -2635, -3450, 134 },
+ { 5258, -2827, -2844, -1052 },
+ { 5798, -1725, -4305, 205 },
+ { 5404, -1213, -3362, 449 },
+ { 6224, -2738, -3046, -581 },
+ { 4223, -2438, -2725, 3745 },
+ { 4751, -3411, -2123, 116 },
+ { 3868, -3000, -3954, 2297 },
+ { 6819, -2899, -4277, 2825 },
+ { 4207, -4754, -2808, 865 },
+ { 4804, -1494, -1997, 4688 },
+ { 5282, -2213, -548, 3559 },
+ { 5580, -1912, -566, 4370 },
+ { 6168, -2857, -672, 4053 },
+ { 6583, -4515, -2850, 1670 },
+ { 6511, -3093, -3988, 1421 },
+ { 4646, -1790, -1443, 3650 },
+ { 5915, -924, -2020, 896 },
+ { 7814, -4181, -3152, 2007 },
+ { 6190, -2238, -4817, 2279 },
+ { 4737, -4034, -3288, 1835 },
+ { 8161, -3633, -3423, 3137 },
+ { 7415, -2351, -2088, 4290 },
+ { 4106, -2517, -62, 2905 },
+ { 4909, -3145, -614, 4112 },
+ { 4938, -3281, -397, 1100 },
+ { -173, 919, 1589, -5363 },
+ { -13, 796, -295, -6655 },
+ { -1860, -829, 1141, -4555 },
+ { 2298, -838, -664, -5005 },
+ { -884, -1097, 2074, -4613 },
+ { -101, 281, 2846, -4535 },
+ { 1166, 453, 2429, -5910 },
+ { 879, -664, 2370, -5452 },
+ { 1415, -370, -1699, -4727 },
+ { -1413, 1277, -669, -6649 },
+ { 2133, 304, -968, -4624 },
+ { 380, 586, -2087, -4892 },
+ { 1336, 275, -82, -5789 },
+ { -2459, 1057, -34, -5416 },
+ { 2278, -1758, 866, -5653 },
+ { 1945, -2295, -149, -5302 },
+ { 1287, -3525, 996, -5255 },
+ { 2297, 803, 1177, -6067 },
+ { 187, -180, -619, -6202 },
+ { -793, -2537, 1554, -5057 },
+ { -2703, -204, -629, -5853 },
+ { -1007, -146, 313, -5582 },
+ { 830, 357, 869, -6363 },
+ { -228, -575, -3177, -4433 },
+ { -1001, -1553, -142, -5708 },
+ { -1644, 1683, 1721, -4533 },
+ { 893, 1924, -15, -5791 },
+ { 2195, 2061, -262, -5471 },
+ { 3031, 270, 311, -5096 },
+ { 1912, 1638, -1523, -4677 },
+ { -3142, -55, 253, -4914 },
+ { 356, -1680, 343, -6123 },
+ { -2241, -1734, -976, -5939 },
+ { -2196, -2893, 547, -4938 },
+ { -1245, 126, -1916, -5419 },
+ { -249, -3755, -1422, -5594 },
+ { 575, -2683, -1926, -4566 },
+ { -762, 1885, 192, -5880 },
+ { -811, -2562, -1068, -6013 },
+ { -2264, -3086, -976, -4775 },
+ { 70, -1215, 2880, -4410 },
+ { 714, -3760, 2916, -4691 },
+ { -244, -3404, 1740, -4493 },
+ { 684, -5137, -328, -5608 },
+ { -529, -3825, -1786, -4535 },
+ { -713, -4743, -1118, -5546 },
+ { 2718, -3788, 1798, -5708 },
+ { -1639, -3679, -1564, -6095 },
+ { 1693, -2642, -1389, -4539 },
+ { 505, -1573, -1651, -4878 },
+ { -835, -2256, -1941, -5352 },
+ { 1464, -411, 1993, -6441 },
+ { 493, -3184, -145, -6148 },
+ { -1413, 499, -1617, -6479 },
+ { -294, 1722, -1419, -5725 },
+ { -2937, -1528, -175, -4624 },
+ { -594, -5911, -56, -6146 },
+ { -300, -4275, 1156, -5947 },
+ { 552, -2643, 2669, -3959 },
+ { 905, -4158, 1789, -5809 },
+ { 1336, -2009, 2108, -5903 },
+ { 1555, -3600, 1110, -6759 },
+ { -1294, -3464, 77, -6084 },
+ { -1139, -4006, -1270, -4181 },
+ { -5094, -3296, 1092, -2847 },
+ { -5503, -2883, 1984, -2067 },
+ { -4671, -4218, -1417, -4132 },
+ { -3763, -3818, 1262, -3082 },
+ { -5132, -3430, 2928, -728 },
+ { -5957, -2877, 1251, -2446 },
+ { -4425, -2319, -212, -4276 },
+ { -6201, -1993, 1774, -2182 },
+ { -5500, -3836, 2201, -1396 },
+ { -6934, -2334, 2366, -1293 },
+ { -6124, -4140, 1337, -1977 },
+ { -6553, -4186, 1756, -1325 },
+ { -5126, -1258, 744, -3656 },
+ { -5167, -1390, 1581, -2895 },
+ { -4525, -3398, 2429, -1865 },
+ { -4076, -3183, 2027, -2510 },
+ { -6191, -3274, 1838, -1814 },
+ { -4454, -2753, 2723, -1185 },
+ { -6655, -4797, 251, -2595 },
+ { -6332, -2232, 1832, 217 },
+ { -5869, -1698, 134, 340 },
+ { -6614, -1045, 2126, -1932 },
+ { -4859, -2107, 2010, -2435 },
+ { -6274, -1622, 2808, -1374 },
+ { -3119, -3209, 521, -3988 },
+ { -5676, -2082, -420, -2711 },
+ { -7073, -3623, 696, -2343 },
+ { -5986, -4224, 572, -2454 },
+ { -4340, -4521, 882, -2771 },
+ { -6178, -1933, 535, -1444 },
+ { -4923, -4163, 1744, -2066 },
+ { -6410, -1519, 1058, -2683 },
+ { -5077, -1185, 856, -2216 },
+ { -7091, -2444, 687, -2597 },
+ { -5284, -2165, 3239, -993 },
+ { -4763, -1497, 197, -3179 },
+ { -4128, -4958, -396, -3578 },
+ { -5054, -3878, -647, -2672 },
+ { -7005, -3348, 1679, -1579 },
+ { -5767, -1017, 2582, -1915 },
+ { -7069, -2787, 1331, -2070 },
+ { -5532, -2296, 706, -2950 },
+ { -5059, -3543, -821, -3637 },
+ { -6639, -1835, 1016, -696 },
+ { -5611, -5220, -694, -3371 },
+ { -5994, -2803, 2933, -729 },
+ { -5948, -619, 1596, -2676 },
+ { -5486, -4419, 153, -3265 },
+ { -4329, -3440, 1646, -1439 },
+ { -4083, -3978, 177, -3569 },
+ { -4289, -2599, 1224, -3075 },
+ { -5707, -3253, 1912, -759 },
+ { -6606, -3437, 2562, -571 },
+ { -5254, -2444, 769, -352 },
+ { -6545, -3154, 582, -1103 },
+ { -5328, -2241, 2566, -1775 },
+ { -7216, -1936, 1538, -1983 },
+ { -3730, -2451, 426, -3869 },
+ { -5110, -1385, 2031, -1169 },
+ { -6470, -2715, 269, -3123 },
+ { -5806, -2480, -97, -3832 },
+ { -3683, -4916, -490, -4330 },
+ { -6341, -2083, -669, -115 },
+ { -4913, -4079, -837, -4673 },
+ { -3274, -2497, 2334, -2652 },
+ { -1286, -1731, 2550, -3756 },
+ { -3375, -877, 926, -3977 },
+ { -2525, -2079, 2879, -2625 },
+ { -5308, -504, 3111, -1607 },
+ { -4904, 460, 4093, -1232 },
+ { -1993, 1616, 4656, -1913 },
+ { -3481, -1176, 3119, -2236 },
+ { -4132, -1502, 2339, -2545 },
+ { -2542, 1151, 3569, -2550 },
+ { -4381, 430, 3147, -2082 },
+ { -3888, 867, 3899, -1657 },
+ { -2861, 1290, 4202, -1979 },
+ { -3893, -253, 2363, -2764 },
+ { -1705, 688, 3827, -2923 },
+ { -2223, 2312, 3700, -3148 },
+ { -1986, -720, 5021, -795 },
+ { -3177, 242, 1952, -3352 },
+ { -1854, 1509, 2528, -3815 },
+ { -3173, 97, 5019, -706 },
+ { -2689, -145, 1375, -3915 },
+ { -4838, -385, 2488, -2427 },
+ { -4557, -355, 1603, -3060 },
+ { -3522, 1832, 3292, -2674 },
+ { -3769, 780, 2378, -2704 },
+ { -4323, -1932, 3414, -1169 },
+ { -2740, 1158, 2729, -3273 },
+ { -3647, 210, 1464, -2892 },
+ { -2342, -2097, 1513, -3727 },
+ { -4422, -1242, 3130, -1833 },
+ { -1308, -1039, 4290, -1875 },
+ { -1754, -2535, 3298, -2314 },
+ { -4102, -186, 4037, -1094 },
+ { -1008, 1570, 3290, 171 },
+ { -3322, -2621, 2791, -1536 },
+ { -2539, -2597, 3442, -1672 },
+ { -3411, -2015, 3670, -1174 },
+ { -2097, 730, 5581, -1399 },
+ { -1510, -74, 4820, -2004 },
+ { -4086, -868, 4425, -771 },
+ { -956, -986, 3640, -2925 },
+ { -2087, -1250, 3464, -2458 },
+ { -3308, -2411, 1334, -3667 },
+ { -2264, -389, 4004, -1854 },
+ { -680, 239, 4058, -3388 },
+ { -1357, 30, 2993, -3658 },
+ { -3601, -552, 1177, -1136 },
+ { -2641, 442, 4374, -1625 },
+ { -2525, 770, 1640, -3895 },
+ { -3172, -891, 3893, -1608 },
+ { -2996, 13, 3277, -2414 },
+ { -899, 1055, 4470, -2501 },
+ { -422, -584, 3475, -3787 },
+ { -1978, -593, 2566, -3415 },
+ { -3150, -1280, 2362, -3047 },
+ { -3592, 224, 1026, -3932 },
+ { -4840, -1189, 3633, -879 },
+ { -3952, -2255, 2916, -1826 },
+ { -1695, 28, 1810, -349 },
+ { -745, -2484, 3308, -3293 },
+ { -1016, 1563, 5365, -1823 },
+ { -2172, -1787, 4266, -1287 },
+ { -1241, -1951, 3982, -2413 },
+ { -2009, -2639, 2330, -3480 },
+ { 5105, -1618, -2588, -2015 },
+ { 6497, -1523, -3218, -910 },
+ { 6526, -2305, -2029, -1790 },
+ { 5289, -99, -3436, -400 },
+ { 5781, -1623, -1577, -2617 },
+ { 5259, -670, -3125, -1700 },
+ { 6343, -1256, -331, -3222 },
+ { 7967, -678, -2195, -1462 },
+ { 6119, -695, -2988, -1538 },
+ { 6108, 494, -3359, -1548 },
+ { 5067, 969, -2328, -2707 },
+ { 7595, -435, -1497, -2056 },
+ { 6929, -719, -2420, -1665 },
+ { 5190, 584, -2982, -2103 },
+ { 6106, -444, -1411, -2739 },
+ { 5584, 289, -1804, -2803 },
+ { 5276, 227, -1180, -3361 },
+ { 7544, -1525, -1834, -1725 },
+ { 5986, -1470, -2606, -1701 },
+ { 5096, -765, -1712, -3006 },
+ { 5423, -149, -3933, -1157 },
+ { 7651, 26, -2445, -1507 },
+ { 4745, -464, -1735, -2362 },
+ { 5352, -1011, -1094, -1999 },
+ { 6300, -672, -542, -1950 },
+ { 6675, -1020, -1318, -1059 },
+ { 7218, -2036, -603, -2462 },
+ { 7755, -1514, -2430, -1229 },
+ { 5041, 449, -1056, -2405 },
+ { 6710, -2277, -1344, -2284 },
+ { 6824, -1347, -2254, 251 },
+ { 6068, -1857, -983, -1316 },
+ { 5603, -2177, -2730, -1477 },
+ { 5838, -1059, -3604, -970 },
+ { 5076, -789, -335, -2413 },
+ { 6191, -1634, -2000, -2129 },
+ { 5092, -1292, -2543, -1034 },
+ { 5305, 435, -1710, -1850 },
+ { 6140, 561, -2176, -2380 },
+ { 6752, 348, -2496, -1890 },
+ { 6405, 273, -1098, -2778 },
+ { 6942, -1340, -496, -1381 },
+ { 5238, -687, -2454, -2349 },
+ { 6959, -882, -1833, -2061 },
+ { 6292, -253, -2125, -2199 },
+ { 5838, -574, -759, -3215 },
+ { 6954, -1484, -640, -2771 },
+ { 7498, -1706, -1210, -2154 },
+ { 6772, -1003, -1235, -2532 },
+ { 6014, 228, -2154, -1108 },
+ { 6943, -2178, -2644, -1122 },
+ { 7262, -763, -3056, -1090 },
+ { 6273, -1478, -1072, 177 },
+ { 4734, 425, -2912, 357 },
+ { 7129, 168, -1537, -2327 },
+ { 7204, -434, -746, -2660 },
+ { 6879, 57, -3087, -1310 },
+ { 4623, -610, -718, -3459 },
+ { 6565, -543, -1998, -339 },
+ { 4752, -277, -2066, -1405 },
+ { 7435, -1416, -1904, -505 },
+ { 4076, 150, -1222, -3556 },
+ { 7082, -28, -1456, -1174 },
+ { 5941, -446, -1326, -1158 },
+ { 3870, -1648, -2474, -2589 },
+ { 858, 37, -3387, -3721 },
+ { 3557, -1503, -1664, -3383 },
+ { 3336, -1972, -3079, -2216 },
+ { 3186, 60, -4185, -863 },
+ { 3456, -773, -3066, -2457 },
+ { 4131, -913, -2060, -2601 },
+ { 4431, -691, -4114, -972 },
+ { 3461, -334, -3680, -1751 },
+ { 2006, -459, -2214, -3827 },
+ { 1322, 32, -2816, -3203 },
+ { 4425, -1897, -2791, -1946 },
+ { 4504, 23, -3421, -1909 },
+ { 3090, -885, -2366, -3264 },
+ { 3209, -2363, -3730, -834 },
+ { 3312, -1471, -3641, -1579 },
+ { 4184, -1669, -3323, -1248 },
+ { 2190, -931, -3302, -2944 },
+ { 2947, -229, -4791, -1195 },
+ { 2020, -1626, -2700, -3125 },
+ { 2214, -326, -4352, -1683 },
+ { 3286, -2619, -2412, -2458 },
+ { 1000, -2571, -4129, -2158 },
+ { 2496, -2627, -3611, -1433 },
+ { 2043, -2191, -2167, -3827 },
+ { 2571, -2544, -1915, -3222 },
+ { 2022, -1501, -3856, -2165 },
+ { 2685, -1180, -1461, -4038 },
+ { 1610, -2313, -4391, -1173 },
+ { 2340, -2490, -4215, -516 },
+ { 1742, -2615, -3632, -2146 },
+ { 523, -1293, -4246, -2442 },
+ { 3725, -2723, -3014, -1576 },
+ { 3554, -1381, -4200, -824 },
+ { 1291, -1594, -4777, -1430 },
+ { 1452, 515, -2960, -3830 },
+ { 4264, -894, -3305, -1826 },
+ { 2606, -1452, -4522, -966 },
+ { 1196, -830, -4807, -1816 },
+ { 1054, -775, -2616, -4071 },
+ { 4206, 415, -4344, -1132 },
+ { 3044, 491, -4126, -1934 },
+ { 988, -901, -3353, -3443 },
+ { 1729, -3063, -2267, -3370 },
+ { 3915, 912, -2989, -2387 },
+ { 3781, 300, -2457, -3050 },
+ { 2712, 924, -1350, -1206 },
+ { 4230, 405, -2343, 665 },
+ { 1878, -873, -225, -29 },
+ { 3510, 56, -1334, -3420 },
+ { 2850, 1447, -2651, -3150 },
+ { 1510, -706, -4125, -2483 },
+ { 3115, 793, -1692, -3894 },
+ { 2667, 213, -2973, -2786 },
+ { 1184, -2384, -3051, -3173 },
+ { 2139, 796, -2079, -3697 },
+ { 1464, -1483, -3726, -2754 },
+ { 2407, -1148, -3915, -1569 },
+ { 2612, -1779, -3217, -2271 },
+ { 2406, -2870, -2937, -2496 },
+ { 2140, 126, -3646, -2758 },
+ { 2952, -1036, 268, -1423 },
+ { 93, -1931, -3841, -3535 },
+ { 389, -2953, -3383, -3343 },
+ { 8652, -5511, -1662, 565 },
+ { 7427, -2791, -2535, -842 },
+ { 8541, -4253, -1407, -988 },
+ { 8018, -3203, -2998, 105 },
+ { 7231, -3926, -958, 1308 },
+ { 7331, -3690, -363, 2586 },
+ { 6803, -3646, -2226, -903 },
+ { 8163, -2811, -477, -2235 },
+ { 9356, -3818, -1685, -684 },
+ { 8466, -2854, -302, -698 },
+ { 8458, -3224, 517, 279 },
+ { 8074, -2619, -1326, 2596 },
+ { 8779, -2761, -2527, -441 },
+ { 6533, -2887, -899, -696 },
+ { 7394, -2305, -1642, -120 },
+ { 8281, -3780, -22, 1305 },
+ { 9158, -4413, -779, 901 },
+ { 9031, -5240, -1109, 1678 },
+ { 8717, -3650, 410, -1075 },
+ { 7317, -3197, -818, -2264 },
+ { 7934, -2385, -1214, -1886 },
+ { 8256, -4441, -291, -587 },
+ { 7358, -3395, 1090, -270 },
+ { 9446, -4910, -1343, -473 },
+ { 8187, -4726, -808, 1166 },
+ { 7504, -3845, -47, 267 },
+ { 8029, -2146, -1283, -383 },
+ { 7461, -2705, -853, 783 },
+ { 9367, -3636, -645, -354 },
+ { 8955, -3473, -308, -1947 },
+ { 8676, -2683, -2099, 1485 },
+ { 7481, -3003, -871, -444 },
+ { 8015, -2839, -1673, 1175 },
+ { 6947, -4643, -1527, -1047 },
+ { 7622, -2575, -137, -960 },
+ { 9388, -4279, -707, -1322 },
+ { 8382, -5259, -1283, -565 },
+ { 6856, -4138, -1030, 630 },
+ { 8659, -2571, -1124, -1666 },
+ { 8763, -3807, -537, 2543 },
+ { 8049, -3578, -2186, -604 },
+ { 8272, -2351, -1985, -1214 },
+ { 6855, -3796, -1527, -1631 },
+ { 7178, -2896, -1600, -1756 },
+ { 7040, -2888, -89, -1586 },
+ { 6261, -3403, -264, 998 },
+ { 7756, -4699, -1543, -834 },
+ { 7682, -4622, -758, -1721 },
+ { 8839, -4232, -2932, 1959 },
+ { 9363, -4679, -1956, 39 },
+ { 7883, -3616, -1414, -1432 },
+ { 8828, -3188, -1356, -1312 },
+ { 7746, -3987, -121, -2424 },
+ { 9262, -3256, -693, 818 },
+ { 7670, -3420, -148, 3504 },
+ { 7344, -3183, 608, 1595 },
+ { 8976, -4139, -1848, 1304 },
+ { 6708, -4131, 33, -852 },
+ { 7840, -4429, -2275, 79 },
+ { 8980, -3858, -2838, 453 },
+ { 7815, -4604, -2563, 944 },
+ { 8372, -4422, -1783, 3071 },
+ { 8623, -5128, -1754, 2888 },
+ { 7462, -3281, 889, 920 },
+ { 8416, -59, -1320, -1825 },
+ { 7928, -1488, -414, -2499 },
+ { 8110, -977, -1047, -2042 },
+ { 8278, -687, -1597, -1550 },
+ { 7988, -174, -977, -2106 },
+ { 8609, -1547, -1628, -1527 },
+ { 9000, -1798, -946, -1761 },
+ { 8954, -872, -1404, -1594 },
+ { 8939, 466, -748, -1212 },
+ { 9549, -329, -177, -1360 },
+ { 9411, -18, -1126, -1568 },
+ { 8859, -782, -488, -1338 },
+ { 8955, -218, -43, -1209 },
+ { 9131, -69, -453, -1001 },
+ { 9069, -1519, -1091, -1199 },
+ { 9247, -1309, -566, -1146 },
+ { 8528, -1617, -287, -1313 },
+ { 7763, -745, -149, -2040 },
+ { 8294, -343, 257, -2633 },
+ { 10149, -893, -552, -1649 },
+ { 9398, -915, 218, -2042 },
+ { 9703, -1194, -675, -1592 },
+ { 9586, -700, -427, -1710 },
+ { 8930, 497, -1445, -1218 },
+ { 9285, -1323, -163, -1552 },
+ { 8431, -1289, -985, -1404 },
+ { 8965, -655, 653, -1483 },
+ { 9542, -1001, -951, -1128 },
+ { 9205, -647, -37, -882 },
+ { 8603, -56, 514, -1793 },
+ { 9300, -12, -1324, -567 },
+ { 8773, 238, -184, -1456 },
+ { 9941, -1306, -69, -1792 },
+ { 9360, 279, -376, -1919 },
+ { 9180, -285, 95, -2170 },
+ { 9922, -501, -970, -1570 },
+ { 8341, -1493, -856, -2092 },
+ { 8780, -981, -850, -1014 },
+ { 9721, -548, -1504, -1094 },
+ { 9973, -1493, 482, -2105 },
+ { 8707, -333, -1027, -1087 },
+ { 9098, -469, -315, -1723 },
+ { 8879, -1050, -661, -2020 },
+ { 8857, 602, -866, -1918 },
+ { 8945, -1025, -2154, -1071 },
+ { 8484, -1930, -468, -2179 },
+ { 9177, -1903, -224, -2112 },
+ { 8652, -137, -2097, -1214 },
+ { 9063, -973, -1405, -772 },
+ { 9328, -456, 662, -2469 },
+ { 10101, -697, 127, -2113 },
+ { 9685, 811, -2359, -1024 },
+ { 8586, -94, -460, -1982 },
+ { 7924, -141, -509, -2513 },
+ { 7773, -669, -107, -2835 },
+ { 8636, -1064, -46, -2409 },
+ { 9748, 596, -1815, -1349 },
+ { 8924, 304, 547, -2614 },
+ { 9442, 746, -1153, -1679 },
+ { 9454, -278, -529, -1976 },
+ { 8488, 561, -32, -2160 },
+ { 10083, -63, -1544, -1364 },
+ { 9390, -1278, 568, -1131 },
+ { 9740, -49, -2253, -910 },
+ { 3636, -2391, -1115, -3614 },
+ { 6014, -3204, -1902, -1808 },
+ { 5787, -3497, -1116, -2590 },
+ { 4365, -3046, -1632, -2668 },
+ { 4733, -2192, -2029, -2468 },
+ { 5412, -2753, -1633, -2464 },
+ { 4455, -3375, -767, -3399 },
+ { 4456, -1644, -983, -2841 },
+ { 4039, -2523, 38, -3967 },
+ { 3406, -2662, 72, -4757 },
+ { 4279, -2005, 1055, -4399 },
+ { 4321, -1377, -860, -3786 },
+ { 3743, -5739, -651, -3047 },
+ { 3528, -5510, 361, -4060 },
+ { 6496, -4886, -136, -2689 },
+ { 4513, -5254, 551, -4010 },
+ { 6557, -3413, -92, -3063 },
+ { 4186, -2059, 187, 47 },
+ { 6210, -4117, -1256, -1985 },
+ { 6038, -4343, 351, -2124 },
+ { 4305, -4780, -2077, -1897 },
+ { 4480, -3815, -2228, -1533 },
+ { 5582, -3689, 1221, -3429 },
+ { 5532, -4874, 1195, -2765 },
+ { 6518, -2853, -905, -2568 },
+ { 5467, -2192, 470, -4115 },
+ { 4139, -1577, 240, -3493 },
+ { 5281, -1926, -729, -3340 },
+ { 5214, -2870, 1359, -4289 },
+ { 3046, -3510, -1536, -3214 },
+ { 5433, -2881, -1230, -1184 },
+ { 4861, -3932, -1071, -2791 },
+ { 5693, -4234, -1906, -1502 },
+ { 4004, -3935, -1804, -2383 },
+ { 3728, -3792, 681, -4773 },
+ { 3621, -3030, -1951, -2598 },
+ { 5133, -3903, 44, -3700 },
+ { 3561, -3451, 1183, -5301 },
+ { 5026, -2762, -2341, -1780 },
+ { 5841, -2492, -467, -3210 },
+ { 5591, -1791, 497, -2472 },
+ { 5054, -3898, -1822, -2097 },
+ { 5813, -2792, 83, -1469 },
+ { 4432, -4497, 1670, -5193 },
+ { 5338, -4653, -1109, -2200 },
+ { 3239, -4401, -648, -3655 },
+ { 2147, -3598, -1200, -4242 },
+ { 4417, -2271, -1552, -3210 },
+ { 6494, -4360, 852, -3565 },
+ { 2393, -6358, -856, -4524 },
+ { 4959, -4196, -847, -1403 },
+ { 4924, -5438, -226, -3026 },
+ { 4254, -5303, -1306, -2424 },
+ { 4121, -3126, -2334, -1981 },
+ { 3437, -4443, -1464, -2953 },
+ { 3203, -3459, -529, -4339 },
+ { 5896, -5945, 543, -3246 },
+ { 1987, -4733, -220, -4863 },
+ { 4358, -4431, -514, -3081 },
+ { 4583, -2416, -492, -2287 },
+ { 2943, -5035, 419, -4927 },
+ { 5358, -5129, 987, -4309 },
+ { 4460, -3392, 1752, -5634 },
+ { 3415, -4633, 1507, -5945 },
+ { 811, -4692, -445, 2333 },
+ { 1009, -5613, -1857, 1360 },
+ { 1338, -2712, -2720, 3036 },
+ { 1002, -3754, -2582, 2344 },
+ { 750, -4608, -2334, 714 },
+ { 2043, -3207, -2822, 2173 },
+ { -140, -4654, -2953, 357 },
+ { -54, -4026, -2376, 2695 },
+ { 1858, -5022, -717, 2287 },
+ { 2064, -3894, -722, 3255 },
+ { 2727, -4558, -332, 2603 },
+ { 1810, -5378, 283, 1826 },
+ { 3935, -4326, 762, 3383 },
+ { -767, -4697, -2510, 1922 },
+ { 2146, -4312, -3090, 1641 },
+ { 54, -5881, -2114, 921 },
+ { 1992, -5766, -640, 1574 },
+ { 1200, -5371, -1114, 1828 },
+ { 2973, -5337, 34, 2266 },
+ { 1531, -5018, -2817, 1192 },
+ { 3078, -4570, 117, 1990 },
+ { 924, -4286, -1388, 2713 },
+ { 142, -5058, -2848, 1487 },
+ { -106, -6180, -881, 842 },
+ { 673, -5433, -229, 1596 },
+ { 783, -5710, -2784, 562 },
+ { 1935, -5729, -2009, 856 },
+ { -410, -3375, -3326, 2734 },
+ { 234, -3000, -2628, 3260 },
+ { 733, -3405, -3806, 1589 },
+ { 771, -4285, -3544, 1314 },
+ { 1192, -3563, -3960, 2178 },
+ { 206, -5555, -1250, 1546 },
+ { -130, -3815, -1210, 3041 },
+ { 646, -3940, -393, 2992 },
+ { -184, -4931, -1767, 1925 },
+ { 2746, -5120, -2275, 1464 },
+ { 2440, -3731, -3352, 2729 },
+ { -490, -4942, -3779, 997 },
+ { 68, -2636, -4167, 3778 },
+ { 48, -3986, -4118, 2106 },
+ { -978, -5486, -1336, 1390 },
+ { 1126, -5297, -855, 640 },
+ { -472, -3975, -3622, 1557 },
+ { 2456, -5344, -1523, 1648 },
+ { -774, -5652, -2417, 1147 },
+ { 995, -6122, -812, 1132 },
+ { 3282, -4571, -1763, 2175 },
+ { 3655, -3862, -676, 3568 },
+ { 3038, -3647, -1672, 3381 },
+ { 2595, -2964, -2772, 3263 },
+ { 4176, -3353, -1148, 4354 },
+ { 1603, -3442, -1500, 3444 },
+ { 828, -6226, -1783, 678 },
+ { 1421, -3333, -3080, 3403 },
+ { 1121, -4727, -1924, 1984 },
+ { -186, -5083, -682, 1796 },
+ { 819, -2778, -3488, 530 },
+ { 421, -2873, -3832, 2596 },
+ { 2164, -4263, -1605, 2282 },
+ { 585, -4437, -682, -491 },
+ { -644, -4452, -1157, 2325 },
+ { 1991, -4299, 210, 2834 },
+ { 2135, -3632, -2113, 665 },
+ { -7482, -2724, -2662, -1380 },
+ { -6983, -2166, -3756, -3509 },
+ { -7085, -1439, -2397, -3112 },
+ { -7760, -3049, -3319, -2822 },
+ { -8413, -2760, -4406, -3298 },
+ { -5995, -3943, -1260, -3750 },
+ { -7879, -1554, -3464, -2606 },
+ { -6314, -2034, -3878, -1681 },
+ { -8849, -2084, -1399, -1231 },
+ { -7153, -2602, -1384, -817 },
+ { -8041, -2571, -407, -2785 },
+ { -7246, -2233, -1578, 260 },
+ { -7336, -3883, -4061, -1342 },
+ { -7619, -3908, -2342, 382 },
+ { -8684, -3724, -1662, -727 },
+ { -7850, -2922, -1770, -3449 },
+ { -6766, -2034, -1293, -1988 },
+ { -6895, -2116, -968, -3744 },
+ { -7136, -5147, -2618, -2809 },
+ { -8224, -3724, -2519, -1589 },
+ { -6711, -2750, -3021, -219 },
+ { -8059, -1638, -1102, -3175 },
+ { -8710, -4839, -3963, -3143 },
+ { -9363, -4965, -3257, -1002 },
+ { -6099, -1751, -3157, -395 },
+ { -6453, -3216, -4597, -483 },
+ { -7879, -5477, -839, -2638 },
+ { -7202, -4038, -526, -2856 },
+ { -8022, -1228, -1910, -1646 },
+ { -9117, -1393, -1582, -2535 },
+ { -9095, -2693, -636, -2605 },
+ { -9076, -2580, -3481, -2519 },
+ { -8327, -4859, -2422, 83 },
+ { -8368, -2129, -2324, -2173 },
+ { -8554, -4563, -3842, -2007 },
+ { -10462, -4261, -1934, -2084 },
+ { -9717, -3187, -2294, -1896 },
+ { -9625, -3889, -3020, -3224 },
+ { -9857, -4955, -4239, -2184 },
+ { -9752, -2351, -2277, -3129 },
+ { -7219, -1302, -2639, -1603 },
+ { -7477, -4360, -3718, -559 },
+ { -5680, -2033, -2326, -3078 },
+ { -10190, -5548, -4643, -3601 },
+ { -9431, -4121, -879, -2479 },
+ { -8365, -5450, -2020, -1439 },
+ { -6289, -5178, -1605, -3845 },
+ { -8319, -3866, -687, -2792 },
+ { -8131, -1031, -3608, -3947 },
+ { -10510, -2560, -1199, -2082 },
+ { -11015, -3640, -2748, -3041 },
+ { -8762, -5022, -5231, -1162 },
+ { -10153, -2715, -4648, -4859 },
+ { -7930, -5205, -1900, -3600 },
+ { -9561, -3548, -4812, -3722 },
+ { -7663, -4709, -1180, -1475 },
+ { -9073, -5707, -1815, -2980 },
+ { -8602, -2363, -2675, -3770 },
+ { -9967, -5614, -3575, -3838 },
+ { -8324, -1005, -2131, -3254 },
+ { -10331, -5737, -2550, -2940 },
+ { -8234, -3354, -3361, -4479 },
+ { -8140, -1951, -4526, -4545 },
+ { -6679, -2662, -2284, -4182 },
+ { -1122, -1514, -6427, -212 },
+ { 54, -1660, -5424, -1404 },
+ { 254, -2778, -5222, 846 },
+ { -267, -1661, -6577, 814 },
+ { -305, -2021, -5759, 1484 },
+ { -1791, -2446, -6867, -86 },
+ { -2929, -3158, -6603, -1799 },
+ { -1391, -3189, -5557, -1053 },
+ { -1602, -884, -6767, -1213 },
+ { -361, -318, -6219, -44 },
+ { -4078, -2635, -5523, -433 },
+ { -956, 478, -4382, 1470 },
+ { -3300, -2462, -6021, -2721 },
+ { 708, -2434, -5085, -540 },
+ { -2435, -3607, -5647, -2110 },
+ { -491, -1134, -4681, -2886 },
+ { 87, -3435, -4641, -1194 },
+ { -586, -2927, -4784, 366 },
+ { -1394, -2326, -6021, 350 },
+ { 97, -2519, -4678, -2120 },
+ { -1547, -1907, -5069, -2993 },
+ { 268, -3724, -4719, 127 },
+ { -827, -1190, -5912, 1144 },
+ { -3959, -2322, -6898, -1974 },
+ { -2728, -2228, -6426, -562 },
+ { -456, -666, -5785, -1609 },
+ { 531, -1096, -5731, -656 },
+ { -3569, -688, -3915, 110 },
+ { -4752, -1725, -4393, -377 },
+ { -3210, -3315, -6960, -840 },
+ { -688, -3416, -4971, 1221 },
+ { -1833, 77, -6491, -2434 },
+ { -239, -255, -6850, -886 },
+ { -2112, -1490, -6291, -2689 },
+ { -1544, -4579, -5198, -1261 },
+ { -2771, -4014, -5520, 683 },
+ { -1635, -2829, -5512, 1214 },
+ { -958, -2582, -4823, 2360 },
+ { -2077, -4566, -4642, 365 },
+ { -3112, -4214, -5960, -823 },
+ { -2467, -2510, -4858, 1467 },
+ { -1561, -3399, -5822, 211 },
+ { -775, -1081, -4424, 2636 },
+ { -1263, 25, -6378, -1392 },
+ { -3476, -366, -5417, -1393 },
+ { -3176, -1476, -4149, 1466 },
+ { -2479, 518, -4448, -257 },
+ { -2992, 158, -4660, -1279 },
+ { -1320, -3872, -4479, 1147 },
+ { -1475, -312, -5318, 539 },
+ { -3527, -1679, -5860, -1681 },
+ { -3397, -3438, -5593, 1866 },
+ { -4089, -2439, -4763, 1275 },
+ { -748, -4513, -4687, -48 },
+ { -2166, -4531, -4691, -2856 },
+ { -2385, -853, -6035, -627 },
+ { -1194, -4091, -4472, -1963 },
+ { -682, -3234, -4084, -3033 },
+ { -3255, -5015, -5328, -12 },
+ { -2313, -3436, -4601, -155 },
+ { -2792, -1038, -6947, -2019 },
+ { -1244, -1526, -5771, -1882 },
+ { -4679, -3731, -5506, 283 },
+ { -3062, -66, -3558, -758 },
+ { -4895, -1187, 4751, 3728 },
+ { -7600, -2752, 3320, 4613 },
+ { -5703, -2975, 3944, 2659 },
+ { -4972, -1257, -246, 2952 },
+ { -4221, -2487, 1702, 4295 },
+ { -2900, -1529, 2458, 4935 },
+ { -5061, 407, 2416, 4050 },
+ { -6931, -3478, 2761, 2213 },
+ { -6037, -3921, 3192, 1866 },
+ { -6113, -811, 2407, 3782 },
+ { -5878, -1716, 1207, 3478 },
+ { -5953, -2853, 2207, 2712 },
+ { -6807, -3223, 2749, 3595 },
+ { -3272, -3157, 1389, 3788 },
+ { -5368, -1904, 1980, 5077 },
+ { -7235, -1398, 3075, 4548 },
+ { -4765, -3487, 2755, 2796 },
+ { -7658, -4435, 2694, 2582 },
+ { -6997, -4282, 456, 3832 },
+ { -5563, -3115, -63, 3713 },
+ { -4244, -4220, 1450, 2767 },
+ { -3801, -2194, 190, 4303 },
+ { -5458, -4119, 1958, 2274 },
+ { -7300, -3469, 3514, 3193 },
+ { -4594, -2067, 775, 4752 },
+ { -3389, -1654, 1464, 5412 },
+ { -4845, -3483, 964, 3437 },
+ { -6007, -2818, 1666, 4659 },
+ { -8709, -5007, 1757, 3287 },
+ { -5833, -4389, 1025, 3171 },
+ { -5788, -1780, 3944, 3661 },
+ { -4430, -920, 1938, 4753 },
+ { -7066, -1857, 4591, 4538 },
+ { -3549, -513, 1427, 5317 },
+ { -7517, -1220, 2883, 3049 },
+ { -7605, -2687, 1874, 2735 },
+ { -8718, -4035, 2676, 3730 },
+ { -7990, -3907, 1185, 2607 },
+ { -6058, -1744, 3349, 5157 },
+ { -5954, 565, 3161, 3250 },
+ { -6478, -612, 1930, 2271 },
+ { -6535, -1445, -2, 1618 },
+ { -8963, -4151, 1192, 4044 },
+ { -7227, -3570, 1600, 4234 },
+ { -4674, 79, 595, 3015 },
+ { -3974, 430, 2727, 5137 },
+ { -5299, 9, 3714, 4779 },
+ { -6779, -2699, -8, 2436 },
+ { -7016, -1145, 1293, 2310 },
+ { -6955, -3312, 1534, 1801 },
+ { -4025, 740, 1850, 4054 },
+ { -9589, -3460, 4154, 5270 },
+ { -4404, -1181, 4298, 5173 },
+ { -7356, -4583, -18, 2644 },
+ { -6516, -1235, 4439, 6234 },
+ { -3453, -301, 4344, 4464 },
+ { -4643, 1530, 3315, 4340 },
+ { -4575, -2557, 3754, 3682 },
+ { -3643, -3501, 2051, 2997 },
+ { -5412, -2475, 2301, 1579 },
+ { -5846, 259, 1360, 2348 },
+ { -5258, -1358, 1050, 838 },
+ { -5542, -219, 6377, 5750 },
+ { -5713, -2952, 922, 899 },
+ { -2049, -1135, 5206, 1033 },
+ { -1693, -1886, 4835, -106 },
+ { -2344, -3504, 4232, -13 },
+ { -2475, -2334, 5043, 1126 },
+ { -787, -2549, 3880, 2138 },
+ { -3159, -2341, 4830, 2887 },
+ { -1780, -1009, 6240, 2061 },
+ { -4327, -3363, 2818, 886 },
+ { -3376, -2743, 4104, 207 },
+ { -3250, -4640, 2718, 1498 },
+ { -382, -1075, 4382, 3460 },
+ { -2416, -4168, 3530, 816 },
+ { -1756, -2708, 4861, 622 },
+ { -1879, -2097, 5156, 2889 },
+ { -2496, -2418, 3722, 2671 },
+ { -2717, -3252, 3341, 1944 },
+ { -4063, -4091, 3306, 267 },
+ { -3549, -3808, 3747, 842 },
+ { -2635, 546, 5794, 1894 },
+ { -1857, -1121, 4383, 3964 },
+ { -2226, -2166, 3489, 3678 },
+ { -3492, -660, 5323, 1063 },
+ { -3033, -3130, 4382, 1828 },
+ { -2703, -625, 6369, 2851 },
+ { -1656, -2842, 4584, -528 },
+ { -4781, -2622, 4390, 2097 },
+ { -413, -2045, 5081, 3035 },
+ { -3810, -2662, 4532, 1095 },
+ { -3144, -1858, 5215, 1880 },
+ { -3562, -1795, 4928, 670 },
+ { -4800, -1509, 5189, 1859 },
+ { -1085, -3832, 4169, 900 },
+ { -1969, -3270, 2857, 2878 },
+ { -4267, -4140, 3176, 1805 },
+ { -5145, -3727, 3524, 1168 },
+ { -1346, -1876, 5501, 1748 },
+ { -4998, -2945, 3699, 338 },
+ { -3458, -3096, 3406, -635 },
+ { -1751, -3209, 3508, 395 },
+ { -2507, 170, 5987, 705 },
+ { -3756, -1072, 5647, 3536 },
+ { -2870, -1439, 5026, 3212 },
+ { -3913, -3225, 3669, 2144 },
+ { -3739, 226, 5747, 764 },
+ { -2052, -820, 5266, 3093 },
+ { -3214, -3820, 2409, 2391 },
+ { -4398, -2588, 3501, -218 },
+ { -4484, -1763, 4180, -198 },
+ { -3368, -1525, 4362, -134 },
+ { -2407, 224, 4905, 3533 },
+ { -1369, -2937, 4728, 1788 },
+ { -4848, -1707, 4159, 851 },
+ { -3454, -1749, 4281, 3230 },
+ { -1990, -3853, 3487, 1735 },
+ { -3117, 92, 6155, 4075 },
+ { -2676, -2472, 4078, -589 },
+ { -1547, -2012, 2626, 1835 },
+ { -4275, -588, 4824, 725 },
+ { -601, -2249, 3736, 3548 },
+ { -4060, -61, 5333, 3097 },
+ { -4303, 7, 6551, 3054 },
+ { -5003, -1029, 5786, 3319 },
+ { -2810, -728, 5392, 199 },
+ { -1232, -200, 5228, 3121 },
+ { 2621, 165, -6255, 298 },
+ { 3669, 537, -6844, 1564 },
+ { 1598, -1190, -6235, 2523 },
+ { 2164, -32, -6894, 1383 },
+ { 853, -1597, -6069, 1449 },
+ { 1377, -1661, -5266, 108 },
+ { 2660, 48, -5172, -517 },
+ { 1903, -391, -5677, 1010 },
+ { 3792, 206, -5274, -11 },
+ { 1239, 2776, -2929, 2721 },
+ { 4071, 149, -7259, 3125 },
+ { 1436, -480, -6156, -196 },
+ { 1373, -1960, -5005, 3122 },
+ { 3413, -1271, -5176, 3283 },
+ { 3060, -68, -6495, 2238 },
+ { 2700, -2075, -4681, 91 },
+ { 2928, -1728, -5168, 1858 },
+ { 4424, 828, -4471, 88 },
+ { 2672, -2604, -4038, 2753 },
+ { 5223, -123, -6749, 2295 },
+ { 4237, -420, -5538, 1353 },
+ { 4744, -1281, -4097, 4708 },
+ { 1103, -2764, -4751, 2024 },
+ { 3747, -1913, -3911, 3960 },
+ { 2470, -1416, -5542, 615 },
+ { 4847, -1354, -5334, 1733 },
+ { 5336, 88, -7593, 4007 },
+ { 2388, -2880, -4807, 1037 },
+ { 4495, 1391, -5685, -139 },
+ { 5253, 1637, -6450, 1533 },
+ { 1199, 795, -5515, 1261 },
+ { 1397, -1259, -4252, 3838 },
+ { 746, 70, -6640, 604 },
+ { 1584, 166, -4972, 3072 },
+ { 380, -999, -5397, 2267 },
+ { 2974, 1707, -3242, 5360 },
+ { 5202, -403, -5453, 2832 },
+ { 3718, -1731, -4760, 714 },
+ { 4150, -975, -4792, 61 },
+ { 2925, -818, -4841, 15 },
+ { 5301, 577, -4006, 3259 },
+ { 5265, 1986, -5679, 3028 },
+ { 3752, 1928, -4509, 3729 },
+ { 3278, 1925, -6370, 1247 },
+ { 5107, 1721, -4853, 3127 },
+ { 3279, 2982, -2515, 4005 },
+ { 4622, 668, -6204, 759 },
+ { 6034, 317, -5763, 4818 },
+ { -558, 57, -3785, 2817 },
+ { 4476, 1616, -3965, 4536 },
+ { 5953, 2056, -8215, 2715 },
+ { 4387, 2613, -7463, 868 },
+ { 5834, 1088, -4736, 4924 },
+ { 6473, -856, -6991, 4172 },
+ { 4959, -293, -5162, 76 },
+ { 2731, -843, -6119, 3847 },
+ { 3245, 1202, -6833, 616 },
+ { 2553, 1383, -3829, 3859 },
+ { 4332, 2099, -3480, 3622 },
+ { 2110, 2683, -2728, 3990 },
+ { 876, 1167, -3290, 3466 },
+ { 3991, 1709, -2410, 4077 },
+ { 5105, 939, -2584, 3256 },
+ { 4719, 688, -1566, 3040 },
+ { -3632, 4335, 1266, -3303 },
+ { -4956, 3207, 1312, -2806 },
+ { -4669, 2627, 2663, -2435 },
+ { -4282, 3708, 2303, -3038 },
+ { -4536, 2297, -175, -3350 },
+ { -5234, 2503, -139, -880 },
+ { -3978, 1512, 1092, -3619 },
+ { -4519, 4649, 1363, -2455 },
+ { -5118, 3132, 1961, -1577 },
+ { -5196, 3379, -182, -1378 },
+ { -6420, 4486, 2397, -1993 },
+ { -5030, 5046, 1292, -1118 },
+ { -4559, 2573, -927, -1406 },
+ { -3501, 3730, 691, -4930 },
+ { -4364, 2758, 1007, -3909 },
+ { -4026, 2839, -1559, -2340 },
+ { -5037, 4053, 836, -1571 },
+ { -4727, 5136, 1110, -3588 },
+ { -5245, 2799, -999, -2164 },
+ { -4954, 1501, 422, -3963 },
+ { -5994, 2726, 1462, -2833 },
+ { -5621, 5159, 2038, -2512 },
+ { -4991, 2291, 1917, -3151 },
+ { -5469, 4382, -148, -2978 },
+ { -5858, 1983, 807, -2720 },
+ { -4709, 3556, 952, -467 },
+ { -2489, 2362, 1714, -4230 },
+ { -4717, 5004, -1180, -3672 },
+ { -5914, 3653, 1359, -1317 },
+ { -5506, 2995, 780, -1059 },
+ { -5287, 3945, 2480, -2293 },
+ { -3849, 4358, 322, -1770 },
+ { -3911, 3570, 252, -3185 },
+ { -3660, 5128, 158, -3719 },
+ { -4599, 3277, -503, -2727 },
+ { -3673, 3760, -1252, -3339 },
+ { -5161, 2337, 388, -1943 },
+ { -3529, 2216, 2156, -3080 },
+ { -4309, 4331, 1808, -1460 },
+ { -4782, 3820, 480, -2504 },
+ { -4166, 3544, -378, -1567 },
+ { -5572, 2466, -418, -2909 },
+ { -6096, 2930, 119, -1878 },
+ { -5963, 3554, 1011, -2233 },
+ { -6433, 4335, 935, -2930 },
+ { -5004, 3314, -1352, -3430 },
+ { -6042, 3463, -1008, -3940 },
+ { -4671, 2214, -640, -5040 },
+ { -2795, 3759, 1412, -3803 },
+ { -3647, 4436, 729, -515 },
+ { -3594, 1033, 56, -4148 },
+ { -2908, 3027, 2889, -3485 },
+ { -3338, 2234, 313, -4285 },
+ { -3825, 4497, -561, -2634 },
+ { -6167, 3012, -48, -3149 },
+ { -4828, 3515, -969, -4475 },
+ { -5789, 2757, -539, -4173 },
+ { -2452, 3067, 564, -4249 },
+ { -4921, 1358, 1331, -2889 },
+ { -3127, 4239, -1045, -1523 },
+ { -4780, 2326, -1118, -3446 },
+ { -3908, 5546, 152, -2622 },
+ { -6972, 2976, 337, -2809 },
+ { -4839, 4613, -35, -4077 },
+ { -1408, 4822, -1149, -4997 },
+ { -981, 4979, -912, -6304 },
+ { -2098, 5689, -888, -2878 },
+ { -3343, 4814, -657, -4434 },
+ { -2461, 3601, -967, -4869 },
+ { -2652, 3944, 87, -5520 },
+ { -1104, 6076, 174, -6407 },
+ { 355, 5370, -1721, -5869 },
+ { 1242, 4497, -1107, -5091 },
+ { -89, 4002, -1491, -5182 },
+ { 1059, 5693, -1591, -4905 },
+ { 1323, 4682, -2078, -4768 },
+ { 818, 3996, -549, -5468 },
+ { -287, 4529, 929, -5543 },
+ { -919, 5519, -2791, -2844 },
+ { -1407, 5679, -3289, -3974 },
+ { -189, 6530, -3547, -4002 },
+ { -900, 7039, -3371, -4855 },
+ { -2983, 7211, -363, -4835 },
+ { -814, 6503, -104, -5106 },
+ { -2386, 6896, 809, -4919 },
+ { 845, 4492, 352, -6621 },
+ { -1998, 7237, -1646, -4231 },
+ { -3380, 6251, 471, -4577 },
+ { -1908, 7059, 84, -5726 },
+ { -340, 6346, -803, -6265 },
+ { -2279, 5834, -47, -4633 },
+ { -1532, 5286, -1748, -1901 },
+ { -2757, 6188, -453, -3415 },
+ { -1255, 6405, -2043, -6357 },
+ { 918, 5581, -121, -5667 },
+ { 1840, 5336, -821, -5034 },
+ { -2475, 4992, -1825, -3104 },
+ { -2413, 5606, -1789, -4298 },
+ { 132, 5128, -2389, -4442 },
+ { 223, 6400, -2653, -4742 },
+ { -673, 5012, 680, -4582 },
+ { -1657, 6624, -349, -3596 },
+ { -755, 6289, -1860, -3978 },
+ { -572, 6894, -1946, -5207 },
+ { -1141, 4756, -2665, -5586 },
+ { -1073, 4269, -431, -4030 },
+ { 186, 5761, 916, -5868 },
+ { -1907, 4836, 1017, -5106 },
+ { -963, 3363, -1248, -6348 },
+ { -3262, 4774, -1818, -5858 },
+ { 847, 3812, -2538, -4302 },
+ { -1223, 5903, 1360, -5479 },
+ { -1094, 6923, -1244, -2381 },
+ { 267, 6276, -709, -2846 },
+ { -157, 5840, 1124, -4266 },
+ { 889, 3206, -910, -5305 },
+ { -1736, 3344, 582, -4838 },
+ { -2357, 5676, -2695, -6277 },
+ { -1916, 6901, -986, -5397 },
+ { -3062, 6028, -695, -5687 },
+ { 1836, 3566, -1357, -5226 },
+ { -2176, 4938, 646, -3872 },
+ { -2199, 3055, -208, -6124 },
+ { -236, 3032, -821, -5325 },
+ { -3989, 7277, -565, -3899 },
+ { -595, 4362, 74, -5975 },
+ { 684, 5874, -841, -4424 },
+ { -2731, 6305, -2389, -5465 },
+ { -5775, 1325, -56, -2528 },
+ { -7029, -534, -1890, -3278 },
+ { -5798, -15, -2734, -2210 },
+ { -5504, -1198, -353, -3659 },
+ { -5079, 960, -894, -4336 },
+ { -6073, -36, -133, -3014 },
+ { -5782, -259, -1025, -3986 },
+ { -6843, 1262, -807, -1639 },
+ { -5263, -918, -3290, -579 },
+ { -4840, 461, -2158, -533 },
+ { -6014, -50, -620, 504 },
+ { -5843, 241, -1359, -282 },
+ { -5898, 577, 769, -3271 },
+ { -6833, -946, -466, -3347 },
+ { -6026, 1459, -512, -729 },
+ { -7361, 747, -388, -1110 },
+ { -6391, 2142, -1160, -2513 },
+ { -6995, 304, 498, -2673 },
+ { -6757, 679, -386, -433 },
+ { -5222, 1688, -1093, -1032 },
+ { -5019, 575, 184, -3627 },
+ { -4237, 628, -3507, -1243 },
+ { -7479, -456, -1722, -1486 },
+ { -6464, 713, -1273, -1153 },
+ { -6255, 1682, -606, -3607 },
+ { -7033, 1497, -71, -1955 },
+ { -6694, 1556, -1721, -3214 },
+ { -6114, -356, 813, -2575 },
+ { -5308, 632, -1851, -1636 },
+ { -5742, -911, -1733, 383 },
+ { -6083, -387, -2313, -879 },
+ { -6535, -530, -1505, -2083 },
+ { -4896, 1223, -2750, -1816 },
+ { -6392, -463, -3247, -2093 },
+ { -5373, 1264, -2706, -3042 },
+ { -3894, -1390, -1020, -891 },
+ { -6179, 1168, -1966, -1922 },
+ { -5162, 1668, -1617, -1916 },
+ { -6453, 920, -1169, -2432 },
+ { -6130, 2005, -536, -1519 },
+ { -6552, -98, -518, -1938 },
+ { -7528, 355, -1101, -1772 },
+ { -5745, 610, -247, -1360 },
+ { -7003, 177, -2064, -1958 },
+ { -6956, -570, -2220, -4225 },
+ { -7830, 791, -1394, -2774 },
+ { -7634, 480, -3171, -4224 },
+ { -7913, 1154, -350, -2381 },
+ { -5063, 1704, -1804, -2977 },
+ { -4887, -524, -2703, 188 },
+ { -5551, 406, -1620, -3063 },
+ { -7109, 1342, 381, -3021 },
+ { -6846, 631, -458, -3398 },
+ { -4606, -605, 11, -3930 },
+ { -8134, -225, -1738, -2648 },
+ { -7043, 402, -2734, -3059 },
+ { -7417, 1825, -2545, -4389 },
+ { -6971, -236, -1031, -665 },
+ { -5752, 2111, -1632, -3808 },
+ { -7660, -78, -624, -3135 },
+ { -6358, 619, -1951, -3911 },
+ { -8134, 408, -1935, -3695 },
+ { -6335, 1911, -2368, -4505 },
+ { -7116, 2163, -344, -2753 },
+ { 2357, 4488, 2220, -5682 },
+ { 1385, 3206, 2300, -5305 },
+ { 1419, 2557, 5203, -3516 },
+ { 262, 4315, 3920, -1847 },
+ { 3316, 3187, 1612, -5609 },
+ { 1729, 2350, 1673, -6068 },
+ { 1603, 6126, 1467, -2839 },
+ { -1339, 3316, 3691, -3530 },
+ { -563, 4618, 3180, -4548 },
+ { 463, 4624, 3111, -5614 },
+ { 1246, 5455, 3356, -5720 },
+ { 480, 2149, 5422, -2893 },
+ { 1768, 4827, 913, -5579 },
+ { -149, 5381, 4366, -3297 },
+ { 985, 3672, 2644, -92 },
+ { -258, 2911, 5817, -2213 },
+ { 3428, 3289, 3351, -3541 },
+ { -666, 3295, 4727, -2869 },
+ { 35, 6641, 4160, -4052 },
+ { 623, 6787, 3156, -4560 },
+ { 2654, 4360, 4676, -4632 },
+ { 1386, 5246, 4834, -4497 },
+ { 3488, 4574, 3856, -5946 },
+ { 383, 4481, 4168, -4110 },
+ { 1753, 3652, 4288, -3326 },
+ { 1344, 4905, 2508, -4660 },
+ { 1580, 4106, 3104, -2224 },
+ { 2027, 5038, 1683, -1554 },
+ { 446, 3699, 5872, -3013 },
+ { 4637, 4087, 3578, -5018 },
+ { 2629, 3560, 5331, -4900 },
+ { 1527, 6674, 2523, -4131 },
+ { -1437, 2804, 2528, -4464 },
+ { -229, 3355, 2016, -5537 },
+ { 3666, 3418, 4374, -4581 },
+ { 1192, 3799, 923, -6596 },
+ { 2040, 2956, 448, -5322 },
+ { 2468, 5768, 4029, -5869 },
+ { 3438, 6516, 3529, -6667 },
+ { 2737, 5495, 680, -5535 },
+ { 3896, 5727, 1801, -4958 },
+ { 4988, 4957, 3592, -6518 },
+ { -542, 4416, 5794, -2787 },
+ { 4136, 4354, 2064, -4696 },
+ { 3067, 5936, 1207, -3396 },
+ { 2789, 4966, 2405, -3854 },
+ { 1731, 3270, 3251, -1063 },
+ { 1767, 5537, 2084, -2349 },
+ { 465, 3116, 4532, -837 },
+ { 1499, 2627, 4610, -2212 },
+ { 122, 3095, 3642, -3552 },
+ { 2542, 2866, 2705, -6402 },
+ { 3134, 4323, 698, -4785 },
+ { 731, 1859, 3112, -5242 },
+ { 2553, 2980, 3241, -4846 },
+ { 1329, 5310, 1607, -6624 },
+ { 2468, 1858, 3476, -1034 },
+ { -172, 4996, 2000, -5562 },
+ { 2621, 4220, 1574, -3386 },
+ { -333, 1832, 3362, -4117 },
+ { 2169, 6762, 3065, -6225 },
+ { 2844, 5528, 3223, -4765 },
+ { 526, 5175, 1644, -4267 },
+ { 2922, 4426, 2414, -2610 },
+ { 452, 1399, -4516, -2636 },
+ { 2872, 1720, -4667, -1435 },
+ { 1279, 702, -5424, -1984 },
+ { 2187, 870, -5021, -1341 },
+ { 583, -144, -4628, -2464 },
+ { 3, 2237, -5284, -2827 },
+ { -19, 1005, -5460, -1819 },
+ { 2897, 2084, -5885, -515 },
+ { -400, 3370, -5527, -2947 },
+ { 1505, 2593, -5518, -1802 },
+ { 1341, 4534, -5094, -1899 },
+ { 3241, 3670, -5493, -1252 },
+ { -1287, 921, -5994, -1675 },
+ { 627, 408, -6652, -364 },
+ { -260, 1127, -4849, -3247 },
+ { 371, 3400, -5976, -2285 },
+ { 1533, 1566, -6373, -610 },
+ { 2462, 4274, -6184, -1254 },
+ { 1782, 3363, -6222, -1381 },
+ { 572, 4650, -5673, -2754 },
+ { 2674, 3414, -4460, -2154 },
+ { 3614, 3820, -6883, -398 },
+ { 1136, -1, -5511, -1112 },
+ { -1773, 1137, -5647, -2377 },
+ { -753, 2104, -6085, -2565 },
+ { -204, 3025, -4731, -1418 },
+ { -1486, 1438, -4380, -216 },
+ { 302, 858, -5786, -264 },
+ { 3486, 1495, -5234, -783 },
+ { 888, 2327, -3423, -3720 },
+ { -259, 772, -6596, -1311 },
+ { -1197, 2073, -5174, -1826 },
+ { 1500, 3470, -4462, -2645 },
+ { 3072, 1960, -3277, -2264 },
+ { 1841, 952, -4324, -2340 },
+ { 1994, 2200, -3940, -2923 },
+ { -1782, 1699, -4667, -1075 },
+ { -1464, 2906, -3468, -375 },
+ { 366, 2380, -3747, 1467 },
+ { -545, 1645, -4619, 376 },
+ { 1724, 2350, -2374, -3512 },
+ { 3184, 2628, -2996, -3275 },
+ { 734, 2010, -6239, -1479 },
+ { 524, 3756, -4496, -3263 },
+ { 1492, 3570, -3494, -3600 },
+ { -932, 618, -5389, -2894 },
+ { -133, 2161, -4083, -3267 },
+ { 786, 774, -3279, -3731 },
+ { 1078, 803, -3843, -3007 },
+ { -332, 3405, -3347, 40 },
+ { -17, 6, -4005, -3690 },
+ { -189, 4372, -4488, -2561 },
+ { -450, 3846, -3790, -1370 },
+ { 362, 2212, -5272, -15 },
+ { -1529, 791, -6802, -2296 },
+ { 2145, 4241, -4474, 376 },
+ { 1813, 2426, -2932, -2726 },
+ { -542, 4557, -3140, -1080 },
+ { 1192, 3784, -4371, -20 },
+ { 2784, 5188, -6399, -1394 },
+ { 431, 4561, -3673, -1398 },
+ { 1382, 3096, -4083, 1253 },
+ { 1209, 4224, -2930, 1500 },
+ { 2798, 2684, -6676, -606 },
+ { -2396, 1510, -5381, -2713 },
+ { -2625, 2542, -4032, -2880 },
+ { -1231, 3967, -4098, -2886 },
+ { -1393, 2374, -3862, -4525 },
+ { -2495, 1665, -1637, -5445 },
+ { -3854, 1759, -1750, -4944 },
+ { -2373, 1668, -2856, -6251 },
+ { -2668, 1981, -886, -4557 },
+ { -2927, 4427, -3451, -6172 },
+ { -1925, 2596, -4696, -2527 },
+ { -3202, 2847, -3928, -5896 },
+ { -3332, 1665, -5025, -3412 },
+ { -3212, 3115, -4155, -4062 },
+ { -1013, 3205, -5133, -3751 },
+ { -2022, 4595, -3947, -5611 },
+ { -3556, 1755, -3715, -2300 },
+ { -1784, 4114, -2723, -1773 },
+ { -3586, 4081, -2733, -4942 },
+ { -1608, 3685, -4154, -4573 },
+ { -3368, 4042, -4452, -6227 },
+ { -1407, 3881, -5729, -3719 },
+ { -2751, 3281, -5077, -4999 },
+ { -3791, 2410, -4906, -5288 },
+ { -730, 2303, -4217, -3755 },
+ { -1812, 2311, -5492, -3709 },
+ { -610, 4336, -3915, -3783 },
+ { -2841, 4337, -4278, -4430 },
+ { -1662, 4666, -4661, -3964 },
+ { -589, 5209, -4923, -3682 },
+ { -4155, 2234, -4076, -4218 },
+ { -3951, 2770, -2665, -2805 },
+ { -2302, 3228, -3717, -1908 },
+ { -3129, 4373, -2264, -2851 },
+ { -447, 1363, -3578, -4323 },
+ { -2648, 4237, -3159, -3071 },
+ { -4072, 3241, -3541, -4605 },
+ { -4507, 3458, -2339, -3838 },
+ { -1646, 997, -4926, -3970 },
+ { -3025, 1614, -3940, -1242 },
+ { -1337, 1756, -3163, -5529 },
+ { -3203, 1865, -3282, -4354 },
+ { -1646, 2118, -2203, -6018 },
+ { 174, 1871, -2707, -4639 },
+ { -2607, 1485, -4778, -4750 },
+ { -2199, 3991, -3134, -4879 },
+ { -2962, 3323, -2816, -2419 },
+ { -5286, 2495, -4548, -5395 },
+ { -2810, 3710, -2274, -4211 },
+ { -330, 3006, -2993, -4678 },
+ { -1187, 2411, -2743, -5196 },
+ { -664, 4033, -3101, -5641 },
+ { -1458, 3602, -2816, -5371 },
+ { -4116, 4923, -3321, -5630 },
+ { -4165, 2528, -2592, -4798 },
+ { -2759, 3080, -2333, -5719 },
+ { -5157, 3011, -5526, -6348 },
+ { -3095, 2126, -5881, -4234 },
+ { -4377, 3849, -3600, -6099 },
+ { -1994, 4947, -5235, -4753 },
+ { -1067, 600, -3258, -5133 },
+ { -4992, 3302, -2208, -5051 },
+ { -3377, 2981, -1655, -4815 },
+ { -3325, 2446, -1787, -6116 },
+ { -2341, 2737, -3240, -6347 },
+ { -2258, -3732, 3710, -1235 },
+ { -1558, -3849, 2694, -3012 },
+ { -599, -4837, 3050, -2951 },
+ { -2246, -5433, 2798, -1910 },
+ { -2255, -4989, 3260, 270 },
+ { -3026, -5353, 2693, -1036 },
+ { -1151, -6097, 1097, -3782 },
+ { -3391, -6012, 2130, -1303 },
+ { -2850, -4422, 3375, -480 },
+ { -1138, -3779, 1491, -4162 },
+ { -551, -3892, 3787, -2082 },
+ { -3221, -3676, 3144, -1202 },
+ { -3023, -5196, 2650, 605 },
+ { -1756, -5729, 2646, 321 },
+ { -2693, -4409, 494, -4797 },
+ { -1913, -4573, 3372, -1730 },
+ { -1277, -3604, 4061, -993 },
+ { -420, -4993, 1351, -4796 },
+ { -3052, -5333, 1435, -1242 },
+ { -602, -5034, 3869, -1141 },
+ { -2436, -4680, 1665, -3019 },
+ { -2657, -3658, 1459, -3391 },
+ { -1220, -6246, 2749, -525 },
+ { -3838, -4844, 2265, -1735 },
+ { -1247, -5679, 3356, -1417 },
+ { -917, -5448, 3342, 105 },
+ { -1756, -6839, 2276, -2350 },
+ { -412, -5206, 1764, -3539 },
+ { -1439, -6915, 1442, -3750 },
+ { -1381, -4439, 3863, -282 },
+ { -3482, -4953, 2726, -336 },
+ { -1376, -5931, 1714, -1987 },
+ { -1716, -4405, 2608, 105 },
+ { -1590, -5191, 2652, -2704 },
+ { -2149, -6442, 2453, -1263 },
+ { -3426, -3832, 2334, -1829 },
+ { -2747, -5948, 2362, -173 },
+ { -2435, -3267, 2966, -1710 },
+ { -3979, -4282, 2705, -775 },
+ { -356, -4238, 2544, -4343 },
+ { -1363, -6471, 2817, -1836 },
+ { -2878, -5117, 218, -3149 },
+ { -3539, -5196, 1710, -2356 },
+ { -2888, -4537, 2746, -1701 },
+ { -1870, -4439, 1496, -4121 },
+ { -1486, -3388, 3349, -2145 },
+ { -3333, -4138, 1467, -2876 },
+ { -345, -5340, 1012, -1190 },
+ { -1672, -4992, 2289, -1029 },
+ { -2146, -5528, 3038, -635 },
+ { -316, -3656, 3426, -3152 },
+ { -2695, -5812, 2336, -2050 },
+ { -2067, -6052, 737, -3258 },
+ { -2664, -4205, -350, -1266 },
+ { -617, -5406, 80, -4853 },
+ { -2418, -3825, 1853, -1326 },
+ { -1961, -4339, 583, -4315 },
+ { -1495, -5141, -133, -5205 },
+ { -3208, -6440, 1691, -2069 },
+ { -2632, -3633, 2325, -2761 },
+ { -2624, -5670, 1252, -3676 },
+ { -3687, -5608, 687, -2833 },
+ { -3320, -5707, 16, -3877 },
+ { -2738, -6112, 84, -5135 },
+ { 2277, -5661, 3076, 843 },
+ { 1555, -5769, 2821, -5236 },
+ { 536, -6381, 603, -4910 },
+ { 734, -4609, 3314, -4092 },
+ { 1836, -4547, 3267, -4322 },
+ { -13, -5976, 3752, -1607 },
+ { 1423, -6318, 2336, 398 },
+ { 365, -7779, 1498, -534 },
+ { 2104, -8366, 2946, -1345 },
+ { 143, -5545, 1898, -3756 },
+ { 655, -6852, 1430, 148 },
+ { 4, -6653, 2397, -59 },
+ { 2346, -5996, 4562, -934 },
+ { 1229, -7104, 2963, -598 },
+ { -528, -7048, 2887, -1790 },
+ { 1451, -6857, 3900, -1637 },
+ { 554, -6018, 3336, 9 },
+ { 3278, -5758, 4034, 129 },
+ { 3541, -7145, 4905, -1575 },
+ { 2339, -6907, 3464, -301 },
+ { 2775, -7301, 1667, -3894 },
+ { 539, -7887, 991, -4156 },
+ { 2115, -7421, 3131, -3075 },
+ { 2803, -8546, 2564, -5836 },
+ { 2869, -5833, 1620, -4561 },
+ { 2591, -7281, 3215, -4719 },
+ { -1228, -8477, 706, -4782 },
+ { 1967, -5243, 4813, -1940 },
+ { 701, -7010, 2273, -3893 },
+ { 915, -8470, 1918, -5620 },
+ { -94, -6715, 156, -3873 },
+ { 1074, -5607, 4389, -1017 },
+ { 2739, -6551, 1227, -3521 },
+ { 725, -7835, 2701, -1291 },
+ { -493, -7475, 2263, -1075 },
+ { -412, -6508, 2984, -744 },
+ { 665, -5451, 3725, -2692 },
+ { 1499, -8129, 3564, -2072 },
+ { 2870, -6333, 4487, -2108 },
+ { 706, -5007, 3911, -152 },
+ { -482, -8660, 1483, -2900 },
+ { 2481, -6596, 2518, -1715 },
+ { 1403, -6414, 1398, -5387 },
+ { 652, -6267, 583, -5942 },
+ { 694, -7540, 646, -6272 },
+ { 2275, -7614, 256, -5015 },
+ { 1416, -9727, 1900, -3153 },
+ { 2760, -6433, 3875, -3771 },
+ { 2325, -11196, 2182, -5155 },
+ { 1223, -11061, 1377, -5097 },
+ { 108, -10603, 307, -4952 },
+ { -118, -8268, 1650, -1572 },
+ { 1839, -7943, 1755, -612 },
+ { 2501, -9056, 981, -2969 },
+ { 2902, -8476, 1491, -5780 },
+ { 1995, -11175, 1585, -3643 },
+ { 696, -8212, 828, -2474 },
+ { 1526, -8649, 1380, -1210 },
+ { 461, -7253, 3222, -2229 },
+ { 2966, -8641, 4121, -3271 },
+ { 833, -6039, 2361, -1086 },
+ { 3565, -7312, 1980, -5427 },
+ { 2850, -8671, 3760, -1846 },
+ { 2643, -7281, 2163, -173 },
+ { 3463, -3706, -3132, -923 },
+ { 1315, -3825, -3443, 2 },
+ { 2594, -4083, -3815, 670 },
+ { 1826, -4291, -2741, -155 },
+ { 868, -3749, -4175, -298 },
+ { 2008, -4237, -3897, -517 },
+ { 1242, -3493, -4335, -1335 },
+ { -88, -4142, -3390, -1529 },
+ { 2176, -3488, -3822, -975 },
+ { 1706, -5188, -3415, -637 },
+ { 2717, -6159, -2333, -882 },
+ { 1276, -3978, -4361, 537 },
+ { 2471, -5556, -2866, -208 },
+ { 799, -4673, -4086, 56 },
+ { 1901, -4786, -3533, 270 },
+ { 3036, -3902, -3606, -333 },
+ { 2249, -3317, -4319, -144 },
+ { 2594, -4207, -2105, -2930 },
+ { 4008, -4774, -2626, -902 },
+ { 1038, -3659, -3496, -2454 },
+ { 2725, -3597, -3298, -1535 },
+ { 1662, -5803, -2813, 175 },
+ { 705, -3757, -3441, -1484 },
+ { 1860, -5987, -2821, -886 },
+ { 3786, -4918, -2199, -1929 },
+ { 3683, -4235, -2547, -1287 },
+ { 2531, -4896, -2956, -1593 },
+ { 1005, -5585, -3324, -180 },
+ { 1625, -5229, -1756, -3642 },
+ { 1494, -5041, -2989, -2685 },
+ { 2718, -4655, -3224, -867 },
+ { 2374, -6640, -1745, -2975 },
+ { 2133, -6436, -2477, -1499 },
+ { 1833, -4418, -3523, -1512 },
+ { 1128, -4910, -2658, -1106 },
+ { 689, -4777, -2831, -2085 },
+ { 3593, -5280, -2627, -315 },
+ { 3264, -3771, -2673, -1861 },
+ { 3202, -5602, -2409, 402 },
+ { 552, -4618, -2221, -3002 },
+ { 3095, -5356, -2666, -1083 },
+ { 3401, -4609, -3146, 45 },
+ { 3051, -4662, -2192, -2232 },
+ { 2798, -5552, -2462, -1941 },
+ { 2354, -5815, -2223, -2619 },
+ { 192, -3708, -2807, -2658 },
+ { 1886, -4226, -1862, -3529 },
+ { 2526, -3976, -2819, -2332 },
+ { 1577, -3870, -2711, -2806 },
+ { 1288, -5588, -3382, -1403 },
+ { 2711, -5399, -1564, -3253 },
+ { 1459, -5492, -2222, -322 },
+ { 2823, -5091, -2886, 776 },
+ { 3559, -5821, -2109, -1360 },
+ { 1587, -6331, -2760, -1909 },
+ { 2139, -5213, -2874, -2120 },
+ { 1318, -4337, -3695, -2098 },
+ { 821, -4471, -1849, -565 },
+ { 3329, -4782, -1725, -89 },
+ { 582, -4914, -4105, -1119 },
+ { 417, -4144, -4072, -2529 },
+ { -199, -3803, -2765, -4042 },
+ { 2731, -4283, -2143, 1 },
+ { 2911, -6187, -1951, -2116 },
+ { 1573, -6094, -493, -2838 },
+ { 2081, -6927, -864, -3211 },
+ { 1058, -7826, 79, -364 },
+ { 3147, -5570, -684, -978 },
+ { 3572, -5856, 1060, 1824 },
+ { 1143, -6702, -1478, 338 },
+ { 2341, -7220, -88, 260 },
+ { 3639, -6861, 668, 815 },
+ { 2227, -6268, -1706, 446 },
+ { 3390, -6082, -353, 1302 },
+ { 1123, -7556, -1237, -430 },
+ { 1729, -7742, 729, -218 },
+ { 1457, -6774, 587, 579 },
+ { 505, -6919, -569, 371 },
+ { 1106, -7245, 78, 158 },
+ { 2755, -6745, -1122, 338 },
+ { 3069, -6040, -1415, 986 },
+ { 2174, -7064, -1430, -283 },
+ { 1390, -8626, -446, -3031 },
+ { 3534, -6890, -431, 547 },
+ { 2267, -9618, 475, -2994 },
+ { 3672, -7673, 75, -115 },
+ { 2131, -7560, -1206, -750 },
+ { 2972, -7477, -685, -262 },
+ { 1604, -6637, -672, 699 },
+ { 1666, -7577, -577, -240 },
+ { 1591, -6554, -2158, -94 },
+ { 2348, -6286, -353, 1123 },
+ { 2017, -8810, -412, -1805 },
+ { 2892, -6713, -1765, -554 },
+ { 2500, -6828, -1995, -1197 },
+ { 3877, -6639, -224, -1655 },
+ { 2392, -7872, -91, -333 },
+ { 3562, -7370, -532, -2836 },
+ { 2552, -7614, 164, -1805 },
+ { 990, -6104, 218, 438 },
+ { 910, -7861, 312, -1195 },
+ { 1472, -6327, 372, -640 },
+ { 1576, -7143, -1983, -843 },
+ { 422, -7625, -457, -278 },
+ { 1797, -8532, 405, -1011 },
+ { 1088, -7396, -238, -2277 },
+ { 3209, -6753, -1431, -2072 },
+ { 2617, -6839, 100, -2573 },
+ { 2575, -8573, -387, -3188 },
+ { 3618, -6971, -1190, -321 },
+ { 2205, -7361, -1695, -2008 },
+ { 2985, -6297, 1464, 1179 },
+ { 2804, -7310, 1053, 338 },
+ { 1362, -6074, -1163, -840 },
+ { 3336, -6325, -1794, 21 },
+ { 2836, -8109, 818, -329 },
+ { 2791, -5879, 560, 1546 },
+ { 2392, -6064, 135, 100 },
+ { 1838, -6194, 596, 1085 },
+ { 1926, -7515, -414, -4901 },
+ { 3225, -7298, -1202, -1189 },
+ { 3960, -7558, -659, -719 },
+ { 3442, -6647, -1692, -1095 },
+ { 3381, -6441, 262, -886 },
+ { 1431, -8150, -1186, -1406 },
+ { 340, -8498, -150, -899 },
+ { 3004, -8149, -260, -953 },
+ { 2749, -6611, 563, 873 },
+ { -6647, -1325, -4517, -4691 },
+ { -6005, -1657, -4089, -3797 },
+ { -3157, 588, -5213, -3068 },
+ { -3311, -1425, -6329, -3726 },
+ { -5866, -819, -3857, -2744 },
+ { -5001, -1799, -1075, -4621 },
+ { -5330, -2650, -2672, -4664 },
+ { -4930, -539, -2363, -4010 },
+ { -2984, 10, -3863, -5749 },
+ { -1055, -2106, -3713, -4267 },
+ { -5476, -502, -4279, -6504 },
+ { -5231, -1543, -5018, -6425 },
+ { -5134, -363, -3165, -5109 },
+ { -3953, -771, -4107, -6393 },
+ { -2159, -563, -3652, -5342 },
+ { -3888, -2321, -919, -5057 },
+ { -1236, -597, -4235, -4193 },
+ { -4053, 675, -3083, -6174 },
+ { -2793, -1089, -5396, -3460 },
+ { -3000, -44, -2209, -6575 },
+ { -3336, -1531, -4313, -5160 },
+ { -2127, 128, -4851, -3692 },
+ { -3321, 136, -2067, -5660 },
+ { -5215, 1404, -4374, -4356 },
+ { -2747, 400, -6340, -3691 },
+ { -3926, -599, -5361, -5006 },
+ { -2875, -2592, -5143, -4092 },
+ { -4991, -1958, -5322, -4891 },
+ { -4965, -1318, -6652, -5333 },
+ { -4920, -1691, -3388, -5561 },
+ { -3644, -3354, -2688, -5982 },
+ { -5076, -919, -4563, -2984 },
+ { -6114, 250, -3884, -3915 },
+ { -4014, 744, -3973, -1924 },
+ { -5543, -1041, -5557, -3847 },
+ { -4711, -1352, -5649, -2603 },
+ { -3362, 775, -5305, -4879 },
+ { -5001, 107, -3554, -2888 },
+ { -6258, -1651, -6356, -6566 },
+ { -4529, 407, -5003, -3865 },
+ { -5154, 550, -5278, -5465 },
+ { -4195, -467, -1894, -3129 },
+ { -5022, 1127, -3349, -3314 },
+ { -6075, 1250, -4313, -5641 },
+ { -2677, -2283, -2312, -5903 },
+ { -4113, 193, -1195, -4833 },
+ { -3940, -1048, -1389, -5079 },
+ { -3703, 917, -4043, -4451 },
+ { -3366, -4231, -1534, -5488 },
+ { -3326, -3583, -2091, -4903 },
+ { -5144, 1254, -2532, -4949 },
+ { -5982, -870, -2545, -4555 },
+ { -3925, -157, -5367, -2281 },
+ { -6419, -746, -5668, -4371 },
+ { -5787, 518, -7096, -5805 },
+ { -4258, 954, -6453, -4321 },
+ { -4771, -695, -4158, -1639 },
+ { -7078, -760, -5195, -5877 },
+ { -7348, 83, -4101, -4586 },
+ { -2430, 184, -2874, -1679 },
+ { -2284, -3943, -2924, -5034 },
+ { -1804, -1785, -3002, -4710 },
+ { -4399, -2772, -1815, -4637 },
+ { -6340, -2626, -2824, -5191 },
+ { -4998, -5168, -3480, 1905 },
+ { -3958, -5492, -1599, 1579 },
+ { -2471, -3755, -276, 3182 },
+ { -3033, -5779, -1063, 1554 },
+ { -2936, -4829, -1290, 2386 },
+ { -1835, -5073, -3051, 1299 },
+ { -1724, -3771, -3935, 2324 },
+ { -5070, -2550, -3692, 768 },
+ { -4326, -5333, -297, 1878 },
+ { -3472, -5619, -3094, 992 },
+ { -3027, -4384, -3038, 2265 },
+ { -3201, -5332, 67, 2200 },
+ { -1681, -4373, -1947, 2461 },
+ { -3221, -3329, -4238, 2564 },
+ { -1262, -2968, -2915, 3227 },
+ { -3419, -1878, -3373, 2110 },
+ { -2244, -5583, -2012, 1288 },
+ { -1971, -5266, -990, 1812 },
+ { -2975, -2778, -452, 4063 },
+ { -2198, -1165, -3298, 2965 },
+ { -4782, -4894, -4767, 664 },
+ { -6002, -3950, -2806, 2025 },
+ { -3142, -3162, -2859, 3295 },
+ { -3262, -3340, -4123, 1596 },
+ { -4014, -3918, -1955, 3361 },
+ { -1700, -3463, -1346, 3449 },
+ { -4245, -4445, -4743, 1644 },
+ { -4180, -3969, -401, 3281 },
+ { -2782, -5240, -4117, 1156 },
+ { -5744, -4040, -1439, 3470 },
+ { -5063, -4663, -323, 3172 },
+ { -4531, -3319, -844, 3988 },
+ { -6226, -5125, -2064, 2976 },
+ { -3115, -3267, -1531, 3898 },
+ { -4628, -4421, -2864, 2808 },
+ { -4559, -2989, -3442, 2024 },
+ { -1775, -4487, -656, 2477 },
+ { -2664, -1865, -1884, 4081 },
+ { -1828, -2575, -3894, 3378 },
+ { -6441, -3677, -2025, 1677 },
+ { -4141, -2156, -1191, 3474 },
+ { -4802, -1623, -1727, 2160 },
+ { -5474, -2745, -1475, 2498 },
+ { -3664, -1056, -1975, 2491 },
+ { -4672, -3062, -2235, 2933 },
+ { -4205, -5960, -2849, 1517 },
+ { -4995, -5708, -1739, 1805 },
+ { -4892, -6080, -4793, 872 },
+ { -4270, -4172, -4263, 2185 },
+ { -4687, -1470, -2905, 1023 },
+ { -6446, -5017, -3919, 1000 },
+ { -6046, -5538, -3943, 2006 },
+ { -6028, -3750, -3953, 771 },
+ { -5959, -4582, -5024, 824 },
+ { -5818, -2576, -2249, 1326 },
+ { -5659, -5345, -1119, 2500 },
+ { -3346, -4155, 606, 2749 },
+ { -5680, -4827, -2501, 1838 },
+ { -6193, -2543, -1295, 840 },
+ { -6871, -4925, -3512, 1801 },
+ { -5605, -1788, -1895, 779 },
+ { -3922, -5712, -4644, 510 },
+ { -4745, -3869, -4533, 99 },
+ { -2984, -4907, -399, 1497 },
+ { 1847, -478, 3061, -5812 },
+ { 4450, -1116, 3609, -6570 },
+ { 3139, 99, 3007, -5532 },
+ { 2590, -3782, 3138, -4770 },
+ { 1881, 1204, 5778, -3404 },
+ { 3631, 2060, 5566, -5038 },
+ { 3461, 1961, 5167, -3800 },
+ { 2947, 273, 4536, -4389 },
+ { 4453, -1730, 5788, -4370 },
+ { 4032, 1805, 2666, -4534 },
+ { 3487, -944, 2313, -6028 },
+ { 1313, 34, 4210, -4067 },
+ { 5632, -1502, 5825, -5855 },
+ { 7736, -547, 4879, -5476 },
+ { 4906, -1512, 4760, -5760 },
+ { 3843, 447, 1091, -4958 },
+ { 2982, -1135, 5442, -4386 },
+ { 3579, 271, 3031, -6770 },
+ { 3932, -211, 4688, -5507 },
+ { 4411, 1720, 2387, -5584 },
+ { 5379, -479, 4575, -6280 },
+ { 3613, -362, 2012, -4885 },
+ { 3744, -2013, 4493, -5073 },
+ { 5693, 109, 4379, -3362 },
+ { 5475, -621, 5317, -3985 },
+ { 6411, -673, 5708, -4752 },
+ { 4933, -796, 7262, -4290 },
+ { 2804, 444, 6276, -3655 },
+ { 4120, -517, 6078, -4531 },
+ { 5119, 841, 3486, -3910 },
+ { 4738, 1539, 3525, -2970 },
+ { 5086, 370, 5895, -5640 },
+ { 4235, 2716, 4589, -5044 },
+ { 3691, 682, 6199, -4700 },
+ { 6111, -570, 6271, -6528 },
+ { 2611, 1277, 3756, -4802 },
+ { 4395, 970, 3807, -5879 },
+ { 5225, 2299, 3242, -4333 },
+ { 5144, 1778, 4946, -5545 },
+ { 2989, -3016, 3247, -5495 },
+ { 2983, 920, 2071, -6059 },
+ { 5270, -903, 4434, -2350 },
+ { 6415, -585, 3970, -3554 },
+ { 3866, -197, 5216, -2884 },
+ { 3767, -1298, 6702, -3315 },
+ { 6299, 2620, 5284, -6824 },
+ { 6654, 646, 3653, -4927 },
+ { 4770, 3047, 5160, -6287 },
+ { 5364, 434, 2919, -5207 },
+ { 2998, 1344, 4801, -2456 },
+ { 3896, 1013, 3773, -1864 },
+ { 2115, 655, 2999, -6344 },
+ { 5170, -981, 2849, -4464 },
+ { 2735, -2159, 2717, -5776 },
+ { 2430, -1952, 4392, -4559 },
+ { 6143, -1180, 3659, -4746 },
+ { 4978, -1483, 1726, -4875 },
+ { 3486, -2383, 3306, -4301 },
+ { 1434, -1372, 4171, -4770 },
+ { 3354, -2627, 1525, -5093 },
+ { 6790, 2386, 3995, -5909 },
+ { 1475, -2674, 3451, -4204 },
+ { 1999, -3494, 3693, -5556 },
+ { 4764, -2848, 2856, -5589 },
+ { -3677, 5131, 2827, -2934 },
+ { -2844, 7078, 2852, -3580 },
+ { -3902, 6434, 4118, -1911 },
+ { -1769, 7530, 3492, -3541 },
+ { -1937, 5679, -447, -1127 },
+ { -2456, 4680, 4196, -2407 },
+ { -2778, 8241, 1698, -4288 },
+ { -2876, 6104, 5182, -2387 },
+ { -2802, 7341, 4463, -2938 },
+ { -1025, 6267, 4752, -3201 },
+ { -2349, 5413, 2041, -3794 },
+ { -2252, 8225, 2856, -4269 },
+ { -1465, 4967, 4976, -2500 },
+ { -636, 7565, 3517, -4233 },
+ { -1905, 5618, 3904, -2942 },
+ { -302, 6816, 3343, -3316 },
+ { -2210, 4156, 2817, -3511 },
+ { -717, 6568, 1863, -2951 },
+ { -3873, 5682, 2164, -575 },
+ { -2878, 5835, 440, -2597 },
+ { -3228, 7701, 2610, -2514 },
+ { -3608, 8888, 3377, -2468 },
+ { -2582, 9717, 2519, -3126 },
+ { -5238, 6202, 2866, -2831 },
+ { -3428, 7370, 3056, -335 },
+ { -1681, 8836, 1210, -2010 },
+ { -3276, 6724, 1156, -3930 },
+ { -894, 8149, 827, -1258 },
+ { -2965, 8631, 2549, -1320 },
+ { -3961, 6902, 3581, 55 },
+ { -1894, 7745, 1750, -841 },
+ { -821, 6844, 850, -676 },
+ { -608, 6948, -4, -1376 },
+ { 615, 6524, 1089, -1147 },
+ { -2972, 5668, 1091, -489 },
+ { -157, 4649, 2904, -413 },
+ { 673, 5121, 1498, -66 },
+ { -390, 5902, 1611, -245 },
+ { -2349, 5478, 4772, -1320 },
+ { 88, 6798, 1972, -1859 },
+ { -1213, 5120, 2991, 200 },
+ { -2347, 6040, 2839, 376 },
+ { -578, 5976, 3364, -1796 },
+ { -1391, 5872, 3002, -965 },
+ { -564, 4496, 3946, -1186 },
+ { -2299, 6386, 3135, -2176 },
+ { -2131, 5641, 2011, 1223 },
+ { -772, 5807, 1124, 895 },
+ { -2837, 6758, 2297, -740 },
+ { -3091, 6298, 1415, -2126 },
+ { -4197, 6036, 1843, -3022 },
+ { -41, 6459, 92, 344 },
+ { -2241, 6860, 2095, -4396 },
+ { -1931, 7088, 2117, -2135 },
+ { -2375, 4422, 1688, -3169 },
+ { -1742, 6674, 1538, -119 },
+ { -4818, 7749, 4192, -1577 },
+ { -2004, 5672, 193, -430 },
+ { -3825, 6042, 2128, -1898 },
+ { -1108, 8033, 2119, -3013 },
+ { -2370, 5453, 1721, 266 },
+ { -1570, 7134, 614, -2638 },
+ { -1519, 8752, 3503, -4330 },
+ { -2050, 3845, 2907, -1126 },
+ { 5085, 4412, -335, -1923 },
+ { 3618, 1423, -613, -4012 },
+ { 4481, 3729, 589, -4631 },
+ { 4270, 3216, -1763, -3168 },
+ { 4241, 1796, -1701, -2796 },
+ { 4787, 2338, -487, -3639 },
+ { 2915, 3429, -621, -4753 },
+ { 5175, 1660, -1265, -3223 },
+ { 4280, 4057, -684, -4079 },
+ { 4980, 4419, -1455, -2719 },
+ { 5436, 2464, 387, -4197 },
+ { 4507, 4018, 1121, -3314 },
+ { 6020, 2401, -413, -3201 },
+ { 4200, 3789, -333, -2813 },
+ { 5229, 2493, -1194, -1878 },
+ { 5851, 2695, -492, -2292 },
+ { 5743, 3288, -697, -1221 },
+ { 5692, 2612, 979, -2227 },
+ { 5085, 2067, 1046, -1214 },
+ { 3163, 2240, -2098, -3435 },
+ { 5228, 1898, 145, -2397 },
+ { 5860, 3976, -418, -2872 },
+ { 6008, 3399, 1027, -3506 },
+ { 4126, 2035, 1865, -893 },
+ { 5375, 3596, 511, -2362 },
+ { 1937, 1493, -852, -122 },
+ { 3473, 4849, 547, -2603 },
+ { 4631, 2977, 1141, -1768 },
+ { 6149, 3050, -71, -1886 },
+ { 4069, 4353, -289, -1429 },
+ { 2884, 1225, -1388, 365 },
+ { 5485, 2518, -235, -571 },
+ { 1216, 4375, 1443, 398 },
+ { 4988, 3106, 107, -1435 },
+ { 4511, 2801, 307, -444 },
+ { 3235, 4386, 327, -676 },
+ { 2055, 3708, 1657, -305 },
+ { 5839, 2374, 290, -1385 },
+ { 5110, 3305, 1936, -4206 },
+ { 6416, 2920, 338, -2736 },
+ { 3350, 2824, -1269, -3881 },
+ { 4840, 1815, 464, 186 },
+ { 2399, 3332, 238, 1238 },
+ { 3516, 1363, 1582, 688 },
+ { 3582, 1874, 154, -4770 },
+ { 3261, 2878, 886, 283 },
+ { 3877, 2658, -327, 884 },
+ { 4151, 3436, 2173, -2923 },
+ { 3592, 3674, 1281, -1295 },
+ { 4561, 3730, -1114, -1747 },
+ { 4595, 3625, -558, -575 },
+ { 2577, 2348, 2267, 120 },
+ { 5242, 3299, 32, -3412 },
+ { 4264, 3637, 709, -2320 },
+ { 6556, 3570, -838, -2472 },
+ { 5745, 4014, -940, -1973 },
+ { 5629, 4475, 477, -3328 },
+ { 5269, 3199, 1682, -3085 },
+ { 4432, 2416, 1145, -3299 },
+ { 4465, 2505, 2162, -2186 },
+ { 4643, 4941, -88, -2885 },
+ { 4568, 5231, 552, -3915 },
+ { 5667, 3075, -1406, -2963 },
+ { 5418, 5259, -771, -2818 },
+ { -256, -7875, 511, -471 },
+ { -1813, -7971, -424, -396 },
+ { -306, -7006, 862, 282 },
+ { -2306, -6422, -1440, 508 },
+ { -245, -6787, 375, -100 },
+ { -1309, -6065, -20, 779 },
+ { -1656, -6047, -641, 1307 },
+ { -1496, -6522, 964, 726 },
+ { -2291, -6588, -202, 795 },
+ { -762, -7522, 1454, -558 },
+ { -2270, -7004, -834, -580 },
+ { -1139, -7078, 259, 362 },
+ { -2535, -7568, -1040, 49 },
+ { -3786, -7280, 934, -476 },
+ { -3336, -6368, 606, 1056 },
+ { -3602, -6924, 52, 714 },
+ { -2278, -6550, 1674, 204 },
+ { -2855, -5765, 930, 1530 },
+ { -2889, -7325, -215, 305 },
+ { -2749, -6080, -237, 1452 },
+ { -985, -6667, 1577, 400 },
+ { -2036, -6083, 380, 1267 },
+ { -2077, -7460, 380, -30 },
+ { -1775, -7175, 1540, -386 },
+ { -3065, -6927, 989, 168 },
+ { -2836, -7602, 117, -3392 },
+ { -1058, -6396, 593, -3078 },
+ { -844, -6062, 999, -236 },
+ { -3261, -6951, 1491, -720 },
+ { -2186, -8484, 75, -1287 },
+ { -2882, -7756, 456, -510 },
+ { -1800, -6879, 960, -1183 },
+ { -2554, -7241, 1614, -1474 },
+ { -2608, -5305, 392, 851 },
+ { -2973, -6562, -859, 858 },
+ { -2640, -5989, 1031, -416 },
+ { -977, -8366, 705, -1434 },
+ { -1213, -7409, -77, -1390 },
+ { -1335, -6657, 2125, -123 },
+ { -2544, -6862, 1852, -737 },
+ { -3235, -6422, 1752, -103 },
+ { -1300, -7557, 939, -348 },
+ { -3476, -7579, 202, -109 },
+ { -2482, -6572, 753, 619 },
+ { -2554, -8136, -648, -429 },
+ { -1012, -7870, -3, -421 },
+ { -3604, -6247, 32, -3102 },
+ { -1486, -7271, 2013, -1021 },
+ { -578, -6799, -523, 405 },
+ { -2841, -5948, 1644, 911 },
+ { -2411, -7473, 1084, -484 },
+ { -2238, -6033, 294, -1059 },
+ { -3459, -6470, -201, -790 },
+ { -2027, -6009, 1833, 805 },
+ { -1433, -8047, 1531, -1754 },
+ { -3258, -7884, 763, -1422 },
+ { -1544, -6928, -729, 478 },
+ { -2314, -8415, 74, -3757 },
+ { -3201, -5684, 95, -2214 },
+ { -2423, -8694, 725, -3631 },
+ { -3545, -7071, 1162, -1798 },
+ { -294, -9662, 403, -2274 },
+ { -2290, -5460, 1196, 402 },
+ { -1603, -6713, 903, -2363 },
+ { 4121, 2491, -3142, -2482 },
+ { 4500, 3305, -3671, -1567 },
+ { 5973, 3172, -1348, -534 },
+ { 4830, 3379, -1549, 643 },
+ { 5214, 3938, -2641, -2302 },
+ { 4639, 4826, -5532, -847 },
+ { 5639, 2731, -2170, -963 },
+ { 6084, 3487, -3525, -1346 },
+ { 5971, 3154, -2190, -2316 },
+ { 5618, 4865, -6927, 116 },
+ { 5345, 3568, -7391, 709 },
+ { 5429, 5078, -3811, -1524 },
+ { 6960, 2037, -3515, -1096 },
+ { 7092, 2531, -4557, -588 },
+ { 6061, 4247, -5651, -478 },
+ { 4595, 3684, -4907, -827 },
+ { 7497, 3213, -3048, -424 },
+ { 5996, 2137, -3098, -1745 },
+ { 6198, 5199, -2223, -2274 },
+ { 6888, 2851, -2768, -1675 },
+ { 6114, 4210, -2316, -954 },
+ { 7127, 4242, -3041, -1408 },
+ { 6126, 3668, -1517, -1427 },
+ { 6245, 6129, -4225, -1186 },
+ { 6816, 3213, -2101, -964 },
+ { 5345, 5276, -2643, -847 },
+ { 6592, 4665, -4338, 484 },
+ { 6746, 3751, -3443, 124 },
+ { 5453, 1980, -2738, 2606 },
+ { 4662, 2179, -4226, -1059 },
+ { 5571, 3208, -3554, 174 },
+ { 5256, 4447, -1815, -1481 },
+ { 5400, 2570, -1210, 235 },
+ { 7056, 2549, -2674, 318 },
+ { 4574, 4340, -2892, -130 },
+ { 6203, 4587, -3273, -305 },
+ { 5103, 1925, -2715, -2137 },
+ { 3905, 4296, -1700, 247 },
+ { 4421, 4605, -3299, 811 },
+ { 5671, 1273, -3870, -924 },
+ { 5486, 1805, -4901, 133 },
+ { 6437, 2578, -1828, -106 },
+ { 5530, 5253, -5058, 1223 },
+ { 4816, 2025, -1215, 1443 },
+ { 3457, 3525, -2456, 3217 },
+ { 3316, 2595, -1108, 2459 },
+ { 3068, 3810, -2207, 1926 },
+ { 6351, 5436, -6470, 600 },
+ { 6324, 4240, -5365, 2416 },
+ { 4851, 4774, -4075, 1878 },
+ { 4900, 3679, -5198, 1078 },
+ { 8347, 3633, -4565, -171 },
+ { 5244, 5718, -3853, 173 },
+ { 3960, 3492, -2939, 2105 },
+ { 6070, 3473, -2351, 161 },
+ { 8228, 3034, -3360, -901 },
+ { 7006, 3985, -1940, -1926 },
+ { 7123, 4681, -4301, -878 },
+ { 5122, 4097, -1851, -449 },
+ { 6200, 2060, -2251, 1049 },
+ { 7106, 3844, -7209, 2625 },
+ { 7108, 3370, -6734, 533 },
+ { 6859, 2849, -3992, 1360 },
+ { 5458, 2278, -3253, 1131 },
+ { -1072, -2109, 4783, -1073 },
+ { -319, -2604, 4257, -2418 },
+ { 2466, 1300, 3476, -314 },
+ { 2847, -1502, 5296, -141 },
+ { 1667, -1273, 5559, -2725 },
+ { 2877, -3402, 6434, 204 },
+ { 53, -2637, 5275, -1181 },
+ { 1091, -2215, 5803, -1549 },
+ { 2397, -922, 4327, 1182 },
+ { 219, -3747, 4647, -1564 },
+ { -29, -2705, 4812, 1277 },
+ { 1499, -2608, 5648, 1407 },
+ { 2139, -2399, 4202, 2791 },
+ { -426, -2064, 5528, 151 },
+ { 2560, -2803, 6179, -2806 },
+ { 4537, -2479, 3797, 1095 },
+ { 888, -3357, 5341, -415 },
+ { 4460, -1814, 5388, -1227 },
+ { 3920, -3268, 6364, -703 },
+ { 3343, -4698, 4410, 784 },
+ { 309, -1897, 6306, 1223 },
+ { 958, -3318, 4254, -3167 },
+ { -99, 1596, 6018, -1983 },
+ { -429, -853, 6407, 878 },
+ { 1170, -1322, 6290, -417 },
+ { 2288, -505, 6303, -1999 },
+ { 3312, -1674, 6749, -2494 },
+ { -415, -3401, 4721, -371 },
+ { -189, -1210, 4844, -2002 },
+ { 888, -4142, 4377, 130 },
+ { 2469, -4381, 5398, -2492 },
+ { 2879, -2912, 5094, -2598 },
+ { -717, -617, 5650, -685 },
+ { 1470, -3863, 5352, -1684 },
+ { 3935, -96, 3823, -730 },
+ { 3769, -430, 3168, 694 },
+ { 2556, 385, 3539, 512 },
+ { 77, -1415, 5111, 2655 },
+ { 2724, -2158, 6715, -822 },
+ { 1832, 1001, 5385, -1900 },
+ { 900, 2198, 4464, -559 },
+ { 441, 69, 5921, -1743 },
+ { -1161, 738, 6732, -308 },
+ { 257, 2035, 4091, 736 },
+ { 1607, 1288, 4355, -23 },
+ { -13, 1316, 4180, 1672 },
+ { 1511, 1336, 3057, 1435 },
+ { 2189, -3813, 4530, 939 },
+ { 3632, -706, 2646, 1375 },
+ { 4266, -3761, 4241, 1077 },
+ { 3101, -427, 5273, -1202 },
+ { 2293, 276, 4810, -313 },
+ { 3430, -1851, 3101, 2045 },
+ { 3453, -2979, 5142, 942 },
+ { 1683, -3281, 4802, 2002 },
+ { 3954, -4715, 5611, 578 },
+ { 1272, -155, 5085, 454 },
+ { 128, -194, 5095, 1409 },
+ { 820, 880, 5797, -2658 },
+ { -1095, 656, 5774, 1095 },
+ { 813, -1669, 4320, -3251 },
+ { -119, 518, 6372, -651 },
+ { 2922, -4299, 6115, -877 },
+ { 4205, -4273, 4004, 2642 },
+ { -1211, -3892, 224, 3127 },
+ { -34, -4371, 1321, 2318 },
+ { 77, -6326, 1201, 828 },
+ { 3995, -3775, 1958, 3233 },
+ { 178, -3301, 1985, 3318 },
+ { 2330, -3801, 1033, 3195 },
+ { 1413, -5536, 826, 1709 },
+ { 2468, -3499, 3653, 3631 },
+ { 741, -4617, 1723, 2008 },
+ { 1246, -3043, 2978, 3949 },
+ { -343, -4308, 2258, 2189 },
+ { -682, -4640, 454, 2272 },
+ { 1236, -4829, 2491, 1642 },
+ { -512, -3766, 1182, 3052 },
+ { 119, -3939, 3712, 971 },
+ { -1145, -4624, 1360, 2281 },
+ { 101, -4746, 2866, 1255 },
+ { -1500, -5455, 539, 1637 },
+ { -969, -5909, 1414, 1128 },
+ { -1261, -4939, -231, 2022 },
+ { -226, -5345, 1207, 705 },
+ { 2712, -5109, 3205, 1866 },
+ { -476, -5913, 273, 1208 },
+ { -2039, -4464, 624, 2545 },
+ { -2351, -3930, 2019, 2673 },
+ { -2675, -4849, 1522, 1990 },
+ { -1524, -3461, 1446, 3204 },
+ { 477, -5314, 1710, 1577 },
+ { 656, -3729, 2346, 2511 },
+ { 550, -5917, 1975, 1040 },
+ { 1728, -4704, 3067, 1058 },
+ { -9, -5247, 506, 1760 },
+ { -574, -5135, 1675, 1672 },
+ { 2129, -3781, 3444, 2313 },
+ { 1144, -4439, 2214, 2529 },
+ { 1292, -4160, 3185, 1833 },
+ { 2445, -3262, 2534, 3227 },
+ { 2266, -4401, 2023, 2400 },
+ { -587, -3602, 3408, 2067 },
+ { -885, -4951, 3228, 1174 },
+ { -728, -2711, 2807, 3552 },
+ { 1019, -3043, 3195, 2954 },
+ { 1888, -4615, 1140, 2454 },
+ { 660, -5616, 754, 800 },
+ { -1975, -5371, 1649, 1585 },
+ { -1544, -5436, 2422, 1081 },
+ { -422, -5882, 2390, 750 },
+ { 1336, -5557, 2441, 1230 },
+ { 136, -4001, 267, 2854 },
+ { -522, -3289, 2226, 2728 },
+ { -971, -4580, 2471, 708 },
+ { 704, -5306, 3300, 1001 },
+ { 325, -3464, 3555, 2398 },
+ { 794, -3686, 848, 3169 },
+ { 660, -3017, 4584, 3242 },
+ { -1486, -3978, 2170, 1644 },
+ { -1615, -4650, 2688, 1844 },
+ { 750, -4578, 538, 2239 },
+ { 1668, -5849, 1455, 1031 },
+ { 3486, -4681, 2030, 2183 },
+ { 2642, -5429, 1696, 1761 },
+ { 4491, -4502, 3538, 2767 },
+ { 3545, -4528, 3514, 2982 },
+ { 3269, -3676, 2758, 3966 },
+ { 5572, 1146, 209, -3379 },
+ { 7459, 1053, 593, -1896 },
+ { 4480, 200, -310, -4259 },
+ { 5577, -939, 242, -3992 },
+ { 8142, 442, 1257, -3083 },
+ { 5442, 1261, 1424, -3236 },
+ { 6260, -183, 3125, -2532 },
+ { 7179, 889, 1618, -2548 },
+ { 6416, 932, 2379, -2487 },
+ { 7094, 2560, 961, -3392 },
+ { 7322, 463, 2732, -3735 },
+ { 6632, 1577, 1912, -3272 },
+ { 6312, 1349, 3028, -3460 },
+ { 6105, 386, 1213, -977 },
+ { 5478, 1158, 1114, -486 },
+ { 6493, 410, 1686, -2180 },
+ { 6378, 1881, 1333, -2240 },
+ { 5711, 812, 1958, -1300 },
+ { 6844, 877, 730, -1189 },
+ { 6824, -245, 2249, -2000 },
+ { 7515, 1521, 1251, -3058 },
+ { 6697, 1051, 1300, -1749 },
+ { 6476, 1425, 811, -2773 },
+ { 7350, 465, -76, -2849 },
+ { 6975, 2095, 567, -2492 },
+ { 4691, 1736, 2660, -2289 },
+ { 7837, 1456, 340, -2767 },
+ { 7930, 507, 838, -2074 },
+ { 6106, 1502, 766, -1110 },
+ { 4891, -659, 835, -3954 },
+ { 7250, 141, 1369, -1523 },
+ { 7651, 67, 1651, -2298 },
+ { 7364, -305, 601, -3132 },
+ { 7179, 193, 2491, -2871 },
+ { 6504, -272, 2167, -1322 },
+ { 4456, 983, 2300, -421 },
+ { 4817, 457, 1695, 371 },
+ { 6914, 555, 850, -3159 },
+ { 5904, 1030, 202, -1959 },
+ { 6258, 880, 2233, -4503 },
+ { 6029, 10, 2130, -3600 },
+ { 6449, 985, 1129, -3963 },
+ { 6616, -18, -111, -3285 },
+ { 4496, 775, 817, -4276 },
+ { 6134, 2338, 1470, -2973 },
+ { 6911, 152, 430, -1946 },
+ { 4053, 991, 3218, -1193 },
+ { 5435, 1285, 3124, -2412 },
+ { 5507, 1836, 1935, -1988 },
+ { 5240, 689, 2189, -2670 },
+ { 6638, 1719, 606, -1799 },
+ { 5556, -180, 129, -2595 },
+ { 5644, 1918, 1281, -4316 },
+ { 6410, 1088, -282, -3117 },
+ { 6503, 1841, 312, -3514 },
+ { 6947, 20, 1358, -3886 },
+ { 5464, 2109, 2398, -3194 },
+ { 5616, -407, 2140, -498 },
+ { 6121, 2707, 2379, -4096 },
+ { 7303, 1846, 2266, -4095 },
+ { 5444, 470, 2718, -1553 },
+ { 5817, -645, 3285, -1349 },
+ { 5625, 1427, 1103, -1991 },
+ { 6041, -806, 1196, -2943 },
+ { 3050, -5722, 4070, -5460 },
+ { 3420, -4386, 4078, -5155 },
+ { 6020, -3982, 7268, -2689 },
+ { 7502, -4317, 7894, -3973 },
+ { 4156, -3558, 5247, -4316 },
+ { 4725, -4401, 7290, -1540 },
+ { 6688, -5122, 8216, -3210 },
+ { 9176, -6576, 9276, -4963 },
+ { 8706, -5708, 7987, -4621 },
+ { 7060, -3535, 6532, -3308 },
+ { 5600, -2719, 5363, -1568 },
+ { 4661, -2803, 6263, -4716 },
+ { 3673, -3636, 6147, -3433 },
+ { 5305, -2585, 6073, -2638 },
+ { 7614, -1962, 6079, -5266 },
+ { 6760, -3366, 7382, -4322 },
+ { 6385, -3883, 4797, -1353 },
+ { 8182, -5120, 4298, -4641 },
+ { 9130, -6198, 4975, -3063 },
+ { 7421, -5436, 5576, -3713 },
+ { 3483, -4898, 5443, -2745 },
+ { 4907, -5643, 6390, -4105 },
+ { 8119, -7008, 7992, -6764 },
+ { 6528, -6122, 6967, -5590 },
+ { 5890, -4190, 6624, -5688 },
+ { 6815, -7934, 7275, -5456 },
+ { 5434, -4306, 5169, -5378 },
+ { 4364, -6436, 5376, -2604 },
+ { 8152, -3404, 5913, -5048 },
+ { 7983, -4863, 4262, -2461 },
+ { 8023, -6188, 6238, -5062 },
+ { 6753, -3692, 3935, -3723 },
+ { 6826, -4760, 3284, -4051 },
+ { 7224, -7423, 4492, -3875 },
+ { 6904, -2590, 6587, -6248 },
+ { 6106, -1944, 7345, -5506 },
+ { 4956, -2990, 7808, -3146 },
+ { 6908, -6885, 5949, -1288 },
+ { 7162, -6058, 3419, -3401 },
+ { 7015, -7080, 6907, -3018 },
+ { 6971, -6832, 5646, -3273 },
+ { 8014, -5546, 5471, -1544 },
+ { 6792, -2220, 5105, -2879 },
+ { 8494, -3974, 4408, -3999 },
+ { 9591, -4866, 6027, -4558 },
+ { 5264, -5161, 6101, -738 },
+ { 5803, -6141, 5197, -5231 },
+ { 4657, -6822, 3232, -5189 },
+ { 4791, -5135, 3809, -4665 },
+ { 6108, -5103, 2379, -3873 },
+ { 4680, -3909, 3234, -5093 },
+ { 5802, -3853, 3795, -4984 },
+ { 4360, -7483, 4802, -3877 },
+ { 5429, -7517, 5911, -3717 },
+ { 6866, -2280, 4880, -4634 },
+ { 10131, -4628, 4414, -4092 },
+ { 10811, -5189, 7746, -5337 },
+ { 5663, -8941, 5287, -5680 },
+ { 8023, -5991, 7403, -2796 },
+ { 9669, -6919, 6525, -4932 },
+ { 7275, -3796, 4962, -2547 },
+ { 8848, -4806, 5677, -3080 },
+ { 8128, -4308, 7749, -6569 },
+ { 4032, -5196, 2282, -6239 },
+ { 6593, 700, -229, 304 },
+ { 8260, 539, -66, -1259 },
+ { 6605, 176, -814, -109 },
+ { 8057, 0, -1, -136 },
+ { 7382, -38, -484, -1129 },
+ { 8373, -929, 682, -454 },
+ { 7674, 690, -1278, 546 },
+ { 7326, -517, 406, -1283 },
+ { 7612, -1715, -1167, 1175 },
+ { 8590, 441, -782, -710 },
+ { 8572, -1202, -291, 260 },
+ { 7308, -147, -1785, 414 },
+ { 6787, -353, -672, 934 },
+ { 5177, -133, 179, 82 },
+ { 4161, -34, 447, 1497 },
+ { 5997, -902, 1533, -121 },
+ { 5727, -871, -1370, 945 },
+ { 8386, -252, 293, -823 },
+ { 6573, -1354, 682, 616 },
+ { 7650, -2096, 725, 457 },
+ { 8122, 78, 636, -1400 },
+ { 8421, 428, -1620, 131 },
+ { 7341, -1292, -717, 186 },
+ { 7998, -49, -720, 266 },
+ { 5987, -351, 669, 844 },
+ { 7314, -1620, 250, -603 },
+ { 7219, -1562, -572, 1994 },
+ { 8682, -358, -290, -388 },
+ { 5810, 155, -178, 1199 },
+ { 7246, -12, 1042, -786 },
+ { 7357, -923, 1468, -475 },
+ { 7801, 621, -212, -724 },
+ { 5346, -514, 1210, 1356 },
+ { 8459, 36, -127, -779 },
+ { 6878, -2429, 854, 1750 },
+ { 7280, -1401, -1353, 2845 },
+ { 7579, -2148, -1463, 2087 },
+ { 6637, 946, -872, 750 },
+ { 4807, -1100, 1289, 2602 },
+ { 4495, 219, 1551, 1128 },
+ { 7639, 506, 446, -1107 },
+ { 6359, 188, 1009, -115 },
+ { 6641, -1820, 1655, 723 },
+ { 5394, -2382, 1604, 2542 },
+ { 6021, -2644, 2396, 1407 },
+ { 4698, 882, 245, 1525 },
+ { 8103, 573, -798, -349 },
+ { 8045, -519, 997, -1092 },
+ { 7571, -122, 227, -338 },
+ { 5347, -1200, 630, 1718 },
+ { 7070, 790, 218, -544 },
+ { 7440, 728, -527, -20 },
+ { 6402, -355, 197, -736 },
+ { 4031, 771, 866, 1895 },
+ { 6009, 896, 445, -31 },
+ { 5160, 1098, -856, 1784 },
+ { 7980, -886, -1293, 1396 },
+ { 6318, -1361, 2423, 252 },
+ { 7547, -699, 133, 506 },
+ { 8562, -2344, 940, 264 },
+ { 5890, 1187, -1425, 2194 },
+ { 6558, -645, -1311, 2621 },
+ { 4634, -1671, 2075, 1623 },
+ { 5614, 105, -816, 2376 },
+ { 6646, 1558, -1365, 630 },
+ { 6998, 1150, -2117, -990 },
+ { 6555, 2311, -1093, -1783 },
+ { 6682, 1430, -2391, -1940 },
+ { 7861, 1555, -2977, -1188 },
+ { 6745, 1723, -459, -2085 },
+ { 7504, 1229, -1666, -2060 },
+ { 7937, 671, -2128, -1529 },
+ { 7139, 991, -735, -2632 },
+ { 6867, 1592, -1303, -2324 },
+ { 6401, 2230, -1732, -2508 },
+ { 7201, 2184, -2169, -1988 },
+ { 6636, 2190, -995, -2840 },
+ { 7620, 2306, -2089, -651 },
+ { 7584, 1875, -1438, -631 },
+ { 9214, 1561, -2464, -1139 },
+ { 6154, 1318, -1237, -2917 },
+ { 7917, 2847, -1797, -1599 },
+ { 8309, 2029, -2555, -465 },
+ { 8204, 1282, -584, -2405 },
+ { 8440, 1035, -1147, -1137 },
+ { 7107, 1858, -60, -1568 },
+ { 6781, 2912, -873, -1463 },
+ { 7603, 1316, -319, -1249 },
+ { 7833, 1335, -78, -1849 },
+ { 7930, 1141, -1016, -695 },
+ { 7883, 1610, -1017, -1314 },
+ { 8069, 1409, -1811, -196 },
+ { 8319, 1031, -582, -1590 },
+ { 5948, 1537, -2153, -2373 },
+ { 8684, 1171, -1871, -850 },
+ { 8357, 2484, -2411, -1292 },
+ { 6516, 2092, -193, -1167 },
+ { 6112, 1697, 22, -525 },
+ { 7161, 703, -602, -1879 },
+ { 6047, 2351, -807, -219 },
+ { 8072, 1854, -1817, -1553 },
+ { 6956, 1304, 76, -1011 },
+ { 6607, 1481, -544, -162 },
+ { 6958, 2541, -265, -1938 },
+ { 6416, 2514, -777, -850 },
+ { 7272, 2110, -899, -1171 },
+ { 7741, 2153, -283, -2614 },
+ { 6482, 2041, -1758, -1221 },
+ { 6762, 940, -1862, -2281 },
+ { 5610, 1194, -1691, -1561 },
+ { 7833, 2164, -823, -1952 },
+ { 5460, 1438, -848, 1189 },
+ { 6011, 1377, -771, -1557 },
+ { 7679, 544, -1134, -2214 },
+ { 7209, 1292, -2714, -1564 },
+ { 5567, 1200, -404, -169 },
+ { 5853, 1461, -1465, -518 },
+ { 6782, 689, -844, -860 },
+ { 7330, 1337, -1152, -71 },
+ { 7189, 1506, -653, -685 },
+ { 6860, 2116, -1403, -240 },
+ { 8804, 1516, -1391, -1760 },
+ { 7210, 2689, -1498, -989 },
+ { 7030, 3022, -1441, -2083 },
+ { 5649, 1836, -407, 525 },
+ { 7451, 3099, -717, -2464 },
+ { 7384, 1656, -2007, 398 },
+ { 6504, 707, -1919, -134 },
+ { -1851, 3639, -2279, -695 },
+ { -4037, 1644, -77, 1329 },
+ { -4025, 1960, -1565, -567 },
+ { -3430, 2495, -795, 368 },
+ { -4771, 2480, 993, 756 },
+ { -3431, 2058, -2539, -971 },
+ { -3802, 3418, 380, 217 },
+ { -3074, 3350, -1652, -1056 },
+ { -3705, 326, -1650, 1535 },
+ { -3122, 1281, -1192, 1607 },
+ { -4601, 1367, -968, 53 },
+ { -3808, 958, 44, 2560 },
+ { -2079, 2530, -1485, 1166 },
+ { -3707, 343, -2889, 180 },
+ { -5249, 1431, -31, 688 },
+ { -4990, 125, -704, 1270 },
+ { -2771, 1334, -2446, 746 },
+ { -2292, 994, -1527, 2630 },
+ { -1261, 3070, -2519, 268 },
+ { -2544, 3890, -1057, -552 },
+ { -4421, 255, -1980, 530 },
+ { -2951, 454, -13, 3643 },
+ { -2262, 1815, -370, 2880 },
+ { -2383, 3657, -649, 576 },
+ { -3541, -161, -1389, 2550 },
+ { -4241, 1575, 1325, 2561 },
+ { -2767, 4037, 1221, 1578 },
+ { -3748, 2697, 1148, 1801 },
+ { -4686, 2385, -220, 0 },
+ { -1531, 1645, -2751, 1327 },
+ { -45, 4032, -799, 2298 },
+ { -2915, 2280, 709, 2495 },
+ { -1199, 3278, -406, 2346 },
+ { -2471, 116, -2706, 2060 },
+ { -2440, 2173, -2894, -344 },
+ { -3375, 2287, 1781, 3226 },
+ { -2153, 3568, 1827, 2918 },
+ { -862, 2267, -1626, 2527 },
+ { -2698, 1135, 301, 4239 },
+ { -2364, 2123, 1010, 3710 },
+ { -2447, 3281, -81, 1408 },
+ { -2660, 4735, 472, 258 },
+ { -1053, 3097, 2682, 2398 },
+ { -3366, -1037, -1152, -868 },
+ { -643, 4242, 2212, 1259 },
+ { 971, 3991, 934, 643 },
+ { -1617, 2002, 2139, 2195 },
+ { -4897, 972, 784, 1719 },
+ { -1275, 2992, 1039, 3821 },
+ { -392, 4973, -209, 1821 },
+ { -1028, 4718, -1479, -137 },
+ { 50, 3914, 553, 2210 },
+ { 678, 4364, 359, 1303 },
+ { -582, 4911, 514, 1671 },
+ { 1276, 3914, -1252, 2934 },
+ { -1496, 3984, 857, 2330 },
+ { 772, 4744, -655, 2332 },
+ { -799, 5283, -439, 624 },
+ { 1341, 2937, 650, 2027 },
+ { -1739, 4892, 1275, 1702 },
+ { -892, 2596, -151, 3951 },
+ { -3532, 1090, 1292, 32 },
+ { 321, 3146, 2647, 1475 },
+ { 264, 4199, -1591, 1317 },
+ { -452, -2357, 2266, 4192 },
+ { 3022, -1033, -2389, 5678 },
+ { -1162, -1342, 3543, 4990 },
+ { -474, -1477, -1223, 5016 },
+ { -699, -2857, 900, 3835 },
+ { -461, -2255, -117, 4626 },
+ { 1204, -2062, -1211, 4403 },
+ { 2192, -3035, -337, 3966 },
+ { 108, -831, 279, 5643 },
+ { 1457, -620, -2908, 5276 },
+ { -2527, -78, 1085, 5460 },
+ { -1978, -1918, -949, 4733 },
+ { 32, 367, -1904, 5166 },
+ { 1890, -1665, 440, 4752 },
+ { -518, -348, 2816, 4891 },
+ { 3695, -2490, -1374, 4603 },
+ { 246, -1965, 3549, 3969 },
+ { 1100, -3111, 656, 3737 },
+ { -1379, 870, -414, 4575 },
+ { 628, -357, -1227, 6179 },
+ { -1129, -1318, -2457, 4576 },
+ { -425, -98, -73, 6336 },
+ { 367, -887, 2990, 4207 },
+ { 2091, -1251, 2444, 3557 },
+ { -1759, -1610, 2046, 5273 },
+ { 3210, 1414, -20, 2616 },
+ { 3303, -2636, 1005, 4237 },
+ { -327, -3107, -640, 3687 },
+ { -197, 764, 572, 5486 },
+ { 646, -767, 1388, 5464 },
+ { 104, 2742, -228, 3907 },
+ { -236, 1829, -579, 4585 },
+ { -2150, -474, -1525, 4006 },
+ { -23, -2632, -2400, 3892 },
+ { -12, -1739, -2910, 4867 },
+ { -2310, -368, -102, 4583 },
+ { -1991, -2061, 533, 4531 },
+ { 3884, -1446, -153, 4393 },
+ { 1568, 14, -289, 5268 },
+ { -1376, -253, -2797, 3417 },
+ { 3193, -2577, 2475, 3566 },
+ { 3418, 617, 1350, 1857 },
+ { 3792, -24, -272, 3370 },
+ { 153, 1159, 2906, 2877 },
+ { 511, 2162, 1548, 2741 },
+ { 262, 819, -2791, 3734 },
+ { 4232, -2015, 1486, 3477 },
+ { 2943, -1110, -1014, 5480 },
+ { 2842, 369, 703, 3476 },
+ { 3011, 1634, -933, 3553 },
+ { 4412, -1548, -942, 5021 },
+ { -1405, 593, 2372, 5267 },
+ { 2093, 2129, 896, 2365 },
+ { 4845, -1980, 0, 3823 },
+ { -2140, 81, 3278, 5637 },
+ { 1484, 2665, -324, 3653 },
+ { 10, 192, 1620, 5291 },
+ { 2152, 738, -2269, 5000 },
+ { 2102, 2748, -1652, 4707 },
+ { 2855, -2131, -387, 5188 },
+ { 1173, 676, 1338, 3277 },
+ { 2340, -2329, -2064, 4095 },
+ { 861, -2024, 1296, 5055 },
+ { 2189, 3225, -695, 2626 },
+ { 6196, -7079, 1943, -822 },
+ { 4547, -4813, 3261, 1856 },
+ { 4243, -6904, 3443, 448 },
+ { 4581, -7503, 946, 506 },
+ { 6626, -7754, 3427, 470 },
+ { 3407, -9088, 3269, -1496 },
+ { 4079, -6464, 2304, 777 },
+ { 5621, -9336, 2684, -768 },
+ { 5351, -6464, 5238, -214 },
+ { 5961, -8007, 1724, -3091 },
+ { 4213, -8067, 603, -246 },
+ { 7208, -7403, 3168, -1738 },
+ { 6098, -7700, 329, -1379 },
+ { 6525, -6735, 4248, -1072 },
+ { 6073, -6241, 2167, -2378 },
+ { 4609, -9218, 3051, -1033 },
+ { 6813, -7283, 1581, -1897 },
+ { 6126, -6275, 2789, 681 },
+ { 4423, -6538, 1621, -1692 },
+ { 6272, -8298, 3167, -1855 },
+ { 6172, -8558, 4498, -1169 },
+ { 4844, -8588, 1647, -366 },
+ { 6209, -8807, 1581, -369 },
+ { 5389, -8059, 550, -192 },
+ { 6654, -9775, 2504, -1063 },
+ { 7103, -7998, 806, 530 },
+ { 5662, -6736, 1565, -3620 },
+ { 4165, -9564, 4191, -2131 },
+ { 4526, -7181, 576, -2875 },
+ { 4633, -8623, 2807, -4742 },
+ { 3709, -7794, 1815, 34 },
+ { 3634, -8622, 2313, -826 },
+ { 6991, -8447, 2063, -3198 },
+ { 7757, -9486, 2255, -558 },
+ { 4149, -7778, 4728, -1696 },
+ { 5767, -7427, 1113, 707 },
+ { 4592, -6261, 2329, 1864 },
+ { 3159, -10498, 1677, -4273 },
+ { 3534, -9010, 2437, -3565 },
+ { 4479, -10821, 2715, -4942 },
+ { 3207, -9805, 3054, -3886 },
+ { 4627, -8189, 3018, -2354 },
+ { 5527, -10566, 3244, -2749 },
+ { 4346, -10127, 3335, -3084 },
+ { 6132, -10085, 3316, -1308 },
+ { 5629, -9704, 2178, -3058 },
+ { 3603, -8538, 1246, -624 },
+ { 3737, -8488, 395, -3167 },
+ { 5465, -11414, 2810, -4640 },
+ { 5306, -7745, 2721, -3988 },
+ { 7000, -9111, 1695, -1409 },
+ { 6663, -7741, 2466, -4079 },
+ { 4083, -7175, 1836, -4831 },
+ { 3613, -9926, 1342, -3455 },
+ { 6588, -8033, 457, -258 },
+ { 4720, -8102, 17, -1209 },
+ { 7414, -8709, 1294, -344 },
+ { 5437, -10030, 4043, -1704 },
+ { 4862, -9281, 1558, -1431 },
+ { 6800, -6403, 5113, 862 },
+ { 4623, -8242, 2667, -228 },
+ { 5919, -5083, 3348, 2135 },
+ { 5985, -8889, 2733, -5105 },
+ { 5029, -5767, 4407, 719 },
+ { 354, -6158, -838, -3001 },
+ { 351, -5943, -2104, -1534 },
+ { -633, -7190, -25, -4798 },
+ { -1595, -7235, -3812, -1400 },
+ { 103, -6197, -2933, -78 },
+ { -1722, -5020, -3441, -4333 },
+ { -1963, -5644, -4365, -270 },
+ { -846, -5743, -3477, 196 },
+ { -191, -5348, -4054, -469 },
+ { -2515, -7754, -3495, -818 },
+ { -2090, -6710, -2701, 117 },
+ { -546, -7036, -1398, 163 },
+ { -278, -7091, -2662, -536 },
+ { -622, -7962, -2731, -1464 },
+ { -1555, -8118, -3612, -2057 },
+ { -1094, -6280, -2314, 505 },
+ { -2556, -8538, -4024, -2247 },
+ { 109, -7134, -3107, -1823 },
+ { -900, -6954, -3340, -717 },
+ { -605, -7113, -3656, -2154 },
+ { 837, -6263, -3211, -2177 },
+ { -417, -5810, -3871, -1469 },
+ { -1318, -5649, -4207, -3198 },
+ { 413, -6765, -2082, -33 },
+ { -3101, -6450, -4362, -766 },
+ { 755, -6489, -2967, -846 },
+ { 1117, -7106, -2452, -1352 },
+ { -1202, -8387, -3072, -2897 },
+ { -365, -4894, -3561, -2937 },
+ { -2372, -8776, -265, -4441 },
+ { -1224, -8678, -896, -5074 },
+ { -755, -10096, -600, -6623 },
+ { 300, -8206, -225, -4568 },
+ { -1176, -6824, -2633, -3527 },
+ { -2006, -5443, -1526, -5849 },
+ { -1115, -5540, -2363, -4785 },
+ { 1059, -6812, -2543, -2654 },
+ { -1976, -6861, -3062, -5508 },
+ { -379, -5328, -2321, -3624 },
+ { -2108, -5860, -4518, -1915 },
+ { -379, -7885, -1329, -594 },
+ { 774, -5389, -581, -5213 },
+ { -2601, -5083, -1849, -4921 },
+ { -176, -5580, 74, -5075 },
+ { -204, -6780, -190, -6232 },
+ { 418, -7594, -1987, -820 },
+ { -1873, -8529, -2926, -1609 },
+ { 1340, -6362, -919, -4975 },
+ { 577, -7990, -2044, -1873 },
+ { -2572, -7413, -1745, -2224 },
+ { -2037, -7030, -1461, -7138 },
+ { -2559, -8756, -2039, -5836 },
+ { -2079, -6764, -1209, -5669 },
+ { -1613, -7801, -2006, -685 },
+ { -1865, -6583, -722, -3529 },
+ { -589, -6358, -1377, -1003 },
+ { -540, -7514, -1331, -3542 },
+ { 419, -6192, -1677, -4927 },
+ { -2786, -8763, -2966, -5065 },
+ { -2172, -8411, -1726, -4675 },
+ { -3382, -9833, -3497, -5722 },
+ { -2433, -10169, -2077, -5775 },
+ { -424, -9451, -1096, -3658 },
+ { -537, -8522, -910, -1897 },
+ { -5550, 2807, 1683, -693 },
+ { -6395, 635, 3573, -1246 },
+ { -7544, 2280, 2140, 44 },
+ { -8751, 1136, 2951, -794 },
+ { -5605, 2709, 2052, 916 },
+ { -7650, 654, 869, 135 },
+ { -6939, 967, 1409, 870 },
+ { -7834, 2123, 3310, 974 },
+ { -6935, 2818, 1274, -1678 },
+ { -5605, 2233, 1013, 471 },
+ { -7095, 1849, 1648, 198 },
+ { -6636, 1634, 712, -37 },
+ { -7279, 978, 296, -315 },
+ { -7664, 3504, 3292, -216 },
+ { -7836, 1209, 1221, -257 },
+ { -7913, 2201, 1765, -1529 },
+ { -7077, 3783, 2632, -1407 },
+ { -5565, 1645, 1410, -622 },
+ { -6494, 2879, 1181, -759 },
+ { -7073, 3137, 3010, 550 },
+ { -7249, 1839, 847, -805 },
+ { -6630, 2197, 282, -1096 },
+ { -8836, 1573, 1988, -1090 },
+ { -7809, 1274, 836, -1198 },
+ { -7895, 2970, 3511, -1097 },
+ { -6960, 1664, 1356, -2442 },
+ { -6582, 2866, 2273, 307 },
+ { -7221, 821, 2851, -1435 },
+ { -6015, 1703, 2001, -2367 },
+ { -8082, 1034, 2103, 239 },
+ { -5952, 1912, 301, -465 },
+ { -6099, 841, 379, 567 },
+ { -6343, 50, 494, 658 },
+ { -6586, 983, 591, -893 },
+ { -5500, 869, 2187, -2479 },
+ { -6482, 60, 1545, -979 },
+ { -6705, 515, 1974, -53 },
+ { -6460, 1755, 1325, -1275 },
+ { -6093, 2617, 2465, -623 },
+ { -7330, 2161, 594, -2115 },
+ { -7324, 762, 1593, -2004 },
+ { -6385, 679, 1510, -2514 },
+ { -6159, 241, 2976, -1631 },
+ { -8583, 3030, 4045, -162 },
+ { -6299, 66, 2209, -2103 },
+ { -5428, 1279, 3267, -1846 },
+ { -6438, 1335, 2728, -1631 },
+ { -8012, 1070, 2428, -1151 },
+ { -6201, 2781, 2349, -1918 },
+ { -5918, 1139, 3121, -148 },
+ { -6314, 2481, 3137, -1808 },
+ { -7180, 1722, 2435, -1602 },
+ { -6750, 1829, 3763, -1145 },
+ { -6713, 1777, 2221, 1212 },
+ { -7479, 1835, 3627, -479 },
+ { -7299, 10, 2406, -1593 },
+ { -8249, 3129, 996, -2870 },
+ { -8374, 1534, 1333, -1882 },
+ { -7507, 3353, 1598, -2299 },
+ { -7379, 2701, 2326, -1167 },
+ { -8440, 2276, 2796, -542 },
+ { -10348, 1527, 2649, -1165 },
+ { -8184, 3614, 2574, -1738 },
+ { -5539, 1574, 1733, 1138 },
+ { 9404, -7652, 67, 79 },
+ { 8654, -3972, 1358, -60 },
+ { 8617, -4794, 117, 2318 },
+ { 7886, -4505, 1784, 1200 },
+ { 8636, -6125, 3879, -1003 },
+ { 9654, -6836, 1816, 205 },
+ { 9374, -6553, 913, 1875 },
+ { 8020, -6150, 1134, 2390 },
+ { 7786, -4970, 2078, -1857 },
+ { 8691, -6119, 711, 708 },
+ { 9039, -5568, 2944, -1902 },
+ { 9955, -5048, 1433, -601 },
+ { 8089, -6927, 3093, -2846 },
+ { 8487, -7024, 2415, 19 },
+ { 9388, -5287, 3577, -2655 },
+ { 8591, -7371, 2300, -996 },
+ { 9104, -4763, 1453, -2558 },
+ { 7615, -5457, 596, 164 },
+ { 9860, -7047, 3433, -614 },
+ { 8756, -4404, 2235, -964 },
+ { 9462, -4660, 299, -1822 },
+ { 10119, -5550, 2689, -1273 },
+ { 10915, -7471, 2705, -1007 },
+ { 11433, -7090, 1410, -1198 },
+ { 9882, -7431, 2965, -1895 },
+ { 7628, -5219, 769, -2661 },
+ { 8169, -5318, 2262, 70 },
+ { 8846, -6320, 1939, -754 },
+ { 7147, -5593, 1248, -971 },
+ { 10652, -5485, 935, 137 },
+ { 7778, -6533, 2564, -1932 },
+ { 8878, -5173, 1214, -361 },
+ { 9828, -4943, 282, 510 },
+ { 10042, -6134, 3895, -1914 },
+ { 7965, -6630, 3566, -433 },
+ { 8573, -4502, 3574, -1209 },
+ { 8398, -4801, 1031, -1347 },
+ { 10136, -7772, 2612, 1547 },
+ { 9890, -7280, 1768, -1083 },
+ { 8407, -6585, -706, -58 },
+ { 7976, -7582, 229, -131 },
+ { 10481, -8866, 1166, -147 },
+ { 10914, -4342, 3189, -2412 },
+ { 10440, -5198, -104, -1109 },
+ { 11227, -6530, 2381, -2449 },
+ { 8487, -8064, 1086, 230 },
+ { 9975, -6123, -857, -134 },
+ { 8339, -6498, 1232, -2337 },
+ { 11042, -4506, 1119, -2098 },
+ { 12563, -5592, 1837, -2062 },
+ { 11801, -5590, 632, -1296 },
+ { 10152, -5617, 1511, -1917 },
+ { 7800, -6473, 51, -1337 },
+ { 7941, -5560, 2438, -3270 },
+ { 6554, -3834, 2100, 1476 },
+ { 9065, -5520, -226, -1120 },
+ { 10794, -7120, -243, 122 },
+ { 10429, -6968, 272, -806 },
+ { 8942, -8914, 1442, -392 },
+ { 9969, -5051, 2033, -2953 },
+ { 7275, -4152, 3058, -64 },
+ { 11127, -5488, 4589, -3227 },
+ { 9626, -6666, 2739, -2958 },
+ { 6943, -5362, 4470, 1008 },
+ { -7456, -967, 2936, -1002 },
+ { -8622, -333, 6962, 2606 },
+ { -7486, -3392, 3668, 1287 },
+ { -8053, -827, 5148, 1097 },
+ { -6610, 454, 4952, 96 },
+ { -7701, -1982, 3161, -468 },
+ { -7307, -1132, 4071, -36 },
+ { -8125, -271, 5199, 3862 },
+ { -9182, -1950, 2813, 1878 },
+ { -9855, -952, 4794, 3010 },
+ { -7241, 1431, 4202, 2468 },
+ { -9646, 157, 4766, 1046 },
+ { -9371, 1230, 6009, 2958 },
+ { -11514, -64, 8630, 5248 },
+ { -6766, 565, 2766, 2140 },
+ { -8426, -9, 2852, 1271 },
+ { -11291, -1113, 5087, 2937 },
+ { -8297, 2092, 4495, 1264 },
+ { -9983, 735, 3809, -51 },
+ { -9048, -1000, 3191, -308 },
+ { -7331, -1987, 2655, 1391 },
+ { -7144, -21, 4333, 2161 },
+ { -6032, -1540, 3543, 896 },
+ { -7987, -1036, 1985, 1529 },
+ { -9264, 2004, 5194, 290 },
+ { -11308, -840, 5754, 1654 },
+ { -9130, -2398, 4292, 2973 },
+ { -6248, 838, 3563, 1223 },
+ { -6819, -2760, 3511, 119 },
+ { -7213, -2006, 4364, 762 },
+ { -5431, -1047, 4533, 166 },
+ { -7098, -641, 2021, 639 },
+ { -8628, -2249, 3588, 399 },
+ { -6352, -1498, 3560, -648 },
+ { -7033, -2190, 4870, 2562 },
+ { -7405, -46, 3772, -581 },
+ { -6104, 796, 5143, 1965 },
+ { -5787, 943, 5784, 3030 },
+ { -8367, 1465, 7192, 4097 },
+ { -8259, 789, 5694, 1963 },
+ { -10614, -1899, 5748, 2645 },
+ { -8258, -805, 3698, 2275 },
+ { -6877, -972, 6431, 3160 },
+ { -6483, 363, 7018, 3129 },
+ { -6283, -1358, 5191, 1524 },
+ { -8853, -3157, 4119, 1741 },
+ { -6086, -267, 3883, -835 },
+ { -7254, 1032, 6613, 4017 },
+ { -11470, -3350, 4649, 3426 },
+ { -6743, 481, 6148, 1239 },
+ { -5394, -166, 5309, 3165 },
+ { -7958, 1068, 4268, -240 },
+ { -10520, 2256, 7916, 2828 },
+ { -5132, -4, 5739, 1176 },
+ { -8643, 120, 3255, -629 },
+ { -9631, 1974, 8870, 4362 },
+ { -10663, -1221, 3733, 589 },
+ { -8224, -1843, 5806, 2655 },
+ { -8282, 1255, 8647, 3478 },
+ { -12311, -1505, 9043, 6256 },
+ { -11312, -856, 7136, 4681 },
+ { -11944, -722, 7941, 3309 },
+ { -7868, -463, 6846, 4196 },
+ { -8679, -241, 7410, 5347 },
+ { 6759, -4680, -508, 1220 },
+ { 5176, -6111, 944, 121 },
+ { 6843, -5667, -1368, -533 },
+ { 5616, -5884, -1471, -695 },
+ { 6030, -5089, -1808, -940 },
+ { 7444, -5463, -52, 1881 },
+ { 4207, -6079, -506, 1571 },
+ { 6785, -4410, -649, 3084 },
+ { 4838, -5214, 2026, 2998 },
+ { 4201, -5790, 645, 1811 },
+ { 6930, -5129, -1940, 1698 },
+ { 6332, -4627, 692, 3027 },
+ { 6285, -4314, -106, 3644 },
+ { 6255, -5450, -1975, 742 },
+ { 4199, -4676, -459, 1796 },
+ { 5592, -5500, 1345, 1300 },
+ { 4358, -5556, -2236, 114 },
+ { 4620, -5875, -1563, 888 },
+ { 4892, -7550, -327, -419 },
+ { 4734, -7085, 7, 613 },
+ { 3883, -5562, -1969, 1080 },
+ { 5610, -4990, -204, 834 },
+ { 4117, -6482, -1271, 341 },
+ { 6585, -5107, 892, 1169 },
+ { 6632, -3683, 302, 3002 },
+ { 6326, -5351, -983, -1250 },
+ { 4382, -7192, -730, -158 },
+ { 5227, -6540, -451, 1123 },
+ { 5468, -6472, -870, -1471 },
+ { 5191, -6402, -1365, -127 },
+ { 7407, -6317, -973, -336 },
+ { 4611, -6530, -820, -1980 },
+ { 4963, -5159, -2050, -966 },
+ { 4414, -5691, -211, -998 },
+ { 5954, -5873, 750, -1749 },
+ { 4394, -4796, -1268, 254 },
+ { 7161, -6214, -1010, 689 },
+ { 4965, -3598, 2372, 1711 },
+ { 6248, -6180, 981, 864 },
+ { 6473, -5336, 525, -600 },
+ { 4591, -6864, -1131, -900 },
+ { 6314, -6440, -1021, -375 },
+ { 5838, -6209, -1199, 944 },
+ { 5308, -5283, -2100, 1267 },
+ { 4342, -5860, -1637, -1356 },
+ { 5680, -4388, -1227, -104 },
+ { 4900, -4098, 1449, 4046 },
+ { 4677, -4284, -106, 3190 },
+ { 7574, -6173, -848, 1859 },
+ { 6493, -7207, -131, 726 },
+ { 5513, -5261, -2117, 4 },
+ { 6191, -7352, -193, -505 },
+ { 5885, -4333, 324, -134 },
+ { 6162, -6081, -312, -2044 },
+ { 4216, -6200, -1810, -572 },
+ { 5652, -7035, -696, -197 },
+ { 7131, -7189, -366, -60 },
+ { 5032, -4803, -1514, 2832 },
+ { 7386, -4610, -606, 3489 },
+ { 4211, -5031, 1221, 3047 },
+ { 4050, -4653, 1584, 1469 },
+ { 6852, -5302, -1861, 206 },
+ { 7736, -4816, -1794, 3359 },
+ { 6290, -3439, 1522, 2454 },
+ { 1768, 5990, -5560, -2594 },
+ { 3903, 5326, -1530, -1501 },
+ { 2472, 3738, -2117, -4240 },
+ { 3260, 5448, -904, -4733 },
+ { 1435, 7297, -3676, -4102 },
+ { 4096, 5951, -656, -3312 },
+ { 2178, 6009, -3146, -3724 },
+ { 3787, 5493, -5473, -1633 },
+ { 2998, 7286, -3334, -3571 },
+ { 2894, 6576, -4708, -2804 },
+ { 830, 6163, -4286, -3348 },
+ { 4755, 5569, -1730, -2739 },
+ { 4604, 6065, -3562, -2605 },
+ { 2749, 5141, -3986, -2775 },
+ { 3942, 4875, -2143, -3340 },
+ { 2819, 8517, -2004, -2724 },
+ { 2146, 6298, -689, -3093 },
+ { 5196, 6504, -3393, -1475 },
+ { 1851, 8386, -1748, -1420 },
+ { 3474, 8572, -3534, -2688 },
+ { 4503, 7560, -3561, -2245 },
+ { 4433, 6219, -2393, -1575 },
+ { 3506, 7248, -2275, -1977 },
+ { 3490, 7409, -3147, -604 },
+ { 4214, 6447, -3520, 516 },
+ { 619, 7034, -829, -1705 },
+ { 1732, 7395, -356, -2208 },
+ { 1226, 5204, -3294, -3732 },
+ { 2027, 5619, -1813, -4146 },
+ { 3078, 5877, 47, -2651 },
+ { 1654, 5458, 424, -682 },
+ { 3163, 5464, -2026, -270 },
+ { 2884, 5375, -685, -530 },
+ { 2950, 7286, -35, -2967 },
+ { 1986, 5066, -597, 482 },
+ { 3459, 4308, -3845, -2333 },
+ { 3155, 7037, -1346, -4345 },
+ { 2193, 6696, -717, -1319 },
+ { 3677, 5089, -3892, -487 },
+ { 2186, 5136, -4186, -1492 },
+ { 773, 5796, -917, 817 },
+ { 2489, 6546, -3570, -2117 },
+ { 1223, 6469, -1362, -33 },
+ { 271, 6061, -1466, -1725 },
+ { 2540, 5171, -1847, 1032 },
+ { 2548, 5251, -2697, 1677 },
+ { 771, 7600, -768, -632 },
+ { 4710, 6647, -4736, -1275 },
+ { 1369, 5917, -2971, -1056 },
+ { 163, 5239, -3499, -2275 },
+ { 2104, 4285, -3211, -3286 },
+ { 1107, 7411, -1972, -1671 },
+ { 2196, 7262, -2310, -1926 },
+ { -244, 6439, -1745, -839 },
+ { 3293, 3832, -2890, -3000 },
+ { 419, 6443, -379, -407 },
+ { 3077, 4930, -1156, -2869 },
+ { 2131, 5874, -2330, 224 },
+ { 690, 6538, -2212, -2841 },
+ { 1602, 4421, -2515, 1542 },
+ { 3318, 9373, -3032, -3477 },
+ { 5646, 7462, -5153, -1463 },
+ { 4139, 7137, -1539, -3321 },
+ { 3481, 9077, -1645, -3653 },
+ { -7747, 375, -106, -543 },
+ { -8587, -1379, -586, -461 },
+ { -10146, -892, 2094, 694 },
+ { -8103, 382, 504, -325 },
+ { -8548, -92, 94, -656 },
+ { -7460, 38, 152, 388 },
+ { -8266, -271, -459, -883 },
+ { -7935, -664, -1026, -802 },
+ { -8341, -109, 853, 161 },
+ { -8802, -1355, 1099, 630 },
+ { -8957, -6, 1108, -669 },
+ { -7260, -1520, -43, -407 },
+ { -7555, -174, 668, -2562 },
+ { -9014, -126, 227, -1191 },
+ { -8184, 769, 290, -1375 },
+ { -9476, 55, 962, -1528 },
+ { -8679, 541, 755, -1030 },
+ { -9842, -1626, 838, -1588 },
+ { -8513, -702, 788, -1998 },
+ { -10101, -1558, -366, -1841 },
+ { -8135, 78, 1479, -1813 },
+ { -9128, -454, 313, -1786 },
+ { -7554, -1084, 831, -2442 },
+ { -7576, -701, 2068, -1665 },
+ { -7791, -1481, 1587, -1808 },
+ { -6701, -596, -97, 802 },
+ { -7418, -15, 684, -963 },
+ { -7127, -477, -139, -426 },
+ { -8097, -110, -36, -264 },
+ { -7620, -1922, -590, -101 },
+ { -7647, -1201, 279, 660 },
+ { -7856, -1974, 758, -2271 },
+ { -8496, -167, 2232, -1143 },
+ { -8506, -1359, 624, -740 },
+ { -7274, -1052, 1062, -139 },
+ { -7800, -217, 91, -1794 },
+ { -7030, -1694, -955, 615 },
+ { -9020, -1864, 101, -2182 },
+ { -9400, -740, 598, -667 },
+ { -8448, -1184, 2024, -1272 },
+ { -8812, -570, -897, -2384 },
+ { -10559, -1286, 538, -1536 },
+ { -8728, -888, -1089, -1397 },
+ { -7080, -1185, 636, -1252 },
+ { -9880, 233, 2344, -782 },
+ { -7952, -1326, -378, -1947 },
+ { -7207, -378, 1408, -2237 },
+ { -8467, -1545, 902, -1987 },
+ { -9163, -1474, 924, -1739 },
+ { -8159, -992, -77, -2744 },
+ { -8343, 148, -423, -1573 },
+ { -9105, -649, -254, -1214 },
+ { -8939, 456, 281, -1905 },
+ { -8837, 179, -394, -2634 },
+ { -9145, 757, 1547, -1319 },
+ { -9775, -723, 441, -1680 },
+ { -8910, -686, 1529, -1525 },
+ { -9492, -1134, 2064, -938 },
+ { -6111, -943, 677, -31 },
+ { -7411, -613, -814, 46 },
+ { -9479, -922, -430, -2061 },
+ { -11298, -1268, 1318, -1117 },
+ { -8190, 832, 671, -2214 },
+ { -10453, -550, 1672, -886 },
+ { 1044, 9353, -1651, -5423 },
+ { 1034, 8149, -455, -6166 },
+ { 761, 8293, -3214, -4838 },
+ { 938, 8077, 164, -5130 },
+ { 1295, 8673, 2582, -5490 },
+ { -314, 7973, -2395, -5231 },
+ { -507, 9012, -2497, -5775 },
+ { 2396, 8314, -1022, -4673 },
+ { -1516, 8501, 1950, -4969 },
+ { -308, 7401, 1549, -4866 },
+ { -112, 8340, 3003, -4920 },
+ { -50, 9315, 1371, -5666 },
+ { -659, 9449, 2496, -5547 },
+ { 2573, 9148, -2270, -4783 },
+ { 830, 7104, -438, -3907 },
+ { 522, 10672, -677, -6483 },
+ { -1190, 10108, -510, -6518 },
+ { -427, 8271, -579, -6315 },
+ { 1602, 8113, -1927, -4418 },
+ { -2266, 8180, 448, -5190 },
+ { -1633, 8816, -226, -5771 },
+ { 759, 9481, -105, -5813 },
+ { 2254, 6679, -466, -5662 },
+ { -88, 6946, 895, -5958 },
+ { -1705, 10009, 1394, -5574 },
+ { 748, 7943, 540, -6692 },
+ { 1411, 7009, 232, -6145 },
+ { 697, 7290, -1221, -5342 },
+ { -1764, 10580, 1944, -3981 },
+ { -1334, 9124, 1195, -3903 },
+ { -905, 10067, 635, -5039 },
+ { 664, 10680, 49, -4625 },
+ { 1374, 9536, -777, -3591 },
+ { 252, 9698, -597, -2931 },
+ { 824, 9164, -1014, -2144 },
+ { 2438, 10569, -2289, -4424 },
+ { 2101, 7102, 507, -3614 },
+ { 294, 8051, -432, -1518 },
+ { -665, 10337, 547, -2852 },
+ { 1168, 11989, -492, -5427 },
+ { 1344, 6416, 302, -5061 },
+ { -1727, 12264, 1507, -4543 },
+ { 674, 10889, -902, -3605 },
+ { -582, 9504, 300, -3618 },
+ { 641, 7654, 689, -2109 },
+ { 2065, 9243, 508, -4367 },
+ { 1055, 8373, 688, -3144 },
+ { -641, 8185, 986, -3307 },
+ { 1120, 7426, 1785, -3757 },
+ { 1660, 8070, -593, -3104 },
+ { 2002, 9467, -1722, -3475 },
+ { 2361, 8368, 100, -3709 },
+ { -772, 7845, -613, -4988 },
+ { 1485, 7430, 1896, -6127 },
+ { -432, 7823, -947, -2882 },
+ { 313, 11122, -760, -4871 },
+ { 412, 8412, -283, -4231 },
+ { 1585, 10402, -1884, -3267 },
+ { 321, 6952, 773, -3016 },
+ { -105, 9014, 121, -2249 },
+ { 1585, 10313, -977, -4812 },
+ { 1619, 11869, 1306, -6876 },
+ { -1168, 8886, -81, -2500 },
+ { -395, 10886, 733, -6490 },
+ { -4949, 4274, 3992, -1054 },
+ { -4241, 5299, 4262, -1584 },
+ { -2710, 3862, 4552, -1673 },
+ { -4608, 2472, 3672, -1715 },
+ { -2843, 2816, 4003, -2326 },
+ { -5229, 2964, 5636, 90 },
+ { -4924, 3442, 5015, -1096 },
+ { -1281, 3313, 5537, -2066 },
+ { -3808, 1939, 4351, -919 },
+ { -1915, 2585, 4939, -1614 },
+ { -3470, 1843, 5562, -682 },
+ { -3800, 870, 5827, 144 },
+ { -4985, 1452, 4728, -709 },
+ { -3745, 2750, 7220, 259 },
+ { -1875, 1900, 6514, -826 },
+ { -4329, 1574, 7192, 1304 },
+ { -5408, 1444, 6208, 631 },
+ { -3327, 5312, 5707, -1541 },
+ { -6966, 3334, 4034, 1028 },
+ { -7484, 4245, 4218, -212 },
+ { -6567, 5839, 4539, -512 },
+ { -5715, 5935, 3747, -1186 },
+ { -6410, 4881, 3356, -1610 },
+ { -5146, 2590, 2850, 2172 },
+ { -5196, 4095, 2569, -373 },
+ { -5043, 6025, 4318, 692 },
+ { -5525, 4884, 3513, 370 },
+ { -6804, 7533, 5812, -488 },
+ { -5657, 2480, 4061, 1234 },
+ { -3155, 1472, 6071, 1188 },
+ { -3427, 5217, 3442, 858 },
+ { -4698, 3013, 5517, 2586 },
+ { -4449, 2226, 5418, 3580 },
+ { -6395, 3547, 5487, 2028 },
+ { -3500, 5019, 4787, 1 },
+ { -4038, 2578, 3073, 3151 },
+ { -2750, 1955, 4469, 3856 },
+ { -5696, 1659, 6118, 2469 },
+ { -4350, 1241, 6840, 3126 },
+ { -5565, 5058, 5196, 1314 },
+ { -1642, 4190, 3948, 607 },
+ { -1233, 4108, 4850, -640 },
+ { -997, 3428, 3239, 1378 },
+ { -6488, 2741, 6926, 2792 },
+ { -4188, 3763, 4235, 2018 },
+ { -3210, 3224, 5646, 1427 },
+ { -5526, 6909, 5070, -627 },
+ { -2815, 3994, 3425, 1903 },
+ { -2163, 2734, 5423, 145 },
+ { -4149, 4247, 2355, 734 },
+ { -410, 2521, 4138, -16 },
+ { -2411, 2385, 4927, 2105 },
+ { -6077, 3591, 3114, 594 },
+ { -4186, 4834, 5926, -1004 },
+ { -7315, 3369, 5966, 448 },
+ { -7042, 5721, 5771, 238 },
+ { -4466, 3907, 3535, -1751 },
+ { -2116, 3970, 6163, -1392 },
+ { -7239, 2143, 8407, 3630 },
+ { -5431, 4486, 6486, -42 },
+ { -1874, 1617, 6333, 519 },
+ { -6478, 2629, 4634, -505 },
+ { -7784, 2342, 7216, 1365 },
+ { -1154, 1432, 4831, 1544 },
+ { -4964, -5801, 1797, 506 },
+ { -4436, -6905, 1059, -1237 },
+ { -5400, -6886, 884, -290 },
+ { -6259, -7103, 523, -227 },
+ { -4819, -6450, 1412, -450 },
+ { -4056, -6213, 1725, -943 },
+ { -5642, -6091, 1357, 605 },
+ { -4196, -5678, 2187, -173 },
+ { -4726, -5126, 2470, 321 },
+ { -6642, -5091, 1507, -1005 },
+ { -5304, -5250, 1944, 1579 },
+ { -7179, -5520, 1468, -425 },
+ { -6033, -4895, 1876, -955 },
+ { -6595, -5143, 2207, 1291 },
+ { -4224, -4943, 1846, 1792 },
+ { -7128, -6950, 539, 724 },
+ { -4369, -4901, 2590, 1103 },
+ { -7413, -5696, 1712, 1440 },
+ { -5885, -6821, 418, 871 },
+ { -6828, -5599, 710, -1563 },
+ { -6123, -5817, 1358, 1631 },
+ { -5291, -5622, 578, 2138 },
+ { -7171, -6004, 347, 2208 },
+ { -6083, -5251, 2132, 425 },
+ { -4329, -5721, 407, -2993 },
+ { -5326, -5056, 1119, -1837 },
+ { -5485, -5856, 185, -2389 },
+ { -6529, -5178, 403, -697 },
+ { -6719, -4412, 2726, 871 },
+ { -5126, -5629, 1835, -771 },
+ { -5622, -4361, 2973, 858 },
+ { -5282, -5895, 45, -335 },
+ { -4357, -5656, 1696, -1558 },
+ { -7139, -6659, 627, -409 },
+ { -4415, -6328, 35, 1306 },
+ { -7639, -6110, 1134, 197 },
+ { -3626, -5592, 2019, 901 },
+ { -3547, -5064, 1176, 1738 },
+ { -5075, -3899, 2087, 266 },
+ { -4086, -6311, 1479, 360 },
+ { -6210, -5220, -199, -1477 },
+ { -3910, -5063, 1356, -15 },
+ { -7616, -4977, 461, 2401 },
+ { -6118, -6131, 1258, -563 },
+ { -6127, -4968, 1286, -27 },
+ { -4121, -5852, 1113, 1476 },
+ { -5157, -4881, 1162, -662 },
+ { -4637, -5031, 1179, 709 },
+ { -5509, -5452, -397, 1224 },
+ { -4597, -6861, 646, 467 },
+ { -6247, -4043, 468, 278 },
+ { -5336, -6465, 874, -1472 },
+ { -6998, -6346, 78, -1798 },
+ { -4915, -4530, 2756, -203 },
+ { -6048, -4373, 1468, 1052 },
+ { -4273, -7100, 942, -323 },
+ { -6552, -4287, 2351, 69 },
+ { -6954, -4613, 722, 1521 },
+ { -4201, -5361, 763, -1562 },
+ { -6881, -5596, -748, 669 },
+ { -6695, -3547, -34, 1299 },
+ { -3981, -5728, 84, 111 },
+ { -4663, -4809, 2173, -1031 },
+ { -6599, -6077, 1303, 256 },
+ { -7596, -4265, -5791, -4140 },
+ { -6610, -2758, -5288, -3936 },
+ { -5880, -3865, -6563, -3088 },
+ { -7228, -5510, -7677, -3912 },
+ { -8854, -6553, -8318, -5361 },
+ { -9362, -5249, -6413, -4319 },
+ { -4418, -3110, -6368, -4358 },
+ { -5544, -4203, -6863, -5013 },
+ { -3056, -4316, -5567, -3181 },
+ { -3078, -5999, -5051, -2657 },
+ { -5884, -6292, -5756, -4013 },
+ { -4825, -4549, -5535, -4053 },
+ { -4443, -6126, -5316, -1368 },
+ { -3972, -6341, -6098, -2686 },
+ { -5751, -2781, -5398, -6230 },
+ { -4466, -6135, -5570, -3679 },
+ { -4291, -5992, -3564, -5189 },
+ { -7189, -4429, -7279, -6082 },
+ { -5076, -4433, -2748, -5366 },
+ { -6225, -2825, -6833, -5663 },
+ { -2989, -4792, -3960, -4492 },
+ { -7836, -7773, -7722, -5741 },
+ { -6559, -5703, -5844, -5589 },
+ { -7612, -5438, -4136, -3774 },
+ { -4218, -4176, -6591, -2333 },
+ { -4837, -5063, -6581, 322 },
+ { -6590, -5990, -2980, -3847 },
+ { -5558, -2971, -5489, -1932 },
+ { -7001, -5323, -4975, -1697 },
+ { -4694, -2688, -6904, -3044 },
+ { -8511, -5379, -5767, -2549 },
+ { -7548, -5412, -6522, -2572 },
+ { -6597, -4973, -6423, -1274 },
+ { -6415, -4022, -5168, -1072 },
+ { -5528, -5530, -7218, -2345 },
+ { -4845, -4805, -5943, -1227 },
+ { -6049, -7150, -6744, -2161 },
+ { -9061, -7299, -8542, -4375 },
+ { -5010, -5546, -5416, -82 },
+ { -4135, -4205, -5109, -3373 },
+ { -3311, -5869, -4007, -5061 },
+ { -5993, -6472, -3962, -4718 },
+ { -2966, -5832, -2821, -6305 },
+ { -4851, -5152, -2067, -3930 },
+ { -3620, -4441, -3362, -5836 },
+ { -4469, -5221, -4534, -5592 },
+ { -4022, -6335, -4321, -6107 },
+ { -4899, -4503, -3084, -3725 },
+ { -4490, -8276, -4620, -6236 },
+ { -6591, -4342, -7365, -4063 },
+ { -6498, -5057, -5553, 485 },
+ { -6060, -2714, -7093, -4144 },
+ { -6199, -7774, -7094, -4057 },
+ { -7536, -6424, -6415, -4265 },
+ { -7439, -2454, -6348, -4827 },
+ { -5333, -7565, -4417, -4639 },
+ { -4353, -7103, -4197, -2689 },
+ { -5229, -6549, -5129, -6804 },
+ { -6129, -7701, -5236, -4836 },
+ { -6797, -3983, -3884, -4406 },
+ { -6624, -4467, -4745, -5052 },
+ { -3324, -7596, -2720, -6553 },
+ { -5473, -6284, -1704, -4511 },
+ { -4131, -7263, -3180, -5196 },
+ { -7116, -5565, -3469, 685 },
+ { -6002, -6021, -3858, 576 },
+ { -3144, -8203, -1291, -434 },
+ { -6096, -7027, -4004, 1353 },
+ { -3943, -7709, -2344, -36 },
+ { -4510, -6767, -2642, 631 },
+ { -3657, -11541, -2570, -3984 },
+ { -5959, -8854, -1333, -867 },
+ { -6699, -8866, -1606, -344 },
+ { -3836, -7961, -2334, -2028 },
+ { -3430, -8045, -3037, -672 },
+ { -3868, -9184, -3635, -1819 },
+ { -4258, -9060, -2621, -1008 },
+ { -3595, -8693, -2022, -752 },
+ { -4573, -8048, -3166, -2622 },
+ { -4852, -7903, -1405, 256 },
+ { -4591, -7057, -1560, 965 },
+ { -6963, -7655, -980, 808 },
+ { -5179, -6641, -3356, 1196 },
+ { -7102, -6941, -2798, 2123 },
+ { -6867, -5834, -3320, -770 },
+ { -5977, -7369, -2500, -778 },
+ { -6160, -6400, -934, -2543 },
+ { -6741, -7608, -355, -1289 },
+ { -6856, -6466, -1433, -1643 },
+ { -4786, -6292, -4970, 376 },
+ { -5407, -8866, -2255, -400 },
+ { -3814, -6506, -1387, -3620 },
+ { -4998, -6137, -1200, -4092 },
+ { -5123, -9557, -2849, -1306 },
+ { -4259, -6444, -4395, -338 },
+ { -5221, -6810, -883, 1225 },
+ { -6137, -6215, -2165, 554 },
+ { -3895, -6557, -3176, -1829 },
+ { -3886, -8188, -87, -954 },
+ { -7243, -6707, -2216, -316 },
+ { -5592, -7606, 85, -432 },
+ { -3957, -7945, -504, -144 },
+ { -4617, -7624, 218, -312 },
+ { -4797, -8737, -844, -1051 },
+ { -4478, -8516, -1401, -454 },
+ { -4557, -7058, -302, -2332 },
+ { -6623, -7736, -271, -50 },
+ { -3157, -7532, -1111, -2207 },
+ { -3590, -7300, -1271, 517 },
+ { -4442, -7306, -507, 590 },
+ { -6458, -7524, -2807, 666 },
+ { -4991, -8466, -3363, -785 },
+ { -7474, -7541, -1056, -1839 },
+ { -7501, -8316, -938, -180 },
+ { -5329, -7739, -579, -2341 },
+ { -4549, -7063, -176, -3539 },
+ { -5191, -8612, -1504, -4250 },
+ { -3083, -7058, -2251, 32 },
+ { -4003, -7043, -1093, -791 },
+ { -5523, -8093, -678, -114 },
+ { -3022, -10265, -2070, -3109 },
+ { -3905, -6274, -182, -3652 },
+ { -3269, -9217, -551, -2650 },
+ { -3138, -9314, -1726, -1704 },
+ { -4420, -10339, -1744, -3459 },
+ { -4163, -8609, -2298, -4113 },
+ { -5566, -6505, -1241, -463 },
+ { -3130, -9746, -2352, -4884 },
+ { -7825, -3439, 1451, -1468 },
+ { -8451, -3318, 2360, -435 },
+ { -8462, -4130, 1438, -1024 },
+ { -9425, -4564, 1328, -689 },
+ { -11014, -3202, 2278, 2080 },
+ { -8269, -2761, -146, -440 },
+ { -7497, -2618, -166, 413 },
+ { -8250, -3060, 522, -2133 },
+ { -8365, -5366, 1347, -451 },
+ { -8589, -3979, 2943, 714 },
+ { -8111, -2572, 1272, -1748 },
+ { -7830, -5193, 605, -1484 },
+ { -8119, -4736, 2141, 256 },
+ { -7724, -4769, 1463, -812 },
+ { -7363, -3911, 2540, 4 },
+ { -7974, -3397, 2363, 1366 },
+ { -7359, -4204, 1752, -958 },
+ { -7622, -3505, 660, 916 },
+ { -9934, -3665, 3165, 828 },
+ { -8721, -4162, 62, 1718 },
+ { -9433, -4768, 2722, 1234 },
+ { -7960, -4496, 138, 1528 },
+ { -8198, -3454, -443, 631 },
+ { -7756, -2246, 655, 1137 },
+ { -8841, -3145, 1113, 829 },
+ { -7817, -3298, 1251, 230 },
+ { -9413, -2733, 323, -1862 },
+ { -9408, -4168, 1270, 1549 },
+ { -9037, -3892, -942, 283 },
+ { -8255, -3849, 1301, 1762 },
+ { -9057, -3987, -41, -682 },
+ { -9441, -4187, 2019, -111 },
+ { -9740, -3178, 1602, -871 },
+ { -8344, -2474, 1461, 1506 },
+ { -9752, -2925, 1996, 1243 },
+ { -9199, -3796, 180, 537 },
+ { -9060, -2405, 1140, -1562 },
+ { -9348, -2376, 309, -162 },
+ { -10786, -3182, -5, -1500 },
+ { -8142, -4540, -434, -826 },
+ { -7528, -2341, 1104, -73 },
+ { -9360, -2658, 3062, 56 },
+ { -8267, -2335, 2000, -1193 },
+ { -12169, -3154, 1287, -640 },
+ { -11398, -2120, 946, -1163 },
+ { -8940, -4559, 328, -1696 },
+ { -11025, -4213, 2813, 840 },
+ { -9224, -3581, 2224, 2039 },
+ { -8943, -3337, 1248, -1298 },
+ { -7900, -4042, 485, -2080 },
+ { -9221, -1947, 2191, -880 },
+ { -10762, -1800, 2516, -324 },
+ { -10095, -2238, 981, -1335 },
+ { -11908, -2808, 3255, 645 },
+ { -10640, -4105, 1283, -595 },
+ { -7663, -2863, 2467, -797 },
+ { -10712, -3854, 3710, 1538 },
+ { -10823, -2893, 1408, -801 },
+ { -9874, -3832, 256, -1638 },
+ { -10394, -3391, 2315, -94 },
+ { -11525, -4079, 4153, 2122 },
+ { -9546, -2088, 1541, 481 },
+ { -8731, -2433, 1042, 2160 },
+ { -7852, -3977, -1370, 1677 },
+ { 7072, -3420, 1398, -1741 },
+ { 6180, -1976, 1280, -3557 },
+ { 7692, -1793, 2844, -1700 },
+ { 8363, -1773, 3104, -2679 },
+ { 9213, -3266, 3756, -3542 },
+ { 9650, -2644, 1426, -1318 },
+ { 7712, -2796, 3686, -1975 },
+ { 7316, -3517, 2821, -622 },
+ { 7434, -2594, 2305, -2264 },
+ { 7237, -1797, 255, -3114 },
+ { 8663, -1983, 1338, -3056 },
+ { 6616, -952, 4059, -2652 },
+ { 8823, -1327, 1362, -1356 },
+ { 9938, -1722, 1287, -2362 },
+ { 7207, -1057, 1913, -1315 },
+ { 7508, -1585, 870, -1982 },
+ { 8217, -3680, 1417, -3170 },
+ { 8329, -2541, 1684, -585 },
+ { 8062, -2335, 252, -2800 },
+ { 8204, -4108, 3097, -2569 },
+ { 7701, -3367, 576, -3008 },
+ { 7350, -786, 2414, -2129 },
+ { 6948, -2568, 1607, -225 },
+ { 7684, -2387, 1308, -3449 },
+ { 8306, -3458, 2394, -1454 },
+ { 8438, -2781, 1043, -1362 },
+ { 9175, -2076, 2144, -1987 },
+ { 8347, -2709, 3489, -4301 },
+ { 5696, -2377, 2870, 851 },
+ { 8825, -1243, 2219, -2603 },
+ { 8801, -1614, 584, -2513 },
+ { 8413, -384, 1421, -2244 },
+ { 9228, -3050, 3279, -2164 },
+ { 6342, -2698, 3547, -107 },
+ { 10053, -2476, 2837, -3168 },
+ { 7439, -604, 3177, -3991 },
+ { 7749, -1064, 4329, -4855 },
+ { 8655, -2177, 2252, -3519 },
+ { 8490, -228, 1958, -3233 },
+ { 10513, -2968, 1911, -2340 },
+ { 8146, -862, 1884, -1723 },
+ { 7788, -666, 3004, -2891 },
+ { 7785, -1620, 4133, -3417 },
+ { 10262, -3731, 3455, -2971 },
+ { 8570, -905, 4519, -4649 },
+ { 9129, -2562, 463, -2465 },
+ { 9451, -3587, 1904, -3056 },
+ { 6549, -2236, 3010, -4523 },
+ { 7175, -2684, 2967, -3458 },
+ { 9872, -3278, 1054, -2472 },
+ { 9153, -931, 1217, -2565 },
+ { 8789, -3469, 753, -2568 },
+ { 6683, -3791, 1797, -3968 },
+ { 6801, -1977, 2311, -452 },
+ { 6336, -1572, 2612, -3264 },
+ { 7996, -1008, 730, -2964 },
+ { 7521, -1059, 1573, -3694 },
+ { 8148, -3973, 2600, -3572 },
+ { 7765, -1532, 2528, -3856 },
+ { 7404, -3918, 4472, -143 },
+ { 8894, -1398, 3299, -3685 },
+ { 5768, -2041, 1487, -637 },
+ { 5131, -2865, 2463, -811 },
+ { 6439, -1568, 3500, -1550 },
+ { -8878, -6798, -5319, -1452 },
+ { -6332, -9713, -3112, -990 },
+ { -8444, -6316, -3694, -687 },
+ { -6123, -10840, -3637, -4358 },
+ { -4784, -9580, -4577, -2581 },
+ { -6108, -10515, -4859, -2524 },
+ { -7605, -7518, -2327, -2797 },
+ { -9662, -8775, -2467, -2010 },
+ { -6494, -7523, -4715, -118 },
+ { -8290, -8982, -1672, -317 },
+ { -8798, -11051, -3888, -1426 },
+ { -6273, -6623, -6791, -142 },
+ { -8313, -7668, -2141, -1275 },
+ { -6453, -8412, -3589, -4102 },
+ { -6747, -7750, -5690, -2498 },
+ { -7814, -6693, -3174, -2446 },
+ { -10383, -10130, -3931, -2364 },
+ { -10606, -8467, -5539, -2772 },
+ { -9475, -6671, -3305, -2271 },
+ { -8982, -9457, -5635, -4005 },
+ { -10111, -7965, -6515, -4180 },
+ { -7301, -6479, -5364, 720 },
+ { -9543, -8999, -7921, -912 },
+ { -9534, -8562, -3469, -384 },
+ { -7601, -10344, -3205, -1127 },
+ { -8088, -8620, -4954, -2888 },
+ { -8202, -8406, -7038, -3775 },
+ { -7312, -8324, -3334, -1775 },
+ { -8566, -9262, -8071, -4174 },
+ { -7068, -11300, -5573, -2907 },
+ { -8295, -8952, -4366, -1544 },
+ { -11104, -10210, -2285, -384 },
+ { -5213, -7520, -5008, -1339 },
+ { -5889, -7940, -5987, -1385 },
+ { -10816, -8201, -4153, -1485 },
+ { -10277, -8919, -6315, -1652 },
+ { -5888, -10320, -3821, -1733 },
+ { -10497, -7181, -6083, -3032 },
+ { -7721, -9724, -6591, -5336 },
+ { -5688, -7894, -3486, -2552 },
+ { -10014, -10500, -3247, -820 },
+ { -6301, -8765, -4506, -2923 },
+ { -8261, -7847, -6213, -1552 },
+ { -10212, -7481, -8113, -3954 },
+ { -6938, -10874, -6074, -4703 },
+ { -7183, -10968, -4446, -1773 },
+ { -7120, -9193, -1966, -2509 },
+ { -6234, -9263, -2313, -4284 },
+ { -8503, -9857, -2429, -608 },
+ { -9372, -7844, -8391, -2120 },
+ { -7951, -7157, -6535, -11 },
+ { -7256, -9473, -2172, -660 },
+ { -10063, -9612, -2515, -15 },
+ { -6684, -9134, -6109, -4206 },
+ { -8204, -11932, -5220, -2306 },
+ { -9710, -6706, -4115, -3275 },
+ { -6855, -7078, -2409, -4447 },
+ { -7344, -7673, -4479, -4116 },
+ { -8851, -6842, -4927, -2948 },
+ { -8927, -10452, -5633, -2194 },
+ { -8627, -9002, -7176, -1575 },
+ { -8209, -9722, -7021, -3324 },
+ { -3770, -10249, -3623, -4816 },
+ { -8183, -7465, -4090, 646 },
+ { -8163, -7149, 200, 498 },
+ { -8289, -6266, 686, -206 },
+ { -10030, -6241, -1032, -1864 },
+ { -8793, -8327, -773, -169 },
+ { -9149, -6215, 969, -15 },
+ { -8303, -5859, -7, 2006 },
+ { -9682, -7283, 255, 1322 },
+ { -9293, -7227, 71, -231 },
+ { -8525, -6215, 287, -837 },
+ { -10477, -5379, 1159, 1449 },
+ { -10726, -7856, -130, 102 },
+ { -8694, -7461, -1210, 690 },
+ { -9367, -5324, 1103, 3170 },
+ { -10686, -8055, -831, 1633 },
+ { -9201, -6873, -2704, 2258 },
+ { -8421, -5358, -1405, 226 },
+ { -9066, -5830, -307, -1571 },
+ { -11150, -7381, -2746, -900 },
+ { -9978, -5925, -2006, -437 },
+ { -9464, -4741, -273, 1061 },
+ { -10543, -6684, -1113, 1660 },
+ { -10073, -5576, 1083, -269 },
+ { -8826, -5763, 1600, 1486 },
+ { -10445, -9071, -1253, -64 },
+ { -12085, -5799, 2, 769 },
+ { -12939, -6663, 1650, 1437 },
+ { -10932, -6434, -1252, -649 },
+ { -11650, -7826, -2053, 710 },
+ { -12122, -6733, -1889, -731 },
+ { -9093, -6095, -2463, -842 },
+ { -10977, -4364, 469, 420 },
+ { -11488, -6908, -521, 893 },
+ { -9669, -5478, -842, 337 },
+ { -10606, -5203, -632, -1361 },
+ { -10198, -6284, 1662, 1277 },
+ { -10135, -5292, 2435, 3493 },
+ { -11027, -6561, 655, 56 },
+ { -10977, -5030, 1127, -358 },
+ { -12766, -3986, 1348, -335 },
+ { -14244, -7731, 264, 317 },
+ { -15124, -10309, -508, 1447 },
+ { -12821, -8638, -608, 137 },
+ { -13076, -8693, -2852, -431 },
+ { -11156, -5546, -2252, -1600 },
+ { -8692, -7366, -819, -1223 },
+ { -12507, -9816, -1714, -121 },
+ { -10712, -6666, 544, 3349 },
+ { -12462, -5890, -2491, -2318 },
+ { -12468, -7226, 437, 232 },
+ { -11300, -5226, 2068, 687 },
+ { -11994, -8320, -626, 2728 },
+ { -12222, -5476, 1142, 18 },
+ { -10277, -8122, -2418, 2003 },
+ { -13418, -6115, -3563, -2802 },
+ { -14759, -9834, -1243, 21 },
+ { -13699, -5665, 1525, 507 },
+ { -16269, -9476, -701, 163 },
+ { -12677, -5437, -247, -1019 },
+ { -11827, -4295, -181, -1243 },
+ { -12847, -4496, 2984, 1123 },
+ { -13860, -7915, -1166, -547 },
+ { -12276, -8145, -2290, -1527 },
+ { -11417, -4830, 2983, 1854 },
+ { -11793, -6002, 1163, 1940 },
+ { 11443, -4920, -3235, 3151 },
+ { 11300, -6616, -1506, 1175 },
+ { 9198, -4628, -2060, 2390 },
+ { 10532, -4027, -643, 912 },
+ { 9902, -3573, -1606, 1327 },
+ { 9653, -3536, -2240, 1869 },
+ { 9948, -5171, -423, 2662 },
+ { 12316, -4004, -1989, 281 },
+ { 12125, -4800, -1265, -163 },
+ { 10650, -2617, -2337, 1462 },
+ { 9909, -4968, -2376, 916 },
+ { 12944, -4647, -1958, 460 },
+ { 12988, -5283, -1141, 41 },
+ { 12321, -2915, -3621, 1025 },
+ { 11449, -2894, -2728, 351 },
+ { 12087, -3041, -2002, -32 },
+ { 11558, -4031, -1343, -399 },
+ { 12983, -3740, -3516, 1245 },
+ { 12099, -2515, -2752, 225 },
+ { 12515, -3465, -2701, 550 },
+ { 14683, -5022, -5272, 2996 },
+ { 12260, -3383, -1215, -528 },
+ { 13810, -5422, -2443, 1166 },
+ { 13421, -5378, -1886, 721 },
+ { 12961, -4259, -2594, 796 },
+ { 12266, -2104, -4768, 1591 },
+ { 13523, -4710, -3045, 1342 },
+ { 12437, -2099, -5610, 2117 },
+ { 11850, -2183, -3497, 661 },
+ { 12275, -3936, -597, -697 },
+ { 12459, -5253, -517, -544 },
+ { 12835, -4094, -1322, -168 },
+ { 14360, -5677, -3305, 1859 },
+ { 13905, -4552, -4309, 2117 },
+ { 11559, -3412, -1847, -81 },
+ { 13379, -3167, -5764, 2746 },
+ { 11910, -1634, -4342, 1052 },
+ { 12662, -4742, 71, -974 },
+ { 13057, -3254, -4424, 1705 },
+ { 15046, -5706, -4851, 3019 },
+ { 14162, -4142, -5514, 2843 },
+ { 12764, -1845, -6684, 2888 },
+ { 13714, -2374, -7838, 3857 },
+ { 13295, -1663, -8293, 4073 },
+ { 10032, -4152, -3403, 1421 },
+ { 10942, -5386, -2222, 950 },
+ { 10532, -6385, -1750, 1925 },
+ { 10273, -5972, -1534, 643 },
+ { 10605, -4782, -1695, 27 },
+ { 10988, -5153, -1123, -341 },
+ { 11629, -5884, -1060, 48 },
+ { 10441, -4045, -2431, 311 },
+ { 10788, -3595, -4171, 1807 },
+ { 12110, -5686, -2127, 976 },
+ { 11746, -4773, -2639, 891 },
+ { 11541, -5299, -3031, 1732 },
+ { 11416, -2559, -5359, 2198 },
+ { 11583, -5376, -704, 677 },
+ { 10416, -3214, -3516, 872 },
+ { 9651, -5435, -1618, 3255 },
+ { 9973, -5133, -996, 3923 },
+ { 11707, -4643, -430, -796 },
+ { 10994, -2709, -3587, 2302 },
+ { 10716, -5118, -645, 270 },
+ { 14100, -10314, 1095, 1531 },
+ { 12944, -8049, 1105, -741 },
+ { 13276, -7035, -511, 274 },
+ { 14008, -7254, -283, 139 },
+ { 11594, -6536, -91, 1671 },
+ { 11732, -8645, 746, 15 },
+ { 14613, -7085, -1578, 1183 },
+ { 13083, -6224, -750, -4 },
+ { 13988, -6256, -1592, 820 },
+ { 14678, -8683, 441, 126 },
+ { 15571, -8872, -521, 1139 },
+ { 15642, -9533, 341, 697 },
+ { 15960, -9586, -168, 1121 },
+ { 15464, -10239, 1433, -1 },
+ { 14934, -7887, -1046, 1080 },
+ { 15252, -7630, -1899, 1628 },
+ { 15485, -8384, -1234, 1484 },
+ { 15962, -8638, -1815, 1931 },
+ { 16501, -10664, 398, 1167 },
+ { 16146, -10145, 411, 918 },
+ { 14573, -7475, -697, 601 },
+ { 14302, -7996, 28, 257 },
+ { 14769, -6792, -2286, 1574 },
+ { 14144, -6137, -2169, 1257 },
+ { 14770, -6271, -3111, 1933 },
+ { 14110, -8312, 1083, -531 },
+ { 15235, -6991, -2993, 2174 },
+ { 13222, -5805, 547, -891 },
+ { 14796, -8762, 1254, -246 },
+ { 16040, -9181, -1005, 1551 },
+ { 16487, -10086, -373, 1420 },
+ { 15077, -9479, 966, 51 },
+ { 13026, -6468, 932, -1080 },
+ { 12703, -6152, -33, -573 },
+ { 15641, -6810, -4128, 2874 },
+ { 13282, -7673, 1583, -1283 },
+ { 12373, -7150, 1512, -917 },
+ { 12992, -7751, -678, 783 },
+ { 10907, -6858, -313, 2597 },
+ { 13026, -8963, 125, 2152 },
+ { 12770, -9946, 1957, -505 },
+ { 12482, -6849, -1268, 833 },
+ { 13790, -6181, -138, -279 },
+ { 12709, -8382, 2044, 227 },
+ { 12244, -6630, 203, -457 },
+ { 14209, -6816, -1032, 632 },
+ { 15134, -8267, -288, 640 },
+ { 13619, -6157, -1090, 356 },
+ { 14044, -7413, 725, -484 },
+ { 12958, -7753, 2585, -1980 },
+ { 13188, -8396, 2306, -1558 },
+ { 14379, -9980, 2132, -688 },
+ { 14275, -9857, 1162, 179 },
+ { 13690, -8648, 1621, -889 },
+ { 11770, -6829, -746, 278 },
+ { 12732, -8202, 286, 90 },
+ { 13630, -10146, 1867, -207 },
+ { 12072, -8740, 1299, -645 },
+ { 12852, -9492, 1226, 62 },
+ { 11792, -7382, -54, -116 },
+ { 13779, -9014, 487, 351 },
+ { 11951, -7729, 121, 834 },
+ { 11970, -9781, 2276, -4 },
+ { 12680, -7984, 2787, -787 },
+ { 13300, -14488, 6408, -1927 },
+ { 13635, -15355, 9153, -3073 },
+ { 12804, -13566, 5517, -1625 },
+ { 16624, -10854, 1690, 28 },
+ { 20387, -18532, 6162, -261 },
+ { 16515, -12642, 3392, -519 },
+ { 15800, -11095, 2151, -202 },
+ { 16824, -11790, 1651, 599 },
+ { 17604, -13213, 2563, 538 },
+ { 17892, -14177, 3562, 147 },
+ { 16987, -11399, 869, 1052 },
+ { 17003, -12456, 2442, 265 },
+ { 21657, -21806, 9198, -1250 },
+ { 16825, -13341, 3980, -686 },
+ { 17525, -12714, 1887, 805 },
+ { 16419, -11034, 1216, 617 },
+ { 20931, -19939, 7469, -684 },
+ { 18452, -15390, 4573, -191 },
+ { 14778, -10077, 2841, -1209 },
+ { 17402, -13319, 3042, 160 },
+ { 19365, -17922, 7087, -1061 },
+ { 16298, -11941, 2810, -351 },
+ { 19087, -16176, 4775, -84 },
+ { 17666, -12289, 938, 1224 },
+ { 18581, -15894, 5132, -430 },
+ { 19823, -16717, 4142, 545 },
+ { 19960, -19423, 8400, -1492 },
+ { 18973, -16817, 5906, -594 },
+ { 19079, -15431, 3528, 503 },
+ { 16667, -12485, 4467, -1302 },
+ { 19791, -17797, 6196, -529 },
+ { 20005, -17606, 5354, -20 },
+ { 20123, -18599, 6886, -728 },
+ { 19068, -14805, 2394, 1105 },
+ { 14443, -13723, 5631, -2029 },
+ { 14730, -14231, 5631, -1450 },
+ { 16089, -15959, 7271, -2029 },
+ { 13473, -11200, 3236, -924 },
+ { 14413, -10902, 2347, -267 },
+ { 17666, -18662, 11381, -3496 },
+ { 14749, -11042, 3305, -275 },
+ { 15304, -10486, 1869, -240 },
+ { 14809, -12126, 3369, -616 },
+ { 16896, -16561, 7307, -1845 },
+ { 15782, -14336, 5380, -1264 },
+ { 16395, -15520, 6415, -1588 },
+ { 13681, -11114, 2584, -320 },
+ { 14244, -12326, 4480, -1632 },
+ { 15247, -13119, 4265, -898 },
+ { 13987, -12091, 3469, -597 },
+ { 13941, -12770, 4240, -839 },
+ { 13771, -13627, 5252, -1384 },
+ { 15010, -16074, 7592, -2249 },
+ { 15852, -17226, 8619, -2655 },
+ { 18921, -16916, 6875, -1501 },
+ { 14909, -11678, 2768, -295 },
+ { 18988, -18353, 8424, -2070 },
+ { 15457, -15080, 6218, -1513 },
+ { 14916, -15512, 6949, -1883 },
+ { 18108, -14702, 4681, -701 },
+ { 17600, -15733, 5616, -775 },
+ { 14070, -13683, 6472, -2626 },
+ { 13832, -11914, 5201, -2232 },
+ { 18846, -19009, 9192, -1961 },
+ { -11981, -10994, -6324, -2264 },
+ { -10976, -9047, -6546, -3828 },
+ { -11288, -10532, -7014, -4191 },
+ { -10139, -10189, -7799, -2688 },
+ { -10555, -9988, -9181, -2040 },
+ { -11596, -11339, -10022, -2707 },
+ { -13400, -13395, -11306, -4206 },
+ { -9774, -12281, -7466, -4133 },
+ { -10842, -13125, -8777, -4956 },
+ { -11964, -15082, -9779, -5095 },
+ { -9382, -10188, -9053, -4927 },
+ { -11562, -11296, -3651, -985 },
+ { -9287, -10083, -7918, -4069 },
+ { -12821, -16556, -11410, -6195 },
+ { -12628, -8959, -4521, -1113 },
+ { -13845, -11581, -3649, -681 },
+ { -12685, -10269, -5483, -1275 },
+ { -14988, -12874, -5107, -1189 },
+ { -13761, -11367, -6202, -1804 },
+ { -13225, -11249, -7820, -3354 },
+ { -14809, -11992, -3202, -312 },
+ { -15620, -15519, -10210, -3433 },
+ { -12954, -10200, -3139, -611 },
+ { -11536, -9981, -5284, -923 },
+ { -13034, -12417, -4612, -1098 },
+ { -16911, -15505, -6123, -1352 },
+ { -17396, -17685, -8330, -2171 },
+ { -14120, -10764, -2265, -99 },
+ { -12598, -7367, -5406, -3530 },
+ { -14143, -12793, -10909, -5226 },
+ { -14692, -16871, -11626, -5554 },
+ { -12581, -11197, -9194, -3837 },
+ { -16752, -16726, -9746, -2808 },
+ { -10600, -10358, -6560, -1227 },
+ { -14573, -13312, -8957, -3393 },
+ { -10172, -8463, -8579, -3387 },
+ { -11418, -12421, -5522, -1842 },
+ { -11855, -14204, -6669, -2625 },
+ { -13308, -8191, -3941, -2194 },
+ { -10007, -12266, -5022, -1811 },
+ { -13532, -15771, -9497, -3175 },
+ { -11760, -11148, -10339, -5529 },
+ { -12149, -12763, -11198, -3697 },
+ { -12029, -12119, -8555, -1792 },
+ { -16995, -19957, -11447, -3471 },
+ { -13144, -14504, -9988, -3191 },
+ { -9938, -11064, -6139, -3162 },
+ { -8873, -11550, -8294, -6550 },
+ { -9303, -13010, -6150, -2711 },
+ { -15463, -10469, -1766, -170 },
+ { -15985, -11693, -3007, -650 },
+ { -17142, -10671, -1434, 47 },
+ { -16063, -13858, -4817, -1058 },
+ { -19446, -19599, -9594, -2464 },
+ { -20076, -18744, -8313, -1889 },
+ { -15047, -16085, -7590, -2250 },
+ { -13481, -16195, -8552, -2998 },
+ { -13829, -14869, -6704, -1932 },
+ { -16357, -18484, -9802, -2959 },
+ { -10551, -8393, -9303, -5070 },
+ { -11345, -9156, -5641, -3107 },
+ { -13217, -13449, -9270, -4541 },
+ { -11988, -13732, -9995, -6374 },
+ { -11007, -9519, -5168, -4107 },
+ { 9930, -7858, 8061, -4375 },
+ { 8274, -7867, 5992, -2096 },
+ { 9692, -9675, 7621, -3670 },
+ { 9589, -8110, 6509, -3010 },
+ { 12617, -11976, 10122, -5360 },
+ { 11867, -8895, 7948, -5323 },
+ { 10388, -10482, 9234, -4324 },
+ { 8188, -8220, 7810, -2737 },
+ { 10407, -8787, 4806, -1930 },
+ { 10348, -8845, 9233, -6614 },
+ { 9422, -7091, 4820, -2878 },
+ { 9758, -9796, 5584, -2256 },
+ { 10188, -7994, 5347, -3343 },
+ { 11133, -7455, 4015, -2306 },
+ { 10676, -10744, 6093, -2629 },
+ { 11522, -12184, 7848, -3375 },
+ { 8805, -9883, 5317, -3071 },
+ { 9498, -9654, 6555, -3592 },
+ { 10488, -8008, 4066, -1252 },
+ { 11261, -8930, 6068, -2738 },
+ { 12180, -10397, 5027, -1531 },
+ { 9138, -8531, 3601, -1959 },
+ { 8107, -8380, 4970, -2061 },
+ { 9737, -13248, 6438, -2617 },
+ { 11178, -10423, 2622, -522 },
+ { 9572, -12372, 5199, -2019 },
+ { 12057, -12144, 4147, -1099 },
+ { 9047, -9925, 2516, -665 },
+ { 10790, -8030, 5882, -4386 },
+ { 7199, -8426, 6337, -2841 },
+ { 7778, -8285, 3529, -3442 },
+ { 7559, -10569, 3484, -1332 },
+ { 9404, -8115, 7484, -5541 },
+ { 7792, -11976, 5546, -2573 },
+ { 9313, -10264, 7661, -5195 },
+ { 6701, -10725, 4370, -1784 },
+ { 4918, -11361, 4507, -4527 },
+ { 5147, -12305, 3978, -5556 },
+ { 6525, -9899, 4481, -3129 },
+ { 7538, -12855, 6060, -4826 },
+ { 8659, -12111, 7159, -4430 },
+ { 8440, -11304, 4547, -1747 },
+ { 9216, -10918, 3507, -1195 },
+ { 6165, -9254, 4771, -4677 },
+ { 9163, -11019, 5637, -4935 },
+ { 13441, -11509, 6676, -2434 },
+ { 7912, -9398, 6663, -4048 },
+ { 11723, -13745, 8131, -4148 },
+ { 6065, -10257, 5005, -6327 },
+ { 11618, -12417, 5336, -1894 },
+ { 8891, -13924, 8407, -6131 },
+ { 9622, -12563, 7908, -5109 },
+ { 11479, -10315, 8349, -3991 },
+ { 11676, -14103, 6611, -2330 },
+ { 11951, -8953, 3829, -1550 },
+ { 10486, -8044, 10493, -5920 },
+ { 11801, -10769, 9763, -5305 },
+ { 6109, -8676, 5827, -1346 },
+ { 7030, -9611, 5624, -5761 },
+ { 12808, -12886, 8683, -4148 },
+ { 13213, -10464, 6381, -3189 },
+ { 11796, -13681, 10703, -6075 },
+ { 9639, -7949, 9625, -3944 },
+ { 8538, -6997, 5309, 453 }
+};
diff --git a/contrib/libdca/tables_fir.h b/contrib/libdca/tables_fir.h
new file mode 100644
index 000000000..a127fee6f
--- /dev/null
+++ b/contrib/libdca/tables_fir.h
@@ -0,0 +1,2086 @@
+/*
+ * fir.h
+ * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
+ *
+ * This file is part of libdca, a free DTS Coherent Acoustics stream decoder.
+ * See http://www.videolan.org/developers/libdca.html for updates.
+ *
+ * libdca 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.
+ *
+ * libdca is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+double fir_32bands_perfect[] =
+{
++1.135985195E-010,
+-6.022448247E-007,
++9.742954035E-007,
++7.018770981E-011,
+-6.628192182E-007,
++1.085227950E-006,
+-1.608403011E-008,
+-6.982898526E-007,
++1.162929266E-006,
+-5.083275667E-008,
+-7.020648809E-007,
++1.194632091E-006,
+-1.543309907E-007,
+-6.767839409E-007,
++1.179182050E-006,
+-3.961981463E-007,
+-6.262345096E-007,
++1.033426656E-006,
+-7.342250683E-007,
+-5.564140224E-007,
++9.451737242E-007,
+-3.970030775E-007,
++7.003467317E-007,
++1.975324267E-006,
+-4.741137047E-007,
++8.419976893E-007,
++1.190443072E-006,
++5.234479659E-007,
++6.402664354E-008,
+-1.470520488E-006,
++2.014677420E-007,
+-3.246264413E-008,
+-1.853591357E-006,
++7.834767501E-008,
+-3.809887872E-008,
++7.198007665E-007,
++8.434094667E-008,
++3.086857760E-006,
+-6.702406963E-010,
++6.437721822E-008,
++6.084746474E-006,
+-1.613285505E-009,
++1.189317118E-006,
++9.561075785E-006,
+-2.682709610E-009,
++2.497214155E-006,
++1.309637537E-005,
+-3.399493131E-009,
++3.617151151E-006,
++2.263354872E-005,
++1.314406006E-008,
++3.157242645E-006,
++2.847247197E-005,
++7.506701927E-009,
++2.319611212E-006,
++3.415624451E-005,
++2.788728892E-008,
++7.869333785E-006,
++3.946387005E-005,
++1.444918922E-007,
++9.826449968E-006,
++4.425736552E-005,
++3.132386439E-007,
++1.177108606E-005,
++4.839275425E-005,
++1.399798180E-006,
++1.379448349E-005,
++5.176846025E-005,
++2.032118118E-006,
++1.571428584E-005,
++5.429694284E-005,
++2.715013807E-006,
++1.743183020E-005,
++5.595519906E-005,
++3.453840463E-006,
++1.884208177E-005,
++4.916387297E-006,
++4.195037945E-006,
++1.987093310E-005,
++9.299508747E-006,
++4.896494374E-006,
++2.042970118E-005,
++1.356193479E-005,
++5.516381407E-006,
+-3.144468428E-005,
++1.751866148E-005,
++6.015239251E-006,
+-3.334947178E-005,
++2.093936746E-005,
++6.361419310E-006,
+-3.460439257E-005,
++2.362549276E-005,
++8.006985809E-006,
+-3.515914432E-005,
++2.537086584E-005,
++8.087732567E-006,
+-3.495384954E-005,
++2.618136386E-005,
++7.941360309E-006,
+-3.397853652E-005,
++2.554462844E-005,
++7.568834008E-006,
+-3.225446198E-005,
++3.018750249E-005,
++6.986399967E-006,
+-2.978993689E-005,
++2.570833203E-005,
++6.225028756E-006,
+-2.677291741E-005,
++1.985177369E-005,
++5.315936960E-006,
+-1.806914770E-005,
++1.191342653E-005,
++4.429412002E-006,
+-1.776598037E-005,
++2.525620175E-006,
++3.332600045E-006,
+-1.661818715E-005,
+-1.521241393E-005,
++8.427224429E-007,
+-1.207003334E-005,
+-1.617751332E-005,
++4.341498823E-007,
+-6.993315310E-006,
++1.992636317E-005,
++9.458596395E-008,
+-5.633860383E-007,
++1.774702469E-005,
++2.975164826E-008,
+-9.984935332E-007,
++4.624524081E-005,
++5.610509834E-005,
+-5.729619297E-004,
++4.244441516E-004,
++6.568001118E-005,
+-6.358824321E-004,
++2.206075296E-004,
++7.513730816E-005,
+-7.021900383E-004,
+-2.719412748E-007,
++8.413690375E-005,
+-7.698345580E-004,
+-2.382978710E-004,
++8.757545584E-005,
+-8.385353722E-004,
+-4.935106263E-004,
++9.517164290E-005,
+-9.078957955E-004,
+-7.658848190E-004,
++1.020687996E-004,
+-9.775133803E-004,
+-1.055365428E-003,
++1.084438481E-004,
+-1.046945457E-003,
+-1.361547387E-003,
++1.140582463E-004,
+-1.115717343E-003,
+-1.684492454E-003,
++1.187910311E-004,
+-1.183370827E-003,
+-2.023874084E-003,
++1.224978914E-004,
+-1.252829796E-003,
+-2.379294252E-003,
++1.250260248E-004,
+-1.316190348E-003,
+-2.750317100E-003,
++1.262027217E-004,
+-1.376571832E-003,
+-3.136433195E-003,
++1.226499153E-004,
+-1.433344092E-003,
+-3.537061159E-003,
++1.213575742E-004,
+-1.485876855E-003,
+-3.951539751E-003,
++1.180980107E-004,
+-1.533520175E-003,
+-4.379155114E-003,
++1.126275165E-004,
+-1.575609902E-003,
+-4.819062538E-003,
++1.047207043E-004,
+-1.611457788E-003,
+-5.270531867E-003,
++9.417100227E-005,
+-1.640390139E-003,
+-5.732392892E-003,
++8.078388782E-005,
+-1.661288203E-003,
+-6.203945260E-003,
++6.447290798E-005,
+-1.674512983E-003,
+-6.683901884E-003,
++4.491530854E-005,
+-1.678415807E-003,
+-7.170005701E-003,
++2.470704203E-005,
+-1.672798418E-003,
+-7.664063945E-003,
+-1.714242217E-006,
+-1.656501088E-003,
+-8.162760176E-003,
+-3.193307566E-005,
+-1.633993932E-003,
+-8.665001951E-003,
+-6.541742187E-005,
+-1.593449386E-003,
+-9.170533158E-003,
+-1.024175072E-004,
++1.542080659E-003,
+-9.676489048E-003,
+-1.312203676E-004,
++1.479332102E-003,
+-1.018219907E-002,
+-1.774113771E-004,
++1.395521569E-003,
+-1.068630442E-002,
+-2.233728592E-004,
++1.303116791E-003,
+-1.118756086E-002,
+-2.682086197E-004,
++1.196175464E-003,
+-1.168460958E-002,
+-3.347633174E-004,
++1.073757303E-003,
+-1.217562053E-002,
+-3.906481725E-004,
++9.358961834E-004,
+-1.265939046E-002,
+-4.490280990E-004,
++7.817269652E-004,
+-1.313448418E-002,
+-5.099929986E-004,
++6.114174030E-004,
+-1.359948888E-002,
+-1.405300573E-002,
++1.572482102E-002,
++4.935106263E-004,
+-1.449365262E-002,
++1.533095632E-002,
++2.382978710E-004,
+-1.492007636E-002,
++1.492007636E-002,
++2.719412748E-007,
+-1.533095632E-002,
++1.449365262E-002,
+-2.206075296E-004,
+-1.572482102E-002,
++1.405300573E-002,
+-4.244441516E-004,
+-1.610082202E-002,
++1.359948888E-002,
+-6.114174030E-004,
+-1.645756140E-002,
++1.313448418E-002,
+-7.817269652E-004,
+-1.679391414E-002,
++1.265939046E-002,
+-9.358961834E-004,
+-1.710879989E-002,
++1.217562053E-002,
+-1.073757303E-003,
+-1.740120351E-002,
++1.168460958E-002,
+-1.196175464E-003,
+-1.767017506E-002,
++1.118756086E-002,
+-1.303116791E-003,
+-1.791484281E-002,
++1.068630442E-002,
+-1.395521569E-003,
+-1.813439466E-002,
++1.018219907E-002,
+-1.479332102E-003,
+-1.832821220E-002,
++9.676489048E-003,
+-1.542080659E-003,
+-1.849545911E-002,
++9.170533158E-003,
++1.593449386E-003,
+-1.863567345E-002,
++8.665001951E-003,
++1.633993932E-003,
+-1.874836907E-002,
++8.162760176E-003,
++1.656501088E-003,
+-1.883326657E-002,
++7.664063945E-003,
++1.672798418E-003,
+-1.889026538E-002,
++7.170005701E-003,
++1.678415807E-003,
+-1.891860925E-002,
++6.683901884E-003,
++1.674512983E-003,
++1.891860925E-002,
++6.203945260E-003,
++1.661288203E-003,
++1.889026538E-002,
++5.732392892E-003,
++1.640390139E-003,
++1.883326657E-002,
++5.270531867E-003,
++1.611457788E-003,
++1.874836907E-002,
++4.819062538E-003,
++1.575609902E-003,
++1.863567345E-002,
++4.379155114E-003,
++1.533520175E-003,
++1.849545911E-002,
++3.951539751E-003,
++1.485876855E-003,
++1.832821220E-002,
++3.537061159E-003,
++1.433344092E-003,
++1.813439466E-002,
++3.136433195E-003,
++1.376571832E-003,
++1.791484281E-002,
++2.750317100E-003,
++1.316190348E-003,
++1.767017506E-002,
++2.379294252E-003,
++1.252829796E-003,
++1.740120351E-002,
++2.023874084E-003,
++1.183370827E-003,
++1.710879989E-002,
++1.684492454E-003,
++1.115717343E-003,
++1.679391414E-002,
++1.361547387E-003,
++1.046945457E-003,
++1.645756140E-002,
++1.055365428E-003,
++9.775133803E-004,
++1.610082202E-002,
++7.658848190E-004,
++9.078957955E-004,
++8.385353722E-004,
+-8.757545584E-005,
+-6.084746474E-006,
++7.698345580E-004,
+-8.413690375E-005,
+-3.086857760E-006,
++7.021900383E-004,
+-7.513730816E-005,
+-7.198007665E-007,
++6.358824321E-004,
+-6.568001118E-005,
++1.853591357E-006,
++5.729619297E-004,
+-5.610509834E-005,
++1.470520488E-006,
++5.099929986E-004,
+-4.624524081E-005,
++9.984935332E-007,
++4.490280990E-004,
+-1.774702469E-005,
++5.633860383E-007,
++3.906481725E-004,
+-1.992636317E-005,
++6.993315310E-006,
++3.347633174E-004,
++1.617751332E-005,
++1.207003334E-005,
++2.682086197E-004,
++1.521241393E-005,
++1.661818715E-005,
++2.233728592E-004,
+-2.525620175E-006,
++1.776598037E-005,
++1.774113771E-004,
+-1.191342653E-005,
++1.806914770E-005,
++1.312203676E-004,
+-1.985177369E-005,
++2.677291741E-005,
++1.024175072E-004,
+-2.570833203E-005,
++2.978993689E-005,
++6.541742187E-005,
+-3.018750249E-005,
++3.225446198E-005,
++3.193307566E-005,
+-2.554462844E-005,
++3.397853652E-005,
++1.714242217E-006,
+-2.618136386E-005,
++3.495384954E-005,
+-2.470704203E-005,
+-2.537086584E-005,
++3.515914432E-005,
+-4.491530854E-005,
+-2.362549276E-005,
++3.460439257E-005,
+-6.447290798E-005,
+-2.093936746E-005,
++3.334947178E-005,
+-8.078388782E-005,
+-1.751866148E-005,
++3.144468428E-005,
+-9.417100227E-005,
+-1.356193479E-005,
+-2.042970118E-005,
+-1.047207043E-004,
+-9.299508747E-006,
+-1.987093310E-005,
+-1.126275165E-004,
+-4.916387297E-006,
+-1.884208177E-005,
+-1.180980107E-004,
+-5.595519906E-005,
+-1.743183020E-005,
+-1.213575742E-004,
+-5.429694284E-005,
+-1.571428584E-005,
+-1.226499153E-004,
+-5.176846025E-005,
+-1.379448349E-005,
+-1.262027217E-004,
+-4.839275425E-005,
+-1.177108606E-005,
+-1.250260248E-004,
+-4.425736552E-005,
+-9.826449968E-006,
+-1.224978914E-004,
+-3.946387005E-005,
+-7.869333785E-006,
+-1.187910311E-004,
+-3.415624451E-005,
+-2.319611212E-006,
+-1.140582463E-004,
+-2.847247197E-005,
+-3.157242645E-006,
+-1.084438481E-004,
+-2.263354872E-005,
+-3.617151151E-006,
+-1.020687996E-004,
+-1.309637537E-005,
+-2.497214155E-006,
+-9.517164290E-005,
+-9.561075785E-006,
+-1.189317118E-006,
+-6.437721822E-008,
+-4.195037945E-006,
+-1.194632091E-006,
+-8.434094667E-008,
+-3.453840463E-006,
+-1.162929266E-006,
++3.809887872E-008,
+-2.715013807E-006,
+-1.085227950E-006,
++3.246264413E-008,
+-2.032118118E-006,
+-9.742954035E-007,
+-6.402664354E-008,
+-1.399798180E-006,
+-8.419976893E-007,
+-2.975164826E-008,
+-3.132386439E-007,
+-7.003467317E-007,
+-9.458596395E-008,
+-1.444918922E-007,
++5.564140224E-007,
+-4.341498823E-007,
+-2.788728892E-008,
++6.262345096E-007,
+-8.427224429E-007,
+-7.506701927E-009,
++6.767839409E-007,
+-3.332600045E-006,
+-1.314406006E-008,
++7.020648809E-007,
+-4.429412002E-006,
++3.399493131E-009,
++6.982898526E-007,
+-5.315936960E-006,
++2.682709610E-009,
++6.628192182E-007,
+-6.225028756E-006,
++1.613285505E-009,
++6.022448247E-007,
+-6.986399967E-006,
++6.702406963E-010,
++4.741137047E-007,
+-7.568834008E-006,
+-7.834767501E-008,
++3.970030775E-007,
+-7.941360309E-006,
+-2.014677420E-007,
++7.342250683E-007,
+-8.087732567E-006,
+-5.234479659E-007,
++3.961981463E-007,
+-8.006985809E-006,
+-1.190443072E-006,
++1.543309907E-007,
+-6.361419310E-006,
+-1.975324267E-006,
++5.083275667E-008,
+-6.015239251E-006,
+-9.451737242E-007,
++1.608403011E-008,
+-5.516381407E-006,
+-1.033426656E-006,
+-7.018770981E-011,
+-4.896494374E-006,
+-1.179182050E-006,
+-1.135985195E-010
+};
+
+double fir_32bands_nonperfect[] =
+{
+-1.390191784E-007,
+-1.693738625E-007,
+-2.030677564E-007,
+-2.404238444E-007,
+-2.818143514E-007,
+-3.276689142E-007,
+-3.784752209E-007,
+-4.347855338E-007,
+-4.972276315E-007,
+-5.665120852E-007,
+-6.434325428E-007,
+-7.288739425E-007,
+-8.238164355E-007,
+-9.293416952E-007,
+-1.046637067E-006,
+-1.176999604E-006,
+-1.321840614E-006,
+-1.482681114E-006,
+-1.661159786E-006,
+-1.859034001E-006,
+-2.078171747E-006,
+-2.320550948E-006,
+-2.588257530E-006,
+-2.883470643E-006,
+-3.208459020E-006,
+-3.565570978E-006,
+-3.957220997E-006,
+-4.385879038E-006,
+-4.854050530E-006,
+-5.364252502E-006,
+-5.918994248E-006,
+-6.520755960E-006,
+-7.171964626E-006,
+-7.874960829E-006,
+-8.631964192E-006,
+-9.445050637E-006,
+-1.031611009E-005,
+-1.124680875E-005,
+-1.223855270E-005,
+-1.329243969E-005,
+-1.440921824E-005,
+-1.558924305E-005,
+-1.683242772E-005,
+-1.813820381E-005,
+-1.950545993E-005,
+-2.093250441E-005,
+-2.241701623E-005,
+-2.395598858E-005,
+-2.554569073E-005,
+-2.718161704E-005,
+-2.885844333E-005,
+-3.056998685E-005,
+-3.230916263E-005,
+-3.406793985E-005,
+-3.583733633E-005,
+-3.760734762E-005,
+-3.936696885E-005,
+-4.110412556E-005,
+-4.280570283E-005,
+-4.445751256E-005,
+-4.604430433E-005,
+-4.754976908E-005,
+-4.895655002E-005,
+-5.024627535E-005,
++5.139957648E-005,
++5.239612074E-005,
++5.321469871E-005,
++5.383323878E-005,
++5.422891263E-005,
++5.437819709E-005,
++5.425697600E-005,
++5.384063843E-005,
++5.310418419E-005,
++5.202236207E-005,
++5.056979353E-005,
++4.872112549E-005,
++4.645117951E-005,
++4.373511547E-005,
++4.054862075E-005,
++3.686808850E-005,
++3.267079956E-005,
++2.793515523E-005,
++2.264085742E-005,
++1.676913780E-005,
++1.030297699E-005,
++3.227306706E-006,
+-4.470633485E-006,
+-1.280130618E-005,
+-2.177240640E-005,
+-3.138873581E-005,
+-4.165195787E-005,
+-5.256036457E-005,
+-6.410864444E-005,
+-7.628766616E-005,
+-8.908427117E-005,
+-1.024810626E-004,
+-1.164562127E-004,
+-1.309833024E-004,
+-1.460311323E-004,
+-1.615635992E-004,
+-1.775395358E-004,
+-1.939126523E-004,
+-2.106313768E-004,
+-2.276388550E-004,
+-2.448728774E-004,
+-2.622658503E-004,
+-2.797449124E-004,
+-2.972317743E-004,
+-3.146430245E-004,
+-3.318900708E-004,
+-3.488793736E-004,
+-3.655125911E-004,
+-3.816867538E-004,
+-3.972945851E-004,
+-4.122247046E-004,
+-4.263620067E-004,
+-4.395879805E-004,
+-4.517810594E-004,
+-4.628172028E-004,
+-4.725702747E-004,
+-4.809123348E-004,
+-4.877146275E-004,
+-4.928477574E-004,
+-4.961824161E-004,
+-4.975944757E-004,
+-4.969481961E-004,
+-4.941228544E-004,
+-4.889960401E-004,
++4.814492422E-004,
++4.713678791E-004,
++4.586426076E-004,
++4.431701091E-004,
++4.248536134E-004,
++4.036037717E-004,
++3.793396754E-004,
++3.519894381E-004,
++3.214911267E-004,
++2.877934603E-004,
++2.508567995E-004,
++2.106537577E-004,
++1.671699720E-004,
++1.204049113E-004,
++7.037253090E-005,
++1.710198012E-005,
+-3.936182839E-005,
+-9.895755647E-005,
+-1.616069785E-004,
+-2.272142592E-004,
+-2.956659591E-004,
+-3.668301215E-004,
+-4.405563814E-004,
+-5.166754709E-004,
+-5.949990009E-004,
+-6.753197522E-004,
+-7.574109477E-004,
+-8.410271257E-004,
+-9.259034996E-004,
+-1.011756598E-003,
+-1.098284614E-003,
+-1.185167348E-003,
+-1.272067428E-003,
+-1.358630019E-003,
+-1.444484224E-003,
+-1.529243193E-003,
+-1.612505526E-003,
+-1.693855622E-003,
+-1.772865304E-003,
+-1.849094522E-003,
+-1.922092517E-003,
+-1.991399564E-003,
+-2.056547208E-003,
+-2.117061289E-003,
+-2.172462177E-003,
+-2.222266514E-003,
+-2.265989315E-003,
+-2.303145360E-003,
+-2.333251061E-003,
+-2.355825622E-003,
+-2.370394068E-003,
+-2.376487479E-003,
+-2.373647178E-003,
+-2.361423569E-003,
+-2.339380793E-003,
+-2.307097195E-003,
+-2.264167881E-003,
+-2.210205887E-003,
+-2.144844970E-003,
+-2.067740774E-003,
+-1.978572691E-003,
+-1.877046190E-003,
+-1.762894331E-003,
+-1.635878929E-003,
++1.495792647E-003,
++1.342460280E-003,
++1.175740734E-003,
++9.955273708E-004,
++8.017504588E-004,
++5.943773431E-004,
++3.734139318E-004,
++1.389056415E-004,
+-1.090620208E-004,
+-3.703625989E-004,
+-6.448282511E-004,
+-9.322494152E-004,
+-1.232374110E-003,
+-1.544908970E-003,
+-1.869517611E-003,
+-2.205822384E-003,
+-2.553403843E-003,
+-2.911801683E-003,
+-3.280514618E-003,
+-3.659002949E-003,
+-4.046686925E-003,
+-4.442950245E-003,
+-4.847140983E-003,
+-5.258570891E-003,
+-5.676518660E-003,
+-6.100233644E-003,
+-6.528933067E-003,
+-6.961807609E-003,
+-7.398022339E-003,
+-7.836719044E-003,
+-8.277016692E-003,
+-8.718019351E-003,
+-9.158811532E-003,
+-9.598465636E-003,
+-1.003604382E-002,
+-1.047059800E-002,
+-1.090117730E-002,
+-1.132682897E-002,
+-1.174659748E-002,
+-1.215953380E-002,
+-1.256469358E-002,
+-1.296114177E-002,
+-1.334795821E-002,
+-1.372423489E-002,
+-1.408908330E-002,
+-1.444163360E-002,
+-1.478104480E-002,
+-1.510649733E-002,
+-1.541720331E-002,
+-1.571240649E-002,
+-1.599138230E-002,
+-1.625344716E-002,
+-1.649795473E-002,
+-1.672429405E-002,
+-1.693190821E-002,
+-1.712027565E-002,
+-1.728892699E-002,
+-1.743743755E-002,
+-1.756543480E-002,
+-1.767260395E-002,
+-1.775865816E-002,
+-1.782339066E-002,
+-1.786663756E-002,
+-1.788828894E-002,
++1.788828894E-002,
++1.786663756E-002,
++1.782339066E-002,
++1.775865816E-002,
++1.767260395E-002,
++1.756543480E-002,
++1.743743755E-002,
++1.728892699E-002,
++1.712027565E-002,
++1.693190821E-002,
++1.672429405E-002,
++1.649795473E-002,
++1.625344716E-002,
++1.599138230E-002,
++1.571240649E-002,
++1.541720331E-002,
++1.510649733E-002,
++1.478104480E-002,
++1.444163360E-002,
++1.408908330E-002,
++1.372423489E-002,
++1.334795821E-002,
++1.296114177E-002,
++1.256469358E-002,
++1.215953380E-002,
++1.174659748E-002,
++1.132682897E-002,
++1.090117730E-002,
++1.047059800E-002,
++1.003604382E-002,
++9.598465636E-003,
++9.158811532E-003,
++8.718019351E-003,
++8.277016692E-003,
++7.836719044E-003,
++7.398022339E-003,
++6.961807609E-003,
++6.528933067E-003,
++6.100233644E-003,
++5.676518660E-003,
++5.258570891E-003,
++4.847140983E-003,
++4.442950245E-003,
++4.046686925E-003,
++3.659002949E-003,
++3.280514618E-003,
++2.911801683E-003,
++2.553403843E-003,
++2.205822384E-003,
++1.869517611E-003,
++1.544908970E-003,
++1.232374110E-003,
++9.322494152E-004,
++6.448282511E-004,
++3.703625989E-004,
++1.090620208E-004,
+-1.389056415E-004,
+-3.734139318E-004,
+-5.943773431E-004,
+-8.017504588E-004,
+-9.955273708E-004,
+-1.175740734E-003,
+-1.342460280E-003,
+-1.495792647E-003,
++1.635878929E-003,
++1.762894331E-003,
++1.877046190E-003,
++1.978572691E-003,
++2.067740774E-003,
++2.144844970E-003,
++2.210205887E-003,
++2.264167881E-003,
++2.307097195E-003,
++2.339380793E-003,
++2.361423569E-003,
++2.373647178E-003,
++2.376487479E-003,
++2.370394068E-003,
++2.355825622E-003,
++2.333251061E-003,
++2.303145360E-003,
++2.265989315E-003,
++2.222266514E-003,
++2.172462177E-003,
++2.117061289E-003,
++2.056547208E-003,
++1.991399564E-003,
++1.922092517E-003,
++1.849094522E-003,
++1.772865304E-003,
++1.693855622E-003,
++1.612505526E-003,
++1.529243193E-003,
++1.444484224E-003,
++1.358630019E-003,
++1.272067428E-003,
++1.185167348E-003,
++1.098284614E-003,
++1.011756598E-003,
++9.259034996E-004,
++8.410271257E-004,
++7.574109477E-004,
++6.753197522E-004,
++5.949990009E-004,
++5.166754709E-004,
++4.405563814E-004,
++3.668301215E-004,
++2.956659591E-004,
++2.272142592E-004,
++1.616069785E-004,
++9.895755647E-005,
++3.936182839E-005,
+-1.710198012E-005,
+-7.037253090E-005,
+-1.204049113E-004,
+-1.671699720E-004,
+-2.106537577E-004,
+-2.508567995E-004,
+-2.877934603E-004,
+-3.214911267E-004,
+-3.519894381E-004,
+-3.793396754E-004,
+-4.036037717E-004,
+-4.248536134E-004,
+-4.431701091E-004,
+-4.586426076E-004,
+-4.713678791E-004,
+-4.814492422E-004,
++4.889960401E-004,
++4.941228544E-004,
++4.969481961E-004,
++4.975944757E-004,
++4.961824161E-004,
++4.928477574E-004,
++4.877146275E-004,
++4.809123348E-004,
++4.725702747E-004,
++4.628172028E-004,
++4.517810594E-004,
++4.395879805E-004,
++4.263620067E-004,
++4.122247046E-004,
++3.972945851E-004,
++3.816867538E-004,
++3.655125911E-004,
++3.488793736E-004,
++3.318900708E-004,
++3.146430245E-004,
++2.972317743E-004,
++2.797449124E-004,
++2.622658503E-004,
++2.448728774E-004,
++2.276388550E-004,
++2.106313768E-004,
++1.939126523E-004,
++1.775395358E-004,
++1.615635992E-004,
++1.460311323E-004,
++1.309833024E-004,
++1.164562127E-004,
++1.024810626E-004,
++8.908427117E-005,
++7.628766616E-005,
++6.410864444E-005,
++5.256036457E-005,
++4.165195787E-005,
++3.138873581E-005,
++2.177240640E-005,
++1.280130618E-005,
++4.470633485E-006,
+-3.227306706E-006,
+-1.030297699E-005,
+-1.676913780E-005,
+-2.264085742E-005,
+-2.793515523E-005,
+-3.267079956E-005,
+-3.686808850E-005,
+-4.054862075E-005,
+-4.373511547E-005,
+-4.645117951E-005,
+-4.872112549E-005,
+-5.056979353E-005,
+-5.202236207E-005,
+-5.310418419E-005,
+-5.384063843E-005,
+-5.425697600E-005,
+-5.437819709E-005,
+-5.422891263E-005,
+-5.383323878E-005,
+-5.321469871E-005,
+-5.239612074E-005,
+-5.139957648E-005,
++5.024627535E-005,
++4.895655002E-005,
++4.754976908E-005,
++4.604430433E-005,
++4.445751256E-005,
++4.280570283E-005,
++4.110412556E-005,
++3.936696885E-005,
++3.760734762E-005,
++3.583733633E-005,
++3.406793985E-005,
++3.230916263E-005,
++3.056998685E-005,
++2.885844333E-005,
++2.718161704E-005,
++2.554569073E-005,
++2.395598858E-005,
++2.241701623E-005,
++2.093250441E-005,
++1.950545993E-005,
++1.813820381E-005,
++1.683242772E-005,
++1.558924305E-005,
++1.440921824E-005,
++1.329243969E-005,
++1.223855270E-005,
++1.124680875E-005,
++1.031611009E-005,
++9.445050637E-006,
++8.631964192E-006,
++7.874960829E-006,
++7.171964626E-006,
++6.520755960E-006,
++5.918994248E-006,
++5.364252502E-006,
++4.854050530E-006,
++4.385879038E-006,
++3.957220997E-006,
++3.565570978E-006,
++3.208459020E-006,
++2.883470643E-006,
++2.588257530E-006,
++2.320550948E-006,
++2.078171747E-006,
++1.859034001E-006,
++1.661159786E-006,
++1.482681114E-006,
++1.321840614E-006,
++1.176999604E-006,
++1.046637067E-006,
++9.293416952E-007,
++8.238164355E-007,
++7.288739425E-007,
++6.434325428E-007,
++5.665120852E-007,
++4.972276315E-007,
++4.347855338E-007,
++3.784752209E-007,
++3.276689142E-007,
++2.818143514E-007,
++2.404238444E-007,
++2.030677564E-007,
++1.693738625E-007,
++1.390191784E-007
+};
+
+double 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
+};
+
+double 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
+};
diff --git a/contrib/libdca/tables_huffman.h b/contrib/libdca/tables_huffman.h
new file mode 100644
index 000000000..abe4c138c
--- /dev/null
+++ b/contrib/libdca/tables_huffman.h
@@ -0,0 +1,1072 @@
+/*
+ * huffman_tables.h
+ * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
+ *
+ * This file is part of libdca, a free DTS Coherent Acoustics stream decoder.
+ * See http://www.videolan.org/developers/libdca.html for updates.
+ *
+ * libdca 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.
+ *
+ * libdca is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+typedef struct huff_entry_s
+{
+ int length;
+ int code;
+ int value;
+
+} huff_entry_t;
+
+huff_entry_t bitalloc_a_12[] =
+{
+ { 1, 0, 1}, { 2, 2, 2}, { 3, 6, 3}, { 4, 14, 4},
+ { 5, 30, 5}, { 6, 62, 6}, { 8, 255, 7}, { 8, 254, 8},
+ { 9, 507, 9}, { 9, 506, 10}, { 9, 505, 11}, { 9, 504, 12},
+ { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_b_12[] =
+{
+ { 1, 1, 1}, { 2, 0, 2}, { 3, 2, 3}, { 5, 15, 4},
+ { 5, 12, 5}, { 6, 29, 6}, { 7, 57, 7}, { 7, 56, 8},
+ { 7, 55, 9}, { 7, 54, 10}, { 7, 53, 11}, { 7, 52, 12},
+ { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_c_12[] =
+{
+ { 2, 0, 1}, { 3, 7, 2}, { 3, 5, 3}, { 3, 4, 4},
+ { 3, 2, 5}, { 4, 13, 6}, { 4, 12, 7}, { 4, 6, 8},
+ { 5, 15, 9}, { 6, 29, 10}, { 7, 57, 11}, { 7, 56, 12},
+ { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_d_12[] =
+{
+ { 2, 3, 1}, { 2, 2, 2}, { 2, 0, 3}, { 3, 2, 4},
+ { 4, 6, 5}, { 5, 14, 6}, { 6, 30, 7}, { 7, 62, 8},
+ { 8, 126, 9}, { 9, 254, 10}, {10, 511, 11}, {10, 510, 12},
+ { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_e_12[] =
+{
+ { 1, 1, 1}, { 2, 0, 2}, { 3, 2, 3}, { 4, 6, 4},
+ { 5, 14, 5}, { 7, 63, 6}, { 7, 61, 7}, { 8, 124, 8},
+ { 8, 121, 9}, { 8, 120, 10}, { 9, 251, 11}, { 9, 250, 12},
+ { 0, 0, 0}
+};
+
+huff_entry_t *bitalloc_12[] =
+{
+ bitalloc_a_12,
+ bitalloc_b_12,
+ bitalloc_c_12,
+ bitalloc_d_12,
+ bitalloc_e_12
+};
+
+huff_entry_t scales_a_129[] =
+{
+ { 2, 1, 0}, { 3, 6, 1}, { 3, 5, -1}, { 3, 0, 2},
+ { 4, 15, -2}, { 4, 8, 3}, { 4, 3, -3}, { 5, 28, 4},
+ { 5, 19, -4}, { 5, 4, 5}, { 6, 59, -5}, { 6, 36, 6},
+ { 6, 11, -6}, { 7, 75, 7}, { 7, 74, -7}, { 8, 233, 8},
+ { 8, 232, -8}, { 8, 41, 9}, { 8, 40, -9}, { 9, 87, 10},
+ { 9, 86,-10}, {10, 937, 11}, {10, 936,-11}, {11, 1877, 12},
+ {11, 1876,-12}, {11, 341, 13}, {11, 340,-13}, {12, 686, 14},
+ {12, 685,-14}, {13, 1375, 15}, {13, 1374,-15}, {13, 1369, 16},
+ {13, 1368,-16}, {13, 1359, 17}, {13, 1358,-17}, {13, 1357, 18},
+ {13, 1356,-18}, {13, 1355, 19}, {13, 1354,-19}, {13, 1353, 20},
+ {13, 1352,-20}, {13, 1351, 21}, {13, 1350,-21}, {13, 1349, 22},
+ {13, 1348,-22}, {13, 1347, 23}, {13, 1346,-23}, {13, 1345, 24},
+ {13, 1344,-24}, {14, 15103, 25}, {14, 15102,-25}, {14, 15101, 26},
+ {14, 15100,-26}, {14, 15099, 27}, {14, 15098,-27}, {14, 15097, 28},
+ {14, 15096,-28}, {14, 15095, 29}, {14, 15094,-29}, {14, 15093, 30},
+ {14, 15092,-30}, {14, 15091, 31}, {14, 15090,-31}, {14, 15089, 32},
+ {14, 15088,-32}, {14, 15087, 33}, {14, 15086,-33}, {14, 15085, 34},
+ {14, 15084,-34}, {14, 15083, 35}, {14, 15082,-35}, {14, 15081, 36},
+ {14, 15080,-36}, {14, 15079, 37}, {14, 15078,-37}, {14, 15077, 38},
+ {14, 15076,-38}, {14, 15075, 39}, {14, 15074,-39}, {14, 15073, 40},
+ {14, 15072,-40}, {14, 15071, 41}, {14, 15070,-41}, {14, 15069, 42},
+ {14, 15068,-42}, {14, 15067, 43}, {14, 15066,-43}, {14, 15065, 44},
+ {14, 15064,-44}, {14, 15063, 45}, {14, 15062,-45}, {14, 15061, 46},
+ {14, 15060,-46}, {14, 15059, 47}, {14, 15058,-47}, {14, 15057, 48},
+ {14, 15056,-48}, {14, 15055, 49}, {14, 15054,-49}, {14, 15053, 50},
+ {14, 15052,-50}, {14, 15051, 51}, {14, 15050,-51}, {14, 15049, 52},
+ {14, 15048,-52}, {14, 15047, 53}, {14, 15046,-53}, {14, 15045, 54},
+ {14, 15044,-54}, {14, 15043, 55}, {14, 15042,-55}, {14, 15041, 56},
+ {14, 15040,-56}, {14, 15039, 57}, {14, 15038,-57}, {14, 15037, 58},
+ {14, 15036,-58}, {14, 15035, 59}, {14, 15034,-59}, {14, 15033, 60},
+ {14, 15032,-60}, {14, 15031, 61}, {14, 15030,-61}, {14, 15029, 62},
+ {14, 15028,-62}, {14, 15027, 63}, {14, 15026,-63}, {14, 15025, 64},
+ {14, 15024,-64}, { 0, 0, 0}
+};
+
+huff_entry_t scales_b_129[] =
+{
+ { 3, 3, 0}, { 3, 2, 1}, { 3, 1, -1}, { 4, 15, 2},
+ { 4, 14, -2}, { 4, 12, 3}, { 4, 11, -3}, { 4, 10, 4},
+ { 4, 9, -4}, { 4, 0, 5}, { 5, 27, -5}, { 5, 17, 6},
+ { 5, 16, -6}, { 6, 53, 7}, { 6, 52, -7}, { 6, 5, 8},
+ { 6, 4, -8}, { 7, 13, 9}, { 7, 12, -9}, { 8, 29, 10},
+ { 8, 28,-10}, { 9, 60, 11}, {10, 127,-11}, {11, 253, 12},
+ {11, 252,-12}, {12, 491, 13}, {12, 490,-13}, {13, 979, 14},
+ {13, 978,-14}, {14, 1955, 15}, {14, 1954,-15}, {14, 1953, 16},
+ {14, 1952,-16}, {15, 4031, 17}, {15, 4030,-17}, {15, 4029, 18},
+ {15, 4028,-18}, {15, 4027, 19}, {15, 4026,-19}, {15, 4025, 20},
+ {15, 4024,-20}, {15, 4023, 21}, {15, 4022,-21}, {15, 4021, 22},
+ {15, 4020,-22}, {15, 4019, 23}, {15, 4018,-23}, {15, 4017, 24},
+ {15, 4016,-24}, {15, 4015, 25}, {15, 4014,-25}, {15, 4013, 26},
+ {15, 4012,-26}, {15, 4011, 27}, {15, 4010,-27}, {15, 4009, 28},
+ {15, 4008,-28}, {15, 4007, 29}, {15, 4006,-29}, {15, 4005, 30},
+ {15, 4004,-30}, {15, 4003, 31}, {15, 4002,-31}, {15, 4001, 32},
+ {15, 4000,-32}, {15, 3999, 33}, {15, 3998,-33}, {15, 3997, 34},
+ {15, 3996,-34}, {15, 3995, 35}, {15, 3994,-35}, {15, 3993, 36},
+ {15, 3992,-36}, {15, 3991, 37}, {15, 3990,-37}, {15, 3989, 38},
+ {15, 3988,-38}, {15, 3987, 39}, {15, 3986,-39}, {15, 3985, 40},
+ {15, 3984,-40}, {15, 3983, 41}, {15, 3982,-41}, {15, 3981, 42},
+ {15, 3980,-42}, {15, 3979, 43}, {15, 3978,-43}, {15, 3977, 44},
+ {15, 3976,-44}, {15, 3975, 45}, {15, 3974,-45}, {15, 3973, 46},
+ {15, 3972,-46}, {15, 3971, 47}, {15, 3970,-47}, {15, 3969, 48},
+ {15, 3968,-48}, {15, 3967, 49}, {15, 3966,-49}, {15, 3965, 50},
+ {15, 3964,-50}, {15, 3963, 51}, {15, 3962,-51}, {15, 3961, 52},
+ {15, 3960,-52}, {15, 3959, 53}, {15, 3958,-53}, {15, 3957, 54},
+ {15, 3956,-54}, {15, 3955, 55}, {15, 3954,-55}, {15, 3953, 56},
+ {15, 3952,-56}, {15, 3951, 57}, {15, 3950,-57}, {15, 3949, 58},
+ {15, 3948,-58}, {15, 3947, 59}, {15, 3946,-59}, {15, 3945, 60},
+ {15, 3944,-60}, {15, 3943, 61}, {15, 3942,-61}, {15, 3941, 62},
+ {15, 3940,-62}, {15, 3939, 63}, {15, 3938,-63}, {15, 3937, 64},
+ {15, 3936,-64}, { 0, 0, 0}
+};
+
+huff_entry_t scales_c_129[] =
+{
+ { 3, 4, 0}, { 3, 1, 1}, { 3, 0, -1}, { 4, 13, 2},
+ { 4, 12, -2}, { 4, 7, 3}, { 4, 6, -3}, { 5, 31, 4},
+ { 5, 30, -4}, { 5, 23, 5}, { 5, 22, -5}, { 5, 11, 6},
+ { 5, 10, -6}, { 6, 59, 7}, { 6, 58, -7}, { 6, 43, 8},
+ { 6, 42, -8}, { 6, 19, 9}, { 6, 18, -9}, { 7, 115, 10},
+ { 7, 114,-10}, { 7, 83, 11}, { 7, 82,-11}, { 7, 35, 12},
+ { 7, 34,-12}, { 8, 227, 13}, { 8, 226,-13}, { 8, 162, 14},
+ { 8, 161,-14}, { 8, 66, 15}, { 8, 65,-15}, { 9, 450, 16},
+ { 9, 449,-16}, { 9, 321, 17}, { 9, 320,-17}, { 9, 129, 18},
+ { 9, 128,-18}, {10, 897, 19}, {10, 896,-19}, {10, 652, 20},
+ {10, 271,-20}, {10, 268, 21}, {11, 1807,-21}, {11, 1308, 22},
+ {11, 1307,-22}, {11, 540, 23}, {11, 539,-23}, {12, 3612, 24},
+ {12, 3611,-24}, {12, 2613, 25}, {12, 2612,-25}, {12, 1077, 26},
+ {12, 1076,-26}, {13, 7226, 27}, {13, 7221,-27}, {13, 2167, 28},
+ {13, 2166,-28}, {13, 2164, 29}, {14, 14455,-29}, {14, 14441, 30},
+ {14, 14440,-30}, {14, 4331, 31}, {14, 4330,-31}, {15, 28909, 32},
+ {15, 28908,-32}, {15, 28879, 33}, {15, 28878,-33}, {15, 28877, 34},
+ {15, 28876,-34}, {15, 28875, 35}, {15, 28874,-35}, {15, 28873, 36},
+ {15, 28872,-36}, {15, 28871, 37}, {15, 28870,-37}, {15, 28869, 38},
+ {15, 28868,-38}, {15, 28867, 39}, {15, 28866,-39}, {15, 28865, 40},
+ {15, 28864,-40}, {15, 20991, 41}, {15, 20990,-41}, {15, 20989, 42},
+ {15, 20988,-42}, {15, 20987, 43}, {15, 20986,-43}, {15, 20985, 44},
+ {15, 20984,-44}, {15, 20983, 45}, {15, 20982,-45}, {15, 20981, 46},
+ {15, 20980,-46}, {15, 20979, 47}, {15, 20978,-47}, {15, 20977, 48},
+ {15, 20976,-48}, {15, 20975, 49}, {15, 20974,-49}, {15, 20973, 50},
+ {15, 20972,-50}, {15, 20971, 51}, {15, 20970,-51}, {15, 20969, 52},
+ {15, 20968,-52}, {15, 20967, 53}, {15, 20966,-53}, {15, 20965, 54},
+ {15, 20964,-54}, {15, 20963, 55}, {15, 20962,-55}, {15, 20961, 56},
+ {15, 20960,-56}, {15, 20959, 57}, {15, 20958,-57}, {15, 20957, 58},
+ {15, 20956,-58}, {15, 20955, 59}, {15, 20954,-59}, {15, 20953, 60},
+ {15, 20952,-60}, {15, 20951, 61}, {15, 20950,-61}, {15, 20949, 62},
+ {15, 20948,-62}, {15, 20947, 63}, {15, 20946,-63}, {15, 20945, 64},
+ {15, 20944,-64}, { 0, 0, 0}
+};
+
+huff_entry_t scales_d_129[] =
+{
+ { 2, 0, 0}, { 3, 5, 1}, { 3, 4, -1}, { 4, 15, 2},
+ { 4, 14, -2}, { 4, 7, 3}, { 4, 6, -3}, { 5, 26, 4},
+ { 5, 25, -4}, { 5, 10, 5}, { 5, 9, -5}, { 6, 54, 6},
+ { 6, 49, -6}, { 6, 22, 7}, { 6, 17, -7}, { 7, 110, 8},
+ { 7, 97, -8}, { 7, 46, 9}, { 7, 33, -9}, { 8, 193, 10},
+ { 8, 192,-10}, { 8, 65, 11}, { 8, 64,-11}, { 9, 444, 12},
+ { 9, 191,-12}, { 9, 188, 13}, {10, 895,-13}, {10, 890, 14},
+ {10, 381,-14}, {10, 378, 15}, {11, 1789,-15}, {11, 761, 16},
+ {11, 760,-16}, {12, 3577, 17}, {12, 3576,-17}, {12, 1519, 18},
+ {12, 1518,-18}, {12, 1516, 19}, {13, 7151,-19}, {13, 7128, 20},
+ {13, 3035,-20}, {14, 14301, 21}, {14, 14300,-21}, {14, 6069, 22},
+ {14, 6068,-22}, {15, 28599, 23}, {15, 28598,-23}, {15, 28597, 24},
+ {15, 28596,-24}, {15, 28595, 25}, {15, 28594,-25}, {15, 28593, 26},
+ {15, 28592,-26}, {15, 28591, 27}, {15, 28590,-27}, {15, 28589, 28},
+ {15, 28588,-28}, {15, 28587, 29}, {15, 28586,-29}, {15, 28585, 30},
+ {15, 28584,-30}, {15, 28583, 31}, {15, 28582,-31}, {15, 28581, 32},
+ {15, 28580,-32}, {15, 28579, 33}, {15, 28578,-33}, {15, 28577, 34},
+ {15, 28576,-34}, {15, 28575, 35}, {15, 28574,-35}, {15, 28573, 36},
+ {15, 28572,-36}, {15, 28571, 37}, {15, 28570,-37}, {15, 28569, 38},
+ {15, 28568,-38}, {15, 28567, 39}, {15, 28566,-39}, {15, 28565, 40},
+ {15, 28564,-40}, {15, 28563, 41}, {15, 28562,-41}, {15, 28561, 42},
+ {15, 28560,-42}, {15, 28559, 43}, {15, 28558,-43}, {15, 28557, 44},
+ {15, 28556,-44}, {15, 28555, 45}, {15, 28554,-45}, {15, 28553, 46},
+ {15, 28552,-46}, {15, 28551, 47}, {15, 28550,-47}, {15, 28549, 48},
+ {15, 28548,-48}, {15, 28547, 49}, {15, 28546,-49}, {15, 28545, 50},
+ {15, 28544,-50}, {15, 28543, 51}, {15, 28542,-51}, {15, 28541, 52},
+ {15, 28540,-52}, {15, 28539, 53}, {15, 28538,-53}, {15, 28537, 54},
+ {15, 28536,-54}, {15, 28535, 55}, {15, 28534,-55}, {15, 28533, 56},
+ {15, 28532,-56}, {15, 28531, 57}, {15, 28530,-57}, {15, 28529, 58},
+ {15, 28528,-58}, {15, 28527, 59}, {15, 28526,-59}, {15, 28525, 60},
+ {15, 28524,-60}, {15, 28523, 61}, {15, 28522,-61}, {15, 28521, 62},
+ {15, 28520,-62}, {15, 28519, 63}, {15, 28518,-63}, {15, 28517, 64},
+ {15, 28516,-64}, { 0, 0, 0}
+};
+
+huff_entry_t scales_e_129[] =
+{
+ { 4, 14, 0}, { 4, 11, 1}, { 4, 10, -1}, { 4, 7, 2},
+ { 4, 6, -2}, { 4, 3, 3}, { 4, 2, -3}, { 5, 31, 4},
+ { 5, 30, -4}, { 5, 25, 5}, { 5, 24, -5}, { 5, 17, 6},
+ { 5, 16, -6}, { 5, 9, 7}, { 5, 8, -7}, { 5, 1, 8},
+ { 5, 0, -8}, { 6, 53, 9}, { 6, 52, -9}, { 6, 37, 10},
+ { 6, 36,-10}, { 6, 21, 11}, { 6, 20,-11}, { 6, 5, 12},
+ { 6, 4,-12}, { 7, 109, 13}, { 7, 108,-13}, { 7, 77, 14},
+ { 7, 76,-14}, { 7, 45, 15}, { 7, 44,-15}, { 7, 13, 16},
+ { 7, 12,-16}, { 8, 221, 17}, { 8, 220,-17}, { 8, 157, 18},
+ { 8, 156,-18}, { 8, 93, 19}, { 8, 92,-19}, { 8, 29, 20},
+ { 8, 28,-20}, { 9, 445, 21}, { 9, 444,-21}, { 9, 317, 22},
+ { 9, 316,-22}, { 9, 189, 23}, { 9, 188,-23}, { 9, 61, 24},
+ { 9, 60,-24}, {10, 892, 25}, {10, 639,-25}, {10, 637, 26},
+ {10, 636,-26}, {10, 381, 27}, {10, 380,-27}, {10, 125, 28},
+ {10, 124,-28}, {11, 1788, 29}, {11, 1787,-29}, {11, 1276, 30},
+ {11, 767,-30}, {11, 764, 31}, {11, 255,-31}, {11, 252, 32},
+ {12, 3583,-32}, {12, 3579, 33}, {12, 3578,-33}, {12, 2555, 34},
+ {12, 2554,-34}, {12, 1531, 35}, {12, 1530,-35}, {12, 507, 36},
+ {12, 506,-36}, {13, 7160, 37}, {13, 7147,-37}, {13, 7144, 38},
+ {13, 3067,-38}, {13, 3065, 39}, {13, 3064,-39}, {13, 1017, 40},
+ {13, 1016,-40}, {14, 14330, 41}, {14, 14329,-41}, {14, 14291, 42},
+ {14, 14290,-42}, {14, 6132, 43}, {14, 2039,-43}, {14, 2038, 44},
+ {14, 2037,-44}, {15, 28663, 45}, {15, 28662,-45}, {15, 28585, 46},
+ {15, 28584,-46}, {15, 12267, 47}, {15, 12266,-47}, {15, 4073, 48},
+ {15, 4072,-48}, {16, 57315, 49}, {16, 57314,-49}, {16, 57313, 50},
+ {16, 57312,-50}, {16, 57311, 51}, {16, 57310,-51}, {16, 57309, 52},
+ {16, 57308,-52}, {16, 57307, 53}, {16, 57306,-53}, {16, 57305, 54},
+ {16, 57304,-54}, {16, 57303, 55}, {16, 57302,-55}, {16, 57301, 56},
+ {16, 57300,-56}, {16, 57299, 57}, {16, 57298,-57}, {16, 57297, 58},
+ {16, 57296,-58}, {16, 57295, 59}, {16, 57294,-59}, {16, 57293, 60},
+ {16, 57292,-60}, {16, 57291, 61}, {16, 57290,-61}, {16, 57289, 62},
+ {16, 57288,-62}, {16, 57175, 63}, {16, 57174,-63}, {16, 57173, 64},
+ {16, 57172,-64}, { 0, 0, 0}
+};
+
+huff_entry_t *scales_129[] =
+{
+ scales_a_129,
+ scales_b_129,
+ scales_c_129,
+ scales_d_129,
+ scales_e_129
+};
+
+huff_entry_t bitalloc_a_3[] =
+{
+ { 1, 0, 0}, { 2, 2, 1}, { 2, 3, -1}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_a_4[] =
+{
+ { 1, 0, 0}, { 2, 2, 1}, { 3, 6, 2}, { 3, 7, 3},
+ { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_b_4[] =
+{
+ { 2, 2, 0}, { 3, 6, 1}, { 3, 7, 2}, { 1, 0, 3},
+ { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_c_4[] =
+{
+ { 3, 6, 0}, { 3, 7, 1}, { 1, 0, 2}, { 2, 2, 3},
+ { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_d_4[] =
+{
+ { 2, 0, 0}, { 2, 1, 1}, { 2, 2, 2}, { 2, 3, 3},
+ { 0, 0, 0}
+};
+
+huff_entry_t *tmode[] =
+{
+ bitalloc_a_4,
+ bitalloc_b_4,
+ bitalloc_c_4,
+ bitalloc_d_4
+};
+
+huff_entry_t bitalloc_a_5[] =
+{
+ { 1, 0, 0}, { 2, 2, 1}, { 3, 6, -1}, { 4, 14, 2},
+ { 4, 15, -2}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_b_5[] =
+{
+ { 2, 2, 0}, { 2, 0, 1}, { 2, 1, -1}, { 3, 6, 2},
+ { 3, 7, -2}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_c_5[] =
+{
+ { 1, 0, 0}, { 3, 4, 1}, { 3, 5, -1}, { 3, 6, 2},
+ { 3, 7, -2}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_a_7[] =
+{
+ { 1, 0, 0}, { 3, 6, 1}, { 3, 5, -1}, { 3, 4, 2},
+ { 4, 14, -2}, { 5, 31, 3}, { 5, 30, -3}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_b_7[] =
+{
+ { 2, 3, 0}, { 2, 1, 1}, { 2, 0, -1}, { 3, 4, 2},
+ { 4, 11, -2}, { 5, 21, 3}, { 5, 20, -3}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_c_7[] =
+{
+ { 2, 3, 0}, { 2, 2, 1}, { 2, 1, -1}, { 4, 3, 2},
+ { 4, 2, -2}, { 4, 1, 3}, { 4, 0, -3}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_a_9[] =
+{
+ { 1, 0, 0}, { 3, 7, 1}, { 3, 5, -1}, { 4, 13, 2},
+ { 4, 9, -2}, { 4, 8, 3}, { 5, 25, -3}, { 6, 49, 4},
+ { 6, 48, -4}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_b_9[] =
+{
+ { 2, 2, 0}, { 2, 0, 1}, { 3, 7, -1}, { 3, 3, 2},
+ { 3, 2, -2}, { 5, 27, 3}, { 5, 26, -3}, { 5, 25, 4},
+ { 5, 24, -4}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_c_9[] =
+{
+ { 2, 2, 0}, { 2, 0, 1}, { 3, 7, -1}, { 3, 6, 2},
+ { 3, 2, -2}, { 4, 6, 3}, { 5, 15, -3}, { 6, 29, 4},
+ { 6, 28, -4}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_a_13[] =
+{
+ { 1, 0, 0}, { 3, 4, 1}, { 4, 15, -1}, { 4, 13, 2},
+ { 4, 12, -2}, { 4, 10, 3}, { 5, 29, -3}, { 5, 22, 4},
+ { 6, 57, -4}, { 6, 47, 5}, { 6, 46, -5}, { 7, 113, 6},
+ { 7, 112, -6}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_b_13[] =
+{
+ { 2, 0, 0}, { 3, 6, 1}, { 3, 5, -1}, { 3, 2, 2},
+ { 4, 15, -2}, { 4, 9, 3}, { 4, 7, -3}, { 4, 6, 4},
+ { 5, 29, -4}, { 5, 17, 5}, { 5, 16, -5}, { 6, 57, 6},
+ { 6, 56, -6}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_c_13[] =
+{
+ { 3, 5, 0}, { 3, 4, 1}, { 3, 3, -1}, { 3, 2, 2},
+ { 3, 0, -2}, { 4, 15, 3}, { 4, 14, -3}, { 4, 12, 4},
+ { 4, 3, -4}, { 5, 27, 5}, { 5, 26, -5}, { 5, 5, 6},
+ { 5, 4, -6}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_a_17[] =
+{
+ { 2, 1, 0}, { 3, 7, 1}, { 3, 6, -1}, { 3, 4, 2},
+ { 3, 1, -2}, { 4, 11, 3}, { 4, 10, -3}, { 4, 0, 4},
+ { 5, 3, -4}, { 6, 4, 5}, { 7, 11, -5}, { 8, 20, 6},
+ { 9, 43, -6}, {10, 84, 7}, {11, 171, -7}, {12, 341, 8},
+ {12, 340, -8}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_b_17[] =
+{
+ { 2, 0, 0}, { 3, 6, 1}, { 3, 5, -1}, { 3, 2, 2},
+ { 4, 15, -2}, { 4, 9, 3}, { 4, 8, -3}, { 5, 29, 4},
+ { 5, 28, -4}, { 5, 14, 5}, { 5, 13, -5}, { 6, 30, 6},
+ { 6, 25, -6}, { 6, 24, 7}, { 7, 63, -7}, { 8, 125, 8},
+ { 8, 124, -8}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_c_17[] =
+{
+ { 3, 6, 0}, { 3, 4, 1}, { 3, 3, -1}, { 3, 0, 2},
+ { 4, 15, -2}, { 4, 11, 3}, { 4, 10, -3}, { 4, 4, 4},
+ { 4, 3, -4}, { 5, 29, 5}, { 5, 28, -5}, { 5, 10, 6},
+ { 5, 5, -6}, { 5, 4, 7}, { 6, 23, -7}, { 7, 45, 8},
+ { 7, 44, -8}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_d_17[] =
+{
+ { 1, 0, 0}, { 3, 7, 1}, { 3, 6, -1}, { 4, 11, 2},
+ { 4, 10, -2}, { 5, 19, 3}, { 5, 18, -3}, { 6, 35, 4},
+ { 6, 34, -4}, { 7, 67, 5}, { 7, 66, -5}, { 8, 131, 6},
+ { 8, 130, -6}, { 9, 259, 7}, { 9, 258, -7}, { 9, 257, 8},
+ { 9, 256, -8}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_e_17[] =
+{
+ { 1, 0, 0}, { 3, 5, 1}, { 3, 4, -1}, { 4, 12, 2},
+ { 5, 31, -2}, { 5, 28, 3}, { 5, 27, -3}, { 6, 60, 4},
+ { 6, 59, -4}, { 6, 53, 5}, { 6, 52, -5}, { 7, 122, 6},
+ { 7, 117, -6}, { 8, 247, 7}, { 8, 246, -7}, { 8, 233, 8},
+ { 8, 232, -8}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_f_17[] =
+{
+ { 3, 6, 0}, { 3, 5, 1}, { 3, 4, -1}, { 3, 2, 2},
+ { 3, 1, -2}, { 4, 15, 3}, { 4, 14, -3}, { 4, 6, 4},
+ { 4, 1, -4}, { 5, 14, 5}, { 5, 1, -5}, { 6, 31, 6},
+ { 6, 30, -6}, { 6, 0, 7}, { 7, 3, -7}, { 8, 5, 8},
+ { 8, 4, -8}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_g_17[] =
+{
+ { 2, 2, 0}, { 3, 7, 1}, { 3, 6, -1}, { 3, 1, 2},
+ { 3, 0, -2}, { 4, 5, 3}, { 4, 4, -3}, { 5, 14, 4},
+ { 5, 13, -4}, { 6, 30, 5}, { 6, 25, -5}, { 7, 62, 6},
+ { 7, 49, -6}, { 8, 127, 7}, { 8, 126, -7}, { 8, 97, 8},
+ { 8, 96, -8}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_a_25[] =
+{
+ { 3, 6, 0}, { 3, 4, 1}, { 3, 3, -1}, { 3, 1, 2},
+ { 3, 0, -2}, { 4, 15, 3}, { 4, 14, -3}, { 4, 5, 4},
+ { 4, 4, -4}, { 5, 22, 5}, { 5, 21, -5}, { 6, 47, 6},
+ { 6, 46, -6}, { 7, 83, 7}, { 7, 82, -7}, { 8, 163, 8},
+ { 8, 162, -8}, { 8, 160, 9}, { 9, 323, -9}, {10, 644, 10},
+ {11, 1291,-10}, {12, 2580, 11}, {13, 5163,-11}, {14, 10325, 12},
+ {14, 10324,-12}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_b_25[] =
+{
+ { 3, 5, 0}, { 3, 2, 1}, { 3, 1, -1}, { 4, 15, 2},
+ { 4, 14, -2}, { 4, 9, 3}, { 4, 8, -3}, { 4, 6, 4},
+ { 4, 1, -4}, { 5, 26, 5}, { 5, 25, -5}, { 5, 15, 6},
+ { 5, 14, -6}, { 6, 55, 7}, { 6, 54, -7}, { 6, 49, 8},
+ { 6, 48, -8}, { 6, 1, 9}, { 6, 0, -9}, { 7, 6, 10},
+ { 7, 5,-10}, { 7, 4, 11}, { 8, 15,-11}, { 9, 29, 12},
+ { 9, 28,-12}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_c_25[] =
+{
+ { 3, 1, 0}, { 4, 15, 1}, { 4, 14, -1}, { 4, 12, 2},
+ { 4, 11, -2}, { 4, 9, 3}, { 4, 8, -3}, { 4, 6, 4},
+ { 4, 5, -4}, { 4, 1, 5}, { 4, 0, -5}, { 5, 26, 6},
+ { 5, 21, -6}, { 5, 15, 7}, { 5, 14, -7}, { 5, 8, 8},
+ { 6, 55, -8}, { 6, 41, 9}, { 6, 40, -9}, { 6, 18, 10},
+ { 7, 109,-10}, { 7, 108, 11}, { 7, 39,-11}, { 8, 77, 12},
+ { 8, 76,-12}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_d_25[] =
+{
+ { 2, 2, 0}, { 3, 7, 1}, { 3, 6, -1}, { 3, 1, 2},
+ { 3, 0, -2}, { 4, 5, 3}, { 4, 4, -3}, { 5, 13, 4},
+ { 5, 12, -4}, { 6, 29, 5}, { 6, 28, -5}, { 7, 62, 6},
+ { 7, 61, -6}, { 8, 126, 7}, { 8, 121, -7}, { 9, 255, 8},
+ { 9, 254, -8}, {10, 483, 9}, {10, 482, -9}, {11, 963, 10},
+ {11, 962,-10}, {12, 1923, 11}, {12, 1922,-11}, {12, 1921, 12},
+ {12, 1920,-12}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_e_25[] =
+{
+ { 2, 3, 0}, { 3, 3, 1}, { 3, 2, -1}, { 4, 11, 2},
+ { 4, 10, -2}, { 4, 1, 3}, { 4, 0, -3}, { 5, 17, 4},
+ { 5, 16, -4}, { 5, 5, 5}, { 5, 4, -5}, { 6, 38, 6},
+ { 6, 37, -6}, { 6, 14, 7}, { 6, 13, -7}, { 7, 79, 8},
+ { 7, 78, -8}, { 7, 72, 9}, { 7, 31, -9}, { 7, 25, 10},
+ { 7, 24,-10}, { 8, 147, 11}, { 8, 146,-11}, { 8, 61, 12},
+ { 8, 60,-12}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_f_25[] =
+{
+ { 3, 1, 0}, { 3, 0, 1}, { 4, 15, -1}, { 4, 14, 2},
+ { 4, 13, -2}, { 4, 11, 3}, { 4, 10, -3}, { 4, 8, 4},
+ { 4, 7, -4}, { 4, 5, 5}, { 4, 4, -5}, { 5, 24, 6},
+ { 5, 19, -6}, { 5, 13, 7}, { 5, 12, -7}, { 6, 37, 8},
+ { 6, 36, -8}, { 7, 102, 9}, { 7, 101, -9}, { 8, 207, 10},
+ { 8, 206,-10}, { 8, 200, 11}, { 9, 403,-11}, {10, 805, 12},
+ {10, 804,-12}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_g_25[] =
+{
+ { 2, 1, 0}, { 3, 6, 1}, { 3, 5, -1}, { 3, 0, 2},
+ { 4, 15, -2}, { 4, 8, 3}, { 4, 3, -3}, { 5, 28, 4},
+ { 5, 19, -4}, { 5, 4, 5}, { 6, 59, -5}, { 6, 36, 6},
+ { 6, 11, -6}, { 7, 116, 7}, { 7, 75, -7}, { 7, 21, 8},
+ { 7, 20, -8}, { 8, 149, 9}, { 8, 148, -9}, { 9, 470, 10},
+ { 9, 469,-10}, {10, 943, 11}, {10, 942,-11}, {10, 937, 12},
+ {10, 936,-12}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_a_33[] =
+{
+ { 3, 2, 0}, { 3, 1, 1}, { 3, 0, -1}, { 4, 14, 2},
+ { 4, 13, -2}, { 4, 12, 3}, { 4, 11, -3}, { 4, 9, 4},
+ { 4, 8, -4}, { 4, 6, 5}, { 5, 31, -5}, { 5, 20, 6},
+ { 5, 15, -6}, { 6, 61, 7}, { 6, 60, -7}, { 6, 29, 8},
+ { 6, 28, -8}, { 7, 85, 9}, { 7, 84, -9}, { 8, 174, 10},
+ { 8, 173,-10}, { 9, 351, 11}, { 9, 350,-11}, {10, 691, 12},
+ {10, 690,-12}, {11, 1379, 13}, {11, 1378,-13}, {12, 2755, 14},
+ {12, 2754,-14}, {13, 5507, 15}, {13, 5506,-15}, {13, 5505, 16},
+ {13, 5504,-16}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_b_33[] =
+{
+ { 3, 1, 0}, { 4, 15, 1}, { 4, 14, -1}, { 4, 11, 2},
+ { 4, 10, -2}, { 4, 8, 3}, { 4, 7, -3}, { 4, 4, 4},
+ { 4, 1, -4}, { 5, 27, 5}, { 5, 26, -5}, { 5, 19, 6},
+ { 5, 18, -6}, { 5, 12, 7}, { 5, 11, -7}, { 5, 1, 8},
+ { 5, 0, -8}, { 6, 50, 9}, { 6, 49, -9}, { 6, 26, 10},
+ { 6, 21,-10}, { 7, 103, 11}, { 7, 102,-11}, { 7, 96, 12},
+ { 7, 55,-12}, { 7, 41, 13}, { 7, 40,-13}, { 8, 194, 14},
+ { 8, 109,-14}, { 8, 108, 15}, { 9, 391,-15}, {10, 781, 16},
+ {10, 780,-16}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_c_33[] =
+{
+ { 4, 13, 0}, { 4, 11, 1}, { 4, 10, -1}, { 4, 8, 2},
+ { 4, 7, -2}, { 4, 4, 3}, { 4, 3, -3}, { 4, 2, 4},
+ { 4, 1, -4}, { 5, 30, 5}, { 5, 29, -5}, { 5, 25, 6},
+ { 5, 24, -6}, { 5, 19, 7}, { 5, 18, -7}, { 5, 11, 8},
+ { 5, 10, -8}, { 5, 0, 9}, { 6, 63, -9}, { 6, 62, 10},
+ { 6, 57,-10}, { 6, 27, 11}, { 6, 26,-11}, { 6, 24, 12},
+ { 6, 3,-12}, { 7, 113, 13}, { 7, 112,-13}, { 7, 50, 14},
+ { 7, 5,-14}, { 7, 4, 15}, { 8, 103,-15}, { 9, 205, 16},
+ { 9, 204,-16}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_d_33[] =
+{
+ { 2, 1, 0}, { 3, 6, 1}, { 3, 5, -1}, { 3, 0, 2},
+ { 4, 15, -2}, { 4, 8, 3}, { 4, 3, -3}, { 5, 28, 4},
+ { 5, 19, -4}, { 5, 4, 5}, { 6, 59, -5}, { 6, 36, 6},
+ { 6, 11, -6}, { 7, 116, 7}, { 7, 75, -7}, { 7, 21, 8},
+ { 7, 20, -8}, { 8, 149, 9}, { 8, 148, -9}, { 9, 469, 10},
+ { 9, 468,-10}, {10, 941, 11}, {10, 940,-11}, {11, 1885, 12},
+ {11, 1884,-12}, {12, 3773, 13}, {12, 3772,-13}, {13, 7551, 14},
+ {13, 7550,-14}, {14, 15099, 15}, {14, 15098,-15}, {14, 15097, 16},
+ {14, 15096,-16}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_e_33[] =
+{
+ { 2, 2, 0}, { 3, 2, 1}, { 3, 1, -1}, { 4, 12, 2},
+ { 4, 7, -2}, { 4, 0, 3}, { 5, 31, -3}, { 5, 27, 4},
+ { 5, 26, -4}, { 5, 3, 5}, { 5, 2, -5}, { 6, 59, 6},
+ { 6, 58, -6}, { 6, 27, 7}, { 6, 26, -7}, { 7, 123, 8},
+ { 7, 122, -8}, { 7, 120, 9}, { 7, 115, -9}, { 7, 112, 10},
+ { 7, 51,-10}, { 7, 49, 11}, { 7, 48,-11}, { 8, 242, 12},
+ { 8, 229,-12}, { 8, 227, 13}, { 8, 226,-13}, { 8, 101, 14},
+ { 8, 100,-14}, { 9, 487, 15}, { 9, 486,-15}, { 9, 457, 16},
+ { 9, 456,-16}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_f_33[] =
+{
+ { 4, 13, 0}, { 4, 12, 1}, { 4, 11, -1}, { 4, 9, 2},
+ { 4, 8, -2}, { 4, 7, 3}, { 4, 6, -3}, { 4, 4, 4},
+ { 4, 3, -4}, { 4, 1, 5}, { 4, 0, -5}, { 5, 30, 6},
+ { 5, 29, -6}, { 5, 21, 7}, { 5, 20, -7}, { 5, 10, 8},
+ { 5, 5, -8}, { 6, 63, 9}, { 6, 62, -9}, { 6, 56, 10},
+ { 6, 23,-10}, { 6, 9, 11}, { 6, 8,-11}, { 7, 45, 12},
+ { 7, 44,-12}, { 8, 230, 13}, { 8, 229,-13}, { 9, 463, 14},
+ { 9, 462,-14}, { 9, 456, 15}, {10, 915,-15}, {11, 1829, 16},
+ {11, 1828,-16}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_g_33[] =
+{
+ { 3, 6, 0}, { 3, 3, 1}, { 3, 2, -1}, { 4, 15, 2},
+ { 4, 14, -2}, { 4, 9, 3}, { 4, 8, -3}, { 4, 1, 4},
+ { 4, 0, -4}, { 5, 22, 5}, { 5, 21, -5}, { 5, 6, 6},
+ { 5, 5, -6}, { 6, 46, 7}, { 6, 41, -7}, { 6, 14, 8},
+ { 6, 9, -8}, { 7, 94, 9}, { 7, 81, -9}, { 7, 30, 10},
+ { 7, 17,-10}, { 8, 191, 11}, { 8, 190,-11}, { 8, 63, 12},
+ { 8, 62,-12}, { 8, 32, 13}, { 9, 323,-13}, { 9, 321, 14},
+ { 9, 320,-14}, { 9, 67, 15}, { 9, 66,-15}, {10, 645, 16},
+ {10, 644,-16}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_a_65[] =
+{
+ { 4, 6, 0}, { 4, 5, 1}, { 4, 4, -1}, { 4, 2, 2},
+ { 4, 1, -2}, { 4, 0, 3}, { 5, 31, -3}, { 5, 29, 4},
+ { 5, 28, -4}, { 5, 27, 5}, { 5, 26, -5}, { 5, 24, 6},
+ { 5, 23, -6}, { 5, 21, 7}, { 5, 20, -7}, { 5, 18, 8},
+ { 5, 17, -8}, { 5, 14, 9}, { 5, 7, -9}, { 5, 6, 10},
+ { 6, 61,-10}, { 6, 50, 11}, { 6, 45,-11}, { 6, 38, 12},
+ { 6, 33,-12}, { 6, 31, 13}, { 6, 30,-13}, { 7, 120, 14},
+ { 7, 103,-14}, { 7, 89, 15}, { 7, 88,-15}, { 7, 65, 16},
+ { 7, 64,-16}, { 8, 205, 17}, { 8, 204,-17}, { 8, 157, 18},
+ { 8, 156,-18}, { 9, 486, 19}, { 9, 485,-19}, { 9, 318, 20},
+ { 9, 317,-20}, {10, 975, 21}, {10, 974,-21}, {10, 639, 22},
+ {10, 638,-22}, {11, 1939, 23}, {11, 1938,-23}, {11, 1936, 24},
+ {11, 1267,-24}, {11, 1264, 25}, {12, 3875,-25}, {12, 2532, 26},
+ {12, 2531,-26}, {13, 7749, 27}, {13, 7748,-27}, {13, 5061, 28},
+ {13, 5060,-28}, {14, 10133, 29}, {14, 10132,-29}, {15, 20269, 30},
+ {15, 20268,-30}, {16, 40543, 31}, {16, 40542,-31}, {16, 40541, 32},
+ {16, 40540,-32}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_b_65[] =
+{
+ { 4, 4, 0}, { 4, 2, 1}, { 4, 1, -1}, { 5, 30, 2},
+ { 5, 29, -2}, { 5, 26, 3}, { 5, 25, -3}, { 5, 23, 4},
+ { 5, 22, -4}, { 5, 19, 5}, { 5, 18, -5}, { 5, 16, 6},
+ { 5, 15, -6}, { 5, 12, 7}, { 5, 11, -7}, { 5, 7, 8},
+ { 5, 6, -8}, { 6, 63, 9}, { 6, 62, -9}, { 6, 56, 10},
+ { 6, 55,-10}, { 6, 49, 11}, { 6, 48,-11}, { 6, 41, 12},
+ { 6, 40,-12}, { 6, 34, 13}, { 6, 29,-13}, { 6, 26, 14},
+ { 6, 21,-14}, { 6, 20, 15}, { 6, 3,-15}, { 6, 0, 16},
+ { 7, 115,-16}, { 7, 109, 17}, { 7, 108,-17}, { 7, 86, 18},
+ { 7, 85,-18}, { 7, 70, 19}, { 7, 57,-19}, { 7, 56, 20},
+ { 7, 55,-20}, { 7, 4, 21}, { 7, 3,-21}, { 8, 229, 22},
+ { 8, 228,-22}, { 8, 175, 23}, { 8, 174,-23}, { 8, 143, 24},
+ { 8, 142,-24}, { 8, 108, 25}, { 8, 11,-25}, { 8, 10, 26},
+ { 8, 5,-26}, { 9, 339, 27}, { 9, 338,-27}, { 9, 336, 28},
+ { 9, 219,-28}, { 9, 9, 29}, { 9, 8,-29}, {10, 674, 30},
+ {10, 437,-30}, {10, 436, 31}, {11, 1351,-31}, {12, 2701, 32},
+ {12, 2700,-32}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_c_65[] =
+{
+ { 5, 28, 0}, { 5, 25, 1}, { 5, 24, -1}, { 5, 23, 2},
+ { 5, 22, -2}, { 5, 19, 3}, { 5, 18, -3}, { 5, 16, 4},
+ { 5, 15, -4}, { 5, 13, 5}, { 5, 12, -5}, { 5, 10, 6},
+ { 5, 9, -6}, { 5, 7, 7}, { 5, 6, -7}, { 5, 4, 8},
+ { 5, 3, -8}, { 5, 1, 9}, { 5, 0, -9}, { 6, 62, 10},
+ { 6, 61,-10}, { 6, 59, 11}, { 6, 58,-11}, { 6, 54, 12},
+ { 6, 53,-12}, { 6, 43, 13}, { 6, 42,-13}, { 6, 40, 14},
+ { 6, 35,-14}, { 6, 29, 15}, { 6, 28,-15}, { 6, 17, 16},
+ { 6, 16,-16}, { 6, 11, 17}, { 6, 10,-17}, { 6, 4, 18},
+ { 7, 127,-18}, { 7, 121, 19}, { 7, 120,-19}, { 7, 110, 20},
+ { 7, 105,-20}, { 7, 83, 21}, { 7, 82,-21}, { 7, 68, 22},
+ { 7, 47,-22}, { 7, 46, 23}, { 7, 45,-23}, { 7, 11, 24},
+ { 7, 10,-24}, { 8, 252, 25}, { 8, 223,-25}, { 8, 209, 26},
+ { 8, 208,-26}, { 8, 138, 27}, { 8, 89,-27}, { 8, 88, 28},
+ { 9, 507,-28}, { 9, 445, 29}, { 9, 444,-29}, { 9, 278, 30},
+ {10, 1013,-30}, {10, 1012, 31}, {10, 559,-31}, {11, 1117, 32},
+ {11, 1116,-32}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_d_65[] =
+{
+ { 3, 4, 0}, { 3, 1, 1}, { 3, 0, -1}, { 4, 13, 2},
+ { 4, 12, -2}, { 4, 7, 3}, { 4, 6, -3}, { 5, 31, 4},
+ { 5, 30, -4}, { 5, 23, 5}, { 5, 22, -5}, { 5, 11, 6},
+ { 5, 10, -6}, { 6, 59, 7}, { 6, 58, -7}, { 6, 43, 8},
+ { 6, 42, -8}, { 6, 19, 9}, { 6, 18, -9}, { 7, 115, 10},
+ { 7, 114,-10}, { 7, 83, 11}, { 7, 82,-11}, { 7, 35, 12},
+ { 7, 34,-12}, { 8, 227, 13}, { 8, 226,-13}, { 8, 163, 14},
+ { 8, 162,-14}, { 8, 160, 15}, { 8, 67,-15}, { 8, 64, 16},
+ { 9, 451,-16}, { 9, 448, 17}, { 9, 323,-17}, { 9, 132, 18},
+ { 9, 131,-18}, {10, 900, 19}, {10, 899,-19}, {10, 644, 20},
+ {10, 267,-20}, {10, 261, 21}, {10, 260,-21}, {11, 1797, 22},
+ {11, 1796,-22}, {11, 533, 23}, {11, 532,-23}, {12, 3605, 24},
+ {12, 3604,-24}, {12, 2582, 25}, {12, 2581,-25}, {13, 7215, 26},
+ {13, 7214,-26}, {13, 5167, 27}, {13, 5166,-27}, {13, 5160, 28},
+ {14, 14427,-28}, {14, 10323, 29}, {14, 10322,-29}, {15, 28853, 30},
+ {15, 28852,-30}, {15, 28851, 31}, {15, 28850,-31}, {15, 28849, 32},
+ {15, 28848,-32}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_e_65[] =
+{
+ { 3, 4, 0}, { 3, 0, 1}, { 4, 15, -1}, { 4, 7, 2},
+ { 4, 6, -2}, { 5, 29, 3}, { 5, 28, -3}, { 5, 23, 4},
+ { 5, 22, -4}, { 5, 10, 5}, { 5, 9, -5}, { 5, 6, 6},
+ { 5, 5, -6}, { 6, 54, 7}, { 6, 53, -7}, { 6, 48, 8},
+ { 6, 43, -8}, { 6, 40, 9}, { 6, 23, -9}, { 6, 16, 10},
+ { 6, 15,-10}, { 6, 9, 11}, { 6, 8,-11}, { 7, 105, 12},
+ { 7, 104,-12}, { 7, 100, 13}, { 7, 99,-13}, { 7, 84, 14},
+ { 7, 83,-14}, { 7, 45, 15}, { 7, 44,-15}, { 7, 29, 16},
+ { 7, 28,-16}, { 8, 221, 17}, { 8, 220,-17}, { 8, 206, 18},
+ { 8, 205,-18}, { 8, 202, 19}, { 8, 197,-19}, { 8, 171, 20},
+ { 8, 170,-20}, { 8, 164, 21}, { 8, 71,-21}, { 8, 69, 22},
+ { 8, 68,-22}, { 9, 446, 23}, { 9, 445,-23}, { 9, 415, 24},
+ { 9, 414,-24}, { 9, 408, 25}, { 9, 407,-25}, { 9, 393, 26},
+ { 9, 392,-26}, { 9, 331, 27}, { 9, 330,-27}, { 9, 141, 28},
+ { 9, 140,-28}, {10, 895, 29}, {10, 894,-29}, {10, 889, 30},
+ {10, 888,-30}, {10, 819, 31}, {10, 818,-31}, {10, 813, 32},
+ {10, 812,-32}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_f_65[] =
+{
+ { 3, 6, 0}, { 3, 3, 1}, { 3, 2, -1}, { 4, 15, 2},
+ { 4, 14, -2}, { 4, 9, 3}, { 4, 8, -3}, { 4, 1, 4},
+ { 4, 0, -4}, { 5, 21, 5}, { 5, 20, -5}, { 5, 5, 6},
+ { 5, 4, -6}, { 6, 45, 7}, { 6, 44, -7}, { 6, 13, 8},
+ { 6, 12, -8}, { 7, 93, 9}, { 7, 92, -9}, { 7, 29, 10},
+ { 7, 28,-10}, { 8, 189, 11}, { 8, 188,-11}, { 8, 61, 12},
+ { 8, 60,-12}, { 9, 381, 13}, { 9, 380,-13}, { 9, 125, 14},
+ { 9, 124,-14}, {10, 765, 15}, {10, 764,-15}, {10, 252, 16},
+ {11, 1535,-16}, {11, 1532, 17}, {11, 511,-17}, {11, 506, 18},
+ {12, 3069,-18}, {12, 3067, 19}, {12, 3066,-19}, {12, 1015, 20},
+ {12, 1014,-20}, {13, 6136, 21}, {13, 2043,-21}, {13, 2035, 22},
+ {13, 2034,-22}, {14, 12275, 23}, {14, 12274,-23}, {14, 4085, 24},
+ {14, 4084,-24}, {14, 4083, 25}, {14, 4082,-25}, {14, 4081, 26},
+ {14, 4080,-26}, {14, 4079, 27}, {14, 4078,-27}, {14, 4077, 28},
+ {14, 4076,-28}, {14, 4075, 29}, {14, 4074,-29}, {14, 4073, 30},
+ {14, 4072,-30}, {14, 4067, 31}, {14, 4066,-31}, {14, 4065, 32},
+ {14, 4064,-32}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_g_65[] =
+{
+ { 4, 14, 0}, { 4, 11, 1}, { 4, 10, -1}, { 4, 8, 2},
+ { 4, 6, -2}, { 4, 4, 3}, { 4, 3, -3}, { 4, 0, 4},
+ { 5, 31, -4}, { 5, 26, 5}, { 5, 25, -5}, { 5, 18, 6},
+ { 5, 15, -6}, { 5, 10, 7}, { 5, 5, -7}, { 5, 2, 8},
+ { 6, 61, -8}, { 6, 54, 9}, { 6, 49, -9}, { 6, 38, 10},
+ { 6, 29,-10}, { 6, 22, 11}, { 6, 9,-11}, { 6, 6, 12},
+ { 7, 121,-12}, { 7, 110, 13}, { 7, 97,-13}, { 7, 78, 14},
+ { 7, 57,-14}, { 7, 46, 15}, { 7, 17,-15}, { 7, 14, 16},
+ { 8, 241,-16}, { 8, 223, 17}, { 8, 222,-17}, { 8, 159, 18},
+ { 8, 158,-18}, { 8, 95, 19}, { 8, 94,-19}, { 8, 31, 20},
+ { 8, 30,-20}, { 9, 480, 21}, { 9, 387,-21}, { 9, 384, 22},
+ { 9, 227,-22}, { 9, 225, 23}, { 9, 224,-23}, { 9, 65, 24},
+ { 9, 64,-24}, {10, 962, 25}, {10, 773,-25}, {10, 771, 26},
+ {10, 770,-26}, {10, 452, 27}, {10, 135,-27}, {10, 133, 28},
+ {10, 132,-28}, {11, 1927, 29}, {11, 1926,-29}, {11, 1545, 30},
+ {11, 1544,-30}, {11, 907, 31}, {11, 906,-31}, {11, 269, 32},
+ {11, 268,-32}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_a_129[] =
+{
+ { 4, 8, 0}, { 4, 10, 1}, { 4, 9, -1}, { 4, 0, 2},
+ { 5, 31, -2}, { 5, 24, 3}, { 5, 23, -3}, { 5, 12, 4},
+ { 5, 11, -4}, { 5, 5, 5}, { 5, 4, -5}, { 6, 60, 6},
+ { 6, 58, -6}, { 6, 54, 7}, { 6, 53, -7}, { 6, 45, 8},
+ { 6, 44, -8}, { 6, 28, 9}, { 6, 27, -9}, { 6, 19, 10},
+ { 6, 18,-10}, { 6, 14, 11}, { 6, 13,-11}, { 6, 6, 12},
+ { 6, 5,-12}, { 7, 122, 13}, { 7, 119,-13}, { 7, 113, 14},
+ { 7, 112,-14}, { 7, 104, 15}, { 7, 103,-15}, { 7, 100, 16},
+ { 7, 63,-16}, { 7, 60, 17}, { 7, 59,-17}, { 7, 52, 18},
+ { 7, 43,-18}, { 7, 40, 19}, { 7, 35,-19}, { 7, 32, 20},
+ { 7, 31,-20}, { 7, 15, 21}, { 7, 14,-21}, { 8, 247, 22},
+ { 8, 246,-22}, { 8, 231, 23}, { 8, 230,-23}, { 8, 223, 24},
+ { 8, 222,-24}, { 8, 211, 25}, { 8, 210,-25}, { 8, 203, 26},
+ { 8, 202,-26}, { 8, 123, 27}, { 8, 122,-27}, { 8, 116, 28},
+ { 8, 107,-28}, { 8, 84, 29}, { 8, 83,-29}, { 8, 68, 30},
+ { 8, 67,-30}, { 8, 60, 31}, { 8, 51,-31}, { 8, 49, 32},
+ { 8, 48,-32}, { 8, 17, 33}, { 8, 16,-33}, { 9, 474, 34},
+ { 9, 473,-34}, { 9, 458, 35}, { 9, 457,-35}, { 9, 442, 36},
+ { 9, 441,-36}, { 9, 411, 37}, { 9, 410,-37}, { 9, 251, 38},
+ { 9, 250,-38}, { 9, 248, 39}, { 9, 235,-39}, { 9, 213, 40},
+ { 9, 212,-40}, { 9, 170, 41}, { 9, 165,-41}, { 9, 139, 42},
+ { 9, 138,-42}, { 9, 132, 43}, { 9, 123,-43}, { 9, 101, 44},
+ { 9, 100,-44}, { 9, 37, 45}, { 9, 36,-45}, {10, 950, 46},
+ {10, 945,-46}, {10, 919, 47}, {10, 918,-47}, {10, 912, 48},
+ {10, 887,-48}, {10, 881, 49}, {10, 880,-49}, {10, 818, 50},
+ {10, 817,-50}, {10, 499, 51}, {10, 498,-51}, {10, 469, 52},
+ {10, 468,-52}, {10, 343, 53}, {10, 342,-53}, {10, 329, 54},
+ {10, 328,-54}, {10, 267, 55}, {10, 266,-55}, {10, 245, 56},
+ {10, 244,-56}, {10, 79, 57}, {10, 78,-57}, {10, 77, 58},
+ {10, 76,-58}, {11, 1903, 59}, {11, 1902,-59}, {11, 1889, 60},
+ {11, 1888,-60}, {11, 1827, 61}, {11, 1826,-61}, {11, 1773, 62},
+ {11, 1772,-62}, {11, 1639, 63}, {11, 1638,-63}, {11, 1633, 64},
+ {11, 1632,-64}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_b_129[] =
+{
+ { 5, 10, 0}, { 5, 7, 1}, { 5, 6, -1}, { 5, 4, 2},
+ { 5, 3, -2}, { 5, 0, 3}, { 6, 63, -3}, { 6, 60, 4},
+ { 6, 59, -4}, { 6, 57, 5}, { 6, 56, -5}, { 6, 53, 6},
+ { 6, 52, -6}, { 6, 50, 7}, { 6, 49, -7}, { 6, 46, 8},
+ { 6, 45, -8}, { 6, 43, 9}, { 6, 42, -9}, { 6, 39, 10},
+ { 6, 38,-10}, { 6, 35, 11}, { 6, 34,-11}, { 6, 32, 12},
+ { 6, 31,-12}, { 6, 28, 13}, { 6, 27,-13}, { 6, 25, 14},
+ { 6, 24,-14}, { 6, 22, 15}, { 6, 19,-15}, { 6, 16, 16},
+ { 6, 11,-16}, { 6, 5, 17}, { 6, 4,-17}, { 7, 125, 18},
+ { 7, 124,-18}, { 7, 122, 19}, { 7, 117,-19}, { 7, 110, 20},
+ { 7, 109,-20}, { 7, 103, 21}, { 7, 102,-21}, { 7, 96, 22},
+ { 7, 95,-22}, { 7, 89, 23}, { 7, 88,-23}, { 7, 81, 24},
+ { 7, 80,-24}, { 7, 74, 25}, { 7, 73,-25}, { 7, 66, 26},
+ { 7, 61,-26}, { 7, 59, 27}, { 7, 58,-27}, { 7, 52, 28},
+ { 7, 47,-28}, { 7, 37, 29}, { 7, 36,-29}, { 7, 21, 30},
+ { 7, 20,-30}, { 7, 6, 31}, { 7, 5,-31}, { 8, 247, 32},
+ { 8, 246,-32}, { 8, 223, 33}, { 8, 222,-33}, { 8, 217, 34},
+ { 8, 216,-34}, { 8, 189, 35}, { 8, 188,-35}, { 8, 166, 36},
+ { 8, 165,-36}, { 8, 151, 37}, { 8, 150,-37}, { 8, 144, 38},
+ { 8, 135,-38}, { 8, 121, 39}, { 8, 120,-39}, { 8, 106, 40},
+ { 8, 93,-40}, { 8, 71, 41}, { 8, 70,-41}, { 8, 68, 42},
+ { 8, 15,-42}, { 8, 9, 43}, { 8, 8,-43}, { 9, 466, 44},
+ { 9, 465,-44}, { 9, 391, 45}, { 9, 390,-45}, { 9, 388, 46},
+ { 9, 335,-46}, { 9, 329, 47}, { 9, 328,-47}, { 9, 269, 48},
+ { 9, 268,-48}, { 9, 215, 49}, { 9, 214,-49}, { 9, 184, 50},
+ { 9, 139,-50}, { 9, 29, 51}, { 9, 28,-51}, {10, 934, 52},
+ {10, 929,-52}, {10, 779, 53}, {10, 778,-53}, {10, 668, 54},
+ {10, 583,-54}, {10, 582, 55}, {10, 581,-55}, {10, 371, 56},
+ {10, 370,-56}, {10, 276, 57}, {11, 1871,-57}, {11, 1857, 58},
+ {11, 1856,-58}, {11, 1338, 59}, {11, 1161,-59}, {11, 1160, 60},
+ {11, 555,-60}, {12, 3741, 61}, {12, 3740,-61}, {12, 2678, 62},
+ {12, 1109,-62}, {12, 1108, 63}, {13, 5359,-63}, {14, 10717, 64},
+ {14, 10716,-64}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_c_129[] =
+{
+ { 6, 58, 0}, { 6, 55, 1}, { 6, 54, -1}, { 6, 52, 2},
+ { 6, 51, -2}, { 6, 49, 3}, { 6, 48, -3}, { 6, 46, 4},
+ { 6, 45, -4}, { 6, 43, 5}, { 6, 42, -5}, { 6, 40, 6},
+ { 6, 39, -6}, { 6, 37, 7}, { 6, 36, -7}, { 6, 34, 8},
+ { 6, 33, -8}, { 6, 30, 9}, { 6, 29, -9}, { 6, 27, 10},
+ { 6, 26,-10}, { 6, 24, 11}, { 6, 23,-11}, { 6, 21, 12},
+ { 6, 20,-12}, { 6, 18, 13}, { 6, 17,-13}, { 6, 14, 14},
+ { 6, 13,-14}, { 6, 12, 15}, { 6, 11,-15}, { 6, 8, 16},
+ { 6, 7,-16}, { 6, 6, 17}, { 6, 5,-17}, { 6, 3, 18},
+ { 6, 2,-18}, { 7, 127, 19}, { 7, 126,-19}, { 7, 124, 20},
+ { 7, 123,-20}, { 7, 121, 21}, { 7, 120,-21}, { 7, 118, 22},
+ { 7, 115,-22}, { 7, 113, 23}, { 7, 112,-23}, { 7, 106, 24},
+ { 7, 101,-24}, { 7, 95, 25}, { 7, 94,-25}, { 7, 88, 26},
+ { 7, 83,-26}, { 7, 77, 27}, { 7, 76,-27}, { 7, 70, 28},
+ { 7, 65,-28}, { 7, 64, 29}, { 7, 63,-29}, { 7, 56, 30},
+ { 7, 51,-30}, { 7, 45, 31}, { 7, 44,-31}, { 7, 39, 32},
+ { 7, 38,-32}, { 7, 31, 33}, { 7, 30,-33}, { 7, 20, 34},
+ { 7, 19,-34}, { 7, 18, 35}, { 7, 9,-35}, { 7, 3, 36},
+ { 7, 2,-36}, { 7, 0, 37}, { 8, 251,-37}, { 8, 245, 38},
+ { 8, 244,-38}, { 8, 238, 39}, { 8, 229,-39}, { 8, 215, 40},
+ { 8, 214,-40}, { 8, 200, 41}, { 8, 179,-41}, { 8, 165, 42},
+ { 8, 164,-42}, { 8, 143, 43}, { 8, 142,-43}, { 8, 124, 44},
+ { 8, 115,-44}, { 8, 101, 45}, { 8, 100,-45}, { 8, 66, 46},
+ { 8, 65,-46}, { 8, 43, 47}, { 8, 42,-47}, { 8, 17, 48},
+ { 8, 16,-48}, { 8, 2, 49}, { 9, 501,-49}, { 9, 479, 50},
+ { 9, 478,-50}, { 9, 456, 51}, { 9, 403,-51}, { 9, 357, 52},
+ { 9, 356,-52}, { 9, 251, 53}, { 9, 250,-53}, { 9, 228, 54},
+ { 9, 135,-54}, { 9, 129, 55}, { 9, 128,-55}, { 9, 6, 56},
+ {10, 1001,-56}, {10, 1000, 57}, {10, 915,-57}, {10, 805, 58},
+ {10, 804,-58}, {10, 458, 59}, {10, 269,-59}, {10, 268, 60},
+ {10, 15,-60}, {11, 1829, 61}, {11, 1828,-61}, {11, 918, 62},
+ {11, 29,-62}, {11, 28, 63}, {12, 1839,-63}, {13, 3677, 64},
+ {13, 3676,-64}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_d_129[] =
+{
+ { 4, 9, 0}, { 4, 6, 1}, { 4, 5, -1}, { 4, 2, 2},
+ { 4, 1, -2}, { 5, 30, 3}, { 5, 29, -3}, { 5, 26, 4},
+ { 5, 25, -4}, { 5, 22, 5}, { 5, 21, -5}, { 5, 16, 6},
+ { 5, 15, -6}, { 5, 8, 7}, { 5, 7, -7}, { 5, 0, 8},
+ { 6, 63, -8}, { 6, 56, 9}, { 6, 55, -9}, { 6, 48, 10},
+ { 6, 47,-10}, { 6, 40, 11}, { 6, 35,-11}, { 6, 28, 12},
+ { 6, 19,-12}, { 6, 12, 13}, { 6, 3,-13}, { 7, 124, 14},
+ { 7, 115,-14}, { 7, 108, 15}, { 7, 99,-15}, { 7, 92, 16},
+ { 7, 83,-16}, { 7, 68, 17}, { 7, 59,-17}, { 7, 36, 18},
+ { 7, 27,-18}, { 7, 4, 19}, { 8, 251,-19}, { 8, 228, 20},
+ { 8, 219,-20}, { 8, 196, 21}, { 8, 187,-21}, { 8, 164, 22},
+ { 8, 139,-22}, { 8, 116, 23}, { 8, 75,-23}, { 8, 52, 24},
+ { 8, 11,-24}, { 9, 501, 25}, { 9, 500,-25}, { 9, 437, 26},
+ { 9, 436,-26}, { 9, 373, 27}, { 9, 372,-27}, { 9, 277, 28},
+ { 9, 276,-28}, { 9, 149, 29}, { 9, 148,-29}, { 9, 21, 30},
+ { 9, 20,-30}, {10, 917, 31}, {10, 916,-31}, {10, 789, 32},
+ {10, 788,-32}, {10, 661, 33}, {10, 660,-33}, {10, 469, 34},
+ {10, 468,-34}, {10, 214, 35}, {10, 213,-35}, {11, 1838, 36},
+ {11, 1837,-36}, {11, 1582, 37}, {11, 1581,-37}, {11, 1326, 38},
+ {11, 1325,-38}, {11, 942, 39}, {11, 941,-39}, {11, 431, 40},
+ {11, 430,-40}, {12, 3679, 41}, {12, 3678,-41}, {12, 3167, 42},
+ {12, 3166,-42}, {12, 3160, 43}, {12, 2655,-43}, {12, 2648, 44},
+ {12, 1887,-44}, {12, 1880, 45}, {12, 851,-45}, {12, 849, 46},
+ {12, 848,-46}, {13, 7346, 47}, {13, 7345,-47}, {13, 6322, 48},
+ {13, 5309,-48}, {13, 3773, 49}, {13, 3772,-49}, {13, 3762, 50},
+ {13, 1701,-50}, {14, 14695, 51}, {14, 14694,-51}, {14, 14688, 52},
+ {14, 12647,-52}, {14, 10617, 53}, {14, 10616,-53}, {14, 10596, 54},
+ {14, 7527,-54}, {14, 3401, 55}, {14, 3400,-55}, {15, 29378, 56},
+ {15, 25293,-56}, {15, 21195, 57}, {15, 21194,-57}, {15, 15053, 58},
+ {15, 15052,-58}, {16, 58759, 59}, {16, 58758,-59}, {16, 50585, 60},
+ {16, 50584,-60}, {16, 42399, 61}, {16, 42398,-61}, {16, 42397, 62},
+ {16, 42396,-62}, {16, 42395, 63}, {16, 42394,-63}, {16, 42393, 64},
+ {16, 42392,-64}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_e_129[] =
+{
+ { 5, 12, 0}, { 5, 11, 1}, { 5, 10, -1}, { 5, 9, 2},
+ { 5, 8, -2}, { 5, 7, 3}, { 5, 6, -3}, { 5, 4, 4},
+ { 5, 3, -4}, { 5, 2, 5}, { 5, 1, -5}, { 5, 0, 6},
+ { 6, 63, -6}, { 6, 61, 7}, { 6, 60, -7}, { 6, 59, 8},
+ { 6, 58, -8}, { 6, 56, 9}, { 6, 55, -9}, { 6, 53, 10},
+ { 6, 52,-10}, { 6, 51, 11}, { 6, 50,-11}, { 6, 47, 12},
+ { 6, 46,-12}, { 6, 45, 13}, { 6, 44,-13}, { 6, 42, 14},
+ { 6, 41,-14}, { 6, 38, 15}, { 6, 37,-15}, { 6, 36, 16},
+ { 6, 35,-16}, { 6, 32, 17}, { 6, 31,-17}, { 6, 29, 18},
+ { 6, 28,-18}, { 6, 26, 19}, { 6, 11,-19}, { 7, 125, 20},
+ { 7, 124,-20}, { 7, 109, 21}, { 7, 108,-21}, { 7, 98, 22},
+ { 7, 97,-22}, { 7, 87, 23}, { 7, 86,-23}, { 7, 79, 24},
+ { 7, 78,-24}, { 7, 68, 25}, { 7, 67,-25}, { 7, 60, 26},
+ { 7, 55,-26}, { 7, 21, 27}, { 7, 20,-27}, { 8, 230, 28},
+ { 8, 229,-28}, { 8, 198, 29}, { 8, 193,-29}, { 8, 163, 30},
+ { 8, 162,-30}, { 8, 139, 31}, { 8, 138,-31}, { 8, 123, 32},
+ { 8, 122,-32}, { 8, 108, 33}, { 9, 463,-33}, { 9, 457, 34},
+ { 9, 456,-34}, { 9, 385, 35}, { 9, 384,-35}, { 9, 321, 36},
+ { 9, 320,-36}, { 9, 266, 37}, { 9, 265,-37}, { 9, 218, 38},
+ {10, 925,-38}, {10, 798, 39}, {10, 797,-39}, {10, 646, 40},
+ {10, 645,-40}, {10, 535, 41}, {10, 534,-41}, {10, 528, 42},
+ {10, 439,-42}, {11, 1848, 43}, {11, 1599,-43}, {11, 1592, 44},
+ {11, 1295,-44}, {11, 1288, 45}, {11, 1059,-45}, {11, 877, 46},
+ {11, 876,-46}, {12, 3197, 47}, {12, 3196,-47}, {12, 2589, 48},
+ {12, 2588,-48}, {12, 2117, 49}, {12, 2116,-49}, {13, 7398, 50},
+ {13, 7397,-50}, {13, 6374, 51}, {13, 6373,-51}, {13, 5158, 52},
+ {13, 5157,-52}, {14, 14799, 53}, {14, 14798,-53}, {14, 12751, 54},
+ {14, 12750,-54}, {14, 10318, 55}, {14, 10313,-55}, {15, 29587, 56},
+ {15, 29586,-56}, {15, 29584, 57}, {15, 25491,-57}, {15, 20625, 58},
+ {15, 20624,-58}, {16, 59171, 59}, {16, 59170,-59}, {16, 50980, 60},
+ {16, 41277,-60}, {16, 50981, 61}, {16, 41278,-61}, {16, 50978, 62},
+ {16, 41279,-62}, {16, 50979, 63}, {16, 50976,-63}, {16, 50977, 64},
+ {16, 41276,-64}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_f_129[] =
+{
+ { 6, 56, 0}, { 6, 55, 1}, { 6, 54, -1}, { 6, 52, 2},
+ { 6, 51, -2}, { 6, 50, 3}, { 6, 49, -3}, { 6, 48, 4},
+ { 6, 47, -4}, { 6, 46, 5}, { 6, 45, -5}, { 6, 44, 6},
+ { 6, 43, -6}, { 6, 41, 7}, { 6, 40, -7}, { 6, 39, 8},
+ { 6, 38, -8}, { 6, 36, 9}, { 6, 35, -9}, { 6, 34, 10},
+ { 6, 33,-10}, { 6, 31, 11}, { 6, 30,-11}, { 6, 29, 12},
+ { 6, 28,-12}, { 6, 26, 13}, { 6, 25,-13}, { 6, 23, 14},
+ { 6, 22,-14}, { 6, 21, 15}, { 6, 20,-15}, { 6, 18, 16},
+ { 6, 17,-16}, { 6, 15, 17}, { 6, 14,-17}, { 6, 12, 18},
+ { 6, 11,-18}, { 6, 9, 19}, { 6, 8,-19}, { 6, 7, 20},
+ { 6, 6,-20}, { 6, 3, 21}, { 6, 2,-21}, { 6, 1, 22},
+ { 6, 0,-22}, { 7, 125, 23}, { 7, 124,-23}, { 7, 123, 24},
+ { 7, 122,-24}, { 7, 120, 25}, { 7, 119,-25}, { 7, 116, 26},
+ { 7, 115,-26}, { 7, 114, 27}, { 7, 107,-27}, { 7, 84, 28},
+ { 7, 75,-28}, { 7, 65, 29}, { 7, 64,-29}, { 7, 54, 30},
+ { 7, 49,-30}, { 7, 39, 31}, { 7, 38,-31}, { 7, 27, 32},
+ { 7, 26,-32}, { 7, 20, 33}, { 7, 11,-33}, { 7, 10, 34},
+ { 7, 9,-34}, { 8, 254, 35}, { 8, 253,-35}, { 8, 243, 36},
+ { 8, 242,-36}, { 8, 235, 37}, { 8, 234,-37}, { 8, 213, 38},
+ { 8, 212,-38}, { 8, 149, 39}, { 8, 148,-39}, { 8, 110, 40},
+ { 8, 97,-40}, { 8, 66, 41}, { 8, 65,-41}, { 8, 43, 42},
+ { 8, 42,-42}, { 8, 16, 43}, { 9, 511,-43}, { 9, 505, 44},
+ { 9, 504,-44}, { 9, 474, 45}, { 9, 473,-45}, { 9, 343, 46},
+ { 9, 342,-46}, { 9, 340, 47}, { 9, 223,-47}, { 9, 192, 48},
+ { 9, 135,-48}, { 9, 129, 49}, { 9, 128,-49}, { 9, 34, 50},
+ {10, 1021,-50}, {10, 951, 51}, {10, 950,-51}, {10, 944, 52},
+ {10, 683,-52}, {10, 445, 53}, {10, 444,-53}, {10, 269, 54},
+ {10, 268,-54}, {10, 71, 55}, {10, 70,-55}, {11, 2040, 56},
+ {11, 1891,-56}, {11, 1364, 57}, {11, 775,-57}, {11, 774, 58},
+ {11, 773,-58}, {12, 4083, 59}, {12, 4082,-59}, {12, 3780, 60},
+ {12, 2731,-60}, {12, 1545, 61}, {12, 1544,-61}, {13, 7562, 62},
+ {13, 5461,-62}, {13, 5460, 63}, {14, 15127,-63}, {15, 30253, 64},
+ {15, 30252,-64}, { 0, 0, 0}
+};
+
+huff_entry_t bitalloc_g_129[] =
+{
+ { 4, 0, 0}, { 5, 29, 1}, { 5, 28, -1}, { 5, 25, 2},
+ { 5, 24, -2}, { 5, 21, 3}, { 5, 20, -3}, { 5, 17, 4},
+ { 5, 16, -4}, { 5, 13, 5}, { 5, 12, -5}, { 5, 9, 6},
+ { 5, 8, -6}, { 5, 5, 7}, { 5, 4, -7}, { 6, 63, 8},
+ { 6, 62, -8}, { 6, 55, 9}, { 6, 54, -9}, { 6, 47, 10},
+ { 6, 46,-10}, { 6, 39, 11}, { 6, 38,-11}, { 6, 31, 12},
+ { 6, 30,-12}, { 6, 23, 13}, { 6, 22,-13}, { 6, 15, 14},
+ { 6, 14,-14}, { 6, 7, 15}, { 6, 6,-15}, { 7, 123, 16},
+ { 7, 122,-16}, { 7, 107, 17}, { 7, 106,-17}, { 7, 91, 18},
+ { 7, 90,-18}, { 7, 75, 19}, { 7, 74,-19}, { 7, 59, 20},
+ { 7, 58,-20}, { 7, 43, 21}, { 7, 42,-21}, { 7, 27, 22},
+ { 7, 26,-22}, { 7, 11, 23}, { 7, 10,-23}, { 7, 8, 24},
+ { 8, 243,-24}, { 8, 240, 25}, { 8, 211,-25}, { 8, 208, 26},
+ { 8, 179,-26}, { 8, 176, 27}, { 8, 147,-27}, { 8, 144, 28},
+ { 8, 115,-28}, { 8, 112, 29}, { 8, 83,-29}, { 8, 80, 30},
+ { 8, 51,-30}, { 8, 48, 31}, { 8, 19,-31}, { 9, 484, 32},
+ { 9, 483,-32}, { 9, 421, 33}, { 9, 420,-33}, { 9, 357, 34},
+ { 9, 356,-34}, { 9, 293, 35}, { 9, 292,-35}, { 9, 229, 36},
+ { 9, 228,-36}, { 9, 226, 37}, { 9, 165,-37}, { 9, 162, 38},
+ { 9, 101,-38}, { 9, 98, 39}, { 9, 37,-39}, {10, 970, 40},
+ {10, 965,-40}, {10, 839, 41}, {10, 838,-41}, {10, 711, 42},
+ {10, 710,-42}, {10, 708, 43}, {10, 583,-43}, {10, 580, 44},
+ {10, 455,-44}, {10, 329, 45}, {10, 328,-45}, {10, 201, 46},
+ {10, 200,-46}, {10, 198, 47}, {10, 73,-47}, {11, 1942, 48},
+ {11, 1929,-48}, {11, 1675, 49}, {11, 1674,-49}, {11, 1672, 50},
+ {11, 1419,-50}, {11, 1165, 51}, {11, 1164,-51}, {11, 1162, 52},
+ {11, 909,-52}, {11, 655, 53}, {11, 654,-53}, {11, 652, 54},
+ {11, 399,-54}, {11, 145, 55}, {11, 144,-55}, {12, 3886, 56},
+ {12, 3857,-56}, {12, 3347, 57}, {12, 3346,-57}, {12, 2837, 58},
+ {12, 2836,-58}, {12, 2327, 59}, {12, 2326,-59}, {12, 1817, 60},
+ {12, 1816,-60}, {12, 1307, 61}, {12, 1306,-61}, {12, 797, 62},
+ {12, 796,-62}, {13, 7775, 63}, {13, 7774,-63}, {13, 7713, 64},
+ {13, 7712,-64}, { 0, 0, 0}
+};
+
+huff_entry_t *bitalloc_select[11][8] =
+{
+ { 0 },
+ { bitalloc_a_3, 0 },
+ { bitalloc_a_5, bitalloc_b_5, bitalloc_c_5, 0 },
+ { bitalloc_a_7, bitalloc_b_7, bitalloc_c_7, 0 },
+ { bitalloc_a_9, bitalloc_b_9, bitalloc_c_9, 0 },
+ { bitalloc_a_13, bitalloc_b_13, bitalloc_c_13, 0 },
+ { bitalloc_a_17, bitalloc_b_17, bitalloc_c_17, bitalloc_d_17,
+ bitalloc_e_17, bitalloc_f_17, bitalloc_g_17, 0 },
+ { bitalloc_a_25, bitalloc_b_25, bitalloc_c_25, bitalloc_d_25,
+ bitalloc_e_25, bitalloc_f_25, bitalloc_g_25, 0 },
+ { bitalloc_a_33, bitalloc_b_33, bitalloc_c_33, bitalloc_d_33,
+ bitalloc_e_33, bitalloc_f_33, bitalloc_g_33, 0 },
+ { bitalloc_a_65, bitalloc_b_65, bitalloc_c_65, bitalloc_d_65,
+ bitalloc_e_65, bitalloc_f_65, bitalloc_g_65, 0 },
+ { bitalloc_a_129, bitalloc_b_129, bitalloc_c_129, bitalloc_d_129,
+ bitalloc_e_129, bitalloc_f_129, bitalloc_g_129, 0 },
+};
+
+static int InverseQ( dca_state_t * state, huff_entry_t * huff )
+{
+ int value = 0;
+ int length = 0, j;
+
+ while( 1 )
+ {
+ length++;
+ value <<= 1;
+ value |= bitstream_get (state, 1);
+
+ for( j = 0; huff[j].length != 0 && huff[j].length < length; j++ );
+
+ if( huff[j].length == 0 ) break;
+
+ for( ; huff[j].length == length; j++ )
+ {
+ if( huff[j].code == value ) return huff[j].value;
+ }
+ }
+
+ return 0;
+}
diff --git a/contrib/libdca/tables_quantization.h b/contrib/libdca/tables_quantization.h
new file mode 100644
index 000000000..4dc3cd0fe
--- /dev/null
+++ b/contrib/libdca/tables_quantization.h
@@ -0,0 +1,89 @@
+/*
+ * tables_quantization.h
+ * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
+ *
+ * This file is part of libdca, a free DTS Coherent Acoustics stream decoder.
+ * See http://www.videolan.org/developers/libdca.html for updates.
+ *
+ * libdca 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.
+ *
+ * libdca is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+int scale_factor_quant6[] =
+{
+ 1, 2, 2, 3, 3, 4, 6, 7,
+ 10, 12, 16, 20, 26, 34, 44, 56,
+ 72, 93, 120, 155, 200, 257, 331, 427,
+ 550, 708, 912, 1175, 1514, 1950, 2512, 3236,
+ 4169, 5370, 6918, 8913, 11482, 14791, 19055, 24547,
+ 31623, 40738, 52481, 67608, 87096, 112202, 144544, 186209,
+ 239883, 309030, 398107, 512861, 660693, 851138, 1096478, 1412538,
+ 1819701, 2344229, 3019952, 3890451, 5011872, 6456542, 8317638, 0
+};
+
+int scale_factor_quant7[] =
+{
+ 1, 1, 2, 2, 2, 2, 3, 3,
+ 3, 4, 4, 5, 6, 7, 7, 8,
+ 10, 11, 12, 14, 16, 18, 20, 23,
+ 26, 30, 34, 38, 44, 50, 56, 64,
+ 72, 82, 93, 106, 120, 136, 155, 176,
+ 200, 226, 257, 292, 331, 376, 427, 484,
+ 550, 624, 708, 804, 912, 1035, 1175, 1334,
+ 1514, 1718, 1950, 2213, 2512, 2851, 3236, 3673,
+ 4169, 4732, 5370, 6095, 6918, 7852, 8913, 10116,
+ 11482, 13032, 14791, 16788, 19055, 21627, 24547, 27861,
+ 31623, 35892, 40738, 46238, 52481, 59566, 67608, 76736,
+ 87096, 98855, 112202, 127350, 144544, 164059, 186209, 211349,
+ 239883, 272270, 309030, 350752, 398107, 451856, 512861, 582103,
+ 660693, 749894, 851138, 966051, 1096478, 1244515, 1412538, 1603245,
+ 1819701, 2065380, 2344229, 2660725, 3019952, 3427678, 3890451, 4415704,
+ 5011872, 5688529, 6456542, 7328245, 8317638, 0, 0, 0
+};
+
+/* 20bits unsigned fractional binary codes */
+int lossy_quant[] =
+{
+ 0, 6710886, 4194304, 3355443, 2474639, 2097152, 1761608, 1426063,
+ 796918, 461373, 251658, 146801, 79692, 46137, 27263, 16777,
+ 10486, 5872, 3355, 1887, 1258, 713, 336, 168,
+ 84, 42, 21, 0, 0, 0, 0, 0
+};
+
+double lossy_quant_d[] =
+{
+ 0, 1.6, 1.0, 0.8, 0.59, 0.50, 0.42, 0.34,
+ 0.19, 0.11, 0.06, 0.035, 0.019, 0.011, 0.0065, 0.0040,
+ 0.0025, 0.0014, 0.0008, 0.00045, 0.00030, 0.00017, 0.00008, 0.00004,
+ 0.00002, 0.00001, 0.000005, 0, 0, 0, 0, 0
+};
+
+/* 20bits unsigned fractional binary codes */
+int lossless_quant[] =
+{
+ 0, 4194304, 2097152, 1384120, 1048576, 696254, 524288, 348127,
+ 262144, 131072, 65431, 33026, 16450, 8208, 4100, 2049,
+ 1024, 512, 256, 128, 64, 32, 16, 8,
+ 4, 2, 1, 0, 0, 0, 0, 0
+};
+
+double lossless_quant_d[] =
+{
+ 0, 1.0, 0.5, 0.33, 0.25, 0.166, 0.125,
+ 0.083, 0.0625, 0.03125, 0.0156, 7.874E-3, 3.922E-3, 1.957E-3,
+ 9.775E-4, 4.885E-4, 2.442E-4, 1.221E-4, 6.104E-5, 3.052E-5, 1.526E-5,
+ 7.629E-6, 3.815E-6, 1.907E-6, 9.537E-7, 4.768E-7, 2.384E-7, 0,
+ 0, 0, 0, 0
+};
diff --git a/contrib/libdca/tables_vq.h b/contrib/libdca/tables_vq.h
new file mode 100644
index 000000000..2aafd762c
--- /dev/null
+++ b/contrib/libdca/tables_vq.h
@@ -0,0 +1,2076 @@
+/*
+ * tables_vq.h
+ * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
+ *
+ * This file is part of libdca, a free DTS Coherent Acoustics stream decoder.
+ * See http://www.videolan.org/developers/libdca.html for updates.
+ *
+ * libdca 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.
+ *
+ * libdca is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/* 8bits signed fractional Q4 binary codes */
+
+static int8_t high_freq_vq[1024][32] =
+{
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ { -4, -2, 2, 1, -16, -10, 1, 3, 1, 0, 6, 1, -3, 7, 1, -22,
+ 2, -4, -3, 11, 14, 6, -1, 1, -13, 29, -28, 10, 10, -8, 0, -9 },
+ { -8, 8, -7, 10, -3, -12, -5, -8, 1, -2, 9, -2, -5, -18, 1, 9,
+ -8, -8, 3, 41, 7, -9, -9, 22, -42, -29, 14, -18, -14, -32, 1, -15 },
+ { -16, 8, 15, 16, -16, 5, 2, 7, -6, -16, -7, 1, 1, -3, -2, 0,
+ 8, 20, -26, -11, 2, -17, 0, -3, -34, -37, 10, 44, -2, 22, 2, -4 },
+ { 7, 14, 5, 6, 15, -1, 3, -3, -9, -23, -5, -14, 8, -1, -14, -6,
+ -5, -8, 54, 31, -6, 18, 2, -19, -2, -11, -30, -6, -19, 2, -2, -14 },
+ { 1, 2, -2, -1, -3, -3, 1, -5, 1, -3, -4, -8, 5, -4, 0, 1,
+ 3, 7, -5, -4, -3, -12, 3, -2, -3, 12, -53, -51, 6, -1, 6, 8 },
+ { 0, -1, 5, 1, -6, -8, 7, 5, -18, -4, -1, 1, 0, -3, -3, -14,
+ -1, -6, 0, -14, -1, -1, 5, -3, -11, 1, -20, 10, 2, 19, -2, -2 },
+ { 2, 4, 3, 0, 5, 0, 3, 1, -2, 0, -6, -3, -4, -5, -3, -3,
+ -7, 0, -34, 4, -43, 17, 0, -53, -13, -7, 24, 14, 5, -18, 9, -20 },
+ { 1, 0, -3, 2, 3, -5, -2, 7, -21, 5, -25, 23, 11, -28, 2, 1,
+ -11, 9, 13, -6, -12, 5, 7, 2, 4, -11, -6, -1, 8, 0, 1, -2 },
+ { 2, -4, -6, -4, 0, -5, -29, 13, -6, -22, -3, -43, 12, -41, 5, 24,
+ 18, -9, -36, -6, 4, -7, -4, 13, 4, -15, -1, -5, 1, 2, -5, 4 },
+ { 0, -1, 13, -6, -5, 1, 0, -3, 1, -5, 19, -22, 31, -27, 4, -15,
+ -6, 15, 9, -13, 1, -9, 10, -17, 4, -1, -1, 4, 2, 0, -3, -5 },
+ { -7, 3, -8, 13, 19, -12, 8, -19, -3, -2, -24, 31, 14, 0, 7, -13,
+ -18, 0, 3, 6, 13, -2, 1, -12, -21, 9, -2, 30, 21, -14, 2, -14 },
+ { -3, -7, 8, -1, -2, -9, 6, 1, -7, 7, 13, 3, -1, -10, 30, 4,
+ -10, 12, 5, 6, -13, -7, -4, -2, -2, 7, -3, -6, 3, 4, 1, 2 },
+ { -8, 9, 2, -3, -5, 2, 0, 9, 3, 7, -4, -16, -13, 3, 23, -27,
+ 18, 46, -38, 6, 4, 43, -1, 0, 8, -7, -4, -1, 11, -7, 6, -3 },
+ { 1, 1, 18, -8, -6, 0, 3, 4, 22, -3, -4, -2, -4, -11, 40, -7,
+ -3, -13, -14, -7, -10, 14, 7, 5, -14, 11, -5, 7, 21, -2, 9, -3 },
+ { 0, 0, -2, 4, -2, 0, 2, 0, -1, 2, -1, 0, 0, 2, 2, 2,
+ -1, 1, -3, -1, -15, -2, -63, -27, -21, -47, -14, 1, -14, 10, 0, 2 },
+ { 1, 0, -4, 0, -3, -9, 4, 2, 6, -6, 0, -5, 11, -7, -15, 6,
+ -7, -6, 3, 7, -15, -5, 23, -13, -6, 12, -8, 9, 2, -3, 3, 4 },
+ { 6, 0, 3, 0, -2, -4, 2, 1, 1, -1, 1, -2, -1, -4, -22, -15,
+ -46, -66, 10, 20, 2, -17, 12, -6, 1, -2, -2, 0, 1, -5, 1, 2 },
+ { -1, 0, 0, 1, 0, -4, 0, 1, -10, -3, -8, 5, 7, -11, 2, -11,
+ 29, -25, 11, 10, 0, -1, 5, -7, -2, -5, -2, 4, 4, -3, 5, -2 },
+ { 1, -1, -1, -3, -2, 1, -8, -3, 2, -2, 4, -5, -1, -7, -2, 1,
+ -14, -7, 3, -30, -15, -14, 3, -4, -1, 3, -13, -1, -3, 1, 2, 3 },
+ { -1, -2, -3, 2, 2, -3, 3, 1, -3, 2, 0, -4, 6, 5, -5, 10,
+ -57, 3, 22, -50, 1, -2, -5, -6, -1, 5, 1, 2, 2, 1, -2, 2 },
+ { 2, 0, -1, -7, 2, 1, 3, 2, 0, 4, 3, -2, 3, -3, 4, -4,
+ 24, -35, -3, 38, -6, -5, 15, 20, 3, 16, -7, -5, 0, -4, -5, 0 },
+ { 0, 1, 0, 0, 0, -1, -1, 1, 1, -1, 1, -2, 0, 0, 0, 0,
+ 0, -1, -2, -1, -5, -2, -43, -3, 46, -52, -10, 7, -8, 11, -2, -1 },
+ { 0, 0, -1, 0, -1, 2, -41, 33, -44, -48, -15, -26, -9, 6, 3, 3,
+ -3, 2, 2, 2, 2, -1, -1, -2, 1, 3, 0, 0, 5, 2, 3, 1 },
+ { -4, 1, 6, 1, -6, -1, -2, 1, -14, -4, 0, -5, -2, 2, -2, 0,
+ -6, 1, 0, 8, -21, 32, -3, -36, -6, -2, -1, -7, 3, 0, 1, -6 },
+ { -3, -2, 3, 0, 2, 2, 8, -4, -4, 6, 2, 1, 3, -6, 4, 3,
+ 13, 0, -12, -1, 25, -20, -2, -23, -15, 7, -3, -11, -3, 6, -1, 0 },
+ { 0, 0, -3, -1, 0, 0, -2, -1, -2, -2, 1, -1, 0, 0, 10, 3,
+ -2, 3, 3, -7, -6, -5, 0, -4, -60, -16, -6, 38, 5, 6, -5, 0 },
+ { 0, 1, 0, 0, 0, 0, 0, 0, 1, -1, -1, 0, 1, 0, 0, 1,
+ 0, 0, -1, 0, -8, 2, -9, 10, 40, 31, -56, -21, 4, 20, -4, 7 },
+ { -2, -2, 0, 4, -3, -1, 7, 3, 1, 3, -8, 0, 3, 1, 2, 5,
+ 1, -2, 14, 5, 4, 5, 5, 5, -5, 9, -66, 0, -20, -2, -8, 4 },
+ { -2, -1, 4, -1, -8, -2, -4, -1, -3, -3, 2, -7, -3, 5, 7, -2,
+ 45, 31, -17, -16, -2, -2, -1, -22, 1, -1, -3, 3, 5, -3, 5, -1 },
+ { -4, 0, 7, 5, 8, 7, 2, 9, -9, -9, -7, -11, -3, -8, 17, -4,
+ 34, 32, 18, 22, 1, 2, 1, -7, -5, 6, -1, 6, 4, 10, -2, -7 },
+ { 6, 0, 14, 9, 6, -1, -2, -3, 4, -6, -8, 4, 7, -1, 28, 38,
+ 15, -1, 16, -11, 5, 8, 4, -10, 3, -10, -17, 5, 3, 3, 3, 1 },
+ { 1, 1, 2, -1, 2, 1, 0, 0, -1, 0, 0, -2, 1, -3, 0, 1,
+ 2, -2, -4, -2, 0, -1, 1, -3, 1, 1, 1, -1, 8, 8, 66, 33 },
+ { -5, 2, -3, -7, 2, -8, -4, 10, 17, -18, -7, 4, -4, -7, -6, -6,
+ -5, 5, -12, 2, 0, 6, 8, -2, 1, 4, -11, 2, 1, 8, 31, 19 },
+ { 6, 9, 16, -6, -6, -1, -2, -3, -11, -2, 7, 7, 17, 3, 4, 10,
+ 2, 5, -13, 8, 7, 1, 4, 5, 7, 6, 7, -8, 9, -8, 33, 6 },
+ { 3, -1, 1, 0, -7, -5, 0, 14, -7, 1, -7, 1, 2, -4, 7, 10,
+ -16, 12, 1, -6, 3, 8, -1, 10, -13, -6, -12, -23, 12, -3, 30, 14 },
+ { -2, -15, 0, 8, 3, -19, 5, -3, 2, 3, 13, 7, 14, -3, -10, 0,
+ 8, 5, -6, -16, -8, -8, 14, 2, -1, 1, -9, -11, 11, -5, 27, 9 },
+ { -8, 6, -4, 4, -4, -1, 5, 4, 1, -7, -5, -4, -15, 1, 9, 0,
+ 8, 4, 1, -17, 11, -2, -19, -1, -6, -8, 3, -12, 3, -17, 33, -10 },
+ { -3, -1, 2, 7, 7, -2, 9, 8, -18, -1, -13, -10, -3, -3, 11, 8,
+ -2, -12, -8, 1, 4, 9, 14, 10, -3, 0, 2, 1, -2, 3, 31, 10 },
+ { -3, -10, 8, -1, -5, -11, 7, -5, 3, 6, 1, 4, -16, 10, 5, -4,
+ -2, -10, -1, 13, 6, -5, -7, 12, 7, -3, -17, 1, 12, -4, 29, 8 },
+ { 1, 2, 5, 2, -6, -7, 0, -1, 6, -1, 10, 6, -4, 5, 2, 2,
+ -2, -8, -6, -11, 14, -13, 27, 3, -2, -12, 5, -16, 2, -26, 20, 15 },
+ { -1, -3, -5, -3, -3, 6, -1, 3, -5, 1, 7, 2, 1, 0, -1, -1,
+ 0, -1, 9, 7, -6, -3, 4, -5, -4, 8, -8, -25, -8, -4, 34, 23 },
+ { -1, -2, 1, 1, -1, -2, -1, 1, -1, 0, 0, 0, 0, -2, -1, 1,
+ 0, 2, 1, -1, 4, 0, 0, 1, -1, 0, 5, 3, 12, -9, 68, -16 },
+ { 10, 0, -8, 14, -6, 1, -12, 0, 0, -3, -5, -11, -6, 12, 9, -10,
+ -3, 5, 0, 7, 11, 2, 4, -3, -8, -3, 7, 4, 3, -3, 34, 4 },
+ { -12, 13, -5, 7, -11, -2, -1, 1, -4, -14, -21, 3, -3, -3, -4, -7,
+ -9, -4, 3, -17, -2, -13, 10, -2, 12, -4, 0, -9, 1, -5, 31, 10 },
+ { -10, 6, 5, 6, 4, -7, 10, 0, -28, -3, 0, -11, -1, -5, 16, -10,
+ -16, 7, 20, 2, -4, 2, -5, 0, 15, 6, 5, -10, 7, -9, 20, 4 },
+ { 1, -7, -2, -7, 4, -3, -2, -7, -1, -14, 6, -16, 4, -5, -4, -6,
+ -5, 0, -2, 2, -6, 9, -5, 4, -18, 8, -10, 8, 15, 0, 32, 1 },
+ { -5, 7, -3, 7, 15, -4, 0, -16, 9, 5, -5, 5, 4, -3, -12, -9,
+ -18, 10, 2, 2, -3, 7, 3, -1, 6, -9, -10, 3, 15, -4, 35, -7 },
+ { -1, -10, 2, 2, -4, -2, 10, 2, -1, 2, -2, 1, -1, -14, -11, 3,
+ -8, 5, -8, -2, 6, -1, -7, 1, 7, 5, 7, 8, 30, -4, 30, 14 },
+ { 2, -2, 1, 2, 3, -8, 3, 0, -2, 0, -9, 2, 1, 4, -6, -1,
+ -2, 5, 0, 1, -2, 12, 6, -3, 9, -3, 4, -12, 21, -39, 24, -2 },
+ { 3, 5, 1, -2, -2, -2, -3, 6, -8, -2, -11, -8, -1, 4, 2, 2,
+ -4, -10, 12, -5, -11, 1, -15, -34, -11, -7, -11, -1, 7, -14, 38, -1 },
+ { -4, 4, 8, 9, 8, 1, -5, -9, 4, -2, 15, -4, 11, -15, 20, -1,
+ -1, -3, 4, -9, -2, -2, -2, 8, 6, 12, -5, 0, 11, -12, 27, -4 },
+ { 0, 8, -4, 3, -11, 6, -11, 2, 3, 0, 5, -8, -7, -6, -9, -21,
+ 4, -11, -1, -16, -7, 16, -3, 7, -7, 4, -5, 0, 11, -7, 31, 3 },
+ { 1, 3, 4, 11, -11, -2, -3, -6, 6, 5, 0, 3, -9, -6, 4, -4,
+ 0, 4, -8, 13, -6, -13, -1, -5, -1, 4, 0, 0, 9, -22, 24, 18 },
+ { -7, 3, 10, -13, -6, 6, -6, 6, 22, 1, 0, -14, 2, 3, 7, -1,
+ 8, 20, -1, 5, -4, 13, 9, -9, -9, 6, 0, -4, 0, -8, 31, -4 },
+ { -3, -4, 0, 1, 7, 3, -7, 0, 5, -2, 1, 3, 3, 1, -5, -2,
+ 5, 2, -11, 4, 0, -1, 12, 0, -3, -13, 15, 8, -6, -27, 34, 0 },
+ { -3, -3, 10, -4, 2, -1, -3, 0, -1, -1, -4, 2, 6, -2, 12, 1,
+ 3, -6, -7, -6, -5, 4, -19, -6, -8, -34, -4, -8, 10, -7, 23, 10 },
+ { -7, 0, -1, -6, 8, 4, -4, 2, -5, -8, -7, -9, -8, 5, 9, 7,
+ -6, 1, -12, -12, -1, -16, 5, 0, 16, 3, -7, -8, 27, -4, 23, 15 },
+ { -8, 4, 8, 5, 6, 11, -3, 5, 3, -1, -11, 6, -5, 0, 2, -6,
+ -3, -6, 4, -1, 5, -5, -12, -6, 7, -5, 9, 3, 6, -7, 29, 1 },
+ { 1, 3, -2, -2, -6, -2, 1, 6, -6, -3, 1, 2, 3, 4, 1, 5,
+ -1, 0, 4, 2, 11, 6, 2, -3, 13, -9, -19, 18, -15, -10, 36, 21 },
+ { -3, -3, 2, -1, -7, 6, -4, 1, -3, -1, -2, 2, 3, -7, -3, 0,
+ -2, 0, -2, 6, -19, 3, -8, 2, -6, 7, -1, 0, 29, -6, 28, -10 },
+ { -5, 1, -3, -7, -12, -4, 1, 1, -1, 13, -10, -1, -9, -5, -13, 6,
+ 13, 3, -4, 2, 3, 11, 2, 6, -25, -16, -6, 0, 14, -1, 27, 16 },
+ { -6, -1, -7, -5, -2, -5, -5, -1, 9, 1, 0, 3, -8, -12, -6, 5,
+ -6, 5, 3, -9, 1, 4, -7, -10, -9, -7, -17, -5, -15, -23, 25, 3 },
+ { -8, -2, 9, -3, -4, 3, -1, 8, -7, -7, -5, -4, -2, 9, 4, -1,
+ -7, -4, -5, -16, 3, -6, 18, -13, -9, 16, -15, 8, 15, -10, 24, 5 },
+ { 1, -38, 2, 34, 9, 10, 11, 2, 2, -6, 3, 2, -2, 5, 4, -7,
+ -1, 1, 4, 0, 3, 1, -8, -1, -6, 5, 4, 2, -4, 5, 2, -1 },
+ { 1, -22, 15, 18, -2, 10, -16, -9, -8, -11, 8, 4, 0, 7, -14, -5,
+ -1, -7, 12, 17, 9, 5, -7, -4, -12, -6, 7, 0, 7, 2, -2, 1 },
+ { -11, -29, 7, 10, 19, -1, -8, -9, 7, 1, 9, 6, 8, -7, -14, 8,
+ -3, -11, -13, 0, -7, -23, -2, -8, 12, 9, 2, 14, 19, 1, -1, 5 },
+ { -24, -27, -11, 36, 2, 6, -3, 4, -6, 8, 0, 12, -1, -4, -6, 3,
+ 4, -1, 2, -3, -2, 3, 2, -1, -2, -4, 0, -1, -2, 7, 2, 3 },
+ { -9, -24, 11, 13, -10, -12, 12, -2, 7, 4, 8, 13, -3, -3, 2, 9,
+ -3, -4, 4, 13, 5, 13, -6, -3, 1, 15, 7, -3, 0, 19, -2, -9 },
+ { -8, -15, 7, 14, -4, -5, 2, -18, -19, -2, 2, 17, 16, 6, -10, 10,
+ -9, 14, -1, -5, -1, -6, -7, 2, 9, 11, 13, 6, -5, -12, 3, 2 },
+ { -10, -37, 13, 1, 3, -14, 0, -20, 4, -3, 8, 2, -2, -3, -9, -5,
+ -3, -17, -1, 13, -11, 2, -6, 4, 4, 0, 3, 1, -9, -4, -5, -4 },
+ { -2, -22, -5, 46, -8, 5, 9, -11, 8, 7, 7, -1, -1, -2, -7, 2,
+ -3, 3, -1, -2, 7, 0, 2, -1, 1, -2, -2, -3, 6, 0, -4, -6 },
+ { -16, -27, 15, 16, -4, 14, -7, -26, 2, -2, 6, 5, -3, 11, 0, 2,
+ 3, 9, -7, -1, 2, -4, -4, -1, 6, 10, 1, 1, -3, -2, 3, 0 },
+ { -3, -22, 10, 26, 1, 2, -3, 3, 17, -3, -7, 9, 1, -21, -4, 5,
+ 3, 0, -7, -6, 3, 3, -8, -7, -9, 3, 7, 1, -8, 12, 6, -7 },
+ { -9, -25, 3, 18, 9, -6, -11, 0, -5, -12, 9, -8, -7, -6, -6, 22,
+ 2, -6, -3, 15, 3, 2, -2, 9, 14, -10, -7, 15, 13, 6, -2, 11 },
+ { 5, -20, -5, 28, 11, 10, -4, -4, 0, -7, 3, 5, 2, -5, -8, 2,
+ 6, 10, 9, -9, -18, 3, 14, 1, 3, -3, -1, -6, 7, 7, 2, -1 },
+ { -8, -30, 7, 12, 10, 8, 7, -13, -16, 0, 1, -1, -6, -11, -15, 4,
+ 1, -2, 10, -15, 1, 11, -2, 8, 9, -7, -7, 9, -5, 2, 7, -18 },
+ { -10, -32, 10, 11, 3, -1, 3, -5, 5, 2, 14, -6, 3, 1, 5, -15,
+ -11, 6, 20, 4, 0, -12, -7, 3, 1, -1, 10, 6, -1, -9, -4, -1 },
+ { 1, -25, -14, 12, -11, 9, 9, -16, -24, -17, 22, -9, 11, -30, -3, -4,
+ 6, -7, 9, 2, -1, -5, -6, 2, -1, -1, 10, 1, -3, 3, 4, 8 },
+ { -14, -26, -6, 9, 8, 17, -11, -24, -7, -4, -8, -2, 10, 2, 2, -1,
+ 2, 13, 12, -7, 4, -6, -10, 6, 6, -13, -11, -7, -16, 0, -2, 5 },
+ { -4, -30, -13, 12, 16, -6, 12, -16, -13, 5, 15, -2, -2, -10, -7, 7,
+ 11, -1, -4, -2, -4, 7, 4, -8, 1, 3, 0, 11, 3, -2, -5, 4 },
+ { -4, -21, 20, 22, 2, 20, -8, 1, -12, -5, -9, 4, -10, -17, -3, -8,
+ -3, 3, -12, 1, -3, 0, 7, 4, 7, 7, -3, 7, 5, 3, 1, -5 },
+ { -12, -20, 2, 29, 11, -6, 9, -7, -6, -4, 0, 6, 17, -13, -2, -10,
+ -17, -1, -18, 2, 0, 14, -6, 1, 0, 3, 2, -10, 1, -5, -2, 5 },
+ { 16, -37, -1, 26, -2, -14, 1, -5, -14, 2, 2, 3, 6, 1, 1, 4,
+ 0, -1, 0, -2, -2, 4, 9, -6, 0, -2, 10, -7, -2, 4, 1, 0 },
+ { -9, -24, -12, 5, 5, 3, -17, -14, 4, 3, 2, -4, 10, -22, -8, -3,
+ 6, 1, 12, -8, 4, 1, 9, -1, 18, -3, 6, 5, 3, -5, 9, -5 },
+ { -14, -33, -2, 20, -13, -10, 2, -7, -1, 11, -9, -8, 18, -3, 1, 8,
+ 0, -2, 10, 7, -2, -13, 9, -3, -4, 5, -2, -2, -1, -5, 1, -7 },
+ { -10, -23, 8, 14, 1, 7, 1, -3, -7, 4, 1, 1, 8, -7, 15, -14,
+ 13, 14, 2, 5, -13, -5, -8, -1, 6, 3, 6, 9, 6, 15, 14, 5 },
+ { -13, -25, -10, 13, -17, -24, -7, -13, -6, -10, -8, 2, 0, -13, -10, -4,
+ -8, 4, -9, 9, -4, 4, -3, -3, 3, 3, -5, -9, 1, -2, 11, 2 },
+ { -12, -23, 1, 18, -11, -2, 5, 9, -5, 5, 14, -9, -3, -2, -6, 2,
+ -2, 11, -13, 1, -3, 11, -9, -4, -2, -6, 8, 10, 1, 4, 2, 1 },
+ { -5, -18, 16, 22, 2, 0, 8, -6, -9, -7, 10, -16, 23, 10, -11, -1,
+ 7, 2, 7, 2, 1, -5, 6, 1, 0, -4, 9, 2, -3, 1, 0, -4 },
+ { -3, -26, 14, 11, 2, -9, 17, -2, -1, -5, -16, -9, -5, 10, -13, 1,
+ 6, 12, 10, 11, 0, 0, -3, -14, 6, -2, 0, 4, -5, -1, -7, -1 },
+ { -10, -33, 1, 8, 11, -5, 1, -6, 7, 4, 5, 6, 1, -2, -10, -5,
+ -6, 12, -11, 5, -10, 4, 12, -1, -1, -3, 4, -1, 9, 0, 16, -17 },
+ { -14, -37, 7, 7, -2, 5, -8, -11, 2, -13, 4, -19, 1, 8, 8, 4,
+ -9, 2, -4, 3, 12, 2, 4, -4, -8, 8, 1, 4, 8, -1, 6, -2 },
+ { -6, -30, 18, 17, 1, -22, -3, 4, -7, -10, 7, 0, -8, 8, -1, 4,
+ 2, 8, 6, -2, 2, 7, 4, 4, 3, -6, 2, 1, -3, 1, -1, -5 },
+ { -17, -18, -3, 22, -8, 1, 9, -2, -17, 20, -5, -5, -12, -5, 4, -5,
+ -9, 8, -2, 16, -3, 0, 19, -8, 8, 1, 2, -4, 0, 11, 0, -3 },
+ { -9, -23, 3, 10, 4, 4, -3, -2, -2, -2, 1, -22, 11, 0, -2, 5,
+ -2, 14, -9, -11, -4, 7, 5, 32, 1, -3, -7, 0, 21, -9, 7, -6 },
+ { 0, 0, 0, 2, -1, 1, 0, 1, 3, 0, 0, 1, 0, 1, 0, 1,
+ -3, 0, -1, -2, 0, -1, -1, -3, -1, 1, -4, 1, -1, -5, -69, -19 },
+ { -3, -5, -8, -12, 4, -3, -19, -11, -5, 0, -14, 7, 18, -6, 7, 22,
+ 8, 14, 15, 10, 3, -1, -3, 5, -1, 7, -7, 1, -6, 3, -26, -11 },
+ { -1, -6, 4, -4, -5, -16, 0, -6, -3, 11, 1, 0, 9, 5, 16, 3,
+ -4, -33, -4, 4, -7, 0, 1, 6, -11, -2, -13, -2, -18, 20, -25, -16 },
+ { 4, 0, -1, 0, -5, 1, 0, 2, 0, 11, -10, 4, -10, 7, 16, 2,
+ 16, 15, 2, -1, 2, 9, 2, 8, -3, -5, -2, 0, -3, 0, -33, -2 },
+ { -3, -15, 10, 10, -9, -1, 7, 3, 5, -5, -8, -8, -3, 15, -9, 4,
+ 12, 13, -13, -14, 10, -6, 9, 22, -27, 23, -1, 5, -24, 2, -30, 5 },
+ { 0, -2, 7, -5, -5, 3, 5, 3, -3, -5, 2, 1, -4, 3, -3, -1,
+ 1, -2, 10, 22, -3, -4, -2, -2, -7, 3, 8, 1, 14, 4, -37, 9 },
+ { -3, -4, -1, 1, -4, 0, 6, 2, 6, -7, -10, -10, -1, -4, 11, -3,
+ 7, -6, 4, -12, -1, 5, 1, -7, 10, -6, 17, -4, 8, 3, -40, 13 },
+ { 2, 12, 4, -7, 14, -3, 16, -2, 18, 2, 13, 5, 5, 1, 11, -1,
+ 0, 9, 2, -6, -1, 2, -6, 2, -5, 3, 5, 1, -1, 1, -32, -7 },
+ { -16, 11, 7, -4, 2, -5, -9, 9, 11, 11, 15, -13, -11, 11, 9, 4,
+ 3, -8, -10, 12, 12, 0, 0, -16, -9, 13, 2, 9, 4, -13, -33, 3 },
+ { 6, 4, 5, 4, 3, -1, 5, 6, 4, 2, -11, -1, -15, -11, -1, 1,
+ 11, -3, -2, 24, -4, -6, -25, -10, -15, -8, 0, 0, -5, 4, -30, 2 },
+ { 10, -3, -6, 1, -9, -5, 6, 9, -10, -3, 8, -1, 4, -1, 11, -11,
+ 3, 9, 11, -3, 6, -17, 5, -8, -33, 9, -13, 19, -2, 9, -25, 2 },
+ { 0, 0, -1, -3, 0, -2, 1, 0, 0, 2, 1, 0, -2, 0, -1, 2,
+ 0, -1, 4, -1, 2, -3, 4, -2, 3, 3, 1, 0, -15, 12, -63, 27 },
+ { -2, 14, 9, -1, 3, 0, 1, 1, -19, 15, 3, 4, 0, -10, 1, -5,
+ 3, 0, -5, -10, 2, -16, -4, 8, -12, -6, 7, -5, -10, -1, -33, -4 },
+ { 0, 3, 1, 3, 1, 2, 4, 4, 9, -6, -8, -5, 1, -12, 3, 8,
+ -10, 6, -1, 1, 13, -5, -5, 2, -4, 13, -18, -10, -7, -9, -33, 10 },
+ { -6, -3, -12, 5, -1, 11, -6, 0, -2, 1, 2, -7, 3, 1, 3, -2,
+ 1, 8, -10, 7, -1, -3, 3, 0, 13, 1, 6, 7, -16, -7, -39, 8 },
+ { -6, -1, 11, 6, -3, 8, 3, -5, 3, 0, -5, -2, -6, -3, -4, 2,
+ -3, 13, -11, 1, 7, 5, 19, -5, -3, -15, -1, 7, -1, 6, -33, 8 },
+ { -7, 3, -4, -3, -4, 1, 6, -5, -5, 6, -8, -1, -7, 4, -1, -6,
+ -2, 1, 7, 0, 1, 1, -5, 2, -2, 0, -13, -2, -31, -14, -39, -12 },
+ { -10, 9, 0, -3, 1, -1, -1, 0, 1, -5, -1, -4, -2, 5, 2, -7,
+ 18, -8, -2, -19, -7, -7, -12, -14, -11, -1, -9, -13, -7, -12, -31, -9 },
+ { -3, -16, 10, 9, 1, -10, -12, 2, -2, 2, 7, -3, -3, 1, -4, -5,
+ -9, 5, 7, 3, -1, 4, -11, -8, 4, 13, -10, 13, 10, -4, -36, 1 },
+ { -7, -12, 4, -20, -7, -7, 2, 11, -1, -2, 3, -12, 1, 0, -6, -7,
+ 6, 4, 13, 3, -3, 4, 3, -6, -12, 5, -5, -22, -13, -8, -37, -6 },
+ { -7, 5, 3, 5, 7, 9, -14, -3, 10, 17, -1, 1, -12, 5, -6, 0,
+ -4, -9, 0, -11, -14, 3, 13, 6, -25, -8, -12, 4, -10, 18, -30, -1 },
+ { -10, 6, -10, 6, 6, 1, -10, 0, -7, 5, -2, 17, -18, -4, 0, -3,
+ -16, -6, -3, -8, 5, 1, -4, 6, -7, 16, 6, 10, -1, 0, -32, -11 },
+ { -1, 9, 9, -5, 4, 9, 6, 9, -4, -2, 7, 11, 4, 2, -5, -4,
+ -6, 0, 2, -3, -1, 5, 10, 0, 12, -10, -18, -3, -1, 14, -33, 2 },
+ { 4, -8, -18, -4, -5, -11, 4, -10, -4, 9, 13, -12, 1, -6, 1, 2,
+ 4, -9, 8, 3, -6, 21, 13, -1, -2, 1, -2, 6, -7, 0, -30, 1 },
+ { 6, -1, 2, -3, -1, -4, 6, -4, 0, 4, 2, 2, -9, 2, 6, 3,
+ -2, 4, -1, 9, -6, 0, 7, -8, 5, 19, -2, 9, -5, 2, -33, -8 },
+ { 2, 1, 12, -5, -8, 8, 3, -2, -4, 1, -2, 5, -4, -9, -8, -8,
+ 7, -11, -4, 6, -10, 7, -1, -1, -2, -1, 16, 32, -7, 20, -33, -6 },
+ { -18, 2, 6, 13, 9, 9, -1, 3, -17, 24, -2, -6, 28, 8, -2, 6,
+ 3, -10, -34, -16, -13, -4, -15, -11, -12, -3, -10, 4, -8, 4, -31, -4 },
+ { -11, 0, 18, 2, -16, -9, -13, -2, -2, -12, -3, -22, 30, 0, 8, 3,
+ 9, -4, -16, 1, 0, -11, 15, -2, -4, 6, -5, 6, 1, 2, -25, -12 },
+ { 14, -1, 5, 7, 3, -15, -8, 1, 5, -2, 12, 13, 11, -25, 3, 1,
+ 0, -2, -4, -16, -23, 0, -5, -17, 7, 5, -9, 6, -5, 2, -32, -7 },
+ { 3, -1, 6, 14, 2, -12, -9, -9, 4, 7, 4, 6, 5, -8, 4, 2,
+ 4, 5, -2, 8, 8, -6, 0, 10, -20, -1, 3, -1, 8, 23, -33, -5 },
+ { -3, 11, -6, 3, -4, 5, 7, 3, 4, 5, -2, 3, -1, 30, 6, 1,
+ 8, -6, 0, 0, -9, 6, -9, 4, 2, 9, -6, 1, -12, 0, -34, 18 },
+ { -17, 13, 0, 1, 9, -4, -11, 0, 7, 0, -10, -4, -1, 6, -6, 4,
+ 1, 6, -9, 3, -5, -6, -11, 2, -4, 14, 23, -3, 2, 5, -30, 12 },
+ { -14, 5, -27, 2, 0, 7, 1, 4, 30, 8, 7, 5, 1, -1, 0, 5,
+ 8, -10, 48, -11, 12, 33, 6, 8, -15, 20, -2, -5, 32, 5, -19, 10 },
+ { -16, -4, -12, -7, -2, 0, 8, -6, -20, -18, 16, -3, 0, 31, -2, 11,
+ 2, -9, 49, -19, -12, -23, 10, 26, 16, -2, 4, -21, -14, 13, -11, -9 },
+ { -5, -9, -1, 3, -5, -21, 2, 10, 0, 0, 10, -21, -7, 7, -26, -9,
+ 22, 32, 58, 11, -3, 11, -5, -8, -13, 6, -5, -9, 1, 10, 14, -8 },
+ { 7, 7, 10, 3, -2, -1, -11, -11, -6, -43, -3, 14, -19, -18, 19, 18,
+ -32, 10, 45, -6, 6, 21, -20, -12, 2, 4, 6, 6, -4, 3, 3, 1 },
+ { 21, 22, -3, -2, -11, -6, -1, -2, 8, 8, 32, -21, 7, 28, -4, -6,
+ -3, -2, 50, 2, 2, 27, -5, -8, 12, 7, -5, -1, -4, -17, 27, 6 },
+ { 13, 7, 2, -6, -12, 2, -10, -5, -17, 11, 4, 17, -12, -2, 5, -17,
+ 37, -16, 48, -14, -18, 29, 8, 24, 11, -5, -9, 11, -1, 1, -13, -3 },
+ { 1, 1, -1, 2, 0, 0, 0, -1, 1, -1, 7, 2, -3, 3, 0, 6,
+ 2, 10, 54, -25, 7, 54, -5, -6, -1, -15, 9, 13, -24, -15, -12, 3 },
+ { 21, 5, 8, 3, -3, -4, -2, -4, 3, -11, -5, -8, 9, 16, 8, -9,
+ -10, -3, 46, -46, 2, 1, -10, 10, 17, 11, -20, -36, 10, 14, 0, -5 },
+ { 7, -13, -6, -9, -24, 45, 2, 8, 8, 0, 17, 20, 12, -24, 1, -7,
+ -15, -3, 46, -13, -2, 20, 1, -13, -11, -13, 2, 15, 1, 10, -1, 3 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -2, -1,
+ -16, -9, 31, -69, -34, 26, 7, 17, -1, -6, -1, 0, 0, 0, 0, 0 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -4,
+ -5, -20, 18, -82, 22, 3, -7, 9, 4, 6, 2, -4, -1, 0, -2, 2 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 4, -1,
+ 15, -5, 62, -36, 4, 52, -7, 5, 0, 6, 1, 2, 1, 1, -1, 0 },
+ { 3, -19, 19, -20, 13, -4, -11, 8, 8, -16, 10, 1, -14, 30, 1, -33,
+ 10, -11, 45, -30, 3, -4, -3, -13, 7, 12, 3, -22, 3, -2, -4, -2 },
+ { -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 1,
+ 11, 8, 70, 48, -10, 21, 4, 9, -9, -9, -4, -6, 0, -1, 0, 0 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0,
+ 2, -1, 80, 2, -15, -36, -10, -5, -2, 8, -2, 2, 0, 0, 0, 0 },
+ { 10, 8, -8, -8, -24, 12, -1, 0, 20, 9, -1, -2, 2, -2, 12, -10,
+ -2, -13, 35, -43, 44, 15, -10, -25, 4, 10, -3, -5, -5, 7, -1, 3 },
+ { 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, -2, -1,
+ -18, 9, 49, -72, 7, -8, 7, -5, 2, 3, 2, -2, 1, -2, -3, 1 },
+ { -1, 4, -3, 10, 19, 4, 3, 20, 6, -24, 6, 9, 8, 15, 18, 18,
+ -36, 19, 57, -11, 4, -3, 8, 7, 2, -3, -2, -9, -15, -2, 12, -4 },
+ { 20, 3, 11, -9, -4, 22, 42, -25, 1, 5, -10, -19, 0, 9, -16, 5,
+ 2, 10, 44, -29, 17, -3, -9, -2, -1, 8, 14, -7, -1, 16, -5, 1 },
+ { -7, 16, -11, 12, 6, 33, -15, 14, -23, 2, -26, 8, 2, 10, 0, -5,
+ 8, -8, 38, -38, -4, 5, 5, 5, 1, 22, -15, 7, 6, 0, 4, 28 },
+ { -1, -12, 2, 10, -2, 0, 7, 17, 12, 22, -4, 10, 25, 29, 5, 18,
+ 4, 1, 27, -39, 31, 17, 2, 2, 22, -23, 13, 16, 1, -7, -4, -5 },
+ { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -2, 0, -14, 0,
+ -7, -11, 49, -22, -4, 19, 17, -39, 4, -29, 10, 2, 36, -4, 23, -1 },
+ { -2, -2, -2, -2, 1, 15, -5, -7, -16, -8, -19, 16, -3, -20, 36, -9,
+ -3, 20, 39, -20, 0, 2, 27, -16, 10, 10, -14, -22, -16, -3, 13, -8 },
+ { 5, -9, 6, -25, 7, 37, 13, -10, -5, 3, -5, 7, 18, -22, -7, 9,
+ -5, -4, 50, -11, -4, -5, -5, 8, -4, -2, -4, -27, 14, 20, 7, -9 },
+ { 0, -14, -10, -27, -14, -17, -6, 26, 10, 2, 14, -12, -5, 0, 8, 9,
+ 0, -28, 55, -7, -12, -7, 4, -10, 10, 7, -12, 11, 3, 5, 9, -8 },
+ { 2, 23, 4, -2, -1, -20, -2, 14, 10, -9, -9, -24, 10, 0, 11, -12,
+ 12, 11, 49, -25, -2, 29, 7, -13, 21, -10, 11, -17, 3, 1, -8, 5 },
+ { 3, 0, -14, -6, 18, -2, 17, -9, -19, 9, -5, 9, 14, 6, 19, -3,
+ 27, 1, 41, -21, 20, -15, 33, 0, 26, 14, 7, 10, 3, 20, -3, -12 },
+ { -1, 16, 15, -8, 3, -8, -8, 21, -5, -16, -29, 4, 1, -6, -4, -28,
+ 2, 31, 37, -26, -2, 13, 24, 8, -9, -6, -29, 10, 7, 2, 7, 8 },
+ { -10, -10, 11, 13, -32, 2, 16, 9, 14, 23, -15, -13, 24, 13, 4, -27,
+ 14, 12, 31, -18, 17, 23, -2, -7, -14, 9, -17, -6, -10, 20, 9, 6 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0,
+ 5, 1, 89, 8, 10, -6, 2, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, -1,
+ 4, -7, 64, -50, 7, 37, 2, 5, 0, 0, 0, 0, 0, 0, 0, 0 },
+ { -2, 5, 3, -4, -4, -3, 2, -3, 3, -3, 5, 4, 1, -6, -1, 1,
+ 6, -2, 50, -35, -7, 43, 7, -7, -5, -26, 24, 21, 3, -15, 5, 6 },
+ { -8, 21, -19, 33, -8, 22, -11, 17, 3, 0, 0, -2, 1, -3, 6, -1,
+ 10, -8, 4, -11, -4, -5, 0, 8, -4, 3, 1, -4, 4, 2, 8, 4 },
+ { -7, 5, -20, 9, -22, 3, -14, 1, 6, 13, 23, -2, -4, -7, 2, 0,
+ 11, 4, 6, 3, -7, -11, -7, 4, 5, 5, -12, 8, 2, 4, 7, -3 },
+ { -7, 6, -4, 20, -20, 16, -2, 7, 6, 16, 11, 12, -7, -7, 5, 3,
+ -9, -4, 1, 2, 5, 2, 1, -9, -2, -17, -4, 6, -10, 7, -7, -6 },
+ { -9, 18, -17, 12, -24, 1, -1, 4, 14, 9, 4, 3, 2, 8, -12, -14,
+ 4, -8, -4, 7, 7, 6, -1, 13, -9, -4, -1, 1, 0, -4, 15, 8 },
+ { -25, 2, -11, 6, -5, 24, -28, -5, 8, 12, -2, 6, 8, -3, 8, -9,
+ -1, -5, -1, -5, 6, -1, -1, -1, -4, 8, -12, -2, -13, 7, 2, 1 },
+ { -14, 14, -18, 20, -10, 12, -2, 9, 1, 0, 12, -2, 15, -10, 26, -17,
+ 16, -11, 10, -10, 9, -2, 4, -8, 2, -3, 4, 4, 2, -3, -5, 1 },
+ { -18, 12, -18, 21, -6, 12, -6, 13, -25, 18, 1, 11, -9, -5, 0, 10,
+ -5, 3, -3, 8, -9, 7, 4, 2, -9, 0, 5, 0, 2, -3, 9, -8 },
+ { -4, 16, 1, 18, -30, 9, 1, 6, -8, 13, 13, -12, -6, -1, 13, 7,
+ 6, 2, -15, -3, 5, 5, 1, -6, 1, -5, 0, 2, -16, 0, 3, -4 },
+ { -21, 1, -2, 6, -43, 18, -1, 5, -1, 4, 6, -2, -1, -3, -1, -3,
+ 0, 1, 2, -9, 0, -1, 0, -2, 0, -1, -1, -2, 6, 0, 1, -2 },
+ { -23, 10, 4, 7, -32, -11, -18, 2, -2, -7, -6, -3, -3, -12, 19, 3,
+ -5, -6, 16, -6, 16, 2, 16, 16, 8, -2, 13, 8, -15, -11, 2, 10 },
+ { -8, 2, -13, 2, -29, 24, -20, 19, 1, 10, -4, 10, 1, 2, -9, 11,
+ -1, -2, 9, -5, 19, -7, 16, -9, -2, -18, 11, 1, 1, 0, 7, -3 },
+ { -6, 3, 4, 13, -26, 10, -10, 28, -7, 28, 1, 7, 0, -14, 5, 7,
+ 4, -4, 3, -2, 3, 3, -11, 7, 6, 4, 0, -1, 2, -1, -3, 2 },
+ { -6, 16, -31, 13, -10, 17, -6, 4, -14, 4, 4, -1, -10, 12, -5, 1,
+ -14, 15, 0, -8, 1, -5, 3, 3, 9, -5, 7, -20, 7, 4, 11, -5 },
+ { -19, 3, -17, 14, -12, 16, -22, 18, 14, 8, -2, 4, 10, 12, -14, 4,
+ -3, 2, 3, 7, -7, 7, -6, 2, -2, -4, -5, 0, -5, -2, 2, 1 },
+ { -9, -7, -11, 24, -36, -9, -11, 5, 7, -12, -13, 18, -2, 20, 1, -4,
+ -1, -10, 15, -6, 14, 1, 0, 2, 1, 2, -9, -16, -11, 7, 13, 0 },
+ { -24, 24, -18, 18, -22, 14, -11, 13, -12, 11, -10, 11, -7, 11, -5, -4,
+ -1, 1, 5, 2, 3, -1, 1, -5, 7, -4, 5, -6, 8, -7, 8, -6 },
+ { -6, 18, -22, 22, 5, 11, -1, 6, 19, 22, 8, 4, -8, 20, -2, 15,
+ -6, -18, 0, -33, -9, -12, -1, 6, 5, 2, 5, 5, -5, -17, -3, -3 },
+ { 1, 11, -16, 9, -18, 11, -4, 18, 20, 26, -10, 8, 1, -11, 8, -4,
+ 0, 7, 3, 5, 2, 2, 10, -2, -4, 4, -4, -2, 1, -4, -5, -1 },
+ { -10, 6, -1, 18, -17, 27, -3, 10, -2, 12, -7, -9, 1, 1, -1, 7,
+ -12, -1, -7, -6, -1, 8, 3, -15, 8, 9, 3, -7, 4, -1, 1, -1 },
+ { -14, 6, -16, 22, 2, 5, 0, 5, -18, 11, 6, -3, 22, -20, -9, -3,
+ 6, -6, -7, -15, 1, 15, -8, 11, 8, -3, -8, 1, -8, 2, 6, -2 },
+ { -21, 5, -19, 19, -7, 4, -7, 0, -8, 6, 12, 5, -3, -22, -13, -6,
+ -1, -3, -2, -14, 6, -3, 1, -8, -7, -5, -6, 11, -3, -10, -5, 2 },
+ { -1, 9, -12, 15, -6, 6, -19, 14, -9, 11, 3, 12, -17, -3, 8, -4,
+ -3, -4, 1, -5, 4, 5, -7, -15, -7, 15, -6, -5, 1, -5, -3, 1 },
+ { -12, 20, -15, 20, -14, 3, -14, 9, -6, 33, -13, 6, -2, 8, -6, 7,
+ -5, -6, -3, -3, 0, 8, -3, -3, 1, -2, 2, 2, 6, -5, -5, -2 },
+ { -7, 12, -18, 12, -18, 10, -4, 8, 2, 4, 8, 9, 0, 3, -8, 3,
+ 6, -12, -4, 1, 25, -5, -9, 6, -7, 0, -9, -7, 3, -5, -4, -4 },
+ { -18, 12, -10, 11, -22, 0, -15, 5, -2, 2, -3, 6, -4, -4, -3, -15,
+ -2, -3, 21, 6, -12, -11, 19, 3, 3, -14, 7, 0, -11, -22, -10, 0 },
+ { -15, 2, -30, 15, -17, 13, -16, 8, -7, 10, -8, 2, 11, 3, 10, -7,
+ 7, -22, 12, -10, 3, -12, 6, -10, 12, -10, 7, -8, 5, 2, 9, 1 },
+ { -9, 11, -14, 6, -10, 21, 5, 12, -5, 5, 7, 21, 6, 2, -2, -1,
+ -1, 4, 2, -20, -18, -1, -14, 3, -1, 4, -7, 10, 1, 11, 4, -4 },
+ { -22, 8, -30, 13, -21, -4, 4, -1, 12, 9, -2, -3, 2, -6, 4, -13,
+ -2, 8, 8, 1, -7, 3, -4, -5, -1, -7, -2, 8, 8, 7, 8, 0 },
+ { -6, -4, -35, 16, -13, 15, -11, 14, -7, 9, -1, 11, 7, 0, 13, 10,
+ -1, 8, 1, 1, -2, 8, -1, 2, 2, 3, -10, -1, 7, -13, -3, -7 },
+ { -15, 7, -16, 14, -18, 17, -6, 14, 3, 4, 7, -3, 10, -22, 5, -15,
+ 4, -4, -11, 15, -15, 11, -11, 20, 1, 0, 2, 1, 11, -3, 11, -7 },
+ { -12, 3, 5, 16, -37, -1, 15, 15, -15, 10, 3, -10, 1, 15, 7, -15,
+ -13, 8, 9, -3, 2, 12, -8, 2, -5, 0, -3, 4, 5, -9, -4, 5 },
+ { -16, 26, -4, 14, -22, 26, 6, -3, -8, 4, 21, 6, 16, -4, -11, 7,
+ -10, 3, 3, 7, -4, 2, -9, 8, -2, 2, 5, -2, -4, -2, 7, -1 },
+ { -7, -10, 4, 3, 2, -4, -12, -10, -4, -5, 16, 19, -16, 1, 2, -9,
+ -10, 0, 9, 7, -8, 3, 12, 8, -6, -11, -13, -1, -3, -20, 6, -5 },
+ { -14, -17, 3, -5, 14, -12, -12, 8, -6, -25, 21, 21, 10, -8, -12, 4,
+ 10, -4, 3, -9, 11, 9, 0, 4, 2, -15, 1, -14, 4, 1, 0, -4 },
+ { -4, -9, -3, -1, 6, 3, -6, 6, -10, -4, 14, 8, 2, -3, -12, -19,
+ 0, 11, -20, 1, 6, -2, -27, -6, 10, -17, -14, -17, -9, 8, -8, 3 },
+ { -12, -13, 16, -4, -2, 12, -7, -11, 2, -13, 3, 7, -16, -18, -1, -12,
+ -2, 1, -12, -9, -2, -6, 2, 9, -22, -3, -4, -14, -7, 7, -1, 2 },
+ { -7, -8, -8, 15, 15, 18, 15, 16, -4, -37, 11, 15, -12, -1, -3, 3,
+ 6, 6, 0, -5, -3, -5, 9, 1, 1, -11, -1, -8, -6, 2, 3, 0 },
+ { -6, 7, -5, -12, 13, 10, -18, -4, -3, -21, 6, 16, -15, -7, -12, -9,
+ 1, -12, -1, 10, -2, -1, -3, 4, -4, 1, -16, -1, 12, -9, 5, 9 },
+ { -14, -5, 9, 3, 4, 26, -28, 3, -6, -24, 4, 5, 3, 13, 5, -1,
+ 3, -1, 3, 1, 1, -5, 3, 0, -7, -8, -7, -3, 3, -5, 4, 0 },
+ { -4, 2, -10, -6, 25, 26, -6, 10, -6, -8, 15, 11, -6, -3, 2, -7,
+ 5, 14, 9, -1, 0, -12, 4, -4, -10, 1, -3, 3, -2, -2, -6, -1 },
+ { -10, 8, -15, -10, 19, 17, -8, 0, -3, -7, 7, 5, -13, -1, 7, -7,
+ 1, 13, -12, -13, 17, -12, 1, 26, -18, -3, -5, -6, 4, 5, 8, 1 },
+ { 2, -5, 3, 0, 0, 0, 2, -3, -2, -5, 7, 13, -4, 9, 0, -5,
+ 4, -1, -11, -8, -4, 0, -13, 2, -47, -23, -8, -11, -4, 4, -2, -3 },
+ { -18, -4, 4, 5, -1, 17, -12, -8, 1, -12, 7, 20, -12, 3, -2, -11,
+ 16, 12, -6, 1, -13, -16, -6, -3, -3, -5, 4, -12, -5, -9, 10, 1 },
+ { -11, 0, 4, 7, 7, 8, 3, -1, 3, -19, 32, 8, -19, -8, 2, 4,
+ -12, 15, -16, 3, 1, 9, -2, 1, -2, 8, 5, 6, -4, -1, 11, -8 },
+ { 3, -1, 4, -2, 14, 32, -9, -23, -10, -12, 22, 15, -1, -2, 10, 0,
+ 4, 6, -8, 4, -15, -2, -1, -4, 0, -8, 4, 1, -8, 3, 4, 1 },
+ { -17, -12, 6, -8, 16, 13, -20, -8, -1, -16, 10, 21, -19, 11, -9, -5,
+ 7, 18, -6, 7, -7, -18, 13, 2, -2, 8, -12, -9, 2, 4, -5, 16 },
+ { 4, 0, 17, -11, 12, 7, -12, 5, -1, -25, 30, -8, -7, -6, -4, -7,
+ 9, 8, 7, 3, 3, -16, 8, 0, -2, -2, -18, -3, -4, -5, 1, 4 },
+ { -3, -6, 6, -16, 17, 6, -3, 2, -9, -17, 12, 11, 11, 2, -20, 8,
+ 1, 1, 0, 2, -2, -6, -21, -13, -9, -15, -1, -8, -6, -8, 0, -2 },
+ { -11, -7, 6, -9, 3, 6, 8, 16, 4, -5, 23, 26, -10, -3, 4, 0,
+ 2, 2, -4, 4, -2, -12, 12, 10, -11, 0, -10, -16, 3, 0, 0, -10 },
+ { -5, -16, 10, -6, 27, 13, -3, 4, -2, -13, 15, 5, 2, 5, 3, -4,
+ 13, 12, -11, -7, 0, 1, 11, 12, 2, 13, -15, -8, 9, -2, 3, 8 },
+ { -5, -8, 4, 3, 9, 3, -11, 10, 14, -25, 14, 8, -2, 5, -12, -21,
+ 2, 10, -7, 2, -3, 2, 0, 2, -1, -3, -5, -6, -1, -16, 2, 8 },
+ { -1, 5, 1, -11, 5, 9, -7, 8, -13, -12, 4, 12, -4, 1, -1, -1,
+ 27, 29, 10, 15, 2, -6, -3, 4, -21, 10, -9, -11, -6, -1, -9, -3 },
+ { -6, -3, -1, -6, 11, -5, 0, -2, -5, -31, 11, 3, -1, 5, -3, 4,
+ 5, 7, -10, 5, -10, -13, 4, 12, -15, -2, 2, -7, 1, -9, -3, -10 },
+ { -3, -7, 17, -8, -5, 36, 8, -7, -8, -20, 12, 8, 1, -1, 3, 0,
+ 1, 4, -10, 3, 1, 4, -2, -3, -2, -3, -10, 4, -1, -7, 3, 2 },
+ { -13, -3, -5, 9, 22, 6, -23, 3, -10, -7, 17, 17, 18, -14, -8, -8,
+ 2, 4, -8, 2, -3, -8, 6, 4, -1, 7, 0, 0, -3, 0, -12, -3 },
+ { -3, -10, -15, -3, 9, 3, -23, -9, -13, -18, 12, 13, -2, 0, 1, 8,
+ -1, 2, -7, -12, -5, 14, 2, 1, -22, 6, -10, -8, -9, 28, -7, -14 },
+ { -3, 1, 2, -1, 13, 7, -2, -7, 1, -3, 6, 9, -3, -2, 4, -2,
+ 2, 1, -10, -2, -2, -22, -2, -7, -10, -5, -11, -27, -12, -16, 4, -7 },
+ { 2, -6, -3, 1, 8, 0, -2, 12, -3, -4, 58, 15, -10, -4, -2, 2,
+ -2, 0, -2, -6, 2, 4, -1, 1, -4, 1, -1, -5, -4, -3, 3, 1 },
+ { 10, -1, 0, 5, 21, 7, -14, 6, -3, -16, 15, 17, -16, 13, 3, -6,
+ -4, 6, -12, -5, 1, -4, -7, -8, 2, 3, -6, 6, -1, -8, 5, 4 },
+ { -6, -2, -8, -11, 15, 10, 0, 8, -6, -15, 33, 8, -2, 18, -15, -11,
+ 5, -1, 0, 15, -15, -4, -4, -1, 10, 7, -13, 4, -4, 0, 8, 3 },
+ { -7, -2, 0, -2, 0, -2, -4, -5, -14, -16, 12, 38, 7, 12, 6, -4,
+ 0, -1, 0, 3, -2, -6, 0, 2, -9, 1, 0, -1, 0, -2, 4, 1 },
+ { -8, -4, 18, 1, 14, 5, -12, -3, 20, -17, 5, 19, -11, -8, 11, -3,
+ 3, 9, -7, -8, 9, -17, 2, 15, -10, -11, 5, -5, 7, 15, -6, -2 },
+ { -7, 2, 38, 5, 19, 16, -5, 4, -13, -20, 0, 4, -4, 6, 4, 2,
+ -7, 6, -8, -2, -5, -7, 6, 3, -4, -3, -2, -3, 7, -6, -4, 0 },
+ { -11, -12, 8, -15, -3, 14, -7, -22, -11, 2, 22, 14, -19, 2, -19, -6,
+ 1, 3, -18, 14, 2, -6, -2, -8, -3, -6, 5, -7, -8, -4, 1, 1 },
+ { 8, 7, 25, -21, 12, -6, -5, -4, -10, 6, 0, 10, 1, -12, 18, -5,
+ -15, 4, 1, 14, -1, 5, 8, -7, 1, -7, -3, 9, 10, 1, -1, 0 },
+ { 9, 10, 32, -15, 8, 2, 11, -7, -18, -8, 2, -6, -9, -16, -3, 3,
+ -1, 3, 1, -5, 4, -2, 1, -8, 0, -6, -3, -11, 1, 5, 0, 0 },
+ { 14, 0, 23, -25, 22, 3, 7, 10, 0, -2, 7, 8, 0, 10, 0, 0,
+ 3, 2, 3, -10, 0, 10, 0, -7, 0, 10, -1, -5, -7, 1, -1, 2 },
+ { 12, 0, 25, -18, -5, -4, 13, -10, 3, -6, 7, 21, 0, -16, 3, -10,
+ -6, 5, -7, -3, 2, 5, 3, -6, 4, 9, -8, 12, -2, 3, 2, 4 },
+ { 31, 15, 27, -20, 10, -7, 15, -10, 9, -8, 4, -5, 3, -3, 5, 6,
+ 11, -2, -12, -2, 6, -2, 1, 2, -1, -1, 1, 1, 3, 1, 1, 2 },
+ { 12, -4, 13, -23, 12, -6, 2, 4, -3, 13, 6, -7, 5, -19, -7, 18,
+ 1, -7, 7, 1, 16, -7, 3, 0, 3, 0, -12, 8, -11, 9, 4, 7 },
+ { 29, 1, 3, -22, -5, 6, 0, 12, -14, 11, 1, 6, -3, 4, 6, -2,
+ 4, -13, 12, 1, 1, 3, -11, 9, -10, -1, -7, 16, -11, -1, 3, 9 },
+ { 4, 4, 36, -23, -5, -8, -15, 1, -6, 3, 13, -1, -5, -7, 4, 9,
+ 2, -11, -3, 5, 1, 3, -6, -1, -4, -4, -2, 2, 3, -1, -5, -2 },
+ { 19, 10, 6, -17, 2, -4, -2, -4, -3, 13, 2, 2, -13, -7, -3, -11,
+ 9, -6, 1, -9, -5, 4, -5, -9, -18, -7, -11, 9, 4, -11, 8, 4 },
+ { 16, -3, 9, -16, 18, -2, -12, -16, -11, 11, -18, 16, -13, 6, 2, 8,
+ 3, 8, -4, -16, 10, -11, -1, -3, -8, 5, -9, -4, 9, -4, 0, -3 },
+ { 14, 15, 3, -23, -5, 7, -8, -6, 2, 17, 2, 12, -8, -12, 13, -1,
+ -9, 3, 1, 1, 19, 15, 4, -1, 1, 2, -3, 2, -3, 1, 5, 3 },
+ { 32, 5, -10, -47, -5, -1, 4, 11, -7, 0, 2, -2, 1, -7, 6, -4,
+ 6, 2, -4, -2, 2, -2, 0, -4, 1, -6, -5, 2, -2, -1, -3, -4 },
+ { 20, 8, 10, -21, -7, -9, -16, 12, 1, 4, 6, -5, 9, -11, -7, 4,
+ -11, 28, -3, 2, 4, -6, 10, -8, -5, -5, -9, 9, -2, -1, 6, -5 },
+ { 38, 3, 23, -25, -6, -18, 3, -10, -8, 6, -10, 1, -10, 2, 2, 0,
+ -7, 2, -4, 5, -1, 8, -3, 0, 3, 3, -1, 1, 0, -4, -4, 0 },
+ { 20, 5, 16, -22, 24, -18, 2, -12, -14, -7, -3, 10, 2, 7, -10, 2,
+ -8, 1, 8, -1, 4, 1, 4, -2, 5, -9, -18, -8, -13, 5, -11, 10 },
+ { 14, 8, -12, -16, 9, -11, -3, -6, -25, -7, 6, 5, -7, -16, 10, 2,
+ -7, -1, -9, -3, 16, 4, 3, 3, -3, -3, -15, 13, -3, 4, 13, -7 },
+ { 16, -9, 19, -23, 7, -19, -3, -5, -15, 11, -21, 21, -16, 18, -1, 6,
+ 10, -10, 18, -14, 16, -15, 6, -5, -9, 5, -17, 13, -10, 13, 0, 10 },
+ { 8, -4, 4, -24, 8, -21, -18, 9, -11, 4, -6, 17, 5, -9, -2, -2,
+ 2, 15, -2, -3, -2, 1, 7, -13, 15, -10, -8, -11, 3, 3, -1, -1 },
+ { 14, 17, 6, -32, 5, -17, -2, 0, 15, -1, -5, 16, 1, -5, -2, 9,
+ -3, 8, 4, -2, -2, -4, -3, 1, 0, 7, -3, 4, -5, 0, -7, 2 },
+ { 24, 6, 22, -12, 8, 3, -14, 4, -7, 8, 6, 5, 6, 1, 6, -12,
+ 15, 10, 4, 11, 9, 6, -7, -4, 10, -9, 2, -1, -5, 11, 15, 3 },
+ { 17, 12, 3, -23, 5, -1, -2, 1, -9, -1, -3, 1, 8, 1, -5, 17,
+ 11, 0, -2, -11, 7, 4, 0, -27, -7, 1, 2, -8, 9, 7, 5, 3 },
+ { 12, 10, 12, -10, -4, 5, -1, 2, -24, 5, -8, 2, 6, -17, 19, 5,
+ 12, -2, 16, -7, -6, -14, 4, 1, -3, 13, -16, 5, -1, 4, 1, 1 },
+ { 31, 9, 11, -17, 10, -3, -7, 7, 1, 2, 2, 4, -3, -1, 11, 4,
+ -5, -8, 1, 4, 15, -6, -28, 1, 8, 3, -6, 5, 17, -2, 2, -4 },
+ { 11, 19, 16, -26, 0, -7, -7, 2, -13, -15, -12, 9, -3, 27, 8, 4,
+ -6, 1, 4, -6, 11, -1, -6, -7, -3, 0, -6, 4, -6, -7, -3, -1 },
+ { 10, 18, 16, -32, 19, -9, -4, -3, -7, 8, 8, -3, -11, -2, -6, -16,
+ 13, 13, -6, -1, 10, -2, -2, -9, 0, -3, 9, 4, 11, -2, -6, 6 },
+ { 9, 4, 19, -33, 4, 7, -12, 36, -3, -1, 8, -2, 2, -8, -9, -4,
+ -8, 0, 1, -1, 0, -4, -4, 3, 0, 3, 6, 0, -6, 2, 0, -2 },
+ { 25, 7, 15, -12, 2, -24, -1, 24, -4, 4, 9, 0, -2, -9, 4, 6,
+ 3, 13, -3, 1, 5, -1, -3, -5, -1, 7, -2, 3, 4, 4, 1, 0 },
+ { 19, 6, 8, -20, 9, -9, 5, -4, -13, 7, 11, -3, 5, -13, -9, 6,
+ -11, -1, 0, 4, 11, 26, 3, 6, -7, 12, 6, -3, 1, -9, 7, 1 },
+ { 15, 6, 19, -23, -3, -9, 3, 16, -6, -4, 6, -5, -10, 1, 16, -14,
+ 2, 0, 2, -13, -3, 8, -6, 3, 1, 1, 2, -5, 12, -4, -8, -3 },
+ { 14, 4, 16, -20, 1, 12, 0, 6, -3, 9, 4, 16, 10, -16, 5, 7,
+ 5, -4, -4, -18, -3, -11, -4, 4, -7, 3, 13, 7, 3, 3, 2, -7 },
+ { 22, 3, -1, -30, 18, -3, -9, 9, -2, 11, -16, -2, -14, 12, 0, 4,
+ -5, 4, -1, 3, -20, 12, 4, -10, -2, -2, -12, -12, 10, 6, 11, -3 },
+ { 15, 7, 2, -21, 5, 4, 9, -9, -33, 7, 7, 3, -6, -14, -8, 10,
+ 12, 0, 2, -1, 5, 4, -2, 0, -7, 0, 2, 4, 0, 1, -3, 8 },
+ { -7, 0, 12, 3, 0, -6, 8, -4, 0, 2, 14, -15, 2, -7, -31, -3,
+ 14, 0, 14, -15, -1, -4, -15, 10, 1, -3, 1, 2, 5, 2, -8, 1 },
+ { -2, 5, 1, 0, -3, 3, 3, -6, -1, 2, -4, 1, -19, 0, -11, 18,
+ 11, 10, 21, 5, 6, 2, 10, 3, -6, 0, -2, 13, 5, -1, -2, 9 },
+ { -9, 1, -5, 0, 0, -15, 8, 4, 8, 3, 8, 12, -13, -2, -39, -2,
+ 4, -4, 5, -3, -4, 3, -3, 3, 10, 5, 3, 2, -3, 5, -2, 8 },
+ { -9, 6, 6, -8, 12, -12, 23, -18, 4, -15, -5, 2, -20, 13, -7, 7,
+ 7, -12, 14, -12, 6, 1, 1, -3, -8, 9, 0, 1, -7, 3, 7, -6 },
+ { -18, 13, 4, 3, -10, -30, -10, -6, -14, 1, -7, -4, -35, 5, -25, 11,
+ 9, 8, 19, -4, -7, -3, -18, -8, 1, 5, 10, -4, -14, -9, 3, -4 },
+ { -6, -1, 4, -9, -9, 4, 20, 0, 0, 3, 11, 7, -16, -17, -20, 11,
+ -6, -14, 1, 4, 19, 2, -8, 6, -15, 3, 6, -5, -14, 3, 7, 2 },
+ { 1, 6, -2, -8, -5, -3, 3, -8, 21, 1, 3, 16, -14, -2, -9, -4,
+ 13, -2, 18, 14, 14, 19, -13, 5, -10, 2, -3, 3, 5, 5, 1, -1 },
+ { -1, -5, -6, -2, -11, -7, 5, -4, 5, -1, 0, 3, -3, 2, -19, 18,
+ 16, 4, 14, -22, -2, -11, -22, 1, -1, 11, 1, 2, 11, -10, 7, -12 },
+ { 1, 4, 5, -1, -9, -5, 1, 12, 5, 6, 12, 9, -24, 23, 1, 20,
+ 14, -11, 13, 5, -2, -2, 5, 6, 2, 1, -9, 6, 10, 5, -4, 11 },
+ { -1, -1, 1, 7, -3, -4, 8, -16, 15, -1, -7, 9, -22, -11, -11, 10,
+ 16, 9, -2, 4, 13, 10, 6, 16, 4, 7, 1, -8, -7, -14, -7, 4 },
+ { 1, 3, -6, 0, 15, -9, -4, 0, 4, 6, 12, 9, -6, -5, -22, 17,
+ 7, -11, 15, -5, 1, 3, -19, 0, -15, -3, 16, 5, 5, -7, -11, 12 },
+ { -2, -1, 13, 2, 4, -24, 37, -5, -2, -6, 12, 7, -2, -23, -4, 9,
+ 2, -3, 3, 2, 3, 3, -14, 11, 0, -4, -2, -2, 3, 10, -10, 4 },
+ { 2, 9, 8, -6, -28, 14, 28, -11, 18, -11, 0, 2, -2, 4, -12, 3,
+ 6, 0, 7, -7, -6, 2, 5, -1, -1, -1, 5, 2, 3, 0, -3, 9 },
+ { -7, 14, 5, -10, -3, 7, 4, -5, 7, -8, -7, 4, -12, 14, -16, 25,
+ 3, 0, 1, -5, 12, -10, 0, -10, 0, 12, 12, 17, 12, 10, -1, 0 },
+ { -4, -2, 5, -2, -17, -3, 5, -5, 7, -17, 1, 5, -4, 4, -20, 0,
+ 11, -15, 13, -8, 10, 1, 1, 5, -12, 9, -8, 0, 6, -1, -11, 4 },
+ { -3, 12, 13, -15, -7, -7, 0, 5, 33, 3, 3, -6, -13, -7, -15, 10,
+ 3, 3, 3, -5, 2, 7, -1, 0, -12, 2, 11, -6, -9, 0, 5, 11 },
+ { -8, 5, 10, -7, -14, -4, 13, 0, 18, -3, -6, 7, 1, -6, 0, 21,
+ 8, -7, 10, -8, -3, 17, -9, 0, -5, 1, 4, 8, -3, 11, -5, 0 },
+ { -8, 8, -3, -8, 8, -11, 16, -16, 17, 0, 8, 16, -17, 10, -16, 10,
+ -8, 6, 11, 0, 10, 7, 4, 5, 7, -5, -5, -6, -7, -5, -1, 16 },
+ { -6, 0, 6, 1, -8, -8, 8, -7, -5, -10, -11, 8, -19, 6, -7, 13,
+ 5, -3, 4, -8, 7, -1, -18, 9, 0, -5, 6, 26, 3, 8, 2, 4 },
+ { -2, -2, 23, -2, -20, 2, 7, -7, -6, -15, 3, 9, -19, -2, -10, 7,
+ -2, 7, 9, 11, 0, 4, -4, 6, 9, -2, 4, -3, 4, 3, 2, 8 },
+ { -6, 12, 10, -10, -7, 4, 17, 11, -6, 1, 12, 11, -18, 8, -12, 4,
+ 1, 13, 6, -13, 23, 9, -5, 8, -2, -5, 1, 3, 0, -2, -4, 4 },
+ { 7, 1, 7, -17, -8, 8, -1, -7, 5, -6, 4, -3, -16, 9, -24, 18,
+ -3, 10, 13, -11, -6, -11, -4, 10, 0, 11, 8, 2, 6, -5, -11, 4 },
+ { -4, 1, -5, -10, 0, -3, 9, -2, 4, -1, 1, 5, -41, -10, -7, 4,
+ -3, 3, 1, 0, -12, 4, -3, 0, 2, -1, -2, -5, 3, 2, -7, 5 },
+ { -2, 1, 4, 4, -3, -6, 1, 0, 12, -5, 11, 0, -17, -3, -1, 11,
+ 4, 1, 27, -12, 0, -14, 2, -15, -3, -9, 0, -7, -3, 15, -8, 6 },
+ { -6, 4, 9, 2, 4, 3, 7, -10, 28, 1, -2, 48, 7, 0, -10, 10,
+ 1, -9, 2, -1, 0, 3, -5, 5, -4, -2, 7, 7, 1, 3, 2, 5 },
+ { -3, 3, -1, 3, -9, 0, -1, 3, 2, -6, 39, -14, -12, 5, -19, 21,
+ 7, -6, 4, -1, -4, 0, -4, 1, 0, -9, 1, 10, 0, -2, 0, 7 },
+ { 4, 2, -29, 12, 5, -3, 16, -6, 15, -13, -4, -1, -13, 22, -16, 17,
+ 16, 4, 9, -4, 4, -6, -4, 11, -8, 7, 8, 4, 3, -3, -7, -13 },
+ { 0, 3, 3, -6, -4, 0, 9, 0, 5, 0, 10, 10, 4, -13, -12, 16,
+ 23, -4, -12, -6, -4, 20, 2, 0, -4, 23, 1, 8, 11, -4, -5, 15 },
+ { -6, 4, -15, -9, -1, -19, 12, -30, -17, -4, 1, -13, -13, 4, -3, 26,
+ 5, -25, 11, -14, -6, -13, 0, -7, 9, 2, 8, -1, -8, 1, -8, 13 },
+ { 1, 6, 1, -4, -4, 1, 2, 0, -3, 2, 10, 6, -6, -2, -11, 4,
+ 32, 15, 15, -47, -8, 3, -12, 4, -5, 4, -1, 0, -5, 5, 1, -7 },
+ { 2, -1, 0, 0, -1, -6, 0, -6, 4, -4, 5, 9, -5, 1, -3, 51,
+ 4, -5, 4, -14, -1, -4, -3, 1, -4, -1, 0, 2, -8, 0, 1, 2 },
+ { 0, 4, -2, -7, -2, -9, 6, -8, 11, -3, -6, 3, -11, -8, -12, 8,
+ 11, 5, 19, 3, -24, 19, -14, 11, -5, -18, -8, -12, -5, -4, -1, 4 },
+ { 16, 9, 10, 14, -18, -2, -18, -27, 10, -5, 12, 14, 4, 0, -2, -6,
+ -12, -7, -1, 3, 4, 7, 11, 10, 5, -5, -7, -16, -3, -6, 6, 9 },
+ { 7, 15, -9, 10, -19, 4, -5, -37, -2, -4, 8, 2, 4, -1, 1, 9,
+ -5, -5, -12, 1, -1, -8, 3, -3, 4, 6, 9, 3, 3, -1, 2, 4 },
+ { 13, 17, 3, 9, -7, -7, -15, -17, -8, -13, -4, -8, 19, 2, 16, 25,
+ 7, 15, 2, 16, -5, -6, -10, -9, -7, -6, -2, -7, 7, 2, 4, 5 },
+ { 24, 7, 9, 8, -13, -2, 0, -4, 1, -13, 3, 6, 7, 10, -4, 15,
+ 5, 7, -4, 5, -5, 3, 13, -7, 5, 15, -11, -2, 7, 5, 8, 6 },
+ { 17, 6, -15, 23, -2, -1, -6, -2, 0, -4, 11, -3, 12, 15, 6, -8,
+ -15, 10, -9, 7, -1, -11, 2, -8, -4, 3, 4, -10, 4, 4, 11, 1 },
+ { 21, 12, -3, 6, -8, 8, -11, -8, -5, -5, 3, 7, -1, -5, 12, 15,
+ -10, -11, 3, 15, 8, 4, 2, -15, 0, 14, 1, -8, -1, 3, 10, -7 },
+ { 16, 12, 5, 13, -6, 15, -23, 0, -17, -9, 0, 4, -9, 13, 6, 18,
+ 0, 0, -4, -1, 0, 14, 5, -1, 8, -4, -8, -6, 5, -2, -2, 0 },
+ { 14, 16, -1, 12, -15, -9, -6, -20, 4, 6, 8, 9, 3, 1, -9, -4,
+ -1, -11, 9, 11, -12, 1, -14, -7, 2, -8, 11, 9, -4, 10, 4, -16 },
+ { 13, 10, 3, 7, 0, -8, -33, -6, 4, -4, 19, -2, 14, 6, 5, 7,
+ 6, -3, -1, -10, -10, -9, 4, -3, 5, 9, 2, 2, 10, 9, -2, -3 },
+ { 11, 10, 25, 18, -1, -6, -21, -21, -11, -16, 6, 5, 14, 4, 8, 7,
+ 0, -10, -7, -9, -5, -4, 3, -1, 1, 6, -1, 6, -2, 2, -3, -9 },
+ { 15, 9, 5, 22, -17, 15, -9, 7, 7, -9, 13, 9, 10, -1, 8, -3,
+ -2, 6, 1, 17, 8, -14, 7, -3, 12, 9, 1, 0, 1, -5, 17, -18 },
+ { 25, 19, -17, 12, -4, -10, 1, -13, -19, -7, -3, 9, 6, -2, 3, 1,
+ 4, -2, -11, -14, -1, -7, -5, -9, 7, -1, -3, 4, -5, 1, 0, -1 },
+ { 20, 8, -3, -10, -24, 3, -6, -2, 0, -12, 14, 6, 7, 11, 4, 7,
+ -12, -5, -8, -10, 5, -1, -4, 4, 16, 7, -14, 6, -1, -2, -7, -11 },
+ { 16, 18, 17, 1, -15, -6, -5, -3, -1, -19, 8, -2, 2, 8, 12, -19,
+ -12, 8, 0, -3, -1, -1, 4, -14, 9, -1, -12, -1, -7, 10, -3, 5 },
+ { 18, 12, -7, 7, 0, -3, -13, 0, -1, -4, 9, -2, 6, -1, 0, 1,
+ 15, -21, 1, -8, 25, -19, 13, -9, 2, 12, 5, -7, -3, -1, -3, 1 },
+ { 13, 16, -4, 9, -2, 2, -1, -19, -7, -4, 18, -6, 14, 18, -5, 4,
+ -6, -3, -19, -14, -1, -12, 10, 6, 7, 17, -12, -13, -10, -4, 5, 4 },
+ { 27, 17, 4, 14, -9, -2, -4, -8, 0, -6, 14, -11, -7, 2, -3, -3,
+ -2, -3, -13, 12, 16, 1, -5, -9, -10, -11, -2, 3, -7, 5, 11, -7 },
+ { 7, 17, -16, -2, -14, -28, -7, -8, 15, -10, 7, 15, 8, 17, 13, -1,
+ 4, -7, -12, -11, 0, 0, 2, 3, -3, 7, -6, 6, 1, -16, 1, -2 },
+ { 23, 11, -9, 15, -23, -4, -6, -4, 2, -9, -7, 9, -8, 3, -13, -4,
+ 8, 18, -6, -2, 1, -5, 6, -14, -5, -2, -6, -5, -3, -2, 4, -5 },
+ { 12, 13, 18, 18, -35, 2, 7, -17, 3, -11, 6, 9, -3, -2, 10, -4,
+ 3, 3, -2, -7, 0, 2, -4, 0, -4, 0, -6, 5, 10, 4, -3, -1 },
+ { 19, 11, 1, 20, -14, 4, -9, -13, -2, 11, 0, 17, -1, -1, -1, -1,
+ -5, -8, 0, 5, -1, -8, 5, -1, 3, 2, -12, 21, -2, -24, 5, 7 },
+ { 15, 15, -15, 17, -14, -22, 3, -4, -11, -3, -7, 1, 18, 10, 1, 10,
+ -6, -3, 8, 2, -7, 0, -2, 1, 1, 2, -9, -2, 1, 2, -3, 4 },
+ { 45, 13, 8, 17, -5, 2, -16, 2, 8, -2, 8, -15, 4, 5, -1, 7,
+ -6, -2, -6, 2, -3, 0, 0, -9, -1, 7, 2, 3, -3, -3, -1, 5 },
+ { 1, 18, -8, 18, -12, -10, 3, 4, -22, -12, 20, 8, -3, 9, 2, 10,
+ -10, -3, 9, 3, 6, -3, 10, -1, -3, 2, -2, 4, 2, 3, -3, -18 },
+ { 9, 10, -5, 9, -35, -21, -18, -16, -1, -12, -6, -7, -15, -19, 12, 4,
+ 4, 9, -7, 2, 14, 1, 4, 0, -1, 6, -7, 2, 1, 1, -4, 4 },
+ { 31, 8, -17, 35, -8, 1, -5, -6, -7, -6, 10, -2, -3, 6, 9, 3,
+ -6, -2, 3, 3, 5, -3, 0, 6, 0, 1, -5, -3, -2, -4, -1, 0 },
+ { 18, 4, -8, 7, -8, -15, -1, -16, 12, 18, 3, 19, 2, 4, 8, 8,
+ 0, -5, -8, -12, 10, -5, 0, 1, 0, 4, -3, 16, 11, 11, -2, -6 },
+ { 27, 15, -17, -10, -23, -22, -1, -14, -4, -7, 20, -2, -7, 6, 15, -5,
+ 32, 4, 9, -11, -3, -8, 11, -4, -1, -4, -8, -6, -4, -5, -2, -7 },
+ { 22, 4, -7, 2, -15, -11, -17, -10, 2, 0, 15, 11, 7, 12, -8, 6,
+ -10, -18, -6, -12, 7, 3, 22, 3, -7, 14, -5, -2, -13, -7, -1, -7 },
+ { 18, 13, 9, 24, -4, -19, -9, -11, 13, 8, 2, 4, -1, 8, 14, 10,
+ -12, 0, 0, 5, 10, 5, 4, -1, 5, 1, -1, 11, 2, -4, 0, -9 },
+ { 15, 19, -5, 1, -4, -10, -8, -27, 6, 8, 5, 10, 4, 11, 5, -5,
+ -11, 0, -11, -14, -4, -9, -8, -8, 6, -9, 4, -5, -1, 1, 5, -4 },
+ { 18, 1, -13, 14, -14, 9, -15, -7, 12, 1, 13, -4, -20, 12, 10, 12,
+ -12, 7, 1, -13, 10, -6, 5, -3, 4, 8, 10, -13, -3, -6, 9, -3 },
+ { 19, -14, 5, -8, -6, 2, -5, 5, -3, -1, -28, 11, 18, -6, -4, -2,
+ 11, 14, -43, -42, 9, 2, 20, -23, 6, 32, 0, 5, 0, 6, 9, 5 },
+ { 8, 11, -14, -1, 7, 12, -7, 2, -16, 2, 10, -3, -1, -7, -7, -1,
+ 1, -10, -60, -23, -18, 42, -13, 9, 18, -11, 0, 1, 0, 2, -5, 1 },
+ { -5, -1, 2, 0, 3, -3, 3, -2, -6, 0, -3, -3, 7, 2, 0, -2,
+ -2, 3, -34, -15, 37, 47, 10, 20, 9, 1, 3, -21, -25, -33, -14, 8 },
+ { 5, 6, 2, -2, -2, -2, 6, 5, -5, 7, -3, 1, -5, -13, 9, 3,
+ -17, -19, -2, -79, -12, -7, -8, -6, -2, -2, -1, -1, -7, -13, 6, -1 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1,
+ 0, 3, 4, -87, 6, -11, 16, -9, -1, 8, 0, 5, 0, 1, 2, 1 },
+ { -5, 6, 2, -24, 5, -9, -7, 0, 7, 3, -3, 16, -14, -16, 0, 18,
+ 15, -9, -14, -28, -17, 53, 14, -6, -28, -1, -3, -10, -7, -14, 19, -15 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -3, 0,
+ -13, 0, -53, 3, -22, 63, 19, 16, 1, -11, 0, -3, 0, -3, 0, 1 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1,
+ -1, -6, -43, -43, -2, 65, -13, -4, 9, 1, 1, 2, 1, 0, 0, 1 },
+ { 0, 1, 0, 0, -1, 0, 1, 1, 0, 0, 1, 2, -1, -1, -3, -1,
+ -23, 1, -61, -55, 3, -28, -6, -4, -4, 8, 2, 1, 1, -1, 0, 0 },
+ { 0, 1, -1, 1, -1, 0, -1, 0, 1, -1, 0, 1, -1, 0, -9, -4,
+ -48, -19, -52, -46, 11, -12, 5, -14, 0, -10, 0, 0, -1, -2, -1, 0 },
+ { 0, -3, -1, -4, 2, -1, -7, 3, 1, 3, -1, 1, -3, 0, -7, 0,
+ 3, -7, -61, -51, -4, -21, -16, -21, -11, 14, -7, 8, 3, -5, 1, 2 },
+ { 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, -1, 9, -3,
+ 56, -11, -6, -67, -1, 13, 0, 7, 1, -9, -1, -1, 0, 0, 1, 0 },
+ { 14, 9, -2, 14, -10, -10, 9, -5, 1, -8, -23, 30, 8, -7, 23, 8,
+ 2, 10, -1, -27, -17, 57, 22, 4, -5, 2, -12, -6, 2, -7, -4, -9 },
+ { 1, 5, 12, -2, -2, -3, 2, -3, 6, 0, 4, -2, -8, -6, 0, 16,
+ -15, 29, -55, -29, -24, 29, 3, 10, 6, 13, 10, -5, 21, 11, -14, 5 },
+ { 4, 2, 26, -6, 10, 11, -23, -10, -27, -20, 3, -24, -11, -10, -13, 25,
+ -10, 5, -9, -36, -7, 43, 3, -13, 6, 13, -2, 0, 1, 3, -3, -4 },
+ { -1, 0, -1, 0, 0, 0, 0, -1, 1, 0, -1, 0, 0, 0, -1, 1,
+ -12, 12, -26, -64, -15, 29, 37, -7, -3, -12, -5, 14, 8, -8, -10, -2 },
+ { 19, -4, -11, -16, 8, 14, 5, 19, 3, 22, -11, -21, -1, -6, -11, 11,
+ 10, -24, -23, -40, -8, 20, 17, 5, 13, -6, 3, 14, -20, -8, 3, 28 },
+ { 2, -12, 10, -14, -18, 26, -22, 4, -2, 5, -21, 8, 3, 1, 19, 0,
+ -12, 24, -14, -40, 15, 29, -15, 6, 15, 1, -19, 2, 4, 7, -12, -3 },
+ { 0, 17, 13, 7, -5, -11, 2, -19, 3, 38, -21, -3, -6, -4, 7, 1,
+ 1, -5, -40, -10, -2, 35, 8, 8, -10, -8, -9, 33, 4, 4, 0, -2 },
+ { -2, -12, 7, 29, -24, 2, 16, -1, -7, 16, 10, -2, -2, -2, 13, -2,
+ -37, 15, -22, -40, -11, 33, 10, -1, 8, 10, 6, 8, 9, 0, -12, 2 },
+ { 15, -8, -9, -2, 7, -17, 7, 19, 14, 4, 12, 27, 11, 10, 4, 11,
+ -15, 14, -13, -48, 5, 18, 0, -9, -36, -11, 2, 4, 5, 5, -15, -12 },
+ { -12, 0, 3, 4, 7, -5, 5, -14, -24, -18, -6, -15, -8, -20, 1, -7,
+ -33, -28, -40, -38, -18, -10, -5, 17, -12, 4, 3, -5, 5, -13, 4, -7 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1,
+ -3, -9, -49, -60, -5, 45, -1, 6, 0, 0, 0, 0, 0, 0, 0, 0 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1,
+ -3, -9, -49, -60, -5, 45, -1, 6, 0, 0, 0, 0, 0, 0, 0, 0 },
+ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0,
+ 3, -2, 9, -29, -11, 55, 8, 32, -36, -13, -7, 37, 4, 11, 0, 3 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 4, -1, -39, -4, -30, 63, 28, -17, -6, 10, 7, -14, -9, 11, 9, 7 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
+ 13, -2, -50, -32, 22, 51, 4, 7, 6, 11, -20, -13, 9, -5, 21, -4 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1,
+ -3, -9, -49, -60, -5, 45, -1, 6, 0, 0, 0, 0, 0, 0, 0, 0 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1,
+ -3, -9, -49, -60, -5, 45, -1, 6, 0, 0, 0, 0, 0, 0, 0, 0 },
+ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0,
+ 3, -2, 9, -29, -11, 55, 8, 32, -36, -13, -7, 37, 4, 11, 0, 3 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 4, -1, -39, -4, -30, 63, 28, -17, -6, 10, 7, -14, -9, 11, 9, 7 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
+ 13, -2, -50, -32, 22, 51, 4, 7, 6, 11, -20, -13, 9, -5, 21, -4 },
+ { -8, 2, 1, 22, -31, -6, -25, -3, -3, 1, -15, -11, -2, -3, 4, -13,
+ -9, 15, -18, 37, -7, -37, 12, -13, -11, -25, -10, -11, -22, 7, 16, 7 },
+ { 14, 10, 4, -10, -1, -5, -7, -3, 16, 13, -5, -15, 5, 11, -1, 8,
+ -27, 7, -12, 49, 17, -22, 9, -2, -9, -1, 2, -15, -1, 41, -18, -17 },
+ { -4, -9, -15, -3, 3, 4, 4, 2, 7, -3, -7, -8, -5, 17, -19, -7,
+ 36, -9, -38, 17, 1, -48, 11, -18, -13, -2, -8, 4, -10, -5, 21, 11 },
+ { 15, -13, 4, 2, 1, -5, -2, 1, -10, 7, -1, 3, -6, 0, 11, -11,
+ 8, 20, -17, 51, -17, -41, 2, 15, 4, 8, -2, 16, -32, -1, 17, 6 },
+ { -8, 8, -18, -5, 4, 6, -3, 8, 0, -4, 2, 0, -1, -4, 5, 8,
+ 30, 30, -8, 70, 2, 8, 2, 0, 7, 1, 13, -1, -6, -7, -11, 2 },
+ { -8, -7, 9, -10, -13, 6, -11, -14, 13, 25, -26, 5, 2, -5, -5, 5,
+ -8, 4, 0, 33, 12, -38, -4, 6, 13, 6, 25, 34, -1, 25, -19, -5 },
+ { 18, 3, -17, 4, -8, 7, 20, 1, -1, 5, -5, -2, -8, 8, -35, 15,
+ 24, 43, -5, 51, 5, -12, -3, 1, -2, 3, -3, -3, -9, 8, -9, 2 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+ 2, 10, 24, 76, -2, -22, 11, -1, 4, 33, 4, 1, -1, 1, 2, 0 },
+ { 0, -1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 2, 0,
+ 24, 13, 32, 70, 26, 5, -21, -9, -6, -15, 2, -2, 2, 4, 1, 1 },
+ { 5, -4, -11, 4, -4, 22, 10, -2, 13, -11, -4, -21, -17, 0, -7, 4,
+ 10, -34, 11, 52, 2, -46, -5, 0, 0, -1, 2, 4, -9, 1, 1, -7 },
+ { 0, 1, 1, 0, -1, 0, 1, 0, 1, 1, 0, 1, 0, 0, -3, 1,
+ -8, 9, -1, 64, -13, -61, -3, 3, -5, 10, 1, 3, -1, -1, -1, -1 },
+ { 0, 1, 0, -1, 0, -1, 0, 0, 1, 0, 0, 0, 1, 1, 2, 1,
+ 10, -2, -31, 79, -10, 27, 0, -1, 3, 8, 1, 1, 0, -1, 0, -1 },
+ { 3, 12, 10, 26, -19, 10, -9, 6, -4, -15, 10, 3, -16, 6, 11, -19,
+ 3, 10, 18, 44, 5, -30, 5, -9, 21, 4, 20, 10, 14, -25, 8, -17 },
+ { 0, 0, 0, 1, -1, 0, -1, 0, 1, 0, 1, 1, 0, 0, -6, -2,
+ 8, -8, 13, 69, 26, -19, -25, -17, 16, 6, -12, 22, 2, -6, 9, 5 },
+ { 0, -1, 0, 1, 0, -1, -1, 0, 0, 1, -2, 1, 0, 0, -4, -1,
+ -34, -15, -33, 56, 9, -42, 9, 10, 6, 9, -8, -11, 0, -6, 15, 5 },
+ { 10, 2, -14, -3, -15, -35, -1, 7, -18, 14, 8, -1, -15, -26, 6, -15,
+ -18, 22, 9, 33, 0, -32, -9, 3, -11, 7, 4, -1, 5, 30, 9, 1 },
+ { 4, 15, 0, 6, -5, -11, 9, 6, 6, 6, 14, 2, -1, 10, -24, -25,
+ -2, -4, -1, 37, 2, -29, 14, -9, 22, 17, -2, 33, 10, -25, 11, -11 },
+ { 0, 5, 2, 18, -12, 21, 22, 33, -7, 21, -9, -7, 7, -15, -7, 16,
+ 7, 0, -14, 44, 10, -25, 5, -4, 15, -8, 10, -4, 5, 9, -1, 16 },
+ { 3, 13, 12, 12, 8, 25, -23, 8, -22, -3, -18, -8, 15, 12, 9, 19,
+ 0, 0, -9, 49, -27, -15, -9, -15, 12, -8, -16, -7, 13, 5, 13, 2 },
+ { 12, -6, 7, -2, 20, -9, -14, 12, 13, -5, -17, 22, -8, -4, 2, 7,
+ -13, -2, -15, 43, -5, -30, 27, 4, 10, -27, 5, 27, -10, -10, -18, 0 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+ -1, 10, -18, 70, -2, -52, -1, -7, 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, 10, -18, 70, -2, -52, -1, -7, 0, 0, 0, 0, 0, 0, 0, 0 },
+ { 15, -13, -20, 16, 2, 13, 5, -11, -8, -5, -3, 2, 24, -23, 30, -7,
+ 11, 30, -15, 43, 5, -15, 15, -3, -14, 1, -23, 8, 3, 9, 4, -11 },
+ { 0, -1, 0, 1, 0, -1, -1, 0, 0, 1, -2, 1, 0, 0, -4, -1,
+ -34, -15, -33, 56, 9, -42, 9, 10, 6, 9, -8, -11, 0, -6, 15, 5 },
+ { 10, 2, -14, -3, -15, -35, -1, 7, -18, 14, 8, -1, -15, -26, 6, -15,
+ -18, 22, 9, 33, 0, -32, -9, 3, -11, 7, 4, -1, 5, 30, 9, 1 },
+ { 4, 15, 0, 6, -5, -11, 9, 6, 6, 6, 14, 2, -1, 10, -24, -25,
+ -2, -4, -1, 37, 2, -29, 14, -9, 22, 17, -2, 33, 10, -25, 11, -11 },
+ { 0, 5, 2, 18, -12, 21, 22, 33, -7, 21, -9, -7, 7, -15, -7, 16,
+ 7, 0, -14, 44, 10, -25, 5, -4, 15, -8, 10, -4, 5, 9, -1, 16 },
+ { 3, 13, 12, 12, 8, 25, -23, 8, -22, -3, -18, -8, 15, 12, 9, 19,
+ 0, 0, -9, 49, -27, -15, -9, -15, 12, -8, -16, -7, 13, 5, 13, 2 },
+ { 12, -6, 7, -2, 20, -9, -14, 12, 13, -5, -17, 22, -8, -4, 2, 7,
+ -13, -2, -15, 43, -5, -30, 27, 4, 10, -27, 5, 27, -10, -10, -18, 0 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+ -1, 10, -18, 70, -2, -52, -1, -7, 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, 10, -18, 70, -2, -52, -1, -7, 0, 0, 0, 0, 0, 0, 0, 0 },
+ { 15, -13, -20, 16, 2, 13, 5, -11, -8, -5, -3, 2, 24, -23, 30, -7,
+ 11, 30, -15, 43, 5, -15, 15, -3, -14, 1, -23, 8, 3, 9, 4, -11 },
+ { 16, -18, 7, -4, 31, -15, -9, -13, 20, -12, -6, 0, 12, -6, -2, 4,
+ 3, -3, -1, 0, 1, 3, 3, -2, 1, 6, 4, 0, -3, 2, -5, 1 },
+ { 38, -5, -13, -4, 8, -15, 11, 1, 2, -4, -1, 9, 13, 4, -12, -7,
+ 0, -2, 7, 2, -6, -2, -3, -2, 3, -4, 6, 15, 1, 1, -11, -2 },
+ { 47, -22, 9, -26, 3, -5, 2, -7, 4, -2, 2, -2, 3, 0, 3, -4,
+ 3, -3, 2, -3, 7, -3, -1, 1, 1, -5, 5, 0, 2, -5, -3, -2 },
+ { 14, -16, 2, -6, 7, -2, -7, -4, -4, -7, 14, -3, 7, -19, -14, -17,
+ -29, 6, 26, 16, -5, 13, -4, -1, 21, 14, 1, 3, -6, 0, -7, -1 },
+ { 29, -11, 5, -3, 4, 11, 4, -10, 1, -22, -3, -10, 5, 4, 2, 8,
+ -2, -7, -12, -12, -8, -3, -18, -2, -9, -5, -1, -3, 2, -14, -14, 7 },
+ { 28, -12, 5, 3, 9, -7, 0, -2, 2, 1, 4, 0, -7, -3, -2, 4,
+ 4, 14, 8, -1, -4, 14, -7, 17, -2, -2, -9, 2, 19, -7, 9, -8 },
+ { 31, -18, -22, 8, 15, -5, -10, -15, 1, 10, 6, 7, 6, -8, 2, -1,
+ 12, -3, 3, -1, 1, 5, -6, -4, 0, 1, 7, -10, -2, 4, -3, -4 },
+ { 53, -30, -4, 12, 2, 3, -3, -3, 0, 1, 6, 5, -5, -4, -7, 1,
+ 0, 2, 1, 3, 1, 5, 0, 2, 2, -1, 0, 4, 2, 0, -2, 0 },
+ { 27, -18, -3, -2, 4, -8, 3, -2, -11, 2, 10, -8, -8, -4, 0, -2,
+ 8, 0, 9, 0, -16, 11, 1, -6, 13, -3, -10, -13, -15, 25, 1, 0 },
+ { 35, -5, -1, -8, 23, 11, -14, -3, 2, -2, 8, -6, 17, -2, 7, 0,
+ -2, 10, -17, 13, -2, -2, 11, 11, -14, 2, -2, -3, -8, -1, -12, -5 },
+ { 29, -9, 7, 3, 2, -10, 0, 3, 9, 0, -3, 5, 1, -10, 10, -5,
+ 3, 6, -20, -9, -6, -4, 1, 0, 12, 17, -8, 9, 3, -1, -9, 0 },
+ { 15, -16, 18, -19, 16, -15, 17, -18, 13, -16, 17, -14, 15, -9, 13, -17,
+ 9, -7, 4, -5, 3, -4, -3, 0, -6, 7, -9, 7, -2, 7, -9, 9 },
+ { 21, -10, 7, -2, 12, -7, 13, -17, 11, -2, 20, 3, 5, -11, -6, -6,
+ -15, 0, -9, 5, -11, 7, -1, 7, 8, -10, -9, 3, -5, 9, -8, -2 },
+ { 23, -22, 15, -5, 16, -4, -3, -12, 9, 3, -1, -2, -8, 2, -2, -16,
+ 3, 4, -2, -6, -7, 12, -8, 2, -14, 2, -7, 11, -2, 6, -4, -1 },
+ { 34, -17, -4, 8, 4, -6, 1, 8, 4, 16, 3, 6, 12, -1, -1, -15,
+ 6, 4, -7, -6, 6, 0, 2, 1, -2, 2, 3, 3, -3, -2, 8, -6 },
+ { 18, -18, 2, -2, 10, 1, 18, -23, -3, -10, 0, 4, 20, -19, -3, -4,
+ 2, 8, 6, 1, -3, 1, 1, 3, 5, -1, -11, 3, -7, 5, -1, 1 },
+ { 15, -14, 2, 3, 10, -8, 12, -13, 13, -15, 6, -8, -4, -10, 14, -9,
+ 24, 2, -7, -18, 13, -11, 8, 14, -6, -2, 3, -1, -4, 7, -7, -4 },
+ { 20, -12, 13, 5, -1, -10, 15, -6, 8, -1, -3, -10, 17, 0, -6, -19,
+ 2, -1, 8, -3, -16, 0, -3, 2, -2, 0, 8, -9, 0, 1, -10, -9 },
+ { 32, 0, -9, -5, -1, 5, 13, -11, 8, 3, 11, -11, 0, -8, -2, -14,
+ 7, 10, 6, -5, 1, 10, 2, 12, -10, 4, 4, 6, 4, 0, -7, -10 },
+ { 16, -14, 10, -7, 11, -11, 11, -11, 18, -13, 8, -15, 16, -11, 13, -9,
+ 8, -7, 12, -11, 7, -6, 3, -5, 9, -5, 4, -1, 7, -4, 8, -3 },
+ { 24, -27, -1, 5, 8, -5, 12, 7, 4, -3, 3, -1, -9, -11, -13, -5,
+ 10, 0, -13, 7, 1, -5, 4, -9, 7, -3, 13, 2, -5, -3, -17, -2 },
+ { 23, -19, 15, 1, -10, -18, -12, -6, 8, -3, 12, 0, -12, -10, -4, -4,
+ 8, -10, 4, 2, -2, -8, 13, -3, -2, -6, 2, -3, 5, -2, 2, 11 },
+ { 25, -12, 4, 2, 24, -3, 3, -6, 14, 11, 0, -21, -3, -3, 1, -8,
+ 7, 0, 0, 3, 3, -6, -7, 6, 2, 1, -4, 5, -1, 10, -2, 9 },
+ { 24, -8, -6, 7, 16, -12, 13, -1, 11, -21, 2, -6, 3, -12, 0, 9,
+ 4, 11, -7, 1, 4, 1, -8, 3, 3, -6, 3, 3, 0, -8, 8, 4 },
+ { 25, -21, 13, 14, 13, -18, 4, -3, 0, -5, -4, 5, -3, 0, 4, 12,
+ 7, 3, 5, -5, 2, -2, 3, -10, 2, -9, -15, 6, 1, 7, -5, 1 },
+ { 23, -16, -2, 10, 4, -1, 3, 1, 32, 3, -5, -2, 9, 10, -1, -4,
+ -6, 2, 9, -1, 14, 12, -6, -1, -17, -2, -4, -9, -7, -6, -8, 3 },
+ { 50, -8, 5, 2, -11, 10, 0, 0, 6, -3, 7, 0, -3, -2, -3, 0,
+ 6, -4, 2, -5, -9, 0, 3, 10, 1, -7, -2, -3, -6, -9, 1, -2 },
+ { 28, -17, 0, -2, 2, -9, 1, 5, -4, -1, 0, 0, 19, -27, 5, -12,
+ 7, -14, -3, -6, 10, -2, -4, -2, 4, -5, -2, -7, 1, 7, -9, 4 },
+ { 22, -19, -6, -6, 3, -22, 3, 5, 20, -8, -14, -5, 1, 1, 20, 2,
+ 16, 6, 3, 14, 4, 3, 5, 1, 5, -7, -10, -6, 3, -6, 1, -14 },
+ { 29, -14, -8, 13, 8, -10, -6, 4, 4, -6, 5, -7, 1, 12, 14, 11,
+ -7, 1, 2, -9, -11, -9, 0, 4, -1, 7, 10, 4, 4, 20, -1, -11 },
+ { 18, -9, 4, 1, 7, -29, 12, 1, -1, -9, -2, -1, -2, 2, 9, -8,
+ -13, 5, 4, -13, -4, 2, -5, -7, -6, 14, -10, -34, -3, 1, -3, -13 },
+ { 38, -9, 24, 8, 11, 4, -6, -11, -2, -12, 1, 1, -11, -8, -5, -2,
+ -15, -8, 8, 0, 1, -7, 5, 4, -1, 8, -2, 11, -3, -1, -5, -5 },
+ { -20, 11, -4, 24, -11, 1, 15, 4, 0, -28, -10, -1, 10, 10, -6, 5,
+ -6, 2, 7, -2, 1, -2, -6, -3, -7, 1, 2, 12, -1, 7, 0, -2 },
+ { -9, 10, -23, 27, -4, -17, 20, -6, 14, -17, 5, -1, 5, -9, -7, 5,
+ -6, 4, -2, 9, 0, 8, 0, 1, -3, -3, -5, -8, 5, -2, -2, 12 },
+ { -10, 19, 4, 9, 1, -16, 17, -2, 9, -29, -16, -11, -4, 7, -5, 4,
+ -1, -3, 3, 2, 3, -4, 5, -12, -2, 6, 5, -4, 4, 1, 4, 10 },
+ { -20, 10, -24, 14, -5, 11, 9, 0, 16, -20, 10, -5, -6, -6, -1, 2,
+ -4, 5, -16, 8, -2, 5, 5, -11, 9, -11, 4, -11, -1, -1, 4, 3 },
+ { -9, 11, 3, 19, 24, 4, 5, -14, 30, -17, -4, -2, -17, 7, 2, 3,
+ 1, 3, -7, -4, 2, -3, 1, 4, -1, -1, 3, -12, -2, 3, -3, 10 },
+ { -19, 18, 11, 19, 19, 19, 10, 4, 13, 6, 5, 4, 8, 3, -2, 12,
+ -6, -2, 7, -6, 15, 12, 16, 16, 18, -3, -4, -20, 0, 10, -9, -3 },
+ { -21, 9, 20, 12, 0, -3, 5, -9, 15, -13, 5, -5, -6, 24, 2, 9,
+ -5, 2, -7, 2, 5, 7, -5, 2, 15, 3, 1, -1, -4, -2, 7, 0 },
+ { -18, 16, 13, 15, 2, -10, 14, -11, 4, -11, 5, 12, 12, 20, 8, 30,
+ 2, 11, -9, 7, 0, -3, -16, -5, -6, 5, -4, -21, 0, 5, 6, 1 },
+ { -26, 8, -13, 9, 6, -10, 2, -11, 7, -4, 6, -19, -11, -6, -12, 16,
+ 0, 5, -7, 8, 5, 6, 17, -9, 10, -10, 5, -3, -11, 2, 4, 10 },
+ { -11, 17, -3, 22, -5, 18, 3, 1, 4, -5, 14, -27, 5, -7, -4, -5,
+ -10, 11, 1, 15, 1, 1, -6, -5, 10, -22, -7, -7, -15, 13, -4, 5 },
+ { -17, 14, -7, 13, 3, 0, 13, -6, 9, -14, -22, -1, 1, 19, 14, -3,
+ 4, -13, -13, 2, -4, 8, -2, -2, 13, -12, 13, -12, -7, -5, -3, 6 },
+ { -17, 17, -1, 33, 6, 3, 9, -16, 3, -14, -8, 6, -17, 8, 3, 13,
+ 8, -6, 3, 1, -2, 0, -2, 8, 4, 9, 13, -10, 4, -17, 0, -6 },
+ { -20, 7, 7, 21, 1, -3, 7, -3, -2, -12, 9, -7, 2, -3, 14, 1,
+ -1, -7, 12, -10, 5, -20, 11, -2, 0, -24, -17, 6, 6, -4, 3, -1 },
+ { -8, 10, 6, 7, -1, -6, 28, -6, 10, -33, 1, -20, 0, -12, 10, 1,
+ -6, 8, -3, -1, -10, 8, 5, 0, 10, -2, 8, 16, -5, -3, -7, 4 },
+ { -17, 13, 3, 15, 1, -5, 27, -5, 6, -6, 12, 2, -4, 8, -1, -3,
+ -2, 12, -15, 3, 4, 1, 2, -9, 0, -16, -21, 2, -4, 16, -7, 4 },
+ { -15, 20, 8, 17, 5, -14, 15, -11, 21, -11, 13, -13, 2, -15, -13, 1,
+ -5, 5, 2, 10, -9, 4, -1, 3, 2, -4, 13, -5, 1, -4, 5, -3 },
+ { -21, 8, 2, 16, -1, 2, 15, -16, 13, -12, -12, -7, -8, 2, -7, 11,
+ -8, 5, 2, -7, 16, -4, 1, -7, 3, -15, 6, -5, -8, 2, -8, 5 },
+ { -15, 17, -6, 3, -3, 3, 9, -7, 14, -23, 11, 1, -1, 4, 7, 6,
+ -1, -14, 7, 6, -8, 5, 1, -15, 10, -9, 2, -3, -1, 4, -10, -4 },
+ { -10, 18, 3, 11, 1, 4, 14, -14, 7, -4, 15, -10, 10, -11, 10, -4,
+ 5, -14, 10, 4, 15, -12, 15, -13, 20, -15, 14, -15, 8, -11, 4, -6 },
+ { -7, 23, 2, 20, 7, 8, 19, -5, 9, -16, -8, -17, -5, 1, 5, -6,
+ -8, 1, -6, -4, 10, 6, 6, 2, -11, -4, 0, 2, 4, 7, 9, -4 },
+ { -15, 20, -5, 22, 11, -8, 9, -5, 10, -13, -8, 8, 2, -2, -3, 7,
+ 6, 10, 1, 2, -5, -9, 1, 10, 16, -22, -7, 0, 7, 7, 6, 1 },
+ { -26, 19, -5, 3, 5, 25, 18, -5, 9, -14, -8, -6, -2, -6, 2, 3,
+ -8, -2, -7, 7, -3, 7, 3, 4, -8, 0, 1, -8, -4, -2, -2, 1 },
+ { -20, 14, -10, 6, -3, 7, 8, -32, -2, -7, -2, -10, 16, -12, -9, 15,
+ -2, -5, -6, 2, -7, 5, 9, 1, 6, -7, -1, 0, -2, -4, -7, 3 },
+ { -14, 16, 4, 11, -8, 1, 23, -4, 17, -13, -10, 1, 12, 9, 12, -4,
+ 7, -1, -1, 5, -8, -6, 3, 3, -6, -3, -18, 0, 18, 20, 4, -2 },
+ { -33, 19, -10, 30, 15, 2, -3, -1, -4, -14, 7, -7, -1, 7, -8, 9,
+ -1, -3, -5, 2, 2, 4, 0, 5, 0, 0, 2, 3, 3, -3, -3, 4 },
+ { -6, 20, 0, 5, 17, -10, 18, -17, 9, -16, 4, -13, -6, 2, -14, 14,
+ -28, 9, -12, 25, -4, 7, 7, -8, 6, -6, -2, -10, 2, -11, -1, 2 },
+ { -12, 14, 12, 52, -3, 5, -5, 4, 8, -13, 2, -5, -4, 2, -2, -1,
+ -2, 3, 3, 5, 2, 3, 0, 1, -5, 2, -4, -3, 1, -5, -2, 0 },
+ { -13, 6, 9, 24, 0, 8, 14, -15, 18, -9, -11, -8, 3, 15, -2, -4,
+ -9, 4, -3, 12, 14, -13, 11, -4, 2, -4, 0, -6, -6, -6, -14, -1 },
+ { -10, 28, 3, 12, 9, 3, 11, -28, 6, -11, -7, 4, 0, 7, 8, -9,
+ 0, -6, 0, -16, 4, 7, 4, 4, 7, 3, 4, -7, 0, -3, -10, 6 },
+ { -11, 14, -2, 19, -1, -1, 7, 9, -2, -27, 10, -14, 15, -4, 12, -4,
+ 2, -2, -6, 12, -6, 0, -5, -4, -5, 1, 3, -11, 5, -9, 3, -8 },
+ { -18, 7, 13, 16, -4, 3, 9, -10, 10, -10, -3, -22, -4, -12, 3, -16,
+ 0, -3, -16, 8, -11, 1, 10, -7, 15, 3, 0, -1, -13, 8, 1, 6 },
+ { -20, 10, -10, 10, 8, -1, 6, 0, 16, -12, 9, -10, -1, -5, -4, -13,
+ 13, 16, -8, 12, -2, 14, 18, 13, 0, -16, 2, -5, -5, -5, -4, 3 },
+ { -14, 5, -7, -17, 5, -13, 23, 20, -4, -1, 1, -6, 13, 5, -1, 4,
+ -14, -2, -7, 8, 3, 2, 2, -7, 2, -1, 4, 7, 3, -9, -1, -5 },
+ { -19, 3, -24, -28, -9, -7, 19, 3, 2, 19, 7, 5, -13, 8, -15, -17,
+ 3, -11, 4, 13, 3, 2, -1, -3, -4, -4, 2, 0, -5, -6, 6, 2 },
+ { -17, 18, -30, -20, -2, -3, 1, 15, -1, -11, 6, -4, 11, 11, -4, -5,
+ -10, 0, 0, 1, 3, -7, 8, 2, 5, 1, 5, -5, 1, 6, 4, 1 },
+ { -6, 1, -30, -25, -1, -8, -2, -9, -17, 16, 3, -1, -2, -9, -6, -7,
+ -3, 12, 6, -4, -10, 0, 10, -8, -6, -5, -3, -11, -4, 0, -1, -3 },
+ { -1, -1, -34, -28, 1, -10, 2, 9, 4, 16, 2, 6, 14, 17, 0, 7,
+ -4, 4, 4, 4, 0, 1, -1, -5, 8, 1, -4, 1, -9, -2, 5, 6 },
+ { -11, 14, 1, -31, -7, -24, 9, 7, 6, 5, -13, 1, -1, 3, 4, -1,
+ -2, -8, -6, 3, 5, -4, -6, 7, -2, 5, 3, 3, 0, 0, -5, 2 },
+ { -25, 8, -11, -18, 1, -4, 8, -3, -4, 15, 6, -5, 8, 2, 3, 4,
+ -4, 5, 6, 8, -7, 6, 1, -11, -15, -13, 9, -4, -14, 10, 12, 7 },
+ { -20, 11, -15, -25, 3, 4, 18, 13, -4, -5, -9, -1, -5, -2, -2, -7,
+ 16, 5, -4, -5, -7, -2, -3, -9, 11, -2, 0, -7, -17, -6, -11, 6 },
+ { -11, 18, -5, -20, -15, -3, 9, 11, -20, 12, 5, 5, 11, -3, 7, 1,
+ 10, -6, -3, -3, 3, 3, 14, -7, 10, -17, 9, -11, -2, -6, 7, -12 },
+ { -20, 8, -14, -17, -9, -13, -3, 0, -27, -14, -3, -14, 4, 3, 6, -6,
+ 7, 4, 23, 9, 11, 9, 3, -4, 9, 2, 4, -1, -6, 1, -8, -11 },
+ { -9, 14, 2, -37, -7, 13, 6, -11, -6, 9, 18, -11, -6, 2, 12, 4,
+ -1, 3, 1, -2, -2, 1, -9, -4, -2, -3, 3, 5, -6, 0, -2, -8 },
+ { -29, 8, -1, -13, -2, 8, 23, 2, -10, 7, 13, -6, -5, 11, 13, 0,
+ -10, -13, 11, -12, -10, 6, 4, 6, 4, 3, 6, -5, -9, -2, -1, 3 },
+ { -18, 6, -10, -55, -4, -11, -2, 0, 1, -3, -9, -6, 3, -2, -1, 6,
+ 3, -1, 3, 1, -4, -7, -2, 6, 3, -2, -1, -3, -2, 0, 4, 1 },
+ { -14, 5, 3, -21, -8, -16, -4, -2, -11, 27, 15, -20, 3, 0, 1, 1,
+ 2, -5, -5, 4, 1, -9, 5, -3, 3, 0, -4, -2, -11, -4, -3, 7 },
+ { -17, -1, -9, -17, -8, -18, 12, -13, -9, 13, -3, 3, 3, -3, 1, -2,
+ 0, 16, -9, 6, 12, 9, 5, 11, 2, -15, 1, -4, -16, 7, -4, -12 },
+ { -18, 8, -6, -11, -8, -7, 13, 7, 1, 6, 8, -1, 21, -4, 14, 15,
+ 18, -4, -3, 15, 0, 9, 4, 7, 3, -1, 9, -2, 0, 7, -8, 2 },
+ { -10, 7, -18, -29, 3, 12, 12, 9, 11, 4, -1, -15, 1, -1, 8, -2,
+ -2, 10, -15, -1, 0, 6, 12, -6, -1, 10, -6, -3, -11, -4, 9, -6 },
+ { -14, 14, -9, -21, -12, -2, -1, -7, -5, -10, 5, -8, 0, 6, 9, -11,
+ 11, -3, -5, 3, 8, 15, -2, -4, -22, 4, -6, 12, 2, 13, 6, -7 },
+ { -12, 11, -5, -29, -25, 4, 12, -13, -11, -7, 4, 2, 2, -5, 5, 8,
+ 7, -5, -5, 6, 3, -10, 1, -6, 6, -6, -5, -1, -2, -4, 7, 6 },
+ { -15, 11, -5, -16, 0, -13, 26, -23, -6, -3, 5, -2, -2, 21, -6, -3,
+ -5, -1, 6, -1, 0, -13, 2, -3, -9, -1, -4, -3, 5, -4, 12, -16 },
+ { -9, 9, -1, -17, -3, -6, 12, 6, -18, -2, 11, -14, -6, 3, 14, -12,
+ -11, -5, 14, 2, 5, -8, -4, -11, 2, -5, 16, 6, -7, -4, 8, 13 },
+ { -13, 5, 3, -28, -14, 0, 6, 23, 5, 4, -1, -17, 1, -3, 0, 0,
+ 5, 4, 0, -18, 14, 10, 4, 2, 5, -2, 4, -3, 2, 0, 2, 0 },
+ { -15, 4, -13, -16, -3, -12, -2, 2, 7, 10, 9, 3, 11, 4, 23, 14,
+ 9, 16, 4, 1, -12, -3, 4, -7, -15, -7, -10, -14, -6, -8, -1, -6 },
+ { -7, 10, -5, -10, -3, -13, 16, -1, -12, 7, -3, -12, 2, 13, 13, 2,
+ 17, 15, -13, 1, -5, -2, 3, -1, 1, -3, 6, -3, -12, -16, 7, -7 },
+ { -11, -5, -12, -30, -6, -22, 1, 4, -6, -3, 12, 6, 7, 0, 16, 6,
+ -2, 0, -22, -2, -9, 2, -13, 8, 6, -8, 4, -7, -1, -6, 4, 6 },
+ { -14, 5, 1, -27, -4, 2, 1, 14, -11, -7, -8, -4, 1, 8, 0, -6,
+ -13, 11, -12, -7, -5, 1, 10, 7, 3, -2, 0, 6, -8, 2, 10, -1 },
+ { -10, 10, -25, -13, -20, -4, 19, 3, 13, 5, 5, 7, -8, 2, 4, 2,
+ 3, -1, -1, -9, 14, 10, 9, 14, 3, 3, -6, 0, -5, 4, 1, -1 },
+ { -9, 15, -18, -17, 4, -11, 6, 7, -12, 8, -1, -11, 2, 3, 7, 16,
+ -3, -9, 7, -12, 23, 0, 6, 7, -14, -9, 8, 1, -2, 6, -2, -1 },
+ { -6, 9, -16, -26, -14, -11, 9, -6, 5, -2, 13, 17, 21, 7, 18, -19,
+ 6, -23, -2, -15, -2, 2, -10, -8, 2, 1, -2, 4, -3, -4, -5, -4 },
+ { 0, 6, -5, -28, -17, -32, 2, -10, 11, 3, -5, 9, 10, 3, 11, 11,
+ -3, 12, -2, 2, 4, -6, 9, -4, -4, -4, -4, -9, 2, 0, 2, 4 },
+ { 0, -8, -18, -34, -9, -7, -4, -11, 10, 15, 11, -1, -8, 15, 6, -13,
+ 9, 2, -4, -12, 0, -1, 19, 12, 6, 5, 0, -3, -10, -12, 3, -5 },
+ { -10, 6, -9, -17, -12, -11, 9, -6, 11, 11, 18, -7, 0, 16, 4, 2,
+ -6, 3, -12, -1, 0, 1, -5, -22, -2, -12, 0, 6, 17, 5, 5, 6 },
+ { 12, -5, 7, 1, -5, -2, -1, 2, 2, -4, -3, -3, -3, -2, -29, 11,
+ 5, -13, -73, 24, 12, 4, -14, -10, 5, 1, 0, -11, -7, -7, 7, 3 },
+ { 10, -3, -1, -3, 4, -11, -5, -2, -8, 7, 9, 2, -8, -6, 6, 7,
+ 21, 17, -54, 47, -14, -10, 14, 19, 13, 21, -4, 3, 1, 2, -4, 2 },
+ { -12, 4, -16, -12, 5, -9, -4, 19, -7, -22, -22, -17, 3, 0, -6, 8,
+ 23, -4, -55, -28, 2, -26, 2, 1, 4, 0, -13, 6, 0, 10, -7, -11 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -1,
+ 35, -1, -67, -35, -24, -24, -6, 2, 2, -2, 1, 3, 2, 0, -1, 1 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 5, 0,
+ 41, -4, -73, -15, 18, 4, 17, 8, -1, -16, -1, -2, 1, 0, 0, 0 },
+ { -4, -4, 4, 6, -1, 2, -16, -10, -15, -10, 21, -2, -6, -2, 14, -7,
+ 10, -5, -55, 34, -12, 11, -13, -2, 2, 28, -26, 0, 7, 4, 21, -7 },
+ { 2, 1, 15, -22, 10, -3, 14, -6, -2, 15, -2, -7, 20, 6, -15, -7,
+ 23, 10, -60, 8, -4, 29, -22, 2, -13, 9, -10, 12, -1, -3, 4, 7 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -1, -2, 11, -5,
+ -21, -11, -60, -27, -17, -39, 6, 36, 0, -8, 2, 2, 0, 0, -2, 3 },
+ { 2, -5, 9, -17, -1, 2, -3, -6, 8, 12, 7, -6, -33, -11, -14, -40,
+ 10, 36, -46, 0, -19, 5, 0, -10, 3, 12, -6, -8, 6, -12, -7, 1 },
+ { 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, -1, 0, 1, 0, -2, 0,
+ 4, -2, -87, -3, -2, 2, -2, 20, 2, 6, -1, 6, 0, 0, 2, -1 },
+ { 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, -1, 0, 0, 1,
+ 1, 7, -76, 41, -7, -24, 0, -6, 3, 6, 0, -2, -1, 1, 0, 0 },
+ { 0, -3, 4, 2, 3, 2, 2, 0, 3, -1, 4, 0, -1, 4, -2, -4,
+ -32, -11, -64, -29, -9, -43, 2, -11, -1, -7, 0, -4, -2, -2, -2, 2 },
+ { 10, -20, 3, -3, 13, 13, 0, -4, 2, 7, -8, 7, -2, 2, -20, -20,
+ -19, 3, -47, -18, -16, -6, -15, -42, -17, 14, -6, 8, 12, -10, 11, -12 },
+ { -3, -2, -2, -1, -1, 4, -3, -1, -6, -2, 3, 2, -3, 6, -1, -9,
+ 10, 13, -68, -9, 26, 3, 5, 3, -21, 10, -15, 21, -22, 19, 11, -14 },
+ { 1, 5, 18, -19, -29, -13, -2, 18, -10, 20, 2, 10, -10, 11, 1, 8,
+ -16, -17, -41, 10, -14, -25, 0, -14, -19, 17, 7, -12, 14, -11, 14, 5 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -1, -43, 5,
+ 6, -12, -48, 19, 8, -38, -8, -3, 22, -21, -10, 15, 20, -9, -5, 8 },
+ { 0, 0, 0, 0, -1, 1, -1, 0, 0, 0, 0, 0, 0, 0, 6, -3,
+ 22, -14, -71, -24, -2, -33, 23, 7, -8, 7, -3, 2, -4, 1, -8, -2 },
+ { 1, 0, -1, 2, 0, -2, 0, 0, -1, 0, 4, 0, 26, -1, 10, -11,
+ -17, -32, -58, 14, -14, -11, -2, 15, 2, -8, 12, 10, -9, 13, -33, -14 },
+ { 15, -17, -19, 7, -8, -15, -32, -22, 7, 12, 18, 0, 0, -15, -4, 16,
+ 37, -2, -46, 11, 2, -8, -10, -8, 14, 9, -4, 5, 7, -17, 4, 3 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, 0,
+ -5, 3, -85, 23, -9, -17, -2, -2, 0, 0, 0, 0, 0, 0, 0, 0 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, 0,
+ -5, 3, -85, 23, -9, -17, -2, -2, 0, 0, 0, 0, 0, 0, 0, 0 },
+ { 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, -1, 0, 0, 1,
+ 1, 7, -76, 41, -7, -24, 0, -6, 3, 6, 0, -2, -1, 1, 0, 0 },
+ { 0, -3, 4, 2, 3, 2, 2, 0, 3, -1, 4, 0, -1, 4, -2, -4,
+ -32, -11, -64, -29, -9, -43, 2, -11, -1, -7, 0, -4, -2, -2, -2, 2 },
+ { 10, -20, 3, -3, 13, 13, 0, -4, 2, 7, -8, 7, -2, 2, -20, -20,
+ -19, 3, -47, -18, -16, -6, -15, -42, -17, 14, -6, 8, 12, -10, 11, -12 },
+ { -3, -2, -2, -1, -1, 4, -3, -1, -6, -2, 3, 2, -3, 6, -1, -9,
+ 10, 13, -68, -9, 26, 3, 5, 3, -21, 10, -15, 21, -22, 19, 11, -14 },
+ { 1, 5, 18, -19, -29, -13, -2, 18, -10, 20, 2, 10, -10, 11, 1, 8,
+ -16, -17, -41, 10, -14, -25, 0, -14, -19, 17, 7, -12, 14, -11, 14, 5 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -1, -43, 5,
+ 6, -12, -48, 19, 8, -38, -8, -3, 22, -21, -10, 15, 20, -9, -5, 8 },
+ { 0, 0, 0, 0, -1, 1, -1, 0, 0, 0, 0, 0, 0, 0, 6, -3,
+ 22, -14, -71, -24, -2, -33, 23, 7, -8, 7, -3, 2, -4, 1, -8, -2 },
+ { 1, 0, -1, 2, 0, -2, 0, 0, -1, 0, 4, 0, 26, -1, 10, -11,
+ -17, -32, -58, 14, -14, -11, -2, 15, 2, -8, 12, 10, -9, 13, -33, -14 },
+ { 15, -17, -19, 7, -8, -15, -32, -22, 7, 12, 18, 0, 0, -15, -4, 16,
+ 37, -2, -46, 11, 2, -8, -10, -8, 14, 9, -4, 5, 7, -17, 4, 3 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, 0,
+ -5, 3, -85, 23, -9, -17, -2, -2, 0, 0, 0, 0, 0, 0, 0, 0 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, 0,
+ -5, 3, -85, 23, -9, -17, -2, -2, 0, 0, 0, 0, 0, 0, 0, 0 },
+ { 16, 65, -2, -2, 4, 3, 0, -7, 3, 1, 3, 1, 0, 5, 1, -5,
+ 0, 2, -1, 3, 0, 0, -1, -2, 6, 0, -2, 0, 0, -1, 1, 1 },
+ { 5, 37, -4, 8, -4, -1, 9, 17, 6, -7, 5, -1, 11, 6, -4, 7,
+ -2, 4, 1, -3, 11, 3, 3, -9, 6, 0, -2, -4, -5, 4, -12, -11 },
+ { 15, 24, -14, 2, 6, 17, 26, 5, 8, 11, -9, -7, -6, -8, 3, -5,
+ 9, 10, -3, 10, 0, 1, 4, -9, 4, 9, 3, 0, 4, 0, -5, 3 },
+ { 9, 36, -9, -8, 7, 7, 4, 3, -1, -16, -2, 7, -5, -6, 6, 12,
+ -11, -12, 9, -1, -3, -9, 12, 6, -6, 2, 2, 5, 0, 5, 6, -6 },
+ { 25, 39, -5, 24, 3, 10, 3, -6, 13, -8, 3, -7, 2, -10, -5, 2,
+ -2, 3, 5, -2, 1, 5, -2, 3, -4, 1, -5, -4, 0, 1, -2, 0 },
+ { 16, 27, -1, 0, -14, 6, 4, -5, 7, -2, -6, 0, -3, -5, 2, -1,
+ -1, -19, 5, -8, 0, 11, 12, 5, 0, 3, 10, 6, -14, 14, -13, -15 },
+ { 12, 23, -14, 2, 1, 4, -3, 16, 7, -8, 2, -8, 8, 6, -8, -7,
+ -3, 0, 2, 8, -13, 7, 13, -6, -4, 6, -13, -16, 14, 11, -7, 5 },
+ { 16, 28, -7, -1, 6, -3, 9, 0, -7, 3, 0, 3, -12, 20, 8, 9,
+ 8, 23, 8, -13, -2, 4, 9, 3, -5, 13, 5, -2, 12, 14, 5, -1 },
+ { 19, 37, 19, 5, 7, 5, 10, 5, 19, 10, 14, 0, 2, 5, 1, -4,
+ -4, 2, 2, -5, -2, -1, 2, -6, -4, -4, -5, -3, 2, -2, -2, -2 },
+ { 24, 21, 1, -11, -10, 17, -14, 14, 6, -1, -6, -1, 0, -13, -1, -12,
+ -2, -5, 6, -4, -12, 14, 5, -2, -8, -8, 15, -7, -30, -12, 4, 0 },
+ { 11, 26, -3, 3, 5, -1, -2, 3, -2, 10, 15, -4, 10, -28, 10, -17,
+ -8, 1, 2, -7, -1, -6, -15, -1, 4, 5, -7, 9, 0, -5, -4, 4 },
+ { 18, 32, 1, 2, -7, 4, 15, 2, -9, -2, 12, -11, 7, 11, 13, 2,
+ 0, 5, 9, -10, 16, 3, -3, 5, -9, -23, 2, -2, -1, 5, 2, 11 },
+ { 35, 24, -20, 2, 4, -1, 5, 14, -10, -9, 8, -7, 0, 5, -7, -7,
+ 11, 1, 5, 3, 2, 0, -2, 3, 0, 1, 4, 0, -2, -8, 0, -4 },
+ { 9, 35, -1, 2, -1, -19, -3, 12, -1, 8, 8, -13, -1, -2, 2, 5,
+ -8, -1, 13, -2, 11, 1, 0, -10, 0, -3, -7, 2, 1, -12, 3, 12 },
+ { 20, 27, -12, -12, 7, 4, -1, -13, -1, -9, 2, 13, -11, 5, 7, -9,
+ 9, 1, 1, 8, -9, 0, -6, 7, 4, 2, -2, 7, 3, -2, 1, -9 },
+ { 8, 37, -20, -5, 0, -21, 10, -8, 3, 19, -9, 7, -3, -8, 10, -2,
+ 0, 5, 6, -4, -2, -1, 0, -7, 6, 1, 0, 4, -5, 6, -8, 2 },
+ { 8, 27, 1, -3, -5, 1, 6, 0, 15, 2, 17, -1, 3, -17, 10, 5,
+ 5, -6, -6, 6, -10, 18, -5, 0, 0, 13, 7, 10, -5, -6, -2, -4 },
+ { 14, 29, -20, -4, -3, 1, -5, -1, 2, 12, -10, -3, 4, -18, 4, 14,
+ -4, -1, -9, 15, -2, 2, -5, -3, 2, 9, -2, -14, -3, 4, -4, -7 },
+ { 23, 23, -23, -11, 27, 4, 4, -1, 7, 0, -5, 9, 2, -11, 3, 7,
+ -2, -5, 2, -7, -7, 13, -3, -6, 2, 3, 3, -4, -1, -8, 5, -2 },
+ { 16, 26, -6, 8, -9, -1, -2, -1, -8, 4, -2, 0, -12, 9, -1, 0,
+ -17, -9, 30, -5, -15, -16, -13, 0, 10, -11, -7, -3, -1, 0, -11, -2 },
+ { 12, 32, -4, -5, 10, 19, -10, 4, -12, 5, -6, 9, -12, -6, -6, -8,
+ 4, 1, 3, 0, 8, 0, -3, -4, -7, -4, 10, 8, 6, 5, -1, 4 },
+ { 46, 42, -3, -14, -2, -6, 6, -2, -5, -1, -3, -3, 1, -1, 3, 1,
+ 1, 4, -1, 2, 3, 1, -2, 6, 0, -1, -2, 4, -2, -1, 2, 2 },
+ { 9, 33, -13, 4, -11, 3, -8, 22, 12, -2, 4, 0, -16, 5, 4, -1,
+ 7, -6, -9, 1, 7, 5, 0, -5, 5, -1, 10, 3, -2, -1, 3, -2 },
+ { 9, 30, 6, -3, 6, 1, -7, 5, 11, 14, 7, 1, 0, 2, 2, -1,
+ 8, 7, -6, -13, -10, -2, 1, -6, 10, 7, 6, 5, -2, -5, -1, -16 },
+ { 9, 28, -11, -10, 9, -10, 15, 8, 4, 9, -4, -7, 0, -5, 9, 8,
+ -7, 2, -15, -23, 4, -4, 4, 16, -8, -3, 0, -8, 14, 5, -3, 15 },
+ { 17, 26, -5, -5, -1, -8, 20, 18, -7, -2, 4, -7, -8, -5, -4, 16,
+ 0, 0, -7, -2, -13, -5, -2, 3, 12, 1, 3, -5, 2, 2, 0, -1 },
+ { 11, 37, 7, -23, 6, -1, 15, 13, 4, -9, 7, 5, 3, -3, -5, -8,
+ -2, 3, -5, -1, -8, 7, 2, 13, 1, 3, 0, -3, -1, 2, 0, -2 },
+ { 21, 33, 7, 20, 21, -10, 6, -5, -5, -6, -9, 2, 10, 0, 8, -4,
+ 10, 2, -2, -2, 0, -10, -6, -2, 0, -5, 3, -11, 3, -9, -3, 1 },
+ { 6, 30, -15, -8, 16, 1, 4, 6, 4, 5, 8, -3, 8, -9, -1, -6,
+ 8, 2, -2, 4, -2, 5, 11, -21, 3, -10, 16, -11, 24, 10, 14, -6 },
+ { 15, 36, -3, -9, -20, 12, 0, -7, -18, -4, -8, -9, 9, -7, -3, -1,
+ 2, 7, -5, -8, 6, 2, 2, -1, 7, 1, 1, -3, 3, -4, -8, 1 },
+ { 16, 34, 21, 3, -9, 10, 7, 9, -7, 1, -4, -9, -4, -5, -5, 3,
+ 3, -19, 1, 5, 4, -2, -6, -5, -10, -11, -8, -2, 2, -5, -8, -7 },
+ { 28, 29, -3, 18, -2, 0, -6, 12, -2, 10, -11, -4, -13, -12, -6, -4,
+ 0, 4, -1, -8, 6, 4, 12, 11, 10, 10, -3, -6, 1, 2, 1, 7 },
+ { 3, 8, 22, -8, 3, 36, -8, -1, 9, 6, -13, -14, 8, -1, 1, 2,
+ -2, -8, 0, 3, 1, 2, -1, 5, -1, -8, 0, -2, 2, 2, -1, 1 },
+ { 0, 6, 0, 0, 4, 13, -7, -16, -6, 15, -14, -21, -9, -10, -10, -6,
+ -21, 5, 4, 2, 12, 4, 12, 11, -4, -6, -6, -10, -7, -18, 1, 4 },
+ { -1, 3, 10, 1, -1, 15, 4, -7, -16, 3, 0, -22, 10, 2, -3, -2,
+ 13, 5, -8, 16, -5, 4, 0, -11, -10, -22, 0, -4, -17, 5, 2, 1 },
+ { 12, 8, -4, -9, 14, 40, -21, 0, 1, -15, -10, -12, 12, 6, -10, 2,
+ 8, 6, -12, -10, -11, 1, 0, -11, 2, 1, 13, 0, 6, 3, 8, 4 },
+ { -10, 3, 5, -4, -3, 3, 0, -9, 2, 8, -22, -23, 17, 8, -17, -3,
+ 14, -8, -4, 1, -8, 3, 0, 5, -1, -3, -2, -4, 1, -10, 0, -2 },
+ { 0, -1, 5, -7, 4, 12, -2, 0, -7, 2, -16, -15, 12, 21, -7, -4,
+ 7, -7, -11, -15, -7, -9, -5, -8, 0, -6, 8, -3, -8, 22, -7, -9 },
+ { 7, 19, 4, -9, 24, 22, 2, -6, 8, 13, -14, -20, -4, 11, 8, -4,
+ -1, 2, 0, -7, 5, -17, -3, 3, -6, 5, 3, 4, -5, -7, -3, 14 },
+ { -2, 6, 2, 8, -2, 5, -4, -2, -10, 3, -45, -30, -3, -3, -12, -4,
+ -3, -3, -1, 9, -6, -6, 5, -4, 0, 5, -1, -2, -1, 0, -6, -1 },
+ { -3, 14, -16, -10, 10, 0, -2, -40, -9, 12, 2, -19, 15, -4, 4, 3,
+ 3, -4, 7, 1, -4, -5, 0, 4, -1, 0, -9, -2, -4, -1, -2, 0 },
+ { 7, 16, 2, -7, 8, 2, 0, 1, 5, 21, -10, -26, 7, 2, -9, -7,
+ -3, -16, 8, 5, 5, -6, 10, 4, -14, -6, 5, 3, -2, -2, -4, 1 },
+ { -9, 14, -1, 3, 3, 11, 1, -5, -3, 13, -16, -18, 20, 6, -5, 0,
+ -3, 2, 8, 4, -19, -9, 12, 0, -8, 2, 2, 1, 6, 13, -7, -11 },
+ { 2, 5, 16, -4, 19, 15, 4, 0, -11, 7, -10, -10, -16, 18, -11, -12,
+ -9, -4, 7, -4, -4, -17, 1, 1, -8, -3, -3, 5, -2, -6, -11, -5 },
+ { 2, 12, 0, -9, -10, 14, 6, 2, -3, 2, -12, -28, 12, 1, -1, 2,
+ 0, -3, -4, 7, 16, 5, -7, 8, -4, -3, -1, 3, -12, 4, -17, -5 },
+ { -4, 7, 11, 6, 1, 14, -4, -6, 5, 5, -6, -24, 23, -9, -15, 13,
+ -7, -9, -15, 10, -1, 8, -5, 1, 12, 6, 2, 0, 4, -2, 9, -10 },
+ { 1, 5, 11, 3, 6, 12, -3, 8, -21, 5, -7, -20, 12, -2, -9, -3,
+ 17, -7, -8, -9, -14, 3, -13, 18, -8, 9, 2, -8, 4, -8, -5, -2 },
+ { -3, -3, -1, 5, -2, 15, 3, 2, 1, -8, 1, -39, -6, 13, -13, 0,
+ -2, -5, -6, -3, 0, -5, -2, 15, -9, 5, -3, -6, -2, 7, 0, -13 },
+ { 2, 8, 5, -12, -13, 22, 8, -16, 11, 5, -2, -32, -2, -4, 11, 5,
+ 5, -6, 1, 3, 1, 5, 3, 6, -5, 4, 4, -8, 8, 4, 1, 3 },
+ { 13, 9, 5, -4, 9, 18, -11, 2, -1, 15, -10, -19, -2, 14, 0, -10,
+ 1, 1, -18, 3, 2, -6, -8, 20, 7, -8, 16, 9, 9, -13, -3, -2 },
+ { -13, 11, 11, -9, -10, 13, -3, -18, 2, 10, 5, -21, 6, 15, -11, -21,
+ 3, 14, 0, -12, 9, -1, -2, -4, 3, -3, -9, -8, -5, -2, -8, 2 },
+ { 3, 3, 11, 4, 0, 13, 1, -8, 10, 13, -6, -26, 2, 12, -3, -5,
+ 12, -2, 1, 8, -7, -17, -19, 5, 10, 7, -3, 2, -3, 0, 5, 0 },
+ { 5, 0, 3, -3, -9, 5, -15, -5, -5, 17, -5, -31, 0, 13, 13, 5,
+ -1, -6, -14, 7, -8, 9, -14, -2, -16, -4, -4, -6, 6, -6, -10, 6 },
+ { 13, 3, 1, 7, -3, 4, -1, -2, -1, 4, -8, -32, -1, -4, 0, 3,
+ -10, 7, 10, -10, 4, -1, 6, 2, -16, -9, 4, 3, 13, -23, -3, -4 },
+ { 4, 11, -4, -9, 4, 11, -12, -12, -12, 6, 1, -28, -3, 14, 18, -2,
+ -12, 7, 15, -3, -5, -7, -3, 2, -6, 4, 4, -2, -5, -3, 2, -13 },
+ { 8, 7, -7, 0, 13, 7, -8, -7, 8, 36, -10, -22, 3, 23, -3, -10,
+ -3, 11, 1, -7, 3, 3, -1, -7, -4, 2, 3, 2, 5, 3, -4, -1 },
+ { -1, 1, 13, 1, -6, -1, -6, -9, -18, 17, -5, -37, -1, -1, -6, -4,
+ 1, -6, -15, 2, 17, -9, 0, -3, 0, 4, 0, -5, 0, 4, 1, -5 },
+ { 0, 14, 5, 0, -7, 2, -6, 17, -6, -9, 7, -16, -5, 23, -14, -13,
+ 8, -15, 11, 10, -11, -13, -33, -5, -2, 1, 6, 8, 0, -13, -9, 5 },
+ { 11, 7, -2, -8, 9, 11, 25, -14, 7, 3, -1, -33, 14, 8, -6, -19,
+ 3, 3, 2, -1, -3, -1, -2, -10, -3, 1, 2, 1, 4, 2, -3, 4 },
+ { -2, 8, 4, -2, 9, 13, -4, -2, -15, -3, 19, -37, 9, 25, -9, 2,
+ -5, -2, -2, -4, 4, 2, 2, 0, 3, 3, 3, 5, -2, -3, -4, -3 },
+ { 10, 13, -1, -15, 4, 6, -18, -4, 25, 1, -23, -17, 15, 13, -8, -8,
+ 7, 4, -5, 3, 6, 9, -7, 6, 0, -5, 8, 0, -6, -1, -2, -2 },
+ { 1, 3, 9, -5, 27, 15, -9, -31, -1, 23, -2, -9, 1, 8, -1, -7,
+ -2, -8, -4, -4, -2, -1, 3, 5, 0, 0, -1, 1, -7, 7, -3, -3 },
+ { -8, 7, 3, -6, 8, 3, -11, -2, 36, 14, 1, -30, 6, 10, -12, -6,
+ -6, -2, -4, -3, -5, 0, 9, 4, -5, -5, -8, 12, 4, -3, 1, -8 },
+ { -2, 9, 33, 0, 12, -3, -7, -4, -4, -1, 6, -25, 11, -6, -9, -11,
+ -2, -4, -2, 6, -1, -3, -6, 15, -6, 3, 10, -4, 1, 0, 5, 8 },
+ { -22, -21, -9, -19, -5, -7, -12, -15, -8, 9, -19, 14, -7, -4, 5, -8,
+ -2, 7, 1, -3, 4, -4, 6, 11, 2, 6, -3, -5, 2, -2, 0, -3 },
+ { -32, -13, 3, -24, 3, -8, 4, 1, -10, 14, -15, 0, 4, 6, -1, 6,
+ 7, -1, 6, 4, -3, -17, 1, 4, -6, -1, 1, 0, 3, 3, -7, -4 },
+ { -32, -11, 7, -8, -12, 13, -5, -22, -4, 12, -16, 2, 0, 4, 0, 1,
+ 0, 6, -5, -8, 2, 6, 5, 0, -3, -6, 5, 6, 5, 5, 13, -4 },
+ { -44, -33, 6, -4, 2, 0, -9, 10, 3, 4, 7, 0, -1, 7, 5, 1,
+ 1, -3, 1, 6, -1, 0, 2, 3, -4, 0, 0, 1, 0, -1, -2, -1 },
+ { -30, -18, -24, -8, 5, 0, -2, 14, 7, 0, 1, 12, 6, 4, -9, 7,
+ 5, 7, -11, -5, 1, -8, -1, 2, 2, -9, 7, -1, 7, 5, 6, 6 },
+ { -22, -20, -13, -9, 20, -3, 10, -8, 6, -4, 2, -7, 10, 8, 0, -1,
+ 2, -3, 6, -19, 2, 4, 3, 3, -7, 2, -1, -6, 1, 1, 6, -2 },
+ { -27, -8, -1, 3, -1, -11, 24, 4, -1, 1, -8, 8, 5, -11, 15, -3,
+ -15, -1, -1, -13, -1, 1, -5, 5, 2, 3, -9, 0, 4, 3, -7, 6 },
+ { -33, -16, -1, -8, 10, -23, 6, 13, -1, -3, -9, 0, 5, -7, -5, -12,
+ -2, 3, 3, 6, -2, -3, 2, -3, 9, -6, -3, -2, 0, 5, -3, -4 },
+ { -22, -17, 11, -3, 3, 1, -1, -5, 17, 2, -15, -2, 10, -9, 6, 14,
+ -16, -12, 20, -1, -7, 6, -3, -12, 1, 10, -10, -1, 7, -3, -1, 10 },
+ { -28, -13, 1, -3, -1, -1, 0, 3, 3, 5, 1, 10, -10, -3, 7, 2,
+ 4, 19, -1, -1, 10, 5, -8, 1, 11, -15, -4, -3, -5, 4, -13, 3 },
+ { -22, -13, 42, -20, 5, -13, 7, -11, 1, 1, -1, 1, 6, 3, 6, -11,
+ 3, 3, -2, 0, -4, 4, -3, -1, -5, 2, 0, 0, -9, -1, 4, 4 },
+ { -26, -15, -2, -6, -4, -2, 16, 8, 21, 8, 1, -3, -10, 7, -8, -12,
+ -5, 12, -9, 3, -2, -3, 18, 1, -12, -15, -4, 5, -3, 0, 12, 7 },
+ { -26, -16, 5, 6, 14, -3, 15, 6, 1, -7, -13, 16, -15, 5, 11, -2,
+ 9, -7, -4, -2, 0, 0, -2, 7, -8, -6, -5, 2, 7, -3, 2, 12 },
+ { -31, -17, -8, -30, 4, 14, 6, -6, 6, -11, 0, 3, -4, 0, 0, -4,
+ 0, -4, 1, 4, 3, 4, 0, -5, 3, 2, 2, 0, 2, 1, 3, 5 },
+ { -61, -10, 4, 10, 4, 7, 0, -3, 0, 1, 0, -3, 0, 1, 0, -2,
+ -1, 1, 2, -2, 4, -3, 1, 1, -1, 1, -2, -4, -4, 4, 0, 0 },
+ { -28, -13, -8, -4, 3, -3, 2, 1, 11, 14, 3, 9, 1, 13, 3, 5,
+ -3, -2, -2, -12, -14, -9, -11, -15, -12, -5, -4, -12, 3, -3, 0, -5 },
+ { -41, 0, 12, -24, 13, 4, 5, 16, -5, -4, 0, 0, 13, -4, 1, -9,
+ 9, -6, -1, 6, -2, 5, 2, 9, 6, -9, -8, 8, -2, -3, -6, -4 },
+ { -26, -19, -2, -15, 4, -14, 6, 0, 26, 20, 8, 9, 9, 3, -4, -5,
+ -8, 1, 0, -1, 5, 9, 3, 4, 4, 7, 1, 3, -2, -2, -10, 0 },
+ { -29, -18, 9, -4, 1, -5, -14, -12, 5, -10, -5, 4, -5, 0, -1, -1,
+ 4, -5, 7, -16, -11, 2, 7, -15, 2, -4, 6, -4, -6, 7, -3, 7 },
+ { -27, -16, 9, -14, 3, -8, 9, 0, 7, -4, -3, -7, 0, -10, -1, 2,
+ 1, -2, 15, -10, 14, 7, 6, 17, 3, -4, 3, -10, 8, -8, 3, 11 },
+ { -21, -20, -8, -8, 4, 5, -3, -2, 0, -5, 14, -10, 11, -4, 13, 0,
+ 5, -11, 19, -18, 18, 3, -5, -3, -4, -8, 11, -10, 10, 3, 4, -9 },
+ { -35, -15, 13, -12, 4, 0, -2, -4, -12, -3, -8, -24, -7, 1, 7, 8,
+ -3, 0, -2, -1, 3, -2, -2, -6, 8, 1, 0, 1, -6, -1, 2, -6 },
+ { -19, -14, 13, -10, 9, -1, 1, 3, -12, 5, -16, 7, 13, 9, 4, -4,
+ 6, -5, 4, 9, -3, 17, -4, 12, -11, -6, -5, -6, 13, 2, 7, -9 },
+ { -34, -8, -4, 1, 2, -1, 3, 6, -20, -11, 8, -1, 4, 2, -9, 4,
+ -4, -5, 16, 10, -4, 14, -13, 1, -6, 0, 2, -10, 0, -3, -3, 7 },
+ { -36, -10, -8, -3, 2, -2, 14, -4, -1, -7, -4, 10, -1, -3, 15, -11,
+ 0, 2, 3, -1, 4, 0, 8, -1, 0, 18, -11, -5, 15, -5, 13, -12 },
+ { -22, -13, 14, -20, 15, 25, 16, 10, 8, -2, -10, -5, -1, -8, 11, 8,
+ -1, -2, -4, 1, 2, -1, -7, 0, 0, 0, -3, 0, 2, -1, 0, 2 },
+ { -31, -22, 7, 6, -2, 5, -20, 14, -6, 7, 0, 14, 3, -7, 3, -6,
+ -2, 1, -3, -5, 1, -10, 1, -24, 6, -2, 3, -7, 1, -7, 8, 7 },
+ { -25, -20, -3, -9, 10, 6, 12, 7, 5, 4, -3, 6, -1, -5, -6, -8,
+ 3, 5, 6, 5, -10, 10, -4, -15, -15, -2, -9, 2, 18, 1, 8, 12 },
+ { -24, -19, -2, -4, -7, 11, 6, 9, 16, 2, -7, 18, 6, -7, 6, 6,
+ -2, -9, 3, 12, -2, 3, -1, 6, 7, 8, 0, 8, -11, 8, 4, 2 },
+ { -26, -20, -12, -12, -2, -3, 1, -5, -1, -2, 0, 3, 7, 9, -2, 2,
+ 9, 22, 13, 4, -4, -1, -2, -14, 5, 15, -8, -5, -7, -11, -14, -6 },
+ { -21, -18, -1, -4, 0, 3, 7, -2, 10, 8, -8, -1, 15, 1, -9, 3,
+ 1, 3, -5, -2, 2, 4, 0, -1, 10, 2, -19, -8, 8, 30, -7, 8 },
+ { -25, -6, 26, 4, -8, 4, -2, 21, 5, -4, -16, 5, 13, 4, -10, -1,
+ -6, -2, 2, -10, -13, 1, 3, -3, -6, -8, 2, 11, 1, -7, 0, 5 },
+ { 0, -1, -2, 19, -12, -48, -6, 11, 8, -2, -4, -2, -7, 5, -3, 2,
+ -2, -1, -1, -7, 0, -3, -3, -4, -4, 4, 1, 3, -3, -1, -2, -5 },
+ { -11, -8, -28, 18, 16, -24, -8, 19, 4, 8, -12, 9, -4, -2, 4, -7,
+ 6, 2, 3, 3, -4, 0, 1, -6, -4, -2, 2, 6, 0, -3, 1, -16 },
+ { -9, -5, -26, 7, -3, -37, -16, -2, 2, -7, 4, -13, 0, -4, -6, -5,
+ -6, -4, 0, 3, 4, -3, -4, -4, 4, -3, 9, -4, -2, 2, 7, -4 },
+ { 2, 9, -18, 7, 29, -24, -1, 7, 14, 10, 3, -3, -2, -5, 6, -10,
+ -6, -3, -8, 0, 5, 1, 4, 3, -12, 2, 6, 1, 3, 4, 1, -3 },
+ { -20, 2, 8, 20, -9, -24, -4, 18, 3, 11, -1, -11, 6, 9, -1, -3,
+ 1, -1, -15, 3, 15, 9, 3, 2, -13, 2, -8, 8, 1, -1, 1, -8 },
+ { -12, 5, -11, 6, 19, -26, -17, -6, 4, 14, 6, -8, 9, 5, -6, -5,
+ 2, -1, 20, 1, -11, -10, -18, 20, -7, 0, -3, 4, 2, 0, 10, 4 },
+ { -15, 1, -2, 13, -8, -21, -22, 4, 4, 3, 3, -7, -31, 4, -10, -14,
+ 0, 8, 4, 5, 8, 11, 2, -8, 6, 7, 0, -2, 6, 8, 8, 7 },
+ { -13, -10, -9, 12, 19, -16, -3, -2, 9, 2, 11, -29, -1, 9, 4, -3,
+ 1, -10, -10, 16, 1, 7, -7, -6, -4, -1, -5, 3, 6, 0, 3, 1 },
+ { -17, -1, -5, 19, 12, -9, -21, -5, 2, 12, -7, -7, -3, 8, 7, -2,
+ 6, -9, -9, 1, -4, 1, 1, 3, -14, 2, -8, 0, 10, 1, -12, -6 },
+ { -13, -5, 8, 15, 0, -20, -2, 20, 8, -8, 8, -19, 12, 10, 2, -11,
+ 0, 12, 1, -11, 0, -11, -15, 5, -11, 2, 4, -4, -11, 5, -4, -5 },
+ { 3, -11, -7, 8, 0, -17, -26, 15, 19, -7, 10, -9, -5, -5, 14, -25,
+ 0, -8, 2, -9, -3, 9, 1, -6, 4, -4, 3, -9, -1, 6, 2, 2 },
+ { -12, 5, 5, 9, 14, -18, -19, 4, 2, 16, 14, -21, -15, -9, -1, 16,
+ 12, -11, -10, -5, -7, 4, 15, -8, -5, -1, 1, 14, 13, -7, -1, -4 },
+ { -10, -5, -1, 8, 7, -23, -10, 14, 6, 11, 10, -16, -3, 16, 6, 0,
+ 0, 9, 6, -2, -7, 1, 22, 5, 3, -8, 0, 3, -2, -10, 3, 0 },
+ { -2, -14, 2, 16, 15, -17, -17, 6, 19, 4, -10, -15, -1, 15, 11, -14,
+ -8, 5, 8, 8, -2, -8, -11, 10, 10, -8, -14, 2, 13, 4, -2, -12 },
+ { -10, 3, 6, 4, 19, -23, -19, 1, 4, -9, -30, 3, -6, 18, 0, 2,
+ 0, -11, 0, 3, 7, -2, 8, 5, 2, -3, 6, -9, 1, -4, 7, -6 },
+ { 9, 5, -2, 21, 20, -33, -13, 7, -10, 8, 8, -15, -6, -4, 1, 5,
+ 3, 7, -2, -9, -1, 4, -6, 1, 0, 9, -1, -5, 2, 1, -3, 3 },
+ { -9, -3, 3, 15, -3, -30, -7, -7, -25, 6, 2, -6, 1, 19, 1, -12,
+ 1, -8, -13, 9, 13, 1, 8, 2, 5, 15, -2, 3, -9, 0, -4, 4 },
+ { -6, -12, -17, 25, 22, -13, -10, 9, 2, 11, -7, -16, 4, 6, 1, 0,
+ 0, 18, -4, -5, 4, -2, -1, -5, 0, -4, 6, 1, 6, -1, 7, 0 },
+ { -1, 0, -10, 8, 8, -27, 0, -2, 29, 16, -2, -4, 9, -1, 2, 0,
+ 6, 10, 6, 4, 2, -7, 9, -18, 3, 3, 3, -10, 17, 10, 9, -6 },
+ { -3, -12, -6, 11, 20, -32, 5, 21, 3, -4, -9, 2, -10, 1, 7, -4,
+ 5, 0, 0, -1, -8, -9, -7, 4, -10, 5, 0, 2, -5, 4, 9, 1 },
+ { -5, -1, -5, 1, 2, -19, -13, 1, 6, 12, 2, -16, -17, 11, 10, 13,
+ 16, -12, -11, 3, -6, 0, 6, 4, -3, 1, 8, 2, 5, -11, 3, -14 },
+ { -19, 5, 10, 11, 2, -23, -9, 16, -2, 7, 0, -11, -7, 10, 6, -7,
+ 26, -15, -4, 8, 6, -4, 7, -9, -15, 1, 8, -4, 4, 2, -12, 16 },
+ { -11, 1, 11, -4, 1, -31, -13, -1, 8, 5, 4, -2, 0, 13, 7, -17,
+ 7, -10, -6, 1, 4, -1, 2, -9, -4, 9, 3, 3, -4, -5, 3, 4 },
+ { -3, 1, 10, -1, 0, -15, -22, 4, 40, -11, -4, -3, -14, 9, 11, -1,
+ 9, -1, -6, 6, 3, -6, 0, 0, -12, 7, -2, 0, 9, 3, 1, 3 },
+ { -1, -1, -1, 14, 8, -24, -14, -8, 5, 8, 5, -12, -17, 8, 2, 7,
+ 10, -8, 0, 4, -6, -6, -10, 8, 4, -12, 3, -9, -12, 5, 4, -3 },
+ { -5, 1, -11, 8, 9, -24, 0, 2, 2, 14, -12, -13, 1, 6, 7, 0,
+ 7, -6, 9, 26, 11, -14, 8, 10, 1, 9, 0, 11, -2, 6, 2, -10 },
+ { -13, 1, 4, 34, 19, -17, -15, 0, 3, -2, -7, -1, 0, -3, -3, -1,
+ 1, -1, -10, 8, 5, 0, -8, 4, -17, 9, -2, 0, 0, 6, 2, -3 },
+ { -6, -4, 1, 2, 2, -14, -29, 0, 9, 34, -3, -5, -14, 6, -10, -9,
+ -5, -1, 0, 3, 3, 0, 1, -1, -2, -1, -1, -3, -3, -4, 3, -3 },
+ { -4, 6, 3, 14, 14, -8, -29, 31, 11, 14, -4, -5, -6, 10, 6, -9,
+ -1, -11, -7, 1, 7, 4, 1, -6, 4, 0, 10, -7, -5, -1, 2, 4 },
+ { -4, -4, -2, 14, 6, -32, -6, -14, 14, -5, -11, 10, -18, -4, 6, -8,
+ 9, 5, -4, 1, -4, 5, -2, -9, 3, 5, 2, -10, -6, -17, 3, 17 },
+ { -16, 9, 21, 19, 4, -20, -17, 14, 9, 15, -6, -17, -1, 1, 6, -3,
+ 1, 1, 8, -3, -6, 6, 9, 4, 9, -9, -5, 1, -1, 0, -1, 2 },
+ { -7, -5, 3, 19, 1, -20, -9, 14, 21, -7, -18, -9, 26, -7, -17, -7,
+ 12, 6, 0, -9, -6, 14, 9, -9, -8, 4, 15, -7, -9, -1, 9, 1 },
+ { -20, 30, -6, 11, 24, -4, 0, -6, -2, 8, -4, 12, -8, -17, 0, 5,
+ -4, 1, -1, 3, -3, 5, 3, 3, 7, -2, -3, -2, 4, 0, 0, -1 },
+ { -35, 17, 6, 1, -9, -1, -16, 3, -20, -13, 8, 7, -4, -7, -4, -20,
+ 7, 12, -5, 5, -5, -11, 12, -1, 15, -9, -6, 16, -4, -9, -13, 4 },
+ { -21, 36, -19, 9, 0, -7, -8, 9, -4, -3, 3, 0, 7, -8, -2, -2,
+ -11, 13, -1, 5, -3, 7, 2, 3, -1, -2, -5, 1, -1, -2, -5, -3 },
+ { -12, 33, -4, 1, -12, -9, 0, -13, -1, 2, -8, 4, -10, 6, -16, -7,
+ -1, -4, -10, 15, -1, 0, -5, -8, 5, 5, -3, 0, 2, -7, 1, -7 },
+ { -14, 32, 5, -7, -15, 3, -5, 8, 14, 5, 9, 13, 3, 18, -3, 7,
+ 4, -10, -10, 10, -1, 2, 0, -2, -11, 5, -3, -4, 2, 2, 7, 4 },
+ { -14, 34, 1, 20, -1, -12, 0, -3, -7, -4, 7, 18, 9, -3, 14, -7,
+ -9, -20, -7, -4, -13, 12, 1, 12, 5, -6, 2, -4, 0, -15, 1, 3 },
+ { -21, 23, 7, -8, 3, -13, -3, 0, -6, -2, -7, 6, -12, 9, -6, -2,
+ -2, -4, -1, 6, 9, 5, -9, 15, 0, 8, -8, 7, 6, -15, 3, -5 },
+ { -27, 32, -1, -4, -2, 4, -10, 12, -3, 8, 13, 7, 0, -15, 4, -2,
+ 3, 5, 7, -4, 9, -12, -1, -2, -1, -4, 0, -4, 2, -5, 6, -6 },
+ { -17, 29, 15, 0, -1, -4, -10, 13, 12, -1, -8, -10, -10, 4, 7, -2,
+ 6, -5, -13, 19, 6, 1, -7, 2, -9, -2, 12, -4, -8, -3, 2, 4 },
+ { -38, 27, 16, -15, -6, 3, -7, -4, 0, -1, 6, -2, -3, -6, 6, -6,
+ -3, 0, 2, 0, -4, 6, 1, -1, 0, 4, -1, 3, 4, 1, -2, 5 },
+ { -33, 40, -4, 2, 1, 0, 0, -10, -14, 0, -7, 4, -1, 3, -2, 5,
+ 7, 6, -1, 4, 1, 3, 1, -7, 1, -4, 5, 7, 0, 4, 3, -4 },
+ { -20, 25, 12, -4, 16, -4, 2, 2, -14, -2, -3, 29, -1, 1, 3, 1,
+ 9, -5, 2, -8, -3, 1, -7, -2, -7, 1, 0, 4, 16, -2, -1, -1 },
+ { -10, 30, 17, 3, -5, -2, 0, -5, -22, 4, 5, 5, -3, -18, -6, 10,
+ -5, -7, 2, 8, 7, -7, -11, -2, 0, -3, 3, 2, 11, -4, 4, -4 },
+ { -11, 30, 11, 4, -3, -8, 1, -2, 4, 18, 3, 1, -1, 0, -8, -4,
+ -3, 10, 13, 14, 5, -5, 1, 1, -10, 2, 15, 4, 9, -1, -5, -3 },
+ { -17, 32, 18, -18, -3, -5, 6, 10, 1, -15, -5, 9, 8, -12, -10, -6,
+ 11, 9, -5, -8, -7, 10, 5, -10, -14, -4, -3, 1, 9, -11, 2, 1 },
+ { -13, 28, -11, -1, 2, -16, -2, 7, -24, 0, 3, 6, 3, -1, -8, -7,
+ -12, 2, 2, -20, 10, 4, 0, -13, -2, -2, 1, 8, -14, 0, 4, 1 },
+ { -14, 23, 12, 8, 8, -26, 2, -4, -14, 13, -14, 15, 3, -9, -1, -13,
+ -10, -2, -10, 6, -16, 12, 8, 0, 9, -10, -7, -4, -4, 7, -8, 8 },
+ { -20, 45, 10, -14, 4, 16, 8, -9, 1, -8, 10, 5, -7, -2, 2, -5,
+ -1, 0, -5, 4, -6, -2, 4, 1, 3, 4, -4, 2, -2, -2, 5, 1 },
+ { -20, 26, -4, 1, 7, 4, -8, 1, -5, -13, 2, 13, -7, -3, 6, -6,
+ 22, 0, 5, 11, -4, -11, 8, -9, 2, -2, -4, -2, 2, -13, -4, -8 },
+ { -28, 18, 17, 3, -8, -23, -16, -6, 5, -10, 14, 10, 5, -1, -8, 4,
+ -2, 13, -3, -2, 3, 4, 3, -2, -3, -4, 0, 1, 3, 4, 0, 4 },
+ { -12, 32, -6, -16, 18, 12, -16, 0, 7, 13, -4, 5, -8, -1, -3, 4,
+ 6, -2, -1, -13, 4, -1, 3, 12, -3, -10, 1, 6, 8, -11, -2, 4 },
+ { -18, 26, 2, 5, 0, -9, -17, 14, 5, 1, 7, -3, -8, -3, 11, 7,
+ -5, -12, -8, 7, 0, -7, 2, -12, -9, 13, -11, 9, 6, -11, -5, 11 },
+ { -24, 22, -15, -9, 8, 1, -7, -12, -9, 3, 11, 15, 14, -11, 12, -15,
+ -5, 7, -2, 0, -8, 3, 3, -1, 2, 11, -11, 14, -6, 13, 1, -6 },
+ { -20, 28, 18, -4, -6, -5, 12, 14, 2, 10, -13, -6, -8, -6, -13, -1,
+ -26, 22, -3, -14, 6, 0, 10, -15, -13, -9, 6, -7, 1, -5, -4, -1 },
+ { -19, 26, -8, -3, -14, -6, -9, -4, -8, 15, -8, 3, -12, -4, -2, -7,
+ -5, 3, 13, -3, -4, -25, 4, -1, 5, -12, -1, -13, 5, 2, 0, 6 },
+ { -18, 43, 14, -8, 1, -23, -2, -2, 1, 3, -7, 0, 0, 8, -1, -3,
+ -5, 1, 5, 2, 0, -2, -2, -2, 1, -1, -1, -7, 0, 3, -3, 9 },
+ { -11, 30, 10, -14, 3, 1, 10, -11, 1, -7, -4, 14, 2, 1, -9, 1,
+ -11, -2, -7, 5, -11, 1, 3, 14, 1, -16, -8, 3, -5, 7, -4, 4 },
+ { -18, 24, 6, 3, 8, 7, -22, -7, -7, 3, -8, 4, 23, 9, 3, -1,
+ 3, 6, 7, -1, -7, 6, 4, 1, -3, 1, -6, -1, 2, -7, 3, 3 },
+ { -15, 38, -7, -1, -11, 2, -17, -24, 24, 8, 7, -4, -5, 2, 2, -7,
+ 1, 4, 0, -9, 5, 0, -1, 1, -1, -5, -6, 3, 0, 7, 8, -3 },
+ { -14, 22, 1, -5, 9, -12, -9, -5, -6, 5, 7, 8, -1, -4, -9, -3,
+ -33, -16, -9, -1, 12, -11, 17, -7, -3, -1, -7, 3, 2, -3, 16, -4 },
+ { -14, 20, 6, 4, -10, -4, -4, -4, 1, -7, 2, 6, 8, -12, 4, 1,
+ -1, 12, 10, 3, -14, -10, -3, 18, -2, 33, -5, -17, 17, -5, 9, 7 },
+ { -12, 23, 13, 0, -11, -8, -11, 12, -5, -9, -16, 11, 6, 4, 12, -5,
+ 5, -13, 7, -12, -3, 1, 2, 12, 1, -4, -1, 5, 4, 11, -12, -3 },
+ { 15, 2, 14, 7, 1, 2, 1, 12, 10, 23, 4, 6, -20, -10, 4, 26,
+ -6, 13, 4, 3, 2, -11, 5, -7, -10, 4, 9, 1, 10, -4, 11, 4 },
+ { 17, 15, 31, 17, 18, 16, 11, 24, 2, 4, 2, 3, -8, -3, 7, -3,
+ -5, -7, -2, -6, -4, -5, -4, -1, -4, -2, -5, -6, 2, -1, 4, -2 },
+ { 16, 8, 15, 14, 3, 7, 21, 9, 8, 15, 21, 6, 8, 12, 5, -5,
+ 7, -3, 10, 2, -3, 8, 6, 0, 5, 5, 6, -3, 2, 4, 0, -5 },
+ { 5, -4, 6, 12, 6, 13, 24, 17, -5, 17, -1, -6, -7, -10, -8, -18,
+ 3, -2, 2, 7, -15, -11, 12, -3, -2, -2, -4, -7, 2, 0, 5, 5 },
+ { 10, -6, 8, 11, 12, 20, 22, -11, -3, 15, -3, 15, -2, -2, 0, 2,
+ 5, -8, 4, -5, -9, -4, -1, 2, -1, -3, 1, 3, 13, -1, 9, 7 },
+ { -5, 8, 5, 11, 14, -5, 14, -9, 2, 35, 8, 15, 1, -2, 2, -2,
+ 4, -9, -3, -14, -12, -2, -2, -4, -2, -8, -3, 1, -6, 3, 10, 0 },
+ { 16, 0, -6, 15, -3, 4, 4, 3, 3, 20, 5, -4, 10, 9, -9, -3,
+ -10, -2, -7, 11, -11, -10, 17, -1, 3, -15, 2, 9, -15, -10, 16, 10 },
+ { 14, 4, -7, 19, 3, 0, 19, 8, 16, 34, -9, 6, -13, -1, 6, 5,
+ -1, -2, 4, 3, 2, 1, 1, -1, 0, -7, 2, -1, 1, 0, 6, -1 },
+ { 1, 6, 9, 13, 9, 10, 15, 16, 10, 18, 13, 17, 3, -1, -7, 2,
+ -15, -11, -10, -4, -13, -6, -17, -13, -6, -14, 1, -10, 6, 4, -1, -1 },
+ { 13, 1, 7, 10, 14, 13, -7, 5, 5, 28, 14, 14, -2, 2, 3, -3,
+ -13, -4, 10, -9, 19, -4, -3, 4, -5, -5, 0, 5, -5, 0, 3, -4 },
+ { 1, 0, 6, 22, 9, 18, 18, -3, 5, 10, 12, -2, 1, -3, -8, -12,
+ 9, -10, -7, 1, -1, 19, 0, 2, -8, -11, -10, 9, 6, 11, 0, 3 },
+ { 10, 11, 19, 44, 0, 14, 1, -7, 6, 22, 2, -1, 9, 2, 0, -4,
+ 4, 0, -6, -6, 3, 0, 0, -2, 2, -5, 1, -2, 0, 1, 1, 1 },
+ { 5, 7, 0, 32, 30, 26, 5, 4, -7, -3, 15, -6, 3, -10, 7, 6,
+ -8, -7, 2, -13, -5, -1, -3, 7, 3, -2, -8, 0, 6, 4, 5, 0 },
+ { 9, 8, -2, 4, 2, 11, 4, 29, -5, 14, 8, -5, -14, 8, 0, 9,
+ 8, -10, 5, -15, -6, -9, 9, -1, 18, -16, 9, -21, -3, -13, -2, 8 },
+ { 25, 7, -9, 23, 20, 18, 6, 16, -9, 8, 8, -5, 11, 13, -8, 7,
+ 4, 10, -2, -1, -7, -9, -7, -9, -4, 1, 1, -5, -10, 8, 4, -5 },
+ { 9, 2, 16, 14, -5, 14, 1, 0, -21, 17, -1, 9, 12, -3, -3, 4,
+ -4, 14, 10, 3, 0, -10, 7, 4, 4, -11, 2, 4, -1, -3, 9, -1 },
+ { 17, 8, 11, 26, 15, -3, 14, -1, 12, 9, 10, -8, 8, -18, -11, -3,
+ -14, -7, 7, -3, -3, -4, 1, -7, -3, 2, -3, 16, 10, 0, 9, 6 },
+ { 9, 8, 3, 8, 18, 14, 11, 1, 10, 6, 1, -4, -16, -2, 14, -2,
+ 1, 8, 12, 14, 3, -3, 8, 8, 12, -15, 3, -3, 3, -2, 14, 10 },
+ { 22, -3, -11, 13, -7, 11, 4, 11, 3, 14, 0, -6, -2, -9, 4, 2,
+ -2, 0, -5, -27, -10, 3, -1, 5, 8, -24, -3, -11, -3, 2, 11, -1 },
+ { 19, 2, 8, 36, 5, -6, 3, 15, -3, -4, -5, 14, -10, 1, -12, -10,
+ -3, -4, 3, -2, 1, -8, 4, 3, 5, -3, 0, 4, 8, -2, 8, 4 },
+ { 8, 14, 15, 9, -4, 10, 5, 11, 9, 10, 8, 9, -15, 15, 6, -8,
+ -10, -13, 5, -8, -20, -13, -6, -11, -1, -3, -6, -4, -1, 0, 13, 15 },
+ { -2, -1, 9, 12, 2, 2, 13, 3, -23, 33, 15, 2, -4, -1, 3, 8,
+ 8, 6, 6, -7, 8, 6, 9, -1, 3, -8, 0, -4, 1, -8, 11, -1 },
+ { 6, 5, -6, 16, 2, -3, 31, 21, -9, 12, 0, -1, -4, 1, -12, 3,
+ -13, -18, 2, -11, -9, 2, -8, -6, 11, -3, -1, 0, -1, 0, 13, 5 },
+ { 5, -1, 2, 0, 25, 5, 10, 16, -5, 21, 14, 12, 13, 2, -5, 5,
+ 5, -3, -2, -14, 0, -12, 7, 11, -1, -7, 19, -1, -1, -1, 8, -1 },
+ { 10, 7, 3, 11, 0, 8, 22, 3, 3, 19, -4, 12, 15, 9, 5, 15,
+ 2, 1, 2, -10, -10, 0, 2, -1, 0, 1, -12, -1, 21, 16, 9, -7 },
+ { 11, -4, -5, 24, -7, 11, 20, 11, -15, 18, 5, -13, -15, 0, -5, 9,
+ 1, 0, -1, -9, 4, -8, 6, -8, 1, -2, -7, 20, 9, 3, 9, 3 },
+ { 20, 0, -12, -6, 9, 31, 9, 12, 8, 27, 15, 7, -16, 5, -3, -7,
+ -1, -9, -2, -7, -3, 4, -8, -3, 3, -6, -2, -2, -3, -6, -1, 2 },
+ { 6, -6, 48, 8, -3, 19, 12, 11, -7, 2, 3, 0, -1, 1, 8, -4,
+ 4, -6, 0, -4, -4, -3, 3, 6, 3, -13, -8, 5, -3, -7, 8, 5 },
+ { 7, -2, 6, 11, 12, 2, 14, 4, -5, 12, 2, 9, 4, 2, 0, -1,
+ 2, 0, -15, -9, -16, -2, 8, -17, -5, -22, -19, -5, -1, -10, 1, -2 },
+ { 11, -9, 3, 12, 6, 6, 1, 17, -6, 19, 14, 7, -7, -1, -1, -9,
+ 9, -11, -17, 0, -6, 16, 0, 1, 9, -24, 3, 3, -9, -3, 3, -2 },
+ { 9, 0, 1, 8, 1, 7, 2, -5, -3, 8, -1, 7, 2, 6, -3, -6,
+ 5, -2, 6, -2, -4, -3, 0, -3, 13, -50, 1, -2, 2, 4, 4, 3 },
+ { 7, 0, 26, 21, -4, 2, 17, 8, 7, 11, -7, 1, -1, -15, -1, -15,
+ -11, -4, -17, -4, 1, -7, 3, 6, 3, -9, 2, 3, 6, 10, 6, 12 },
+ { 1, -2, 2, -1, -10, -4, 6, -3, -5, -2, -8, 2, 2, 2, 8, 0,
+ 1, 1, 6, 0, 11, 13, 3, 4, 0, -12, 11, -5, 19, 20, 2, 5 },
+ { 5, 3, -13, -2, 1, -12, 11, -7, -12, 7, 10, 0, 7, 0, -2, 4,
+ -6, -9, -11, -12, -23, 12, 10, -3, 0, 6, 19, -1, 24, 18, 9, 12 },
+ { 6, -3, 2, 5, 2, 2, -2, -5, -8, -11, -4, 3, -8, -4, 5, -3,
+ -16, -4, 3, -12, -4, 3, 32, 7, 2, 8, 32, -18, -1, 12, 1, 7 },
+ { 0, -8, -1, 0, -8, 7, -8, -1, -1, 4, -12, -1, 3, 0, 1, -18,
+ 8, 8, -14, -10, -11, 19, 9, 5, -7, 6, 8, -4, 26, 12, -1, 6 },
+ { 3, 5, -14, 7, 14, 8, 20, -13, -16, -10, -2, 17, -7, 4, -8, -9,
+ 14, -5, 3, -4, -12, 7, 14, -10, -19, -20, 35, 8, 13, 14, -2, 9 },
+ { -2, -4, -1, 1, -3, 0, -1, 1, 2, 2, 6, 0, 0, 4, 5, -2,
+ 3, 3, 3, -2, -7, -3, -3, -1, 6, -2, 29, 22, 13, 34, 0, 14 },
+ { -3, -9, 3, 1, 5, -4, 2, 0, 7, -9, 0, 2, -5, -3, 0, 6,
+ -1, -1, -1, 2, 2, 4, 8, 7, 20, -6, 7, 16, 33, 20, 6, -1 },
+ { -11, 1, -3, -3, -11, 3, -9, -25, -1, -16, 4, -8, 15, 1, -2, 7,
+ 8, 23, 2, 18, -13, 16, 3, -7, 6, 3, 16, -8, 12, 16, 3, 4 },
+ { 0, 5, 5, -5, 1, -1, 2, -3, -2, 1, -13, 2, 2, 10, 6, 7,
+ 18, 18, 7, 9, 8, 9, 21, 14, 7, 12, 15, 14, 15, 12, 11, 5 },
+ { 1, -5, 11, -2, 17, 8, 3, 0, -1, 6, 11, -7, 6, 6, 7, 5,
+ -15, 14, 1, 11, 4, 10, 12, 1, 2, 4, 30, 1, 11, 1, 6, 13 },
+ { 2, 4, 3, -7, 5, 8, -11, 7, -5, 9, -10, 6, 8, -10, -3, 10,
+ 1, -29, -4, -26, 5, -8, 13, 4, 3, 6, 35, 1, 3, 6, 3, 0 },
+ { -2, 1, 0, 0, -1, -3, -7, -3, -9, -3, -1, -6, 3, 4, 4, 0,
+ 5, -1, -2, -2, -1, -4, -10, 8, 0, -6, 10, -4, 46, 12, 2, 28 },
+ { 4, -1, 4, 1, 0, 4, -2, -2, -2, -1, 2, -4, 1, 5, 0, -3,
+ 1, 1, -2, 0, 1, -2, -1, -1, 3, -6, 35, -11, 13, 53, -3, -1 },
+ { -5, -2, 0, -13, -16, 5, -12, -11, 1, -30, 3, -18, -24, -8, -5, -19,
+ 1, -3, -8, 7, -7, -8, 15, -19, 4, 10, 30, 24, 6, 1, -9, 10 },
+ { -4, 8, -7, -4, -6, 12, -1, -9, -4, 2, -9, 3, 2, -2, 4, 2,
+ 22, 9, 4, -5, 0, 5, -2, -9, -3, 1, 18, -12, 18, 16, 4, 16 },
+ { -5, -8, -3, -5, -3, 6, -7, -3, -2, -5, -3, 1, 2, 2, 4, -6,
+ 10, 3, 12, -3, 20, 0, 27, -4, 16, 5, 18, -3, 23, 4, 12, 11 },
+ { 0, 1, 0, 1, -2, 1, 2, 1, -1, 0, -2, 2, -2, -4, 1, -2,
+ -2, -1, -5, -2, 0, 0, -2, 2, 9, 7, 63, 5, 12, -1, 1, 0 },
+ { 4, -3, -7, -5, -11, -5, -12, -10, -10, -12, -15, -12, -14, -14, 1, 1,
+ 10, -10, 16, 6, 2, 9, 11, 9, 9, 8, 12, -1, 13, 12, 6, 3 },
+ { 7, -3, -2, 4, 6, -8, 2, -3, -12, -5, -9, -8, -10, 15, -2, -4,
+ 8, 9, 7, -13, -18, 34, -5, 7, 12, 22, 16, -11, 13, 25, -15, -11 },
+ { -3, -2, 0, -4, 1, 0, -3, -13, -7, 13, 12, -7, -10, 13, 19, 6,
+ 16, 15, -12, -15, -3, 34, 1, 5, 1, -9, 11, 21, 8, 17, -5, -6 },
+ { 3, -5, 0, -4, 0, 4, -11, 4, -7, -3, -1, -8, 3, -2, 2, 1,
+ 11, 5, 6, 14, -3, 2, -4, -7, 0, 31, 15, -2, 24, 11, 5, 4 },
+ { -1, -4, -9, 5, -8, -18, -4, -9, -20, -18, 7, -14, -16, 3, 8, -3,
+ 29, 11, -13, -13, 7, 1, 17, 6, 6, 21, 11, 1, 14, -8, 2, 5 },
+ { -3, 8, -10, -6, 12, 2, 1, 3, 3, 3, 3, -6, -8, -14, 15, -5,
+ 16, 4, 16, 0, 7, -1, 0, 16, 2, 1, 22, 4, 19, 13, -11, 1 },
+ { 2, -3, 10, 20, -4, -1, -8, 5, -8, -9, -6, -2, -4, -7, 8, -10,
+ 0, 8, -6, 1, -8, 14, 13, 5, 17, -6, 26, -1, 7, -1, 0, 12 },
+ { -4, -7, -31, -2, -7, -1, 5, -5, -5, -12, 4, -7, -6, 3, 15, -2,
+ 5, -2, 7, -1, 10, 7, 8, -1, 14, 20, 14, 9, 16, 16, 8, 24 },
+ { -7, 0, -3, -6, 1, 3, -13, -6, -4, -4, -5, -9, -1, -10, -4, -8,
+ 2, 0, -1, 1, 24, 24, 21, 31, 5, 2, 11, 12, 7, 4, 3, 6 },
+ { -3, -5, 6, -4, -3, -1, 2, -1, -2, 1, 0, -8, -1, 2, 0, -4,
+ 6, 22, -1, -5, 8, 12, -1, -2, 28, 27, 20, -27, 14, 1, 2, -3 },
+ { 1, -5, -2, -2, 6, -2, 9, 1, -2, -5, 3, 4, 11, 5, 2, 8,
+ -3, -1, 1, -2, -3, -5, 5, 8, 49, 12, 8, -3, 9, 20, 12, 17 },
+ { -6, 0, 1, 7, 0, 9, -2, -4, 8, 0, -2, -10, 0, 7, 21, -1,
+ 0, 1, 17, -7, -5, 2, 4, 16, -2, 17, 14, -20, 15, 14, 4, 15 },
+ { 0, 3, -4, 9, -4, 0, 6, 4, -6, -6, -5, -7, 2, -9, -10, -2,
+ -5, 0, -3, -21, 9, 14, -11, 13, 29, 2, 25, 4, 22, -1, 2, -3 },
+ { 2, 12, -11, 2, 16, 9, -4, 7, 1, -10, -15, 11, -4, 3, -2, 4,
+ 4, -5, -10, 1, 4, 19, -15, 6, -4, -2, 30, -7, 11, 21, -12, 5 },
+ { -2, -3, -2, 4, -1, -5, -3, -7, -5, 1, 0, -6, 1, -6, 7, 0,
+ 8, -7, -3, -2, 2, 14, 2, -3, -26, -1, 26, 22, 32, 1, -2, 6 },
+ { 1, -38, -1, -20, -2, -3, -6, -4, 2, 2, 7, 0, 3, 5, 3, 10,
+ 6, 1, -3, -5, 7, 5, -5, -4, 8, 3, 1, -14, -1, -9, -5, -4 },
+ { -5, -26, -7, -19, -10, -5, -11, 5, -11, -25, -8, -14, -9, -16, -8, -6,
+ -17, -14, -1, -1, 6, 2, 2, 2, 3, 0, 2, 8, -8, 3, 0, -3 },
+ { 17, -49, -3, -23, -1, 11, 7, 3, 4, -4, 0, 0, -1, 4, 2, 4,
+ -2, -4, 2, -2, -1, -2, 2, 0, 0, -1, 0, 0, 1, 2, 0, 0 },
+ { 4, -34, -6, -9, 1, 21, -7, 3, -2, -1, -3, 18, 2, -16, 7, -3,
+ 8, 7, -5, 7, 2, 4, 8, -6, -7, -2, -5, -1, 4, 1, 2, -4 },
+ { 5, -29, 13, -2, -14, 3, 1, 18, -15, 4, -8, 8, -10, 8, 2, 1,
+ -8, 15, 3, -10, -4, -4, -2, 0, -3, -4, 2, -3, -4, -3, 12, -6 },
+ { 13, -20, 3, -18, -17, 4, -14, 13, 28, 11, -8, -6, 16, 6, 0, 10,
+ 3, 4, -9, 13, 5, -7, 12, -5, 0, -7, 5, 1, 3, 3, 2, 1 },
+ { 3, -27, -5, -11, -21, -11, -12, 0, -5, 7, -22, 1, 3, 5, 0, -5,
+ 8, 7, 1, -5, -7, 2, -5, 4, 1, 3, -8, -2, 0, 4, -2, 6 },
+ { 31, -45, 0, -1, -12, 1, 2, -6, 4, 3, -1, 3, 3, 0, 5, 3,
+ -5, 12, 4, 6, 2, 1, -2, 1, 3, 2, 5, 2, 2, 2, 3, -1 },
+ { 9, -45, 6, 5, -1, -17, -2, 18, -3, 2, 0, 1, 0, -1, 10, 8,
+ -7, -2, -5, -8, 6, -1, 0, 4, 6, -3, 12, -1, -2, 0, 5, -7 },
+ { 3, -26, -2, -12, -12, 2, -10, 16, -3, 12, 4, 5, 11, 8, -16, -17,
+ -2, -3, -3, 2, 5, -9, 13, 1, 10, 11, 3, 5, -2, 2, 2, -7 },
+ { 8, -26, 32, -7, -5, 22, 2, 14, -10, -8, -7, 3, 3, 7, 0, -5,
+ 0, -1, -3, 0, 8, 4, -5, -7, 6, -1, 4, 8, 1, 1, 7, -6 },
+ { 4, -31, 2, -14, 2, 0, 1, 8, -6, -1, 17, -3, 13, -6, 5, -10,
+ -2, -10, -2, -10, -3, 7, 1, 5, -8, 8, -14, -3, -15, 7, -10, -6 },
+ { 16, -27, 13, -4, -23, 7, -9, 6, -7, 5, 4, 2, -1, -3, 23, -18,
+ 7, 0, -3, 4, -3, 9, -6, -2, -1, 8, -6, 2, 6, -3, 2, -2 },
+ { -1, -35, -2, -8, 11, -1, -7, -3, -2, 11, 7, 6, -6, -10, 9, 6,
+ -3, -5, -6, -3, 9, 16, -16, -9, -20, 12, 3, 5, -3, 1, -9, 4 },
+ { 2, -24, 1, -12, -16, 5, -4, 3, -4, -1, -11, -11, -8, -14, 14, 10,
+ -8, 20, 8, -3, -11, 1, 1, -4, -4, -7, -3, 15, 2, -6, -2, 7 },
+ { 9, -21, 2, -19, -7, -5, -8, 25, 3, 17, 5, -3, 9, -12, 8, 2,
+ -4, 3, 3, 1, 11, -9, -4, -3, 4, 3, -22, 6, 4, 6, 11, -5 },
+ { 16, -23, 13, -17, -21, -12, 5, 9, -20, 7, 6, -6, 0, 2, -9, 6,
+ -6, -13, -7, -1, 5, -3, 5, -7, -10, 1, 0, 8, -9, 11, 0, -8 },
+ { 10, -26, -9, -7, -19, -4, 6, 16, -7, 5, -4, 4, 8, 0, 4, -1,
+ 6, -7, 1, -8, -11, 10, -14, 0, -16, 6, -3, 5, -1, 14, 12, 1 },
+ { 8, -27, 12, -14, -1, -1, -19, 10, -11, 21, -14, 9, -8, -3, 8, -1,
+ 12, -13, 3, -4, -2, 0, -9, 0, -7, 2, -3, 12, 1, -3, 3, 1 },
+ { 18, -20, -14, -14, -16, -3, -24, 6, -17, 2, -3, -11, 2, -3, 12, 10,
+ 10, 1, 10, 7, 8, 5, 5, 4, -1, 7, 2, 2, 0, 4, 7, 0 },
+ { 0, -30, 9, -16, -18, 15, 12, -3, 4, -4, -5, -11, -4, -12, -10, 0,
+ 2, -2, -4, -1, 2, 0, -1, -6, 2, -3, 4, -5, 7, 3, 5, 7 },
+ { 25, -24, -1, -6, -9, 6, -13, -2, 3, 15, -3, 11, 4, -8, -11, 2,
+ 0, -9, -2, 7, 4, 8, 5, -8, 5, 6, -1, -11, -15, -5, 0, 11 },
+ { 0, -34, -7, -11, -7, 9, -3, 19, 4, -8, 3, -11, 11, -3, -9, 12,
+ 9, 9, 2, 1, -7, 1, -3, 0, -6, -2, -1, 3, 0, -7, -2, -5 },
+ { 6, -34, -4, -5, -3, -9, 2, 9, -1, 9, -5, -3, -26, -12, 8, -6,
+ -7, 11, -8, 4, 4, 1, -1, 0, 8, 9, -4, 7, -1, 1, -3, -1 },
+ { 3, -30, 5, 6, -10, 3, -7, 6, 3, 3, -26, -19, -3, 1, 7, 5,
+ -4, -5, 6, 10, 13, -10, 4, -7, -4, 5, -3, 9, -6, 3, 9, 5 },
+ { 4, -24, 9, -19, 2, -4, -5, 8, -3, 2, 0, -15, -1, 9, -4, 22,
+ 6, 9, 3, 7, 11, -9, 0, -3, 4, 5, -5, 10, -8, 5, -7, -3 },
+ { 8, -27, 7, -3, -1, 2, -9, 13, 7, 12, -4, -6, -6, 5, 0, 7,
+ 5, 1, 15, -3, -4, 0, -5, -2, 7, -5, -7, 1, -2, 13, -8, 13 },
+ { 17, -22, -15, -11, -8, 16, -14, 18, 2, -1, 14, -7, 14, -6, -6, -7,
+ -8, 17, 6, 4, 4, -7, -5, -9, -14, -6, -1, 9, -3, 1, 6, -5 },
+ { 25, -30, 2, -12, -13, 18, -18, 16, 8, -3, 10, -8, -3, -1, -6, 3,
+ -5, -7, 4, 6, 7, 1, 1, -11, -5, 6, 2, -4, 9, -1, -5, -2 },
+ { 7, -23, 7, -15, -1, -3, -1, 0, -10, 12, 2, 5, -4, 0, 4, 6,
+ -1, 5, -9, -1, -1, -7, 1, 17, 9, -17, -16, 8, 4, -14, 11, 14 },
+ { 0, -31, 7, -13, 3, -11, -7, 6, 1, -11, 8, -7, 15, -3, 16, -11,
+ -1, -15, 16, -3, 5, 0, -2, -2, -6, 11, 5, 6, 5, -5, 6, 3 },
+ { 13, -24, -2, -20, -10, 7, -3, -1, 15, 2, 6, -5, -7, -10, -20, 1,
+ -4, 14, 8, -2, 3, -13, -3, 1, -4, 1, -3, 2, 8, -7, 16, -4 },
+ { 1, -2, -2, -3, -4, -7, 0, 3, 6, 7, 3, 2, 1, -2, -1, 0,
+ -6, 4, 2, -4, -3, -4, 5, 9, 5, 0, -3, -3, -4, -7, -31, -50 },
+ { -1, -3, 7, 2, -1, 2, 4, 6, 0, 10, -2, 0, -20, -6, -3, 9,
+ -20, -22, -1, -1, 15, 9, -12, 10, -13, -20, 12, 3, 5, 6, -7, -26 },
+ { 0, 4, -2, -14, -12, 6, -13, 11, -10, 3, 22, 6, 16, -2, -5, 1,
+ -3, -11, 0, -7, 5, -5, 0, 1, -1, -6, 8, 8, 10, 9, -5, -27 },
+ { -5, 10, -2, 7, 9, -9, 5, -9, 5, 4, -15, 14, 1, 3, -10, 5,
+ 0, -2, 7, 3, -13, 6, 9, -6, 5, -14, -17, -1, 11, 14, -2, -26 },
+ { 0, 6, -3, 0, -8, 6, 0, 1, 4, -8, 2, -5, 4, 7, 15, 11,
+ 9, 19, -2, 14, -8, 7, -1, 3, -3, -3, -10, -2, 12, -2, -12, -29 },
+ { -12, -5, 0, -3, -2, 6, 3, -3, 2, -2, 1, 11, 2, -7, 5, 1,
+ 2, -2, -14, 0, -1, -5, 3, 8, -28, -26, 6, -6, 3, 8, -10, -27 },
+ { -1, -3, 6, 2, 4, 15, 1, 0, 2, -2, -2, 13, 3, 6, 0, 6,
+ -1, -4, -1, -5, 8, -1, 5, -5, -15, 11, -8, -5, 14, -6, -14, -29 },
+ { -5, -6, 0, 1, 0, 6, -3, 2, -5, -1, 5, -3, 2, -10, 3, 4,
+ 3, 0, 13, -3, -1, 4, -4, -6, 2, 9, 8, 2, -3, 28, -11, -31 },
+ { 1, -4, -10, -9, -4, -3, -15, -6, 1, 5, -3, -6, 5, -6, -22, 27,
+ -13, 5, 3, -7, -4, 20, -7, -12, -1, -24, -4, -13, -8, -11, -15, -21 },
+ { -6, -4, 19, -6, 2, 11, -6, 1, -3, -10, 9, -9, 12, -10, 2, 1,
+ -9, 1, 15, 7, -5, 5, -29, -35, 4, -30, 9, 9, 19, 17, 2, -17 },
+ { -3, 3, -3, 1, 2, 5, -1, 5, -2, -3, 1, -3, -8, 3, -4, -2,
+ -4, -1, 12, 0, 2, -8, -6, -4, 16, -1, -14, -2, 25, -6, -15, -36 },
+ { 0, -1, 3, -4, -4, -1, 7, -4, 8, 0, 10, 9, -4, 1, 10, -1,
+ -3, -13, -5, -4, -1, -4, 8, 11, 14, -7, -5, 16, 12, 13, -1, -28 },
+ { 1, -2, 2, -3, -8, 10, 4, 9, 12, 3, 5, 0, 8, -3, -6, 2,
+ 16, -11, 11, 0, 1, 6, 1, 18, -10, -16, -1, -4, 5, -14, -15, -20 },
+ { 1, -12, 5, 4, -7, 8, -1, -17, -2, -9, -14, -11, 6, -9, 5, -4,
+ 3, -2, 7, 18, -5, 5, 6, -1, -11, -2, -10, -3, 8, -3, -2, -32 },
+ { -12, 5, 20, -5, -6, -11, -6, -6, -13, 4, -6, 19, -8, 2, 3, -9,
+ -4, -4, -1, 9, -1, 21, -1, 7, 15, -10, -1, -3, 9, -3, 2, -24 },
+ { 0, -3, 2, -6, 4, -1, -9, -2, -1, -3, 6, -1, -5, -6, -5, -8,
+ 0, -2, -6, 9, -4, 3, 2, -13, 1, -7, 23, -13, 4, -3, -15, -33 },
+ { -7, 2, -15, 11, -10, 14, 0, -11, 3, -1, 12, -4, -4, 9, 11, -13,
+ -13, -3, -14, 1, 3, 6, -5, 8, 0, 5, 5, -10, 4, 5, -6, -30 },
+ { -6, 4, 0, -5, 4, 1, -1, -1, 3, 6, 5, -2, -5, 0, -2, 5,
+ -4, -2, -4, -2, 4, 7, -7, -1, 1, -4, -3, -19, 37, 12, 10, -40 },
+ { -7, 2, -7, -12, 17, 11, -7, 2, 2, 3, 1, -1, 3, 4, -2, -5,
+ 9, -9, 6, 4, 9, 12, 11, -5, 2, -1, 0, 9, 5, -7, -2, -24 },
+ { -7, 6, 1, 3, 1, 0, 6, 0, 4, -12, -2, -2, 1, -9, 10, -2,
+ 11, -1, 21, -12, 15, -5, 10, -5, 5, -5, 14, -6, 5, -7, -3, -29 },
+ { -2, 0, -5, -2, -3, 1, -3, 0, 4, 2, 3, 0, 2, -2, 7, -2,
+ 3, -5, 2, -1, 6, -4, 0, -3, 8, -11, 19, -8, 22, -34, 13, -35 },
+ { -1, -3, -1, 9, 11, -3, -3, -1, 7, 18, 11, -5, 2, -12, -11, 18,
+ 9, -5, 1, -6, -9, 12, 1, -3, -3, -9, -14, 9, 9, 8, -6, -26 },
+ { 0, 5, -5, -1, -1, -2, 4, 6, 8, 2, -1, -2, 5, 1, -5, -4,
+ 1, 1, 18, 1, 7, -10, 3, -2, 12, -1, -15, 9, 12, -14, 13, -38 },
+ { 3, 0, -8, -1, 0, 8, -9, -3, -8, 16, 3, 16, -5, -9, 0, -1,
+ -7, -1, -4, 13, 7, 0, 1, 2, -1, -16, 0, -2, 1, 8, -8, -28 },
+ { 7, 9, -5, -3, -2, 2, 0, 3, 11, -6, -4, -2, -2, -5, 28, -18,
+ -6, 2, 15, -10, -15, -10, -2, 0, -2, -2, 4, -3, 7, 11, 5, -30 },
+ { 9, 0, -7, -1, -4, -7, 2, 2, 9, -2, 2, 3, -8, -6, -6, 3,
+ -10, 4, 10, 5, 21, -4, 14, -18, 1, 3, -10, -2, 6, 14, -8, -26 },
+ { -14, -1, 2, 3, -3, 7, 1, -22, -1, -1, 0, 1, 12, -14, 3, -5,
+ 0, 10, -3, 1, -5, 12, -3, 10, -8, -22, -11, -13, -7, -10, -13, -25 },
+ { -2, -5, -4, -4, -9, -18, 9, -3, -5, 17, 13, 5, 6, 11, 3, 8,
+ 20, 4, 2, 9, 8, 5, 6, 1, 7, -7, -6, -2, -7, 0, -17, -23 },
+ { -5, -5, 2, 0, 6, 2, -2, 2, -3, 4, 4, 0, -5, -2, -4, 6,
+ 8, 10, -1, 1, -5, 5, -14, -2, -11, 8, 6, 25, 7, -1, 0, -43 },
+ { -4, 0, 4, -2, 7, 0, 3, 17, 5, 2, -5, 1, 21, 3, -2, -10,
+ -16, -9, 7, -12, 9, -8, 2, 5, -5, -10, -2, -11, -5, -1, -9, -30 },
+ { -2, 3, 1, -4, -1, 0, 8, 1, 12, 4, -1, -1, 3, -17, 13, 9,
+ 0, 7, -6, -5, 9, 1, 5, 4, -10, -18, 0, 14, 11, -4, -16, -28 },
+ { -1, 0, 2, -1, 4, 1, -1, 1, -1, -2, -1, -2, 3, 0, 0, -1,
+ -1, 1, 2, -2, 3, 3, -2, 4, -2, -1, -6, 1, -1, -1, 6, -70 },
+ { 7, 3, -11, -1, 12, -4, -14, 4, 4, -4, 4, -2, 2, -12, -4, 15,
+ -17, -4, -3, 6, 8, -5, 22, -22, 5, -11, 15, -4, 4, -1, -21, -1 },
+ { 10, -2, -13, 11, 4, 14, 4, 9, 8, 8, 19, 15, 14, 15, 5, 10,
+ 8, 15, -5, 4, 14, -8, 1, 1, 2, 1, -1, -3, 21, 8, -29, 13 },
+ { -6, 0, -6, 6, -1, 2, 8, -4, -5, 4, -4, -5, 0, -2, -4, 0,
+ 9, -2, 1, -2, 26, -19, 21, -10, 4, 1, -8, 5, 22, -10, -13, 15 },
+ { 11, -5, 1, 0, 6, 3, 7, -2, -2, -3, -5, -1, -2, -6, 1, 1,
+ -8, -5, -13, 13, -2, -3, -1, -9, -28, 4, 2, -11, 18, -20, -24, 9 },
+ { 7, 4, -3, 6, 6, -6, -7, -5, -7, -4, -4, 0, -7, -5, -6, -5,
+ 2, -13, -12, 2, 0, 5, 18, 15, -13, -7, 13, -20, 16, -10, -19, 6 },
+ { 5, -8, -1, 5, 10, 2, -1, -10, -11, 23, 8, -5, -8, 4, -5, -4,
+ -5, -5, -11, -8, 5, 1, 7, -9, -9, -6, 12, 14, 17, -12, -22, 3 },
+ { -5, -8, -3, 3, 12, -1, 0, -4, -5, 1, 1, 6, 1, 5, -5, 7,
+ -2, 7, 1, 6, 6, 2, 0, -5, 17, -4, -5, -24, 13, -20, -27, 14 },
+ { -1, 2, -3, 1, -3, 1, -3, 0, -2, 3, -2, 1, 2, -1, -2, -1,
+ -2, -5, 5, -2, 0, -7, 1, -6, 8, 8, 11, -5, 24, -43, -13, 2 },
+ { -2, 4, 7, -3, -4, 4, 13, -4, 0, 0, -2, 9, 0, -3, -6, 1,
+ -7, 1, -1, 10, 0, 5, -1, -24, 25, -15, 7, 2, 22, -10, -21, 0 },
+ { -5, 2, 6, -2, 13, 3, 5, -12, -11, 16, 6, 10, -5, 0, -3, 6,
+ 5, -5, -5, 10, 12, 10, 11, -7, 8, -14, 2, -15, 13, -14, -8, -3 },
+ { 5, 6, -7, -5, 5, 2, 9, 5, 0, -1, -4, 2, 8, 0, 3, 5,
+ -12, 3, -3, -6, 2, -1, -5, 14, 11, -20, -21, -25, 24, -1, -10, 6 },
+ { -5, 5, -2, 9, 4, -4, -1, -6, 11, -6, 5, 0, 2, -3, 6, -1,
+ -17, -18, -4, -13, 9, -1, 9, -7, -4, -8, 2, -3, 12, -31, -18, 5 },
+ { -7, -11, 6, -8, 4, -3, -12, 0, -1, -6, -3, 0, 5, 9, 7, 2,
+ 1, -8, -6, 8, 2, -5, 7, -1, 16, -10, 16, -12, 18, -1, -25, -12 },
+ { 3, -12, 1, 2, -2, -18, -8, -15, -10, -9, 2, -7, 11, -11, 2, -1,
+ -1, -1, -9, -6, 3, -14, -2, -1, 2, -13, -7, -9, 19, -5, -17, 2 },
+ { 7, 1, -8, 7, 17, -13, -10, 5, 7, 1, -6, 4, 9, -4, 0, 3,
+ 8, 1, -14, -9, 4, 7, -9, 0, 6, -5, -12, -2, 25, -2, -19, 1 },
+ { 7, -3, 6, -3, 1, 6, -7, 0, 10, 0, 4, -5, -17, -4, 4, -1,
+ 0, -3, -7, 19, 24, -1, 21, 8, 10, 9, 8, -1, 23, -2, -18, -2 },
+ { 3, -3, 0, 5, 8, -2, -9, 2, 9, 6, 19, 8, 2, 6, -9, -2,
+ -4, -3, -8, 7, -7, -8, 5, 4, 26, -6, 7, 18, 24, 0, -13, 4 },
+ { 0, -13, -11, -1, 3, -9, 5, 4, -7, 3, 0, 2, -1, 4, -5, 2,
+ 9, -2, -11, 15, 1, -21, 1, -1, 0, 4, -14, -4, 24, -16, -13, 1 },
+ { 1, -9, -8, 0, 0, -4, 11, -1, 14, 16, 0, 17, -2, -9, -12, 0,
+ -1, -14, -9, -14, 0, -2, 19, 4, 6, 4, 4, -11, 8, -17, -19, -5 },
+ { -3, 1, 2, 12, -4, -18, -1, -4, -7, 14, -3, 2, 0, -7, -8, 12,
+ -5, -9, 14, 12, -9, -2, 4, -6, 4, 18, -1, -25, 22, 2, -23, -5 },
+ { -2, 0, 0, 0, 1, 3, 5, -1, 5, -2, -2, 2, -3, 0, 1, 2,
+ 0, -1, 2, -1, -9, -6, -7, -4, -2, 4, -7, -5, 64, -3, -25, 4 },
+ { 12, -2, -3, 0, 8, -9, 13, -7, 6, -3, -12, 12, 15, -9, -4, 2,
+ 9, -4, -12, 3, 14, 1, 7, -15, 15, 0, -6, -12, 0, -3, -20, 6 },
+ { 2, -1, -4, 5, 9, 6, -7, 2, -2, -7, -2, 0, -1, -18, -4, -6,
+ -15, -5, 11, 5, -10, -1, 2, 7, 12, -19, -7, 8, 21, -4, -15, 4 },
+ { 4, 2, 5, 5, -5, 1, 3, 2, -8, 13, 0, -5, -2, -14, -11, 6,
+ 2, 17, 8, -13, 26, -2, 5, -15, -4, -14, 12, -9, 13, -21, -23, -4 },
+ { 2, -3, -2, -3, 3, -2, 6, 9, -9, 13, 4, 2, 12, -3, -3, 1,
+ -17, -22, -3, 4, 3, -2, 1, -9, 1, -6, 11, -13, 14, 0, -15, 6 },
+ { -16, -4, 17, -2, -20, -11, 11, 10, 5, -8, 16, 2, -17, -14, 11, 11,
+ -6, -11, -7, 12, 12, -10, -6, 5, 8, -4, -2, -5, 28, 3, -13, 4 },
+ { 0, -3, 3, -7, 6, 8, -12, 20, -19, 18, -11, 10, -5, 0, -9, 11,
+ 3, 0, -2, 9, -7, -5, 18, 3, -2, -16, 1, 6, 12, -7, -16, 1 },
+ { 4, 1, 5, -5, 15, 2, -8, 3, 5, -11, 15, -3, 8, -8, -1, 7,
+ 4, 7, -2, 6, -9, 5, 12, 2, 33, -2, -6, -18, 4, 0, -18, 11 },
+ { 3, -1, 1, -1, 0, 1, 4, -1, -5, 0, 1, 0, 4, 2, -1, 4,
+ -3, 2, 0, -2, 4, 6, -1, 6, 42, 19, -4, -37, 19, 1, -15, -4 },
+ { 2, 0, -5, 0, 10, 0, 0, -5, 3, 0, 0, -3, -3, 0, 2, -4,
+ -10, 2, -6, 4, 4, 1, 27, -7, 17, -34, 5, -9, 15, -16, -7, -5 },
+ { -2, 7, 7, -2, 9, -2, -15, 11, 11, 7, 5, 1, 15, 1, -9, 31,
+ 2, -15, 2, 4, 3, 4, -1, -8, 2, -7, 6, -17, 11, -14, -11, 2 },
+ { 1, 1, -11, 9, 9, -6, -14, -11, -10, 8, -3, 11, 16, -9, -8, -13,
+ -8, 9, 0, 6, 6, -2, 13, -8, -2, 3, 13, -3, 10, -6, -17, 4 },
+ { 14, 5, 4, -6, -12, 10, -7, 8, 21, -8, -30, 15, -2, 1, 11, -9,
+ -5, 1, 0, -1, -1, -6, -2, 3, -5, 7, 9, 5, -5, 2, 0, 1 },
+ { -1, 2, 20, -17, -15, 3, 3, 7, 11, -17, -13, -6, -3, 18, 17, -15,
+ -4, -4, -5, 22, 14, -14, -2, -10, -7, 11, 8, -7, -3, 0, -7, 11 },
+ { 7, -11, -7, -8, -14, 22, 5, 2, 6, 13, -12, -2, 10, 3, 0, -21,
+ -4, 20, 3, 10, 21, -10, -12, 8, 11, 2, -5, 2, 1, 3, -1, 15 },
+ { -1, -2, -1, -2, -13, 8, -4, 0, 7, -2, -17, 8, 18, 5, 3, 8,
+ -8, -2, 3, -4, 14, -18, -13, 14, 15, -13, -1, -2, 4, 11, 1, 12 },
+ { 13, -6, -4, -16, -17, 16, 21, -2, 5, -11, -9, 19, 21, -17, -3, -17,
+ 3, 12, 8, -12, -6, 1, -7, 9, 9, -7, -5, -1, -3, 5, -6, -4 },
+ { 11, 5, 12, -20, -6, 10, 4, 12, 8, -5, -10, 15, 13, 14, 10, -15,
+ -13, 1, 6, 14, 15, -17, -13, 4, -5, 10, 7, -6, -8, -3, -4, 12 },
+ { 25, -1, 7, -5, -7, 11, 1, 17, 13, -15, -14, -4, 5, 3, 8, -3,
+ -2, 2, 0, 6, 16, -12, -6, -4, 4, -3, 7, -10, -3, -7, -13, 7 },
+ { -8, 10, -3, -13, 5, 2, 4, 9, 9, -17, -13, 2, 11, 1, 6, -4,
+ 8, -10, 4, 1, 19, -15, -4, 12, 31, 7, -5, -17, -4, 9, -2, 7 },
+ { 14, -6, -6, -6, -14, 13, 17, -5, 4, -14, -9, 7, 7, -9, 3, -16,
+ -15, 11, 11, 6, 4, -11, -19, 3, 5, 8, 13, -14, -14, 3, -4, 12 },
+ { -2, -4, 10, -4, -7, -1, 27, 5, 2, -16, -18, 4, 12, -2, -3, -2,
+ -1, 1, -8, -12, 3, -4, 8, 15, 2, 4, 9, -13, -14, 9, -7, 5 },
+ { 4, 2, -10, -5, -7, 2, 1, 4, -1, -6, -15, 6, 1, 10, 5, -10,
+ -9, -1, 13, -3, 5, -21, -11, 8, 8, 5, 27, -21, -18, -5, -1, 15 },
+ { 11, 1, -16, -8, -11, 0, 5, -8, -12, -13, -17, 22, 4, -6, -1, -18,
+ -10, 0, 19, 2, -2, -8, -7, -3, 2, -2, -9, -17, -5, 4, 4, 10 },
+ { 8, -6, -19, -5, -4, 12, 14, 15, 10, -9, -1, -9, 19, 12, 0, -1,
+ 2, 4, 7, 9, 16, -16, -14, 9, -4, 3, 1, 0, -2, 10, -1, -1 },
+ { 12, -8, 12, -9, 0, 25, 7, 9, 2, -31, -9, -4, 15, 4, -5, 1,
+ -10, 11, 8, 10, 0, -6, 5, 11, -1, -6, 4, -10, -9, 6, 4, 5 },
+ { 14, 6, -17, -2, 17, 12, -9, 2, 0, -25, -14, 5, 20, 14, 8, -20,
+ 5, 2, -2, -3, 9, -13, -3, -1, -6, 3, 7, -6, 0, 2, 3, 1 },
+ { 8, 4, -15, -3, 10, 18, -4, 13, 8, -22, -10, 9, 19, -15, 7, -5,
+ -13, 12, -4, 9, 2, -9, -6, 0, 2, 1, -9, -6, 6, 1, -1, 11 },
+ { 4, 1, 4, -5, -10, 18, 7, 2, -4, -9, -11, 0, 32, -7, 4, -16,
+ -1, 0, 6, 3, 6, -3, -14, 16, 9, -2, 7, -1, 0, -5, 5, -3 },
+ { -3, 2, 3, -8, -6, 4, 6, 2, 4, -12, -15, 2, 8, 8, 9, -3,
+ -18, 6, 34, 11, 12, -15, -1, 2, 9, 2, -4, -4, 2, 4, 2, -3 },
+ { 18, -6, -12, -8, -1, 15, 20, -4, -1, -11, -5, 6, 6, -11, -15, -7,
+ 3, 7, 10, 2, 8, -10, -5, 8, 15, -5, 5, -17, -13, 13, 11, 7 },
+ { 8, -4, -6, -1, -14, -3, 6, -2, 1, -5, -1, 10, 10, -15, 5, 0,
+ -10, -4, -3, 7, -4, -19, -15, 27, 11, 18, 3, -19, -2, 6, 0, 12 },
+ { 12, 0, -5, 0, 4, -5, 1, 5, 10, -7, -11, 21, 29, 1, -2, 1,
+ -4, -11, -1, 13, 11, -20, -1, 4, 4, 4, -5, 6, -13, -2, 11, 9 },
+ { 2, -7, -7, -3, -10, -1, 20, 12, 1, -19, -19, -1, 5, 4, -7, -25,
+ 14, 1, -3, 2, 12, -4, -3, -3, -2, 6, 1, 0, 3, 2, 5, -1 },
+ { 12, -8, 3, -12, -10, 10, 13, 0, 23, -14, -18, 10, 0, 15, 3, -12,
+ -3, -5, 5, -4, 2, -14, -10, 8, 2, 9, -1, -11, -3, 5, 13, 2 },
+ { 9, -6, 7, -7, -30, 17, 6, 13, 1, -14, 0, -1, 6, -9, 8, 3,
+ -4, 0, -1, -7, -5, -13, -19, -3, -4, 4, -6, -2, -13, 1, -2, 3 },
+ { 10, 1, 3, -18, -26, 17, 4, -16, 4, -3, -13, -4, -6, -11, -4, -21,
+ 7, 8, 2, 5, 13, -6, 1, 5, 8, 7, 9, -6, -6, 1, -1, 2 },
+ { -3, -1, 0, -2, -2, 0, -1, 3, 4, -14, -8, -9, 13, 2, 50, -23,
+ -8, 8, 7, 11, 16, 3, -7, 0, -2, 6, 5, -1, 1, -2, 4, 3 },
+ { 1, 3, 1, 1, -6, 3, 6, 6, 2, -2, -3, 10, 2, -8, -5, -5,
+ 5, 4, 4, -2, 10, -8, -40, -1, 21, 8, 3, -4, -1, 13, 4, 7 },
+ { 2, 0, -4, -8, 5, 2, 7, -5, 5, -8, -4, -1, 12, 2, 12, -13,
+ -9, 0, 1, -12, 9, -43, 1, -5, 12, 1, 3, 6, 1, -1, 3, -2 },
+ { 6, -2, -1, 1, 0, 4, 8, 14, 4, -7, -23, -5, 23, -17, -6, -15,
+ -8, 7, 10, -1, 7, -16, 4, -6, 2, 3, -3, -3, -1, 8, -1, 4 },
+ { 10, 4, -4, 1, 7, -3, 2, 11, 4, -6, -3, 8, 5, 4, 1, -45,
+ -6, -4, 4, 2, 1, -14, -10, 1, 1, 6, 2, -8, -1, -3, 3, 3 },
+ { 1, -1, 2, -3, -8, 9, 3, 3, -2, -5, -8, 8, 7, -7, -4, -6,
+ 5, -9, 11, -2, 46, -5, -1, 9, -2, 0, 3, -5, -3, -5, 7, 0 },
+ { -4, 1, -2, -1, -11, 11, 8, -3, -2, -10, 0, 4, 9, 9, -17, -17,
+ -34, -4, -5, -7, -3, -12, -3, 11, 18, 3, -2, -5, -18, -5, -3, 6 },
+ { 7, -5, -3, 1, -4, -3, -5, -1, 2, 5, -2, 3, -10, 12, -18, -5,
+ -10, 12, -9, 4, -6, 2, 0, 16, -17, 15, 14, -12, -10, -2, -9, -1 },
+ { 4, -5, -3, -5, -3, -1, 7, 18, -7, 12, 3, 5, -8, -4, -20, 1,
+ -25, 1, -8, 13, -10, 8, -19, -1, -8, 10, 6, -9, -1, 0, 12, 4 },
+ { -4, 5, 0, -1, 2, 5, -8, -2, -6, 4, -8, 9, 3, 2, -7, 4,
+ -25, 13, -23, 10, 14, 15, -11, 3, -18, 4, 16, -4, 1, -10, -10, 3 },
+ { 5, -3, -1, -3, 4, 1, -3, -4, -5, 1, -12, 14, -7, 11, -15, 6,
+ -6, 24, -4, 13, -1, 15, -13, 8, 3, 7, -5, 2, 2, 0, 3, -7 },
+ { -3, 1, 0, 8, 6, -1, 6, 5, -5, -2, -12, 4, 0, -2, -3, 5,
+ -6, 0, -8, 9, -10, 4, -28, 12, -20, 11, -13, 7, -18, 1, -11, 1 },
+ { 1, -4, -15, 5, 0, -13, -5, 13, -11, 4, -4, -5, 5, -14, -16, 0,
+ -14, 5, -20, 12, 10, -7, -5, 6, 6, 22, 6, -4, -2, 3, 8, 11 },
+ { 13, -11, -2, 16, 16, -7, 0, 20, -7, -1, 0, 5, -9, 12, -2, -5,
+ -22, 5, -10, 12, -6, 11, 9, 21, -8, 15, 4, 0, -8, -4, -4, 10 },
+ { 18, -4, -13, 0, 1, -15, -1, -3, 2, 10, -1, 6, 1, -4, -20, -5,
+ -8, 6, -8, 17, -5, 5, -10, 8, -22, 6, -5, -2, 8, -17, 8, 2 },
+ { 1, -2, -9, 6, -31, -8, -8, 8, 0, 5, -9, -4, 2, 3, -12, 11,
+ -18, 10, -5, 3, -11, 13, -6, 11, -3, 12, -7, 3, -9, -1, 2, 11 },
+ { -9, -6, 21, -8, -15, 4, -11, 12, -11, 17, -1, 2, -6, 0, -15, 13,
+ -12, 19, 0, 2, -6, -3, -9, 10, 3, 17, -2, 5, -10, -3, 0, 1 },
+ { 4, -6, 5, -10, 1, -5, 1, 0, 0, 0, 2, 7, -2, 2, -2, 0,
+ -4, 3, -4, 1, -12, 6, -49, 16, -10, 13, 0, -2, 8, 6, 1, 8 },
+ { 5, -8, -7, 9, 13, -5, 7, 0, 10, 11, -4, -3, -1, 13, -14, 6,
+ -15, -6, -14, 16, 15, 1, -18, -4, -20, 20, -7, -1, -9, -2, -10, 10 },
+ { -12, 4, 0, 10, 0, 3, 8, 4, -27, -1, -2, 19, -4, 2, -13, 3,
+ 1, 9, -12, 1, -22, 19, -5, 4, -9, 12, 2, -9, -8, 11, -3, 7 },
+ { 4, -5, 11, -6, 17, -17, 5, -4, -2, -6, 1, -5, 2, 4, -14, 6,
+ -20, 19, -20, 12, -21, 5, -14, 13, -2, 11, 4, -3, 0, -10, -4, -2 },
+ { -2, -1, -3, 8, -9, -7, -22, -3, -24, 13, -2, 10, -15, 5, -9, 4,
+ -7, 0, -5, 15, -8, 11, -13, 6, -4, 19, -8, 12, -4, 6, 9, 7 },
+ { 2, -3, 2, -1, 0, 3, 1, 2, 1, -4, -2, -3, 1, 5, -12, 6,
+ -16, 14, -23, 10, -14, 17, -15, 16, -2, 9, -25, 9, -10, 16, 4, 9 },
+ { -3, 7, -8, -3, 2, 2, -4, -8, -9, 10, 3, -11, 25, -10, -28, 27,
+ -9, 7, -13, 9, -2, 4, -12, -8, -14, 6, 7, -10, 3, 3, -3, 5 },
+ { -8, -3, 1, -10, 8, -3, -9, -4, 13, 7, 2, 4, -10, 4, 3, 7,
+ -18, 2, -22, 15, 4, 20, -7, 5, -6, 13, -1, 4, -7, -6, 6, 13 },
+ { -2, 3, 0, 2, -4, -2, 0, 0, 1, 2, -2, -5, 0, 1, -4, 0,
+ -2, -3, 1, 2, -1, 2, -8, -1, -24, 68, -3, 8, 3, 3, -1, -1 },
+ { -15, -2, -9, -7, -1, 8, -14, 8, 3, 6, 0, -1, -8, 8, -23, 2,
+ -14, 17, -15, 8, -4, 7, -18, 0, -8, -3, -1, -4, -10, 4, -1, 4 },
+ { 8, 0, 2, -7, 0, 5, 1, 3, -11, 4, -8, 14, 3, 20, 1, 26,
+ -11, 13, -13, 20, -2, 0, -8, 2, -6, 6, -1, 9, 3, -6, -3, 10 },
+ { 5, 0, -1, -7, 10, 1, -3, 5, 4, 7, -5, -1, -3, -1, 12, -3,
+ -15, 7, -9, 22, -19, 8, -9, 4, -23, 13, -14, 6, -6, -14, -4, 7 },
+ { 14, -5, -8, -10, 25, 3, -23, -7, -28, 0, -1, -9, 4, 1, -13, 20,
+ -8, 10, -16, 8, 12, -13, -21, 5, -13, 11, -2, 1, 12, -7, 2, -10 },
+ { -5, -4, 9, 5, -6, 35, -7, 8, 15, 2, -1, -9, -6, 2, -18, 7,
+ -15, 6, -3, 2, 8, 12, -30, 7, -4, 20, 2, 6, 13, -6, -4, 0 },
+ { 1, 8, -9, 9, -5, 12, -9, 16, -9, 16, -17, 14, -13, 15, -18, 14,
+ -15, 17, -12, 14, -13, 7, -16, 13, -9, 5, -11, 10, -9, 6, -12, 13 },
+ { -10, -4, 5, 3, 1, 6, 8, -14, -5, 15, 7, 4, 8, 7, -22, 8,
+ -7, -8, -15, 26, 1, 13, -3, 17, -5, 9, -2, 4, -6, 3, -8, 9 },
+ { 8, -3, 2, 3, 3, 1, -2, -1, -11, 8, -4, 0, -6, -5, -1, 13,
+ -37, 9, 1, -6, -10, -2, -10, 11, 8, 13, -3, -2, -6, 8, -4, 13 },
+ { 3, 2, -3, -4, -4, 7, -8, 9, -8, 9, -20, 12, -19, 15, -18, 17,
+ -15, 7, -1, 20, -11, 6, -6, 3, 1, 9, 2, -14, -2, -2, 2, 1 },
+ { -7, 1, -1, -3, -6, 4, 4, -3, 3, -1, 5, -4, 3, 2, -1, 9,
+ -59, 5, -4, 30, 3, 3, -2, -3, -1, 2, 2, 1, -1, -1, -2, 1 },
+ { 0, -3, 2, 0, -1, -8, 0, 2, -3, 4, -4, 1, 10, 6, -6, 8,
+ -7, 4, 10, 11, -41, 27, -20, 3, -3, 8, 1, 11, -5, -8, 0, 4 },
+ { 5, 1, 4, -2, 1, 2, -1, 6, -7, 2, 11, 4, 0, 0, -8, 7,
+ -10, 0, 0, 8, 2, 10, -1, 1, -2, 44, -2, -21, -12, -3, -1, 2 },
+ { -4, 4, -2, -2, 6, -8, 2, 1, -10, 14, 8, 6, 5, 1, -2, 4,
+ -13, 4, 2, 5, 10, -2, -21, 32, -3, 18, 9, -6, -9, -9, 10, 2 },
+ { 9, -16, -6, -2, 1, 4, 22, 2, -2, 1, -3, -2, -9, 3, 16, 19,
+ -24, -6, -6, -5, -8, -7, 8, -7, -1, -12, 5, -3, 0, 4, 2, -3 },
+ { 10, 3, -16, -4, -1, 13, 4, 4, 1, -3, 1, -6, -14, 18, 3, 8,
+ -8, -28, -16, 4, 4, 2, 12, 7, 9, -4, -4, 5, -1, -1, 2, 2 },
+ { -5, -13, -22, -3, -8, 21, -2, -9, 21, -4, -9, 5, -8, 15, 5, 1,
+ -5, -9, -7, -2, -5, -5, -1, -5, -5, -5, 3, 10, -4, 0, -7, -2 },
+ { 5, -10, -18, 2, 20, 4, 13, -10, 8, -15, -11, -3, -1, 16, 10, 9,
+ -8, 6, 7, -5, 6, 11, 5, 17, -4, 7, -11, 5, -3, -6, 2, 1 },
+ { 3, -5, -19, 1, 1, -3, -2, -25, -11, -17, 0, -13, -4, 10, 10, 2,
+ -5, 4, 0, 3, -3, -5, -10, -2, 13, -22, 0, 3, -11, -5, 7, -1 },
+ { 12, -14, -29, 6, -1, 10, 7, -17, -12, 14, 3, 9, -9, 9, 7, 6,
+ -3, -13, 0, 5, 3, -1, -6, -1, 0, 2, 4, -12, -5, -1, 2, 11 },
+ { 12, -15, -7, -2, -12, 17, 20, -16, -2, -12, -6, 15, -6, 12, 11, 9,
+ 7, -6, 7, -4, -19, 6, 2, 2, 3, -11, -10, -4, -5, -3, 3, 2 },
+ { 11, -22, -6, 0, 8, 18, 3, -11, -4, -7, -15, -17, -12, 6, 16, 4,
+ -9, 4, -5, 3, 6, -16, 10, -7, -7, -3, 5, 0, 1, -15, -4, 5 },
+ { 12, -22, -16, 5, -6, 8, 12, -4, -9, -17, -11, 3, 5, 8, -17, 0,
+ 11, -4, -13, -6, 2, -1, -1, 3, 3, -11, -12, -1, 1, 1, 12, -2 },
+ { 8, -10, -33, -5, -3, -6, 1, -7, -8, -4, -6, -1, 5, -4, -6, -12,
+ -16, -8, 11, 8, -14, 7, 12, 11, 4, -14, -3, 6, -7, -5, -3, 3 },
+ { 0, -8, -7, 2, -4, 24, 2, -9, -11, -3, -7, 11, -12, 17, 1, -1,
+ 3, -5, -7, 12, 4, 11, 0, 3, 2, -18, -3, 4, 7, -6, 3, 15 },
+ { 10, -15, -16, -2, -4, -9, 7, -15, -6, 2, -16, 13, -8, 7, 19, -21,
+ -4, -12, -9, -3, -3, 6, 11, -3, -1, -19, 3, -7, -9, -4, 3, -6 },
+ { -5, -10, -21, 0, -3, -7, 18, -21, 15, -5, -12, -4, -13, 2, 6, -9,
+ -9, -11, -4, 13, -3, 6, 4, -1, 7, -9, -4, 9, 5, 2, 6, 3 },
+ { 15, -1, -27, -2, 10, 3, 7, -8, 9, -2, 7, 1, -2, -5, 18, 9,
+ -11, -17, -2, 7, -9, 11, 10, 0, -8, 6, -16, -3, 2, -7, 3, 11 },
+ { 4, -9, -39, 19, 6, -13, 13, -5, -5, -15, -2, 9, 0, 4, 14, 6,
+ -10, -4, -5, 2, -4, -2, 5, -11, 3, 3, -2, -2, -7, 9, 7, -10 },
+ { 5, -11, -8, 10, -2, 12, 16, 0, 12, -2, -6, 8, 14, 8, 7, 1,
+ 18, -30, 4, 10, -4, -6, 2, -11, 9, -10, -8, 5, 0, 0, -7, 6 },
+ { -1, -16, -10, 11, 0, 13, 12, -4, -4, -5, -21, 12, 4, 13, 14, -7,
+ 6, -16, -13, 8, 2, 9, 15, -12, 1, -9, -22, 10, -9, 9, 9, -7 },
+ { 4, -12, -27, 1, -2, 11, 15, 3, 14, -14, -9, 0, -9, 16, 22, 10,
+ 16, -10, 5, -5, -9, 1, 1, 6, 6, -4, 2, -17, -5, -6, -15, -1 },
+ { 7, -12, -17, 1, -9, 5, 20, -7, 3, 23, -8, -8, -8, -1, 13, 17,
+ -7, -13, 4, -4, 7, 14, 8, 11, -3, -3, 4, 0, 4, 6, -1, -9 },
+ { 7, -15, -15, -4, 10, 12, 3, -13, 6, 14, 9, -8, -15, 14, 23, -5,
+ -10, -5, 1, 15, -10, -7, 1, 9, 4, -13, -10, 10, 7, -3, 2, 3 },
+ { 4, -10, -14, 0, 3, 4, 0, -9, -3, -4, -11, 2, -17, 8, 2, 15,
+ 6, -12, -12, 15, -5, 17, 18, 3, -3, -3, -4, -6, -8, 13, 4, 10 },
+ { -2, -18, -26, 10, -4, 10, 13, 4, -4, -16, -7, -17, -3, 5, -4, 2,
+ -15, -10, -1, -8, -7, -3, 2, 2, 8, -10, -7, 2, 2, -4, 4, -1 },
+ { 4, -19, -5, -1, -1, -6, 2, -8, 10, -16, -28, -6, 8, -1, 11, 28,
+ 2, -10, -4, 6, -6, 6, 11, 15, -4, -2, 7, 3, 7, -7, 4, 1 },
+ { -3, -6, -10, -5, 13, 18, 10, -15, -5, -3, -13, 5, 1, 2, 18, -5,
+ -10, -10, -7, 4, 2, 1, 5, 4, 2, 5, 4, 8, -9, -17, 7, 7 },
+ { 20, -12, -2, -4, 5, 14, 7, -11, -1, -16, -6, -4, -11, 17, 14, 0,
+ -8, -10, -8, 10, 3, 5, 10, -16, 3, -8, -14, 10, 3, 9, 0, 3 },
+ { 12, -10, -36, 0, 7, 15, 2, -16, 2, -1, 0, -1, 5, 4, 5, -3,
+ 1, -10, 5, -1, -15, -3, -12, 12, 2, 5, -1, 5, 6, -3, -2, 2 },
+ { 17, -15, -31, 23, -4, 15, -2, -3, 6, -7, -5, 1, -12, 4, 6, 8,
+ -10, 8, 3, 5, -4, 1, 5, 3, -1, -4, -3, 1, 10, -4, -2, -2 },
+ { 6, -18, -5, 12, 10, 12, 14, -11, 15, 2, -9, -6, -5, -2, -9, 4,
+ -5, -28, -4, 14, 0, -16, 9, 14, -1, 3, -4, -4, 2, 1, 0, 4 },
+ { -5, -14, -31, 8, 16, 7, 13, -13, 5, 6, -16, 10, -5, 2, -2, 2,
+ 14, -5, 8, -5, 7, -16, 6, -13, -5, 0, -5, 8, -3, -1, 4, 3 },
+ { 1, -2, -1, 0, 6, 5, 2, -4, -3, -1, 0, 1, 4, 2, 43, 28,
+ -12, -35, -2, -2, -7, -1, 0, 2, -1, -2, -2, 1, -4, 0, -2, 3 },
+ { 2, -9, -22, 12, 3, 3, -7, -4, -19, -22, -14, -4, -1, 21, 9, -3,
+ -15, -16, -13, 1, -11, 4, -9, 1, -7, -1, -1, 0, -2, 9, -13, -3 },
+ { -1, -3, -23, 0, 2, 12, 3, -9, -4, 7, 3, 9, -10, 1, 27, 28,
+ 0, 9, -15, -2, -2, 1, 6, 8, -8, 7, -3, 20, 0, 0, -1, -6 },
+ { -1, 11, 8, -2, 1, 5, -6, -1, 4, 2, -4, 0, -1, -5, 4, -6,
+ -10, -12, 19, 1, -7, 9, -8, -9, -16, -11, -2, 12, 14, 4, 4, 34 },
+ { 17, 7, -6, 1, 4, -10, -5, 4, -11, 3, -18, 4, 14, -13, -3, 1,
+ 0, 0, -11, 0, 7, -17, -4, 4, -11, -6, -8, 18, 0, 0, 0, 26 },
+ { -6, -7, -1, -1, 11, -8, 1, 3, 2, 11, -6, -6, 10, -3, 1, -3,
+ 7, 4, -12, -8, 0, -9, 8, -22, -5, 0, -6, 22, -2, 11, -13, 24 },
+ { -3, 4, 0, 3, 9, 10, -1, 3, -9, -12, 1, -5, 18, 0, -3, 8,
+ 25, 15, -8, 2, 2, -2, 4, 8, 9, -1, -5, 10, -3, 1, -1, 23 },
+ { -5, 2, -9, -1, -3, 0, 3, -1, -10, -4, 0, -13, 16, 9, -1, -14,
+ 2, 6, -2, -6, -5, -2, -7, 7, 5, 3, 11, -2, -14, 0, -9, 30 },
+ { 4, 6, 6, 5, -3, -1, 4, 5, 10, 0, 5, -4, 7, -11, 14, 14,
+ 7, 34, -9, 0, -10, 22, -7, -1, 7, -9, 2, -8, 0, -7, -5, 29 },
+ { -4, 3, -1, -4, -3, 5, 1, -4, 0, 2, 4, 2, 1, -1, -10, 1,
+ 6, -6, -4, 1, 4, -3, -3, -5, 0, 3, 7, -12, 0, -2, -10, 55 },
+ { 5, 9, -1, 0, 4, 9, -21, -9, 4, 2, 6, -7, 11, -7, 1, -5,
+ 0, -4, 2, -3, -13, -8, 0, -9, -4, 2, 16, -2, -15, -7, -11, 31 },
+ { 8, 2, -1, 0, 3, -5, -5, 5, 1, -1, -9, 1, 0, -6, -2, -1,
+ 5, 2, 0, 0, 12, 20, -19, 1, 8, -12, -11, 0, 6, -5, 2, 31 },
+ { -1, -1, -2, 1, -1, 3, -9, -5, 8, -2, 5, -1, 0, -2, 4, -2,
+ -3, -12, 0, -2, 3, 0, 9, 4, -1, 21, -8, 3, -4, 9, -6, 30 },
+ { -4, 0, -7, 17, 10, -12, -2, -10, -12, -3, 10, 0, 11, -4, -13, -3,
+ 5, 6, 10, 7, -8, 0, -7, -13, 1, 0, -2, 7, -12, 4, -3, 24 },
+ { -13, 9, 4, -2, 2, -4, -14, -1, -3, -5, -10, 4, 13, -2, 5, 13,
+ 8, 3, -2, 1, 5, -6, 7, -18, -10, 1, -1, 5, 4, 1, 0, 25 },
+ { -5, -1, 18, 12, 8, 8, -16, -1, 1, 1, 1, -4, -5, 3, 3, 4,
+ 4, -11, -12, -16, -6, 2, 12, -13, 0, 9, 7, 9, -9, 0, -10, 24 },
+ { -4, 1, -3, 0, 2, -4, 4, 1, 5, 0, -3, 2, -3, -2, 2, -1,
+ 1, 4, -1, -2, -2, 1, -1, -1, -4, -1, -4, -2, -6, 6, 12, 69 },
+ { 8, 5, 11, 0, -15, -4, 13, 6, 0, -4, 9, 1, -5, -3, 15, 0,
+ 1, 6, -5, 0, 1, 6, 5, 8, 0, 7, 1, -1, -4, -11, -9, 41 },
+ { -4, -9, 32, -6, 0, 7, -4, 6, -6, 1, -6, -2, 4, -8, -5, -3,
+ -16, -1, -2, -6, 1, 15, 0, 21, 3, -3, -4, 3, -12, 16, 2, 27 },
+ { -6, -5, 1, -9, -5, 3, 7, -3, 5, 5, 14, 13, 20, -7, -1, 12,
+ -1, 10, -11, -11, -7, -4, -14, 7, -14, 13, 22, 18, -1, 0, 14, 28 },
+ { -8, 3, -2, 0, 5, 6, -1, -4, 1, 3, -7, 3, 1, -15, 4, -9,
+ 22, -10, -9, -4, 1, 8, -4, 9, -15, 2, -6, -4, -16, 12, -10, 23 },
+ { 0, 0, 2, 0, -1, 3, -3, -1, 3, -5, 7, 1, 5, -5, -8, 1,
+ 13, -15, -5, -7, 12, -6, -2, 3, 10, -5, -8, 17, -5, -11, -14, 23 },
+ { -7, -4, 6, -4, 5, -6, -5, 2, -4, 11, 9, -4, 2, -2, -4, 6,
+ 15, 3, -3, 18, -15, -2, -6, 3, 3, -20, 17, 11, -4, 2, 3, 29 },
+ { 6, 1, -6, 2, 3, 0, 0, -3, 3, 3, -1, 3, -4, -6, -6, -7,
+ -3, -2, -7, -2, -4, 5, 3, -5, -20, -13, -4, 10, -14, -29, 14, 37 },
+ { 3, 4, 3, -6, -4, 5, 0, 3, 2, 3, 0, -2, 4, 0, -3, -5,
+ -4, 4, -4, 4, 4, 3, 1, -4, -4, -9, -14, 20, -30, 3, -18, 33 },
+ { 0, 2, 5, -2, -4, -2, -1, 2, -6, -3, -2, -2, 2, -5, -1, 4,
+ 3, 2, -3, 0, -1, -1, -10, -7, 2, -4, -18, 2, -37, -1, 12, 40 },
+ { -7, 2, -1, 0, -2, 4, -8, 1, -4, 12, 7, 4, 15, -7, 1, -9,
+ 18, 0, 12, -17, -3, -1, 0, 0, 0, 2, -6, 0, -4, -3, -1, 26 },
+ { -6, 4, 8, -5, -6, -2, 2, -1, 1, -1, -15, 8, 7, -1, -17, -4,
+ 1, 5, 6, -11, -6, 14, 17, -5, -15, 11, 8, 0, -3, -15, -6, 28 },
+ { -1, 0, 0, 0, 1, 0, -1, 0, 1, 3, 2, -2, 3, -1, -1, 2,
+ 2, -1, -1, -7, 1, 2, -9, 0, -1, -4, -18, 7, -10, 49, -13, 32 },
+ { -1, -3, 4, 1, 2, -5, 1, -7, -1, 5, -9, 4, 4, 25, 1, -1,
+ 2, -5, 2, -7, 17, -2, 10, -5, 0, 2, -15, 3, -9, 7, -9, 30 },
+ { -5, -1, 0, 2, 1, -1, 2, 5, -33, 3, -5, 14, 11, 7, 5, -3,
+ 2, -8, -4, -2, -7, -6, 4, -8, -1, -8, 2, -2, -8, -1, -4, 27 },
+ { -1, 0, -1, -2, 1, -1, -2, -1, 2, 0, 1, 2, 2, 4, 1, 3,
+ 4, 2, 1, -7, -4, 1, -3, -4, -35, -25, 17, 10, -3, -26, -7, 32 },
+ { -5, 1, 6, -2, 6, 6, -9, 3, -1, -4, 5, -4, -2, -2, -9, 2,
+ -5, 2, 2, 4, 3, 5, -5, -16, -31, -12, -11, 2, -19, 20, -2, 21 },
+ { -5, 2, 7, -7, -7, 5, -7, 2, 0, 0, -4, 3, -1, 0, -1, -2,
+ 0, -3, 5, -11, -8, -3, -7, -7, 28, -11, -7, 0, -16, -11, -4, 29 },
+ { 2, 1, -3, -2, -1, 3, 4, 0, 1, 0, -1, -5, 4, -5, -12, 2,
+ -2, -5, -22, -2, -1, 11, 8, -7, -12, 0, -34, 6, -5, 11, -8, 19 },
+ { -1, -3, 5, 11, 18, -2, -2, -5, -2, 4, -1, 8, 5, -6, 1, -1,
+ 2, 8, 4, -5, -8, -2, 5, -18, 7, 12, 7, 19, -18, 2, -6, -13 },
+ { 9, 0, 0, 5, 4, 3, -6, 4, 1, -4, 5, -1, -4, 8, 8, 6,
+ -8, -6, 0, 6, -3, 3, 5, -3, 17, 31, 16, 10, -13, 0, -9, -19 },
+ { 12, -10, 2, -2, -2, -1, -3, 6, -12, -5, -2, 14, -16, 4, 12, 12,
+ 17, 4, 7, -16, 7, -6, 11, 7, 7, 2, -25, 23, -24, 5, -7, -9 },
+ { 10, 4, 13, 10, 10, 3, -6, 3, 3, 2, -1, -6, 8, 4, 10, 0,
+ 1, 2, -4, 2, -3, -8, 0, -1, 9, 9, -10, -3, -29, 1, -1, -27 },
+ { 2, 2, 0, 7, 9, -2, -10, -1, -1, 1, -9, -5, 8, 4, 1, 2,
+ -10, 1, 13, 12, -3, 15, -9, 2, -7, 1, -10, 23, -20, -18, -9, -15 },
+ { -3, -5, -1, 8, 0, -5, -1, 4, 7, -1, -7, 2, -8, -5, 11, 7,
+ -6, 3, -3, -9, 7, 9, -22, 1, 6, -4, 14, 27, -25, -14, 3, -5 },
+ { 1, 3, 8, 4, 7, 6, 12, -17, -15, 1, -8, -10, 7, -14, -8, 6,
+ -2, -2, -11, -11, -7, 13, -2, -2, 4, 5, -5, 13, -23, -6, -17, -8 },
+ { -5, 4, -14, -5, -4, -5, 6, 5, -8, -5, -2, -11, -7, -12, 3, -11,
+ 2, -6, 4, -10, -5, -7, 14, 5, 23, 11, 7, 12, -16, -6, -4, -16 },
+ { 5, 6, 2, 5, -2, -5, -5, -6, -5, -19, -13, -1, -3, -13, 5, 0,
+ 6, -2, -2, -6, -7, -7, -1, -9, 4, 14, 17, -12, -27, 3, 0, -1 },
+ { 7, -1, 9, -10, 8, 2, -7, -2, 5, 2, -3, -7, 3, 0, 6, 4,
+ 12, 5, 11, 14, -13, -1, 8, 1, 13, 9, 12, 12, -18, -14, -11, -16 },
+ { -7, -5, -6, -5, 0, -1, -3, 2, 2, 1, 4, 9, 2, 3, 5, -2,
+ 2, 1, 8, 0, 3, 0, -2, 2, 1, 7, 29, 0, -36, -5, -9, -21 },
+ { 14, -6, -9, 0, -1, -8, -8, -11, 2, 2, -9, -12, 12, -4, 5, 3,
+ -5, -9, 11, -1, -3, 12, -21, -3, 12, 5, 3, 11, -18, -15, 1, -2 },
+ { -1, 3, -9, -3, 7, -7, -18, 2, 4, 12, -10, 2, 8, -3, -14, 13,
+ 17, -5, 5, -9, 13, -3, -7, -18, 17, -2, 5, 7, -20, -3, -6, -11 },
+ { -3, 3, 3, -1, 1, -6, -5, 1, 5, -3, -14, -6, -5, -8, 14, -6,
+ 7, -1, 5, 1, 15, -1, -7, -4, 6, -11, 9, -2, -37, 16, -7, -3 },
+ { -1, 0, 6, 1, -3, -9, 0, 11, -8, 2, -2, 0, 5, 2, 12, -10,
+ 10, 13, 2, 7, -6, 2, -10, -10, 21, -5, 5, 5, -12, -23, 3, -14 },
+ { 6, 0, -2, 1, 0, 1, 0, -4, 1, 1, 8, -2, 2, -5, -2, 1,
+ 8, -4, -1, -1, 4, -1, 2, 6, 32, 1, -5, -20, -40, -4, -18, -14 },
+ { 2, 2, -7, -2, 4, 4, -1, 2, 0, -2, -4, -7, 3, 5, 0, -5,
+ 1, 2, -6, 4, -1, -2, -1, -15, 8, 3, 9, 46, -7, -18, 6, -11 },
+ { 5, 5, 16, 21, 3, -11, -4, 11, -12, 2, 4, -12, -1, 11, 8, 1,
+ -4, 11, -11, -21, 1, 1, -11, 3, 13, 1, 5, 12, -25, 1, -3, -2 },
+ { 1, 6, -7, 4, 2, 3, 1, -5, 8, 9, -15, 3, -3, -14, 17, 4,
+ -8, 14, -2, -8, -4, 5, 8, -7, 8, 9, 7, 6, -29, -17, 8, 4 },
+ { -7, -7, 4, 0, 13, 1, 0, 4, 4, -16, -10, -7, 5, 9, -15, -10,
+ -10, 8, -4, -1, -11, -1, -10, -15, 3, 3, 14, 10, -19, 2, -18, -12 },
+ { -4, 0, 2, 0, 5, -2, -9, 0, 4, -4, 2, -1, -2, 2, -4, 9,
+ 2, -6, -4, -2, -1, -3, -3, -1, 2, 5, -1, 11, -24, -44, -9, -15 },
+ { -1, -10, 6, 21, 11, 15, -7, 10, -14, -9, -8, -8, 4, 6, 19, 1,
+ -6, 1, -5, -17, -8, -10, 9, 5, 11, 18, -1, 10, -16, -7, -9, -8 },
+ { 3, -5, 0, 0, -2, -2, -6, 4, -4, 1, -1, 0, 7, -3, 4, -4,
+ -7, 7, 17, -20, 6, 4, 1, -6, -12, 31, 13, 19, -14, -10, -7, -2 },
+ { -2, 6, -10, 3, 9, 6, -14, 15, 2, -5, 2, -11, 9, -8, 4, 6,
+ 20, -15, -3, -3, -1, 32, -21, 6, 1, 9, 11, 17, -19, 6, -1, -3 },
+ { 8, 10, -2, 0, -8, -16, 7, 7, 6, 10, 4, -14, 7, -6, 21, -7,
+ 10, 5, 5, 0, -7, 2, -6, 0, -7, 11, -9, 15, -20, -7, -11, 2 },
+ { 0, -7, 5, 2, 0, -3, -6, -4, -2, -1, -4, -5, -13, -1, 27, -9,
+ -6, -11, -7, 1, 11, -4, -4, -14, -2, 11, 6, 10, -19, -6, -15, 2 },
+ { 0, 7, -1, 2, -7, -15, -2, -3, 13, -5, -5, 12, 3, 0, 5, -5,
+ -22, 2, 7, 22, 13, 0, -1, 2, 3, 2, -7, 7, -27, -4, -4, -12 },
+ { 11, 1, -16, 6, -15, 1, 3, 2, 0, 2, -3, 2, 5, -2, -5, 9,
+ 5, -3, 3, -2, -11, 3, 9, 6, 9, 3, -1, 12, -41, 8, -6, 9 },
+ { 3, -7, 3, 2, 5, 5, 0, -1, 1, 3, -5, -2, -13, 7, -1, -2,
+ -2, -6, 4, -6, 0, 2, -2, 2, 4, 1, -4, 1, -47, -21, 7, -6 },
+ { 3, 16, -7, 13, -4, -2, 10, -3, -1, 18, -13, 7, -13, -4, 8, 4,
+ 8, 9, -5, 13, 8, -5, 3, -6, 7, 18, -8, 10, -25, -3, -12, -12 },
+ { 1, -1, -1, 0, 2, 5, -5, -3, 0, -5, -1, 0, -4, -8, -2, 3,
+ 2, -2, -17, -6, -4, 1, 33, -6, -20, -6, 8, 31, -26, -8, -1, -4 },
+ { 3, -3, -3, 5, -3, -2, 1, 7, 0, 3, 6, 3, 6, -2, 9, 15,
+ -10, -3, -15, -5, -3, -4, -6, -30, 17, -8, -2, 2, -20, 0, -8, -2 },
+ { -2, -1, -1, -1, 3, -5, -2, -3, 4, -2, 0, 5, 8, -3, 1, -4,
+ 1, 1, -3, 4, 4, -14, 3, 11, -5, 3, -3, 7, -3, 13, 23, -16 },
+ { 2, -6, 1, -3, 5, 0, -6, -11, -7, -4, -1, 2, -7, -1, -1, 7,
+ 1, -2, 6, 12, -6, 8, -13, 17, 25, -23, -19, -7, -12, 9, 16, -17 },
+ { 9, 4, 4, 4, -3, -1, 6, -2, -3, 0, 13, -4, -7, 14, 1, -7,
+ 0, -5, 3, -19, -3, 5, 3, 9, -1, 9, -13, 13, -17, 4, 21, -26 },
+ { 0, -5, 0, 0, -4, -5, 2, -6, -4, 5, -7, 10, 0, 2, 0, -2,
+ -2, 0, 4, -6, 7, -2, 6, 5, -5, 2, -12, 1, -29, 29, 27, 12 },
+ { 9, -10, -22, 6, -1, -1, 9, -14, -12, -2, 1, -1, 10, -11, -16, 0,
+ 3, 11, 13, -14, -9, -2, -1, 6, 4, -14, 0, -10, -2, 16, 17, -11 },
+ { 2, 0, -1, -2, 4, 3, -6, -2, 1, -1, 1, 3, -4, 1, 3, -4,
+ -1, -1, 4, -1, 1, 0, 1, 6, -5, -7, 2, 1, -47, -3, 50, -17 },
+ { 8, -4, -11, -7, 11, 11, 14, -7, 12, -7, 6, 2, 13, -6, -3, -2,
+ -14, 6, 6, 6, 0, 2, -1, 5, -20, 2, -1, 4, -5, 6, 21, -11 },
+ { -2, -9, 3, 0, -6, 7, 8, -8, 1, -3, 4, 1, 5, -2, -3, -7,
+ 4, 7, -12, -9, -2, 10, -6, 13, 6, 5, 20, 2, -15, 9, 28, -7 },
+ { 0, -5, -6, -6, -6, 1, -6, 6, -2, 4, 8, -3, 12, -1, -4, -2,
+ 6, 16, -14, 9, -14, -2, -8, -27, -3, 18, -1, -7, -3, 8, 23, -23 },
+ { 1, 4, -9, -1, -5, 10, -2, 1, -11, 1, -9, 4, 7, 14, -9, -2,
+ -3, 2, -5, -1, -6, -10, -7, 11, 20, 2, 3, -19, 3, 15, 30, -9 },
+ { 7, 2, -14, -4, 0, -2, 5, 2, 5, -2, 8, -3, -7, 6, 6, -11,
+ -14, 1, 10, -1, -7, -8, 1, 10, 3, -6, -15, -12, -17, 4, 30, -6 },
+ { 4, 2, 1, -2, 3, 0, 1, 0, 2, 0, 1, 6, -7, 0, 3, 4,
+ 4, -4, -2, -5, -2, 2, -1, -2, 0, -2, -11, -7, -3, 42, 24, -14 },
+ { 4, 1, 3, 2, 0, -2, -3, -2, 2, -1, 4, 11, -2, 2, 3, -4,
+ -5, 9, 2, -4, -9, 5, 8, -1, -7, 1, 24, -13, -28, 20, 15, -22 },
+ { -3, 7, 6, 3, -2, -5, -10, -2, -2, -1, -6, -6, -2, -14, -16, -6,
+ -5, 0, 18, 0, 9, 1, 7, -13, -5, -6, -9, 11, -15, 9, 22, -11 },
+ { 9, -2, 6, 5, 2, 9, -10, 1, 1, 5, -4, 12, 2, 2, -10, -7,
+ -4, -6, 7, 9, 6, 15, 6, 6, -10, 10, 5, -13, -5, 6, 24, -12 },
+ { 1, 3, -3, -3, 8, 1, -6, 2, -5, -3, 7, 2, 14, 6, 9, -6,
+ -5, -4, 27, 7, -3, 8, -6, 3, -8, 8, 22, -5, -6, -2, 22, -17 },
+ { -2, -2, 3, 10, 9, 9, 12, -15, -1, -11, -13, 3, -2, 1, -3, -11,
+ 7, 9, 16, -3, -10, -5, -5, 1, 8, -3, 9, 9, -5, 3, 31, -12 },
+ { 7, -5, 10, -4, -8, 2, 16, -2, 10, 10, -3, -2, 3, -8, -3, 3,
+ -13, -6, 15, 20, -9, -3, -12, 1, -2, -16, 8, 8, -1, 16, 22, -5 },
+ { 5, -3, -15, -2, 12, -8, 8, -5, 2, -8, 20, -18, 14, -4, 3, 3,
+ 7, -13, -16, 1, -10, 7, 16, 7, 4, -14, -4, -5, -9, 8, 23, -6 },
+ { 5, -4, -5, -4, 1, 8, 4, -7, -5, 8, 10, 6, -6, -10, -2, 6,
+ 9, -17, -14, 11, 12, -3, -13, -7, 2, 18, 3, -25, -16, 18, 22, -5 },
+ { 5, 6, -7, -20, -4, 2, 8, 4, -24, -4, 1, 4, -5, -2, 1, -10,
+ -2, 9, 3, -4, -3, -4, -4, -4, 10, 10, 3, 0, -6, 25, 21, -11 },
+ { 0, 7, -1, 14, -6, -4, -10, 5, 4, 4, 4, -5, 3, 4, -1, -7,
+ 8, -19, 0, 6, 2, 3, -18, -3, -6, 2, 8, 14, -26, 22, 27, -13 },
+ { -2, -6, 7, -5, 12, -7, 8, -1, 3, -2, 4, 1, 8, -2, 0, 14,
+ 6, -5, 6, -4, -7, 7, -21, 8, 1, 8, -9, -4, -3, 11, 25, -13 },
+ { 4, 4, -1, -6, 4, 9, -8, 1, -3, -10, -2, 0, 15, -9, -16, 11,
+ 1, 1, 6, 3, -9, -5, 16, 26, 1, -14, 1, -3, -14, 7, 15, -9 },
+ { -12, -2, -9, -13, 2, 6, 14, 0, 1, 0, -1, -13, 0, 10, -1, 6,
+ 9, -7, 8, 8, 19, 6, -1, 9, 10, -4, 1, -7, -22, -2, 29, -7 },
+ { 2, 4, 13, -12, -8, -4, -5, 13, 12, -5, -3, -3, -4, 1, -1, 10,
+ 15, -6, -1, -11, -30, 4, 15, -1, 9, -7, 0, -2, -7, 10, 25, -16 },
+ { 7, -15, -7, -7, -1, -5, -5, -11, -20, 10, 3, -10, -3, 5, 20, -4,
+ 0, -2, -2, 17, 2, 0, -3, 3, 6, 5, -1, -12, -3, 15, 22, -16 },
+ { 4, -1, 3, 4, -5, 0, -1, -5, -24, -29, 4, -9, 1, -3, 0, 0,
+ 0, -4, 7, -4, -4, -4, 3, 1, -6, 5, -3, -5, -10, 3, 25, -10 },
+ { -2, -1, -1, 4, 4, -1, 2, 0, -4, -4, 2, -1, -3, -1, -2, -2,
+ 1, -3, -5, -1, 2, -3, -4, -4, -3, 5, -9, 1, -11, 7, 46, -46 },
+ { 0, -9, 3, 4, 4, 3, -5, -6, 5, -4, 4, -2, 1, 7, -4, -10,
+ 13, 1, 3, -6, 4, -4, 7, 2, -19, -25, -3, -16, -12, 16, 20, -1 },
+ { 18, 6, 4, -12, 0, -14, 9, -6, -1, -4, -5, 2, 1, 12, 4, 2,
+ 7, 0, 2, 5, -11, -5, -2, 2, -4, 10, 0, -9, -7, 9, 25, -8 },
+ { 5, 0, -6, 5, 6, 3, 3, -10, -5, 1, -1, 4, 3, -11, -8, 5,
+ 4, -5, 5, -5, -7, -5, 11, 5, 20, -8, -16, 21, -4, 27, 23, -5 }
+};
diff --git a/contrib/libmad/COPYING b/contrib/libmad/COPYING
new file mode 100644
index 000000000..d60c31a97
--- /dev/null
+++ b/contrib/libmad/COPYING
@@ -0,0 +1,340 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/contrib/libmad/D.dat b/contrib/libmad/D.dat
new file mode 100644
index 000000000..4a7fa4fa9
--- /dev/null
+++ b/contrib/libmad/D.dat
@@ -0,0 +1,607 @@
+/*
+ * libmad - MPEG audio decoder library
+ * Copyright (C) 2000-2004 Underbit Technologies, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: D.dat,v 1.9 2004/01/23 09:41:32 rob Exp $
+ */
+
+/*
+ * These are the coefficients for the subband synthesis window. This is a
+ * reordered version of Table B.3 from ISO/IEC 11172-3.
+ *
+ * Every value is parameterized so that shift optimizations can be made at
+ * compile-time. For example, every value can be right-shifted 12 bits to
+ * minimize multiply instruction times without any loss of accuracy.
+ */
+
+ { PRESHIFT(0x00000000) /* 0.000000000 */, /* 0 */
+ -PRESHIFT(0x0001d000) /* -0.000442505 */,
+ PRESHIFT(0x000d5000) /* 0.003250122 */,
+ -PRESHIFT(0x001cb000) /* -0.007003784 */,
+ PRESHIFT(0x007f5000) /* 0.031082153 */,
+ -PRESHIFT(0x01421000) /* -0.078628540 */,
+ PRESHIFT(0x019ae000) /* 0.100311279 */,
+ -PRESHIFT(0x09271000) /* -0.572036743 */,
+ PRESHIFT(0x1251e000) /* 1.144989014 */,
+ PRESHIFT(0x09271000) /* 0.572036743 */,
+ PRESHIFT(0x019ae000) /* 0.100311279 */,
+ PRESHIFT(0x01421000) /* 0.078628540 */,
+ PRESHIFT(0x007f5000) /* 0.031082153 */,
+ PRESHIFT(0x001cb000) /* 0.007003784 */,
+ PRESHIFT(0x000d5000) /* 0.003250122 */,
+ PRESHIFT(0x0001d000) /* 0.000442505 */,
+
+ PRESHIFT(0x00000000) /* 0.000000000 */,
+ -PRESHIFT(0x0001d000) /* -0.000442505 */,
+ PRESHIFT(0x000d5000) /* 0.003250122 */,
+ -PRESHIFT(0x001cb000) /* -0.007003784 */,
+ PRESHIFT(0x007f5000) /* 0.031082153 */,
+ -PRESHIFT(0x01421000) /* -0.078628540 */,
+ PRESHIFT(0x019ae000) /* 0.100311279 */,
+ -PRESHIFT(0x09271000) /* -0.572036743 */,
+ PRESHIFT(0x1251e000) /* 1.144989014 */,
+ PRESHIFT(0x09271000) /* 0.572036743 */,
+ PRESHIFT(0x019ae000) /* 0.100311279 */,
+ PRESHIFT(0x01421000) /* 0.078628540 */,
+ PRESHIFT(0x007f5000) /* 0.031082153 */,
+ PRESHIFT(0x001cb000) /* 0.007003784 */,
+ PRESHIFT(0x000d5000) /* 0.003250122 */,
+ PRESHIFT(0x0001d000) /* 0.000442505 */ },
+
+ { -PRESHIFT(0x00001000) /* -0.000015259 */, /* 1 */
+ -PRESHIFT(0x0001f000) /* -0.000473022 */,
+ PRESHIFT(0x000da000) /* 0.003326416 */,
+ -PRESHIFT(0x00207000) /* -0.007919312 */,
+ PRESHIFT(0x007d0000) /* 0.030517578 */,
+ -PRESHIFT(0x0158d000) /* -0.084182739 */,
+ PRESHIFT(0x01747000) /* 0.090927124 */,
+ -PRESHIFT(0x099a8000) /* -0.600219727 */,
+ PRESHIFT(0x124f0000) /* 1.144287109 */,
+ PRESHIFT(0x08b38000) /* 0.543823242 */,
+ PRESHIFT(0x01bde000) /* 0.108856201 */,
+ PRESHIFT(0x012b4000) /* 0.073059082 */,
+ PRESHIFT(0x0080f000) /* 0.031478882 */,
+ PRESHIFT(0x00191000) /* 0.006118774 */,
+ PRESHIFT(0x000d0000) /* 0.003173828 */,
+ PRESHIFT(0x0001a000) /* 0.000396729 */,
+
+ -PRESHIFT(0x00001000) /* -0.000015259 */,
+ -PRESHIFT(0x0001f000) /* -0.000473022 */,
+ PRESHIFT(0x000da000) /* 0.003326416 */,
+ -PRESHIFT(0x00207000) /* -0.007919312 */,
+ PRESHIFT(0x007d0000) /* 0.030517578 */,
+ -PRESHIFT(0x0158d000) /* -0.084182739 */,
+ PRESHIFT(0x01747000) /* 0.090927124 */,
+ -PRESHIFT(0x099a8000) /* -0.600219727 */,
+ PRESHIFT(0x124f0000) /* 1.144287109 */,
+ PRESHIFT(0x08b38000) /* 0.543823242 */,
+ PRESHIFT(0x01bde000) /* 0.108856201 */,
+ PRESHIFT(0x012b4000) /* 0.073059082 */,
+ PRESHIFT(0x0080f000) /* 0.031478882 */,
+ PRESHIFT(0x00191000) /* 0.006118774 */,
+ PRESHIFT(0x000d0000) /* 0.003173828 */,
+ PRESHIFT(0x0001a000) /* 0.000396729 */ },
+
+ { -PRESHIFT(0x00001000) /* -0.000015259 */, /* 2 */
+ -PRESHIFT(0x00023000) /* -0.000534058 */,
+ PRESHIFT(0x000de000) /* 0.003387451 */,
+ -PRESHIFT(0x00245000) /* -0.008865356 */,
+ PRESHIFT(0x007a0000) /* 0.029785156 */,
+ -PRESHIFT(0x016f7000) /* -0.089706421 */,
+ PRESHIFT(0x014a8000) /* 0.080688477 */,
+ -PRESHIFT(0x0a0d8000) /* -0.628295898 */,
+ PRESHIFT(0x12468000) /* 1.142211914 */,
+ PRESHIFT(0x083ff000) /* 0.515609741 */,
+ PRESHIFT(0x01dd8000) /* 0.116577148 */,
+ PRESHIFT(0x01149000) /* 0.067520142 */,
+ PRESHIFT(0x00820000) /* 0.031738281 */,
+ PRESHIFT(0x0015b000) /* 0.005294800 */,
+ PRESHIFT(0x000ca000) /* 0.003082275 */,
+ PRESHIFT(0x00018000) /* 0.000366211 */,
+
+ -PRESHIFT(0x00001000) /* -0.000015259 */,
+ -PRESHIFT(0x00023000) /* -0.000534058 */,
+ PRESHIFT(0x000de000) /* 0.003387451 */,
+ -PRESHIFT(0x00245000) /* -0.008865356 */,
+ PRESHIFT(0x007a0000) /* 0.029785156 */,
+ -PRESHIFT(0x016f7000) /* -0.089706421 */,
+ PRESHIFT(0x014a8000) /* 0.080688477 */,
+ -PRESHIFT(0x0a0d8000) /* -0.628295898 */,
+ PRESHIFT(0x12468000) /* 1.142211914 */,
+ PRESHIFT(0x083ff000) /* 0.515609741 */,
+ PRESHIFT(0x01dd8000) /* 0.116577148 */,
+ PRESHIFT(0x01149000) /* 0.067520142 */,
+ PRESHIFT(0x00820000) /* 0.031738281 */,
+ PRESHIFT(0x0015b000) /* 0.005294800 */,
+ PRESHIFT(0x000ca000) /* 0.003082275 */,
+ PRESHIFT(0x00018000) /* 0.000366211 */ },
+
+ { -PRESHIFT(0x00001000) /* -0.000015259 */, /* 3 */
+ -PRESHIFT(0x00026000) /* -0.000579834 */,
+ PRESHIFT(0x000e1000) /* 0.003433228 */,
+ -PRESHIFT(0x00285000) /* -0.009841919 */,
+ PRESHIFT(0x00765000) /* 0.028884888 */,
+ -PRESHIFT(0x0185d000) /* -0.095169067 */,
+ PRESHIFT(0x011d1000) /* 0.069595337 */,
+ -PRESHIFT(0x0a7fe000) /* -0.656219482 */,
+ PRESHIFT(0x12386000) /* 1.138763428 */,
+ PRESHIFT(0x07ccb000) /* 0.487472534 */,
+ PRESHIFT(0x01f9c000) /* 0.123474121 */,
+ PRESHIFT(0x00fdf000) /* 0.061996460 */,
+ PRESHIFT(0x00827000) /* 0.031845093 */,
+ PRESHIFT(0x00126000) /* 0.004486084 */,
+ PRESHIFT(0x000c4000) /* 0.002990723 */,
+ PRESHIFT(0x00015000) /* 0.000320435 */,
+
+ -PRESHIFT(0x00001000) /* -0.000015259 */,
+ -PRESHIFT(0x00026000) /* -0.000579834 */,
+ PRESHIFT(0x000e1000) /* 0.003433228 */,
+ -PRESHIFT(0x00285000) /* -0.009841919 */,
+ PRESHIFT(0x00765000) /* 0.028884888 */,
+ -PRESHIFT(0x0185d000) /* -0.095169067 */,
+ PRESHIFT(0x011d1000) /* 0.069595337 */,
+ -PRESHIFT(0x0a7fe000) /* -0.656219482 */,
+ PRESHIFT(0x12386000) /* 1.138763428 */,
+ PRESHIFT(0x07ccb000) /* 0.487472534 */,
+ PRESHIFT(0x01f9c000) /* 0.123474121 */,
+ PRESHIFT(0x00fdf000) /* 0.061996460 */,
+ PRESHIFT(0x00827000) /* 0.031845093 */,
+ PRESHIFT(0x00126000) /* 0.004486084 */,
+ PRESHIFT(0x000c4000) /* 0.002990723 */,
+ PRESHIFT(0x00015000) /* 0.000320435 */ },
+
+ { -PRESHIFT(0x00001000) /* -0.000015259 */, /* 4 */
+ -PRESHIFT(0x00029000) /* -0.000625610 */,
+ PRESHIFT(0x000e3000) /* 0.003463745 */,
+ -PRESHIFT(0x002c7000) /* -0.010848999 */,
+ PRESHIFT(0x0071e000) /* 0.027801514 */,
+ -PRESHIFT(0x019bd000) /* -0.100540161 */,
+ PRESHIFT(0x00ec0000) /* 0.057617187 */,
+ -PRESHIFT(0x0af15000) /* -0.683914185 */,
+ PRESHIFT(0x12249000) /* 1.133926392 */,
+ PRESHIFT(0x075a0000) /* 0.459472656 */,
+ PRESHIFT(0x0212c000) /* 0.129577637 */,
+ PRESHIFT(0x00e79000) /* 0.056533813 */,
+ PRESHIFT(0x00825000) /* 0.031814575 */,
+ PRESHIFT(0x000f4000) /* 0.003723145 */,
+ PRESHIFT(0x000be000) /* 0.002899170 */,
+ PRESHIFT(0x00013000) /* 0.000289917 */,
+
+ -PRESHIFT(0x00001000) /* -0.000015259 */,
+ -PRESHIFT(0x00029000) /* -0.000625610 */,
+ PRESHIFT(0x000e3000) /* 0.003463745 */,
+ -PRESHIFT(0x002c7000) /* -0.010848999 */,
+ PRESHIFT(0x0071e000) /* 0.027801514 */,
+ -PRESHIFT(0x019bd000) /* -0.100540161 */,
+ PRESHIFT(0x00ec0000) /* 0.057617187 */,
+ -PRESHIFT(0x0af15000) /* -0.683914185 */,
+ PRESHIFT(0x12249000) /* 1.133926392 */,
+ PRESHIFT(0x075a0000) /* 0.459472656 */,
+ PRESHIFT(0x0212c000) /* 0.129577637 */,
+ PRESHIFT(0x00e79000) /* 0.056533813 */,
+ PRESHIFT(0x00825000) /* 0.031814575 */,
+ PRESHIFT(0x000f4000) /* 0.003723145 */,
+ PRESHIFT(0x000be000) /* 0.002899170 */,
+ PRESHIFT(0x00013000) /* 0.000289917 */ },
+
+ { -PRESHIFT(0x00001000) /* -0.000015259 */, /* 5 */
+ -PRESHIFT(0x0002d000) /* -0.000686646 */,
+ PRESHIFT(0x000e4000) /* 0.003479004 */,
+ -PRESHIFT(0x0030b000) /* -0.011886597 */,
+ PRESHIFT(0x006cb000) /* 0.026535034 */,
+ -PRESHIFT(0x01b17000) /* -0.105819702 */,
+ PRESHIFT(0x00b77000) /* 0.044784546 */,
+ -PRESHIFT(0x0b619000) /* -0.711318970 */,
+ PRESHIFT(0x120b4000) /* 1.127746582 */,
+ PRESHIFT(0x06e81000) /* 0.431655884 */,
+ PRESHIFT(0x02288000) /* 0.134887695 */,
+ PRESHIFT(0x00d17000) /* 0.051132202 */,
+ PRESHIFT(0x0081b000) /* 0.031661987 */,
+ PRESHIFT(0x000c5000) /* 0.003005981 */,
+ PRESHIFT(0x000b7000) /* 0.002792358 */,
+ PRESHIFT(0x00011000) /* 0.000259399 */,
+
+ -PRESHIFT(0x00001000) /* -0.000015259 */,
+ -PRESHIFT(0x0002d000) /* -0.000686646 */,
+ PRESHIFT(0x000e4000) /* 0.003479004 */,
+ -PRESHIFT(0x0030b000) /* -0.011886597 */,
+ PRESHIFT(0x006cb000) /* 0.026535034 */,
+ -PRESHIFT(0x01b17000) /* -0.105819702 */,
+ PRESHIFT(0x00b77000) /* 0.044784546 */,
+ -PRESHIFT(0x0b619000) /* -0.711318970 */,
+ PRESHIFT(0x120b4000) /* 1.127746582 */,
+ PRESHIFT(0x06e81000) /* 0.431655884 */,
+ PRESHIFT(0x02288000) /* 0.134887695 */,
+ PRESHIFT(0x00d17000) /* 0.051132202 */,
+ PRESHIFT(0x0081b000) /* 0.031661987 */,
+ PRESHIFT(0x000c5000) /* 0.003005981 */,
+ PRESHIFT(0x000b7000) /* 0.002792358 */,
+ PRESHIFT(0x00011000) /* 0.000259399 */ },
+
+ { -PRESHIFT(0x00001000) /* -0.000015259 */, /* 6 */
+ -PRESHIFT(0x00031000) /* -0.000747681 */,
+ PRESHIFT(0x000e4000) /* 0.003479004 */,
+ -PRESHIFT(0x00350000) /* -0.012939453 */,
+ PRESHIFT(0x0066c000) /* 0.025085449 */,
+ -PRESHIFT(0x01c67000) /* -0.110946655 */,
+ PRESHIFT(0x007f5000) /* 0.031082153 */,
+ -PRESHIFT(0x0bd06000) /* -0.738372803 */,
+ PRESHIFT(0x11ec7000) /* 1.120223999 */,
+ PRESHIFT(0x06772000) /* 0.404083252 */,
+ PRESHIFT(0x023b3000) /* 0.139450073 */,
+ PRESHIFT(0x00bbc000) /* 0.045837402 */,
+ PRESHIFT(0x00809000) /* 0.031387329 */,
+ PRESHIFT(0x00099000) /* 0.002334595 */,
+ PRESHIFT(0x000b0000) /* 0.002685547 */,
+ PRESHIFT(0x00010000) /* 0.000244141 */,
+
+ -PRESHIFT(0x00001000) /* -0.000015259 */,
+ -PRESHIFT(0x00031000) /* -0.000747681 */,
+ PRESHIFT(0x000e4000) /* 0.003479004 */,
+ -PRESHIFT(0x00350000) /* -0.012939453 */,
+ PRESHIFT(0x0066c000) /* 0.025085449 */,
+ -PRESHIFT(0x01c67000) /* -0.110946655 */,
+ PRESHIFT(0x007f5000) /* 0.031082153 */,
+ -PRESHIFT(0x0bd06000) /* -0.738372803 */,
+ PRESHIFT(0x11ec7000) /* 1.120223999 */,
+ PRESHIFT(0x06772000) /* 0.404083252 */,
+ PRESHIFT(0x023b3000) /* 0.139450073 */,
+ PRESHIFT(0x00bbc000) /* 0.045837402 */,
+ PRESHIFT(0x00809000) /* 0.031387329 */,
+ PRESHIFT(0x00099000) /* 0.002334595 */,
+ PRESHIFT(0x000b0000) /* 0.002685547 */,
+ PRESHIFT(0x00010000) /* 0.000244141 */ },
+
+ { -PRESHIFT(0x00002000) /* -0.000030518 */, /* 7 */
+ -PRESHIFT(0x00035000) /* -0.000808716 */,
+ PRESHIFT(0x000e3000) /* 0.003463745 */,
+ -PRESHIFT(0x00397000) /* -0.014022827 */,
+ PRESHIFT(0x005ff000) /* 0.023422241 */,
+ -PRESHIFT(0x01dad000) /* -0.115921021 */,
+ PRESHIFT(0x0043a000) /* 0.016510010 */,
+ -PRESHIFT(0x0c3d9000) /* -0.765029907 */,
+ PRESHIFT(0x11c83000) /* 1.111373901 */,
+ PRESHIFT(0x06076000) /* 0.376800537 */,
+ PRESHIFT(0x024ad000) /* 0.143264771 */,
+ PRESHIFT(0x00a67000) /* 0.040634155 */,
+ PRESHIFT(0x007f0000) /* 0.031005859 */,
+ PRESHIFT(0x0006f000) /* 0.001693726 */,
+ PRESHIFT(0x000a9000) /* 0.002578735 */,
+ PRESHIFT(0x0000e000) /* 0.000213623 */,
+
+ -PRESHIFT(0x00002000) /* -0.000030518 */,
+ -PRESHIFT(0x00035000) /* -0.000808716 */,
+ PRESHIFT(0x000e3000) /* 0.003463745 */,
+ -PRESHIFT(0x00397000) /* -0.014022827 */,
+ PRESHIFT(0x005ff000) /* 0.023422241 */,
+ -PRESHIFT(0x01dad000) /* -0.115921021 */,
+ PRESHIFT(0x0043a000) /* 0.016510010 */,
+ -PRESHIFT(0x0c3d9000) /* -0.765029907 */,
+ PRESHIFT(0x11c83000) /* 1.111373901 */,
+ PRESHIFT(0x06076000) /* 0.376800537 */,
+ PRESHIFT(0x024ad000) /* 0.143264771 */,
+ PRESHIFT(0x00a67000) /* 0.040634155 */,
+ PRESHIFT(0x007f0000) /* 0.031005859 */,
+ PRESHIFT(0x0006f000) /* 0.001693726 */,
+ PRESHIFT(0x000a9000) /* 0.002578735 */,
+ PRESHIFT(0x0000e000) /* 0.000213623 */ },
+
+ { -PRESHIFT(0x00002000) /* -0.000030518 */, /* 8 */
+ -PRESHIFT(0x0003a000) /* -0.000885010 */,
+ PRESHIFT(0x000e0000) /* 0.003417969 */,
+ -PRESHIFT(0x003df000) /* -0.015121460 */,
+ PRESHIFT(0x00586000) /* 0.021575928 */,
+ -PRESHIFT(0x01ee6000) /* -0.120697021 */,
+ PRESHIFT(0x00046000) /* 0.001068115 */,
+ -PRESHIFT(0x0ca8d000) /* -0.791213989 */,
+ PRESHIFT(0x119e9000) /* 1.101211548 */,
+ PRESHIFT(0x05991000) /* 0.349868774 */,
+ PRESHIFT(0x02578000) /* 0.146362305 */,
+ PRESHIFT(0x0091a000) /* 0.035552979 */,
+ PRESHIFT(0x007d1000) /* 0.030532837 */,
+ PRESHIFT(0x00048000) /* 0.001098633 */,
+ PRESHIFT(0x000a1000) /* 0.002456665 */,
+ PRESHIFT(0x0000d000) /* 0.000198364 */,
+
+ -PRESHIFT(0x00002000) /* -0.000030518 */,
+ -PRESHIFT(0x0003a000) /* -0.000885010 */,
+ PRESHIFT(0x000e0000) /* 0.003417969 */,
+ -PRESHIFT(0x003df000) /* -0.015121460 */,
+ PRESHIFT(0x00586000) /* 0.021575928 */,
+ -PRESHIFT(0x01ee6000) /* -0.120697021 */,
+ PRESHIFT(0x00046000) /* 0.001068115 */,
+ -PRESHIFT(0x0ca8d000) /* -0.791213989 */,
+ PRESHIFT(0x119e9000) /* 1.101211548 */,
+ PRESHIFT(0x05991000) /* 0.349868774 */,
+ PRESHIFT(0x02578000) /* 0.146362305 */,
+ PRESHIFT(0x0091a000) /* 0.035552979 */,
+ PRESHIFT(0x007d1000) /* 0.030532837 */,
+ PRESHIFT(0x00048000) /* 0.001098633 */,
+ PRESHIFT(0x000a1000) /* 0.002456665 */,
+ PRESHIFT(0x0000d000) /* 0.000198364 */ },
+
+ { -PRESHIFT(0x00002000) /* -0.000030518 */, /* 9 */
+ -PRESHIFT(0x0003f000) /* -0.000961304 */,
+ PRESHIFT(0x000dd000) /* 0.003372192 */,
+ -PRESHIFT(0x00428000) /* -0.016235352 */,
+ PRESHIFT(0x00500000) /* 0.019531250 */,
+ -PRESHIFT(0x02011000) /* -0.125259399 */,
+ -PRESHIFT(0x003e6000) /* -0.015228271 */,
+ -PRESHIFT(0x0d11e000) /* -0.816864014 */,
+ PRESHIFT(0x116fc000) /* 1.089782715 */,
+ PRESHIFT(0x052c5000) /* 0.323318481 */,
+ PRESHIFT(0x02616000) /* 0.148773193 */,
+ PRESHIFT(0x007d6000) /* 0.030609131 */,
+ PRESHIFT(0x007aa000) /* 0.029937744 */,
+ PRESHIFT(0x00024000) /* 0.000549316 */,
+ PRESHIFT(0x0009a000) /* 0.002349854 */,
+ PRESHIFT(0x0000b000) /* 0.000167847 */,
+
+ -PRESHIFT(0x00002000) /* -0.000030518 */,
+ -PRESHIFT(0x0003f000) /* -0.000961304 */,
+ PRESHIFT(0x000dd000) /* 0.003372192 */,
+ -PRESHIFT(0x00428000) /* -0.016235352 */,
+ PRESHIFT(0x00500000) /* 0.019531250 */,
+ -PRESHIFT(0x02011000) /* -0.125259399 */,
+ -PRESHIFT(0x003e6000) /* -0.015228271 */,
+ -PRESHIFT(0x0d11e000) /* -0.816864014 */,
+ PRESHIFT(0x116fc000) /* 1.089782715 */,
+ PRESHIFT(0x052c5000) /* 0.323318481 */,
+ PRESHIFT(0x02616000) /* 0.148773193 */,
+ PRESHIFT(0x007d6000) /* 0.030609131 */,
+ PRESHIFT(0x007aa000) /* 0.029937744 */,
+ PRESHIFT(0x00024000) /* 0.000549316 */,
+ PRESHIFT(0x0009a000) /* 0.002349854 */,
+ PRESHIFT(0x0000b000) /* 0.000167847 */ },
+
+ { -PRESHIFT(0x00002000) /* -0.000030518 */, /* 10 */
+ -PRESHIFT(0x00044000) /* -0.001037598 */,
+ PRESHIFT(0x000d7000) /* 0.003280640 */,
+ -PRESHIFT(0x00471000) /* -0.017349243 */,
+ PRESHIFT(0x0046b000) /* 0.017257690 */,
+ -PRESHIFT(0x0212b000) /* -0.129562378 */,
+ -PRESHIFT(0x0084a000) /* -0.032379150 */,
+ -PRESHIFT(0x0d78a000) /* -0.841949463 */,
+ PRESHIFT(0x113be000) /* 1.077117920 */,
+ PRESHIFT(0x04c16000) /* 0.297210693 */,
+ PRESHIFT(0x02687000) /* 0.150497437 */,
+ PRESHIFT(0x0069c000) /* 0.025817871 */,
+ PRESHIFT(0x0077f000) /* 0.029281616 */,
+ PRESHIFT(0x00002000) /* 0.000030518 */,
+ PRESHIFT(0x00093000) /* 0.002243042 */,
+ PRESHIFT(0x0000a000) /* 0.000152588 */,
+
+ -PRESHIFT(0x00002000) /* -0.000030518 */,
+ -PRESHIFT(0x00044000) /* -0.001037598 */,
+ PRESHIFT(0x000d7000) /* 0.003280640 */,
+ -PRESHIFT(0x00471000) /* -0.017349243 */,
+ PRESHIFT(0x0046b000) /* 0.017257690 */,
+ -PRESHIFT(0x0212b000) /* -0.129562378 */,
+ -PRESHIFT(0x0084a000) /* -0.032379150 */,
+ -PRESHIFT(0x0d78a000) /* -0.841949463 */,
+ PRESHIFT(0x113be000) /* 1.077117920 */,
+ PRESHIFT(0x04c16000) /* 0.297210693 */,
+ PRESHIFT(0x02687000) /* 0.150497437 */,
+ PRESHIFT(0x0069c000) /* 0.025817871 */,
+ PRESHIFT(0x0077f000) /* 0.029281616 */,
+ PRESHIFT(0x00002000) /* 0.000030518 */,
+ PRESHIFT(0x00093000) /* 0.002243042 */,
+ PRESHIFT(0x0000a000) /* 0.000152588 */ },
+
+ { -PRESHIFT(0x00003000) /* -0.000045776 */, /* 11 */
+ -PRESHIFT(0x00049000) /* -0.001113892 */,
+ PRESHIFT(0x000d0000) /* 0.003173828 */,
+ -PRESHIFT(0x004ba000) /* -0.018463135 */,
+ PRESHIFT(0x003ca000) /* 0.014801025 */,
+ -PRESHIFT(0x02233000) /* -0.133590698 */,
+ -PRESHIFT(0x00ce4000) /* -0.050354004 */,
+ -PRESHIFT(0x0ddca000) /* -0.866363525 */,
+ PRESHIFT(0x1102f000) /* 1.063217163 */,
+ PRESHIFT(0x04587000) /* 0.271591187 */,
+ PRESHIFT(0x026cf000) /* 0.151596069 */,
+ PRESHIFT(0x0056c000) /* 0.021179199 */,
+ PRESHIFT(0x0074e000) /* 0.028533936 */,
+ -PRESHIFT(0x0001d000) /* -0.000442505 */,
+ PRESHIFT(0x0008b000) /* 0.002120972 */,
+ PRESHIFT(0x00009000) /* 0.000137329 */,
+
+ -PRESHIFT(0x00003000) /* -0.000045776 */,
+ -PRESHIFT(0x00049000) /* -0.001113892 */,
+ PRESHIFT(0x000d0000) /* 0.003173828 */,
+ -PRESHIFT(0x004ba000) /* -0.018463135 */,
+ PRESHIFT(0x003ca000) /* 0.014801025 */,
+ -PRESHIFT(0x02233000) /* -0.133590698 */,
+ -PRESHIFT(0x00ce4000) /* -0.050354004 */,
+ -PRESHIFT(0x0ddca000) /* -0.866363525 */,
+ PRESHIFT(0x1102f000) /* 1.063217163 */,
+ PRESHIFT(0x04587000) /* 0.271591187 */,
+ PRESHIFT(0x026cf000) /* 0.151596069 */,
+ PRESHIFT(0x0056c000) /* 0.021179199 */,
+ PRESHIFT(0x0074e000) /* 0.028533936 */,
+ -PRESHIFT(0x0001d000) /* -0.000442505 */,
+ PRESHIFT(0x0008b000) /* 0.002120972 */,
+ PRESHIFT(0x00009000) /* 0.000137329 */ },
+
+ { -PRESHIFT(0x00003000) /* -0.000045776 */, /* 12 */
+ -PRESHIFT(0x0004f000) /* -0.001205444 */,
+ PRESHIFT(0x000c8000) /* 0.003051758 */,
+ -PRESHIFT(0x00503000) /* -0.019577026 */,
+ PRESHIFT(0x0031a000) /* 0.012115479 */,
+ -PRESHIFT(0x02326000) /* -0.137298584 */,
+ -PRESHIFT(0x011b5000) /* -0.069168091 */,
+ -PRESHIFT(0x0e3dd000) /* -0.890090942 */,
+ PRESHIFT(0x10c54000) /* 1.048156738 */,
+ PRESHIFT(0x03f1b000) /* 0.246505737 */,
+ PRESHIFT(0x026ee000) /* 0.152069092 */,
+ PRESHIFT(0x00447000) /* 0.016708374 */,
+ PRESHIFT(0x00719000) /* 0.027725220 */,
+ -PRESHIFT(0x00039000) /* -0.000869751 */,
+ PRESHIFT(0x00084000) /* 0.002014160 */,
+ PRESHIFT(0x00008000) /* 0.000122070 */,
+
+ -PRESHIFT(0x00003000) /* -0.000045776 */,
+ -PRESHIFT(0x0004f000) /* -0.001205444 */,
+ PRESHIFT(0x000c8000) /* 0.003051758 */,
+ -PRESHIFT(0x00503000) /* -0.019577026 */,
+ PRESHIFT(0x0031a000) /* 0.012115479 */,
+ -PRESHIFT(0x02326000) /* -0.137298584 */,
+ -PRESHIFT(0x011b5000) /* -0.069168091 */,
+ -PRESHIFT(0x0e3dd000) /* -0.890090942 */,
+ PRESHIFT(0x10c54000) /* 1.048156738 */,
+ PRESHIFT(0x03f1b000) /* 0.246505737 */,
+ PRESHIFT(0x026ee000) /* 0.152069092 */,
+ PRESHIFT(0x00447000) /* 0.016708374 */,
+ PRESHIFT(0x00719000) /* 0.027725220 */,
+ -PRESHIFT(0x00039000) /* -0.000869751 */,
+ PRESHIFT(0x00084000) /* 0.002014160 */,
+ PRESHIFT(0x00008000) /* 0.000122070 */ },
+
+ { -PRESHIFT(0x00004000) /* -0.000061035 */, /* 13 */
+ -PRESHIFT(0x00055000) /* -0.001296997 */,
+ PRESHIFT(0x000bd000) /* 0.002883911 */,
+ -PRESHIFT(0x0054c000) /* -0.020690918 */,
+ PRESHIFT(0x0025d000) /* 0.009231567 */,
+ -PRESHIFT(0x02403000) /* -0.140670776 */,
+ -PRESHIFT(0x016ba000) /* -0.088775635 */,
+ -PRESHIFT(0x0e9be000) /* -0.913055420 */,
+ PRESHIFT(0x1082d000) /* 1.031936646 */,
+ PRESHIFT(0x038d4000) /* 0.221984863 */,
+ PRESHIFT(0x026e7000) /* 0.151962280 */,
+ PRESHIFT(0x0032e000) /* 0.012420654 */,
+ PRESHIFT(0x006df000) /* 0.026840210 */,
+ -PRESHIFT(0x00053000) /* -0.001266479 */,
+ PRESHIFT(0x0007d000) /* 0.001907349 */,
+ PRESHIFT(0x00007000) /* 0.000106812 */,
+
+ -PRESHIFT(0x00004000) /* -0.000061035 */,
+ -PRESHIFT(0x00055000) /* -0.001296997 */,
+ PRESHIFT(0x000bd000) /* 0.002883911 */,
+ -PRESHIFT(0x0054c000) /* -0.020690918 */,
+ PRESHIFT(0x0025d000) /* 0.009231567 */,
+ -PRESHIFT(0x02403000) /* -0.140670776 */,
+ -PRESHIFT(0x016ba000) /* -0.088775635 */,
+ -PRESHIFT(0x0e9be000) /* -0.913055420 */,
+ PRESHIFT(0x1082d000) /* 1.031936646 */,
+ PRESHIFT(0x038d4000) /* 0.221984863 */,
+ PRESHIFT(0x026e7000) /* 0.151962280 */,
+ PRESHIFT(0x0032e000) /* 0.012420654 */,
+ PRESHIFT(0x006df000) /* 0.026840210 */,
+ -PRESHIFT(0x00053000) /* -0.001266479 */,
+ PRESHIFT(0x0007d000) /* 0.001907349 */,
+ PRESHIFT(0x00007000) /* 0.000106812 */ },
+
+ { -PRESHIFT(0x00004000) /* -0.000061035 */, /* 14 */
+ -PRESHIFT(0x0005b000) /* -0.001388550 */,
+ PRESHIFT(0x000b1000) /* 0.002700806 */,
+ -PRESHIFT(0x00594000) /* -0.021789551 */,
+ PRESHIFT(0x00192000) /* 0.006134033 */,
+ -PRESHIFT(0x024c8000) /* -0.143676758 */,
+ -PRESHIFT(0x01bf2000) /* -0.109161377 */,
+ -PRESHIFT(0x0ef69000) /* -0.935195923 */,
+ PRESHIFT(0x103be000) /* 1.014617920 */,
+ PRESHIFT(0x032b4000) /* 0.198059082 */,
+ PRESHIFT(0x026bc000) /* 0.151306152 */,
+ PRESHIFT(0x00221000) /* 0.008316040 */,
+ PRESHIFT(0x006a2000) /* 0.025909424 */,
+ -PRESHIFT(0x0006a000) /* -0.001617432 */,
+ PRESHIFT(0x00075000) /* 0.001785278 */,
+ PRESHIFT(0x00007000) /* 0.000106812 */,
+
+ -PRESHIFT(0x00004000) /* -0.000061035 */,
+ -PRESHIFT(0x0005b000) /* -0.001388550 */,
+ PRESHIFT(0x000b1000) /* 0.002700806 */,
+ -PRESHIFT(0x00594000) /* -0.021789551 */,
+ PRESHIFT(0x00192000) /* 0.006134033 */,
+ -PRESHIFT(0x024c8000) /* -0.143676758 */,
+ -PRESHIFT(0x01bf2000) /* -0.109161377 */,
+ -PRESHIFT(0x0ef69000) /* -0.935195923 */,
+ PRESHIFT(0x103be000) /* 1.014617920 */,
+ PRESHIFT(0x032b4000) /* 0.198059082 */,
+ PRESHIFT(0x026bc000) /* 0.151306152 */,
+ PRESHIFT(0x00221000) /* 0.008316040 */,
+ PRESHIFT(0x006a2000) /* 0.025909424 */,
+ -PRESHIFT(0x0006a000) /* -0.001617432 */,
+ PRESHIFT(0x00075000) /* 0.001785278 */,
+ PRESHIFT(0x00007000) /* 0.000106812 */ },
+
+ { -PRESHIFT(0x00005000) /* -0.000076294 */, /* 15 */
+ -PRESHIFT(0x00061000) /* -0.001480103 */,
+ PRESHIFT(0x000a3000) /* 0.002487183 */,
+ -PRESHIFT(0x005da000) /* -0.022857666 */,
+ PRESHIFT(0x000b9000) /* 0.002822876 */,
+ -PRESHIFT(0x02571000) /* -0.146255493 */,
+ -PRESHIFT(0x0215c000) /* -0.130310059 */,
+ -PRESHIFT(0x0f4dc000) /* -0.956481934 */,
+ PRESHIFT(0x0ff0a000) /* 0.996246338 */,
+ PRESHIFT(0x02cbf000) /* 0.174789429 */,
+ PRESHIFT(0x0266e000) /* 0.150115967 */,
+ PRESHIFT(0x00120000) /* 0.004394531 */,
+ PRESHIFT(0x00662000) /* 0.024932861 */,
+ -PRESHIFT(0x0007f000) /* -0.001937866 */,
+ PRESHIFT(0x0006f000) /* 0.001693726 */,
+ PRESHIFT(0x00006000) /* 0.000091553 */,
+
+ -PRESHIFT(0x00005000) /* -0.000076294 */,
+ -PRESHIFT(0x00061000) /* -0.001480103 */,
+ PRESHIFT(0x000a3000) /* 0.002487183 */,
+ -PRESHIFT(0x005da000) /* -0.022857666 */,
+ PRESHIFT(0x000b9000) /* 0.002822876 */,
+ -PRESHIFT(0x02571000) /* -0.146255493 */,
+ -PRESHIFT(0x0215c000) /* -0.130310059 */,
+ -PRESHIFT(0x0f4dc000) /* -0.956481934 */,
+ PRESHIFT(0x0ff0a000) /* 0.996246338 */,
+ PRESHIFT(0x02cbf000) /* 0.174789429 */,
+ PRESHIFT(0x0266e000) /* 0.150115967 */,
+ PRESHIFT(0x00120000) /* 0.004394531 */,
+ PRESHIFT(0x00662000) /* 0.024932861 */,
+ -PRESHIFT(0x0007f000) /* -0.001937866 */,
+ PRESHIFT(0x0006f000) /* 0.001693726 */,
+ PRESHIFT(0x00006000) /* 0.000091553 */ },
+
+ { -PRESHIFT(0x00005000) /* -0.000076294 */, /* 16 */
+ -PRESHIFT(0x00068000) /* -0.001586914 */,
+ PRESHIFT(0x00092000) /* 0.002227783 */,
+ -PRESHIFT(0x0061f000) /* -0.023910522 */,
+ -PRESHIFT(0x0002d000) /* -0.000686646 */,
+ -PRESHIFT(0x025ff000) /* -0.148422241 */,
+ -PRESHIFT(0x026f7000) /* -0.152206421 */,
+ -PRESHIFT(0x0fa13000) /* -0.976852417 */,
+ PRESHIFT(0x0fa13000) /* 0.976852417 */,
+ PRESHIFT(0x026f7000) /* 0.152206421 */,
+ PRESHIFT(0x025ff000) /* 0.148422241 */,
+ PRESHIFT(0x0002d000) /* 0.000686646 */,
+ PRESHIFT(0x0061f000) /* 0.023910522 */,
+ -PRESHIFT(0x00092000) /* -0.002227783 */,
+ PRESHIFT(0x00068000) /* 0.001586914 */,
+ PRESHIFT(0x00005000) /* 0.000076294 */,
+
+ -PRESHIFT(0x00005000) /* -0.000076294 */,
+ -PRESHIFT(0x00068000) /* -0.001586914 */,
+ PRESHIFT(0x00092000) /* 0.002227783 */,
+ -PRESHIFT(0x0061f000) /* -0.023910522 */,
+ -PRESHIFT(0x0002d000) /* -0.000686646 */,
+ -PRESHIFT(0x025ff000) /* -0.148422241 */,
+ -PRESHIFT(0x026f7000) /* -0.152206421 */,
+ -PRESHIFT(0x0fa13000) /* -0.976852417 */,
+ PRESHIFT(0x0fa13000) /* 0.976852417 */,
+ PRESHIFT(0x026f7000) /* 0.152206421 */,
+ PRESHIFT(0x025ff000) /* 0.148422241 */,
+ PRESHIFT(0x0002d000) /* 0.000686646 */,
+ PRESHIFT(0x0061f000) /* 0.023910522 */,
+ -PRESHIFT(0x00092000) /* -0.002227783 */,
+ PRESHIFT(0x00068000) /* 0.001586914 */,
+ PRESHIFT(0x00005000) /* 0.000076294 */ }
diff --git a/contrib/libmad/Makefile.am b/contrib/libmad/Makefile.am
new file mode 100644
index 000000000..d3c285b01
--- /dev/null
+++ b/contrib/libmad/Makefile.am
@@ -0,0 +1,44 @@
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+AM_CPPFLAGS = -DOPT_SPEED
+
+EXTRA_DIST = COPYING
+
+if ENABLE_MAD
+if !WITH_EXTERNAL_MAD
+noinst_LTLIBRARIES = libmad.la
+endif
+endif
+
+##
+## libmad - MPEG audio decoder library
+## Copyright (C) 2000-2004 Underbit Technologies, Inc.
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##
+## $Id: Makefile.am,v 1.23 2004/02/17 02:02:03 rob Exp $
+##
+
+exported_headers = version.h fixed.h bit.h timer.h stream.h frame.h \
+ synth.h decoder.h
+
+headers = $(exported_headers) \
+ global.h layer12.h layer3.h huffman.h
+
+data_includes = D.dat imdct_s.dat qc_table.dat rq_table.dat \
+ sf_table.dat
+
+libmad_la_SOURCES = version.c fixed.c bit.c timer.c stream.c frame.c \
+ synth.c decoder.c layer12.c layer3.c huffman.c \
+ $(headers) $(data_includes)
diff --git a/contrib/libmad/bit.c b/contrib/libmad/bit.c
new file mode 100644
index 000000000..c2bfb243c
--- /dev/null
+++ b/contrib/libmad/bit.c
@@ -0,0 +1,237 @@
+/*
+ * libmad - MPEG audio decoder library
+ * Copyright (C) 2000-2004 Underbit Technologies, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: bit.c,v 1.12 2004/01/23 09:41:32 rob Exp $
+ */
+
+# ifdef HAVE_CONFIG_H
+# include "config.h"
+# endif
+
+# include "global.h"
+
+# ifdef HAVE_LIMITS_H
+# include <limits.h>
+# else
+# define CHAR_BIT 8
+# endif
+
+# include "bit.h"
+
+/*
+ * This is the lookup table for computing the CRC-check word.
+ * As described in section 2.4.3.1 and depicted in Figure A.9
+ * of ISO/IEC 11172-3, the generator polynomial is:
+ *
+ * G(X) = X^16 + X^15 + X^2 + 1
+ */
+static
+unsigned short const crc_table[256] = {
+ 0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
+ 0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022,
+ 0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072,
+ 0x0050, 0x8055, 0x805f, 0x005a, 0x804b, 0x004e, 0x0044, 0x8041,
+ 0x80c3, 0x00c6, 0x00cc, 0x80c9, 0x00d8, 0x80dd, 0x80d7, 0x00d2,
+ 0x00f0, 0x80f5, 0x80ff, 0x00fa, 0x80eb, 0x00ee, 0x00e4, 0x80e1,
+ 0x00a0, 0x80a5, 0x80af, 0x00aa, 0x80bb, 0x00be, 0x00b4, 0x80b1,
+ 0x8093, 0x0096, 0x009c, 0x8099, 0x0088, 0x808d, 0x8087, 0x0082,
+
+ 0x8183, 0x0186, 0x018c, 0x8189, 0x0198, 0x819d, 0x8197, 0x0192,
+ 0x01b0, 0x81b5, 0x81bf, 0x01ba, 0x81ab, 0x01ae, 0x01a4, 0x81a1,
+ 0x01e0, 0x81e5, 0x81ef, 0x01ea, 0x81fb, 0x01fe, 0x01f4, 0x81f1,
+ 0x81d3, 0x01d6, 0x01dc, 0x81d9, 0x01c8, 0x81cd, 0x81c7, 0x01c2,
+ 0x0140, 0x8145, 0x814f, 0x014a, 0x815b, 0x015e, 0x0154, 0x8151,
+ 0x8173, 0x0176, 0x017c, 0x8179, 0x0168, 0x816d, 0x8167, 0x0162,
+ 0x8123, 0x0126, 0x012c, 0x8129, 0x0138, 0x813d, 0x8137, 0x0132,
+ 0x0110, 0x8115, 0x811f, 0x011a, 0x810b, 0x010e, 0x0104, 0x8101,
+
+ 0x8303, 0x0306, 0x030c, 0x8309, 0x0318, 0x831d, 0x8317, 0x0312,
+ 0x0330, 0x8335, 0x833f, 0x033a, 0x832b, 0x032e, 0x0324, 0x8321,
+ 0x0360, 0x8365, 0x836f, 0x036a, 0x837b, 0x037e, 0x0374, 0x8371,
+ 0x8353, 0x0356, 0x035c, 0x8359, 0x0348, 0x834d, 0x8347, 0x0342,
+ 0x03c0, 0x83c5, 0x83cf, 0x03ca, 0x83db, 0x03de, 0x03d4, 0x83d1,
+ 0x83f3, 0x03f6, 0x03fc, 0x83f9, 0x03e8, 0x83ed, 0x83e7, 0x03e2,
+ 0x83a3, 0x03a6, 0x03ac, 0x83a9, 0x03b8, 0x83bd, 0x83b7, 0x03b2,
+ 0x0390, 0x8395, 0x839f, 0x039a, 0x838b, 0x038e, 0x0384, 0x8381,
+
+ 0x0280, 0x8285, 0x828f, 0x028a, 0x829b, 0x029e, 0x0294, 0x8291,
+ 0x82b3, 0x02b6, 0x02bc, 0x82b9, 0x02a8, 0x82ad, 0x82a7, 0x02a2,
+ 0x82e3, 0x02e6, 0x02ec, 0x82e9, 0x02f8, 0x82fd, 0x82f7, 0x02f2,
+ 0x02d0, 0x82d5, 0x82df, 0x02da, 0x82cb, 0x02ce, 0x02c4, 0x82c1,
+ 0x8243, 0x0246, 0x024c, 0x8249, 0x0258, 0x825d, 0x8257, 0x0252,
+ 0x0270, 0x8275, 0x827f, 0x027a, 0x826b, 0x026e, 0x0264, 0x8261,
+ 0x0220, 0x8225, 0x822f, 0x022a, 0x823b, 0x023e, 0x0234, 0x8231,
+ 0x8213, 0x0216, 0x021c, 0x8219, 0x0208, 0x820d, 0x8207, 0x0202
+};
+
+# define CRC_POLY 0x8005
+
+/*
+ * NAME: bit->init()
+ * DESCRIPTION: initialize bit pointer struct
+ */
+void mad_bit_init(struct mad_bitptr *bitptr, unsigned char const *byte)
+{
+ bitptr->byte = byte;
+ bitptr->cache = 0;
+ bitptr->left = CHAR_BIT;
+}
+
+/*
+ * NAME: bit->length()
+ * DESCRIPTION: return number of bits between start and end points
+ */
+unsigned int mad_bit_length(struct mad_bitptr const *begin,
+ struct mad_bitptr const *end)
+{
+ return begin->left +
+ CHAR_BIT * (end->byte - (begin->byte + 1)) + (CHAR_BIT - end->left);
+}
+
+/*
+ * NAME: bit->nextbyte()
+ * DESCRIPTION: return pointer to next unprocessed byte
+ */
+unsigned char const *mad_bit_nextbyte(struct mad_bitptr const *bitptr)
+{
+ return bitptr->left == CHAR_BIT ? bitptr->byte : bitptr->byte + 1;
+}
+
+/*
+ * NAME: bit->skip()
+ * DESCRIPTION: advance bit pointer
+ */
+void mad_bit_skip(struct mad_bitptr *bitptr, unsigned int len)
+{
+ bitptr->byte += len / CHAR_BIT;
+ bitptr->left -= len % CHAR_BIT;
+
+ if (bitptr->left > CHAR_BIT) {
+ bitptr->byte++;
+ bitptr->left += CHAR_BIT;
+ }
+
+ if (bitptr->left < CHAR_BIT)
+ bitptr->cache = *bitptr->byte;
+}
+
+/*
+ * NAME: bit->read()
+ * DESCRIPTION: read an arbitrary number of bits and return their UIMSBF value
+ */
+unsigned long mad_bit_read(struct mad_bitptr *bitptr, unsigned int len)
+{
+ register unsigned long value;
+
+ if (bitptr->left == CHAR_BIT)
+ bitptr->cache = *bitptr->byte;
+
+ if (len < bitptr->left) {
+ value = (bitptr->cache & ((1 << bitptr->left) - 1)) >>
+ (bitptr->left - len);
+ bitptr->left -= len;
+
+ return value;
+ }
+
+ /* remaining bits in current byte */
+
+ value = bitptr->cache & ((1 << bitptr->left) - 1);
+ len -= bitptr->left;
+
+ bitptr->byte++;
+ bitptr->left = CHAR_BIT;
+
+ /* more bytes */
+
+ while (len >= CHAR_BIT) {
+ value = (value << CHAR_BIT) | *bitptr->byte++;
+ len -= CHAR_BIT;
+ }
+
+ if (len > 0) {
+ bitptr->cache = *bitptr->byte;
+
+ value = (value << len) | (bitptr->cache >> (CHAR_BIT - len));
+ bitptr->left -= len;
+ }
+
+ return value;
+}
+
+# if 0
+/*
+ * NAME: bit->write()
+ * DESCRIPTION: write an arbitrary number of bits
+ */
+void mad_bit_write(struct mad_bitptr *bitptr, unsigned int len,
+ unsigned long value)
+{
+ unsigned char *ptr;
+
+ ptr = (unsigned char *) bitptr->byte;
+
+ /* ... */
+}
+# endif
+
+/*
+ * NAME: bit->crc()
+ * DESCRIPTION: compute CRC-check word
+ */
+unsigned short mad_bit_crc(struct mad_bitptr bitptr, unsigned int len,
+ unsigned short init)
+{
+ register unsigned int crc;
+
+ for (crc = init; len >= 32; len -= 32) {
+ register unsigned long data;
+
+ data = mad_bit_read(&bitptr, 32);
+
+ crc = (crc << 8) ^ crc_table[((crc >> 8) ^ (data >> 24)) & 0xff];
+ crc = (crc << 8) ^ crc_table[((crc >> 8) ^ (data >> 16)) & 0xff];
+ crc = (crc << 8) ^ crc_table[((crc >> 8) ^ (data >> 8)) & 0xff];
+ crc = (crc << 8) ^ crc_table[((crc >> 8) ^ (data >> 0)) & 0xff];
+ }
+
+ switch (len / 8) {
+ case 3: crc = (crc << 8) ^
+ crc_table[((crc >> 8) ^ mad_bit_read(&bitptr, 8)) & 0xff];
+ case 2: crc = (crc << 8) ^
+ crc_table[((crc >> 8) ^ mad_bit_read(&bitptr, 8)) & 0xff];
+ case 1: crc = (crc << 8) ^
+ crc_table[((crc >> 8) ^ mad_bit_read(&bitptr, 8)) & 0xff];
+
+ len %= 8;
+
+ case 0: break;
+ }
+
+ while (len--) {
+ register unsigned int msb;
+
+ msb = mad_bit_read(&bitptr, 1) ^ (crc >> 15);
+
+ crc <<= 1;
+ if (msb & 1)
+ crc ^= CRC_POLY;
+ }
+
+ return crc & 0xffff;
+}
diff --git a/contrib/libmad/bit.h b/contrib/libmad/bit.h
new file mode 100644
index 000000000..5a51570b2
--- /dev/null
+++ b/contrib/libmad/bit.h
@@ -0,0 +1,47 @@
+/*
+ * libmad - MPEG audio decoder library
+ * Copyright (C) 2000-2004 Underbit Technologies, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: bit.h,v 1.12 2004/01/23 09:41:32 rob Exp $
+ */
+
+# ifndef LIBMAD_BIT_H
+# define LIBMAD_BIT_H
+
+struct mad_bitptr {
+ unsigned char const *byte;
+ unsigned short cache;
+ unsigned short left;
+};
+
+void mad_bit_init(struct mad_bitptr *, unsigned char const *);
+
+# define mad_bit_finish(bitptr) /* nothing */
+
+unsigned int mad_bit_length(struct mad_bitptr const *,
+ struct mad_bitptr const *);
+
+# define mad_bit_bitsleft(bitptr) ((bitptr)->left)
+unsigned char const *mad_bit_nextbyte(struct mad_bitptr const *);
+
+void mad_bit_skip(struct mad_bitptr *, unsigned int);
+unsigned long mad_bit_read(struct mad_bitptr *, unsigned int);
+void mad_bit_write(struct mad_bitptr *, unsigned int, unsigned long);
+
+unsigned short mad_bit_crc(struct mad_bitptr, unsigned int, unsigned short);
+
+# endif
diff --git a/contrib/libmad/decoder.c b/contrib/libmad/decoder.c
new file mode 100644
index 000000000..6d6df0db5
--- /dev/null
+++ b/contrib/libmad/decoder.c
@@ -0,0 +1,582 @@
+/*
+ * libmad - MPEG audio decoder library
+ * Copyright (C) 2000-2004 Underbit Technologies, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: decoder.c,v 1.22 2004/01/23 09:41:32 rob Exp $
+ */
+
+# ifdef HAVE_CONFIG_H
+# include "config.h"
+# endif
+
+# include "global.h"
+
+# ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+# endif
+
+# ifdef HAVE_SYS_WAIT_H
+# include <sys/wait.h>
+# endif
+
+# ifdef HAVE_UNISTD_H
+# include <unistd.h>
+# endif
+
+# ifdef HAVE_FCNTL_H
+# include <fcntl.h>
+# endif
+
+# include <stdlib.h>
+
+# ifdef HAVE_ERRNO_H
+# include <errno.h>
+# endif
+
+# include "stream.h"
+# include "frame.h"
+# include "synth.h"
+# include "decoder.h"
+
+/*
+ * NAME: decoder->init()
+ * DESCRIPTION: initialize a decoder object with callback routines
+ */
+void mad_decoder_init(struct mad_decoder *decoder, void *data,
+ enum mad_flow (*input_func)(void *,
+ struct mad_stream *),
+ enum mad_flow (*header_func)(void *,
+ struct mad_header const *),
+ enum mad_flow (*filter_func)(void *,
+ struct mad_stream const *,
+ struct mad_frame *),
+ enum mad_flow (*output_func)(void *,
+ struct mad_header const *,
+ struct mad_pcm *),
+ enum mad_flow (*error_func)(void *,
+ struct mad_stream *,
+ struct mad_frame *),
+ enum mad_flow (*message_func)(void *,
+ void *, unsigned int *))
+{
+ decoder->mode = -1;
+
+ decoder->options = 0;
+
+ decoder->async.pid = 0;
+ decoder->async.in = -1;
+ decoder->async.out = -1;
+
+ decoder->sync = 0;
+
+ decoder->cb_data = data;
+
+ decoder->input_func = input_func;
+ decoder->header_func = header_func;
+ decoder->filter_func = filter_func;
+ decoder->output_func = output_func;
+ decoder->error_func = error_func;
+ decoder->message_func = message_func;
+}
+
+int mad_decoder_finish(struct mad_decoder *decoder)
+{
+# if defined(USE_ASYNC)
+ if (decoder->mode == MAD_DECODER_MODE_ASYNC && decoder->async.pid) {
+ pid_t pid;
+ int status;
+
+ close(decoder->async.in);
+
+ do
+ pid = waitpid(decoder->async.pid, &status, 0);
+ while (pid == -1 && errno == EINTR);
+
+ decoder->mode = -1;
+
+ close(decoder->async.out);
+
+ decoder->async.pid = 0;
+ decoder->async.in = -1;
+ decoder->async.out = -1;
+
+ if (pid == -1)
+ return -1;
+
+ return (!WIFEXITED(status) || WEXITSTATUS(status)) ? -1 : 0;
+ }
+# endif
+
+ return 0;
+}
+
+# if defined(USE_ASYNC)
+static
+enum mad_flow send_io(int fd, void const *data, size_t len)
+{
+ char const *ptr = data;
+ ssize_t count;
+
+ while (len) {
+ do
+ count = write(fd, ptr, len);
+ while (count == -1 && errno == EINTR);
+
+ if (count == -1)
+ return MAD_FLOW_BREAK;
+
+ len -= count;
+ ptr += count;
+ }
+
+ return MAD_FLOW_CONTINUE;
+}
+
+static
+enum mad_flow receive_io(int fd, void *buffer, size_t len)
+{
+ char *ptr = buffer;
+ ssize_t count;
+
+ while (len) {
+ do
+ count = read(fd, ptr, len);
+ while (count == -1 && errno == EINTR);
+
+ if (count == -1)
+ return (errno == EAGAIN) ? MAD_FLOW_IGNORE : MAD_FLOW_BREAK;
+ else if (count == 0)
+ return MAD_FLOW_STOP;
+
+ len -= count;
+ ptr += count;
+ }
+
+ return MAD_FLOW_CONTINUE;
+}
+
+static
+enum mad_flow receive_io_blocking(int fd, void *buffer, size_t len)
+{
+ int flags, blocking;
+ enum mad_flow result;
+
+ flags = fcntl(fd, F_GETFL);
+ if (flags == -1)
+ return MAD_FLOW_BREAK;
+
+ blocking = flags & ~O_NONBLOCK;
+
+ if (blocking != flags &&
+ fcntl(fd, F_SETFL, blocking) == -1)
+ return MAD_FLOW_BREAK;
+
+ result = receive_io(fd, buffer, len);
+
+ if (flags != blocking &&
+ fcntl(fd, F_SETFL, flags) == -1)
+ return MAD_FLOW_BREAK;
+
+ return result;
+}
+
+static
+enum mad_flow send(int fd, void const *message, unsigned int size)
+{
+ enum mad_flow result;
+
+ /* send size */
+
+ result = send_io(fd, &size, sizeof(size));
+
+ /* send message */
+
+ if (result == MAD_FLOW_CONTINUE)
+ result = send_io(fd, message, size);
+
+ return result;
+}
+
+static
+enum mad_flow receive(int fd, void **message, unsigned int *size)
+{
+ enum mad_flow result;
+ unsigned int actual;
+
+ if (*message == 0)
+ *size = 0;
+
+ /* receive size */
+
+ result = receive_io(fd, &actual, sizeof(actual));
+
+ /* receive message */
+
+ if (result == MAD_FLOW_CONTINUE) {
+ if (actual > *size)
+ actual -= *size;
+ else {
+ *size = actual;
+ actual = 0;
+ }
+
+ if (*size > 0) {
+ if (*message == 0) {
+ *message = malloc(*size);
+ if (*message == 0)
+ return MAD_FLOW_BREAK;
+ }
+
+ result = receive_io_blocking(fd, *message, *size);
+ }
+
+ /* throw away remainder of message */
+
+ while (actual && result == MAD_FLOW_CONTINUE) {
+ char sink[256];
+ unsigned int len;
+
+ len = actual > sizeof(sink) ? sizeof(sink) : actual;
+
+ result = receive_io_blocking(fd, sink, len);
+
+ actual -= len;
+ }
+ }
+
+ return result;
+}
+
+static
+enum mad_flow check_message(struct mad_decoder *decoder)
+{
+ enum mad_flow result;
+ void *message = 0;
+ unsigned int size;
+
+ result = receive(decoder->async.in, &message, &size);
+
+ if (result == MAD_FLOW_CONTINUE) {
+ if (decoder->message_func == 0)
+ size = 0;
+ else {
+ result = decoder->message_func(decoder->cb_data, message, &size);
+
+ if (result == MAD_FLOW_IGNORE ||
+ result == MAD_FLOW_BREAK)
+ size = 0;
+ }
+
+ if (send(decoder->async.out, message, size) != MAD_FLOW_CONTINUE)
+ result = MAD_FLOW_BREAK;
+ }
+
+ if (message)
+ free(message);
+
+ return result;
+}
+# endif
+
+static
+enum mad_flow error_default(void *data, struct mad_stream *stream,
+ struct mad_frame *frame)
+{
+ int *bad_last_frame = data;
+
+ switch (stream->error) {
+ case MAD_ERROR_BADCRC:
+ if (*bad_last_frame)
+ mad_frame_mute(frame);
+ else
+ *bad_last_frame = 1;
+
+ return MAD_FLOW_IGNORE;
+
+ default:
+ return MAD_FLOW_CONTINUE;
+ }
+}
+
+static
+int run_sync(struct mad_decoder *decoder)
+{
+ enum mad_flow (*error_func)(void *, struct mad_stream *, struct mad_frame *);
+ void *error_data;
+ int bad_last_frame = 0;
+ struct mad_stream *stream;
+ struct mad_frame *frame;
+ struct mad_synth *synth;
+ int result = 0;
+
+ if (decoder->input_func == 0)
+ return 0;
+
+ if (decoder->error_func) {
+ error_func = decoder->error_func;
+ error_data = decoder->cb_data;
+ }
+ else {
+ error_func = error_default;
+ error_data = &bad_last_frame;
+ }
+
+ stream = &decoder->sync->stream;
+ frame = &decoder->sync->frame;
+ synth = &decoder->sync->synth;
+
+ mad_stream_init(stream);
+ mad_frame_init(frame);
+ mad_synth_init(synth);
+
+ mad_stream_options(stream, decoder->options);
+
+ do {
+ switch (decoder->input_func(decoder->cb_data, stream)) {
+ case MAD_FLOW_STOP:
+ goto done;
+ case MAD_FLOW_BREAK:
+ goto fail;
+ case MAD_FLOW_IGNORE:
+ continue;
+ case MAD_FLOW_CONTINUE:
+ break;
+ }
+
+ while (1) {
+# if defined(USE_ASYNC)
+ if (decoder->mode == MAD_DECODER_MODE_ASYNC) {
+ switch (check_message(decoder)) {
+ case MAD_FLOW_IGNORE:
+ case MAD_FLOW_CONTINUE:
+ break;
+ case MAD_FLOW_BREAK:
+ goto fail;
+ case MAD_FLOW_STOP:
+ goto done;
+ }
+ }
+# endif
+
+ if (decoder->header_func) {
+ if (mad_header_decode(&frame->header, stream) == -1) {
+ if (!MAD_RECOVERABLE(stream->error))
+ break;
+
+ switch (error_func(error_data, stream, frame)) {
+ case MAD_FLOW_STOP:
+ goto done;
+ case MAD_FLOW_BREAK:
+ goto fail;
+ case MAD_FLOW_IGNORE:
+ case MAD_FLOW_CONTINUE:
+ default:
+ continue;
+ }
+ }
+
+ switch (decoder->header_func(decoder->cb_data, &frame->header)) {
+ case MAD_FLOW_STOP:
+ goto done;
+ case MAD_FLOW_BREAK:
+ goto fail;
+ case MAD_FLOW_IGNORE:
+ continue;
+ case MAD_FLOW_CONTINUE:
+ break;
+ }
+ }
+
+ if (mad_frame_decode(frame, stream) == -1) {
+ if (!MAD_RECOVERABLE(stream->error))
+ break;
+
+ switch (error_func(error_data, stream, frame)) {
+ case MAD_FLOW_STOP:
+ goto done;
+ case MAD_FLOW_BREAK:
+ goto fail;
+ case MAD_FLOW_IGNORE:
+ break;
+ case MAD_FLOW_CONTINUE:
+ default:
+ continue;
+ }
+ }
+ else
+ bad_last_frame = 0;
+
+ if (decoder->filter_func) {
+ switch (decoder->filter_func(decoder->cb_data, stream, frame)) {
+ case MAD_FLOW_STOP:
+ goto done;
+ case MAD_FLOW_BREAK:
+ goto fail;
+ case MAD_FLOW_IGNORE:
+ continue;
+ case MAD_FLOW_CONTINUE:
+ break;
+ }
+ }
+
+ mad_synth_frame(synth, frame);
+
+ if (decoder->output_func) {
+ switch (decoder->output_func(decoder->cb_data,
+ &frame->header, &synth->pcm)) {
+ case MAD_FLOW_STOP:
+ goto done;
+ case MAD_FLOW_BREAK:
+ goto fail;
+ case MAD_FLOW_IGNORE:
+ case MAD_FLOW_CONTINUE:
+ break;
+ }
+ }
+ }
+ }
+ while (stream->error == MAD_ERROR_BUFLEN);
+
+ fail:
+ result = -1;
+
+ done:
+ mad_synth_finish(synth);
+ mad_frame_finish(frame);
+ mad_stream_finish(stream);
+
+ return result;
+}
+
+# if defined(USE_ASYNC)
+static
+int run_async(struct mad_decoder *decoder)
+{
+ pid_t pid;
+ int ptoc[2], ctop[2], flags;
+
+ if (pipe(ptoc) == -1)
+ return -1;
+
+ if (pipe(ctop) == -1) {
+ close(ptoc[0]);
+ close(ptoc[1]);
+ return -1;
+ }
+
+ flags = fcntl(ptoc[0], F_GETFL);
+ if (flags == -1 ||
+ fcntl(ptoc[0], F_SETFL, flags | O_NONBLOCK) == -1) {
+ close(ctop[0]);
+ close(ctop[1]);
+ close(ptoc[0]);
+ close(ptoc[1]);
+ return -1;
+ }
+
+ pid = fork();
+ if (pid == -1) {
+ close(ctop[0]);
+ close(ctop[1]);
+ close(ptoc[0]);
+ close(ptoc[1]);
+ return -1;
+ }
+
+ decoder->async.pid = pid;
+
+ if (pid) {
+ /* parent */
+
+ close(ptoc[0]);
+ close(ctop[1]);
+
+ decoder->async.in = ctop[0];
+ decoder->async.out = ptoc[1];
+
+ return 0;
+ }
+
+ /* child */
+
+ close(ptoc[1]);
+ close(ctop[0]);
+
+ decoder->async.in = ptoc[0];
+ decoder->async.out = ctop[1];
+
+ _exit(run_sync(decoder));
+
+ /* not reached */
+ return -1;
+}
+# endif
+
+/*
+ * NAME: decoder->run()
+ * DESCRIPTION: run the decoder thread either synchronously or asynchronously
+ */
+int mad_decoder_run(struct mad_decoder *decoder, enum mad_decoder_mode mode)
+{
+ int result;
+ int (*run)(struct mad_decoder *) = 0;
+
+ switch (decoder->mode = mode) {
+ case MAD_DECODER_MODE_SYNC:
+ run = run_sync;
+ break;
+
+ case MAD_DECODER_MODE_ASYNC:
+# if defined(USE_ASYNC)
+ run = run_async;
+# endif
+ break;
+ }
+
+ if (run == 0)
+ return -1;
+
+ decoder->sync = malloc(sizeof(*decoder->sync));
+ if (decoder->sync == 0)
+ return -1;
+
+ result = run(decoder);
+
+ free(decoder->sync);
+ decoder->sync = 0;
+
+ return result;
+}
+
+/*
+ * NAME: decoder->message()
+ * DESCRIPTION: send a message to and receive a reply from the decoder process
+ */
+int mad_decoder_message(struct mad_decoder *decoder,
+ void *message, unsigned int *len)
+{
+# if defined(USE_ASYNC)
+ if (decoder->mode != MAD_DECODER_MODE_ASYNC ||
+ send(decoder->async.out, message, *len) != MAD_FLOW_CONTINUE ||
+ receive(decoder->async.in, &message, len) != MAD_FLOW_CONTINUE)
+ return -1;
+
+ return 0;
+# else
+ return -1;
+# endif
+}
diff --git a/contrib/libmad/decoder.h b/contrib/libmad/decoder.h
new file mode 100644
index 000000000..f0ad758dd
--- /dev/null
+++ b/contrib/libmad/decoder.h
@@ -0,0 +1,91 @@
+/*
+ * libmad - MPEG audio decoder library
+ * Copyright (C) 2000-2004 Underbit Technologies, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: decoder.h,v 1.17 2004/01/23 09:41:32 rob Exp $
+ */
+
+# ifndef LIBMAD_DECODER_H
+# define LIBMAD_DECODER_H
+
+# include "stream.h"
+# include "frame.h"
+# include "synth.h"
+
+enum mad_decoder_mode {
+ MAD_DECODER_MODE_SYNC = 0,
+ MAD_DECODER_MODE_ASYNC
+};
+
+enum mad_flow {
+ MAD_FLOW_CONTINUE = 0x0000, /* continue normally */
+ MAD_FLOW_STOP = 0x0010, /* stop decoding normally */
+ MAD_FLOW_BREAK = 0x0011, /* stop decoding and signal an error */
+ MAD_FLOW_IGNORE = 0x0020 /* ignore the current frame */
+};
+
+struct mad_decoder {
+ enum mad_decoder_mode mode;
+
+ int options;
+
+ struct {
+ long pid;
+ int in;
+ int out;
+ } async;
+
+ struct {
+ struct mad_stream stream;
+ struct mad_frame frame;
+ struct mad_synth synth;
+ } *sync;
+
+ void *cb_data;
+
+ enum mad_flow (*input_func)(void *, struct mad_stream *);
+ enum mad_flow (*header_func)(void *, struct mad_header const *);
+ enum mad_flow (*filter_func)(void *,
+ struct mad_stream const *, struct mad_frame *);
+ enum mad_flow (*output_func)(void *,
+ struct mad_header const *, struct mad_pcm *);
+ enum mad_flow (*error_func)(void *, struct mad_stream *, struct mad_frame *);
+ enum mad_flow (*message_func)(void *, void *, unsigned int *);
+};
+
+void mad_decoder_init(struct mad_decoder *, void *,
+ enum mad_flow (*)(void *, struct mad_stream *),
+ enum mad_flow (*)(void *, struct mad_header const *),
+ enum mad_flow (*)(void *,
+ struct mad_stream const *,
+ struct mad_frame *),
+ enum mad_flow (*)(void *,
+ struct mad_header const *,
+ struct mad_pcm *),
+ enum mad_flow (*)(void *,
+ struct mad_stream *,
+ struct mad_frame *),
+ enum mad_flow (*)(void *, void *, unsigned int *));
+int mad_decoder_finish(struct mad_decoder *);
+
+# define mad_decoder_options(decoder, opts) \
+ ((void) ((decoder)->options = (opts)))
+
+int mad_decoder_run(struct mad_decoder *, enum mad_decoder_mode);
+int mad_decoder_message(struct mad_decoder *, void *, unsigned int *);
+
+# endif
diff --git a/contrib/libmad/fixed.c b/contrib/libmad/fixed.c
new file mode 100644
index 000000000..9785466f6
--- /dev/null
+++ b/contrib/libmad/fixed.c
@@ -0,0 +1,81 @@
+/*
+ * libmad - MPEG audio decoder library
+ * Copyright (C) 2000-2004 Underbit Technologies, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: fixed.c,v 1.13 2004/01/23 09:41:32 rob Exp $
+ */
+
+# ifdef HAVE_CONFIG_H
+# include "config.h"
+# endif
+
+# include "global.h"
+
+# include "fixed.h"
+
+/*
+ * NAME: fixed->abs()
+ * DESCRIPTION: return absolute value of a fixed-point number
+ */
+mad_fixed_t mad_f_abs(mad_fixed_t x)
+{
+ return x < 0 ? -x : x;
+}
+
+/*
+ * NAME: fixed->div()
+ * DESCRIPTION: perform division using fixed-point math
+ */
+mad_fixed_t mad_f_div(mad_fixed_t x, mad_fixed_t y)
+{
+ mad_fixed_t q, r;
+ unsigned int bits;
+
+ q = mad_f_abs(x / y);
+
+ if (x < 0) {
+ x = -x;
+ y = -y;
+ }
+
+ r = x % y;
+
+ if (y < 0) {
+ x = -x;
+ y = -y;
+ }
+
+ if (q > mad_f_intpart(MAD_F_MAX) &&
+ !(q == -mad_f_intpart(MAD_F_MIN) && r == 0 && (x < 0) != (y < 0)))
+ return 0;
+
+ for (bits = MAD_F_FRACBITS; bits && r; --bits) {
+ q <<= 1, r <<= 1;
+ if (r >= y)
+ r -= y, ++q;
+ }
+
+ /* round */
+ if (2 * r >= y)
+ ++q;
+
+ /* fix sign */
+ if ((x < 0) != (y < 0))
+ q = -q;
+
+ return q << bits;
+}
diff --git a/contrib/libmad/fixed.h b/contrib/libmad/fixed.h
new file mode 100644
index 000000000..4b58abf56
--- /dev/null
+++ b/contrib/libmad/fixed.h
@@ -0,0 +1,499 @@
+/*
+ * libmad - MPEG audio decoder library
+ * Copyright (C) 2000-2004 Underbit Technologies, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: fixed.h,v 1.38 2004/02/17 02:02:03 rob Exp $
+ */
+
+# ifndef LIBMAD_FIXED_H
+# define LIBMAD_FIXED_H
+
+# if SIZEOF_INT >= 4
+typedef signed int mad_fixed_t;
+
+typedef signed int mad_fixed64hi_t;
+typedef unsigned int mad_fixed64lo_t;
+# else
+typedef signed long mad_fixed_t;
+
+typedef signed long mad_fixed64hi_t;
+typedef unsigned long mad_fixed64lo_t;
+# endif
+
+# if defined(_MSC_VER)
+# define mad_fixed64_t signed __int64
+# elif 1 || defined(__GNUC__)
+# define mad_fixed64_t signed long long
+# endif
+
+# if defined(FPM_FLOAT)
+typedef double mad_sample_t;
+# else
+typedef mad_fixed_t mad_sample_t;
+# endif
+
+/*
+ * Fixed-point format: 0xABBBBBBB
+ * A == whole part (sign + 3 bits)
+ * B == fractional part (28 bits)
+ *
+ * Values are signed two's complement, so the effective range is:
+ * 0x80000000 to 0x7fffffff
+ * -8.0 to +7.9999999962747097015380859375
+ *
+ * The smallest representable value is:
+ * 0x00000001 == 0.0000000037252902984619140625 (i.e. about 3.725e-9)
+ *
+ * 28 bits of fractional accuracy represent about
+ * 8.6 digits of decimal accuracy.
+ *
+ * Fixed-point numbers can be added or subtracted as normal
+ * integers, but multiplication requires shifting the 64-bit result
+ * from 56 fractional bits back to 28 (and rounding.)
+ *
+ * Changing the definition of MAD_F_FRACBITS is only partially
+ * supported, and must be done with care.
+ */
+
+# define MAD_F_FRACBITS 28
+
+# if MAD_F_FRACBITS == 28
+# define MAD_F(x) ((mad_fixed_t) (x##L))
+# else
+# if MAD_F_FRACBITS < 28
+# warning "MAD_F_FRACBITS < 28"
+# define MAD_F(x) ((mad_fixed_t) \
+ (((x##L) + \
+ (1L << (28 - MAD_F_FRACBITS - 1))) >> \
+ (28 - MAD_F_FRACBITS)))
+# elif MAD_F_FRACBITS > 28
+# error "MAD_F_FRACBITS > 28 not currently supported"
+# define MAD_F(x) ((mad_fixed_t) \
+ ((x##L) << (MAD_F_FRACBITS - 28)))
+# endif
+# endif
+
+# define MAD_F_MIN ((mad_fixed_t) -0x80000000L)
+# define MAD_F_MAX ((mad_fixed_t) +0x7fffffffL)
+
+# define MAD_F_ONE MAD_F(0x10000000)
+
+# define mad_f_tofixed(x) ((mad_fixed_t) \
+ ((x) * (double) (1L << MAD_F_FRACBITS) + 0.5))
+# define mad_f_todouble(x) ((double) \
+ ((x) / (double) (1L << MAD_F_FRACBITS)))
+
+# define mad_f_intpart(x) ((x) >> MAD_F_FRACBITS)
+# define mad_f_fracpart(x) ((x) & ((1L << MAD_F_FRACBITS) - 1))
+ /* (x should be positive) */
+
+# define mad_f_fromint(x) ((x) << MAD_F_FRACBITS)
+
+# define mad_f_add(x, y) ((x) + (y))
+# define mad_f_sub(x, y) ((x) - (y))
+
+# if defined(FPM_FLOAT)
+# error "FPM_FLOAT not yet supported"
+
+# undef MAD_F
+# define MAD_F(x) mad_f_todouble(x)
+
+# define mad_f_mul(x, y) ((x) * (y))
+# define mad_f_scale64
+
+# undef ASO_ZEROCHECK
+
+# elif defined(FPM_64BIT)
+
+/*
+ * This version should be the most accurate if 64-bit types are supported by
+ * the compiler, although it may not be the most efficient.
+ */
+# if defined(OPT_ACCURACY)
+# define mad_f_mul(x, y) \
+ ((mad_fixed_t) \
+ ((((mad_fixed64_t) (x) * (y)) + \
+ (1L << (MAD_F_SCALEBITS - 1))) >> MAD_F_SCALEBITS))
+# else
+# define mad_f_mul(x, y) \
+ ((mad_fixed_t) (((mad_fixed64_t) (x) * (y)) >> MAD_F_SCALEBITS))
+# endif
+
+# define MAD_F_SCALEBITS MAD_F_FRACBITS
+
+/* --- Intel --------------------------------------------------------------- */
+
+# elif defined(FPM_INTEL)
+
+# if defined(_MSC_VER)
+# pragma warning(push)
+# pragma warning(disable: 4035) /* no return value */
+static __forceinline
+mad_fixed_t mad_f_mul_inline(mad_fixed_t x, mad_fixed_t y)
+{
+ enum {
+ fracbits = MAD_F_FRACBITS
+ };
+
+ __asm {
+ mov eax, x
+ imul y
+ shrd eax, edx, fracbits
+ }
+
+ /* implicit return of eax */
+}
+# pragma warning(pop)
+
+# define mad_f_mul mad_f_mul_inline
+# define mad_f_scale64
+# else
+/*
+ * This Intel version is fast and accurate; the disposition of the least
+ * significant bit depends on OPT_ACCURACY via mad_f_scale64().
+ */
+# define MAD_F_MLX(hi, lo, x, y) \
+ asm ("imull %3" \
+ : "=a" (lo), "=d" (hi) \
+ : "%a" (x), "rm" (y) \
+ : "cc")
+
+# if defined(OPT_ACCURACY)
+/*
+ * This gives best accuracy but is not very fast.
+ */
+# define MAD_F_MLA(hi, lo, x, y) \
+ ({ mad_fixed64hi_t __hi; \
+ mad_fixed64lo_t __lo; \
+ MAD_F_MLX(__hi, __lo, (x), (y)); \
+ asm ("addl %2,%0\n\t" \
+ "adcl %3,%1" \
+ : "=rm" (lo), "=rm" (hi) \
+ : "r" (__lo), "r" (__hi), "0" (lo), "1" (hi) \
+ : "cc"); \
+ })
+# endif /* OPT_ACCURACY */
+
+# if defined(OPT_ACCURACY)
+/*
+ * Surprisingly, this is faster than SHRD followed by ADC.
+ */
+# define mad_f_scale64(hi, lo) \
+ ({ mad_fixed64hi_t __hi_; \
+ mad_fixed64lo_t __lo_; \
+ mad_fixed_t __result; \
+ asm ("addl %4,%2\n\t" \
+ "adcl %5,%3" \
+ : "=rm" (__lo_), "=rm" (__hi_) \
+ : "0" (lo), "1" (hi), \
+ "ir" (1L << (MAD_F_SCALEBITS - 1)), "ir" (0) \
+ : "cc"); \
+ asm ("shrdl %3,%2,%1" \
+ : "=rm" (__result) \
+ : "0" (__lo_), "r" (__hi_), "I" (MAD_F_SCALEBITS) \
+ : "cc"); \
+ __result; \
+ })
+# elif defined(OPT_INTEL)
+/*
+ * Alternate Intel scaling that may or may not perform better.
+ */
+# define mad_f_scale64(hi, lo) \
+ ({ mad_fixed_t __result; \
+ asm ("shrl %3,%1\n\t" \
+ "shll %4,%2\n\t" \
+ "orl %2,%1" \
+ : "=rm" (__result) \
+ : "0" (lo), "r" (hi), \
+ "I" (MAD_F_SCALEBITS), "I" (32 - MAD_F_SCALEBITS) \
+ : "cc"); \
+ __result; \
+ })
+# else
+# define mad_f_scale64(hi, lo) \
+ ({ mad_fixed_t __result; \
+ asm ("shrdl %3,%2,%1" \
+ : "=rm" (__result) \
+ : "0" (lo), "r" (hi), "I" (MAD_F_SCALEBITS) \
+ : "cc"); \
+ __result; \
+ })
+# endif /* OPT_ACCURACY */
+
+# define MAD_F_SCALEBITS MAD_F_FRACBITS
+# endif
+
+/* --- ARM ----------------------------------------------------------------- */
+
+# elif defined(FPM_ARM)
+
+/*
+ * This ARM V4 version is as accurate as FPM_64BIT but much faster. The
+ * least significant bit is properly rounded at no CPU cycle cost!
+ */
+# if 1
+/*
+ * This is faster than the default implementation via MAD_F_MLX() and
+ * mad_f_scale64().
+ */
+# define mad_f_mul(x, y) \
+ ({ mad_fixed64hi_t __hi; \
+ mad_fixed64lo_t __lo; \
+ mad_fixed_t __result; \
+ asm ("smull %0, %1, %3, %4\n\t" \
+ "movs %0, %0, lsr %5\n\t" \
+ "adc %2, %0, %1, lsl %6" \
+ : "=&r" (__lo), "=&r" (__hi), "=r" (__result) \
+ : "%r" (x), "r" (y), \
+ "M" (MAD_F_SCALEBITS), "M" (32 - MAD_F_SCALEBITS) \
+ : "cc"); \
+ __result; \
+ })
+# endif
+
+# define MAD_F_MLX(hi, lo, x, y) \
+ asm ("smull %0, %1, %2, %3" \
+ : "=&r" (lo), "=&r" (hi) \
+ : "%r" (x), "r" (y))
+
+# define MAD_F_MLA(hi, lo, x, y) \
+ asm ("smlal %0, %1, %2, %3" \
+ : "+r" (lo), "+r" (hi) \
+ : "%r" (x), "r" (y))
+
+# define MAD_F_MLN(hi, lo) \
+ asm ("rsbs %0, %2, #0\n\t" \
+ "rsc %1, %3, #0" \
+ : "=r" (lo), "=r" (hi) \
+ : "0" (lo), "1" (hi) \
+ : "cc")
+
+# define mad_f_scale64(hi, lo) \
+ ({ mad_fixed_t __result; \
+ asm ("movs %0, %1, lsr %3\n\t" \
+ "adc %0, %0, %2, lsl %4" \
+ : "=&r" (__result) \
+ : "r" (lo), "r" (hi), \
+ "M" (MAD_F_SCALEBITS), "M" (32 - MAD_F_SCALEBITS) \
+ : "cc"); \
+ __result; \
+ })
+
+# define MAD_F_SCALEBITS MAD_F_FRACBITS
+
+/* --- MIPS ---------------------------------------------------------------- */
+
+# elif defined(FPM_MIPS)
+
+/*
+ * This MIPS version is fast and accurate; the disposition of the least
+ * significant bit depends on OPT_ACCURACY via mad_f_scale64().
+ */
+# define MAD_F_MLX(hi, lo, x, y) \
+ asm ("mult %2,%3" \
+ : "=l" (lo), "=h" (hi) \
+ : "%r" (x), "r" (y))
+
+# if defined(HAVE_MADD_ASM)
+# define MAD_F_MLA(hi, lo, x, y) \
+ asm ("madd %2,%3" \
+ : "+l" (lo), "+h" (hi) \
+ : "%r" (x), "r" (y))
+# elif defined(HAVE_MADD16_ASM)
+/*
+ * This loses significant accuracy due to the 16-bit integer limit in the
+ * multiply/accumulate instruction.
+ */
+# define MAD_F_ML0(hi, lo, x, y) \
+ asm ("mult %2,%3" \
+ : "=l" (lo), "=h" (hi) \
+ : "%r" ((x) >> 12), "r" ((y) >> 16))
+# define MAD_F_MLA(hi, lo, x, y) \
+ asm ("madd16 %2,%3" \
+ : "+l" (lo), "+h" (hi) \
+ : "%r" ((x) >> 12), "r" ((y) >> 16))
+# define MAD_F_MLZ(hi, lo) ((mad_fixed_t) (lo))
+# endif
+
+# if defined(OPT_SPEED)
+# define mad_f_scale64(hi, lo) \
+ ((mad_fixed_t) ((hi) << (32 - MAD_F_SCALEBITS)))
+# define MAD_F_SCALEBITS MAD_F_FRACBITS
+# endif
+
+/* --- SPARC --------------------------------------------------------------- */
+
+# elif defined(FPM_SPARC)
+
+/*
+ * This SPARC V8 version is fast and accurate; the disposition of the least
+ * significant bit depends on OPT_ACCURACY via mad_f_scale64().
+ */
+# define MAD_F_MLX(hi, lo, x, y) \
+ asm ("smul %2, %3, %0\n\t" \
+ "rd %%y, %1" \
+ : "=r" (lo), "=r" (hi) \
+ : "%r" (x), "rI" (y))
+
+/* --- PowerPC ------------------------------------------------------------- */
+
+# elif defined(FPM_PPC)
+
+/*
+ * This PowerPC version is fast and accurate; the disposition of the least
+ * significant bit depends on OPT_ACCURACY via mad_f_scale64().
+ */
+# define MAD_F_MLX(hi, lo, x, y) \
+ do { \
+ asm ("mullw %0,%1,%2" \
+ : "=r" (lo) \
+ : "%r" (x), "r" (y)); \
+ asm ("mulhw %0,%1,%2" \
+ : "=r" (hi) \
+ : "%r" (x), "r" (y)); \
+ } \
+ while (0)
+
+# if defined(OPT_ACCURACY)
+/*
+ * This gives best accuracy but is not very fast.
+ */
+# define MAD_F_MLA(hi, lo, x, y) \
+ ({ mad_fixed64hi_t __hi; \
+ mad_fixed64lo_t __lo; \
+ MAD_F_MLX(__hi, __lo, (x), (y)); \
+ asm ("addc %0,%2,%3\n\t" \
+ "adde %1,%4,%5" \
+ : "=r" (lo), "=r" (hi) \
+ : "%r" (lo), "r" (__lo), \
+ "%r" (hi), "r" (__hi) \
+ : "xer"); \
+ })
+# endif
+
+# if defined(OPT_ACCURACY)
+/*
+ * This is slower than the truncating version below it.
+ */
+# define mad_f_scale64(hi, lo) \
+ ({ mad_fixed_t __result, __round; \
+ asm ("rotrwi %0,%1,%2" \
+ : "=r" (__result) \
+ : "r" (lo), "i" (MAD_F_SCALEBITS)); \
+ asm ("extrwi %0,%1,1,0" \
+ : "=r" (__round) \
+ : "r" (__result)); \
+ asm ("insrwi %0,%1,%2,0" \
+ : "+r" (__result) \
+ : "r" (hi), "i" (MAD_F_SCALEBITS)); \
+ asm ("add %0,%1,%2" \
+ : "=r" (__result) \
+ : "%r" (__result), "r" (__round)); \
+ __result; \
+ })
+# else
+# define mad_f_scale64(hi, lo) \
+ ({ mad_fixed_t __result; \
+ asm ("rotrwi %0,%1,%2" \
+ : "=r" (__result) \
+ : "r" (lo), "i" (MAD_F_SCALEBITS)); \
+ asm ("insrwi %0,%1,%2,0" \
+ : "+r" (__result) \
+ : "r" (hi), "i" (MAD_F_SCALEBITS)); \
+ __result; \
+ })
+# endif
+
+# define MAD_F_SCALEBITS MAD_F_FRACBITS
+
+/* --- Default ------------------------------------------------------------- */
+
+# elif defined(FPM_DEFAULT)
+
+/*
+ * This version is the most portable but it loses significant accuracy.
+ * Furthermore, accuracy is biased against the second argument, so care
+ * should be taken when ordering operands.
+ *
+ * The scale factors are constant as this is not used with SSO.
+ *
+ * Pre-rounding is required to stay within the limits of compliance.
+ */
+# if defined(OPT_SPEED)
+# define mad_f_mul(x, y) (((x) >> 12) * ((y) >> 16))
+# else
+# define mad_f_mul(x, y) ((((x) + (1L << 11)) >> 12) * \
+ (((y) + (1L << 15)) >> 16))
+# endif
+
+/* ------------------------------------------------------------------------- */
+
+# else
+# error "no FPM selected"
+# endif
+
+/* default implementations */
+
+# if !defined(mad_f_mul)
+# define mad_f_mul(x, y) \
+ ({ register mad_fixed64hi_t __hi; \
+ register mad_fixed64lo_t __lo; \
+ MAD_F_MLX(__hi, __lo, (x), (y)); \
+ mad_f_scale64(__hi, __lo); \
+ })
+# endif
+
+# if !defined(MAD_F_MLA)
+# define MAD_F_ML0(hi, lo, x, y) ((lo) = mad_f_mul((x), (y)))
+# define MAD_F_MLA(hi, lo, x, y) ((lo) += mad_f_mul((x), (y)))
+# define MAD_F_MLN(hi, lo) ((lo) = -(lo))
+# define MAD_F_MLZ(hi, lo) ((void) (hi), (mad_fixed_t) (lo))
+# endif
+
+# if !defined(MAD_F_ML0)
+# define MAD_F_ML0(hi, lo, x, y) MAD_F_MLX((hi), (lo), (x), (y))
+# endif
+
+# if !defined(MAD_F_MLN)
+# define MAD_F_MLN(hi, lo) ((hi) = ((lo) = -(lo)) ? ~(hi) : -(hi))
+# endif
+
+# if !defined(MAD_F_MLZ)
+# define MAD_F_MLZ(hi, lo) mad_f_scale64((hi), (lo))
+# endif
+
+# if !defined(mad_f_scale64)
+# if defined(OPT_ACCURACY)
+# define mad_f_scale64(hi, lo) \
+ ((((mad_fixed_t) \
+ (((hi) << (32 - (MAD_F_SCALEBITS - 1))) | \
+ ((lo) >> (MAD_F_SCALEBITS - 1)))) + 1) >> 1)
+# else
+# define mad_f_scale64(hi, lo) \
+ ((mad_fixed_t) \
+ (((hi) << (32 - MAD_F_SCALEBITS)) | \
+ ((lo) >> MAD_F_SCALEBITS)))
+# endif
+# define MAD_F_SCALEBITS MAD_F_FRACBITS
+# endif
+
+/* C routines */
+
+mad_fixed_t mad_f_abs(mad_fixed_t);
+mad_fixed_t mad_f_div(mad_fixed_t, mad_fixed_t);
+
+# endif
diff --git a/contrib/libmad/frame.c b/contrib/libmad/frame.c
new file mode 100644
index 000000000..0cb3d0f33
--- /dev/null
+++ b/contrib/libmad/frame.c
@@ -0,0 +1,503 @@
+/*
+ * libmad - MPEG audio decoder library
+ * Copyright (C) 2000-2004 Underbit Technologies, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: frame.c,v 1.29 2004/02/04 22:59:19 rob Exp $
+ */
+
+# ifdef HAVE_CONFIG_H
+# include "config.h"
+# endif
+
+# include "global.h"
+
+# include <stdlib.h>
+
+# include "bit.h"
+# include "stream.h"
+# include "frame.h"
+# include "timer.h"
+# include "layer12.h"
+# include "layer3.h"
+
+static
+unsigned long const bitrate_table[5][15] = {
+ /* MPEG-1 */
+ { 0, 32000, 64000, 96000, 128000, 160000, 192000, 224000, /* Layer I */
+ 256000, 288000, 320000, 352000, 384000, 416000, 448000 },
+ { 0, 32000, 48000, 56000, 64000, 80000, 96000, 112000, /* Layer II */
+ 128000, 160000, 192000, 224000, 256000, 320000, 384000 },
+ { 0, 32000, 40000, 48000, 56000, 64000, 80000, 96000, /* Layer III */
+ 112000, 128000, 160000, 192000, 224000, 256000, 320000 },
+
+ /* MPEG-2 LSF */
+ { 0, 32000, 48000, 56000, 64000, 80000, 96000, 112000, /* Layer I */
+ 128000, 144000, 160000, 176000, 192000, 224000, 256000 },
+ { 0, 8000, 16000, 24000, 32000, 40000, 48000, 56000, /* Layers */
+ 64000, 80000, 96000, 112000, 128000, 144000, 160000 } /* II & III */
+};
+
+static
+unsigned int const samplerate_table[3] = { 44100, 48000, 32000 };
+
+static
+int (*const decoder_table[3])(struct mad_stream *, struct mad_frame *) = {
+ mad_layer_I,
+ mad_layer_II,
+ mad_layer_III
+};
+
+/*
+ * NAME: header->init()
+ * DESCRIPTION: initialize header struct
+ */
+void mad_header_init(struct mad_header *header)
+{
+ header->layer = 0;
+ header->mode = 0;
+ header->mode_extension = 0;
+ header->emphasis = 0;
+
+ header->bitrate = 0;
+ header->samplerate = 0;
+
+ header->crc_check = 0;
+ header->crc_target = 0;
+
+ header->flags = 0;
+ header->private_bits = 0;
+
+ header->duration = mad_timer_zero;
+}
+
+/*
+ * NAME: frame->init()
+ * DESCRIPTION: initialize frame struct
+ */
+void mad_frame_init(struct mad_frame *frame)
+{
+ mad_header_init(&frame->header);
+
+ frame->options = 0;
+
+ frame->overlap = 0;
+ mad_frame_mute(frame);
+}
+
+/*
+ * NAME: frame->finish()
+ * DESCRIPTION: deallocate any dynamic memory associated with frame
+ */
+void mad_frame_finish(struct mad_frame *frame)
+{
+ mad_header_finish(&frame->header);
+
+ if (frame->overlap) {
+ free(frame->overlap);
+ frame->overlap = 0;
+ }
+}
+
+/*
+ * NAME: decode_header()
+ * DESCRIPTION: read header data and following CRC word
+ */
+static
+int decode_header(struct mad_header *header, struct mad_stream *stream)
+{
+ unsigned int index;
+
+ header->flags = 0;
+ header->private_bits = 0;
+
+ /* header() */
+
+ /* syncword */
+ mad_bit_skip(&stream->ptr, 11);
+
+ /* MPEG 2.5 indicator (really part of syncword) */
+ if (mad_bit_read(&stream->ptr, 1) == 0)
+ header->flags |= MAD_FLAG_MPEG_2_5_EXT;
+
+ /* ID */
+ if (mad_bit_read(&stream->ptr, 1) == 0)
+ header->flags |= MAD_FLAG_LSF_EXT;
+ else if (header->flags & MAD_FLAG_MPEG_2_5_EXT) {
+ stream->error = MAD_ERROR_LOSTSYNC;
+ return -1;
+ }
+
+ /* layer */
+ header->layer = 4 - mad_bit_read(&stream->ptr, 2);
+
+ if (header->layer == 4) {
+ stream->error = MAD_ERROR_BADLAYER;
+ return -1;
+ }
+
+ /* protection_bit */
+ if (mad_bit_read(&stream->ptr, 1) == 0) {
+ header->flags |= MAD_FLAG_PROTECTION;
+ header->crc_check = mad_bit_crc(stream->ptr, 16, 0xffff);
+ }
+
+ /* bitrate_index */
+ index = mad_bit_read(&stream->ptr, 4);
+
+ if (index == 15) {
+ stream->error = MAD_ERROR_BADBITRATE;
+ return -1;
+ }
+
+ if (header->flags & MAD_FLAG_LSF_EXT)
+ header->bitrate = bitrate_table[3 + (header->layer >> 1)][index];
+ else
+ header->bitrate = bitrate_table[header->layer - 1][index];
+
+ /* sampling_frequency */
+ index = mad_bit_read(&stream->ptr, 2);
+
+ if (index == 3) {
+ stream->error = MAD_ERROR_BADSAMPLERATE;
+ return -1;
+ }
+
+ header->samplerate = samplerate_table[index];
+
+ if (header->flags & MAD_FLAG_LSF_EXT) {
+ header->samplerate /= 2;
+
+ if (header->flags & MAD_FLAG_MPEG_2_5_EXT)
+ header->samplerate /= 2;
+ }
+
+ /* padding_bit */
+ if (mad_bit_read(&stream->ptr, 1))
+ header->flags |= MAD_FLAG_PADDING;
+
+ /* private_bit */
+ if (mad_bit_read(&stream->ptr, 1))
+ header->private_bits |= MAD_PRIVATE_HEADER;
+
+ /* mode */
+ header->mode = 3 - mad_bit_read(&stream->ptr, 2);
+
+ /* mode_extension */
+ header->mode_extension = mad_bit_read(&stream->ptr, 2);
+
+ /* copyright */
+ if (mad_bit_read(&stream->ptr, 1))
+ header->flags |= MAD_FLAG_COPYRIGHT;
+
+ /* original/copy */
+ if (mad_bit_read(&stream->ptr, 1))
+ header->flags |= MAD_FLAG_ORIGINAL;
+
+ /* emphasis */
+ header->emphasis = mad_bit_read(&stream->ptr, 2);
+
+# if defined(OPT_STRICT)
+ /*
+ * ISO/IEC 11172-3 says this is a reserved emphasis value, but
+ * streams exist which use it anyway. Since the value is not important
+ * to the decoder proper, we allow it unless OPT_STRICT is defined.
+ */
+ if (header->emphasis == MAD_EMPHASIS_RESERVED) {
+ stream->error = MAD_ERROR_BADEMPHASIS;
+ return -1;
+ }
+# endif
+
+ /* error_check() */
+
+ /* crc_check */
+ if (header->flags & MAD_FLAG_PROTECTION)
+ header->crc_target = mad_bit_read(&stream->ptr, 16);
+
+ return 0;
+}
+
+/*
+ * NAME: free_bitrate()
+ * DESCRIPTION: attempt to discover the bitstream's free bitrate
+ */
+static
+int free_bitrate(struct mad_stream *stream, struct mad_header const *header)
+{
+ struct mad_bitptr keep_ptr;
+ unsigned long rate = 0;
+ unsigned int pad_slot, slots_per_frame;
+ unsigned char const *ptr = 0;
+
+ keep_ptr = stream->ptr;
+
+ pad_slot = (header->flags & MAD_FLAG_PADDING) ? 1 : 0;
+ slots_per_frame = (header->layer == MAD_LAYER_III &&
+ (header->flags & MAD_FLAG_LSF_EXT)) ? 72 : 144;
+
+ while (mad_stream_sync(stream) == 0) {
+ struct mad_stream peek_stream;
+ struct mad_header peek_header;
+
+ peek_stream = *stream;
+ peek_header = *header;
+
+ if (decode_header(&peek_header, &peek_stream) == 0 &&
+ peek_header.layer == header->layer &&
+ peek_header.samplerate == header->samplerate) {
+ unsigned int N;
+
+ ptr = mad_bit_nextbyte(&stream->ptr);
+
+ N = ptr - stream->this_frame;
+
+ if (header->layer == MAD_LAYER_I) {
+ rate = (unsigned long) header->samplerate *
+ (N - 4 * pad_slot + 4) / 48 / 1000;
+ }
+ else {
+ rate = (unsigned long) header->samplerate *
+ (N - pad_slot + 1) / slots_per_frame / 1000;
+ }
+
+ if (rate >= 8)
+ break;
+ }
+
+ mad_bit_skip(&stream->ptr, 8);
+ }
+
+ stream->ptr = keep_ptr;
+
+ if (rate < 8 || (header->layer == MAD_LAYER_III && rate > 640)) {
+ stream->error = MAD_ERROR_LOSTSYNC;
+ return -1;
+ }
+
+ stream->freerate = rate * 1000;
+
+ return 0;
+}
+
+/*
+ * NAME: header->decode()
+ * DESCRIPTION: read the next frame header from the stream
+ */
+int mad_header_decode(struct mad_header *header, struct mad_stream *stream)
+{
+ register unsigned char const *ptr, *end;
+ unsigned int pad_slot, N;
+
+ ptr = stream->next_frame;
+ end = stream->bufend;
+
+ if (ptr == 0) {
+ stream->error = MAD_ERROR_BUFPTR;
+ goto fail;
+ }
+
+ /* stream skip */
+ if (stream->skiplen) {
+ if (!stream->sync)
+ ptr = stream->this_frame;
+
+ if (end - ptr < stream->skiplen) {
+ stream->skiplen -= end - ptr;
+ stream->next_frame = end;
+
+ stream->error = MAD_ERROR_BUFLEN;
+ goto fail;
+ }
+
+ ptr += stream->skiplen;
+ stream->skiplen = 0;
+
+ stream->sync = 1;
+ }
+
+ sync:
+ /* synchronize */
+ if (stream->sync) {
+ if (end - ptr < MAD_BUFFER_GUARD) {
+ stream->next_frame = ptr;
+
+ stream->error = MAD_ERROR_BUFLEN;
+ goto fail;
+ }
+ else if (!(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0)) {
+ /* mark point where frame sync word was expected */
+ stream->this_frame = ptr;
+ stream->next_frame = ptr + 1;
+
+ stream->error = MAD_ERROR_LOSTSYNC;
+ goto fail;
+ }
+ }
+ else {
+ mad_bit_init(&stream->ptr, ptr);
+
+ if (mad_stream_sync(stream) == -1) {
+ if (end - stream->next_frame >= MAD_BUFFER_GUARD)
+ stream->next_frame = end - MAD_BUFFER_GUARD;
+
+ stream->error = MAD_ERROR_BUFLEN;
+ goto fail;
+ }
+
+ ptr = mad_bit_nextbyte(&stream->ptr);
+ }
+
+ /* begin processing */
+ stream->this_frame = ptr;
+ stream->next_frame = ptr + 1; /* possibly bogus sync word */
+
+ mad_bit_init(&stream->ptr, stream->this_frame);
+
+ if (decode_header(header, stream) == -1)
+ goto fail;
+
+ /* calculate frame duration */
+ mad_timer_set(&header->duration, 0,
+ 32 * MAD_NSBSAMPLES(header), header->samplerate);
+
+ /* calculate free bit rate */
+ if (header->bitrate == 0) {
+ if ((stream->freerate == 0 || !stream->sync ||
+ (header->layer == MAD_LAYER_III && stream->freerate > 640000)) &&
+ free_bitrate(stream, header) == -1)
+ goto fail;
+
+ header->bitrate = stream->freerate;
+ header->flags |= MAD_FLAG_FREEFORMAT;
+ }
+
+ /* calculate beginning of next frame */
+ pad_slot = (header->flags & MAD_FLAG_PADDING) ? 1 : 0;
+
+ if (header->layer == MAD_LAYER_I)
+ N = ((12 * header->bitrate / header->samplerate) + pad_slot) * 4;
+ else {
+ unsigned int slots_per_frame;
+
+ slots_per_frame = (header->layer == MAD_LAYER_III &&
+ (header->flags & MAD_FLAG_LSF_EXT)) ? 72 : 144;
+
+ N = (slots_per_frame * header->bitrate / header->samplerate) + pad_slot;
+ }
+
+ /* verify there is enough data left in buffer to decode this frame */
+ if (N + MAD_BUFFER_GUARD > end - stream->this_frame) {
+ stream->next_frame = stream->this_frame;
+
+ stream->error = MAD_ERROR_BUFLEN;
+ goto fail;
+ }
+
+ stream->next_frame = stream->this_frame + N;
+
+ if (!stream->sync) {
+ /* check that a valid frame header follows this frame */
+
+ ptr = stream->next_frame;
+ if (!(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0)) {
+ ptr = stream->next_frame = stream->this_frame + 1;
+ goto sync;
+ }
+
+ stream->sync = 1;
+ }
+
+ header->flags |= MAD_FLAG_INCOMPLETE;
+
+ return 0;
+
+ fail:
+ stream->sync = 0;
+
+ return -1;
+}
+
+/*
+ * NAME: frame->decode()
+ * DESCRIPTION: decode a single frame from a bitstream
+ */
+int mad_frame_decode(struct mad_frame *frame, struct mad_stream *stream)
+{
+ frame->options = stream->options;
+
+ /* header() */
+ /* error_check() */
+
+ if (!(frame->header.flags & MAD_FLAG_INCOMPLETE) &&
+ mad_header_decode(&frame->header, stream) == -1)
+ goto fail;
+
+ /* audio_data() */
+
+ frame->header.flags &= ~MAD_FLAG_INCOMPLETE;
+
+ if (decoder_table[frame->header.layer - 1](stream, frame) == -1) {
+ if (!MAD_RECOVERABLE(stream->error))
+ stream->next_frame = stream->this_frame;
+
+ goto fail;
+ }
+
+ /* ancillary_data() */
+
+ if (frame->header.layer != MAD_LAYER_III) {
+ struct mad_bitptr next_frame;
+
+ mad_bit_init(&next_frame, stream->next_frame);
+
+ stream->anc_ptr = stream->ptr;
+ stream->anc_bitlen = mad_bit_length(&stream->ptr, &next_frame);
+
+ mad_bit_finish(&next_frame);
+ }
+
+ return 0;
+
+ fail:
+ stream->anc_bitlen = 0;
+ return -1;
+}
+
+/*
+ * NAME: frame->mute()
+ * DESCRIPTION: zero all subband values so the frame becomes silent
+ */
+void mad_frame_mute(struct mad_frame *frame)
+{
+ unsigned int s, sb;
+
+ for (s = 0; s < 36; ++s) {
+ for (sb = 0; sb < 32; ++sb) {
+ frame->sbsample[0][s][sb] =
+ frame->sbsample[1][s][sb] = 0;
+ }
+ }
+
+ if (frame->overlap) {
+ for (s = 0; s < 18; ++s) {
+ for (sb = 0; sb < 32; ++sb) {
+ (*frame->overlap)[0][sb][s] =
+ (*frame->overlap)[1][sb][s] = 0;
+ }
+ }
+ }
+}
diff --git a/contrib/libmad/frame.h b/contrib/libmad/frame.h
new file mode 100644
index 000000000..3f5bf37ef
--- /dev/null
+++ b/contrib/libmad/frame.h
@@ -0,0 +1,118 @@
+/*
+ * libmad - MPEG audio decoder library
+ * Copyright (C) 2000-2004 Underbit Technologies, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: frame.h,v 1.20 2004/01/23 09:41:32 rob Exp $
+ */
+
+# ifndef LIBMAD_FRAME_H
+# define LIBMAD_FRAME_H
+
+# include "fixed.h"
+# include "timer.h"
+# include "stream.h"
+
+enum mad_layer {
+ MAD_LAYER_I = 1, /* Layer I */
+ MAD_LAYER_II = 2, /* Layer II */
+ MAD_LAYER_III = 3 /* Layer III */
+};
+
+enum mad_mode {
+ MAD_MODE_SINGLE_CHANNEL = 0, /* single channel */
+ MAD_MODE_DUAL_CHANNEL = 1, /* dual channel */
+ MAD_MODE_JOINT_STEREO = 2, /* joint (MS/intensity) stereo */
+ MAD_MODE_STEREO = 3 /* normal LR stereo */
+};
+
+enum mad_emphasis {
+ MAD_EMPHASIS_NONE = 0, /* no emphasis */
+ MAD_EMPHASIS_50_15_US = 1, /* 50/15 microseconds emphasis */
+ MAD_EMPHASIS_CCITT_J_17 = 3, /* CCITT J.17 emphasis */
+ MAD_EMPHASIS_RESERVED = 2 /* unknown emphasis */
+};
+
+struct mad_header {
+ enum mad_layer layer; /* audio layer (1, 2, or 3) */
+ enum mad_mode mode; /* channel mode (see above) */
+ int mode_extension; /* additional mode info */
+ enum mad_emphasis emphasis; /* de-emphasis to use (see above) */
+
+ unsigned long bitrate; /* stream bitrate (bps) */
+ unsigned int samplerate; /* sampling frequency (Hz) */
+
+ unsigned short crc_check; /* frame CRC accumulator */
+ unsigned short crc_target; /* final target CRC checksum */
+
+ int flags; /* flags (see below) */
+ int private_bits; /* private bits (see below) */
+
+ mad_timer_t duration; /* audio playing time of frame */
+};
+
+struct mad_frame {
+ struct mad_header header; /* MPEG audio header */
+
+ int options; /* decoding options (from stream) */
+
+ mad_fixed_t sbsample[2][36][32]; /* synthesis subband filter samples */
+ mad_fixed_t (*overlap)[2][32][18]; /* Layer III block overlap data */
+};
+
+# define MAD_NCHANNELS(header) ((header)->mode ? 2 : 1)
+# define MAD_NSBSAMPLES(header) \
+ ((header)->layer == MAD_LAYER_I ? 12 : \
+ (((header)->layer == MAD_LAYER_III && \
+ ((header)->flags & MAD_FLAG_LSF_EXT)) ? 18 : 36))
+
+enum {
+ MAD_FLAG_NPRIVATE_III = 0x0007, /* number of Layer III private bits */
+ MAD_FLAG_INCOMPLETE = 0x0008, /* header but not data is decoded */
+
+ MAD_FLAG_PROTECTION = 0x0010, /* frame has CRC protection */
+ MAD_FLAG_COPYRIGHT = 0x0020, /* frame is copyright */
+ MAD_FLAG_ORIGINAL = 0x0040, /* frame is original (else copy) */
+ MAD_FLAG_PADDING = 0x0080, /* frame has additional slot */
+
+ MAD_FLAG_I_STEREO = 0x0100, /* uses intensity joint stereo */
+ MAD_FLAG_MS_STEREO = 0x0200, /* uses middle/side joint stereo */
+ MAD_FLAG_FREEFORMAT = 0x0400, /* uses free format bitrate */
+
+ MAD_FLAG_LSF_EXT = 0x1000, /* lower sampling freq. extension */
+ MAD_FLAG_MC_EXT = 0x2000, /* multichannel audio extension */
+ MAD_FLAG_MPEG_2_5_EXT = 0x4000 /* MPEG 2.5 (unofficial) extension */
+};
+
+enum {
+ MAD_PRIVATE_HEADER = 0x0100, /* header private bit */
+ MAD_PRIVATE_III = 0x001f /* Layer III private bits (up to 5) */
+};
+
+void mad_header_init(struct mad_header *);
+
+# define mad_header_finish(header) /* nothing */
+
+int mad_header_decode(struct mad_header *, struct mad_stream *);
+
+void mad_frame_init(struct mad_frame *);
+void mad_frame_finish(struct mad_frame *);
+
+int mad_frame_decode(struct mad_frame *, struct mad_stream *);
+
+void mad_frame_mute(struct mad_frame *);
+
+# endif
diff --git a/contrib/libmad/global.h b/contrib/libmad/global.h
new file mode 100644
index 000000000..a6debfd8b
--- /dev/null
+++ b/contrib/libmad/global.h
@@ -0,0 +1,58 @@
+/*
+ * libmad - MPEG audio decoder library
+ * Copyright (C) 2000-2004 Underbit Technologies, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: global.h,v 1.11 2004/01/23 09:41:32 rob Exp $
+ */
+
+# ifndef LIBMAD_GLOBAL_H
+# define LIBMAD_GLOBAL_H
+
+/* conditional debugging */
+
+# if defined(DEBUG) && defined(NDEBUG)
+# error "cannot define both DEBUG and NDEBUG"
+# endif
+
+# if defined(DEBUG)
+# include <stdio.h>
+# endif
+
+/* conditional features */
+
+# if defined(OPT_SPEED) && defined(OPT_ACCURACY)
+# error "cannot optimize for both speed and accuracy"
+# endif
+
+# if defined(OPT_SPEED) && !defined(OPT_SSO)
+# define OPT_SSO
+# endif
+
+# if defined(HAVE_UNISTD_H) && defined(HAVE_WAITPID) && \
+ defined(HAVE_FCNTL) && defined(HAVE_PIPE) && defined(HAVE_FORK)
+# define USE_ASYNC
+# endif
+
+# if !defined(HAVE_ASSERT_H)
+# if defined(NDEBUG)
+# define assert(x) /* nothing */
+# else
+# define assert(x) do { if (!(x)) abort(); } while (0)
+# endif
+# endif
+
+# endif
diff --git a/contrib/libmad/huffman.c b/contrib/libmad/huffman.c
new file mode 100644
index 000000000..a230a9c10
--- /dev/null
+++ b/contrib/libmad/huffman.c
@@ -0,0 +1,3109 @@
+/*
+ * libmad - MPEG audio decoder library
+ * Copyright (C) 2000-2004 Underbit Technologies, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: huffman.c,v 1.10 2004/01/23 09:41:32 rob Exp $
+ */
+
+# ifdef HAVE_CONFIG_H
+# include "config.h"
+# endif
+
+# include "global.h"
+
+# include "huffman.h"
+
+/*
+ * These are the Huffman code words for Layer III.
+ * The data for these tables are derived from Table B.7 of ISO/IEC 11172-3.
+ *
+ * These tables support decoding up to 4 Huffman code bits at a time.
+ */
+
+# if defined(__GNUC__) || \
+ (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901)
+# define PTR(offs, bits) { .ptr = { 0, bits, offs } }
+# define V(v, w, x, y, hlen) { .value = { 1, hlen, v, w, x, y } }
+# else
+# define PTR(offs, bits) { { 0, bits, offs } }
+# if defined(WORDS_BIGENDIAN)
+# define V(v, w, x, y, hlen) { { 1, hlen, (v << 11) | (w << 10) | \
+ (x << 9) | (y << 8) } }
+# else
+# define V(v, w, x, y, hlen) { { 1, hlen, (v << 0) | (w << 1) | \
+ (x << 2) | (y << 3) } }
+# endif
+# endif
+
+static
+union huffquad const hufftabA[] = {
+ /* 0000 */ PTR(16, 2),
+ /* 0001 */ PTR(20, 2),
+ /* 0010 */ PTR(24, 1),
+ /* 0011 */ PTR(26, 1),
+ /* 0100 */ V(0, 0, 1, 0, 4),
+ /* 0101 */ V(0, 0, 0, 1, 4),
+ /* 0110 */ V(0, 1, 0, 0, 4),
+ /* 0111 */ V(1, 0, 0, 0, 4),
+ /* 1000 */ V(0, 0, 0, 0, 1),
+ /* 1001 */ V(0, 0, 0, 0, 1),
+ /* 1010 */ V(0, 0, 0, 0, 1),
+ /* 1011 */ V(0, 0, 0, 0, 1),
+ /* 1100 */ V(0, 0, 0, 0, 1),
+ /* 1101 */ V(0, 0, 0, 0, 1),
+ /* 1110 */ V(0, 0, 0, 0, 1),
+ /* 1111 */ V(0, 0, 0, 0, 1),
+
+ /* 0000 ... */
+ /* 00 */ V(1, 0, 1, 1, 2), /* 16 */
+ /* 01 */ V(1, 1, 1, 1, 2),
+ /* 10 */ V(1, 1, 0, 1, 2),
+ /* 11 */ V(1, 1, 1, 0, 2),
+
+ /* 0001 ... */
+ /* 00 */ V(0, 1, 1, 1, 2), /* 20 */
+ /* 01 */ V(0, 1, 0, 1, 2),
+ /* 10 */ V(1, 0, 0, 1, 1),
+ /* 11 */ V(1, 0, 0, 1, 1),
+
+ /* 0010 ... */
+ /* 0 */ V(0, 1, 1, 0, 1), /* 24 */
+ /* 1 */ V(0, 0, 1, 1, 1),
+
+ /* 0011 ... */
+ /* 0 */ V(1, 0, 1, 0, 1), /* 26 */
+ /* 1 */ V(1, 1, 0, 0, 1)
+};
+
+static
+union huffquad const hufftabB[] = {
+ /* 0000 */ V(1, 1, 1, 1, 4),
+ /* 0001 */ V(1, 1, 1, 0, 4),
+ /* 0010 */ V(1, 1, 0, 1, 4),
+ /* 0011 */ V(1, 1, 0, 0, 4),
+ /* 0100 */ V(1, 0, 1, 1, 4),
+ /* 0101 */ V(1, 0, 1, 0, 4),
+ /* 0110 */ V(1, 0, 0, 1, 4),
+ /* 0111 */ V(1, 0, 0, 0, 4),
+ /* 1000 */ V(0, 1, 1, 1, 4),
+ /* 1001 */ V(0, 1, 1, 0, 4),
+ /* 1010 */ V(0, 1, 0, 1, 4),
+ /* 1011 */ V(0, 1, 0, 0, 4),
+ /* 1100 */ V(0, 0, 1, 1, 4),
+ /* 1101 */ V(0, 0, 1, 0, 4),
+ /* 1110 */ V(0, 0, 0, 1, 4),
+ /* 1111 */ V(0, 0, 0, 0, 4)
+};
+
+# undef V
+# undef PTR
+
+# if defined(__GNUC__) || \
+ (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901)
+# define PTR(offs, bits) { .ptr = { 0, bits, offs } }
+# define V(x, y, hlen) { .value = { 1, hlen, x, y } }
+# else
+# define PTR(offs, bits) { { 0, bits, offs } }
+# if defined(WORDS_BIGENDIAN)
+# define V(x, y, hlen) { { 1, hlen, (x << 8) | (y << 4) } }
+# else
+# define V(x, y, hlen) { { 1, hlen, (x << 0) | (y << 4) } }
+# endif
+# endif
+
+static
+union huffpair const hufftab0[] = {
+ /* */ V(0, 0, 0)
+};
+
+static
+union huffpair const hufftab1[] = {
+ /* 000 */ V(1, 1, 3),
+ /* 001 */ V(0, 1, 3),
+ /* 010 */ V(1, 0, 2),
+ /* 011 */ V(1, 0, 2),
+ /* 100 */ V(0, 0, 1),
+ /* 101 */ V(0, 0, 1),
+ /* 110 */ V(0, 0, 1),
+ /* 111 */ V(0, 0, 1)
+};
+
+static
+union huffpair const hufftab2[] = {
+ /* 000 */ PTR(8, 3),
+ /* 001 */ V(1, 1, 3),
+ /* 010 */ V(0, 1, 3),
+ /* 011 */ V(1, 0, 3),
+ /* 100 */ V(0, 0, 1),
+ /* 101 */ V(0, 0, 1),
+ /* 110 */ V(0, 0, 1),
+ /* 111 */ V(0, 0, 1),
+
+ /* 000 ... */
+ /* 000 */ V(2, 2, 3), /* 8 */
+ /* 001 */ V(0, 2, 3),
+ /* 010 */ V(1, 2, 2),
+ /* 011 */ V(1, 2, 2),
+ /* 100 */ V(2, 1, 2),
+ /* 101 */ V(2, 1, 2),
+ /* 110 */ V(2, 0, 2),
+ /* 111 */ V(2, 0, 2)
+};
+
+static
+union huffpair const hufftab3[] = {
+ /* 000 */ PTR(8, 3),
+ /* 001 */ V(1, 0, 3),
+ /* 010 */ V(1, 1, 2),
+ /* 011 */ V(1, 1, 2),
+ /* 100 */ V(0, 1, 2),
+ /* 101 */ V(0, 1, 2),
+ /* 110 */ V(0, 0, 2),
+ /* 111 */ V(0, 0, 2),
+
+ /* 000 ... */
+ /* 000 */ V(2, 2, 3), /* 8 */
+ /* 001 */ V(0, 2, 3),
+ /* 010 */ V(1, 2, 2),
+ /* 011 */ V(1, 2, 2),
+ /* 100 */ V(2, 1, 2),
+ /* 101 */ V(2, 1, 2),
+ /* 110 */ V(2, 0, 2),
+ /* 111 */ V(2, 0, 2)
+};
+
+static
+union huffpair const hufftab5[] = {
+ /* 000 */ PTR(8, 4),
+ /* 001 */ V(1, 1, 3),
+ /* 010 */ V(0, 1, 3),
+ /* 011 */ V(1, 0, 3),
+ /* 100 */ V(0, 0, 1),
+ /* 101 */ V(0, 0, 1),
+ /* 110 */ V(0, 0, 1),
+ /* 111 */ V(0, 0, 1),
+
+ /* 000 ... */
+ /* 0000 */ PTR(24, 1), /* 8 */
+ /* 0001 */ V(3, 2, 4),
+ /* 0010 */ V(3, 1, 3),
+ /* 0011 */ V(3, 1, 3),
+ /* 0100 */ V(1, 3, 4),
+ /* 0101 */ V(0, 3, 4),
+ /* 0110 */ V(3, 0, 4),
+ /* 0111 */ V(2, 2, 4),
+ /* 1000 */ V(1, 2, 3),
+ /* 1001 */ V(1, 2, 3),
+ /* 1010 */ V(2, 1, 3),
+ /* 1011 */ V(2, 1, 3),
+ /* 1100 */ V(0, 2, 3),
+ /* 1101 */ V(0, 2, 3),
+ /* 1110 */ V(2, 0, 3),
+ /* 1111 */ V(2, 0, 3),
+
+ /* 000 0000 ... */
+ /* 0 */ V(3, 3, 1), /* 24 */
+ /* 1 */ V(2, 3, 1)
+};
+
+static
+union huffpair const hufftab6[] = {
+ /* 0000 */ PTR(16, 3),
+ /* 0001 */ PTR(24, 1),
+ /* 0010 */ PTR(26, 1),
+ /* 0011 */ V(1, 2, 4),
+ /* 0100 */ V(2, 1, 4),
+ /* 0101 */ V(2, 0, 4),
+ /* 0110 */ V(0, 1, 3),
+ /* 0111 */ V(0, 1, 3),
+ /* 1000 */ V(1, 1, 2),
+ /* 1001 */ V(1, 1, 2),
+ /* 1010 */ V(1, 1, 2),
+ /* 1011 */ V(1, 1, 2),
+ /* 1100 */ V(1, 0, 3),
+ /* 1101 */ V(1, 0, 3),
+ /* 1110 */ V(0, 0, 3),
+ /* 1111 */ V(0, 0, 3),
+
+ /* 0000 ... */
+ /* 000 */ V(3, 3, 3), /* 16 */
+ /* 001 */ V(0, 3, 3),
+ /* 010 */ V(2, 3, 2),
+ /* 011 */ V(2, 3, 2),
+ /* 100 */ V(3, 2, 2),
+ /* 101 */ V(3, 2, 2),
+ /* 110 */ V(3, 0, 2),
+ /* 111 */ V(3, 0, 2),
+
+ /* 0001 ... */
+ /* 0 */ V(1, 3, 1), /* 24 */
+ /* 1 */ V(3, 1, 1),
+
+ /* 0010 ... */
+ /* 0 */ V(2, 2, 1), /* 26 */
+ /* 1 */ V(0, 2, 1)
+};
+
+static
+union huffpair const hufftab7[] = {
+ /* 0000 */ PTR(16, 4),
+ /* 0001 */ PTR(32, 4),
+ /* 0010 */ PTR(48, 2),
+ /* 0011 */ V(1, 1, 4),
+ /* 0100 */ V(0, 1, 3),
+ /* 0101 */ V(0, 1, 3),
+ /* 0110 */ V(1, 0, 3),
+ /* 0111 */ V(1, 0, 3),
+ /* 1000 */ V(0, 0, 1),
+ /* 1001 */ V(0, 0, 1),
+ /* 1010 */ V(0, 0, 1),
+ /* 1011 */ V(0, 0, 1),
+ /* 1100 */ V(0, 0, 1),
+ /* 1101 */ V(0, 0, 1),
+ /* 1110 */ V(0, 0, 1),
+ /* 1111 */ V(0, 0, 1),
+
+ /* 0000 ... */
+ /* 0000 */ PTR(52, 2), /* 16 */
+ /* 0001 */ PTR(56, 1),
+ /* 0010 */ PTR(58, 1),
+ /* 0011 */ V(1, 5, 4),
+ /* 0100 */ V(5, 1, 4),
+ /* 0101 */ PTR(60, 1),
+ /* 0110 */ V(5, 0, 4),
+ /* 0111 */ PTR(62, 1),
+ /* 1000 */ V(2, 4, 4),
+ /* 1001 */ V(4, 2, 4),
+ /* 1010 */ V(1, 4, 3),
+ /* 1011 */ V(1, 4, 3),
+ /* 1100 */ V(4, 1, 3),
+ /* 1101 */ V(4, 1, 3),
+ /* 1110 */ V(4, 0, 3),
+ /* 1111 */ V(4, 0, 3),
+
+ /* 0001 ... */
+ /* 0000 */ V(0, 4, 4), /* 32 */
+ /* 0001 */ V(2, 3, 4),
+ /* 0010 */ V(3, 2, 4),
+ /* 0011 */ V(0, 3, 4),
+ /* 0100 */ V(1, 3, 3),
+ /* 0101 */ V(1, 3, 3),
+ /* 0110 */ V(3, 1, 3),
+ /* 0111 */ V(3, 1, 3),
+ /* 1000 */ V(3, 0, 3),
+ /* 1001 */ V(3, 0, 3),
+ /* 1010 */ V(2, 2, 3),
+ /* 1011 */ V(2, 2, 3),
+ /* 1100 */ V(1, 2, 2),
+ /* 1101 */ V(1, 2, 2),
+ /* 1110 */ V(1, 2, 2),
+ /* 1111 */ V(1, 2, 2),
+
+ /* 0010 ... */
+ /* 00 */ V(2, 1, 1), /* 48 */
+ /* 01 */ V(2, 1, 1),
+ /* 10 */ V(0, 2, 2),
+ /* 11 */ V(2, 0, 2),
+
+ /* 0000 0000 ... */
+ /* 00 */ V(5, 5, 2), /* 52 */
+ /* 01 */ V(4, 5, 2),
+ /* 10 */ V(5, 4, 2),
+ /* 11 */ V(5, 3, 2),
+
+ /* 0000 0001 ... */
+ /* 0 */ V(3, 5, 1), /* 56 */
+ /* 1 */ V(4, 4, 1),
+
+ /* 0000 0010 ... */
+ /* 0 */ V(2, 5, 1), /* 58 */
+ /* 1 */ V(5, 2, 1),
+
+ /* 0000 0101 ... */
+ /* 0 */ V(0, 5, 1), /* 60 */
+ /* 1 */ V(3, 4, 1),
+
+ /* 0000 0111 ... */
+ /* 0 */ V(4, 3, 1), /* 62 */
+ /* 1 */ V(3, 3, 1)
+};
+
+# if 0
+/* this version saves 8 entries (16 bytes) at the expense of
+ an extra lookup in 4 out of 36 cases */
+static
+union huffpair const hufftab8[] = {
+ /* 0000 */ PTR(16, 4),
+ /* 0001 */ PTR(32, 2),
+ /* 0010 */ V(1, 2, 4),
+ /* 0011 */ V(2, 1, 4),
+ /* 0100 */ V(1, 1, 2),
+ /* 0101 */ V(1, 1, 2),
+ /* 0110 */ V(1, 1, 2),
+ /* 0111 */ V(1, 1, 2),
+ /* 1000 */ V(0, 1, 3),
+ /* 1001 */ V(0, 1, 3),
+ /* 1010 */ V(1, 0, 3),
+ /* 1011 */ V(1, 0, 3),
+ /* 1100 */ V(0, 0, 2),
+ /* 1101 */ V(0, 0, 2),
+ /* 1110 */ V(0, 0, 2),
+ /* 1111 */ V(0, 0, 2),
+
+ /* 0000 ... */
+ /* 0000 */ PTR(36, 3), /* 16 */
+ /* 0001 */ PTR(44, 2),
+ /* 0010 */ PTR(48, 1),
+ /* 0011 */ V(1, 5, 4),
+ /* 0100 */ V(5, 1, 4),
+ /* 0101 */ PTR(50, 1),
+ /* 0110 */ PTR(52, 1),
+ /* 0111 */ V(2, 4, 4),
+ /* 1000 */ V(4, 2, 4),
+ /* 1001 */ V(1, 4, 4),
+ /* 1010 */ V(4, 1, 3),
+ /* 1011 */ V(4, 1, 3),
+ /* 1100 */ V(0, 4, 4),
+ /* 1101 */ V(4, 0, 4),
+ /* 1110 */ V(2, 3, 4),
+ /* 1111 */ V(3, 2, 4),
+
+ /* 0001 ... */
+ /* 00 */ PTR(54, 2), /* 32 */
+ /* 01 */ V(2, 2, 2),
+ /* 10 */ V(0, 2, 2),
+ /* 11 */ V(2, 0, 2),
+
+ /* 0000 0000 ... */
+ /* 000 */ V(5, 5, 3), /* 36 */
+ /* 001 */ V(5, 4, 3),
+ /* 010 */ V(4, 5, 2),
+ /* 011 */ V(4, 5, 2),
+ /* 100 */ V(5, 3, 1),
+ /* 101 */ V(5, 3, 1),
+ /* 110 */ V(5, 3, 1),
+ /* 111 */ V(5, 3, 1),
+
+ /* 0000 0001 ... */
+ /* 00 */ V(3, 5, 2), /* 44 */
+ /* 01 */ V(4, 4, 2),
+ /* 10 */ V(2, 5, 1),
+ /* 11 */ V(2, 5, 1),
+
+ /* 0000 0010 ... */
+ /* 0 */ V(5, 2, 1), /* 48 */
+ /* 1 */ V(0, 5, 1),
+
+ /* 0000 0101 ... */
+ /* 0 */ V(3, 4, 1), /* 50 */
+ /* 1 */ V(4, 3, 1),
+
+ /* 0000 0110 ... */
+ /* 0 */ V(5, 0, 1), /* 52 */
+ /* 1 */ V(3, 3, 1),
+
+ /* 0001 00 ... */
+ /* 00 */ V(1, 3, 2), /* 54 */
+ /* 01 */ V(3, 1, 2),
+ /* 10 */ V(0, 3, 2),
+ /* 11 */ V(3, 0, 2),
+};
+# else
+static
+union huffpair const hufftab8[] = {
+ /* 0000 */ PTR(16, 4),
+ /* 0001 */ PTR(32, 4),
+ /* 0010 */ V(1, 2, 4),
+ /* 0011 */ V(2, 1, 4),
+ /* 0100 */ V(1, 1, 2),
+ /* 0101 */ V(1, 1, 2),
+ /* 0110 */ V(1, 1, 2),
+ /* 0111 */ V(1, 1, 2),
+ /* 1000 */ V(0, 1, 3),
+ /* 1001 */ V(0, 1, 3),
+ /* 1010 */ V(1, 0, 3),
+ /* 1011 */ V(1, 0, 3),
+ /* 1100 */ V(0, 0, 2),
+ /* 1101 */ V(0, 0, 2),
+ /* 1110 */ V(0, 0, 2),
+ /* 1111 */ V(0, 0, 2),
+
+ /* 0000 ... */
+ /* 0000 */ PTR(48, 3), /* 16 */
+ /* 0001 */ PTR(56, 2),
+ /* 0010 */ PTR(60, 1),
+ /* 0011 */ V(1, 5, 4),
+ /* 0100 */ V(5, 1, 4),
+ /* 0101 */ PTR(62, 1),
+ /* 0110 */ PTR(64, 1),
+ /* 0111 */ V(2, 4, 4),
+ /* 1000 */ V(4, 2, 4),
+ /* 1001 */ V(1, 4, 4),
+ /* 1010 */ V(4, 1, 3),
+ /* 1011 */ V(4, 1, 3),
+ /* 1100 */ V(0, 4, 4),
+ /* 1101 */ V(4, 0, 4),
+ /* 1110 */ V(2, 3, 4),
+ /* 1111 */ V(3, 2, 4),
+
+ /* 0001 ... */
+ /* 0000 */ V(1, 3, 4), /* 32 */
+ /* 0001 */ V(3, 1, 4),
+ /* 0010 */ V(0, 3, 4),
+ /* 0011 */ V(3, 0, 4),
+ /* 0100 */ V(2, 2, 2),
+ /* 0101 */ V(2, 2, 2),
+ /* 0110 */ V(2, 2, 2),
+ /* 0111 */ V(2, 2, 2),
+ /* 1000 */ V(0, 2, 2),
+ /* 1001 */ V(0, 2, 2),
+ /* 1010 */ V(0, 2, 2),
+ /* 1011 */ V(0, 2, 2),
+ /* 1100 */ V(2, 0, 2),
+ /* 1101 */ V(2, 0, 2),
+ /* 1110 */ V(2, 0, 2),
+ /* 1111 */ V(2, 0, 2),
+
+ /* 0000 0000 ... */
+ /* 000 */ V(5, 5, 3), /* 48 */
+ /* 001 */ V(5, 4, 3),
+ /* 010 */ V(4, 5, 2),
+ /* 011 */ V(4, 5, 2),
+ /* 100 */ V(5, 3, 1),
+ /* 101 */ V(5, 3, 1),
+ /* 110 */ V(5, 3, 1),
+ /* 111 */ V(5, 3, 1),
+
+ /* 0000 0001 ... */
+ /* 00 */ V(3, 5, 2), /* 56 */
+ /* 01 */ V(4, 4, 2),
+ /* 10 */ V(2, 5, 1),
+ /* 11 */ V(2, 5, 1),
+
+ /* 0000 0010 ... */
+ /* 0 */ V(5, 2, 1), /* 60 */
+ /* 1 */ V(0, 5, 1),
+
+ /* 0000 0101 ... */
+ /* 0 */ V(3, 4, 1), /* 62 */
+ /* 1 */ V(4, 3, 1),
+
+ /* 0000 0110 ... */
+ /* 0 */ V(5, 0, 1), /* 64 */
+ /* 1 */ V(3, 3, 1)
+};
+# endif
+
+static
+union huffpair const hufftab9[] = {
+ /* 0000 */ PTR(16, 4),
+ /* 0001 */ PTR(32, 3),
+ /* 0010 */ PTR(40, 2),
+ /* 0011 */ PTR(44, 2),
+ /* 0100 */ PTR(48, 1),
+ /* 0101 */ V(1, 2, 4),
+ /* 0110 */ V(2, 1, 4),
+ /* 0111 */ V(2, 0, 4),
+ /* 1000 */ V(1, 1, 3),
+ /* 1001 */ V(1, 1, 3),
+ /* 1010 */ V(0, 1, 3),
+ /* 1011 */ V(0, 1, 3),
+ /* 1100 */ V(1, 0, 3),
+ /* 1101 */ V(1, 0, 3),
+ /* 1110 */ V(0, 0, 3),
+ /* 1111 */ V(0, 0, 3),
+
+ /* 0000 ... */
+ /* 0000 */ PTR(50, 1), /* 16 */
+ /* 0001 */ V(3, 5, 4),
+ /* 0010 */ V(5, 3, 4),
+ /* 0011 */ PTR(52, 1),
+ /* 0100 */ V(4, 4, 4),
+ /* 0101 */ V(2, 5, 4),
+ /* 0110 */ V(5, 2, 4),
+ /* 0111 */ V(1, 5, 4),
+ /* 1000 */ V(5, 1, 3),
+ /* 1001 */ V(5, 1, 3),
+ /* 1010 */ V(3, 4, 3),
+ /* 1011 */ V(3, 4, 3),
+ /* 1100 */ V(4, 3, 3),
+ /* 1101 */ V(4, 3, 3),
+ /* 1110 */ V(5, 0, 4),
+ /* 1111 */ V(0, 4, 4),
+
+ /* 0001 ... */
+ /* 000 */ V(2, 4, 3), /* 32 */
+ /* 001 */ V(4, 2, 3),
+ /* 010 */ V(3, 3, 3),
+ /* 011 */ V(4, 0, 3),
+ /* 100 */ V(1, 4, 2),
+ /* 101 */ V(1, 4, 2),
+ /* 110 */ V(4, 1, 2),
+ /* 111 */ V(4, 1, 2),
+
+ /* 0010 ... */
+ /* 00 */ V(2, 3, 2), /* 40 */
+ /* 01 */ V(3, 2, 2),
+ /* 10 */ V(1, 3, 1),
+ /* 11 */ V(1, 3, 1),
+
+ /* 0011 ... */
+ /* 00 */ V(3, 1, 1), /* 44 */
+ /* 01 */ V(3, 1, 1),
+ /* 10 */ V(0, 3, 2),
+ /* 11 */ V(3, 0, 2),
+
+ /* 0100 ... */
+ /* 0 */ V(2, 2, 1), /* 48 */
+ /* 1 */ V(0, 2, 1),
+
+ /* 0000 0000 ... */
+ /* 0 */ V(5, 5, 1), /* 50 */
+ /* 1 */ V(4, 5, 1),
+
+ /* 0000 0011 ... */
+ /* 0 */ V(5, 4, 1), /* 52 */
+ /* 1 */ V(0, 5, 1)
+};
+
+static
+union huffpair const hufftab10[] = {
+ /* 0000 */ PTR(16, 4),
+ /* 0001 */ PTR(32, 4),
+ /* 0010 */ PTR(48, 2),
+ /* 0011 */ V(1, 1, 4),
+ /* 0100 */ V(0, 1, 3),
+ /* 0101 */ V(0, 1, 3),
+ /* 0110 */ V(1, 0, 3),
+ /* 0111 */ V(1, 0, 3),
+ /* 1000 */ V(0, 0, 1),
+ /* 1001 */ V(0, 0, 1),
+ /* 1010 */ V(0, 0, 1),
+ /* 1011 */ V(0, 0, 1),
+ /* 1100 */ V(0, 0, 1),
+ /* 1101 */ V(0, 0, 1),
+ /* 1110 */ V(0, 0, 1),
+ /* 1111 */ V(0, 0, 1),
+
+ /* 0000 ... */
+ /* 0000 */ PTR(52, 3), /* 16 */
+ /* 0001 */ PTR(60, 2),
+ /* 0010 */ PTR(64, 3),
+ /* 0011 */ PTR(72, 1),
+ /* 0100 */ PTR(74, 2),
+ /* 0101 */ PTR(78, 2),
+ /* 0110 */ PTR(82, 2),
+ /* 0111 */ V(1, 7, 4),
+ /* 1000 */ V(7, 1, 4),
+ /* 1001 */ PTR(86, 1),
+ /* 1010 */ PTR(88, 2),
+ /* 1011 */ PTR(92, 2),
+ /* 1100 */ V(1, 6, 4),
+ /* 1101 */ V(6, 1, 4),
+ /* 1110 */ V(6, 0, 4),
+ /* 1111 */ PTR(96, 1),
+
+ /* 0001 ... */
+ /* 0000 */ PTR(98, 1), /* 32 */
+ /* 0001 */ PTR(100, 1),
+ /* 0010 */ V(1, 4, 4),
+ /* 0011 */ V(4, 1, 4),
+ /* 0100 */ V(4, 0, 4),
+ /* 0101 */ V(2, 3, 4),
+ /* 0110 */ V(3, 2, 4),
+ /* 0111 */ V(0, 3, 4),
+ /* 1000 */ V(1, 3, 3),
+ /* 1001 */ V(1, 3, 3),
+ /* 1010 */ V(3, 1, 3),
+ /* 1011 */ V(3, 1, 3),
+ /* 1100 */ V(3, 0, 3),
+ /* 1101 */ V(3, 0, 3),
+ /* 1110 */ V(2, 2, 3),
+ /* 1111 */ V(2, 2, 3),
+
+ /* 0010 ... */
+ /* 00 */ V(1, 2, 2), /* 48 */
+ /* 01 */ V(2, 1, 2),
+ /* 10 */ V(0, 2, 2),
+ /* 11 */ V(2, 0, 2),
+
+ /* 0000 0000 ... */
+ /* 000 */ V(7, 7, 3), /* 52 */
+ /* 001 */ V(6, 7, 3),
+ /* 010 */ V(7, 6, 3),
+ /* 011 */ V(5, 7, 3),
+ /* 100 */ V(7, 5, 3),
+ /* 101 */ V(6, 6, 3),
+ /* 110 */ V(4, 7, 2),
+ /* 111 */ V(4, 7, 2),
+
+ /* 0000 0001 ... */
+ /* 00 */ V(7, 4, 2), /* 60 */
+ /* 01 */ V(5, 6, 2),
+ /* 10 */ V(6, 5, 2),
+ /* 11 */ V(3, 7, 2),
+
+ /* 0000 0010 ... */
+ /* 000 */ V(7, 3, 2), /* 64 */
+ /* 001 */ V(7, 3, 2),
+ /* 010 */ V(4, 6, 2),
+ /* 011 */ V(4, 6, 2),
+ /* 100 */ V(5, 5, 3),
+ /* 101 */ V(5, 4, 3),
+ /* 110 */ V(6, 3, 2),
+ /* 111 */ V(6, 3, 2),
+
+ /* 0000 0011 ... */
+ /* 0 */ V(2, 7, 1), /* 72 */
+ /* 1 */ V(7, 2, 1),
+
+ /* 0000 0100 ... */
+ /* 00 */ V(6, 4, 2), /* 74 */
+ /* 01 */ V(0, 7, 2),
+ /* 10 */ V(7, 0, 1),
+ /* 11 */ V(7, 0, 1),
+
+ /* 0000 0101 ... */
+ /* 00 */ V(6, 2, 1), /* 78 */
+ /* 01 */ V(6, 2, 1),
+ /* 10 */ V(4, 5, 2),
+ /* 11 */ V(3, 5, 2),
+
+ /* 0000 0110 ... */
+ /* 00 */ V(0, 6, 1), /* 82 */
+ /* 01 */ V(0, 6, 1),
+ /* 10 */ V(5, 3, 2),
+ /* 11 */ V(4, 4, 2),
+
+ /* 0000 1001 ... */
+ /* 0 */ V(3, 6, 1), /* 86 */
+ /* 1 */ V(2, 6, 1),
+
+ /* 0000 1010 ... */
+ /* 00 */ V(2, 5, 2), /* 88 */
+ /* 01 */ V(5, 2, 2),
+ /* 10 */ V(1, 5, 1),
+ /* 11 */ V(1, 5, 1),
+
+ /* 0000 1011 ... */
+ /* 00 */ V(5, 1, 1), /* 92 */
+ /* 01 */ V(5, 1, 1),
+ /* 10 */ V(3, 4, 2),
+ /* 11 */ V(4, 3, 2),
+
+ /* 0000 1111 ... */
+ /* 0 */ V(0, 5, 1), /* 96 */
+ /* 1 */ V(5, 0, 1),
+
+ /* 0001 0000 ... */
+ /* 0 */ V(2, 4, 1), /* 98 */
+ /* 1 */ V(4, 2, 1),
+
+ /* 0001 0001 ... */
+ /* 0 */ V(3, 3, 1), /* 100 */
+ /* 1 */ V(0, 4, 1)
+};
+
+static
+union huffpair const hufftab11[] = {
+ /* 0000 */ PTR(16, 4),
+ /* 0001 */ PTR(32, 4),
+ /* 0010 */ PTR(48, 4),
+ /* 0011 */ PTR(64, 3),
+ /* 0100 */ V(1, 2, 4),
+ /* 0101 */ PTR(72, 1),
+ /* 0110 */ V(1, 1, 3),
+ /* 0111 */ V(1, 1, 3),
+ /* 1000 */ V(0, 1, 3),
+ /* 1001 */ V(0, 1, 3),
+ /* 1010 */ V(1, 0, 3),
+ /* 1011 */ V(1, 0, 3),
+ /* 1100 */ V(0, 0, 2),
+ /* 1101 */ V(0, 0, 2),
+ /* 1110 */ V(0, 0, 2),
+ /* 1111 */ V(0, 0, 2),
+
+ /* 0000 ... */
+ /* 0000 */ PTR(74, 2), /* 16 */
+ /* 0001 */ PTR(78, 3),
+ /* 0010 */ PTR(86, 2),
+ /* 0011 */ PTR(90, 1),
+ /* 0100 */ PTR(92, 2),
+ /* 0101 */ V(2, 7, 4),
+ /* 0110 */ V(7, 2, 4),
+ /* 0111 */ PTR(96, 1),
+ /* 1000 */ V(7, 1, 3),
+ /* 1001 */ V(7, 1, 3),
+ /* 1010 */ V(1, 7, 4),
+ /* 1011 */ V(7, 0, 4),
+ /* 1100 */ V(3, 6, 4),
+ /* 1101 */ V(6, 3, 4),
+ /* 1110 */ V(6, 0, 4),
+ /* 1111 */ PTR(98, 1),
+
+ /* 0001 ... */
+ /* 0000 */ PTR(100, 1), /* 32 */
+ /* 0001 */ V(1, 5, 4),
+ /* 0010 */ V(6, 2, 3),
+ /* 0011 */ V(6, 2, 3),
+ /* 0100 */ V(2, 6, 4),
+ /* 0101 */ V(0, 6, 4),
+ /* 0110 */ V(1, 6, 3),
+ /* 0111 */ V(1, 6, 3),
+ /* 1000 */ V(6, 1, 3),
+ /* 1001 */ V(6, 1, 3),
+ /* 1010 */ V(5, 1, 4),
+ /* 1011 */ V(3, 4, 4),
+ /* 1100 */ V(5, 0, 4),
+ /* 1101 */ PTR(102, 1),
+ /* 1110 */ V(2, 4, 4),
+ /* 1111 */ V(4, 2, 4),
+
+ /* 0010 ... */
+ /* 0000 */ V(1, 4, 4), /* 48 */
+ /* 0001 */ V(4, 1, 4),
+ /* 0010 */ V(0, 4, 4),
+ /* 0011 */ V(4, 0, 4),
+ /* 0100 */ V(2, 3, 3),
+ /* 0101 */ V(2, 3, 3),
+ /* 0110 */ V(3, 2, 3),
+ /* 0111 */ V(3, 2, 3),
+ /* 1000 */ V(1, 3, 2),
+ /* 1001 */ V(1, 3, 2),
+ /* 1010 */ V(1, 3, 2),
+ /* 1011 */ V(1, 3, 2),
+ /* 1100 */ V(3, 1, 2),
+ /* 1101 */ V(3, 1, 2),
+ /* 1110 */ V(3, 1, 2),
+ /* 1111 */ V(3, 1, 2),
+
+ /* 0011 ... */
+ /* 000 */ V(0, 3, 3), /* 64 */
+ /* 001 */ V(3, 0, 3),
+ /* 010 */ V(2, 2, 2),
+ /* 011 */ V(2, 2, 2),
+ /* 100 */ V(2, 1, 1),
+ /* 101 */ V(2, 1, 1),
+ /* 110 */ V(2, 1, 1),
+ /* 111 */ V(2, 1, 1),
+
+ /* 0101 ... */
+ /* 0 */ V(0, 2, 1), /* 72 */
+ /* 1 */ V(2, 0, 1),
+
+ /* 0000 0000 ... */
+ /* 00 */ V(7, 7, 2), /* 74 */
+ /* 01 */ V(6, 7, 2),
+ /* 10 */ V(7, 6, 2),
+ /* 11 */ V(7, 5, 2),
+
+ /* 0000 0001 ... */
+ /* 000 */ V(6, 6, 2), /* 78 */
+ /* 001 */ V(6, 6, 2),
+ /* 010 */ V(4, 7, 2),
+ /* 011 */ V(4, 7, 2),
+ /* 100 */ V(7, 4, 2),
+ /* 101 */ V(7, 4, 2),
+ /* 110 */ V(5, 7, 3),
+ /* 111 */ V(5, 5, 3),
+
+ /* 0000 0010 ... */
+ /* 00 */ V(5, 6, 2), /* 86 */
+ /* 01 */ V(6, 5, 2),
+ /* 10 */ V(3, 7, 1),
+ /* 11 */ V(3, 7, 1),
+
+ /* 0000 0011 ... */
+ /* 0 */ V(7, 3, 1), /* 90 */
+ /* 1 */ V(4, 6, 1),
+
+ /* 0000 0100 ... */
+ /* 00 */ V(4, 5, 2), /* 92 */
+ /* 01 */ V(5, 4, 2),
+ /* 10 */ V(3, 5, 2),
+ /* 11 */ V(5, 3, 2),
+
+ /* 0000 0111 ... */
+ /* 0 */ V(6, 4, 1), /* 96 */
+ /* 1 */ V(0, 7, 1),
+
+ /* 0000 1111 ... */
+ /* 0 */ V(4, 4, 1), /* 98 */
+ /* 1 */ V(2, 5, 1),
+
+ /* 0001 0000 ... */
+ /* 0 */ V(5, 2, 1), /* 100 */
+ /* 1 */ V(0, 5, 1),
+
+ /* 0001 1101 ... */
+ /* 0 */ V(4, 3, 1), /* 102 */
+ /* 1 */ V(3, 3, 1)
+};
+
+static
+union huffpair const hufftab12[] = {
+ /* 0000 */ PTR(16, 4),
+ /* 0001 */ PTR(32, 4),
+ /* 0010 */ PTR(48, 4),
+ /* 0011 */ PTR(64, 2),
+ /* 0100 */ PTR(68, 3),
+ /* 0101 */ PTR(76, 1),
+ /* 0110 */ V(1, 2, 4),
+ /* 0111 */ V(2, 1, 4),
+ /* 1000 */ PTR(78, 1),
+ /* 1001 */ V(0, 0, 4),
+ /* 1010 */ V(1, 1, 3),
+ /* 1011 */ V(1, 1, 3),
+ /* 1100 */ V(0, 1, 3),
+ /* 1101 */ V(0, 1, 3),
+ /* 1110 */ V(1, 0, 3),
+ /* 1111 */ V(1, 0, 3),
+
+ /* 0000 ... */
+ /* 0000 */ PTR(80, 2), /* 16 */
+ /* 0001 */ PTR(84, 1),
+ /* 0010 */ PTR(86, 1),
+ /* 0011 */ PTR(88, 1),
+ /* 0100 */ V(5, 6, 4),
+ /* 0101 */ V(3, 7, 4),
+ /* 0110 */ PTR(90, 1),
+ /* 0111 */ V(2, 7, 4),
+ /* 1000 */ V(7, 2, 4),
+ /* 1001 */ V(4, 6, 4),
+ /* 1010 */ V(6, 4, 4),
+ /* 1011 */ V(1, 7, 4),
+ /* 1100 */ V(7, 1, 4),
+ /* 1101 */ PTR(92, 1),
+ /* 1110 */ V(3, 6, 4),
+ /* 1111 */ V(6, 3, 4),
+
+ /* 0001 ... */
+ /* 0000 */ V(4, 5, 4), /* 32 */
+ /* 0001 */ V(5, 4, 4),
+ /* 0010 */ V(4, 4, 4),
+ /* 0011 */ PTR(94, 1),
+ /* 0100 */ V(2, 6, 3),
+ /* 0101 */ V(2, 6, 3),
+ /* 0110 */ V(6, 2, 3),
+ /* 0111 */ V(6, 2, 3),
+ /* 1000 */ V(6, 1, 3),
+ /* 1001 */ V(6, 1, 3),
+ /* 1010 */ V(1, 6, 4),
+ /* 1011 */ V(6, 0, 4),
+ /* 1100 */ V(3, 5, 4),
+ /* 1101 */ V(5, 3, 4),
+ /* 1110 */ V(2, 5, 4),
+ /* 1111 */ V(5, 2, 4),
+
+ /* 0010 ... */
+ /* 0000 */ V(1, 5, 3), /* 48 */
+ /* 0001 */ V(1, 5, 3),
+ /* 0010 */ V(5, 1, 3),
+ /* 0011 */ V(5, 1, 3),
+ /* 0100 */ V(3, 4, 3),
+ /* 0101 */ V(3, 4, 3),
+ /* 0110 */ V(4, 3, 3),
+ /* 0111 */ V(4, 3, 3),
+ /* 1000 */ V(5, 0, 4),
+ /* 1001 */ V(0, 4, 4),
+ /* 1010 */ V(2, 4, 3),
+ /* 1011 */ V(2, 4, 3),
+ /* 1100 */ V(4, 2, 3),
+ /* 1101 */ V(4, 2, 3),
+ /* 1110 */ V(1, 4, 3),
+ /* 1111 */ V(1, 4, 3),
+
+ /* 0011 ... */
+ /* 00 */ V(3, 3, 2), /* 64 */
+ /* 01 */ V(4, 1, 2),
+ /* 10 */ V(2, 3, 2),
+ /* 11 */ V(3, 2, 2),
+
+ /* 0100 ... */
+ /* 000 */ V(4, 0, 3), /* 68 */
+ /* 001 */ V(0, 3, 3),
+ /* 010 */ V(3, 0, 2),
+ /* 011 */ V(3, 0, 2),
+ /* 100 */ V(1, 3, 1),
+ /* 101 */ V(1, 3, 1),
+ /* 110 */ V(1, 3, 1),
+ /* 111 */ V(1, 3, 1),
+
+ /* 0101 ... */
+ /* 0 */ V(3, 1, 1), /* 76 */
+ /* 1 */ V(2, 2, 1),
+
+ /* 1000 ... */
+ /* 0 */ V(0, 2, 1), /* 78 */
+ /* 1 */ V(2, 0, 1),
+
+ /* 0000 0000 ... */
+ /* 00 */ V(7, 7, 2), /* 80 */
+ /* 01 */ V(6, 7, 2),
+ /* 10 */ V(7, 6, 1),
+ /* 11 */ V(7, 6, 1),
+
+ /* 0000 0001 ... */
+ /* 0 */ V(5, 7, 1), /* 84 */
+ /* 1 */ V(7, 5, 1),
+
+ /* 0000 0010 ... */
+ /* 0 */ V(6, 6, 1), /* 86 */
+ /* 1 */ V(4, 7, 1),
+
+ /* 0000 0011 ... */
+ /* 0 */ V(7, 4, 1), /* 88 */
+ /* 1 */ V(6, 5, 1),
+
+ /* 0000 0110 ... */
+ /* 0 */ V(7, 3, 1), /* 90 */
+ /* 1 */ V(5, 5, 1),
+
+ /* 0000 1101 ... */
+ /* 0 */ V(0, 7, 1), /* 92 */
+ /* 1 */ V(7, 0, 1),
+
+ /* 0001 0011 ... */
+ /* 0 */ V(0, 6, 1), /* 94 */
+ /* 1 */ V(0, 5, 1)
+};
+
+static
+union huffpair const hufftab13[] = {
+ /* 0000 */ PTR(16, 4),
+ /* 0001 */ PTR(32, 4),
+ /* 0010 */ PTR(48, 4),
+ /* 0011 */ PTR(64, 2),
+ /* 0100 */ V(1, 1, 4),
+ /* 0101 */ V(0, 1, 4),
+ /* 0110 */ V(1, 0, 3),
+ /* 0111 */ V(1, 0, 3),
+ /* 1000 */ V(0, 0, 1),
+ /* 1001 */ V(0, 0, 1),
+ /* 1010 */ V(0, 0, 1),
+ /* 1011 */ V(0, 0, 1),
+ /* 1100 */ V(0, 0, 1),
+ /* 1101 */ V(0, 0, 1),
+ /* 1110 */ V(0, 0, 1),
+ /* 1111 */ V(0, 0, 1),
+
+ /* 0000 ... */
+ /* 0000 */ PTR(68, 4), /* 16 */
+ /* 0001 */ PTR(84, 4),
+ /* 0010 */ PTR(100, 4),
+ /* 0011 */ PTR(116, 4),
+ /* 0100 */ PTR(132, 4),
+ /* 0101 */ PTR(148, 4),
+ /* 0110 */ PTR(164, 3),
+ /* 0111 */ PTR(172, 3),
+ /* 1000 */ PTR(180, 3),
+ /* 1001 */ PTR(188, 3),
+ /* 1010 */ PTR(196, 3),
+ /* 1011 */ PTR(204, 3),
+ /* 1100 */ PTR(212, 1),
+ /* 1101 */ PTR(214, 2),
+ /* 1110 */ PTR(218, 3),
+ /* 1111 */ PTR(226, 1),
+
+ /* 0001 ... */
+ /* 0000 */ PTR(228, 2), /* 32 */
+ /* 0001 */ PTR(232, 2),
+ /* 0010 */ PTR(236, 2),
+ /* 0011 */ PTR(240, 2),
+ /* 0100 */ V(8, 1, 4),
+ /* 0101 */ PTR(244, 1),
+ /* 0110 */ PTR(246, 1),
+ /* 0111 */ PTR(248, 1),
+ /* 1000 */ PTR(250, 2),
+ /* 1001 */ PTR(254, 1),
+ /* 1010 */ V(1, 5, 4),
+ /* 1011 */ V(5, 1, 4),
+ /* 1100 */ PTR(256, 1),
+ /* 1101 */ PTR(258, 1),
+ /* 1110 */ PTR(260, 1),
+ /* 1111 */ V(1, 4, 4),
+
+ /* 0010 ... */
+ /* 0000 */ V(4, 1, 3), /* 48 */
+ /* 0001 */ V(4, 1, 3),
+ /* 0010 */ V(0, 4, 4),
+ /* 0011 */ V(4, 0, 4),
+ /* 0100 */ V(2, 3, 4),
+ /* 0101 */ V(3, 2, 4),
+ /* 0110 */ V(1, 3, 3),
+ /* 0111 */ V(1, 3, 3),
+ /* 1000 */ V(3, 1, 3),
+ /* 1001 */ V(3, 1, 3),
+ /* 1010 */ V(0, 3, 3),
+ /* 1011 */ V(0, 3, 3),
+ /* 1100 */ V(3, 0, 3),
+ /* 1101 */ V(3, 0, 3),
+ /* 1110 */ V(2, 2, 3),
+ /* 1111 */ V(2, 2, 3),
+
+ /* 0011 ... */
+ /* 00 */ V(1, 2, 2), /* 64 */
+ /* 01 */ V(2, 1, 2),
+ /* 10 */ V(0, 2, 2),
+ /* 11 */ V(2, 0, 2),
+
+ /* 0000 0000 ... */
+ /* 0000 */ PTR(262, 4), /* 68 */
+ /* 0001 */ PTR(278, 4),
+ /* 0010 */ PTR(294, 4),
+ /* 0011 */ PTR(310, 3),
+ /* 0100 */ PTR(318, 2),
+ /* 0101 */ PTR(322, 2),
+ /* 0110 */ PTR(326, 3),
+ /* 0111 */ PTR(334, 2),
+ /* 1000 */ PTR(338, 1),
+ /* 1001 */ PTR(340, 2),
+ /* 1010 */ PTR(344, 2),
+ /* 1011 */ PTR(348, 2),
+ /* 1100 */ PTR(352, 2),
+ /* 1101 */ PTR(356, 2),
+ /* 1110 */ V(1, 15, 4),
+ /* 1111 */ V(15, 1, 4),
+
+ /* 0000 0001 ... */
+ /* 0000 */ V(15, 0, 4), /* 84 */
+ /* 0001 */ PTR(360, 1),
+ /* 0010 */ PTR(362, 1),
+ /* 0011 */ PTR(364, 1),
+ /* 0100 */ V(14, 2, 4),
+ /* 0101 */ PTR(366, 1),
+ /* 0110 */ V(1, 14, 4),
+ /* 0111 */ V(14, 1, 4),
+ /* 1000 */ PTR(368, 1),
+ /* 1001 */ PTR(370, 1),
+ /* 1010 */ PTR(372, 1),
+ /* 1011 */ PTR(374, 1),
+ /* 1100 */ PTR(376, 1),
+ /* 1101 */ PTR(378, 1),
+ /* 1110 */ V(12, 6, 4),
+ /* 1111 */ V(3, 13, 4),
+
+ /* 0000 0010 ... */
+ /* 0000 */ PTR(380, 1), /* 100 */
+ /* 0001 */ V(2, 13, 4),
+ /* 0010 */ V(13, 2, 4),
+ /* 0011 */ V(1, 13, 4),
+ /* 0100 */ V(11, 7, 4),
+ /* 0101 */ PTR(382, 1),
+ /* 0110 */ PTR(384, 1),
+ /* 0111 */ V(12, 3, 4),
+ /* 1000 */ PTR(386, 1),
+ /* 1001 */ V(4, 11, 4),
+ /* 1010 */ V(13, 1, 3),
+ /* 1011 */ V(13, 1, 3),
+ /* 1100 */ V(0, 13, 4),
+ /* 1101 */ V(13, 0, 4),
+ /* 1110 */ V(8, 10, 4),
+ /* 1111 */ V(10, 8, 4),
+
+ /* 0000 0011 ... */
+ /* 0000 */ V(4, 12, 4), /* 116 */
+ /* 0001 */ V(12, 4, 4),
+ /* 0010 */ V(6, 11, 4),
+ /* 0011 */ V(11, 6, 4),
+ /* 0100 */ V(3, 12, 3),
+ /* 0101 */ V(3, 12, 3),
+ /* 0110 */ V(2, 12, 3),
+ /* 0111 */ V(2, 12, 3),
+ /* 1000 */ V(12, 2, 3),
+ /* 1001 */ V(12, 2, 3),
+ /* 1010 */ V(5, 11, 3),
+ /* 1011 */ V(5, 11, 3),
+ /* 1100 */ V(11, 5, 4),
+ /* 1101 */ V(8, 9, 4),
+ /* 1110 */ V(1, 12, 3),
+ /* 1111 */ V(1, 12, 3),
+
+ /* 0000 0100 ... */
+ /* 0000 */ V(12, 1, 3), /* 132 */
+ /* 0001 */ V(12, 1, 3),
+ /* 0010 */ V(9, 8, 4),
+ /* 0011 */ V(0, 12, 4),
+ /* 0100 */ V(12, 0, 3),
+ /* 0101 */ V(12, 0, 3),
+ /* 0110 */ V(11, 4, 4),
+ /* 0111 */ V(6, 10, 4),
+ /* 1000 */ V(10, 6, 4),
+ /* 1001 */ V(7, 9, 4),
+ /* 1010 */ V(3, 11, 3),
+ /* 1011 */ V(3, 11, 3),
+ /* 1100 */ V(11, 3, 3),
+ /* 1101 */ V(11, 3, 3),
+ /* 1110 */ V(8, 8, 4),
+ /* 1111 */ V(5, 10, 4),
+
+ /* 0000 0101 ... */
+ /* 0000 */ V(2, 11, 3), /* 148 */
+ /* 0001 */ V(2, 11, 3),
+ /* 0010 */ V(10, 5, 4),
+ /* 0011 */ V(6, 9, 4),
+ /* 0100 */ V(10, 4, 3),
+ /* 0101 */ V(10, 4, 3),
+ /* 0110 */ V(7, 8, 4),
+ /* 0111 */ V(8, 7, 4),
+ /* 1000 */ V(9, 4, 3),
+ /* 1001 */ V(9, 4, 3),
+ /* 1010 */ V(7, 7, 4),
+ /* 1011 */ V(7, 6, 4),
+ /* 1100 */ V(11, 2, 2),
+ /* 1101 */ V(11, 2, 2),
+ /* 1110 */ V(11, 2, 2),
+ /* 1111 */ V(11, 2, 2),
+
+ /* 0000 0110 ... */
+ /* 000 */ V(1, 11, 2), /* 164 */
+ /* 001 */ V(1, 11, 2),
+ /* 010 */ V(11, 1, 2),
+ /* 011 */ V(11, 1, 2),
+ /* 100 */ V(0, 11, 3),
+ /* 101 */ V(11, 0, 3),
+ /* 110 */ V(9, 6, 3),
+ /* 111 */ V(4, 10, 3),
+
+ /* 0000 0111 ... */
+ /* 000 */ V(3, 10, 3), /* 172 */
+ /* 001 */ V(10, 3, 3),
+ /* 010 */ V(5, 9, 3),
+ /* 011 */ V(9, 5, 3),
+ /* 100 */ V(2, 10, 2),
+ /* 101 */ V(2, 10, 2),
+ /* 110 */ V(10, 2, 2),
+ /* 111 */ V(10, 2, 2),
+
+ /* 0000 1000 ... */
+ /* 000 */ V(1, 10, 2), /* 180 */
+ /* 001 */ V(1, 10, 2),
+ /* 010 */ V(10, 1, 2),
+ /* 011 */ V(10, 1, 2),
+ /* 100 */ V(0, 10, 3),
+ /* 101 */ V(6, 8, 3),
+ /* 110 */ V(10, 0, 2),
+ /* 111 */ V(10, 0, 2),
+
+ /* 0000 1001 ... */
+ /* 000 */ V(8, 6, 3), /* 188 */
+ /* 001 */ V(4, 9, 3),
+ /* 010 */ V(9, 3, 2),
+ /* 011 */ V(9, 3, 2),
+ /* 100 */ V(3, 9, 3),
+ /* 101 */ V(5, 8, 3),
+ /* 110 */ V(8, 5, 3),
+ /* 111 */ V(6, 7, 3),
+
+ /* 0000 1010 ... */
+ /* 000 */ V(2, 9, 2), /* 196 */
+ /* 001 */ V(2, 9, 2),
+ /* 010 */ V(9, 2, 2),
+ /* 011 */ V(9, 2, 2),
+ /* 100 */ V(5, 7, 3),
+ /* 101 */ V(7, 5, 3),
+ /* 110 */ V(3, 8, 2),
+ /* 111 */ V(3, 8, 2),
+
+ /* 0000 1011 ... */
+ /* 000 */ V(8, 3, 2), /* 204 */
+ /* 001 */ V(8, 3, 2),
+ /* 010 */ V(6, 6, 3),
+ /* 011 */ V(4, 7, 3),
+ /* 100 */ V(7, 4, 3),
+ /* 101 */ V(5, 6, 3),
+ /* 110 */ V(6, 5, 3),
+ /* 111 */ V(7, 3, 3),
+
+ /* 0000 1100 ... */
+ /* 0 */ V(1, 9, 1), /* 212 */
+ /* 1 */ V(9, 1, 1),
+
+ /* 0000 1101 ... */
+ /* 00 */ V(0, 9, 2), /* 214 */
+ /* 01 */ V(9, 0, 2),
+ /* 10 */ V(4, 8, 2),
+ /* 11 */ V(8, 4, 2),
+
+ /* 0000 1110 ... */
+ /* 000 */ V(7, 2, 2), /* 218 */
+ /* 001 */ V(7, 2, 2),
+ /* 010 */ V(4, 6, 3),
+ /* 011 */ V(6, 4, 3),
+ /* 100 */ V(2, 8, 1),
+ /* 101 */ V(2, 8, 1),
+ /* 110 */ V(2, 8, 1),
+ /* 111 */ V(2, 8, 1),
+
+ /* 0000 1111 ... */
+ /* 0 */ V(8, 2, 1), /* 226 */
+ /* 1 */ V(1, 8, 1),
+
+ /* 0001 0000 ... */
+ /* 00 */ V(3, 7, 2), /* 228 */
+ /* 01 */ V(2, 7, 2),
+ /* 10 */ V(1, 7, 1),
+ /* 11 */ V(1, 7, 1),
+
+ /* 0001 0001 ... */
+ /* 00 */ V(7, 1, 1), /* 232 */
+ /* 01 */ V(7, 1, 1),
+ /* 10 */ V(5, 5, 2),
+ /* 11 */ V(0, 7, 2),
+
+ /* 0001 0010 ... */
+ /* 00 */ V(7, 0, 2), /* 236 */
+ /* 01 */ V(3, 6, 2),
+ /* 10 */ V(6, 3, 2),
+ /* 11 */ V(4, 5, 2),
+
+ /* 0001 0011 ... */
+ /* 00 */ V(5, 4, 2), /* 240 */
+ /* 01 */ V(2, 6, 2),
+ /* 10 */ V(6, 2, 2),
+ /* 11 */ V(3, 5, 2),
+
+ /* 0001 0101 ... */
+ /* 0 */ V(0, 8, 1), /* 244 */
+ /* 1 */ V(8, 0, 1),
+
+ /* 0001 0110 ... */
+ /* 0 */ V(1, 6, 1), /* 246 */
+ /* 1 */ V(6, 1, 1),
+
+ /* 0001 0111 ... */
+ /* 0 */ V(0, 6, 1), /* 248 */
+ /* 1 */ V(6, 0, 1),
+
+ /* 0001 1000 ... */
+ /* 00 */ V(5, 3, 2), /* 250 */
+ /* 01 */ V(4, 4, 2),
+ /* 10 */ V(2, 5, 1),
+ /* 11 */ V(2, 5, 1),
+
+ /* 0001 1001 ... */
+ /* 0 */ V(5, 2, 1), /* 254 */
+ /* 1 */ V(0, 5, 1),
+
+ /* 0001 1100 ... */
+ /* 0 */ V(3, 4, 1), /* 256 */
+ /* 1 */ V(4, 3, 1),
+
+ /* 0001 1101 ... */
+ /* 0 */ V(5, 0, 1), /* 258 */
+ /* 1 */ V(2, 4, 1),
+
+ /* 0001 1110 ... */
+ /* 0 */ V(4, 2, 1), /* 260 */
+ /* 1 */ V(3, 3, 1),
+
+ /* 0000 0000 0000 ... */
+ /* 0000 */ PTR(388, 3), /* 262 */
+ /* 0001 */ V(15, 15, 4),
+ /* 0010 */ V(14, 15, 4),
+ /* 0011 */ V(13, 15, 4),
+ /* 0100 */ V(14, 14, 4),
+ /* 0101 */ V(12, 15, 4),
+ /* 0110 */ V(13, 14, 4),
+ /* 0111 */ V(11, 15, 4),
+ /* 1000 */ V(15, 11, 4),
+ /* 1001 */ V(12, 14, 4),
+ /* 1010 */ V(13, 12, 4),
+ /* 1011 */ PTR(396, 1),
+ /* 1100 */ V(14, 12, 3),
+ /* 1101 */ V(14, 12, 3),
+ /* 1110 */ V(13, 13, 3),
+ /* 1111 */ V(13, 13, 3),
+
+ /* 0000 0000 0001 ... */
+ /* 0000 */ V(15, 10, 4), /* 278 */
+ /* 0001 */ V(12, 13, 4),
+ /* 0010 */ V(11, 14, 3),
+ /* 0011 */ V(11, 14, 3),
+ /* 0100 */ V(14, 11, 3),
+ /* 0101 */ V(14, 11, 3),
+ /* 0110 */ V(9, 15, 3),
+ /* 0111 */ V(9, 15, 3),
+ /* 1000 */ V(15, 9, 3),
+ /* 1001 */ V(15, 9, 3),
+ /* 1010 */ V(14, 10, 3),
+ /* 1011 */ V(14, 10, 3),
+ /* 1100 */ V(11, 13, 3),
+ /* 1101 */ V(11, 13, 3),
+ /* 1110 */ V(13, 11, 3),
+ /* 1111 */ V(13, 11, 3),
+
+ /* 0000 0000 0010 ... */
+ /* 0000 */ V(8, 15, 3), /* 294 */
+ /* 0001 */ V(8, 15, 3),
+ /* 0010 */ V(15, 8, 3),
+ /* 0011 */ V(15, 8, 3),
+ /* 0100 */ V(12, 12, 3),
+ /* 0101 */ V(12, 12, 3),
+ /* 0110 */ V(10, 14, 4),
+ /* 0111 */ V(9, 14, 4),
+ /* 1000 */ V(8, 14, 3),
+ /* 1001 */ V(8, 14, 3),
+ /* 1010 */ V(7, 15, 4),
+ /* 1011 */ V(7, 14, 4),
+ /* 1100 */ V(15, 7, 2),
+ /* 1101 */ V(15, 7, 2),
+ /* 1110 */ V(15, 7, 2),
+ /* 1111 */ V(15, 7, 2),
+
+ /* 0000 0000 0011 ... */
+ /* 000 */ V(13, 10, 2), /* 310 */
+ /* 001 */ V(13, 10, 2),
+ /* 010 */ V(10, 13, 3),
+ /* 011 */ V(11, 12, 3),
+ /* 100 */ V(12, 11, 3),
+ /* 101 */ V(15, 6, 3),
+ /* 110 */ V(6, 15, 2),
+ /* 111 */ V(6, 15, 2),
+
+ /* 0000 0000 0100 ... */
+ /* 00 */ V(14, 8, 2), /* 318 */
+ /* 01 */ V(5, 15, 2),
+ /* 10 */ V(9, 13, 2),
+ /* 11 */ V(13, 9, 2),
+
+ /* 0000 0000 0101 ... */
+ /* 00 */ V(15, 5, 2), /* 322 */
+ /* 01 */ V(14, 7, 2),
+ /* 10 */ V(10, 12, 2),
+ /* 11 */ V(11, 11, 2),
+
+ /* 0000 0000 0110 ... */
+ /* 000 */ V(4, 15, 2), /* 326 */
+ /* 001 */ V(4, 15, 2),
+ /* 010 */ V(15, 4, 2),
+ /* 011 */ V(15, 4, 2),
+ /* 100 */ V(12, 10, 3),
+ /* 101 */ V(14, 6, 3),
+ /* 110 */ V(15, 3, 2),
+ /* 111 */ V(15, 3, 2),
+
+ /* 0000 0000 0111 ... */
+ /* 00 */ V(3, 15, 1), /* 334 */
+ /* 01 */ V(3, 15, 1),
+ /* 10 */ V(8, 13, 2),
+ /* 11 */ V(13, 8, 2),
+
+ /* 0000 0000 1000 ... */
+ /* 0 */ V(2, 15, 1), /* 338 */
+ /* 1 */ V(15, 2, 1),
+
+ /* 0000 0000 1001 ... */
+ /* 00 */ V(6, 14, 2), /* 340 */
+ /* 01 */ V(9, 12, 2),
+ /* 10 */ V(0, 15, 1),
+ /* 11 */ V(0, 15, 1),
+
+ /* 0000 0000 1010 ... */
+ /* 00 */ V(12, 9, 2), /* 344 */
+ /* 01 */ V(5, 14, 2),
+ /* 10 */ V(10, 11, 1),
+ /* 11 */ V(10, 11, 1),
+
+ /* 0000 0000 1011 ... */
+ /* 00 */ V(7, 13, 2), /* 348 */
+ /* 01 */ V(13, 7, 2),
+ /* 10 */ V(4, 14, 1),
+ /* 11 */ V(4, 14, 1),
+
+ /* 0000 0000 1100 ... */
+ /* 00 */ V(12, 8, 2), /* 352 */
+ /* 01 */ V(13, 6, 2),
+ /* 10 */ V(3, 14, 1),
+ /* 11 */ V(3, 14, 1),
+
+ /* 0000 0000 1101 ... */
+ /* 00 */ V(11, 9, 1), /* 356 */
+ /* 01 */ V(11, 9, 1),
+ /* 10 */ V(9, 11, 2),
+ /* 11 */ V(10, 10, 2),
+
+ /* 0000 0001 0001 ... */
+ /* 0 */ V(11, 10, 1), /* 360 */
+ /* 1 */ V(14, 5, 1),
+
+ /* 0000 0001 0010 ... */
+ /* 0 */ V(14, 4, 1), /* 362 */
+ /* 1 */ V(8, 12, 1),
+
+ /* 0000 0001 0011 ... */
+ /* 0 */ V(6, 13, 1), /* 364 */
+ /* 1 */ V(14, 3, 1),
+
+ /* 0000 0001 0101 ... */
+ /* 0 */ V(2, 14, 1), /* 366 */
+ /* 1 */ V(0, 14, 1),
+
+ /* 0000 0001 1000 ... */
+ /* 0 */ V(14, 0, 1), /* 368 */
+ /* 1 */ V(5, 13, 1),
+
+ /* 0000 0001 1001 ... */
+ /* 0 */ V(13, 5, 1), /* 370 */
+ /* 1 */ V(7, 12, 1),
+
+ /* 0000 0001 1010 ... */
+ /* 0 */ V(12, 7, 1), /* 372 */
+ /* 1 */ V(4, 13, 1),
+
+ /* 0000 0001 1011 ... */
+ /* 0 */ V(8, 11, 1), /* 374 */
+ /* 1 */ V(11, 8, 1),
+
+ /* 0000 0001 1100 ... */
+ /* 0 */ V(13, 4, 1), /* 376 */
+ /* 1 */ V(9, 10, 1),
+
+ /* 0000 0001 1101 ... */
+ /* 0 */ V(10, 9, 1), /* 378 */
+ /* 1 */ V(6, 12, 1),
+
+ /* 0000 0010 0000 ... */
+ /* 0 */ V(13, 3, 1), /* 380 */
+ /* 1 */ V(7, 11, 1),
+
+ /* 0000 0010 0101 ... */
+ /* 0 */ V(5, 12, 1), /* 382 */
+ /* 1 */ V(12, 5, 1),
+
+ /* 0000 0010 0110 ... */
+ /* 0 */ V(9, 9, 1), /* 384 */
+ /* 1 */ V(7, 10, 1),
+
+ /* 0000 0010 1000 ... */
+ /* 0 */ V(10, 7, 1), /* 386 */
+ /* 1 */ V(9, 7, 1),
+
+ /* 0000 0000 0000 0000 ... */
+ /* 000 */ V(15, 14, 3), /* 388 */
+ /* 001 */ V(15, 12, 3),
+ /* 010 */ V(15, 13, 2),
+ /* 011 */ V(15, 13, 2),
+ /* 100 */ V(14, 13, 1),
+ /* 101 */ V(14, 13, 1),
+ /* 110 */ V(14, 13, 1),
+ /* 111 */ V(14, 13, 1),
+
+ /* 0000 0000 0000 1011 ... */
+ /* 0 */ V(10, 15, 1), /* 396 */
+ /* 1 */ V(14, 9, 1)
+};
+
+static
+union huffpair const hufftab15[] = {
+ /* 0000 */ PTR(16, 4),
+ /* 0001 */ PTR(32, 4),
+ /* 0010 */ PTR(48, 4),
+ /* 0011 */ PTR(64, 4),
+ /* 0100 */ PTR(80, 4),
+ /* 0101 */ PTR(96, 3),
+ /* 0110 */ PTR(104, 3),
+ /* 0111 */ PTR(112, 2),
+ /* 1000 */ PTR(116, 1),
+ /* 1001 */ PTR(118, 1),
+ /* 1010 */ V(1, 1, 3),
+ /* 1011 */ V(1, 1, 3),
+ /* 1100 */ V(0, 1, 4),
+ /* 1101 */ V(1, 0, 4),
+ /* 1110 */ V(0, 0, 3),
+ /* 1111 */ V(0, 0, 3),
+
+ /* 0000 ... */
+ /* 0000 */ PTR(120, 4), /* 16 */
+ /* 0001 */ PTR(136, 4),
+ /* 0010 */ PTR(152, 4),
+ /* 0011 */ PTR(168, 4),
+ /* 0100 */ PTR(184, 4),
+ /* 0101 */ PTR(200, 3),
+ /* 0110 */ PTR(208, 3),
+ /* 0111 */ PTR(216, 4),
+ /* 1000 */ PTR(232, 3),
+ /* 1001 */ PTR(240, 3),
+ /* 1010 */ PTR(248, 3),
+ /* 1011 */ PTR(256, 3),
+ /* 1100 */ PTR(264, 2),
+ /* 1101 */ PTR(268, 3),
+ /* 1110 */ PTR(276, 3),
+ /* 1111 */ PTR(284, 2),
+
+ /* 0001 ... */
+ /* 0000 */ PTR(288, 2), /* 32 */
+ /* 0001 */ PTR(292, 2),
+ /* 0010 */ PTR(296, 2),
+ /* 0011 */ PTR(300, 2),
+ /* 0100 */ PTR(304, 2),
+ /* 0101 */ PTR(308, 2),
+ /* 0110 */ PTR(312, 2),
+ /* 0111 */ PTR(316, 2),
+ /* 1000 */ PTR(320, 1),
+ /* 1001 */ PTR(322, 1),
+ /* 1010 */ PTR(324, 1),
+ /* 1011 */ PTR(326, 2),
+ /* 1100 */ PTR(330, 1),
+ /* 1101 */ PTR(332, 1),
+ /* 1110 */ PTR(334, 2),
+ /* 1111 */ PTR(338, 1),
+
+ /* 0010 ... */
+ /* 0000 */ PTR(340, 1), /* 48 */
+ /* 0001 */ PTR(342, 1),
+ /* 0010 */ V(9, 1, 4),
+ /* 0011 */ PTR(344, 1),
+ /* 0100 */ PTR(346, 1),
+ /* 0101 */ PTR(348, 1),
+ /* 0110 */ PTR(350, 1),
+ /* 0111 */ PTR(352, 1),
+ /* 1000 */ V(2, 8, 4),
+ /* 1001 */ V(8, 2, 4),
+ /* 1010 */ V(1, 8, 4),
+ /* 1011 */ V(8, 1, 4),
+ /* 1100 */ PTR(354, 1),
+ /* 1101 */ PTR(356, 1),
+ /* 1110 */ PTR(358, 1),
+ /* 1111 */ PTR(360, 1),
+
+ /* 0011 ... */
+ /* 0000 */ V(2, 7, 4), /* 64 */
+ /* 0001 */ V(7, 2, 4),
+ /* 0010 */ V(6, 4, 4),
+ /* 0011 */ V(1, 7, 4),
+ /* 0100 */ V(5, 5, 4),
+ /* 0101 */ V(7, 1, 4),
+ /* 0110 */ PTR(362, 1),
+ /* 0111 */ V(3, 6, 4),
+ /* 1000 */ V(6, 3, 4),
+ /* 1001 */ V(4, 5, 4),
+ /* 1010 */ V(5, 4, 4),
+ /* 1011 */ V(2, 6, 4),
+ /* 1100 */ V(6, 2, 4),
+ /* 1101 */ V(1, 6, 4),
+ /* 1110 */ PTR(364, 1),
+ /* 1111 */ V(3, 5, 4),
+
+ /* 0100 ... */
+ /* 0000 */ V(6, 1, 3), /* 80 */
+ /* 0001 */ V(6, 1, 3),
+ /* 0010 */ V(5, 3, 4),
+ /* 0011 */ V(4, 4, 4),
+ /* 0100 */ V(2, 5, 3),
+ /* 0101 */ V(2, 5, 3),
+ /* 0110 */ V(5, 2, 3),
+ /* 0111 */ V(5, 2, 3),
+ /* 1000 */ V(1, 5, 3),
+ /* 1001 */ V(1, 5, 3),
+ /* 1010 */ V(5, 1, 3),
+ /* 1011 */ V(5, 1, 3),
+ /* 1100 */ V(0, 5, 4),
+ /* 1101 */ V(5, 0, 4),
+ /* 1110 */ V(3, 4, 3),
+ /* 1111 */ V(3, 4, 3),
+
+ /* 0101 ... */
+ /* 000 */ V(4, 3, 3), /* 96 */
+ /* 001 */ V(2, 4, 3),
+ /* 010 */ V(4, 2, 3),
+ /* 011 */ V(3, 3, 3),
+ /* 100 */ V(4, 1, 2),
+ /* 101 */ V(4, 1, 2),
+ /* 110 */ V(1, 4, 3),
+ /* 111 */ V(0, 4, 3),
+
+ /* 0110 ... */
+ /* 000 */ V(2, 3, 2), /* 104 */
+ /* 001 */ V(2, 3, 2),
+ /* 010 */ V(3, 2, 2),
+ /* 011 */ V(3, 2, 2),
+ /* 100 */ V(4, 0, 3),
+ /* 101 */ V(0, 3, 3),
+ /* 110 */ V(1, 3, 2),
+ /* 111 */ V(1, 3, 2),
+
+ /* 0111 ... */
+ /* 00 */ V(3, 1, 2), /* 112 */
+ /* 01 */ V(3, 0, 2),
+ /* 10 */ V(2, 2, 1),
+ /* 11 */ V(2, 2, 1),
+
+ /* 1000 ... */
+ /* 0 */ V(1, 2, 1), /* 116 */
+ /* 1 */ V(2, 1, 1),
+
+ /* 1001 ... */
+ /* 0 */ V(0, 2, 1), /* 118 */
+ /* 1 */ V(2, 0, 1),
+
+ /* 0000 0000 ... */
+ /* 0000 */ PTR(366, 1), /* 120 */
+ /* 0001 */ PTR(368, 1),
+ /* 0010 */ V(14, 14, 4),
+ /* 0011 */ PTR(370, 1),
+ /* 0100 */ PTR(372, 1),
+ /* 0101 */ PTR(374, 1),
+ /* 0110 */ V(15, 11, 4),
+ /* 0111 */ PTR(376, 1),
+ /* 1000 */ V(13, 13, 4),
+ /* 1001 */ V(10, 15, 4),
+ /* 1010 */ V(15, 10, 4),
+ /* 1011 */ V(11, 14, 4),
+ /* 1100 */ V(14, 11, 4),
+ /* 1101 */ V(12, 13, 4),
+ /* 1110 */ V(13, 12, 4),
+ /* 1111 */ V(9, 15, 4),
+
+ /* 0000 0001 ... */
+ /* 0000 */ V(15, 9, 4), /* 136 */
+ /* 0001 */ V(14, 10, 4),
+ /* 0010 */ V(11, 13, 4),
+ /* 0011 */ V(13, 11, 4),
+ /* 0100 */ V(8, 15, 4),
+ /* 0101 */ V(15, 8, 4),
+ /* 0110 */ V(12, 12, 4),
+ /* 0111 */ V(9, 14, 4),
+ /* 1000 */ V(14, 9, 4),
+ /* 1001 */ V(7, 15, 4),
+ /* 1010 */ V(15, 7, 4),
+ /* 1011 */ V(10, 13, 4),
+ /* 1100 */ V(13, 10, 4),
+ /* 1101 */ V(11, 12, 4),
+ /* 1110 */ V(6, 15, 4),
+ /* 1111 */ PTR(378, 1),
+
+ /* 0000 0010 ... */
+ /* 0000 */ V(12, 11, 3), /* 152 */
+ /* 0001 */ V(12, 11, 3),
+ /* 0010 */ V(15, 6, 3),
+ /* 0011 */ V(15, 6, 3),
+ /* 0100 */ V(8, 14, 4),
+ /* 0101 */ V(14, 8, 4),
+ /* 0110 */ V(5, 15, 4),
+ /* 0111 */ V(9, 13, 4),
+ /* 1000 */ V(15, 5, 3),
+ /* 1001 */ V(15, 5, 3),
+ /* 1010 */ V(7, 14, 3),
+ /* 1011 */ V(7, 14, 3),
+ /* 1100 */ V(14, 7, 3),
+ /* 1101 */ V(14, 7, 3),
+ /* 1110 */ V(10, 12, 3),
+ /* 1111 */ V(10, 12, 3),
+
+ /* 0000 0011 ... */
+ /* 0000 */ V(12, 10, 3), /* 168 */
+ /* 0001 */ V(12, 10, 3),
+ /* 0010 */ V(11, 11, 3),
+ /* 0011 */ V(11, 11, 3),
+ /* 0100 */ V(13, 9, 4),
+ /* 0101 */ V(8, 13, 4),
+ /* 0110 */ V(4, 15, 3),
+ /* 0111 */ V(4, 15, 3),
+ /* 1000 */ V(15, 4, 3),
+ /* 1001 */ V(15, 4, 3),
+ /* 1010 */ V(3, 15, 3),
+ /* 1011 */ V(3, 15, 3),
+ /* 1100 */ V(15, 3, 3),
+ /* 1101 */ V(15, 3, 3),
+ /* 1110 */ V(13, 8, 3),
+ /* 1111 */ V(13, 8, 3),
+
+ /* 0000 0100 ... */
+ /* 0000 */ V(14, 6, 3), /* 184 */
+ /* 0001 */ V(14, 6, 3),
+ /* 0010 */ V(2, 15, 3),
+ /* 0011 */ V(2, 15, 3),
+ /* 0100 */ V(15, 2, 3),
+ /* 0101 */ V(15, 2, 3),
+ /* 0110 */ V(6, 14, 4),
+ /* 0111 */ V(15, 0, 4),
+ /* 1000 */ V(1, 15, 3),
+ /* 1001 */ V(1, 15, 3),
+ /* 1010 */ V(15, 1, 3),
+ /* 1011 */ V(15, 1, 3),
+ /* 1100 */ V(9, 12, 3),
+ /* 1101 */ V(9, 12, 3),
+ /* 1110 */ V(12, 9, 3),
+ /* 1111 */ V(12, 9, 3),
+
+ /* 0000 0101 ... */
+ /* 000 */ V(5, 14, 3), /* 200 */
+ /* 001 */ V(10, 11, 3),
+ /* 010 */ V(11, 10, 3),
+ /* 011 */ V(14, 5, 3),
+ /* 100 */ V(7, 13, 3),
+ /* 101 */ V(13, 7, 3),
+ /* 110 */ V(4, 14, 3),
+ /* 111 */ V(14, 4, 3),
+
+ /* 0000 0110 ... */
+ /* 000 */ V(8, 12, 3), /* 208 */
+ /* 001 */ V(12, 8, 3),
+ /* 010 */ V(3, 14, 3),
+ /* 011 */ V(6, 13, 3),
+ /* 100 */ V(13, 6, 3),
+ /* 101 */ V(14, 3, 3),
+ /* 110 */ V(9, 11, 3),
+ /* 111 */ V(11, 9, 3),
+
+ /* 0000 0111 ... */
+ /* 0000 */ V(2, 14, 3), /* 216 */
+ /* 0001 */ V(2, 14, 3),
+ /* 0010 */ V(10, 10, 3),
+ /* 0011 */ V(10, 10, 3),
+ /* 0100 */ V(14, 2, 3),
+ /* 0101 */ V(14, 2, 3),
+ /* 0110 */ V(1, 14, 3),
+ /* 0111 */ V(1, 14, 3),
+ /* 1000 */ V(14, 1, 3),
+ /* 1001 */ V(14, 1, 3),
+ /* 1010 */ V(0, 14, 4),
+ /* 1011 */ V(14, 0, 4),
+ /* 1100 */ V(5, 13, 3),
+ /* 1101 */ V(5, 13, 3),
+ /* 1110 */ V(13, 5, 3),
+ /* 1111 */ V(13, 5, 3),
+
+ /* 0000 1000 ... */
+ /* 000 */ V(7, 12, 3), /* 232 */
+ /* 001 */ V(12, 7, 3),
+ /* 010 */ V(4, 13, 3),
+ /* 011 */ V(8, 11, 3),
+ /* 100 */ V(13, 4, 2),
+ /* 101 */ V(13, 4, 2),
+ /* 110 */ V(11, 8, 3),
+ /* 111 */ V(9, 10, 3),
+
+ /* 0000 1001 ... */
+ /* 000 */ V(10, 9, 3), /* 240 */
+ /* 001 */ V(6, 12, 3),
+ /* 010 */ V(12, 6, 3),
+ /* 011 */ V(3, 13, 3),
+ /* 100 */ V(13, 3, 2),
+ /* 101 */ V(13, 3, 2),
+ /* 110 */ V(13, 2, 2),
+ /* 111 */ V(13, 2, 2),
+
+ /* 0000 1010 ... */
+ /* 000 */ V(2, 13, 3), /* 248 */
+ /* 001 */ V(0, 13, 3),
+ /* 010 */ V(1, 13, 2),
+ /* 011 */ V(1, 13, 2),
+ /* 100 */ V(7, 11, 2),
+ /* 101 */ V(7, 11, 2),
+ /* 110 */ V(11, 7, 2),
+ /* 111 */ V(11, 7, 2),
+
+ /* 0000 1011 ... */
+ /* 000 */ V(13, 1, 2), /* 256 */
+ /* 001 */ V(13, 1, 2),
+ /* 010 */ V(5, 12, 3),
+ /* 011 */ V(13, 0, 3),
+ /* 100 */ V(12, 5, 2),
+ /* 101 */ V(12, 5, 2),
+ /* 110 */ V(8, 10, 2),
+ /* 111 */ V(8, 10, 2),
+
+ /* 0000 1100 ... */
+ /* 00 */ V(10, 8, 2), /* 264 */
+ /* 01 */ V(4, 12, 2),
+ /* 10 */ V(12, 4, 2),
+ /* 11 */ V(6, 11, 2),
+
+ /* 0000 1101 ... */
+ /* 000 */ V(11, 6, 2), /* 268 */
+ /* 001 */ V(11, 6, 2),
+ /* 010 */ V(9, 9, 3),
+ /* 011 */ V(0, 12, 3),
+ /* 100 */ V(3, 12, 2),
+ /* 101 */ V(3, 12, 2),
+ /* 110 */ V(12, 3, 2),
+ /* 111 */ V(12, 3, 2),
+
+ /* 0000 1110 ... */
+ /* 000 */ V(7, 10, 2), /* 276 */
+ /* 001 */ V(7, 10, 2),
+ /* 010 */ V(10, 7, 2),
+ /* 011 */ V(10, 7, 2),
+ /* 100 */ V(10, 6, 2),
+ /* 101 */ V(10, 6, 2),
+ /* 110 */ V(12, 0, 3),
+ /* 111 */ V(0, 11, 3),
+
+ /* 0000 1111 ... */
+ /* 00 */ V(12, 2, 1), /* 284 */
+ /* 01 */ V(12, 2, 1),
+ /* 10 */ V(2, 12, 2),
+ /* 11 */ V(5, 11, 2),
+
+ /* 0001 0000 ... */
+ /* 00 */ V(11, 5, 2), /* 288 */
+ /* 01 */ V(1, 12, 2),
+ /* 10 */ V(8, 9, 2),
+ /* 11 */ V(9, 8, 2),
+
+ /* 0001 0001 ... */
+ /* 00 */ V(12, 1, 2), /* 292 */
+ /* 01 */ V(4, 11, 2),
+ /* 10 */ V(11, 4, 2),
+ /* 11 */ V(6, 10, 2),
+
+ /* 0001 0010 ... */
+ /* 00 */ V(3, 11, 2), /* 296 */
+ /* 01 */ V(7, 9, 2),
+ /* 10 */ V(11, 3, 1),
+ /* 11 */ V(11, 3, 1),
+
+ /* 0001 0011 ... */
+ /* 00 */ V(9, 7, 2), /* 300 */
+ /* 01 */ V(8, 8, 2),
+ /* 10 */ V(2, 11, 2),
+ /* 11 */ V(5, 10, 2),
+
+ /* 0001 0100 ... */
+ /* 00 */ V(11, 2, 1), /* 304 */
+ /* 01 */ V(11, 2, 1),
+ /* 10 */ V(10, 5, 2),
+ /* 11 */ V(1, 11, 2),
+
+ /* 0001 0101 ... */
+ /* 00 */ V(11, 1, 1), /* 308 */
+ /* 01 */ V(11, 1, 1),
+ /* 10 */ V(11, 0, 2),
+ /* 11 */ V(6, 9, 2),
+
+ /* 0001 0110 ... */
+ /* 00 */ V(9, 6, 2), /* 312 */
+ /* 01 */ V(4, 10, 2),
+ /* 10 */ V(10, 4, 2),
+ /* 11 */ V(7, 8, 2),
+
+ /* 0001 0111 ... */
+ /* 00 */ V(8, 7, 2), /* 316 */
+ /* 01 */ V(3, 10, 2),
+ /* 10 */ V(10, 3, 1),
+ /* 11 */ V(10, 3, 1),
+
+ /* 0001 1000 ... */
+ /* 0 */ V(5, 9, 1), /* 320 */
+ /* 1 */ V(9, 5, 1),
+
+ /* 0001 1001 ... */
+ /* 0 */ V(2, 10, 1), /* 322 */
+ /* 1 */ V(10, 2, 1),
+
+ /* 0001 1010 ... */
+ /* 0 */ V(1, 10, 1), /* 324 */
+ /* 1 */ V(10, 1, 1),
+
+ /* 0001 1011 ... */
+ /* 00 */ V(0, 10, 2), /* 326 */
+ /* 01 */ V(10, 0, 2),
+ /* 10 */ V(6, 8, 1),
+ /* 11 */ V(6, 8, 1),
+
+ /* 0001 1100 ... */
+ /* 0 */ V(8, 6, 1), /* 330 */
+ /* 1 */ V(4, 9, 1),
+
+ /* 0001 1101 ... */
+ /* 0 */ V(9, 4, 1), /* 332 */
+ /* 1 */ V(3, 9, 1),
+
+ /* 0001 1110 ... */
+ /* 00 */ V(9, 3, 1), /* 334 */
+ /* 01 */ V(9, 3, 1),
+ /* 10 */ V(7, 7, 2),
+ /* 11 */ V(0, 9, 2),
+
+ /* 0001 1111 ... */
+ /* 0 */ V(5, 8, 1), /* 338 */
+ /* 1 */ V(8, 5, 1),
+
+ /* 0010 0000 ... */
+ /* 0 */ V(2, 9, 1), /* 340 */
+ /* 1 */ V(6, 7, 1),
+
+ /* 0010 0001 ... */
+ /* 0 */ V(7, 6, 1), /* 342 */
+ /* 1 */ V(9, 2, 1),
+
+ /* 0010 0011 ... */
+ /* 0 */ V(1, 9, 1), /* 344 */
+ /* 1 */ V(9, 0, 1),
+
+ /* 0010 0100 ... */
+ /* 0 */ V(4, 8, 1), /* 346 */
+ /* 1 */ V(8, 4, 1),
+
+ /* 0010 0101 ... */
+ /* 0 */ V(5, 7, 1), /* 348 */
+ /* 1 */ V(7, 5, 1),
+
+ /* 0010 0110 ... */
+ /* 0 */ V(3, 8, 1), /* 350 */
+ /* 1 */ V(8, 3, 1),
+
+ /* 0010 0111 ... */
+ /* 0 */ V(6, 6, 1), /* 352 */
+ /* 1 */ V(4, 7, 1),
+
+ /* 0010 1100 ... */
+ /* 0 */ V(7, 4, 1), /* 354 */
+ /* 1 */ V(0, 8, 1),
+
+ /* 0010 1101 ... */
+ /* 0 */ V(8, 0, 1), /* 356 */
+ /* 1 */ V(5, 6, 1),
+
+ /* 0010 1110 ... */
+ /* 0 */ V(6, 5, 1), /* 358 */
+ /* 1 */ V(3, 7, 1),
+
+ /* 0010 1111 ... */
+ /* 0 */ V(7, 3, 1), /* 360 */
+ /* 1 */ V(4, 6, 1),
+
+ /* 0011 0110 ... */
+ /* 0 */ V(0, 7, 1), /* 362 */
+ /* 1 */ V(7, 0, 1),
+
+ /* 0011 1110 ... */
+ /* 0 */ V(0, 6, 1), /* 364 */
+ /* 1 */ V(6, 0, 1),
+
+ /* 0000 0000 0000 ... */
+ /* 0 */ V(15, 15, 1), /* 366 */
+ /* 1 */ V(14, 15, 1),
+
+ /* 0000 0000 0001 ... */
+ /* 0 */ V(15, 14, 1), /* 368 */
+ /* 1 */ V(13, 15, 1),
+
+ /* 0000 0000 0011 ... */
+ /* 0 */ V(15, 13, 1), /* 370 */
+ /* 1 */ V(12, 15, 1),
+
+ /* 0000 0000 0100 ... */
+ /* 0 */ V(15, 12, 1), /* 372 */
+ /* 1 */ V(13, 14, 1),
+
+ /* 0000 0000 0101 ... */
+ /* 0 */ V(14, 13, 1), /* 374 */
+ /* 1 */ V(11, 15, 1),
+
+ /* 0000 0000 0111 ... */
+ /* 0 */ V(12, 14, 1), /* 376 */
+ /* 1 */ V(14, 12, 1),
+
+ /* 0000 0001 1111 ... */
+ /* 0 */ V(10, 14, 1), /* 378 */
+ /* 1 */ V(0, 15, 1)
+};
+
+static
+union huffpair const hufftab16[] = {
+ /* 0000 */ PTR(16, 4),
+ /* 0001 */ PTR(32, 4),
+ /* 0010 */ PTR(48, 4),
+ /* 0011 */ PTR(64, 2),
+ /* 0100 */ V(1, 1, 4),
+ /* 0101 */ V(0, 1, 4),
+ /* 0110 */ V(1, 0, 3),
+ /* 0111 */ V(1, 0, 3),
+ /* 1000 */ V(0, 0, 1),
+ /* 1001 */ V(0, 0, 1),
+ /* 1010 */ V(0, 0, 1),
+ /* 1011 */ V(0, 0, 1),
+ /* 1100 */ V(0, 0, 1),
+ /* 1101 */ V(0, 0, 1),
+ /* 1110 */ V(0, 0, 1),
+ /* 1111 */ V(0, 0, 1),
+
+ /* 0000 ... */
+ /* 0000 */ PTR(68, 3), /* 16 */
+ /* 0001 */ PTR(76, 3),
+ /* 0010 */ PTR(84, 2),
+ /* 0011 */ V(15, 15, 4),
+ /* 0100 */ PTR(88, 2),
+ /* 0101 */ PTR(92, 1),
+ /* 0110 */ PTR(94, 4),
+ /* 0111 */ V(15, 2, 4),
+ /* 1000 */ PTR(110, 1),
+ /* 1001 */ V(1, 15, 4),
+ /* 1010 */ V(15, 1, 4),
+ /* 1011 */ PTR(112, 4),
+ /* 1100 */ PTR(128, 4),
+ /* 1101 */ PTR(144, 4),
+ /* 1110 */ PTR(160, 4),
+ /* 1111 */ PTR(176, 4),
+
+ /* 0001 ... */
+ /* 0000 */ PTR(192, 4), /* 32 */
+ /* 0001 */ PTR(208, 3),
+ /* 0010 */ PTR(216, 3),
+ /* 0011 */ PTR(224, 3),
+ /* 0100 */ PTR(232, 3),
+ /* 0101 */ PTR(240, 3),
+ /* 0110 */ PTR(248, 3),
+ /* 0111 */ PTR(256, 3),
+ /* 1000 */ PTR(264, 2),
+ /* 1001 */ PTR(268, 2),
+ /* 1010 */ PTR(272, 1),
+ /* 1011 */ PTR(274, 2),
+ /* 1100 */ PTR(278, 2),
+ /* 1101 */ PTR(282, 1),
+ /* 1110 */ V(5, 1, 4),
+ /* 1111 */ PTR(284, 1),
+
+ /* 0010 ... */
+ /* 0000 */ PTR(286, 1), /* 48 */
+ /* 0001 */ PTR(288, 1),
+ /* 0010 */ PTR(290, 1),
+ /* 0011 */ V(1, 4, 4),
+ /* 0100 */ V(4, 1, 4),
+ /* 0101 */ PTR(292, 1),
+ /* 0110 */ V(2, 3, 4),
+ /* 0111 */ V(3, 2, 4),
+ /* 1000 */ V(1, 3, 3),
+ /* 1001 */ V(1, 3, 3),
+ /* 1010 */ V(3, 1, 3),
+ /* 1011 */ V(3, 1, 3),
+ /* 1100 */ V(0, 3, 4),
+ /* 1101 */ V(3, 0, 4),
+ /* 1110 */ V(2, 2, 3),
+ /* 1111 */ V(2, 2, 3),
+
+ /* 0011 ... */
+ /* 00 */ V(1, 2, 2), /* 64 */
+ /* 01 */ V(2, 1, 2),
+ /* 10 */ V(0, 2, 2),
+ /* 11 */ V(2, 0, 2),
+
+ /* 0000 0000 ... */
+ /* 000 */ V(14, 15, 3), /* 68 */
+ /* 001 */ V(15, 14, 3),
+ /* 010 */ V(13, 15, 3),
+ /* 011 */ V(15, 13, 3),
+ /* 100 */ V(12, 15, 3),
+ /* 101 */ V(15, 12, 3),
+ /* 110 */ V(11, 15, 3),
+ /* 111 */ V(15, 11, 3),
+
+ /* 0000 0001 ... */
+ /* 000 */ V(10, 15, 2), /* 76 */
+ /* 001 */ V(10, 15, 2),
+ /* 010 */ V(15, 10, 3),
+ /* 011 */ V(9, 15, 3),
+ /* 100 */ V(15, 9, 3),
+ /* 101 */ V(15, 8, 3),
+ /* 110 */ V(8, 15, 2),
+ /* 111 */ V(8, 15, 2),
+
+ /* 0000 0010 ... */
+ /* 00 */ V(7, 15, 2), /* 84 */
+ /* 01 */ V(15, 7, 2),
+ /* 10 */ V(6, 15, 2),
+ /* 11 */ V(15, 6, 2),
+
+ /* 0000 0100 ... */
+ /* 00 */ V(5, 15, 2), /* 88 */
+ /* 01 */ V(15, 5, 2),
+ /* 10 */ V(4, 15, 1),
+ /* 11 */ V(4, 15, 1),
+
+ /* 0000 0101 ... */
+ /* 0 */ V(15, 4, 1), /* 92 */
+ /* 1 */ V(15, 3, 1),
+
+ /* 0000 0110 ... */
+ /* 0000 */ V(15, 0, 1), /* 94 */
+ /* 0001 */ V(15, 0, 1),
+ /* 0010 */ V(15, 0, 1),
+ /* 0011 */ V(15, 0, 1),
+ /* 0100 */ V(15, 0, 1),
+ /* 0101 */ V(15, 0, 1),
+ /* 0110 */ V(15, 0, 1),
+ /* 0111 */ V(15, 0, 1),
+ /* 1000 */ V(3, 15, 2),
+ /* 1001 */ V(3, 15, 2),
+ /* 1010 */ V(3, 15, 2),
+ /* 1011 */ V(3, 15, 2),
+ /* 1100 */ PTR(294, 4),
+ /* 1101 */ PTR(310, 3),
+ /* 1110 */ PTR(318, 3),
+ /* 1111 */ PTR(326, 3),
+
+ /* 0000 1000 ... */
+ /* 0 */ V(2, 15, 1), /* 110 */
+ /* 1 */ V(0, 15, 1),
+
+ /* 0000 1011 ... */
+ /* 0000 */ PTR(334, 2), /* 112 */
+ /* 0001 */ PTR(338, 2),
+ /* 0010 */ PTR(342, 2),
+ /* 0011 */ PTR(346, 1),
+ /* 0100 */ PTR(348, 2),
+ /* 0101 */ PTR(352, 2),
+ /* 0110 */ PTR(356, 1),
+ /* 0111 */ PTR(358, 2),
+ /* 1000 */ PTR(362, 2),
+ /* 1001 */ PTR(366, 2),
+ /* 1010 */ PTR(370, 2),
+ /* 1011 */ V(14, 3, 4),
+ /* 1100 */ PTR(374, 1),
+ /* 1101 */ PTR(376, 1),
+ /* 1110 */ PTR(378, 1),
+ /* 1111 */ PTR(380, 1),
+
+ /* 0000 1100 ... */
+ /* 0000 */ PTR(382, 1), /* 128 */
+ /* 0001 */ PTR(384, 1),
+ /* 0010 */ PTR(386, 1),
+ /* 0011 */ V(0, 13, 4),
+ /* 0100 */ PTR(388, 1),
+ /* 0101 */ PTR(390, 1),
+ /* 0110 */ PTR(392, 1),
+ /* 0111 */ V(3, 12, 4),
+ /* 1000 */ PTR(394, 1),
+ /* 1001 */ V(1, 12, 4),
+ /* 1010 */ V(12, 0, 4),
+ /* 1011 */ PTR(396, 1),
+ /* 1100 */ V(14, 2, 3),
+ /* 1101 */ V(14, 2, 3),
+ /* 1110 */ V(2, 14, 4),
+ /* 1111 */ V(1, 14, 4),
+
+ /* 0000 1101 ... */
+ /* 0000 */ V(13, 3, 4), /* 144 */
+ /* 0001 */ V(2, 13, 4),
+ /* 0010 */ V(13, 2, 4),
+ /* 0011 */ V(13, 1, 4),
+ /* 0100 */ V(3, 11, 4),
+ /* 0101 */ PTR(398, 1),
+ /* 0110 */ V(1, 13, 3),
+ /* 0111 */ V(1, 13, 3),
+ /* 1000 */ V(12, 4, 4),
+ /* 1001 */ V(6, 11, 4),
+ /* 1010 */ V(12, 3, 4),
+ /* 1011 */ V(10, 7, 4),
+ /* 1100 */ V(2, 12, 3),
+ /* 1101 */ V(2, 12, 3),
+ /* 1110 */ V(12, 2, 4),
+ /* 1111 */ V(11, 5, 4),
+
+ /* 0000 1110 ... */
+ /* 0000 */ V(12, 1, 4), /* 160 */
+ /* 0001 */ V(0, 12, 4),
+ /* 0010 */ V(4, 11, 4),
+ /* 0011 */ V(11, 4, 4),
+ /* 0100 */ V(6, 10, 4),
+ /* 0101 */ V(10, 6, 4),
+ /* 0110 */ V(11, 3, 3),
+ /* 0111 */ V(11, 3, 3),
+ /* 1000 */ V(5, 10, 4),
+ /* 1001 */ V(10, 5, 4),
+ /* 1010 */ V(2, 11, 3),
+ /* 1011 */ V(2, 11, 3),
+ /* 1100 */ V(11, 2, 3),
+ /* 1101 */ V(11, 2, 3),
+ /* 1110 */ V(1, 11, 3),
+ /* 1111 */ V(1, 11, 3),
+
+ /* 0000 1111 ... */
+ /* 0000 */ V(11, 1, 3), /* 176 */
+ /* 0001 */ V(11, 1, 3),
+ /* 0010 */ V(0, 11, 4),
+ /* 0011 */ V(11, 0, 4),
+ /* 0100 */ V(6, 9, 4),
+ /* 0101 */ V(9, 6, 4),
+ /* 0110 */ V(4, 10, 4),
+ /* 0111 */ V(10, 4, 4),
+ /* 1000 */ V(7, 8, 4),
+ /* 1001 */ V(8, 7, 4),
+ /* 1010 */ V(10, 3, 3),
+ /* 1011 */ V(10, 3, 3),
+ /* 1100 */ V(3, 10, 4),
+ /* 1101 */ V(5, 9, 4),
+ /* 1110 */ V(2, 10, 3),
+ /* 1111 */ V(2, 10, 3),
+
+ /* 0001 0000 ... */
+ /* 0000 */ V(9, 5, 4), /* 192 */
+ /* 0001 */ V(6, 8, 4),
+ /* 0010 */ V(10, 1, 3),
+ /* 0011 */ V(10, 1, 3),
+ /* 0100 */ V(8, 6, 4),
+ /* 0101 */ V(7, 7, 4),
+ /* 0110 */ V(9, 4, 3),
+ /* 0111 */ V(9, 4, 3),
+ /* 1000 */ V(4, 9, 4),
+ /* 1001 */ V(5, 7, 4),
+ /* 1010 */ V(6, 7, 3),
+ /* 1011 */ V(6, 7, 3),
+ /* 1100 */ V(10, 2, 2),
+ /* 1101 */ V(10, 2, 2),
+ /* 1110 */ V(10, 2, 2),
+ /* 1111 */ V(10, 2, 2),
+
+ /* 0001 0001 ... */
+ /* 000 */ V(1, 10, 2), /* 208 */
+ /* 001 */ V(1, 10, 2),
+ /* 010 */ V(0, 10, 3),
+ /* 011 */ V(10, 0, 3),
+ /* 100 */ V(3, 9, 3),
+ /* 101 */ V(9, 3, 3),
+ /* 110 */ V(5, 8, 3),
+ /* 111 */ V(8, 5, 3),
+
+ /* 0001 0010 ... */
+ /* 000 */ V(2, 9, 2), /* 216 */
+ /* 001 */ V(2, 9, 2),
+ /* 010 */ V(9, 2, 2),
+ /* 011 */ V(9, 2, 2),
+ /* 100 */ V(7, 6, 3),
+ /* 101 */ V(0, 9, 3),
+ /* 110 */ V(1, 9, 2),
+ /* 111 */ V(1, 9, 2),
+
+ /* 0001 0011 ... */
+ /* 000 */ V(9, 1, 2), /* 224 */
+ /* 001 */ V(9, 1, 2),
+ /* 010 */ V(9, 0, 3),
+ /* 011 */ V(4, 8, 3),
+ /* 100 */ V(8, 4, 3),
+ /* 101 */ V(7, 5, 3),
+ /* 110 */ V(3, 8, 3),
+ /* 111 */ V(8, 3, 3),
+
+ /* 0001 0100 ... */
+ /* 000 */ V(6, 6, 3), /* 232 */
+ /* 001 */ V(2, 8, 3),
+ /* 010 */ V(8, 2, 2),
+ /* 011 */ V(8, 2, 2),
+ /* 100 */ V(4, 7, 3),
+ /* 101 */ V(7, 4, 3),
+ /* 110 */ V(1, 8, 2),
+ /* 111 */ V(1, 8, 2),
+
+ /* 0001 0101 ... */
+ /* 000 */ V(8, 1, 2), /* 240 */
+ /* 001 */ V(8, 1, 2),
+ /* 010 */ V(8, 0, 2),
+ /* 011 */ V(8, 0, 2),
+ /* 100 */ V(0, 8, 3),
+ /* 101 */ V(5, 6, 3),
+ /* 110 */ V(3, 7, 2),
+ /* 111 */ V(3, 7, 2),
+
+ /* 0001 0110 ... */
+ /* 000 */ V(7, 3, 2), /* 248 */
+ /* 001 */ V(7, 3, 2),
+ /* 010 */ V(6, 5, 3),
+ /* 011 */ V(4, 6, 3),
+ /* 100 */ V(2, 7, 2),
+ /* 101 */ V(2, 7, 2),
+ /* 110 */ V(7, 2, 2),
+ /* 111 */ V(7, 2, 2),
+
+ /* 0001 0111 ... */
+ /* 000 */ V(6, 4, 3), /* 256 */
+ /* 001 */ V(5, 5, 3),
+ /* 010 */ V(0, 7, 2),
+ /* 011 */ V(0, 7, 2),
+ /* 100 */ V(1, 7, 1),
+ /* 101 */ V(1, 7, 1),
+ /* 110 */ V(1, 7, 1),
+ /* 111 */ V(1, 7, 1),
+
+ /* 0001 1000 ... */
+ /* 00 */ V(7, 1, 1), /* 264 */
+ /* 01 */ V(7, 1, 1),
+ /* 10 */ V(7, 0, 2),
+ /* 11 */ V(3, 6, 2),
+
+ /* 0001 1001 ... */
+ /* 00 */ V(6, 3, 2), /* 268 */
+ /* 01 */ V(4, 5, 2),
+ /* 10 */ V(5, 4, 2),
+ /* 11 */ V(2, 6, 2),
+
+ /* 0001 1010 ... */
+ /* 0 */ V(6, 2, 1), /* 272 */
+ /* 1 */ V(1, 6, 1),
+
+ /* 0001 1011 ... */
+ /* 00 */ V(6, 1, 1), /* 274 */
+ /* 01 */ V(6, 1, 1),
+ /* 10 */ V(0, 6, 2),
+ /* 11 */ V(6, 0, 2),
+
+ /* 0001 1100 ... */
+ /* 00 */ V(5, 3, 1), /* 278 */
+ /* 01 */ V(5, 3, 1),
+ /* 10 */ V(3, 5, 2),
+ /* 11 */ V(4, 4, 2),
+
+ /* 0001 1101 ... */
+ /* 0 */ V(2, 5, 1), /* 282 */
+ /* 1 */ V(5, 2, 1),
+
+ /* 0001 1111 ... */
+ /* 0 */ V(1, 5, 1), /* 284 */
+ /* 1 */ V(0, 5, 1),
+
+ /* 0010 0000 ... */
+ /* 0 */ V(3, 4, 1), /* 286 */
+ /* 1 */ V(4, 3, 1),
+
+ /* 0010 0001 ... */
+ /* 0 */ V(5, 0, 1), /* 288 */
+ /* 1 */ V(2, 4, 1),
+
+ /* 0010 0010 ... */
+ /* 0 */ V(4, 2, 1), /* 290 */
+ /* 1 */ V(3, 3, 1),
+
+ /* 0010 0101 ... */
+ /* 0 */ V(0, 4, 1), /* 292 */
+ /* 1 */ V(4, 0, 1),
+
+ /* 0000 0110 1100 ... */
+ /* 0000 */ V(12, 14, 4), /* 294 */
+ /* 0001 */ PTR(400, 1),
+ /* 0010 */ V(13, 14, 3),
+ /* 0011 */ V(13, 14, 3),
+ /* 0100 */ V(14, 9, 3),
+ /* 0101 */ V(14, 9, 3),
+ /* 0110 */ V(14, 10, 4),
+ /* 0111 */ V(13, 9, 4),
+ /* 1000 */ V(14, 14, 2),
+ /* 1001 */ V(14, 14, 2),
+ /* 1010 */ V(14, 14, 2),
+ /* 1011 */ V(14, 14, 2),
+ /* 1100 */ V(14, 13, 3),
+ /* 1101 */ V(14, 13, 3),
+ /* 1110 */ V(14, 11, 3),
+ /* 1111 */ V(14, 11, 3),
+
+ /* 0000 0110 1101 ... */
+ /* 000 */ V(11, 14, 2), /* 310 */
+ /* 001 */ V(11, 14, 2),
+ /* 010 */ V(12, 13, 2),
+ /* 011 */ V(12, 13, 2),
+ /* 100 */ V(13, 12, 3),
+ /* 101 */ V(13, 11, 3),
+ /* 110 */ V(10, 14, 2),
+ /* 111 */ V(10, 14, 2),
+
+ /* 0000 0110 1110 ... */
+ /* 000 */ V(12, 12, 2), /* 318 */
+ /* 001 */ V(12, 12, 2),
+ /* 010 */ V(10, 13, 3),
+ /* 011 */ V(13, 10, 3),
+ /* 100 */ V(7, 14, 3),
+ /* 101 */ V(10, 12, 3),
+ /* 110 */ V(12, 10, 2),
+ /* 111 */ V(12, 10, 2),
+
+ /* 0000 0110 1111 ... */
+ /* 000 */ V(12, 9, 3), /* 326 */
+ /* 001 */ V(7, 13, 3),
+ /* 010 */ V(5, 14, 2),
+ /* 011 */ V(5, 14, 2),
+ /* 100 */ V(11, 13, 1),
+ /* 101 */ V(11, 13, 1),
+ /* 110 */ V(11, 13, 1),
+ /* 111 */ V(11, 13, 1),
+
+ /* 0000 1011 0000 ... */
+ /* 00 */ V(9, 14, 1), /* 334 */
+ /* 01 */ V(9, 14, 1),
+ /* 10 */ V(11, 12, 2),
+ /* 11 */ V(12, 11, 2),
+
+ /* 0000 1011 0001 ... */
+ /* 00 */ V(8, 14, 2), /* 338 */
+ /* 01 */ V(14, 8, 2),
+ /* 10 */ V(9, 13, 2),
+ /* 11 */ V(14, 7, 2),
+
+ /* 0000 1011 0010 ... */
+ /* 00 */ V(11, 11, 2), /* 342 */
+ /* 01 */ V(8, 13, 2),
+ /* 10 */ V(13, 8, 2),
+ /* 11 */ V(6, 14, 2),
+
+ /* 0000 1011 0011 ... */
+ /* 0 */ V(14, 6, 1), /* 346 */
+ /* 1 */ V(9, 12, 1),
+
+ /* 0000 1011 0100 ... */
+ /* 00 */ V(10, 11, 2), /* 348 */
+ /* 01 */ V(11, 10, 2),
+ /* 10 */ V(14, 5, 2),
+ /* 11 */ V(13, 7, 2),
+
+ /* 0000 1011 0101 ... */
+ /* 00 */ V(4, 14, 1), /* 352 */
+ /* 01 */ V(4, 14, 1),
+ /* 10 */ V(14, 4, 2),
+ /* 11 */ V(8, 12, 2),
+
+ /* 0000 1011 0110 ... */
+ /* 0 */ V(12, 8, 1), /* 356 */
+ /* 1 */ V(3, 14, 1),
+
+ /* 0000 1011 0111 ... */
+ /* 00 */ V(6, 13, 1), /* 358 */
+ /* 01 */ V(6, 13, 1),
+ /* 10 */ V(13, 6, 2),
+ /* 11 */ V(9, 11, 2),
+
+ /* 0000 1011 1000 ... */
+ /* 00 */ V(11, 9, 2), /* 362 */
+ /* 01 */ V(10, 10, 2),
+ /* 10 */ V(14, 1, 1),
+ /* 11 */ V(14, 1, 1),
+
+ /* 0000 1011 1001 ... */
+ /* 00 */ V(13, 4, 1), /* 366 */
+ /* 01 */ V(13, 4, 1),
+ /* 10 */ V(11, 8, 2),
+ /* 11 */ V(10, 9, 2),
+
+ /* 0000 1011 1010 ... */
+ /* 00 */ V(7, 11, 1), /* 370 */
+ /* 01 */ V(7, 11, 1),
+ /* 10 */ V(11, 7, 2),
+ /* 11 */ V(13, 0, 2),
+
+ /* 0000 1011 1100 ... */
+ /* 0 */ V(0, 14, 1), /* 374 */
+ /* 1 */ V(14, 0, 1),
+
+ /* 0000 1011 1101 ... */
+ /* 0 */ V(5, 13, 1), /* 376 */
+ /* 1 */ V(13, 5, 1),
+
+ /* 0000 1011 1110 ... */
+ /* 0 */ V(7, 12, 1), /* 378 */
+ /* 1 */ V(12, 7, 1),
+
+ /* 0000 1011 1111 ... */
+ /* 0 */ V(4, 13, 1), /* 380 */
+ /* 1 */ V(8, 11, 1),
+
+ /* 0000 1100 0000 ... */
+ /* 0 */ V(9, 10, 1), /* 382 */
+ /* 1 */ V(6, 12, 1),
+
+ /* 0000 1100 0001 ... */
+ /* 0 */ V(12, 6, 1), /* 384 */
+ /* 1 */ V(3, 13, 1),
+
+ /* 0000 1100 0010 ... */
+ /* 0 */ V(5, 12, 1), /* 386 */
+ /* 1 */ V(12, 5, 1),
+
+ /* 0000 1100 0100 ... */
+ /* 0 */ V(8, 10, 1), /* 388 */
+ /* 1 */ V(10, 8, 1),
+
+ /* 0000 1100 0101 ... */
+ /* 0 */ V(9, 9, 1), /* 390 */
+ /* 1 */ V(4, 12, 1),
+
+ /* 0000 1100 0110 ... */
+ /* 0 */ V(11, 6, 1), /* 392 */
+ /* 1 */ V(7, 10, 1),
+
+ /* 0000 1100 1000 ... */
+ /* 0 */ V(5, 11, 1), /* 394 */
+ /* 1 */ V(8, 9, 1),
+
+ /* 0000 1100 1011 ... */
+ /* 0 */ V(9, 8, 1), /* 396 */
+ /* 1 */ V(7, 9, 1),
+
+ /* 0000 1101 0101 ... */
+ /* 0 */ V(9, 7, 1), /* 398 */
+ /* 1 */ V(8, 8, 1),
+
+ /* 0000 0110 1100 0001 ... */
+ /* 0 */ V(14, 12, 1), /* 400 */
+ /* 1 */ V(13, 13, 1)
+};
+
+static
+union huffpair const hufftab24[] = {
+ /* 0000 */ PTR(16, 4),
+ /* 0001 */ PTR(32, 4),
+ /* 0010 */ PTR(48, 4),
+ /* 0011 */ V(15, 15, 4),
+ /* 0100 */ PTR(64, 4),
+ /* 0101 */ PTR(80, 4),
+ /* 0110 */ PTR(96, 4),
+ /* 0111 */ PTR(112, 4),
+ /* 1000 */ PTR(128, 4),
+ /* 1001 */ PTR(144, 4),
+ /* 1010 */ PTR(160, 3),
+ /* 1011 */ PTR(168, 2),
+ /* 1100 */ V(1, 1, 4),
+ /* 1101 */ V(0, 1, 4),
+ /* 1110 */ V(1, 0, 4),
+ /* 1111 */ V(0, 0, 4),
+
+ /* 0000 ... */
+ /* 0000 */ V(14, 15, 4), /* 16 */
+ /* 0001 */ V(15, 14, 4),
+ /* 0010 */ V(13, 15, 4),
+ /* 0011 */ V(15, 13, 4),
+ /* 0100 */ V(12, 15, 4),
+ /* 0101 */ V(15, 12, 4),
+ /* 0110 */ V(11, 15, 4),
+ /* 0111 */ V(15, 11, 4),
+ /* 1000 */ V(15, 10, 3),
+ /* 1001 */ V(15, 10, 3),
+ /* 1010 */ V(10, 15, 4),
+ /* 1011 */ V(9, 15, 4),
+ /* 1100 */ V(15, 9, 3),
+ /* 1101 */ V(15, 9, 3),
+ /* 1110 */ V(15, 8, 3),
+ /* 1111 */ V(15, 8, 3),
+
+ /* 0001 ... */
+ /* 0000 */ V(8, 15, 4), /* 32 */
+ /* 0001 */ V(7, 15, 4),
+ /* 0010 */ V(15, 7, 3),
+ /* 0011 */ V(15, 7, 3),
+ /* 0100 */ V(6, 15, 3),
+ /* 0101 */ V(6, 15, 3),
+ /* 0110 */ V(15, 6, 3),
+ /* 0111 */ V(15, 6, 3),
+ /* 1000 */ V(5, 15, 3),
+ /* 1001 */ V(5, 15, 3),
+ /* 1010 */ V(15, 5, 3),
+ /* 1011 */ V(15, 5, 3),
+ /* 1100 */ V(4, 15, 3),
+ /* 1101 */ V(4, 15, 3),
+ /* 1110 */ V(15, 4, 3),
+ /* 1111 */ V(15, 4, 3),
+
+ /* 0010 ... */
+ /* 0000 */ V(3, 15, 3), /* 48 */
+ /* 0001 */ V(3, 15, 3),
+ /* 0010 */ V(15, 3, 3),
+ /* 0011 */ V(15, 3, 3),
+ /* 0100 */ V(2, 15, 3),
+ /* 0101 */ V(2, 15, 3),
+ /* 0110 */ V(15, 2, 3),
+ /* 0111 */ V(15, 2, 3),
+ /* 1000 */ V(15, 1, 3),
+ /* 1001 */ V(15, 1, 3),
+ /* 1010 */ V(1, 15, 4),
+ /* 1011 */ V(15, 0, 4),
+ /* 1100 */ PTR(172, 3),
+ /* 1101 */ PTR(180, 3),
+ /* 1110 */ PTR(188, 3),
+ /* 1111 */ PTR(196, 3),
+
+ /* 0100 ... */
+ /* 0000 */ PTR(204, 4), /* 64 */
+ /* 0001 */ PTR(220, 3),
+ /* 0010 */ PTR(228, 3),
+ /* 0011 */ PTR(236, 3),
+ /* 0100 */ PTR(244, 2),
+ /* 0101 */ PTR(248, 2),
+ /* 0110 */ PTR(252, 2),
+ /* 0111 */ PTR(256, 2),
+ /* 1000 */ PTR(260, 2),
+ /* 1001 */ PTR(264, 2),
+ /* 1010 */ PTR(268, 2),
+ /* 1011 */ PTR(272, 2),
+ /* 1100 */ PTR(276, 2),
+ /* 1101 */ PTR(280, 3),
+ /* 1110 */ PTR(288, 2),
+ /* 1111 */ PTR(292, 2),
+
+ /* 0101 ... */
+ /* 0000 */ PTR(296, 2), /* 80 */
+ /* 0001 */ PTR(300, 3),
+ /* 0010 */ PTR(308, 2),
+ /* 0011 */ PTR(312, 3),
+ /* 0100 */ PTR(320, 1),
+ /* 0101 */ PTR(322, 2),
+ /* 0110 */ PTR(326, 2),
+ /* 0111 */ PTR(330, 1),
+ /* 1000 */ PTR(332, 2),
+ /* 1001 */ PTR(336, 1),
+ /* 1010 */ PTR(338, 1),
+ /* 1011 */ PTR(340, 1),
+ /* 1100 */ PTR(342, 1),
+ /* 1101 */ PTR(344, 1),
+ /* 1110 */ PTR(346, 1),
+ /* 1111 */ PTR(348, 1),
+
+ /* 0110 ... */
+ /* 0000 */ PTR(350, 1), /* 96 */
+ /* 0001 */ PTR(352, 1),
+ /* 0010 */ PTR(354, 1),
+ /* 0011 */ PTR(356, 1),
+ /* 0100 */ PTR(358, 1),
+ /* 0101 */ PTR(360, 1),
+ /* 0110 */ PTR(362, 1),
+ /* 0111 */ PTR(364, 1),
+ /* 1000 */ PTR(366, 1),
+ /* 1001 */ PTR(368, 1),
+ /* 1010 */ PTR(370, 2),
+ /* 1011 */ PTR(374, 1),
+ /* 1100 */ PTR(376, 2),
+ /* 1101 */ V(7, 3, 4),
+ /* 1110 */ PTR(380, 1),
+ /* 1111 */ V(7, 2, 4),
+
+ /* 0111 ... */
+ /* 0000 */ V(4, 6, 4), /* 112 */
+ /* 0001 */ V(6, 4, 4),
+ /* 0010 */ V(5, 5, 4),
+ /* 0011 */ V(7, 1, 4),
+ /* 0100 */ V(3, 6, 4),
+ /* 0101 */ V(6, 3, 4),
+ /* 0110 */ V(4, 5, 4),
+ /* 0111 */ V(5, 4, 4),
+ /* 1000 */ V(2, 6, 4),
+ /* 1001 */ V(6, 2, 4),
+ /* 1010 */ V(1, 6, 4),
+ /* 1011 */ V(6, 1, 4),
+ /* 1100 */ PTR(382, 1),
+ /* 1101 */ V(3, 5, 4),
+ /* 1110 */ V(5, 3, 4),
+ /* 1111 */ V(4, 4, 4),
+
+ /* 1000 ... */
+ /* 0000 */ V(2, 5, 4), /* 128 */
+ /* 0001 */ V(5, 2, 4),
+ /* 0010 */ V(1, 5, 4),
+ /* 0011 */ PTR(384, 1),
+ /* 0100 */ V(5, 1, 3),
+ /* 0101 */ V(5, 1, 3),
+ /* 0110 */ V(3, 4, 4),
+ /* 0111 */ V(4, 3, 4),
+ /* 1000 */ V(2, 4, 3),
+ /* 1001 */ V(2, 4, 3),
+ /* 1010 */ V(4, 2, 3),
+ /* 1011 */ V(4, 2, 3),
+ /* 1100 */ V(3, 3, 3),
+ /* 1101 */ V(3, 3, 3),
+ /* 1110 */ V(1, 4, 3),
+ /* 1111 */ V(1, 4, 3),
+
+ /* 1001 ... */
+ /* 0000 */ V(4, 1, 3), /* 144 */
+ /* 0001 */ V(4, 1, 3),
+ /* 0010 */ V(0, 4, 4),
+ /* 0011 */ V(4, 0, 4),
+ /* 0100 */ V(2, 3, 3),
+ /* 0101 */ V(2, 3, 3),
+ /* 0110 */ V(3, 2, 3),
+ /* 0111 */ V(3, 2, 3),
+ /* 1000 */ V(1, 3, 2),
+ /* 1001 */ V(1, 3, 2),
+ /* 1010 */ V(1, 3, 2),
+ /* 1011 */ V(1, 3, 2),
+ /* 1100 */ V(3, 1, 2),
+ /* 1101 */ V(3, 1, 2),
+ /* 1110 */ V(3, 1, 2),
+ /* 1111 */ V(3, 1, 2),
+
+ /* 1010 ... */
+ /* 000 */ V(0, 3, 3), /* 160 */
+ /* 001 */ V(3, 0, 3),
+ /* 010 */ V(2, 2, 2),
+ /* 011 */ V(2, 2, 2),
+ /* 100 */ V(1, 2, 1),
+ /* 101 */ V(1, 2, 1),
+ /* 110 */ V(1, 2, 1),
+ /* 111 */ V(1, 2, 1),
+
+ /* 1011 ... */
+ /* 00 */ V(2, 1, 1), /* 168 */
+ /* 01 */ V(2, 1, 1),
+ /* 10 */ V(0, 2, 2),
+ /* 11 */ V(2, 0, 2),
+
+ /* 0010 1100 ... */
+ /* 000 */ V(0, 15, 1), /* 172 */
+ /* 001 */ V(0, 15, 1),
+ /* 010 */ V(0, 15, 1),
+ /* 011 */ V(0, 15, 1),
+ /* 100 */ V(14, 14, 3),
+ /* 101 */ V(13, 14, 3),
+ /* 110 */ V(14, 13, 3),
+ /* 111 */ V(12, 14, 3),
+
+ /* 0010 1101 ... */
+ /* 000 */ V(14, 12, 3), /* 180 */
+ /* 001 */ V(13, 13, 3),
+ /* 010 */ V(11, 14, 3),
+ /* 011 */ V(14, 11, 3),
+ /* 100 */ V(12, 13, 3),
+ /* 101 */ V(13, 12, 3),
+ /* 110 */ V(10, 14, 3),
+ /* 111 */ V(14, 10, 3),
+
+ /* 0010 1110 ... */
+ /* 000 */ V(11, 13, 3), /* 188 */
+ /* 001 */ V(13, 11, 3),
+ /* 010 */ V(12, 12, 3),
+ /* 011 */ V(9, 14, 3),
+ /* 100 */ V(14, 9, 3),
+ /* 101 */ V(10, 13, 3),
+ /* 110 */ V(13, 10, 3),
+ /* 111 */ V(11, 12, 3),
+
+ /* 0010 1111 ... */
+ /* 000 */ V(12, 11, 3), /* 196 */
+ /* 001 */ V(8, 14, 3),
+ /* 010 */ V(14, 8, 3),
+ /* 011 */ V(9, 13, 3),
+ /* 100 */ V(13, 9, 3),
+ /* 101 */ V(7, 14, 3),
+ /* 110 */ V(14, 7, 3),
+ /* 111 */ V(10, 12, 3),
+
+ /* 0100 0000 ... */
+ /* 0000 */ V(12, 10, 3), /* 204 */
+ /* 0001 */ V(12, 10, 3),
+ /* 0010 */ V(11, 11, 3),
+ /* 0011 */ V(11, 11, 3),
+ /* 0100 */ V(8, 13, 3),
+ /* 0101 */ V(8, 13, 3),
+ /* 0110 */ V(13, 8, 3),
+ /* 0111 */ V(13, 8, 3),
+ /* 1000 */ V(0, 14, 4),
+ /* 1001 */ V(14, 0, 4),
+ /* 1010 */ V(0, 13, 3),
+ /* 1011 */ V(0, 13, 3),
+ /* 1100 */ V(14, 6, 2),
+ /* 1101 */ V(14, 6, 2),
+ /* 1110 */ V(14, 6, 2),
+ /* 1111 */ V(14, 6, 2),
+
+ /* 0100 0001 ... */
+ /* 000 */ V(6, 14, 3), /* 220 */
+ /* 001 */ V(9, 12, 3),
+ /* 010 */ V(12, 9, 2),
+ /* 011 */ V(12, 9, 2),
+ /* 100 */ V(5, 14, 2),
+ /* 101 */ V(5, 14, 2),
+ /* 110 */ V(11, 10, 2),
+ /* 111 */ V(11, 10, 2),
+
+ /* 0100 0010 ... */
+ /* 000 */ V(14, 5, 2), /* 228 */
+ /* 001 */ V(14, 5, 2),
+ /* 010 */ V(10, 11, 3),
+ /* 011 */ V(7, 13, 3),
+ /* 100 */ V(13, 7, 2),
+ /* 101 */ V(13, 7, 2),
+ /* 110 */ V(14, 4, 2),
+ /* 111 */ V(14, 4, 2),
+
+ /* 0100 0011 ... */
+ /* 000 */ V(8, 12, 2), /* 236 */
+ /* 001 */ V(8, 12, 2),
+ /* 010 */ V(12, 8, 2),
+ /* 011 */ V(12, 8, 2),
+ /* 100 */ V(4, 14, 3),
+ /* 101 */ V(2, 14, 3),
+ /* 110 */ V(3, 14, 2),
+ /* 111 */ V(3, 14, 2),
+
+ /* 0100 0100 ... */
+ /* 00 */ V(6, 13, 2), /* 244 */
+ /* 01 */ V(13, 6, 2),
+ /* 10 */ V(14, 3, 2),
+ /* 11 */ V(9, 11, 2),
+
+ /* 0100 0101 ... */
+ /* 00 */ V(11, 9, 2), /* 248 */
+ /* 01 */ V(10, 10, 2),
+ /* 10 */ V(14, 2, 2),
+ /* 11 */ V(1, 14, 2),
+
+ /* 0100 0110 ... */
+ /* 00 */ V(14, 1, 2), /* 252 */
+ /* 01 */ V(5, 13, 2),
+ /* 10 */ V(13, 5, 2),
+ /* 11 */ V(7, 12, 2),
+
+ /* 0100 0111 ... */
+ /* 00 */ V(12, 7, 2), /* 256 */
+ /* 01 */ V(4, 13, 2),
+ /* 10 */ V(8, 11, 2),
+ /* 11 */ V(11, 8, 2),
+
+ /* 0100 1000 ... */
+ /* 00 */ V(13, 4, 2), /* 260 */
+ /* 01 */ V(9, 10, 2),
+ /* 10 */ V(10, 9, 2),
+ /* 11 */ V(6, 12, 2),
+
+ /* 0100 1001 ... */
+ /* 00 */ V(12, 6, 2), /* 264 */
+ /* 01 */ V(3, 13, 2),
+ /* 10 */ V(13, 3, 2),
+ /* 11 */ V(2, 13, 2),
+
+ /* 0100 1010 ... */
+ /* 00 */ V(13, 2, 2), /* 268 */
+ /* 01 */ V(1, 13, 2),
+ /* 10 */ V(7, 11, 2),
+ /* 11 */ V(11, 7, 2),
+
+ /* 0100 1011 ... */
+ /* 00 */ V(13, 1, 2), /* 272 */
+ /* 01 */ V(5, 12, 2),
+ /* 10 */ V(12, 5, 2),
+ /* 11 */ V(8, 10, 2),
+
+ /* 0100 1100 ... */
+ /* 00 */ V(10, 8, 2), /* 276 */
+ /* 01 */ V(9, 9, 2),
+ /* 10 */ V(4, 12, 2),
+ /* 11 */ V(12, 4, 2),
+
+ /* 0100 1101 ... */
+ /* 000 */ V(6, 11, 2), /* 280 */
+ /* 001 */ V(6, 11, 2),
+ /* 010 */ V(11, 6, 2),
+ /* 011 */ V(11, 6, 2),
+ /* 100 */ V(13, 0, 3),
+ /* 101 */ V(0, 12, 3),
+ /* 110 */ V(3, 12, 2),
+ /* 111 */ V(3, 12, 2),
+
+ /* 0100 1110 ... */
+ /* 00 */ V(12, 3, 2), /* 288 */
+ /* 01 */ V(7, 10, 2),
+ /* 10 */ V(10, 7, 2),
+ /* 11 */ V(2, 12, 2),
+
+ /* 0100 1111 ... */
+ /* 00 */ V(12, 2, 2), /* 292 */
+ /* 01 */ V(5, 11, 2),
+ /* 10 */ V(11, 5, 2),
+ /* 11 */ V(1, 12, 2),
+
+ /* 0101 0000 ... */
+ /* 00 */ V(8, 9, 2), /* 296 */
+ /* 01 */ V(9, 8, 2),
+ /* 10 */ V(12, 1, 2),
+ /* 11 */ V(4, 11, 2),
+
+ /* 0101 0001 ... */
+ /* 000 */ V(12, 0, 3), /* 300 */
+ /* 001 */ V(0, 11, 3),
+ /* 010 */ V(3, 11, 2),
+ /* 011 */ V(3, 11, 2),
+ /* 100 */ V(11, 0, 3),
+ /* 101 */ V(0, 10, 3),
+ /* 110 */ V(1, 10, 2),
+ /* 111 */ V(1, 10, 2),
+
+ /* 0101 0010 ... */
+ /* 00 */ V(11, 4, 1), /* 308 */
+ /* 01 */ V(11, 4, 1),
+ /* 10 */ V(6, 10, 2),
+ /* 11 */ V(10, 6, 2),
+
+ /* 0101 0011 ... */
+ /* 000 */ V(7, 9, 2), /* 312 */
+ /* 001 */ V(7, 9, 2),
+ /* 010 */ V(9, 7, 2),
+ /* 011 */ V(9, 7, 2),
+ /* 100 */ V(10, 0, 3),
+ /* 101 */ V(0, 9, 3),
+ /* 110 */ V(9, 0, 2),
+ /* 111 */ V(9, 0, 2),
+
+ /* 0101 0100 ... */
+ /* 0 */ V(11, 3, 1), /* 320 */
+ /* 1 */ V(8, 8, 1),
+
+ /* 0101 0101 ... */
+ /* 00 */ V(2, 11, 2), /* 322 */
+ /* 01 */ V(5, 10, 2),
+ /* 10 */ V(11, 2, 1),
+ /* 11 */ V(11, 2, 1),
+
+ /* 0101 0110 ... */
+ /* 00 */ V(10, 5, 2), /* 326 */
+ /* 01 */ V(1, 11, 2),
+ /* 10 */ V(11, 1, 2),
+ /* 11 */ V(6, 9, 2),
+
+ /* 0101 0111 ... */
+ /* 0 */ V(9, 6, 1), /* 330 */
+ /* 1 */ V(10, 4, 1),
+
+ /* 0101 1000 ... */
+ /* 00 */ V(4, 10, 2), /* 332 */
+ /* 01 */ V(7, 8, 2),
+ /* 10 */ V(8, 7, 1),
+ /* 11 */ V(8, 7, 1),
+
+ /* 0101 1001 ... */
+ /* 0 */ V(3, 10, 1), /* 336 */
+ /* 1 */ V(10, 3, 1),
+
+ /* 0101 1010 ... */
+ /* 0 */ V(5, 9, 1), /* 338 */
+ /* 1 */ V(9, 5, 1),
+
+ /* 0101 1011 ... */
+ /* 0 */ V(2, 10, 1), /* 340 */
+ /* 1 */ V(10, 2, 1),
+
+ /* 0101 1100 ... */
+ /* 0 */ V(10, 1, 1), /* 342 */
+ /* 1 */ V(6, 8, 1),
+
+ /* 0101 1101 ... */
+ /* 0 */ V(8, 6, 1), /* 344 */
+ /* 1 */ V(7, 7, 1),
+
+ /* 0101 1110 ... */
+ /* 0 */ V(4, 9, 1), /* 346 */
+ /* 1 */ V(9, 4, 1),
+
+ /* 0101 1111 ... */
+ /* 0 */ V(3, 9, 1), /* 348 */
+ /* 1 */ V(9, 3, 1),
+
+ /* 0110 0000 ... */
+ /* 0 */ V(5, 8, 1), /* 350 */
+ /* 1 */ V(8, 5, 1),
+
+ /* 0110 0001 ... */
+ /* 0 */ V(2, 9, 1), /* 352 */
+ /* 1 */ V(6, 7, 1),
+
+ /* 0110 0010 ... */
+ /* 0 */ V(7, 6, 1), /* 354 */
+ /* 1 */ V(9, 2, 1),
+
+ /* 0110 0011 ... */
+ /* 0 */ V(1, 9, 1), /* 356 */
+ /* 1 */ V(9, 1, 1),
+
+ /* 0110 0100 ... */
+ /* 0 */ V(4, 8, 1), /* 358 */
+ /* 1 */ V(8, 4, 1),
+
+ /* 0110 0101 ... */
+ /* 0 */ V(5, 7, 1), /* 360 */
+ /* 1 */ V(7, 5, 1),
+
+ /* 0110 0110 ... */
+ /* 0 */ V(3, 8, 1), /* 362 */
+ /* 1 */ V(8, 3, 1),
+
+ /* 0110 0111 ... */
+ /* 0 */ V(6, 6, 1), /* 364 */
+ /* 1 */ V(2, 8, 1),
+
+ /* 0110 1000 ... */
+ /* 0 */ V(8, 2, 1), /* 366 */
+ /* 1 */ V(1, 8, 1),
+
+ /* 0110 1001 ... */
+ /* 0 */ V(4, 7, 1), /* 368 */
+ /* 1 */ V(7, 4, 1),
+
+ /* 0110 1010 ... */
+ /* 00 */ V(8, 1, 1), /* 370 */
+ /* 01 */ V(8, 1, 1),
+ /* 10 */ V(0, 8, 2),
+ /* 11 */ V(8, 0, 2),
+
+ /* 0110 1011 ... */
+ /* 0 */ V(5, 6, 1), /* 374 */
+ /* 1 */ V(6, 5, 1),
+
+ /* 0110 1100 ... */
+ /* 00 */ V(1, 7, 1), /* 376 */
+ /* 01 */ V(1, 7, 1),
+ /* 10 */ V(0, 7, 2),
+ /* 11 */ V(7, 0, 2),
+
+ /* 0110 1110 ... */
+ /* 0 */ V(3, 7, 1), /* 380 */
+ /* 1 */ V(2, 7, 1),
+
+ /* 0111 1100 ... */
+ /* 0 */ V(0, 6, 1), /* 382 */
+ /* 1 */ V(6, 0, 1),
+
+ /* 1000 0011 ... */
+ /* 0 */ V(0, 5, 1), /* 384 */
+ /* 1 */ V(5, 0, 1)
+};
+
+# undef V
+# undef PTR
+
+/* external tables */
+
+union huffquad const *const mad_huff_quad_table[2] = { hufftabA, hufftabB };
+
+struct hufftable const mad_huff_pair_table[32] = {
+ /* 0 */ { hufftab0, 0, 0 },
+ /* 1 */ { hufftab1, 0, 3 },
+ /* 2 */ { hufftab2, 0, 3 },
+ /* 3 */ { hufftab3, 0, 3 },
+ /* 4 */ { 0 /* not used */ },
+ /* 5 */ { hufftab5, 0, 3 },
+ /* 6 */ { hufftab6, 0, 4 },
+ /* 7 */ { hufftab7, 0, 4 },
+ /* 8 */ { hufftab8, 0, 4 },
+ /* 9 */ { hufftab9, 0, 4 },
+ /* 10 */ { hufftab10, 0, 4 },
+ /* 11 */ { hufftab11, 0, 4 },
+ /* 12 */ { hufftab12, 0, 4 },
+ /* 13 */ { hufftab13, 0, 4 },
+ /* 14 */ { 0 /* not used */ },
+ /* 15 */ { hufftab15, 0, 4 },
+ /* 16 */ { hufftab16, 1, 4 },
+ /* 17 */ { hufftab16, 2, 4 },
+ /* 18 */ { hufftab16, 3, 4 },
+ /* 19 */ { hufftab16, 4, 4 },
+ /* 20 */ { hufftab16, 6, 4 },
+ /* 21 */ { hufftab16, 8, 4 },
+ /* 22 */ { hufftab16, 10, 4 },
+ /* 23 */ { hufftab16, 13, 4 },
+ /* 24 */ { hufftab24, 4, 4 },
+ /* 25 */ { hufftab24, 5, 4 },
+ /* 26 */ { hufftab24, 6, 4 },
+ /* 27 */ { hufftab24, 7, 4 },
+ /* 28 */ { hufftab24, 8, 4 },
+ /* 29 */ { hufftab24, 9, 4 },
+ /* 30 */ { hufftab24, 11, 4 },
+ /* 31 */ { hufftab24, 13, 4 }
+};
diff --git a/contrib/libmad/huffman.h b/contrib/libmad/huffman.h
new file mode 100644
index 000000000..6325db44a
--- /dev/null
+++ b/contrib/libmad/huffman.h
@@ -0,0 +1,66 @@
+/*
+ * libmad - MPEG audio decoder library
+ * Copyright (C) 2000-2004 Underbit Technologies, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: huffman.h,v 1.11 2004/01/23 09:41:32 rob Exp $
+ */
+
+# ifndef LIBMAD_HUFFMAN_H
+# define LIBMAD_HUFFMAN_H
+
+union huffquad {
+ struct {
+ unsigned short final : 1;
+ unsigned short bits : 3;
+ unsigned short offset : 12;
+ } ptr;
+ struct {
+ unsigned short final : 1;
+ unsigned short hlen : 3;
+ unsigned short v : 1;
+ unsigned short w : 1;
+ unsigned short x : 1;
+ unsigned short y : 1;
+ } value;
+ unsigned short final : 1;
+};
+
+union huffpair {
+ struct {
+ unsigned short final : 1;
+ unsigned short bits : 3;
+ unsigned short offset : 12;
+ } ptr;
+ struct {
+ unsigned short final : 1;
+ unsigned short hlen : 3;
+ unsigned short x : 4;
+ unsigned short y : 4;
+ } value;
+ unsigned short final : 1;
+};
+
+struct hufftable {
+ union huffpair const *table;
+ unsigned short linbits;
+ unsigned short startbits;
+};
+
+extern union huffquad const *const mad_huff_quad_table[2];
+extern struct hufftable const mad_huff_pair_table[32];
+
+# endif
diff --git a/contrib/libmad/imdct_s.dat b/contrib/libmad/imdct_s.dat
new file mode 100644
index 000000000..476710eaf
--- /dev/null
+++ b/contrib/libmad/imdct_s.dat
@@ -0,0 +1,62 @@
+/*
+ * libmad - MPEG audio decoder library
+ * Copyright (C) 2000-2004 Underbit Technologies, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: imdct_s.dat,v 1.8 2004/01/23 09:41:32 rob Exp $
+ */
+
+ /* 0 */ { MAD_F(0x09bd7ca0) /* 0.608761429 */,
+ -MAD_F(0x0ec835e8) /* -0.923879533 */,
+ -MAD_F(0x0216a2a2) /* -0.130526192 */,
+ MAD_F(0x0fdcf549) /* 0.991444861 */,
+ -MAD_F(0x061f78aa) /* -0.382683432 */,
+ -MAD_F(0x0cb19346) /* -0.793353340 */ },
+
+ /* 6 */ { -MAD_F(0x0cb19346) /* -0.793353340 */,
+ MAD_F(0x061f78aa) /* 0.382683432 */,
+ MAD_F(0x0fdcf549) /* 0.991444861 */,
+ MAD_F(0x0216a2a2) /* 0.130526192 */,
+ -MAD_F(0x0ec835e8) /* -0.923879533 */,
+ -MAD_F(0x09bd7ca0) /* -0.608761429 */ },
+
+ /* 1 */ { MAD_F(0x061f78aa) /* 0.382683432 */,
+ -MAD_F(0x0ec835e8) /* -0.923879533 */,
+ MAD_F(0x0ec835e8) /* 0.923879533 */,
+ -MAD_F(0x061f78aa) /* -0.382683432 */,
+ -MAD_F(0x061f78aa) /* -0.382683432 */,
+ MAD_F(0x0ec835e8) /* 0.923879533 */ },
+
+ /* 7 */ { -MAD_F(0x0ec835e8) /* -0.923879533 */,
+ -MAD_F(0x061f78aa) /* -0.382683432 */,
+ MAD_F(0x061f78aa) /* 0.382683432 */,
+ MAD_F(0x0ec835e8) /* 0.923879533 */,
+ MAD_F(0x0ec835e8) /* 0.923879533 */,
+ MAD_F(0x061f78aa) /* 0.382683432 */ },
+
+ /* 2 */ { MAD_F(0x0216a2a2) /* 0.130526192 */,
+ -MAD_F(0x061f78aa) /* -0.382683432 */,
+ MAD_F(0x09bd7ca0) /* 0.608761429 */,
+ -MAD_F(0x0cb19346) /* -0.793353340 */,
+ MAD_F(0x0ec835e8) /* 0.923879533 */,
+ -MAD_F(0x0fdcf549) /* -0.991444861 */ },
+
+ /* 8 */ { -MAD_F(0x0fdcf549) /* -0.991444861 */,
+ -MAD_F(0x0ec835e8) /* -0.923879533 */,
+ -MAD_F(0x0cb19346) /* -0.793353340 */,
+ -MAD_F(0x09bd7ca0) /* -0.608761429 */,
+ -MAD_F(0x061f78aa) /* -0.382683432 */,
+ -MAD_F(0x0216a2a2) /* -0.130526192 */ }
diff --git a/contrib/libmad/layer12.c b/contrib/libmad/layer12.c
new file mode 100644
index 000000000..6981f9ce1
--- /dev/null
+++ b/contrib/libmad/layer12.c
@@ -0,0 +1,534 @@
+/*
+ * libmad - MPEG audio decoder library
+ * Copyright (C) 2000-2004 Underbit Technologies, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: layer12.c,v 1.17 2004/02/05 09:02:39 rob Exp $
+ */
+
+# ifdef HAVE_CONFIG_H
+# include "config.h"
+# endif
+
+# include "global.h"
+
+# ifdef HAVE_LIMITS_H
+# include <limits.h>
+# else
+# define CHAR_BIT 8
+# endif
+
+# include "fixed.h"
+# include "bit.h"
+# include "stream.h"
+# include "frame.h"
+# include "layer12.h"
+
+/*
+ * scalefactor table
+ * used in both Layer I and Layer II decoding
+ */
+static
+mad_fixed_t const sf_table[64] = {
+# include "sf_table.dat"
+};
+
+/* --- Layer I ------------------------------------------------------------- */
+
+/* linear scaling table */
+static
+mad_fixed_t const linear_table[14] = {
+ MAD_F(0x15555555), /* 2^2 / (2^2 - 1) == 1.33333333333333 */
+ MAD_F(0x12492492), /* 2^3 / (2^3 - 1) == 1.14285714285714 */
+ MAD_F(0x11111111), /* 2^4 / (2^4 - 1) == 1.06666666666667 */
+ MAD_F(0x10842108), /* 2^5 / (2^5 - 1) == 1.03225806451613 */
+ MAD_F(0x10410410), /* 2^6 / (2^6 - 1) == 1.01587301587302 */
+ MAD_F(0x10204081), /* 2^7 / (2^7 - 1) == 1.00787401574803 */
+ MAD_F(0x10101010), /* 2^8 / (2^8 - 1) == 1.00392156862745 */
+ MAD_F(0x10080402), /* 2^9 / (2^9 - 1) == 1.00195694716243 */
+ MAD_F(0x10040100), /* 2^10 / (2^10 - 1) == 1.00097751710655 */
+ MAD_F(0x10020040), /* 2^11 / (2^11 - 1) == 1.00048851978505 */
+ MAD_F(0x10010010), /* 2^12 / (2^12 - 1) == 1.00024420024420 */
+ MAD_F(0x10008004), /* 2^13 / (2^13 - 1) == 1.00012208521548 */
+ MAD_F(0x10004001), /* 2^14 / (2^14 - 1) == 1.00006103888177 */
+ MAD_F(0x10002000) /* 2^15 / (2^15 - 1) == 1.00003051850948 */
+};
+
+/*
+ * NAME: I_sample()
+ * DESCRIPTION: decode one requantized Layer I sample from a bitstream
+ */
+static
+mad_fixed_t I_sample(struct mad_bitptr *ptr, unsigned int nb)
+{
+ mad_fixed_t sample;
+
+ sample = mad_bit_read(ptr, nb);
+
+ /* invert most significant bit, extend sign, then scale to fixed format */
+
+ sample ^= 1 << (nb - 1);
+ sample |= -(sample & (1 << (nb - 1)));
+
+ sample <<= MAD_F_FRACBITS - (nb - 1);
+
+ /* requantize the sample */
+
+ /* s'' = (2^nb / (2^nb - 1)) * (s''' + 2^(-nb + 1)) */
+
+ sample += MAD_F_ONE >> (nb - 1);
+
+ return mad_f_mul(sample, linear_table[nb - 2]);
+
+ /* s' = factor * s'' */
+ /* (to be performed by caller) */
+}
+
+/*
+ * NAME: layer->I()
+ * DESCRIPTION: decode a single Layer I frame
+ */
+int mad_layer_I(struct mad_stream *stream, struct mad_frame *frame)
+{
+ struct mad_header *header = &frame->header;
+ unsigned int nch, bound, ch, s, sb, nb;
+ unsigned char allocation[2][32], scalefactor[2][32];
+
+ nch = MAD_NCHANNELS(header);
+
+ bound = 32;
+ if (header->mode == MAD_MODE_JOINT_STEREO) {
+ header->flags |= MAD_FLAG_I_STEREO;
+ bound = 4 + header->mode_extension * 4;
+ }
+
+ /* check CRC word */
+
+ if (header->flags & MAD_FLAG_PROTECTION) {
+ header->crc_check =
+ mad_bit_crc(stream->ptr, 4 * (bound * nch + (32 - bound)),
+ header->crc_check);
+
+ if (header->crc_check != header->crc_target &&
+ !(frame->options & MAD_OPTION_IGNORECRC)) {
+ stream->error = MAD_ERROR_BADCRC;
+ return -1;
+ }
+ }
+
+ /* decode bit allocations */
+
+ for (sb = 0; sb < bound; ++sb) {
+ for (ch = 0; ch < nch; ++ch) {
+ nb = mad_bit_read(&stream->ptr, 4);
+
+ if (nb == 15) {
+ stream->error = MAD_ERROR_BADBITALLOC;
+ return -1;
+ }
+
+ allocation[ch][sb] = nb ? nb + 1 : 0;
+ }
+ }
+
+ for (sb = bound; sb < 32; ++sb) {
+ nb = mad_bit_read(&stream->ptr, 4);
+
+ if (nb == 15) {
+ stream->error = MAD_ERROR_BADBITALLOC;
+ return -1;
+ }
+
+ allocation[0][sb] =
+ allocation[1][sb] = nb ? nb + 1 : 0;
+ }
+
+ /* decode scalefactors */
+
+ for (sb = 0; sb < 32; ++sb) {
+ for (ch = 0; ch < nch; ++ch) {
+ if (allocation[ch][sb]) {
+ scalefactor[ch][sb] = mad_bit_read(&stream->ptr, 6);
+
+# if defined(OPT_STRICT)
+ /*
+ * Scalefactor index 63 does not appear in Table B.1 of
+ * ISO/IEC 11172-3. Nonetheless, other implementations accept it,
+ * so we only reject it if OPT_STRICT is defined.
+ */
+ if (scalefactor[ch][sb] == 63) {
+ stream->error = MAD_ERROR_BADSCALEFACTOR;
+ return -1;
+ }
+# endif
+ }
+ }
+ }
+
+ /* decode samples */
+
+ for (s = 0; s < 12; ++s) {
+ for (sb = 0; sb < bound; ++sb) {
+ for (ch = 0; ch < nch; ++ch) {
+ nb = allocation[ch][sb];
+ frame->sbsample[ch][s][sb] = nb ?
+ mad_f_mul(I_sample(&stream->ptr, nb),
+ sf_table[scalefactor[ch][sb]]) : 0;
+ }
+ }
+
+ for (sb = bound; sb < 32; ++sb) {
+ if ((nb = allocation[0][sb])) {
+ mad_fixed_t sample;
+
+ sample = I_sample(&stream->ptr, nb);
+
+ for (ch = 0; ch < nch; ++ch) {
+ frame->sbsample[ch][s][sb] =
+ mad_f_mul(sample, sf_table[scalefactor[ch][sb]]);
+ }
+ }
+ else {
+ for (ch = 0; ch < nch; ++ch)
+ frame->sbsample[ch][s][sb] = 0;
+ }
+ }
+ }
+
+ return 0;
+}
+
+/* --- Layer II ------------------------------------------------------------ */
+
+/* possible quantization per subband table */
+static
+struct {
+ unsigned int sblimit;
+ unsigned char const offsets[30];
+} const sbquant_table[5] = {
+ /* ISO/IEC 11172-3 Table B.2a */
+ { 27, { 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 3, 3, 3, 3, 3, /* 0 */
+ 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0 } },
+ /* ISO/IEC 11172-3 Table B.2b */
+ { 30, { 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 3, 3, 3, 3, 3, /* 1 */
+ 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0 } },
+ /* ISO/IEC 11172-3 Table B.2c */
+ { 8, { 5, 5, 2, 2, 2, 2, 2, 2 } }, /* 2 */
+ /* ISO/IEC 11172-3 Table B.2d */
+ { 12, { 5, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 } }, /* 3 */
+ /* ISO/IEC 13818-3 Table B.1 */
+ { 30, { 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, /* 4 */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } }
+};
+
+/* bit allocation table */
+static
+struct {
+ unsigned short nbal;
+ unsigned short offset;
+} const bitalloc_table[8] = {
+ { 2, 0 }, /* 0 */
+ { 2, 3 }, /* 1 */
+ { 3, 3 }, /* 2 */
+ { 3, 1 }, /* 3 */
+ { 4, 2 }, /* 4 */
+ { 4, 3 }, /* 5 */
+ { 4, 4 }, /* 6 */
+ { 4, 5 } /* 7 */
+};
+
+/* offsets into quantization class table */
+static
+unsigned char const offset_table[6][15] = {
+ { 0, 1, 16 }, /* 0 */
+ { 0, 1, 2, 3, 4, 5, 16 }, /* 1 */
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }, /* 2 */
+ { 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, /* 3 */
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16 }, /* 4 */
+ { 0, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 } /* 5 */
+};
+
+/* quantization class table */
+static
+struct quantclass {
+ unsigned short nlevels;
+ unsigned char group;
+ unsigned char bits;
+ mad_fixed_t C;
+ mad_fixed_t D;
+} const qc_table[17] = {
+# include "qc_table.dat"
+};
+
+/*
+ * NAME: II_samples()
+ * DESCRIPTION: decode three requantized Layer II samples from a bitstream
+ */
+static
+void II_samples(struct mad_bitptr *ptr,
+ struct quantclass const *quantclass,
+ mad_fixed_t output[3])
+{
+ unsigned int nb, s, sample[3];
+
+ if ((nb = quantclass->group)) {
+ unsigned int c, nlevels;
+
+ /* degrouping */
+ c = mad_bit_read(ptr, quantclass->bits);
+ nlevels = quantclass->nlevels;
+
+ for (s = 0; s < 3; ++s) {
+ sample[s] = c % nlevels;
+ c /= nlevels;
+ }
+ }
+ else {
+ nb = quantclass->bits;
+
+ for (s = 0; s < 3; ++s)
+ sample[s] = mad_bit_read(ptr, nb);
+ }
+
+ for (s = 0; s < 3; ++s) {
+ mad_fixed_t requantized;
+
+ /* invert most significant bit, extend sign, then scale to fixed format */
+
+ requantized = sample[s] ^ (1 << (nb - 1));
+ requantized |= -(requantized & (1 << (nb - 1)));
+
+ requantized <<= MAD_F_FRACBITS - (nb - 1);
+
+ /* requantize the sample */
+
+ /* s'' = C * (s''' + D) */
+
+ output[s] = mad_f_mul(requantized + quantclass->D, quantclass->C);
+
+ /* s' = factor * s'' */
+ /* (to be performed by caller) */
+ }
+}
+
+/*
+ * NAME: layer->II()
+ * DESCRIPTION: decode a single Layer II frame
+ */
+int mad_layer_II(struct mad_stream *stream, struct mad_frame *frame)
+{
+ struct mad_header *header = &frame->header;
+ struct mad_bitptr start;
+ unsigned int index, sblimit, nbal, nch, bound, gr, ch, s, sb;
+ unsigned char const *offsets;
+ unsigned char allocation[2][32], scfsi[2][32], scalefactor[2][32][3];
+ mad_fixed_t samples[3];
+
+ nch = MAD_NCHANNELS(header);
+
+ if (header->flags & MAD_FLAG_LSF_EXT)
+ index = 4;
+ else if (header->flags & MAD_FLAG_FREEFORMAT)
+ goto freeformat;
+ else {
+ unsigned long bitrate_per_channel;
+
+ bitrate_per_channel = header->bitrate;
+ if (nch == 2) {
+ bitrate_per_channel /= 2;
+
+# if defined(OPT_STRICT)
+ /*
+ * ISO/IEC 11172-3 allows only single channel mode for 32, 48, 56, and
+ * 80 kbps bitrates in Layer II, but some encoders ignore this
+ * restriction. We enforce it if OPT_STRICT is defined.
+ */
+ if (bitrate_per_channel <= 28000 || bitrate_per_channel == 40000) {
+ stream->error = MAD_ERROR_BADMODE;
+ return -1;
+ }
+# endif
+ }
+ else { /* nch == 1 */
+ if (bitrate_per_channel > 192000) {
+ /*
+ * ISO/IEC 11172-3 does not allow single channel mode for 224, 256,
+ * 320, or 384 kbps bitrates in Layer II.
+ */
+ stream->error = MAD_ERROR_BADMODE;
+ return -1;
+ }
+ }
+
+ if (bitrate_per_channel <= 48000)
+ index = (header->samplerate == 32000) ? 3 : 2;
+ else if (bitrate_per_channel <= 80000)
+ index = 0;
+ else {
+ freeformat:
+ index = (header->samplerate == 48000) ? 0 : 1;
+ }
+ }
+
+ sblimit = sbquant_table[index].sblimit;
+ offsets = sbquant_table[index].offsets;
+
+ bound = 32;
+ if (header->mode == MAD_MODE_JOINT_STEREO) {
+ header->flags |= MAD_FLAG_I_STEREO;
+ bound = 4 + header->mode_extension * 4;
+ }
+
+ if (bound > sblimit)
+ bound = sblimit;
+
+ start = stream->ptr;
+
+ /* decode bit allocations */
+
+ for (sb = 0; sb < bound; ++sb) {
+ nbal = bitalloc_table[offsets[sb]].nbal;
+
+ for (ch = 0; ch < nch; ++ch)
+ allocation[ch][sb] = mad_bit_read(&stream->ptr, nbal);
+ }
+
+ for (sb = bound; sb < sblimit; ++sb) {
+ nbal = bitalloc_table[offsets[sb]].nbal;
+
+ allocation[0][sb] =
+ allocation[1][sb] = mad_bit_read(&stream->ptr, nbal);
+ }
+
+ /* decode scalefactor selection info */
+
+ for (sb = 0; sb < sblimit; ++sb) {
+ for (ch = 0; ch < nch; ++ch) {
+ if (allocation[ch][sb])
+ scfsi[ch][sb] = mad_bit_read(&stream->ptr, 2);
+ }
+ }
+
+ /* check CRC word */
+
+ if (header->flags & MAD_FLAG_PROTECTION) {
+ header->crc_check =
+ mad_bit_crc(start, mad_bit_length(&start, &stream->ptr),
+ header->crc_check);
+
+ if (header->crc_check != header->crc_target &&
+ !(frame->options & MAD_OPTION_IGNORECRC)) {
+ stream->error = MAD_ERROR_BADCRC;
+ return -1;
+ }
+ }
+
+ /* decode scalefactors */
+
+ for (sb = 0; sb < sblimit; ++sb) {
+ for (ch = 0; ch < nch; ++ch) {
+ if (allocation[ch][sb]) {
+ scalefactor[ch][sb][0] = mad_bit_read(&stream->ptr, 6);
+
+ switch (scfsi[ch][sb]) {
+ case 2:
+ scalefactor[ch][sb][2] =
+ scalefactor[ch][sb][1] =
+ scalefactor[ch][sb][0];
+ break;
+
+ case 0:
+ scalefactor[ch][sb][1] = mad_bit_read(&stream->ptr, 6);
+ /* fall through */
+
+ case 1:
+ case 3:
+ scalefactor[ch][sb][2] = mad_bit_read(&stream->ptr, 6);
+ }
+
+ if (scfsi[ch][sb] & 1)
+ scalefactor[ch][sb][1] = scalefactor[ch][sb][scfsi[ch][sb] - 1];
+
+# if defined(OPT_STRICT)
+ /*
+ * Scalefactor index 63 does not appear in Table B.1 of
+ * ISO/IEC 11172-3. Nonetheless, other implementations accept it,
+ * so we only reject it if OPT_STRICT is defined.
+ */
+ if (scalefactor[ch][sb][0] == 63 ||
+ scalefactor[ch][sb][1] == 63 ||
+ scalefactor[ch][sb][2] == 63) {
+ stream->error = MAD_ERROR_BADSCALEFACTOR;
+ return -1;
+ }
+# endif
+ }
+ }
+ }
+
+ /* decode samples */
+
+ for (gr = 0; gr < 12; ++gr) {
+ for (sb = 0; sb < bound; ++sb) {
+ for (ch = 0; ch < nch; ++ch) {
+ if ((index = allocation[ch][sb])) {
+ index = offset_table[bitalloc_table[offsets[sb]].offset][index - 1];
+
+ II_samples(&stream->ptr, &qc_table[index], samples);
+
+ for (s = 0; s < 3; ++s) {
+ frame->sbsample[ch][3 * gr + s][sb] =
+ mad_f_mul(samples[s], sf_table[scalefactor[ch][sb][gr / 4]]);
+ }
+ }
+ else {
+ for (s = 0; s < 3; ++s)
+ frame->sbsample[ch][3 * gr + s][sb] = 0;
+ }
+ }
+ }
+
+ for (sb = bound; sb < sblimit; ++sb) {
+ if ((index = allocation[0][sb])) {
+ index = offset_table[bitalloc_table[offsets[sb]].offset][index - 1];
+
+ II_samples(&stream->ptr, &qc_table[index], samples);
+
+ for (ch = 0; ch < nch; ++ch) {
+ for (s = 0; s < 3; ++s) {
+ frame->sbsample[ch][3 * gr + s][sb] =
+ mad_f_mul(samples[s], sf_table[scalefactor[ch][sb][gr / 4]]);
+ }
+ }
+ }
+ else {
+ for (ch = 0; ch < nch; ++ch) {
+ for (s = 0; s < 3; ++s)
+ frame->sbsample[ch][3 * gr + s][sb] = 0;
+ }
+ }
+ }
+
+ for (ch = 0; ch < nch; ++ch) {
+ for (s = 0; s < 3; ++s) {
+ for (sb = sblimit; sb < 32; ++sb)
+ frame->sbsample[ch][3 * gr + s][sb] = 0;
+ }
+ }
+ }
+
+ return 0;
+}
diff --git a/contrib/libmad/layer12.h b/contrib/libmad/layer12.h
new file mode 100644
index 000000000..e1c499696
--- /dev/null
+++ b/contrib/libmad/layer12.h
@@ -0,0 +1,31 @@
+/*
+ * libmad - MPEG audio decoder library
+ * Copyright (C) 2000-2004 Underbit Technologies, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: layer12.h,v 1.10 2004/01/23 09:41:32 rob Exp $
+ */
+
+# ifndef LIBMAD_LAYER12_H
+# define LIBMAD_LAYER12_H
+
+# include "stream.h"
+# include "frame.h"
+
+int mad_layer_I(struct mad_stream *, struct mad_frame *);
+int mad_layer_II(struct mad_stream *, struct mad_frame *);
+
+# endif
diff --git a/contrib/libmad/layer3.c b/contrib/libmad/layer3.c
new file mode 100644
index 000000000..4e5d3fa02
--- /dev/null
+++ b/contrib/libmad/layer3.c
@@ -0,0 +1,2698 @@
+/*
+ * libmad - MPEG audio decoder library
+ * Copyright (C) 2000-2004 Underbit Technologies, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: layer3.c,v 1.43 2004/01/23 09:41:32 rob Exp $
+ */
+
+# ifdef HAVE_CONFIG_H
+# include "config.h"
+# endif
+
+# include "global.h"
+
+# include <stdlib.h>
+# include <string.h>
+
+# ifdef HAVE_ASSERT_H
+# include <assert.h>
+# endif
+
+# ifdef HAVE_LIMITS_H
+# include <limits.h>
+# else
+# define CHAR_BIT 8
+# endif
+
+# include "fixed.h"
+# include "bit.h"
+# include "stream.h"
+# include "frame.h"
+# include "huffman.h"
+# include "layer3.h"
+
+/* --- Layer III ----------------------------------------------------------- */
+
+enum {
+ count1table_select = 0x01,
+ scalefac_scale = 0x02,
+ preflag = 0x04,
+ mixed_block_flag = 0x08
+};
+
+enum {
+ I_STEREO = 0x1,
+ MS_STEREO = 0x2
+};
+
+struct sideinfo {
+ unsigned int main_data_begin;
+ unsigned int private_bits;
+
+ unsigned char scfsi[2];
+
+ struct granule {
+ struct channel {
+ /* from side info */
+ unsigned short part2_3_length;
+ unsigned short big_values;
+ unsigned short global_gain;
+ unsigned short scalefac_compress;
+
+ unsigned char flags;
+ unsigned char block_type;
+ unsigned char table_select[3];
+ unsigned char subblock_gain[3];
+ unsigned char region0_count;
+ unsigned char region1_count;
+
+ /* from main_data */
+ unsigned char scalefac[39]; /* scalefac_l and/or scalefac_s */
+ } ch[2];
+ } gr[2];
+};
+
+/*
+ * scalefactor bit lengths
+ * derived from section 2.4.2.7 of ISO/IEC 11172-3
+ */
+static
+struct {
+ unsigned char slen1;
+ unsigned char slen2;
+} const sflen_table[16] = {
+ { 0, 0 }, { 0, 1 }, { 0, 2 }, { 0, 3 },
+ { 3, 0 }, { 1, 1 }, { 1, 2 }, { 1, 3 },
+ { 2, 1 }, { 2, 2 }, { 2, 3 }, { 3, 1 },
+ { 3, 2 }, { 3, 3 }, { 4, 2 }, { 4, 3 }
+};
+
+/*
+ * number of LSF scalefactor band values
+ * derived from section 2.4.3.2 of ISO/IEC 13818-3
+ */
+static
+unsigned char const nsfb_table[6][3][4] = {
+ { { 6, 5, 5, 5 },
+ { 9, 9, 9, 9 },
+ { 6, 9, 9, 9 } },
+
+ { { 6, 5, 7, 3 },
+ { 9, 9, 12, 6 },
+ { 6, 9, 12, 6 } },
+
+ { { 11, 10, 0, 0 },
+ { 18, 18, 0, 0 },
+ { 15, 18, 0, 0 } },
+
+ { { 7, 7, 7, 0 },
+ { 12, 12, 12, 0 },
+ { 6, 15, 12, 0 } },
+
+ { { 6, 6, 6, 3 },
+ { 12, 9, 9, 6 },
+ { 6, 12, 9, 6 } },
+
+ { { 8, 8, 5, 0 },
+ { 15, 12, 9, 0 },
+ { 6, 18, 9, 0 } }
+};
+
+/*
+ * MPEG-1 scalefactor band widths
+ * derived from Table B.8 of ISO/IEC 11172-3
+ */
+static
+unsigned char const sfb_48000_long[] = {
+ 4, 4, 4, 4, 4, 4, 6, 6, 6, 8, 10,
+ 12, 16, 18, 22, 28, 34, 40, 46, 54, 54, 192
+};
+
+static
+unsigned char const sfb_44100_long[] = {
+ 4, 4, 4, 4, 4, 4, 6, 6, 8, 8, 10,
+ 12, 16, 20, 24, 28, 34, 42, 50, 54, 76, 158
+};
+
+static
+unsigned char const sfb_32000_long[] = {
+ 4, 4, 4, 4, 4, 4, 6, 6, 8, 10, 12,
+ 16, 20, 24, 30, 38, 46, 56, 68, 84, 102, 26
+};
+
+static
+unsigned char const sfb_48000_short[] = {
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6,
+ 6, 6, 6, 6, 6, 10, 10, 10, 12, 12, 12, 14, 14,
+ 14, 16, 16, 16, 20, 20, 20, 26, 26, 26, 66, 66, 66
+};
+
+static
+unsigned char const sfb_44100_short[] = {
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6,
+ 6, 6, 8, 8, 8, 10, 10, 10, 12, 12, 12, 14, 14,
+ 14, 18, 18, 18, 22, 22, 22, 30, 30, 30, 56, 56, 56
+};
+
+static
+unsigned char const sfb_32000_short[] = {
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6,
+ 6, 6, 8, 8, 8, 12, 12, 12, 16, 16, 16, 20, 20,
+ 20, 26, 26, 26, 34, 34, 34, 42, 42, 42, 12, 12, 12
+};
+
+static
+unsigned char const sfb_48000_mixed[] = {
+ /* long */ 4, 4, 4, 4, 4, 4, 6, 6,
+ /* short */ 4, 4, 4, 6, 6, 6, 6, 6, 6, 10,
+ 10, 10, 12, 12, 12, 14, 14, 14, 16, 16,
+ 16, 20, 20, 20, 26, 26, 26, 66, 66, 66
+};
+
+static
+unsigned char const sfb_44100_mixed[] = {
+ /* long */ 4, 4, 4, 4, 4, 4, 6, 6,
+ /* short */ 4, 4, 4, 6, 6, 6, 8, 8, 8, 10,
+ 10, 10, 12, 12, 12, 14, 14, 14, 18, 18,
+ 18, 22, 22, 22, 30, 30, 30, 56, 56, 56
+};
+
+static
+unsigned char const sfb_32000_mixed[] = {
+ /* long */ 4, 4, 4, 4, 4, 4, 6, 6,
+ /* short */ 4, 4, 4, 6, 6, 6, 8, 8, 8, 12,
+ 12, 12, 16, 16, 16, 20, 20, 20, 26, 26,
+ 26, 34, 34, 34, 42, 42, 42, 12, 12, 12
+};
+
+/*
+ * MPEG-2 scalefactor band widths
+ * derived from Table B.2 of ISO/IEC 13818-3
+ */
+static
+unsigned char const sfb_24000_long[] = {
+ 6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16,
+ 18, 22, 26, 32, 38, 46, 54, 62, 70, 76, 36
+};
+
+static
+unsigned char const sfb_22050_long[] = {
+ 6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16,
+ 20, 24, 28, 32, 38, 46, 52, 60, 68, 58, 54
+};
+
+# define sfb_16000_long sfb_22050_long
+
+static
+unsigned char const sfb_24000_short[] = {
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 8,
+ 8, 8, 10, 10, 10, 12, 12, 12, 14, 14, 14, 18, 18,
+ 18, 24, 24, 24, 32, 32, 32, 44, 44, 44, 12, 12, 12
+};
+
+static
+unsigned char const sfb_22050_short[] = {
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 6,
+ 6, 6, 8, 8, 8, 10, 10, 10, 14, 14, 14, 18, 18,
+ 18, 26, 26, 26, 32, 32, 32, 42, 42, 42, 18, 18, 18
+};
+
+static
+unsigned char const sfb_16000_short[] = {
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 8,
+ 8, 8, 10, 10, 10, 12, 12, 12, 14, 14, 14, 18, 18,
+ 18, 24, 24, 24, 30, 30, 30, 40, 40, 40, 18, 18, 18
+};
+
+static
+unsigned char const sfb_24000_mixed[] = {
+ /* long */ 6, 6, 6, 6, 6, 6,
+ /* short */ 6, 6, 6, 8, 8, 8, 10, 10, 10, 12,
+ 12, 12, 14, 14, 14, 18, 18, 18, 24, 24,
+ 24, 32, 32, 32, 44, 44, 44, 12, 12, 12
+};
+
+static
+unsigned char const sfb_22050_mixed[] = {
+ /* long */ 6, 6, 6, 6, 6, 6,
+ /* short */ 6, 6, 6, 6, 6, 6, 8, 8, 8, 10,
+ 10, 10, 14, 14, 14, 18, 18, 18, 26, 26,
+ 26, 32, 32, 32, 42, 42, 42, 18, 18, 18
+};
+
+static
+unsigned char const sfb_16000_mixed[] = {
+ /* long */ 6, 6, 6, 6, 6, 6,
+ /* short */ 6, 6, 6, 8, 8, 8, 10, 10, 10, 12,
+ 12, 12, 14, 14, 14, 18, 18, 18, 24, 24,
+ 24, 30, 30, 30, 40, 40, 40, 18, 18, 18
+};
+
+/*
+ * MPEG 2.5 scalefactor band widths
+ * derived from public sources
+ */
+# define sfb_12000_long sfb_16000_long
+# define sfb_11025_long sfb_12000_long
+
+static
+unsigned char const sfb_8000_long[] = {
+ 12, 12, 12, 12, 12, 12, 16, 20, 24, 28, 32,
+ 40, 48, 56, 64, 76, 90, 2, 2, 2, 2, 2
+};
+
+# define sfb_12000_short sfb_16000_short
+# define sfb_11025_short sfb_12000_short
+
+static
+unsigned char const sfb_8000_short[] = {
+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 12, 12, 12, 16,
+ 16, 16, 20, 20, 20, 24, 24, 24, 28, 28, 28, 36, 36,
+ 36, 2, 2, 2, 2, 2, 2, 2, 2, 2, 26, 26, 26
+};
+
+# define sfb_12000_mixed sfb_16000_mixed
+# define sfb_11025_mixed sfb_12000_mixed
+
+/* the 8000 Hz short block scalefactor bands do not break after
+ the first 36 frequency lines, so this is probably wrong */
+static
+unsigned char const sfb_8000_mixed[] = {
+ /* long */ 12, 12, 12,
+ /* short */ 4, 4, 4, 8, 8, 8, 12, 12, 12, 16, 16, 16,
+ 20, 20, 20, 24, 24, 24, 28, 28, 28, 36, 36, 36,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 26, 26, 26
+};
+
+static
+struct {
+ unsigned char const *l;
+ unsigned char const *s;
+ unsigned char const *m;
+} const sfbwidth_table[9] = {
+ { sfb_48000_long, sfb_48000_short, sfb_48000_mixed },
+ { sfb_44100_long, sfb_44100_short, sfb_44100_mixed },
+ { sfb_32000_long, sfb_32000_short, sfb_32000_mixed },
+ { sfb_24000_long, sfb_24000_short, sfb_24000_mixed },
+ { sfb_22050_long, sfb_22050_short, sfb_22050_mixed },
+ { sfb_16000_long, sfb_16000_short, sfb_16000_mixed },
+ { sfb_12000_long, sfb_12000_short, sfb_12000_mixed },
+ { sfb_11025_long, sfb_11025_short, sfb_11025_mixed },
+ { sfb_8000_long, sfb_8000_short, sfb_8000_mixed }
+};
+
+/*
+ * scalefactor band preemphasis (used only when preflag is set)
+ * derived from Table B.6 of ISO/IEC 11172-3
+ */
+static
+unsigned char const pretab[22] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 2, 0
+};
+
+/*
+ * table for requantization
+ *
+ * rq_table[x].mantissa * 2^(rq_table[x].exponent) = x^(4/3)
+ */
+static
+struct fixedfloat {
+ unsigned long mantissa : 27;
+ unsigned short exponent : 5;
+} const rq_table[8207] = {
+# include "rq_table.dat"
+};
+
+/*
+ * fractional powers of two
+ * used for requantization and joint stereo decoding
+ *
+ * root_table[3 + x] = 2^(x/4)
+ */
+static
+mad_fixed_t const root_table[7] = {
+ MAD_F(0x09837f05) /* 2^(-3/4) == 0.59460355750136 */,
+ MAD_F(0x0b504f33) /* 2^(-2/4) == 0.70710678118655 */,
+ MAD_F(0x0d744fcd) /* 2^(-1/4) == 0.84089641525371 */,
+ MAD_F(0x10000000) /* 2^( 0/4) == 1.00000000000000 */,
+ MAD_F(0x1306fe0a) /* 2^(+1/4) == 1.18920711500272 */,
+ MAD_F(0x16a09e66) /* 2^(+2/4) == 1.41421356237310 */,
+ MAD_F(0x1ae89f99) /* 2^(+3/4) == 1.68179283050743 */
+};
+
+/*
+ * coefficients for aliasing reduction
+ * derived from Table B.9 of ISO/IEC 11172-3
+ *
+ * c[] = { -0.6, -0.535, -0.33, -0.185, -0.095, -0.041, -0.0142, -0.0037 }
+ * cs[i] = 1 / sqrt(1 + c[i]^2)
+ * ca[i] = c[i] / sqrt(1 + c[i]^2)
+ */
+static
+mad_fixed_t const cs[8] = {
+ +MAD_F(0x0db84a81) /* +0.857492926 */, +MAD_F(0x0e1b9d7f) /* +0.881741997 */,
+ +MAD_F(0x0f31adcf) /* +0.949628649 */, +MAD_F(0x0fbba815) /* +0.983314592 */,
+ +MAD_F(0x0feda417) /* +0.995517816 */, +MAD_F(0x0ffc8fc8) /* +0.999160558 */,
+ +MAD_F(0x0fff964c) /* +0.999899195 */, +MAD_F(0x0ffff8d3) /* +0.999993155 */
+};
+
+static
+mad_fixed_t const ca[8] = {
+ -MAD_F(0x083b5fe7) /* -0.514495755 */, -MAD_F(0x078c36d2) /* -0.471731969 */,
+ -MAD_F(0x05039814) /* -0.313377454 */, -MAD_F(0x02e91dd1) /* -0.181913200 */,
+ -MAD_F(0x0183603a) /* -0.094574193 */, -MAD_F(0x00a7cb87) /* -0.040965583 */,
+ -MAD_F(0x003a2847) /* -0.014198569 */, -MAD_F(0x000f27b4) /* -0.003699975 */
+};
+
+/*
+ * IMDCT coefficients for short blocks
+ * derived from section 2.4.3.4.10.2 of ISO/IEC 11172-3
+ *
+ * imdct_s[i/even][k] = cos((PI / 24) * (2 * (i / 2) + 7) * (2 * k + 1))
+ * imdct_s[i /odd][k] = cos((PI / 24) * (2 * (6 + (i-1)/2) + 7) * (2 * k + 1))
+ */
+static
+mad_fixed_t const imdct_s[6][6] = {
+# include "imdct_s.dat"
+};
+
+# if !defined(ASO_IMDCT)
+/*
+ * windowing coefficients for long blocks
+ * derived from section 2.4.3.4.10.3 of ISO/IEC 11172-3
+ *
+ * window_l[i] = sin((PI / 36) * (i + 1/2))
+ */
+static
+mad_fixed_t const window_l[36] = {
+ MAD_F(0x00b2aa3e) /* 0.043619387 */, MAD_F(0x0216a2a2) /* 0.130526192 */,
+ MAD_F(0x03768962) /* 0.216439614 */, MAD_F(0x04cfb0e2) /* 0.300705800 */,
+ MAD_F(0x061f78aa) /* 0.382683432 */, MAD_F(0x07635284) /* 0.461748613 */,
+ MAD_F(0x0898c779) /* 0.537299608 */, MAD_F(0x09bd7ca0) /* 0.608761429 */,
+ MAD_F(0x0acf37ad) /* 0.675590208 */, MAD_F(0x0bcbe352) /* 0.737277337 */,
+ MAD_F(0x0cb19346) /* 0.793353340 */, MAD_F(0x0d7e8807) /* 0.843391446 */,
+
+ MAD_F(0x0e313245) /* 0.887010833 */, MAD_F(0x0ec835e8) /* 0.923879533 */,
+ MAD_F(0x0f426cb5) /* 0.953716951 */, MAD_F(0x0f9ee890) /* 0.976296007 */,
+ MAD_F(0x0fdcf549) /* 0.991444861 */, MAD_F(0x0ffc19fd) /* 0.999048222 */,
+ MAD_F(0x0ffc19fd) /* 0.999048222 */, MAD_F(0x0fdcf549) /* 0.991444861 */,
+ MAD_F(0x0f9ee890) /* 0.976296007 */, MAD_F(0x0f426cb5) /* 0.953716951 */,
+ MAD_F(0x0ec835e8) /* 0.923879533 */, MAD_F(0x0e313245) /* 0.887010833 */,
+
+ MAD_F(0x0d7e8807) /* 0.843391446 */, MAD_F(0x0cb19346) /* 0.793353340 */,
+ MAD_F(0x0bcbe352) /* 0.737277337 */, MAD_F(0x0acf37ad) /* 0.675590208 */,
+ MAD_F(0x09bd7ca0) /* 0.608761429 */, MAD_F(0x0898c779) /* 0.537299608 */,
+ MAD_F(0x07635284) /* 0.461748613 */, MAD_F(0x061f78aa) /* 0.382683432 */,
+ MAD_F(0x04cfb0e2) /* 0.300705800 */, MAD_F(0x03768962) /* 0.216439614 */,
+ MAD_F(0x0216a2a2) /* 0.130526192 */, MAD_F(0x00b2aa3e) /* 0.043619387 */,
+};
+# endif /* ASO_IMDCT */
+
+/*
+ * windowing coefficients for short blocks
+ * derived from section 2.4.3.4.10.3 of ISO/IEC 11172-3
+ *
+ * window_s[i] = sin((PI / 12) * (i + 1/2))
+ */
+static
+mad_fixed_t const window_s[12] = {
+ MAD_F(0x0216a2a2) /* 0.130526192 */, MAD_F(0x061f78aa) /* 0.382683432 */,
+ MAD_F(0x09bd7ca0) /* 0.608761429 */, MAD_F(0x0cb19346) /* 0.793353340 */,
+ MAD_F(0x0ec835e8) /* 0.923879533 */, MAD_F(0x0fdcf549) /* 0.991444861 */,
+ MAD_F(0x0fdcf549) /* 0.991444861 */, MAD_F(0x0ec835e8) /* 0.923879533 */,
+ MAD_F(0x0cb19346) /* 0.793353340 */, MAD_F(0x09bd7ca0) /* 0.608761429 */,
+ MAD_F(0x061f78aa) /* 0.382683432 */, MAD_F(0x0216a2a2) /* 0.130526192 */,
+};
+
+/*
+ * coefficients for intensity stereo processing
+ * derived from section 2.4.3.4.9.3 of ISO/IEC 11172-3
+ *
+ * is_ratio[i] = tan(i * (PI / 12))
+ * is_table[i] = is_ratio[i] / (1 + is_ratio[i])
+ */
+static
+mad_fixed_t const is_table[7] = {
+ MAD_F(0x00000000) /* 0.000000000 */,
+ MAD_F(0x0361962f) /* 0.211324865 */,
+ MAD_F(0x05db3d74) /* 0.366025404 */,
+ MAD_F(0x08000000) /* 0.500000000 */,
+ MAD_F(0x0a24c28c) /* 0.633974596 */,
+ MAD_F(0x0c9e69d1) /* 0.788675135 */,
+ MAD_F(0x10000000) /* 1.000000000 */
+};
+
+/*
+ * coefficients for LSF intensity stereo processing
+ * derived from section 2.4.3.2 of ISO/IEC 13818-3
+ *
+ * is_lsf_table[0][i] = (1 / sqrt(sqrt(2)))^(i + 1)
+ * is_lsf_table[1][i] = (1 / sqrt(2)) ^(i + 1)
+ */
+static
+mad_fixed_t const is_lsf_table[2][15] = {
+ {
+ MAD_F(0x0d744fcd) /* 0.840896415 */,
+ MAD_F(0x0b504f33) /* 0.707106781 */,
+ MAD_F(0x09837f05) /* 0.594603558 */,
+ MAD_F(0x08000000) /* 0.500000000 */,
+ MAD_F(0x06ba27e6) /* 0.420448208 */,
+ MAD_F(0x05a8279a) /* 0.353553391 */,
+ MAD_F(0x04c1bf83) /* 0.297301779 */,
+ MAD_F(0x04000000) /* 0.250000000 */,
+ MAD_F(0x035d13f3) /* 0.210224104 */,
+ MAD_F(0x02d413cd) /* 0.176776695 */,
+ MAD_F(0x0260dfc1) /* 0.148650889 */,
+ MAD_F(0x02000000) /* 0.125000000 */,
+ MAD_F(0x01ae89fa) /* 0.105112052 */,
+ MAD_F(0x016a09e6) /* 0.088388348 */,
+ MAD_F(0x01306fe1) /* 0.074325445 */
+ }, {
+ MAD_F(0x0b504f33) /* 0.707106781 */,
+ MAD_F(0x08000000) /* 0.500000000 */,
+ MAD_F(0x05a8279a) /* 0.353553391 */,
+ MAD_F(0x04000000) /* 0.250000000 */,
+ MAD_F(0x02d413cd) /* 0.176776695 */,
+ MAD_F(0x02000000) /* 0.125000000 */,
+ MAD_F(0x016a09e6) /* 0.088388348 */,
+ MAD_F(0x01000000) /* 0.062500000 */,
+ MAD_F(0x00b504f3) /* 0.044194174 */,
+ MAD_F(0x00800000) /* 0.031250000 */,
+ MAD_F(0x005a827a) /* 0.022097087 */,
+ MAD_F(0x00400000) /* 0.015625000 */,
+ MAD_F(0x002d413d) /* 0.011048543 */,
+ MAD_F(0x00200000) /* 0.007812500 */,
+ MAD_F(0x0016a09e) /* 0.005524272 */
+ }
+};
+
+/*
+ * NAME: III_sideinfo()
+ * DESCRIPTION: decode frame side information from a bitstream
+ */
+static
+enum mad_error III_sideinfo(struct mad_bitptr *ptr, unsigned int nch,
+ int lsf, struct sideinfo *si,
+ unsigned int *data_bitlen,
+ unsigned int *priv_bitlen)
+{
+ unsigned int ngr, gr, ch, i;
+ enum mad_error result = MAD_ERROR_NONE;
+
+ *data_bitlen = 0;
+ *priv_bitlen = lsf ? ((nch == 1) ? 1 : 2) : ((nch == 1) ? 5 : 3);
+
+ si->main_data_begin = mad_bit_read(ptr, lsf ? 8 : 9);
+ si->private_bits = mad_bit_read(ptr, *priv_bitlen);
+
+ ngr = 1;
+ if (!lsf) {
+ ngr = 2;
+
+ for (ch = 0; ch < nch; ++ch)
+ si->scfsi[ch] = mad_bit_read(ptr, 4);
+ }
+
+ for (gr = 0; gr < ngr; ++gr) {
+ struct granule *granule = &si->gr[gr];
+
+ for (ch = 0; ch < nch; ++ch) {
+ struct channel *channel = &granule->ch[ch];
+
+ channel->part2_3_length = mad_bit_read(ptr, 12);
+ channel->big_values = mad_bit_read(ptr, 9);
+ channel->global_gain = mad_bit_read(ptr, 8);
+ channel->scalefac_compress = mad_bit_read(ptr, lsf ? 9 : 4);
+
+ *data_bitlen += channel->part2_3_length;
+
+ if (channel->big_values > 288 && result == 0)
+ result = MAD_ERROR_BADBIGVALUES;
+
+ channel->flags = 0;
+
+ /* window_switching_flag */
+ if (mad_bit_read(ptr, 1)) {
+ channel->block_type = mad_bit_read(ptr, 2);
+
+ if (channel->block_type == 0 && result == 0)
+ result = MAD_ERROR_BADBLOCKTYPE;
+
+ if (!lsf && channel->block_type == 2 && si->scfsi[ch] && result == 0)
+ result = MAD_ERROR_BADSCFSI;
+
+ channel->region0_count = 7;
+ channel->region1_count = 36;
+
+ if (mad_bit_read(ptr, 1))
+ channel->flags |= mixed_block_flag;
+ else if (channel->block_type == 2)
+ channel->region0_count = 8;
+
+ for (i = 0; i < 2; ++i)
+ channel->table_select[i] = mad_bit_read(ptr, 5);
+
+# if defined(DEBUG)
+ channel->table_select[2] = 4; /* not used */
+# endif
+
+ for (i = 0; i < 3; ++i)
+ channel->subblock_gain[i] = mad_bit_read(ptr, 3);
+ }
+ else {
+ channel->block_type = 0;
+
+ for (i = 0; i < 3; ++i)
+ channel->table_select[i] = mad_bit_read(ptr, 5);
+
+ channel->region0_count = mad_bit_read(ptr, 4);
+ channel->region1_count = mad_bit_read(ptr, 3);
+ }
+
+ /* [preflag,] scalefac_scale, count1table_select */
+ channel->flags |= mad_bit_read(ptr, lsf ? 2 : 3);
+ }
+ }
+
+ return result;
+}
+
+/*
+ * NAME: III_scalefactors_lsf()
+ * DESCRIPTION: decode channel scalefactors for LSF from a bitstream
+ */
+static
+unsigned int III_scalefactors_lsf(struct mad_bitptr *ptr,
+ struct channel *channel,
+ struct channel *gr1ch, int mode_extension)
+{
+ struct mad_bitptr start;
+ unsigned int scalefac_compress, index, slen[4], part, n, i;
+ unsigned char const *nsfb;
+
+ start = *ptr;
+
+ scalefac_compress = channel->scalefac_compress;
+ index = (channel->block_type == 2) ?
+ ((channel->flags & mixed_block_flag) ? 2 : 1) : 0;
+
+ if (!((mode_extension & I_STEREO) && gr1ch)) {
+ if (scalefac_compress < 400) {
+ slen[0] = (scalefac_compress >> 4) / 5;
+ slen[1] = (scalefac_compress >> 4) % 5;
+ slen[2] = (scalefac_compress % 16) >> 2;
+ slen[3] = scalefac_compress % 4;
+
+ nsfb = nsfb_table[0][index];
+ }
+ else if (scalefac_compress < 500) {
+ scalefac_compress -= 400;
+
+ slen[0] = (scalefac_compress >> 2) / 5;
+ slen[1] = (scalefac_compress >> 2) % 5;
+ slen[2] = scalefac_compress % 4;
+ slen[3] = 0;
+
+ nsfb = nsfb_table[1][index];
+ }
+ else {
+ scalefac_compress -= 500;
+
+ slen[0] = scalefac_compress / 3;
+ slen[1] = scalefac_compress % 3;
+ slen[2] = 0;
+ slen[3] = 0;
+
+ channel->flags |= preflag;
+
+ nsfb = nsfb_table[2][index];
+ }
+
+ n = 0;
+ for (part = 0; part < 4; ++part) {
+ for (i = 0; i < nsfb[part]; ++i)
+ channel->scalefac[n++] = mad_bit_read(ptr, slen[part]);
+ }
+
+ while (n < 39)
+ channel->scalefac[n++] = 0;
+ }
+ else { /* (mode_extension & I_STEREO) && gr1ch (i.e. ch == 1) */
+ scalefac_compress >>= 1;
+
+ if (scalefac_compress < 180) {
+ slen[0] = scalefac_compress / 36;
+ slen[1] = (scalefac_compress % 36) / 6;
+ slen[2] = (scalefac_compress % 36) % 6;
+ slen[3] = 0;
+
+ nsfb = nsfb_table[3][index];
+ }
+ else if (scalefac_compress < 244) {
+ scalefac_compress -= 180;
+
+ slen[0] = (scalefac_compress % 64) >> 4;
+ slen[1] = (scalefac_compress % 16) >> 2;
+ slen[2] = scalefac_compress % 4;
+ slen[3] = 0;
+
+ nsfb = nsfb_table[4][index];
+ }
+ else {
+ scalefac_compress -= 244;
+
+ slen[0] = scalefac_compress / 3;
+ slen[1] = scalefac_compress % 3;
+ slen[2] = 0;
+ slen[3] = 0;
+
+ nsfb = nsfb_table[5][index];
+ }
+
+ n = 0;
+ for (part = 0; part < 4; ++part) {
+ unsigned int max, is_pos;
+
+ max = (1 << slen[part]) - 1;
+
+ for (i = 0; i < nsfb[part]; ++i) {
+ is_pos = mad_bit_read(ptr, slen[part]);
+
+ channel->scalefac[n] = is_pos;
+ gr1ch->scalefac[n++] = (is_pos == max);
+ }
+ }
+
+ while (n < 39) {
+ channel->scalefac[n] = 0;
+ gr1ch->scalefac[n++] = 0; /* apparently not illegal */
+ }
+ }
+
+ return mad_bit_length(&start, ptr);
+}
+
+/*
+ * NAME: III_scalefactors()
+ * DESCRIPTION: decode channel scalefactors of one granule from a bitstream
+ */
+static
+unsigned int III_scalefactors(struct mad_bitptr *ptr, struct channel *channel,
+ struct channel const *gr0ch, unsigned int scfsi)
+{
+ struct mad_bitptr start;
+ unsigned int slen1, slen2, sfbi;
+
+ start = *ptr;
+
+ slen1 = sflen_table[channel->scalefac_compress].slen1;
+ slen2 = sflen_table[channel->scalefac_compress].slen2;
+
+ if (channel->block_type == 2) {
+ unsigned int nsfb;
+
+ sfbi = 0;
+
+ nsfb = (channel->flags & mixed_block_flag) ? 8 + 3 * 3 : 6 * 3;
+ while (nsfb--)
+ channel->scalefac[sfbi++] = mad_bit_read(ptr, slen1);
+
+ nsfb = 6 * 3;
+ while (nsfb--)
+ channel->scalefac[sfbi++] = mad_bit_read(ptr, slen2);
+
+ nsfb = 1 * 3;
+ while (nsfb--)
+ channel->scalefac[sfbi++] = 0;
+ }
+ else { /* channel->block_type != 2 */
+ if (scfsi & 0x8) {
+ for (sfbi = 0; sfbi < 6; ++sfbi)
+ channel->scalefac[sfbi] = gr0ch->scalefac[sfbi];
+ }
+ else {
+ for (sfbi = 0; sfbi < 6; ++sfbi)
+ channel->scalefac[sfbi] = mad_bit_read(ptr, slen1);
+ }
+
+ if (scfsi & 0x4) {
+ for (sfbi = 6; sfbi < 11; ++sfbi)
+ channel->scalefac[sfbi] = gr0ch->scalefac[sfbi];
+ }
+ else {
+ for (sfbi = 6; sfbi < 11; ++sfbi)
+ channel->scalefac[sfbi] = mad_bit_read(ptr, slen1);
+ }
+
+ if (scfsi & 0x2) {
+ for (sfbi = 11; sfbi < 16; ++sfbi)
+ channel->scalefac[sfbi] = gr0ch->scalefac[sfbi];
+ }
+ else {
+ for (sfbi = 11; sfbi < 16; ++sfbi)
+ channel->scalefac[sfbi] = mad_bit_read(ptr, slen2);
+ }
+
+ if (scfsi & 0x1) {
+ for (sfbi = 16; sfbi < 21; ++sfbi)
+ channel->scalefac[sfbi] = gr0ch->scalefac[sfbi];
+ }
+ else {
+ for (sfbi = 16; sfbi < 21; ++sfbi)
+ channel->scalefac[sfbi] = mad_bit_read(ptr, slen2);
+ }
+
+ channel->scalefac[21] = 0;
+ }
+
+ return mad_bit_length(&start, ptr);
+}
+
+/*
+ * The Layer III formula for requantization and scaling is defined by
+ * section 2.4.3.4.7.1 of ISO/IEC 11172-3, as follows:
+ *
+ * long blocks:
+ * xr[i] = sign(is[i]) * abs(is[i])^(4/3) *
+ * 2^((1/4) * (global_gain - 210)) *
+ * 2^-(scalefac_multiplier *
+ * (scalefac_l[sfb] + preflag * pretab[sfb]))
+ *
+ * short blocks:
+ * xr[i] = sign(is[i]) * abs(is[i])^(4/3) *
+ * 2^((1/4) * (global_gain - 210 - 8 * subblock_gain[w])) *
+ * 2^-(scalefac_multiplier * scalefac_s[sfb][w])
+ *
+ * where:
+ * scalefac_multiplier = (scalefac_scale + 1) / 2
+ *
+ * The routines III_exponents() and III_requantize() facilitate this
+ * calculation.
+ */
+
+/*
+ * NAME: III_exponents()
+ * DESCRIPTION: calculate scalefactor exponents
+ */
+static
+void III_exponents(struct channel const *channel,
+ unsigned char const *sfbwidth, signed int exponents[39])
+{
+ signed int gain;
+ unsigned int scalefac_multiplier, sfbi;
+
+ gain = (signed int) channel->global_gain - 210;
+ scalefac_multiplier = (channel->flags & scalefac_scale) ? 2 : 1;
+
+ if (channel->block_type == 2) {
+ unsigned int l;
+ signed int gain0, gain1, gain2;
+
+ sfbi = l = 0;
+
+ if (channel->flags & mixed_block_flag) {
+ unsigned int premask;
+
+ premask = (channel->flags & preflag) ? ~0 : 0;
+
+ /* long block subbands 0-1 */
+
+ while (l < 36) {
+ exponents[sfbi] = gain -
+ (signed int) ((channel->scalefac[sfbi] + (pretab[sfbi] & premask)) <<
+ scalefac_multiplier);
+
+ l += sfbwidth[sfbi++];
+ }
+ }
+
+ /* this is probably wrong for 8000 Hz short/mixed blocks */
+
+ gain0 = gain - 8 * (signed int) channel->subblock_gain[0];
+ gain1 = gain - 8 * (signed int) channel->subblock_gain[1];
+ gain2 = gain - 8 * (signed int) channel->subblock_gain[2];
+
+ while (l < 576) {
+ exponents[sfbi + 0] = gain0 -
+ (signed int) (channel->scalefac[sfbi + 0] << scalefac_multiplier);
+ exponents[sfbi + 1] = gain1 -
+ (signed int) (channel->scalefac[sfbi + 1] << scalefac_multiplier);
+ exponents[sfbi + 2] = gain2 -
+ (signed int) (channel->scalefac[sfbi + 2] << scalefac_multiplier);
+
+ l += 3 * sfbwidth[sfbi];
+ sfbi += 3;
+ }
+ }
+ else { /* channel->block_type != 2 */
+ if (channel->flags & preflag) {
+ for (sfbi = 0; sfbi < 22; ++sfbi) {
+ exponents[sfbi] = gain -
+ (signed int) ((channel->scalefac[sfbi] + pretab[sfbi]) <<
+ scalefac_multiplier);
+ }
+ }
+ else {
+ for (sfbi = 0; sfbi < 22; ++sfbi) {
+ exponents[sfbi] = gain -
+ (signed int) (channel->scalefac[sfbi] << scalefac_multiplier);
+ }
+ }
+ }
+}
+
+/*
+ * NAME: III_requantize()
+ * DESCRIPTION: requantize one (positive) value
+ */
+static
+mad_fixed_t III_requantize(unsigned int value, signed int exp)
+{
+ mad_fixed_t requantized;
+ signed int frac;
+ struct fixedfloat const *power;
+
+ frac = exp % 4; /* assumes sign(frac) == sign(exp) */
+ exp /= 4;
+
+ power = &rq_table[value];
+ requantized = power->mantissa;
+ exp += power->exponent;
+
+ if (exp < 0) {
+ if (-exp >= sizeof(mad_fixed_t) * CHAR_BIT) {
+ /* underflow */
+ requantized = 0;
+ }
+ else {
+ requantized += 1L << (-exp - 1);
+ requantized >>= -exp;
+ }
+ }
+ else {
+ if (exp >= 5) {
+ /* overflow */
+# if defined(DEBUG)
+ fprintf(stderr, "requantize overflow (%f * 2^%d)\n",
+ mad_f_todouble(requantized), exp);
+# endif
+ requantized = MAD_F_MAX;
+ }
+ else
+ requantized <<= exp;
+ }
+
+ return frac ? mad_f_mul(requantized, root_table[3 + frac]) : requantized;
+}
+
+/* we must take care that sz >= bits and sz < sizeof(long) lest bits == 0 */
+# define MASK(cache, sz, bits) \
+ (((cache) >> ((sz) - (bits))) & ((1 << (bits)) - 1))
+# define MASK1BIT(cache, sz) \
+ ((cache) & (1 << ((sz) - 1)))
+
+/*
+ * NAME: III_huffdecode()
+ * DESCRIPTION: decode Huffman code words of one channel of one granule
+ */
+static
+enum mad_error III_huffdecode(struct mad_bitptr *ptr, mad_fixed_t xr[576],
+ struct channel *channel,
+ unsigned char const *sfbwidth,
+ unsigned int part2_length)
+{
+ signed int exponents[39], exp;
+ signed int const *expptr;
+ struct mad_bitptr peek;
+ signed int bits_left, cachesz;
+ register mad_fixed_t *xrptr;
+ mad_fixed_t const *sfbound;
+ register unsigned long bitcache;
+
+ bits_left = (signed) channel->part2_3_length - (signed) part2_length;
+ if (bits_left < 0)
+ return MAD_ERROR_BADPART3LEN;
+
+ III_exponents(channel, sfbwidth, exponents);
+
+ peek = *ptr;
+ mad_bit_skip(ptr, bits_left);
+
+ /* align bit reads to byte boundaries */
+ cachesz = mad_bit_bitsleft(&peek);
+ cachesz += ((32 - 1 - 24) + (24 - cachesz)) & ~7;
+
+ bitcache = mad_bit_read(&peek, cachesz);
+ bits_left -= cachesz;
+
+ xrptr = &xr[0];
+
+ /* big_values */
+ {
+ unsigned int region, rcount;
+ struct hufftable const *entry;
+ union huffpair const *table;
+ unsigned int linbits, startbits, big_values, reqhits;
+ mad_fixed_t reqcache[16];
+
+ sfbound = xrptr + *sfbwidth++;
+ rcount = channel->region0_count + 1;
+
+ entry = &mad_huff_pair_table[channel->table_select[region = 0]];
+ table = entry->table;
+ linbits = entry->linbits;
+ startbits = entry->startbits;
+
+ if (table == 0)
+ return MAD_ERROR_BADHUFFTABLE;
+
+ expptr = &exponents[0];
+ exp = *expptr++;
+ reqhits = 0;
+
+ big_values = channel->big_values;
+
+ while (big_values-- && cachesz + bits_left > 0) {
+ union huffpair const *pair;
+ unsigned int clumpsz, value;
+ register mad_fixed_t requantized;
+
+ if (xrptr == sfbound) {
+ sfbound += *sfbwidth++;
+
+ /* change table if region boundary */
+
+ if (--rcount == 0) {
+ if (region == 0)
+ rcount = channel->region1_count + 1;
+ else
+ rcount = 0; /* all remaining */
+
+ entry = &mad_huff_pair_table[channel->table_select[++region]];
+ table = entry->table;
+ linbits = entry->linbits;
+ startbits = entry->startbits;
+
+ if (table == 0)
+ return MAD_ERROR_BADHUFFTABLE;
+ }
+
+ if (exp != *expptr) {
+ exp = *expptr;
+ reqhits = 0;
+ }
+
+ ++expptr;
+ }
+
+ if (cachesz < 21) {
+ unsigned int bits;
+
+ bits = ((32 - 1 - 21) + (21 - cachesz)) & ~7;
+ bitcache = (bitcache << bits) | mad_bit_read(&peek, bits);
+ cachesz += bits;
+ bits_left -= bits;
+ }
+
+ /* hcod (0..19) */
+
+ clumpsz = startbits;
+ pair = &table[MASK(bitcache, cachesz, clumpsz)];
+
+ while (!pair->final) {
+ cachesz -= clumpsz;
+
+ clumpsz = pair->ptr.bits;
+ pair = &table[pair->ptr.offset + MASK(bitcache, cachesz, clumpsz)];
+ }
+
+ cachesz -= pair->value.hlen;
+
+ if (linbits) {
+ /* x (0..14) */
+
+ value = pair->value.x;
+
+ switch (value) {
+ case 0:
+ xrptr[0] = 0;
+ break;
+
+ case 15:
+ if (cachesz < linbits + 2) {
+ bitcache = (bitcache << 16) | mad_bit_read(&peek, 16);
+ cachesz += 16;
+ bits_left -= 16;
+ }
+
+ value += MASK(bitcache, cachesz, linbits);
+ cachesz -= linbits;
+
+ requantized = III_requantize(value, exp);
+ goto x_final;
+
+ default:
+ if (reqhits & (1 << value))
+ requantized = reqcache[value];
+ else {
+ reqhits |= (1 << value);
+ requantized = reqcache[value] = III_requantize(value, exp);
+ }
+
+ x_final:
+ xrptr[0] = MASK1BIT(bitcache, cachesz--) ?
+ -requantized : requantized;
+ }
+
+ /* y (0..14) */
+
+ value = pair->value.y;
+
+ switch (value) {
+ case 0:
+ xrptr[1] = 0;
+ break;
+
+ case 15:
+ if (cachesz < linbits + 1) {
+ bitcache = (bitcache << 16) | mad_bit_read(&peek, 16);
+ cachesz += 16;
+ bits_left -= 16;
+ }
+
+ value += MASK(bitcache, cachesz, linbits);
+ cachesz -= linbits;
+
+ requantized = III_requantize(value, exp);
+ goto y_final;
+
+ default:
+ if (reqhits & (1 << value))
+ requantized = reqcache[value];
+ else {
+ reqhits |= (1 << value);
+ requantized = reqcache[value] = III_requantize(value, exp);
+ }
+
+ y_final:
+ xrptr[1] = MASK1BIT(bitcache, cachesz--) ?
+ -requantized : requantized;
+ }
+ }
+ else {
+ /* x (0..1) */
+
+ value = pair->value.x;
+
+ if (value == 0)
+ xrptr[0] = 0;
+ else {
+ if (reqhits & (1 << value))
+ requantized = reqcache[value];
+ else {
+ reqhits |= (1 << value);
+ requantized = reqcache[value] = III_requantize(value, exp);
+ }
+
+ xrptr[0] = MASK1BIT(bitcache, cachesz--) ?
+ -requantized : requantized;
+ }
+
+ /* y (0..1) */
+
+ value = pair->value.y;
+
+ if (value == 0)
+ xrptr[1] = 0;
+ else {
+ if (reqhits & (1 << value))
+ requantized = reqcache[value];
+ else {
+ reqhits |= (1 << value);
+ requantized = reqcache[value] = III_requantize(value, exp);
+ }
+
+ xrptr[1] = MASK1BIT(bitcache, cachesz--) ?
+ -requantized : requantized;
+ }
+ }
+
+ xrptr += 2;
+ }
+ }
+
+ if (cachesz + bits_left < 0)
+ return MAD_ERROR_BADHUFFDATA; /* big_values overrun */
+
+ /* count1 */
+ {
+ union huffquad const *table;
+ register mad_fixed_t requantized;
+
+ table = mad_huff_quad_table[channel->flags & count1table_select];
+
+ requantized = III_requantize(1, exp);
+
+ while (cachesz + bits_left > 0 && xrptr <= &xr[572]) {
+ union huffquad const *quad;
+
+ /* hcod (1..6) */
+
+ if (cachesz < 10) {
+ bitcache = (bitcache << 16) | mad_bit_read(&peek, 16);
+ cachesz += 16;
+ bits_left -= 16;
+ }
+
+ quad = &table[MASK(bitcache, cachesz, 4)];
+
+ /* quad tables guaranteed to have at most one extra lookup */
+ if (!quad->final) {
+ cachesz -= 4;
+
+ quad = &table[quad->ptr.offset +
+ MASK(bitcache, cachesz, quad->ptr.bits)];
+ }
+
+ cachesz -= quad->value.hlen;
+
+ if (xrptr == sfbound) {
+ sfbound += *sfbwidth++;
+
+ if (exp != *expptr) {
+ exp = *expptr;
+ requantized = III_requantize(1, exp);
+ }
+
+ ++expptr;
+ }
+
+ /* v (0..1) */
+
+ xrptr[0] = quad->value.v ?
+ (MASK1BIT(bitcache, cachesz--) ? -requantized : requantized) : 0;
+
+ /* w (0..1) */
+
+ xrptr[1] = quad->value.w ?
+ (MASK1BIT(bitcache, cachesz--) ? -requantized : requantized) : 0;
+
+ xrptr += 2;
+
+ if (xrptr == sfbound) {
+ sfbound += *sfbwidth++;
+
+ if (exp != *expptr) {
+ exp = *expptr;
+ requantized = III_requantize(1, exp);
+ }
+
+ ++expptr;
+ }
+
+ /* x (0..1) */
+
+ xrptr[0] = quad->value.x ?
+ (MASK1BIT(bitcache, cachesz--) ? -requantized : requantized) : 0;
+
+ /* y (0..1) */
+
+ xrptr[1] = quad->value.y ?
+ (MASK1BIT(bitcache, cachesz--) ? -requantized : requantized) : 0;
+
+ xrptr += 2;
+ }
+
+ if (cachesz + bits_left < 0) {
+# if 0 && defined(DEBUG)
+ fprintf(stderr, "huffman count1 overrun (%d bits)\n",
+ -(cachesz + bits_left));
+# endif
+
+ /* technically the bitstream is misformatted, but apparently
+ some encoders are just a bit sloppy with stuffing bits */
+
+ xrptr -= 4;
+ }
+ }
+
+ assert(-bits_left <= MAD_BUFFER_GUARD * CHAR_BIT);
+
+# if 0 && defined(DEBUG)
+ if (bits_left < 0)
+ fprintf(stderr, "read %d bits too many\n", -bits_left);
+ else if (cachesz + bits_left > 0)
+ fprintf(stderr, "%d stuffing bits\n", cachesz + bits_left);
+# endif
+
+ /* rzero */
+ while (xrptr < &xr[576]) {
+ xrptr[0] = 0;
+ xrptr[1] = 0;
+
+ xrptr += 2;
+ }
+
+ return MAD_ERROR_NONE;
+}
+
+# undef MASK
+# undef MASK1BIT
+
+/*
+ * NAME: III_reorder()
+ * DESCRIPTION: reorder frequency lines of a short block into subband order
+ */
+static
+void III_reorder(mad_fixed_t xr[576], struct channel const *channel,
+ unsigned char const sfbwidth[39])
+{
+ mad_fixed_t tmp[32][3][6];
+ unsigned int sb, l, f, w, sbw[3], sw[3];
+
+ /* this is probably wrong for 8000 Hz mixed blocks */
+
+ sb = 0;
+ if (channel->flags & mixed_block_flag) {
+ sb = 2;
+
+ l = 0;
+ while (l < 36)
+ l += *sfbwidth++;
+ }
+
+ for (w = 0; w < 3; ++w) {
+ sbw[w] = sb;
+ sw[w] = 0;
+ }
+
+ f = *sfbwidth++;
+ w = 0;
+
+ for (l = 18 * sb; l < 576; ++l) {
+ if (f-- == 0) {
+ f = *sfbwidth++ - 1;
+ w = (w + 1) % 3;
+ }
+
+ tmp[sbw[w]][w][sw[w]++] = xr[l];
+
+ if (sw[w] == 6) {
+ sw[w] = 0;
+ ++sbw[w];
+ }
+ }
+
+ memcpy(&xr[18 * sb], &tmp[sb], (576 - 18 * sb) * sizeof(mad_fixed_t));
+}
+
+/*
+ * NAME: III_stereo()
+ * DESCRIPTION: perform joint stereo processing on a granule
+ */
+static
+enum mad_error III_stereo(mad_fixed_t xr[2][576],
+ struct granule const *granule,
+ struct mad_header *header,
+ unsigned char const *sfbwidth)
+{
+ short modes[39];
+ unsigned int sfbi, l, n, i;
+
+ if (granule->ch[0].block_type !=
+ granule->ch[1].block_type ||
+ (granule->ch[0].flags & mixed_block_flag) !=
+ (granule->ch[1].flags & mixed_block_flag))
+ return MAD_ERROR_BADSTEREO;
+
+ for (i = 0; i < 39; ++i)
+ modes[i] = header->mode_extension;
+
+ /* intensity stereo */
+
+ if (header->mode_extension & I_STEREO) {
+ struct channel const *right_ch = &granule->ch[1];
+ mad_fixed_t const *right_xr = xr[1];
+ unsigned int is_pos;
+
+ header->flags |= MAD_FLAG_I_STEREO;
+
+ /* first determine which scalefactor bands are to be processed */
+
+ if (right_ch->block_type == 2) {
+ unsigned int lower, start, max, bound[3], w;
+
+ lower = start = max = bound[0] = bound[1] = bound[2] = 0;
+
+ sfbi = l = 0;
+
+ if (right_ch->flags & mixed_block_flag) {
+ while (l < 36) {
+ n = sfbwidth[sfbi++];
+
+ for (i = 0; i < n; ++i) {
+ if (right_xr[i]) {
+ lower = sfbi;
+ break;
+ }
+ }
+
+ right_xr += n;
+ l += n;
+ }
+
+ start = sfbi;
+ }
+
+ w = 0;
+ while (l < 576) {
+ n = sfbwidth[sfbi++];
+
+ for (i = 0; i < n; ++i) {
+ if (right_xr[i]) {
+ max = bound[w] = sfbi;
+ break;
+ }
+ }
+
+ right_xr += n;
+ l += n;
+ w = (w + 1) % 3;
+ }
+
+ if (max)
+ lower = start;
+
+ /* long blocks */
+
+ for (i = 0; i < lower; ++i)
+ modes[i] = header->mode_extension & ~I_STEREO;
+
+ /* short blocks */
+
+ w = 0;
+ for (i = start; i < max; ++i) {
+ if (i < bound[w])
+ modes[i] = header->mode_extension & ~I_STEREO;
+
+ w = (w + 1) % 3;
+ }
+ }
+ else { /* right_ch->block_type != 2 */
+ unsigned int bound;
+
+ bound = 0;
+ for (sfbi = l = 0; l < 576; l += n) {
+ n = sfbwidth[sfbi++];
+
+ for (i = 0; i < n; ++i) {
+ if (right_xr[i]) {
+ bound = sfbi;
+ break;
+ }
+ }
+
+ right_xr += n;
+ }
+
+ for (i = 0; i < bound; ++i)
+ modes[i] = header->mode_extension & ~I_STEREO;
+ }
+
+ /* now do the actual processing */
+
+ if (header->flags & MAD_FLAG_LSF_EXT) {
+ unsigned char const *illegal_pos = granule[1].ch[1].scalefac;
+ mad_fixed_t const *lsf_scale;
+
+ /* intensity_scale */
+ lsf_scale = is_lsf_table[right_ch->scalefac_compress & 0x1];
+
+ for (sfbi = l = 0; l < 576; ++sfbi, l += n) {
+ n = sfbwidth[sfbi];
+
+ if (!(modes[sfbi] & I_STEREO))
+ continue;
+
+ if (illegal_pos[sfbi]) {
+ modes[sfbi] &= ~I_STEREO;
+ continue;
+ }
+
+ is_pos = right_ch->scalefac[sfbi];
+
+ for (i = 0; i < n; ++i) {
+ register mad_fixed_t left;
+
+ left = xr[0][l + i];
+
+ if (is_pos == 0)
+ xr[1][l + i] = left;
+ else {
+ register mad_fixed_t opposite;
+
+ opposite = mad_f_mul(left, lsf_scale[(is_pos - 1) / 2]);
+
+ if (is_pos & 1) {
+ xr[0][l + i] = opposite;
+ xr[1][l + i] = left;
+ }
+ else
+ xr[1][l + i] = opposite;
+ }
+ }
+ }
+ }
+ else { /* !(header->flags & MAD_FLAG_LSF_EXT) */
+ for (sfbi = l = 0; l < 576; ++sfbi, l += n) {
+ n = sfbwidth[sfbi];
+
+ if (!(modes[sfbi] & I_STEREO))
+ continue;
+
+ is_pos = right_ch->scalefac[sfbi];
+
+ if (is_pos >= 7) { /* illegal intensity position */
+ modes[sfbi] &= ~I_STEREO;
+ continue;
+ }
+
+ for (i = 0; i < n; ++i) {
+ register mad_fixed_t left;
+
+ left = xr[0][l + i];
+
+ xr[0][l + i] = mad_f_mul(left, is_table[ is_pos]);
+ xr[1][l + i] = mad_f_mul(left, is_table[6 - is_pos]);
+ }
+ }
+ }
+ }
+
+ /* middle/side stereo */
+
+ if (header->mode_extension & MS_STEREO) {
+ register mad_fixed_t invsqrt2;
+
+ header->flags |= MAD_FLAG_MS_STEREO;
+
+ invsqrt2 = root_table[3 + -2];
+
+ for (sfbi = l = 0; l < 576; ++sfbi, l += n) {
+ n = sfbwidth[sfbi];
+
+ if (modes[sfbi] != MS_STEREO)
+ continue;
+
+ for (i = 0; i < n; ++i) {
+ register mad_fixed_t m, s;
+
+ m = xr[0][l + i];
+ s = xr[1][l + i];
+
+ xr[0][l + i] = mad_f_mul(m + s, invsqrt2); /* l = (m + s) / sqrt(2) */
+ xr[1][l + i] = mad_f_mul(m - s, invsqrt2); /* r = (m - s) / sqrt(2) */
+ }
+ }
+ }
+
+ return MAD_ERROR_NONE;
+}
+
+/*
+ * NAME: III_aliasreduce()
+ * DESCRIPTION: perform frequency line alias reduction
+ */
+static
+void III_aliasreduce(mad_fixed_t xr[576], int lines)
+{
+ mad_fixed_t const *bound;
+ int i;
+
+ bound = &xr[lines];
+ for (xr += 18; xr < bound; xr += 18) {
+ for (i = 0; i < 8; ++i) {
+ register mad_fixed_t a, b;
+ register mad_fixed64hi_t hi;
+ register mad_fixed64lo_t lo;
+
+ a = xr[-1 - i];
+ b = xr[ i];
+
+# if defined(ASO_ZEROCHECK)
+ if (a | b) {
+# endif
+ MAD_F_ML0(hi, lo, a, cs[i]);
+ MAD_F_MLA(hi, lo, -b, ca[i]);
+
+ xr[-1 - i] = MAD_F_MLZ(hi, lo);
+
+ MAD_F_ML0(hi, lo, b, cs[i]);
+ MAD_F_MLA(hi, lo, a, ca[i]);
+
+ xr[ i] = MAD_F_MLZ(hi, lo);
+# if defined(ASO_ZEROCHECK)
+ }
+# endif
+ }
+ }
+}
+
+# if defined(ASO_IMDCT)
+void III_imdct_l(mad_fixed_t const [18], mad_fixed_t [36], unsigned int);
+# else
+# if 1
+static
+void fastsdct(mad_fixed_t const x[9], mad_fixed_t y[18])
+{
+ mad_fixed_t a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12;
+ mad_fixed_t a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25;
+ mad_fixed_t m0, m1, m2, m3, m4, m5, m6, m7;
+
+ enum {
+ c0 = MAD_F(0x1f838b8d), /* 2 * cos( 1 * PI / 18) */
+ c1 = MAD_F(0x1bb67ae8), /* 2 * cos( 3 * PI / 18) */
+ c2 = MAD_F(0x18836fa3), /* 2 * cos( 4 * PI / 18) */
+ c3 = MAD_F(0x1491b752), /* 2 * cos( 5 * PI / 18) */
+ c4 = MAD_F(0x0af1d43a), /* 2 * cos( 7 * PI / 18) */
+ c5 = MAD_F(0x058e86a0), /* 2 * cos( 8 * PI / 18) */
+ c6 = -MAD_F(0x1e11f642) /* 2 * cos(16 * PI / 18) */
+ };
+
+ a0 = x[3] + x[5];
+ a1 = x[3] - x[5];
+ a2 = x[6] + x[2];
+ a3 = x[6] - x[2];
+ a4 = x[1] + x[7];
+ a5 = x[1] - x[7];
+ a6 = x[8] + x[0];
+ a7 = x[8] - x[0];
+
+ a8 = a0 + a2;
+ a9 = a0 - a2;
+ a10 = a0 - a6;
+ a11 = a2 - a6;
+ a12 = a8 + a6;
+ a13 = a1 - a3;
+ a14 = a13 + a7;
+ a15 = a3 + a7;
+ a16 = a1 - a7;
+ a17 = a1 + a3;
+
+ m0 = mad_f_mul(a17, -c3);
+ m1 = mad_f_mul(a16, -c0);
+ m2 = mad_f_mul(a15, -c4);
+ m3 = mad_f_mul(a14, -c1);
+ m4 = mad_f_mul(a5, -c1);
+ m5 = mad_f_mul(a11, -c6);
+ m6 = mad_f_mul(a10, -c5);
+ m7 = mad_f_mul(a9, -c2);
+
+ a18 = x[4] + a4;
+ a19 = 2 * x[4] - a4;
+ a20 = a19 + m5;
+ a21 = a19 - m5;
+ a22 = a19 + m6;
+ a23 = m4 + m2;
+ a24 = m4 - m2;
+ a25 = m4 + m1;
+
+ /* output to every other slot for convenience */
+
+ y[ 0] = a18 + a12;
+ y[ 2] = m0 - a25;
+ y[ 4] = m7 - a20;
+ y[ 6] = m3;
+ y[ 8] = a21 - m6;
+ y[10] = a24 - m1;
+ y[12] = a12 - 2 * a18;
+ y[14] = a23 + m0;
+ y[16] = a22 + m7;
+}
+
+static inline
+void sdctII(mad_fixed_t const x[18], mad_fixed_t X[18])
+{
+ mad_fixed_t tmp[9];
+ int i;
+
+ /* scale[i] = 2 * cos(PI * (2 * i + 1) / (2 * 18)) */
+ static mad_fixed_t const scale[9] = {
+ MAD_F(0x1fe0d3b4), MAD_F(0x1ee8dd47), MAD_F(0x1d007930),
+ MAD_F(0x1a367e59), MAD_F(0x16a09e66), MAD_F(0x125abcf8),
+ MAD_F(0x0d8616bc), MAD_F(0x08483ee1), MAD_F(0x02c9fad7)
+ };
+
+ /* divide the 18-point SDCT-II into two 9-point SDCT-IIs */
+
+ /* even input butterfly */
+
+ for (i = 0; i < 9; i += 3) {
+ tmp[i + 0] = x[i + 0] + x[18 - (i + 0) - 1];
+ tmp[i + 1] = x[i + 1] + x[18 - (i + 1) - 1];
+ tmp[i + 2] = x[i + 2] + x[18 - (i + 2) - 1];
+ }
+
+ fastsdct(tmp, &X[0]);
+
+ /* odd input butterfly and scaling */
+
+ for (i = 0; i < 9; i += 3) {
+ tmp[i + 0] = mad_f_mul(x[i + 0] - x[18 - (i + 0) - 1], scale[i + 0]);
+ tmp[i + 1] = mad_f_mul(x[i + 1] - x[18 - (i + 1) - 1], scale[i + 1]);
+ tmp[i + 2] = mad_f_mul(x[i + 2] - x[18 - (i + 2) - 1], scale[i + 2]);
+ }
+
+ fastsdct(tmp, &X[1]);
+
+ /* output accumulation */
+
+ for (i = 3; i < 18; i += 8) {
+ X[i + 0] -= X[(i + 0) - 2];
+ X[i + 2] -= X[(i + 2) - 2];
+ X[i + 4] -= X[(i + 4) - 2];
+ X[i + 6] -= X[(i + 6) - 2];
+ }
+}
+
+static inline
+void dctIV(mad_fixed_t const y[18], mad_fixed_t X[18])
+{
+ mad_fixed_t tmp[18];
+ int i;
+
+ /* scale[i] = 2 * cos(PI * (2 * i + 1) / (4 * 18)) */
+ static mad_fixed_t const scale[18] = {
+ MAD_F(0x1ff833fa), MAD_F(0x1fb9ea93), MAD_F(0x1f3dd120),
+ MAD_F(0x1e84d969), MAD_F(0x1d906bcf), MAD_F(0x1c62648b),
+ MAD_F(0x1afd100f), MAD_F(0x1963268b), MAD_F(0x1797c6a4),
+ MAD_F(0x159e6f5b), MAD_F(0x137af940), MAD_F(0x11318ef3),
+ MAD_F(0x0ec6a507), MAD_F(0x0c3ef153), MAD_F(0x099f61c5),
+ MAD_F(0x06ed12c5), MAD_F(0x042d4544), MAD_F(0x0165547c)
+ };
+
+ /* scaling */
+
+ for (i = 0; i < 18; i += 3) {
+ tmp[i + 0] = mad_f_mul(y[i + 0], scale[i + 0]);
+ tmp[i + 1] = mad_f_mul(y[i + 1], scale[i + 1]);
+ tmp[i + 2] = mad_f_mul(y[i + 2], scale[i + 2]);
+ }
+
+ /* SDCT-II */
+
+ sdctII(tmp, X);
+
+ /* scale reduction and output accumulation */
+
+ X[0] /= 2;
+ for (i = 1; i < 17; i += 4) {
+ X[i + 0] = X[i + 0] / 2 - X[(i + 0) - 1];
+ X[i + 1] = X[i + 1] / 2 - X[(i + 1) - 1];
+ X[i + 2] = X[i + 2] / 2 - X[(i + 2) - 1];
+ X[i + 3] = X[i + 3] / 2 - X[(i + 3) - 1];
+ }
+ X[17] = X[17] / 2 - X[16];
+}
+
+/*
+ * NAME: imdct36
+ * DESCRIPTION: perform X[18]->x[36] IMDCT using Szu-Wei Lee's fast algorithm
+ */
+static inline
+void imdct36(mad_fixed_t const x[18], mad_fixed_t y[36])
+{
+ mad_fixed_t tmp[18];
+ int i;
+
+ /* DCT-IV */
+
+ dctIV(x, tmp);
+
+ /* convert 18-point DCT-IV to 36-point IMDCT */
+
+ for (i = 0; i < 9; i += 3) {
+ y[i + 0] = tmp[9 + (i + 0)];
+ y[i + 1] = tmp[9 + (i + 1)];
+ y[i + 2] = tmp[9 + (i + 2)];
+ }
+ for (i = 9; i < 27; i += 3) {
+ y[i + 0] = -tmp[36 - (9 + (i + 0)) - 1];
+ y[i + 1] = -tmp[36 - (9 + (i + 1)) - 1];
+ y[i + 2] = -tmp[36 - (9 + (i + 2)) - 1];
+ }
+ for (i = 27; i < 36; i += 3) {
+ y[i + 0] = -tmp[(i + 0) - 27];
+ y[i + 1] = -tmp[(i + 1) - 27];
+ y[i + 2] = -tmp[(i + 2) - 27];
+ }
+}
+# else
+/*
+ * NAME: imdct36
+ * DESCRIPTION: perform X[18]->x[36] IMDCT
+ */
+static inline
+void imdct36(mad_fixed_t const X[18], mad_fixed_t x[36])
+{
+ mad_fixed_t t0, t1, t2, t3, t4, t5, t6, t7;
+ mad_fixed_t t8, t9, t10, t11, t12, t13, t14, t15;
+ register mad_fixed64hi_t hi;
+ register mad_fixed64lo_t lo;
+
+ MAD_F_ML0(hi, lo, X[4], MAD_F(0x0ec835e8));
+ MAD_F_MLA(hi, lo, X[13], MAD_F(0x061f78aa));
+
+ t6 = MAD_F_MLZ(hi, lo);
+
+ MAD_F_MLA(hi, lo, (t14 = X[1] - X[10]), -MAD_F(0x061f78aa));
+ MAD_F_MLA(hi, lo, (t15 = X[7] + X[16]), -MAD_F(0x0ec835e8));
+
+ t0 = MAD_F_MLZ(hi, lo);
+
+ MAD_F_MLA(hi, lo, (t8 = X[0] - X[11] - X[12]), MAD_F(0x0216a2a2));
+ MAD_F_MLA(hi, lo, (t9 = X[2] - X[9] - X[14]), MAD_F(0x09bd7ca0));
+ MAD_F_MLA(hi, lo, (t10 = X[3] - X[8] - X[15]), -MAD_F(0x0cb19346));
+ MAD_F_MLA(hi, lo, (t11 = X[5] - X[6] - X[17]), -MAD_F(0x0fdcf549));
+
+ x[7] = MAD_F_MLZ(hi, lo);
+ x[10] = -x[7];
+
+ MAD_F_ML0(hi, lo, t8, -MAD_F(0x0cb19346));
+ MAD_F_MLA(hi, lo, t9, MAD_F(0x0fdcf549));
+ MAD_F_MLA(hi, lo, t10, MAD_F(0x0216a2a2));
+ MAD_F_MLA(hi, lo, t11, -MAD_F(0x09bd7ca0));
+
+ x[19] = x[34] = MAD_F_MLZ(hi, lo) - t0;
+
+ t12 = X[0] - X[3] + X[8] - X[11] - X[12] + X[15];
+ t13 = X[2] + X[5] - X[6] - X[9] - X[14] - X[17];
+
+ MAD_F_ML0(hi, lo, t12, -MAD_F(0x0ec835e8));
+ MAD_F_MLA(hi, lo, t13, MAD_F(0x061f78aa));
+
+ x[22] = x[31] = MAD_F_MLZ(hi, lo) + t0;
+
+ MAD_F_ML0(hi, lo, X[1], -MAD_F(0x09bd7ca0));
+ MAD_F_MLA(hi, lo, X[7], MAD_F(0x0216a2a2));
+ MAD_F_MLA(hi, lo, X[10], -MAD_F(0x0fdcf549));
+ MAD_F_MLA(hi, lo, X[16], MAD_F(0x0cb19346));
+
+ t1 = MAD_F_MLZ(hi, lo) + t6;
+
+ MAD_F_ML0(hi, lo, X[0], MAD_F(0x03768962));
+ MAD_F_MLA(hi, lo, X[2], MAD_F(0x0e313245));
+ MAD_F_MLA(hi, lo, X[3], -MAD_F(0x0ffc19fd));
+ MAD_F_MLA(hi, lo, X[5], -MAD_F(0x0acf37ad));
+ MAD_F_MLA(hi, lo, X[6], MAD_F(0x04cfb0e2));
+ MAD_F_MLA(hi, lo, X[8], -MAD_F(0x0898c779));
+ MAD_F_MLA(hi, lo, X[9], MAD_F(0x0d7e8807));
+ MAD_F_MLA(hi, lo, X[11], MAD_F(0x0f426cb5));
+ MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0bcbe352));
+ MAD_F_MLA(hi, lo, X[14], MAD_F(0x00b2aa3e));
+ MAD_F_MLA(hi, lo, X[15], -MAD_F(0x07635284));
+ MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0f9ee890));
+
+ x[6] = MAD_F_MLZ(hi, lo) + t1;
+ x[11] = -x[6];
+
+ MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0f426cb5));
+ MAD_F_MLA(hi, lo, X[2], -MAD_F(0x00b2aa3e));
+ MAD_F_MLA(hi, lo, X[3], MAD_F(0x0898c779));
+ MAD_F_MLA(hi, lo, X[5], MAD_F(0x0f9ee890));
+ MAD_F_MLA(hi, lo, X[6], MAD_F(0x0acf37ad));
+ MAD_F_MLA(hi, lo, X[8], -MAD_F(0x07635284));
+ MAD_F_MLA(hi, lo, X[9], -MAD_F(0x0e313245));
+ MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0bcbe352));
+ MAD_F_MLA(hi, lo, X[12], -MAD_F(0x03768962));
+ MAD_F_MLA(hi, lo, X[14], MAD_F(0x0d7e8807));
+ MAD_F_MLA(hi, lo, X[15], MAD_F(0x0ffc19fd));
+ MAD_F_MLA(hi, lo, X[17], MAD_F(0x04cfb0e2));
+
+ x[23] = x[30] = MAD_F_MLZ(hi, lo) + t1;
+
+ MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0bcbe352));
+ MAD_F_MLA(hi, lo, X[2], MAD_F(0x0d7e8807));
+ MAD_F_MLA(hi, lo, X[3], -MAD_F(0x07635284));
+ MAD_F_MLA(hi, lo, X[5], MAD_F(0x04cfb0e2));
+ MAD_F_MLA(hi, lo, X[6], MAD_F(0x0f9ee890));
+ MAD_F_MLA(hi, lo, X[8], -MAD_F(0x0ffc19fd));
+ MAD_F_MLA(hi, lo, X[9], -MAD_F(0x00b2aa3e));
+ MAD_F_MLA(hi, lo, X[11], MAD_F(0x03768962));
+ MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0f426cb5));
+ MAD_F_MLA(hi, lo, X[14], MAD_F(0x0e313245));
+ MAD_F_MLA(hi, lo, X[15], MAD_F(0x0898c779));
+ MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0acf37ad));
+
+ x[18] = x[35] = MAD_F_MLZ(hi, lo) - t1;
+
+ MAD_F_ML0(hi, lo, X[4], MAD_F(0x061f78aa));
+ MAD_F_MLA(hi, lo, X[13], -MAD_F(0x0ec835e8));
+
+ t7 = MAD_F_MLZ(hi, lo);
+
+ MAD_F_MLA(hi, lo, X[1], -MAD_F(0x0cb19346));
+ MAD_F_MLA(hi, lo, X[7], MAD_F(0x0fdcf549));
+ MAD_F_MLA(hi, lo, X[10], MAD_F(0x0216a2a2));
+ MAD_F_MLA(hi, lo, X[16], -MAD_F(0x09bd7ca0));
+
+ t2 = MAD_F_MLZ(hi, lo);
+
+ MAD_F_MLA(hi, lo, X[0], MAD_F(0x04cfb0e2));
+ MAD_F_MLA(hi, lo, X[2], MAD_F(0x0ffc19fd));
+ MAD_F_MLA(hi, lo, X[3], -MAD_F(0x0d7e8807));
+ MAD_F_MLA(hi, lo, X[5], MAD_F(0x03768962));
+ MAD_F_MLA(hi, lo, X[6], -MAD_F(0x0bcbe352));
+ MAD_F_MLA(hi, lo, X[8], -MAD_F(0x0e313245));
+ MAD_F_MLA(hi, lo, X[9], MAD_F(0x07635284));
+ MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0acf37ad));
+ MAD_F_MLA(hi, lo, X[12], MAD_F(0x0f9ee890));
+ MAD_F_MLA(hi, lo, X[14], MAD_F(0x0898c779));
+ MAD_F_MLA(hi, lo, X[15], MAD_F(0x00b2aa3e));
+ MAD_F_MLA(hi, lo, X[17], MAD_F(0x0f426cb5));
+
+ x[5] = MAD_F_MLZ(hi, lo);
+ x[12] = -x[5];
+
+ MAD_F_ML0(hi, lo, X[0], MAD_F(0x0acf37ad));
+ MAD_F_MLA(hi, lo, X[2], -MAD_F(0x0898c779));
+ MAD_F_MLA(hi, lo, X[3], MAD_F(0x0e313245));
+ MAD_F_MLA(hi, lo, X[5], -MAD_F(0x0f426cb5));
+ MAD_F_MLA(hi, lo, X[6], -MAD_F(0x03768962));
+ MAD_F_MLA(hi, lo, X[8], MAD_F(0x00b2aa3e));
+ MAD_F_MLA(hi, lo, X[9], -MAD_F(0x0ffc19fd));
+ MAD_F_MLA(hi, lo, X[11], MAD_F(0x0f9ee890));
+ MAD_F_MLA(hi, lo, X[12], -MAD_F(0x04cfb0e2));
+ MAD_F_MLA(hi, lo, X[14], MAD_F(0x07635284));
+ MAD_F_MLA(hi, lo, X[15], MAD_F(0x0d7e8807));
+ MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0bcbe352));
+
+ x[0] = MAD_F_MLZ(hi, lo) + t2;
+ x[17] = -x[0];
+
+ MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0f9ee890));
+ MAD_F_MLA(hi, lo, X[2], -MAD_F(0x07635284));
+ MAD_F_MLA(hi, lo, X[3], -MAD_F(0x00b2aa3e));
+ MAD_F_MLA(hi, lo, X[5], MAD_F(0x0bcbe352));
+ MAD_F_MLA(hi, lo, X[6], MAD_F(0x0f426cb5));
+ MAD_F_MLA(hi, lo, X[8], MAD_F(0x0d7e8807));
+ MAD_F_MLA(hi, lo, X[9], MAD_F(0x0898c779));
+ MAD_F_MLA(hi, lo, X[11], -MAD_F(0x04cfb0e2));
+ MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0acf37ad));
+ MAD_F_MLA(hi, lo, X[14], -MAD_F(0x0ffc19fd));
+ MAD_F_MLA(hi, lo, X[15], -MAD_F(0x0e313245));
+ MAD_F_MLA(hi, lo, X[17], -MAD_F(0x03768962));
+
+ x[24] = x[29] = MAD_F_MLZ(hi, lo) + t2;
+
+ MAD_F_ML0(hi, lo, X[1], -MAD_F(0x0216a2a2));
+ MAD_F_MLA(hi, lo, X[7], -MAD_F(0x09bd7ca0));
+ MAD_F_MLA(hi, lo, X[10], MAD_F(0x0cb19346));
+ MAD_F_MLA(hi, lo, X[16], MAD_F(0x0fdcf549));
+
+ t3 = MAD_F_MLZ(hi, lo) + t7;
+
+ MAD_F_ML0(hi, lo, X[0], MAD_F(0x00b2aa3e));
+ MAD_F_MLA(hi, lo, X[2], MAD_F(0x03768962));
+ MAD_F_MLA(hi, lo, X[3], -MAD_F(0x04cfb0e2));
+ MAD_F_MLA(hi, lo, X[5], -MAD_F(0x07635284));
+ MAD_F_MLA(hi, lo, X[6], MAD_F(0x0898c779));
+ MAD_F_MLA(hi, lo, X[8], MAD_F(0x0acf37ad));
+ MAD_F_MLA(hi, lo, X[9], -MAD_F(0x0bcbe352));
+ MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0d7e8807));
+ MAD_F_MLA(hi, lo, X[12], MAD_F(0x0e313245));
+ MAD_F_MLA(hi, lo, X[14], MAD_F(0x0f426cb5));
+ MAD_F_MLA(hi, lo, X[15], -MAD_F(0x0f9ee890));
+ MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0ffc19fd));
+
+ x[8] = MAD_F_MLZ(hi, lo) + t3;
+ x[9] = -x[8];
+
+ MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0e313245));
+ MAD_F_MLA(hi, lo, X[2], MAD_F(0x0bcbe352));
+ MAD_F_MLA(hi, lo, X[3], MAD_F(0x0f9ee890));
+ MAD_F_MLA(hi, lo, X[5], -MAD_F(0x0898c779));
+ MAD_F_MLA(hi, lo, X[6], -MAD_F(0x0ffc19fd));
+ MAD_F_MLA(hi, lo, X[8], MAD_F(0x04cfb0e2));
+ MAD_F_MLA(hi, lo, X[9], MAD_F(0x0f426cb5));
+ MAD_F_MLA(hi, lo, X[11], -MAD_F(0x00b2aa3e));
+ MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0d7e8807));
+ MAD_F_MLA(hi, lo, X[14], -MAD_F(0x03768962));
+ MAD_F_MLA(hi, lo, X[15], MAD_F(0x0acf37ad));
+ MAD_F_MLA(hi, lo, X[17], MAD_F(0x07635284));
+
+ x[21] = x[32] = MAD_F_MLZ(hi, lo) + t3;
+
+ MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0d7e8807));
+ MAD_F_MLA(hi, lo, X[2], MAD_F(0x0f426cb5));
+ MAD_F_MLA(hi, lo, X[3], MAD_F(0x0acf37ad));
+ MAD_F_MLA(hi, lo, X[5], -MAD_F(0x0ffc19fd));
+ MAD_F_MLA(hi, lo, X[6], -MAD_F(0x07635284));
+ MAD_F_MLA(hi, lo, X[8], MAD_F(0x0f9ee890));
+ MAD_F_MLA(hi, lo, X[9], MAD_F(0x03768962));
+ MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0e313245));
+ MAD_F_MLA(hi, lo, X[12], MAD_F(0x00b2aa3e));
+ MAD_F_MLA(hi, lo, X[14], MAD_F(0x0bcbe352));
+ MAD_F_MLA(hi, lo, X[15], -MAD_F(0x04cfb0e2));
+ MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0898c779));
+
+ x[20] = x[33] = MAD_F_MLZ(hi, lo) - t3;
+
+ MAD_F_ML0(hi, lo, t14, -MAD_F(0x0ec835e8));
+ MAD_F_MLA(hi, lo, t15, MAD_F(0x061f78aa));
+
+ t4 = MAD_F_MLZ(hi, lo) - t7;
+
+ MAD_F_ML0(hi, lo, t12, MAD_F(0x061f78aa));
+ MAD_F_MLA(hi, lo, t13, MAD_F(0x0ec835e8));
+
+ x[4] = MAD_F_MLZ(hi, lo) + t4;
+ x[13] = -x[4];
+
+ MAD_F_ML0(hi, lo, t8, MAD_F(0x09bd7ca0));
+ MAD_F_MLA(hi, lo, t9, -MAD_F(0x0216a2a2));
+ MAD_F_MLA(hi, lo, t10, MAD_F(0x0fdcf549));
+ MAD_F_MLA(hi, lo, t11, -MAD_F(0x0cb19346));
+
+ x[1] = MAD_F_MLZ(hi, lo) + t4;
+ x[16] = -x[1];
+
+ MAD_F_ML0(hi, lo, t8, -MAD_F(0x0fdcf549));
+ MAD_F_MLA(hi, lo, t9, -MAD_F(0x0cb19346));
+ MAD_F_MLA(hi, lo, t10, -MAD_F(0x09bd7ca0));
+ MAD_F_MLA(hi, lo, t11, -MAD_F(0x0216a2a2));
+
+ x[25] = x[28] = MAD_F_MLZ(hi, lo) + t4;
+
+ MAD_F_ML0(hi, lo, X[1], -MAD_F(0x0fdcf549));
+ MAD_F_MLA(hi, lo, X[7], -MAD_F(0x0cb19346));
+ MAD_F_MLA(hi, lo, X[10], -MAD_F(0x09bd7ca0));
+ MAD_F_MLA(hi, lo, X[16], -MAD_F(0x0216a2a2));
+
+ t5 = MAD_F_MLZ(hi, lo) - t6;
+
+ MAD_F_ML0(hi, lo, X[0], MAD_F(0x0898c779));
+ MAD_F_MLA(hi, lo, X[2], MAD_F(0x04cfb0e2));
+ MAD_F_MLA(hi, lo, X[3], MAD_F(0x0bcbe352));
+ MAD_F_MLA(hi, lo, X[5], MAD_F(0x00b2aa3e));
+ MAD_F_MLA(hi, lo, X[6], MAD_F(0x0e313245));
+ MAD_F_MLA(hi, lo, X[8], -MAD_F(0x03768962));
+ MAD_F_MLA(hi, lo, X[9], MAD_F(0x0f9ee890));
+ MAD_F_MLA(hi, lo, X[11], -MAD_F(0x07635284));
+ MAD_F_MLA(hi, lo, X[12], MAD_F(0x0ffc19fd));
+ MAD_F_MLA(hi, lo, X[14], -MAD_F(0x0acf37ad));
+ MAD_F_MLA(hi, lo, X[15], MAD_F(0x0f426cb5));
+ MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0d7e8807));
+
+ x[2] = MAD_F_MLZ(hi, lo) + t5;
+ x[15] = -x[2];
+
+ MAD_F_ML0(hi, lo, X[0], MAD_F(0x07635284));
+ MAD_F_MLA(hi, lo, X[2], MAD_F(0x0acf37ad));
+ MAD_F_MLA(hi, lo, X[3], MAD_F(0x03768962));
+ MAD_F_MLA(hi, lo, X[5], MAD_F(0x0d7e8807));
+ MAD_F_MLA(hi, lo, X[6], -MAD_F(0x00b2aa3e));
+ MAD_F_MLA(hi, lo, X[8], MAD_F(0x0f426cb5));
+ MAD_F_MLA(hi, lo, X[9], -MAD_F(0x04cfb0e2));
+ MAD_F_MLA(hi, lo, X[11], MAD_F(0x0ffc19fd));
+ MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0898c779));
+ MAD_F_MLA(hi, lo, X[14], MAD_F(0x0f9ee890));
+ MAD_F_MLA(hi, lo, X[15], -MAD_F(0x0bcbe352));
+ MAD_F_MLA(hi, lo, X[17], MAD_F(0x0e313245));
+
+ x[3] = MAD_F_MLZ(hi, lo) + t5;
+ x[14] = -x[3];
+
+ MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0ffc19fd));
+ MAD_F_MLA(hi, lo, X[2], -MAD_F(0x0f9ee890));
+ MAD_F_MLA(hi, lo, X[3], -MAD_F(0x0f426cb5));
+ MAD_F_MLA(hi, lo, X[5], -MAD_F(0x0e313245));
+ MAD_F_MLA(hi, lo, X[6], -MAD_F(0x0d7e8807));
+ MAD_F_MLA(hi, lo, X[8], -MAD_F(0x0bcbe352));
+ MAD_F_MLA(hi, lo, X[9], -MAD_F(0x0acf37ad));
+ MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0898c779));
+ MAD_F_MLA(hi, lo, X[12], -MAD_F(0x07635284));
+ MAD_F_MLA(hi, lo, X[14], -MAD_F(0x04cfb0e2));
+ MAD_F_MLA(hi, lo, X[15], -MAD_F(0x03768962));
+ MAD_F_MLA(hi, lo, X[17], -MAD_F(0x00b2aa3e));
+
+ x[26] = x[27] = MAD_F_MLZ(hi, lo) + t5;
+}
+# endif
+
+/*
+ * NAME: III_imdct_l()
+ * DESCRIPTION: perform IMDCT and windowing for long blocks
+ */
+static
+void III_imdct_l(mad_fixed_t const X[18], mad_fixed_t z[36],
+ unsigned int block_type)
+{
+ unsigned int i;
+
+ /* IMDCT */
+
+ imdct36(X, z);
+
+ /* windowing */
+
+ switch (block_type) {
+ case 0: /* normal window */
+# if defined(ASO_INTERLEAVE1)
+ {
+ register mad_fixed_t tmp1, tmp2;
+
+ tmp1 = window_l[0];
+ tmp2 = window_l[1];
+
+ for (i = 0; i < 34; i += 2) {
+ z[i + 0] = mad_f_mul(z[i + 0], tmp1);
+ tmp1 = window_l[i + 2];
+ z[i + 1] = mad_f_mul(z[i + 1], tmp2);
+ tmp2 = window_l[i + 3];
+ }
+
+ z[34] = mad_f_mul(z[34], tmp1);
+ z[35] = mad_f_mul(z[35], tmp2);
+ }
+# elif defined(ASO_INTERLEAVE2)
+ {
+ register mad_fixed_t tmp1, tmp2;
+
+ tmp1 = z[0];
+ tmp2 = window_l[0];
+
+ for (i = 0; i < 35; ++i) {
+ z[i] = mad_f_mul(tmp1, tmp2);
+ tmp1 = z[i + 1];
+ tmp2 = window_l[i + 1];
+ }
+
+ z[35] = mad_f_mul(tmp1, tmp2);
+ }
+# elif 1
+ for (i = 0; i < 36; i += 4) {
+ z[i + 0] = mad_f_mul(z[i + 0], window_l[i + 0]);
+ z[i + 1] = mad_f_mul(z[i + 1], window_l[i + 1]);
+ z[i + 2] = mad_f_mul(z[i + 2], window_l[i + 2]);
+ z[i + 3] = mad_f_mul(z[i + 3], window_l[i + 3]);
+ }
+# else
+ for (i = 0; i < 36; ++i) z[i] = mad_f_mul(z[i], window_l[i]);
+# endif
+ break;
+
+ case 1: /* start block */
+ for (i = 0; i < 18; i += 3) {
+ z[i + 0] = mad_f_mul(z[i + 0], window_l[i + 0]);
+ z[i + 1] = mad_f_mul(z[i + 1], window_l[i + 1]);
+ z[i + 2] = mad_f_mul(z[i + 2], window_l[i + 2]);
+ }
+ /* (i = 18; i < 24; ++i) z[i] unchanged */
+ for (i = 24; i < 30; ++i) z[i] = mad_f_mul(z[i], window_s[i - 18]);
+ for (i = 30; i < 36; ++i) z[i] = 0;
+ break;
+
+ case 3: /* stop block */
+ for (i = 0; i < 6; ++i) z[i] = 0;
+ for (i = 6; i < 12; ++i) z[i] = mad_f_mul(z[i], window_s[i - 6]);
+ /* (i = 12; i < 18; ++i) z[i] unchanged */
+ for (i = 18; i < 36; i += 3) {
+ z[i + 0] = mad_f_mul(z[i + 0], window_l[i + 0]);
+ z[i + 1] = mad_f_mul(z[i + 1], window_l[i + 1]);
+ z[i + 2] = mad_f_mul(z[i + 2], window_l[i + 2]);
+ }
+ break;
+ }
+}
+# endif /* ASO_IMDCT */
+
+/*
+ * NAME: III_imdct_s()
+ * DESCRIPTION: perform IMDCT and windowing for short blocks
+ */
+static
+void III_imdct_s(mad_fixed_t const X[18], mad_fixed_t z[36])
+{
+ mad_fixed_t y[36], *yptr;
+ mad_fixed_t const *wptr;
+ int w, i;
+ register mad_fixed64hi_t hi;
+ register mad_fixed64lo_t lo;
+
+ /* IMDCT */
+
+ yptr = &y[0];
+
+ for (w = 0; w < 3; ++w) {
+ register mad_fixed_t const (*s)[6];
+
+ s = imdct_s;
+
+ for (i = 0; i < 3; ++i) {
+ MAD_F_ML0(hi, lo, X[0], (*s)[0]);
+ MAD_F_MLA(hi, lo, X[1], (*s)[1]);
+ MAD_F_MLA(hi, lo, X[2], (*s)[2]);
+ MAD_F_MLA(hi, lo, X[3], (*s)[3]);
+ MAD_F_MLA(hi, lo, X[4], (*s)[4]);
+ MAD_F_MLA(hi, lo, X[5], (*s)[5]);
+
+ yptr[i + 0] = MAD_F_MLZ(hi, lo);
+ yptr[5 - i] = -yptr[i + 0];
+
+ ++s;
+
+ MAD_F_ML0(hi, lo, X[0], (*s)[0]);
+ MAD_F_MLA(hi, lo, X[1], (*s)[1]);
+ MAD_F_MLA(hi, lo, X[2], (*s)[2]);
+ MAD_F_MLA(hi, lo, X[3], (*s)[3]);
+ MAD_F_MLA(hi, lo, X[4], (*s)[4]);
+ MAD_F_MLA(hi, lo, X[5], (*s)[5]);
+
+ yptr[ i + 6] = MAD_F_MLZ(hi, lo);
+ yptr[11 - i] = yptr[i + 6];
+
+ ++s;
+ }
+
+ yptr += 12;
+ X += 6;
+ }
+
+ /* windowing, overlapping and concatenation */
+
+ yptr = &y[0];
+ wptr = &window_s[0];
+
+ for (i = 0; i < 6; ++i) {
+ z[i + 0] = 0;
+ z[i + 6] = mad_f_mul(yptr[ 0 + 0], wptr[0]);
+
+ MAD_F_ML0(hi, lo, yptr[ 0 + 6], wptr[6]);
+ MAD_F_MLA(hi, lo, yptr[12 + 0], wptr[0]);
+
+ z[i + 12] = MAD_F_MLZ(hi, lo);
+
+ MAD_F_ML0(hi, lo, yptr[12 + 6], wptr[6]);
+ MAD_F_MLA(hi, lo, yptr[24 + 0], wptr[0]);
+
+ z[i + 18] = MAD_F_MLZ(hi, lo);
+
+ z[i + 24] = mad_f_mul(yptr[24 + 6], wptr[6]);
+ z[i + 30] = 0;
+
+ ++yptr;
+ ++wptr;
+ }
+}
+
+/*
+ * NAME: III_overlap()
+ * DESCRIPTION: perform overlap-add of windowed IMDCT outputs
+ */
+static
+void III_overlap(mad_fixed_t const output[36], mad_fixed_t overlap[18],
+ mad_fixed_t sample[18][32], unsigned int sb)
+{
+ unsigned int i;
+
+# if defined(ASO_INTERLEAVE2)
+ {
+ register mad_fixed_t tmp1, tmp2;
+
+ tmp1 = overlap[0];
+ tmp2 = overlap[1];
+
+ for (i = 0; i < 16; i += 2) {
+ sample[i + 0][sb] = output[i + 0 + 0] + tmp1;
+ overlap[i + 0] = output[i + 0 + 18];
+ tmp1 = overlap[i + 2];
+
+ sample[i + 1][sb] = output[i + 1 + 0] + tmp2;
+ overlap[i + 1] = output[i + 1 + 18];
+ tmp2 = overlap[i + 3];
+ }
+
+ sample[16][sb] = output[16 + 0] + tmp1;
+ overlap[16] = output[16 + 18];
+ sample[17][sb] = output[17 + 0] + tmp2;
+ overlap[17] = output[17 + 18];
+ }
+# elif 0
+ for (i = 0; i < 18; i += 2) {
+ sample[i + 0][sb] = output[i + 0 + 0] + overlap[i + 0];
+ overlap[i + 0] = output[i + 0 + 18];
+
+ sample[i + 1][sb] = output[i + 1 + 0] + overlap[i + 1];
+ overlap[i + 1] = output[i + 1 + 18];
+ }
+# else
+ for (i = 0; i < 18; ++i) {
+ sample[i][sb] = output[i + 0] + overlap[i];
+ overlap[i] = output[i + 18];
+ }
+# endif
+}
+
+/*
+ * NAME: III_overlap_z()
+ * DESCRIPTION: perform "overlap-add" of zero IMDCT outputs
+ */
+static inline
+void III_overlap_z(mad_fixed_t overlap[18],
+ mad_fixed_t sample[18][32], unsigned int sb)
+{
+ unsigned int i;
+
+# if defined(ASO_INTERLEAVE2)
+ {
+ register mad_fixed_t tmp1, tmp2;
+
+ tmp1 = overlap[0];
+ tmp2 = overlap[1];
+
+ for (i = 0; i < 16; i += 2) {
+ sample[i + 0][sb] = tmp1;
+ overlap[i + 0] = 0;
+ tmp1 = overlap[i + 2];
+
+ sample[i + 1][sb] = tmp2;
+ overlap[i + 1] = 0;
+ tmp2 = overlap[i + 3];
+ }
+
+ sample[16][sb] = tmp1;
+ overlap[16] = 0;
+ sample[17][sb] = tmp2;
+ overlap[17] = 0;
+ }
+# else
+ for (i = 0; i < 18; ++i) {
+ sample[i][sb] = overlap[i];
+ overlap[i] = 0;
+ }
+# endif
+}
+
+/*
+ * NAME: III_freqinver()
+ * DESCRIPTION: perform subband frequency inversion for odd sample lines
+ */
+static
+void III_freqinver(mad_fixed_t sample[18][32], unsigned int sb)
+{
+ unsigned int i;
+
+# if 1 || defined(ASO_INTERLEAVE1) || defined(ASO_INTERLEAVE2)
+ {
+ register mad_fixed_t tmp1, tmp2;
+
+ tmp1 = sample[1][sb];
+ tmp2 = sample[3][sb];
+
+ for (i = 1; i < 13; i += 4) {
+ sample[i + 0][sb] = -tmp1;
+ tmp1 = sample[i + 4][sb];
+ sample[i + 2][sb] = -tmp2;
+ tmp2 = sample[i + 6][sb];
+ }
+
+ sample[13][sb] = -tmp1;
+ tmp1 = sample[17][sb];
+ sample[15][sb] = -tmp2;
+ sample[17][sb] = -tmp1;
+ }
+# else
+ for (i = 1; i < 18; i += 2)
+ sample[i][sb] = -sample[i][sb];
+# endif
+}
+
+/*
+ * NAME: III_decode()
+ * DESCRIPTION: decode frame main_data
+ */
+static
+enum mad_error III_decode(struct mad_bitptr *ptr, struct mad_frame *frame,
+ struct sideinfo *si, unsigned int nch)
+{
+ struct mad_header *header = &frame->header;
+ unsigned int sfreqi, ngr, gr;
+
+ {
+ unsigned int sfreq;
+
+ sfreq = header->samplerate;
+ if (header->flags & MAD_FLAG_MPEG_2_5_EXT)
+ sfreq *= 2;
+
+ /* 48000 => 0, 44100 => 1, 32000 => 2,
+ 24000 => 3, 22050 => 4, 16000 => 5 */
+ sfreqi = ((sfreq >> 7) & 0x000f) +
+ ((sfreq >> 15) & 0x0001) - 8;
+
+ if (header->flags & MAD_FLAG_MPEG_2_5_EXT)
+ sfreqi += 3;
+ }
+
+ /* scalefactors, Huffman decoding, requantization */
+
+ ngr = (header->flags & MAD_FLAG_LSF_EXT) ? 1 : 2;
+
+ for (gr = 0; gr < ngr; ++gr) {
+ struct granule *granule = &si->gr[gr];
+ unsigned char const *sfbwidth[2];
+ mad_fixed_t xr[2][576];
+ unsigned int ch;
+ enum mad_error error;
+
+ for (ch = 0; ch < nch; ++ch) {
+ struct channel *channel = &granule->ch[ch];
+ unsigned int part2_length;
+
+ sfbwidth[ch] = sfbwidth_table[sfreqi].l;
+ if (channel->block_type == 2) {
+ sfbwidth[ch] = (channel->flags & mixed_block_flag) ?
+ sfbwidth_table[sfreqi].m : sfbwidth_table[sfreqi].s;
+ }
+
+ if (header->flags & MAD_FLAG_LSF_EXT) {
+ part2_length = III_scalefactors_lsf(ptr, channel,
+ ch == 0 ? 0 : &si->gr[1].ch[1],
+ header->mode_extension);
+ }
+ else {
+ part2_length = III_scalefactors(ptr, channel, &si->gr[0].ch[ch],
+ gr == 0 ? 0 : si->scfsi[ch]);
+ }
+
+ error = III_huffdecode(ptr, xr[ch], channel, sfbwidth[ch], part2_length);
+ if (error)
+ return error;
+ }
+
+ /* joint stereo processing */
+
+ if (header->mode == MAD_MODE_JOINT_STEREO && header->mode_extension) {
+ error = III_stereo(xr, granule, header, sfbwidth[0]);
+ if (error)
+ return error;
+ }
+
+ /* reordering, alias reduction, IMDCT, overlap-add, frequency inversion */
+
+ for (ch = 0; ch < nch; ++ch) {
+ struct channel const *channel = &granule->ch[ch];
+ mad_fixed_t (*sample)[32] = &frame->sbsample[ch][18 * gr];
+ unsigned int sb, l, i, sblimit;
+ mad_fixed_t output[36];
+
+ if (channel->block_type == 2) {
+ III_reorder(xr[ch], channel, sfbwidth[ch]);
+
+# if !defined(OPT_STRICT)
+ /*
+ * According to ISO/IEC 11172-3, "Alias reduction is not applied for
+ * granules with block_type == 2 (short block)." However, other
+ * sources suggest alias reduction should indeed be performed on the
+ * lower two subbands of mixed blocks. Most other implementations do
+ * this, so by default we will too.
+ */
+ if (channel->flags & mixed_block_flag)
+ III_aliasreduce(xr[ch], 36);
+# endif
+ }
+ else
+ III_aliasreduce(xr[ch], 576);
+
+ l = 0;
+
+ /* subbands 0-1 */
+
+ if (channel->block_type != 2 || (channel->flags & mixed_block_flag)) {
+ unsigned int block_type;
+
+ block_type = channel->block_type;
+ if (channel->flags & mixed_block_flag)
+ block_type = 0;
+
+ /* long blocks */
+ for (sb = 0; sb < 2; ++sb, l += 18) {
+ III_imdct_l(&xr[ch][l], output, block_type);
+ III_overlap(output, (*frame->overlap)[ch][sb], sample, sb);
+ }
+ }
+ else {
+ /* short blocks */
+ for (sb = 0; sb < 2; ++sb, l += 18) {
+ III_imdct_s(&xr[ch][l], output);
+ III_overlap(output, (*frame->overlap)[ch][sb], sample, sb);
+ }
+ }
+
+ III_freqinver(sample, 1);
+
+ /* (nonzero) subbands 2-31 */
+
+ i = 576;
+ while (i > 36 && xr[ch][i - 1] == 0)
+ --i;
+
+ sblimit = 32 - (576 - i) / 18;
+
+ if (channel->block_type != 2) {
+ /* long blocks */
+ for (sb = 2; sb < sblimit; ++sb, l += 18) {
+ III_imdct_l(&xr[ch][l], output, channel->block_type);
+ III_overlap(output, (*frame->overlap)[ch][sb], sample, sb);
+
+ if (sb & 1)
+ III_freqinver(sample, sb);
+ }
+ }
+ else {
+ /* short blocks */
+ for (sb = 2; sb < sblimit; ++sb, l += 18) {
+ III_imdct_s(&xr[ch][l], output);
+ III_overlap(output, (*frame->overlap)[ch][sb], sample, sb);
+
+ if (sb & 1)
+ III_freqinver(sample, sb);
+ }
+ }
+
+ /* remaining (zero) subbands */
+
+ for (sb = sblimit; sb < 32; ++sb) {
+ III_overlap_z((*frame->overlap)[ch][sb], sample, sb);
+
+ if (sb & 1)
+ III_freqinver(sample, sb);
+ }
+ }
+ }
+
+ return MAD_ERROR_NONE;
+}
+
+/*
+ * NAME: layer->III()
+ * DESCRIPTION: decode a single Layer III frame
+ */
+int mad_layer_III(struct mad_stream *stream, struct mad_frame *frame)
+{
+ struct mad_header *header = &frame->header;
+ unsigned int nch, priv_bitlen, next_md_begin = 0;
+ unsigned int si_len, data_bitlen, md_len;
+ unsigned int frame_space, frame_used, frame_free;
+ struct mad_bitptr ptr;
+ struct sideinfo si;
+ enum mad_error error;
+ int result = 0;
+
+ /* allocate Layer III dynamic structures */
+
+ if (stream->main_data == 0) {
+ stream->main_data = malloc(MAD_BUFFER_MDLEN);
+ if (stream->main_data == 0) {
+ stream->error = MAD_ERROR_NOMEM;
+ return -1;
+ }
+ }
+
+ if (frame->overlap == 0) {
+ frame->overlap = calloc(2 * 32 * 18, sizeof(mad_fixed_t));
+ if (frame->overlap == 0) {
+ stream->error = MAD_ERROR_NOMEM;
+ return -1;
+ }
+ }
+
+ nch = MAD_NCHANNELS(header);
+ si_len = (header->flags & MAD_FLAG_LSF_EXT) ?
+ (nch == 1 ? 9 : 17) : (nch == 1 ? 17 : 32);
+
+ /* check frame sanity */
+
+ if (stream->next_frame - mad_bit_nextbyte(&stream->ptr) <
+ (signed int) si_len) {
+ stream->error = MAD_ERROR_BADFRAMELEN;
+ stream->md_len = 0;
+ return -1;
+ }
+
+ /* check CRC word */
+
+ if (header->flags & MAD_FLAG_PROTECTION) {
+ header->crc_check =
+ mad_bit_crc(stream->ptr, si_len * CHAR_BIT, header->crc_check);
+
+ if (header->crc_check != header->crc_target &&
+ !(frame->options & MAD_OPTION_IGNORECRC)) {
+ stream->error = MAD_ERROR_BADCRC;
+ result = -1;
+ }
+ }
+
+ /* decode frame side information */
+
+ error = III_sideinfo(&stream->ptr, nch, header->flags & MAD_FLAG_LSF_EXT,
+ &si, &data_bitlen, &priv_bitlen);
+ if (error && result == 0) {
+ stream->error = error;
+ result = -1;
+ }
+
+ header->flags |= priv_bitlen;
+ header->private_bits |= si.private_bits;
+
+ /* find main_data of next frame */
+
+ {
+ struct mad_bitptr peek;
+ unsigned long header;
+
+ mad_bit_init(&peek, stream->next_frame);
+
+ header = mad_bit_read(&peek, 32);
+ if ((header & 0xffe60000L) /* syncword | layer */ == 0xffe20000L) {
+ if (!(header & 0x00010000L)) /* protection_bit */
+ mad_bit_skip(&peek, 16); /* crc_check */
+
+ next_md_begin =
+ mad_bit_read(&peek, (header & 0x00080000L) /* ID */ ? 9 : 8);
+ }
+
+ mad_bit_finish(&peek);
+ }
+
+ /* find main_data of this frame */
+
+ frame_space = stream->next_frame - mad_bit_nextbyte(&stream->ptr);
+
+ if (next_md_begin > si.main_data_begin + frame_space)
+ next_md_begin = 0;
+
+ md_len = si.main_data_begin + frame_space - next_md_begin;
+
+ frame_used = 0;
+
+ if (si.main_data_begin == 0) {
+ ptr = stream->ptr;
+ stream->md_len = 0;
+
+ frame_used = md_len;
+ }
+ else {
+ if (si.main_data_begin > stream->md_len) {
+ if (result == 0) {
+ stream->error = MAD_ERROR_BADDATAPTR;
+ result = -1;
+ }
+ }
+ else {
+ mad_bit_init(&ptr,
+ *stream->main_data + stream->md_len - si.main_data_begin);
+
+ if (md_len > si.main_data_begin) {
+ assert(stream->md_len + md_len -
+ si.main_data_begin <= MAD_BUFFER_MDLEN);
+
+ memcpy(*stream->main_data + stream->md_len,
+ mad_bit_nextbyte(&stream->ptr),
+ frame_used = md_len - si.main_data_begin);
+ stream->md_len += frame_used;
+ }
+ }
+ }
+
+ frame_free = frame_space - frame_used;
+
+ /* decode main_data */
+
+ if (result == 0) {
+ error = III_decode(&ptr, frame, &si, nch);
+ if (error) {
+ stream->error = error;
+ result = -1;
+ }
+
+ /* designate ancillary bits */
+
+ stream->anc_ptr = ptr;
+ stream->anc_bitlen = md_len * CHAR_BIT - data_bitlen;
+ }
+
+# if 0 && defined(DEBUG)
+ fprintf(stderr,
+ "main_data_begin:%u, md_len:%u, frame_free:%u, "
+ "data_bitlen:%u, anc_bitlen: %u\n",
+ si.main_data_begin, md_len, frame_free,
+ data_bitlen, stream->anc_bitlen);
+# endif
+
+ /* preload main_data buffer with up to 511 bytes for next frame(s) */
+
+ if (frame_free >= next_md_begin) {
+ memcpy(*stream->main_data,
+ stream->next_frame - next_md_begin, next_md_begin);
+ stream->md_len = next_md_begin;
+ }
+ else {
+ if (md_len < si.main_data_begin) {
+ unsigned int extra;
+
+ extra = si.main_data_begin - md_len;
+ if (extra + frame_free > next_md_begin)
+ extra = next_md_begin - frame_free;
+
+ if (extra < stream->md_len) {
+ memmove(*stream->main_data,
+ *stream->main_data + stream->md_len - extra, extra);
+ stream->md_len = extra;
+ }
+ }
+ else
+ stream->md_len = 0;
+
+ memcpy(*stream->main_data + stream->md_len,
+ stream->next_frame - frame_free, frame_free);
+ stream->md_len += frame_free;
+ }
+
+ return result;
+}
diff --git a/contrib/libmad/layer3.h b/contrib/libmad/layer3.h
new file mode 100644
index 000000000..2504d461a
--- /dev/null
+++ b/contrib/libmad/layer3.h
@@ -0,0 +1,30 @@
+/*
+ * libmad - MPEG audio decoder library
+ * Copyright (C) 2000-2004 Underbit Technologies, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: layer3.h,v 1.10 2004/01/23 09:41:32 rob Exp $
+ */
+
+# ifndef LIBMAD_LAYER3_H
+# define LIBMAD_LAYER3_H
+
+# include "stream.h"
+# include "frame.h"
+
+int mad_layer_III(struct mad_stream *, struct mad_frame *);
+
+# endif
diff --git a/contrib/libmad/qc_table.dat b/contrib/libmad/qc_table.dat
new file mode 100644
index 000000000..35a22234f
--- /dev/null
+++ b/contrib/libmad/qc_table.dat
@@ -0,0 +1,77 @@
+/*
+ * libmad - MPEG audio decoder library
+ * Copyright (C) 2000-2004 Underbit Technologies, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: qc_table.dat,v 1.7 2004/01/23 09:41:32 rob Exp $
+ */
+
+/*
+ * These are the Layer II classes of quantization.
+ * The table is derived from Table B.4 of ISO/IEC 11172-3.
+ */
+
+ { 3, 2, 5,
+ MAD_F(0x15555555) /* 1.33333333333 => 1.33333333209, e 0.00000000124 */,
+ MAD_F(0x08000000) /* 0.50000000000 => 0.50000000000, e 0.00000000000 */ },
+ { 5, 3, 7,
+ MAD_F(0x1999999a) /* 1.60000000000 => 1.60000000149, e -0.00000000149 */,
+ MAD_F(0x08000000) /* 0.50000000000 => 0.50000000000, e 0.00000000000 */ },
+ { 7, 0, 3,
+ MAD_F(0x12492492) /* 1.14285714286 => 1.14285714179, e 0.00000000107 */,
+ MAD_F(0x04000000) /* 0.25000000000 => 0.25000000000, e 0.00000000000 */ },
+ { 9, 4, 10,
+ MAD_F(0x1c71c71c) /* 1.77777777777 => 1.77777777612, e 0.00000000165 */,
+ MAD_F(0x08000000) /* 0.50000000000 => 0.50000000000, e 0.00000000000 */ },
+ { 15, 0, 4,
+ MAD_F(0x11111111) /* 1.06666666666 => 1.06666666642, e 0.00000000024 */,
+ MAD_F(0x02000000) /* 0.12500000000 => 0.12500000000, e 0.00000000000 */ },
+ { 31, 0, 5,
+ MAD_F(0x10842108) /* 1.03225806452 => 1.03225806355, e 0.00000000097 */,
+ MAD_F(0x01000000) /* 0.06250000000 => 0.06250000000, e 0.00000000000 */ },
+ { 63, 0, 6,
+ MAD_F(0x10410410) /* 1.01587301587 => 1.01587301493, e 0.00000000094 */,
+ MAD_F(0x00800000) /* 0.03125000000 => 0.03125000000, e 0.00000000000 */ },
+ { 127, 0, 7,
+ MAD_F(0x10204081) /* 1.00787401575 => 1.00787401572, e 0.00000000003 */,
+ MAD_F(0x00400000) /* 0.01562500000 => 0.01562500000, e 0.00000000000 */ },
+ { 255, 0, 8,
+ MAD_F(0x10101010) /* 1.00392156863 => 1.00392156839, e 0.00000000024 */,
+ MAD_F(0x00200000) /* 0.00781250000 => 0.00781250000, e 0.00000000000 */ },
+ { 511, 0, 9,
+ MAD_F(0x10080402) /* 1.00195694716 => 1.00195694715, e 0.00000000001 */,
+ MAD_F(0x00100000) /* 0.00390625000 => 0.00390625000, e 0.00000000000 */ },
+ { 1023, 0, 10,
+ MAD_F(0x10040100) /* 1.00097751711 => 1.00097751617, e 0.00000000094 */,
+ MAD_F(0x00080000) /* 0.00195312500 => 0.00195312500, e 0.00000000000 */ },
+ { 2047, 0, 11,
+ MAD_F(0x10020040) /* 1.00048851979 => 1.00048851967, e 0.00000000012 */,
+ MAD_F(0x00040000) /* 0.00097656250 => 0.00097656250, e 0.00000000000 */ },
+ { 4095, 0, 12,
+ MAD_F(0x10010010) /* 1.00024420024 => 1.00024420023, e 0.00000000001 */,
+ MAD_F(0x00020000) /* 0.00048828125 => 0.00048828125, e 0.00000000000 */ },
+ { 8191, 0, 13,
+ MAD_F(0x10008004) /* 1.00012208522 => 1.00012208521, e 0.00000000001 */,
+ MAD_F(0x00010000) /* 0.00024414063 => 0.00024414062, e 0.00000000000 */ },
+ { 16383, 0, 14,
+ MAD_F(0x10004001) /* 1.00006103888 => 1.00006103888, e -0.00000000000 */,
+ MAD_F(0x00008000) /* 0.00012207031 => 0.00012207031, e -0.00000000000 */ },
+ { 32767, 0, 15,
+ MAD_F(0x10002000) /* 1.00003051851 => 1.00003051758, e 0.00000000093 */,
+ MAD_F(0x00004000) /* 0.00006103516 => 0.00006103516, e 0.00000000000 */ },
+ { 65535, 0, 16,
+ MAD_F(0x10001000) /* 1.00001525902 => 1.00001525879, e 0.00000000023 */,
+ MAD_F(0x00002000) /* 0.00003051758 => 0.00003051758, e 0.00000000000 */ }
diff --git a/contrib/libmad/rq_table.dat b/contrib/libmad/rq_table.dat
new file mode 100644
index 000000000..059c4f318
--- /dev/null
+++ b/contrib/libmad/rq_table.dat
@@ -0,0 +1,8747 @@
+/*
+ * libmad - MPEG audio decoder library
+ * Copyright (C) 2000-2004 Underbit Technologies, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: rq_table.dat,v 1.7 2004/01/23 09:41:32 rob Exp $
+ */
+
+/*
+ * This is the lookup table used to compute x^(4/3) for Layer III
+ * requantization. To maintain the best possible accuracy, the value is
+ * stored as a normalized mantissa with exponent. The requantization
+ * algorithm recombines these parts with appropriate scaling.
+ */
+
+ /* 0 */ { MAD_F(0x00000000) /* 0.000000000 */, 0 },
+ /* 1 */ { MAD_F(0x04000000) /* 0.250000000 */, 2 },
+ /* 2 */ { MAD_F(0x050a28be) /* 0.314980262 */, 3 },
+ /* 3 */ { MAD_F(0x0453a5cd) /* 0.270421794 */, 4 },
+ /* 4 */ { MAD_F(0x06597fa9) /* 0.396850263 */, 4 },
+ /* 5 */ { MAD_F(0x04466275) /* 0.267183742 */, 5 },
+ /* 6 */ { MAD_F(0x05738c72) /* 0.340710111 */, 5 },
+ /* 7 */ { MAD_F(0x06b1fc81) /* 0.418453696 */, 5 },
+ /* 8 */ { MAD_F(0x04000000) /* 0.250000000 */, 6 },
+ /* 9 */ { MAD_F(0x04ae20d7) /* 0.292511788 */, 6 },
+ /* 10 */ { MAD_F(0x0562d694) /* 0.336630420 */, 6 },
+ /* 11 */ { MAD_F(0x061dae96) /* 0.382246578 */, 6 },
+ /* 12 */ { MAD_F(0x06de47f4) /* 0.429267841 */, 6 },
+ /* 13 */ { MAD_F(0x07a44f7a) /* 0.477614858 */, 6 },
+ /* 14 */ { MAD_F(0x0437be65) /* 0.263609310 */, 7 },
+ /* 15 */ { MAD_F(0x049fc824) /* 0.289009227 */, 7 },
+
+ /* 16 */ { MAD_F(0x050a28be) /* 0.314980262 */, 7 },
+ /* 17 */ { MAD_F(0x0576c6f5) /* 0.341498336 */, 7 },
+ /* 18 */ { MAD_F(0x05e58c0b) /* 0.368541759 */, 7 },
+ /* 19 */ { MAD_F(0x06566361) /* 0.396090870 */, 7 },
+ /* 20 */ { MAD_F(0x06c93a2e) /* 0.424127753 */, 7 },
+ /* 21 */ { MAD_F(0x073dff3e) /* 0.452635998 */, 7 },
+ /* 22 */ { MAD_F(0x07b4a2bc) /* 0.481600510 */, 7 },
+ /* 23 */ { MAD_F(0x04168b05) /* 0.255503674 */, 8 },
+ /* 24 */ { MAD_F(0x0453a5cd) /* 0.270421794 */, 8 },
+ /* 25 */ { MAD_F(0x04919b6a) /* 0.285548607 */, 8 },
+ /* 26 */ { MAD_F(0x04d065fb) /* 0.300878507 */, 8 },
+ /* 27 */ { MAD_F(0x05100000) /* 0.316406250 */, 8 },
+ /* 28 */ { MAD_F(0x05506451) /* 0.332126919 */, 8 },
+ /* 29 */ { MAD_F(0x05918e15) /* 0.348035890 */, 8 },
+ /* 30 */ { MAD_F(0x05d378bb) /* 0.364128809 */, 8 },
+ /* 31 */ { MAD_F(0x06161ff3) /* 0.380401563 */, 8 },
+
+ /* 32 */ { MAD_F(0x06597fa9) /* 0.396850263 */, 8 },
+ /* 33 */ { MAD_F(0x069d9400) /* 0.413471222 */, 8 },
+ /* 34 */ { MAD_F(0x06e2594c) /* 0.430260942 */, 8 },
+ /* 35 */ { MAD_F(0x0727cc11) /* 0.447216097 */, 8 },
+ /* 36 */ { MAD_F(0x076de8fc) /* 0.464333519 */, 8 },
+ /* 37 */ { MAD_F(0x07b4ace3) /* 0.481610189 */, 8 },
+ /* 38 */ { MAD_F(0x07fc14bf) /* 0.499043224 */, 8 },
+ /* 39 */ { MAD_F(0x04220ed7) /* 0.258314934 */, 9 },
+ /* 40 */ { MAD_F(0x04466275) /* 0.267183742 */, 9 },
+ /* 41 */ { MAD_F(0x046b03e7) /* 0.276126771 */, 9 },
+ /* 42 */ { MAD_F(0x048ff1e8) /* 0.285142811 */, 9 },
+ /* 43 */ { MAD_F(0x04b52b3f) /* 0.294230696 */, 9 },
+ /* 44 */ { MAD_F(0x04daaec0) /* 0.303389310 */, 9 },
+ /* 45 */ { MAD_F(0x05007b49) /* 0.312617576 */, 9 },
+ /* 46 */ { MAD_F(0x05268fc6) /* 0.321914457 */, 9 },
+ /* 47 */ { MAD_F(0x054ceb2a) /* 0.331278957 */, 9 },
+
+ /* 48 */ { MAD_F(0x05738c72) /* 0.340710111 */, 9 },
+ /* 49 */ { MAD_F(0x059a72a5) /* 0.350206992 */, 9 },
+ /* 50 */ { MAD_F(0x05c19cd3) /* 0.359768701 */, 9 },
+ /* 51 */ { MAD_F(0x05e90a12) /* 0.369394372 */, 9 },
+ /* 52 */ { MAD_F(0x0610b982) /* 0.379083164 */, 9 },
+ /* 53 */ { MAD_F(0x0638aa48) /* 0.388834268 */, 9 },
+ /* 54 */ { MAD_F(0x0660db91) /* 0.398646895 */, 9 },
+ /* 55 */ { MAD_F(0x06894c90) /* 0.408520284 */, 9 },
+ /* 56 */ { MAD_F(0x06b1fc81) /* 0.418453696 */, 9 },
+ /* 57 */ { MAD_F(0x06daeaa1) /* 0.428446415 */, 9 },
+ /* 58 */ { MAD_F(0x07041636) /* 0.438497744 */, 9 },
+ /* 59 */ { MAD_F(0x072d7e8b) /* 0.448607009 */, 9 },
+ /* 60 */ { MAD_F(0x075722ef) /* 0.458773552 */, 9 },
+ /* 61 */ { MAD_F(0x078102b8) /* 0.468996735 */, 9 },
+ /* 62 */ { MAD_F(0x07ab1d3e) /* 0.479275937 */, 9 },
+ /* 63 */ { MAD_F(0x07d571e0) /* 0.489610555 */, 9 },
+
+ /* 64 */ { MAD_F(0x04000000) /* 0.250000000 */, 10 },
+ /* 65 */ { MAD_F(0x04156381) /* 0.255221850 */, 10 },
+ /* 66 */ { MAD_F(0x042ae32a) /* 0.260470548 */, 10 },
+ /* 67 */ { MAD_F(0x04407eb1) /* 0.265745823 */, 10 },
+ /* 68 */ { MAD_F(0x045635cf) /* 0.271047409 */, 10 },
+ /* 69 */ { MAD_F(0x046c083e) /* 0.276375048 */, 10 },
+ /* 70 */ { MAD_F(0x0481f5bb) /* 0.281728487 */, 10 },
+ /* 71 */ { MAD_F(0x0497fe03) /* 0.287107481 */, 10 },
+ /* 72 */ { MAD_F(0x04ae20d7) /* 0.292511788 */, 10 },
+ /* 73 */ { MAD_F(0x04c45df6) /* 0.297941173 */, 10 },
+ /* 74 */ { MAD_F(0x04dab524) /* 0.303395408 */, 10 },
+ /* 75 */ { MAD_F(0x04f12624) /* 0.308874267 */, 10 },
+ /* 76 */ { MAD_F(0x0507b0bc) /* 0.314377532 */, 10 },
+ /* 77 */ { MAD_F(0x051e54b1) /* 0.319904987 */, 10 },
+ /* 78 */ { MAD_F(0x053511cb) /* 0.325456423 */, 10 },
+ /* 79 */ { MAD_F(0x054be7d4) /* 0.331031635 */, 10 },
+
+ /* 80 */ { MAD_F(0x0562d694) /* 0.336630420 */, 10 },
+ /* 81 */ { MAD_F(0x0579ddd8) /* 0.342252584 */, 10 },
+ /* 82 */ { MAD_F(0x0590fd6c) /* 0.347897931 */, 10 },
+ /* 83 */ { MAD_F(0x05a8351c) /* 0.353566275 */, 10 },
+ /* 84 */ { MAD_F(0x05bf84b8) /* 0.359257429 */, 10 },
+ /* 85 */ { MAD_F(0x05d6ec0e) /* 0.364971213 */, 10 },
+ /* 86 */ { MAD_F(0x05ee6aef) /* 0.370707448 */, 10 },
+ /* 87 */ { MAD_F(0x0606012b) /* 0.376465960 */, 10 },
+ /* 88 */ { MAD_F(0x061dae96) /* 0.382246578 */, 10 },
+ /* 89 */ { MAD_F(0x06357302) /* 0.388049134 */, 10 },
+ /* 90 */ { MAD_F(0x064d4e43) /* 0.393873464 */, 10 },
+ /* 91 */ { MAD_F(0x0665402d) /* 0.399719406 */, 10 },
+ /* 92 */ { MAD_F(0x067d4896) /* 0.405586801 */, 10 },
+ /* 93 */ { MAD_F(0x06956753) /* 0.411475493 */, 10 },
+ /* 94 */ { MAD_F(0x06ad9c3d) /* 0.417385331 */, 10 },
+ /* 95 */ { MAD_F(0x06c5e72b) /* 0.423316162 */, 10 },
+
+ /* 96 */ { MAD_F(0x06de47f4) /* 0.429267841 */, 10 },
+ /* 97 */ { MAD_F(0x06f6be73) /* 0.435240221 */, 10 },
+ /* 98 */ { MAD_F(0x070f4a80) /* 0.441233161 */, 10 },
+ /* 99 */ { MAD_F(0x0727ebf7) /* 0.447246519 */, 10 },
+ /* 100 */ { MAD_F(0x0740a2b2) /* 0.453280160 */, 10 },
+ /* 101 */ { MAD_F(0x07596e8d) /* 0.459333946 */, 10 },
+ /* 102 */ { MAD_F(0x07724f64) /* 0.465407744 */, 10 },
+ /* 103 */ { MAD_F(0x078b4514) /* 0.471501425 */, 10 },
+ /* 104 */ { MAD_F(0x07a44f7a) /* 0.477614858 */, 10 },
+ /* 105 */ { MAD_F(0x07bd6e75) /* 0.483747918 */, 10 },
+ /* 106 */ { MAD_F(0x07d6a1e2) /* 0.489900479 */, 10 },
+ /* 107 */ { MAD_F(0x07efe9a1) /* 0.496072418 */, 10 },
+ /* 108 */ { MAD_F(0x0404a2c9) /* 0.251131807 */, 11 },
+ /* 109 */ { MAD_F(0x04115aca) /* 0.254236974 */, 11 },
+ /* 110 */ { MAD_F(0x041e1cc4) /* 0.257351652 */, 11 },
+ /* 111 */ { MAD_F(0x042ae8a7) /* 0.260475783 */, 11 },
+
+ /* 112 */ { MAD_F(0x0437be65) /* 0.263609310 */, 11 },
+ /* 113 */ { MAD_F(0x04449dee) /* 0.266752177 */, 11 },
+ /* 114 */ { MAD_F(0x04518733) /* 0.269904329 */, 11 },
+ /* 115 */ { MAD_F(0x045e7a26) /* 0.273065710 */, 11 },
+ /* 116 */ { MAD_F(0x046b76b9) /* 0.276236269 */, 11 },
+ /* 117 */ { MAD_F(0x04787cdc) /* 0.279415952 */, 11 },
+ /* 118 */ { MAD_F(0x04858c83) /* 0.282604707 */, 11 },
+ /* 119 */ { MAD_F(0x0492a59f) /* 0.285802482 */, 11 },
+ /* 120 */ { MAD_F(0x049fc824) /* 0.289009227 */, 11 },
+ /* 121 */ { MAD_F(0x04acf402) /* 0.292224893 */, 11 },
+ /* 122 */ { MAD_F(0x04ba292e) /* 0.295449429 */, 11 },
+ /* 123 */ { MAD_F(0x04c7679a) /* 0.298682788 */, 11 },
+ /* 124 */ { MAD_F(0x04d4af3a) /* 0.301924921 */, 11 },
+ /* 125 */ { MAD_F(0x04e20000) /* 0.305175781 */, 11 },
+ /* 126 */ { MAD_F(0x04ef59e0) /* 0.308435322 */, 11 },
+ /* 127 */ { MAD_F(0x04fcbcce) /* 0.311703498 */, 11 },
+
+ /* 128 */ { MAD_F(0x050a28be) /* 0.314980262 */, 11 },
+ /* 129 */ { MAD_F(0x05179da4) /* 0.318265572 */, 11 },
+ /* 130 */ { MAD_F(0x05251b73) /* 0.321559381 */, 11 },
+ /* 131 */ { MAD_F(0x0532a220) /* 0.324861647 */, 11 },
+ /* 132 */ { MAD_F(0x054031a0) /* 0.328172327 */, 11 },
+ /* 133 */ { MAD_F(0x054dc9e7) /* 0.331491377 */, 11 },
+ /* 134 */ { MAD_F(0x055b6ae9) /* 0.334818756 */, 11 },
+ /* 135 */ { MAD_F(0x0569149c) /* 0.338154423 */, 11 },
+ /* 136 */ { MAD_F(0x0576c6f5) /* 0.341498336 */, 11 },
+ /* 137 */ { MAD_F(0x058481e9) /* 0.344850455 */, 11 },
+ /* 138 */ { MAD_F(0x0592456d) /* 0.348210741 */, 11 },
+ /* 139 */ { MAD_F(0x05a01176) /* 0.351579152 */, 11 },
+ /* 140 */ { MAD_F(0x05ade5fa) /* 0.354955651 */, 11 },
+ /* 141 */ { MAD_F(0x05bbc2ef) /* 0.358340200 */, 11 },
+ /* 142 */ { MAD_F(0x05c9a84a) /* 0.361732758 */, 11 },
+ /* 143 */ { MAD_F(0x05d79601) /* 0.365133291 */, 11 },
+
+ /* 144 */ { MAD_F(0x05e58c0b) /* 0.368541759 */, 11 },
+ /* 145 */ { MAD_F(0x05f38a5d) /* 0.371958126 */, 11 },
+ /* 146 */ { MAD_F(0x060190ee) /* 0.375382356 */, 11 },
+ /* 147 */ { MAD_F(0x060f9fb3) /* 0.378814413 */, 11 },
+ /* 148 */ { MAD_F(0x061db6a5) /* 0.382254261 */, 11 },
+ /* 149 */ { MAD_F(0x062bd5b8) /* 0.385701865 */, 11 },
+ /* 150 */ { MAD_F(0x0639fce4) /* 0.389157191 */, 11 },
+ /* 151 */ { MAD_F(0x06482c1f) /* 0.392620204 */, 11 },
+ /* 152 */ { MAD_F(0x06566361) /* 0.396090870 */, 11 },
+ /* 153 */ { MAD_F(0x0664a2a0) /* 0.399569155 */, 11 },
+ /* 154 */ { MAD_F(0x0672e9d4) /* 0.403055027 */, 11 },
+ /* 155 */ { MAD_F(0x068138f3) /* 0.406548452 */, 11 },
+ /* 156 */ { MAD_F(0x068f8ff5) /* 0.410049398 */, 11 },
+ /* 157 */ { MAD_F(0x069deed1) /* 0.413557833 */, 11 },
+ /* 158 */ { MAD_F(0x06ac557f) /* 0.417073724 */, 11 },
+ /* 159 */ { MAD_F(0x06bac3f6) /* 0.420597041 */, 11 },
+
+ /* 160 */ { MAD_F(0x06c93a2e) /* 0.424127753 */, 11 },
+ /* 161 */ { MAD_F(0x06d7b81f) /* 0.427665827 */, 11 },
+ /* 162 */ { MAD_F(0x06e63dc0) /* 0.431211234 */, 11 },
+ /* 163 */ { MAD_F(0x06f4cb09) /* 0.434763944 */, 11 },
+ /* 164 */ { MAD_F(0x07035ff3) /* 0.438323927 */, 11 },
+ /* 165 */ { MAD_F(0x0711fc75) /* 0.441891153 */, 11 },
+ /* 166 */ { MAD_F(0x0720a087) /* 0.445465593 */, 11 },
+ /* 167 */ { MAD_F(0x072f4c22) /* 0.449047217 */, 11 },
+ /* 168 */ { MAD_F(0x073dff3e) /* 0.452635998 */, 11 },
+ /* 169 */ { MAD_F(0x074cb9d3) /* 0.456231906 */, 11 },
+ /* 170 */ { MAD_F(0x075b7bdb) /* 0.459834914 */, 11 },
+ /* 171 */ { MAD_F(0x076a454c) /* 0.463444993 */, 11 },
+ /* 172 */ { MAD_F(0x07791620) /* 0.467062117 */, 11 },
+ /* 173 */ { MAD_F(0x0787ee50) /* 0.470686258 */, 11 },
+ /* 174 */ { MAD_F(0x0796cdd4) /* 0.474317388 */, 11 },
+ /* 175 */ { MAD_F(0x07a5b4a5) /* 0.477955481 */, 11 },
+
+ /* 176 */ { MAD_F(0x07b4a2bc) /* 0.481600510 */, 11 },
+ /* 177 */ { MAD_F(0x07c39812) /* 0.485252449 */, 11 },
+ /* 178 */ { MAD_F(0x07d294a0) /* 0.488911273 */, 11 },
+ /* 179 */ { MAD_F(0x07e1985f) /* 0.492576954 */, 11 },
+ /* 180 */ { MAD_F(0x07f0a348) /* 0.496249468 */, 11 },
+ /* 181 */ { MAD_F(0x07ffb554) /* 0.499928790 */, 11 },
+ /* 182 */ { MAD_F(0x0407673f) /* 0.251807447 */, 12 },
+ /* 183 */ { MAD_F(0x040ef75e) /* 0.253653877 */, 12 },
+ /* 184 */ { MAD_F(0x04168b05) /* 0.255503674 */, 12 },
+ /* 185 */ { MAD_F(0x041e2230) /* 0.257356825 */, 12 },
+ /* 186 */ { MAD_F(0x0425bcdd) /* 0.259213318 */, 12 },
+ /* 187 */ { MAD_F(0x042d5b07) /* 0.261073141 */, 12 },
+ /* 188 */ { MAD_F(0x0434fcad) /* 0.262936282 */, 12 },
+ /* 189 */ { MAD_F(0x043ca1c9) /* 0.264802730 */, 12 },
+ /* 190 */ { MAD_F(0x04444a5a) /* 0.266672472 */, 12 },
+ /* 191 */ { MAD_F(0x044bf65d) /* 0.268545497 */, 12 },
+
+ /* 192 */ { MAD_F(0x0453a5cd) /* 0.270421794 */, 12 },
+ /* 193 */ { MAD_F(0x045b58a9) /* 0.272301352 */, 12 },
+ /* 194 */ { MAD_F(0x04630eed) /* 0.274184158 */, 12 },
+ /* 195 */ { MAD_F(0x046ac896) /* 0.276070203 */, 12 },
+ /* 196 */ { MAD_F(0x047285a2) /* 0.277959474 */, 12 },
+ /* 197 */ { MAD_F(0x047a460c) /* 0.279851960 */, 12 },
+ /* 198 */ { MAD_F(0x048209d3) /* 0.281747652 */, 12 },
+ /* 199 */ { MAD_F(0x0489d0f4) /* 0.283646538 */, 12 },
+ /* 200 */ { MAD_F(0x04919b6a) /* 0.285548607 */, 12 },
+ /* 201 */ { MAD_F(0x04996935) /* 0.287453849 */, 12 },
+ /* 202 */ { MAD_F(0x04a13a50) /* 0.289362253 */, 12 },
+ /* 203 */ { MAD_F(0x04a90eba) /* 0.291273810 */, 12 },
+ /* 204 */ { MAD_F(0x04b0e66e) /* 0.293188507 */, 12 },
+ /* 205 */ { MAD_F(0x04b8c16c) /* 0.295106336 */, 12 },
+ /* 206 */ { MAD_F(0x04c09faf) /* 0.297027285 */, 12 },
+ /* 207 */ { MAD_F(0x04c88135) /* 0.298951346 */, 12 },
+
+ /* 208 */ { MAD_F(0x04d065fb) /* 0.300878507 */, 12 },
+ /* 209 */ { MAD_F(0x04d84dff) /* 0.302808759 */, 12 },
+ /* 210 */ { MAD_F(0x04e0393e) /* 0.304742092 */, 12 },
+ /* 211 */ { MAD_F(0x04e827b6) /* 0.306678497 */, 12 },
+ /* 212 */ { MAD_F(0x04f01963) /* 0.308617963 */, 12 },
+ /* 213 */ { MAD_F(0x04f80e44) /* 0.310560480 */, 12 },
+ /* 214 */ { MAD_F(0x05000655) /* 0.312506041 */, 12 },
+ /* 215 */ { MAD_F(0x05080195) /* 0.314454634 */, 12 },
+ /* 216 */ { MAD_F(0x05100000) /* 0.316406250 */, 12 },
+ /* 217 */ { MAD_F(0x05180194) /* 0.318360880 */, 12 },
+ /* 218 */ { MAD_F(0x0520064f) /* 0.320318516 */, 12 },
+ /* 219 */ { MAD_F(0x05280e2d) /* 0.322279147 */, 12 },
+ /* 220 */ { MAD_F(0x0530192e) /* 0.324242764 */, 12 },
+ /* 221 */ { MAD_F(0x0538274e) /* 0.326209359 */, 12 },
+ /* 222 */ { MAD_F(0x0540388a) /* 0.328178922 */, 12 },
+ /* 223 */ { MAD_F(0x05484ce2) /* 0.330151445 */, 12 },
+
+ /* 224 */ { MAD_F(0x05506451) /* 0.332126919 */, 12 },
+ /* 225 */ { MAD_F(0x05587ed5) /* 0.334105334 */, 12 },
+ /* 226 */ { MAD_F(0x05609c6e) /* 0.336086683 */, 12 },
+ /* 227 */ { MAD_F(0x0568bd17) /* 0.338070956 */, 12 },
+ /* 228 */ { MAD_F(0x0570e0cf) /* 0.340058145 */, 12 },
+ /* 229 */ { MAD_F(0x05790793) /* 0.342048241 */, 12 },
+ /* 230 */ { MAD_F(0x05813162) /* 0.344041237 */, 12 },
+ /* 231 */ { MAD_F(0x05895e39) /* 0.346037122 */, 12 },
+ /* 232 */ { MAD_F(0x05918e15) /* 0.348035890 */, 12 },
+ /* 233 */ { MAD_F(0x0599c0f4) /* 0.350037532 */, 12 },
+ /* 234 */ { MAD_F(0x05a1f6d5) /* 0.352042040 */, 12 },
+ /* 235 */ { MAD_F(0x05aa2fb5) /* 0.354049405 */, 12 },
+ /* 236 */ { MAD_F(0x05b26b92) /* 0.356059619 */, 12 },
+ /* 237 */ { MAD_F(0x05baaa69) /* 0.358072674 */, 12 },
+ /* 238 */ { MAD_F(0x05c2ec39) /* 0.360088563 */, 12 },
+ /* 239 */ { MAD_F(0x05cb3100) /* 0.362107278 */, 12 },
+
+ /* 240 */ { MAD_F(0x05d378bb) /* 0.364128809 */, 12 },
+ /* 241 */ { MAD_F(0x05dbc368) /* 0.366153151 */, 12 },
+ /* 242 */ { MAD_F(0x05e41105) /* 0.368180294 */, 12 },
+ /* 243 */ { MAD_F(0x05ec6190) /* 0.370210231 */, 12 },
+ /* 244 */ { MAD_F(0x05f4b507) /* 0.372242955 */, 12 },
+ /* 245 */ { MAD_F(0x05fd0b68) /* 0.374278458 */, 12 },
+ /* 246 */ { MAD_F(0x060564b1) /* 0.376316732 */, 12 },
+ /* 247 */ { MAD_F(0x060dc0e0) /* 0.378357769 */, 12 },
+ /* 248 */ { MAD_F(0x06161ff3) /* 0.380401563 */, 12 },
+ /* 249 */ { MAD_F(0x061e81e8) /* 0.382448106 */, 12 },
+ /* 250 */ { MAD_F(0x0626e6bc) /* 0.384497391 */, 12 },
+ /* 251 */ { MAD_F(0x062f4e6f) /* 0.386549409 */, 12 },
+ /* 252 */ { MAD_F(0x0637b8fd) /* 0.388604155 */, 12 },
+ /* 253 */ { MAD_F(0x06402666) /* 0.390661620 */, 12 },
+ /* 254 */ { MAD_F(0x064896a7) /* 0.392721798 */, 12 },
+ /* 255 */ { MAD_F(0x065109be) /* 0.394784681 */, 12 },
+
+ /* 256 */ { MAD_F(0x06597fa9) /* 0.396850263 */, 12 },
+ /* 257 */ { MAD_F(0x0661f867) /* 0.398918536 */, 12 },
+ /* 258 */ { MAD_F(0x066a73f5) /* 0.400989493 */, 12 },
+ /* 259 */ { MAD_F(0x0672f252) /* 0.403063128 */, 12 },
+ /* 260 */ { MAD_F(0x067b737c) /* 0.405139433 */, 12 },
+ /* 261 */ { MAD_F(0x0683f771) /* 0.407218402 */, 12 },
+ /* 262 */ { MAD_F(0x068c7e2f) /* 0.409300027 */, 12 },
+ /* 263 */ { MAD_F(0x069507b5) /* 0.411384303 */, 12 },
+ /* 264 */ { MAD_F(0x069d9400) /* 0.413471222 */, 12 },
+ /* 265 */ { MAD_F(0x06a6230f) /* 0.415560778 */, 12 },
+ /* 266 */ { MAD_F(0x06aeb4e0) /* 0.417652964 */, 12 },
+ /* 267 */ { MAD_F(0x06b74971) /* 0.419747773 */, 12 },
+ /* 268 */ { MAD_F(0x06bfe0c0) /* 0.421845199 */, 12 },
+ /* 269 */ { MAD_F(0x06c87acc) /* 0.423945235 */, 12 },
+ /* 270 */ { MAD_F(0x06d11794) /* 0.426047876 */, 12 },
+ /* 271 */ { MAD_F(0x06d9b714) /* 0.428153114 */, 12 },
+
+ /* 272 */ { MAD_F(0x06e2594c) /* 0.430260942 */, 12 },
+ /* 273 */ { MAD_F(0x06eafe3a) /* 0.432371356 */, 12 },
+ /* 274 */ { MAD_F(0x06f3a5dc) /* 0.434484348 */, 12 },
+ /* 275 */ { MAD_F(0x06fc5030) /* 0.436599912 */, 12 },
+ /* 276 */ { MAD_F(0x0704fd35) /* 0.438718042 */, 12 },
+ /* 277 */ { MAD_F(0x070dacea) /* 0.440838732 */, 12 },
+ /* 278 */ { MAD_F(0x07165f4b) /* 0.442961975 */, 12 },
+ /* 279 */ { MAD_F(0x071f1459) /* 0.445087765 */, 12 },
+ /* 280 */ { MAD_F(0x0727cc11) /* 0.447216097 */, 12 },
+ /* 281 */ { MAD_F(0x07308671) /* 0.449346964 */, 12 },
+ /* 282 */ { MAD_F(0x07394378) /* 0.451480360 */, 12 },
+ /* 283 */ { MAD_F(0x07420325) /* 0.453616280 */, 12 },
+ /* 284 */ { MAD_F(0x074ac575) /* 0.455754717 */, 12 },
+ /* 285 */ { MAD_F(0x07538a67) /* 0.457895665 */, 12 },
+ /* 286 */ { MAD_F(0x075c51fa) /* 0.460039119 */, 12 },
+ /* 287 */ { MAD_F(0x07651c2c) /* 0.462185072 */, 12 },
+
+ /* 288 */ { MAD_F(0x076de8fc) /* 0.464333519 */, 12 },
+ /* 289 */ { MAD_F(0x0776b867) /* 0.466484455 */, 12 },
+ /* 290 */ { MAD_F(0x077f8a6d) /* 0.468637872 */, 12 },
+ /* 291 */ { MAD_F(0x07885f0b) /* 0.470793767 */, 12 },
+ /* 292 */ { MAD_F(0x07913641) /* 0.472952132 */, 12 },
+ /* 293 */ { MAD_F(0x079a100c) /* 0.475112962 */, 12 },
+ /* 294 */ { MAD_F(0x07a2ec6c) /* 0.477276252 */, 12 },
+ /* 295 */ { MAD_F(0x07abcb5f) /* 0.479441997 */, 12 },
+ /* 296 */ { MAD_F(0x07b4ace3) /* 0.481610189 */, 12 },
+ /* 297 */ { MAD_F(0x07bd90f6) /* 0.483780825 */, 12 },
+ /* 298 */ { MAD_F(0x07c67798) /* 0.485953899 */, 12 },
+ /* 299 */ { MAD_F(0x07cf60c7) /* 0.488129404 */, 12 },
+ /* 300 */ { MAD_F(0x07d84c81) /* 0.490307336 */, 12 },
+ /* 301 */ { MAD_F(0x07e13ac5) /* 0.492487690 */, 12 },
+ /* 302 */ { MAD_F(0x07ea2b92) /* 0.494670459 */, 12 },
+ /* 303 */ { MAD_F(0x07f31ee6) /* 0.496855639 */, 12 },
+
+ /* 304 */ { MAD_F(0x07fc14bf) /* 0.499043224 */, 12 },
+ /* 305 */ { MAD_F(0x0402868e) /* 0.250616605 */, 13 },
+ /* 306 */ { MAD_F(0x040703ff) /* 0.251712795 */, 13 },
+ /* 307 */ { MAD_F(0x040b82b0) /* 0.252810180 */, 13 },
+ /* 308 */ { MAD_F(0x041002a1) /* 0.253908756 */, 13 },
+ /* 309 */ { MAD_F(0x041483d1) /* 0.255008523 */, 13 },
+ /* 310 */ { MAD_F(0x04190640) /* 0.256109476 */, 13 },
+ /* 311 */ { MAD_F(0x041d89ed) /* 0.257211614 */, 13 },
+ /* 312 */ { MAD_F(0x04220ed7) /* 0.258314934 */, 13 },
+ /* 313 */ { MAD_F(0x042694fe) /* 0.259419433 */, 13 },
+ /* 314 */ { MAD_F(0x042b1c60) /* 0.260525110 */, 13 },
+ /* 315 */ { MAD_F(0x042fa4fe) /* 0.261631960 */, 13 },
+ /* 316 */ { MAD_F(0x04342ed7) /* 0.262739982 */, 13 },
+ /* 317 */ { MAD_F(0x0438b9e9) /* 0.263849174 */, 13 },
+ /* 318 */ { MAD_F(0x043d4635) /* 0.264959533 */, 13 },
+ /* 319 */ { MAD_F(0x0441d3b9) /* 0.266071056 */, 13 },
+
+ /* 320 */ { MAD_F(0x04466275) /* 0.267183742 */, 13 },
+ /* 321 */ { MAD_F(0x044af269) /* 0.268297587 */, 13 },
+ /* 322 */ { MAD_F(0x044f8393) /* 0.269412589 */, 13 },
+ /* 323 */ { MAD_F(0x045415f3) /* 0.270528746 */, 13 },
+ /* 324 */ { MAD_F(0x0458a989) /* 0.271646056 */, 13 },
+ /* 325 */ { MAD_F(0x045d3e53) /* 0.272764515 */, 13 },
+ /* 326 */ { MAD_F(0x0461d451) /* 0.273884123 */, 13 },
+ /* 327 */ { MAD_F(0x04666b83) /* 0.275004875 */, 13 },
+ /* 328 */ { MAD_F(0x046b03e7) /* 0.276126771 */, 13 },
+ /* 329 */ { MAD_F(0x046f9d7e) /* 0.277249808 */, 13 },
+ /* 330 */ { MAD_F(0x04743847) /* 0.278373983 */, 13 },
+ /* 331 */ { MAD_F(0x0478d440) /* 0.279499294 */, 13 },
+ /* 332 */ { MAD_F(0x047d716a) /* 0.280625739 */, 13 },
+ /* 333 */ { MAD_F(0x04820fc3) /* 0.281753315 */, 13 },
+ /* 334 */ { MAD_F(0x0486af4c) /* 0.282882021 */, 13 },
+ /* 335 */ { MAD_F(0x048b5003) /* 0.284011853 */, 13 },
+
+ /* 336 */ { MAD_F(0x048ff1e8) /* 0.285142811 */, 13 },
+ /* 337 */ { MAD_F(0x049494fb) /* 0.286274891 */, 13 },
+ /* 338 */ { MAD_F(0x0499393a) /* 0.287408091 */, 13 },
+ /* 339 */ { MAD_F(0x049ddea5) /* 0.288542409 */, 13 },
+ /* 340 */ { MAD_F(0x04a2853c) /* 0.289677844 */, 13 },
+ /* 341 */ { MAD_F(0x04a72cfe) /* 0.290814392 */, 13 },
+ /* 342 */ { MAD_F(0x04abd5ea) /* 0.291952051 */, 13 },
+ /* 343 */ { MAD_F(0x04b08000) /* 0.293090820 */, 13 },
+ /* 344 */ { MAD_F(0x04b52b3f) /* 0.294230696 */, 13 },
+ /* 345 */ { MAD_F(0x04b9d7a7) /* 0.295371678 */, 13 },
+ /* 346 */ { MAD_F(0x04be8537) /* 0.296513762 */, 13 },
+ /* 347 */ { MAD_F(0x04c333ee) /* 0.297656947 */, 13 },
+ /* 348 */ { MAD_F(0x04c7e3cc) /* 0.298801231 */, 13 },
+ /* 349 */ { MAD_F(0x04cc94d1) /* 0.299946611 */, 13 },
+ /* 350 */ { MAD_F(0x04d146fb) /* 0.301093085 */, 13 },
+ /* 351 */ { MAD_F(0x04d5fa4b) /* 0.302240653 */, 13 },
+
+ /* 352 */ { MAD_F(0x04daaec0) /* 0.303389310 */, 13 },
+ /* 353 */ { MAD_F(0x04df6458) /* 0.304539056 */, 13 },
+ /* 354 */ { MAD_F(0x04e41b14) /* 0.305689888 */, 13 },
+ /* 355 */ { MAD_F(0x04e8d2f3) /* 0.306841804 */, 13 },
+ /* 356 */ { MAD_F(0x04ed8bf5) /* 0.307994802 */, 13 },
+ /* 357 */ { MAD_F(0x04f24618) /* 0.309148880 */, 13 },
+ /* 358 */ { MAD_F(0x04f7015d) /* 0.310304037 */, 13 },
+ /* 359 */ { MAD_F(0x04fbbdc3) /* 0.311460269 */, 13 },
+ /* 360 */ { MAD_F(0x05007b49) /* 0.312617576 */, 13 },
+ /* 361 */ { MAD_F(0x050539ef) /* 0.313775954 */, 13 },
+ /* 362 */ { MAD_F(0x0509f9b4) /* 0.314935403 */, 13 },
+ /* 363 */ { MAD_F(0x050eba98) /* 0.316095920 */, 13 },
+ /* 364 */ { MAD_F(0x05137c9a) /* 0.317257503 */, 13 },
+ /* 365 */ { MAD_F(0x05183fba) /* 0.318420150 */, 13 },
+ /* 366 */ { MAD_F(0x051d03f7) /* 0.319583859 */, 13 },
+ /* 367 */ { MAD_F(0x0521c950) /* 0.320748629 */, 13 },
+
+ /* 368 */ { MAD_F(0x05268fc6) /* 0.321914457 */, 13 },
+ /* 369 */ { MAD_F(0x052b5757) /* 0.323081342 */, 13 },
+ /* 370 */ { MAD_F(0x05302003) /* 0.324249281 */, 13 },
+ /* 371 */ { MAD_F(0x0534e9ca) /* 0.325418273 */, 13 },
+ /* 372 */ { MAD_F(0x0539b4ab) /* 0.326588316 */, 13 },
+ /* 373 */ { MAD_F(0x053e80a6) /* 0.327759407 */, 13 },
+ /* 374 */ { MAD_F(0x05434db9) /* 0.328931546 */, 13 },
+ /* 375 */ { MAD_F(0x05481be5) /* 0.330104730 */, 13 },
+ /* 376 */ { MAD_F(0x054ceb2a) /* 0.331278957 */, 13 },
+ /* 377 */ { MAD_F(0x0551bb85) /* 0.332454225 */, 13 },
+ /* 378 */ { MAD_F(0x05568cf8) /* 0.333630533 */, 13 },
+ /* 379 */ { MAD_F(0x055b5f81) /* 0.334807879 */, 13 },
+ /* 380 */ { MAD_F(0x05603321) /* 0.335986261 */, 13 },
+ /* 381 */ { MAD_F(0x056507d6) /* 0.337165677 */, 13 },
+ /* 382 */ { MAD_F(0x0569dda0) /* 0.338346125 */, 13 },
+ /* 383 */ { MAD_F(0x056eb47f) /* 0.339527604 */, 13 },
+
+ /* 384 */ { MAD_F(0x05738c72) /* 0.340710111 */, 13 },
+ /* 385 */ { MAD_F(0x05786578) /* 0.341893646 */, 13 },
+ /* 386 */ { MAD_F(0x057d3f92) /* 0.343078205 */, 13 },
+ /* 387 */ { MAD_F(0x05821abf) /* 0.344263788 */, 13 },
+ /* 388 */ { MAD_F(0x0586f6fd) /* 0.345450393 */, 13 },
+ /* 389 */ { MAD_F(0x058bd44e) /* 0.346638017 */, 13 },
+ /* 390 */ { MAD_F(0x0590b2b0) /* 0.347826659 */, 13 },
+ /* 391 */ { MAD_F(0x05959222) /* 0.349016318 */, 13 },
+ /* 392 */ { MAD_F(0x059a72a5) /* 0.350206992 */, 13 },
+ /* 393 */ { MAD_F(0x059f5438) /* 0.351398678 */, 13 },
+ /* 394 */ { MAD_F(0x05a436da) /* 0.352591376 */, 13 },
+ /* 395 */ { MAD_F(0x05a91a8c) /* 0.353785083 */, 13 },
+ /* 396 */ { MAD_F(0x05adff4c) /* 0.354979798 */, 13 },
+ /* 397 */ { MAD_F(0x05b2e51a) /* 0.356175519 */, 13 },
+ /* 398 */ { MAD_F(0x05b7cbf5) /* 0.357372244 */, 13 },
+ /* 399 */ { MAD_F(0x05bcb3de) /* 0.358569972 */, 13 },
+
+ /* 400 */ { MAD_F(0x05c19cd3) /* 0.359768701 */, 13 },
+ /* 401 */ { MAD_F(0x05c686d5) /* 0.360968429 */, 13 },
+ /* 402 */ { MAD_F(0x05cb71e2) /* 0.362169156 */, 13 },
+ /* 403 */ { MAD_F(0x05d05dfb) /* 0.363370878 */, 13 },
+ /* 404 */ { MAD_F(0x05d54b1f) /* 0.364573594 */, 13 },
+ /* 405 */ { MAD_F(0x05da394d) /* 0.365777304 */, 13 },
+ /* 406 */ { MAD_F(0x05df2885) /* 0.366982004 */, 13 },
+ /* 407 */ { MAD_F(0x05e418c7) /* 0.368187694 */, 13 },
+ /* 408 */ { MAD_F(0x05e90a12) /* 0.369394372 */, 13 },
+ /* 409 */ { MAD_F(0x05edfc66) /* 0.370602036 */, 13 },
+ /* 410 */ { MAD_F(0x05f2efc2) /* 0.371810684 */, 13 },
+ /* 411 */ { MAD_F(0x05f7e426) /* 0.373020316 */, 13 },
+ /* 412 */ { MAD_F(0x05fcd992) /* 0.374230929 */, 13 },
+ /* 413 */ { MAD_F(0x0601d004) /* 0.375442522 */, 13 },
+ /* 414 */ { MAD_F(0x0606c77d) /* 0.376655093 */, 13 },
+ /* 415 */ { MAD_F(0x060bbffd) /* 0.377868641 */, 13 },
+
+ /* 416 */ { MAD_F(0x0610b982) /* 0.379083164 */, 13 },
+ /* 417 */ { MAD_F(0x0615b40c) /* 0.380298661 */, 13 },
+ /* 418 */ { MAD_F(0x061aaf9c) /* 0.381515130 */, 13 },
+ /* 419 */ { MAD_F(0x061fac2f) /* 0.382732569 */, 13 },
+ /* 420 */ { MAD_F(0x0624a9c7) /* 0.383950977 */, 13 },
+ /* 421 */ { MAD_F(0x0629a863) /* 0.385170352 */, 13 },
+ /* 422 */ { MAD_F(0x062ea802) /* 0.386390694 */, 13 },
+ /* 423 */ { MAD_F(0x0633a8a3) /* 0.387611999 */, 13 },
+ /* 424 */ { MAD_F(0x0638aa48) /* 0.388834268 */, 13 },
+ /* 425 */ { MAD_F(0x063dacee) /* 0.390057497 */, 13 },
+ /* 426 */ { MAD_F(0x0642b096) /* 0.391281687 */, 13 },
+ /* 427 */ { MAD_F(0x0647b53f) /* 0.392506834 */, 13 },
+ /* 428 */ { MAD_F(0x064cbae9) /* 0.393732939 */, 13 },
+ /* 429 */ { MAD_F(0x0651c193) /* 0.394959999 */, 13 },
+ /* 430 */ { MAD_F(0x0656c93d) /* 0.396188012 */, 13 },
+ /* 431 */ { MAD_F(0x065bd1e7) /* 0.397416978 */, 13 },
+
+ /* 432 */ { MAD_F(0x0660db91) /* 0.398646895 */, 13 },
+ /* 433 */ { MAD_F(0x0665e639) /* 0.399877761 */, 13 },
+ /* 434 */ { MAD_F(0x066af1df) /* 0.401109575 */, 13 },
+ /* 435 */ { MAD_F(0x066ffe84) /* 0.402342335 */, 13 },
+ /* 436 */ { MAD_F(0x06750c26) /* 0.403576041 */, 13 },
+ /* 437 */ { MAD_F(0x067a1ac6) /* 0.404810690 */, 13 },
+ /* 438 */ { MAD_F(0x067f2a62) /* 0.406046281 */, 13 },
+ /* 439 */ { MAD_F(0x06843afb) /* 0.407282813 */, 13 },
+ /* 440 */ { MAD_F(0x06894c90) /* 0.408520284 */, 13 },
+ /* 441 */ { MAD_F(0x068e5f21) /* 0.409758693 */, 13 },
+ /* 442 */ { MAD_F(0x069372ae) /* 0.410998038 */, 13 },
+ /* 443 */ { MAD_F(0x06988735) /* 0.412238319 */, 13 },
+ /* 444 */ { MAD_F(0x069d9cb7) /* 0.413479532 */, 13 },
+ /* 445 */ { MAD_F(0x06a2b333) /* 0.414721679 */, 13 },
+ /* 446 */ { MAD_F(0x06a7caa9) /* 0.415964756 */, 13 },
+ /* 447 */ { MAD_F(0x06ace318) /* 0.417208762 */, 13 },
+
+ /* 448 */ { MAD_F(0x06b1fc81) /* 0.418453696 */, 13 },
+ /* 449 */ { MAD_F(0x06b716e2) /* 0.419699557 */, 13 },
+ /* 450 */ { MAD_F(0x06bc323b) /* 0.420946343 */, 13 },
+ /* 451 */ { MAD_F(0x06c14e8d) /* 0.422194054 */, 13 },
+ /* 452 */ { MAD_F(0x06c66bd6) /* 0.423442686 */, 13 },
+ /* 453 */ { MAD_F(0x06cb8a17) /* 0.424692240 */, 13 },
+ /* 454 */ { MAD_F(0x06d0a94e) /* 0.425942714 */, 13 },
+ /* 455 */ { MAD_F(0x06d5c97c) /* 0.427194106 */, 13 },
+ /* 456 */ { MAD_F(0x06daeaa1) /* 0.428446415 */, 13 },
+ /* 457 */ { MAD_F(0x06e00cbb) /* 0.429699640 */, 13 },
+ /* 458 */ { MAD_F(0x06e52fca) /* 0.430953779 */, 13 },
+ /* 459 */ { MAD_F(0x06ea53cf) /* 0.432208832 */, 13 },
+ /* 460 */ { MAD_F(0x06ef78c8) /* 0.433464796 */, 13 },
+ /* 461 */ { MAD_F(0x06f49eb6) /* 0.434721671 */, 13 },
+ /* 462 */ { MAD_F(0x06f9c597) /* 0.435979455 */, 13 },
+ /* 463 */ { MAD_F(0x06feed6d) /* 0.437238146 */, 13 },
+
+ /* 464 */ { MAD_F(0x07041636) /* 0.438497744 */, 13 },
+ /* 465 */ { MAD_F(0x07093ff2) /* 0.439758248 */, 13 },
+ /* 466 */ { MAD_F(0x070e6aa0) /* 0.441019655 */, 13 },
+ /* 467 */ { MAD_F(0x07139641) /* 0.442281965 */, 13 },
+ /* 468 */ { MAD_F(0x0718c2d3) /* 0.443545176 */, 13 },
+ /* 469 */ { MAD_F(0x071df058) /* 0.444809288 */, 13 },
+ /* 470 */ { MAD_F(0x07231ecd) /* 0.446074298 */, 13 },
+ /* 471 */ { MAD_F(0x07284e34) /* 0.447340205 */, 13 },
+ /* 472 */ { MAD_F(0x072d7e8b) /* 0.448607009 */, 13 },
+ /* 473 */ { MAD_F(0x0732afd2) /* 0.449874708 */, 13 },
+ /* 474 */ { MAD_F(0x0737e209) /* 0.451143300 */, 13 },
+ /* 475 */ { MAD_F(0x073d1530) /* 0.452412785 */, 13 },
+ /* 476 */ { MAD_F(0x07424946) /* 0.453683161 */, 13 },
+ /* 477 */ { MAD_F(0x07477e4b) /* 0.454954427 */, 13 },
+ /* 478 */ { MAD_F(0x074cb43e) /* 0.456226581 */, 13 },
+ /* 479 */ { MAD_F(0x0751eb20) /* 0.457499623 */, 13 },
+
+ /* 480 */ { MAD_F(0x075722ef) /* 0.458773552 */, 13 },
+ /* 481 */ { MAD_F(0x075c5bac) /* 0.460048365 */, 13 },
+ /* 482 */ { MAD_F(0x07619557) /* 0.461324062 */, 13 },
+ /* 483 */ { MAD_F(0x0766cfee) /* 0.462600642 */, 13 },
+ /* 484 */ { MAD_F(0x076c0b72) /* 0.463878102 */, 13 },
+ /* 485 */ { MAD_F(0x077147e2) /* 0.465156443 */, 13 },
+ /* 486 */ { MAD_F(0x0776853e) /* 0.466435663 */, 13 },
+ /* 487 */ { MAD_F(0x077bc385) /* 0.467715761 */, 13 },
+ /* 488 */ { MAD_F(0x078102b8) /* 0.468996735 */, 13 },
+ /* 489 */ { MAD_F(0x078642d6) /* 0.470278584 */, 13 },
+ /* 490 */ { MAD_F(0x078b83de) /* 0.471561307 */, 13 },
+ /* 491 */ { MAD_F(0x0790c5d1) /* 0.472844904 */, 13 },
+ /* 492 */ { MAD_F(0x079608ae) /* 0.474129372 */, 13 },
+ /* 493 */ { MAD_F(0x079b4c74) /* 0.475414710 */, 13 },
+ /* 494 */ { MAD_F(0x07a09124) /* 0.476700918 */, 13 },
+ /* 495 */ { MAD_F(0x07a5d6bd) /* 0.477987994 */, 13 },
+
+ /* 496 */ { MAD_F(0x07ab1d3e) /* 0.479275937 */, 13 },
+ /* 497 */ { MAD_F(0x07b064a8) /* 0.480564746 */, 13 },
+ /* 498 */ { MAD_F(0x07b5acfb) /* 0.481854420 */, 13 },
+ /* 499 */ { MAD_F(0x07baf635) /* 0.483144957 */, 13 },
+ /* 500 */ { MAD_F(0x07c04056) /* 0.484436356 */, 13 },
+ /* 501 */ { MAD_F(0x07c58b5f) /* 0.485728617 */, 13 },
+ /* 502 */ { MAD_F(0x07cad74e) /* 0.487021738 */, 13 },
+ /* 503 */ { MAD_F(0x07d02424) /* 0.488315717 */, 13 },
+ /* 504 */ { MAD_F(0x07d571e0) /* 0.489610555 */, 13 },
+ /* 505 */ { MAD_F(0x07dac083) /* 0.490906249 */, 13 },
+ /* 506 */ { MAD_F(0x07e0100a) /* 0.492202799 */, 13 },
+ /* 507 */ { MAD_F(0x07e56078) /* 0.493500203 */, 13 },
+ /* 508 */ { MAD_F(0x07eab1ca) /* 0.494798460 */, 13 },
+ /* 509 */ { MAD_F(0x07f00401) /* 0.496097570 */, 13 },
+ /* 510 */ { MAD_F(0x07f5571d) /* 0.497397530 */, 13 },
+ /* 511 */ { MAD_F(0x07faab1c) /* 0.498698341 */, 13 },
+
+ /* 512 */ { MAD_F(0x04000000) /* 0.250000000 */, 14 },
+ /* 513 */ { MAD_F(0x0402aae3) /* 0.250651254 */, 14 },
+ /* 514 */ { MAD_F(0x04055638) /* 0.251302930 */, 14 },
+ /* 515 */ { MAD_F(0x040801ff) /* 0.251955030 */, 14 },
+ /* 516 */ { MAD_F(0x040aae37) /* 0.252607552 */, 14 },
+ /* 517 */ { MAD_F(0x040d5ae0) /* 0.253260495 */, 14 },
+ /* 518 */ { MAD_F(0x041007fa) /* 0.253913860 */, 14 },
+ /* 519 */ { MAD_F(0x0412b586) /* 0.254567645 */, 14 },
+ /* 520 */ { MAD_F(0x04156381) /* 0.255221850 */, 14 },
+ /* 521 */ { MAD_F(0x041811ee) /* 0.255876475 */, 14 },
+ /* 522 */ { MAD_F(0x041ac0cb) /* 0.256531518 */, 14 },
+ /* 523 */ { MAD_F(0x041d7018) /* 0.257186980 */, 14 },
+ /* 524 */ { MAD_F(0x04201fd5) /* 0.257842860 */, 14 },
+ /* 525 */ { MAD_F(0x0422d003) /* 0.258499157 */, 14 },
+ /* 526 */ { MAD_F(0x042580a0) /* 0.259155872 */, 14 },
+ /* 527 */ { MAD_F(0x042831ad) /* 0.259813002 */, 14 },
+
+ /* 528 */ { MAD_F(0x042ae32a) /* 0.260470548 */, 14 },
+ /* 529 */ { MAD_F(0x042d9516) /* 0.261128510 */, 14 },
+ /* 530 */ { MAD_F(0x04304772) /* 0.261786886 */, 14 },
+ /* 531 */ { MAD_F(0x0432fa3d) /* 0.262445676 */, 14 },
+ /* 532 */ { MAD_F(0x0435ad76) /* 0.263104880 */, 14 },
+ /* 533 */ { MAD_F(0x0438611f) /* 0.263764497 */, 14 },
+ /* 534 */ { MAD_F(0x043b1536) /* 0.264424527 */, 14 },
+ /* 535 */ { MAD_F(0x043dc9bc) /* 0.265084969 */, 14 },
+ /* 536 */ { MAD_F(0x04407eb1) /* 0.265745823 */, 14 },
+ /* 537 */ { MAD_F(0x04433414) /* 0.266407088 */, 14 },
+ /* 538 */ { MAD_F(0x0445e9e5) /* 0.267068763 */, 14 },
+ /* 539 */ { MAD_F(0x0448a024) /* 0.267730848 */, 14 },
+ /* 540 */ { MAD_F(0x044b56d1) /* 0.268393343 */, 14 },
+ /* 541 */ { MAD_F(0x044e0dec) /* 0.269056248 */, 14 },
+ /* 542 */ { MAD_F(0x0450c575) /* 0.269719560 */, 14 },
+ /* 543 */ { MAD_F(0x04537d6b) /* 0.270383281 */, 14 },
+
+ /* 544 */ { MAD_F(0x045635cf) /* 0.271047409 */, 14 },
+ /* 545 */ { MAD_F(0x0458ee9f) /* 0.271711944 */, 14 },
+ /* 546 */ { MAD_F(0x045ba7dd) /* 0.272376886 */, 14 },
+ /* 547 */ { MAD_F(0x045e6188) /* 0.273042234 */, 14 },
+ /* 548 */ { MAD_F(0x04611ba0) /* 0.273707988 */, 14 },
+ /* 549 */ { MAD_F(0x0463d625) /* 0.274374147 */, 14 },
+ /* 550 */ { MAD_F(0x04669116) /* 0.275040710 */, 14 },
+ /* 551 */ { MAD_F(0x04694c74) /* 0.275707677 */, 14 },
+ /* 552 */ { MAD_F(0x046c083e) /* 0.276375048 */, 14 },
+ /* 553 */ { MAD_F(0x046ec474) /* 0.277042822 */, 14 },
+ /* 554 */ { MAD_F(0x04718116) /* 0.277710999 */, 14 },
+ /* 555 */ { MAD_F(0x04743e25) /* 0.278379578 */, 14 },
+ /* 556 */ { MAD_F(0x0476fb9f) /* 0.279048558 */, 14 },
+ /* 557 */ { MAD_F(0x0479b984) /* 0.279717940 */, 14 },
+ /* 558 */ { MAD_F(0x047c77d6) /* 0.280387722 */, 14 },
+ /* 559 */ { MAD_F(0x047f3693) /* 0.281057905 */, 14 },
+
+ /* 560 */ { MAD_F(0x0481f5bb) /* 0.281728487 */, 14 },
+ /* 561 */ { MAD_F(0x0484b54e) /* 0.282399469 */, 14 },
+ /* 562 */ { MAD_F(0x0487754c) /* 0.283070849 */, 14 },
+ /* 563 */ { MAD_F(0x048a35b6) /* 0.283742628 */, 14 },
+ /* 564 */ { MAD_F(0x048cf68a) /* 0.284414805 */, 14 },
+ /* 565 */ { MAD_F(0x048fb7c8) /* 0.285087379 */, 14 },
+ /* 566 */ { MAD_F(0x04927972) /* 0.285760350 */, 14 },
+ /* 567 */ { MAD_F(0x04953b85) /* 0.286433717 */, 14 },
+ /* 568 */ { MAD_F(0x0497fe03) /* 0.287107481 */, 14 },
+ /* 569 */ { MAD_F(0x049ac0eb) /* 0.287781640 */, 14 },
+ /* 570 */ { MAD_F(0x049d843e) /* 0.288456194 */, 14 },
+ /* 571 */ { MAD_F(0x04a047fa) /* 0.289131142 */, 14 },
+ /* 572 */ { MAD_F(0x04a30c20) /* 0.289806485 */, 14 },
+ /* 573 */ { MAD_F(0x04a5d0af) /* 0.290482221 */, 14 },
+ /* 574 */ { MAD_F(0x04a895a8) /* 0.291158351 */, 14 },
+ /* 575 */ { MAD_F(0x04ab5b0b) /* 0.291834873 */, 14 },
+
+ /* 576 */ { MAD_F(0x04ae20d7) /* 0.292511788 */, 14 },
+ /* 577 */ { MAD_F(0x04b0e70c) /* 0.293189094 */, 14 },
+ /* 578 */ { MAD_F(0x04b3adaa) /* 0.293866792 */, 14 },
+ /* 579 */ { MAD_F(0x04b674b1) /* 0.294544881 */, 14 },
+ /* 580 */ { MAD_F(0x04b93c21) /* 0.295223360 */, 14 },
+ /* 581 */ { MAD_F(0x04bc03fa) /* 0.295902229 */, 14 },
+ /* 582 */ { MAD_F(0x04becc3b) /* 0.296581488 */, 14 },
+ /* 583 */ { MAD_F(0x04c194e4) /* 0.297261136 */, 14 },
+ /* 584 */ { MAD_F(0x04c45df6) /* 0.297941173 */, 14 },
+ /* 585 */ { MAD_F(0x04c72771) /* 0.298621598 */, 14 },
+ /* 586 */ { MAD_F(0x04c9f153) /* 0.299302411 */, 14 },
+ /* 587 */ { MAD_F(0x04ccbb9d) /* 0.299983611 */, 14 },
+ /* 588 */ { MAD_F(0x04cf864f) /* 0.300665198 */, 14 },
+ /* 589 */ { MAD_F(0x04d25169) /* 0.301347172 */, 14 },
+ /* 590 */ { MAD_F(0x04d51ceb) /* 0.302029532 */, 14 },
+ /* 591 */ { MAD_F(0x04d7e8d4) /* 0.302712277 */, 14 },
+
+ /* 592 */ { MAD_F(0x04dab524) /* 0.303395408 */, 14 },
+ /* 593 */ { MAD_F(0x04dd81dc) /* 0.304078923 */, 14 },
+ /* 594 */ { MAD_F(0x04e04efb) /* 0.304762823 */, 14 },
+ /* 595 */ { MAD_F(0x04e31c81) /* 0.305447106 */, 14 },
+ /* 596 */ { MAD_F(0x04e5ea6e) /* 0.306131773 */, 14 },
+ /* 597 */ { MAD_F(0x04e8b8c2) /* 0.306816823 */, 14 },
+ /* 598 */ { MAD_F(0x04eb877c) /* 0.307502256 */, 14 },
+ /* 599 */ { MAD_F(0x04ee569d) /* 0.308188071 */, 14 },
+ /* 600 */ { MAD_F(0x04f12624) /* 0.308874267 */, 14 },
+ /* 601 */ { MAD_F(0x04f3f612) /* 0.309560845 */, 14 },
+ /* 602 */ { MAD_F(0x04f6c666) /* 0.310247804 */, 14 },
+ /* 603 */ { MAD_F(0x04f99721) /* 0.310935143 */, 14 },
+ /* 604 */ { MAD_F(0x04fc6841) /* 0.311622862 */, 14 },
+ /* 605 */ { MAD_F(0x04ff39c7) /* 0.312310961 */, 14 },
+ /* 606 */ { MAD_F(0x05020bb3) /* 0.312999439 */, 14 },
+ /* 607 */ { MAD_F(0x0504de05) /* 0.313688296 */, 14 },
+
+ /* 608 */ { MAD_F(0x0507b0bc) /* 0.314377532 */, 14 },
+ /* 609 */ { MAD_F(0x050a83d8) /* 0.315067145 */, 14 },
+ /* 610 */ { MAD_F(0x050d575b) /* 0.315757136 */, 14 },
+ /* 611 */ { MAD_F(0x05102b42) /* 0.316447504 */, 14 },
+ /* 612 */ { MAD_F(0x0512ff8e) /* 0.317138249 */, 14 },
+ /* 613 */ { MAD_F(0x0515d440) /* 0.317829370 */, 14 },
+ /* 614 */ { MAD_F(0x0518a956) /* 0.318520867 */, 14 },
+ /* 615 */ { MAD_F(0x051b7ed1) /* 0.319212739 */, 14 },
+ /* 616 */ { MAD_F(0x051e54b1) /* 0.319904987 */, 14 },
+ /* 617 */ { MAD_F(0x05212af5) /* 0.320597609 */, 14 },
+ /* 618 */ { MAD_F(0x0524019e) /* 0.321290606 */, 14 },
+ /* 619 */ { MAD_F(0x0526d8ab) /* 0.321983976 */, 14 },
+ /* 620 */ { MAD_F(0x0529b01d) /* 0.322677720 */, 14 },
+ /* 621 */ { MAD_F(0x052c87f2) /* 0.323371837 */, 14 },
+ /* 622 */ { MAD_F(0x052f602c) /* 0.324066327 */, 14 },
+ /* 623 */ { MAD_F(0x053238ca) /* 0.324761189 */, 14 },
+
+ /* 624 */ { MAD_F(0x053511cb) /* 0.325456423 */, 14 },
+ /* 625 */ { MAD_F(0x0537eb30) /* 0.326152028 */, 14 },
+ /* 626 */ { MAD_F(0x053ac4f9) /* 0.326848005 */, 14 },
+ /* 627 */ { MAD_F(0x053d9f25) /* 0.327544352 */, 14 },
+ /* 628 */ { MAD_F(0x054079b5) /* 0.328241070 */, 14 },
+ /* 629 */ { MAD_F(0x054354a8) /* 0.328938157 */, 14 },
+ /* 630 */ { MAD_F(0x05462ffe) /* 0.329635614 */, 14 },
+ /* 631 */ { MAD_F(0x05490bb7) /* 0.330333440 */, 14 },
+ /* 632 */ { MAD_F(0x054be7d4) /* 0.331031635 */, 14 },
+ /* 633 */ { MAD_F(0x054ec453) /* 0.331730198 */, 14 },
+ /* 634 */ { MAD_F(0x0551a134) /* 0.332429129 */, 14 },
+ /* 635 */ { MAD_F(0x05547e79) /* 0.333128427 */, 14 },
+ /* 636 */ { MAD_F(0x05575c20) /* 0.333828093 */, 14 },
+ /* 637 */ { MAD_F(0x055a3a2a) /* 0.334528126 */, 14 },
+ /* 638 */ { MAD_F(0x055d1896) /* 0.335228525 */, 14 },
+ /* 639 */ { MAD_F(0x055ff764) /* 0.335929290 */, 14 },
+
+ /* 640 */ { MAD_F(0x0562d694) /* 0.336630420 */, 14 },
+ /* 641 */ { MAD_F(0x0565b627) /* 0.337331916 */, 14 },
+ /* 642 */ { MAD_F(0x0568961b) /* 0.338033777 */, 14 },
+ /* 643 */ { MAD_F(0x056b7671) /* 0.338736002 */, 14 },
+ /* 644 */ { MAD_F(0x056e5729) /* 0.339438592 */, 14 },
+ /* 645 */ { MAD_F(0x05713843) /* 0.340141545 */, 14 },
+ /* 646 */ { MAD_F(0x057419be) /* 0.340844862 */, 14 },
+ /* 647 */ { MAD_F(0x0576fb9a) /* 0.341548541 */, 14 },
+ /* 648 */ { MAD_F(0x0579ddd8) /* 0.342252584 */, 14 },
+ /* 649 */ { MAD_F(0x057cc077) /* 0.342956988 */, 14 },
+ /* 650 */ { MAD_F(0x057fa378) /* 0.343661754 */, 14 },
+ /* 651 */ { MAD_F(0x058286d9) /* 0.344366882 */, 14 },
+ /* 652 */ { MAD_F(0x05856a9b) /* 0.345072371 */, 14 },
+ /* 653 */ { MAD_F(0x05884ebe) /* 0.345778221 */, 14 },
+ /* 654 */ { MAD_F(0x058b3342) /* 0.346484431 */, 14 },
+ /* 655 */ { MAD_F(0x058e1827) /* 0.347191002 */, 14 },
+
+ /* 656 */ { MAD_F(0x0590fd6c) /* 0.347897931 */, 14 },
+ /* 657 */ { MAD_F(0x0593e311) /* 0.348605221 */, 14 },
+ /* 658 */ { MAD_F(0x0596c917) /* 0.349312869 */, 14 },
+ /* 659 */ { MAD_F(0x0599af7d) /* 0.350020876 */, 14 },
+ /* 660 */ { MAD_F(0x059c9643) /* 0.350729240 */, 14 },
+ /* 661 */ { MAD_F(0x059f7d6a) /* 0.351437963 */, 14 },
+ /* 662 */ { MAD_F(0x05a264f0) /* 0.352147044 */, 14 },
+ /* 663 */ { MAD_F(0x05a54cd6) /* 0.352856481 */, 14 },
+ /* 664 */ { MAD_F(0x05a8351c) /* 0.353566275 */, 14 },
+ /* 665 */ { MAD_F(0x05ab1dc2) /* 0.354276426 */, 14 },
+ /* 666 */ { MAD_F(0x05ae06c7) /* 0.354986932 */, 14 },
+ /* 667 */ { MAD_F(0x05b0f02b) /* 0.355697795 */, 14 },
+ /* 668 */ { MAD_F(0x05b3d9f0) /* 0.356409012 */, 14 },
+ /* 669 */ { MAD_F(0x05b6c413) /* 0.357120585 */, 14 },
+ /* 670 */ { MAD_F(0x05b9ae95) /* 0.357832512 */, 14 },
+ /* 671 */ { MAD_F(0x05bc9977) /* 0.358544794 */, 14 },
+
+ /* 672 */ { MAD_F(0x05bf84b8) /* 0.359257429 */, 14 },
+ /* 673 */ { MAD_F(0x05c27057) /* 0.359970419 */, 14 },
+ /* 674 */ { MAD_F(0x05c55c56) /* 0.360683761 */, 14 },
+ /* 675 */ { MAD_F(0x05c848b3) /* 0.361397456 */, 14 },
+ /* 676 */ { MAD_F(0x05cb356e) /* 0.362111504 */, 14 },
+ /* 677 */ { MAD_F(0x05ce2289) /* 0.362825904 */, 14 },
+ /* 678 */ { MAD_F(0x05d11001) /* 0.363540655 */, 14 },
+ /* 679 */ { MAD_F(0x05d3fdd8) /* 0.364255759 */, 14 },
+ /* 680 */ { MAD_F(0x05d6ec0e) /* 0.364971213 */, 14 },
+ /* 681 */ { MAD_F(0x05d9daa1) /* 0.365687018 */, 14 },
+ /* 682 */ { MAD_F(0x05dcc993) /* 0.366403174 */, 14 },
+ /* 683 */ { MAD_F(0x05dfb8e2) /* 0.367119680 */, 14 },
+ /* 684 */ { MAD_F(0x05e2a890) /* 0.367836535 */, 14 },
+ /* 685 */ { MAD_F(0x05e5989b) /* 0.368553740 */, 14 },
+ /* 686 */ { MAD_F(0x05e88904) /* 0.369271294 */, 14 },
+ /* 687 */ { MAD_F(0x05eb79cb) /* 0.369989197 */, 14 },
+
+ /* 688 */ { MAD_F(0x05ee6aef) /* 0.370707448 */, 14 },
+ /* 689 */ { MAD_F(0x05f15c70) /* 0.371426047 */, 14 },
+ /* 690 */ { MAD_F(0x05f44e4f) /* 0.372144994 */, 14 },
+ /* 691 */ { MAD_F(0x05f7408b) /* 0.372864289 */, 14 },
+ /* 692 */ { MAD_F(0x05fa3324) /* 0.373583930 */, 14 },
+ /* 693 */ { MAD_F(0x05fd261b) /* 0.374303918 */, 14 },
+ /* 694 */ { MAD_F(0x0600196e) /* 0.375024253 */, 14 },
+ /* 695 */ { MAD_F(0x06030d1e) /* 0.375744934 */, 14 },
+ /* 696 */ { MAD_F(0x0606012b) /* 0.376465960 */, 14 },
+ /* 697 */ { MAD_F(0x0608f595) /* 0.377187332 */, 14 },
+ /* 698 */ { MAD_F(0x060bea5c) /* 0.377909049 */, 14 },
+ /* 699 */ { MAD_F(0x060edf7f) /* 0.378631110 */, 14 },
+ /* 700 */ { MAD_F(0x0611d4fe) /* 0.379353516 */, 14 },
+ /* 701 */ { MAD_F(0x0614cada) /* 0.380076266 */, 14 },
+ /* 702 */ { MAD_F(0x0617c112) /* 0.380799360 */, 14 },
+ /* 703 */ { MAD_F(0x061ab7a6) /* 0.381522798 */, 14 },
+
+ /* 704 */ { MAD_F(0x061dae96) /* 0.382246578 */, 14 },
+ /* 705 */ { MAD_F(0x0620a5e3) /* 0.382970701 */, 14 },
+ /* 706 */ { MAD_F(0x06239d8b) /* 0.383695167 */, 14 },
+ /* 707 */ { MAD_F(0x0626958f) /* 0.384419975 */, 14 },
+ /* 708 */ { MAD_F(0x06298def) /* 0.385145124 */, 14 },
+ /* 709 */ { MAD_F(0x062c86aa) /* 0.385870615 */, 14 },
+ /* 710 */ { MAD_F(0x062f7fc1) /* 0.386596448 */, 14 },
+ /* 711 */ { MAD_F(0x06327934) /* 0.387322621 */, 14 },
+ /* 712 */ { MAD_F(0x06357302) /* 0.388049134 */, 14 },
+ /* 713 */ { MAD_F(0x06386d2b) /* 0.388775988 */, 14 },
+ /* 714 */ { MAD_F(0x063b67b0) /* 0.389503182 */, 14 },
+ /* 715 */ { MAD_F(0x063e6290) /* 0.390230715 */, 14 },
+ /* 716 */ { MAD_F(0x06415dcb) /* 0.390958588 */, 14 },
+ /* 717 */ { MAD_F(0x06445960) /* 0.391686799 */, 14 },
+ /* 718 */ { MAD_F(0x06475551) /* 0.392415349 */, 14 },
+ /* 719 */ { MAD_F(0x064a519c) /* 0.393144238 */, 14 },
+
+ /* 720 */ { MAD_F(0x064d4e43) /* 0.393873464 */, 14 },
+ /* 721 */ { MAD_F(0x06504b44) /* 0.394603028 */, 14 },
+ /* 722 */ { MAD_F(0x0653489f) /* 0.395332930 */, 14 },
+ /* 723 */ { MAD_F(0x06564655) /* 0.396063168 */, 14 },
+ /* 724 */ { MAD_F(0x06594465) /* 0.396793743 */, 14 },
+ /* 725 */ { MAD_F(0x065c42d0) /* 0.397524655 */, 14 },
+ /* 726 */ { MAD_F(0x065f4195) /* 0.398255903 */, 14 },
+ /* 727 */ { MAD_F(0x066240b4) /* 0.398987487 */, 14 },
+ /* 728 */ { MAD_F(0x0665402d) /* 0.399719406 */, 14 },
+ /* 729 */ { MAD_F(0x06684000) /* 0.400451660 */, 14 },
+ /* 730 */ { MAD_F(0x066b402d) /* 0.401184249 */, 14 },
+ /* 731 */ { MAD_F(0x066e40b3) /* 0.401917173 */, 14 },
+ /* 732 */ { MAD_F(0x06714194) /* 0.402650431 */, 14 },
+ /* 733 */ { MAD_F(0x067442ce) /* 0.403384024 */, 14 },
+ /* 734 */ { MAD_F(0x06774462) /* 0.404117949 */, 14 },
+ /* 735 */ { MAD_F(0x067a464f) /* 0.404852209 */, 14 },
+
+ /* 736 */ { MAD_F(0x067d4896) /* 0.405586801 */, 14 },
+ /* 737 */ { MAD_F(0x06804b36) /* 0.406321726 */, 14 },
+ /* 738 */ { MAD_F(0x06834e2f) /* 0.407056983 */, 14 },
+ /* 739 */ { MAD_F(0x06865181) /* 0.407792573 */, 14 },
+ /* 740 */ { MAD_F(0x0689552c) /* 0.408528495 */, 14 },
+ /* 741 */ { MAD_F(0x068c5931) /* 0.409264748 */, 14 },
+ /* 742 */ { MAD_F(0x068f5d8e) /* 0.410001332 */, 14 },
+ /* 743 */ { MAD_F(0x06926245) /* 0.410738247 */, 14 },
+ /* 744 */ { MAD_F(0x06956753) /* 0.411475493 */, 14 },
+ /* 745 */ { MAD_F(0x06986cbb) /* 0.412213070 */, 14 },
+ /* 746 */ { MAD_F(0x069b727b) /* 0.412950976 */, 14 },
+ /* 747 */ { MAD_F(0x069e7894) /* 0.413689213 */, 14 },
+ /* 748 */ { MAD_F(0x06a17f05) /* 0.414427779 */, 14 },
+ /* 749 */ { MAD_F(0x06a485cf) /* 0.415166674 */, 14 },
+ /* 750 */ { MAD_F(0x06a78cf1) /* 0.415905897 */, 14 },
+ /* 751 */ { MAD_F(0x06aa946b) /* 0.416645450 */, 14 },
+
+ /* 752 */ { MAD_F(0x06ad9c3d) /* 0.417385331 */, 14 },
+ /* 753 */ { MAD_F(0x06b0a468) /* 0.418125540 */, 14 },
+ /* 754 */ { MAD_F(0x06b3acea) /* 0.418866076 */, 14 },
+ /* 755 */ { MAD_F(0x06b6b5c4) /* 0.419606940 */, 14 },
+ /* 756 */ { MAD_F(0x06b9bef6) /* 0.420348132 */, 14 },
+ /* 757 */ { MAD_F(0x06bcc880) /* 0.421089650 */, 14 },
+ /* 758 */ { MAD_F(0x06bfd261) /* 0.421831494 */, 14 },
+ /* 759 */ { MAD_F(0x06c2dc9a) /* 0.422573665 */, 14 },
+ /* 760 */ { MAD_F(0x06c5e72b) /* 0.423316162 */, 14 },
+ /* 761 */ { MAD_F(0x06c8f213) /* 0.424058985 */, 14 },
+ /* 762 */ { MAD_F(0x06cbfd52) /* 0.424802133 */, 14 },
+ /* 763 */ { MAD_F(0x06cf08e9) /* 0.425545607 */, 14 },
+ /* 764 */ { MAD_F(0x06d214d7) /* 0.426289405 */, 14 },
+ /* 765 */ { MAD_F(0x06d5211c) /* 0.427033528 */, 14 },
+ /* 766 */ { MAD_F(0x06d82db8) /* 0.427777975 */, 14 },
+ /* 767 */ { MAD_F(0x06db3aaa) /* 0.428522746 */, 14 },
+
+ /* 768 */ { MAD_F(0x06de47f4) /* 0.429267841 */, 14 },
+ /* 769 */ { MAD_F(0x06e15595) /* 0.430013259 */, 14 },
+ /* 770 */ { MAD_F(0x06e4638d) /* 0.430759001 */, 14 },
+ /* 771 */ { MAD_F(0x06e771db) /* 0.431505065 */, 14 },
+ /* 772 */ { MAD_F(0x06ea807f) /* 0.432251452 */, 14 },
+ /* 773 */ { MAD_F(0x06ed8f7b) /* 0.432998162 */, 14 },
+ /* 774 */ { MAD_F(0x06f09ecc) /* 0.433745193 */, 14 },
+ /* 775 */ { MAD_F(0x06f3ae75) /* 0.434492546 */, 14 },
+ /* 776 */ { MAD_F(0x06f6be73) /* 0.435240221 */, 14 },
+ /* 777 */ { MAD_F(0x06f9cec8) /* 0.435988217 */, 14 },
+ /* 778 */ { MAD_F(0x06fcdf72) /* 0.436736534 */, 14 },
+ /* 779 */ { MAD_F(0x06fff073) /* 0.437485172 */, 14 },
+ /* 780 */ { MAD_F(0x070301ca) /* 0.438234130 */, 14 },
+ /* 781 */ { MAD_F(0x07061377) /* 0.438983408 */, 14 },
+ /* 782 */ { MAD_F(0x0709257a) /* 0.439733006 */, 14 },
+ /* 783 */ { MAD_F(0x070c37d2) /* 0.440482924 */, 14 },
+
+ /* 784 */ { MAD_F(0x070f4a80) /* 0.441233161 */, 14 },
+ /* 785 */ { MAD_F(0x07125d84) /* 0.441983717 */, 14 },
+ /* 786 */ { MAD_F(0x071570de) /* 0.442734592 */, 14 },
+ /* 787 */ { MAD_F(0x0718848d) /* 0.443485785 */, 14 },
+ /* 788 */ { MAD_F(0x071b9891) /* 0.444237296 */, 14 },
+ /* 789 */ { MAD_F(0x071eaceb) /* 0.444989126 */, 14 },
+ /* 790 */ { MAD_F(0x0721c19a) /* 0.445741273 */, 14 },
+ /* 791 */ { MAD_F(0x0724d69e) /* 0.446493738 */, 14 },
+ /* 792 */ { MAD_F(0x0727ebf7) /* 0.447246519 */, 14 },
+ /* 793 */ { MAD_F(0x072b01a6) /* 0.447999618 */, 14 },
+ /* 794 */ { MAD_F(0x072e17a9) /* 0.448753033 */, 14 },
+ /* 795 */ { MAD_F(0x07312e01) /* 0.449506765 */, 14 },
+ /* 796 */ { MAD_F(0x073444ae) /* 0.450260813 */, 14 },
+ /* 797 */ { MAD_F(0x07375bb0) /* 0.451015176 */, 14 },
+ /* 798 */ { MAD_F(0x073a7307) /* 0.451769856 */, 14 },
+ /* 799 */ { MAD_F(0x073d8ab2) /* 0.452524850 */, 14 },
+
+ /* 800 */ { MAD_F(0x0740a2b2) /* 0.453280160 */, 14 },
+ /* 801 */ { MAD_F(0x0743bb06) /* 0.454035784 */, 14 },
+ /* 802 */ { MAD_F(0x0746d3af) /* 0.454791723 */, 14 },
+ /* 803 */ { MAD_F(0x0749ecac) /* 0.455547976 */, 14 },
+ /* 804 */ { MAD_F(0x074d05fe) /* 0.456304543 */, 14 },
+ /* 805 */ { MAD_F(0x07501fa3) /* 0.457061423 */, 14 },
+ /* 806 */ { MAD_F(0x0753399d) /* 0.457818618 */, 14 },
+ /* 807 */ { MAD_F(0x075653eb) /* 0.458576125 */, 14 },
+ /* 808 */ { MAD_F(0x07596e8d) /* 0.459333946 */, 14 },
+ /* 809 */ { MAD_F(0x075c8983) /* 0.460092079 */, 14 },
+ /* 810 */ { MAD_F(0x075fa4cc) /* 0.460850524 */, 14 },
+ /* 811 */ { MAD_F(0x0762c06a) /* 0.461609282 */, 14 },
+ /* 812 */ { MAD_F(0x0765dc5b) /* 0.462368352 */, 14 },
+ /* 813 */ { MAD_F(0x0768f8a0) /* 0.463127733 */, 14 },
+ /* 814 */ { MAD_F(0x076c1538) /* 0.463887426 */, 14 },
+ /* 815 */ { MAD_F(0x076f3224) /* 0.464647430 */, 14 },
+
+ /* 816 */ { MAD_F(0x07724f64) /* 0.465407744 */, 14 },
+ /* 817 */ { MAD_F(0x07756cf7) /* 0.466168370 */, 14 },
+ /* 818 */ { MAD_F(0x07788add) /* 0.466929306 */, 14 },
+ /* 819 */ { MAD_F(0x077ba916) /* 0.467690552 */, 14 },
+ /* 820 */ { MAD_F(0x077ec7a3) /* 0.468452108 */, 14 },
+ /* 821 */ { MAD_F(0x0781e683) /* 0.469213973 */, 14 },
+ /* 822 */ { MAD_F(0x078505b5) /* 0.469976148 */, 14 },
+ /* 823 */ { MAD_F(0x0788253b) /* 0.470738632 */, 14 },
+ /* 824 */ { MAD_F(0x078b4514) /* 0.471501425 */, 14 },
+ /* 825 */ { MAD_F(0x078e653f) /* 0.472264527 */, 14 },
+ /* 826 */ { MAD_F(0x079185be) /* 0.473027937 */, 14 },
+ /* 827 */ { MAD_F(0x0794a68f) /* 0.473791655 */, 14 },
+ /* 828 */ { MAD_F(0x0797c7b2) /* 0.474555681 */, 14 },
+ /* 829 */ { MAD_F(0x079ae929) /* 0.475320014 */, 14 },
+ /* 830 */ { MAD_F(0x079e0af1) /* 0.476084655 */, 14 },
+ /* 831 */ { MAD_F(0x07a12d0c) /* 0.476849603 */, 14 },
+
+ /* 832 */ { MAD_F(0x07a44f7a) /* 0.477614858 */, 14 },
+ /* 833 */ { MAD_F(0x07a7723a) /* 0.478380420 */, 14 },
+ /* 834 */ { MAD_F(0x07aa954c) /* 0.479146288 */, 14 },
+ /* 835 */ { MAD_F(0x07adb8b0) /* 0.479912463 */, 14 },
+ /* 836 */ { MAD_F(0x07b0dc67) /* 0.480678943 */, 14 },
+ /* 837 */ { MAD_F(0x07b4006f) /* 0.481445729 */, 14 },
+ /* 838 */ { MAD_F(0x07b724ca) /* 0.482212820 */, 14 },
+ /* 839 */ { MAD_F(0x07ba4976) /* 0.482980216 */, 14 },
+ /* 840 */ { MAD_F(0x07bd6e75) /* 0.483747918 */, 14 },
+ /* 841 */ { MAD_F(0x07c093c5) /* 0.484515924 */, 14 },
+ /* 842 */ { MAD_F(0x07c3b967) /* 0.485284235 */, 14 },
+ /* 843 */ { MAD_F(0x07c6df5a) /* 0.486052849 */, 14 },
+ /* 844 */ { MAD_F(0x07ca059f) /* 0.486821768 */, 14 },
+ /* 845 */ { MAD_F(0x07cd2c36) /* 0.487590991 */, 14 },
+ /* 846 */ { MAD_F(0x07d0531e) /* 0.488360517 */, 14 },
+ /* 847 */ { MAD_F(0x07d37a57) /* 0.489130346 */, 14 },
+
+ /* 848 */ { MAD_F(0x07d6a1e2) /* 0.489900479 */, 14 },
+ /* 849 */ { MAD_F(0x07d9c9be) /* 0.490670914 */, 14 },
+ /* 850 */ { MAD_F(0x07dcf1ec) /* 0.491441651 */, 14 },
+ /* 851 */ { MAD_F(0x07e01a6a) /* 0.492212691 */, 14 },
+ /* 852 */ { MAD_F(0x07e3433a) /* 0.492984033 */, 14 },
+ /* 853 */ { MAD_F(0x07e66c5a) /* 0.493755677 */, 14 },
+ /* 854 */ { MAD_F(0x07e995cc) /* 0.494527623 */, 14 },
+ /* 855 */ { MAD_F(0x07ecbf8e) /* 0.495299870 */, 14 },
+ /* 856 */ { MAD_F(0x07efe9a1) /* 0.496072418 */, 14 },
+ /* 857 */ { MAD_F(0x07f31405) /* 0.496845266 */, 14 },
+ /* 858 */ { MAD_F(0x07f63eba) /* 0.497618416 */, 14 },
+ /* 859 */ { MAD_F(0x07f969c0) /* 0.498391866 */, 14 },
+ /* 860 */ { MAD_F(0x07fc9516) /* 0.499165616 */, 14 },
+ /* 861 */ { MAD_F(0x07ffc0bc) /* 0.499939666 */, 14 },
+ /* 862 */ { MAD_F(0x04017659) /* 0.250357008 */, 15 },
+ /* 863 */ { MAD_F(0x04030c7d) /* 0.250744333 */, 15 },
+
+ /* 864 */ { MAD_F(0x0404a2c9) /* 0.251131807 */, 15 },
+ /* 865 */ { MAD_F(0x0406393d) /* 0.251519431 */, 15 },
+ /* 866 */ { MAD_F(0x0407cfd9) /* 0.251907204 */, 15 },
+ /* 867 */ { MAD_F(0x0409669d) /* 0.252295127 */, 15 },
+ /* 868 */ { MAD_F(0x040afd89) /* 0.252683198 */, 15 },
+ /* 869 */ { MAD_F(0x040c949e) /* 0.253071419 */, 15 },
+ /* 870 */ { MAD_F(0x040e2bda) /* 0.253459789 */, 15 },
+ /* 871 */ { MAD_F(0x040fc33e) /* 0.253848307 */, 15 },
+ /* 872 */ { MAD_F(0x04115aca) /* 0.254236974 */, 15 },
+ /* 873 */ { MAD_F(0x0412f27e) /* 0.254625790 */, 15 },
+ /* 874 */ { MAD_F(0x04148a5a) /* 0.255014755 */, 15 },
+ /* 875 */ { MAD_F(0x0416225d) /* 0.255403867 */, 15 },
+ /* 876 */ { MAD_F(0x0417ba89) /* 0.255793128 */, 15 },
+ /* 877 */ { MAD_F(0x041952dc) /* 0.256182537 */, 15 },
+ /* 878 */ { MAD_F(0x041aeb57) /* 0.256572095 */, 15 },
+ /* 879 */ { MAD_F(0x041c83fa) /* 0.256961800 */, 15 },
+
+ /* 880 */ { MAD_F(0x041e1cc4) /* 0.257351652 */, 15 },
+ /* 881 */ { MAD_F(0x041fb5b6) /* 0.257741653 */, 15 },
+ /* 882 */ { MAD_F(0x04214ed0) /* 0.258131801 */, 15 },
+ /* 883 */ { MAD_F(0x0422e811) /* 0.258522097 */, 15 },
+ /* 884 */ { MAD_F(0x04248179) /* 0.258912540 */, 15 },
+ /* 885 */ { MAD_F(0x04261b0a) /* 0.259303130 */, 15 },
+ /* 886 */ { MAD_F(0x0427b4c2) /* 0.259693868 */, 15 },
+ /* 887 */ { MAD_F(0x04294ea1) /* 0.260084752 */, 15 },
+ /* 888 */ { MAD_F(0x042ae8a7) /* 0.260475783 */, 15 },
+ /* 889 */ { MAD_F(0x042c82d6) /* 0.260866961 */, 15 },
+ /* 890 */ { MAD_F(0x042e1d2b) /* 0.261258286 */, 15 },
+ /* 891 */ { MAD_F(0x042fb7a8) /* 0.261649758 */, 15 },
+ /* 892 */ { MAD_F(0x0431524c) /* 0.262041376 */, 15 },
+ /* 893 */ { MAD_F(0x0432ed17) /* 0.262433140 */, 15 },
+ /* 894 */ { MAD_F(0x0434880a) /* 0.262825051 */, 15 },
+ /* 895 */ { MAD_F(0x04362324) /* 0.263217107 */, 15 },
+
+ /* 896 */ { MAD_F(0x0437be65) /* 0.263609310 */, 15 },
+ /* 897 */ { MAD_F(0x043959cd) /* 0.264001659 */, 15 },
+ /* 898 */ { MAD_F(0x043af55d) /* 0.264394153 */, 15 },
+ /* 899 */ { MAD_F(0x043c9113) /* 0.264786794 */, 15 },
+ /* 900 */ { MAD_F(0x043e2cf1) /* 0.265179580 */, 15 },
+ /* 901 */ { MAD_F(0x043fc8f6) /* 0.265572511 */, 15 },
+ /* 902 */ { MAD_F(0x04416522) /* 0.265965588 */, 15 },
+ /* 903 */ { MAD_F(0x04430174) /* 0.266358810 */, 15 },
+ /* 904 */ { MAD_F(0x04449dee) /* 0.266752177 */, 15 },
+ /* 905 */ { MAD_F(0x04463a8f) /* 0.267145689 */, 15 },
+ /* 906 */ { MAD_F(0x0447d756) /* 0.267539347 */, 15 },
+ /* 907 */ { MAD_F(0x04497445) /* 0.267933149 */, 15 },
+ /* 908 */ { MAD_F(0x044b115a) /* 0.268327096 */, 15 },
+ /* 909 */ { MAD_F(0x044cae96) /* 0.268721187 */, 15 },
+ /* 910 */ { MAD_F(0x044e4bf9) /* 0.269115423 */, 15 },
+ /* 911 */ { MAD_F(0x044fe983) /* 0.269509804 */, 15 },
+
+ /* 912 */ { MAD_F(0x04518733) /* 0.269904329 */, 15 },
+ /* 913 */ { MAD_F(0x0453250a) /* 0.270298998 */, 15 },
+ /* 914 */ { MAD_F(0x0454c308) /* 0.270693811 */, 15 },
+ /* 915 */ { MAD_F(0x0456612d) /* 0.271088768 */, 15 },
+ /* 916 */ { MAD_F(0x0457ff78) /* 0.271483869 */, 15 },
+ /* 917 */ { MAD_F(0x04599dea) /* 0.271879114 */, 15 },
+ /* 918 */ { MAD_F(0x045b3c82) /* 0.272274503 */, 15 },
+ /* 919 */ { MAD_F(0x045cdb41) /* 0.272670035 */, 15 },
+ /* 920 */ { MAD_F(0x045e7a26) /* 0.273065710 */, 15 },
+ /* 921 */ { MAD_F(0x04601932) /* 0.273461530 */, 15 },
+ /* 922 */ { MAD_F(0x0461b864) /* 0.273857492 */, 15 },
+ /* 923 */ { MAD_F(0x046357bd) /* 0.274253597 */, 15 },
+ /* 924 */ { MAD_F(0x0464f73c) /* 0.274649846 */, 15 },
+ /* 925 */ { MAD_F(0x046696e2) /* 0.275046238 */, 15 },
+ /* 926 */ { MAD_F(0x046836ae) /* 0.275442772 */, 15 },
+ /* 927 */ { MAD_F(0x0469d6a0) /* 0.275839449 */, 15 },
+
+ /* 928 */ { MAD_F(0x046b76b9) /* 0.276236269 */, 15 },
+ /* 929 */ { MAD_F(0x046d16f7) /* 0.276633232 */, 15 },
+ /* 930 */ { MAD_F(0x046eb75c) /* 0.277030337 */, 15 },
+ /* 931 */ { MAD_F(0x047057e8) /* 0.277427584 */, 15 },
+ /* 932 */ { MAD_F(0x0471f899) /* 0.277824973 */, 15 },
+ /* 933 */ { MAD_F(0x04739971) /* 0.278222505 */, 15 },
+ /* 934 */ { MAD_F(0x04753a6f) /* 0.278620179 */, 15 },
+ /* 935 */ { MAD_F(0x0476db92) /* 0.279017995 */, 15 },
+ /* 936 */ { MAD_F(0x04787cdc) /* 0.279415952 */, 15 },
+ /* 937 */ { MAD_F(0x047a1e4c) /* 0.279814051 */, 15 },
+ /* 938 */ { MAD_F(0x047bbfe2) /* 0.280212292 */, 15 },
+ /* 939 */ { MAD_F(0x047d619e) /* 0.280610675 */, 15 },
+ /* 940 */ { MAD_F(0x047f0380) /* 0.281009199 */, 15 },
+ /* 941 */ { MAD_F(0x0480a588) /* 0.281407864 */, 15 },
+ /* 942 */ { MAD_F(0x048247b6) /* 0.281806670 */, 15 },
+ /* 943 */ { MAD_F(0x0483ea0a) /* 0.282205618 */, 15 },
+
+ /* 944 */ { MAD_F(0x04858c83) /* 0.282604707 */, 15 },
+ /* 945 */ { MAD_F(0x04872f22) /* 0.283003936 */, 15 },
+ /* 946 */ { MAD_F(0x0488d1e8) /* 0.283403307 */, 15 },
+ /* 947 */ { MAD_F(0x048a74d3) /* 0.283802818 */, 15 },
+ /* 948 */ { MAD_F(0x048c17e3) /* 0.284202470 */, 15 },
+ /* 949 */ { MAD_F(0x048dbb1a) /* 0.284602263 */, 15 },
+ /* 950 */ { MAD_F(0x048f5e76) /* 0.285002195 */, 15 },
+ /* 951 */ { MAD_F(0x049101f8) /* 0.285402269 */, 15 },
+ /* 952 */ { MAD_F(0x0492a59f) /* 0.285802482 */, 15 },
+ /* 953 */ { MAD_F(0x0494496c) /* 0.286202836 */, 15 },
+ /* 954 */ { MAD_F(0x0495ed5f) /* 0.286603329 */, 15 },
+ /* 955 */ { MAD_F(0x04979177) /* 0.287003963 */, 15 },
+ /* 956 */ { MAD_F(0x049935b5) /* 0.287404737 */, 15 },
+ /* 957 */ { MAD_F(0x049ada19) /* 0.287805650 */, 15 },
+ /* 958 */ { MAD_F(0x049c7ea1) /* 0.288206703 */, 15 },
+ /* 959 */ { MAD_F(0x049e2350) /* 0.288607895 */, 15 },
+
+ /* 960 */ { MAD_F(0x049fc824) /* 0.289009227 */, 15 },
+ /* 961 */ { MAD_F(0x04a16d1d) /* 0.289410699 */, 15 },
+ /* 962 */ { MAD_F(0x04a3123b) /* 0.289812309 */, 15 },
+ /* 963 */ { MAD_F(0x04a4b77f) /* 0.290214059 */, 15 },
+ /* 964 */ { MAD_F(0x04a65ce8) /* 0.290615948 */, 15 },
+ /* 965 */ { MAD_F(0x04a80277) /* 0.291017976 */, 15 },
+ /* 966 */ { MAD_F(0x04a9a82b) /* 0.291420143 */, 15 },
+ /* 967 */ { MAD_F(0x04ab4e04) /* 0.291822449 */, 15 },
+ /* 968 */ { MAD_F(0x04acf402) /* 0.292224893 */, 15 },
+ /* 969 */ { MAD_F(0x04ae9a26) /* 0.292627476 */, 15 },
+ /* 970 */ { MAD_F(0x04b0406e) /* 0.293030197 */, 15 },
+ /* 971 */ { MAD_F(0x04b1e6dc) /* 0.293433057 */, 15 },
+ /* 972 */ { MAD_F(0x04b38d6f) /* 0.293836055 */, 15 },
+ /* 973 */ { MAD_F(0x04b53427) /* 0.294239192 */, 15 },
+ /* 974 */ { MAD_F(0x04b6db05) /* 0.294642466 */, 15 },
+ /* 975 */ { MAD_F(0x04b88207) /* 0.295045879 */, 15 },
+
+ /* 976 */ { MAD_F(0x04ba292e) /* 0.295449429 */, 15 },
+ /* 977 */ { MAD_F(0x04bbd07a) /* 0.295853118 */, 15 },
+ /* 978 */ { MAD_F(0x04bd77ec) /* 0.296256944 */, 15 },
+ /* 979 */ { MAD_F(0x04bf1f82) /* 0.296660907 */, 15 },
+ /* 980 */ { MAD_F(0x04c0c73d) /* 0.297065009 */, 15 },
+ /* 981 */ { MAD_F(0x04c26f1d) /* 0.297469248 */, 15 },
+ /* 982 */ { MAD_F(0x04c41722) /* 0.297873624 */, 15 },
+ /* 983 */ { MAD_F(0x04c5bf4c) /* 0.298278137 */, 15 },
+ /* 984 */ { MAD_F(0x04c7679a) /* 0.298682788 */, 15 },
+ /* 985 */ { MAD_F(0x04c9100d) /* 0.299087576 */, 15 },
+ /* 986 */ { MAD_F(0x04cab8a6) /* 0.299492500 */, 15 },
+ /* 987 */ { MAD_F(0x04cc6163) /* 0.299897562 */, 15 },
+ /* 988 */ { MAD_F(0x04ce0a44) /* 0.300302761 */, 15 },
+ /* 989 */ { MAD_F(0x04cfb34b) /* 0.300708096 */, 15 },
+ /* 990 */ { MAD_F(0x04d15c76) /* 0.301113568 */, 15 },
+ /* 991 */ { MAD_F(0x04d305c5) /* 0.301519176 */, 15 },
+
+ /* 992 */ { MAD_F(0x04d4af3a) /* 0.301924921 */, 15 },
+ /* 993 */ { MAD_F(0x04d658d2) /* 0.302330802 */, 15 },
+ /* 994 */ { MAD_F(0x04d80290) /* 0.302736820 */, 15 },
+ /* 995 */ { MAD_F(0x04d9ac72) /* 0.303142973 */, 15 },
+ /* 996 */ { MAD_F(0x04db5679) /* 0.303549263 */, 15 },
+ /* 997 */ { MAD_F(0x04dd00a4) /* 0.303955689 */, 15 },
+ /* 998 */ { MAD_F(0x04deaaf3) /* 0.304362251 */, 15 },
+ /* 999 */ { MAD_F(0x04e05567) /* 0.304768948 */, 15 },
+ /* 1000 */ { MAD_F(0x04e20000) /* 0.305175781 */, 15 },
+ /* 1001 */ { MAD_F(0x04e3aabd) /* 0.305582750 */, 15 },
+ /* 1002 */ { MAD_F(0x04e5559e) /* 0.305989854 */, 15 },
+ /* 1003 */ { MAD_F(0x04e700a3) /* 0.306397094 */, 15 },
+ /* 1004 */ { MAD_F(0x04e8abcd) /* 0.306804470 */, 15 },
+ /* 1005 */ { MAD_F(0x04ea571c) /* 0.307211980 */, 15 },
+ /* 1006 */ { MAD_F(0x04ec028e) /* 0.307619626 */, 15 },
+ /* 1007 */ { MAD_F(0x04edae25) /* 0.308027406 */, 15 },
+
+ /* 1008 */ { MAD_F(0x04ef59e0) /* 0.308435322 */, 15 },
+ /* 1009 */ { MAD_F(0x04f105bf) /* 0.308843373 */, 15 },
+ /* 1010 */ { MAD_F(0x04f2b1c3) /* 0.309251558 */, 15 },
+ /* 1011 */ { MAD_F(0x04f45dea) /* 0.309659879 */, 15 },
+ /* 1012 */ { MAD_F(0x04f60a36) /* 0.310068333 */, 15 },
+ /* 1013 */ { MAD_F(0x04f7b6a6) /* 0.310476923 */, 15 },
+ /* 1014 */ { MAD_F(0x04f9633a) /* 0.310885647 */, 15 },
+ /* 1015 */ { MAD_F(0x04fb0ff2) /* 0.311294505 */, 15 },
+ /* 1016 */ { MAD_F(0x04fcbcce) /* 0.311703498 */, 15 },
+ /* 1017 */ { MAD_F(0x04fe69ce) /* 0.312112625 */, 15 },
+ /* 1018 */ { MAD_F(0x050016f3) /* 0.312521885 */, 15 },
+ /* 1019 */ { MAD_F(0x0501c43b) /* 0.312931280 */, 15 },
+ /* 1020 */ { MAD_F(0x050371a7) /* 0.313340809 */, 15 },
+ /* 1021 */ { MAD_F(0x05051f37) /* 0.313750472 */, 15 },
+ /* 1022 */ { MAD_F(0x0506cceb) /* 0.314160269 */, 15 },
+ /* 1023 */ { MAD_F(0x05087ac2) /* 0.314570199 */, 15 },
+
+ /* 1024 */ { MAD_F(0x050a28be) /* 0.314980262 */, 15 },
+ /* 1025 */ { MAD_F(0x050bd6de) /* 0.315390460 */, 15 },
+ /* 1026 */ { MAD_F(0x050d8521) /* 0.315800790 */, 15 },
+ /* 1027 */ { MAD_F(0x050f3388) /* 0.316211255 */, 15 },
+ /* 1028 */ { MAD_F(0x0510e213) /* 0.316621852 */, 15 },
+ /* 1029 */ { MAD_F(0x051290c2) /* 0.317032582 */, 15 },
+ /* 1030 */ { MAD_F(0x05143f94) /* 0.317443446 */, 15 },
+ /* 1031 */ { MAD_F(0x0515ee8a) /* 0.317854442 */, 15 },
+ /* 1032 */ { MAD_F(0x05179da4) /* 0.318265572 */, 15 },
+ /* 1033 */ { MAD_F(0x05194ce1) /* 0.318676834 */, 15 },
+ /* 1034 */ { MAD_F(0x051afc42) /* 0.319088229 */, 15 },
+ /* 1035 */ { MAD_F(0x051cabc7) /* 0.319499756 */, 15 },
+ /* 1036 */ { MAD_F(0x051e5b6f) /* 0.319911417 */, 15 },
+ /* 1037 */ { MAD_F(0x05200b3a) /* 0.320323209 */, 15 },
+ /* 1038 */ { MAD_F(0x0521bb2a) /* 0.320735134 */, 15 },
+ /* 1039 */ { MAD_F(0x05236b3d) /* 0.321147192 */, 15 },
+
+ /* 1040 */ { MAD_F(0x05251b73) /* 0.321559381 */, 15 },
+ /* 1041 */ { MAD_F(0x0526cbcd) /* 0.321971703 */, 15 },
+ /* 1042 */ { MAD_F(0x05287c4a) /* 0.322384156 */, 15 },
+ /* 1043 */ { MAD_F(0x052a2cea) /* 0.322796742 */, 15 },
+ /* 1044 */ { MAD_F(0x052bddae) /* 0.323209460 */, 15 },
+ /* 1045 */ { MAD_F(0x052d8e96) /* 0.323622309 */, 15 },
+ /* 1046 */ { MAD_F(0x052f3fa1) /* 0.324035290 */, 15 },
+ /* 1047 */ { MAD_F(0x0530f0cf) /* 0.324448403 */, 15 },
+ /* 1048 */ { MAD_F(0x0532a220) /* 0.324861647 */, 15 },
+ /* 1049 */ { MAD_F(0x05345395) /* 0.325275023 */, 15 },
+ /* 1050 */ { MAD_F(0x0536052d) /* 0.325688530 */, 15 },
+ /* 1051 */ { MAD_F(0x0537b6e8) /* 0.326102168 */, 15 },
+ /* 1052 */ { MAD_F(0x053968c6) /* 0.326515938 */, 15 },
+ /* 1053 */ { MAD_F(0x053b1ac8) /* 0.326929839 */, 15 },
+ /* 1054 */ { MAD_F(0x053ccced) /* 0.327343870 */, 15 },
+ /* 1055 */ { MAD_F(0x053e7f35) /* 0.327758033 */, 15 },
+
+ /* 1056 */ { MAD_F(0x054031a0) /* 0.328172327 */, 15 },
+ /* 1057 */ { MAD_F(0x0541e42e) /* 0.328586751 */, 15 },
+ /* 1058 */ { MAD_F(0x054396df) /* 0.329001306 */, 15 },
+ /* 1059 */ { MAD_F(0x054549b4) /* 0.329415992 */, 15 },
+ /* 1060 */ { MAD_F(0x0546fcab) /* 0.329830808 */, 15 },
+ /* 1061 */ { MAD_F(0x0548afc6) /* 0.330245755 */, 15 },
+ /* 1062 */ { MAD_F(0x054a6303) /* 0.330660832 */, 15 },
+ /* 1063 */ { MAD_F(0x054c1663) /* 0.331076039 */, 15 },
+ /* 1064 */ { MAD_F(0x054dc9e7) /* 0.331491377 */, 15 },
+ /* 1065 */ { MAD_F(0x054f7d8d) /* 0.331906845 */, 15 },
+ /* 1066 */ { MAD_F(0x05513156) /* 0.332322443 */, 15 },
+ /* 1067 */ { MAD_F(0x0552e542) /* 0.332738170 */, 15 },
+ /* 1068 */ { MAD_F(0x05549951) /* 0.333154028 */, 15 },
+ /* 1069 */ { MAD_F(0x05564d83) /* 0.333570016 */, 15 },
+ /* 1070 */ { MAD_F(0x055801d8) /* 0.333986133 */, 15 },
+ /* 1071 */ { MAD_F(0x0559b64f) /* 0.334402380 */, 15 },
+
+ /* 1072 */ { MAD_F(0x055b6ae9) /* 0.334818756 */, 15 },
+ /* 1073 */ { MAD_F(0x055d1fa6) /* 0.335235262 */, 15 },
+ /* 1074 */ { MAD_F(0x055ed486) /* 0.335651898 */, 15 },
+ /* 1075 */ { MAD_F(0x05608988) /* 0.336068662 */, 15 },
+ /* 1076 */ { MAD_F(0x05623ead) /* 0.336485556 */, 15 },
+ /* 1077 */ { MAD_F(0x0563f3f5) /* 0.336902579 */, 15 },
+ /* 1078 */ { MAD_F(0x0565a960) /* 0.337319732 */, 15 },
+ /* 1079 */ { MAD_F(0x05675eed) /* 0.337737013 */, 15 },
+ /* 1080 */ { MAD_F(0x0569149c) /* 0.338154423 */, 15 },
+ /* 1081 */ { MAD_F(0x056aca6f) /* 0.338571962 */, 15 },
+ /* 1082 */ { MAD_F(0x056c8064) /* 0.338989630 */, 15 },
+ /* 1083 */ { MAD_F(0x056e367b) /* 0.339407426 */, 15 },
+ /* 1084 */ { MAD_F(0x056fecb5) /* 0.339825351 */, 15 },
+ /* 1085 */ { MAD_F(0x0571a311) /* 0.340243405 */, 15 },
+ /* 1086 */ { MAD_F(0x05735990) /* 0.340661587 */, 15 },
+ /* 1087 */ { MAD_F(0x05751032) /* 0.341079898 */, 15 },
+
+ /* 1088 */ { MAD_F(0x0576c6f5) /* 0.341498336 */, 15 },
+ /* 1089 */ { MAD_F(0x05787ddc) /* 0.341916903 */, 15 },
+ /* 1090 */ { MAD_F(0x057a34e4) /* 0.342335598 */, 15 },
+ /* 1091 */ { MAD_F(0x057bec0f) /* 0.342754421 */, 15 },
+ /* 1092 */ { MAD_F(0x057da35d) /* 0.343173373 */, 15 },
+ /* 1093 */ { MAD_F(0x057f5acc) /* 0.343592452 */, 15 },
+ /* 1094 */ { MAD_F(0x0581125e) /* 0.344011659 */, 15 },
+ /* 1095 */ { MAD_F(0x0582ca12) /* 0.344430993 */, 15 },
+ /* 1096 */ { MAD_F(0x058481e9) /* 0.344850455 */, 15 },
+ /* 1097 */ { MAD_F(0x058639e2) /* 0.345270045 */, 15 },
+ /* 1098 */ { MAD_F(0x0587f1fd) /* 0.345689763 */, 15 },
+ /* 1099 */ { MAD_F(0x0589aa3a) /* 0.346109608 */, 15 },
+ /* 1100 */ { MAD_F(0x058b629a) /* 0.346529580 */, 15 },
+ /* 1101 */ { MAD_F(0x058d1b1b) /* 0.346949679 */, 15 },
+ /* 1102 */ { MAD_F(0x058ed3bf) /* 0.347369906 */, 15 },
+ /* 1103 */ { MAD_F(0x05908c85) /* 0.347790260 */, 15 },
+
+ /* 1104 */ { MAD_F(0x0592456d) /* 0.348210741 */, 15 },
+ /* 1105 */ { MAD_F(0x0593fe77) /* 0.348631348 */, 15 },
+ /* 1106 */ { MAD_F(0x0595b7a3) /* 0.349052083 */, 15 },
+ /* 1107 */ { MAD_F(0x059770f1) /* 0.349472945 */, 15 },
+ /* 1108 */ { MAD_F(0x05992a61) /* 0.349893933 */, 15 },
+ /* 1109 */ { MAD_F(0x059ae3f3) /* 0.350315048 */, 15 },
+ /* 1110 */ { MAD_F(0x059c9da8) /* 0.350736290 */, 15 },
+ /* 1111 */ { MAD_F(0x059e577e) /* 0.351157658 */, 15 },
+ /* 1112 */ { MAD_F(0x05a01176) /* 0.351579152 */, 15 },
+ /* 1113 */ { MAD_F(0x05a1cb90) /* 0.352000773 */, 15 },
+ /* 1114 */ { MAD_F(0x05a385cc) /* 0.352422520 */, 15 },
+ /* 1115 */ { MAD_F(0x05a5402a) /* 0.352844394 */, 15 },
+ /* 1116 */ { MAD_F(0x05a6faa9) /* 0.353266393 */, 15 },
+ /* 1117 */ { MAD_F(0x05a8b54b) /* 0.353688519 */, 15 },
+ /* 1118 */ { MAD_F(0x05aa700e) /* 0.354110771 */, 15 },
+ /* 1119 */ { MAD_F(0x05ac2af3) /* 0.354533148 */, 15 },
+
+ /* 1120 */ { MAD_F(0x05ade5fa) /* 0.354955651 */, 15 },
+ /* 1121 */ { MAD_F(0x05afa123) /* 0.355378281 */, 15 },
+ /* 1122 */ { MAD_F(0x05b15c6d) /* 0.355801035 */, 15 },
+ /* 1123 */ { MAD_F(0x05b317d9) /* 0.356223916 */, 15 },
+ /* 1124 */ { MAD_F(0x05b4d367) /* 0.356646922 */, 15 },
+ /* 1125 */ { MAD_F(0x05b68f16) /* 0.357070053 */, 15 },
+ /* 1126 */ { MAD_F(0x05b84ae7) /* 0.357493310 */, 15 },
+ /* 1127 */ { MAD_F(0x05ba06da) /* 0.357916692 */, 15 },
+ /* 1128 */ { MAD_F(0x05bbc2ef) /* 0.358340200 */, 15 },
+ /* 1129 */ { MAD_F(0x05bd7f25) /* 0.358763832 */, 15 },
+ /* 1130 */ { MAD_F(0x05bf3b7c) /* 0.359187590 */, 15 },
+ /* 1131 */ { MAD_F(0x05c0f7f5) /* 0.359611472 */, 15 },
+ /* 1132 */ { MAD_F(0x05c2b490) /* 0.360035480 */, 15 },
+ /* 1133 */ { MAD_F(0x05c4714c) /* 0.360459613 */, 15 },
+ /* 1134 */ { MAD_F(0x05c62e2a) /* 0.360883870 */, 15 },
+ /* 1135 */ { MAD_F(0x05c7eb29) /* 0.361308252 */, 15 },
+
+ /* 1136 */ { MAD_F(0x05c9a84a) /* 0.361732758 */, 15 },
+ /* 1137 */ { MAD_F(0x05cb658c) /* 0.362157390 */, 15 },
+ /* 1138 */ { MAD_F(0x05cd22ef) /* 0.362582145 */, 15 },
+ /* 1139 */ { MAD_F(0x05cee074) /* 0.363007026 */, 15 },
+ /* 1140 */ { MAD_F(0x05d09e1b) /* 0.363432030 */, 15 },
+ /* 1141 */ { MAD_F(0x05d25be2) /* 0.363857159 */, 15 },
+ /* 1142 */ { MAD_F(0x05d419cb) /* 0.364282412 */, 15 },
+ /* 1143 */ { MAD_F(0x05d5d7d5) /* 0.364707789 */, 15 },
+ /* 1144 */ { MAD_F(0x05d79601) /* 0.365133291 */, 15 },
+ /* 1145 */ { MAD_F(0x05d9544e) /* 0.365558916 */, 15 },
+ /* 1146 */ { MAD_F(0x05db12bc) /* 0.365984665 */, 15 },
+ /* 1147 */ { MAD_F(0x05dcd14c) /* 0.366410538 */, 15 },
+ /* 1148 */ { MAD_F(0x05de8ffc) /* 0.366836535 */, 15 },
+ /* 1149 */ { MAD_F(0x05e04ece) /* 0.367262655 */, 15 },
+ /* 1150 */ { MAD_F(0x05e20dc1) /* 0.367688900 */, 15 },
+ /* 1151 */ { MAD_F(0x05e3ccd5) /* 0.368115267 */, 15 },
+
+ /* 1152 */ { MAD_F(0x05e58c0b) /* 0.368541759 */, 15 },
+ /* 1153 */ { MAD_F(0x05e74b61) /* 0.368968373 */, 15 },
+ /* 1154 */ { MAD_F(0x05e90ad9) /* 0.369395111 */, 15 },
+ /* 1155 */ { MAD_F(0x05eaca72) /* 0.369821973 */, 15 },
+ /* 1156 */ { MAD_F(0x05ec8a2b) /* 0.370248957 */, 15 },
+ /* 1157 */ { MAD_F(0x05ee4a06) /* 0.370676065 */, 15 },
+ /* 1158 */ { MAD_F(0x05f00a02) /* 0.371103295 */, 15 },
+ /* 1159 */ { MAD_F(0x05f1ca1f) /* 0.371530649 */, 15 },
+ /* 1160 */ { MAD_F(0x05f38a5d) /* 0.371958126 */, 15 },
+ /* 1161 */ { MAD_F(0x05f54abc) /* 0.372385725 */, 15 },
+ /* 1162 */ { MAD_F(0x05f70b3c) /* 0.372813448 */, 15 },
+ /* 1163 */ { MAD_F(0x05f8cbdc) /* 0.373241292 */, 15 },
+ /* 1164 */ { MAD_F(0x05fa8c9e) /* 0.373669260 */, 15 },
+ /* 1165 */ { MAD_F(0x05fc4d81) /* 0.374097350 */, 15 },
+ /* 1166 */ { MAD_F(0x05fe0e84) /* 0.374525563 */, 15 },
+ /* 1167 */ { MAD_F(0x05ffcfa8) /* 0.374953898 */, 15 },
+
+ /* 1168 */ { MAD_F(0x060190ee) /* 0.375382356 */, 15 },
+ /* 1169 */ { MAD_F(0x06035254) /* 0.375810936 */, 15 },
+ /* 1170 */ { MAD_F(0x060513da) /* 0.376239638 */, 15 },
+ /* 1171 */ { MAD_F(0x0606d582) /* 0.376668462 */, 15 },
+ /* 1172 */ { MAD_F(0x0608974a) /* 0.377097408 */, 15 },
+ /* 1173 */ { MAD_F(0x060a5934) /* 0.377526476 */, 15 },
+ /* 1174 */ { MAD_F(0x060c1b3d) /* 0.377955667 */, 15 },
+ /* 1175 */ { MAD_F(0x060ddd68) /* 0.378384979 */, 15 },
+ /* 1176 */ { MAD_F(0x060f9fb3) /* 0.378814413 */, 15 },
+ /* 1177 */ { MAD_F(0x0611621f) /* 0.379243968 */, 15 },
+ /* 1178 */ { MAD_F(0x061324ac) /* 0.379673646 */, 15 },
+ /* 1179 */ { MAD_F(0x0614e759) /* 0.380103444 */, 15 },
+ /* 1180 */ { MAD_F(0x0616aa27) /* 0.380533365 */, 15 },
+ /* 1181 */ { MAD_F(0x06186d16) /* 0.380963407 */, 15 },
+ /* 1182 */ { MAD_F(0x061a3025) /* 0.381393570 */, 15 },
+ /* 1183 */ { MAD_F(0x061bf354) /* 0.381823855 */, 15 },
+
+ /* 1184 */ { MAD_F(0x061db6a5) /* 0.382254261 */, 15 },
+ /* 1185 */ { MAD_F(0x061f7a15) /* 0.382684788 */, 15 },
+ /* 1186 */ { MAD_F(0x06213da7) /* 0.383115436 */, 15 },
+ /* 1187 */ { MAD_F(0x06230158) /* 0.383546205 */, 15 },
+ /* 1188 */ { MAD_F(0x0624c52a) /* 0.383977096 */, 15 },
+ /* 1189 */ { MAD_F(0x0626891d) /* 0.384408107 */, 15 },
+ /* 1190 */ { MAD_F(0x06284d30) /* 0.384839239 */, 15 },
+ /* 1191 */ { MAD_F(0x062a1164) /* 0.385270492 */, 15 },
+ /* 1192 */ { MAD_F(0x062bd5b8) /* 0.385701865 */, 15 },
+ /* 1193 */ { MAD_F(0x062d9a2c) /* 0.386133359 */, 15 },
+ /* 1194 */ { MAD_F(0x062f5ec1) /* 0.386564974 */, 15 },
+ /* 1195 */ { MAD_F(0x06312376) /* 0.386996709 */, 15 },
+ /* 1196 */ { MAD_F(0x0632e84b) /* 0.387428565 */, 15 },
+ /* 1197 */ { MAD_F(0x0634ad41) /* 0.387860541 */, 15 },
+ /* 1198 */ { MAD_F(0x06367257) /* 0.388292637 */, 15 },
+ /* 1199 */ { MAD_F(0x0638378d) /* 0.388724854 */, 15 },
+
+ /* 1200 */ { MAD_F(0x0639fce4) /* 0.389157191 */, 15 },
+ /* 1201 */ { MAD_F(0x063bc25b) /* 0.389589648 */, 15 },
+ /* 1202 */ { MAD_F(0x063d87f2) /* 0.390022225 */, 15 },
+ /* 1203 */ { MAD_F(0x063f4da9) /* 0.390454922 */, 15 },
+ /* 1204 */ { MAD_F(0x06411380) /* 0.390887739 */, 15 },
+ /* 1205 */ { MAD_F(0x0642d978) /* 0.391320675 */, 15 },
+ /* 1206 */ { MAD_F(0x06449f8f) /* 0.391753732 */, 15 },
+ /* 1207 */ { MAD_F(0x064665c7) /* 0.392186908 */, 15 },
+ /* 1208 */ { MAD_F(0x06482c1f) /* 0.392620204 */, 15 },
+ /* 1209 */ { MAD_F(0x0649f297) /* 0.393053619 */, 15 },
+ /* 1210 */ { MAD_F(0x064bb92f) /* 0.393487154 */, 15 },
+ /* 1211 */ { MAD_F(0x064d7fe8) /* 0.393920808 */, 15 },
+ /* 1212 */ { MAD_F(0x064f46c0) /* 0.394354582 */, 15 },
+ /* 1213 */ { MAD_F(0x06510db8) /* 0.394788475 */, 15 },
+ /* 1214 */ { MAD_F(0x0652d4d0) /* 0.395222488 */, 15 },
+ /* 1215 */ { MAD_F(0x06549c09) /* 0.395656619 */, 15 },
+
+ /* 1216 */ { MAD_F(0x06566361) /* 0.396090870 */, 15 },
+ /* 1217 */ { MAD_F(0x06582ad9) /* 0.396525239 */, 15 },
+ /* 1218 */ { MAD_F(0x0659f271) /* 0.396959728 */, 15 },
+ /* 1219 */ { MAD_F(0x065bba29) /* 0.397394336 */, 15 },
+ /* 1220 */ { MAD_F(0x065d8201) /* 0.397829062 */, 15 },
+ /* 1221 */ { MAD_F(0x065f49f9) /* 0.398263907 */, 15 },
+ /* 1222 */ { MAD_F(0x06611211) /* 0.398698871 */, 15 },
+ /* 1223 */ { MAD_F(0x0662da49) /* 0.399133954 */, 15 },
+ /* 1224 */ { MAD_F(0x0664a2a0) /* 0.399569155 */, 15 },
+ /* 1225 */ { MAD_F(0x06666b17) /* 0.400004475 */, 15 },
+ /* 1226 */ { MAD_F(0x066833ae) /* 0.400439913 */, 15 },
+ /* 1227 */ { MAD_F(0x0669fc65) /* 0.400875470 */, 15 },
+ /* 1228 */ { MAD_F(0x066bc53c) /* 0.401311145 */, 15 },
+ /* 1229 */ { MAD_F(0x066d8e32) /* 0.401746938 */, 15 },
+ /* 1230 */ { MAD_F(0x066f5748) /* 0.402182850 */, 15 },
+ /* 1231 */ { MAD_F(0x0671207e) /* 0.402618879 */, 15 },
+
+ /* 1232 */ { MAD_F(0x0672e9d4) /* 0.403055027 */, 15 },
+ /* 1233 */ { MAD_F(0x0674b349) /* 0.403491293 */, 15 },
+ /* 1234 */ { MAD_F(0x06767cde) /* 0.403927676 */, 15 },
+ /* 1235 */ { MAD_F(0x06784692) /* 0.404364178 */, 15 },
+ /* 1236 */ { MAD_F(0x067a1066) /* 0.404800797 */, 15 },
+ /* 1237 */ { MAD_F(0x067bda5a) /* 0.405237535 */, 15 },
+ /* 1238 */ { MAD_F(0x067da46d) /* 0.405674390 */, 15 },
+ /* 1239 */ { MAD_F(0x067f6ea0) /* 0.406111362 */, 15 },
+ /* 1240 */ { MAD_F(0x068138f3) /* 0.406548452 */, 15 },
+ /* 1241 */ { MAD_F(0x06830365) /* 0.406985660 */, 15 },
+ /* 1242 */ { MAD_F(0x0684cdf6) /* 0.407422985 */, 15 },
+ /* 1243 */ { MAD_F(0x068698a8) /* 0.407860427 */, 15 },
+ /* 1244 */ { MAD_F(0x06886378) /* 0.408297987 */, 15 },
+ /* 1245 */ { MAD_F(0x068a2e68) /* 0.408735664 */, 15 },
+ /* 1246 */ { MAD_F(0x068bf978) /* 0.409173458 */, 15 },
+ /* 1247 */ { MAD_F(0x068dc4a7) /* 0.409611370 */, 15 },
+
+ /* 1248 */ { MAD_F(0x068f8ff5) /* 0.410049398 */, 15 },
+ /* 1249 */ { MAD_F(0x06915b63) /* 0.410487544 */, 15 },
+ /* 1250 */ { MAD_F(0x069326f0) /* 0.410925806 */, 15 },
+ /* 1251 */ { MAD_F(0x0694f29c) /* 0.411364185 */, 15 },
+ /* 1252 */ { MAD_F(0x0696be68) /* 0.411802681 */, 15 },
+ /* 1253 */ { MAD_F(0x06988a54) /* 0.412241294 */, 15 },
+ /* 1254 */ { MAD_F(0x069a565e) /* 0.412680024 */, 15 },
+ /* 1255 */ { MAD_F(0x069c2288) /* 0.413118870 */, 15 },
+ /* 1256 */ { MAD_F(0x069deed1) /* 0.413557833 */, 15 },
+ /* 1257 */ { MAD_F(0x069fbb3a) /* 0.413996912 */, 15 },
+ /* 1258 */ { MAD_F(0x06a187c1) /* 0.414436108 */, 15 },
+ /* 1259 */ { MAD_F(0x06a35468) /* 0.414875420 */, 15 },
+ /* 1260 */ { MAD_F(0x06a5212f) /* 0.415314849 */, 15 },
+ /* 1261 */ { MAD_F(0x06a6ee14) /* 0.415754393 */, 15 },
+ /* 1262 */ { MAD_F(0x06a8bb18) /* 0.416194054 */, 15 },
+ /* 1263 */ { MAD_F(0x06aa883c) /* 0.416633831 */, 15 },
+
+ /* 1264 */ { MAD_F(0x06ac557f) /* 0.417073724 */, 15 },
+ /* 1265 */ { MAD_F(0x06ae22e1) /* 0.417513734 */, 15 },
+ /* 1266 */ { MAD_F(0x06aff062) /* 0.417953859 */, 15 },
+ /* 1267 */ { MAD_F(0x06b1be03) /* 0.418394100 */, 15 },
+ /* 1268 */ { MAD_F(0x06b38bc2) /* 0.418834457 */, 15 },
+ /* 1269 */ { MAD_F(0x06b559a1) /* 0.419274929 */, 15 },
+ /* 1270 */ { MAD_F(0x06b7279e) /* 0.419715518 */, 15 },
+ /* 1271 */ { MAD_F(0x06b8f5bb) /* 0.420156222 */, 15 },
+ /* 1272 */ { MAD_F(0x06bac3f6) /* 0.420597041 */, 15 },
+ /* 1273 */ { MAD_F(0x06bc9251) /* 0.421037977 */, 15 },
+ /* 1274 */ { MAD_F(0x06be60cb) /* 0.421479027 */, 15 },
+ /* 1275 */ { MAD_F(0x06c02f63) /* 0.421920193 */, 15 },
+ /* 1276 */ { MAD_F(0x06c1fe1b) /* 0.422361475 */, 15 },
+ /* 1277 */ { MAD_F(0x06c3ccf1) /* 0.422802871 */, 15 },
+ /* 1278 */ { MAD_F(0x06c59be7) /* 0.423244383 */, 15 },
+ /* 1279 */ { MAD_F(0x06c76afb) /* 0.423686010 */, 15 },
+
+ /* 1280 */ { MAD_F(0x06c93a2e) /* 0.424127753 */, 15 },
+ /* 1281 */ { MAD_F(0x06cb0981) /* 0.424569610 */, 15 },
+ /* 1282 */ { MAD_F(0x06ccd8f2) /* 0.425011582 */, 15 },
+ /* 1283 */ { MAD_F(0x06cea881) /* 0.425453669 */, 15 },
+ /* 1284 */ { MAD_F(0x06d07830) /* 0.425895871 */, 15 },
+ /* 1285 */ { MAD_F(0x06d247fe) /* 0.426338188 */, 15 },
+ /* 1286 */ { MAD_F(0x06d417ea) /* 0.426780620 */, 15 },
+ /* 1287 */ { MAD_F(0x06d5e7f5) /* 0.427223166 */, 15 },
+ /* 1288 */ { MAD_F(0x06d7b81f) /* 0.427665827 */, 15 },
+ /* 1289 */ { MAD_F(0x06d98868) /* 0.428108603 */, 15 },
+ /* 1290 */ { MAD_F(0x06db58cf) /* 0.428551493 */, 15 },
+ /* 1291 */ { MAD_F(0x06dd2955) /* 0.428994497 */, 15 },
+ /* 1292 */ { MAD_F(0x06def9fa) /* 0.429437616 */, 15 },
+ /* 1293 */ { MAD_F(0x06e0cabe) /* 0.429880849 */, 15 },
+ /* 1294 */ { MAD_F(0x06e29ba0) /* 0.430324197 */, 15 },
+ /* 1295 */ { MAD_F(0x06e46ca1) /* 0.430767659 */, 15 },
+
+ /* 1296 */ { MAD_F(0x06e63dc0) /* 0.431211234 */, 15 },
+ /* 1297 */ { MAD_F(0x06e80efe) /* 0.431654924 */, 15 },
+ /* 1298 */ { MAD_F(0x06e9e05b) /* 0.432098728 */, 15 },
+ /* 1299 */ { MAD_F(0x06ebb1d6) /* 0.432542647 */, 15 },
+ /* 1300 */ { MAD_F(0x06ed8370) /* 0.432986678 */, 15 },
+ /* 1301 */ { MAD_F(0x06ef5529) /* 0.433430824 */, 15 },
+ /* 1302 */ { MAD_F(0x06f12700) /* 0.433875084 */, 15 },
+ /* 1303 */ { MAD_F(0x06f2f8f5) /* 0.434319457 */, 15 },
+ /* 1304 */ { MAD_F(0x06f4cb09) /* 0.434763944 */, 15 },
+ /* 1305 */ { MAD_F(0x06f69d3c) /* 0.435208545 */, 15 },
+ /* 1306 */ { MAD_F(0x06f86f8d) /* 0.435653259 */, 15 },
+ /* 1307 */ { MAD_F(0x06fa41fd) /* 0.436098087 */, 15 },
+ /* 1308 */ { MAD_F(0x06fc148b) /* 0.436543029 */, 15 },
+ /* 1309 */ { MAD_F(0x06fde737) /* 0.436988083 */, 15 },
+ /* 1310 */ { MAD_F(0x06ffba02) /* 0.437433251 */, 15 },
+ /* 1311 */ { MAD_F(0x07018ceb) /* 0.437878533 */, 15 },
+
+ /* 1312 */ { MAD_F(0x07035ff3) /* 0.438323927 */, 15 },
+ /* 1313 */ { MAD_F(0x07053319) /* 0.438769435 */, 15 },
+ /* 1314 */ { MAD_F(0x0707065d) /* 0.439215056 */, 15 },
+ /* 1315 */ { MAD_F(0x0708d9c0) /* 0.439660790 */, 15 },
+ /* 1316 */ { MAD_F(0x070aad41) /* 0.440106636 */, 15 },
+ /* 1317 */ { MAD_F(0x070c80e1) /* 0.440552596 */, 15 },
+ /* 1318 */ { MAD_F(0x070e549f) /* 0.440998669 */, 15 },
+ /* 1319 */ { MAD_F(0x0710287b) /* 0.441444855 */, 15 },
+ /* 1320 */ { MAD_F(0x0711fc75) /* 0.441891153 */, 15 },
+ /* 1321 */ { MAD_F(0x0713d08d) /* 0.442337564 */, 15 },
+ /* 1322 */ { MAD_F(0x0715a4c4) /* 0.442784088 */, 15 },
+ /* 1323 */ { MAD_F(0x07177919) /* 0.443230724 */, 15 },
+ /* 1324 */ { MAD_F(0x07194d8c) /* 0.443677473 */, 15 },
+ /* 1325 */ { MAD_F(0x071b221e) /* 0.444124334 */, 15 },
+ /* 1326 */ { MAD_F(0x071cf6ce) /* 0.444571308 */, 15 },
+ /* 1327 */ { MAD_F(0x071ecb9b) /* 0.445018394 */, 15 },
+
+ /* 1328 */ { MAD_F(0x0720a087) /* 0.445465593 */, 15 },
+ /* 1329 */ { MAD_F(0x07227591) /* 0.445912903 */, 15 },
+ /* 1330 */ { MAD_F(0x07244ab9) /* 0.446360326 */, 15 },
+ /* 1331 */ { MAD_F(0x07262000) /* 0.446807861 */, 15 },
+ /* 1332 */ { MAD_F(0x0727f564) /* 0.447255509 */, 15 },
+ /* 1333 */ { MAD_F(0x0729cae7) /* 0.447703268 */, 15 },
+ /* 1334 */ { MAD_F(0x072ba087) /* 0.448151139 */, 15 },
+ /* 1335 */ { MAD_F(0x072d7646) /* 0.448599122 */, 15 },
+ /* 1336 */ { MAD_F(0x072f4c22) /* 0.449047217 */, 15 },
+ /* 1337 */ { MAD_F(0x0731221d) /* 0.449495424 */, 15 },
+ /* 1338 */ { MAD_F(0x0732f835) /* 0.449943742 */, 15 },
+ /* 1339 */ { MAD_F(0x0734ce6c) /* 0.450392173 */, 15 },
+ /* 1340 */ { MAD_F(0x0736a4c1) /* 0.450840715 */, 15 },
+ /* 1341 */ { MAD_F(0x07387b33) /* 0.451289368 */, 15 },
+ /* 1342 */ { MAD_F(0x073a51c4) /* 0.451738133 */, 15 },
+ /* 1343 */ { MAD_F(0x073c2872) /* 0.452187010 */, 15 },
+
+ /* 1344 */ { MAD_F(0x073dff3e) /* 0.452635998 */, 15 },
+ /* 1345 */ { MAD_F(0x073fd628) /* 0.453085097 */, 15 },
+ /* 1346 */ { MAD_F(0x0741ad30) /* 0.453534308 */, 15 },
+ /* 1347 */ { MAD_F(0x07438456) /* 0.453983630 */, 15 },
+ /* 1348 */ { MAD_F(0x07455b9a) /* 0.454433063 */, 15 },
+ /* 1349 */ { MAD_F(0x074732fc) /* 0.454882607 */, 15 },
+ /* 1350 */ { MAD_F(0x07490a7b) /* 0.455332262 */, 15 },
+ /* 1351 */ { MAD_F(0x074ae218) /* 0.455782029 */, 15 },
+ /* 1352 */ { MAD_F(0x074cb9d3) /* 0.456231906 */, 15 },
+ /* 1353 */ { MAD_F(0x074e91ac) /* 0.456681894 */, 15 },
+ /* 1354 */ { MAD_F(0x075069a3) /* 0.457131993 */, 15 },
+ /* 1355 */ { MAD_F(0x075241b7) /* 0.457582203 */, 15 },
+ /* 1356 */ { MAD_F(0x075419e9) /* 0.458032524 */, 15 },
+ /* 1357 */ { MAD_F(0x0755f239) /* 0.458482956 */, 15 },
+ /* 1358 */ { MAD_F(0x0757caa7) /* 0.458933498 */, 15 },
+ /* 1359 */ { MAD_F(0x0759a332) /* 0.459384151 */, 15 },
+
+ /* 1360 */ { MAD_F(0x075b7bdb) /* 0.459834914 */, 15 },
+ /* 1361 */ { MAD_F(0x075d54a1) /* 0.460285788 */, 15 },
+ /* 1362 */ { MAD_F(0x075f2d85) /* 0.460736772 */, 15 },
+ /* 1363 */ { MAD_F(0x07610687) /* 0.461187867 */, 15 },
+ /* 1364 */ { MAD_F(0x0762dfa6) /* 0.461639071 */, 15 },
+ /* 1365 */ { MAD_F(0x0764b8e3) /* 0.462090387 */, 15 },
+ /* 1366 */ { MAD_F(0x0766923e) /* 0.462541812 */, 15 },
+ /* 1367 */ { MAD_F(0x07686bb6) /* 0.462993348 */, 15 },
+ /* 1368 */ { MAD_F(0x076a454c) /* 0.463444993 */, 15 },
+ /* 1369 */ { MAD_F(0x076c1eff) /* 0.463896749 */, 15 },
+ /* 1370 */ { MAD_F(0x076df8d0) /* 0.464348615 */, 15 },
+ /* 1371 */ { MAD_F(0x076fd2be) /* 0.464800591 */, 15 },
+ /* 1372 */ { MAD_F(0x0771acca) /* 0.465252676 */, 15 },
+ /* 1373 */ { MAD_F(0x077386f3) /* 0.465704872 */, 15 },
+ /* 1374 */ { MAD_F(0x0775613a) /* 0.466157177 */, 15 },
+ /* 1375 */ { MAD_F(0x07773b9e) /* 0.466609592 */, 15 },
+
+ /* 1376 */ { MAD_F(0x07791620) /* 0.467062117 */, 15 },
+ /* 1377 */ { MAD_F(0x077af0bf) /* 0.467514751 */, 15 },
+ /* 1378 */ { MAD_F(0x077ccb7c) /* 0.467967495 */, 15 },
+ /* 1379 */ { MAD_F(0x077ea656) /* 0.468420349 */, 15 },
+ /* 1380 */ { MAD_F(0x0780814d) /* 0.468873312 */, 15 },
+ /* 1381 */ { MAD_F(0x07825c62) /* 0.469326384 */, 15 },
+ /* 1382 */ { MAD_F(0x07843794) /* 0.469779566 */, 15 },
+ /* 1383 */ { MAD_F(0x078612e3) /* 0.470232857 */, 15 },
+ /* 1384 */ { MAD_F(0x0787ee50) /* 0.470686258 */, 15 },
+ /* 1385 */ { MAD_F(0x0789c9da) /* 0.471139767 */, 15 },
+ /* 1386 */ { MAD_F(0x078ba581) /* 0.471593386 */, 15 },
+ /* 1387 */ { MAD_F(0x078d8146) /* 0.472047114 */, 15 },
+ /* 1388 */ { MAD_F(0x078f5d28) /* 0.472500951 */, 15 },
+ /* 1389 */ { MAD_F(0x07913927) /* 0.472954896 */, 15 },
+ /* 1390 */ { MAD_F(0x07931543) /* 0.473408951 */, 15 },
+ /* 1391 */ { MAD_F(0x0794f17d) /* 0.473863115 */, 15 },
+
+ /* 1392 */ { MAD_F(0x0796cdd4) /* 0.474317388 */, 15 },
+ /* 1393 */ { MAD_F(0x0798aa48) /* 0.474771769 */, 15 },
+ /* 1394 */ { MAD_F(0x079a86d9) /* 0.475226259 */, 15 },
+ /* 1395 */ { MAD_F(0x079c6388) /* 0.475680858 */, 15 },
+ /* 1396 */ { MAD_F(0x079e4053) /* 0.476135565 */, 15 },
+ /* 1397 */ { MAD_F(0x07a01d3c) /* 0.476590381 */, 15 },
+ /* 1398 */ { MAD_F(0x07a1fa42) /* 0.477045306 */, 15 },
+ /* 1399 */ { MAD_F(0x07a3d765) /* 0.477500339 */, 15 },
+ /* 1400 */ { MAD_F(0x07a5b4a5) /* 0.477955481 */, 15 },
+ /* 1401 */ { MAD_F(0x07a79202) /* 0.478410731 */, 15 },
+ /* 1402 */ { MAD_F(0x07a96f7d) /* 0.478866089 */, 15 },
+ /* 1403 */ { MAD_F(0x07ab4d14) /* 0.479321555 */, 15 },
+ /* 1404 */ { MAD_F(0x07ad2ac8) /* 0.479777130 */, 15 },
+ /* 1405 */ { MAD_F(0x07af089a) /* 0.480232813 */, 15 },
+ /* 1406 */ { MAD_F(0x07b0e688) /* 0.480688604 */, 15 },
+ /* 1407 */ { MAD_F(0x07b2c494) /* 0.481144503 */, 15 },
+
+ /* 1408 */ { MAD_F(0x07b4a2bc) /* 0.481600510 */, 15 },
+ /* 1409 */ { MAD_F(0x07b68102) /* 0.482056625 */, 15 },
+ /* 1410 */ { MAD_F(0x07b85f64) /* 0.482512848 */, 15 },
+ /* 1411 */ { MAD_F(0x07ba3de4) /* 0.482969179 */, 15 },
+ /* 1412 */ { MAD_F(0x07bc1c80) /* 0.483425618 */, 15 },
+ /* 1413 */ { MAD_F(0x07bdfb39) /* 0.483882164 */, 15 },
+ /* 1414 */ { MAD_F(0x07bfda0f) /* 0.484338818 */, 15 },
+ /* 1415 */ { MAD_F(0x07c1b902) /* 0.484795580 */, 15 },
+ /* 1416 */ { MAD_F(0x07c39812) /* 0.485252449 */, 15 },
+ /* 1417 */ { MAD_F(0x07c5773f) /* 0.485709426 */, 15 },
+ /* 1418 */ { MAD_F(0x07c75689) /* 0.486166511 */, 15 },
+ /* 1419 */ { MAD_F(0x07c935ef) /* 0.486623703 */, 15 },
+ /* 1420 */ { MAD_F(0x07cb1573) /* 0.487081002 */, 15 },
+ /* 1421 */ { MAD_F(0x07ccf513) /* 0.487538409 */, 15 },
+ /* 1422 */ { MAD_F(0x07ced4d0) /* 0.487995923 */, 15 },
+ /* 1423 */ { MAD_F(0x07d0b4aa) /* 0.488453544 */, 15 },
+
+ /* 1424 */ { MAD_F(0x07d294a0) /* 0.488911273 */, 15 },
+ /* 1425 */ { MAD_F(0x07d474b3) /* 0.489369108 */, 15 },
+ /* 1426 */ { MAD_F(0x07d654e4) /* 0.489827051 */, 15 },
+ /* 1427 */ { MAD_F(0x07d83530) /* 0.490285101 */, 15 },
+ /* 1428 */ { MAD_F(0x07da159a) /* 0.490743258 */, 15 },
+ /* 1429 */ { MAD_F(0x07dbf620) /* 0.491201522 */, 15 },
+ /* 1430 */ { MAD_F(0x07ddd6c3) /* 0.491659892 */, 15 },
+ /* 1431 */ { MAD_F(0x07dfb783) /* 0.492118370 */, 15 },
+ /* 1432 */ { MAD_F(0x07e1985f) /* 0.492576954 */, 15 },
+ /* 1433 */ { MAD_F(0x07e37958) /* 0.493035645 */, 15 },
+ /* 1434 */ { MAD_F(0x07e55a6e) /* 0.493494443 */, 15 },
+ /* 1435 */ { MAD_F(0x07e73ba0) /* 0.493953348 */, 15 },
+ /* 1436 */ { MAD_F(0x07e91cef) /* 0.494412359 */, 15 },
+ /* 1437 */ { MAD_F(0x07eafe5a) /* 0.494871476 */, 15 },
+ /* 1438 */ { MAD_F(0x07ecdfe2) /* 0.495330701 */, 15 },
+ /* 1439 */ { MAD_F(0x07eec187) /* 0.495790031 */, 15 },
+
+ /* 1440 */ { MAD_F(0x07f0a348) /* 0.496249468 */, 15 },
+ /* 1441 */ { MAD_F(0x07f28526) /* 0.496709012 */, 15 },
+ /* 1442 */ { MAD_F(0x07f46720) /* 0.497168662 */, 15 },
+ /* 1443 */ { MAD_F(0x07f64937) /* 0.497628418 */, 15 },
+ /* 1444 */ { MAD_F(0x07f82b6a) /* 0.498088280 */, 15 },
+ /* 1445 */ { MAD_F(0x07fa0dba) /* 0.498548248 */, 15 },
+ /* 1446 */ { MAD_F(0x07fbf026) /* 0.499008323 */, 15 },
+ /* 1447 */ { MAD_F(0x07fdd2af) /* 0.499468503 */, 15 },
+ /* 1448 */ { MAD_F(0x07ffb554) /* 0.499928790 */, 15 },
+ /* 1449 */ { MAD_F(0x0400cc0b) /* 0.250194591 */, 16 },
+ /* 1450 */ { MAD_F(0x0401bd7a) /* 0.250424840 */, 16 },
+ /* 1451 */ { MAD_F(0x0402aef7) /* 0.250655143 */, 16 },
+ /* 1452 */ { MAD_F(0x0403a083) /* 0.250885498 */, 16 },
+ /* 1453 */ { MAD_F(0x0404921c) /* 0.251115906 */, 16 },
+ /* 1454 */ { MAD_F(0x040583c4) /* 0.251346367 */, 16 },
+ /* 1455 */ { MAD_F(0x0406757a) /* 0.251576880 */, 16 },
+
+ /* 1456 */ { MAD_F(0x0407673f) /* 0.251807447 */, 16 },
+ /* 1457 */ { MAD_F(0x04085911) /* 0.252038066 */, 16 },
+ /* 1458 */ { MAD_F(0x04094af1) /* 0.252268738 */, 16 },
+ /* 1459 */ { MAD_F(0x040a3ce0) /* 0.252499463 */, 16 },
+ /* 1460 */ { MAD_F(0x040b2edd) /* 0.252730240 */, 16 },
+ /* 1461 */ { MAD_F(0x040c20e8) /* 0.252961071 */, 16 },
+ /* 1462 */ { MAD_F(0x040d1301) /* 0.253191953 */, 16 },
+ /* 1463 */ { MAD_F(0x040e0529) /* 0.253422889 */, 16 },
+ /* 1464 */ { MAD_F(0x040ef75e) /* 0.253653877 */, 16 },
+ /* 1465 */ { MAD_F(0x040fe9a1) /* 0.253884918 */, 16 },
+ /* 1466 */ { MAD_F(0x0410dbf3) /* 0.254116011 */, 16 },
+ /* 1467 */ { MAD_F(0x0411ce53) /* 0.254347157 */, 16 },
+ /* 1468 */ { MAD_F(0x0412c0c1) /* 0.254578356 */, 16 },
+ /* 1469 */ { MAD_F(0x0413b33d) /* 0.254809606 */, 16 },
+ /* 1470 */ { MAD_F(0x0414a5c7) /* 0.255040910 */, 16 },
+ /* 1471 */ { MAD_F(0x0415985f) /* 0.255272266 */, 16 },
+
+ /* 1472 */ { MAD_F(0x04168b05) /* 0.255503674 */, 16 },
+ /* 1473 */ { MAD_F(0x04177db9) /* 0.255735135 */, 16 },
+ /* 1474 */ { MAD_F(0x0418707c) /* 0.255966648 */, 16 },
+ /* 1475 */ { MAD_F(0x0419634c) /* 0.256198213 */, 16 },
+ /* 1476 */ { MAD_F(0x041a562a) /* 0.256429831 */, 16 },
+ /* 1477 */ { MAD_F(0x041b4917) /* 0.256661501 */, 16 },
+ /* 1478 */ { MAD_F(0x041c3c11) /* 0.256893223 */, 16 },
+ /* 1479 */ { MAD_F(0x041d2f1a) /* 0.257124998 */, 16 },
+ /* 1480 */ { MAD_F(0x041e2230) /* 0.257356825 */, 16 },
+ /* 1481 */ { MAD_F(0x041f1555) /* 0.257588704 */, 16 },
+ /* 1482 */ { MAD_F(0x04200888) /* 0.257820635 */, 16 },
+ /* 1483 */ { MAD_F(0x0420fbc8) /* 0.258052619 */, 16 },
+ /* 1484 */ { MAD_F(0x0421ef17) /* 0.258284654 */, 16 },
+ /* 1485 */ { MAD_F(0x0422e273) /* 0.258516742 */, 16 },
+ /* 1486 */ { MAD_F(0x0423d5de) /* 0.258748882 */, 16 },
+ /* 1487 */ { MAD_F(0x0424c956) /* 0.258981074 */, 16 },
+
+ /* 1488 */ { MAD_F(0x0425bcdd) /* 0.259213318 */, 16 },
+ /* 1489 */ { MAD_F(0x0426b071) /* 0.259445614 */, 16 },
+ /* 1490 */ { MAD_F(0x0427a414) /* 0.259677962 */, 16 },
+ /* 1491 */ { MAD_F(0x042897c4) /* 0.259910362 */, 16 },
+ /* 1492 */ { MAD_F(0x04298b83) /* 0.260142814 */, 16 },
+ /* 1493 */ { MAD_F(0x042a7f4f) /* 0.260375318 */, 16 },
+ /* 1494 */ { MAD_F(0x042b7329) /* 0.260607874 */, 16 },
+ /* 1495 */ { MAD_F(0x042c6711) /* 0.260840481 */, 16 },
+ /* 1496 */ { MAD_F(0x042d5b07) /* 0.261073141 */, 16 },
+ /* 1497 */ { MAD_F(0x042e4f0b) /* 0.261305852 */, 16 },
+ /* 1498 */ { MAD_F(0x042f431d) /* 0.261538616 */, 16 },
+ /* 1499 */ { MAD_F(0x0430373d) /* 0.261771431 */, 16 },
+ /* 1500 */ { MAD_F(0x04312b6b) /* 0.262004297 */, 16 },
+ /* 1501 */ { MAD_F(0x04321fa6) /* 0.262237216 */, 16 },
+ /* 1502 */ { MAD_F(0x043313f0) /* 0.262470186 */, 16 },
+ /* 1503 */ { MAD_F(0x04340847) /* 0.262703208 */, 16 },
+
+ /* 1504 */ { MAD_F(0x0434fcad) /* 0.262936282 */, 16 },
+ /* 1505 */ { MAD_F(0x0435f120) /* 0.263169407 */, 16 },
+ /* 1506 */ { MAD_F(0x0436e5a1) /* 0.263402584 */, 16 },
+ /* 1507 */ { MAD_F(0x0437da2f) /* 0.263635813 */, 16 },
+ /* 1508 */ { MAD_F(0x0438cecc) /* 0.263869093 */, 16 },
+ /* 1509 */ { MAD_F(0x0439c377) /* 0.264102425 */, 16 },
+ /* 1510 */ { MAD_F(0x043ab82f) /* 0.264335808 */, 16 },
+ /* 1511 */ { MAD_F(0x043bacf5) /* 0.264569243 */, 16 },
+ /* 1512 */ { MAD_F(0x043ca1c9) /* 0.264802730 */, 16 },
+ /* 1513 */ { MAD_F(0x043d96ab) /* 0.265036267 */, 16 },
+ /* 1514 */ { MAD_F(0x043e8b9b) /* 0.265269857 */, 16 },
+ /* 1515 */ { MAD_F(0x043f8098) /* 0.265503498 */, 16 },
+ /* 1516 */ { MAD_F(0x044075a3) /* 0.265737190 */, 16 },
+ /* 1517 */ { MAD_F(0x04416abc) /* 0.265970933 */, 16 },
+ /* 1518 */ { MAD_F(0x04425fe3) /* 0.266204728 */, 16 },
+ /* 1519 */ { MAD_F(0x04435518) /* 0.266438574 */, 16 },
+
+ /* 1520 */ { MAD_F(0x04444a5a) /* 0.266672472 */, 16 },
+ /* 1521 */ { MAD_F(0x04453fab) /* 0.266906421 */, 16 },
+ /* 1522 */ { MAD_F(0x04463508) /* 0.267140421 */, 16 },
+ /* 1523 */ { MAD_F(0x04472a74) /* 0.267374472 */, 16 },
+ /* 1524 */ { MAD_F(0x04481fee) /* 0.267608575 */, 16 },
+ /* 1525 */ { MAD_F(0x04491575) /* 0.267842729 */, 16 },
+ /* 1526 */ { MAD_F(0x044a0b0a) /* 0.268076934 */, 16 },
+ /* 1527 */ { MAD_F(0x044b00ac) /* 0.268311190 */, 16 },
+ /* 1528 */ { MAD_F(0x044bf65d) /* 0.268545497 */, 16 },
+ /* 1529 */ { MAD_F(0x044cec1b) /* 0.268779856 */, 16 },
+ /* 1530 */ { MAD_F(0x044de1e7) /* 0.269014265 */, 16 },
+ /* 1531 */ { MAD_F(0x044ed7c0) /* 0.269248726 */, 16 },
+ /* 1532 */ { MAD_F(0x044fcda8) /* 0.269483238 */, 16 },
+ /* 1533 */ { MAD_F(0x0450c39c) /* 0.269717800 */, 16 },
+ /* 1534 */ { MAD_F(0x0451b99f) /* 0.269952414 */, 16 },
+ /* 1535 */ { MAD_F(0x0452afaf) /* 0.270187079 */, 16 },
+
+ /* 1536 */ { MAD_F(0x0453a5cd) /* 0.270421794 */, 16 },
+ /* 1537 */ { MAD_F(0x04549bf9) /* 0.270656561 */, 16 },
+ /* 1538 */ { MAD_F(0x04559232) /* 0.270891379 */, 16 },
+ /* 1539 */ { MAD_F(0x04568879) /* 0.271126247 */, 16 },
+ /* 1540 */ { MAD_F(0x04577ece) /* 0.271361166 */, 16 },
+ /* 1541 */ { MAD_F(0x04587530) /* 0.271596136 */, 16 },
+ /* 1542 */ { MAD_F(0x04596ba0) /* 0.271831157 */, 16 },
+ /* 1543 */ { MAD_F(0x045a621e) /* 0.272066229 */, 16 },
+ /* 1544 */ { MAD_F(0x045b58a9) /* 0.272301352 */, 16 },
+ /* 1545 */ { MAD_F(0x045c4f42) /* 0.272536525 */, 16 },
+ /* 1546 */ { MAD_F(0x045d45e9) /* 0.272771749 */, 16 },
+ /* 1547 */ { MAD_F(0x045e3c9d) /* 0.273007024 */, 16 },
+ /* 1548 */ { MAD_F(0x045f335e) /* 0.273242350 */, 16 },
+ /* 1549 */ { MAD_F(0x04602a2e) /* 0.273477726 */, 16 },
+ /* 1550 */ { MAD_F(0x0461210b) /* 0.273713153 */, 16 },
+ /* 1551 */ { MAD_F(0x046217f5) /* 0.273948630 */, 16 },
+
+ /* 1552 */ { MAD_F(0x04630eed) /* 0.274184158 */, 16 },
+ /* 1553 */ { MAD_F(0x046405f3) /* 0.274419737 */, 16 },
+ /* 1554 */ { MAD_F(0x0464fd06) /* 0.274655366 */, 16 },
+ /* 1555 */ { MAD_F(0x0465f427) /* 0.274891046 */, 16 },
+ /* 1556 */ { MAD_F(0x0466eb55) /* 0.275126776 */, 16 },
+ /* 1557 */ { MAD_F(0x0467e291) /* 0.275362557 */, 16 },
+ /* 1558 */ { MAD_F(0x0468d9db) /* 0.275598389 */, 16 },
+ /* 1559 */ { MAD_F(0x0469d132) /* 0.275834270 */, 16 },
+ /* 1560 */ { MAD_F(0x046ac896) /* 0.276070203 */, 16 },
+ /* 1561 */ { MAD_F(0x046bc009) /* 0.276306185 */, 16 },
+ /* 1562 */ { MAD_F(0x046cb788) /* 0.276542218 */, 16 },
+ /* 1563 */ { MAD_F(0x046daf15) /* 0.276778302 */, 16 },
+ /* 1564 */ { MAD_F(0x046ea6b0) /* 0.277014435 */, 16 },
+ /* 1565 */ { MAD_F(0x046f9e58) /* 0.277250619 */, 16 },
+ /* 1566 */ { MAD_F(0x0470960e) /* 0.277486854 */, 16 },
+ /* 1567 */ { MAD_F(0x04718dd1) /* 0.277723139 */, 16 },
+
+ /* 1568 */ { MAD_F(0x047285a2) /* 0.277959474 */, 16 },
+ /* 1569 */ { MAD_F(0x04737d80) /* 0.278195859 */, 16 },
+ /* 1570 */ { MAD_F(0x0474756c) /* 0.278432294 */, 16 },
+ /* 1571 */ { MAD_F(0x04756d65) /* 0.278668780 */, 16 },
+ /* 1572 */ { MAD_F(0x0476656b) /* 0.278905316 */, 16 },
+ /* 1573 */ { MAD_F(0x04775d7f) /* 0.279141902 */, 16 },
+ /* 1574 */ { MAD_F(0x047855a1) /* 0.279378538 */, 16 },
+ /* 1575 */ { MAD_F(0x04794dd0) /* 0.279615224 */, 16 },
+ /* 1576 */ { MAD_F(0x047a460c) /* 0.279851960 */, 16 },
+ /* 1577 */ { MAD_F(0x047b3e56) /* 0.280088747 */, 16 },
+ /* 1578 */ { MAD_F(0x047c36ae) /* 0.280325583 */, 16 },
+ /* 1579 */ { MAD_F(0x047d2f12) /* 0.280562470 */, 16 },
+ /* 1580 */ { MAD_F(0x047e2784) /* 0.280799406 */, 16 },
+ /* 1581 */ { MAD_F(0x047f2004) /* 0.281036393 */, 16 },
+ /* 1582 */ { MAD_F(0x04801891) /* 0.281273429 */, 16 },
+ /* 1583 */ { MAD_F(0x0481112b) /* 0.281510516 */, 16 },
+
+ /* 1584 */ { MAD_F(0x048209d3) /* 0.281747652 */, 16 },
+ /* 1585 */ { MAD_F(0x04830288) /* 0.281984838 */, 16 },
+ /* 1586 */ { MAD_F(0x0483fb4b) /* 0.282222075 */, 16 },
+ /* 1587 */ { MAD_F(0x0484f41b) /* 0.282459361 */, 16 },
+ /* 1588 */ { MAD_F(0x0485ecf8) /* 0.282696697 */, 16 },
+ /* 1589 */ { MAD_F(0x0486e5e3) /* 0.282934082 */, 16 },
+ /* 1590 */ { MAD_F(0x0487dedb) /* 0.283171518 */, 16 },
+ /* 1591 */ { MAD_F(0x0488d7e1) /* 0.283409003 */, 16 },
+ /* 1592 */ { MAD_F(0x0489d0f4) /* 0.283646538 */, 16 },
+ /* 1593 */ { MAD_F(0x048aca14) /* 0.283884123 */, 16 },
+ /* 1594 */ { MAD_F(0x048bc341) /* 0.284121757 */, 16 },
+ /* 1595 */ { MAD_F(0x048cbc7c) /* 0.284359441 */, 16 },
+ /* 1596 */ { MAD_F(0x048db5c4) /* 0.284597175 */, 16 },
+ /* 1597 */ { MAD_F(0x048eaf1a) /* 0.284834959 */, 16 },
+ /* 1598 */ { MAD_F(0x048fa87d) /* 0.285072792 */, 16 },
+ /* 1599 */ { MAD_F(0x0490a1ed) /* 0.285310675 */, 16 },
+
+ /* 1600 */ { MAD_F(0x04919b6a) /* 0.285548607 */, 16 },
+ /* 1601 */ { MAD_F(0x049294f5) /* 0.285786589 */, 16 },
+ /* 1602 */ { MAD_F(0x04938e8d) /* 0.286024621 */, 16 },
+ /* 1603 */ { MAD_F(0x04948833) /* 0.286262702 */, 16 },
+ /* 1604 */ { MAD_F(0x049581e5) /* 0.286500832 */, 16 },
+ /* 1605 */ { MAD_F(0x04967ba5) /* 0.286739012 */, 16 },
+ /* 1606 */ { MAD_F(0x04977573) /* 0.286977242 */, 16 },
+ /* 1607 */ { MAD_F(0x04986f4d) /* 0.287215521 */, 16 },
+ /* 1608 */ { MAD_F(0x04996935) /* 0.287453849 */, 16 },
+ /* 1609 */ { MAD_F(0x049a632a) /* 0.287692227 */, 16 },
+ /* 1610 */ { MAD_F(0x049b5d2c) /* 0.287930654 */, 16 },
+ /* 1611 */ { MAD_F(0x049c573c) /* 0.288169131 */, 16 },
+ /* 1612 */ { MAD_F(0x049d5159) /* 0.288407657 */, 16 },
+ /* 1613 */ { MAD_F(0x049e4b83) /* 0.288646232 */, 16 },
+ /* 1614 */ { MAD_F(0x049f45ba) /* 0.288884857 */, 16 },
+ /* 1615 */ { MAD_F(0x04a03ffe) /* 0.289123530 */, 16 },
+
+ /* 1616 */ { MAD_F(0x04a13a50) /* 0.289362253 */, 16 },
+ /* 1617 */ { MAD_F(0x04a234af) /* 0.289601026 */, 16 },
+ /* 1618 */ { MAD_F(0x04a32f1b) /* 0.289839847 */, 16 },
+ /* 1619 */ { MAD_F(0x04a42995) /* 0.290078718 */, 16 },
+ /* 1620 */ { MAD_F(0x04a5241b) /* 0.290317638 */, 16 },
+ /* 1621 */ { MAD_F(0x04a61eaf) /* 0.290556607 */, 16 },
+ /* 1622 */ { MAD_F(0x04a71950) /* 0.290795626 */, 16 },
+ /* 1623 */ { MAD_F(0x04a813fe) /* 0.291034693 */, 16 },
+ /* 1624 */ { MAD_F(0x04a90eba) /* 0.291273810 */, 16 },
+ /* 1625 */ { MAD_F(0x04aa0982) /* 0.291512975 */, 16 },
+ /* 1626 */ { MAD_F(0x04ab0458) /* 0.291752190 */, 16 },
+ /* 1627 */ { MAD_F(0x04abff3b) /* 0.291991453 */, 16 },
+ /* 1628 */ { MAD_F(0x04acfa2b) /* 0.292230766 */, 16 },
+ /* 1629 */ { MAD_F(0x04adf528) /* 0.292470128 */, 16 },
+ /* 1630 */ { MAD_F(0x04aef032) /* 0.292709539 */, 16 },
+ /* 1631 */ { MAD_F(0x04afeb4a) /* 0.292948998 */, 16 },
+
+ /* 1632 */ { MAD_F(0x04b0e66e) /* 0.293188507 */, 16 },
+ /* 1633 */ { MAD_F(0x04b1e1a0) /* 0.293428065 */, 16 },
+ /* 1634 */ { MAD_F(0x04b2dcdf) /* 0.293667671 */, 16 },
+ /* 1635 */ { MAD_F(0x04b3d82b) /* 0.293907326 */, 16 },
+ /* 1636 */ { MAD_F(0x04b4d384) /* 0.294147031 */, 16 },
+ /* 1637 */ { MAD_F(0x04b5ceea) /* 0.294386784 */, 16 },
+ /* 1638 */ { MAD_F(0x04b6ca5e) /* 0.294626585 */, 16 },
+ /* 1639 */ { MAD_F(0x04b7c5de) /* 0.294866436 */, 16 },
+ /* 1640 */ { MAD_F(0x04b8c16c) /* 0.295106336 */, 16 },
+ /* 1641 */ { MAD_F(0x04b9bd06) /* 0.295346284 */, 16 },
+ /* 1642 */ { MAD_F(0x04bab8ae) /* 0.295586281 */, 16 },
+ /* 1643 */ { MAD_F(0x04bbb463) /* 0.295826327 */, 16 },
+ /* 1644 */ { MAD_F(0x04bcb024) /* 0.296066421 */, 16 },
+ /* 1645 */ { MAD_F(0x04bdabf3) /* 0.296306564 */, 16 },
+ /* 1646 */ { MAD_F(0x04bea7cf) /* 0.296546756 */, 16 },
+ /* 1647 */ { MAD_F(0x04bfa3b8) /* 0.296786996 */, 16 },
+
+ /* 1648 */ { MAD_F(0x04c09faf) /* 0.297027285 */, 16 },
+ /* 1649 */ { MAD_F(0x04c19bb2) /* 0.297267623 */, 16 },
+ /* 1650 */ { MAD_F(0x04c297c2) /* 0.297508009 */, 16 },
+ /* 1651 */ { MAD_F(0x04c393df) /* 0.297748444 */, 16 },
+ /* 1652 */ { MAD_F(0x04c49009) /* 0.297988927 */, 16 },
+ /* 1653 */ { MAD_F(0x04c58c41) /* 0.298229459 */, 16 },
+ /* 1654 */ { MAD_F(0x04c68885) /* 0.298470039 */, 16 },
+ /* 1655 */ { MAD_F(0x04c784d6) /* 0.298710668 */, 16 },
+ /* 1656 */ { MAD_F(0x04c88135) /* 0.298951346 */, 16 },
+ /* 1657 */ { MAD_F(0x04c97da0) /* 0.299192071 */, 16 },
+ /* 1658 */ { MAD_F(0x04ca7a18) /* 0.299432846 */, 16 },
+ /* 1659 */ { MAD_F(0x04cb769e) /* 0.299673668 */, 16 },
+ /* 1660 */ { MAD_F(0x04cc7330) /* 0.299914539 */, 16 },
+ /* 1661 */ { MAD_F(0x04cd6fcf) /* 0.300155459 */, 16 },
+ /* 1662 */ { MAD_F(0x04ce6c7b) /* 0.300396426 */, 16 },
+ /* 1663 */ { MAD_F(0x04cf6935) /* 0.300637443 */, 16 },
+
+ /* 1664 */ { MAD_F(0x04d065fb) /* 0.300878507 */, 16 },
+ /* 1665 */ { MAD_F(0x04d162ce) /* 0.301119620 */, 16 },
+ /* 1666 */ { MAD_F(0x04d25fae) /* 0.301360781 */, 16 },
+ /* 1667 */ { MAD_F(0x04d35c9b) /* 0.301601990 */, 16 },
+ /* 1668 */ { MAD_F(0x04d45995) /* 0.301843247 */, 16 },
+ /* 1669 */ { MAD_F(0x04d5569c) /* 0.302084553 */, 16 },
+ /* 1670 */ { MAD_F(0x04d653b0) /* 0.302325907 */, 16 },
+ /* 1671 */ { MAD_F(0x04d750d1) /* 0.302567309 */, 16 },
+ /* 1672 */ { MAD_F(0x04d84dff) /* 0.302808759 */, 16 },
+ /* 1673 */ { MAD_F(0x04d94b3a) /* 0.303050257 */, 16 },
+ /* 1674 */ { MAD_F(0x04da4881) /* 0.303291804 */, 16 },
+ /* 1675 */ { MAD_F(0x04db45d6) /* 0.303533399 */, 16 },
+ /* 1676 */ { MAD_F(0x04dc4337) /* 0.303775041 */, 16 },
+ /* 1677 */ { MAD_F(0x04dd40a6) /* 0.304016732 */, 16 },
+ /* 1678 */ { MAD_F(0x04de3e21) /* 0.304258471 */, 16 },
+ /* 1679 */ { MAD_F(0x04df3ba9) /* 0.304500257 */, 16 },
+
+ /* 1680 */ { MAD_F(0x04e0393e) /* 0.304742092 */, 16 },
+ /* 1681 */ { MAD_F(0x04e136e0) /* 0.304983975 */, 16 },
+ /* 1682 */ { MAD_F(0x04e2348f) /* 0.305225906 */, 16 },
+ /* 1683 */ { MAD_F(0x04e3324b) /* 0.305467885 */, 16 },
+ /* 1684 */ { MAD_F(0x04e43013) /* 0.305709911 */, 16 },
+ /* 1685 */ { MAD_F(0x04e52de9) /* 0.305951986 */, 16 },
+ /* 1686 */ { MAD_F(0x04e62bcb) /* 0.306194108 */, 16 },
+ /* 1687 */ { MAD_F(0x04e729ba) /* 0.306436279 */, 16 },
+ /* 1688 */ { MAD_F(0x04e827b6) /* 0.306678497 */, 16 },
+ /* 1689 */ { MAD_F(0x04e925bf) /* 0.306920763 */, 16 },
+ /* 1690 */ { MAD_F(0x04ea23d4) /* 0.307163077 */, 16 },
+ /* 1691 */ { MAD_F(0x04eb21f7) /* 0.307405438 */, 16 },
+ /* 1692 */ { MAD_F(0x04ec2026) /* 0.307647848 */, 16 },
+ /* 1693 */ { MAD_F(0x04ed1e62) /* 0.307890305 */, 16 },
+ /* 1694 */ { MAD_F(0x04ee1cab) /* 0.308132810 */, 16 },
+ /* 1695 */ { MAD_F(0x04ef1b01) /* 0.308375362 */, 16 },
+
+ /* 1696 */ { MAD_F(0x04f01963) /* 0.308617963 */, 16 },
+ /* 1697 */ { MAD_F(0x04f117d3) /* 0.308860611 */, 16 },
+ /* 1698 */ { MAD_F(0x04f2164f) /* 0.309103306 */, 16 },
+ /* 1699 */ { MAD_F(0x04f314d8) /* 0.309346050 */, 16 },
+ /* 1700 */ { MAD_F(0x04f4136d) /* 0.309588841 */, 16 },
+ /* 1701 */ { MAD_F(0x04f51210) /* 0.309831679 */, 16 },
+ /* 1702 */ { MAD_F(0x04f610bf) /* 0.310074565 */, 16 },
+ /* 1703 */ { MAD_F(0x04f70f7b) /* 0.310317499 */, 16 },
+ /* 1704 */ { MAD_F(0x04f80e44) /* 0.310560480 */, 16 },
+ /* 1705 */ { MAD_F(0x04f90d19) /* 0.310803509 */, 16 },
+ /* 1706 */ { MAD_F(0x04fa0bfc) /* 0.311046586 */, 16 },
+ /* 1707 */ { MAD_F(0x04fb0aeb) /* 0.311289710 */, 16 },
+ /* 1708 */ { MAD_F(0x04fc09e7) /* 0.311532881 */, 16 },
+ /* 1709 */ { MAD_F(0x04fd08ef) /* 0.311776100 */, 16 },
+ /* 1710 */ { MAD_F(0x04fe0805) /* 0.312019366 */, 16 },
+ /* 1711 */ { MAD_F(0x04ff0727) /* 0.312262680 */, 16 },
+
+ /* 1712 */ { MAD_F(0x05000655) /* 0.312506041 */, 16 },
+ /* 1713 */ { MAD_F(0x05010591) /* 0.312749449 */, 16 },
+ /* 1714 */ { MAD_F(0x050204d9) /* 0.312992905 */, 16 },
+ /* 1715 */ { MAD_F(0x0503042e) /* 0.313236408 */, 16 },
+ /* 1716 */ { MAD_F(0x0504038f) /* 0.313479959 */, 16 },
+ /* 1717 */ { MAD_F(0x050502fe) /* 0.313723556 */, 16 },
+ /* 1718 */ { MAD_F(0x05060279) /* 0.313967202 */, 16 },
+ /* 1719 */ { MAD_F(0x05070200) /* 0.314210894 */, 16 },
+ /* 1720 */ { MAD_F(0x05080195) /* 0.314454634 */, 16 },
+ /* 1721 */ { MAD_F(0x05090136) /* 0.314698420 */, 16 },
+ /* 1722 */ { MAD_F(0x050a00e3) /* 0.314942255 */, 16 },
+ /* 1723 */ { MAD_F(0x050b009e) /* 0.315186136 */, 16 },
+ /* 1724 */ { MAD_F(0x050c0065) /* 0.315430064 */, 16 },
+ /* 1725 */ { MAD_F(0x050d0039) /* 0.315674040 */, 16 },
+ /* 1726 */ { MAD_F(0x050e0019) /* 0.315918063 */, 16 },
+ /* 1727 */ { MAD_F(0x050f0006) /* 0.316162133 */, 16 },
+
+ /* 1728 */ { MAD_F(0x05100000) /* 0.316406250 */, 16 },
+ /* 1729 */ { MAD_F(0x05110006) /* 0.316650414 */, 16 },
+ /* 1730 */ { MAD_F(0x05120019) /* 0.316894625 */, 16 },
+ /* 1731 */ { MAD_F(0x05130039) /* 0.317138884 */, 16 },
+ /* 1732 */ { MAD_F(0x05140065) /* 0.317383189 */, 16 },
+ /* 1733 */ { MAD_F(0x0515009e) /* 0.317627541 */, 16 },
+ /* 1734 */ { MAD_F(0x051600e3) /* 0.317871941 */, 16 },
+ /* 1735 */ { MAD_F(0x05170135) /* 0.318116387 */, 16 },
+ /* 1736 */ { MAD_F(0x05180194) /* 0.318360880 */, 16 },
+ /* 1737 */ { MAD_F(0x051901ff) /* 0.318605421 */, 16 },
+ /* 1738 */ { MAD_F(0x051a0277) /* 0.318850008 */, 16 },
+ /* 1739 */ { MAD_F(0x051b02fc) /* 0.319094642 */, 16 },
+ /* 1740 */ { MAD_F(0x051c038d) /* 0.319339323 */, 16 },
+ /* 1741 */ { MAD_F(0x051d042a) /* 0.319584051 */, 16 },
+ /* 1742 */ { MAD_F(0x051e04d4) /* 0.319828826 */, 16 },
+ /* 1743 */ { MAD_F(0x051f058b) /* 0.320073647 */, 16 },
+
+ /* 1744 */ { MAD_F(0x0520064f) /* 0.320318516 */, 16 },
+ /* 1745 */ { MAD_F(0x0521071f) /* 0.320563431 */, 16 },
+ /* 1746 */ { MAD_F(0x052207fb) /* 0.320808393 */, 16 },
+ /* 1747 */ { MAD_F(0x052308e4) /* 0.321053402 */, 16 },
+ /* 1748 */ { MAD_F(0x052409da) /* 0.321298457 */, 16 },
+ /* 1749 */ { MAD_F(0x05250adc) /* 0.321543560 */, 16 },
+ /* 1750 */ { MAD_F(0x05260bea) /* 0.321788709 */, 16 },
+ /* 1751 */ { MAD_F(0x05270d06) /* 0.322033904 */, 16 },
+ /* 1752 */ { MAD_F(0x05280e2d) /* 0.322279147 */, 16 },
+ /* 1753 */ { MAD_F(0x05290f62) /* 0.322524436 */, 16 },
+ /* 1754 */ { MAD_F(0x052a10a3) /* 0.322769771 */, 16 },
+ /* 1755 */ { MAD_F(0x052b11f0) /* 0.323015154 */, 16 },
+ /* 1756 */ { MAD_F(0x052c134a) /* 0.323260583 */, 16 },
+ /* 1757 */ { MAD_F(0x052d14b0) /* 0.323506058 */, 16 },
+ /* 1758 */ { MAD_F(0x052e1623) /* 0.323751580 */, 16 },
+ /* 1759 */ { MAD_F(0x052f17a2) /* 0.323997149 */, 16 },
+
+ /* 1760 */ { MAD_F(0x0530192e) /* 0.324242764 */, 16 },
+ /* 1761 */ { MAD_F(0x05311ac6) /* 0.324488426 */, 16 },
+ /* 1762 */ { MAD_F(0x05321c6b) /* 0.324734134 */, 16 },
+ /* 1763 */ { MAD_F(0x05331e1c) /* 0.324979889 */, 16 },
+ /* 1764 */ { MAD_F(0x05341fda) /* 0.325225690 */, 16 },
+ /* 1765 */ { MAD_F(0x053521a4) /* 0.325471538 */, 16 },
+ /* 1766 */ { MAD_F(0x0536237b) /* 0.325717432 */, 16 },
+ /* 1767 */ { MAD_F(0x0537255e) /* 0.325963372 */, 16 },
+ /* 1768 */ { MAD_F(0x0538274e) /* 0.326209359 */, 16 },
+ /* 1769 */ { MAD_F(0x0539294a) /* 0.326455392 */, 16 },
+ /* 1770 */ { MAD_F(0x053a2b52) /* 0.326701472 */, 16 },
+ /* 1771 */ { MAD_F(0x053b2d67) /* 0.326947598 */, 16 },
+ /* 1772 */ { MAD_F(0x053c2f89) /* 0.327193770 */, 16 },
+ /* 1773 */ { MAD_F(0x053d31b6) /* 0.327439989 */, 16 },
+ /* 1774 */ { MAD_F(0x053e33f1) /* 0.327686254 */, 16 },
+ /* 1775 */ { MAD_F(0x053f3637) /* 0.327932565 */, 16 },
+
+ /* 1776 */ { MAD_F(0x0540388a) /* 0.328178922 */, 16 },
+ /* 1777 */ { MAD_F(0x05413aea) /* 0.328425326 */, 16 },
+ /* 1778 */ { MAD_F(0x05423d56) /* 0.328671776 */, 16 },
+ /* 1779 */ { MAD_F(0x05433fce) /* 0.328918272 */, 16 },
+ /* 1780 */ { MAD_F(0x05444253) /* 0.329164814 */, 16 },
+ /* 1781 */ { MAD_F(0x054544e4) /* 0.329411403 */, 16 },
+ /* 1782 */ { MAD_F(0x05464781) /* 0.329658038 */, 16 },
+ /* 1783 */ { MAD_F(0x05474a2b) /* 0.329904718 */, 16 },
+ /* 1784 */ { MAD_F(0x05484ce2) /* 0.330151445 */, 16 },
+ /* 1785 */ { MAD_F(0x05494fa4) /* 0.330398218 */, 16 },
+ /* 1786 */ { MAD_F(0x054a5273) /* 0.330645037 */, 16 },
+ /* 1787 */ { MAD_F(0x054b554e) /* 0.330891903 */, 16 },
+ /* 1788 */ { MAD_F(0x054c5836) /* 0.331138814 */, 16 },
+ /* 1789 */ { MAD_F(0x054d5b2a) /* 0.331385771 */, 16 },
+ /* 1790 */ { MAD_F(0x054e5e2b) /* 0.331632774 */, 16 },
+ /* 1791 */ { MAD_F(0x054f6138) /* 0.331879824 */, 16 },
+
+ /* 1792 */ { MAD_F(0x05506451) /* 0.332126919 */, 16 },
+ /* 1793 */ { MAD_F(0x05516776) /* 0.332374060 */, 16 },
+ /* 1794 */ { MAD_F(0x05526aa8) /* 0.332621247 */, 16 },
+ /* 1795 */ { MAD_F(0x05536de6) /* 0.332868480 */, 16 },
+ /* 1796 */ { MAD_F(0x05547131) /* 0.333115759 */, 16 },
+ /* 1797 */ { MAD_F(0x05557487) /* 0.333363084 */, 16 },
+ /* 1798 */ { MAD_F(0x055677ea) /* 0.333610455 */, 16 },
+ /* 1799 */ { MAD_F(0x05577b5a) /* 0.333857872 */, 16 },
+ /* 1800 */ { MAD_F(0x05587ed5) /* 0.334105334 */, 16 },
+ /* 1801 */ { MAD_F(0x0559825e) /* 0.334352843 */, 16 },
+ /* 1802 */ { MAD_F(0x055a85f2) /* 0.334600397 */, 16 },
+ /* 1803 */ { MAD_F(0x055b8992) /* 0.334847997 */, 16 },
+ /* 1804 */ { MAD_F(0x055c8d3f) /* 0.335095642 */, 16 },
+ /* 1805 */ { MAD_F(0x055d90f9) /* 0.335343334 */, 16 },
+ /* 1806 */ { MAD_F(0x055e94be) /* 0.335591071 */, 16 },
+ /* 1807 */ { MAD_F(0x055f9890) /* 0.335838854 */, 16 },
+
+ /* 1808 */ { MAD_F(0x05609c6e) /* 0.336086683 */, 16 },
+ /* 1809 */ { MAD_F(0x0561a058) /* 0.336334557 */, 16 },
+ /* 1810 */ { MAD_F(0x0562a44f) /* 0.336582477 */, 16 },
+ /* 1811 */ { MAD_F(0x0563a851) /* 0.336830443 */, 16 },
+ /* 1812 */ { MAD_F(0x0564ac60) /* 0.337078454 */, 16 },
+ /* 1813 */ { MAD_F(0x0565b07c) /* 0.337326511 */, 16 },
+ /* 1814 */ { MAD_F(0x0566b4a3) /* 0.337574614 */, 16 },
+ /* 1815 */ { MAD_F(0x0567b8d7) /* 0.337822762 */, 16 },
+ /* 1816 */ { MAD_F(0x0568bd17) /* 0.338070956 */, 16 },
+ /* 1817 */ { MAD_F(0x0569c163) /* 0.338319195 */, 16 },
+ /* 1818 */ { MAD_F(0x056ac5bc) /* 0.338567480 */, 16 },
+ /* 1819 */ { MAD_F(0x056bca20) /* 0.338815811 */, 16 },
+ /* 1820 */ { MAD_F(0x056cce91) /* 0.339064186 */, 16 },
+ /* 1821 */ { MAD_F(0x056dd30e) /* 0.339312608 */, 16 },
+ /* 1822 */ { MAD_F(0x056ed798) /* 0.339561075 */, 16 },
+ /* 1823 */ { MAD_F(0x056fdc2d) /* 0.339809587 */, 16 },
+
+ /* 1824 */ { MAD_F(0x0570e0cf) /* 0.340058145 */, 16 },
+ /* 1825 */ { MAD_F(0x0571e57d) /* 0.340306748 */, 16 },
+ /* 1826 */ { MAD_F(0x0572ea37) /* 0.340555397 */, 16 },
+ /* 1827 */ { MAD_F(0x0573eefd) /* 0.340804091 */, 16 },
+ /* 1828 */ { MAD_F(0x0574f3d0) /* 0.341052830 */, 16 },
+ /* 1829 */ { MAD_F(0x0575f8ae) /* 0.341301615 */, 16 },
+ /* 1830 */ { MAD_F(0x0576fd99) /* 0.341550445 */, 16 },
+ /* 1831 */ { MAD_F(0x05780290) /* 0.341799321 */, 16 },
+ /* 1832 */ { MAD_F(0x05790793) /* 0.342048241 */, 16 },
+ /* 1833 */ { MAD_F(0x057a0ca3) /* 0.342297207 */, 16 },
+ /* 1834 */ { MAD_F(0x057b11be) /* 0.342546219 */, 16 },
+ /* 1835 */ { MAD_F(0x057c16e6) /* 0.342795275 */, 16 },
+ /* 1836 */ { MAD_F(0x057d1c1a) /* 0.343044377 */, 16 },
+ /* 1837 */ { MAD_F(0x057e2159) /* 0.343293524 */, 16 },
+ /* 1838 */ { MAD_F(0x057f26a6) /* 0.343542717 */, 16 },
+ /* 1839 */ { MAD_F(0x05802bfe) /* 0.343791954 */, 16 },
+
+ /* 1840 */ { MAD_F(0x05813162) /* 0.344041237 */, 16 },
+ /* 1841 */ { MAD_F(0x058236d2) /* 0.344290564 */, 16 },
+ /* 1842 */ { MAD_F(0x05833c4f) /* 0.344539937 */, 16 },
+ /* 1843 */ { MAD_F(0x058441d8) /* 0.344789356 */, 16 },
+ /* 1844 */ { MAD_F(0x0585476c) /* 0.345038819 */, 16 },
+ /* 1845 */ { MAD_F(0x05864d0d) /* 0.345288327 */, 16 },
+ /* 1846 */ { MAD_F(0x058752ba) /* 0.345537880 */, 16 },
+ /* 1847 */ { MAD_F(0x05885873) /* 0.345787479 */, 16 },
+ /* 1848 */ { MAD_F(0x05895e39) /* 0.346037122 */, 16 },
+ /* 1849 */ { MAD_F(0x058a640a) /* 0.346286811 */, 16 },
+ /* 1850 */ { MAD_F(0x058b69e7) /* 0.346536545 */, 16 },
+ /* 1851 */ { MAD_F(0x058c6fd1) /* 0.346786323 */, 16 },
+ /* 1852 */ { MAD_F(0x058d75c6) /* 0.347036147 */, 16 },
+ /* 1853 */ { MAD_F(0x058e7bc8) /* 0.347286015 */, 16 },
+ /* 1854 */ { MAD_F(0x058f81d5) /* 0.347535929 */, 16 },
+ /* 1855 */ { MAD_F(0x059087ef) /* 0.347785887 */, 16 },
+
+ /* 1856 */ { MAD_F(0x05918e15) /* 0.348035890 */, 16 },
+ /* 1857 */ { MAD_F(0x05929447) /* 0.348285939 */, 16 },
+ /* 1858 */ { MAD_F(0x05939a84) /* 0.348536032 */, 16 },
+ /* 1859 */ { MAD_F(0x0594a0ce) /* 0.348786170 */, 16 },
+ /* 1860 */ { MAD_F(0x0595a724) /* 0.349036353 */, 16 },
+ /* 1861 */ { MAD_F(0x0596ad86) /* 0.349286580 */, 16 },
+ /* 1862 */ { MAD_F(0x0597b3f4) /* 0.349536853 */, 16 },
+ /* 1863 */ { MAD_F(0x0598ba6e) /* 0.349787170 */, 16 },
+ /* 1864 */ { MAD_F(0x0599c0f4) /* 0.350037532 */, 16 },
+ /* 1865 */ { MAD_F(0x059ac786) /* 0.350287939 */, 16 },
+ /* 1866 */ { MAD_F(0x059bce25) /* 0.350538391 */, 16 },
+ /* 1867 */ { MAD_F(0x059cd4cf) /* 0.350788887 */, 16 },
+ /* 1868 */ { MAD_F(0x059ddb85) /* 0.351039428 */, 16 },
+ /* 1869 */ { MAD_F(0x059ee247) /* 0.351290014 */, 16 },
+ /* 1870 */ { MAD_F(0x059fe915) /* 0.351540645 */, 16 },
+ /* 1871 */ { MAD_F(0x05a0efef) /* 0.351791320 */, 16 },
+
+ /* 1872 */ { MAD_F(0x05a1f6d5) /* 0.352042040 */, 16 },
+ /* 1873 */ { MAD_F(0x05a2fdc7) /* 0.352292804 */, 16 },
+ /* 1874 */ { MAD_F(0x05a404c5) /* 0.352543613 */, 16 },
+ /* 1875 */ { MAD_F(0x05a50bcf) /* 0.352794467 */, 16 },
+ /* 1876 */ { MAD_F(0x05a612e5) /* 0.353045365 */, 16 },
+ /* 1877 */ { MAD_F(0x05a71a07) /* 0.353296308 */, 16 },
+ /* 1878 */ { MAD_F(0x05a82135) /* 0.353547296 */, 16 },
+ /* 1879 */ { MAD_F(0x05a9286f) /* 0.353798328 */, 16 },
+ /* 1880 */ { MAD_F(0x05aa2fb5) /* 0.354049405 */, 16 },
+ /* 1881 */ { MAD_F(0x05ab3707) /* 0.354300526 */, 16 },
+ /* 1882 */ { MAD_F(0x05ac3e65) /* 0.354551691 */, 16 },
+ /* 1883 */ { MAD_F(0x05ad45ce) /* 0.354802901 */, 16 },
+ /* 1884 */ { MAD_F(0x05ae4d44) /* 0.355054156 */, 16 },
+ /* 1885 */ { MAD_F(0x05af54c6) /* 0.355305455 */, 16 },
+ /* 1886 */ { MAD_F(0x05b05c53) /* 0.355556799 */, 16 },
+ /* 1887 */ { MAD_F(0x05b163ed) /* 0.355808187 */, 16 },
+
+ /* 1888 */ { MAD_F(0x05b26b92) /* 0.356059619 */, 16 },
+ /* 1889 */ { MAD_F(0x05b37343) /* 0.356311096 */, 16 },
+ /* 1890 */ { MAD_F(0x05b47b00) /* 0.356562617 */, 16 },
+ /* 1891 */ { MAD_F(0x05b582c9) /* 0.356814182 */, 16 },
+ /* 1892 */ { MAD_F(0x05b68a9e) /* 0.357065792 */, 16 },
+ /* 1893 */ { MAD_F(0x05b7927f) /* 0.357317446 */, 16 },
+ /* 1894 */ { MAD_F(0x05b89a6c) /* 0.357569145 */, 16 },
+ /* 1895 */ { MAD_F(0x05b9a265) /* 0.357820887 */, 16 },
+ /* 1896 */ { MAD_F(0x05baaa69) /* 0.358072674 */, 16 },
+ /* 1897 */ { MAD_F(0x05bbb27a) /* 0.358324506 */, 16 },
+ /* 1898 */ { MAD_F(0x05bcba96) /* 0.358576381 */, 16 },
+ /* 1899 */ { MAD_F(0x05bdc2be) /* 0.358828301 */, 16 },
+ /* 1900 */ { MAD_F(0x05becaf2) /* 0.359080265 */, 16 },
+ /* 1901 */ { MAD_F(0x05bfd332) /* 0.359332273 */, 16 },
+ /* 1902 */ { MAD_F(0x05c0db7e) /* 0.359584326 */, 16 },
+ /* 1903 */ { MAD_F(0x05c1e3d6) /* 0.359836423 */, 16 },
+
+ /* 1904 */ { MAD_F(0x05c2ec39) /* 0.360088563 */, 16 },
+ /* 1905 */ { MAD_F(0x05c3f4a9) /* 0.360340748 */, 16 },
+ /* 1906 */ { MAD_F(0x05c4fd24) /* 0.360592977 */, 16 },
+ /* 1907 */ { MAD_F(0x05c605ab) /* 0.360845251 */, 16 },
+ /* 1908 */ { MAD_F(0x05c70e3e) /* 0.361097568 */, 16 },
+ /* 1909 */ { MAD_F(0x05c816dd) /* 0.361349929 */, 16 },
+ /* 1910 */ { MAD_F(0x05c91f87) /* 0.361602335 */, 16 },
+ /* 1911 */ { MAD_F(0x05ca283e) /* 0.361854784 */, 16 },
+ /* 1912 */ { MAD_F(0x05cb3100) /* 0.362107278 */, 16 },
+ /* 1913 */ { MAD_F(0x05cc39ce) /* 0.362359815 */, 16 },
+ /* 1914 */ { MAD_F(0x05cd42a8) /* 0.362612397 */, 16 },
+ /* 1915 */ { MAD_F(0x05ce4b8d) /* 0.362865022 */, 16 },
+ /* 1916 */ { MAD_F(0x05cf547f) /* 0.363117692 */, 16 },
+ /* 1917 */ { MAD_F(0x05d05d7c) /* 0.363370405 */, 16 },
+ /* 1918 */ { MAD_F(0x05d16685) /* 0.363623163 */, 16 },
+ /* 1919 */ { MAD_F(0x05d26f9a) /* 0.363875964 */, 16 },
+
+ /* 1920 */ { MAD_F(0x05d378bb) /* 0.364128809 */, 16 },
+ /* 1921 */ { MAD_F(0x05d481e7) /* 0.364381698 */, 16 },
+ /* 1922 */ { MAD_F(0x05d58b1f) /* 0.364634632 */, 16 },
+ /* 1923 */ { MAD_F(0x05d69463) /* 0.364887608 */, 16 },
+ /* 1924 */ { MAD_F(0x05d79db3) /* 0.365140629 */, 16 },
+ /* 1925 */ { MAD_F(0x05d8a70f) /* 0.365393694 */, 16 },
+ /* 1926 */ { MAD_F(0x05d9b076) /* 0.365646802 */, 16 },
+ /* 1927 */ { MAD_F(0x05dab9e9) /* 0.365899955 */, 16 },
+ /* 1928 */ { MAD_F(0x05dbc368) /* 0.366153151 */, 16 },
+ /* 1929 */ { MAD_F(0x05dcccf2) /* 0.366406390 */, 16 },
+ /* 1930 */ { MAD_F(0x05ddd689) /* 0.366659674 */, 16 },
+ /* 1931 */ { MAD_F(0x05dee02b) /* 0.366913001 */, 16 },
+ /* 1932 */ { MAD_F(0x05dfe9d8) /* 0.367166372 */, 16 },
+ /* 1933 */ { MAD_F(0x05e0f392) /* 0.367419787 */, 16 },
+ /* 1934 */ { MAD_F(0x05e1fd57) /* 0.367673246 */, 16 },
+ /* 1935 */ { MAD_F(0x05e30728) /* 0.367926748 */, 16 },
+
+ /* 1936 */ { MAD_F(0x05e41105) /* 0.368180294 */, 16 },
+ /* 1937 */ { MAD_F(0x05e51aed) /* 0.368433883 */, 16 },
+ /* 1938 */ { MAD_F(0x05e624e1) /* 0.368687517 */, 16 },
+ /* 1939 */ { MAD_F(0x05e72ee1) /* 0.368941193 */, 16 },
+ /* 1940 */ { MAD_F(0x05e838ed) /* 0.369194914 */, 16 },
+ /* 1941 */ { MAD_F(0x05e94304) /* 0.369448678 */, 16 },
+ /* 1942 */ { MAD_F(0x05ea4d27) /* 0.369702485 */, 16 },
+ /* 1943 */ { MAD_F(0x05eb5756) /* 0.369956336 */, 16 },
+ /* 1944 */ { MAD_F(0x05ec6190) /* 0.370210231 */, 16 },
+ /* 1945 */ { MAD_F(0x05ed6bd6) /* 0.370464169 */, 16 },
+ /* 1946 */ { MAD_F(0x05ee7628) /* 0.370718151 */, 16 },
+ /* 1947 */ { MAD_F(0x05ef8085) /* 0.370972177 */, 16 },
+ /* 1948 */ { MAD_F(0x05f08aee) /* 0.371226245 */, 16 },
+ /* 1949 */ { MAD_F(0x05f19563) /* 0.371480358 */, 16 },
+ /* 1950 */ { MAD_F(0x05f29fe3) /* 0.371734513 */, 16 },
+ /* 1951 */ { MAD_F(0x05f3aa6f) /* 0.371988712 */, 16 },
+
+ /* 1952 */ { MAD_F(0x05f4b507) /* 0.372242955 */, 16 },
+ /* 1953 */ { MAD_F(0x05f5bfab) /* 0.372497241 */, 16 },
+ /* 1954 */ { MAD_F(0x05f6ca5a) /* 0.372751570 */, 16 },
+ /* 1955 */ { MAD_F(0x05f7d514) /* 0.373005943 */, 16 },
+ /* 1956 */ { MAD_F(0x05f8dfdb) /* 0.373260359 */, 16 },
+ /* 1957 */ { MAD_F(0x05f9eaad) /* 0.373514819 */, 16 },
+ /* 1958 */ { MAD_F(0x05faf58a) /* 0.373769322 */, 16 },
+ /* 1959 */ { MAD_F(0x05fc0073) /* 0.374023868 */, 16 },
+ /* 1960 */ { MAD_F(0x05fd0b68) /* 0.374278458 */, 16 },
+ /* 1961 */ { MAD_F(0x05fe1669) /* 0.374533091 */, 16 },
+ /* 1962 */ { MAD_F(0x05ff2175) /* 0.374787767 */, 16 },
+ /* 1963 */ { MAD_F(0x06002c8d) /* 0.375042486 */, 16 },
+ /* 1964 */ { MAD_F(0x060137b0) /* 0.375297249 */, 16 },
+ /* 1965 */ { MAD_F(0x060242df) /* 0.375552055 */, 16 },
+ /* 1966 */ { MAD_F(0x06034e19) /* 0.375806904 */, 16 },
+ /* 1967 */ { MAD_F(0x0604595f) /* 0.376061796 */, 16 },
+
+ /* 1968 */ { MAD_F(0x060564b1) /* 0.376316732 */, 16 },
+ /* 1969 */ { MAD_F(0x0606700f) /* 0.376571710 */, 16 },
+ /* 1970 */ { MAD_F(0x06077b77) /* 0.376826732 */, 16 },
+ /* 1971 */ { MAD_F(0x060886ec) /* 0.377081797 */, 16 },
+ /* 1972 */ { MAD_F(0x0609926c) /* 0.377336905 */, 16 },
+ /* 1973 */ { MAD_F(0x060a9df8) /* 0.377592057 */, 16 },
+ /* 1974 */ { MAD_F(0x060ba98f) /* 0.377847251 */, 16 },
+ /* 1975 */ { MAD_F(0x060cb532) /* 0.378102489 */, 16 },
+ /* 1976 */ { MAD_F(0x060dc0e0) /* 0.378357769 */, 16 },
+ /* 1977 */ { MAD_F(0x060ecc9a) /* 0.378613093 */, 16 },
+ /* 1978 */ { MAD_F(0x060fd860) /* 0.378868460 */, 16 },
+ /* 1979 */ { MAD_F(0x0610e431) /* 0.379123870 */, 16 },
+ /* 1980 */ { MAD_F(0x0611f00d) /* 0.379379322 */, 16 },
+ /* 1981 */ { MAD_F(0x0612fbf5) /* 0.379634818 */, 16 },
+ /* 1982 */ { MAD_F(0x061407e9) /* 0.379890357 */, 16 },
+ /* 1983 */ { MAD_F(0x061513e8) /* 0.380145939 */, 16 },
+
+ /* 1984 */ { MAD_F(0x06161ff3) /* 0.380401563 */, 16 },
+ /* 1985 */ { MAD_F(0x06172c09) /* 0.380657231 */, 16 },
+ /* 1986 */ { MAD_F(0x0618382b) /* 0.380912942 */, 16 },
+ /* 1987 */ { MAD_F(0x06194458) /* 0.381168695 */, 16 },
+ /* 1988 */ { MAD_F(0x061a5091) /* 0.381424492 */, 16 },
+ /* 1989 */ { MAD_F(0x061b5cd5) /* 0.381680331 */, 16 },
+ /* 1990 */ { MAD_F(0x061c6925) /* 0.381936213 */, 16 },
+ /* 1991 */ { MAD_F(0x061d7581) /* 0.382192138 */, 16 },
+ /* 1992 */ { MAD_F(0x061e81e8) /* 0.382448106 */, 16 },
+ /* 1993 */ { MAD_F(0x061f8e5a) /* 0.382704117 */, 16 },
+ /* 1994 */ { MAD_F(0x06209ad8) /* 0.382960171 */, 16 },
+ /* 1995 */ { MAD_F(0x0621a761) /* 0.383216267 */, 16 },
+ /* 1996 */ { MAD_F(0x0622b3f6) /* 0.383472406 */, 16 },
+ /* 1997 */ { MAD_F(0x0623c096) /* 0.383728588 */, 16 },
+ /* 1998 */ { MAD_F(0x0624cd42) /* 0.383984813 */, 16 },
+ /* 1999 */ { MAD_F(0x0625d9f9) /* 0.384241080 */, 16 },
+
+ /* 2000 */ { MAD_F(0x0626e6bc) /* 0.384497391 */, 16 },
+ /* 2001 */ { MAD_F(0x0627f38a) /* 0.384753744 */, 16 },
+ /* 2002 */ { MAD_F(0x06290064) /* 0.385010139 */, 16 },
+ /* 2003 */ { MAD_F(0x062a0d49) /* 0.385266578 */, 16 },
+ /* 2004 */ { MAD_F(0x062b1a3a) /* 0.385523059 */, 16 },
+ /* 2005 */ { MAD_F(0x062c2736) /* 0.385779582 */, 16 },
+ /* 2006 */ { MAD_F(0x062d343d) /* 0.386036149 */, 16 },
+ /* 2007 */ { MAD_F(0x062e4150) /* 0.386292758 */, 16 },
+ /* 2008 */ { MAD_F(0x062f4e6f) /* 0.386549409 */, 16 },
+ /* 2009 */ { MAD_F(0x06305b99) /* 0.386806104 */, 16 },
+ /* 2010 */ { MAD_F(0x063168ce) /* 0.387062840 */, 16 },
+ /* 2011 */ { MAD_F(0x0632760f) /* 0.387319620 */, 16 },
+ /* 2012 */ { MAD_F(0x0633835b) /* 0.387576442 */, 16 },
+ /* 2013 */ { MAD_F(0x063490b2) /* 0.387833306 */, 16 },
+ /* 2014 */ { MAD_F(0x06359e15) /* 0.388090213 */, 16 },
+ /* 2015 */ { MAD_F(0x0636ab83) /* 0.388347163 */, 16 },
+
+ /* 2016 */ { MAD_F(0x0637b8fd) /* 0.388604155 */, 16 },
+ /* 2017 */ { MAD_F(0x0638c682) /* 0.388861190 */, 16 },
+ /* 2018 */ { MAD_F(0x0639d413) /* 0.389118267 */, 16 },
+ /* 2019 */ { MAD_F(0x063ae1af) /* 0.389375386 */, 16 },
+ /* 2020 */ { MAD_F(0x063bef56) /* 0.389632548 */, 16 },
+ /* 2021 */ { MAD_F(0x063cfd09) /* 0.389889752 */, 16 },
+ /* 2022 */ { MAD_F(0x063e0ac7) /* 0.390146999 */, 16 },
+ /* 2023 */ { MAD_F(0x063f1891) /* 0.390404289 */, 16 },
+ /* 2024 */ { MAD_F(0x06402666) /* 0.390661620 */, 16 },
+ /* 2025 */ { MAD_F(0x06413446) /* 0.390918994 */, 16 },
+ /* 2026 */ { MAD_F(0x06424232) /* 0.391176411 */, 16 },
+ /* 2027 */ { MAD_F(0x06435029) /* 0.391433869 */, 16 },
+ /* 2028 */ { MAD_F(0x06445e2b) /* 0.391691371 */, 16 },
+ /* 2029 */ { MAD_F(0x06456c39) /* 0.391948914 */, 16 },
+ /* 2030 */ { MAD_F(0x06467a52) /* 0.392206500 */, 16 },
+ /* 2031 */ { MAD_F(0x06478877) /* 0.392464128 */, 16 },
+
+ /* 2032 */ { MAD_F(0x064896a7) /* 0.392721798 */, 16 },
+ /* 2033 */ { MAD_F(0x0649a4e2) /* 0.392979511 */, 16 },
+ /* 2034 */ { MAD_F(0x064ab328) /* 0.393237266 */, 16 },
+ /* 2035 */ { MAD_F(0x064bc17a) /* 0.393495063 */, 16 },
+ /* 2036 */ { MAD_F(0x064ccfd8) /* 0.393752902 */, 16 },
+ /* 2037 */ { MAD_F(0x064dde40) /* 0.394010784 */, 16 },
+ /* 2038 */ { MAD_F(0x064eecb4) /* 0.394268707 */, 16 },
+ /* 2039 */ { MAD_F(0x064ffb33) /* 0.394526673 */, 16 },
+ /* 2040 */ { MAD_F(0x065109be) /* 0.394784681 */, 16 },
+ /* 2041 */ { MAD_F(0x06521854) /* 0.395042732 */, 16 },
+ /* 2042 */ { MAD_F(0x065326f5) /* 0.395300824 */, 16 },
+ /* 2043 */ { MAD_F(0x065435a1) /* 0.395558959 */, 16 },
+ /* 2044 */ { MAD_F(0x06554459) /* 0.395817135 */, 16 },
+ /* 2045 */ { MAD_F(0x0656531c) /* 0.396075354 */, 16 },
+ /* 2046 */ { MAD_F(0x065761ea) /* 0.396333615 */, 16 },
+ /* 2047 */ { MAD_F(0x065870c4) /* 0.396591918 */, 16 },
+
+ /* 2048 */ { MAD_F(0x06597fa9) /* 0.396850263 */, 16 },
+ /* 2049 */ { MAD_F(0x065a8e99) /* 0.397108650 */, 16 },
+ /* 2050 */ { MAD_F(0x065b9d95) /* 0.397367079 */, 16 },
+ /* 2051 */ { MAD_F(0x065cac9c) /* 0.397625550 */, 16 },
+ /* 2052 */ { MAD_F(0x065dbbae) /* 0.397884063 */, 16 },
+ /* 2053 */ { MAD_F(0x065ecacb) /* 0.398142619 */, 16 },
+ /* 2054 */ { MAD_F(0x065fd9f4) /* 0.398401216 */, 16 },
+ /* 2055 */ { MAD_F(0x0660e928) /* 0.398659855 */, 16 },
+ /* 2056 */ { MAD_F(0x0661f867) /* 0.398918536 */, 16 },
+ /* 2057 */ { MAD_F(0x066307b1) /* 0.399177259 */, 16 },
+ /* 2058 */ { MAD_F(0x06641707) /* 0.399436024 */, 16 },
+ /* 2059 */ { MAD_F(0x06652668) /* 0.399694831 */, 16 },
+ /* 2060 */ { MAD_F(0x066635d4) /* 0.399953679 */, 16 },
+ /* 2061 */ { MAD_F(0x0667454c) /* 0.400212570 */, 16 },
+ /* 2062 */ { MAD_F(0x066854ce) /* 0.400471503 */, 16 },
+ /* 2063 */ { MAD_F(0x0669645c) /* 0.400730477 */, 16 },
+
+ /* 2064 */ { MAD_F(0x066a73f5) /* 0.400989493 */, 16 },
+ /* 2065 */ { MAD_F(0x066b839a) /* 0.401248551 */, 16 },
+ /* 2066 */ { MAD_F(0x066c9349) /* 0.401507651 */, 16 },
+ /* 2067 */ { MAD_F(0x066da304) /* 0.401766793 */, 16 },
+ /* 2068 */ { MAD_F(0x066eb2ca) /* 0.402025976 */, 16 },
+ /* 2069 */ { MAD_F(0x066fc29b) /* 0.402285202 */, 16 },
+ /* 2070 */ { MAD_F(0x0670d278) /* 0.402544469 */, 16 },
+ /* 2071 */ { MAD_F(0x0671e25f) /* 0.402803777 */, 16 },
+ /* 2072 */ { MAD_F(0x0672f252) /* 0.403063128 */, 16 },
+ /* 2073 */ { MAD_F(0x06740250) /* 0.403322520 */, 16 },
+ /* 2074 */ { MAD_F(0x0675125a) /* 0.403581954 */, 16 },
+ /* 2075 */ { MAD_F(0x0676226e) /* 0.403841430 */, 16 },
+ /* 2076 */ { MAD_F(0x0677328e) /* 0.404100947 */, 16 },
+ /* 2077 */ { MAD_F(0x067842b9) /* 0.404360506 */, 16 },
+ /* 2078 */ { MAD_F(0x067952ef) /* 0.404620107 */, 16 },
+ /* 2079 */ { MAD_F(0x067a6330) /* 0.404879749 */, 16 },
+
+ /* 2080 */ { MAD_F(0x067b737c) /* 0.405139433 */, 16 },
+ /* 2081 */ { MAD_F(0x067c83d4) /* 0.405399159 */, 16 },
+ /* 2082 */ { MAD_F(0x067d9436) /* 0.405658926 */, 16 },
+ /* 2083 */ { MAD_F(0x067ea4a4) /* 0.405918735 */, 16 },
+ /* 2084 */ { MAD_F(0x067fb51d) /* 0.406178585 */, 16 },
+ /* 2085 */ { MAD_F(0x0680c5a2) /* 0.406438477 */, 16 },
+ /* 2086 */ { MAD_F(0x0681d631) /* 0.406698410 */, 16 },
+ /* 2087 */ { MAD_F(0x0682e6cb) /* 0.406958385 */, 16 },
+ /* 2088 */ { MAD_F(0x0683f771) /* 0.407218402 */, 16 },
+ /* 2089 */ { MAD_F(0x06850822) /* 0.407478460 */, 16 },
+ /* 2090 */ { MAD_F(0x068618de) /* 0.407738559 */, 16 },
+ /* 2091 */ { MAD_F(0x068729a5) /* 0.407998700 */, 16 },
+ /* 2092 */ { MAD_F(0x06883a77) /* 0.408258883 */, 16 },
+ /* 2093 */ { MAD_F(0x06894b55) /* 0.408519107 */, 16 },
+ /* 2094 */ { MAD_F(0x068a5c3d) /* 0.408779372 */, 16 },
+ /* 2095 */ { MAD_F(0x068b6d31) /* 0.409039679 */, 16 },
+
+ /* 2096 */ { MAD_F(0x068c7e2f) /* 0.409300027 */, 16 },
+ /* 2097 */ { MAD_F(0x068d8f39) /* 0.409560417 */, 16 },
+ /* 2098 */ { MAD_F(0x068ea04e) /* 0.409820848 */, 16 },
+ /* 2099 */ { MAD_F(0x068fb16e) /* 0.410081321 */, 16 },
+ /* 2100 */ { MAD_F(0x0690c299) /* 0.410341834 */, 16 },
+ /* 2101 */ { MAD_F(0x0691d3cf) /* 0.410602390 */, 16 },
+ /* 2102 */ { MAD_F(0x0692e511) /* 0.410862986 */, 16 },
+ /* 2103 */ { MAD_F(0x0693f65d) /* 0.411123624 */, 16 },
+ /* 2104 */ { MAD_F(0x069507b5) /* 0.411384303 */, 16 },
+ /* 2105 */ { MAD_F(0x06961917) /* 0.411645024 */, 16 },
+ /* 2106 */ { MAD_F(0x06972a85) /* 0.411905785 */, 16 },
+ /* 2107 */ { MAD_F(0x06983bfe) /* 0.412166588 */, 16 },
+ /* 2108 */ { MAD_F(0x06994d82) /* 0.412427433 */, 16 },
+ /* 2109 */ { MAD_F(0x069a5f11) /* 0.412688318 */, 16 },
+ /* 2110 */ { MAD_F(0x069b70ab) /* 0.412949245 */, 16 },
+ /* 2111 */ { MAD_F(0x069c8250) /* 0.413210213 */, 16 },
+
+ /* 2112 */ { MAD_F(0x069d9400) /* 0.413471222 */, 16 },
+ /* 2113 */ { MAD_F(0x069ea5bb) /* 0.413732273 */, 16 },
+ /* 2114 */ { MAD_F(0x069fb781) /* 0.413993364 */, 16 },
+ /* 2115 */ { MAD_F(0x06a0c953) /* 0.414254497 */, 16 },
+ /* 2116 */ { MAD_F(0x06a1db2f) /* 0.414515671 */, 16 },
+ /* 2117 */ { MAD_F(0x06a2ed16) /* 0.414776886 */, 16 },
+ /* 2118 */ { MAD_F(0x06a3ff09) /* 0.415038142 */, 16 },
+ /* 2119 */ { MAD_F(0x06a51106) /* 0.415299440 */, 16 },
+ /* 2120 */ { MAD_F(0x06a6230f) /* 0.415560778 */, 16 },
+ /* 2121 */ { MAD_F(0x06a73522) /* 0.415822157 */, 16 },
+ /* 2122 */ { MAD_F(0x06a84741) /* 0.416083578 */, 16 },
+ /* 2123 */ { MAD_F(0x06a9596a) /* 0.416345040 */, 16 },
+ /* 2124 */ { MAD_F(0x06aa6b9f) /* 0.416606542 */, 16 },
+ /* 2125 */ { MAD_F(0x06ab7ddf) /* 0.416868086 */, 16 },
+ /* 2126 */ { MAD_F(0x06ac9029) /* 0.417129671 */, 16 },
+ /* 2127 */ { MAD_F(0x06ada27f) /* 0.417391297 */, 16 },
+
+ /* 2128 */ { MAD_F(0x06aeb4e0) /* 0.417652964 */, 16 },
+ /* 2129 */ { MAD_F(0x06afc74b) /* 0.417914672 */, 16 },
+ /* 2130 */ { MAD_F(0x06b0d9c2) /* 0.418176420 */, 16 },
+ /* 2131 */ { MAD_F(0x06b1ec43) /* 0.418438210 */, 16 },
+ /* 2132 */ { MAD_F(0x06b2fed0) /* 0.418700041 */, 16 },
+ /* 2133 */ { MAD_F(0x06b41168) /* 0.418961912 */, 16 },
+ /* 2134 */ { MAD_F(0x06b5240a) /* 0.419223825 */, 16 },
+ /* 2135 */ { MAD_F(0x06b636b8) /* 0.419485778 */, 16 },
+ /* 2136 */ { MAD_F(0x06b74971) /* 0.419747773 */, 16 },
+ /* 2137 */ { MAD_F(0x06b85c34) /* 0.420009808 */, 16 },
+ /* 2138 */ { MAD_F(0x06b96f03) /* 0.420271884 */, 16 },
+ /* 2139 */ { MAD_F(0x06ba81dc) /* 0.420534001 */, 16 },
+ /* 2140 */ { MAD_F(0x06bb94c1) /* 0.420796159 */, 16 },
+ /* 2141 */ { MAD_F(0x06bca7b0) /* 0.421058358 */, 16 },
+ /* 2142 */ { MAD_F(0x06bdbaaa) /* 0.421320597 */, 16 },
+ /* 2143 */ { MAD_F(0x06becdb0) /* 0.421582878 */, 16 },
+
+ /* 2144 */ { MAD_F(0x06bfe0c0) /* 0.421845199 */, 16 },
+ /* 2145 */ { MAD_F(0x06c0f3db) /* 0.422107561 */, 16 },
+ /* 2146 */ { MAD_F(0x06c20702) /* 0.422369964 */, 16 },
+ /* 2147 */ { MAD_F(0x06c31a33) /* 0.422632407 */, 16 },
+ /* 2148 */ { MAD_F(0x06c42d6f) /* 0.422894891 */, 16 },
+ /* 2149 */ { MAD_F(0x06c540b6) /* 0.423157416 */, 16 },
+ /* 2150 */ { MAD_F(0x06c65408) /* 0.423419982 */, 16 },
+ /* 2151 */ { MAD_F(0x06c76765) /* 0.423682588 */, 16 },
+ /* 2152 */ { MAD_F(0x06c87acc) /* 0.423945235 */, 16 },
+ /* 2153 */ { MAD_F(0x06c98e3f) /* 0.424207923 */, 16 },
+ /* 2154 */ { MAD_F(0x06caa1bd) /* 0.424470652 */, 16 },
+ /* 2155 */ { MAD_F(0x06cbb545) /* 0.424733421 */, 16 },
+ /* 2156 */ { MAD_F(0x06ccc8d9) /* 0.424996230 */, 16 },
+ /* 2157 */ { MAD_F(0x06cddc77) /* 0.425259081 */, 16 },
+ /* 2158 */ { MAD_F(0x06cef020) /* 0.425521972 */, 16 },
+ /* 2159 */ { MAD_F(0x06d003d4) /* 0.425784903 */, 16 },
+
+ /* 2160 */ { MAD_F(0x06d11794) /* 0.426047876 */, 16 },
+ /* 2161 */ { MAD_F(0x06d22b5e) /* 0.426310889 */, 16 },
+ /* 2162 */ { MAD_F(0x06d33f32) /* 0.426573942 */, 16 },
+ /* 2163 */ { MAD_F(0x06d45312) /* 0.426837036 */, 16 },
+ /* 2164 */ { MAD_F(0x06d566fd) /* 0.427100170 */, 16 },
+ /* 2165 */ { MAD_F(0x06d67af2) /* 0.427363345 */, 16 },
+ /* 2166 */ { MAD_F(0x06d78ef3) /* 0.427626561 */, 16 },
+ /* 2167 */ { MAD_F(0x06d8a2fe) /* 0.427889817 */, 16 },
+ /* 2168 */ { MAD_F(0x06d9b714) /* 0.428153114 */, 16 },
+ /* 2169 */ { MAD_F(0x06dacb35) /* 0.428416451 */, 16 },
+ /* 2170 */ { MAD_F(0x06dbdf61) /* 0.428679828 */, 16 },
+ /* 2171 */ { MAD_F(0x06dcf398) /* 0.428943246 */, 16 },
+ /* 2172 */ { MAD_F(0x06de07d9) /* 0.429206704 */, 16 },
+ /* 2173 */ { MAD_F(0x06df1c26) /* 0.429470203 */, 16 },
+ /* 2174 */ { MAD_F(0x06e0307d) /* 0.429733743 */, 16 },
+ /* 2175 */ { MAD_F(0x06e144df) /* 0.429997322 */, 16 },
+
+ /* 2176 */ { MAD_F(0x06e2594c) /* 0.430260942 */, 16 },
+ /* 2177 */ { MAD_F(0x06e36dc4) /* 0.430524603 */, 16 },
+ /* 2178 */ { MAD_F(0x06e48246) /* 0.430788304 */, 16 },
+ /* 2179 */ { MAD_F(0x06e596d4) /* 0.431052045 */, 16 },
+ /* 2180 */ { MAD_F(0x06e6ab6c) /* 0.431315826 */, 16 },
+ /* 2181 */ { MAD_F(0x06e7c00f) /* 0.431579648 */, 16 },
+ /* 2182 */ { MAD_F(0x06e8d4bd) /* 0.431843511 */, 16 },
+ /* 2183 */ { MAD_F(0x06e9e976) /* 0.432107413 */, 16 },
+ /* 2184 */ { MAD_F(0x06eafe3a) /* 0.432371356 */, 16 },
+ /* 2185 */ { MAD_F(0x06ec1308) /* 0.432635339 */, 16 },
+ /* 2186 */ { MAD_F(0x06ed27e2) /* 0.432899362 */, 16 },
+ /* 2187 */ { MAD_F(0x06ee3cc6) /* 0.433163426 */, 16 },
+ /* 2188 */ { MAD_F(0x06ef51b4) /* 0.433427530 */, 16 },
+ /* 2189 */ { MAD_F(0x06f066ae) /* 0.433691674 */, 16 },
+ /* 2190 */ { MAD_F(0x06f17bb3) /* 0.433955859 */, 16 },
+ /* 2191 */ { MAD_F(0x06f290c2) /* 0.434220083 */, 16 },
+
+ /* 2192 */ { MAD_F(0x06f3a5dc) /* 0.434484348 */, 16 },
+ /* 2193 */ { MAD_F(0x06f4bb01) /* 0.434748653 */, 16 },
+ /* 2194 */ { MAD_F(0x06f5d030) /* 0.435012998 */, 16 },
+ /* 2195 */ { MAD_F(0x06f6e56b) /* 0.435277383 */, 16 },
+ /* 2196 */ { MAD_F(0x06f7fab0) /* 0.435541809 */, 16 },
+ /* 2197 */ { MAD_F(0x06f91000) /* 0.435806274 */, 16 },
+ /* 2198 */ { MAD_F(0x06fa255a) /* 0.436070780 */, 16 },
+ /* 2199 */ { MAD_F(0x06fb3ac0) /* 0.436335326 */, 16 },
+ /* 2200 */ { MAD_F(0x06fc5030) /* 0.436599912 */, 16 },
+ /* 2201 */ { MAD_F(0x06fd65ab) /* 0.436864538 */, 16 },
+ /* 2202 */ { MAD_F(0x06fe7b31) /* 0.437129204 */, 16 },
+ /* 2203 */ { MAD_F(0x06ff90c2) /* 0.437393910 */, 16 },
+ /* 2204 */ { MAD_F(0x0700a65d) /* 0.437658657 */, 16 },
+ /* 2205 */ { MAD_F(0x0701bc03) /* 0.437923443 */, 16 },
+ /* 2206 */ { MAD_F(0x0702d1b4) /* 0.438188269 */, 16 },
+ /* 2207 */ { MAD_F(0x0703e76f) /* 0.438453136 */, 16 },
+
+ /* 2208 */ { MAD_F(0x0704fd35) /* 0.438718042 */, 16 },
+ /* 2209 */ { MAD_F(0x07061306) /* 0.438982988 */, 16 },
+ /* 2210 */ { MAD_F(0x070728e2) /* 0.439247975 */, 16 },
+ /* 2211 */ { MAD_F(0x07083ec9) /* 0.439513001 */, 16 },
+ /* 2212 */ { MAD_F(0x070954ba) /* 0.439778067 */, 16 },
+ /* 2213 */ { MAD_F(0x070a6ab6) /* 0.440043173 */, 16 },
+ /* 2214 */ { MAD_F(0x070b80bc) /* 0.440308320 */, 16 },
+ /* 2215 */ { MAD_F(0x070c96ce) /* 0.440573506 */, 16 },
+ /* 2216 */ { MAD_F(0x070dacea) /* 0.440838732 */, 16 },
+ /* 2217 */ { MAD_F(0x070ec310) /* 0.441103997 */, 16 },
+ /* 2218 */ { MAD_F(0x070fd942) /* 0.441369303 */, 16 },
+ /* 2219 */ { MAD_F(0x0710ef7e) /* 0.441634649 */, 16 },
+ /* 2220 */ { MAD_F(0x071205c5) /* 0.441900034 */, 16 },
+ /* 2221 */ { MAD_F(0x07131c17) /* 0.442165460 */, 16 },
+ /* 2222 */ { MAD_F(0x07143273) /* 0.442430925 */, 16 },
+ /* 2223 */ { MAD_F(0x071548da) /* 0.442696430 */, 16 },
+
+ /* 2224 */ { MAD_F(0x07165f4b) /* 0.442961975 */, 16 },
+ /* 2225 */ { MAD_F(0x071775c8) /* 0.443227559 */, 16 },
+ /* 2226 */ { MAD_F(0x07188c4f) /* 0.443493184 */, 16 },
+ /* 2227 */ { MAD_F(0x0719a2e0) /* 0.443758848 */, 16 },
+ /* 2228 */ { MAD_F(0x071ab97d) /* 0.444024552 */, 16 },
+ /* 2229 */ { MAD_F(0x071bd024) /* 0.444290296 */, 16 },
+ /* 2230 */ { MAD_F(0x071ce6d6) /* 0.444556079 */, 16 },
+ /* 2231 */ { MAD_F(0x071dfd92) /* 0.444821902 */, 16 },
+ /* 2232 */ { MAD_F(0x071f1459) /* 0.445087765 */, 16 },
+ /* 2233 */ { MAD_F(0x07202b2b) /* 0.445353668 */, 16 },
+ /* 2234 */ { MAD_F(0x07214207) /* 0.445619610 */, 16 },
+ /* 2235 */ { MAD_F(0x072258ee) /* 0.445885592 */, 16 },
+ /* 2236 */ { MAD_F(0x07236fe0) /* 0.446151614 */, 16 },
+ /* 2237 */ { MAD_F(0x072486dc) /* 0.446417675 */, 16 },
+ /* 2238 */ { MAD_F(0x07259de3) /* 0.446683776 */, 16 },
+ /* 2239 */ { MAD_F(0x0726b4f4) /* 0.446949917 */, 16 },
+
+ /* 2240 */ { MAD_F(0x0727cc11) /* 0.447216097 */, 16 },
+ /* 2241 */ { MAD_F(0x0728e338) /* 0.447482317 */, 16 },
+ /* 2242 */ { MAD_F(0x0729fa69) /* 0.447748576 */, 16 },
+ /* 2243 */ { MAD_F(0x072b11a5) /* 0.448014875 */, 16 },
+ /* 2244 */ { MAD_F(0x072c28ec) /* 0.448281214 */, 16 },
+ /* 2245 */ { MAD_F(0x072d403d) /* 0.448547592 */, 16 },
+ /* 2246 */ { MAD_F(0x072e5799) /* 0.448814010 */, 16 },
+ /* 2247 */ { MAD_F(0x072f6f00) /* 0.449080467 */, 16 },
+ /* 2248 */ { MAD_F(0x07308671) /* 0.449346964 */, 16 },
+ /* 2249 */ { MAD_F(0x07319ded) /* 0.449613501 */, 16 },
+ /* 2250 */ { MAD_F(0x0732b573) /* 0.449880076 */, 16 },
+ /* 2251 */ { MAD_F(0x0733cd04) /* 0.450146692 */, 16 },
+ /* 2252 */ { MAD_F(0x0734e4a0) /* 0.450413347 */, 16 },
+ /* 2253 */ { MAD_F(0x0735fc46) /* 0.450680041 */, 16 },
+ /* 2254 */ { MAD_F(0x073713f7) /* 0.450946775 */, 16 },
+ /* 2255 */ { MAD_F(0x07382bb2) /* 0.451213548 */, 16 },
+
+ /* 2256 */ { MAD_F(0x07394378) /* 0.451480360 */, 16 },
+ /* 2257 */ { MAD_F(0x073a5b49) /* 0.451747213 */, 16 },
+ /* 2258 */ { MAD_F(0x073b7324) /* 0.452014104 */, 16 },
+ /* 2259 */ { MAD_F(0x073c8b0a) /* 0.452281035 */, 16 },
+ /* 2260 */ { MAD_F(0x073da2fa) /* 0.452548005 */, 16 },
+ /* 2261 */ { MAD_F(0x073ebaf5) /* 0.452815015 */, 16 },
+ /* 2262 */ { MAD_F(0x073fd2fa) /* 0.453082064 */, 16 },
+ /* 2263 */ { MAD_F(0x0740eb0a) /* 0.453349152 */, 16 },
+ /* 2264 */ { MAD_F(0x07420325) /* 0.453616280 */, 16 },
+ /* 2265 */ { MAD_F(0x07431b4a) /* 0.453883447 */, 16 },
+ /* 2266 */ { MAD_F(0x0744337a) /* 0.454150653 */, 16 },
+ /* 2267 */ { MAD_F(0x07454bb4) /* 0.454417899 */, 16 },
+ /* 2268 */ { MAD_F(0x074663f8) /* 0.454685184 */, 16 },
+ /* 2269 */ { MAD_F(0x07477c48) /* 0.454952508 */, 16 },
+ /* 2270 */ { MAD_F(0x074894a2) /* 0.455219872 */, 16 },
+ /* 2271 */ { MAD_F(0x0749ad06) /* 0.455487275 */, 16 },
+
+ /* 2272 */ { MAD_F(0x074ac575) /* 0.455754717 */, 16 },
+ /* 2273 */ { MAD_F(0x074bddee) /* 0.456022198 */, 16 },
+ /* 2274 */ { MAD_F(0x074cf672) /* 0.456289719 */, 16 },
+ /* 2275 */ { MAD_F(0x074e0f01) /* 0.456557278 */, 16 },
+ /* 2276 */ { MAD_F(0x074f279a) /* 0.456824877 */, 16 },
+ /* 2277 */ { MAD_F(0x0750403e) /* 0.457092516 */, 16 },
+ /* 2278 */ { MAD_F(0x075158ec) /* 0.457360193 */, 16 },
+ /* 2279 */ { MAD_F(0x075271a4) /* 0.457627909 */, 16 },
+ /* 2280 */ { MAD_F(0x07538a67) /* 0.457895665 */, 16 },
+ /* 2281 */ { MAD_F(0x0754a335) /* 0.458163460 */, 16 },
+ /* 2282 */ { MAD_F(0x0755bc0d) /* 0.458431294 */, 16 },
+ /* 2283 */ { MAD_F(0x0756d4f0) /* 0.458699167 */, 16 },
+ /* 2284 */ { MAD_F(0x0757eddd) /* 0.458967079 */, 16 },
+ /* 2285 */ { MAD_F(0x075906d5) /* 0.459235030 */, 16 },
+ /* 2286 */ { MAD_F(0x075a1fd7) /* 0.459503021 */, 16 },
+ /* 2287 */ { MAD_F(0x075b38e3) /* 0.459771050 */, 16 },
+
+ /* 2288 */ { MAD_F(0x075c51fa) /* 0.460039119 */, 16 },
+ /* 2289 */ { MAD_F(0x075d6b1c) /* 0.460307226 */, 16 },
+ /* 2290 */ { MAD_F(0x075e8448) /* 0.460575373 */, 16 },
+ /* 2291 */ { MAD_F(0x075f9d7f) /* 0.460843559 */, 16 },
+ /* 2292 */ { MAD_F(0x0760b6c0) /* 0.461111783 */, 16 },
+ /* 2293 */ { MAD_F(0x0761d00b) /* 0.461380047 */, 16 },
+ /* 2294 */ { MAD_F(0x0762e961) /* 0.461648350 */, 16 },
+ /* 2295 */ { MAD_F(0x076402c1) /* 0.461916691 */, 16 },
+ /* 2296 */ { MAD_F(0x07651c2c) /* 0.462185072 */, 16 },
+ /* 2297 */ { MAD_F(0x076635a2) /* 0.462453492 */, 16 },
+ /* 2298 */ { MAD_F(0x07674f22) /* 0.462721950 */, 16 },
+ /* 2299 */ { MAD_F(0x076868ac) /* 0.462990448 */, 16 },
+ /* 2300 */ { MAD_F(0x07698240) /* 0.463258984 */, 16 },
+ /* 2301 */ { MAD_F(0x076a9be0) /* 0.463527560 */, 16 },
+ /* 2302 */ { MAD_F(0x076bb589) /* 0.463796174 */, 16 },
+ /* 2303 */ { MAD_F(0x076ccf3d) /* 0.464064827 */, 16 },
+
+ /* 2304 */ { MAD_F(0x076de8fc) /* 0.464333519 */, 16 },
+ /* 2305 */ { MAD_F(0x076f02c5) /* 0.464602250 */, 16 },
+ /* 2306 */ { MAD_F(0x07701c98) /* 0.464871020 */, 16 },
+ /* 2307 */ { MAD_F(0x07713676) /* 0.465139829 */, 16 },
+ /* 2308 */ { MAD_F(0x0772505e) /* 0.465408676 */, 16 },
+ /* 2309 */ { MAD_F(0x07736a51) /* 0.465677563 */, 16 },
+ /* 2310 */ { MAD_F(0x0774844e) /* 0.465946488 */, 16 },
+ /* 2311 */ { MAD_F(0x07759e55) /* 0.466215452 */, 16 },
+ /* 2312 */ { MAD_F(0x0776b867) /* 0.466484455 */, 16 },
+ /* 2313 */ { MAD_F(0x0777d283) /* 0.466753496 */, 16 },
+ /* 2314 */ { MAD_F(0x0778ecaa) /* 0.467022577 */, 16 },
+ /* 2315 */ { MAD_F(0x077a06db) /* 0.467291696 */, 16 },
+ /* 2316 */ { MAD_F(0x077b2117) /* 0.467560854 */, 16 },
+ /* 2317 */ { MAD_F(0x077c3b5d) /* 0.467830050 */, 16 },
+ /* 2318 */ { MAD_F(0x077d55ad) /* 0.468099285 */, 16 },
+ /* 2319 */ { MAD_F(0x077e7008) /* 0.468368560 */, 16 },
+
+ /* 2320 */ { MAD_F(0x077f8a6d) /* 0.468637872 */, 16 },
+ /* 2321 */ { MAD_F(0x0780a4dc) /* 0.468907224 */, 16 },
+ /* 2322 */ { MAD_F(0x0781bf56) /* 0.469176614 */, 16 },
+ /* 2323 */ { MAD_F(0x0782d9da) /* 0.469446043 */, 16 },
+ /* 2324 */ { MAD_F(0x0783f469) /* 0.469715510 */, 16 },
+ /* 2325 */ { MAD_F(0x07850f02) /* 0.469985016 */, 16 },
+ /* 2326 */ { MAD_F(0x078629a5) /* 0.470254561 */, 16 },
+ /* 2327 */ { MAD_F(0x07874453) /* 0.470524145 */, 16 },
+ /* 2328 */ { MAD_F(0x07885f0b) /* 0.470793767 */, 16 },
+ /* 2329 */ { MAD_F(0x078979ce) /* 0.471063427 */, 16 },
+ /* 2330 */ { MAD_F(0x078a949a) /* 0.471333126 */, 16 },
+ /* 2331 */ { MAD_F(0x078baf72) /* 0.471602864 */, 16 },
+ /* 2332 */ { MAD_F(0x078cca53) /* 0.471872641 */, 16 },
+ /* 2333 */ { MAD_F(0x078de53f) /* 0.472142456 */, 16 },
+ /* 2334 */ { MAD_F(0x078f0035) /* 0.472412309 */, 16 },
+ /* 2335 */ { MAD_F(0x07901b36) /* 0.472682201 */, 16 },
+
+ /* 2336 */ { MAD_F(0x07913641) /* 0.472952132 */, 16 },
+ /* 2337 */ { MAD_F(0x07925156) /* 0.473222101 */, 16 },
+ /* 2338 */ { MAD_F(0x07936c76) /* 0.473492108 */, 16 },
+ /* 2339 */ { MAD_F(0x079487a0) /* 0.473762155 */, 16 },
+ /* 2340 */ { MAD_F(0x0795a2d4) /* 0.474032239 */, 16 },
+ /* 2341 */ { MAD_F(0x0796be13) /* 0.474302362 */, 16 },
+ /* 2342 */ { MAD_F(0x0797d95c) /* 0.474572524 */, 16 },
+ /* 2343 */ { MAD_F(0x0798f4af) /* 0.474842724 */, 16 },
+ /* 2344 */ { MAD_F(0x079a100c) /* 0.475112962 */, 16 },
+ /* 2345 */ { MAD_F(0x079b2b74) /* 0.475383239 */, 16 },
+ /* 2346 */ { MAD_F(0x079c46e7) /* 0.475653554 */, 16 },
+ /* 2347 */ { MAD_F(0x079d6263) /* 0.475923908 */, 16 },
+ /* 2348 */ { MAD_F(0x079e7dea) /* 0.476194300 */, 16 },
+ /* 2349 */ { MAD_F(0x079f997b) /* 0.476464731 */, 16 },
+ /* 2350 */ { MAD_F(0x07a0b516) /* 0.476735200 */, 16 },
+ /* 2351 */ { MAD_F(0x07a1d0bc) /* 0.477005707 */, 16 },
+
+ /* 2352 */ { MAD_F(0x07a2ec6c) /* 0.477276252 */, 16 },
+ /* 2353 */ { MAD_F(0x07a40827) /* 0.477546836 */, 16 },
+ /* 2354 */ { MAD_F(0x07a523eb) /* 0.477817459 */, 16 },
+ /* 2355 */ { MAD_F(0x07a63fba) /* 0.478088119 */, 16 },
+ /* 2356 */ { MAD_F(0x07a75b93) /* 0.478358818 */, 16 },
+ /* 2357 */ { MAD_F(0x07a87777) /* 0.478629555 */, 16 },
+ /* 2358 */ { MAD_F(0x07a99364) /* 0.478900331 */, 16 },
+ /* 2359 */ { MAD_F(0x07aaaf5c) /* 0.479171145 */, 16 },
+ /* 2360 */ { MAD_F(0x07abcb5f) /* 0.479441997 */, 16 },
+ /* 2361 */ { MAD_F(0x07ace76b) /* 0.479712887 */, 16 },
+ /* 2362 */ { MAD_F(0x07ae0382) /* 0.479983816 */, 16 },
+ /* 2363 */ { MAD_F(0x07af1fa3) /* 0.480254782 */, 16 },
+ /* 2364 */ { MAD_F(0x07b03bcf) /* 0.480525787 */, 16 },
+ /* 2365 */ { MAD_F(0x07b15804) /* 0.480796831 */, 16 },
+ /* 2366 */ { MAD_F(0x07b27444) /* 0.481067912 */, 16 },
+ /* 2367 */ { MAD_F(0x07b3908e) /* 0.481339032 */, 16 },
+
+ /* 2368 */ { MAD_F(0x07b4ace3) /* 0.481610189 */, 16 },
+ /* 2369 */ { MAD_F(0x07b5c941) /* 0.481881385 */, 16 },
+ /* 2370 */ { MAD_F(0x07b6e5aa) /* 0.482152620 */, 16 },
+ /* 2371 */ { MAD_F(0x07b8021d) /* 0.482423892 */, 16 },
+ /* 2372 */ { MAD_F(0x07b91e9b) /* 0.482695202 */, 16 },
+ /* 2373 */ { MAD_F(0x07ba3b22) /* 0.482966551 */, 16 },
+ /* 2374 */ { MAD_F(0x07bb57b4) /* 0.483237938 */, 16 },
+ /* 2375 */ { MAD_F(0x07bc7450) /* 0.483509362 */, 16 },
+ /* 2376 */ { MAD_F(0x07bd90f6) /* 0.483780825 */, 16 },
+ /* 2377 */ { MAD_F(0x07beada7) /* 0.484052326 */, 16 },
+ /* 2378 */ { MAD_F(0x07bfca61) /* 0.484323865 */, 16 },
+ /* 2379 */ { MAD_F(0x07c0e726) /* 0.484595443 */, 16 },
+ /* 2380 */ { MAD_F(0x07c203f5) /* 0.484867058 */, 16 },
+ /* 2381 */ { MAD_F(0x07c320cf) /* 0.485138711 */, 16 },
+ /* 2382 */ { MAD_F(0x07c43db2) /* 0.485410402 */, 16 },
+ /* 2383 */ { MAD_F(0x07c55aa0) /* 0.485682131 */, 16 },
+
+ /* 2384 */ { MAD_F(0x07c67798) /* 0.485953899 */, 16 },
+ /* 2385 */ { MAD_F(0x07c7949a) /* 0.486225704 */, 16 },
+ /* 2386 */ { MAD_F(0x07c8b1a7) /* 0.486497547 */, 16 },
+ /* 2387 */ { MAD_F(0x07c9cebd) /* 0.486769429 */, 16 },
+ /* 2388 */ { MAD_F(0x07caebde) /* 0.487041348 */, 16 },
+ /* 2389 */ { MAD_F(0x07cc0909) /* 0.487313305 */, 16 },
+ /* 2390 */ { MAD_F(0x07cd263e) /* 0.487585300 */, 16 },
+ /* 2391 */ { MAD_F(0x07ce437d) /* 0.487857333 */, 16 },
+ /* 2392 */ { MAD_F(0x07cf60c7) /* 0.488129404 */, 16 },
+ /* 2393 */ { MAD_F(0x07d07e1b) /* 0.488401513 */, 16 },
+ /* 2394 */ { MAD_F(0x07d19b79) /* 0.488673660 */, 16 },
+ /* 2395 */ { MAD_F(0x07d2b8e1) /* 0.488945845 */, 16 },
+ /* 2396 */ { MAD_F(0x07d3d653) /* 0.489218067 */, 16 },
+ /* 2397 */ { MAD_F(0x07d4f3cf) /* 0.489490328 */, 16 },
+ /* 2398 */ { MAD_F(0x07d61156) /* 0.489762626 */, 16 },
+ /* 2399 */ { MAD_F(0x07d72ee6) /* 0.490034962 */, 16 },
+
+ /* 2400 */ { MAD_F(0x07d84c81) /* 0.490307336 */, 16 },
+ /* 2401 */ { MAD_F(0x07d96a26) /* 0.490579748 */, 16 },
+ /* 2402 */ { MAD_F(0x07da87d5) /* 0.490852198 */, 16 },
+ /* 2403 */ { MAD_F(0x07dba58f) /* 0.491124686 */, 16 },
+ /* 2404 */ { MAD_F(0x07dcc352) /* 0.491397211 */, 16 },
+ /* 2405 */ { MAD_F(0x07dde120) /* 0.491669774 */, 16 },
+ /* 2406 */ { MAD_F(0x07defef7) /* 0.491942375 */, 16 },
+ /* 2407 */ { MAD_F(0x07e01cd9) /* 0.492215014 */, 16 },
+ /* 2408 */ { MAD_F(0x07e13ac5) /* 0.492487690 */, 16 },
+ /* 2409 */ { MAD_F(0x07e258bc) /* 0.492760404 */, 16 },
+ /* 2410 */ { MAD_F(0x07e376bc) /* 0.493033156 */, 16 },
+ /* 2411 */ { MAD_F(0x07e494c6) /* 0.493305946 */, 16 },
+ /* 2412 */ { MAD_F(0x07e5b2db) /* 0.493578773 */, 16 },
+ /* 2413 */ { MAD_F(0x07e6d0f9) /* 0.493851638 */, 16 },
+ /* 2414 */ { MAD_F(0x07e7ef22) /* 0.494124541 */, 16 },
+ /* 2415 */ { MAD_F(0x07e90d55) /* 0.494397481 */, 16 },
+
+ /* 2416 */ { MAD_F(0x07ea2b92) /* 0.494670459 */, 16 },
+ /* 2417 */ { MAD_F(0x07eb49d9) /* 0.494943475 */, 16 },
+ /* 2418 */ { MAD_F(0x07ec682a) /* 0.495216529 */, 16 },
+ /* 2419 */ { MAD_F(0x07ed8686) /* 0.495489620 */, 16 },
+ /* 2420 */ { MAD_F(0x07eea4eb) /* 0.495762748 */, 16 },
+ /* 2421 */ { MAD_F(0x07efc35b) /* 0.496035915 */, 16 },
+ /* 2422 */ { MAD_F(0x07f0e1d4) /* 0.496309119 */, 16 },
+ /* 2423 */ { MAD_F(0x07f20058) /* 0.496582360 */, 16 },
+ /* 2424 */ { MAD_F(0x07f31ee6) /* 0.496855639 */, 16 },
+ /* 2425 */ { MAD_F(0x07f43d7e) /* 0.497128956 */, 16 },
+ /* 2426 */ { MAD_F(0x07f55c20) /* 0.497402310 */, 16 },
+ /* 2427 */ { MAD_F(0x07f67acc) /* 0.497675702 */, 16 },
+ /* 2428 */ { MAD_F(0x07f79982) /* 0.497949132 */, 16 },
+ /* 2429 */ { MAD_F(0x07f8b842) /* 0.498222598 */, 16 },
+ /* 2430 */ { MAD_F(0x07f9d70c) /* 0.498496103 */, 16 },
+ /* 2431 */ { MAD_F(0x07faf5e1) /* 0.498769645 */, 16 },
+
+ /* 2432 */ { MAD_F(0x07fc14bf) /* 0.499043224 */, 16 },
+ /* 2433 */ { MAD_F(0x07fd33a8) /* 0.499316841 */, 16 },
+ /* 2434 */ { MAD_F(0x07fe529a) /* 0.499590496 */, 16 },
+ /* 2435 */ { MAD_F(0x07ff7197) /* 0.499864188 */, 16 },
+ /* 2436 */ { MAD_F(0x0400484f) /* 0.250068959 */, 17 },
+ /* 2437 */ { MAD_F(0x0400d7d7) /* 0.250205842 */, 17 },
+ /* 2438 */ { MAD_F(0x04016764) /* 0.250342744 */, 17 },
+ /* 2439 */ { MAD_F(0x0401f6f7) /* 0.250479665 */, 17 },
+ /* 2440 */ { MAD_F(0x0402868e) /* 0.250616605 */, 17 },
+ /* 2441 */ { MAD_F(0x0403162b) /* 0.250753563 */, 17 },
+ /* 2442 */ { MAD_F(0x0403a5cc) /* 0.250890540 */, 17 },
+ /* 2443 */ { MAD_F(0x04043573) /* 0.251027536 */, 17 },
+ /* 2444 */ { MAD_F(0x0404c51e) /* 0.251164550 */, 17 },
+ /* 2445 */ { MAD_F(0x040554cf) /* 0.251301583 */, 17 },
+ /* 2446 */ { MAD_F(0x0405e484) /* 0.251438635 */, 17 },
+ /* 2447 */ { MAD_F(0x0406743f) /* 0.251575706 */, 17 },
+
+ /* 2448 */ { MAD_F(0x040703ff) /* 0.251712795 */, 17 },
+ /* 2449 */ { MAD_F(0x040793c3) /* 0.251849903 */, 17 },
+ /* 2450 */ { MAD_F(0x0408238d) /* 0.251987029 */, 17 },
+ /* 2451 */ { MAD_F(0x0408b35b) /* 0.252124174 */, 17 },
+ /* 2452 */ { MAD_F(0x0409432f) /* 0.252261338 */, 17 },
+ /* 2453 */ { MAD_F(0x0409d308) /* 0.252398520 */, 17 },
+ /* 2454 */ { MAD_F(0x040a62e5) /* 0.252535721 */, 17 },
+ /* 2455 */ { MAD_F(0x040af2c8) /* 0.252672941 */, 17 },
+ /* 2456 */ { MAD_F(0x040b82b0) /* 0.252810180 */, 17 },
+ /* 2457 */ { MAD_F(0x040c129c) /* 0.252947436 */, 17 },
+ /* 2458 */ { MAD_F(0x040ca28e) /* 0.253084712 */, 17 },
+ /* 2459 */ { MAD_F(0x040d3284) /* 0.253222006 */, 17 },
+ /* 2460 */ { MAD_F(0x040dc280) /* 0.253359319 */, 17 },
+ /* 2461 */ { MAD_F(0x040e5281) /* 0.253496651 */, 17 },
+ /* 2462 */ { MAD_F(0x040ee286) /* 0.253634001 */, 17 },
+ /* 2463 */ { MAD_F(0x040f7291) /* 0.253771369 */, 17 },
+
+ /* 2464 */ { MAD_F(0x041002a1) /* 0.253908756 */, 17 },
+ /* 2465 */ { MAD_F(0x041092b5) /* 0.254046162 */, 17 },
+ /* 2466 */ { MAD_F(0x041122cf) /* 0.254183587 */, 17 },
+ /* 2467 */ { MAD_F(0x0411b2ed) /* 0.254321030 */, 17 },
+ /* 2468 */ { MAD_F(0x04124311) /* 0.254458491 */, 17 },
+ /* 2469 */ { MAD_F(0x0412d339) /* 0.254595971 */, 17 },
+ /* 2470 */ { MAD_F(0x04136367) /* 0.254733470 */, 17 },
+ /* 2471 */ { MAD_F(0x0413f399) /* 0.254870987 */, 17 },
+ /* 2472 */ { MAD_F(0x041483d1) /* 0.255008523 */, 17 },
+ /* 2473 */ { MAD_F(0x0415140d) /* 0.255146077 */, 17 },
+ /* 2474 */ { MAD_F(0x0415a44f) /* 0.255283650 */, 17 },
+ /* 2475 */ { MAD_F(0x04163495) /* 0.255421241 */, 17 },
+ /* 2476 */ { MAD_F(0x0416c4e1) /* 0.255558851 */, 17 },
+ /* 2477 */ { MAD_F(0x04175531) /* 0.255696480 */, 17 },
+ /* 2478 */ { MAD_F(0x0417e586) /* 0.255834127 */, 17 },
+ /* 2479 */ { MAD_F(0x041875e1) /* 0.255971792 */, 17 },
+
+ /* 2480 */ { MAD_F(0x04190640) /* 0.256109476 */, 17 },
+ /* 2481 */ { MAD_F(0x041996a4) /* 0.256247179 */, 17 },
+ /* 2482 */ { MAD_F(0x041a270d) /* 0.256384900 */, 17 },
+ /* 2483 */ { MAD_F(0x041ab77b) /* 0.256522639 */, 17 },
+ /* 2484 */ { MAD_F(0x041b47ef) /* 0.256660397 */, 17 },
+ /* 2485 */ { MAD_F(0x041bd867) /* 0.256798174 */, 17 },
+ /* 2486 */ { MAD_F(0x041c68e4) /* 0.256935969 */, 17 },
+ /* 2487 */ { MAD_F(0x041cf966) /* 0.257073782 */, 17 },
+ /* 2488 */ { MAD_F(0x041d89ed) /* 0.257211614 */, 17 },
+ /* 2489 */ { MAD_F(0x041e1a79) /* 0.257349465 */, 17 },
+ /* 2490 */ { MAD_F(0x041eab0a) /* 0.257487334 */, 17 },
+ /* 2491 */ { MAD_F(0x041f3b9f) /* 0.257625221 */, 17 },
+ /* 2492 */ { MAD_F(0x041fcc3a) /* 0.257763127 */, 17 },
+ /* 2493 */ { MAD_F(0x04205cda) /* 0.257901051 */, 17 },
+ /* 2494 */ { MAD_F(0x0420ed7f) /* 0.258038994 */, 17 },
+ /* 2495 */ { MAD_F(0x04217e28) /* 0.258176955 */, 17 },
+
+ /* 2496 */ { MAD_F(0x04220ed7) /* 0.258314934 */, 17 },
+ /* 2497 */ { MAD_F(0x04229f8a) /* 0.258452932 */, 17 },
+ /* 2498 */ { MAD_F(0x04233043) /* 0.258590948 */, 17 },
+ /* 2499 */ { MAD_F(0x0423c100) /* 0.258728983 */, 17 },
+ /* 2500 */ { MAD_F(0x042451c3) /* 0.258867036 */, 17 },
+ /* 2501 */ { MAD_F(0x0424e28a) /* 0.259005108 */, 17 },
+ /* 2502 */ { MAD_F(0x04257356) /* 0.259143198 */, 17 },
+ /* 2503 */ { MAD_F(0x04260428) /* 0.259281307 */, 17 },
+ /* 2504 */ { MAD_F(0x042694fe) /* 0.259419433 */, 17 },
+ /* 2505 */ { MAD_F(0x042725d9) /* 0.259557579 */, 17 },
+ /* 2506 */ { MAD_F(0x0427b6b9) /* 0.259695742 */, 17 },
+ /* 2507 */ { MAD_F(0x0428479e) /* 0.259833924 */, 17 },
+ /* 2508 */ { MAD_F(0x0428d888) /* 0.259972124 */, 17 },
+ /* 2509 */ { MAD_F(0x04296976) /* 0.260110343 */, 17 },
+ /* 2510 */ { MAD_F(0x0429fa6a) /* 0.260248580 */, 17 },
+ /* 2511 */ { MAD_F(0x042a8b63) /* 0.260386836 */, 17 },
+
+ /* 2512 */ { MAD_F(0x042b1c60) /* 0.260525110 */, 17 },
+ /* 2513 */ { MAD_F(0x042bad63) /* 0.260663402 */, 17 },
+ /* 2514 */ { MAD_F(0x042c3e6a) /* 0.260801712 */, 17 },
+ /* 2515 */ { MAD_F(0x042ccf77) /* 0.260940041 */, 17 },
+ /* 2516 */ { MAD_F(0x042d6088) /* 0.261078388 */, 17 },
+ /* 2517 */ { MAD_F(0x042df19e) /* 0.261216754 */, 17 },
+ /* 2518 */ { MAD_F(0x042e82b9) /* 0.261355137 */, 17 },
+ /* 2519 */ { MAD_F(0x042f13d9) /* 0.261493540 */, 17 },
+ /* 2520 */ { MAD_F(0x042fa4fe) /* 0.261631960 */, 17 },
+ /* 2521 */ { MAD_F(0x04303628) /* 0.261770399 */, 17 },
+ /* 2522 */ { MAD_F(0x0430c757) /* 0.261908856 */, 17 },
+ /* 2523 */ { MAD_F(0x0431588b) /* 0.262047331 */, 17 },
+ /* 2524 */ { MAD_F(0x0431e9c3) /* 0.262185825 */, 17 },
+ /* 2525 */ { MAD_F(0x04327b01) /* 0.262324337 */, 17 },
+ /* 2526 */ { MAD_F(0x04330c43) /* 0.262462867 */, 17 },
+ /* 2527 */ { MAD_F(0x04339d8a) /* 0.262601416 */, 17 },
+
+ /* 2528 */ { MAD_F(0x04342ed7) /* 0.262739982 */, 17 },
+ /* 2529 */ { MAD_F(0x0434c028) /* 0.262878568 */, 17 },
+ /* 2530 */ { MAD_F(0x0435517e) /* 0.263017171 */, 17 },
+ /* 2531 */ { MAD_F(0x0435e2d9) /* 0.263155792 */, 17 },
+ /* 2532 */ { MAD_F(0x04367439) /* 0.263294432 */, 17 },
+ /* 2533 */ { MAD_F(0x0437059e) /* 0.263433090 */, 17 },
+ /* 2534 */ { MAD_F(0x04379707) /* 0.263571767 */, 17 },
+ /* 2535 */ { MAD_F(0x04382876) /* 0.263710461 */, 17 },
+ /* 2536 */ { MAD_F(0x0438b9e9) /* 0.263849174 */, 17 },
+ /* 2537 */ { MAD_F(0x04394b61) /* 0.263987905 */, 17 },
+ /* 2538 */ { MAD_F(0x0439dcdf) /* 0.264126655 */, 17 },
+ /* 2539 */ { MAD_F(0x043a6e61) /* 0.264265422 */, 17 },
+ /* 2540 */ { MAD_F(0x043affe8) /* 0.264404208 */, 17 },
+ /* 2541 */ { MAD_F(0x043b9174) /* 0.264543012 */, 17 },
+ /* 2542 */ { MAD_F(0x043c2305) /* 0.264681834 */, 17 },
+ /* 2543 */ { MAD_F(0x043cb49a) /* 0.264820674 */, 17 },
+
+ /* 2544 */ { MAD_F(0x043d4635) /* 0.264959533 */, 17 },
+ /* 2545 */ { MAD_F(0x043dd7d4) /* 0.265098410 */, 17 },
+ /* 2546 */ { MAD_F(0x043e6979) /* 0.265237305 */, 17 },
+ /* 2547 */ { MAD_F(0x043efb22) /* 0.265376218 */, 17 },
+ /* 2548 */ { MAD_F(0x043f8cd0) /* 0.265515149 */, 17 },
+ /* 2549 */ { MAD_F(0x04401e83) /* 0.265654099 */, 17 },
+ /* 2550 */ { MAD_F(0x0440b03b) /* 0.265793066 */, 17 },
+ /* 2551 */ { MAD_F(0x044141f7) /* 0.265932052 */, 17 },
+ /* 2552 */ { MAD_F(0x0441d3b9) /* 0.266071056 */, 17 },
+ /* 2553 */ { MAD_F(0x04426580) /* 0.266210078 */, 17 },
+ /* 2554 */ { MAD_F(0x0442f74b) /* 0.266349119 */, 17 },
+ /* 2555 */ { MAD_F(0x0443891b) /* 0.266488177 */, 17 },
+ /* 2556 */ { MAD_F(0x04441af0) /* 0.266627254 */, 17 },
+ /* 2557 */ { MAD_F(0x0444acca) /* 0.266766349 */, 17 },
+ /* 2558 */ { MAD_F(0x04453ea9) /* 0.266905462 */, 17 },
+ /* 2559 */ { MAD_F(0x0445d08d) /* 0.267044593 */, 17 },
+
+ /* 2560 */ { MAD_F(0x04466275) /* 0.267183742 */, 17 },
+ /* 2561 */ { MAD_F(0x0446f463) /* 0.267322909 */, 17 },
+ /* 2562 */ { MAD_F(0x04478655) /* 0.267462094 */, 17 },
+ /* 2563 */ { MAD_F(0x0448184c) /* 0.267601298 */, 17 },
+ /* 2564 */ { MAD_F(0x0448aa48) /* 0.267740519 */, 17 },
+ /* 2565 */ { MAD_F(0x04493c49) /* 0.267879759 */, 17 },
+ /* 2566 */ { MAD_F(0x0449ce4f) /* 0.268019017 */, 17 },
+ /* 2567 */ { MAD_F(0x044a6059) /* 0.268158293 */, 17 },
+ /* 2568 */ { MAD_F(0x044af269) /* 0.268297587 */, 17 },
+ /* 2569 */ { MAD_F(0x044b847d) /* 0.268436899 */, 17 },
+ /* 2570 */ { MAD_F(0x044c1696) /* 0.268576229 */, 17 },
+ /* 2571 */ { MAD_F(0x044ca8b4) /* 0.268715577 */, 17 },
+ /* 2572 */ { MAD_F(0x044d3ad7) /* 0.268854943 */, 17 },
+ /* 2573 */ { MAD_F(0x044dccff) /* 0.268994328 */, 17 },
+ /* 2574 */ { MAD_F(0x044e5f2b) /* 0.269133730 */, 17 },
+ /* 2575 */ { MAD_F(0x044ef15d) /* 0.269273150 */, 17 },
+
+ /* 2576 */ { MAD_F(0x044f8393) /* 0.269412589 */, 17 },
+ /* 2577 */ { MAD_F(0x045015ce) /* 0.269552045 */, 17 },
+ /* 2578 */ { MAD_F(0x0450a80e) /* 0.269691520 */, 17 },
+ /* 2579 */ { MAD_F(0x04513a53) /* 0.269831013 */, 17 },
+ /* 2580 */ { MAD_F(0x0451cc9c) /* 0.269970523 */, 17 },
+ /* 2581 */ { MAD_F(0x04525eeb) /* 0.270110052 */, 17 },
+ /* 2582 */ { MAD_F(0x0452f13e) /* 0.270249599 */, 17 },
+ /* 2583 */ { MAD_F(0x04538396) /* 0.270389163 */, 17 },
+ /* 2584 */ { MAD_F(0x045415f3) /* 0.270528746 */, 17 },
+ /* 2585 */ { MAD_F(0x0454a855) /* 0.270668347 */, 17 },
+ /* 2586 */ { MAD_F(0x04553abb) /* 0.270807965 */, 17 },
+ /* 2587 */ { MAD_F(0x0455cd27) /* 0.270947602 */, 17 },
+ /* 2588 */ { MAD_F(0x04565f97) /* 0.271087257 */, 17 },
+ /* 2589 */ { MAD_F(0x0456f20c) /* 0.271226930 */, 17 },
+ /* 2590 */ { MAD_F(0x04578486) /* 0.271366620 */, 17 },
+ /* 2591 */ { MAD_F(0x04581705) /* 0.271506329 */, 17 },
+
+ /* 2592 */ { MAD_F(0x0458a989) /* 0.271646056 */, 17 },
+ /* 2593 */ { MAD_F(0x04593c11) /* 0.271785800 */, 17 },
+ /* 2594 */ { MAD_F(0x0459ce9e) /* 0.271925563 */, 17 },
+ /* 2595 */ { MAD_F(0x045a6130) /* 0.272065343 */, 17 },
+ /* 2596 */ { MAD_F(0x045af3c7) /* 0.272205142 */, 17 },
+ /* 2597 */ { MAD_F(0x045b8663) /* 0.272344958 */, 17 },
+ /* 2598 */ { MAD_F(0x045c1903) /* 0.272484793 */, 17 },
+ /* 2599 */ { MAD_F(0x045caba9) /* 0.272624645 */, 17 },
+ /* 2600 */ { MAD_F(0x045d3e53) /* 0.272764515 */, 17 },
+ /* 2601 */ { MAD_F(0x045dd102) /* 0.272904403 */, 17 },
+ /* 2602 */ { MAD_F(0x045e63b6) /* 0.273044310 */, 17 },
+ /* 2603 */ { MAD_F(0x045ef66e) /* 0.273184234 */, 17 },
+ /* 2604 */ { MAD_F(0x045f892b) /* 0.273324176 */, 17 },
+ /* 2605 */ { MAD_F(0x04601bee) /* 0.273464136 */, 17 },
+ /* 2606 */ { MAD_F(0x0460aeb5) /* 0.273604113 */, 17 },
+ /* 2607 */ { MAD_F(0x04614180) /* 0.273744109 */, 17 },
+
+ /* 2608 */ { MAD_F(0x0461d451) /* 0.273884123 */, 17 },
+ /* 2609 */ { MAD_F(0x04626727) /* 0.274024154 */, 17 },
+ /* 2610 */ { MAD_F(0x0462fa01) /* 0.274164204 */, 17 },
+ /* 2611 */ { MAD_F(0x04638ce0) /* 0.274304271 */, 17 },
+ /* 2612 */ { MAD_F(0x04641fc4) /* 0.274444356 */, 17 },
+ /* 2613 */ { MAD_F(0x0464b2ac) /* 0.274584459 */, 17 },
+ /* 2614 */ { MAD_F(0x0465459a) /* 0.274724580 */, 17 },
+ /* 2615 */ { MAD_F(0x0465d88c) /* 0.274864719 */, 17 },
+ /* 2616 */ { MAD_F(0x04666b83) /* 0.275004875 */, 17 },
+ /* 2617 */ { MAD_F(0x0466fe7f) /* 0.275145050 */, 17 },
+ /* 2618 */ { MAD_F(0x0467917f) /* 0.275285242 */, 17 },
+ /* 2619 */ { MAD_F(0x04682485) /* 0.275425452 */, 17 },
+ /* 2620 */ { MAD_F(0x0468b78f) /* 0.275565681 */, 17 },
+ /* 2621 */ { MAD_F(0x04694a9e) /* 0.275705926 */, 17 },
+ /* 2622 */ { MAD_F(0x0469ddb2) /* 0.275846190 */, 17 },
+ /* 2623 */ { MAD_F(0x046a70ca) /* 0.275986472 */, 17 },
+
+ /* 2624 */ { MAD_F(0x046b03e7) /* 0.276126771 */, 17 },
+ /* 2625 */ { MAD_F(0x046b970a) /* 0.276267088 */, 17 },
+ /* 2626 */ { MAD_F(0x046c2a31) /* 0.276407423 */, 17 },
+ /* 2627 */ { MAD_F(0x046cbd5c) /* 0.276547776 */, 17 },
+ /* 2628 */ { MAD_F(0x046d508d) /* 0.276688147 */, 17 },
+ /* 2629 */ { MAD_F(0x046de3c2) /* 0.276828535 */, 17 },
+ /* 2630 */ { MAD_F(0x046e76fc) /* 0.276968942 */, 17 },
+ /* 2631 */ { MAD_F(0x046f0a3b) /* 0.277109366 */, 17 },
+ /* 2632 */ { MAD_F(0x046f9d7e) /* 0.277249808 */, 17 },
+ /* 2633 */ { MAD_F(0x047030c7) /* 0.277390267 */, 17 },
+ /* 2634 */ { MAD_F(0x0470c414) /* 0.277530745 */, 17 },
+ /* 2635 */ { MAD_F(0x04715766) /* 0.277671240 */, 17 },
+ /* 2636 */ { MAD_F(0x0471eabc) /* 0.277811753 */, 17 },
+ /* 2637 */ { MAD_F(0x04727e18) /* 0.277952284 */, 17 },
+ /* 2638 */ { MAD_F(0x04731178) /* 0.278092832 */, 17 },
+ /* 2639 */ { MAD_F(0x0473a4dd) /* 0.278233399 */, 17 },
+
+ /* 2640 */ { MAD_F(0x04743847) /* 0.278373983 */, 17 },
+ /* 2641 */ { MAD_F(0x0474cbb5) /* 0.278514584 */, 17 },
+ /* 2642 */ { MAD_F(0x04755f29) /* 0.278655204 */, 17 },
+ /* 2643 */ { MAD_F(0x0475f2a1) /* 0.278795841 */, 17 },
+ /* 2644 */ { MAD_F(0x0476861d) /* 0.278936496 */, 17 },
+ /* 2645 */ { MAD_F(0x0477199f) /* 0.279077169 */, 17 },
+ /* 2646 */ { MAD_F(0x0477ad25) /* 0.279217860 */, 17 },
+ /* 2647 */ { MAD_F(0x047840b0) /* 0.279358568 */, 17 },
+ /* 2648 */ { MAD_F(0x0478d440) /* 0.279499294 */, 17 },
+ /* 2649 */ { MAD_F(0x047967d5) /* 0.279640037 */, 17 },
+ /* 2650 */ { MAD_F(0x0479fb6e) /* 0.279780799 */, 17 },
+ /* 2651 */ { MAD_F(0x047a8f0c) /* 0.279921578 */, 17 },
+ /* 2652 */ { MAD_F(0x047b22af) /* 0.280062375 */, 17 },
+ /* 2653 */ { MAD_F(0x047bb657) /* 0.280203189 */, 17 },
+ /* 2654 */ { MAD_F(0x047c4a03) /* 0.280344021 */, 17 },
+ /* 2655 */ { MAD_F(0x047cddb4) /* 0.280484871 */, 17 },
+
+ /* 2656 */ { MAD_F(0x047d716a) /* 0.280625739 */, 17 },
+ /* 2657 */ { MAD_F(0x047e0524) /* 0.280766624 */, 17 },
+ /* 2658 */ { MAD_F(0x047e98e4) /* 0.280907527 */, 17 },
+ /* 2659 */ { MAD_F(0x047f2ca8) /* 0.281048447 */, 17 },
+ /* 2660 */ { MAD_F(0x047fc071) /* 0.281189385 */, 17 },
+ /* 2661 */ { MAD_F(0x0480543e) /* 0.281330341 */, 17 },
+ /* 2662 */ { MAD_F(0x0480e811) /* 0.281471315 */, 17 },
+ /* 2663 */ { MAD_F(0x04817be8) /* 0.281612306 */, 17 },
+ /* 2664 */ { MAD_F(0x04820fc3) /* 0.281753315 */, 17 },
+ /* 2665 */ { MAD_F(0x0482a3a4) /* 0.281894341 */, 17 },
+ /* 2666 */ { MAD_F(0x04833789) /* 0.282035386 */, 17 },
+ /* 2667 */ { MAD_F(0x0483cb73) /* 0.282176447 */, 17 },
+ /* 2668 */ { MAD_F(0x04845f62) /* 0.282317527 */, 17 },
+ /* 2669 */ { MAD_F(0x0484f355) /* 0.282458624 */, 17 },
+ /* 2670 */ { MAD_F(0x0485874d) /* 0.282599738 */, 17 },
+ /* 2671 */ { MAD_F(0x04861b4a) /* 0.282740871 */, 17 },
+
+ /* 2672 */ { MAD_F(0x0486af4c) /* 0.282882021 */, 17 },
+ /* 2673 */ { MAD_F(0x04874352) /* 0.283023188 */, 17 },
+ /* 2674 */ { MAD_F(0x0487d75d) /* 0.283164373 */, 17 },
+ /* 2675 */ { MAD_F(0x04886b6d) /* 0.283305576 */, 17 },
+ /* 2676 */ { MAD_F(0x0488ff82) /* 0.283446796 */, 17 },
+ /* 2677 */ { MAD_F(0x0489939b) /* 0.283588034 */, 17 },
+ /* 2678 */ { MAD_F(0x048a27b9) /* 0.283729290 */, 17 },
+ /* 2679 */ { MAD_F(0x048abbdc) /* 0.283870563 */, 17 },
+ /* 2680 */ { MAD_F(0x048b5003) /* 0.284011853 */, 17 },
+ /* 2681 */ { MAD_F(0x048be42f) /* 0.284153161 */, 17 },
+ /* 2682 */ { MAD_F(0x048c7860) /* 0.284294487 */, 17 },
+ /* 2683 */ { MAD_F(0x048d0c96) /* 0.284435831 */, 17 },
+ /* 2684 */ { MAD_F(0x048da0d0) /* 0.284577192 */, 17 },
+ /* 2685 */ { MAD_F(0x048e350f) /* 0.284718570 */, 17 },
+ /* 2686 */ { MAD_F(0x048ec953) /* 0.284859966 */, 17 },
+ /* 2687 */ { MAD_F(0x048f5d9b) /* 0.285001380 */, 17 },
+
+ /* 2688 */ { MAD_F(0x048ff1e8) /* 0.285142811 */, 17 },
+ /* 2689 */ { MAD_F(0x0490863a) /* 0.285284259 */, 17 },
+ /* 2690 */ { MAD_F(0x04911a91) /* 0.285425726 */, 17 },
+ /* 2691 */ { MAD_F(0x0491aeec) /* 0.285567209 */, 17 },
+ /* 2692 */ { MAD_F(0x0492434c) /* 0.285708711 */, 17 },
+ /* 2693 */ { MAD_F(0x0492d7b0) /* 0.285850229 */, 17 },
+ /* 2694 */ { MAD_F(0x04936c1a) /* 0.285991766 */, 17 },
+ /* 2695 */ { MAD_F(0x04940088) /* 0.286133319 */, 17 },
+ /* 2696 */ { MAD_F(0x049494fb) /* 0.286274891 */, 17 },
+ /* 2697 */ { MAD_F(0x04952972) /* 0.286416480 */, 17 },
+ /* 2698 */ { MAD_F(0x0495bdee) /* 0.286558086 */, 17 },
+ /* 2699 */ { MAD_F(0x0496526f) /* 0.286699710 */, 17 },
+ /* 2700 */ { MAD_F(0x0496e6f5) /* 0.286841351 */, 17 },
+ /* 2701 */ { MAD_F(0x04977b7f) /* 0.286983010 */, 17 },
+ /* 2702 */ { MAD_F(0x0498100e) /* 0.287124686 */, 17 },
+ /* 2703 */ { MAD_F(0x0498a4a1) /* 0.287266380 */, 17 },
+
+ /* 2704 */ { MAD_F(0x0499393a) /* 0.287408091 */, 17 },
+ /* 2705 */ { MAD_F(0x0499cdd7) /* 0.287549820 */, 17 },
+ /* 2706 */ { MAD_F(0x049a6278) /* 0.287691566 */, 17 },
+ /* 2707 */ { MAD_F(0x049af71f) /* 0.287833330 */, 17 },
+ /* 2708 */ { MAD_F(0x049b8bca) /* 0.287975111 */, 17 },
+ /* 2709 */ { MAD_F(0x049c207a) /* 0.288116909 */, 17 },
+ /* 2710 */ { MAD_F(0x049cb52e) /* 0.288258725 */, 17 },
+ /* 2711 */ { MAD_F(0x049d49e7) /* 0.288400559 */, 17 },
+ /* 2712 */ { MAD_F(0x049ddea5) /* 0.288542409 */, 17 },
+ /* 2713 */ { MAD_F(0x049e7367) /* 0.288684278 */, 17 },
+ /* 2714 */ { MAD_F(0x049f082f) /* 0.288826163 */, 17 },
+ /* 2715 */ { MAD_F(0x049f9cfa) /* 0.288968067 */, 17 },
+ /* 2716 */ { MAD_F(0x04a031cb) /* 0.289109987 */, 17 },
+ /* 2717 */ { MAD_F(0x04a0c6a0) /* 0.289251925 */, 17 },
+ /* 2718 */ { MAD_F(0x04a15b7a) /* 0.289393881 */, 17 },
+ /* 2719 */ { MAD_F(0x04a1f059) /* 0.289535854 */, 17 },
+
+ /* 2720 */ { MAD_F(0x04a2853c) /* 0.289677844 */, 17 },
+ /* 2721 */ { MAD_F(0x04a31a24) /* 0.289819851 */, 17 },
+ /* 2722 */ { MAD_F(0x04a3af10) /* 0.289961876 */, 17 },
+ /* 2723 */ { MAD_F(0x04a44401) /* 0.290103919 */, 17 },
+ /* 2724 */ { MAD_F(0x04a4d8f7) /* 0.290245979 */, 17 },
+ /* 2725 */ { MAD_F(0x04a56df2) /* 0.290388056 */, 17 },
+ /* 2726 */ { MAD_F(0x04a602f1) /* 0.290530150 */, 17 },
+ /* 2727 */ { MAD_F(0x04a697f5) /* 0.290672262 */, 17 },
+ /* 2728 */ { MAD_F(0x04a72cfe) /* 0.290814392 */, 17 },
+ /* 2729 */ { MAD_F(0x04a7c20b) /* 0.290956538 */, 17 },
+ /* 2730 */ { MAD_F(0x04a8571d) /* 0.291098703 */, 17 },
+ /* 2731 */ { MAD_F(0x04a8ec33) /* 0.291240884 */, 17 },
+ /* 2732 */ { MAD_F(0x04a9814e) /* 0.291383083 */, 17 },
+ /* 2733 */ { MAD_F(0x04aa166e) /* 0.291525299 */, 17 },
+ /* 2734 */ { MAD_F(0x04aaab93) /* 0.291667532 */, 17 },
+ /* 2735 */ { MAD_F(0x04ab40bc) /* 0.291809783 */, 17 },
+
+ /* 2736 */ { MAD_F(0x04abd5ea) /* 0.291952051 */, 17 },
+ /* 2737 */ { MAD_F(0x04ac6b1c) /* 0.292094337 */, 17 },
+ /* 2738 */ { MAD_F(0x04ad0053) /* 0.292236640 */, 17 },
+ /* 2739 */ { MAD_F(0x04ad958f) /* 0.292378960 */, 17 },
+ /* 2740 */ { MAD_F(0x04ae2ad0) /* 0.292521297 */, 17 },
+ /* 2741 */ { MAD_F(0x04aec015) /* 0.292663652 */, 17 },
+ /* 2742 */ { MAD_F(0x04af555e) /* 0.292806024 */, 17 },
+ /* 2743 */ { MAD_F(0x04afeaad) /* 0.292948414 */, 17 },
+ /* 2744 */ { MAD_F(0x04b08000) /* 0.293090820 */, 17 },
+ /* 2745 */ { MAD_F(0x04b11557) /* 0.293233244 */, 17 },
+ /* 2746 */ { MAD_F(0x04b1aab4) /* 0.293375686 */, 17 },
+ /* 2747 */ { MAD_F(0x04b24015) /* 0.293518144 */, 17 },
+ /* 2748 */ { MAD_F(0x04b2d57a) /* 0.293660620 */, 17 },
+ /* 2749 */ { MAD_F(0x04b36ae4) /* 0.293803113 */, 17 },
+ /* 2750 */ { MAD_F(0x04b40053) /* 0.293945624 */, 17 },
+ /* 2751 */ { MAD_F(0x04b495c7) /* 0.294088151 */, 17 },
+
+ /* 2752 */ { MAD_F(0x04b52b3f) /* 0.294230696 */, 17 },
+ /* 2753 */ { MAD_F(0x04b5c0bc) /* 0.294373259 */, 17 },
+ /* 2754 */ { MAD_F(0x04b6563d) /* 0.294515838 */, 17 },
+ /* 2755 */ { MAD_F(0x04b6ebc3) /* 0.294658435 */, 17 },
+ /* 2756 */ { MAD_F(0x04b7814e) /* 0.294801049 */, 17 },
+ /* 2757 */ { MAD_F(0x04b816dd) /* 0.294943680 */, 17 },
+ /* 2758 */ { MAD_F(0x04b8ac71) /* 0.295086329 */, 17 },
+ /* 2759 */ { MAD_F(0x04b9420a) /* 0.295228995 */, 17 },
+ /* 2760 */ { MAD_F(0x04b9d7a7) /* 0.295371678 */, 17 },
+ /* 2761 */ { MAD_F(0x04ba6d49) /* 0.295514378 */, 17 },
+ /* 2762 */ { MAD_F(0x04bb02ef) /* 0.295657095 */, 17 },
+ /* 2763 */ { MAD_F(0x04bb989a) /* 0.295799830 */, 17 },
+ /* 2764 */ { MAD_F(0x04bc2e4a) /* 0.295942582 */, 17 },
+ /* 2765 */ { MAD_F(0x04bcc3fe) /* 0.296085351 */, 17 },
+ /* 2766 */ { MAD_F(0x04bd59b7) /* 0.296228138 */, 17 },
+ /* 2767 */ { MAD_F(0x04bdef74) /* 0.296370941 */, 17 },
+
+ /* 2768 */ { MAD_F(0x04be8537) /* 0.296513762 */, 17 },
+ /* 2769 */ { MAD_F(0x04bf1afd) /* 0.296656600 */, 17 },
+ /* 2770 */ { MAD_F(0x04bfb0c9) /* 0.296799455 */, 17 },
+ /* 2771 */ { MAD_F(0x04c04699) /* 0.296942327 */, 17 },
+ /* 2772 */ { MAD_F(0x04c0dc6d) /* 0.297085217 */, 17 },
+ /* 2773 */ { MAD_F(0x04c17247) /* 0.297228124 */, 17 },
+ /* 2774 */ { MAD_F(0x04c20824) /* 0.297371048 */, 17 },
+ /* 2775 */ { MAD_F(0x04c29e07) /* 0.297513989 */, 17 },
+ /* 2776 */ { MAD_F(0x04c333ee) /* 0.297656947 */, 17 },
+ /* 2777 */ { MAD_F(0x04c3c9da) /* 0.297799922 */, 17 },
+ /* 2778 */ { MAD_F(0x04c45fca) /* 0.297942915 */, 17 },
+ /* 2779 */ { MAD_F(0x04c4f5bf) /* 0.298085925 */, 17 },
+ /* 2780 */ { MAD_F(0x04c58bb8) /* 0.298228951 */, 17 },
+ /* 2781 */ { MAD_F(0x04c621b6) /* 0.298371996 */, 17 },
+ /* 2782 */ { MAD_F(0x04c6b7b9) /* 0.298515057 */, 17 },
+ /* 2783 */ { MAD_F(0x04c74dc0) /* 0.298658135 */, 17 },
+
+ /* 2784 */ { MAD_F(0x04c7e3cc) /* 0.298801231 */, 17 },
+ /* 2785 */ { MAD_F(0x04c879dd) /* 0.298944343 */, 17 },
+ /* 2786 */ { MAD_F(0x04c90ff2) /* 0.299087473 */, 17 },
+ /* 2787 */ { MAD_F(0x04c9a60c) /* 0.299230620 */, 17 },
+ /* 2788 */ { MAD_F(0x04ca3c2a) /* 0.299373784 */, 17 },
+ /* 2789 */ { MAD_F(0x04cad24d) /* 0.299516965 */, 17 },
+ /* 2790 */ { MAD_F(0x04cb6874) /* 0.299660163 */, 17 },
+ /* 2791 */ { MAD_F(0x04cbfea0) /* 0.299803378 */, 17 },
+ /* 2792 */ { MAD_F(0x04cc94d1) /* 0.299946611 */, 17 },
+ /* 2793 */ { MAD_F(0x04cd2b06) /* 0.300089860 */, 17 },
+ /* 2794 */ { MAD_F(0x04cdc140) /* 0.300233127 */, 17 },
+ /* 2795 */ { MAD_F(0x04ce577f) /* 0.300376411 */, 17 },
+ /* 2796 */ { MAD_F(0x04ceedc2) /* 0.300519711 */, 17 },
+ /* 2797 */ { MAD_F(0x04cf8409) /* 0.300663029 */, 17 },
+ /* 2798 */ { MAD_F(0x04d01a55) /* 0.300806364 */, 17 },
+ /* 2799 */ { MAD_F(0x04d0b0a6) /* 0.300949716 */, 17 },
+
+ /* 2800 */ { MAD_F(0x04d146fb) /* 0.301093085 */, 17 },
+ /* 2801 */ { MAD_F(0x04d1dd55) /* 0.301236472 */, 17 },
+ /* 2802 */ { MAD_F(0x04d273b4) /* 0.301379875 */, 17 },
+ /* 2803 */ { MAD_F(0x04d30a17) /* 0.301523295 */, 17 },
+ /* 2804 */ { MAD_F(0x04d3a07f) /* 0.301666733 */, 17 },
+ /* 2805 */ { MAD_F(0x04d436eb) /* 0.301810187 */, 17 },
+ /* 2806 */ { MAD_F(0x04d4cd5c) /* 0.301953659 */, 17 },
+ /* 2807 */ { MAD_F(0x04d563d1) /* 0.302097147 */, 17 },
+ /* 2808 */ { MAD_F(0x04d5fa4b) /* 0.302240653 */, 17 },
+ /* 2809 */ { MAD_F(0x04d690ca) /* 0.302384175 */, 17 },
+ /* 2810 */ { MAD_F(0x04d7274d) /* 0.302527715 */, 17 },
+ /* 2811 */ { MAD_F(0x04d7bdd5) /* 0.302671271 */, 17 },
+ /* 2812 */ { MAD_F(0x04d85461) /* 0.302814845 */, 17 },
+ /* 2813 */ { MAD_F(0x04d8eaf2) /* 0.302958436 */, 17 },
+ /* 2814 */ { MAD_F(0x04d98187) /* 0.303102044 */, 17 },
+ /* 2815 */ { MAD_F(0x04da1821) /* 0.303245668 */, 17 },
+
+ /* 2816 */ { MAD_F(0x04daaec0) /* 0.303389310 */, 17 },
+ /* 2817 */ { MAD_F(0x04db4563) /* 0.303532969 */, 17 },
+ /* 2818 */ { MAD_F(0x04dbdc0a) /* 0.303676645 */, 17 },
+ /* 2819 */ { MAD_F(0x04dc72b7) /* 0.303820337 */, 17 },
+ /* 2820 */ { MAD_F(0x04dd0967) /* 0.303964047 */, 17 },
+ /* 2821 */ { MAD_F(0x04dda01d) /* 0.304107774 */, 17 },
+ /* 2822 */ { MAD_F(0x04de36d7) /* 0.304251517 */, 17 },
+ /* 2823 */ { MAD_F(0x04decd95) /* 0.304395278 */, 17 },
+ /* 2824 */ { MAD_F(0x04df6458) /* 0.304539056 */, 17 },
+ /* 2825 */ { MAD_F(0x04dffb20) /* 0.304682850 */, 17 },
+ /* 2826 */ { MAD_F(0x04e091ec) /* 0.304826662 */, 17 },
+ /* 2827 */ { MAD_F(0x04e128bc) /* 0.304970491 */, 17 },
+ /* 2828 */ { MAD_F(0x04e1bf92) /* 0.305114336 */, 17 },
+ /* 2829 */ { MAD_F(0x04e2566b) /* 0.305258199 */, 17 },
+ /* 2830 */ { MAD_F(0x04e2ed4a) /* 0.305402078 */, 17 },
+ /* 2831 */ { MAD_F(0x04e3842d) /* 0.305545974 */, 17 },
+
+ /* 2832 */ { MAD_F(0x04e41b14) /* 0.305689888 */, 17 },
+ /* 2833 */ { MAD_F(0x04e4b200) /* 0.305833818 */, 17 },
+ /* 2834 */ { MAD_F(0x04e548f1) /* 0.305977765 */, 17 },
+ /* 2835 */ { MAD_F(0x04e5dfe6) /* 0.306121729 */, 17 },
+ /* 2836 */ { MAD_F(0x04e676df) /* 0.306265710 */, 17 },
+ /* 2837 */ { MAD_F(0x04e70dde) /* 0.306409708 */, 17 },
+ /* 2838 */ { MAD_F(0x04e7a4e0) /* 0.306553723 */, 17 },
+ /* 2839 */ { MAD_F(0x04e83be7) /* 0.306697755 */, 17 },
+ /* 2840 */ { MAD_F(0x04e8d2f3) /* 0.306841804 */, 17 },
+ /* 2841 */ { MAD_F(0x04e96a04) /* 0.306985869 */, 17 },
+ /* 2842 */ { MAD_F(0x04ea0118) /* 0.307129952 */, 17 },
+ /* 2843 */ { MAD_F(0x04ea9832) /* 0.307274051 */, 17 },
+ /* 2844 */ { MAD_F(0x04eb2f50) /* 0.307418168 */, 17 },
+ /* 2845 */ { MAD_F(0x04ebc672) /* 0.307562301 */, 17 },
+ /* 2846 */ { MAD_F(0x04ec5d99) /* 0.307706451 */, 17 },
+ /* 2847 */ { MAD_F(0x04ecf4c5) /* 0.307850618 */, 17 },
+
+ /* 2848 */ { MAD_F(0x04ed8bf5) /* 0.307994802 */, 17 },
+ /* 2849 */ { MAD_F(0x04ee2329) /* 0.308139003 */, 17 },
+ /* 2850 */ { MAD_F(0x04eeba63) /* 0.308283220 */, 17 },
+ /* 2851 */ { MAD_F(0x04ef51a0) /* 0.308427455 */, 17 },
+ /* 2852 */ { MAD_F(0x04efe8e2) /* 0.308571706 */, 17 },
+ /* 2853 */ { MAD_F(0x04f08029) /* 0.308715974 */, 17 },
+ /* 2854 */ { MAD_F(0x04f11774) /* 0.308860260 */, 17 },
+ /* 2855 */ { MAD_F(0x04f1aec4) /* 0.309004561 */, 17 },
+ /* 2856 */ { MAD_F(0x04f24618) /* 0.309148880 */, 17 },
+ /* 2857 */ { MAD_F(0x04f2dd71) /* 0.309293216 */, 17 },
+ /* 2858 */ { MAD_F(0x04f374cf) /* 0.309437568 */, 17 },
+ /* 2859 */ { MAD_F(0x04f40c30) /* 0.309581938 */, 17 },
+ /* 2860 */ { MAD_F(0x04f4a397) /* 0.309726324 */, 17 },
+ /* 2861 */ { MAD_F(0x04f53b02) /* 0.309870727 */, 17 },
+ /* 2862 */ { MAD_F(0x04f5d271) /* 0.310015147 */, 17 },
+ /* 2863 */ { MAD_F(0x04f669e5) /* 0.310159583 */, 17 },
+
+ /* 2864 */ { MAD_F(0x04f7015d) /* 0.310304037 */, 17 },
+ /* 2865 */ { MAD_F(0x04f798da) /* 0.310448507 */, 17 },
+ /* 2866 */ { MAD_F(0x04f8305c) /* 0.310592994 */, 17 },
+ /* 2867 */ { MAD_F(0x04f8c7e2) /* 0.310737498 */, 17 },
+ /* 2868 */ { MAD_F(0x04f95f6c) /* 0.310882018 */, 17 },
+ /* 2869 */ { MAD_F(0x04f9f6fb) /* 0.311026556 */, 17 },
+ /* 2870 */ { MAD_F(0x04fa8e8f) /* 0.311171110 */, 17 },
+ /* 2871 */ { MAD_F(0x04fb2627) /* 0.311315681 */, 17 },
+ /* 2872 */ { MAD_F(0x04fbbdc3) /* 0.311460269 */, 17 },
+ /* 2873 */ { MAD_F(0x04fc5564) /* 0.311604874 */, 17 },
+ /* 2874 */ { MAD_F(0x04fced0a) /* 0.311749495 */, 17 },
+ /* 2875 */ { MAD_F(0x04fd84b4) /* 0.311894133 */, 17 },
+ /* 2876 */ { MAD_F(0x04fe1c62) /* 0.312038788 */, 17 },
+ /* 2877 */ { MAD_F(0x04feb415) /* 0.312183460 */, 17 },
+ /* 2878 */ { MAD_F(0x04ff4bcd) /* 0.312328148 */, 17 },
+ /* 2879 */ { MAD_F(0x04ffe389) /* 0.312472854 */, 17 },
+
+ /* 2880 */ { MAD_F(0x05007b49) /* 0.312617576 */, 17 },
+ /* 2881 */ { MAD_F(0x0501130e) /* 0.312762314 */, 17 },
+ /* 2882 */ { MAD_F(0x0501aad8) /* 0.312907070 */, 17 },
+ /* 2883 */ { MAD_F(0x050242a6) /* 0.313051842 */, 17 },
+ /* 2884 */ { MAD_F(0x0502da78) /* 0.313196631 */, 17 },
+ /* 2885 */ { MAD_F(0x0503724f) /* 0.313341437 */, 17 },
+ /* 2886 */ { MAD_F(0x05040a2b) /* 0.313486259 */, 17 },
+ /* 2887 */ { MAD_F(0x0504a20b) /* 0.313631098 */, 17 },
+ /* 2888 */ { MAD_F(0x050539ef) /* 0.313775954 */, 17 },
+ /* 2889 */ { MAD_F(0x0505d1d8) /* 0.313920827 */, 17 },
+ /* 2890 */ { MAD_F(0x050669c5) /* 0.314065716 */, 17 },
+ /* 2891 */ { MAD_F(0x050701b7) /* 0.314210622 */, 17 },
+ /* 2892 */ { MAD_F(0x050799ae) /* 0.314355545 */, 17 },
+ /* 2893 */ { MAD_F(0x050831a9) /* 0.314500484 */, 17 },
+ /* 2894 */ { MAD_F(0x0508c9a8) /* 0.314645440 */, 17 },
+ /* 2895 */ { MAD_F(0x050961ac) /* 0.314790413 */, 17 },
+
+ /* 2896 */ { MAD_F(0x0509f9b4) /* 0.314935403 */, 17 },
+ /* 2897 */ { MAD_F(0x050a91c1) /* 0.315080409 */, 17 },
+ /* 2898 */ { MAD_F(0x050b29d2) /* 0.315225432 */, 17 },
+ /* 2899 */ { MAD_F(0x050bc1e8) /* 0.315370472 */, 17 },
+ /* 2900 */ { MAD_F(0x050c5a02) /* 0.315515528 */, 17 },
+ /* 2901 */ { MAD_F(0x050cf221) /* 0.315660601 */, 17 },
+ /* 2902 */ { MAD_F(0x050d8a44) /* 0.315805690 */, 17 },
+ /* 2903 */ { MAD_F(0x050e226c) /* 0.315950797 */, 17 },
+ /* 2904 */ { MAD_F(0x050eba98) /* 0.316095920 */, 17 },
+ /* 2905 */ { MAD_F(0x050f52c9) /* 0.316241059 */, 17 },
+ /* 2906 */ { MAD_F(0x050feafe) /* 0.316386216 */, 17 },
+ /* 2907 */ { MAD_F(0x05108337) /* 0.316531388 */, 17 },
+ /* 2908 */ { MAD_F(0x05111b75) /* 0.316676578 */, 17 },
+ /* 2909 */ { MAD_F(0x0511b3b8) /* 0.316821784 */, 17 },
+ /* 2910 */ { MAD_F(0x05124bff) /* 0.316967007 */, 17 },
+ /* 2911 */ { MAD_F(0x0512e44a) /* 0.317112247 */, 17 },
+
+ /* 2912 */ { MAD_F(0x05137c9a) /* 0.317257503 */, 17 },
+ /* 2913 */ { MAD_F(0x051414ee) /* 0.317402775 */, 17 },
+ /* 2914 */ { MAD_F(0x0514ad47) /* 0.317548065 */, 17 },
+ /* 2915 */ { MAD_F(0x051545a5) /* 0.317693371 */, 17 },
+ /* 2916 */ { MAD_F(0x0515de06) /* 0.317838693 */, 17 },
+ /* 2917 */ { MAD_F(0x0516766d) /* 0.317984033 */, 17 },
+ /* 2918 */ { MAD_F(0x05170ed7) /* 0.318129388 */, 17 },
+ /* 2919 */ { MAD_F(0x0517a746) /* 0.318274761 */, 17 },
+ /* 2920 */ { MAD_F(0x05183fba) /* 0.318420150 */, 17 },
+ /* 2921 */ { MAD_F(0x0518d832) /* 0.318565555 */, 17 },
+ /* 2922 */ { MAD_F(0x051970ae) /* 0.318710978 */, 17 },
+ /* 2923 */ { MAD_F(0x051a092f) /* 0.318856416 */, 17 },
+ /* 2924 */ { MAD_F(0x051aa1b5) /* 0.319001872 */, 17 },
+ /* 2925 */ { MAD_F(0x051b3a3f) /* 0.319147344 */, 17 },
+ /* 2926 */ { MAD_F(0x051bd2cd) /* 0.319292832 */, 17 },
+ /* 2927 */ { MAD_F(0x051c6b60) /* 0.319438338 */, 17 },
+
+ /* 2928 */ { MAD_F(0x051d03f7) /* 0.319583859 */, 17 },
+ /* 2929 */ { MAD_F(0x051d9c92) /* 0.319729398 */, 17 },
+ /* 2930 */ { MAD_F(0x051e3532) /* 0.319874952 */, 17 },
+ /* 2931 */ { MAD_F(0x051ecdd7) /* 0.320020524 */, 17 },
+ /* 2932 */ { MAD_F(0x051f6680) /* 0.320166112 */, 17 },
+ /* 2933 */ { MAD_F(0x051fff2d) /* 0.320311716 */, 17 },
+ /* 2934 */ { MAD_F(0x052097df) /* 0.320457337 */, 17 },
+ /* 2935 */ { MAD_F(0x05213095) /* 0.320602975 */, 17 },
+ /* 2936 */ { MAD_F(0x0521c950) /* 0.320748629 */, 17 },
+ /* 2937 */ { MAD_F(0x0522620f) /* 0.320894300 */, 17 },
+ /* 2938 */ { MAD_F(0x0522fad3) /* 0.321039987 */, 17 },
+ /* 2939 */ { MAD_F(0x0523939b) /* 0.321185691 */, 17 },
+ /* 2940 */ { MAD_F(0x05242c68) /* 0.321331411 */, 17 },
+ /* 2941 */ { MAD_F(0x0524c538) /* 0.321477148 */, 17 },
+ /* 2942 */ { MAD_F(0x05255e0e) /* 0.321622901 */, 17 },
+ /* 2943 */ { MAD_F(0x0525f6e8) /* 0.321768671 */, 17 },
+
+ /* 2944 */ { MAD_F(0x05268fc6) /* 0.321914457 */, 17 },
+ /* 2945 */ { MAD_F(0x052728a9) /* 0.322060260 */, 17 },
+ /* 2946 */ { MAD_F(0x0527c190) /* 0.322206079 */, 17 },
+ /* 2947 */ { MAD_F(0x05285a7b) /* 0.322351915 */, 17 },
+ /* 2948 */ { MAD_F(0x0528f36b) /* 0.322497768 */, 17 },
+ /* 2949 */ { MAD_F(0x05298c5f) /* 0.322643636 */, 17 },
+ /* 2950 */ { MAD_F(0x052a2558) /* 0.322789522 */, 17 },
+ /* 2951 */ { MAD_F(0x052abe55) /* 0.322935424 */, 17 },
+ /* 2952 */ { MAD_F(0x052b5757) /* 0.323081342 */, 17 },
+ /* 2953 */ { MAD_F(0x052bf05d) /* 0.323227277 */, 17 },
+ /* 2954 */ { MAD_F(0x052c8968) /* 0.323373228 */, 17 },
+ /* 2955 */ { MAD_F(0x052d2277) /* 0.323519196 */, 17 },
+ /* 2956 */ { MAD_F(0x052dbb8a) /* 0.323665180 */, 17 },
+ /* 2957 */ { MAD_F(0x052e54a2) /* 0.323811180 */, 17 },
+ /* 2958 */ { MAD_F(0x052eedbe) /* 0.323957197 */, 17 },
+ /* 2959 */ { MAD_F(0x052f86de) /* 0.324103231 */, 17 },
+
+ /* 2960 */ { MAD_F(0x05302003) /* 0.324249281 */, 17 },
+ /* 2961 */ { MAD_F(0x0530b92d) /* 0.324395347 */, 17 },
+ /* 2962 */ { MAD_F(0x0531525b) /* 0.324541430 */, 17 },
+ /* 2963 */ { MAD_F(0x0531eb8d) /* 0.324687530 */, 17 },
+ /* 2964 */ { MAD_F(0x053284c4) /* 0.324833646 */, 17 },
+ /* 2965 */ { MAD_F(0x05331dff) /* 0.324979778 */, 17 },
+ /* 2966 */ { MAD_F(0x0533b73e) /* 0.325125926 */, 17 },
+ /* 2967 */ { MAD_F(0x05345082) /* 0.325272091 */, 17 },
+ /* 2968 */ { MAD_F(0x0534e9ca) /* 0.325418273 */, 17 },
+ /* 2969 */ { MAD_F(0x05358317) /* 0.325564471 */, 17 },
+ /* 2970 */ { MAD_F(0x05361c68) /* 0.325710685 */, 17 },
+ /* 2971 */ { MAD_F(0x0536b5be) /* 0.325856916 */, 17 },
+ /* 2972 */ { MAD_F(0x05374f17) /* 0.326003163 */, 17 },
+ /* 2973 */ { MAD_F(0x0537e876) /* 0.326149427 */, 17 },
+ /* 2974 */ { MAD_F(0x053881d9) /* 0.326295707 */, 17 },
+ /* 2975 */ { MAD_F(0x05391b40) /* 0.326442003 */, 17 },
+
+ /* 2976 */ { MAD_F(0x0539b4ab) /* 0.326588316 */, 17 },
+ /* 2977 */ { MAD_F(0x053a4e1b) /* 0.326734645 */, 17 },
+ /* 2978 */ { MAD_F(0x053ae78f) /* 0.326880990 */, 17 },
+ /* 2979 */ { MAD_F(0x053b8108) /* 0.327027352 */, 17 },
+ /* 2980 */ { MAD_F(0x053c1a85) /* 0.327173730 */, 17 },
+ /* 2981 */ { MAD_F(0x053cb407) /* 0.327320125 */, 17 },
+ /* 2982 */ { MAD_F(0x053d4d8d) /* 0.327466536 */, 17 },
+ /* 2983 */ { MAD_F(0x053de717) /* 0.327612963 */, 17 },
+ /* 2984 */ { MAD_F(0x053e80a6) /* 0.327759407 */, 17 },
+ /* 2985 */ { MAD_F(0x053f1a39) /* 0.327905867 */, 17 },
+ /* 2986 */ { MAD_F(0x053fb3d0) /* 0.328052344 */, 17 },
+ /* 2987 */ { MAD_F(0x05404d6c) /* 0.328198837 */, 17 },
+ /* 2988 */ { MAD_F(0x0540e70c) /* 0.328345346 */, 17 },
+ /* 2989 */ { MAD_F(0x054180b1) /* 0.328491871 */, 17 },
+ /* 2990 */ { MAD_F(0x05421a5a) /* 0.328638413 */, 17 },
+ /* 2991 */ { MAD_F(0x0542b407) /* 0.328784971 */, 17 },
+
+ /* 2992 */ { MAD_F(0x05434db9) /* 0.328931546 */, 17 },
+ /* 2993 */ { MAD_F(0x0543e76f) /* 0.329078137 */, 17 },
+ /* 2994 */ { MAD_F(0x0544812a) /* 0.329224744 */, 17 },
+ /* 2995 */ { MAD_F(0x05451ae9) /* 0.329371367 */, 17 },
+ /* 2996 */ { MAD_F(0x0545b4ac) /* 0.329518007 */, 17 },
+ /* 2997 */ { MAD_F(0x05464e74) /* 0.329664663 */, 17 },
+ /* 2998 */ { MAD_F(0x0546e840) /* 0.329811336 */, 17 },
+ /* 2999 */ { MAD_F(0x05478211) /* 0.329958024 */, 17 },
+ /* 3000 */ { MAD_F(0x05481be5) /* 0.330104730 */, 17 },
+ /* 3001 */ { MAD_F(0x0548b5bf) /* 0.330251451 */, 17 },
+ /* 3002 */ { MAD_F(0x05494f9c) /* 0.330398189 */, 17 },
+ /* 3003 */ { MAD_F(0x0549e97e) /* 0.330544943 */, 17 },
+ /* 3004 */ { MAD_F(0x054a8364) /* 0.330691713 */, 17 },
+ /* 3005 */ { MAD_F(0x054b1d4f) /* 0.330838499 */, 17 },
+ /* 3006 */ { MAD_F(0x054bb73e) /* 0.330985302 */, 17 },
+ /* 3007 */ { MAD_F(0x054c5132) /* 0.331132121 */, 17 },
+
+ /* 3008 */ { MAD_F(0x054ceb2a) /* 0.331278957 */, 17 },
+ /* 3009 */ { MAD_F(0x054d8526) /* 0.331425808 */, 17 },
+ /* 3010 */ { MAD_F(0x054e1f26) /* 0.331572676 */, 17 },
+ /* 3011 */ { MAD_F(0x054eb92b) /* 0.331719560 */, 17 },
+ /* 3012 */ { MAD_F(0x054f5334) /* 0.331866461 */, 17 },
+ /* 3013 */ { MAD_F(0x054fed42) /* 0.332013377 */, 17 },
+ /* 3014 */ { MAD_F(0x05508754) /* 0.332160310 */, 17 },
+ /* 3015 */ { MAD_F(0x0551216b) /* 0.332307260 */, 17 },
+ /* 3016 */ { MAD_F(0x0551bb85) /* 0.332454225 */, 17 },
+ /* 3017 */ { MAD_F(0x055255a4) /* 0.332601207 */, 17 },
+ /* 3018 */ { MAD_F(0x0552efc8) /* 0.332748205 */, 17 },
+ /* 3019 */ { MAD_F(0x055389f0) /* 0.332895219 */, 17 },
+ /* 3020 */ { MAD_F(0x0554241c) /* 0.333042249 */, 17 },
+ /* 3021 */ { MAD_F(0x0554be4c) /* 0.333189296 */, 17 },
+ /* 3022 */ { MAD_F(0x05555881) /* 0.333336359 */, 17 },
+ /* 3023 */ { MAD_F(0x0555f2ba) /* 0.333483438 */, 17 },
+
+ /* 3024 */ { MAD_F(0x05568cf8) /* 0.333630533 */, 17 },
+ /* 3025 */ { MAD_F(0x0557273a) /* 0.333777645 */, 17 },
+ /* 3026 */ { MAD_F(0x0557c180) /* 0.333924772 */, 17 },
+ /* 3027 */ { MAD_F(0x05585bcb) /* 0.334071916 */, 17 },
+ /* 3028 */ { MAD_F(0x0558f61a) /* 0.334219076 */, 17 },
+ /* 3029 */ { MAD_F(0x0559906d) /* 0.334366253 */, 17 },
+ /* 3030 */ { MAD_F(0x055a2ac5) /* 0.334513445 */, 17 },
+ /* 3031 */ { MAD_F(0x055ac521) /* 0.334660654 */, 17 },
+ /* 3032 */ { MAD_F(0x055b5f81) /* 0.334807879 */, 17 },
+ /* 3033 */ { MAD_F(0x055bf9e6) /* 0.334955120 */, 17 },
+ /* 3034 */ { MAD_F(0x055c944f) /* 0.335102377 */, 17 },
+ /* 3035 */ { MAD_F(0x055d2ebd) /* 0.335249651 */, 17 },
+ /* 3036 */ { MAD_F(0x055dc92e) /* 0.335396941 */, 17 },
+ /* 3037 */ { MAD_F(0x055e63a5) /* 0.335544246 */, 17 },
+ /* 3038 */ { MAD_F(0x055efe1f) /* 0.335691568 */, 17 },
+ /* 3039 */ { MAD_F(0x055f989e) /* 0.335838906 */, 17 },
+
+ /* 3040 */ { MAD_F(0x05603321) /* 0.335986261 */, 17 },
+ /* 3041 */ { MAD_F(0x0560cda8) /* 0.336133631 */, 17 },
+ /* 3042 */ { MAD_F(0x05616834) /* 0.336281018 */, 17 },
+ /* 3043 */ { MAD_F(0x056202c4) /* 0.336428421 */, 17 },
+ /* 3044 */ { MAD_F(0x05629d59) /* 0.336575840 */, 17 },
+ /* 3045 */ { MAD_F(0x056337f2) /* 0.336723275 */, 17 },
+ /* 3046 */ { MAD_F(0x0563d28f) /* 0.336870726 */, 17 },
+ /* 3047 */ { MAD_F(0x05646d30) /* 0.337018193 */, 17 },
+ /* 3048 */ { MAD_F(0x056507d6) /* 0.337165677 */, 17 },
+ /* 3049 */ { MAD_F(0x0565a280) /* 0.337313176 */, 17 },
+ /* 3050 */ { MAD_F(0x05663d2f) /* 0.337460692 */, 17 },
+ /* 3051 */ { MAD_F(0x0566d7e1) /* 0.337608224 */, 17 },
+ /* 3052 */ { MAD_F(0x05677298) /* 0.337755772 */, 17 },
+ /* 3053 */ { MAD_F(0x05680d54) /* 0.337903336 */, 17 },
+ /* 3054 */ { MAD_F(0x0568a814) /* 0.338050916 */, 17 },
+ /* 3055 */ { MAD_F(0x056942d8) /* 0.338198513 */, 17 },
+
+ /* 3056 */ { MAD_F(0x0569dda0) /* 0.338346125 */, 17 },
+ /* 3057 */ { MAD_F(0x056a786d) /* 0.338493753 */, 17 },
+ /* 3058 */ { MAD_F(0x056b133e) /* 0.338641398 */, 17 },
+ /* 3059 */ { MAD_F(0x056bae13) /* 0.338789059 */, 17 },
+ /* 3060 */ { MAD_F(0x056c48ed) /* 0.338936736 */, 17 },
+ /* 3061 */ { MAD_F(0x056ce3cb) /* 0.339084429 */, 17 },
+ /* 3062 */ { MAD_F(0x056d7ead) /* 0.339232138 */, 17 },
+ /* 3063 */ { MAD_F(0x056e1994) /* 0.339379863 */, 17 },
+ /* 3064 */ { MAD_F(0x056eb47f) /* 0.339527604 */, 17 },
+ /* 3065 */ { MAD_F(0x056f4f6e) /* 0.339675361 */, 17 },
+ /* 3066 */ { MAD_F(0x056fea62) /* 0.339823134 */, 17 },
+ /* 3067 */ { MAD_F(0x0570855a) /* 0.339970924 */, 17 },
+ /* 3068 */ { MAD_F(0x05712056) /* 0.340118729 */, 17 },
+ /* 3069 */ { MAD_F(0x0571bb56) /* 0.340266550 */, 17 },
+ /* 3070 */ { MAD_F(0x0572565b) /* 0.340414388 */, 17 },
+ /* 3071 */ { MAD_F(0x0572f164) /* 0.340562242 */, 17 },
+
+ /* 3072 */ { MAD_F(0x05738c72) /* 0.340710111 */, 17 },
+ /* 3073 */ { MAD_F(0x05742784) /* 0.340857997 */, 17 },
+ /* 3074 */ { MAD_F(0x0574c29a) /* 0.341005899 */, 17 },
+ /* 3075 */ { MAD_F(0x05755db4) /* 0.341153816 */, 17 },
+ /* 3076 */ { MAD_F(0x0575f8d3) /* 0.341301750 */, 17 },
+ /* 3077 */ { MAD_F(0x057693f6) /* 0.341449700 */, 17 },
+ /* 3078 */ { MAD_F(0x05772f1d) /* 0.341597666 */, 17 },
+ /* 3079 */ { MAD_F(0x0577ca49) /* 0.341745648 */, 17 },
+ /* 3080 */ { MAD_F(0x05786578) /* 0.341893646 */, 17 },
+ /* 3081 */ { MAD_F(0x057900ad) /* 0.342041659 */, 17 },
+ /* 3082 */ { MAD_F(0x05799be5) /* 0.342189689 */, 17 },
+ /* 3083 */ { MAD_F(0x057a3722) /* 0.342337735 */, 17 },
+ /* 3084 */ { MAD_F(0x057ad263) /* 0.342485797 */, 17 },
+ /* 3085 */ { MAD_F(0x057b6da8) /* 0.342633875 */, 17 },
+ /* 3086 */ { MAD_F(0x057c08f2) /* 0.342781969 */, 17 },
+ /* 3087 */ { MAD_F(0x057ca440) /* 0.342930079 */, 17 },
+
+ /* 3088 */ { MAD_F(0x057d3f92) /* 0.343078205 */, 17 },
+ /* 3089 */ { MAD_F(0x057ddae9) /* 0.343226347 */, 17 },
+ /* 3090 */ { MAD_F(0x057e7644) /* 0.343374505 */, 17 },
+ /* 3091 */ { MAD_F(0x057f11a3) /* 0.343522679 */, 17 },
+ /* 3092 */ { MAD_F(0x057fad06) /* 0.343670869 */, 17 },
+ /* 3093 */ { MAD_F(0x0580486e) /* 0.343819075 */, 17 },
+ /* 3094 */ { MAD_F(0x0580e3da) /* 0.343967296 */, 17 },
+ /* 3095 */ { MAD_F(0x05817f4a) /* 0.344115534 */, 17 },
+ /* 3096 */ { MAD_F(0x05821abf) /* 0.344263788 */, 17 },
+ /* 3097 */ { MAD_F(0x0582b638) /* 0.344412058 */, 17 },
+ /* 3098 */ { MAD_F(0x058351b5) /* 0.344560343 */, 17 },
+ /* 3099 */ { MAD_F(0x0583ed36) /* 0.344708645 */, 17 },
+ /* 3100 */ { MAD_F(0x058488bc) /* 0.344856963 */, 17 },
+ /* 3101 */ { MAD_F(0x05852446) /* 0.345005296 */, 17 },
+ /* 3102 */ { MAD_F(0x0585bfd4) /* 0.345153646 */, 17 },
+ /* 3103 */ { MAD_F(0x05865b67) /* 0.345302011 */, 17 },
+
+ /* 3104 */ { MAD_F(0x0586f6fd) /* 0.345450393 */, 17 },
+ /* 3105 */ { MAD_F(0x05879298) /* 0.345598790 */, 17 },
+ /* 3106 */ { MAD_F(0x05882e38) /* 0.345747203 */, 17 },
+ /* 3107 */ { MAD_F(0x0588c9dc) /* 0.345895632 */, 17 },
+ /* 3108 */ { MAD_F(0x05896583) /* 0.346044077 */, 17 },
+ /* 3109 */ { MAD_F(0x058a0130) /* 0.346192538 */, 17 },
+ /* 3110 */ { MAD_F(0x058a9ce0) /* 0.346341015 */, 17 },
+ /* 3111 */ { MAD_F(0x058b3895) /* 0.346489508 */, 17 },
+ /* 3112 */ { MAD_F(0x058bd44e) /* 0.346638017 */, 17 },
+ /* 3113 */ { MAD_F(0x058c700b) /* 0.346786542 */, 17 },
+ /* 3114 */ { MAD_F(0x058d0bcd) /* 0.346935082 */, 17 },
+ /* 3115 */ { MAD_F(0x058da793) /* 0.347083639 */, 17 },
+ /* 3116 */ { MAD_F(0x058e435d) /* 0.347232211 */, 17 },
+ /* 3117 */ { MAD_F(0x058edf2b) /* 0.347380799 */, 17 },
+ /* 3118 */ { MAD_F(0x058f7afe) /* 0.347529403 */, 17 },
+ /* 3119 */ { MAD_F(0x059016d5) /* 0.347678023 */, 17 },
+
+ /* 3120 */ { MAD_F(0x0590b2b0) /* 0.347826659 */, 17 },
+ /* 3121 */ { MAD_F(0x05914e8f) /* 0.347975311 */, 17 },
+ /* 3122 */ { MAD_F(0x0591ea73) /* 0.348123979 */, 17 },
+ /* 3123 */ { MAD_F(0x0592865b) /* 0.348272662 */, 17 },
+ /* 3124 */ { MAD_F(0x05932247) /* 0.348421362 */, 17 },
+ /* 3125 */ { MAD_F(0x0593be37) /* 0.348570077 */, 17 },
+ /* 3126 */ { MAD_F(0x05945a2c) /* 0.348718808 */, 17 },
+ /* 3127 */ { MAD_F(0x0594f625) /* 0.348867555 */, 17 },
+ /* 3128 */ { MAD_F(0x05959222) /* 0.349016318 */, 17 },
+ /* 3129 */ { MAD_F(0x05962e24) /* 0.349165097 */, 17 },
+ /* 3130 */ { MAD_F(0x0596ca2a) /* 0.349313892 */, 17 },
+ /* 3131 */ { MAD_F(0x05976634) /* 0.349462702 */, 17 },
+ /* 3132 */ { MAD_F(0x05980242) /* 0.349611528 */, 17 },
+ /* 3133 */ { MAD_F(0x05989e54) /* 0.349760370 */, 17 },
+ /* 3134 */ { MAD_F(0x05993a6b) /* 0.349909228 */, 17 },
+ /* 3135 */ { MAD_F(0x0599d686) /* 0.350058102 */, 17 },
+
+ /* 3136 */ { MAD_F(0x059a72a5) /* 0.350206992 */, 17 },
+ /* 3137 */ { MAD_F(0x059b0ec9) /* 0.350355897 */, 17 },
+ /* 3138 */ { MAD_F(0x059baaf1) /* 0.350504818 */, 17 },
+ /* 3139 */ { MAD_F(0x059c471d) /* 0.350653756 */, 17 },
+ /* 3140 */ { MAD_F(0x059ce34d) /* 0.350802708 */, 17 },
+ /* 3141 */ { MAD_F(0x059d7f81) /* 0.350951677 */, 17 },
+ /* 3142 */ { MAD_F(0x059e1bba) /* 0.351100662 */, 17 },
+ /* 3143 */ { MAD_F(0x059eb7f7) /* 0.351249662 */, 17 },
+ /* 3144 */ { MAD_F(0x059f5438) /* 0.351398678 */, 17 },
+ /* 3145 */ { MAD_F(0x059ff07e) /* 0.351547710 */, 17 },
+ /* 3146 */ { MAD_F(0x05a08cc7) /* 0.351696758 */, 17 },
+ /* 3147 */ { MAD_F(0x05a12915) /* 0.351845821 */, 17 },
+ /* 3148 */ { MAD_F(0x05a1c567) /* 0.351994901 */, 17 },
+ /* 3149 */ { MAD_F(0x05a261be) /* 0.352143996 */, 17 },
+ /* 3150 */ { MAD_F(0x05a2fe18) /* 0.352293107 */, 17 },
+ /* 3151 */ { MAD_F(0x05a39a77) /* 0.352442233 */, 17 },
+
+ /* 3152 */ { MAD_F(0x05a436da) /* 0.352591376 */, 17 },
+ /* 3153 */ { MAD_F(0x05a4d342) /* 0.352740534 */, 17 },
+ /* 3154 */ { MAD_F(0x05a56fad) /* 0.352889708 */, 17 },
+ /* 3155 */ { MAD_F(0x05a60c1d) /* 0.353038898 */, 17 },
+ /* 3156 */ { MAD_F(0x05a6a891) /* 0.353188103 */, 17 },
+ /* 3157 */ { MAD_F(0x05a7450a) /* 0.353337325 */, 17 },
+ /* 3158 */ { MAD_F(0x05a7e186) /* 0.353486562 */, 17 },
+ /* 3159 */ { MAD_F(0x05a87e07) /* 0.353635814 */, 17 },
+ /* 3160 */ { MAD_F(0x05a91a8c) /* 0.353785083 */, 17 },
+ /* 3161 */ { MAD_F(0x05a9b715) /* 0.353934367 */, 17 },
+ /* 3162 */ { MAD_F(0x05aa53a2) /* 0.354083667 */, 17 },
+ /* 3163 */ { MAD_F(0x05aaf034) /* 0.354232983 */, 17 },
+ /* 3164 */ { MAD_F(0x05ab8cca) /* 0.354382314 */, 17 },
+ /* 3165 */ { MAD_F(0x05ac2964) /* 0.354531662 */, 17 },
+ /* 3166 */ { MAD_F(0x05acc602) /* 0.354681025 */, 17 },
+ /* 3167 */ { MAD_F(0x05ad62a5) /* 0.354830403 */, 17 },
+
+ /* 3168 */ { MAD_F(0x05adff4c) /* 0.354979798 */, 17 },
+ /* 3169 */ { MAD_F(0x05ae9bf7) /* 0.355129208 */, 17 },
+ /* 3170 */ { MAD_F(0x05af38a6) /* 0.355278634 */, 17 },
+ /* 3171 */ { MAD_F(0x05afd559) /* 0.355428075 */, 17 },
+ /* 3172 */ { MAD_F(0x05b07211) /* 0.355577533 */, 17 },
+ /* 3173 */ { MAD_F(0x05b10ecd) /* 0.355727006 */, 17 },
+ /* 3174 */ { MAD_F(0x05b1ab8d) /* 0.355876494 */, 17 },
+ /* 3175 */ { MAD_F(0x05b24851) /* 0.356025999 */, 17 },
+ /* 3176 */ { MAD_F(0x05b2e51a) /* 0.356175519 */, 17 },
+ /* 3177 */ { MAD_F(0x05b381e6) /* 0.356325054 */, 17 },
+ /* 3178 */ { MAD_F(0x05b41eb7) /* 0.356474606 */, 17 },
+ /* 3179 */ { MAD_F(0x05b4bb8c) /* 0.356624173 */, 17 },
+ /* 3180 */ { MAD_F(0x05b55866) /* 0.356773756 */, 17 },
+ /* 3181 */ { MAD_F(0x05b5f543) /* 0.356923354 */, 17 },
+ /* 3182 */ { MAD_F(0x05b69225) /* 0.357072969 */, 17 },
+ /* 3183 */ { MAD_F(0x05b72f0b) /* 0.357222598 */, 17 },
+
+ /* 3184 */ { MAD_F(0x05b7cbf5) /* 0.357372244 */, 17 },
+ /* 3185 */ { MAD_F(0x05b868e3) /* 0.357521905 */, 17 },
+ /* 3186 */ { MAD_F(0x05b905d6) /* 0.357671582 */, 17 },
+ /* 3187 */ { MAD_F(0x05b9a2cd) /* 0.357821275 */, 17 },
+ /* 3188 */ { MAD_F(0x05ba3fc8) /* 0.357970983 */, 17 },
+ /* 3189 */ { MAD_F(0x05badcc7) /* 0.358120707 */, 17 },
+ /* 3190 */ { MAD_F(0x05bb79ca) /* 0.358270446 */, 17 },
+ /* 3191 */ { MAD_F(0x05bc16d2) /* 0.358420201 */, 17 },
+ /* 3192 */ { MAD_F(0x05bcb3de) /* 0.358569972 */, 17 },
+ /* 3193 */ { MAD_F(0x05bd50ee) /* 0.358719758 */, 17 },
+ /* 3194 */ { MAD_F(0x05bdee02) /* 0.358869560 */, 17 },
+ /* 3195 */ { MAD_F(0x05be8b1a) /* 0.359019378 */, 17 },
+ /* 3196 */ { MAD_F(0x05bf2837) /* 0.359169211 */, 17 },
+ /* 3197 */ { MAD_F(0x05bfc558) /* 0.359319060 */, 17 },
+ /* 3198 */ { MAD_F(0x05c0627d) /* 0.359468925 */, 17 },
+ /* 3199 */ { MAD_F(0x05c0ffa6) /* 0.359618805 */, 17 },
+
+ /* 3200 */ { MAD_F(0x05c19cd3) /* 0.359768701 */, 17 },
+ /* 3201 */ { MAD_F(0x05c23a05) /* 0.359918612 */, 17 },
+ /* 3202 */ { MAD_F(0x05c2d73a) /* 0.360068540 */, 17 },
+ /* 3203 */ { MAD_F(0x05c37474) /* 0.360218482 */, 17 },
+ /* 3204 */ { MAD_F(0x05c411b2) /* 0.360368440 */, 17 },
+ /* 3205 */ { MAD_F(0x05c4aef5) /* 0.360518414 */, 17 },
+ /* 3206 */ { MAD_F(0x05c54c3b) /* 0.360668404 */, 17 },
+ /* 3207 */ { MAD_F(0x05c5e986) /* 0.360818409 */, 17 },
+ /* 3208 */ { MAD_F(0x05c686d5) /* 0.360968429 */, 17 },
+ /* 3209 */ { MAD_F(0x05c72428) /* 0.361118466 */, 17 },
+ /* 3210 */ { MAD_F(0x05c7c17f) /* 0.361268517 */, 17 },
+ /* 3211 */ { MAD_F(0x05c85eda) /* 0.361418585 */, 17 },
+ /* 3212 */ { MAD_F(0x05c8fc3a) /* 0.361568668 */, 17 },
+ /* 3213 */ { MAD_F(0x05c9999e) /* 0.361718766 */, 17 },
+ /* 3214 */ { MAD_F(0x05ca3706) /* 0.361868881 */, 17 },
+ /* 3215 */ { MAD_F(0x05cad472) /* 0.362019010 */, 17 },
+
+ /* 3216 */ { MAD_F(0x05cb71e2) /* 0.362169156 */, 17 },
+ /* 3217 */ { MAD_F(0x05cc0f57) /* 0.362319316 */, 17 },
+ /* 3218 */ { MAD_F(0x05ccaccf) /* 0.362469493 */, 17 },
+ /* 3219 */ { MAD_F(0x05cd4a4c) /* 0.362619685 */, 17 },
+ /* 3220 */ { MAD_F(0x05cde7cd) /* 0.362769892 */, 17 },
+ /* 3221 */ { MAD_F(0x05ce8552) /* 0.362920115 */, 17 },
+ /* 3222 */ { MAD_F(0x05cf22dc) /* 0.363070354 */, 17 },
+ /* 3223 */ { MAD_F(0x05cfc069) /* 0.363220608 */, 17 },
+ /* 3224 */ { MAD_F(0x05d05dfb) /* 0.363370878 */, 17 },
+ /* 3225 */ { MAD_F(0x05d0fb91) /* 0.363521163 */, 17 },
+ /* 3226 */ { MAD_F(0x05d1992b) /* 0.363671464 */, 17 },
+ /* 3227 */ { MAD_F(0x05d236c9) /* 0.363821780 */, 17 },
+ /* 3228 */ { MAD_F(0x05d2d46c) /* 0.363972112 */, 17 },
+ /* 3229 */ { MAD_F(0x05d37212) /* 0.364122459 */, 17 },
+ /* 3230 */ { MAD_F(0x05d40fbd) /* 0.364272822 */, 17 },
+ /* 3231 */ { MAD_F(0x05d4ad6c) /* 0.364423200 */, 17 },
+
+ /* 3232 */ { MAD_F(0x05d54b1f) /* 0.364573594 */, 17 },
+ /* 3233 */ { MAD_F(0x05d5e8d6) /* 0.364724004 */, 17 },
+ /* 3234 */ { MAD_F(0x05d68691) /* 0.364874429 */, 17 },
+ /* 3235 */ { MAD_F(0x05d72451) /* 0.365024869 */, 17 },
+ /* 3236 */ { MAD_F(0x05d7c215) /* 0.365175325 */, 17 },
+ /* 3237 */ { MAD_F(0x05d85fdc) /* 0.365325796 */, 17 },
+ /* 3238 */ { MAD_F(0x05d8fda8) /* 0.365476283 */, 17 },
+ /* 3239 */ { MAD_F(0x05d99b79) /* 0.365626786 */, 17 },
+ /* 3240 */ { MAD_F(0x05da394d) /* 0.365777304 */, 17 },
+ /* 3241 */ { MAD_F(0x05dad726) /* 0.365927837 */, 17 },
+ /* 3242 */ { MAD_F(0x05db7502) /* 0.366078386 */, 17 },
+ /* 3243 */ { MAD_F(0x05dc12e3) /* 0.366228950 */, 17 },
+ /* 3244 */ { MAD_F(0x05dcb0c8) /* 0.366379530 */, 17 },
+ /* 3245 */ { MAD_F(0x05dd4eb1) /* 0.366530125 */, 17 },
+ /* 3246 */ { MAD_F(0x05ddec9e) /* 0.366680736 */, 17 },
+ /* 3247 */ { MAD_F(0x05de8a90) /* 0.366831362 */, 17 },
+
+ /* 3248 */ { MAD_F(0x05df2885) /* 0.366982004 */, 17 },
+ /* 3249 */ { MAD_F(0x05dfc67f) /* 0.367132661 */, 17 },
+ /* 3250 */ { MAD_F(0x05e0647d) /* 0.367283334 */, 17 },
+ /* 3251 */ { MAD_F(0x05e1027f) /* 0.367434022 */, 17 },
+ /* 3252 */ { MAD_F(0x05e1a085) /* 0.367584725 */, 17 },
+ /* 3253 */ { MAD_F(0x05e23e8f) /* 0.367735444 */, 17 },
+ /* 3254 */ { MAD_F(0x05e2dc9e) /* 0.367886179 */, 17 },
+ /* 3255 */ { MAD_F(0x05e37ab0) /* 0.368036929 */, 17 },
+ /* 3256 */ { MAD_F(0x05e418c7) /* 0.368187694 */, 17 },
+ /* 3257 */ { MAD_F(0x05e4b6e2) /* 0.368338475 */, 17 },
+ /* 3258 */ { MAD_F(0x05e55501) /* 0.368489271 */, 17 },
+ /* 3259 */ { MAD_F(0x05e5f324) /* 0.368640082 */, 17 },
+ /* 3260 */ { MAD_F(0x05e6914c) /* 0.368790909 */, 17 },
+ /* 3261 */ { MAD_F(0x05e72f77) /* 0.368941752 */, 17 },
+ /* 3262 */ { MAD_F(0x05e7cda7) /* 0.369092610 */, 17 },
+ /* 3263 */ { MAD_F(0x05e86bda) /* 0.369243483 */, 17 },
+
+ /* 3264 */ { MAD_F(0x05e90a12) /* 0.369394372 */, 17 },
+ /* 3265 */ { MAD_F(0x05e9a84e) /* 0.369545276 */, 17 },
+ /* 3266 */ { MAD_F(0x05ea468e) /* 0.369696195 */, 17 },
+ /* 3267 */ { MAD_F(0x05eae4d3) /* 0.369847130 */, 17 },
+ /* 3268 */ { MAD_F(0x05eb831b) /* 0.369998080 */, 17 },
+ /* 3269 */ { MAD_F(0x05ec2168) /* 0.370149046 */, 17 },
+ /* 3270 */ { MAD_F(0x05ecbfb8) /* 0.370300027 */, 17 },
+ /* 3271 */ { MAD_F(0x05ed5e0d) /* 0.370451024 */, 17 },
+ /* 3272 */ { MAD_F(0x05edfc66) /* 0.370602036 */, 17 },
+ /* 3273 */ { MAD_F(0x05ee9ac3) /* 0.370753063 */, 17 },
+ /* 3274 */ { MAD_F(0x05ef3924) /* 0.370904105 */, 17 },
+ /* 3275 */ { MAD_F(0x05efd78a) /* 0.371055163 */, 17 },
+ /* 3276 */ { MAD_F(0x05f075f3) /* 0.371206237 */, 17 },
+ /* 3277 */ { MAD_F(0x05f11461) /* 0.371357326 */, 17 },
+ /* 3278 */ { MAD_F(0x05f1b2d3) /* 0.371508430 */, 17 },
+ /* 3279 */ { MAD_F(0x05f25148) /* 0.371659549 */, 17 },
+
+ /* 3280 */ { MAD_F(0x05f2efc2) /* 0.371810684 */, 17 },
+ /* 3281 */ { MAD_F(0x05f38e40) /* 0.371961834 */, 17 },
+ /* 3282 */ { MAD_F(0x05f42cc3) /* 0.372113000 */, 17 },
+ /* 3283 */ { MAD_F(0x05f4cb49) /* 0.372264181 */, 17 },
+ /* 3284 */ { MAD_F(0x05f569d3) /* 0.372415377 */, 17 },
+ /* 3285 */ { MAD_F(0x05f60862) /* 0.372566589 */, 17 },
+ /* 3286 */ { MAD_F(0x05f6a6f5) /* 0.372717816 */, 17 },
+ /* 3287 */ { MAD_F(0x05f7458b) /* 0.372869058 */, 17 },
+ /* 3288 */ { MAD_F(0x05f7e426) /* 0.373020316 */, 17 },
+ /* 3289 */ { MAD_F(0x05f882c5) /* 0.373171589 */, 17 },
+ /* 3290 */ { MAD_F(0x05f92169) /* 0.373322877 */, 17 },
+ /* 3291 */ { MAD_F(0x05f9c010) /* 0.373474181 */, 17 },
+ /* 3292 */ { MAD_F(0x05fa5ebb) /* 0.373625500 */, 17 },
+ /* 3293 */ { MAD_F(0x05fafd6b) /* 0.373776834 */, 17 },
+ /* 3294 */ { MAD_F(0x05fb9c1e) /* 0.373928184 */, 17 },
+ /* 3295 */ { MAD_F(0x05fc3ad6) /* 0.374079549 */, 17 },
+
+ /* 3296 */ { MAD_F(0x05fcd992) /* 0.374230929 */, 17 },
+ /* 3297 */ { MAD_F(0x05fd7852) /* 0.374382325 */, 17 },
+ /* 3298 */ { MAD_F(0x05fe1716) /* 0.374533735 */, 17 },
+ /* 3299 */ { MAD_F(0x05feb5de) /* 0.374685162 */, 17 },
+ /* 3300 */ { MAD_F(0x05ff54aa) /* 0.374836603 */, 17 },
+ /* 3301 */ { MAD_F(0x05fff37b) /* 0.374988060 */, 17 },
+ /* 3302 */ { MAD_F(0x0600924f) /* 0.375139532 */, 17 },
+ /* 3303 */ { MAD_F(0x06013128) /* 0.375291019 */, 17 },
+ /* 3304 */ { MAD_F(0x0601d004) /* 0.375442522 */, 17 },
+ /* 3305 */ { MAD_F(0x06026ee5) /* 0.375594040 */, 17 },
+ /* 3306 */ { MAD_F(0x06030dca) /* 0.375745573 */, 17 },
+ /* 3307 */ { MAD_F(0x0603acb3) /* 0.375897122 */, 17 },
+ /* 3308 */ { MAD_F(0x06044ba0) /* 0.376048685 */, 17 },
+ /* 3309 */ { MAD_F(0x0604ea91) /* 0.376200265 */, 17 },
+ /* 3310 */ { MAD_F(0x06058987) /* 0.376351859 */, 17 },
+ /* 3311 */ { MAD_F(0x06062880) /* 0.376503468 */, 17 },
+
+ /* 3312 */ { MAD_F(0x0606c77d) /* 0.376655093 */, 17 },
+ /* 3313 */ { MAD_F(0x0607667f) /* 0.376806733 */, 17 },
+ /* 3314 */ { MAD_F(0x06080585) /* 0.376958389 */, 17 },
+ /* 3315 */ { MAD_F(0x0608a48f) /* 0.377110059 */, 17 },
+ /* 3316 */ { MAD_F(0x0609439c) /* 0.377261745 */, 17 },
+ /* 3317 */ { MAD_F(0x0609e2ae) /* 0.377413446 */, 17 },
+ /* 3318 */ { MAD_F(0x060a81c4) /* 0.377565163 */, 17 },
+ /* 3319 */ { MAD_F(0x060b20df) /* 0.377716894 */, 17 },
+ /* 3320 */ { MAD_F(0x060bbffd) /* 0.377868641 */, 17 },
+ /* 3321 */ { MAD_F(0x060c5f1f) /* 0.378020403 */, 17 },
+ /* 3322 */ { MAD_F(0x060cfe46) /* 0.378172181 */, 17 },
+ /* 3323 */ { MAD_F(0x060d9d70) /* 0.378323973 */, 17 },
+ /* 3324 */ { MAD_F(0x060e3c9f) /* 0.378475781 */, 17 },
+ /* 3325 */ { MAD_F(0x060edbd1) /* 0.378627604 */, 17 },
+ /* 3326 */ { MAD_F(0x060f7b08) /* 0.378779442 */, 17 },
+ /* 3327 */ { MAD_F(0x06101a43) /* 0.378931296 */, 17 },
+
+ /* 3328 */ { MAD_F(0x0610b982) /* 0.379083164 */, 17 },
+ /* 3329 */ { MAD_F(0x061158c5) /* 0.379235048 */, 17 },
+ /* 3330 */ { MAD_F(0x0611f80c) /* 0.379386947 */, 17 },
+ /* 3331 */ { MAD_F(0x06129757) /* 0.379538862 */, 17 },
+ /* 3332 */ { MAD_F(0x061336a6) /* 0.379690791 */, 17 },
+ /* 3333 */ { MAD_F(0x0613d5fa) /* 0.379842736 */, 17 },
+ /* 3334 */ { MAD_F(0x06147551) /* 0.379994696 */, 17 },
+ /* 3335 */ { MAD_F(0x061514ad) /* 0.380146671 */, 17 },
+ /* 3336 */ { MAD_F(0x0615b40c) /* 0.380298661 */, 17 },
+ /* 3337 */ { MAD_F(0x06165370) /* 0.380450666 */, 17 },
+ /* 3338 */ { MAD_F(0x0616f2d8) /* 0.380602687 */, 17 },
+ /* 3339 */ { MAD_F(0x06179243) /* 0.380754723 */, 17 },
+ /* 3340 */ { MAD_F(0x061831b3) /* 0.380906774 */, 17 },
+ /* 3341 */ { MAD_F(0x0618d127) /* 0.381058840 */, 17 },
+ /* 3342 */ { MAD_F(0x0619709f) /* 0.381210921 */, 17 },
+ /* 3343 */ { MAD_F(0x061a101b) /* 0.381363018 */, 17 },
+
+ /* 3344 */ { MAD_F(0x061aaf9c) /* 0.381515130 */, 17 },
+ /* 3345 */ { MAD_F(0x061b4f20) /* 0.381667257 */, 17 },
+ /* 3346 */ { MAD_F(0x061beea8) /* 0.381819399 */, 17 },
+ /* 3347 */ { MAD_F(0x061c8e34) /* 0.381971556 */, 17 },
+ /* 3348 */ { MAD_F(0x061d2dc5) /* 0.382123728 */, 17 },
+ /* 3349 */ { MAD_F(0x061dcd59) /* 0.382275916 */, 17 },
+ /* 3350 */ { MAD_F(0x061e6cf2) /* 0.382428118 */, 17 },
+ /* 3351 */ { MAD_F(0x061f0c8f) /* 0.382580336 */, 17 },
+ /* 3352 */ { MAD_F(0x061fac2f) /* 0.382732569 */, 17 },
+ /* 3353 */ { MAD_F(0x06204bd4) /* 0.382884817 */, 17 },
+ /* 3354 */ { MAD_F(0x0620eb7d) /* 0.383037080 */, 17 },
+ /* 3355 */ { MAD_F(0x06218b2a) /* 0.383189358 */, 17 },
+ /* 3356 */ { MAD_F(0x06222adb) /* 0.383341652 */, 17 },
+ /* 3357 */ { MAD_F(0x0622ca90) /* 0.383493960 */, 17 },
+ /* 3358 */ { MAD_F(0x06236a49) /* 0.383646284 */, 17 },
+ /* 3359 */ { MAD_F(0x06240a06) /* 0.383798623 */, 17 },
+
+ /* 3360 */ { MAD_F(0x0624a9c7) /* 0.383950977 */, 17 },
+ /* 3361 */ { MAD_F(0x0625498d) /* 0.384103346 */, 17 },
+ /* 3362 */ { MAD_F(0x0625e956) /* 0.384255730 */, 17 },
+ /* 3363 */ { MAD_F(0x06268923) /* 0.384408129 */, 17 },
+ /* 3364 */ { MAD_F(0x062728f5) /* 0.384560544 */, 17 },
+ /* 3365 */ { MAD_F(0x0627c8ca) /* 0.384712973 */, 17 },
+ /* 3366 */ { MAD_F(0x062868a4) /* 0.384865418 */, 17 },
+ /* 3367 */ { MAD_F(0x06290881) /* 0.385017878 */, 17 },
+ /* 3368 */ { MAD_F(0x0629a863) /* 0.385170352 */, 17 },
+ /* 3369 */ { MAD_F(0x062a4849) /* 0.385322842 */, 17 },
+ /* 3370 */ { MAD_F(0x062ae832) /* 0.385475347 */, 17 },
+ /* 3371 */ { MAD_F(0x062b8820) /* 0.385627867 */, 17 },
+ /* 3372 */ { MAD_F(0x062c2812) /* 0.385780402 */, 17 },
+ /* 3373 */ { MAD_F(0x062cc808) /* 0.385932953 */, 17 },
+ /* 3374 */ { MAD_F(0x062d6802) /* 0.386085518 */, 17 },
+ /* 3375 */ { MAD_F(0x062e0800) /* 0.386238098 */, 17 },
+
+ /* 3376 */ { MAD_F(0x062ea802) /* 0.386390694 */, 17 },
+ /* 3377 */ { MAD_F(0x062f4808) /* 0.386543304 */, 17 },
+ /* 3378 */ { MAD_F(0x062fe812) /* 0.386695930 */, 17 },
+ /* 3379 */ { MAD_F(0x06308820) /* 0.386848570 */, 17 },
+ /* 3380 */ { MAD_F(0x06312832) /* 0.387001226 */, 17 },
+ /* 3381 */ { MAD_F(0x0631c849) /* 0.387153897 */, 17 },
+ /* 3382 */ { MAD_F(0x06326863) /* 0.387306582 */, 17 },
+ /* 3383 */ { MAD_F(0x06330881) /* 0.387459283 */, 17 },
+ /* 3384 */ { MAD_F(0x0633a8a3) /* 0.387611999 */, 17 },
+ /* 3385 */ { MAD_F(0x063448ca) /* 0.387764730 */, 17 },
+ /* 3386 */ { MAD_F(0x0634e8f4) /* 0.387917476 */, 17 },
+ /* 3387 */ { MAD_F(0x06358923) /* 0.388070237 */, 17 },
+ /* 3388 */ { MAD_F(0x06362955) /* 0.388223013 */, 17 },
+ /* 3389 */ { MAD_F(0x0636c98c) /* 0.388375804 */, 17 },
+ /* 3390 */ { MAD_F(0x063769c6) /* 0.388528610 */, 17 },
+ /* 3391 */ { MAD_F(0x06380a05) /* 0.388681431 */, 17 },
+
+ /* 3392 */ { MAD_F(0x0638aa48) /* 0.388834268 */, 17 },
+ /* 3393 */ { MAD_F(0x06394a8e) /* 0.388987119 */, 17 },
+ /* 3394 */ { MAD_F(0x0639ead9) /* 0.389139985 */, 17 },
+ /* 3395 */ { MAD_F(0x063a8b28) /* 0.389292866 */, 17 },
+ /* 3396 */ { MAD_F(0x063b2b7b) /* 0.389445762 */, 17 },
+ /* 3397 */ { MAD_F(0x063bcbd1) /* 0.389598674 */, 17 },
+ /* 3398 */ { MAD_F(0x063c6c2c) /* 0.389751600 */, 17 },
+ /* 3399 */ { MAD_F(0x063d0c8b) /* 0.389904541 */, 17 },
+ /* 3400 */ { MAD_F(0x063dacee) /* 0.390057497 */, 17 },
+ /* 3401 */ { MAD_F(0x063e4d55) /* 0.390210468 */, 17 },
+ /* 3402 */ { MAD_F(0x063eedc0) /* 0.390363455 */, 17 },
+ /* 3403 */ { MAD_F(0x063f8e2f) /* 0.390516456 */, 17 },
+ /* 3404 */ { MAD_F(0x06402ea2) /* 0.390669472 */, 17 },
+ /* 3405 */ { MAD_F(0x0640cf19) /* 0.390822503 */, 17 },
+ /* 3406 */ { MAD_F(0x06416f94) /* 0.390975549 */, 17 },
+ /* 3407 */ { MAD_F(0x06421013) /* 0.391128611 */, 17 },
+
+ /* 3408 */ { MAD_F(0x0642b096) /* 0.391281687 */, 17 },
+ /* 3409 */ { MAD_F(0x0643511d) /* 0.391434778 */, 17 },
+ /* 3410 */ { MAD_F(0x0643f1a8) /* 0.391587884 */, 17 },
+ /* 3411 */ { MAD_F(0x06449237) /* 0.391741005 */, 17 },
+ /* 3412 */ { MAD_F(0x064532ca) /* 0.391894141 */, 17 },
+ /* 3413 */ { MAD_F(0x0645d361) /* 0.392047292 */, 17 },
+ /* 3414 */ { MAD_F(0x064673fc) /* 0.392200458 */, 17 },
+ /* 3415 */ { MAD_F(0x0647149c) /* 0.392353638 */, 17 },
+ /* 3416 */ { MAD_F(0x0647b53f) /* 0.392506834 */, 17 },
+ /* 3417 */ { MAD_F(0x064855e6) /* 0.392660045 */, 17 },
+ /* 3418 */ { MAD_F(0x0648f691) /* 0.392813271 */, 17 },
+ /* 3419 */ { MAD_F(0x06499740) /* 0.392966511 */, 17 },
+ /* 3420 */ { MAD_F(0x064a37f4) /* 0.393119767 */, 17 },
+ /* 3421 */ { MAD_F(0x064ad8ab) /* 0.393273038 */, 17 },
+ /* 3422 */ { MAD_F(0x064b7966) /* 0.393426323 */, 17 },
+ /* 3423 */ { MAD_F(0x064c1a25) /* 0.393579623 */, 17 },
+
+ /* 3424 */ { MAD_F(0x064cbae9) /* 0.393732939 */, 17 },
+ /* 3425 */ { MAD_F(0x064d5bb0) /* 0.393886269 */, 17 },
+ /* 3426 */ { MAD_F(0x064dfc7b) /* 0.394039614 */, 17 },
+ /* 3427 */ { MAD_F(0x064e9d4b) /* 0.394192974 */, 17 },
+ /* 3428 */ { MAD_F(0x064f3e1e) /* 0.394346349 */, 17 },
+ /* 3429 */ { MAD_F(0x064fdef5) /* 0.394499739 */, 17 },
+ /* 3430 */ { MAD_F(0x06507fd0) /* 0.394653144 */, 17 },
+ /* 3431 */ { MAD_F(0x065120b0) /* 0.394806564 */, 17 },
+ /* 3432 */ { MAD_F(0x0651c193) /* 0.394959999 */, 17 },
+ /* 3433 */ { MAD_F(0x0652627a) /* 0.395113448 */, 17 },
+ /* 3434 */ { MAD_F(0x06530366) /* 0.395266913 */, 17 },
+ /* 3435 */ { MAD_F(0x0653a455) /* 0.395420392 */, 17 },
+ /* 3436 */ { MAD_F(0x06544548) /* 0.395573886 */, 17 },
+ /* 3437 */ { MAD_F(0x0654e640) /* 0.395727395 */, 17 },
+ /* 3438 */ { MAD_F(0x0655873b) /* 0.395880919 */, 17 },
+ /* 3439 */ { MAD_F(0x0656283a) /* 0.396034458 */, 17 },
+
+ /* 3440 */ { MAD_F(0x0656c93d) /* 0.396188012 */, 17 },
+ /* 3441 */ { MAD_F(0x06576a45) /* 0.396341581 */, 17 },
+ /* 3442 */ { MAD_F(0x06580b50) /* 0.396495164 */, 17 },
+ /* 3443 */ { MAD_F(0x0658ac5f) /* 0.396648763 */, 17 },
+ /* 3444 */ { MAD_F(0x06594d73) /* 0.396802376 */, 17 },
+ /* 3445 */ { MAD_F(0x0659ee8a) /* 0.396956004 */, 17 },
+ /* 3446 */ { MAD_F(0x065a8fa5) /* 0.397109647 */, 17 },
+ /* 3447 */ { MAD_F(0x065b30c4) /* 0.397263305 */, 17 },
+ /* 3448 */ { MAD_F(0x065bd1e7) /* 0.397416978 */, 17 },
+ /* 3449 */ { MAD_F(0x065c730f) /* 0.397570666 */, 17 },
+ /* 3450 */ { MAD_F(0x065d143a) /* 0.397724368 */, 17 },
+ /* 3451 */ { MAD_F(0x065db569) /* 0.397878085 */, 17 },
+ /* 3452 */ { MAD_F(0x065e569c) /* 0.398031818 */, 17 },
+ /* 3453 */ { MAD_F(0x065ef7d3) /* 0.398185565 */, 17 },
+ /* 3454 */ { MAD_F(0x065f990e) /* 0.398339326 */, 17 },
+ /* 3455 */ { MAD_F(0x06603a4e) /* 0.398493103 */, 17 },
+
+ /* 3456 */ { MAD_F(0x0660db91) /* 0.398646895 */, 17 },
+ /* 3457 */ { MAD_F(0x06617cd8) /* 0.398800701 */, 17 },
+ /* 3458 */ { MAD_F(0x06621e23) /* 0.398954522 */, 17 },
+ /* 3459 */ { MAD_F(0x0662bf72) /* 0.399108358 */, 17 },
+ /* 3460 */ { MAD_F(0x066360c5) /* 0.399262209 */, 17 },
+ /* 3461 */ { MAD_F(0x0664021c) /* 0.399416075 */, 17 },
+ /* 3462 */ { MAD_F(0x0664a377) /* 0.399569955 */, 17 },
+ /* 3463 */ { MAD_F(0x066544d6) /* 0.399723851 */, 17 },
+ /* 3464 */ { MAD_F(0x0665e639) /* 0.399877761 */, 17 },
+ /* 3465 */ { MAD_F(0x066687a0) /* 0.400031686 */, 17 },
+ /* 3466 */ { MAD_F(0x0667290b) /* 0.400185625 */, 17 },
+ /* 3467 */ { MAD_F(0x0667ca79) /* 0.400339580 */, 17 },
+ /* 3468 */ { MAD_F(0x06686bec) /* 0.400493549 */, 17 },
+ /* 3469 */ { MAD_F(0x06690d63) /* 0.400647534 */, 17 },
+ /* 3470 */ { MAD_F(0x0669aede) /* 0.400801533 */, 17 },
+ /* 3471 */ { MAD_F(0x066a505d) /* 0.400955546 */, 17 },
+
+ /* 3472 */ { MAD_F(0x066af1df) /* 0.401109575 */, 17 },
+ /* 3473 */ { MAD_F(0x066b9366) /* 0.401263618 */, 17 },
+ /* 3474 */ { MAD_F(0x066c34f1) /* 0.401417676 */, 17 },
+ /* 3475 */ { MAD_F(0x066cd67f) /* 0.401571749 */, 17 },
+ /* 3476 */ { MAD_F(0x066d7812) /* 0.401725837 */, 17 },
+ /* 3477 */ { MAD_F(0x066e19a9) /* 0.401879939 */, 17 },
+ /* 3478 */ { MAD_F(0x066ebb43) /* 0.402034056 */, 17 },
+ /* 3479 */ { MAD_F(0x066f5ce2) /* 0.402188188 */, 17 },
+ /* 3480 */ { MAD_F(0x066ffe84) /* 0.402342335 */, 17 },
+ /* 3481 */ { MAD_F(0x0670a02a) /* 0.402496497 */, 17 },
+ /* 3482 */ { MAD_F(0x067141d5) /* 0.402650673 */, 17 },
+ /* 3483 */ { MAD_F(0x0671e383) /* 0.402804864 */, 17 },
+ /* 3484 */ { MAD_F(0x06728535) /* 0.402959070 */, 17 },
+ /* 3485 */ { MAD_F(0x067326ec) /* 0.403113291 */, 17 },
+ /* 3486 */ { MAD_F(0x0673c8a6) /* 0.403267526 */, 17 },
+ /* 3487 */ { MAD_F(0x06746a64) /* 0.403421776 */, 17 },
+
+ /* 3488 */ { MAD_F(0x06750c26) /* 0.403576041 */, 17 },
+ /* 3489 */ { MAD_F(0x0675adec) /* 0.403730320 */, 17 },
+ /* 3490 */ { MAD_F(0x06764fb6) /* 0.403884615 */, 17 },
+ /* 3491 */ { MAD_F(0x0676f184) /* 0.404038924 */, 17 },
+ /* 3492 */ { MAD_F(0x06779356) /* 0.404193247 */, 17 },
+ /* 3493 */ { MAD_F(0x0678352c) /* 0.404347586 */, 17 },
+ /* 3494 */ { MAD_F(0x0678d706) /* 0.404501939 */, 17 },
+ /* 3495 */ { MAD_F(0x067978e4) /* 0.404656307 */, 17 },
+ /* 3496 */ { MAD_F(0x067a1ac6) /* 0.404810690 */, 17 },
+ /* 3497 */ { MAD_F(0x067abcac) /* 0.404965087 */, 17 },
+ /* 3498 */ { MAD_F(0x067b5e95) /* 0.405119499 */, 17 },
+ /* 3499 */ { MAD_F(0x067c0083) /* 0.405273926 */, 17 },
+ /* 3500 */ { MAD_F(0x067ca275) /* 0.405428368 */, 17 },
+ /* 3501 */ { MAD_F(0x067d446a) /* 0.405582824 */, 17 },
+ /* 3502 */ { MAD_F(0x067de664) /* 0.405737295 */, 17 },
+ /* 3503 */ { MAD_F(0x067e8861) /* 0.405891781 */, 17 },
+
+ /* 3504 */ { MAD_F(0x067f2a62) /* 0.406046281 */, 17 },
+ /* 3505 */ { MAD_F(0x067fcc68) /* 0.406200796 */, 17 },
+ /* 3506 */ { MAD_F(0x06806e71) /* 0.406355326 */, 17 },
+ /* 3507 */ { MAD_F(0x0681107e) /* 0.406509870 */, 17 },
+ /* 3508 */ { MAD_F(0x0681b28f) /* 0.406664429 */, 17 },
+ /* 3509 */ { MAD_F(0x068254a4) /* 0.406819003 */, 17 },
+ /* 3510 */ { MAD_F(0x0682f6bd) /* 0.406973592 */, 17 },
+ /* 3511 */ { MAD_F(0x068398da) /* 0.407128195 */, 17 },
+ /* 3512 */ { MAD_F(0x06843afb) /* 0.407282813 */, 17 },
+ /* 3513 */ { MAD_F(0x0684dd20) /* 0.407437445 */, 17 },
+ /* 3514 */ { MAD_F(0x06857f49) /* 0.407592093 */, 17 },
+ /* 3515 */ { MAD_F(0x06862176) /* 0.407746754 */, 17 },
+ /* 3516 */ { MAD_F(0x0686c3a6) /* 0.407901431 */, 17 },
+ /* 3517 */ { MAD_F(0x068765db) /* 0.408056122 */, 17 },
+ /* 3518 */ { MAD_F(0x06880814) /* 0.408210828 */, 17 },
+ /* 3519 */ { MAD_F(0x0688aa50) /* 0.408365549 */, 17 },
+
+ /* 3520 */ { MAD_F(0x06894c90) /* 0.408520284 */, 17 },
+ /* 3521 */ { MAD_F(0x0689eed5) /* 0.408675034 */, 17 },
+ /* 3522 */ { MAD_F(0x068a911d) /* 0.408829798 */, 17 },
+ /* 3523 */ { MAD_F(0x068b3369) /* 0.408984577 */, 17 },
+ /* 3524 */ { MAD_F(0x068bd5b9) /* 0.409139371 */, 17 },
+ /* 3525 */ { MAD_F(0x068c780e) /* 0.409294180 */, 17 },
+ /* 3526 */ { MAD_F(0x068d1a66) /* 0.409449003 */, 17 },
+ /* 3527 */ { MAD_F(0x068dbcc1) /* 0.409603840 */, 17 },
+ /* 3528 */ { MAD_F(0x068e5f21) /* 0.409758693 */, 17 },
+ /* 3529 */ { MAD_F(0x068f0185) /* 0.409913560 */, 17 },
+ /* 3530 */ { MAD_F(0x068fa3ed) /* 0.410068441 */, 17 },
+ /* 3531 */ { MAD_F(0x06904658) /* 0.410223338 */, 17 },
+ /* 3532 */ { MAD_F(0x0690e8c8) /* 0.410378249 */, 17 },
+ /* 3533 */ { MAD_F(0x06918b3c) /* 0.410533174 */, 17 },
+ /* 3534 */ { MAD_F(0x06922db3) /* 0.410688114 */, 17 },
+ /* 3535 */ { MAD_F(0x0692d02e) /* 0.410843069 */, 17 },
+
+ /* 3536 */ { MAD_F(0x069372ae) /* 0.410998038 */, 17 },
+ /* 3537 */ { MAD_F(0x06941531) /* 0.411153022 */, 17 },
+ /* 3538 */ { MAD_F(0x0694b7b8) /* 0.411308021 */, 17 },
+ /* 3539 */ { MAD_F(0x06955a43) /* 0.411463034 */, 17 },
+ /* 3540 */ { MAD_F(0x0695fcd2) /* 0.411618062 */, 17 },
+ /* 3541 */ { MAD_F(0x06969f65) /* 0.411773104 */, 17 },
+ /* 3542 */ { MAD_F(0x069741fb) /* 0.411928161 */, 17 },
+ /* 3543 */ { MAD_F(0x0697e496) /* 0.412083232 */, 17 },
+ /* 3544 */ { MAD_F(0x06988735) /* 0.412238319 */, 17 },
+ /* 3545 */ { MAD_F(0x069929d7) /* 0.412393419 */, 17 },
+ /* 3546 */ { MAD_F(0x0699cc7e) /* 0.412548535 */, 17 },
+ /* 3547 */ { MAD_F(0x069a6f28) /* 0.412703664 */, 17 },
+ /* 3548 */ { MAD_F(0x069b11d6) /* 0.412858809 */, 17 },
+ /* 3549 */ { MAD_F(0x069bb489) /* 0.413013968 */, 17 },
+ /* 3550 */ { MAD_F(0x069c573f) /* 0.413169142 */, 17 },
+ /* 3551 */ { MAD_F(0x069cf9f9) /* 0.413324330 */, 17 },
+
+ /* 3552 */ { MAD_F(0x069d9cb7) /* 0.413479532 */, 17 },
+ /* 3553 */ { MAD_F(0x069e3f78) /* 0.413634750 */, 17 },
+ /* 3554 */ { MAD_F(0x069ee23e) /* 0.413789982 */, 17 },
+ /* 3555 */ { MAD_F(0x069f8508) /* 0.413945228 */, 17 },
+ /* 3556 */ { MAD_F(0x06a027d5) /* 0.414100489 */, 17 },
+ /* 3557 */ { MAD_F(0x06a0caa7) /* 0.414255765 */, 17 },
+ /* 3558 */ { MAD_F(0x06a16d7c) /* 0.414411055 */, 17 },
+ /* 3559 */ { MAD_F(0x06a21055) /* 0.414566359 */, 17 },
+ /* 3560 */ { MAD_F(0x06a2b333) /* 0.414721679 */, 17 },
+ /* 3561 */ { MAD_F(0x06a35614) /* 0.414877012 */, 17 },
+ /* 3562 */ { MAD_F(0x06a3f8f9) /* 0.415032361 */, 17 },
+ /* 3563 */ { MAD_F(0x06a49be2) /* 0.415187723 */, 17 },
+ /* 3564 */ { MAD_F(0x06a53ece) /* 0.415343101 */, 17 },
+ /* 3565 */ { MAD_F(0x06a5e1bf) /* 0.415498493 */, 17 },
+ /* 3566 */ { MAD_F(0x06a684b4) /* 0.415653899 */, 17 },
+ /* 3567 */ { MAD_F(0x06a727ac) /* 0.415809320 */, 17 },
+
+ /* 3568 */ { MAD_F(0x06a7caa9) /* 0.415964756 */, 17 },
+ /* 3569 */ { MAD_F(0x06a86da9) /* 0.416120206 */, 17 },
+ /* 3570 */ { MAD_F(0x06a910ad) /* 0.416275670 */, 17 },
+ /* 3571 */ { MAD_F(0x06a9b3b5) /* 0.416431149 */, 17 },
+ /* 3572 */ { MAD_F(0x06aa56c1) /* 0.416586643 */, 17 },
+ /* 3573 */ { MAD_F(0x06aaf9d1) /* 0.416742151 */, 17 },
+ /* 3574 */ { MAD_F(0x06ab9ce5) /* 0.416897673 */, 17 },
+ /* 3575 */ { MAD_F(0x06ac3ffc) /* 0.417053210 */, 17 },
+ /* 3576 */ { MAD_F(0x06ace318) /* 0.417208762 */, 17 },
+ /* 3577 */ { MAD_F(0x06ad8637) /* 0.417364328 */, 17 },
+ /* 3578 */ { MAD_F(0x06ae295b) /* 0.417519909 */, 17 },
+ /* 3579 */ { MAD_F(0x06aecc82) /* 0.417675504 */, 17 },
+ /* 3580 */ { MAD_F(0x06af6fad) /* 0.417831113 */, 17 },
+ /* 3581 */ { MAD_F(0x06b012dc) /* 0.417986737 */, 17 },
+ /* 3582 */ { MAD_F(0x06b0b60f) /* 0.418142376 */, 17 },
+ /* 3583 */ { MAD_F(0x06b15946) /* 0.418298029 */, 17 },
+
+ /* 3584 */ { MAD_F(0x06b1fc81) /* 0.418453696 */, 17 },
+ /* 3585 */ { MAD_F(0x06b29fbf) /* 0.418609378 */, 17 },
+ /* 3586 */ { MAD_F(0x06b34302) /* 0.418765075 */, 17 },
+ /* 3587 */ { MAD_F(0x06b3e648) /* 0.418920786 */, 17 },
+ /* 3588 */ { MAD_F(0x06b48992) /* 0.419076511 */, 17 },
+ /* 3589 */ { MAD_F(0x06b52ce0) /* 0.419232251 */, 17 },
+ /* 3590 */ { MAD_F(0x06b5d032) /* 0.419388005 */, 17 },
+ /* 3591 */ { MAD_F(0x06b67388) /* 0.419543774 */, 17 },
+ /* 3592 */ { MAD_F(0x06b716e2) /* 0.419699557 */, 17 },
+ /* 3593 */ { MAD_F(0x06b7ba3f) /* 0.419855355 */, 17 },
+ /* 3594 */ { MAD_F(0x06b85da1) /* 0.420011167 */, 17 },
+ /* 3595 */ { MAD_F(0x06b90106) /* 0.420166994 */, 17 },
+ /* 3596 */ { MAD_F(0x06b9a470) /* 0.420322835 */, 17 },
+ /* 3597 */ { MAD_F(0x06ba47dd) /* 0.420478690 */, 17 },
+ /* 3598 */ { MAD_F(0x06baeb4e) /* 0.420634560 */, 17 },
+ /* 3599 */ { MAD_F(0x06bb8ec3) /* 0.420790445 */, 17 },
+
+ /* 3600 */ { MAD_F(0x06bc323b) /* 0.420946343 */, 17 },
+ /* 3601 */ { MAD_F(0x06bcd5b8) /* 0.421102257 */, 17 },
+ /* 3602 */ { MAD_F(0x06bd7939) /* 0.421258184 */, 17 },
+ /* 3603 */ { MAD_F(0x06be1cbd) /* 0.421414127 */, 17 },
+ /* 3604 */ { MAD_F(0x06bec045) /* 0.421570083 */, 17 },
+ /* 3605 */ { MAD_F(0x06bf63d1) /* 0.421726054 */, 17 },
+ /* 3606 */ { MAD_F(0x06c00761) /* 0.421882040 */, 17 },
+ /* 3607 */ { MAD_F(0x06c0aaf5) /* 0.422038039 */, 17 },
+ /* 3608 */ { MAD_F(0x06c14e8d) /* 0.422194054 */, 17 },
+ /* 3609 */ { MAD_F(0x06c1f229) /* 0.422350082 */, 17 },
+ /* 3610 */ { MAD_F(0x06c295c8) /* 0.422506125 */, 17 },
+ /* 3611 */ { MAD_F(0x06c3396c) /* 0.422662183 */, 17 },
+ /* 3612 */ { MAD_F(0x06c3dd13) /* 0.422818255 */, 17 },
+ /* 3613 */ { MAD_F(0x06c480be) /* 0.422974341 */, 17 },
+ /* 3614 */ { MAD_F(0x06c5246d) /* 0.423130442 */, 17 },
+ /* 3615 */ { MAD_F(0x06c5c820) /* 0.423286557 */, 17 },
+
+ /* 3616 */ { MAD_F(0x06c66bd6) /* 0.423442686 */, 17 },
+ /* 3617 */ { MAD_F(0x06c70f91) /* 0.423598830 */, 17 },
+ /* 3618 */ { MAD_F(0x06c7b34f) /* 0.423754988 */, 17 },
+ /* 3619 */ { MAD_F(0x06c85712) /* 0.423911161 */, 17 },
+ /* 3620 */ { MAD_F(0x06c8fad8) /* 0.424067348 */, 17 },
+ /* 3621 */ { MAD_F(0x06c99ea2) /* 0.424223550 */, 17 },
+ /* 3622 */ { MAD_F(0x06ca4270) /* 0.424379765 */, 17 },
+ /* 3623 */ { MAD_F(0x06cae641) /* 0.424535996 */, 17 },
+ /* 3624 */ { MAD_F(0x06cb8a17) /* 0.424692240 */, 17 },
+ /* 3625 */ { MAD_F(0x06cc2df0) /* 0.424848499 */, 17 },
+ /* 3626 */ { MAD_F(0x06ccd1ce) /* 0.425004772 */, 17 },
+ /* 3627 */ { MAD_F(0x06cd75af) /* 0.425161060 */, 17 },
+ /* 3628 */ { MAD_F(0x06ce1994) /* 0.425317362 */, 17 },
+ /* 3629 */ { MAD_F(0x06cebd7d) /* 0.425473678 */, 17 },
+ /* 3630 */ { MAD_F(0x06cf6169) /* 0.425630009 */, 17 },
+ /* 3631 */ { MAD_F(0x06d0055a) /* 0.425786354 */, 17 },
+
+ /* 3632 */ { MAD_F(0x06d0a94e) /* 0.425942714 */, 17 },
+ /* 3633 */ { MAD_F(0x06d14d47) /* 0.426099088 */, 17 },
+ /* 3634 */ { MAD_F(0x06d1f143) /* 0.426255476 */, 17 },
+ /* 3635 */ { MAD_F(0x06d29543) /* 0.426411878 */, 17 },
+ /* 3636 */ { MAD_F(0x06d33947) /* 0.426568295 */, 17 },
+ /* 3637 */ { MAD_F(0x06d3dd4e) /* 0.426724726 */, 17 },
+ /* 3638 */ { MAD_F(0x06d4815a) /* 0.426881172 */, 17 },
+ /* 3639 */ { MAD_F(0x06d52569) /* 0.427037632 */, 17 },
+ /* 3640 */ { MAD_F(0x06d5c97c) /* 0.427194106 */, 17 },
+ /* 3641 */ { MAD_F(0x06d66d93) /* 0.427350594 */, 17 },
+ /* 3642 */ { MAD_F(0x06d711ae) /* 0.427507097 */, 17 },
+ /* 3643 */ { MAD_F(0x06d7b5cd) /* 0.427663614 */, 17 },
+ /* 3644 */ { MAD_F(0x06d859f0) /* 0.427820146 */, 17 },
+ /* 3645 */ { MAD_F(0x06d8fe16) /* 0.427976692 */, 17 },
+ /* 3646 */ { MAD_F(0x06d9a240) /* 0.428133252 */, 17 },
+ /* 3647 */ { MAD_F(0x06da466f) /* 0.428289826 */, 17 },
+
+ /* 3648 */ { MAD_F(0x06daeaa1) /* 0.428446415 */, 17 },
+ /* 3649 */ { MAD_F(0x06db8ed6) /* 0.428603018 */, 17 },
+ /* 3650 */ { MAD_F(0x06dc3310) /* 0.428759635 */, 17 },
+ /* 3651 */ { MAD_F(0x06dcd74d) /* 0.428916267 */, 17 },
+ /* 3652 */ { MAD_F(0x06dd7b8f) /* 0.429072913 */, 17 },
+ /* 3653 */ { MAD_F(0x06de1fd4) /* 0.429229573 */, 17 },
+ /* 3654 */ { MAD_F(0x06dec41d) /* 0.429386248 */, 17 },
+ /* 3655 */ { MAD_F(0x06df686a) /* 0.429542937 */, 17 },
+ /* 3656 */ { MAD_F(0x06e00cbb) /* 0.429699640 */, 17 },
+ /* 3657 */ { MAD_F(0x06e0b10f) /* 0.429856357 */, 17 },
+ /* 3658 */ { MAD_F(0x06e15567) /* 0.430013089 */, 17 },
+ /* 3659 */ { MAD_F(0x06e1f9c4) /* 0.430169835 */, 17 },
+ /* 3660 */ { MAD_F(0x06e29e24) /* 0.430326595 */, 17 },
+ /* 3661 */ { MAD_F(0x06e34287) /* 0.430483370 */, 17 },
+ /* 3662 */ { MAD_F(0x06e3e6ef) /* 0.430640159 */, 17 },
+ /* 3663 */ { MAD_F(0x06e48b5b) /* 0.430796962 */, 17 },
+
+ /* 3664 */ { MAD_F(0x06e52fca) /* 0.430953779 */, 17 },
+ /* 3665 */ { MAD_F(0x06e5d43d) /* 0.431110611 */, 17 },
+ /* 3666 */ { MAD_F(0x06e678b4) /* 0.431267457 */, 17 },
+ /* 3667 */ { MAD_F(0x06e71d2f) /* 0.431424317 */, 17 },
+ /* 3668 */ { MAD_F(0x06e7c1ae) /* 0.431581192 */, 17 },
+ /* 3669 */ { MAD_F(0x06e86630) /* 0.431738080 */, 17 },
+ /* 3670 */ { MAD_F(0x06e90ab7) /* 0.431894983 */, 17 },
+ /* 3671 */ { MAD_F(0x06e9af41) /* 0.432051900 */, 17 },
+ /* 3672 */ { MAD_F(0x06ea53cf) /* 0.432208832 */, 17 },
+ /* 3673 */ { MAD_F(0x06eaf860) /* 0.432365778 */, 17 },
+ /* 3674 */ { MAD_F(0x06eb9cf6) /* 0.432522737 */, 17 },
+ /* 3675 */ { MAD_F(0x06ec418f) /* 0.432679712 */, 17 },
+ /* 3676 */ { MAD_F(0x06ece62d) /* 0.432836700 */, 17 },
+ /* 3677 */ { MAD_F(0x06ed8ace) /* 0.432993703 */, 17 },
+ /* 3678 */ { MAD_F(0x06ee2f73) /* 0.433150720 */, 17 },
+ /* 3679 */ { MAD_F(0x06eed41b) /* 0.433307751 */, 17 },
+
+ /* 3680 */ { MAD_F(0x06ef78c8) /* 0.433464796 */, 17 },
+ /* 3681 */ { MAD_F(0x06f01d78) /* 0.433621856 */, 17 },
+ /* 3682 */ { MAD_F(0x06f0c22c) /* 0.433778929 */, 17 },
+ /* 3683 */ { MAD_F(0x06f166e4) /* 0.433936017 */, 17 },
+ /* 3684 */ { MAD_F(0x06f20ba0) /* 0.434093120 */, 17 },
+ /* 3685 */ { MAD_F(0x06f2b060) /* 0.434250236 */, 17 },
+ /* 3686 */ { MAD_F(0x06f35523) /* 0.434407367 */, 17 },
+ /* 3687 */ { MAD_F(0x06f3f9eb) /* 0.434564512 */, 17 },
+ /* 3688 */ { MAD_F(0x06f49eb6) /* 0.434721671 */, 17 },
+ /* 3689 */ { MAD_F(0x06f54385) /* 0.434878844 */, 17 },
+ /* 3690 */ { MAD_F(0x06f5e857) /* 0.435036032 */, 17 },
+ /* 3691 */ { MAD_F(0x06f68d2e) /* 0.435193233 */, 17 },
+ /* 3692 */ { MAD_F(0x06f73208) /* 0.435350449 */, 17 },
+ /* 3693 */ { MAD_F(0x06f7d6e6) /* 0.435507679 */, 17 },
+ /* 3694 */ { MAD_F(0x06f87bc8) /* 0.435664924 */, 17 },
+ /* 3695 */ { MAD_F(0x06f920ae) /* 0.435822182 */, 17 },
+
+ /* 3696 */ { MAD_F(0x06f9c597) /* 0.435979455 */, 17 },
+ /* 3697 */ { MAD_F(0x06fa6a85) /* 0.436136741 */, 17 },
+ /* 3698 */ { MAD_F(0x06fb0f76) /* 0.436294042 */, 17 },
+ /* 3699 */ { MAD_F(0x06fbb46b) /* 0.436451358 */, 17 },
+ /* 3700 */ { MAD_F(0x06fc5964) /* 0.436608687 */, 17 },
+ /* 3701 */ { MAD_F(0x06fcfe60) /* 0.436766031 */, 17 },
+ /* 3702 */ { MAD_F(0x06fda361) /* 0.436923388 */, 17 },
+ /* 3703 */ { MAD_F(0x06fe4865) /* 0.437080760 */, 17 },
+ /* 3704 */ { MAD_F(0x06feed6d) /* 0.437238146 */, 17 },
+ /* 3705 */ { MAD_F(0x06ff9279) /* 0.437395547 */, 17 },
+ /* 3706 */ { MAD_F(0x07003788) /* 0.437552961 */, 17 },
+ /* 3707 */ { MAD_F(0x0700dc9c) /* 0.437710389 */, 17 },
+ /* 3708 */ { MAD_F(0x070181b3) /* 0.437867832 */, 17 },
+ /* 3709 */ { MAD_F(0x070226ce) /* 0.438025289 */, 17 },
+ /* 3710 */ { MAD_F(0x0702cbed) /* 0.438182760 */, 17 },
+ /* 3711 */ { MAD_F(0x0703710f) /* 0.438340245 */, 17 },
+
+ /* 3712 */ { MAD_F(0x07041636) /* 0.438497744 */, 17 },
+ /* 3713 */ { MAD_F(0x0704bb60) /* 0.438655258 */, 17 },
+ /* 3714 */ { MAD_F(0x0705608e) /* 0.438812785 */, 17 },
+ /* 3715 */ { MAD_F(0x070605c0) /* 0.438970327 */, 17 },
+ /* 3716 */ { MAD_F(0x0706aaf5) /* 0.439127883 */, 17 },
+ /* 3717 */ { MAD_F(0x0707502f) /* 0.439285453 */, 17 },
+ /* 3718 */ { MAD_F(0x0707f56c) /* 0.439443037 */, 17 },
+ /* 3719 */ { MAD_F(0x07089aad) /* 0.439600635 */, 17 },
+ /* 3720 */ { MAD_F(0x07093ff2) /* 0.439758248 */, 17 },
+ /* 3721 */ { MAD_F(0x0709e53a) /* 0.439915874 */, 17 },
+ /* 3722 */ { MAD_F(0x070a8a86) /* 0.440073515 */, 17 },
+ /* 3723 */ { MAD_F(0x070b2fd7) /* 0.440231170 */, 17 },
+ /* 3724 */ { MAD_F(0x070bd52a) /* 0.440388839 */, 17 },
+ /* 3725 */ { MAD_F(0x070c7a82) /* 0.440546522 */, 17 },
+ /* 3726 */ { MAD_F(0x070d1fde) /* 0.440704219 */, 17 },
+ /* 3727 */ { MAD_F(0x070dc53d) /* 0.440861930 */, 17 },
+
+ /* 3728 */ { MAD_F(0x070e6aa0) /* 0.441019655 */, 17 },
+ /* 3729 */ { MAD_F(0x070f1007) /* 0.441177395 */, 17 },
+ /* 3730 */ { MAD_F(0x070fb571) /* 0.441335148 */, 17 },
+ /* 3731 */ { MAD_F(0x07105ae0) /* 0.441492916 */, 17 },
+ /* 3732 */ { MAD_F(0x07110052) /* 0.441650697 */, 17 },
+ /* 3733 */ { MAD_F(0x0711a5c8) /* 0.441808493 */, 17 },
+ /* 3734 */ { MAD_F(0x07124b42) /* 0.441966303 */, 17 },
+ /* 3735 */ { MAD_F(0x0712f0bf) /* 0.442124127 */, 17 },
+ /* 3736 */ { MAD_F(0x07139641) /* 0.442281965 */, 17 },
+ /* 3737 */ { MAD_F(0x07143bc6) /* 0.442439817 */, 17 },
+ /* 3738 */ { MAD_F(0x0714e14f) /* 0.442597683 */, 17 },
+ /* 3739 */ { MAD_F(0x071586db) /* 0.442755564 */, 17 },
+ /* 3740 */ { MAD_F(0x07162c6c) /* 0.442913458 */, 17 },
+ /* 3741 */ { MAD_F(0x0716d200) /* 0.443071366 */, 17 },
+ /* 3742 */ { MAD_F(0x07177798) /* 0.443229289 */, 17 },
+ /* 3743 */ { MAD_F(0x07181d34) /* 0.443387226 */, 17 },
+
+ /* 3744 */ { MAD_F(0x0718c2d3) /* 0.443545176 */, 17 },
+ /* 3745 */ { MAD_F(0x07196877) /* 0.443703141 */, 17 },
+ /* 3746 */ { MAD_F(0x071a0e1e) /* 0.443861120 */, 17 },
+ /* 3747 */ { MAD_F(0x071ab3c9) /* 0.444019113 */, 17 },
+ /* 3748 */ { MAD_F(0x071b5977) /* 0.444177119 */, 17 },
+ /* 3749 */ { MAD_F(0x071bff2a) /* 0.444335140 */, 17 },
+ /* 3750 */ { MAD_F(0x071ca4e0) /* 0.444493175 */, 17 },
+ /* 3751 */ { MAD_F(0x071d4a9a) /* 0.444651224 */, 17 },
+ /* 3752 */ { MAD_F(0x071df058) /* 0.444809288 */, 17 },
+ /* 3753 */ { MAD_F(0x071e9619) /* 0.444967365 */, 17 },
+ /* 3754 */ { MAD_F(0x071f3bde) /* 0.445125456 */, 17 },
+ /* 3755 */ { MAD_F(0x071fe1a8) /* 0.445283561 */, 17 },
+ /* 3756 */ { MAD_F(0x07208774) /* 0.445441680 */, 17 },
+ /* 3757 */ { MAD_F(0x07212d45) /* 0.445599814 */, 17 },
+ /* 3758 */ { MAD_F(0x0721d319) /* 0.445757961 */, 17 },
+ /* 3759 */ { MAD_F(0x072278f1) /* 0.445916122 */, 17 },
+
+ /* 3760 */ { MAD_F(0x07231ecd) /* 0.446074298 */, 17 },
+ /* 3761 */ { MAD_F(0x0723c4ad) /* 0.446232487 */, 17 },
+ /* 3762 */ { MAD_F(0x07246a90) /* 0.446390690 */, 17 },
+ /* 3763 */ { MAD_F(0x07251077) /* 0.446548908 */, 17 },
+ /* 3764 */ { MAD_F(0x0725b662) /* 0.446707139 */, 17 },
+ /* 3765 */ { MAD_F(0x07265c51) /* 0.446865385 */, 17 },
+ /* 3766 */ { MAD_F(0x07270244) /* 0.447023644 */, 17 },
+ /* 3767 */ { MAD_F(0x0727a83a) /* 0.447181918 */, 17 },
+ /* 3768 */ { MAD_F(0x07284e34) /* 0.447340205 */, 17 },
+ /* 3769 */ { MAD_F(0x0728f431) /* 0.447498507 */, 17 },
+ /* 3770 */ { MAD_F(0x07299a33) /* 0.447656822 */, 17 },
+ /* 3771 */ { MAD_F(0x072a4038) /* 0.447815152 */, 17 },
+ /* 3772 */ { MAD_F(0x072ae641) /* 0.447973495 */, 17 },
+ /* 3773 */ { MAD_F(0x072b8c4e) /* 0.448131853 */, 17 },
+ /* 3774 */ { MAD_F(0x072c325e) /* 0.448290224 */, 17 },
+ /* 3775 */ { MAD_F(0x072cd873) /* 0.448448609 */, 17 },
+
+ /* 3776 */ { MAD_F(0x072d7e8b) /* 0.448607009 */, 17 },
+ /* 3777 */ { MAD_F(0x072e24a7) /* 0.448765422 */, 17 },
+ /* 3778 */ { MAD_F(0x072ecac6) /* 0.448923850 */, 17 },
+ /* 3779 */ { MAD_F(0x072f70e9) /* 0.449082291 */, 17 },
+ /* 3780 */ { MAD_F(0x07301710) /* 0.449240746 */, 17 },
+ /* 3781 */ { MAD_F(0x0730bd3b) /* 0.449399216 */, 17 },
+ /* 3782 */ { MAD_F(0x0731636a) /* 0.449557699 */, 17 },
+ /* 3783 */ { MAD_F(0x0732099c) /* 0.449716196 */, 17 },
+ /* 3784 */ { MAD_F(0x0732afd2) /* 0.449874708 */, 17 },
+ /* 3785 */ { MAD_F(0x0733560c) /* 0.450033233 */, 17 },
+ /* 3786 */ { MAD_F(0x0733fc49) /* 0.450191772 */, 17 },
+ /* 3787 */ { MAD_F(0x0734a28b) /* 0.450350325 */, 17 },
+ /* 3788 */ { MAD_F(0x073548d0) /* 0.450508892 */, 17 },
+ /* 3789 */ { MAD_F(0x0735ef18) /* 0.450667473 */, 17 },
+ /* 3790 */ { MAD_F(0x07369565) /* 0.450826068 */, 17 },
+ /* 3791 */ { MAD_F(0x07373bb5) /* 0.450984677 */, 17 },
+
+ /* 3792 */ { MAD_F(0x0737e209) /* 0.451143300 */, 17 },
+ /* 3793 */ { MAD_F(0x07388861) /* 0.451301937 */, 17 },
+ /* 3794 */ { MAD_F(0x07392ebc) /* 0.451460588 */, 17 },
+ /* 3795 */ { MAD_F(0x0739d51c) /* 0.451619252 */, 17 },
+ /* 3796 */ { MAD_F(0x073a7b7f) /* 0.451777931 */, 17 },
+ /* 3797 */ { MAD_F(0x073b21e5) /* 0.451936623 */, 17 },
+ /* 3798 */ { MAD_F(0x073bc850) /* 0.452095330 */, 17 },
+ /* 3799 */ { MAD_F(0x073c6ebe) /* 0.452254050 */, 17 },
+ /* 3800 */ { MAD_F(0x073d1530) /* 0.452412785 */, 17 },
+ /* 3801 */ { MAD_F(0x073dbba6) /* 0.452571533 */, 17 },
+ /* 3802 */ { MAD_F(0x073e621f) /* 0.452730295 */, 17 },
+ /* 3803 */ { MAD_F(0x073f089c) /* 0.452889071 */, 17 },
+ /* 3804 */ { MAD_F(0x073faf1d) /* 0.453047861 */, 17 },
+ /* 3805 */ { MAD_F(0x074055a2) /* 0.453206665 */, 17 },
+ /* 3806 */ { MAD_F(0x0740fc2a) /* 0.453365483 */, 17 },
+ /* 3807 */ { MAD_F(0x0741a2b6) /* 0.453524315 */, 17 },
+
+ /* 3808 */ { MAD_F(0x07424946) /* 0.453683161 */, 17 },
+ /* 3809 */ { MAD_F(0x0742efd9) /* 0.453842020 */, 17 },
+ /* 3810 */ { MAD_F(0x07439671) /* 0.454000894 */, 17 },
+ /* 3811 */ { MAD_F(0x07443d0c) /* 0.454159781 */, 17 },
+ /* 3812 */ { MAD_F(0x0744e3aa) /* 0.454318683 */, 17 },
+ /* 3813 */ { MAD_F(0x07458a4d) /* 0.454477598 */, 17 },
+ /* 3814 */ { MAD_F(0x074630f3) /* 0.454636527 */, 17 },
+ /* 3815 */ { MAD_F(0x0746d79d) /* 0.454795470 */, 17 },
+ /* 3816 */ { MAD_F(0x07477e4b) /* 0.454954427 */, 17 },
+ /* 3817 */ { MAD_F(0x074824fc) /* 0.455113397 */, 17 },
+ /* 3818 */ { MAD_F(0x0748cbb1) /* 0.455272382 */, 17 },
+ /* 3819 */ { MAD_F(0x0749726a) /* 0.455431381 */, 17 },
+ /* 3820 */ { MAD_F(0x074a1927) /* 0.455590393 */, 17 },
+ /* 3821 */ { MAD_F(0x074abfe7) /* 0.455749419 */, 17 },
+ /* 3822 */ { MAD_F(0x074b66ab) /* 0.455908459 */, 17 },
+ /* 3823 */ { MAD_F(0x074c0d73) /* 0.456067513 */, 17 },
+
+ /* 3824 */ { MAD_F(0x074cb43e) /* 0.456226581 */, 17 },
+ /* 3825 */ { MAD_F(0x074d5b0d) /* 0.456385663 */, 17 },
+ /* 3826 */ { MAD_F(0x074e01e0) /* 0.456544759 */, 17 },
+ /* 3827 */ { MAD_F(0x074ea8b7) /* 0.456703868 */, 17 },
+ /* 3828 */ { MAD_F(0x074f4f91) /* 0.456862992 */, 17 },
+ /* 3829 */ { MAD_F(0x074ff66f) /* 0.457022129 */, 17 },
+ /* 3830 */ { MAD_F(0x07509d51) /* 0.457181280 */, 17 },
+ /* 3831 */ { MAD_F(0x07514437) /* 0.457340445 */, 17 },
+ /* 3832 */ { MAD_F(0x0751eb20) /* 0.457499623 */, 17 },
+ /* 3833 */ { MAD_F(0x0752920d) /* 0.457658816 */, 17 },
+ /* 3834 */ { MAD_F(0x075338fd) /* 0.457818022 */, 17 },
+ /* 3835 */ { MAD_F(0x0753dff2) /* 0.457977243 */, 17 },
+ /* 3836 */ { MAD_F(0x075486ea) /* 0.458136477 */, 17 },
+ /* 3837 */ { MAD_F(0x07552de6) /* 0.458295725 */, 17 },
+ /* 3838 */ { MAD_F(0x0755d4e5) /* 0.458454987 */, 17 },
+ /* 3839 */ { MAD_F(0x07567be8) /* 0.458614262 */, 17 },
+
+ /* 3840 */ { MAD_F(0x075722ef) /* 0.458773552 */, 17 },
+ /* 3841 */ { MAD_F(0x0757c9fa) /* 0.458932855 */, 17 },
+ /* 3842 */ { MAD_F(0x07587108) /* 0.459092172 */, 17 },
+ /* 3843 */ { MAD_F(0x0759181a) /* 0.459251503 */, 17 },
+ /* 3844 */ { MAD_F(0x0759bf30) /* 0.459410848 */, 17 },
+ /* 3845 */ { MAD_F(0x075a664a) /* 0.459570206 */, 17 },
+ /* 3846 */ { MAD_F(0x075b0d67) /* 0.459729579 */, 17 },
+ /* 3847 */ { MAD_F(0x075bb488) /* 0.459888965 */, 17 },
+ /* 3848 */ { MAD_F(0x075c5bac) /* 0.460048365 */, 17 },
+ /* 3849 */ { MAD_F(0x075d02d5) /* 0.460207779 */, 17 },
+ /* 3850 */ { MAD_F(0x075daa01) /* 0.460367206 */, 17 },
+ /* 3851 */ { MAD_F(0x075e5130) /* 0.460526648 */, 17 },
+ /* 3852 */ { MAD_F(0x075ef864) /* 0.460686103 */, 17 },
+ /* 3853 */ { MAD_F(0x075f9f9b) /* 0.460845572 */, 17 },
+ /* 3854 */ { MAD_F(0x076046d6) /* 0.461005055 */, 17 },
+ /* 3855 */ { MAD_F(0x0760ee14) /* 0.461164552 */, 17 },
+
+ /* 3856 */ { MAD_F(0x07619557) /* 0.461324062 */, 17 },
+ /* 3857 */ { MAD_F(0x07623c9d) /* 0.461483586 */, 17 },
+ /* 3858 */ { MAD_F(0x0762e3e6) /* 0.461643124 */, 17 },
+ /* 3859 */ { MAD_F(0x07638b34) /* 0.461802676 */, 17 },
+ /* 3860 */ { MAD_F(0x07643285) /* 0.461962242 */, 17 },
+ /* 3861 */ { MAD_F(0x0764d9d9) /* 0.462121821 */, 17 },
+ /* 3862 */ { MAD_F(0x07658132) /* 0.462281414 */, 17 },
+ /* 3863 */ { MAD_F(0x0766288e) /* 0.462441021 */, 17 },
+ /* 3864 */ { MAD_F(0x0766cfee) /* 0.462600642 */, 17 },
+ /* 3865 */ { MAD_F(0x07677751) /* 0.462760276 */, 17 },
+ /* 3866 */ { MAD_F(0x07681eb9) /* 0.462919924 */, 17 },
+ /* 3867 */ { MAD_F(0x0768c624) /* 0.463079586 */, 17 },
+ /* 3868 */ { MAD_F(0x07696d92) /* 0.463239262 */, 17 },
+ /* 3869 */ { MAD_F(0x076a1505) /* 0.463398951 */, 17 },
+ /* 3870 */ { MAD_F(0x076abc7b) /* 0.463558655 */, 17 },
+ /* 3871 */ { MAD_F(0x076b63f4) /* 0.463718372 */, 17 },
+
+ /* 3872 */ { MAD_F(0x076c0b72) /* 0.463878102 */, 17 },
+ /* 3873 */ { MAD_F(0x076cb2f3) /* 0.464037847 */, 17 },
+ /* 3874 */ { MAD_F(0x076d5a78) /* 0.464197605 */, 17 },
+ /* 3875 */ { MAD_F(0x076e0200) /* 0.464357377 */, 17 },
+ /* 3876 */ { MAD_F(0x076ea98c) /* 0.464517163 */, 17 },
+ /* 3877 */ { MAD_F(0x076f511c) /* 0.464676962 */, 17 },
+ /* 3878 */ { MAD_F(0x076ff8b0) /* 0.464836776 */, 17 },
+ /* 3879 */ { MAD_F(0x0770a047) /* 0.464996603 */, 17 },
+ /* 3880 */ { MAD_F(0x077147e2) /* 0.465156443 */, 17 },
+ /* 3881 */ { MAD_F(0x0771ef80) /* 0.465316298 */, 17 },
+ /* 3882 */ { MAD_F(0x07729723) /* 0.465476166 */, 17 },
+ /* 3883 */ { MAD_F(0x07733ec9) /* 0.465636048 */, 17 },
+ /* 3884 */ { MAD_F(0x0773e672) /* 0.465795943 */, 17 },
+ /* 3885 */ { MAD_F(0x07748e20) /* 0.465955853 */, 17 },
+ /* 3886 */ { MAD_F(0x077535d1) /* 0.466115776 */, 17 },
+ /* 3887 */ { MAD_F(0x0775dd85) /* 0.466275713 */, 17 },
+
+ /* 3888 */ { MAD_F(0x0776853e) /* 0.466435663 */, 17 },
+ /* 3889 */ { MAD_F(0x07772cfa) /* 0.466595627 */, 17 },
+ /* 3890 */ { MAD_F(0x0777d4ba) /* 0.466755605 */, 17 },
+ /* 3891 */ { MAD_F(0x07787c7d) /* 0.466915597 */, 17 },
+ /* 3892 */ { MAD_F(0x07792444) /* 0.467075602 */, 17 },
+ /* 3893 */ { MAD_F(0x0779cc0f) /* 0.467235621 */, 17 },
+ /* 3894 */ { MAD_F(0x077a73dd) /* 0.467395654 */, 17 },
+ /* 3895 */ { MAD_F(0x077b1baf) /* 0.467555701 */, 17 },
+ /* 3896 */ { MAD_F(0x077bc385) /* 0.467715761 */, 17 },
+ /* 3897 */ { MAD_F(0x077c6b5f) /* 0.467875835 */, 17 },
+ /* 3898 */ { MAD_F(0x077d133c) /* 0.468035922 */, 17 },
+ /* 3899 */ { MAD_F(0x077dbb1d) /* 0.468196023 */, 17 },
+ /* 3900 */ { MAD_F(0x077e6301) /* 0.468356138 */, 17 },
+ /* 3901 */ { MAD_F(0x077f0ae9) /* 0.468516267 */, 17 },
+ /* 3902 */ { MAD_F(0x077fb2d5) /* 0.468676409 */, 17 },
+ /* 3903 */ { MAD_F(0x07805ac5) /* 0.468836565 */, 17 },
+
+ /* 3904 */ { MAD_F(0x078102b8) /* 0.468996735 */, 17 },
+ /* 3905 */ { MAD_F(0x0781aaaf) /* 0.469156918 */, 17 },
+ /* 3906 */ { MAD_F(0x078252aa) /* 0.469317115 */, 17 },
+ /* 3907 */ { MAD_F(0x0782faa8) /* 0.469477326 */, 17 },
+ /* 3908 */ { MAD_F(0x0783a2aa) /* 0.469637550 */, 17 },
+ /* 3909 */ { MAD_F(0x07844aaf) /* 0.469797788 */, 17 },
+ /* 3910 */ { MAD_F(0x0784f2b8) /* 0.469958040 */, 17 },
+ /* 3911 */ { MAD_F(0x07859ac5) /* 0.470118305 */, 17 },
+ /* 3912 */ { MAD_F(0x078642d6) /* 0.470278584 */, 17 },
+ /* 3913 */ { MAD_F(0x0786eaea) /* 0.470438877 */, 17 },
+ /* 3914 */ { MAD_F(0x07879302) /* 0.470599183 */, 17 },
+ /* 3915 */ { MAD_F(0x07883b1e) /* 0.470759503 */, 17 },
+ /* 3916 */ { MAD_F(0x0788e33d) /* 0.470919836 */, 17 },
+ /* 3917 */ { MAD_F(0x07898b60) /* 0.471080184 */, 17 },
+ /* 3918 */ { MAD_F(0x078a3386) /* 0.471240545 */, 17 },
+ /* 3919 */ { MAD_F(0x078adbb0) /* 0.471400919 */, 17 },
+
+ /* 3920 */ { MAD_F(0x078b83de) /* 0.471561307 */, 17 },
+ /* 3921 */ { MAD_F(0x078c2c10) /* 0.471721709 */, 17 },
+ /* 3922 */ { MAD_F(0x078cd445) /* 0.471882125 */, 17 },
+ /* 3923 */ { MAD_F(0x078d7c7e) /* 0.472042554 */, 17 },
+ /* 3924 */ { MAD_F(0x078e24ba) /* 0.472202996 */, 17 },
+ /* 3925 */ { MAD_F(0x078eccfb) /* 0.472363453 */, 17 },
+ /* 3926 */ { MAD_F(0x078f753e) /* 0.472523923 */, 17 },
+ /* 3927 */ { MAD_F(0x07901d86) /* 0.472684406 */, 17 },
+ /* 3928 */ { MAD_F(0x0790c5d1) /* 0.472844904 */, 17 },
+ /* 3929 */ { MAD_F(0x07916e20) /* 0.473005414 */, 17 },
+ /* 3930 */ { MAD_F(0x07921672) /* 0.473165939 */, 17 },
+ /* 3931 */ { MAD_F(0x0792bec8) /* 0.473326477 */, 17 },
+ /* 3932 */ { MAD_F(0x07936722) /* 0.473487029 */, 17 },
+ /* 3933 */ { MAD_F(0x07940f80) /* 0.473647594 */, 17 },
+ /* 3934 */ { MAD_F(0x0794b7e1) /* 0.473808173 */, 17 },
+ /* 3935 */ { MAD_F(0x07956045) /* 0.473968765 */, 17 },
+
+ /* 3936 */ { MAD_F(0x079608ae) /* 0.474129372 */, 17 },
+ /* 3937 */ { MAD_F(0x0796b11a) /* 0.474289991 */, 17 },
+ /* 3938 */ { MAD_F(0x0797598a) /* 0.474450625 */, 17 },
+ /* 3939 */ { MAD_F(0x079801fd) /* 0.474611272 */, 17 },
+ /* 3940 */ { MAD_F(0x0798aa74) /* 0.474771932 */, 17 },
+ /* 3941 */ { MAD_F(0x079952ee) /* 0.474932606 */, 17 },
+ /* 3942 */ { MAD_F(0x0799fb6d) /* 0.475093294 */, 17 },
+ /* 3943 */ { MAD_F(0x079aa3ef) /* 0.475253995 */, 17 },
+ /* 3944 */ { MAD_F(0x079b4c74) /* 0.475414710 */, 17 },
+ /* 3945 */ { MAD_F(0x079bf4fd) /* 0.475575439 */, 17 },
+ /* 3946 */ { MAD_F(0x079c9d8a) /* 0.475736181 */, 17 },
+ /* 3947 */ { MAD_F(0x079d461b) /* 0.475896936 */, 17 },
+ /* 3948 */ { MAD_F(0x079deeaf) /* 0.476057705 */, 17 },
+ /* 3949 */ { MAD_F(0x079e9747) /* 0.476218488 */, 17 },
+ /* 3950 */ { MAD_F(0x079f3fe2) /* 0.476379285 */, 17 },
+ /* 3951 */ { MAD_F(0x079fe881) /* 0.476540095 */, 17 },
+
+ /* 3952 */ { MAD_F(0x07a09124) /* 0.476700918 */, 17 },
+ /* 3953 */ { MAD_F(0x07a139ca) /* 0.476861755 */, 17 },
+ /* 3954 */ { MAD_F(0x07a1e274) /* 0.477022606 */, 17 },
+ /* 3955 */ { MAD_F(0x07a28b22) /* 0.477183470 */, 17 },
+ /* 3956 */ { MAD_F(0x07a333d3) /* 0.477344348 */, 17 },
+ /* 3957 */ { MAD_F(0x07a3dc88) /* 0.477505239 */, 17 },
+ /* 3958 */ { MAD_F(0x07a48541) /* 0.477666144 */, 17 },
+ /* 3959 */ { MAD_F(0x07a52dfd) /* 0.477827062 */, 17 },
+ /* 3960 */ { MAD_F(0x07a5d6bd) /* 0.477987994 */, 17 },
+ /* 3961 */ { MAD_F(0x07a67f80) /* 0.478148940 */, 17 },
+ /* 3962 */ { MAD_F(0x07a72847) /* 0.478309899 */, 17 },
+ /* 3963 */ { MAD_F(0x07a7d112) /* 0.478470871 */, 17 },
+ /* 3964 */ { MAD_F(0x07a879e1) /* 0.478631857 */, 17 },
+ /* 3965 */ { MAD_F(0x07a922b3) /* 0.478792857 */, 17 },
+ /* 3966 */ { MAD_F(0x07a9cb88) /* 0.478953870 */, 17 },
+ /* 3967 */ { MAD_F(0x07aa7462) /* 0.479114897 */, 17 },
+
+ /* 3968 */ { MAD_F(0x07ab1d3e) /* 0.479275937 */, 17 },
+ /* 3969 */ { MAD_F(0x07abc61f) /* 0.479436991 */, 17 },
+ /* 3970 */ { MAD_F(0x07ac6f03) /* 0.479598058 */, 17 },
+ /* 3971 */ { MAD_F(0x07ad17eb) /* 0.479759139 */, 17 },
+ /* 3972 */ { MAD_F(0x07adc0d6) /* 0.479920233 */, 17 },
+ /* 3973 */ { MAD_F(0x07ae69c6) /* 0.480081341 */, 17 },
+ /* 3974 */ { MAD_F(0x07af12b8) /* 0.480242463 */, 17 },
+ /* 3975 */ { MAD_F(0x07afbbaf) /* 0.480403598 */, 17 },
+ /* 3976 */ { MAD_F(0x07b064a8) /* 0.480564746 */, 17 },
+ /* 3977 */ { MAD_F(0x07b10da6) /* 0.480725908 */, 17 },
+ /* 3978 */ { MAD_F(0x07b1b6a7) /* 0.480887083 */, 17 },
+ /* 3979 */ { MAD_F(0x07b25fac) /* 0.481048272 */, 17 },
+ /* 3980 */ { MAD_F(0x07b308b5) /* 0.481209475 */, 17 },
+ /* 3981 */ { MAD_F(0x07b3b1c1) /* 0.481370691 */, 17 },
+ /* 3982 */ { MAD_F(0x07b45ad0) /* 0.481531920 */, 17 },
+ /* 3983 */ { MAD_F(0x07b503e4) /* 0.481693163 */, 17 },
+
+ /* 3984 */ { MAD_F(0x07b5acfb) /* 0.481854420 */, 17 },
+ /* 3985 */ { MAD_F(0x07b65615) /* 0.482015690 */, 17 },
+ /* 3986 */ { MAD_F(0x07b6ff33) /* 0.482176973 */, 17 },
+ /* 3987 */ { MAD_F(0x07b7a855) /* 0.482338270 */, 17 },
+ /* 3988 */ { MAD_F(0x07b8517b) /* 0.482499580 */, 17 },
+ /* 3989 */ { MAD_F(0x07b8faa4) /* 0.482660904 */, 17 },
+ /* 3990 */ { MAD_F(0x07b9a3d0) /* 0.482822242 */, 17 },
+ /* 3991 */ { MAD_F(0x07ba4d01) /* 0.482983592 */, 17 },
+ /* 3992 */ { MAD_F(0x07baf635) /* 0.483144957 */, 17 },
+ /* 3993 */ { MAD_F(0x07bb9f6c) /* 0.483306335 */, 17 },
+ /* 3994 */ { MAD_F(0x07bc48a7) /* 0.483467726 */, 17 },
+ /* 3995 */ { MAD_F(0x07bcf1e6) /* 0.483629131 */, 17 },
+ /* 3996 */ { MAD_F(0x07bd9b28) /* 0.483790549 */, 17 },
+ /* 3997 */ { MAD_F(0x07be446e) /* 0.483951980 */, 17 },
+ /* 3998 */ { MAD_F(0x07beedb8) /* 0.484113426 */, 17 },
+ /* 3999 */ { MAD_F(0x07bf9705) /* 0.484274884 */, 17 },
+
+ /* 4000 */ { MAD_F(0x07c04056) /* 0.484436356 */, 17 },
+ /* 4001 */ { MAD_F(0x07c0e9aa) /* 0.484597842 */, 17 },
+ /* 4002 */ { MAD_F(0x07c19302) /* 0.484759341 */, 17 },
+ /* 4003 */ { MAD_F(0x07c23c5e) /* 0.484920853 */, 17 },
+ /* 4004 */ { MAD_F(0x07c2e5bd) /* 0.485082379 */, 17 },
+ /* 4005 */ { MAD_F(0x07c38f20) /* 0.485243918 */, 17 },
+ /* 4006 */ { MAD_F(0x07c43887) /* 0.485405471 */, 17 },
+ /* 4007 */ { MAD_F(0x07c4e1f1) /* 0.485567037 */, 17 },
+ /* 4008 */ { MAD_F(0x07c58b5f) /* 0.485728617 */, 17 },
+ /* 4009 */ { MAD_F(0x07c634d0) /* 0.485890210 */, 17 },
+ /* 4010 */ { MAD_F(0x07c6de45) /* 0.486051817 */, 17 },
+ /* 4011 */ { MAD_F(0x07c787bd) /* 0.486213436 */, 17 },
+ /* 4012 */ { MAD_F(0x07c83139) /* 0.486375070 */, 17 },
+ /* 4013 */ { MAD_F(0x07c8dab9) /* 0.486536717 */, 17 },
+ /* 4014 */ { MAD_F(0x07c9843c) /* 0.486698377 */, 17 },
+ /* 4015 */ { MAD_F(0x07ca2dc3) /* 0.486860051 */, 17 },
+
+ /* 4016 */ { MAD_F(0x07cad74e) /* 0.487021738 */, 17 },
+ /* 4017 */ { MAD_F(0x07cb80dc) /* 0.487183438 */, 17 },
+ /* 4018 */ { MAD_F(0x07cc2a6e) /* 0.487345152 */, 17 },
+ /* 4019 */ { MAD_F(0x07ccd403) /* 0.487506879 */, 17 },
+ /* 4020 */ { MAD_F(0x07cd7d9c) /* 0.487668620 */, 17 },
+ /* 4021 */ { MAD_F(0x07ce2739) /* 0.487830374 */, 17 },
+ /* 4022 */ { MAD_F(0x07ced0d9) /* 0.487992142 */, 17 },
+ /* 4023 */ { MAD_F(0x07cf7a7d) /* 0.488153923 */, 17 },
+ /* 4024 */ { MAD_F(0x07d02424) /* 0.488315717 */, 17 },
+ /* 4025 */ { MAD_F(0x07d0cdcf) /* 0.488477525 */, 17 },
+ /* 4026 */ { MAD_F(0x07d1777e) /* 0.488639346 */, 17 },
+ /* 4027 */ { MAD_F(0x07d22130) /* 0.488801181 */, 17 },
+ /* 4028 */ { MAD_F(0x07d2cae5) /* 0.488963029 */, 17 },
+ /* 4029 */ { MAD_F(0x07d3749f) /* 0.489124890 */, 17 },
+ /* 4030 */ { MAD_F(0x07d41e5c) /* 0.489286765 */, 17 },
+ /* 4031 */ { MAD_F(0x07d4c81c) /* 0.489448653 */, 17 },
+
+ /* 4032 */ { MAD_F(0x07d571e0) /* 0.489610555 */, 17 },
+ /* 4033 */ { MAD_F(0x07d61ba8) /* 0.489772470 */, 17 },
+ /* 4034 */ { MAD_F(0x07d6c573) /* 0.489934398 */, 17 },
+ /* 4035 */ { MAD_F(0x07d76f42) /* 0.490096340 */, 17 },
+ /* 4036 */ { MAD_F(0x07d81915) /* 0.490258295 */, 17 },
+ /* 4037 */ { MAD_F(0x07d8c2eb) /* 0.490420263 */, 17 },
+ /* 4038 */ { MAD_F(0x07d96cc4) /* 0.490582245 */, 17 },
+ /* 4039 */ { MAD_F(0x07da16a2) /* 0.490744240 */, 17 },
+ /* 4040 */ { MAD_F(0x07dac083) /* 0.490906249 */, 17 },
+ /* 4041 */ { MAD_F(0x07db6a67) /* 0.491068271 */, 17 },
+ /* 4042 */ { MAD_F(0x07dc144f) /* 0.491230306 */, 17 },
+ /* 4043 */ { MAD_F(0x07dcbe3b) /* 0.491392355 */, 17 },
+ /* 4044 */ { MAD_F(0x07dd682a) /* 0.491554417 */, 17 },
+ /* 4045 */ { MAD_F(0x07de121d) /* 0.491716492 */, 17 },
+ /* 4046 */ { MAD_F(0x07debc13) /* 0.491878581 */, 17 },
+ /* 4047 */ { MAD_F(0x07df660d) /* 0.492040683 */, 17 },
+
+ /* 4048 */ { MAD_F(0x07e0100a) /* 0.492202799 */, 17 },
+ /* 4049 */ { MAD_F(0x07e0ba0c) /* 0.492364928 */, 17 },
+ /* 4050 */ { MAD_F(0x07e16410) /* 0.492527070 */, 17 },
+ /* 4051 */ { MAD_F(0x07e20e19) /* 0.492689225 */, 17 },
+ /* 4052 */ { MAD_F(0x07e2b824) /* 0.492851394 */, 17 },
+ /* 4053 */ { MAD_F(0x07e36234) /* 0.493013576 */, 17 },
+ /* 4054 */ { MAD_F(0x07e40c47) /* 0.493175772 */, 17 },
+ /* 4055 */ { MAD_F(0x07e4b65e) /* 0.493337981 */, 17 },
+ /* 4056 */ { MAD_F(0x07e56078) /* 0.493500203 */, 17 },
+ /* 4057 */ { MAD_F(0x07e60a95) /* 0.493662438 */, 17 },
+ /* 4058 */ { MAD_F(0x07e6b4b7) /* 0.493824687 */, 17 },
+ /* 4059 */ { MAD_F(0x07e75edc) /* 0.493986949 */, 17 },
+ /* 4060 */ { MAD_F(0x07e80904) /* 0.494149225 */, 17 },
+ /* 4061 */ { MAD_F(0x07e8b330) /* 0.494311514 */, 17 },
+ /* 4062 */ { MAD_F(0x07e95d60) /* 0.494473816 */, 17 },
+ /* 4063 */ { MAD_F(0x07ea0793) /* 0.494636131 */, 17 },
+
+ /* 4064 */ { MAD_F(0x07eab1ca) /* 0.494798460 */, 17 },
+ /* 4065 */ { MAD_F(0x07eb5c04) /* 0.494960802 */, 17 },
+ /* 4066 */ { MAD_F(0x07ec0642) /* 0.495123158 */, 17 },
+ /* 4067 */ { MAD_F(0x07ecb084) /* 0.495285526 */, 17 },
+ /* 4068 */ { MAD_F(0x07ed5ac9) /* 0.495447908 */, 17 },
+ /* 4069 */ { MAD_F(0x07ee0512) /* 0.495610304 */, 17 },
+ /* 4070 */ { MAD_F(0x07eeaf5e) /* 0.495772712 */, 17 },
+ /* 4071 */ { MAD_F(0x07ef59ae) /* 0.495935134 */, 17 },
+ /* 4072 */ { MAD_F(0x07f00401) /* 0.496097570 */, 17 },
+ /* 4073 */ { MAD_F(0x07f0ae58) /* 0.496260018 */, 17 },
+ /* 4074 */ { MAD_F(0x07f158b3) /* 0.496422480 */, 17 },
+ /* 4075 */ { MAD_F(0x07f20311) /* 0.496584955 */, 17 },
+ /* 4076 */ { MAD_F(0x07f2ad72) /* 0.496747444 */, 17 },
+ /* 4077 */ { MAD_F(0x07f357d8) /* 0.496909945 */, 17 },
+ /* 4078 */ { MAD_F(0x07f40240) /* 0.497072460 */, 17 },
+ /* 4079 */ { MAD_F(0x07f4acad) /* 0.497234989 */, 17 },
+
+ /* 4080 */ { MAD_F(0x07f5571d) /* 0.497397530 */, 17 },
+ /* 4081 */ { MAD_F(0x07f60190) /* 0.497560085 */, 17 },
+ /* 4082 */ { MAD_F(0x07f6ac07) /* 0.497722653 */, 17 },
+ /* 4083 */ { MAD_F(0x07f75682) /* 0.497885235 */, 17 },
+ /* 4084 */ { MAD_F(0x07f80100) /* 0.498047829 */, 17 },
+ /* 4085 */ { MAD_F(0x07f8ab82) /* 0.498210437 */, 17 },
+ /* 4086 */ { MAD_F(0x07f95607) /* 0.498373058 */, 17 },
+ /* 4087 */ { MAD_F(0x07fa0090) /* 0.498535693 */, 17 },
+ /* 4088 */ { MAD_F(0x07faab1c) /* 0.498698341 */, 17 },
+ /* 4089 */ { MAD_F(0x07fb55ac) /* 0.498861002 */, 17 },
+ /* 4090 */ { MAD_F(0x07fc0040) /* 0.499023676 */, 17 },
+ /* 4091 */ { MAD_F(0x07fcaad7) /* 0.499186364 */, 17 },
+ /* 4092 */ { MAD_F(0x07fd5572) /* 0.499349064 */, 17 },
+ /* 4093 */ { MAD_F(0x07fe0010) /* 0.499511778 */, 17 },
+ /* 4094 */ { MAD_F(0x07feaab2) /* 0.499674506 */, 17 },
+ /* 4095 */ { MAD_F(0x07ff5557) /* 0.499837246 */, 17 },
+
+ /* 4096 */ { MAD_F(0x04000000) /* 0.250000000 */, 18 },
+ /* 4097 */ { MAD_F(0x04005556) /* 0.250081384 */, 18 },
+ /* 4098 */ { MAD_F(0x0400aaae) /* 0.250162774 */, 18 },
+ /* 4099 */ { MAD_F(0x04010008) /* 0.250244170 */, 18 },
+ /* 4100 */ { MAD_F(0x04015563) /* 0.250325574 */, 18 },
+ /* 4101 */ { MAD_F(0x0401aac1) /* 0.250406984 */, 18 },
+ /* 4102 */ { MAD_F(0x04020020) /* 0.250488400 */, 18 },
+ /* 4103 */ { MAD_F(0x04025581) /* 0.250569824 */, 18 },
+ /* 4104 */ { MAD_F(0x0402aae3) /* 0.250651254 */, 18 },
+ /* 4105 */ { MAD_F(0x04030048) /* 0.250732690 */, 18 },
+ /* 4106 */ { MAD_F(0x040355ae) /* 0.250814133 */, 18 },
+ /* 4107 */ { MAD_F(0x0403ab16) /* 0.250895583 */, 18 },
+ /* 4108 */ { MAD_F(0x04040080) /* 0.250977039 */, 18 },
+ /* 4109 */ { MAD_F(0x040455eb) /* 0.251058502 */, 18 },
+ /* 4110 */ { MAD_F(0x0404ab59) /* 0.251139971 */, 18 },
+ /* 4111 */ { MAD_F(0x040500c8) /* 0.251221448 */, 18 },
+
+ /* 4112 */ { MAD_F(0x04055638) /* 0.251302930 */, 18 },
+ /* 4113 */ { MAD_F(0x0405abab) /* 0.251384420 */, 18 },
+ /* 4114 */ { MAD_F(0x0406011f) /* 0.251465916 */, 18 },
+ /* 4115 */ { MAD_F(0x04065696) /* 0.251547418 */, 18 },
+ /* 4116 */ { MAD_F(0x0406ac0e) /* 0.251628927 */, 18 },
+ /* 4117 */ { MAD_F(0x04070187) /* 0.251710443 */, 18 },
+ /* 4118 */ { MAD_F(0x04075703) /* 0.251791965 */, 18 },
+ /* 4119 */ { MAD_F(0x0407ac80) /* 0.251873494 */, 18 },
+ /* 4120 */ { MAD_F(0x040801ff) /* 0.251955030 */, 18 },
+ /* 4121 */ { MAD_F(0x04085780) /* 0.252036572 */, 18 },
+ /* 4122 */ { MAD_F(0x0408ad02) /* 0.252118121 */, 18 },
+ /* 4123 */ { MAD_F(0x04090287) /* 0.252199676 */, 18 },
+ /* 4124 */ { MAD_F(0x0409580d) /* 0.252281238 */, 18 },
+ /* 4125 */ { MAD_F(0x0409ad95) /* 0.252362807 */, 18 },
+ /* 4126 */ { MAD_F(0x040a031e) /* 0.252444382 */, 18 },
+ /* 4127 */ { MAD_F(0x040a58aa) /* 0.252525963 */, 18 },
+
+ /* 4128 */ { MAD_F(0x040aae37) /* 0.252607552 */, 18 },
+ /* 4129 */ { MAD_F(0x040b03c6) /* 0.252689147 */, 18 },
+ /* 4130 */ { MAD_F(0x040b5957) /* 0.252770748 */, 18 },
+ /* 4131 */ { MAD_F(0x040baee9) /* 0.252852356 */, 18 },
+ /* 4132 */ { MAD_F(0x040c047e) /* 0.252933971 */, 18 },
+ /* 4133 */ { MAD_F(0x040c5a14) /* 0.253015592 */, 18 },
+ /* 4134 */ { MAD_F(0x040cafab) /* 0.253097220 */, 18 },
+ /* 4135 */ { MAD_F(0x040d0545) /* 0.253178854 */, 18 },
+ /* 4136 */ { MAD_F(0x040d5ae0) /* 0.253260495 */, 18 },
+ /* 4137 */ { MAD_F(0x040db07d) /* 0.253342143 */, 18 },
+ /* 4138 */ { MAD_F(0x040e061c) /* 0.253423797 */, 18 },
+ /* 4139 */ { MAD_F(0x040e5bbd) /* 0.253505457 */, 18 },
+ /* 4140 */ { MAD_F(0x040eb15f) /* 0.253587125 */, 18 },
+ /* 4141 */ { MAD_F(0x040f0703) /* 0.253668799 */, 18 },
+ /* 4142 */ { MAD_F(0x040f5ca9) /* 0.253750479 */, 18 },
+ /* 4143 */ { MAD_F(0x040fb251) /* 0.253832166 */, 18 },
+
+ /* 4144 */ { MAD_F(0x041007fa) /* 0.253913860 */, 18 },
+ /* 4145 */ { MAD_F(0x04105da6) /* 0.253995560 */, 18 },
+ /* 4146 */ { MAD_F(0x0410b353) /* 0.254077266 */, 18 },
+ /* 4147 */ { MAD_F(0x04110901) /* 0.254158980 */, 18 },
+ /* 4148 */ { MAD_F(0x04115eb2) /* 0.254240700 */, 18 },
+ /* 4149 */ { MAD_F(0x0411b464) /* 0.254322426 */, 18 },
+ /* 4150 */ { MAD_F(0x04120a18) /* 0.254404159 */, 18 },
+ /* 4151 */ { MAD_F(0x04125fce) /* 0.254485899 */, 18 },
+ /* 4152 */ { MAD_F(0x0412b586) /* 0.254567645 */, 18 },
+ /* 4153 */ { MAD_F(0x04130b3f) /* 0.254649397 */, 18 },
+ /* 4154 */ { MAD_F(0x041360fa) /* 0.254731157 */, 18 },
+ /* 4155 */ { MAD_F(0x0413b6b7) /* 0.254812922 */, 18 },
+ /* 4156 */ { MAD_F(0x04140c75) /* 0.254894695 */, 18 },
+ /* 4157 */ { MAD_F(0x04146236) /* 0.254976474 */, 18 },
+ /* 4158 */ { MAD_F(0x0414b7f8) /* 0.255058259 */, 18 },
+ /* 4159 */ { MAD_F(0x04150dbc) /* 0.255140051 */, 18 },
+
+ /* 4160 */ { MAD_F(0x04156381) /* 0.255221850 */, 18 },
+ /* 4161 */ { MAD_F(0x0415b949) /* 0.255303655 */, 18 },
+ /* 4162 */ { MAD_F(0x04160f12) /* 0.255385467 */, 18 },
+ /* 4163 */ { MAD_F(0x041664dd) /* 0.255467285 */, 18 },
+ /* 4164 */ { MAD_F(0x0416baaa) /* 0.255549110 */, 18 },
+ /* 4165 */ { MAD_F(0x04171078) /* 0.255630941 */, 18 },
+ /* 4166 */ { MAD_F(0x04176648) /* 0.255712779 */, 18 },
+ /* 4167 */ { MAD_F(0x0417bc1a) /* 0.255794624 */, 18 },
+ /* 4168 */ { MAD_F(0x041811ee) /* 0.255876475 */, 18 },
+ /* 4169 */ { MAD_F(0x041867c3) /* 0.255958332 */, 18 },
+ /* 4170 */ { MAD_F(0x0418bd9b) /* 0.256040196 */, 18 },
+ /* 4171 */ { MAD_F(0x04191374) /* 0.256122067 */, 18 },
+ /* 4172 */ { MAD_F(0x0419694e) /* 0.256203944 */, 18 },
+ /* 4173 */ { MAD_F(0x0419bf2b) /* 0.256285828 */, 18 },
+ /* 4174 */ { MAD_F(0x041a1509) /* 0.256367718 */, 18 },
+ /* 4175 */ { MAD_F(0x041a6ae9) /* 0.256449615 */, 18 },
+
+ /* 4176 */ { MAD_F(0x041ac0cb) /* 0.256531518 */, 18 },
+ /* 4177 */ { MAD_F(0x041b16ae) /* 0.256613428 */, 18 },
+ /* 4178 */ { MAD_F(0x041b6c94) /* 0.256695344 */, 18 },
+ /* 4179 */ { MAD_F(0x041bc27b) /* 0.256777267 */, 18 },
+ /* 4180 */ { MAD_F(0x041c1863) /* 0.256859197 */, 18 },
+ /* 4181 */ { MAD_F(0x041c6e4e) /* 0.256941133 */, 18 },
+ /* 4182 */ { MAD_F(0x041cc43a) /* 0.257023076 */, 18 },
+ /* 4183 */ { MAD_F(0x041d1a28) /* 0.257105025 */, 18 },
+ /* 4184 */ { MAD_F(0x041d7018) /* 0.257186980 */, 18 },
+ /* 4185 */ { MAD_F(0x041dc60a) /* 0.257268942 */, 18 },
+ /* 4186 */ { MAD_F(0x041e1bfd) /* 0.257350911 */, 18 },
+ /* 4187 */ { MAD_F(0x041e71f2) /* 0.257432886 */, 18 },
+ /* 4188 */ { MAD_F(0x041ec7e9) /* 0.257514868 */, 18 },
+ /* 4189 */ { MAD_F(0x041f1de1) /* 0.257596856 */, 18 },
+ /* 4190 */ { MAD_F(0x041f73dc) /* 0.257678851 */, 18 },
+ /* 4191 */ { MAD_F(0x041fc9d8) /* 0.257760852 */, 18 },
+
+ /* 4192 */ { MAD_F(0x04201fd5) /* 0.257842860 */, 18 },
+ /* 4193 */ { MAD_F(0x042075d5) /* 0.257924875 */, 18 },
+ /* 4194 */ { MAD_F(0x0420cbd6) /* 0.258006895 */, 18 },
+ /* 4195 */ { MAD_F(0x042121d9) /* 0.258088923 */, 18 },
+ /* 4196 */ { MAD_F(0x042177de) /* 0.258170957 */, 18 },
+ /* 4197 */ { MAD_F(0x0421cde5) /* 0.258252997 */, 18 },
+ /* 4198 */ { MAD_F(0x042223ed) /* 0.258335044 */, 18 },
+ /* 4199 */ { MAD_F(0x042279f7) /* 0.258417097 */, 18 },
+ /* 4200 */ { MAD_F(0x0422d003) /* 0.258499157 */, 18 },
+ /* 4201 */ { MAD_F(0x04232611) /* 0.258581224 */, 18 },
+ /* 4202 */ { MAD_F(0x04237c20) /* 0.258663297 */, 18 },
+ /* 4203 */ { MAD_F(0x0423d231) /* 0.258745376 */, 18 },
+ /* 4204 */ { MAD_F(0x04242844) /* 0.258827462 */, 18 },
+ /* 4205 */ { MAD_F(0x04247e58) /* 0.258909555 */, 18 },
+ /* 4206 */ { MAD_F(0x0424d46e) /* 0.258991654 */, 18 },
+ /* 4207 */ { MAD_F(0x04252a87) /* 0.259073760 */, 18 },
+
+ /* 4208 */ { MAD_F(0x042580a0) /* 0.259155872 */, 18 },
+ /* 4209 */ { MAD_F(0x0425d6bc) /* 0.259237990 */, 18 },
+ /* 4210 */ { MAD_F(0x04262cd9) /* 0.259320115 */, 18 },
+ /* 4211 */ { MAD_F(0x042682f8) /* 0.259402247 */, 18 },
+ /* 4212 */ { MAD_F(0x0426d919) /* 0.259484385 */, 18 },
+ /* 4213 */ { MAD_F(0x04272f3b) /* 0.259566529 */, 18 },
+ /* 4214 */ { MAD_F(0x04278560) /* 0.259648680 */, 18 },
+ /* 4215 */ { MAD_F(0x0427db86) /* 0.259730838 */, 18 },
+ /* 4216 */ { MAD_F(0x042831ad) /* 0.259813002 */, 18 },
+ /* 4217 */ { MAD_F(0x042887d7) /* 0.259895173 */, 18 },
+ /* 4218 */ { MAD_F(0x0428de02) /* 0.259977350 */, 18 },
+ /* 4219 */ { MAD_F(0x0429342f) /* 0.260059533 */, 18 },
+ /* 4220 */ { MAD_F(0x04298a5e) /* 0.260141723 */, 18 },
+ /* 4221 */ { MAD_F(0x0429e08e) /* 0.260223920 */, 18 },
+ /* 4222 */ { MAD_F(0x042a36c0) /* 0.260306123 */, 18 },
+ /* 4223 */ { MAD_F(0x042a8cf4) /* 0.260388332 */, 18 },
+
+ /* 4224 */ { MAD_F(0x042ae32a) /* 0.260470548 */, 18 },
+ /* 4225 */ { MAD_F(0x042b3962) /* 0.260552771 */, 18 },
+ /* 4226 */ { MAD_F(0x042b8f9b) /* 0.260635000 */, 18 },
+ /* 4227 */ { MAD_F(0x042be5d6) /* 0.260717235 */, 18 },
+ /* 4228 */ { MAD_F(0x042c3c12) /* 0.260799477 */, 18 },
+ /* 4229 */ { MAD_F(0x042c9251) /* 0.260881725 */, 18 },
+ /* 4230 */ { MAD_F(0x042ce891) /* 0.260963980 */, 18 },
+ /* 4231 */ { MAD_F(0x042d3ed3) /* 0.261046242 */, 18 },
+ /* 4232 */ { MAD_F(0x042d9516) /* 0.261128510 */, 18 },
+ /* 4233 */ { MAD_F(0x042deb5c) /* 0.261210784 */, 18 },
+ /* 4234 */ { MAD_F(0x042e41a3) /* 0.261293065 */, 18 },
+ /* 4235 */ { MAD_F(0x042e97ec) /* 0.261375352 */, 18 },
+ /* 4236 */ { MAD_F(0x042eee36) /* 0.261457646 */, 18 },
+ /* 4237 */ { MAD_F(0x042f4482) /* 0.261539946 */, 18 },
+ /* 4238 */ { MAD_F(0x042f9ad1) /* 0.261622253 */, 18 },
+ /* 4239 */ { MAD_F(0x042ff120) /* 0.261704566 */, 18 },
+
+ /* 4240 */ { MAD_F(0x04304772) /* 0.261786886 */, 18 },
+ /* 4241 */ { MAD_F(0x04309dc5) /* 0.261869212 */, 18 },
+ /* 4242 */ { MAD_F(0x0430f41a) /* 0.261951545 */, 18 },
+ /* 4243 */ { MAD_F(0x04314a71) /* 0.262033884 */, 18 },
+ /* 4244 */ { MAD_F(0x0431a0c9) /* 0.262116229 */, 18 },
+ /* 4245 */ { MAD_F(0x0431f723) /* 0.262198581 */, 18 },
+ /* 4246 */ { MAD_F(0x04324d7f) /* 0.262280940 */, 18 },
+ /* 4247 */ { MAD_F(0x0432a3dd) /* 0.262363305 */, 18 },
+ /* 4248 */ { MAD_F(0x0432fa3d) /* 0.262445676 */, 18 },
+ /* 4249 */ { MAD_F(0x0433509e) /* 0.262528054 */, 18 },
+ /* 4250 */ { MAD_F(0x0433a701) /* 0.262610438 */, 18 },
+ /* 4251 */ { MAD_F(0x0433fd65) /* 0.262692829 */, 18 },
+ /* 4252 */ { MAD_F(0x043453cc) /* 0.262775227 */, 18 },
+ /* 4253 */ { MAD_F(0x0434aa34) /* 0.262857630 */, 18 },
+ /* 4254 */ { MAD_F(0x0435009d) /* 0.262940040 */, 18 },
+ /* 4255 */ { MAD_F(0x04355709) /* 0.263022457 */, 18 },
+
+ /* 4256 */ { MAD_F(0x0435ad76) /* 0.263104880 */, 18 },
+ /* 4257 */ { MAD_F(0x043603e5) /* 0.263187310 */, 18 },
+ /* 4258 */ { MAD_F(0x04365a56) /* 0.263269746 */, 18 },
+ /* 4259 */ { MAD_F(0x0436b0c9) /* 0.263352188 */, 18 },
+ /* 4260 */ { MAD_F(0x0437073d) /* 0.263434637 */, 18 },
+ /* 4261 */ { MAD_F(0x04375db3) /* 0.263517093 */, 18 },
+ /* 4262 */ { MAD_F(0x0437b42a) /* 0.263599554 */, 18 },
+ /* 4263 */ { MAD_F(0x04380aa4) /* 0.263682023 */, 18 },
+ /* 4264 */ { MAD_F(0x0438611f) /* 0.263764497 */, 18 },
+ /* 4265 */ { MAD_F(0x0438b79c) /* 0.263846979 */, 18 },
+ /* 4266 */ { MAD_F(0x04390e1a) /* 0.263929466 */, 18 },
+ /* 4267 */ { MAD_F(0x0439649b) /* 0.264011960 */, 18 },
+ /* 4268 */ { MAD_F(0x0439bb1d) /* 0.264094461 */, 18 },
+ /* 4269 */ { MAD_F(0x043a11a1) /* 0.264176968 */, 18 },
+ /* 4270 */ { MAD_F(0x043a6826) /* 0.264259481 */, 18 },
+ /* 4271 */ { MAD_F(0x043abead) /* 0.264342001 */, 18 },
+
+ /* 4272 */ { MAD_F(0x043b1536) /* 0.264424527 */, 18 },
+ /* 4273 */ { MAD_F(0x043b6bc1) /* 0.264507060 */, 18 },
+ /* 4274 */ { MAD_F(0x043bc24d) /* 0.264589599 */, 18 },
+ /* 4275 */ { MAD_F(0x043c18dc) /* 0.264672145 */, 18 },
+ /* 4276 */ { MAD_F(0x043c6f6c) /* 0.264754697 */, 18 },
+ /* 4277 */ { MAD_F(0x043cc5fd) /* 0.264837255 */, 18 },
+ /* 4278 */ { MAD_F(0x043d1c91) /* 0.264919820 */, 18 },
+ /* 4279 */ { MAD_F(0x043d7326) /* 0.265002392 */, 18 },
+ /* 4280 */ { MAD_F(0x043dc9bc) /* 0.265084969 */, 18 },
+ /* 4281 */ { MAD_F(0x043e2055) /* 0.265167554 */, 18 },
+ /* 4282 */ { MAD_F(0x043e76ef) /* 0.265250144 */, 18 },
+ /* 4283 */ { MAD_F(0x043ecd8b) /* 0.265332741 */, 18 },
+ /* 4284 */ { MAD_F(0x043f2429) /* 0.265415345 */, 18 },
+ /* 4285 */ { MAD_F(0x043f7ac8) /* 0.265497955 */, 18 },
+ /* 4286 */ { MAD_F(0x043fd169) /* 0.265580571 */, 18 },
+ /* 4287 */ { MAD_F(0x0440280c) /* 0.265663194 */, 18 },
+
+ /* 4288 */ { MAD_F(0x04407eb1) /* 0.265745823 */, 18 },
+ /* 4289 */ { MAD_F(0x0440d557) /* 0.265828459 */, 18 },
+ /* 4290 */ { MAD_F(0x04412bff) /* 0.265911101 */, 18 },
+ /* 4291 */ { MAD_F(0x044182a9) /* 0.265993749 */, 18 },
+ /* 4292 */ { MAD_F(0x0441d955) /* 0.266076404 */, 18 },
+ /* 4293 */ { MAD_F(0x04423002) /* 0.266159065 */, 18 },
+ /* 4294 */ { MAD_F(0x044286b1) /* 0.266241733 */, 18 },
+ /* 4295 */ { MAD_F(0x0442dd61) /* 0.266324407 */, 18 },
+ /* 4296 */ { MAD_F(0x04433414) /* 0.266407088 */, 18 },
+ /* 4297 */ { MAD_F(0x04438ac8) /* 0.266489775 */, 18 },
+ /* 4298 */ { MAD_F(0x0443e17e) /* 0.266572468 */, 18 },
+ /* 4299 */ { MAD_F(0x04443835) /* 0.266655168 */, 18 },
+ /* 4300 */ { MAD_F(0x04448eef) /* 0.266737874 */, 18 },
+ /* 4301 */ { MAD_F(0x0444e5aa) /* 0.266820587 */, 18 },
+ /* 4302 */ { MAD_F(0x04453c66) /* 0.266903306 */, 18 },
+ /* 4303 */ { MAD_F(0x04459325) /* 0.266986031 */, 18 },
+
+ /* 4304 */ { MAD_F(0x0445e9e5) /* 0.267068763 */, 18 },
+ /* 4305 */ { MAD_F(0x044640a7) /* 0.267151501 */, 18 },
+ /* 4306 */ { MAD_F(0x0446976a) /* 0.267234246 */, 18 },
+ /* 4307 */ { MAD_F(0x0446ee30) /* 0.267316997 */, 18 },
+ /* 4308 */ { MAD_F(0x044744f7) /* 0.267399755 */, 18 },
+ /* 4309 */ { MAD_F(0x04479bc0) /* 0.267482518 */, 18 },
+ /* 4310 */ { MAD_F(0x0447f28a) /* 0.267565289 */, 18 },
+ /* 4311 */ { MAD_F(0x04484956) /* 0.267648065 */, 18 },
+ /* 4312 */ { MAD_F(0x0448a024) /* 0.267730848 */, 18 },
+ /* 4313 */ { MAD_F(0x0448f6f4) /* 0.267813638 */, 18 },
+ /* 4314 */ { MAD_F(0x04494dc5) /* 0.267896434 */, 18 },
+ /* 4315 */ { MAD_F(0x0449a498) /* 0.267979236 */, 18 },
+ /* 4316 */ { MAD_F(0x0449fb6d) /* 0.268062045 */, 18 },
+ /* 4317 */ { MAD_F(0x044a5243) /* 0.268144860 */, 18 },
+ /* 4318 */ { MAD_F(0x044aa91c) /* 0.268227681 */, 18 },
+ /* 4319 */ { MAD_F(0x044afff6) /* 0.268310509 */, 18 },
+
+ /* 4320 */ { MAD_F(0x044b56d1) /* 0.268393343 */, 18 },
+ /* 4321 */ { MAD_F(0x044badaf) /* 0.268476184 */, 18 },
+ /* 4322 */ { MAD_F(0x044c048e) /* 0.268559031 */, 18 },
+ /* 4323 */ { MAD_F(0x044c5b6f) /* 0.268641885 */, 18 },
+ /* 4324 */ { MAD_F(0x044cb251) /* 0.268724744 */, 18 },
+ /* 4325 */ { MAD_F(0x044d0935) /* 0.268807611 */, 18 },
+ /* 4326 */ { MAD_F(0x044d601b) /* 0.268890483 */, 18 },
+ /* 4327 */ { MAD_F(0x044db703) /* 0.268973362 */, 18 },
+ /* 4328 */ { MAD_F(0x044e0dec) /* 0.269056248 */, 18 },
+ /* 4329 */ { MAD_F(0x044e64d7) /* 0.269139139 */, 18 },
+ /* 4330 */ { MAD_F(0x044ebbc4) /* 0.269222037 */, 18 },
+ /* 4331 */ { MAD_F(0x044f12b3) /* 0.269304942 */, 18 },
+ /* 4332 */ { MAD_F(0x044f69a3) /* 0.269387853 */, 18 },
+ /* 4333 */ { MAD_F(0x044fc095) /* 0.269470770 */, 18 },
+ /* 4334 */ { MAD_F(0x04501788) /* 0.269553694 */, 18 },
+ /* 4335 */ { MAD_F(0x04506e7e) /* 0.269636624 */, 18 },
+
+ /* 4336 */ { MAD_F(0x0450c575) /* 0.269719560 */, 18 },
+ /* 4337 */ { MAD_F(0x04511c6e) /* 0.269802503 */, 18 },
+ /* 4338 */ { MAD_F(0x04517368) /* 0.269885452 */, 18 },
+ /* 4339 */ { MAD_F(0x0451ca64) /* 0.269968408 */, 18 },
+ /* 4340 */ { MAD_F(0x04522162) /* 0.270051370 */, 18 },
+ /* 4341 */ { MAD_F(0x04527862) /* 0.270134338 */, 18 },
+ /* 4342 */ { MAD_F(0x0452cf63) /* 0.270217312 */, 18 },
+ /* 4343 */ { MAD_F(0x04532666) /* 0.270300293 */, 18 },
+ /* 4344 */ { MAD_F(0x04537d6b) /* 0.270383281 */, 18 },
+ /* 4345 */ { MAD_F(0x0453d472) /* 0.270466275 */, 18 },
+ /* 4346 */ { MAD_F(0x04542b7a) /* 0.270549275 */, 18 },
+ /* 4347 */ { MAD_F(0x04548284) /* 0.270632281 */, 18 },
+ /* 4348 */ { MAD_F(0x0454d98f) /* 0.270715294 */, 18 },
+ /* 4349 */ { MAD_F(0x0455309c) /* 0.270798313 */, 18 },
+ /* 4350 */ { MAD_F(0x045587ab) /* 0.270881339 */, 18 },
+ /* 4351 */ { MAD_F(0x0455debc) /* 0.270964371 */, 18 },
+
+ /* 4352 */ { MAD_F(0x045635cf) /* 0.271047409 */, 18 },
+ /* 4353 */ { MAD_F(0x04568ce3) /* 0.271130454 */, 18 },
+ /* 4354 */ { MAD_F(0x0456e3f9) /* 0.271213505 */, 18 },
+ /* 4355 */ { MAD_F(0x04573b10) /* 0.271296562 */, 18 },
+ /* 4356 */ { MAD_F(0x04579229) /* 0.271379626 */, 18 },
+ /* 4357 */ { MAD_F(0x0457e944) /* 0.271462696 */, 18 },
+ /* 4358 */ { MAD_F(0x04584061) /* 0.271545772 */, 18 },
+ /* 4359 */ { MAD_F(0x0458977f) /* 0.271628855 */, 18 },
+ /* 4360 */ { MAD_F(0x0458ee9f) /* 0.271711944 */, 18 },
+ /* 4361 */ { MAD_F(0x045945c1) /* 0.271795040 */, 18 },
+ /* 4362 */ { MAD_F(0x04599ce5) /* 0.271878142 */, 18 },
+ /* 4363 */ { MAD_F(0x0459f40a) /* 0.271961250 */, 18 },
+ /* 4364 */ { MAD_F(0x045a4b31) /* 0.272044365 */, 18 },
+ /* 4365 */ { MAD_F(0x045aa259) /* 0.272127486 */, 18 },
+ /* 4366 */ { MAD_F(0x045af984) /* 0.272210613 */, 18 },
+ /* 4367 */ { MAD_F(0x045b50b0) /* 0.272293746 */, 18 },
+
+ /* 4368 */ { MAD_F(0x045ba7dd) /* 0.272376886 */, 18 },
+ /* 4369 */ { MAD_F(0x045bff0d) /* 0.272460033 */, 18 },
+ /* 4370 */ { MAD_F(0x045c563e) /* 0.272543185 */, 18 },
+ /* 4371 */ { MAD_F(0x045cad71) /* 0.272626344 */, 18 },
+ /* 4372 */ { MAD_F(0x045d04a5) /* 0.272709510 */, 18 },
+ /* 4373 */ { MAD_F(0x045d5bdc) /* 0.272792681 */, 18 },
+ /* 4374 */ { MAD_F(0x045db313) /* 0.272875859 */, 18 },
+ /* 4375 */ { MAD_F(0x045e0a4d) /* 0.272959044 */, 18 },
+ /* 4376 */ { MAD_F(0x045e6188) /* 0.273042234 */, 18 },
+ /* 4377 */ { MAD_F(0x045eb8c5) /* 0.273125431 */, 18 },
+ /* 4378 */ { MAD_F(0x045f1004) /* 0.273208635 */, 18 },
+ /* 4379 */ { MAD_F(0x045f6745) /* 0.273291844 */, 18 },
+ /* 4380 */ { MAD_F(0x045fbe87) /* 0.273375060 */, 18 },
+ /* 4381 */ { MAD_F(0x046015cb) /* 0.273458283 */, 18 },
+ /* 4382 */ { MAD_F(0x04606d10) /* 0.273541511 */, 18 },
+ /* 4383 */ { MAD_F(0x0460c457) /* 0.273624747 */, 18 },
+
+ /* 4384 */ { MAD_F(0x04611ba0) /* 0.273707988 */, 18 },
+ /* 4385 */ { MAD_F(0x046172eb) /* 0.273791236 */, 18 },
+ /* 4386 */ { MAD_F(0x0461ca37) /* 0.273874490 */, 18 },
+ /* 4387 */ { MAD_F(0x04622185) /* 0.273957750 */, 18 },
+ /* 4388 */ { MAD_F(0x046278d5) /* 0.274041017 */, 18 },
+ /* 4389 */ { MAD_F(0x0462d026) /* 0.274124290 */, 18 },
+ /* 4390 */ { MAD_F(0x0463277a) /* 0.274207569 */, 18 },
+ /* 4391 */ { MAD_F(0x04637ece) /* 0.274290855 */, 18 },
+ /* 4392 */ { MAD_F(0x0463d625) /* 0.274374147 */, 18 },
+ /* 4393 */ { MAD_F(0x04642d7d) /* 0.274457445 */, 18 },
+ /* 4394 */ { MAD_F(0x046484d7) /* 0.274540749 */, 18 },
+ /* 4395 */ { MAD_F(0x0464dc33) /* 0.274624060 */, 18 },
+ /* 4396 */ { MAD_F(0x04653390) /* 0.274707378 */, 18 },
+ /* 4397 */ { MAD_F(0x04658aef) /* 0.274790701 */, 18 },
+ /* 4398 */ { MAD_F(0x0465e250) /* 0.274874031 */, 18 },
+ /* 4399 */ { MAD_F(0x046639b2) /* 0.274957367 */, 18 },
+
+ /* 4400 */ { MAD_F(0x04669116) /* 0.275040710 */, 18 },
+ /* 4401 */ { MAD_F(0x0466e87c) /* 0.275124059 */, 18 },
+ /* 4402 */ { MAD_F(0x04673fe3) /* 0.275207414 */, 18 },
+ /* 4403 */ { MAD_F(0x0467974d) /* 0.275290775 */, 18 },
+ /* 4404 */ { MAD_F(0x0467eeb7) /* 0.275374143 */, 18 },
+ /* 4405 */ { MAD_F(0x04684624) /* 0.275457517 */, 18 },
+ /* 4406 */ { MAD_F(0x04689d92) /* 0.275540897 */, 18 },
+ /* 4407 */ { MAD_F(0x0468f502) /* 0.275624284 */, 18 },
+ /* 4408 */ { MAD_F(0x04694c74) /* 0.275707677 */, 18 },
+ /* 4409 */ { MAD_F(0x0469a3e7) /* 0.275791076 */, 18 },
+ /* 4410 */ { MAD_F(0x0469fb5c) /* 0.275874482 */, 18 },
+ /* 4411 */ { MAD_F(0x046a52d3) /* 0.275957894 */, 18 },
+ /* 4412 */ { MAD_F(0x046aaa4b) /* 0.276041312 */, 18 },
+ /* 4413 */ { MAD_F(0x046b01c5) /* 0.276124737 */, 18 },
+ /* 4414 */ { MAD_F(0x046b5941) /* 0.276208167 */, 18 },
+ /* 4415 */ { MAD_F(0x046bb0bf) /* 0.276291605 */, 18 },
+
+ /* 4416 */ { MAD_F(0x046c083e) /* 0.276375048 */, 18 },
+ /* 4417 */ { MAD_F(0x046c5fbf) /* 0.276458498 */, 18 },
+ /* 4418 */ { MAD_F(0x046cb741) /* 0.276541954 */, 18 },
+ /* 4419 */ { MAD_F(0x046d0ec5) /* 0.276625416 */, 18 },
+ /* 4420 */ { MAD_F(0x046d664b) /* 0.276708885 */, 18 },
+ /* 4421 */ { MAD_F(0x046dbdd3) /* 0.276792360 */, 18 },
+ /* 4422 */ { MAD_F(0x046e155c) /* 0.276875841 */, 18 },
+ /* 4423 */ { MAD_F(0x046e6ce7) /* 0.276959328 */, 18 },
+ /* 4424 */ { MAD_F(0x046ec474) /* 0.277042822 */, 18 },
+ /* 4425 */ { MAD_F(0x046f1c02) /* 0.277126322 */, 18 },
+ /* 4426 */ { MAD_F(0x046f7392) /* 0.277209829 */, 18 },
+ /* 4427 */ { MAD_F(0x046fcb24) /* 0.277293341 */, 18 },
+ /* 4428 */ { MAD_F(0x047022b8) /* 0.277376860 */, 18 },
+ /* 4429 */ { MAD_F(0x04707a4d) /* 0.277460385 */, 18 },
+ /* 4430 */ { MAD_F(0x0470d1e4) /* 0.277543917 */, 18 },
+ /* 4431 */ { MAD_F(0x0471297c) /* 0.277627455 */, 18 },
+
+ /* 4432 */ { MAD_F(0x04718116) /* 0.277710999 */, 18 },
+ /* 4433 */ { MAD_F(0x0471d8b2) /* 0.277794549 */, 18 },
+ /* 4434 */ { MAD_F(0x04723050) /* 0.277878106 */, 18 },
+ /* 4435 */ { MAD_F(0x047287ef) /* 0.277961669 */, 18 },
+ /* 4436 */ { MAD_F(0x0472df90) /* 0.278045238 */, 18 },
+ /* 4437 */ { MAD_F(0x04733733) /* 0.278128813 */, 18 },
+ /* 4438 */ { MAD_F(0x04738ed7) /* 0.278212395 */, 18 },
+ /* 4439 */ { MAD_F(0x0473e67d) /* 0.278295983 */, 18 },
+ /* 4440 */ { MAD_F(0x04743e25) /* 0.278379578 */, 18 },
+ /* 4441 */ { MAD_F(0x047495ce) /* 0.278463178 */, 18 },
+ /* 4442 */ { MAD_F(0x0474ed79) /* 0.278546785 */, 18 },
+ /* 4443 */ { MAD_F(0x04754526) /* 0.278630398 */, 18 },
+ /* 4444 */ { MAD_F(0x04759cd4) /* 0.278714018 */, 18 },
+ /* 4445 */ { MAD_F(0x0475f484) /* 0.278797643 */, 18 },
+ /* 4446 */ { MAD_F(0x04764c36) /* 0.278881275 */, 18 },
+ /* 4447 */ { MAD_F(0x0476a3ea) /* 0.278964914 */, 18 },
+
+ /* 4448 */ { MAD_F(0x0476fb9f) /* 0.279048558 */, 18 },
+ /* 4449 */ { MAD_F(0x04775356) /* 0.279132209 */, 18 },
+ /* 4450 */ { MAD_F(0x0477ab0e) /* 0.279215866 */, 18 },
+ /* 4451 */ { MAD_F(0x047802c8) /* 0.279299529 */, 18 },
+ /* 4452 */ { MAD_F(0x04785a84) /* 0.279383199 */, 18 },
+ /* 4453 */ { MAD_F(0x0478b242) /* 0.279466875 */, 18 },
+ /* 4454 */ { MAD_F(0x04790a01) /* 0.279550557 */, 18 },
+ /* 4455 */ { MAD_F(0x047961c2) /* 0.279634245 */, 18 },
+ /* 4456 */ { MAD_F(0x0479b984) /* 0.279717940 */, 18 },
+ /* 4457 */ { MAD_F(0x047a1149) /* 0.279801641 */, 18 },
+ /* 4458 */ { MAD_F(0x047a690f) /* 0.279885348 */, 18 },
+ /* 4459 */ { MAD_F(0x047ac0d6) /* 0.279969061 */, 18 },
+ /* 4460 */ { MAD_F(0x047b18a0) /* 0.280052781 */, 18 },
+ /* 4461 */ { MAD_F(0x047b706b) /* 0.280136507 */, 18 },
+ /* 4462 */ { MAD_F(0x047bc837) /* 0.280220239 */, 18 },
+ /* 4463 */ { MAD_F(0x047c2006) /* 0.280303978 */, 18 },
+
+ /* 4464 */ { MAD_F(0x047c77d6) /* 0.280387722 */, 18 },
+ /* 4465 */ { MAD_F(0x047ccfa8) /* 0.280471473 */, 18 },
+ /* 4466 */ { MAD_F(0x047d277b) /* 0.280555230 */, 18 },
+ /* 4467 */ { MAD_F(0x047d7f50) /* 0.280638994 */, 18 },
+ /* 4468 */ { MAD_F(0x047dd727) /* 0.280722764 */, 18 },
+ /* 4469 */ { MAD_F(0x047e2eff) /* 0.280806540 */, 18 },
+ /* 4470 */ { MAD_F(0x047e86d9) /* 0.280890322 */, 18 },
+ /* 4471 */ { MAD_F(0x047edeb5) /* 0.280974110 */, 18 },
+ /* 4472 */ { MAD_F(0x047f3693) /* 0.281057905 */, 18 },
+ /* 4473 */ { MAD_F(0x047f8e72) /* 0.281141706 */, 18 },
+ /* 4474 */ { MAD_F(0x047fe653) /* 0.281225513 */, 18 },
+ /* 4475 */ { MAD_F(0x04803e35) /* 0.281309326 */, 18 },
+ /* 4476 */ { MAD_F(0x04809619) /* 0.281393146 */, 18 },
+ /* 4477 */ { MAD_F(0x0480edff) /* 0.281476972 */, 18 },
+ /* 4478 */ { MAD_F(0x048145e7) /* 0.281560804 */, 18 },
+ /* 4479 */ { MAD_F(0x04819dd0) /* 0.281644643 */, 18 },
+
+ /* 4480 */ { MAD_F(0x0481f5bb) /* 0.281728487 */, 18 },
+ /* 4481 */ { MAD_F(0x04824da7) /* 0.281812338 */, 18 },
+ /* 4482 */ { MAD_F(0x0482a595) /* 0.281896195 */, 18 },
+ /* 4483 */ { MAD_F(0x0482fd85) /* 0.281980059 */, 18 },
+ /* 4484 */ { MAD_F(0x04835577) /* 0.282063928 */, 18 },
+ /* 4485 */ { MAD_F(0x0483ad6a) /* 0.282147804 */, 18 },
+ /* 4486 */ { MAD_F(0x0484055f) /* 0.282231686 */, 18 },
+ /* 4487 */ { MAD_F(0x04845d56) /* 0.282315574 */, 18 },
+ /* 4488 */ { MAD_F(0x0484b54e) /* 0.282399469 */, 18 },
+ /* 4489 */ { MAD_F(0x04850d48) /* 0.282483370 */, 18 },
+ /* 4490 */ { MAD_F(0x04856544) /* 0.282567277 */, 18 },
+ /* 4491 */ { MAD_F(0x0485bd41) /* 0.282651190 */, 18 },
+ /* 4492 */ { MAD_F(0x04861540) /* 0.282735109 */, 18 },
+ /* 4493 */ { MAD_F(0x04866d40) /* 0.282819035 */, 18 },
+ /* 4494 */ { MAD_F(0x0486c543) /* 0.282902967 */, 18 },
+ /* 4495 */ { MAD_F(0x04871d47) /* 0.282986905 */, 18 },
+
+ /* 4496 */ { MAD_F(0x0487754c) /* 0.283070849 */, 18 },
+ /* 4497 */ { MAD_F(0x0487cd54) /* 0.283154800 */, 18 },
+ /* 4498 */ { MAD_F(0x0488255d) /* 0.283238757 */, 18 },
+ /* 4499 */ { MAD_F(0x04887d67) /* 0.283322720 */, 18 },
+ /* 4500 */ { MAD_F(0x0488d574) /* 0.283406689 */, 18 },
+ /* 4501 */ { MAD_F(0x04892d82) /* 0.283490665 */, 18 },
+ /* 4502 */ { MAD_F(0x04898591) /* 0.283574646 */, 18 },
+ /* 4503 */ { MAD_F(0x0489dda3) /* 0.283658634 */, 18 },
+ /* 4504 */ { MAD_F(0x048a35b6) /* 0.283742628 */, 18 },
+ /* 4505 */ { MAD_F(0x048a8dca) /* 0.283826629 */, 18 },
+ /* 4506 */ { MAD_F(0x048ae5e1) /* 0.283910635 */, 18 },
+ /* 4507 */ { MAD_F(0x048b3df9) /* 0.283994648 */, 18 },
+ /* 4508 */ { MAD_F(0x048b9612) /* 0.284078667 */, 18 },
+ /* 4509 */ { MAD_F(0x048bee2e) /* 0.284162692 */, 18 },
+ /* 4510 */ { MAD_F(0x048c464b) /* 0.284246723 */, 18 },
+ /* 4511 */ { MAD_F(0x048c9e69) /* 0.284330761 */, 18 },
+
+ /* 4512 */ { MAD_F(0x048cf68a) /* 0.284414805 */, 18 },
+ /* 4513 */ { MAD_F(0x048d4eac) /* 0.284498855 */, 18 },
+ /* 4514 */ { MAD_F(0x048da6cf) /* 0.284582911 */, 18 },
+ /* 4515 */ { MAD_F(0x048dfef5) /* 0.284666974 */, 18 },
+ /* 4516 */ { MAD_F(0x048e571c) /* 0.284751042 */, 18 },
+ /* 4517 */ { MAD_F(0x048eaf44) /* 0.284835117 */, 18 },
+ /* 4518 */ { MAD_F(0x048f076f) /* 0.284919198 */, 18 },
+ /* 4519 */ { MAD_F(0x048f5f9b) /* 0.285003285 */, 18 },
+ /* 4520 */ { MAD_F(0x048fb7c8) /* 0.285087379 */, 18 },
+ /* 4521 */ { MAD_F(0x04900ff8) /* 0.285171479 */, 18 },
+ /* 4522 */ { MAD_F(0x04906829) /* 0.285255584 */, 18 },
+ /* 4523 */ { MAD_F(0x0490c05b) /* 0.285339697 */, 18 },
+ /* 4524 */ { MAD_F(0x04911890) /* 0.285423815 */, 18 },
+ /* 4525 */ { MAD_F(0x049170c6) /* 0.285507939 */, 18 },
+ /* 4526 */ { MAD_F(0x0491c8fd) /* 0.285592070 */, 18 },
+ /* 4527 */ { MAD_F(0x04922137) /* 0.285676207 */, 18 },
+
+ /* 4528 */ { MAD_F(0x04927972) /* 0.285760350 */, 18 },
+ /* 4529 */ { MAD_F(0x0492d1ae) /* 0.285844499 */, 18 },
+ /* 4530 */ { MAD_F(0x049329ed) /* 0.285928655 */, 18 },
+ /* 4531 */ { MAD_F(0x0493822c) /* 0.286012816 */, 18 },
+ /* 4532 */ { MAD_F(0x0493da6e) /* 0.286096984 */, 18 },
+ /* 4533 */ { MAD_F(0x049432b1) /* 0.286181158 */, 18 },
+ /* 4534 */ { MAD_F(0x04948af6) /* 0.286265338 */, 18 },
+ /* 4535 */ { MAD_F(0x0494e33d) /* 0.286349525 */, 18 },
+ /* 4536 */ { MAD_F(0x04953b85) /* 0.286433717 */, 18 },
+ /* 4537 */ { MAD_F(0x049593cf) /* 0.286517916 */, 18 },
+ /* 4538 */ { MAD_F(0x0495ec1b) /* 0.286602121 */, 18 },
+ /* 4539 */ { MAD_F(0x04964468) /* 0.286686332 */, 18 },
+ /* 4540 */ { MAD_F(0x04969cb7) /* 0.286770550 */, 18 },
+ /* 4541 */ { MAD_F(0x0496f508) /* 0.286854773 */, 18 },
+ /* 4542 */ { MAD_F(0x04974d5a) /* 0.286939003 */, 18 },
+ /* 4543 */ { MAD_F(0x0497a5ae) /* 0.287023239 */, 18 },
+
+ /* 4544 */ { MAD_F(0x0497fe03) /* 0.287107481 */, 18 },
+ /* 4545 */ { MAD_F(0x0498565a) /* 0.287191729 */, 18 },
+ /* 4546 */ { MAD_F(0x0498aeb3) /* 0.287275983 */, 18 },
+ /* 4547 */ { MAD_F(0x0499070e) /* 0.287360244 */, 18 },
+ /* 4548 */ { MAD_F(0x04995f6a) /* 0.287444511 */, 18 },
+ /* 4549 */ { MAD_F(0x0499b7c8) /* 0.287528784 */, 18 },
+ /* 4550 */ { MAD_F(0x049a1027) /* 0.287613063 */, 18 },
+ /* 4551 */ { MAD_F(0x049a6889) /* 0.287697348 */, 18 },
+ /* 4552 */ { MAD_F(0x049ac0eb) /* 0.287781640 */, 18 },
+ /* 4553 */ { MAD_F(0x049b1950) /* 0.287865937 */, 18 },
+ /* 4554 */ { MAD_F(0x049b71b6) /* 0.287950241 */, 18 },
+ /* 4555 */ { MAD_F(0x049bca1e) /* 0.288034551 */, 18 },
+ /* 4556 */ { MAD_F(0x049c2287) /* 0.288118867 */, 18 },
+ /* 4557 */ { MAD_F(0x049c7af2) /* 0.288203190 */, 18 },
+ /* 4558 */ { MAD_F(0x049cd35f) /* 0.288287518 */, 18 },
+ /* 4559 */ { MAD_F(0x049d2bce) /* 0.288371853 */, 18 },
+
+ /* 4560 */ { MAD_F(0x049d843e) /* 0.288456194 */, 18 },
+ /* 4561 */ { MAD_F(0x049ddcaf) /* 0.288540541 */, 18 },
+ /* 4562 */ { MAD_F(0x049e3523) /* 0.288624894 */, 18 },
+ /* 4563 */ { MAD_F(0x049e8d98) /* 0.288709253 */, 18 },
+ /* 4564 */ { MAD_F(0x049ee60e) /* 0.288793619 */, 18 },
+ /* 4565 */ { MAD_F(0x049f3e87) /* 0.288877990 */, 18 },
+ /* 4566 */ { MAD_F(0x049f9701) /* 0.288962368 */, 18 },
+ /* 4567 */ { MAD_F(0x049fef7c) /* 0.289046752 */, 18 },
+ /* 4568 */ { MAD_F(0x04a047fa) /* 0.289131142 */, 18 },
+ /* 4569 */ { MAD_F(0x04a0a079) /* 0.289215538 */, 18 },
+ /* 4570 */ { MAD_F(0x04a0f8f9) /* 0.289299941 */, 18 },
+ /* 4571 */ { MAD_F(0x04a1517c) /* 0.289384349 */, 18 },
+ /* 4572 */ { MAD_F(0x04a1a9ff) /* 0.289468764 */, 18 },
+ /* 4573 */ { MAD_F(0x04a20285) /* 0.289553185 */, 18 },
+ /* 4574 */ { MAD_F(0x04a25b0c) /* 0.289637612 */, 18 },
+ /* 4575 */ { MAD_F(0x04a2b395) /* 0.289722045 */, 18 },
+
+ /* 4576 */ { MAD_F(0x04a30c20) /* 0.289806485 */, 18 },
+ /* 4577 */ { MAD_F(0x04a364ac) /* 0.289890930 */, 18 },
+ /* 4578 */ { MAD_F(0x04a3bd3a) /* 0.289975382 */, 18 },
+ /* 4579 */ { MAD_F(0x04a415c9) /* 0.290059840 */, 18 },
+ /* 4580 */ { MAD_F(0x04a46e5a) /* 0.290144304 */, 18 },
+ /* 4581 */ { MAD_F(0x04a4c6ed) /* 0.290228774 */, 18 },
+ /* 4582 */ { MAD_F(0x04a51f81) /* 0.290313250 */, 18 },
+ /* 4583 */ { MAD_F(0x04a57818) /* 0.290397733 */, 18 },
+ /* 4584 */ { MAD_F(0x04a5d0af) /* 0.290482221 */, 18 },
+ /* 4585 */ { MAD_F(0x04a62949) /* 0.290566716 */, 18 },
+ /* 4586 */ { MAD_F(0x04a681e4) /* 0.290651217 */, 18 },
+ /* 4587 */ { MAD_F(0x04a6da80) /* 0.290735724 */, 18 },
+ /* 4588 */ { MAD_F(0x04a7331f) /* 0.290820237 */, 18 },
+ /* 4589 */ { MAD_F(0x04a78bbf) /* 0.290904756 */, 18 },
+ /* 4590 */ { MAD_F(0x04a7e460) /* 0.290989281 */, 18 },
+ /* 4591 */ { MAD_F(0x04a83d03) /* 0.291073813 */, 18 },
+
+ /* 4592 */ { MAD_F(0x04a895a8) /* 0.291158351 */, 18 },
+ /* 4593 */ { MAD_F(0x04a8ee4f) /* 0.291242894 */, 18 },
+ /* 4594 */ { MAD_F(0x04a946f7) /* 0.291327444 */, 18 },
+ /* 4595 */ { MAD_F(0x04a99fa1) /* 0.291412001 */, 18 },
+ /* 4596 */ { MAD_F(0x04a9f84c) /* 0.291496563 */, 18 },
+ /* 4597 */ { MAD_F(0x04aa50fa) /* 0.291581131 */, 18 },
+ /* 4598 */ { MAD_F(0x04aaa9a8) /* 0.291665706 */, 18 },
+ /* 4599 */ { MAD_F(0x04ab0259) /* 0.291750286 */, 18 },
+ /* 4600 */ { MAD_F(0x04ab5b0b) /* 0.291834873 */, 18 },
+ /* 4601 */ { MAD_F(0x04abb3bf) /* 0.291919466 */, 18 },
+ /* 4602 */ { MAD_F(0x04ac0c74) /* 0.292004065 */, 18 },
+ /* 4603 */ { MAD_F(0x04ac652b) /* 0.292088670 */, 18 },
+ /* 4604 */ { MAD_F(0x04acbde4) /* 0.292173281 */, 18 },
+ /* 4605 */ { MAD_F(0x04ad169e) /* 0.292257899 */, 18 },
+ /* 4606 */ { MAD_F(0x04ad6f5a) /* 0.292342522 */, 18 },
+ /* 4607 */ { MAD_F(0x04adc818) /* 0.292427152 */, 18 },
+
+ /* 4608 */ { MAD_F(0x04ae20d7) /* 0.292511788 */, 18 },
+ /* 4609 */ { MAD_F(0x04ae7998) /* 0.292596430 */, 18 },
+ /* 4610 */ { MAD_F(0x04aed25a) /* 0.292681078 */, 18 },
+ /* 4611 */ { MAD_F(0x04af2b1e) /* 0.292765732 */, 18 },
+ /* 4612 */ { MAD_F(0x04af83e4) /* 0.292850392 */, 18 },
+ /* 4613 */ { MAD_F(0x04afdcac) /* 0.292935058 */, 18 },
+ /* 4614 */ { MAD_F(0x04b03575) /* 0.293019731 */, 18 },
+ /* 4615 */ { MAD_F(0x04b08e40) /* 0.293104409 */, 18 },
+ /* 4616 */ { MAD_F(0x04b0e70c) /* 0.293189094 */, 18 },
+ /* 4617 */ { MAD_F(0x04b13fda) /* 0.293273785 */, 18 },
+ /* 4618 */ { MAD_F(0x04b198aa) /* 0.293358482 */, 18 },
+ /* 4619 */ { MAD_F(0x04b1f17b) /* 0.293443185 */, 18 },
+ /* 4620 */ { MAD_F(0x04b24a4e) /* 0.293527894 */, 18 },
+ /* 4621 */ { MAD_F(0x04b2a322) /* 0.293612609 */, 18 },
+ /* 4622 */ { MAD_F(0x04b2fbf9) /* 0.293697331 */, 18 },
+ /* 4623 */ { MAD_F(0x04b354d1) /* 0.293782058 */, 18 },
+
+ /* 4624 */ { MAD_F(0x04b3adaa) /* 0.293866792 */, 18 },
+ /* 4625 */ { MAD_F(0x04b40685) /* 0.293951532 */, 18 },
+ /* 4626 */ { MAD_F(0x04b45f62) /* 0.294036278 */, 18 },
+ /* 4627 */ { MAD_F(0x04b4b840) /* 0.294121029 */, 18 },
+ /* 4628 */ { MAD_F(0x04b51120) /* 0.294205788 */, 18 },
+ /* 4629 */ { MAD_F(0x04b56a02) /* 0.294290552 */, 18 },
+ /* 4630 */ { MAD_F(0x04b5c2e6) /* 0.294375322 */, 18 },
+ /* 4631 */ { MAD_F(0x04b61bcb) /* 0.294460098 */, 18 },
+ /* 4632 */ { MAD_F(0x04b674b1) /* 0.294544881 */, 18 },
+ /* 4633 */ { MAD_F(0x04b6cd99) /* 0.294629669 */, 18 },
+ /* 4634 */ { MAD_F(0x04b72683) /* 0.294714464 */, 18 },
+ /* 4635 */ { MAD_F(0x04b77f6f) /* 0.294799265 */, 18 },
+ /* 4636 */ { MAD_F(0x04b7d85c) /* 0.294884072 */, 18 },
+ /* 4637 */ { MAD_F(0x04b8314b) /* 0.294968885 */, 18 },
+ /* 4638 */ { MAD_F(0x04b88a3b) /* 0.295053704 */, 18 },
+ /* 4639 */ { MAD_F(0x04b8e32d) /* 0.295138529 */, 18 },
+
+ /* 4640 */ { MAD_F(0x04b93c21) /* 0.295223360 */, 18 },
+ /* 4641 */ { MAD_F(0x04b99516) /* 0.295308197 */, 18 },
+ /* 4642 */ { MAD_F(0x04b9ee0d) /* 0.295393041 */, 18 },
+ /* 4643 */ { MAD_F(0x04ba4706) /* 0.295477890 */, 18 },
+ /* 4644 */ { MAD_F(0x04baa000) /* 0.295562746 */, 18 },
+ /* 4645 */ { MAD_F(0x04baf8fc) /* 0.295647608 */, 18 },
+ /* 4646 */ { MAD_F(0x04bb51fa) /* 0.295732476 */, 18 },
+ /* 4647 */ { MAD_F(0x04bbaaf9) /* 0.295817349 */, 18 },
+ /* 4648 */ { MAD_F(0x04bc03fa) /* 0.295902229 */, 18 },
+ /* 4649 */ { MAD_F(0x04bc5cfc) /* 0.295987115 */, 18 },
+ /* 4650 */ { MAD_F(0x04bcb600) /* 0.296072008 */, 18 },
+ /* 4651 */ { MAD_F(0x04bd0f06) /* 0.296156906 */, 18 },
+ /* 4652 */ { MAD_F(0x04bd680d) /* 0.296241810 */, 18 },
+ /* 4653 */ { MAD_F(0x04bdc116) /* 0.296326721 */, 18 },
+ /* 4654 */ { MAD_F(0x04be1a21) /* 0.296411637 */, 18 },
+ /* 4655 */ { MAD_F(0x04be732d) /* 0.296496560 */, 18 },
+
+ /* 4656 */ { MAD_F(0x04becc3b) /* 0.296581488 */, 18 },
+ /* 4657 */ { MAD_F(0x04bf254a) /* 0.296666423 */, 18 },
+ /* 4658 */ { MAD_F(0x04bf7e5b) /* 0.296751364 */, 18 },
+ /* 4659 */ { MAD_F(0x04bfd76e) /* 0.296836311 */, 18 },
+ /* 4660 */ { MAD_F(0x04c03083) /* 0.296921264 */, 18 },
+ /* 4661 */ { MAD_F(0x04c08999) /* 0.297006223 */, 18 },
+ /* 4662 */ { MAD_F(0x04c0e2b0) /* 0.297091188 */, 18 },
+ /* 4663 */ { MAD_F(0x04c13bca) /* 0.297176159 */, 18 },
+ /* 4664 */ { MAD_F(0x04c194e4) /* 0.297261136 */, 18 },
+ /* 4665 */ { MAD_F(0x04c1ee01) /* 0.297346120 */, 18 },
+ /* 4666 */ { MAD_F(0x04c2471f) /* 0.297431109 */, 18 },
+ /* 4667 */ { MAD_F(0x04c2a03f) /* 0.297516105 */, 18 },
+ /* 4668 */ { MAD_F(0x04c2f960) /* 0.297601106 */, 18 },
+ /* 4669 */ { MAD_F(0x04c35283) /* 0.297686114 */, 18 },
+ /* 4670 */ { MAD_F(0x04c3aba8) /* 0.297771128 */, 18 },
+ /* 4671 */ { MAD_F(0x04c404ce) /* 0.297856147 */, 18 },
+
+ /* 4672 */ { MAD_F(0x04c45df6) /* 0.297941173 */, 18 },
+ /* 4673 */ { MAD_F(0x04c4b720) /* 0.298026205 */, 18 },
+ /* 4674 */ { MAD_F(0x04c5104b) /* 0.298111243 */, 18 },
+ /* 4675 */ { MAD_F(0x04c56978) /* 0.298196287 */, 18 },
+ /* 4676 */ { MAD_F(0x04c5c2a7) /* 0.298281337 */, 18 },
+ /* 4677 */ { MAD_F(0x04c61bd7) /* 0.298366393 */, 18 },
+ /* 4678 */ { MAD_F(0x04c67508) /* 0.298451456 */, 18 },
+ /* 4679 */ { MAD_F(0x04c6ce3c) /* 0.298536524 */, 18 },
+ /* 4680 */ { MAD_F(0x04c72771) /* 0.298621598 */, 18 },
+ /* 4681 */ { MAD_F(0x04c780a7) /* 0.298706679 */, 18 },
+ /* 4682 */ { MAD_F(0x04c7d9df) /* 0.298791765 */, 18 },
+ /* 4683 */ { MAD_F(0x04c83319) /* 0.298876858 */, 18 },
+ /* 4684 */ { MAD_F(0x04c88c55) /* 0.298961956 */, 18 },
+ /* 4685 */ { MAD_F(0x04c8e592) /* 0.299047061 */, 18 },
+ /* 4686 */ { MAD_F(0x04c93ed1) /* 0.299132172 */, 18 },
+ /* 4687 */ { MAD_F(0x04c99811) /* 0.299217288 */, 18 },
+
+ /* 4688 */ { MAD_F(0x04c9f153) /* 0.299302411 */, 18 },
+ /* 4689 */ { MAD_F(0x04ca4a97) /* 0.299387540 */, 18 },
+ /* 4690 */ { MAD_F(0x04caa3dc) /* 0.299472675 */, 18 },
+ /* 4691 */ { MAD_F(0x04cafd23) /* 0.299557816 */, 18 },
+ /* 4692 */ { MAD_F(0x04cb566b) /* 0.299642963 */, 18 },
+ /* 4693 */ { MAD_F(0x04cbafb5) /* 0.299728116 */, 18 },
+ /* 4694 */ { MAD_F(0x04cc0901) /* 0.299813275 */, 18 },
+ /* 4695 */ { MAD_F(0x04cc624e) /* 0.299898440 */, 18 },
+ /* 4696 */ { MAD_F(0x04ccbb9d) /* 0.299983611 */, 18 },
+ /* 4697 */ { MAD_F(0x04cd14ee) /* 0.300068789 */, 18 },
+ /* 4698 */ { MAD_F(0x04cd6e40) /* 0.300153972 */, 18 },
+ /* 4699 */ { MAD_F(0x04cdc794) /* 0.300239161 */, 18 },
+ /* 4700 */ { MAD_F(0x04ce20e9) /* 0.300324357 */, 18 },
+ /* 4701 */ { MAD_F(0x04ce7a40) /* 0.300409558 */, 18 },
+ /* 4702 */ { MAD_F(0x04ced399) /* 0.300494765 */, 18 },
+ /* 4703 */ { MAD_F(0x04cf2cf3) /* 0.300579979 */, 18 },
+
+ /* 4704 */ { MAD_F(0x04cf864f) /* 0.300665198 */, 18 },
+ /* 4705 */ { MAD_F(0x04cfdfad) /* 0.300750424 */, 18 },
+ /* 4706 */ { MAD_F(0x04d0390c) /* 0.300835656 */, 18 },
+ /* 4707 */ { MAD_F(0x04d0926d) /* 0.300920893 */, 18 },
+ /* 4708 */ { MAD_F(0x04d0ebcf) /* 0.301006137 */, 18 },
+ /* 4709 */ { MAD_F(0x04d14533) /* 0.301091387 */, 18 },
+ /* 4710 */ { MAD_F(0x04d19e99) /* 0.301176643 */, 18 },
+ /* 4711 */ { MAD_F(0x04d1f800) /* 0.301261904 */, 18 },
+ /* 4712 */ { MAD_F(0x04d25169) /* 0.301347172 */, 18 },
+ /* 4713 */ { MAD_F(0x04d2aad4) /* 0.301432446 */, 18 },
+ /* 4714 */ { MAD_F(0x04d30440) /* 0.301517726 */, 18 },
+ /* 4715 */ { MAD_F(0x04d35dae) /* 0.301603012 */, 18 },
+ /* 4716 */ { MAD_F(0x04d3b71d) /* 0.301688304 */, 18 },
+ /* 4717 */ { MAD_F(0x04d4108e) /* 0.301773602 */, 18 },
+ /* 4718 */ { MAD_F(0x04d46a01) /* 0.301858906 */, 18 },
+ /* 4719 */ { MAD_F(0x04d4c375) /* 0.301944216 */, 18 },
+
+ /* 4720 */ { MAD_F(0x04d51ceb) /* 0.302029532 */, 18 },
+ /* 4721 */ { MAD_F(0x04d57662) /* 0.302114854 */, 18 },
+ /* 4722 */ { MAD_F(0x04d5cfdb) /* 0.302200182 */, 18 },
+ /* 4723 */ { MAD_F(0x04d62956) /* 0.302285516 */, 18 },
+ /* 4724 */ { MAD_F(0x04d682d2) /* 0.302370856 */, 18 },
+ /* 4725 */ { MAD_F(0x04d6dc50) /* 0.302456203 */, 18 },
+ /* 4726 */ { MAD_F(0x04d735d0) /* 0.302541555 */, 18 },
+ /* 4727 */ { MAD_F(0x04d78f51) /* 0.302626913 */, 18 },
+ /* 4728 */ { MAD_F(0x04d7e8d4) /* 0.302712277 */, 18 },
+ /* 4729 */ { MAD_F(0x04d84258) /* 0.302797648 */, 18 },
+ /* 4730 */ { MAD_F(0x04d89bde) /* 0.302883024 */, 18 },
+ /* 4731 */ { MAD_F(0x04d8f566) /* 0.302968406 */, 18 },
+ /* 4732 */ { MAD_F(0x04d94eef) /* 0.303053794 */, 18 },
+ /* 4733 */ { MAD_F(0x04d9a87a) /* 0.303139189 */, 18 },
+ /* 4734 */ { MAD_F(0x04da0207) /* 0.303224589 */, 18 },
+ /* 4735 */ { MAD_F(0x04da5b95) /* 0.303309995 */, 18 },
+
+ /* 4736 */ { MAD_F(0x04dab524) /* 0.303395408 */, 18 },
+ /* 4737 */ { MAD_F(0x04db0eb6) /* 0.303480826 */, 18 },
+ /* 4738 */ { MAD_F(0x04db6849) /* 0.303566251 */, 18 },
+ /* 4739 */ { MAD_F(0x04dbc1dd) /* 0.303651681 */, 18 },
+ /* 4740 */ { MAD_F(0x04dc1b73) /* 0.303737117 */, 18 },
+ /* 4741 */ { MAD_F(0x04dc750b) /* 0.303822560 */, 18 },
+ /* 4742 */ { MAD_F(0x04dccea5) /* 0.303908008 */, 18 },
+ /* 4743 */ { MAD_F(0x04dd2840) /* 0.303993463 */, 18 },
+ /* 4744 */ { MAD_F(0x04dd81dc) /* 0.304078923 */, 18 },
+ /* 4745 */ { MAD_F(0x04dddb7a) /* 0.304164390 */, 18 },
+ /* 4746 */ { MAD_F(0x04de351a) /* 0.304249862 */, 18 },
+ /* 4747 */ { MAD_F(0x04de8ebc) /* 0.304335340 */, 18 },
+ /* 4748 */ { MAD_F(0x04dee85f) /* 0.304420825 */, 18 },
+ /* 4749 */ { MAD_F(0x04df4203) /* 0.304506315 */, 18 },
+ /* 4750 */ { MAD_F(0x04df9baa) /* 0.304591812 */, 18 },
+ /* 4751 */ { MAD_F(0x04dff552) /* 0.304677314 */, 18 },
+
+ /* 4752 */ { MAD_F(0x04e04efb) /* 0.304762823 */, 18 },
+ /* 4753 */ { MAD_F(0x04e0a8a6) /* 0.304848337 */, 18 },
+ /* 4754 */ { MAD_F(0x04e10253) /* 0.304933858 */, 18 },
+ /* 4755 */ { MAD_F(0x04e15c01) /* 0.305019384 */, 18 },
+ /* 4756 */ { MAD_F(0x04e1b5b1) /* 0.305104917 */, 18 },
+ /* 4757 */ { MAD_F(0x04e20f63) /* 0.305190455 */, 18 },
+ /* 4758 */ { MAD_F(0x04e26916) /* 0.305275999 */, 18 },
+ /* 4759 */ { MAD_F(0x04e2c2cb) /* 0.305361550 */, 18 },
+ /* 4760 */ { MAD_F(0x04e31c81) /* 0.305447106 */, 18 },
+ /* 4761 */ { MAD_F(0x04e37639) /* 0.305532669 */, 18 },
+ /* 4762 */ { MAD_F(0x04e3cff3) /* 0.305618237 */, 18 },
+ /* 4763 */ { MAD_F(0x04e429ae) /* 0.305703811 */, 18 },
+ /* 4764 */ { MAD_F(0x04e4836b) /* 0.305789392 */, 18 },
+ /* 4765 */ { MAD_F(0x04e4dd29) /* 0.305874978 */, 18 },
+ /* 4766 */ { MAD_F(0x04e536e9) /* 0.305960571 */, 18 },
+ /* 4767 */ { MAD_F(0x04e590ab) /* 0.306046169 */, 18 },
+
+ /* 4768 */ { MAD_F(0x04e5ea6e) /* 0.306131773 */, 18 },
+ /* 4769 */ { MAD_F(0x04e64433) /* 0.306217383 */, 18 },
+ /* 4770 */ { MAD_F(0x04e69df9) /* 0.306303000 */, 18 },
+ /* 4771 */ { MAD_F(0x04e6f7c1) /* 0.306388622 */, 18 },
+ /* 4772 */ { MAD_F(0x04e7518b) /* 0.306474250 */, 18 },
+ /* 4773 */ { MAD_F(0x04e7ab56) /* 0.306559885 */, 18 },
+ /* 4774 */ { MAD_F(0x04e80523) /* 0.306645525 */, 18 },
+ /* 4775 */ { MAD_F(0x04e85ef2) /* 0.306731171 */, 18 },
+ /* 4776 */ { MAD_F(0x04e8b8c2) /* 0.306816823 */, 18 },
+ /* 4777 */ { MAD_F(0x04e91293) /* 0.306902481 */, 18 },
+ /* 4778 */ { MAD_F(0x04e96c67) /* 0.306988145 */, 18 },
+ /* 4779 */ { MAD_F(0x04e9c63b) /* 0.307073816 */, 18 },
+ /* 4780 */ { MAD_F(0x04ea2012) /* 0.307159492 */, 18 },
+ /* 4781 */ { MAD_F(0x04ea79ea) /* 0.307245174 */, 18 },
+ /* 4782 */ { MAD_F(0x04ead3c4) /* 0.307330862 */, 18 },
+ /* 4783 */ { MAD_F(0x04eb2d9f) /* 0.307416556 */, 18 },
+
+ /* 4784 */ { MAD_F(0x04eb877c) /* 0.307502256 */, 18 },
+ /* 4785 */ { MAD_F(0x04ebe15b) /* 0.307587962 */, 18 },
+ /* 4786 */ { MAD_F(0x04ec3b3b) /* 0.307673674 */, 18 },
+ /* 4787 */ { MAD_F(0x04ec951c) /* 0.307759392 */, 18 },
+ /* 4788 */ { MAD_F(0x04ecef00) /* 0.307845115 */, 18 },
+ /* 4789 */ { MAD_F(0x04ed48e5) /* 0.307930845 */, 18 },
+ /* 4790 */ { MAD_F(0x04eda2cb) /* 0.308016581 */, 18 },
+ /* 4791 */ { MAD_F(0x04edfcb3) /* 0.308102323 */, 18 },
+ /* 4792 */ { MAD_F(0x04ee569d) /* 0.308188071 */, 18 },
+ /* 4793 */ { MAD_F(0x04eeb088) /* 0.308273824 */, 18 },
+ /* 4794 */ { MAD_F(0x04ef0a75) /* 0.308359584 */, 18 },
+ /* 4795 */ { MAD_F(0x04ef6464) /* 0.308445350 */, 18 },
+ /* 4796 */ { MAD_F(0x04efbe54) /* 0.308531121 */, 18 },
+ /* 4797 */ { MAD_F(0x04f01846) /* 0.308616899 */, 18 },
+ /* 4798 */ { MAD_F(0x04f07239) /* 0.308702682 */, 18 },
+ /* 4799 */ { MAD_F(0x04f0cc2e) /* 0.308788472 */, 18 },
+
+ /* 4800 */ { MAD_F(0x04f12624) /* 0.308874267 */, 18 },
+ /* 4801 */ { MAD_F(0x04f1801d) /* 0.308960068 */, 18 },
+ /* 4802 */ { MAD_F(0x04f1da16) /* 0.309045876 */, 18 },
+ /* 4803 */ { MAD_F(0x04f23412) /* 0.309131689 */, 18 },
+ /* 4804 */ { MAD_F(0x04f28e0f) /* 0.309217508 */, 18 },
+ /* 4805 */ { MAD_F(0x04f2e80d) /* 0.309303334 */, 18 },
+ /* 4806 */ { MAD_F(0x04f3420d) /* 0.309389165 */, 18 },
+ /* 4807 */ { MAD_F(0x04f39c0f) /* 0.309475002 */, 18 },
+ /* 4808 */ { MAD_F(0x04f3f612) /* 0.309560845 */, 18 },
+ /* 4809 */ { MAD_F(0x04f45017) /* 0.309646694 */, 18 },
+ /* 4810 */ { MAD_F(0x04f4aa1e) /* 0.309732549 */, 18 },
+ /* 4811 */ { MAD_F(0x04f50426) /* 0.309818410 */, 18 },
+ /* 4812 */ { MAD_F(0x04f55e30) /* 0.309904277 */, 18 },
+ /* 4813 */ { MAD_F(0x04f5b83b) /* 0.309990150 */, 18 },
+ /* 4814 */ { MAD_F(0x04f61248) /* 0.310076028 */, 18 },
+ /* 4815 */ { MAD_F(0x04f66c56) /* 0.310161913 */, 18 },
+
+ /* 4816 */ { MAD_F(0x04f6c666) /* 0.310247804 */, 18 },
+ /* 4817 */ { MAD_F(0x04f72078) /* 0.310333700 */, 18 },
+ /* 4818 */ { MAD_F(0x04f77a8b) /* 0.310419603 */, 18 },
+ /* 4819 */ { MAD_F(0x04f7d4a0) /* 0.310505511 */, 18 },
+ /* 4820 */ { MAD_F(0x04f82eb7) /* 0.310591426 */, 18 },
+ /* 4821 */ { MAD_F(0x04f888cf) /* 0.310677346 */, 18 },
+ /* 4822 */ { MAD_F(0x04f8e2e9) /* 0.310763272 */, 18 },
+ /* 4823 */ { MAD_F(0x04f93d04) /* 0.310849205 */, 18 },
+ /* 4824 */ { MAD_F(0x04f99721) /* 0.310935143 */, 18 },
+ /* 4825 */ { MAD_F(0x04f9f13f) /* 0.311021087 */, 18 },
+ /* 4826 */ { MAD_F(0x04fa4b5f) /* 0.311107037 */, 18 },
+ /* 4827 */ { MAD_F(0x04faa581) /* 0.311192993 */, 18 },
+ /* 4828 */ { MAD_F(0x04faffa4) /* 0.311278955 */, 18 },
+ /* 4829 */ { MAD_F(0x04fb59c9) /* 0.311364923 */, 18 },
+ /* 4830 */ { MAD_F(0x04fbb3ef) /* 0.311450897 */, 18 },
+ /* 4831 */ { MAD_F(0x04fc0e17) /* 0.311536877 */, 18 },
+
+ /* 4832 */ { MAD_F(0x04fc6841) /* 0.311622862 */, 18 },
+ /* 4833 */ { MAD_F(0x04fcc26c) /* 0.311708854 */, 18 },
+ /* 4834 */ { MAD_F(0x04fd1c99) /* 0.311794851 */, 18 },
+ /* 4835 */ { MAD_F(0x04fd76c7) /* 0.311880855 */, 18 },
+ /* 4836 */ { MAD_F(0x04fdd0f7) /* 0.311966864 */, 18 },
+ /* 4837 */ { MAD_F(0x04fe2b29) /* 0.312052880 */, 18 },
+ /* 4838 */ { MAD_F(0x04fe855c) /* 0.312138901 */, 18 },
+ /* 4839 */ { MAD_F(0x04fedf91) /* 0.312224928 */, 18 },
+ /* 4840 */ { MAD_F(0x04ff39c7) /* 0.312310961 */, 18 },
+ /* 4841 */ { MAD_F(0x04ff93ff) /* 0.312397000 */, 18 },
+ /* 4842 */ { MAD_F(0x04ffee38) /* 0.312483045 */, 18 },
+ /* 4843 */ { MAD_F(0x05004874) /* 0.312569096 */, 18 },
+ /* 4844 */ { MAD_F(0x0500a2b0) /* 0.312655153 */, 18 },
+ /* 4845 */ { MAD_F(0x0500fcef) /* 0.312741216 */, 18 },
+ /* 4846 */ { MAD_F(0x0501572e) /* 0.312827284 */, 18 },
+ /* 4847 */ { MAD_F(0x0501b170) /* 0.312913359 */, 18 },
+
+ /* 4848 */ { MAD_F(0x05020bb3) /* 0.312999439 */, 18 },
+ /* 4849 */ { MAD_F(0x050265f8) /* 0.313085526 */, 18 },
+ /* 4850 */ { MAD_F(0x0502c03e) /* 0.313171618 */, 18 },
+ /* 4851 */ { MAD_F(0x05031a86) /* 0.313257716 */, 18 },
+ /* 4852 */ { MAD_F(0x050374cf) /* 0.313343820 */, 18 },
+ /* 4853 */ { MAD_F(0x0503cf1a) /* 0.313429931 */, 18 },
+ /* 4854 */ { MAD_F(0x05042967) /* 0.313516047 */, 18 },
+ /* 4855 */ { MAD_F(0x050483b5) /* 0.313602168 */, 18 },
+ /* 4856 */ { MAD_F(0x0504de05) /* 0.313688296 */, 18 },
+ /* 4857 */ { MAD_F(0x05053856) /* 0.313774430 */, 18 },
+ /* 4858 */ { MAD_F(0x050592a9) /* 0.313860570 */, 18 },
+ /* 4859 */ { MAD_F(0x0505ecfd) /* 0.313946715 */, 18 },
+ /* 4860 */ { MAD_F(0x05064754) /* 0.314032867 */, 18 },
+ /* 4861 */ { MAD_F(0x0506a1ab) /* 0.314119024 */, 18 },
+ /* 4862 */ { MAD_F(0x0506fc04) /* 0.314205187 */, 18 },
+ /* 4863 */ { MAD_F(0x0507565f) /* 0.314291357 */, 18 },
+
+ /* 4864 */ { MAD_F(0x0507b0bc) /* 0.314377532 */, 18 },
+ /* 4865 */ { MAD_F(0x05080b1a) /* 0.314463713 */, 18 },
+ /* 4866 */ { MAD_F(0x05086579) /* 0.314549900 */, 18 },
+ /* 4867 */ { MAD_F(0x0508bfdb) /* 0.314636092 */, 18 },
+ /* 4868 */ { MAD_F(0x05091a3d) /* 0.314722291 */, 18 },
+ /* 4869 */ { MAD_F(0x050974a2) /* 0.314808496 */, 18 },
+ /* 4870 */ { MAD_F(0x0509cf08) /* 0.314894706 */, 18 },
+ /* 4871 */ { MAD_F(0x050a296f) /* 0.314980923 */, 18 },
+ /* 4872 */ { MAD_F(0x050a83d8) /* 0.315067145 */, 18 },
+ /* 4873 */ { MAD_F(0x050ade43) /* 0.315153373 */, 18 },
+ /* 4874 */ { MAD_F(0x050b38af) /* 0.315239607 */, 18 },
+ /* 4875 */ { MAD_F(0x050b931d) /* 0.315325847 */, 18 },
+ /* 4876 */ { MAD_F(0x050bed8d) /* 0.315412093 */, 18 },
+ /* 4877 */ { MAD_F(0x050c47fe) /* 0.315498345 */, 18 },
+ /* 4878 */ { MAD_F(0x050ca271) /* 0.315584603 */, 18 },
+ /* 4879 */ { MAD_F(0x050cfce5) /* 0.315670866 */, 18 },
+
+ /* 4880 */ { MAD_F(0x050d575b) /* 0.315757136 */, 18 },
+ /* 4881 */ { MAD_F(0x050db1d2) /* 0.315843411 */, 18 },
+ /* 4882 */ { MAD_F(0x050e0c4b) /* 0.315929693 */, 18 },
+ /* 4883 */ { MAD_F(0x050e66c5) /* 0.316015980 */, 18 },
+ /* 4884 */ { MAD_F(0x050ec141) /* 0.316102273 */, 18 },
+ /* 4885 */ { MAD_F(0x050f1bbf) /* 0.316188572 */, 18 },
+ /* 4886 */ { MAD_F(0x050f763e) /* 0.316274877 */, 18 },
+ /* 4887 */ { MAD_F(0x050fd0bf) /* 0.316361187 */, 18 },
+ /* 4888 */ { MAD_F(0x05102b42) /* 0.316447504 */, 18 },
+ /* 4889 */ { MAD_F(0x051085c6) /* 0.316533826 */, 18 },
+ /* 4890 */ { MAD_F(0x0510e04b) /* 0.316620155 */, 18 },
+ /* 4891 */ { MAD_F(0x05113ad3) /* 0.316706489 */, 18 },
+ /* 4892 */ { MAD_F(0x0511955b) /* 0.316792829 */, 18 },
+ /* 4893 */ { MAD_F(0x0511efe6) /* 0.316879175 */, 18 },
+ /* 4894 */ { MAD_F(0x05124a72) /* 0.316965527 */, 18 },
+ /* 4895 */ { MAD_F(0x0512a4ff) /* 0.317051885 */, 18 },
+
+ /* 4896 */ { MAD_F(0x0512ff8e) /* 0.317138249 */, 18 },
+ /* 4897 */ { MAD_F(0x05135a1f) /* 0.317224618 */, 18 },
+ /* 4898 */ { MAD_F(0x0513b4b1) /* 0.317310994 */, 18 },
+ /* 4899 */ { MAD_F(0x05140f45) /* 0.317397375 */, 18 },
+ /* 4900 */ { MAD_F(0x051469da) /* 0.317483762 */, 18 },
+ /* 4901 */ { MAD_F(0x0514c471) /* 0.317570155 */, 18 },
+ /* 4902 */ { MAD_F(0x05151f0a) /* 0.317656554 */, 18 },
+ /* 4903 */ { MAD_F(0x051579a4) /* 0.317742959 */, 18 },
+ /* 4904 */ { MAD_F(0x0515d440) /* 0.317829370 */, 18 },
+ /* 4905 */ { MAD_F(0x05162edd) /* 0.317915786 */, 18 },
+ /* 4906 */ { MAD_F(0x0516897c) /* 0.318002209 */, 18 },
+ /* 4907 */ { MAD_F(0x0516e41c) /* 0.318088637 */, 18 },
+ /* 4908 */ { MAD_F(0x05173ebe) /* 0.318175071 */, 18 },
+ /* 4909 */ { MAD_F(0x05179962) /* 0.318261511 */, 18 },
+ /* 4910 */ { MAD_F(0x0517f407) /* 0.318347957 */, 18 },
+ /* 4911 */ { MAD_F(0x05184eae) /* 0.318434409 */, 18 },
+
+ /* 4912 */ { MAD_F(0x0518a956) /* 0.318520867 */, 18 },
+ /* 4913 */ { MAD_F(0x05190400) /* 0.318607330 */, 18 },
+ /* 4914 */ { MAD_F(0x05195eab) /* 0.318693800 */, 18 },
+ /* 4915 */ { MAD_F(0x0519b958) /* 0.318780275 */, 18 },
+ /* 4916 */ { MAD_F(0x051a1407) /* 0.318866756 */, 18 },
+ /* 4917 */ { MAD_F(0x051a6eb7) /* 0.318953243 */, 18 },
+ /* 4918 */ { MAD_F(0x051ac969) /* 0.319039736 */, 18 },
+ /* 4919 */ { MAD_F(0x051b241c) /* 0.319126235 */, 18 },
+ /* 4920 */ { MAD_F(0x051b7ed1) /* 0.319212739 */, 18 },
+ /* 4921 */ { MAD_F(0x051bd987) /* 0.319299250 */, 18 },
+ /* 4922 */ { MAD_F(0x051c3440) /* 0.319385766 */, 18 },
+ /* 4923 */ { MAD_F(0x051c8ef9) /* 0.319472288 */, 18 },
+ /* 4924 */ { MAD_F(0x051ce9b4) /* 0.319558816 */, 18 },
+ /* 4925 */ { MAD_F(0x051d4471) /* 0.319645350 */, 18 },
+ /* 4926 */ { MAD_F(0x051d9f2f) /* 0.319731890 */, 18 },
+ /* 4927 */ { MAD_F(0x051df9ef) /* 0.319818435 */, 18 },
+
+ /* 4928 */ { MAD_F(0x051e54b1) /* 0.319904987 */, 18 },
+ /* 4929 */ { MAD_F(0x051eaf74) /* 0.319991544 */, 18 },
+ /* 4930 */ { MAD_F(0x051f0a38) /* 0.320078107 */, 18 },
+ /* 4931 */ { MAD_F(0x051f64ff) /* 0.320164676 */, 18 },
+ /* 4932 */ { MAD_F(0x051fbfc6) /* 0.320251251 */, 18 },
+ /* 4933 */ { MAD_F(0x05201a90) /* 0.320337832 */, 18 },
+ /* 4934 */ { MAD_F(0x0520755b) /* 0.320424419 */, 18 },
+ /* 4935 */ { MAD_F(0x0520d027) /* 0.320511011 */, 18 },
+ /* 4936 */ { MAD_F(0x05212af5) /* 0.320597609 */, 18 },
+ /* 4937 */ { MAD_F(0x052185c5) /* 0.320684213 */, 18 },
+ /* 4938 */ { MAD_F(0x0521e096) /* 0.320770823 */, 18 },
+ /* 4939 */ { MAD_F(0x05223b69) /* 0.320857439 */, 18 },
+ /* 4940 */ { MAD_F(0x0522963d) /* 0.320944061 */, 18 },
+ /* 4941 */ { MAD_F(0x0522f113) /* 0.321030688 */, 18 },
+ /* 4942 */ { MAD_F(0x05234bea) /* 0.321117322 */, 18 },
+ /* 4943 */ { MAD_F(0x0523a6c3) /* 0.321203961 */, 18 },
+
+ /* 4944 */ { MAD_F(0x0524019e) /* 0.321290606 */, 18 },
+ /* 4945 */ { MAD_F(0x05245c7a) /* 0.321377257 */, 18 },
+ /* 4946 */ { MAD_F(0x0524b758) /* 0.321463913 */, 18 },
+ /* 4947 */ { MAD_F(0x05251237) /* 0.321550576 */, 18 },
+ /* 4948 */ { MAD_F(0x05256d18) /* 0.321637244 */, 18 },
+ /* 4949 */ { MAD_F(0x0525c7fb) /* 0.321723919 */, 18 },
+ /* 4950 */ { MAD_F(0x052622df) /* 0.321810599 */, 18 },
+ /* 4951 */ { MAD_F(0x05267dc4) /* 0.321897285 */, 18 },
+ /* 4952 */ { MAD_F(0x0526d8ab) /* 0.321983976 */, 18 },
+ /* 4953 */ { MAD_F(0x05273394) /* 0.322070674 */, 18 },
+ /* 4954 */ { MAD_F(0x05278e7e) /* 0.322157377 */, 18 },
+ /* 4955 */ { MAD_F(0x0527e96a) /* 0.322244087 */, 18 },
+ /* 4956 */ { MAD_F(0x05284457) /* 0.322330802 */, 18 },
+ /* 4957 */ { MAD_F(0x05289f46) /* 0.322417523 */, 18 },
+ /* 4958 */ { MAD_F(0x0528fa37) /* 0.322504249 */, 18 },
+ /* 4959 */ { MAD_F(0x05295529) /* 0.322590982 */, 18 },
+
+ /* 4960 */ { MAD_F(0x0529b01d) /* 0.322677720 */, 18 },
+ /* 4961 */ { MAD_F(0x052a0b12) /* 0.322764465 */, 18 },
+ /* 4962 */ { MAD_F(0x052a6609) /* 0.322851215 */, 18 },
+ /* 4963 */ { MAD_F(0x052ac101) /* 0.322937971 */, 18 },
+ /* 4964 */ { MAD_F(0x052b1bfb) /* 0.323024732 */, 18 },
+ /* 4965 */ { MAD_F(0x052b76f7) /* 0.323111500 */, 18 },
+ /* 4966 */ { MAD_F(0x052bd1f4) /* 0.323198273 */, 18 },
+ /* 4967 */ { MAD_F(0x052c2cf2) /* 0.323285052 */, 18 },
+ /* 4968 */ { MAD_F(0x052c87f2) /* 0.323371837 */, 18 },
+ /* 4969 */ { MAD_F(0x052ce2f4) /* 0.323458628 */, 18 },
+ /* 4970 */ { MAD_F(0x052d3df7) /* 0.323545425 */, 18 },
+ /* 4971 */ { MAD_F(0x052d98fc) /* 0.323632227 */, 18 },
+ /* 4972 */ { MAD_F(0x052df403) /* 0.323719036 */, 18 },
+ /* 4973 */ { MAD_F(0x052e4f0b) /* 0.323805850 */, 18 },
+ /* 4974 */ { MAD_F(0x052eaa14) /* 0.323892670 */, 18 },
+ /* 4975 */ { MAD_F(0x052f051f) /* 0.323979496 */, 18 },
+
+ /* 4976 */ { MAD_F(0x052f602c) /* 0.324066327 */, 18 },
+ /* 4977 */ { MAD_F(0x052fbb3a) /* 0.324153165 */, 18 },
+ /* 4978 */ { MAD_F(0x0530164a) /* 0.324240008 */, 18 },
+ /* 4979 */ { MAD_F(0x0530715b) /* 0.324326857 */, 18 },
+ /* 4980 */ { MAD_F(0x0530cc6e) /* 0.324413712 */, 18 },
+ /* 4981 */ { MAD_F(0x05312783) /* 0.324500572 */, 18 },
+ /* 4982 */ { MAD_F(0x05318299) /* 0.324587439 */, 18 },
+ /* 4983 */ { MAD_F(0x0531ddb0) /* 0.324674311 */, 18 },
+ /* 4984 */ { MAD_F(0x053238ca) /* 0.324761189 */, 18 },
+ /* 4985 */ { MAD_F(0x053293e4) /* 0.324848073 */, 18 },
+ /* 4986 */ { MAD_F(0x0532ef01) /* 0.324934963 */, 18 },
+ /* 4987 */ { MAD_F(0x05334a1e) /* 0.325021858 */, 18 },
+ /* 4988 */ { MAD_F(0x0533a53e) /* 0.325108760 */, 18 },
+ /* 4989 */ { MAD_F(0x0534005f) /* 0.325195667 */, 18 },
+ /* 4990 */ { MAD_F(0x05345b81) /* 0.325282580 */, 18 },
+ /* 4991 */ { MAD_F(0x0534b6a5) /* 0.325369498 */, 18 },
+
+ /* 4992 */ { MAD_F(0x053511cb) /* 0.325456423 */, 18 },
+ /* 4993 */ { MAD_F(0x05356cf2) /* 0.325543353 */, 18 },
+ /* 4994 */ { MAD_F(0x0535c81b) /* 0.325630290 */, 18 },
+ /* 4995 */ { MAD_F(0x05362345) /* 0.325717232 */, 18 },
+ /* 4996 */ { MAD_F(0x05367e71) /* 0.325804179 */, 18 },
+ /* 4997 */ { MAD_F(0x0536d99f) /* 0.325891133 */, 18 },
+ /* 4998 */ { MAD_F(0x053734ce) /* 0.325978092 */, 18 },
+ /* 4999 */ { MAD_F(0x05378ffe) /* 0.326065057 */, 18 },
+ /* 5000 */ { MAD_F(0x0537eb30) /* 0.326152028 */, 18 },
+ /* 5001 */ { MAD_F(0x05384664) /* 0.326239005 */, 18 },
+ /* 5002 */ { MAD_F(0x0538a199) /* 0.326325988 */, 18 },
+ /* 5003 */ { MAD_F(0x0538fcd0) /* 0.326412976 */, 18 },
+ /* 5004 */ { MAD_F(0x05395808) /* 0.326499970 */, 18 },
+ /* 5005 */ { MAD_F(0x0539b342) /* 0.326586970 */, 18 },
+ /* 5006 */ { MAD_F(0x053a0e7d) /* 0.326673976 */, 18 },
+ /* 5007 */ { MAD_F(0x053a69ba) /* 0.326760988 */, 18 },
+
+ /* 5008 */ { MAD_F(0x053ac4f9) /* 0.326848005 */, 18 },
+ /* 5009 */ { MAD_F(0x053b2039) /* 0.326935028 */, 18 },
+ /* 5010 */ { MAD_F(0x053b7b7b) /* 0.327022057 */, 18 },
+ /* 5011 */ { MAD_F(0x053bd6be) /* 0.327109092 */, 18 },
+ /* 5012 */ { MAD_F(0x053c3203) /* 0.327196132 */, 18 },
+ /* 5013 */ { MAD_F(0x053c8d49) /* 0.327283178 */, 18 },
+ /* 5014 */ { MAD_F(0x053ce891) /* 0.327370231 */, 18 },
+ /* 5015 */ { MAD_F(0x053d43da) /* 0.327457288 */, 18 },
+ /* 5016 */ { MAD_F(0x053d9f25) /* 0.327544352 */, 18 },
+ /* 5017 */ { MAD_F(0x053dfa72) /* 0.327631421 */, 18 },
+ /* 5018 */ { MAD_F(0x053e55c0) /* 0.327718497 */, 18 },
+ /* 5019 */ { MAD_F(0x053eb10f) /* 0.327805578 */, 18 },
+ /* 5020 */ { MAD_F(0x053f0c61) /* 0.327892665 */, 18 },
+ /* 5021 */ { MAD_F(0x053f67b3) /* 0.327979757 */, 18 },
+ /* 5022 */ { MAD_F(0x053fc308) /* 0.328066855 */, 18 },
+ /* 5023 */ { MAD_F(0x05401e5e) /* 0.328153960 */, 18 },
+
+ /* 5024 */ { MAD_F(0x054079b5) /* 0.328241070 */, 18 },
+ /* 5025 */ { MAD_F(0x0540d50e) /* 0.328328185 */, 18 },
+ /* 5026 */ { MAD_F(0x05413068) /* 0.328415307 */, 18 },
+ /* 5027 */ { MAD_F(0x05418bc4) /* 0.328502434 */, 18 },
+ /* 5028 */ { MAD_F(0x0541e722) /* 0.328589567 */, 18 },
+ /* 5029 */ { MAD_F(0x05424281) /* 0.328676706 */, 18 },
+ /* 5030 */ { MAD_F(0x05429de2) /* 0.328763850 */, 18 },
+ /* 5031 */ { MAD_F(0x0542f944) /* 0.328851001 */, 18 },
+ /* 5032 */ { MAD_F(0x054354a8) /* 0.328938157 */, 18 },
+ /* 5033 */ { MAD_F(0x0543b00d) /* 0.329025319 */, 18 },
+ /* 5034 */ { MAD_F(0x05440b74) /* 0.329112486 */, 18 },
+ /* 5035 */ { MAD_F(0x054466dd) /* 0.329199660 */, 18 },
+ /* 5036 */ { MAD_F(0x0544c247) /* 0.329286839 */, 18 },
+ /* 5037 */ { MAD_F(0x05451db2) /* 0.329374024 */, 18 },
+ /* 5038 */ { MAD_F(0x0545791f) /* 0.329461215 */, 18 },
+ /* 5039 */ { MAD_F(0x0545d48e) /* 0.329548411 */, 18 },
+
+ /* 5040 */ { MAD_F(0x05462ffe) /* 0.329635614 */, 18 },
+ /* 5041 */ { MAD_F(0x05468b70) /* 0.329722822 */, 18 },
+ /* 5042 */ { MAD_F(0x0546e6e3) /* 0.329810036 */, 18 },
+ /* 5043 */ { MAD_F(0x05474258) /* 0.329897255 */, 18 },
+ /* 5044 */ { MAD_F(0x05479dce) /* 0.329984481 */, 18 },
+ /* 5045 */ { MAD_F(0x0547f946) /* 0.330071712 */, 18 },
+ /* 5046 */ { MAD_F(0x054854c0) /* 0.330158949 */, 18 },
+ /* 5047 */ { MAD_F(0x0548b03b) /* 0.330246191 */, 18 },
+ /* 5048 */ { MAD_F(0x05490bb7) /* 0.330333440 */, 18 },
+ /* 5049 */ { MAD_F(0x05496735) /* 0.330420694 */, 18 },
+ /* 5050 */ { MAD_F(0x0549c2b5) /* 0.330507954 */, 18 },
+ /* 5051 */ { MAD_F(0x054a1e36) /* 0.330595220 */, 18 },
+ /* 5052 */ { MAD_F(0x054a79b9) /* 0.330682491 */, 18 },
+ /* 5053 */ { MAD_F(0x054ad53d) /* 0.330769768 */, 18 },
+ /* 5054 */ { MAD_F(0x054b30c3) /* 0.330857051 */, 18 },
+ /* 5055 */ { MAD_F(0x054b8c4b) /* 0.330944340 */, 18 },
+
+ /* 5056 */ { MAD_F(0x054be7d4) /* 0.331031635 */, 18 },
+ /* 5057 */ { MAD_F(0x054c435e) /* 0.331118935 */, 18 },
+ /* 5058 */ { MAD_F(0x054c9eea) /* 0.331206241 */, 18 },
+ /* 5059 */ { MAD_F(0x054cfa78) /* 0.331293553 */, 18 },
+ /* 5060 */ { MAD_F(0x054d5607) /* 0.331380870 */, 18 },
+ /* 5061 */ { MAD_F(0x054db197) /* 0.331468193 */, 18 },
+ /* 5062 */ { MAD_F(0x054e0d2a) /* 0.331555522 */, 18 },
+ /* 5063 */ { MAD_F(0x054e68bd) /* 0.331642857 */, 18 },
+ /* 5064 */ { MAD_F(0x054ec453) /* 0.331730198 */, 18 },
+ /* 5065 */ { MAD_F(0x054f1fe9) /* 0.331817544 */, 18 },
+ /* 5066 */ { MAD_F(0x054f7b82) /* 0.331904896 */, 18 },
+ /* 5067 */ { MAD_F(0x054fd71c) /* 0.331992254 */, 18 },
+ /* 5068 */ { MAD_F(0x055032b7) /* 0.332079617 */, 18 },
+ /* 5069 */ { MAD_F(0x05508e54) /* 0.332166986 */, 18 },
+ /* 5070 */ { MAD_F(0x0550e9f3) /* 0.332254361 */, 18 },
+ /* 5071 */ { MAD_F(0x05514593) /* 0.332341742 */, 18 },
+
+ /* 5072 */ { MAD_F(0x0551a134) /* 0.332429129 */, 18 },
+ /* 5073 */ { MAD_F(0x0551fcd8) /* 0.332516521 */, 18 },
+ /* 5074 */ { MAD_F(0x0552587c) /* 0.332603919 */, 18 },
+ /* 5075 */ { MAD_F(0x0552b423) /* 0.332691323 */, 18 },
+ /* 5076 */ { MAD_F(0x05530fca) /* 0.332778732 */, 18 },
+ /* 5077 */ { MAD_F(0x05536b74) /* 0.332866147 */, 18 },
+ /* 5078 */ { MAD_F(0x0553c71f) /* 0.332953568 */, 18 },
+ /* 5079 */ { MAD_F(0x055422cb) /* 0.333040995 */, 18 },
+ /* 5080 */ { MAD_F(0x05547e79) /* 0.333128427 */, 18 },
+ /* 5081 */ { MAD_F(0x0554da29) /* 0.333215865 */, 18 },
+ /* 5082 */ { MAD_F(0x055535da) /* 0.333303309 */, 18 },
+ /* 5083 */ { MAD_F(0x0555918c) /* 0.333390759 */, 18 },
+ /* 5084 */ { MAD_F(0x0555ed40) /* 0.333478214 */, 18 },
+ /* 5085 */ { MAD_F(0x055648f6) /* 0.333565675 */, 18 },
+ /* 5086 */ { MAD_F(0x0556a4ad) /* 0.333653142 */, 18 },
+ /* 5087 */ { MAD_F(0x05570066) /* 0.333740615 */, 18 },
+
+ /* 5088 */ { MAD_F(0x05575c20) /* 0.333828093 */, 18 },
+ /* 5089 */ { MAD_F(0x0557b7dc) /* 0.333915577 */, 18 },
+ /* 5090 */ { MAD_F(0x05581399) /* 0.334003067 */, 18 },
+ /* 5091 */ { MAD_F(0x05586f58) /* 0.334090562 */, 18 },
+ /* 5092 */ { MAD_F(0x0558cb19) /* 0.334178063 */, 18 },
+ /* 5093 */ { MAD_F(0x055926db) /* 0.334265570 */, 18 },
+ /* 5094 */ { MAD_F(0x0559829e) /* 0.334353083 */, 18 },
+ /* 5095 */ { MAD_F(0x0559de63) /* 0.334440601 */, 18 },
+ /* 5096 */ { MAD_F(0x055a3a2a) /* 0.334528126 */, 18 },
+ /* 5097 */ { MAD_F(0x055a95f2) /* 0.334615655 */, 18 },
+ /* 5098 */ { MAD_F(0x055af1bb) /* 0.334703191 */, 18 },
+ /* 5099 */ { MAD_F(0x055b4d87) /* 0.334790732 */, 18 },
+ /* 5100 */ { MAD_F(0x055ba953) /* 0.334878279 */, 18 },
+ /* 5101 */ { MAD_F(0x055c0522) /* 0.334965832 */, 18 },
+ /* 5102 */ { MAD_F(0x055c60f1) /* 0.335053391 */, 18 },
+ /* 5103 */ { MAD_F(0x055cbcc3) /* 0.335140955 */, 18 },
+
+ /* 5104 */ { MAD_F(0x055d1896) /* 0.335228525 */, 18 },
+ /* 5105 */ { MAD_F(0x055d746a) /* 0.335316100 */, 18 },
+ /* 5106 */ { MAD_F(0x055dd040) /* 0.335403682 */, 18 },
+ /* 5107 */ { MAD_F(0x055e2c17) /* 0.335491269 */, 18 },
+ /* 5108 */ { MAD_F(0x055e87f0) /* 0.335578861 */, 18 },
+ /* 5109 */ { MAD_F(0x055ee3cb) /* 0.335666460 */, 18 },
+ /* 5110 */ { MAD_F(0x055f3fa7) /* 0.335754064 */, 18 },
+ /* 5111 */ { MAD_F(0x055f9b85) /* 0.335841674 */, 18 },
+ /* 5112 */ { MAD_F(0x055ff764) /* 0.335929290 */, 18 },
+ /* 5113 */ { MAD_F(0x05605344) /* 0.336016911 */, 18 },
+ /* 5114 */ { MAD_F(0x0560af27) /* 0.336104538 */, 18 },
+ /* 5115 */ { MAD_F(0x05610b0a) /* 0.336192171 */, 18 },
+ /* 5116 */ { MAD_F(0x056166f0) /* 0.336279809 */, 18 },
+ /* 5117 */ { MAD_F(0x0561c2d7) /* 0.336367453 */, 18 },
+ /* 5118 */ { MAD_F(0x05621ebf) /* 0.336455103 */, 18 },
+ /* 5119 */ { MAD_F(0x05627aa9) /* 0.336542759 */, 18 },
+
+ /* 5120 */ { MAD_F(0x0562d694) /* 0.336630420 */, 18 },
+ /* 5121 */ { MAD_F(0x05633281) /* 0.336718087 */, 18 },
+ /* 5122 */ { MAD_F(0x05638e70) /* 0.336805760 */, 18 },
+ /* 5123 */ { MAD_F(0x0563ea60) /* 0.336893439 */, 18 },
+ /* 5124 */ { MAD_F(0x05644651) /* 0.336981123 */, 18 },
+ /* 5125 */ { MAD_F(0x0564a244) /* 0.337068813 */, 18 },
+ /* 5126 */ { MAD_F(0x0564fe39) /* 0.337156508 */, 18 },
+ /* 5127 */ { MAD_F(0x05655a2f) /* 0.337244209 */, 18 },
+ /* 5128 */ { MAD_F(0x0565b627) /* 0.337331916 */, 18 },
+ /* 5129 */ { MAD_F(0x05661220) /* 0.337419629 */, 18 },
+ /* 5130 */ { MAD_F(0x05666e1a) /* 0.337507347 */, 18 },
+ /* 5131 */ { MAD_F(0x0566ca17) /* 0.337595071 */, 18 },
+ /* 5132 */ { MAD_F(0x05672614) /* 0.337682801 */, 18 },
+ /* 5133 */ { MAD_F(0x05678214) /* 0.337770537 */, 18 },
+ /* 5134 */ { MAD_F(0x0567de15) /* 0.337858278 */, 18 },
+ /* 5135 */ { MAD_F(0x05683a17) /* 0.337946025 */, 18 },
+
+ /* 5136 */ { MAD_F(0x0568961b) /* 0.338033777 */, 18 },
+ /* 5137 */ { MAD_F(0x0568f220) /* 0.338121535 */, 18 },
+ /* 5138 */ { MAD_F(0x05694e27) /* 0.338209299 */, 18 },
+ /* 5139 */ { MAD_F(0x0569aa30) /* 0.338297069 */, 18 },
+ /* 5140 */ { MAD_F(0x056a063a) /* 0.338384844 */, 18 },
+ /* 5141 */ { MAD_F(0x056a6245) /* 0.338472625 */, 18 },
+ /* 5142 */ { MAD_F(0x056abe52) /* 0.338560412 */, 18 },
+ /* 5143 */ { MAD_F(0x056b1a61) /* 0.338648204 */, 18 },
+ /* 5144 */ { MAD_F(0x056b7671) /* 0.338736002 */, 18 },
+ /* 5145 */ { MAD_F(0x056bd283) /* 0.338823806 */, 18 },
+ /* 5146 */ { MAD_F(0x056c2e96) /* 0.338911616 */, 18 },
+ /* 5147 */ { MAD_F(0x056c8aab) /* 0.338999431 */, 18 },
+ /* 5148 */ { MAD_F(0x056ce6c1) /* 0.339087252 */, 18 },
+ /* 5149 */ { MAD_F(0x056d42d9) /* 0.339175078 */, 18 },
+ /* 5150 */ { MAD_F(0x056d9ef2) /* 0.339262910 */, 18 },
+ /* 5151 */ { MAD_F(0x056dfb0d) /* 0.339350748 */, 18 },
+
+ /* 5152 */ { MAD_F(0x056e5729) /* 0.339438592 */, 18 },
+ /* 5153 */ { MAD_F(0x056eb347) /* 0.339526441 */, 18 },
+ /* 5154 */ { MAD_F(0x056f0f66) /* 0.339614296 */, 18 },
+ /* 5155 */ { MAD_F(0x056f6b87) /* 0.339702157 */, 18 },
+ /* 5156 */ { MAD_F(0x056fc7aa) /* 0.339790023 */, 18 },
+ /* 5157 */ { MAD_F(0x057023cd) /* 0.339877895 */, 18 },
+ /* 5158 */ { MAD_F(0x05707ff3) /* 0.339965773 */, 18 },
+ /* 5159 */ { MAD_F(0x0570dc1a) /* 0.340053656 */, 18 },
+ /* 5160 */ { MAD_F(0x05713843) /* 0.340141545 */, 18 },
+ /* 5161 */ { MAD_F(0x0571946d) /* 0.340229440 */, 18 },
+ /* 5162 */ { MAD_F(0x0571f098) /* 0.340317340 */, 18 },
+ /* 5163 */ { MAD_F(0x05724cc5) /* 0.340405246 */, 18 },
+ /* 5164 */ { MAD_F(0x0572a8f4) /* 0.340493158 */, 18 },
+ /* 5165 */ { MAD_F(0x05730524) /* 0.340581075 */, 18 },
+ /* 5166 */ { MAD_F(0x05736156) /* 0.340668999 */, 18 },
+ /* 5167 */ { MAD_F(0x0573bd89) /* 0.340756927 */, 18 },
+
+ /* 5168 */ { MAD_F(0x057419be) /* 0.340844862 */, 18 },
+ /* 5169 */ { MAD_F(0x057475f4) /* 0.340932802 */, 18 },
+ /* 5170 */ { MAD_F(0x0574d22c) /* 0.341020748 */, 18 },
+ /* 5171 */ { MAD_F(0x05752e65) /* 0.341108699 */, 18 },
+ /* 5172 */ { MAD_F(0x05758aa0) /* 0.341196656 */, 18 },
+ /* 5173 */ { MAD_F(0x0575e6dc) /* 0.341284619 */, 18 },
+ /* 5174 */ { MAD_F(0x0576431a) /* 0.341372587 */, 18 },
+ /* 5175 */ { MAD_F(0x05769f59) /* 0.341460562 */, 18 },
+ /* 5176 */ { MAD_F(0x0576fb9a) /* 0.341548541 */, 18 },
+ /* 5177 */ { MAD_F(0x057757dd) /* 0.341636527 */, 18 },
+ /* 5178 */ { MAD_F(0x0577b421) /* 0.341724518 */, 18 },
+ /* 5179 */ { MAD_F(0x05781066) /* 0.341812515 */, 18 },
+ /* 5180 */ { MAD_F(0x05786cad) /* 0.341900517 */, 18 },
+ /* 5181 */ { MAD_F(0x0578c8f5) /* 0.341988525 */, 18 },
+ /* 5182 */ { MAD_F(0x0579253f) /* 0.342076539 */, 18 },
+ /* 5183 */ { MAD_F(0x0579818b) /* 0.342164558 */, 18 },
+
+ /* 5184 */ { MAD_F(0x0579ddd8) /* 0.342252584 */, 18 },
+ /* 5185 */ { MAD_F(0x057a3a27) /* 0.342340614 */, 18 },
+ /* 5186 */ { MAD_F(0x057a9677) /* 0.342428651 */, 18 },
+ /* 5187 */ { MAD_F(0x057af2c8) /* 0.342516693 */, 18 },
+ /* 5188 */ { MAD_F(0x057b4f1c) /* 0.342604741 */, 18 },
+ /* 5189 */ { MAD_F(0x057bab70) /* 0.342692794 */, 18 },
+ /* 5190 */ { MAD_F(0x057c07c6) /* 0.342780853 */, 18 },
+ /* 5191 */ { MAD_F(0x057c641e) /* 0.342868918 */, 18 },
+ /* 5192 */ { MAD_F(0x057cc077) /* 0.342956988 */, 18 },
+ /* 5193 */ { MAD_F(0x057d1cd2) /* 0.343045064 */, 18 },
+ /* 5194 */ { MAD_F(0x057d792e) /* 0.343133146 */, 18 },
+ /* 5195 */ { MAD_F(0x057dd58c) /* 0.343221233 */, 18 },
+ /* 5196 */ { MAD_F(0x057e31eb) /* 0.343309326 */, 18 },
+ /* 5197 */ { MAD_F(0x057e8e4c) /* 0.343397425 */, 18 },
+ /* 5198 */ { MAD_F(0x057eeaae) /* 0.343485529 */, 18 },
+ /* 5199 */ { MAD_F(0x057f4712) /* 0.343573639 */, 18 },
+
+ /* 5200 */ { MAD_F(0x057fa378) /* 0.343661754 */, 18 },
+ /* 5201 */ { MAD_F(0x057fffde) /* 0.343749876 */, 18 },
+ /* 5202 */ { MAD_F(0x05805c47) /* 0.343838003 */, 18 },
+ /* 5203 */ { MAD_F(0x0580b8b1) /* 0.343926135 */, 18 },
+ /* 5204 */ { MAD_F(0x0581151c) /* 0.344014273 */, 18 },
+ /* 5205 */ { MAD_F(0x05817189) /* 0.344102417 */, 18 },
+ /* 5206 */ { MAD_F(0x0581cdf7) /* 0.344190566 */, 18 },
+ /* 5207 */ { MAD_F(0x05822a67) /* 0.344278722 */, 18 },
+ /* 5208 */ { MAD_F(0x058286d9) /* 0.344366882 */, 18 },
+ /* 5209 */ { MAD_F(0x0582e34c) /* 0.344455049 */, 18 },
+ /* 5210 */ { MAD_F(0x05833fc0) /* 0.344543221 */, 18 },
+ /* 5211 */ { MAD_F(0x05839c36) /* 0.344631398 */, 18 },
+ /* 5212 */ { MAD_F(0x0583f8ae) /* 0.344719582 */, 18 },
+ /* 5213 */ { MAD_F(0x05845527) /* 0.344807771 */, 18 },
+ /* 5214 */ { MAD_F(0x0584b1a1) /* 0.344895965 */, 18 },
+ /* 5215 */ { MAD_F(0x05850e1e) /* 0.344984165 */, 18 },
+
+ /* 5216 */ { MAD_F(0x05856a9b) /* 0.345072371 */, 18 },
+ /* 5217 */ { MAD_F(0x0585c71a) /* 0.345160583 */, 18 },
+ /* 5218 */ { MAD_F(0x0586239b) /* 0.345248800 */, 18 },
+ /* 5219 */ { MAD_F(0x0586801d) /* 0.345337023 */, 18 },
+ /* 5220 */ { MAD_F(0x0586dca1) /* 0.345425251 */, 18 },
+ /* 5221 */ { MAD_F(0x05873926) /* 0.345513485 */, 18 },
+ /* 5222 */ { MAD_F(0x058795ac) /* 0.345601725 */, 18 },
+ /* 5223 */ { MAD_F(0x0587f235) /* 0.345689970 */, 18 },
+ /* 5224 */ { MAD_F(0x05884ebe) /* 0.345778221 */, 18 },
+ /* 5225 */ { MAD_F(0x0588ab49) /* 0.345866478 */, 18 },
+ /* 5226 */ { MAD_F(0x058907d6) /* 0.345954740 */, 18 },
+ /* 5227 */ { MAD_F(0x05896464) /* 0.346043008 */, 18 },
+ /* 5228 */ { MAD_F(0x0589c0f4) /* 0.346131281 */, 18 },
+ /* 5229 */ { MAD_F(0x058a1d85) /* 0.346219560 */, 18 },
+ /* 5230 */ { MAD_F(0x058a7a18) /* 0.346307845 */, 18 },
+ /* 5231 */ { MAD_F(0x058ad6ac) /* 0.346396135 */, 18 },
+
+ /* 5232 */ { MAD_F(0x058b3342) /* 0.346484431 */, 18 },
+ /* 5233 */ { MAD_F(0x058b8fd9) /* 0.346572733 */, 18 },
+ /* 5234 */ { MAD_F(0x058bec72) /* 0.346661040 */, 18 },
+ /* 5235 */ { MAD_F(0x058c490c) /* 0.346749353 */, 18 },
+ /* 5236 */ { MAD_F(0x058ca5a8) /* 0.346837671 */, 18 },
+ /* 5237 */ { MAD_F(0x058d0246) /* 0.346925996 */, 18 },
+ /* 5238 */ { MAD_F(0x058d5ee4) /* 0.347014325 */, 18 },
+ /* 5239 */ { MAD_F(0x058dbb85) /* 0.347102661 */, 18 },
+ /* 5240 */ { MAD_F(0x058e1827) /* 0.347191002 */, 18 },
+ /* 5241 */ { MAD_F(0x058e74ca) /* 0.347279348 */, 18 },
+ /* 5242 */ { MAD_F(0x058ed16f) /* 0.347367700 */, 18 },
+ /* 5243 */ { MAD_F(0x058f2e15) /* 0.347456058 */, 18 },
+ /* 5244 */ { MAD_F(0x058f8abd) /* 0.347544422 */, 18 },
+ /* 5245 */ { MAD_F(0x058fe766) /* 0.347632791 */, 18 },
+ /* 5246 */ { MAD_F(0x05904411) /* 0.347721165 */, 18 },
+ /* 5247 */ { MAD_F(0x0590a0be) /* 0.347809546 */, 18 },
+
+ /* 5248 */ { MAD_F(0x0590fd6c) /* 0.347897931 */, 18 },
+ /* 5249 */ { MAD_F(0x05915a1b) /* 0.347986323 */, 18 },
+ /* 5250 */ { MAD_F(0x0591b6cc) /* 0.348074720 */, 18 },
+ /* 5251 */ { MAD_F(0x0592137e) /* 0.348163123 */, 18 },
+ /* 5252 */ { MAD_F(0x05927032) /* 0.348251531 */, 18 },
+ /* 5253 */ { MAD_F(0x0592cce8) /* 0.348339945 */, 18 },
+ /* 5254 */ { MAD_F(0x0593299f) /* 0.348428365 */, 18 },
+ /* 5255 */ { MAD_F(0x05938657) /* 0.348516790 */, 18 },
+ /* 5256 */ { MAD_F(0x0593e311) /* 0.348605221 */, 18 },
+ /* 5257 */ { MAD_F(0x05943fcd) /* 0.348693657 */, 18 },
+ /* 5258 */ { MAD_F(0x05949c8a) /* 0.348782099 */, 18 },
+ /* 5259 */ { MAD_F(0x0594f948) /* 0.348870547 */, 18 },
+ /* 5260 */ { MAD_F(0x05955608) /* 0.348959000 */, 18 },
+ /* 5261 */ { MAD_F(0x0595b2ca) /* 0.349047459 */, 18 },
+ /* 5262 */ { MAD_F(0x05960f8c) /* 0.349135923 */, 18 },
+ /* 5263 */ { MAD_F(0x05966c51) /* 0.349224393 */, 18 },
+
+ /* 5264 */ { MAD_F(0x0596c917) /* 0.349312869 */, 18 },
+ /* 5265 */ { MAD_F(0x059725de) /* 0.349401350 */, 18 },
+ /* 5266 */ { MAD_F(0x059782a7) /* 0.349489837 */, 18 },
+ /* 5267 */ { MAD_F(0x0597df72) /* 0.349578329 */, 18 },
+ /* 5268 */ { MAD_F(0x05983c3e) /* 0.349666827 */, 18 },
+ /* 5269 */ { MAD_F(0x0598990c) /* 0.349755331 */, 18 },
+ /* 5270 */ { MAD_F(0x0598f5db) /* 0.349843840 */, 18 },
+ /* 5271 */ { MAD_F(0x059952ab) /* 0.349932355 */, 18 },
+ /* 5272 */ { MAD_F(0x0599af7d) /* 0.350020876 */, 18 },
+ /* 5273 */ { MAD_F(0x059a0c51) /* 0.350109402 */, 18 },
+ /* 5274 */ { MAD_F(0x059a6926) /* 0.350197933 */, 18 },
+ /* 5275 */ { MAD_F(0x059ac5fc) /* 0.350286470 */, 18 },
+ /* 5276 */ { MAD_F(0x059b22d4) /* 0.350375013 */, 18 },
+ /* 5277 */ { MAD_F(0x059b7fae) /* 0.350463562 */, 18 },
+ /* 5278 */ { MAD_F(0x059bdc89) /* 0.350552116 */, 18 },
+ /* 5279 */ { MAD_F(0x059c3965) /* 0.350640675 */, 18 },
+
+ /* 5280 */ { MAD_F(0x059c9643) /* 0.350729240 */, 18 },
+ /* 5281 */ { MAD_F(0x059cf323) /* 0.350817811 */, 18 },
+ /* 5282 */ { MAD_F(0x059d5004) /* 0.350906388 */, 18 },
+ /* 5283 */ { MAD_F(0x059dace6) /* 0.350994970 */, 18 },
+ /* 5284 */ { MAD_F(0x059e09cb) /* 0.351083557 */, 18 },
+ /* 5285 */ { MAD_F(0x059e66b0) /* 0.351172150 */, 18 },
+ /* 5286 */ { MAD_F(0x059ec397) /* 0.351260749 */, 18 },
+ /* 5287 */ { MAD_F(0x059f2080) /* 0.351349353 */, 18 },
+ /* 5288 */ { MAD_F(0x059f7d6a) /* 0.351437963 */, 18 },
+ /* 5289 */ { MAD_F(0x059fda55) /* 0.351526579 */, 18 },
+ /* 5290 */ { MAD_F(0x05a03742) /* 0.351615200 */, 18 },
+ /* 5291 */ { MAD_F(0x05a09431) /* 0.351703827 */, 18 },
+ /* 5292 */ { MAD_F(0x05a0f121) /* 0.351792459 */, 18 },
+ /* 5293 */ { MAD_F(0x05a14e12) /* 0.351881097 */, 18 },
+ /* 5294 */ { MAD_F(0x05a1ab05) /* 0.351969740 */, 18 },
+ /* 5295 */ { MAD_F(0x05a207fa) /* 0.352058389 */, 18 },
+
+ /* 5296 */ { MAD_F(0x05a264f0) /* 0.352147044 */, 18 },
+ /* 5297 */ { MAD_F(0x05a2c1e7) /* 0.352235704 */, 18 },
+ /* 5298 */ { MAD_F(0x05a31ee1) /* 0.352324369 */, 18 },
+ /* 5299 */ { MAD_F(0x05a37bdb) /* 0.352413041 */, 18 },
+ /* 5300 */ { MAD_F(0x05a3d8d7) /* 0.352501718 */, 18 },
+ /* 5301 */ { MAD_F(0x05a435d5) /* 0.352590400 */, 18 },
+ /* 5302 */ { MAD_F(0x05a492d4) /* 0.352679088 */, 18 },
+ /* 5303 */ { MAD_F(0x05a4efd4) /* 0.352767782 */, 18 },
+ /* 5304 */ { MAD_F(0x05a54cd6) /* 0.352856481 */, 18 },
+ /* 5305 */ { MAD_F(0x05a5a9da) /* 0.352945186 */, 18 },
+ /* 5306 */ { MAD_F(0x05a606df) /* 0.353033896 */, 18 },
+ /* 5307 */ { MAD_F(0x05a663e5) /* 0.353122612 */, 18 },
+ /* 5308 */ { MAD_F(0x05a6c0ed) /* 0.353211333 */, 18 },
+ /* 5309 */ { MAD_F(0x05a71df7) /* 0.353300061 */, 18 },
+ /* 5310 */ { MAD_F(0x05a77b02) /* 0.353388793 */, 18 },
+ /* 5311 */ { MAD_F(0x05a7d80e) /* 0.353477531 */, 18 },
+
+ /* 5312 */ { MAD_F(0x05a8351c) /* 0.353566275 */, 18 },
+ /* 5313 */ { MAD_F(0x05a8922c) /* 0.353655024 */, 18 },
+ /* 5314 */ { MAD_F(0x05a8ef3c) /* 0.353743779 */, 18 },
+ /* 5315 */ { MAD_F(0x05a94c4f) /* 0.353832540 */, 18 },
+ /* 5316 */ { MAD_F(0x05a9a963) /* 0.353921306 */, 18 },
+ /* 5317 */ { MAD_F(0x05aa0678) /* 0.354010077 */, 18 },
+ /* 5318 */ { MAD_F(0x05aa638f) /* 0.354098855 */, 18 },
+ /* 5319 */ { MAD_F(0x05aac0a8) /* 0.354187637 */, 18 },
+ /* 5320 */ { MAD_F(0x05ab1dc2) /* 0.354276426 */, 18 },
+ /* 5321 */ { MAD_F(0x05ab7add) /* 0.354365220 */, 18 },
+ /* 5322 */ { MAD_F(0x05abd7fa) /* 0.354454019 */, 18 },
+ /* 5323 */ { MAD_F(0x05ac3518) /* 0.354542824 */, 18 },
+ /* 5324 */ { MAD_F(0x05ac9238) /* 0.354631635 */, 18 },
+ /* 5325 */ { MAD_F(0x05acef5a) /* 0.354720451 */, 18 },
+ /* 5326 */ { MAD_F(0x05ad4c7d) /* 0.354809272 */, 18 },
+ /* 5327 */ { MAD_F(0x05ada9a1) /* 0.354898100 */, 18 },
+
+ /* 5328 */ { MAD_F(0x05ae06c7) /* 0.354986932 */, 18 },
+ /* 5329 */ { MAD_F(0x05ae63ee) /* 0.355075771 */, 18 },
+ /* 5330 */ { MAD_F(0x05aec117) /* 0.355164615 */, 18 },
+ /* 5331 */ { MAD_F(0x05af1e41) /* 0.355253464 */, 18 },
+ /* 5332 */ { MAD_F(0x05af7b6d) /* 0.355342319 */, 18 },
+ /* 5333 */ { MAD_F(0x05afd89b) /* 0.355431180 */, 18 },
+ /* 5334 */ { MAD_F(0x05b035c9) /* 0.355520046 */, 18 },
+ /* 5335 */ { MAD_F(0x05b092fa) /* 0.355608917 */, 18 },
+ /* 5336 */ { MAD_F(0x05b0f02b) /* 0.355697795 */, 18 },
+ /* 5337 */ { MAD_F(0x05b14d5f) /* 0.355786677 */, 18 },
+ /* 5338 */ { MAD_F(0x05b1aa94) /* 0.355875566 */, 18 },
+ /* 5339 */ { MAD_F(0x05b207ca) /* 0.355964460 */, 18 },
+ /* 5340 */ { MAD_F(0x05b26502) /* 0.356053359 */, 18 },
+ /* 5341 */ { MAD_F(0x05b2c23b) /* 0.356142264 */, 18 },
+ /* 5342 */ { MAD_F(0x05b31f76) /* 0.356231175 */, 18 },
+ /* 5343 */ { MAD_F(0x05b37cb2) /* 0.356320091 */, 18 },
+
+ /* 5344 */ { MAD_F(0x05b3d9f0) /* 0.356409012 */, 18 },
+ /* 5345 */ { MAD_F(0x05b4372f) /* 0.356497940 */, 18 },
+ /* 5346 */ { MAD_F(0x05b4946f) /* 0.356586872 */, 18 },
+ /* 5347 */ { MAD_F(0x05b4f1b2) /* 0.356675811 */, 18 },
+ /* 5348 */ { MAD_F(0x05b54ef5) /* 0.356764754 */, 18 },
+ /* 5349 */ { MAD_F(0x05b5ac3a) /* 0.356853704 */, 18 },
+ /* 5350 */ { MAD_F(0x05b60981) /* 0.356942659 */, 18 },
+ /* 5351 */ { MAD_F(0x05b666c9) /* 0.357031619 */, 18 },
+ /* 5352 */ { MAD_F(0x05b6c413) /* 0.357120585 */, 18 },
+ /* 5353 */ { MAD_F(0x05b7215e) /* 0.357209557 */, 18 },
+ /* 5354 */ { MAD_F(0x05b77eab) /* 0.357298534 */, 18 },
+ /* 5355 */ { MAD_F(0x05b7dbf9) /* 0.357387516 */, 18 },
+ /* 5356 */ { MAD_F(0x05b83948) /* 0.357476504 */, 18 },
+ /* 5357 */ { MAD_F(0x05b89699) /* 0.357565498 */, 18 },
+ /* 5358 */ { MAD_F(0x05b8f3ec) /* 0.357654497 */, 18 },
+ /* 5359 */ { MAD_F(0x05b95140) /* 0.357743502 */, 18 },
+
+ /* 5360 */ { MAD_F(0x05b9ae95) /* 0.357832512 */, 18 },
+ /* 5361 */ { MAD_F(0x05ba0bec) /* 0.357921528 */, 18 },
+ /* 5362 */ { MAD_F(0x05ba6945) /* 0.358010550 */, 18 },
+ /* 5363 */ { MAD_F(0x05bac69f) /* 0.358099576 */, 18 },
+ /* 5364 */ { MAD_F(0x05bb23fa) /* 0.358188609 */, 18 },
+ /* 5365 */ { MAD_F(0x05bb8157) /* 0.358277647 */, 18 },
+ /* 5366 */ { MAD_F(0x05bbdeb6) /* 0.358366690 */, 18 },
+ /* 5367 */ { MAD_F(0x05bc3c16) /* 0.358455739 */, 18 },
+ /* 5368 */ { MAD_F(0x05bc9977) /* 0.358544794 */, 18 },
+ /* 5369 */ { MAD_F(0x05bcf6da) /* 0.358633854 */, 18 },
+ /* 5370 */ { MAD_F(0x05bd543e) /* 0.358722920 */, 18 },
+ /* 5371 */ { MAD_F(0x05bdb1a4) /* 0.358811991 */, 18 },
+ /* 5372 */ { MAD_F(0x05be0f0b) /* 0.358901067 */, 18 },
+ /* 5373 */ { MAD_F(0x05be6c74) /* 0.358990150 */, 18 },
+ /* 5374 */ { MAD_F(0x05bec9df) /* 0.359079237 */, 18 },
+ /* 5375 */ { MAD_F(0x05bf274a) /* 0.359168331 */, 18 },
+
+ /* 5376 */ { MAD_F(0x05bf84b8) /* 0.359257429 */, 18 },
+ /* 5377 */ { MAD_F(0x05bfe226) /* 0.359346534 */, 18 },
+ /* 5378 */ { MAD_F(0x05c03f97) /* 0.359435644 */, 18 },
+ /* 5379 */ { MAD_F(0x05c09d08) /* 0.359524759 */, 18 },
+ /* 5380 */ { MAD_F(0x05c0fa7c) /* 0.359613880 */, 18 },
+ /* 5381 */ { MAD_F(0x05c157f0) /* 0.359703006 */, 18 },
+ /* 5382 */ { MAD_F(0x05c1b566) /* 0.359792138 */, 18 },
+ /* 5383 */ { MAD_F(0x05c212de) /* 0.359881276 */, 18 },
+ /* 5384 */ { MAD_F(0x05c27057) /* 0.359970419 */, 18 },
+ /* 5385 */ { MAD_F(0x05c2cdd2) /* 0.360059567 */, 18 },
+ /* 5386 */ { MAD_F(0x05c32b4e) /* 0.360148721 */, 18 },
+ /* 5387 */ { MAD_F(0x05c388cb) /* 0.360237881 */, 18 },
+ /* 5388 */ { MAD_F(0x05c3e64b) /* 0.360327046 */, 18 },
+ /* 5389 */ { MAD_F(0x05c443cb) /* 0.360416216 */, 18 },
+ /* 5390 */ { MAD_F(0x05c4a14d) /* 0.360505392 */, 18 },
+ /* 5391 */ { MAD_F(0x05c4fed1) /* 0.360594574 */, 18 },
+
+ /* 5392 */ { MAD_F(0x05c55c56) /* 0.360683761 */, 18 },
+ /* 5393 */ { MAD_F(0x05c5b9dc) /* 0.360772953 */, 18 },
+ /* 5394 */ { MAD_F(0x05c61764) /* 0.360862152 */, 18 },
+ /* 5395 */ { MAD_F(0x05c674ed) /* 0.360951355 */, 18 },
+ /* 5396 */ { MAD_F(0x05c6d278) /* 0.361040564 */, 18 },
+ /* 5397 */ { MAD_F(0x05c73005) /* 0.361129779 */, 18 },
+ /* 5398 */ { MAD_F(0x05c78d93) /* 0.361218999 */, 18 },
+ /* 5399 */ { MAD_F(0x05c7eb22) /* 0.361308225 */, 18 },
+ /* 5400 */ { MAD_F(0x05c848b3) /* 0.361397456 */, 18 },
+ /* 5401 */ { MAD_F(0x05c8a645) /* 0.361486693 */, 18 },
+ /* 5402 */ { MAD_F(0x05c903d9) /* 0.361575935 */, 18 },
+ /* 5403 */ { MAD_F(0x05c9616e) /* 0.361665183 */, 18 },
+ /* 5404 */ { MAD_F(0x05c9bf05) /* 0.361754436 */, 18 },
+ /* 5405 */ { MAD_F(0x05ca1c9d) /* 0.361843695 */, 18 },
+ /* 5406 */ { MAD_F(0x05ca7a37) /* 0.361932959 */, 18 },
+ /* 5407 */ { MAD_F(0x05cad7d2) /* 0.362022229 */, 18 },
+
+ /* 5408 */ { MAD_F(0x05cb356e) /* 0.362111504 */, 18 },
+ /* 5409 */ { MAD_F(0x05cb930d) /* 0.362200785 */, 18 },
+ /* 5410 */ { MAD_F(0x05cbf0ac) /* 0.362290071 */, 18 },
+ /* 5411 */ { MAD_F(0x05cc4e4d) /* 0.362379362 */, 18 },
+ /* 5412 */ { MAD_F(0x05ccabf0) /* 0.362468660 */, 18 },
+ /* 5413 */ { MAD_F(0x05cd0994) /* 0.362557962 */, 18 },
+ /* 5414 */ { MAD_F(0x05cd6739) /* 0.362647271 */, 18 },
+ /* 5415 */ { MAD_F(0x05cdc4e0) /* 0.362736584 */, 18 },
+ /* 5416 */ { MAD_F(0x05ce2289) /* 0.362825904 */, 18 },
+ /* 5417 */ { MAD_F(0x05ce8033) /* 0.362915228 */, 18 },
+ /* 5418 */ { MAD_F(0x05ceddde) /* 0.363004559 */, 18 },
+ /* 5419 */ { MAD_F(0x05cf3b8b) /* 0.363093894 */, 18 },
+ /* 5420 */ { MAD_F(0x05cf9939) /* 0.363183236 */, 18 },
+ /* 5421 */ { MAD_F(0x05cff6e9) /* 0.363272582 */, 18 },
+ /* 5422 */ { MAD_F(0x05d0549a) /* 0.363361935 */, 18 },
+ /* 5423 */ { MAD_F(0x05d0b24d) /* 0.363451292 */, 18 },
+
+ /* 5424 */ { MAD_F(0x05d11001) /* 0.363540655 */, 18 },
+ /* 5425 */ { MAD_F(0x05d16db7) /* 0.363630024 */, 18 },
+ /* 5426 */ { MAD_F(0x05d1cb6e) /* 0.363719398 */, 18 },
+ /* 5427 */ { MAD_F(0x05d22927) /* 0.363808778 */, 18 },
+ /* 5428 */ { MAD_F(0x05d286e1) /* 0.363898163 */, 18 },
+ /* 5429 */ { MAD_F(0x05d2e49d) /* 0.363987554 */, 18 },
+ /* 5430 */ { MAD_F(0x05d3425a) /* 0.364076950 */, 18 },
+ /* 5431 */ { MAD_F(0x05d3a018) /* 0.364166352 */, 18 },
+ /* 5432 */ { MAD_F(0x05d3fdd8) /* 0.364255759 */, 18 },
+ /* 5433 */ { MAD_F(0x05d45b9a) /* 0.364345171 */, 18 },
+ /* 5434 */ { MAD_F(0x05d4b95d) /* 0.364434589 */, 18 },
+ /* 5435 */ { MAD_F(0x05d51721) /* 0.364524013 */, 18 },
+ /* 5436 */ { MAD_F(0x05d574e7) /* 0.364613442 */, 18 },
+ /* 5437 */ { MAD_F(0x05d5d2af) /* 0.364702877 */, 18 },
+ /* 5438 */ { MAD_F(0x05d63078) /* 0.364792317 */, 18 },
+ /* 5439 */ { MAD_F(0x05d68e42) /* 0.364881762 */, 18 },
+
+ /* 5440 */ { MAD_F(0x05d6ec0e) /* 0.364971213 */, 18 },
+ /* 5441 */ { MAD_F(0x05d749db) /* 0.365060669 */, 18 },
+ /* 5442 */ { MAD_F(0x05d7a7aa) /* 0.365150131 */, 18 },
+ /* 5443 */ { MAD_F(0x05d8057a) /* 0.365239599 */, 18 },
+ /* 5444 */ { MAD_F(0x05d8634c) /* 0.365329072 */, 18 },
+ /* 5445 */ { MAD_F(0x05d8c11f) /* 0.365418550 */, 18 },
+ /* 5446 */ { MAD_F(0x05d91ef4) /* 0.365508034 */, 18 },
+ /* 5447 */ { MAD_F(0x05d97cca) /* 0.365597523 */, 18 },
+ /* 5448 */ { MAD_F(0x05d9daa1) /* 0.365687018 */, 18 },
+ /* 5449 */ { MAD_F(0x05da387a) /* 0.365776518 */, 18 },
+ /* 5450 */ { MAD_F(0x05da9655) /* 0.365866024 */, 18 },
+ /* 5451 */ { MAD_F(0x05daf431) /* 0.365955536 */, 18 },
+ /* 5452 */ { MAD_F(0x05db520e) /* 0.366045052 */, 18 },
+ /* 5453 */ { MAD_F(0x05dbafed) /* 0.366134574 */, 18 },
+ /* 5454 */ { MAD_F(0x05dc0dce) /* 0.366224102 */, 18 },
+ /* 5455 */ { MAD_F(0x05dc6baf) /* 0.366313635 */, 18 },
+
+ /* 5456 */ { MAD_F(0x05dcc993) /* 0.366403174 */, 18 },
+ /* 5457 */ { MAD_F(0x05dd2778) /* 0.366492718 */, 18 },
+ /* 5458 */ { MAD_F(0x05dd855e) /* 0.366582267 */, 18 },
+ /* 5459 */ { MAD_F(0x05dde346) /* 0.366671822 */, 18 },
+ /* 5460 */ { MAD_F(0x05de412f) /* 0.366761383 */, 18 },
+ /* 5461 */ { MAD_F(0x05de9f1a) /* 0.366850949 */, 18 },
+ /* 5462 */ { MAD_F(0x05defd06) /* 0.366940520 */, 18 },
+ /* 5463 */ { MAD_F(0x05df5af3) /* 0.367030097 */, 18 },
+ /* 5464 */ { MAD_F(0x05dfb8e2) /* 0.367119680 */, 18 },
+ /* 5465 */ { MAD_F(0x05e016d3) /* 0.367209267 */, 18 },
+ /* 5466 */ { MAD_F(0x05e074c5) /* 0.367298861 */, 18 },
+ /* 5467 */ { MAD_F(0x05e0d2b8) /* 0.367388459 */, 18 },
+ /* 5468 */ { MAD_F(0x05e130ad) /* 0.367478064 */, 18 },
+ /* 5469 */ { MAD_F(0x05e18ea4) /* 0.367567673 */, 18 },
+ /* 5470 */ { MAD_F(0x05e1ec9c) /* 0.367657288 */, 18 },
+ /* 5471 */ { MAD_F(0x05e24a95) /* 0.367746909 */, 18 },
+
+ /* 5472 */ { MAD_F(0x05e2a890) /* 0.367836535 */, 18 },
+ /* 5473 */ { MAD_F(0x05e3068c) /* 0.367926167 */, 18 },
+ /* 5474 */ { MAD_F(0x05e3648a) /* 0.368015804 */, 18 },
+ /* 5475 */ { MAD_F(0x05e3c289) /* 0.368105446 */, 18 },
+ /* 5476 */ { MAD_F(0x05e4208a) /* 0.368195094 */, 18 },
+ /* 5477 */ { MAD_F(0x05e47e8c) /* 0.368284747 */, 18 },
+ /* 5478 */ { MAD_F(0x05e4dc8f) /* 0.368374406 */, 18 },
+ /* 5479 */ { MAD_F(0x05e53a94) /* 0.368464070 */, 18 },
+ /* 5480 */ { MAD_F(0x05e5989b) /* 0.368553740 */, 18 },
+ /* 5481 */ { MAD_F(0x05e5f6a3) /* 0.368643415 */, 18 },
+ /* 5482 */ { MAD_F(0x05e654ac) /* 0.368733096 */, 18 },
+ /* 5483 */ { MAD_F(0x05e6b2b7) /* 0.368822782 */, 18 },
+ /* 5484 */ { MAD_F(0x05e710c4) /* 0.368912473 */, 18 },
+ /* 5485 */ { MAD_F(0x05e76ed2) /* 0.369002170 */, 18 },
+ /* 5486 */ { MAD_F(0x05e7cce1) /* 0.369091873 */, 18 },
+ /* 5487 */ { MAD_F(0x05e82af2) /* 0.369181581 */, 18 },
+
+ /* 5488 */ { MAD_F(0x05e88904) /* 0.369271294 */, 18 },
+ /* 5489 */ { MAD_F(0x05e8e718) /* 0.369361013 */, 18 },
+ /* 5490 */ { MAD_F(0x05e9452d) /* 0.369450737 */, 18 },
+ /* 5491 */ { MAD_F(0x05e9a343) /* 0.369540467 */, 18 },
+ /* 5492 */ { MAD_F(0x05ea015c) /* 0.369630202 */, 18 },
+ /* 5493 */ { MAD_F(0x05ea5f75) /* 0.369719942 */, 18 },
+ /* 5494 */ { MAD_F(0x05eabd90) /* 0.369809688 */, 18 },
+ /* 5495 */ { MAD_F(0x05eb1bad) /* 0.369899440 */, 18 },
+ /* 5496 */ { MAD_F(0x05eb79cb) /* 0.369989197 */, 18 },
+ /* 5497 */ { MAD_F(0x05ebd7ea) /* 0.370078959 */, 18 },
+ /* 5498 */ { MAD_F(0x05ec360b) /* 0.370168727 */, 18 },
+ /* 5499 */ { MAD_F(0x05ec942d) /* 0.370258500 */, 18 },
+ /* 5500 */ { MAD_F(0x05ecf251) /* 0.370348279 */, 18 },
+ /* 5501 */ { MAD_F(0x05ed5076) /* 0.370438063 */, 18 },
+ /* 5502 */ { MAD_F(0x05edae9d) /* 0.370527853 */, 18 },
+ /* 5503 */ { MAD_F(0x05ee0cc5) /* 0.370617648 */, 18 },
+
+ /* 5504 */ { MAD_F(0x05ee6aef) /* 0.370707448 */, 18 },
+ /* 5505 */ { MAD_F(0x05eec91a) /* 0.370797254 */, 18 },
+ /* 5506 */ { MAD_F(0x05ef2746) /* 0.370887065 */, 18 },
+ /* 5507 */ { MAD_F(0x05ef8574) /* 0.370976882 */, 18 },
+ /* 5508 */ { MAD_F(0x05efe3a4) /* 0.371066704 */, 18 },
+ /* 5509 */ { MAD_F(0x05f041d5) /* 0.371156532 */, 18 },
+ /* 5510 */ { MAD_F(0x05f0a007) /* 0.371246365 */, 18 },
+ /* 5511 */ { MAD_F(0x05f0fe3b) /* 0.371336203 */, 18 },
+ /* 5512 */ { MAD_F(0x05f15c70) /* 0.371426047 */, 18 },
+ /* 5513 */ { MAD_F(0x05f1baa7) /* 0.371515897 */, 18 },
+ /* 5514 */ { MAD_F(0x05f218df) /* 0.371605751 */, 18 },
+ /* 5515 */ { MAD_F(0x05f27719) /* 0.371695612 */, 18 },
+ /* 5516 */ { MAD_F(0x05f2d554) /* 0.371785477 */, 18 },
+ /* 5517 */ { MAD_F(0x05f33390) /* 0.371875348 */, 18 },
+ /* 5518 */ { MAD_F(0x05f391cf) /* 0.371965225 */, 18 },
+ /* 5519 */ { MAD_F(0x05f3f00e) /* 0.372055107 */, 18 },
+
+ /* 5520 */ { MAD_F(0x05f44e4f) /* 0.372144994 */, 18 },
+ /* 5521 */ { MAD_F(0x05f4ac91) /* 0.372234887 */, 18 },
+ /* 5522 */ { MAD_F(0x05f50ad5) /* 0.372324785 */, 18 },
+ /* 5523 */ { MAD_F(0x05f5691b) /* 0.372414689 */, 18 },
+ /* 5524 */ { MAD_F(0x05f5c761) /* 0.372504598 */, 18 },
+ /* 5525 */ { MAD_F(0x05f625aa) /* 0.372594513 */, 18 },
+ /* 5526 */ { MAD_F(0x05f683f3) /* 0.372684433 */, 18 },
+ /* 5527 */ { MAD_F(0x05f6e23f) /* 0.372774358 */, 18 },
+ /* 5528 */ { MAD_F(0x05f7408b) /* 0.372864289 */, 18 },
+ /* 5529 */ { MAD_F(0x05f79ed9) /* 0.372954225 */, 18 },
+ /* 5530 */ { MAD_F(0x05f7fd29) /* 0.373044167 */, 18 },
+ /* 5531 */ { MAD_F(0x05f85b7a) /* 0.373134114 */, 18 },
+ /* 5532 */ { MAD_F(0x05f8b9cc) /* 0.373224066 */, 18 },
+ /* 5533 */ { MAD_F(0x05f91820) /* 0.373314024 */, 18 },
+ /* 5534 */ { MAD_F(0x05f97675) /* 0.373403987 */, 18 },
+ /* 5535 */ { MAD_F(0x05f9d4cc) /* 0.373493956 */, 18 },
+
+ /* 5536 */ { MAD_F(0x05fa3324) /* 0.373583930 */, 18 },
+ /* 5537 */ { MAD_F(0x05fa917e) /* 0.373673910 */, 18 },
+ /* 5538 */ { MAD_F(0x05faefd9) /* 0.373763895 */, 18 },
+ /* 5539 */ { MAD_F(0x05fb4e36) /* 0.373853885 */, 18 },
+ /* 5540 */ { MAD_F(0x05fbac94) /* 0.373943881 */, 18 },
+ /* 5541 */ { MAD_F(0x05fc0af3) /* 0.374033882 */, 18 },
+ /* 5542 */ { MAD_F(0x05fc6954) /* 0.374123889 */, 18 },
+ /* 5543 */ { MAD_F(0x05fcc7b7) /* 0.374213901 */, 18 },
+ /* 5544 */ { MAD_F(0x05fd261b) /* 0.374303918 */, 18 },
+ /* 5545 */ { MAD_F(0x05fd8480) /* 0.374393941 */, 18 },
+ /* 5546 */ { MAD_F(0x05fde2e7) /* 0.374483970 */, 18 },
+ /* 5547 */ { MAD_F(0x05fe414f) /* 0.374574003 */, 18 },
+ /* 5548 */ { MAD_F(0x05fe9fb9) /* 0.374664042 */, 18 },
+ /* 5549 */ { MAD_F(0x05fefe24) /* 0.374754087 */, 18 },
+ /* 5550 */ { MAD_F(0x05ff5c91) /* 0.374844137 */, 18 },
+ /* 5551 */ { MAD_F(0x05ffbaff) /* 0.374934192 */, 18 },
+
+ /* 5552 */ { MAD_F(0x0600196e) /* 0.375024253 */, 18 },
+ /* 5553 */ { MAD_F(0x060077df) /* 0.375114319 */, 18 },
+ /* 5554 */ { MAD_F(0x0600d651) /* 0.375204391 */, 18 },
+ /* 5555 */ { MAD_F(0x060134c5) /* 0.375294468 */, 18 },
+ /* 5556 */ { MAD_F(0x0601933b) /* 0.375384550 */, 18 },
+ /* 5557 */ { MAD_F(0x0601f1b1) /* 0.375474638 */, 18 },
+ /* 5558 */ { MAD_F(0x0602502a) /* 0.375564731 */, 18 },
+ /* 5559 */ { MAD_F(0x0602aea3) /* 0.375654830 */, 18 },
+ /* 5560 */ { MAD_F(0x06030d1e) /* 0.375744934 */, 18 },
+ /* 5561 */ { MAD_F(0x06036b9b) /* 0.375835043 */, 18 },
+ /* 5562 */ { MAD_F(0x0603ca19) /* 0.375925158 */, 18 },
+ /* 5563 */ { MAD_F(0x06042898) /* 0.376015278 */, 18 },
+ /* 5564 */ { MAD_F(0x06048719) /* 0.376105404 */, 18 },
+ /* 5565 */ { MAD_F(0x0604e59c) /* 0.376195535 */, 18 },
+ /* 5566 */ { MAD_F(0x0605441f) /* 0.376285671 */, 18 },
+ /* 5567 */ { MAD_F(0x0605a2a5) /* 0.376375813 */, 18 },
+
+ /* 5568 */ { MAD_F(0x0606012b) /* 0.376465960 */, 18 },
+ /* 5569 */ { MAD_F(0x06065fb4) /* 0.376556113 */, 18 },
+ /* 5570 */ { MAD_F(0x0606be3d) /* 0.376646271 */, 18 },
+ /* 5571 */ { MAD_F(0x06071cc8) /* 0.376736434 */, 18 },
+ /* 5572 */ { MAD_F(0x06077b55) /* 0.376826603 */, 18 },
+ /* 5573 */ { MAD_F(0x0607d9e3) /* 0.376916777 */, 18 },
+ /* 5574 */ { MAD_F(0x06083872) /* 0.377006957 */, 18 },
+ /* 5575 */ { MAD_F(0x06089703) /* 0.377097141 */, 18 },
+ /* 5576 */ { MAD_F(0x0608f595) /* 0.377187332 */, 18 },
+ /* 5577 */ { MAD_F(0x06095429) /* 0.377277528 */, 18 },
+ /* 5578 */ { MAD_F(0x0609b2be) /* 0.377367729 */, 18 },
+ /* 5579 */ { MAD_F(0x060a1155) /* 0.377457935 */, 18 },
+ /* 5580 */ { MAD_F(0x060a6fed) /* 0.377548147 */, 18 },
+ /* 5581 */ { MAD_F(0x060ace86) /* 0.377638364 */, 18 },
+ /* 5582 */ { MAD_F(0x060b2d21) /* 0.377728587 */, 18 },
+ /* 5583 */ { MAD_F(0x060b8bbe) /* 0.377818815 */, 18 },
+
+ /* 5584 */ { MAD_F(0x060bea5c) /* 0.377909049 */, 18 },
+ /* 5585 */ { MAD_F(0x060c48fb) /* 0.377999288 */, 18 },
+ /* 5586 */ { MAD_F(0x060ca79c) /* 0.378089532 */, 18 },
+ /* 5587 */ { MAD_F(0x060d063e) /* 0.378179781 */, 18 },
+ /* 5588 */ { MAD_F(0x060d64e1) /* 0.378270036 */, 18 },
+ /* 5589 */ { MAD_F(0x060dc387) /* 0.378360297 */, 18 },
+ /* 5590 */ { MAD_F(0x060e222d) /* 0.378450563 */, 18 },
+ /* 5591 */ { MAD_F(0x060e80d5) /* 0.378540834 */, 18 },
+ /* 5592 */ { MAD_F(0x060edf7f) /* 0.378631110 */, 18 },
+ /* 5593 */ { MAD_F(0x060f3e29) /* 0.378721392 */, 18 },
+ /* 5594 */ { MAD_F(0x060f9cd6) /* 0.378811680 */, 18 },
+ /* 5595 */ { MAD_F(0x060ffb83) /* 0.378901972 */, 18 },
+ /* 5596 */ { MAD_F(0x06105a33) /* 0.378992270 */, 18 },
+ /* 5597 */ { MAD_F(0x0610b8e3) /* 0.379082574 */, 18 },
+ /* 5598 */ { MAD_F(0x06111795) /* 0.379172883 */, 18 },
+ /* 5599 */ { MAD_F(0x06117649) /* 0.379263197 */, 18 },
+
+ /* 5600 */ { MAD_F(0x0611d4fe) /* 0.379353516 */, 18 },
+ /* 5601 */ { MAD_F(0x061233b4) /* 0.379443841 */, 18 },
+ /* 5602 */ { MAD_F(0x0612926c) /* 0.379534172 */, 18 },
+ /* 5603 */ { MAD_F(0x0612f125) /* 0.379624507 */, 18 },
+ /* 5604 */ { MAD_F(0x06134fe0) /* 0.379714848 */, 18 },
+ /* 5605 */ { MAD_F(0x0613ae9c) /* 0.379805195 */, 18 },
+ /* 5606 */ { MAD_F(0x06140d5a) /* 0.379895547 */, 18 },
+ /* 5607 */ { MAD_F(0x06146c19) /* 0.379985904 */, 18 },
+ /* 5608 */ { MAD_F(0x0614cada) /* 0.380076266 */, 18 },
+ /* 5609 */ { MAD_F(0x0615299c) /* 0.380166634 */, 18 },
+ /* 5610 */ { MAD_F(0x0615885f) /* 0.380257008 */, 18 },
+ /* 5611 */ { MAD_F(0x0615e724) /* 0.380347386 */, 18 },
+ /* 5612 */ { MAD_F(0x061645ea) /* 0.380437770 */, 18 },
+ /* 5613 */ { MAD_F(0x0616a4b2) /* 0.380528160 */, 18 },
+ /* 5614 */ { MAD_F(0x0617037b) /* 0.380618555 */, 18 },
+ /* 5615 */ { MAD_F(0x06176246) /* 0.380708955 */, 18 },
+
+ /* 5616 */ { MAD_F(0x0617c112) /* 0.380799360 */, 18 },
+ /* 5617 */ { MAD_F(0x06181fdf) /* 0.380889771 */, 18 },
+ /* 5618 */ { MAD_F(0x06187eae) /* 0.380980187 */, 18 },
+ /* 5619 */ { MAD_F(0x0618dd7e) /* 0.381070609 */, 18 },
+ /* 5620 */ { MAD_F(0x06193c50) /* 0.381161036 */, 18 },
+ /* 5621 */ { MAD_F(0x06199b24) /* 0.381251468 */, 18 },
+ /* 5622 */ { MAD_F(0x0619f9f8) /* 0.381341906 */, 18 },
+ /* 5623 */ { MAD_F(0x061a58ce) /* 0.381432349 */, 18 },
+ /* 5624 */ { MAD_F(0x061ab7a6) /* 0.381522798 */, 18 },
+ /* 5625 */ { MAD_F(0x061b167f) /* 0.381613251 */, 18 },
+ /* 5626 */ { MAD_F(0x061b7559) /* 0.381703711 */, 18 },
+ /* 5627 */ { MAD_F(0x061bd435) /* 0.381794175 */, 18 },
+ /* 5628 */ { MAD_F(0x061c3313) /* 0.381884645 */, 18 },
+ /* 5629 */ { MAD_F(0x061c91f1) /* 0.381975120 */, 18 },
+ /* 5630 */ { MAD_F(0x061cf0d2) /* 0.382065601 */, 18 },
+ /* 5631 */ { MAD_F(0x061d4fb3) /* 0.382156087 */, 18 },
+
+ /* 5632 */ { MAD_F(0x061dae96) /* 0.382246578 */, 18 },
+ /* 5633 */ { MAD_F(0x061e0d7b) /* 0.382337075 */, 18 },
+ /* 5634 */ { MAD_F(0x061e6c61) /* 0.382427577 */, 18 },
+ /* 5635 */ { MAD_F(0x061ecb48) /* 0.382518084 */, 18 },
+ /* 5636 */ { MAD_F(0x061f2a31) /* 0.382608597 */, 18 },
+ /* 5637 */ { MAD_F(0x061f891b) /* 0.382699115 */, 18 },
+ /* 5638 */ { MAD_F(0x061fe807) /* 0.382789638 */, 18 },
+ /* 5639 */ { MAD_F(0x062046f4) /* 0.382880167 */, 18 },
+ /* 5640 */ { MAD_F(0x0620a5e3) /* 0.382970701 */, 18 },
+ /* 5641 */ { MAD_F(0x062104d3) /* 0.383061241 */, 18 },
+ /* 5642 */ { MAD_F(0x062163c4) /* 0.383151786 */, 18 },
+ /* 5643 */ { MAD_F(0x0621c2b7) /* 0.383242336 */, 18 },
+ /* 5644 */ { MAD_F(0x062221ab) /* 0.383332891 */, 18 },
+ /* 5645 */ { MAD_F(0x062280a1) /* 0.383423452 */, 18 },
+ /* 5646 */ { MAD_F(0x0622df98) /* 0.383514018 */, 18 },
+ /* 5647 */ { MAD_F(0x06233e91) /* 0.383604590 */, 18 },
+
+ /* 5648 */ { MAD_F(0x06239d8b) /* 0.383695167 */, 18 },
+ /* 5649 */ { MAD_F(0x0623fc86) /* 0.383785749 */, 18 },
+ /* 5650 */ { MAD_F(0x06245b83) /* 0.383876337 */, 18 },
+ /* 5651 */ { MAD_F(0x0624ba82) /* 0.383966930 */, 18 },
+ /* 5652 */ { MAD_F(0x06251981) /* 0.384057528 */, 18 },
+ /* 5653 */ { MAD_F(0x06257883) /* 0.384148132 */, 18 },
+ /* 5654 */ { MAD_F(0x0625d785) /* 0.384238741 */, 18 },
+ /* 5655 */ { MAD_F(0x06263689) /* 0.384329355 */, 18 },
+ /* 5656 */ { MAD_F(0x0626958f) /* 0.384419975 */, 18 },
+ /* 5657 */ { MAD_F(0x0626f496) /* 0.384510600 */, 18 },
+ /* 5658 */ { MAD_F(0x0627539e) /* 0.384601230 */, 18 },
+ /* 5659 */ { MAD_F(0x0627b2a8) /* 0.384691866 */, 18 },
+ /* 5660 */ { MAD_F(0x062811b3) /* 0.384782507 */, 18 },
+ /* 5661 */ { MAD_F(0x062870c0) /* 0.384873153 */, 18 },
+ /* 5662 */ { MAD_F(0x0628cfce) /* 0.384963805 */, 18 },
+ /* 5663 */ { MAD_F(0x06292ede) /* 0.385054462 */, 18 },
+
+ /* 5664 */ { MAD_F(0x06298def) /* 0.385145124 */, 18 },
+ /* 5665 */ { MAD_F(0x0629ed01) /* 0.385235792 */, 18 },
+ /* 5666 */ { MAD_F(0x062a4c15) /* 0.385326465 */, 18 },
+ /* 5667 */ { MAD_F(0x062aab2a) /* 0.385417143 */, 18 },
+ /* 5668 */ { MAD_F(0x062b0a41) /* 0.385507827 */, 18 },
+ /* 5669 */ { MAD_F(0x062b6959) /* 0.385598516 */, 18 },
+ /* 5670 */ { MAD_F(0x062bc873) /* 0.385689211 */, 18 },
+ /* 5671 */ { MAD_F(0x062c278e) /* 0.385779910 */, 18 },
+ /* 5672 */ { MAD_F(0x062c86aa) /* 0.385870615 */, 18 },
+ /* 5673 */ { MAD_F(0x062ce5c8) /* 0.385961326 */, 18 },
+ /* 5674 */ { MAD_F(0x062d44e8) /* 0.386052041 */, 18 },
+ /* 5675 */ { MAD_F(0x062da408) /* 0.386142762 */, 18 },
+ /* 5676 */ { MAD_F(0x062e032a) /* 0.386233489 */, 18 },
+ /* 5677 */ { MAD_F(0x062e624e) /* 0.386324221 */, 18 },
+ /* 5678 */ { MAD_F(0x062ec173) /* 0.386414958 */, 18 },
+ /* 5679 */ { MAD_F(0x062f209a) /* 0.386505700 */, 18 },
+
+ /* 5680 */ { MAD_F(0x062f7fc1) /* 0.386596448 */, 18 },
+ /* 5681 */ { MAD_F(0x062fdeeb) /* 0.386687201 */, 18 },
+ /* 5682 */ { MAD_F(0x06303e16) /* 0.386777959 */, 18 },
+ /* 5683 */ { MAD_F(0x06309d42) /* 0.386868723 */, 18 },
+ /* 5684 */ { MAD_F(0x0630fc6f) /* 0.386959492 */, 18 },
+ /* 5685 */ { MAD_F(0x06315b9e) /* 0.387050266 */, 18 },
+ /* 5686 */ { MAD_F(0x0631bacf) /* 0.387141045 */, 18 },
+ /* 5687 */ { MAD_F(0x06321a01) /* 0.387231830 */, 18 },
+ /* 5688 */ { MAD_F(0x06327934) /* 0.387322621 */, 18 },
+ /* 5689 */ { MAD_F(0x0632d869) /* 0.387413416 */, 18 },
+ /* 5690 */ { MAD_F(0x0633379f) /* 0.387504217 */, 18 },
+ /* 5691 */ { MAD_F(0x063396d7) /* 0.387595023 */, 18 },
+ /* 5692 */ { MAD_F(0x0633f610) /* 0.387685835 */, 18 },
+ /* 5693 */ { MAD_F(0x0634554a) /* 0.387776652 */, 18 },
+ /* 5694 */ { MAD_F(0x0634b486) /* 0.387867474 */, 18 },
+ /* 5695 */ { MAD_F(0x063513c3) /* 0.387958301 */, 18 },
+
+ /* 5696 */ { MAD_F(0x06357302) /* 0.388049134 */, 18 },
+ /* 5697 */ { MAD_F(0x0635d242) /* 0.388139972 */, 18 },
+ /* 5698 */ { MAD_F(0x06363184) /* 0.388230816 */, 18 },
+ /* 5699 */ { MAD_F(0x063690c7) /* 0.388321665 */, 18 },
+ /* 5700 */ { MAD_F(0x0636f00b) /* 0.388412519 */, 18 },
+ /* 5701 */ { MAD_F(0x06374f51) /* 0.388503378 */, 18 },
+ /* 5702 */ { MAD_F(0x0637ae99) /* 0.388594243 */, 18 },
+ /* 5703 */ { MAD_F(0x06380de1) /* 0.388685113 */, 18 },
+ /* 5704 */ { MAD_F(0x06386d2b) /* 0.388775988 */, 18 },
+ /* 5705 */ { MAD_F(0x0638cc77) /* 0.388866869 */, 18 },
+ /* 5706 */ { MAD_F(0x06392bc4) /* 0.388957755 */, 18 },
+ /* 5707 */ { MAD_F(0x06398b12) /* 0.389048646 */, 18 },
+ /* 5708 */ { MAD_F(0x0639ea62) /* 0.389139542 */, 18 },
+ /* 5709 */ { MAD_F(0x063a49b4) /* 0.389230444 */, 18 },
+ /* 5710 */ { MAD_F(0x063aa906) /* 0.389321352 */, 18 },
+ /* 5711 */ { MAD_F(0x063b085a) /* 0.389412264 */, 18 },
+
+ /* 5712 */ { MAD_F(0x063b67b0) /* 0.389503182 */, 18 },
+ /* 5713 */ { MAD_F(0x063bc707) /* 0.389594105 */, 18 },
+ /* 5714 */ { MAD_F(0x063c265f) /* 0.389685033 */, 18 },
+ /* 5715 */ { MAD_F(0x063c85b9) /* 0.389775967 */, 18 },
+ /* 5716 */ { MAD_F(0x063ce514) /* 0.389866906 */, 18 },
+ /* 5717 */ { MAD_F(0x063d4471) /* 0.389957850 */, 18 },
+ /* 5718 */ { MAD_F(0x063da3cf) /* 0.390048800 */, 18 },
+ /* 5719 */ { MAD_F(0x063e032f) /* 0.390139755 */, 18 },
+ /* 5720 */ { MAD_F(0x063e6290) /* 0.390230715 */, 18 },
+ /* 5721 */ { MAD_F(0x063ec1f2) /* 0.390321681 */, 18 },
+ /* 5722 */ { MAD_F(0x063f2156) /* 0.390412651 */, 18 },
+ /* 5723 */ { MAD_F(0x063f80bb) /* 0.390503628 */, 18 },
+ /* 5724 */ { MAD_F(0x063fe022) /* 0.390594609 */, 18 },
+ /* 5725 */ { MAD_F(0x06403f8a) /* 0.390685596 */, 18 },
+ /* 5726 */ { MAD_F(0x06409ef3) /* 0.390776588 */, 18 },
+ /* 5727 */ { MAD_F(0x0640fe5e) /* 0.390867585 */, 18 },
+
+ /* 5728 */ { MAD_F(0x06415dcb) /* 0.390958588 */, 18 },
+ /* 5729 */ { MAD_F(0x0641bd38) /* 0.391049596 */, 18 },
+ /* 5730 */ { MAD_F(0x06421ca7) /* 0.391140609 */, 18 },
+ /* 5731 */ { MAD_F(0x06427c18) /* 0.391231627 */, 18 },
+ /* 5732 */ { MAD_F(0x0642db8a) /* 0.391322651 */, 18 },
+ /* 5733 */ { MAD_F(0x06433afd) /* 0.391413680 */, 18 },
+ /* 5734 */ { MAD_F(0x06439a72) /* 0.391504714 */, 18 },
+ /* 5735 */ { MAD_F(0x0643f9e9) /* 0.391595754 */, 18 },
+ /* 5736 */ { MAD_F(0x06445960) /* 0.391686799 */, 18 },
+ /* 5737 */ { MAD_F(0x0644b8d9) /* 0.391777849 */, 18 },
+ /* 5738 */ { MAD_F(0x06451854) /* 0.391868905 */, 18 },
+ /* 5739 */ { MAD_F(0x064577d0) /* 0.391959966 */, 18 },
+ /* 5740 */ { MAD_F(0x0645d74d) /* 0.392051032 */, 18 },
+ /* 5741 */ { MAD_F(0x064636cc) /* 0.392142103 */, 18 },
+ /* 5742 */ { MAD_F(0x0646964c) /* 0.392233180 */, 18 },
+ /* 5743 */ { MAD_F(0x0646f5ce) /* 0.392324262 */, 18 },
+
+ /* 5744 */ { MAD_F(0x06475551) /* 0.392415349 */, 18 },
+ /* 5745 */ { MAD_F(0x0647b4d5) /* 0.392506442 */, 18 },
+ /* 5746 */ { MAD_F(0x0648145b) /* 0.392597540 */, 18 },
+ /* 5747 */ { MAD_F(0x064873e3) /* 0.392688643 */, 18 },
+ /* 5748 */ { MAD_F(0x0648d36b) /* 0.392779751 */, 18 },
+ /* 5749 */ { MAD_F(0x064932f6) /* 0.392870865 */, 18 },
+ /* 5750 */ { MAD_F(0x06499281) /* 0.392961984 */, 18 },
+ /* 5751 */ { MAD_F(0x0649f20e) /* 0.393053108 */, 18 },
+ /* 5752 */ { MAD_F(0x064a519c) /* 0.393144238 */, 18 },
+ /* 5753 */ { MAD_F(0x064ab12c) /* 0.393235372 */, 18 },
+ /* 5754 */ { MAD_F(0x064b10be) /* 0.393326513 */, 18 },
+ /* 5755 */ { MAD_F(0x064b7050) /* 0.393417658 */, 18 },
+ /* 5756 */ { MAD_F(0x064bcfe4) /* 0.393508809 */, 18 },
+ /* 5757 */ { MAD_F(0x064c2f7a) /* 0.393599965 */, 18 },
+ /* 5758 */ { MAD_F(0x064c8f11) /* 0.393691126 */, 18 },
+ /* 5759 */ { MAD_F(0x064ceea9) /* 0.393782292 */, 18 },
+
+ /* 5760 */ { MAD_F(0x064d4e43) /* 0.393873464 */, 18 },
+ /* 5761 */ { MAD_F(0x064dadde) /* 0.393964641 */, 18 },
+ /* 5762 */ { MAD_F(0x064e0d7a) /* 0.394055823 */, 18 },
+ /* 5763 */ { MAD_F(0x064e6d18) /* 0.394147011 */, 18 },
+ /* 5764 */ { MAD_F(0x064eccb8) /* 0.394238204 */, 18 },
+ /* 5765 */ { MAD_F(0x064f2c59) /* 0.394329402 */, 18 },
+ /* 5766 */ { MAD_F(0x064f8bfb) /* 0.394420605 */, 18 },
+ /* 5767 */ { MAD_F(0x064feb9e) /* 0.394511814 */, 18 },
+ /* 5768 */ { MAD_F(0x06504b44) /* 0.394603028 */, 18 },
+ /* 5769 */ { MAD_F(0x0650aaea) /* 0.394694247 */, 18 },
+ /* 5770 */ { MAD_F(0x06510a92) /* 0.394785472 */, 18 },
+ /* 5771 */ { MAD_F(0x06516a3b) /* 0.394876702 */, 18 },
+ /* 5772 */ { MAD_F(0x0651c9e6) /* 0.394967937 */, 18 },
+ /* 5773 */ { MAD_F(0x06522992) /* 0.395059177 */, 18 },
+ /* 5774 */ { MAD_F(0x06528940) /* 0.395150423 */, 18 },
+ /* 5775 */ { MAD_F(0x0652e8ef) /* 0.395241673 */, 18 },
+
+ /* 5776 */ { MAD_F(0x0653489f) /* 0.395332930 */, 18 },
+ /* 5777 */ { MAD_F(0x0653a851) /* 0.395424191 */, 18 },
+ /* 5778 */ { MAD_F(0x06540804) /* 0.395515458 */, 18 },
+ /* 5779 */ { MAD_F(0x065467b9) /* 0.395606730 */, 18 },
+ /* 5780 */ { MAD_F(0x0654c76f) /* 0.395698007 */, 18 },
+ /* 5781 */ { MAD_F(0x06552726) /* 0.395789289 */, 18 },
+ /* 5782 */ { MAD_F(0x065586df) /* 0.395880577 */, 18 },
+ /* 5783 */ { MAD_F(0x0655e699) /* 0.395971870 */, 18 },
+ /* 5784 */ { MAD_F(0x06564655) /* 0.396063168 */, 18 },
+ /* 5785 */ { MAD_F(0x0656a612) /* 0.396154472 */, 18 },
+ /* 5786 */ { MAD_F(0x065705d0) /* 0.396245780 */, 18 },
+ /* 5787 */ { MAD_F(0x06576590) /* 0.396337094 */, 18 },
+ /* 5788 */ { MAD_F(0x0657c552) /* 0.396428414 */, 18 },
+ /* 5789 */ { MAD_F(0x06582514) /* 0.396519738 */, 18 },
+ /* 5790 */ { MAD_F(0x065884d9) /* 0.396611068 */, 18 },
+ /* 5791 */ { MAD_F(0x0658e49e) /* 0.396702403 */, 18 },
+
+ /* 5792 */ { MAD_F(0x06594465) /* 0.396793743 */, 18 },
+ /* 5793 */ { MAD_F(0x0659a42e) /* 0.396885089 */, 18 },
+ /* 5794 */ { MAD_F(0x065a03f7) /* 0.396976440 */, 18 },
+ /* 5795 */ { MAD_F(0x065a63c3) /* 0.397067796 */, 18 },
+ /* 5796 */ { MAD_F(0x065ac38f) /* 0.397159157 */, 18 },
+ /* 5797 */ { MAD_F(0x065b235d) /* 0.397250524 */, 18 },
+ /* 5798 */ { MAD_F(0x065b832d) /* 0.397341896 */, 18 },
+ /* 5799 */ { MAD_F(0x065be2fe) /* 0.397433273 */, 18 },
+ /* 5800 */ { MAD_F(0x065c42d0) /* 0.397524655 */, 18 },
+ /* 5801 */ { MAD_F(0x065ca2a3) /* 0.397616043 */, 18 },
+ /* 5802 */ { MAD_F(0x065d0279) /* 0.397707436 */, 18 },
+ /* 5803 */ { MAD_F(0x065d624f) /* 0.397798834 */, 18 },
+ /* 5804 */ { MAD_F(0x065dc227) /* 0.397890237 */, 18 },
+ /* 5805 */ { MAD_F(0x065e2200) /* 0.397981646 */, 18 },
+ /* 5806 */ { MAD_F(0x065e81db) /* 0.398073059 */, 18 },
+ /* 5807 */ { MAD_F(0x065ee1b7) /* 0.398164479 */, 18 },
+
+ /* 5808 */ { MAD_F(0x065f4195) /* 0.398255903 */, 18 },
+ /* 5809 */ { MAD_F(0x065fa174) /* 0.398347333 */, 18 },
+ /* 5810 */ { MAD_F(0x06600154) /* 0.398438767 */, 18 },
+ /* 5811 */ { MAD_F(0x06606136) /* 0.398530207 */, 18 },
+ /* 5812 */ { MAD_F(0x0660c119) /* 0.398621653 */, 18 },
+ /* 5813 */ { MAD_F(0x066120fd) /* 0.398713103 */, 18 },
+ /* 5814 */ { MAD_F(0x066180e3) /* 0.398804559 */, 18 },
+ /* 5815 */ { MAD_F(0x0661e0cb) /* 0.398896020 */, 18 },
+ /* 5816 */ { MAD_F(0x066240b4) /* 0.398987487 */, 18 },
+ /* 5817 */ { MAD_F(0x0662a09e) /* 0.399078958 */, 18 },
+ /* 5818 */ { MAD_F(0x06630089) /* 0.399170435 */, 18 },
+ /* 5819 */ { MAD_F(0x06636077) /* 0.399261917 */, 18 },
+ /* 5820 */ { MAD_F(0x0663c065) /* 0.399353404 */, 18 },
+ /* 5821 */ { MAD_F(0x06642055) /* 0.399444897 */, 18 },
+ /* 5822 */ { MAD_F(0x06648046) /* 0.399536395 */, 18 },
+ /* 5823 */ { MAD_F(0x0664e039) /* 0.399627898 */, 18 },
+
+ /* 5824 */ { MAD_F(0x0665402d) /* 0.399719406 */, 18 },
+ /* 5825 */ { MAD_F(0x0665a022) /* 0.399810919 */, 18 },
+ /* 5826 */ { MAD_F(0x06660019) /* 0.399902438 */, 18 },
+ /* 5827 */ { MAD_F(0x06666011) /* 0.399993962 */, 18 },
+ /* 5828 */ { MAD_F(0x0666c00b) /* 0.400085491 */, 18 },
+ /* 5829 */ { MAD_F(0x06672006) /* 0.400177026 */, 18 },
+ /* 5830 */ { MAD_F(0x06678003) /* 0.400268565 */, 18 },
+ /* 5831 */ { MAD_F(0x0667e000) /* 0.400360110 */, 18 },
+ /* 5832 */ { MAD_F(0x06684000) /* 0.400451660 */, 18 },
+ /* 5833 */ { MAD_F(0x0668a000) /* 0.400543216 */, 18 },
+ /* 5834 */ { MAD_F(0x06690003) /* 0.400634776 */, 18 },
+ /* 5835 */ { MAD_F(0x06696006) /* 0.400726342 */, 18 },
+ /* 5836 */ { MAD_F(0x0669c00b) /* 0.400817913 */, 18 },
+ /* 5837 */ { MAD_F(0x066a2011) /* 0.400909489 */, 18 },
+ /* 5838 */ { MAD_F(0x066a8019) /* 0.401001071 */, 18 },
+ /* 5839 */ { MAD_F(0x066ae022) /* 0.401092657 */, 18 },
+
+ /* 5840 */ { MAD_F(0x066b402d) /* 0.401184249 */, 18 },
+ /* 5841 */ { MAD_F(0x066ba039) /* 0.401275847 */, 18 },
+ /* 5842 */ { MAD_F(0x066c0046) /* 0.401367449 */, 18 },
+ /* 5843 */ { MAD_F(0x066c6055) /* 0.401459057 */, 18 },
+ /* 5844 */ { MAD_F(0x066cc065) /* 0.401550670 */, 18 },
+ /* 5845 */ { MAD_F(0x066d2076) /* 0.401642288 */, 18 },
+ /* 5846 */ { MAD_F(0x066d8089) /* 0.401733911 */, 18 },
+ /* 5847 */ { MAD_F(0x066de09e) /* 0.401825540 */, 18 },
+ /* 5848 */ { MAD_F(0x066e40b3) /* 0.401917173 */, 18 },
+ /* 5849 */ { MAD_F(0x066ea0cb) /* 0.402008812 */, 18 },
+ /* 5850 */ { MAD_F(0x066f00e3) /* 0.402100457 */, 18 },
+ /* 5851 */ { MAD_F(0x066f60fd) /* 0.402192106 */, 18 },
+ /* 5852 */ { MAD_F(0x066fc118) /* 0.402283761 */, 18 },
+ /* 5853 */ { MAD_F(0x06702135) /* 0.402375420 */, 18 },
+ /* 5854 */ { MAD_F(0x06708153) /* 0.402467086 */, 18 },
+ /* 5855 */ { MAD_F(0x0670e173) /* 0.402558756 */, 18 },
+
+ /* 5856 */ { MAD_F(0x06714194) /* 0.402650431 */, 18 },
+ /* 5857 */ { MAD_F(0x0671a1b6) /* 0.402742112 */, 18 },
+ /* 5858 */ { MAD_F(0x067201da) /* 0.402833798 */, 18 },
+ /* 5859 */ { MAD_F(0x067261ff) /* 0.402925489 */, 18 },
+ /* 5860 */ { MAD_F(0x0672c226) /* 0.403017186 */, 18 },
+ /* 5861 */ { MAD_F(0x0673224e) /* 0.403108887 */, 18 },
+ /* 5862 */ { MAD_F(0x06738277) /* 0.403200594 */, 18 },
+ /* 5863 */ { MAD_F(0x0673e2a2) /* 0.403292306 */, 18 },
+ /* 5864 */ { MAD_F(0x067442ce) /* 0.403384024 */, 18 },
+ /* 5865 */ { MAD_F(0x0674a2fc) /* 0.403475746 */, 18 },
+ /* 5866 */ { MAD_F(0x0675032b) /* 0.403567474 */, 18 },
+ /* 5867 */ { MAD_F(0x0675635b) /* 0.403659207 */, 18 },
+ /* 5868 */ { MAD_F(0x0675c38d) /* 0.403750945 */, 18 },
+ /* 5869 */ { MAD_F(0x067623c0) /* 0.403842688 */, 18 },
+ /* 5870 */ { MAD_F(0x067683f4) /* 0.403934437 */, 18 },
+ /* 5871 */ { MAD_F(0x0676e42a) /* 0.404026190 */, 18 },
+
+ /* 5872 */ { MAD_F(0x06774462) /* 0.404117949 */, 18 },
+ /* 5873 */ { MAD_F(0x0677a49b) /* 0.404209714 */, 18 },
+ /* 5874 */ { MAD_F(0x067804d5) /* 0.404301483 */, 18 },
+ /* 5875 */ { MAD_F(0x06786510) /* 0.404393258 */, 18 },
+ /* 5876 */ { MAD_F(0x0678c54d) /* 0.404485037 */, 18 },
+ /* 5877 */ { MAD_F(0x0679258c) /* 0.404576822 */, 18 },
+ /* 5878 */ { MAD_F(0x067985cb) /* 0.404668613 */, 18 },
+ /* 5879 */ { MAD_F(0x0679e60c) /* 0.404760408 */, 18 },
+ /* 5880 */ { MAD_F(0x067a464f) /* 0.404852209 */, 18 },
+ /* 5881 */ { MAD_F(0x067aa693) /* 0.404944014 */, 18 },
+ /* 5882 */ { MAD_F(0x067b06d8) /* 0.405035825 */, 18 },
+ /* 5883 */ { MAD_F(0x067b671f) /* 0.405127642 */, 18 },
+ /* 5884 */ { MAD_F(0x067bc767) /* 0.405219463 */, 18 },
+ /* 5885 */ { MAD_F(0x067c27b1) /* 0.405311290 */, 18 },
+ /* 5886 */ { MAD_F(0x067c87fc) /* 0.405403122 */, 18 },
+ /* 5887 */ { MAD_F(0x067ce848) /* 0.405494959 */, 18 },
+
+ /* 5888 */ { MAD_F(0x067d4896) /* 0.405586801 */, 18 },
+ /* 5889 */ { MAD_F(0x067da8e5) /* 0.405678648 */, 18 },
+ /* 5890 */ { MAD_F(0x067e0935) /* 0.405770501 */, 18 },
+ /* 5891 */ { MAD_F(0x067e6987) /* 0.405862359 */, 18 },
+ /* 5892 */ { MAD_F(0x067ec9da) /* 0.405954222 */, 18 },
+ /* 5893 */ { MAD_F(0x067f2a2f) /* 0.406046090 */, 18 },
+ /* 5894 */ { MAD_F(0x067f8a85) /* 0.406137963 */, 18 },
+ /* 5895 */ { MAD_F(0x067feadd) /* 0.406229842 */, 18 },
+ /* 5896 */ { MAD_F(0x06804b36) /* 0.406321726 */, 18 },
+ /* 5897 */ { MAD_F(0x0680ab90) /* 0.406413615 */, 18 },
+ /* 5898 */ { MAD_F(0x06810beb) /* 0.406505509 */, 18 },
+ /* 5899 */ { MAD_F(0x06816c49) /* 0.406597408 */, 18 },
+ /* 5900 */ { MAD_F(0x0681cca7) /* 0.406689313 */, 18 },
+ /* 5901 */ { MAD_F(0x06822d07) /* 0.406781223 */, 18 },
+ /* 5902 */ { MAD_F(0x06828d68) /* 0.406873138 */, 18 },
+ /* 5903 */ { MAD_F(0x0682edcb) /* 0.406965058 */, 18 },
+
+ /* 5904 */ { MAD_F(0x06834e2f) /* 0.407056983 */, 18 },
+ /* 5905 */ { MAD_F(0x0683ae94) /* 0.407148914 */, 18 },
+ /* 5906 */ { MAD_F(0x06840efb) /* 0.407240850 */, 18 },
+ /* 5907 */ { MAD_F(0x06846f63) /* 0.407332791 */, 18 },
+ /* 5908 */ { MAD_F(0x0684cfcd) /* 0.407424737 */, 18 },
+ /* 5909 */ { MAD_F(0x06853038) /* 0.407516688 */, 18 },
+ /* 5910 */ { MAD_F(0x068590a4) /* 0.407608645 */, 18 },
+ /* 5911 */ { MAD_F(0x0685f112) /* 0.407700606 */, 18 },
+ /* 5912 */ { MAD_F(0x06865181) /* 0.407792573 */, 18 },
+ /* 5913 */ { MAD_F(0x0686b1f2) /* 0.407884545 */, 18 },
+ /* 5914 */ { MAD_F(0x06871264) /* 0.407976522 */, 18 },
+ /* 5915 */ { MAD_F(0x068772d7) /* 0.408068505 */, 18 },
+ /* 5916 */ { MAD_F(0x0687d34c) /* 0.408160492 */, 18 },
+ /* 5917 */ { MAD_F(0x068833c2) /* 0.408252485 */, 18 },
+ /* 5918 */ { MAD_F(0x06889439) /* 0.408344483 */, 18 },
+ /* 5919 */ { MAD_F(0x0688f4b2) /* 0.408436486 */, 18 },
+
+ /* 5920 */ { MAD_F(0x0689552c) /* 0.408528495 */, 18 },
+ /* 5921 */ { MAD_F(0x0689b5a8) /* 0.408620508 */, 18 },
+ /* 5922 */ { MAD_F(0x068a1625) /* 0.408712527 */, 18 },
+ /* 5923 */ { MAD_F(0x068a76a4) /* 0.408804551 */, 18 },
+ /* 5924 */ { MAD_F(0x068ad724) /* 0.408896580 */, 18 },
+ /* 5925 */ { MAD_F(0x068b37a5) /* 0.408988614 */, 18 },
+ /* 5926 */ { MAD_F(0x068b9827) /* 0.409080653 */, 18 },
+ /* 5927 */ { MAD_F(0x068bf8ac) /* 0.409172698 */, 18 },
+ /* 5928 */ { MAD_F(0x068c5931) /* 0.409264748 */, 18 },
+ /* 5929 */ { MAD_F(0x068cb9b8) /* 0.409356803 */, 18 },
+ /* 5930 */ { MAD_F(0x068d1a40) /* 0.409448863 */, 18 },
+ /* 5931 */ { MAD_F(0x068d7aca) /* 0.409540928 */, 18 },
+ /* 5932 */ { MAD_F(0x068ddb54) /* 0.409632999 */, 18 },
+ /* 5933 */ { MAD_F(0x068e3be1) /* 0.409725074 */, 18 },
+ /* 5934 */ { MAD_F(0x068e9c6f) /* 0.409817155 */, 18 },
+ /* 5935 */ { MAD_F(0x068efcfe) /* 0.409909241 */, 18 },
+
+ /* 5936 */ { MAD_F(0x068f5d8e) /* 0.410001332 */, 18 },
+ /* 5937 */ { MAD_F(0x068fbe20) /* 0.410093428 */, 18 },
+ /* 5938 */ { MAD_F(0x06901eb4) /* 0.410185530 */, 18 },
+ /* 5939 */ { MAD_F(0x06907f48) /* 0.410277637 */, 18 },
+ /* 5940 */ { MAD_F(0x0690dfde) /* 0.410369748 */, 18 },
+ /* 5941 */ { MAD_F(0x06914076) /* 0.410461865 */, 18 },
+ /* 5942 */ { MAD_F(0x0691a10f) /* 0.410553988 */, 18 },
+ /* 5943 */ { MAD_F(0x069201a9) /* 0.410646115 */, 18 },
+ /* 5944 */ { MAD_F(0x06926245) /* 0.410738247 */, 18 },
+ /* 5945 */ { MAD_F(0x0692c2e2) /* 0.410830385 */, 18 },
+ /* 5946 */ { MAD_F(0x06932380) /* 0.410922528 */, 18 },
+ /* 5947 */ { MAD_F(0x06938420) /* 0.411014676 */, 18 },
+ /* 5948 */ { MAD_F(0x0693e4c1) /* 0.411106829 */, 18 },
+ /* 5949 */ { MAD_F(0x06944563) /* 0.411198987 */, 18 },
+ /* 5950 */ { MAD_F(0x0694a607) /* 0.411291151 */, 18 },
+ /* 5951 */ { MAD_F(0x069506ad) /* 0.411383320 */, 18 },
+
+ /* 5952 */ { MAD_F(0x06956753) /* 0.411475493 */, 18 },
+ /* 5953 */ { MAD_F(0x0695c7fc) /* 0.411567672 */, 18 },
+ /* 5954 */ { MAD_F(0x069628a5) /* 0.411659857 */, 18 },
+ /* 5955 */ { MAD_F(0x06968950) /* 0.411752046 */, 18 },
+ /* 5956 */ { MAD_F(0x0696e9fc) /* 0.411844240 */, 18 },
+ /* 5957 */ { MAD_F(0x06974aaa) /* 0.411936440 */, 18 },
+ /* 5958 */ { MAD_F(0x0697ab59) /* 0.412028645 */, 18 },
+ /* 5959 */ { MAD_F(0x06980c09) /* 0.412120855 */, 18 },
+ /* 5960 */ { MAD_F(0x06986cbb) /* 0.412213070 */, 18 },
+ /* 5961 */ { MAD_F(0x0698cd6e) /* 0.412305290 */, 18 },
+ /* 5962 */ { MAD_F(0x06992e23) /* 0.412397516 */, 18 },
+ /* 5963 */ { MAD_F(0x06998ed9) /* 0.412489746 */, 18 },
+ /* 5964 */ { MAD_F(0x0699ef90) /* 0.412581982 */, 18 },
+ /* 5965 */ { MAD_F(0x069a5049) /* 0.412674223 */, 18 },
+ /* 5966 */ { MAD_F(0x069ab103) /* 0.412766469 */, 18 },
+ /* 5967 */ { MAD_F(0x069b11bf) /* 0.412858720 */, 18 },
+
+ /* 5968 */ { MAD_F(0x069b727b) /* 0.412950976 */, 18 },
+ /* 5969 */ { MAD_F(0x069bd33a) /* 0.413043238 */, 18 },
+ /* 5970 */ { MAD_F(0x069c33f9) /* 0.413135505 */, 18 },
+ /* 5971 */ { MAD_F(0x069c94ba) /* 0.413227776 */, 18 },
+ /* 5972 */ { MAD_F(0x069cf57d) /* 0.413320053 */, 18 },
+ /* 5973 */ { MAD_F(0x069d5641) /* 0.413412335 */, 18 },
+ /* 5974 */ { MAD_F(0x069db706) /* 0.413504623 */, 18 },
+ /* 5975 */ { MAD_F(0x069e17cc) /* 0.413596915 */, 18 },
+ /* 5976 */ { MAD_F(0x069e7894) /* 0.413689213 */, 18 },
+ /* 5977 */ { MAD_F(0x069ed95e) /* 0.413781515 */, 18 },
+ /* 5978 */ { MAD_F(0x069f3a28) /* 0.413873823 */, 18 },
+ /* 5979 */ { MAD_F(0x069f9af4) /* 0.413966136 */, 18 },
+ /* 5980 */ { MAD_F(0x069ffbc2) /* 0.414058454 */, 18 },
+ /* 5981 */ { MAD_F(0x06a05c91) /* 0.414150778 */, 18 },
+ /* 5982 */ { MAD_F(0x06a0bd61) /* 0.414243106 */, 18 },
+ /* 5983 */ { MAD_F(0x06a11e32) /* 0.414335440 */, 18 },
+
+ /* 5984 */ { MAD_F(0x06a17f05) /* 0.414427779 */, 18 },
+ /* 5985 */ { MAD_F(0x06a1dfda) /* 0.414520122 */, 18 },
+ /* 5986 */ { MAD_F(0x06a240b0) /* 0.414612471 */, 18 },
+ /* 5987 */ { MAD_F(0x06a2a187) /* 0.414704826 */, 18 },
+ /* 5988 */ { MAD_F(0x06a3025f) /* 0.414797185 */, 18 },
+ /* 5989 */ { MAD_F(0x06a36339) /* 0.414889549 */, 18 },
+ /* 5990 */ { MAD_F(0x06a3c414) /* 0.414981919 */, 18 },
+ /* 5991 */ { MAD_F(0x06a424f1) /* 0.415074294 */, 18 },
+ /* 5992 */ { MAD_F(0x06a485cf) /* 0.415166674 */, 18 },
+ /* 5993 */ { MAD_F(0x06a4e6ae) /* 0.415259059 */, 18 },
+ /* 5994 */ { MAD_F(0x06a5478f) /* 0.415351449 */, 18 },
+ /* 5995 */ { MAD_F(0x06a5a871) /* 0.415443844 */, 18 },
+ /* 5996 */ { MAD_F(0x06a60955) /* 0.415536244 */, 18 },
+ /* 5997 */ { MAD_F(0x06a66a3a) /* 0.415628650 */, 18 },
+ /* 5998 */ { MAD_F(0x06a6cb20) /* 0.415721061 */, 18 },
+ /* 5999 */ { MAD_F(0x06a72c08) /* 0.415813476 */, 18 },
+
+ /* 6000 */ { MAD_F(0x06a78cf1) /* 0.415905897 */, 18 },
+ /* 6001 */ { MAD_F(0x06a7eddb) /* 0.415998324 */, 18 },
+ /* 6002 */ { MAD_F(0x06a84ec7) /* 0.416090755 */, 18 },
+ /* 6003 */ { MAD_F(0x06a8afb4) /* 0.416183191 */, 18 },
+ /* 6004 */ { MAD_F(0x06a910a3) /* 0.416275633 */, 18 },
+ /* 6005 */ { MAD_F(0x06a97193) /* 0.416368079 */, 18 },
+ /* 6006 */ { MAD_F(0x06a9d284) /* 0.416460531 */, 18 },
+ /* 6007 */ { MAD_F(0x06aa3377) /* 0.416552988 */, 18 },
+ /* 6008 */ { MAD_F(0x06aa946b) /* 0.416645450 */, 18 },
+ /* 6009 */ { MAD_F(0x06aaf561) /* 0.416737917 */, 18 },
+ /* 6010 */ { MAD_F(0x06ab5657) /* 0.416830389 */, 18 },
+ /* 6011 */ { MAD_F(0x06abb750) /* 0.416922867 */, 18 },
+ /* 6012 */ { MAD_F(0x06ac1849) /* 0.417015349 */, 18 },
+ /* 6013 */ { MAD_F(0x06ac7944) /* 0.417107837 */, 18 },
+ /* 6014 */ { MAD_F(0x06acda41) /* 0.417200330 */, 18 },
+ /* 6015 */ { MAD_F(0x06ad3b3e) /* 0.417292828 */, 18 },
+
+ /* 6016 */ { MAD_F(0x06ad9c3d) /* 0.417385331 */, 18 },
+ /* 6017 */ { MAD_F(0x06adfd3e) /* 0.417477839 */, 18 },
+ /* 6018 */ { MAD_F(0x06ae5e40) /* 0.417570352 */, 18 },
+ /* 6019 */ { MAD_F(0x06aebf43) /* 0.417662871 */, 18 },
+ /* 6020 */ { MAD_F(0x06af2047) /* 0.417755394 */, 18 },
+ /* 6021 */ { MAD_F(0x06af814d) /* 0.417847923 */, 18 },
+ /* 6022 */ { MAD_F(0x06afe255) /* 0.417940457 */, 18 },
+ /* 6023 */ { MAD_F(0x06b0435e) /* 0.418032996 */, 18 },
+ /* 6024 */ { MAD_F(0x06b0a468) /* 0.418125540 */, 18 },
+ /* 6025 */ { MAD_F(0x06b10573) /* 0.418218089 */, 18 },
+ /* 6026 */ { MAD_F(0x06b16680) /* 0.418310643 */, 18 },
+ /* 6027 */ { MAD_F(0x06b1c78e) /* 0.418403203 */, 18 },
+ /* 6028 */ { MAD_F(0x06b2289e) /* 0.418495767 */, 18 },
+ /* 6029 */ { MAD_F(0x06b289af) /* 0.418588337 */, 18 },
+ /* 6030 */ { MAD_F(0x06b2eac1) /* 0.418680911 */, 18 },
+ /* 6031 */ { MAD_F(0x06b34bd5) /* 0.418773491 */, 18 },
+
+ /* 6032 */ { MAD_F(0x06b3acea) /* 0.418866076 */, 18 },
+ /* 6033 */ { MAD_F(0x06b40e00) /* 0.418958666 */, 18 },
+ /* 6034 */ { MAD_F(0x06b46f18) /* 0.419051262 */, 18 },
+ /* 6035 */ { MAD_F(0x06b4d031) /* 0.419143862 */, 18 },
+ /* 6036 */ { MAD_F(0x06b5314c) /* 0.419236467 */, 18 },
+ /* 6037 */ { MAD_F(0x06b59268) /* 0.419329078 */, 18 },
+ /* 6038 */ { MAD_F(0x06b5f385) /* 0.419421694 */, 18 },
+ /* 6039 */ { MAD_F(0x06b654a4) /* 0.419514314 */, 18 },
+ /* 6040 */ { MAD_F(0x06b6b5c4) /* 0.419606940 */, 18 },
+ /* 6041 */ { MAD_F(0x06b716e6) /* 0.419699571 */, 18 },
+ /* 6042 */ { MAD_F(0x06b77808) /* 0.419792208 */, 18 },
+ /* 6043 */ { MAD_F(0x06b7d92d) /* 0.419884849 */, 18 },
+ /* 6044 */ { MAD_F(0x06b83a52) /* 0.419977495 */, 18 },
+ /* 6045 */ { MAD_F(0x06b89b79) /* 0.420070147 */, 18 },
+ /* 6046 */ { MAD_F(0x06b8fca1) /* 0.420162803 */, 18 },
+ /* 6047 */ { MAD_F(0x06b95dcb) /* 0.420255465 */, 18 },
+
+ /* 6048 */ { MAD_F(0x06b9bef6) /* 0.420348132 */, 18 },
+ /* 6049 */ { MAD_F(0x06ba2023) /* 0.420440803 */, 18 },
+ /* 6050 */ { MAD_F(0x06ba8150) /* 0.420533481 */, 18 },
+ /* 6051 */ { MAD_F(0x06bae280) /* 0.420626163 */, 18 },
+ /* 6052 */ { MAD_F(0x06bb43b0) /* 0.420718850 */, 18 },
+ /* 6053 */ { MAD_F(0x06bba4e2) /* 0.420811542 */, 18 },
+ /* 6054 */ { MAD_F(0x06bc0615) /* 0.420904240 */, 18 },
+ /* 6055 */ { MAD_F(0x06bc674a) /* 0.420996942 */, 18 },
+ /* 6056 */ { MAD_F(0x06bcc880) /* 0.421089650 */, 18 },
+ /* 6057 */ { MAD_F(0x06bd29b7) /* 0.421182362 */, 18 },
+ /* 6058 */ { MAD_F(0x06bd8af0) /* 0.421275080 */, 18 },
+ /* 6059 */ { MAD_F(0x06bdec2a) /* 0.421367803 */, 18 },
+ /* 6060 */ { MAD_F(0x06be4d66) /* 0.421460531 */, 18 },
+ /* 6061 */ { MAD_F(0x06beaea3) /* 0.421553264 */, 18 },
+ /* 6062 */ { MAD_F(0x06bf0fe1) /* 0.421646003 */, 18 },
+ /* 6063 */ { MAD_F(0x06bf7120) /* 0.421738746 */, 18 },
+
+ /* 6064 */ { MAD_F(0x06bfd261) /* 0.421831494 */, 18 },
+ /* 6065 */ { MAD_F(0x06c033a4) /* 0.421924248 */, 18 },
+ /* 6066 */ { MAD_F(0x06c094e7) /* 0.422017007 */, 18 },
+ /* 6067 */ { MAD_F(0x06c0f62c) /* 0.422109770 */, 18 },
+ /* 6068 */ { MAD_F(0x06c15773) /* 0.422202539 */, 18 },
+ /* 6069 */ { MAD_F(0x06c1b8bb) /* 0.422295313 */, 18 },
+ /* 6070 */ { MAD_F(0x06c21a04) /* 0.422388092 */, 18 },
+ /* 6071 */ { MAD_F(0x06c27b4e) /* 0.422480876 */, 18 },
+ /* 6072 */ { MAD_F(0x06c2dc9a) /* 0.422573665 */, 18 },
+ /* 6073 */ { MAD_F(0x06c33de8) /* 0.422666460 */, 18 },
+ /* 6074 */ { MAD_F(0x06c39f36) /* 0.422759259 */, 18 },
+ /* 6075 */ { MAD_F(0x06c40086) /* 0.422852064 */, 18 },
+ /* 6076 */ { MAD_F(0x06c461d8) /* 0.422944873 */, 18 },
+ /* 6077 */ { MAD_F(0x06c4c32a) /* 0.423037688 */, 18 },
+ /* 6078 */ { MAD_F(0x06c5247f) /* 0.423130508 */, 18 },
+ /* 6079 */ { MAD_F(0x06c585d4) /* 0.423223333 */, 18 },
+
+ /* 6080 */ { MAD_F(0x06c5e72b) /* 0.423316162 */, 18 },
+ /* 6081 */ { MAD_F(0x06c64883) /* 0.423408997 */, 18 },
+ /* 6082 */ { MAD_F(0x06c6a9dd) /* 0.423501838 */, 18 },
+ /* 6083 */ { MAD_F(0x06c70b38) /* 0.423594683 */, 18 },
+ /* 6084 */ { MAD_F(0x06c76c94) /* 0.423687533 */, 18 },
+ /* 6085 */ { MAD_F(0x06c7cdf2) /* 0.423780389 */, 18 },
+ /* 6086 */ { MAD_F(0x06c82f51) /* 0.423873249 */, 18 },
+ /* 6087 */ { MAD_F(0x06c890b1) /* 0.423966115 */, 18 },
+ /* 6088 */ { MAD_F(0x06c8f213) /* 0.424058985 */, 18 },
+ /* 6089 */ { MAD_F(0x06c95376) /* 0.424151861 */, 18 },
+ /* 6090 */ { MAD_F(0x06c9b4da) /* 0.424244742 */, 18 },
+ /* 6091 */ { MAD_F(0x06ca1640) /* 0.424337628 */, 18 },
+ /* 6092 */ { MAD_F(0x06ca77a8) /* 0.424430519 */, 18 },
+ /* 6093 */ { MAD_F(0x06cad910) /* 0.424523415 */, 18 },
+ /* 6094 */ { MAD_F(0x06cb3a7a) /* 0.424616316 */, 18 },
+ /* 6095 */ { MAD_F(0x06cb9be5) /* 0.424709222 */, 18 },
+
+ /* 6096 */ { MAD_F(0x06cbfd52) /* 0.424802133 */, 18 },
+ /* 6097 */ { MAD_F(0x06cc5ec0) /* 0.424895050 */, 18 },
+ /* 6098 */ { MAD_F(0x06ccc030) /* 0.424987971 */, 18 },
+ /* 6099 */ { MAD_F(0x06cd21a0) /* 0.425080898 */, 18 },
+ /* 6100 */ { MAD_F(0x06cd8313) /* 0.425173829 */, 18 },
+ /* 6101 */ { MAD_F(0x06cde486) /* 0.425266766 */, 18 },
+ /* 6102 */ { MAD_F(0x06ce45fb) /* 0.425359708 */, 18 },
+ /* 6103 */ { MAD_F(0x06cea771) /* 0.425452655 */, 18 },
+ /* 6104 */ { MAD_F(0x06cf08e9) /* 0.425545607 */, 18 },
+ /* 6105 */ { MAD_F(0x06cf6a62) /* 0.425638564 */, 18 },
+ /* 6106 */ { MAD_F(0x06cfcbdc) /* 0.425731526 */, 18 },
+ /* 6107 */ { MAD_F(0x06d02d58) /* 0.425824493 */, 18 },
+ /* 6108 */ { MAD_F(0x06d08ed5) /* 0.425917465 */, 18 },
+ /* 6109 */ { MAD_F(0x06d0f053) /* 0.426010443 */, 18 },
+ /* 6110 */ { MAD_F(0x06d151d3) /* 0.426103425 */, 18 },
+ /* 6111 */ { MAD_F(0x06d1b354) /* 0.426196412 */, 18 },
+
+ /* 6112 */ { MAD_F(0x06d214d7) /* 0.426289405 */, 18 },
+ /* 6113 */ { MAD_F(0x06d2765a) /* 0.426382403 */, 18 },
+ /* 6114 */ { MAD_F(0x06d2d7e0) /* 0.426475405 */, 18 },
+ /* 6115 */ { MAD_F(0x06d33966) /* 0.426568413 */, 18 },
+ /* 6116 */ { MAD_F(0x06d39aee) /* 0.426661426 */, 18 },
+ /* 6117 */ { MAD_F(0x06d3fc77) /* 0.426754444 */, 18 },
+ /* 6118 */ { MAD_F(0x06d45e02) /* 0.426847467 */, 18 },
+ /* 6119 */ { MAD_F(0x06d4bf8e) /* 0.426940495 */, 18 },
+ /* 6120 */ { MAD_F(0x06d5211c) /* 0.427033528 */, 18 },
+ /* 6121 */ { MAD_F(0x06d582aa) /* 0.427126566 */, 18 },
+ /* 6122 */ { MAD_F(0x06d5e43a) /* 0.427219609 */, 18 },
+ /* 6123 */ { MAD_F(0x06d645cc) /* 0.427312657 */, 18 },
+ /* 6124 */ { MAD_F(0x06d6a75f) /* 0.427405711 */, 18 },
+ /* 6125 */ { MAD_F(0x06d708f3) /* 0.427498769 */, 18 },
+ /* 6126 */ { MAD_F(0x06d76a88) /* 0.427591833 */, 18 },
+ /* 6127 */ { MAD_F(0x06d7cc1f) /* 0.427684901 */, 18 },
+
+ /* 6128 */ { MAD_F(0x06d82db8) /* 0.427777975 */, 18 },
+ /* 6129 */ { MAD_F(0x06d88f51) /* 0.427871054 */, 18 },
+ /* 6130 */ { MAD_F(0x06d8f0ec) /* 0.427964137 */, 18 },
+ /* 6131 */ { MAD_F(0x06d95288) /* 0.428057226 */, 18 },
+ /* 6132 */ { MAD_F(0x06d9b426) /* 0.428150320 */, 18 },
+ /* 6133 */ { MAD_F(0x06da15c5) /* 0.428243419 */, 18 },
+ /* 6134 */ { MAD_F(0x06da7766) /* 0.428336523 */, 18 },
+ /* 6135 */ { MAD_F(0x06dad907) /* 0.428429632 */, 18 },
+ /* 6136 */ { MAD_F(0x06db3aaa) /* 0.428522746 */, 18 },
+ /* 6137 */ { MAD_F(0x06db9c4f) /* 0.428615865 */, 18 },
+ /* 6138 */ { MAD_F(0x06dbfdf5) /* 0.428708989 */, 18 },
+ /* 6139 */ { MAD_F(0x06dc5f9c) /* 0.428802119 */, 18 },
+ /* 6140 */ { MAD_F(0x06dcc145) /* 0.428895253 */, 18 },
+ /* 6141 */ { MAD_F(0x06dd22ee) /* 0.428988392 */, 18 },
+ /* 6142 */ { MAD_F(0x06dd849a) /* 0.429081537 */, 18 },
+ /* 6143 */ { MAD_F(0x06dde646) /* 0.429174686 */, 18 },
+
+ /* 6144 */ { MAD_F(0x06de47f4) /* 0.429267841 */, 18 },
+ /* 6145 */ { MAD_F(0x06dea9a4) /* 0.429361001 */, 18 },
+ /* 6146 */ { MAD_F(0x06df0b54) /* 0.429454165 */, 18 },
+ /* 6147 */ { MAD_F(0x06df6d06) /* 0.429547335 */, 18 },
+ /* 6148 */ { MAD_F(0x06dfceba) /* 0.429640510 */, 18 },
+ /* 6149 */ { MAD_F(0x06e0306f) /* 0.429733690 */, 18 },
+ /* 6150 */ { MAD_F(0x06e09225) /* 0.429826874 */, 18 },
+ /* 6151 */ { MAD_F(0x06e0f3dc) /* 0.429920064 */, 18 },
+ /* 6152 */ { MAD_F(0x06e15595) /* 0.430013259 */, 18 },
+ /* 6153 */ { MAD_F(0x06e1b74f) /* 0.430106459 */, 18 },
+ /* 6154 */ { MAD_F(0x06e2190b) /* 0.430199664 */, 18 },
+ /* 6155 */ { MAD_F(0x06e27ac8) /* 0.430292875 */, 18 },
+ /* 6156 */ { MAD_F(0x06e2dc86) /* 0.430386090 */, 18 },
+ /* 6157 */ { MAD_F(0x06e33e46) /* 0.430479310 */, 18 },
+ /* 6158 */ { MAD_F(0x06e3a007) /* 0.430572535 */, 18 },
+ /* 6159 */ { MAD_F(0x06e401c9) /* 0.430665765 */, 18 },
+
+ /* 6160 */ { MAD_F(0x06e4638d) /* 0.430759001 */, 18 },
+ /* 6161 */ { MAD_F(0x06e4c552) /* 0.430852241 */, 18 },
+ /* 6162 */ { MAD_F(0x06e52718) /* 0.430945487 */, 18 },
+ /* 6163 */ { MAD_F(0x06e588e0) /* 0.431038737 */, 18 },
+ /* 6164 */ { MAD_F(0x06e5eaa9) /* 0.431131993 */, 18 },
+ /* 6165 */ { MAD_F(0x06e64c73) /* 0.431225253 */, 18 },
+ /* 6166 */ { MAD_F(0x06e6ae3f) /* 0.431318519 */, 18 },
+ /* 6167 */ { MAD_F(0x06e7100c) /* 0.431411790 */, 18 },
+ /* 6168 */ { MAD_F(0x06e771db) /* 0.431505065 */, 18 },
+ /* 6169 */ { MAD_F(0x06e7d3ab) /* 0.431598346 */, 18 },
+ /* 6170 */ { MAD_F(0x06e8357c) /* 0.431691632 */, 18 },
+ /* 6171 */ { MAD_F(0x06e8974e) /* 0.431784923 */, 18 },
+ /* 6172 */ { MAD_F(0x06e8f922) /* 0.431878218 */, 18 },
+ /* 6173 */ { MAD_F(0x06e95af8) /* 0.431971519 */, 18 },
+ /* 6174 */ { MAD_F(0x06e9bcce) /* 0.432064825 */, 18 },
+ /* 6175 */ { MAD_F(0x06ea1ea6) /* 0.432158136 */, 18 },
+
+ /* 6176 */ { MAD_F(0x06ea807f) /* 0.432251452 */, 18 },
+ /* 6177 */ { MAD_F(0x06eae25a) /* 0.432344773 */, 18 },
+ /* 6178 */ { MAD_F(0x06eb4436) /* 0.432438099 */, 18 },
+ /* 6179 */ { MAD_F(0x06eba614) /* 0.432531431 */, 18 },
+ /* 6180 */ { MAD_F(0x06ec07f2) /* 0.432624767 */, 18 },
+ /* 6181 */ { MAD_F(0x06ec69d2) /* 0.432718108 */, 18 },
+ /* 6182 */ { MAD_F(0x06eccbb4) /* 0.432811454 */, 18 },
+ /* 6183 */ { MAD_F(0x06ed2d97) /* 0.432904805 */, 18 },
+ /* 6184 */ { MAD_F(0x06ed8f7b) /* 0.432998162 */, 18 },
+ /* 6185 */ { MAD_F(0x06edf160) /* 0.433091523 */, 18 },
+ /* 6186 */ { MAD_F(0x06ee5347) /* 0.433184889 */, 18 },
+ /* 6187 */ { MAD_F(0x06eeb52f) /* 0.433278261 */, 18 },
+ /* 6188 */ { MAD_F(0x06ef1719) /* 0.433371637 */, 18 },
+ /* 6189 */ { MAD_F(0x06ef7904) /* 0.433465019 */, 18 },
+ /* 6190 */ { MAD_F(0x06efdaf0) /* 0.433558405 */, 18 },
+ /* 6191 */ { MAD_F(0x06f03cde) /* 0.433651797 */, 18 },
+
+ /* 6192 */ { MAD_F(0x06f09ecc) /* 0.433745193 */, 18 },
+ /* 6193 */ { MAD_F(0x06f100bd) /* 0.433838595 */, 18 },
+ /* 6194 */ { MAD_F(0x06f162ae) /* 0.433932001 */, 18 },
+ /* 6195 */ { MAD_F(0x06f1c4a1) /* 0.434025413 */, 18 },
+ /* 6196 */ { MAD_F(0x06f22696) /* 0.434118830 */, 18 },
+ /* 6197 */ { MAD_F(0x06f2888b) /* 0.434212251 */, 18 },
+ /* 6198 */ { MAD_F(0x06f2ea82) /* 0.434305678 */, 18 },
+ /* 6199 */ { MAD_F(0x06f34c7b) /* 0.434399110 */, 18 },
+ /* 6200 */ { MAD_F(0x06f3ae75) /* 0.434492546 */, 18 },
+ /* 6201 */ { MAD_F(0x06f41070) /* 0.434585988 */, 18 },
+ /* 6202 */ { MAD_F(0x06f4726c) /* 0.434679435 */, 18 },
+ /* 6203 */ { MAD_F(0x06f4d46a) /* 0.434772887 */, 18 },
+ /* 6204 */ { MAD_F(0x06f53669) /* 0.434866344 */, 18 },
+ /* 6205 */ { MAD_F(0x06f59869) /* 0.434959806 */, 18 },
+ /* 6206 */ { MAD_F(0x06f5fa6b) /* 0.435053272 */, 18 },
+ /* 6207 */ { MAD_F(0x06f65c6e) /* 0.435146744 */, 18 },
+
+ /* 6208 */ { MAD_F(0x06f6be73) /* 0.435240221 */, 18 },
+ /* 6209 */ { MAD_F(0x06f72079) /* 0.435333703 */, 18 },
+ /* 6210 */ { MAD_F(0x06f78280) /* 0.435427190 */, 18 },
+ /* 6211 */ { MAD_F(0x06f7e489) /* 0.435520682 */, 18 },
+ /* 6212 */ { MAD_F(0x06f84693) /* 0.435614179 */, 18 },
+ /* 6213 */ { MAD_F(0x06f8a89e) /* 0.435707681 */, 18 },
+ /* 6214 */ { MAD_F(0x06f90aaa) /* 0.435801188 */, 18 },
+ /* 6215 */ { MAD_F(0x06f96cb8) /* 0.435894700 */, 18 },
+ /* 6216 */ { MAD_F(0x06f9cec8) /* 0.435988217 */, 18 },
+ /* 6217 */ { MAD_F(0x06fa30d8) /* 0.436081739 */, 18 },
+ /* 6218 */ { MAD_F(0x06fa92ea) /* 0.436175266 */, 18 },
+ /* 6219 */ { MAD_F(0x06faf4fe) /* 0.436268799 */, 18 },
+ /* 6220 */ { MAD_F(0x06fb5712) /* 0.436362336 */, 18 },
+ /* 6221 */ { MAD_F(0x06fbb928) /* 0.436455878 */, 18 },
+ /* 6222 */ { MAD_F(0x06fc1b40) /* 0.436549425 */, 18 },
+ /* 6223 */ { MAD_F(0x06fc7d58) /* 0.436642977 */, 18 },
+
+ /* 6224 */ { MAD_F(0x06fcdf72) /* 0.436736534 */, 18 },
+ /* 6225 */ { MAD_F(0x06fd418e) /* 0.436830096 */, 18 },
+ /* 6226 */ { MAD_F(0x06fda3ab) /* 0.436923664 */, 18 },
+ /* 6227 */ { MAD_F(0x06fe05c9) /* 0.437017236 */, 18 },
+ /* 6228 */ { MAD_F(0x06fe67e8) /* 0.437110813 */, 18 },
+ /* 6229 */ { MAD_F(0x06feca09) /* 0.437204395 */, 18 },
+ /* 6230 */ { MAD_F(0x06ff2c2b) /* 0.437297982 */, 18 },
+ /* 6231 */ { MAD_F(0x06ff8e4f) /* 0.437391575 */, 18 },
+ /* 6232 */ { MAD_F(0x06fff073) /* 0.437485172 */, 18 },
+ /* 6233 */ { MAD_F(0x0700529a) /* 0.437578774 */, 18 },
+ /* 6234 */ { MAD_F(0x0700b4c1) /* 0.437672381 */, 18 },
+ /* 6235 */ { MAD_F(0x070116ea) /* 0.437765994 */, 18 },
+ /* 6236 */ { MAD_F(0x07017914) /* 0.437859611 */, 18 },
+ /* 6237 */ { MAD_F(0x0701db40) /* 0.437953233 */, 18 },
+ /* 6238 */ { MAD_F(0x07023d6c) /* 0.438046860 */, 18 },
+ /* 6239 */ { MAD_F(0x07029f9b) /* 0.438140493 */, 18 },
+
+ /* 6240 */ { MAD_F(0x070301ca) /* 0.438234130 */, 18 },
+ /* 6241 */ { MAD_F(0x070363fb) /* 0.438327772 */, 18 },
+ /* 6242 */ { MAD_F(0x0703c62d) /* 0.438421419 */, 18 },
+ /* 6243 */ { MAD_F(0x07042861) /* 0.438515072 */, 18 },
+ /* 6244 */ { MAD_F(0x07048a96) /* 0.438608729 */, 18 },
+ /* 6245 */ { MAD_F(0x0704eccc) /* 0.438702391 */, 18 },
+ /* 6246 */ { MAD_F(0x07054f04) /* 0.438796059 */, 18 },
+ /* 6247 */ { MAD_F(0x0705b13d) /* 0.438889731 */, 18 },
+ /* 6248 */ { MAD_F(0x07061377) /* 0.438983408 */, 18 },
+ /* 6249 */ { MAD_F(0x070675b3) /* 0.439077090 */, 18 },
+ /* 6250 */ { MAD_F(0x0706d7f0) /* 0.439170778 */, 18 },
+ /* 6251 */ { MAD_F(0x07073a2e) /* 0.439264470 */, 18 },
+ /* 6252 */ { MAD_F(0x07079c6e) /* 0.439358167 */, 18 },
+ /* 6253 */ { MAD_F(0x0707feaf) /* 0.439451869 */, 18 },
+ /* 6254 */ { MAD_F(0x070860f1) /* 0.439545577 */, 18 },
+ /* 6255 */ { MAD_F(0x0708c335) /* 0.439639289 */, 18 },
+
+ /* 6256 */ { MAD_F(0x0709257a) /* 0.439733006 */, 18 },
+ /* 6257 */ { MAD_F(0x070987c0) /* 0.439826728 */, 18 },
+ /* 6258 */ { MAD_F(0x0709ea08) /* 0.439920456 */, 18 },
+ /* 6259 */ { MAD_F(0x070a4c51) /* 0.440014188 */, 18 },
+ /* 6260 */ { MAD_F(0x070aae9b) /* 0.440107925 */, 18 },
+ /* 6261 */ { MAD_F(0x070b10e7) /* 0.440201667 */, 18 },
+ /* 6262 */ { MAD_F(0x070b7334) /* 0.440295414 */, 18 },
+ /* 6263 */ { MAD_F(0x070bd583) /* 0.440389167 */, 18 },
+ /* 6264 */ { MAD_F(0x070c37d2) /* 0.440482924 */, 18 },
+ /* 6265 */ { MAD_F(0x070c9a23) /* 0.440576686 */, 18 },
+ /* 6266 */ { MAD_F(0x070cfc76) /* 0.440670453 */, 18 },
+ /* 6267 */ { MAD_F(0x070d5eca) /* 0.440764225 */, 18 },
+ /* 6268 */ { MAD_F(0x070dc11f) /* 0.440858002 */, 18 },
+ /* 6269 */ { MAD_F(0x070e2375) /* 0.440951784 */, 18 },
+ /* 6270 */ { MAD_F(0x070e85cd) /* 0.441045572 */, 18 },
+ /* 6271 */ { MAD_F(0x070ee826) /* 0.441139364 */, 18 },
+
+ /* 6272 */ { MAD_F(0x070f4a80) /* 0.441233161 */, 18 },
+ /* 6273 */ { MAD_F(0x070facdc) /* 0.441326963 */, 18 },
+ /* 6274 */ { MAD_F(0x07100f39) /* 0.441420770 */, 18 },
+ /* 6275 */ { MAD_F(0x07107198) /* 0.441514582 */, 18 },
+ /* 6276 */ { MAD_F(0x0710d3f8) /* 0.441608399 */, 18 },
+ /* 6277 */ { MAD_F(0x07113659) /* 0.441702221 */, 18 },
+ /* 6278 */ { MAD_F(0x071198bb) /* 0.441796048 */, 18 },
+ /* 6279 */ { MAD_F(0x0711fb1f) /* 0.441889880 */, 18 },
+ /* 6280 */ { MAD_F(0x07125d84) /* 0.441983717 */, 18 },
+ /* 6281 */ { MAD_F(0x0712bfeb) /* 0.442077559 */, 18 },
+ /* 6282 */ { MAD_F(0x07132253) /* 0.442171406 */, 18 },
+ /* 6283 */ { MAD_F(0x071384bc) /* 0.442265257 */, 18 },
+ /* 6284 */ { MAD_F(0x0713e726) /* 0.442359114 */, 18 },
+ /* 6285 */ { MAD_F(0x07144992) /* 0.442452976 */, 18 },
+ /* 6286 */ { MAD_F(0x0714abff) /* 0.442546843 */, 18 },
+ /* 6287 */ { MAD_F(0x07150e6e) /* 0.442640715 */, 18 },
+
+ /* 6288 */ { MAD_F(0x071570de) /* 0.442734592 */, 18 },
+ /* 6289 */ { MAD_F(0x0715d34f) /* 0.442828473 */, 18 },
+ /* 6290 */ { MAD_F(0x071635c1) /* 0.442922360 */, 18 },
+ /* 6291 */ { MAD_F(0x07169835) /* 0.443016252 */, 18 },
+ /* 6292 */ { MAD_F(0x0716faaa) /* 0.443110148 */, 18 },
+ /* 6293 */ { MAD_F(0x07175d21) /* 0.443204050 */, 18 },
+ /* 6294 */ { MAD_F(0x0717bf99) /* 0.443297957 */, 18 },
+ /* 6295 */ { MAD_F(0x07182212) /* 0.443391868 */, 18 },
+ /* 6296 */ { MAD_F(0x0718848d) /* 0.443485785 */, 18 },
+ /* 6297 */ { MAD_F(0x0718e709) /* 0.443579706 */, 18 },
+ /* 6298 */ { MAD_F(0x07194986) /* 0.443673633 */, 18 },
+ /* 6299 */ { MAD_F(0x0719ac04) /* 0.443767564 */, 18 },
+ /* 6300 */ { MAD_F(0x071a0e84) /* 0.443861501 */, 18 },
+ /* 6301 */ { MAD_F(0x071a7105) /* 0.443955442 */, 18 },
+ /* 6302 */ { MAD_F(0x071ad388) /* 0.444049389 */, 18 },
+ /* 6303 */ { MAD_F(0x071b360c) /* 0.444143340 */, 18 },
+
+ /* 6304 */ { MAD_F(0x071b9891) /* 0.444237296 */, 18 },
+ /* 6305 */ { MAD_F(0x071bfb18) /* 0.444331258 */, 18 },
+ /* 6306 */ { MAD_F(0x071c5d9f) /* 0.444425224 */, 18 },
+ /* 6307 */ { MAD_F(0x071cc029) /* 0.444519195 */, 18 },
+ /* 6308 */ { MAD_F(0x071d22b3) /* 0.444613171 */, 18 },
+ /* 6309 */ { MAD_F(0x071d853f) /* 0.444707153 */, 18 },
+ /* 6310 */ { MAD_F(0x071de7cc) /* 0.444801139 */, 18 },
+ /* 6311 */ { MAD_F(0x071e4a5b) /* 0.444895130 */, 18 },
+ /* 6312 */ { MAD_F(0x071eaceb) /* 0.444989126 */, 18 },
+ /* 6313 */ { MAD_F(0x071f0f7c) /* 0.445083127 */, 18 },
+ /* 6314 */ { MAD_F(0x071f720e) /* 0.445177133 */, 18 },
+ /* 6315 */ { MAD_F(0x071fd4a2) /* 0.445271144 */, 18 },
+ /* 6316 */ { MAD_F(0x07203737) /* 0.445365160 */, 18 },
+ /* 6317 */ { MAD_F(0x072099ce) /* 0.445459181 */, 18 },
+ /* 6318 */ { MAD_F(0x0720fc66) /* 0.445553206 */, 18 },
+ /* 6319 */ { MAD_F(0x07215eff) /* 0.445647237 */, 18 },
+
+ /* 6320 */ { MAD_F(0x0721c19a) /* 0.445741273 */, 18 },
+ /* 6321 */ { MAD_F(0x07222436) /* 0.445835314 */, 18 },
+ /* 6322 */ { MAD_F(0x072286d3) /* 0.445929359 */, 18 },
+ /* 6323 */ { MAD_F(0x0722e971) /* 0.446023410 */, 18 },
+ /* 6324 */ { MAD_F(0x07234c11) /* 0.446117466 */, 18 },
+ /* 6325 */ { MAD_F(0x0723aeb2) /* 0.446211526 */, 18 },
+ /* 6326 */ { MAD_F(0x07241155) /* 0.446305592 */, 18 },
+ /* 6327 */ { MAD_F(0x072473f9) /* 0.446399662 */, 18 },
+ /* 6328 */ { MAD_F(0x0724d69e) /* 0.446493738 */, 18 },
+ /* 6329 */ { MAD_F(0x07253944) /* 0.446587818 */, 18 },
+ /* 6330 */ { MAD_F(0x07259bec) /* 0.446681903 */, 18 },
+ /* 6331 */ { MAD_F(0x0725fe95) /* 0.446775994 */, 18 },
+ /* 6332 */ { MAD_F(0x07266140) /* 0.446870089 */, 18 },
+ /* 6333 */ { MAD_F(0x0726c3ec) /* 0.446964189 */, 18 },
+ /* 6334 */ { MAD_F(0x07272699) /* 0.447058294 */, 18 },
+ /* 6335 */ { MAD_F(0x07278947) /* 0.447152404 */, 18 },
+
+ /* 6336 */ { MAD_F(0x0727ebf7) /* 0.447246519 */, 18 },
+ /* 6337 */ { MAD_F(0x07284ea8) /* 0.447340639 */, 18 },
+ /* 6338 */ { MAD_F(0x0728b15b) /* 0.447434764 */, 18 },
+ /* 6339 */ { MAD_F(0x0729140f) /* 0.447528894 */, 18 },
+ /* 6340 */ { MAD_F(0x072976c4) /* 0.447623029 */, 18 },
+ /* 6341 */ { MAD_F(0x0729d97a) /* 0.447717169 */, 18 },
+ /* 6342 */ { MAD_F(0x072a3c32) /* 0.447811314 */, 18 },
+ /* 6343 */ { MAD_F(0x072a9eeb) /* 0.447905463 */, 18 },
+ /* 6344 */ { MAD_F(0x072b01a6) /* 0.447999618 */, 18 },
+ /* 6345 */ { MAD_F(0x072b6461) /* 0.448093778 */, 18 },
+ /* 6346 */ { MAD_F(0x072bc71e) /* 0.448187942 */, 18 },
+ /* 6347 */ { MAD_F(0x072c29dd) /* 0.448282112 */, 18 },
+ /* 6348 */ { MAD_F(0x072c8c9d) /* 0.448376286 */, 18 },
+ /* 6349 */ { MAD_F(0x072cef5e) /* 0.448470466 */, 18 },
+ /* 6350 */ { MAD_F(0x072d5220) /* 0.448564650 */, 18 },
+ /* 6351 */ { MAD_F(0x072db4e4) /* 0.448658839 */, 18 },
+
+ /* 6352 */ { MAD_F(0x072e17a9) /* 0.448753033 */, 18 },
+ /* 6353 */ { MAD_F(0x072e7a6f) /* 0.448847233 */, 18 },
+ /* 6354 */ { MAD_F(0x072edd37) /* 0.448941437 */, 18 },
+ /* 6355 */ { MAD_F(0x072f4000) /* 0.449035646 */, 18 },
+ /* 6356 */ { MAD_F(0x072fa2ca) /* 0.449129860 */, 18 },
+ /* 6357 */ { MAD_F(0x07300596) /* 0.449224079 */, 18 },
+ /* 6358 */ { MAD_F(0x07306863) /* 0.449318303 */, 18 },
+ /* 6359 */ { MAD_F(0x0730cb32) /* 0.449412531 */, 18 },
+ /* 6360 */ { MAD_F(0x07312e01) /* 0.449506765 */, 18 },
+ /* 6361 */ { MAD_F(0x073190d2) /* 0.449601004 */, 18 },
+ /* 6362 */ { MAD_F(0x0731f3a5) /* 0.449695247 */, 18 },
+ /* 6363 */ { MAD_F(0x07325678) /* 0.449789496 */, 18 },
+ /* 6364 */ { MAD_F(0x0732b94d) /* 0.449883749 */, 18 },
+ /* 6365 */ { MAD_F(0x07331c23) /* 0.449978008 */, 18 },
+ /* 6366 */ { MAD_F(0x07337efb) /* 0.450072271 */, 18 },
+ /* 6367 */ { MAD_F(0x0733e1d4) /* 0.450166540 */, 18 },
+
+ /* 6368 */ { MAD_F(0x073444ae) /* 0.450260813 */, 18 },
+ /* 6369 */ { MAD_F(0x0734a78a) /* 0.450355091 */, 18 },
+ /* 6370 */ { MAD_F(0x07350a67) /* 0.450449374 */, 18 },
+ /* 6371 */ { MAD_F(0x07356d45) /* 0.450543662 */, 18 },
+ /* 6372 */ { MAD_F(0x0735d025) /* 0.450637955 */, 18 },
+ /* 6373 */ { MAD_F(0x07363306) /* 0.450732253 */, 18 },
+ /* 6374 */ { MAD_F(0x073695e8) /* 0.450826556 */, 18 },
+ /* 6375 */ { MAD_F(0x0736f8cb) /* 0.450920864 */, 18 },
+ /* 6376 */ { MAD_F(0x07375bb0) /* 0.451015176 */, 18 },
+ /* 6377 */ { MAD_F(0x0737be96) /* 0.451109494 */, 18 },
+ /* 6378 */ { MAD_F(0x0738217e) /* 0.451203817 */, 18 },
+ /* 6379 */ { MAD_F(0x07388467) /* 0.451298144 */, 18 },
+ /* 6380 */ { MAD_F(0x0738e751) /* 0.451392477 */, 18 },
+ /* 6381 */ { MAD_F(0x07394a3d) /* 0.451486814 */, 18 },
+ /* 6382 */ { MAD_F(0x0739ad29) /* 0.451581156 */, 18 },
+ /* 6383 */ { MAD_F(0x073a1017) /* 0.451675503 */, 18 },
+
+ /* 6384 */ { MAD_F(0x073a7307) /* 0.451769856 */, 18 },
+ /* 6385 */ { MAD_F(0x073ad5f8) /* 0.451864213 */, 18 },
+ /* 6386 */ { MAD_F(0x073b38ea) /* 0.451958575 */, 18 },
+ /* 6387 */ { MAD_F(0x073b9bdd) /* 0.452052942 */, 18 },
+ /* 6388 */ { MAD_F(0x073bfed2) /* 0.452147313 */, 18 },
+ /* 6389 */ { MAD_F(0x073c61c8) /* 0.452241690 */, 18 },
+ /* 6390 */ { MAD_F(0x073cc4bf) /* 0.452336072 */, 18 },
+ /* 6391 */ { MAD_F(0x073d27b8) /* 0.452430458 */, 18 },
+ /* 6392 */ { MAD_F(0x073d8ab2) /* 0.452524850 */, 18 },
+ /* 6393 */ { MAD_F(0x073dedae) /* 0.452619246 */, 18 },
+ /* 6394 */ { MAD_F(0x073e50aa) /* 0.452713648 */, 18 },
+ /* 6395 */ { MAD_F(0x073eb3a8) /* 0.452808054 */, 18 },
+ /* 6396 */ { MAD_F(0x073f16a8) /* 0.452902465 */, 18 },
+ /* 6397 */ { MAD_F(0x073f79a8) /* 0.452996882 */, 18 },
+ /* 6398 */ { MAD_F(0x073fdcaa) /* 0.453091303 */, 18 },
+ /* 6399 */ { MAD_F(0x07403fad) /* 0.453185729 */, 18 },
+
+ /* 6400 */ { MAD_F(0x0740a2b2) /* 0.453280160 */, 18 },
+ /* 6401 */ { MAD_F(0x074105b8) /* 0.453374595 */, 18 },
+ /* 6402 */ { MAD_F(0x074168bf) /* 0.453469036 */, 18 },
+ /* 6403 */ { MAD_F(0x0741cbc8) /* 0.453563482 */, 18 },
+ /* 6404 */ { MAD_F(0x07422ed2) /* 0.453657932 */, 18 },
+ /* 6405 */ { MAD_F(0x074291dd) /* 0.453752388 */, 18 },
+ /* 6406 */ { MAD_F(0x0742f4e9) /* 0.453846848 */, 18 },
+ /* 6407 */ { MAD_F(0x074357f7) /* 0.453941314 */, 18 },
+ /* 6408 */ { MAD_F(0x0743bb06) /* 0.454035784 */, 18 },
+ /* 6409 */ { MAD_F(0x07441e17) /* 0.454130259 */, 18 },
+ /* 6410 */ { MAD_F(0x07448129) /* 0.454224739 */, 18 },
+ /* 6411 */ { MAD_F(0x0744e43c) /* 0.454319224 */, 18 },
+ /* 6412 */ { MAD_F(0x07454750) /* 0.454413714 */, 18 },
+ /* 6413 */ { MAD_F(0x0745aa66) /* 0.454508209 */, 18 },
+ /* 6414 */ { MAD_F(0x07460d7d) /* 0.454602708 */, 18 },
+ /* 6415 */ { MAD_F(0x07467095) /* 0.454697213 */, 18 },
+
+ /* 6416 */ { MAD_F(0x0746d3af) /* 0.454791723 */, 18 },
+ /* 6417 */ { MAD_F(0x074736ca) /* 0.454886237 */, 18 },
+ /* 6418 */ { MAD_F(0x074799e7) /* 0.454980756 */, 18 },
+ /* 6419 */ { MAD_F(0x0747fd04) /* 0.455075281 */, 18 },
+ /* 6420 */ { MAD_F(0x07486023) /* 0.455169810 */, 18 },
+ /* 6421 */ { MAD_F(0x0748c344) /* 0.455264344 */, 18 },
+ /* 6422 */ { MAD_F(0x07492665) /* 0.455358883 */, 18 },
+ /* 6423 */ { MAD_F(0x07498988) /* 0.455453427 */, 18 },
+ /* 6424 */ { MAD_F(0x0749ecac) /* 0.455547976 */, 18 },
+ /* 6425 */ { MAD_F(0x074a4fd2) /* 0.455642529 */, 18 },
+ /* 6426 */ { MAD_F(0x074ab2f9) /* 0.455737088 */, 18 },
+ /* 6427 */ { MAD_F(0x074b1621) /* 0.455831652 */, 18 },
+ /* 6428 */ { MAD_F(0x074b794b) /* 0.455926220 */, 18 },
+ /* 6429 */ { MAD_F(0x074bdc75) /* 0.456020793 */, 18 },
+ /* 6430 */ { MAD_F(0x074c3fa1) /* 0.456115372 */, 18 },
+ /* 6431 */ { MAD_F(0x074ca2cf) /* 0.456209955 */, 18 },
+
+ /* 6432 */ { MAD_F(0x074d05fe) /* 0.456304543 */, 18 },
+ /* 6433 */ { MAD_F(0x074d692e) /* 0.456399136 */, 18 },
+ /* 6434 */ { MAD_F(0x074dcc5f) /* 0.456493733 */, 18 },
+ /* 6435 */ { MAD_F(0x074e2f92) /* 0.456588336 */, 18 },
+ /* 6436 */ { MAD_F(0x074e92c6) /* 0.456682944 */, 18 },
+ /* 6437 */ { MAD_F(0x074ef5fb) /* 0.456777556 */, 18 },
+ /* 6438 */ { MAD_F(0x074f5932) /* 0.456872174 */, 18 },
+ /* 6439 */ { MAD_F(0x074fbc6a) /* 0.456966796 */, 18 },
+ /* 6440 */ { MAD_F(0x07501fa3) /* 0.457061423 */, 18 },
+ /* 6441 */ { MAD_F(0x075082de) /* 0.457156056 */, 18 },
+ /* 6442 */ { MAD_F(0x0750e61a) /* 0.457250693 */, 18 },
+ /* 6443 */ { MAD_F(0x07514957) /* 0.457345335 */, 18 },
+ /* 6444 */ { MAD_F(0x0751ac96) /* 0.457439981 */, 18 },
+ /* 6445 */ { MAD_F(0x07520fd6) /* 0.457534633 */, 18 },
+ /* 6446 */ { MAD_F(0x07527317) /* 0.457629290 */, 18 },
+ /* 6447 */ { MAD_F(0x0752d659) /* 0.457723951 */, 18 },
+
+ /* 6448 */ { MAD_F(0x0753399d) /* 0.457818618 */, 18 },
+ /* 6449 */ { MAD_F(0x07539ce2) /* 0.457913289 */, 18 },
+ /* 6450 */ { MAD_F(0x07540029) /* 0.458007965 */, 18 },
+ /* 6451 */ { MAD_F(0x07546371) /* 0.458102646 */, 18 },
+ /* 6452 */ { MAD_F(0x0754c6ba) /* 0.458197332 */, 18 },
+ /* 6453 */ { MAD_F(0x07552a04) /* 0.458292023 */, 18 },
+ /* 6454 */ { MAD_F(0x07558d50) /* 0.458386719 */, 18 },
+ /* 6455 */ { MAD_F(0x0755f09d) /* 0.458481420 */, 18 },
+ /* 6456 */ { MAD_F(0x075653eb) /* 0.458576125 */, 18 },
+ /* 6457 */ { MAD_F(0x0756b73b) /* 0.458670836 */, 18 },
+ /* 6458 */ { MAD_F(0x07571a8c) /* 0.458765551 */, 18 },
+ /* 6459 */ { MAD_F(0x07577dde) /* 0.458860271 */, 18 },
+ /* 6460 */ { MAD_F(0x0757e131) /* 0.458954996 */, 18 },
+ /* 6461 */ { MAD_F(0x07584486) /* 0.459049726 */, 18 },
+ /* 6462 */ { MAD_F(0x0758a7dd) /* 0.459144461 */, 18 },
+ /* 6463 */ { MAD_F(0x07590b34) /* 0.459239201 */, 18 },
+
+ /* 6464 */ { MAD_F(0x07596e8d) /* 0.459333946 */, 18 },
+ /* 6465 */ { MAD_F(0x0759d1e7) /* 0.459428695 */, 18 },
+ /* 6466 */ { MAD_F(0x075a3542) /* 0.459523450 */, 18 },
+ /* 6467 */ { MAD_F(0x075a989f) /* 0.459618209 */, 18 },
+ /* 6468 */ { MAD_F(0x075afbfd) /* 0.459712973 */, 18 },
+ /* 6469 */ { MAD_F(0x075b5f5d) /* 0.459807742 */, 18 },
+ /* 6470 */ { MAD_F(0x075bc2bd) /* 0.459902516 */, 18 },
+ /* 6471 */ { MAD_F(0x075c261f) /* 0.459997295 */, 18 },
+ /* 6472 */ { MAD_F(0x075c8983) /* 0.460092079 */, 18 },
+ /* 6473 */ { MAD_F(0x075cece7) /* 0.460186867 */, 18 },
+ /* 6474 */ { MAD_F(0x075d504d) /* 0.460281661 */, 18 },
+ /* 6475 */ { MAD_F(0x075db3b5) /* 0.460376459 */, 18 },
+ /* 6476 */ { MAD_F(0x075e171d) /* 0.460471262 */, 18 },
+ /* 6477 */ { MAD_F(0x075e7a87) /* 0.460566071 */, 18 },
+ /* 6478 */ { MAD_F(0x075eddf2) /* 0.460660884 */, 18 },
+ /* 6479 */ { MAD_F(0x075f415f) /* 0.460755701 */, 18 },
+
+ /* 6480 */ { MAD_F(0x075fa4cc) /* 0.460850524 */, 18 },
+ /* 6481 */ { MAD_F(0x0760083b) /* 0.460945352 */, 18 },
+ /* 6482 */ { MAD_F(0x07606bac) /* 0.461040184 */, 18 },
+ /* 6483 */ { MAD_F(0x0760cf1e) /* 0.461135022 */, 18 },
+ /* 6484 */ { MAD_F(0x07613291) /* 0.461229864 */, 18 },
+ /* 6485 */ { MAD_F(0x07619605) /* 0.461324711 */, 18 },
+ /* 6486 */ { MAD_F(0x0761f97b) /* 0.461419563 */, 18 },
+ /* 6487 */ { MAD_F(0x07625cf2) /* 0.461514420 */, 18 },
+ /* 6488 */ { MAD_F(0x0762c06a) /* 0.461609282 */, 18 },
+ /* 6489 */ { MAD_F(0x076323e3) /* 0.461704149 */, 18 },
+ /* 6490 */ { MAD_F(0x0763875e) /* 0.461799020 */, 18 },
+ /* 6491 */ { MAD_F(0x0763eadb) /* 0.461893897 */, 18 },
+ /* 6492 */ { MAD_F(0x07644e58) /* 0.461988778 */, 18 },
+ /* 6493 */ { MAD_F(0x0764b1d7) /* 0.462083664 */, 18 },
+ /* 6494 */ { MAD_F(0x07651557) /* 0.462178555 */, 18 },
+ /* 6495 */ { MAD_F(0x076578d8) /* 0.462273451 */, 18 },
+
+ /* 6496 */ { MAD_F(0x0765dc5b) /* 0.462368352 */, 18 },
+ /* 6497 */ { MAD_F(0x07663fdf) /* 0.462463257 */, 18 },
+ /* 6498 */ { MAD_F(0x0766a364) /* 0.462558168 */, 18 },
+ /* 6499 */ { MAD_F(0x076706eb) /* 0.462653083 */, 18 },
+ /* 6500 */ { MAD_F(0x07676a73) /* 0.462748003 */, 18 },
+ /* 6501 */ { MAD_F(0x0767cdfc) /* 0.462842928 */, 18 },
+ /* 6502 */ { MAD_F(0x07683187) /* 0.462937858 */, 18 },
+ /* 6503 */ { MAD_F(0x07689513) /* 0.463032793 */, 18 },
+ /* 6504 */ { MAD_F(0x0768f8a0) /* 0.463127733 */, 18 },
+ /* 6505 */ { MAD_F(0x07695c2e) /* 0.463222678 */, 18 },
+ /* 6506 */ { MAD_F(0x0769bfbe) /* 0.463317627 */, 18 },
+ /* 6507 */ { MAD_F(0x076a234f) /* 0.463412581 */, 18 },
+ /* 6508 */ { MAD_F(0x076a86e2) /* 0.463507540 */, 18 },
+ /* 6509 */ { MAD_F(0x076aea75) /* 0.463602504 */, 18 },
+ /* 6510 */ { MAD_F(0x076b4e0a) /* 0.463697473 */, 18 },
+ /* 6511 */ { MAD_F(0x076bb1a1) /* 0.463792447 */, 18 },
+
+ /* 6512 */ { MAD_F(0x076c1538) /* 0.463887426 */, 18 },
+ /* 6513 */ { MAD_F(0x076c78d1) /* 0.463982409 */, 18 },
+ /* 6514 */ { MAD_F(0x076cdc6c) /* 0.464077398 */, 18 },
+ /* 6515 */ { MAD_F(0x076d4007) /* 0.464172391 */, 18 },
+ /* 6516 */ { MAD_F(0x076da3a4) /* 0.464267389 */, 18 },
+ /* 6517 */ { MAD_F(0x076e0742) /* 0.464362392 */, 18 },
+ /* 6518 */ { MAD_F(0x076e6ae2) /* 0.464457399 */, 18 },
+ /* 6519 */ { MAD_F(0x076ece82) /* 0.464552412 */, 18 },
+ /* 6520 */ { MAD_F(0x076f3224) /* 0.464647430 */, 18 },
+ /* 6521 */ { MAD_F(0x076f95c8) /* 0.464742452 */, 18 },
+ /* 6522 */ { MAD_F(0x076ff96c) /* 0.464837479 */, 18 },
+ /* 6523 */ { MAD_F(0x07705d12) /* 0.464932511 */, 18 },
+ /* 6524 */ { MAD_F(0x0770c0ba) /* 0.465027548 */, 18 },
+ /* 6525 */ { MAD_F(0x07712462) /* 0.465122590 */, 18 },
+ /* 6526 */ { MAD_F(0x0771880c) /* 0.465217637 */, 18 },
+ /* 6527 */ { MAD_F(0x0771ebb7) /* 0.465312688 */, 18 },
+
+ /* 6528 */ { MAD_F(0x07724f64) /* 0.465407744 */, 18 },
+ /* 6529 */ { MAD_F(0x0772b312) /* 0.465502806 */, 18 },
+ /* 6530 */ { MAD_F(0x077316c1) /* 0.465597872 */, 18 },
+ /* 6531 */ { MAD_F(0x07737a71) /* 0.465692943 */, 18 },
+ /* 6532 */ { MAD_F(0x0773de23) /* 0.465788018 */, 18 },
+ /* 6533 */ { MAD_F(0x077441d6) /* 0.465883099 */, 18 },
+ /* 6534 */ { MAD_F(0x0774a58a) /* 0.465978184 */, 18 },
+ /* 6535 */ { MAD_F(0x07750940) /* 0.466073275 */, 18 },
+ /* 6536 */ { MAD_F(0x07756cf7) /* 0.466168370 */, 18 },
+ /* 6537 */ { MAD_F(0x0775d0af) /* 0.466263470 */, 18 },
+ /* 6538 */ { MAD_F(0x07763468) /* 0.466358575 */, 18 },
+ /* 6539 */ { MAD_F(0x07769823) /* 0.466453684 */, 18 },
+ /* 6540 */ { MAD_F(0x0776fbdf) /* 0.466548799 */, 18 },
+ /* 6541 */ { MAD_F(0x07775f9d) /* 0.466643918 */, 18 },
+ /* 6542 */ { MAD_F(0x0777c35c) /* 0.466739043 */, 18 },
+ /* 6543 */ { MAD_F(0x0778271c) /* 0.466834172 */, 18 },
+
+ /* 6544 */ { MAD_F(0x07788add) /* 0.466929306 */, 18 },
+ /* 6545 */ { MAD_F(0x0778ee9f) /* 0.467024445 */, 18 },
+ /* 6546 */ { MAD_F(0x07795263) /* 0.467119588 */, 18 },
+ /* 6547 */ { MAD_F(0x0779b629) /* 0.467214737 */, 18 },
+ /* 6548 */ { MAD_F(0x077a19ef) /* 0.467309890 */, 18 },
+ /* 6549 */ { MAD_F(0x077a7db7) /* 0.467405048 */, 18 },
+ /* 6550 */ { MAD_F(0x077ae180) /* 0.467500211 */, 18 },
+ /* 6551 */ { MAD_F(0x077b454b) /* 0.467595379 */, 18 },
+ /* 6552 */ { MAD_F(0x077ba916) /* 0.467690552 */, 18 },
+ /* 6553 */ { MAD_F(0x077c0ce3) /* 0.467785729 */, 18 },
+ /* 6554 */ { MAD_F(0x077c70b2) /* 0.467880912 */, 18 },
+ /* 6555 */ { MAD_F(0x077cd481) /* 0.467976099 */, 18 },
+ /* 6556 */ { MAD_F(0x077d3852) /* 0.468071291 */, 18 },
+ /* 6557 */ { MAD_F(0x077d9c24) /* 0.468166488 */, 18 },
+ /* 6558 */ { MAD_F(0x077dfff8) /* 0.468261690 */, 18 },
+ /* 6559 */ { MAD_F(0x077e63cd) /* 0.468356896 */, 18 },
+
+ /* 6560 */ { MAD_F(0x077ec7a3) /* 0.468452108 */, 18 },
+ /* 6561 */ { MAD_F(0x077f2b7a) /* 0.468547324 */, 18 },
+ /* 6562 */ { MAD_F(0x077f8f53) /* 0.468642545 */, 18 },
+ /* 6563 */ { MAD_F(0x077ff32d) /* 0.468737771 */, 18 },
+ /* 6564 */ { MAD_F(0x07805708) /* 0.468833002 */, 18 },
+ /* 6565 */ { MAD_F(0x0780bae5) /* 0.468928237 */, 18 },
+ /* 6566 */ { MAD_F(0x07811ec3) /* 0.469023478 */, 18 },
+ /* 6567 */ { MAD_F(0x078182a2) /* 0.469118723 */, 18 },
+ /* 6568 */ { MAD_F(0x0781e683) /* 0.469213973 */, 18 },
+ /* 6569 */ { MAD_F(0x07824a64) /* 0.469309228 */, 18 },
+ /* 6570 */ { MAD_F(0x0782ae47) /* 0.469404488 */, 18 },
+ /* 6571 */ { MAD_F(0x0783122c) /* 0.469499752 */, 18 },
+ /* 6572 */ { MAD_F(0x07837612) /* 0.469595022 */, 18 },
+ /* 6573 */ { MAD_F(0x0783d9f9) /* 0.469690296 */, 18 },
+ /* 6574 */ { MAD_F(0x07843de1) /* 0.469785575 */, 18 },
+ /* 6575 */ { MAD_F(0x0784a1ca) /* 0.469880859 */, 18 },
+
+ /* 6576 */ { MAD_F(0x078505b5) /* 0.469976148 */, 18 },
+ /* 6577 */ { MAD_F(0x078569a2) /* 0.470071442 */, 18 },
+ /* 6578 */ { MAD_F(0x0785cd8f) /* 0.470166740 */, 18 },
+ /* 6579 */ { MAD_F(0x0786317e) /* 0.470262043 */, 18 },
+ /* 6580 */ { MAD_F(0x0786956e) /* 0.470357351 */, 18 },
+ /* 6581 */ { MAD_F(0x0786f95f) /* 0.470452664 */, 18 },
+ /* 6582 */ { MAD_F(0x07875d52) /* 0.470547982 */, 18 },
+ /* 6583 */ { MAD_F(0x0787c146) /* 0.470643305 */, 18 },
+ /* 6584 */ { MAD_F(0x0788253b) /* 0.470738632 */, 18 },
+ /* 6585 */ { MAD_F(0x07888932) /* 0.470833964 */, 18 },
+ /* 6586 */ { MAD_F(0x0788ed2a) /* 0.470929301 */, 18 },
+ /* 6587 */ { MAD_F(0x07895123) /* 0.471024643 */, 18 },
+ /* 6588 */ { MAD_F(0x0789b51d) /* 0.471119990 */, 18 },
+ /* 6589 */ { MAD_F(0x078a1919) /* 0.471215341 */, 18 },
+ /* 6590 */ { MAD_F(0x078a7d16) /* 0.471310698 */, 18 },
+ /* 6591 */ { MAD_F(0x078ae114) /* 0.471406059 */, 18 },
+
+ /* 6592 */ { MAD_F(0x078b4514) /* 0.471501425 */, 18 },
+ /* 6593 */ { MAD_F(0x078ba915) /* 0.471596796 */, 18 },
+ /* 6594 */ { MAD_F(0x078c0d17) /* 0.471692171 */, 18 },
+ /* 6595 */ { MAD_F(0x078c711a) /* 0.471787552 */, 18 },
+ /* 6596 */ { MAD_F(0x078cd51f) /* 0.471882937 */, 18 },
+ /* 6597 */ { MAD_F(0x078d3925) /* 0.471978327 */, 18 },
+ /* 6598 */ { MAD_F(0x078d9d2d) /* 0.472073722 */, 18 },
+ /* 6599 */ { MAD_F(0x078e0135) /* 0.472169122 */, 18 },
+ /* 6600 */ { MAD_F(0x078e653f) /* 0.472264527 */, 18 },
+ /* 6601 */ { MAD_F(0x078ec94b) /* 0.472359936 */, 18 },
+ /* 6602 */ { MAD_F(0x078f2d57) /* 0.472455350 */, 18 },
+ /* 6603 */ { MAD_F(0x078f9165) /* 0.472550769 */, 18 },
+ /* 6604 */ { MAD_F(0x078ff574) /* 0.472646193 */, 18 },
+ /* 6605 */ { MAD_F(0x07905985) /* 0.472741622 */, 18 },
+ /* 6606 */ { MAD_F(0x0790bd96) /* 0.472837055 */, 18 },
+ /* 6607 */ { MAD_F(0x079121a9) /* 0.472932493 */, 18 },
+
+ /* 6608 */ { MAD_F(0x079185be) /* 0.473027937 */, 18 },
+ /* 6609 */ { MAD_F(0x0791e9d3) /* 0.473123384 */, 18 },
+ /* 6610 */ { MAD_F(0x07924dea) /* 0.473218837 */, 18 },
+ /* 6611 */ { MAD_F(0x0792b202) /* 0.473314295 */, 18 },
+ /* 6612 */ { MAD_F(0x0793161c) /* 0.473409757 */, 18 },
+ /* 6613 */ { MAD_F(0x07937a37) /* 0.473505224 */, 18 },
+ /* 6614 */ { MAD_F(0x0793de53) /* 0.473600696 */, 18 },
+ /* 6615 */ { MAD_F(0x07944270) /* 0.473696173 */, 18 },
+ /* 6616 */ { MAD_F(0x0794a68f) /* 0.473791655 */, 18 },
+ /* 6617 */ { MAD_F(0x07950aaf) /* 0.473887141 */, 18 },
+ /* 6618 */ { MAD_F(0x07956ed0) /* 0.473982632 */, 18 },
+ /* 6619 */ { MAD_F(0x0795d2f2) /* 0.474078128 */, 18 },
+ /* 6620 */ { MAD_F(0x07963716) /* 0.474173629 */, 18 },
+ /* 6621 */ { MAD_F(0x07969b3b) /* 0.474269135 */, 18 },
+ /* 6622 */ { MAD_F(0x0796ff62) /* 0.474364645 */, 18 },
+ /* 6623 */ { MAD_F(0x07976389) /* 0.474460161 */, 18 },
+
+ /* 6624 */ { MAD_F(0x0797c7b2) /* 0.474555681 */, 18 },
+ /* 6625 */ { MAD_F(0x07982bdd) /* 0.474651205 */, 18 },
+ /* 6626 */ { MAD_F(0x07989008) /* 0.474746735 */, 18 },
+ /* 6627 */ { MAD_F(0x0798f435) /* 0.474842270 */, 18 },
+ /* 6628 */ { MAD_F(0x07995863) /* 0.474937809 */, 18 },
+ /* 6629 */ { MAD_F(0x0799bc92) /* 0.475033353 */, 18 },
+ /* 6630 */ { MAD_F(0x079a20c3) /* 0.475128902 */, 18 },
+ /* 6631 */ { MAD_F(0x079a84f5) /* 0.475224456 */, 18 },
+ /* 6632 */ { MAD_F(0x079ae929) /* 0.475320014 */, 18 },
+ /* 6633 */ { MAD_F(0x079b4d5d) /* 0.475415578 */, 18 },
+ /* 6634 */ { MAD_F(0x079bb193) /* 0.475511146 */, 18 },
+ /* 6635 */ { MAD_F(0x079c15ca) /* 0.475606719 */, 18 },
+ /* 6636 */ { MAD_F(0x079c7a03) /* 0.475702296 */, 18 },
+ /* 6637 */ { MAD_F(0x079cde3c) /* 0.475797879 */, 18 },
+ /* 6638 */ { MAD_F(0x079d4277) /* 0.475893466 */, 18 },
+ /* 6639 */ { MAD_F(0x079da6b4) /* 0.475989058 */, 18 },
+
+ /* 6640 */ { MAD_F(0x079e0af1) /* 0.476084655 */, 18 },
+ /* 6641 */ { MAD_F(0x079e6f30) /* 0.476180257 */, 18 },
+ /* 6642 */ { MAD_F(0x079ed370) /* 0.476275863 */, 18 },
+ /* 6643 */ { MAD_F(0x079f37b2) /* 0.476371475 */, 18 },
+ /* 6644 */ { MAD_F(0x079f9bf5) /* 0.476467091 */, 18 },
+ /* 6645 */ { MAD_F(0x07a00039) /* 0.476562712 */, 18 },
+ /* 6646 */ { MAD_F(0x07a0647e) /* 0.476658338 */, 18 },
+ /* 6647 */ { MAD_F(0x07a0c8c5) /* 0.476753968 */, 18 },
+ /* 6648 */ { MAD_F(0x07a12d0c) /* 0.476849603 */, 18 },
+ /* 6649 */ { MAD_F(0x07a19156) /* 0.476945243 */, 18 },
+ /* 6650 */ { MAD_F(0x07a1f5a0) /* 0.477040888 */, 18 },
+ /* 6651 */ { MAD_F(0x07a259ec) /* 0.477136538 */, 18 },
+ /* 6652 */ { MAD_F(0x07a2be39) /* 0.477232193 */, 18 },
+ /* 6653 */ { MAD_F(0x07a32287) /* 0.477327852 */, 18 },
+ /* 6654 */ { MAD_F(0x07a386d7) /* 0.477423516 */, 18 },
+ /* 6655 */ { MAD_F(0x07a3eb28) /* 0.477519185 */, 18 },
+
+ /* 6656 */ { MAD_F(0x07a44f7a) /* 0.477614858 */, 18 },
+ /* 6657 */ { MAD_F(0x07a4b3ce) /* 0.477710537 */, 18 },
+ /* 6658 */ { MAD_F(0x07a51822) /* 0.477806220 */, 18 },
+ /* 6659 */ { MAD_F(0x07a57c78) /* 0.477901908 */, 18 },
+ /* 6660 */ { MAD_F(0x07a5e0d0) /* 0.477997601 */, 18 },
+ /* 6661 */ { MAD_F(0x07a64528) /* 0.478093299 */, 18 },
+ /* 6662 */ { MAD_F(0x07a6a982) /* 0.478189001 */, 18 },
+ /* 6663 */ { MAD_F(0x07a70ddd) /* 0.478284708 */, 18 },
+ /* 6664 */ { MAD_F(0x07a7723a) /* 0.478380420 */, 18 },
+ /* 6665 */ { MAD_F(0x07a7d698) /* 0.478476137 */, 18 },
+ /* 6666 */ { MAD_F(0x07a83af7) /* 0.478571858 */, 18 },
+ /* 6667 */ { MAD_F(0x07a89f57) /* 0.478667585 */, 18 },
+ /* 6668 */ { MAD_F(0x07a903b9) /* 0.478763316 */, 18 },
+ /* 6669 */ { MAD_F(0x07a9681c) /* 0.478859052 */, 18 },
+ /* 6670 */ { MAD_F(0x07a9cc80) /* 0.478954793 */, 18 },
+ /* 6671 */ { MAD_F(0x07aa30e5) /* 0.479050538 */, 18 },
+
+ /* 6672 */ { MAD_F(0x07aa954c) /* 0.479146288 */, 18 },
+ /* 6673 */ { MAD_F(0x07aaf9b4) /* 0.479242043 */, 18 },
+ /* 6674 */ { MAD_F(0x07ab5e1e) /* 0.479337803 */, 18 },
+ /* 6675 */ { MAD_F(0x07abc288) /* 0.479433568 */, 18 },
+ /* 6676 */ { MAD_F(0x07ac26f4) /* 0.479529337 */, 18 },
+ /* 6677 */ { MAD_F(0x07ac8b61) /* 0.479625111 */, 18 },
+ /* 6678 */ { MAD_F(0x07acefd0) /* 0.479720890 */, 18 },
+ /* 6679 */ { MAD_F(0x07ad543f) /* 0.479816674 */, 18 },
+ /* 6680 */ { MAD_F(0x07adb8b0) /* 0.479912463 */, 18 },
+ /* 6681 */ { MAD_F(0x07ae1d23) /* 0.480008256 */, 18 },
+ /* 6682 */ { MAD_F(0x07ae8196) /* 0.480104054 */, 18 },
+ /* 6683 */ { MAD_F(0x07aee60b) /* 0.480199857 */, 18 },
+ /* 6684 */ { MAD_F(0x07af4a81) /* 0.480295664 */, 18 },
+ /* 6685 */ { MAD_F(0x07afaef9) /* 0.480391477 */, 18 },
+ /* 6686 */ { MAD_F(0x07b01372) /* 0.480487294 */, 18 },
+ /* 6687 */ { MAD_F(0x07b077ec) /* 0.480583116 */, 18 },
+
+ /* 6688 */ { MAD_F(0x07b0dc67) /* 0.480678943 */, 18 },
+ /* 6689 */ { MAD_F(0x07b140e4) /* 0.480774774 */, 18 },
+ /* 6690 */ { MAD_F(0x07b1a561) /* 0.480870611 */, 18 },
+ /* 6691 */ { MAD_F(0x07b209e1) /* 0.480966452 */, 18 },
+ /* 6692 */ { MAD_F(0x07b26e61) /* 0.481062298 */, 18 },
+ /* 6693 */ { MAD_F(0x07b2d2e3) /* 0.481158148 */, 18 },
+ /* 6694 */ { MAD_F(0x07b33766) /* 0.481254004 */, 18 },
+ /* 6695 */ { MAD_F(0x07b39bea) /* 0.481349864 */, 18 },
+ /* 6696 */ { MAD_F(0x07b4006f) /* 0.481445729 */, 18 },
+ /* 6697 */ { MAD_F(0x07b464f6) /* 0.481541598 */, 18 },
+ /* 6698 */ { MAD_F(0x07b4c97e) /* 0.481637473 */, 18 },
+ /* 6699 */ { MAD_F(0x07b52e08) /* 0.481733352 */, 18 },
+ /* 6700 */ { MAD_F(0x07b59292) /* 0.481829236 */, 18 },
+ /* 6701 */ { MAD_F(0x07b5f71e) /* 0.481925125 */, 18 },
+ /* 6702 */ { MAD_F(0x07b65bac) /* 0.482021019 */, 18 },
+ /* 6703 */ { MAD_F(0x07b6c03a) /* 0.482116917 */, 18 },
+
+ /* 6704 */ { MAD_F(0x07b724ca) /* 0.482212820 */, 18 },
+ /* 6705 */ { MAD_F(0x07b7895b) /* 0.482308728 */, 18 },
+ /* 6706 */ { MAD_F(0x07b7eded) /* 0.482404640 */, 18 },
+ /* 6707 */ { MAD_F(0x07b85281) /* 0.482500558 */, 18 },
+ /* 6708 */ { MAD_F(0x07b8b716) /* 0.482596480 */, 18 },
+ /* 6709 */ { MAD_F(0x07b91bac) /* 0.482692407 */, 18 },
+ /* 6710 */ { MAD_F(0x07b98044) /* 0.482788339 */, 18 },
+ /* 6711 */ { MAD_F(0x07b9e4dc) /* 0.482884275 */, 18 },
+ /* 6712 */ { MAD_F(0x07ba4976) /* 0.482980216 */, 18 },
+ /* 6713 */ { MAD_F(0x07baae12) /* 0.483076162 */, 18 },
+ /* 6714 */ { MAD_F(0x07bb12ae) /* 0.483172113 */, 18 },
+ /* 6715 */ { MAD_F(0x07bb774c) /* 0.483268069 */, 18 },
+ /* 6716 */ { MAD_F(0x07bbdbeb) /* 0.483364029 */, 18 },
+ /* 6717 */ { MAD_F(0x07bc408c) /* 0.483459994 */, 18 },
+ /* 6718 */ { MAD_F(0x07bca52d) /* 0.483555964 */, 18 },
+ /* 6719 */ { MAD_F(0x07bd09d0) /* 0.483651939 */, 18 },
+
+ /* 6720 */ { MAD_F(0x07bd6e75) /* 0.483747918 */, 18 },
+ /* 6721 */ { MAD_F(0x07bdd31a) /* 0.483843902 */, 18 },
+ /* 6722 */ { MAD_F(0x07be37c1) /* 0.483939891 */, 18 },
+ /* 6723 */ { MAD_F(0x07be9c69) /* 0.484035885 */, 18 },
+ /* 6724 */ { MAD_F(0x07bf0113) /* 0.484131883 */, 18 },
+ /* 6725 */ { MAD_F(0x07bf65bd) /* 0.484227886 */, 18 },
+ /* 6726 */ { MAD_F(0x07bfca69) /* 0.484323894 */, 18 },
+ /* 6727 */ { MAD_F(0x07c02f16) /* 0.484419907 */, 18 },
+ /* 6728 */ { MAD_F(0x07c093c5) /* 0.484515924 */, 18 },
+ /* 6729 */ { MAD_F(0x07c0f875) /* 0.484611946 */, 18 },
+ /* 6730 */ { MAD_F(0x07c15d26) /* 0.484707973 */, 18 },
+ /* 6731 */ { MAD_F(0x07c1c1d8) /* 0.484804005 */, 18 },
+ /* 6732 */ { MAD_F(0x07c2268b) /* 0.484900041 */, 18 },
+ /* 6733 */ { MAD_F(0x07c28b40) /* 0.484996083 */, 18 },
+ /* 6734 */ { MAD_F(0x07c2eff6) /* 0.485092128 */, 18 },
+ /* 6735 */ { MAD_F(0x07c354ae) /* 0.485188179 */, 18 },
+
+ /* 6736 */ { MAD_F(0x07c3b967) /* 0.485284235 */, 18 },
+ /* 6737 */ { MAD_F(0x07c41e21) /* 0.485380295 */, 18 },
+ /* 6738 */ { MAD_F(0x07c482dc) /* 0.485476360 */, 18 },
+ /* 6739 */ { MAD_F(0x07c4e798) /* 0.485572430 */, 18 },
+ /* 6740 */ { MAD_F(0x07c54c56) /* 0.485668504 */, 18 },
+ /* 6741 */ { MAD_F(0x07c5b115) /* 0.485764583 */, 18 },
+ /* 6742 */ { MAD_F(0x07c615d6) /* 0.485860667 */, 18 },
+ /* 6743 */ { MAD_F(0x07c67a97) /* 0.485956756 */, 18 },
+ /* 6744 */ { MAD_F(0x07c6df5a) /* 0.486052849 */, 18 },
+ /* 6745 */ { MAD_F(0x07c7441e) /* 0.486148948 */, 18 },
+ /* 6746 */ { MAD_F(0x07c7a8e4) /* 0.486245051 */, 18 },
+ /* 6747 */ { MAD_F(0x07c80daa) /* 0.486341158 */, 18 },
+ /* 6748 */ { MAD_F(0x07c87272) /* 0.486437271 */, 18 },
+ /* 6749 */ { MAD_F(0x07c8d73c) /* 0.486533388 */, 18 },
+ /* 6750 */ { MAD_F(0x07c93c06) /* 0.486629510 */, 18 },
+ /* 6751 */ { MAD_F(0x07c9a0d2) /* 0.486725637 */, 18 },
+
+ /* 6752 */ { MAD_F(0x07ca059f) /* 0.486821768 */, 18 },
+ /* 6753 */ { MAD_F(0x07ca6a6d) /* 0.486917905 */, 18 },
+ /* 6754 */ { MAD_F(0x07cacf3d) /* 0.487014045 */, 18 },
+ /* 6755 */ { MAD_F(0x07cb340e) /* 0.487110191 */, 18 },
+ /* 6756 */ { MAD_F(0x07cb98e0) /* 0.487206342 */, 18 },
+ /* 6757 */ { MAD_F(0x07cbfdb4) /* 0.487302497 */, 18 },
+ /* 6758 */ { MAD_F(0x07cc6288) /* 0.487398657 */, 18 },
+ /* 6759 */ { MAD_F(0x07ccc75e) /* 0.487494821 */, 18 },
+ /* 6760 */ { MAD_F(0x07cd2c36) /* 0.487590991 */, 18 },
+ /* 6761 */ { MAD_F(0x07cd910e) /* 0.487687165 */, 18 },
+ /* 6762 */ { MAD_F(0x07cdf5e8) /* 0.487783344 */, 18 },
+ /* 6763 */ { MAD_F(0x07ce5ac3) /* 0.487879528 */, 18 },
+ /* 6764 */ { MAD_F(0x07cebfa0) /* 0.487975716 */, 18 },
+ /* 6765 */ { MAD_F(0x07cf247d) /* 0.488071909 */, 18 },
+ /* 6766 */ { MAD_F(0x07cf895c) /* 0.488168107 */, 18 },
+ /* 6767 */ { MAD_F(0x07cfee3c) /* 0.488264310 */, 18 },
+
+ /* 6768 */ { MAD_F(0x07d0531e) /* 0.488360517 */, 18 },
+ /* 6769 */ { MAD_F(0x07d0b801) /* 0.488456729 */, 18 },
+ /* 6770 */ { MAD_F(0x07d11ce5) /* 0.488552946 */, 18 },
+ /* 6771 */ { MAD_F(0x07d181ca) /* 0.488649167 */, 18 },
+ /* 6772 */ { MAD_F(0x07d1e6b0) /* 0.488745394 */, 18 },
+ /* 6773 */ { MAD_F(0x07d24b98) /* 0.488841625 */, 18 },
+ /* 6774 */ { MAD_F(0x07d2b081) /* 0.488937860 */, 18 },
+ /* 6775 */ { MAD_F(0x07d3156c) /* 0.489034101 */, 18 },
+ /* 6776 */ { MAD_F(0x07d37a57) /* 0.489130346 */, 18 },
+ /* 6777 */ { MAD_F(0x07d3df44) /* 0.489226596 */, 18 },
+ /* 6778 */ { MAD_F(0x07d44432) /* 0.489322851 */, 18 },
+ /* 6779 */ { MAD_F(0x07d4a922) /* 0.489419110 */, 18 },
+ /* 6780 */ { MAD_F(0x07d50e13) /* 0.489515375 */, 18 },
+ /* 6781 */ { MAD_F(0x07d57305) /* 0.489611643 */, 18 },
+ /* 6782 */ { MAD_F(0x07d5d7f8) /* 0.489707917 */, 18 },
+ /* 6783 */ { MAD_F(0x07d63cec) /* 0.489804195 */, 18 },
+
+ /* 6784 */ { MAD_F(0x07d6a1e2) /* 0.489900479 */, 18 },
+ /* 6785 */ { MAD_F(0x07d706d9) /* 0.489996766 */, 18 },
+ /* 6786 */ { MAD_F(0x07d76bd2) /* 0.490093059 */, 18 },
+ /* 6787 */ { MAD_F(0x07d7d0cb) /* 0.490189356 */, 18 },
+ /* 6788 */ { MAD_F(0x07d835c6) /* 0.490285658 */, 18 },
+ /* 6789 */ { MAD_F(0x07d89ac2) /* 0.490381965 */, 18 },
+ /* 6790 */ { MAD_F(0x07d8ffc0) /* 0.490478277 */, 18 },
+ /* 6791 */ { MAD_F(0x07d964be) /* 0.490574593 */, 18 },
+ /* 6792 */ { MAD_F(0x07d9c9be) /* 0.490670914 */, 18 },
+ /* 6793 */ { MAD_F(0x07da2ebf) /* 0.490767239 */, 18 },
+ /* 6794 */ { MAD_F(0x07da93c2) /* 0.490863570 */, 18 },
+ /* 6795 */ { MAD_F(0x07daf8c6) /* 0.490959905 */, 18 },
+ /* 6796 */ { MAD_F(0x07db5dcb) /* 0.491056245 */, 18 },
+ /* 6797 */ { MAD_F(0x07dbc2d1) /* 0.491152589 */, 18 },
+ /* 6798 */ { MAD_F(0x07dc27d9) /* 0.491248939 */, 18 },
+ /* 6799 */ { MAD_F(0x07dc8ce1) /* 0.491345293 */, 18 },
+
+ /* 6800 */ { MAD_F(0x07dcf1ec) /* 0.491441651 */, 18 },
+ /* 6801 */ { MAD_F(0x07dd56f7) /* 0.491538015 */, 18 },
+ /* 6802 */ { MAD_F(0x07ddbc04) /* 0.491634383 */, 18 },
+ /* 6803 */ { MAD_F(0x07de2111) /* 0.491730756 */, 18 },
+ /* 6804 */ { MAD_F(0x07de8621) /* 0.491827134 */, 18 },
+ /* 6805 */ { MAD_F(0x07deeb31) /* 0.491923516 */, 18 },
+ /* 6806 */ { MAD_F(0x07df5043) /* 0.492019903 */, 18 },
+ /* 6807 */ { MAD_F(0x07dfb556) /* 0.492116295 */, 18 },
+ /* 6808 */ { MAD_F(0x07e01a6a) /* 0.492212691 */, 18 },
+ /* 6809 */ { MAD_F(0x07e07f80) /* 0.492309093 */, 18 },
+ /* 6810 */ { MAD_F(0x07e0e496) /* 0.492405499 */, 18 },
+ /* 6811 */ { MAD_F(0x07e149ae) /* 0.492501909 */, 18 },
+ /* 6812 */ { MAD_F(0x07e1aec8) /* 0.492598325 */, 18 },
+ /* 6813 */ { MAD_F(0x07e213e2) /* 0.492694745 */, 18 },
+ /* 6814 */ { MAD_F(0x07e278fe) /* 0.492791170 */, 18 },
+ /* 6815 */ { MAD_F(0x07e2de1b) /* 0.492887599 */, 18 },
+
+ /* 6816 */ { MAD_F(0x07e3433a) /* 0.492984033 */, 18 },
+ /* 6817 */ { MAD_F(0x07e3a859) /* 0.493080472 */, 18 },
+ /* 6818 */ { MAD_F(0x07e40d7a) /* 0.493176916 */, 18 },
+ /* 6819 */ { MAD_F(0x07e4729c) /* 0.493273365 */, 18 },
+ /* 6820 */ { MAD_F(0x07e4d7c0) /* 0.493369818 */, 18 },
+ /* 6821 */ { MAD_F(0x07e53ce4) /* 0.493466275 */, 18 },
+ /* 6822 */ { MAD_F(0x07e5a20a) /* 0.493562738 */, 18 },
+ /* 6823 */ { MAD_F(0x07e60732) /* 0.493659205 */, 18 },
+ /* 6824 */ { MAD_F(0x07e66c5a) /* 0.493755677 */, 18 },
+ /* 6825 */ { MAD_F(0x07e6d184) /* 0.493852154 */, 18 },
+ /* 6826 */ { MAD_F(0x07e736af) /* 0.493948635 */, 18 },
+ /* 6827 */ { MAD_F(0x07e79bdb) /* 0.494045122 */, 18 },
+ /* 6828 */ { MAD_F(0x07e80109) /* 0.494141612 */, 18 },
+ /* 6829 */ { MAD_F(0x07e86638) /* 0.494238108 */, 18 },
+ /* 6830 */ { MAD_F(0x07e8cb68) /* 0.494334608 */, 18 },
+ /* 6831 */ { MAD_F(0x07e93099) /* 0.494431113 */, 18 },
+
+ /* 6832 */ { MAD_F(0x07e995cc) /* 0.494527623 */, 18 },
+ /* 6833 */ { MAD_F(0x07e9fb00) /* 0.494624137 */, 18 },
+ /* 6834 */ { MAD_F(0x07ea6035) /* 0.494720656 */, 18 },
+ /* 6835 */ { MAD_F(0x07eac56b) /* 0.494817180 */, 18 },
+ /* 6836 */ { MAD_F(0x07eb2aa3) /* 0.494913709 */, 18 },
+ /* 6837 */ { MAD_F(0x07eb8fdc) /* 0.495010242 */, 18 },
+ /* 6838 */ { MAD_F(0x07ebf516) /* 0.495106780 */, 18 },
+ /* 6839 */ { MAD_F(0x07ec5a51) /* 0.495203322 */, 18 },
+ /* 6840 */ { MAD_F(0x07ecbf8e) /* 0.495299870 */, 18 },
+ /* 6841 */ { MAD_F(0x07ed24cc) /* 0.495396422 */, 18 },
+ /* 6842 */ { MAD_F(0x07ed8a0b) /* 0.495492978 */, 18 },
+ /* 6843 */ { MAD_F(0x07edef4c) /* 0.495589540 */, 18 },
+ /* 6844 */ { MAD_F(0x07ee548e) /* 0.495686106 */, 18 },
+ /* 6845 */ { MAD_F(0x07eeb9d1) /* 0.495782677 */, 18 },
+ /* 6846 */ { MAD_F(0x07ef1f15) /* 0.495879252 */, 18 },
+ /* 6847 */ { MAD_F(0x07ef845b) /* 0.495975833 */, 18 },
+
+ /* 6848 */ { MAD_F(0x07efe9a1) /* 0.496072418 */, 18 },
+ /* 6849 */ { MAD_F(0x07f04ee9) /* 0.496169007 */, 18 },
+ /* 6850 */ { MAD_F(0x07f0b433) /* 0.496265602 */, 18 },
+ /* 6851 */ { MAD_F(0x07f1197d) /* 0.496362201 */, 18 },
+ /* 6852 */ { MAD_F(0x07f17ec9) /* 0.496458804 */, 18 },
+ /* 6853 */ { MAD_F(0x07f1e416) /* 0.496555413 */, 18 },
+ /* 6854 */ { MAD_F(0x07f24965) /* 0.496652026 */, 18 },
+ /* 6855 */ { MAD_F(0x07f2aeb5) /* 0.496748644 */, 18 },
+ /* 6856 */ { MAD_F(0x07f31405) /* 0.496845266 */, 18 },
+ /* 6857 */ { MAD_F(0x07f37958) /* 0.496941894 */, 18 },
+ /* 6858 */ { MAD_F(0x07f3deab) /* 0.497038526 */, 18 },
+ /* 6859 */ { MAD_F(0x07f44400) /* 0.497135162 */, 18 },
+ /* 6860 */ { MAD_F(0x07f4a956) /* 0.497231804 */, 18 },
+ /* 6861 */ { MAD_F(0x07f50ead) /* 0.497328450 */, 18 },
+ /* 6862 */ { MAD_F(0x07f57405) /* 0.497425100 */, 18 },
+ /* 6863 */ { MAD_F(0x07f5d95f) /* 0.497521756 */, 18 },
+
+ /* 6864 */ { MAD_F(0x07f63eba) /* 0.497618416 */, 18 },
+ /* 6865 */ { MAD_F(0x07f6a416) /* 0.497715081 */, 18 },
+ /* 6866 */ { MAD_F(0x07f70974) /* 0.497811750 */, 18 },
+ /* 6867 */ { MAD_F(0x07f76ed3) /* 0.497908425 */, 18 },
+ /* 6868 */ { MAD_F(0x07f7d433) /* 0.498005103 */, 18 },
+ /* 6869 */ { MAD_F(0x07f83994) /* 0.498101787 */, 18 },
+ /* 6870 */ { MAD_F(0x07f89ef7) /* 0.498198475 */, 18 },
+ /* 6871 */ { MAD_F(0x07f9045a) /* 0.498295168 */, 18 },
+ /* 6872 */ { MAD_F(0x07f969c0) /* 0.498391866 */, 18 },
+ /* 6873 */ { MAD_F(0x07f9cf26) /* 0.498488568 */, 18 },
+ /* 6874 */ { MAD_F(0x07fa348e) /* 0.498585275 */, 18 },
+ /* 6875 */ { MAD_F(0x07fa99f6) /* 0.498681987 */, 18 },
+ /* 6876 */ { MAD_F(0x07faff60) /* 0.498778704 */, 18 },
+ /* 6877 */ { MAD_F(0x07fb64cc) /* 0.498875425 */, 18 },
+ /* 6878 */ { MAD_F(0x07fbca38) /* 0.498972150 */, 18 },
+ /* 6879 */ { MAD_F(0x07fc2fa6) /* 0.499068881 */, 18 },
+
+ /* 6880 */ { MAD_F(0x07fc9516) /* 0.499165616 */, 18 },
+ /* 6881 */ { MAD_F(0x07fcfa86) /* 0.499262356 */, 18 },
+ /* 6882 */ { MAD_F(0x07fd5ff8) /* 0.499359101 */, 18 },
+ /* 6883 */ { MAD_F(0x07fdc56b) /* 0.499455850 */, 18 },
+ /* 6884 */ { MAD_F(0x07fe2adf) /* 0.499552604 */, 18 },
+ /* 6885 */ { MAD_F(0x07fe9054) /* 0.499649362 */, 18 },
+ /* 6886 */ { MAD_F(0x07fef5cb) /* 0.499746126 */, 18 },
+ /* 6887 */ { MAD_F(0x07ff5b43) /* 0.499842894 */, 18 },
+ /* 6888 */ { MAD_F(0x07ffc0bc) /* 0.499939666 */, 18 },
+ /* 6889 */ { MAD_F(0x0400131b) /* 0.250018222 */, 19 },
+ /* 6890 */ { MAD_F(0x040045d9) /* 0.250066613 */, 19 },
+ /* 6891 */ { MAD_F(0x04007897) /* 0.250115006 */, 19 },
+ /* 6892 */ { MAD_F(0x0400ab57) /* 0.250163402 */, 19 },
+ /* 6893 */ { MAD_F(0x0400de16) /* 0.250211800 */, 19 },
+ /* 6894 */ { MAD_F(0x040110d7) /* 0.250260200 */, 19 },
+ /* 6895 */ { MAD_F(0x04014398) /* 0.250308603 */, 19 },
+
+ /* 6896 */ { MAD_F(0x04017659) /* 0.250357008 */, 19 },
+ /* 6897 */ { MAD_F(0x0401a91c) /* 0.250405415 */, 19 },
+ /* 6898 */ { MAD_F(0x0401dbdf) /* 0.250453825 */, 19 },
+ /* 6899 */ { MAD_F(0x04020ea2) /* 0.250502237 */, 19 },
+ /* 6900 */ { MAD_F(0x04024166) /* 0.250550652 */, 19 },
+ /* 6901 */ { MAD_F(0x0402742b) /* 0.250599068 */, 19 },
+ /* 6902 */ { MAD_F(0x0402a6f0) /* 0.250647488 */, 19 },
+ /* 6903 */ { MAD_F(0x0402d9b6) /* 0.250695909 */, 19 },
+ /* 6904 */ { MAD_F(0x04030c7d) /* 0.250744333 */, 19 },
+ /* 6905 */ { MAD_F(0x04033f44) /* 0.250792759 */, 19 },
+ /* 6906 */ { MAD_F(0x0403720c) /* 0.250841187 */, 19 },
+ /* 6907 */ { MAD_F(0x0403a4d5) /* 0.250889618 */, 19 },
+ /* 6908 */ { MAD_F(0x0403d79e) /* 0.250938051 */, 19 },
+ /* 6909 */ { MAD_F(0x04040a68) /* 0.250986487 */, 19 },
+ /* 6910 */ { MAD_F(0x04043d32) /* 0.251034924 */, 19 },
+ /* 6911 */ { MAD_F(0x04046ffd) /* 0.251083365 */, 19 },
+
+ /* 6912 */ { MAD_F(0x0404a2c9) /* 0.251131807 */, 19 },
+ /* 6913 */ { MAD_F(0x0404d595) /* 0.251180252 */, 19 },
+ /* 6914 */ { MAD_F(0x04050862) /* 0.251228699 */, 19 },
+ /* 6915 */ { MAD_F(0x04053b30) /* 0.251277148 */, 19 },
+ /* 6916 */ { MAD_F(0x04056dfe) /* 0.251325600 */, 19 },
+ /* 6917 */ { MAD_F(0x0405a0cd) /* 0.251374054 */, 19 },
+ /* 6918 */ { MAD_F(0x0405d39c) /* 0.251422511 */, 19 },
+ /* 6919 */ { MAD_F(0x0406066c) /* 0.251470970 */, 19 },
+ /* 6920 */ { MAD_F(0x0406393d) /* 0.251519431 */, 19 },
+ /* 6921 */ { MAD_F(0x04066c0e) /* 0.251567894 */, 19 },
+ /* 6922 */ { MAD_F(0x04069ee0) /* 0.251616360 */, 19 },
+ /* 6923 */ { MAD_F(0x0406d1b3) /* 0.251664828 */, 19 },
+ /* 6924 */ { MAD_F(0x04070486) /* 0.251713299 */, 19 },
+ /* 6925 */ { MAD_F(0x0407375a) /* 0.251761772 */, 19 },
+ /* 6926 */ { MAD_F(0x04076a2e) /* 0.251810247 */, 19 },
+ /* 6927 */ { MAD_F(0x04079d03) /* 0.251858724 */, 19 },
+
+ /* 6928 */ { MAD_F(0x0407cfd9) /* 0.251907204 */, 19 },
+ /* 6929 */ { MAD_F(0x040802af) /* 0.251955686 */, 19 },
+ /* 6930 */ { MAD_F(0x04083586) /* 0.252004171 */, 19 },
+ /* 6931 */ { MAD_F(0x0408685e) /* 0.252052658 */, 19 },
+ /* 6932 */ { MAD_F(0x04089b36) /* 0.252101147 */, 19 },
+ /* 6933 */ { MAD_F(0x0408ce0f) /* 0.252149638 */, 19 },
+ /* 6934 */ { MAD_F(0x040900e8) /* 0.252198132 */, 19 },
+ /* 6935 */ { MAD_F(0x040933c2) /* 0.252246628 */, 19 },
+ /* 6936 */ { MAD_F(0x0409669d) /* 0.252295127 */, 19 },
+ /* 6937 */ { MAD_F(0x04099978) /* 0.252343627 */, 19 },
+ /* 6938 */ { MAD_F(0x0409cc54) /* 0.252392131 */, 19 },
+ /* 6939 */ { MAD_F(0x0409ff31) /* 0.252440636 */, 19 },
+ /* 6940 */ { MAD_F(0x040a320e) /* 0.252489144 */, 19 },
+ /* 6941 */ { MAD_F(0x040a64ec) /* 0.252537654 */, 19 },
+ /* 6942 */ { MAD_F(0x040a97cb) /* 0.252586166 */, 19 },
+ /* 6943 */ { MAD_F(0x040acaaa) /* 0.252634681 */, 19 },
+
+ /* 6944 */ { MAD_F(0x040afd89) /* 0.252683198 */, 19 },
+ /* 6945 */ { MAD_F(0x040b306a) /* 0.252731718 */, 19 },
+ /* 6946 */ { MAD_F(0x040b634b) /* 0.252780240 */, 19 },
+ /* 6947 */ { MAD_F(0x040b962c) /* 0.252828764 */, 19 },
+ /* 6948 */ { MAD_F(0x040bc90e) /* 0.252877290 */, 19 },
+ /* 6949 */ { MAD_F(0x040bfbf1) /* 0.252925819 */, 19 },
+ /* 6950 */ { MAD_F(0x040c2ed5) /* 0.252974350 */, 19 },
+ /* 6951 */ { MAD_F(0x040c61b9) /* 0.253022883 */, 19 },
+ /* 6952 */ { MAD_F(0x040c949e) /* 0.253071419 */, 19 },
+ /* 6953 */ { MAD_F(0x040cc783) /* 0.253119957 */, 19 },
+ /* 6954 */ { MAD_F(0x040cfa69) /* 0.253168498 */, 19 },
+ /* 6955 */ { MAD_F(0x040d2d4f) /* 0.253217040 */, 19 },
+ /* 6956 */ { MAD_F(0x040d6037) /* 0.253265585 */, 19 },
+ /* 6957 */ { MAD_F(0x040d931e) /* 0.253314133 */, 19 },
+ /* 6958 */ { MAD_F(0x040dc607) /* 0.253362682 */, 19 },
+ /* 6959 */ { MAD_F(0x040df8f0) /* 0.253411234 */, 19 },
+
+ /* 6960 */ { MAD_F(0x040e2bda) /* 0.253459789 */, 19 },
+ /* 6961 */ { MAD_F(0x040e5ec4) /* 0.253508345 */, 19 },
+ /* 6962 */ { MAD_F(0x040e91af) /* 0.253556904 */, 19 },
+ /* 6963 */ { MAD_F(0x040ec49b) /* 0.253605466 */, 19 },
+ /* 6964 */ { MAD_F(0x040ef787) /* 0.253654029 */, 19 },
+ /* 6965 */ { MAD_F(0x040f2a74) /* 0.253702595 */, 19 },
+ /* 6966 */ { MAD_F(0x040f5d61) /* 0.253751164 */, 19 },
+ /* 6967 */ { MAD_F(0x040f904f) /* 0.253799734 */, 19 },
+ /* 6968 */ { MAD_F(0x040fc33e) /* 0.253848307 */, 19 },
+ /* 6969 */ { MAD_F(0x040ff62d) /* 0.253896883 */, 19 },
+ /* 6970 */ { MAD_F(0x0410291d) /* 0.253945460 */, 19 },
+ /* 6971 */ { MAD_F(0x04105c0e) /* 0.253994040 */, 19 },
+ /* 6972 */ { MAD_F(0x04108eff) /* 0.254042622 */, 19 },
+ /* 6973 */ { MAD_F(0x0410c1f1) /* 0.254091207 */, 19 },
+ /* 6974 */ { MAD_F(0x0410f4e3) /* 0.254139794 */, 19 },
+ /* 6975 */ { MAD_F(0x041127d6) /* 0.254188383 */, 19 },
+
+ /* 6976 */ { MAD_F(0x04115aca) /* 0.254236974 */, 19 },
+ /* 6977 */ { MAD_F(0x04118dbe) /* 0.254285568 */, 19 },
+ /* 6978 */ { MAD_F(0x0411c0b3) /* 0.254334165 */, 19 },
+ /* 6979 */ { MAD_F(0x0411f3a9) /* 0.254382763 */, 19 },
+ /* 6980 */ { MAD_F(0x0412269f) /* 0.254431364 */, 19 },
+ /* 6981 */ { MAD_F(0x04125996) /* 0.254479967 */, 19 },
+ /* 6982 */ { MAD_F(0x04128c8d) /* 0.254528572 */, 19 },
+ /* 6983 */ { MAD_F(0x0412bf85) /* 0.254577180 */, 19 },
+ /* 6984 */ { MAD_F(0x0412f27e) /* 0.254625790 */, 19 },
+ /* 6985 */ { MAD_F(0x04132577) /* 0.254674403 */, 19 },
+ /* 6986 */ { MAD_F(0x04135871) /* 0.254723017 */, 19 },
+ /* 6987 */ { MAD_F(0x04138b6c) /* 0.254771635 */, 19 },
+ /* 6988 */ { MAD_F(0x0413be67) /* 0.254820254 */, 19 },
+ /* 6989 */ { MAD_F(0x0413f163) /* 0.254868876 */, 19 },
+ /* 6990 */ { MAD_F(0x0414245f) /* 0.254917500 */, 19 },
+ /* 6991 */ { MAD_F(0x0414575c) /* 0.254966126 */, 19 },
+
+ /* 6992 */ { MAD_F(0x04148a5a) /* 0.255014755 */, 19 },
+ /* 6993 */ { MAD_F(0x0414bd58) /* 0.255063386 */, 19 },
+ /* 6994 */ { MAD_F(0x0414f057) /* 0.255112019 */, 19 },
+ /* 6995 */ { MAD_F(0x04152356) /* 0.255160655 */, 19 },
+ /* 6996 */ { MAD_F(0x04155657) /* 0.255209292 */, 19 },
+ /* 6997 */ { MAD_F(0x04158957) /* 0.255257933 */, 19 },
+ /* 6998 */ { MAD_F(0x0415bc59) /* 0.255306575 */, 19 },
+ /* 6999 */ { MAD_F(0x0415ef5b) /* 0.255355220 */, 19 },
+ /* 7000 */ { MAD_F(0x0416225d) /* 0.255403867 */, 19 },
+ /* 7001 */ { MAD_F(0x04165561) /* 0.255452517 */, 19 },
+ /* 7002 */ { MAD_F(0x04168864) /* 0.255501169 */, 19 },
+ /* 7003 */ { MAD_F(0x0416bb69) /* 0.255549823 */, 19 },
+ /* 7004 */ { MAD_F(0x0416ee6e) /* 0.255598479 */, 19 },
+ /* 7005 */ { MAD_F(0x04172174) /* 0.255647138 */, 19 },
+ /* 7006 */ { MAD_F(0x0417547a) /* 0.255695799 */, 19 },
+ /* 7007 */ { MAD_F(0x04178781) /* 0.255744463 */, 19 },
+
+ /* 7008 */ { MAD_F(0x0417ba89) /* 0.255793128 */, 19 },
+ /* 7009 */ { MAD_F(0x0417ed91) /* 0.255841796 */, 19 },
+ /* 7010 */ { MAD_F(0x0418209a) /* 0.255890467 */, 19 },
+ /* 7011 */ { MAD_F(0x041853a3) /* 0.255939139 */, 19 },
+ /* 7012 */ { MAD_F(0x041886ad) /* 0.255987814 */, 19 },
+ /* 7013 */ { MAD_F(0x0418b9b8) /* 0.256036492 */, 19 },
+ /* 7014 */ { MAD_F(0x0418ecc3) /* 0.256085171 */, 19 },
+ /* 7015 */ { MAD_F(0x04191fcf) /* 0.256133853 */, 19 },
+ /* 7016 */ { MAD_F(0x041952dc) /* 0.256182537 */, 19 },
+ /* 7017 */ { MAD_F(0x041985e9) /* 0.256231224 */, 19 },
+ /* 7018 */ { MAD_F(0x0419b8f7) /* 0.256279913 */, 19 },
+ /* 7019 */ { MAD_F(0x0419ec05) /* 0.256328604 */, 19 },
+ /* 7020 */ { MAD_F(0x041a1f15) /* 0.256377297 */, 19 },
+ /* 7021 */ { MAD_F(0x041a5224) /* 0.256425993 */, 19 },
+ /* 7022 */ { MAD_F(0x041a8534) /* 0.256474691 */, 19 },
+ /* 7023 */ { MAD_F(0x041ab845) /* 0.256523392 */, 19 },
+
+ /* 7024 */ { MAD_F(0x041aeb57) /* 0.256572095 */, 19 },
+ /* 7025 */ { MAD_F(0x041b1e69) /* 0.256620800 */, 19 },
+ /* 7026 */ { MAD_F(0x041b517c) /* 0.256669507 */, 19 },
+ /* 7027 */ { MAD_F(0x041b848f) /* 0.256718217 */, 19 },
+ /* 7028 */ { MAD_F(0x041bb7a3) /* 0.256766929 */, 19 },
+ /* 7029 */ { MAD_F(0x041beab8) /* 0.256815643 */, 19 },
+ /* 7030 */ { MAD_F(0x041c1dcd) /* 0.256864359 */, 19 },
+ /* 7031 */ { MAD_F(0x041c50e3) /* 0.256913078 */, 19 },
+ /* 7032 */ { MAD_F(0x041c83fa) /* 0.256961800 */, 19 },
+ /* 7033 */ { MAD_F(0x041cb711) /* 0.257010523 */, 19 },
+ /* 7034 */ { MAD_F(0x041cea28) /* 0.257059249 */, 19 },
+ /* 7035 */ { MAD_F(0x041d1d41) /* 0.257107977 */, 19 },
+ /* 7036 */ { MAD_F(0x041d505a) /* 0.257156708 */, 19 },
+ /* 7037 */ { MAD_F(0x041d8373) /* 0.257205440 */, 19 },
+ /* 7038 */ { MAD_F(0x041db68e) /* 0.257254175 */, 19 },
+ /* 7039 */ { MAD_F(0x041de9a8) /* 0.257302913 */, 19 },
+
+ /* 7040 */ { MAD_F(0x041e1cc4) /* 0.257351652 */, 19 },
+ /* 7041 */ { MAD_F(0x041e4fe0) /* 0.257400394 */, 19 },
+ /* 7042 */ { MAD_F(0x041e82fd) /* 0.257449139 */, 19 },
+ /* 7043 */ { MAD_F(0x041eb61a) /* 0.257497885 */, 19 },
+ /* 7044 */ { MAD_F(0x041ee938) /* 0.257546634 */, 19 },
+ /* 7045 */ { MAD_F(0x041f1c57) /* 0.257595386 */, 19 },
+ /* 7046 */ { MAD_F(0x041f4f76) /* 0.257644139 */, 19 },
+ /* 7047 */ { MAD_F(0x041f8296) /* 0.257692895 */, 19 },
+ /* 7048 */ { MAD_F(0x041fb5b6) /* 0.257741653 */, 19 },
+ /* 7049 */ { MAD_F(0x041fe8d7) /* 0.257790414 */, 19 },
+ /* 7050 */ { MAD_F(0x04201bf9) /* 0.257839176 */, 19 },
+ /* 7051 */ { MAD_F(0x04204f1b) /* 0.257887941 */, 19 },
+ /* 7052 */ { MAD_F(0x0420823e) /* 0.257936709 */, 19 },
+ /* 7053 */ { MAD_F(0x0420b561) /* 0.257985478 */, 19 },
+ /* 7054 */ { MAD_F(0x0420e885) /* 0.258034250 */, 19 },
+ /* 7055 */ { MAD_F(0x04211baa) /* 0.258083025 */, 19 },
+
+ /* 7056 */ { MAD_F(0x04214ed0) /* 0.258131801 */, 19 },
+ /* 7057 */ { MAD_F(0x042181f6) /* 0.258180580 */, 19 },
+ /* 7058 */ { MAD_F(0x0421b51c) /* 0.258229361 */, 19 },
+ /* 7059 */ { MAD_F(0x0421e843) /* 0.258278145 */, 19 },
+ /* 7060 */ { MAD_F(0x04221b6b) /* 0.258326931 */, 19 },
+ /* 7061 */ { MAD_F(0x04224e94) /* 0.258375719 */, 19 },
+ /* 7062 */ { MAD_F(0x042281bd) /* 0.258424509 */, 19 },
+ /* 7063 */ { MAD_F(0x0422b4e6) /* 0.258473302 */, 19 },
+ /* 7064 */ { MAD_F(0x0422e811) /* 0.258522097 */, 19 },
+ /* 7065 */ { MAD_F(0x04231b3c) /* 0.258570894 */, 19 },
+ /* 7066 */ { MAD_F(0x04234e67) /* 0.258619694 */, 19 },
+ /* 7067 */ { MAD_F(0x04238193) /* 0.258668496 */, 19 },
+ /* 7068 */ { MAD_F(0x0423b4c0) /* 0.258717300 */, 19 },
+ /* 7069 */ { MAD_F(0x0423e7ee) /* 0.258766106 */, 19 },
+ /* 7070 */ { MAD_F(0x04241b1c) /* 0.258814915 */, 19 },
+ /* 7071 */ { MAD_F(0x04244e4a) /* 0.258863726 */, 19 },
+
+ /* 7072 */ { MAD_F(0x04248179) /* 0.258912540 */, 19 },
+ /* 7073 */ { MAD_F(0x0424b4a9) /* 0.258961356 */, 19 },
+ /* 7074 */ { MAD_F(0x0424e7da) /* 0.259010174 */, 19 },
+ /* 7075 */ { MAD_F(0x04251b0b) /* 0.259058994 */, 19 },
+ /* 7076 */ { MAD_F(0x04254e3d) /* 0.259107817 */, 19 },
+ /* 7077 */ { MAD_F(0x0425816f) /* 0.259156642 */, 19 },
+ /* 7078 */ { MAD_F(0x0425b4a2) /* 0.259205469 */, 19 },
+ /* 7079 */ { MAD_F(0x0425e7d6) /* 0.259254298 */, 19 },
+ /* 7080 */ { MAD_F(0x04261b0a) /* 0.259303130 */, 19 },
+ /* 7081 */ { MAD_F(0x04264e3f) /* 0.259351964 */, 19 },
+ /* 7082 */ { MAD_F(0x04268174) /* 0.259400801 */, 19 },
+ /* 7083 */ { MAD_F(0x0426b4aa) /* 0.259449639 */, 19 },
+ /* 7084 */ { MAD_F(0x0426e7e1) /* 0.259498480 */, 19 },
+ /* 7085 */ { MAD_F(0x04271b18) /* 0.259547324 */, 19 },
+ /* 7086 */ { MAD_F(0x04274e50) /* 0.259596169 */, 19 },
+ /* 7087 */ { MAD_F(0x04278188) /* 0.259645017 */, 19 },
+
+ /* 7088 */ { MAD_F(0x0427b4c2) /* 0.259693868 */, 19 },
+ /* 7089 */ { MAD_F(0x0427e7fb) /* 0.259742720 */, 19 },
+ /* 7090 */ { MAD_F(0x04281b36) /* 0.259791575 */, 19 },
+ /* 7091 */ { MAD_F(0x04284e71) /* 0.259840432 */, 19 },
+ /* 7092 */ { MAD_F(0x042881ac) /* 0.259889291 */, 19 },
+ /* 7093 */ { MAD_F(0x0428b4e8) /* 0.259938153 */, 19 },
+ /* 7094 */ { MAD_F(0x0428e825) /* 0.259987017 */, 19 },
+ /* 7095 */ { MAD_F(0x04291b63) /* 0.260035883 */, 19 },
+ /* 7096 */ { MAD_F(0x04294ea1) /* 0.260084752 */, 19 },
+ /* 7097 */ { MAD_F(0x042981df) /* 0.260133623 */, 19 },
+ /* 7098 */ { MAD_F(0x0429b51f) /* 0.260182496 */, 19 },
+ /* 7099 */ { MAD_F(0x0429e85f) /* 0.260231372 */, 19 },
+ /* 7100 */ { MAD_F(0x042a1b9f) /* 0.260280249 */, 19 },
+ /* 7101 */ { MAD_F(0x042a4ee0) /* 0.260329129 */, 19 },
+ /* 7102 */ { MAD_F(0x042a8222) /* 0.260378012 */, 19 },
+ /* 7103 */ { MAD_F(0x042ab564) /* 0.260426896 */, 19 },
+
+ /* 7104 */ { MAD_F(0x042ae8a7) /* 0.260475783 */, 19 },
+ /* 7105 */ { MAD_F(0x042b1beb) /* 0.260524673 */, 19 },
+ /* 7106 */ { MAD_F(0x042b4f2f) /* 0.260573564 */, 19 },
+ /* 7107 */ { MAD_F(0x042b8274) /* 0.260622458 */, 19 },
+ /* 7108 */ { MAD_F(0x042bb5ba) /* 0.260671354 */, 19 },
+ /* 7109 */ { MAD_F(0x042be900) /* 0.260720252 */, 19 },
+ /* 7110 */ { MAD_F(0x042c1c46) /* 0.260769153 */, 19 },
+ /* 7111 */ { MAD_F(0x042c4f8e) /* 0.260818056 */, 19 },
+ /* 7112 */ { MAD_F(0x042c82d6) /* 0.260866961 */, 19 },
+ /* 7113 */ { MAD_F(0x042cb61e) /* 0.260915869 */, 19 },
+ /* 7114 */ { MAD_F(0x042ce967) /* 0.260964779 */, 19 },
+ /* 7115 */ { MAD_F(0x042d1cb1) /* 0.261013691 */, 19 },
+ /* 7116 */ { MAD_F(0x042d4ffb) /* 0.261062606 */, 19 },
+ /* 7117 */ { MAD_F(0x042d8346) /* 0.261111522 */, 19 },
+ /* 7118 */ { MAD_F(0x042db692) /* 0.261160441 */, 19 },
+ /* 7119 */ { MAD_F(0x042de9de) /* 0.261209363 */, 19 },
+
+ /* 7120 */ { MAD_F(0x042e1d2b) /* 0.261258286 */, 19 },
+ /* 7121 */ { MAD_F(0x042e5078) /* 0.261307212 */, 19 },
+ /* 7122 */ { MAD_F(0x042e83c6) /* 0.261356140 */, 19 },
+ /* 7123 */ { MAD_F(0x042eb715) /* 0.261405071 */, 19 },
+ /* 7124 */ { MAD_F(0x042eea64) /* 0.261454004 */, 19 },
+ /* 7125 */ { MAD_F(0x042f1db4) /* 0.261502939 */, 19 },
+ /* 7126 */ { MAD_F(0x042f5105) /* 0.261551876 */, 19 },
+ /* 7127 */ { MAD_F(0x042f8456) /* 0.261600816 */, 19 },
+ /* 7128 */ { MAD_F(0x042fb7a8) /* 0.261649758 */, 19 },
+ /* 7129 */ { MAD_F(0x042feafa) /* 0.261698702 */, 19 },
+ /* 7130 */ { MAD_F(0x04301e4d) /* 0.261747649 */, 19 },
+ /* 7131 */ { MAD_F(0x043051a1) /* 0.261796597 */, 19 },
+ /* 7132 */ { MAD_F(0x043084f5) /* 0.261845548 */, 19 },
+ /* 7133 */ { MAD_F(0x0430b84a) /* 0.261894502 */, 19 },
+ /* 7134 */ { MAD_F(0x0430eb9f) /* 0.261943458 */, 19 },
+ /* 7135 */ { MAD_F(0x04311ef5) /* 0.261992416 */, 19 },
+
+ /* 7136 */ { MAD_F(0x0431524c) /* 0.262041376 */, 19 },
+ /* 7137 */ { MAD_F(0x043185a3) /* 0.262090338 */, 19 },
+ /* 7138 */ { MAD_F(0x0431b8fb) /* 0.262139303 */, 19 },
+ /* 7139 */ { MAD_F(0x0431ec54) /* 0.262188270 */, 19 },
+ /* 7140 */ { MAD_F(0x04321fad) /* 0.262237240 */, 19 },
+ /* 7141 */ { MAD_F(0x04325306) /* 0.262286211 */, 19 },
+ /* 7142 */ { MAD_F(0x04328661) /* 0.262335185 */, 19 },
+ /* 7143 */ { MAD_F(0x0432b9bc) /* 0.262384162 */, 19 },
+ /* 7144 */ { MAD_F(0x0432ed17) /* 0.262433140 */, 19 },
+ /* 7145 */ { MAD_F(0x04332074) /* 0.262482121 */, 19 },
+ /* 7146 */ { MAD_F(0x043353d0) /* 0.262531104 */, 19 },
+ /* 7147 */ { MAD_F(0x0433872e) /* 0.262580089 */, 19 },
+ /* 7148 */ { MAD_F(0x0433ba8c) /* 0.262629077 */, 19 },
+ /* 7149 */ { MAD_F(0x0433edea) /* 0.262678067 */, 19 },
+ /* 7150 */ { MAD_F(0x0434214a) /* 0.262727059 */, 19 },
+ /* 7151 */ { MAD_F(0x043454aa) /* 0.262776054 */, 19 },
+
+ /* 7152 */ { MAD_F(0x0434880a) /* 0.262825051 */, 19 },
+ /* 7153 */ { MAD_F(0x0434bb6b) /* 0.262874050 */, 19 },
+ /* 7154 */ { MAD_F(0x0434eecd) /* 0.262923051 */, 19 },
+ /* 7155 */ { MAD_F(0x0435222f) /* 0.262972055 */, 19 },
+ /* 7156 */ { MAD_F(0x04355592) /* 0.263021061 */, 19 },
+ /* 7157 */ { MAD_F(0x043588f6) /* 0.263070069 */, 19 },
+ /* 7158 */ { MAD_F(0x0435bc5a) /* 0.263119079 */, 19 },
+ /* 7159 */ { MAD_F(0x0435efbf) /* 0.263168092 */, 19 },
+ /* 7160 */ { MAD_F(0x04362324) /* 0.263217107 */, 19 },
+ /* 7161 */ { MAD_F(0x0436568a) /* 0.263266125 */, 19 },
+ /* 7162 */ { MAD_F(0x043689f1) /* 0.263315144 */, 19 },
+ /* 7163 */ { MAD_F(0x0436bd58) /* 0.263364166 */, 19 },
+ /* 7164 */ { MAD_F(0x0436f0c0) /* 0.263413191 */, 19 },
+ /* 7165 */ { MAD_F(0x04372428) /* 0.263462217 */, 19 },
+ /* 7166 */ { MAD_F(0x04375791) /* 0.263511246 */, 19 },
+ /* 7167 */ { MAD_F(0x04378afb) /* 0.263560277 */, 19 },
+
+ /* 7168 */ { MAD_F(0x0437be65) /* 0.263609310 */, 19 },
+ /* 7169 */ { MAD_F(0x0437f1d0) /* 0.263658346 */, 19 },
+ /* 7170 */ { MAD_F(0x0438253c) /* 0.263707384 */, 19 },
+ /* 7171 */ { MAD_F(0x043858a8) /* 0.263756424 */, 19 },
+ /* 7172 */ { MAD_F(0x04388c14) /* 0.263805466 */, 19 },
+ /* 7173 */ { MAD_F(0x0438bf82) /* 0.263854511 */, 19 },
+ /* 7174 */ { MAD_F(0x0438f2f0) /* 0.263903558 */, 19 },
+ /* 7175 */ { MAD_F(0x0439265e) /* 0.263952607 */, 19 },
+ /* 7176 */ { MAD_F(0x043959cd) /* 0.264001659 */, 19 },
+ /* 7177 */ { MAD_F(0x04398d3d) /* 0.264050713 */, 19 },
+ /* 7178 */ { MAD_F(0x0439c0ae) /* 0.264099769 */, 19 },
+ /* 7179 */ { MAD_F(0x0439f41f) /* 0.264148827 */, 19 },
+ /* 7180 */ { MAD_F(0x043a2790) /* 0.264197888 */, 19 },
+ /* 7181 */ { MAD_F(0x043a5b02) /* 0.264246951 */, 19 },
+ /* 7182 */ { MAD_F(0x043a8e75) /* 0.264296016 */, 19 },
+ /* 7183 */ { MAD_F(0x043ac1e9) /* 0.264345084 */, 19 },
+
+ /* 7184 */ { MAD_F(0x043af55d) /* 0.264394153 */, 19 },
+ /* 7185 */ { MAD_F(0x043b28d2) /* 0.264443225 */, 19 },
+ /* 7186 */ { MAD_F(0x043b5c47) /* 0.264492300 */, 19 },
+ /* 7187 */ { MAD_F(0x043b8fbd) /* 0.264541376 */, 19 },
+ /* 7188 */ { MAD_F(0x043bc333) /* 0.264590455 */, 19 },
+ /* 7189 */ { MAD_F(0x043bf6aa) /* 0.264639536 */, 19 },
+ /* 7190 */ { MAD_F(0x043c2a22) /* 0.264688620 */, 19 },
+ /* 7191 */ { MAD_F(0x043c5d9a) /* 0.264737706 */, 19 },
+ /* 7192 */ { MAD_F(0x043c9113) /* 0.264786794 */, 19 },
+ /* 7193 */ { MAD_F(0x043cc48d) /* 0.264835884 */, 19 },
+ /* 7194 */ { MAD_F(0x043cf807) /* 0.264884976 */, 19 },
+ /* 7195 */ { MAD_F(0x043d2b82) /* 0.264934071 */, 19 },
+ /* 7196 */ { MAD_F(0x043d5efd) /* 0.264983168 */, 19 },
+ /* 7197 */ { MAD_F(0x043d9279) /* 0.265032268 */, 19 },
+ /* 7198 */ { MAD_F(0x043dc5f6) /* 0.265081369 */, 19 },
+ /* 7199 */ { MAD_F(0x043df973) /* 0.265130473 */, 19 },
+
+ /* 7200 */ { MAD_F(0x043e2cf1) /* 0.265179580 */, 19 },
+ /* 7201 */ { MAD_F(0x043e6070) /* 0.265228688 */, 19 },
+ /* 7202 */ { MAD_F(0x043e93ef) /* 0.265277799 */, 19 },
+ /* 7203 */ { MAD_F(0x043ec76e) /* 0.265326912 */, 19 },
+ /* 7204 */ { MAD_F(0x043efaef) /* 0.265376027 */, 19 },
+ /* 7205 */ { MAD_F(0x043f2e6f) /* 0.265425145 */, 19 },
+ /* 7206 */ { MAD_F(0x043f61f1) /* 0.265474264 */, 19 },
+ /* 7207 */ { MAD_F(0x043f9573) /* 0.265523387 */, 19 },
+ /* 7208 */ { MAD_F(0x043fc8f6) /* 0.265572511 */, 19 },
+ /* 7209 */ { MAD_F(0x043ffc79) /* 0.265621638 */, 19 },
+ /* 7210 */ { MAD_F(0x04402ffd) /* 0.265670766 */, 19 },
+ /* 7211 */ { MAD_F(0x04406382) /* 0.265719898 */, 19 },
+ /* 7212 */ { MAD_F(0x04409707) /* 0.265769031 */, 19 },
+ /* 7213 */ { MAD_F(0x0440ca8d) /* 0.265818167 */, 19 },
+ /* 7214 */ { MAD_F(0x0440fe13) /* 0.265867305 */, 19 },
+ /* 7215 */ { MAD_F(0x0441319a) /* 0.265916445 */, 19 },
+
+ /* 7216 */ { MAD_F(0x04416522) /* 0.265965588 */, 19 },
+ /* 7217 */ { MAD_F(0x044198aa) /* 0.266014732 */, 19 },
+ /* 7218 */ { MAD_F(0x0441cc33) /* 0.266063880 */, 19 },
+ /* 7219 */ { MAD_F(0x0441ffbc) /* 0.266113029 */, 19 },
+ /* 7220 */ { MAD_F(0x04423346) /* 0.266162181 */, 19 },
+ /* 7221 */ { MAD_F(0x044266d1) /* 0.266211334 */, 19 },
+ /* 7222 */ { MAD_F(0x04429a5c) /* 0.266260491 */, 19 },
+ /* 7223 */ { MAD_F(0x0442cde8) /* 0.266309649 */, 19 },
+ /* 7224 */ { MAD_F(0x04430174) /* 0.266358810 */, 19 },
+ /* 7225 */ { MAD_F(0x04433501) /* 0.266407973 */, 19 },
+ /* 7226 */ { MAD_F(0x0443688f) /* 0.266457138 */, 19 },
+ /* 7227 */ { MAD_F(0x04439c1d) /* 0.266506305 */, 19 },
+ /* 7228 */ { MAD_F(0x0443cfac) /* 0.266555475 */, 19 },
+ /* 7229 */ { MAD_F(0x0444033c) /* 0.266604647 */, 19 },
+ /* 7230 */ { MAD_F(0x044436cc) /* 0.266653822 */, 19 },
+ /* 7231 */ { MAD_F(0x04446a5d) /* 0.266702998 */, 19 },
+
+ /* 7232 */ { MAD_F(0x04449dee) /* 0.266752177 */, 19 },
+ /* 7233 */ { MAD_F(0x0444d180) /* 0.266801358 */, 19 },
+ /* 7234 */ { MAD_F(0x04450513) /* 0.266850541 */, 19 },
+ /* 7235 */ { MAD_F(0x044538a6) /* 0.266899727 */, 19 },
+ /* 7236 */ { MAD_F(0x04456c39) /* 0.266948915 */, 19 },
+ /* 7237 */ { MAD_F(0x04459fce) /* 0.266998105 */, 19 },
+ /* 7238 */ { MAD_F(0x0445d363) /* 0.267047298 */, 19 },
+ /* 7239 */ { MAD_F(0x044606f8) /* 0.267096492 */, 19 },
+ /* 7240 */ { MAD_F(0x04463a8f) /* 0.267145689 */, 19 },
+ /* 7241 */ { MAD_F(0x04466e25) /* 0.267194888 */, 19 },
+ /* 7242 */ { MAD_F(0x0446a1bd) /* 0.267244090 */, 19 },
+ /* 7243 */ { MAD_F(0x0446d555) /* 0.267293294 */, 19 },
+ /* 7244 */ { MAD_F(0x044708ee) /* 0.267342500 */, 19 },
+ /* 7245 */ { MAD_F(0x04473c87) /* 0.267391708 */, 19 },
+ /* 7246 */ { MAD_F(0x04477021) /* 0.267440919 */, 19 },
+ /* 7247 */ { MAD_F(0x0447a3bb) /* 0.267490131 */, 19 },
+
+ /* 7248 */ { MAD_F(0x0447d756) /* 0.267539347 */, 19 },
+ /* 7249 */ { MAD_F(0x04480af2) /* 0.267588564 */, 19 },
+ /* 7250 */ { MAD_F(0x04483e8e) /* 0.267637783 */, 19 },
+ /* 7251 */ { MAD_F(0x0448722b) /* 0.267687005 */, 19 },
+ /* 7252 */ { MAD_F(0x0448a5c9) /* 0.267736229 */, 19 },
+ /* 7253 */ { MAD_F(0x0448d967) /* 0.267785456 */, 19 },
+ /* 7254 */ { MAD_F(0x04490d05) /* 0.267834685 */, 19 },
+ /* 7255 */ { MAD_F(0x044940a5) /* 0.267883915 */, 19 },
+ /* 7256 */ { MAD_F(0x04497445) /* 0.267933149 */, 19 },
+ /* 7257 */ { MAD_F(0x0449a7e5) /* 0.267982384 */, 19 },
+ /* 7258 */ { MAD_F(0x0449db86) /* 0.268031622 */, 19 },
+ /* 7259 */ { MAD_F(0x044a0f28) /* 0.268080862 */, 19 },
+ /* 7260 */ { MAD_F(0x044a42ca) /* 0.268130104 */, 19 },
+ /* 7261 */ { MAD_F(0x044a766d) /* 0.268179349 */, 19 },
+ /* 7262 */ { MAD_F(0x044aaa11) /* 0.268228595 */, 19 },
+ /* 7263 */ { MAD_F(0x044addb5) /* 0.268277844 */, 19 },
+
+ /* 7264 */ { MAD_F(0x044b115a) /* 0.268327096 */, 19 },
+ /* 7265 */ { MAD_F(0x044b44ff) /* 0.268376349 */, 19 },
+ /* 7266 */ { MAD_F(0x044b78a5) /* 0.268425605 */, 19 },
+ /* 7267 */ { MAD_F(0x044bac4c) /* 0.268474863 */, 19 },
+ /* 7268 */ { MAD_F(0x044bdff3) /* 0.268524123 */, 19 },
+ /* 7269 */ { MAD_F(0x044c139b) /* 0.268573386 */, 19 },
+ /* 7270 */ { MAD_F(0x044c4743) /* 0.268622651 */, 19 },
+ /* 7271 */ { MAD_F(0x044c7aec) /* 0.268671918 */, 19 },
+ /* 7272 */ { MAD_F(0x044cae96) /* 0.268721187 */, 19 },
+ /* 7273 */ { MAD_F(0x044ce240) /* 0.268770459 */, 19 },
+ /* 7274 */ { MAD_F(0x044d15eb) /* 0.268819733 */, 19 },
+ /* 7275 */ { MAD_F(0x044d4997) /* 0.268869009 */, 19 },
+ /* 7276 */ { MAD_F(0x044d7d43) /* 0.268918287 */, 19 },
+ /* 7277 */ { MAD_F(0x044db0ef) /* 0.268967568 */, 19 },
+ /* 7278 */ { MAD_F(0x044de49d) /* 0.269016851 */, 19 },
+ /* 7279 */ { MAD_F(0x044e184b) /* 0.269066136 */, 19 },
+
+ /* 7280 */ { MAD_F(0x044e4bf9) /* 0.269115423 */, 19 },
+ /* 7281 */ { MAD_F(0x044e7fa8) /* 0.269164713 */, 19 },
+ /* 7282 */ { MAD_F(0x044eb358) /* 0.269214005 */, 19 },
+ /* 7283 */ { MAD_F(0x044ee708) /* 0.269263299 */, 19 },
+ /* 7284 */ { MAD_F(0x044f1ab9) /* 0.269312595 */, 19 },
+ /* 7285 */ { MAD_F(0x044f4e6b) /* 0.269361894 */, 19 },
+ /* 7286 */ { MAD_F(0x044f821d) /* 0.269411195 */, 19 },
+ /* 7287 */ { MAD_F(0x044fb5cf) /* 0.269460498 */, 19 },
+ /* 7288 */ { MAD_F(0x044fe983) /* 0.269509804 */, 19 },
+ /* 7289 */ { MAD_F(0x04501d37) /* 0.269559111 */, 19 },
+ /* 7290 */ { MAD_F(0x045050eb) /* 0.269608421 */, 19 },
+ /* 7291 */ { MAD_F(0x045084a0) /* 0.269657734 */, 19 },
+ /* 7292 */ { MAD_F(0x0450b856) /* 0.269707048 */, 19 },
+ /* 7293 */ { MAD_F(0x0450ec0d) /* 0.269756365 */, 19 },
+ /* 7294 */ { MAD_F(0x04511fc4) /* 0.269805684 */, 19 },
+ /* 7295 */ { MAD_F(0x0451537b) /* 0.269855005 */, 19 },
+
+ /* 7296 */ { MAD_F(0x04518733) /* 0.269904329 */, 19 },
+ /* 7297 */ { MAD_F(0x0451baec) /* 0.269953654 */, 19 },
+ /* 7298 */ { MAD_F(0x0451eea5) /* 0.270002982 */, 19 },
+ /* 7299 */ { MAD_F(0x0452225f) /* 0.270052313 */, 19 },
+ /* 7300 */ { MAD_F(0x0452561a) /* 0.270101645 */, 19 },
+ /* 7301 */ { MAD_F(0x045289d5) /* 0.270150980 */, 19 },
+ /* 7302 */ { MAD_F(0x0452bd91) /* 0.270200317 */, 19 },
+ /* 7303 */ { MAD_F(0x0452f14d) /* 0.270249656 */, 19 },
+ /* 7304 */ { MAD_F(0x0453250a) /* 0.270298998 */, 19 },
+ /* 7305 */ { MAD_F(0x045358c8) /* 0.270348341 */, 19 },
+ /* 7306 */ { MAD_F(0x04538c86) /* 0.270397687 */, 19 },
+ /* 7307 */ { MAD_F(0x0453c045) /* 0.270447036 */, 19 },
+ /* 7308 */ { MAD_F(0x0453f405) /* 0.270496386 */, 19 },
+ /* 7309 */ { MAD_F(0x045427c5) /* 0.270545739 */, 19 },
+ /* 7310 */ { MAD_F(0x04545b85) /* 0.270595094 */, 19 },
+ /* 7311 */ { MAD_F(0x04548f46) /* 0.270644451 */, 19 },
+
+ /* 7312 */ { MAD_F(0x0454c308) /* 0.270693811 */, 19 },
+ /* 7313 */ { MAD_F(0x0454f6cb) /* 0.270743173 */, 19 },
+ /* 7314 */ { MAD_F(0x04552a8e) /* 0.270792537 */, 19 },
+ /* 7315 */ { MAD_F(0x04555e51) /* 0.270841903 */, 19 },
+ /* 7316 */ { MAD_F(0x04559216) /* 0.270891271 */, 19 },
+ /* 7317 */ { MAD_F(0x0455c5db) /* 0.270940642 */, 19 },
+ /* 7318 */ { MAD_F(0x0455f9a0) /* 0.270990015 */, 19 },
+ /* 7319 */ { MAD_F(0x04562d66) /* 0.271039390 */, 19 },
+ /* 7320 */ { MAD_F(0x0456612d) /* 0.271088768 */, 19 },
+ /* 7321 */ { MAD_F(0x045694f4) /* 0.271138148 */, 19 },
+ /* 7322 */ { MAD_F(0x0456c8bc) /* 0.271187530 */, 19 },
+ /* 7323 */ { MAD_F(0x0456fc84) /* 0.271236914 */, 19 },
+ /* 7324 */ { MAD_F(0x0457304e) /* 0.271286301 */, 19 },
+ /* 7325 */ { MAD_F(0x04576417) /* 0.271335689 */, 19 },
+ /* 7326 */ { MAD_F(0x045797e2) /* 0.271385080 */, 19 },
+ /* 7327 */ { MAD_F(0x0457cbac) /* 0.271434474 */, 19 },
+
+ /* 7328 */ { MAD_F(0x0457ff78) /* 0.271483869 */, 19 },
+ /* 7329 */ { MAD_F(0x04583344) /* 0.271533267 */, 19 },
+ /* 7330 */ { MAD_F(0x04586711) /* 0.271582667 */, 19 },
+ /* 7331 */ { MAD_F(0x04589ade) /* 0.271632069 */, 19 },
+ /* 7332 */ { MAD_F(0x0458ceac) /* 0.271681474 */, 19 },
+ /* 7333 */ { MAD_F(0x0459027b) /* 0.271730880 */, 19 },
+ /* 7334 */ { MAD_F(0x0459364a) /* 0.271780289 */, 19 },
+ /* 7335 */ { MAD_F(0x04596a19) /* 0.271829701 */, 19 },
+ /* 7336 */ { MAD_F(0x04599dea) /* 0.271879114 */, 19 },
+ /* 7337 */ { MAD_F(0x0459d1bb) /* 0.271928530 */, 19 },
+ /* 7338 */ { MAD_F(0x045a058c) /* 0.271977948 */, 19 },
+ /* 7339 */ { MAD_F(0x045a395e) /* 0.272027368 */, 19 },
+ /* 7340 */ { MAD_F(0x045a6d31) /* 0.272076790 */, 19 },
+ /* 7341 */ { MAD_F(0x045aa104) /* 0.272126215 */, 19 },
+ /* 7342 */ { MAD_F(0x045ad4d8) /* 0.272175642 */, 19 },
+ /* 7343 */ { MAD_F(0x045b08ad) /* 0.272225071 */, 19 },
+
+ /* 7344 */ { MAD_F(0x045b3c82) /* 0.272274503 */, 19 },
+ /* 7345 */ { MAD_F(0x045b7058) /* 0.272323936 */, 19 },
+ /* 7346 */ { MAD_F(0x045ba42e) /* 0.272373372 */, 19 },
+ /* 7347 */ { MAD_F(0x045bd805) /* 0.272422810 */, 19 },
+ /* 7348 */ { MAD_F(0x045c0bdd) /* 0.272472251 */, 19 },
+ /* 7349 */ { MAD_F(0x045c3fb5) /* 0.272521693 */, 19 },
+ /* 7350 */ { MAD_F(0x045c738e) /* 0.272571138 */, 19 },
+ /* 7351 */ { MAD_F(0x045ca767) /* 0.272620585 */, 19 },
+ /* 7352 */ { MAD_F(0x045cdb41) /* 0.272670035 */, 19 },
+ /* 7353 */ { MAD_F(0x045d0f1b) /* 0.272719486 */, 19 },
+ /* 7354 */ { MAD_F(0x045d42f7) /* 0.272768940 */, 19 },
+ /* 7355 */ { MAD_F(0x045d76d2) /* 0.272818396 */, 19 },
+ /* 7356 */ { MAD_F(0x045daaaf) /* 0.272867855 */, 19 },
+ /* 7357 */ { MAD_F(0x045dde8c) /* 0.272917315 */, 19 },
+ /* 7358 */ { MAD_F(0x045e1269) /* 0.272966778 */, 19 },
+ /* 7359 */ { MAD_F(0x045e4647) /* 0.273016243 */, 19 },
+
+ /* 7360 */ { MAD_F(0x045e7a26) /* 0.273065710 */, 19 },
+ /* 7361 */ { MAD_F(0x045eae06) /* 0.273115180 */, 19 },
+ /* 7362 */ { MAD_F(0x045ee1e6) /* 0.273164652 */, 19 },
+ /* 7363 */ { MAD_F(0x045f15c6) /* 0.273214126 */, 19 },
+ /* 7364 */ { MAD_F(0x045f49a7) /* 0.273263602 */, 19 },
+ /* 7365 */ { MAD_F(0x045f7d89) /* 0.273313081 */, 19 },
+ /* 7366 */ { MAD_F(0x045fb16c) /* 0.273362561 */, 19 },
+ /* 7367 */ { MAD_F(0x045fe54f) /* 0.273412044 */, 19 },
+ /* 7368 */ { MAD_F(0x04601932) /* 0.273461530 */, 19 },
+ /* 7369 */ { MAD_F(0x04604d16) /* 0.273511017 */, 19 },
+ /* 7370 */ { MAD_F(0x046080fb) /* 0.273560507 */, 19 },
+ /* 7371 */ { MAD_F(0x0460b4e1) /* 0.273609999 */, 19 },
+ /* 7372 */ { MAD_F(0x0460e8c7) /* 0.273659493 */, 19 },
+ /* 7373 */ { MAD_F(0x04611cad) /* 0.273708989 */, 19 },
+ /* 7374 */ { MAD_F(0x04615094) /* 0.273758488 */, 19 },
+ /* 7375 */ { MAD_F(0x0461847c) /* 0.273807989 */, 19 },
+
+ /* 7376 */ { MAD_F(0x0461b864) /* 0.273857492 */, 19 },
+ /* 7377 */ { MAD_F(0x0461ec4d) /* 0.273906997 */, 19 },
+ /* 7378 */ { MAD_F(0x04622037) /* 0.273956505 */, 19 },
+ /* 7379 */ { MAD_F(0x04625421) /* 0.274006015 */, 19 },
+ /* 7380 */ { MAD_F(0x0462880c) /* 0.274055527 */, 19 },
+ /* 7381 */ { MAD_F(0x0462bbf7) /* 0.274105041 */, 19 },
+ /* 7382 */ { MAD_F(0x0462efe3) /* 0.274154558 */, 19 },
+ /* 7383 */ { MAD_F(0x046323d0) /* 0.274204076 */, 19 },
+ /* 7384 */ { MAD_F(0x046357bd) /* 0.274253597 */, 19 },
+ /* 7385 */ { MAD_F(0x04638bab) /* 0.274303121 */, 19 },
+ /* 7386 */ { MAD_F(0x0463bf99) /* 0.274352646 */, 19 },
+ /* 7387 */ { MAD_F(0x0463f388) /* 0.274402174 */, 19 },
+ /* 7388 */ { MAD_F(0x04642778) /* 0.274451704 */, 19 },
+ /* 7389 */ { MAD_F(0x04645b68) /* 0.274501236 */, 19 },
+ /* 7390 */ { MAD_F(0x04648f59) /* 0.274550771 */, 19 },
+ /* 7391 */ { MAD_F(0x0464c34a) /* 0.274600307 */, 19 },
+
+ /* 7392 */ { MAD_F(0x0464f73c) /* 0.274649846 */, 19 },
+ /* 7393 */ { MAD_F(0x04652b2f) /* 0.274699387 */, 19 },
+ /* 7394 */ { MAD_F(0x04655f22) /* 0.274748931 */, 19 },
+ /* 7395 */ { MAD_F(0x04659316) /* 0.274798476 */, 19 },
+ /* 7396 */ { MAD_F(0x0465c70a) /* 0.274848024 */, 19 },
+ /* 7397 */ { MAD_F(0x0465faff) /* 0.274897574 */, 19 },
+ /* 7398 */ { MAD_F(0x04662ef5) /* 0.274947126 */, 19 },
+ /* 7399 */ { MAD_F(0x046662eb) /* 0.274996681 */, 19 },
+ /* 7400 */ { MAD_F(0x046696e2) /* 0.275046238 */, 19 },
+ /* 7401 */ { MAD_F(0x0466cad9) /* 0.275095797 */, 19 },
+ /* 7402 */ { MAD_F(0x0466fed1) /* 0.275145358 */, 19 },
+ /* 7403 */ { MAD_F(0x046732ca) /* 0.275194921 */, 19 },
+ /* 7404 */ { MAD_F(0x046766c3) /* 0.275244487 */, 19 },
+ /* 7405 */ { MAD_F(0x04679abd) /* 0.275294055 */, 19 },
+ /* 7406 */ { MAD_F(0x0467ceb7) /* 0.275343625 */, 19 },
+ /* 7407 */ { MAD_F(0x046802b2) /* 0.275393198 */, 19 },
+
+ /* 7408 */ { MAD_F(0x046836ae) /* 0.275442772 */, 19 },
+ /* 7409 */ { MAD_F(0x04686aaa) /* 0.275492349 */, 19 },
+ /* 7410 */ { MAD_F(0x04689ea7) /* 0.275541928 */, 19 },
+ /* 7411 */ { MAD_F(0x0468d2a4) /* 0.275591509 */, 19 },
+ /* 7412 */ { MAD_F(0x046906a2) /* 0.275641093 */, 19 },
+ /* 7413 */ { MAD_F(0x04693aa1) /* 0.275690679 */, 19 },
+ /* 7414 */ { MAD_F(0x04696ea0) /* 0.275740267 */, 19 },
+ /* 7415 */ { MAD_F(0x0469a2a0) /* 0.275789857 */, 19 },
+ /* 7416 */ { MAD_F(0x0469d6a0) /* 0.275839449 */, 19 },
+ /* 7417 */ { MAD_F(0x046a0aa1) /* 0.275889044 */, 19 },
+ /* 7418 */ { MAD_F(0x046a3ea3) /* 0.275938641 */, 19 },
+ /* 7419 */ { MAD_F(0x046a72a5) /* 0.275988240 */, 19 },
+ /* 7420 */ { MAD_F(0x046aa6a8) /* 0.276037842 */, 19 },
+ /* 7421 */ { MAD_F(0x046adaab) /* 0.276087445 */, 19 },
+ /* 7422 */ { MAD_F(0x046b0eaf) /* 0.276137051 */, 19 },
+ /* 7423 */ { MAD_F(0x046b42b3) /* 0.276186659 */, 19 },
+
+ /* 7424 */ { MAD_F(0x046b76b9) /* 0.276236269 */, 19 },
+ /* 7425 */ { MAD_F(0x046baabe) /* 0.276285882 */, 19 },
+ /* 7426 */ { MAD_F(0x046bdec5) /* 0.276335497 */, 19 },
+ /* 7427 */ { MAD_F(0x046c12cc) /* 0.276385113 */, 19 },
+ /* 7428 */ { MAD_F(0x046c46d3) /* 0.276434733 */, 19 },
+ /* 7429 */ { MAD_F(0x046c7adb) /* 0.276484354 */, 19 },
+ /* 7430 */ { MAD_F(0x046caee4) /* 0.276533978 */, 19 },
+ /* 7431 */ { MAD_F(0x046ce2ee) /* 0.276583604 */, 19 },
+ /* 7432 */ { MAD_F(0x046d16f7) /* 0.276633232 */, 19 },
+ /* 7433 */ { MAD_F(0x046d4b02) /* 0.276682862 */, 19 },
+ /* 7434 */ { MAD_F(0x046d7f0d) /* 0.276732495 */, 19 },
+ /* 7435 */ { MAD_F(0x046db319) /* 0.276782129 */, 19 },
+ /* 7436 */ { MAD_F(0x046de725) /* 0.276831766 */, 19 },
+ /* 7437 */ { MAD_F(0x046e1b32) /* 0.276881406 */, 19 },
+ /* 7438 */ { MAD_F(0x046e4f40) /* 0.276931047 */, 19 },
+ /* 7439 */ { MAD_F(0x046e834e) /* 0.276980691 */, 19 },
+
+ /* 7440 */ { MAD_F(0x046eb75c) /* 0.277030337 */, 19 },
+ /* 7441 */ { MAD_F(0x046eeb6c) /* 0.277079985 */, 19 },
+ /* 7442 */ { MAD_F(0x046f1f7c) /* 0.277129635 */, 19 },
+ /* 7443 */ { MAD_F(0x046f538c) /* 0.277179288 */, 19 },
+ /* 7444 */ { MAD_F(0x046f879d) /* 0.277228942 */, 19 },
+ /* 7445 */ { MAD_F(0x046fbbaf) /* 0.277278600 */, 19 },
+ /* 7446 */ { MAD_F(0x046fefc1) /* 0.277328259 */, 19 },
+ /* 7447 */ { MAD_F(0x047023d4) /* 0.277377920 */, 19 },
+ /* 7448 */ { MAD_F(0x047057e8) /* 0.277427584 */, 19 },
+ /* 7449 */ { MAD_F(0x04708bfc) /* 0.277477250 */, 19 },
+ /* 7450 */ { MAD_F(0x0470c011) /* 0.277526918 */, 19 },
+ /* 7451 */ { MAD_F(0x0470f426) /* 0.277576588 */, 19 },
+ /* 7452 */ { MAD_F(0x0471283c) /* 0.277626261 */, 19 },
+ /* 7453 */ { MAD_F(0x04715c52) /* 0.277675936 */, 19 },
+ /* 7454 */ { MAD_F(0x04719069) /* 0.277725613 */, 19 },
+ /* 7455 */ { MAD_F(0x0471c481) /* 0.277775292 */, 19 },
+
+ /* 7456 */ { MAD_F(0x0471f899) /* 0.277824973 */, 19 },
+ /* 7457 */ { MAD_F(0x04722cb2) /* 0.277874657 */, 19 },
+ /* 7458 */ { MAD_F(0x047260cc) /* 0.277924343 */, 19 },
+ /* 7459 */ { MAD_F(0x047294e6) /* 0.277974031 */, 19 },
+ /* 7460 */ { MAD_F(0x0472c900) /* 0.278023722 */, 19 },
+ /* 7461 */ { MAD_F(0x0472fd1b) /* 0.278073414 */, 19 },
+ /* 7462 */ { MAD_F(0x04733137) /* 0.278123109 */, 19 },
+ /* 7463 */ { MAD_F(0x04736554) /* 0.278172806 */, 19 },
+ /* 7464 */ { MAD_F(0x04739971) /* 0.278222505 */, 19 },
+ /* 7465 */ { MAD_F(0x0473cd8e) /* 0.278272207 */, 19 },
+ /* 7466 */ { MAD_F(0x047401ad) /* 0.278321910 */, 19 },
+ /* 7467 */ { MAD_F(0x047435cb) /* 0.278371616 */, 19 },
+ /* 7468 */ { MAD_F(0x047469eb) /* 0.278421324 */, 19 },
+ /* 7469 */ { MAD_F(0x04749e0b) /* 0.278471035 */, 19 },
+ /* 7470 */ { MAD_F(0x0474d22c) /* 0.278520747 */, 19 },
+ /* 7471 */ { MAD_F(0x0475064d) /* 0.278570462 */, 19 },
+
+ /* 7472 */ { MAD_F(0x04753a6f) /* 0.278620179 */, 19 },
+ /* 7473 */ { MAD_F(0x04756e91) /* 0.278669898 */, 19 },
+ /* 7474 */ { MAD_F(0x0475a2b4) /* 0.278719619 */, 19 },
+ /* 7475 */ { MAD_F(0x0475d6d7) /* 0.278769343 */, 19 },
+ /* 7476 */ { MAD_F(0x04760afc) /* 0.278819069 */, 19 },
+ /* 7477 */ { MAD_F(0x04763f20) /* 0.278868797 */, 19 },
+ /* 7478 */ { MAD_F(0x04767346) /* 0.278918527 */, 19 },
+ /* 7479 */ { MAD_F(0x0476a76c) /* 0.278968260 */, 19 },
+ /* 7480 */ { MAD_F(0x0476db92) /* 0.279017995 */, 19 },
+ /* 7481 */ { MAD_F(0x04770fba) /* 0.279067731 */, 19 },
+ /* 7482 */ { MAD_F(0x047743e1) /* 0.279117471 */, 19 },
+ /* 7483 */ { MAD_F(0x0477780a) /* 0.279167212 */, 19 },
+ /* 7484 */ { MAD_F(0x0477ac33) /* 0.279216956 */, 19 },
+ /* 7485 */ { MAD_F(0x0477e05c) /* 0.279266701 */, 19 },
+ /* 7486 */ { MAD_F(0x04781486) /* 0.279316449 */, 19 },
+ /* 7487 */ { MAD_F(0x047848b1) /* 0.279366200 */, 19 },
+
+ /* 7488 */ { MAD_F(0x04787cdc) /* 0.279415952 */, 19 },
+ /* 7489 */ { MAD_F(0x0478b108) /* 0.279465707 */, 19 },
+ /* 7490 */ { MAD_F(0x0478e535) /* 0.279515464 */, 19 },
+ /* 7491 */ { MAD_F(0x04791962) /* 0.279565223 */, 19 },
+ /* 7492 */ { MAD_F(0x04794d8f) /* 0.279614984 */, 19 },
+ /* 7493 */ { MAD_F(0x047981be) /* 0.279664748 */, 19 },
+ /* 7494 */ { MAD_F(0x0479b5ed) /* 0.279714513 */, 19 },
+ /* 7495 */ { MAD_F(0x0479ea1c) /* 0.279764281 */, 19 },
+ /* 7496 */ { MAD_F(0x047a1e4c) /* 0.279814051 */, 19 },
+ /* 7497 */ { MAD_F(0x047a527d) /* 0.279863824 */, 19 },
+ /* 7498 */ { MAD_F(0x047a86ae) /* 0.279913598 */, 19 },
+ /* 7499 */ { MAD_F(0x047abae0) /* 0.279963375 */, 19 },
+ /* 7500 */ { MAD_F(0x047aef12) /* 0.280013154 */, 19 },
+ /* 7501 */ { MAD_F(0x047b2346) /* 0.280062935 */, 19 },
+ /* 7502 */ { MAD_F(0x047b5779) /* 0.280112719 */, 19 },
+ /* 7503 */ { MAD_F(0x047b8bad) /* 0.280162504 */, 19 },
+
+ /* 7504 */ { MAD_F(0x047bbfe2) /* 0.280212292 */, 19 },
+ /* 7505 */ { MAD_F(0x047bf418) /* 0.280262082 */, 19 },
+ /* 7506 */ { MAD_F(0x047c284e) /* 0.280311875 */, 19 },
+ /* 7507 */ { MAD_F(0x047c5c84) /* 0.280361669 */, 19 },
+ /* 7508 */ { MAD_F(0x047c90bb) /* 0.280411466 */, 19 },
+ /* 7509 */ { MAD_F(0x047cc4f3) /* 0.280461265 */, 19 },
+ /* 7510 */ { MAD_F(0x047cf92c) /* 0.280511066 */, 19 },
+ /* 7511 */ { MAD_F(0x047d2d65) /* 0.280560869 */, 19 },
+ /* 7512 */ { MAD_F(0x047d619e) /* 0.280610675 */, 19 },
+ /* 7513 */ { MAD_F(0x047d95d8) /* 0.280660483 */, 19 },
+ /* 7514 */ { MAD_F(0x047dca13) /* 0.280710292 */, 19 },
+ /* 7515 */ { MAD_F(0x047dfe4e) /* 0.280760105 */, 19 },
+ /* 7516 */ { MAD_F(0x047e328a) /* 0.280809919 */, 19 },
+ /* 7517 */ { MAD_F(0x047e66c7) /* 0.280859736 */, 19 },
+ /* 7518 */ { MAD_F(0x047e9b04) /* 0.280909554 */, 19 },
+ /* 7519 */ { MAD_F(0x047ecf42) /* 0.280959375 */, 19 },
+
+ /* 7520 */ { MAD_F(0x047f0380) /* 0.281009199 */, 19 },
+ /* 7521 */ { MAD_F(0x047f37bf) /* 0.281059024 */, 19 },
+ /* 7522 */ { MAD_F(0x047f6bff) /* 0.281108852 */, 19 },
+ /* 7523 */ { MAD_F(0x047fa03f) /* 0.281158682 */, 19 },
+ /* 7524 */ { MAD_F(0x047fd47f) /* 0.281208514 */, 19 },
+ /* 7525 */ { MAD_F(0x048008c1) /* 0.281258348 */, 19 },
+ /* 7526 */ { MAD_F(0x04803d02) /* 0.281308184 */, 19 },
+ /* 7527 */ { MAD_F(0x04807145) /* 0.281358023 */, 19 },
+ /* 7528 */ { MAD_F(0x0480a588) /* 0.281407864 */, 19 },
+ /* 7529 */ { MAD_F(0x0480d9cc) /* 0.281457707 */, 19 },
+ /* 7530 */ { MAD_F(0x04810e10) /* 0.281507552 */, 19 },
+ /* 7531 */ { MAD_F(0x04814255) /* 0.281557400 */, 19 },
+ /* 7532 */ { MAD_F(0x0481769a) /* 0.281607250 */, 19 },
+ /* 7533 */ { MAD_F(0x0481aae0) /* 0.281657101 */, 19 },
+ /* 7534 */ { MAD_F(0x0481df27) /* 0.281706956 */, 19 },
+ /* 7535 */ { MAD_F(0x0482136e) /* 0.281756812 */, 19 },
+
+ /* 7536 */ { MAD_F(0x048247b6) /* 0.281806670 */, 19 },
+ /* 7537 */ { MAD_F(0x04827bfe) /* 0.281856531 */, 19 },
+ /* 7538 */ { MAD_F(0x0482b047) /* 0.281906394 */, 19 },
+ /* 7539 */ { MAD_F(0x0482e491) /* 0.281956259 */, 19 },
+ /* 7540 */ { MAD_F(0x048318db) /* 0.282006127 */, 19 },
+ /* 7541 */ { MAD_F(0x04834d26) /* 0.282055996 */, 19 },
+ /* 7542 */ { MAD_F(0x04838171) /* 0.282105868 */, 19 },
+ /* 7543 */ { MAD_F(0x0483b5bd) /* 0.282155742 */, 19 },
+ /* 7544 */ { MAD_F(0x0483ea0a) /* 0.282205618 */, 19 },
+ /* 7545 */ { MAD_F(0x04841e57) /* 0.282255496 */, 19 },
+ /* 7546 */ { MAD_F(0x048452a4) /* 0.282305377 */, 19 },
+ /* 7547 */ { MAD_F(0x048486f3) /* 0.282355260 */, 19 },
+ /* 7548 */ { MAD_F(0x0484bb42) /* 0.282405145 */, 19 },
+ /* 7549 */ { MAD_F(0x0484ef91) /* 0.282455032 */, 19 },
+ /* 7550 */ { MAD_F(0x048523e1) /* 0.282504921 */, 19 },
+ /* 7551 */ { MAD_F(0x04855832) /* 0.282554813 */, 19 },
+
+ /* 7552 */ { MAD_F(0x04858c83) /* 0.282604707 */, 19 },
+ /* 7553 */ { MAD_F(0x0485c0d5) /* 0.282654603 */, 19 },
+ /* 7554 */ { MAD_F(0x0485f527) /* 0.282704501 */, 19 },
+ /* 7555 */ { MAD_F(0x0486297a) /* 0.282754401 */, 19 },
+ /* 7556 */ { MAD_F(0x04865dce) /* 0.282804304 */, 19 },
+ /* 7557 */ { MAD_F(0x04869222) /* 0.282854209 */, 19 },
+ /* 7558 */ { MAD_F(0x0486c677) /* 0.282904116 */, 19 },
+ /* 7559 */ { MAD_F(0x0486facc) /* 0.282954025 */, 19 },
+ /* 7560 */ { MAD_F(0x04872f22) /* 0.283003936 */, 19 },
+ /* 7561 */ { MAD_F(0x04876379) /* 0.283053850 */, 19 },
+ /* 7562 */ { MAD_F(0x048797d0) /* 0.283103766 */, 19 },
+ /* 7563 */ { MAD_F(0x0487cc28) /* 0.283153684 */, 19 },
+ /* 7564 */ { MAD_F(0x04880080) /* 0.283203604 */, 19 },
+ /* 7565 */ { MAD_F(0x048834d9) /* 0.283253527 */, 19 },
+ /* 7566 */ { MAD_F(0x04886933) /* 0.283303451 */, 19 },
+ /* 7567 */ { MAD_F(0x04889d8d) /* 0.283353378 */, 19 },
+
+ /* 7568 */ { MAD_F(0x0488d1e8) /* 0.283403307 */, 19 },
+ /* 7569 */ { MAD_F(0x04890643) /* 0.283453238 */, 19 },
+ /* 7570 */ { MAD_F(0x04893a9f) /* 0.283503172 */, 19 },
+ /* 7571 */ { MAD_F(0x04896efb) /* 0.283553107 */, 19 },
+ /* 7572 */ { MAD_F(0x0489a358) /* 0.283603045 */, 19 },
+ /* 7573 */ { MAD_F(0x0489d7b6) /* 0.283652985 */, 19 },
+ /* 7574 */ { MAD_F(0x048a0c14) /* 0.283702927 */, 19 },
+ /* 7575 */ { MAD_F(0x048a4073) /* 0.283752872 */, 19 },
+ /* 7576 */ { MAD_F(0x048a74d3) /* 0.283802818 */, 19 },
+ /* 7577 */ { MAD_F(0x048aa933) /* 0.283852767 */, 19 },
+ /* 7578 */ { MAD_F(0x048add93) /* 0.283902718 */, 19 },
+ /* 7579 */ { MAD_F(0x048b11f5) /* 0.283952671 */, 19 },
+ /* 7580 */ { MAD_F(0x048b4656) /* 0.284002627 */, 19 },
+ /* 7581 */ { MAD_F(0x048b7ab9) /* 0.284052584 */, 19 },
+ /* 7582 */ { MAD_F(0x048baf1c) /* 0.284102544 */, 19 },
+ /* 7583 */ { MAD_F(0x048be37f) /* 0.284152506 */, 19 },
+
+ /* 7584 */ { MAD_F(0x048c17e3) /* 0.284202470 */, 19 },
+ /* 7585 */ { MAD_F(0x048c4c48) /* 0.284252436 */, 19 },
+ /* 7586 */ { MAD_F(0x048c80ad) /* 0.284302405 */, 19 },
+ /* 7587 */ { MAD_F(0x048cb513) /* 0.284352376 */, 19 },
+ /* 7588 */ { MAD_F(0x048ce97a) /* 0.284402349 */, 19 },
+ /* 7589 */ { MAD_F(0x048d1de1) /* 0.284452324 */, 19 },
+ /* 7590 */ { MAD_F(0x048d5249) /* 0.284502301 */, 19 },
+ /* 7591 */ { MAD_F(0x048d86b1) /* 0.284552281 */, 19 },
+ /* 7592 */ { MAD_F(0x048dbb1a) /* 0.284602263 */, 19 },
+ /* 7593 */ { MAD_F(0x048def83) /* 0.284652246 */, 19 },
+ /* 7594 */ { MAD_F(0x048e23ed) /* 0.284702233 */, 19 },
+ /* 7595 */ { MAD_F(0x048e5858) /* 0.284752221 */, 19 },
+ /* 7596 */ { MAD_F(0x048e8cc3) /* 0.284802211 */, 19 },
+ /* 7597 */ { MAD_F(0x048ec12f) /* 0.284852204 */, 19 },
+ /* 7598 */ { MAD_F(0x048ef59b) /* 0.284902199 */, 19 },
+ /* 7599 */ { MAD_F(0x048f2a08) /* 0.284952196 */, 19 },
+
+ /* 7600 */ { MAD_F(0x048f5e76) /* 0.285002195 */, 19 },
+ /* 7601 */ { MAD_F(0x048f92e4) /* 0.285052197 */, 19 },
+ /* 7602 */ { MAD_F(0x048fc753) /* 0.285102201 */, 19 },
+ /* 7603 */ { MAD_F(0x048ffbc2) /* 0.285152206 */, 19 },
+ /* 7604 */ { MAD_F(0x04903032) /* 0.285202214 */, 19 },
+ /* 7605 */ { MAD_F(0x049064a3) /* 0.285252225 */, 19 },
+ /* 7606 */ { MAD_F(0x04909914) /* 0.285302237 */, 19 },
+ /* 7607 */ { MAD_F(0x0490cd86) /* 0.285352252 */, 19 },
+ /* 7608 */ { MAD_F(0x049101f8) /* 0.285402269 */, 19 },
+ /* 7609 */ { MAD_F(0x0491366b) /* 0.285452288 */, 19 },
+ /* 7610 */ { MAD_F(0x04916ade) /* 0.285502309 */, 19 },
+ /* 7611 */ { MAD_F(0x04919f52) /* 0.285552332 */, 19 },
+ /* 7612 */ { MAD_F(0x0491d3c7) /* 0.285602358 */, 19 },
+ /* 7613 */ { MAD_F(0x0492083c) /* 0.285652386 */, 19 },
+ /* 7614 */ { MAD_F(0x04923cb2) /* 0.285702416 */, 19 },
+ /* 7615 */ { MAD_F(0x04927128) /* 0.285752448 */, 19 },
+
+ /* 7616 */ { MAD_F(0x0492a59f) /* 0.285802482 */, 19 },
+ /* 7617 */ { MAD_F(0x0492da17) /* 0.285852519 */, 19 },
+ /* 7618 */ { MAD_F(0x04930e8f) /* 0.285902557 */, 19 },
+ /* 7619 */ { MAD_F(0x04934308) /* 0.285952598 */, 19 },
+ /* 7620 */ { MAD_F(0x04937781) /* 0.286002641 */, 19 },
+ /* 7621 */ { MAD_F(0x0493abfb) /* 0.286052687 */, 19 },
+ /* 7622 */ { MAD_F(0x0493e076) /* 0.286102734 */, 19 },
+ /* 7623 */ { MAD_F(0x049414f1) /* 0.286152784 */, 19 },
+ /* 7624 */ { MAD_F(0x0494496c) /* 0.286202836 */, 19 },
+ /* 7625 */ { MAD_F(0x04947de9) /* 0.286252890 */, 19 },
+ /* 7626 */ { MAD_F(0x0494b266) /* 0.286302946 */, 19 },
+ /* 7627 */ { MAD_F(0x0494e6e3) /* 0.286353005 */, 19 },
+ /* 7628 */ { MAD_F(0x04951b61) /* 0.286403065 */, 19 },
+ /* 7629 */ { MAD_F(0x04954fe0) /* 0.286453128 */, 19 },
+ /* 7630 */ { MAD_F(0x0495845f) /* 0.286503193 */, 19 },
+ /* 7631 */ { MAD_F(0x0495b8df) /* 0.286553260 */, 19 },
+
+ /* 7632 */ { MAD_F(0x0495ed5f) /* 0.286603329 */, 19 },
+ /* 7633 */ { MAD_F(0x049621e0) /* 0.286653401 */, 19 },
+ /* 7634 */ { MAD_F(0x04965662) /* 0.286703475 */, 19 },
+ /* 7635 */ { MAD_F(0x04968ae4) /* 0.286753551 */, 19 },
+ /* 7636 */ { MAD_F(0x0496bf67) /* 0.286803629 */, 19 },
+ /* 7637 */ { MAD_F(0x0496f3ea) /* 0.286853709 */, 19 },
+ /* 7638 */ { MAD_F(0x0497286e) /* 0.286903792 */, 19 },
+ /* 7639 */ { MAD_F(0x04975cf2) /* 0.286953876 */, 19 },
+ /* 7640 */ { MAD_F(0x04979177) /* 0.287003963 */, 19 },
+ /* 7641 */ { MAD_F(0x0497c5fd) /* 0.287054052 */, 19 },
+ /* 7642 */ { MAD_F(0x0497fa83) /* 0.287104143 */, 19 },
+ /* 7643 */ { MAD_F(0x04982f0a) /* 0.287154237 */, 19 },
+ /* 7644 */ { MAD_F(0x04986392) /* 0.287204332 */, 19 },
+ /* 7645 */ { MAD_F(0x0498981a) /* 0.287254430 */, 19 },
+ /* 7646 */ { MAD_F(0x0498cca2) /* 0.287304530 */, 19 },
+ /* 7647 */ { MAD_F(0x0499012c) /* 0.287354632 */, 19 },
+
+ /* 7648 */ { MAD_F(0x049935b5) /* 0.287404737 */, 19 },
+ /* 7649 */ { MAD_F(0x04996a40) /* 0.287454843 */, 19 },
+ /* 7650 */ { MAD_F(0x04999ecb) /* 0.287504952 */, 19 },
+ /* 7651 */ { MAD_F(0x0499d356) /* 0.287555063 */, 19 },
+ /* 7652 */ { MAD_F(0x049a07e2) /* 0.287605176 */, 19 },
+ /* 7653 */ { MAD_F(0x049a3c6f) /* 0.287655291 */, 19 },
+ /* 7654 */ { MAD_F(0x049a70fc) /* 0.287705409 */, 19 },
+ /* 7655 */ { MAD_F(0x049aa58a) /* 0.287755528 */, 19 },
+ /* 7656 */ { MAD_F(0x049ada19) /* 0.287805650 */, 19 },
+ /* 7657 */ { MAD_F(0x049b0ea8) /* 0.287855774 */, 19 },
+ /* 7658 */ { MAD_F(0x049b4337) /* 0.287905900 */, 19 },
+ /* 7659 */ { MAD_F(0x049b77c8) /* 0.287956028 */, 19 },
+ /* 7660 */ { MAD_F(0x049bac58) /* 0.288006159 */, 19 },
+ /* 7661 */ { MAD_F(0x049be0ea) /* 0.288056292 */, 19 },
+ /* 7662 */ { MAD_F(0x049c157c) /* 0.288106427 */, 19 },
+ /* 7663 */ { MAD_F(0x049c4a0e) /* 0.288156564 */, 19 },
+
+ /* 7664 */ { MAD_F(0x049c7ea1) /* 0.288206703 */, 19 },
+ /* 7665 */ { MAD_F(0x049cb335) /* 0.288256844 */, 19 },
+ /* 7666 */ { MAD_F(0x049ce7ca) /* 0.288306988 */, 19 },
+ /* 7667 */ { MAD_F(0x049d1c5e) /* 0.288357134 */, 19 },
+ /* 7668 */ { MAD_F(0x049d50f4) /* 0.288407282 */, 19 },
+ /* 7669 */ { MAD_F(0x049d858a) /* 0.288457432 */, 19 },
+ /* 7670 */ { MAD_F(0x049dba21) /* 0.288507584 */, 19 },
+ /* 7671 */ { MAD_F(0x049deeb8) /* 0.288557739 */, 19 },
+ /* 7672 */ { MAD_F(0x049e2350) /* 0.288607895 */, 19 },
+ /* 7673 */ { MAD_F(0x049e57e8) /* 0.288658054 */, 19 },
+ /* 7674 */ { MAD_F(0x049e8c81) /* 0.288708215 */, 19 },
+ /* 7675 */ { MAD_F(0x049ec11b) /* 0.288758379 */, 19 },
+ /* 7676 */ { MAD_F(0x049ef5b5) /* 0.288808544 */, 19 },
+ /* 7677 */ { MAD_F(0x049f2a50) /* 0.288858712 */, 19 },
+ /* 7678 */ { MAD_F(0x049f5eeb) /* 0.288908881 */, 19 },
+ /* 7679 */ { MAD_F(0x049f9387) /* 0.288959053 */, 19 },
+
+ /* 7680 */ { MAD_F(0x049fc824) /* 0.289009227 */, 19 },
+ /* 7681 */ { MAD_F(0x049ffcc1) /* 0.289059404 */, 19 },
+ /* 7682 */ { MAD_F(0x04a0315e) /* 0.289109582 */, 19 },
+ /* 7683 */ { MAD_F(0x04a065fd) /* 0.289159763 */, 19 },
+ /* 7684 */ { MAD_F(0x04a09a9b) /* 0.289209946 */, 19 },
+ /* 7685 */ { MAD_F(0x04a0cf3b) /* 0.289260131 */, 19 },
+ /* 7686 */ { MAD_F(0x04a103db) /* 0.289310318 */, 19 },
+ /* 7687 */ { MAD_F(0x04a1387b) /* 0.289360507 */, 19 },
+ /* 7688 */ { MAD_F(0x04a16d1d) /* 0.289410699 */, 19 },
+ /* 7689 */ { MAD_F(0x04a1a1be) /* 0.289460893 */, 19 },
+ /* 7690 */ { MAD_F(0x04a1d661) /* 0.289511088 */, 19 },
+ /* 7691 */ { MAD_F(0x04a20b04) /* 0.289561287 */, 19 },
+ /* 7692 */ { MAD_F(0x04a23fa7) /* 0.289611487 */, 19 },
+ /* 7693 */ { MAD_F(0x04a2744b) /* 0.289661689 */, 19 },
+ /* 7694 */ { MAD_F(0x04a2a8f0) /* 0.289711894 */, 19 },
+ /* 7695 */ { MAD_F(0x04a2dd95) /* 0.289762101 */, 19 },
+
+ /* 7696 */ { MAD_F(0x04a3123b) /* 0.289812309 */, 19 },
+ /* 7697 */ { MAD_F(0x04a346e2) /* 0.289862521 */, 19 },
+ /* 7698 */ { MAD_F(0x04a37b89) /* 0.289912734 */, 19 },
+ /* 7699 */ { MAD_F(0x04a3b030) /* 0.289962949 */, 19 },
+ /* 7700 */ { MAD_F(0x04a3e4d8) /* 0.290013167 */, 19 },
+ /* 7701 */ { MAD_F(0x04a41981) /* 0.290063387 */, 19 },
+ /* 7702 */ { MAD_F(0x04a44e2b) /* 0.290113609 */, 19 },
+ /* 7703 */ { MAD_F(0x04a482d5) /* 0.290163833 */, 19 },
+ /* 7704 */ { MAD_F(0x04a4b77f) /* 0.290214059 */, 19 },
+ /* 7705 */ { MAD_F(0x04a4ec2a) /* 0.290264288 */, 19 },
+ /* 7706 */ { MAD_F(0x04a520d6) /* 0.290314519 */, 19 },
+ /* 7707 */ { MAD_F(0x04a55582) /* 0.290364751 */, 19 },
+ /* 7708 */ { MAD_F(0x04a58a2f) /* 0.290414986 */, 19 },
+ /* 7709 */ { MAD_F(0x04a5bedd) /* 0.290465224 */, 19 },
+ /* 7710 */ { MAD_F(0x04a5f38b) /* 0.290515463 */, 19 },
+ /* 7711 */ { MAD_F(0x04a62839) /* 0.290565705 */, 19 },
+
+ /* 7712 */ { MAD_F(0x04a65ce8) /* 0.290615948 */, 19 },
+ /* 7713 */ { MAD_F(0x04a69198) /* 0.290666194 */, 19 },
+ /* 7714 */ { MAD_F(0x04a6c648) /* 0.290716442 */, 19 },
+ /* 7715 */ { MAD_F(0x04a6faf9) /* 0.290766692 */, 19 },
+ /* 7716 */ { MAD_F(0x04a72fab) /* 0.290816945 */, 19 },
+ /* 7717 */ { MAD_F(0x04a7645d) /* 0.290867199 */, 19 },
+ /* 7718 */ { MAD_F(0x04a79910) /* 0.290917456 */, 19 },
+ /* 7719 */ { MAD_F(0x04a7cdc3) /* 0.290967715 */, 19 },
+ /* 7720 */ { MAD_F(0x04a80277) /* 0.291017976 */, 19 },
+ /* 7721 */ { MAD_F(0x04a8372b) /* 0.291068239 */, 19 },
+ /* 7722 */ { MAD_F(0x04a86be0) /* 0.291118505 */, 19 },
+ /* 7723 */ { MAD_F(0x04a8a096) /* 0.291168772 */, 19 },
+ /* 7724 */ { MAD_F(0x04a8d54c) /* 0.291219042 */, 19 },
+ /* 7725 */ { MAD_F(0x04a90a03) /* 0.291269314 */, 19 },
+ /* 7726 */ { MAD_F(0x04a93eba) /* 0.291319588 */, 19 },
+ /* 7727 */ { MAD_F(0x04a97372) /* 0.291369865 */, 19 },
+
+ /* 7728 */ { MAD_F(0x04a9a82b) /* 0.291420143 */, 19 },
+ /* 7729 */ { MAD_F(0x04a9dce4) /* 0.291470424 */, 19 },
+ /* 7730 */ { MAD_F(0x04aa119d) /* 0.291520706 */, 19 },
+ /* 7731 */ { MAD_F(0x04aa4658) /* 0.291570991 */, 19 },
+ /* 7732 */ { MAD_F(0x04aa7b13) /* 0.291621278 */, 19 },
+ /* 7733 */ { MAD_F(0x04aaafce) /* 0.291671568 */, 19 },
+ /* 7734 */ { MAD_F(0x04aae48a) /* 0.291721859 */, 19 },
+ /* 7735 */ { MAD_F(0x04ab1947) /* 0.291772153 */, 19 },
+ /* 7736 */ { MAD_F(0x04ab4e04) /* 0.291822449 */, 19 },
+ /* 7737 */ { MAD_F(0x04ab82c2) /* 0.291872747 */, 19 },
+ /* 7738 */ { MAD_F(0x04abb780) /* 0.291923047 */, 19 },
+ /* 7739 */ { MAD_F(0x04abec3f) /* 0.291973349 */, 19 },
+ /* 7740 */ { MAD_F(0x04ac20fe) /* 0.292023653 */, 19 },
+ /* 7741 */ { MAD_F(0x04ac55be) /* 0.292073960 */, 19 },
+ /* 7742 */ { MAD_F(0x04ac8a7f) /* 0.292124269 */, 19 },
+ /* 7743 */ { MAD_F(0x04acbf40) /* 0.292174580 */, 19 },
+
+ /* 7744 */ { MAD_F(0x04acf402) /* 0.292224893 */, 19 },
+ /* 7745 */ { MAD_F(0x04ad28c5) /* 0.292275208 */, 19 },
+ /* 7746 */ { MAD_F(0x04ad5d88) /* 0.292325526 */, 19 },
+ /* 7747 */ { MAD_F(0x04ad924b) /* 0.292375845 */, 19 },
+ /* 7748 */ { MAD_F(0x04adc70f) /* 0.292426167 */, 19 },
+ /* 7749 */ { MAD_F(0x04adfbd4) /* 0.292476491 */, 19 },
+ /* 7750 */ { MAD_F(0x04ae3099) /* 0.292526817 */, 19 },
+ /* 7751 */ { MAD_F(0x04ae655f) /* 0.292577145 */, 19 },
+ /* 7752 */ { MAD_F(0x04ae9a26) /* 0.292627476 */, 19 },
+ /* 7753 */ { MAD_F(0x04aeceed) /* 0.292677808 */, 19 },
+ /* 7754 */ { MAD_F(0x04af03b4) /* 0.292728143 */, 19 },
+ /* 7755 */ { MAD_F(0x04af387d) /* 0.292778480 */, 19 },
+ /* 7756 */ { MAD_F(0x04af6d45) /* 0.292828819 */, 19 },
+ /* 7757 */ { MAD_F(0x04afa20f) /* 0.292879160 */, 19 },
+ /* 7758 */ { MAD_F(0x04afd6d9) /* 0.292929504 */, 19 },
+ /* 7759 */ { MAD_F(0x04b00ba3) /* 0.292979849 */, 19 },
+
+ /* 7760 */ { MAD_F(0x04b0406e) /* 0.293030197 */, 19 },
+ /* 7761 */ { MAD_F(0x04b0753a) /* 0.293080547 */, 19 },
+ /* 7762 */ { MAD_F(0x04b0aa06) /* 0.293130899 */, 19 },
+ /* 7763 */ { MAD_F(0x04b0ded3) /* 0.293181253 */, 19 },
+ /* 7764 */ { MAD_F(0x04b113a1) /* 0.293231610 */, 19 },
+ /* 7765 */ { MAD_F(0x04b1486f) /* 0.293281968 */, 19 },
+ /* 7766 */ { MAD_F(0x04b17d3d) /* 0.293332329 */, 19 },
+ /* 7767 */ { MAD_F(0x04b1b20c) /* 0.293382692 */, 19 },
+ /* 7768 */ { MAD_F(0x04b1e6dc) /* 0.293433057 */, 19 },
+ /* 7769 */ { MAD_F(0x04b21bad) /* 0.293483424 */, 19 },
+ /* 7770 */ { MAD_F(0x04b2507d) /* 0.293533794 */, 19 },
+ /* 7771 */ { MAD_F(0x04b2854f) /* 0.293584165 */, 19 },
+ /* 7772 */ { MAD_F(0x04b2ba21) /* 0.293634539 */, 19 },
+ /* 7773 */ { MAD_F(0x04b2eef4) /* 0.293684915 */, 19 },
+ /* 7774 */ { MAD_F(0x04b323c7) /* 0.293735293 */, 19 },
+ /* 7775 */ { MAD_F(0x04b3589b) /* 0.293785673 */, 19 },
+
+ /* 7776 */ { MAD_F(0x04b38d6f) /* 0.293836055 */, 19 },
+ /* 7777 */ { MAD_F(0x04b3c244) /* 0.293886440 */, 19 },
+ /* 7778 */ { MAD_F(0x04b3f71a) /* 0.293936826 */, 19 },
+ /* 7779 */ { MAD_F(0x04b42bf0) /* 0.293987215 */, 19 },
+ /* 7780 */ { MAD_F(0x04b460c7) /* 0.294037606 */, 19 },
+ /* 7781 */ { MAD_F(0x04b4959e) /* 0.294087999 */, 19 },
+ /* 7782 */ { MAD_F(0x04b4ca76) /* 0.294138395 */, 19 },
+ /* 7783 */ { MAD_F(0x04b4ff4e) /* 0.294188792 */, 19 },
+ /* 7784 */ { MAD_F(0x04b53427) /* 0.294239192 */, 19 },
+ /* 7785 */ { MAD_F(0x04b56901) /* 0.294289593 */, 19 },
+ /* 7786 */ { MAD_F(0x04b59ddb) /* 0.294339997 */, 19 },
+ /* 7787 */ { MAD_F(0x04b5d2b6) /* 0.294390403 */, 19 },
+ /* 7788 */ { MAD_F(0x04b60791) /* 0.294440812 */, 19 },
+ /* 7789 */ { MAD_F(0x04b63c6d) /* 0.294491222 */, 19 },
+ /* 7790 */ { MAD_F(0x04b6714a) /* 0.294541635 */, 19 },
+ /* 7791 */ { MAD_F(0x04b6a627) /* 0.294592049 */, 19 },
+
+ /* 7792 */ { MAD_F(0x04b6db05) /* 0.294642466 */, 19 },
+ /* 7793 */ { MAD_F(0x04b70fe3) /* 0.294692885 */, 19 },
+ /* 7794 */ { MAD_F(0x04b744c2) /* 0.294743306 */, 19 },
+ /* 7795 */ { MAD_F(0x04b779a1) /* 0.294793730 */, 19 },
+ /* 7796 */ { MAD_F(0x04b7ae81) /* 0.294844155 */, 19 },
+ /* 7797 */ { MAD_F(0x04b7e362) /* 0.294894583 */, 19 },
+ /* 7798 */ { MAD_F(0x04b81843) /* 0.294945013 */, 19 },
+ /* 7799 */ { MAD_F(0x04b84d24) /* 0.294995445 */, 19 },
+ /* 7800 */ { MAD_F(0x04b88207) /* 0.295045879 */, 19 },
+ /* 7801 */ { MAD_F(0x04b8b6ea) /* 0.295096315 */, 19 },
+ /* 7802 */ { MAD_F(0x04b8ebcd) /* 0.295146753 */, 19 },
+ /* 7803 */ { MAD_F(0x04b920b1) /* 0.295197194 */, 19 },
+ /* 7804 */ { MAD_F(0x04b95596) /* 0.295247637 */, 19 },
+ /* 7805 */ { MAD_F(0x04b98a7b) /* 0.295298082 */, 19 },
+ /* 7806 */ { MAD_F(0x04b9bf61) /* 0.295348529 */, 19 },
+ /* 7807 */ { MAD_F(0x04b9f447) /* 0.295398978 */, 19 },
+
+ /* 7808 */ { MAD_F(0x04ba292e) /* 0.295449429 */, 19 },
+ /* 7809 */ { MAD_F(0x04ba5e16) /* 0.295499883 */, 19 },
+ /* 7810 */ { MAD_F(0x04ba92fe) /* 0.295550338 */, 19 },
+ /* 7811 */ { MAD_F(0x04bac7e6) /* 0.295600796 */, 19 },
+ /* 7812 */ { MAD_F(0x04bafcd0) /* 0.295651256 */, 19 },
+ /* 7813 */ { MAD_F(0x04bb31b9) /* 0.295701718 */, 19 },
+ /* 7814 */ { MAD_F(0x04bb66a4) /* 0.295752183 */, 19 },
+ /* 7815 */ { MAD_F(0x04bb9b8f) /* 0.295802649 */, 19 },
+ /* 7816 */ { MAD_F(0x04bbd07a) /* 0.295853118 */, 19 },
+ /* 7817 */ { MAD_F(0x04bc0566) /* 0.295903588 */, 19 },
+ /* 7818 */ { MAD_F(0x04bc3a53) /* 0.295954061 */, 19 },
+ /* 7819 */ { MAD_F(0x04bc6f40) /* 0.296004536 */, 19 },
+ /* 7820 */ { MAD_F(0x04bca42e) /* 0.296055013 */, 19 },
+ /* 7821 */ { MAD_F(0x04bcd91d) /* 0.296105493 */, 19 },
+ /* 7822 */ { MAD_F(0x04bd0e0c) /* 0.296155974 */, 19 },
+ /* 7823 */ { MAD_F(0x04bd42fb) /* 0.296206458 */, 19 },
+
+ /* 7824 */ { MAD_F(0x04bd77ec) /* 0.296256944 */, 19 },
+ /* 7825 */ { MAD_F(0x04bdacdc) /* 0.296307432 */, 19 },
+ /* 7826 */ { MAD_F(0x04bde1ce) /* 0.296357922 */, 19 },
+ /* 7827 */ { MAD_F(0x04be16c0) /* 0.296408414 */, 19 },
+ /* 7828 */ { MAD_F(0x04be4bb2) /* 0.296458908 */, 19 },
+ /* 7829 */ { MAD_F(0x04be80a5) /* 0.296509405 */, 19 },
+ /* 7830 */ { MAD_F(0x04beb599) /* 0.296559904 */, 19 },
+ /* 7831 */ { MAD_F(0x04beea8d) /* 0.296610404 */, 19 },
+ /* 7832 */ { MAD_F(0x04bf1f82) /* 0.296660907 */, 19 },
+ /* 7833 */ { MAD_F(0x04bf5477) /* 0.296711413 */, 19 },
+ /* 7834 */ { MAD_F(0x04bf896d) /* 0.296761920 */, 19 },
+ /* 7835 */ { MAD_F(0x04bfbe64) /* 0.296812429 */, 19 },
+ /* 7836 */ { MAD_F(0x04bff35b) /* 0.296862941 */, 19 },
+ /* 7837 */ { MAD_F(0x04c02852) /* 0.296913455 */, 19 },
+ /* 7838 */ { MAD_F(0x04c05d4b) /* 0.296963971 */, 19 },
+ /* 7839 */ { MAD_F(0x04c09243) /* 0.297014489 */, 19 },
+
+ /* 7840 */ { MAD_F(0x04c0c73d) /* 0.297065009 */, 19 },
+ /* 7841 */ { MAD_F(0x04c0fc37) /* 0.297115531 */, 19 },
+ /* 7842 */ { MAD_F(0x04c13131) /* 0.297166056 */, 19 },
+ /* 7843 */ { MAD_F(0x04c1662d) /* 0.297216582 */, 19 },
+ /* 7844 */ { MAD_F(0x04c19b28) /* 0.297267111 */, 19 },
+ /* 7845 */ { MAD_F(0x04c1d025) /* 0.297317642 */, 19 },
+ /* 7846 */ { MAD_F(0x04c20521) /* 0.297368175 */, 19 },
+ /* 7847 */ { MAD_F(0x04c23a1f) /* 0.297418710 */, 19 },
+ /* 7848 */ { MAD_F(0x04c26f1d) /* 0.297469248 */, 19 },
+ /* 7849 */ { MAD_F(0x04c2a41b) /* 0.297519787 */, 19 },
+ /* 7850 */ { MAD_F(0x04c2d91b) /* 0.297570329 */, 19 },
+ /* 7851 */ { MAD_F(0x04c30e1a) /* 0.297620873 */, 19 },
+ /* 7852 */ { MAD_F(0x04c3431b) /* 0.297671418 */, 19 },
+ /* 7853 */ { MAD_F(0x04c3781c) /* 0.297721967 */, 19 },
+ /* 7854 */ { MAD_F(0x04c3ad1d) /* 0.297772517 */, 19 },
+ /* 7855 */ { MAD_F(0x04c3e21f) /* 0.297823069 */, 19 },
+
+ /* 7856 */ { MAD_F(0x04c41722) /* 0.297873624 */, 19 },
+ /* 7857 */ { MAD_F(0x04c44c25) /* 0.297924180 */, 19 },
+ /* 7858 */ { MAD_F(0x04c48129) /* 0.297974739 */, 19 },
+ /* 7859 */ { MAD_F(0x04c4b62d) /* 0.298025300 */, 19 },
+ /* 7860 */ { MAD_F(0x04c4eb32) /* 0.298075863 */, 19 },
+ /* 7861 */ { MAD_F(0x04c52038) /* 0.298126429 */, 19 },
+ /* 7862 */ { MAD_F(0x04c5553e) /* 0.298176996 */, 19 },
+ /* 7863 */ { MAD_F(0x04c58a44) /* 0.298227565 */, 19 },
+ /* 7864 */ { MAD_F(0x04c5bf4c) /* 0.298278137 */, 19 },
+ /* 7865 */ { MAD_F(0x04c5f453) /* 0.298328711 */, 19 },
+ /* 7866 */ { MAD_F(0x04c6295c) /* 0.298379287 */, 19 },
+ /* 7867 */ { MAD_F(0x04c65e65) /* 0.298429865 */, 19 },
+ /* 7868 */ { MAD_F(0x04c6936e) /* 0.298480445 */, 19 },
+ /* 7869 */ { MAD_F(0x04c6c878) /* 0.298531028 */, 19 },
+ /* 7870 */ { MAD_F(0x04c6fd83) /* 0.298581612 */, 19 },
+ /* 7871 */ { MAD_F(0x04c7328e) /* 0.298632199 */, 19 },
+
+ /* 7872 */ { MAD_F(0x04c7679a) /* 0.298682788 */, 19 },
+ /* 7873 */ { MAD_F(0x04c79ca7) /* 0.298733379 */, 19 },
+ /* 7874 */ { MAD_F(0x04c7d1b4) /* 0.298783972 */, 19 },
+ /* 7875 */ { MAD_F(0x04c806c1) /* 0.298834567 */, 19 },
+ /* 7876 */ { MAD_F(0x04c83bcf) /* 0.298885165 */, 19 },
+ /* 7877 */ { MAD_F(0x04c870de) /* 0.298935764 */, 19 },
+ /* 7878 */ { MAD_F(0x04c8a5ed) /* 0.298986366 */, 19 },
+ /* 7879 */ { MAD_F(0x04c8dafd) /* 0.299036970 */, 19 },
+ /* 7880 */ { MAD_F(0x04c9100d) /* 0.299087576 */, 19 },
+ /* 7881 */ { MAD_F(0x04c9451e) /* 0.299138184 */, 19 },
+ /* 7882 */ { MAD_F(0x04c97a30) /* 0.299188794 */, 19 },
+ /* 7883 */ { MAD_F(0x04c9af42) /* 0.299239406 */, 19 },
+ /* 7884 */ { MAD_F(0x04c9e455) /* 0.299290021 */, 19 },
+ /* 7885 */ { MAD_F(0x04ca1968) /* 0.299340638 */, 19 },
+ /* 7886 */ { MAD_F(0x04ca4e7c) /* 0.299391256 */, 19 },
+ /* 7887 */ { MAD_F(0x04ca8391) /* 0.299441877 */, 19 },
+
+ /* 7888 */ { MAD_F(0x04cab8a6) /* 0.299492500 */, 19 },
+ /* 7889 */ { MAD_F(0x04caedbb) /* 0.299543126 */, 19 },
+ /* 7890 */ { MAD_F(0x04cb22d1) /* 0.299593753 */, 19 },
+ /* 7891 */ { MAD_F(0x04cb57e8) /* 0.299644382 */, 19 },
+ /* 7892 */ { MAD_F(0x04cb8d00) /* 0.299695014 */, 19 },
+ /* 7893 */ { MAD_F(0x04cbc217) /* 0.299745648 */, 19 },
+ /* 7894 */ { MAD_F(0x04cbf730) /* 0.299796284 */, 19 },
+ /* 7895 */ { MAD_F(0x04cc2c49) /* 0.299846922 */, 19 },
+ /* 7896 */ { MAD_F(0x04cc6163) /* 0.299897562 */, 19 },
+ /* 7897 */ { MAD_F(0x04cc967d) /* 0.299948204 */, 19 },
+ /* 7898 */ { MAD_F(0x04cccb98) /* 0.299998849 */, 19 },
+ /* 7899 */ { MAD_F(0x04cd00b3) /* 0.300049495 */, 19 },
+ /* 7900 */ { MAD_F(0x04cd35cf) /* 0.300100144 */, 19 },
+ /* 7901 */ { MAD_F(0x04cd6aeb) /* 0.300150795 */, 19 },
+ /* 7902 */ { MAD_F(0x04cda008) /* 0.300201448 */, 19 },
+ /* 7903 */ { MAD_F(0x04cdd526) /* 0.300252103 */, 19 },
+
+ /* 7904 */ { MAD_F(0x04ce0a44) /* 0.300302761 */, 19 },
+ /* 7905 */ { MAD_F(0x04ce3f63) /* 0.300353420 */, 19 },
+ /* 7906 */ { MAD_F(0x04ce7482) /* 0.300404082 */, 19 },
+ /* 7907 */ { MAD_F(0x04cea9a2) /* 0.300454745 */, 19 },
+ /* 7908 */ { MAD_F(0x04cedec3) /* 0.300505411 */, 19 },
+ /* 7909 */ { MAD_F(0x04cf13e4) /* 0.300556079 */, 19 },
+ /* 7910 */ { MAD_F(0x04cf4906) /* 0.300606749 */, 19 },
+ /* 7911 */ { MAD_F(0x04cf7e28) /* 0.300657421 */, 19 },
+ /* 7912 */ { MAD_F(0x04cfb34b) /* 0.300708096 */, 19 },
+ /* 7913 */ { MAD_F(0x04cfe86e) /* 0.300758772 */, 19 },
+ /* 7914 */ { MAD_F(0x04d01d92) /* 0.300809451 */, 19 },
+ /* 7915 */ { MAD_F(0x04d052b6) /* 0.300860132 */, 19 },
+ /* 7916 */ { MAD_F(0x04d087db) /* 0.300910815 */, 19 },
+ /* 7917 */ { MAD_F(0x04d0bd01) /* 0.300961500 */, 19 },
+ /* 7918 */ { MAD_F(0x04d0f227) /* 0.301012187 */, 19 },
+ /* 7919 */ { MAD_F(0x04d1274e) /* 0.301062876 */, 19 },
+
+ /* 7920 */ { MAD_F(0x04d15c76) /* 0.301113568 */, 19 },
+ /* 7921 */ { MAD_F(0x04d1919e) /* 0.301164261 */, 19 },
+ /* 7922 */ { MAD_F(0x04d1c6c6) /* 0.301214957 */, 19 },
+ /* 7923 */ { MAD_F(0x04d1fbef) /* 0.301265655 */, 19 },
+ /* 7924 */ { MAD_F(0x04d23119) /* 0.301316355 */, 19 },
+ /* 7925 */ { MAD_F(0x04d26643) /* 0.301367057 */, 19 },
+ /* 7926 */ { MAD_F(0x04d29b6e) /* 0.301417761 */, 19 },
+ /* 7927 */ { MAD_F(0x04d2d099) /* 0.301468468 */, 19 },
+ /* 7928 */ { MAD_F(0x04d305c5) /* 0.301519176 */, 19 },
+ /* 7929 */ { MAD_F(0x04d33af2) /* 0.301569887 */, 19 },
+ /* 7930 */ { MAD_F(0x04d3701f) /* 0.301620599 */, 19 },
+ /* 7931 */ { MAD_F(0x04d3a54d) /* 0.301671314 */, 19 },
+ /* 7932 */ { MAD_F(0x04d3da7b) /* 0.301722031 */, 19 },
+ /* 7933 */ { MAD_F(0x04d40faa) /* 0.301772751 */, 19 },
+ /* 7934 */ { MAD_F(0x04d444d9) /* 0.301823472 */, 19 },
+ /* 7935 */ { MAD_F(0x04d47a09) /* 0.301874195 */, 19 },
+
+ /* 7936 */ { MAD_F(0x04d4af3a) /* 0.301924921 */, 19 },
+ /* 7937 */ { MAD_F(0x04d4e46b) /* 0.301975649 */, 19 },
+ /* 7938 */ { MAD_F(0x04d5199c) /* 0.302026378 */, 19 },
+ /* 7939 */ { MAD_F(0x04d54ecf) /* 0.302077110 */, 19 },
+ /* 7940 */ { MAD_F(0x04d58401) /* 0.302127845 */, 19 },
+ /* 7941 */ { MAD_F(0x04d5b935) /* 0.302178581 */, 19 },
+ /* 7942 */ { MAD_F(0x04d5ee69) /* 0.302229319 */, 19 },
+ /* 7943 */ { MAD_F(0x04d6239d) /* 0.302280060 */, 19 },
+ /* 7944 */ { MAD_F(0x04d658d2) /* 0.302330802 */, 19 },
+ /* 7945 */ { MAD_F(0x04d68e08) /* 0.302381547 */, 19 },
+ /* 7946 */ { MAD_F(0x04d6c33e) /* 0.302432294 */, 19 },
+ /* 7947 */ { MAD_F(0x04d6f875) /* 0.302483043 */, 19 },
+ /* 7948 */ { MAD_F(0x04d72dad) /* 0.302533794 */, 19 },
+ /* 7949 */ { MAD_F(0x04d762e5) /* 0.302584547 */, 19 },
+ /* 7950 */ { MAD_F(0x04d7981d) /* 0.302635303 */, 19 },
+ /* 7951 */ { MAD_F(0x04d7cd56) /* 0.302686060 */, 19 },
+
+ /* 7952 */ { MAD_F(0x04d80290) /* 0.302736820 */, 19 },
+ /* 7953 */ { MAD_F(0x04d837ca) /* 0.302787581 */, 19 },
+ /* 7954 */ { MAD_F(0x04d86d05) /* 0.302838345 */, 19 },
+ /* 7955 */ { MAD_F(0x04d8a240) /* 0.302889111 */, 19 },
+ /* 7956 */ { MAD_F(0x04d8d77c) /* 0.302939879 */, 19 },
+ /* 7957 */ { MAD_F(0x04d90cb9) /* 0.302990650 */, 19 },
+ /* 7958 */ { MAD_F(0x04d941f6) /* 0.303041422 */, 19 },
+ /* 7959 */ { MAD_F(0x04d97734) /* 0.303092197 */, 19 },
+ /* 7960 */ { MAD_F(0x04d9ac72) /* 0.303142973 */, 19 },
+ /* 7961 */ { MAD_F(0x04d9e1b1) /* 0.303193752 */, 19 },
+ /* 7962 */ { MAD_F(0x04da16f0) /* 0.303244533 */, 19 },
+ /* 7963 */ { MAD_F(0x04da4c30) /* 0.303295316 */, 19 },
+ /* 7964 */ { MAD_F(0x04da8171) /* 0.303346101 */, 19 },
+ /* 7965 */ { MAD_F(0x04dab6b2) /* 0.303396889 */, 19 },
+ /* 7966 */ { MAD_F(0x04daebf4) /* 0.303447678 */, 19 },
+ /* 7967 */ { MAD_F(0x04db2136) /* 0.303498469 */, 19 },
+
+ /* 7968 */ { MAD_F(0x04db5679) /* 0.303549263 */, 19 },
+ /* 7969 */ { MAD_F(0x04db8bbc) /* 0.303600059 */, 19 },
+ /* 7970 */ { MAD_F(0x04dbc100) /* 0.303650857 */, 19 },
+ /* 7971 */ { MAD_F(0x04dbf644) /* 0.303701657 */, 19 },
+ /* 7972 */ { MAD_F(0x04dc2b8a) /* 0.303752459 */, 19 },
+ /* 7973 */ { MAD_F(0x04dc60cf) /* 0.303803263 */, 19 },
+ /* 7974 */ { MAD_F(0x04dc9616) /* 0.303854070 */, 19 },
+ /* 7975 */ { MAD_F(0x04dccb5c) /* 0.303904878 */, 19 },
+ /* 7976 */ { MAD_F(0x04dd00a4) /* 0.303955689 */, 19 },
+ /* 7977 */ { MAD_F(0x04dd35ec) /* 0.304006502 */, 19 },
+ /* 7978 */ { MAD_F(0x04dd6b34) /* 0.304057317 */, 19 },
+ /* 7979 */ { MAD_F(0x04dda07d) /* 0.304108134 */, 19 },
+ /* 7980 */ { MAD_F(0x04ddd5c7) /* 0.304158953 */, 19 },
+ /* 7981 */ { MAD_F(0x04de0b11) /* 0.304209774 */, 19 },
+ /* 7982 */ { MAD_F(0x04de405c) /* 0.304260597 */, 19 },
+ /* 7983 */ { MAD_F(0x04de75a7) /* 0.304311423 */, 19 },
+
+ /* 7984 */ { MAD_F(0x04deaaf3) /* 0.304362251 */, 19 },
+ /* 7985 */ { MAD_F(0x04dee040) /* 0.304413080 */, 19 },
+ /* 7986 */ { MAD_F(0x04df158d) /* 0.304463912 */, 19 },
+ /* 7987 */ { MAD_F(0x04df4adb) /* 0.304514746 */, 19 },
+ /* 7988 */ { MAD_F(0x04df8029) /* 0.304565582 */, 19 },
+ /* 7989 */ { MAD_F(0x04dfb578) /* 0.304616421 */, 19 },
+ /* 7990 */ { MAD_F(0x04dfeac7) /* 0.304667261 */, 19 },
+ /* 7991 */ { MAD_F(0x04e02017) /* 0.304718103 */, 19 },
+ /* 7992 */ { MAD_F(0x04e05567) /* 0.304768948 */, 19 },
+ /* 7993 */ { MAD_F(0x04e08ab8) /* 0.304819795 */, 19 },
+ /* 7994 */ { MAD_F(0x04e0c00a) /* 0.304870644 */, 19 },
+ /* 7995 */ { MAD_F(0x04e0f55c) /* 0.304921495 */, 19 },
+ /* 7996 */ { MAD_F(0x04e12aaf) /* 0.304972348 */, 19 },
+ /* 7997 */ { MAD_F(0x04e16002) /* 0.305023203 */, 19 },
+ /* 7998 */ { MAD_F(0x04e19556) /* 0.305074060 */, 19 },
+ /* 7999 */ { MAD_F(0x04e1caab) /* 0.305124920 */, 19 },
+
+ /* 8000 */ { MAD_F(0x04e20000) /* 0.305175781 */, 19 },
+ /* 8001 */ { MAD_F(0x04e23555) /* 0.305226645 */, 19 },
+ /* 8002 */ { MAD_F(0x04e26aac) /* 0.305277511 */, 19 },
+ /* 8003 */ { MAD_F(0x04e2a002) /* 0.305328379 */, 19 },
+ /* 8004 */ { MAD_F(0x04e2d55a) /* 0.305379249 */, 19 },
+ /* 8005 */ { MAD_F(0x04e30ab2) /* 0.305430121 */, 19 },
+ /* 8006 */ { MAD_F(0x04e3400a) /* 0.305480995 */, 19 },
+ /* 8007 */ { MAD_F(0x04e37563) /* 0.305531872 */, 19 },
+ /* 8008 */ { MAD_F(0x04e3aabd) /* 0.305582750 */, 19 },
+ /* 8009 */ { MAD_F(0x04e3e017) /* 0.305633631 */, 19 },
+ /* 8010 */ { MAD_F(0x04e41572) /* 0.305684513 */, 19 },
+ /* 8011 */ { MAD_F(0x04e44acd) /* 0.305735398 */, 19 },
+ /* 8012 */ { MAD_F(0x04e48029) /* 0.305786285 */, 19 },
+ /* 8013 */ { MAD_F(0x04e4b585) /* 0.305837174 */, 19 },
+ /* 8014 */ { MAD_F(0x04e4eae2) /* 0.305888066 */, 19 },
+ /* 8015 */ { MAD_F(0x04e52040) /* 0.305938959 */, 19 },
+
+ /* 8016 */ { MAD_F(0x04e5559e) /* 0.305989854 */, 19 },
+ /* 8017 */ { MAD_F(0x04e58afd) /* 0.306040752 */, 19 },
+ /* 8018 */ { MAD_F(0x04e5c05c) /* 0.306091652 */, 19 },
+ /* 8019 */ { MAD_F(0x04e5f5bc) /* 0.306142554 */, 19 },
+ /* 8020 */ { MAD_F(0x04e62b1c) /* 0.306193457 */, 19 },
+ /* 8021 */ { MAD_F(0x04e6607d) /* 0.306244364 */, 19 },
+ /* 8022 */ { MAD_F(0x04e695df) /* 0.306295272 */, 19 },
+ /* 8023 */ { MAD_F(0x04e6cb41) /* 0.306346182 */, 19 },
+ /* 8024 */ { MAD_F(0x04e700a3) /* 0.306397094 */, 19 },
+ /* 8025 */ { MAD_F(0x04e73607) /* 0.306448009 */, 19 },
+ /* 8026 */ { MAD_F(0x04e76b6b) /* 0.306498925 */, 19 },
+ /* 8027 */ { MAD_F(0x04e7a0cf) /* 0.306549844 */, 19 },
+ /* 8028 */ { MAD_F(0x04e7d634) /* 0.306600765 */, 19 },
+ /* 8029 */ { MAD_F(0x04e80b99) /* 0.306651688 */, 19 },
+ /* 8030 */ { MAD_F(0x04e84100) /* 0.306702613 */, 19 },
+ /* 8031 */ { MAD_F(0x04e87666) /* 0.306753540 */, 19 },
+
+ /* 8032 */ { MAD_F(0x04e8abcd) /* 0.306804470 */, 19 },
+ /* 8033 */ { MAD_F(0x04e8e135) /* 0.306855401 */, 19 },
+ /* 8034 */ { MAD_F(0x04e9169e) /* 0.306906334 */, 19 },
+ /* 8035 */ { MAD_F(0x04e94c07) /* 0.306957270 */, 19 },
+ /* 8036 */ { MAD_F(0x04e98170) /* 0.307008208 */, 19 },
+ /* 8037 */ { MAD_F(0x04e9b6da) /* 0.307059148 */, 19 },
+ /* 8038 */ { MAD_F(0x04e9ec45) /* 0.307110090 */, 19 },
+ /* 8039 */ { MAD_F(0x04ea21b0) /* 0.307161034 */, 19 },
+ /* 8040 */ { MAD_F(0x04ea571c) /* 0.307211980 */, 19 },
+ /* 8041 */ { MAD_F(0x04ea8c88) /* 0.307262928 */, 19 },
+ /* 8042 */ { MAD_F(0x04eac1f5) /* 0.307313879 */, 19 },
+ /* 8043 */ { MAD_F(0x04eaf762) /* 0.307364831 */, 19 },
+ /* 8044 */ { MAD_F(0x04eb2cd0) /* 0.307415786 */, 19 },
+ /* 8045 */ { MAD_F(0x04eb623f) /* 0.307466743 */, 19 },
+ /* 8046 */ { MAD_F(0x04eb97ae) /* 0.307517702 */, 19 },
+ /* 8047 */ { MAD_F(0x04ebcd1e) /* 0.307568663 */, 19 },
+
+ /* 8048 */ { MAD_F(0x04ec028e) /* 0.307619626 */, 19 },
+ /* 8049 */ { MAD_F(0x04ec37ff) /* 0.307670591 */, 19 },
+ /* 8050 */ { MAD_F(0x04ec6d71) /* 0.307721558 */, 19 },
+ /* 8051 */ { MAD_F(0x04eca2e3) /* 0.307772528 */, 19 },
+ /* 8052 */ { MAD_F(0x04ecd855) /* 0.307823499 */, 19 },
+ /* 8053 */ { MAD_F(0x04ed0dc8) /* 0.307874473 */, 19 },
+ /* 8054 */ { MAD_F(0x04ed433c) /* 0.307925449 */, 19 },
+ /* 8055 */ { MAD_F(0x04ed78b0) /* 0.307976426 */, 19 },
+ /* 8056 */ { MAD_F(0x04edae25) /* 0.308027406 */, 19 },
+ /* 8057 */ { MAD_F(0x04ede39a) /* 0.308078389 */, 19 },
+ /* 8058 */ { MAD_F(0x04ee1910) /* 0.308129373 */, 19 },
+ /* 8059 */ { MAD_F(0x04ee4e87) /* 0.308180359 */, 19 },
+ /* 8060 */ { MAD_F(0x04ee83fe) /* 0.308231347 */, 19 },
+ /* 8061 */ { MAD_F(0x04eeb976) /* 0.308282338 */, 19 },
+ /* 8062 */ { MAD_F(0x04eeeeee) /* 0.308333331 */, 19 },
+ /* 8063 */ { MAD_F(0x04ef2467) /* 0.308384325 */, 19 },
+
+ /* 8064 */ { MAD_F(0x04ef59e0) /* 0.308435322 */, 19 },
+ /* 8065 */ { MAD_F(0x04ef8f5a) /* 0.308486321 */, 19 },
+ /* 8066 */ { MAD_F(0x04efc4d5) /* 0.308537322 */, 19 },
+ /* 8067 */ { MAD_F(0x04effa50) /* 0.308588325 */, 19 },
+ /* 8068 */ { MAD_F(0x04f02fcb) /* 0.308639331 */, 19 },
+ /* 8069 */ { MAD_F(0x04f06547) /* 0.308690338 */, 19 },
+ /* 8070 */ { MAD_F(0x04f09ac4) /* 0.308741348 */, 19 },
+ /* 8071 */ { MAD_F(0x04f0d041) /* 0.308792359 */, 19 },
+ /* 8072 */ { MAD_F(0x04f105bf) /* 0.308843373 */, 19 },
+ /* 8073 */ { MAD_F(0x04f13b3e) /* 0.308894389 */, 19 },
+ /* 8074 */ { MAD_F(0x04f170bd) /* 0.308945407 */, 19 },
+ /* 8075 */ { MAD_F(0x04f1a63c) /* 0.308996427 */, 19 },
+ /* 8076 */ { MAD_F(0x04f1dbbd) /* 0.309047449 */, 19 },
+ /* 8077 */ { MAD_F(0x04f2113d) /* 0.309098473 */, 19 },
+ /* 8078 */ { MAD_F(0x04f246bf) /* 0.309149499 */, 19 },
+ /* 8079 */ { MAD_F(0x04f27c40) /* 0.309200528 */, 19 },
+
+ /* 8080 */ { MAD_F(0x04f2b1c3) /* 0.309251558 */, 19 },
+ /* 8081 */ { MAD_F(0x04f2e746) /* 0.309302591 */, 19 },
+ /* 8082 */ { MAD_F(0x04f31cc9) /* 0.309353626 */, 19 },
+ /* 8083 */ { MAD_F(0x04f3524d) /* 0.309404663 */, 19 },
+ /* 8084 */ { MAD_F(0x04f387d2) /* 0.309455702 */, 19 },
+ /* 8085 */ { MAD_F(0x04f3bd57) /* 0.309506743 */, 19 },
+ /* 8086 */ { MAD_F(0x04f3f2dd) /* 0.309557786 */, 19 },
+ /* 8087 */ { MAD_F(0x04f42864) /* 0.309608831 */, 19 },
+ /* 8088 */ { MAD_F(0x04f45dea) /* 0.309659879 */, 19 },
+ /* 8089 */ { MAD_F(0x04f49372) /* 0.309710928 */, 19 },
+ /* 8090 */ { MAD_F(0x04f4c8fa) /* 0.309761980 */, 19 },
+ /* 8091 */ { MAD_F(0x04f4fe83) /* 0.309813033 */, 19 },
+ /* 8092 */ { MAD_F(0x04f5340c) /* 0.309864089 */, 19 },
+ /* 8093 */ { MAD_F(0x04f56996) /* 0.309915147 */, 19 },
+ /* 8094 */ { MAD_F(0x04f59f20) /* 0.309966207 */, 19 },
+ /* 8095 */ { MAD_F(0x04f5d4ab) /* 0.310017269 */, 19 },
+
+ /* 8096 */ { MAD_F(0x04f60a36) /* 0.310068333 */, 19 },
+ /* 8097 */ { MAD_F(0x04f63fc2) /* 0.310119400 */, 19 },
+ /* 8098 */ { MAD_F(0x04f6754f) /* 0.310170468 */, 19 },
+ /* 8099 */ { MAD_F(0x04f6aadc) /* 0.310221539 */, 19 },
+ /* 8100 */ { MAD_F(0x04f6e06a) /* 0.310272611 */, 19 },
+ /* 8101 */ { MAD_F(0x04f715f8) /* 0.310323686 */, 19 },
+ /* 8102 */ { MAD_F(0x04f74b87) /* 0.310374763 */, 19 },
+ /* 8103 */ { MAD_F(0x04f78116) /* 0.310425842 */, 19 },
+ /* 8104 */ { MAD_F(0x04f7b6a6) /* 0.310476923 */, 19 },
+ /* 8105 */ { MAD_F(0x04f7ec37) /* 0.310528006 */, 19 },
+ /* 8106 */ { MAD_F(0x04f821c8) /* 0.310579091 */, 19 },
+ /* 8107 */ { MAD_F(0x04f85759) /* 0.310630179 */, 19 },
+ /* 8108 */ { MAD_F(0x04f88cec) /* 0.310681268 */, 19 },
+ /* 8109 */ { MAD_F(0x04f8c27e) /* 0.310732360 */, 19 },
+ /* 8110 */ { MAD_F(0x04f8f812) /* 0.310783453 */, 19 },
+ /* 8111 */ { MAD_F(0x04f92da6) /* 0.310834549 */, 19 },
+
+ /* 8112 */ { MAD_F(0x04f9633a) /* 0.310885647 */, 19 },
+ /* 8113 */ { MAD_F(0x04f998cf) /* 0.310936747 */, 19 },
+ /* 8114 */ { MAD_F(0x04f9ce65) /* 0.310987849 */, 19 },
+ /* 8115 */ { MAD_F(0x04fa03fb) /* 0.311038953 */, 19 },
+ /* 8116 */ { MAD_F(0x04fa3992) /* 0.311090059 */, 19 },
+ /* 8117 */ { MAD_F(0x04fa6f29) /* 0.311141168 */, 19 },
+ /* 8118 */ { MAD_F(0x04faa4c1) /* 0.311192278 */, 19 },
+ /* 8119 */ { MAD_F(0x04fada59) /* 0.311243390 */, 19 },
+ /* 8120 */ { MAD_F(0x04fb0ff2) /* 0.311294505 */, 19 },
+ /* 8121 */ { MAD_F(0x04fb458c) /* 0.311345622 */, 19 },
+ /* 8122 */ { MAD_F(0x04fb7b26) /* 0.311396741 */, 19 },
+ /* 8123 */ { MAD_F(0x04fbb0c1) /* 0.311447862 */, 19 },
+ /* 8124 */ { MAD_F(0x04fbe65c) /* 0.311498985 */, 19 },
+ /* 8125 */ { MAD_F(0x04fc1bf8) /* 0.311550110 */, 19 },
+ /* 8126 */ { MAD_F(0x04fc5194) /* 0.311601237 */, 19 },
+ /* 8127 */ { MAD_F(0x04fc8731) /* 0.311652366 */, 19 },
+
+ /* 8128 */ { MAD_F(0x04fcbcce) /* 0.311703498 */, 19 },
+ /* 8129 */ { MAD_F(0x04fcf26c) /* 0.311754631 */, 19 },
+ /* 8130 */ { MAD_F(0x04fd280b) /* 0.311805767 */, 19 },
+ /* 8131 */ { MAD_F(0x04fd5daa) /* 0.311856905 */, 19 },
+ /* 8132 */ { MAD_F(0x04fd934a) /* 0.311908044 */, 19 },
+ /* 8133 */ { MAD_F(0x04fdc8ea) /* 0.311959186 */, 19 },
+ /* 8134 */ { MAD_F(0x04fdfe8b) /* 0.312010330 */, 19 },
+ /* 8135 */ { MAD_F(0x04fe342c) /* 0.312061476 */, 19 },
+ /* 8136 */ { MAD_F(0x04fe69ce) /* 0.312112625 */, 19 },
+ /* 8137 */ { MAD_F(0x04fe9f71) /* 0.312163775 */, 19 },
+ /* 8138 */ { MAD_F(0x04fed514) /* 0.312214927 */, 19 },
+ /* 8139 */ { MAD_F(0x04ff0ab8) /* 0.312266082 */, 19 },
+ /* 8140 */ { MAD_F(0x04ff405c) /* 0.312317238 */, 19 },
+ /* 8141 */ { MAD_F(0x04ff7601) /* 0.312368397 */, 19 },
+ /* 8142 */ { MAD_F(0x04ffaba6) /* 0.312419558 */, 19 },
+ /* 8143 */ { MAD_F(0x04ffe14c) /* 0.312470720 */, 19 },
+
+ /* 8144 */ { MAD_F(0x050016f3) /* 0.312521885 */, 19 },
+ /* 8145 */ { MAD_F(0x05004c9a) /* 0.312573052 */, 19 },
+ /* 8146 */ { MAD_F(0x05008241) /* 0.312624222 */, 19 },
+ /* 8147 */ { MAD_F(0x0500b7e9) /* 0.312675393 */, 19 },
+ /* 8148 */ { MAD_F(0x0500ed92) /* 0.312726566 */, 19 },
+ /* 8149 */ { MAD_F(0x0501233b) /* 0.312777742 */, 19 },
+ /* 8150 */ { MAD_F(0x050158e5) /* 0.312828919 */, 19 },
+ /* 8151 */ { MAD_F(0x05018e90) /* 0.312880099 */, 19 },
+ /* 8152 */ { MAD_F(0x0501c43b) /* 0.312931280 */, 19 },
+ /* 8153 */ { MAD_F(0x0501f9e6) /* 0.312982464 */, 19 },
+ /* 8154 */ { MAD_F(0x05022f92) /* 0.313033650 */, 19 },
+ /* 8155 */ { MAD_F(0x0502653f) /* 0.313084838 */, 19 },
+ /* 8156 */ { MAD_F(0x05029aec) /* 0.313136028 */, 19 },
+ /* 8157 */ { MAD_F(0x0502d09a) /* 0.313187220 */, 19 },
+ /* 8158 */ { MAD_F(0x05030648) /* 0.313238414 */, 19 },
+ /* 8159 */ { MAD_F(0x05033bf7) /* 0.313289611 */, 19 },
+
+ /* 8160 */ { MAD_F(0x050371a7) /* 0.313340809 */, 19 },
+ /* 8161 */ { MAD_F(0x0503a757) /* 0.313392010 */, 19 },
+ /* 8162 */ { MAD_F(0x0503dd07) /* 0.313443212 */, 19 },
+ /* 8163 */ { MAD_F(0x050412b9) /* 0.313494417 */, 19 },
+ /* 8164 */ { MAD_F(0x0504486a) /* 0.313545624 */, 19 },
+ /* 8165 */ { MAD_F(0x05047e1d) /* 0.313596833 */, 19 },
+ /* 8166 */ { MAD_F(0x0504b3cf) /* 0.313648044 */, 19 },
+ /* 8167 */ { MAD_F(0x0504e983) /* 0.313699257 */, 19 },
+ /* 8168 */ { MAD_F(0x05051f37) /* 0.313750472 */, 19 },
+ /* 8169 */ { MAD_F(0x050554eb) /* 0.313801689 */, 19 },
+ /* 8170 */ { MAD_F(0x05058aa0) /* 0.313852909 */, 19 },
+ /* 8171 */ { MAD_F(0x0505c056) /* 0.313904130 */, 19 },
+ /* 8172 */ { MAD_F(0x0505f60c) /* 0.313955354 */, 19 },
+ /* 8173 */ { MAD_F(0x05062bc3) /* 0.314006579 */, 19 },
+ /* 8174 */ { MAD_F(0x0506617a) /* 0.314057807 */, 19 },
+ /* 8175 */ { MAD_F(0x05069732) /* 0.314109037 */, 19 },
+
+ /* 8176 */ { MAD_F(0x0506cceb) /* 0.314160269 */, 19 },
+ /* 8177 */ { MAD_F(0x050702a4) /* 0.314211502 */, 19 },
+ /* 8178 */ { MAD_F(0x0507385d) /* 0.314262739 */, 19 },
+ /* 8179 */ { MAD_F(0x05076e17) /* 0.314313977 */, 19 },
+ /* 8180 */ { MAD_F(0x0507a3d2) /* 0.314365217 */, 19 },
+ /* 8181 */ { MAD_F(0x0507d98d) /* 0.314416459 */, 19 },
+ /* 8182 */ { MAD_F(0x05080f49) /* 0.314467704 */, 19 },
+ /* 8183 */ { MAD_F(0x05084506) /* 0.314518950 */, 19 },
+ /* 8184 */ { MAD_F(0x05087ac2) /* 0.314570199 */, 19 },
+ /* 8185 */ { MAD_F(0x0508b080) /* 0.314621449 */, 19 },
+ /* 8186 */ { MAD_F(0x0508e63e) /* 0.314672702 */, 19 },
+ /* 8187 */ { MAD_F(0x05091bfd) /* 0.314723957 */, 19 },
+ /* 8188 */ { MAD_F(0x050951bc) /* 0.314775214 */, 19 },
+ /* 8189 */ { MAD_F(0x0509877c) /* 0.314826473 */, 19 },
+ /* 8190 */ { MAD_F(0x0509bd3c) /* 0.314877734 */, 19 },
+ /* 8191 */ { MAD_F(0x0509f2fd) /* 0.314928997 */, 19 },
+
+ /* 8192 */ { MAD_F(0x050a28be) /* 0.314980262 */, 19 },
+ /* 8193 */ { MAD_F(0x050a5e80) /* 0.315031530 */, 19 },
+ /* 8194 */ { MAD_F(0x050a9443) /* 0.315082799 */, 19 },
+ /* 8195 */ { MAD_F(0x050aca06) /* 0.315134071 */, 19 },
+ /* 8196 */ { MAD_F(0x050affc9) /* 0.315185344 */, 19 },
+ /* 8197 */ { MAD_F(0x050b358e) /* 0.315236620 */, 19 },
+ /* 8198 */ { MAD_F(0x050b6b52) /* 0.315287898 */, 19 },
+ /* 8199 */ { MAD_F(0x050ba118) /* 0.315339178 */, 19 },
+ /* 8200 */ { MAD_F(0x050bd6de) /* 0.315390460 */, 19 },
+ /* 8201 */ { MAD_F(0x050c0ca4) /* 0.315441744 */, 19 },
+ /* 8202 */ { MAD_F(0x050c426b) /* 0.315493030 */, 19 },
+ /* 8203 */ { MAD_F(0x050c7833) /* 0.315544318 */, 19 },
+ /* 8204 */ { MAD_F(0x050cadfb) /* 0.315595608 */, 19 },
+ /* 8205 */ { MAD_F(0x050ce3c4) /* 0.315646901 */, 19 },
+ /* 8206 */ { MAD_F(0x050d198d) /* 0.315698195 */, 19 }
diff --git a/contrib/libmad/sf_table.dat b/contrib/libmad/sf_table.dat
new file mode 100644
index 000000000..db1484a0e
--- /dev/null
+++ b/contrib/libmad/sf_table.dat
@@ -0,0 +1,106 @@
+/*
+ * libmad - MPEG audio decoder library
+ * Copyright (C) 2000-2004 Underbit Technologies, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: sf_table.dat,v 1.7 2004/01/23 09:41:33 rob Exp $
+ */
+
+/*
+ * These are the scalefactor values for Layer I and Layer II.
+ * The values are from Table B.1 of ISO/IEC 11172-3.
+ *
+ * There is some error introduced by the 32-bit fixed-point representation;
+ * the amount of error is shown. For 16-bit PCM output, this shouldn't be
+ * too much of a problem.
+ *
+ * Strictly speaking, Table B.1 has only 63 entries (0-62), thus a strict
+ * interpretation of ISO/IEC 11172-3 would suggest that a scalefactor index of
+ * 63 is invalid. However, for better compatibility with current practices, we
+ * add a 64th entry.
+ */
+
+ MAD_F(0x20000000), /* 2.000000000000 => 2.000000000000, e 0.000000000000 */
+ MAD_F(0x1965fea5), /* 1.587401051968 => 1.587401051074, e 0.000000000894 */
+ MAD_F(0x1428a2fa), /* 1.259921049895 => 1.259921051562, e -0.000000001667 */
+ MAD_F(0x10000000), /* 1.000000000000 => 1.000000000000, e 0.000000000000 */
+ MAD_F(0x0cb2ff53), /* 0.793700525984 => 0.793700527400, e -0.000000001416 */
+ MAD_F(0x0a14517d), /* 0.629960524947 => 0.629960525781, e -0.000000000833 */
+ MAD_F(0x08000000), /* 0.500000000000 => 0.500000000000, e 0.000000000000 */
+ MAD_F(0x06597fa9), /* 0.396850262992 => 0.396850261837, e 0.000000001155 */
+
+ MAD_F(0x050a28be), /* 0.314980262474 => 0.314980261028, e 0.000000001446 */
+ MAD_F(0x04000000), /* 0.250000000000 => 0.250000000000, e 0.000000000000 */
+ MAD_F(0x032cbfd5), /* 0.198425131496 => 0.198425132781, e -0.000000001285 */
+ MAD_F(0x0285145f), /* 0.157490131237 => 0.157490130514, e 0.000000000723 */
+ MAD_F(0x02000000), /* 0.125000000000 => 0.125000000000, e 0.000000000000 */
+ MAD_F(0x01965fea), /* 0.099212565748 => 0.099212564528, e 0.000000001220 */
+ MAD_F(0x01428a30), /* 0.078745065618 => 0.078745067120, e -0.000000001501 */
+ MAD_F(0x01000000), /* 0.062500000000 => 0.062500000000, e 0.000000000000 */
+
+ MAD_F(0x00cb2ff5), /* 0.049606282874 => 0.049606282264, e 0.000000000610 */
+ MAD_F(0x00a14518), /* 0.039372532809 => 0.039372533560, e -0.000000000751 */
+ MAD_F(0x00800000), /* 0.031250000000 => 0.031250000000, e 0.000000000000 */
+ MAD_F(0x006597fb), /* 0.024803141437 => 0.024803142995, e -0.000000001558 */
+ MAD_F(0x0050a28c), /* 0.019686266405 => 0.019686266780, e -0.000000000375 */
+ MAD_F(0x00400000), /* 0.015625000000 => 0.015625000000, e 0.000000000000 */
+ MAD_F(0x0032cbfd), /* 0.012401570719 => 0.012401569635, e 0.000000001084 */
+ MAD_F(0x00285146), /* 0.009843133202 => 0.009843133390, e -0.000000000188 */
+
+ MAD_F(0x00200000), /* 0.007812500000 => 0.007812500000, e 0.000000000000 */
+ MAD_F(0x001965ff), /* 0.006200785359 => 0.006200786680, e -0.000000001321 */
+ MAD_F(0x001428a3), /* 0.004921566601 => 0.004921566695, e -0.000000000094 */
+ MAD_F(0x00100000), /* 0.003906250000 => 0.003906250000, e 0.000000000000 */
+ MAD_F(0x000cb2ff), /* 0.003100392680 => 0.003100391477, e 0.000000001202 */
+ MAD_F(0x000a1451), /* 0.002460783301 => 0.002460781485, e 0.000000001816 */
+ MAD_F(0x00080000), /* 0.001953125000 => 0.001953125000, e 0.000000000000 */
+ MAD_F(0x00065980), /* 0.001550196340 => 0.001550197601, e -0.000000001262 */
+
+ MAD_F(0x00050a29), /* 0.001230391650 => 0.001230392605, e -0.000000000955 */
+ MAD_F(0x00040000), /* 0.000976562500 => 0.000976562500, e 0.000000000000 */
+ MAD_F(0x00032cc0), /* 0.000775098170 => 0.000775098801, e -0.000000000631 */
+ MAD_F(0x00028514), /* 0.000615195825 => 0.000615194440, e 0.000000001385 */
+ MAD_F(0x00020000), /* 0.000488281250 => 0.000488281250, e 0.000000000000 */
+ MAD_F(0x00019660), /* 0.000387549085 => 0.000387549400, e -0.000000000315 */
+ MAD_F(0x0001428a), /* 0.000307597913 => 0.000307597220, e 0.000000000693 */
+ MAD_F(0x00010000), /* 0.000244140625 => 0.000244140625, e 0.000000000000 */
+
+ MAD_F(0x0000cb30), /* 0.000193774542 => 0.000193774700, e -0.000000000158 */
+ MAD_F(0x0000a145), /* 0.000153798956 => 0.000153798610, e 0.000000000346 */
+ MAD_F(0x00008000), /* 0.000122070313 => 0.000122070313, e 0.000000000000 */
+ MAD_F(0x00006598), /* 0.000096887271 => 0.000096887350, e -0.000000000079 */
+ MAD_F(0x000050a3), /* 0.000076899478 => 0.000076901168, e -0.000000001689 */
+ MAD_F(0x00004000), /* 0.000061035156 => 0.000061035156, e 0.000000000000 */
+ MAD_F(0x000032cc), /* 0.000048443636 => 0.000048443675, e -0.000000000039 */
+ MAD_F(0x00002851), /* 0.000038449739 => 0.000038448721, e 0.000000001018 */
+
+ MAD_F(0x00002000), /* 0.000030517578 => 0.000030517578, e 0.000000000000 */
+ MAD_F(0x00001966), /* 0.000024221818 => 0.000024221838, e -0.000000000020 */
+ MAD_F(0x00001429), /* 0.000019224870 => 0.000019226223, e -0.000000001354 */
+ MAD_F(0x00001000), /* 0.000015258789 => 0.000015258789, e -0.000000000000 */
+ MAD_F(0x00000cb3), /* 0.000012110909 => 0.000012110919, e -0.000000000010 */
+ MAD_F(0x00000a14), /* 0.000009612435 => 0.000009611249, e 0.000000001186 */
+ MAD_F(0x00000800), /* 0.000007629395 => 0.000007629395, e -0.000000000000 */
+ MAD_F(0x00000659), /* 0.000006055454 => 0.000006053597, e 0.000000001858 */
+
+ MAD_F(0x0000050a), /* 0.000004806217 => 0.000004805624, e 0.000000000593 */
+ MAD_F(0x00000400), /* 0.000003814697 => 0.000003814697, e 0.000000000000 */
+ MAD_F(0x0000032d), /* 0.000003027727 => 0.000003028661, e -0.000000000934 */
+ MAD_F(0x00000285), /* 0.000002403109 => 0.000002402812, e 0.000000000296 */
+ MAD_F(0x00000200), /* 0.000001907349 => 0.000001907349, e -0.000000000000 */
+ MAD_F(0x00000196), /* 0.000001513864 => 0.000001512468, e 0.000000001396 */
+ MAD_F(0x00000143), /* 0.000001201554 => 0.000001203269, e -0.000000001714 */
+ MAD_F(0x00000000) /* this compatibility entry is not part of Table B.1 */
diff --git a/contrib/libmad/stream.c b/contrib/libmad/stream.c
new file mode 100644
index 000000000..8bb4d6a49
--- /dev/null
+++ b/contrib/libmad/stream.c
@@ -0,0 +1,161 @@
+/*
+ * libmad - MPEG audio decoder library
+ * Copyright (C) 2000-2004 Underbit Technologies, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: stream.c,v 1.12 2004/02/05 09:02:39 rob Exp $
+ */
+
+# ifdef HAVE_CONFIG_H
+# include "config.h"
+# endif
+
+# include "global.h"
+
+# include <stdlib.h>
+
+# include "bit.h"
+# include "stream.h"
+
+/*
+ * NAME: stream->init()
+ * DESCRIPTION: initialize stream struct
+ */
+void mad_stream_init(struct mad_stream *stream)
+{
+ stream->buffer = 0;
+ stream->bufend = 0;
+ stream->skiplen = 0;
+
+ stream->sync = 0;
+ stream->freerate = 0;
+
+ stream->this_frame = 0;
+ stream->next_frame = 0;
+ mad_bit_init(&stream->ptr, 0);
+
+ mad_bit_init(&stream->anc_ptr, 0);
+ stream->anc_bitlen = 0;
+
+ stream->main_data = 0;
+ stream->md_len = 0;
+
+ stream->options = 0;
+ stream->error = MAD_ERROR_NONE;
+}
+
+/*
+ * NAME: stream->finish()
+ * DESCRIPTION: deallocate any dynamic memory associated with stream
+ */
+void mad_stream_finish(struct mad_stream *stream)
+{
+ if (stream->main_data) {
+ free(stream->main_data);
+ stream->main_data = 0;
+ }
+
+ mad_bit_finish(&stream->anc_ptr);
+ mad_bit_finish(&stream->ptr);
+}
+
+/*
+ * NAME: stream->buffer()
+ * DESCRIPTION: set stream buffer pointers
+ */
+void mad_stream_buffer(struct mad_stream *stream,
+ unsigned char const *buffer, unsigned long length)
+{
+ stream->buffer = buffer;
+ stream->bufend = buffer + length;
+
+ stream->this_frame = buffer;
+ stream->next_frame = buffer;
+
+ stream->sync = 1;
+
+ mad_bit_init(&stream->ptr, buffer);
+}
+
+/*
+ * NAME: stream->skip()
+ * DESCRIPTION: arrange to skip bytes before the next frame
+ */
+void mad_stream_skip(struct mad_stream *stream, unsigned long length)
+{
+ stream->skiplen += length;
+}
+
+/*
+ * NAME: stream->sync()
+ * DESCRIPTION: locate the next stream sync word
+ */
+int mad_stream_sync(struct mad_stream *stream)
+{
+ register unsigned char const *ptr, *end;
+
+ ptr = mad_bit_nextbyte(&stream->ptr);
+ end = stream->bufend;
+
+ while (ptr < end - 1 &&
+ !(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0))
+ ++ptr;
+
+ if (end - ptr < MAD_BUFFER_GUARD)
+ return -1;
+
+ mad_bit_init(&stream->ptr, ptr);
+
+ return 0;
+}
+
+/*
+ * NAME: stream->errorstr()
+ * DESCRIPTION: return a string description of the current error condition
+ */
+char const *mad_stream_errorstr(struct mad_stream const *stream)
+{
+ switch (stream->error) {
+ case MAD_ERROR_NONE: return "no error";
+
+ case MAD_ERROR_BUFLEN: return "input buffer too small (or EOF)";
+ case MAD_ERROR_BUFPTR: return "invalid (null) buffer pointer";
+
+ case MAD_ERROR_NOMEM: return "not enough memory";
+
+ case MAD_ERROR_LOSTSYNC: return "lost synchronization";
+ case MAD_ERROR_BADLAYER: return "reserved header layer value";
+ case MAD_ERROR_BADBITRATE: return "forbidden bitrate value";
+ case MAD_ERROR_BADSAMPLERATE: return "reserved sample frequency value";
+ case MAD_ERROR_BADEMPHASIS: return "reserved emphasis value";
+
+ case MAD_ERROR_BADCRC: return "CRC check failed";
+ case MAD_ERROR_BADBITALLOC: return "forbidden bit allocation value";
+ case MAD_ERROR_BADSCALEFACTOR: return "bad scalefactor index";
+ case MAD_ERROR_BADMODE: return "bad bitrate/mode combination";
+ case MAD_ERROR_BADFRAMELEN: return "bad frame length";
+ case MAD_ERROR_BADBIGVALUES: return "bad big_values count";
+ case MAD_ERROR_BADBLOCKTYPE: return "reserved block_type";
+ case MAD_ERROR_BADSCFSI: return "bad scalefactor selection info";
+ case MAD_ERROR_BADDATAPTR: return "bad main_data_begin pointer";
+ case MAD_ERROR_BADPART3LEN: return "bad audio data length";
+ case MAD_ERROR_BADHUFFTABLE: return "bad Huffman table select";
+ case MAD_ERROR_BADHUFFDATA: return "Huffman data overrun";
+ case MAD_ERROR_BADSTEREO: return "incompatible block_type for JS";
+ }
+
+ return 0;
+}
diff --git a/contrib/libmad/stream.h b/contrib/libmad/stream.h
new file mode 100644
index 000000000..8bff8b49d
--- /dev/null
+++ b/contrib/libmad/stream.h
@@ -0,0 +1,108 @@
+/*
+ * libmad - MPEG audio decoder library
+ * Copyright (C) 2000-2004 Underbit Technologies, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: stream.h,v 1.20 2004/02/05 09:02:39 rob Exp $
+ */
+
+# ifndef LIBMAD_STREAM_H
+# define LIBMAD_STREAM_H
+
+# include "bit.h"
+
+# define MAD_BUFFER_GUARD 8
+# define MAD_BUFFER_MDLEN (511 + 2048 + MAD_BUFFER_GUARD)
+
+enum mad_error {
+ MAD_ERROR_NONE = 0x0000, /* no error */
+
+ MAD_ERROR_BUFLEN = 0x0001, /* input buffer too small (or EOF) */
+ MAD_ERROR_BUFPTR = 0x0002, /* invalid (null) buffer pointer */
+
+ MAD_ERROR_NOMEM = 0x0031, /* not enough memory */
+
+ MAD_ERROR_LOSTSYNC = 0x0101, /* lost synchronization */
+ MAD_ERROR_BADLAYER = 0x0102, /* reserved header layer value */
+ MAD_ERROR_BADBITRATE = 0x0103, /* forbidden bitrate value */
+ MAD_ERROR_BADSAMPLERATE = 0x0104, /* reserved sample frequency value */
+ MAD_ERROR_BADEMPHASIS = 0x0105, /* reserved emphasis value */
+
+ MAD_ERROR_BADCRC = 0x0201, /* CRC check failed */
+ MAD_ERROR_BADBITALLOC = 0x0211, /* forbidden bit allocation value */
+ MAD_ERROR_BADSCALEFACTOR = 0x0221, /* bad scalefactor index */
+ MAD_ERROR_BADMODE = 0x0222, /* bad bitrate/mode combination */
+ MAD_ERROR_BADFRAMELEN = 0x0231, /* bad frame length */
+ MAD_ERROR_BADBIGVALUES = 0x0232, /* bad big_values count */
+ MAD_ERROR_BADBLOCKTYPE = 0x0233, /* reserved block_type */
+ MAD_ERROR_BADSCFSI = 0x0234, /* bad scalefactor selection info */
+ MAD_ERROR_BADDATAPTR = 0x0235, /* bad main_data_begin pointer */
+ MAD_ERROR_BADPART3LEN = 0x0236, /* bad audio data length */
+ MAD_ERROR_BADHUFFTABLE = 0x0237, /* bad Huffman table select */
+ MAD_ERROR_BADHUFFDATA = 0x0238, /* Huffman data overrun */
+ MAD_ERROR_BADSTEREO = 0x0239 /* incompatible block_type for JS */
+};
+
+# define MAD_RECOVERABLE(error) ((error) & 0xff00)
+
+struct mad_stream {
+ unsigned char const *buffer; /* input bitstream buffer */
+ unsigned char const *bufend; /* end of buffer */
+ unsigned long skiplen; /* bytes to skip before next frame */
+
+ int sync; /* stream sync found */
+ unsigned long freerate; /* free bitrate (fixed) */
+
+ unsigned char const *this_frame; /* start of current frame */
+ unsigned char const *next_frame; /* start of next frame */
+ struct mad_bitptr ptr; /* current processing bit pointer */
+
+ struct mad_bitptr anc_ptr; /* ancillary bits pointer */
+ unsigned int anc_bitlen; /* number of ancillary bits */
+
+ unsigned char (*main_data)[MAD_BUFFER_MDLEN];
+ /* Layer III main_data() */
+ unsigned int md_len; /* bytes in main_data */
+
+ int options; /* decoding options (see below) */
+ enum mad_error error; /* error code (see above) */
+};
+
+enum {
+ MAD_OPTION_IGNORECRC = 0x0001, /* ignore CRC errors */
+ MAD_OPTION_HALFSAMPLERATE = 0x0002 /* generate PCM at 1/2 sample rate */
+# if 0 /* not yet implemented */
+ MAD_OPTION_LEFTCHANNEL = 0x0010, /* decode left channel only */
+ MAD_OPTION_RIGHTCHANNEL = 0x0020, /* decode right channel only */
+ MAD_OPTION_SINGLECHANNEL = 0x0030 /* combine channels */
+# endif
+};
+
+void mad_stream_init(struct mad_stream *);
+void mad_stream_finish(struct mad_stream *);
+
+# define mad_stream_options(stream, opts) \
+ ((void) ((stream)->options = (opts)))
+
+void mad_stream_buffer(struct mad_stream *,
+ unsigned char const *, unsigned long);
+void mad_stream_skip(struct mad_stream *, unsigned long);
+
+int mad_stream_sync(struct mad_stream *);
+
+char const *mad_stream_errorstr(struct mad_stream const *);
+
+# endif
diff --git a/contrib/libmad/synth.c b/contrib/libmad/synth.c
new file mode 100644
index 000000000..1d28d438c
--- /dev/null
+++ b/contrib/libmad/synth.c
@@ -0,0 +1,857 @@
+/*
+ * libmad - MPEG audio decoder library
+ * Copyright (C) 2000-2004 Underbit Technologies, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: synth.c,v 1.25 2004/01/23 09:41:33 rob Exp $
+ */
+
+# ifdef HAVE_CONFIG_H
+# include "config.h"
+# endif
+
+# include "global.h"
+
+# include "fixed.h"
+# include "frame.h"
+# include "synth.h"
+
+/*
+ * NAME: synth->init()
+ * DESCRIPTION: initialize synth struct
+ */
+void mad_synth_init(struct mad_synth *synth)
+{
+ mad_synth_mute(synth);
+
+ synth->phase = 0;
+
+ synth->pcm.samplerate = 0;
+ synth->pcm.channels = 0;
+ synth->pcm.length = 0;
+}
+
+/*
+ * NAME: synth->mute()
+ * DESCRIPTION: zero all polyphase filterbank values, resetting synthesis
+ */
+void mad_synth_mute(struct mad_synth *synth)
+{
+ unsigned int ch, s, v;
+
+ for (ch = 0; ch < 2; ++ch) {
+ for (s = 0; s < 16; ++s) {
+ for (v = 0; v < 8; ++v) {
+ synth->filter[ch][0][0][s][v] = synth->filter[ch][0][1][s][v] =
+ synth->filter[ch][1][0][s][v] = synth->filter[ch][1][1][s][v] = 0;
+ }
+ }
+ }
+}
+
+/*
+ * An optional optimization called here the Subband Synthesis Optimization
+ * (SSO) improves the performance of subband synthesis at the expense of
+ * accuracy.
+ *
+ * The idea is to simplify 32x32->64-bit multiplication to 32x32->32 such
+ * that extra scaling and rounding are not necessary. This often allows the
+ * compiler to use faster 32-bit multiply-accumulate instructions instead of
+ * explicit 64-bit multiply, shift, and add instructions.
+ *
+ * SSO works like this: a full 32x32->64-bit multiply of two mad_fixed_t
+ * values requires the result to be right-shifted 28 bits to be properly
+ * scaled to the same fixed-point format. Right shifts can be applied at any
+ * time to either operand or to the result, so the optimization involves
+ * careful placement of these shifts to minimize the loss of accuracy.
+ *
+ * First, a 14-bit shift is applied with rounding at compile-time to the D[]
+ * table of coefficients for the subband synthesis window. This only loses 2
+ * bits of accuracy because the lower 12 bits are always zero. A second
+ * 12-bit shift occurs after the DCT calculation. This loses 12 bits of
+ * accuracy. Finally, a third 2-bit shift occurs just before the sample is
+ * saved in the PCM buffer. 14 + 12 + 2 == 28 bits.
+ */
+
+/* FPM_DEFAULT without OPT_SSO will actually lose accuracy and performance */
+
+# if defined(FPM_DEFAULT) && !defined(OPT_SSO)
+# define OPT_SSO
+# endif
+
+/* second SSO shift, with rounding */
+
+# if defined(OPT_SSO)
+# define SHIFT(x) (((x) + (1L << 11)) >> 12)
+# else
+# define SHIFT(x) (x)
+# endif
+
+/* possible DCT speed optimization */
+
+# if defined(OPT_SPEED) && defined(MAD_F_MLX)
+# define OPT_DCTO
+# define MUL(x, y) \
+ ({ mad_fixed64hi_t hi; \
+ mad_fixed64lo_t lo; \
+ MAD_F_MLX(hi, lo, (x), (y)); \
+ hi << (32 - MAD_F_SCALEBITS - 3); \
+ })
+# else
+# undef OPT_DCTO
+# define MUL(x, y) mad_f_mul((x), (y))
+# endif
+
+/*
+ * NAME: dct32()
+ * DESCRIPTION: perform fast in[32]->out[32] DCT
+ */
+static
+void dct32(mad_fixed_t const in[32], unsigned int slot,
+ mad_fixed_t lo[16][8], mad_fixed_t hi[16][8])
+{
+ mad_fixed_t t0, t1, t2, t3, t4, t5, t6, t7;
+ mad_fixed_t t8, t9, t10, t11, t12, t13, t14, t15;
+ mad_fixed_t t16, t17, t18, t19, t20, t21, t22, t23;
+ mad_fixed_t t24, t25, t26, t27, t28, t29, t30, t31;
+ mad_fixed_t t32, t33, t34, t35, t36, t37, t38, t39;
+ mad_fixed_t t40, t41, t42, t43, t44, t45, t46, t47;
+ mad_fixed_t t48, t49, t50, t51, t52, t53, t54, t55;
+ mad_fixed_t t56, t57, t58, t59, t60, t61, t62, t63;
+ mad_fixed_t t64, t65, t66, t67, t68, t69, t70, t71;
+ mad_fixed_t t72, t73, t74, t75, t76, t77, t78, t79;
+ mad_fixed_t t80, t81, t82, t83, t84, t85, t86, t87;
+ mad_fixed_t t88, t89, t90, t91, t92, t93, t94, t95;
+ mad_fixed_t t96, t97, t98, t99, t100, t101, t102, t103;
+ mad_fixed_t t104, t105, t106, t107, t108, t109, t110, t111;
+ mad_fixed_t t112, t113, t114, t115, t116, t117, t118, t119;
+ mad_fixed_t t120, t121, t122, t123, t124, t125, t126, t127;
+ mad_fixed_t t128, t129, t130, t131, t132, t133, t134, t135;
+ mad_fixed_t t136, t137, t138, t139, t140, t141, t142, t143;
+ mad_fixed_t t144, t145, t146, t147, t148, t149, t150, t151;
+ mad_fixed_t t152, t153, t154, t155, t156, t157, t158, t159;
+ mad_fixed_t t160, t161, t162, t163, t164, t165, t166, t167;
+ mad_fixed_t t168, t169, t170, t171, t172, t173, t174, t175;
+ mad_fixed_t t176;
+
+ /* costab[i] = cos(PI / (2 * 32) * i) */
+
+# if defined(OPT_DCTO)
+# define costab1 MAD_F(0x7fd8878e)
+# define costab2 MAD_F(0x7f62368f)
+# define costab3 MAD_F(0x7e9d55fc)
+# define costab4 MAD_F(0x7d8a5f40)
+# define costab5 MAD_F(0x7c29fbee)
+# define costab6 MAD_F(0x7a7d055b)
+# define costab7 MAD_F(0x78848414)
+# define costab8 MAD_F(0x7641af3d)
+# define costab9 MAD_F(0x73b5ebd1)
+# define costab10 MAD_F(0x70e2cbc6)
+# define costab11 MAD_F(0x6dca0d14)
+# define costab12 MAD_F(0x6a6d98a4)
+# define costab13 MAD_F(0x66cf8120)
+# define costab14 MAD_F(0x62f201ac)
+# define costab15 MAD_F(0x5ed77c8a)
+# define costab16 MAD_F(0x5a82799a)
+# define costab17 MAD_F(0x55f5a4d2)
+# define costab18 MAD_F(0x5133cc94)
+# define costab19 MAD_F(0x4c3fdff4)
+# define costab20 MAD_F(0x471cece7)
+# define costab21 MAD_F(0x41ce1e65)
+# define costab22 MAD_F(0x3c56ba70)
+# define costab23 MAD_F(0x36ba2014)
+# define costab24 MAD_F(0x30fbc54d)
+# define costab25 MAD_F(0x2b1f34eb)
+# define costab26 MAD_F(0x25280c5e)
+# define costab27 MAD_F(0x1f19f97b)
+# define costab28 MAD_F(0x18f8b83c)
+# define costab29 MAD_F(0x12c8106f)
+# define costab30 MAD_F(0x0c8bd35e)
+# define costab31 MAD_F(0x0647d97c)
+# else
+# define costab1 MAD_F(0x0ffb10f2) /* 0.998795456 */
+# define costab2 MAD_F(0x0fec46d2) /* 0.995184727 */
+# define costab3 MAD_F(0x0fd3aac0) /* 0.989176510 */
+# define costab4 MAD_F(0x0fb14be8) /* 0.980785280 */
+# define costab5 MAD_F(0x0f853f7e) /* 0.970031253 */
+# define costab6 MAD_F(0x0f4fa0ab) /* 0.956940336 */
+# define costab7 MAD_F(0x0f109082) /* 0.941544065 */
+# define costab8 MAD_F(0x0ec835e8) /* 0.923879533 */
+# define costab9 MAD_F(0x0e76bd7a) /* 0.903989293 */
+# define costab10 MAD_F(0x0e1c5979) /* 0.881921264 */
+# define costab11 MAD_F(0x0db941a3) /* 0.857728610 */
+# define costab12 MAD_F(0x0d4db315) /* 0.831469612 */
+# define costab13 MAD_F(0x0cd9f024) /* 0.803207531 */
+# define costab14 MAD_F(0x0c5e4036) /* 0.773010453 */
+# define costab15 MAD_F(0x0bdaef91) /* 0.740951125 */
+# define costab16 MAD_F(0x0b504f33) /* 0.707106781 */
+# define costab17 MAD_F(0x0abeb49a) /* 0.671558955 */
+# define costab18 MAD_F(0x0a267993) /* 0.634393284 */
+# define costab19 MAD_F(0x0987fbfe) /* 0.595699304 */
+# define costab20 MAD_F(0x08e39d9d) /* 0.555570233 */
+# define costab21 MAD_F(0x0839c3cd) /* 0.514102744 */
+# define costab22 MAD_F(0x078ad74e) /* 0.471396737 */
+# define costab23 MAD_F(0x06d74402) /* 0.427555093 */
+# define costab24 MAD_F(0x061f78aa) /* 0.382683432 */
+# define costab25 MAD_F(0x0563e69d) /* 0.336889853 */
+# define costab26 MAD_F(0x04a5018c) /* 0.290284677 */
+# define costab27 MAD_F(0x03e33f2f) /* 0.242980180 */
+# define costab28 MAD_F(0x031f1708) /* 0.195090322 */
+# define costab29 MAD_F(0x0259020e) /* 0.146730474 */
+# define costab30 MAD_F(0x01917a6c) /* 0.098017140 */
+# define costab31 MAD_F(0x00c8fb30) /* 0.049067674 */
+# endif
+
+ t0 = in[0] + in[31]; t16 = MUL(in[0] - in[31], costab1);
+ t1 = in[15] + in[16]; t17 = MUL(in[15] - in[16], costab31);
+
+ t41 = t16 + t17;
+ t59 = MUL(t16 - t17, costab2);
+ t33 = t0 + t1;
+ t50 = MUL(t0 - t1, costab2);
+
+ t2 = in[7] + in[24]; t18 = MUL(in[7] - in[24], costab15);
+ t3 = in[8] + in[23]; t19 = MUL(in[8] - in[23], costab17);
+
+ t42 = t18 + t19;
+ t60 = MUL(t18 - t19, costab30);
+ t34 = t2 + t3;
+ t51 = MUL(t2 - t3, costab30);
+
+ t4 = in[3] + in[28]; t20 = MUL(in[3] - in[28], costab7);
+ t5 = in[12] + in[19]; t21 = MUL(in[12] - in[19], costab25);
+
+ t43 = t20 + t21;
+ t61 = MUL(t20 - t21, costab14);
+ t35 = t4 + t5;
+ t52 = MUL(t4 - t5, costab14);
+
+ t6 = in[4] + in[27]; t22 = MUL(in[4] - in[27], costab9);
+ t7 = in[11] + in[20]; t23 = MUL(in[11] - in[20], costab23);
+
+ t44 = t22 + t23;
+ t62 = MUL(t22 - t23, costab18);
+ t36 = t6 + t7;
+ t53 = MUL(t6 - t7, costab18);
+
+ t8 = in[1] + in[30]; t24 = MUL(in[1] - in[30], costab3);
+ t9 = in[14] + in[17]; t25 = MUL(in[14] - in[17], costab29);
+
+ t45 = t24 + t25;
+ t63 = MUL(t24 - t25, costab6);
+ t37 = t8 + t9;
+ t54 = MUL(t8 - t9, costab6);
+
+ t10 = in[6] + in[25]; t26 = MUL(in[6] - in[25], costab13);
+ t11 = in[9] + in[22]; t27 = MUL(in[9] - in[22], costab19);
+
+ t46 = t26 + t27;
+ t64 = MUL(t26 - t27, costab26);
+ t38 = t10 + t11;
+ t55 = MUL(t10 - t11, costab26);
+
+ t12 = in[2] + in[29]; t28 = MUL(in[2] - in[29], costab5);
+ t13 = in[13] + in[18]; t29 = MUL(in[13] - in[18], costab27);
+
+ t47 = t28 + t29;
+ t65 = MUL(t28 - t29, costab10);
+ t39 = t12 + t13;
+ t56 = MUL(t12 - t13, costab10);
+
+ t14 = in[5] + in[26]; t30 = MUL(in[5] - in[26], costab11);
+ t15 = in[10] + in[21]; t31 = MUL(in[10] - in[21], costab21);
+
+ t48 = t30 + t31;
+ t66 = MUL(t30 - t31, costab22);
+ t40 = t14 + t15;
+ t57 = MUL(t14 - t15, costab22);
+
+ t69 = t33 + t34; t89 = MUL(t33 - t34, costab4);
+ t70 = t35 + t36; t90 = MUL(t35 - t36, costab28);
+ t71 = t37 + t38; t91 = MUL(t37 - t38, costab12);
+ t72 = t39 + t40; t92 = MUL(t39 - t40, costab20);
+ t73 = t41 + t42; t94 = MUL(t41 - t42, costab4);
+ t74 = t43 + t44; t95 = MUL(t43 - t44, costab28);
+ t75 = t45 + t46; t96 = MUL(t45 - t46, costab12);
+ t76 = t47 + t48; t97 = MUL(t47 - t48, costab20);
+
+ t78 = t50 + t51; t100 = MUL(t50 - t51, costab4);
+ t79 = t52 + t53; t101 = MUL(t52 - t53, costab28);
+ t80 = t54 + t55; t102 = MUL(t54 - t55, costab12);
+ t81 = t56 + t57; t103 = MUL(t56 - t57, costab20);
+
+ t83 = t59 + t60; t106 = MUL(t59 - t60, costab4);
+ t84 = t61 + t62; t107 = MUL(t61 - t62, costab28);
+ t85 = t63 + t64; t108 = MUL(t63 - t64, costab12);
+ t86 = t65 + t66; t109 = MUL(t65 - t66, costab20);
+
+ t113 = t69 + t70;
+ t114 = t71 + t72;
+
+ /* 0 */ hi[15][slot] = SHIFT(t113 + t114);
+ /* 16 */ lo[ 0][slot] = SHIFT(MUL(t113 - t114, costab16));
+
+ t115 = t73 + t74;
+ t116 = t75 + t76;
+
+ t32 = t115 + t116;
+
+ /* 1 */ hi[14][slot] = SHIFT(t32);
+
+ t118 = t78 + t79;
+ t119 = t80 + t81;
+
+ t58 = t118 + t119;
+
+ /* 2 */ hi[13][slot] = SHIFT(t58);
+
+ t121 = t83 + t84;
+ t122 = t85 + t86;
+
+ t67 = t121 + t122;
+
+ t49 = (t67 * 2) - t32;
+
+ /* 3 */ hi[12][slot] = SHIFT(t49);
+
+ t125 = t89 + t90;
+ t126 = t91 + t92;
+
+ t93 = t125 + t126;
+
+ /* 4 */ hi[11][slot] = SHIFT(t93);
+
+ t128 = t94 + t95;
+ t129 = t96 + t97;
+
+ t98 = t128 + t129;
+
+ t68 = (t98 * 2) - t49;
+
+ /* 5 */ hi[10][slot] = SHIFT(t68);
+
+ t132 = t100 + t101;
+ t133 = t102 + t103;
+
+ t104 = t132 + t133;
+
+ t82 = (t104 * 2) - t58;
+
+ /* 6 */ hi[ 9][slot] = SHIFT(t82);
+
+ t136 = t106 + t107;
+ t137 = t108 + t109;
+
+ t110 = t136 + t137;
+
+ t87 = (t110 * 2) - t67;
+
+ t77 = (t87 * 2) - t68;
+
+ /* 7 */ hi[ 8][slot] = SHIFT(t77);
+
+ t141 = MUL(t69 - t70, costab8);
+ t142 = MUL(t71 - t72, costab24);
+ t143 = t141 + t142;
+
+ /* 8 */ hi[ 7][slot] = SHIFT(t143);
+ /* 24 */ lo[ 8][slot] =
+ SHIFT((MUL(t141 - t142, costab16) * 2) - t143);
+
+ t144 = MUL(t73 - t74, costab8);
+ t145 = MUL(t75 - t76, costab24);
+ t146 = t144 + t145;
+
+ t88 = (t146 * 2) - t77;
+
+ /* 9 */ hi[ 6][slot] = SHIFT(t88);
+
+ t148 = MUL(t78 - t79, costab8);
+ t149 = MUL(t80 - t81, costab24);
+ t150 = t148 + t149;
+
+ t105 = (t150 * 2) - t82;
+
+ /* 10 */ hi[ 5][slot] = SHIFT(t105);
+
+ t152 = MUL(t83 - t84, costab8);
+ t153 = MUL(t85 - t86, costab24);
+ t154 = t152 + t153;
+
+ t111 = (t154 * 2) - t87;
+
+ t99 = (t111 * 2) - t88;
+
+ /* 11 */ hi[ 4][slot] = SHIFT(t99);
+
+ t157 = MUL(t89 - t90, costab8);
+ t158 = MUL(t91 - t92, costab24);
+ t159 = t157 + t158;
+
+ t127 = (t159 * 2) - t93;
+
+ /* 12 */ hi[ 3][slot] = SHIFT(t127);
+
+ t160 = (MUL(t125 - t126, costab16) * 2) - t127;
+
+ /* 20 */ lo[ 4][slot] = SHIFT(t160);
+ /* 28 */ lo[12][slot] =
+ SHIFT((((MUL(t157 - t158, costab16) * 2) - t159) * 2) - t160);
+
+ t161 = MUL(t94 - t95, costab8);
+ t162 = MUL(t96 - t97, costab24);
+ t163 = t161 + t162;
+
+ t130 = (t163 * 2) - t98;
+
+ t112 = (t130 * 2) - t99;
+
+ /* 13 */ hi[ 2][slot] = SHIFT(t112);
+
+ t164 = (MUL(t128 - t129, costab16) * 2) - t130;
+
+ t166 = MUL(t100 - t101, costab8);
+ t167 = MUL(t102 - t103, costab24);
+ t168 = t166 + t167;
+
+ t134 = (t168 * 2) - t104;
+
+ t120 = (t134 * 2) - t105;
+
+ /* 14 */ hi[ 1][slot] = SHIFT(t120);
+
+ t135 = (MUL(t118 - t119, costab16) * 2) - t120;
+
+ /* 18 */ lo[ 2][slot] = SHIFT(t135);
+
+ t169 = (MUL(t132 - t133, costab16) * 2) - t134;
+
+ t151 = (t169 * 2) - t135;
+
+ /* 22 */ lo[ 6][slot] = SHIFT(t151);
+
+ t170 = (((MUL(t148 - t149, costab16) * 2) - t150) * 2) - t151;
+
+ /* 26 */ lo[10][slot] = SHIFT(t170);
+ /* 30 */ lo[14][slot] =
+ SHIFT((((((MUL(t166 - t167, costab16) * 2) -
+ t168) * 2) - t169) * 2) - t170);
+
+ t171 = MUL(t106 - t107, costab8);
+ t172 = MUL(t108 - t109, costab24);
+ t173 = t171 + t172;
+
+ t138 = (t173 * 2) - t110;
+
+ t123 = (t138 * 2) - t111;
+
+ t139 = (MUL(t121 - t122, costab16) * 2) - t123;
+
+ t117 = (t123 * 2) - t112;
+
+ /* 15 */ hi[ 0][slot] = SHIFT(t117);
+
+ t124 = (MUL(t115 - t116, costab16) * 2) - t117;
+
+ /* 17 */ lo[ 1][slot] = SHIFT(t124);
+
+ t131 = (t139 * 2) - t124;
+
+ /* 19 */ lo[ 3][slot] = SHIFT(t131);
+
+ t140 = (t164 * 2) - t131;
+
+ /* 21 */ lo[ 5][slot] = SHIFT(t140);
+
+ t174 = (MUL(t136 - t137, costab16) * 2) - t138;
+
+ t155 = (t174 * 2) - t139;
+
+ t147 = (t155 * 2) - t140;
+
+ /* 23 */ lo[ 7][slot] = SHIFT(t147);
+
+ t156 = (((MUL(t144 - t145, costab16) * 2) - t146) * 2) - t147;
+
+ /* 25 */ lo[ 9][slot] = SHIFT(t156);
+
+ t175 = (((MUL(t152 - t153, costab16) * 2) - t154) * 2) - t155;
+
+ t165 = (t175 * 2) - t156;
+
+ /* 27 */ lo[11][slot] = SHIFT(t165);
+
+ t176 = (((((MUL(t161 - t162, costab16) * 2) -
+ t163) * 2) - t164) * 2) - t165;
+
+ /* 29 */ lo[13][slot] = SHIFT(t176);
+ /* 31 */ lo[15][slot] =
+ SHIFT((((((((MUL(t171 - t172, costab16) * 2) -
+ t173) * 2) - t174) * 2) - t175) * 2) - t176);
+
+ /*
+ * Totals:
+ * 80 multiplies
+ * 80 additions
+ * 119 subtractions
+ * 49 shifts (not counting SSO)
+ */
+}
+
+# undef MUL
+# undef SHIFT
+
+/* third SSO shift and/or D[] optimization preshift */
+
+# if defined(OPT_SSO)
+# if MAD_F_FRACBITS != 28
+# error "MAD_F_FRACBITS must be 28 to use OPT_SSO"
+# endif
+# define ML0(hi, lo, x, y) ((lo) = (x) * (y))
+# define MLA(hi, lo, x, y) ((lo) += (x) * (y))
+# define MLN(hi, lo) ((lo) = -(lo))
+# define MLZ(hi, lo) ((void) (hi), (mad_fixed_t) (lo))
+# define SHIFT(x) ((x) >> 2)
+# define PRESHIFT(x) ((MAD_F(x) + (1L << 13)) >> 14)
+# else
+# define ML0(hi, lo, x, y) MAD_F_ML0((hi), (lo), (x), (y))
+# define MLA(hi, lo, x, y) MAD_F_MLA((hi), (lo), (x), (y))
+# define MLN(hi, lo) MAD_F_MLN((hi), (lo))
+# define MLZ(hi, lo) MAD_F_MLZ((hi), (lo))
+# define SHIFT(x) (x)
+# if defined(MAD_F_SCALEBITS)
+# undef MAD_F_SCALEBITS
+# define MAD_F_SCALEBITS (MAD_F_FRACBITS - 12)
+# define PRESHIFT(x) (MAD_F(x) >> 12)
+# else
+# define PRESHIFT(x) MAD_F(x)
+# endif
+# endif
+
+static
+mad_fixed_t const D[17][32] = {
+# include "D.dat"
+};
+
+# if defined(ASO_SYNTH)
+void synth_full(struct mad_synth *, struct mad_frame const *,
+ unsigned int, unsigned int);
+# else
+/*
+ * NAME: synth->full()
+ * DESCRIPTION: perform full frequency PCM synthesis
+ */
+static
+void synth_full(struct mad_synth *synth, struct mad_frame const *frame,
+ unsigned int nch, unsigned int ns)
+{
+ unsigned int phase, ch, s, sb, pe, po;
+ mad_fixed_t *pcm1, *pcm2, (*filter)[2][2][16][8];
+ mad_fixed_t const (*sbsample)[36][32];
+ register mad_fixed_t (*fe)[8], (*fx)[8], (*fo)[8];
+ register mad_fixed_t const (*Dptr)[32], *ptr;
+ register mad_fixed64hi_t hi;
+ register mad_fixed64lo_t lo;
+
+ for (ch = 0; ch < nch; ++ch) {
+ sbsample = &frame->sbsample[ch];
+ filter = &synth->filter[ch];
+ phase = synth->phase;
+ pcm1 = synth->pcm.samples[ch];
+
+ for (s = 0; s < ns; ++s) {
+ dct32((*sbsample)[s], phase >> 1,
+ (*filter)[0][phase & 1], (*filter)[1][phase & 1]);
+
+ pe = phase & ~1;
+ po = ((phase - 1) & 0xf) | 1;
+
+ /* calculate 32 samples */
+
+ fe = &(*filter)[0][ phase & 1][0];
+ fx = &(*filter)[0][~phase & 1][0];
+ fo = &(*filter)[1][~phase & 1][0];
+
+ Dptr = &D[0];
+
+ ptr = *Dptr + po;
+ ML0(hi, lo, (*fx)[0], ptr[ 0]);
+ MLA(hi, lo, (*fx)[1], ptr[14]);
+ MLA(hi, lo, (*fx)[2], ptr[12]);
+ MLA(hi, lo, (*fx)[3], ptr[10]);
+ MLA(hi, lo, (*fx)[4], ptr[ 8]);
+ MLA(hi, lo, (*fx)[5], ptr[ 6]);
+ MLA(hi, lo, (*fx)[6], ptr[ 4]);
+ MLA(hi, lo, (*fx)[7], ptr[ 2]);
+ MLN(hi, lo);
+
+ ptr = *Dptr + pe;
+ MLA(hi, lo, (*fe)[0], ptr[ 0]);
+ MLA(hi, lo, (*fe)[1], ptr[14]);
+ MLA(hi, lo, (*fe)[2], ptr[12]);
+ MLA(hi, lo, (*fe)[3], ptr[10]);
+ MLA(hi, lo, (*fe)[4], ptr[ 8]);
+ MLA(hi, lo, (*fe)[5], ptr[ 6]);
+ MLA(hi, lo, (*fe)[6], ptr[ 4]);
+ MLA(hi, lo, (*fe)[7], ptr[ 2]);
+
+ *pcm1++ = SHIFT(MLZ(hi, lo));
+
+ pcm2 = pcm1 + 30;
+
+ for (sb = 1; sb < 16; ++sb) {
+ ++fe;
+ ++Dptr;
+
+ /* D[32 - sb][i] == -D[sb][31 - i] */
+
+ ptr = *Dptr + po;
+ ML0(hi, lo, (*fo)[0], ptr[ 0]);
+ MLA(hi, lo, (*fo)[1], ptr[14]);
+ MLA(hi, lo, (*fo)[2], ptr[12]);
+ MLA(hi, lo, (*fo)[3], ptr[10]);
+ MLA(hi, lo, (*fo)[4], ptr[ 8]);
+ MLA(hi, lo, (*fo)[5], ptr[ 6]);
+ MLA(hi, lo, (*fo)[6], ptr[ 4]);
+ MLA(hi, lo, (*fo)[7], ptr[ 2]);
+ MLN(hi, lo);
+
+ ptr = *Dptr + pe;
+ MLA(hi, lo, (*fe)[7], ptr[ 2]);
+ MLA(hi, lo, (*fe)[6], ptr[ 4]);
+ MLA(hi, lo, (*fe)[5], ptr[ 6]);
+ MLA(hi, lo, (*fe)[4], ptr[ 8]);
+ MLA(hi, lo, (*fe)[3], ptr[10]);
+ MLA(hi, lo, (*fe)[2], ptr[12]);
+ MLA(hi, lo, (*fe)[1], ptr[14]);
+ MLA(hi, lo, (*fe)[0], ptr[ 0]);
+
+ *pcm1++ = SHIFT(MLZ(hi, lo));
+
+ ptr = *Dptr - pe;
+ ML0(hi, lo, (*fe)[0], ptr[31 - 16]);
+ MLA(hi, lo, (*fe)[1], ptr[31 - 14]);
+ MLA(hi, lo, (*fe)[2], ptr[31 - 12]);
+ MLA(hi, lo, (*fe)[3], ptr[31 - 10]);
+ MLA(hi, lo, (*fe)[4], ptr[31 - 8]);
+ MLA(hi, lo, (*fe)[5], ptr[31 - 6]);
+ MLA(hi, lo, (*fe)[6], ptr[31 - 4]);
+ MLA(hi, lo, (*fe)[7], ptr[31 - 2]);
+
+ ptr = *Dptr - po;
+ MLA(hi, lo, (*fo)[7], ptr[31 - 2]);
+ MLA(hi, lo, (*fo)[6], ptr[31 - 4]);
+ MLA(hi, lo, (*fo)[5], ptr[31 - 6]);
+ MLA(hi, lo, (*fo)[4], ptr[31 - 8]);
+ MLA(hi, lo, (*fo)[3], ptr[31 - 10]);
+ MLA(hi, lo, (*fo)[2], ptr[31 - 12]);
+ MLA(hi, lo, (*fo)[1], ptr[31 - 14]);
+ MLA(hi, lo, (*fo)[0], ptr[31 - 16]);
+
+ *pcm2-- = SHIFT(MLZ(hi, lo));
+
+ ++fo;
+ }
+
+ ++Dptr;
+
+ ptr = *Dptr + po;
+ ML0(hi, lo, (*fo)[0], ptr[ 0]);
+ MLA(hi, lo, (*fo)[1], ptr[14]);
+ MLA(hi, lo, (*fo)[2], ptr[12]);
+ MLA(hi, lo, (*fo)[3], ptr[10]);
+ MLA(hi, lo, (*fo)[4], ptr[ 8]);
+ MLA(hi, lo, (*fo)[5], ptr[ 6]);
+ MLA(hi, lo, (*fo)[6], ptr[ 4]);
+ MLA(hi, lo, (*fo)[7], ptr[ 2]);
+
+ *pcm1 = SHIFT(-MLZ(hi, lo));
+ pcm1 += 16;
+
+ phase = (phase + 1) % 16;
+ }
+ }
+}
+# endif
+
+/*
+ * NAME: synth->half()
+ * DESCRIPTION: perform half frequency PCM synthesis
+ */
+static
+void synth_half(struct mad_synth *synth, struct mad_frame const *frame,
+ unsigned int nch, unsigned int ns)
+{
+ unsigned int phase, ch, s, sb, pe, po;
+ mad_fixed_t *pcm1, *pcm2, (*filter)[2][2][16][8];
+ mad_fixed_t const (*sbsample)[36][32];
+ register mad_fixed_t (*fe)[8], (*fx)[8], (*fo)[8];
+ register mad_fixed_t const (*Dptr)[32], *ptr;
+ register mad_fixed64hi_t hi;
+ register mad_fixed64lo_t lo;
+
+ for (ch = 0; ch < nch; ++ch) {
+ sbsample = &frame->sbsample[ch];
+ filter = &synth->filter[ch];
+ phase = synth->phase;
+ pcm1 = synth->pcm.samples[ch];
+
+ for (s = 0; s < ns; ++s) {
+ dct32((*sbsample)[s], phase >> 1,
+ (*filter)[0][phase & 1], (*filter)[1][phase & 1]);
+
+ pe = phase & ~1;
+ po = ((phase - 1) & 0xf) | 1;
+
+ /* calculate 16 samples */
+
+ fe = &(*filter)[0][ phase & 1][0];
+ fx = &(*filter)[0][~phase & 1][0];
+ fo = &(*filter)[1][~phase & 1][0];
+
+ Dptr = &D[0];
+
+ ptr = *Dptr + po;
+ ML0(hi, lo, (*fx)[0], ptr[ 0]);
+ MLA(hi, lo, (*fx)[1], ptr[14]);
+ MLA(hi, lo, (*fx)[2], ptr[12]);
+ MLA(hi, lo, (*fx)[3], ptr[10]);
+ MLA(hi, lo, (*fx)[4], ptr[ 8]);
+ MLA(hi, lo, (*fx)[5], ptr[ 6]);
+ MLA(hi, lo, (*fx)[6], ptr[ 4]);
+ MLA(hi, lo, (*fx)[7], ptr[ 2]);
+ MLN(hi, lo);
+
+ ptr = *Dptr + pe;
+ MLA(hi, lo, (*fe)[0], ptr[ 0]);
+ MLA(hi, lo, (*fe)[1], ptr[14]);
+ MLA(hi, lo, (*fe)[2], ptr[12]);
+ MLA(hi, lo, (*fe)[3], ptr[10]);
+ MLA(hi, lo, (*fe)[4], ptr[ 8]);
+ MLA(hi, lo, (*fe)[5], ptr[ 6]);
+ MLA(hi, lo, (*fe)[6], ptr[ 4]);
+ MLA(hi, lo, (*fe)[7], ptr[ 2]);
+
+ *pcm1++ = SHIFT(MLZ(hi, lo));
+
+ pcm2 = pcm1 + 14;
+
+ for (sb = 1; sb < 16; ++sb) {
+ ++fe;
+ ++Dptr;
+
+ /* D[32 - sb][i] == -D[sb][31 - i] */
+
+ if (!(sb & 1)) {
+ ptr = *Dptr + po;
+ ML0(hi, lo, (*fo)[0], ptr[ 0]);
+ MLA(hi, lo, (*fo)[1], ptr[14]);
+ MLA(hi, lo, (*fo)[2], ptr[12]);
+ MLA(hi, lo, (*fo)[3], ptr[10]);
+ MLA(hi, lo, (*fo)[4], ptr[ 8]);
+ MLA(hi, lo, (*fo)[5], ptr[ 6]);
+ MLA(hi, lo, (*fo)[6], ptr[ 4]);
+ MLA(hi, lo, (*fo)[7], ptr[ 2]);
+ MLN(hi, lo);
+
+ ptr = *Dptr + pe;
+ MLA(hi, lo, (*fe)[7], ptr[ 2]);
+ MLA(hi, lo, (*fe)[6], ptr[ 4]);
+ MLA(hi, lo, (*fe)[5], ptr[ 6]);
+ MLA(hi, lo, (*fe)[4], ptr[ 8]);
+ MLA(hi, lo, (*fe)[3], ptr[10]);
+ MLA(hi, lo, (*fe)[2], ptr[12]);
+ MLA(hi, lo, (*fe)[1], ptr[14]);
+ MLA(hi, lo, (*fe)[0], ptr[ 0]);
+
+ *pcm1++ = SHIFT(MLZ(hi, lo));
+
+ ptr = *Dptr - po;
+ ML0(hi, lo, (*fo)[7], ptr[31 - 2]);
+ MLA(hi, lo, (*fo)[6], ptr[31 - 4]);
+ MLA(hi, lo, (*fo)[5], ptr[31 - 6]);
+ MLA(hi, lo, (*fo)[4], ptr[31 - 8]);
+ MLA(hi, lo, (*fo)[3], ptr[31 - 10]);
+ MLA(hi, lo, (*fo)[2], ptr[31 - 12]);
+ MLA(hi, lo, (*fo)[1], ptr[31 - 14]);
+ MLA(hi, lo, (*fo)[0], ptr[31 - 16]);
+
+ ptr = *Dptr - pe;
+ MLA(hi, lo, (*fe)[0], ptr[31 - 16]);
+ MLA(hi, lo, (*fe)[1], ptr[31 - 14]);
+ MLA(hi, lo, (*fe)[2], ptr[31 - 12]);
+ MLA(hi, lo, (*fe)[3], ptr[31 - 10]);
+ MLA(hi, lo, (*fe)[4], ptr[31 - 8]);
+ MLA(hi, lo, (*fe)[5], ptr[31 - 6]);
+ MLA(hi, lo, (*fe)[6], ptr[31 - 4]);
+ MLA(hi, lo, (*fe)[7], ptr[31 - 2]);
+
+ *pcm2-- = SHIFT(MLZ(hi, lo));
+ }
+
+ ++fo;
+ }
+
+ ++Dptr;
+
+ ptr = *Dptr + po;
+ ML0(hi, lo, (*fo)[0], ptr[ 0]);
+ MLA(hi, lo, (*fo)[1], ptr[14]);
+ MLA(hi, lo, (*fo)[2], ptr[12]);
+ MLA(hi, lo, (*fo)[3], ptr[10]);
+ MLA(hi, lo, (*fo)[4], ptr[ 8]);
+ MLA(hi, lo, (*fo)[5], ptr[ 6]);
+ MLA(hi, lo, (*fo)[6], ptr[ 4]);
+ MLA(hi, lo, (*fo)[7], ptr[ 2]);
+
+ *pcm1 = SHIFT(-MLZ(hi, lo));
+ pcm1 += 8;
+
+ phase = (phase + 1) % 16;
+ }
+ }
+}
+
+/*
+ * NAME: synth->frame()
+ * DESCRIPTION: perform PCM synthesis of frame subband samples
+ */
+void mad_synth_frame(struct mad_synth *synth, struct mad_frame const *frame)
+{
+ unsigned int nch, ns;
+ void (*synth_frame)(struct mad_synth *, struct mad_frame const *,
+ unsigned int, unsigned int);
+
+ nch = MAD_NCHANNELS(&frame->header);
+ ns = MAD_NSBSAMPLES(&frame->header);
+
+ synth->pcm.samplerate = frame->header.samplerate;
+ synth->pcm.channels = nch;
+ synth->pcm.length = 32 * ns;
+
+ synth_frame = synth_full;
+
+ if (frame->options & MAD_OPTION_HALFSAMPLERATE) {
+ synth->pcm.samplerate /= 2;
+ synth->pcm.length /= 2;
+
+ synth_frame = synth_half;
+ }
+
+ synth_frame(synth, frame, nch, ns);
+
+ synth->phase = (synth->phase + ns) % 16;
+}
diff --git a/contrib/libmad/synth.h b/contrib/libmad/synth.h
new file mode 100644
index 000000000..8ae4bc95e
--- /dev/null
+++ b/contrib/libmad/synth.h
@@ -0,0 +1,69 @@
+/*
+ * libmad - MPEG audio decoder library
+ * Copyright (C) 2000-2004 Underbit Technologies, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: synth.h,v 1.15 2004/01/23 09:41:33 rob Exp $
+ */
+
+# ifndef LIBMAD_SYNTH_H
+# define LIBMAD_SYNTH_H
+
+# include "fixed.h"
+# include "frame.h"
+
+struct mad_pcm {
+ unsigned int samplerate; /* sampling frequency (Hz) */
+ unsigned short channels; /* number of channels */
+ unsigned short length; /* number of samples per channel */
+ mad_fixed_t samples[2][1152]; /* PCM output samples [ch][sample] */
+};
+
+struct mad_synth {
+ mad_fixed_t filter[2][2][2][16][8]; /* polyphase filterbank outputs */
+ /* [ch][eo][peo][s][v] */
+
+ unsigned int phase; /* current processing phase */
+
+ struct mad_pcm pcm; /* PCM output */
+};
+
+/* single channel PCM selector */
+enum {
+ MAD_PCM_CHANNEL_SINGLE = 0
+};
+
+/* dual channel PCM selector */
+enum {
+ MAD_PCM_CHANNEL_DUAL_1 = 0,
+ MAD_PCM_CHANNEL_DUAL_2 = 1
+};
+
+/* stereo PCM selector */
+enum {
+ MAD_PCM_CHANNEL_STEREO_LEFT = 0,
+ MAD_PCM_CHANNEL_STEREO_RIGHT = 1
+};
+
+void mad_synth_init(struct mad_synth *);
+
+# define mad_synth_finish(synth) /* nothing */
+
+void mad_synth_mute(struct mad_synth *);
+
+void mad_synth_frame(struct mad_synth *, struct mad_frame const *);
+
+# endif
diff --git a/contrib/libmad/timer.c b/contrib/libmad/timer.c
new file mode 100644
index 000000000..4b909aba9
--- /dev/null
+++ b/contrib/libmad/timer.c
@@ -0,0 +1,485 @@
+/*
+ * libmad - MPEG audio decoder library
+ * Copyright (C) 2000-2004 Underbit Technologies, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: timer.c,v 1.18 2004/01/23 09:41:33 rob Exp $
+ */
+
+# ifdef HAVE_CONFIG_H
+# include "config.h"
+# endif
+
+# include "global.h"
+
+# include <stdio.h>
+
+# ifdef HAVE_ASSERT_H
+# include <assert.h>
+# endif
+
+# include "timer.h"
+
+mad_timer_t const mad_timer_zero = { 0, 0 };
+
+/*
+ * NAME: timer->compare()
+ * DESCRIPTION: indicate relative order of two timers
+ */
+int mad_timer_compare(mad_timer_t timer1, mad_timer_t timer2)
+{
+ signed long diff;
+
+ diff = timer1.seconds - timer2.seconds;
+ if (diff < 0)
+ return -1;
+ else if (diff > 0)
+ return +1;
+
+ diff = timer1.fraction - timer2.fraction;
+ if (diff < 0)
+ return -1;
+ else if (diff > 0)
+ return +1;
+
+ return 0;
+}
+
+/*
+ * NAME: timer->negate()
+ * DESCRIPTION: invert the sign of a timer
+ */
+void mad_timer_negate(mad_timer_t *timer)
+{
+ timer->seconds = -timer->seconds;
+
+ if (timer->fraction) {
+ timer->seconds -= 1;
+ timer->fraction = MAD_TIMER_RESOLUTION - timer->fraction;
+ }
+}
+
+/*
+ * NAME: timer->abs()
+ * DESCRIPTION: return the absolute value of a timer
+ */
+mad_timer_t mad_timer_abs(mad_timer_t timer)
+{
+ if (timer.seconds < 0)
+ mad_timer_negate(&timer);
+
+ return timer;
+}
+
+/*
+ * NAME: reduce_timer()
+ * DESCRIPTION: carry timer fraction into seconds
+ */
+static
+void reduce_timer(mad_timer_t *timer)
+{
+ timer->seconds += timer->fraction / MAD_TIMER_RESOLUTION;
+ timer->fraction %= MAD_TIMER_RESOLUTION;
+}
+
+/*
+ * NAME: gcd()
+ * DESCRIPTION: compute greatest common denominator
+ */
+static
+unsigned long gcd(unsigned long num1, unsigned long num2)
+{
+ unsigned long tmp;
+
+ while (num2) {
+ tmp = num2;
+ num2 = num1 % num2;
+ num1 = tmp;
+ }
+
+ return num1;
+}
+
+/*
+ * NAME: reduce_rational()
+ * DESCRIPTION: convert rational expression to lowest terms
+ */
+static
+void reduce_rational(unsigned long *numer, unsigned long *denom)
+{
+ unsigned long factor;
+
+ factor = gcd(*numer, *denom);
+
+ assert(factor != 0);
+
+ *numer /= factor;
+ *denom /= factor;
+}
+
+/*
+ * NAME: scale_rational()
+ * DESCRIPTION: solve numer/denom == ?/scale avoiding overflowing
+ */
+static
+unsigned long scale_rational(unsigned long numer, unsigned long denom,
+ unsigned long scale)
+{
+ reduce_rational(&numer, &denom);
+ reduce_rational(&scale, &denom);
+
+ assert(denom != 0);
+
+ if (denom < scale)
+ return numer * (scale / denom) + numer * (scale % denom) / denom;
+ if (denom < numer)
+ return scale * (numer / denom) + scale * (numer % denom) / denom;
+
+ return numer * scale / denom;
+}
+
+/*
+ * NAME: timer->set()
+ * DESCRIPTION: set timer to specific (positive) value
+ */
+void mad_timer_set(mad_timer_t *timer, unsigned long seconds,
+ unsigned long numer, unsigned long denom)
+{
+ timer->seconds = seconds;
+ if (numer >= denom && denom > 0) {
+ timer->seconds += numer / denom;
+ numer %= denom;
+ }
+
+ switch (denom) {
+ case 0:
+ case 1:
+ timer->fraction = 0;
+ break;
+
+ case MAD_TIMER_RESOLUTION:
+ timer->fraction = numer;
+ break;
+
+ case 1000:
+ timer->fraction = numer * (MAD_TIMER_RESOLUTION / 1000);
+ break;
+
+ case 8000:
+ timer->fraction = numer * (MAD_TIMER_RESOLUTION / 8000);
+ break;
+
+ case 11025:
+ timer->fraction = numer * (MAD_TIMER_RESOLUTION / 11025);
+ break;
+
+ case 12000:
+ timer->fraction = numer * (MAD_TIMER_RESOLUTION / 12000);
+ break;
+
+ case 16000:
+ timer->fraction = numer * (MAD_TIMER_RESOLUTION / 16000);
+ break;
+
+ case 22050:
+ timer->fraction = numer * (MAD_TIMER_RESOLUTION / 22050);
+ break;
+
+ case 24000:
+ timer->fraction = numer * (MAD_TIMER_RESOLUTION / 24000);
+ break;
+
+ case 32000:
+ timer->fraction = numer * (MAD_TIMER_RESOLUTION / 32000);
+ break;
+
+ case 44100:
+ timer->fraction = numer * (MAD_TIMER_RESOLUTION / 44100);
+ break;
+
+ case 48000:
+ timer->fraction = numer * (MAD_TIMER_RESOLUTION / 48000);
+ break;
+
+ default:
+ timer->fraction = scale_rational(numer, denom, MAD_TIMER_RESOLUTION);
+ break;
+ }
+
+ if (timer->fraction >= MAD_TIMER_RESOLUTION)
+ reduce_timer(timer);
+}
+
+/*
+ * NAME: timer->add()
+ * DESCRIPTION: add one timer to another
+ */
+void mad_timer_add(mad_timer_t *timer, mad_timer_t incr)
+{
+ timer->seconds += incr.seconds;
+ timer->fraction += incr.fraction;
+
+ if (timer->fraction >= MAD_TIMER_RESOLUTION)
+ reduce_timer(timer);
+}
+
+/*
+ * NAME: timer->multiply()
+ * DESCRIPTION: multiply a timer by a scalar value
+ */
+void mad_timer_multiply(mad_timer_t *timer, signed long scalar)
+{
+ mad_timer_t addend;
+ unsigned long factor;
+
+ factor = scalar;
+ if (scalar < 0) {
+ factor = -scalar;
+ mad_timer_negate(timer);
+ }
+
+ addend = *timer;
+ *timer = mad_timer_zero;
+
+ while (factor) {
+ if (factor & 1)
+ mad_timer_add(timer, addend);
+
+ mad_timer_add(&addend, addend);
+ factor >>= 1;
+ }
+}
+
+/*
+ * NAME: timer->count()
+ * DESCRIPTION: return timer value in selected units
+ */
+signed long mad_timer_count(mad_timer_t timer, enum mad_units units)
+{
+ switch (units) {
+ case MAD_UNITS_HOURS:
+ return timer.seconds / 60 / 60;
+
+ case MAD_UNITS_MINUTES:
+ return timer.seconds / 60;
+
+ case MAD_UNITS_SECONDS:
+ return timer.seconds;
+
+ case MAD_UNITS_DECISECONDS:
+ case MAD_UNITS_CENTISECONDS:
+ case MAD_UNITS_MILLISECONDS:
+
+ case MAD_UNITS_8000_HZ:
+ case MAD_UNITS_11025_HZ:
+ case MAD_UNITS_12000_HZ:
+ case MAD_UNITS_16000_HZ:
+ case MAD_UNITS_22050_HZ:
+ case MAD_UNITS_24000_HZ:
+ case MAD_UNITS_32000_HZ:
+ case MAD_UNITS_44100_HZ:
+ case MAD_UNITS_48000_HZ:
+
+ case MAD_UNITS_24_FPS:
+ case MAD_UNITS_25_FPS:
+ case MAD_UNITS_30_FPS:
+ case MAD_UNITS_48_FPS:
+ case MAD_UNITS_50_FPS:
+ case MAD_UNITS_60_FPS:
+ case MAD_UNITS_75_FPS:
+ return timer.seconds * (signed long) units +
+ (signed long) scale_rational(timer.fraction, MAD_TIMER_RESOLUTION,
+ units);
+
+ case MAD_UNITS_23_976_FPS:
+ case MAD_UNITS_24_975_FPS:
+ case MAD_UNITS_29_97_FPS:
+ case MAD_UNITS_47_952_FPS:
+ case MAD_UNITS_49_95_FPS:
+ case MAD_UNITS_59_94_FPS:
+ return (mad_timer_count(timer, -units) + 1) * 1000 / 1001;
+ }
+
+ /* unsupported units */
+ return 0;
+}
+
+/*
+ * NAME: timer->fraction()
+ * DESCRIPTION: return fractional part of timer in arbitrary terms
+ */
+unsigned long mad_timer_fraction(mad_timer_t timer, unsigned long denom)
+{
+ timer = mad_timer_abs(timer);
+
+ switch (denom) {
+ case 0:
+ return timer.fraction ?
+ MAD_TIMER_RESOLUTION / timer.fraction : MAD_TIMER_RESOLUTION + 1;
+
+ case MAD_TIMER_RESOLUTION:
+ return timer.fraction;
+
+ default:
+ return scale_rational(timer.fraction, MAD_TIMER_RESOLUTION, denom);
+ }
+}
+
+/*
+ * NAME: timer->string()
+ * DESCRIPTION: write a string representation of a timer using a template
+ */
+void mad_timer_string(mad_timer_t timer,
+ char *dest, char const *format, enum mad_units units,
+ enum mad_units fracunits, unsigned long subparts)
+{
+ unsigned long hours, minutes, seconds, sub;
+ unsigned int frac;
+
+ timer = mad_timer_abs(timer);
+
+ seconds = timer.seconds;
+ frac = sub = 0;
+
+ switch (fracunits) {
+ case MAD_UNITS_HOURS:
+ case MAD_UNITS_MINUTES:
+ case MAD_UNITS_SECONDS:
+ break;
+
+ case MAD_UNITS_DECISECONDS:
+ case MAD_UNITS_CENTISECONDS:
+ case MAD_UNITS_MILLISECONDS:
+
+ case MAD_UNITS_8000_HZ:
+ case MAD_UNITS_11025_HZ:
+ case MAD_UNITS_12000_HZ:
+ case MAD_UNITS_16000_HZ:
+ case MAD_UNITS_22050_HZ:
+ case MAD_UNITS_24000_HZ:
+ case MAD_UNITS_32000_HZ:
+ case MAD_UNITS_44100_HZ:
+ case MAD_UNITS_48000_HZ:
+
+ case MAD_UNITS_24_FPS:
+ case MAD_UNITS_25_FPS:
+ case MAD_UNITS_30_FPS:
+ case MAD_UNITS_48_FPS:
+ case MAD_UNITS_50_FPS:
+ case MAD_UNITS_60_FPS:
+ case MAD_UNITS_75_FPS:
+ {
+ unsigned long denom;
+
+ denom = MAD_TIMER_RESOLUTION / fracunits;
+
+ frac = timer.fraction / denom;
+ sub = scale_rational(timer.fraction % denom, denom, subparts);
+ }
+ break;
+
+ case MAD_UNITS_23_976_FPS:
+ case MAD_UNITS_24_975_FPS:
+ case MAD_UNITS_29_97_FPS:
+ case MAD_UNITS_47_952_FPS:
+ case MAD_UNITS_49_95_FPS:
+ case MAD_UNITS_59_94_FPS:
+ /* drop-frame encoding */
+ /* N.B. this is only well-defined for MAD_UNITS_29_97_FPS */
+ {
+ unsigned long frame, cycle, d, m;
+
+ frame = mad_timer_count(timer, fracunits);
+
+ cycle = -fracunits * 60 * 10 - (10 - 1) * 2;
+
+ d = frame / cycle;
+ m = frame % cycle;
+ frame += (10 - 1) * 2 * d;
+ if (m > 2)
+ frame += 2 * ((m - 2) / (cycle / 10));
+
+ frac = frame % -fracunits;
+ seconds = frame / -fracunits;
+ }
+ break;
+ }
+
+ switch (units) {
+ case MAD_UNITS_HOURS:
+ minutes = seconds / 60;
+ hours = minutes / 60;
+
+ sprintf(dest, format,
+ hours,
+ (unsigned int) (minutes % 60),
+ (unsigned int) (seconds % 60),
+ frac, sub);
+ break;
+
+ case MAD_UNITS_MINUTES:
+ minutes = seconds / 60;
+
+ sprintf(dest, format,
+ minutes,
+ (unsigned int) (seconds % 60),
+ frac, sub);
+ break;
+
+ case MAD_UNITS_SECONDS:
+ sprintf(dest, format,
+ seconds,
+ frac, sub);
+ break;
+
+ case MAD_UNITS_23_976_FPS:
+ case MAD_UNITS_24_975_FPS:
+ case MAD_UNITS_29_97_FPS:
+ case MAD_UNITS_47_952_FPS:
+ case MAD_UNITS_49_95_FPS:
+ case MAD_UNITS_59_94_FPS:
+ if (fracunits < 0) {
+ /* not yet implemented */
+ sub = 0;
+ }
+
+ /* fall through */
+
+ case MAD_UNITS_DECISECONDS:
+ case MAD_UNITS_CENTISECONDS:
+ case MAD_UNITS_MILLISECONDS:
+
+ case MAD_UNITS_8000_HZ:
+ case MAD_UNITS_11025_HZ:
+ case MAD_UNITS_12000_HZ:
+ case MAD_UNITS_16000_HZ:
+ case MAD_UNITS_22050_HZ:
+ case MAD_UNITS_24000_HZ:
+ case MAD_UNITS_32000_HZ:
+ case MAD_UNITS_44100_HZ:
+ case MAD_UNITS_48000_HZ:
+
+ case MAD_UNITS_24_FPS:
+ case MAD_UNITS_25_FPS:
+ case MAD_UNITS_30_FPS:
+ case MAD_UNITS_48_FPS:
+ case MAD_UNITS_50_FPS:
+ case MAD_UNITS_60_FPS:
+ case MAD_UNITS_75_FPS:
+ sprintf(dest, format, mad_timer_count(timer, units), sub);
+ break;
+ }
+}
diff --git a/contrib/libmad/timer.h b/contrib/libmad/timer.h
new file mode 100644
index 000000000..eb4542bb9
--- /dev/null
+++ b/contrib/libmad/timer.h
@@ -0,0 +1,100 @@
+/*
+ * libmad - MPEG audio decoder library
+ * Copyright (C) 2000-2004 Underbit Technologies, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: timer.h,v 1.16 2004/01/23 09:41:33 rob Exp $
+ */
+
+# ifndef LIBMAD_TIMER_H
+# define LIBMAD_TIMER_H
+
+typedef struct {
+ signed long seconds; /* whole seconds */
+ unsigned long fraction; /* 1/MAD_TIMER_RESOLUTION seconds */
+} mad_timer_t;
+
+extern mad_timer_t const mad_timer_zero;
+
+# define MAD_TIMER_RESOLUTION 352800000UL
+
+enum mad_units {
+ MAD_UNITS_HOURS = -2,
+ MAD_UNITS_MINUTES = -1,
+ MAD_UNITS_SECONDS = 0,
+
+ /* metric units */
+
+ MAD_UNITS_DECISECONDS = 10,
+ MAD_UNITS_CENTISECONDS = 100,
+ MAD_UNITS_MILLISECONDS = 1000,
+
+ /* audio sample units */
+
+ MAD_UNITS_8000_HZ = 8000,
+ MAD_UNITS_11025_HZ = 11025,
+ MAD_UNITS_12000_HZ = 12000,
+
+ MAD_UNITS_16000_HZ = 16000,
+ MAD_UNITS_22050_HZ = 22050,
+ MAD_UNITS_24000_HZ = 24000,
+
+ MAD_UNITS_32000_HZ = 32000,
+ MAD_UNITS_44100_HZ = 44100,
+ MAD_UNITS_48000_HZ = 48000,
+
+ /* video frame/field units */
+
+ MAD_UNITS_24_FPS = 24,
+ MAD_UNITS_25_FPS = 25,
+ MAD_UNITS_30_FPS = 30,
+ MAD_UNITS_48_FPS = 48,
+ MAD_UNITS_50_FPS = 50,
+ MAD_UNITS_60_FPS = 60,
+
+ /* CD audio frames */
+
+ MAD_UNITS_75_FPS = 75,
+
+ /* video drop-frame units */
+
+ MAD_UNITS_23_976_FPS = -24,
+ MAD_UNITS_24_975_FPS = -25,
+ MAD_UNITS_29_97_FPS = -30,
+ MAD_UNITS_47_952_FPS = -48,
+ MAD_UNITS_49_95_FPS = -50,
+ MAD_UNITS_59_94_FPS = -60
+};
+
+# define mad_timer_reset(timer) ((void) (*(timer) = mad_timer_zero))
+
+int mad_timer_compare(mad_timer_t, mad_timer_t);
+
+# define mad_timer_sign(timer) mad_timer_compare((timer), mad_timer_zero)
+
+void mad_timer_negate(mad_timer_t *);
+mad_timer_t mad_timer_abs(mad_timer_t);
+
+void mad_timer_set(mad_timer_t *, unsigned long, unsigned long, unsigned long);
+void mad_timer_add(mad_timer_t *, mad_timer_t);
+void mad_timer_multiply(mad_timer_t *, signed long);
+
+signed long mad_timer_count(mad_timer_t, enum mad_units);
+unsigned long mad_timer_fraction(mad_timer_t, unsigned long);
+void mad_timer_string(mad_timer_t, char *, char const *,
+ enum mad_units, enum mad_units, unsigned long);
+
+# endif
diff --git a/contrib/libmad/version.c b/contrib/libmad/version.c
new file mode 100644
index 000000000..e643fa71e
--- /dev/null
+++ b/contrib/libmad/version.c
@@ -0,0 +1,91 @@
+/*
+ * libmad - MPEG audio decoder library
+ * Copyright (C) 2000-2004 Underbit Technologies, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: version.c,v 1.15 2004/01/23 09:41:33 rob Exp $
+ */
+
+# ifdef HAVE_CONFIG_H
+# include "config.h"
+# endif
+
+# include "global.h"
+
+# include "version.h"
+
+char const mad_version[] = "MPEG Audio Decoder " MAD_VERSION;
+char const mad_copyright[] = "Copyright (C) " MAD_PUBLISHYEAR " " MAD_AUTHOR;
+char const mad_author[] = MAD_AUTHOR " <" MAD_EMAIL ">";
+
+char const mad_build[] = ""
+# if defined(DEBUG)
+ "DEBUG "
+# elif defined(NDEBUG)
+ "NDEBUG "
+# endif
+
+# if defined(EXPERIMENTAL)
+ "EXPERIMENTAL "
+# endif
+
+# if defined(FPM_64BIT)
+ "FPM_64BIT "
+# elif defined(FPM_INTEL)
+ "FPM_INTEL "
+# elif defined(FPM_ARM)
+ "FPM_ARM "
+# elif defined(FPM_MIPS)
+ "FPM_MIPS "
+# elif defined(FPM_SPARC)
+ "FPM_SPARC "
+# elif defined(FPM_PPC)
+ "FPM_PPC "
+# elif defined(FPM_DEFAULT)
+ "FPM_DEFAULT "
+# endif
+
+# if defined(ASO_IMDCT)
+ "ASO_IMDCT "
+# endif
+# if defined(ASO_INTERLEAVE1)
+ "ASO_INTERLEAVE1 "
+# endif
+# if defined(ASO_INTERLEAVE2)
+ "ASO_INTERLEAVE2 "
+# endif
+# if defined(ASO_ZEROCHECK)
+ "ASO_ZEROCHECK "
+# endif
+
+# if defined(OPT_SPEED)
+ "OPT_SPEED "
+# elif defined(OPT_ACCURACY)
+ "OPT_ACCURACY "
+# endif
+
+# if defined(OPT_SSO)
+ "OPT_SSO "
+# endif
+
+# if defined(OPT_DCTO) /* never defined here */
+ "OPT_DCTO "
+# endif
+
+# if defined(OPT_STRICT)
+ "OPT_STRICT "
+# endif
+;
diff --git a/contrib/libmad/version.h b/contrib/libmad/version.h
new file mode 100644
index 000000000..d215d4c10
--- /dev/null
+++ b/contrib/libmad/version.h
@@ -0,0 +1,47 @@
+/*
+ * libmad - MPEG audio decoder library
+ * Copyright (C) 2000-2004 Underbit Technologies, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: version.h,v 1.26 2004/01/23 09:41:33 rob Exp $
+ */
+
+# ifndef LIBMAD_VERSION_H
+# define LIBMAD_VERSION_H
+
+# define MAD_VERSION_MAJOR 0
+# define MAD_VERSION_MINOR 15
+# define MAD_VERSION_PATCH 1
+# define MAD_VERSION_EXTRA " (beta)"
+
+# define MAD_VERSION_STRINGIZE(str) #str
+# define MAD_VERSION_STRING(num) MAD_VERSION_STRINGIZE(num)
+
+# define MAD_VERSION MAD_VERSION_STRING(MAD_VERSION_MAJOR) "." \
+ MAD_VERSION_STRING(MAD_VERSION_MINOR) "." \
+ MAD_VERSION_STRING(MAD_VERSION_PATCH) \
+ MAD_VERSION_EXTRA
+
+# define MAD_PUBLISHYEAR "2000-2004"
+# define MAD_AUTHOR "Underbit Technologies, Inc."
+# define MAD_EMAIL "info@underbit.com"
+
+extern char const mad_version[];
+extern char const mad_copyright[];
+extern char const mad_author[];
+extern char const mad_build[];
+
+# endif
diff --git a/contrib/libmpcdec/COPYING b/contrib/libmpcdec/COPYING
new file mode 100644
index 000000000..10190c014
--- /dev/null
+++ b/contrib/libmpcdec/COPYING
@@ -0,0 +1,31 @@
+Copyright (c) 2005, The Musepack Development Team
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of the The Musepack Development Team nor the
+ names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/contrib/libmpcdec/Makefile.am b/contrib/libmpcdec/Makefile.am
new file mode 100644
index 000000000..24e2c0157
--- /dev/null
+++ b/contrib/libmpcdec/Makefile.am
@@ -0,0 +1,15 @@
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+
+EXTRA_DIST = diff_from_libmpcdec_1.2.5.patch COPYING
+
+if ENABLE_MUSEPACK
+if !WITH_EXTERNAL_LIBMPCDEC
+noinst_LTLIBRARIES = libmpcdec.la
+endif
+endif
+
+libmpcdec_la_SOURCES = huffsv46.c huffsv7.c idtag.c mpc_decoder.c mpc_reader.c \
+ requant.c streaminfo.c synth_filter.c \
+ mpcdec/internal.h mpcdec/mpcdec.h mpcdec/streaminfo.h mpcdec/math.h \
+ mpcdec/decoder.h mpcdec/config_types.h mpcdec/requant.h mpcdec/huffman.h \
+ mpcdec/reader.h
diff --git a/contrib/libmpcdec/diff_from_libmpcdec_1.2.5.patch b/contrib/libmpcdec/diff_from_libmpcdec_1.2.5.patch
new file mode 100644
index 000000000..f0e3b0cb6
--- /dev/null
+++ b/contrib/libmpcdec/diff_from_libmpcdec_1.2.5.patch
@@ -0,0 +1,20 @@
+Use xine's os_types.h file.
+Define MPC_LITTLE_ENDIAN when needed.
+
+Index: libmpcdec/mpcdec/config_types.h
+===================================================================
+--- libmpcdec.orig/mpcdec/config_types.h
++++ libmpcdec/mpcdec/config_types.h
+@@ -35,7 +35,11 @@
+ #ifndef __MUSEPACK_CONFIG_TYPES_H__
+ #define __MUSEPACK_CONFIG_TYPES_H__
+
+-#include <inttypes.h>
++#include "os_types.h"
++
++#ifndef WORDS_BIGENDIAN
++# define MPC_LITTLE_ENDIAN
++#endif
+
+ typedef unsigned char mpc_bool_t;
+ #define TRUE 1
diff --git a/contrib/libmpcdec/huffsv46.c b/contrib/libmpcdec/huffsv46.c
new file mode 100644
index 000000000..a6f031160
--- /dev/null
+++ b/contrib/libmpcdec/huffsv46.c
@@ -0,0 +1,75 @@
+/*
+ Copyright (c) 2005, The Musepack Development Team
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of the The Musepack Development Team nor the
+ names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/// \file huffsv46.c
+/// Implementations of huffman decoding for streamversions < 7.
+
+#include <mpcdec/mpcdec.h>
+#include <mpcdec/requant.h>
+#include <mpcdec/huffman.h>
+
+#ifdef MPC_SUPPORT_SV456
+
+
+const HuffmanTyp mpc_table_SCFI_Bundle [ 8] =
+{{2147483648u,1,7},{1073741824u,2,3},{939524096u,5,1},{805306368u,5,2},{738197504u,6,0},{671088640u,6,6},{536870912u,5,4},{0u,3,5},};
+const HuffmanTyp mpc_table_DSCF_Entropie [13] =
+{{3758096384u,3,1},{3489660928u,4,3},{3355443200u,5,5},{3221225472u,5,-3},{2952790016u,4,-2},{2684354560u,4,4},{2147483648u,3,-1},{1610612736u,3,2},{1476395008u,5,-5},{1409286144u,6,6},{1342177280u,6,-6},{1073741824u,4,-4},{0u,2,0},};
+const HuffmanTyp mpc_table_Region_A [16] =
+{{2147483648u,1,1},{2013265920u,5,3},{1946157056u,6,4},{1912602624u,7,7},{1895825408u,8,8},{1887436800u,9,9},{1883242496u,10,10},{1881145344u,11,11},{1880096768u,12,12},{1879572480u,13,13},{1879310336u,14,14},{1879048192u,14,15},{1744830464u,5,5},{1610612736u,5,6},{1073741824u,3,0},{0u,2,2},};
+const HuffmanTyp mpc_table_Region_B [ 8] =
+{{2147483648u,1,1},{1073741824u,2,0},{536870912u,3,2},{268435456u,4,3},{134217728u,5,4},{67108864u,6,5},{33554432u,7,6},{0u,7,7},};
+const HuffmanTyp mpc_table_Region_C [ 4] =
+{{2147483648u,1,0},{1073741824u,2,1},{536870912u,3,2},{0u,3,3},};
+
+static const HuffmanTyp mpc_table_Entropie_1 [ 3] =
+{{2147483648u,1,0},{1073741824u,2,-1},{0u,2,1},};
+static const HuffmanTyp mpc_table_Entropie_2 [ 5] =
+{{3221225472u,2,0},{2684354560u,3,2},{2147483648u,3,-2},{1073741824u,2,1},{0u,2,-1},};
+static const HuffmanTyp mpc_table_Entropie_3 [ 7] =
+{{3221225472u,2,0},{2684354560u,3,-2},{2415919104u,4,2},{2281701376u,5,-3},{2147483648u,5,3},{1073741824u,2,-1},{0u,2,1},};
+static const HuffmanTyp mpc_table_Entropie_4 [ 9] =
+{{4026531840u,4,3},{3758096384u,4,-3},{3221225472u,3,1},{2684354560u,3,-1},{2147483648u,3,2},{1610612736u,3,-2},{1342177280u,4,-4},{1073741824u,4,4},{0u,2,0},};
+static const HuffmanTyp mpc_table_Entropie_5 [15] =
+{{4026531840u,4,-2},{3892314112u,5,-5},{3825205248u,6,-7},{3758096384u,6,7},{3489660928u,4,-3},{3221225472u,4,3},{3087007744u,5,-6},{2952790016u,5,6},{2684354560u,4,4},{2147483648u,3,0},{1610612736u,3,1},{1073741824u,3,-1},{805306368u,4,-4},{536870912u,4,5},{0u,3,2},};
+static const HuffmanTyp mpc_table_Entropie_6 [31] =
+{{4160749568u,5,-4},{4026531840u,5,5},{3892314112u,5,-5},{3825205248u,6,10},{3758096384u,6,-10},{3623878656u,5,-6},{3489660928u,5,6},{3355443200u,5,7},{3221225472u,5,-7},{3087007744u,5,-8},{3019898880u,6,-11},{2986344448u,7,14},{2952790016u,7,-14},{2818572288u,5,8},{2751463424u,6,11},{2684354560u,6,-13},{2415919104u,4,0},{2147483648u,4,1},{1879048192u,4,-1},{1610612736u,4,3},{1342177280u,4,2},{1207959552u,5,-9},{1140850688u,6,12},{1073741824u,6,13},{805306368u,4,-3},{536870912u,4,-2},{402653184u,5,9},{335544320u,6,-12},{301989888u,7,15},{268435456u,7,-15},{0u,4,4},};
+static const HuffmanTyp mpc_table_Entropie_7 [63] =
+{{4278190080u,8,28},{4261412864u,8,26},{4227858432u,7,-20},{4160749568u,6,8},{4093640704u,6,-8},{4026531840u,6,-9},{3959422976u,6,9},{3925868544u,7,20},{3892314112u,7,21},{3825205248u,6,-10},{3758096384u,6,-11},{3690987520u,6,10},{3623878656u,6,11},{3590324224u,7,-21},{3573547008u,8,29},{3556769792u,8,-29},{3489660928u,6,13},{3422552064u,6,-13},{3355443200u,6,-12},{3288334336u,6,12},{3254779904u,7,-22},{3221225472u,7,22},{3154116608u,6,14},{3087007744u,6,15},{3019898880u,6,-14},{2986344448u,7,-23},{2952790016u,7,23},{2885681152u,6,-15},{2818572288u,6,-16},{2751463424u,6,16},{2717908992u,7,27},{2684354560u,7,-27},{2617245696u,6,17},{2550136832u,6,-17},{2533359616u,8,-30},{2516582400u,8,30},{2483027968u,7,24},{2415919104u,6,-18},{2281701376u,5,-1},{2147483648u,5,1},{2113929216u,7,-24},{2080374784u,7,25},{2013265920u,6,18},{1879048192u,5,-3},{1744830464u,5,3},{1610612736u,5,5},{1476395008u,5,0},{1342177280u,5,-2},{1275068416u,6,19},{1207959552u,6,-19},{1073741824u,5,-5},{939524096u,5,-4},{805306368u,5,-7},{671088640u,5,2},{536870912u,5,4},{402653184u,5,7},{369098752u,7,-25},{335544320u,7,-26},{301989888u,7,-28},{285212672u,8,-31},{268435456u,8,31},{134217728u,5,6},{0u,5,-6},};
+
+const HuffmanTyp* mpc_table_SampleHuff [18] = {
+ NULL,mpc_table_Entropie_1,mpc_table_Entropie_2,mpc_table_Entropie_3,mpc_table_Entropie_4,mpc_table_Entropie_5,mpc_table_Entropie_6,mpc_table_Entropie_7,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
+};
+
+#endif //#ifdef MPC_SUPPORT_SV456
diff --git a/contrib/libmpcdec/huffsv7.c b/contrib/libmpcdec/huffsv7.c
new file mode 100644
index 000000000..96f81ce24
--- /dev/null
+++ b/contrib/libmpcdec/huffsv7.c
@@ -0,0 +1,81 @@
+/*
+ Copyright (c) 2005, The Musepack Development Team
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of the The Musepack Development Team nor the
+ names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/// \file huffsv7.c
+/// Implementations of sv7 huffman decoding functions.
+
+#include <mpcdec/mpcdec.h>
+#include <mpcdec/huffman.h>
+#include <mpcdec/requant.h>
+
+const HuffmanTyp mpc_table_HuffHdr [10] =
+{{2147483648u,1,0},{1610612736u,3,1},{1577058304u,7,-4},{1568669696u,9,3},{1560281088u,9,4},{1543503872u,8,-5},{1476395008u,6,2},{1342177280u,5,-3},{1073741824u,4,-2},{0u,2,-1},};
+const HuffmanTyp mpc_table_HuffSCFI [ 4] =
+{{2147483648u,1,1},{1610612736u,3,2},{1073741824u,3,0},{0u,2,3},};
+const HuffmanTyp mpc_table_HuffDSCF [16] =
+{{4160749568u,5,5},{4026531840u,5,-4},{3758096384u,4,3},{3489660928u,4,-3},{3221225472u,4,8},{2684354560u,3,1},{2415919104u,4,0},{2281701376u,5,-5},{2214592512u,6,7},{2147483648u,6,-7},{1610612736u,3,-1},{1073741824u,3,2},{805306368u,4,4},{671088640u,5,6},{536870912u,5,-6},{0u,3,-2},};
+
+static const HuffmanTyp mpc_table_HuffQ1 [2] [3*3*3] = {
+ {{3758096384u,3,13},{3690987520u,6,26},{3623878656u,6,0},{3556769792u,6,20},{3489660928u,6,6},{3221225472u,4,14},{2952790016u,4,12},{2684354560u,4,4},{2415919104u,4,22},{2348810240u,6,8},{2281701376u,6,18},{2214592512u,6,24},{2147483648u,6,2},{1879048192u,4,16},{1610612736u,4,10},{1476395008u,5,17},{1342177280u,5,9},{1207959552u,5,1},{1073741824u,5,25},{939524096u,5,5},{805306368u,5,21},{671088640u,5,3},{536870912u,5,11},{402653184u,5,15},{268435456u,5,23},{134217728u,5,19},{0u,5,7},},
+ {{2147483648u,1,13},{2113929216u,7,15},{2080374784u,7,1},{2046820352u,7,11},{2013265920u,7,7},{1979711488u,7,17},{1946157056u,7,25},{1912602624u,7,19},{1904214016u,9,8},{1895825408u,9,18},{1887436800u,9,2},{1879048192u,9,24},{1845493760u,7,3},{1811939328u,7,23},{1778384896u,7,21},{1744830464u,7,5},{1728053248u,8,0},{1711276032u,8,26},{1694498816u,8,6},{1677721600u,8,20},{1610612736u,6,9},{1342177280u,4,14},{1073741824u,4,12},{805306368u,4,4},{536870912u,4,22},{268435456u,4,16},{0u,4,10},},
+};
+static const HuffmanTyp mpc_table_HuffQ2 [2] [5*5] = {
+ {{4026531840u,4,13},{3758096384u,4,17},{3489660928u,4,7},{3221225472u,4,11},{3154116608u,6,1},{3087007744u,6,23},{3053453312u,7,4},{3019898880u,7,20},{2986344448u,7,0},{2952790016u,7,24},{2818572288u,5,22},{2684354560u,5,10},{2147483648u,3,12},{2013265920u,5,2},{1879048192u,5,14},{1610612736u,4,6},{1342177280u,4,18},{1073741824u,4,8},{805306368u,4,16},{671088640u,5,9},{536870912u,5,5},{402653184u,5,15},{268435456u,5,21},{134217728u,5,19},{0u,5,3},},
+ {{4160749568u,5,18},{4026531840u,5,6},{3892314112u,5,8},{3875536896u,8,3},{3871342592u,10,24},{3867148288u,10,4},{3862953984u,10,0},{3858759680u,10,20},{3825205248u,7,23},{3791650816u,7,1},{3758096384u,7,19},{3623878656u,5,16},{3590324224u,7,15},{3556769792u,7,21},{3523215360u,7,9},{3489660928u,7,5},{3422552064u,6,2},{3355443200u,6,10},{3288334336u,6,14},{3221225472u,6,22},{2147483648u,2,12},{1610612736u,3,13},{1073741824u,3,17},{536870912u,3,11},{0u,3,7},},
+};
+static const HuffmanTyp mpc_table_HuffQ3 [2] [ 7] = {
+ {{3758096384u,3,1},{3489660928u,4,3},{3221225472u,4,-3},{2684354560u,3,2},{2147483648u,3,-2},{1073741824u,2,0},{0u,2,-1},},
+ {{3221225472u,2,0},{2147483648u,2,-1},{1073741824u,2,1},{805306368u,4,-2},{671088640u,5,3},{536870912u,5,-3},{0u,3,2},},
+};
+static const HuffmanTyp mpc_table_HuffQ4 [2] [ 9] = {
+ {{3758096384u,3,0},{3221225472u,3,-1},{2684354560u,3,1},{2147483648u,3,-2},{1610612736u,3,2},{1342177280u,4,-4},{1073741824u,4,4},{536870912u,3,3},{0u,3,-3},},
+ {{3758096384u,3,1},{3489660928u,4,2},{3221225472u,4,-3},{2147483648u,2,0},{1610612736u,3,-2},{1342177280u,4,3},{1207959552u,5,-4},{1073741824u,5,4},{0u,2,-1},},
+};
+static const HuffmanTyp mpc_table_HuffQ5 [2] [15] = {
+ {{4026531840u,4,2},{3892314112u,5,5},{3825205248u,6,-7},{3758096384u,6,7},{3489660928u,4,-3},{3221225472u,4,3},{3087007744u,5,-6},{2952790016u,5,6},{2684354560u,4,-4},{2415919104u,4,4},{2147483648u,4,-5},{1610612736u,3,0},{1073741824u,3,-1},{536870912u,3,1},{0u,3,-2},},
+ {{4026531840u,4,3},{3892314112u,5,4},{3858759680u,7,6},{3841982464u,8,-7},{3825205248u,8,7},{3758096384u,6,-6},{3221225472u,3,0},{2684354560u,3,-1},{2147483648u,3,1},{1610612736u,3,-2},{1073741824u,3,2},{939524096u,5,-5},{805306368u,5,5},{536870912u,4,-4},{0u,3,-3},},
+};
+static const HuffmanTyp mpc_table_HuffQ6 [2] [31] = {
+ {{4160749568u,5,3},{4026531840u,5,-4},{3959422976u,6,-11},{3892314112u,6,12},{3758096384u,5,4},{3623878656u,5,6},{3489660928u,5,-5},{3355443200u,5,5},{3221225472u,5,7},{3087007744u,5,-7},{3019898880u,6,-12},{2952790016u,6,-13},{2818572288u,5,-6},{2684354560u,5,8},{2550136832u,5,-8},{2415919104u,5,9},{2281701376u,5,-9},{2214592512u,6,13},{2181038080u,7,-15},{2147483648u,7,15},{1879048192u,4,0},{1744830464u,5,-10},{1610612736u,5,10},{1342177280u,4,-1},{1073741824u,4,2},{805306368u,4,1},{536870912u,4,-2},{469762048u,6,14},{402653184u,6,-14},{268435456u,5,11},{0u,4,-3},},
+ {{4160749568u,5,-6},{4026531840u,5,6},{3758096384u,4,1},{3489660928u,4,-1},{3456106496u,7,10},{3422552064u,7,-10},{3405774848u,8,-11},{3397386240u,9,-12},{3395289088u,11,13},{3394764800u,13,15},{3394240512u,13,-14},{3393716224u,13,14},{3393191936u,13,-15},{3388997632u,10,-13},{3372220416u,8,11},{3355443200u,8,12},{3288334336u,6,-9},{3221225472u,6,9},{2952790016u,4,-2},{2684354560u,4,2},{2415919104u,4,3},{2147483648u,4,-3},{2013265920u,5,-7},{1879048192u,5,7},{1610612736u,4,-4},{1342177280u,4,4},{1207959552u,5,-8},{1073741824u,5,8},{805306368u,4,5},{536870912u,4,-5},{0u,3,0},},
+};
+static const HuffmanTyp mpc_table_HuffQ7 [2] [63] = {
+ {{4227858432u,6,7},{4160749568u,6,8},{4093640704u,6,9},{4026531840u,6,-8},{3959422976u,6,11},{3925868544u,7,21},{3909091328u,8,-28},{3892314112u,8,28},{3825205248u,6,-9},{3791650816u,7,-22},{3758096384u,7,-21},{3690987520u,6,-10},{3623878656u,6,-11},{3556769792u,6,10},{3489660928u,6,12},{3422552064u,6,-13},{3388997632u,7,22},{3355443200u,7,23},{3288334336u,6,-12},{3221225472u,6,13},{3154116608u,6,14},{3087007744u,6,-14},{3053453312u,7,-23},{3036676096u,8,-29},{3019898880u,8,29},{2952790016u,6,-15},{2885681152u,6,15},{2818572288u,6,16},{2751463424u,6,-16},{2717908992u,7,-24},{2684354560u,7,24},{2617245696u,6,17},{2583691264u,7,-25},{2566914048u,8,-30},{2550136832u,8,30},{2483027968u,6,-17},{2415919104u,6,18},{2348810240u,6,-18},{2315255808u,7,25},{2281701376u,7,26},{2214592512u,6,19},{2181038080u,7,-26},{2147483648u,7,-27},{2013265920u,5,2},{1946157056u,6,-19},{1879048192u,6,20},{1744830464u,5,-1},{1728053248u,8,-31},{1711276032u,8,31},{1677721600u,7,27},{1610612736u,6,-20},{1476395008u,5,1},{1342177280u,5,-5},{1207959552u,5,-3},{1073741824u,5,3},{939524096u,5,0},{805306368u,5,-2},{671088640u,5,-4},{536870912u,5,4},{402653184u,5,5},{268435456u,5,-6},{134217728u,5,6},{0u,5,-7},},
+ {{4160749568u,5,-1},{4026531840u,5,2},{3892314112u,5,-2},{3758096384u,5,3},{3741319168u,8,-20},{3737124864u,10,24},{3736862720u,14,28},{3736600576u,14,-28},{3736338432u,14,-30},{3736076288u,14,30},{3735027712u,12,-27},{3734765568u,14,29},{3734503424u,14,-29},{3734241280u,14,31},{3733979136u,14,-31},{3732930560u,12,27},{3724541952u,9,-22},{3690987520u,7,-17},{3623878656u,6,-11},{3489660928u,5,-3},{3355443200u,5,4},{3221225472u,5,-4},{3187671040u,7,17},{3170893824u,8,20},{3162505216u,9,22},{3158310912u,10,-25},{3154116608u,10,-26},{3087007744u,6,12},{2952790016u,5,5},{2818572288u,5,-5},{2684354560u,5,6},{2550136832u,5,-6},{2483027968u,6,-12},{2449473536u,7,-18},{2415919104u,7,18},{2348810240u,6,13},{2281701376u,6,-13},{2147483648u,5,-7},{2080374784u,6,14},{2063597568u,8,21},{2046820352u,8,-21},{2013265920u,7,-19},{1879048192u,5,7},{1744830464u,5,8},{1677721600u,6,-14},{1610612736u,6,-15},{1476395008u,5,-8},{1409286144u,6,15},{1375731712u,7,19},{1371537408u,10,25},{1367343104u,10,26},{1358954496u,9,-23},{1350565888u,9,23},{1342177280u,9,-24},{1207959552u,5,-9},{1073741824u,5,9},{1006632960u,6,16},{939524096u,6,-16},{805306368u,5,10},{536870912u,4,0},{402653184u,5,-10},{268435456u,5,11},{0u,4,1},},
+};
+
+const HuffmanTyp* mpc_table_HuffQ [2] [8] = {
+ {0,mpc_table_HuffQ1[0],mpc_table_HuffQ2[0],mpc_table_HuffQ3[0],mpc_table_HuffQ4[0],mpc_table_HuffQ5[0],mpc_table_HuffQ6[0],mpc_table_HuffQ7[0]},
+ {0,mpc_table_HuffQ1[1],mpc_table_HuffQ2[1],mpc_table_HuffQ3[1],mpc_table_HuffQ4[1],mpc_table_HuffQ5[1],mpc_table_HuffQ6[1],mpc_table_HuffQ7[1]},
+};
diff --git a/contrib/libmpcdec/idtag.c b/contrib/libmpcdec/idtag.c
new file mode 100644
index 000000000..7cecdb04e
--- /dev/null
+++ b/contrib/libmpcdec/idtag.c
@@ -0,0 +1,83 @@
+/*
+ Copyright (c) 2005, The Musepack Development Team
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of the The Musepack Development Team nor the
+ names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/// \file idtag.c
+/// Rudimentary id3tag handling routines, just enough to skip id3v2 tags,
+/// if present.
+
+#include <mpcdec/mpcdec.h>
+#include <mpcdec/internal.h>
+
+mpc_int32_t
+JumpID3v2 (mpc_reader* r) {
+ unsigned char tmp [10];
+ mpc_uint32_t Unsynchronisation; // ID3v2.4-flag
+ mpc_uint32_t ExtHeaderPresent; // ID3v2.4-flag
+ mpc_uint32_t ExperimentalFlag; // ID3v2.4-flag
+ mpc_uint32_t FooterPresent; // ID3v2.4-flag
+ mpc_int32_t ret;
+
+ // seek to first byte of mpc data
+ if (!r->seek (r->data, 0)) {
+ return 0;
+ }
+
+ r->read(r->data, tmp, sizeof(tmp));
+
+ // check id3-tag
+ if ( 0 != memcmp ( tmp, "ID3", 3) )
+ return 0;
+
+ // read flags
+ Unsynchronisation = tmp[5] & 0x80;
+ ExtHeaderPresent = tmp[5] & 0x40;
+ ExperimentalFlag = tmp[5] & 0x20;
+ FooterPresent = tmp[5] & 0x10;
+
+ if ( tmp[5] & 0x0F )
+ return -1; // not (yet???) allowed
+ if ( (tmp[6] | tmp[7] | tmp[8] | tmp[9]) & 0x80 )
+ return -1; // not allowed
+
+ // read HeaderSize (syncsave: 4 * $0xxxxxxx = 28 significant bits)
+ ret = tmp[6] << 21;
+ ret += tmp[7] << 14;
+ ret += tmp[8] << 7;
+ ret += tmp[9] ;
+ ret += 10;
+ if ( FooterPresent )
+ ret += 10;
+
+ return ret;
+}
diff --git a/contrib/libmpcdec/mpc_decoder.c b/contrib/libmpcdec/mpc_decoder.c
new file mode 100644
index 000000000..0617869c8
--- /dev/null
+++ b/contrib/libmpcdec/mpc_decoder.c
@@ -0,0 +1,1271 @@
+/*
+ Copyright (c) 2005, The Musepack Development Team
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of the The Musepack Development Team nor the
+ names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/// \file mpc_decoder.c
+/// Core decoding routines and logic.
+
+#include <mpcdec/mpcdec.h>
+#include <mpcdec/internal.h>
+#include <mpcdec/requant.h>
+#include <mpcdec/huffman.h>
+
+//SV7 tables
+extern const HuffmanTyp* mpc_table_HuffQ [2] [8];
+extern const HuffmanTyp mpc_table_HuffHdr [10];
+extern const HuffmanTyp mpc_table_HuffSCFI [ 4];
+extern const HuffmanTyp mpc_table_HuffDSCF [16];
+
+
+#ifdef MPC_SUPPORT_SV456
+//SV4/5/6 tables
+extern const HuffmanTyp* mpc_table_SampleHuff [18];
+extern const HuffmanTyp mpc_table_SCFI_Bundle [ 8];
+extern const HuffmanTyp mpc_table_DSCF_Entropie [13];
+extern const HuffmanTyp mpc_table_Region_A [16];
+extern const HuffmanTyp mpc_table_Region_B [ 8];
+extern const HuffmanTyp mpc_table_Region_C [ 4];
+
+#endif
+
+#ifndef MPC_LITTLE_ENDIAN
+#define SWAP(X) mpc_swap32(X)
+#else
+#define SWAP(X) (X)
+#endif
+
+//------------------------------------------------------------------------------
+// types
+//------------------------------------------------------------------------------
+enum
+ {
+ EQ_TAP = 13, // length of FIR filter for EQ
+ DELAY = ((EQ_TAP + 1) / 2), // delay of FIR
+ FIR_BANDS = 4, // number of subbands to be FIR filtered
+ MEMSIZE = MPC_DECODER_MEMSIZE, // overall buffer size
+ MEMSIZE2 = (MEMSIZE/2), // size of one buffer
+ MEMMASK = (MEMSIZE-1)
+ };
+
+//------------------------------------------------------------------------------
+// forward declarations
+//------------------------------------------------------------------------------
+void mpc_decoder_read_bitstream_sv6(mpc_decoder *d, mpc_bool_t seeking);
+void mpc_decoder_read_bitstream_sv7(mpc_decoder *d, mpc_bool_t seeking);
+mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample);
+void mpc_decoder_requantisierung(mpc_decoder *d, const mpc_int32_t Last_Band);
+
+//------------------------------------------------------------------------------
+// utility functions
+//------------------------------------------------------------------------------
+static mpc_int32_t f_read(mpc_decoder *d, void *ptr, mpc_int32_t size)
+{
+ return d->r->read(d->r->data, ptr, size);
+}
+
+static mpc_bool_t f_seek(mpc_decoder *d, mpc_int32_t offset)
+{
+ return d->r->seek(d->r->data, offset);
+}
+
+static mpc_int32_t f_read_dword(mpc_decoder *d, mpc_uint32_t * ptr, mpc_uint32_t count)
+{
+ return f_read(d, ptr, count << 2) >> 2;
+}
+
+static void mpc_decoder_seek(mpc_decoder *d, mpc_uint32_t bitpos)
+{
+ f_seek(d, (bitpos>>5) * 4 + d->MPCHeaderPos);
+ f_read_dword(d, d->Speicher, MEMSIZE);
+ d->dword = SWAP(d->Speicher[d->Zaehler = 0]);
+ d->pos = bitpos & 31;
+ d->WordsRead = bitpos >> 5;
+}
+
+// jump desired number of bits out of the bitstream
+static void mpc_decoder_bitstream_jump(mpc_decoder *d, const mpc_uint32_t bits)
+{
+ d->pos += bits;
+
+ if (d->pos >= 32) {
+ d->Zaehler = (d->Zaehler + (d->pos >> 5)) & MEMMASK;
+ d->dword = SWAP(d->Speicher[d->Zaehler]);
+ d->WordsRead += d->pos >> 5;
+ d->pos &= 31;
+ }
+}
+
+void mpc_decoder_update_buffer(mpc_decoder *d, mpc_uint32_t RING)
+{
+ if ((RING ^ d->Zaehler) & MEMSIZE2 ) {
+ // update buffer
+ f_read_dword(d, d->Speicher + (RING & MEMSIZE2), MEMSIZE2);
+ }
+}
+
+//------------------------------------------------------------------------------
+// huffman & bitstream functions
+//------------------------------------------------------------------------------
+
+/* F U N C T I O N S */
+
+// resets bitstream decoding
+static void
+mpc_decoder_reset_bitstream_decode(mpc_decoder *d)
+{
+ d->dword = 0;
+ d->pos = 0;
+ d->Zaehler = 0;
+ d->WordsRead = 0;
+}
+
+// reports the number of read bits
+static mpc_uint32_t
+mpc_decoder_bits_read(mpc_decoder *d)
+{
+ return 32 * d->WordsRead + d->pos;
+}
+
+// read desired number of bits out of the bitstream (max 31)
+static mpc_uint32_t
+mpc_decoder_bitstream_read(mpc_decoder *d, const mpc_uint32_t bits)
+{
+ mpc_uint32_t out = d->dword;
+
+ d->pos += bits;
+
+ if (d->pos < 32) {
+ out >>= (32 - d->pos);
+ } else {
+ d->dword = SWAP(d->Speicher[d->Zaehler = (d->Zaehler + 1) & MEMMASK]);
+ d->pos -= 32;
+ if (d->pos) {
+ out <<= d->pos;
+ out |= d->dword >> (32 - d->pos);
+ }
+ d->WordsRead++;
+ }
+
+ return out & ((1 << bits) - 1);
+}
+
+// basic huffman decoding routine
+// works with maximum lengths up to max_length
+static mpc_int32_t
+mpc_decoder_huffman_decode(mpc_decoder *d, const HuffmanTyp *Table,
+ const mpc_uint32_t max_length)
+{
+ // load preview and decode
+ mpc_uint32_t code = d->dword << d->pos;
+ if (32 - d->pos < max_length)
+ code |= SWAP(d->Speicher[(d->Zaehler + 1) & MEMMASK]) >> (32 - d->pos);
+
+ while (code < Table->Code) Table++;
+
+ // set the new position within bitstream without performing a dummy-read
+ if ((d->pos += Table->Length) >= 32) {
+ d->pos -= 32;
+ d->dword = SWAP(d->Speicher[d->Zaehler = (d->Zaehler + 1) & MEMMASK]);
+ d->WordsRead++;
+ }
+
+ return Table->Value;
+}
+
+// decode SCFI-bundle (sv4,5,6)
+static void
+mpc_decoder_scfi_bundle_read(mpc_decoder *d, const HuffmanTyp* Table,
+ mpc_int32_t* SCFI, mpc_bool_t* DSCF)
+{
+ mpc_uint32_t value = mpc_decoder_huffman_decode(d, Table, 6);
+
+ *SCFI = value >> 1;
+ *DSCF = value & 1;
+}
+
+static void
+mpc_decoder_reset_v(mpc_decoder *d)
+{
+ memset(d->V_L, 0, sizeof d->V_L);
+ memset(d->V_R, 0, sizeof d->V_R);
+}
+
+static void
+mpc_decoder_reset_synthesis(mpc_decoder *d)
+{
+ mpc_decoder_reset_v(d);
+}
+
+static void
+mpc_decoder_reset_y(mpc_decoder *d)
+{
+ memset(d->Y_L, 0, sizeof d->Y_L);
+ memset(d->Y_R, 0, sizeof d->Y_R);
+}
+
+static void
+mpc_decoder_reset_globals(mpc_decoder *d)
+{
+ mpc_decoder_reset_bitstream_decode(d);
+
+ d->DecodedFrames = 0;
+ d->StreamVersion = 0;
+ d->MS_used = 0;
+
+ memset(d->Y_L , 0, sizeof d->Y_L );
+ memset(d->Y_R , 0, sizeof d->Y_R );
+ memset(d->SCF_Index_L , 1, sizeof d->SCF_Index_L );
+ memset(d->SCF_Index_R , 1, sizeof d->SCF_Index_R );
+ memset(d->Res_L , 0, sizeof d->Res_L );
+ memset(d->Res_R , 0, sizeof d->Res_R );
+ memset(d->SCFI_L , 0, sizeof d->SCFI_L );
+ memset(d->SCFI_R , 0, sizeof d->SCFI_R );
+ memset(d->DSCF_Flag_L , 0, sizeof d->DSCF_Flag_L );
+ memset(d->DSCF_Flag_R , 0, sizeof d->DSCF_Flag_R );
+ memset(d->Q , 0, sizeof d->Q );
+ memset(d->MS_Flag , 0, sizeof d->MS_Flag );
+ memset(d->seeking_table , 0, sizeof d->seeking_table );
+}
+
+// Frame decoding. Takes big endian 32 bits words as input
+mpc_uint32_t
+mpc_decoder_decode_frame(mpc_decoder *d, mpc_uint32_t *in_buffer,
+ mpc_uint32_t in_len, MPC_SAMPLE_FORMAT *out_buffer)
+{
+ unsigned int i;
+ mpc_decoder_reset_bitstream_decode(d);
+ if (in_len > sizeof(d->Speicher)) in_len = sizeof(d->Speicher);
+ memcpy(d->Speicher, in_buffer, in_len);
+ for (i = 0; i < (in_len + 3) / 4; i++)
+ d->Speicher[i] = mpc_swap32(d->Speicher[i]);
+ d->dword = SWAP(d->Speicher[0]);
+ switch (d->StreamVersion) {
+#ifdef MPC_SUPPORT_SV456
+ case 0x04:
+ case 0x05:
+ case 0x06:
+ mpc_decoder_read_bitstream_sv6(d, FALSE);
+ break;
+#endif
+ case 0x07:
+ case 0x17:
+ mpc_decoder_read_bitstream_sv7(d, FALSE);
+ break;
+ default:
+ return (mpc_uint32_t)(-1);
+ }
+ mpc_decoder_requantisierung(d, d->Max_Band);
+ mpc_decoder_synthese_filter_float(d, out_buffer);
+ return mpc_decoder_bits_read(d);
+}
+
+static mpc_uint32_t
+mpc_decoder_decode_internal(mpc_decoder *d, MPC_SAMPLE_FORMAT *buffer)
+{
+ mpc_uint32_t output_frame_length = MPC_FRAME_LENGTH;
+ mpc_uint32_t FwdJumpInfo = 0;
+ mpc_uint32_t FrameBitCnt = 0;
+
+ if (d->DecodedFrames >= d->OverallFrames) {
+ return (mpc_uint32_t)(-1); // end of file -> abort decoding
+ }
+
+ // add seeking info
+ if (d->seeking_table_frames < d->DecodedFrames &&
+ (d->DecodedFrames & ((1 << d->seeking_pwr) - 1)) == 0) {
+ d->seeking_table[d->DecodedFrames >> d->seeking_pwr] = mpc_decoder_bits_read(d);
+ d->seeking_table_frames = d->DecodedFrames;
+ }
+
+ // read jump-info for validity check of frame
+ FwdJumpInfo = mpc_decoder_bitstream_read(d, 20);
+
+ // decode data and check for validity of frame
+ FrameBitCnt = mpc_decoder_bits_read(d);
+ switch (d->StreamVersion) {
+#ifdef MPC_SUPPORT_SV456
+ case 0x04:
+ case 0x05:
+ case 0x06:
+ mpc_decoder_read_bitstream_sv6(d, FALSE);
+ break;
+#endif
+ case 0x07:
+ case 0x17:
+ mpc_decoder_read_bitstream_sv7(d, FALSE);
+ break;
+ default:
+ return (mpc_uint32_t)(-1);
+ }
+ d->FrameWasValid = mpc_decoder_bits_read(d) - FrameBitCnt == FwdJumpInfo;
+
+ // synthesize signal
+ mpc_decoder_requantisierung(d, d->Max_Band);
+ mpc_decoder_synthese_filter_float(d, buffer);
+
+ d->DecodedFrames++;
+
+ // cut off first MPC_DECODER_SYNTH_DELAY zero-samples
+ if (d->DecodedFrames == d->OverallFrames && d->StreamVersion >= 6) {
+ // reconstruct exact filelength
+ mpc_int32_t mod_block = mpc_decoder_bitstream_read(d, 11);
+ mpc_int32_t FilterDecay;
+
+ if (mod_block == 0) {
+ // Encoder bugfix
+ mod_block = 1152;
+ }
+ FilterDecay = (mod_block + MPC_DECODER_SYNTH_DELAY) % MPC_FRAME_LENGTH;
+
+ // additional FilterDecay samples are needed for decay of synthesis filter
+ if (MPC_DECODER_SYNTH_DELAY + mod_block >= MPC_FRAME_LENGTH) {
+ if (!d->TrueGaplessPresent) {
+ mpc_decoder_reset_y(d);
+ } else {
+ mpc_decoder_bitstream_read(d, 20);
+ mpc_decoder_read_bitstream_sv7(d, FALSE);
+ mpc_decoder_requantisierung(d, d->Max_Band);
+ }
+
+ mpc_decoder_synthese_filter_float(d, buffer + 2304);
+
+ output_frame_length = MPC_FRAME_LENGTH + FilterDecay;
+ }
+ else { // there are only FilterDecay samples needed for this frame
+ output_frame_length = FilterDecay;
+ }
+ }
+
+ if (d->samples_to_skip) {
+ if (output_frame_length < d->samples_to_skip) {
+ d->samples_to_skip -= output_frame_length;
+ output_frame_length = 0;
+ }
+ else {
+ output_frame_length -= d->samples_to_skip;
+ memmove(
+ buffer,
+ buffer + d->samples_to_skip * 2,
+ output_frame_length * 2 * sizeof (MPC_SAMPLE_FORMAT));
+ d->samples_to_skip = 0;
+ }
+ }
+
+ return output_frame_length;
+}
+
+mpc_uint32_t mpc_decoder_decode(
+ mpc_decoder *d,
+ MPC_SAMPLE_FORMAT *buffer,
+ mpc_uint32_t *vbr_update_acc,
+ mpc_uint32_t *vbr_update_bits)
+{
+ for(;;)
+ {
+ //const mpc_int32_t MaxBrokenFrames = 0; // PluginSettings.MaxBrokenFrames
+
+ mpc_uint32_t RING = d->Zaehler;
+ mpc_int32_t vbr_ring = (RING << 5) + d->pos;
+
+ mpc_uint32_t valid_samples = mpc_decoder_decode_internal(d, buffer);
+
+ if (valid_samples == (mpc_uint32_t)(-1) ) {
+ return 0;
+ }
+
+ /**************** ERROR CONCEALMENT *****************/
+ if (d->FrameWasValid == 0 ) {
+ // error occurred in bitstream
+ return (mpc_uint32_t)(-1);
+ }
+ else {
+ if (vbr_update_acc && vbr_update_bits) {
+ (*vbr_update_acc) ++;
+ vbr_ring = (d->Zaehler << 5) + d->pos - vbr_ring;
+ if (vbr_ring < 0) {
+ vbr_ring += 524288;
+ }
+ (*vbr_update_bits) += vbr_ring;
+ }
+
+ }
+ mpc_decoder_update_buffer(d, RING);
+
+ if (valid_samples > 0) {
+ return valid_samples;
+ }
+ }
+}
+
+void
+mpc_decoder_requantisierung(mpc_decoder *d, const mpc_int32_t Last_Band)
+{
+ mpc_int32_t Band;
+ mpc_int32_t n;
+ MPC_SAMPLE_FORMAT facL;
+ MPC_SAMPLE_FORMAT facR;
+ MPC_SAMPLE_FORMAT templ;
+ MPC_SAMPLE_FORMAT tempr;
+ MPC_SAMPLE_FORMAT* YL;
+ MPC_SAMPLE_FORMAT* YR;
+ mpc_int32_t* L;
+ mpc_int32_t* R;
+
+#ifdef MPC_FIXED_POINT
+#if MPC_FIXED_POINT_FRACTPART == 14
+#define MPC_MULTIPLY_SCF(CcVal, SCF_idx) \
+ MPC_MULTIPLY_EX(CcVal, d->SCF[SCF_idx], d->SCF_shift[SCF_idx])
+#else
+
+#error FIXME, Cc table is in 18.14 format
+
+#endif
+#else
+#define MPC_MULTIPLY_SCF(CcVal, SCF_idx) \
+ MPC_MULTIPLY(CcVal, d->SCF[SCF_idx])
+#endif
+ // requantization and scaling of subband-samples
+ for ( Band = 0; Band <= Last_Band; Band++ ) { // setting pointers
+ YL = d->Y_L[0] + Band;
+ YR = d->Y_R[0] + Band;
+ L = d->Q[Band].L;
+ R = d->Q[Band].R;
+ /************************** MS-coded **************************/
+ if ( d->MS_Flag [Band] ) {
+ if ( d->Res_L [Band] ) {
+ if ( d->Res_R [Band] ) { // M!=0, S!=0
+ facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][0]);
+ facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][0]);
+ for ( n = 0; n < 12; n++, YL += 32, YR += 32 ) {
+ *YL = (templ = MPC_MULTIPLY_FLOAT_INT(facL,*L++))+(tempr = MPC_MULTIPLY_FLOAT_INT(facR,*R++));
+ *YR = templ - tempr;
+ }
+ facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][1]);
+ facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][1]);
+ for ( ; n < 24; n++, YL += 32, YR += 32 ) {
+ *YL = (templ = MPC_MULTIPLY_FLOAT_INT(facL,*L++))+(tempr = MPC_MULTIPLY_FLOAT_INT(facR,*R++));
+ *YR = templ - tempr;
+ }
+ facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][2]);
+ facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][2]);
+ for ( ; n < 36; n++, YL += 32, YR += 32 ) {
+ *YL = (templ = MPC_MULTIPLY_FLOAT_INT(facL,*L++))+(tempr = MPC_MULTIPLY_FLOAT_INT(facR,*R++));
+ *YR = templ - tempr;
+ }
+ } else { // M!=0, S==0
+ facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][0]);
+ for ( n = 0; n < 12; n++, YL += 32, YR += 32 ) {
+ *YR = *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++);
+ }
+ facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][1]);
+ for ( ; n < 24; n++, YL += 32, YR += 32 ) {
+ *YR = *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++);
+ }
+ facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][2]);
+ for ( ; n < 36; n++, YL += 32, YR += 32 ) {
+ *YR = *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++);
+ }
+ }
+ } else {
+ if (d->Res_R[Band]) // M==0, S!=0
+ {
+ facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][0]);
+ for ( n = 0; n < 12; n++, YL += 32, YR += 32 ) {
+ *YR = - (*YL = MPC_MULTIPLY_FLOAT_INT(facR,*(R++)));
+ }
+ facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][1]);
+ for ( ; n < 24; n++, YL += 32, YR += 32 ) {
+ *YR = - (*YL = MPC_MULTIPLY_FLOAT_INT(facR,*(R++)));
+ }
+ facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][2]);
+ for ( ; n < 36; n++, YL += 32, YR += 32 ) {
+ *YR = - (*YL = MPC_MULTIPLY_FLOAT_INT(facR,*(R++)));
+ }
+ } else { // M==0, S==0
+ for ( n = 0; n < 36; n++, YL += 32, YR += 32 ) {
+ *YR = *YL = 0;
+ }
+ }
+ }
+ }
+ /************************** LR-coded **************************/
+ else {
+ if ( d->Res_L [Band] ) {
+ if ( d->Res_R [Band] ) { // L!=0, R!=0
+ facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][0]);
+ facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][0]);
+ for (n = 0; n < 12; n++, YL += 32, YR += 32 ) {
+ *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++);
+ *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++);
+ }
+ facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][1]);
+ facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][1]);
+ for (; n < 24; n++, YL += 32, YR += 32 ) {
+ *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++);
+ *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++);
+ }
+ facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][2]);
+ facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][2]);
+ for (; n < 36; n++, YL += 32, YR += 32 ) {
+ *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++);
+ *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++);
+ }
+ } else { // L!=0, R==0
+ facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][0]);
+ for ( n = 0; n < 12; n++, YL += 32, YR += 32 ) {
+ *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++);
+ *YR = 0;
+ }
+ facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][1]);
+ for ( ; n < 24; n++, YL += 32, YR += 32 ) {
+ *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++);
+ *YR = 0;
+ }
+ facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][2]);
+ for ( ; n < 36; n++, YL += 32, YR += 32 ) {
+ *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++);
+ *YR = 0;
+ }
+ }
+ }
+ else {
+ if ( d->Res_R [Band] ) { // L==0, R!=0
+ facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][0]);
+ for ( n = 0; n < 12; n++, YL += 32, YR += 32 ) {
+ *YL = 0;
+ *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++);
+ }
+ facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][1]);
+ for ( ; n < 24; n++, YL += 32, YR += 32 ) {
+ *YL = 0;
+ *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++);
+ }
+ facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][2]);
+ for ( ; n < 36; n++, YL += 32, YR += 32 ) {
+ *YL = 0;
+ *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++);
+ }
+ } else { // L==0, R==0
+ for ( n = 0; n < 36; n++, YL += 32, YR += 32 ) {
+ *YR = *YL = 0;
+ }
+ }
+ }
+ }
+ }
+}
+
+#ifdef MPC_SUPPORT_SV456
+static const unsigned char Q_res[32][16] = {
+{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17},
+{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17},
+{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17},
+{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17},
+{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17},
+{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17},
+{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17},
+{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17},
+{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17},
+{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17},
+{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17},
+{0,1,2,3,4,5,6,17,0,0,0,0,0,0,0,0},
+{0,1,2,3,4,5,6,17,0,0,0,0,0,0,0,0},
+{0,1,2,3,4,5,6,17,0,0,0,0,0,0,0,0},
+{0,1,2,3,4,5,6,17,0,0,0,0,0,0,0,0},
+{0,1,2,3,4,5,6,17,0,0,0,0,0,0,0,0},
+{0,1,2,3,4,5,6,17,0,0,0,0,0,0,0,0},
+{0,1,2,3,4,5,6,17,0,0,0,0,0,0,0,0},
+{0,1,2,3,4,5,6,17,0,0,0,0,0,0,0,0},
+{0,1,2,3,4,5,6,17,0,0,0,0,0,0,0,0},
+{0,1,2,3,4,5,6,17,0,0,0,0,0,0,0,0},
+{0,1,2,3,4,5,6,17,0,0,0,0,0,0,0,0},
+{0,1,2,3,4,5,6,17,0,0,0,0,0,0,0,0},
+{0,1,2,17,0,0,0,0,0,0,0,0,0,0,0,0},
+{0,1,2,17,0,0,0,0,0,0,0,0,0,0,0,0},
+{0,1,2,17,0,0,0,0,0,0,0,0,0,0,0,0},
+{0,1,2,17,0,0,0,0,0,0,0,0,0,0,0,0},
+{0,1,2,17,0,0,0,0,0,0,0,0,0,0,0,0},
+{0,1,2,17,0,0,0,0,0,0,0,0,0,0,0,0},
+{0,1,2,17,0,0,0,0,0,0,0,0,0,0,0,0},
+{0,1,2,17,0,0,0,0,0,0,0,0,0,0,0,0},
+{0,1,2,17,0,0,0,0,0,0,0,0,0,0,0,0},
+};
+
+/****************************************** SV 6 ******************************************/
+void
+mpc_decoder_read_bitstream_sv6(mpc_decoder *d, mpc_bool_t seeking)
+{
+ mpc_int32_t n,k;
+ mpc_int32_t Max_used_Band=0;
+ const HuffmanTyp *Table;
+ const HuffmanTyp *x1;
+ const HuffmanTyp *x2;
+ mpc_int32_t *L;
+ mpc_int32_t *R;
+ mpc_int32_t *ResL = d->Res_L;
+ mpc_int32_t *ResR = d->Res_R;
+
+ /************************ HEADER **************************/
+ ResL = d->Res_L;
+ ResR = d->Res_R;
+ for (n=0; n <= d->Max_Band; ++n, ++ResL, ++ResR)
+ {
+ if (n<11) Table = mpc_table_Region_A;
+ else if (n>=11 && n<=22) Table = mpc_table_Region_B;
+ else /*if (n>=23)*/ Table = mpc_table_Region_C;
+
+ *ResL = Q_res[n][mpc_decoder_huffman_decode(d, Table, 14)];
+ if (d->MS_used) {
+ d->MS_Flag[n] = mpc_decoder_bitstream_read(d, 1);
+ }
+ *ResR = Q_res[n][mpc_decoder_huffman_decode(d, Table, 14)];
+
+ // only perform the following procedure up to the maximum non-zero subband
+ if (*ResL || *ResR) Max_used_Band = n;
+ }
+
+ /************************* SCFI-Bundle *****************************/
+ ResL = d->Res_L;
+ ResR = d->Res_R;
+ for (n=0; n<=Max_used_Band; ++n, ++ResL, ++ResR) {
+ if (*ResL) mpc_decoder_scfi_bundle_read(d, mpc_table_SCFI_Bundle, &(d->SCFI_L[n]), &(d->DSCF_Flag_L[n]));
+ if (*ResR) mpc_decoder_scfi_bundle_read(d, mpc_table_SCFI_Bundle, &(d->SCFI_R[n]), &(d->DSCF_Flag_R[n]));
+ }
+
+ /***************************** SCFI ********************************/
+ ResL = d->Res_L;
+ ResR = d->Res_R;
+ L = d->SCF_Index_L[0];
+ R = d->SCF_Index_R[0];
+ for (n=0; n <= Max_used_Band; ++n, ++ResL, ++ResR, L+=3, R+=3)
+ {
+ if (*ResL)
+ {
+ /*********** DSCF ************/
+ if (d->DSCF_Flag_L[n]==1)
+ {
+ switch (d->SCFI_L[n])
+ {
+ case 3:
+ L[0] = L[2] + mpc_decoder_huffman_decode(d, mpc_table_DSCF_Entropie, 6);
+ L[1] = L[0];
+ L[2] = L[1];
+ break;
+ case 1:
+ L[0] = L[2] + mpc_decoder_huffman_decode(d, mpc_table_DSCF_Entropie, 6);
+ L[1] = L[0] + mpc_decoder_huffman_decode(d, mpc_table_DSCF_Entropie, 6);
+ L[2] = L[1];
+ break;
+ case 2:
+ L[0] = L[2] + mpc_decoder_huffman_decode(d, mpc_table_DSCF_Entropie, 6);
+ L[1] = L[0];
+ L[2] = L[1] + mpc_decoder_huffman_decode(d, mpc_table_DSCF_Entropie, 6);
+ break;
+ case 0:
+ L[0] = L[2] + mpc_decoder_huffman_decode(d, mpc_table_DSCF_Entropie, 6);
+ L[1] = L[0] + mpc_decoder_huffman_decode(d, mpc_table_DSCF_Entropie, 6);
+ L[2] = L[1] + mpc_decoder_huffman_decode(d, mpc_table_DSCF_Entropie, 6);
+ break;
+ default:
+ return;
+ }
+ if (L[0] > 1024)
+ L[0] = 0x8080;
+ if (L[1] > 1024)
+ L[1] = 0x8080;
+ if (L[2] > 1024)
+ L[2] = 0x8080;
+ }
+ /************ SCF ************/
+ else
+ {
+ switch (d->SCFI_L[n])
+ {
+ case 3:
+ L[0] = mpc_decoder_bitstream_read(d, 6);
+ L[1] = L[0];
+ L[2] = L[1];
+ break;
+ case 1:
+ L[0] = mpc_decoder_bitstream_read(d, 6);
+ L[1] = mpc_decoder_bitstream_read(d, 6);
+ L[2] = L[1];
+ break;
+ case 2:
+ L[0] = mpc_decoder_bitstream_read(d, 6);
+ L[1] = L[0];
+ L[2] = mpc_decoder_bitstream_read(d, 6);
+ break;
+ case 0:
+ L[0] = mpc_decoder_bitstream_read(d, 6);
+ L[1] = mpc_decoder_bitstream_read(d, 6);
+ L[2] = mpc_decoder_bitstream_read(d, 6);
+ break;
+ default:
+ return;
+ }
+ }
+ }
+ if (*ResR)
+ {
+ /*********** DSCF ************/
+ if (d->DSCF_Flag_R[n]==1)
+ {
+ switch (d->SCFI_R[n])
+ {
+ case 3:
+ R[0] = R[2] + mpc_decoder_huffman_decode(d, mpc_table_DSCF_Entropie, 6);
+ R[1] = R[0];
+ R[2] = R[1];
+ break;
+ case 1:
+ R[0] = R[2] + mpc_decoder_huffman_decode(d, mpc_table_DSCF_Entropie, 6);
+ R[1] = R[0] + mpc_decoder_huffman_decode(d, mpc_table_DSCF_Entropie, 6);
+ R[2] = R[1];
+ break;
+ case 2:
+ R[0] = R[2] + mpc_decoder_huffman_decode(d, mpc_table_DSCF_Entropie, 6);
+ R[1] = R[0];
+ R[2] = R[1] + mpc_decoder_huffman_decode(d, mpc_table_DSCF_Entropie, 6);
+ break;
+ case 0:
+ R[0] = R[2] + mpc_decoder_huffman_decode(d, mpc_table_DSCF_Entropie, 6);
+ R[1] = R[0] + mpc_decoder_huffman_decode(d, mpc_table_DSCF_Entropie, 6);
+ R[2] = R[1] + mpc_decoder_huffman_decode(d, mpc_table_DSCF_Entropie, 6);
+ break;
+ default:
+ return;
+ }
+ if (R[0] > 1024)
+ R[0] = 0x8080;
+ if (R[1] > 1024)
+ R[1] = 0x8080;
+ if (R[2] > 1024)
+ R[2] = 0x8080;
+ }
+ /************ SCF ************/
+ else
+ {
+ switch (d->SCFI_R[n])
+ {
+ case 3:
+ R[0] = mpc_decoder_bitstream_read(d, 6);
+ R[1] = R[0];
+ R[2] = R[1];
+ break;
+ case 1:
+ R[0] = mpc_decoder_bitstream_read(d, 6);
+ R[1] = mpc_decoder_bitstream_read(d, 6);
+ R[2] = R[1];
+ break;
+ case 2:
+ R[0] = mpc_decoder_bitstream_read(d, 6);
+ R[1] = R[0];
+ R[2] = mpc_decoder_bitstream_read(d, 6);
+ break;
+ case 0:
+ R[0] = mpc_decoder_bitstream_read(d, 6);
+ R[1] = mpc_decoder_bitstream_read(d, 6);
+ R[2] = mpc_decoder_bitstream_read(d, 6);
+ break;
+ default:
+ return;
+ break;
+ }
+ }
+ }
+ }
+
+ if (seeking == TRUE)
+ return;
+
+ /**************************** Samples ****************************/
+ ResL = d->Res_L;
+ ResR = d->Res_R;
+ for (n=0; n <= Max_used_Band; ++n, ++ResL, ++ResR)
+ {
+ // setting pointers
+ x1 = mpc_table_SampleHuff[*ResL];
+ x2 = mpc_table_SampleHuff[*ResR];
+ L = d->Q[n].L;
+ R = d->Q[n].R;
+
+ if (x1!=NULL || x2!=NULL)
+ for (k=0; k<36; ++k)
+ {
+ if (x1 != NULL) *L++ = mpc_decoder_huffman_decode(d, x1, 8);
+ if (x2 != NULL) *R++ = mpc_decoder_huffman_decode(d, x2, 8);
+ }
+
+ if (*ResL>7 || *ResR>7)
+ for (k=0; k<36; ++k)
+ {
+ if (*ResL>7) *L++ = (mpc_int32_t)mpc_decoder_bitstream_read(d, Res_bit[*ResL]) - Dc[*ResL];
+ if (*ResR>7) *R++ = (mpc_int32_t)mpc_decoder_bitstream_read(d, Res_bit[*ResR]) - Dc[*ResR];
+ }
+ }
+}
+#endif //MPC_SUPPORT_SV456
+/****************************************** SV 7 ******************************************/
+void
+mpc_decoder_read_bitstream_sv7(mpc_decoder *d, mpc_bool_t seeking)
+{
+ // these arrays hold decoding results for bundled quantizers (3- and 5-step)
+ static const mpc_int32_t idx30[] = { -1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1};
+ static const mpc_int32_t idx31[] = { -1,-1,-1, 0, 0, 0, 1, 1, 1,-1,-1,-1, 0, 0, 0, 1, 1, 1,-1,-1,-1, 0, 0, 0, 1, 1, 1};
+ static const mpc_int32_t idx32[] = { -1,-1,-1,-1,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1};
+ static const mpc_int32_t idx50[] = { -2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2};
+ static const mpc_int32_t idx51[] = { -2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2};
+
+ mpc_int32_t n,k;
+ mpc_int32_t Max_used_Band=0;
+ const HuffmanTyp *Table;
+ mpc_int32_t idx;
+ mpc_int32_t *L ,*R;
+ mpc_int32_t *ResL,*ResR;
+ mpc_uint32_t tmp;
+
+ /***************************** Header *****************************/
+ ResL = d->Res_L;
+ ResR = d->Res_R;
+
+ // first subband
+ *ResL = mpc_decoder_bitstream_read(d, 4);
+ *ResR = mpc_decoder_bitstream_read(d, 4);
+ if (d->MS_used && !(*ResL==0 && *ResR==0)) {
+ d->MS_Flag[0] = mpc_decoder_bitstream_read(d, 1);
+ }
+
+ // consecutive subbands
+ ++ResL; ++ResR; // increase pointers
+ for (n=1; n <= d->Max_Band; ++n, ++ResL, ++ResR)
+ {
+ idx = mpc_decoder_huffman_decode(d, mpc_table_HuffHdr, 9);
+ *ResL = (idx!=4) ? *(ResL-1) + idx : (int) mpc_decoder_bitstream_read(d, 4);
+
+ idx = mpc_decoder_huffman_decode(d, mpc_table_HuffHdr, 9);
+ *ResR = (idx!=4) ? *(ResR-1) + idx : (int) mpc_decoder_bitstream_read(d, 4);
+
+ if (d->MS_used && !(*ResL==0 && *ResR==0)) {
+ d->MS_Flag[n] = mpc_decoder_bitstream_read(d, 1);
+ }
+
+ // only perform following procedures up to the maximum non-zero subband
+ if (*ResL!=0 || *ResR!=0) {
+ Max_used_Band = n;
+ }
+ }
+ /****************************** SCFI ******************************/
+ L = d->SCFI_L;
+ R = d->SCFI_R;
+ ResL = d->Res_L;
+ ResR = d->Res_R;
+ for (n=0; n <= Max_used_Band; ++n, ++L, ++R, ++ResL, ++ResR) {
+ if (*ResL) *L = mpc_decoder_huffman_decode(d, mpc_table_HuffSCFI, 3);
+ if (*ResR) *R = mpc_decoder_huffman_decode(d, mpc_table_HuffSCFI, 3);
+ }
+
+ /**************************** SCF/DSCF ****************************/
+ ResL = d->Res_L;
+ ResR = d->Res_R;
+ L = d->SCF_Index_L[0];
+ R = d->SCF_Index_R[0];
+ for (n=0; n<=Max_used_Band; ++n, ++ResL, ++ResR, L+=3, R+=3) {
+ if (*ResL)
+ {
+ switch (d->SCFI_L[n])
+ {
+ case 1:
+ idx = mpc_decoder_huffman_decode(d, mpc_table_HuffDSCF, 6);
+ L[0] = (idx!=8) ? L[2] + idx : (int) mpc_decoder_bitstream_read(d, 6);
+ idx = mpc_decoder_huffman_decode(d, mpc_table_HuffDSCF, 6);
+ L[1] = (idx!=8) ? L[0] + idx : (int) mpc_decoder_bitstream_read(d, 6);
+ L[2] = L[1];
+ break;
+ case 3:
+ idx = mpc_decoder_huffman_decode(d, mpc_table_HuffDSCF, 6);
+ L[0] = (idx!=8) ? L[2] + idx : (int) mpc_decoder_bitstream_read(d, 6);
+ L[1] = L[0];
+ L[2] = L[1];
+ break;
+ case 2:
+ idx = mpc_decoder_huffman_decode(d, mpc_table_HuffDSCF, 6);
+ L[0] = (idx!=8) ? L[2] + idx : (int) mpc_decoder_bitstream_read(d, 6);
+ L[1] = L[0];
+ idx = mpc_decoder_huffman_decode(d, mpc_table_HuffDSCF, 6);
+ L[2] = (idx!=8) ? L[1] + idx : (int) mpc_decoder_bitstream_read(d, 6);
+ break;
+ case 0:
+ idx = mpc_decoder_huffman_decode(d, mpc_table_HuffDSCF, 6);
+ L[0] = (idx!=8) ? L[2] + idx : (int) mpc_decoder_bitstream_read(d, 6);
+ idx = mpc_decoder_huffman_decode(d, mpc_table_HuffDSCF, 6);
+ L[1] = (idx!=8) ? L[0] + idx : (int) mpc_decoder_bitstream_read(d, 6);
+ idx = mpc_decoder_huffman_decode(d, mpc_table_HuffDSCF, 6);
+ L[2] = (idx!=8) ? L[1] + idx : (int) mpc_decoder_bitstream_read(d, 6);
+ break;
+ default:
+ return;
+ }
+ if (L[0] > 1024)
+ L[0] = 0x8080;
+ if (L[1] > 1024)
+ L[1] = 0x8080;
+ if (L[2] > 1024)
+ L[2] = 0x8080;
+ }
+ if (*ResR)
+ {
+ switch (d->SCFI_R[n])
+ {
+ case 1:
+ idx = mpc_decoder_huffman_decode(d, mpc_table_HuffDSCF, 6);
+ R[0] = (idx!=8) ? R[2] + idx : (int) mpc_decoder_bitstream_read(d, 6);
+ idx = mpc_decoder_huffman_decode(d, mpc_table_HuffDSCF, 6);
+ R[1] = (idx!=8) ? R[0] + idx : (int) mpc_decoder_bitstream_read(d, 6);
+ R[2] = R[1];
+ break;
+ case 3:
+ idx = mpc_decoder_huffman_decode(d, mpc_table_HuffDSCF, 6);
+ R[0] = (idx!=8) ? R[2] + idx : (int) mpc_decoder_bitstream_read(d, 6);
+ R[1] = R[0];
+ R[2] = R[1];
+ break;
+ case 2:
+ idx = mpc_decoder_huffman_decode(d, mpc_table_HuffDSCF, 6);
+ R[0] = (idx!=8) ? R[2] + idx : (int) mpc_decoder_bitstream_read(d, 6);
+ R[1] = R[0];
+ idx = mpc_decoder_huffman_decode(d, mpc_table_HuffDSCF, 6);
+ R[2] = (idx!=8) ? R[1] + idx : (int) mpc_decoder_bitstream_read(d, 6);
+ break;
+ case 0:
+ idx = mpc_decoder_huffman_decode(d, mpc_table_HuffDSCF, 6);
+ R[0] = (idx!=8) ? R[2] + idx : (int) mpc_decoder_bitstream_read(d, 6);
+ idx = mpc_decoder_huffman_decode(d, mpc_table_HuffDSCF, 6);
+ R[1] = (idx!=8) ? R[0] + idx : (int) mpc_decoder_bitstream_read(d, 6);
+ idx = mpc_decoder_huffman_decode(d, mpc_table_HuffDSCF, 6);
+ R[2] = (idx!=8) ? R[1] + idx : (int) mpc_decoder_bitstream_read(d, 6);
+ break;
+ default:
+ return;
+ }
+ if (R[0] > 1024)
+ R[0] = 0x8080;
+ if (R[1] > 1024)
+ R[1] = 0x8080;
+ if (R[2] > 1024)
+ R[2] = 0x8080;
+ }
+ }
+
+ if (seeking == TRUE)
+ return;
+
+ /***************************** Samples ****************************/
+ ResL = d->Res_L;
+ ResR = d->Res_R;
+ L = d->Q[0].L;
+ R = d->Q[0].R;
+ for (n=0; n <= Max_used_Band; ++n, ++ResL, ++ResR, L+=36, R+=36)
+ {
+ /************** links **************/
+ switch (*ResL)
+ {
+ case -2: case -3: case -4: case -5: case -6: case -7: case -8: case -9:
+ case -10: case -11: case -12: case -13: case -14: case -15: case -16: case -17:
+ L += 36;
+ break;
+ case -1:
+ for (k=0; k<36; k++ ) {
+ tmp = mpc_random_int(d);
+ *L++ = ((tmp >> 24) & 0xFF) + ((tmp >> 16) & 0xFF) + ((tmp >> 8) & 0xFF) + ((tmp >> 0) & 0xFF) - 510;
+ }
+ break;
+ case 0:
+ L += 36;// increase pointer
+ break;
+ case 1:
+ Table = mpc_table_HuffQ[mpc_decoder_bitstream_read(d, 1)][1];
+ for (k=0; k<12; ++k)
+ {
+ idx = mpc_decoder_huffman_decode(d, Table, 9);
+ *L++ = idx30[idx];
+ *L++ = idx31[idx];
+ *L++ = idx32[idx];
+ }
+ break;
+ case 2:
+ Table = mpc_table_HuffQ[mpc_decoder_bitstream_read(d, 1)][2];
+ for (k=0; k<18; ++k)
+ {
+ idx = mpc_decoder_huffman_decode(d, Table, 10);
+ *L++ = idx50[idx];
+ *L++ = idx51[idx];
+ }
+ break;
+ case 3:
+ case 4:
+ Table = mpc_table_HuffQ[mpc_decoder_bitstream_read(d, 1)][*ResL];
+ for (k=0; k<36; ++k)
+ *L++ = mpc_decoder_huffman_decode(d, Table, 5);
+ break;
+ case 5:
+ Table = mpc_table_HuffQ[mpc_decoder_bitstream_read(d, 1)][*ResL];
+ for (k=0; k<36; ++k)
+ *L++ = mpc_decoder_huffman_decode(d, Table, 8);
+ break;
+ case 6:
+ case 7:
+ Table = mpc_table_HuffQ[mpc_decoder_bitstream_read(d, 1)][*ResL];
+ for (k=0; k<36; ++k)
+ *L++ = mpc_decoder_huffman_decode(d, Table, 14);
+ break;
+ case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17:
+ tmp = Dc[*ResL];
+ for (k=0; k<36; ++k)
+ *L++ = (mpc_int32_t)mpc_decoder_bitstream_read(d, Res_bit[*ResL]) - tmp;
+ break;
+ default:
+ return;
+ }
+ /************** rechts **************/
+ switch (*ResR)
+ {
+ case -2: case -3: case -4: case -5: case -6: case -7: case -8: case -9:
+ case -10: case -11: case -12: case -13: case -14: case -15: case -16: case -17:
+ R += 36;
+ break;
+ case -1:
+ for (k=0; k<36; k++ ) {
+ tmp = mpc_random_int(d);
+ *R++ = ((tmp >> 24) & 0xFF) + ((tmp >> 16) & 0xFF) + ((tmp >> 8) & 0xFF) + ((tmp >> 0) & 0xFF) - 510;
+ }
+ break;
+ case 0:
+ R += 36;// increase pointer
+ break;
+ case 1:
+ Table = mpc_table_HuffQ[mpc_decoder_bitstream_read(d, 1)][1];
+ for (k=0; k<12; ++k)
+ {
+ idx = mpc_decoder_huffman_decode(d, Table, 9);
+ *R++ = idx30[idx];
+ *R++ = idx31[idx];
+ *R++ = idx32[idx];
+ }
+ break;
+ case 2:
+ Table = mpc_table_HuffQ[mpc_decoder_bitstream_read(d, 1)][2];
+ for (k=0; k<18; ++k)
+ {
+ idx = mpc_decoder_huffman_decode(d, Table, 10);
+ *R++ = idx50[idx];
+ *R++ = idx51[idx];
+ }
+ break;
+ case 3:
+ case 4:
+ Table = mpc_table_HuffQ[mpc_decoder_bitstream_read(d, 1)][*ResR];
+ for (k=0; k<36; ++k)
+ *R++ = mpc_decoder_huffman_decode(d, Table, 5);
+ break;
+ case 5:
+ Table = mpc_table_HuffQ[mpc_decoder_bitstream_read(d, 1)][*ResR];
+ for (k=0; k<36; ++k)
+ *R++ = mpc_decoder_huffman_decode(d, Table, 8);
+ break;
+ case 6:
+ case 7:
+ Table = mpc_table_HuffQ[mpc_decoder_bitstream_read(d, 1)][*ResR];
+ for (k=0; k<36; ++k)
+ *R++ = mpc_decoder_huffman_decode(d, Table, 14);
+ break;
+ case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17:
+ tmp = Dc[*ResR];
+ for (k=0; k<36; ++k)
+ *R++ = (mpc_int32_t)mpc_decoder_bitstream_read(d, Res_bit[*ResR]) - tmp;
+ break;
+ default:
+ return;
+ }
+ }
+}
+
+void mpc_decoder_setup(mpc_decoder *d, mpc_reader *r)
+{
+ d->r = r;
+
+ d->MPCHeaderPos = 0;
+ d->StreamVersion = 0;
+ d->MS_used = 0;
+ d->FrameWasValid = 0;
+ d->OverallFrames = 0;
+ d->DecodedFrames = 0;
+ d->TrueGaplessPresent = 0;
+ d->WordsRead = 0;
+ d->Max_Band = 0;
+ d->SampleRate = 0;
+ d->__r1 = 1;
+ d->__r2 = 1;
+
+ d->Max_Band = 0;
+ d->seeking_window = FAST_SEEKING_WINDOW;
+
+ mpc_decoder_reset_bitstream_decode(d);
+ mpc_decoder_initialisiere_quantisierungstabellen(d, 1.0f);
+#if 0
+ mpc_decoder_init_huffman_sv6(d);
+ mpc_decoder_init_huffman_sv7(d);
+#endif
+}
+
+static mpc_uint32_t get_initial_fpos(mpc_decoder *d)
+{
+ mpc_uint32_t fpos = 0;
+ switch ( d->StreamVersion ) { // setting position to the beginning of the data-bitstream
+ case 0x04: fpos = 48; break;
+ case 0x05:
+ case 0x06: fpos = 64; break;
+ case 0x07:
+ case 0x17: fpos = 200; break;
+ }
+ return fpos;
+}
+
+void mpc_decoder_set_streaminfo(mpc_decoder *d, mpc_streaminfo *si)
+{
+ mpc_decoder_reset_synthesis(d);
+ mpc_decoder_reset_globals(d);
+
+ d->StreamVersion = si->stream_version;
+ d->MS_used = si->ms;
+ d->Max_Band = si->max_band;
+ d->OverallFrames = si->frames;
+ d->MPCHeaderPos = si->header_position;
+ d->TrueGaplessPresent = si->is_true_gapless;
+ d->SampleRate = (mpc_int32_t)si->sample_freq;
+
+ d->samples_to_skip = MPC_DECODER_SYNTH_DELAY;
+}
+
+mpc_bool_t mpc_decoder_initialize(mpc_decoder *d, mpc_streaminfo *si)
+{
+ mpc_decoder_set_streaminfo(d, si);
+
+ // AB: setting position to the beginning of the data-bitstream
+ mpc_decoder_seek(d, get_initial_fpos(d));
+
+ d->seeking_pwr = 0;
+ while (d->OverallFrames > (SEEKING_TABLE_SIZE << d->seeking_pwr))
+ d->seeking_pwr++;
+ d->seeking_table_frames = 0;
+ d->seeking_table[0] = get_initial_fpos(d);
+
+ return TRUE;
+}
+
+void mpc_decoder_set_seeking(mpc_decoder *d, mpc_streaminfo *si, mpc_bool_t fast_seeking)
+{
+ d->seeking_window = FAST_SEEKING_WINDOW;
+ if (si->fast_seek == 0 && fast_seeking == 0)
+ d->seeking_window = SLOW_SEEKING_WINDOW;
+}
+
+mpc_bool_t mpc_decoder_seek_seconds(mpc_decoder *d, double seconds)
+{
+ return mpc_decoder_seek_sample(d, (mpc_int64_t)(seconds * (double)d->SampleRate + 0.5));
+}
+
+mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample)
+{
+ mpc_uint32_t fpos;
+ mpc_uint32_t fwd;
+
+ fwd = (mpc_uint32_t) (destsample / MPC_FRAME_LENGTH);
+ d->samples_to_skip = MPC_DECODER_SYNTH_DELAY + (mpc_uint32_t)(destsample % MPC_FRAME_LENGTH);
+
+ // resetting synthesis filter to avoid "clicks"
+ mpc_decoder_reset_synthesis(d);
+
+ // prevent from desired position out of allowed range
+ fwd = fwd < d->OverallFrames ? fwd : d->OverallFrames;
+
+ if (fwd > d->DecodedFrames + d->seeking_window || fwd < d->DecodedFrames) {
+ memset(d->SCF_Index_L, 1, sizeof d->SCF_Index_L );
+ memset(d->SCF_Index_R, 1, sizeof d->SCF_Index_R );
+ }
+
+ if (d->seeking_table_frames > d->DecodedFrames || fwd < d->DecodedFrames) {
+ d->DecodedFrames = 0;
+ if (fwd > d->seeking_window)
+ d->DecodedFrames = (fwd - d->seeking_window) & (-1 << d->seeking_pwr);
+ if (d->DecodedFrames > d->seeking_table_frames)
+ d->DecodedFrames = d->seeking_table_frames;
+ fpos = d->seeking_table[d->DecodedFrames >> d->seeking_pwr];
+ mpc_decoder_seek(d, fpos);
+ }
+
+ // read the last 32 frames before the desired position to scan the scalefactors (artifactless jumping)
+ for ( ; d->DecodedFrames < fwd; d->DecodedFrames++ ) {
+ mpc_uint32_t RING = d->Zaehler;
+ mpc_uint32_t FwdJumpInfo;
+
+ // add seeking info
+ if (d->seeking_table_frames < d->DecodedFrames &&
+ (d->DecodedFrames & ((1 << d->seeking_pwr) - 1)) == 0) {
+ d->seeking_table[d->DecodedFrames >> d->seeking_pwr] = mpc_decoder_bits_read(d);
+ d->seeking_table_frames = d->DecodedFrames;
+ }
+
+ // read jump-info
+ FwdJumpInfo = mpc_decoder_bitstream_read(d, 20);
+ FwdJumpInfo += mpc_decoder_bits_read(d);
+
+ if (fwd <= d->DecodedFrames + d->seeking_window) {
+ if (d->StreamVersion >= 7) {
+ mpc_decoder_read_bitstream_sv7(d, TRUE);
+ } else {
+#ifdef MPC_SUPPORT_SV456
+ mpc_decoder_read_bitstream_sv6(d, TRUE);
+#else
+ return FALSE;
+#endif
+ }
+ }
+ mpc_decoder_bitstream_jump(d, FwdJumpInfo - mpc_decoder_bits_read(d));
+
+ // update buffer
+ mpc_decoder_update_buffer(d, RING);
+ }
+
+ return TRUE;
+}
diff --git a/contrib/libmpcdec/mpc_reader.c b/contrib/libmpcdec/mpc_reader.c
new file mode 100644
index 000000000..1d0accc01
--- /dev/null
+++ b/contrib/libmpcdec/mpc_reader.c
@@ -0,0 +1,96 @@
+/*
+ Copyright (c) 2005, The Musepack Development Team
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of the The Musepack Development Team nor the
+ names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/// \file mpc_reader.c
+/// Contains implementations for simple file-based mpc_reader
+
+#include <mpcdec/mpcdec.h>
+
+/// mpc_reader callback implementations
+static mpc_int32_t
+read_impl(void *data, void *ptr, mpc_int32_t size)
+{
+ mpc_reader_file *d = (mpc_reader_file *) data;
+
+ return (mpc_int32_t) fread(ptr, 1, size, d->file);
+}
+
+static mpc_bool_t
+seek_impl(void *data, mpc_int32_t offset)
+{
+ mpc_reader_file *d = (mpc_reader_file *) data;
+
+ return d->is_seekable ? fseek(d->file, offset, SEEK_SET) == 0 : FALSE;
+}
+
+static mpc_int32_t
+tell_impl(void *data)
+{
+ mpc_reader_file *d = (mpc_reader_file *) data;
+
+ return ftell(d->file);
+}
+
+static mpc_int32_t
+get_size_impl(void *data)
+{
+ mpc_reader_file *d = (mpc_reader_file *) data;
+
+ return d->file_size;
+}
+
+static mpc_bool_t
+canseek_impl(void *data)
+{
+ mpc_reader_file *d = (mpc_reader_file *) data;
+
+ return d->is_seekable;
+}
+
+void
+mpc_reader_setup_file_reader(mpc_reader_file *p_reader, FILE *input)
+{
+ p_reader->reader.seek = seek_impl;
+ p_reader->reader.read = read_impl;
+ p_reader->reader.tell = tell_impl;
+ p_reader->reader.get_size = get_size_impl;
+ p_reader->reader.canseek = canseek_impl;
+ p_reader->reader.data = p_reader; // point back to ourselves
+
+ p_reader->file = input;
+ p_reader->is_seekable = TRUE;
+ fseek(input, 0, SEEK_END);
+ p_reader->file_size = ftell(input);
+ fseek(input, 0, SEEK_SET);
+}
diff --git a/contrib/libmpcdec/mpcdec/config_types.h b/contrib/libmpcdec/mpcdec/config_types.h
new file mode 100644
index 000000000..97197d048
--- /dev/null
+++ b/contrib/libmpcdec/mpcdec/config_types.h
@@ -0,0 +1,50 @@
+/*
+ Copyright (c) 2005, The Musepack Development Team
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of the The Musepack Development Team nor the
+ names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef __MUSEPACK_CONFIG_TYPES_H__
+#define __MUSEPACK_CONFIG_TYPES_H__
+
+#include "os_types.h"
+
+typedef unsigned char mpc_bool_t;
+#define TRUE 1
+#define FALSE 0
+
+typedef int16_t mpc_int16_t;
+typedef uint16_t mpc_uint16_t;
+typedef int32_t mpc_int32_t;
+typedef uint32_t mpc_uint32_t;
+typedef int64_t mpc_int64_t;
+
+#endif // __MUSEPACK_CONFIG_TYPES_H__
diff --git a/contrib/libmpcdec/mpcdec/decoder.h b/contrib/libmpcdec/mpcdec/decoder.h
new file mode 100644
index 000000000..9a737453e
--- /dev/null
+++ b/contrib/libmpcdec/mpcdec/decoder.h
@@ -0,0 +1,124 @@
+/*
+ Copyright (c) 2005, The Musepack Development Team
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of the The Musepack Development Team nor the
+ names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/// \file decoder.h
+
+#ifndef _mpcdec_decoder_h_
+#define _mpcdec_decoder_h_
+
+#include "huffman.h"
+#include "math.h"
+#include "mpcdec.h"
+#include "reader.h"
+#include "streaminfo.h"
+
+#define MPC_SUPPORT_SV456
+
+#define SEEKING_TABLE_SIZE 256u
+// set it to SLOW_SEEKING_WINDOW to not use fast seeking
+#define FAST_SEEKING_WINDOW 32
+// set it to FAST_SEEKING_WINDOW to only use fast seeking
+#define SLOW_SEEKING_WINDOW 0x80000000
+
+enum {
+ MPC_V_MEM = 2304,
+ MPC_DECODER_MEMSIZE = 16384, // overall buffer size
+};
+
+typedef struct {
+ mpc_int32_t L [36];
+ mpc_int32_t R [36];
+} QuantTyp;
+
+typedef struct mpc_decoder_t {
+ mpc_reader *r;
+
+ /// @name internal state variables
+ //@{
+
+ mpc_uint32_t dword; /// currently decoded 32bit-word
+ mpc_uint32_t pos; /// bit-position within dword
+ mpc_uint32_t Speicher[MPC_DECODER_MEMSIZE]; /// read-buffer
+ mpc_uint32_t Zaehler; /// actual index within read-buffer
+
+ mpc_uint32_t samples_to_skip;
+
+ mpc_uint32_t DecodedFrames;
+ mpc_uint32_t OverallFrames;
+ mpc_int32_t SampleRate; // Sample frequency
+
+ mpc_uint32_t StreamVersion; // version of bitstream
+ mpc_int32_t Max_Band;
+ mpc_uint32_t MPCHeaderPos; // AB: needed to support ID3v2
+
+ mpc_uint32_t FrameWasValid;
+ mpc_uint32_t MS_used; // MS-coding used ?
+ mpc_uint32_t TrueGaplessPresent;
+
+ mpc_uint32_t WordsRead; // counts amount of decoded dwords
+
+ // randomizer state variables
+ mpc_uint32_t __r1;
+ mpc_uint32_t __r2;
+
+ // seeking
+ mpc_uint32_t seeking_table[SEEKING_TABLE_SIZE];
+ mpc_uint32_t seeking_pwr; // distance between 2 frames in seeking_table = 2^seeking_pwr
+ mpc_uint32_t seeking_table_frames; // last frame in seaking table
+ mpc_uint32_t seeking_window; // number of frames to look for scalefactors
+
+ mpc_int32_t SCF_Index_L [32] [3];
+ mpc_int32_t SCF_Index_R [32] [3]; // holds scalefactor-indices
+ QuantTyp Q [32]; // holds quantized samples
+ mpc_int32_t Res_L [32];
+ mpc_int32_t Res_R [32]; // holds the chosen quantizer for each subband
+ mpc_bool_t DSCF_Flag_L [32];
+ mpc_bool_t DSCF_Flag_R [32]; // differential SCF used?
+ mpc_int32_t SCFI_L [32];
+ mpc_int32_t SCFI_R [32]; // describes order of transmitted SCF
+ mpc_bool_t MS_Flag[32]; // MS used?
+#ifdef MPC_FIXED_POINT
+ unsigned char SCF_shift[256];
+#endif
+
+ MPC_SAMPLE_FORMAT V_L[MPC_V_MEM + 960];
+ MPC_SAMPLE_FORMAT V_R[MPC_V_MEM + 960];
+ MPC_SAMPLE_FORMAT Y_L[36][32];
+ MPC_SAMPLE_FORMAT Y_R[36][32];
+ MPC_SAMPLE_FORMAT SCF[256]; ///< holds adapted scalefactors (for clipping prevention)
+ //@}
+
+} mpc_decoder;
+
+#endif // _mpc_decoder_h
diff --git a/contrib/libmpcdec/mpcdec/huffman.h b/contrib/libmpcdec/mpcdec/huffman.h
new file mode 100644
index 000000000..99d02ce71
--- /dev/null
+++ b/contrib/libmpcdec/mpcdec/huffman.h
@@ -0,0 +1,58 @@
+/*
+ Copyright (c) 2005, The Musepack Development Team
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of the The Musepack Development Team nor the
+ names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/// \file huffman.h
+/// Data structures and functions for huffman coding.
+
+#ifndef _mpcdec_huffman_h_
+#define _mpcdec_huffman_h_
+
+#ifndef WIN32
+#include "mpcdec/config_types.h"
+#else
+#include "mpcdec/config_win32.h"
+#endif
+
+#include "decoder.h"
+
+struct mpc_decoder_t; // forward declare to break circular dependencies
+
+/// Huffman table entry.
+typedef struct huffman_type_t {
+ mpc_uint32_t Code;
+ mpc_uint16_t Length;
+ mpc_int16_t Value;
+} HuffmanTyp;
+
+#endif // _mpcdec_huffman_h_
diff --git a/contrib/libmpcdec/mpcdec/internal.h b/contrib/libmpcdec/mpcdec/internal.h
new file mode 100644
index 000000000..19642a240
--- /dev/null
+++ b/contrib/libmpcdec/mpcdec/internal.h
@@ -0,0 +1,65 @@
+/*
+ Copyright (c) 2005, The Musepack Development Team
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of the The Musepack Development Team nor the
+ names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/// \file internal.h
+/// Definitions and structures used only internally by the libmpcdec.
+
+#ifndef _mpcdec_internal_h
+#define _mpcdec_internal_h
+
+
+enum {
+ MPC_DECODER_SYNTH_DELAY = 481
+};
+
+/// Big/little endian 32 bit byte swapping routine.
+static __inline
+mpc_uint32_t mpc_swap32(mpc_uint32_t val) {
+ return (((val & 0xff000000) >> 24) | ((val & 0x00ff0000) >> 8) |
+ ((val & 0x0000ff00) << 8) | ((val & 0x000000ff) << 24));
+}
+
+/// Searches for a ID3v2-tag and reads the length (in bytes) of it.
+/// \param reader supplying raw stream data
+/// \return size of tag, in bytes
+/// \return -1 on errors of any kind
+mpc_int32_t JumpID3v2(mpc_reader* fp);
+
+/// helper functions used by multiple files
+mpc_uint32_t mpc_random_int(mpc_decoder *d); // in synth_filter.c
+void mpc_decoder_initialisiere_quantisierungstabellen(mpc_decoder *d, double scale_factor);
+void mpc_decoder_synthese_filter_float(mpc_decoder *d, MPC_SAMPLE_FORMAT* OutData);
+
+#endif // _mpcdec_internal_h
+
diff --git a/contrib/libmpcdec/mpcdec/math.h b/contrib/libmpcdec/mpcdec/math.h
new file mode 100644
index 000000000..31d078896
--- /dev/null
+++ b/contrib/libmpcdec/mpcdec/math.h
@@ -0,0 +1,144 @@
+/*
+ Copyright (c) 2005, The Musepack Development Team
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of the The Musepack Development Team nor the
+ names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/// \file math.h
+/// Libmpcdec internal math routines.
+
+#ifndef _mpcdec_math_h_
+#define _mpcdec_math_h_
+
+//#define MPC_FIXED_POINT
+
+#define MPC_FIXED_POINT_SHIFT 16
+
+#ifdef MPC_FIXED_POINT
+
+
+#ifdef _WIN32_WCE
+
+#include <cmnintrin.h>
+
+#define MPC_HAVE_MULHIGH
+
+#endif
+
+
+#define MPC_FIXED_POINT_SCALE_SHIFT (MPC_FIXED_POINT_SHIFT + MPC_FIXED_POINT_FRACTPART)
+#define MPC_FIXED_POINT_SCALE (1 << (MPC_FIXED_POINT_SCALE_SHIFT - 1))
+
+
+//in fixedpoint mode, results in decode output buffer are in -MPC_FIXED_POINT_SCALE ... MPC_FIXED_POINT_SCALE range
+
+#define MPC_FIXED_POINT_FRACTPART 14
+typedef mpc_int32_t MPC_SAMPLE_FORMAT;
+
+typedef mpc_int64_t MPC_SAMPLE_FORMAT_MULTIPLY;
+
+#define MAKE_MPC_SAMPLE(X) (MPC_SAMPLE_FORMAT)((double)(X) * (double)(((mpc_int64_t)1)<<MPC_FIXED_POINT_FRACTPART))
+#define MAKE_MPC_SAMPLE_EX(X,Y) (MPC_SAMPLE_FORMAT)((double)(X) * (double)(((mpc_int64_t)1)<<(Y)))
+
+#define MPC_MULTIPLY_NOTRUNCATE(X,Y) \
+ (((MPC_SAMPLE_FORMAT_MULTIPLY)(X) * (MPC_SAMPLE_FORMAT_MULTIPLY)(Y)) >> MPC_FIXED_POINT_FRACTPART)
+
+#define MPC_MULTIPLY_EX_NOTRUNCATE(X,Y,Z) \
+ (((MPC_SAMPLE_FORMAT_MULTIPLY)(X) * (MPC_SAMPLE_FORMAT_MULTIPLY)(Y)) >> (Z))
+
+#ifdef _DEBUG
+static inline MPC_SAMPLE_FORMAT MPC_MULTIPLY(MPC_SAMPLE_FORMAT item1,MPC_SAMPLE_FORMAT item2)
+{
+ MPC_SAMPLE_FORMAT_MULTIPLY temp = MPC_MULTIPLY_NOTRUNCATE(item1,item2);
+ assert(temp == (MPC_SAMPLE_FORMAT_MULTIPLY)(MPC_SAMPLE_FORMAT)temp);
+ return (MPC_SAMPLE_FORMAT)temp;
+}
+
+static inline MPC_SAMPLE_FORMAT MPC_MULTIPLY_EX(MPC_SAMPLE_FORMAT item1,MPC_SAMPLE_FORMAT item2,unsigned shift)
+{
+ MPC_SAMPLE_FORMAT_MULTIPLY temp = MPC_MULTIPLY_EX_NOTRUNCATE(item1,item2,shift);
+ assert(temp == (MPC_SAMPLE_FORMAT_MULTIPLY)(MPC_SAMPLE_FORMAT)temp);
+ return (MPC_SAMPLE_FORMAT)temp;
+}
+
+#else
+
+#define MPC_MULTIPLY(X,Y) ((MPC_SAMPLE_FORMAT)MPC_MULTIPLY_NOTRUNCATE(X,Y))
+#define MPC_MULTIPLY_EX(X,Y,Z) ((MPC_SAMPLE_FORMAT)MPC_MULTIPLY_EX_NOTRUNCATE(X,Y,Z))
+
+#endif
+
+#ifdef MPC_HAVE_MULHIGH
+#define MPC_MULTIPLY_FRACT(X,Y) _MulHigh(X,Y)
+#else
+#define MPC_MULTIPLY_FRACT(X,Y) MPC_MULTIPLY_EX(X,Y,32)
+#endif
+
+#define MPC_MAKE_FRACT_CONST(X) (MPC_SAMPLE_FORMAT)((X) * (double)(((mpc_int64_t)1)<<32) )
+#define MPC_MULTIPLY_FRACT_CONST(X,Y) MPC_MULTIPLY_FRACT(X,MPC_MAKE_FRACT_CONST(Y))
+#define MPC_MULTIPLY_FRACT_CONST_FIX(X,Y,Z) ( MPC_MULTIPLY_FRACT(X,MPC_MAKE_FRACT_CONST( Y / (1<<(Z)) )) << (Z) )
+#define MPC_MULTIPLY_FRACT_CONST_SHR(X,Y,Z) MPC_MULTIPLY_FRACT(X,MPC_MAKE_FRACT_CONST( Y / (1<<(Z)) ))
+
+#define MPC_MULTIPLY_FLOAT_INT(X,Y) ((X)*(Y))
+#define MPC_SCALE_CONST(X,Y,Z) MPC_MULTIPLY_EX(X,MAKE_MPC_SAMPLE_EX(Y,Z),(Z))
+#define MPC_SCALE_CONST_SHL(X,Y,Z,S) MPC_MULTIPLY_EX(X,MAKE_MPC_SAMPLE_EX(Y,Z),(Z)-(S))
+#define MPC_SCALE_CONST_SHR(X,Y,Z,S) MPC_MULTIPLY_EX(X,MAKE_MPC_SAMPLE_EX(Y,Z),(Z)+(S))
+#define MPC_SHR(X,Y) ((X)>>(Y))
+#define MPC_SHL(X,Y) ((X)<<(Y))
+
+#else
+
+//in floating-point mode, decoded samples are in -1...1 range
+
+typedef float MPC_SAMPLE_FORMAT;
+
+#define MAKE_MPC_SAMPLE(X) ((MPC_SAMPLE_FORMAT)(X))
+#define MAKE_MPC_SAMPLE_EX(X,Y) ((MPC_SAMPLE_FORMAT)(X))
+
+#define MPC_MULTIPLY_FRACT(X,Y) ((X)*(Y))
+#define MPC_MAKE_FRACT_CONST(X) (X)
+#define MPC_MULTIPLY_FRACT_CONST(X,Y) MPC_MULTPLY_FRACT(X,MPC_MAKE_FRACT_CONST(Y))
+#define MPC_MULTIPLY_FRACT_CONST_SHR(X,Y,Z) MPC_MULTIPLY_FRACT(X,MPC_MAKE_FRACT_CONST( Y ))
+#define MPC_MULTIPLY_FRACT_CONST_FIX(X,Y,Z) MPC_MULTIPLY_FRACT(X,MPC_MAKE_FRACT_CONST( Y ))
+
+#define MPC_MULTIPLY_FLOAT_INT(X,Y) ((X)*(Y))
+#define MPC_MULTIPLY(X,Y) ((X)*(Y))
+#define MPC_MULTIPLY_EX(X,Y,Z) ((X)*(Y))
+#define MPC_SCALE_CONST(X,Y,Z) ((X)*(Y))
+#define MPC_SCALE_CONST_SHL(X,Y,Z,S) ((X)*(Y))
+#define MPC_SCALE_CONST_SHR(X,Y,Z,S) ((X)*(Y))
+#define MPC_SHR(X,Y) (X)
+#define MPC_SHL(X,Y) (X)
+
+#endif
+
+#endif // _mpcdec_math_h_
+
diff --git a/contrib/libmpcdec/mpcdec/mpcdec.h b/contrib/libmpcdec/mpcdec/mpcdec.h
new file mode 100644
index 000000000..77418fbcc
--- /dev/null
+++ b/contrib/libmpcdec/mpcdec/mpcdec.h
@@ -0,0 +1,145 @@
+/*
+ Copyright (c) 2005, The Musepack Development Team
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of the The Musepack Development Team nor the
+ names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/// \file mpcdec.h
+/// Top level include file for libmpcdec.
+
+#ifndef _mpcdec_h_
+#define _mpcdec_h_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifndef WIN32
+#include "mpcdec/config_types.h"
+#else
+#include "mpcdec/config_win32.h"
+#endif
+
+#include "decoder.h"
+#include "math.h"
+#include "reader.h"
+#include "streaminfo.h"
+
+enum {
+ MPC_FRAME_LENGTH = (36 * 32), /// samples per mpc frame
+ MPC_DECODER_BUFFER_LENGTH = 4 * MPC_FRAME_LENGTH /// required buffer size for decoder
+};
+
+// error codes
+#define ERROR_CODE_OK 0
+#define ERROR_CODE_FILE -1
+#define ERROR_CODE_SV7BETA 1
+#define ERROR_CODE_CBR 2
+#define ERROR_CODE_IS 3
+#define ERROR_CODE_BLOCKSIZE 4
+#define ERROR_CODE_INVALIDSV 5
+
+/// Initializes a streaminfo structure.
+/// \param si streaminfo structure to initialize
+void mpc_streaminfo_init(mpc_streaminfo *si);
+
+/// Reads streaminfo header from the mpc stream supplied by r.
+/// \param si streaminfo pointer to which info will be written
+/// \param r stream reader to supply raw data
+/// \return error code
+mpc_int32_t mpc_streaminfo_read(mpc_streaminfo *si, mpc_reader *r);
+
+/// Gets length of stream si, in seconds.
+/// \return length of stream in seconds
+double mpc_streaminfo_get_length(mpc_streaminfo *si);
+
+/// Returns length of stream si, in samples.
+/// \return length of stream in samples
+mpc_int64_t mpc_streaminfo_get_length_samples(mpc_streaminfo *si);
+
+/// Sets up decoder library.
+/// Call this first when preparing to decode an mpc stream.
+/// \param r reader that will supply raw data to the decoder
+void mpc_decoder_setup(mpc_decoder *d, mpc_reader *r);
+
+/// Initializes mpc decoder with the supplied stream info parameters.
+/// Call this next after calling mpc_decoder_setup.
+/// \param si streaminfo structure indicating format of source stream
+/// \return TRUE if decoder was initalized successfully, FALSE otherwise
+mpc_bool_t mpc_decoder_initialize(mpc_decoder *d, mpc_streaminfo *si);
+
+/// Call this next after calling mpc_decoder_setup.
+/// \param si streaminfo structure indicating format of source stream
+/// \param fast_seeking boolean 0 = use fast seeking if safe, 1 = force fast seeking
+void mpc_decoder_set_seeking(mpc_decoder *d, mpc_streaminfo *si, mpc_bool_t fast_seeking);
+
+void mpc_decoder_set_streaminfo(mpc_decoder *d, mpc_streaminfo *si);
+
+/// Sets decoder sample scaling factor. All decoded samples will be multiplied
+/// by this factor.
+/// \param scale_factor multiplicative scaling factor
+void mpc_decoder_scale_output(mpc_decoder *d, double scale_factor);
+
+/// Actually reads data from previously initialized stream. Call
+/// this iteratively to decode the mpc stream.
+/// \param buffer destination buffer for decoded samples
+/// \param vbr_update_acc \todo document me
+/// \param vbr_update_bits \todo document me
+/// \return -1 if an error is encountered
+/// \return 0 if the stream has been completely decoded successfully and there are no more samples
+/// \return > 0 to indicate the number of bytes that were actually read from the stream.
+mpc_uint32_t mpc_decoder_decode(
+ mpc_decoder *d,
+ MPC_SAMPLE_FORMAT *buffer,
+ mpc_uint32_t *vbr_update_acc,
+ mpc_uint32_t *vbr_update_bits);
+
+mpc_uint32_t mpc_decoder_decode_frame(
+ mpc_decoder *d,
+ mpc_uint32_t *in_buffer,
+ mpc_uint32_t in_len,
+ MPC_SAMPLE_FORMAT *out_buffer);
+
+/// Seeks to the specified sample in the source stream.
+mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample);
+
+/// Seeks to specified position in seconds in the source stream.
+mpc_bool_t mpc_decoder_seek_seconds(mpc_decoder *d, double seconds);
+
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+
+#endif // _mpcdec_h_
diff --git a/contrib/libmpcdec/mpcdec/reader.h b/contrib/libmpcdec/mpcdec/reader.h
new file mode 100644
index 000000000..3d4f57edc
--- /dev/null
+++ b/contrib/libmpcdec/mpcdec/reader.h
@@ -0,0 +1,82 @@
+/*
+ Copyright (c) 2005, The Musepack Development Team
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of the The Musepack Development Team nor the
+ names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/// \file reader.h
+
+#ifndef _mpcdec_reader_h_
+#define _mpcdec_reader_h_
+
+/// \brief Stream reader interface structure.
+///
+/// This is the structure you must supply to the musepack decoding library
+/// to feed it with raw data. Implement the five member functions to provide
+/// a functional reader.
+typedef struct mpc_reader_t {
+ /// Reads size bytes of data into buffer at ptr.
+ mpc_int32_t (*read)(void *t, void *ptr, mpc_int32_t size);
+
+ /// Seeks to byte position offset.
+ mpc_bool_t (*seek)(void *t, mpc_int32_t offset);
+
+ /// Returns the current byte offset in the stream.
+ mpc_int32_t (*tell)(void *t);
+
+ /// Returns the total length of the source stream, in bytes.
+ mpc_int32_t (*get_size)(void *t);
+
+ /// True if the stream is a seekable stream.
+ mpc_bool_t (*canseek)(void *t);
+
+ /// Field that can be used to identify a particular instance of
+ /// reader or carry along data associated with that reader.
+ void *data;
+
+} mpc_reader;
+
+typedef struct mpc_reader_file_t {
+ mpc_reader reader;
+
+ FILE *file;
+ long file_size;
+ mpc_bool_t is_seekable;
+} mpc_reader_file;
+
+/// Initializes reader with default stdio file reader implementation. Use
+/// this if you're just reading from a plain file.
+///
+/// \param r reader struct to initalize
+/// \param input input stream to attach to the reader
+void mpc_reader_setup_file_reader(mpc_reader_file *r, FILE *input);
+
+#endif // _mpcdec_reader_h_
diff --git a/contrib/libmpcdec/mpcdec/requant.h b/contrib/libmpcdec/mpcdec/requant.h
new file mode 100644
index 000000000..a0aab981b
--- /dev/null
+++ b/contrib/libmpcdec/mpcdec/requant.h
@@ -0,0 +1,51 @@
+/*
+ Copyright (c) 2005, The Musepack Development Team
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of the The Musepack Development Team nor the
+ names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/// \file requant.h
+/// Requantization function definitions.
+
+#ifndef _mpcdec_requant_h
+#define _mpcdec_requant_h_
+
+#include "mpcdec.h"
+
+/* C O N S T A N T S */
+extern const mpc_uint32_t Res_bit [18]; // bits per sample for chosen quantizer
+extern const MPC_SAMPLE_FORMAT __Cc [1 + 18]; // coefficients for requantization
+extern const mpc_int32_t __Dc [1 + 18]; // offset for requantization
+
+#define Cc (__Cc + 1)
+#define Dc (__Dc + 1)
+
+#endif // _mpcdec_requant_h_
diff --git a/contrib/libmpcdec/mpcdec/streaminfo.h b/contrib/libmpcdec/mpcdec/streaminfo.h
new file mode 100644
index 000000000..7cf941c47
--- /dev/null
+++ b/contrib/libmpcdec/mpcdec/streaminfo.h
@@ -0,0 +1,91 @@
+/*
+ Copyright (c) 2005, The Musepack Development Team
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of the The Musepack Development Team nor the
+ names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/// \file streaminfo.h
+
+#ifndef _mpcdec_streaminfo_h_
+#define _mpcdec_streaminfo_h_
+
+typedef mpc_int32_t mpc_streaminfo_off_t;
+
+/// \brief mpc stream properties structure
+///
+/// Structure containing all the properties of an mpc stream. Populated
+/// by the streaminfo_read function.
+typedef struct mpc_streaminfo {
+ /// @name core mpc stream properties
+ //@{
+ mpc_uint32_t sample_freq; ///< sample frequency of stream
+ mpc_uint32_t channels; ///< number of channels in stream
+ mpc_streaminfo_off_t header_position; ///< byte offset of position of header in stream
+ mpc_uint32_t stream_version; ///< streamversion of stream
+ mpc_uint32_t bitrate; ///< bitrate of stream file (in bps)
+ double average_bitrate; ///< average bitrate of stream (in bits/sec)
+ mpc_uint32_t frames; ///< number of frames in stream
+ mpc_int64_t pcm_samples;
+ mpc_uint32_t max_band; ///< maximum band-index used in stream (0...31)
+ mpc_uint32_t is; ///< intensity stereo (0: off, 1: on)
+ mpc_uint32_t ms; ///< mid/side stereo (0: off, 1: on)
+ mpc_uint32_t block_size; ///< only needed for SV4...SV6 -> not supported
+ mpc_uint32_t profile; ///< quality profile of stream
+ const char* profile_name; ///< name of profile used by stream
+ //@}
+
+ /// @name replaygain related fields
+ //@{
+ mpc_int16_t gain_title; ///< replaygain title value
+ mpc_int16_t gain_album; ///< replaygain album value
+ mpc_uint16_t peak_album; ///< peak album loudness level
+ mpc_uint16_t peak_title; ///< peak title loudness level
+ //@}
+
+ /// @name true gapless support data
+ //@{
+ mpc_uint32_t is_true_gapless; ///< true gapless? (0: no, 1: yes)
+ mpc_uint32_t last_frame_samples; ///< number of valid samples within last frame
+
+ mpc_uint32_t encoder_version; ///< version of encoder used
+ char encoder[256]; ///< encoder name
+
+ mpc_streaminfo_off_t tag_offset; ///< offset to file tags
+ mpc_streaminfo_off_t total_file_length; ///< total length of underlying file
+ //@}
+
+ /// @name fast seeking support
+ //@{
+ mpc_uint32_t fast_seek; ///< support fast seeking ? (0: no, 1: yes)
+ //@}
+} mpc_streaminfo;
+
+#endif // _mpcdec_streaminfo_h_
diff --git a/contrib/libmpcdec/requant.c b/contrib/libmpcdec/requant.c
new file mode 100644
index 000000000..2e4c98b62
--- /dev/null
+++ b/contrib/libmpcdec/requant.c
@@ -0,0 +1,120 @@
+/*
+ Copyright (c) 2005, The Musepack Development Team
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of the The Musepack Development Team nor the
+ names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/// \file requant.c
+/// Requantization function implementations.
+/// \todo document me
+
+#include <mpcdec/mpcdec.h>
+#include <mpcdec/internal.h>
+
+/* C O N S T A N T S */
+// bits per sample for chosen quantizer
+const mpc_uint32_t Res_bit [18] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
+};
+
+// coefficients for requantization
+// 65536/step bzw. 65536/(2*D+1)
+
+#define _(X) MAKE_MPC_SAMPLE_EX(X,14)
+
+const MPC_SAMPLE_FORMAT __Cc [1 + 18] = {
+ _(111.285962475327f), // 32768/2/255*sqrt(3)
+ _(65536.000000000000f), _(21845.333333333332f), _(13107.200000000001f), _(9362.285714285713f),
+ _(7281.777777777777f), _(4369.066666666666f), _(2114.064516129032f), _(1040.253968253968f),
+ _(516.031496062992f), _(257.003921568627f), _(128.250489236790f), _(64.062561094819f),
+ _(32.015632633121f), _(16.003907203907f), _(8.000976681723f), _(4.000244155527f),
+ _(2.000061037018f), _(1.000015259021f)
+};
+
+#undef _
+
+// offset for requantization
+// 2*D+1 = steps of quantizer
+const mpc_int32_t __Dc [1 + 18] = {
+ 2,
+ 0, 1, 2, 3, 4, 7, 15, 31, 63,
+ 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767
+};
+
+#ifdef MPC_FIXED_POINT
+static mpc_uint32_t find_shift(double fval)
+{
+ mpc_int64_t val = (mpc_int64_t)fval;
+ mpc_uint32_t ptr = 0;
+ if (val<0) val = -val;
+ while(val) {val>>=1;ptr++;}
+
+ return ptr > 31 ? 0 : 31 - ptr;
+}
+#endif
+
+/* F U N C T I O N S */
+
+#define SET_SCF(N,X) d->SCF[N] = MAKE_MPC_SAMPLE_EX(X,d->SCF_shift[N] = (unsigned char)find_shift(X));
+
+void
+mpc_decoder_scale_output(mpc_decoder *d, double factor)
+{
+ mpc_int32_t n;
+ double f1;
+ double f2;
+#ifndef MPC_FIXED_POINT
+ factor *= 1.0 / (double)(1<<(MPC_FIXED_POINT_SHIFT-1));
+#else
+ factor *= 1.0 / (double)(1<<(16 - MPC_FIXED_POINT_SHIFT));
+#endif
+ f1 = f2 = factor;
+
+ // handles +1.58...-98.41 dB, where's scf[n] / scf[n-1] = 1.20050805774840750476
+
+ SET_SCF(1,factor);
+
+ f1 *= 0.83298066476582673961;
+ f2 *= 1/0.83298066476582673961;
+
+ for ( n = 1; n <= 128; n++ ) {
+ SET_SCF((unsigned char)(1+n),f1);
+ SET_SCF((unsigned char)(1-n),f2);
+ f1 *= 0.83298066476582673961;
+ f2 *= 1/0.83298066476582673961;
+ }
+}
+
+void
+mpc_decoder_initialisiere_quantisierungstabellen(mpc_decoder *d, double scale_factor)
+{
+ mpc_decoder_scale_output(d, scale_factor);
+}
diff --git a/contrib/libmpcdec/streaminfo.c b/contrib/libmpcdec/streaminfo.c
new file mode 100644
index 000000000..060da08d0
--- /dev/null
+++ b/contrib/libmpcdec/streaminfo.c
@@ -0,0 +1,281 @@
+/*
+ Copyright (c) 2005, The Musepack Development Team
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of the The Musepack Development Team nor the
+ names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/// \file streaminfo.c
+/// Implementation of streaminfo reading functions.
+
+#include <mpcdec/mpcdec.h>
+#include <mpcdec/internal.h>
+
+static const char *
+Stringify(mpc_uint32_t profile) // profile is 0...15, where 7...13 is used
+{
+ static const char na[] = "n.a.";
+ static const char *Names[] = {
+ na, "'Unstable/Experimental'", na, na,
+ na, "'quality 0'", "'quality 1'", "'Telephone'",
+ "'Thumb'", "'Radio'", "'Standard'", "'Xtreme'",
+ "'Insane'", "'BrainDead'", "'quality 9'", "'quality 10'"
+ };
+
+ return profile >= sizeof(Names) / sizeof(*Names) ? na : Names[profile];
+}
+
+void
+mpc_streaminfo_init(mpc_streaminfo * si)
+{
+ memset(si, 0, sizeof(mpc_streaminfo));
+}
+
+/// Reads streaminfo from SV7 header.
+static mpc_int32_t
+streaminfo_read_header_sv7(mpc_streaminfo * si, mpc_uint32_t HeaderData[8])
+{
+ const mpc_int32_t samplefreqs[4] = { 44100, 48000, 37800, 32000 };
+
+ //mpc_uint32_t HeaderData [8];
+ mpc_uint16_t Estimatedpeak_title = 0;
+
+ if (si->stream_version > 0x71) {
+ // Update (si->stream_version);
+ return 0;
+ }
+
+ /*
+ if ( !fp->seek ( si->header_position ) ) // seek to header start
+ return ERROR_CODE_FILE;
+ if ( fp->read ( HeaderData, sizeof HeaderData) != sizeof HeaderData )
+ return ERROR_CODE_FILE;
+ */
+
+ si->bitrate = 0;
+ si->frames = HeaderData[1];
+ si->is = 0;
+ si->ms = (HeaderData[2] >> 30) & 0x0001;
+ si->max_band = (HeaderData[2] >> 24) & 0x003F;
+ si->block_size = 1;
+ si->profile = (HeaderData[2] << 8) >> 28;
+ si->profile_name = Stringify(si->profile);
+ si->sample_freq = samplefreqs[(HeaderData[2] >> 16) & 0x0003];
+ Estimatedpeak_title = (mpc_uint16_t) (HeaderData[2] & 0xFFFF); // read the ReplayGain data
+ si->gain_title = (mpc_uint16_t) ((HeaderData[3] >> 16) & 0xFFFF);
+ si->peak_title = (mpc_uint16_t) (HeaderData[3] & 0xFFFF);
+ si->gain_album = (mpc_uint16_t) ((HeaderData[4] >> 16) & 0xFFFF);
+ si->peak_album = (mpc_uint16_t) (HeaderData[4] & 0xFFFF);
+ si->is_true_gapless = (HeaderData[5] >> 31) & 0x0001; // true gapless: used?
+ si->last_frame_samples = (HeaderData[5] >> 20) & 0x07FF; // true gapless: valid samples for last frame
+ si->fast_seek = (HeaderData[5] >> 19) & 0x0001; // fast seeking
+ si->encoder_version = (HeaderData[6] >> 24) & 0x00FF;
+
+ if (si->encoder_version == 0) {
+ sprintf(si->encoder, "Buschmann 1.7.0...9, Klemm 0.90...1.05");
+ }
+ else {
+ switch (si->encoder_version % 10) {
+ case 0:
+ sprintf(si->encoder, "Release %u.%u", si->encoder_version / 100,
+ si->encoder_version / 10 % 10);
+ break;
+ case 2:
+ case 4:
+ case 6:
+ case 8:
+ sprintf(si->encoder, "Beta %u.%02u", si->encoder_version / 100,
+ si->encoder_version % 100);
+ break;
+ default:
+ sprintf(si->encoder, "--Alpha-- %u.%02u",
+ si->encoder_version / 100, si->encoder_version % 100);
+ break;
+ }
+ }
+
+ // if ( si->peak_title == 0 ) // there is no correct peak_title contained within header
+ // si->peak_title = (mpc_uint16_t)(Estimatedpeak_title * 1.18);
+ // if ( si->peak_album == 0 )
+ // si->peak_album = si->peak_title; // no correct peak_album, use peak_title
+
+ //si->sample_freq = 44100; // AB: used by all files up to SV7
+ si->channels = 2;
+
+ return ERROR_CODE_OK;
+}
+
+// read information from SV4-SV6 header
+#ifdef MPC_SUPPORT_SV456
+static mpc_int32_t
+streaminfo_read_header_sv6(mpc_streaminfo * si, mpc_uint32_t HeaderData[8])
+{
+ //mpc_uint32_t HeaderData [8];
+
+ /*
+ if ( !fp->seek ( si->header_position ) ) // seek to header start
+ return ERROR_CODE_FILE;
+ if ( fp->read ( HeaderData, sizeof HeaderData ) != sizeof HeaderData )
+ return ERROR_CODE_FILE;
+ */
+
+ si->bitrate = (HeaderData[0] >> 23) & 0x01FF; // read the file-header (SV6 and below)
+ si->is = (HeaderData[0] >> 22) & 0x0001;
+ si->ms = (HeaderData[0] >> 21) & 0x0001;
+ si->stream_version = (HeaderData[0] >> 11) & 0x03FF;
+ si->max_band = (HeaderData[0] >> 6) & 0x001F;
+ si->block_size = (HeaderData[0]) & 0x003F;
+ si->profile = 0;
+ si->profile_name = Stringify((mpc_uint32_t) (-1));
+ if (si->stream_version >= 5)
+ si->frames = HeaderData[1]; // 32 bit
+ else
+ si->frames = (HeaderData[1] >> 16); // 16 bit
+
+ si->gain_title = 0; // not supported
+ si->peak_title = 0;
+ si->gain_album = 0;
+ si->peak_album = 0;
+
+ si->last_frame_samples = 0;
+ si->is_true_gapless = 0;
+
+ si->encoder_version = 0;
+ si->encoder[0] = '\0';
+
+ if (si->stream_version == 7)
+ return ERROR_CODE_SV7BETA; // are there any unsupported parameters used?
+ if (si->bitrate != 0)
+ return ERROR_CODE_CBR;
+ if (si->is != 0)
+ return ERROR_CODE_IS;
+ if (si->block_size != 1)
+ return ERROR_CODE_BLOCKSIZE;
+
+ if (si->stream_version < 6) // Bugfix: last frame was invalid for up to SV5
+ si->frames -= 1;
+
+ si->sample_freq = 44100; // AB: used by all files up to SV7
+ si->channels = 2;
+
+ if (si->stream_version < 4 || si->stream_version > 7)
+ return ERROR_CODE_INVALIDSV;
+
+ return ERROR_CODE_OK;
+}
+#endif
+// reads file header and tags
+mpc_int32_t
+mpc_streaminfo_read(mpc_streaminfo * si, mpc_reader * r)
+{
+ mpc_uint32_t HeaderData[8];
+ mpc_int32_t Error = 0;
+
+ // get header position
+ if ((si->header_position = JumpID3v2(r)) < 0) {
+ return ERROR_CODE_FILE;
+ }
+ // seek to first byte of mpc data
+ if (!r->seek(r->data, si->header_position)) {
+ return ERROR_CODE_FILE;
+ }
+ if (r->read(r->data, HeaderData, 8 * 4) != 8 * 4) {
+ return ERROR_CODE_FILE;
+ }
+ if (!r->seek(r->data, si->header_position + 6 * 4)) {
+ return ERROR_CODE_FILE;
+ }
+
+ si->total_file_length = r->get_size(r->data);
+ si->tag_offset = si->total_file_length;
+
+ if (memcmp(HeaderData, "MP+", 3)) return ERROR_CODE_INVALIDSV;
+#ifndef MPC_LITTLE_ENDIAN
+ {
+ mpc_uint32_t ptr;
+ for (ptr = 0; ptr < 8; ptr++) {
+ HeaderData[ptr] = mpc_swap32(HeaderData[ptr]);
+ }
+ }
+#endif
+
+ si->stream_version = HeaderData[0] >> 24;
+
+ // stream version 8
+ if ((si->stream_version & 15) >= 8) {
+ return ERROR_CODE_INVALIDSV;
+ }
+ // stream version 7
+ else if ((si->stream_version & 15) == 7) {
+ Error = streaminfo_read_header_sv7(si, HeaderData);
+ if (Error != ERROR_CODE_OK) return Error;
+ }
+#ifdef MPC_SUPPORT_SV456
+ else {
+ // stream version 4-6
+ Error = streaminfo_read_header_sv6(si, HeaderData);
+ if (Error != ERROR_CODE_OK) return Error;
+ }
+#endif
+
+ // estimation, exact value needs too much time
+ si->pcm_samples = 1152 * si->frames - 576;
+
+ if (si->pcm_samples > 0) {
+ si->average_bitrate =
+ (si->tag_offset -
+ si->header_position) * 8.0 * si->sample_freq / si->pcm_samples;
+ }
+ else {
+ si->average_bitrate = 0;
+ }
+
+ return ERROR_CODE_OK;
+}
+
+double
+mpc_streaminfo_get_length(mpc_streaminfo * si)
+{
+ return (double)mpc_streaminfo_get_length_samples(si) /
+ (double)si->sample_freq;
+}
+
+mpc_int64_t
+mpc_streaminfo_get_length_samples(mpc_streaminfo * si)
+{
+ mpc_int64_t samples = (mpc_int64_t) si->frames * MPC_FRAME_LENGTH;
+ if (si->is_true_gapless) {
+ samples -= (MPC_FRAME_LENGTH - si->last_frame_samples);
+ }
+ else {
+ samples -= MPC_DECODER_SYNTH_DELAY;
+ }
+ return samples;
+}
diff --git a/contrib/libmpcdec/synth_filter.c b/contrib/libmpcdec/synth_filter.c
new file mode 100644
index 000000000..08308005d
--- /dev/null
+++ b/contrib/libmpcdec/synth_filter.c
@@ -0,0 +1,440 @@
+/*
+ Copyright (c) 2005, The Musepack Development Team
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of the The Musepack Development Team nor the
+ names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/// \file synth_filter.c
+/// Synthesis functions.
+/// \todo document me
+
+#include <mpcdec/mpcdec.h>
+#include <mpcdec/internal.h>
+
+/* C O N S T A N T S */
+#undef _
+
+#define MPC_FIXED_POINT_SYNTH_FIX 2
+
+#ifdef MPC_FIXED_POINT
+#define _(value) MPC_MAKE_FRACT_CONST((double)value/(double)(0x40000))
+#else
+#define _(value) MAKE_MPC_SAMPLE((double)value/(double)(0x10000))
+#endif
+
+
+static const MPC_SAMPLE_FORMAT Di_opt [32] [16] = {
+ { _( 0), _( -29), _( 213), _( -459), _( 2037), _(-5153), _( 6574), _(-37489), _(75038), _(37489), _(6574), _( 5153), _(2037), _( 459), _(213), _(29) },
+ { _( -1), _( -31), _( 218), _( -519), _( 2000), _(-5517), _( 5959), _(-39336), _(74992), _(35640), _(7134), _( 4788), _(2063), _( 401), _(208), _(26) },
+ { _( -1), _( -35), _( 222), _( -581), _( 1952), _(-5879), _( 5288), _(-41176), _(74856), _(33791), _(7640), _( 4425), _(2080), _( 347), _(202), _(24) },
+ { _( -1), _( -38), _( 225), _( -645), _( 1893), _(-6237), _( 4561), _(-43006), _(74630), _(31947), _(8092), _( 4063), _(2087), _( 294), _(196), _(21) },
+ { _( -1), _( -41), _( 227), _( -711), _( 1822), _(-6589), _( 3776), _(-44821), _(74313), _(30112), _(8492), _( 3705), _(2085), _( 244), _(190), _(19) },
+ { _( -1), _( -45), _( 228), _( -779), _( 1739), _(-6935), _( 2935), _(-46617), _(73908), _(28289), _(8840), _( 3351), _(2075), _( 197), _(183), _(17) },
+ { _( -1), _( -49), _( 228), _( -848), _( 1644), _(-7271), _( 2037), _(-48390), _(73415), _(26482), _(9139), _( 3004), _(2057), _( 153), _(176), _(16) },
+ { _( -2), _( -53), _( 227), _( -919), _( 1535), _(-7597), _( 1082), _(-50137), _(72835), _(24694), _(9389), _( 2663), _(2032), _( 111), _(169), _(14) },
+ { _( -2), _( -58), _( 224), _( -991), _( 1414), _(-7910), _( 70), _(-51853), _(72169), _(22929), _(9592), _( 2330), _(2001), _( 72), _(161), _(13) },
+ { _( -2), _( -63), _( 221), _(-1064), _( 1280), _(-8209), _( -998), _(-53534), _(71420), _(21189), _(9750), _( 2006), _(1962), _( 36), _(154), _(11) },
+ { _( -2), _( -68), _( 215), _(-1137), _( 1131), _(-8491), _( -2122), _(-55178), _(70590), _(19478), _(9863), _( 1692), _(1919), _( 2), _(147), _(10) },
+ { _( -3), _( -73), _( 208), _(-1210), _( 970), _(-8755), _( -3300), _(-56778), _(69679), _(17799), _(9935), _( 1388), _(1870), _( -29), _(139), _( 9) },
+ { _( -3), _( -79), _( 200), _(-1283), _( 794), _(-8998), _( -4533), _(-58333), _(68692), _(16155), _(9966), _( 1095), _(1817), _( -57), _(132), _( 8) },
+ { _( -4), _( -85), _( 189), _(-1356), _( 605), _(-9219), _( -5818), _(-59838), _(67629), _(14548), _(9959), _( 814), _(1759), _( -83), _(125), _( 7) },
+ { _( -4), _( -91), _( 177), _(-1428), _( 402), _(-9416), _( -7154), _(-61289), _(66494), _(12980), _(9916), _( 545), _(1698), _(-106), _(117), _( 7) },
+ { _( -5), _( -97), _( 163), _(-1498), _( 185), _(-9585), _( -8540), _(-62684), _(65290), _(11455), _(9838), _( 288), _(1634), _(-127), _(111), _( 6) },
+ { _( -5), _(-104), _( 146), _(-1567), _( -45), _(-9727), _( -9975), _(-64019), _(64019), _( 9975), _(9727), _( 45), _(1567), _(-146), _(104), _( 5) },
+ { _( -6), _(-111), _( 127), _(-1634), _( -288), _(-9838), _(-11455), _(-65290), _(62684), _( 8540), _(9585), _( -185), _(1498), _(-163), _( 97), _( 5) },
+ { _( -7), _(-117), _( 106), _(-1698), _( -545), _(-9916), _(-12980), _(-66494), _(61289), _( 7154), _(9416), _( -402), _(1428), _(-177), _( 91), _( 4) },
+ { _( -7), _(-125), _( 83), _(-1759), _( -814), _(-9959), _(-14548), _(-67629), _(59838), _( 5818), _(9219), _( -605), _(1356), _(-189), _( 85), _( 4) },
+ { _( -8), _(-132), _( 57), _(-1817), _(-1095), _(-9966), _(-16155), _(-68692), _(58333), _( 4533), _(8998), _( -794), _(1283), _(-200), _( 79), _( 3) },
+ { _( -9), _(-139), _( 29), _(-1870), _(-1388), _(-9935), _(-17799), _(-69679), _(56778), _( 3300), _(8755), _( -970), _(1210), _(-208), _( 73), _( 3) },
+ { _(-10), _(-147), _( -2), _(-1919), _(-1692), _(-9863), _(-19478), _(-70590), _(55178), _( 2122), _(8491), _(-1131), _(1137), _(-215), _( 68), _( 2) },
+ { _(-11), _(-154), _( -36), _(-1962), _(-2006), _(-9750), _(-21189), _(-71420), _(53534), _( 998), _(8209), _(-1280), _(1064), _(-221), _( 63), _( 2) },
+ { _(-13), _(-161), _( -72), _(-2001), _(-2330), _(-9592), _(-22929), _(-72169), _(51853), _( -70), _(7910), _(-1414), _( 991), _(-224), _( 58), _( 2) },
+ { _(-14), _(-169), _(-111), _(-2032), _(-2663), _(-9389), _(-24694), _(-72835), _(50137), _(-1082), _(7597), _(-1535), _( 919), _(-227), _( 53), _( 2) },
+ { _(-16), _(-176), _(-153), _(-2057), _(-3004), _(-9139), _(-26482), _(-73415), _(48390), _(-2037), _(7271), _(-1644), _( 848), _(-228), _( 49), _( 1) },
+ { _(-17), _(-183), _(-197), _(-2075), _(-3351), _(-8840), _(-28289), _(-73908), _(46617), _(-2935), _(6935), _(-1739), _( 779), _(-228), _( 45), _( 1) },
+ { _(-19), _(-190), _(-244), _(-2085), _(-3705), _(-8492), _(-30112), _(-74313), _(44821), _(-3776), _(6589), _(-1822), _( 711), _(-227), _( 41), _( 1) },
+ { _(-21), _(-196), _(-294), _(-2087), _(-4063), _(-8092), _(-31947), _(-74630), _(43006), _(-4561), _(6237), _(-1893), _( 645), _(-225), _( 38), _( 1) },
+ { _(-24), _(-202), _(-347), _(-2080), _(-4425), _(-7640), _(-33791), _(-74856), _(41176), _(-5288), _(5879), _(-1952), _( 581), _(-222), _( 35), _( 1) },
+ { _(-26), _(-208), _(-401), _(-2063), _(-4788), _(-7134), _(-35640), _(-74992), _(39336), _(-5959), _(5517), _(-2000), _( 519), _(-218), _( 31), _( 1) }
+};
+
+#undef _
+
+static void Calculate_New_V ( const MPC_SAMPLE_FORMAT * Sample, MPC_SAMPLE_FORMAT * V )
+{
+ // Calculating new V-buffer values for left channel
+ // calculate new V-values (ISO-11172-3, p. 39)
+ // based upon fast-MDCT algorithm by Byeong Gi Lee
+ /*static*/ MPC_SAMPLE_FORMAT A00, A01, A02, A03, A04, A05, A06, A07, A08, A09, A10, A11, A12, A13, A14, A15;
+ /*static*/ MPC_SAMPLE_FORMAT B00, B01, B02, B03, B04, B05, B06, B07, B08, B09, B10, B11, B12, B13, B14, B15;
+ MPC_SAMPLE_FORMAT tmp;
+
+ A00 = Sample[ 0] + Sample[31];
+ A01 = Sample[ 1] + Sample[30];
+ A02 = Sample[ 2] + Sample[29];
+ A03 = Sample[ 3] + Sample[28];
+ A04 = Sample[ 4] + Sample[27];
+ A05 = Sample[ 5] + Sample[26];
+ A06 = Sample[ 6] + Sample[25];
+ A07 = Sample[ 7] + Sample[24];
+ A08 = Sample[ 8] + Sample[23];
+ A09 = Sample[ 9] + Sample[22];
+ A10 = Sample[10] + Sample[21];
+ A11 = Sample[11] + Sample[20];
+ A12 = Sample[12] + Sample[19];
+ A13 = Sample[13] + Sample[18];
+ A14 = Sample[14] + Sample[17];
+ A15 = Sample[15] + Sample[16];
+
+ B00 = A00 + A15;
+ B01 = A01 + A14;
+ B02 = A02 + A13;
+ B03 = A03 + A12;
+ B04 = A04 + A11;
+ B05 = A05 + A10;
+ B06 = A06 + A09;
+ B07 = A07 + A08;;
+ B08 = MPC_SCALE_CONST((A00 - A15) , 0.5024192929f , 31);
+ B09 = MPC_SCALE_CONST((A01 - A14) , 0.5224986076f , 31);
+ B10 = MPC_SCALE_CONST((A02 - A13) , 0.5669440627f , 31);
+ B11 = MPC_SCALE_CONST((A03 - A12) , 0.6468217969f , 31);
+ B12 = MPC_SCALE_CONST((A04 - A11) , 0.7881546021f , 31);
+ B13 = MPC_SCALE_CONST((A05 - A10) , 1.0606776476f , 30);
+ B14 = MPC_SCALE_CONST((A06 - A09) , 1.7224471569f , 30);
+ B15 = MPC_SCALE_CONST((A07 - A08) , 5.1011486053f , 28);
+
+ A00 = B00 + B07;
+ A01 = B01 + B06;
+ A02 = B02 + B05;
+ A03 = B03 + B04;
+ A04 = MPC_SCALE_CONST((B00 - B07) , 0.5097956061f , 31);
+ A05 = MPC_SCALE_CONST((B01 - B06) , 0.6013448834f , 31);
+ A06 = MPC_SCALE_CONST((B02 - B05) , 0.8999761939f , 31);
+ A07 = MPC_SCALE_CONST((B03 - B04) , 2.5629155636f , 29);
+ A08 = B08 + B15;
+ A09 = B09 + B14;
+ A10 = B10 + B13;
+ A11 = B11 + B12;
+ A12 = MPC_SCALE_CONST((B08 - B15) , 0.5097956061f , 31);
+ A13 = MPC_SCALE_CONST((B09 - B14) , 0.6013448834f , 31);
+ A14 = MPC_SCALE_CONST((B10 - B13) , 0.8999761939f , 31);
+ A15 = MPC_SCALE_CONST((B11 - B12) , 2.5629155636f , 29);
+
+ B00 = A00 + A03;
+ B01 = A01 + A02;
+ B02 = MPC_MULTIPLY_FRACT_CONST_FIX((A00 - A03) , 0.5411961079f , 1);
+ B03 = MPC_MULTIPLY_FRACT_CONST_FIX((A01 - A02) , 1.3065630198f , 2);
+ B04 = A04 + A07;
+ B05 = A05 + A06;
+ B06 = MPC_MULTIPLY_FRACT_CONST_FIX((A04 - A07) , 0.5411961079f , 1);
+ B07 = MPC_MULTIPLY_FRACT_CONST_FIX((A05 - A06) , 1.3065630198f , 2);
+ B08 = A08 + A11;
+ B09 = A09 + A10;
+ B10 = MPC_MULTIPLY_FRACT_CONST_FIX((A08 - A11) , 0.5411961079f , 1);
+ B11 = MPC_MULTIPLY_FRACT_CONST_FIX((A09 - A10) , 1.3065630198f , 2);
+ B12 = A12 + A15;
+ B13 = A13 + A14;
+ B14 = MPC_MULTIPLY_FRACT_CONST_FIX((A12 - A15) , 0.5411961079f , 1);
+ B15 = MPC_MULTIPLY_FRACT_CONST_FIX((A13 - A14) , 1.3065630198f , 2);
+
+ A00 = B00 + B01;
+ A01 = MPC_MULTIPLY_FRACT_CONST_FIX((B00 - B01) , 0.7071067691f , 1);
+ A02 = B02 + B03;
+ A03 = MPC_MULTIPLY_FRACT_CONST_FIX((B02 - B03) , 0.7071067691f , 1);
+ A04 = B04 + B05;
+ A05 = MPC_MULTIPLY_FRACT_CONST_FIX((B04 - B05) , 0.7071067691f , 1);
+ A06 = B06 + B07;
+ A07 = MPC_MULTIPLY_FRACT_CONST_FIX((B06 - B07) , 0.7071067691f , 1);
+ A08 = B08 + B09;
+ A09 = MPC_MULTIPLY_FRACT_CONST_FIX((B08 - B09) , 0.7071067691f , 1);
+ A10 = B10 + B11;
+ A11 = MPC_MULTIPLY_FRACT_CONST_FIX((B10 - B11) , 0.7071067691f , 1);
+ A12 = B12 + B13;
+ A13 = MPC_MULTIPLY_FRACT_CONST_FIX((B12 - B13) , 0.7071067691f , 1);
+ A14 = B14 + B15;
+ A15 = MPC_MULTIPLY_FRACT_CONST_FIX((B14 - B15) , 0.7071067691f , 1);
+
+ V[48] = -A00;
+ V[ 0] = A01;
+ V[40] = -A02 - (V[ 8] = A03);
+ V[36] = -((V[ 4] = A05 + (V[12] = A07)) + A06);
+ V[44] = - A04 - A06 - A07;
+ V[ 6] = (V[10] = A11 + (V[14] = A15)) + A13;
+ V[38] = (V[34] = -(V[ 2] = A09 + A13 + A15) - A14) + A09 - A10 - A11;
+ V[46] = (tmp = -(A12 + A14 + A15)) - A08;
+ V[42] = tmp - A10 - A11;
+
+ A00 = MPC_MULTIPLY_FRACT_CONST_SHR((Sample[ 0] - Sample[31]) , 0.5006030202f , MPC_FIXED_POINT_SYNTH_FIX);
+ A01 = MPC_MULTIPLY_FRACT_CONST_SHR((Sample[ 1] - Sample[30]) , 0.5054709315f , MPC_FIXED_POINT_SYNTH_FIX);
+ A02 = MPC_MULTIPLY_FRACT_CONST_SHR((Sample[ 2] - Sample[29]) , 0.5154473186f , MPC_FIXED_POINT_SYNTH_FIX);
+ A03 = MPC_MULTIPLY_FRACT_CONST_SHR((Sample[ 3] - Sample[28]) , 0.5310425758f , MPC_FIXED_POINT_SYNTH_FIX);
+ A04 = MPC_MULTIPLY_FRACT_CONST_SHR((Sample[ 4] - Sample[27]) , 0.5531039238f , MPC_FIXED_POINT_SYNTH_FIX);
+ A05 = MPC_MULTIPLY_FRACT_CONST_SHR((Sample[ 5] - Sample[26]) , 0.5829349756f , MPC_FIXED_POINT_SYNTH_FIX);
+ A06 = MPC_MULTIPLY_FRACT_CONST_SHR((Sample[ 6] - Sample[25]) , 0.6225041151f , MPC_FIXED_POINT_SYNTH_FIX);
+ A07 = MPC_MULTIPLY_FRACT_CONST_SHR((Sample[ 7] - Sample[24]) , 0.6748083234f , MPC_FIXED_POINT_SYNTH_FIX);
+ A08 = MPC_MULTIPLY_FRACT_CONST_SHR((Sample[ 8] - Sample[23]) , 0.7445362806f , MPC_FIXED_POINT_SYNTH_FIX);
+ A09 = MPC_MULTIPLY_FRACT_CONST_SHR((Sample[ 9] - Sample[22]) , 0.8393496275f , MPC_FIXED_POINT_SYNTH_FIX);
+ A10 = MPC_MULTIPLY_FRACT_CONST_SHR((Sample[10] - Sample[21]) , 0.9725682139f , MPC_FIXED_POINT_SYNTH_FIX);
+#if MPC_FIXED_POINT_SYNTH_FIX>=2
+ A11 = MPC_MULTIPLY_FRACT_CONST_SHR((Sample[11] - Sample[20]) , 1.1694399118f , MPC_FIXED_POINT_SYNTH_FIX);
+ A12 = MPC_MULTIPLY_FRACT_CONST_SHR((Sample[12] - Sample[19]) , 1.4841645956f , MPC_FIXED_POINT_SYNTH_FIX);
+#else
+ A11 = MPC_SCALE_CONST_SHR ((Sample[11] - Sample[20]) , 1.1694399118f , 30, MPC_FIXED_POINT_SYNTH_FIX);
+ A12 = MPC_SCALE_CONST_SHR ((Sample[12] - Sample[19]) , 1.4841645956f , 30, MPC_FIXED_POINT_SYNTH_FIX);
+#endif
+ A13 = MPC_SCALE_CONST_SHR ((Sample[13] - Sample[18]) , 2.0577809811f , 29, MPC_FIXED_POINT_SYNTH_FIX);
+ A14 = MPC_SCALE_CONST_SHR ((Sample[14] - Sample[17]) , 3.4076085091f , 29, MPC_FIXED_POINT_SYNTH_FIX);
+ A15 = MPC_SCALE_CONST_SHR ((Sample[15] - Sample[16]) , 10.1900081635f, 27 ,MPC_FIXED_POINT_SYNTH_FIX);
+
+ B00 = A00 + A15;
+ B01 = A01 + A14;
+ B02 = A02 + A13;
+ B03 = A03 + A12;
+ B04 = A04 + A11;
+ B05 = A05 + A10;
+ B06 = A06 + A09;
+ B07 = A07 + A08;
+ B08 = MPC_SCALE_CONST((A00 - A15) , 0.5024192929f , 31);
+ B09 = MPC_SCALE_CONST((A01 - A14) , 0.5224986076f , 31);
+ B10 = MPC_SCALE_CONST((A02 - A13) , 0.5669440627f , 31);
+ B11 = MPC_SCALE_CONST((A03 - A12) , 0.6468217969f , 31);
+ B12 = MPC_SCALE_CONST((A04 - A11) , 0.7881546021f , 31);
+ B13 = MPC_SCALE_CONST((A05 - A10) , 1.0606776476f , 30);
+ B14 = MPC_SCALE_CONST((A06 - A09) , 1.7224471569f , 30);
+ B15 = MPC_SCALE_CONST((A07 - A08) , 5.1011486053f , 28);
+
+ A00 = B00 + B07;
+ A01 = B01 + B06;
+ A02 = B02 + B05;
+ A03 = B03 + B04;
+ A04 = MPC_SCALE_CONST((B00 - B07) , 0.5097956061f , 31);
+ A05 = MPC_SCALE_CONST((B01 - B06) , 0.6013448834f , 31);
+ A06 = MPC_SCALE_CONST((B02 - B05) , 0.8999761939f , 31);
+ A07 = MPC_SCALE_CONST((B03 - B04) , 2.5629155636f , 29);
+ A08 = B08 + B15;
+ A09 = B09 + B14;
+ A10 = B10 + B13;
+ A11 = B11 + B12;
+ A12 = MPC_SCALE_CONST((B08 - B15) , 0.5097956061f , 31);
+ A13 = MPC_SCALE_CONST((B09 - B14) , 0.6013448834f , 31);
+ A14 = MPC_SCALE_CONST((B10 - B13) , 0.8999761939f , 31);
+ A15 = MPC_SCALE_CONST((B11 - B12) , 2.5629155636f , 29);
+
+ B00 = A00 + A03;
+ B01 = A01 + A02;
+ B02 = MPC_SCALE_CONST((A00 - A03) , 0.5411961079f , 31);
+ B03 = MPC_SCALE_CONST((A01 - A02) , 1.3065630198f , 30);
+ B04 = A04 + A07;
+ B05 = A05 + A06;
+ B06 = MPC_SCALE_CONST((A04 - A07) , 0.5411961079f , 31);
+ B07 = MPC_SCALE_CONST((A05 - A06) , 1.3065630198f , 30);
+ B08 = A08 + A11;
+ B09 = A09 + A10;
+ B10 = MPC_SCALE_CONST((A08 - A11) , 0.5411961079f , 31);
+ B11 = MPC_SCALE_CONST((A09 - A10) , 1.3065630198f , 30);
+ B12 = A12 + A15;
+ B13 = A13 + A14;
+ B14 = MPC_SCALE_CONST((A12 - A15) , 0.5411961079f , 31);
+ B15 = MPC_SCALE_CONST((A13 - A14) , 1.3065630198f , 30);
+
+ A00 = MPC_SHL(B00 + B01, MPC_FIXED_POINT_SYNTH_FIX);
+ A01 = MPC_SCALE_CONST_SHL((B00 - B01) , 0.7071067691f , 31, MPC_FIXED_POINT_SYNTH_FIX);
+ A02 = MPC_SHL(B02 + B03, MPC_FIXED_POINT_SYNTH_FIX);
+ A03 = MPC_SCALE_CONST_SHL((B02 - B03) , 0.7071067691f , 31, MPC_FIXED_POINT_SYNTH_FIX);
+ A04 = MPC_SHL(B04 + B05, MPC_FIXED_POINT_SYNTH_FIX);
+ A05 = MPC_SCALE_CONST_SHL((B04 - B05) , 0.7071067691f , 31, MPC_FIXED_POINT_SYNTH_FIX);
+ A06 = MPC_SHL(B06 + B07, MPC_FIXED_POINT_SYNTH_FIX);
+ A07 = MPC_SCALE_CONST_SHL((B06 - B07) , 0.7071067691f , 31, MPC_FIXED_POINT_SYNTH_FIX);
+ A08 = MPC_SHL(B08 + B09, MPC_FIXED_POINT_SYNTH_FIX);
+ A09 = MPC_SCALE_CONST_SHL((B08 - B09) , 0.7071067691f , 31, MPC_FIXED_POINT_SYNTH_FIX);
+ A10 = MPC_SHL(B10 + B11, MPC_FIXED_POINT_SYNTH_FIX);
+ A11 = MPC_SCALE_CONST_SHL((B10 - B11) , 0.7071067691f , 31, MPC_FIXED_POINT_SYNTH_FIX);
+ A12 = MPC_SHL(B12 + B13, MPC_FIXED_POINT_SYNTH_FIX);
+ A13 = MPC_SCALE_CONST_SHL((B12 - B13) , 0.7071067691f , 31, MPC_FIXED_POINT_SYNTH_FIX);
+ A14 = MPC_SHL(B14 + B15, MPC_FIXED_POINT_SYNTH_FIX);
+ A15 = MPC_SCALE_CONST_SHL((B14 - B15) , 0.7071067691f , 31, MPC_FIXED_POINT_SYNTH_FIX);
+
+ // mehrfach verwendete Ausdrücke: A04+A06+A07, A09+A13+A15
+ V[ 5] = (V[11] = (V[13] = A07 + (V[15] = A15)) + A11) + A05 + A13;
+ V[ 7] = (V[ 9] = A03 + A11 + A15) + A13;
+ V[33] = -(V[ 1] = A01 + A09 + A13 + A15) - A14;
+ V[35] = -(V[ 3] = A05 + A07 + A09 + A13 + A15) - A06 - A14;
+ V[37] = (tmp = -(A10 + A11 + A13 + A14 + A15)) - A05 - A06 - A07;
+ V[39] = tmp - A02 - A03; // abhängig vom Befehl drüber
+ V[41] = (tmp += A13 - A12) - A02 - A03; // abhängig vom Befehl 2 drüber
+ V[43] = tmp - A04 - A06 - A07; // abhängig von Befehlen 1 und 3 drüber
+ V[47] = (tmp = -(A08 + A12 + A14 + A15)) - A00;
+ V[45] = tmp - A04 - A06 - A07; // abhängig vom Befehl drüber
+
+ V[32] = -V[ 0];
+ V[31] = -V[ 1];
+ V[30] = -V[ 2];
+ V[29] = -V[ 3];
+ V[28] = -V[ 4];
+ V[27] = -V[ 5];
+ V[26] = -V[ 6];
+ V[25] = -V[ 7];
+ V[24] = -V[ 8];
+ V[23] = -V[ 9];
+ V[22] = -V[10];
+ V[21] = -V[11];
+ V[20] = -V[12];
+ V[19] = -V[13];
+ V[18] = -V[14];
+ V[17] = -V[15];
+
+ V[63] = V[33];
+ V[62] = V[34];
+ V[61] = V[35];
+ V[60] = V[36];
+ V[59] = V[37];
+ V[58] = V[38];
+ V[57] = V[39];
+ V[56] = V[40];
+ V[55] = V[41];
+ V[54] = V[42];
+ V[53] = V[43];
+ V[52] = V[44];
+ V[51] = V[45];
+ V[50] = V[46];
+ V[49] = V[47];
+}
+
+static void Synthese_Filter_float_internal(MPC_SAMPLE_FORMAT * OutData,MPC_SAMPLE_FORMAT * V,const MPC_SAMPLE_FORMAT * Y)
+{
+ mpc_uint32_t n;
+ for ( n = 0; n < 36; n++, Y += 32 ) {
+ V -= 64;
+ Calculate_New_V ( Y, V );
+ {
+ MPC_SAMPLE_FORMAT * Data = OutData;
+ const MPC_SAMPLE_FORMAT * D = (const MPC_SAMPLE_FORMAT *) &Di_opt;
+ mpc_int32_t k;
+ //mpc_int32_t tmp;
+
+
+
+ for ( k = 0; k < 32; k++, D += 16, V++ ) {
+ *Data = MPC_SHL(
+ MPC_MULTIPLY_FRACT(V[ 0],D[ 0]) + MPC_MULTIPLY_FRACT(V[ 96],D[ 1]) + MPC_MULTIPLY_FRACT(V[128],D[ 2]) + MPC_MULTIPLY_FRACT(V[224],D[ 3])
+ + MPC_MULTIPLY_FRACT(V[256],D[ 4]) + MPC_MULTIPLY_FRACT(V[352],D[ 5]) + MPC_MULTIPLY_FRACT(V[384],D[ 6]) + MPC_MULTIPLY_FRACT(V[480],D[ 7])
+ + MPC_MULTIPLY_FRACT(V[512],D[ 8]) + MPC_MULTIPLY_FRACT(V[608],D[ 9]) + MPC_MULTIPLY_FRACT(V[640],D[10]) + MPC_MULTIPLY_FRACT(V[736],D[11])
+ + MPC_MULTIPLY_FRACT(V[768],D[12]) + MPC_MULTIPLY_FRACT(V[864],D[13]) + MPC_MULTIPLY_FRACT(V[896],D[14]) + MPC_MULTIPLY_FRACT(V[992],D[15])
+ , 2);
+
+ Data += 2;
+ }
+ V -= 32;//bleh
+ OutData+=64;
+ }
+ }
+}
+
+void
+mpc_decoder_synthese_filter_float(mpc_decoder *d, MPC_SAMPLE_FORMAT* OutData)
+{
+ /********* left channel ********/
+ memmove(d->V_L + MPC_V_MEM, d->V_L, 960 * sizeof(MPC_SAMPLE_FORMAT) );
+
+ Synthese_Filter_float_internal(
+ OutData,
+ (MPC_SAMPLE_FORMAT *)(d->V_L + MPC_V_MEM),
+ (MPC_SAMPLE_FORMAT *)(d->Y_L [0]));
+
+ /******** right channel ********/
+ memmove(d->V_R + MPC_V_MEM, d->V_R, 960 * sizeof(MPC_SAMPLE_FORMAT) );
+
+ Synthese_Filter_float_internal(
+ OutData + 1,
+ (MPC_SAMPLE_FORMAT *)(d->V_R + MPC_V_MEM),
+ (MPC_SAMPLE_FORMAT *)(d->Y_R [0]));
+}
+
+/*******************************************/
+/* */
+/* dithered synthesis */
+/* */
+/*******************************************/
+
+static const unsigned char Parity [256] = { // parity
+ 0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
+ 1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,
+ 1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,
+ 0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
+ 1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,
+ 0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
+ 0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
+ 1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0
+};
+
+/*
+ * This is a simple random number generator with good quality for audio purposes.
+ * It consists of two polycounters with opposite rotation direction and different
+ * periods. The periods are coprime, so the total period is the product of both.
+ *
+ * -------------------------------------------------------------------------------------------------
+ * +-> |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|
+ * | -------------------------------------------------------------------------------------------------
+ * | | | | | | |
+ * | +--+--+--+-XOR-+--------+
+ * | |
+ * +--------------------------------------------------------------------------------------+
+ *
+ * -------------------------------------------------------------------------------------------------
+ * |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| <-+
+ * ------------------------------------------------------------------------------------------------- |
+ * | | | | |
+ * +--+----XOR----+--+ |
+ * | |
+ * +----------------------------------------------------------------------------------------+
+ *
+ *
+ * The first has an period of 3*5*17*257*65537, the second of 7*47*73*178481,
+ * which gives a period of 18.410.713.077.675.721.215. The result is the
+ * XORed values of both generators.
+ */
+mpc_uint32_t
+mpc_random_int(mpc_decoder *d)
+{
+#if 1
+ mpc_uint32_t t1, t2, t3, t4;
+
+ t3 = t1 = d->__r1; t4 = t2 = d->__r2; // Parity calculation is done via table lookup, this is also available
+ t1 &= 0xF5; t2 >>= 25; // on CPUs without parity, can be implemented in C and avoid unpredictable
+ t1 = Parity [t1]; t2 &= 0x63; // jumps and slow rotate through the carry flag operations.
+ t1 <<= 31; t2 = Parity [t2];
+
+ return (d->__r1 = (t3 >> 1) | t1 ) ^ (d->__r2 = (t4 + t4) | t2 );
+#else
+ return (d->__r1 = (d->__r1 >> 1) | ((mpc_uint32_t)Parity [d->__r1 & 0xF5] << 31) ) ^
+ (d->__r2 = (d->__r2 << 1) | (mpc_uint32_t)Parity [(d->__r2 >> 25) & 0x63] );
+#endif
+}
diff --git a/contrib/libxdg-basedir/Makefile.am b/contrib/libxdg-basedir/Makefile.am
new file mode 100644
index 000000000..420d85999
--- /dev/null
+++ b/contrib/libxdg-basedir/Makefile.am
@@ -0,0 +1,7 @@
+if !EXTERNAL_LIBXDG_BASEDIR
+noinst_LTLIBRARIES = libxdg-basedir.la
+endif
+
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+
+libxdg_basedir_la_SOURCES = basedir.c basedir.h
diff --git a/contrib/libxdg-basedir/basedir.c b/contrib/libxdg-basedir/basedir.c
new file mode 100644
index 000000000..ae50d1bba
--- /dev/null
+++ b/contrib/libxdg-basedir/basedir.c
@@ -0,0 +1,486 @@
+/* Copyright (c) 2007 Mark Nevill
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/** @file basedir.c
+ * @brief Implementation of the XDG basedir specification. */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#if STDC_HEADERS || HAVE_STDLIB_H
+# include <stdlib.h>
+#endif
+#if HAVE_MEMORY_H
+# include <memory.h>
+#endif
+#if HAVE_STRING_H
+# include <string.h>
+#else
+# if HAVE_STRINGS_H
+# include <strings.h>
+# endif /* !HAVE_STRINGS_H */
+#endif /* !HAVE_STRING_H */
+
+#if defined _WIN32 && !defined __CYGWIN__
+ /* Use Windows separators on all _WIN32 defining
+ environments, except Cygwin. */
+# define DIR_SEPARATOR_CHAR '\\'
+# define DIR_SEPARATOR_STR "\\"
+# define PATH_SEPARATOR_CHAR ';'
+# define PATH_SEPARATOR_STR ";"
+# define NO_ESCAPES_IN_PATHS
+#else
+# define DIR_SEPARATOR_CHAR '/'
+# define DIR_SEPARATOR_STR "/"
+# define PATH_SEPARATOR_CHAR ':'
+# define PATH_SEPARATOR_STR ":"
+#endif
+
+#include <stdarg.h>
+#include <basedir.h>
+
+#ifndef MAX
+# define MAX(a, b) ((b) > (a) ? (b) : (a))
+#endif
+
+static const char
+ DefaultRelativeDataHome[] = DIR_SEPARATOR_STR ".local" DIR_SEPARATOR_STR "share",
+ DefaultRelativeConfigHome[] = DIR_SEPARATOR_STR ".config",
+ DefaultDataDirectories1[] = DIR_SEPARATOR_STR "usr" DIR_SEPARATOR_STR "local" DIR_SEPARATOR_STR "share",
+ DefaultDataDirectories2[] = DIR_SEPARATOR_STR "usr" DIR_SEPARATOR_STR "share",
+ DefaultConfigDirectories[] = DIR_SEPARATOR_STR "etc" DIR_SEPARATOR_STR "xdg",
+ DefaultRelativeCacheHome[] = DIR_SEPARATOR_STR ".cache";
+
+typedef struct _xdgCachedData
+{
+ char * dataHome;
+ char * configHome;
+ char * cacheHome;
+ /* Note: string lists are null-terminated and all items */
+ /* except the first are assumed to be allocated using malloc. */
+ /* The first item is assumed to be allocated by malloc only if */
+ /* it is not equal to the appropriate home directory string above. */
+ char ** searchableDataDirectories;
+ char ** searchableConfigDirectories;
+} xdgCachedData;
+
+#define GET_CACHE(handle) ((xdgCachedData*)(handle->reserved))
+
+xdgHandle xdgAllocHandle()
+{
+ xdgHandle handle = (xdgHandle)malloc(sizeof(*handle));
+ if (!handle) return 0;
+ handle->reserved = 0; /* So xdgUpdateData() doesn't free it */
+ if (xdgUpdateData(handle))
+ return handle;
+ else
+ free(handle);
+ return 0;
+}
+
+/** Free all memory used by a NULL-terminated string list */
+static void xdgFreeStringList(char** list)
+{
+ char** ptr = list;
+ if (!list) return;
+ for (; *ptr; ptr++)
+ free(*ptr);
+ free(list);
+}
+
+/** Free all data in the cache and set pointers to null. */
+static void xdgFreeData(xdgCachedData *cache)
+{
+ if (cache->dataHome);
+ {
+ /* the first element of the directory lists is usually the home directory */
+ if (cache->searchableDataDirectories[0] != cache->dataHome)
+ free(cache->dataHome);
+ cache->dataHome = 0;
+ }
+ if (cache->configHome);
+ {
+ if (cache->searchableConfigDirectories[0] != cache->configHome)
+ free(cache->configHome);
+ cache->configHome = 0;
+ }
+ xdgFreeStringList(cache->searchableDataDirectories);
+ cache->searchableDataDirectories = 0;
+ xdgFreeStringList(cache->searchableConfigDirectories);
+ cache->searchableConfigDirectories = 0;
+}
+
+void xdgFreeHandle(xdgHandle handle)
+{
+ xdgCachedData* cache = (xdgCachedData*)(handle->reserved);
+ xdgFreeData(cache);
+ free(cache);
+ free(handle);
+}
+
+/** Get value for environment variable $name, defaulting to "defaultValue".
+ * @param name Name of environment variable.
+ * @param defaultValue Value to assume for environment variable if it is
+ * unset or empty.
+ */
+static char* xdgGetEnv(const char* name, const char* defaultValue)
+{
+ const char* env;
+ char* value;
+
+ env = getenv(name);
+ if (env && env[0])
+ {
+ if (!(value = (char*)malloc(strlen(env)+1))) return 0;
+ strcpy(value, env);
+ }
+ else
+ {
+ if (!(value = (char*)malloc(strlen(defaultValue)+1))) return 0;
+ strcpy(value, defaultValue);
+ }
+ return value;
+}
+
+/** Split string at ':', return null-terminated list of resulting strings.
+ * @param string String to be split
+ */
+static char** xdgSplitPath(const char* string)
+{
+ unsigned int size, i, j, k;
+ char** itemlist;
+
+ /* Get the number of paths */
+ size=2; /* One item more than seperators + terminating null item */
+ for (i = 0; string[i]; ++i)
+ {
+#ifndef NO_ESCAPES_IN_PATHS
+ if (string[i] == '\\' && string[i+1]) ++i; /* skip escaped characters including seperators */
+#endif
+ else if (string[i] == PATH_SEPARATOR_CHAR) ++size;
+ }
+
+ if (!(itemlist = (char**)malloc(sizeof(char*)*size))) return 0;
+ memset(itemlist, 0, sizeof(char*)*size);
+
+ for (i = 0; *string; ++i)
+ {
+ /* get length of current string */
+ for (j = 0; string[j] && string[j] != PATH_SEPARATOR_CHAR; ++j)
+#ifndef NO_ESCAPES_IN_PATHS
+ if (string[j] == '\\' && string[j+1]) ++j
+#endif
+ ;
+
+ if (!(itemlist[i] = (char*)malloc(j+1))) { xdgFreeStringList(itemlist); return 0; }
+
+ /* transfer string, unescaping any escaped seperators */
+ for (k = j = 0; string[j] && string[j] != PATH_SEPARATOR_CHAR; ++j, ++k)
+ {
+#ifndef NO_ESCAPES_IN_PATHS
+ if (string[j] == '\\' && string[j+1] == PATH_SEPARATOR_CHAR) ++j; /* replace escaped ':' with just ':' */
+ else if (string[j] == '\\' && string[j+1]) /* skip escaped characters so escaping remains aligned to pairs. */
+ {
+ itemlist[i][k]=string[j];
+ ++j, ++k;
+ }
+#endif
+ itemlist[i][k] = string[j];
+ }
+ itemlist[i][k] = 0; // Bugfix provided by Diego 'Flameeyes' Pettenò
+ /* move to next string */
+ string += j;
+ if (*string == PATH_SEPARATOR_CHAR) string++; /* skip seperator */
+ }
+ return itemlist;
+}
+
+/** Get $PATH-style environment variable as list of strings.
+ * If $name is unset or empty, use default strings specified by variable arguments.
+ * @param name Name of environment variable
+ * @param numDefaults Number of default paths in variable argument list
+ * @param ... numDefaults number of strings to be copied and used as defaults
+ */
+static char** xdgGetPathListEnv(const char* name, int numDefaults, ...)
+{
+ const char* env;
+ va_list ap;
+ char* item;
+ const char* arg;
+ char** itemlist;
+ int i;
+
+ env = getenv(name);
+ if (env && env[0])
+ {
+ if (!(item = (char*)malloc(strlen(env)+1))) return 0;
+ strcpy(item, env);
+
+ itemlist = xdgSplitPath(item);
+ free(item);
+ }
+ else
+ {
+ if (!(itemlist = (char**)malloc(sizeof(char*)*numDefaults+1))) return 0;
+ memset(itemlist, 0, sizeof(char*)*(numDefaults+1));
+
+ /* Copy the varargs into the itemlist */
+ va_start(ap, numDefaults);
+ for (i = 0; i < numDefaults; i++)
+ {
+ arg = va_arg(ap, const char*);
+ if (!(item = (char*)malloc(strlen(arg)+1))) { xdgFreeStringList(itemlist); return 0; }
+ strcpy(item, arg);
+ itemlist[i] = item;
+ }
+ va_end(ap);
+ }
+ return itemlist;
+}
+
+/** Update all *Home variables of cache.
+ * This includes xdgCachedData::dataHome, xdgCachedData::configHome and xdgCachedData::cacheHome.
+ * @param cache Data cache to be updated
+ */
+static bool xdgUpdateHomeDirectories(xdgCachedData* cache)
+{
+ const char* env;
+ char* home, *defVal;
+
+ env = getenv("HOME");
+ if (!env || !env[0])
+ return false;
+ if (!(home = (char*)malloc(strlen(env)+1))) return false;
+ strcpy(home, env);
+
+ /* Allocate maximum needed for any of the 3 default values */
+ defVal = (char*)malloc(strlen(home)+
+ MAX(MAX(sizeof(DefaultRelativeDataHome), sizeof(DefaultRelativeConfigHome)), sizeof(DefaultRelativeCacheHome)));
+ if (!defVal) return false;
+
+ strcpy(defVal, home);
+ strcat(defVal, DefaultRelativeDataHome);
+ if (!(cache->dataHome = xdgGetEnv("XDG_DATA_HOME", defVal))) return false;
+
+ defVal[strlen(home)] = 0;
+ strcat(defVal, DefaultRelativeConfigHome);
+ if (!(cache->configHome = xdgGetEnv("XDG_CONFIG_HOME", defVal))) return false;
+
+ defVal[strlen(home)] = 0;
+ strcat(defVal, DefaultRelativeCacheHome);
+ if (!(cache->cacheHome = xdgGetEnv("XDG_CACHE_HOME", defVal))) return false;
+
+ free(defVal);
+ free(home);
+
+ return true;
+}
+
+/** Update all *Directories variables of cache.
+ * This includes xdgCachedData::searchableDataDirectories and xdgCachedData::searchableConfigDirectories.
+ * @param cache Data cache to be updated.
+ */
+static bool xdgUpdateDirectoryLists(xdgCachedData* cache)
+{
+ char** itemlist;
+ int size;
+
+ itemlist = xdgGetPathListEnv("XDG_DATA_DIRS", 2,
+ DefaultDataDirectories1, DefaultDataDirectories2);
+ if (!itemlist) return false;
+ for (size = 0; itemlist[size]; size++) ; /* Get list size */
+ if (!(cache->searchableDataDirectories = (char**)malloc(sizeof(char*)*(size+2))))
+ {
+ xdgFreeStringList(itemlist);
+ return false;
+ }
+ /* "home" directory has highest priority according to spec */
+ cache->searchableDataDirectories[0] = cache->dataHome;
+ memcpy(&(cache->searchableDataDirectories[1]), itemlist, sizeof(char*)*(size+1));
+ free(itemlist);
+
+ itemlist = xdgGetPathListEnv("XDG_CONFIG_DIRS", 1, DefaultConfigDirectories);
+ if (!itemlist) return false;
+ for (size = 0; itemlist[size]; size++) ; /* Get list size */
+ if (!(cache->searchableConfigDirectories = (char**)malloc(sizeof(char*)*(size+2))))
+ {
+ xdgFreeStringList(itemlist);
+ return false;
+ }
+ cache->searchableConfigDirectories[0] = cache->configHome;
+ memcpy(&(cache->searchableConfigDirectories[1]), itemlist, sizeof(char*)*(size+1));
+ free(itemlist);
+
+ return true;
+}
+
+bool xdgUpdateData(xdgHandle handle)
+{
+ xdgCachedData* cache = (xdgCachedData*)malloc(sizeof(xdgCachedData));
+ if (!cache) return false;
+ memset(cache, 0, sizeof(xdgCachedData));
+
+ if (xdgUpdateHomeDirectories(cache) &&
+ xdgUpdateDirectoryLists(cache))
+ {
+ /* Update successful, replace pointer to old cache with pointer to new cache */
+ if (handle->reserved) free(handle->reserved);
+ handle->reserved = cache;
+ return true;
+ }
+ else
+ {
+ /* Update failed, discard new cache and leave old cache unmodified */
+ xdgFreeData(cache);
+ free(cache);
+ return false;
+ }
+}
+
+/** Find all existing files corresponding to relativePath relative to each item in dirList.
+ * @param relativePath Relative path to search for.
+ * @param dirList <tt>NULL</tt>-terminated list of directory paths.
+ * @return A sequence of null-terminated strings terminated by a
+ * double-<tt>NULL</tt> (empty string) and allocated using malloc().
+ */
+static const char* xdgFindExisting(const char * relativePath, const char * const * dirList)
+{
+ char * fullPath;
+ char * returnString = 0;
+ char * tmpString;
+ int strLen = 0;
+ FILE * testFile;
+ const char * const * item;
+
+ for (item = dirList; *item; item++)
+ {
+ if (!(fullPath = (char*)malloc(strlen(*item)+strlen(relativePath)+2)))
+ {
+ if (returnString) free(returnString);
+ return 0;
+ }
+ strcpy(fullPath, *item);
+ if (fullPath[strlen(fullPath)-1] != DIR_SEPARATOR_CHAR)
+ strcat(fullPath, DIR_SEPARATOR_STR);
+ strcat(fullPath, relativePath);
+ testFile = fopen(fullPath, "r");
+ if (testFile)
+ {
+ if (!(tmpString = (char*)realloc(returnString, strLen+strlen(fullPath)+2)))
+ {
+ free(returnString);
+ free(fullPath);
+ return 0;
+ }
+ returnString = tmpString;
+ strcpy(&returnString[strLen], fullPath);
+ strLen = strLen+strlen(fullPath)+1;
+ fclose(testFile);
+ }
+ free(fullPath);
+ }
+ if (returnString)
+ returnString[strLen] = 0;
+ else
+ {
+ if ((returnString = (char*)malloc(2)))
+ strcpy(returnString, "\0");
+ }
+ return returnString;
+}
+
+/** Open first possible config file corresponding to relativePath.
+ * @param relativePath Path to scan for.
+ * @param mode Mode with which to attempt to open files (see fopen modes).
+ * @param dirList <tt>NULL</tt>-terminated list of paths in which to search for relativePath.
+ * @return File pointer if successful else @c NULL. Client must use @c fclose to close file.
+ */
+static FILE * xdgFileOpen(const char * relativePath, const char * mode, const char * const * dirList)
+{
+ char * fullPath;
+ FILE * testFile;
+ const char * const * item;
+
+ for (item = dirList; *item; item++)
+ {
+ if (fullPath = (char*)malloc(strlen(*item)+strlen(relativePath)+2))
+ return 0;
+ strcpy(fullPath, *item);
+ if (fullPath[strlen(fullPath)-1] != DIR_SEPARATOR_CHAR)
+ strcat(fullPath, DIR_SEPARATOR_STR);
+ strcat(fullPath, relativePath);
+ testFile = fopen(fullPath, mode);
+ free(fullPath);
+ if (testFile)
+ return testFile;
+ }
+ return 0;
+}
+
+const char * xdgDataHome(xdgHandle handle)
+{
+ return GET_CACHE(handle)->dataHome;
+}
+const char * xdgConfigHome(xdgHandle handle)
+{
+ return GET_CACHE(handle)->configHome;
+}
+const char * const * xdgDataDirectories(xdgHandle handle)
+{
+ return &(GET_CACHE(handle)->searchableDataDirectories[1]);
+}
+const char * const * xdgSearchableDataDirectories(xdgHandle handle)
+{
+ return GET_CACHE(handle)->searchableDataDirectories;
+}
+const char * const * xdgConfigDirectories(xdgHandle handle)
+{
+ return &(GET_CACHE(handle)->searchableConfigDirectories[1]);
+}
+const char * const * xdgSearchableConfigDirectories(xdgHandle handle)
+{
+ return GET_CACHE(handle)->searchableConfigDirectories;
+}
+const char * xdgCacheHome(xdgHandle handle)
+{
+ return GET_CACHE(handle)->cacheHome;
+}
+const char * xdgDataFind(const char * relativePath, xdgHandle handle)
+{
+ return xdgFindExisting(relativePath, xdgSearchableDataDirectories(handle));
+}
+const char * xdgConfigFind(const char * relativePath, xdgHandle handle)
+{
+ return xdgFindExisting(relativePath, xdgSearchableConfigDirectories(handle));
+}
+FILE * xdgDataOpen(const char * relativePath, const char * mode, xdgHandle handle)
+{
+ return xdgFileOpen(relativePath, mode, xdgSearchableDataDirectories(handle));
+}
+FILE * xdgConfigOpen(const char * relativePath, const char * mode, xdgHandle handle)
+{
+ return xdgFileOpen(relativePath, mode, xdgSearchableConfigDirectories(handle));
+}
+
diff --git a/contrib/libxdg-basedir/basedir.h b/contrib/libxdg-basedir/basedir.h
new file mode 100644
index 000000000..cfdd88bec
--- /dev/null
+++ b/contrib/libxdg-basedir/basedir.h
@@ -0,0 +1,185 @@
+/* Copyright (c) 2007 Mark Nevill
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/** @file basedir.h
+ * @brief Functions for using the XDG basedir specification.
+ * See http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html for details. */
+
+#ifndef XDG_BASEDIR_H
+#define XDG_BASEDIR_H
+
+#if !defined(__cplusplus) && !defined(__bool_true_false_are_defined) && !defined(_DOXYGEN)
+#if defined(STDC_HEADERS) || defined(HAVE_STDBOOL_H)
+#include <stdbool.h>
+#else
+#ifdef HAVE__BOOL
+#define bool _Bool
+#else
+#define bool int
+#endif // HAVE__BOOL
+#define true 1
+#define false 0
+#define XDG_BASEDIR_H_LOCAL_BOOL_DEFINE
+#define __bool_true_false_are_defined
+#endif // STDC_HEADERS || HAVE_STDBOOL_H
+#endif // !__cplusplus && !__bool_true_false_are_defined
+
+#include <stdio.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** Version of XDG basedir-spec implemented in this library. */
+#define XDG_BASEDIR_SPEC 0.6
+
+/** @name XDG data cache management */
+/*@{*/
+
+/** Handle to XDG data cache.
+ * Handles are allocated with xdgAllocHandle() and
+ * freed with xdgFreeHandle(). */
+typedef struct /*_xdgHandle*/ {
+ void *reserved;
+} *xdgHandle;
+
+
+
+/** Get a handle to an XDG data cache and initialize the cache.
+ * Use xdgFreeHandle() to free the handle. */
+xdgHandle xdgAllocHandle();
+
+/** Free handle to XDG data cache.
+ * Free handle allocated using xdgAllocHandle(). */
+void xdgFreeHandle(xdgHandle handle);
+
+/** Update the data cache.
+ * This should not be done frequently as it reallocates the cache.
+ * Even if updating the cache fails the handle remains valid and can
+ * be used to access XDG data as it was before xdgUpdateData() was called.
+ * @return 0 if update failed, non-0 if successful.*/
+bool xdgUpdateData(xdgHandle handle);
+
+/*@}*/
+/** @name Basic XDG-Basedir Queries */
+/*@{*/
+
+/** Base directory for user specific data files.
+ * "${XDG_DATA_HOME:-$HOME/.local/share}" */
+const char * xdgDataHome(xdgHandle handle);
+
+/** Base directory for user specific configuration files.
+ * "${XDG_CONFIG_HOME:-$HOME/.config}" */
+const char * xdgConfigHome(xdgHandle handle);
+
+/** Preference-ordered set of base directories to search for data files
+ * in addition to the $XDG_DATA_HOME base directory.
+ * "${XDG_DATA_DIRS:-/usr/local/share/:/usr/share/}".
+ * @return A null-terminated list of directory strings. */
+const char * const * xdgDataDirectories(xdgHandle handle);
+
+/** Preference-ordered set of base directories to search for data files
+ * with $XDG_DATA_HOME prepended.
+ * The base directory defined by $XDG_DATA_HOME is considered more
+ * important than any of the base directories defined by $XDG_DATA_DIRS.
+ * @return A null-terminated list of directory strings. */
+const char * const * xdgSearchableDataDirectories(xdgHandle handle);
+
+/** Preference-ordered set of base directories to search for configuration
+ * files in addition to the $XDG_CONFIG_HOME base directory.
+ * "${XDG_CONFIG_DIRS:-/etc/xdg}".
+ * @return A null-terminated list of directory strings. */
+const char * const * xdgConfigDirectories(xdgHandle handle);
+
+/** Preference-ordered set of base directories to search for configuration
+ * files with $XDG_CONFIG_HOME prepended.
+ * The base directory defined by $XDG_CONFIG_HOME is considered more
+ * important than any of the base directories defined by $XDG_CONFIG_DIRS.
+ * @return A null-terminated list of directory strings. */
+const char * const * xdgSearchableConfigDirectories(xdgHandle handle);
+
+/** Base directory for user specific non-essential data files.
+ * "${XDG_CACHE_HOME:-$HOME/.cache}" */
+const char * xdgCacheHome(xdgHandle handle);
+
+/*@}*/
+
+/** @name Higher-level XDG-Basedir Queries */
+/*@{*/
+
+/** Find all existing data files corresponding to relativePath.
+ * Consider as performing @code fopen(filename, "r") @endcode on every possible @c filename
+ * and returning the successful <tt>filename</tt>s.
+ * @param relativePath Path to scan for.
+ * @param handle Handle to data cache.
+ * @return A sequence of null-terminated strings terminated by a double-null (empty string)
+ * and allocated using malloc(), e.g.: @code "/etc/share\0/home/jdoe/.local\0" @endcode
+ */
+const char * xdgDataFind(const char* relativePath, xdgHandle handle);
+
+/** Find all existing config files corresponding to relativePath.
+ * Consider as performing @code fopen(filename, "r") @endcode on every possible @c filename
+ * and returning the successful <tt>filename</tt>s.
+ * @param relativePath Path to scan for.
+ * @param handle Handle to data cache.
+ * @return A sequence of null-terminated strings terminated by a double-null (empty string)
+ * and allocated using malloc(), e.g.: @code "/etc/xdg\0/home/jdoe/.config\0" @endcode
+ */
+const char * xdgConfigFind(const char* relativePath, xdgHandle handle);
+
+/** Open first possible data file corresponding to relativePath.
+ * Consider as performing @code fopen(filename, mode) @endcode on every possible @c filename
+ * and returning the first successful @c filename or @c NULL.
+ * @param relativePath Path to scan for.
+ * @param mode Mode with which to attempt to open files (see fopen modes).
+ * @param handle Handle to data cache.
+ * @return File pointer if successful else @c NULL. Client must use @c fclose to close file.
+ */
+FILE * xdgDataOpen(const char* relativePath, const char* mode, xdgHandle handle);
+
+/** Open first possible config file corresponding to relativePath.
+ * Consider as performing @code fopen(filename, mode) @endcode on every possible @c filename
+ * and returning the first successful @c filename or @c NULL.
+ * @param relativePath Path to scan for.
+ * @param mode Mode with which to attempt to open files (see fopen modes).
+ * @param handle Handle to data cache.
+ * @return File pointer if successful else @c NULL. Client must use @c fclose to close file.
+ */
+FILE * xdgConfigOpen(const char* relativePath, const char* mode, xdgHandle handle);
+
+/*@}*/
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#ifdef XDG_BASEDIR_H_LOCAL_BOOL_DEFINE
+#undef bool
+#undef true
+#undef false
+#undef __bool_true_false_are_defined
+#undef XDG_BASEDIR_H_LOCAL_BOOL_DEFINE
+#endif
+
+#endif /*XDG_BASEDIR_H*/
diff --git a/contrib/nosefart/Makefile.am b/contrib/nosefart/Makefile.am
new file mode 100644
index 000000000..83c04a28d
--- /dev/null
+++ b/contrib/nosefart/Makefile.am
@@ -0,0 +1,37 @@
+include $(top_srcdir)/misc/Makefile.common
+
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+
+noinst_LTLIBRARIES = libnosefart.la
+
+libnosefart_la_SOURCES = \
+ fds_snd.c \
+ log.c \
+ mmc5_snd.c \
+ nes_apu.c \
+ vrc7_snd.c \
+ dis6502.c \
+ fmopl.c \
+ memguard.c \
+ nes6502.c \
+ nsf.c \
+ vrcvisnd.c
+
+libnosefart_la_CFLAGS = $(AM_CFLAGS) -fno-strict-aliasing
+libnosefart_la_CPPFLAGS = -DNSF_PLAYER
+
+noinst_HEADERS = \
+ dis6502.h \
+ fmopl.h \
+ memguard.h \
+ nes6502.h \
+ nsf.h \
+ types.h \
+ vrc7_snd.h \
+ fds_snd.h \
+ log.h \
+ mmc5_snd.h \
+ nes_apu.h \
+ osd.h \
+ version.h \
+ vrcvisnd.h
diff --git a/contrib/nosefart/diff_to_nosefart_cvs.patch b/contrib/nosefart/diff_to_nosefart_cvs.patch
new file mode 100644
index 000000000..2b6202fb8
--- /dev/null
+++ b/contrib/nosefart/diff_to_nosefart_cvs.patch
@@ -0,0 +1,117 @@
+diff -u -p -r1.1.1.1 types.h
+--- types.h 26 Jul 2004 15:27:59 -0000 1.1.1.1
++++ types.h 26 Aug 2004 16:00:07 -0000
+@@ -23,8 +23,8 @@
+ ** $Id: diff_to_nosefart_cvs.patch,v 1.2 2005/05/07 09:11:39 valtri Exp $
+ */
+
+-#ifndef _TYPES_H_
+-#define _TYPES_H_
++#ifndef _NOSEFART_TYPES_H_
++#define _NOSEFART_TYPES_H_
+
+ #ifdef HAVE_CONFIG_H
+ #include "config.h"
+@@ -88,7 +88,7 @@ typedef uint8 boolean;
+ #define ASSERT_MSG(msg)
+ #endif
+
+-#endif /* _TYPES_H_ */
++#endif /* _NOSEFART_TYPES_H_ */
+
+ /*
+ ** $Log: diff_to_nosefart_cvs.patch,v $
+ ** Revision 1.2 2005/05/07 09:11:39 valtri
+ ** *BUGFIX*
+ ** gcc4 patches from Dams Nadé (livna.org) and Keenan Pepper.
+ **
+ ** Revision 1.1 2004/08/27 19:33:37 valtri
+ ** MINGW32 port. Engine library and most of plugins compiles now.
+ **
+ ** List of some changes:
+ ** - replaced some _MSC_VER by more common WIN32
+ ** - define INTLDIR, remove -static flag for included intl
+ ** - shared more common CFLAGS with DEBUG_CFLAGS
+ ** - use WIN32_CFLAGS for all building
+ ** - separate some flags into THREAD_CFLAGS_CONFIG,
+ ** THREAD_CFLAGS_CONFIG and ZLIB_LIB_CONFIG for public xine-config,
+ ** automatically use internal libs if necessary
+ ** - don't warn about missing X for mingw and cygwin
+ ** - libw32dll disabled for WIN32 (making native loader would be
+ ** interesting, or porting wine code to Windows? :->)
+ ** - DVB and RTP disabled for WIN32, not ported yet
+ ** - fix build and fix a warning in cdda
+ ** - fix build for nosefart and libfaad
+ ** - implement configure option --disable-freetype
+ ** - sync libxine.pc and xine-config.in
+ ** - add -liberty to goom under WIN32
+ ** - move original build files from included phread and zlib into archives
+ ** and replace them by autotools
+ **
+Index: nes_apu.c
+===================================================================
+RCS file: /home/valtri/CVS/xine-lib/src/libxineadec/nosefart/nes_apu.c,v
+retrieving revision 1.1.1.1
+diff -u -p -r1.1.1.1 nes_apu.c
+--- nes_apu.c 12 Dec 2004 13:57:16 -0000 1.1.1.1
++++ nes_apu.c 7 May 2005 08:23:36 -0000
+@@ -1011,10 +1011,13 @@ void apu_process(void *buffer, int num_s
+ accum = -0x8000;
+
+ /* signed 16-bit output, unsigned 8-bit */
+- if (16 == apu->sample_bits)
+- *((int16 *) buffer)++ = (int16) accum;
+- else
+- *((uint8 *) buffer)++ = (accum >> 8) ^ 0x80;
++ if (16 == apu->sample_bits) {
++ *((int16 *) buffer) = (int16) accum;
++ buffer = (int16 *) buffer + 1;
++ } else {
++ *((uint8 *) buffer) = (accum >> 8) ^ 0x80;
++ buffer = (int8 *) buffer + 1;
++ }
+ }
+
+ /* resync cycle counter */
+--- a/src/libxineadec/nosefart/nsf.h Tue Apr 10 13:42:00 2007 +0200
++++ b/src/libxineadec/nosefart/nsf.h Tue Apr 10 13:48:50 2007 +0200
+@@ -29,6 +29,8 @@
+ #include "osd.h"
+ #include "nes6502.h"
+ #include "nes_apu.h"
++
++#include "config.h"
+
+ #define NSF_MAGIC "NESM\x1A"
+
+@@ -96,7 +98,7 @@ typedef struct nsf_s
+
+ /* our main processing routine, calls all external mixing routines */
+ void (*process)(void *buffer, int num_samples);
+-} __PACKED__ nsf_t;
++} XINE_PACKED nsf_t;
+
+ /* Function prototypes */
+ extern void nsf_init(void);
+--- a/src/libxineadec/nosefart/osd.h Tue Apr 10 13:42:00 2007 +0200
++++ b/src/libxineadec/nosefart/osd.h Tue Apr 10 13:19:34 2007 +0200
+@@ -26,19 +26,15 @@
+ #ifndef _OSD_H_
+ #define _OSD_H_
+
+-
+ #if defined(__GNUC__) || defined(__ICC)
+-#define __PACKED__ __attribute__ ((packed))
+ #define PATH_SEP '/'
+ #ifdef __DJGPP__
+ #include <dpmi.h>
+ #include "dos_ints.h"
+ #endif
+ #elif defined(WIN32)
+-#define __PACKED__
+ #define PATH_SEP '\\'
+ #else /* crapintosh? */
+-#define __PACKED__
+ #define PATH_SEP ':'
+ #endif
+
diff --git a/src/libxineadec/nosefart/dis6502.c b/contrib/nosefart/dis6502.c
index ff552d219..ff552d219 100644
--- a/src/libxineadec/nosefart/dis6502.c
+++ b/contrib/nosefart/dis6502.c
diff --git a/src/libxineadec/nosefart/dis6502.h b/contrib/nosefart/dis6502.h
index a02fd73ae..a02fd73ae 100644
--- a/src/libxineadec/nosefart/dis6502.h
+++ b/contrib/nosefart/dis6502.h
diff --git a/src/libxineadec/nosefart/fds_snd.c b/contrib/nosefart/fds_snd.c
index fe2e4d624..fe2e4d624 100644
--- a/src/libxineadec/nosefart/fds_snd.c
+++ b/contrib/nosefart/fds_snd.c
diff --git a/src/libxineadec/nosefart/fds_snd.h b/contrib/nosefart/fds_snd.h
index 9d20b5b2a..9d20b5b2a 100644
--- a/src/libxineadec/nosefart/fds_snd.h
+++ b/contrib/nosefart/fds_snd.h
diff --git a/src/libxineadec/nosefart/fmopl.c b/contrib/nosefart/fmopl.c
index 29c884096..29c884096 100644
--- a/src/libxineadec/nosefart/fmopl.c
+++ b/contrib/nosefart/fmopl.c
diff --git a/src/libxineadec/nosefart/fmopl.h b/contrib/nosefart/fmopl.h
index 92a2859d7..92a2859d7 100644
--- a/src/libxineadec/nosefart/fmopl.h
+++ b/contrib/nosefart/fmopl.h
diff --git a/src/libxineadec/nosefart/log.c b/contrib/nosefart/log.c
index 8935a596e..8935a596e 100644
--- a/src/libxineadec/nosefart/log.c
+++ b/contrib/nosefart/log.c
diff --git a/src/libxineadec/nosefart/log.h b/contrib/nosefart/log.h
index a12deff0a..a12deff0a 100644
--- a/src/libxineadec/nosefart/log.h
+++ b/contrib/nosefart/log.h
diff --git a/src/libxineadec/nosefart/memguard.c b/contrib/nosefart/memguard.c
index 35b3ef6ba..35b3ef6ba 100644
--- a/src/libxineadec/nosefart/memguard.c
+++ b/contrib/nosefart/memguard.c
diff --git a/src/libxineadec/nosefart/memguard.h b/contrib/nosefart/memguard.h
index d80d6fb7c..d80d6fb7c 100644
--- a/src/libxineadec/nosefart/memguard.h
+++ b/contrib/nosefart/memguard.h
diff --git a/src/libxineadec/nosefart/mmc5_snd.c b/contrib/nosefart/mmc5_snd.c
index 7269fa967..7269fa967 100644
--- a/src/libxineadec/nosefart/mmc5_snd.c
+++ b/contrib/nosefart/mmc5_snd.c
diff --git a/src/libxineadec/nosefart/mmc5_snd.h b/contrib/nosefart/mmc5_snd.h
index 256cc2285..256cc2285 100644
--- a/src/libxineadec/nosefart/mmc5_snd.h
+++ b/contrib/nosefart/mmc5_snd.h
diff --git a/src/libxineadec/nosefart/nes6502.c b/contrib/nosefart/nes6502.c
index f1ca80af4..f1ca80af4 100644
--- a/src/libxineadec/nosefart/nes6502.c
+++ b/contrib/nosefart/nes6502.c
diff --git a/src/libxineadec/nosefart/nes6502.h b/contrib/nosefart/nes6502.h
index 9b9be5811..9b9be5811 100644
--- a/src/libxineadec/nosefart/nes6502.h
+++ b/contrib/nosefart/nes6502.h
diff --git a/src/libxineadec/nosefart/nes_apu.c b/contrib/nosefart/nes_apu.c
index 4a2ed8f4d..4a2ed8f4d 100644
--- a/src/libxineadec/nosefart/nes_apu.c
+++ b/contrib/nosefart/nes_apu.c
diff --git a/src/libxineadec/nosefart/nes_apu.h b/contrib/nosefart/nes_apu.h
index 09b5842d9..09b5842d9 100644
--- a/src/libxineadec/nosefart/nes_apu.h
+++ b/contrib/nosefart/nes_apu.h
diff --git a/src/libxineadec/nosefart/nsf.c b/contrib/nosefart/nsf.c
index 6bbc96423..6bbc96423 100644
--- a/src/libxineadec/nosefart/nsf.c
+++ b/contrib/nosefart/nsf.c
diff --git a/contrib/nosefart/nsf.h b/contrib/nosefart/nsf.h
new file mode 100644
index 000000000..79ec1dbb6
--- /dev/null
+++ b/contrib/nosefart/nsf.h
@@ -0,0 +1,152 @@
+/*
+** Nofrendo (c) 1998-2000 Matthew Conte (matt@conte.com)
+**
+**
+** This program is free software; you can redistribute it and/or
+** modify it under the terms of version 2 of the GNU Library General
+** Public License as published by the Free Software Foundation.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+** Library General Public License for more details. To obtain a
+** copy of the GNU Library General Public License, write to the Free
+** Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** Any permitted reproduction of these routines, in whole or in part,
+** must bear this legend.
+**
+**
+** nsf.h
+**
+** NSF loading/saving related defines / prototypes
+** $Id: nsf.h,v 1.3 2007/01/18 21:34:10 dgp85 Exp $
+*/
+
+#ifndef _NSF_H_
+#define _NSF_H_
+
+#include "osd.h"
+#include "nes6502.h"
+#include "nes_apu.h"
+
+#include "config.h"
+
+#define NSF_MAGIC "NESM\x1A"
+
+#define NSF_DEDICATED_PAL 0x01
+#define NSF_DUAL_PAL_NTSC 0x02
+
+#define EXT_SOUND_NONE 0x00
+#define EXT_SOUND_VRCVI 0x01
+#define EXT_SOUND_VRCVII 0x02
+#define EXT_SOUND_FDS 0x04
+#define EXT_SOUND_MMC5 0x08
+#define EXT_SOUND_NAMCO106 0x10
+#define EXT_SOUND_SUNSOFT_FME07 0x20
+/* bits 6,7: future expansion */
+
+#define NSF_HEADER_SIZE 0x80
+
+/* 60 Hertz refresh (NTSC) */
+#define NES_MASTER_CLOCK 21477272.7272
+#define NTSC_REFRESH 60
+#define NTSC_SUBCARRIER_DIV 12
+#define NTSC_SCANLINES 262
+
+#define NES_FRAME_CYCLES ((NES_MASTER_CLOCK / NTSC_SUBCARRIER_DIV) / NTSC_REFRESH)
+#define NES_SCANLINE_CYCLES (NES_FRAME_CYCLES / NTSC_SCANLINES)
+
+/* filter levels */
+enum
+{
+ NSF_FILTER_NONE,
+ NSF_FILTER_LOWPASS,
+ NSF_FILTER_WEIGHTED
+};
+
+typedef struct nsf_s
+{
+ /* NESM header */
+ uint8 id[5]; /* NESM\x1A */
+ uint8 version; /* spec version */
+ uint8 num_songs; /* total num songs */
+ uint8 start_song; /* first song */
+ uint16 load_addr; /* loc to load code */
+ uint16 init_addr; /* init call address */
+ uint16 play_addr; /* play call address */
+ uint8 song_name[32]; /* name of song */
+ uint8 artist_name[32]; /* artist name */
+ uint8 copyright[32]; /* copyright info */
+ uint16 ntsc_speed; /* playback speed (if NTSC) */
+ uint8 bankswitch_info[8]; /* initial code banking */
+ uint16 pal_speed; /* playback speed (if PAL) */
+ uint8 pal_ntsc_bits; /* NTSC/PAL determination bits */
+ uint8 ext_sound_type; /* type of external sound gen. */
+ uint8 reserved[4]; /* reserved */
+
+ /* things that the NSF player needs */
+ uint8 *data; /* actual NSF data */
+ uint32 length; /* length of data */
+ uint32 playback_rate; /* current playback rate */
+ uint8 current_song; /* current song */
+ boolean bankswitched; /* is bankswitched? */
+
+ /* CPU and APU contexts */
+ nes6502_context *cpu;
+ apu_t *apu;
+
+ /* our main processing routine, calls all external mixing routines */
+ void (*process)(void *buffer, int num_samples);
+} XINE_PACKED nsf_t;
+
+/* Function prototypes */
+extern void nsf_init(void);
+
+extern nsf_t *nsf_load(char *filename, void *source, int length);
+extern void nsf_free(nsf_t **nsf_info);
+
+extern void nsf_playtrack(nsf_t *nsf, int track, int sample_rate, int sample_bits,
+ boolean stereo);
+extern void nsf_frame(nsf_t *nsf);
+extern void nsf_setchan(nsf_t *nsf, int chan, boolean enabled);
+extern void nsf_setfilter(nsf_t *nsf, int filter_type);
+
+#endif /* _NSF_H_ */
+
+/*
+** $Log: nsf.h,v $
+** Revision 1.3 2007/01/18 21:34:10 dgp85
+** __attribute__(packed) is used on the struct, not on its members.
+**
+** Revision 1.2 2003/12/05 15:55:01 f1rmb
+** cleanup phase II. use xprintf when it's relevant, use xine_xmalloc when it's relevant too. Small other little fix (can't remember). Change few internal function prototype because it xine_t pointer need to be used if some xine's internal sections. NOTE: libdvd{nav,read} is still too noisy, i will take a look to made it quit, without invasive changes. To be continued...
+**
+** Revision 1.1 2003/01/08 07:04:35 tmmm
+** initial import of Nosefart sources
+**
+** Revision 1.11 2000/07/04 04:59:24 matt
+** removed DOS-specific stuff
+**
+** Revision 1.10 2000/07/03 02:19:36 matt
+** dynamic address range handlers, cleaner and faster
+**
+** Revision 1.9 2000/06/23 03:27:58 matt
+** cleaned up external sound inteface
+**
+** Revision 1.8 2000/06/20 04:04:37 matt
+** moved external soundchip struct to apu module
+**
+** Revision 1.7 2000/06/20 00:05:45 matt
+** changed to driver-based external sound generation
+**
+** Revision 1.6 2000/06/13 03:51:54 matt
+** update API to take freq/sample data on nsf_playtrack
+**
+** Revision 1.5 2000/06/12 01:13:00 matt
+** added CPU/APU as members of the nsf struct
+**
+** Revision 1.4 2000/06/09 15:12:26 matt
+** initial revision
+**
+*/
diff --git a/contrib/nosefart/osd.h b/contrib/nosefart/osd.h
new file mode 100644
index 000000000..38b9480c7
--- /dev/null
+++ b/contrib/nosefart/osd.h
@@ -0,0 +1,94 @@
+/*
+** Nofrendo (c) 1998-2000 Matthew Conte (matt@conte.com)
+**
+**
+** This program is free software; you can redistribute it and/or
+** modify it under the terms of version 2 of the GNU Library General
+** Public License as published by the Free Software Foundation.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+** Library General Public License for more details. To obtain a
+** copy of the GNU Library General Public License, write to the Free
+** Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** Any permitted reproduction of these routines, in whole or in part,
+** must bear this legend.
+**
+**
+** osd.h
+**
+** O/S dependent routine defintions (must be customized)
+** $Id: osd.h,v 1.2 2003/07/12 12:31:14 mroi Exp $
+*/
+
+#ifndef _OSD_H_
+#define _OSD_H_
+
+#if defined(__GNUC__) || defined(__ICC)
+#define PATH_SEP '/'
+#ifdef __DJGPP__
+#include <dpmi.h>
+#include "dos_ints.h"
+#endif
+#elif defined(WIN32)
+#define PATH_SEP '\\'
+#else /* crapintosh? */
+#define PATH_SEP ':'
+#endif
+
+extern void osd_loginit(void);
+extern void osd_logshutdown(void);
+extern void osd_logprint(const char *string);
+
+extern int osd_startsound(void (*playfunc)(void *buffer, int size));
+extern int osd_getsoundbps(void);
+extern int osd_getsamplerate(void);
+
+
+#ifndef NSF_PLAYER
+#include "rgb.h"
+#include "bitmap.h"
+
+extern bitmap_t *osd_getvidbuf(void);
+typedef void (*blitproc_t)(bitmap_t *bmp, int x_pos, int y_pos, int width, int height);
+extern blitproc_t osd_blit;
+extern void osd_copytoscreen(void);
+
+extern void osd_showusage(char *filename);
+extern void osd_fullname(char *fullname, const char *shortname);
+extern char *osd_newextension(char *string, char *ext);
+
+extern void osd_setpalette(rgb_t *pal);
+extern void osd_restorepalette(void);
+
+extern void osd_getinput(void);
+extern int osd_gethostinput(void);
+extern void osd_getmouse(int *x, int *y, int *button);
+
+extern int osd_init(void);
+extern void osd_shutdown(void);
+#endif /* !NSF_PLAYER */
+
+#endif /* _OSD_H_ */
+
+/*
+** $Log: osd.h,v $
+** Revision 1.2 2003/07/12 12:31:14 mroi
+** - adding support for the Intel compiler icc
+** - general multipass compilation make targets
+**
+** Revision 1.1 2003/01/08 07:04:35 tmmm
+** initial import of Nosefart sources
+**
+** Revision 1.7 2000/07/04 04:45:33 matt
+** moved INLINE define into types.h
+**
+** Revision 1.6 2000/06/29 16:06:18 neil
+** Wrapped DOS-specific headers in an ifdef
+**
+** Revision 1.5 2000/06/09 15:12:25 matt
+** initial revision
+**
+*/
diff --git a/src/libxineadec/nosefart/types.h b/contrib/nosefart/types.h
index 01f196035..01f196035 100644
--- a/src/libxineadec/nosefart/types.h
+++ b/contrib/nosefart/types.h
diff --git a/src/libxineadec/nosefart/version.h b/contrib/nosefart/version.h
index d7dcb2e5d..d7dcb2e5d 100644
--- a/src/libxineadec/nosefart/version.h
+++ b/contrib/nosefart/version.h
diff --git a/src/libxineadec/nosefart/vrc7_snd.c b/contrib/nosefart/vrc7_snd.c
index 42cff0103..42cff0103 100644
--- a/src/libxineadec/nosefart/vrc7_snd.c
+++ b/contrib/nosefart/vrc7_snd.c
diff --git a/src/libxineadec/nosefart/vrc7_snd.h b/contrib/nosefart/vrc7_snd.h
index fd3880b63..fd3880b63 100644
--- a/src/libxineadec/nosefart/vrc7_snd.h
+++ b/contrib/nosefart/vrc7_snd.h
diff --git a/src/libxineadec/nosefart/vrcvisnd.c b/contrib/nosefart/vrcvisnd.c
index b1f26fe52..b1f26fe52 100644
--- a/src/libxineadec/nosefart/vrcvisnd.c
+++ b/contrib/nosefart/vrcvisnd.c
diff --git a/src/libxineadec/nosefart/vrcvisnd.h b/contrib/nosefart/vrcvisnd.h
index 7666fec0c..7666fec0c 100644
--- a/src/libxineadec/nosefart/vrcvisnd.h
+++ b/contrib/nosefart/vrcvisnd.h
diff --git a/debian/changelog b/debian/changelog
index 178f0341a..640044a8e 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+xine-lib (1.2.0~hg-0) unstable; urgency=low
+
+ * Hg snapshot.
+ * Adjust for libxine2.
+
+ -- Darren Salt <linux@youmustbejoking.demon.co.uk> Tue, 17 Apr 2007 16:50:37 +0100
+
xine-lib (1.1.6~hg-0) unstable; urgency=low
* Hg snapshot.
diff --git a/debian/control b/debian/control
index c01e82fa5..fc7bf047c 100644
--- a/debian/control
+++ b/debian/control
@@ -25,7 +25,7 @@ Standards-Version: 3.7.2
Package: libxine-dev
Architecture: any
Section: libdevel
-Depends: libxine1 (= ${Source-Version}), libc6-dev, zlib1g-dev | libz-dev, libslang2-dev | slang1-dev, libfreetype6-dev
+Depends: libxine2 (= ${Source-Version}), libc6-dev, zlib1g-dev | libz-dev, libslang2-dev | slang1-dev, libfreetype6-dev
Conflicts: xine-ui (<< 0.9.10)
Description: the xine video player library, development packages
This contains development files (headers, documentation and the like)
@@ -42,7 +42,7 @@ Description: the xine video player library, development packages
The xine-ui and gxine packages each provide one for your convenience, so
you can just start watching your VCDs ;-)
-Package: libxine1
+Package: libxine2
Architecture: any
Depends: ${shlibs:Depends}
Recommends: ${shlibs:Recommends}
@@ -61,10 +61,10 @@ Description: the xine video/media player library, binary files
The xine-ui and gxine packages each provide one for your convenience, so
you can just start watching your VCDs ;-)
-Package: libxine1-dbg
+Package: libxine2-dbg
Priority: extra
Architecture: any
-Depends: libxine1 (= ${Source-Version})
+Depends: libxine2 (= ${Source-Version})
Description: the xine video/media player library, debug data
This is the xine media player library (libxine).
.
diff --git a/debian/libxine1.install b/debian/libxine1.install
deleted file mode 100644
index 1efbabbea..000000000
--- a/debian/libxine1.install
+++ /dev/null
@@ -1,11 +0,0 @@
-usr/lib/libxine*.so.*
-usr/lib/xine/plugins/*/post/*.so
-usr/lib/xine/plugins/*/*.so
-usr/lib/xine/plugins/*/vidix/*.so
-usr/share/locale
-usr/share/xine
-usr/share/man/man5/xine.5
-usr/share/doc/libxine1/faq/*
-usr/share/doc/libxine1/README*
-usr/share/doc/libxine1/hackersguide/*
-usr/share/bug/libxine1/presubj
diff --git a/debian/libxine2.install b/debian/libxine2.install
new file mode 100644
index 000000000..42f7937c2
--- /dev/null
+++ b/debian/libxine2.install
@@ -0,0 +1,11 @@
+usr/lib/libxine*.so.*
+usr/lib/xine/plugins/*/post/*.so
+usr/lib/xine/plugins/*/*.so
+usr/lib/xine/plugins/*/vidix/*.so
+usr/share/locale
+usr/share/xine-lib
+usr/share/man/man5/xine.5
+usr/share/doc/libxine2/faq/*
+usr/share/doc/libxine2/README*
+usr/share/doc/libxine2/hackersguide/*
+usr/share/bug/libxine2/presubj
diff --git a/debian/reportbug.presubj b/debian/reportbug.presubj
index 229cd9d74..847ff0bad 100644
--- a/debian/reportbug.presubj
+++ b/debian/reportbug.presubj
@@ -21,9 +21,9 @@ with xine-ui, then file the bug against gxine)
Report bugs for xine crashes
============================
-If you report a bug that applications linked against libxine1
+If you report a bug that applications linked against libxine2
(xine-ui, gxine, amarok, totem, etc) segfault, please install the
-packages 'xine-ui' and 'libxine1-dbg', and try to reproduce it with
+packages 'xine-ui' and 'libxine2-dbg', and try to reproduce it with
this command:
> ulimit -c unlimited ; /usr/bin/xine --bug-report <mrl>
diff --git a/debian/rules b/debian/rules
index 395b983e0..5082cc75a 100755
--- a/debian/rules
+++ b/debian/rules
@@ -58,12 +58,15 @@ ifeq (,$(findstring optimize,$(DEB_BUILD_OPTIONS)))
DEB_BUILD_CONFIG_OPTIONS += --build=$(DEB_BUILD_GNU_TYPE)
endif
+# enable SyncFB video output plugin on Linux
+ifeq (linux,$(filter linux,$(subst -, ,$(DEB_BUILD_GNU_TYPE))))
+ DEB_BUILD_CONFIG_OPTIONS += --enable-syncfb
+endif
+
# --mandir - remove after etch released (autoconf >= 2.59c gets it right)
CONFIGURE_FLAGS := --prefix=/usr \
- --mandir=\$${prefix}/share/man \
--with-external-libmad \
--with-external-a52dec \
- --with-external-libdts \
$(DEB_BUILD_CONFIG_OPTIONS) \
CFLAGS="$(CFLAGS)"
@@ -128,10 +131,10 @@ binary-arch: build install
dh_installdocs
dh_installchangelogs -k ChangeLog
dh_link
- dh_strip --dbg-package=libxine1
+ dh_strip --dbg-package=libxine2
dh_compress
dh_fixperms
- dh_makeshlibs -V 'libxine1 (>= 1.1.2-5)'
+ dh_makeshlibs -V 'libxine2 (>= 1.2.0~)'
dh_installdeb
chmod +x debian/shlibdeps.sh
debian/shlibdeps.sh libxine${major}
diff --git a/doc/Doxyfile.in b/doc/Doxyfile.in
new file mode 100644
index 000000000..38d9179c3
--- /dev/null
+++ b/doc/Doxyfile.in
@@ -0,0 +1,1039 @@
+# Doxyfile 1.5.1
+
+# This file describes the settings to be used by the documentation system
+# doxygen (www.doxygen.org) for a project
+#
+# All text after a hash (#) is considered a comment and will be ignored
+# The format is:
+# TAG = value [value, ...]
+# For lists items can also be appended using:
+# TAG += value [value, ...]
+# Values that contain spaces should be placed between quotes (" ")
+
+#---------------------------------------------------------------------------
+# Project related configuration options
+#---------------------------------------------------------------------------
+
+# The PROJECT_NAME tag is a single word (or a sequence of words surrounded
+# by quotes) that should identify the project.
+
+PROJECT_NAME = @PACKAGE@
+
+# The PROJECT_NUMBER tag can be used to enter a project or revision number.
+# This could be handy for archiving the generated documentation or
+# if some version control system is used.
+
+PROJECT_NUMBER = @VERSION@
+
+# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
+# base path where the generated documentation will be put.
+# If a relative path is entered, it will be relative to the location
+# where doxygen was started. If left blank the current directory will be used.
+
+OUTPUT_DIRECTORY = @abs_top_builddir@/doc/api/
+
+# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create
+# 4096 sub-directories (in 2 levels) under the output directory of each output
+# format and will distribute the generated files over these directories.
+# Enabling this option can be useful when feeding doxygen a huge amount of
+# source files, where putting all generated files in the same directory would
+# otherwise cause performance problems for the file system.
+
+CREATE_SUBDIRS = NO
+
+# The OUTPUT_LANGUAGE tag is used to specify the language in which all
+# documentation generated by doxygen is written. Doxygen will use this
+# information to generate all constant output in the proper language.
+# The default language is English, other supported languages are:
+# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional,
+# Croatian, Czech, Danish, Dutch, Finnish, French, German, Greek, Hungarian,
+# Italian, Japanese, Japanese-en (Japanese with English messages), Korean,
+# Korean-en, Lithuanian, Norwegian, Polish, Portuguese, Romanian, Russian,
+# Serbian, Slovak, Slovene, Spanish, Swedish, and Ukrainian.
+
+OUTPUT_LANGUAGE = English
+
+# This tag can be used to specify the encoding used in the generated output.
+# The encoding is not always determined by the language that is chosen,
+# but also whether or not the output is meant for Windows or non-Windows users.
+# In case there is a difference, setting the USE_WINDOWS_ENCODING tag to YES
+# forces the Windows encoding (this is the default for the Windows binary),
+# whereas setting the tag to NO uses a Unix-style encoding (the default for
+# all platforms other than Windows).
+
+USE_WINDOWS_ENCODING = NO
+
+# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will
+# include brief member descriptions after the members that are listed in
+# the file and class documentation (similar to JavaDoc).
+# Set to NO to disable this.
+
+BRIEF_MEMBER_DESC = YES
+
+# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend
+# the brief description of a member or function before the detailed description.
+# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the
+# brief descriptions will be completely suppressed.
+
+REPEAT_BRIEF = YES
+
+# This tag implements a quasi-intelligent brief description abbreviator
+# that is used to form the text in various listings. Each string
+# in this list, if found as the leading text of the brief description, will be
+# stripped from the text and the result after processing the whole list, is
+# used as the annotated text. Otherwise, the brief description is used as-is.
+# If left blank, the following values are used ("$name" is automatically
+# replaced with the name of the entity): "The $name class" "The $name widget"
+# "The $name file" "is" "provides" "specifies" "contains"
+# "represents" "a" "an" "the"
+
+ABBREVIATE_BRIEF =
+
+# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then
+# Doxygen will generate a detailed section even if there is only a brief
+# description.
+
+ALWAYS_DETAILED_SEC = NO
+
+# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all
+# inherited members of a class in the documentation of that class as if those
+# members were ordinary class members. Constructors, destructors and assignment
+# operators of the base classes will not be shown.
+
+INLINE_INHERITED_MEMB = NO
+
+# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full
+# path before files name in the file list and in the header files. If set
+# to NO the shortest path that makes the file name unique will be used.
+
+FULL_PATH_NAMES = YES
+
+# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag
+# can be used to strip a user-defined part of the path. Stripping is
+# only done if one of the specified strings matches the left-hand part of
+# the path. The tag can be used to show relative paths in the file list.
+# If left blank the directory from which doxygen is run is used as the
+# path to strip.
+
+STRIP_FROM_PATH = @top_srcdir@
+
+# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of
+# the path mentioned in the documentation of a class, which tells
+# the reader which header file to include in order to use a class.
+# If left blank only the name of the header file containing the class
+# definition is used. Otherwise one should specify the include paths that
+# are normally passed to the compiler using the -I flag.
+
+STRIP_FROM_INC_PATH =
+
+# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter
+# (but less readable) file names. This can be useful is your file systems
+# doesn't support long names like on DOS, Mac, or CD-ROM.
+
+SHORT_NAMES = NO
+
+# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen
+# will interpret the first line (until the first dot) of a JavaDoc-style
+# comment as the brief description. If set to NO, the JavaDoc
+# comments will behave just like the Qt-style comments (thus requiring an
+# explicit @brief command for a brief description.
+
+JAVADOC_AUTOBRIEF = NO
+
+# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen
+# treat a multi-line C++ special comment block (i.e. a block of //! or ///
+# comments) as a brief description. This used to be the default behaviour.
+# The new default is to treat a multi-line C++ comment block as a detailed
+# description. Set this tag to YES if you prefer the old behaviour instead.
+
+MULTILINE_CPP_IS_BRIEF = NO
+
+# If the DETAILS_AT_TOP tag is set to YES then Doxygen
+# will output the detailed description near the top, like JavaDoc.
+# If set to NO, the detailed description appears after the member
+# documentation.
+
+DETAILS_AT_TOP = NO
+
+# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented
+# member inherits the documentation from any documented member that it
+# re-implements.
+
+INHERIT_DOCS = YES
+
+# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce
+# a new page for each member. If set to NO, the documentation of a member will
+# be part of the file/class/namespace that contains it.
+
+SEPARATE_MEMBER_PAGES = NO
+
+# The TAB_SIZE tag can be used to set the number of spaces in a tab.
+# Doxygen uses this value to replace tabs by spaces in code fragments.
+
+TAB_SIZE = 8
+
+# This tag can be used to specify a number of aliases that acts
+# as commands in the documentation. An alias has the form "name=value".
+# For example adding "sideeffect=\par Side Effects:\n" will allow you to
+# put the command \sideeffect (or @sideeffect) in the documentation, which
+# will result in a user-defined paragraph with heading "Side Effects:".
+# You can put \n's in the value part of an alias to insert newlines.
+
+ALIASES =
+
+# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C
+# sources only. Doxygen will then generate output that is more tailored for C.
+# For instance, some of the names that are used will be different. The list
+# of all members will be omitted, etc.
+
+OPTIMIZE_OUTPUT_FOR_C = YES
+
+# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java
+# sources only. Doxygen will then generate output that is more tailored for Java.
+# For instance, namespaces will be presented as packages, qualified scopes
+# will look different, etc.
+
+OPTIMIZE_OUTPUT_JAVA = NO
+
+# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want to
+# include (a tag file for) the STL sources as input, then you should
+# set this tag to YES in order to let doxygen match functions declarations and
+# definitions whose arguments contain STL classes (e.g. func(std::string); v.s.
+# func(std::string) {}). This also make the inheritance and collaboration
+# diagrams that involve STL classes more complete and accurate.
+
+BUILTIN_STL_SUPPORT = NO
+
+# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC
+# tag is set to YES, then doxygen will reuse the documentation of the first
+# member in the group (if any) for the other members of the group. By default
+# all members of a group must be documented explicitly.
+
+DISTRIBUTE_GROUP_DOC = NO
+
+# Set the SUBGROUPING tag to YES (the default) to allow class member groups of
+# the same type (for instance a group of public functions) to be put as a
+# subgroup of that type (e.g. under the Public Functions section). Set it to
+# NO to prevent subgrouping. Alternatively, this can be done per class using
+# the \nosubgrouping command.
+
+SUBGROUPING = YES
+
+#---------------------------------------------------------------------------
+# Build related configuration options
+#---------------------------------------------------------------------------
+
+# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in
+# documentation are documented, even if no documentation was available.
+# Private class members and static file members will be hidden unless
+# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES
+
+EXTRACT_ALL = YES
+
+# If the EXTRACT_PRIVATE tag is set to YES all private members of a class
+# will be included in the documentation.
+
+EXTRACT_PRIVATE = YES
+
+# If the EXTRACT_STATIC tag is set to YES all static members of a file
+# will be included in the documentation.
+
+EXTRACT_STATIC = YES
+
+# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs)
+# defined locally in source files will be included in the documentation.
+# If set to NO only classes defined in header files are included.
+
+EXTRACT_LOCAL_CLASSES = YES
+
+# This flag is only useful for Objective-C code. When set to YES local
+# methods, which are defined in the implementation section but not in
+# the interface are included in the documentation.
+# If set to NO (the default) only methods in the interface are included.
+
+EXTRACT_LOCAL_METHODS = NO
+
+# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all
+# undocumented members of documented classes, files or namespaces.
+# If set to NO (the default) these members will be included in the
+# various overviews, but no documentation section is generated.
+# This option has no effect if EXTRACT_ALL is enabled.
+
+HIDE_UNDOC_MEMBERS = NO
+
+# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all
+# undocumented classes that are normally visible in the class hierarchy.
+# If set to NO (the default) these classes will be included in the various
+# overviews. This option has no effect if EXTRACT_ALL is enabled.
+
+HIDE_UNDOC_CLASSES = NO
+
+# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all
+# friend (class|struct|union) declarations.
+# If set to NO (the default) these declarations will be included in the
+# documentation.
+
+HIDE_FRIEND_COMPOUNDS = NO
+
+# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any
+# documentation blocks found inside the body of a function.
+# If set to NO (the default) these blocks will be appended to the
+# function's detailed documentation block.
+
+HIDE_IN_BODY_DOCS = NO
+
+# The INTERNAL_DOCS tag determines if documentation
+# that is typed after a \internal command is included. If the tag is set
+# to NO (the default) then the documentation will be excluded.
+# Set it to YES to include the internal documentation.
+
+INTERNAL_DOCS = YES
+
+# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate
+# file names in lower-case letters. If set to YES upper-case letters are also
+# allowed. This is useful if you have classes or files whose names only differ
+# in case and if your file system supports case sensitive file names. Windows
+# and Mac users are advised to set this option to NO.
+
+CASE_SENSE_NAMES = YES
+
+# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen
+# will show members with their full class and namespace scopes in the
+# documentation. If set to YES the scope will be hidden.
+
+HIDE_SCOPE_NAMES = NO
+
+# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen
+# will put a list of the files that are included by a file in the documentation
+# of that file.
+
+SHOW_INCLUDE_FILES = YES
+
+# If the INLINE_INFO tag is set to YES (the default) then a tag [inline]
+# is inserted in the documentation for inline members.
+
+INLINE_INFO = YES
+
+# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen
+# will sort the (detailed) documentation of file and class members
+# alphabetically by member name. If set to NO the members will appear in
+# declaration order.
+
+SORT_MEMBER_DOCS = YES
+
+# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the
+# brief documentation of file, namespace and class members alphabetically
+# by member name. If set to NO (the default) the members will appear in
+# declaration order.
+
+SORT_BRIEF_DOCS = NO
+
+# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be
+# sorted by fully-qualified names, including namespaces. If set to
+# NO (the default), the class list will be sorted only by class name,
+# not including the namespace part.
+# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES.
+# Note: This option applies only to the class list, not to the
+# alphabetical list.
+
+SORT_BY_SCOPE_NAME = NO
+
+# The GENERATE_TODOLIST tag can be used to enable (YES) or
+# disable (NO) the todo list. This list is created by putting \todo
+# commands in the documentation.
+
+GENERATE_TODOLIST = YES
+
+# The GENERATE_TESTLIST tag can be used to enable (YES) or
+# disable (NO) the test list. This list is created by putting \test
+# commands in the documentation.
+
+GENERATE_TESTLIST = YES
+
+# The GENERATE_BUGLIST tag can be used to enable (YES) or
+# disable (NO) the bug list. This list is created by putting \bug
+# commands in the documentation.
+
+GENERATE_BUGLIST = YES
+
+# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or
+# disable (NO) the deprecated list. This list is created by putting
+# \deprecated commands in the documentation.
+
+GENERATE_DEPRECATEDLIST= YES
+
+# The ENABLED_SECTIONS tag can be used to enable conditional
+# documentation sections, marked by \if sectionname ... \endif.
+
+ENABLED_SECTIONS =
+
+# The MAX_INITIALIZER_LINES tag determines the maximum number of lines
+# the initial value of a variable or define consists of for it to appear in
+# the documentation. If the initializer consists of more lines than specified
+# here it will be hidden. Use a value of 0 to hide initializers completely.
+# The appearance of the initializer of individual variables and defines in the
+# documentation can be controlled using \showinitializer or \hideinitializer
+# command in the documentation regardless of this setting.
+
+MAX_INITIALIZER_LINES = 30
+
+# Set the SHOW_USED_FILES tag to NO to disable the list of files generated
+# at the bottom of the documentation of classes and structs. If set to YES the
+# list will mention the files that were used to generate the documentation.
+
+SHOW_USED_FILES = YES
+
+# If the sources in your project are distributed over multiple directories
+# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy
+# in the documentation. The default is NO.
+
+SHOW_DIRECTORIES = NO
+
+# The FILE_VERSION_FILTER tag can be used to specify a program or script that
+# doxygen should invoke to get the current version for each file (typically from the
+# version control system). Doxygen will invoke the program by executing (via
+# popen()) the command <command> <input-file>, where <command> is the value of
+# the FILE_VERSION_FILTER tag, and <input-file> is the name of an input file
+# provided by doxygen. Whatever the program writes to standard output
+# is used as the file version. See the manual for examples.
+
+FILE_VERSION_FILTER =
+
+#---------------------------------------------------------------------------
+# configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+
+# The QUIET tag can be used to turn on/off the messages that are generated
+# by doxygen. Possible values are YES and NO. If left blank NO is used.
+
+QUIET = NO
+
+# The WARNINGS tag can be used to turn on/off the warning messages that are
+# generated by doxygen. Possible values are YES and NO. If left blank
+# NO is used.
+
+WARNINGS = YES
+
+# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings
+# for undocumented members. If EXTRACT_ALL is set to YES then this flag will
+# automatically be disabled.
+
+WARN_IF_UNDOCUMENTED = YES
+
+# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for
+# potential errors in the documentation, such as not documenting some
+# parameters in a documented function, or documenting parameters that
+# don't exist or using markup commands wrongly.
+
+WARN_IF_DOC_ERROR = YES
+
+# This WARN_NO_PARAMDOC option can be abled to get warnings for
+# functions that are documented, but have no documentation for their parameters
+# or return value. If set to NO (the default) doxygen will only warn about
+# wrong or incomplete parameter documentation, but not about the absence of
+# documentation.
+
+WARN_NO_PARAMDOC = NO
+
+# The WARN_FORMAT tag determines the format of the warning messages that
+# doxygen can produce. The string should contain the $file, $line, and $text
+# tags, which will be replaced by the file and line number from which the
+# warning originated and the warning text. Optionally the format may contain
+# $version, which will be replaced by the version of the file (if it could
+# be obtained via FILE_VERSION_FILTER)
+
+WARN_FORMAT = "$file:$line: $text"
+
+# The WARN_LOGFILE tag can be used to specify a file to which warning
+# and error messages should be written. If left blank the output is written
+# to stderr.
+
+WARN_LOGFILE =
+
+#---------------------------------------------------------------------------
+# configuration options related to the input files
+#---------------------------------------------------------------------------
+
+# The INPUT tag can be used to specify the files and/or directories that contain
+# documented source files. You may enter file names like "myfile.cpp" or
+# directories like "/usr/src/myproject". Separate the files or directories
+# with spaces.
+
+INPUT = @abs_top_srcdir@/src @abs_top_builddir@/include
+
+# If the value of the INPUT tag contains directories, you can use the
+# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
+# and *.h) to filter out the source-files in the directories. If left
+# blank the following patterns are tested:
+# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx
+# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py
+
+FILE_PATTERNS =
+
+# The RECURSIVE tag can be used to turn specify whether or not subdirectories
+# should be searched for input files as well. Possible values are YES and NO.
+# If left blank NO is used.
+
+RECURSIVE = YES
+
+# The EXCLUDE tag can be used to specify files and/or directories that should
+# excluded from the INPUT source files. This way you can easily exclude a
+# subdirectory from a directory tree whose root is specified with the INPUT tag.
+
+EXCLUDE =
+
+# The EXCLUDE_SYMLINKS tag can be used select whether or not files or
+# directories that are symbolic links (a Unix filesystem feature) are excluded
+# from the input.
+
+EXCLUDE_SYMLINKS = NO
+
+# If the value of the INPUT tag contains directories, you can use the
+# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
+# certain files from those directories. Note that the wildcards are matched
+# against the file with absolute path, so to exclude all test directories
+# for example use the pattern */test/*
+
+EXCLUDE_PATTERNS = */src/libw32dll/wine/*
+EXCLUDE_PATTERNS += */src/input/libdvdnav/*
+EXCLUDE_PATTERNS += */src/input/vcd/libcdio/*
+EXCLUDE_PATTERNS += */src/input/vcd/libvcd/*
+EXCLUDE_PATTERNS += */src/libxineadec/nosefart/*
+EXCLUDE_PATTERNS += */src/libxineadec/gsm610/*
+
+# The EXAMPLE_PATH tag can be used to specify one or more files or
+# directories that contain example code fragments that are included (see
+# the \include command).
+
+EXAMPLE_PATH =
+
+# If the value of the EXAMPLE_PATH tag contains directories, you can use the
+# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
+# and *.h) to filter out the source-files in the directories. If left
+# blank all files are included.
+
+EXAMPLE_PATTERNS =
+
+# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be
+# searched for input files to be used with the \include or \dontinclude
+# commands irrespective of the value of the RECURSIVE tag.
+# Possible values are YES and NO. If left blank NO is used.
+
+EXAMPLE_RECURSIVE = NO
+
+# The IMAGE_PATH tag can be used to specify one or more files or
+# directories that contain image that are included in the documentation (see
+# the \image command).
+
+IMAGE_PATH =
+
+# The INPUT_FILTER tag can be used to specify a program that doxygen should
+# invoke to filter for each input file. Doxygen will invoke the filter program
+# by executing (via popen()) the command <filter> <input-file>, where <filter>
+# is the value of the INPUT_FILTER tag, and <input-file> is the name of an
+# input file. Doxygen will then use the output that the filter program writes
+# to standard output. If FILTER_PATTERNS is specified, this tag will be
+# ignored.
+
+INPUT_FILTER =
+
+# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern
+# basis. Doxygen will compare the file name with each pattern and apply the
+# filter if there is a match. The filters are a list of the form:
+# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further
+# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER
+# is applied to all files.
+
+FILTER_PATTERNS =
+
+# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using
+# INPUT_FILTER) will be used to filter the input files when producing source
+# files to browse (i.e. when SOURCE_BROWSER is set to YES).
+
+FILTER_SOURCE_FILES = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to source browsing
+#---------------------------------------------------------------------------
+
+# If the SOURCE_BROWSER tag is set to YES then a list of source files will
+# be generated. Documented entities will be cross-referenced with these sources.
+# Note: To get rid of all source code in the generated output, make sure also
+# VERBATIM_HEADERS is set to NO.
+
+SOURCE_BROWSER = NO
+
+# Setting the INLINE_SOURCES tag to YES will include the body
+# of functions and classes directly in the documentation.
+
+INLINE_SOURCES = NO
+
+# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct
+# doxygen to hide any special comment blocks from generated source code
+# fragments. Normal C and C++ comments will always remain visible.
+
+STRIP_CODE_COMMENTS = YES
+
+# If the REFERENCED_BY_RELATION tag is set to YES (the default)
+# then for each documented function all documented
+# functions referencing it will be listed.
+
+REFERENCED_BY_RELATION = YES
+
+# If the REFERENCES_RELATION tag is set to YES (the default)
+# then for each documented function all documented entities
+# called/used by that function will be listed.
+
+REFERENCES_RELATION = YES
+
+# If the REFERENCES_LINK_SOURCE tag is set to YES (the default)
+# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from
+# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will
+# link to the source code. Otherwise they will link to the documentstion.
+
+REFERENCES_LINK_SOURCE = YES
+
+# If the USE_HTAGS tag is set to YES then the references to source code
+# will point to the HTML generated by the htags(1) tool instead of doxygen
+# built-in source browser. The htags tool is part of GNU's global source
+# tagging system (see http://www.gnu.org/software/global/global.html). You
+# will need version 4.8.6 or higher.
+
+USE_HTAGS = NO
+
+# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen
+# will generate a verbatim copy of the header file for each class for
+# which an include is specified. Set to NO to disable this.
+
+VERBATIM_HEADERS = YES
+
+#---------------------------------------------------------------------------
+# configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+
+# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index
+# of all compounds will be generated. Enable this if the project
+# contains a lot of classes, structs, unions or interfaces.
+
+ALPHABETICAL_INDEX = NO
+
+# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then
+# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns
+# in which this list will be split (can be a number in the range [1..20])
+
+COLS_IN_ALPHA_INDEX = 5
+
+# In case all classes in a project start with a common prefix, all
+# classes will be put under the same header in the alphabetical index.
+# The IGNORE_PREFIX tag can be used to specify one or more prefixes that
+# should be ignored while generating the index headers.
+
+IGNORE_PREFIX =
+
+#---------------------------------------------------------------------------
+# configuration options related to the HTML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_HTML tag is set to YES (the default) Doxygen will
+# generate HTML output.
+
+GENERATE_HTML = YES
+
+# The HTML_OUTPUT tag is used to specify where the HTML docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `html' will be used as the default path.
+
+HTML_OUTPUT = .
+
+# The HTML_FILE_EXTENSION tag can be used to specify the file extension for
+# each generated HTML page (for example: .htm,.php,.asp). If it is left blank
+# doxygen will generate files with .html extension.
+
+HTML_FILE_EXTENSION = .html
+
+# The HTML_HEADER tag can be used to specify a personal HTML header for
+# each generated HTML page. If it is left blank doxygen will generate a
+# standard header.
+
+HTML_HEADER =
+
+# The HTML_FOOTER tag can be used to specify a personal HTML footer for
+# each generated HTML page. If it is left blank doxygen will generate a
+# standard footer.
+
+HTML_FOOTER =
+
+# The HTML_STYLESHEET tag can be used to specify a user-defined cascading
+# style sheet that is used by each HTML page. It can be used to
+# fine-tune the look of the HTML output. If the tag is left blank doxygen
+# will generate a default style sheet. Note that doxygen will try to copy
+# the style sheet file to the HTML output directory, so don't put your own
+# stylesheet in the HTML output directory as well, or it will be erased!
+
+HTML_STYLESHEET =
+
+# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes,
+# files or namespaces will be aligned in HTML using tables. If set to
+# NO a bullet list will be used.
+
+HTML_ALIGN_MEMBERS = YES
+
+# If the GENERATE_HTMLHELP tag is set to YES, additional index files
+# will be generated that can be used as input for tools like the
+# Microsoft HTML help workshop to generate a compressed HTML help file (.chm)
+# of the generated HTML documentation.
+
+GENERATE_HTMLHELP = NO
+
+# The DISABLE_INDEX tag can be used to turn on/off the condensed index at
+# top of each HTML page. The value NO (the default) enables the index and
+# the value YES disables it.
+
+DISABLE_INDEX = NO
+
+# This tag can be used to set the number of enum values (range [1..20])
+# that doxygen will group on one line in the generated HTML documentation.
+
+ENUM_VALUES_PER_LINE = 4
+
+# If the GENERATE_TREEVIEW tag is set to YES, a side panel will be
+# generated containing a tree-like index structure (just like the one that
+# is generated for HTML Help). For this to work a browser that supports
+# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+,
+# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are
+# probably better off using the HTML help feature.
+
+GENERATE_TREEVIEW = NO
+
+# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be
+# used to set the initial width (in pixels) of the frame in which the tree
+# is shown.
+
+TREEVIEW_WIDTH = 250
+
+#---------------------------------------------------------------------------
+# configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will
+# generate Latex output.
+
+GENERATE_LATEX = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the man page output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_MAN tag is set to YES (the default) Doxygen will
+# generate man pages
+
+GENERATE_MAN = NO
+
+# The MAN_OUTPUT tag is used to specify where the man pages will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `man' will be used as the default path.
+
+MAN_OUTPUT = man
+
+# The MAN_EXTENSION tag determines the extension that is added to
+# the generated man pages (default is the subroutine's section .3)
+
+MAN_EXTENSION = .3
+
+# If the MAN_LINKS tag is set to YES and Doxygen generates man output,
+# then it will generate one additional man file for each entity
+# documented in the real man page(s). These additional files
+# only source the real man page, but without them the man command
+# would be unable to find the correct page. The default is NO.
+
+MAN_LINKS = NO
+
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor
+#---------------------------------------------------------------------------
+
+# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will
+# evaluate all C-preprocessor directives found in the sources and include
+# files.
+
+ENABLE_PREPROCESSING = YES
+
+# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro
+# names in the source code. If set to NO (the default) only conditional
+# compilation will be performed. Macro expansion can be done in a controlled
+# way by setting EXPAND_ONLY_PREDEF to YES.
+
+MACRO_EXPANSION = YES
+
+# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES
+# then the macro expansion is limited to the macros specified with the
+# PREDEFINED and EXPAND_AS_DEFINED tags.
+
+EXPAND_ONLY_PREDEF = NO
+
+# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files
+# in the INCLUDE_PATH (see below) will be search if a #include is found.
+
+SEARCH_INCLUDES = YES
+
+# The INCLUDE_PATH tag can be used to specify one or more directories that
+# contain include files that are not input files but should be processed by
+# the preprocessor.
+
+INCLUDE_PATH =
+
+# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard
+# patterns (like *.h and *.hpp) to filter out the header-files in the
+# directories. If left blank, the patterns specified with FILE_PATTERNS will
+# be used.
+
+INCLUDE_FILE_PATTERNS =
+
+# The PREDEFINED tag can be used to specify one or more macro names that
+# are defined before the preprocessor is started (similar to the -D option of
+# gcc). The argument of the tag is a list of macros of the form: name
+# or name=definition (no spaces). If the definition and the = are
+# omitted =1 is assumed. To prevent a macro definition from being
+# undefined via #undef or recursively expanded use the := operator
+# instead of the = operator.
+
+PREDEFINED = DOXYGEN XINE_COMPILE
+PREDEFINED += XINE_PACKED= ATTR_ALIGN(x)= XINE_PROTECTED=
+PREDEFINED += XINE_MALLOC=
+
+# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
+# this tag can be used to specify a list of macro names that should be expanded.
+# The macro definition that is found in the sources will be used.
+# Use the PREDEFINED tag if you want to use a different macro definition.
+
+EXPAND_AS_DEFINED =
+
+# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then
+# doxygen's preprocessor will remove all function-like macros that are alone
+# on a line, have an all uppercase name, and do not end with a semicolon. Such
+# function macros are typically used for boiler-plate code, and will confuse
+# the parser if not removed.
+
+SKIP_FUNCTION_MACROS = YES
+
+#---------------------------------------------------------------------------
+# Configuration::additions related to external references
+#---------------------------------------------------------------------------
+
+# The TAGFILES option can be used to specify one or more tagfiles.
+# Optionally an initial location of the external documentation
+# can be added for each tagfile. The format of a tag file without
+# this location is as follows:
+# TAGFILES = file1 file2 ...
+# Adding location for the tag files is done as follows:
+# TAGFILES = file1=loc1 "file2 = loc2" ...
+# where "loc1" and "loc2" can be relative or absolute paths or
+# URLs. If a location is present for each tag, the installdox tool
+# does not have to be run to correct the links.
+# Note that each tag file must have a unique name
+# (where the name does NOT include the path)
+# If a tag file is not located in the directory in which doxygen
+# is run, you must also specify the path to the tagfile here.
+
+TAGFILES =
+
+# When a file name is specified after GENERATE_TAGFILE, doxygen will create
+# a tag file that is based on the input files it reads.
+
+GENERATE_TAGFILE =
+
+# If the ALLEXTERNALS tag is set to YES all external classes will be listed
+# in the class index. If set to NO only the inherited external classes
+# will be listed.
+
+ALLEXTERNALS = NO
+
+# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed
+# in the modules index. If set to NO, only the current project's groups will
+# be listed.
+
+EXTERNAL_GROUPS = YES
+
+# The PERL_PATH should be the absolute path and name of the perl script
+# interpreter (i.e. the result of `which perl').
+
+PERL_PATH = /usr/bin/perl
+
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool
+#---------------------------------------------------------------------------
+
+# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will
+# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base
+# or super classes. Setting the tag to NO turns the diagrams off. Note that
+# this option is superseded by the HAVE_DOT option below. This is only a
+# fallback. It is recommended to install and use dot, since it yields more
+# powerful graphs.
+
+CLASS_DIAGRAMS = YES
+
+# If set to YES, the inheritance and collaboration graphs will hide
+# inheritance and usage relations if the target is undocumented
+# or is not a class.
+
+HIDE_UNDOC_RELATIONS = YES
+
+# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is
+# available from the path. This tool is part of Graphviz, a graph visualization
+# toolkit from AT&T and Lucent Bell Labs. The other options in this section
+# have no effect if this option is set to NO (the default)
+
+HAVE_DOT = NO
+
+# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for each documented class showing the direct and
+# indirect inheritance relations. Setting this tag to YES will force the
+# the CLASS_DIAGRAMS tag to NO.
+
+CLASS_GRAPH = YES
+
+# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for each documented class showing the direct and
+# indirect implementation dependencies (inheritance, containment, and
+# class references variables) of the class with other documented classes.
+
+COLLABORATION_GRAPH = YES
+
+# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for groups, showing the direct groups dependencies
+
+GROUP_GRAPHS = YES
+
+# If the UML_LOOK tag is set to YES doxygen will generate inheritance and
+# collaboration diagrams in a style similar to the OMG's Unified Modeling
+# Language.
+
+UML_LOOK = NO
+
+# If set to YES, the inheritance and collaboration graphs will show the
+# relations between templates and their instances.
+
+TEMPLATE_RELATIONS = NO
+
+# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT
+# tags are set to YES then doxygen will generate a graph for each documented
+# file showing the direct and indirect include dependencies of the file with
+# other documented files.
+
+INCLUDE_GRAPH = YES
+
+# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and
+# HAVE_DOT tags are set to YES then doxygen will generate a graph for each
+# documented header file showing the documented files that directly or
+# indirectly include this file.
+
+INCLUDED_BY_GRAPH = YES
+
+# If the CALL_GRAPH and HAVE_DOT tags are set to YES then doxygen will
+# generate a call dependency graph for every global function or class method.
+# Note that enabling this option will significantly increase the time of a run.
+# So in most cases it will be better to enable call graphs for selected
+# functions only using the \callgraph command.
+
+CALL_GRAPH = NO
+
+# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then doxygen will
+# generate a caller dependency graph for every global function or class method.
+# Note that enabling this option will significantly increase the time of a run.
+# So in most cases it will be better to enable caller graphs for selected
+# functions only using the \callergraph command.
+
+CALLER_GRAPH = NO
+
+# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen
+# will graphical hierarchy of all classes instead of a textual one.
+
+GRAPHICAL_HIERARCHY = YES
+
+# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES
+# then doxygen will show the dependencies a directory has on other directories
+# in a graphical way. The dependency relations are determined by the #include
+# relations between the files in the directories.
+
+DIRECTORY_GRAPH = YES
+
+# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images
+# generated by dot. Possible values are png, jpg, or gif
+# If left blank png will be used.
+
+DOT_IMAGE_FORMAT = png
+
+# The tag DOT_PATH can be used to specify the path where the dot tool can be
+# found. If left blank, it is assumed the dot tool can be found in the path.
+
+DOT_PATH =
+
+# The DOTFILE_DIRS tag can be used to specify one or more directories that
+# contain dot files that are included in the documentation (see the
+# \dotfile command).
+
+DOTFILE_DIRS =
+
+# The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width
+# (in pixels) of the graphs generated by dot. If a graph becomes larger than
+# this value, doxygen will try to truncate the graph, so that it fits within
+# the specified constraint. Beware that most browsers cannot cope with very
+# large images.
+
+MAX_DOT_GRAPH_WIDTH = 1024
+
+# The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height
+# (in pixels) of the graphs generated by dot. If a graph becomes larger than
+# this value, doxygen will try to truncate the graph, so that it fits within
+# the specified constraint. Beware that most browsers cannot cope with very
+# large images.
+
+MAX_DOT_GRAPH_HEIGHT = 1024
+
+# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the
+# graphs generated by dot. A depth value of 3 means that only nodes reachable
+# from the root by following a path via at most 3 edges will be shown. Nodes
+# that lay further from the root node will be omitted. Note that setting this
+# option to 1 or 2 may greatly reduce the computation time needed for large
+# code bases. Also note that a graph may be further truncated if the graph's
+# image dimensions are not sufficient to fit the graph (see MAX_DOT_GRAPH_WIDTH
+# and MAX_DOT_GRAPH_HEIGHT). If 0 is used for the depth value (the default),
+# the graph is not depth-constrained.
+
+MAX_DOT_GRAPH_DEPTH = 0
+
+# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent
+# background. This is disabled by default, which results in a white background.
+# Warning: Depending on the platform used, enabling this option may lead to
+# badly anti-aliased labels on the edges of a graph (i.e. they become hard to
+# read).
+
+DOT_TRANSPARENT = NO
+
+# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output
+# files in one run (i.e. multiple -o and -T options on the command line). This
+# makes dot run faster, but since only newer versions of dot (>1.8.10)
+# support this, this feature is disabled by default.
+
+DOT_MULTI_TARGETS = NO
+
+# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will
+# generate a legend page explaining the meaning of the various boxes and
+# arrows in the dot generated graphs.
+
+GENERATE_LEGEND = YES
+
+# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will
+# remove the intermediate dot files that are used to generate
+# the various graphs.
+
+DOT_CLEANUP = YES
+
+#---------------------------------------------------------------------------
+# Configuration::additions related to the search engine
+#---------------------------------------------------------------------------
+
+# The SEARCHENGINE tag specifies whether or not a search engine should be
+# used. If set to NO the values of all tags below this one will be ignored.
+
+SEARCHENGINE = NO
diff --git a/doc/Makefile.am b/doc/Makefile.am
index 1a757a4ca..c456d8438 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -5,7 +5,7 @@ SUBDIRS = man hackersguide faq
doc_DATA = README README.dvb README.dxr3 \
README.freebsd README.irix README.network_dvd README.opengl \
README.solaris README.syncfb README_xxmc.html README.MINGWCROSS \
- README.WIN32
+ README.WIN32 README.macosx
EXTRA_DIST = $(doc_DATA)
diff --git a/doc/README b/doc/README
index 56d133a70..2674a0869 100644
--- a/doc/README
+++ b/doc/README
@@ -29,6 +29,9 @@ README.freebsd
README.irix
hints on running xine on IRIX
+README.macosx
+ hints on building xine on Mac OS X
+
README.network_dvd
how to play DVDs / Audio CDs over the network
diff --git a/doc/README.dvb b/doc/README.dvb
index c04013330..9de8295aa 100644
--- a/doc/README.dvb
+++ b/doc/README.dvb
@@ -49,7 +49,7 @@ install a channel list
xine's dvb input plugin needs a channel/transponder list that fits your
dvb equipment. xine now uses the channels.conf format of szap, czap and
tzap as appropriate for DVB-S, DVB-C and DVB-T. it will search the channel
-list file in ~/.xine/channels.conf
+list file in ~/.config/xine/channels.conf
channel list format for DVB-S: (satellite)
-------------------------------------------
@@ -72,11 +72,11 @@ which comes with the dvb package. compile it using something like
then start scanning
-# scan >~/.xine/channels.conf
+# scan >~/.config/xine/channels.conf
newer versions of scan (after July 2004) are called dvbscan, but you can use it much the same way:
-# dvbscan Hotbird-13.0 >~/.xine/channels.conf
+# dvbscan Hotbird-13.0 >~/.config/xine/channels.conf
this can take a while. in a DiSEqC environment, use the -s N switch to select
different sattelites to scan and paste the results in one big channels.conf file. As always,
diff --git a/doc/README.macosx b/doc/README.macosx
new file mode 100644
index 000000000..02c98c8d9
--- /dev/null
+++ b/doc/README.macosx
@@ -0,0 +1,141 @@
+Building
+--------
+Mac OS X builds of xine-lib are built using the same autoconf-based build
+scripts that are used on other Unix-based platforms (e.g., Linux, FreeBSD).
+There is no Xcode project, nor is there any intention to create and/or
+maintain one in the future. There's no good reason, and it would only add
+unnecessary complexity and an additional maintenance burden.
+
+Currently, xine-lib is only supported on Mac OS X 10.4 Tiger. There are no
+plans to support older versions of Mac OS X for a variety of reasons.
+
+As of xine-lib 1.2, specific versions of build tools are required. They are
+as follows:
+
+ - GNU M4 1.4.7 (1.4.9 is current, 1.4.2 is installed on Tiger)
+ - autoconf 2.59 (2.61 is current, 2.59 is installed on Tiger)
+ - automake 1.9 (1.10 is current, 1.6.3 is installed on Tiger)
+ - GNU libtool 1.5.20 (1.5.22 is current, 1.5 is installed on Tiger)
+
+When building on Tiger, since some of the system-installed tools are out of
+date, you'll need to update at least some of them. It is recommended that you
+bring all of them up to current releases as listed above.
+
+The order in which you install updated tools to replace the system-installed
+versions is important, and in some cases, specific build options are required
+for them to work properly.
+
+ 1. Install GNU M4 >= 1.4.7
+ - This is optional if you use the system-installed version of autoconf;
+ however, if you install a newer version of autoconf, you MUST install
+ a newer version of GNU M4 first.
+ - Run its configure script with --program-prefix=g
+ 2. Install autoconf >= 2.59
+ - This is optional, but it is recommended that you use autoconf 2.61.
+ - No special configure options are required. Simply configure, make, and
+ make install.
+ 3. Install automake >= 1.9
+ - This is required, and since it is required, it is recommended that you
+ use automake 1.10.
+ - No special configure options are required. Simply configure, make, and
+ make install.
+ 4. Install GNU libtool >= 1.5.20
+ - This is required, and since it is required, it is recommended that you
+ use GNU libtool 1.5.22.
+ - Run its configure script with --program-prefix=g
+
+ ** A special note about GNU libtool:
+ Mac OS X has its own utility called libtool that is NOT the same as GNU
+ libtool, but the Developer tools install GNU libtool as well. The system-
+ installed version of GNU libtool is installed with a g- prefix, and xine's
+ build scripts expect this as well if you install your own version. If you
+ do not install GNU libtool with a g- prefix, xine's build scripts will
+ pick up the system-installed version instead of the newer one you install!
+
+With your tool chain brought up-to-date with xine's requirements, you can go
+ahead and build xine-lib by first running configure, then make, and finally,
+make install, just as you would on, say, Linux. If you are building from a
+source repository snapshot or checkout, you will need to run autogen.sh first.
+
+When running configure, it's best if you do not attempt to forcibly enable most
+options that are disabled by default. For example, DVB support is disabled by
+default on Mac OS X because it doesn't work. Enabling it may allow it to build
+okay, but it will not work at runtime.
+
+The one exception is --enable-macosx-universal. Universal binaries are not
+enabled by default, but they are fully supported. With this optional enabled,
+the default is to build FAT binaries for ppc and i386; however, you may also
+enable support for ppc64 and/or x86_64. For example:
+
+ ./configure --enable-macosx-universal=i386,ppc,x86_64,ppc64
+
+CoreAudio audio output support will be enabled by default. Mac OS X video
+output support will be enabled by default. Xwindows support will be enabled
+by default for video output (using XShm, Xv, and OpenGL). In most cases,
+you'll probably want to disable Xwindows support, and that is safe to do by
+adding --without-x to the configure command-line.
+
+Running
+-------
+Very limited run-time testing has been done so far. The Mac OS X port of
+xine-lib is in its early stages, only recently becoming buildable at all,
+though some quick-and-dirty efforts have been made in the past to build and
+run on Mac OS X.
+
+At this time, native video output only works with Objective-C Cocoa windows
+using the XineOpenGLView class that resides in libxineMacOSXVideo.dylib. This
+works, but it isn't yet stable enough for every day use. Xwindows video output
+support builds, but it is unknown whether it works. If you plan on using the
+Cocoa video output support, you'll need to link with both libxine.dylib and
+libxineMacOSXVideo.dylib as well as libxine.dylib.
+
+Instantiate an audio output port as follows:
+
+ ao_port = xine_open_audio_driver(xine_instance, "coreaudio", NULL);
+
+Instantiate a video output port as follows:
+
+ vo_port = xine_open_video_driver(xine_instance, "macosx",
+ XINE_VISUAL_TYPE_MACOSX, view);
+
+In both cases, xine_instance is the return from xine_new() that has been then
+been initialized with xine_init(). For video output, the view argument to
+xine_open_video_driver() is the XineOpenGLView instance in which to render.
+
+The Future
+----------
+A full, proper port of xine-lib to Mac OS X is in progress. Efforts are under
+way to make as many of the various plug-ins work properly on Mac OS X as makes
+sense, but it is unlikely that full support will be complete by the time that
+xine-lib 1.2 is released.
+
+The following is a list of the things that will definitely be done:
+
+ * CoreVideo support for video output instead of the current NSOpenGLView-
+ based video output plug-in. The existing video output plugin will not be
+ retained as a plug-in, but the code will remain available based on the new
+ CoreVideo video output plugin.
+ * Building xine-lib as an application bundle embeddable framework, as well as
+ a system-wide installable framework, though the utility of the latter is
+ questionable.
+ * Enable VCD input support. Mac OS X specific code is required in xine-lib
+ itself to support this. Currently, only FreeBSD, Linux, and Solaris can
+ build the VCD input plugin.
+ * Investigate enabling Real binary and Win32 binary support for Intel Macs.
+ * Investigate better font support without the need for FreeType2.
+ * SPDIF pass-through for CoreAudio
+
+Known Issues
+------------
+ * Building on Leopard does not work due to build problems with ffmpeg.
+ * VCD support is not yet available, though internal versions of libcdio and
+ libvcd will build. If you enable VCD at configure time, the build WILL
+ fail.
+ * Real binary codec support is not yet available.
+ * On Intel, Win32 binary codec support is not yet available.
+ * Very little run-time testing has been done. Basic file input and ffmpeg
+ based demux/decoding is known to work.
+ * Xwindows support builds, but it has not been tested at all.
+ * Applications using xine-lib must link with both libxine.dylib and
+ libxineMacOSXVideo.dylib if they will be using the Cocoa video output
+ support.
diff --git a/doc/faq/faq.sgml b/doc/faq/faq.sgml
index 9743cf361..db1762f51 100644
--- a/doc/faq/faq.sgml
+++ b/doc/faq/faq.sgml
@@ -1316,7 +1316,8 @@
You can do this either in the config dialog while xine is running (press
the config button on the xine panel and go to the AUDIO tab) or have it
the complicated way by editing the config file yourself which is located
- in your home directory in <filename>.gxine</filename> or <filename>.xine</filename>:
+ in your home directory in <filename>.config/gxine</filename> or
+ <filename>.xine</filename>:
<programlisting>
&nbsp;&nbsp;&nbsp;audio.output.speaker_arrangement:Surround 4.0
&nbsp;&nbsp;&nbsp;audio.output.speaker_arrangement:Surround 4.1
@@ -1329,8 +1330,8 @@
<para>
xine can do that too. Pretty much the same story as for 4-/5-channel
surround (see above). You can either use the config dialog or edit
- the config file (<filename>~/.xine/config</filename> or <filename>~/.gxine/config</filename>)
- yourself:
+ the config file (<filename>~/.xine/config</filename> or
+ <filename>~/.config/gxine/config</filename>) yourself:
<programlisting>&nbsp;&nbsp;&nbsp;audio.output.speaker_arrangement:Pass Through</programlisting>
</para>
</sect2>
@@ -1858,8 +1859,8 @@
</para>
<para>
Unscaled OSD usage by subtitles and xine-ui is controlled by
- the following settings
- (<filename>~/.xine/config</filename> or <filename>~/.gxine/config</filename>):
+ the following settings (<filename>~/.xine/config</filename> or
+ <filename>~/.config/gxine/config</filename>):
<programlisting>&nbsp;&nbsp;&nbsp;gui.osd_use_unscaled:0</programlisting>
<programlisting>&nbsp;&nbsp;&nbsp;subtitles.separate.use_unscaled_osd:0</programlisting>
</para>
diff --git a/doc/man/en/xine.5 b/doc/man/en/xine.5
index 3457af8a5..acf1b5109 100644
--- a/doc/man/en/xine.5
+++ b/doc/man/en/xine.5
@@ -190,7 +190,8 @@ Play entry 0 of /tmp/ntsc.nrg (Nero file). Works for some simple Nero images.
.br
.SS DVB
.PP
-DVB MRLs require that ~/.xine/channels.conf exists and contains valid data.
+DVB MRLs require that xine-lib/channels.conf exists in $XDG_CONFIG_HOME/ or
+~/.config/ and contains valid data.
This can be obtained by generating a tuning file using the LinuxTV DVB apps
utility "scan" (or "dvbscan" if you're using a version newer than 1.1.0):
.PP
diff --git a/include/Makefile.am b/include/Makefile.am
index 97d82e063..621bd423c 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -8,12 +8,6 @@ include_HEADERS = xine.h
CONFIG_CLEAN_FILES = xine.h $(inttypes_h)
-debug:
- @$(MAKE) CFLAGS="$(DEBUG_CFLAGS)"
-
-install-debug: debug
- @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
-
mostlyclean-generic:
-rm -f *~ \#* .*~ .\#*
diff --git a/include/xine.h.in b/include/xine.h.in
index f25038796..8425cc17d 100644
--- a/include/xine.h.in
+++ b/include/xine.h.in
@@ -466,17 +466,17 @@ typedef struct {
int64_t vpts; /* timestamp 1/90000 sec for a/v sync */
int64_t duration;
+ double aspect_ratio;
int width, height;
int colorspace; /* XINE_IMGFMT_* */
- double aspect_ratio;
int pos_stream; /* bytes from stream start */
int pos_time; /* milliseconds */
+ int frame_number; /* frame number (may be unknown) */
+
uint8_t *data;
void *xine_frame; /* used internally by xine engine */
-
- int frame_number; /* frame number (may be unknown) */
} xine_video_frame_t;
int xine_get_next_video_frame (xine_video_port_t *port,
@@ -494,11 +494,11 @@ typedef struct {
int num_channels;
int bits_per_sample; /* per channel */
- off_t pos_stream; /* bytes from stream start */
- int pos_time; /* milliseconds */
-
uint8_t *data;
void *xine_frame; /* used internally by xine engine */
+
+ off_t pos_stream; /* bytes from stream start */
+ int pos_time; /* milliseconds */
} xine_audio_frame_t;
int xine_get_next_audio_frame (xine_audio_port_t *port,
@@ -596,13 +596,13 @@ struct xine_post_in_s {
/* the name identifying this input */
const char *name;
- /* the datatype of this input, use one of XINE_POST_DATA_* here */
- int type;
-
/* the data pointer; input is directed to this memory location,
* so you simply access the pointer to access the input data */
void *data;
+ /* the datatype of this input, use one of XINE_POST_DATA_* here */
+ int type;
+
};
struct xine_post_out_s {
@@ -610,9 +610,6 @@ struct xine_post_out_s {
/* the name identifying this output */
const char *name;
- /* the datatype of this output, use one of XINE_POST_DATA_* here */
- int type;
-
/* the data pointer; output should be directed to this memory location,
* so in the easy case you simply write through the pointer */
void *data;
@@ -628,6 +625,9 @@ struct xine_post_out_s {
* if you do not implement rewiring, set this to NULL */
int (*rewire) (xine_post_out_t *self, void *data);
+ /* the datatype of this output, use one of XINE_POST_DATA_* here */
+ int type;
+
};
/* get a list of all inputs of a post plugin */
@@ -962,8 +962,8 @@ typedef struct {
char *origin; /* file plugin: path */
char *mrl; /* <type>://<location> */
char *link;
- uint32_t type; /* see below */
off_t size; /* size of this source, may be 0 */
+ uint32_t type; /* see below */
} xine_mrl_t;
/* mrl types */
@@ -1358,12 +1358,12 @@ typedef struct {
#define CHECK_XV 6
struct xine_health_check_s {
- int status;
const char* cdrom_dev;
const char* dvd_dev;
char* msg;
char* title;
char* explanation;
+ int status;
};
typedef struct xine_health_check_s xine_health_check_t;
@@ -1400,6 +1400,11 @@ struct xine_cfg_entry_s {
int type;
+ /* user experience level */
+ int exp_level; /* 0 => beginner,
+ 10 => advanced user,
+ 20 => expert */
+
/* type unknown */
char *unknown_value;
@@ -1433,11 +1438,6 @@ struct xine_cfg_entry_s {
const char *description;
const char *help;
- /* user experience level */
- int exp_level; /* 0 => beginner,
- 10 => advanced user,
- 20 => expert */
-
/* callback function and data for live changeable values */
/* some config entries will take effect immediately, although they
* do not have a callback registered; such values will have some
@@ -1668,12 +1668,13 @@ void xine_config_reset (xine_t *self) XINE_PROTECTED;
* xine event struct
*/
typedef struct {
- int type; /* event type (constants see above) */
xine_stream_t *stream; /* stream this event belongs to */
void *data; /* contents depending on type */
int data_length;
+ int type; /* event type (constants see above) */
+
/* you do not have to provide this, it will be filled in by xine_event_send() */
struct timeval tv; /* timestamp of event creation */
} xine_event_t;
@@ -1931,6 +1932,7 @@ typedef struct {
#define XINE_MSG_AUDIO_OUT_UNAVAILABLE 11 /* none */
#define XINE_MSG_PERMISSION_ERROR 12 /* (file name or mrl) */
#define XINE_MSG_FILE_EMPTY 13 /* file is empty */
+#define XINE_MSG_AUTHENTICATION_NEEDED 14 /* (mrl, likely http) */
/* opaque xine_event_queue_t */
typedef struct xine_event_queue_s xine_event_queue_t;
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 36b695bc8..c6462037e 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -1,5 +1,7 @@
include $(top_srcdir)/misc/Makefile.common
+AM_CFLAGS = $(DEFAULT_OCFLAGS)
+
EXTRA_DIST = Makefile.common
noinst_LTLIBRARIES = libxineposix.la
diff --git a/lib/os_internal.h b/lib/os_internal.h
index dd48e04f7..1e536b9fa 100644
--- a/lib/os_internal.h
+++ b/lib/os_internal.h
@@ -1,6 +1,69 @@
#ifndef _XINE_OS_INTERNAL_H
#define _XINE_OS_INTERNAL_H
+/* When using Apple's GCC, __APPLE__ will be defined. This is a whole lot of
+ * messiness, but it's necessary in order to perform universal builds properly.
+ * It's meant to over-ride configure time stuff that would be different at
+ * compile time.
+ */
+#if defined(__APPLE__) && defined(XINE_MACOSX_UNIVERSAL_BINARY)
+
+/* __ppc__, __ppc64__, __i386__, __x86_64__ are interesting arch macros */
+#undef HOST_ARCH
+#if defined(__ppc__) || defined(__ppc64__)
+#define ARCH_PPC
+#if defined(__ppc64__)
+#define HOST_ARCH "darwin/powerpc64"
+#else
+#define HOST_ARCH "darwin/powerpc"
+#endif
+#elif defined(__i386__) || defined(__x86_64__)
+#define ARCH_X86
+#define BITFIELD_LSBF
+#define HAVE_MMX
+#if defined(__x86_64__)
+#define ARCH_X86_64
+#define HOST_ARCH "darwin/x86_64"
+#elif defined(__i386__)
+#define ARCH_X86_32
+#define HOST_ARCH "darwin/x86_32"
+#else
+#error unrecognized/unsupported CPU type building for Apple Darwin
+#endif
+#endif
+
+/* See /Developer/SDKs/MacOSX10.4u.sdk/usr/include/machine/limits.h */
+#if SIZEOF_INT != 4
+#undef SIZEOF_INT
+#define SIZEOF_INT 4
+#endif
+
+#if defined(__LP64__) && SIZEOF_LONG != 8
+#undef SIZEOF_LONG
+#define SIZEOF_LONG 8
+#elif !defined(__LP64__) && SIZEOF_LONG != 4
+#undef SIZEOF_LONG
+#define SIZEOF_LONG 4
+#endif
+
+/* WORDS_BIGENDIAN (replaces AC_C_BIGENDIAN autoconf test at compile time) */
+#include <machine/endian.h>
+#if BYTE_ORDER == BIG_ENDIAN
+#define WORDS_BIGENDIAN 1
+#else
+#undef WORDS_BIGENDIAN
+#endif
+
+#if defined(__LP64__)
+#define FPM_64BIT 1
+#elif defined(__ppc__) || defined(__ppc64__)
+#define FPM_PPC 1
+#elif defined(__i386__) || defined(__x86_64__)
+#define FPM_INTEL 1
+#endif
+
+#endif /* __APPLE__ */
+
#include <stddef.h>
#include <stdarg.h>
@@ -17,7 +80,7 @@
#endif
#include <inttypes.h>
-
+#include <pthread.h>
#if defined(WIN32) || defined(__CYGWIN__)
# define XINE_PATH_SEPARATOR_STRING ";"
@@ -131,6 +194,13 @@ int xine_private_vasprintf(char **string, const char *format, va_list ap) XINE_F
char *xine_private_strndup(const char *s, size_t n);
#endif
+/* replacement of pthread_mutex_timedlock */
+#ifndef HAVE_PTHREAD_MUTEX_TIMEDLOCK
+#define HAVE_PTHREAD_MUTEX_TIMEDLOCK
+#define pthread_mutex_timedlock(M, T) xine_private_pthread_mutex_timedlock((M), (T))
+int xine_private_pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abs_timeout);
+#endif
+
/* handle non-standard function names */
#if !defined(HAVE_SNPRINTF) && defined(HAVE__SNPRINTF)
# define HAVE_SNPRINTF
diff --git a/lib/timedlock.c b/lib/timedlock.c
new file mode 100644
index 000000000..997ef6235
--- /dev/null
+++ b/lib/timedlock.c
@@ -0,0 +1,33 @@
+#include "config.h"
+
+#include <errno.h>
+
+#define _x_min(a, b) ((a) < (b) ? (a) : (b))
+
+int xine_private_pthread_mutex_timedlock(pthread_mutex_t *mutex,
+ const struct timespec *abs_timeout)
+{
+ int pthread_rc;
+ struct timespec remaining, slept, ts;
+
+ remaining = *abs_timeout;
+ while ((pthread_rc = pthread_mutex_trylock(mutex)) == EBUSY) {
+ ts.tv_sec = 0;
+ ts.tv_nsec = (remaining.tv_sec > 0 ? 10000000
+ : _x_min(remaining.tv_nsec, 10000000));
+ nanosleep(&ts, &slept);
+ ts.tv_nsec -= slept.tv_nsec;
+ if (ts.tv_nsec <= remaining.tv_nsec) {
+ remaining.tv_nsec -= ts.tv_nsec;
+ }
+ else {
+ remaining.tv_sec--;
+ remaining.tv_nsec = (1000000 - (ts.tv_nsec - remaining.tv_nsec));
+ }
+ if (remaining.tv_sec < 0 || (!remaining.tv_sec && remaining.tv_nsec <= 0)) {
+ return ETIMEDOUT;
+ }
+ }
+
+ return pthread_rc;
+}
diff --git a/m4/Makefile.am b/m4/Makefile.am
index 3a5209dc3..068661ebd 100644
--- a/m4/Makefile.am
+++ b/m4/Makefile.am
@@ -1,5 +1,7 @@
include $(top_srcdir)/misc/Makefile.common
+SUBDIRS = gettext
+
if INSTALL_M4
m4datadir = $(ACLOCAL_DIR)
else
@@ -8,29 +10,20 @@ endif
m4data_DATA = xine.m4
-EXTRA_DIST = glibc2.m4 intdiv0.m4 intmax.m4 inttypes.m4 inttypes_h.m4 inttypes-pri.m4 lib-ld.m4 lib-link.m4 lib-prefix.m4 longdouble.m4 longlong.m4 nls.m4 po.m4 printf-posix.m4 signed.m4 size_max.m4 stdint_h.m4 uintmax_t.m4 ulonglong.m4 wchar_t.m4 wint_t.m4 xsize.m4 \
- aa.m4 \
- arts.m4 \
+EXTRA_DIST = \
attributes.m4 \
- codeset.m4 \
+ audio_out.m4 \
+ decoders.m4 \
directx.m4 \
- dl.m4 \
- dvdnav.m4 \
- gettext.m4 \
- glibc21.m4 \
- iconv.m4 \
- irixal.m4 \
- isc-posix.m4 \
- lcmessage.m4 \
- libFLAC.m4 \
- libfame.m4 \
- libtool15.m4 \
- opengl.m4 \
- optimizations.m4 \
+ gas.m4 \
+ input.m4 \
+ macosx.m4 \
+ objc.m4 \
pkg.m4 \
- progtest.m4 \
- xine.m4 \
- _xine.m4 \
- xv.m4 \
+ programs.m4 \
pthreads.m4 \
- gas.m4
+ symbol.m4 \
+ summary.m4 \
+ types.m4 \
+ video_out.m4 \
+ xine.m4
diff --git a/m4/_xine.m4 b/m4/_xine.m4
deleted file mode 100644
index 930703bbb..000000000
--- a/m4/_xine.m4
+++ /dev/null
@@ -1,568 +0,0 @@
-dnl AC_C_ALWAYS_INLINE
-dnl Define inline to something appropriate, including the new always_inline
-dnl attribute from gcc 3.1
-dnl Thanks to Michel LESPINASSE <walken@zoy.org>
-dnl __inline__ "check" added by Darren Salt
-AC_DEFUN([AC_C_ALWAYS_INLINE],
- [AC_C_INLINE
- if test x"$GCC" = x"yes" -a x"$ac_cv_c_inline" = x"inline"; then
- AC_MSG_CHECKING([for always_inline])
- SAVE_CFLAGS="$CFLAGS"
- CFLAGS="$CFLAGS -Wall -Werror"
- AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[inline __attribute__ ((__always_inline__)) void f (void);]])],
- [ac_cv_always_inline=yes],[ac_cv_always_inline=no])
- CFLAGS="$SAVE_CFLAGS"
- AC_MSG_RESULT([$ac_cv_always_inline])
- if test x"$ac_cv_always_inline" = x"yes"; then
- AH_TOP([
-#ifdef inline
-/* the strange formatting below is needed to prevent config.status from rewriting it */
-# undef \
- inline
-#endif
- ])
- AC_DEFINE_UNQUOTED([inline],[inline __attribute__ ((__always_inline__))])
- fi
- ac_cv_c___inline__=''
- else
- # FIXME: test the compiler to see if it supports __inline__
- # instead of assuming that if it isn't gcc, it doesn't
- case "$ac_cv_c_inline" in
- yes)
- ac_cv_c___inline__=inline
- ;;
- inline|__inline__)
- ac_cv_c___inline__=''
- ;;
- *)
- ac_cv_c___inline__="$ac_cv_c_inline"
- ;;
- esac
- fi
- if test x"$ac_cv_c___inline__" != x; then
- AC_DEFINE_UNQUOTED([__inline__],[$ac_cv_c___inline__],[Define if the compiler doesn't recognise __inline__])
- fi
-])
-
-dnl
-dnl Check for minimum version of libtool
-dnl AC_PREREQ_LIBTOOL([MINIMUM VERSION],[ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]])
-AC_DEFUN([AC_PREREQ_LIBTOOL],
- [
- lt_min_full=ifelse([$1], ,1.3.5,$1)
- lt_min=`echo $lt_min_full | sed -e 's/\.//g'`
- AC_MSG_CHECKING(for libtool >= $lt_min_full)
- lt_version="`grep '^VERSION' $srcdir/ltmain.sh | sed -e 's/VERSION\=//g;s/[[-.a-zA-Z]]//g'`"
-
- if test $lt_version -lt 100 ; then
- lt_version=`expr $lt_version \* 10`
- fi
-
- if test $lt_version -lt $lt_min ; then
- AC_MSG_RESULT(no)
- ifelse([$3], , :, [$3])
- fi
- AC_MSG_RESULT(yes)
- ifelse([$2], , :, [$2])
- ])
-
-dnl
-AC_DEFUN([AC_CHECK_LIRC],
- [AC_ARG_ENABLE(lirc,
- AS_HELP_STRING([--disable-lirc], [turn off LIRC support]),
- enable_lirc=$enableval, enable_lirc=yes)
-
- if test x"$enable_lirc" = xyes; then
- have_lirc=yes
- AC_REQUIRE_CPP
- AC_CHECK_LIB(lirc_client,lirc_init,
- AC_CHECK_HEADER(lirc/lirc_client.h, true, have_lirc=no), have_lirc=no)
- if test "$have_lirc" = "yes"; then
-
- if test x"$LIRC_PREFIX" != "x"; then
- lirc_libprefix="$LIRC_PREFIX/lib"
- LIRC_INCLUDE="-I$LIRC_PREFIX/include"
- fi
- for llirc in $lirc_libprefix /lib /usr/lib /usr/local/lib; do
- AC_CHECK_FILE("$llirc/liblirc_client.a",
- LIRC_LIBS="$llirc/liblirc_client.a"
- AC_DEFINE(HAVE_LIRC),,)
- done
- else
- AC_MSG_RESULT([*** LIRC client support not available, LIRC support will be disabled ***]);
- fi
- fi
-
- AC_SUBST(LIRC_LIBS)
- AC_SUBST(LIRC_INCLUDE)
-])
-
-
-dnl AC_LINUX_PATH(DEFAULT PATH)
-AC_DEFUN([AC_LINUX_PATH],
- [AC_ARG_WITH(linux-path,
- AS_HELP_STRING([--with-linux-path=PATH], [where the linux sources are located]),
- linux_path="$withval", linux_path="$1")
- LINUX_INCLUDE="-I$linux_path/include"
-])
-
-dnl AC_CHECK_DXR3()
-AC_DEFUN([AC_CHECK_DXR3],
-[
- AC_ARG_ENABLE(dxr3,
- AS_HELP_STRING([--disable-dxr3], [do not build the DXR3/HW+ plugins]),
- enable_dxr3=$enableval, enable_dxr3=yes)
- if test x"$enable_dxr3" = xyes; then
- have_dxr3=yes
- AC_MSG_RESULT([*** checking for a supported mpeg encoder])
- have_encoder=no
- have_libfame=yes
- AC_CHECK_LIB(fame, fame_open,
- [AC_CHECK_HEADER(fame.h, true, have_libfame=no)], have_libfame=no)
- if test "$have_libfame" = "yes"; then
- AC_DEFINE(HAVE_LIBFAME)
- have_encoder=yes
- fi
- have_librte=yes
- AC_CHECK_LIB(rte, rte_init,
- [AC_CHECK_HEADER(rte.h, true, have_librte=no)], have_librte=no)
- if test "$have_librte" = "yes"; then
- AC_DEFINE(HAVE_LIBRTE)
- AC_MSG_WARN([this will probably only work with rte version 0.4!])
- have_encoder=yes
- fi
- if test "$have_encoder" = "yes"; then
- AC_MSG_RESULT([*** found one or more external mpeg encoders]);
- else
- AC_MSG_RESULT([*** no external mpeg encoder found]);
- fi
- else
- AC_MSG_RESULT([DXR3 plugins will not be built.])
- have_dxr3=no
- fi
-])
-
-dnl AC_TRY_CFLAGS (CFLAGS, [ACTION-IF-WORKS], [ACTION-IF-FAILS])
-dnl check if $CC supports a given set of cflags
-AC_DEFUN([AC_TRY_CFLAGS],
- [AC_MSG_CHECKING([if $CC supports $1 flags])
- SAVE_CFLAGS="$CFLAGS"
- CFLAGS="$1"
- AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],[ac_cv_try_cflags_ok=yes],[ac_cv_try_cflags_ok=no])
- CFLAGS="$SAVE_CFLAGS"
- AC_MSG_RESULT([$ac_cv_try_cflags_ok])
- if test x"$ac_cv_try_cflags_ok" = x"yes"; then
- ifelse([$2],[],[:],[$2])
- else
- ifelse([$3],[],[:],[$3])
- fi])
-
-dnl AC_TRY_LDFLAGS (CFLAGS, [ACTION-IF-WORKS], [ACTION-IF-FAILS])
-dnl check if $CC supports a given set of ldflags
-AC_DEFUN([AC_TRY_LDFLAGS],
- [AC_MSG_CHECKING([if $CC supports $1 flags])
- SAVE_LDFLAGS="$LDFLAGS"
- LDFLAGS="$1"
- AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],[ac_cv_try_ldflags_ok=yes],[ac_cv_try_ldflags_ok=no])
- LDFLAGS="$SAVE_LDFLAGS"
- AC_MSG_RESULT([$ac_cv_try_ldflags_ok])
- if test x"$ac_cv_try_ldflags_ok" = x"yes"; then
- ifelse([$2],[],[:],[$2])
- else
- ifelse([$3],[],[:],[$3])
- fi])
-
-dnl AC_CHECK_GENERATE_INTTYPES_H (INCLUDE-DIRECTORY)
-dnl generate a default inttypes.h if the header file does not exist already
-AC_DEFUN([AC_CHECK_GENERATE_INTTYPES],
- [AC_CHECK_HEADER([inttypes.h],,
- [if test ! -d $1; then mkdir $1; fi
- AC_CHECK_HEADER([stdint.h],
- [cat >$1/inttypes.h << EOF
-#ifndef _INTTYPES_H
-#define _INTTYPES_H
-/* helper inttypes.h for people who do not have it on their system */
-
-#include <stdint.h>
-EOF
- ],
- [AC_COMPILE_CHECK_SIZEOF([char],[1])
- AC_COMPILE_CHECK_SIZEOF([short],[2])
- AC_COMPILE_CHECK_SIZEOF([int],[4])
- AC_COMPILE_CHECK_SIZEOF([long long],[8])
- cat >$1/inttypes.h << EOF
-#ifndef _INTTYPES_H
-#define _INTTYPES_H
-/* default inttypes.h for people who do not have it on their system */
-#if (!defined __int8_t_defined) && (!defined __BIT_TYPES_DEFINED__)
-#define __int8_t_defined
-typedef signed char int8_t;
-typedef signed short int16_t;
-typedef signed int int32_t;
-#ifdef ARCH_X86
-typedef signed long long int64_t;
-#endif
-#endif
-#if (!defined __uint8_t_defined) && (!defined _LINUX_TYPES_H)
-#define __uint8_t_defined
-typedef unsigned char uint8_t;
-typedef unsigned short uint16_t;
-typedef unsigned int uint32_t;
-#ifdef ARCH_X86
-typedef unsigned long long uint64_t;
-#endif
-#endif
-EOF
- ])
- cat >>$1/inttypes.h << EOF
-
-#ifdef WIN32
-# define PRI64_PREFIX "I64"
-#else
-# define PRI64_PREFIX "l"
-#endif
-
-#ifndef PRId8
-# define PRId8 "d"
-#endif
-#ifndef PRId16
-# define PRId16 "d"
-#endif
-#ifndef PRId32
-# define PRId32 "d"
-#endif
-#ifndef PRId64
-# define PRId64 PRI64_PREFIX "d"
-#endif
-
-#ifndef PRIu8
-# define PRIu8 "u"
-#endif
-#ifndef PRIu16
-# define PRIu16 "u"
-#endif
-#ifndef PRIu32
-# define PRIu32 "u"
-#endif
-#ifndef PRIu64
-# define PRIu64 PRI64_PREFIX "u"
-#endif
-
-#ifndef PRIx8
-# define PRIx8 "x"
-#endif
-#ifndef PRIx16
-# define PRIx16 "x"
-#endif
-#ifndef PRIx32
-# define PRIx32 "x"
-#endif
-#ifndef PRIx64
-# define PRIx64 PRI64_PREFIX "x"
-#endif
-
-#ifndef PRIX8
-# define PRIX8 "X"
-#endif
-#ifndef PRIX16
-# define PRIX16 "X"
-#endif
-#ifndef PRIX32
-# define PRIX32 "X"
-#endif
-#ifndef PRIX64
-# define PRIX64 PRI64_PREFIX "X"
-#endif
-
-#ifndef PRIdFAST8
-# define PRIdFAST8 "d"
-#endif
-#ifndef PRIdFAST16
-# define PRIdFAST16 "d"
-#endif
-#ifndef PRIdFAST32
-# define PRIdFAST32 "d"
-#endif
-#ifndef PRIdFAST64
-# define PRIdFAST64 "d"
-#endif
-
-#ifndef PRIuFAST8
-# define PRIuFAST8 "u"
-#endif
-#ifndef PRIuFAST16
-# define PRIuFAST16 "u"
-#endif
-#ifndef PRIuFAST32
-# define PRIuFAST32 "u"
-#endif
-#ifndef PRIuFAST64
-# define PRIuFAST64 PRI64_PREFIX "u"
-#endif
-
-#ifndef PRIxFAST8
-# define PRIxFAST8 "x"
-#endif
-#ifndef PRIxFAST16
-# define PRIxFAST16 "x"
-#endif
-#ifndef PRIxFAST32
-# define PRIxFAST32 "x"
-#endif
-#ifndef PRIxFAST64
-# define PRIxFAST64 PRI64_PREFIX "x"
-#endif
-
-#ifndef SCNd8
-# define SCNd8 "hhd"
-#endif
-#ifndef SCNd16
-# define SCNd16 "hd"
-#endif
-#ifndef SCNd32
-# define SCNd32 "d"
-#endif
-#ifndef SCNd64
-# define SCNd64 PRI64_PREFIX "d"
-#endif
-
-#ifndef SCNu8
-# define SCNu8 "hhu"
-#endif
-#ifndef SCNu16
-# define SCNu16 "hu"
-#endif
-#ifndef SCNu32
-# define SCNu32 "u"
-#endif
-#ifndef SCNu64
-# define SCNu64 PRI64_PREFIX "u"
-#endif
-
-#ifndef PRIdMAX
-# define PRIdMAX PRId64
-#endif
-#ifndef PRIuMAX
-# define PRIuMAX PRIu64
-#endif
-#ifndef PRIxMAX
-# define PRIxMAX PRIx64
-#endif
-#ifndef SCNdMAX
-# define SCNdMAX SCNd64
-#endif
-
-#endif
-EOF
- ])]
-)
-
-
-dnl AC_COMPILE_CHECK_SIZEOF (TYPE SUPPOSED-SIZE)
-dnl abort if the given type does not have the supposed size
-AC_DEFUN([AC_COMPILE_CHECK_SIZEOF],
- [AC_MSG_CHECKING(that size of $1 is $2)
- AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[switch (0) case 0: case (sizeof ($1) == $2):;]])],[],
- [AC_MSG_ERROR([can not build a default inttypes.h])])
- AC_MSG_RESULT([yes])])
-
-
-dnl AM_CHECK_CDROM_IOCTLS ([ACTION-IF-YES], [ACTION-IF-NO])
-dnl check for CDROM_DRIVE_STATUS in ioctl.h
-AC_DEFUN([AM_CHECK_CDROM_IOCTLS],
- [AC_CACHE_CHECK([if cdrom ioctls are available],
- [am_cv_have_cdrom_ioctls],
- [AC_EGREP_HEADER([CDROM_DRIVE_STATUS],[sys/ioctl.h],
- am_cv_have_cdrom_ioctls=yes,
- [AC_EGREP_HEADER([CDIOCALLOW],[sys/ioctl.h],
- am_cv_have_cdrom_ioctls=yes,
- [AC_EGREP_CPP(we_have_cdrom_ioctls,[
-#include <sys/ioctl.h>
-#ifdef HAVE_SYS_CDIO_H
-# include <sys/cdio.h>
-#endif
-#ifdef HAVE_LINUX_CDROM_H
-# include <linux/cdrom.h>
-#endif
-#if defined(CDROM_DRIVE_STATUS) || defined(CDIOCALLOW) || defined(CDROMCDXA)
- we_have_cdrom_ioctls
-#endif
-],
- am_cv_have_cdrom_ioctls=yes,
- am_cv_have_cdrom_ioctls=no
- )])])])
- have_cdrom_ioctls=$am_cv_have_cdrom_ioctls
- if test "x$have_cdrom_ioctls" = xyes ; then
- ifelse([$1], , :, [$1])
- else
- ifelse([$2], , :, [$2])
- fi
-])
-
-
-dnl AC_CHECK_IP_MREQN
-dnl check for struct ip_mreqn in netinet/in.h
-AC_DEFUN([AC_CHECK_IP_MREQN],
- [AC_CACHE_CHECK([for ip_mreqn], [ac_cv_have_ip_mreqn],
- [AC_EGREP_HEADER([ip_mreqn],
- [netinet/in.h],
- [ac_cv_have_ip_mreqn=yes],
- [ac_cv_have_ip_mreqn=no])])
- if test $ac_cv_have_ip_mreqn = yes; then
- AC_DEFINE([HAVE_IP_MREQN],1,[Define this if you have ip_mreqn in netinet/in.h])
- fi
-])
-
-
-dnl AC_PROG_GMSGFMT_PLURAL
-dnl ----------------------
-dnl Validate the GMSGFMT program found by gettext.m4; reject old versions
-dnl of GNU msgfmt that do not support the "msgid_plural" extension.
-AC_DEFUN([AC_PROG_GMSGFMT_PLURAL],
- [dnl AC_REQUIRE(AM_GNU_GETTEXT)
-
- if test "$GMSGFMT" != ":"; then
- AC_MSG_CHECKING([for plural forms in GNU msgfmt])
-
- changequote(,)dnl We use [ and ] in in .po test input
-
- dnl If the GNU msgfmt does not accept msgid_plural we define it
- dnl as : so that the Makefiles still can work.
- cat >conftest.po <<_ACEOF
-msgid "channel"
-msgid_plural "channels"
-msgstr[0] "canal"
-msgstr[1] "canal"
-
-_ACEOF
- changequote([,])dnl
-
- if $GMSGFMT -o /dev/null conftest.po >/dev/null 2>&1; then
- AC_MSG_RESULT(yes)
- else
- AC_MSG_RESULT(no)
- AC_MSG_RESULT(
- [found GNU msgfmt program is too old, it does not support plural forms; ignore it])
- GMSGFMT=":"
- fi
- rm -f conftest.po
- fi
-])dnl AC_PROG_GMSGFMT_PLURAL
-
-
-# AC_PROG_LIBTOOL_SANITYCHECK
-# ----------------------
-# Default configuration of libtool on solaris produces non-working
-# plugin modules, when gcc is used as compiler, and gcc does not
-# use gnu-ld
-AC_DEFUN([AC_PROG_LIBTOOL_SANITYCHECK],
- [dnl AC_REQUIRE(AC_PROG_CC)
- dnl AC_REQUIRE(AC_PROG_LD)
- dnl AC_REQUIRE(AC_PROG_LIBTOOL)
-
- case $host in
- *-*-solaris*)
- if test "$GCC" = yes && test "$with_gnu_ld" != yes; then
- AC_MSG_CHECKING([if libtool can build working modules])
- cat > conftest1.c <<_ACEOF
-#undef NDEBUG
-#include <assert.h>
-int shlib_func(long long a, long long b) {
- assert(b);
- switch (a&3) {
- case 0: return a/b;
- case 1: return a%b;
- case 2: return (unsigned long long)a/b;
- case 3: return (unsigned long long)a%b;
- }
-}
-_ACEOF
-
- cat > conftest2.c <<_ACEOF
-#include <dlfcn.h>
-int main(){
- void *dl = dlopen(".libs/libconftest.so", RTLD_NOW);
- if (!dl) printf("%s\n", dlerror());
- exit(dl ? 0 : 1);
-}
-_ACEOF
-
- if ./libtool $CC -c conftest1.c >/dev/null 2>&1 && \
- ./libtool $CC -o libconftest.la conftest1.lo \
- -module -avoid-version -rpath /tmp >/dev/null 2>&1 && \
- ./libtool $CC -o conftest2 conftest2.c -ldl >/dev/null 2>&1
- then
- if ./conftest2 >/dev/null 2>&1; then
- AC_MSG_RESULT(yes)
- else
- dnl typical problem: dlopen'ed module not self contained, because
- dnl it wasn't linked with -lgcc
- AC_MSG_RESULT(no)
- if grep '^archive_cmds=.*$LD -G' libtool >/dev/null; then
- AC_MSG_CHECKING([if libtool can be fixed])
-
- dnl first try to update gcc2's spec file to add the
- dnl gcc3 -mimpure-text flag
-
- libtool_specs=""
-
- if $CC -dumpspecs | grep -- '-G -dy -z text' >/dev/null; then
- $CC -dumpspecs | \
- sed 's/-G -dy -z text/-G -dy %{!mimpure-text:-z text}/g' \
- > gcc-libtool-specs
- libtool_specs=" -specs=`pwd`/gcc-libtool-specs"
- fi
-
- sed -e "s,\$LD -G,\$CC${libtool_specs} -shared -mimpure-text,g" \
- -e 's/ -M / -Wl,-M,/' libtool >libtool-fixed
- chmod +x libtool-fixed
- if ./libtool-fixed $CC -o libconftest.la conftest1.lo \
- -module -avoid-version -rpath /tmp >/dev/null 2>&1 && \
- ./conftest2 >/dev/null 2>&1; then
-
- dnl the fixed libtool works
- AC_MSG_RESULT(yes)
- mv -f libtool-fixed libtool
-
- else
- AC_MSG_RESULT(no)
- fi
- fi
- fi
- else
- AC_MSG_RESULT(no)
- fi
- rm -f conftest1.c conftest1.lo conftest1.o conftest2.c \
- libconftest.la conftest libtool-fixed
- rm -rf .libs
- fi ;;
- esac
-])# AC_PROG_LIBTOOL_SANITYCHECK
-
-dnl Check for the type of the third argument of getsockname
-AC_DEFUN([AC_CHECK_SOCKLEN_T], [
- AC_MSG_CHECKING(for socklen_t)
- AC_LANG_PUSH(C++)
-
- AC_CACHE_VAL(ac_cv_socklen_t, [
- AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
-#include <sys/socket.h>
- ]], [[socklen_t a=0;
-getsockname(0,(struct sockaddr*)0, &a);
- ]])],[ac_cv_socklen_t=socklen_t],[ac_cv_socklen_t=''])
- if test "x$ac_cv_socklen_t" = x; then
- AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
-#include <sys/socket.h>]], [[
-int a=0;
-getsockname(0,(struct sockaddr*)0, &a);]])],
- [ac_cv_socklen_t=int],[ac_cv_socklen_t=size_t])
- fi
- ])
- AC_LANG_POP([C++])
-
- AC_MSG_RESULT($ac_cv_socklen_t)
- if test "$ac_cv_socklen_t" != "socklen_t"; then
- AC_DEFINE_UNQUOTED(socklen_t, $ac_cv_socklen_t,
- [Define the real type of socklen_t])
- fi
-])
diff --git a/m4/aa.m4 b/m4/aa.m4
deleted file mode 100644
index bab0d9d28..000000000
--- a/m4/aa.m4
+++ /dev/null
@@ -1,272 +0,0 @@
-dnl Configure path and dependencies for aalib.
-dnl
-dnl Copyright (C) 2001 Daniel Caujolle-Bert <segfault@club-internet.fr>
-dnl
-dnl This program is free software; you can redistribute it and/or modify
-dnl it under the terms of the GNU General Public License as published by
-dnl the Free Software Foundation; either version 2 of the License, or
-dnl (at your option) any later version.
-dnl
-dnl This program is distributed in the hope that it will be useful,
-dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
-dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-dnl GNU General Public License for more details.
-dnl
-dnl You should have received a copy of the GNU General Public License
-dnl along with this program; if not, write to the Free Software
-dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-dnl
-dnl
-dnl As a special exception to the GNU General Public License, if you
-dnl distribute this file as part of a program that contains a configuration
-dnl script generated by Autoconf, you may include it under the same
-dnl distribution terms that you use for the rest of that program.
-dnl
-dnl AM_PATH_AALIB([MINIMUM-VERSION, [ACTION-IF-FOUND [,ACTION-IF-NOT-FOUND ]]])
-dnl Test for AALIB, and define AALIB_CFLAGS and AALIB_LIBS, AALIB_STATIC_LIBS.
-dnl
-dnl ***********************
-dnl 26/09/2001
-dnl * fixed --disable-aalibtest.
-dnl 17/09/2001
-dnl * use both aalib-config, and *last chance* aainfo for guessing.
-dnl 19/08/2001
-dnl * use aalib-config instead of aainfo now.
-dnl 17/06/2001
-dnl * First shot
-dnl
-
-dnl Internal bits, used by AM_PATH_AALIB.
-dnl Requires AALIB_CFLAGS and AALIB_FLAGS to be defined
-AC_DEFUN([_AALIB_CHECK_VERSION], [
- ac_save_CFLAGS="$CFLAGS"
- ac_save_LIBS="$LIBS"
- CFLAGS="$AALIB_CFLAGS $CFLAGS"
- LIBS="$AALIB_LIBS $LIBS"
-
-dnl Now check if the installed AALIB is sufficiently new. (Also sanity
-dnl checks the results of aalib-config to some extent.)
-
- rm -f conf.aalibtest
- AC_RUN_IFELSE([AC_LANG_SOURCE([[
-#include <stdio.h>
-#include <stdlib.h>
-#include <aalib.h>
-
-int main () {
- int major, minor;
- char *tmp_version;
-
- system ("touch conf.aalibtest");
-
- /* HP/UX 9 (%@#!) writes to sscanf strings */
- tmp_version = (char *) strdup("$min_aalib_version");
- if (sscanf(tmp_version, "%d.%d", &major, &minor) != 2) {
- printf("%s, bad version string\n", "$min_aalib_version");
- exit(1);
- }
-
- if ((AA_LIB_VERSION > major) || ((AA_LIB_VERSION == major) &&
-#ifdef AA_LIB_MINNOR
- (AA_LIB_MINNOR >= minor)
-#else
- (AA_LIB_MINOR >= minor)
-#endif
- )) {
- return 0;
- }
- else {
-#ifdef AA_LIB_MINNOR
- printf("\n*** An old version of AALIB (%d.%d) was found.\n", AA_LIB_VERSION, AA_LIB_MINNOR);
-#else
- printf("\n*** An old version of AALIB (%d.%d) was found.\n", AA_LIB_VERSION, AA_LIB_MINOR);
-#endif
- printf("*** You need a version of AALIB newer than %d.%d. The latest version of\n", major, minor);
- printf("*** AALIB is always available from:\n");
- printf("*** http://www.ta.jcu.cz://aa\n");
- printf("***\n");
- }
- return 1;
-}
-]])],[],[no_aalib=yes],[no_aalib=cc])
- if test "x$no_aalib" = xcc; then
- AC_LINK_IFELSE([AC_LANG_PROGRAM([[
-#include <stdio.h>
-#include <aalib.h>
-]], [[ return ((AA_LIB_VERSION) ||
-#ifdef AA_LIB_MINNOR
- (AA_LIB_MINNOR)
-#else
- (AA_LIB_MINOR)
-#endif
- ); ]])],[no_aalib=''],[no_aalib=yes])
- fi
- CFLAGS="$ac_save_CFLAGS"
- LIBS="$ac_save_LIBS"
-])
-
-
-AC_DEFUN([AM_PATH_AALIB],
-[dnl
-dnl
-AC_ARG_WITH(aalib-prefix,
- AS_HELP_STRING([--with-aalib-prefix=DIR], [prefix where AALIB is installed (optional)]),
- aalib_config_prefix="$withval", aalib_config_prefix="")
-AC_ARG_WITH(aalib-exec-prefix,
- AS_HELP_STRING([--with-aalib-exec-prefix=DIR], [exec prefix where AALIB is installed (optional)]),
- aalib_config_exec_prefix="$withval", aalib_config_exec_prefix="")
-AC_ARG_ENABLE(aalibtest,
- AS_HELP_STRING([--disable-aalibtest], [do not try to compile and run a test AALIB program]),
- enable_aalibtest=$enableval, enable_aalibtest=yes)
-
- AC_LANG_PUSH([C])
-
- if test x$aalib_config_exec_prefix != x ; then
- aalib_config_args="$aalib_config_args --exec-prefix=$aalib_config_exec_prefix"
- if test x${AALIB_CONFIG+set} != xset ; then
- AALIB_CONFIG=$aalib_config_exec_prefix/bin/aalib-config
- fi
- fi
- if test x$aalib_config_prefix != x ; then
- aalib_config_args="$aalib_config_args --prefix=$aalib_config_prefix"
- if test x${AALIB_CONFIG+set} != xset ; then
- AALIB_CONFIG=$aalib_config_prefix/bin/aalib-config
- fi
- fi
-
- min_aalib_version=ifelse([$1], ,1.4,$1)
-
- if test x"$enable_aalibtest" != "xyes"; then
- AC_MSG_CHECKING([for AALIB version >= $min_aalib_version])
- else
- if test ! -x "$AALIB_CONFIG"; then
- AALIB_CONFIG=""
- fi
- AC_PATH_TOOL(AALIB_CONFIG, aalib-config, no)
-
- if test "$AALIB_CONFIG" = "no" ; then
-
-dnl aalib-config is missing, check for old aainfo
-
- AALIB_LIBS="$AALIB_LIBS -laa"
- if test x$aalib_config_exec_prefix != x ; then
- AALIB_CFLAGS="-I$aalib_config_exec_prefix/include"
- AALIB_LIBS="-L$aalib_config_exec_prefix/lib -laa"
- if test x${AAINFO+set} != xset ; then
- AAINFO=$aalib_config_exec_prefix/bin/aainfo
- fi
- fi
-
- if test x$aalib_config_prefix != x ; then
- AALIB_CFLAGS="-I$aalib_config_prefix/include"
- AALIB_LIBS="-L$aalib_config_prefix/lib -laa"
- if test x${AAINFO+set} != xset ; then
- AAINFO=$aalib_config_prefix/bin/aainfo
- fi
- fi
-
- if test x"$aalib_config_prefix" = "x"; then
- AC_PATH_TOOL(AAINFO, aainfo, no)
- else
- AC_MSG_CHECKING(for $AAINFO)
- if test -x $AAINFO; then
- AC_MSG_RESULT(yes)
- else
- AAINFO="no"
- AC_MSG_RESULT(no)
- fi
- fi
-
- AC_MSG_CHECKING([for AALIB version >= $min_aalib_version])
- no_aalib=""
-
- if test x"$AAINFO" = "xno"; then
- no_aalib=yes
- else
- aalib_drivers="`$AAINFO --help | grep drivers | sed -e 's/available//g;s/drivers//g;s/\://g'`"
- for drv in $aalib_drivers; do
- if test $drv = "X11" -a x$x11dep = "x"; then
- AALIB_CFLAGS="$AALIB_CFLAGS `echo $X_CFLAGS|sed -e 's/\-I/\-L/g;s/include/lib/g'`"
- x11dep="yes"
- fi
-dnl if test $drv = "slang" -a x$slangdep = "x"; then
-dnl slangdep="yes"
-dnl fi
-dnl if test $drv = "gpm" -a x$gmpdep = "x"; then
-dnl gpmdep="yes"
-dnl fi
- done
-
- _AALIB_CHECK_VERSION
- fi
-
- else dnl AALIB_CONFIG
- AC_MSG_CHECKING([for AALIB version >= $min_aalib_version])
- no_aalib=""
- AALIB_CFLAGS="`$AALIB_CONFIG $aalib_config_args --cflags`"
- AALIB_LIBS="`$AALIB_CONFIG $aalib_config_args --libs`"
- aalib_config_major_version=`$AALIB_CONFIG $aalib_config_args --version | \
- sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
- aalib_config_minor_version=`$AALIB_CONFIG $aalib_config_args --version | \
- sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
- aalib_config_sub_version=`$AALIB_CONFIG $aalib_config_args --version | \
- sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
-
- _AALIB_CHECK_VERSION
- fi dnl AALIB_CONFIG
- fi dnl enable_aalibtest
-
- if test "x$no_aalib" = x; then
- AC_MSG_RESULT(yes)
- ifelse([$2], , :, [$2])
- else
- AC_MSG_RESULT(no)
- if test "$AALIB_CONFIG" = "no"; then
- echo "*** The [aalib-config|aainfo] program installed by AALIB could not be found"
- echo "*** If AALIB was installed in PREFIX, make sure PREFIX/bin is in"
- echo "*** your path, or use --with-aalib-prefix to set the prefix"
- echo "*** where AALIB is installed."
- else
- if test -f conf.aalibtest ; then
- :
- else
- echo "*** Could not run AALIB test program, checking why..."
- CFLAGS="$CFLAGS $AALIB_CFLAGS"
- LIBS="$LIBS $AALIB_LIBS"
- AC_LINK_IFELSE([AC_LANG_PROGRAM([[
-#include <stdio.h>
-#include <aalib.h>
-]], [[
- return ((AA_LIB_VERSION) ||
-#ifdef AA_LIB_MINNOR
- (AA_LIB_MINNOR)
-#else
- (AA_LIB_MINOR)
-#endif
- ); ]])],
- [ echo "*** The test program compiled, but did not run. This usually means"
- echo "*** that the run-time linker is not finding AALIB or finding the wrong"
- echo "*** version of AALIB. If it is not finding AALIB, you'll need to set your"
- echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
- echo "*** to the installed location Also, make sure you have run ldconfig if that"
- echo "*** is required on your system"
- echo "***"
- echo "*** If you have an old version installed, it is best to remove it, although"
- echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"
- echo "***"],
- [ echo "*** The test program failed to compile or link. See the file config.log for the"
- echo "*** exact error that occured. This usually means AALIB was incorrectly installed"
- echo "*** or that you have moved AALIB since it was installed." ])
- CFLAGS="$ac_save_CFLAGS"
- LIBS="$ac_save_LIBS"
- fi
- fi
- AALIB_CFLAGS=""
- AALIB_LIBS=""
- ifelse([$3], , :, [$3])
- fi
- AC_SUBST(AALIB_CFLAGS)
- AC_SUBST(AALIB_LIBS)
- AC_LANG_POP([C])
- rm -f conf.aalibtest
-])
diff --git a/m4/arts.m4 b/m4/arts.m4
deleted file mode 100644
index 079c21ba8..000000000
--- a/m4/arts.m4
+++ /dev/null
@@ -1,168 +0,0 @@
-# Configure paths for ARTS
-# Philip Stadermann 2001-06-21
-# stolen from esd.m4
-
-dnl AM_PATH_ARTS([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
-dnl Test for ARTS, and define ARTS_CFLAGS and ARTS_LIBS
-dnl
-AC_DEFUN([AM_PATH_ARTS],
-[dnl
-dnl Get the cflags and libraries from the artsc-config script
-dnl
-AC_ARG_WITH(arts-prefix, AS_HELP_STRING([--with-arts-prefix=DIR], [prefix where ARTS is installed (optional)]),
- arts_prefix="$withval", arts_prefix="")
-AC_ARG_ENABLE(artstest, AS_HELP_STRING([--disable-artstest], [do not try to compile and run a test ARTS program]),
- enable_artstest=$enableval, enable_artstest=yes)
-
- if test x$arts_prefix != x ; then
- arts_args="$arts_args --arts-prefix=$arts_prefix"
- if test x${ARTS_CONFIG+set} != xset ; then
- ARTS_CONFIG=$arts_prefix/bin/artsc-config
- fi
- fi
-
- AC_PATH_TOOL(ARTS_CONFIG, artsc-config, no)
-
- min_arts_version=ifelse([$1], ,0.9.5,$1)
- AC_MSG_CHECKING(for ARTS artsc - version >= $min_arts_version)
- no_arts=""
- if test "$ARTS_CONFIG" = "no" ; then
- no_arts=yes
- else
- ARTS_CFLAGS=`$ARTS_CONFIG $artsconf_args --cflags`
- ARTS_LIBS=`$ARTS_CONFIG $artsconf_args --libs`
-
- arts_major_version=`$ARTS_CONFIG $arts_args --version | \
- sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
- arts_minor_version=`$ARTS_CONFIG $arts_args --version | \
- sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
- arts_micro_version=`$ARTS_CONFIG $arts_config_args --version | \
- sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
- if test "x$enable_artstest" = "xyes" ; then
- ac_save_CFLAGS="$CFLAGS"
- ac_save_LIBS="$LIBS"
- CFLAGS="$CFLAGS $ARTS_CFLAGS"
- LIBS="$LIBS $ARTS_LIBS"
-dnl
-dnl Check if the installed ARTS is actually available -- when cross-compiling,
-dnl we have probably detected the build system's version of artsc-config
-dnl
- AC_CHECK_LIB([artsc], [arts_init], [], [no_arts=yes], [$ARTS_LIBS])
-
-dnl
-dnl Now check if the installed ARTS is sufficiently new. (Also sanity
-dnl checks the results of artsc-config to some extent)
-dnl
- rm -f conf.artstest
- AC_RUN_IFELSE([AC_LANG_SOURCE([[
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <artsc.h>
-
-char*
-my_strdup (char *str)
-{
- char *new_str;
-
- if (str)
- {
- new_str = malloc ((strlen (str) + 1) * sizeof(char));
- strcpy (new_str, str);
- }
- else
- new_str = NULL;
-
- return new_str;
-}
-
-int main ()
-{
- int major, minor, micro;
- char *tmp_version;
-
- system ("touch conf.artstest");
-
- /* HP/UX 9 (%@#!) writes to sscanf strings */
- tmp_version = my_strdup("$min_arts_version");
- if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
- printf("%s, bad version string\n", "$min_arts_version");
- exit(1);
- }
-
- if (($arts_major_version > major) ||
- (($arts_major_version == major) && ($arts_minor_version > minor)) ||
- (($arts_major_version == major) && ($arts_minor_version == minor) && ($arts_micro_version >= micro)))
- {
- return 0;
- }
- else
- {
- printf("\n*** 'artsc-config --version' returned %d.%d.%d, but the minimum version\n", $arts_major_version, $arts_minor_version, $arts_micro_version);
- printf("*** of ARTS required is %d.%d.%d. If artsc-config is correct, then it is\n", major, minor, micro);
- printf("*** best to upgrade to the required version.\n");
- printf("*** If artsc-config was wrong, set the environment variable ARTS_CONFIG\n");
- printf("*** to point to the correct copy of artsc-config, and remove the file\n");
- printf("*** config.cache before re-running configure\n");
- return 1;
- }
-}
-
-]])],[],[no_arts=yes],[no_arts=cc])
-
- if test "x$no_arts" = "xcc"; then
- AC_LINK_IFELSE([AC_LANG_PROGRAM([[
-#include <stdio.h>
-#include <artsc.h>
-]], [[ return 0; ]])],[no_arts=''],[no_arts=yes])
- fi
- CFLAGS="$ac_save_CFLAGS"
- LIBS="$ac_save_LIBS"
- fi
- fi
- if test "x$no_arts" = x ; then
- AC_MSG_RESULT(yes)
- ifelse([$2], , :, [$2])
- else
- AC_MSG_RESULT(no)
- if test "$ARTS_CONFIG" = "no" ; then
- echo "*** The artsc-config script installed by ARTS could not be found"
- echo "*** If ARTS was installed in PREFIX, make sure PREFIX/bin is in"
- echo "*** your path, or set the ARTS_CONFIG environment variable to the"
- echo "*** full path to artsc-config."
- else
- if test -f conf.artstest ; then
- :
- else
- echo "*** Could not run ARTS test program, checking why..."
- CFLAGS="$CFLAGS $ARTS_CFLAGS"
- LIBS="$LIBS $ARTS_LIBS"
- AC_LINK_IFELSE([AC_LANG_PROGRAM([[
-#include <stdio.h>
-#include <artsc.h>
-]], [[ return 0; ]])],
- [ echo "*** The test program compiled, but did not run. This usually means"
- echo "*** that the run-time linker is not finding ARTS or finding the wrong"
- echo "*** version of ARTS. If it is not finding ARTS, you'll need to set your"
- echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
- echo "*** to the installed location Also, make sure you have run ldconfig if that"
- echo "*** is required on your system"
- echo "***"
- echo "*** If you have an old version installed, it is best to remove it, although"
- echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
- [ echo "*** The test program failed to compile or link. See the file config.log for the"
- echo "*** exact error that occured. This usually means ARTS was incorrectly installed"
- echo "*** or that you have moved ARTS since it was installed. In the latter case, you"
- echo "*** may want to edit the artsc-config script: $ARTS_CONFIG" ])
- CFLAGS="$ac_save_CFLAGS"
- LIBS="$ac_save_LIBS"
- fi
- fi
- ARTS_CFLAGS=""
- ARTS_LIBS=""
- ifelse([$3], , :, [$3])
- fi
- AC_SUBST(ARTS_CFLAGS)
- AC_SUBST(ARTS_LIBS)
- rm -f conf.artstest
-])
diff --git a/m4/attributes.m4 b/m4/attributes.m4
index 55f34c9f7..1f4750a71 100644
--- a/m4/attributes.m4
+++ b/m4/attributes.m4
@@ -50,6 +50,24 @@ AC_DEFUN([CC_CHECK_CFLAGS], [
fi
])
+AC_DEFUN([CC_CHECK_LDFLAGS], [
+ AC_CACHE_CHECK([if $CC supports $1 flag],
+ AS_TR_SH([cc_cv_ldflags_$1]),
+ [ac_save_LDFLAGS="$LDFLAGS"
+ LDFLAGS="$LDFLAGS $1"
+ AC_LINK_IFELSE([int a;],
+ [eval "AS_TR_SH([cc_cv_ldflags_$1])='yes'"],
+ [eval "AS_TR_SH([cc_cv_ldflags_$1])="])
+ LDFLAGS="$ac_save_LDFLAGS"
+ ])
+
+ if eval test [x$]AS_TR_SH([cc_cv_ldflags_$1]) = xyes; then
+ ifelse([$2], , [:], [$2])
+ else
+ ifelse([$3], , [:], [$3])
+ fi
+])
+
dnl Check for a -Werror flag or equivalent. -Werror is the GCC
dnl and ICC flag that tells the compiler to treat all the warnings
dnl as fatal. We usually need this option to make sure that some
@@ -322,3 +340,90 @@ AC_DEFUN([CC_ATTRIBUTE_ALIGNED], [
[Define the highest alignment supported])
fi
])
+
+AC_DEFUN([CC_ATTRIBUTE_PACKED], [
+ AC_REQUIRE([CC_CHECK_WERROR])
+ AC_CACHE_CHECK([if $CC supports __attribute__((packed))],
+ [cc_cv_attribute_packed],
+ [ac_save_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS $cc_cv_werror"
+ AC_COMPILE_IFELSE([struct { char a; short b; int c; } __attribute__((packed)) foo;],
+ [cc_cv_attribute_packed=yes],
+ [cc_cv_attribute_packed=no])
+ CFLAGS="$ac_save_CFLAGS"
+ ])
+
+ if test x$cc_cv_attribute_packed = xyes; then
+ AC_DEFINE([SUPPORT_ATTRIBUTE_PACKED], 1, [Define this if the compiler supports __attribute__((packed))])
+ ifelse([$1], , [:], [$1])
+ else
+ ifelse([$2], , [:], [$2])
+ fi
+])
+
+AC_DEFUN([CC_ATTRIBUTE_MALLOC], [
+ AC_REQUIRE([CC_CHECK_WERROR])
+ AC_CACHE_CHECK([if $CC supports __attribute__((__malloc__))],
+ [cc_cv_attribute_malloc],
+ [ac_save_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS $cc_cv_werror"
+ AC_COMPILE_IFELSE([void *fooalloc(int size) __attribute__((__malloc__));],
+ [cc_cv_attribute_malloc=yes],
+ [cc_cv_attribute_malloc=no])
+ CFLAGS="$ac_save_CFLAGS"
+ ])
+
+ if test x$cc_cv_attribute_malloc = xyes; then
+ AC_DEFINE([SUPPORT_ATTRIBUTE_MALLOC], 1, [Define this if the compiler supports __attribute__((__malloc__))])
+ ifelse([$1], , [:], [$1])
+ else
+ ifelse([$2], , [:], [$2])
+ fi
+])
+
+
+dnl AC_C_ALWAYS_INLINE
+dnl Define inline to something appropriate, including the new always_inline
+dnl attribute from gcc 3.1
+dnl Thanks to Michel LESPINASSE <walken@zoy.org>
+dnl __inline__ "check" added by Darren Salt
+AC_DEFUN([AC_C_ALWAYS_INLINE], [
+ AC_C_INLINE
+ if test x"$GCC" = x"yes" -a x"$ac_cv_c_inline" = x"inline"; then
+ AC_MSG_CHECKING([for always_inline])
+ SAVE_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS -Wall -Werror"
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[inline __attribute__ ((__always_inline__)) void f (void);]])],
+ [ac_cv_always_inline=yes],[ac_cv_always_inline=no])
+ CFLAGS="$SAVE_CFLAGS"
+ AC_MSG_RESULT([$ac_cv_always_inline])
+ if test x"$ac_cv_always_inline" = x"yes"; then
+ AH_TOP([
+#ifdef inline
+/* the strange formatting below is needed to prevent config.status from rewriting it */
+# undef \
+ inline
+#endif
+ ])
+ AC_DEFINE_UNQUOTED([inline],[inline __attribute__ ((__always_inline__))])
+ fi
+ ac_cv_c___inline__=''
+ else
+ # FIXME: test the compiler to see if it supports __inline__
+ # instead of assuming that if it isn't gcc, it doesn't
+ case "$ac_cv_c_inline" in
+ yes)
+ ac_cv_c___inline__=inline
+ ;;
+ inline|__inline__)
+ ac_cv_c___inline__=''
+ ;;
+ *)
+ ac_cv_c___inline__="$ac_cv_c_inline"
+ ;;
+ esac
+ fi
+ if test x"$ac_cv_c___inline__" != x; then
+ AC_DEFINE_UNQUOTED([__inline__],[$ac_cv_c___inline__],[Define if the compiler doesn't recognise __inline__])
+ fi
+])
diff --git a/m4/audio_out.m4 b/m4/audio_out.m4
new file mode 100644
index 000000000..cdfe8b65d
--- /dev/null
+++ b/m4/audio_out.m4
@@ -0,0 +1,239 @@
+dnl -----------------
+dnl Audio out plugins
+dnl -----------------
+AC_DEFUN([XINE_AUDIO_OUT_PLUGINS], [
+ dnl Setup defaults for the target operating system. For example, alsa is
+ dnl only ever available on Linux, so don't bother checking for it unless
+ dnl explicitly requested to do so on other operating systems.
+ dnl Notes:
+ dnl - Alsa is Linux only
+ dnl - aRts is Linux only
+ dnl - CoreAudio is Mac OS X only
+ dnl - EsounD is reported to be available on most platforms
+ dnl - FusionSound is Linux only, but don't enable it by default
+ dnl - Jack is Linux and Mac OS X primarily
+ dnl - OSS is most unix variants
+ dnl - PulseAudio has been tested on Linux, Solaris, FreeBSD, Windows
+ dnl - SunAudio is NetBSD, OpenBSD, Solaris (anything else?)
+
+ default_enable_coreaudio=disable
+ default_enable_irixal=disable
+ default_enable_oss=enable
+ default_enable_sunaudio=disable
+
+ default_with_alsa=without
+ default_with_arts=without
+ default_with_esound=with
+ default_with_fusionsound=without
+ default_with_jack=without
+ default_with_pulseaudio=without
+
+ case "$host_os" in
+ cygwin* | mingw*)
+ default_enable_oss=disable
+ default_with_pulseaudio=with
+ ;;
+ darwin*)
+ default_enable_coreaudio=enable
+ default_with_jack=with
+ default_enable_oss=disable
+ ;;
+ freebsd*)
+ default_with_pulseaudio=with
+ ;;
+ irix*)
+ default_enable_irixal=enable
+ default_enable_oss=disable
+ ;;
+ linux*)
+ default_with_alsa=with
+ default_with_arts=with
+ default_with_jack=with
+ default_with_pulseaudio=with
+ ;;
+ netbsd*)
+ default_enable_sunaudio=enable
+ ;;
+ openbsd*)
+ default_enable_sunaudio=enable
+ ;;
+ solaris*)
+ default_with_pulseaudio=with
+ default_enable_sunaudio=enable
+ ;;
+ esac
+
+
+ dnl Alsa support
+ AC_ARG_WITH([alsa],
+ [AS_HELP_STRING([--with-alsa], [Build with ALSA audio output support])],
+ [test x"$withval" != x"no" && with_alsa="yes"],
+ [test $default_with_alsa = without && with_alsa="no"])
+ if test x"$with_alsa" != x"no"; then
+ PKG_CHECK_MODULES([ALSA], [alsa >= 0.9.0], [have_alsa=yes], [have_alsa=no])
+ if test x"$with_alsa" = x"yes" && test x"$have_alsa" != x"yes"; then
+ AC_MSG_ERROR([ALSA support requested but not found.])
+ elif test x"$have_alsa" = x"yes"; then
+ dnl This is needed by src/input/input_v4l.c
+ AC_DEFINE([HAVE_ALSA], 1, [Define this if you have ALSA installed])
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_ALSA], [test x"$have_alsa" = x"yes"])
+
+
+ dnl aRts support
+ AC_ARG_WITH([arts],
+ [AS_HELP_STRING([--with-arts], [Build with aRts audio output support])],
+ [test x"$withval" != x"no" && with_arts="yes"],
+ [test $default_with_arts = without && with_arts="no"])
+ if test x"$with_arts" != x"no"; then
+ ACX_PACKAGE_CHECK([ARTS], [0.9.5], [artsc-config], [have_arts=yes], [have_arts=no])
+ if test x"$with_arts" = x"yes" && test x"$have_arts" != x"yes"; then
+ AC_MSG_ERROR([aRts support requested, but aRts not found])
+ elif test x"$have_arts" = x"yes"; then
+ AC_DEFINE([HAVE_ARTS], 1, [Define this if you have aRts (libartsc) installed])
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_ARTS], [test x"$have_arts" = x"yes"])
+
+
+ dnl CoreAudio for Mac OS X
+ AC_ARG_ENABLE([coreaudio],
+ [AS_HELP_STRING([--enable-coreaudio], [Enable support for Mac OS X CoreAudio])],
+ [test x"$enableval" != x"no" && enable_coreaudio="yes"],
+ [test $default_enable_coreaudio = disable && enable_coreaudio="no"])
+ if test x"$enable_coreaudio" != x"no"; then
+ AC_MSG_CHECKING([for CoreAudio frameworks])
+ ac_save_LIBS="$LIBS" LIBS="$LIBS -framework CoreAudio -framework AudioUnit"
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[return 0]])], [have_coreaudio=yes], [have_coreaudio=no])
+ LIBS="$ac_save_LIBS"
+ AC_MSG_RESULT([$have_coreaudio])
+ if test x"$enable_coreaudio" = x"yes" && test x"$have_coreaudio" != x"yes"; then
+ AC_MSG_ERROR([CoreAudio support requested, but CoreAudio not found])
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_COREAUDIO], [test x"$have_coreaudio" = x"yes"])
+
+
+ dnl EsounD support
+ AC_ARG_WITH([esound],
+ [AS_HELP_STRING([--with-esound], [Build with EsounD audio output support])],
+ [test x"$withval" != x"no" && with_esound="yes"],
+ [test $default_with_esound = without && with_esound="no"])
+ if test x"$with_esound" != x"no"; then
+ PKG_CHECK_MODULES([ESD], [esound], [have_esound=yes], [have_esound=no])
+ if test x"$with_esound" = x"yes" && test x"$have_esound" != x"yes"; then
+ AC_MSG_ERROR([EsounD support requested, but EsounD not found])
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_ESD], [test x"$have_esound" = x"yes"])
+
+
+ dnl FusionSound support
+ AC_ARG_WITH([fusionsound],
+ [AS_HELP_STRING([--with-fusionsound], [Build with FunsionSound audio output support])],
+ [test x"$withval" != x"no" && with_fusionsound="yes"],
+ [test $default_with_fusionsound = without && with_fusionsound="no"])
+ if test x"$with_fusionsound" != x"no"; then
+ PKG_CHECK_MODULES([FUSIONSOUND], [fusionsound >= 0.9.23], [have_fusionsound=yes], [have_fusionsound=no])
+ if test x"$with_fusionsound" = x"yes" && test x"$have_fusionsound" != x"yes"; then
+ AC_MSG_ERROR([FusionSound support requested, but FusionSound not found])
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_FUSIONSOUND], [test x"$have_fusionsound" = x"yes"])
+
+
+ dnl IRIX style audio interface
+ AC_ARG_ENABLE([irixal],
+ [AS_HELP_STRING([--enable-irixal], [Enable support for IRIX libaudio])],
+ [test x"$enableval" != x"no" && enable_irixal="yes"],
+ [test $default_enable_irixal = disable && enable_irixal="no"])
+ if test x"$enable_irixal" != x"no"; then
+ AC_CACHE_CHECK([for IRIX libaudio support], [am_cv_have_irixal],
+ [AC_CHECK_HEADER([dmedia/audio.h],
+ [am_cv_have_irixal=yes], [am_cv_have_irixal=no])])
+ if test x"$am_cv_have_irixal" = x"yes"; then
+ AC_DEFINE([HAVE_IRIXAL], 1, [Define this if you have a usable IRIX al interface available])
+ IRIXAL_LIBS="-laudio"
+ IRIXAL_STATIC_LIB="/usr/lib/libaudio.a"
+ AC_SUBST(IRIXAL_LIBS)
+ AC_SUBST(IRIXAL_STATIC_LIB)
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_IRIXAL], [test x"$am_cv_have_irixal" = x"yes"])
+
+
+ dnl JACK support
+ AC_ARG_WITH([jack],
+ [AS_HELP_STRING([--with-jack], [Build with Jack support])],
+ [test x"$withval" != x"no" && with_jack="yes"],
+ [test $default_with_jack = without && with_jack="no"])
+ if test x"$with_jack" != x"no"; then
+ PKG_CHECK_MODULES([JACK], [jack >= 0.100], [have_jack=yes], [have_jack=no])
+ if test x"$with_jack" = x"yes" && test x"$have_jack" != x"yes"; then
+ AC_MSG_ERROR([Jack support requested, but Jack not found])
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_JACK], [test x"$have_jack" = x"yes"])
+
+
+ dnl OSS (Open Sound System)
+ AC_ARG_ENABLE([oss],
+ [AS_HELP_STRING([--enable-oss], [Enable OSS (Open Sound System) support])],
+ [test x"$enableval" != x"no" && enable_oss="yes"],
+ [test $default_enable_oss = disable && enable_oss="no"])
+ if test x"$enable_oss" != x"no"; then
+ AC_CHECK_HEADERS([sys/soundcard.h machine/soundcard.h soundcard.h], [break])
+ AC_CHECK_DECL([SNDCTL_DSP_SETFRAGMENT], [have_oss=yes], [have_oss=no],
+ [#ifdef HAVE_SYS_SOUNDCARD_H
+ # include <sys/soundcard.h>
+ #endif
+ #ifdef HAVE_MACHINE_SOUNDCARD_H
+ # include <sys/soundcard.h>
+ #endif
+ #ifdef HAVE_SOUNDCARD_H
+ # include <soundcard.h>
+ #endif])
+ if test x"$enable_oss" = x"yes" && test x"$have_oss" != x"yes"; then
+ AC_MSG_ERROR([OSS support requested, but OSS not found])
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_OSS], [test x"$have_oss" = x"yes"])
+
+
+ dnl PulseAudio
+ AC_ARG_WITH([pulseaudio],
+ [AS_HELP_STRING([--with-pulseaudio], [Build with PulseAudio support])],
+ [test x"$withval" != x"no" && with_pulseaudio="yes"],
+ [test $default_with_pulseaudio = without && with_pulseaudio="no"])
+ if test x"$with_pulseaudio" != x"no"; then
+ PKG_CHECK_MODULES([PULSEAUDIO], [libpulse], [have_pulseaudio="yes"], [have_pulseaudio="no"])
+ if test x"$with_pulseaudio" = x"yes" && test x"$have_pulseaudio" != x"yes"; then
+ AC_MSG_ERROR([PulseAudio support requested, but PulseAudio not found])
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_PULSEAUDIO], [test x"$have_pulseaudio" = x"yes"])
+
+
+ dnl SUN style audio interface
+ AC_ARG_ENABLE([sunaudio],
+ [AS_HELP_STRING([--enable-sunaudio], [Enable Sun audio support])],
+ [test x"$enableval" != x"no" && enable_sunaudio="yes"],
+ [test $default_enable_sunaudio = disable && enable_sunaudio="no"])
+ if test x"$enable_sunaudio" != x"no"; then
+ AC_MSG_CHECKING([for Sun audio support])
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
+ #include <sys/audioio.h>]],
+ [[audio_info_t audio_info; AUDIO_INITINFO(&audio_info)]])],
+ [have_sunaudio=yes], [have_sunaudio=no])
+ AC_MSG_RESULT([$have_sunaudio])
+ if test x"$enable_sunaudio" = x"yes" && test x"$have_sunaudio" != x"yes"; then
+ AC_MSG_ERROR([Sun audio support requested, but Sun audio not found])
+ elif test x"$have_sunaudio" = x"yes"; then
+ dnl NetBSD and OpenBSD don't have this, but check for it
+ dnl rather than assuming that it doesn't happen elsewhere.
+ AC_CHECK_MEMBERS([audio_info_t.output_muted])
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_SUNAUDIO], [test x"$have_sunaudio" = x"yes"])
+])dnl XINE_AUDIO_OUT_PLUGINS
diff --git a/m4/decoders.m4 b/m4/decoders.m4
new file mode 100644
index 000000000..535af20bf
--- /dev/null
+++ b/m4/decoders.m4
@@ -0,0 +1,495 @@
+dnl ---------------------------
+dnl Decoder and Demuxer Plugins
+dnl ---------------------------
+AC_DEFUN([XINE_DECODER_PLUGINS], [
+ dnl a52dec (optional; enabled by default; external version allowed)
+ AC_ARG_ENABLE([a52dec],
+ [AS_HELP_STRING([--enable-a52dec], [Enable support for a52dec decoding library (default: enabled)])],
+ [test x"$enableval" != x"no" && enable_a52dec="yes"])
+ AC_ARG_WITH([external-a52dec],
+ [AS_HELP_STRING([--with-external-a52dec], [Use external a52dec library (not recommended)])],
+ [test x"$withval" != x"no" && with_external_a52dec="yes"], [with_external_a52dec="no"])
+ if test x"$enable_a52dec" != x"no"; then
+ if test x"$with_external_a52dec" != x"no"; then
+ AC_CHECK_LIB([a52], [a52_init],
+ [AC_CHECK_HEADERS([a52dec/a52.h a52dec/a52_internal.h], [have_external_a52dec=yes], [have_external_a52dec=no],
+ [#ifdef HAVE_SYS_TYPES_H
+ # include <sys/types.h>
+ #endif
+ #ifdef HAVE_INTTYPES_H
+ # include <inttypes.h>
+ #endif
+ #ifdef HAVE_STDINT_H
+ # include <stdint.h>
+ #endif
+ #include <a52dec/a52.h>])], [have_external_a52dec=no], [-lm])
+ if test x"$have_external_a52dec" = x"no"; then
+ AC_MSG_RESULT([*** no usable version of a52dec found, using internal copy ***])
+ fi
+ else
+ AC_MSG_RESULT([Using included a52dec support])
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_A52DEC], [test x"$enable_a52dec" != x"no"])
+ AM_CONDITIONAL([WITH_EXTERNAL_A52DEC], [test x"$have_external_a52dec" = x"yes"])
+
+
+ dnl ASF (optional; enabled by default)
+ AC_ARG_ENABLE([asf],
+ [AS_HELP_STRING([--enable-asf], [Enable support for ASF demuxer (default: enabled)])],
+ [test x"$enableval" != x"no" && enable_asf="yes"])
+ AM_CONDITIONAL([ENABLE_ASF], [test x"$enable_asf" != x"no"])
+
+
+ dnl FAAD (optional; enabled by default)
+ AC_ARG_ENABLE([faad],
+ [AS_HELP_STRING([--enable-faad], [Enable support for FAAD decoder (default: enabled)])],
+ [test x"$enableval" != x"no" && enable_faad="yes"])
+ AM_CONDITIONAL([ENABLE_FAAD], [test x"$enable_faad" != x"no"])
+
+
+ dnl ffmpeg (required; external version allowed)
+ AC_ARG_WITH([external-ffmpeg],
+ [AS_HELP_STRING([--with-external-ffmpeg], [use external ffmpeg library])],
+ [], [with_external_ffmpeg="no"])
+ AC_ARG_ENABLE([ffmpeg_uncommon_codecs],
+ [AS_HELP_STRING([--disable-ffmpeg-uncommon-codecs], [don't build uncommon ffmpeg codecs])],
+ [test x"$enableval" != x"no" && enable_ffmpeg_uncommon_codecs="yes"])
+ AC_ARG_ENABLE([ffmpeg_popular_codecs],
+ [AS_HELP_STRING([--disable-ffmpeg-popular-codecs], [don't build popular ffmpeg codecs])],
+ [test x"$enableval" != x"no" && enable_ffmpeg_popular_codecs="yes"])
+ case x"$with_external_ffmpeg" in
+ x"no") with_external_ffmpeg=no ;;
+ x"soft")
+ PKG_CHECK_MODULES([FFMPEG], [libavcodec >= 51.20.0], [with_external_ffmpeg=yes], [with_external_ffmpeg=no])
+ ;;
+ x*)
+ PKG_CHECK_MODULES([FFMPEG], [libavcodec >= 51.20.0], [with_external_ffmpeg=yes])
+ ;;
+ esac
+ if test x"$with_external_ffmpeg" != x"no"; then
+ PKG_CHECK_MODULES([FFMPEG_POSTPROC], [libpostproc])
+ AC_DEFINE([HAVE_FFMPEG], 1, [Define this if you have ffmpeg library])
+
+ AC_MSG_NOTICE([
+*********************************************************************
+xine-lib is configured with external ffmpeg.
+
+This requires the same version of ffmpeg what is included in xine and
+you should know what you do. If some problems occur, please try to
+use internal ffmpeg.
+*********************************************************************])
+ else
+ AC_MSG_RESULT([Using included ffmpeg])
+ fi
+ AM_CONDITIONAL([FFMPEG_DISABLE_UNCOMMON_CODECS], [test x"$enable_ffmpeg_uncommon_codecs" = x"no"])
+ AM_CONDITIONAL([FFMPEG_DISABLE_POPULAR_CODECS], [test x"$enable_ffmpeg_popular_codecs" = x"no"])
+ AM_CONDITIONAL([WITH_EXTERNAL_FFMPEG], [test x"$with_external_ffmpeg" != x"no"])
+
+
+ dnl gdk-pixbuf (optional; enabled by default)
+ AC_ARG_ENABLE([gdkpixbuf],
+ [AS_HELP_STRING([--enable-gdkpixbuf], [Enable GdkPixbuf support (default: enabled)])],
+ [test x"$enableval" != x"no" && enable_gdkpixbuf="yes"])
+ if test x"$enable_gdkpixbuf" != x"no"; then
+ PKG_CHECK_MODULES([GDK_PIXBUF], [gdk-pixbuf-2.0], [have_gdkpixbuf=yes], [have_gdkpixbuf=no])
+ if test x"$enable_gdkpixbuf" = x"yes" && test x"$have_gdkpixbuf" != x"yes"; then
+ AC_MSG_ERROR([GdkPixbuf support requested, but GdkPixbuf not found])
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_GDK_PIXBUF], [test x"$have_gdkpixbuf" = x"yes"])
+
+
+ dnl ImageMagick (optional; enabled by default)
+ AC_ARG_WITH([imagemagick],
+ [AS_HELP_STRING([--with-imagemagick], [Enable ImageMagick image decoder support (default: enabled)])],
+ [test x"$withval" != x"no" && with_imagemagick="yes"])
+ if test x"$with_imagemagick" != x"no"; then
+ PKG_CHECK_MODULES([WAND], [Wand], [have_imagemagick=yes], [have_imagemagick=no])
+ if test x"$with_imagemagick" = x"yes" && test x"$have_imagemagick" = x"no"; then
+ AC_MSG_ERROR([ImageMagick support requested, but ImageMagick not found])
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_IMAGEMAGICK], [test x"$have_imagemagick" = x"yes"])
+
+
+ dnl libdts (optional; enabled by default; external version allowed)
+ AC_ARG_ENABLE([dts],
+ [AS_HELP_STRING([--enable-dts], [Enable support for DTS decoding library (default: enabled)])],
+ [test x"$enableval" != x"no" && enable_dts="yes"])
+ AC_ARG_WITH([external-libdts],
+ [AS_HELP_STRING([--with-external-libdts], [Use external libdts/libdca library (not recommended)])],
+ [test x"$withval" != x"no" && with_external_libdts="yes"], [with_external_libdts="no"])
+ if test x"$enable_dts" != x"no"; then
+ if test x"$with_external_libdts" != x"no"; then
+ PKG_CHECK_MODULES([LIBDTS], [libdts], [have_external_dts=yes], [have_external_dts=no])
+ if test x"$have_external_dts" != x"yes"; then
+ AC_MSG_RESULT([*** no usable version of libdts found, using internal copy ***])
+ fi
+ else
+ AC_MSG_RESULT([Using included libdts support])
+ fi
+ if test x"$have_external_libdts" != x"yes"; then
+ LIBDTS_CFLAGS='-I$(top_srcdir)/contrib/libdca/include'
+ LIBDTS_DEPS='$(top_builddir)/contrib/libdca/libdca.la'
+ LIBDTS_LIBS='$(top_builddir)/contrib/libdca/libdca.la'
+ AC_SUBST(LIBDTS_DEPS)
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_DTS], [test x"$enable_dts" != x"no"])
+ AM_CONDITIONAL([WITH_EXTERNAL_LIBDTS], [test x"$have_external_libdts" = x"yes"])
+
+
+ dnl libFLAC (optional; disabled by default)
+ AC_ARG_WITH([libflac],
+ [AS_HELP_STRING([--with-libflac], [build libFLAC-based decoder and demuxer])],
+ [test x"$withval" != x"no" && with_libflac="yes"], [with_libflac="no"])
+ AC_ARG_WITH([libFLAC-prefix],
+ [AS_HELP_STRING([--with-libFLAC-prefix=DIR], [prefix where libFLAC is installed (optional)])])
+ AC_ARG_WITH([libFLAC-libraries],
+ [AS_HELP_STRING([--with-libFLAC-libraries=DIR], [directory where libFLAC library is installed (optional)])])
+ AC_ARG_WITH([libFLAC-includes],
+ [AS_HELP_STRING([--with-libFLAC-includes=DIR], [directory where libFLAC header files are installed (optional)])])
+ if test x"$with_libflac" != x"no"; then
+ AC_MSG_CHECKING([libdir name])
+ case "$host_or_hostalias" in
+ *-*-linux*)
+ # Test if the compiler is 64bit
+ echo 'int i;' > conftest.$ac_ext
+ xine_cv_cc_64bit_output=no
+ if AC_TRY_EVAL(ac_compile); then
+ case `"$MAGIC_CMD" conftest.$ac_objext` in
+ *"ELF 64"*) xine_cv_cc_64bit_output=yes ;;
+ esac
+ fi
+ rm -rf conftest*
+ ;;
+ esac
+ case "$host_cpu:$xine_cv_cc_64bit_output" in
+ powerpc64:yes | s390x:yes | sparc64:yes | x86_64:yes)
+ XINE_LIBDIRNAME="lib64" ;;
+ *:*)
+ XINE_LIBDIRNAME="lib" ;;
+ esac
+ AC_MSG_RESULT([$XINE_LIBDIRNAME])
+
+ if test x"$with_libFLAC_includes" != x""; then
+ LIBFLAC_CFLAGS="-I$with_libFLAC_includes"
+ elif test x"$with_libFLAC_prefix" != x""; then
+ LIBFLAC_CFLAGS="-I$with_libFLAC_prefix/include"
+ elif test x"$prefix" != x"NONE"; then
+ LIBFLAC_CFLAGS="-I$prefix/include"
+ fi
+ AC_SUBST(LIBFLAC_CFLAGS)
+
+ if test x"$with_libFLAC_libraries" != x""; then
+ LIBFLAC_LIBS="-L$with_libFLAC_libraries"
+ elif test x"$with_libFLAC_prefix" != x""; then
+ LIBFLAC_LIBS="-L$with_libFLAC_prefix/$XINE_LIBDIRNAME"
+ elif test x"$prefix" != x"NONE"; then
+ LIBFLAC_LIBS="-L$prefix/$XINE_LIBDIRNAME"
+ fi
+ AC_SUBST(LIBFLAC_LIBS)
+
+ ac_save_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $LIBFLAC_CFLAGS"
+ AC_CHECK_LIB([FLAC], [FLAC__stream_decoder_new],
+ [AC_CHECK_HEADERS([FLAC/stream_decoder.h],
+ [have_libflac=yes LIBFLAC_LIBS="$LIBFLAC_LIBS -lFLAC -lm"],
+ [have_libflac=no])],
+ [have_libflac=no], [-lm])
+ CPPFLAGS="$ac_save_CPPFLAGS"
+
+ if test x"$with_libflac" = x"yes" && test x"$have_libflac" != x"yes"; then
+ AC_MSG_ERROR([libFLAC-based decoder support requested, but libFLAC not found])
+ elif test x"$have_libflac" != x"yes"; then
+ LIBFLAC_CFLAGS="" LIBFLAC_LIBS=""
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_LIBFLAC], [test x"$have_libflac" = x"yes"])
+
+
+ dnl libmad (optional; enabled by default; external version allowed)
+ AC_ARG_ENABLE([mad],
+ [AS_HELP_STRING([--enable-mad], [Enable support for MAD decoding library (default: enabled)])],
+ [test x"$enableval" != x"no" && enable_mad="yes"])
+ AC_ARG_WITH([external-libmad],
+ [AS_HELP_STRING([--with-external-libmad], [use external libmad library (not recommended)])],
+ [test x"$withval" != x"no" && with_external_libmad="yes"], [with_external_libmad="no"])
+ if test x"$enable_mad" != x"no"; then
+ if test x"$with_external_libmad" != x"no"; then
+ PKG_CHECK_MODULES([LIBMAD], [mad],
+ [AC_CHECK_HEADERS([mad.h], [have_external_libmad=yes], [have_external_libmad=no])],
+ [have_external_libmad=no])
+ if test x"$have_external_libmad" != x"yes"; then
+ AC_MSG_RESULT([*** no usable version of libmad found, using internal copy ***])
+ fi
+ else
+ AC_MSG_RESULT([Using included libmad support])
+ fi
+ if test x"$have_external_libmad" != x"no"; then
+ case "$host_or_hostalias" in
+ i?86-* | k?-* | athlon-* | pentium*-)
+ AC_DEFINE([FPM_INTEL], 1, [Define to select libmad fixed point arithmetic implementation])
+ ;;
+ x86_64-*)
+ AC_DEFINE([FPM_64BIT], 1, [Define to select libmad fixed point arithmetic implementation])
+ ;;
+ ppc-* | powerpc-*)
+ AC_DEFINE([FPM_PPC], 1, [Define to select libmad fixed point arithmetic implementation])
+ ;;
+ sparc*-*)
+ if test "$GCC" = yes; then
+ AC_DEFINE([FPM_SPARC], 1, [Define to select libmad fixed point arithmetic implementation])
+ else
+ AC_DEFINE([FPM_64BIT], 1, [Define to select libmad fixed point arithmetic implementation])
+ fi
+ ;;
+ mips-*)
+ AC_DEFINE([FPM_MIPS], 1, [Define to select libmad fixed point arithmetic implementation])
+ ;;
+ alphaev56-* | alpha* | ia64-* | hppa*-linux-*)
+ AC_DEFINE([FPM_64BIT], 1, [Define to select libmad fixed point arithmetic implementation])
+ ;;
+ arm*-*)
+ AC_DEFINE([FPM_ARM], 1, [Define to select libmad fixed point arithmetic implementation])
+ ;;
+ universal-*)
+ ;;
+ *)
+ AC_DEFINE([FPM_DEFAULT], 1, [Define to select libmad fixed point arithmetic implementation])
+ ;;
+ esac
+ fi
+ if test x"$have_external_libmad" != x"yes"; then
+ LIBMAD_CFLAGS='-I$(top_srcdir)/contrib/libmad'
+ LIBMAD_LIBS='$(top_builddir)/contrib/libmad/libmad.la'
+ LIBMAD_DEPS='$(top_builddir)/contrib/libmad/libmad.la'
+ fi
+ AC_SUBST(LIBMAD_CFLAGS)
+ AC_SUBST(LIBMAD_DEPS)
+ AC_SUBST(LIBMAD_LIBS)
+ fi
+ AM_CONDITIONAL([ENABLE_MAD], [test x"$enable_mad" != x"no"])
+ AM_CONDITIONAL([WITH_EXTERNAL_MAD], [test x"$have_external_libmad" = x"yes"])
+
+
+ dnl libmodplug (optional; enabled by default)
+ AC_ARG_ENABLE([modplug],
+ [AS_HELP_STRING([--enable-modplug], [Enable MODPlug support (default: enabled)])],
+ [test x"$enableval" != x"no" && enable_modplug="yes"])
+ if test x"$enable_modplug" != x"no"; then
+ PKG_CHECK_MODULES([LIBMODPLUG], [libmodplug >= 0.7], [have_modplug=yes], [have_modplug=no])
+ if test x"$enable_modplug" = x"yes" && test x"$have_modplug" != x"yes"; then
+ AC_MSG_ERROR([MODPlug support requested, but MODPlug not found])
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_MODPLUG], [test x"$have_modplug" = x"yes"])
+
+
+ dnl libmpcdec (optional; enabled by default; external version allowed)
+ AC_ARG_ENABLE([musepack],
+ [AS_HELP_STRING([--enable-musepack], [Enable support for Musepack decoding (default: enabled)])],
+ [test x"$enableval" != x"no" && enable_musepack="yes"])
+ AC_ARG_WITH([external-libmpcdec],
+ [AS_HELP_STRING([--with-external-libmpcdec], [Use external libmpc library])],
+ [test x"$withval" != x"no" && with_external_libmpcdec="yes"], [with_external_libmpcdec="no"])
+ if test x"$enable_musepack" != x"no"; then
+ if test x"$with_external_libmpcdec" != x"no"; then
+ AC_CHECK_LIB([mpcdec], [mpc_decoder_decode],
+ [AC_CHECK_HEADERS([mpcdec/mpcdec.h], [have_external_libmpcdec=yes], [have_external_libmpcdec=no])],
+ [have_external_libmpcdec=no])
+ if test x"$have_external_libmpcdec" != x"yes"; then
+ AC_MSG_RESULT([*** no usable version of libmpcdec found, using internal copy ***])
+ else
+ MPCDEC_CFLAGS=""
+ MPCDEC_DEPS=""
+ MPCDEC_LIBS="-lmpcdec"
+ fi
+ else
+ AC_MSG_RESULT([Using included libmpcdec (Musepack)])
+ fi
+ if test x"$have_external_libmpcdec" != x"yes"; then
+ MPCDEC_CFLAGS='-I$(top_srcdir)/contrib/libmpcdec'
+ MPCDEC_LIBS='$(top_builddir)/contrib/libmpcdec/libmpcdec.la'
+ MPCDEC_DEPS='$(top_builddir)/contrib/libmpcdec/libmpcdec.la'
+ fi
+ AC_SUBST(MPCDEC_CFLAGS)
+ AC_SUBST(MPCDEC_DEPS)
+ AC_SUBST(MPCDEC_LIBS)
+ fi
+ AM_CONDITIONAL([ENABLE_MUSEPACK], [test x"$enable_musepack" != x"no"])
+ AM_CONDITIONAL([WITH_EXTERNAL_LIBMPCDEC], [test x"$have_external_libmpcdec" = x"yes"])
+
+
+ dnl mlib
+ AC_ARG_ENABLE([mlib],
+ [AS_HELP_STRING([--enable-mlib], [do not build Sun mediaLib support (default: enabled)])],
+ [test x"$enableval" != x"no" && enable_mlib="yes"])
+ AC_ARG_ENABLE([mlib-lazyload],
+ [AS_HELP_STRING([--enable-mlib-lazyload], [check for Sun mediaLib at runtime])],
+ [test x"$enableval" != x"no" && enable_mlib_lazyload="yes"], [enable_mlib_lazyload="no"])
+ if test x"$enable_mlib" != x"no"; then
+ mlibhome="$MLIBHOME" test x"$mlibhome" = x"" && mlibhome="/opt/SUNWmlib"
+ AC_CHECK_LIB([mlib], [mlib_VideoAddBlock_U8_S16],
+ [saved_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS -I$mlibhome/include"
+ AC_CHECK_HEADERS([mlib_video.h],
+ [if test x"$enable_mlib_lazyload" != x"no"; then
+ if test "$GCC" = yes; then
+ MLIB_LIBS="-L$mlibhome/lib -Wl,-z,lazyload,-lmlib,-z,nolazyload"
+ else
+ MLIB_LIBS="-L$mlibhome/lib -z lazyload -lmlib -z nolazyload"
+ fi
+ AC_DEFINE([MLIB_LAZYLOAD], 1, [Define this if you want to load mlib lazily])
+ else
+ MLIB_LIBS="-L$mlibhome/lib -lmlib"
+ fi
+ MLIB_CFLAGS="-I$mlibhome/include"
+ AC_SUBST(MLIB_LIBS)
+ AC_SUBST(MLIB_CFLAGS)
+ dnl TODO: src/video_out/yuv2rgb.c and src/xine-utils/cpu_accel.c should be changed to use LIBMPEG2_MLIB
+ dnl and HAVE_MLIB should go away.
+ AC_DEFINE([HAVE_MLIB], 1, [Define this if you have mlib installed])
+ AC_DEFINE([LIBMPEG2_MLIB], 1, [Define this if you have mlib installed])
+ have_mlib=yes])
+ CPPFLAGS="$saved_CPPFLAGS"], [], ["-L$mlibhome/lib"])
+ fi
+ AM_CONDITIONAL([HAVE_MLIB], [test x"$have_mlib" = x"yes"])
+
+
+ dnl mng (optional; enabled by default)
+ AC_ARG_ENABLE([mng],
+ [AS_HELP_STRING([--enable-mng], [Enable MNG decoder support (default: enabled)])],
+ [test x"$enableval" != x"no" && enable_mng="yes"])
+ if test x"$with_mng" != x"no"; then
+ AC_CHECK_LIB([mng], [mng_initialize],
+ [AC_CHECK_HEADERS([libmng.h], [have_mng=yes], [have_mng=no])], [have_mng=no])
+ if test x"$with_mng" = x"yes" && test x"$have_mng" != x"yes"; then
+ AC_MSG_ERROR([MNG support requested, but libmng not found])
+ elif test x"$have_mng" = x"yes"; then
+ MNG_LIBS="-lmng"
+ AC_SUBST(MNG_LIBS)
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_MNG], [test x"$have_mng" = x"yes"])
+
+
+ dnl Ogg/Speex (optional; enabled by default; external)
+ AC_ARG_WITH([speex],
+ [AS_HELP_STRING([--with-speex], [Enable Speex audio decoder support (default: enabled)])],
+ [test x"$withval" != x"no" && with_speex="yes"])
+ if test x"$with_speex" != x"no"; then
+ PKG_CHECK_MODULES([SPEEX], [ogg speex], [have_speex=yes], [have_speex=no])
+ if test x"$with_speex" = x"yes" && test x"$have_speex" != x"yes"; then
+ AC_MSG_ERROR([Speex support requested, but libspeex not found])
+ elif test x"$have_speex" = x"yes"; then
+ AC_DEFINE([HAVE_SPEEX], 1, [Define this if you have speex])
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_SPEEX], [test x"$have_speex" = x"yes"])
+
+
+ dnl Ogg/Theora (optional; enabled by default; external)
+ AC_ARG_WITH([theora],
+ [AS_HELP_STRING([--with-theora], [Enable Theora video decoder support (default: enabled)])],
+ [test x"$withval" != x"no" && with_theora="yes"])
+ if test x"$with_theora" != x"no"; then
+ PKG_CHECK_MODULES([THEORA], [ogg theora], [have_theora=yes], [have_theora=no])
+ if test x"$with_theora" = x"yes" && test x"$have_theora" = x"no"; then
+ AC_MSG_ERROR([Theora support requested, but libtheora not found])
+ elif test x"$have_theora" = x"yes"; then
+ AC_DEFINE([HAVE_THEORA], 1, [Define this if you have theora])
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_THEORA], [test x"$have_theora" = x"yes"])
+
+
+ dnl Ogg/Vorbis (optional; enabled by default; external)
+ AC_ARG_WITH([vorbis],
+ [AS_HELP_STRING([--with-vorbis], [Enable Vorbis audio decoder support (default: enabled)])],
+ [test x"$withval" != x"no" && with_vorbis="yes"])
+ if test x"$with_vorbis" != x"no"; then
+ PKG_CHECK_MODULES([VORBIS], [ogg vorbis], [have_vorbis=yes], [have_vorbis=no])
+ if test x"$with_vorbis" = x"yes" && test x"$have_vorbis" = "xno"; then
+ AC_MSG_ERROR([Vorbis support requested, but libvorbis not found])
+ elif test x"$have_vorbis" = x"yes"; then
+ AC_DEFINE([HAVE_VORBIS], 1, [Define this if you have vorbis])
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_VORBIS], [test x"$have_vorbis" = x"yes"])
+
+
+ dnl real (optional; enabled by default)
+ dnl On some systems, we cannot enable Real codecs support to begin with.
+ dnl This includes Darwin, because it uses Mach-O rather than ELF.
+ AC_ARG_ENABLE([real-codecs],
+ [AS_HELP_STRING([--enable-real-codecs], [Enable Real binary codecs support (default: enabled)])],
+ [test x"$enableval" != x"no" && enable_real_codecs="yes"])
+ AC_ARG_WITH([real-codecs-path],
+ [AS_HELP_STRING([--with-real-codecs-path=PATH], [Specify directory for Real binary codecs])])
+ if test x"$enable_real_codecs" != x"no"; then
+ case "$host_os" in
+ darwin*) have_real_codecs=no ;;
+ *)
+ have_real_codecs=yes
+
+ dnl For those that have a replacement, break at the first one found
+ AC_CHECK_SYMBOLS([__environ _environ environ], [break], [need_weak_aliases=yes])
+ AC_CHECK_SYMBOLS([stderr __stderrp], [break], [need_weak_aliases=yes])
+
+ dnl For these there are no replacements
+ AC_CHECK_SYMBOLS([___brk_addr __ctype_b])
+
+ if test x"$need_weak_aliases" = x"yes"; then
+ CC_ATTRIBUTE_ALIAS([], [have_real_codecs=no])
+ fi
+ ;;
+ esac
+ if test x"$enable_real_codecs" = x"yes" && test x"$have_real_codecs" != x"yes"; then
+ AC_MSG_ERROR([Binary Real codec support requested, but it is not available])
+ elif test x"$have_real_codecs" = x"yes"; then
+ if test "${with_real_codecs_path+set}" = "set"; then
+ AC_DEFINE_UNQUOTED([REAL_CODEC_PATH], ["$with_real_codecs_path"], [Default path in which to find Real binary codecs])
+ fi
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_REAL], [test x"$have_real_codecs" = x"yes"])
+
+
+ dnl w32dll (optional; x86 only; enabled if using GNU as; GNU as required)
+ AC_ARG_ENABLE([w32dll],
+ [AS_HELP_STRING([--enable-w32dll], [Enable Win32 DLL support (default: enabled)])],
+ [test x"$enableval" != x"no" && enable_w32dll="yes"],
+ [test x"$with_gnu_as" != x"yes" && enable_w32dll="no"])
+ AC_ARG_WITH([w32-path],
+ [AS_HELP_STRING([--with-w32-path=PATH], [location of Win32 binary codecs])],
+ [w32_path="$withval"], [w32_path="/usr/lib/codecs"])
+ if test x"$enable_w32dll" != x"no"; then
+ case "$host_or_hostalias" in
+ *-mingw* | *-cygwin) have_w32dll=no ;;
+ i?86-* | k?-* | athlon-* | pentium*-) have_w32dll="$with_gnu_as" ;;
+ *) enable_w32dll=no ;;
+ esac
+ if test x"$enable_w32dll" = x"yes" && test x"$have_w32dll" != x"yes"; then
+ AC_MSG_ERROR([Win32 DLL support requested, but Win32 DLL support is not available])
+ fi
+ fi
+ AC_SUBST(w32_path)
+ AM_CONDITIONAL([ENABLE_W32DLL], [test x"$have_w32dll" = x"yes"])
+
+
+ dnl wavpack (optional; disabled by default)
+ AC_ARG_WITH([wavpack],
+ [AS_HELP_STRING([--with-wavpack], [Enable Wavpack decoder (requires libwavpack)])],
+ [test x"$withval" != x"no" && with_wavpack="yes"], [with_wavpack="no"])
+ if test x"$with_wavpack" != x"no"; then
+ PKG_CHECK_MODULES([WAVPACK], [wavpack], [have_wavpack=yes], [have_wavpack=no])
+ if test x"$with_wavpack" = x"yes" && test x"$have_wavpack" != x"yes"; then
+ AC_MSG_ERROR([Wavpack decoder support requested, but libwavpack not found])
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_WAVPACK], [test x"$have_wavpack" = x"yes"])
+
+
+ dnl Only enable building dmx image if either gdk_pixbuf or ImageMagick are enabled
+ AM_CONDITIONAL([BUILD_DMX_IMAGE], [test x"$have_imagemagick" = x"yes" -o x"$have_gdkpixbuf" = x"yes"])
+])
diff --git a/m4/directx.m4 b/m4/directx.m4
index 6d023528e..4417023ee 100644
--- a/m4/directx.m4
+++ b/m4/directx.m4
@@ -10,62 +10,40 @@ dnl It looks for DirectX, defines DIRECTX_CPPFLAGS, DIRECTX_AUDIO_LIBS and
dnl DIRECTX_VIDEO_LIBS.
dnl
AC_DEFUN([AM_PATH_DIRECTX], [
-
-AC_ARG_WITH(dxheaders, AS_HELP_STRING([--with-dxheaders], [specify location of DirectX headers]),
- [dxheaders_prefix="$withval"],
- [dxheaders_prefix="no"]
-)
-
-if test x"$dxheaders_prefix" != "xno"; then
- DIRECTX_CPPFLAGS="-I${dxheaders_prefix} ${DIRECTX_CPPFLAGS}"
-fi
-
-AC_MSG_CHECKING(for DirectX)
-DIRECTX_VIDEO_LIBS="$DIRECTX_LIBS -lgdi32 -lddraw"
-DIRECTX_AUDIO_LIBS="$DIRECTX_LIBS -ldsound"
-AC_LANG_PUSH([C])
-ac_save_CPPFLAGS="$CPPFLAGS"
-ac_save_LIBS="$LIBS"
-CPPFLAGS="$CPPFLAGS $DIRECTX_CPPFLAGS"
-LIBS="$LIBS $DIRECTX_VIDEO_LIBS $DIRECTX_AUDIO_LIBS"
-AC_COMPILE_IFELSE(
- [
-#include <stddef.h>
-
-#include <windows.h>
-#include <ddraw.h>
-#include <dsound.h>
-
-int main() {
- DirectDrawCreate(0, NULL, 0);
- DirectsoundCreate(0, NULL, 0);
-
- return 0;
-}
- ],
- [have_directx=yes
- AC_DEFINE(HAVE_DIRECTX,1,[Define this if you have DirectX])],,)
-CPPFLAGS=$ac_save_CPPFLAGS
-LIBS=$ac_save_LIBS
-AC_LANG_POP([C])
-
-if test x$have_directx = xyes ; then
- AC_MSG_RESULT(yes)
-else
- AC_MSG_RESULT(no)
- AC_MSG_RESULT(*** All DirectX dependent parts will be disabled ***)
-fi
-
-AC_SUBST(DIRECTX_CPPFLAGS)
-AC_SUBST(DIRECTX_AUDIO_LIBS)
-AC_SUBST(DIRECTX_VIDEO_LIBS)
-AM_CONDITIONAL(HAVE_DIRECTX, test x$have_directx = "xyes")
-
-dnl result
-if test x"$have_directx" = "xyes"; then
- ifelse([$1], , :, [$1])
-else
- ifelse([$2], , :, [$2])
-fi
-
+ AC_ARG_WITH([dxheaders],
+ [AS_HELP_STRING([--with-dxheaders], [specify location of DirectX headers])],
+ [dxheaders_prefix="$withval"], [dxheaders_prefix="no"])
+ if test x"$dxheaders_prefix" != x"no"; then
+ DIRECTX_CPPFLAGS="-I$dxheaders_prefix $DIRECTX_CPPFLAGS"
+ fi
+
+ AC_MSG_CHECKING([for DirectX])
+ DIRECTX_AUDIO_LIBS="$DIRECTX_LIBS -ldsound"
+ DIRECTX_VIDEO_LIBS="$DIRECTX_LIBS -lgdi32 -lddraw"
+
+ AC_LANG_PUSH([C])
+ ac_save_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $DIRECTX_CPPFLAGS"
+ ac_save_LIBS="$LIBS" LIBS="$LIBS $DIRECTX_VIDEO_LIBS $DIRECTX_AUDIO_LIBS"
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stddef.h>
+ #include <windows.h>
+ #include <ddraw.h>
+ #include <dsound.h>]],
+ [[DirectDrawCreate(0, NULL, 0); DirectsoundCreate(0, NULL, 0)]])],
+ [have_directx=yes], [have_directx=no])
+ CPPFLAGS="$ac_save_CPPFLAGS"
+ LIBS="$ac_save_LIBS"
+ AC_LANG_POP([C])
+
+ AC_SUBST(DIRECTX_CPPFLAGS)
+ AC_SUBST(DIRECTX_AUDIO_LIBS)
+ AC_SUBST(DIRECTX_VIDEO_LIBS)
+ AM_CONDITIONAL([ENABLE_DIRECTX], [test x"$have_directx" = x"yes"])
+
+ AC_MSG_RESULT([$have_directx])
+ if test x"$have_directx" = x"yes"; then
+ AC_DEFINE([HAVE_DIRECTX], 1, [Define this if you have DirectX])
+ ifelse([$1], , :, [$1])
+ else
+ ifelse([$2], , :, [$2])
+ fi
])
diff --git a/m4/dl.m4 b/m4/dl.m4
deleted file mode 100644
index 30ea00b1c..000000000
--- a/m4/dl.m4
+++ /dev/null
@@ -1,53 +0,0 @@
-dnl
-dnl Check for dlopen symbol and set DYNAMIC_LD_LIBS.
-dnl
-dnl AM_DL()
-dnl
-
-AC_DEFUN([AM_DL], [
- AC_CHECK_LIB(c, dlopen,
- [DYNAMIC_LD_LIBS=""
- have_dl=yes])
-
- if test x$have_dl != "xyes"; then
- AC_CHECK_LIB(dl, dlopen,
- [DYNAMIC_LD_LIBS="-ldl"
- have_dl=yes])
- fi
-
- if test x$have_dl != "xyes"; then
- AC_MSG_CHECKING(for dlopen under win32)
- AC_LANG_PUSH([C])
-
- ac_save_CPPFLAGS="$CPPFLAGS"
- ac_save_LIBS="$LIBS"
- CPPFLAGS="-I${srcdir}/win32/include $CPPFLAGS"
- LIBS="$LIBS -lkernel32"
- AC_COMPILE_IFELSE([
-#include <stddef.h>
-#include <dlfcn.h>
-
-int main() {
- dlopen(NULL, 0);
- return 0;
-}
-],
- [DYNAMIC_LD_LIBS=-lkernel32
- have_dl=yes
- AC_MSG_RESULT(yes)],
- AC_MSG_RESULT(no)
- )
-
- CPPFLAGS=$ac_save_CPPFLAGS
- LIBS=$ac_save_LIBS
-
- AC_LANG_POP([C])
- fi
-
- if test x$have_dl != "xyes"; then
- AC_MSG_ERROR(dynamic linker needed)
- fi
-
- AC_SUBST(DYNAMIC_LD_LIBS)
-
-])
diff --git a/m4/dvdnav.m4 b/m4/dvdnav.m4
deleted file mode 100644
index 0f24080f7..000000000
--- a/m4/dvdnav.m4
+++ /dev/null
@@ -1,187 +0,0 @@
-dnl Configure paths for DVDNAV
-dnl
-dnl Copyright (C) 2001 Daniel Caujolle-Bert <segfault@club-internet.fr>
-dnl
-dnl This program is free software; you can redistribute it and/or modify
-dnl it under the terms of the GNU General Public License as published by
-dnl the Free Software Foundation; either version 2 of the License, or
-dnl (at your option) any later version.
-dnl
-dnl This program is distributed in the hope that it will be useful,
-dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
-dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-dnl GNU General Public License for more details.
-dnl
-dnl You should have received a copy of the GNU General Public License
-dnl along with this program; if not, write to the Free Software
-dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-dnl
-dnl
-dnl As a special exception to the GNU General Public License, if you
-dnl distribute this file as part of a program that contains a configuration
-dnl script generated by Autoconf, you may include it under the same
-dnl distribution terms that you use for the rest of that program.
-dnl
-
-dnl AM_PATH_DVDNAV([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
-dnl Test for DVDNAV, and define DVDNAV_CFLAGS and DVDNAV_LIBS
-dnl
-AC_DEFUN([AM_PATH_DVDNAV],
-[dnl
-dnl Get the cflags and libraries from the dvdnav-config script
-dnl
-AC_ARG_WITH(dvdnav-prefix,
- AS_HELP_STRING([--with-dvdnav-prefix=DIR], [prefix where DVDNAV is installed (optional)]),
- dvdnav_config_prefix="$withval", dvdnav_config_prefix="")
-AC_ARG_WITH(dvdnav-exec-prefix,
- AS_HELP_STRING([--with-dvdnav-exec-prefix=DIR], [exec prefix where DVDNAV is installed (optional)]),
- dvdnav_config_exec_prefix="$withval", dvdnav_config_exec_prefix="")
-AC_ARG_ENABLE(dvdnavtest,
- AS_HELP_STRING([--disable-dvdnavtest], [do not try to compile and run a test DVDNAV program]),
- enable_dvdnavtest=$enableval, enable_dvdnavtest=yes)
-
- AC_LANG_PUSH([C])
-
- if test x$dvdnav_config_exec_prefix != x ; then
- dvdnav_config_args="$dvdnav_config_args --exec-prefix=$dvdnav_config_exec_prefix"
- if test x${DVDNAV_CONFIG+set} != xset ; then
- DVDNAV_CONFIG=$dvdnav_config_exec_prefix/bin/dvdnav-config
- fi
- fi
- if test x$dvdnav_config_prefix != x ; then
- dvdnav_config_args="$dvdnav_config_args --prefix=$dvdnav_config_prefix"
- if test x${DVDNAV_CONFIG+set} != xset ; then
- DVDNAV_CONFIG=$dvdnav_config_prefix/bin/dvdnav-config
- fi
- fi
-
- min_dvdnav_version=ifelse([$1], ,0.0.0,$1)
- if test "x$enable_dvdnavtest" != "xyes" ; then
- AC_MSG_CHECKING([for DVDNAV-LIB version >= $min_dvdnav_version])
- else
- AC_PATH_TOOL(DVDNAV_CONFIG, dvdnav-config, no)
- AC_MSG_CHECKING([for DVDNAV-LIB version >= $min_dvdnav_version])
- no_dvdnav=""
- if test "$DVDNAV_CONFIG" = "no" ; then
- no_dvdnav=yes
- else
- DVDNAV_CFLAGS=`$DVDNAV_CONFIG $dvdnav_config_args --cflags`
- DVDNAV_LIBS=`$DVDNAV_CONFIG $dvdnav_config_args --libs`
- dvdnav_config_major_version=`$DVDNAV_CONFIG $dvdnav_config_args --version | \
- sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
- dvdnav_config_minor_version=`$DVDNAV_CONFIG $dvdnav_config_args --version | \
- sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
- dvdnav_config_sub_version=`$DVDNAV_CONFIG $dvdnav_config_args --version | \
- sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
- dnl if test "x$enable_dvdnavtest" = "xyes" ; then
- ac_save_CFLAGS="$CFLAGS"
- ac_save_LIBS="$LIBS"
- CFLAGS="$CFLAGS $DVDNAV_CFLAGS"
- LIBS="$DVDNAV_LIBS $LIBS"
-dnl
-dnl Now check if the installed DVDNAV is sufficiently new. (Also sanity
-dnl checks the results of dvdnav-config to some extent
-dnl
- rm -f conf.dvdnavtest
- AC_RUN_IFELSE([AC_LANG_SOURCE([[
-#include <dvdnav.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-int
-main ()
-{
- int major, minor, sub;
- char *tmp_version;
-
- system ("touch conf.dvdnavtest");
-
- /* HP/UX 9 (%@#!) writes to sscanf strings */
- tmp_version = (char *) strdup("$min_dvdnav_version");
- if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &sub) != 3) {
- printf("%s, bad version string\n", "$min_dvdnav_version");
- exit(1);
- }
-
- if (($dvdnav_config_major_version > major) ||
- (($dvdnav_config_major_version == major) && ($dvdnav_config_minor_version > minor)) ||
- (($dvdnav_config_major_version == major) && ($dvdnav_config_minor_version == minor) && ($dvdnav_config_sub_version >= sub))) {
- return 0;
- } else {
- printf("\n*** An old version of libdvdnav (%d.%d.%d) was found.\n",
- $dvdnav_config_major_version, $dvdnav_config_minor_version, $dvdnav_config_sub_version);
- printf("*** You need a version of libdvdnav newer than %d.%d.%d. The latest version of\n",
- major, minor, sub);
- printf("*** libdvdnav is always available from:\n");
- printf("*** http://dvd.sourceforge.net\n");
- printf("***\n");
- printf("*** If you have already installed a sufficiently new version, this error\n");
- printf("*** probably means that the wrong copy of the dvdnav-config shell script is\n");
- printf("*** being found. The easiest way to fix this is to remove the old version\n");
- printf("*** of libdvdnav, but you can also set the DVDNAV_CONFIG environment to point to the\n");
- printf("*** correct copy of dvdnav-config. (In this case, you will have to\n");
- printf("*** modify your LD_LIBRARY_PATH enviroment variable, or edit /etc/ld.so.conf\n");
- printf("*** so that the correct libraries are found at run-time))\n");
- }
- return 1;
-}
-]])],[],[no_dvdnav=yes],[no_dvdnav=cc])
- if test "x$no_dvdnav" = xcc; then
- AC_LINK_IFELSE([AC_LANG_PROGRAM([[
-#include <dvdnav.h>
-#include <stdio.h>
-]], [[ return 0; ]])],[no_dvdnav=''],[no_dvdnav=yes])
- fi
- CFLAGS="$ac_save_CFLAGS"
- LIBS="$ac_save_LIBS"
- fi
- fi
- if test "x$no_dvdnav" = x ; then
- AC_MSG_RESULT(yes)
- ifelse([$2], , :, [$2])
- else
- AC_MSG_RESULT(no)
- if test "$DVDNAV_CONFIG" = "no" ; then
- echo "*** The dvdnav-config script installed by DVDNAV could not be found"
- echo "*** If DVDNAV was installed in PREFIX, make sure PREFIX/bin is in"
- echo "*** your path, or set the DVDNAV_CONFIG environment variable to the"
- echo "*** full path to dvdnav-config."
- else
- if test -f conf.dvdnavtest ; then
- :
- else
- echo "*** Could not run DVDNAV test program, checking why..."
- CFLAGS="$CFLAGS $DVDNAV_CFLAGS"
- LIBS="$LIBS $DVDNAV_LIBS"
- AC_LINK_IFELSE([AC_LANG_PROGRAM([[
-#include <dvdnav.h>
-#include <stdio.h>
-]], [[ return 0; ]])],
- [ echo "*** The test program compiled, but did not run. This usually means"
- echo "*** that the run-time linker is not finding DVDNAV or finding the wrong"
- echo "*** version of DVDNAV. If it is not finding DVDNAV, you'll need to set your"
- echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
- echo "*** to the installed location Also, make sure you have run ldconfig if that"
- echo "*** is required on your system"
- echo "***"
- echo "*** If you have an old version installed, it is best to remove it, although"
- echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"
- echo "***"],
- [ echo "*** The test program failed to compile or link. See the file config.log for the"
- echo "*** exact error that occured. This usually means DVDNAV was incorrectly installed"
- echo "*** or that you have moved DVDNAV since it was installed. In the latter case, you"
- echo "*** may want to edit the dvdnav-config script: $DVDNAV_CONFIG" ])
- CFLAGS="$ac_save_CFLAGS"
- LIBS="$ac_save_LIBS"
- fi
- fi
- DVDNAV_CFLAGS=""
- DVDNAV_LIBS=""
- ifelse([$3], , :, [$3])
- fi
- AC_SUBST(DVDNAV_CFLAGS)
- AC_SUBST(DVDNAV_LIBS)
- AC_LANG_POP([C])
- rm -f conf.dvdnavtest
-])
diff --git a/m4/gas.m4 b/m4/gas.m4
index 923c3f90c..a3c600793 100644
--- a/m4/gas.m4
+++ b/m4/gas.m4
@@ -10,111 +10,98 @@ dnl modifications, as long as this notice is preserved.
dnl AC_PROG_AS
dnl ----------
dnl find the pathname to the GNU or non-GNU assembler
-AC_DEFUN([CC_PROG_AS],
-[AC_ARG_WITH([gnu-as],
- [AS_HELP_STRING([--with-gnu-as],
- [assume the C compiler uses GNU as @<:@default=no@:>@])],
- [test "$withval" = no || with_gnu_as=yes],
- [with_gnu_as=no])
-AC_REQUIRE([LT_AC_PROG_SED])dnl
-AC_REQUIRE([AC_PROG_CC])dnl
-AC_REQUIRE([AC_CANONICAL_HOST])dnl
-AC_REQUIRE([AC_CANONICAL_BUILD])dnl
-cc_prog=as
-if test "$GCC" = yes; then
- # Check if gcc -print-prog-name=as gives a path.
- AC_MSG_CHECKING([for as used by $CC])
- case $host in
- *-*-mingw*)
- # gcc leaves a trailing carriage return which upsets mingw
- ac_prog=`($CC -print-prog-name=as) 2>&5 | tr -d '\015'` ;;
- *)
- ac_prog=`($CC -print-prog-name=as) 2>&5` ;;
- esac
- case $ac_prog in
- # Accept absolute paths.
- [[\\/]]* | ?:[[\\/]]*)
- re_direlt='/[[^/]][[^/]]*/\.\./'
- # Canonicalize the pathname of as
- ac_prog=`echo $ac_prog| $SED 's%\\\\%/%g'`
- while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do
- ac_prog=`echo $ac_prog| $SED "s%$re_direlt%/%"`
- done
- test -z "$AS" && AS="$ac_prog"
- ;;
- "")
- # If it fails, then pretend we aren't using GCC.
- ac_prog=as
- ;;
- *)
- # If it is relative, then search for the first as in PATH.
- with_gnu_as=unknown
- ;;
- esac
-elif test "$with_gnu_as" = yes; then
- AC_MSG_CHECKING([for GNU as])
-else
- AC_MSG_CHECKING([for non-GNU as])
-fi
-AC_CACHE_VAL(cc_cv_path_AS,
-[if test -z "$AS"; then
- lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
- for ac_dir in $PATH; do
- IFS="$lt_save_ifs"
- test -z "$ac_dir" && ac_dir=.
- if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
- lt_cv_path_AS="$ac_dir/$ac_prog"
- # Check to see if the program is GNU as. I'd rather use --version,
- # but apparently some variants of GNU as only accept -v.
- # Break only if it was the GNU/non-GNU as that we prefer.
- case `"$cc_cv_path_AS" -v 2>&1 </dev/null` in
- dnl Apple's assembler reports itself as GNU as 1.38;
- dnl but it doesn't provide the functions we need.
- *Apple*)
- test "$with_gnu_as" != yes && break
- ;;
- *GNU* | *'with BFD'*)
- test "$with_gnu_as" != no && break
- ;;
- *)
- test "$with_gnu_as" != yes && break
- ;;
- esac
- fi
- done
- IFS="$lt_save_ifs"
-else
- cc_cv_path_AS="$AS" # Let the user override the test with a path.
-fi])
-AS="$cc_cv_path_AS"
-if test -n "$AS"; then
- AC_MSG_RESULT($AS)
-else
- AC_MSG_RESULT(no)
-fi
-test -z "$AS" && AC_MSG_ERROR([no acceptable as found in \$PATH])
-CC_PROG_AS_GNU
-])
+dnl based on AC_PROG_LD from libtool
+AC_DEFUN([CC_PROG_AS], [
+ AC_REQUIRE([LT_AC_PROG_SED])dnl
+ AC_REQUIRE([AC_PROG_CC])dnl
+ AC_REQUIRE([AM_PROG_AS])dnl
+ AC_REQUIRE([AC_CANONICAL_HOST])dnl
+ AC_REQUIRE([AC_CANONICAL_BUILD])dnl
+
+ AC_ARG_WITH([gnu-as],
+ [AS_HELP_STRING([--with-gnu-as], [assume the C compiler uses GNU as @<:@default=no@:>@])],
+ [test "$withval" = no || with_gnu_as=yes], [with_gnu_as=unknown])
+ if test x"$with_gnu_as" = x"unknown"; then
+ dnl If CCAS is not the same as CC, check to see if it's GCC.
+ if test x"$CCAS" = x"$CC"; then
+ ccas_is_gnu="$GCC"
+ else
+ AC_CACHE_CHECK([whether $CCAS is a GNU compiler], [ac_cv_CCAS_compiler_gnu],
+ [saved_CC="$CC" CC="$CCAS"
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[#ifndef __GNUC__
+ choke me
+ #endif]])],
+ [ac_cv_CCAS_compiler_gnu=yes], [ac_cv_CCAS_compiler_gnu=no])
+ CC="$saved_CC"])
+ ccas_is_gnu="$ac_cv_CCAS_compiler_gnu"
+ fi
+ dnl Try to figure out the assembler command. Fallback to as.
+ ac_prog=""
+ if test x"$AS" = x""; then
+ AC_MSG_CHECKING([for as used by $CCAS])
+ if test x"$ccas_is_gnu" = x"yes"; then
+ # Check if gcc -print-prog-name=as gives a path.
+ case "$host_or_hostalias" in
+ *-*-mingw*)
+ # gcc leaves a trailing carriage return which upsets mingw
+ ac_prog=`($CCAS -print-prog-name=as) 2>&5 | tr -d '\015'`
+ ;;
+ *)
+ ac_prog=`($CCAS -print-prog-name=as) 2>&5`
+ ;;
+ esac
+
+ case "$ac_prog" in
+ # Accept absolute paths.
+ [[\\/]]* | ?:[[\\/]]*)
+ re_direlt='/[[^/]][[^/]]*/\.\./'
+ # Canonicalize the pathname of as
+ ac_prog=`echo $ac_prog| $SED 's%\\\\%/%g'`
+ while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do
+ ac_prog=`echo $ac_prog| $SED "s%$re_direlt%/%"`
+ done
+ ;;
+ *) ac_prog="" ;;
+ esac
+ fi
+ fi
+ if test x"$ac_prog" = x""; then
+ # If it fails, then pretend we aren't using GCC.
+ lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+ for ac_dir in $PATH; do
+ IFS="$lt_save_ifs"
+ test -z "$ac_dir" && ac_dir=.
+ if test -f "$ac_dir/as" || test -f "$ac_dir/as$ac_exeext"; then
+ ac_prog="$ac_dir/as"
+ break
+ fi
+ done
+ IFS="$lt_save_ifs"
+ fi
+ if test x"$ac_prog" = x""; then
+ AC_MSG_RESULT([unknown])
+ else
+ AS="$ac_prog"
+ AC_MSG_RESULT([$AS])
+ fi
+ fi
-dnl AC_PROG_AS_GNU
-dnl --------------
-AC_DEFUN([CC_PROG_AS_GNU],
-[AC_REQUIRE([AC_PROG_EGREP])dnl
-AC_CACHE_CHECK([if the assembler ($AS) is GNU as], cc_cv_prog_gnu_as,
-[# I'd rather use --version here, but apparently some GNU as's only accept -v.
-case `$AS -v 2>&1 </dev/null` in
-dnl Apple's assembler reports itself as GNU as 1.38;
-dnl but it doesn't provide the functions we need.
-*Apple*)
- cc_cv_prog_gnu_as=no
- ;;
-*GNU* | *'with BFD'*)
- cc_cv_prog_gnu_as=yes
- ;;
-*)
- cc_cv_prog_gnu_as=no
- ;;
-esac])
-with_gnu_as=$cc_cv_prog_gnu_as
+ test -z "$AS" && AC_MSG_ERROR([no acceptable as found in \$PATH])
+ AC_CACHE_CHECK([if the assembler ($AS) is GNU as], [cc_cv_prog_gnu_as], [
+ # I'd rather use --version here, but apparently some GNU as's only accept -v.
+ case `"$AS" -v 2>&1 </dev/null` in
+ *Apple*)
+ # Apple's assembler reports itself as GNU as 1.38;
+ # but it doesn't provide the functions we need.
+ cc_cv_prog_gnu_as=no
+ ;;
+ *GNU* | *'with BFD'*)
+ cc_cv_prog_gnu_as=yes
+ ;;
+ *)
+ cc_cv_prog_gnu_as=no
+ ;;
+ esac])
+ with_gnu_as="$cc_cv_prog_gnu_as"
])
diff --git a/m4/gettext.m4 b/m4/gettext.m4
deleted file mode 100644
index 624a80785..000000000
--- a/m4/gettext.m4
+++ /dev/null
@@ -1,549 +0,0 @@
-# gettext.m4 serial 37 (gettext-0.14.4)
-dnl Copyright (C) 1995-2005 Free Software Foundation, Inc.
-dnl This file is free software; the Free Software Foundation
-dnl gives unlimited permission to copy and/or distribute it,
-dnl with or without modifications, as long as this notice is preserved.
-dnl
-dnl This file can can be used in projects which are not available under
-dnl the GNU General Public License or the GNU Library General Public
-dnl License but which still want to provide support for the GNU gettext
-dnl functionality.
-dnl Please note that the actual code of the GNU gettext library is covered
-dnl by the GNU Library General Public License, and the rest of the GNU
-dnl gettext package package is covered by the GNU General Public License.
-dnl They are *not* in the public domain.
-
-dnl Authors:
-dnl Ulrich Drepper <drepper@cygnus.com>, 1995-2000.
-dnl Bruno Haible <haible@clisp.cons.org>, 2000-2003.
-
-dnl Macro to add for using GNU gettext.
-
-dnl Usage: AM_GNU_GETTEXT([INTLSYMBOL], [NEEDSYMBOL], [INTLDIR]).
-dnl INTLSYMBOL can be one of 'external', 'no-libtool', 'use-libtool'. The
-dnl default (if it is not specified or empty) is 'no-libtool'.
-dnl INTLSYMBOL should be 'external' for packages with no intl directory,
-dnl and 'no-libtool' or 'use-libtool' for packages with an intl directory.
-dnl If INTLSYMBOL is 'use-libtool', then a libtool library
-dnl $(top_builddir)/intl/libintl.la will be created (shared and/or static,
-dnl depending on --{enable,disable}-{shared,static} and on the presence of
-dnl AM-DISABLE-SHARED). If INTLSYMBOL is 'no-libtool', a static library
-dnl $(top_builddir)/intl/libintl.a will be created.
-dnl If NEEDSYMBOL is specified and is 'need-ngettext', then GNU gettext
-dnl implementations (in libc or libintl) without the ngettext() function
-dnl will be ignored. If NEEDSYMBOL is specified and is
-dnl 'need-formatstring-macros', then GNU gettext implementations that don't
-dnl support the ISO C 99 <inttypes.h> formatstring macros will be ignored.
-dnl INTLDIR is used to find the intl libraries. If empty,
-dnl the value `$(top_builddir)/intl/' is used.
-dnl
-dnl The result of the configuration is one of three cases:
-dnl 1) GNU gettext, as included in the intl subdirectory, will be compiled
-dnl and used.
-dnl Catalog format: GNU --> install in $(datadir)
-dnl Catalog extension: .mo after installation, .gmo in source tree
-dnl 2) GNU gettext has been found in the system's C library.
-dnl Catalog format: GNU --> install in $(datadir)
-dnl Catalog extension: .mo after installation, .gmo in source tree
-dnl 3) No internationalization, always use English msgid.
-dnl Catalog format: none
-dnl Catalog extension: none
-dnl If INTLSYMBOL is 'external', only cases 2 and 3 can occur.
-dnl The use of .gmo is historical (it was needed to avoid overwriting the
-dnl GNU format catalogs when building on a platform with an X/Open gettext),
-dnl but we keep it in order not to force irrelevant filename changes on the
-dnl maintainers.
-dnl
-AC_DEFUN([AM_GNU_GETTEXT],
-[
- dnl Argument checking.
- ifelse([$1], [], , [ifelse([$1], [external], , [ifelse([$1], [no-libtool], , [ifelse([$1], [use-libtool], ,
- [errprint([ERROR: invalid first argument to AM_GNU_GETTEXT
-])])])])])
- ifelse([$2], [], , [ifelse([$2], [need-ngettext], , [ifelse([$2], [need-formatstring-macros], ,
- [errprint([ERROR: invalid second argument to AM_GNU_GETTEXT
-])])])])
- define([gt_included_intl], ifelse([$1], [external], [no], [yes]))
- define([gt_libtool_suffix_prefix], ifelse([$1], [use-libtool], [l], []))
-
- AC_REQUIRE([AM_PO_SUBDIRS])dnl
- ifelse(gt_included_intl, yes, [
- AC_REQUIRE([AM_INTL_SUBDIR])dnl
- ])
-
- dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
- AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
- AC_REQUIRE([AC_LIB_RPATH])
-
- dnl Sometimes libintl requires libiconv, so first search for libiconv.
- dnl Ideally we would do this search only after the
- dnl if test "$USE_NLS" = "yes"; then
- dnl if test "$gt_cv_func_gnugettext_libc" != "yes"; then
- dnl tests. But if configure.in invokes AM_ICONV after AM_GNU_GETTEXT
- dnl the configure script would need to contain the same shell code
- dnl again, outside any 'if'. There are two solutions:
- dnl - Invoke AM_ICONV_LINKFLAGS_BODY here, outside any 'if'.
- dnl - Control the expansions in more detail using AC_PROVIDE_IFELSE.
- dnl Since AC_PROVIDE_IFELSE is only in autoconf >= 2.52 and not
- dnl documented, we avoid it.
- ifelse(gt_included_intl, yes, , [
- AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY])
- ])
-
- dnl Sometimes, on MacOS X, libintl requires linking with CoreFoundation.
- gt_INTL_MACOSX
-
- dnl Set USE_NLS.
- AM_NLS
-
- ifelse(gt_included_intl, yes, [
- BUILD_INCLUDED_LIBINTL=no
- USE_INCLUDED_LIBINTL=no
- ])
- LIBINTL=
- LTLIBINTL=
- POSUB=
-
- dnl If we use NLS figure out what method
- if test "$USE_NLS" = "yes"; then
- gt_use_preinstalled_gnugettext=no
- ifelse(gt_included_intl, yes, [
- AC_MSG_CHECKING([whether included gettext is requested])
- AC_ARG_WITH(included-gettext,
- [ --with-included-gettext use the GNU gettext library included here],
- nls_cv_force_use_gnu_gettext=$withval,
- nls_cv_force_use_gnu_gettext=no)
- AC_MSG_RESULT($nls_cv_force_use_gnu_gettext)
-
- nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext"
- if test "$nls_cv_force_use_gnu_gettext" != "yes"; then
- ])
- dnl User does not insist on using GNU NLS library. Figure out what
- dnl to use. If GNU gettext is available we use this. Else we have
- dnl to fall back to GNU NLS library.
-
- dnl Add a version number to the cache macros.
- define([gt_api_version], ifelse([$2], [need-formatstring-macros], 3, ifelse([$2], [need-ngettext], 2, 1)))
- define([gt_cv_func_gnugettext_libc], [gt_cv_func_gnugettext]gt_api_version[_libc])
- define([gt_cv_func_gnugettext_libintl], [gt_cv_func_gnugettext]gt_api_version[_libintl])
-
- AC_CACHE_CHECK([for GNU gettext in libc], gt_cv_func_gnugettext_libc,
- [AC_TRY_LINK([#include <libintl.h>
-]ifelse([$2], [need-formatstring-macros],
-[#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
-#define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1)
-#endif
-changequote(,)dnl
-typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1];
-changequote([,])dnl
-], [])[extern int _nl_msg_cat_cntr;
-extern int *_nl_domain_bindings;],
- [bindtextdomain ("", "");
-return * gettext ("")]ifelse([$2], [need-ngettext], [ + * ngettext ("", "", 0)], [])[ + _nl_msg_cat_cntr + *_nl_domain_bindings],
- gt_cv_func_gnugettext_libc=yes,
- gt_cv_func_gnugettext_libc=no)])
-
- if test "$gt_cv_func_gnugettext_libc" != "yes"; then
- dnl Sometimes libintl requires libiconv, so first search for libiconv.
- ifelse(gt_included_intl, yes, , [
- AM_ICONV_LINK
- ])
- dnl Search for libintl and define LIBINTL, LTLIBINTL and INCINTL
- dnl accordingly. Don't use AC_LIB_LINKFLAGS_BODY([intl],[iconv])
- dnl because that would add "-liconv" to LIBINTL and LTLIBINTL
- dnl even if libiconv doesn't exist.
- AC_LIB_LINKFLAGS_BODY([intl])
- AC_CACHE_CHECK([for GNU gettext in libintl],
- gt_cv_func_gnugettext_libintl,
- [gt_save_CPPFLAGS="$CPPFLAGS"
- CPPFLAGS="$CPPFLAGS $INCINTL"
- gt_save_LIBS="$LIBS"
- LIBS="$LIBS $LIBINTL"
- dnl Now see whether libintl exists and does not depend on libiconv.
- AC_TRY_LINK([#include <libintl.h>
-]ifelse([$2], [need-formatstring-macros],
-[#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
-#define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1)
-#endif
-changequote(,)dnl
-typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1];
-changequote([,])dnl
-], [])[extern int _nl_msg_cat_cntr;
-extern
-#ifdef __cplusplus
-"C"
-#endif
-const char *_nl_expand_alias (const char *);],
- [bindtextdomain ("", "");
-return * gettext ("")]ifelse([$2], [need-ngettext], [ + * ngettext ("", "", 0)], [])[ + _nl_msg_cat_cntr + *_nl_expand_alias ("")],
- gt_cv_func_gnugettext_libintl=yes,
- gt_cv_func_gnugettext_libintl=no)
- dnl Now see whether libintl exists and depends on libiconv.
- if test "$gt_cv_func_gnugettext_libintl" != yes && test -n "$LIBICONV"; then
- LIBS="$LIBS $LIBICONV"
- AC_TRY_LINK([#include <libintl.h>
-]ifelse([$2], [need-formatstring-macros],
-[#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
-#define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1)
-#endif
-changequote(,)dnl
-typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1];
-changequote([,])dnl
-], [])[extern int _nl_msg_cat_cntr;
-extern
-#ifdef __cplusplus
-"C"
-#endif
-const char *_nl_expand_alias (const char *);],
- [bindtextdomain ("", "");
-return * gettext ("")]ifelse([$2], [need-ngettext], [ + * ngettext ("", "", 0)], [])[ + _nl_msg_cat_cntr + *_nl_expand_alias ("")],
- [LIBINTL="$LIBINTL $LIBICONV"
- LTLIBINTL="$LTLIBINTL $LTLIBICONV"
- gt_cv_func_gnugettext_libintl=yes
- ])
- fi
- CPPFLAGS="$gt_save_CPPFLAGS"
- LIBS="$gt_save_LIBS"])
- fi
-
- dnl If an already present or preinstalled GNU gettext() is found,
- dnl use it. But if this macro is used in GNU gettext, and GNU
- dnl gettext is already preinstalled in libintl, we update this
- dnl libintl. (Cf. the install rule in intl/Makefile.in.)
- if test "$gt_cv_func_gnugettext_libc" = "yes" \
- || { test "$gt_cv_func_gnugettext_libintl" = "yes" \
- && test "$PACKAGE" != gettext-runtime \
- && test "$PACKAGE" != gettext-tools; }; then
- gt_use_preinstalled_gnugettext=yes
- else
- dnl Reset the values set by searching for libintl.
- LIBINTL=
- LTLIBINTL=
- INCINTL=
- fi
-
- ifelse(gt_included_intl, yes, [
- if test "$gt_use_preinstalled_gnugettext" != "yes"; then
- dnl GNU gettext is not found in the C library.
- dnl Fall back on included GNU gettext library.
- nls_cv_use_gnu_gettext=yes
- fi
- fi
-
- if test "$nls_cv_use_gnu_gettext" = "yes"; then
- dnl Mark actions used to generate GNU NLS library.
- BUILD_INCLUDED_LIBINTL=yes
- USE_INCLUDED_LIBINTL=yes
- LIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LIBICONV"
- LTLIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LTLIBICONV"
- LIBS=`echo " $LIBS " | sed -e 's/ -lintl / /' -e 's/^ //' -e 's/ $//'`
- fi
-
- CATOBJEXT=
- if test "$gt_use_preinstalled_gnugettext" = "yes" \
- || test "$nls_cv_use_gnu_gettext" = "yes"; then
- dnl Mark actions to use GNU gettext tools.
- CATOBJEXT=.gmo
- fi
- ])
-
- if test -n "$INTL_MACOSX_LIBS"; then
- if test "$gt_use_preinstalled_gnugettext" = "yes" \
- || test "$nls_cv_use_gnu_gettext" = "yes"; then
- dnl Some extra flags are needed during linking.
- LIBINTL="$LIBINTL $INTL_MACOSX_LIBS"
- LTLIBINTL="$LTLIBINTL $INTL_MACOSX_LIBS"
- fi
- fi
-
- if test "$gt_use_preinstalled_gnugettext" = "yes" \
- || test "$nls_cv_use_gnu_gettext" = "yes"; then
- AC_DEFINE(ENABLE_NLS, 1,
- [Define to 1 if translation of program messages to the user's native language
- is requested.])
- else
- USE_NLS=no
- fi
- fi
-
- AC_MSG_CHECKING([whether to use NLS])
- AC_MSG_RESULT([$USE_NLS])
- if test "$USE_NLS" = "yes"; then
- AC_MSG_CHECKING([where the gettext function comes from])
- if test "$gt_use_preinstalled_gnugettext" = "yes"; then
- if test "$gt_cv_func_gnugettext_libintl" = "yes"; then
- gt_source="external libintl"
- else
- gt_source="libc"
- fi
- else
- gt_source="included intl directory"
- fi
- AC_MSG_RESULT([$gt_source])
- fi
-
- if test "$USE_NLS" = "yes"; then
-
- if test "$gt_use_preinstalled_gnugettext" = "yes"; then
- if test "$gt_cv_func_gnugettext_libintl" = "yes"; then
- AC_MSG_CHECKING([how to link with libintl])
- AC_MSG_RESULT([$LIBINTL])
- AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCINTL])
- fi
-
- dnl For backward compatibility. Some packages may be using this.
- AC_DEFINE(HAVE_GETTEXT, 1,
- [Define if the GNU gettext() function is already present or preinstalled.])
- AC_DEFINE(HAVE_DCGETTEXT, 1,
- [Define if the GNU dcgettext() function is already present or preinstalled.])
- fi
-
- dnl We need to process the po/ directory.
- POSUB=po
- fi
-
- ifelse(gt_included_intl, yes, [
- dnl If this is used in GNU gettext we have to set BUILD_INCLUDED_LIBINTL
- dnl to 'yes' because some of the testsuite requires it.
- if test "$PACKAGE" = gettext-runtime || test "$PACKAGE" = gettext-tools; then
- BUILD_INCLUDED_LIBINTL=yes
- fi
-
- dnl Make all variables we use known to autoconf.
- AC_SUBST(BUILD_INCLUDED_LIBINTL)
- AC_SUBST(USE_INCLUDED_LIBINTL)
- AC_SUBST(CATOBJEXT)
-
- dnl For backward compatibility. Some configure.ins may be using this.
- nls_cv_header_intl=
- nls_cv_header_libgt=
-
- dnl For backward compatibility. Some Makefiles may be using this.
- DATADIRNAME=share
- AC_SUBST(DATADIRNAME)
-
- dnl For backward compatibility. Some Makefiles may be using this.
- INSTOBJEXT=.mo
- AC_SUBST(INSTOBJEXT)
-
- dnl For backward compatibility. Some Makefiles may be using this.
- GENCAT=gencat
- AC_SUBST(GENCAT)
-
- dnl For backward compatibility. Some Makefiles may be using this.
- INTLOBJS=
- if test "$USE_INCLUDED_LIBINTL" = yes; then
- INTLOBJS="\$(GETTOBJS)"
- fi
- AC_SUBST(INTLOBJS)
-
- dnl Enable libtool support if the surrounding package wishes it.
- INTL_LIBTOOL_SUFFIX_PREFIX=gt_libtool_suffix_prefix
- AC_SUBST(INTL_LIBTOOL_SUFFIX_PREFIX)
- ])
-
- dnl For backward compatibility. Some Makefiles may be using this.
- INTLLIBS="$LIBINTL"
- AC_SUBST(INTLLIBS)
-
- dnl Make all documented variables known to autoconf.
- AC_SUBST(LIBINTL)
- AC_SUBST(LTLIBINTL)
- AC_SUBST(POSUB)
-])
-
-
-dnl Checks for all prerequisites of the intl subdirectory,
-dnl except for INTL_LIBTOOL_SUFFIX_PREFIX (and possibly LIBTOOL), INTLOBJS,
-dnl USE_INCLUDED_LIBINTL, BUILD_INCLUDED_LIBINTL.
-AC_DEFUN([AM_INTL_SUBDIR],
-[
- AC_REQUIRE([AC_PROG_INSTALL])dnl
- AC_REQUIRE([AM_MKINSTALLDIRS])dnl
- AC_REQUIRE([AC_PROG_CC])dnl
- AC_REQUIRE([AC_CANONICAL_HOST])dnl
- AC_REQUIRE([gt_GLIBC2])dnl
- AC_REQUIRE([AC_PROG_RANLIB])dnl
- AC_REQUIRE([AC_ISC_POSIX])dnl
- AC_REQUIRE([AC_HEADER_STDC])dnl
- AC_REQUIRE([AC_C_CONST])dnl
- AC_REQUIRE([bh_C_SIGNED])dnl
- AC_REQUIRE([AC_C_INLINE])dnl
- AC_REQUIRE([AC_TYPE_OFF_T])dnl
- AC_REQUIRE([AC_TYPE_SIZE_T])dnl
- AC_REQUIRE([gl_AC_TYPE_LONG_LONG])dnl
- AC_REQUIRE([gt_TYPE_LONGDOUBLE])dnl
- AC_REQUIRE([gt_TYPE_WCHAR_T])dnl
- AC_REQUIRE([gt_TYPE_WINT_T])dnl
- AC_REQUIRE([gl_AC_HEADER_INTTYPES_H])
- AC_REQUIRE([gl_AC_HEADER_STDINT_H])
- AC_REQUIRE([gt_TYPE_INTMAX_T])
- AC_REQUIRE([gt_PRINTF_POSIX])
- AC_REQUIRE([AC_FUNC_ALLOCA])dnl
- AC_REQUIRE([AC_FUNC_MMAP])dnl
- AC_REQUIRE([gl_GLIBC21])dnl
- AC_REQUIRE([gt_INTDIV0])dnl
- AC_REQUIRE([gl_AC_TYPE_UINTMAX_T])dnl
- AC_REQUIRE([gt_HEADER_INTTYPES_H])dnl
- AC_REQUIRE([gt_INTTYPES_PRI])dnl
- AC_REQUIRE([gl_XSIZE])dnl
- AC_REQUIRE([gt_INTL_MACOSX])dnl
-
- AC_CHECK_TYPE([ptrdiff_t], ,
- [AC_DEFINE([ptrdiff_t], [long],
- [Define as the type of the result of subtracting two pointers, if the system doesn't define it.])
- ])
- AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h stddef.h \
-stdlib.h string.h unistd.h sys/param.h])
- AC_CHECK_FUNCS([asprintf fwprintf getcwd getegid geteuid getgid getuid \
-mempcpy munmap putenv setenv setlocale snprintf stpcpy strcasecmp strdup \
-strtoul tsearch wcslen __argz_count __argz_stringify __argz_next \
-__fsetlocking])
-
- dnl Use the _snprintf function only if it is declared (because on NetBSD it
- dnl is defined as a weak alias of snprintf; we prefer to use the latter).
- gt_CHECK_DECL(_snprintf, [#include <stdio.h>])
- gt_CHECK_DECL(_snwprintf, [#include <stdio.h>])
-
- dnl Use the *_unlocked functions only if they are declared.
- dnl (because some of them were defined without being declared in Solaris
- dnl 2.5.1 but were removed in Solaris 2.6, whereas we want binaries built
- dnl on Solaris 2.5.1 to run on Solaris 2.6).
- dnl Don't use AC_CHECK_DECLS because it isn't supported in autoconf-2.13.
- gt_CHECK_DECL(feof_unlocked, [#include <stdio.h>])
- gt_CHECK_DECL(fgets_unlocked, [#include <stdio.h>])
- gt_CHECK_DECL(getc_unlocked, [#include <stdio.h>])
-
- case $gt_cv_func_printf_posix in
- *yes) HAVE_POSIX_PRINTF=1 ;;
- *) HAVE_POSIX_PRINTF=0 ;;
- esac
- AC_SUBST([HAVE_POSIX_PRINTF])
- if test "$ac_cv_func_asprintf" = yes; then
- HAVE_ASPRINTF=1
- else
- HAVE_ASPRINTF=0
- fi
- AC_SUBST([HAVE_ASPRINTF])
- if test "$ac_cv_func_snprintf" = yes; then
- HAVE_SNPRINTF=1
- else
- HAVE_SNPRINTF=0
- fi
- AC_SUBST([HAVE_SNPRINTF])
- if test "$ac_cv_func_wprintf" = yes; then
- HAVE_WPRINTF=1
- else
- HAVE_WPRINTF=0
- fi
- AC_SUBST([HAVE_WPRINTF])
-
- AM_ICONV
- AM_LANGINFO_CODESET
- if test $ac_cv_header_locale_h = yes; then
- gt_LC_MESSAGES
- fi
-
- if test -n "$INTL_MACOSX_LIBS"; then
- CPPFLAGS="$CPPFLAGS -I/System/Library/Frameworks/CoreFoundation.framework/Headers"
- fi
-
- dnl intl/plural.c is generated from intl/plural.y. It requires bison,
- dnl because plural.y uses bison specific features. It requires at least
- dnl bison-1.26 because earlier versions generate a plural.c that doesn't
- dnl compile.
- dnl bison is only needed for the maintainer (who touches plural.y). But in
- dnl order to avoid separate Makefiles or --enable-maintainer-mode, we put
- dnl the rule in general Makefile. Now, some people carelessly touch the
- dnl files or have a broken "make" program, hence the plural.c rule will
- dnl sometimes fire. To avoid an error, defines BISON to ":" if it is not
- dnl present or too old.
- AC_CHECK_PROGS([INTLBISON], [bison])
- if test -z "$INTLBISON"; then
- ac_verc_fail=yes
- else
- dnl Found it, now check the version.
- AC_MSG_CHECKING([version of bison])
-changequote(<<,>>)dnl
- ac_prog_version=`$INTLBISON --version 2>&1 | sed -n 's/^.*GNU Bison.* \([0-9]*\.[0-9.]*\).*$/\1/p'`
- case $ac_prog_version in
- '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;;
- 1.2[6-9]* | 1.[3-9][0-9]* | [2-9].*)
-changequote([,])dnl
- ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;;
- *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;;
- esac
- AC_MSG_RESULT([$ac_prog_version])
- fi
- if test $ac_verc_fail = yes; then
- INTLBISON=:
- fi
-])
-
-
-dnl Checks for special options needed on MacOS X.
-dnl Defines INTL_MACOSX_LIBS.
-AC_DEFUN([gt_INTL_MACOSX],
-[
- dnl Check for API introduced in MacOS X 10.2.
- AC_CACHE_CHECK([for CFPreferencesCopyAppValue],
- gt_cv_func_CFPreferencesCopyAppValue,
- [gt_save_CPPFLAGS="$CPPFLAGS"
- CPPFLAGS="$CPPFLAGS -I/System/Library/Frameworks/CoreFoundation.framework/Headers"
- gt_save_LIBS="$LIBS"
- LIBS="$LIBS -framework CoreFoundation"
- AC_TRY_LINK([#include <CFPreferences.h>],
- [CFPreferencesCopyAppValue(NULL, NULL)],
- [gt_cv_func_CFPreferencesCopyAppValue=yes],
- [gt_cv_func_CFPreferencesCopyAppValue=no])
- CPPFLAGS="$gt_save_CPPFLAGS"
- LIBS="$gt_save_LIBS"])
- if test $gt_cv_func_CFPreferencesCopyAppValue = yes; then
- AC_DEFINE([HAVE_CFPREFERENCESCOPYAPPVALUE], 1,
- [Define to 1 if you have the MacOS X function CFPreferencesCopyAppValue in the CoreFoundation framework.])
- fi
- dnl Check for API introduced in MacOS X 10.3.
- AC_CACHE_CHECK([for CFLocaleCopyCurrent], gt_cv_func_CFLocaleCopyCurrent,
- [gt_save_CPPFLAGS="$CPPFLAGS"
- CPPFLAGS="$CPPFLAGS -I/System/Library/Frameworks/CoreFoundation.framework/Headers"
- gt_save_LIBS="$LIBS"
- LIBS="$LIBS -framework CoreFoundation"
- AC_TRY_LINK([#include <CFLocale.h>], [CFLocaleCopyCurrent();],
- [gt_cv_func_CFLocaleCopyCurrent=yes],
- [gt_cv_func_CFLocaleCopyCurrent=no])
- CPPFLAGS="$gt_save_CPPFLAGS"
- LIBS="$gt_save_LIBS"])
- if test $gt_cv_func_CFLocaleCopyCurrent = yes; then
- AC_DEFINE([HAVE_CFLOCALECOPYCURRENT], 1,
- [Define to 1 if you have the MacOS X function CFLocaleCopyCurrent in the CoreFoundation framework.])
- fi
- INTL_MACOSX_LIBS=
- if test $gt_cv_func_CFPreferencesCopyAppValue = yes || test $gt_cv_func_CFLocaleCopyCurrent = yes; then
- INTL_MACOSX_LIBS="-Wl,-framework -Wl,CoreFoundation"
- fi
- AC_SUBST([INTL_MACOSX_LIBS])
-])
-
-
-dnl gt_CHECK_DECL(FUNC, INCLUDES)
-dnl Check whether a function is declared.
-AC_DEFUN([gt_CHECK_DECL],
-[
- AC_CACHE_CHECK([whether $1 is declared], ac_cv_have_decl_$1,
- [AC_TRY_COMPILE([$2], [
-#ifndef $1
- char *p = (char *) $1;
-#endif
-], ac_cv_have_decl_$1=yes, ac_cv_have_decl_$1=no)])
- if test $ac_cv_have_decl_$1 = yes; then
- gt_value=1
- else
- gt_value=0
- fi
- AC_DEFINE_UNQUOTED([HAVE_DECL_]translit($1, [a-z], [A-Z]), [$gt_value],
- [Define to 1 if you have the declaration of `$1', and to 0 if you don't.])
-])
-
-
-dnl Usage: AM_GNU_GETTEXT_VERSION([gettext-version])
-AC_DEFUN([AM_GNU_GETTEXT_VERSION], [])
diff --git a/m4/gettext/Makefile.am b/m4/gettext/Makefile.am
new file mode 100644
index 000000000..d5f2fe6f0
--- /dev/null
+++ b/m4/gettext/Makefile.am
@@ -0,0 +1,32 @@
+include $(top_srcdir)/misc/Makefile.common
+
+EXTRA_DIST = \
+ codeset.m4 \
+ gettext.m4 \
+ glibc2.m4 \
+ glibc21.m4 \
+ iconv.m4 \
+ intdiv0.m4 \
+ intmax.m4 \
+ inttypes-pri.m4 \
+ inttypes.m4 \
+ inttypes_h.m4 \
+ isc-posix.m4 \
+ lcmessage.m4 \
+ lib-ld.m4 \
+ lib-link.m4 \
+ lib-prefix.m4 \
+ longdouble.m4 \
+ longlong.m4 \
+ nls.m4 \
+ po.m4 \
+ printf-posix.m4 \
+ progtest.m4 \
+ signed.m4 \
+ size_max.m4 \
+ stdint_h.m4 \
+ uintmax_t.m4 \
+ ulonglong.m4 \
+ wchar_t.m4 \
+ wint_t.m4 \
+ xsize.m4
diff --git a/m4/codeset.m4 b/m4/gettext/codeset.m4
index a6e67ec49..a6e67ec49 100644
--- a/m4/codeset.m4
+++ b/m4/gettext/codeset.m4
diff --git a/m4/gettext/gettext.m4 b/m4/gettext/gettext.m4
new file mode 100644
index 000000000..91c345e99
--- /dev/null
+++ b/m4/gettext/gettext.m4
@@ -0,0 +1,419 @@
+# gettext.m4 serial 59 (gettext-0.16.1)
+dnl Copyright (C) 1995-2006 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+dnl
+dnl This file can can be used in projects which are not available under
+dnl the GNU General Public License or the GNU Library General Public
+dnl License but which still want to provide support for the GNU gettext
+dnl functionality.
+dnl Please note that the actual code of the GNU gettext library is covered
+dnl by the GNU Library General Public License, and the rest of the GNU
+dnl gettext package package is covered by the GNU General Public License.
+dnl They are *not* in the public domain.
+
+dnl Authors:
+dnl Ulrich Drepper <drepper@cygnus.com>, 1995-2000.
+dnl Bruno Haible <haible@clisp.cons.org>, 2000-2006.
+
+dnl Macro to add for using GNU gettext.
+
+dnl Usage: AM_GNU_GETTEXT([INTLSYMBOL], [NEEDSYMBOL], [INTLDIR]).
+dnl INTLSYMBOL can be one of 'external', 'no-libtool', 'use-libtool'. The
+dnl default (if it is not specified or empty) is 'no-libtool'.
+dnl INTLSYMBOL should be 'external' for packages with no intl directory,
+dnl and 'no-libtool' or 'use-libtool' for packages with an intl directory.
+dnl If INTLSYMBOL is 'use-libtool', then a libtool library
+dnl $(top_builddir)/intl/libintl.la will be created (shared and/or static,
+dnl depending on --{enable,disable}-{shared,static} and on the presence of
+dnl AM-DISABLE-SHARED). If INTLSYMBOL is 'no-libtool', a static library
+dnl $(top_builddir)/intl/libintl.a will be created.
+dnl If NEEDSYMBOL is specified and is 'need-ngettext', then GNU gettext
+dnl implementations (in libc or libintl) without the ngettext() function
+dnl will be ignored. If NEEDSYMBOL is specified and is
+dnl 'need-formatstring-macros', then GNU gettext implementations that don't
+dnl support the ISO C 99 <inttypes.h> formatstring macros will be ignored.
+dnl INTLDIR is used to find the intl libraries. If empty,
+dnl the value `$(top_builddir)/intl/' is used.
+dnl
+dnl The result of the configuration is one of three cases:
+dnl 1) GNU gettext, as included in the intl subdirectory, will be compiled
+dnl and used.
+dnl Catalog format: GNU --> install in $(datadir)
+dnl Catalog extension: .mo after installation, .gmo in source tree
+dnl 2) GNU gettext has been found in the system's C library.
+dnl Catalog format: GNU --> install in $(datadir)
+dnl Catalog extension: .mo after installation, .gmo in source tree
+dnl 3) No internationalization, always use English msgid.
+dnl Catalog format: none
+dnl Catalog extension: none
+dnl If INTLSYMBOL is 'external', only cases 2 and 3 can occur.
+dnl The use of .gmo is historical (it was needed to avoid overwriting the
+dnl GNU format catalogs when building on a platform with an X/Open gettext),
+dnl but we keep it in order not to force irrelevant filename changes on the
+dnl maintainers.
+dnl
+AC_DEFUN([AM_GNU_GETTEXT],
+[
+ dnl Argument checking.
+ ifelse([$1], [], , [ifelse([$1], [external], , [ifelse([$1], [no-libtool], , [ifelse([$1], [use-libtool], ,
+ [errprint([ERROR: invalid first argument to AM_GNU_GETTEXT
+])])])])])
+ ifelse([$2], [], , [ifelse([$2], [need-ngettext], , [ifelse([$2], [need-formatstring-macros], ,
+ [errprint([ERROR: invalid second argument to AM_GNU_GETTEXT
+])])])])
+ define([gt_included_intl],
+ ifelse([$1], [external],
+ ifdef([AM_GNU_GETTEXT_][INTL_SUBDIR], [yes], [no]),
+ [yes]))
+ define([gt_libtool_suffix_prefix], ifelse([$1], [use-libtool], [l], []))
+ gt_NEEDS_INIT
+ AM_GNU_GETTEXT_NEED([$2])
+
+ AC_REQUIRE([AM_PO_SUBDIRS])dnl
+ ifelse(gt_included_intl, yes, [
+ AC_REQUIRE([AM_INTL_SUBDIR])dnl
+ ])
+
+ dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
+ AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
+ AC_REQUIRE([AC_LIB_RPATH])
+
+ dnl Sometimes libintl requires libiconv, so first search for libiconv.
+ dnl Ideally we would do this search only after the
+ dnl if test "$USE_NLS" = "yes"; then
+ dnl if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" != "yes"; }; then
+ dnl tests. But if configure.in invokes AM_ICONV after AM_GNU_GETTEXT
+ dnl the configure script would need to contain the same shell code
+ dnl again, outside any 'if'. There are two solutions:
+ dnl - Invoke AM_ICONV_LINKFLAGS_BODY here, outside any 'if'.
+ dnl - Control the expansions in more detail using AC_PROVIDE_IFELSE.
+ dnl Since AC_PROVIDE_IFELSE is only in autoconf >= 2.52 and not
+ dnl documented, we avoid it.
+ ifelse(gt_included_intl, yes, , [
+ AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY])
+ ])
+
+ dnl Sometimes, on MacOS X, libintl requires linking with CoreFoundation.
+ gt_INTL_MACOSX
+
+ dnl Set USE_NLS.
+ AC_REQUIRE([AM_NLS])
+
+ ifelse(gt_included_intl, yes, [
+ BUILD_INCLUDED_LIBINTL=no
+ USE_INCLUDED_LIBINTL=no
+ ])
+ LIBINTL=
+ LTLIBINTL=
+ POSUB=
+
+ dnl Add a version number to the cache macros.
+ case " $gt_needs " in
+ *" need-formatstring-macros "*) gt_api_version=3 ;;
+ *" need-ngettext "*) gt_api_version=2 ;;
+ *) gt_api_version=1 ;;
+ esac
+ gt_func_gnugettext_libc="gt_cv_func_gnugettext${gt_api_version}_libc"
+ gt_func_gnugettext_libintl="gt_cv_func_gnugettext${gt_api_version}_libintl"
+
+ dnl If we use NLS figure out what method
+ if test "$USE_NLS" = "yes"; then
+ gt_use_preinstalled_gnugettext=no
+ ifelse(gt_included_intl, yes, [
+ AC_MSG_CHECKING([whether included gettext is requested])
+ AC_ARG_WITH(included-gettext,
+ [ --with-included-gettext use the GNU gettext library included here],
+ nls_cv_force_use_gnu_gettext=$withval,
+ nls_cv_force_use_gnu_gettext=no)
+ AC_MSG_RESULT($nls_cv_force_use_gnu_gettext)
+
+ nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext"
+ if test "$nls_cv_force_use_gnu_gettext" != "yes"; then
+ ])
+ dnl User does not insist on using GNU NLS library. Figure out what
+ dnl to use. If GNU gettext is available we use this. Else we have
+ dnl to fall back to GNU NLS library.
+
+ if test $gt_api_version -ge 3; then
+ gt_revision_test_code='
+#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
+#define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1)
+#endif
+changequote(,)dnl
+typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1];
+changequote([,])dnl
+'
+ else
+ gt_revision_test_code=
+ fi
+ if test $gt_api_version -ge 2; then
+ gt_expression_test_code=' + * ngettext ("", "", 0)'
+ else
+ gt_expression_test_code=
+ fi
+
+ AC_CACHE_CHECK([for GNU gettext in libc], [$gt_func_gnugettext_libc],
+ [AC_TRY_LINK([#include <libintl.h>
+$gt_revision_test_code
+extern int _nl_msg_cat_cntr;
+extern int *_nl_domain_bindings;],
+ [bindtextdomain ("", "");
+return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_domain_bindings],
+ [eval "$gt_func_gnugettext_libc=yes"],
+ [eval "$gt_func_gnugettext_libc=no"])])
+
+ if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" != "yes"; }; then
+ dnl Sometimes libintl requires libiconv, so first search for libiconv.
+ ifelse(gt_included_intl, yes, , [
+ AM_ICONV_LINK
+ ])
+ dnl Search for libintl and define LIBINTL, LTLIBINTL and INCINTL
+ dnl accordingly. Don't use AC_LIB_LINKFLAGS_BODY([intl],[iconv])
+ dnl because that would add "-liconv" to LIBINTL and LTLIBINTL
+ dnl even if libiconv doesn't exist.
+ AC_LIB_LINKFLAGS_BODY([intl])
+ AC_CACHE_CHECK([for GNU gettext in libintl],
+ [$gt_func_gnugettext_libintl],
+ [gt_save_CPPFLAGS="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $INCINTL"
+ gt_save_LIBS="$LIBS"
+ LIBS="$LIBS $LIBINTL"
+ dnl Now see whether libintl exists and does not depend on libiconv.
+ AC_TRY_LINK([#include <libintl.h>
+$gt_revision_test_code
+extern int _nl_msg_cat_cntr;
+extern
+#ifdef __cplusplus
+"C"
+#endif
+const char *_nl_expand_alias (const char *);],
+ [bindtextdomain ("", "");
+return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_expand_alias ("")],
+ [eval "$gt_func_gnugettext_libintl=yes"],
+ [eval "$gt_func_gnugettext_libintl=no"])
+ dnl Now see whether libintl exists and depends on libiconv.
+ if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" != yes; } && test -n "$LIBICONV"; then
+ LIBS="$LIBS $LIBICONV"
+ AC_TRY_LINK([#include <libintl.h>
+$gt_revision_test_code
+extern int _nl_msg_cat_cntr;
+extern
+#ifdef __cplusplus
+"C"
+#endif
+const char *_nl_expand_alias (const char *);],
+ [bindtextdomain ("", "");
+return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_expand_alias ("")],
+ [LIBINTL="$LIBINTL $LIBICONV"
+ LTLIBINTL="$LTLIBINTL $LTLIBICONV"
+ eval "$gt_func_gnugettext_libintl=yes"
+ ])
+ fi
+ CPPFLAGS="$gt_save_CPPFLAGS"
+ LIBS="$gt_save_LIBS"])
+ fi
+
+ dnl If an already present or preinstalled GNU gettext() is found,
+ dnl use it. But if this macro is used in GNU gettext, and GNU
+ dnl gettext is already preinstalled in libintl, we update this
+ dnl libintl. (Cf. the install rule in intl/Makefile.in.)
+ if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" = "yes"; } \
+ || { { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; } \
+ && test "$PACKAGE" != gettext-runtime \
+ && test "$PACKAGE" != gettext-tools; }; then
+ gt_use_preinstalled_gnugettext=yes
+ else
+ dnl Reset the values set by searching for libintl.
+ LIBINTL=
+ LTLIBINTL=
+ INCINTL=
+ fi
+
+ ifelse(gt_included_intl, yes, [
+ if test "$gt_use_preinstalled_gnugettext" != "yes"; then
+ dnl GNU gettext is not found in the C library.
+ dnl Fall back on included GNU gettext library.
+ nls_cv_use_gnu_gettext=yes
+ fi
+ fi
+
+ if test "$nls_cv_use_gnu_gettext" = "yes"; then
+ dnl Mark actions used to generate GNU NLS library.
+ BUILD_INCLUDED_LIBINTL=yes
+ USE_INCLUDED_LIBINTL=yes
+ LIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LIBICONV $LIBTHREAD"
+ LTLIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LTLIBICONV $LTLIBTHREAD"
+ LIBS=`echo " $LIBS " | sed -e 's/ -lintl / /' -e 's/^ //' -e 's/ $//'`
+ fi
+
+ CATOBJEXT=
+ if test "$gt_use_preinstalled_gnugettext" = "yes" \
+ || test "$nls_cv_use_gnu_gettext" = "yes"; then
+ dnl Mark actions to use GNU gettext tools.
+ CATOBJEXT=.gmo
+ fi
+ ])
+
+ if test -n "$INTL_MACOSX_LIBS"; then
+ if test "$gt_use_preinstalled_gnugettext" = "yes" \
+ || test "$nls_cv_use_gnu_gettext" = "yes"; then
+ dnl Some extra flags are needed during linking.
+ LIBINTL="$LIBINTL $INTL_MACOSX_LIBS"
+ LTLIBINTL="$LTLIBINTL $INTL_MACOSX_LIBS"
+ fi
+ fi
+
+ if test "$gt_use_preinstalled_gnugettext" = "yes" \
+ || test "$nls_cv_use_gnu_gettext" = "yes"; then
+ AC_DEFINE(ENABLE_NLS, 1,
+ [Define to 1 if translation of program messages to the user's native language
+ is requested.])
+ else
+ USE_NLS=no
+ fi
+ fi
+
+ AC_MSG_CHECKING([whether to use NLS])
+ AC_MSG_RESULT([$USE_NLS])
+ if test "$USE_NLS" = "yes"; then
+ AC_MSG_CHECKING([where the gettext function comes from])
+ if test "$gt_use_preinstalled_gnugettext" = "yes"; then
+ if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; }; then
+ gt_source="external libintl"
+ else
+ gt_source="libc"
+ fi
+ else
+ gt_source="included intl directory"
+ fi
+ AC_MSG_RESULT([$gt_source])
+ fi
+
+ if test "$USE_NLS" = "yes"; then
+
+ if test "$gt_use_preinstalled_gnugettext" = "yes"; then
+ if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; }; then
+ AC_MSG_CHECKING([how to link with libintl])
+ AC_MSG_RESULT([$LIBINTL])
+ AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCINTL])
+ fi
+
+ dnl For backward compatibility. Some packages may be using this.
+ AC_DEFINE(HAVE_GETTEXT, 1,
+ [Define if the GNU gettext() function is already present or preinstalled.])
+ AC_DEFINE(HAVE_DCGETTEXT, 1,
+ [Define if the GNU dcgettext() function is already present or preinstalled.])
+ fi
+
+ dnl We need to process the po/ directory.
+ POSUB=po
+ fi
+
+ ifelse(gt_included_intl, yes, [
+ dnl If this is used in GNU gettext we have to set BUILD_INCLUDED_LIBINTL
+ dnl to 'yes' because some of the testsuite requires it.
+ if test "$PACKAGE" = gettext-runtime || test "$PACKAGE" = gettext-tools; then
+ BUILD_INCLUDED_LIBINTL=yes
+ fi
+
+ dnl Make all variables we use known to autoconf.
+ AC_SUBST(BUILD_INCLUDED_LIBINTL)
+ AC_SUBST(USE_INCLUDED_LIBINTL)
+ AC_SUBST(CATOBJEXT)
+
+ dnl For backward compatibility. Some configure.ins may be using this.
+ nls_cv_header_intl=
+ nls_cv_header_libgt=
+
+ dnl For backward compatibility. Some Makefiles may be using this.
+ DATADIRNAME=share
+ AC_SUBST(DATADIRNAME)
+
+ dnl For backward compatibility. Some Makefiles may be using this.
+ INSTOBJEXT=.mo
+ AC_SUBST(INSTOBJEXT)
+
+ dnl For backward compatibility. Some Makefiles may be using this.
+ GENCAT=gencat
+ AC_SUBST(GENCAT)
+
+ dnl For backward compatibility. Some Makefiles may be using this.
+ INTLOBJS=
+ if test "$USE_INCLUDED_LIBINTL" = yes; then
+ INTLOBJS="\$(GETTOBJS)"
+ fi
+ AC_SUBST(INTLOBJS)
+
+ dnl Enable libtool support if the surrounding package wishes it.
+ INTL_LIBTOOL_SUFFIX_PREFIX=gt_libtool_suffix_prefix
+ AC_SUBST(INTL_LIBTOOL_SUFFIX_PREFIX)
+ ])
+
+ dnl For backward compatibility. Some Makefiles may be using this.
+ INTLLIBS="$LIBINTL"
+ AC_SUBST(INTLLIBS)
+
+ dnl Make all documented variables known to autoconf.
+ AC_SUBST(LIBINTL)
+ AC_SUBST(LTLIBINTL)
+ AC_SUBST(POSUB)
+])
+
+
+dnl Checks for special options needed on MacOS X.
+dnl Defines INTL_MACOSX_LIBS.
+AC_DEFUN([gt_INTL_MACOSX],
+[
+ dnl Check for API introduced in MacOS X 10.2.
+ AC_CACHE_CHECK([for CFPreferencesCopyAppValue],
+ gt_cv_func_CFPreferencesCopyAppValue,
+ [gt_save_LIBS="$LIBS"
+ LIBS="$LIBS -Wl,-framework -Wl,CoreFoundation"
+ AC_TRY_LINK([#include <CoreFoundation/CFPreferences.h>],
+ [CFPreferencesCopyAppValue(NULL, NULL)],
+ [gt_cv_func_CFPreferencesCopyAppValue=yes],
+ [gt_cv_func_CFPreferencesCopyAppValue=no])
+ LIBS="$gt_save_LIBS"])
+ if test $gt_cv_func_CFPreferencesCopyAppValue = yes; then
+ AC_DEFINE([HAVE_CFPREFERENCESCOPYAPPVALUE], 1,
+ [Define to 1 if you have the MacOS X function CFPreferencesCopyAppValue in the CoreFoundation framework.])
+ fi
+ dnl Check for API introduced in MacOS X 10.3.
+ AC_CACHE_CHECK([for CFLocaleCopyCurrent], gt_cv_func_CFLocaleCopyCurrent,
+ [gt_save_LIBS="$LIBS"
+ LIBS="$LIBS -Wl,-framework -Wl,CoreFoundation"
+ AC_TRY_LINK([#include <CoreFoundation/CFLocale.h>], [CFLocaleCopyCurrent();],
+ [gt_cv_func_CFLocaleCopyCurrent=yes],
+ [gt_cv_func_CFLocaleCopyCurrent=no])
+ LIBS="$gt_save_LIBS"])
+ if test $gt_cv_func_CFLocaleCopyCurrent = yes; then
+ AC_DEFINE([HAVE_CFLOCALECOPYCURRENT], 1,
+ [Define to 1 if you have the MacOS X function CFLocaleCopyCurrent in the CoreFoundation framework.])
+ fi
+ INTL_MACOSX_LIBS=
+ if test $gt_cv_func_CFPreferencesCopyAppValue = yes || test $gt_cv_func_CFLocaleCopyCurrent = yes; then
+ INTL_MACOSX_LIBS="-Wl,-framework -Wl,CoreFoundation"
+ fi
+ AC_SUBST([INTL_MACOSX_LIBS])
+])
+
+
+dnl gt_NEEDS_INIT ensures that the gt_needs variable is initialized.
+m4_define([gt_NEEDS_INIT],
+[
+ m4_divert_text([DEFAULTS], [gt_needs=])
+ m4_define([gt_NEEDS_INIT], [])
+])
+
+
+dnl Usage: AM_GNU_GETTEXT_NEED([NEEDSYMBOL])
+AC_DEFUN([AM_GNU_GETTEXT_NEED],
+[
+ m4_divert_text([INIT_PREPARE], [gt_needs="$gt_needs $1"])
+])
+
+
+dnl Usage: AM_GNU_GETTEXT_VERSION([gettext-version])
+AC_DEFUN([AM_GNU_GETTEXT_VERSION], [])
diff --git a/m4/glibc2.m4 b/m4/gettext/glibc2.m4
index e8f5bfe6e..e8f5bfe6e 100644
--- a/m4/glibc2.m4
+++ b/m4/gettext/glibc2.m4
diff --git a/m4/glibc21.m4 b/m4/gettext/glibc21.m4
index d95fd9861..d95fd9861 100644
--- a/m4/glibc21.m4
+++ b/m4/gettext/glibc21.m4
diff --git a/m4/gettext/iconv.m4 b/m4/gettext/iconv.m4
new file mode 100644
index 000000000..654c41589
--- /dev/null
+++ b/m4/gettext/iconv.m4
@@ -0,0 +1,101 @@
+# iconv.m4 serial AM4 (gettext-0.11.3)
+dnl Copyright (C) 2000-2002 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Bruno Haible.
+
+AC_DEFUN([AM_ICONV_LINKFLAGS_BODY],
+[
+ dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
+ AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
+ AC_REQUIRE([AC_LIB_RPATH])
+
+ dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
+ dnl accordingly.
+ AC_LIB_LINKFLAGS_BODY([iconv])
+])
+
+AC_DEFUN([AM_ICONV_LINK],
+[
+ dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
+ dnl those with the standalone portable GNU libiconv installed).
+
+ dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
+ dnl accordingly.
+ AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY])
+
+ dnl Add $INCICONV to CPPFLAGS before performing the following checks,
+ dnl because if the user has installed libiconv and not disabled its use
+ dnl via --without-libiconv-prefix, he wants to use it. The first
+ dnl AC_TRY_LINK will then fail, the second AC_TRY_LINK will succeed.
+ am_save_CPPFLAGS="$CPPFLAGS"
+ AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV])
+
+ AC_CACHE_CHECK(for iconv, am_cv_func_iconv, [
+ am_cv_func_iconv="no, consider installing GNU libiconv"
+ am_cv_lib_iconv=no
+ AC_TRY_LINK([#include <stdlib.h>
+#include <iconv.h>],
+ [iconv_t cd = iconv_open("","");
+ iconv(cd,NULL,NULL,NULL,NULL);
+ iconv_close(cd);],
+ am_cv_func_iconv=yes)
+ if test "$am_cv_func_iconv" != yes; then
+ am_save_LIBS="$LIBS"
+ LIBS="$LIBS $LIBICONV"
+ AC_TRY_LINK([#include <stdlib.h>
+#include <iconv.h>],
+ [iconv_t cd = iconv_open("","");
+ iconv(cd,NULL,NULL,NULL,NULL);
+ iconv_close(cd);],
+ am_cv_lib_iconv=yes
+ am_cv_func_iconv=yes)
+ LIBS="$am_save_LIBS"
+ fi
+ ])
+ if test "$am_cv_func_iconv" = yes; then
+ AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
+ fi
+ if test "$am_cv_lib_iconv" = yes; then
+ AC_MSG_CHECKING([how to link with libiconv])
+ AC_MSG_RESULT([$LIBICONV])
+ else
+ dnl If $LIBICONV didn't lead to a usable library, we don't need $INCICONV
+ dnl either.
+ CPPFLAGS="$am_save_CPPFLAGS"
+ LIBICONV=
+ LTLIBICONV=
+ fi
+ AC_SUBST(LIBICONV)
+ AC_SUBST(LTLIBICONV)
+])
+
+AC_DEFUN([AM_ICONV],
+[
+ AM_ICONV_LINK
+ if test "$am_cv_func_iconv" = yes; then
+ AC_MSG_CHECKING([for iconv declaration])
+ AC_CACHE_VAL(am_cv_proto_iconv, [
+ AC_TRY_COMPILE([
+#include <stdlib.h>
+#include <iconv.h>
+extern
+#ifdef __cplusplus
+"C"
+#endif
+#if defined(__STDC__) || defined(__cplusplus)
+size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
+#else
+size_t iconv();
+#endif
+], [], am_cv_proto_iconv_arg1="", am_cv_proto_iconv_arg1="const")
+ am_cv_proto_iconv="extern size_t iconv (iconv_t cd, $am_cv_proto_iconv_arg1 char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);"])
+ am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
+ AC_MSG_RESULT([$]{ac_t:-
+ }[$]am_cv_proto_iconv)
+ AC_DEFINE_UNQUOTED(ICONV_CONST, $am_cv_proto_iconv_arg1,
+ [Define as const if the declaration of iconv() needs const.])
+ fi
+])
diff --git a/m4/intdiv0.m4 b/m4/gettext/intdiv0.m4
index b8d78176a..b8d78176a 100644
--- a/m4/intdiv0.m4
+++ b/m4/gettext/intdiv0.m4
diff --git a/m4/intmax.m4 b/m4/gettext/intmax.m4
index d99c999fd..d99c999fd 100644
--- a/m4/intmax.m4
+++ b/m4/gettext/intmax.m4
diff --git a/m4/inttypes-pri.m4 b/m4/gettext/inttypes-pri.m4
index 4d56a9ad3..4d56a9ad3 100644
--- a/m4/inttypes-pri.m4
+++ b/m4/gettext/inttypes-pri.m4
diff --git a/m4/inttypes.m4 b/m4/gettext/inttypes.m4
index 779bcea05..779bcea05 100644
--- a/m4/inttypes.m4
+++ b/m4/gettext/inttypes.m4
diff --git a/m4/inttypes_h.m4 b/m4/gettext/inttypes_h.m4
index a5d075d96..a5d075d96 100644
--- a/m4/inttypes_h.m4
+++ b/m4/gettext/inttypes_h.m4
diff --git a/m4/isc-posix.m4 b/m4/gettext/isc-posix.m4
index 74dc8f26d..74dc8f26d 100644
--- a/m4/isc-posix.m4
+++ b/m4/gettext/isc-posix.m4
diff --git a/m4/lcmessage.m4 b/m4/gettext/lcmessage.m4
index 19aa77e4f..19aa77e4f 100644
--- a/m4/lcmessage.m4
+++ b/m4/gettext/lcmessage.m4
diff --git a/m4/lib-ld.m4 b/m4/gettext/lib-ld.m4
index 96c4e2c33..96c4e2c33 100644
--- a/m4/lib-ld.m4
+++ b/m4/gettext/lib-ld.m4
diff --git a/m4/gettext/lib-link.m4 b/m4/gettext/lib-link.m4
new file mode 100644
index 000000000..f95b7ba88
--- /dev/null
+++ b/m4/gettext/lib-link.m4
@@ -0,0 +1,644 @@
+# lib-link.m4 serial 9 (gettext-0.16)
+dnl Copyright (C) 2001-2006 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Bruno Haible.
+
+AC_PREREQ(2.50)
+
+dnl AC_LIB_LINKFLAGS(name [, dependencies]) searches for libname and
+dnl the libraries corresponding to explicit and implicit dependencies.
+dnl Sets and AC_SUBSTs the LIB${NAME} and LTLIB${NAME} variables and
+dnl augments the CPPFLAGS variable.
+AC_DEFUN([AC_LIB_LINKFLAGS],
+[
+ AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
+ AC_REQUIRE([AC_LIB_RPATH])
+ define([Name],[translit([$1],[./-], [___])])
+ define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
+ [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
+ AC_CACHE_CHECK([how to link with lib[]$1], [ac_cv_lib[]Name[]_libs], [
+ AC_LIB_LINKFLAGS_BODY([$1], [$2])
+ ac_cv_lib[]Name[]_libs="$LIB[]NAME"
+ ac_cv_lib[]Name[]_ltlibs="$LTLIB[]NAME"
+ ac_cv_lib[]Name[]_cppflags="$INC[]NAME"
+ ])
+ LIB[]NAME="$ac_cv_lib[]Name[]_libs"
+ LTLIB[]NAME="$ac_cv_lib[]Name[]_ltlibs"
+ INC[]NAME="$ac_cv_lib[]Name[]_cppflags"
+ AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME)
+ AC_SUBST([LIB]NAME)
+ AC_SUBST([LTLIB]NAME)
+ dnl Also set HAVE_LIB[]NAME so that AC_LIB_HAVE_LINKFLAGS can reuse the
+ dnl results of this search when this library appears as a dependency.
+ HAVE_LIB[]NAME=yes
+ undefine([Name])
+ undefine([NAME])
+])
+
+dnl AC_LIB_HAVE_LINKFLAGS(name, dependencies, includes, testcode)
+dnl searches for libname and the libraries corresponding to explicit and
+dnl implicit dependencies, together with the specified include files and
+dnl the ability to compile and link the specified testcode. If found, it
+dnl sets and AC_SUBSTs HAVE_LIB${NAME}=yes and the LIB${NAME} and
+dnl LTLIB${NAME} variables and augments the CPPFLAGS variable, and
+dnl #defines HAVE_LIB${NAME} to 1. Otherwise, it sets and AC_SUBSTs
+dnl HAVE_LIB${NAME}=no and LIB${NAME} and LTLIB${NAME} to empty.
+AC_DEFUN([AC_LIB_HAVE_LINKFLAGS],
+[
+ AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
+ AC_REQUIRE([AC_LIB_RPATH])
+ define([Name],[translit([$1],[./-], [___])])
+ define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
+ [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
+
+ dnl Search for lib[]Name and define LIB[]NAME, LTLIB[]NAME and INC[]NAME
+ dnl accordingly.
+ AC_LIB_LINKFLAGS_BODY([$1], [$2])
+
+ dnl Add $INC[]NAME to CPPFLAGS before performing the following checks,
+ dnl because if the user has installed lib[]Name and not disabled its use
+ dnl via --without-lib[]Name-prefix, he wants to use it.
+ ac_save_CPPFLAGS="$CPPFLAGS"
+ AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME)
+
+ AC_CACHE_CHECK([for lib[]$1], [ac_cv_lib[]Name], [
+ ac_save_LIBS="$LIBS"
+ LIBS="$LIBS $LIB[]NAME"
+ AC_TRY_LINK([$3], [$4], [ac_cv_lib[]Name=yes], [ac_cv_lib[]Name=no])
+ LIBS="$ac_save_LIBS"
+ ])
+ if test "$ac_cv_lib[]Name" = yes; then
+ HAVE_LIB[]NAME=yes
+ AC_DEFINE([HAVE_LIB]NAME, 1, [Define if you have the $1 library.])
+ AC_MSG_CHECKING([how to link with lib[]$1])
+ AC_MSG_RESULT([$LIB[]NAME])
+ else
+ HAVE_LIB[]NAME=no
+ dnl If $LIB[]NAME didn't lead to a usable library, we don't need
+ dnl $INC[]NAME either.
+ CPPFLAGS="$ac_save_CPPFLAGS"
+ LIB[]NAME=
+ LTLIB[]NAME=
+ fi
+ AC_SUBST([HAVE_LIB]NAME)
+ AC_SUBST([LIB]NAME)
+ AC_SUBST([LTLIB]NAME)
+ undefine([Name])
+ undefine([NAME])
+])
+
+dnl Determine the platform dependent parameters needed to use rpath:
+dnl libext, shlibext, hardcode_libdir_flag_spec, hardcode_libdir_separator,
+dnl hardcode_direct, hardcode_minus_L.
+AC_DEFUN([AC_LIB_RPATH],
+[
+ dnl Tell automake >= 1.10 to complain if config.rpath is missing.
+ m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([config.rpath])])
+ AC_REQUIRE([AC_PROG_CC]) dnl we use $CC, $GCC, $LDFLAGS
+ AC_REQUIRE([AC_LIB_PROG_LD]) dnl we use $LD, $with_gnu_ld
+ AC_REQUIRE([AC_CANONICAL_HOST]) dnl we use $host
+ AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT]) dnl we use $ac_aux_dir
+ AC_CACHE_CHECK([for shared library run path origin], acl_cv_rpath, [
+ CC="$CC" GCC="$GCC" LDFLAGS="$LDFLAGS" LD="$LD" with_gnu_ld="$with_gnu_ld" \
+ ${CONFIG_SHELL-/bin/sh} "$ac_aux_dir/config.rpath" "$host" > conftest.sh
+ . ./conftest.sh
+ rm -f ./conftest.sh
+ acl_cv_rpath=done
+ ])
+ wl="$acl_cv_wl"
+ libext="$acl_cv_libext"
+ shlibext="$acl_cv_shlibext"
+ hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec"
+ hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator"
+ hardcode_direct="$acl_cv_hardcode_direct"
+ hardcode_minus_L="$acl_cv_hardcode_minus_L"
+ dnl Determine whether the user wants rpath handling at all.
+ AC_ARG_ENABLE(rpath,
+ [ --disable-rpath do not hardcode runtime library paths],
+ :, enable_rpath=yes)
+])
+
+dnl AC_LIB_LINKFLAGS_BODY(name [, dependencies]) searches for libname and
+dnl the libraries corresponding to explicit and implicit dependencies.
+dnl Sets the LIB${NAME}, LTLIB${NAME} and INC${NAME} variables.
+AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
+[
+ AC_REQUIRE([AC_LIB_PREPARE_MULTILIB])
+ define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
+ [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
+ dnl By default, look in $includedir and $libdir.
+ use_additional=yes
+ AC_LIB_WITH_FINAL_PREFIX([
+ eval additional_includedir=\"$includedir\"
+ eval additional_libdir=\"$libdir\"
+ ])
+ AC_LIB_ARG_WITH([lib$1-prefix],
+[ --with-lib$1-prefix[=DIR] search for lib$1 in DIR/include and DIR/lib
+ --without-lib$1-prefix don't search for lib$1 in includedir and libdir],
+[
+ if test "X$withval" = "Xno"; then
+ use_additional=no
+ else
+ if test "X$withval" = "X"; then
+ AC_LIB_WITH_FINAL_PREFIX([
+ eval additional_includedir=\"$includedir\"
+ eval additional_libdir=\"$libdir\"
+ ])
+ else
+ additional_includedir="$withval/include"
+ additional_libdir="$withval/$acl_libdirstem"
+ fi
+ fi
+])
+ dnl Search the library and its dependencies in $additional_libdir and
+ dnl $LDFLAGS. Using breadth-first-seach.
+ LIB[]NAME=
+ LTLIB[]NAME=
+ INC[]NAME=
+ rpathdirs=
+ ltrpathdirs=
+ names_already_handled=
+ names_next_round='$1 $2'
+ while test -n "$names_next_round"; do
+ names_this_round="$names_next_round"
+ names_next_round=
+ for name in $names_this_round; do
+ already_handled=
+ for n in $names_already_handled; do
+ if test "$n" = "$name"; then
+ already_handled=yes
+ break
+ fi
+ done
+ if test -z "$already_handled"; then
+ names_already_handled="$names_already_handled $name"
+ dnl See if it was already located by an earlier AC_LIB_LINKFLAGS
+ dnl or AC_LIB_HAVE_LINKFLAGS call.
+ uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./-|ABCDEFGHIJKLMNOPQRSTUVWXYZ___|'`
+ eval value=\"\$HAVE_LIB$uppername\"
+ if test -n "$value"; then
+ if test "$value" = yes; then
+ eval value=\"\$LIB$uppername\"
+ test -z "$value" || LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$value"
+ eval value=\"\$LTLIB$uppername\"
+ test -z "$value" || LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$value"
+ else
+ dnl An earlier call to AC_LIB_HAVE_LINKFLAGS has determined
+ dnl that this library doesn't exist. So just drop it.
+ :
+ fi
+ else
+ dnl Search the library lib$name in $additional_libdir and $LDFLAGS
+ dnl and the already constructed $LIBNAME/$LTLIBNAME.
+ found_dir=
+ found_la=
+ found_so=
+ found_a=
+ if test $use_additional = yes; then
+ if test -n "$shlibext" \
+ && { test -f "$additional_libdir/lib$name.$shlibext" \
+ || { test "$shlibext" = dll \
+ && test -f "$additional_libdir/lib$name.dll.a"; }; }; then
+ found_dir="$additional_libdir"
+ if test -f "$additional_libdir/lib$name.$shlibext"; then
+ found_so="$additional_libdir/lib$name.$shlibext"
+ else
+ found_so="$additional_libdir/lib$name.dll.a"
+ fi
+ if test -f "$additional_libdir/lib$name.la"; then
+ found_la="$additional_libdir/lib$name.la"
+ fi
+ else
+ if test -f "$additional_libdir/lib$name.$libext"; then
+ found_dir="$additional_libdir"
+ found_a="$additional_libdir/lib$name.$libext"
+ if test -f "$additional_libdir/lib$name.la"; then
+ found_la="$additional_libdir/lib$name.la"
+ fi
+ fi
+ fi
+ fi
+ if test "X$found_dir" = "X"; then
+ for x in $LDFLAGS $LTLIB[]NAME; do
+ AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
+ case "$x" in
+ -L*)
+ dir=`echo "X$x" | sed -e 's/^X-L//'`
+ if test -n "$shlibext" \
+ && { test -f "$dir/lib$name.$shlibext" \
+ || { test "$shlibext" = dll \
+ && test -f "$dir/lib$name.dll.a"; }; }; then
+ found_dir="$dir"
+ if test -f "$dir/lib$name.$shlibext"; then
+ found_so="$dir/lib$name.$shlibext"
+ else
+ found_so="$dir/lib$name.dll.a"
+ fi
+ if test -f "$dir/lib$name.la"; then
+ found_la="$dir/lib$name.la"
+ fi
+ else
+ if test -f "$dir/lib$name.$libext"; then
+ found_dir="$dir"
+ found_a="$dir/lib$name.$libext"
+ if test -f "$dir/lib$name.la"; then
+ found_la="$dir/lib$name.la"
+ fi
+ fi
+ fi
+ ;;
+ esac
+ if test "X$found_dir" != "X"; then
+ break
+ fi
+ done
+ fi
+ if test "X$found_dir" != "X"; then
+ dnl Found the library.
+ LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$found_dir -l$name"
+ if test "X$found_so" != "X"; then
+ dnl Linking with a shared library. We attempt to hardcode its
+ dnl directory into the executable's runpath, unless it's the
+ dnl standard /usr/lib.
+ if test "$enable_rpath" = no || test "X$found_dir" = "X/usr/$acl_libdirstem"; then
+ dnl No hardcoding is needed.
+ LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
+ else
+ dnl Use an explicit option to hardcode DIR into the resulting
+ dnl binary.
+ dnl Potentially add DIR to ltrpathdirs.
+ dnl The ltrpathdirs will be appended to $LTLIBNAME at the end.
+ haveit=
+ for x in $ltrpathdirs; do
+ if test "X$x" = "X$found_dir"; then
+ haveit=yes
+ break
+ fi
+ done
+ if test -z "$haveit"; then
+ ltrpathdirs="$ltrpathdirs $found_dir"
+ fi
+ dnl The hardcoding into $LIBNAME is system dependent.
+ if test "$hardcode_direct" = yes; then
+ dnl Using DIR/libNAME.so during linking hardcodes DIR into the
+ dnl resulting binary.
+ LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
+ else
+ if test -n "$hardcode_libdir_flag_spec" && test "$hardcode_minus_L" = no; then
+ dnl Use an explicit option to hardcode DIR into the resulting
+ dnl binary.
+ LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
+ dnl Potentially add DIR to rpathdirs.
+ dnl The rpathdirs will be appended to $LIBNAME at the end.
+ haveit=
+ for x in $rpathdirs; do
+ if test "X$x" = "X$found_dir"; then
+ haveit=yes
+ break
+ fi
+ done
+ if test -z "$haveit"; then
+ rpathdirs="$rpathdirs $found_dir"
+ fi
+ else
+ dnl Rely on "-L$found_dir".
+ dnl But don't add it if it's already contained in the LDFLAGS
+ dnl or the already constructed $LIBNAME
+ haveit=
+ for x in $LDFLAGS $LIB[]NAME; do
+ AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
+ if test "X$x" = "X-L$found_dir"; then
+ haveit=yes
+ break
+ fi
+ done
+ if test -z "$haveit"; then
+ LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir"
+ fi
+ if test "$hardcode_minus_L" != no; then
+ dnl FIXME: Not sure whether we should use
+ dnl "-L$found_dir -l$name" or "-L$found_dir $found_so"
+ dnl here.
+ LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
+ else
+ dnl We cannot use $hardcode_runpath_var and LD_RUN_PATH
+ dnl here, because this doesn't fit in flags passed to the
+ dnl compiler. So give up. No hardcoding. This affects only
+ dnl very old systems.
+ dnl FIXME: Not sure whether we should use
+ dnl "-L$found_dir -l$name" or "-L$found_dir $found_so"
+ dnl here.
+ LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"
+ fi
+ fi
+ fi
+ fi
+ else
+ if test "X$found_a" != "X"; then
+ dnl Linking with a static library.
+ LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_a"
+ else
+ dnl We shouldn't come here, but anyway it's good to have a
+ dnl fallback.
+ LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir -l$name"
+ fi
+ fi
+ dnl Assume the include files are nearby.
+ additional_includedir=
+ case "$found_dir" in
+ */$acl_libdirstem | */$acl_libdirstem/)
+ basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem/"'*$,,'`
+ additional_includedir="$basedir/include"
+ ;;
+ esac
+ if test "X$additional_includedir" != "X"; then
+ dnl Potentially add $additional_includedir to $INCNAME.
+ dnl But don't add it
+ dnl 1. if it's the standard /usr/include,
+ dnl 2. if it's /usr/local/include and we are using GCC on Linux,
+ dnl 3. if it's already present in $CPPFLAGS or the already
+ dnl constructed $INCNAME,
+ dnl 4. if it doesn't exist as a directory.
+ if test "X$additional_includedir" != "X/usr/include"; then
+ haveit=
+ if test "X$additional_includedir" = "X/usr/local/include"; then
+ if test -n "$GCC"; then
+ case $host_os in
+ linux* | gnu* | k*bsd*-gnu) haveit=yes;;
+ esac
+ fi
+ fi
+ if test -z "$haveit"; then
+ for x in $CPPFLAGS $INC[]NAME; do
+ AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
+ if test "X$x" = "X-I$additional_includedir"; then
+ haveit=yes
+ break
+ fi
+ done
+ if test -z "$haveit"; then
+ if test -d "$additional_includedir"; then
+ dnl Really add $additional_includedir to $INCNAME.
+ INC[]NAME="${INC[]NAME}${INC[]NAME:+ }-I$additional_includedir"
+ fi
+ fi
+ fi
+ fi
+ fi
+ dnl Look for dependencies.
+ if test -n "$found_la"; then
+ dnl Read the .la file. It defines the variables
+ dnl dlname, library_names, old_library, dependency_libs, current,
+ dnl age, revision, installed, dlopen, dlpreopen, libdir.
+ save_libdir="$libdir"
+ case "$found_la" in
+ */* | *\\*) . "$found_la" ;;
+ *) . "./$found_la" ;;
+ esac
+ libdir="$save_libdir"
+ dnl We use only dependency_libs.
+ for dep in $dependency_libs; do
+ case "$dep" in
+ -L*)
+ additional_libdir=`echo "X$dep" | sed -e 's/^X-L//'`
+ dnl Potentially add $additional_libdir to $LIBNAME and $LTLIBNAME.
+ dnl But don't add it
+ dnl 1. if it's the standard /usr/lib,
+ dnl 2. if it's /usr/local/lib and we are using GCC on Linux,
+ dnl 3. if it's already present in $LDFLAGS or the already
+ dnl constructed $LIBNAME,
+ dnl 4. if it doesn't exist as a directory.
+ if test "X$additional_libdir" != "X/usr/$acl_libdirstem"; then
+ haveit=
+ if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem"; then
+ if test -n "$GCC"; then
+ case $host_os in
+ linux* | gnu* | k*bsd*-gnu) haveit=yes;;
+ esac
+ fi
+ fi
+ if test -z "$haveit"; then
+ haveit=
+ for x in $LDFLAGS $LIB[]NAME; do
+ AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
+ if test "X$x" = "X-L$additional_libdir"; then
+ haveit=yes
+ break
+ fi
+ done
+ if test -z "$haveit"; then
+ if test -d "$additional_libdir"; then
+ dnl Really add $additional_libdir to $LIBNAME.
+ LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$additional_libdir"
+ fi
+ fi
+ haveit=
+ for x in $LDFLAGS $LTLIB[]NAME; do
+ AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
+ if test "X$x" = "X-L$additional_libdir"; then
+ haveit=yes
+ break
+ fi
+ done
+ if test -z "$haveit"; then
+ if test -d "$additional_libdir"; then
+ dnl Really add $additional_libdir to $LTLIBNAME.
+ LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$additional_libdir"
+ fi
+ fi
+ fi
+ fi
+ ;;
+ -R*)
+ dir=`echo "X$dep" | sed -e 's/^X-R//'`
+ if test "$enable_rpath" != no; then
+ dnl Potentially add DIR to rpathdirs.
+ dnl The rpathdirs will be appended to $LIBNAME at the end.
+ haveit=
+ for x in $rpathdirs; do
+ if test "X$x" = "X$dir"; then
+ haveit=yes
+ break
+ fi
+ done
+ if test -z "$haveit"; then
+ rpathdirs="$rpathdirs $dir"
+ fi
+ dnl Potentially add DIR to ltrpathdirs.
+ dnl The ltrpathdirs will be appended to $LTLIBNAME at the end.
+ haveit=
+ for x in $ltrpathdirs; do
+ if test "X$x" = "X$dir"; then
+ haveit=yes
+ break
+ fi
+ done
+ if test -z "$haveit"; then
+ ltrpathdirs="$ltrpathdirs $dir"
+ fi
+ fi
+ ;;
+ -l*)
+ dnl Handle this in the next round.
+ names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'`
+ ;;
+ *.la)
+ dnl Handle this in the next round. Throw away the .la's
+ dnl directory; it is already contained in a preceding -L
+ dnl option.
+ names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'`
+ ;;
+ *)
+ dnl Most likely an immediate library name.
+ LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$dep"
+ LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$dep"
+ ;;
+ esac
+ done
+ fi
+ else
+ dnl Didn't find the library; assume it is in the system directories
+ dnl known to the linker and runtime loader. (All the system
+ dnl directories known to the linker should also be known to the
+ dnl runtime loader, otherwise the system is severely misconfigured.)
+ LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"
+ LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-l$name"
+ fi
+ fi
+ fi
+ done
+ done
+ if test "X$rpathdirs" != "X"; then
+ if test -n "$hardcode_libdir_separator"; then
+ dnl Weird platform: only the last -rpath option counts, the user must
+ dnl pass all path elements in one option. We can arrange that for a
+ dnl single library, but not when more than one $LIBNAMEs are used.
+ alldirs=
+ for found_dir in $rpathdirs; do
+ alldirs="${alldirs}${alldirs:+$hardcode_libdir_separator}$found_dir"
+ done
+ dnl Note: hardcode_libdir_flag_spec uses $libdir and $wl.
+ acl_save_libdir="$libdir"
+ libdir="$alldirs"
+ eval flag=\"$hardcode_libdir_flag_spec\"
+ libdir="$acl_save_libdir"
+ LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"
+ else
+ dnl The -rpath options are cumulative.
+ for found_dir in $rpathdirs; do
+ acl_save_libdir="$libdir"
+ libdir="$found_dir"
+ eval flag=\"$hardcode_libdir_flag_spec\"
+ libdir="$acl_save_libdir"
+ LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"
+ done
+ fi
+ fi
+ if test "X$ltrpathdirs" != "X"; then
+ dnl When using libtool, the option that works for both libraries and
+ dnl executables is -R. The -R options are cumulative.
+ for found_dir in $ltrpathdirs; do
+ LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-R$found_dir"
+ done
+ fi
+])
+
+dnl AC_LIB_APPENDTOVAR(VAR, CONTENTS) appends the elements of CONTENTS to VAR,
+dnl unless already present in VAR.
+dnl Works only for CPPFLAGS, not for LIB* variables because that sometimes
+dnl contains two or three consecutive elements that belong together.
+AC_DEFUN([AC_LIB_APPENDTOVAR],
+[
+ for element in [$2]; do
+ haveit=
+ for x in $[$1]; do
+ AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
+ if test "X$x" = "X$element"; then
+ haveit=yes
+ break
+ fi
+ done
+ if test -z "$haveit"; then
+ [$1]="${[$1]}${[$1]:+ }$element"
+ fi
+ done
+])
+
+dnl For those cases where a variable contains several -L and -l options
+dnl referring to unknown libraries and directories, this macro determines the
+dnl necessary additional linker options for the runtime path.
+dnl AC_LIB_LINKFLAGS_FROM_LIBS([LDADDVAR], [LIBSVALUE], [USE-LIBTOOL])
+dnl sets LDADDVAR to linker options needed together with LIBSVALUE.
+dnl If USE-LIBTOOL evaluates to non-empty, linking with libtool is assumed,
+dnl otherwise linking without libtool is assumed.
+AC_DEFUN([AC_LIB_LINKFLAGS_FROM_LIBS],
+[
+ AC_REQUIRE([AC_LIB_RPATH])
+ AC_REQUIRE([AC_LIB_PREPARE_MULTILIB])
+ $1=
+ if test "$enable_rpath" != no; then
+ if test -n "$hardcode_libdir_flag_spec" && test "$hardcode_minus_L" = no; then
+ dnl Use an explicit option to hardcode directories into the resulting
+ dnl binary.
+ rpathdirs=
+ next=
+ for opt in $2; do
+ if test -n "$next"; then
+ dir="$next"
+ dnl No need to hardcode the standard /usr/lib.
+ if test "X$dir" != "X/usr/$acl_libdirstem"; then
+ rpathdirs="$rpathdirs $dir"
+ fi
+ next=
+ else
+ case $opt in
+ -L) next=yes ;;
+ -L*) dir=`echo "X$opt" | sed -e 's,^X-L,,'`
+ dnl No need to hardcode the standard /usr/lib.
+ if test "X$dir" != "X/usr/$acl_libdirstem"; then
+ rpathdirs="$rpathdirs $dir"
+ fi
+ next= ;;
+ *) next= ;;
+ esac
+ fi
+ done
+ if test "X$rpathdirs" != "X"; then
+ if test -n ""$3""; then
+ dnl libtool is used for linking. Use -R options.
+ for dir in $rpathdirs; do
+ $1="${$1}${$1:+ }-R$dir"
+ done
+ else
+ dnl The linker is used for linking directly.
+ if test -n "$hardcode_libdir_separator"; then
+ dnl Weird platform: only the last -rpath option counts, the user
+ dnl must pass all path elements in one option.
+ alldirs=
+ for dir in $rpathdirs; do
+ alldirs="${alldirs}${alldirs:+$hardcode_libdir_separator}$dir"
+ done
+ acl_save_libdir="$libdir"
+ libdir="$alldirs"
+ eval flag=\"$hardcode_libdir_flag_spec\"
+ libdir="$acl_save_libdir"
+ $1="$flag"
+ else
+ dnl The -rpath options are cumulative.
+ for dir in $rpathdirs; do
+ acl_save_libdir="$libdir"
+ libdir="$dir"
+ eval flag=\"$hardcode_libdir_flag_spec\"
+ libdir="$acl_save_libdir"
+ $1="${$1}${$1:+ }$flag"
+ done
+ fi
+ fi
+ fi
+ fi
+ fi
+ AC_SUBST([$1])
+])
diff --git a/m4/gettext/lib-prefix.m4 b/m4/gettext/lib-prefix.m4
new file mode 100644
index 000000000..a8684e17e
--- /dev/null
+++ b/m4/gettext/lib-prefix.m4
@@ -0,0 +1,185 @@
+# lib-prefix.m4 serial 5 (gettext-0.15)
+dnl Copyright (C) 2001-2005 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Bruno Haible.
+
+dnl AC_LIB_ARG_WITH is synonymous to AC_ARG_WITH in autoconf-2.13, and
+dnl similar to AC_ARG_WITH in autoconf 2.52...2.57 except that is doesn't
+dnl require excessive bracketing.
+ifdef([AC_HELP_STRING],
+[AC_DEFUN([AC_LIB_ARG_WITH], [AC_ARG_WITH([$1],[[$2]],[$3],[$4])])],
+[AC_DEFUN([AC_][LIB_ARG_WITH], [AC_ARG_WITH([$1],[$2],[$3],[$4])])])
+
+dnl AC_LIB_PREFIX adds to the CPPFLAGS and LDFLAGS the flags that are needed
+dnl to access previously installed libraries. The basic assumption is that
+dnl a user will want packages to use other packages he previously installed
+dnl with the same --prefix option.
+dnl This macro is not needed if only AC_LIB_LINKFLAGS is used to locate
+dnl libraries, but is otherwise very convenient.
+AC_DEFUN([AC_LIB_PREFIX],
+[
+ AC_BEFORE([$0], [AC_LIB_LINKFLAGS])
+ AC_REQUIRE([AC_PROG_CC])
+ AC_REQUIRE([AC_CANONICAL_HOST])
+ AC_REQUIRE([AC_LIB_PREPARE_MULTILIB])
+ AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
+ dnl By default, look in $includedir and $libdir.
+ use_additional=yes
+ AC_LIB_WITH_FINAL_PREFIX([
+ eval additional_includedir=\"$includedir\"
+ eval additional_libdir=\"$libdir\"
+ ])
+ AC_LIB_ARG_WITH([lib-prefix],
+[ --with-lib-prefix[=DIR] search for libraries in DIR/include and DIR/lib
+ --without-lib-prefix don't search for libraries in includedir and libdir],
+[
+ if test "X$withval" = "Xno"; then
+ use_additional=no
+ else
+ if test "X$withval" = "X"; then
+ AC_LIB_WITH_FINAL_PREFIX([
+ eval additional_includedir=\"$includedir\"
+ eval additional_libdir=\"$libdir\"
+ ])
+ else
+ additional_includedir="$withval/include"
+ additional_libdir="$withval/$acl_libdirstem"
+ fi
+ fi
+])
+ if test $use_additional = yes; then
+ dnl Potentially add $additional_includedir to $CPPFLAGS.
+ dnl But don't add it
+ dnl 1. if it's the standard /usr/include,
+ dnl 2. if it's already present in $CPPFLAGS,
+ dnl 3. if it's /usr/local/include and we are using GCC on Linux,
+ dnl 4. if it doesn't exist as a directory.
+ if test "X$additional_includedir" != "X/usr/include"; then
+ haveit=
+ for x in $CPPFLAGS; do
+ AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
+ if test "X$x" = "X-I$additional_includedir"; then
+ haveit=yes
+ break
+ fi
+ done
+ if test -z "$haveit"; then
+ if test "X$additional_includedir" = "X/usr/local/include"; then
+ if test -n "$GCC"; then
+ case $host_os in
+ linux* | gnu* | k*bsd*-gnu) haveit=yes;;
+ esac
+ fi
+ fi
+ if test -z "$haveit"; then
+ if test -d "$additional_includedir"; then
+ dnl Really add $additional_includedir to $CPPFLAGS.
+ CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }-I$additional_includedir"
+ fi
+ fi
+ fi
+ fi
+ dnl Potentially add $additional_libdir to $LDFLAGS.
+ dnl But don't add it
+ dnl 1. if it's the standard /usr/lib,
+ dnl 2. if it's already present in $LDFLAGS,
+ dnl 3. if it's /usr/local/lib and we are using GCC on Linux,
+ dnl 4. if it doesn't exist as a directory.
+ if test "X$additional_libdir" != "X/usr/$acl_libdirstem"; then
+ haveit=
+ for x in $LDFLAGS; do
+ AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
+ if test "X$x" = "X-L$additional_libdir"; then
+ haveit=yes
+ break
+ fi
+ done
+ if test -z "$haveit"; then
+ if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem"; then
+ if test -n "$GCC"; then
+ case $host_os in
+ linux*) haveit=yes;;
+ esac
+ fi
+ fi
+ if test -z "$haveit"; then
+ if test -d "$additional_libdir"; then
+ dnl Really add $additional_libdir to $LDFLAGS.
+ LDFLAGS="${LDFLAGS}${LDFLAGS:+ }-L$additional_libdir"
+ fi
+ fi
+ fi
+ fi
+ fi
+])
+
+dnl AC_LIB_PREPARE_PREFIX creates variables acl_final_prefix,
+dnl acl_final_exec_prefix, containing the values to which $prefix and
+dnl $exec_prefix will expand at the end of the configure script.
+AC_DEFUN([AC_LIB_PREPARE_PREFIX],
+[
+ dnl Unfortunately, prefix and exec_prefix get only finally determined
+ dnl at the end of configure.
+ if test "X$prefix" = "XNONE"; then
+ acl_final_prefix="$ac_default_prefix"
+ else
+ acl_final_prefix="$prefix"
+ fi
+ if test "X$exec_prefix" = "XNONE"; then
+ acl_final_exec_prefix='${prefix}'
+ else
+ acl_final_exec_prefix="$exec_prefix"
+ fi
+ acl_save_prefix="$prefix"
+ prefix="$acl_final_prefix"
+ eval acl_final_exec_prefix=\"$acl_final_exec_prefix\"
+ prefix="$acl_save_prefix"
+])
+
+dnl AC_LIB_WITH_FINAL_PREFIX([statement]) evaluates statement, with the
+dnl variables prefix and exec_prefix bound to the values they will have
+dnl at the end of the configure script.
+AC_DEFUN([AC_LIB_WITH_FINAL_PREFIX],
+[
+ acl_save_prefix="$prefix"
+ prefix="$acl_final_prefix"
+ acl_save_exec_prefix="$exec_prefix"
+ exec_prefix="$acl_final_exec_prefix"
+ $1
+ exec_prefix="$acl_save_exec_prefix"
+ prefix="$acl_save_prefix"
+])
+
+dnl AC_LIB_PREPARE_MULTILIB creates a variable acl_libdirstem, containing
+dnl the basename of the libdir, either "lib" or "lib64".
+AC_DEFUN([AC_LIB_PREPARE_MULTILIB],
+[
+ dnl There is no formal standard regarding lib and lib64. The current
+ dnl practice is that on a system supporting 32-bit and 64-bit instruction
+ dnl sets or ABIs, 64-bit libraries go under $prefix/lib64 and 32-bit
+ dnl libraries go under $prefix/lib. We determine the compiler's default
+ dnl mode by looking at the compiler's library search path. If at least
+ dnl of its elements ends in /lib64 or points to a directory whose absolute
+ dnl pathname ends in /lib64, we assume a 64-bit ABI. Otherwise we use the
+ dnl default, namely "lib".
+ acl_libdirstem=lib
+ searchpath=`(LC_ALL=C $CC -print-search-dirs) 2>/dev/null | sed -n -e 's,^libraries: ,,p' | sed -e 's,^=,,'`
+ if test -n "$searchpath"; then
+ acl_save_IFS="${IFS= }"; IFS=":"
+ for searchdir in $searchpath; do
+ if test -d "$searchdir"; then
+ case "$searchdir" in
+ */lib64/ | */lib64 ) acl_libdirstem=lib64 ;;
+ *) searchdir=`cd "$searchdir" && pwd`
+ case "$searchdir" in
+ */lib64 ) acl_libdirstem=lib64 ;;
+ esac ;;
+ esac
+ fi
+ done
+ IFS="$acl_save_IFS"
+ fi
+])
diff --git a/m4/longdouble.m4 b/m4/gettext/longdouble.m4
index 40cd7ce02..40cd7ce02 100644
--- a/m4/longdouble.m4
+++ b/m4/gettext/longdouble.m4
diff --git a/m4/longlong.m4 b/m4/gettext/longlong.m4
index 7b399e012..7b399e012 100644
--- a/m4/longlong.m4
+++ b/m4/gettext/longlong.m4
diff --git a/m4/gettext/nls.m4 b/m4/gettext/nls.m4
new file mode 100644
index 000000000..7967cc2f9
--- /dev/null
+++ b/m4/gettext/nls.m4
@@ -0,0 +1,31 @@
+# nls.m4 serial 3 (gettext-0.15)
+dnl Copyright (C) 1995-2003, 2005-2006 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+dnl
+dnl This file can can be used in projects which are not available under
+dnl the GNU General Public License or the GNU Library General Public
+dnl License but which still want to provide support for the GNU gettext
+dnl functionality.
+dnl Please note that the actual code of the GNU gettext library is covered
+dnl by the GNU Library General Public License, and the rest of the GNU
+dnl gettext package package is covered by the GNU General Public License.
+dnl They are *not* in the public domain.
+
+dnl Authors:
+dnl Ulrich Drepper <drepper@cygnus.com>, 1995-2000.
+dnl Bruno Haible <haible@clisp.cons.org>, 2000-2003.
+
+AC_PREREQ(2.50)
+
+AC_DEFUN([AM_NLS],
+[
+ AC_MSG_CHECKING([whether NLS is requested])
+ dnl Default is enabled NLS
+ AC_ARG_ENABLE(nls,
+ [ --disable-nls do not use Native Language Support],
+ USE_NLS=$enableval, USE_NLS=yes)
+ AC_MSG_RESULT($USE_NLS)
+ AC_SUBST(USE_NLS)
+])
diff --git a/m4/gettext/po.m4 b/m4/gettext/po.m4
new file mode 100644
index 000000000..00133ef36
--- /dev/null
+++ b/m4/gettext/po.m4
@@ -0,0 +1,428 @@
+# po.m4 serial 13 (gettext-0.15)
+dnl Copyright (C) 1995-2006 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+dnl
+dnl This file can can be used in projects which are not available under
+dnl the GNU General Public License or the GNU Library General Public
+dnl License but which still want to provide support for the GNU gettext
+dnl functionality.
+dnl Please note that the actual code of the GNU gettext library is covered
+dnl by the GNU Library General Public License, and the rest of the GNU
+dnl gettext package package is covered by the GNU General Public License.
+dnl They are *not* in the public domain.
+
+dnl Authors:
+dnl Ulrich Drepper <drepper@cygnus.com>, 1995-2000.
+dnl Bruno Haible <haible@clisp.cons.org>, 2000-2003.
+
+AC_PREREQ(2.50)
+
+dnl Checks for all prerequisites of the po subdirectory.
+AC_DEFUN([AM_PO_SUBDIRS],
+[
+ AC_REQUIRE([AC_PROG_MAKE_SET])dnl
+ AC_REQUIRE([AC_PROG_INSTALL])dnl
+ AC_REQUIRE([AM_PROG_MKDIR_P])dnl defined by automake
+ AC_REQUIRE([AM_NLS])dnl
+
+ dnl Perform the following tests also if --disable-nls has been given,
+ dnl because they are needed for "make dist" to work.
+
+ dnl Search for GNU msgfmt in the PATH.
+ dnl The first test excludes Solaris msgfmt and early GNU msgfmt versions.
+ dnl The second test excludes FreeBSD msgfmt.
+ AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
+ [$ac_dir/$ac_word --statistics /dev/null >&]AS_MESSAGE_LOG_FD[ 2>&1 &&
+ (if $ac_dir/$ac_word --statistics /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi)],
+ :)
+ AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
+
+ dnl Test whether it is GNU msgfmt >= 0.15.
+changequote(,)dnl
+ case `$MSGFMT --version | sed 1q | sed -e 's,^[^0-9]*,,'` in
+ '' | 0.[0-9] | 0.[0-9].* | 0.1[0-4] | 0.1[0-4].*) MSGFMT_015=: ;;
+ *) MSGFMT_015=$MSGFMT ;;
+ esac
+changequote([,])dnl
+ AC_SUBST([MSGFMT_015])
+changequote(,)dnl
+ case `$GMSGFMT --version | sed 1q | sed -e 's,^[^0-9]*,,'` in
+ '' | 0.[0-9] | 0.[0-9].* | 0.1[0-4] | 0.1[0-4].*) GMSGFMT_015=: ;;
+ *) GMSGFMT_015=$GMSGFMT ;;
+ esac
+changequote([,])dnl
+ AC_SUBST([GMSGFMT_015])
+
+ dnl Search for GNU xgettext 0.12 or newer in the PATH.
+ dnl The first test excludes Solaris xgettext and early GNU xgettext versions.
+ dnl The second test excludes FreeBSD xgettext.
+ AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
+ [$ac_dir/$ac_word --omit-header --copyright-holder= --msgid-bugs-address= /dev/null >&]AS_MESSAGE_LOG_FD[ 2>&1 &&
+ (if $ac_dir/$ac_word --omit-header --copyright-holder= --msgid-bugs-address= /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi)],
+ :)
+ dnl Remove leftover from FreeBSD xgettext call.
+ rm -f messages.po
+
+ dnl Test whether it is GNU xgettext >= 0.15.
+changequote(,)dnl
+ case `$XGETTEXT --version | sed 1q | sed -e 's,^[^0-9]*,,'` in
+ '' | 0.[0-9] | 0.[0-9].* | 0.1[0-4] | 0.1[0-4].*) XGETTEXT_015=: ;;
+ *) XGETTEXT_015=$XGETTEXT ;;
+ esac
+changequote([,])dnl
+ AC_SUBST([XGETTEXT_015])
+
+ dnl Search for GNU msgmerge 0.11 or newer in the PATH.
+ AM_PATH_PROG_WITH_TEST(MSGMERGE, msgmerge,
+ [$ac_dir/$ac_word --update -q /dev/null /dev/null >&]AS_MESSAGE_LOG_FD[ 2>&1], :)
+
+ dnl Installation directories.
+ dnl Autoconf >= 2.60 defines localedir. For older versions of autoconf, we
+ dnl have to define it here, so that it can be used in po/Makefile.
+ test -n "$localedir" || localedir='${datadir}/locale'
+ AC_SUBST([localedir])
+
+ AC_CONFIG_COMMANDS([po-directories], [[
+ for ac_file in $CONFIG_FILES; do
+ # Support "outfile[:infile[:infile...]]"
+ case "$ac_file" in
+ *:*) ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;;
+ esac
+ # PO directories have a Makefile.in generated from Makefile.in.in.
+ case "$ac_file" in */Makefile.in)
+ # Adjust a relative srcdir.
+ ac_dir=`echo "$ac_file"|sed 's%/[^/][^/]*$%%'`
+ ac_dir_suffix="/`echo "$ac_dir"|sed 's%^\./%%'`"
+ ac_dots=`echo "$ac_dir_suffix"|sed 's%/[^/]*%../%g'`
+ # In autoconf-2.13 it is called $ac_given_srcdir.
+ # In autoconf-2.50 it is called $srcdir.
+ test -n "$ac_given_srcdir" || ac_given_srcdir="$srcdir"
+ case "$ac_given_srcdir" in
+ .) top_srcdir=`echo $ac_dots|sed 's%/$%%'` ;;
+ /*) top_srcdir="$ac_given_srcdir" ;;
+ *) top_srcdir="$ac_dots$ac_given_srcdir" ;;
+ esac
+ # Treat a directory as a PO directory if and only if it has a
+ # POTFILES.in file. This allows packages to have multiple PO
+ # directories under different names or in different locations.
+ if test -f "$ac_given_srcdir/$ac_dir/POTFILES.in"; then
+ rm -f "$ac_dir/POTFILES"
+ test -n "$as_me" && echo "$as_me: creating $ac_dir/POTFILES" || echo "creating $ac_dir/POTFILES"
+ cat "$ac_given_srcdir/$ac_dir/POTFILES.in" | sed -e "/^#/d" -e "/^[ ]*\$/d" -e "s,.*, $top_srcdir/& \\\\," | sed -e "\$s/\(.*\) \\\\/\1/" > "$ac_dir/POTFILES"
+ POMAKEFILEDEPS="POTFILES.in"
+ # ALL_LINGUAS, POFILES, UPDATEPOFILES, DUMMYPOFILES, GMOFILES depend
+ # on $ac_dir but don't depend on user-specified configuration
+ # parameters.
+ if test -f "$ac_given_srcdir/$ac_dir/LINGUAS"; then
+ # The LINGUAS file contains the set of available languages.
+ if test -n "$OBSOLETE_ALL_LINGUAS"; then
+ test -n "$as_me" && echo "$as_me: setting ALL_LINGUAS in configure.in is obsolete" || echo "setting ALL_LINGUAS in configure.in is obsolete"
+ fi
+ ALL_LINGUAS_=`sed -e "/^#/d" -e "s/#.*//" "$ac_given_srcdir/$ac_dir/LINGUAS"`
+ # Hide the ALL_LINGUAS assigment from automake < 1.5.
+ eval 'ALL_LINGUAS''=$ALL_LINGUAS_'
+ POMAKEFILEDEPS="$POMAKEFILEDEPS LINGUAS"
+ else
+ # The set of available languages was given in configure.in.
+ # Hide the ALL_LINGUAS assigment from automake < 1.5.
+ eval 'ALL_LINGUAS''=$OBSOLETE_ALL_LINGUAS'
+ fi
+ # Compute POFILES
+ # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).po)
+ # Compute UPDATEPOFILES
+ # as $(foreach lang, $(ALL_LINGUAS), $(lang).po-update)
+ # Compute DUMMYPOFILES
+ # as $(foreach lang, $(ALL_LINGUAS), $(lang).nop)
+ # Compute GMOFILES
+ # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).gmo)
+ case "$ac_given_srcdir" in
+ .) srcdirpre= ;;
+ *) srcdirpre='$(srcdir)/' ;;
+ esac
+ POFILES=
+ UPDATEPOFILES=
+ DUMMYPOFILES=
+ GMOFILES=
+ for lang in $ALL_LINGUAS; do
+ POFILES="$POFILES $srcdirpre$lang.po"
+ UPDATEPOFILES="$UPDATEPOFILES $lang.po-update"
+ DUMMYPOFILES="$DUMMYPOFILES $lang.nop"
+ GMOFILES="$GMOFILES $srcdirpre$lang.gmo"
+ done
+ # CATALOGS depends on both $ac_dir and the user's LINGUAS
+ # environment variable.
+ INST_LINGUAS=
+ if test -n "$ALL_LINGUAS"; then
+ for presentlang in $ALL_LINGUAS; do
+ useit=no
+ if test "%UNSET%" != "$LINGUAS"; then
+ desiredlanguages="$LINGUAS"
+ else
+ desiredlanguages="$ALL_LINGUAS"
+ fi
+ for desiredlang in $desiredlanguages; do
+ # Use the presentlang catalog if desiredlang is
+ # a. equal to presentlang, or
+ # b. a variant of presentlang (because in this case,
+ # presentlang can be used as a fallback for messages
+ # which are not translated in the desiredlang catalog).
+ case "$desiredlang" in
+ "$presentlang"*) useit=yes;;
+ esac
+ done
+ if test $useit = yes; then
+ INST_LINGUAS="$INST_LINGUAS $presentlang"
+ fi
+ done
+ fi
+ CATALOGS=
+ if test -n "$INST_LINGUAS"; then
+ for lang in $INST_LINGUAS; do
+ CATALOGS="$CATALOGS $lang.gmo"
+ done
+ fi
+ test -n "$as_me" && echo "$as_me: creating $ac_dir/Makefile" || echo "creating $ac_dir/Makefile"
+ sed -e "/^POTFILES =/r $ac_dir/POTFILES" -e "/^# Makevars/r $ac_given_srcdir/$ac_dir/Makevars" -e "s|@POFILES@|$POFILES|g" -e "s|@UPDATEPOFILES@|$UPDATEPOFILES|g" -e "s|@DUMMYPOFILES@|$DUMMYPOFILES|g" -e "s|@GMOFILES@|$GMOFILES|g" -e "s|@CATALOGS@|$CATALOGS|g" -e "s|@POMAKEFILEDEPS@|$POMAKEFILEDEPS|g" "$ac_dir/Makefile.in" > "$ac_dir/Makefile"
+ for f in "$ac_given_srcdir/$ac_dir"/Rules-*; do
+ if test -f "$f"; then
+ case "$f" in
+ *.orig | *.bak | *~) ;;
+ *) cat "$f" >> "$ac_dir/Makefile" ;;
+ esac
+ fi
+ done
+ fi
+ ;;
+ esac
+ done]],
+ [# Capture the value of obsolete ALL_LINGUAS because we need it to compute
+ # POFILES, UPDATEPOFILES, DUMMYPOFILES, GMOFILES, CATALOGS. But hide it
+ # from automake < 1.5.
+ eval 'OBSOLETE_ALL_LINGUAS''="$ALL_LINGUAS"'
+ # Capture the value of LINGUAS because we need it to compute CATALOGS.
+ LINGUAS="${LINGUAS-%UNSET%}"
+ ])
+])
+
+dnl Postprocesses a Makefile in a directory containing PO files.
+AC_DEFUN([AM_POSTPROCESS_PO_MAKEFILE],
+[
+ # When this code is run, in config.status, two variables have already been
+ # set:
+ # - OBSOLETE_ALL_LINGUAS is the value of LINGUAS set in configure.in,
+ # - LINGUAS is the value of the environment variable LINGUAS at configure
+ # time.
+
+changequote(,)dnl
+ # Adjust a relative srcdir.
+ ac_dir=`echo "$ac_file"|sed 's%/[^/][^/]*$%%'`
+ ac_dir_suffix="/`echo "$ac_dir"|sed 's%^\./%%'`"
+ ac_dots=`echo "$ac_dir_suffix"|sed 's%/[^/]*%../%g'`
+ # In autoconf-2.13 it is called $ac_given_srcdir.
+ # In autoconf-2.50 it is called $srcdir.
+ test -n "$ac_given_srcdir" || ac_given_srcdir="$srcdir"
+ case "$ac_given_srcdir" in
+ .) top_srcdir=`echo $ac_dots|sed 's%/$%%'` ;;
+ /*) top_srcdir="$ac_given_srcdir" ;;
+ *) top_srcdir="$ac_dots$ac_given_srcdir" ;;
+ esac
+
+ # Find a way to echo strings without interpreting backslash.
+ if test "X`(echo '\t') 2>/dev/null`" = 'X\t'; then
+ gt_echo='echo'
+ else
+ if test "X`(printf '%s\n' '\t') 2>/dev/null`" = 'X\t'; then
+ gt_echo='printf %s\n'
+ else
+ echo_func () {
+ cat <<EOT
+$*
+EOT
+ }
+ gt_echo='echo_func'
+ fi
+ fi
+
+ # A sed script that extracts the value of VARIABLE from a Makefile.
+ sed_x_variable='
+# Test if the hold space is empty.
+x
+s/P/P/
+x
+ta
+# Yes it was empty. Look if we have the expected variable definition.
+/^[ ]*VARIABLE[ ]*=/{
+ # Seen the first line of the variable definition.
+ s/^[ ]*VARIABLE[ ]*=//
+ ba
+}
+bd
+:a
+# Here we are processing a line from the variable definition.
+# Remove comment, more precisely replace it with a space.
+s/#.*$/ /
+# See if the line ends in a backslash.
+tb
+:b
+s/\\$//
+# Print the line, without the trailing backslash.
+p
+tc
+# There was no trailing backslash. The end of the variable definition is
+# reached. Clear the hold space.
+s/^.*$//
+x
+bd
+:c
+# A trailing backslash means that the variable definition continues in the
+# next line. Put a nonempty string into the hold space to indicate this.
+s/^.*$/P/
+x
+:d
+'
+changequote([,])dnl
+
+ # Set POTFILES to the value of the Makefile variable POTFILES.
+ sed_x_POTFILES=`$gt_echo "$sed_x_variable" | sed -e '/^ *#/d' -e 's/VARIABLE/POTFILES/g'`
+ POTFILES=`sed -n -e "$sed_x_POTFILES" < "$ac_file"`
+ # Compute POTFILES_DEPS as
+ # $(foreach file, $(POTFILES), $(top_srcdir)/$(file))
+ POTFILES_DEPS=
+ for file in $POTFILES; do
+ POTFILES_DEPS="$POTFILES_DEPS "'$(top_srcdir)/'"$file"
+ done
+ POMAKEFILEDEPS=""
+
+ if test -n "$OBSOLETE_ALL_LINGUAS"; then
+ test -n "$as_me" && echo "$as_me: setting ALL_LINGUAS in configure.in is obsolete" || echo "setting ALL_LINGUAS in configure.in is obsolete"
+ fi
+ if test -f "$ac_given_srcdir/$ac_dir/LINGUAS"; then
+ # The LINGUAS file contains the set of available languages.
+ ALL_LINGUAS_=`sed -e "/^#/d" -e "s/#.*//" "$ac_given_srcdir/$ac_dir/LINGUAS"`
+ POMAKEFILEDEPS="$POMAKEFILEDEPS LINGUAS"
+ else
+ # Set ALL_LINGUAS to the value of the Makefile variable LINGUAS.
+ sed_x_LINGUAS=`$gt_echo "$sed_x_variable" | sed -e '/^ *#/d' -e 's/VARIABLE/LINGUAS/g'`
+ ALL_LINGUAS_=`sed -n -e "$sed_x_LINGUAS" < "$ac_file"`
+ fi
+ # Hide the ALL_LINGUAS assigment from automake < 1.5.
+ eval 'ALL_LINGUAS''=$ALL_LINGUAS_'
+ # Compute POFILES
+ # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).po)
+ # Compute UPDATEPOFILES
+ # as $(foreach lang, $(ALL_LINGUAS), $(lang).po-update)
+ # Compute DUMMYPOFILES
+ # as $(foreach lang, $(ALL_LINGUAS), $(lang).nop)
+ # Compute GMOFILES
+ # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).gmo)
+ # Compute PROPERTIESFILES
+ # as $(foreach lang, $(ALL_LINGUAS), $(top_srcdir)/$(DOMAIN)_$(lang).properties)
+ # Compute CLASSFILES
+ # as $(foreach lang, $(ALL_LINGUAS), $(top_srcdir)/$(DOMAIN)_$(lang).class)
+ # Compute QMFILES
+ # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).qm)
+ # Compute MSGFILES
+ # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(frob $(lang)).msg)
+ # Compute RESOURCESDLLFILES
+ # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(frob $(lang))/$(DOMAIN).resources.dll)
+ case "$ac_given_srcdir" in
+ .) srcdirpre= ;;
+ *) srcdirpre='$(srcdir)/' ;;
+ esac
+ POFILES=
+ UPDATEPOFILES=
+ DUMMYPOFILES=
+ GMOFILES=
+ PROPERTIESFILES=
+ CLASSFILES=
+ QMFILES=
+ MSGFILES=
+ RESOURCESDLLFILES=
+ for lang in $ALL_LINGUAS; do
+ POFILES="$POFILES $srcdirpre$lang.po"
+ UPDATEPOFILES="$UPDATEPOFILES $lang.po-update"
+ DUMMYPOFILES="$DUMMYPOFILES $lang.nop"
+ GMOFILES="$GMOFILES $srcdirpre$lang.gmo"
+ PROPERTIESFILES="$PROPERTIESFILES \$(top_srcdir)/\$(DOMAIN)_$lang.properties"
+ CLASSFILES="$CLASSFILES \$(top_srcdir)/\$(DOMAIN)_$lang.class"
+ QMFILES="$QMFILES $srcdirpre$lang.qm"
+ frobbedlang=`echo $lang | sed -e 's/\..*$//' -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
+ MSGFILES="$MSGFILES $srcdirpre$frobbedlang.msg"
+ frobbedlang=`echo $lang | sed -e 's/_/-/g' -e 's/^sr-CS/sr-SP/' -e 's/@latin$/-Latn/' -e 's/@cyrillic$/-Cyrl/' -e 's/^sr-SP$/sr-SP-Latn/' -e 's/^uz-UZ$/uz-UZ-Latn/'`
+ RESOURCESDLLFILES="$RESOURCESDLLFILES $srcdirpre$frobbedlang/\$(DOMAIN).resources.dll"
+ done
+ # CATALOGS depends on both $ac_dir and the user's LINGUAS
+ # environment variable.
+ INST_LINGUAS=
+ if test -n "$ALL_LINGUAS"; then
+ for presentlang in $ALL_LINGUAS; do
+ useit=no
+ if test "%UNSET%" != "$LINGUAS"; then
+ desiredlanguages="$LINGUAS"
+ else
+ desiredlanguages="$ALL_LINGUAS"
+ fi
+ for desiredlang in $desiredlanguages; do
+ # Use the presentlang catalog if desiredlang is
+ # a. equal to presentlang, or
+ # b. a variant of presentlang (because in this case,
+ # presentlang can be used as a fallback for messages
+ # which are not translated in the desiredlang catalog).
+ case "$desiredlang" in
+ "$presentlang"*) useit=yes;;
+ esac
+ done
+ if test $useit = yes; then
+ INST_LINGUAS="$INST_LINGUAS $presentlang"
+ fi
+ done
+ fi
+ CATALOGS=
+ JAVACATALOGS=
+ QTCATALOGS=
+ TCLCATALOGS=
+ CSHARPCATALOGS=
+ if test -n "$INST_LINGUAS"; then
+ for lang in $INST_LINGUAS; do
+ CATALOGS="$CATALOGS $lang.gmo"
+ JAVACATALOGS="$JAVACATALOGS \$(DOMAIN)_$lang.properties"
+ QTCATALOGS="$QTCATALOGS $lang.qm"
+ frobbedlang=`echo $lang | sed -e 's/\..*$//' -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
+ TCLCATALOGS="$TCLCATALOGS $frobbedlang.msg"
+ frobbedlang=`echo $lang | sed -e 's/_/-/g' -e 's/^sr-CS/sr-SP/' -e 's/@latin$/-Latn/' -e 's/@cyrillic$/-Cyrl/' -e 's/^sr-SP$/sr-SP-Latn/' -e 's/^uz-UZ$/uz-UZ-Latn/'`
+ CSHARPCATALOGS="$CSHARPCATALOGS $frobbedlang/\$(DOMAIN).resources.dll"
+ done
+ fi
+
+ sed -e "s|@POTFILES_DEPS@|$POTFILES_DEPS|g" -e "s|@POFILES@|$POFILES|g" -e "s|@UPDATEPOFILES@|$UPDATEPOFILES|g" -e "s|@DUMMYPOFILES@|$DUMMYPOFILES|g" -e "s|@GMOFILES@|$GMOFILES|g" -e "s|@PROPERTIESFILES@|$PROPERTIESFILES|g" -e "s|@CLASSFILES@|$CLASSFILES|g" -e "s|@QMFILES@|$QMFILES|g" -e "s|@MSGFILES@|$MSGFILES|g" -e "s|@RESOURCESDLLFILES@|$RESOURCESDLLFILES|g" -e "s|@CATALOGS@|$CATALOGS|g" -e "s|@JAVACATALOGS@|$JAVACATALOGS|g" -e "s|@QTCATALOGS@|$QTCATALOGS|g" -e "s|@TCLCATALOGS@|$TCLCATALOGS|g" -e "s|@CSHARPCATALOGS@|$CSHARPCATALOGS|g" -e 's,^#distdir:,distdir:,' < "$ac_file" > "$ac_file.tmp"
+ if grep -l '@TCLCATALOGS@' "$ac_file" > /dev/null; then
+ # Add dependencies that cannot be formulated as a simple suffix rule.
+ for lang in $ALL_LINGUAS; do
+ frobbedlang=`echo $lang | sed -e 's/\..*$//' -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
+ cat >> "$ac_file.tmp" <<EOF
+$frobbedlang.msg: $lang.po
+ @echo "\$(MSGFMT) -c --tcl -d \$(srcdir) -l $lang $srcdirpre$lang.po"; \
+ \$(MSGFMT) -c --tcl -d "\$(srcdir)" -l $lang $srcdirpre$lang.po || { rm -f "\$(srcdir)/$frobbedlang.msg"; exit 1; }
+EOF
+ done
+ fi
+ if grep -l '@CSHARPCATALOGS@' "$ac_file" > /dev/null; then
+ # Add dependencies that cannot be formulated as a simple suffix rule.
+ for lang in $ALL_LINGUAS; do
+ frobbedlang=`echo $lang | sed -e 's/_/-/g' -e 's/^sr-CS/sr-SP/' -e 's/@latin$/-Latn/' -e 's/@cyrillic$/-Cyrl/' -e 's/^sr-SP$/sr-SP-Latn/' -e 's/^uz-UZ$/uz-UZ-Latn/'`
+ cat >> "$ac_file.tmp" <<EOF
+$frobbedlang/\$(DOMAIN).resources.dll: $lang.po
+ @echo "\$(MSGFMT) -c --csharp -d \$(srcdir) -l $lang $srcdirpre$lang.po -r \$(DOMAIN)"; \
+ \$(MSGFMT) -c --csharp -d "\$(srcdir)" -l $lang $srcdirpre$lang.po -r "\$(DOMAIN)" || { rm -f "\$(srcdir)/$frobbedlang.msg"; exit 1; }
+EOF
+ done
+ fi
+ if test -n "$POMAKEFILEDEPS"; then
+ cat >> "$ac_file.tmp" <<EOF
+Makefile: $POMAKEFILEDEPS
+EOF
+ fi
+ mv "$ac_file.tmp" "$ac_file"
+])
diff --git a/m4/printf-posix.m4 b/m4/gettext/printf-posix.m4
index af10170af..af10170af 100644
--- a/m4/printf-posix.m4
+++ b/m4/gettext/printf-posix.m4
diff --git a/m4/progtest.m4 b/m4/gettext/progtest.m4
index a56365cd3..a56365cd3 100644
--- a/m4/progtest.m4
+++ b/m4/gettext/progtest.m4
diff --git a/m4/signed.m4 b/m4/gettext/signed.m4
index 048f59369..048f59369 100644
--- a/m4/signed.m4
+++ b/m4/gettext/signed.m4
diff --git a/m4/size_max.m4 b/m4/gettext/size_max.m4
index 4fe81c7b0..4fe81c7b0 100644
--- a/m4/size_max.m4
+++ b/m4/gettext/size_max.m4
diff --git a/m4/stdint_h.m4 b/m4/gettext/stdint_h.m4
index 3355f35aa..3355f35aa 100644
--- a/m4/stdint_h.m4
+++ b/m4/gettext/stdint_h.m4
diff --git a/m4/uintmax_t.m4 b/m4/gettext/uintmax_t.m4
index bf83ed746..bf83ed746 100644
--- a/m4/uintmax_t.m4
+++ b/m4/gettext/uintmax_t.m4
diff --git a/m4/ulonglong.m4 b/m4/gettext/ulonglong.m4
index dee10ccc3..dee10ccc3 100644
--- a/m4/ulonglong.m4
+++ b/m4/gettext/ulonglong.m4
diff --git a/m4/wchar_t.m4 b/m4/gettext/wchar_t.m4
index cde2129a9..cde2129a9 100644
--- a/m4/wchar_t.m4
+++ b/m4/gettext/wchar_t.m4
diff --git a/m4/wint_t.m4 b/m4/gettext/wint_t.m4
index b8fff9c86..b8fff9c86 100644
--- a/m4/wint_t.m4
+++ b/m4/gettext/wint_t.m4
diff --git a/m4/xsize.m4 b/m4/gettext/xsize.m4
index 85bb721e4..85bb721e4 100644
--- a/m4/xsize.m4
+++ b/m4/gettext/xsize.m4
diff --git a/m4/iconv.m4 b/m4/iconv.m4
deleted file mode 100644
index 5ed7c43ae..000000000
--- a/m4/iconv.m4
+++ /dev/null
@@ -1,117 +0,0 @@
-# iconv.m4 serial AM4 (gettext-0.11.3)
-dnl Copyright (C) 2000-2002 Free Software Foundation, Inc.
-dnl This file is free software; the Free Software Foundation
-dnl gives unlimited permission to copy and/or distribute it,
-dnl with or without modifications, as long as this notice is preserved.
-
-dnl From Bruno Haible.
-
-AC_DEFUN([AM_ICONV_LINKFLAGS_BODY],
-[
- dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
- AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
- AC_REQUIRE([AC_LIB_RPATH])
-
- dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
- dnl accordingly.
- AC_LIB_LINKFLAGS_BODY([iconv])
-
- dnl
- dnl xine: added the prefix /usr/local on FreeBSD if none specified
- dnl
- if test -z "$INCICONV"; then
- case "$host" in
- *-*-freebsd*)
- dir=/usr/local
- if test -d $dir/include; then INCICONV="$INCICONV -I$dir/include"; fi
- if test -d $dir/lib; then
- LIBICONV="$LIBICONV -L$dir/lib"
- LTLIBICONV="$LTLIBICONV -L$dir/lib"
- fi
- ;;
- esac
- fi
-])
-
-AC_DEFUN([AM_ICONV_LINK],
-[
- dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
- dnl those with the standalone portable GNU libiconv installed).
-
- dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
- dnl accordingly.
- AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY])
-
- dnl Add $INCICONV to CPPFLAGS before performing the following checks,
- dnl because if the user has installed libiconv and not disabled its use
- dnl via --without-libiconv-prefix, he wants to use it. The first
- dnl AC_TRY_LINK will then fail, the second AC_TRY_LINK will succeed.
- am_save_CPPFLAGS="$CPPFLAGS"
- AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV])
-
- AC_CACHE_CHECK(for iconv, am_cv_func_iconv, [
- am_cv_func_iconv="no, consider installing GNU libiconv"
- am_cv_lib_iconv=no
- AC_TRY_LINK([#include <stdlib.h>
-#include <iconv.h>],
- [iconv_t cd = iconv_open("","");
- iconv(cd,NULL,NULL,NULL,NULL);
- iconv_close(cd);],
- am_cv_func_iconv=yes)
- if test "$am_cv_func_iconv" != yes; then
- am_save_LIBS="$LIBS"
- LIBS="$LIBS $LIBICONV"
- AC_TRY_LINK([#include <stdlib.h>
-#include <iconv.h>],
- [iconv_t cd = iconv_open("","");
- iconv(cd,NULL,NULL,NULL,NULL);
- iconv_close(cd);],
- am_cv_lib_iconv=yes
- am_cv_func_iconv=yes)
- LIBS="$am_save_LIBS"
- fi
- ])
- if test "$am_cv_func_iconv" = yes; then
- AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
- fi
- if test "$am_cv_lib_iconv" = yes; then
- AC_MSG_CHECKING([how to link with libiconv])
- AC_MSG_RESULT([$LIBICONV])
- else
- dnl If $LIBICONV didn't lead to a usable library, we don't need $INCICONV
- dnl either.
- CPPFLAGS="$am_save_CPPFLAGS"
- LIBICONV=
- LTLIBICONV=
- fi
- AC_SUBST(LIBICONV)
- AC_SUBST(LTLIBICONV)
-])
-
-AC_DEFUN([AM_ICONV],
-[
- AM_ICONV_LINK
- if test "$am_cv_func_iconv" = yes; then
- AC_MSG_CHECKING([for iconv declaration])
- AC_CACHE_VAL(am_cv_proto_iconv, [
- AC_TRY_COMPILE([
-#include <stdlib.h>
-#include <iconv.h>
-extern
-#ifdef __cplusplus
-"C"
-#endif
-#if defined(__STDC__) || defined(__cplusplus)
-size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
-#else
-size_t iconv();
-#endif
-], [], am_cv_proto_iconv_arg1="", am_cv_proto_iconv_arg1="const")
- am_cv_proto_iconv="extern size_t iconv (iconv_t cd, $am_cv_proto_iconv_arg1 char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);"])
- am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
- AC_MSG_RESULT([$]{ac_t:-
- }[$]am_cv_proto_iconv)
- AC_DEFINE_UNQUOTED(ICONV_CONST, $am_cv_proto_iconv_arg1,
- [Define as const if the declaration of iconv() needs const.])
- fi
-])
diff --git a/m4/input.m4 b/m4/input.m4
new file mode 100644
index 000000000..76ad12ad9
--- /dev/null
+++ b/m4/input.m4
@@ -0,0 +1,280 @@
+dnl -------------
+dnl Input Plugins
+dnl -------------
+AC_DEFUN([XINE_INPUT_PLUGINS], [
+ dnl Setup defaults for the target operating system. For example, v4l is
+ dnl only ever available on Linux, so don't bother checking for it unless
+ dnl explicitly requested to do so on other operating systems.
+ dnl Notes:
+ dnl - dvb is Linux only
+ dnl - v4l is Linux only
+
+ default_enable_dvb=disable
+ default_enable_gnomevfs=enable
+ default_enable_samba=enable
+ default_enable_v4l=disable
+ default_enable_vcd=enable
+ default_enable_vcdo=disable
+
+ default_with_internal_vcdlibs=without
+
+ case "$host_os" in
+ cygwin* | mingw*)
+ default_enable_gnomevfs=disable
+ default_enable_samba=disable
+ ;;
+ darwin*)
+ default_enable_gnomevfs=disable
+ default_enable_samba=disable
+ ;;
+ freebsd*)
+ default_enable_vcdo=enable
+ ;;
+ linux*)
+ default_enable_dvb=enable
+ default_enable_v4l=enable
+ default_enable_vcdo=enable
+ ;;
+ solaris*)
+ default_enable_vcdo=enable
+ ;;
+ esac
+
+ dnl dvb
+ AC_ARG_ENABLE([dvb],
+ [AS_HELP_STRING([--enable-dvb], [Enable support for the DVB plugin (Linux only)])],
+ [test x"$enableval" != x"no" && enable_dvb="yes"],
+ [test $default_enable_dvb = disable && enable_dvb="no"])
+ if test x"$enable_dvb" != x"no"; then
+ case "$host_os" in
+ linux*) have_dvb=yes ;;
+ *) have_dvb=no ;;
+ esac
+ if test x"$enable_dvb" = x"yes" && test x"$have_dvb" != x"yes"; then
+ AC_MSG_ERROR([DVB support requested, but DVB not found])
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_DVB], [test x"$have_dvb" = x"yes"])
+
+
+ dnl gnome-vfs
+ AC_ARG_ENABLE([gnomevfs],
+ [AS_HELP_STRING([--enable-gnomevfs], [Enable support for the Gnome-VFS plugin])],
+ [test x"$enableval" != x"no" && enable_gnomevfs="yes"],
+ [test $default_enable_gnomevfs = disable && enable_gnomevfs="no"])
+ if test x"$enable_gnomevfs" != x"no"; then
+ PKG_CHECK_MODULES([GNOME_VFS], [gnome-vfs-2.0], [have_gnomevfs=yes], [have_gnome_vfs=no])
+ if test x"$enable_gnomevfs" = x"yes" && test x"$have_gnomevfs" != x"yes"; then
+ AC_MSG_ERROR([Gnome-VFS support requested, but Gnome-VFS not found])
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_GNOME_VFS], [test x"$have_gnomevfs" = x"yes"])
+
+
+ dnl libsmbclient
+ AC_ARG_ENABLE([samba],
+ [AS_HELP_STRING([--enable-samba], [Enable support for the Samba plugin])],
+ [test x"$enableval" != x"no" && enable_samba="yes"],
+ [test $default_enable_samba = disable && enable_samba="no"])
+ if test x"$enable_samba" != x"no"; then
+ AC_CHECK_LIB([smbclient], [smbc_init],
+ [AC_CHECK_HEADERS([libsmbclient.h], [have_samba=yes LIBSMBCLIENT_LIBS="-lsmbclient"])])
+ AC_SUBST(LIBSMBCLIENT_LIBS)
+ if test x"$enable_samba" = x"yes" && test x"$have_samba" != x"yes"; then
+ AC_MSG_ERROR([Samba support requested, but Samba not found])
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_LIBSMBCLIENT], [test x"$have_samba" = x"yes"])
+
+
+ dnl video-for-linux (v4l)
+ AC_ARG_ENABLE([v4l],
+ [AS_HELP_STRING([--enable-v4l], [Enable Video4Linux support])],
+ [test x"$enableval" != x"no" && enable_v4l="yes"],
+ [test $default_enable_v4l = disable && enable_v4l="no"])
+ if test x"$enable_v4l" != x"no"; then
+ AC_CHECK_HEADERS([linux/videodev.h], [have_v4l=yes], [have_v4l=no])
+ AC_CHECK_HEADERS([asm/types.h])
+ if test x"$enable_v4l" = x"yes" && test x"$have_v4l" != x"yes"; then
+ AC_MSG_ERROR([Video4Linux support requested, but prerequisite headers not found.])
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_V4L], [test x"$have_v4l" = x"yes"])
+
+
+ dnl dvdnav
+ dnl XXX: This could be cleaned up so that code does not have to ifdef so much
+ AC_ARG_WITH([external-dvdnav],
+ [AS_HELP_STRING([--with-external-dvdnav], [Use external dvdnav library (not recommended)])],
+ [test x"$withval" != x"no" && with_external_dvdnav="yes"], [with_external_dvdnav="no"])
+ if test x"$with_external_dvdnav" != x"no"; then
+ ACX_PACKAGE_CHECK([DVDNAV], [0.1.9], [dvdnav-config],
+ [AC_DEFINE([HAVE_DVDNAV], 1, [Define this if you have a suitable version of libdvdnav])],
+ [AC_MSG_RESULT([*** no usable version of libdvdnav found, using internal copy ***])])
+ else
+ AC_MSG_RESULT([Using included DVDNAV support])
+ fi
+ AM_CONDITIONAL([WITH_EXTERNAL_DVDNAV], [test x"$with_external_dvdnav" != x"no"])
+
+
+ dnl Video CD
+ dnl XXX: This could be cleaned up so that code does not have it ifdef so much
+ AC_ARG_ENABLE([vcd],
+ [AS_HELP_STRING([--enable-vcd], [Enable VCD (VideoCD) support])],
+ [test x"$enableval" != x"no" && enable_vcd="yes"],
+ [test $default_enable_vcd = disable && enable_vcd="no"])
+ AC_ARG_WITH([internal-vcdlibs],
+ [AS_HELP_STRING([--with-internal-vcdlibs], [force using internal libcdio/libvcd/libvcdinfo])],
+ [test x"$withval" != x"no" && with_internal_vcdlibs="yes"],
+ [test $default_with_internal_vcdlibs = without && with_internal_vcdlibs="no"])
+ if test x"$enable_vcd" != x"no"; then
+ dnl check twice - fallback is to use internal vcdlibs
+ if test x"$with_internal_vcdlibs" = x"no"; then
+ PKG_CHECK_MODULES([LIBCDIO], [libcdio >= 0.71], [], [with_internal_vcdlibs=yes])
+ PKG_CHECK_MODULES([LIBVCDINFO], [libvcdinfo >= 0.7.23], [], [with_internal_vcdlibs=yes])
+ if test x"$with_internal_vcdlibs" = x"yes"; then
+ AC_MSG_RESULT([Using included libcdio/libvcdinfo support])
+ fi
+ fi
+ if test x"$with_internal_vcdlibs" = x"no"; then
+ AC_DEFINE([HAVE_VCDNAV], 1, [Define this if you use external libcdio/libvcdinfo])
+ else
+ AC_DEFINE_UNQUOTED([HOST_ARCH], ["$host_os/$host_cpu"], [host os/cpu identifier])
+ AC_DEFINE([_DEVELOPMENT_], [], [enable warnings about being development release])
+
+ dnl
+ dnl bitfield order
+ dnl
+ AC_MSG_CHECKING([bitfield ordering in structs])
+
+ dnl basic compile test for all platforms
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
+ struct { char bit_0:1, bit_12:2, bit_345:3, bit_67:2; }
+ #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
+ __attribute__((packed))
+ #endif
+ bf = { 1,1,1,1 };
+ switch (0) case 0: case sizeof(bf) == 1:;]])],
+ [], [AC_MSG_ERROR([compiler doesn't support bitfield structs])])
+
+
+ dnl run test
+ AC_RUN_IFELSE([[
+ int main() {
+ struct { char bit_0:1, bit_12:2, bit_345:3, bit_67:2; }
+ #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
+ __attribute__((packed))
+ #endif
+ bf = { 1,1,1,1 };
+ if (sizeof (bf) != 1) return 1;
+ return *((unsigned char*) &bf) != 0x4b;
+ }]], [bf_lsbf=1], [
+ AC_RUN_IFELSE([[
+ int main() {
+ struct { char bit_0:1, bit_12:2, bit_345:3, bit_67:2; }
+ #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
+ __attribute__((packed))
+ #endif
+ bf = { 1,1,1,1 };
+ if (sizeof (bf) != 1) return 1;
+ return *((unsigned char*) &bf) != 0xa5;
+ }]], [bf_lsbf=0], [AC_MSG_ERROR([unsupported bitfield ordering])])],
+ [case "$host" in
+ *-*-mingw32* | *-*-cygwin* | i?86-* | k?-* | athlon-* | pentium*- | x86_64-*)
+ bf_lsbf=1
+ ;;
+ universal-*-darwin*)
+ bf_lsbf=2
+ ;;
+ powerpc-* | powerpc64-* | ppc-* | sparc*-* | mips-*)
+ bf_lsbf=0
+ ;;
+ *)
+ AC_MSG_RESULT([unknown])
+ AC_MSG_ERROR([value of bitfield test isn't known for $host
+ *********************************************************************
+ Value of bitfield test can't be found out for cross-compiling and we
+ don't know its value for host "$host".
+
+ Because it's needed for VCD plugin, disable VCD by configure option
+ --disable-vcd or use external VCD library.
+ *********************************************************************])
+ ;;
+ esac])
+
+ if test "x$cross_compiling" = "xyes"; then
+ TEXT=" (guessed)"
+ else
+ TEXT=""
+ fi
+ if test "x$bf_lsbf" = "x1"; then
+ AC_MSG_RESULT([LSBF${TEXT}])
+ AC_DEFINE([BITFIELD_LSBF], [], [compiler does lsbf in struct bitfields])
+ else
+ if test "x$bf_lsbf" = "x2"; then
+ AC_MSG_RESULT([indeterminate (universal build)])
+ else
+ AC_MSG_RESULT([MSBF${TEXT}])
+ fi
+ fi
+
+ LIBCDIO_CFLAGS='-I$(top_srcdir)/src/input/vcd/libcdio'
+ LIBCDIO_LIBS='$(top_builddir)/src/input/vcd/libcdio/libcdio.la'
+ LIBISO9660_LIBS='$(top_builddir)/src/input/vcd/libcdio/libiso9660.la'
+ LIBVCD_CFLAGS='-I$(top_srcdir)/src/input/vcd/libvcd'
+ LIBVCD_LIBS='$(top_builddir)/src/input/vcd/libvcd/libvcd.la'
+ LIBVCDINFO_LIBS='$(top_builddir)/src/input/vcd/libvcd/libvcdinfo.la'
+
+ case "$host_os" in
+ bsdi*)
+ AC_CHECK_HEADERS([dvd.h],
+ [AC_DEFINE([HAVE_BSDI_CDROM], 1, [Define 1 if you have BSDI-type CD-ROM support])])
+ ;;
+ cygwin*)
+ AC_DEFINE([CYGWIN], 1, [Define 1 if you are compiling using cygwin])
+ AC_DEFINE([HAVE_WIN32_CDROM], 1, [Define 1 if you have MinGW CD-ROM support])
+ LIBCDIO_LIBS="$LIBCDIO_LIBS -lwinmm"
+ LIBVCD_LIBS="$LIBVCD_LIBS -lwinmm"
+ ;;
+ darwin*)
+ AC_CHECK_HEADERS([IOKit/IOKitLib.h CoreFoundation/CFBase.h],
+ [AC_DEFINE([HAVE_DARWIN_CDROM], 1, [Define 1 if you have Darwin OS X-type CD-ROM support])])
+ LIBVCD_LIBS="$LIBVCD_LIBS -framework CoreFoundation -framework IOKit"
+ ;;
+ freebsd4.*)
+ AC_DEFINE([HAVE_FREEBSD_CDROM], 1, [Define 1 if you have FreeBSD CD-ROM support])
+ ;;
+ linux*)
+ AC_CHECK_HEADERS([linux/version.h])
+ ;;
+ mingw*)
+ AC_DEFINE([MINGW32], 1, [Define 1 if you are compiling using MinGW])
+ AC_DEFINE([HAVE_WIN32_CDROM], 1, [Define 1 if you have MinGW CD-ROM support])
+ ;;
+ sunos*|sun*|solaris*)
+ AC_CHECK_HEADERS([sys/cdio.h],
+ [AC_DEFINE([HAVE_SOLARIS_CDROM], 1, [Define 1 if you have Solaris CD-ROM support])])
+ ;;
+ *)
+ AC_MSG_WARN([Don't have OS CD-reading support for ${host_os} ... Will use generic support.])
+ ;;
+ esac
+
+ fi
+ fi
+
+ enable_vcdo=no
+ test $default_enable_vcdo = enable && test x"$enable_vcd" != x"no" && enable_vcdo=yes
+
+ AC_DEFINE([LIBCDIO_CONFIG_H], 1, [Get of rid system libcdio build configuration])
+ AC_DEFINE([EXTERNAL_LIBCDIO_CONFIG_H], 1, [Get of rid system libcdio build configuration])
+ AC_SUBST(LIBCDIO_CFLAGS)
+ AC_SUBST(LIBCDIO_LIBS)
+ AC_SUBST(LIBISO9660_LIBS)
+ AC_SUBST(LIBVCD_CFLAGS)
+ AC_SUBST(LIBVCD_LIBS)
+ AC_SUBST(LIBVCDINFO_LIBS)
+ AM_CONDITIONAL([WITH_EXTERNAL_VCDLIBS], [test x"$with_internal_vcdlibs" = x"no"])
+ AM_CONDITIONAL([ENABLE_VCD], [test x"$enable_vcd" != x"no"])
+ AM_CONDITIONAL([ENABLE_VCDO], [test x"$enable_vcdo" != x"no"])
+])
diff --git a/m4/ioctl_request.m4 b/m4/ioctl_request.m4
deleted file mode 100644
index c6d12258e..000000000
--- a/m4/ioctl_request.m4
+++ /dev/null
@@ -1,52 +0,0 @@
-dnl Simple macro to find the type of the ioctl request parameter
-dnl Copyright (c) 2007 xine project
-dnl
-dnl This program is free software; you can redistribute it and/or modify
-dnl it under the terms of the GNU General Public License as published by
-dnl the Free Software Foundation; either version 2, or (at your option)
-dnl any later version.
-dnl
-dnl This program is distributed in the hope that it will be useful,
-dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
-dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-dnl GNU General Public License for more details.
-dnl
-dnl You should have received a copy of the GNU General Public License
-dnl along with this program; if not, write to the Free Software
-dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-dnl 02110-1301, USA.
-dnl
-dnl As a special exception, the xine project, as copyright owner of the
-dnl macro gives unlimited permission to copy, distribute and modify the
-dnl configure scripts that are the output of Autoconf when processing the
-dnl Macro. You need not follow the terms of the GNU General Public
-dnl License when using or distributing such scripts, even though portions
-dnl of the text of the Macro appear in them. The GNU General Public
-dnl License (GPL) does govern all other use of the material that
-dnl constitutes the Autoconf Macro.
-dnl
-dnl This special exception to the GPL applies to versions of the
-dnl Autoconf Macro released by the xine project. When you make and
-dnl distribute a modified version of the Autoconf Macro, you may extend
-dnl this special exception to the GPL to apply to your modified version as
-dnl well.
-
-
-dnl Usage AC_IOCTL_REQUEST
-AC_DEFUN([AC_IOCTL_REQUEST], [
- AC_CACHE_CHECK([type of request parameter for ioctl()],
- ac_cv_ioctl_request,
- [for ac_ioctl_request_type in "unsigned long" "int"
- do
- AC_LINK_IFELSE([AC_LANG_PROGRAM([[
- #include <sys/ioctl.h>
- int ioctl(int fd, $ac_ioctl_request_type request, ...);
- ]], [[]])],[ac_cv_ioctl_request=$ac_ioctl_request_type],[])
- done])
-
- if test "x$ac_cv_ioctl_request" = "x"; then
- AC_MSG_ERROR([Unable to determine the type for ioctl() request parameter])
- fi
-
- AC_DEFINE_UNQUOTED([IOCTL_REQUEST_TYPE], $ac_cv_ioctl_request, [Type of the request parameter for ioctl()])
-])
diff --git a/m4/irixal.m4 b/m4/irixal.m4
deleted file mode 100644
index 3ff633cf8..000000000
--- a/m4/irixal.m4
+++ /dev/null
@@ -1,19 +0,0 @@
-dnl AM_CHECK_IRIXAL ([ACTION-IF-YES], [ACTION-IF-NO])
-dnl Configure paths/version for IRIX AL
-AC_DEFUN([AM_CHECK_IRIXAL],
- [AC_CACHE_CHECK([for IRIX libaudio support],
- [am_cv_have_irixal],
- [AC_CHECK_HEADER([dmedia/audio.h],
- am_cv_have_irixal=yes, am_cv_have_irixal=no)])
- if test "x$am_cv_have_irixal" = xyes ; then
- IRIXAL_LIBS="-laudio"
- IRIXAL_STATIC_LIB="/usr/lib/libaudio.a"
- ifelse([$1], , :, [$1])
- else
- ifelse([$2], , :, [$2])
- fi
- AC_SUBST(IRIXAL_CFLAGS)
- AC_SUBST(IRIXAL_STATIC_LIB)
- AC_SUBST(IRIXAL_LIBS)
-])
-
diff --git a/m4/lib-link.m4 b/m4/lib-link.m4
deleted file mode 100644
index ea0b0c4ea..000000000
--- a/m4/lib-link.m4
+++ /dev/null
@@ -1,553 +0,0 @@
-# lib-link.m4 serial 6 (gettext-0.14.3)
-dnl Copyright (C) 2001-2005 Free Software Foundation, Inc.
-dnl This file is free software; the Free Software Foundation
-dnl gives unlimited permission to copy and/or distribute it,
-dnl with or without modifications, as long as this notice is preserved.
-
-dnl From Bruno Haible.
-
-AC_PREREQ(2.50)
-
-dnl AC_LIB_LINKFLAGS(name [, dependencies]) searches for libname and
-dnl the libraries corresponding to explicit and implicit dependencies.
-dnl Sets and AC_SUBSTs the LIB${NAME} and LTLIB${NAME} variables and
-dnl augments the CPPFLAGS variable.
-AC_DEFUN([AC_LIB_LINKFLAGS],
-[
- AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
- AC_REQUIRE([AC_LIB_RPATH])
- define([Name],[translit([$1],[./-], [___])])
- define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
- [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
- AC_CACHE_CHECK([how to link with lib[]$1], [ac_cv_lib[]Name[]_libs], [
- AC_LIB_LINKFLAGS_BODY([$1], [$2])
- ac_cv_lib[]Name[]_libs="$LIB[]NAME"
- ac_cv_lib[]Name[]_ltlibs="$LTLIB[]NAME"
- ac_cv_lib[]Name[]_cppflags="$INC[]NAME"
- ])
- LIB[]NAME="$ac_cv_lib[]Name[]_libs"
- LTLIB[]NAME="$ac_cv_lib[]Name[]_ltlibs"
- INC[]NAME="$ac_cv_lib[]Name[]_cppflags"
- AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME)
- AC_SUBST([LIB]NAME)
- AC_SUBST([LTLIB]NAME)
- dnl Also set HAVE_LIB[]NAME so that AC_LIB_HAVE_LINKFLAGS can reuse the
- dnl results of this search when this library appears as a dependency.
- HAVE_LIB[]NAME=yes
- undefine([Name])
- undefine([NAME])
-])
-
-dnl AC_LIB_HAVE_LINKFLAGS(name, dependencies, includes, testcode)
-dnl searches for libname and the libraries corresponding to explicit and
-dnl implicit dependencies, together with the specified include files and
-dnl the ability to compile and link the specified testcode. If found, it
-dnl sets and AC_SUBSTs HAVE_LIB${NAME}=yes and the LIB${NAME} and
-dnl LTLIB${NAME} variables and augments the CPPFLAGS variable, and
-dnl #defines HAVE_LIB${NAME} to 1. Otherwise, it sets and AC_SUBSTs
-dnl HAVE_LIB${NAME}=no and LIB${NAME} and LTLIB${NAME} to empty.
-AC_DEFUN([AC_LIB_HAVE_LINKFLAGS],
-[
- AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
- AC_REQUIRE([AC_LIB_RPATH])
- define([Name],[translit([$1],[./-], [___])])
- define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
- [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
-
- dnl Search for lib[]Name and define LIB[]NAME, LTLIB[]NAME and INC[]NAME
- dnl accordingly.
- AC_LIB_LINKFLAGS_BODY([$1], [$2])
-
- dnl Add $INC[]NAME to CPPFLAGS before performing the following checks,
- dnl because if the user has installed lib[]Name and not disabled its use
- dnl via --without-lib[]Name-prefix, he wants to use it.
- ac_save_CPPFLAGS="$CPPFLAGS"
- AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME)
-
- AC_CACHE_CHECK([for lib[]$1], [ac_cv_lib[]Name], [
- ac_save_LIBS="$LIBS"
- LIBS="$LIBS $LIB[]NAME"
- AC_TRY_LINK([$3], [$4], [ac_cv_lib[]Name=yes], [ac_cv_lib[]Name=no])
- LIBS="$ac_save_LIBS"
- ])
- if test "$ac_cv_lib[]Name" = yes; then
- HAVE_LIB[]NAME=yes
- AC_DEFINE([HAVE_LIB]NAME, 1, [Define if you have the $1 library.])
- AC_MSG_CHECKING([how to link with lib[]$1])
- AC_MSG_RESULT([$LIB[]NAME])
- else
- HAVE_LIB[]NAME=no
- dnl If $LIB[]NAME didn't lead to a usable library, we don't need
- dnl $INC[]NAME either.
- CPPFLAGS="$ac_save_CPPFLAGS"
- LIB[]NAME=
- LTLIB[]NAME=
- fi
- AC_SUBST([HAVE_LIB]NAME)
- AC_SUBST([LIB]NAME)
- AC_SUBST([LTLIB]NAME)
- undefine([Name])
- undefine([NAME])
-])
-
-dnl Determine the platform dependent parameters needed to use rpath:
-dnl libext, shlibext, hardcode_libdir_flag_spec, hardcode_libdir_separator,
-dnl hardcode_direct, hardcode_minus_L.
-AC_DEFUN([AC_LIB_RPATH],
-[
- dnl Tell automake >= 1.10 to complain if config.rpath is missing.
- m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([config.rpath])])
- AC_REQUIRE([AC_PROG_CC]) dnl we use $CC, $GCC, $LDFLAGS
- AC_REQUIRE([AC_LIB_PROG_LD]) dnl we use $LD, $with_gnu_ld
- AC_REQUIRE([AC_CANONICAL_HOST]) dnl we use $host
- AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT]) dnl we use $ac_aux_dir
- AC_CACHE_CHECK([for shared library run path origin], acl_cv_rpath, [
- CC="$CC" GCC="$GCC" LDFLAGS="$LDFLAGS" LD="$LD" with_gnu_ld="$with_gnu_ld" \
- ${CONFIG_SHELL-/bin/sh} "$ac_aux_dir/config.rpath" "$host" > conftest.sh
- . ./conftest.sh
- rm -f ./conftest.sh
- acl_cv_rpath=done
- ])
- wl="$acl_cv_wl"
- libext="$acl_cv_libext"
- shlibext="$acl_cv_shlibext"
- hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec"
- hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator"
- hardcode_direct="$acl_cv_hardcode_direct"
- hardcode_minus_L="$acl_cv_hardcode_minus_L"
- dnl Determine whether the user wants rpath handling at all.
- AC_ARG_ENABLE(rpath,
- [ --disable-rpath do not hardcode runtime library paths],
- :, enable_rpath=yes)
-])
-
-dnl AC_LIB_LINKFLAGS_BODY(name [, dependencies]) searches for libname and
-dnl the libraries corresponding to explicit and implicit dependencies.
-dnl Sets the LIB${NAME}, LTLIB${NAME} and INC${NAME} variables.
-AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
-[
- define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
- [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
- dnl By default, look in $includedir and $libdir.
- use_additional=yes
- AC_LIB_WITH_FINAL_PREFIX([
- eval additional_includedir=\"$includedir\"
- eval additional_libdir=\"$libdir\"
- ])
- AC_LIB_ARG_WITH([lib$1-prefix],
-[ --with-lib$1-prefix[=DIR] search for lib$1 in DIR/include and DIR/lib
- --without-lib$1-prefix don't search for lib$1 in includedir and libdir],
-[
- if test "X$withval" = "Xno"; then
- use_additional=no
- else
- if test "X$withval" = "X"; then
- AC_LIB_WITH_FINAL_PREFIX([
- eval additional_includedir=\"$includedir\"
- eval additional_libdir=\"$libdir\"
- ])
- else
- additional_includedir="$withval/include"
- additional_libdir="$withval/lib"
- fi
- fi
-])
- dnl Search the library and its dependencies in $additional_libdir and
- dnl $LDFLAGS. Using breadth-first-seach.
- LIB[]NAME=
- LTLIB[]NAME=
- INC[]NAME=
- rpathdirs=
- ltrpathdirs=
- names_already_handled=
- names_next_round='$1 $2'
- while test -n "$names_next_round"; do
- names_this_round="$names_next_round"
- names_next_round=
- for name in $names_this_round; do
- already_handled=
- for n in $names_already_handled; do
- if test "$n" = "$name"; then
- already_handled=yes
- break
- fi
- done
- if test -z "$already_handled"; then
- names_already_handled="$names_already_handled $name"
- dnl See if it was already located by an earlier AC_LIB_LINKFLAGS
- dnl or AC_LIB_HAVE_LINKFLAGS call.
- uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./-|ABCDEFGHIJKLMNOPQRSTUVWXYZ___|'`
- eval value=\"\$HAVE_LIB$uppername\"
- if test -n "$value"; then
- if test "$value" = yes; then
- eval value=\"\$LIB$uppername\"
- test -z "$value" || LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$value"
- eval value=\"\$LTLIB$uppername\"
- test -z "$value" || LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$value"
- else
- dnl An earlier call to AC_LIB_HAVE_LINKFLAGS has determined
- dnl that this library doesn't exist. So just drop it.
- :
- fi
- else
- dnl Search the library lib$name in $additional_libdir and $LDFLAGS
- dnl and the already constructed $LIBNAME/$LTLIBNAME.
- found_dir=
- found_la=
- found_so=
- found_a=
- if test $use_additional = yes; then
- if test -n "$shlibext" && test -f "$additional_libdir/lib$name.$shlibext"; then
- found_dir="$additional_libdir"
- found_so="$additional_libdir/lib$name.$shlibext"
- if test -f "$additional_libdir/lib$name.la"; then
- found_la="$additional_libdir/lib$name.la"
- fi
- else
- if test -f "$additional_libdir/lib$name.$libext"; then
- found_dir="$additional_libdir"
- found_a="$additional_libdir/lib$name.$libext"
- if test -f "$additional_libdir/lib$name.la"; then
- found_la="$additional_libdir/lib$name.la"
- fi
- fi
- fi
- fi
- if test "X$found_dir" = "X"; then
- for x in $LDFLAGS $LTLIB[]NAME; do
- AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
- case "$x" in
- -L*)
- dir=`echo "X$x" | sed -e 's/^X-L//'`
- if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext"; then
- found_dir="$dir"
- found_so="$dir/lib$name.$shlibext"
- if test -f "$dir/lib$name.la"; then
- found_la="$dir/lib$name.la"
- fi
- else
- if test -f "$dir/lib$name.$libext"; then
- found_dir="$dir"
- found_a="$dir/lib$name.$libext"
- if test -f "$dir/lib$name.la"; then
- found_la="$dir/lib$name.la"
- fi
- fi
- fi
- ;;
- esac
- if test "X$found_dir" != "X"; then
- break
- fi
- done
- fi
- if test "X$found_dir" != "X"; then
- dnl Found the library.
- LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$found_dir -l$name"
- if test "X$found_so" != "X"; then
- dnl Linking with a shared library. We attempt to hardcode its
- dnl directory into the executable's runpath, unless it's the
- dnl standard /usr/lib.
- if test "$enable_rpath" = no || test "X$found_dir" = "X/usr/lib"; then
- dnl No hardcoding is needed.
- LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
- else
- dnl Use an explicit option to hardcode DIR into the resulting
- dnl binary.
- dnl Potentially add DIR to ltrpathdirs.
- dnl The ltrpathdirs will be appended to $LTLIBNAME at the end.
- haveit=
- for x in $ltrpathdirs; do
- if test "X$x" = "X$found_dir"; then
- haveit=yes
- break
- fi
- done
- if test -z "$haveit"; then
- ltrpathdirs="$ltrpathdirs $found_dir"
- fi
- dnl The hardcoding into $LIBNAME is system dependent.
- if test "$hardcode_direct" = yes; then
- dnl Using DIR/libNAME.so during linking hardcodes DIR into the
- dnl resulting binary.
- LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
- else
- if test -n "$hardcode_libdir_flag_spec" && test "$hardcode_minus_L" = no; then
- dnl Use an explicit option to hardcode DIR into the resulting
- dnl binary.
- LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
- dnl Potentially add DIR to rpathdirs.
- dnl The rpathdirs will be appended to $LIBNAME at the end.
- haveit=
- for x in $rpathdirs; do
- if test "X$x" = "X$found_dir"; then
- haveit=yes
- break
- fi
- done
- if test -z "$haveit"; then
- rpathdirs="$rpathdirs $found_dir"
- fi
- else
- dnl Rely on "-L$found_dir".
- dnl But don't add it if it's already contained in the LDFLAGS
- dnl or the already constructed $LIBNAME
- haveit=
- for x in $LDFLAGS $LIB[]NAME; do
- AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
- if test "X$x" = "X-L$found_dir"; then
- haveit=yes
- break
- fi
- done
- if test -z "$haveit"; then
- LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir"
- fi
- if test "$hardcode_minus_L" != no; then
- dnl FIXME: Not sure whether we should use
- dnl "-L$found_dir -l$name" or "-L$found_dir $found_so"
- dnl here.
- LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
- else
- dnl We cannot use $hardcode_runpath_var and LD_RUN_PATH
- dnl here, because this doesn't fit in flags passed to the
- dnl compiler. So give up. No hardcoding. This affects only
- dnl very old systems.
- dnl FIXME: Not sure whether we should use
- dnl "-L$found_dir -l$name" or "-L$found_dir $found_so"
- dnl here.
- LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"
- fi
- fi
- fi
- fi
- else
- if test "X$found_a" != "X"; then
- dnl Linking with a static library.
- LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_a"
- else
- dnl We shouldn't come here, but anyway it's good to have a
- dnl fallback.
- LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir -l$name"
- fi
- fi
- dnl Assume the include files are nearby.
- additional_includedir=
- case "$found_dir" in
- */lib | */lib/)
- basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e 's,/lib/*$,,'`
- additional_includedir="$basedir/include"
- ;;
- esac
- if test "X$additional_includedir" != "X"; then
- dnl Potentially add $additional_includedir to $INCNAME.
- dnl But don't add it
- dnl 1. if it's the standard /usr/include,
- dnl 2. if it's /usr/local/include and we are using GCC on Linux,
- dnl 3. if it's already present in $CPPFLAGS or the already
- dnl constructed $INCNAME,
- dnl 4. if it doesn't exist as a directory.
- if test "X$additional_includedir" != "X/usr/include"; then
- haveit=
- if test "X$additional_includedir" = "X/usr/local/include"; then
- if test -n "$GCC"; then
- case $host_os in
- linux* | gnu* | k*bsd*-gnu) haveit=yes;;
- esac
- fi
- fi
- if test -z "$haveit"; then
- for x in $CPPFLAGS $INC[]NAME; do
- AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
- if test "X$x" = "X-I$additional_includedir"; then
- haveit=yes
- break
- fi
- done
- if test -z "$haveit"; then
- if test -d "$additional_includedir"; then
- dnl Really add $additional_includedir to $INCNAME.
- INC[]NAME="${INC[]NAME}${INC[]NAME:+ }-I$additional_includedir"
- fi
- fi
- fi
- fi
- fi
- dnl Look for dependencies.
- if test -n "$found_la"; then
- dnl Read the .la file. It defines the variables
- dnl dlname, library_names, old_library, dependency_libs, current,
- dnl age, revision, installed, dlopen, dlpreopen, libdir.
- save_libdir="$libdir"
- case "$found_la" in
- */* | *\\*) . "$found_la" ;;
- *) . "./$found_la" ;;
- esac
- libdir="$save_libdir"
- dnl We use only dependency_libs.
- for dep in $dependency_libs; do
- case "$dep" in
- -L*)
- additional_libdir=`echo "X$dep" | sed -e 's/^X-L//'`
- dnl Potentially add $additional_libdir to $LIBNAME and $LTLIBNAME.
- dnl But don't add it
- dnl 1. if it's the standard /usr/lib,
- dnl 2. if it's /usr/local/lib and we are using GCC on Linux,
- dnl 3. if it's already present in $LDFLAGS or the already
- dnl constructed $LIBNAME,
- dnl 4. if it doesn't exist as a directory.
- if test "X$additional_libdir" != "X/usr/lib"; then
- haveit=
- if test "X$additional_libdir" = "X/usr/local/lib"; then
- if test -n "$GCC"; then
- case $host_os in
- linux* | gnu* | k*bsd*-gnu) haveit=yes;;
- esac
- fi
- fi
- if test -z "$haveit"; then
- haveit=
- for x in $LDFLAGS $LIB[]NAME; do
- AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
- if test "X$x" = "X-L$additional_libdir"; then
- haveit=yes
- break
- fi
- done
- if test -z "$haveit"; then
- if test -d "$additional_libdir"; then
- dnl Really add $additional_libdir to $LIBNAME.
- LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$additional_libdir"
- fi
- fi
- haveit=
- for x in $LDFLAGS $LTLIB[]NAME; do
- AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
- if test "X$x" = "X-L$additional_libdir"; then
- haveit=yes
- break
- fi
- done
- if test -z "$haveit"; then
- if test -d "$additional_libdir"; then
- dnl Really add $additional_libdir to $LTLIBNAME.
- LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$additional_libdir"
- fi
- fi
- fi
- fi
- ;;
- -R*)
- dir=`echo "X$dep" | sed -e 's/^X-R//'`
- if test "$enable_rpath" != no; then
- dnl Potentially add DIR to rpathdirs.
- dnl The rpathdirs will be appended to $LIBNAME at the end.
- haveit=
- for x in $rpathdirs; do
- if test "X$x" = "X$dir"; then
- haveit=yes
- break
- fi
- done
- if test -z "$haveit"; then
- rpathdirs="$rpathdirs $dir"
- fi
- dnl Potentially add DIR to ltrpathdirs.
- dnl The ltrpathdirs will be appended to $LTLIBNAME at the end.
- haveit=
- for x in $ltrpathdirs; do
- if test "X$x" = "X$dir"; then
- haveit=yes
- break
- fi
- done
- if test -z "$haveit"; then
- ltrpathdirs="$ltrpathdirs $dir"
- fi
- fi
- ;;
- -l*)
- dnl Handle this in the next round.
- names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'`
- ;;
- *.la)
- dnl Handle this in the next round. Throw away the .la's
- dnl directory; it is already contained in a preceding -L
- dnl option.
- names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'`
- ;;
- *)
- dnl Most likely an immediate library name.
- LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$dep"
- LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$dep"
- ;;
- esac
- done
- fi
- else
- dnl Didn't find the library; assume it is in the system directories
- dnl known to the linker and runtime loader. (All the system
- dnl directories known to the linker should also be known to the
- dnl runtime loader, otherwise the system is severely misconfigured.)
- LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"
- LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-l$name"
- fi
- fi
- fi
- done
- done
- if test "X$rpathdirs" != "X"; then
- if test -n "$hardcode_libdir_separator"; then
- dnl Weird platform: only the last -rpath option counts, the user must
- dnl pass all path elements in one option. We can arrange that for a
- dnl single library, but not when more than one $LIBNAMEs are used.
- alldirs=
- for found_dir in $rpathdirs; do
- alldirs="${alldirs}${alldirs:+$hardcode_libdir_separator}$found_dir"
- done
- dnl Note: hardcode_libdir_flag_spec uses $libdir and $wl.
- acl_save_libdir="$libdir"
- libdir="$alldirs"
- eval flag=\"$hardcode_libdir_flag_spec\"
- libdir="$acl_save_libdir"
- LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"
- else
- dnl The -rpath options are cumulative.
- for found_dir in $rpathdirs; do
- acl_save_libdir="$libdir"
- libdir="$found_dir"
- eval flag=\"$hardcode_libdir_flag_spec\"
- libdir="$acl_save_libdir"
- LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"
- done
- fi
- fi
- if test "X$ltrpathdirs" != "X"; then
- dnl When using libtool, the option that works for both libraries and
- dnl executables is -R. The -R options are cumulative.
- for found_dir in $ltrpathdirs; do
- LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-R$found_dir"
- done
- fi
-])
-
-dnl AC_LIB_APPENDTOVAR(VAR, CONTENTS) appends the elements of CONTENTS to VAR,
-dnl unless already present in VAR.
-dnl Works only for CPPFLAGS, not for LIB* variables because that sometimes
-dnl contains two or three consecutive elements that belong together.
-AC_DEFUN([AC_LIB_APPENDTOVAR],
-[
- for element in [$2]; do
- haveit=
- for x in $[$1]; do
- AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
- if test "X$x" = "X$element"; then
- haveit=yes
- break
- fi
- done
- if test -z "$haveit"; then
- [$1]="${[$1]}${[$1]:+ }$element"
- fi
- done
-])
diff --git a/m4/lib-prefix.m4 b/m4/lib-prefix.m4
deleted file mode 100644
index e0736ce1c..000000000
--- a/m4/lib-prefix.m4
+++ /dev/null
@@ -1,153 +0,0 @@
-# lib-prefix.m4 serial 4 (gettext-0.14.2)
-dnl Copyright (C) 2001-2005 Free Software Foundation, Inc.
-dnl This file is free software; the Free Software Foundation
-dnl gives unlimited permission to copy and/or distribute it,
-dnl with or without modifications, as long as this notice is preserved.
-
-dnl From Bruno Haible.
-
-dnl AC_LIB_ARG_WITH is synonymous to AC_ARG_WITH in autoconf-2.13, and
-dnl similar to AC_ARG_WITH in autoconf 2.52...2.57 except that is doesn't
-dnl require excessive bracketing.
-ifdef([AS_HELP_STRING],
-[AC_DEFUN([AC_LIB_ARG_WITH], [AC_ARG_WITH([$1],[[$2]],[$3],[$4])])],
-[AC_DEFUN([AC_][LIB_ARG_WITH], [AC_ARG_WITH([$1],[$2],[$3],[$4])])])
-
-dnl AC_LIB_PREFIX adds to the CPPFLAGS and LDFLAGS the flags that are needed
-dnl to access previously installed libraries. The basic assumption is that
-dnl a user will want packages to use other packages he previously installed
-dnl with the same --prefix option.
-dnl This macro is not needed if only AC_LIB_LINKFLAGS is used to locate
-dnl libraries, but is otherwise very convenient.
-AC_DEFUN([AC_LIB_PREFIX],
-[
- AC_BEFORE([$0], [AC_LIB_LINKFLAGS])
- AC_REQUIRE([AC_PROG_CC])
- AC_REQUIRE([AC_CANONICAL_HOST])
- AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
- dnl By default, look in $includedir and $libdir.
- use_additional=yes
- AC_LIB_WITH_FINAL_PREFIX([
- eval additional_includedir=\"$includedir\"
- eval additional_libdir=\"$libdir\"
- ])
- AC_LIB_ARG_WITH([lib-prefix],
-[ --with-lib-prefix[=DIR] search for libraries in DIR/include and DIR/lib
- --without-lib-prefix don't search for libraries in includedir and libdir],
-[
- if test "X$withval" = "Xno"; then
- use_additional=no
- else
- if test "X$withval" = "X"; then
- AC_LIB_WITH_FINAL_PREFIX([
- eval additional_includedir=\"$includedir\"
- eval additional_libdir=\"$libdir\"
- ])
- else
- additional_includedir="$withval/include"
- additional_libdir="$withval/lib"
- fi
- fi
-])
- if test $use_additional = yes; then
- dnl Potentially add $additional_includedir to $CPPFLAGS.
- dnl But don't add it
- dnl 1. if it's the standard /usr/include,
- dnl 2. if it's already present in $CPPFLAGS,
- dnl 3. if it's /usr/local/include and we are using GCC on Linux,
- dnl 4. if it doesn't exist as a directory.
- if test "X$additional_includedir" != "X/usr/include"; then
- haveit=
- for x in $CPPFLAGS; do
- AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
- if test "X$x" = "X-I$additional_includedir"; then
- haveit=yes
- break
- fi
- done
- if test -z "$haveit"; then
- if test "X$additional_includedir" = "X/usr/local/include"; then
- if test -n "$GCC"; then
- case $host_os in
- linux* | gnu* | k*bsd*-gnu) haveit=yes;;
- esac
- fi
- fi
- if test -z "$haveit"; then
- if test -d "$additional_includedir"; then
- dnl Really add $additional_includedir to $CPPFLAGS.
- CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }-I$additional_includedir"
- fi
- fi
- fi
- fi
- dnl Potentially add $additional_libdir to $LDFLAGS.
- dnl But don't add it
- dnl 1. if it's the standard /usr/lib,
- dnl 2. if it's already present in $LDFLAGS,
- dnl 3. if it's /usr/local/lib and we are using GCC on Linux,
- dnl 4. if it doesn't exist as a directory.
- if test "X$additional_libdir" != "X/usr/lib"; then
- haveit=
- for x in $LDFLAGS; do
- AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
- if test "X$x" = "X-L$additional_libdir"; then
- haveit=yes
- break
- fi
- done
- if test -z "$haveit"; then
- if test "X$additional_libdir" = "X/usr/local/lib"; then
- if test -n "$GCC"; then
- case $host_os in
- linux*) haveit=yes;;
- esac
- fi
- fi
- if test -z "$haveit"; then
- if test -d "$additional_libdir"; then
- dnl Really add $additional_libdir to $LDFLAGS.
- LDFLAGS="${LDFLAGS}${LDFLAGS:+ }-L$additional_libdir"
- fi
- fi
- fi
- fi
- fi
-])
-
-dnl AC_LIB_PREPARE_PREFIX creates variables acl_final_prefix,
-dnl acl_final_exec_prefix, containing the values to which $prefix and
-dnl $exec_prefix will expand at the end of the configure script.
-AC_DEFUN([AC_LIB_PREPARE_PREFIX],
-[
- dnl Unfortunately, prefix and exec_prefix get only finally determined
- dnl at the end of configure.
- if test "X$prefix" = "XNONE"; then
- acl_final_prefix="$ac_default_prefix"
- else
- acl_final_prefix="$prefix"
- fi
- if test "X$exec_prefix" = "XNONE"; then
- acl_final_exec_prefix='${prefix}'
- else
- acl_final_exec_prefix="$exec_prefix"
- fi
- acl_save_prefix="$prefix"
- prefix="$acl_final_prefix"
- eval acl_final_exec_prefix=\"$acl_final_exec_prefix\"
- prefix="$acl_save_prefix"
-])
-
-dnl AC_LIB_WITH_FINAL_PREFIX([statement]) evaluates statement, with the
-dnl variables prefix and exec_prefix bound to the values they will have
-dnl at the end of the configure script.
-AC_DEFUN([AC_LIB_WITH_FINAL_PREFIX],
-[
- acl_save_prefix="$prefix"
- prefix="$acl_final_prefix"
- acl_save_exec_prefix="$exec_prefix"
- exec_prefix="$acl_final_exec_prefix"
- $1
- exec_prefix="$acl_save_exec_prefix"
- prefix="$acl_save_prefix"
-])
diff --git a/m4/libFLAC.m4 b/m4/libFLAC.m4
index 9ecf8dd51..9778d25d6 100644
--- a/m4/libFLAC.m4
+++ b/m4/libFLAC.m4
@@ -13,6 +13,33 @@ AC_ARG_WITH(libFLAC-libraries, AS_HELP_STRING([--with-libFLAC-libraries=DIR], [d
AC_ARG_WITH(libFLAC-includes, AS_HELP_STRING([--with-libFLAC-includes=DIR], [directory where libFLAC header files are installed (optional)]), libFLAC_includes="$withval", libFLAC_includes="")
AC_ARG_ENABLE(libFLACtest, AS_HELP_STRING([--disable-libFLACtest], [do not try to compile and run a test libFLAC program]), enable_libFLACtest=$enableval, enable_libFLACtest=yes)
+ AC_MSG_CHECKING([libdir name])
+ case $host_or_hostalias in
+ *-*-linux*)
+ # Test if the compiler is 64bit
+ echo 'int i;' > conftest.$ac_ext
+ xine_cv_cc_64bit_output=no
+ if AC_TRY_EVAL(ac_compile); then
+ case `"$MAGIC_CMD" conftest.$ac_objext` in
+ *"ELF 64"*)
+ xine_cv_cc_64bit_output=yes
+ ;;
+ esac
+ fi
+ rm -rf conftest*
+ ;;
+ esac
+
+ case $host_cpu:$xine_cv_cc_64bit_output in
+ powerpc64:yes | s390x:yes | sparc64:yes | x86_64:yes)
+ XINE_LIBNAME="lib64"
+ ;;
+ *:*)
+ XINE_LIBNAME="lib"
+ ;;
+ esac
+ AC_MSG_RESULT([$XINE_LIBNAME])
+
if test "x$libFLAC_libraries" != "x" ; then
LIBFLAC_LIBS="-L$libFLAC_libraries"
elif test "x$libFLAC_prefix" != "x" ; then
diff --git a/m4/libfame.m4 b/m4/libfame.m4
deleted file mode 100644
index 5fc34cc56..000000000
--- a/m4/libfame.m4
+++ /dev/null
@@ -1,183 +0,0 @@
-dnl AM_PATH_LIBFAME([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND [, MODULES]]]])
-dnl Test for libfame, and define LIBFAME_CFLAGS and LIBFAME_LIBS
-dnl Vivien Chappelier 12/11/00
-dnl stolen from ORBit autoconf
-dnl
-AC_DEFUN([AM_PATH_LIBFAME],
-[dnl
-dnl Get the cflags and libraries from the libfame-config script
-dnl
-AC_ARG_WITH(libfame-prefix, AS_HELP_STRING([--with-libfame-prefix=DIR], [prefix where libfame is installed (optional)]),
- libfame_config_prefix="$withval", libfame_config_prefix="")
-AC_ARG_WITH(libfame-exec-prefix, AS_HELP_STRING([--with-libfame-exec-prefix=DIR], [exec prefix where libfame is installed (optional)]),
- libfame_config_exec_prefix="$withval", libfame_config_exec_prefix="")
-AC_ARG_ENABLE(libfametest, AS_HELP_STRING([--disable-libfametest], [do not try to compile and run a test libfame program]),
- enable_libfametest=$enableval, enable_libfametest=yes)
-
- if test x$libfame_config_exec_prefix != x ; then
- libfame_config_args="$libfame_config_args --exec-prefix=$libfame_config_exec_prefix"
- if test x${LIBFAME_CONFIG+set} != xset ; then
- LIBFAME_CONFIG=$libfame_config_exec_prefix/bin/libfame-config
- fi
- fi
- if test x$libfame_config_prefix != x ; then
- libfame_config_args="$libfame_config_args --prefix=$libfame_config_prefix"
- if test x${LIBFAME_CONFIG+set} != xset ; then
- LIBFAME_CONFIG=$libfame_config_prefix/bin/libfame-config
- fi
- fi
-
- AC_PATH_TOOL(LIBFAME_CONFIG, libfame-config, no)
- min_libfame_version=ifelse([$1], , 0.9.0, $1)
- AC_MSG_CHECKING(for libfame - version >= $min_libfame_version)
- no_libfame=""
- if test "$LIBFAME_CONFIG" = "no" ; then
- no_libfame=yes
- else
- LIBFAME_CFLAGS=`$LIBFAME_CONFIG $libfame_config_args --cflags`
- LIBFAME_LIBS=`$LIBFAME_CONFIG $libfame_config_args --libs`
- libfame_config_major_version=`$LIBFAME_CONFIG $libfame_config_args --version | \
- sed -e 's,[[^0-9.]],,g' -e 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
- libfame_config_minor_version=`$LIBFAME_CONFIG $libfame_config_args --version | \
- sed -e 's,[[^0-9.]],,g' -e 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
- libfame_config_micro_version=`$LIBFAME_CONFIG $libfame_config_args --version | \
- sed -e 's,[[^0-9.]],,g' -e 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
- if test "x$enable_libfametest" = "xyes" ; then
- ac_save_CFLAGS="$CFLAGS"
- ac_save_LIBS="$LIBS"
- CFLAGS="$CFLAGS $LIBFAME_CFLAGS"
- LIBS="$LIBFAME_LIBS $LIBS"
-dnl
-dnl Now check if the installed LIBFAME is sufficiently new. (Also sanity
-dnl checks the results of libfame-config to some extent
-dnl
- rm -f conf.libfametest
- AC_TRY_RUN([
-#include <fame.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-int
-main ()
-{
- int major, minor, micro;
- char *tmp_version;
-
- system ("touch conf.libfametest");
-
- /* HP/UX 9 (%@#!) writes to sscanf strings */
- tmp_version = strdup("$min_libfame_version");
- if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
- printf("%s, bad version string\n", "$min_libfame_version");
- exit(1);
- }
-
- if ((libfame_major_version != $libfame_config_major_version) ||
- (libfame_minor_version != $libfame_config_minor_version) ||
- (libfame_micro_version != $libfame_config_micro_version))
- {
- printf("\n*** 'libfame-config --version' returned %d.%d.%d, but Libfame (%d.%d.%d)\n",
- $libfame_config_major_version, $libfame_config_minor_version, $libfame_config_micro_version,
- libfame_major_version, libfame_minor_version, libfame_micro_version);
- printf ("*** was found! If libfame-config was correct, then it is best\n");
- printf ("*** to remove the old version of libfame. You may also be able to fix the error\n");
- printf("*** by modifying your LD_LIBRARY_PATH enviroment variable, or by editing\n");
- printf("*** /etc/ld.so.conf. Make sure you have run ldconfig if that is\n");
- printf("*** required on your system.\n");
- printf("*** If libfame-config was wrong, set the environment variable LIBFAME_CONFIG\n");
- printf("*** to point to the correct copy of libfame-config, and remove the file config.cache\n");
- printf("*** before re-running configure\n");
- }
-#if defined (LIBFAME_MAJOR_VERSION) && defined (LIBFAME_MINOR_VERSION) && defined (LIBFAME_MICRO_VERSION)
- else if ((libfame_major_version != LIBFAME_MAJOR_VERSION) ||
- (libfame_minor_version != LIBFAME_MINOR_VERSION) ||
- (libfame_micro_version != LIBFAME_MICRO_VERSION))
- {
- printf("*** libfame header files (version %d.%d.%d) do not match\n",
- LIBFAME_MAJOR_VERSION, LIBFAME_MINOR_VERSION, LIBFAME_MICRO_VERSION);
- printf("*** library (version %d.%d.%d)\n",
- libfame_major_version, libfame_minor_version, libfame_micro_version);
- }
-#endif /* defined (LIBFAME_MAJOR_VERSION) ... */
- else
- {
- if ((libfame_major_version > major) ||
- ((libfame_major_version == major) && (libfame_minor_version > minor)) ||
- ((libfame_major_version == major) && (libfame_minor_version == minor) && (libfame_micro_version >= micro)))
- {
- return 0;
- }
- else
- {
- printf("\n*** An old version of libfame (%d.%d.%d) was found.\n",
- libfame_major_version, libfame_minor_version, libfame_micro_version);
- printf("*** You need a version of libfame newer than %d.%d.%d. The latest version of\n",
- major, minor, micro);
- printf("*** libfame is always available from http://www-eleves.enst-bretagne.fr/~chappeli/fame\n");
- printf("***\n");
- printf("*** If you have already installed a sufficiently new version, this error\n");
- printf("*** probably means that the wrong copy of the libfame-config shell script is\n");
- printf("*** being found. The easiest way to fix this is to remove the old version\n");
- printf("*** of libfame, but you can also set the LIBFAME_CONFIG environment to point to the\n");
- printf("*** correct copy of libfame-config. (In this case, you will have to\n");
- printf("*** modify your LD_LIBRARY_PATH enviroment variable, or edit /etc/ld.so.conf\n");
- printf("*** so that the correct libraries are found at run-time))\n");
- }
- }
- return 1;
-}
-],, no_libfame=yes,
- AC_TRY_LINK([
-#include <fame.h>
-#include <stdio.h>
-], [ return 0; ],, no_libfame=yes))
- CFLAGS="$ac_save_CFLAGS"
- LIBS="$ac_save_LIBS"
- fi
- fi
- if test "x$no_libfame" = x ; then
- AC_MSG_RESULT(yes)
- ifelse([$2], , :, [$2])
- else
- AC_MSG_RESULT(no)
- if test "$LIBFAME_CONFIG" = "no" ; then
- echo "*** The libfame-config script installed by libfame could not be found"
- echo "*** If libfame was installed in PREFIX, make sure PREFIX/bin is in"
- echo "*** your path, or set the LIBFAME_CONFIG environment variable to the"
- echo "*** full path to libfame-config."
- else
- if test -f conf.libfametest ; then
- :
- else
- echo "*** Could not run libfame test program, checking why..."
- CFLAGS="$CFLAGS $LIBFAME_CFLAGS"
- LIBS="$LIBS $LIBFAME_LIBS"
- AC_TRY_LINK([
-#include <fame.h>
-#include <stdio.h>
-], [ return ((libfame_major_version) || (libfame_minor_version) || (libfame_micro_version)); ],
- [ echo "*** The test program compiled, but did not run. This usually means"
- echo "*** that the run-time linker is not finding libfame or finding the wrong"
- echo "*** version of LIBFAME. If it is not finding libfame, you'll need to set your"
- echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
- echo "*** to the installed location Also, make sure you have run ldconfig if that"
- echo "*** is required on your system"
- echo "***"
- echo "*** If you have an old version installed, it is best to remove it, although"
- echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"
- echo "***" ],
- [ echo "*** The test program failed to compile or link. See the file config.log for the"
- echo "*** exact error that occured. This usually means libfame was incorrectly installed"
- echo "*** or that you have moved libfame since it was installed. In the latter case, you"
- echo "*** may want to edit the libfame-config script: $LIBFAME_CONFIG" ])
- CFLAGS="$ac_save_CFLAGS"
- LIBS="$ac_save_LIBS"
- fi
- fi
- ifelse([$3], , :, [$3])
- fi
-
- AC_SUBST(LIBFAME_CFLAGS)
- AC_SUBST(LIBFAME_LIBS)
- rm -f conf.libfametest
-])
diff --git a/m4/libtool15.m4 b/m4/libtool15.m4
deleted file mode 100644
index 1f0567787..000000000
--- a/m4/libtool15.m4
+++ /dev/null
@@ -1,6168 +0,0 @@
-# libtool.m4 - Configure libtool for the host system. -*-Autoconf-*-
-## Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005
-## Free Software Foundation, Inc.
-## Originally by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
-##
-## This file is free software; the Free Software Foundation gives
-## unlimited permission to copy and/or distribute it, with or without
-## modifications, as long as this notice is preserved.
-
-# serial 47 AC_PROG_LIBTOOL
-
-
-# AC_PROVIDE_IFELSE(MACRO-NAME, IF-PROVIDED, IF-NOT-PROVIDED)
-# -----------------------------------------------------------
-# If this macro is not defined by Autoconf, define it here.
-m4_ifdef([AC_PROVIDE_IFELSE],
- [],
- [m4_define([AC_PROVIDE_IFELSE],
- [m4_ifdef([AC_PROVIDE_$1],
- [$2], [$3])])])
-
-
-# AC_PROG_LIBTOOL
-# ---------------
-AC_DEFUN([AC_PROG_LIBTOOL],
-[AC_REQUIRE([_AC_PROG_LIBTOOL])dnl
-dnl If AC_PROG_CXX has already been expanded, run AC_LIBTOOL_CXX
-dnl immediately, otherwise, hook it in at the end of AC_PROG_CXX.
- AC_PROVIDE_IFELSE([AC_PROG_CXX],
- [AC_LIBTOOL_CXX],
- [define([AC_PROG_CXX], defn([AC_PROG_CXX])[AC_LIBTOOL_CXX
- ])])
-dnl And a similar setup for Fortran 77 support
- AC_PROVIDE_IFELSE([AC_PROG_F77],
- [AC_LIBTOOL_F77],
- [define([AC_PROG_F77], defn([AC_PROG_F77])[AC_LIBTOOL_F77
-])])
-
-dnl Quote A][M_PROG_GCJ so that aclocal doesn't bring it in needlessly.
-dnl If either AC_PROG_GCJ or A][M_PROG_GCJ have already been expanded, run
-dnl AC_LIBTOOL_GCJ immediately, otherwise, hook it in at the end of both.
- AC_PROVIDE_IFELSE([AC_PROG_GCJ],
- [AC_LIBTOOL_GCJ],
- [AC_PROVIDE_IFELSE([A][M_PROG_GCJ],
- [AC_LIBTOOL_GCJ],
- [AC_PROVIDE_IFELSE([LT_AC_PROG_GCJ],
- [AC_LIBTOOL_GCJ],
- [ifdef([AC_PROG_GCJ],
- [define([AC_PROG_GCJ], defn([AC_PROG_GCJ])[AC_LIBTOOL_GCJ])])
- ifdef([A][M_PROG_GCJ],
- [define([A][M_PROG_GCJ], defn([A][M_PROG_GCJ])[AC_LIBTOOL_GCJ])])
- ifdef([LT_AC_PROG_GCJ],
- [define([LT_AC_PROG_GCJ],
- defn([LT_AC_PROG_GCJ])[AC_LIBTOOL_GCJ])])])])
-])])# AC_PROG_LIBTOOL
-
-
-# _AC_PROG_LIBTOOL
-# ----------------
-AC_DEFUN([_AC_PROG_LIBTOOL],
-[AC_REQUIRE([AC_LIBTOOL_SETUP])dnl
-AC_BEFORE([$0],[AC_LIBTOOL_CXX])dnl
-AC_BEFORE([$0],[AC_LIBTOOL_F77])dnl
-AC_BEFORE([$0],[AC_LIBTOOL_GCJ])dnl
-
-# This can be used to rebuild libtool when needed
-LIBTOOL_DEPS="$ac_aux_dir/ltmain.sh"
-
-# Always use our own libtool.
-LIBTOOL='$(SHELL) $(top_builddir)/libtool'
-AC_SUBST(LIBTOOL)dnl
-
-# Prevent multiple expansion
-define([AC_PROG_LIBTOOL], [])
-])# _AC_PROG_LIBTOOL
-
-
-# AC_LIBTOOL_SETUP
-# ----------------
-AC_DEFUN([AC_LIBTOOL_SETUP],
-[AC_PREREQ(2.50)dnl
-AC_REQUIRE([AC_ENABLE_SHARED])dnl
-AC_REQUIRE([AC_ENABLE_STATIC])dnl
-AC_REQUIRE([AC_ENABLE_FAST_INSTALL])dnl
-AC_REQUIRE([AC_CANONICAL_HOST])dnl
-AC_REQUIRE([AC_CANONICAL_BUILD])dnl
-AC_REQUIRE([AC_PROG_CC])dnl
-AC_REQUIRE([AC_PROG_LD])dnl
-AC_REQUIRE([AC_PROG_LD_RELOAD_FLAG])dnl
-AC_REQUIRE([AC_PROG_NM])dnl
-
-AC_REQUIRE([AC_PROG_LN_S])dnl
-AC_REQUIRE([AC_DEPLIBS_CHECK_METHOD])dnl
-# Autoconf 2.13's AC_OBJEXT and AC_EXEEXT macros only works for C compilers!
-AC_REQUIRE([AC_OBJEXT])dnl
-AC_REQUIRE([AC_EXEEXT])dnl
-dnl
-
-AC_LIBTOOL_SYS_MAX_CMD_LEN
-AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE
-AC_LIBTOOL_OBJDIR
-
-AC_REQUIRE([_LT_AC_SYS_COMPILER])dnl
-_LT_AC_PROG_ECHO_BACKSLASH
-
-case $host_os in
-aix3*)
- # AIX sometimes has problems with the GCC collect2 program. For some
- # reason, if we set the COLLECT_NAMES environment variable, the problems
- # vanish in a puff of smoke.
- if test "X${COLLECT_NAMES+set}" != Xset; then
- COLLECT_NAMES=
- export COLLECT_NAMES
- fi
- ;;
-esac
-
-# Sed substitution that helps us do robust quoting. It backslashifies
-# metacharacters that are still active within double-quoted strings.
-Xsed='sed -e 1s/^X//'
-[sed_quote_subst='s/\([\\"\\`$\\\\]\)/\\\1/g']
-
-# Same as above, but do not quote variable references.
-[double_quote_subst='s/\([\\"\\`\\\\]\)/\\\1/g']
-
-# Sed substitution to delay expansion of an escaped shell variable in a
-# double_quote_subst'ed string.
-delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g'
-
-# Sed substitution to avoid accidental globbing in evaled expressions
-no_glob_subst='s/\*/\\\*/g'
-
-# Constants:
-rm="rm -f"
-
-# Global variables:
-default_ofile=libtool
-can_build_shared=yes
-
-# All known linkers require a `.a' archive for static linking (except M$VC,
-# which needs '.lib').
-libext=a
-ltmain="$ac_aux_dir/ltmain.sh"
-ofile="$default_ofile"
-with_gnu_ld="$lt_cv_prog_gnu_ld"
-
-AC_CHECK_TOOL(AR, ar, false)
-AC_CHECK_TOOL(RANLIB, ranlib, :)
-AC_CHECK_TOOL(STRIP, strip, :)
-
-old_CC="$CC"
-old_CFLAGS="$CFLAGS"
-
-# Set sane defaults for various variables
-test -z "$AR" && AR=ar
-test -z "$AR_FLAGS" && AR_FLAGS=cru
-test -z "$AS" && AS=as
-test -z "$CC" && CC=cc
-test -z "$LTCC" && LTCC=$CC
-test -z "$DLLTOOL" && DLLTOOL=dlltool
-test -z "$LD" && LD=ld
-test -z "$LN_S" && LN_S="ln -s"
-test -z "$MAGIC_CMD" && MAGIC_CMD=file
-test -z "$NM" && NM=nm
-test -z "$SED" && SED=sed
-test -z "$OBJDUMP" && OBJDUMP=objdump
-test -z "$RANLIB" && RANLIB=:
-test -z "$STRIP" && STRIP=:
-test -z "$ac_objext" && ac_objext=o
-
-# Determine commands to create old-style static archives.
-old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs$old_deplibs'
-old_postinstall_cmds='chmod 644 $oldlib'
-old_postuninstall_cmds=
-
-if test -n "$RANLIB"; then
- case $host_os in
- openbsd*)
- old_postinstall_cmds="\$RANLIB -t \$oldlib~$old_postinstall_cmds"
- ;;
- *)
- old_postinstall_cmds="\$RANLIB \$oldlib~$old_postinstall_cmds"
- ;;
- esac
- old_archive_cmds="$old_archive_cmds~\$RANLIB \$oldlib"
-fi
-
-_LT_CC_BASENAME([$compiler])
-
-# Only perform the check for file, if the check method requires it
-case $deplibs_check_method in
-file_magic*)
- if test "$file_magic_cmd" = '$MAGIC_CMD'; then
- AC_PATH_MAGIC
- fi
- ;;
-esac
-
-AC_PROVIDE_IFELSE([AC_LIBTOOL_DLOPEN], enable_dlopen=yes, enable_dlopen=no)
-AC_PROVIDE_IFELSE([AC_LIBTOOL_WIN32_DLL],
-enable_win32_dll=yes, enable_win32_dll=no)
-
-AC_ARG_ENABLE([libtool-lock],
- [AS_HELP_STRING([--disable-libtool-lock],
- [avoid locking (might break parallel builds)])])
-test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes
-
-AC_ARG_WITH([pic],
- [AS_HELP_STRING([--with-pic],
- [try to use only PIC/non-PIC objects @<:@default=use both@:>@])],
- [pic_mode="$withval"],
- [pic_mode=default])
-test -z "$pic_mode" && pic_mode=default
-
-# Use C for the default configuration in the libtool script
-tagname=
-AC_LIBTOOL_LANG_C_CONFIG
-_LT_AC_TAGCONFIG
-])# AC_LIBTOOL_SETUP
-
-
-# _LT_AC_SYS_COMPILER
-# -------------------
-AC_DEFUN([_LT_AC_SYS_COMPILER],
-[AC_REQUIRE([AC_PROG_CC])dnl
-
-# If no C compiler was specified, use CC.
-LTCC=${LTCC-"$CC"}
-
-# Allow CC to be a program name with arguments.
-compiler=$CC
-])# _LT_AC_SYS_COMPILER
-
-
-# _LT_CC_BASENAME(CC)
-# -------------------
-# Calculate cc_basename. Skip known compiler wrappers and cross-prefix.
-AC_DEFUN([_LT_CC_BASENAME],
-[for cc_temp in $1""; do
- case $cc_temp in
- compile | *[[\\/]]compile | ccache | *[[\\/]]ccache ) ;;
- distcc | *[[\\/]]distcc | purify | *[[\\/]]purify ) ;;
- \-*) ;;
- *) break;;
- esac
-done
-cc_basename=`$echo "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"`
-])
-
-
-# _LT_COMPILER_BOILERPLATE
-# ------------------------
-# Check for compiler boilerplate output or warnings with
-# the simple compiler test code.
-AC_DEFUN([_LT_COMPILER_BOILERPLATE],
-[ac_outfile=conftest.$ac_objext
-printf "$lt_simple_compile_test_code" >conftest.$ac_ext
-eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d' >conftest.err
-_lt_compiler_boilerplate=`cat conftest.err`
-$rm conftest*
-])# _LT_COMPILER_BOILERPLATE
-
-
-# _LT_LINKER_BOILERPLATE
-# ----------------------
-# Check for linker boilerplate output or warnings with
-# the simple link test code.
-AC_DEFUN([_LT_LINKER_BOILERPLATE],
-[ac_outfile=conftest.$ac_objext
-printf "$lt_simple_link_test_code" >conftest.$ac_ext
-eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d' >conftest.err
-_lt_linker_boilerplate=`cat conftest.err`
-$rm conftest*
-])# _LT_LINKER_BOILERPLATE
-
-
-# _LT_AC_SYS_LIBPATH_AIX
-# ----------------------
-# Links a minimal program and checks the executable
-# for the system default hardcoded library path. In most cases,
-# this is /usr/lib:/lib, but when the MPI compilers are used
-# the location of the communication and MPI libs are included too.
-# If we don't find anything, use the default library path according
-# to the aix ld manual.
-AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX],
-[AC_LINK_IFELSE(AC_LANG_PROGRAM,[
-aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/; p; }
-}'`
-# Check for a 64-bit object if we didn't find anything.
-if test -z "$aix_libpath"; then aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/; p; }
-}'`; fi],[])
-if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
-])# _LT_AC_SYS_LIBPATH_AIX
-
-
-# _LT_AC_SHELL_INIT(ARG)
-# ----------------------
-AC_DEFUN([_LT_AC_SHELL_INIT],
-[ifdef([AC_DIVERSION_NOTICE],
- [AC_DIVERT_PUSH(AC_DIVERSION_NOTICE)],
- [AC_DIVERT_PUSH(NOTICE)])
-$1
-AC_DIVERT_POP
-])# _LT_AC_SHELL_INIT
-
-
-# _LT_AC_PROG_ECHO_BACKSLASH
-# --------------------------
-# Add some code to the start of the generated configure script which
-# will find an echo command which doesn't interpret backslashes.
-AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH],
-[_LT_AC_SHELL_INIT([
-# Check that we are running under the correct shell.
-SHELL=${CONFIG_SHELL-/bin/sh}
-
-case X$ECHO in
-X*--fallback-echo)
- # Remove one level of quotation (which was required for Make).
- ECHO=`echo "$ECHO" | sed 's,\\\\\[$]\\[$]0,'[$]0','`
- ;;
-esac
-
-echo=${ECHO-echo}
-if test "X[$]1" = X--no-reexec; then
- # Discard the --no-reexec flag, and continue.
- shift
-elif test "X[$]1" = X--fallback-echo; then
- # Avoid inline document here, it may be left over
- :
-elif test "X`($echo '\t') 2>/dev/null`" = 'X\t' ; then
- # Yippee, $echo works!
- :
-else
- # Restart under the correct shell.
- exec $SHELL "[$]0" --no-reexec ${1+"[$]@"}
-fi
-
-if test "X[$]1" = X--fallback-echo; then
- # used as fallback echo
- shift
- cat <<EOF
-[$]*
-EOF
- exit 0
-fi
-
-# The HP-UX ksh and POSIX shell print the target directory to stdout
-# if CDPATH is set.
-(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
-
-if test -z "$ECHO"; then
-if test "X${echo_test_string+set}" != Xset; then
-# find a string as large as possible, as long as the shell can cope with it
- for cmd in 'sed 50q "[$]0"' 'sed 20q "[$]0"' 'sed 10q "[$]0"' 'sed 2q "[$]0"' 'echo test'; do
- # expected sizes: less than 2Kb, 1Kb, 512 bytes, 16 bytes, ...
- if (echo_test_string="`eval $cmd`") 2>/dev/null &&
- echo_test_string="`eval $cmd`" &&
- (test "X$echo_test_string" = "X$echo_test_string") 2>/dev/null
- then
- break
- fi
- done
-fi
-
-if test "X`($echo '\t') 2>/dev/null`" = 'X\t' &&
- echo_testing_string=`($echo "$echo_test_string") 2>/dev/null` &&
- test "X$echo_testing_string" = "X$echo_test_string"; then
- :
-else
- # The Solaris, AIX, and Digital Unix default echo programs unquote
- # backslashes. This makes it impossible to quote backslashes using
- # echo "$something" | sed 's/\\/\\\\/g'
- #
- # So, first we look for a working echo in the user's PATH.
-
- lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
- for dir in $PATH /usr/ucb; do
- IFS="$lt_save_ifs"
- if (test -f $dir/echo || test -f $dir/echo$ac_exeext) &&
- test "X`($dir/echo '\t') 2>/dev/null`" = 'X\t' &&
- echo_testing_string=`($dir/echo "$echo_test_string") 2>/dev/null` &&
- test "X$echo_testing_string" = "X$echo_test_string"; then
- echo="$dir/echo"
- break
- fi
- done
- IFS="$lt_save_ifs"
-
- if test "X$echo" = Xecho; then
- # We didn't find a better echo, so look for alternatives.
- if test "X`(print -r '\t') 2>/dev/null`" = 'X\t' &&
- echo_testing_string=`(print -r "$echo_test_string") 2>/dev/null` &&
- test "X$echo_testing_string" = "X$echo_test_string"; then
- # This shell has a builtin print -r that does the trick.
- echo='print -r'
- elif (test -f /bin/ksh || test -f /bin/ksh$ac_exeext) &&
- test "X$CONFIG_SHELL" != X/bin/ksh; then
- # If we have ksh, try running configure again with it.
- ORIGINAL_CONFIG_SHELL=${CONFIG_SHELL-/bin/sh}
- export ORIGINAL_CONFIG_SHELL
- CONFIG_SHELL=/bin/ksh
- export CONFIG_SHELL
- exec $CONFIG_SHELL "[$]0" --no-reexec ${1+"[$]@"}
- else
- # Try using printf.
- echo='printf %s\n'
- if test "X`($echo '\t') 2>/dev/null`" = 'X\t' &&
- echo_testing_string=`($echo "$echo_test_string") 2>/dev/null` &&
- test "X$echo_testing_string" = "X$echo_test_string"; then
- # Cool, printf works
- :
- elif echo_testing_string=`($ORIGINAL_CONFIG_SHELL "[$]0" --fallback-echo '\t') 2>/dev/null` &&
- test "X$echo_testing_string" = 'X\t' &&
- echo_testing_string=`($ORIGINAL_CONFIG_SHELL "[$]0" --fallback-echo "$echo_test_string") 2>/dev/null` &&
- test "X$echo_testing_string" = "X$echo_test_string"; then
- CONFIG_SHELL=$ORIGINAL_CONFIG_SHELL
- export CONFIG_SHELL
- SHELL="$CONFIG_SHELL"
- export SHELL
- echo="$CONFIG_SHELL [$]0 --fallback-echo"
- elif echo_testing_string=`($CONFIG_SHELL "[$]0" --fallback-echo '\t') 2>/dev/null` &&
- test "X$echo_testing_string" = 'X\t' &&
- echo_testing_string=`($CONFIG_SHELL "[$]0" --fallback-echo "$echo_test_string") 2>/dev/null` &&
- test "X$echo_testing_string" = "X$echo_test_string"; then
- echo="$CONFIG_SHELL [$]0 --fallback-echo"
- else
- # maybe with a smaller string...
- prev=:
-
- for cmd in 'echo test' 'sed 2q "[$]0"' 'sed 10q "[$]0"' 'sed 20q "[$]0"' 'sed 50q "[$]0"'; do
- if (test "X$echo_test_string" = "X`eval $cmd`") 2>/dev/null
- then
- break
- fi
- prev="$cmd"
- done
-
- if test "$prev" != 'sed 50q "[$]0"'; then
- echo_test_string=`eval $prev`
- export echo_test_string
- exec ${ORIGINAL_CONFIG_SHELL-${CONFIG_SHELL-/bin/sh}} "[$]0" ${1+"[$]@"}
- else
- # Oops. We lost completely, so just stick with echo.
- echo=echo
- fi
- fi
- fi
- fi
-fi
-fi
-
-# Copy echo and quote the copy suitably for passing to libtool from
-# the Makefile, instead of quoting the original, which is used later.
-ECHO=$echo
-if test "X$ECHO" = "X$CONFIG_SHELL [$]0 --fallback-echo"; then
- ECHO="$CONFIG_SHELL \\\$\[$]0 --fallback-echo"
-fi
-
-AC_SUBST(ECHO)
-])])# _LT_AC_PROG_ECHO_BACKSLASH
-
-
-# _LT_AC_LOCK
-# -----------
-AC_DEFUN([_LT_AC_LOCK],
-[AC_ARG_ENABLE([libtool-lock],
- [AS_HELP_STRING([--disable-libtool-lock],
- [avoid locking (might break parallel builds)])])
-test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes
-
-# Some flags need to be propagated to the compiler or linker for good
-# libtool support.
-case $host in
-ia64-*-hpux*)
- # Find out which ABI we are using.
- echo 'int i;' > conftest.$ac_ext
- if AC_TRY_EVAL(ac_compile); then
- case `/usr/bin/file conftest.$ac_objext` in
- *ELF-32*)
- HPUX_IA64_MODE="32"
- ;;
- *ELF-64*)
- HPUX_IA64_MODE="64"
- ;;
- esac
- fi
- rm -rf conftest*
- ;;
-*-*-irix6*)
- # Find out which ABI we are using.
- echo '[#]line __oline__ "configure"' > conftest.$ac_ext
- if AC_TRY_EVAL(ac_compile); then
- if test "$lt_cv_prog_gnu_ld" = yes; then
- case `/usr/bin/file conftest.$ac_objext` in
- *32-bit*)
- LD="${LD-ld} -melf32bsmip"
- ;;
- *N32*)
- LD="${LD-ld} -melf32bmipn32"
- ;;
- *64-bit*)
- LD="${LD-ld} -melf64bmip"
- ;;
- esac
- else
- case `/usr/bin/file conftest.$ac_objext` in
- *32-bit*)
- LD="${LD-ld} -32"
- ;;
- *N32*)
- LD="${LD-ld} -n32"
- ;;
- *64-bit*)
- LD="${LD-ld} -64"
- ;;
- esac
- fi
- fi
- rm -rf conftest*
- ;;
-
-x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*|s390*-*linux*|sparc*-*linux*)
- # Find out which ABI we are using.
- echo 'int i;' > conftest.$ac_ext
- if AC_TRY_EVAL(ac_compile); then
- case "`/usr/bin/file conftest.o`" in
- *32-bit*)
- case $host in
- x86_64-*linux*)
- LD="${LD-ld} -m elf_i386"
- ;;
- ppc64-*linux*|powerpc64-*linux*)
- LD="${LD-ld} -m elf32ppclinux"
- ;;
- s390x-*linux*)
- LD="${LD-ld} -m elf_s390"
- ;;
- sparc64-*linux*)
- LD="${LD-ld} -m elf32_sparc"
- ;;
- esac
- ;;
- *64-bit*)
- case $host in
- x86_64-*linux*)
- LD="${LD-ld} -m elf_x86_64"
- ;;
- ppc*-*linux*|powerpc*-*linux*)
- LD="${LD-ld} -m elf64ppc"
- ;;
- s390*-*linux*)
- LD="${LD-ld} -m elf64_s390"
- ;;
- sparc*-*linux*)
- LD="${LD-ld} -m elf64_sparc"
- ;;
- esac
- ;;
- esac
- fi
- rm -rf conftest*
- ;;
-
-*-*-sco3.2v5*)
- # On SCO OpenServer 5, we need -belf to get full-featured binaries.
- SAVE_CFLAGS="$CFLAGS"
- CFLAGS="$CFLAGS -belf"
- AC_CACHE_CHECK([whether the C compiler needs -belf], lt_cv_cc_needs_belf,
- [AC_LANG_PUSH(C)
- AC_TRY_LINK([],[],[lt_cv_cc_needs_belf=yes],[lt_cv_cc_needs_belf=no])
- AC_LANG_POP])
- if test x"$lt_cv_cc_needs_belf" != x"yes"; then
- # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf
- CFLAGS="$SAVE_CFLAGS"
- fi
- ;;
-AC_PROVIDE_IFELSE([AC_LIBTOOL_WIN32_DLL],
-[*-*-cygwin* | *-*-mingw* | *-*-pw32*)
- AC_CHECK_TOOL(DLLTOOL, dlltool, false)
- AC_CHECK_TOOL(AS, as, false)
- AC_CHECK_TOOL(OBJDUMP, objdump, false)
- ;;
- ])
-esac
-
-need_locks="$enable_libtool_lock"
-
-])# _LT_AC_LOCK
-
-
-# AC_LIBTOOL_COMPILER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS,
-# [OUTPUT-FILE], [ACTION-SUCCESS], [ACTION-FAILURE])
-# ----------------------------------------------------------------
-# Check whether the given compiler option works
-AC_DEFUN([AC_LIBTOOL_COMPILER_OPTION],
-[AC_REQUIRE([LT_AC_PROG_SED])
-AC_CACHE_CHECK([$1], [$2],
- [$2=no
- ifelse([$4], , [ac_outfile=conftest.$ac_objext], [ac_outfile=$4])
- printf "$lt_simple_compile_test_code" > conftest.$ac_ext
- lt_compiler_flag="$3"
- # Insert the option either (1) after the last *FLAGS variable, or
- # (2) before a word containing "conftest.", or (3) at the end.
- # Note that $ac_compile itself does not contain backslashes and begins
- # with a dollar sign (not a hyphen), so the echo should work correctly.
- # The option is referenced via a variable to avoid confusing sed.
- lt_compile=`echo "$ac_compile" | $SED \
- -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
- -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \
- -e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:__oline__: $lt_compile\"" >&AS_MESSAGE_LOG_FD)
- (eval "$lt_compile" 2>conftest.err)
- ac_status=$?
- cat conftest.err >&AS_MESSAGE_LOG_FD
- echo "$as_me:__oline__: \$? = $ac_status" >&AS_MESSAGE_LOG_FD
- if (exit $ac_status) && test -s "$ac_outfile"; then
- # The compiler can only warn and ignore the option if not recognized
- # So say no if there are warnings other than the usual output.
- $echo "X$_lt_compiler_boilerplate" | $Xsed >conftest.exp
- $SED '/^$/d' conftest.err >conftest.er2
- if test ! -s conftest.err || diff conftest.exp conftest.er2 >/dev/null; then
- $2=yes
- fi
- fi
- $rm conftest*
-])
-
-if test x"[$]$2" = xyes; then
- ifelse([$5], , :, [$5])
-else
- ifelse([$6], , :, [$6])
-fi
-])# AC_LIBTOOL_COMPILER_OPTION
-
-
-# AC_LIBTOOL_LINKER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS,
-# [ACTION-SUCCESS], [ACTION-FAILURE])
-# ------------------------------------------------------------
-# Check whether the given compiler option works
-AC_DEFUN([AC_LIBTOOL_LINKER_OPTION],
-[AC_CACHE_CHECK([$1], [$2],
- [$2=no
- save_LDFLAGS="$LDFLAGS"
- LDFLAGS="$LDFLAGS $3"
- printf "$lt_simple_link_test_code" > conftest.$ac_ext
- if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then
- # The compiler can only warn and ignore the option if not recognized
- # So say no if there are warnings
- if test -s conftest.err; then
- # Append any errors to the config.log.
- cat conftest.err 1>&AS_MESSAGE_LOG_FD
- $echo "X$_lt_linker_boilerplate" | $Xsed > conftest.exp
- $SED '/^$/d' conftest.err >conftest.er2
- if diff conftest.exp conftest.er2 >/dev/null; then
- $2=yes
- fi
- else
- $2=yes
- fi
- fi
- $rm conftest*
- LDFLAGS="$save_LDFLAGS"
-])
-
-if test x"[$]$2" = xyes; then
- ifelse([$4], , :, [$4])
-else
- ifelse([$5], , :, [$5])
-fi
-])# AC_LIBTOOL_LINKER_OPTION
-
-
-# AC_LIBTOOL_SYS_MAX_CMD_LEN
-# --------------------------
-AC_DEFUN([AC_LIBTOOL_SYS_MAX_CMD_LEN],
-[# find the maximum length of command line arguments
-AC_MSG_CHECKING([the maximum length of command line arguments])
-AC_CACHE_VAL([lt_cv_sys_max_cmd_len], [dnl
- i=0
- teststring="ABCD"
-
- case $build_os in
- msdosdjgpp*)
- # On DJGPP, this test can blow up pretty badly due to problems in libc
- # (any single argument exceeding 2000 bytes causes a buffer overrun
- # during glob expansion). Even if it were fixed, the result of this
- # check would be larger than it should be.
- lt_cv_sys_max_cmd_len=12288; # 12K is about right
- ;;
-
- gnu*)
- # Under GNU Hurd, this test is not required because there is
- # no limit to the length of command line arguments.
- # Libtool will interpret -1 as no limit whatsoever
- lt_cv_sys_max_cmd_len=-1;
- ;;
-
- cygwin* | mingw*)
- # On Win9x/ME, this test blows up -- it succeeds, but takes
- # about 5 minutes as the teststring grows exponentially.
- # Worse, since 9x/ME are not pre-emptively multitasking,
- # you end up with a "frozen" computer, even though with patience
- # the test eventually succeeds (with a max line length of 256k).
- # Instead, let's just punt: use the minimum linelength reported by
- # all of the supported platforms: 8192 (on NT/2K/XP).
- lt_cv_sys_max_cmd_len=8192;
- ;;
-
- amigaos*)
- # On AmigaOS with pdksh, this test takes hours, literally.
- # So we just punt and use a minimum line length of 8192.
- lt_cv_sys_max_cmd_len=8192;
- ;;
-
- netbsd* | freebsd* | openbsd* | darwin* | dragonfly*)
- # This has been around since 386BSD, at least. Likely further.
- if test -x /sbin/sysctl; then
- lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax`
- elif test -x /usr/sbin/sysctl; then
- lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax`
- else
- lt_cv_sys_max_cmd_len=65536 # usable default for *BSD
- fi
- # And add a safety zone
- lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4`
- lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3`
- ;;
- osf*)
- # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure
- # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not
- # nice to cause kernel panics so lets avoid the loop below.
- # First set a reasonable default.
- lt_cv_sys_max_cmd_len=16384
- #
- if test -x /sbin/sysconfig; then
- case `/sbin/sysconfig -q proc exec_disable_arg_limit` in
- *1*) lt_cv_sys_max_cmd_len=-1 ;;
- esac
- fi
- ;;
- *)
- # If test is not a shell built-in, we'll probably end up computing a
- # maximum length that is only half of the actual maximum length, but
- # we can't tell.
- SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}}
- while (test "X"`$SHELL [$]0 --fallback-echo "X$teststring" 2>/dev/null` \
- = "XX$teststring") >/dev/null 2>&1 &&
- new_result=`expr "X$teststring" : ".*" 2>&1` &&
- lt_cv_sys_max_cmd_len=$new_result &&
- test $i != 17 # 1/2 MB should be enough
- do
- i=`expr $i + 1`
- teststring=$teststring$teststring
- done
- teststring=
- # Add a significant safety factor because C++ compilers can tack on massive
- # amounts of additional arguments before passing them to the linker.
- # It appears as though 1/2 is a usable value.
- lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2`
- ;;
- esac
-])
-if test -n $lt_cv_sys_max_cmd_len ; then
- AC_MSG_RESULT($lt_cv_sys_max_cmd_len)
-else
- AC_MSG_RESULT(none)
-fi
-])# AC_LIBTOOL_SYS_MAX_CMD_LEN
-
-
-# _LT_AC_CHECK_DLFCN
-# --------------------
-AC_DEFUN([_LT_AC_CHECK_DLFCN],
-[AC_CHECK_HEADERS(dlfcn.h)dnl
-])# _LT_AC_CHECK_DLFCN
-
-
-# _LT_AC_TRY_DLOPEN_SELF (ACTION-IF-TRUE, ACTION-IF-TRUE-W-USCORE,
-# ACTION-IF-FALSE, ACTION-IF-CROSS-COMPILING)
-# ------------------------------------------------------------------
-AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF],
-[AC_REQUIRE([_LT_AC_CHECK_DLFCN])dnl
-if test "$cross_compiling" = yes; then :
- [$4]
-else
- lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
- lt_status=$lt_dlunknown
- cat > conftest.$ac_ext <<EOF
-[#line __oline__ "configure"
-#include "confdefs.h"
-
-#if HAVE_DLFCN_H
-#include <dlfcn.h>
-#endif
-
-#include <stdio.h>
-
-#ifdef RTLD_GLOBAL
-# define LT_DLGLOBAL RTLD_GLOBAL
-#else
-# ifdef DL_GLOBAL
-# define LT_DLGLOBAL DL_GLOBAL
-# else
-# define LT_DLGLOBAL 0
-# endif
-#endif
-
-/* We may have to define LT_DLLAZY_OR_NOW in the command line if we
- find out it does not work in some platform. */
-#ifndef LT_DLLAZY_OR_NOW
-# ifdef RTLD_LAZY
-# define LT_DLLAZY_OR_NOW RTLD_LAZY
-# else
-# ifdef DL_LAZY
-# define LT_DLLAZY_OR_NOW DL_LAZY
-# else
-# ifdef RTLD_NOW
-# define LT_DLLAZY_OR_NOW RTLD_NOW
-# else
-# ifdef DL_NOW
-# define LT_DLLAZY_OR_NOW DL_NOW
-# else
-# define LT_DLLAZY_OR_NOW 0
-# endif
-# endif
-# endif
-# endif
-#endif
-
-#ifdef __cplusplus
-extern "C" void exit (int);
-#endif
-
-void fnord() { int i=42;}
-int main ()
-{
- void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW);
- int status = $lt_dlunknown;
-
- if (self)
- {
- if (dlsym (self,"fnord")) status = $lt_dlno_uscore;
- else if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore;
- /* dlclose (self); */
- }
-
- exit (status);
-}]
-EOF
- if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext} 2>/dev/null; then
- (./conftest; exit; ) 2>/dev/null
- lt_status=$?
- case x$lt_status in
- x$lt_dlno_uscore) $1 ;;
- x$lt_dlneed_uscore) $2 ;;
- x$lt_unknown|x*) $3 ;;
- esac
- else :
- # compilation failed
- $3
- fi
-fi
-rm -fr conftest*
-])# _LT_AC_TRY_DLOPEN_SELF
-
-
-# AC_LIBTOOL_DLOPEN_SELF
-# -------------------
-AC_DEFUN([AC_LIBTOOL_DLOPEN_SELF],
-[AC_REQUIRE([_LT_AC_CHECK_DLFCN])dnl
-if test "x$enable_dlopen" != xyes; then
- enable_dlopen=unknown
- enable_dlopen_self=unknown
- enable_dlopen_self_static=unknown
-else
- lt_cv_dlopen=no
- lt_cv_dlopen_libs=
-
- case $host_os in
- beos*)
- lt_cv_dlopen="load_add_on"
- lt_cv_dlopen_libs=
- lt_cv_dlopen_self=yes
- ;;
-
- mingw* | pw32*)
- lt_cv_dlopen="LoadLibrary"
- lt_cv_dlopen_libs=
- ;;
-
- cygwin*)
- lt_cv_dlopen="dlopen"
- lt_cv_dlopen_libs=
- ;;
-
- darwin*)
- # if libdl is installed we need to link against it
- AC_CHECK_LIB([dl], [dlopen],
- [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"],[
- lt_cv_dlopen="dyld"
- lt_cv_dlopen_libs=
- lt_cv_dlopen_self=yes
- ])
- ;;
-
- *)
- AC_CHECK_FUNC([shl_load],
- [lt_cv_dlopen="shl_load"],
- [AC_CHECK_LIB([dld], [shl_load],
- [lt_cv_dlopen="shl_load" lt_cv_dlopen_libs="-dld"],
- [AC_CHECK_FUNC([dlopen],
- [lt_cv_dlopen="dlopen"],
- [AC_CHECK_LIB([dl], [dlopen],
- [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"],
- [AC_CHECK_LIB([svld], [dlopen],
- [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-lsvld"],
- [AC_CHECK_LIB([dld], [dld_link],
- [lt_cv_dlopen="dld_link" lt_cv_dlopen_libs="-dld"])
- ])
- ])
- ])
- ])
- ])
- ;;
- esac
-
- if test "x$lt_cv_dlopen" != xno; then
- enable_dlopen=yes
- else
- enable_dlopen=no
- fi
-
- case $lt_cv_dlopen in
- dlopen)
- save_CPPFLAGS="$CPPFLAGS"
- test "x$ac_cv_header_dlfcn_h" = xyes && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H"
-
- save_LDFLAGS="$LDFLAGS"
- eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\"
-
- save_LIBS="$LIBS"
- LIBS="$lt_cv_dlopen_libs $LIBS"
-
- AC_CACHE_CHECK([whether a program can dlopen itself],
- lt_cv_dlopen_self, [dnl
- _LT_AC_TRY_DLOPEN_SELF(
- lt_cv_dlopen_self=yes, lt_cv_dlopen_self=yes,
- lt_cv_dlopen_self=no, lt_cv_dlopen_self=cross)
- ])
-
- if test "x$lt_cv_dlopen_self" = xyes; then
- LDFLAGS="$LDFLAGS $link_static_flag"
- AC_CACHE_CHECK([whether a statically linked program can dlopen itself],
- lt_cv_dlopen_self_static, [dnl
- _LT_AC_TRY_DLOPEN_SELF(
- lt_cv_dlopen_self_static=yes, lt_cv_dlopen_self_static=yes,
- lt_cv_dlopen_self_static=no, lt_cv_dlopen_self_static=cross)
- ])
- fi
-
- CPPFLAGS="$save_CPPFLAGS"
- LDFLAGS="$save_LDFLAGS"
- LIBS="$save_LIBS"
- ;;
- esac
-
- case $lt_cv_dlopen_self in
- yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;;
- *) enable_dlopen_self=unknown ;;
- esac
-
- case $lt_cv_dlopen_self_static in
- yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;;
- *) enable_dlopen_self_static=unknown ;;
- esac
-fi
-])# AC_LIBTOOL_DLOPEN_SELF
-
-
-# AC_LIBTOOL_PROG_CC_C_O([TAGNAME])
-# ---------------------------------
-# Check to see if options -c and -o are simultaneously supported by compiler
-AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O],
-[AC_REQUIRE([_LT_AC_SYS_COMPILER])dnl
-AC_CACHE_CHECK([if $compiler supports -c -o file.$ac_objext],
- [_LT_AC_TAGVAR(lt_cv_prog_compiler_c_o, $1)],
- [_LT_AC_TAGVAR(lt_cv_prog_compiler_c_o, $1)=no
- $rm -r conftest 2>/dev/null
- mkdir conftest
- cd conftest
- mkdir out
- printf "$lt_simple_compile_test_code" > conftest.$ac_ext
-
- lt_compiler_flag="-o out/conftest2.$ac_objext"
- # Insert the option either (1) after the last *FLAGS variable, or
- # (2) before a word containing "conftest.", or (3) at the end.
- # Note that $ac_compile itself does not contain backslashes and begins
- # with a dollar sign (not a hyphen), so the echo should work correctly.
- lt_compile=`echo "$ac_compile" | $SED \
- -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
- -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \
- -e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:__oline__: $lt_compile\"" >&AS_MESSAGE_LOG_FD)
- (eval "$lt_compile" 2>out/conftest.err)
- ac_status=$?
- cat out/conftest.err >&AS_MESSAGE_LOG_FD
- echo "$as_me:__oline__: \$? = $ac_status" >&AS_MESSAGE_LOG_FD
- if (exit $ac_status) && test -s out/conftest2.$ac_objext
- then
- # The compiler can only warn and ignore the option if not recognized
- # So say no if there are warnings
- $echo "X$_lt_compiler_boilerplate" | $Xsed > out/conftest.exp
- $SED '/^$/d' out/conftest.err >out/conftest.er2
- if test ! -s out/conftest.err || diff out/conftest.exp out/conftest.er2 >/dev/null; then
- _LT_AC_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes
- fi
- fi
- chmod u+w .
- $rm conftest*
- # SGI C++ compiler will create directory out/ii_files/ for
- # template instantiation
- test -d out/ii_files && $rm out/ii_files/* && rmdir out/ii_files
- $rm out/* && rmdir out
- cd ..
- rmdir conftest
- $rm conftest*
-])
-])# AC_LIBTOOL_PROG_CC_C_O
-
-
-# AC_LIBTOOL_SYS_HARD_LINK_LOCKS([TAGNAME])
-# -----------------------------------------
-# Check to see if we can do hard links to lock some files if needed
-AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS],
-[AC_REQUIRE([_LT_AC_LOCK])dnl
-
-hard_links="nottested"
-if test "$_LT_AC_TAGVAR(lt_cv_prog_compiler_c_o, $1)" = no && test "$need_locks" != no; then
- # do not overwrite the value of need_locks provided by the user
- AC_MSG_CHECKING([if we can lock with hard links])
- hard_links=yes
- $rm conftest*
- ln conftest.a conftest.b 2>/dev/null && hard_links=no
- touch conftest.a
- ln conftest.a conftest.b 2>&5 || hard_links=no
- ln conftest.a conftest.b 2>/dev/null && hard_links=no
- AC_MSG_RESULT([$hard_links])
- if test "$hard_links" = no; then
- AC_MSG_WARN([`$CC' does not support `-c -o', so `make -j' may be unsafe])
- need_locks=warn
- fi
-else
- need_locks=no
-fi
-])# AC_LIBTOOL_SYS_HARD_LINK_LOCKS
-
-
-# AC_LIBTOOL_OBJDIR
-# -----------------
-AC_DEFUN([AC_LIBTOOL_OBJDIR],
-[AC_CACHE_CHECK([for objdir], [lt_cv_objdir],
-[rm -f .libs 2>/dev/null
-mkdir .libs 2>/dev/null
-if test -d .libs; then
- lt_cv_objdir=.libs
-else
- # MS-DOS does not allow filenames that begin with a dot.
- lt_cv_objdir=_libs
-fi
-rmdir .libs 2>/dev/null])
-objdir=$lt_cv_objdir
-])# AC_LIBTOOL_OBJDIR
-
-
-# AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH([TAGNAME])
-# ----------------------------------------------
-# Check hardcoding attributes.
-AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH],
-[AC_MSG_CHECKING([how to hardcode library paths into programs])
-_LT_AC_TAGVAR(hardcode_action, $1)=
-if test -n "$_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)" || \
- test -n "$_LT_AC_TAGVAR(runpath_var, $1)" || \
- test "X$_LT_AC_TAGVAR(hardcode_automatic, $1)" = "Xyes" ; then
-
- # We can hardcode non-existant directories.
- if test "$_LT_AC_TAGVAR(hardcode_direct, $1)" != no &&
- # If the only mechanism to avoid hardcoding is shlibpath_var, we
- # have to relink, otherwise we might link with an installed library
- # when we should be linking with a yet-to-be-installed one
- ## test "$_LT_AC_TAGVAR(hardcode_shlibpath_var, $1)" != no &&
- test "$_LT_AC_TAGVAR(hardcode_minus_L, $1)" != no; then
- # Linking always hardcodes the temporary library directory.
- _LT_AC_TAGVAR(hardcode_action, $1)=relink
- else
- # We can link without hardcoding, and we can hardcode nonexisting dirs.
- _LT_AC_TAGVAR(hardcode_action, $1)=immediate
- fi
-else
- # We cannot hardcode anything, or else we can only hardcode existing
- # directories.
- _LT_AC_TAGVAR(hardcode_action, $1)=unsupported
-fi
-AC_MSG_RESULT([$_LT_AC_TAGVAR(hardcode_action, $1)])
-
-if test "$_LT_AC_TAGVAR(hardcode_action, $1)" = relink; then
- # Fast installation is not supported
- enable_fast_install=no
-elif test "$shlibpath_overrides_runpath" = yes ||
- test "$enable_shared" = no; then
- # Fast installation is not necessary
- enable_fast_install=needless
-fi
-])# AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH
-
-
-# AC_LIBTOOL_SYS_LIB_STRIP
-# ------------------------
-AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP],
-[striplib=
-old_striplib=
-AC_MSG_CHECKING([whether stripping libraries is possible])
-if test -n "$STRIP" && $STRIP -V 2>&1 | grep "GNU strip" >/dev/null; then
- test -z "$old_striplib" && old_striplib="$STRIP --strip-debug"
- test -z "$striplib" && striplib="$STRIP --strip-unneeded"
- AC_MSG_RESULT([yes])
-else
-# FIXME - insert some real tests, host_os isn't really good enough
- case $host_os in
- darwin*)
- if test -n "$STRIP" ; then
- striplib="$STRIP -x"
- AC_MSG_RESULT([yes])
- else
- AC_MSG_RESULT([no])
-fi
- ;;
- *)
- AC_MSG_RESULT([no])
- ;;
- esac
-fi
-])# AC_LIBTOOL_SYS_LIB_STRIP
-
-
-# AC_LIBTOOL_SYS_DYNAMIC_LINKER
-# -----------------------------
-# PORTME Fill in your ld.so characteristics
-AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER],
-[AC_MSG_CHECKING([dynamic linker characteristics])
-library_names_spec=
-libname_spec='lib$name'
-soname_spec=
-shrext_cmds=".so"; shrext="$shrext_cmds"
-postinstall_cmds=
-postuninstall_cmds=
-finish_cmds=
-finish_eval=
-shlibpath_var=
-shlibpath_overrides_runpath=unknown
-version_type=none
-dynamic_linker="$host_os ld.so"
-sys_lib_dlsearch_path_spec="/lib /usr/lib"
-if test "$GCC" = yes; then
- sys_lib_search_path_spec=`$CC -print-search-dirs | grep "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"`
- if echo "$sys_lib_search_path_spec" | grep ';' >/dev/null ; then
- # if the path contains ";" then we assume it to be the separator
- # otherwise default to the standard path separator (i.e. ":") - it is
- # assumed that no part of a normal pathname contains ";" but that should
- # okay in the real world where ";" in dirpaths is itself problematic.
- sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'`
- else
- sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"`
- fi
-else
- sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib"
-fi
-need_lib_prefix=unknown
-hardcode_into_libs=no
-
-# when you set need_version to no, make sure it does not cause -set_version
-# flags to be left without arguments
-need_version=unknown
-
-case $host_os in
-aix3*)
- version_type=linux
- library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a'
- shlibpath_var=LIBPATH
-
- # AIX 3 has no versioning support, so we append a major version to the name.
- soname_spec='${libname}${release}${shared_ext}$major'
- ;;
-
-aix4* | aix5*)
- version_type=linux
- need_lib_prefix=no
- need_version=no
- hardcode_into_libs=yes
- if test "$host_cpu" = ia64; then
- # AIX 5 supports IA64
- library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}'
- shlibpath_var=LD_LIBRARY_PATH
- else
- # With GCC up to 2.95.x, collect2 would create an import file
- # for dependence libraries. The import file would start with
- # the line `#! .'. This would cause the generated library to
- # depend on `.', always an invalid library. This was fixed in
- # development snapshots of GCC prior to 3.0.
- case $host_os in
- aix4 | aix4.[[01]] | aix4.[[01]].*)
- if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)'
- echo ' yes '
- echo '#endif'; } | ${CC} -E - | grep yes > /dev/null; then
- :
- else
- can_build_shared=no
- fi
- ;;
- esac
- # AIX (on Power*) has no versioning support, so currently we can not hardcode correct
- # soname into executable. Probably we can add versioning support to
- # collect2, so additional links can be useful in future.
- if test "$aix_use_runtimelinking" = yes; then
- # If using run time linking (on AIX 4.2 or later) use lib<name>.so
- # instead of lib<name>.a to let people know that these are not
- # typical AIX shared libraries.
- library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
- else
- # We preserve .a as extension for shared libraries through AIX4.2
- # and later when we are not doing run time linking.
- library_names_spec='${libname}${release}.a $libname.a'
- soname_spec='${libname}${release}${shared_ext}$major'
- fi
- shlibpath_var=LIBPATH
- fi
- ;;
-
-amigaos*)
- library_names_spec='$libname.ixlibrary $libname.a'
- # Create ${libname}_ixlibrary.a entries in /sys/libs.
- finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$echo "X$lib" | $Xsed -e '\''s%^.*/\([[^/]]*\)\.ixlibrary$%\1%'\''`; test $rm /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done'
- ;;
-
-beos*)
- library_names_spec='${libname}${shared_ext}'
- dynamic_linker="$host_os ld.so"
- shlibpath_var=LIBRARY_PATH
- ;;
-
-bsdi[[45]]*)
- version_type=linux
- need_version=no
- library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
- soname_spec='${libname}${release}${shared_ext}$major'
- finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir'
- shlibpath_var=LD_LIBRARY_PATH
- sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib"
- sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib"
- # the default ld.so.conf also contains /usr/contrib/lib and
- # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow
- # libtool to hard-code these into programs
- ;;
-
-cygwin* | mingw* | pw32*)
- version_type=windows
- shrext_cmds=".dll"; shrext="$shrext_cmds"
- need_version=no
- need_lib_prefix=no
-
- case $GCC,$host_os in
- yes,cygwin* | yes,mingw* | yes,pw32*)
- library_names_spec='$libname.dll.a'
- # DLL is installed to $(libdir)/../bin by postinstall_cmds
- postinstall_cmds='base_file=`basename \${file}`~
- dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i;echo \$dlname'\''`~
- dldir=$destdir/`dirname \$dlpath`~
- test -d \$dldir || mkdir -p \$dldir~
- $install_prog $dir/$dlname \$dldir/$dlname'
- postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
- dlpath=$dir/\$dldll~
- $rm \$dlpath'
- shlibpath_overrides_runpath=yes
-
- case $host_os in
- cygwin*)
- # Cygwin DLLs use 'cyg' prefix rather than 'lib'
- soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}'
- sys_lib_search_path_spec="/usr/lib /lib/w32api /lib /usr/local/lib"
- ;;
- mingw*)
- # MinGW DLLs use traditional 'lib' prefix
- soname_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}'
- sys_lib_search_path_spec=`$CC -print-search-dirs | grep "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"`
- if echo "$sys_lib_search_path_spec" | [grep ';[c-zC-Z]:/' >/dev/null]; then
- # It is most probably a Windows format PATH printed by
- # mingw gcc, but we are running on Cygwin. Gcc prints its search
- # path with ; separators, and with drive letters. We can handle the
- # drive letters (cygwin fileutils understands them), so leave them,
- # especially as we might pass files found there to a mingw objdump,
- # which wouldn't understand a cygwinified path. Ahh.
- sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'`
- else
- sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"`
- fi
- ;;
- pw32*)
- # pw32 DLLs use 'pw' prefix rather than 'lib'
- library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}'
- ;;
- esac
- ;;
-
- *)
- library_names_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext} $libname.lib'
- ;;
- esac
- dynamic_linker='Win32 ld.exe'
- # FIXME: first we should search . and the directory the executable is in
- shlibpath_var=PATH
- ;;
-
-darwin* | rhapsody*)
- dynamic_linker="$host_os dyld"
- version_type=darwin
- need_lib_prefix=no
- need_version=no
- library_names_spec='${libname}${release}${versuffix}$shared_ext ${libname}${release}${major}$shared_ext ${libname}$shared_ext'
- soname_spec='${libname}${release}${major}$shared_ext'
- shlibpath_overrides_runpath=yes
- shlibpath_var=DYLD_LIBRARY_PATH
- shrext_cmds='$(test .$module = .yes && echo .so || echo .dylib)'; shrext="$shrext_cmds"
- # Apple's gcc prints 'gcc -print-search-dirs' doesn't operate the same.
- if test "$GCC" = yes; then
- sys_lib_search_path_spec=`$CC -print-search-dirs | tr "\n" "$PATH_SEPARATOR" | sed -e 's/libraries:/@libraries:/' | tr "@" "\n" | grep "^libraries:" | sed -e "s/^libraries://" -e "s,=/,/,g" -e "s,$PATH_SEPARATOR, ,g" -e "s,.*,& /lib /usr/lib /usr/local/lib,g"`
- else
- sys_lib_search_path_spec='/lib /usr/lib /usr/local/lib'
- fi
- sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib'
- ;;
-
-dgux*)
- version_type=linux
- need_lib_prefix=no
- need_version=no
- library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext'
- soname_spec='${libname}${release}${shared_ext}$major'
- shlibpath_var=LD_LIBRARY_PATH
- ;;
-
-freebsd1*)
- dynamic_linker=no
- ;;
-
-kfreebsd*-gnu)
- version_type=linux
- need_lib_prefix=no
- need_version=no
- library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
- soname_spec='${libname}${release}${shared_ext}$major'
- shlibpath_var=LD_LIBRARY_PATH
- shlibpath_overrides_runpath=no
- hardcode_into_libs=yes
- dynamic_linker='GNU ld.so'
- ;;
-
-freebsd* | dragonfly*)
- # DragonFly does not have aout. When/if they implement a new
- # versioning mechanism, adjust this.
- objformat=`test -x /usr/bin/objformat && /usr/bin/objformat || echo aout`
- version_type=freebsd-$objformat
- case $version_type in
- freebsd-elf*)
- library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
- need_version=no
- need_lib_prefix=no
- ;;
- freebsd-*)
- library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix'
- need_version=yes
- ;;
- esac
- shlibpath_var=LD_LIBRARY_PATH
- case $host_os in
- freebsd2*)
- shlibpath_overrides_runpath=yes
- ;;
- freebsd3.[[01]]* | freebsdelf3.[[01]]*)
- shlibpath_overrides_runpath=yes
- hardcode_into_libs=yes
- ;;
- *) # from 3.2 on
- shlibpath_overrides_runpath=no
- hardcode_into_libs=yes
- ;;
- esac
- ;;
-
-gnu*)
- version_type=linux
- need_lib_prefix=no
- need_version=no
- library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}'
- soname_spec='${libname}${release}${shared_ext}$major'
- shlibpath_var=LD_LIBRARY_PATH
- hardcode_into_libs=yes
- ;;
-
-hpux9* | hpux10* | hpux11*)
- # Give a soname corresponding to the major version so that dld.sl refuses to
- # link against other versions.
- version_type=sunos
- need_lib_prefix=no
- need_version=no
- case "$host_cpu" in
- ia64*)
- shrext_cmds='.so'; shrext="$shrext_cmds"
- hardcode_into_libs=yes
- dynamic_linker="$host_os dld.so"
- shlibpath_var=LD_LIBRARY_PATH
- shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
- library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
- soname_spec='${libname}${release}${shared_ext}$major'
- if test "X$HPUX_IA64_MODE" = X32; then
- sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib"
- else
- sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64"
- fi
- sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
- ;;
- hppa*64*)
- shrext_cmds='.sl'; shrext="$shrext_cmds"
- hardcode_into_libs=yes
- dynamic_linker="$host_os dld.sl"
- shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH
- shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
- library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
- soname_spec='${libname}${release}${shared_ext}$major'
- sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64"
- sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
- ;;
- *)
- shrext_cmds='.sl'; shrext="$shrext_cmds"
- dynamic_linker="$host_os dld.sl"
- shlibpath_var=SHLIB_PATH
- shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH
- library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
- soname_spec='${libname}${release}${shared_ext}$major'
- ;;
- esac
- # HP-UX runs *really* slowly unless shared libraries are mode 555.
- postinstall_cmds='chmod 555 $lib'
- ;;
-
-irix5* | irix6* | nonstopux*)
- case $host_os in
- nonstopux*) version_type=nonstopux ;;
- *)
- if test "$lt_cv_prog_gnu_ld" = yes; then
- version_type=linux
- else
- version_type=irix
- fi ;;
- esac
- need_lib_prefix=no
- need_version=no
- soname_spec='${libname}${release}${shared_ext}$major'
- library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}'
- case $host_os in
- irix5* | nonstopux*)
- libsuff= shlibsuff=
- ;;
- *)
- case $LD in # libtool.m4 will add one of these switches to LD
- *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ")
- libsuff= shlibsuff= libmagic=32-bit;;
- *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ")
- libsuff=32 shlibsuff=N32 libmagic=N32;;
- *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ")
- libsuff=64 shlibsuff=64 libmagic=64-bit;;
- *) libsuff= shlibsuff= libmagic=never-match;;
- esac
- ;;
- esac
- shlibpath_var=LD_LIBRARY${shlibsuff}_PATH
- shlibpath_overrides_runpath=no
- sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}"
- sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}"
- hardcode_into_libs=yes
- ;;
-
-# No shared lib support for Linux oldld, aout, or coff.
-linux*oldld* | linux*aout* | linux*coff*)
- dynamic_linker=no
- ;;
-
-# This must be Linux ELF.
-linux*)
- version_type=linux
- need_lib_prefix=no
- need_version=no
- library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
- soname_spec='${libname}${release}${shared_ext}$major'
- finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir'
- shlibpath_var=LD_LIBRARY_PATH
- shlibpath_overrides_runpath=no
- # This implies no fast_install, which is unacceptable.
- # Some rework will be needed to allow for fast_install
- # before this can be enabled.
- hardcode_into_libs=yes
-
- # Append ld.so.conf contents to the search path
- if test -f /etc/ld.so.conf; then
- lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s", \[$]2)); skip = 1; } { if (!skip) print \[$]0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;/^$/d' | tr '\n' ' '`
- sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra"
- fi
-
- # We used to test for /lib/ld.so.1 and disable shared libraries on
- # powerpc, because MkLinux only supported shared libraries with the
- # GNU dynamic linker. Since this was broken with cross compilers,
- # most powerpc-linux boxes support dynamic linking these days and
- # people can always --disable-shared, the test was removed, and we
- # assume the GNU/Linux dynamic linker is in use.
- dynamic_linker='GNU/Linux ld.so'
- ;;
-
-knetbsd*-gnu)
- version_type=linux
- need_lib_prefix=no
- need_version=no
- library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
- soname_spec='${libname}${release}${shared_ext}$major'
- shlibpath_var=LD_LIBRARY_PATH
- shlibpath_overrides_runpath=no
- hardcode_into_libs=yes
- dynamic_linker='GNU ld.so'
- ;;
-
-netbsd*)
- version_type=sunos
- need_lib_prefix=no
- need_version=no
- if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then
- library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
- finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
- dynamic_linker='NetBSD (a.out) ld.so'
- else
- library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
- soname_spec='${libname}${release}${shared_ext}$major'
- dynamic_linker='NetBSD ld.elf_so'
- fi
- shlibpath_var=LD_LIBRARY_PATH
- shlibpath_overrides_runpath=yes
- hardcode_into_libs=yes
- ;;
-
-newsos6)
- version_type=linux
- library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
- shlibpath_var=LD_LIBRARY_PATH
- shlibpath_overrides_runpath=yes
- ;;
-
-nto-qnx*)
- version_type=linux
- need_lib_prefix=no
- need_version=no
- library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
- soname_spec='${libname}${release}${shared_ext}$major'
- shlibpath_var=LD_LIBRARY_PATH
- shlibpath_overrides_runpath=yes
- ;;
-
-openbsd*)
- version_type=sunos
- need_lib_prefix=no
- # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs.
- case $host_os in
- openbsd3.3 | openbsd3.3.*) need_version=yes ;;
- *) need_version=no ;;
- esac
- library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
- finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
- shlibpath_var=LD_LIBRARY_PATH
- if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
- case $host_os in
- openbsd2.[[89]] | openbsd2.[[89]].*)
- shlibpath_overrides_runpath=no
- ;;
- *)
- shlibpath_overrides_runpath=yes
- ;;
- esac
- else
- shlibpath_overrides_runpath=yes
- fi
- ;;
-
-os2*)
- libname_spec='$name'
- shrext_cmds=".dll"; shrext="$shrext_cmds"
- need_lib_prefix=no
- library_names_spec='$libname${shared_ext} $libname.a'
- dynamic_linker='OS/2 ld.exe'
- shlibpath_var=LIBPATH
- ;;
-
-osf3* | osf4* | osf5*)
- version_type=osf
- need_lib_prefix=no
- need_version=no
- soname_spec='${libname}${release}${shared_ext}$major'
- library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
- shlibpath_var=LD_LIBRARY_PATH
- sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib"
- sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec"
- ;;
-
-sco3.2v5*)
- version_type=osf
- soname_spec='${libname}${release}${shared_ext}$major'
- library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
- shlibpath_var=LD_LIBRARY_PATH
- ;;
-
-solaris*)
- version_type=linux
- need_lib_prefix=no
- need_version=no
- library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
- soname_spec='${libname}${release}${shared_ext}$major'
- shlibpath_var=LD_LIBRARY_PATH
- shlibpath_overrides_runpath=yes
- hardcode_into_libs=yes
- # ldd complains unless libraries are executable
- postinstall_cmds='chmod +x $lib'
- ;;
-
-sunos4*)
- version_type=sunos
- library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
- finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir'
- shlibpath_var=LD_LIBRARY_PATH
- shlibpath_overrides_runpath=yes
- if test "$with_gnu_ld" = yes; then
- need_lib_prefix=no
- fi
- need_version=yes
- ;;
-
-sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*)
- version_type=linux
- library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
- soname_spec='${libname}${release}${shared_ext}$major'
- shlibpath_var=LD_LIBRARY_PATH
- case $host_vendor in
- sni)
- shlibpath_overrides_runpath=no
- need_lib_prefix=no
- export_dynamic_flag_spec='${wl}-Blargedynsym'
- runpath_var=LD_RUN_PATH
- ;;
- siemens)
- need_lib_prefix=no
- ;;
- motorola)
- need_lib_prefix=no
- need_version=no
- shlibpath_overrides_runpath=no
- sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib'
- ;;
- esac
- ;;
-
-sysv4*MP*)
- if test -d /usr/nec ;then
- version_type=linux
- library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}'
- soname_spec='$libname${shared_ext}.$major'
- shlibpath_var=LD_LIBRARY_PATH
- fi
- ;;
-
-uts4*)
- version_type=linux
- library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
- soname_spec='${libname}${release}${shared_ext}$major'
- shlibpath_var=LD_LIBRARY_PATH
- ;;
-
-*)
- dynamic_linker=no
- ;;
-esac
-AC_MSG_RESULT([$dynamic_linker])
-test "$dynamic_linker" = no && can_build_shared=no
-])# AC_LIBTOOL_SYS_DYNAMIC_LINKER
-
-
-# _LT_AC_TAGCONFIG
-# ----------------
-AC_DEFUN([_LT_AC_TAGCONFIG],
-[AC_ARG_WITH([tags],
- [AS_HELP_STRING([--with-tags@<:@=TAGS@:>@],
- [include additional configurations @<:@automatic@:>@])],
- [tagnames="$withval"])
-
-if test -f "$ltmain" && test -n "$tagnames"; then
- if test ! -f "${ofile}"; then
- AC_MSG_WARN([output file `$ofile' does not exist])
- fi
-
- if test -z "$LTCC"; then
- eval "`$SHELL ${ofile} --config | grep '^LTCC='`"
- if test -z "$LTCC"; then
- AC_MSG_WARN([output file `$ofile' does not look like a libtool script])
- else
- AC_MSG_WARN([using `LTCC=$LTCC', extracted from `$ofile'])
- fi
- fi
-
- # Extract list of available tagged configurations in $ofile.
- # Note that this assumes the entire list is on one line.
- available_tags=`grep "^available_tags=" "${ofile}" | $SED -e 's/available_tags=\(.*$\)/\1/' -e 's/\"//g'`
-
- lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
- for tagname in $tagnames; do
- IFS="$lt_save_ifs"
- # Check whether tagname contains only valid characters
- case `$echo "X$tagname" | $Xsed -e 's:[[-_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890,/]]::g'` in
- "") ;;
- *) AC_MSG_ERROR([invalid tag name: $tagname])
- ;;
- esac
-
- if grep "^# ### BEGIN LIBTOOL TAG CONFIG: $tagname$" < "${ofile}" > /dev/null
- then
- AC_MSG_ERROR([tag name \"$tagname\" already exists])
- fi
-
- # Update the list of available tags.
- if test -n "$tagname"; then
- echo appending configuration tag \"$tagname\" to $ofile
-
- case $tagname in
- CXX)
- if test -n "$CXX" && ( test "X$CXX" != "Xno" &&
- ( (test "X$CXX" = "Xg++" && `g++ -v >/dev/null 2>&1` ) ||
- (test "X$CXX" != "Xg++"))) ; then
- AC_LIBTOOL_LANG_CXX_CONFIG
- else
- tagname=""
- fi
- ;;
-
- F77)
- if test -n "$F77" && test "X$F77" != "Xno"; then
- AC_LIBTOOL_LANG_F77_CONFIG
- else
- tagname=""
- fi
- ;;
-
- GCJ)
- if test -n "$GCJ" && test "X$GCJ" != "Xno"; then
- AC_LIBTOOL_LANG_GCJ_CONFIG
- else
- tagname=""
- fi
- ;;
-
- RC)
- AC_LIBTOOL_LANG_RC_CONFIG
- ;;
-
- *)
- AC_MSG_ERROR([Unsupported tag name: $tagname])
- ;;
- esac
-
- # Append the new tag name to the list of available tags.
- if test -n "$tagname" ; then
- available_tags="$available_tags $tagname"
- fi
- fi
- done
- IFS="$lt_save_ifs"
-
- # Now substitute the updated list of available tags.
- if eval "sed -e 's/^available_tags=.*\$/available_tags=\"$available_tags\"/' \"$ofile\" > \"${ofile}T\""; then
- mv "${ofile}T" "$ofile"
- chmod +x "$ofile"
- else
- rm -f "${ofile}T"
- AC_MSG_ERROR([unable to update list of available tagged configurations.])
- fi
-fi
-])# _LT_AC_TAGCONFIG
-
-
-# AC_LIBTOOL_DLOPEN
-# -----------------
-# enable checks for dlopen support
-AC_DEFUN([AC_LIBTOOL_DLOPEN],
- [AC_BEFORE([$0],[AC_LIBTOOL_SETUP])
-])# AC_LIBTOOL_DLOPEN
-
-
-# AC_LIBTOOL_WIN32_DLL
-# --------------------
-# declare package support for building win32 dll's
-AC_DEFUN([AC_LIBTOOL_WIN32_DLL],
-[AC_BEFORE([$0], [AC_LIBTOOL_SETUP])
-])# AC_LIBTOOL_WIN32_DLL
-
-
-# AC_ENABLE_SHARED([DEFAULT])
-# ---------------------------
-# implement the --enable-shared flag
-# DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'.
-AC_DEFUN([AC_ENABLE_SHARED],
-[define([AC_ENABLE_SHARED_DEFAULT], ifelse($1, no, no, yes))dnl
-AC_ARG_ENABLE([shared],
- [AS_HELP_STRING([--enable-shared@<:@=PKGS@:>@],
- [build shared libraries @<:@default=]AC_ENABLE_SHARED_DEFAULT[@:>@])],
- [p=${PACKAGE-default}
- case $enableval in
- yes) enable_shared=yes ;;
- no) enable_shared=no ;;
- *)
- enable_shared=no
- # Look at the argument we got. We use all the common list separators.
- lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
- for pkg in $enableval; do
- IFS="$lt_save_ifs"
- if test "X$pkg" = "X$p"; then
- enable_shared=yes
- fi
- done
- IFS="$lt_save_ifs"
- ;;
- esac],
- [enable_shared=]AC_ENABLE_SHARED_DEFAULT)
-])# AC_ENABLE_SHARED
-
-
-# AC_DISABLE_SHARED
-# -----------------
-#- set the default shared flag to --disable-shared
-AC_DEFUN([AC_DISABLE_SHARED],
-[AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
-AC_ENABLE_SHARED(no)
-])# AC_DISABLE_SHARED
-
-
-# AC_ENABLE_STATIC([DEFAULT])
-# ---------------------------
-# implement the --enable-static flag
-# DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'.
-AC_DEFUN([AC_ENABLE_STATIC],
-[define([AC_ENABLE_STATIC_DEFAULT], ifelse($1, no, no, yes))dnl
-AC_ARG_ENABLE([static],
- [AS_HELP_STRING([--enable-static@<:@=PKGS@:>@],
- [build static libraries @<:@default=]AC_ENABLE_STATIC_DEFAULT[@:>@])],
- [p=${PACKAGE-default}
- case $enableval in
- yes) enable_static=yes ;;
- no) enable_static=no ;;
- *)
- enable_static=no
- # Look at the argument we got. We use all the common list separators.
- lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
- for pkg in $enableval; do
- IFS="$lt_save_ifs"
- if test "X$pkg" = "X$p"; then
- enable_static=yes
- fi
- done
- IFS="$lt_save_ifs"
- ;;
- esac],
- [enable_static=]AC_ENABLE_STATIC_DEFAULT)
-])# AC_ENABLE_STATIC
-
-
-# AC_DISABLE_STATIC
-# -----------------
-# set the default static flag to --disable-static
-AC_DEFUN([AC_DISABLE_STATIC],
-[AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
-AC_ENABLE_STATIC(no)
-])# AC_DISABLE_STATIC
-
-
-# AC_ENABLE_FAST_INSTALL([DEFAULT])
-# ---------------------------------
-# implement the --enable-fast-install flag
-# DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'.
-AC_DEFUN([AC_ENABLE_FAST_INSTALL],
-[define([AC_ENABLE_FAST_INSTALL_DEFAULT], ifelse($1, no, no, yes))dnl
-AC_ARG_ENABLE([fast-install],
- [AS_HELP_STRING([--enable-fast-install@<:@=PKGS@:>@],
- [optimize for fast installation @<:@default=]AC_ENABLE_FAST_INSTALL_DEFAULT[@:>@])],
- [p=${PACKAGE-default}
- case $enableval in
- yes) enable_fast_install=yes ;;
- no) enable_fast_install=no ;;
- *)
- enable_fast_install=no
- # Look at the argument we got. We use all the common list separators.
- lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
- for pkg in $enableval; do
- IFS="$lt_save_ifs"
- if test "X$pkg" = "X$p"; then
- enable_fast_install=yes
- fi
- done
- IFS="$lt_save_ifs"
- ;;
- esac],
- [enable_fast_install=]AC_ENABLE_FAST_INSTALL_DEFAULT)
-])# AC_ENABLE_FAST_INSTALL
-
-
-# AC_DISABLE_FAST_INSTALL
-# -----------------------
-# set the default to --disable-fast-install
-AC_DEFUN([AC_DISABLE_FAST_INSTALL],
-[AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
-AC_ENABLE_FAST_INSTALL(no)
-])# AC_DISABLE_FAST_INSTALL
-
-
-# AC_LIBTOOL_PICMODE([MODE])
-# --------------------------
-# implement the --with-pic flag
-# MODE is either `yes' or `no'. If omitted, it defaults to `both'.
-AC_DEFUN([AC_LIBTOOL_PICMODE],
-[AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
-pic_mode=ifelse($#,1,$1,default)
-])# AC_LIBTOOL_PICMODE
-
-
-# AC_PROG_EGREP
-# -------------
-# This is predefined starting with Autoconf 2.54, so this conditional
-# definition can be removed once we require Autoconf 2.54 or later.
-m4_ifndef([AC_PROG_EGREP], [AC_DEFUN([AC_PROG_EGREP],
-[AC_CACHE_CHECK([for egrep], [ac_cv_prog_egrep],
- [if echo a | (grep -E '(a|b)') >/dev/null 2>&1
- then ac_cv_prog_egrep='grep -E'
- else ac_cv_prog_egrep='egrep'
- fi])
- EGREP=$ac_cv_prog_egrep
- AC_SUBST([EGREP])
-])])
-
-
-# AC_PATH_TOOL_PREFIX
-# -------------------
-# find a file program which can recognise shared library
-AC_DEFUN([AC_PATH_TOOL_PREFIX],
-[AC_REQUIRE([AC_PROG_EGREP])dnl
-AC_MSG_CHECKING([for $1])
-AC_CACHE_VAL(lt_cv_path_MAGIC_CMD,
-[case $MAGIC_CMD in
-[[\\/*] | ?:[\\/]*])
- lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path.
- ;;
-*)
- lt_save_MAGIC_CMD="$MAGIC_CMD"
- lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
-dnl $ac_dummy forces splitting on constant user-supplied paths.
-dnl POSIX.2 word splitting is done only on the output of word expansions,
-dnl not every word. This closes a longstanding sh security hole.
- ac_dummy="ifelse([$2], , $PATH, [$2])"
- for ac_dir in $ac_dummy; do
- IFS="$lt_save_ifs"
- test -z "$ac_dir" && ac_dir=.
- if test -f $ac_dir/$1; then
- lt_cv_path_MAGIC_CMD="$ac_dir/$1"
- if test -n "$file_magic_test_file"; then
- case $deplibs_check_method in
- "file_magic "*)
- file_magic_regex="`expr \"$deplibs_check_method\" : \"file_magic \(.*\)\"`"
- MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
- if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null |
- $EGREP "$file_magic_regex" > /dev/null; then
- :
- else
- cat <<EOF 1>&2
-
-*** Warning: the command libtool uses to detect shared libraries,
-*** $file_magic_cmd, produces output that libtool cannot recognize.
-*** The result is that libtool may fail to recognize shared libraries
-*** as such. This will affect the creation of libtool libraries that
-*** depend on shared libraries, but programs linked with such libtool
-*** libraries will work regardless of this problem. Nevertheless, you
-*** may want to report the problem to your system manager and/or to
-*** bug-libtool@gnu.org
-
-EOF
- fi ;;
- esac
- fi
- break
- fi
- done
- IFS="$lt_save_ifs"
- MAGIC_CMD="$lt_save_MAGIC_CMD"
- ;;
-esac])
-MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
-if test -n "$MAGIC_CMD"; then
- AC_MSG_RESULT($MAGIC_CMD)
-else
- AC_MSG_RESULT(no)
-fi
-])# AC_PATH_TOOL_PREFIX
-
-
-# AC_PATH_MAGIC
-# -------------
-# find a file program which can recognise a shared library
-AC_DEFUN([AC_PATH_MAGIC],
-[AC_PATH_TOOL_PREFIX(${ac_tool_prefix}file, /usr/bin$PATH_SEPARATOR$PATH)
-if test -z "$lt_cv_path_MAGIC_CMD"; then
- if test -n "$ac_tool_prefix"; then
- AC_PATH_TOOL_PREFIX(file, /usr/bin$PATH_SEPARATOR$PATH)
- else
- MAGIC_CMD=:
- fi
-fi
-])# AC_PATH_MAGIC
-
-
-# AC_PROG_LD
-# ----------
-# find the pathname to the GNU or non-GNU linker
-AC_DEFUN([AC_PROG_LD],
-[AC_ARG_WITH([gnu-ld],
- [AS_HELP_STRING([--with-gnu-ld],
- [assume the C compiler uses GNU ld @<:@default=no@:>@])],
- [test "$withval" = no || with_gnu_ld=yes],
- [with_gnu_ld=no])
-AC_REQUIRE([LT_AC_PROG_SED])dnl
-AC_REQUIRE([AC_PROG_CC])dnl
-AC_REQUIRE([AC_CANONICAL_HOST])dnl
-AC_REQUIRE([AC_CANONICAL_BUILD])dnl
-ac_prog=ld
-if test "$GCC" = yes; then
- # Check if gcc -print-prog-name=ld gives a path.
- AC_MSG_CHECKING([for ld used by $CC])
- case $host in
- *-*-mingw*)
- # gcc leaves a trailing carriage return which upsets mingw
- ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
- *)
- ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
- esac
- case $ac_prog in
- # Accept absolute paths.
- [[\\/]]* | ?:[[\\/]]*)
- re_direlt='/[[^/]][[^/]]*/\.\./'
- # Canonicalize the pathname of ld
- ac_prog=`echo $ac_prog| $SED 's%\\\\%/%g'`
- while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do
- ac_prog=`echo $ac_prog| $SED "s%$re_direlt%/%"`
- done
- test -z "$LD" && LD="$ac_prog"
- ;;
- "")
- # If it fails, then pretend we aren't using GCC.
- ac_prog=ld
- ;;
- *)
- # If it is relative, then search for the first ld in PATH.
- with_gnu_ld=unknown
- ;;
- esac
-elif test "$with_gnu_ld" = yes; then
- AC_MSG_CHECKING([for GNU ld])
-else
- AC_MSG_CHECKING([for non-GNU ld])
-fi
-AC_CACHE_VAL(lt_cv_path_LD,
-[if test -z "$LD"; then
- lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
- for ac_dir in $PATH; do
- IFS="$lt_save_ifs"
- test -z "$ac_dir" && ac_dir=.
- if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
- lt_cv_path_LD="$ac_dir/$ac_prog"
- # Check to see if the program is GNU ld. I'd rather use --version,
- # but apparently some GNU ld's only accept -v.
- # Break only if it was the GNU/non-GNU ld that we prefer.
- case `"$lt_cv_path_LD" -v 2>&1 </dev/null` in
- *GNU* | *'with BFD'*)
- test "$with_gnu_ld" != no && break
- ;;
- *)
- test "$with_gnu_ld" != yes && break
- ;;
- esac
- fi
- done
- IFS="$lt_save_ifs"
-else
- lt_cv_path_LD="$LD" # Let the user override the test with a path.
-fi])
-LD="$lt_cv_path_LD"
-if test -n "$LD"; then
- AC_MSG_RESULT($LD)
-else
- AC_MSG_RESULT(no)
-fi
-test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH])
-AC_PROG_LD_GNU
-])# AC_PROG_LD
-
-
-# AC_PROG_LD_GNU
-# --------------
-AC_DEFUN([AC_PROG_LD_GNU],
-[AC_REQUIRE([AC_PROG_EGREP])dnl
-AC_CACHE_CHECK([if the linker ($LD) is GNU ld], lt_cv_prog_gnu_ld,
-[# I'd rather use --version here, but apparently some GNU ld's only accept -v.
-case `$LD -v 2>&1 </dev/null` in
-*GNU* | *'with BFD'*)
- lt_cv_prog_gnu_ld=yes
- ;;
-*)
- lt_cv_prog_gnu_ld=no
- ;;
-esac])
-with_gnu_ld=$lt_cv_prog_gnu_ld
-])# AC_PROG_LD_GNU
-
-
-# AC_PROG_LD_RELOAD_FLAG
-# ----------------------
-# find reload flag for linker
-# -- PORTME Some linkers may need a different reload flag.
-AC_DEFUN([AC_PROG_LD_RELOAD_FLAG],
-[AC_CACHE_CHECK([for $LD option to reload object files],
- lt_cv_ld_reload_flag,
- [lt_cv_ld_reload_flag='-r'])
-reload_flag=$lt_cv_ld_reload_flag
-case $reload_flag in
-"" | " "*) ;;
-*) reload_flag=" $reload_flag" ;;
-esac
-reload_cmds='$LD$reload_flag -o $output$reload_objs'
-case $host_os in
- darwin*)
- if test "$GCC" = yes; then
- reload_cmds='$CC -nostdlib ${wl}-r -o $output$reload_objs'
- else
- reload_cmds='$LD$reload_flag -o $output$reload_objs'
- fi
- ;;
-esac
-])# AC_PROG_LD_RELOAD_FLAG
-
-
-# AC_DEPLIBS_CHECK_METHOD
-# -----------------------
-# how to check for library dependencies
-# -- PORTME fill in with the dynamic library characteristics
-AC_DEFUN([AC_DEPLIBS_CHECK_METHOD],
-[AC_CACHE_CHECK([how to recognise dependent libraries],
-lt_cv_deplibs_check_method,
-[lt_cv_file_magic_cmd='$MAGIC_CMD'
-lt_cv_file_magic_test_file=
-lt_cv_deplibs_check_method='unknown'
-# Need to set the preceding variable on all platforms that support
-# interlibrary dependencies.
-# 'none' -- dependencies not supported.
-# `unknown' -- same as none, but documents that we really don't know.
-# 'pass_all' -- all dependencies passed with no checks.
-# 'test_compile' -- check by making test program.
-# 'file_magic [[regex]]' -- check by looking for files in library path
-# which responds to the $file_magic_cmd with a given extended regex.
-# If you have `file' or equivalent on your system and you're not sure
-# whether `pass_all' will *always* work, you probably want this one.
-
-case $host_os in
-aix4* | aix5*)
- lt_cv_deplibs_check_method=pass_all
- ;;
-
-beos*)
- lt_cv_deplibs_check_method=pass_all
- ;;
-
-bsdi[[45]]*)
- lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib)'
- lt_cv_file_magic_cmd='/usr/bin/file -L'
- lt_cv_file_magic_test_file=/shlib/libc.so
- ;;
-
-cygwin*)
- # func_win32_libid is a shell function defined in ltmain.sh
- lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
- lt_cv_file_magic_cmd='func_win32_libid'
- ;;
-
-mingw* | pw32*)
- # Base MSYS/MinGW do not provide the 'file' command needed by
- # func_win32_libid shell function, so use a weaker test based on 'objdump'.
- lt_cv_deplibs_check_method='file_magic file format pei*-i386(.*architecture: i386)?'
- lt_cv_file_magic_cmd='$OBJDUMP -f'
- ;;
-
-darwin* | rhapsody*)
- lt_cv_deplibs_check_method=pass_all
- ;;
-
-freebsd* | kfreebsd*-gnu | dragonfly*)
- if echo __ELF__ | $CC -E - | grep __ELF__ > /dev/null; then
- case $host_cpu in
- i*86 )
- # Not sure whether the presence of OpenBSD here was a mistake.
- # Let's accept both of them until this is cleared up.
- lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[[3-9]]86 (compact )?demand paged shared library'
- lt_cv_file_magic_cmd=/usr/bin/file
- lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*`
- ;;
- esac
- else
- lt_cv_deplibs_check_method=pass_all
- fi
- ;;
-
-gnu*)
- lt_cv_deplibs_check_method=pass_all
- ;;
-
-hpux10.20* | hpux11*)
- lt_cv_file_magic_cmd=/usr/bin/file
- case "$host_cpu" in
- ia64*)
- lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|ELF-[[0-9]][[0-9]]) shared object file - IA64'
- lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so
- ;;
- hppa*64*)
- [lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - PA-RISC [0-9].[0-9]']
- lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl
- ;;
- *)
- lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|PA-RISC[[0-9]].[[0-9]]) shared library'
- lt_cv_file_magic_test_file=/usr/lib/libc.sl
- ;;
- esac
- ;;
-
-irix5* | irix6* | nonstopux*)
- case $LD in
- *-32|*"-32 ") libmagic=32-bit;;
- *-n32|*"-n32 ") libmagic=N32;;
- *-64|*"-64 ") libmagic=64-bit;;
- *) libmagic=never-match;;
- esac
- lt_cv_deplibs_check_method=pass_all
- ;;
-
-# This must be Linux ELF.
-linux*)
- lt_cv_deplibs_check_method=pass_all
- ;;
-
-netbsd*)
- if echo __ELF__ | $CC -E - | grep __ELF__ > /dev/null; then
- lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$'
- else
- lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|_pic\.a)$'
- fi
- ;;
-
-newos6*)
- lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (executable|dynamic lib)'
- lt_cv_file_magic_cmd=/usr/bin/file
- lt_cv_file_magic_test_file=/usr/lib/libnls.so
- ;;
-
-nto-qnx*)
- lt_cv_deplibs_check_method=unknown
- ;;
-
-openbsd*)
- if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
- lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|\.so|_pic\.a)$'
- else
- lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$'
- fi
- ;;
-
-osf3* | osf4* | osf5*)
- lt_cv_deplibs_check_method=pass_all
- ;;
-
-sco3.2v5*)
- lt_cv_deplibs_check_method=pass_all
- ;;
-
-solaris*)
- lt_cv_deplibs_check_method=pass_all
- ;;
-
-sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*)
- case $host_vendor in
- motorola)
- lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib) M[[0-9]][[0-9]]* Version [[0-9]]'
- lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*`
- ;;
- ncr)
- lt_cv_deplibs_check_method=pass_all
- ;;
- sequent)
- lt_cv_file_magic_cmd='/bin/file'
- lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB (shared object|dynamic lib )'
- ;;
- sni)
- lt_cv_file_magic_cmd='/bin/file'
- lt_cv_deplibs_check_method="file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB dynamic lib"
- lt_cv_file_magic_test_file=/lib/libc.so
- ;;
- siemens)
- lt_cv_deplibs_check_method=pass_all
- ;;
- esac
- ;;
-
-sysv5OpenUNIX8* | sysv5UnixWare7* | sysv5uw[[78]]* | unixware7* | sysv4*uw2*)
- lt_cv_deplibs_check_method=pass_all
- ;;
-esac
-])
-file_magic_cmd=$lt_cv_file_magic_cmd
-deplibs_check_method=$lt_cv_deplibs_check_method
-test -z "$deplibs_check_method" && deplibs_check_method=unknown
-])# AC_DEPLIBS_CHECK_METHOD
-
-
-# AC_PROG_NM
-# ----------
-# find the pathname to a BSD-compatible name lister
-AC_DEFUN([AC_PROG_NM],
-[AC_CACHE_CHECK([for BSD-compatible nm], lt_cv_path_NM,
-[if test -n "$NM"; then
- # Let the user override the test.
- lt_cv_path_NM="$NM"
-else
- lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
- for ac_dir in $PATH /usr/ccs/bin /usr/ucb /bin; do
- IFS="$lt_save_ifs"
- test -z "$ac_dir" && ac_dir=.
- tmp_nm="$ac_dir/${ac_tool_prefix}nm"
- if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext" ; then
- # Check to see if the nm accepts a BSD-compat flag.
- # Adding the `sed 1q' prevents false positives on HP-UX, which says:
- # nm: unknown option "B" ignored
- # Tru64's nm complains that /dev/null is an invalid object file
- case `"$tmp_nm" -B /dev/null 2>&1 | sed '1q'` in
- */dev/null* | *'Invalid file or object type'*)
- lt_cv_path_NM="$tmp_nm -B"
- break
- ;;
- *)
- case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in
- */dev/null*)
- lt_cv_path_NM="$tmp_nm -p"
- break
- ;;
- *)
- lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but
- continue # so that we can try to find one that supports BSD flags
- ;;
- esac
- esac
- fi
- done
- IFS="$lt_save_ifs"
- test -z "$lt_cv_path_NM" && lt_cv_path_NM=nm
-fi])
-NM="$lt_cv_path_NM"
-])# AC_PROG_NM
-
-
-# AC_CHECK_LIBM
-# -------------
-# check for math library
-AC_DEFUN([AC_CHECK_LIBM],
-[AC_REQUIRE([AC_CANONICAL_HOST])dnl
-LIBM=
-case $host in
-*-*-beos* | *-*-cygwin* | *-*-pw32* | *-*-darwin*)
- # These system don't have libm, or don't need it
- ;;
-*-ncr-sysv4.3*)
- AC_CHECK_LIB(mw, _mwvalidcheckl, LIBM="-lmw")
- AC_CHECK_LIB(m, cos, LIBM="$LIBM -lm")
- ;;
-*)
- AC_CHECK_LIB(m, cos, LIBM="-lm")
- ;;
-esac
-])# AC_CHECK_LIBM
-
-
-# AC_LIBLTDL_CONVENIENCE([DIRECTORY])
-# -----------------------------------
-# sets LIBLTDL to the link flags for the libltdl convenience library and
-# LTDLINCL to the include flags for the libltdl header and adds
-# --enable-ltdl-convenience to the configure arguments. Note that LIBLTDL
-# and LTDLINCL are not AC_SUBSTed, nor is AC_CONFIG_SUBDIRS called. If
-# DIRECTORY is not provided, it is assumed to be `libltdl'. LIBLTDL will
-# be prefixed with '${top_builddir}/' and LTDLINCL will be prefixed with
-# '${top_srcdir}/' (note the single quotes!). If your package is not
-# flat and you're not using automake, define top_builddir and
-# top_srcdir appropriately in the Makefiles.
-AC_DEFUN([AC_LIBLTDL_CONVENIENCE],
-[AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
- case $enable_ltdl_convenience in
- no) AC_MSG_ERROR([this package needs a convenience libltdl]) ;;
- "") enable_ltdl_convenience=yes
- ac_configure_args="$ac_configure_args --enable-ltdl-convenience" ;;
- esac
- LIBLTDL='${top_builddir}/'ifelse($#,1,[$1],['libltdl'])/libltdlc.la
- LTDLINCL='-I${top_srcdir}/'ifelse($#,1,[$1],['libltdl'])
- # For backwards non-gettext consistent compatibility...
- INCLTDL="$LTDLINCL"
-])# AC_LIBLTDL_CONVENIENCE
-
-
-# AC_LIBLTDL_INSTALLABLE([DIRECTORY])
-# -----------------------------------
-# sets LIBLTDL to the link flags for the libltdl installable library and
-# LTDLINCL to the include flags for the libltdl header and adds
-# --enable-ltdl-install to the configure arguments. Note that LIBLTDL
-# and LTDLINCL are not AC_SUBSTed, nor is AC_CONFIG_SUBDIRS called. If
-# DIRECTORY is not provided and an installed libltdl is not found, it is
-# assumed to be `libltdl'. LIBLTDL will be prefixed with '${top_builddir}/'
-# and LTDLINCL will be prefixed with '${top_srcdir}/' (note the single
-# quotes!). If your package is not flat and you're not using automake,
-# define top_builddir and top_srcdir appropriately in the Makefiles.
-# In the future, this macro may have to be called after AC_PROG_LIBTOOL.
-AC_DEFUN([AC_LIBLTDL_INSTALLABLE],
-[AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
- AC_CHECK_LIB(ltdl, lt_dlinit,
- [test x"$enable_ltdl_install" != xyes && enable_ltdl_install=no],
- [if test x"$enable_ltdl_install" = xno; then
- AC_MSG_WARN([libltdl not installed, but installation disabled])
- else
- enable_ltdl_install=yes
- fi
- ])
- if test x"$enable_ltdl_install" = x"yes"; then
- ac_configure_args="$ac_configure_args --enable-ltdl-install"
- LIBLTDL='${top_builddir}/'ifelse($#,1,[$1],['libltdl'])/libltdl.la
- LTDLINCL='-I${top_srcdir}/'ifelse($#,1,[$1],['libltdl'])
- else
- ac_configure_args="$ac_configure_args --enable-ltdl-install=no"
- LIBLTDL="-lltdl"
- LTDLINCL=
- fi
- # For backwards non-gettext consistent compatibility...
- INCLTDL="$LTDLINCL"
-])# AC_LIBLTDL_INSTALLABLE
-
-
-# AC_LIBTOOL_CXX
-# --------------
-# enable support for C++ libraries
-AC_DEFUN([AC_LIBTOOL_CXX],
-[AC_REQUIRE([_LT_AC_LANG_CXX])
-])# AC_LIBTOOL_CXX
-
-
-# _LT_AC_LANG_CXX
-# ---------------
-AC_DEFUN([_LT_AC_LANG_CXX],
-[AC_REQUIRE([AC_PROG_CXX])
-AC_REQUIRE([_LT_AC_PROG_CXXCPP])
-_LT_AC_SHELL_INIT([tagnames=${tagnames+${tagnames},}CXX])
-])# _LT_AC_LANG_CXX
-
-# _LT_AC_PROG_CXXCPP
-# ---------------
-AC_DEFUN([_LT_AC_PROG_CXXCPP],
-[
-AC_REQUIRE([AC_PROG_CXX])
-if test -n "$CXX" && ( test "X$CXX" != "Xno" &&
- ( (test "X$CXX" = "Xg++" && `g++ -v >/dev/null 2>&1` ) ||
- (test "X$CXX" != "Xg++"))) ; then
- AC_PROG_CXXCPP
-fi
-])# _LT_AC_PROG_CXXCPP
-
-# AC_LIBTOOL_F77
-# --------------
-# enable support for Fortran 77 libraries
-AC_DEFUN([AC_LIBTOOL_F77],
-[AC_REQUIRE([_LT_AC_LANG_F77])
-])# AC_LIBTOOL_F77
-
-
-# _LT_AC_LANG_F77
-# ---------------
-AC_DEFUN([_LT_AC_LANG_F77],
-[AC_REQUIRE([AC_PROG_F77])
-_LT_AC_SHELL_INIT([tagnames=${tagnames+${tagnames},}F77])
-])# _LT_AC_LANG_F77
-
-
-# AC_LIBTOOL_GCJ
-# --------------
-# enable support for GCJ libraries
-AC_DEFUN([AC_LIBTOOL_GCJ],
-[AC_REQUIRE([_LT_AC_LANG_GCJ])
-])# AC_LIBTOOL_GCJ
-
-
-# _LT_AC_LANG_GCJ
-# ---------------
-AC_DEFUN([_LT_AC_LANG_GCJ],
-[AC_PROVIDE_IFELSE([AC_PROG_GCJ],[],
- [AC_PROVIDE_IFELSE([A][M_PROG_GCJ],[],
- [AC_PROVIDE_IFELSE([LT_AC_PROG_GCJ],[],
- [ifdef([AC_PROG_GCJ],[AC_REQUIRE([AC_PROG_GCJ])],
- [ifdef([A][M_PROG_GCJ],[AC_REQUIRE([A][M_PROG_GCJ])],
- [AC_REQUIRE([A][C_PROG_GCJ_OR_A][M_PROG_GCJ])])])])])])
-_LT_AC_SHELL_INIT([tagnames=${tagnames+${tagnames},}GCJ])
-])# _LT_AC_LANG_GCJ
-
-
-# AC_LIBTOOL_RC
-# --------------
-# enable support for Windows resource files
-AC_DEFUN([AC_LIBTOOL_RC],
-[AC_REQUIRE([LT_AC_PROG_RC])
-_LT_AC_SHELL_INIT([tagnames=${tagnames+${tagnames},}RC])
-])# AC_LIBTOOL_RC
-
-
-# AC_LIBTOOL_LANG_C_CONFIG
-# ------------------------
-# Ensure that the configuration vars for the C compiler are
-# suitably defined. Those variables are subsequently used by
-# AC_LIBTOOL_CONFIG to write the compiler configuration to `libtool'.
-AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG], [_LT_AC_LANG_C_CONFIG])
-AC_DEFUN([_LT_AC_LANG_C_CONFIG],
-[lt_save_CC="$CC"
-AC_LANG_PUSH(C)
-
-# Source file extension for C test sources.
-ac_ext=c
-
-# Object file extension for compiled C test sources.
-objext=o
-_LT_AC_TAGVAR(objext, $1)=$objext
-
-# Code to be used in simple compile tests
-lt_simple_compile_test_code="int some_variable = 0;\n"
-
-# Code to be used in simple link tests
-lt_simple_link_test_code='int main(){return(0);}\n'
-
-_LT_AC_SYS_COMPILER
-
-# save warnings/boilerplate of simple test code
-_LT_COMPILER_BOILERPLATE
-_LT_LINKER_BOILERPLATE
-
-#
-# Check for any special shared library compilation flags.
-#
-_LT_AC_TAGVAR(lt_prog_cc_shlib, $1)=
-if test "$GCC" = no; then
- case $host_os in
- sco3.2v5*)
- _LT_AC_TAGVAR(lt_prog_cc_shlib, $1)='-belf'
- ;;
- esac
-fi
-if test -n "$_LT_AC_TAGVAR(lt_prog_cc_shlib, $1)"; then
- AC_MSG_WARN([`$CC' requires `$_LT_AC_TAGVAR(lt_prog_cc_shlib, $1)' to build shared libraries])
- if echo "$old_CC $old_CFLAGS " | grep "[[ ]]$_LT_AC_TAGVAR(lt_prog_cc_shlib, $1)[[ ]]" >/dev/null; then :
- else
- AC_MSG_WARN([add `$_LT_AC_TAGVAR(lt_prog_cc_shlib, $1)' to the CC or CFLAGS env variable and reconfigure])
- _LT_AC_TAGVAR(lt_cv_prog_cc_can_build_shared, $1)=no
- fi
-fi
-
-
-#
-# Check to make sure the static flag actually works.
-#
-AC_LIBTOOL_LINKER_OPTION([if $compiler static flag $_LT_AC_TAGVAR(lt_prog_compiler_static, $1) works],
- _LT_AC_TAGVAR(lt_prog_compiler_static_works, $1),
- $_LT_AC_TAGVAR(lt_prog_compiler_static, $1),
- [],
- [_LT_AC_TAGVAR(lt_prog_compiler_static, $1)=])
-
-
-## CAVEAT EMPTOR:
-## There is no encapsulation within the following macros, do not change
-## the running order or otherwise move them around unless you know exactly
-## what you are doing...
-AC_LIBTOOL_PROG_COMPILER_NO_RTTI($1)
-AC_LIBTOOL_PROG_COMPILER_PIC($1)
-AC_LIBTOOL_PROG_CC_C_O($1)
-AC_LIBTOOL_SYS_HARD_LINK_LOCKS($1)
-AC_LIBTOOL_PROG_LD_SHLIBS($1)
-AC_LIBTOOL_SYS_DYNAMIC_LINKER($1)
-AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH($1)
-AC_LIBTOOL_SYS_LIB_STRIP
-AC_LIBTOOL_DLOPEN_SELF($1)
-
-# Report which librarie types wil actually be built
-AC_MSG_CHECKING([if libtool supports shared libraries])
-AC_MSG_RESULT([$can_build_shared])
-
-AC_MSG_CHECKING([whether to build shared libraries])
-test "$can_build_shared" = "no" && enable_shared=no
-
-# On AIX, shared libraries and static libraries use the same namespace, and
-# are all built from PIC.
-case "$host_os" in
-aix3*)
- test "$enable_shared" = yes && enable_static=no
- if test -n "$RANLIB"; then
- archive_cmds="$archive_cmds~\$RANLIB \$lib"
- postinstall_cmds='$RANLIB $lib'
- fi
- ;;
-
-aix4* | aix5*)
- if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then
- test "$enable_shared" = yes && enable_static=no
- fi
- ;;
-esac
-AC_MSG_RESULT([$enable_shared])
-
-AC_MSG_CHECKING([whether to build static libraries])
-# Make sure either enable_shared or enable_static is yes.
-test "$enable_shared" = yes || enable_static=yes
-AC_MSG_RESULT([$enable_static])
-
-AC_LIBTOOL_CONFIG($1)
-
-AC_LANG_POP
-CC="$lt_save_CC"
-])# AC_LIBTOOL_LANG_C_CONFIG
-
-
-# AC_LIBTOOL_LANG_CXX_CONFIG
-# --------------------------
-# Ensure that the configuration vars for the C compiler are
-# suitably defined. Those variables are subsequently used by
-# AC_LIBTOOL_CONFIG to write the compiler configuration to `libtool'.
-AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG], [_LT_AC_LANG_CXX_CONFIG(CXX)])
-AC_DEFUN([_LT_AC_LANG_CXX_CONFIG],
-[AC_LANG_PUSH(C++)
-AC_REQUIRE([AC_PROG_CXX])
-AC_REQUIRE([_LT_AC_PROG_CXXCPP])
-
-_LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
-_LT_AC_TAGVAR(allow_undefined_flag, $1)=
-_LT_AC_TAGVAR(always_export_symbols, $1)=no
-_LT_AC_TAGVAR(archive_expsym_cmds, $1)=
-_LT_AC_TAGVAR(export_dynamic_flag_spec, $1)=
-_LT_AC_TAGVAR(hardcode_direct, $1)=no
-_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)=
-_LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1)=
-_LT_AC_TAGVAR(hardcode_libdir_separator, $1)=
-_LT_AC_TAGVAR(hardcode_minus_L, $1)=no
-_LT_AC_TAGVAR(hardcode_automatic, $1)=no
-_LT_AC_TAGVAR(module_cmds, $1)=
-_LT_AC_TAGVAR(module_expsym_cmds, $1)=
-_LT_AC_TAGVAR(link_all_deplibs, $1)=unknown
-_LT_AC_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
-_LT_AC_TAGVAR(no_undefined_flag, $1)=
-_LT_AC_TAGVAR(whole_archive_flag_spec, $1)=
-_LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1)=no
-
-# Dependencies to place before and after the object being linked:
-_LT_AC_TAGVAR(predep_objects, $1)=
-_LT_AC_TAGVAR(postdep_objects, $1)=
-_LT_AC_TAGVAR(predeps, $1)=
-_LT_AC_TAGVAR(postdeps, $1)=
-_LT_AC_TAGVAR(compiler_lib_search_path, $1)=
-
-# Source file extension for C++ test sources.
-ac_ext=cc
-
-# Object file extension for compiled C++ test sources.
-objext=o
-_LT_AC_TAGVAR(objext, $1)=$objext
-
-# Code to be used in simple compile tests
-lt_simple_compile_test_code="int some_variable = 0;\n"
-
-# Code to be used in simple link tests
-lt_simple_link_test_code='int main(int, char *[]) { return(0); }\n'
-
-# ltmain only uses $CC for tagged configurations so make sure $CC is set.
-_LT_AC_SYS_COMPILER
-
-# save warnings/boilerplate of simple test code
-_LT_COMPILER_BOILERPLATE
-_LT_LINKER_BOILERPLATE
-
-# Allow CC to be a program name with arguments.
-lt_save_CC=$CC
-lt_save_LD=$LD
-lt_save_GCC=$GCC
-GCC=$GXX
-lt_save_with_gnu_ld=$with_gnu_ld
-lt_save_path_LD=$lt_cv_path_LD
-if test -n "${lt_cv_prog_gnu_ldcxx+set}"; then
- lt_cv_prog_gnu_ld=$lt_cv_prog_gnu_ldcxx
-else
- unset lt_cv_prog_gnu_ld
-fi
-if test -n "${lt_cv_path_LDCXX+set}"; then
- lt_cv_path_LD=$lt_cv_path_LDCXX
-else
- unset lt_cv_path_LD
-fi
-test -z "${LDCXX+set}" || LD=$LDCXX
-CC=${CXX-"c++"}
-compiler=$CC
-_LT_AC_TAGVAR(compiler, $1)=$CC
-_LT_CC_BASENAME([$compiler])
-
-# We don't want -fno-exception wen compiling C++ code, so set the
-# no_builtin_flag separately
-if test "$GXX" = yes; then
- _LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin'
-else
- _LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=
-fi
-
-if test "$GXX" = yes; then
- # Set up default GNU C++ configuration
-
- AC_PROG_LD
-
- # Check if GNU C++ uses GNU ld as the underlying linker, since the
- # archiving commands below assume that GNU ld is being used.
- if test "$with_gnu_ld" = yes; then
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib'
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
-
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}--rpath ${wl}$libdir'
- _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
-
- # If archive_cmds runs LD, not CC, wlarc should be empty
- # XXX I think wlarc can be eliminated in ltcf-cxx, but I need to
- # investigate it a little bit more. (MM)
- wlarc='${wl}'
-
- # ancient GNU ld didn't support --whole-archive et. al.
- if eval "`$CC -print-prog-name=ld` --help 2>&1" | \
- grep 'no-whole-archive' > /dev/null; then
- _LT_AC_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
- else
- _LT_AC_TAGVAR(whole_archive_flag_spec, $1)=
- fi
- else
- with_gnu_ld=no
- wlarc=
-
- # A generic and very simple default shared library creation
- # command for GNU C++ for the case where it uses the native
- # linker, instead of GNU ld. If possible, this setting should
- # overridden to take advantage of the native linker features on
- # the platform it is being used on.
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib'
- fi
-
- # Commands to make compiler produce verbose output that lists
- # what "hidden" libraries, object files and flags are used when
- # linking a shared library.
- output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "\-L"'
-
-else
- GXX=no
- with_gnu_ld=no
- wlarc=
-fi
-
-# PORTME: fill in a description of your system's C++ link characteristics
-AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries])
-_LT_AC_TAGVAR(ld_shlibs, $1)=yes
-case $host_os in
- aix3*)
- # FIXME: insert proper C++ library support
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- ;;
- aix4* | aix5*)
- if test "$host_cpu" = ia64; then
- # On IA64, the linker does run time linking by default, so we don't
- # have to do anything special.
- aix_use_runtimelinking=no
- exp_sym_flag='-Bexport'
- no_entry_flag=""
- else
- aix_use_runtimelinking=no
-
- # Test if we are trying to use run time linking or normal
- # AIX style linking. If -brtl is somewhere in LDFLAGS, we
- # need to do runtime linking.
- case $host_os in aix4.[[23]]|aix4.[[23]].*|aix5*)
- for ld_flag in $LDFLAGS; do
- case $ld_flag in
- *-brtl*)
- aix_use_runtimelinking=yes
- break
- ;;
- esac
- done
- esac
-
- exp_sym_flag='-bexport'
- no_entry_flag='-bnoentry'
- fi
-
- # When large executables or shared objects are built, AIX ld can
- # have problems creating the table of contents. If linking a library
- # or program results in "error TOC overflow" add -mminimal-toc to
- # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not
- # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS.
-
- _LT_AC_TAGVAR(archive_cmds, $1)=''
- _LT_AC_TAGVAR(hardcode_direct, $1)=yes
- _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=':'
- _LT_AC_TAGVAR(link_all_deplibs, $1)=yes
-
- if test "$GXX" = yes; then
- case $host_os in aix4.[[012]]|aix4.[[012]].*)
- # We only want to do this on AIX 4.2 and lower, the check
- # below for broken collect2 doesn't work under 4.3+
- collect2name=`${CC} -print-prog-name=collect2`
- if test -f "$collect2name" && \
- strings "$collect2name" | grep resolve_lib_name >/dev/null
- then
- # We have reworked collect2
- _LT_AC_TAGVAR(hardcode_direct, $1)=yes
- else
- # We have old collect2
- _LT_AC_TAGVAR(hardcode_direct, $1)=unsupported
- # It fails to find uninstalled libraries when the uninstalled
- # path is not listed in the libpath. Setting hardcode_minus_L
- # to unsupported forces relinking
- _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
- _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=
- fi
- esac
- shared_flag='-shared'
- if test "$aix_use_runtimelinking" = yes; then
- shared_flag="$shared_flag "'${wl}-G'
- fi
- else
- # not using gcc
- if test "$host_cpu" = ia64; then
- # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release
- # chokes on -Wl,-G. The following line is correct:
- shared_flag='-G'
- else
- if test "$aix_use_runtimelinking" = yes; then
- shared_flag='${wl}-G'
- else
- shared_flag='${wl}-bM:SRE'
- fi
- fi
- fi
-
- # It seems that -bexpall does not export symbols beginning with
- # underscore (_), so it is better to generate a list of symbols to export.
- _LT_AC_TAGVAR(always_export_symbols, $1)=yes
- if test "$aix_use_runtimelinking" = yes; then
- # Warning - without using the other runtime loading flags (-brtl),
- # -berok will link without error, but may produce a broken library.
- _LT_AC_TAGVAR(allow_undefined_flag, $1)='-berok'
- # Determine the default libpath from the value encoded in an empty executable.
- _LT_AC_SYS_LIBPATH_AIX
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
-
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)="\$CC"' -o $output_objdir/$soname $libobjs $deplibs $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then echo "${wl}${allow_undefined_flag}"; else :; fi` '"\${wl}$no_entry_flag \${wl}$exp_sym_flag:\$export_symbols $shared_flag"
- else
- if test "$host_cpu" = ia64; then
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib'
- _LT_AC_TAGVAR(allow_undefined_flag, $1)="-z nodefs"
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$no_entry_flag \${wl}$exp_sym_flag:\$export_symbols"
- else
- # Determine the default libpath from the value encoded in an empty executable.
- _LT_AC_SYS_LIBPATH_AIX
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
- # Warning - without using the other run time loading flags,
- # -berok will link without error, but may produce a broken library.
- _LT_AC_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok'
- _LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok'
- # -bexpall does not export symbols beginning with underscore (_)
- _LT_AC_TAGVAR(always_export_symbols, $1)=yes
- # Exported symbols can be pulled into shared objects from archives
- _LT_AC_TAGVAR(whole_archive_flag_spec, $1)=' '
- _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=yes
- # This is similar to how AIX traditionally builds it's shared libraries.
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs $compiler_flags ${wl}-bE:$export_symbols ${wl}-bnoentry${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname'
- fi
- fi
- ;;
- chorus*)
- case $cc_basename in
- *)
- # FIXME: insert proper C++ library support
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- ;;
- esac
- ;;
-
-
- cygwin* | mingw* | pw32*)
- # _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless,
- # as there is no search path for DLLs.
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
- _LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported
- _LT_AC_TAGVAR(always_export_symbols, $1)=no
- _LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1)=yes
-
- if $LD --help 2>&1 | grep 'auto-import' > /dev/null; then
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--image-base=0x10000000 ${wl}--out-implib,$lib'
- # If the export-symbols file already is a .def file (1st line
- # is EXPORTS), use it as is; otherwise, prepend...
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
- cp $export_symbols $output_objdir/$soname.def;
- else
- echo EXPORTS > $output_objdir/$soname.def;
- cat $export_symbols >> $output_objdir/$soname.def;
- fi~
- $CC -shared -nostdlib $output_objdir/$soname.def $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--image-base=0x10000000 ${wl}--out-implib,$lib'
- else
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- fi
- ;;
- darwin* | rhapsody*)
- case "$host_os" in
- rhapsody* | darwin1.[[012]])
- _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-undefined ${wl}suppress'
- ;;
- *) # Darwin 1.3 on
- if test -z ${MACOSX_DEPLOYMENT_TARGET} ; then
- _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-flat_namespace ${wl}-undefined ${wl}suppress'
- else
- case ${MACOSX_DEPLOYMENT_TARGET} in
- 10.[[012]])
- _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-flat_namespace ${wl}-undefined ${wl}suppress'
- ;;
- 10.*)
- _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-undefined ${wl}dynamic_lookup'
- ;;
- esac
- fi
- ;;
- esac
- _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
- _LT_AC_TAGVAR(hardcode_direct, $1)=no
- _LT_AC_TAGVAR(hardcode_automatic, $1)=yes
- _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=unsupported
- _LT_AC_TAGVAR(whole_archive_flag_spec, $1)=''
- _LT_AC_TAGVAR(link_all_deplibs, $1)=yes
-
- if test "$GXX" = yes ; then
- lt_int_apple_cc_single_mod=no
- output_verbose_link_cmd='echo'
- if $CC -dumpspecs 2>&1 | $EGREP 'single_module' >/dev/null ; then
- lt_int_apple_cc_single_mod=yes
- fi
- if test "X$lt_int_apple_cc_single_mod" = Xyes ; then
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -dynamiclib -single_module $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags -install_name $rpath/$soname $verstring'
- else
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -r -keep_private_externs -nostdlib -o ${lib}-master.o $libobjs~$CC -dynamiclib $allow_undefined_flag -o $lib ${lib}-master.o $deplibs $compiler_flags -install_name $rpath/$soname $verstring'
- fi
- _LT_AC_TAGVAR(module_cmds, $1)='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags'
- # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin ld's
- if test "X$lt_int_apple_cc_single_mod" = Xyes ; then
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -dynamiclib -single_module $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags -install_name $rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
- else
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -r -keep_private_externs -nostdlib -o ${lib}-master.o $libobjs~$CC -dynamiclib $allow_undefined_flag -o $lib ${lib}-master.o $deplibs $compiler_flags -install_name $rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
- fi
- _LT_AC_TAGVAR(module_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
- else
- case $cc_basename in
- xlc*)
- output_verbose_link_cmd='echo'
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -qmkshrobj ${wl}-single_module $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}`echo $rpath/$soname` $verstring'
- _LT_AC_TAGVAR(module_cmds, $1)='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags'
- # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin ld's
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -qmkshrobj ${wl}-single_module $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}$rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
- _LT_AC_TAGVAR(module_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
- ;;
- *)
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- ;;
- esac
- fi
- ;;
-
- dgux*)
- case $cc_basename in
- ec++*)
- # FIXME: insert proper C++ library support
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- ;;
- ghcx*)
- # Green Hills C++ Compiler
- # FIXME: insert proper C++ library support
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- ;;
- *)
- # FIXME: insert proper C++ library support
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- ;;
- esac
- ;;
- freebsd[[12]]*)
- # C++ shared libraries reported to be fairly broken before switch to ELF
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- ;;
- freebsd-elf*)
- _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
- ;;
- freebsd* | kfreebsd*-gnu | dragonfly*)
- # FreeBSD 3 and later use GNU C++ and GNU ld with standard ELF
- # conventions
- _LT_AC_TAGVAR(ld_shlibs, $1)=yes
- ;;
- gnu*)
- ;;
- hpux9*)
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
- _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
- _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
- _LT_AC_TAGVAR(hardcode_direct, $1)=yes
- _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH,
- # but as the default
- # location of the library.
-
- case $cc_basename in
- CC*)
- # FIXME: insert proper C++ library support
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- ;;
- aCC*)
- _LT_AC_TAGVAR(archive_cmds, $1)='$rm $output_objdir/$soname~$CC -b ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
- # Commands to make compiler produce verbose output that lists
- # what "hidden" libraries, object files and flags are used when
- # linking a shared library.
- #
- # There doesn't appear to be a way to prevent this compiler from
- # explicitly linking system object files so we need to strip them
- # from the output so that they don't get included in the library
- # dependencies.
- output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | grep "[[-]]L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list'
- ;;
- *)
- if test "$GXX" = yes; then
- _LT_AC_TAGVAR(archive_cmds, $1)='$rm $output_objdir/$soname~$CC -shared -nostdlib -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
- else
- # FIXME: insert proper C++ library support
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- fi
- ;;
- esac
- ;;
- hpux10*|hpux11*)
- if test $with_gnu_ld = no; then
- case "$host_cpu" in
- hppa*64*)
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1)='+b $libdir'
- _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
- ;;
- ia64*)
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
- ;;
- *)
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
- _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
- _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
- ;;
- esac
- fi
- case "$host_cpu" in
- hppa*64*)
- _LT_AC_TAGVAR(hardcode_direct, $1)=no
- _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
- ;;
- ia64*)
- _LT_AC_TAGVAR(hardcode_direct, $1)=no
- _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
- _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH,
- # but as the default
- # location of the library.
- ;;
- *)
- _LT_AC_TAGVAR(hardcode_direct, $1)=yes
- _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH,
- # but as the default
- # location of the library.
- ;;
- esac
-
- case $cc_basename in
- CC*)
- # FIXME: insert proper C++ library support
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- ;;
- aCC*)
- case "$host_cpu" in
- hppa*64*|ia64*)
- _LT_AC_TAGVAR(archive_cmds, $1)='$LD -b +h $soname -o $lib $linker_flags $libobjs $deplibs'
- ;;
- *)
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
- ;;
- esac
- # Commands to make compiler produce verbose output that lists
- # what "hidden" libraries, object files and flags are used when
- # linking a shared library.
- #
- # There doesn't appear to be a way to prevent this compiler from
- # explicitly linking system object files so we need to strip them
- # from the output so that they don't get included in the library
- # dependencies.
- output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | grep "\-L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list'
- ;;
- *)
- if test "$GXX" = yes; then
- if test $with_gnu_ld = no; then
- case "$host_cpu" in
- ia64*|hppa*64*)
- _LT_AC_TAGVAR(archive_cmds, $1)='$LD -b +h $soname -o $lib $linker_flags $libobjs $deplibs'
- ;;
- *)
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
- ;;
- esac
- fi
- else
- # FIXME: insert proper C++ library support
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- fi
- ;;
- esac
- ;;
- irix5* | irix6*)
- case $cc_basename in
- CC*)
- # SGI C++
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -all -multigot $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib'
-
- # Archives containing C++ object files must be created using
- # "CC -ar", where "CC" is the IRIX C++ compiler. This is
- # necessary to make sure instantiated templates are included
- # in the archive.
- _LT_AC_TAGVAR(old_archive_cmds, $1)='$CC -ar -WR,-u -o $oldlib $oldobjs'
- ;;
- *)
- if test "$GXX" = yes; then
- if test "$with_gnu_ld" = no; then
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
- else
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` -o $lib'
- fi
- fi
- _LT_AC_TAGVAR(link_all_deplibs, $1)=yes
- ;;
- esac
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
- _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
- ;;
- linux*)
- case $cc_basename in
- KCC*)
- # Kuck and Associates, Inc. (KAI) C++ Compiler
-
- # KCC will only create a shared library if the output file
- # ends with ".so" (or ".sl" for HP-UX), so rename the library
- # to its proper name (with version) after linking.
- _LT_AC_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib'
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib ${wl}-retain-symbols-file,$export_symbols; mv \$templib $lib'
- # Commands to make compiler produce verbose output that lists
- # what "hidden" libraries, object files and flags are used when
- # linking a shared library.
- #
- # There doesn't appear to be a way to prevent this compiler from
- # explicitly linking system object files so we need to strip them
- # from the output so that they don't get included in the library
- # dependencies.
- output_verbose_link_cmd='templist=`$CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 | grep "ld"`; rm -f libconftest$shared_ext; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list'
-
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}--rpath,$libdir'
- _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
-
- # Archives containing C++ object files must be created using
- # "CC -Bstatic", where "CC" is the KAI C++ compiler.
- _LT_AC_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs'
- ;;
- icpc*)
- # Intel C++
- with_gnu_ld=yes
- # version 8.0 and above of icpc choke on multiply defined symbols
- # if we add $predep_objects and $postdep_objects, however 7.1 and
- # earlier do not add the objects themselves.
- case `$CC -V 2>&1` in
- *"Version 7."*)
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib'
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
- ;;
- *) # Version 8.0 or newer
- tmp_idyn=
- case $host_cpu in
- ia64*) tmp_idyn=' -i_dynamic';;
- esac
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
- ;;
- esac
- _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
- _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
- _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive$convenience ${wl}--no-whole-archive'
- ;;
- pgCC*)
- # Portland Group C++ compiler
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib'
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib'
-
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}--rpath ${wl}$libdir'
- _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
- _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive,`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive'
- ;;
- cxx*)
- # Compaq C++
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib'
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib ${wl}-retain-symbols-file $wl$export_symbols'
-
- runpath_var=LD_RUN_PATH
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir'
- _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
-
- # Commands to make compiler produce verbose output that lists
- # what "hidden" libraries, object files and flags are used when
- # linking a shared library.
- #
- # There doesn't appear to be a way to prevent this compiler from
- # explicitly linking system object files so we need to strip them
- # from the output so that they don't get included in the library
- # dependencies.
- output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "ld"`; templist=`echo $templist | $SED "s/\(^.*ld.*\)\( .*ld .*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list'
- ;;
- esac
- ;;
- lynxos*)
- # FIXME: insert proper C++ library support
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- ;;
- m88k*)
- # FIXME: insert proper C++ library support
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- ;;
- mvs*)
- case $cc_basename in
- cxx*)
- # FIXME: insert proper C++ library support
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- ;;
- *)
- # FIXME: insert proper C++ library support
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- ;;
- esac
- ;;
- netbsd*)
- if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then
- _LT_AC_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $predep_objects $libobjs $deplibs $postdep_objects $linker_flags'
- wlarc=
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
- _LT_AC_TAGVAR(hardcode_direct, $1)=yes
- _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
- fi
- # Workaround some broken pre-1.5 toolchains
- output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep conftest.$objext | $SED -e "s:-lgcc -lc -lgcc::"'
- ;;
- openbsd2*)
- # C++ shared libraries are fairly broken
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- ;;
- openbsd*)
- _LT_AC_TAGVAR(hardcode_direct, $1)=yes
- _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib'
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
- if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file,$export_symbols -o $lib'
- _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
- _LT_AC_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
- fi
- output_verbose_link_cmd='echo'
- ;;
- osf3*)
- case $cc_basename in
- KCC*)
- # Kuck and Associates, Inc. (KAI) C++ Compiler
-
- # KCC will only create a shared library if the output file
- # ends with ".so" (or ".sl" for HP-UX), so rename the library
- # to its proper name (with version) after linking.
- _LT_AC_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib'
-
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
- _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
-
- # Archives containing C++ object files must be created using
- # "CC -Bstatic", where "CC" is the KAI C++ compiler.
- _LT_AC_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs'
-
- ;;
- RCC*)
- # Rational C++ 2.4.1
- # FIXME: insert proper C++ library support
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- ;;
- cxx*)
- _LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $soname `test -n "$verstring" && echo ${wl}-set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib'
-
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
- _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
-
- # Commands to make compiler produce verbose output that lists
- # what "hidden" libraries, object files and flags are used when
- # linking a shared library.
- #
- # There doesn't appear to be a way to prevent this compiler from
- # explicitly linking system object files so we need to strip them
- # from the output so that they don't get included in the library
- # dependencies.
- output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "ld" | grep -v "ld:"`; templist=`echo $templist | $SED "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list'
- ;;
- *)
- if test "$GXX" = yes && test "$with_gnu_ld" = no; then
- _LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
-
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
- _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
-
- # Commands to make compiler produce verbose output that lists
- # what "hidden" libraries, object files and flags are used when
- # linking a shared library.
- output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "\-L"'
-
- else
- # FIXME: insert proper C++ library support
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- fi
- ;;
- esac
- ;;
- osf4* | osf5*)
- case $cc_basename in
- KCC*)
- # Kuck and Associates, Inc. (KAI) C++ Compiler
-
- # KCC will only create a shared library if the output file
- # ends with ".so" (or ".sl" for HP-UX), so rename the library
- # to its proper name (with version) after linking.
- _LT_AC_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib'
-
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
- _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
-
- # Archives containing C++ object files must be created using
- # the KAI C++ compiler.
- _LT_AC_TAGVAR(old_archive_cmds, $1)='$CC -o $oldlib $oldobjs'
- ;;
- RCC*)
- # Rational C++ 2.4.1
- # FIXME: insert proper C++ library support
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- ;;
- cxx*)
- _LT_AC_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*'
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib'
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done~
- echo "-hidden">> $lib.exp~
- $CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname -Wl,-input -Wl,$lib.exp `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib~
- $rm $lib.exp'
-
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir'
- _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
-
- # Commands to make compiler produce verbose output that lists
- # what "hidden" libraries, object files and flags are used when
- # linking a shared library.
- #
- # There doesn't appear to be a way to prevent this compiler from
- # explicitly linking system object files so we need to strip them
- # from the output so that they don't get included in the library
- # dependencies.
- output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "ld" | grep -v "ld:"`; templist=`echo $templist | $SED "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list'
- ;;
- *)
- if test "$GXX" = yes && test "$with_gnu_ld" = no; then
- _LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
-
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
- _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
-
- # Commands to make compiler produce verbose output that lists
- # what "hidden" libraries, object files and flags are used when
- # linking a shared library.
- output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "\-L"'
-
- else
- # FIXME: insert proper C++ library support
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- fi
- ;;
- esac
- ;;
- psos*)
- # FIXME: insert proper C++ library support
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- ;;
- sco*)
- _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
- case $cc_basename in
- CC*)
- # FIXME: insert proper C++ library support
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- ;;
- *)
- # FIXME: insert proper C++ library support
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- ;;
- esac
- ;;
- sunos4*)
- case $cc_basename in
- CC*)
- # Sun C++ 4.x
- # FIXME: insert proper C++ library support
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- ;;
- lcc*)
- # Lucid
- # FIXME: insert proper C++ library support
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- ;;
- *)
- # FIXME: insert proper C++ library support
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- ;;
- esac
- ;;
- solaris*)
- case $cc_basename in
- CC*)
- # Sun C++ 4.2, 5.x and Centerline C++
- _LT_AC_TAGVAR(no_undefined_flag, $1)=' -zdefs'
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -nolib -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~
- $CC -G${allow_undefined_flag} -nolib ${wl}-M ${wl}$lib.exp -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$rm $lib.exp'
-
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
- _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
- case $host_os in
- solaris2.[[0-5]] | solaris2.[[0-5]].*) ;;
- *)
- # The C++ compiler is used as linker so we must use $wl
- # flag to pass the commands to the underlying system
- # linker. We must also pass each convience library through
- # to the system linker between allextract/defaultextract.
- # The C++ compiler will combine linker options so we
- # cannot just pass the convience library names through
- # without $wl.
- # Supported since Solaris 2.6 (maybe 2.5.1?)
- _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}-z ${wl}defaultextract'
- ;;
- esac
- _LT_AC_TAGVAR(link_all_deplibs, $1)=yes
-
- # Commands to make compiler produce verbose output that lists
- # what "hidden" libraries, object files and flags are used when
- # linking a shared library.
- #
- # There doesn't appear to be a way to prevent this compiler from
- # explicitly linking system object files so we need to strip them
- # from the output so that they don't get included in the library
- # dependencies.
- output_verbose_link_cmd='templist=`$CC -G $CFLAGS -v conftest.$objext 2>&1 | grep "\-[[LR]]"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list'
-
- # Archives containing C++ object files must be created using
- # "CC -xar", where "CC" is the Sun C++ compiler. This is
- # necessary to make sure instantiated templates are included
- # in the archive.
- _LT_AC_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs'
- ;;
- gcx*)
- # Green Hills C++ Compiler
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib'
-
- # The C++ compiler must be used to create the archive.
- _LT_AC_TAGVAR(old_archive_cmds, $1)='$CC $LDFLAGS -archive -o $oldlib $oldobjs'
- ;;
- *)
- # GNU C++ compiler with Solaris linker
- if test "$GXX" = yes && test "$with_gnu_ld" = no; then
- _LT_AC_TAGVAR(no_undefined_flag, $1)=' ${wl}-z ${wl}defs'
- if $CC --version | grep -v '^2\.7' > /dev/null; then
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib'
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~
- $CC -shared -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$rm $lib.exp'
-
- # Commands to make compiler produce verbose output that lists
- # what "hidden" libraries, object files and flags are used when
- # linking a shared library.
- output_verbose_link_cmd="$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep \"\-L\""
- else
- # g++ 2.7 appears to require `-G' NOT `-shared' on this
- # platform.
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -G -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib'
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~
- $CC -G -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$rm $lib.exp'
-
- # Commands to make compiler produce verbose output that lists
- # what "hidden" libraries, object files and flags are used when
- # linking a shared library.
- output_verbose_link_cmd="$CC -G $CFLAGS -v conftest.$objext 2>&1 | grep \"\-L\""
- fi
-
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $wl$libdir'
- fi
- ;;
- esac
- ;;
- sysv5OpenUNIX8* | sysv5UnixWare7* | sysv5uw[[78]]* | unixware7*)
- _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
- ;;
- tandem*)
- case $cc_basename in
- NCC*)
- # NonStop-UX NCC 3.20
- # FIXME: insert proper C++ library support
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- ;;
- *)
- # FIXME: insert proper C++ library support
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- ;;
- esac
- ;;
- vxworks*)
- # FIXME: insert proper C++ library support
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- ;;
- *)
- # FIXME: insert proper C++ library support
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- ;;
-esac
-AC_MSG_RESULT([$_LT_AC_TAGVAR(ld_shlibs, $1)])
-test "$_LT_AC_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no
-
-_LT_AC_TAGVAR(GCC, $1)="$GXX"
-_LT_AC_TAGVAR(LD, $1)="$LD"
-
-## CAVEAT EMPTOR:
-## There is no encapsulation within the following macros, do not change
-## the running order or otherwise move them around unless you know exactly
-## what you are doing...
-AC_LIBTOOL_POSTDEP_PREDEP($1)
-AC_LIBTOOL_PROG_COMPILER_PIC($1)
-AC_LIBTOOL_PROG_CC_C_O($1)
-AC_LIBTOOL_SYS_HARD_LINK_LOCKS($1)
-AC_LIBTOOL_PROG_LD_SHLIBS($1)
-AC_LIBTOOL_SYS_DYNAMIC_LINKER($1)
-AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH($1)
-AC_LIBTOOL_SYS_LIB_STRIP
-AC_LIBTOOL_DLOPEN_SELF($1)
-
-AC_LIBTOOL_CONFIG($1)
-
-AC_LANG_POP
-CC=$lt_save_CC
-LDCXX=$LD
-LD=$lt_save_LD
-GCC=$lt_save_GCC
-with_gnu_ldcxx=$with_gnu_ld
-with_gnu_ld=$lt_save_with_gnu_ld
-lt_cv_path_LDCXX=$lt_cv_path_LD
-lt_cv_path_LD=$lt_save_path_LD
-lt_cv_prog_gnu_ldcxx=$lt_cv_prog_gnu_ld
-lt_cv_prog_gnu_ld=$lt_save_with_gnu_ld
-])# AC_LIBTOOL_LANG_CXX_CONFIG
-
-# AC_LIBTOOL_POSTDEP_PREDEP([TAGNAME])
-# ------------------------
-# Figure out "hidden" library dependencies from verbose
-# compiler output when linking a shared library.
-# Parse the compiler output and extract the necessary
-# objects, libraries and library flags.
-AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP],[
-dnl we can't use the lt_simple_compile_test_code here,
-dnl because it contains code intended for an executable,
-dnl not a library. It's possible we should let each
-dnl tag define a new lt_????_link_test_code variable,
-dnl but it's only used here...
-ifelse([$1],[],[cat > conftest.$ac_ext <<EOF
-int a;
-void foo (void) { a = 0; }
-EOF
-],[$1],[CXX],[cat > conftest.$ac_ext <<EOF
-class Foo
-{
-public:
- Foo (void) { a = 0; }
-private:
- int a;
-};
-EOF
-],[$1],[F77],[cat > conftest.$ac_ext <<EOF
- subroutine foo
- implicit none
- integer*4 a
- a=0
- return
- end
-EOF
-],[$1],[GCJ],[cat > conftest.$ac_ext <<EOF
-public class foo {
- private int a;
- public void bar (void) {
- a = 0;
- }
-};
-EOF
-])
-dnl Parse the compiler output and extract the necessary
-dnl objects, libraries and library flags.
-if AC_TRY_EVAL(ac_compile); then
- # Parse the compiler output and extract the necessary
- # objects, libraries and library flags.
-
- # Sentinel used to keep track of whether or not we are before
- # the conftest object file.
- pre_test_object_deps_done=no
-
- # The `*' in the case matches for architectures that use `case' in
- # $output_verbose_cmd can trigger glob expansion during the loop
- # eval without this substitution.
- output_verbose_link_cmd="`$echo \"X$output_verbose_link_cmd\" | $Xsed -e \"$no_glob_subst\"`"
-
- for p in `eval $output_verbose_link_cmd`; do
- case $p in
-
- -L* | -R* | -l*)
- # Some compilers place space between "-{L,R}" and the path.
- # Remove the space.
- if test $p = "-L" \
- || test $p = "-R"; then
- prev=$p
- continue
- else
- prev=
- fi
-
- if test "$pre_test_object_deps_done" = no; then
- case $p in
- -L* | -R*)
- # Internal compiler library paths should come after those
- # provided the user. The postdeps already come after the
- # user supplied libs so there is no need to process them.
- if test -z "$_LT_AC_TAGVAR(compiler_lib_search_path, $1)"; then
- _LT_AC_TAGVAR(compiler_lib_search_path, $1)="${prev}${p}"
- else
- _LT_AC_TAGVAR(compiler_lib_search_path, $1)="${_LT_AC_TAGVAR(compiler_lib_search_path, $1)} ${prev}${p}"
- fi
- ;;
- # The "-l" case would never come before the object being
- # linked, so don't bother handling this case.
- esac
- else
- if test -z "$_LT_AC_TAGVAR(postdeps, $1)"; then
- _LT_AC_TAGVAR(postdeps, $1)="${prev}${p}"
- else
- _LT_AC_TAGVAR(postdeps, $1)="${_LT_AC_TAGVAR(postdeps, $1)} ${prev}${p}"
- fi
- fi
- ;;
-
- *.$objext)
- # This assumes that the test object file only shows up
- # once in the compiler output.
- if test "$p" = "conftest.$objext"; then
- pre_test_object_deps_done=yes
- continue
- fi
-
- if test "$pre_test_object_deps_done" = no; then
- if test -z "$_LT_AC_TAGVAR(predep_objects, $1)"; then
- _LT_AC_TAGVAR(predep_objects, $1)="$p"
- else
- _LT_AC_TAGVAR(predep_objects, $1)="$_LT_AC_TAGVAR(predep_objects, $1) $p"
- fi
- else
- if test -z "$_LT_AC_TAGVAR(postdep_objects, $1)"; then
- _LT_AC_TAGVAR(postdep_objects, $1)="$p"
- else
- _LT_AC_TAGVAR(postdep_objects, $1)="$_LT_AC_TAGVAR(postdep_objects, $1) $p"
- fi
- fi
- ;;
-
- *) ;; # Ignore the rest.
-
- esac
- done
-
- # Clean up.
- rm -f a.out a.exe
-else
- echo "libtool.m4: error: problem compiling $1 test program"
-fi
-
-$rm -f confest.$objext
-
-case " $_LT_AC_TAGVAR(postdeps, $1) " in
-*" -lc "*) _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no ;;
-esac
-])# AC_LIBTOOL_POSTDEP_PREDEP
-
-# AC_LIBTOOL_LANG_F77_CONFIG
-# ------------------------
-# Ensure that the configuration vars for the C compiler are
-# suitably defined. Those variables are subsequently used by
-# AC_LIBTOOL_CONFIG to write the compiler configuration to `libtool'.
-AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG], [_LT_AC_LANG_F77_CONFIG(F77)])
-AC_DEFUN([_LT_AC_LANG_F77_CONFIG],
-[AC_REQUIRE([AC_PROG_F77])
-AC_LANG_PUSH(Fortran 77)
-
-_LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
-_LT_AC_TAGVAR(allow_undefined_flag, $1)=
-_LT_AC_TAGVAR(always_export_symbols, $1)=no
-_LT_AC_TAGVAR(archive_expsym_cmds, $1)=
-_LT_AC_TAGVAR(export_dynamic_flag_spec, $1)=
-_LT_AC_TAGVAR(hardcode_direct, $1)=no
-_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)=
-_LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1)=
-_LT_AC_TAGVAR(hardcode_libdir_separator, $1)=
-_LT_AC_TAGVAR(hardcode_minus_L, $1)=no
-_LT_AC_TAGVAR(hardcode_automatic, $1)=no
-_LT_AC_TAGVAR(module_cmds, $1)=
-_LT_AC_TAGVAR(module_expsym_cmds, $1)=
-_LT_AC_TAGVAR(link_all_deplibs, $1)=unknown
-_LT_AC_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
-_LT_AC_TAGVAR(no_undefined_flag, $1)=
-_LT_AC_TAGVAR(whole_archive_flag_spec, $1)=
-_LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1)=no
-
-# Source file extension for f77 test sources.
-ac_ext=f
-
-# Object file extension for compiled f77 test sources.
-objext=o
-_LT_AC_TAGVAR(objext, $1)=$objext
-
-# Code to be used in simple compile tests
-lt_simple_compile_test_code=" subroutine t\n return\n end\n"
-
-# Code to be used in simple link tests
-lt_simple_link_test_code=" program t\n end\n"
-
-# ltmain only uses $CC for tagged configurations so make sure $CC is set.
-_LT_AC_SYS_COMPILER
-
-# save warnings/boilerplate of simple test code
-_LT_COMPILER_BOILERPLATE
-_LT_LINKER_BOILERPLATE
-
-# Allow CC to be a program name with arguments.
-lt_save_CC="$CC"
-CC=${F77-"f77"}
-compiler=$CC
-_LT_AC_TAGVAR(compiler, $1)=$CC
-_LT_CC_BASENAME([$compiler])
-
-AC_MSG_CHECKING([if libtool supports shared libraries])
-AC_MSG_RESULT([$can_build_shared])
-
-AC_MSG_CHECKING([whether to build shared libraries])
-test "$can_build_shared" = "no" && enable_shared=no
-
-# On AIX, shared libraries and static libraries use the same namespace, and
-# are all built from PIC.
-case "$host_os" in
-aix3*)
- test "$enable_shared" = yes && enable_static=no
- if test -n "$RANLIB"; then
- archive_cmds="$archive_cmds~\$RANLIB \$lib"
- postinstall_cmds='$RANLIB $lib'
- fi
- ;;
-aix4* | aix5*)
- if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then
- test "$enable_shared" = yes && enable_static=no
- fi
- ;;
-esac
-AC_MSG_RESULT([$enable_shared])
-
-AC_MSG_CHECKING([whether to build static libraries])
-# Make sure either enable_shared or enable_static is yes.
-test "$enable_shared" = yes || enable_static=yes
-AC_MSG_RESULT([$enable_static])
-
-test "$_LT_AC_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no
-
-_LT_AC_TAGVAR(GCC, $1)="$G77"
-_LT_AC_TAGVAR(LD, $1)="$LD"
-
-AC_LIBTOOL_PROG_COMPILER_PIC($1)
-AC_LIBTOOL_PROG_CC_C_O($1)
-AC_LIBTOOL_SYS_HARD_LINK_LOCKS($1)
-AC_LIBTOOL_PROG_LD_SHLIBS($1)
-AC_LIBTOOL_SYS_DYNAMIC_LINKER($1)
-AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH($1)
-AC_LIBTOOL_SYS_LIB_STRIP
-
-
-AC_LIBTOOL_CONFIG($1)
-
-AC_LANG_POP
-CC="$lt_save_CC"
-])# AC_LIBTOOL_LANG_F77_CONFIG
-
-
-# AC_LIBTOOL_LANG_GCJ_CONFIG
-# --------------------------
-# Ensure that the configuration vars for the C compiler are
-# suitably defined. Those variables are subsequently used by
-# AC_LIBTOOL_CONFIG to write the compiler configuration to `libtool'.
-AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG], [_LT_AC_LANG_GCJ_CONFIG(GCJ)])
-AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG],
-[AC_LANG_SAVE
-
-# Source file extension for Java test sources.
-ac_ext=java
-
-# Object file extension for compiled Java test sources.
-objext=o
-_LT_AC_TAGVAR(objext, $1)=$objext
-
-# Code to be used in simple compile tests
-lt_simple_compile_test_code="class foo {}\n"
-
-# Code to be used in simple link tests
-lt_simple_link_test_code='public class conftest { public static void main(String[[]] argv) {}; }\n'
-
-# ltmain only uses $CC for tagged configurations so make sure $CC is set.
-_LT_AC_SYS_COMPILER
-
-# save warnings/boilerplate of simple test code
-_LT_COMPILER_BOILERPLATE
-_LT_LINKER_BOILERPLATE
-
-# Allow CC to be a program name with arguments.
-lt_save_CC="$CC"
-CC=${GCJ-"gcj"}
-compiler=$CC
-_LT_AC_TAGVAR(compiler, $1)=$CC
-_LT_CC_BASENAME([$compiler])
-
-# GCJ did not exist at the time GCC didn't implicitly link libc in.
-_LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
-
-_LT_AC_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
-
-## CAVEAT EMPTOR:
-## There is no encapsulation within the following macros, do not change
-## the running order or otherwise move them around unless you know exactly
-## what you are doing...
-AC_LIBTOOL_PROG_COMPILER_NO_RTTI($1)
-AC_LIBTOOL_PROG_COMPILER_PIC($1)
-AC_LIBTOOL_PROG_CC_C_O($1)
-AC_LIBTOOL_SYS_HARD_LINK_LOCKS($1)
-AC_LIBTOOL_PROG_LD_SHLIBS($1)
-AC_LIBTOOL_SYS_DYNAMIC_LINKER($1)
-AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH($1)
-AC_LIBTOOL_SYS_LIB_STRIP
-AC_LIBTOOL_DLOPEN_SELF($1)
-
-AC_LIBTOOL_CONFIG($1)
-
-AC_LANG_RESTORE
-CC="$lt_save_CC"
-])# AC_LIBTOOL_LANG_GCJ_CONFIG
-
-
-# AC_LIBTOOL_LANG_RC_CONFIG
-# --------------------------
-# Ensure that the configuration vars for the Windows resource compiler are
-# suitably defined. Those variables are subsequently used by
-# AC_LIBTOOL_CONFIG to write the compiler configuration to `libtool'.
-AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG], [_LT_AC_LANG_RC_CONFIG(RC)])
-AC_DEFUN([_LT_AC_LANG_RC_CONFIG],
-[AC_LANG_SAVE
-
-# Source file extension for RC test sources.
-ac_ext=rc
-
-# Object file extension for compiled RC test sources.
-objext=o
-_LT_AC_TAGVAR(objext, $1)=$objext
-
-# Code to be used in simple compile tests
-lt_simple_compile_test_code='sample MENU { MENUITEM "&Soup", 100, CHECKED }\n'
-
-# Code to be used in simple link tests
-lt_simple_link_test_code="$lt_simple_compile_test_code"
-
-# ltmain only uses $CC for tagged configurations so make sure $CC is set.
-_LT_AC_SYS_COMPILER
-
-# save warnings/boilerplate of simple test code
-_LT_COMPILER_BOILERPLATE
-_LT_LINKER_BOILERPLATE
-
-# Allow CC to be a program name with arguments.
-lt_save_CC="$CC"
-CC=${RC-"windres"}
-compiler=$CC
-_LT_AC_TAGVAR(compiler, $1)=$CC
-_LT_CC_BASENAME([$compiler])
-_LT_AC_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes
-
-AC_LIBTOOL_CONFIG($1)
-
-AC_LANG_RESTORE
-CC="$lt_save_CC"
-])# AC_LIBTOOL_LANG_RC_CONFIG
-
-
-# AC_LIBTOOL_CONFIG([TAGNAME])
-# ----------------------------
-# If TAGNAME is not passed, then create an initial libtool script
-# with a default configuration from the untagged config vars. Otherwise
-# add code to config.status for appending the configuration named by
-# TAGNAME from the matching tagged config vars.
-AC_DEFUN([AC_LIBTOOL_CONFIG],
-[# The else clause should only fire when bootstrapping the
-# libtool distribution, otherwise you forgot to ship ltmain.sh
-# with your package, and you will get complaints that there are
-# no rules to generate ltmain.sh.
-if test -f "$ltmain"; then
- # See if we are running on zsh, and set the options which allow our commands through
- # without removal of \ escapes.
- if test -n "${ZSH_VERSION+set}" ; then
- setopt NO_GLOB_SUBST
- fi
- # Now quote all the things that may contain metacharacters while being
- # careful not to overquote the AC_SUBSTed values. We take copies of the
- # variables and quote the copies for generation of the libtool script.
- for var in echo old_CC old_CFLAGS AR AR_FLAGS EGREP RANLIB LN_S LTCC NM \
- SED SHELL STRIP \
- libname_spec library_names_spec soname_spec extract_expsyms_cmds \
- old_striplib striplib file_magic_cmd finish_cmds finish_eval \
- deplibs_check_method reload_flag reload_cmds need_locks \
- lt_cv_sys_global_symbol_pipe lt_cv_sys_global_symbol_to_cdecl \
- lt_cv_sys_global_symbol_to_c_name_address \
- sys_lib_search_path_spec sys_lib_dlsearch_path_spec \
- old_postinstall_cmds old_postuninstall_cmds \
- _LT_AC_TAGVAR(compiler, $1) \
- _LT_AC_TAGVAR(CC, $1) \
- _LT_AC_TAGVAR(LD, $1) \
- _LT_AC_TAGVAR(lt_prog_compiler_wl, $1) \
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1) \
- _LT_AC_TAGVAR(lt_prog_compiler_static, $1) \
- _LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1) \
- _LT_AC_TAGVAR(export_dynamic_flag_spec, $1) \
- _LT_AC_TAGVAR(thread_safe_flag_spec, $1) \
- _LT_AC_TAGVAR(whole_archive_flag_spec, $1) \
- _LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1) \
- _LT_AC_TAGVAR(old_archive_cmds, $1) \
- _LT_AC_TAGVAR(old_archive_from_new_cmds, $1) \
- _LT_AC_TAGVAR(predep_objects, $1) \
- _LT_AC_TAGVAR(postdep_objects, $1) \
- _LT_AC_TAGVAR(predeps, $1) \
- _LT_AC_TAGVAR(postdeps, $1) \
- _LT_AC_TAGVAR(compiler_lib_search_path, $1) \
- _LT_AC_TAGVAR(archive_cmds, $1) \
- _LT_AC_TAGVAR(archive_expsym_cmds, $1) \
- _LT_AC_TAGVAR(postinstall_cmds, $1) \
- _LT_AC_TAGVAR(postuninstall_cmds, $1) \
- _LT_AC_TAGVAR(old_archive_from_expsyms_cmds, $1) \
- _LT_AC_TAGVAR(allow_undefined_flag, $1) \
- _LT_AC_TAGVAR(no_undefined_flag, $1) \
- _LT_AC_TAGVAR(export_symbols_cmds, $1) \
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1) \
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1) \
- _LT_AC_TAGVAR(hardcode_libdir_separator, $1) \
- _LT_AC_TAGVAR(hardcode_automatic, $1) \
- _LT_AC_TAGVAR(module_cmds, $1) \
- _LT_AC_TAGVAR(module_expsym_cmds, $1) \
- _LT_AC_TAGVAR(lt_cv_prog_compiler_c_o, $1) \
- _LT_AC_TAGVAR(exclude_expsyms, $1) \
- _LT_AC_TAGVAR(include_expsyms, $1); do
-
- case $var in
- _LT_AC_TAGVAR(old_archive_cmds, $1) | \
- _LT_AC_TAGVAR(old_archive_from_new_cmds, $1) | \
- _LT_AC_TAGVAR(archive_cmds, $1) | \
- _LT_AC_TAGVAR(archive_expsym_cmds, $1) | \
- _LT_AC_TAGVAR(module_cmds, $1) | \
- _LT_AC_TAGVAR(module_expsym_cmds, $1) | \
- _LT_AC_TAGVAR(old_archive_from_expsyms_cmds, $1) | \
- _LT_AC_TAGVAR(export_symbols_cmds, $1) | \
- extract_expsyms_cmds | reload_cmds | finish_cmds | \
- postinstall_cmds | postuninstall_cmds | \
- old_postinstall_cmds | old_postuninstall_cmds | \
- sys_lib_search_path_spec | sys_lib_dlsearch_path_spec)
- # Double-quote double-evaled strings.
- eval "lt_$var=\\\"\`\$echo \"X\$$var\" | \$Xsed -e \"\$double_quote_subst\" -e \"\$sed_quote_subst\" -e \"\$delay_variable_subst\"\`\\\""
- ;;
- *)
- eval "lt_$var=\\\"\`\$echo \"X\$$var\" | \$Xsed -e \"\$sed_quote_subst\"\`\\\""
- ;;
- esac
- done
-
- case $lt_echo in
- *'\[$]0 --fallback-echo"')
- lt_echo=`$echo "X$lt_echo" | $Xsed -e 's/\\\\\\\[$]0 --fallback-echo"[$]/[$]0 --fallback-echo"/'`
- ;;
- esac
-
-ifelse([$1], [],
- [cfgfile="${ofile}T"
- trap "$rm \"$cfgfile\"; exit 1" 1 2 15
- $rm -f "$cfgfile"
- AC_MSG_NOTICE([creating $ofile])],
- [cfgfile="$ofile"])
-
- cat <<__EOF__ >> "$cfgfile"
-ifelse([$1], [],
-[#! $SHELL
-
-# `$echo "$cfgfile" | sed 's%^.*/%%'` - Provide generalized library-building support services.
-# Generated automatically by $PROGRAM (GNU $PACKAGE $VERSION$TIMESTAMP)
-# NOTE: Changes made to this file will be lost: look at ltmain.sh.
-#
-# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001
-# Free Software Foundation, Inc.
-#
-# This file is part of GNU Libtool:
-# Originally by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# As a special exception to the GNU General Public License, if you
-# distribute this file as part of a program that contains a
-# configuration script generated by Autoconf, you may include it under
-# the same distribution terms that you use for the rest of that program.
-
-# A sed program that does not truncate output.
-SED=$lt_SED
-
-# Sed that helps us avoid accidentally triggering echo(1) options like -n.
-Xsed="$SED -e 1s/^X//"
-
-# The HP-UX ksh and POSIX shell print the target directory to stdout
-# if CDPATH is set.
-(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
-
-# The names of the tagged configurations supported by this script.
-available_tags=
-
-# ### BEGIN LIBTOOL CONFIG],
-[# ### BEGIN LIBTOOL TAG CONFIG: $tagname])
-
-# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
-
-# Shell to use when invoking shell scripts.
-SHELL=$lt_SHELL
-
-# Whether or not to build shared libraries.
-build_libtool_libs=$enable_shared
-
-# Whether or not to build static libraries.
-build_old_libs=$enable_static
-
-# Whether or not to add -lc for building shared libraries.
-build_libtool_need_lc=$_LT_AC_TAGVAR(archive_cmds_need_lc, $1)
-
-# Whether or not to disallow shared libs when runtime libs are static
-allow_libtool_libs_with_static_runtimes=$_LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1)
-
-# Whether or not to optimize for fast installation.
-fast_install=$enable_fast_install
-
-# The host system.
-host_alias=$host_alias
-host=$host
-host_os=$host_os
-
-# The build system.
-build_alias=$build_alias
-build=$build
-build_os=$build_os
-
-# An echo program that does not interpret backslashes.
-echo=$lt_echo
-
-# The archiver.
-AR=$lt_AR
-AR_FLAGS=$lt_AR_FLAGS
-
-# A C compiler.
-LTCC=$lt_LTCC
-
-# A language-specific compiler.
-CC=$lt_[]_LT_AC_TAGVAR(compiler, $1)
-
-# Is the compiler the GNU C compiler?
-with_gcc=$_LT_AC_TAGVAR(GCC, $1)
-
-# An ERE matcher.
-EGREP=$lt_EGREP
-
-# The linker used to build libraries.
-LD=$lt_[]_LT_AC_TAGVAR(LD, $1)
-
-# Whether we need hard or soft links.
-LN_S=$lt_LN_S
-
-# A BSD-compatible nm program.
-NM=$lt_NM
-
-# A symbol stripping program
-STRIP=$lt_STRIP
-
-# Used to examine libraries when file_magic_cmd begins "file"
-MAGIC_CMD=$MAGIC_CMD
-
-# Used on cygwin: DLL creation program.
-DLLTOOL="$DLLTOOL"
-
-# Used on cygwin: object dumper.
-OBJDUMP="$OBJDUMP"
-
-# Used on cygwin: assembler.
-AS="$AS"
-
-# The name of the directory that contains temporary libtool files.
-objdir=$objdir
-
-# How to create reloadable object files.
-reload_flag=$lt_reload_flag
-reload_cmds=$lt_reload_cmds
-
-# How to pass a linker flag through the compiler.
-wl=$lt_[]_LT_AC_TAGVAR(lt_prog_compiler_wl, $1)
-
-# Object file suffix (normally "o").
-objext="$ac_objext"
-
-# Old archive suffix (normally "a").
-libext="$libext"
-
-# Shared library suffix (normally ".so").
-shrext_cmds='$shrext_cmds'; shrext="$shrext_cmds"
-
-# Executable file suffix (normally "").
-exeext="$exeext"
-
-# Additional compiler flags for building library objects.
-pic_flag=$lt_[]_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)
-pic_mode=$pic_mode
-
-# What is the maximum length of a command?
-max_cmd_len=$lt_cv_sys_max_cmd_len
-
-# Does compiler simultaneously support -c and -o options?
-compiler_c_o=$lt_[]_LT_AC_TAGVAR(lt_cv_prog_compiler_c_o, $1)
-
-# Must we lock files when doing compilation?
-need_locks=$lt_need_locks
-
-# Do we need the lib prefix for modules?
-need_lib_prefix=$need_lib_prefix
-
-# Do we need a version for libraries?
-need_version=$need_version
-
-# Whether dlopen is supported.
-dlopen_support=$enable_dlopen
-
-# Whether dlopen of programs is supported.
-dlopen_self=$enable_dlopen_self
-
-# Whether dlopen of statically linked programs is supported.
-dlopen_self_static=$enable_dlopen_self_static
-
-# Compiler flag to prevent dynamic linking.
-link_static_flag=$lt_[]_LT_AC_TAGVAR(lt_prog_compiler_static, $1)
-
-# Compiler flag to turn off builtin functions.
-no_builtin_flag=$lt_[]_LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)
-
-# Compiler flag to allow reflexive dlopens.
-export_dynamic_flag_spec=$lt_[]_LT_AC_TAGVAR(export_dynamic_flag_spec, $1)
-
-# Compiler flag to generate shared objects directly from archives.
-whole_archive_flag_spec=$lt_[]_LT_AC_TAGVAR(whole_archive_flag_spec, $1)
-
-# Compiler flag to generate thread-safe objects.
-thread_safe_flag_spec=$lt_[]_LT_AC_TAGVAR(thread_safe_flag_spec, $1)
-
-# Library versioning type.
-version_type=$version_type
-
-# Format of library name prefix.
-libname_spec=$lt_libname_spec
-
-# List of archive names. First name is the real one, the rest are links.
-# The last name is the one that the linker finds with -lNAME.
-library_names_spec=$lt_library_names_spec
-
-# The coded name of the library, if different from the real name.
-soname_spec=$lt_soname_spec
-
-# Commands used to build and install an old-style archive.
-RANLIB=$lt_RANLIB
-old_archive_cmds=$lt_[]_LT_AC_TAGVAR(old_archive_cmds, $1)
-old_postinstall_cmds=$lt_old_postinstall_cmds
-old_postuninstall_cmds=$lt_old_postuninstall_cmds
-
-# Create an old-style archive from a shared archive.
-old_archive_from_new_cmds=$lt_[]_LT_AC_TAGVAR(old_archive_from_new_cmds, $1)
-
-# Create a temporary old-style archive to link instead of a shared archive.
-old_archive_from_expsyms_cmds=$lt_[]_LT_AC_TAGVAR(old_archive_from_expsyms_cmds, $1)
-
-# Commands used to build and install a shared archive.
-archive_cmds=$lt_[]_LT_AC_TAGVAR(archive_cmds, $1)
-archive_expsym_cmds=$lt_[]_LT_AC_TAGVAR(archive_expsym_cmds, $1)
-postinstall_cmds=$lt_postinstall_cmds
-postuninstall_cmds=$lt_postuninstall_cmds
-
-# Commands used to build a loadable module (assumed same as above if empty)
-module_cmds=$lt_[]_LT_AC_TAGVAR(module_cmds, $1)
-module_expsym_cmds=$lt_[]_LT_AC_TAGVAR(module_expsym_cmds, $1)
-
-# Commands to strip libraries.
-old_striplib=$lt_old_striplib
-striplib=$lt_striplib
-
-# Dependencies to place before the objects being linked to create a
-# shared library.
-predep_objects=$lt_[]_LT_AC_TAGVAR(predep_objects, $1)
-
-# Dependencies to place after the objects being linked to create a
-# shared library.
-postdep_objects=$lt_[]_LT_AC_TAGVAR(postdep_objects, $1)
-
-# Dependencies to place before the objects being linked to create a
-# shared library.
-predeps=$lt_[]_LT_AC_TAGVAR(predeps, $1)
-
-# Dependencies to place after the objects being linked to create a
-# shared library.
-postdeps=$lt_[]_LT_AC_TAGVAR(postdeps, $1)
-
-# The library search path used internally by the compiler when linking
-# a shared library.
-compiler_lib_search_path=$lt_[]_LT_AC_TAGVAR(compiler_lib_search_path, $1)
-
-# Method to check whether dependent libraries are shared objects.
-deplibs_check_method=$lt_deplibs_check_method
-
-# Command to use when deplibs_check_method == file_magic.
-file_magic_cmd=$lt_file_magic_cmd
-
-# Flag that allows shared libraries with undefined symbols to be built.
-allow_undefined_flag=$lt_[]_LT_AC_TAGVAR(allow_undefined_flag, $1)
-
-# Flag that forces no undefined symbols.
-no_undefined_flag=$lt_[]_LT_AC_TAGVAR(no_undefined_flag, $1)
-
-# Commands used to finish a libtool library installation in a directory.
-finish_cmds=$lt_finish_cmds
-
-# Same as above, but a single script fragment to be evaled but not shown.
-finish_eval=$lt_finish_eval
-
-# Take the output of nm and produce a listing of raw symbols and C names.
-global_symbol_pipe=$lt_lt_cv_sys_global_symbol_pipe
-
-# Transform the output of nm in a proper C declaration
-global_symbol_to_cdecl=$lt_lt_cv_sys_global_symbol_to_cdecl
-
-# Transform the output of nm in a C name address pair
-global_symbol_to_c_name_address=$lt_lt_cv_sys_global_symbol_to_c_name_address
-
-# This is the shared library runtime path variable.
-runpath_var=$runpath_var
-
-# This is the shared library path variable.
-shlibpath_var=$shlibpath_var
-
-# Is shlibpath searched before the hard-coded library search path?
-shlibpath_overrides_runpath=$shlibpath_overrides_runpath
-
-# How to hardcode a shared library path into an executable.
-hardcode_action=$_LT_AC_TAGVAR(hardcode_action, $1)
-
-# Whether we should hardcode library paths into libraries.
-hardcode_into_libs=$hardcode_into_libs
-
-# Flag to hardcode \$libdir into a binary during linking.
-# This must work even if \$libdir does not exist.
-hardcode_libdir_flag_spec=$lt_[]_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)
-
-# If ld is used when linking, flag to hardcode \$libdir into
-# a binary during linking. This must work even if \$libdir does
-# not exist.
-hardcode_libdir_flag_spec_ld=$lt_[]_LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1)
-
-# Whether we need a single -rpath flag with a separated argument.
-hardcode_libdir_separator=$lt_[]_LT_AC_TAGVAR(hardcode_libdir_separator, $1)
-
-# Set to yes if using DIR/libNAME${shared_ext} during linking hardcodes DIR into the
-# resulting binary.
-hardcode_direct=$_LT_AC_TAGVAR(hardcode_direct, $1)
-
-# Set to yes if using the -LDIR flag during linking hardcodes DIR into the
-# resulting binary.
-hardcode_minus_L=$_LT_AC_TAGVAR(hardcode_minus_L, $1)
-
-# Set to yes if using SHLIBPATH_VAR=DIR during linking hardcodes DIR into
-# the resulting binary.
-hardcode_shlibpath_var=$_LT_AC_TAGVAR(hardcode_shlibpath_var, $1)
-
-# Set to yes if building a shared library automatically hardcodes DIR into the library
-# and all subsequent libraries and executables linked against it.
-hardcode_automatic=$_LT_AC_TAGVAR(hardcode_automatic, $1)
-
-# Variables whose values should be saved in libtool wrapper scripts and
-# restored at relink time.
-variables_saved_for_relink="$variables_saved_for_relink"
-
-# Whether libtool must link a program against all its dependency libraries.
-link_all_deplibs=$_LT_AC_TAGVAR(link_all_deplibs, $1)
-
-# Compile-time system search path for libraries
-sys_lib_search_path_spec=$lt_sys_lib_search_path_spec
-
-# Run-time system search path for libraries
-sys_lib_dlsearch_path_spec=$lt_sys_lib_dlsearch_path_spec
-
-# Fix the shell variable \$srcfile for the compiler.
-fix_srcfile_path="$_LT_AC_TAGVAR(fix_srcfile_path, $1)"
-
-# Set to yes if exported symbols are required.
-always_export_symbols=$_LT_AC_TAGVAR(always_export_symbols, $1)
-
-# The commands to list exported symbols.
-export_symbols_cmds=$lt_[]_LT_AC_TAGVAR(export_symbols_cmds, $1)
-
-# The commands to extract the exported symbol list from a shared archive.
-extract_expsyms_cmds=$lt_extract_expsyms_cmds
-
-# Symbols that should not be listed in the preloaded symbols.
-exclude_expsyms=$lt_[]_LT_AC_TAGVAR(exclude_expsyms, $1)
-
-# Symbols that must always be exported.
-include_expsyms=$lt_[]_LT_AC_TAGVAR(include_expsyms, $1)
-
-ifelse([$1],[],
-[# ### END LIBTOOL CONFIG],
-[# ### END LIBTOOL TAG CONFIG: $tagname])
-
-__EOF__
-
-ifelse([$1],[], [
- case $host_os in
- aix3*)
- cat <<\EOF >> "$cfgfile"
-
-# AIX sometimes has problems with the GCC collect2 program. For some
-# reason, if we set the COLLECT_NAMES environment variable, the problems
-# vanish in a puff of smoke.
-if test "X${COLLECT_NAMES+set}" != Xset; then
- COLLECT_NAMES=
- export COLLECT_NAMES
-fi
-EOF
- ;;
- esac
-
- # We use sed instead of cat because bash on DJGPP gets confused if
- # if finds mixed CR/LF and LF-only lines. Since sed operates in
- # text mode, it properly converts lines to CR/LF. This bash problem
- # is reportedly fixed, but why not run on old versions too?
- sed '$q' "$ltmain" >> "$cfgfile" || (rm -f "$cfgfile"; exit 1)
-
- mv -f "$cfgfile" "$ofile" || \
- (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile")
- chmod +x "$ofile"
-])
-else
- # If there is no Makefile yet, we rely on a make rule to execute
- # `config.status --recheck' to rerun these tests and create the
- # libtool script then.
- ltmain_in=`echo $ltmain | sed -e 's/\.sh$/.in/'`
- if test -f "$ltmain_in"; then
- test -f Makefile && make "$ltmain"
- fi
-fi
-])# AC_LIBTOOL_CONFIG
-
-
-# AC_LIBTOOL_PROG_COMPILER_NO_RTTI([TAGNAME])
-# -------------------------------------------
-AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI],
-[AC_REQUIRE([_LT_AC_SYS_COMPILER])dnl
-
-_LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=
-
-if test "$GCC" = yes; then
- _LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin'
-
- AC_LIBTOOL_COMPILER_OPTION([if $compiler supports -fno-rtti -fno-exceptions],
- lt_cv_prog_compiler_rtti_exceptions,
- [-fno-rtti -fno-exceptions], [],
- [_LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)="$_LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1) -fno-rtti -fno-exceptions"])
-fi
-])# AC_LIBTOOL_PROG_COMPILER_NO_RTTI
-
-
-# AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE
-# ---------------------------------
-AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE],
-[AC_REQUIRE([AC_CANONICAL_HOST])
-AC_REQUIRE([AC_PROG_NM])
-AC_REQUIRE([AC_OBJEXT])
-# Check for command to grab the raw symbol name followed by C symbol from nm.
-AC_MSG_CHECKING([command to parse $NM output from $compiler object])
-AC_CACHE_VAL([lt_cv_sys_global_symbol_pipe],
-[
-# These are sane defaults that work on at least a few old systems.
-# [They come from Ultrix. What could be older than Ultrix?!! ;)]
-
-# Character class describing NM global symbol codes.
-symcode='[[BCDEGRST]]'
-
-# Regexp to match symbols that can be accessed directly from C.
-sympat='\([[_A-Za-z]][[_A-Za-z0-9]]*\)'
-
-# Transform an extracted symbol line into a proper C declaration
-lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^. .* \(.*\)$/extern int \1;/p'"
-
-# Transform an extracted symbol line into symbol name and symbol address
-lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([[^ ]]*\) $/ {\\\"\1\\\", (lt_ptr) 0},/p' -e 's/^$symcode \([[^ ]]*\) \([[^ ]]*\)$/ {\"\2\", (lt_ptr) \&\2},/p'"
-
-# Define system-specific variables.
-case $host_os in
-aix*)
- symcode='[[BCDT]]'
- ;;
-cygwin* | mingw* | pw32*)
- symcode='[[ABCDGISTW]]'
- ;;
-hpux*) # Its linker distinguishes data from code symbols
- if test "$host_cpu" = ia64; then
- symcode='[[ABCDEGRST]]'
- fi
- lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'"
- lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([[^ ]]*\) $/ {\\\"\1\\\", (lt_ptr) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/ {\"\2\", (lt_ptr) \&\2},/p'"
- ;;
-linux*)
- if test "$host_cpu" = ia64; then
- symcode='[[ABCDGIRSTW]]'
- lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'"
- lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([[^ ]]*\) $/ {\\\"\1\\\", (lt_ptr) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/ {\"\2\", (lt_ptr) \&\2},/p'"
- fi
- ;;
-irix* | nonstopux*)
- symcode='[[BCDEGRST]]'
- ;;
-osf*)
- symcode='[[BCDEGQRST]]'
- ;;
-solaris* | sysv5*)
- symcode='[[BDRT]]'
- ;;
-sysv4)
- symcode='[[DFNSTU]]'
- ;;
-esac
-
-# Handle CRLF in mingw tool chain
-opt_cr=
-case $build_os in
-mingw*)
- opt_cr=`echo 'x\{0,1\}' | tr x '\015'` # option cr in regexp
- ;;
-esac
-
-# If we're using GNU nm, then use its standard symbol codes.
-case `$NM -V 2>&1` in
-*GNU* | *'with BFD'*)
- symcode='[[ABCDGIRSTW]]' ;;
-esac
-
-# Try without a prefix undercore, then with it.
-for ac_symprfx in "" "_"; do
-
- # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol.
- symxfrm="\\1 $ac_symprfx\\2 \\2"
-
- # Write the raw and C identifiers.
- lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[[ ]]\($symcode$symcode*\)[[ ]][[ ]]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'"
-
- # Check to see that the pipe works correctly.
- pipe_works=no
-
- rm -f conftest*
- cat > conftest.$ac_ext <<EOF
-#ifdef __cplusplus
-extern "C" {
-#endif
-char nm_test_var;
-void nm_test_func(){}
-#ifdef __cplusplus
-}
-#endif
-int main(){nm_test_var='a';nm_test_func();return(0);}
-EOF
-
- if AC_TRY_EVAL(ac_compile); then
- # Now try to grab the symbols.
- nlist=conftest.nm
- if AC_TRY_EVAL(NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $nlist) && test -s "$nlist"; then
- # Try sorting and uniquifying the output.
- if sort "$nlist" | uniq > "$nlist"T; then
- mv -f "$nlist"T "$nlist"
- else
- rm -f "$nlist"T
- fi
-
- # Make sure that we snagged all the symbols we need.
- if grep ' nm_test_var$' "$nlist" >/dev/null; then
- if grep ' nm_test_func$' "$nlist" >/dev/null; then
- cat <<EOF > conftest.$ac_ext
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-EOF
- # Now generate the symbol file.
- eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | grep -v main >> conftest.$ac_ext'
-
- cat <<EOF >> conftest.$ac_ext
-#if defined (__STDC__) && __STDC__
-# define lt_ptr_t void *
-#else
-# define lt_ptr_t char *
-# define const
-#endif
-
-/* The mapping between symbol names and symbols. */
-const struct {
- const char *name;
- lt_ptr_t address;
-}
-lt_preloaded_symbols[[]] =
-{
-EOF
- $SED "s/^$symcode$symcode* \(.*\) \(.*\)$/ {\"\2\", (lt_ptr_t) \&\2},/" < "$nlist" | grep -v main >> conftest.$ac_ext
- cat <<\EOF >> conftest.$ac_ext
- {0, (lt_ptr_t) 0}
-};
-
-#ifdef __cplusplus
-}
-#endif
-EOF
- # Now try linking the two files.
- mv conftest.$ac_objext conftstm.$ac_objext
- lt_save_LIBS="$LIBS"
- lt_save_CFLAGS="$CFLAGS"
- LIBS="conftstm.$ac_objext"
- CFLAGS="$CFLAGS$_LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)"
- if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext}; then
- pipe_works=yes
- fi
- LIBS="$lt_save_LIBS"
- CFLAGS="$lt_save_CFLAGS"
- else
- echo "cannot find nm_test_func in $nlist" >&AS_MESSAGE_LOG_FD
- fi
- else
- echo "cannot find nm_test_var in $nlist" >&AS_MESSAGE_LOG_FD
- fi
- else
- echo "cannot run $lt_cv_sys_global_symbol_pipe" >&AS_MESSAGE_LOG_FD
- fi
- else
- echo "$progname: failed program was:" >&AS_MESSAGE_LOG_FD
- cat conftest.$ac_ext >&5
- fi
- rm -f conftest* conftst*
-
- # Do not use the global_symbol_pipe unless it works.
- if test "$pipe_works" = yes; then
- break
- else
- lt_cv_sys_global_symbol_pipe=
- fi
-done
-])
-if test -z "$lt_cv_sys_global_symbol_pipe"; then
- lt_cv_sys_global_symbol_to_cdecl=
-fi
-if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then
- AC_MSG_RESULT(failed)
-else
- AC_MSG_RESULT(ok)
-fi
-]) # AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE
-
-
-# AC_LIBTOOL_PROG_COMPILER_PIC([TAGNAME])
-# ---------------------------------------
-AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC],
-[_LT_AC_TAGVAR(lt_prog_compiler_wl, $1)=
-_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=
-_LT_AC_TAGVAR(lt_prog_compiler_static, $1)=
-
-AC_MSG_CHECKING([for $compiler option to produce PIC])
- ifelse([$1],[CXX],[
- # C++ specific cases for pic, static, wl, etc.
- if test "$GXX" = yes; then
- _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
- _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-static'
-
- case $host_os in
- aix*)
- # All AIX code is PIC.
- if test "$host_cpu" = ia64; then
- # AIX 5 now supports IA64 processor
- _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
- fi
- ;;
- amigaos*)
- # FIXME: we need at least 68020 code to build shared libraries, but
- # adding the `-m68020' flag to GCC prevents building anything better,
- # like `-m68040'.
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4'
- ;;
- beos* | cygwin* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*)
- # PIC is the default for these OSes.
- ;;
- mingw* | os2* | pw32*)
- # This hack is so that the source file can tell whether it is being
- # built for inclusion in a dll (and should export symbols for example).
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT'
- ;;
- darwin* | rhapsody*)
- # PIC is the default on this platform
- # Common symbols not allowed in MH_DYLIB files
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common'
- ;;
- *djgpp*)
- # DJGPP does not support shared libraries at all
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=
- ;;
- sysv4*MP*)
- if test -d /usr/nec; then
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic
- fi
- ;;
- hpux*)
- # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but
- # not for PA HP-UX.
- case "$host_cpu" in
- hppa*64*|ia64*)
- ;;
- *)
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
- ;;
- esac
- ;;
- *)
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
- ;;
- esac
- else
- case $host_os in
- aix4* | aix5*)
- # All AIX code is PIC.
- if test "$host_cpu" = ia64; then
- # AIX 5 now supports IA64 processor
- _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
- else
- _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp'
- fi
- ;;
- chorus*)
- case $cc_basename in
- cxch68*)
- # Green Hills C++ Compiler
- # _LT_AC_TAGVAR(lt_prog_compiler_static, $1)="--no_auto_instantiation -u __main -u __premain -u _abort -r $COOL_DIR/lib/libOrb.a $MVME_DIR/lib/CC/libC.a $MVME_DIR/lib/classix/libcx.s.a"
- ;;
- esac
- ;;
- darwin*)
- # PIC is the default on this platform
- # Common symbols not allowed in MH_DYLIB files
- case $cc_basename in
- xlc*)
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-qnocommon'
- _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
- ;;
- esac
- ;;
- dgux*)
- case $cc_basename in
- ec++*)
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
- ;;
- ghcx*)
- # Green Hills C++ Compiler
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
- ;;
- *)
- ;;
- esac
- ;;
- freebsd* | kfreebsd*-gnu | dragonfly*)
- # FreeBSD uses GNU C++
- ;;
- hpux9* | hpux10* | hpux11*)
- case $cc_basename in
- CC*)
- _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
- _LT_AC_TAGVAR(lt_prog_compiler_static, $1)="${ac_cv_prog_cc_wl}-a ${ac_cv_prog_cc_wl}archive"
- if test "$host_cpu" != ia64; then
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='+Z'
- fi
- ;;
- aCC*)
- _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
- _LT_AC_TAGVAR(lt_prog_compiler_static, $1)="${ac_cv_prog_cc_wl}-a ${ac_cv_prog_cc_wl}archive"
- case "$host_cpu" in
- hppa*64*|ia64*)
- # +Z the default
- ;;
- *)
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='+Z'
- ;;
- esac
- ;;
- *)
- ;;
- esac
- ;;
- irix5* | irix6* | nonstopux*)
- case $cc_basename in
- CC*)
- _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
- _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
- # CC pic flag -KPIC is the default.
- ;;
- *)
- ;;
- esac
- ;;
- linux*)
- case $cc_basename in
- KCC*)
- # KAI C++ Compiler
- _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,'
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
- ;;
- icpc* | ecpc*)
- # Intel C++
- _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
- _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-static'
- ;;
- pgCC*)
- # Portland Group C++ compiler.
- _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fpic'
- _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-static'
- ;;
- cxx*)
- # Compaq C++
- # Make sure the PIC flag is empty. It appears that all Alpha
- # Linux and Compaq Tru64 Unix objects are PIC.
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=
- _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
- ;;
- *)
- ;;
- esac
- ;;
- lynxos*)
- ;;
- m88k*)
- ;;
- mvs*)
- case $cc_basename in
- cxx*)
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-W c,exportall'
- ;;
- *)
- ;;
- esac
- ;;
- netbsd*)
- ;;
- osf3* | osf4* | osf5*)
- case $cc_basename in
- KCC*)
- _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,'
- ;;
- RCC*)
- # Rational C++ 2.4.1
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
- ;;
- cxx*)
- # Digital/Compaq C++
- _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
- # Make sure the PIC flag is empty. It appears that all Alpha
- # Linux and Compaq Tru64 Unix objects are PIC.
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=
- _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
- ;;
- *)
- ;;
- esac
- ;;
- psos*)
- ;;
- sco*)
- case $cc_basename in
- CC*)
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
- ;;
- *)
- ;;
- esac
- ;;
- solaris*)
- case $cc_basename in
- CC*)
- # Sun C++ 4.2, 5.x and Centerline C++
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
- _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
- _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld '
- ;;
- gcx*)
- # Green Hills C++ Compiler
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-PIC'
- ;;
- *)
- ;;
- esac
- ;;
- sunos4*)
- case $cc_basename in
- CC*)
- # Sun C++ 4.x
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
- _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
- ;;
- lcc*)
- # Lucid
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
- ;;
- *)
- ;;
- esac
- ;;
- tandem*)
- case $cc_basename in
- NCC*)
- # NonStop-UX NCC 3.20
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
- ;;
- *)
- ;;
- esac
- ;;
- unixware*)
- ;;
- vxworks*)
- ;;
- *)
- _LT_AC_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
- ;;
- esac
- fi
-],
-[
- if test "$GCC" = yes; then
- _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
- _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-static'
-
- case $host_os in
- aix*)
- # All AIX code is PIC.
- if test "$host_cpu" = ia64; then
- # AIX 5 now supports IA64 processor
- _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
- fi
- ;;
-
- amigaos*)
- # FIXME: we need at least 68020 code to build shared libraries, but
- # adding the `-m68020' flag to GCC prevents building anything better,
- # like `-m68040'.
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4'
- ;;
-
- beos* | cygwin* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*)
- # PIC is the default for these OSes.
- ;;
-
- mingw* | pw32* | os2*)
- # This hack is so that the source file can tell whether it is being
- # built for inclusion in a dll (and should export symbols for example).
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT'
- ;;
-
- darwin* | rhapsody*)
- # PIC is the default on this platform
- # Common symbols not allowed in MH_DYLIB files
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common'
- ;;
-
- msdosdjgpp*)
- # Just because we use GCC doesn't mean we suddenly get shared libraries
- # on systems that don't support them.
- _LT_AC_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
- enable_shared=no
- ;;
-
- sysv4*MP*)
- if test -d /usr/nec; then
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic
- fi
- ;;
-
- hpux*)
- # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but
- # not for PA HP-UX.
- case "$host_cpu" in
- hppa*64*|ia64*)
- # +Z the default
- ;;
- *)
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
- ;;
- esac
- ;;
-
- *)
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
- ;;
- esac
- else
- # PORTME Check for flag to pass linker flags through the system compiler.
- case $host_os in
- aix*)
- _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
- if test "$host_cpu" = ia64; then
- # AIX 5 now supports IA64 processor
- _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
- else
- _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp'
- fi
- ;;
- darwin*)
- # PIC is the default on this platform
- # Common symbols not allowed in MH_DYLIB files
- case $cc_basename in
- xlc*)
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-qnocommon'
- _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
- ;;
- esac
- ;;
-
- mingw* | pw32* | os2*)
- # This hack is so that the source file can tell whether it is being
- # built for inclusion in a dll (and should export symbols for example).
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT'
- ;;
-
- hpux9* | hpux10* | hpux11*)
- _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
- # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but
- # not for PA HP-UX.
- case "$host_cpu" in
- hppa*64*|ia64*)
- # +Z the default
- ;;
- *)
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='+Z'
- ;;
- esac
- # Is there a better lt_prog_compiler_static that works with the bundled CC?
- _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive'
- ;;
-
- irix5* | irix6* | nonstopux*)
- _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
- # PIC (with -KPIC) is the default.
- _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
- ;;
-
- newsos6)
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
- _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
- ;;
-
- linux*)
- case $cc_basename in
- icc* | ecc*)
- _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
- _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-static'
- ;;
- pgcc* | pgf77* | pgf90*)
- # Portland Group compilers (*not* the Pentium gcc compiler,
- # which looks to be a dead project)
- _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fpic'
- _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-static'
- ;;
- ccc*)
- _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
- # All Alpha code is PIC.
- _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
- ;;
- esac
- ;;
-
- osf3* | osf4* | osf5*)
- _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
- # All OSF/1 code is PIC.
- _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
- ;;
-
- sco3.2v5*)
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-Kpic'
- _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-dn'
- ;;
-
- solaris*)
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
- _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
- case $cc_basename in
- f77* | f90* | f95*)
- _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ';;
- *)
- _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,';;
- esac
- ;;
-
- sunos4*)
- _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld '
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-PIC'
- _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
- ;;
-
- sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*)
- _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
- _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
- ;;
-
- sysv4*MP*)
- if test -d /usr/nec ;then
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-Kconform_pic'
- _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
- fi
- ;;
-
- unicos*)
- _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
- _LT_AC_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
- ;;
-
- uts4*)
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
- _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
- ;;
-
- *)
- _LT_AC_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
- ;;
- esac
- fi
-])
-AC_MSG_RESULT([$_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)])
-
-#
-# Check to make sure the PIC flag actually works.
-#
-if test -n "$_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)"; then
- AC_LIBTOOL_COMPILER_OPTION([if $compiler PIC flag $_LT_AC_TAGVAR(lt_prog_compiler_pic, $1) works],
- _LT_AC_TAGVAR(lt_prog_compiler_pic_works, $1),
- [$_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)ifelse([$1],[],[ -DPIC],[ifelse([$1],[CXX],[ -DPIC],[])])], [],
- [case $_LT_AC_TAGVAR(lt_prog_compiler_pic, $1) in
- "" | " "*) ;;
- *) _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=" $_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)" ;;
- esac],
- [_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=
- _LT_AC_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no])
-fi
-case "$host_os" in
- # For platforms which do not support PIC, -DPIC is meaningless:
- *djgpp*)
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=
- ;;
- *)
- _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)="$_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)ifelse([$1],[],[ -DPIC],[ifelse([$1],[CXX],[ -DPIC],[])])"
- ;;
-esac
-])
-
-
-# AC_LIBTOOL_PROG_LD_SHLIBS([TAGNAME])
-# ------------------------------------
-# See if the linker supports building shared libraries.
-AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS],
-[AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries])
-ifelse([$1],[CXX],[
- _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
- case $host_os in
- aix4* | aix5*)
- # If we're using GNU nm, then we don't want the "-C" option.
- # -C means demangle to AIX nm, but means don't demangle with GNU nm
- if $NM -V 2>&1 | grep 'GNU' > /dev/null; then
- _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\[$]2 == "T") || (\[$]2 == "D") || (\[$]2 == "B")) && ([substr](\[$]3,1,1) != ".")) { print \[$]3 } }'\'' | sort -u > $export_symbols'
- else
- _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\[$]2 == "T") || (\[$]2 == "D") || (\[$]2 == "B")) && ([substr](\[$]3,1,1) != ".")) { print \[$]3 } }'\'' | sort -u > $export_symbols'
- fi
- ;;
- pw32*)
- _LT_AC_TAGVAR(export_symbols_cmds, $1)="$ltdll_cmds"
- ;;
- cygwin* | mingw*)
- _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]] /s/.* \([[^ ]]*\)/\1 DATA/;/^.* __nm__/s/^.* __nm__\([[^ ]]*\) [[^ ]]*/\1 DATA/;/^I /d;/^[[AITW]] /s/.* //'\'' | sort | uniq > $export_symbols'
- ;;
- *)
- _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
- ;;
- esac
-],[
- runpath_var=
- _LT_AC_TAGVAR(allow_undefined_flag, $1)=
- _LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1)=no
- _LT_AC_TAGVAR(archive_cmds, $1)=
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)=
- _LT_AC_TAGVAR(old_archive_From_new_cmds, $1)=
- _LT_AC_TAGVAR(old_archive_from_expsyms_cmds, $1)=
- _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)=
- _LT_AC_TAGVAR(whole_archive_flag_spec, $1)=
- _LT_AC_TAGVAR(thread_safe_flag_spec, $1)=
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)=
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1)=
- _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=
- _LT_AC_TAGVAR(hardcode_direct, $1)=no
- _LT_AC_TAGVAR(hardcode_minus_L, $1)=no
- _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=unsupported
- _LT_AC_TAGVAR(link_all_deplibs, $1)=unknown
- _LT_AC_TAGVAR(hardcode_automatic, $1)=no
- _LT_AC_TAGVAR(module_cmds, $1)=
- _LT_AC_TAGVAR(module_expsym_cmds, $1)=
- _LT_AC_TAGVAR(always_export_symbols, $1)=no
- _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
- # include_expsyms should be a list of space-separated symbols to be *always*
- # included in the symbol list
- _LT_AC_TAGVAR(include_expsyms, $1)=
- # exclude_expsyms can be an extended regexp of symbols to exclude
- # it will be wrapped by ` (' and `)$', so one must not match beginning or
- # end of line. Example: `a|bc|.*d.*' will exclude the symbols `a' and `bc',
- # as well as any symbol that contains `d'.
- _LT_AC_TAGVAR(exclude_expsyms, $1)="_GLOBAL_OFFSET_TABLE_"
- # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out
- # platforms (ab)use it in PIC code, but their linkers get confused if
- # the symbol is explicitly referenced. Since portable code cannot
- # rely on this symbol name, it's probably fine to never include it in
- # preloaded symbol tables.
- extract_expsyms_cmds=
- # Just being paranoid about ensuring that cc_basename is set.
- _LT_CC_BASENAME([$compiler])
- case $host_os in
- cygwin* | mingw* | pw32*)
- # FIXME: the MSVC++ port hasn't been tested in a loooong time
- # When not using gcc, we currently assume that we are using
- # Microsoft Visual C++.
- if test "$GCC" != yes; then
- with_gnu_ld=no
- fi
- ;;
- openbsd*)
- with_gnu_ld=no
- ;;
- esac
-
- _LT_AC_TAGVAR(ld_shlibs, $1)=yes
- if test "$with_gnu_ld" = yes; then
- # If archive_cmds runs LD, not CC, wlarc should be empty
- wlarc='${wl}'
-
- # Set some defaults for GNU ld with shared library support. These
- # are reset later if shared libraries are not supported. Putting them
- # here allows them to be overridden if necessary.
- runpath_var=LD_RUN_PATH
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}--rpath ${wl}$libdir'
- _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
- # ancient GNU ld didn't support --whole-archive et. al.
- if $LD --help 2>&1 | grep 'no-whole-archive' > /dev/null; then
- _LT_AC_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
- else
- _LT_AC_TAGVAR(whole_archive_flag_spec, $1)=
- fi
- supports_anon_versioning=no
- case `$LD -v 2>/dev/null` in
- *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.10.*) ;; # catch versions < 2.11
- *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ...
- *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ...
- *\ 2.11.*) ;; # other 2.11 versions
- *) supports_anon_versioning=yes ;;
- esac
-
- # See if GNU ld supports shared libraries.
- case $host_os in
- aix3* | aix4* | aix5*)
- # On AIX/PPC, the GNU linker is very broken
- if test "$host_cpu" != ia64; then
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- cat <<EOF 1>&2
-
-*** Warning: the GNU linker, at least up to release 2.9.1, is reported
-*** to be unable to reliably create shared libraries on AIX.
-*** Therefore, libtool is disabling shared libraries support. If you
-*** really care for shared libraries, you may want to modify your PATH
-*** so that a non-GNU linker is found, and then restart.
-
-EOF
- fi
- ;;
-
- amigaos*)
- _LT_AC_TAGVAR(archive_cmds, $1)='$rm $output_objdir/a2ixlibrary.data~$echo "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$echo "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$echo "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$echo "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
- _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
-
- # Samuel A. Falvo II <kc5tja@dolphin.openprojects.net> reports
- # that the semantics of dynamic libraries on AmigaOS, at least up
- # to version 4, is to share data among multiple programs linked
- # with the same dynamic library. Since this doesn't match the
- # behavior of shared libraries on other platforms, we can't use
- # them.
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- ;;
-
- beos*)
- if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
- _LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported
- # Joseph Beckenbach <jrb3@best.com> says some releases of gcc
- # support --undefined. This deserves some investigation. FIXME
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
- else
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- fi
- ;;
-
- cygwin* | mingw* | pw32*)
- # _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless,
- # as there is no search path for DLLs.
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
- _LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported
- _LT_AC_TAGVAR(always_export_symbols, $1)=no
- _LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1)=yes
- _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]] /s/.* \([[^ ]]*\)/\1 DATA/'\'' | $SED -e '\''/^[[AITW]] /s/.* //'\'' | sort | uniq > $export_symbols'
-
- if $LD --help 2>&1 | grep 'auto-import' > /dev/null; then
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--image-base=0x10000000 ${wl}--out-implib,$lib'
- # If the export-symbols file already is a .def file (1st line
- # is EXPORTS), use it as is; otherwise, prepend...
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
- cp $export_symbols $output_objdir/$soname.def;
- else
- echo EXPORTS > $output_objdir/$soname.def;
- cat $export_symbols >> $output_objdir/$soname.def;
- fi~
- $CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--image-base=0x10000000 ${wl}--out-implib,$lib'
- else
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- fi
- ;;
-
- linux*)
- if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
- tmp_addflag=
- case $cc_basename,$host_cpu in
- pgcc*) # Portland Group C compiler
- _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive,`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive'
- tmp_addflag=' $pic_flag'
- ;;
- pgf77* | pgf90* ) # Portland Group f77 and f90 compilers
- _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive,`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive'
- tmp_addflag=' $pic_flag -Mnomain' ;;
- ecc*,ia64* | icc*,ia64*) # Intel C compiler on ia64
- tmp_addflag=' -i_dynamic' ;;
- efc*,ia64* | ifort*,ia64*) # Intel Fortran compiler on ia64
- tmp_addflag=' -i_dynamic -nofor_main' ;;
- ifc* | ifort*) # Intel Fortran compiler
- tmp_addflag=' -nofor_main' ;;
- esac
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared'"$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
-
- if test $supports_anon_versioning = yes; then
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$echo "{ global:" > $output_objdir/$libname.ver~
- cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
- $echo "local: *; };" >> $output_objdir/$libname.ver~
- $CC -shared'"$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib'
- fi
- else
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- fi
- ;;
-
- netbsd*)
- if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then
- _LT_AC_TAGVAR(archive_cmds, $1)='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib'
- wlarc=
- else
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
- fi
- ;;
-
- solaris* | sysv5*)
- if $LD -v 2>&1 | grep 'BFD 2\.8' > /dev/null; then
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- cat <<EOF 1>&2
-
-*** Warning: The releases 2.8.* of the GNU linker cannot reliably
-*** create shared libraries on Solaris systems. Therefore, libtool
-*** is disabling shared libraries support. We urge you to upgrade GNU
-*** binutils to release 2.9.1 or newer. Another option is to modify
-*** your PATH or compiler configuration so that the native linker is
-*** used, and then restart.
-
-EOF
- elif $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
- else
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- fi
- ;;
-
- sunos4*)
- _LT_AC_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags'
- wlarc=
- _LT_AC_TAGVAR(hardcode_direct, $1)=yes
- _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
- ;;
-
- *)
- if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
- else
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- fi
- ;;
- esac
-
- if test "$_LT_AC_TAGVAR(ld_shlibs, $1)" = no; then
- runpath_var=
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)=
- _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)=
- _LT_AC_TAGVAR(whole_archive_flag_spec, $1)=
- fi
- else
- # PORTME fill in a description of your system's linker (not GNU ld)
- case $host_os in
- aix3*)
- _LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported
- _LT_AC_TAGVAR(always_export_symbols, $1)=yes
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname'
- # Note: this linker hardcodes the directories in LIBPATH if there
- # are no directories specified by -L.
- _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
- if test "$GCC" = yes && test -z "$link_static_flag"; then
- # Neither direct hardcoding nor static linking is supported with a
- # broken collect2.
- _LT_AC_TAGVAR(hardcode_direct, $1)=unsupported
- fi
- ;;
-
- aix4* | aix5*)
- if test "$host_cpu" = ia64; then
- # On IA64, the linker does run time linking by default, so we don't
- # have to do anything special.
- aix_use_runtimelinking=no
- exp_sym_flag='-Bexport'
- no_entry_flag=""
- else
- # If we're using GNU nm, then we don't want the "-C" option.
- # -C means demangle to AIX nm, but means don't demangle with GNU nm
- if $NM -V 2>&1 | grep 'GNU' > /dev/null; then
- _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\[$]2 == "T") || (\[$]2 == "D") || (\[$]2 == "B")) && ([substr](\[$]3,1,1) != ".")) { print \[$]3 } }'\'' | sort -u > $export_symbols'
- else
- _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\[$]2 == "T") || (\[$]2 == "D") || (\[$]2 == "B")) && ([substr](\[$]3,1,1) != ".")) { print \[$]3 } }'\'' | sort -u > $export_symbols'
- fi
- aix_use_runtimelinking=no
-
- # Test if we are trying to use run time linking or normal
- # AIX style linking. If -brtl is somewhere in LDFLAGS, we
- # need to do runtime linking.
- case $host_os in aix4.[[23]]|aix4.[[23]].*|aix5*)
- for ld_flag in $LDFLAGS; do
- if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then
- aix_use_runtimelinking=yes
- break
- fi
- done
- esac
-
- exp_sym_flag='-bexport'
- no_entry_flag='-bnoentry'
- fi
-
- # When large executables or shared objects are built, AIX ld can
- # have problems creating the table of contents. If linking a library
- # or program results in "error TOC overflow" add -mminimal-toc to
- # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not
- # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS.
-
- _LT_AC_TAGVAR(archive_cmds, $1)=''
- _LT_AC_TAGVAR(hardcode_direct, $1)=yes
- _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=':'
- _LT_AC_TAGVAR(link_all_deplibs, $1)=yes
-
- if test "$GCC" = yes; then
- case $host_os in aix4.[[012]]|aix4.[[012]].*)
- # We only want to do this on AIX 4.2 and lower, the check
- # below for broken collect2 doesn't work under 4.3+
- collect2name=`${CC} -print-prog-name=collect2`
- if test -f "$collect2name" && \
- strings "$collect2name" | grep resolve_lib_name >/dev/null
- then
- # We have reworked collect2
- _LT_AC_TAGVAR(hardcode_direct, $1)=yes
- else
- # We have old collect2
- _LT_AC_TAGVAR(hardcode_direct, $1)=unsupported
- # It fails to find uninstalled libraries when the uninstalled
- # path is not listed in the libpath. Setting hardcode_minus_L
- # to unsupported forces relinking
- _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
- _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=
- fi
- esac
- shared_flag='-shared'
- if test "$aix_use_runtimelinking" = yes; then
- shared_flag="$shared_flag "'${wl}-G'
- fi
- else
- # not using gcc
- if test "$host_cpu" = ia64; then
- # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release
- # chokes on -Wl,-G. The following line is correct:
- shared_flag='-G'
- else
- if test "$aix_use_runtimelinking" = yes; then
- shared_flag='${wl}-G'
- else
- shared_flag='${wl}-bM:SRE'
- fi
- fi
- fi
-
- # It seems that -bexpall does not export symbols beginning with
- # underscore (_), so it is better to generate a list of symbols to export.
- _LT_AC_TAGVAR(always_export_symbols, $1)=yes
- if test "$aix_use_runtimelinking" = yes; then
- # Warning - without using the other runtime loading flags (-brtl),
- # -berok will link without error, but may produce a broken library.
- _LT_AC_TAGVAR(allow_undefined_flag, $1)='-berok'
- # Determine the default libpath from the value encoded in an empty executable.
- _LT_AC_SYS_LIBPATH_AIX
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)="\$CC"' -o $output_objdir/$soname $libobjs $deplibs $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then echo "${wl}${allow_undefined_flag}"; else :; fi` '"\${wl}$no_entry_flag \${wl}$exp_sym_flag:\$export_symbols $shared_flag"
- else
- if test "$host_cpu" = ia64; then
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib'
- _LT_AC_TAGVAR(allow_undefined_flag, $1)="-z nodefs"
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$no_entry_flag \${wl}$exp_sym_flag:\$export_symbols"
- else
- # Determine the default libpath from the value encoded in an empty executable.
- _LT_AC_SYS_LIBPATH_AIX
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
- # Warning - without using the other run time loading flags,
- # -berok will link without error, but may produce a broken library.
- _LT_AC_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok'
- _LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok'
- # -bexpall does not export symbols beginning with underscore (_)
- _LT_AC_TAGVAR(always_export_symbols, $1)=yes
- # Exported symbols can be pulled into shared objects from archives
- _LT_AC_TAGVAR(whole_archive_flag_spec, $1)=' '
- _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=yes
- # This is similar to how AIX traditionally builds it's shared libraries.
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs $compiler_flags ${wl}-bE:$export_symbols ${wl}-bnoentry${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname'
- fi
- fi
- ;;
-
- amigaos*)
- _LT_AC_TAGVAR(archive_cmds, $1)='$rm $output_objdir/a2ixlibrary.data~$echo "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$echo "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$echo "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$echo "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
- _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
- # see comment about different semantics on the GNU ld section
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- ;;
-
- bsdi[[45]]*)
- _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)=-rdynamic
- ;;
-
- cygwin* | mingw* | pw32*)
- # When not using gcc, we currently assume that we are using
- # Microsoft Visual C++.
- # hardcode_libdir_flag_spec is actually meaningless, as there is
- # no search path for DLLs.
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)=' '
- _LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported
- # Tell ltmain to make .lib files, not .a files.
- libext=lib
- # Tell ltmain to make .dll files, not .so files.
- shrext_cmds=".dll"; shrext="$shrext_cmds"
- # FIXME: Setting linknames here is a bad hack.
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -o $lib $libobjs $compiler_flags `echo "$deplibs" | $SED -e '\''s/ -lc$//'\''` -link -dll~linknames='
- # The linker will automatically build a .lib file if we build a DLL.
- _LT_AC_TAGVAR(old_archive_From_new_cmds, $1)='true'
- # FIXME: Should let the user specify the lib program.
- _LT_AC_TAGVAR(old_archive_cmds, $1)='lib /OUT:$oldlib$oldobjs$old_deplibs'
- _LT_AC_TAGVAR(fix_srcfile_path, $1)='`cygpath -w "$srcfile"`'
- _LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1)=yes
- ;;
-
- darwin* | rhapsody*)
- case "$host_os" in
- rhapsody* | darwin1.[[012]])
- _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-undefined ${wl}suppress'
- ;;
- *) # Darwin 1.3 on
- if test -z ${MACOSX_DEPLOYMENT_TARGET} ; then
- _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-flat_namespace ${wl}-undefined ${wl}suppress'
- else
- case ${MACOSX_DEPLOYMENT_TARGET} in
- 10.[[012]])
- _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-flat_namespace ${wl}-undefined ${wl}suppress'
- ;;
- 10.*)
- _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-undefined ${wl}dynamic_lookup'
- ;;
- esac
- fi
- ;;
- esac
- _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
- _LT_AC_TAGVAR(hardcode_direct, $1)=no
- _LT_AC_TAGVAR(hardcode_automatic, $1)=yes
- _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=unsupported
- _LT_AC_TAGVAR(whole_archive_flag_spec, $1)=''
- _LT_AC_TAGVAR(link_all_deplibs, $1)=yes
- if test "$GCC" = yes ; then
- output_verbose_link_cmd='echo'
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -dynamiclib $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags -install_name $rpath/$soname $verstring'
- _LT_AC_TAGVAR(module_cmds, $1)='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags'
- # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin ld's
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -dynamiclib $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags -install_name $rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
- _LT_AC_TAGVAR(module_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
- else
- case $cc_basename in
- xlc*)
- output_verbose_link_cmd='echo'
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -qmkshrobj $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}`echo $rpath/$soname` $verstring'
- _LT_AC_TAGVAR(module_cmds, $1)='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags'
- # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin ld's
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -qmkshrobj $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}$rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
- _LT_AC_TAGVAR(module_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
- ;;
- *)
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- ;;
- esac
- fi
- ;;
-
- dgux*)
- _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
- _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
- ;;
-
- freebsd1*)
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- ;;
-
- # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor
- # support. Future versions do this automatically, but an explicit c++rt0.o
- # does not break anything, and helps significantly (at the cost of a little
- # extra space).
- freebsd2.2*)
- _LT_AC_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o'
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
- _LT_AC_TAGVAR(hardcode_direct, $1)=yes
- _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
- ;;
-
- # Unfortunately, older versions of FreeBSD 2 do not have this feature.
- freebsd2*)
- _LT_AC_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
- _LT_AC_TAGVAR(hardcode_direct, $1)=yes
- _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
- _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
- ;;
-
- # FreeBSD 3 and greater uses gcc -shared to do shared libraries.
- freebsd* | kfreebsd*-gnu | dragonfly*)
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -o $lib $libobjs $deplibs $compiler_flags'
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
- _LT_AC_TAGVAR(hardcode_direct, $1)=yes
- _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
- ;;
-
- hpux9*)
- if test "$GCC" = yes; then
- _LT_AC_TAGVAR(archive_cmds, $1)='$rm $output_objdir/$soname~$CC -shared -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
- else
- _LT_AC_TAGVAR(archive_cmds, $1)='$rm $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
- fi
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
- _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
- _LT_AC_TAGVAR(hardcode_direct, $1)=yes
-
- # hardcode_minus_L: Not really in the search PATH,
- # but as the default location of the library.
- _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
- _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
- ;;
-
- hpux10* | hpux11*)
- if test "$GCC" = yes -a "$with_gnu_ld" = no; then
- case "$host_cpu" in
- hppa*64*|ia64*)
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
- ;;
- *)
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
- ;;
- esac
- else
- case "$host_cpu" in
- hppa*64*|ia64*)
- _LT_AC_TAGVAR(archive_cmds, $1)='$LD -b +h $soname -o $lib $libobjs $deplibs $linker_flags'
- ;;
- *)
- _LT_AC_TAGVAR(archive_cmds, $1)='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags'
- ;;
- esac
- fi
- if test "$with_gnu_ld" = no; then
- case "$host_cpu" in
- hppa*64*)
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1)='+b $libdir'
- _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
- _LT_AC_TAGVAR(hardcode_direct, $1)=no
- _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
- ;;
- ia64*)
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
- _LT_AC_TAGVAR(hardcode_direct, $1)=no
- _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
-
- # hardcode_minus_L: Not really in the search PATH,
- # but as the default location of the library.
- _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
- ;;
- *)
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
- _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
- _LT_AC_TAGVAR(hardcode_direct, $1)=yes
- _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
-
- # hardcode_minus_L: Not really in the search PATH,
- # but as the default location of the library.
- _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
- ;;
- esac
- fi
- ;;
-
- irix5* | irix6* | nonstopux*)
- if test "$GCC" = yes; then
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
- else
- _LT_AC_TAGVAR(archive_cmds, $1)='$LD -shared $libobjs $deplibs $linker_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib'
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1)='-rpath $libdir'
- fi
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
- _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
- _LT_AC_TAGVAR(link_all_deplibs, $1)=yes
- ;;
-
- netbsd*)
- if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then
- _LT_AC_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out
- else
- _LT_AC_TAGVAR(archive_cmds, $1)='$LD -shared -o $lib $libobjs $deplibs $linker_flags' # ELF
- fi
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
- _LT_AC_TAGVAR(hardcode_direct, $1)=yes
- _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
- ;;
-
- newsos6)
- _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
- _LT_AC_TAGVAR(hardcode_direct, $1)=yes
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
- _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
- _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
- ;;
-
- openbsd*)
- _LT_AC_TAGVAR(hardcode_direct, $1)=yes
- _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
- if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-retain-symbols-file,$export_symbols'
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
- _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
- else
- case $host_os in
- openbsd[[01]].* | openbsd2.[[0-7]] | openbsd2.[[0-7]].*)
- _LT_AC_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
- ;;
- *)
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
- ;;
- esac
- fi
- ;;
-
- os2*)
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
- _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
- _LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported
- _LT_AC_TAGVAR(archive_cmds, $1)='$echo "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$echo "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~$echo DATA >> $output_objdir/$libname.def~$echo " SINGLE NONSHARED" >> $output_objdir/$libname.def~$echo EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def'
- _LT_AC_TAGVAR(old_archive_From_new_cmds, $1)='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def'
- ;;
-
- osf3*)
- if test "$GCC" = yes; then
- _LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
- else
- _LT_AC_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*'
- _LT_AC_TAGVAR(archive_cmds, $1)='$LD -shared${allow_undefined_flag} $libobjs $deplibs $linker_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib'
- fi
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
- _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
- ;;
-
- osf4* | osf5*) # as osf3* with the addition of -msym flag
- if test "$GCC" = yes; then
- _LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
- else
- _LT_AC_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*'
- _LT_AC_TAGVAR(archive_cmds, $1)='$LD -shared${allow_undefined_flag} $libobjs $deplibs $linker_flags -msym -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib'
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; echo "-hidden">> $lib.exp~
- $LD -shared${allow_undefined_flag} -input $lib.exp $linker_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib~$rm $lib.exp'
-
- # Both c and cxx compiler support -rpath directly
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir'
- fi
- _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
- ;;
-
- sco3.2v5*)
- _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
- _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
- _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Bexport'
- runpath_var=LD_RUN_PATH
- hardcode_runpath_var=yes
- ;;
-
- solaris*)
- _LT_AC_TAGVAR(no_undefined_flag, $1)=' -z text'
- if test "$GCC" = yes; then
- wlarc='${wl}'
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~
- $CC -shared ${wl}-M ${wl}$lib.exp ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags~$rm $lib.exp'
- else
- wlarc=''
- _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags'
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~
- $LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$rm $lib.exp'
- fi
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
- _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
- case $host_os in
- solaris2.[[0-5]] | solaris2.[[0-5]].*) ;;
- *)
- # The compiler driver will combine linker options so we
- # cannot just pass the convience library names through
- # without $wl, iff we do not link with $LD.
- # Luckily, gcc supports the same syntax we need for Sun Studio.
- # Supported since Solaris 2.6 (maybe 2.5.1?)
- case $wlarc in
- '')
- _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract' ;;
- *)
- _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}-z ${wl}defaultextract' ;;
- esac ;;
- esac
- _LT_AC_TAGVAR(link_all_deplibs, $1)=yes
- ;;
-
- sunos4*)
- if test "x$host_vendor" = xsequent; then
- # Use $CC to link under sequent, because it throws in some extra .o
- # files that make .init and .fini sections work.
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h $soname -o $lib $libobjs $deplibs $compiler_flags'
- else
- _LT_AC_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags'
- fi
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
- _LT_AC_TAGVAR(hardcode_direct, $1)=yes
- _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
- _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
- ;;
-
- sysv4)
- case $host_vendor in
- sni)
- _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
- _LT_AC_TAGVAR(hardcode_direct, $1)=yes # is this really true???
- ;;
- siemens)
- ## LD is ld it makes a PLAMLIB
- ## CC just makes a GrossModule.
- _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -o $lib $libobjs $deplibs $linker_flags'
- _LT_AC_TAGVAR(reload_cmds, $1)='$CC -r -o $output$reload_objs'
- _LT_AC_TAGVAR(hardcode_direct, $1)=no
- ;;
- motorola)
- _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
- _LT_AC_TAGVAR(hardcode_direct, $1)=no #Motorola manual says yes, but my tests say they lie
- ;;
- esac
- runpath_var='LD_RUN_PATH'
- _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
- ;;
-
- sysv4.3*)
- _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
- _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
- _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='-Bexport'
- ;;
-
- sysv4*MP*)
- if test -d /usr/nec; then
- _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
- _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
- runpath_var=LD_RUN_PATH
- hardcode_runpath_var=yes
- _LT_AC_TAGVAR(ld_shlibs, $1)=yes
- fi
- ;;
-
- sysv4.2uw2*)
- _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -o $lib $libobjs $deplibs $linker_flags'
- _LT_AC_TAGVAR(hardcode_direct, $1)=yes
- _LT_AC_TAGVAR(hardcode_minus_L, $1)=no
- _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
- hardcode_runpath_var=yes
- runpath_var=LD_RUN_PATH
- ;;
-
- sysv5OpenUNIX8* | sysv5UnixWare7* | sysv5uw[[78]]* | unixware7*)
- _LT_AC_TAGVAR(no_undefined_flag, $1)='${wl}-z ${wl}text'
- if test "$GCC" = yes; then
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
- else
- _LT_AC_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
- fi
- runpath_var='LD_RUN_PATH'
- _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
- ;;
-
- sysv5*)
- _LT_AC_TAGVAR(no_undefined_flag, $1)=' -z text'
- # $CC -shared without GNU ld will not create a library from C++
- # object files and a static libstdc++, better avoid it by now
- _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags'
- _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~
- $LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$rm $lib.exp'
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)=
- _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
- runpath_var='LD_RUN_PATH'
- ;;
-
- uts4*)
- _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
- _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
- _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
- ;;
-
- *)
- _LT_AC_TAGVAR(ld_shlibs, $1)=no
- ;;
- esac
- fi
-])
-AC_MSG_RESULT([$_LT_AC_TAGVAR(ld_shlibs, $1)])
-test "$_LT_AC_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no
-
-variables_saved_for_relink="PATH $shlibpath_var $runpath_var"
-if test "$GCC" = yes; then
- variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH"
-fi
-
-#
-# Do we need to explicitly link libc?
-#
-case "x$_LT_AC_TAGVAR(archive_cmds_need_lc, $1)" in
-x|xyes)
- # Assume -lc should be added
- _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=yes
-
- if test "$enable_shared" = yes && test "$GCC" = yes; then
- case $_LT_AC_TAGVAR(archive_cmds, $1) in
- *'~'*)
- # FIXME: we may have to deal with multi-command sequences.
- ;;
- '$CC '*)
- # Test whether the compiler implicitly links with -lc since on some
- # systems, -lgcc has to come before -lc. If gcc already passes -lc
- # to ld, don't add -lc before -lgcc.
- AC_MSG_CHECKING([whether -lc should be explicitly linked in])
- $rm conftest*
- printf "$lt_simple_compile_test_code" > conftest.$ac_ext
-
- if AC_TRY_EVAL(ac_compile) 2>conftest.err; then
- soname=conftest
- lib=conftest
- libobjs=conftest.$ac_objext
- deplibs=
- wl=$_LT_AC_TAGVAR(lt_prog_compiler_wl, $1)
- compiler_flags=-v
- linker_flags=-v
- verstring=
- output_objdir=.
- libname=conftest
- lt_save_allow_undefined_flag=$_LT_AC_TAGVAR(allow_undefined_flag, $1)
- _LT_AC_TAGVAR(allow_undefined_flag, $1)=
- if AC_TRY_EVAL(_LT_AC_TAGVAR(archive_cmds, $1) 2\>\&1 \| grep \" -lc \" \>/dev/null 2\>\&1)
- then
- _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
- else
- _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=yes
- fi
- _LT_AC_TAGVAR(allow_undefined_flag, $1)=$lt_save_allow_undefined_flag
- else
- cat conftest.err 1>&5
- fi
- $rm conftest*
- AC_MSG_RESULT([$_LT_AC_TAGVAR(archive_cmds_need_lc, $1)])
- ;;
- esac
- fi
- ;;
-esac
-])# AC_LIBTOOL_PROG_LD_SHLIBS
-
-
-# _LT_AC_FILE_LTDLL_C
-# -------------------
-# Be careful that the start marker always follows a newline.
-AC_DEFUN([_LT_AC_FILE_LTDLL_C], [
-# /* ltdll.c starts here */
-# #define WIN32_LEAN_AND_MEAN
-# #include <windows.h>
-# #undef WIN32_LEAN_AND_MEAN
-# #include <stdio.h>
-#
-# #ifndef __CYGWIN__
-# # ifdef __CYGWIN32__
-# # define __CYGWIN__ __CYGWIN32__
-# # endif
-# #endif
-#
-# #ifdef __cplusplus
-# extern "C" {
-# #endif
-# BOOL APIENTRY DllMain (HINSTANCE hInst, DWORD reason, LPVOID reserved);
-# #ifdef __cplusplus
-# }
-# #endif
-#
-# #ifdef __CYGWIN__
-# #include <cygwin/cygwin_dll.h>
-# DECLARE_CYGWIN_DLL( DllMain );
-# #endif
-# HINSTANCE __hDllInstance_base;
-#
-# BOOL APIENTRY
-# DllMain (HINSTANCE hInst, DWORD reason, LPVOID reserved)
-# {
-# __hDllInstance_base = hInst;
-# return TRUE;
-# }
-# /* ltdll.c ends here */
-])# _LT_AC_FILE_LTDLL_C
-
-
-# _LT_AC_TAGVAR(VARNAME, [TAGNAME])
-# ---------------------------------
-AC_DEFUN([_LT_AC_TAGVAR], [ifelse([$2], [], [$1], [$1_$2])])
-
-
-# old names
-AC_DEFUN([AM_PROG_LIBTOOL], [AC_PROG_LIBTOOL])
-AC_DEFUN([AM_ENABLE_SHARED], [AC_ENABLE_SHARED($@)])
-AC_DEFUN([AM_ENABLE_STATIC], [AC_ENABLE_STATIC($@)])
-AC_DEFUN([AM_DISABLE_SHARED], [AC_DISABLE_SHARED($@)])
-AC_DEFUN([AM_DISABLE_STATIC], [AC_DISABLE_STATIC($@)])
-AC_DEFUN([AM_PROG_LD], [AC_PROG_LD])
-AC_DEFUN([AM_PROG_NM], [AC_PROG_NM])
-
-# This is just to silence aclocal about the macro not being used
-ifelse([AC_DISABLE_FAST_INSTALL])
-
-AC_DEFUN([LT_AC_PROG_GCJ],
-[AC_CHECK_TOOL(GCJ, gcj, no)
- test "x${GCJFLAGS+set}" = xset || GCJFLAGS="-g -O2"
- AC_SUBST(GCJFLAGS)
-])
-
-AC_DEFUN([LT_AC_PROG_RC],
-[AC_CHECK_TOOL(RC, windres, no)
-])
-
-############################################################
-# NOTE: This macro has been submitted for inclusion into #
-# GNU Autoconf as AC_PROG_SED. When it is available in #
-# a released version of Autoconf we should remove this #
-# macro and use it instead. #
-############################################################
-# LT_AC_PROG_SED
-# --------------
-# Check for a fully-functional sed program, that truncates
-# as few characters as possible. Prefer GNU sed if found.
-AC_DEFUN([LT_AC_PROG_SED],
-[AC_MSG_CHECKING([for a sed that does not truncate output])
-AC_CACHE_VAL(lt_cv_path_SED,
-[# Loop through the user's path and test for sed and gsed.
-# Then use that list of sed's as ones to test for truncation.
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
- IFS=$as_save_IFS
- test -z "$as_dir" && as_dir=.
- for lt_ac_prog in sed gsed; do
- for ac_exec_ext in '' $ac_executable_extensions; do
- if $as_executable_p "$as_dir/$lt_ac_prog$ac_exec_ext"; then
- lt_ac_sed_list="$lt_ac_sed_list $as_dir/$lt_ac_prog$ac_exec_ext"
- fi
- done
- done
-done
-lt_ac_max=0
-lt_ac_count=0
-# Add /usr/xpg4/bin/sed as it is typically found on Solaris
-# along with /bin/sed that truncates output.
-for lt_ac_sed in $lt_ac_sed_list /usr/xpg4/bin/sed; do
- test ! -f $lt_ac_sed && continue
- cat /dev/null > conftest.in
- lt_ac_count=0
- echo $ECHO_N "0123456789$ECHO_C" >conftest.in
- # Check for GNU sed and select it if it is found.
- if "$lt_ac_sed" --version 2>&1 < /dev/null | grep 'GNU' > /dev/null; then
- lt_cv_path_SED=$lt_ac_sed
- break
- fi
- while true; do
- cat conftest.in conftest.in >conftest.tmp
- mv conftest.tmp conftest.in
- cp conftest.in conftest.nl
- echo >>conftest.nl
- $lt_ac_sed -e 's/a$//' < conftest.nl >conftest.out || break
- cmp -s conftest.out conftest.nl || break
- # 10000 chars as input seems more than enough
- test $lt_ac_count -gt 10 && break
- lt_ac_count=`expr $lt_ac_count + 1`
- if test $lt_ac_count -gt $lt_ac_max; then
- lt_ac_max=$lt_ac_count
- lt_cv_path_SED=$lt_ac_sed
- fi
- done
-done
-])
-SED=$lt_cv_path_SED
-AC_MSG_RESULT([$SED])
-])
diff --git a/m4/macosx.m4 b/m4/macosx.m4
new file mode 100644
index 000000000..0151b41e9
--- /dev/null
+++ b/m4/macosx.m4
@@ -0,0 +1,43 @@
+AC_DEFUN([MACOSX_UNIVERSAL_BINARIES], [
+ AC_ARG_ENABLE([macosx-universal],
+ AS_HELP_STRING([--enable-macosx-universal], [build universal binaries for Mac OS X)]),
+ [], [enable_macosx_universal="no"])
+ if test x"$enable_macosx_universal" != x"no" ; then
+ case "$host_os" in
+ *darwin*)
+ dnl x64_64 and ppc64 binaries could also be built, but there is no
+ dnl version of Mac OS X currently shipping that can run them, so
+ dnl do not enable them by default for now.
+ if test x"$enable_macosx_universal" = x"yes" ; then
+ UNIVERSAL_ARCHES="i386 ppc"
+ else
+ UNIVERSAL_ARCHES=`echo "$enable_macosx_universal" | sed -e 's/,/ /g'`
+ fi
+ ;;
+ *)
+ AC_MSG_ERROR([Universal binaries can only be built on Darwin])
+ ;;
+ esac
+ AC_SUBST(UNIVERSAL_ARCHES)
+
+ CFLAGS="$CFLAGS -isysroot /Developer/SDKs/MacOSX10.4u.sdk"
+ LDFLAGS="$LDFLAGS -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk"
+
+ if test x"$UNIVERSAL_ARCHES" != x"" ; then
+ # Forcibly disable dependency tracking for Universal builds, because -M
+ # does not work with multiple -arch arguments on the gcc command-line.
+ ac_tool_warned=yes
+ cross_compiling=yes
+ enable_dependency_tracking=no
+ host="`echo $host | sed -e s/$host_cpu/universal/g`"
+ host_cpu=universal
+
+ AC_DEFINE([XINE_MACOSX_UNIVERSAL_BINARY], 1, [Define this if a universal binary is being built for Mac OS X])
+ for arch in $UNIVERSAL_ARCHES ; do
+ UNIVERSAL_CFLAGS="$UNIVERSAL_CFLAGS -arch $arch"
+ UNIVERSAL_LDFLAGS="$UNIVERSAL_LDFLAGS -arch $arch"
+ done
+ fi
+ fi
+ AM_CONDITIONAL([MACOSX_UNIVERSAL_BINARY], [test x"$enable_macosx_universal" = x"yes"])
+])dnl MACOSX_UNIVERSAL_BINARIES
diff --git a/m4/nls.m4 b/m4/nls.m4
deleted file mode 100644
index 2082c3b24..000000000
--- a/m4/nls.m4
+++ /dev/null
@@ -1,51 +0,0 @@
-# nls.m4 serial 2 (gettext-0.14.3)
-dnl Copyright (C) 1995-2003, 2005 Free Software Foundation, Inc.
-dnl This file is free software; the Free Software Foundation
-dnl gives unlimited permission to copy and/or distribute it,
-dnl with or without modifications, as long as this notice is preserved.
-dnl
-dnl This file can can be used in projects which are not available under
-dnl the GNU General Public License or the GNU Library General Public
-dnl License but which still want to provide support for the GNU gettext
-dnl functionality.
-dnl Please note that the actual code of the GNU gettext library is covered
-dnl by the GNU Library General Public License, and the rest of the GNU
-dnl gettext package package is covered by the GNU General Public License.
-dnl They are *not* in the public domain.
-
-dnl Authors:
-dnl Ulrich Drepper <drepper@cygnus.com>, 1995-2000.
-dnl Bruno Haible <haible@clisp.cons.org>, 2000-2003.
-
-AC_PREREQ(2.50)
-
-AC_DEFUN([AM_NLS],
-[
- AC_MSG_CHECKING([whether NLS is requested])
- dnl Default is enabled NLS
- AC_ARG_ENABLE(nls,
- [ --disable-nls do not use Native Language Support],
- USE_NLS=$enableval, USE_NLS=yes)
- AC_MSG_RESULT($USE_NLS)
- AC_SUBST(USE_NLS)
-])
-
-AC_DEFUN([AM_MKINSTALLDIRS],
-[
- dnl Tell automake >= 1.10 to complain if mkinstalldirs is missing.
- m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([mkinstalldirs])])
- dnl If the AC_CONFIG_AUX_DIR macro for autoconf is used we possibly
- dnl find the mkinstalldirs script in another subdir but $(top_srcdir).
- dnl Try to locate it.
- MKINSTALLDIRS=
- if test -n "$ac_aux_dir"; then
- case "$ac_aux_dir" in
- /*) MKINSTALLDIRS="$ac_aux_dir/mkinstalldirs" ;;
- *) MKINSTALLDIRS="\$(top_builddir)/$ac_aux_dir/mkinstalldirs" ;;
- esac
- fi
- if test -z "$MKINSTALLDIRS"; then
- MKINSTALLDIRS="\$(top_srcdir)/mkinstalldirs"
- fi
- AC_SUBST(MKINSTALLDIRS)
-])
diff --git a/m4/objc.m4 b/m4/objc.m4
new file mode 100644
index 000000000..73dd8b6a0
--- /dev/null
+++ b/m4/objc.m4
@@ -0,0 +1,253 @@
+# Extracted from autoconf 2.61 to obtain Objective C macros.
+# Only expand if the version of autoconf in use doesn't have the macro itself.
+m4_ifdef([AC_PROG_OBJC], [], [
+
+# This file is part of Autoconf. -*- Autoconf -*-
+# Programming languages support.
+# Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 Free Software
+# Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+#
+# As a special exception, the Free Software Foundation gives unlimited
+# permission to copy, distribute and modify the configure scripts that
+# are the output of Autoconf. You need not follow the terms of the GNU
+# General Public License when using or distributing such scripts, even
+# though portions of the text of Autoconf appear in them. The GNU
+# General Public License (GPL) does govern all other use of the material
+# that constitutes the Autoconf program.
+#
+# Certain portions of the Autoconf source text are designed to be copied
+# (in certain cases, depending on the input) into the output of
+# Autoconf. We call these the "data" portions. The rest of the Autoconf
+# source text consists of comments plus executable code that decides which
+# of the data portions to output in any given case. We call these
+# comments and executable code the "non-data" portions. Autoconf never
+# copies any of the non-data portions into its output.
+#
+# This special exception to the GPL applies to versions of Autoconf
+# released by the Free Software Foundation. When you make and
+# distribute a modified version of Autoconf, you may extend this special
+# exception to the GPL to apply to your modified version as well, *unless*
+# your modified version has the potential to copy into its output some
+# of the text that was the non-data portion of the version that you started
+# with. (In other words, unless your change moves or copies text from
+# the non-data portions to the data portions.) If your modification has
+# such potential, you must delete any notice of this special exception
+# to the GPL from your modified version.
+#
+# Written by David MacKenzie, with help from
+# Akim Demaille, Paul Eggert,
+# Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
+# Roland McGrath, Noah Friedman, david d zuhn, and many others.
+
+# ------------------------------ #
+# 1d. The Objective C language. #
+# ------------------------------ #
+
+
+# AC_LANG(Objective C)
+# --------------------
+m4_define([AC_LANG(Objective C)],
+[ac_ext=m
+ac_cpp='$OBJCPP $CPPFLAGS'
+ac_compile='$OBJC -c $OBJCFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
+ac_link='$OBJC -o conftest$ac_exeext $OBJCFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
+ac_compiler_gnu=$ac_cv_objc_compiler_gnu
+])
+
+
+# AC_LANG_OBJC
+# ------------
+AU_DEFUN([AC_LANG_OBJC], [AC_LANG(Objective C)])
+
+
+# _AC_LANG_ABBREV(Objective C)
+# ----------------------------
+m4_define([_AC_LANG_ABBREV(Objective C)], [objc])
+
+
+# _AC_LANG_PREFIX(Objective C)
+# ----------------------------
+m4_define([_AC_LANG_PREFIX(Objective C)], [OBJC])
+
+
+# ------------------------- #
+# 2d. Objective C sources. #
+# ------------------------- #
+
+# AC_LANG_SOURCE(Objective C)(BODY)
+# ---------------------------------
+m4_copy([AC_LANG_SOURCE(C)], [AC_LANG_SOURCE(Objective C)])
+
+
+# AC_LANG_PROGRAM(Objective C)([PROLOGUE], [BODY])
+# ------------------------------------------------
+m4_copy([AC_LANG_PROGRAM(C)], [AC_LANG_PROGRAM(Objective C)])
+
+
+# AC_LANG_CALL(Objective C)(PROLOGUE, FUNCTION)
+# ---------------------------------------------
+m4_copy([AC_LANG_CALL(C)], [AC_LANG_CALL(Objective C)])
+
+
+# AC_LANG_FUNC_LINK_TRY(Objective C)(FUNCTION)
+# --------------------------------------------
+m4_copy([AC_LANG_FUNC_LINK_TRY(C)], [AC_LANG_FUNC_LINK_TRY(Objective C)])
+
+
+# AC_LANG_BOOL_COMPILE_TRY(Objective C)(PROLOGUE, EXPRESSION)
+# -----------------------------------------------------------
+m4_copy([AC_LANG_BOOL_COMPILE_TRY(C)], [AC_LANG_BOOL_COMPILE_TRY(Objective C)])
+
+
+# AC_LANG_INT_SAVE(Objective C)(PROLOGUE, EXPRESSION)
+# ---------------------------------------------------
+m4_copy([AC_LANG_INT_SAVE(C)], [AC_LANG_INT_SAVE(Objective C)])
+
+
+# ------------------------------ #
+# 3d. The Objective C compiler. #
+# ------------------------------ #
+
+# AC_LANG_PREPROC(Objective C)
+# ----------------------------
+# Find the Objective C preprocessor. Must be AC_DEFUN'd to be AC_REQUIRE'able.
+m4_defun([AC_LANG_PREPROC(Objective C)],
+[AC_REQUIRE([AC_PROG_OBJCPP])])
+
+
+# AC_PROG_OBJCPP
+# --------------
+# Find a working Objective C preprocessor.
+AC_DEFUN([AC_PROG_OBJCPP],
+[AC_REQUIRE([AC_PROG_OBJC])dnl
+AC_ARG_VAR([OBJCPP], [Objective C preprocessor])dnl
+_AC_ARG_VAR_CPPFLAGS()dnl
+AC_LANG_PUSH(Objective C)dnl
+AC_MSG_CHECKING([how to run the Objective C preprocessor])
+if test -z "$OBJCPP"; then
+ AC_CACHE_VAL(ac_cv_prog_OBJCPP,
+ [dnl
+ # Double quotes because OBJCPP needs to be expanded
+ for OBJCPP in "$OBJC -E" "/lib/cpp"
+ do
+ _AC_PROG_PREPROC_WORKS_IFELSE([break])
+ done
+ ac_cv_prog_OBJCPP=$OBJCPP
+ ])dnl
+ OBJCPP=$ac_cv_prog_OBJCPP
+else
+ ac_cv_prog_OBJCPP=$OBJCPP
+fi
+AC_MSG_RESULT([$OBJCPP])
+_AC_PROG_PREPROC_WORKS_IFELSE([],
+ [AC_MSG_FAILURE([Objective C preprocessor "$OBJCPP" fails sanity check])])
+AC_SUBST(OBJCPP)dnl
+AC_LANG_POP(Objective C)dnl
+])# AC_PROG_OBJCPP
+
+
+# AC_LANG_COMPILER(Objective C)
+# -----------------------------
+# Find the Objective C compiler. Must be AC_DEFUN'd to be AC_REQUIRE'able.
+m4_defun([AC_LANG_COMPILER(Objective C)],
+[AC_REQUIRE([AC_PROG_OBJC])])
+
+
+
+# AC_PROG_OBJC([LIST-OF-COMPILERS])
+# ---------------------------------
+# LIST-OF-COMPILERS is a space separated list of Objective C compilers to
+# search for (if not specified, a default list is used). This just gives
+# the user an opportunity to specify an alternative search list for the
+# Objective C compiler.
+# objcc StepStone Objective-C compiler (also "standard" name for OBJC)
+# objc David Stes' POC. If you installed this, you likely want it.
+# cc Native C compiler (for instance, Apple).
+# CC You never know.
+AN_MAKEVAR([OBJC], [AC_PROG_OBJC])
+AN_PROGRAM([objcc], [AC_PROG_OBJC])
+AN_PROGRAM([objc], [AC_PROG_OBJC])
+AC_DEFUN([AC_PROG_OBJC],
+[AC_LANG_PUSH(Objective C)dnl
+AC_ARG_VAR([OBJC], [Objective C compiler command])dnl
+AC_ARG_VAR([OBJCFLAGS], [Objective C compiler flags])dnl
+_AC_ARG_VAR_LDFLAGS()dnl
+dnl _AC_ARG_VAR_LIBS()dnl
+_AC_ARG_VAR_CPPFLAGS()dnl
+_AC_ARG_VAR_PRECIOUS([OBJC])dnl
+AC_CHECK_TOOLS(OBJC,
+ [m4_default([$1], [gcc objcc objc cc CC])],
+ gcc)
+# Provide some information about the compiler.
+echo "$as_me:$LINENO:" \
+ "checking for _AC_LANG compiler version" >&AS_MESSAGE_LOG_FD
+ac_compiler=`set X $ac_compile; echo $[2]`
+_AC_EVAL([$ac_compiler --version </dev/null >&AS_MESSAGE_LOG_FD])
+_AC_EVAL([$ac_compiler -v </dev/null >&AS_MESSAGE_LOG_FD])
+_AC_EVAL([$ac_compiler -V </dev/null >&AS_MESSAGE_LOG_FD])
+
+m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
+m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
+_AC_LANG_COMPILER_GNU
+GOBJC=`test $ac_compiler_gnu = yes && echo yes`
+_AC_PROG_OBJC_G
+AC_LANG_POP(Objective C)dnl
+])# AC_PROG_OBJC
+
+
+# _AC_PROG_OBJC_G
+# ---------------
+# Check whether -g works, even if OBJCFLAGS is set, in case the package
+# plays around with OBJCFLAGS (such as to build both debugging and
+# normal versions of a library), tasteless as that idea is.
+# Don't consider -g to work if it generates warnings when plain compiles don't.
+m4_define([_AC_PROG_OBJC_G],
+[ac_test_OBJCFLAGS=${OBJCFLAGS+set}
+ac_save_OBJCFLAGS=$OBJCFLAGS
+AC_CACHE_CHECK(whether $OBJC accepts -g, ac_cv_prog_objc_g,
+ [ac_save_objc_werror_flag=$ac_objc_werror_flag
+ ac_objc_werror_flag=yes
+ ac_cv_prog_objc_g=no
+ OBJCFLAGS="-g"
+ _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
+ [ac_cv_prog_objc_g=yes],
+ [OBJCFLAGS=""
+ _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
+ [],
+ [ac_objc_werror_flag=$ac_save_objc_werror_flag
+ OBJCFLAGS="-g"
+ _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
+ [ac_cv_prog_objc_g=yes])])])
+ ac_objc_werror_flag=$ac_save_objc_werror_flag])
+if test "$ac_test_OBJCFLAGS" = set; then
+ OBJCFLAGS=$ac_save_OBJCFLAGS
+elif test $ac_cv_prog_objc_g = yes; then
+ if test "$GOBJC" = yes; then
+ OBJCFLAGS="-g -O2"
+ else
+ OBJCFLAGS="-g"
+ fi
+else
+ if test "$GOBJC" = yes; then
+ OBJCFLAGS="-O2"
+ else
+ OBJCFLAGS=
+ fi
+fi[]dnl
+])# _AC_PROG_OBJC_G
+])dnl m4_ifdef([AC_PROG_OBJC])
diff --git a/m4/opengl.m4 b/m4/opengl.m4
deleted file mode 100644
index 2c12949d9..000000000
--- a/m4/opengl.m4
+++ /dev/null
@@ -1,74 +0,0 @@
-dnl
-dnl Check for OpenGL & GLU
-dnl
-dnl AM_PATH_OPENGL([ACTION IF FOUND [, ACTION IF NOT FOUND]])
-dnl
-
-AC_DEFUN([AM_PATH_OPENGL], [
-
- AC_ARG_ENABLE(opengl, AS_HELP_STRING([--disable-opengl], [do not build OpenGL plugin]),
- [enableopengl=$enableval],
- [enableopengl="yes"]
- )
- AC_ARG_ENABLE(glu, AS_HELP_STRING([--disable-glu], [build OpenGL plugin without GLU (no verbose errors)]),
- [enableglu=$enableval],
- [enableglu="yes"]
- )
-
- if test x$enableopengl = "xyes"; then
- AC_CHECK_LIB(GL, glBegin,
- [AC_CHECK_LIB(m, tan,
- [AC_CHECK_HEADER(GL/gl.h,
- [ac_have_opengl="yes"
- OPENGL_LIBS="-lGL -lm"
- AC_DEFINE(HAVE_OPENGL,1,[Define this if you have OpenGL support available])
- dnl
- dnl need to check with some test if this linking with -lGLU actually works...
- dnl check for GLU
- dnl
- if test x$enableglu = "xyes"; then
- AC_CHECK_LIB(GLU, gluPerspective,
- [AC_CHECK_HEADER(GL/glu.h,
- [AC_MSG_CHECKING([if GLU is sane])
- ac_save_LIBS="$LIBS"
- LIBS="$X_LIBS $XPRE_LIBS $OPENGL_LIBS -lGLU $X_EXTRA_LIBS"
- AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <GL/gl.h>
-#include <GL/glu.h>]], [[ gluPerspective(45.0f,1.33f,1.0f,1000.0f); glBegin(GL_POINTS); glEnd(); return 0 ]])],
- [ ac_have_glu="yes"
- GLU_LIBS="-lGLU"
- AC_DEFINE(HAVE_GLU,1,[Define this if you have GLU support available])
- AC_MSG_RESULT(yes)],
- [ AC_MSG_RESULT(no)
- echo "*** GLU doesn't link with GL; GLU is disabled ***"])
- LIBS="$ac_save_LIBS"]
- )],
- [],
- [$X_LIBS $X_PRE_LIBS $OPENGL_LIBS -lGLU $X_EXTRA_LIBS]
- )
- fi
- ]
- )],
- [],
- [$X_LIBS $X_PRE_LIBS -lGL -lm $X_EXTRA_LIBS]
- )],
- [],
- [$X_LIBS $X_PRE_LIBS $X_EXTRA_LIBS]
- )
- if test x$ac_have_opengl = "xyes"; then
- ac_use_opengl=yes
- fi
- fi
-
- AC_SUBST(OPENGL_CFLAGS)
- AC_SUBST(OPENGL_LIBS)
- AC_SUBST(GLU_LIBS)
- AM_CONDITIONAL(HAVE_OPENGL, [test x$ac_use_opengl = "xyes"])
-
- dnl result
- if test x$ac_use_opengl = "xyes"; then
- ifelse([$1], , :, [$1])
- else
- ifelse([$2], , :, [$2])
- fi
-
-])
diff --git a/m4/optimizations.m4 b/m4/optimizations.m4
deleted file mode 100644
index a1f2f2f00..000000000
--- a/m4/optimizations.m4
+++ /dev/null
@@ -1,252 +0,0 @@
-dnl
-dnl M4 macro to add support for extra optimizations
-dnl
-dnl It understand --enable/--disable-optimizations .
-dnl when optimizations are disabled, it does not touch cflags
-dnl
-dnl Note: always disable while crosscompiling
-dnl
-
-AC_DEFUN([AC_OPTIMIZATIONS], [
- AC_ARG_ENABLE([optimizations],
- AS_HELP_STRING([--disable-optimizations], [Don't try to guess what optimization to enable]))
-
- if test "x$enable_optimizations" != "xno"; then
- INLINE_FUNCTIONS=-finline-functions
-
- if test "$GCC" = yes; then
- dnl
- dnl check cflags not supported by all gcc versions
- AC_TRY_CFLAGS("-fschedule-insns2", f_si="-fschedule-insns2", f_si="")
- AC_TRY_CFLAGS("-mwide-multiply", m_wm="-mwide-multiply", m_wm="")
- dnl
- dnl gcc 3.1 uses the -f version
- dnl
- AC_TRY_CFLAGS("-falign-functions=4", f_af="-falign-functions=4",
- f_af="-malign-functions=4")
- AC_TRY_CFLAGS("-falign-loops=4", f_al="-falign-loops=4",
- f_al="-malign-loops=4")
- AC_TRY_CFLAGS("-falign-jumps=4", f_aj="-falign-jumps=4",
- f_aj="-malign-jumps=4")
- dnl
- dnl Check for some optimization disabling
- dnl needed for win32 code
- dnl
- AC_TRY_CFLAGS("-fno-omit-frame-pointer", W32_NO_OPTIMIZE="$W32_NO_OPTIMIZE -fno-omit-frame-pointer",)
- AC_TRY_CFLAGS("-fno-inline-functions", W32_NO_OPTIMIZE="$W32_NO_OPTIMIZE -fno-inline-functions",)
- AC_TRY_CFLAGS("-fno-rename-registers", W32_NO_OPTIMIZE="$W32_NO_OPTIMIZE -fno-rename-registers",)
- AC_SUBST(W32_NO_OPTIMIZE)
- dnl
- dnl Multipass compilation
- dnl
- AC_TRY_CFLAGS("-fprofile-arcs", PASS1_CFLAGS="-fprofile_arcs $PASS1_CFLAGS",)
- AC_TRY_CFLAGS("-fbranch-probabilities", PASS2_CFLAGS="-fbranch-probabilities $PASS2_CFLAGS",)
- AC_SUBST(PASS1_CFLAGS)
- AC_SUBST(PASS2_CFLAGS)
- dnl
- dnl Warnings
- dnl
- CFLAGS="-Wchar-subscripts -Wmissing-declarations -Wmissing-prototypes $CFLAGS"
- CFLAGS="-Wnested-externs -Wcast-align $CFLAGS"
- dnl some combinations of gcc+glibc produce useless warnings on memset
- dnl when compiling with -Wpointer-arith, so we check for this first
- AC_MSG_CHECKING(for sane -Wpointer-arith)
- SAVE_CFLAGS="$CFLAGS"
- CFLAGS="-O2 -Wpointer-arith -Werror $CFLAGS"
- AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <string.h>]], [[int a; memset(&a, 0, sizeof(int));]])],
- [AC_MSG_RESULT(yes); CFLAGS="-Wpointer-arith $SAVE_CFLAGS"],
- [AC_MSG_RESULT(no); CFLAGS="$SAVE_CFLAGS"]);
-
- dnl gcc 3.3.5 (at least) is known to be buggy wrt optimisation and
- dnl -finline-functions. Use -fno-inline-functions for gcc < 3.4.0.
-
- AC_MSG_CHECKING(for gcc 3.4.0 or later)
- newGCC="`"$CC" -dumpversion |
- awk -F. '{ if ((@S|@1 * 10000 + @S|@2 * 100 + @S|@3) >= 30400) { print "yes" } }'
- `"
- AC_MSG_RESULT(${newGCC:-no - assuming bugginess in -finline-functions})
- test "$newGCC" = yes || INLINE_FUNCTIONS=-fno-inline-functions
- fi
-
- dnl Flags not supported by all *cc* variants
- AC_TRY_CFLAGS("-Wall", wall="-Wall", wall="")
-
- CFLAGS="$wall ${CFLAGS}"
- DEBUG_CFLAGS="$wall ${DEBUG_CFLAGS}"
-
- case "$host_or_hostalias" in
- i?86-* | k?-* | athlon-* | pentium*)
- if test "$GCC" = yes -o "${CC##*/}x" = "iccx" ; then
-
- if test "$GCC" = yes; then
- dnl Check for gcc cpu optimization support
- AC_TRY_CFLAGS("-mtune=i386",
- sarchopt="-mtune",
- AC_TRY_CFLAGS("-mcpu=i386",
- sarchopt="-mcpu",
- AC_TRY_CFLAGS("-march=i386",
- sarchopt="-march",
- [ AC_MSG_RESULT(** no cpu optimization supports **)
- sarchopt=no
- ]
- )
- )
- )
-
- dnl special check for k7 cpu CC support
- AC_TRY_CFLAGS("$sarchopt=athlon", k7cpu="athlon", k7cpu="i686")
-
- dnl add x86 specific gcc CFLAGS
- CFLAGS="-O3 -pipe -fomit-frame-pointer $f_af $f_al $f_aj $m_wm $m_psb -fexpensive-optimizations $f_si -ffast-math $INLINE_FUNCTIONS $CFLAGS"
-
- DEBUG_CFLAGS="-O $DEBUG_CFLAGS"
-
- if test x"$sarchopt" != "xno"; then
- archopt_val=
-
- case "$host_or_hostalias" in
- i386-*)
- archopt_val="i386" ;;
- i486-*)
- archopt_val="i486" ;;
- i586-*)
- archopt_val="pentium"
- ;;
- pentium-mmx-*)
- archopt_val="pentium-mmx"
- ;;
- pentiumpro-* | pentium2-* | i686-*)
- archopt_val="pentiumpro"
- if test x"$check_athlon" = "xyes"; then
- if test -f /proc/cpuinfo; then
- modelname=`cat /proc/cpuinfo | grep "model\ name\ :" | sed -e 's/ //g' | cut -d':' -f2`
- case "$modelname" in
- *Athlon* | *Duron* | *K7*)
- archopt_val="$k7cpu"
- ;;
- VIAEzra)
- archopt_val="c3"
- ;;
- esac
- fi
- fi
- ;;
- k6-2-* | k6-3-*)
- archopt_val="k6-2"
- ;;
- k6-*)
- archopt_val="k6"
- ;;
- pentium3-*)
- archopt_val="pentium3"
- ;;
- pentium4-*)
- archopt_val="pentium4"
- ;;
- athlon-4-* | athlon-xp-* | athlon-mp-*)
- archopt_val="athlon-4"
- ;;
- k7-* | athlon-tbird-* | athlon-*)
- archopt_val="athlon"
- ;;
-
- esac
- if test x"$archopt_val" != x; then
- CFLAGS="$sarchopt=$archopt_val $CFLAGS"
- DEBUG_CFLAGS="$sarchopt=$archopt_val $DEBUG_CFLAGS"
- fi
- fi
- else
- dnl we have the Intel compiler
- CFLAGS="-unroll -ipo -ipo_obj -O3 $CFLAGS"
- PASS1_CFLAGS="-prof_genx -prof_dir \$(PWD)/\$(top_builddir)/ $PASS1_CFLAGS"
- PASS2_CFLAGS="-prof_use -prof_dir \$(PWD)/\$(top_builddir)/ $PASS2_CFLAGS"
- AC_SUBST(PASS1_CFLAGS)
- AC_SUBST(PASS2_CFLAGS)
- fi
-
- else
- dnl add x86 specific cc CFLAGS
- CFLAGS="-O $CFLAGS"
- DEBUG_CFLAGS="-O $DEBUG_CFLAGS"
- AC_DEFINE_UNQUOTED(FPM_64BIT,,[Define to select libmad fixed point arithmetic implementation])
- fi
- ;;
- alphaev56-*)
- CFLAGS="-O3 -mcpu=ev56 -mieee $CFLAGS"
- DEBUG_CFLAGS="-O3 -mcpu=ev56 -mieee $DEBUG_CFLAGS"
- ;;
- alpha*)
- CFLAGS="-O3 -mieee $CFLAGS"
- DEBUG_CFLAGS="-O3 -mieee $DEBUG_CFLAGS"
- ;;
- *darwin*)
- CFLAGS="-O3 -pipe -fomit-frame-pointer $m_wm $m_psb -fexpensive-optimizations $f_si -ffast-math $INLINE_FUNCTIONS -no-cpp-precomp -D_INTL_REDIRECT_MACROS $CFLAGS"
- DEBUG_CFLAGS="-O3 $DEBUG_CFLAGS"
- ;;
- ppc-*-linux* | powerpc-*)
- CFLAGS="-O3 -pipe -fomit-frame-pointer $m_wm $m_psb -fexpensive-optimizations $f_si -ffast-math $INLINE_FUNCTIONS $CFLAGS"
- DEBUG_CFLAGS="-O3 $DEBUG_CFLAGS"
- ;;
- sparc*-*-linux*)
- CFLAGS="-O3 $cpu_cflags $INLINE_FUNCTIONS $CFLAGS"
- DEBUG_CFLAGS="-O $cpu_cflags $INLINE_FUNCTIONS $DEBUG_CFLAGS"
-
- case `uname -m` in
- sparc)
- cpu_cflags="-mcpu=supersparc -mtune=supersparc" ;;
- sparc64)
- cpu_cflags="-mcpu=ultrasparc -mtune=ultrasparc" ;;
- esac
- ;;
- sparc-*-solaris*)
- if test "$GCC" = yes; then
- case `uname -m` in
- sun4c) cpu_cflags="-mcpu=v7 -mtune=supersparc" ;;
- sun4m) cpu_cflags="-mcpu=v8 -mtune=supersparc" ;;
- sun4u)
- case `$CC --version 2>/dev/null` in
- 1.*|2.*)
- # -mcpu=ultrasparc triggers a GCC 2.95.x compiler bug when
- # compiling video_out.c:
- # gcc: Internal compiler error: program cc1 got fatal signal 11
- # avoid -mcpu=ultrasparc with gcc 2.*
- cpu_cflags="-mcpu=v8 -mtune=ultrasparc"
- ;;
- *)
- # GCC 3 or newer should have no problem with -mcpu=ultrasparc
- cpu_cflags="-mcpu=ultrasparc -mtune=ultrasparc"
- ;;
- esac
- ;;
- esac
- cc_optimize_cflags="-O3 $cpu_cflags $INLINE_FUNCTIONS"
- cc_debug_cflags="-O $cpu_cflags $INLINE_FUNCTIONS"
- else
- case `uname -m` in
- sun4c) cpu_cflags="-xarch=v7" ;;
- sun4m) cpu_cflags="-xarch=v8" ;;
- sun4u) cpu_cflags="-xarch=v8plusa" ;;
- esac
- cc_optimize_cflags="-fast $cpu_cflags -xCC"
- cc_debug_cflags="-O"
- fi
-
- CFLAGS="$cc_optimize_cflags $CFLAGS"
- DEBUG_CFLAGS="$cc_debug_cflags $DEBUG_CFLAGS"
- ;;
- x86_64-*)
- CFLAGS="-O3 -fomit-frame-pointer $m_wm $m_psb -fexpensive-optimizations $f_si -ffast-math $INLINE_FUNCTIONS $CFLAGS"
- DEBUG_CFLAGS="-g $DEBUG_CFLAGS"
- ;;
- armv4l-*-linux*)
- CFLAGS="-O2 -fsigned-char -ffast-math -mcpu=strongarm1100 -fomit-frame-pointer -fthread-jumps -fregmove $CFLAGS"
- dnl CFLAGS="-O1 -fforce-mem -fforce-addr -fthread-jumps -fcse-follow-jumps -fcse-skip-blocks -fexpensive-optimizations -fregmove -fschedule-insns2 $INLINE_FUNCTIONS -fsigned-char -fomit-frame-pointer -march=armv4 -mtune=strongarm $CFLAGS"
- DEBUG_CFLAGS="-O2 $DEBUG_CFLAGS"
- ;;
- esac
- fi
-])
-
-dnl Kate modeline: leave at the end
-dnl kate: indent-width 2; replace-trailing-space-save 1; space-indent 1; backspace-indents 1;
diff --git a/m4/package.m4 b/m4/package.m4
new file mode 100644
index 000000000..69f721440
--- /dev/null
+++ b/m4/package.m4
@@ -0,0 +1,72 @@
+dnl _ACX_VERSION_PARSE(version)
+AC_DEFUN([_ACX_VERSION_PARSE], [`echo $1 | perl -e 'my $v = <>; chomp $v;
+my @v = split(" ", $v); $v = $v[[@S|@#v]]; $v =~ s/[[^0-9.]].*$//; @v = split (/\./, $v);
+push @v, 0 while $[#v] < 2; print $v[[0]] * 10000 + $v[[1]] * 100 + $v[[2]], "\n"'`])
+
+dnl ACX_VERSION_CHECK(required, actual)
+AC_DEFUN([ACX_VERSION_CHECK], [
+ required_version=ifelse([$1], , [0.0.0], [$1])
+ required_version_parsed=_ACX_VERSION_PARSE([$required_version])
+ actual_version=ifelse([$2], , [0.0.0], [$2])
+ actual_version_parsed=_ACX_VERSION_PARSE([$actual_version])
+ if test $required_version_parsed -le $actual_version_parsed; then
+ ifelse([$3], , [:], [$3])
+ else
+ ifelse([$4], , [:], [$4])
+ fi
+])
+
+AC_DEFUN([ASX_TR_LOWER], [m4_translit([[$1]], [ABCDEFGHIJKLMNOPQRSTUVWXYZ], [abcdefghijklmnopqrstuvwxyz])])
+
+dnl ACX_PACKAGE_CHECK(VARIABLE-PREFIX, MINIMUM-VERSION, CONFIG-SCRIPT,
+dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
+AC_DEFUN([ACX_PACKAGE_CHECK], [
+ AC_ARG_VAR([$1][_CONFIG], [Full path to $3])
+ AC_ARG_WITH(ASX_TR_LOWER([$1][-prefix]),
+ [AS_HELP_STRING(ASX_TR_LOWER([--with-][$1][-prefix])[=PATH], [prefix where $3 is installed (optional)])],
+ [package_config_prefix="$withval"], [package_config_prefix=""])
+ AC_ARG_WITH(ASX_TR_LOWER([$1][-exec-prefix]),
+ [AS_HELP_STRING(ASX_TR_LOWER([--with-][$1][-exec-prefix])[=PATH], [exec prefix where $3 is installed (optional)])],
+ [package_config_exec_prefix="$withval"], [package_config_exec_prefix=""])
+ package_config_args=""
+ if test x"$package_config_exec_prefix" != x""; then
+ package_config_args="$package_config_args --exec-prefix=$package_config_exec_prefix"
+ test x"${[$1][_CONFIG]+set}" != x"set" && [$1][_CONFIG]="$package_config_exec_prefix/bin/$3"
+ fi
+ if test x"$package_config_prefix" != x""; then
+ package_config_args="$package_config_args --prefix=$package_config_prefix"
+ test x"${[$1][_CONFIG]+set}" != x"set" && [$1][_CONFIG]="$package_config_prefix/bin/$3"
+ fi
+
+ min_package_version=ifelse([$2], , [0.0.0], [$2])
+ AC_PATH_TOOL([[$1][_CONFIG]], [$3], [no])
+ AC_MSG_CHECKING([for $1 version >= $min_package_version])
+ if test x"$[$1][_CONFIG]" = x"no"; then
+ AC_MSG_RESULT([unknown])
+ AC_MSG_NOTICE([The $3 script installed by $1 could not be found.
+*** If $1 was installed in PREFIX, make sure PREFIX/bin is in your path, or
+*** set the $1][_CONFIG environment variable to the full path to the program.])
+ else
+ [$1][_CFLAGS]="`$[$1][_CONFIG] $package_config_args --cflags`"
+ [$1][_LIBS]="`$[$1][_CONFIG] $package_config_args --libs`"
+ [$1][_VERSION]="`$[$1][_CONFIG] $package_config_args --version`"
+ ACX_VERSION_CHECK([$min_package_version], [$[$1][_VERSION]],
+ [package_version_ok=yes; AC_MSG_RESULT([yes -- $[$1][_VERSION]])],
+ [[$1][_CFLAGS]="" [$1][_LIBS]=""; AC_MSG_RESULT([no -- $[$1][_VERSION]])
+ AC_MSG_NOTICE([If you have already installed a sufficiently new version,
+*** this error probably means that the wrong copy of the $3
+*** shell script is being found. The easiest way to fix this is to remove the
+*** old version, but you can also set the $1][_CONFIG environment
+*** variable to point to the correct copy. In this case, you will have to
+*** modify your LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf
+*** so that the correct libraries are found at run-time.])])
+ fi
+
+ if test x"$package_version_ok" = x"yes"; then
+ ifelse([$4], , [:], [$4])
+ else
+ ifelse([$5], , [:], [$5])
+ fi
+ AC_SUBST([$1][_CFLAGS])
+ AC_SUBST([$1][_LIBS])
+])
diff --git a/m4/pkg.m4 b/m4/pkg.m4
index cbb46dbf8..69445f39a 100644
--- a/m4/pkg.m4
+++ b/m4/pkg.m4
@@ -136,7 +136,8 @@ installed software in a non-standard prefix.
_PKG_TEXT
])],
- [$4])
+ [AC_MSG_RESULT([no])
+ $4])
elif test $pkg_failed = untried; then
ifelse([$4], , [AC_MSG_FAILURE(dnl
[The pkg-config script could not be found or is too old. Make sure it
@@ -146,7 +147,8 @@ path to pkg-config.
_PKG_TEXT
To get pkg-config, see <http://www.freedesktop.org/software/pkgconfig>.])],
- [$4])
+ [AC_MSG_RESULT([no])
+ $4])
else
$1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
$1[]_LIBS=$pkg_cv_[]$1[]_LIBS
diff --git a/m4/po.m4 b/m4/po.m4
deleted file mode 100644
index f2795eea0..000000000
--- a/m4/po.m4
+++ /dev/null
@@ -1,429 +0,0 @@
-# po.m4 serial 7 (gettext-0.14.3)
-dnl Copyright (C) 1995-2005 Free Software Foundation, Inc.
-dnl This file is free software; the Free Software Foundation
-dnl gives unlimited permission to copy and/or distribute it,
-dnl with or without modifications, as long as this notice is preserved.
-dnl
-dnl This file can can be used in projects which are not available under
-dnl the GNU General Public License or the GNU Library General Public
-dnl License but which still want to provide support for the GNU gettext
-dnl functionality.
-dnl Please note that the actual code of the GNU gettext library is covered
-dnl by the GNU Library General Public License, and the rest of the GNU
-dnl gettext package package is covered by the GNU General Public License.
-dnl They are *not* in the public domain.
-
-dnl Authors:
-dnl Ulrich Drepper <drepper@cygnus.com>, 1995-2000.
-dnl Bruno Haible <haible@clisp.cons.org>, 2000-2003.
-
-AC_PREREQ(2.50)
-
-dnl Checks for all prerequisites of the po subdirectory.
-AC_DEFUN([AM_PO_SUBDIRS],
-[
- AC_REQUIRE([AC_PROG_MAKE_SET])dnl
- AC_REQUIRE([AC_PROG_INSTALL])dnl
- AC_REQUIRE([AM_MKINSTALLDIRS])dnl
- AC_REQUIRE([AM_NLS])dnl
-
- dnl Perform the following tests also if --disable-nls has been given,
- dnl because they are needed for "make dist" to work.
-
- dnl Search for GNU msgfmt in the PATH.
- dnl The first test excludes Solaris msgfmt and early GNU msgfmt versions.
- dnl The second test excludes FreeBSD msgfmt.
- AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
- [$ac_dir/$ac_word --statistics /dev/null >&]AS_MESSAGE_LOG_FD[ 2>&1 &&
- (if $ac_dir/$ac_word --statistics /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi)],
- :)
- AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
-
- dnl Search for GNU xgettext 0.12 or newer in the PATH.
- dnl The first test excludes Solaris xgettext and early GNU xgettext versions.
- dnl The second test excludes FreeBSD xgettext.
- AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
- [$ac_dir/$ac_word --omit-header --copyright-holder= --msgid-bugs-address= /dev/null >&]AS_MESSAGE_LOG_FD[ 2>&1 &&
- (if $ac_dir/$ac_word --omit-header --copyright-holder= --msgid-bugs-address= /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi)],
- :)
- dnl Remove leftover from FreeBSD xgettext call.
- rm -f messages.po
-
- dnl Search for GNU msgmerge 0.11 or newer in the PATH.
- AM_PATH_PROG_WITH_TEST(MSGMERGE, msgmerge,
- [$ac_dir/$ac_word --update -q /dev/null /dev/null >&]AS_MESSAGE_LOG_FD[ 2>&1], :)
-
- dnl This could go away some day; the PATH_PROG_WITH_TEST already does it.
- dnl Test whether we really found GNU msgfmt.
- if test "$GMSGFMT" != ":"; then
- dnl If it is no GNU msgfmt we define it as : so that the
- dnl Makefiles still can work.
- if $GMSGFMT --statistics /dev/null >/dev/null 2>&1 &&
- (if $GMSGFMT --statistics /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi); then
- : ;
- else
- GMSGFMT=`echo "$GMSGFMT" | sed -e 's,^.*/,,'`
- AC_MSG_RESULT(
- [found $GMSGFMT program is not GNU msgfmt; ignore it])
- GMSGFMT=":"
- fi
- fi
-
- dnl This could go away some day; the PATH_PROG_WITH_TEST already does it.
- dnl Test whether we really found GNU xgettext.
- if test "$XGETTEXT" != ":"; then
- dnl If it is no GNU xgettext we define it as : so that the
- dnl Makefiles still can work.
- if $XGETTEXT --omit-header --copyright-holder= --msgid-bugs-address= /dev/null >/dev/null 2>&1 &&
- (if $XGETTEXT --omit-header --copyright-holder= --msgid-bugs-address= /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi); then
- : ;
- else
- AC_MSG_RESULT(
- [found xgettext program is not GNU xgettext; ignore it])
- XGETTEXT=":"
- fi
- dnl Remove leftover from FreeBSD xgettext call.
- rm -f messages.po
- fi
-
- AC_OUTPUT_COMMANDS([
- for ac_file in $CONFIG_FILES; do
- # Support "outfile[:infile[:infile...]]"
- case "$ac_file" in
- *:*) ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;;
- esac
- # PO directories have a Makefile.in generated from Makefile.in.in.
- case "$ac_file" in */Makefile.in)
- # Adjust a relative srcdir.
- ac_dir=`echo "$ac_file"|sed 's%/[^/][^/]*$%%'`
- ac_dir_suffix="/`echo "$ac_dir"|sed 's%^\./%%'`"
- ac_dots=`echo "$ac_dir_suffix"|sed 's%/[^/]*%../%g'`
- # In autoconf-2.13 it is called $ac_given_srcdir.
- # In autoconf-2.50 it is called $srcdir.
- test -n "$ac_given_srcdir" || ac_given_srcdir="$srcdir"
- case "$ac_given_srcdir" in
- .) top_srcdir=`echo $ac_dots|sed 's%/$%%'` ;;
- /*) top_srcdir="$ac_given_srcdir" ;;
- *) top_srcdir="$ac_dots$ac_given_srcdir" ;;
- esac
- # Treat a directory as a PO directory if and only if it has a
- # POTFILES.in file. This allows packages to have multiple PO
- # directories under different names or in different locations.
- if test -f "$ac_given_srcdir/$ac_dir/POTFILES.in"; then
- rm -f "$ac_dir/POTFILES"
- test -n "$as_me" && echo "$as_me: creating $ac_dir/POTFILES" || echo "creating $ac_dir/POTFILES"
- cat "$ac_given_srcdir/$ac_dir/POTFILES.in" | sed -e "/^#/d" -e "/^[ ]*\$/d" -e "s,.*, $top_srcdir/& \\\\," | sed -e "\$s/\(.*\) \\\\/\1/" > "$ac_dir/POTFILES"
- POMAKEFILEDEPS="POTFILES.in"
- # ALL_LINGUAS, POFILES, UPDATEPOFILES, DUMMYPOFILES, GMOFILES depend
- # on $ac_dir but don't depend on user-specified configuration
- # parameters.
- if test -f "$ac_given_srcdir/$ac_dir/LINGUAS"; then
- # The LINGUAS file contains the set of available languages.
- if test -n "$OBSOLETE_ALL_LINGUAS"; then
- test -n "$as_me" && echo "$as_me: setting ALL_LINGUAS in configure.in is obsolete" || echo "setting ALL_LINGUAS in configure.in is obsolete"
- fi
- ALL_LINGUAS_=`sed -e "/^#/d" -e "s/#.*//" "$ac_given_srcdir/$ac_dir/LINGUAS"`
- # Hide the ALL_LINGUAS assigment from automake.
- eval 'ALL_LINGUAS''=$ALL_LINGUAS_'
- POMAKEFILEDEPS="$POMAKEFILEDEPS LINGUAS"
- else
- # The set of available languages was given in configure.in.
- eval 'ALL_LINGUAS''=$OBSOLETE_ALL_LINGUAS'
- fi
- # Compute POFILES
- # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).po)
- # Compute UPDATEPOFILES
- # as $(foreach lang, $(ALL_LINGUAS), $(lang).po-update)
- # Compute DUMMYPOFILES
- # as $(foreach lang, $(ALL_LINGUAS), $(lang).nop)
- # Compute GMOFILES
- # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).gmo)
- case "$ac_given_srcdir" in
- .) srcdirpre= ;;
- *) srcdirpre='$(srcdir)/' ;;
- esac
- POFILES=
- UPDATEPOFILES=
- DUMMYPOFILES=
- GMOFILES=
- for lang in $ALL_LINGUAS; do
- POFILES="$POFILES $srcdirpre$lang.po"
- UPDATEPOFILES="$UPDATEPOFILES $lang.po-update"
- DUMMYPOFILES="$DUMMYPOFILES $lang.nop"
- GMOFILES="$GMOFILES $srcdirpre$lang.gmo"
- done
- # CATALOGS depends on both $ac_dir and the user's LINGUAS
- # environment variable.
- INST_LINGUAS=
- if test -n "$ALL_LINGUAS"; then
- for presentlang in $ALL_LINGUAS; do
- useit=no
- if test "%UNSET%" != "$LINGUAS"; then
- desiredlanguages="$LINGUAS"
- else
- desiredlanguages="$ALL_LINGUAS"
- fi
- for desiredlang in $desiredlanguages; do
- # Use the presentlang catalog if desiredlang is
- # a. equal to presentlang, or
- # b. a variant of presentlang (because in this case,
- # presentlang can be used as a fallback for messages
- # which are not translated in the desiredlang catalog).
- case "$desiredlang" in
- "$presentlang"*) useit=yes;;
- esac
- done
- if test $useit = yes; then
- INST_LINGUAS="$INST_LINGUAS $presentlang"
- fi
- done
- fi
- CATALOGS=
- if test -n "$INST_LINGUAS"; then
- for lang in $INST_LINGUAS; do
- CATALOGS="$CATALOGS $lang.gmo"
- done
- fi
- test -n "$as_me" && echo "$as_me: creating $ac_dir/Makefile" || echo "creating $ac_dir/Makefile"
- sed -e "/^POTFILES =/r $ac_dir/POTFILES" -e "/^# Makevars/r $ac_given_srcdir/$ac_dir/Makevars" -e "s|@POFILES@|$POFILES|g" -e "s|@UPDATEPOFILES@|$UPDATEPOFILES|g" -e "s|@DUMMYPOFILES@|$DUMMYPOFILES|g" -e "s|@GMOFILES@|$GMOFILES|g" -e "s|@CATALOGS@|$CATALOGS|g" -e "s|@POMAKEFILEDEPS@|$POMAKEFILEDEPS|g" "$ac_dir/Makefile.in" > "$ac_dir/Makefile"
- for f in "$ac_given_srcdir/$ac_dir"/Rules-*; do
- if test -f "$f"; then
- case "$f" in
- *.orig | *.bak | *~) ;;
- *) cat "$f" >> "$ac_dir/Makefile" ;;
- esac
- fi
- done
- fi
- ;;
- esac
- done],
- [# Capture the value of obsolete ALL_LINGUAS because we need it to compute
- # POFILES, UPDATEPOFILES, DUMMYPOFILES, GMOFILES, CATALOGS. But hide it
- # from automake.
- eval 'OBSOLETE_ALL_LINGUAS''="$ALL_LINGUAS"'
- # Capture the value of LINGUAS because we need it to compute CATALOGS.
- LINGUAS="${LINGUAS-%UNSET%}"
- ])
-])
-
-dnl Postprocesses a Makefile in a directory containing PO files.
-AC_DEFUN([AM_POSTPROCESS_PO_MAKEFILE],
-[
- # When this code is run, in config.status, two variables have already been
- # set:
- # - OBSOLETE_ALL_LINGUAS is the value of LINGUAS set in configure.in,
- # - LINGUAS is the value of the environment variable LINGUAS at configure
- # time.
-
-changequote(,)dnl
- # Adjust a relative srcdir.
- ac_dir=`echo "$ac_file"|sed 's%/[^/][^/]*$%%'`
- ac_dir_suffix="/`echo "$ac_dir"|sed 's%^\./%%'`"
- ac_dots=`echo "$ac_dir_suffix"|sed 's%/[^/]*%../%g'`
- # In autoconf-2.13 it is called $ac_given_srcdir.
- # In autoconf-2.50 it is called $srcdir.
- test -n "$ac_given_srcdir" || ac_given_srcdir="$srcdir"
- case "$ac_given_srcdir" in
- .) top_srcdir=`echo $ac_dots|sed 's%/$%%'` ;;
- /*) top_srcdir="$ac_given_srcdir" ;;
- *) top_srcdir="$ac_dots$ac_given_srcdir" ;;
- esac
-
- # Find a way to echo strings without interpreting backslash.
- if test "X`(echo '\t') 2>/dev/null`" = 'X\t'; then
- gt_echo='echo'
- else
- if test "X`(printf '%s\n' '\t') 2>/dev/null`" = 'X\t'; then
- gt_echo='printf %s\n'
- else
- echo_func () {
- cat <<EOT
-$*
-EOT
- }
- gt_echo='echo_func'
- fi
- fi
-
- # A sed script that extracts the value of VARIABLE from a Makefile.
- sed_x_variable='
-# Test if the hold space is empty.
-x
-s/P/P/
-x
-ta
-# Yes it was empty. Look if we have the expected variable definition.
-/^[ ]*VARIABLE[ ]*=/{
- # Seen the first line of the variable definition.
- s/^[ ]*VARIABLE[ ]*=//
- ba
-}
-bd
-:a
-# Here we are processing a line from the variable definition.
-# Remove comment, more precisely replace it with a space.
-s/#.*$/ /
-# See if the line ends in a backslash.
-tb
-:b
-s/\\$//
-# Print the line, without the trailing backslash.
-p
-tc
-# There was no trailing backslash. The end of the variable definition is
-# reached. Clear the hold space.
-s/^.*$//
-x
-bd
-:c
-# A trailing backslash means that the variable definition continues in the
-# next line. Put a nonempty string into the hold space to indicate this.
-s/^.*$/P/
-x
-:d
-'
-changequote([,])dnl
-
- # Set POTFILES to the value of the Makefile variable POTFILES.
- sed_x_POTFILES="`$gt_echo \"$sed_x_variable\" | sed -e '/^ *#/d' -e 's/VARIABLE/POTFILES/g'`"
- POTFILES=`sed -n -e "$sed_x_POTFILES" < "$ac_file"`
- # Compute POTFILES_DEPS as
- # $(foreach file, $(POTFILES), $(top_srcdir)/$(file))
- POTFILES_DEPS=
- for file in $POTFILES; do
- POTFILES_DEPS="$POTFILES_DEPS "'$(top_srcdir)/'"$file"
- done
- POMAKEFILEDEPS=""
-
- if test -n "$OBSOLETE_ALL_LINGUAS"; then
- test -n "$as_me" && echo "$as_me: setting ALL_LINGUAS in configure.in is obsolete" || echo "setting ALL_LINGUAS in configure.in is obsolete"
- fi
- if test -f "$ac_given_srcdir/$ac_dir/LINGUAS"; then
- # The LINGUAS file contains the set of available languages.
- ALL_LINGUAS_=`sed -e "/^#/d" -e "s/#.*//" "$ac_given_srcdir/$ac_dir/LINGUAS"`
- POMAKEFILEDEPS="$POMAKEFILEDEPS LINGUAS"
- else
- # Set ALL_LINGUAS to the value of the Makefile variable LINGUAS.
- sed_x_LINGUAS="`$gt_echo \"$sed_x_variable\" | sed -e '/^ *#/d' -e 's/VARIABLE/LINGUAS/g'`"
- ALL_LINGUAS_=`sed -n -e "$sed_x_LINGUAS" < "$ac_file"`
- fi
- # Hide the ALL_LINGUAS assigment from automake.
- eval 'ALL_LINGUAS''=$ALL_LINGUAS_'
- # Compute POFILES
- # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).po)
- # Compute UPDATEPOFILES
- # as $(foreach lang, $(ALL_LINGUAS), $(lang).po-update)
- # Compute DUMMYPOFILES
- # as $(foreach lang, $(ALL_LINGUAS), $(lang).nop)
- # Compute GMOFILES
- # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).gmo)
- # Compute PROPERTIESFILES
- # as $(foreach lang, $(ALL_LINGUAS), $(top_srcdir)/$(DOMAIN)_$(lang).properties)
- # Compute CLASSFILES
- # as $(foreach lang, $(ALL_LINGUAS), $(top_srcdir)/$(DOMAIN)_$(lang).class)
- # Compute QMFILES
- # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).qm)
- # Compute MSGFILES
- # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(frob $(lang)).msg)
- # Compute RESOURCESDLLFILES
- # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(frob $(lang))/$(DOMAIN).resources.dll)
- case "$ac_given_srcdir" in
- .) srcdirpre= ;;
- *) srcdirpre='$(srcdir)/' ;;
- esac
- POFILES=
- UPDATEPOFILES=
- DUMMYPOFILES=
- GMOFILES=
- PROPERTIESFILES=
- CLASSFILES=
- QMFILES=
- MSGFILES=
- RESOURCESDLLFILES=
- for lang in $ALL_LINGUAS; do
- POFILES="$POFILES $srcdirpre$lang.po"
- UPDATEPOFILES="$UPDATEPOFILES $lang.po-update"
- DUMMYPOFILES="$DUMMYPOFILES $lang.nop"
- GMOFILES="$GMOFILES $srcdirpre$lang.gmo"
- PROPERTIESFILES="$PROPERTIESFILES \$(top_srcdir)/\$(DOMAIN)_$lang.properties"
- CLASSFILES="$CLASSFILES \$(top_srcdir)/\$(DOMAIN)_$lang.class"
- QMFILES="$QMFILES $srcdirpre$lang.qm"
- frobbedlang=`echo $lang | sed -e 's/\..*$//' -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
- MSGFILES="$MSGFILES $srcdirpre$frobbedlang.msg"
- frobbedlang=`echo $lang | sed -e 's/_/-/g' -e 's/^sr-CS/sr-SP/' -e 's/@latin$/-Latn/' -e 's/@cyrillic$/-Cyrl/' -e 's/^sr-SP$/sr-SP-Latn/' -e 's/^uz-UZ$/uz-UZ-Latn/'`
- RESOURCESDLLFILES="$RESOURCESDLLFILES $srcdirpre$frobbedlang/\$(DOMAIN).resources.dll"
- done
- # CATALOGS depends on both $ac_dir and the user's LINGUAS
- # environment variable.
- INST_LINGUAS=
- if test -n "$ALL_LINGUAS"; then
- for presentlang in $ALL_LINGUAS; do
- useit=no
- if test "%UNSET%" != "$LINGUAS"; then
- desiredlanguages="$LINGUAS"
- else
- desiredlanguages="$ALL_LINGUAS"
- fi
- for desiredlang in $desiredlanguages; do
- # Use the presentlang catalog if desiredlang is
- # a. equal to presentlang, or
- # b. a variant of presentlang (because in this case,
- # presentlang can be used as a fallback for messages
- # which are not translated in the desiredlang catalog).
- case "$desiredlang" in
- "$presentlang"*) useit=yes;;
- esac
- done
- if test $useit = yes; then
- INST_LINGUAS="$INST_LINGUAS $presentlang"
- fi
- done
- fi
- CATALOGS=
- JAVACATALOGS=
- QTCATALOGS=
- TCLCATALOGS=
- CSHARPCATALOGS=
- if test -n "$INST_LINGUAS"; then
- for lang in $INST_LINGUAS; do
- CATALOGS="$CATALOGS $lang.gmo"
- JAVACATALOGS="$JAVACATALOGS \$(DOMAIN)_$lang.properties"
- QTCATALOGS="$QTCATALOGS $lang.qm"
- frobbedlang=`echo $lang | sed -e 's/\..*$//' -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
- TCLCATALOGS="$TCLCATALOGS $frobbedlang.msg"
- frobbedlang=`echo $lang | sed -e 's/_/-/g' -e 's/^sr-CS/sr-SP/' -e 's/@latin$/-Latn/' -e 's/@cyrillic$/-Cyrl/' -e 's/^sr-SP$/sr-SP-Latn/' -e 's/^uz-UZ$/uz-UZ-Latn/'`
- CSHARPCATALOGS="$CSHARPCATALOGS $frobbedlang/\$(DOMAIN).resources.dll"
- done
- fi
-
- sed -e "s|@POTFILES_DEPS@|$POTFILES_DEPS|g" -e "s|@POFILES@|$POFILES|g" -e "s|@UPDATEPOFILES@|$UPDATEPOFILES|g" -e "s|@DUMMYPOFILES@|$DUMMYPOFILES|g" -e "s|@GMOFILES@|$GMOFILES|g" -e "s|@PROPERTIESFILES@|$PROPERTIESFILES|g" -e "s|@CLASSFILES@|$CLASSFILES|g" -e "s|@QMFILES@|$QMFILES|g" -e "s|@MSGFILES@|$MSGFILES|g" -e "s|@RESOURCESDLLFILES@|$RESOURCESDLLFILES|g" -e "s|@CATALOGS@|$CATALOGS|g" -e "s|@JAVACATALOGS@|$JAVACATALOGS|g" -e "s|@QTCATALOGS@|$QTCATALOGS|g" -e "s|@TCLCATALOGS@|$TCLCATALOGS|g" -e "s|@CSHARPCATALOGS@|$CSHARPCATALOGS|g" -e 's,^#distdir:,distdir:,' < "$ac_file" > "$ac_file.tmp"
- if grep -l '@TCLCATALOGS@' "$ac_file" > /dev/null; then
- # Add dependencies that cannot be formulated as a simple suffix rule.
- for lang in $ALL_LINGUAS; do
- frobbedlang=`echo $lang | sed -e 's/\..*$//' -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
- cat >> "$ac_file.tmp" <<EOF
-$frobbedlang.msg: $lang.po
- @echo "\$(MSGFMT) -c --tcl -d \$(srcdir) -l $lang $srcdirpre$lang.po"; \
- \$(MSGFMT) -c --tcl -d "\$(srcdir)" -l $lang $srcdirpre$lang.po || { rm -f "\$(srcdir)/$frobbedlang.msg"; exit 1; }
-EOF
- done
- fi
- if grep -l '@CSHARPCATALOGS@' "$ac_file" > /dev/null; then
- # Add dependencies that cannot be formulated as a simple suffix rule.
- for lang in $ALL_LINGUAS; do
- frobbedlang=`echo $lang | sed -e 's/_/-/g' -e 's/^sr-CS/sr-SP/' -e 's/@latin$/-Latn/' -e 's/@cyrillic$/-Cyrl/' -e 's/^sr-SP$/sr-SP-Latn/' -e 's/^uz-UZ$/uz-UZ-Latn/'`
- cat >> "$ac_file.tmp" <<EOF
-$frobbedlang/\$(DOMAIN).resources.dll: $lang.po
- @echo "\$(MSGFMT) -c --csharp -d \$(srcdir) -l $lang $srcdirpre$lang.po -r \$(DOMAIN)"; \
- \$(MSGFMT) -c --csharp -d "\$(srcdir)" -l $lang $srcdirpre$lang.po -r "\$(DOMAIN)" || { rm -f "\$(srcdir)/$frobbedlang.msg"; exit 1; }
-EOF
- done
- fi
- if test -n "$POMAKEFILEDEPS"; then
- cat >> "$ac_file.tmp" <<EOF
-Makefile: $POMAKEFILEDEPS
-EOF
- fi
- mv "$ac_file.tmp" "$ac_file"
-])
diff --git a/m4/programs.m4 b/m4/programs.m4
new file mode 100644
index 000000000..493888a0a
--- /dev/null
+++ b/m4/programs.m4
@@ -0,0 +1,124 @@
+dnl AC_PROG_GMSGFMT_PLURAL
+dnl ----------------------
+dnl Validate the GMSGFMT program found by gettext.m4; reject old versions
+dnl of GNU msgfmt that do not support the "msgid_plural" extension.
+AC_DEFUN([AC_PROG_GMSGFMT_PLURAL],
+ [dnl AC_REQUIRE(AM_GNU_GETTEXT)
+
+ if test "$GMSGFMT" != ":"; then
+ AC_MSG_CHECKING([for plural forms in GNU msgfmt])
+
+ changequote(,)dnl We use [ and ] in in .po test input
+
+ dnl If the GNU msgfmt does not accept msgid_plural we define it
+ dnl as : so that the Makefiles still can work.
+ cat >conftest.po <<_ACEOF
+msgid "channel"
+msgid_plural "channels"
+msgstr[0] "canal"
+msgstr[1] "canal"
+
+_ACEOF
+ changequote([,])dnl
+
+ if $GMSGFMT -o /dev/null conftest.po >/dev/null 2>&1; then
+ AC_MSG_RESULT(yes)
+ else
+ AC_MSG_RESULT(no)
+ AC_MSG_RESULT(
+ [found GNU msgfmt program is too old, it does not support plural forms; ignore it])
+ GMSGFMT=":"
+ fi
+ rm -f conftest.po
+ fi
+])dnl AC_PROG_GMSGFMT_PLURAL
+
+
+# AC_PROG_LIBTOOL_SANITYCHECK
+# ----------------------
+# Default configuration of libtool on solaris produces non-working
+# plugin modules, when gcc is used as compiler, and gcc does not
+# use gnu-ld
+AC_DEFUN([AC_PROG_LIBTOOL_SANITYCHECK],
+ [dnl AC_REQUIRE(AC_PROG_CC)
+ dnl AC_REQUIRE(AC_PROG_LD)
+ dnl AC_REQUIRE(AC_PROG_LIBTOOL)
+
+ case $host in
+ *-*-solaris*)
+ if test "$GCC" = yes && test "$with_gnu_ld" != yes; then
+ AC_MSG_CHECKING([if libtool can build working modules])
+ cat > conftest1.c <<_ACEOF
+#undef NDEBUG
+#include <assert.h>
+int shlib_func(long long a, long long b) {
+ assert(b);
+ switch (a&3) {
+ case 0: return a/b;
+ case 1: return a%b;
+ case 2: return (unsigned long long)a/b;
+ case 3: return (unsigned long long)a%b;
+ }
+}
+_ACEOF
+
+ cat > conftest2.c <<_ACEOF
+#include <dlfcn.h>
+int main(){
+ void *dl = dlopen(".libs/libconftest.so", RTLD_NOW);
+ if (!dl) printf("%s\n", dlerror());
+ exit(dl ? 0 : 1);
+}
+_ACEOF
+
+ if ./libtool $CC -c conftest1.c >/dev/null 2>&1 && \
+ ./libtool $CC -o libconftest.la conftest1.lo \
+ -module -avoid-version -rpath /tmp >/dev/null 2>&1 && \
+ ./libtool $CC -o conftest2 conftest2.c -ldl >/dev/null 2>&1
+ then
+ if ./conftest2 >/dev/null 2>&1; then
+ AC_MSG_RESULT(yes)
+ else
+ dnl typical problem: dlopen'ed module not self contained, because
+ dnl it wasn't linked with -lgcc
+ AC_MSG_RESULT(no)
+ if grep '^archive_cmds=.*$LD -G' libtool >/dev/null; then
+ AC_MSG_CHECKING([if libtool can be fixed])
+
+ dnl first try to update gcc2's spec file to add the
+ dnl gcc3 -mimpure-text flag
+
+ libtool_specs=""
+
+ if $CC -dumpspecs | grep -- '-G -dy -z text' >/dev/null; then
+ $CC -dumpspecs | \
+ sed 's/-G -dy -z text/-G -dy %{!mimpure-text:-z text}/g' \
+ > gcc-libtool-specs
+ libtool_specs=" -specs=`pwd`/gcc-libtool-specs"
+ fi
+
+ sed -e "s,\$LD -G,\$CC${libtool_specs} -shared -mimpure-text,g" \
+ -e 's/ -M / -Wl,-M,/' libtool >libtool-fixed
+ chmod +x libtool-fixed
+ if ./libtool-fixed $CC -o libconftest.la conftest1.lo \
+ -module -avoid-version -rpath /tmp >/dev/null 2>&1 && \
+ ./conftest2 >/dev/null 2>&1; then
+
+ dnl the fixed libtool works
+ AC_MSG_RESULT(yes)
+ mv -f libtool-fixed libtool
+
+ else
+ AC_MSG_RESULT(no)
+ fi
+ fi
+ fi
+ else
+ AC_MSG_RESULT(no)
+ fi
+ rm -f conftest1.c conftest1.lo conftest1.o conftest2.c \
+ libconftest.la conftest libtool-fixed
+ rm -rf .libs
+ fi ;;
+ esac
+])# AC_PROG_LIBTOOL_SANITYCHECK
diff --git a/m4/pthreads.m4 b/m4/pthreads.m4
index 363a8b4b2..d68cd13c8 100644
--- a/m4/pthreads.m4
+++ b/m4/pthreads.m4
@@ -61,3 +61,28 @@ AC_DEFUN([CC_PTHREAD_FLAGS], [
ifelse([$2], , [:], [$2])
fi
])
+
+AC_DEFUN([CC_PTHREAD_RECURSIVE_MUTEX], [
+ AC_REQUIRE([CC_PTHREAD_FLAGS])
+ AC_MSG_CHECKING([for recursive mutex support in pthread])
+
+ ac_save_LIBS="$LIBS"
+ LIBS="$LIBS $PTHREAD_LIBS"
+ AC_COMPILE_IFELSE(AC_LANG_SOURCE([#include <pthread.h>
+
+int main() {
+ pthread_mutexattr_t attr;
+ pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
+ return 0;
+}
+ ]), [have_recursive_mutex=yes], [have_recursive_mutex=no])
+ LIBS="$ac_save_LIBS"
+
+ AC_MSG_RESULT([$have_recursive_mutex])
+
+ if test x"$have_recursive_mutex" = x"yes"; then
+ ifelse([$1], , [:], [$1])
+ else
+ ifelse([$2], , [:], [$2])
+ fi
+])
diff --git a/m4/summary.m4 b/m4/summary.m4
new file mode 100644
index 000000000..792c5d319
--- /dev/null
+++ b/m4/summary.m4
@@ -0,0 +1,364 @@
+AC_DEFUN([XINE_LIB_SUMMARY], [
+ dnl ---------------------------------------------
+ dnl Some infos:
+ dnl ---------------------------------------------
+
+ echo "xine-lib summary:"
+ echo "----------------"
+
+ dnl Input
+ echo " * input plugins:"
+ echo " - file - net"
+ echo " - stdin_fifo - rtp"
+ echo " - http - mms"
+ echo " - pnm - rtsp"
+ if test x"$enable_vcd" != x"no"; then
+ if test x"$enable_vcdo" != x"no"; then
+ if test x"$with_internal_vcdlibs" = x"no"; then
+ echo " - vcdo - vcd (external libs)"
+ else
+ echo " - vcdo - vcd (internal libs)"
+ fi
+ else
+ if test x"$with_internal_vcdlibs" = x"no"; then
+ echo " - vcd (external libs)"
+ else
+ echo " - vcd (internal libs)"
+ fi
+ fi
+ fi
+ if test x"$with_external_dvdnav" != x"no"; then
+ echo " - dvd (external libs)"
+ else
+ echo " - dvd (internal libs)"
+ fi
+ test x"$have_dvb" = x"yes" && echo " - dvb - vdr"
+ test x"$have_gnomevfs" = x"yes" && echo " - gnome-vfs"
+ test x"$have_samba" = x"yes" && echo " - smb"
+ test x"$have_v4l" = x"yes" && echo " - v4l"
+ echo " - cdda"
+ echo ""
+
+ dnl Demuxers
+ echo " * demultiplexer plugins:"
+ echo " - avi - mpeg"
+ echo " - mpeg_block - mpeg_audio"
+ echo " - mpeg_elem - mpeg_pes"
+ echo " - mpeg_ts - qt/mpeg-4"
+ echo " - film - roq"
+ echo " - fli - smjpeg"
+ echo " - idcin - wav"
+ echo " - wc3 mve - voc"
+ echo " - vqa - aiff"
+ echo " - cdda - snd/au"
+ echo " - yuv4mpeg2 - real/realaudio"
+ echo " - ea wve - raw dv"
+ echo " - interplay mve - psx str"
+ echo " - ws aud - pva"
+ echo " - vox - nsf"
+ echo " - nsv - 4xm"
+ echo " - FLAC - aac"
+ echo " - iff - matroska"
+ echo " - vmd - flv"
+ if test x"$enable_a52dec" != x"no"; then
+ if test x"$have_external_a52dec" = x"yes"; then
+ echo " - ac3 (external library)"
+ else
+ echo " - ac3 (internal library)"
+ fi
+ fi
+ test x"$enable_asf" != x"no" && echo " - asf"
+ test x"$enable_mng" != x"no" && echo " - mng"
+ test x"$have_modplug" = x"yes" && echo " - mod"
+ test x"$have_libflac" = x"yes" && echo " - FLAC (with libFLAC)"
+ test x"$have_vorbis" = x"yes" && echo " - ogg"
+ test x"$have_wavpack" = x"yes" && echo " - WavPack"
+ echo ""
+
+ dnl video decoders
+ echo " * video decoder plugins:"
+ echo " - MPEG 1,2 - Amiga Bitplane"
+ echo " - Raw RGB - Raw YUV"
+ test x"$have_dxr3" = x"yes" && echo " - dxr3_video"
+ test x"$have_gdkpixbuf" = x"yes" && echo " - gdk-pixbuf"
+ test x"$have_imagemagick" = x"yes" && echo " - image"
+ test x"$have_theora" = x"yes" && echo " - theora"
+ test x"$have_w32dll" = x"yes" && echo " - w32dll"
+ if test x"$with_external_ffmpeg" != x"no"; then
+ echo " - ffmpeg (external library)"
+ else
+ echo " - ffmpeg (internal library):"
+ echo " - MPEG-4 (ISO, Microsoft, DivX*, XviD)"
+ echo " - Creative YUV - Motion JPEG"
+ echo " - Cinepak - MS Video-1"
+ echo " - FLI/FLC - MS RLE"
+ echo " - Id RoQ - Id Cin"
+ echo " - Apple Graphics - Apple Video"
+ echo " - Apple Animation - Interplay Video"
+ echo " - Westwood VQA - Origin Xan"
+ echo " - H.263 - Intel Indeo 3"
+ echo " - SVQ1 - SVQ3"
+ echo " - Real Video 1.0 - Real Video 2.0"
+ echo " - 4X Video - Sierra Video"
+ echo " - Asus v1/v2 - HuffYUV"
+ echo " - On2 VP3 - DV"
+ echo " - 8BPS - Duck TrueMotion v1"
+ echo " - ATI VCR1 - Flash Video"
+ echo " - ZLIB - MSZH"
+ fi
+ echo ""
+
+ dnl audio decoders
+ echo " * audio decoder plugins:"
+ echo " - GSM 06.10"
+ echo " - linear PCM - Nosefart (NSF)"
+ test x"$enable_faad" != x"no" && echo " - faad"
+ test x"$have_libflac" = x"yes" && echo " - FLAC (with libFLAC)"
+ test x"$have_speex" = x"yes" && echo " - speex"
+ test x"$have_vorbis" = x"yes" && echo " - vorbis"
+ test x"$have_w32dll" = x"yes" && echo " - w32dll"
+ test x"$have_wavpack" = x"yes" && echo " - WavPack"
+ if test x"$enable_mad" != x"no"; then
+ if test x"$have_external_libmad" = x"yes"; then
+ echo " - MAD (MPG 1/2/3) (external library)"
+ else
+ echo " - MAD (MPG 1/2/3) (internal library)"
+ fi
+ fi
+ if test x"$enable_libdts" != x"no"; then
+ if test x"$have_external_libdts" = x"yes"; then
+ echo " - DTS (external library)"
+ else
+ echo " - DTS (internal library)"
+ fi
+ fi
+ if test x"$enable_a52dec" != x"no"; then
+ if test x"$have_external_a52dec" = x"yes"; then
+ echo " - A52/ra-dnet (external library)"
+ else
+ echo " - A52/ra-dnet (internal library)"
+ fi
+ fi
+ if test x"$enable_musepack" != x"no"; then
+ if test x"$have_external_libmpcdec" = x"yes"; then
+ echo " - Musepack (external library)"
+ else
+ echo " - Musepack (internal library)"
+ fi
+ fi
+ if test x"$with_external_ffmpeg" = x"yes"; then
+ echo " - ffmpeg (external library)"
+ else
+ echo " - ffmpeg (internal library):"
+ echo " - Windows Media Audio v1/v2"
+ echo " - DV - logarithmic PCM"
+ echo " - 14k4 - 28k8"
+ echo " - MS ADPCM - IMA ADPCM"
+ echo " - XA ADPCM - Game DPCM/ADPCM"
+ echo " - Mace 3:13 - Mace 6:1"
+ echo " - FLAC"
+ fi
+ echo ""
+
+ dnl spu decoders
+ echo " * subtitle decoder plugins:"
+ echo " - spu - spucc"
+ echo " - spucmml - sputext"
+ echo " - spudvb"
+ test x"$have_dxr3" = x"yes" && echo " - dxr3_spu"
+ echo ""
+
+ dnl post plugins
+ echo " * post effect plugins:"
+ echo " * planar video effects:"
+ echo " - invert - expand"
+ echo " - eq - eq2"
+ echo " - boxblur - denoise3d"
+ echo " - unsharp - tvtime"
+ test x"$have_dvb" = x"yes" && echo " - vdr"
+ echo " * SFX:"
+ echo " - goom - oscope"
+ echo " - fftscope - mosaico"
+ echo ""
+
+ dnl Video plugins
+ echo " * video driver plugins:"
+ if test x"$no_x" != x"yes"; then
+ echo " - XShm (X11 shared memory)"
+ if test x"$have_syncfb" = x"yes"; then
+ echo " - SyncFB (for Matrox G200/G400 cards)"
+ fi
+ if test x"$have_xv" = x"yes"; then
+ if test x"$have_xv_static" = x"yes"; then
+ echo " - Xv (XVideo *static*)"
+ else
+ echo " - Xv (XVideo *shared*)"
+ fi
+ fi
+ if test x"$have_xxmc" = x"yes"; then
+ if test x"$have_vldexts" = x"yes"; then
+ echo " - XxMC (XVideo extended motion compensation)"
+ else
+ echo " - XxMC (XVideo motion compensation - vld extensions DISABLED)"
+ fi
+ fi
+ if test x"$have_xvmc" = x"yes"; then
+ echo " - XvMC (XVideo motion compensation)"
+ fi
+ if test x"$have_opengl" = x"yes"; then
+ if test x"$have_glu" = x"yes"; then
+ echo " - OpenGL (with GLU support)"
+ else
+ echo " - OpenGL"
+ fi
+ fi
+ if test x"$have_sunfb" = x"yes"; then
+ if test x"$have_sundga" = x"yes"; then
+ echo " - PGX64 (for Sun XVR100/PGX64/PGX24 cards)"
+ echo " - PGX32 (for Sun PGX32 cards)"
+ fi
+ fi
+ fi
+ if test x"$have_xcb" = x"yes"; then
+ if test x"$have_xcbshm" = x"yes"; then
+ echo " - xcb-shm (X shared memory using XCB)"
+ fi
+ if test x"$have_xcbxv" = x"yes"; then
+ echo " - xcb-xv (XVideo using XCB)"
+ fi
+ fi
+
+
+ test x"$have_aalib" = x"yes" && echo " - aa (Ascii ART)"
+ test x"$have_caca" = x"yes" && echo " - caca (Color AsCii Art)"
+ test x"$have_directfb" = x"yes" && echo " - directfb (DirectFB driver)"
+ test x"$have_directx" = x"yes" && echo " - directx (DirectX video driver)"
+ test x"$have_fb" = x"yes" && echo " - fb (Linux framebuffer device)"
+ test x"$have_libstk" = x"yes" && echo " - stk (Libstk Set-top Toolkit)"
+ test x"$have_macosx_video" = x"yes" && echo " - Mac OS X OpenGL"
+ test x"$have_sdl" = x"yes" && echo " - sdl (Simple DirectMedia Layer)"
+
+
+ if test x"$have_dxr3" = x"yes"; then
+ if test x"$have_encoder" = x"yes"; then
+ echo " - dxr3 (Hollywood+ and Creative dxr3, both mpeg and non-mpeg video)"
+ else
+ echo " - dxr3 (Hollywood+ and Creative dxr3, mpeg video only)"
+ fi
+ fi
+ if test x"$have_vidix" = x"yes"; then
+ echo $ECHO_N " - vidix ("
+
+ if test x"$no_x" != x"yes"; then
+ echo $ECHO_N "X11"
+ if test x"$have_fb" = x"yes"; then
+ echo $ECHO_N " and "
+ fi
+ fi
+
+ if test x"$have_fb" = x"yes"; then
+ echo $ECHO_N "framebuffer"
+ fi
+
+ echo $ECHO_N " support"
+
+ if test x"$enable_dha_kmod" != x"no"; then
+ echo " with dhahelper)"
+ else
+ echo ")"
+ fi
+ fi
+
+ echo ""
+
+ dnl Audio plugins
+ echo " * audio driver plugins:"
+ test x"$have_alsa" = x"yes" && echo " - alsa (ALSA - Advanced Linux Sound Architecture)"
+ test x"$have_arts" = x"yes" && echo " - arts (aRts - KDE soundserver)"
+ test x"$have_coreaudio" = x"yes" && echo " - CoreAudio (Mac OS X audio driver)"
+ test x"$have_directx" = x"yes" && echo " - directx (DirectX audio driver)"
+ test x"$have_esound" = x"yes" && echo " - esd (Enlightened Sound Daemon)"
+ test x"$have_fusionsound" = x"yes" && echo " - fusionsound (FusionSound driver)"
+ test x"$am_cv_have_irixal" = x"yes" && echo " - irixal (Irix audio library)"
+ test x"$have_jack" = x"yes" && echo " - Jack"
+ test x"$have_oss" = x"yes" && echo " - oss (Open Sound System)"
+ test x"$have_pulseaudio" = x"yes" && echo " - pulseaudio (PulseAudio sound server)"
+ test x"$have_sunaudio" = x"yes" && echo " - sun (Sun audio interface)"
+ echo "---"
+
+
+ dnl ---------------------------------------------
+ dnl some user warnings
+ dnl ---------------------------------------------
+
+ dnl some levels of variable expansion to get final install paths
+ final_libdir="`eval eval eval eval echo $libdir`"
+ final_bindir="`eval eval eval eval echo $bindir`"
+
+ if test -r /etc/ld.so.conf && ! grep -x "$final_libdir" /etc/ld.so.conf >/dev/null ; then
+ if test "$final_libdir" != "/lib" -a "$final_libdir" != "/usr/lib" ; then
+ if ! echo "$LD_LIBRARY_PATH" | egrep "(:|^)$final_libdir(/?:|/?$)" >/dev/null ; then
+ echo
+ echo "****************************************************************"
+ echo "xine-lib will be installed to $final_libdir"
+ echo
+ echo "This path is not mentioned among the linker search paths in your"
+ echo "/etc/ld.so.conf. This means it is possible that xine-lib will"
+ echo "not be found when you try to compile or run a program using it."
+ echo "If this happens, you should add $final_libdir to"
+ echo "the environment variable LD_LIBRARY_PATH like that:"
+ echo
+ echo "export LD_LIBRARY_PATH=$final_libdir:\$LD_LIBRARY_PATH"
+ echo
+ echo "Alternatively you can add a line \"$final_libdir\""
+ echo "to your /etc/ld.so.conf."
+ echo "****************************************************************"
+ echo
+ fi
+ fi
+ fi
+
+ if ! echo "$PATH" | egrep "(:|^)$final_bindir(/?:|/?$)" >/dev/null ; then
+ echo
+ echo "****************************************************************"
+ echo "xine-config will be installed to $final_bindir"
+ echo
+ echo "This path is not in your search path. This means it is possible"
+ echo "that xine-config will not be found when you try to compile a"
+ echo "program using xine-lib. This will result in build failures."
+ echo "If this happens, you should add $final_bindir to"
+ echo "the environment variable PATH like that:"
+ echo
+ echo "export PATH=$final_bindir:\$PATH"
+ echo
+ echo "Note that this is only needed for compilation. It is not needed"
+ echo "to have xine-config in your search path at runtime. (Although"
+ echo "it will not cause any harm either.)"
+ echo "****************************************************************"
+ echo
+ fi
+
+ dnl warn if no X11 plugins will be built
+ if test "x$no_x" = "xyes"; then
+ case $host in
+ *mingw*|*-cygwin) ;;
+ *-darwin*) ;;
+ *)
+ echo
+ echo "****************************************************************"
+ echo "WARNING! No X11 output plugins will be built."
+ echo
+ echo "For some reason, the requirements for building the X11 video"
+ echo "output plugins are not met. That means, that you will NOT be"
+ echo "able to use the resulting xine-lib to watch videos in a window"
+ echo "on any X11-based display (e.g. your desktop)."
+ echo
+ echo "If this is not what you want, provide the necessary X11 build"
+ echo "dependencies (usually done by installing a package called"
+ echo "XFree86-devel or similar) and run configure again."
+ echo "****************************************************************"
+ echo
+ ;;
+ esac
+ fi
+])
diff --git a/m4/types.m4 b/m4/types.m4
new file mode 100644
index 000000000..bf13428cb
--- /dev/null
+++ b/m4/types.m4
@@ -0,0 +1,215 @@
+dnl AC_COMPILE_CHECK_SIZEOF (TYPE SUPPOSED-SIZE)
+dnl abort if the given type does not have the supposed size
+AC_DEFUN([AC_COMPILE_CHECK_SIZEOF], [
+ AC_MSG_CHECKING(that size of $1 is $2)
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[switch (0) case 0: case (sizeof ($1) == $2):;]])],
+ [AC_MSG_RESULT([yes])], [AC_MSG_ERROR([can not build a default inttypes.h])])
+])
+
+
+dnl AC_CHECK_GENERATE_INTTYPES_H (INCLUDE-DIRECTORY)
+dnl generate a default inttypes.h if the header file does not exist already
+AC_DEFUN([AC_CHECK_GENERATE_INTTYPES],
+ [AC_CHECK_HEADER([inttypes.h],,
+ [if test ! -d $1; then mkdir $1; fi
+ AC_CHECK_HEADER([stdint.h],
+ [cat >$1/inttypes.h << EOF
+#ifndef _INTTYPES_H
+#define _INTTYPES_H
+/* helper inttypes.h for people who do not have it on their system */
+
+#include <stdint.h>
+EOF
+ ],
+ [AC_COMPILE_CHECK_SIZEOF([char],[1])
+ AC_COMPILE_CHECK_SIZEOF([short],[2])
+ AC_COMPILE_CHECK_SIZEOF([int],[4])
+ AC_COMPILE_CHECK_SIZEOF([long long],[8])
+ cat >$1/inttypes.h << EOF
+#ifndef _INTTYPES_H
+#define _INTTYPES_H
+/* default inttypes.h for people who do not have it on their system */
+#if (!defined __int8_t_defined) && (!defined __BIT_TYPES_DEFINED__)
+#define __int8_t_defined
+typedef signed char int8_t;
+typedef signed short int16_t;
+typedef signed int int32_t;
+#ifdef ARCH_X86
+typedef signed long long int64_t;
+#endif
+#endif
+#if (!defined __uint8_t_defined) && (!defined _LINUX_TYPES_H)
+#define __uint8_t_defined
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+#ifdef ARCH_X86
+typedef unsigned long long uint64_t;
+#endif
+#endif
+EOF
+ ])
+ cat >>$1/inttypes.h << EOF
+
+#ifdef WIN32
+# define PRI64_PREFIX "I64"
+#else
+# define PRI64_PREFIX "l"
+#endif
+
+#ifndef PRId8
+# define PRId8 "d"
+#endif
+#ifndef PRId16
+# define PRId16 "d"
+#endif
+#ifndef PRId32
+# define PRId32 "d"
+#endif
+#ifndef PRId64
+# define PRId64 PRI64_PREFIX "d"
+#endif
+
+#ifndef PRIu8
+# define PRIu8 "u"
+#endif
+#ifndef PRIu16
+# define PRIu16 "u"
+#endif
+#ifndef PRIu32
+# define PRIu32 "u"
+#endif
+#ifndef PRIu64
+# define PRIu64 PRI64_PREFIX "u"
+#endif
+
+#ifndef PRIx8
+# define PRIx8 "x"
+#endif
+#ifndef PRIx16
+# define PRIx16 "x"
+#endif
+#ifndef PRIx32
+# define PRIx32 "x"
+#endif
+#ifndef PRIx64
+# define PRIx64 PRI64_PREFIX "x"
+#endif
+
+#ifndef PRIX8
+# define PRIX8 "X"
+#endif
+#ifndef PRIX16
+# define PRIX16 "X"
+#endif
+#ifndef PRIX32
+# define PRIX32 "X"
+#endif
+#ifndef PRIX64
+# define PRIX64 PRI64_PREFIX "X"
+#endif
+
+#ifndef PRIdFAST8
+# define PRIdFAST8 "d"
+#endif
+#ifndef PRIdFAST16
+# define PRIdFAST16 "d"
+#endif
+#ifndef PRIdFAST32
+# define PRIdFAST32 "d"
+#endif
+#ifndef PRIdFAST64
+# define PRIdFAST64 "d"
+#endif
+
+#ifndef PRIuFAST8
+# define PRIuFAST8 "u"
+#endif
+#ifndef PRIuFAST16
+# define PRIuFAST16 "u"
+#endif
+#ifndef PRIuFAST32
+# define PRIuFAST32 "u"
+#endif
+#ifndef PRIuFAST64
+# define PRIuFAST64 PRI64_PREFIX "u"
+#endif
+
+#ifndef PRIxFAST8
+# define PRIxFAST8 "x"
+#endif
+#ifndef PRIxFAST16
+# define PRIxFAST16 "x"
+#endif
+#ifndef PRIxFAST32
+# define PRIxFAST32 "x"
+#endif
+#ifndef PRIxFAST64
+# define PRIxFAST64 PRI64_PREFIX "x"
+#endif
+
+#ifndef SCNd8
+# define SCNd8 "hhd"
+#endif
+#ifndef SCNd16
+# define SCNd16 "hd"
+#endif
+#ifndef SCNd32
+# define SCNd32 "d"
+#endif
+#ifndef SCNd64
+# define SCNd64 PRI64_PREFIX "d"
+#endif
+
+#ifndef SCNu8
+# define SCNu8 "hhu"
+#endif
+#ifndef SCNu16
+# define SCNu16 "hu"
+#endif
+#ifndef SCNu32
+# define SCNu32 "u"
+#endif
+#ifndef SCNu64
+# define SCNu64 PRI64_PREFIX "u"
+#endif
+
+#ifndef PRIdMAX
+# define PRIdMAX PRId64
+#endif
+#ifndef PRIuMAX
+# define PRIuMAX PRIu64
+#endif
+#ifndef PRIxMAX
+# define PRIxMAX PRIx64
+#endif
+#ifndef SCNdMAX
+# define SCNdMAX SCNd64
+#endif
+
+#endif
+EOF
+ ])])
+
+
+dnl Check for the type of the third argument of getsockname
+AC_DEFUN([AC_CHECK_SOCKLEN_T], [
+ AC_MSG_CHECKING([for socklen_t])
+ AC_LANG_PUSH([C])
+ AC_CACHE_VAL([ac_cv_socklen_t],
+ [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
+ #include <sys/socket.h>]],
+ [[socklen_t a=0; getsockname(0,(struct sockaddr*)0, &a)]])],
+ [ac_cv_socklen_t=socklen_t], [ac_cv_socklen_t=''])
+ if test x"$ac_cv_socklen_t" = x""; then
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
+ #include <sys/socket.h>]],
+ [[int a=0; getsockname(0,(struct sockaddr*)0, &a);]])],
+ [ac_cv_socklen_t=int], [ac_cv_socklen_t=size_t])
+ fi])
+ AC_LANG_POP([C])
+ AC_MSG_RESULT([$ac_cv_socklen_t])
+ if test x"$ac_cv_socklen_t" != x"socklen_t"; then
+ AC_DEFINE_UNQUOTED([socklen_t], [$ac_cv_socklen_t], [Define the real type of socklen_t])
+ fi
+])
diff --git a/m4/video_out.m4 b/m4/video_out.m4
new file mode 100644
index 000000000..4a0a37787
--- /dev/null
+++ b/m4/video_out.m4
@@ -0,0 +1,519 @@
+dnl -----------------
+dnl Video out plugins
+dnl -----------------
+AC_DEFUN([XINE_VIDEO_OUT_PLUGINS], [
+ dnl Setup defaults for the target operating system. For example, syncfb is
+ dnl only ever available on Linux, so don't bother checking for it unless
+ dnl explicitly requested to do so on other operating systems.
+ dnl Notes:
+ dnl - dha_kmod is Linux only, but disabled by default
+ dnl - directx is Windows only
+ dnl - dxr3 is Linux only
+ dnl - Mac OS X video is Mac OS X only
+ dnl - OpenGL requires Xwindows
+ dnl - SyncFB is Linux only, but disabled by default
+ dnl - Vidix is FreeBSD and Linux only
+ dnl - XvMC and xxmc depend on Xv
+
+ default_enable_aalib=enable
+ default_enable_dha_kmod=disable
+ default_enable_directfb=disable
+ default_enable_directx=disable
+ default_enable_dxr3=disable
+ default_enable_glu=enable
+ default_enable_linuxfb=disable
+ default_enable_macosx_video=disable
+ default_enable_opengl=enable
+ default_enable_syncfb=disable
+ default_enable_vidix=disable
+ default_enable_xinerama=enable
+ default_enable_xvmc=enable
+
+ default_with_caca=with
+ default_with_libstk=without
+ default_with_sdl=with
+ default_with_xcb=with
+
+ case "$host_os" in
+ cygwin* | mingw*)
+ default_enable_directx=enable
+ ;;
+
+ darwin*)
+ default_enable_macosx_video=enable
+ ;;
+
+ freebsd*)
+ default_enable_vidix=enable
+ ;;
+
+ linux*)
+ default_enable_dxr3=enable
+ default_enable_linuxfb=enable
+ default_enable_vidix=enable
+ enable_linux=yes
+ ;;
+ esac
+
+
+ dnl Ascii-Art
+ AC_ARG_ENABLE([aalib],
+ [AS_HELP_STRING([--enable-aalib], [enable support for AALIB])],
+ [test x"$enableval" != x"no" && enable_aalib="yes"],
+ [test $default_enable_aalib = disable && enable_aalib="no"])
+ if test x"$enable_aalib" != x"no"; then
+ ACX_PACKAGE_CHECK([AALIB], [1.4], [aalib-config], [have_aalib=yes], [have_aalib=no])
+ if test x"$enable_aalib" = x"yes" && test x"$have_aalib" != x"yes"; then
+ AC_MSG_ERROR([aalib support requested, but aalib not found])
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_AA], [test x"$have_aalib" = x"yes"])
+
+
+ dnl Color AsCii Art
+ AC_ARG_WITH([caca],
+ [AS_HELP_STRING([--with-caca], [enable support for CACA])],
+ [test x"$withval" != x"no" && with_caca="yes"],
+ [test $default_with_caca = without && with_caca=no])
+ if test x"$with_caca" != x"no"; then
+ PKG_CHECK_MODULES([CACA], [caca cucul], [have_caca="yes"], [have_caca="no"])
+ if test x"$with_caca" = x"yes" && test x"$have_caca" != x"yes"; then
+ AC_MSG_ERROR([CACA support requested, but libcaca 0.99 not found])
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_CACA], [test x"$have_caca" = x"yes"])
+
+
+ dnl dha (Linux only)
+ AC_ARG_ENABLE([dha-kmod],
+ [AS_HELP_STRING([--enable-dha-kmod], [build Linux DHA kernel module])],
+ [test x"$enableval" != x"no" && enable_dha_kmod="yes"],
+ [test $default_enable_dha_kmod = disable && enable_dha_kmod="no"])
+ if test x"$enable_dha_kmod" != x"no"; then
+ AC_ARG_WITH([linux-path],
+ [AS_HELP_STRING([--with-linux-path=PATH], [where the linux sources are located])],
+ [linux_path="$withval"], [linux_path="/usr/src/linux"])
+ LINUX_INCLUDE="-I$linux_path/include"
+ AC_SUBST(LINUX_INCLUDE)
+ AC_CHECK_PROG([MKNOD], [mknod], [mknod], [no])
+ AC_CHECK_PROG([DEPMOD], [depmod], [depmod], [no], ["$PATH:/sbin"])
+ fi
+ AM_CONDITIONAL([HAVE_LINUX], [test x"$enable_linux" = x"yes"])
+ AM_CONDITIONAL([BUILD_DHA_KMOD], [test x"$enable_dha_kmod" != x"no"])
+
+
+ dnl DirectFB
+ AC_ARG_ENABLE([directfb],
+ [AS_HELP_STRING([--enable-directfb], [enable use of DirectFB])],
+ [test x"$enableval" != x"no" && enable_directfb="yes"],
+ [test $default_enable_directfb = disable && enable_directfb="no"])
+ if test "x$enable_directfb" = "xyes"; then
+ PKG_CHECK_MODULES([DIRECTFB], [directfb >= 0.9.22], [have_directfb=yes], [have_directfb=no])
+ if test x"$enable_directfb" = x"yes" && test x"$have_directfb" != x"yes"; then
+ AC_MSG_ERROR([DirectFB support requested, but DirectFB not found])
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_DIRECTFB], [test x"$have_directfb" = x"yes"])
+
+
+ dnl DirectX (see directx.m4)
+ AM_PATH_DIRECTX
+
+
+ dnl dxr3 / hollywood plus card
+ AC_ARG_ENABLE([dxr3],
+ [AS_HELP_STRING([--enable-dxr3], [enable support for DXR3/HW+])],
+ [test x"$enableval" != x"no" && enable_dxr3="yes"],
+ [test $default_enable_dxr3 = disable && enable_dxr3="no"])
+ if test x"$enable_dxr3" != x"no"; then
+ have_dxr3=yes
+ AC_MSG_RESULT([*** checking for a supported mpeg encoder])
+ AC_CHECK_LIB([fame], [fame_open],
+ [AC_CHECK_HEADERS([fame.h], [have_libfame=yes], [have_libfame=no])], [have_libfame=no])
+ if test x"$have_libfame" = x"yes"; then
+ have_encoder=yes
+ AC_DEFINE([HAVE_LIBFAME], 1, [Define this if you have libfame mpeg encoder installed (fame.sf.net)])
+ ACX_PACKAGE_CHECK([LIBFAME], [0.8.10], [libfame-config],
+ [AC_DEFINE([HAVE_NEW_LIBFAME], 1, [Define this if you have libfame 0.8.10 or above])])
+ fi
+ AC_CHECK_LIB([rte], [rte_init],
+ [AC_CHECK_HEADERS([rte.h], [have_librte=yes], [have_librte=no])], [have_librte=no])
+ if test x"$have_librte" = x"yes"; then
+ have_encoder=yes
+ AC_MSG_WARN([this will probably only work with rte version 0.4!])
+ AC_DEFINE([HAVE_LIBRTE], 1, [Define this if you have librte mpeg encoder installed (zapping.sf.net)])
+ fi
+ if test "$have_encoder" = "yes"; then
+ AC_MSG_RESULT([*** found one or more external mpeg encoders])
+ else
+ AC_MSG_RESULT([*** no external mpeg encoder found])
+ fi
+ else
+ have_dxr3=no have_libfame=no have_librte=no have_encoder=no
+ fi
+ AM_CONDITIONAL([ENABLE_DXR3], [test x"$have_dxr3" = x"yes"])
+ AM_CONDITIONAL([HAVE_LIBFAME], [test x"$have_libfame" = x"yes"])
+ AM_CONDITIONAL([HAVE_LIBRTE], [test x"$have_librte" = x"yes"])
+
+
+ dnl LibSTK - http://www.libstk.net (project appears to be dead)
+ AC_ARG_WITH([libstk],
+ [AS_HELP_STRING([--with-libstk], [Build with STK surface video driver])],
+ [test x"$withval" != x"no" && with_libstk="yes"],
+ [test $default_with_libstk = without && with_libstk="no"])
+ if test x"$with_libstk" != x"no"; then
+ PKG_CHECK_MODULES([LIBSTK], [libstk >= 0.2.0], [have_libstk=yes], [have_libstk=no])
+ if test x"$with_libstk" = x"yes" && test x"$have_libstk" != x"yes"; then
+ AC_MSG_ERROR([libstk support requested, but libstk not found])
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_STK], [test x"$have_libstk" = x"yes"])
+
+
+ dnl Linux framebuffer device
+ AC_ARG_ENABLE([fb],
+ [AS_HELP_STRING([--enable-fb], [enable Linux framebuffer support])],
+ [test x"$enableval" != x"no" && enable_fb="yes"],
+ [test $default_enable_linuxfb = disable && enable_linuxfb="no"])
+ if test x"$enable_linuxfb" != x"no"; then
+ AC_CHECK_HEADERS([linux/fb.h], [have_fb=yes], [have_fb=no])
+ if test x"$enable_fb" = x"yes" && test x"$have_fb" != x"yes"; then
+ AC_MSG_ERROR([Linux framebuffer support requested, but required header file(s) not found])
+ elif test x"$have_fb" = x"yes"; then
+ dnl This define is needed by src/video_out/video_out_vidix.c
+ AC_DEFINE([HAVE_FB], 1, [Define this if you have linux framebuffer support])
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_FB], [test x"$have_fb" = x"yes"])
+
+
+ dnl Mac OS X OpenGL video output
+ AC_ARG_ENABLE([macosx-video],
+ [AS_HELP_STRING([--enable-macosx-video], [enable support for Mac OS X OpenGL video output])],
+ [test x"$enableval" != x"no" && enable_macosx_video="yes"],
+ [test $default_enable_macosx_video = disable && enable_macosx_video="no"])
+ if test x"$enable_macosx_video" != x"no"; then
+ AC_MSG_CHECKING([for Mac OS X video output frameworks])
+ ac_save_LIBS="$LIBS" LIBS="$LIBS -framework Cocoa -framework OpenGL"
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[return 0]])], [have_macosx_video=yes], [have_macosx_video=no])
+ LIBS="$ac_save_LIBS"
+ AC_MSG_RESULT([$have_macosx_video])
+ if test x"$enable_macosx_video" = x"yes" && test x"$have_macosx_video" != x"yes"; then
+ AC_MSG_ERROR([Mac OS X OpenGL video output support requested, but required frameworks not found])
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_MACOSX_VIDEO], [test x"$have_macosx_video" = x"yes"])
+
+
+ dnl OpenGL, including GLut and/or GLU
+ AC_ARG_ENABLE([opengl],
+ [AS_HELP_STRING([--enable-opengl], [enable support for X-based OpenGL video output])],
+ [test x"$enableval" != x"no" && enable_opengl="yes"],
+ [test $default_enable_opengl = disable && enable_opengl="no"])
+ AC_ARG_ENABLE([glu],
+ [AS_HELP_STRING([--enable-glu], [enable support for GLU in the OpenGL plugin])],
+ [test x"$enableval" != x"no" && enable_glu="yes"],
+ [test $default_enable_glu = disable && enable_glu="no"])
+ if test x"$enable_opengl" != x"no"; then
+ if test x"$no_x" = x"yes"; then
+ if test x"$enable_opengl" = x"yes"; then
+ AC_MSG_ERROR([OpenGL support requested, but X support is disabled])
+ fi
+ enable_opengl=no
+ fi
+ fi
+ if test x"$enable_opengl" != x"no"; then
+ ac_save_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $X_CFLAGS"
+ AC_CHECK_LIB([GL], [glBegin],
+ [AC_CHECK_HEADERS([GL/gl.h], [have_opengl=yes], [have_opengl=no])], [have_opengl=no],
+ [$X_LIBS -lm])
+ if test x"$enable_opengl" = x"yes" && test x"$have_opengl" != x"yes"; then
+ AC_MSG_ERROR([OpenGL support requested, but OpenGL not found])
+ elif test x"$have_opengl" = x"yes"; then
+ OPENGL_LIBS="-lGL -lm"
+ if test x"$enable_glu" != x"no"; then
+ have_glu=no
+ AC_CHECK_LIB([GLU], [gluPerspective],
+ [AC_CHECK_HEADERS([GL/glu.h],
+ [AC_MSG_CHECKING([if GLU is sane])
+ ac_save_LIBS="$LIBS" LIBS="-lGLU $X_LIBS $OPENGL_LIBS $LIBS"
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <GL/gl.h>
+ #include <GL/glu.h>]],
+ [[gluPerspective(45.0f, 1.33f, 1.0f, 1000.0f);
+ glBegin(GL_POINTS); glEnd()]])],
+ [have_glu=yes], [have_glu=no])
+ LIBS="$ac_save_LIBS"
+ AC_MSG_RESULT([$have_glu])], [have_glu=no])], [have_glu=no],
+ [$X_LIBS $OPENGL_LIBS])
+ if test x"$enable_glu" = x"yes" && test x"$have_glu" != x"yes"; then
+ AC_MSG_ERROR([OpenGL GLU support requested, but GLU not found])
+ elif test x"$have_glu" = x"yes"; then
+ AC_DEFINE([HAVE_GLU], 1, [Define this if you have GLU support available])
+ GLU_LIBS="-lGLU"
+ fi
+ fi
+ fi
+ CPPFLAGS="$ac_save_CPPFLAGS"
+ AC_SUBST(OPENGL_CFLAGS)
+ AC_SUBST(OPENGL_LIBS)
+ AC_SUBST(GLU_LIBS)
+ fi
+ AM_CONDITIONAL([ENABLE_OPENGL], [test x"$have_opengl" = x"yes"])
+
+
+ dnl SDL
+ AC_ARG_WITH([sdl],
+ [AS_HELP_STRING([--with-sdl], [Enable support for SDL video output])],
+ [test x"$withval" != x"no" && with_sdl="yes"],
+ [test $default_with_sdl = without && with_sdl="no"])
+ if test x"$with_sdl" != x"no"; then
+ PKG_CHECK_MODULES([SDL], [sdl], [have_sdl=yes], [have_sdl=no])
+ if test x"$with_sdl" = x"yes" && test x"$have_sdl" != x"yes"; then
+ AC_MSG_ERROR([SDL support requested, but SDL not found])
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_SDL], [test x"$have_sdl" = x"yes"])
+
+
+ dnl Solaris framebuffer device support (exists for more than just Solaris)
+ AC_CHECK_HEADERS([sys/fbio.h], [have_sunfb=yes], [have_sunfb=no])
+ if test x"$have_sunfb" = x"yes"; then
+ saved_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS -I/usr/openwin/include"
+ saved_LDFLAGS="$LDFLAGS" LDFLAGS="$LDFLAGS -L/usr/openwin/lib"
+ AC_CHECK_LIB([dga], [XDgaGrabDrawable],
+ [AC_CHECK_HEADER([dga/dga.h],
+ [SUNDGA_CFLAGS="-I/usr/openwin/include"
+ SUNDGA_LIBS="-L/usr/openwin/lib -R/usr/openwin/lib -ldga"
+ have_sundga=yes])])
+ CPPFLAGS="$saved_CPPFLAGS" LDFLAGS="$saved_LDFLAGS"
+ AC_SUBST(SUNDGA_CPPFLAGS)
+ AC_SUBST(SUNDGA_LIBS)
+ fi
+ AM_CONDITIONAL([ENABLE_SUNDGA], [test x"$have_sundga" = x"yes"])
+ AM_CONDITIONAL([ENABLE_SUNFB], [test x"$have_sunfb" = x"yes"])
+
+
+ dnl syncfb (Linux only)
+ AC_ARG_ENABLE([syncfb],
+ [AS_HELP_STRING([--enable-syncfb], [enable support for syncfb (Linux only)])],
+ [test x"$enableval" != x"no" && enable_syncfb="yes"],
+ [test $default_enable_syncfb = disable && enable_syncfb="no"])
+ dnl There's no good test for this. If the user says so, then do it
+ if test x"$enable_syncfb" != x"no" && test x"$no_x" != x"yes"; then
+ have_syncfb=yes
+ fi
+ if test x"$enable_syncfb" = x"yes" && test x"$have_syncfb" != x"yes"; then
+ AC_MSG_ERROR([Linux syncfb support requested, but required X support is disabled])
+ fi
+ AM_CONDITIONAL([ENABLE_SYNCFB], [test x"$have_syncfb" = x"yes"])
+
+
+ dnl xcb
+ AC_ARG_WITH([xcb],
+ [AS_HELP_STRING([--with-xcb], [Enable support for XCB video out plugins])],
+ [test x"$withval" != x"no" && with_xcb="yes"],
+ [test $default_with_xcb = without && with_xcb="no"])
+ if test x"$with_xcb" != x"no"; then
+ PKG_CHECK_MODULES([XCB], [xcb-shape >= 1.0], [have_xcb=yes], [have_xcb=no])
+ if test x"$enable_xcb" = x"yes" && test x"$have_xcb" != x"yes"; then
+ AC_MSG_ERROR([XCB support requested, but XCB not found])
+ elif test x"$have_xcb" = x"yes"; then
+ PKG_CHECK_MODULES([XCBSHM], [xcb-shm], [have_xcbshm=yes], [have_xcbshm=no])
+ PKG_CHECK_MODULES([XCBXV], [xcb-xv], [have_xcbxv=yes], [have_xcbxv=no])
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_XCB], [test x"$have_xcb" = x"yes"])
+ AM_CONDITIONAL([ENABLE_XCBSHM], [test x"$have_xcbshm" = x"yes"])
+ AM_CONDITIONAL([ENABLE_XCBXV], [test x"$have_xcbxv" = x"yes"])
+
+
+ dnl vidix/libdha
+ dnl Requires X11 or Linux framebuffer
+ AC_ARG_ENABLE([vidix],
+ [AS_HELP_STRING([--enable-vidix], [enable support for Vidix])],
+ [test x"$enableval" != x"no" && enable_vidix="yes"],
+ [test $default_enable_vidix = disable && enable_vidix="no"])
+ if test x"$enable_vidix" != x"no"; then
+ have_vidix=yes
+ if test x"$ac_cv_prog_AWK" = x"no"; then
+ have_vidix=no
+ else
+ if test x"$no_x" = x"yes" -o x"$have_fb" != x"yes"; then
+ have_vidix=no
+ else
+ case "$host_or_hostalias" in
+ i?86-*-linux* | k?-*-linux* | athlon-*-linux*) ;;
+ i?86-*-freebsd* | k?-*-freebsd* | athlon-*-freebsd*) ;;
+ *) have_vidix="no" ;;
+ esac
+ fi
+ fi
+ if test x"$enable_vidix" = x"yes" && test x"$have_vidix" != x"yes"; then
+ AC_MSG_ERROR([Vidix support requested, but not all requirements are met])
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_VIDIX], test x"$have_vidix" = x"yes")
+
+
+ dnl Xinerama
+ AC_ARG_ENABLE([xinerama],
+ [AS_HELP_STRING([--enable-xinerama], [enable support for Xinerama])],
+ [test x"$enableval" != x"no" && enable_xinerama="yes"],
+ [test $default_enable_xinerama = disable && enable_xinerama="no"])
+ if test x"$enable_xinerama" != x"no"; then
+ if test x"$no_x" != x"yes"; then
+ PKG_CHECK_MODULES([XINERAMA], [xinerama], [have_xinerama=yes],
+ [AC_CHECK_LIB([Xinerama], [XineramaQueryExtension],
+ [XINERAMA_LIBS="-lXinerama" have_xinerama="yes"], [],
+ [$X_LIBS])])
+ fi
+ if test x"$enable_xinerama" = x"yes" && test x"$have_xinerama" != x"yes"; then
+ AC_MSG_ERROR([Xinerama support requested, but Xinerama not found or X disabled])
+ elif test x"$have_xinerama" = x"yes"; then
+ AC_DEFINE([HAVE_XINERAMA], 1, [Define this if you have libXinerama installed])
+ X_LIBS="$X_LIBS $XINERAMA_LIBS"
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_XINERAMA], [test x"$have_xinerama" = x"yes"])
+
+
+ dnl xv
+ AC_ARG_WITH([xv-path],
+ [AS_HELP_STRING([--with-xv-path=path], [where libXv is installed])])
+ dnl With recent XFree86 or Xorg, dynamic linking is preferred!
+ dnl Only dynamic linking is possible when using libtool < 1.4.0
+ AC_ARG_ENABLE([static-xv],
+ [AS_HELP_STRING([--enable-static-xv], [Enable this to force linking against libXv.a])],
+ [test x"$enableval" != x"no" && xv_prefer_static="yes"], [xv_prefer_static="no"])
+ case "$host_or_hostalias" in
+ hppa*) xv_libexts="$acl_cv_shlibext" ;;
+ *)
+ if test x"$xv_prefer_static" = x"yes"; then
+ xv_libexts="$acl_cv_libext $acl_cv_shlibext"
+ else
+ xv_libexts="$acl_cv_shlibext $acl_cv_libext"
+ fi
+ ;;
+ esac
+ if test x"$no_x" != x"yes"; then
+ PKG_CHECK_MODULES([XV], [xv], [have_xv=yes], [have_xv=no])
+ if test x"$have_xv" = x"no"; then
+ dnl No Xv package -- search for it
+ for xv_libext in $xv_libexts; do
+ xv_lib="libXv.$xv_libext"
+ AC_MSG_CHECKING([for $xv_lib])
+ for xv_try_path in "$with_xv_path" "$x_libraries" /usr/X11R6/lib /usr/lib; do
+ if test x"$xv_try_path" != x"" && test -f "$xv_try_path/$xv_lib"; then
+ case $xv_lib in
+ *.$acl_cv_libext) have_xv_static=yes xv_try_libs="$xv_try_path/$xv_lib" ;;
+ *.$acl_cv_shlibext) have_xv_static=no xv_try_libs="${xv_try_path:+-L}$xv_try_path -lXv" ;;
+ esac
+ ac_save_LIBS="$LIBS" LIBS="$xv_try_libs $X_PRE_LIBS $X_LIBS $X_EXTRA_LIBS $LIBS"
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[XvShmCreateImage()]])], [have_xv=yes], [])
+ LIBS="$ac_save_LIBS"
+ if test x"$have_xv" = x"yes"; then
+ AC_MSG_RESULT([$xv_try_path])
+ XV_LIBS="$xv_try_libs"
+ break
+ fi
+ fi
+ done
+ test x"$have_xv" = x"yes" && break
+ AC_MSG_RESULT([no])
+ done
+ fi
+ if test x"$have_xv" = x"yes"; then
+ AC_DEFINE([HAVE_XV], 1, [Define this if you have libXv installed])
+ fi
+ fi
+ AM_CONDITIONAL([HAVE_XV], [test x"$have_xv" = x"yes"])
+
+
+ dnl XvMC
+ AC_ARG_ENABLE([xvmc],
+ [AS_HELP_STRING([--enable-xvmc], [Disable xxmc and XvMC outplut plugins])],
+ [test x"$enableval" != x"no" && enable_xvmc="yes"],
+ [test $default_enable_xvmc = disable && enable_xvmc="no"])
+ AC_ARG_WITH([xvmc-path],
+ [AS_HELP_STRING([--with-xvmc-path=PATH], [where libXvMC for the xvmc plugin are installed])],
+ [], [with_xvmc_path="$x_libraries"])
+ AC_ARG_WITH([xvmc-lib],
+ [AS_HELP_STRING([--with-xvmc-lib=LIBNAME], [The name of the XvMC library libLIBNAME.so for the xvmc plugin])],
+ [], [with_xvmc_lib="XvMCW"])
+ AC_ARG_WITH([xxmc-path],
+ [AS_HELP_STRING([--with-xxmc-path=PATH], [Where libXvMC for the xxmc plugin are installed])],
+ [], [with_xxmc_path="$x_libraries"])
+ AC_ARG_WITH([xxmc-lib],
+ [AS_HELP_STRING([--with-xxmc-lib=LIBNAME], [The name of the XvMC library libLIBNAME.so for the xxmc plugin])],
+ [], [with_xxmc_lib="XvMCW"])
+ if test x"$enable_xvmc" != x"no"; then
+ if test x"$have_xv" != x"yes"; then
+ have_xvmc=no have_xxmc=no have_xvmc_or_xxmc=no
+ else
+ ac_save_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $X_CFLAGS"
+ ac_save_LIBS="$LIBS"
+
+ dnl Check for xxmc
+ XXMC_LIBS="${with_xxmc_path:+-L}$with_xxmc_path -l$with_xxmc_lib"
+ AC_SUBST(XXMC_LIBS)
+ AC_MSG_CHECKING([whether to enable the xxmc plugin with VLD extensions])
+ AC_MSG_RESULT([])
+ LIBS="$XXMC_LIBS $X_LIBS $XV_LIBS $LIBS"
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[XvMCPutSlice()]])], [have_xxmc=yes],
+ [LIBS="$XXMC_LIBS -lXvMC $X_LIBS $XV_LIBS $LIBS"
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[XvMCPutSlice()]])],
+ [have_xxmc=yes XXMC_LIBS="$XXMC_LIBS -lXvMC"])])
+ if test x"$have_xxmc" = x"yes"; then
+ AC_CHECK_HEADERS([X11/extensions/vldXvMC.h],
+ [have_vldexts=yes
+ AC_DEFINE([HAVE_VLDXVMC], 1, [Define if you have vldXvMC.h])],
+ [have_vldexts=no])
+ else
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[XvMCCreateContext()]])], [have_xxmc=yes],
+ [LIBS="$XXMC_LIBS -lXvMC $X_LIBS $XV_LIBS $LIBS"
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[XvMCCreateContext()]])],
+ [have_xxmc=yes XXMC_LIBS="$XXMC_LIBS -lXvMC"])])
+ fi
+ if test x"$have_xxmc" = x"yes"; then
+ AC_CHECK_HEADERS([X11/extensions/XvMC.h], [], [have_xxmc=no])
+ fi
+
+ dnl Check for xvmc
+ XVMC_LIBS="${with_xvmc_path:+-L}$with_xvmc_path -l$with_xvmc_lib"
+ AC_SUBST(XVMC_LIBS)
+ AC_MSG_CHECKING([whether to enable the xvmc plugin])
+ AC_MSG_RESULT([])
+ LIBS="$XVMC_LIBS $X_LIBS $XV_LIBS $LIBS"
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[XvMCCreateContext()]])], [have_xvmc=yes],
+ [LIBS="$XVMC_LIBS -lXvMC $X_LIBS $XV_LIBS $LIBS"
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[XvMCCreateContext()]])],
+ [have_xvmc=yes XVMC_LIBS="$XVMC_LIBS -lXvMC"])])
+ if test x"$have_xvmc" = x"yes"; then
+ AC_CHECK_HEADERS([X11/extensions/XvMC.h], [], [have_xvmc=no])
+ fi
+ CPPFLAGS="$ac_save_CPPFLAGS" LIBS="$ac_save_LIBS"
+ fi
+ have_xvmc_or_xxmc="$have_xvmc"; test x"$have_xxmc" = x"yes" && have_xvmc_or_xxmc=yes
+ if test x"$enable_xvmc" = x"yes" && test x"$have_xvmc_or_xxmc" != x"yes"; then
+ AC_MSG_ERROR([XvMC support requested, but neither XvMC nor xxmc could be found, or X is disabled])
+ else
+ if test x"$have_xvmc" = x"yes"; then
+ AC_DEFINE([HAVE_XVMC], 1, [Define this if you have an XvMC library and XvMC.h installed.])
+ AC_MSG_RESULT([*** Enabling old xvmc plugin.])
+ else
+ AC_MSG_RESULT([*** Disabling old xvmc plugin.])
+ fi
+ if test x"$have_xxmc" = x"yes"; then
+ if test x"$have_vldexts" = x"yes"; then
+ AC_MSG_RESULT([*** Enabling xxmc plugin with vld extensions.])
+ else
+ AC_MSG_RESULT([*** Enabling xxmc plugin for standard XvMC *only*.])
+ fi
+ else
+ AC_MSG_RESULT([*** Disabling xxmc plugin.])
+ fi
+ fi
+ fi
+ AM_CONDITIONAL([ENABLE_XVMC], [test x"$have_xvmc" = x"yes"])
+ AM_CONDITIONAL([ENABLE_XXMC], [test x"$have_xxmc" = x"yes"])
+])dnl XINE_VIDEO_OUT_PLUGINS
diff --git a/m4/xine.m4 b/m4/xine.m4
index cb64bad1a..336a2d7d2 100644
--- a/m4/xine.m4
+++ b/m4/xine.m4
@@ -23,193 +23,91 @@ dnl script generated by Autoconf, you may include it under the same
dnl distribution terms that you use for the rest of that program.
dnl
-dnl AM_PATH_XINE([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
-dnl Test for XINE, and define XINE_CFLAGS and XINE_LIBS
-dnl
-AC_DEFUN([AM_PATH_XINE],
-[dnl
-dnl Get the cflags and libraries from the xine-config script
-dnl
-AC_ARG_WITH(xine-prefix,
- AS_HELP_STRING([--with-xine-prefix=DIR], [prefix where XINE is installed (optional)]),
- xine_config_prefix="$withval", xine_config_prefix="")
-AC_ARG_WITH(xine-exec-prefix,
- AS_HELP_STRING([--with-xine-exec-prefix=DIR], [exec prefix where XINE is installed (optional)]),
- xine_config_exec_prefix="$withval", xine_config_exec_prefix="")
-AC_ARG_ENABLE(xinetest,
- AS_HELP_STRING([--disable-xinetest], [do not try to compile and run a test XINE program]),
- enable_xinetest=$enableval, enable_xinetest=yes)
-
- AC_LANG_PUSH([C])
+dnl _XINE_VERSION_PARSE(version)
+AC_DEFUN([_XINE_VERSION_PARSE], [`echo $1 | perl -e 'my $v = <>; chomp $v;
+my @v = split(" ", $v); $v = $v[[@S|@#v]]; $v =~ s/[[^0-9.]].*$//; @v = split (/\./, $v);
+push @v, 0 while $[#v] < 2; print $v[[0]] * 10000 + $v[[1]] * 100 + $v[[2]], "\n"'`])
- if test x$xine_config_exec_prefix != x ; then
- xine_config_args="$xine_config_args --exec-prefix=$xine_config_exec_prefix"
- if test x${XINE_CONFIG+set} != xset ; then
- XINE_CONFIG=$xine_config_exec_prefix/bin/xine-config
- fi
- fi
- if test x$xine_config_prefix != x ; then
- xine_config_args="$xine_config_args --prefix=$xine_config_prefix"
- if test x${XINE_CONFIG+set} != xset ; then
- XINE_CONFIG=$xine_config_prefix/bin/xine-config
- fi
- fi
- min_xine_version=ifelse([$1], ,0.5.0,$1)
- if test "x$enable_xinetest" != "xyes" ; then
- AC_MSG_CHECKING([for XINE-LIB version >= $min_xine_version])
- else
- AC_PATH_TOOL(XINE_CONFIG, xine-config, no)
- AC_MSG_CHECKING([for XINE-LIB version >= $min_xine_version])
- no_xine=""
- if test "$XINE_CONFIG" = "no" ; then
- no_xine=yes
+dnl _XINE_VERSION_CHECK(required, actual)
+AC_DEFUN([_XINE_VERSION_CHECK], [
+ required_version=ifelse([$1], , [0.0.0], [$1])
+ required_version_parsed=_XINE_VERSION_PARSE([$required_version])
+ actual_version=ifelse([$2], , [0.0.0], [$2])
+ actual_version_parsed=_XINE_VERSION_PARSE([$actual_version])
+ if test $required_version_parsed -le $actual_version_parsed; then
+ ifelse([$3], , [:], [$3])
else
- XINE_CFLAGS=`$XINE_CONFIG $xine_config_args --cflags`
- XINE_LIBS=`$XINE_CONFIG $xine_config_args --libs`
- XINE_ACFLAGS=`$XINE_CONFIG $xine_config_args --acflags`
- xine_config_major_version=`$XINE_CONFIG $xine_config_args --version | \
- sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
- xine_config_minor_version=`$XINE_CONFIG $xine_config_args --version | \
- sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
- xine_config_sub_version=`$XINE_CONFIG $xine_config_args --version | \
- sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
- xine_data_dir=`$XINE_CONFIG $xine_config_args --datadir`
- xine_script_dir=`$XINE_CONFIG $xine_config_args --scriptdir`
- xine_plugin_dir=`$XINE_CONFIG $xine_config_args --plugindir`
- xine_locale_dir=`$XINE_CONFIG $xine_config_args --localedir`
- dnl if test "x$enable_xinetest" = "xyes" ; then
- ac_save_CFLAGS="$CFLAGS"
- ac_save_LIBS="$LIBS"
- CFLAGS="$CFLAGS $XINE_CFLAGS"
- LIBS="$XINE_LIBS $LIBS"
-dnl
-dnl Now check if the installed XINE is sufficiently new. (Also sanity
-dnl checks the results of xine-config to some extent
-dnl
- rm -f conf.xinetest
- AC_RUN_IFELSE([AC_LANG_SOURCE([[
-#include <xine.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-int
-main ()
-{
- int major, minor, sub;
- char *tmp_version;
+ ifelse([$4], , [:], [$4])
+ fi
+])
- system ("touch conf.xinetest");
- /* HP/UX 9 (%@#!) writes to sscanf strings */
- tmp_version = (char *) strdup("$min_xine_version");
- if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &sub) != 3) {
- printf("%s, bad version string\n", "$min_xine_version");
- exit(1);
- }
+dnl AM_PATH_XINE([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
+dnl Test for XINE, and define XINE_CFLAGS and XINE_LIBS
+dnl
+AC_DEFUN([AM_PATH_XINE], [
+ AC_ARG_VAR([XINE_CONFIG], [Full path to xine-config])
+ AC_ARG_WITH([xine-prefix],
+ [AS_HELP_STRING([--with-xine-prefix], [prefix where xine-lib is installed (optional)])])
+ AC_ARG_WITH([xine-exec-prefix],
+ [AS_HELP_STRING([--with-xine-exec-prefix], [exec prefix where xine-lib is installed (optional)])])
- if ((XINE_MAJOR_VERSION != $xine_config_major_version) ||
- (XINE_MINOR_VERSION != $xine_config_minor_version) ||
- (XINE_SUB_VERSION != $xine_config_sub_version))
- {
- printf("\n*** 'xine-config --version' returned %d.%d.%d, but XINE (%d.%d.%d)\n",
- $xine_config_major_version, $xine_config_minor_version, $xine_config_sub_version,
- XINE_MAJOR_VERSION, XINE_MINOR_VERSION, XINE_SUB_VERSION);
- printf ("*** was found! If xine-config was correct, then it is best\n");
- printf ("*** to remove the old version of XINE. You may also be able to fix the error\n");
- printf("*** by modifying your LD_LIBRARY_PATH enviroment variable, or by editing\n");
- printf("*** /etc/ld.so.conf. Make sure you have run ldconfig if that is\n");
- printf("*** required on your system.\n");
- printf("*** If xine-config was wrong, set the environment variable XINE_CONFIG\n");
- printf("*** to point to the correct copy of xine-config, and remove the file config.cache\n");
- printf("*** before re-running configure\n");
- }
- else
- {
- if ((XINE_MAJOR_VERSION > major) ||
- ((XINE_MAJOR_VERSION == major) && (XINE_MINOR_VERSION > minor)) ||
- ((XINE_MAJOR_VERSION == major) && (XINE_MINOR_VERSION == minor) && (XINE_SUB_VERSION >= sub)))
- {
- return 0;
- }
- else
- {
- printf("\n*** An old version of XINE (%d.%d.%d) was found.\n",
- XINE_MAJOR_VERSION, XINE_MINOR_VERSION, XINE_SUB_VERSION);
- printf("*** You need a version of XINE newer than %d.%d.%d. The latest version of\n",
- major, minor, sub);
- printf("*** XINE is always available from:\n");
- printf("*** http://xine.sourceforge.net\n");
- printf("***\n");
- printf("*** If you have already installed a sufficiently new version, this error\n");
- printf("*** probably means that the wrong copy of the xine-config shell script is\n");
- printf("*** being found. The easiest way to fix this is to remove the old version\n");
- printf("*** of XINE, but you can also set the XINE_CONFIG environment to point to the\n");
- printf("*** correct copy of xine-config. (In this case, you will have to\n");
- printf("*** modify your LD_LIBRARY_PATH enviroment variable, or edit /etc/ld.so.conf\n");
- printf("*** so that the correct libraries are found at run-time))\n");
- }
- }
- return 1;
-}
-]])],[],[no_xine=yes],[echo $ac_n "cross compiling; assumed OK... $ac_c"])
- CFLAGS="$ac_save_CFLAGS"
- LIBS="$ac_save_LIBS"
- fi
+ xine_config_args=""
+ if test x"$with_xine_exec_prefix" != x""; then
+ xine_config_args="$xine_config_args --exec-prefix=$with_xine_exec_prefix"
+ test x"$XINE_CONFIG" != x"" && XINE_CONFIG="$with_xine_exec_prefix/bin/xine-config"
+ fi
+ if test x"$with_xine_prefix" != x""; then
+ xine_config_args="$xine_config_args --prefix=$with_xine_prefix"
+ test x"$XINE_CONFIG" = x"" && XINE_CONFIG="$with_xine_prefix/bin/xine-config"
fi
- if test "x$no_xine" = x ; then
- AC_MSG_RESULT(yes)
- ifelse([$2], , :, [$2])
+
+ min_xine_version=ifelse([$1], , [0.5.0], [$1])
+ AC_PATH_TOOL([XINE_CONFIG], [xine-config], [no])
+ AC_MSG_CHECKING([for XINE-LIB version >= $min_xine_version])
+ if test x"$XINE_CONFIG" = x"no"; then
+ AC_MSG_RESULT([unknown])
+ AC_MSG_NOTICE([
+*** If xine-lib was installed in PREFIX, make sure PREFIX/bin is in your path,
+*** or set the XINE_CONFIG environment variable to the full path to the
+*** xine-config shell script.
+ ])
else
- AC_MSG_RESULT(no)
- if test "$XINE_CONFIG" = "no" ; then
- echo "*** The xine-config script installed by XINE could not be found"
- echo "*** If XINE was installed in PREFIX, make sure PREFIX/bin is in"
- echo "*** your path, or set the XINE_CONFIG environment variable to the"
- echo "*** full path to xine-config."
- else
- if test -f conf.xinetest ; then
- :
- else
- echo "*** Could not run XINE test program, checking why..."
- CFLAGS="$CFLAGS $XINE_CFLAGS"
- LIBS="$LIBS $XINE_LIBS"
- AC_LINK_IFELSE([AC_LANG_PROGRAM([[
-#include <xine.h>
-#include <stdio.h>
-]], [[ return ((XINE_MAJOR_VERSION) || (XINE_MINOR_VERSION) || (XINE_SUB_VERSION)); ]])],
- [ echo "*** The test program compiled, but did not run. This usually means"
- echo "*** that the run-time linker is not finding XINE or finding the wrong"
- echo "*** version of XINE. If it is not finding XINE, you'll need to set your"
- echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
- echo "*** to the installed location Also, make sure you have run ldconfig if that"
- echo "*** is required on your system"
- echo "***"
- echo "*** If you have an old version installed, it is best to remove it, although"
- echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"
- echo "***"],
- [ echo "*** The test program failed to compile or link. See the file config.log for the"
- echo "*** exact error that occured. This usually means XINE was incorrectly installed"
- echo "*** or that you have moved XINE since it was installed. In the latter case, you"
- echo "*** may want to edit the xine-config script: $XINE_CONFIG" ])
- CFLAGS="$ac_save_CFLAGS"
- LIBS="$ac_save_LIBS"
+ XINE_CFLAGS="`$XINE_CONFIG $xine_config_args --cflags`"
+ XINE_LIBS="`$XINE_CONFIG $xine_config_args --libs`"
+ XINE_VERSION="`$XINE_CONFIG $xine_config_args --version`"
+ XINE_ACFLAGS="`$XINE_CONFIG $xine_config_args --acflags`"
+ xine_data_dir="`$XINE_CONFIG $xine_config_args --datadir`"
+ xine_script_dir="`$XINE_CONFIG $xine_config_args --scriptdir`"
+ xine_plugin_dir="`$XINE_CONFIG $xine_config_args --plugindir`"
+ xine_locale_dir="`$XINE_CONFIG $xine_config_args --localedir`"
+ _XINE_VERSION_CHECK([$min_xine_version], [$XINE_VERSION],
+ [xine_version_ok=yes; AC_MSG_RESULT([yes, $XINE_VERSION])],
+ [xine_version_ok=no; AC_MSG_RESULT([no, $XINE_VERSION])])
+ if test x"$xine_version_ok" != x"yes"; then
+ AC_MSG_NOTICE([
+*** You need a version of xine-lib newer than $XINE_VERSION.
+*** The latest version of xine-lib is always available from:
+*** http://www.xinehq.de
+***
+*** If you have already installed a sufficiently new version, this error
+*** probably means that the wrong copy of the xine-config shell script is
+*** being found. The easiest way to fix this is to remove the old version
+*** of xine-lib, but you can also set the XINE_CONFIG environment variable
+*** to point to the correct copy of xine-config. In this case, you will have
+*** to modify your LD_LIBRARY_PATH enviroment variable, or edit
+*** /etc/ld.so.conf so that the correct libraries are found at run-time.
+ ])
fi
- fi
- XINE_CFLAGS=""
- XINE_LIBS=""
- ifelse([$3], , :, [$3])
- fi
- AC_SUBST(XINE_CFLAGS)
- AC_SUBST(XINE_LIBS)
- AC_SUBST(XINE_ACFLAGS)
- AC_LANG_POP([C])
- rm -f conf.xinetest
+ fi
+ AC_SUBST(XINE_CFLAGS)
+ AC_SUBST(XINE_LIBS)
+ AC_SUBST(XINE_ACFLAGS)
-dnl Make sure HAVE_STRSEP, HAVE_SETENV and HAVE_STRPBRK are defined as
-dnl necessary.
- AC_CHECK_FUNCS([strsep strpbrk setenv])
-dnl alloca (in public macro) and MinGW
- AC_CHECK_HEADERS([malloc.h])
+ if test x"$xine_version_ok" = x"yes"; then
+ ifelse([$2], , [:], [$2])
+ else
+ ifelse([$3], , [:], [$3])
+ fi
])
diff --git a/m4/xv.m4 b/m4/xv.m4
deleted file mode 100644
index 91380a1de..000000000
--- a/m4/xv.m4
+++ /dev/null
@@ -1,93 +0,0 @@
-# AC_FIND_LIBXV_IMPL (LIB)
-# -------------------------
-#
-AC_DEFUN([AC_PATH_LIBXV_IMPL],
-[
- AC_MSG_CHECKING([for $1])
- if test -f "$xv_path/$1"; then
- AC_MSG_RESULT([found $1 in $xv_path])
- XV_LIBS="$1"
- else
- if test -f "/usr/lib/$1"; then
- AC_MSG_RESULT([found $1 in /usr/lib])
- XV_LIBS="$1"
- else
- AC_MSG_RESULT([$1 not found in $xv_path])
- fi
- fi
-])
-
-AC_DEFUN([AC_TEST_LIBXV],
-[
- dnl -----------------------------------------------
- dnl Testing installed Xv library
- dnl -----------------------------------------------
- AC_CHECK_LIB(Xv, XvShmCreateImage,
- [
- AC_DEFINE(HAVE_XV,
- 1,
- [Define this if you have libXv installed])
-
- ac_have_xv="yes"
- case x$XV_LIBS in
- x*.a)
- AC_DEFINE(HAVE_XV_STATIC,
- 1,
- [Define this if you have libXv.a])
- ac_have_xv_static="yes"
- XV_LIBS="$xv_path/$XV_LIBS"
- ;;
- x*.so)
- XV_LIBS=`echo $XV_LIBS | sed 's/^lib/-l/; s/\.so$//'`
- ;;
- *)
- AC_MSG_ERROR([sorry, I don't know about $XV_LIBS])
- ;;
- esac
- ],
- ,
- [$X_LIBS $X_PRE_LIBS -lXext $X_EXTRA_LIBS])
-
- dnl -----------------------------------------------
- dnl xine_check use Xv functions API.
- dnl -----------------------------------------------
- if test x$ac_have_xv = "xyes"; then
- EXTRA_X_LIBS="-L$xv_path $XV_LIBS -lXext"
- EXTRA_X_CFLAGS=""
- fi
- AC_SUBST(XV_LIBS)
- AC_SUBST(EXTRA_X_LIBS)
- AC_SUBST(EXTRA_X_CFLAGS)
-])
-
-# AC_PATH_LIBXV
-# -------------------------
-#
-AC_DEFUN([AC_FIND_LIBXV],
-[
- # Ensure that AC_PATH_XTRA is executed before this
- AC_REQUIRE([AC_PATH_XTRA])
-
- if test x$xv_path = x; then
- xv_path=/usr/X11R6/lib
- fi
-
- if test "x$xv_prefer_shared" = "xyes"; then
- AC_PATH_LIBXV_IMPL([libXv.so])
- else
- AC_PATH_LIBXV_IMPL([libXv.a])
- fi
-
- # Try the other lib if prefered failed
- if test x$XV_LIBS = x; then
- if ! test "x$xv_prefer_shared" = "xyes"; then
- AC_PATH_LIBXV_IMPL([libXv.so])
- else
- AC_PATH_LIBXV_IMPL([libXv.a])
- fi
- fi
-
- if ! test x$XV_LIBS = x; then
- AC_TEST_LIBXV
- fi
-])
diff --git a/misc/Makefile.common b/misc/Makefile.common
index d23ea5b5e..edafcea4b 100644
--- a/misc/Makefile.common
+++ b/misc/Makefile.common
@@ -9,7 +9,10 @@ xinepostdir = $(XINE_PLUGINDIR)/post
vidixdir = $(XINE_PLUGINDIR)/vidix
$(XINE_LIB):
- @cd $(top_srcdir)/src/xine-engine && $(MAKE)
+ $(MAKE) -C $(top_builddir)/src/xine-engine
+
+$(top_builddir)/contrib/libxdg-basedir/libxdg-basedir.la:
+ $(MAKE) -C $(top_builddir)/contrib/libxdg-basedir
install-data-hook:
@if test $$MAKELEVEL -le 4 ; then \
@@ -38,16 +41,6 @@ pass1:
pass2:
@$(MAKE) MULTIPASS_CFLAGS="$(PASS2_CFLAGS)"
-debug:
- @$(MAKE) CFLAGS="$(DEBUG_CFLAGS)"
-
-install-debug: debug
- @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
- @list='$(SUBDIRS)'; for subdir in $$list; do \
- (cd $$subdir && $(MAKE) $@) || exit; \
- done;
- $(MAKE) $(AM_MAKEFLAGS) install-data-hook
-
uninstall-hook:
@list='$(xineplug_LTLIBRARIES)'; for p in $$list; do \
p="`echo $$p | sed -e 's/\.la$$/\.so/g;s|^.*/||'`"; \
diff --git a/misc/SlackBuild.in b/misc/SlackBuild.in
index d356a1766..118613c6a 100644
--- a/misc/SlackBuild.in
+++ b/misc/SlackBuild.in
@@ -27,7 +27,7 @@ EOF
#
do_descr() {
cat > package_descriptions << EOF
-@PACKAGE@: @PACKAGE@ @SPEC_VERSION@.
+@PACKAGE@: @PACKAGE@ @PACKAGE_VERSION@.
@PACKAGE@:
@PACKAGE@: xine-lib is the beating heart of xine (a free gpl-licensed
@PACKAGE@: video player for unix-like systems) which among others provides
@@ -53,12 +53,12 @@ do_build() {
cd $CWD
rm -rf $TMPBUILD
mkdir -p $TMPBUILD
- cd $TMPBUILD && tar -xzf $CWD/@TAR_NAME@.tar.gz
+ cd $TMPBUILD && tar -xzf $CWD/@PACKAGE_TARNAME@.tar.gz
do_install_sh;
- cd @TAR_NAME@
+ cd @PACKAGE_TARNAME@
DIE=1
- echo "./configure --prefix=$PREFIX $CONFIG_OPT && make && make install-strip DESTDIR=$PKG LIBRARY_PATH=$TMPBUILD/@TAR_NAME@/src/xine-engine/.libs" && \
- ./configure --prefix=$PREFIX $CONFIG_OPT && make && make install-strip DESTDIR=$PKG LIBRARY_PATH=$TMPBUILD/@TAR_NAME@/src/xine-engine/.libs && \
+ echo "./configure --prefix=$PREFIX $CONFIG_OPT && make && make install-strip DESTDIR=$PKG LIBRARY_PATH=$TMPBUILD/@PACKAGE_TARNAME@/src/xine-engine/.libs" && \
+ ./configure --prefix=$PREFIX $CONFIG_OPT && make && make install-strip DESTDIR=$PKG LIBRARY_PATH=$TMPBUILD/@PACKAGE_TARNAME@/src/xine-engine/.libs && \
mkdir -p $PKG/install && cp $TMPBUILD/doinst.sh $PKG/install && \
cd $PKG && \
echo "n" | /sbin/makepkg $PACKAGE && \
@@ -172,7 +172,7 @@ main() {
build_pentium
build_k6
build_k7
- mv -f $CWD/@TAR_NAME@.tar.gz $SLCK
+ mv -f $CWD/@PACKAGE_TARNAME@.tar.gz $SLCK
}
@@ -184,7 +184,7 @@ build_arch() {
mkdir -p $SLCK
rm -f config.cache && ./autogen.sh && make dist
$barch
- mv -f $CWD/@TAR_NAME@.tar.gz $SLCK
+ mv -f $CWD/@PACKAGE_TARNAME@.tar.gz $SLCK
}
case "$1" in
diff --git a/misc/build_rpms.sh.in b/misc/build_rpms.sh.in
index b3ec065b1..c3096e5f0 100644
--- a/misc/build_rpms.sh.in
+++ b/misc/build_rpms.sh.in
@@ -44,9 +44,9 @@ export XINE_BUILD=i586-pc-linux-gnu
eval $RPM_BA
-mv /usr/src/redhat/SRPMS/libxine-@SPEC_VERSION@-$DATE.src.rpm ./rpms/
-mv /usr/src/redhat/RPMS/i386/$PKGNAME-@SPEC_VERSION@-$DATE.i386.rpm ./rpms/$PKGNAME-@SPEC_VERSION@-$DATE.i586.rpm
-mv /usr/src/redhat/RPMS/i386/$PKGNAME-devel-@SPEC_VERSION@-$DATE.i386.rpm ./rpms/$PKGNAME-devel-@SPEC_VERSION@-$DATE.i586.rpm
+mv /usr/src/redhat/SRPMS/libxine-@PACKAGE_VERSION@-$DATE.src.rpm ./rpms/
+mv /usr/src/redhat/RPMS/i386/$PKGNAME-@PACKAGE_VERSION@-$DATE.i386.rpm ./rpms/$PKGNAME-@PACKAGE_VERSION@-$DATE.i586.rpm
+mv /usr/src/redhat/RPMS/i386/$PKGNAME-devel-@PACKAGE_VERSION@-$DATE.i386.rpm ./rpms/$PKGNAME-devel-@PACKAGE_VERSION@-$DATE.i586.rpm
echo "*****************************************************"
echo
@@ -61,7 +61,7 @@ export XINE_BUILD=i686-pc-linux-gnu
eval $RPM_BB
-mv /usr/src/redhat/RPMS/i386/$PKGNAME-@SPEC_VERSION@-$DATE.i386.rpm ./rpms/$PKGNAME-@SPEC_VERSION@-$DATE.i686.rpm
+mv /usr/src/redhat/RPMS/i386/$PKGNAME-@PACKAGE_VERSION@-$DATE.i386.rpm ./rpms/$PKGNAME-@PACKAGE_VERSION@-$DATE.i686.rpm
echo "*****************************************************"
echo
@@ -76,7 +76,7 @@ export XINE_BUILD=k6-pc-linux-gnu
eval $RPM_BB
-mv /usr/src/redhat/RPMS/i386/$PKGNAME-@SPEC_VERSION@-$DATE.i386.rpm ./rpms/$PKGNAME-@SPEC_VERSION@-$DATE.k6.rpm
+mv /usr/src/redhat/RPMS/i386/$PKGNAME-@PACKAGE_VERSION@-$DATE.i386.rpm ./rpms/$PKGNAME-@PACKAGE_VERSION@-$DATE.k6.rpm
echo "*****************************************************"
echo
@@ -91,6 +91,6 @@ export XINE_BUILD=athlon-pc-linux-gnu
eval $RPM_BB
-mv /usr/src/redhat/RPMS/i386/$PKGNAME-@SPEC_VERSION@-$DATE.i386.rpm ./rpms/$PKGNAME-@SPEC_VERSION@-$DATE.k7.rpm
+mv /usr/src/redhat/RPMS/i386/$PKGNAME-@PACKAGE_VERSION@-$DATE.i386.rpm ./rpms/$PKGNAME-@PACKAGE_VERSION@-$DATE.k7.rpm
echo "Done."
diff --git a/misc/fonts/Makefile.am b/misc/fonts/Makefile.am
index ae22beefa..32664da5c 100644
--- a/misc/fonts/Makefile.am
+++ b/misc/fonts/Makefile.am
@@ -1,6 +1,6 @@
include $(top_srcdir)/misc/Makefile.common
-fontdir = $(XINE_FONTPATH)
+fontdir = $(pkgdatadir)/fonts
font_DATA = \
cetus-16.xinefont.gz \
cetus-20.xinefont.gz \
@@ -39,7 +39,9 @@ font_DATA = \
serif-48.xinefont.gz \
serif-64.xinefont.gz
+doc_DATA = README.cetus
+
#
# font used for osd
#
-EXTRA_DIST = cetus.ttf README.cetus $(font_DATA)
+EXTRA_DIST = cetus.ttf $(doc_DATA) $(font_DATA)
diff --git a/misc/relchk.sh.in b/misc/relchk.sh.in
index 242a97486..09cce24b2 100644..100755
--- a/misc/relchk.sh.in
+++ b/misc/relchk.sh.in
@@ -4,7 +4,7 @@
##
topdir="`pwd`"
-distdir="@TAR_NAME@"
+distdir="@PACKAGE_TARNAME@"
log="$topdir/dist-log"
logerror="$topdir/dist-errors"
diff --git a/misc/xine-lib.spec.in b/misc/xine-lib.spec.in
index 6382b9b9a..6c5d9b96c 100644
--- a/misc/xine-lib.spec.in
+++ b/misc/xine-lib.spec.in
@@ -1,6 +1,6 @@
%define shortname libxine
-%define name libxine1
-%define version @SPEC_VERSION@
+%define name libxine2
+%define version @PACKAGE_VERSION@
%define release 0
%define major 1
@@ -642,11 +642,11 @@ libxine Soundausgabeplugin für den jack-Soundserver
%endif
%prep
-%setup -q -n @TAR_NAME@
+%setup -q -n @PACKAGE_TARNAME@
%build
export CFLAGS="${RPM_OPT_FLAGS}"
-export XINE_DOCPATH="%{_docdir}/libxine1"
+export XINE_DOCPATH="%{_docdir}/libxine2"
if [ ! -f configure ]; then
NO_CONFIGURE=1 ./autogen.sh
@@ -682,175 +682,175 @@ make DESTDIR=%{?buildroot:%{buildroot}} LIBRARY_PATH=%{?buildroot:%{buildroot}}%
cd ${RPM_BUILD_ROOT}
-echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_zw
+echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine2_zw
%if %BUILD_DEVEL
-echo "%doc README TODO AUTHORS COPYING ChangeLog" >> ${RPM_BUILD_DIR}/filelist_libxine1_zw
+echo "%doc README TODO AUTHORS COPYING ChangeLog" >> ${RPM_BUILD_DIR}/filelist_libxine2_zw
%else
-echo "%doc README TODO AUTHORS COPYING ChangeLog doc/hackersguide/*.sgml doc/hackersguide/*.fig doc/hackersguide/README" >> ${RPM_BUILD_DIR}/filelist_libxine1_zw
+echo "%doc README TODO AUTHORS COPYING ChangeLog doc/hackersguide/*.sgml doc/hackersguide/*.fig doc/hackersguide/README" >> ${RPM_BUILD_DIR}/filelist_libxine2_zw
%endif
-find . -type f | sed 's,^\.%{_datadir}/doc,\%doc %{_datadir}/doc,' | sed 's,^\.,,' >> ${RPM_BUILD_DIR}/filelist_libxine1_zw
-find . -type l | sed 's,^\.%{_datadir}/doc,\%doc %{_datadir}/doc,' | sed 's,^\.,,' >> ${RPM_BUILD_DIR}/filelist_libxine1_zw
-find . -type d | grep xine | sed 's,^\.,\%dir ,' >> ${RPM_BUILD_DIR}/filelist_libxine1_zw
-grep -v "/man/" ${RPM_BUILD_DIR}/filelist_libxine1_zw | cat - > ${RPM_BUILD_DIR}/filelist_libxine1
-grep "/man/" ${RPM_BUILD_DIR}/filelist_libxine1_zw | sed -e 's/$/\*/g' | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1
-rm ${RPM_BUILD_DIR}/filelist_libxine1_zw
+find . -type f | sed 's,^\.%{_datadir}/doc,\%doc %{_datadir}/doc,' | sed 's,^\.,,' >> ${RPM_BUILD_DIR}/filelist_libxine2_zw
+find . -type l | sed 's,^\.%{_datadir}/doc,\%doc %{_datadir}/doc,' | sed 's,^\.,,' >> ${RPM_BUILD_DIR}/filelist_libxine2_zw
+find . -type d | grep xine | sed 's,^\.,\%dir ,' >> ${RPM_BUILD_DIR}/filelist_libxine2_zw
+grep -v "/man/" ${RPM_BUILD_DIR}/filelist_libxine2_zw | cat - > ${RPM_BUILD_DIR}/filelist_libxine2
+grep "/man/" ${RPM_BUILD_DIR}/filelist_libxine2_zw | sed -e 's/$/\*/g' | cat - >> ${RPM_BUILD_DIR}/filelist_libxine2
+rm ${RPM_BUILD_DIR}/filelist_libxine2_zw
%if %BUILD_DEVEL
-echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_devel
-echo "%doc doc/hackersguide/*.sgml doc/hackersguide/*.fig doc/hackersguide/README" >> ${RPM_BUILD_DIR}/filelist_libxine1_devel
-mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old
-grep -E "/include/|dhahelper\.o|libxine*\.(so|la)$|\.m4$" ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_devel
-grep -v -E "/include/|dhahelper\.o|libxine*\.(so|la)$|\.m4$" ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1
-rm ${RPM_BUILD_DIR}/filelist_libxine1_old
+echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine2_devel
+echo "%doc doc/hackersguide/*.sgml doc/hackersguide/*.fig doc/hackersguide/README" >> ${RPM_BUILD_DIR}/filelist_libxine2_devel
+mv ${RPM_BUILD_DIR}/filelist_libxine2 ${RPM_BUILD_DIR}/filelist_libxine2_old
+grep -E "/include/|dhahelper\.o|libxine*\.(so|la)$|\.m4$" ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine2_devel
+grep -v -E "/include/|dhahelper\.o|libxine*\.(so|la)$|\.m4$" ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine2
+rm ${RPM_BUILD_DIR}/filelist_libxine2_old
%endif
%if %BUILD_ALSA
-echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_alsa
-mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old
-grep "xineplug_ao_out_alsa\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_alsa
-grep -v "xineplug_ao_out_alsa\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1
-rm ${RPM_BUILD_DIR}/filelist_libxine1_old
+echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine2_alsa
+mv ${RPM_BUILD_DIR}/filelist_libxine2 ${RPM_BUILD_DIR}/filelist_libxine2_old
+grep "xineplug_ao_out_alsa\." ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine2_alsa
+grep -v "xineplug_ao_out_alsa\." ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine2
+rm ${RPM_BUILD_DIR}/filelist_libxine2_old
%endif
%if %BUILD_ARTS
-echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_arts
-mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old
-grep "xineplug_ao_out_arts\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_arts
-grep -v "xineplug_ao_out_arts\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1
-rm ${RPM_BUILD_DIR}/filelist_libxine1_old
+echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine2_arts
+mv ${RPM_BUILD_DIR}/filelist_libxine2 ${RPM_BUILD_DIR}/filelist_libxine2_old
+grep "xineplug_ao_out_arts\." ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine2_arts
+grep -v "xineplug_ao_out_arts\." ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine2
+rm ${RPM_BUILD_DIR}/filelist_libxine2_old
%endif
%if %BUILD_ESD
-echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_esd
-mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old
-grep "xineplug_ao_out_esd\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_esd
-grep -v "xineplug_ao_out_esd\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1
-rm ${RPM_BUILD_DIR}/filelist_libxine1_old
+echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine2_esd
+mv ${RPM_BUILD_DIR}/filelist_libxine2 ${RPM_BUILD_DIR}/filelist_libxine2_old
+grep "xineplug_ao_out_esd\." ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine2_esd
+grep -v "xineplug_ao_out_esd\." ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine2
+rm ${RPM_BUILD_DIR}/filelist_libxine2_old
%endif
%if %BUILD_DXR3
%ifarch i386 i486 i586 i686 i786 i868 i986 k6 k7 athlon x86_64 amd64 ia32e
-echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_dxr3
-mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old
-grep "dxr3" ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_dxr3
-grep -v "dxr3" ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1
-rm ${RPM_BUILD_DIR}/filelist_libxine1_old
+echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine2_dxr3
+mv ${RPM_BUILD_DIR}/filelist_libxine2 ${RPM_BUILD_DIR}/filelist_libxine2_old
+grep "dxr3" ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine2_dxr3
+grep -v "dxr3" ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine2
+rm ${RPM_BUILD_DIR}/filelist_libxine2_old
%endif
%endif
%if %BUILD_SDL
-echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_sdl
-mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old
-grep "xineplug_vo_out_sdl\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_sdl
-grep -v "xineplug_vo_out_sdl\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1
-rm ${RPM_BUILD_DIR}/filelist_libxine1_old
+echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine2_sdl
+mv ${RPM_BUILD_DIR}/filelist_libxine2 ${RPM_BUILD_DIR}/filelist_libxine2_old
+grep "xineplug_vo_out_sdl\." ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine2_sdl
+grep -v "xineplug_vo_out_sdl\." ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine2
+rm ${RPM_BUILD_DIR}/filelist_libxine2_old
%endif
%if %BUILD_AA
-echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_aa
-mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old
-grep "xineplug_vo_out_aa\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_aa
-grep -v "xineplug_vo_out_aa\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1
-rm ${RPM_BUILD_DIR}/filelist_libxine1_old
+echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine2_aa
+mv ${RPM_BUILD_DIR}/filelist_libxine2 ${RPM_BUILD_DIR}/filelist_libxine2_old
+grep "xineplug_vo_out_aa\." ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine2_aa
+grep -v "xineplug_vo_out_aa\." ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine2
+rm ${RPM_BUILD_DIR}/filelist_libxine2_old
%endif
%if %BUILD_OPENGL
-echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_opengl
-mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old
-grep -E "xineplug_vo_out_opengl\.|README.opengl" ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_opengl
-grep -v -E "xineplug_vo_out_opengl\.|README.opengl" ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1
-rm ${RPM_BUILD_DIR}/filelist_libxine1_old
+echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine2_opengl
+mv ${RPM_BUILD_DIR}/filelist_libxine2 ${RPM_BUILD_DIR}/filelist_libxine2_old
+grep -E "xineplug_vo_out_opengl\.|README.opengl" ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine2_opengl
+grep -v -E "xineplug_vo_out_opengl\.|README.opengl" ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine2
+rm ${RPM_BUILD_DIR}/filelist_libxine2_old
%endif
%if %BUILD_SYNCFB
-echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_syncfb
-mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old
-grep -E "xineplug_vo_out_syncfb\.|README\.syncfb" ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_syncfb
-grep -v -E "xineplug_vo_out_syncfb\.|README\.syncfb" ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1
-rm ${RPM_BUILD_DIR}/filelist_libxine1_old
+echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine2_syncfb
+mv ${RPM_BUILD_DIR}/filelist_libxine2 ${RPM_BUILD_DIR}/filelist_libxine2_old
+grep -E "xineplug_vo_out_syncfb\.|README\.syncfb" ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine2_syncfb
+grep -v -E "xineplug_vo_out_syncfb\.|README\.syncfb" ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine2
+rm ${RPM_BUILD_DIR}/filelist_libxine2_old
%endif
%if %BUILD_DIRECTFB
-echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_directfb
-mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old
-grep -E "xineplug_vo_out_directfb\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_directfb
-grep -v -E "xineplug_vo_out_directfb\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1
-rm ${RPM_BUILD_DIR}/filelist_libxine1_old
+echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine2_directfb
+mv ${RPM_BUILD_DIR}/filelist_libxine2 ${RPM_BUILD_DIR}/filelist_libxine2_old
+grep -E "xineplug_vo_out_directfb\." ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine2_directfb
+grep -v -E "xineplug_vo_out_directfb\." ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine2
+rm ${RPM_BUILD_DIR}/filelist_libxine2_old
%endif
%if %BUILD_STK
-echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_stk
-mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old
-grep -E "xineplug_vo_out_stk\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_stk
-grep -v -E "xineplug_vo_out_stk\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1
-rm ${RPM_BUILD_DIR}/filelist_libxine1_old
+echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine2_stk
+mv ${RPM_BUILD_DIR}/filelist_libxine2 ${RPM_BUILD_DIR}/filelist_libxine2_old
+grep -E "xineplug_vo_out_stk\." ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine2_stk
+grep -v -E "xineplug_vo_out_stk\." ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine2
+rm ${RPM_BUILD_DIR}/filelist_libxine2_old
%endif
%if %BUILD_XVMC
%ifarch i386 i486 i586 i686 i786 i868 i986 k6 k7 athlon x86_64 amd64 ia32e
-echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_xvmc
-mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old
-grep "xineplug_vo_out_x[x|v]mc\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_xvmc
-grep -v "xineplug_vo_out_x[x|v]mc\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1
-rm ${RPM_BUILD_DIR}/filelist_libxine1_old
+echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine2_xvmc
+mv ${RPM_BUILD_DIR}/filelist_libxine2 ${RPM_BUILD_DIR}/filelist_libxine2_old
+grep "xineplug_vo_out_x[x|v]mc\." ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine2_xvmc
+grep -v "xineplug_vo_out_x[x|v]mc\." ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine2
+rm ${RPM_BUILD_DIR}/filelist_libxine2_old
%endif
%endif
%if %BUILD_W32DLL
%ifarch i386 i486 i586 i686 i786 i868 i986 k6 k7 athlon
-echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_w32dll
-mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old
-grep -E "xineplug_decode_qt\.|xineplug_decode_w32dll\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_w32dll
-grep -v -E "xineplug_decode_qt\.|xineplug_decode_w32dll\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1
-rm ${RPM_BUILD_DIR}/filelist_libxine1_old
+echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine2_w32dll
+mv ${RPM_BUILD_DIR}/filelist_libxine2 ${RPM_BUILD_DIR}/filelist_libxine2_old
+grep -E "xineplug_decode_qt\.|xineplug_decode_w32dll\." ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine2_w32dll
+grep -v -E "xineplug_decode_qt\.|xineplug_decode_w32dll\." ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine2
+rm ${RPM_BUILD_DIR}/filelist_libxine2_old
%endif
%endif
%if %BUILD_DVB
-echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_dvb
-mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old
-grep -E "xineplug_inp_dvb\.|README\.dvb" ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_dvb
-grep -v -E "xineplug_inp_dvb\.|README\.dvb" ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1
-rm ${RPM_BUILD_DIR}/filelist_libxine1_old
+echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine2_dvb
+mv ${RPM_BUILD_DIR}/filelist_libxine2 ${RPM_BUILD_DIR}/filelist_libxine2_old
+grep -E "xineplug_inp_dvb\.|README\.dvb" ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine2_dvb
+grep -v -E "xineplug_inp_dvb\.|README\.dvb" ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine2
+rm ${RPM_BUILD_DIR}/filelist_libxine2_old
%endif
%if %BUILD_DVD
-echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_dvd
-mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old
-grep -E "xineplug_inp_dvd\.|README\.network_dvd" ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_dvd
-grep -v -E "xineplug_inp_dvd\.|README\.network_dvd" ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1
-rm ${RPM_BUILD_DIR}/filelist_libxine1_old
+echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine2_dvd
+mv ${RPM_BUILD_DIR}/filelist_libxine2 ${RPM_BUILD_DIR}/filelist_libxine2_old
+grep -E "xineplug_inp_dvd\.|README\.network_dvd" ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine2_dvd
+grep -v -E "xineplug_inp_dvd\.|README\.network_dvd" ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine2
+rm ${RPM_BUILD_DIR}/filelist_libxine2_old
%endif
%if %BUILD_GNOME_VFS
-echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_gnome_vfs
-mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old
-grep "xineplug_inp_gnome_vfs\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_gnome_vfs
-grep -v "xineplug_inp_gnome_vfs\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1
-rm ${RPM_BUILD_DIR}/filelist_libxine1_old
+echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine2_gnome_vfs
+mv ${RPM_BUILD_DIR}/filelist_libxine2 ${RPM_BUILD_DIR}/filelist_libxine2_old
+grep "xineplug_inp_gnome_vfs\." ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine2_gnome_vfs
+grep -v "xineplug_inp_gnome_vfs\." ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine2
+rm ${RPM_BUILD_DIR}/filelist_libxine2_old
%endif
%if %BUILD_FLAC
-echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_flac
-mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old
-grep "xineplug_flac\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_flac
-grep -v "xineplug_flac\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1
-rm ${RPM_BUILD_DIR}/filelist_libxine1_old
+echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine2_flac
+mv ${RPM_BUILD_DIR}/filelist_libxine2 ${RPM_BUILD_DIR}/filelist_libxine2_old
+grep "xineplug_flac\." ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine2_flac
+grep -v "xineplug_flac\." ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine2
+rm ${RPM_BUILD_DIR}/filelist_libxine2_old
%endif
%if %BUILD_OGG
-echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_ogg
-mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old
-grep -E "xineplug_decode_vorbis\.|xineplug_dmx_ogg\.|xineplug_decode_theora\.|xineplug_decode_speex\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_ogg
-grep -v -E "xineplug_decode_vorbis\.|xineplug_dmx_ogg\.|xineplug_decode_theora\.|xineplug_decode_speex\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1
-rm ${RPM_BUILD_DIR}/filelist_libxine1_old
+echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine2_ogg
+mv ${RPM_BUILD_DIR}/filelist_libxine2 ${RPM_BUILD_DIR}/filelist_libxine2_old
+grep -E "xineplug_decode_vorbis\.|xineplug_dmx_ogg\.|xineplug_decode_theora\.|xineplug_decode_speex\." ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine2_ogg
+grep -v -E "xineplug_decode_vorbis\.|xineplug_dmx_ogg\.|xineplug_decode_theora\.|xineplug_decode_speex\." ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine2
+rm ${RPM_BUILD_DIR}/filelist_libxine2_old
%endif
%if %BUILD_JACK
-echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_jack
-mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old
-grep "xineplug_ao_out_jack\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_jack
-grep -v "xineplug_ao_out_jack\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1
-rm ${RPM_BUILD_DIR}/filelist_libxine1_old
+echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine2_jack
+mv ${RPM_BUILD_DIR}/filelist_libxine2 ${RPM_BUILD_DIR}/filelist_libxine2_old
+grep "xineplug_ao_out_jack\." ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine2_jack
+grep -v "xineplug_ao_out_jack\." ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine2
+rm ${RPM_BUILD_DIR}/filelist_libxine2_old
%endif
@@ -860,88 +860,88 @@ rm ${RPM_BUILD_DIR}/filelist_libxine1_old
%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig
-%files -f ../filelist_libxine1
+%files -f ../filelist_libxine2
%if %BUILD_DEVEL
-%files devel -f ../filelist_libxine1_devel
+%files devel -f ../filelist_libxine2_devel
%endif
%if %BUILD_ALSA
-%files alsa -f ../filelist_libxine1_alsa
+%files alsa -f ../filelist_libxine2_alsa
%endif
%if %BUILD_ARTS
-%files arts -f ../filelist_libxine1_arts
+%files arts -f ../filelist_libxine2_arts
%endif
%if %BUILD_ESD
-%files esd -f ../filelist_libxine1_esd
+%files esd -f ../filelist_libxine2_esd
%endif
%if %BUILD_DXR3
%ifarch i386 i486 i586 i686 i786 i868 i986 k6 k7 athlon x86_64 amd64 ia32e
-%files dxr3 -f ../filelist_libxine1_dxr3
+%files dxr3 -f ../filelist_libxine2_dxr3
%endif
%endif
%if %BUILD_SDL
-%files sdl -f ../filelist_libxine1_sdl
+%files sdl -f ../filelist_libxine2_sdl
%endif
%if %BUILD_AA
-%files aa -f ../filelist_libxine1_aa
+%files aa -f ../filelist_libxine2_aa
%endif
%if %BUILD_OPENGL
-%files opengl -f ../filelist_libxine1_opengl
+%files opengl -f ../filelist_libxine2_opengl
%endif
%if %BUILD_SYNCFB
-%files syncfb -f ../filelist_libxine1_syncfb
+%files syncfb -f ../filelist_libxine2_syncfb
%endif
%if %BUILD_DIRECTFB
-%files directfb -f ../filelist_libxine1_directfb
+%files directfb -f ../filelist_libxine2_directfb
%endif
%if %BUILD_STK
-%files stk -f ../filelist_libxine1_stk
+%files stk -f ../filelist_libxine2_stk
%endif
%if %BUILD_XVMC
%ifarch i386 i486 i586 i686 i786 i868 i986 k6 k7 athlon x86_64 amd64 ia32e
-%files xvmc -f ../filelist_libxine1_xvmc
+%files xvmc -f ../filelist_libxine2_xvmc
%endif
%endif
%if %BUILD_W32DLL
%ifarch i386 i486 i586 i686 i786 i868 i986 k6 k7 athlon
-%files w32dll -f ../filelist_libxine1_w32dll
+%files w32dll -f ../filelist_libxine2_w32dll
%endif
%endif
%if %BUILD_DVB
-%files dvb -f ../filelist_libxine1_dvb
+%files dvb -f ../filelist_libxine2_dvb
%endif
%if %BUILD_DVD
-%files dvd -f ../filelist_libxine1_dvd
+%files dvd -f ../filelist_libxine2_dvd
%endif
%if %BUILD_GNOME_VFS
-%files gnome-vfs -f ../filelist_libxine1_gnome_vfs
+%files gnome-vfs -f ../filelist_libxine2_gnome_vfs
%endif
%if %BUILD_FLAC
-%files flac -f ../filelist_libxine1_flac
+%files flac -f ../filelist_libxine2_flac
%endif
%if %BUILD_OGG
-%files ogg -f ../filelist_libxine1_ogg
+%files ogg -f ../filelist_libxine2_ogg
%endif
%if %BUILD_JACK
-%files jack -f ../filelist_libxine1_jack
+%files jack -f ../filelist_libxine2_jack
%endif
%changelog
diff --git a/po/Makefile.in.in b/po/Makefile.in.in
index 2b9a10dc5..f59b1c08b 100644
--- a/po/Makefile.in.in
+++ b/po/Makefile.in.in
@@ -1,5 +1,5 @@
# Makefile for PO directory in any package using GNU gettext.
-# Copyright (C) 1995-1997, 2000-2005 by Ulrich Drepper <drepper@gnu.ai.mit.edu>
+# Copyright (C) 1995-1997, 2000-2006 by Ulrich Drepper <drepper@gnu.ai.mit.edu>
#
# This file can be copied and used freely without restrictions. It can
# be used in projects which are not available under the GNU General Public
@@ -8,7 +8,7 @@
# Please note that the actual code of GNU gettext is covered by the GNU
# General Public License and is *not* in the public domain.
#
-# Origin: gettext-0.14.4
+# Origin: gettext-0.16
include @srcdir@/Makefile.format
@@ -27,21 +27,37 @@ VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
datarootdir = @datarootdir@
-ifeq ($(datarootdir),\@datarootdir\@)
-datarootdir = @datadir@
-endif
datadir = @datadir@
-localedir = $(datadir)/locale
-gettextsrcdir = $(datarootdir)/gettext/po
+localedir = @localedir@
+gettextsrcdir = $(datadir)/gettext/po
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
-MKINSTALLDIRS = @MKINSTALLDIRS@
-mkinstalldirs = $(SHELL) $(MKINSTALLDIRS)
-GMSGFMT = @GMSGFMT@
-MSGFMT = @MSGFMT@
-XGETTEXT = @XGETTEXT@
+# We use $(mkdir_p).
+# In automake <= 1.9.x, $(mkdir_p) is defined either as "mkdir -p --" or as
+# "$(mkinstalldirs)" or as "$(install_sh) -d". For these automake versions,
+# @install_sh@ does not start with $(SHELL), so we add it.
+# In automake >= 1.10, @mkdir_p@ is derived from ${MKDIR_P}, which is defined
+# either as "/path/to/mkdir -p" or ".../install-sh -c -d". For these automake
+# versions, $(mkinstalldirs) and $(install_sh) are unused.
+mkinstalldirs = $(SHELL) @install_sh@ -d
+install_sh = $(SHELL) @install_sh@
+MKDIR_P = @MKDIR_P@
+mkdir_p = @mkdir_p@
+
+GMSGFMT_ = @GMSGFMT@
+GMSGFMT_no = @GMSGFMT@
+GMSGFMT_yes = @GMSGFMT_015@
+GMSGFMT = $(GMSGFMT_$(USE_MSGCTXT))
+MSGFMT_ = @MSGFMT@
+MSGFMT_no = @MSGFMT@
+MSGFMT_yes = @MSGFMT_015@
+MSGFMT = $(MSGFMT_$(USE_MSGCTXT))
+XGETTEXT_ = @XGETTEXT@
+XGETTEXT_no = @XGETTEXT@
+XGETTEXT_yes = @XGETTEXT_015@
+XGETTEXT = $(XGETTEXT_$(USE_MSGCTXT))
MSGMERGE = msgmerge
MSGMERGE_UPDATE = @MSGMERGE@ --update
MSGINIT = msginit
@@ -166,7 +182,7 @@ install: install-exec install-data
install-exec:
install-data: install-data-@USE_NLS@
if test "$(PACKAGE)" = "gettext-tools"; then \
- $(mkinstalldirs) $(DESTDIR)$(gettextsrcdir); \
+ $(mkdir_p) $(DESTDIR)$(gettextsrcdir); \
for file in $(DISTFILES.common) Makevars.template; do \
$(INSTALL_DATA) $(srcdir)/$$file \
$(DESTDIR)$(gettextsrcdir)/$$file; \
@@ -179,13 +195,13 @@ install-data: install-data-@USE_NLS@
fi
install-data-no: all
install-data-yes: all
- $(mkinstalldirs) $(DESTDIR)$(datadir)
+ $(mkdir_p) $(DESTDIR)$(datadir)
@catalogs='$(CATALOGS)'; \
for cat in $$catalogs; do \
cat=`basename $$cat`; \
lang=`echo $$cat | sed -e 's/\.gmo$$//'`; \
dir=$(localedir)/$$lang/LC_MESSAGES; \
- $(mkinstalldirs) $(DESTDIR)$$dir; \
+ $(mkdir_p) $(DESTDIR)$$dir; \
if test -r $$cat; then realcat=$$cat; else realcat=$(srcdir)/$$cat; fi; \
$(INSTALL_DATA) $$realcat $(DESTDIR)$$dir/$(DOMAIN).mo; \
echo "installing $$realcat as $(DESTDIR)$$dir/$(DOMAIN).mo"; \
@@ -225,19 +241,19 @@ installdirs: installdirs-exec installdirs-data
installdirs-exec:
installdirs-data: installdirs-data-@USE_NLS@
if test "$(PACKAGE)" = "gettext-tools"; then \
- $(mkinstalldirs) $(DESTDIR)$(gettextsrcdir); \
+ $(mkdir_p) $(DESTDIR)$(gettextsrcdir); \
else \
: ; \
fi
installdirs-data-no:
installdirs-data-yes:
- $(mkinstalldirs) $(DESTDIR)$(datadir)
+ $(mkdir_p) $(DESTDIR)$(datadir)
@catalogs='$(CATALOGS)'; \
for cat in $$catalogs; do \
cat=`basename $$cat`; \
lang=`echo $$cat | sed -e 's/\.gmo$$//'`; \
dir=$(localedir)/$$lang/LC_MESSAGES; \
- $(mkinstalldirs) $(DESTDIR)$$dir; \
+ $(mkdir_p) $(DESTDIR)$$dir; \
for lc in '' $(EXTRA_LOCALE_CATEGORIES); do \
if test -n "$$lc"; then \
if (cd $(DESTDIR)$(localedir)/$$lang && LC_ALL=C ls -l -d $$lc 2>/dev/null) | grep ' -> ' >/dev/null; then \
@@ -382,11 +398,7 @@ update-gmo: Makefile $(GMOFILES)
Makefile: Makefile.in.in Makevars $(top_builddir)/config.status @POMAKEFILEDEPS@
cd $(top_builddir) \
- && CONFIG_FILES=$(subdir)/$@.in CONFIG_HEADERS= \
- $(SHELL) ./config.status
-
-debug:
-install-debug:
+ && $(SHELL) ./config.status $(subdir)/$@.in po-directories
force:
diff --git a/po/Makefile.in.in.diff b/po/Makefile.in.in.diff
new file mode 100644
index 000000000..583640149
--- /dev/null
+++ b/po/Makefile.in.in.diff
@@ -0,0 +1,30 @@
+--- /usr/share/gettext/po/Makefile.in.in 2006-11-27 23:24:08.000000000 +0000
++++ ./po/Makefile.in.in 2007-05-17 14:31:43.000000000 +0100
+@@ -10,7 +10,10 @@
+ #
+ # Origin: gettext-0.16
+
++include @srcdir@/Makefile.format
++
+ PACKAGE = @PACKAGE@
++LIBNAME = @LIBNAME@
+ VERSION = @VERSION@
+ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+
+@@ -65,7 +68,7 @@
+ GMOFILES = @GMOFILES@
+ UPDATEPOFILES = @UPDATEPOFILES@
+ DUMMYPOFILES = @DUMMYPOFILES@
+-DISTFILES.common = Makefile.in.in remove-potcdate.sin \
++DISTFILES.common = Makefile.in.in remove-potcdate.sin Makefile.format \
+ $(DISTFILES.common.extra1) $(DISTFILES.common.extra2) $(DISTFILES.common.extra3)
+ DISTFILES = $(DISTFILES.common) Makevars POTFILES.in \
+ $(POFILES) $(GMOFILES) \
+@@ -136,6 +139,7 @@
+ msgid_bugs_address='$(PACKAGE_BUGREPORT)'; \
+ fi; \
+ $(XGETTEXT) --default-domain=$(DOMAIN) --directory=$(top_srcdir) \
++ $(XGETTEXT_FORMAT_FLAGS) $(XGETTEXT_FORMAT_FLAGS_PRIVATE) \
+ --add-comments=TRANSLATORS: $(XGETTEXT_OPTIONS) \
+ --files-from=$(srcdir)/POTFILES.in \
+ --copyright-holder='$(COPYRIGHT_HOLDER)' \
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 2fb531266..d56ea9160 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -62,15 +62,15 @@ src/input/vcd/vcdplayer.c
src/input/vcd/vcdplayer.h
src/input/vcd/xineplug_inp_vcd.c
src/liba52/xine_a52_decoder.c
-src/libdts/xine_dts_decoder.c
+src/libxineadec/xine_dts_decoder.c
src/libfaad/xine_faad_decoder.c
src/libffmpeg/ff_audio_decoder.c
src/libffmpeg/ff_dvaudio_decoder.c
src/libffmpeg/ff_video_decoder.c
src/libffmpeg/ffmpeg_encoder.c
-src/libmusepack/requant.c
-src/libmusepack/synth_filter.c
-src/libmusepack/xine_musepack_decoder.c
+contrib/libmpcdec/requant.c
+contrib/libmpcdec/synth_filter.c
+src/libxineadec/xine_musepack_decoder.c
src/libreal/real_common.c
src/libreal/xine_real_video_decoder.c
src/libreal/xine_real_audio_decoder.c
diff --git a/po/cs.po b/po/cs.po
index b5150c889..69af8bba6 100644
--- a/po/cs.po
+++ b/po/cs.po
@@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: xine-lib 1.0.1\n"
"Report-Msgid-Bugs-To: xine-devel@lists.sourceforge.net\n"
-"POT-Creation-Date: 2007-04-06 15:39+0200\n"
+"POT-Creation-Date: 2007-04-24 21:48+0100\n"
"PO-Revision-Date: 2005-12-11 20:47+0100\n"
"Last-Translator: František Dvořák <valtri@atlas.cz>\n"
"Language-Team: Czech <cs@li.org>\n"
@@ -46,22 +46,22 @@ msgstr "Zjišťování jména selhalo"
msgid "Unknown error"
msgstr "neznámá chyba"
-#: src/audio_out/audio_alsa_out.c:354
+#: src/audio_out/audio_alsa_out.c:351
#, c-format
msgid "audio_alsa_out:Already open...WHY!"
msgstr "audio_alsa_out: Již otevřeno...PROČ!"
-#: src/audio_out/audio_alsa_out.c:382
+#: src/audio_out/audio_alsa_out.c:379
#, c-format
msgid "audio_alsa_out: snd_pcm_open() of %s failed: %s\n"
msgstr "audio_alsa_out: snd_pcm_open() na %s selhalo: %s\n"
-#: src/audio_out/audio_alsa_out.c:384
+#: src/audio_out/audio_alsa_out.c:381
msgid "audio_alsa_out: >>> check if another program already uses PCM <<<\n"
msgstr ""
"audio_alsa_out: >>> zkontrolujte, jestli už jiný program nepoužívá PCM <<<\n"
-#: src/audio_out/audio_alsa_out.c:397
+#: src/audio_out/audio_alsa_out.c:394
#, c-format
msgid ""
"audio_alsa_out: broken configuration for this PCM: no configurations "
@@ -70,11 +70,11 @@ msgstr ""
"audio_alsa_out: přerušena konfigurace tohoto PCM: žádná konfigurace není k "
"dispozici: %s\n"
-#: src/audio_out/audio_alsa_out.c:1289
+#: src/audio_out/audio_alsa_out.c:1286
msgid "notify changes to the hardware mixer"
msgstr "uvědomit o změnách hardwarový mixer"
-#: src/audio_out/audio_alsa_out.c:1290
+#: src/audio_out/audio_alsa_out.c:1287
msgid ""
"When the hardware mixer changes, your application will receive a "
"notification so that it can update its graphical representation of the mixer "
@@ -83,16 +83,16 @@ msgstr ""
"Když se změní hardwarový mixer, vaše aplikace obdrží upozornění, a tak může "
"za běhu aktualizovat svoji grafickou reprezentaci nastavení mixeru."
-#: src/audio_out/audio_alsa_out.c:1355
+#: src/audio_out/audio_alsa_out.c:1352
#, c-format
msgid "snd_lib_error_set_handler() failed: %d"
msgstr "snd_lib_error_set_handler() selhalo: %d"
-#: src/audio_out/audio_alsa_out.c:1362
+#: src/audio_out/audio_alsa_out.c:1359
msgid "sound card can do mmap"
msgstr "zvuková karta umožňuje provádět mmap"
-#: src/audio_out/audio_alsa_out.c:1363
+#: src/audio_out/audio_alsa_out.c:1360
msgid ""
"Enable this, if your sound card and alsa driver support memory mapped IO.\n"
"You can try enabling it and check, if everything works. If it does, this "
@@ -103,11 +103,11 @@ msgstr ""
"Můžete to zkusit povolit a zkontrolovat, zda vše funguje. Pokud ano, zlepší "
"toto nastavení výkon."
-#: src/audio_out/audio_alsa_out.c:1372
+#: src/audio_out/audio_alsa_out.c:1369
msgid "device used for mono output"
msgstr "zařízení použité pro mono výstup"
-#: src/audio_out/audio_alsa_out.c:1373
+#: src/audio_out/audio_alsa_out.c:1370
msgid ""
"xine will use this alsa device to output mono sound.\n"
"See the alsa documentation for information on alsa devices."
@@ -115,11 +115,11 @@ msgstr ""
"xine použije toto zařízení ALSA pro výstup zvuku mono.\n"
"Informace o zařízeních ALSA naleznete v dokumentaci k ALSA."
-#: src/audio_out/audio_alsa_out.c:1381
+#: src/audio_out/audio_alsa_out.c:1378
msgid "device used for stereo output"
msgstr "zařízení použité pro stereo výstup"
-#: src/audio_out/audio_alsa_out.c:1382
+#: src/audio_out/audio_alsa_out.c:1379
msgid ""
"xine will use this alsa device to output stereo sound.\n"
"See the alsa documentation for information on alsa devices."
@@ -127,11 +127,11 @@ msgstr ""
"xine použije toto zařízení ALSA pro výstup zvuku stereo.\n"
"Informace o zařízeních ALSA naleznete v dokumentaci k ALSA."
-#: src/audio_out/audio_alsa_out.c:1390
+#: src/audio_out/audio_alsa_out.c:1387
msgid "device used for 4-channel output"
msgstr "zařízení použité pro ÄtyÅ™kanálový výstup"
-#: src/audio_out/audio_alsa_out.c:1391
+#: src/audio_out/audio_alsa_out.c:1388
msgid ""
"xine will use this alsa device to output 4 channel (4.0) surround sound.\n"
"See the alsa documentation for information on alsa devices."
@@ -139,11 +139,11 @@ msgstr ""
"xine použije toto zařízení ALSA pro výstup surround zvuku 4kanálově (4.0).\n"
"Informace o zařízeních ALSA naleznete v dokumentaci k ALSA."
-#: src/audio_out/audio_alsa_out.c:1400 src/audio_out/audio_alsa_out.c:1410
+#: src/audio_out/audio_alsa_out.c:1397 src/audio_out/audio_alsa_out.c:1407
msgid "device used for 5.1-channel output"
msgstr "zařízení použité pro 5.1-kanálový výstup"
-#: src/audio_out/audio_alsa_out.c:1401
+#: src/audio_out/audio_alsa_out.c:1398
msgid ""
"xine will use this alsa device to output 5 channel plus LFE (5.1) surround "
"sound.\n"
@@ -153,7 +153,7 @@ msgstr ""
"(5.1).\n"
"Informace o zařízeních ALSA naleznete v dokumentaci k ALSA."
-#: src/audio_out/audio_alsa_out.c:1411
+#: src/audio_out/audio_alsa_out.c:1408
msgid ""
"xine will use this alsa device to output undecoded digital surround sound. "
"This can be used be external surround decoders.\n"
@@ -163,21 +163,21 @@ msgstr ""
"Může to být použito vnějšími surround dekodéry.\n"
"Informace o zařízeních ALSA naleznete v dokumentaci k ALSA."
-#: src/audio_out/audio_alsa_out.c:1431
+#: src/audio_out/audio_alsa_out.c:1428
#, c-format
msgid "snd_pcm_open() failed:%d:%s\n"
msgstr "snd_cm_open() selhalo:%d:%s\n"
-#: src/audio_out/audio_alsa_out.c:1433
+#: src/audio_out/audio_alsa_out.c:1430
#, c-format
msgid ">>> Check if another program already uses PCM <<<\n"
msgstr ">>> Zkontrolujte, jestli už jiný program nepoužívá PCM <<<\n"
-#: src/audio_out/audio_alsa_out.c:1464 src/audio_out/audio_oss_out.c:929
+#: src/audio_out/audio_alsa_out.c:1461 src/audio_out/audio_oss_out.c:929
msgid "speaker arrangement"
msgstr "uspořádání reproduktorů"
-#: src/audio_out/audio_alsa_out.c:1465 src/audio_out/audio_oss_out.c:930
+#: src/audio_out/audio_alsa_out.c:1462 src/audio_out/audio_oss_out.c:930
msgid ""
"Select how your speakers are arranged, this determines which speakers xine "
"uses for sound output. The individual values are:\n"
@@ -236,79 +236,79 @@ msgstr ""
"Na digitální výstup vaší zvukové karty potřebujete připojit digitální "
"surround dekodér schopný dekódovat formáty, které chcete přehrát."
-#: src/audio_out/audio_alsa_out.c:1494
+#: src/audio_out/audio_alsa_out.c:1491
msgid "audio_alsa_out : supported modes are "
msgstr "audio_alsa_out : podporované režimy jsou "
-#: src/audio_out/audio_alsa_out.c:1497
+#: src/audio_out/audio_alsa_out.c:1494
msgid "8bit "
msgstr "8bitový"
-#: src/audio_out/audio_alsa_out.c:1502
+#: src/audio_out/audio_alsa_out.c:1499
msgid "16bit "
msgstr "16bitový"
-#: src/audio_out/audio_alsa_out.c:1506
+#: src/audio_out/audio_alsa_out.c:1503
msgid "24bit "
msgstr "24bitový"
-#: src/audio_out/audio_alsa_out.c:1510
+#: src/audio_out/audio_alsa_out.c:1507
msgid "32bit "
msgstr "32bitový"
-#: src/audio_out/audio_alsa_out.c:1521
+#: src/audio_out/audio_alsa_out.c:1518
msgid "mono "
msgstr "mono"
-#: src/audio_out/audio_alsa_out.c:1525
+#: src/audio_out/audio_alsa_out.c:1522
msgid "stereo "
msgstr "stereo"
-#: src/audio_out/audio_alsa_out.c:1530
+#: src/audio_out/audio_alsa_out.c:1527
msgid "4-channel "
msgstr "4kanálový"
-#: src/audio_out/audio_alsa_out.c:1533
+#: src/audio_out/audio_alsa_out.c:1530
msgid "(4-channel not enabled in xine config) "
msgstr "(4kanálový není povolen v konfiguraci xine)"
-#: src/audio_out/audio_alsa_out.c:1538
+#: src/audio_out/audio_alsa_out.c:1535
msgid "4.1-channel "
msgstr "4.1kanálový"
-#: src/audio_out/audio_alsa_out.c:1541
+#: src/audio_out/audio_alsa_out.c:1538
msgid "(4.1-channel not enabled in xine config) "
msgstr "(4.1kanálový není povolen v konfiguraci xine)"
-#: src/audio_out/audio_alsa_out.c:1546
+#: src/audio_out/audio_alsa_out.c:1543
msgid "5-channel "
msgstr "5kanálový"
-#: src/audio_out/audio_alsa_out.c:1549
+#: src/audio_out/audio_alsa_out.c:1546
msgid "(5-channel not enabled in xine config) "
msgstr "(5kanálový není povolen v kondifuraci xine)"
-#: src/audio_out/audio_alsa_out.c:1554
+#: src/audio_out/audio_alsa_out.c:1551
msgid "5.1-channel "
msgstr "5.1kanálový"
-#: src/audio_out/audio_alsa_out.c:1557
+#: src/audio_out/audio_alsa_out.c:1554
msgid "(5.1-channel not enabled in xine config) "
msgstr "(5.1kanálový není povolen v konfiguraci xine)"
-#: src/audio_out/audio_alsa_out.c:1580
+#: src/audio_out/audio_alsa_out.c:1577
msgid "a/52 and DTS pass-through\n"
msgstr "a/52 a DTS pass-through\n"
-#: src/audio_out/audio_alsa_out.c:1583
+#: src/audio_out/audio_alsa_out.c:1580
msgid "(a/52 and DTS pass-through not enabled in xine config)\n"
msgstr "(a/52 a DTS pass-through nejsou povoleny v konfiguraci xine)\n"
-#: src/audio_out/audio_alsa_out.c:1590
+#: src/audio_out/audio_alsa_out.c:1587
msgid "alsa mixer device"
msgstr "mixovací zařízení alsa"
-#: src/audio_out/audio_alsa_out.c:1591
+#: src/audio_out/audio_alsa_out.c:1588
msgid ""
"xine will use this alsa mixer device to change the volume.\n"
"See the alsa documentation for information on alsa devices."
@@ -316,7 +316,7 @@ msgstr ""
"ke změně hlasitosti použije xine toto zařízení mixeru ALSA.\n"
"Informace o zařízeních ALSA nalzeznete v dokumentaci k ALSA."
-#: src/audio_out/audio_alsa_out.c:1665
+#: src/audio_out/audio_alsa_out.c:1662
msgid "xine audio output plugin using alsa-compliant audio devices/drivers"
msgstr "výstupní zvukový modul xine použije zvuková zařízení/ovladaÄe alsa"
@@ -328,201 +328,201 @@ msgstr "modul zvukového výstupu xine použije artsd"
msgid "xine output plugin for Coreaudio/Mac OS X"
msgstr "modul zvukového výstupu xine pro Coreaudio/Mac OS X"
-#: src/audio_out/audio_directx2_out.c:166
+#: src/audio_out/audio_directx2_out.c:163
msgid "Error"
msgstr "Chyba"
-#: src/audio_out/audio_directx2_out.c:173
+#: src/audio_out/audio_directx2_out.c:170
msgid "success"
msgstr "úspěch"
-#: src/audio_out/audio_directx2_out.c:175
+#: src/audio_out/audio_directx2_out.c:172
msgid "access denied"
msgstr "přístup odepřen"
-#: src/audio_out/audio_directx2_out.c:177
+#: src/audio_out/audio_directx2_out.c:174
msgid "resource is already in use"
msgstr "zdroj je již používán"
-#: src/audio_out/audio_directx2_out.c:178
+#: src/audio_out/audio_directx2_out.c:175
msgid "object was already initialized"
msgstr "objekt již byl inicializován"
-#: src/audio_out/audio_directx2_out.c:179
+#: src/audio_out/audio_directx2_out.c:176
msgid "specified wave format is not supported"
msgstr "uvedený wave formát není podporován"
-#: src/audio_out/audio_directx2_out.c:180
+#: src/audio_out/audio_directx2_out.c:177
msgid "memory buffer has been lost and must be restored"
msgstr "paměťový buffer byl ztracen a musí být obnoven"
-#: src/audio_out/audio_directx2_out.c:181
+#: src/audio_out/audio_directx2_out.c:178
msgid "requested buffer control is not available"
msgstr "požadované řízení bufferu není k dispozici"
-#: src/audio_out/audio_directx2_out.c:182
+#: src/audio_out/audio_directx2_out.c:179
msgid "undetermined error inside DirectSound subsystem"
msgstr "neurÄená chyba uvnitÅ™ sybsystéme DirectSound"
-#: src/audio_out/audio_directx2_out.c:184
+#: src/audio_out/audio_directx2_out.c:181
msgid "DirectSound hardware device is unavailable"
msgstr "hardwarové zařízení DirectSound není k dispozici"
-#: src/audio_out/audio_directx2_out.c:186
+#: src/audio_out/audio_directx2_out.c:183
msgid "function is not valid for the current state of the object"
msgstr "pro stávající stav objektu není funkce platná"
-#: src/audio_out/audio_directx2_out.c:187
+#: src/audio_out/audio_directx2_out.c:184
msgid "invalid parameter was passed"
msgstr "byl předán neplatný parametr"
-#: src/audio_out/audio_directx2_out.c:188
+#: src/audio_out/audio_directx2_out.c:185
msgid "object doesn't support aggregation"
msgstr "objekt nepodporuje agregaci"
-#: src/audio_out/audio_directx2_out.c:189
+#: src/audio_out/audio_directx2_out.c:186
msgid "no sound driver available for use"
msgstr "není k dispozici žádný zvukový ovladaÄ k použití"
-#: src/audio_out/audio_directx2_out.c:190
+#: src/audio_out/audio_directx2_out.c:187
msgid "requested COM interface not available"
msgstr "požadované COM rozhraní není k dispozici"
-#: src/audio_out/audio_directx2_out.c:191
+#: src/audio_out/audio_directx2_out.c:188
msgid "another application has a higher priority level"
msgstr "jiná aplikace má vyšší úroveň priority"
-#: src/audio_out/audio_directx2_out.c:192
+#: src/audio_out/audio_directx2_out.c:189
msgid "insufficient memory"
msgstr "nedostatek paměti"
-#: src/audio_out/audio_directx2_out.c:193
+#: src/audio_out/audio_directx2_out.c:190
msgid "low priority level for this function"
msgstr "pro tuto funkci nízká úroveň priority"
-#: src/audio_out/audio_directx2_out.c:194
+#: src/audio_out/audio_directx2_out.c:191
msgid "DirectSound wasn't initialized"
msgstr "DirectSound nebyl inicializován"
-#: src/audio_out/audio_directx2_out.c:195
+#: src/audio_out/audio_directx2_out.c:192
msgid "function is not supported"
msgstr "funkce není podporována"
-#: src/audio_out/audio_directx2_out.c:196
+#: src/audio_out/audio_directx2_out.c:193
msgid "unknown error"
msgstr "neznámá chyba"
-#: src/audio_out/audio_directx2_out.c:206
+#: src/audio_out/audio_directx2_out.c:203
#, c-format
msgid "Unable to create direct sound object."
msgstr "Nepodařilo se vytvořit objekt direct sound."
-#: src/audio_out/audio_directx2_out.c:212
+#: src/audio_out/audio_directx2_out.c:209
#, c-format
msgid "Could not set direct sound cooperative level."
msgstr "Nelze nastavit cooperativní úroveň direct sound."
-#: src/audio_out/audio_directx2_out.c:286
+#: src/audio_out/audio_directx2_out.c:283
msgid "Unable to create secondary direct sound buffer"
msgstr "Nepodařilo se vytvořit sekundární buffer direct sound"
-#: src/audio_out/audio_directx2_out.c:310
+#: src/audio_out/audio_directx2_out.c:307
#, c-format
msgid "Unable to create buffer position events."
msgstr "NepodaÅ™ilo se vytvoÅ™it poziÄní události bufferu."
-#: src/audio_out/audio_directx2_out.c:318
+#: src/audio_out/audio_directx2_out.c:315
msgid "Unable to get notification interface"
msgstr "Nepodařilo se získat rozhraní na upozorňování (notification interface)"
-#: src/audio_out/audio_directx2_out.c:323
+#: src/audio_out/audio_directx2_out.c:320
msgid "Unable to set notification positions"
msgstr "Nepodařilo se nastavit pozice upozorňování"
-#: src/audio_out/audio_directx2_out.c:343
+#: src/audio_out/audio_directx2_out.c:340
msgid "Couldn't play sound buffer"
msgstr "Nelze přehrát zvukový buffer"
-#: src/audio_out/audio_directx2_out.c:355
+#: src/audio_out/audio_directx2_out.c:352
msgid "Couldn't stop sound buffer"
msgstr "Nelze zastavit zvukový buffer"
-#: src/audio_out/audio_directx2_out.c:368
+#: src/audio_out/audio_directx2_out.c:365
msgid "Can't get buffer position"
msgstr "Nelze získat pozici bufferu"
-#: src/audio_out/audio_directx2_out.c:382
+#: src/audio_out/audio_directx2_out.c:379
msgid "Can't set buffer position"
msgstr "Nelze nastavit pozici bufferu"
-#: src/audio_out/audio_directx2_out.c:414
+#: src/audio_out/audio_directx2_out.c:411
msgid "Can't set sound volume"
msgstr "Nelze nastavit hlasitost zvuku"
-#: src/audio_out/audio_directx2_out.c:432
+#: src/audio_out/audio_directx2_out.c:429
#, c-format
msgid ": buffer lost, tryig to restore\n"
msgstr ": buffer ztracen, zkusí se obnovit\n"
-#: src/audio_out/audio_directx2_out.c:436
+#: src/audio_out/audio_directx2_out.c:433
msgid "Couldn't lock direct sound buffer"
msgstr "Nešlo zamknou buffer direct sound"
-#: src/audio_out/audio_directx2_out.c:447
+#: src/audio_out/audio_directx2_out.c:444
msgid "Couldn't unlock direct sound buffer"
msgstr "Nešlo odemknout buffer direct sound"
-#: src/audio_out/audio_directx2_out.c:544
+#: src/audio_out/audio_directx2_out.c:541
#, c-format
msgid "Unable to create primary direct sound buffer."
msgstr "Nepodařilo se vytvořit primární buffer direct sound."
-#: src/audio_out/audio_directx2_out.c:637
+#: src/audio_out/audio_directx2_out.c:634
#, c-format
msgid ": play cursor overran, flushing buffers\n"
msgstr ": kurzor přehrávání přeběhl, resetování bufferů\n"
-#: src/audio_out/audio_directx2_out.c:655
+#: src/audio_out/audio_directx2_out.c:652
#, c-format
msgid ": delayed by %ld msec\n"
msgstr ": zpožděno o %ld ms\n"
-#: src/audio_out/audio_directx2_out.c:759
+#: src/audio_out/audio_directx2_out.c:756
#, c-format
msgid ": can't create pthread condition: %s\n"
msgstr ": nelze vytvořit pthread condition: %s\n"
-#: src/audio_out/audio_directx2_out.c:763
+#: src/audio_out/audio_directx2_out.c:760
#, c-format
msgid ": can't create pthread mutex: %s\n"
msgstr ": nelze vytvořit pthread mutex: %s\n"
-#: src/audio_out/audio_directx2_out.c:770
+#: src/audio_out/audio_directx2_out.c:767
#, c-format
msgid ": can't create buffer pthread: %s\n"
msgstr ": nelze vytvořit vlákno bufferu: %s\n"
-#: src/audio_out/audio_directx2_out.c:877
+#: src/audio_out/audio_directx2_out.c:874
#, c-format
msgid ": can't destroy buffer pthread: %s\n"
msgstr ": nelze zlikvidovat vlákno bufferu: %s\n"
-#: src/audio_out/audio_directx2_out.c:884
+#: src/audio_out/audio_directx2_out.c:881
#, c-format
msgid ": can't destroy pthread condition: %s\n"
msgstr ": nelze zlikvidovat pthread condition: %s\n"
-#: src/audio_out/audio_directx2_out.c:887
+#: src/audio_out/audio_directx2_out.c:884
#, c-format
msgid ": can't destroy pthread mutex: %s\n"
msgstr ": nelze zlikvidovat pthread mutex: %s\n"
-#: src/audio_out/audio_directx2_out.c:947
+#: src/audio_out/audio_directx2_out.c:944
#, c-format
msgid ": unknown control command %d\n"
msgstr ": neznámý řídicí příkaz: %d\n"
-#: src/audio_out/audio_directx2_out.c:1003
+#: src/audio_out/audio_directx2_out.c:1000
msgid "second xine audio output plugin using directx"
msgstr "druhý modul zvukového výstupu xine používající DirectX"
@@ -999,7 +999,7 @@ msgstr "demux_snd: Å¡patné parametry hlaviÄky\n"
msgid "demux_snd: unsupported audio type: %d\n"
msgstr "demux_snd: nepodporovaný typ zvuku: %d\n"
-#: src/demuxers/demux_tta.c:88
+#: src/demuxers/demux_tta.c:86
msgid "demux_tta: total frames count too high\n"
msgstr ""
@@ -1020,7 +1020,7 @@ msgid "demux_wc3movie: SHOT chunk referenced invalid palette (%d >= %d)\n"
msgstr ""
"demux_wc3movie: datový blok SHOT odkazoval na neplatnou paletu (%d >= %d)\n"
-#: src/demuxers/demux_wc3movie.c:406
+#: src/demuxers/demux_wc3movie.c:404
#, c-format
msgid "demux_wc3movie: There was a problem while loading palette chunks\n"
msgstr "demux_wc3movie: Byl zde problém bÄ›hem naÄítání datových bloků palety\n"
@@ -1488,30 +1488,30 @@ msgstr ""
"video_out_dxr3: CHYBA Ätení souboru inicializace pÅ™ekrývání. SpusÅ¥te "
"autocal!\n"
-#: src/input/input_cdda.c:1621
+#: src/input/input_cdda.c:1608
#, c-format
msgid "%s: can't connect to %s:%d\n"
msgstr "%s: http: nelze se připojit k %s:%d\n"
-#: src/input/input_cdda.c:1668
+#: src/input/input_cdda.c:1655
#, c-format
msgid "input_cdda: successfuly connected to cddb server '%s:%d'.\n"
msgstr "input_cdda: úspěšně připojeno k CDDB serveru '%s:%d'.\n"
-#: src/input/input_cdda.c:1673
+#: src/input/input_cdda.c:1660
#, c-format
msgid "input_cdda: failed to connect to cddb server '%s:%d' (%s).\n"
msgstr "input_cdda: nelze se připojit k CDDB serveru '%s:%d' (%s).\n"
-#: src/input/input_cdda.c:2707
+#: src/input/input_cdda.c:2690
msgid "CD Digital Audio (aka. CDDA)"
msgstr "digitální zvukové CD (CDDA)"
-#: src/input/input_cdda.c:2760
+#: src/input/input_cdda.c:2742
msgid "device used for CD audio"
msgstr "zařízení použité pro zvukové CD"
-#: src/input/input_cdda.c:2761
+#: src/input/input_cdda.c:2743
msgid ""
"The path to the device, usually a CD or DVD drive, which you intend to use "
"for playing audio CDs."
@@ -1519,11 +1519,11 @@ msgstr ""
"Cesta k zeřízení, obvykle CD nebo DVD mechanika, které máte v úmyslu "
"používat k přehrávání zvukových CD."
-#: src/input/input_cdda.c:2767
+#: src/input/input_cdda.c:2749
msgid "query CDDB"
msgstr "dotazovat se CDDB"
-#: src/input/input_cdda.c:2767
+#: src/input/input_cdda.c:2749
msgid ""
"Enables CDDB queries, which will give you convenient title and track names "
"for your audio CDs.\n"
@@ -1537,11 +1537,11 @@ msgstr ""
"internetového serveru, který by pak mohl znát profil vašich poslechových "
"zvyků."
-#: src/input/input_cdda.c:2775
+#: src/input/input_cdda.c:2757
msgid "CDDB server name"
msgstr "jméno serveru CDDB"
-#: src/input/input_cdda.c:2775
+#: src/input/input_cdda.c:2757
msgid ""
"The CDDB server used to retrieve the title and track information from.\n"
"This setting is security critical, because the sever will receive "
@@ -1554,37 +1554,21 @@ msgstr ""
"posílány informace o vašich poslechovích zvycích a také mohl by odpovídat na "
"dotazy zákeÅ™nými odpovÄ›Ämi. UjistÄ›te se, že serveru můžete důvěřovat."
-#: src/input/input_cdda.c:2783
+#: src/input/input_cdda.c:2765
msgid "CDDB server port"
msgstr "port serveru CDDB"
-#: src/input/input_cdda.c:2783
+#: src/input/input_cdda.c:2765
msgid "The server port used to retrieve the title and track information from."
msgstr ""
"Port serveru, který se použije, aby se z něj získávaly nadpisy a informace o "
"stopÄ›."
-#: src/input/input_cdda.c:2789
-msgid "CDDB cache directory"
-msgstr "adresář se záznamy CDDB"
-
-#: src/input/input_cdda.c:2789
-msgid ""
-"The replies from the CDDB server will be cached in this directory.\n"
-"This setting is security critical, because files with uncontrollable names "
-"will be created in this directory. Be sure to use a dedicated directory not "
-"used for anything but CDDB caching."
-msgstr ""
-"Odpovědi z CDDB serveru budou uchovávány v tomto adresáři.\n"
-"Toto nastavení je kritické s ohledem na bezpeÄnost, protože mohou být v "
-"tomto adresáři vytvářeny soubory s nekontrolovatelnými jmény. Ujistěte se, "
-"že daný adresář není používán pro nic jiného než cachování CDDB."
-
-#: src/input/input_cdda.c:2797
+#: src/input/input_cdda.c:2771
msgid "slow down disc drive to this speed factor"
msgstr "zpomalit diskovou jednotku na tento rychlostní faktor"
-#: src/input/input_cdda.c:2798
+#: src/input/input_cdda.c:2772
msgid ""
"Since some CD or DVD drives make some really loud noises because of the fast "
"disc rotation, xine will try to slow them down. With standard CD or DVD "
@@ -1598,56 +1582,61 @@ msgstr ""
"potřebné, a tak by nemělo zpomalení ovlivnit výkon přehrávání.\n"
"Hodnota nula zde zakáže zpomalování."
-#: src/input/input_dvb.c:881
-#, c-format
-msgid "input_dvb: failed to open dvb channel file '%s'\n"
+#: src/input/input_dvb.c:899
+#, fuzzy, c-format
+msgid "input_dvb: failed to open dvb channel file '%s': %s\n"
msgstr "input_dvb: selhalo otevření souboru kanálu dvb '%s'\n"
-#: src/input/input_dvb.c:2082 src/input/input_dvb.c:2910
+#: src/input/input_dvb.c:905
+#, fuzzy, c-format
+msgid "input_dvb: dvb channel file '%s' is not a plain file\n"
+msgstr "input_dvb: selhalo otevření souboru kanálu dvb '%s'\n"
+
+#: src/input/input_dvb.c:2115 src/input/input_dvb.c:2943
msgid "input_dvb: tuner_set_channel failed\n"
msgstr "input_dvb: selhalo nastavení kanálu\n"
-#: src/input/input_dvb.c:2710
+#: src/input/input_dvb.c:2743
msgid "input_dvb: cannot open dvb device\n"
msgstr "input_dvb: nelze otevřít zařízení dvb\n"
-#: src/input/input_dvb.c:2734
+#: src/input/input_dvb.c:2767
#, c-format
msgid "input_dvb: channel %d out of range, defaulting to 0\n"
msgstr "input_dvb: kanál %d mimo rozsah, použije se výchozí 0\n"
-#: src/input/input_dvb.c:2745
+#: src/input/input_dvb.c:2778
#, c-format
msgid "input_dvb: searching for channel %s\n"
msgstr "input_dvb: hledání kanálu %s\n"
-#: src/input/input_dvb.c:2768
+#: src/input/input_dvb.c:2801
#, c-format
msgid "input_dvb: exact match for %s not found: trying partial matches\n"
msgstr "input_dvb: pÅ™esná shoda pro %s nenalezena: zkusí se ÄásteÄné shody\n"
-#: src/input/input_dvb.c:2775
+#: src/input/input_dvb.c:2808
#, c-format
msgid "input_dvb: found matching channel %s\n"
msgstr "input_dvb: nalezen odpovídající kanál %s\n"
-#: src/input/input_dvb.c:2788
+#: src/input/input_dvb.c:2821
#, c-format
msgid "input_dvb: channel %s not found in channels.conf, defaulting.\n"
msgstr "input_dvb: kanál %s nenalezen v channels.conf, použije se výchozí.\n"
-#: src/input/input_dvb.c:2794
+#: src/input/input_dvb.c:2827
msgid ""
"input_dvb: invalid channel specification, defaulting to last viewed "
"channel.\n"
msgstr ""
"input_dvb: neplatná specifikace kanálu, použije se naposledy sledovaný\n"
-#: src/input/input_dvb.c:2800
+#: src/input/input_dvb.c:2833
msgid "input_dvb: invalid channel specification, defaulting to channel 0\n"
msgstr "input_dvb: neplatná specifikace kanálu, použije se výchozí kanál 0\n"
-#: src/input/input_dvb.c:2812
+#: src/input/input_dvb.c:2845
msgid ""
"input_dvb: dvbs mrl specified but the tuner doesn't appear to be QPSK (DVB-"
"S)\n"
@@ -1655,7 +1644,7 @@ msgstr ""
"input_dvb: bylo uvedeno MRL DVBS, ale nezdá se, že by tuner byl QPSK (DVB-"
"S)\n"
-#: src/input/input_dvb.c:2832
+#: src/input/input_dvb.c:2865
msgid ""
"input_dvb: dvbt mrl specified but the tuner doesn't appear to be OFDM (DVB-"
"T)\n"
@@ -1663,27 +1652,27 @@ msgstr ""
"input_dvb: bylo uvedeno MRL DVBT, ale nezdá se, že by byl tuner OFDM (DVB-"
"T)\n"
-#: src/input/input_dvb.c:2855 src/input/input_dvb.c:2881
+#: src/input/input_dvb.c:2888 src/input/input_dvb.c:2914
msgid ""
"input_dvb: dvbc mrl specified but the tuner doesn't appear to be QAM (DVB-"
"C)\n"
msgstr ""
"input_dvb: bylo uvedeno MRL DVBC, ale nezdá se, že by byl tuner QAM (DVB-C)\n"
-#: src/input/input_dvb.c:2916
+#: src/input/input_dvb.c:2949
#, c-format
msgid "input_dvb: cannot open dvr device '%s'\n"
msgstr "input_dvb: nelze otevřít zařízení dvr '%s'\n"
-#: src/input/input_dvb.c:2938
+#: src/input/input_dvb.c:2971
msgid "input_dvb: cannot create EPG updater thread\n"
msgstr "input_dvb: nelze vytvořit vlákno na aktualizace EPG\n"
-#: src/input/input_dvb.c:3000
+#: src/input/input_dvb.c:3033
msgid "use DVB 'center cutout' (zoom)"
msgstr "použít 'středový výsek' DVB (zvětšení)"
-#: src/input/input_dvb.c:3001
+#: src/input/input_dvb.c:3034
msgid ""
"This will allow fullscreen playback of 4:3 content transmitted in a 16:9 "
"frame."
@@ -1691,15 +1680,15 @@ msgstr ""
"Toto dovolí přehrát obsah 4:3 na celé obrazovce, který byl přenášen ve "
"formátu 16:9."
-#: src/input/input_dvb.c:3094
+#: src/input/input_dvb.c:3127
msgid "DVB (Digital TV) input plugin"
msgstr "vstupní modul DVB (digitální TV)"
-#: src/input/input_dvb.c:3242
+#: src/input/input_dvb.c:3244
msgid "Remember last DVB channel watched"
msgstr "Pamatovat si naposledy sledovaný kanál DVB"
-#: src/input/input_dvb.c:3243
+#: src/input/input_dvb.c:3245
msgid ""
"On autoplay, xine will remember and switch to the channel indicated in media."
"dvb.last_channel. "
@@ -1707,21 +1696,21 @@ msgstr ""
"Při automatickém přehrávání xine přepne na poslední kanál uvedený v media."
"dvb.last_channel."
-#: src/input/input_dvb.c:3250
+#: src/input/input_dvb.c:3252
msgid "Last DVB channel viewed"
msgstr "Naposledy sledovaný kanál DVB"
-#: src/input/input_dvb.c:3251
+#: src/input/input_dvb.c:3253
msgid "If enabled xine will remember and switch to this channel. "
msgstr ""
"Pokud je povoleno, xine si bude pamatovat tento kanál a bude se na něj "
"automaticky přepínat."
-#: src/input/input_dvb.c:3257
+#: src/input/input_dvb.c:3259
msgid "Number of dvb card to use."
msgstr "PoÄet karet DVB, které se mají použít."
-#: src/input/input_dvb.c:3258
+#: src/input/input_dvb.c:3260
msgid ""
"Leave this at zero unless you really have more than 1 card in your system."
msgstr ""
@@ -1755,11 +1744,11 @@ msgstr ""
"Cesta k zařízení, obvykle DVD mechanice, které chcete používat pro "
"přehrávání DVD."
-#: src/input/input_dvd.c:1800
+#: src/input/input_dvd.c:1799
msgid "raw device set up for DVD access"
msgstr "cesta k raw zařízení nastavenému pro přístup k DVD"
-#: src/input/input_dvd.c:1801
+#: src/input/input_dvd.c:1800
msgid ""
"If this points to a raw device connected to your DVD device, xine will use "
"the raw device for playback. This has the advantage of being slightly faster "
@@ -1777,11 +1766,11 @@ msgstr ""
"použita pouze jednou.\n"
"Další informace viz. dokumentace o raw zařízeních (man raw)."
-#: src/input/input_dvd.c:1814
+#: src/input/input_dvd.c:1813
msgid "CSS decryption method"
msgstr "metoda dešifrování CSS"
-#: src/input/input_dvd.c:1815
+#: src/input/input_dvd.c:1814
msgid ""
"Selects the decryption method libdvdcss will use to descramble copy "
"protected DVDs. Try the various methods, if you have problems playing "
@@ -1791,29 +1780,11 @@ msgstr ""
"chráněních proti kopírování. Pokud máte problémy s přehráváním zakódovaných "
"DVD, vyzkoušejte různé metody."
-#: src/input/input_dvd.c:1823
-msgid "path to the title key cache"
-msgstr "cesta ke cache klíÄů titulů"
-
-#: src/input/input_dvd.c:1824
-msgid ""
-"Since cracking the copy protection of scrambled DVDs can be quite time "
-"consuming, libdvdcss will cache the cracked keys in this directory.\n"
-"This setting is security critical, because files with uncontrollable names "
-"will be created in this directory. Be sure to use a dedicated directory not "
-"used for anything but DVD key caching."
-msgstr ""
-"Protože crackování ochrany kopírování zaÅ¡ifrovaných DVD může být ÄasovÄ› "
-"celkem nároÄné, libdvdcss bude v tomto adresáři cachovat cracklé klíÄe.\n"
-"Toto nastavení je kritické s ohledem na bezpeÄnost, protože mohou být v "
-"tomto adresáři vytvářeny soubory s nekontrolovatelnými jmény. Ujistěte se, "
-"že daný adresář není kromÄ› cachování DVD klíÄů používán na nic jiného."
-
-#: src/input/input_dvd.c:1846
+#: src/input/input_dvd.c:1829
msgid "region the DVD player claims to be in (1 to 8)"
msgstr "DVD pÅ™ehrávaÄ tvrdí, že je v oblasti (1 až 8)"
-#: src/input/input_dvd.c:1847
+#: src/input/input_dvd.c:1830
msgid ""
"This only needs to be changed if your DVD jumps to a screen complaining "
"about a wrong region code. It has nothing to do with the region code set in "
@@ -1823,11 +1794,11 @@ msgstr ""
"na špatný kód oblasti. Nemá to nic dělat s kódem oblasti nastaveným v DVD "
"mechanikách, je to ÄistÄ› softwarové."
-#: src/input/input_dvd.c:1853
+#: src/input/input_dvd.c:1836
msgid "default language for DVD playback"
msgstr "výchozí jazyk pro přehrávání DVD"
-#: src/input/input_dvd.c:1854
+#: src/input/input_dvd.c:1837
msgid ""
"xine tries to use this language as a default for DVD playback. As far as the "
"DVD supports it, menus and audio tracks will be presented in this language.\n"
@@ -1837,11 +1808,11 @@ msgstr ""
"bude podporovat, volby a zvukové stopy budou prezentovány v tomto jazyce.\n"
"Hodnotou musí být dva znaky jazykového kódu ISO639."
-#: src/input/input_dvd.c:1860
+#: src/input/input_dvd.c:1843
msgid "read-ahead caching"
msgstr "read-ahead cachování"
-#: src/input/input_dvd.c:1861
+#: src/input/input_dvd.c:1844
msgid ""
"xine can use a read ahead cache for DVD drive access.\n"
"This may lead to jerky playback on slow drives, but it improves the impact "
@@ -1851,11 +1822,11 @@ msgstr ""
"To může vést na pomalých mechanikách ke škubavému přehrávání, ale na "
"rychlejších mechanikách to zlepší výsledek změny vrstvy DVD."
-#: src/input/input_dvd.c:1867
+#: src/input/input_dvd.c:1850
msgid "unit for the skip action"
msgstr "jednotka pro akci skoku"
-#: src/input/input_dvd.c:1868
+#: src/input/input_dvd.c:1851
msgid ""
"You can configure the behaviour when issuing a skip command (using the skip "
"buttons for example). The individual values mean:\n"
@@ -1887,11 +1858,11 @@ msgstr ""
"skip title\n"
"pÅ™eskoÄí DVD titul, což je stavební jednotka reprezentující celé DVD"
-#: src/input/input_dvd.c:1883
+#: src/input/input_dvd.c:1866
msgid "unit for seeking"
msgstr "jednotka pro nastavení pozice"
-#: src/input/input_dvd.c:1884
+#: src/input/input_dvd.c:1867
msgid ""
"You can configure the domain spanned by the seek slider. The individual "
"values mean:\n"
@@ -1915,11 +1886,11 @@ msgstr ""
"nastavování pozice se týká programu DVD, což je navigaÄní jednotka "
"reprezentující kapitolu souÄasného dÄ›jství"
-#: src/input/input_dvd.c:1895
+#: src/input/input_dvd.c:1878
msgid "play mode when title/chapter is given"
msgstr "režim přehrávání, když je zadán titul nebo kapitola"
-#: src/input/input_dvd.c:1896
+#: src/input/input_dvd.c:1879
msgid ""
"You can configure the behaviour when playing a dvd from a given title/"
"chapter (eg. using MRL 'dvd:/1.2'). The individual values mean:\n"
@@ -2668,7 +2639,7 @@ msgstr ""
"1024: nehybný snímek\n"
"2048: debugování z VCDINFO\n"
-#: src/liba52/xine_a52_decoder.c:742 src/libdts/xine_dts_decoder.c:546
+#: src/liba52/xine_a52_decoder.c:742 src/libxineadec/xine_dts_decoder.c:524
msgid "HELP! a mono-only audio driver?!\n"
msgstr "POMÓC! Zvukový ovladaÄ pouze mono?!\n"
@@ -2729,61 +2700,61 @@ msgstr "libfaad: selhala funkce NeAACDecInit2.\n"
msgid "libfaad: libfaad NeAACDecInit failed.\n"
msgstr "libfaad: selhala funkce NeAACDecInit.\n"
-#: src/libffmpeg/ff_audio_decoder.c:120
+#: src/libffmpeg/ff_audio_decoder.c:122
#, c-format
msgid "ffmpeg_audio_dec: increasing buffer to %d to avoid overflow.\n"
msgstr "ffmpeg_audio_dec: zvÄ›tÅ¡ení bufferu na %d, aby se pÅ™edeÅ¡lo pÅ™eteÄení.\n"
-#: src/libffmpeg/ff_audio_decoder.c:164
+#: src/libffmpeg/ff_audio_decoder.c:166
#, c-format
msgid "ffmpeg_audio_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"
msgstr "ffmpeg_audio_dec: nelze nalézt dekodér ffmpeg pro buffer typu 0x%X\n"
-#: src/libffmpeg/ff_audio_decoder.c:256
+#: src/libffmpeg/ff_audio_decoder.c:258
#, fuzzy
msgid "ffmpeg_audio_dec: trying to open null codec\n"
msgstr "ffmpeg_audio_dec: nelze otevřít dekodér\n"
-#: src/libffmpeg/ff_audio_decoder.c:265
+#: src/libffmpeg/ff_audio_decoder.c:267
msgid "ffmpeg_audio_dec: couldn't open decoder\n"
msgstr "ffmpeg_audio_dec: nelze otevřít dekodér\n"
-#: src/libffmpeg/ff_dvaudio_decoder.c:286
+#: src/libffmpeg/ff_dvaudio_decoder.c:280
#, c-format
msgid "dvaudio: increasing buffer to %d to avoid overflow.\n"
msgstr "dvaudio: zvÄ›tÅ¡ení bufferu na %d, aby se pÅ™edeÅ¡lo pÅ™eteÄení.\n"
-#: src/libffmpeg/ff_video_decoder.c:157
+#: src/libffmpeg/ff_video_decoder.c:155
msgid "ffmpeg_video_dec: unsupported frame format, DR1 disabled.\n"
msgstr "ffmpeg_video_dec: nepodporovaný formát, DR1 zakázáno.\n"
-#: src/libffmpeg/ff_video_decoder.c:175
+#: src/libffmpeg/ff_video_decoder.c:173
msgid "ffmpeg_video_dec: unsupported frame dimensions, DR1 disabled.\n"
msgstr "ffmpeg_video_dec: nepodporované rozměry snímku, DR1 zakázáno.\n"
-#: src/libffmpeg/ff_video_decoder.c:335
+#: src/libffmpeg/ff_video_decoder.c:333
#, c-format
msgid "ffmpeg_video_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"
msgstr "ffmpeg_video_dec: nelze nalézt dekodér ffmpeg pro buffer typu 0x%X\n"
-#: src/libffmpeg/ff_video_decoder.c:364
+#: src/libffmpeg/ff_video_decoder.c:362
msgid "ffmpeg_video_dec: couldn't open decoder\n"
msgstr "ffmpeg_video_dec: nelze otevřít dekodér\n"
-#: src/libffmpeg/ff_video_decoder.c:399
+#: src/libffmpeg/ff_video_decoder.c:397
msgid "ffmpeg_video_dec: direct rendering enabled\n"
msgstr "ffmpeg_video_dec: přímé renderování povoleno\n"
-#: src/libffmpeg/ff_video_decoder.c:818
+#: src/libffmpeg/ff_video_decoder.c:816
#, c-format
msgid "ffmpeg_video_dec: increasing buffer to %d to avoid overflow.\n"
msgstr "ffmpeg_video_dec: zvÄ›tÅ¡ení bufferu na %d, aby se pÅ™edeÅ¡lo pÅ™eteÄení.\n"
-#: src/libffmpeg/ff_video_decoder.c:1516
+#: src/libffmpeg/ff_video_decoder.c:1514
msgid "MPEG-4 postprocessing quality"
msgstr "kvalita dodateÄného zpracování MPEG-4"
-#: src/libffmpeg/ff_video_decoder.c:1517
+#: src/libffmpeg/ff_video_decoder.c:1515
msgid ""
"You can adjust the amount of post processing applied to MPEG-4 video.\n"
"Higher values result in better quality, but need more CPU. Lower values may "
@@ -2798,11 +2769,11 @@ msgstr ""
"Pro vysokou kvalitu videa může příliÅ¡ silné dodateÄné zpracování způsobit "
"horší obraz tím, že ho více rozmaže."
-#: src/libffmpeg/ffmpeg_encoder.c:167
+#: src/libffmpeg/ffmpeg_encoder.c:163
msgid "libavcodec mpeg output bitrate (kbit/s)"
msgstr "výstupní rychlost libavcodec mpeg (kbit/s)"
-#: src/libffmpeg/ffmpeg_encoder.c:168
+#: src/libffmpeg/ffmpeg_encoder.c:164
msgid ""
"The bitrate the libavcodec mpeg encoder should use for DXR3's encoding mode. "
"Higher values will increase quality and CPU usage.\n"
@@ -2812,11 +2783,11 @@ msgstr ""
"v režimu kódování DXR3. Vyšší hodnoty zvýší využití procesoru a kvalitu.\n"
"Toto nastavení je uvažováno pouze, když je zakázán režim konstantní kvality."
-#: src/libffmpeg/ffmpeg_encoder.c:175
+#: src/libffmpeg/ffmpeg_encoder.c:171
msgid "constant quality mode"
msgstr "režim konstantní kvality"
-#: src/libffmpeg/ffmpeg_encoder.c:176
+#: src/libffmpeg/ffmpeg_encoder.c:172
msgid ""
"When enabled, libavcodec will use a constant quality mode by dynamically "
"compressing the images based on their complexity. When disabled, libavcodec "
@@ -2826,39 +2797,39 @@ msgstr ""
"kompresí obrázků na základě jejich složitosti. Když bude zakázáno, "
"libavcodec použije režim konstantní bitové rychlosti."
-#: src/libffmpeg/ffmpeg_encoder.c:183
+#: src/libffmpeg/ffmpeg_encoder.c:179
msgid "minimum compression"
msgstr "minimálné komprese"
-#: src/libffmpeg/ffmpeg_encoder.c:184
+#: src/libffmpeg/ffmpeg_encoder.c:180
msgid "The minimum compression to apply to an image in constant quality mode."
msgstr ""
"Minimální komprese, která se použije na obraz v režimu konstatní kvality."
-#: src/libffmpeg/ffmpeg_encoder.c:189
+#: src/libffmpeg/ffmpeg_encoder.c:185
msgid "maximum quantizer"
msgstr "Maximální kvantizér"
-#: src/libffmpeg/ffmpeg_encoder.c:190
+#: src/libffmpeg/ffmpeg_encoder.c:186
msgid "The maximum compression to apply to an image in constant quality mode."
msgstr ""
"Maximální komprese, která se použije na obraz v režimu konstantní kvality."
-#: src/libmusepack/xine_musepack_decoder.c:241
+#: src/libxineadec/xine_musepack_decoder.c:249
#, c-format
msgid "libmusepack: mpc_streaminfo_read failed: %d\n"
msgstr "libmusepack: mpc_streaminfo_read selhalo: %d\n"
-#: src/libmusepack/xine_musepack_decoder.c:315
+#: src/libxineadec/xine_musepack_decoder.c:323
msgid "libmusepack: data after last frame ignored\n"
msgstr "libmusepack: data po posledním snímku ignorována\n"
-#: src/libmusepack/xine_musepack_decoder.c:326
+#: src/libxineadec/xine_musepack_decoder.c:334
msgid "libmusepack: mpc_decoder_initialise failed\n"
msgstr "libmusepack: selhalo mpc_decoder_initialise\n"
-#: src/libmusepack/xine_musepack_decoder.c:346
-#: src/libmusepack/xine_musepack_decoder.c:361
+#: src/libxineadec/xine_musepack_decoder.c:354
+#: src/libxineadec/xine_musepack_decoder.c:369
#, c-format
msgid "libmusepack: mpc_decoder_decode failed: %d\n"
msgstr "libmusepack: selhalo mpc_decoder_decode: %d\n"
@@ -3783,7 +3754,7 @@ msgid "Select the video output layer by its id."
msgstr "Vybere vrstvu výstupu videa podle jeho ID."
#: src/video_out/video_out_directfb.c:1804
-#: src/video_out/video_out_directfb.c:2013
+#: src/video_out/video_out_directfb.c:2014
#, fuzzy, c-format
msgid "video_out_directfb: using display layer #%d.\n"
msgstr "video_out_directfb: žádná použitelná vrstva overlay nebyla nalezena!\n"
@@ -3792,12 +3763,12 @@ msgstr "video_out_directfb: žádná použitelná vrstva overlay nebyla nalezena
msgid "xine video output plugin using DirectFB."
msgstr "výstupní modul videa xine použije DirectFB."
-#: src/video_out/video_out_directfb.c:2006
+#: src/video_out/video_out_directfb.c:2007
#, fuzzy
msgid "video_out_directfb: no usable display layer was found!\n"
msgstr "video_out_directfb: žádná použitelná vrstva overlay nebyla nalezena!\n"
-#: src/video_out/video_out_directfb.c:2095
+#: src/video_out/video_out_directfb.c:2096
msgid "xine video output plugin using DirectFB under XDirectFB."
msgstr "výstupní modul videa xine použije DirectFB pod XDirectFB."
@@ -3805,7 +3776,7 @@ msgstr "výstupní modul videa xine použije DirectFB pod XDirectFB."
msgid "xine video output plugin for win32 using directx"
msgstr "výstupní modul videa xine pro win32 používající directx"
-#: src/video_out/video_out_fb.c:792
+#: src/video_out/video_out_fb.c:780
#, c-format
msgid ""
"video_out_fb: only packed truecolor/directcolor is supported (%d).\n"
@@ -3815,11 +3786,11 @@ msgstr ""
"d).\n"
" Zkontrolujte 'fbset -i' nebo zkuste 'fbset -depth 16'.\n"
-#: src/video_out/video_out_fb.c:852 src/video_out/video_out_vidix.c:1239
+#: src/video_out/video_out_fb.c:840 src/video_out/video_out_vidix.c:1239
msgid "framebuffer device name"
msgstr "jméno zařízení framebufferu"
-#: src/video_out/video_out_fb.c:853 src/video_out/video_out_vidix.c:1240
+#: src/video_out/video_out_fb.c:841 src/video_out/video_out_vidix.c:1240
msgid ""
"Specifies the file name for the framebuffer device to be used.\n"
"This setting is security critical, because when changed to a different file, "
@@ -3832,20 +3803,20 @@ msgstr ""
"obsahem. A tak by jste si měli být jistí, že hodnota, kterou zadáváte, "
"skuteÄnÄ› je náležité zařízení framebufferu."
-#: src/video_out/video_out_fb.c:927
-msgid "video_out_fb: Your video mode was not recognized, sorry.\n"
+#: src/video_out/video_out_fb.c:915
+#, fuzzy, c-format
+msgid "%s: Your video mode was not recognized, sorry.\n"
msgstr "video_out_fb: Váš videorežim nebyl rozpoznán, bohužel.\n"
-#: src/video_out/video_out_fb.c:984
-#, c-format
-msgid "video_out_fb: %d video RAM buffers are available.\n"
+#: src/video_out/video_out_fb.c:972
+#, fuzzy, c-format
+msgid "%s: %d video RAM buffers are available.\n"
msgstr "video_out_fb: je k dispozici %d video RAM bufferů.\n"
-#: src/video_out/video_out_fb.c:990
-#, c-format
+#: src/video_out/video_out_fb.c:978
+#, fuzzy, c-format
msgid ""
-"WARNING: video_out_fb: Zero copy buffers are DISABLED because only %d "
-"buffers\n"
+"WARNING: %s: Zero copy buffers are DISABLED because only %d buffers\n"
" are available which is less than the recommended %d buffers. Lowering\n"
" the frame buffer resolution might help.\n"
msgstr ""
@@ -3854,27 +3825,30 @@ msgstr ""
" pouze %d bufferů, což je ménÄ› než doporuÄovaných %d bufferů.\n"
" Mohlo by pomoci snížení rozlišení bufferu.\n"
-#: src/video_out/video_out_fb.c:1001
+#: src/video_out/video_out_fb.c:989
+#, fuzzy, c-format
msgid ""
-"WARNING: video_out_fb: Zero copy buffers are DISABLED because kernel driver\n"
+"WARNING: %s: Zero copy buffers are DISABLED because kernel driver\n"
" do not support screen panning (used for frame flips).\n"
msgstr ""
"VAROVÃNÃ: video_out_fb: Buffery s nulami jsou ZAKÃZÃNY, protože ovladaÄ "
"jádra\n"
" nepodporuje \"screen panning\" (použito pro přepínání snímků).\n"
-#: src/video_out/video_out_fb.c:1070
-#, c-format
+#: src/video_out/video_out_fb.c:1058
+#, fuzzy, c-format
msgid ""
-"WARNING: video_out_fb: current display depth is %d. For better performance\n"
+"WARNING: %s: current display depth is %d. For better performance\n"
" a depth of 16 bpp is recommended!\n"
"\n"
msgstr ""
-"VAROVÃNÃ: video_out_fb: souÄasná hloubka displeje je %d. Pro lepší výkon\n"
-" je doporuÄována hloubka 16 bitů/bod!\n"
+"\n"
+"\n"
+"VAROVÃNÃ: hloubka souÄasného displeje je %d. Pro lepší výkon\n"
+"je doporuÄována hloubka 16 bitů/bod!\n"
"\n"
-#: src/video_out/video_out_fb.c:1101
+#: src/video_out/video_out_fb.c:1090
msgid "Xine video output plugin using the Linux frame buffer device"
msgstr "výstupní modul videa xine použije zařízení framebuffer"
@@ -3951,8 +3925,8 @@ msgstr ""
"Ignorováno u statických renderovacích podprogramů.\n"
#: src/video_out/video_out_opengl.c:1918 src/video_out/video_out_vidix.c:1015
-#: src/video_out/video_out_xcbxv.c:1472 src/video_out/video_out_xv.c:1486
-#: src/video_out/video_out_xvmc.c:1461 src/video_out/video_out_xxmc.c:2468
+#: src/video_out/video_out_xcbxv.c:1476 src/video_out/video_out_xv.c:1489
+#: src/video_out/video_out_xvmc.c:1461 src/video_out/video_out_xxmc.c:2465
msgid "enable double buffering"
msgstr "povolit dvojité bufferování"
@@ -4038,9 +4012,9 @@ msgstr ""
msgid "video_out_pgx64: Error: ioctl failed (FBIOGATTR)\n"
msgstr "video_out_pgx64: Chyba: selhalo ioctl (FBIOGATTR)\n"
-#: src/video_out/video_out_pgx64.c:1464 src/video_out/video_out_xcbxv.c:1439
-#: src/video_out/video_out_xv.c:1453 src/video_out/video_out_xvmc.c:1446
-#: src/video_out/video_out_xxmc.c:2435
+#: src/video_out/video_out_pgx64.c:1464 src/video_out/video_out_xcbxv.c:1443
+#: src/video_out/video_out_xv.c:1456 src/video_out/video_out_xvmc.c:1446
+#: src/video_out/video_out_xxmc.c:2432
msgid "video overlay colour key"
msgstr "hodnota klíÄové barvy pÅ™ekrývání"
@@ -4215,9 +4189,9 @@ msgstr "intenzita modré"
msgid "The intensity of the blue colour components."
msgstr "Intenzita modré barevné složky."
-#: src/video_out/video_out_vidix.c:1016 src/video_out/video_out_xcbxv.c:1473
-#: src/video_out/video_out_xv.c:1487 src/video_out/video_out_xvmc.c:1462
-#: src/video_out/video_out_xxmc.c:2469
+#: src/video_out/video_out_vidix.c:1016 src/video_out/video_out_xcbxv.c:1477
+#: src/video_out/video_out_xv.c:1490 src/video_out/video_out_xvmc.c:1462
+#: src/video_out/video_out_xxmc.c:2466
msgid ""
"Double buffering will synchronize the update of the video image to the "
"repainting of the entire screen (\"vertical retrace\"). This eliminates "
@@ -4253,9 +4227,9 @@ msgid "video overlay colour key red component"
msgstr "klíÄová barva pÅ™ekrývání videa Äervené složky"
#: src/video_out/video_out_vidix.c:1159 src/video_out/video_out_vidix.c:1166
-#: src/video_out/video_out_vidix.c:1173 src/video_out/video_out_xcbxv.c:1440
-#: src/video_out/video_out_xv.c:1454 src/video_out/video_out_xvmc.c:1447
-#: src/video_out/video_out_xxmc.c:2436
+#: src/video_out/video_out_vidix.c:1173 src/video_out/video_out_xcbxv.c:1444
+#: src/video_out/video_out_xv.c:1457 src/video_out/video_out_xvmc.c:1447
+#: src/video_out/video_out_xxmc.c:2433
msgid ""
"The colour key is used to tell the graphics card where to overlay the video "
"image. Try different values, if you experience windows becoming transparent."
@@ -4280,35 +4254,40 @@ msgstr "výstupní modul videa xine použije libvidix pro X11"
msgid "xine video output plugin using libvidix for linux frame buffer"
msgstr "výstupní modul videa xine použije libvidix pro linux frame buffer"
-#: src/video_out/video_out_xcbshm.c:157
-#, fuzzy, c-format
-msgid ""
-"video_out_xcbshm: %s: allocating image\n"
-"video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbshm.c:157 src/video_out/video_out_xshm.c:219
+#, c-format
+msgid "%s: %s: allocating image\n"
msgstr ""
-"video_out_xshm: %s: alokování obrázku\n"
-"video_out_xshm: => rozšíření MIT Shared Memory se nepoužije.\n"
-#: src/video_out/video_out_xcbshm.c:166
-#, fuzzy
-msgid ""
-"video_out_xcbshm: shared memory error (address error) when allocating "
-"image \n"
-"video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbshm.c:159 src/video_out/video_out_xcbshm.c:169
+#: src/video_out/video_out_xcbshm.c:181 src/video_out/video_out_xcbxv.c:272
+#: src/video_out/video_out_xcbxv.c:282 src/video_out/video_out_xcbxv.c:292
+#: src/video_out/video_out_xcbxv.c:304 src/video_out/video_out_xshm.c:204
+#: src/video_out/video_out_xshm.c:221 src/video_out/video_out_xshm.c:232
+#: src/video_out/video_out_xshm.c:251 src/video_out/video_out_xv.c:296
+#: src/video_out/video_out_xv.c:307 src/video_out/video_out_xv.c:316
+#: src/video_out/video_out_xv.c:352 src/video_out/video_out_xxmc.c:648
+#: src/video_out/video_out_xxmc.c:659 src/video_out/video_out_xxmc.c:668
+#: src/video_out/video_out_xxmc.c:704
+#, fuzzy, c-format
+msgid "%s: => not using MIT Shared Memory extension.\n"
+msgstr "výstupní modul videa xine použije rozšíření MIT X shared memory"
+
+#: src/video_out/video_out_xcbshm.c:167 src/video_out/video_out_xshm.c:230
+#, fuzzy, c-format
+msgid "%s: shared memory error (address error) when allocating image \n"
msgstr ""
"video_out_xshm: chyba sdílené paměti (chyba adresy) během alokování obrázku\n"
"video_out_xshm: => rozšíření MIT Shared Memory se nepoužije.\n"
-#: src/video_out/video_out_xcbshm.c:177
-#, fuzzy
-msgid ""
-"video_out_xcbshm: x11 error during shared memory XImage creation\n"
-"video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbshm.c:179 src/video_out/video_out_xcbxv.c:302
+#: src/video_out/video_out_xshm.c:249 src/video_out/video_out_xv.c:350
+#: src/video_out/video_out_xxmc.c:702
+#, c-format
+msgid "%s: x11 error during shared memory XImage creation\n"
msgstr ""
-"video_out_xshm: chyba x11 během vytváření XImage ve sdílené paměti\n"
-"video_out_xshm: => rozšíření MIT Shared Memory se nepoužije.\n"
-#: src/video_out/video_out_xcbshm.c:1100 src/video_out/video_out_xshm.c:1157
+#: src/video_out/video_out_xcbshm.c:1103 src/video_out/video_out_xshm.c:1161
#, c-format
msgid ""
"\n"
@@ -4323,92 +4302,82 @@ msgstr ""
"je doporuÄována hloubka 16 bitů/bod!\n"
"\n"
-#: src/video_out/video_out_xcbshm.c:1113
-#, fuzzy
-msgid "video_out_xcbshm: MIT shared memory extension not present on display.\n"
+#: src/video_out/video_out_xcbshm.c:1116 src/video_out/video_out_xshm.c:1174
+#, fuzzy, c-format
+msgid "%s: MIT shared memory extension not present on display.\n"
msgstr ""
"video_out_xshm: Rozšíření MIT shared memory není na displeji přítomno.\n"
-#: src/video_out/video_out_xcbshm.c:1212
-#, fuzzy
-msgid "video_out_xcbshm: your video mode was not recognized, sorry :-(\n"
-msgstr "video_out_xshm: váš videorežim nebyl rozpoznán, bohužel :-(\n"
+#: src/video_out/video_out_xcbshm.c:1215 src/video_out/video_out_xshm.c:1258
+#, fuzzy, c-format
+msgid "%s: your video mode was not recognized, sorry :-(\n"
+msgstr "video_out_fb: Váš videorežim nebyl rozpoznán, bohužel.\n"
-#: src/video_out/video_out_xcbshm.c:1242 src/video_out/video_out_xshm.c:1303
+#: src/video_out/video_out_xcbshm.c:1245 src/video_out/video_out_xshm.c:1307
msgid "xine video output plugin using the MIT X shared memory extension"
msgstr "výstupní modul videa xine použije rozšíření MIT X shared memory"
-#: src/video_out/video_out_xcbxv.c:272
-#, fuzzy
-msgid ""
-"video_out_xcbxv: XvShmCreateImage returned a zero size\n"
-"video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbxv.c:270 src/video_out/video_out_xv.c:305
+#: src/video_out/video_out_xxmc.c:657
+#, c-format
+msgid "%s: XvShmCreateImage returned a zero size\n"
msgstr ""
-"video_out_xv: funkce XvShmCreateImage vrátila nulovou velikost\n"
-"video_out_xv: => rozšíření MIT Shared Memory se nepoužije.\n"
-#: src/video_out/video_out_xcbxv.c:281
-#, fuzzy, c-format
-msgid ""
-"video_out_xcbxv: shared memory error in shmget: %s\n"
-"video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbxv.c:280 src/video_out/video_out_xv.c:314
+#: src/video_out/video_out_xxmc.c:666
+#, c-format
+msgid "%s: shared memory error in shmget: %s\n"
msgstr ""
-"video_out_xv: chyba sdílené paměti v shmget: %s\n"
-"video_out_xv: => rozšíření MIT Shared Memory se nepoužije.\n"
-#: src/video_out/video_out_xcbxv.c:300
-#, fuzzy
-msgid ""
-"video_out_xcbxv: x11 error during shared memory XImage creation\n"
-"video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbxv.c:290
+#, c-format
+msgid "%s: shared memory error (address error)\n"
msgstr ""
-"video_out_xv: chyba x11 během vytváření XImage\n"
-"video_out_xv: => rozšíření MIT Shared Memory se nepoužije.\n"
-#: src/video_out/video_out_xcbxv.c:1291
-#, fuzzy
-msgid "video_out_xcbxv: Xv extension not present.\n"
+#: src/video_out/video_out_xcbxv.c:1294 src/video_out/video_out_xv.c:1301
+#: src/video_out/video_out_xxmc.c:2283
+#, fuzzy, c-format
+msgid "%s: Xv extension not present.\n"
msgstr "video_out_xv: Rozšíření Xv není přítomno.\n"
-#: src/video_out/video_out_xcbxv.c:1333
-#, fuzzy
+#: src/video_out/video_out_xcbxv.c:1336 src/video_out/video_out_xv.c:1338
+#: src/video_out/video_out_xxmc.c:2320
+#, fuzzy, c-format
msgid ""
-"video_out_xcbxv: Xv extension is present but I couldn't find a usable yuv12 "
-"port.\n"
-" Looks like your graphics hardware driver doesn't support "
-"Xv?!\n"
+"%s: Xv extension is present but I couldn't find a usable yuv12 port.\n"
+"\tLooks like your graphics hardware driver doesn't support Xv?!\n"
msgstr ""
"video_out_xv: Rozšíření Xv je přítomno, ale nepodařilo se nalézt použitelný "
"port yuv12.\n"
" Vypadá to, jako by váš grafický hardwarový ovladaÄ "
"nepodporoval Xv?!\n"
-#: src/video_out/video_out_xcbxv.c:1341
+#: src/video_out/video_out_xcbxv.c:1345
#, fuzzy, c-format
msgid ""
-"video_out_xcbxv: using Xv port %d from adaptor %s for hardware colorspace "
-"conversion and scaling.\n"
+"%s: using Xv port %d from adaptor %s for hardware colorspace conversion and "
+"scaling.\n"
msgstr ""
"video_out_xv: pro hardwarovou konverzi barevného prostoru a škálování se "
"použije Xv port %ld z adaptéru %s.\n"
-#: src/video_out/video_out_xcbxv.c:1448 src/video_out/video_out_xv.c:1462
-#: src/video_out/video_out_xvmc.c:1455 src/video_out/video_out_xxmc.c:2444
+#: src/video_out/video_out_xcbxv.c:1452 src/video_out/video_out_xv.c:1465
+#: src/video_out/video_out_xvmc.c:1455 src/video_out/video_out_xxmc.c:2441
msgid "autopaint colour key"
msgstr "klíÄová barva pro automatické vykreslování"
-#: src/video_out/video_out_xcbxv.c:1449 src/video_out/video_out_xv.c:1463
-#: src/video_out/video_out_xvmc.c:1456 src/video_out/video_out_xxmc.c:2445
+#: src/video_out/video_out_xcbxv.c:1453 src/video_out/video_out_xv.c:1466
+#: src/video_out/video_out_xvmc.c:1456 src/video_out/video_out_xxmc.c:2442
msgid "Make Xv autopaint its colorkey."
msgstr "PÅ™imÄ›t Xv automaticky kreslit svou klíÄovou barvu."
-#: src/video_out/video_out_xcbxv.c:1456 src/video_out/video_out_xv.c:1470
-#: src/video_out/video_out_xxmc.c:2452
+#: src/video_out/video_out_xcbxv.c:1460 src/video_out/video_out_xv.c:1473
+#: src/video_out/video_out_xxmc.c:2449
msgid "bilinear scaling mode"
msgstr "bilineární režim škálování"
-#: src/video_out/video_out_xcbxv.c:1457 src/video_out/video_out_xv.c:1471
-#: src/video_out/video_out_xxmc.c:2453
+#: src/video_out/video_out_xcbxv.c:1461 src/video_out/video_out_xv.c:1474
+#: src/video_out/video_out_xxmc.c:2450
msgid ""
"Selects the bilinear scaling mode for Permedia cards. The individual values "
"are:\n"
@@ -4434,33 +4403,35 @@ msgstr ""
"1 - horizontální lineární filtrování\n"
"2 - povolit plné bilineární filtrování"
-#: src/video_out/video_out_xcbxv.c:1509
-#, fuzzy
-msgid "video_out_xcbxv: this adaptor supports the yv12 format.\n"
+#: src/video_out/video_out_xcbxv.c:1513 src/video_out/video_out_xv.c:1523
+#: src/video_out/video_out_xxmc.c:2506
+#, fuzzy, c-format
+msgid "%s: this adaptor supports the yv12 format.\n"
msgstr "video_out_xv: tento adaptér podporuje formát yv12.\n"
-#: src/video_out/video_out_xcbxv.c:1514
-#, fuzzy
-msgid "video_out_xcbxv: this adaptor supports the yuy2 format.\n"
+#: src/video_out/video_out_xcbxv.c:1518 src/video_out/video_out_xv.c:1528
+#: src/video_out/video_out_xxmc.c:2511
+#, fuzzy, c-format
+msgid "%s: this adaptor supports the yuy2 format.\n"
msgstr "video_out_xv: tento adaptér podporuje formát yuy2.\n"
-#: src/video_out/video_out_xcbxv.c:1522 src/video_out/video_out_xv.c:1547
-#: src/video_out/video_out_xxmc.c:2537
+#: src/video_out/video_out_xcbxv.c:1526 src/video_out/video_out_xv.c:1550
+#: src/video_out/video_out_xxmc.c:2534
msgid "pitch alignment workaround"
msgstr "obcházet chybu zarovnávání rozteÄe"
-#: src/video_out/video_out_xcbxv.c:1523 src/video_out/video_out_xv.c:1548
-#: src/video_out/video_out_xxmc.c:2538
+#: src/video_out/video_out_xcbxv.c:1527 src/video_out/video_out_xv.c:1551
+#: src/video_out/video_out_xxmc.c:2535
msgid "Some buggy video drivers need a workaround to function properly."
msgstr ""
"NÄ›které chybové ovladaÄe videa potÅ™ebují ke správnÄ› funkci tento workaround."
-#: src/video_out/video_out_xcbxv.c:1529 src/video_out/video_out_xv.c:1554
+#: src/video_out/video_out_xcbxv.c:1533 src/video_out/video_out_xv.c:1557
#: src/video_out/video_out_xvmc.c:1524
msgid "deinterlace method (deprecated)"
msgstr "metoda korekce prokládání (zavrženo)"
-#: src/video_out/video_out_xcbxv.c:1530 src/video_out/video_out_xv.c:1555
+#: src/video_out/video_out_xcbxv.c:1534 src/video_out/video_out_xv.c:1558
#: src/video_out/video_out_xvmc.c:1525
msgid ""
"This config setting is deprecated. You should use the new deinterlacing post "
@@ -4534,118 +4505,30 @@ msgstr ""
"K odstranění hřebenových artefaktů použije lehké rozmazání. Dobré výsledky "
"se střední zátěží CPU."
-#: src/video_out/video_out_xcbxv.c:1584 src/video_out/video_out_xv.c:1628
-#: src/video_out/video_out_xxmc.c:2618
+#: src/video_out/video_out_xcbxv.c:1588 src/video_out/video_out_xv.c:1631
+#: src/video_out/video_out_xxmc.c:2615
msgid "xine video output plugin using the MIT X video extension"
msgstr "výstupní modul videa xine použije rozšíření MIT X video"
#: src/video_out/video_out_xshm.c:202
-msgid ""
-"video_out_xshm: shared memory error when allocating image\n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xshm: chyba sdílené paměti během alokování obrázku\n"
-"video_out_xshm: => rozšíření MIT Shared Memory se nepoužije.\n"
-
-#: src/video_out/video_out_xshm.c:218
#, c-format
-msgid ""
-"video_out_xshm: %s: allocating image\n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xshm: %s: alokování obrázku\n"
-"video_out_xshm: => rozšíření MIT Shared Memory se nepoužije.\n"
-
-#: src/video_out/video_out_xshm.c:228
-msgid ""
-"video_out_xshm: shared memory error (address error) when allocating image \n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
+msgid "%s: shared memory error when allocating image\n"
msgstr ""
-"video_out_xshm: chyba sdílené paměti (chyba adresy) během alokování obrázku\n"
-"video_out_xshm: => rozšíření MIT Shared Memory se nepoužije.\n"
-#: src/video_out/video_out_xshm.c:245
-msgid ""
-"video_out_xshm: x11 error during shared memory XImage creation\n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xshm: chyba x11 během vytváření XImage ve sdílené paměti\n"
-"video_out_xshm: => rozšíření MIT Shared Memory se nepoužije.\n"
-
-#: src/video_out/video_out_xshm.c:1170
-msgid "video_out_xshm: MIT shared memory extension not present on display.\n"
-msgstr ""
-"video_out_xshm: Rozšíření MIT shared memory není na displeji přítomno.\n"
-
-#: src/video_out/video_out_xshm.c:1254
-msgid "video_out_xshm: your video mode was not recognized, sorry :-(\n"
-msgstr "video_out_xshm: váš videorežim nebyl rozpoznán, bohužel :-(\n"
-
-#: src/video_out/video_out_xv.c:296
-msgid ""
-"video_out_xv: XvShmCreateImage failed\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xv: selhalo XvShmCreateImage\n"
-"video_out_xv: => rozšíření MIT Shared Memory se nepoužije.\n"
-
-#: src/video_out/video_out_xv.c:306
-msgid ""
-"video_out_xv: XvShmCreateImage returned a zero size\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xv: funkce XvShmCreateImage vrátila nulovou velikost\n"
-"video_out_xv: => rozšíření MIT Shared Memory se nepoužije.\n"
-
-#: src/video_out/video_out_xv.c:314
+#: src/video_out/video_out_xv.c:294 src/video_out/video_out_xxmc.c:646
#, c-format
-msgid ""
-"video_out_xv: shared memory error in shmget: %s\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xv: chyba sdílené paměti v shmget: %s\n"
-"video_out_xv: => rozšíření MIT Shared Memory se nepoužije.\n"
-
-#: src/video_out/video_out_xv.c:346
-msgid ""
-"video_out_xv: x11 error during shared memory XImage creation\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
+msgid "%s: XvShmCreateImage failed\n"
msgstr ""
-"video_out_xv: chyba x11 během vytváření XImage\n"
-"video_out_xv: => rozšíření MIT Shared Memory se nepoužije.\n"
-#: src/video_out/video_out_xv.c:1299
-msgid "video_out_xv: Xv extension not present.\n"
-msgstr "video_out_xv: Rozšíření Xv není přítomno.\n"
-
-#: src/video_out/video_out_xv.c:1336
-msgid ""
-"video_out_xv: Xv extension is present but I couldn't find a usable yuv12 "
-"port.\n"
-" Looks like your graphics hardware driver doesn't support Xv?!\n"
-msgstr ""
-"video_out_xv: Rozšíření Xv je přítomno, ale nepodařilo se nalézt použitelný "
-"port yuv12.\n"
-" Vypadá to, jako by váš grafický hardwarový ovladaÄ "
-"nepodporoval Xv?!\n"
-
-#: src/video_out/video_out_xv.c:1345
-#, c-format
+#: src/video_out/video_out_xv.c:1348 src/video_out/video_out_xxmc.c:2330
+#, fuzzy, c-format
msgid ""
-"video_out_xv: using Xv port %ld from adaptor %s for hardware colorspace "
-"conversion and scaling.\n"
+"%s: using Xv port %ld from adaptor %s for hardware colorspace conversion and "
+"scaling.\n"
msgstr ""
"video_out_xv: pro hardwarovou konverzi barevného prostoru a škálování se "
"použije Xv port %ld z adaptéru %s.\n"
-#: src/video_out/video_out_xv.c:1520
-msgid "video_out_xv: this adaptor supports the yv12 format.\n"
-msgstr "video_out_xv: tento adaptér podporuje formát yv12.\n"
-
-#: src/video_out/video_out_xv.c:1525
-msgid "video_out_xv: this adaptor supports the yuy2 format.\n"
-msgstr "video_out_xv: tento adaptér podporuje formát yuy2.\n"
-
#: src/video_out/video_out_xvmc.c:1593
msgid "xine video output plugin using the XvMC X video extension"
msgstr "výstupní modul videa xine použije X video rozšíření XvMC"
@@ -4688,77 +4571,11 @@ msgstr " žádná podpora XvMC\n"
msgid " With Overlay = %d; UnsignedIntra = %d.\n"
msgstr " S Overlay = %d; UnsignedIntra = %d.\n"
-#: src/video_out/video_out_xxmc.c:650
-msgid ""
-"video_out_xxmc: XvShmCreateImage failed\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xxmc: selhalo XvShmCreateImage\n"
-"video_out_xxmc: => rozšíření MIT Shared Memory se nepoužije.\n"
-
-#: src/video_out/video_out_xxmc.c:660
-msgid ""
-"video_out_xxmc: XvShmCreateImage returned a zero size\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xxmc: funkce XvShmCreateImage vrátila nulovou velikost\n"
-"video_out_xxmc: => rozšíření MIT Shared Memory se nepoužije.\n"
-
-#: src/video_out/video_out_xxmc.c:668
-#, c-format
-msgid ""
-"video_out_xxmc: shared memory error in shmget: %s\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xxmc: chyba sdílené paměti v shmget: %s\n"
-"video_out_xxmc: => rozšíření MIT Shared Memory se nepoužije.\n"
-
-#: src/video_out/video_out_xxmc.c:700
-msgid ""
-"video_out_xxmc: x11 error during shared memory XImage creation\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xxmc: chyba x11 během vytváření XImage ve sdílené paměti\n"
-"video_out_xxmc: => rozšíření MIT Shared Memory se nepoužije.\n"
-
-#: src/video_out/video_out_xxmc.c:2287
-msgid "video_out_xxmc: Xv extension not present.\n"
-msgstr "video_out_xxmc: rozšíření Xv není přítomno.\n"
-
-#: src/video_out/video_out_xxmc.c:2324
-msgid ""
-"video_out_xxmc: Xv extension is present but I couldn't find a usable yuv12 "
-"port.\n"
-" Looks like your graphics hardware driver doesn't support Xv?!\n"
-msgstr ""
-"video_out_xxmc: Rozšíření Xv je přítomno, ale nepodařilo se nalézt "
-"použitelný\n"
-" port yuv12.\n"
-" Vypadá to, jako by váš grafický hardwarový ovladaÄ\n"
-" nepodporoval Xv?!\n"
-
-#: src/video_out/video_out_xxmc.c:2333
-#, c-format
-msgid ""
-"video_out_xxmc: using Xv port %ld from adaptor %s for hardware colorspace "
-"conversion and scaling.\n"
-msgstr ""
-"video_out_xxmc: pro hardwarovou konverzi barevného prostoru a škálování se "
-"použije Xv port %ld z adaptéru %s.\n"
-
-#: src/video_out/video_out_xxmc.c:2509
-msgid "video_out_xxmc: this adaptor supports the yv12 format.\n"
-msgstr "video_out_xxmc: tento adaptér podporuje formát yv12.\n"
-
-#: src/video_out/video_out_xxmc.c:2514
-msgid "video_out_xxmc: this adaptor supports the yuy2 format.\n"
-msgstr "video_out_xxmc: tento adaptér podporuje formát yuy2.\n"
-
-#: src/video_out/video_out_xxmc.c:2543
+#: src/video_out/video_out_xxmc.c:2540
msgid "Make XvMC allocate more frames for better buffering."
msgstr "PÅ™imÄ›t XvMC alokovat více snímků za úÄelem lepšího buferrování."
-#: src/video_out/video_out_xxmc.c:2544
+#: src/video_out/video_out_xxmc.c:2541
msgid ""
"Some XvMC implementations allow more than 8 frames.\n"
"This option, when turned on, makes the driver try to\n"
@@ -4768,11 +4585,11 @@ msgstr ""
"Tato volba, pokud je zapnuta, pÅ™imÄ›je ovladaÄ zkusit alokovat 15 snímků. "
"Nutnost pro unichrome a live VDR.\n"
-#: src/video_out/video_out_xxmc.c:2550
+#: src/video_out/video_out_xxmc.c:2547
msgid "Unichrome cpu save"
msgstr "Šetření procesoru unichrome"
-#: src/video_out/video_out_xxmc.c:2551
+#: src/video_out/video_out_xxmc.c:2548
msgid ""
"Saves CPU time by sleeping while decoder works.\n"
"Only for Linux kernel 2.6 series or 2.4 with multimedia patch.\n"
@@ -4782,11 +4599,11 @@ msgstr ""
"Pouze pro jádra Linuxu řady 2.6 nebo 2.4 s multimediálním patchem.\n"
"Experimentální.\n"
-#: src/video_out/video_out_xxmc.c:2557
+#: src/video_out/video_out_xxmc.c:2554
msgid "Fix buggy NVIDIA XvMC subpicture colors"
msgstr "Opravovat chybné barvy elementů XvMC"
-#: src/video_out/video_out_xxmc.c:2558
+#: src/video_out/video_out_xxmc.c:2555
msgid ""
"There's a bug in NVIDIA's XvMC lib that makes red OSD colors\n"
"look blue and vice versa. This option provides a workaround.\n"
@@ -4794,11 +4611,11 @@ msgstr ""
"V knivovnÄ› XvMC od NVidie je chyba, která způsobuje, že Äervené barvy OSD "
"vypadají modře a naopak. Tato volba umožňuje chybu obejít.\n"
-#: src/video_out/video_out_xxmc.c:2563
+#: src/video_out/video_out_xxmc.c:2560
msgid "Use bob as accelerated deinterlace method."
msgstr "Použít 'bob' jako akcelerovanou metodu korekce prokládání."
-#: src/video_out/video_out_xxmc.c:2564
+#: src/video_out/video_out_xxmc.c:2561
msgid ""
"When interlacing is enabled for hardware accelerated frames,\n"
"Alternate between top and bottom field at double the frame rate.\n"
@@ -5070,12 +4887,12 @@ msgid ""
"info_helper: unsupported conversion %s -> UTF-8, no conversion performed\n"
msgstr "info_helper: nepodporovaná konverze %s -> UTF-8, nebude prováděna\n"
-#: src/xine-engine/input_cache.c:167
+#: src/xine-engine/input_cache.c:171
#, c-format
msgid ": open() function should never be called\n"
msgstr ": funkce open() by nikdy neměla být volána\n"
-#: src/xine-engine/input_cache.c:349
+#: src/xine-engine/input_cache.c:353
#, c-format
msgid ": input plugin not defined!\n"
msgstr ": vstupní modul není definován!\n"
@@ -5190,12 +5007,12 @@ msgstr "io_helper: Soubor nenalezen\n"
msgid "io_helper: Connection Refused\n"
msgstr "io_helper: Spojení odmítnuto\n"
-#: src/xine-engine/load_plugins.c:212
+#: src/xine-engine/load_plugins.c:215
#, c-format
msgid "map_decoder_list: no space for decoder, skipped.\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:327
+#: src/xine-engine/load_plugins.c:330
#, c-format
msgid ""
"load_plugins: ignoring plugin %s, wrong iface version %d (should be %d)\n"
@@ -5203,12 +5020,12 @@ msgstr ""
"load_plugins: ignoruje se zásuvný modul %s, nesprávná verze rozhraní %d "
"(měla by být %d)\n"
-#: src/xine-engine/load_plugins.c:384
+#: src/xine-engine/load_plugins.c:387
#, c-format
msgid "priority for %s decoder"
msgstr "priorita dekodéru %s"
-#: src/xine-engine/load_plugins.c:395
+#: src/xine-engine/load_plugins.c:398
msgid ""
"The priority provides a ranking in case some media can be handled by more "
"than one decoder.\n"
@@ -5218,7 +5035,7 @@ msgstr ""
"zpracovávána více než jedním dekodérem.\n"
"Priorita 0 povolí výchozí prioritu dekodéru."
-#: src/xine-engine/load_plugins.c:423
+#: src/xine-engine/load_plugins.c:426
#, c-format
msgid ""
"load_plugins: demuxer plugin %s does not provide a priority, xine-lib will "
@@ -5227,7 +5044,7 @@ msgstr ""
"load_plugins: demultiplexní modul %s neposkytuje prioritu, xine-lib použije "
"výchozí hodnotu.\n"
-#: src/xine-engine/load_plugins.c:440
+#: src/xine-engine/load_plugins.c:443
#, c-format
msgid ""
"load_plugins: input plugin %s does not provide a priority, xine-lib will use "
@@ -5236,43 +5053,43 @@ msgstr ""
"load_plugins: vstupní modul %s neposkytuje prioritu, xine-lib použije "
"výchozí hodnotu.\n"
-#: src/xine-engine/load_plugins.c:496
+#: src/xine-engine/load_plugins.c:499
#, c-format
msgid "load_plugins: plugin %s found\n"
msgstr "load_plugins: nalezen modul %s\n"
-#: src/xine-engine/load_plugins.c:499
+#: src/xine-engine/load_plugins.c:502
#, c-format
msgid "load_plugins: static plugin found\n"
msgstr "load_plugins: nalezen statický modul\n"
-#: src/xine-engine/load_plugins.c:506
+#: src/xine-engine/load_plugins.c:509
#, c-format
msgid "load_plugins: plugin limit reached, %s could not be loaded\n"
msgstr "load_plugins: dosažen limit poÄtu modulů, %s nemohl být nahrán\n"
-#: src/xine-engine/load_plugins.c:509
+#: src/xine-engine/load_plugins.c:512
#, c-format
msgid "load_plugins: plugin limit reached, static plugin could not be loaded\n"
msgstr ""
"load_plugins: dosažen limit poÄtu modulů, statický modul nemohl být nahrán\n"
-#: src/xine-engine/load_plugins.c:526
+#: src/xine-engine/load_plugins.c:529
#, c-format
msgid "load_plugins: unknown plugin type %d in %s\n"
msgstr "load_plugins: neznámý typ modulu %d v %s\n"
-#: src/xine-engine/load_plugins.c:530
+#: src/xine-engine/load_plugins.c:533
#, c-format
msgid "load_plugins: unknown statically linked plugin type %d\n"
msgstr "load_plugins: neznámý typ %d staticky liknovaného modulu\n"
-#: src/xine-engine/load_plugins.c:590
+#: src/xine-engine/load_plugins.c:593
#, c-format
msgid "load_plugins: unable to stat %s\n"
msgstr "load_plugins: nelze provést stat na %s\n"
-#: src/xine-engine/load_plugins.c:631
+#: src/xine-engine/load_plugins.c:634
#, c-format
msgid ""
"load_plugins: cannot open plugin lib %s:\n"
@@ -5281,7 +5098,7 @@ msgstr ""
"load_plugins: nelze otevřít knihovnu modulu %s:\n"
"%s\n"
-#: src/xine-engine/load_plugins.c:646
+#: src/xine-engine/load_plugins.c:649
#, c-format
msgid ""
"load_plugins: can't get plugin info from %s:\n"
@@ -5290,12 +5107,12 @@ msgstr ""
"load_plugins: nelze získat informace modulu z %s:\n"
"%s\n"
-#: src/xine-engine/load_plugins.c:664
+#: src/xine-engine/load_plugins.c:667
#, c-format
msgid "load_plugins: skipping unreadable plugin directory %s.\n"
msgstr "load_plugins: pÅ™eskoÄí se adresář s moduly %s.\n"
-#: src/xine-engine/load_plugins.c:713
+#: src/xine-engine/load_plugins.c:716
#, c-format
msgid ""
"load_plugins: cannot (stage 2) open plugin lib %s:\n"
@@ -5304,27 +5121,32 @@ msgstr ""
"load_plugins: nelze (fáze 2) otevřít knihovnu modulu %s:\n"
"%s\n"
-#: src/xine-engine/load_plugins.c:739
+#: src/xine-engine/load_plugins.c:742
#, c-format
msgid "load_plugins: Yikes! %s doesn't contain plugin info.\n"
msgstr "load_plugins: Co?! %s neobsahuje informace modulu.\n"
-#: src/xine-engine/load_plugins.c:1305
+#: src/xine-engine/load_plugins.c:1104 src/xine-engine/load_plugins.c:1113
+#, fuzzy, c-format
+msgid "Unable to create %s directory: %s\n"
+msgstr "Nepodařilo se vytvořit objekt direct sound."
+
+#: src/xine-engine/load_plugins.c:1345
#, c-format
msgid "load_plugins: unknown content detection strategy %d\n"
msgstr "load_plugins: neznámá strategie %d zjišťování obsahu\n"
-#: src/xine-engine/load_plugins.c:1415
+#: src/xine-engine/load_plugins.c:1455
#, c-format
msgid "load_plugins: using demuxer '%s'\n"
msgstr "load_plugins: použije se demultiplexor '%s'\n"
-#: src/xine-engine/load_plugins.c:1726
+#: src/xine-engine/load_plugins.c:1766
#, c-format
msgid "load_plugins: failed to load audio output plugin <%s>\n"
msgstr "load_plugins: nelze naÄíst zvukový modul <%s>\n"
-#: src/xine-engine/load_plugins.c:1729
+#: src/xine-engine/load_plugins.c:1769
msgid ""
"load_plugins: audio output auto-probing didn't find any usable audio "
"driver.\n"
@@ -5332,7 +5154,7 @@ msgstr ""
"load_plugins: automatické testování zvukového výstupu nenašlo žádný "
"použitelný zvukový ovladaÄ.\n"
-#: src/xine-engine/load_plugins.c:2033
+#: src/xine-engine/load_plugins.c:2073
#, c-format
msgid ""
"load_plugins: cannot unload plugin lib %s:\n"
@@ -5341,31 +5163,27 @@ msgstr ""
"load_plugins: nelze uvolnit knihovnu modulu %s:\n"
"%s\n"
-#: src/xine-engine/osd.c:745
+#: src/xine-engine/osd.c:747
#, c-format
msgid "font '%s-%d' already loaded, weird.\n"
msgstr "font '%s-%d' je již nahrán, divné.\n"
-#: src/xine-engine/osd.c:757
+#: src/xine-engine/osd.c:759
#, c-format
msgid "font '%s' loading failed (%d < %d)\n"
msgstr "naÄítání fontu '%s' selhalo (%d < %d)\n"
-#: src/xine-engine/osd.c:767
+#: src/xine-engine/osd.c:769
#, c-format
msgid "wrong version for font '%s'. expected %d found %d.\n"
msgstr "nesprávná verze u fontu '%s'. oÄekávána %d, nalezena %d.\n"
-#: src/xine-engine/osd.c:834
-msgid "osd: cannot initialize ft2 library\n"
-msgstr "osd: nelze inicializovat knihovnu ft2\n"
-
-#: src/xine-engine/osd.c:857
+#: src/xine-engine/osd.c:856
#, fuzzy, c-format
msgid "osd: error matching font %s with FontConfig"
msgstr "osd: chyba naÄítání fontu %s pomocí ft2\n"
-#: src/xine-engine/osd.c:871
+#: src/xine-engine/osd.c:870
#, fuzzy, c-format
msgid "osd: error loading font %s with FontConfig"
msgstr "osd: chyba naÄítání fontu %s pomocí ft2\n"
@@ -5375,16 +5193,20 @@ msgstr "osd: chyba naÄítání fontu %s pomocí ft2\n"
msgid "osd: error looking up font %s with FontConfig"
msgstr "osd: chyba naÄítání fontu %s pomocí ft2\n"
-#: src/xine-engine/osd.c:895
-#, c-format
-msgid "osd: error loading font %s with ft2\n"
+#: src/xine-engine/osd.c:914
+#, fuzzy, c-format
+msgid "osd: error loading font %s with in XDG data directories.\n"
msgstr "osd: chyba naÄítání fontu %s pomocí ft2\n"
-#: src/xine-engine/osd.c:905
+#: src/xine-engine/osd.c:923
+msgid "osd: cannot initialize ft2 library\n"
+msgstr "osd: nelze inicializovat knihovnu ft2\n"
+
+#: src/xine-engine/osd.c:945
msgid "osd: error setting font size (no scalable font?)\n"
msgstr "osd: chyba při nastavování velikosti fontu (font není škálovatelný?)\n"
-#: src/xine-engine/osd.c:1021
+#: src/xine-engine/osd.c:1061
#, c-format
msgid ""
"osd: unknown sequence starting with byte 0x%02X in encoding \"%s\", "
@@ -5393,41 +5215,41 @@ msgstr ""
"osd: neznámá sekvence zaÄínající bytem 0x%02X v kódování \"%s\", pÅ™eskoÄí "
"se\n"
-#: src/xine-engine/osd.c:1077
+#: src/xine-engine/osd.c:1117
msgid "osd: can't find out current locale character set\n"
msgstr "osd: nelze zjistit aktuální kódovou stránku\n"
-#: src/xine-engine/osd.c:1087
+#: src/xine-engine/osd.c:1127
#, c-format
msgid "osd: unsupported conversion %s -> %s, no conversion performed\n"
msgstr "osd: nepodporovaná konverze %s -> %s, nebude prováděna\n"
-#: src/xine-engine/osd.c:1142 src/xine-engine/osd.c:1310
+#: src/xine-engine/osd.c:1182 src/xine-engine/osd.c:1350
msgid "osd: font isn't defined\n"
msgstr "osd: font není definován\n"
-#: src/xine-engine/osd.c:1181
+#: src/xine-engine/osd.c:1221
msgid "osd: error loading glyph\n"
msgstr "osd: chyba naÄítaní glyfu\n"
-#: src/xine-engine/osd.c:1187
+#: src/xine-engine/osd.c:1227
msgid "osd: error in rendering glyph\n"
msgstr "osd: chyba v renderování glyfu\n"
-#: src/xine-engine/osd.c:1347
+#: src/xine-engine/osd.c:1387
#, c-format
msgid "osd: error loading glyph %i\n"
msgstr "osd: chyba naÄítání glyfu %i\n"
-#: src/xine-engine/osd.c:1354
+#: src/xine-engine/osd.c:1394
msgid "osd: error in rendering\n"
msgstr "osd: chyba při renderování\n"
-#: src/xine-engine/osd.c:1611
+#: src/xine-engine/osd.c:1660
msgid "palette (foreground-border-background) to use for subtitles and OSD"
msgstr "paleta (popředí-okraj-pozadí) použitá na titulky a OSD"
-#: src/xine-engine/osd.c:1612
+#: src/xine-engine/osd.c:1661
msgid ""
"The palette for on-screen-display and some subtitle formats that do not "
"specify any colouring themselves. The palettes are listed in the form: "
@@ -5570,129 +5392,129 @@ msgstr ""
"videovýstupy jako je XShm, kde není škálování obrazu hardwarově urychlováno, "
"může toto dramaticky snížit využití CPU."
-#: src/xine-engine/xine.c:704 src/xine-engine/xine.c:811
-#: src/xine-engine/xine.c:850 src/xine-engine/xine.c:886
-#: src/xine-engine/xine.c:898 src/xine-engine/xine.c:911
-#: src/xine-engine/xine.c:924 src/xine-engine/xine.c:937
-#: src/xine-engine/xine.c:963 src/xine-engine/xine.c:988
-#: src/xine-engine/xine.c:1023
+#: src/xine-engine/xine.c:706 src/xine-engine/xine.c:813
+#: src/xine-engine/xine.c:852 src/xine-engine/xine.c:888
+#: src/xine-engine/xine.c:900 src/xine-engine/xine.c:913
+#: src/xine-engine/xine.c:926 src/xine-engine/xine.c:939
+#: src/xine-engine/xine.c:965 src/xine-engine/xine.c:990
+#: src/xine-engine/xine.c:1025
msgid "xine: error while parsing mrl\n"
msgstr "xine: chyba během zpracování MRL\n"
-#: src/xine-engine/xine.c:740
+#: src/xine-engine/xine.c:742
#, c-format
msgid "xine: found input plugin : %s\n"
msgstr "xine: nelze nalézt vstupní modul: %s\n"
-#: src/xine-engine/xine.c:758
+#: src/xine-engine/xine.c:760
#, c-format
msgid "xine: input plugin cannot open MRL [%s]\n"
msgstr "xine: vstupní modul nemůže otevřít MRL [%s]\n"
-#: src/xine-engine/xine.c:774
+#: src/xine-engine/xine.c:776
#, c-format
msgid "xine: cannot find input plugin for MRL [%s]\n"
msgstr "xine: nelze nalézt vstupní modul pro MRL [%s]\n"
-#: src/xine-engine/xine.c:800
+#: src/xine-engine/xine.c:802
#, c-format
msgid "xine: specified demuxer %s failed to start\n"
msgstr "xine: selhalo spuštění demultiplexoru %s\n"
-#: src/xine-engine/xine.c:836
+#: src/xine-engine/xine.c:838
#, c-format
msgid "xine: join rip input plugin\n"
msgstr "xine: připojen ripovací vstupní modul\n"
-#: src/xine-engine/xine.c:843
+#: src/xine-engine/xine.c:845
msgid "xine: error opening rip input plugin instance\n"
msgstr "xine: chyba otevírání instance ripovacího vstupního modulu\n"
-#: src/xine-engine/xine.c:874
+#: src/xine-engine/xine.c:876
#, c-format
msgid "xine: last_probed demuxer %s failed to start\n"
msgstr "xine: selhalo spuštění posledního vyzkoušeného demultiplexoru %s\n"
-#: src/xine-engine/xine.c:903
+#: src/xine-engine/xine.c:905
msgid "ignoring video\n"
msgstr "ignoruje se video\n"
-#: src/xine-engine/xine.c:916
+#: src/xine-engine/xine.c:918
msgid "ignoring audio\n"
msgstr "ignoruje se zvuk\n"
-#: src/xine-engine/xine.c:929
+#: src/xine-engine/xine.c:931
msgid "ignoring subpicture\n"
msgstr "ignorují se titulky\n"
-#: src/xine-engine/xine.c:942
+#: src/xine-engine/xine.c:944
msgid "input cache plugin disabled\n"
msgstr "vstupní modul cache zakázán\n"
-#: src/xine-engine/xine.c:1013
+#: src/xine-engine/xine.c:1015
#, c-format
msgid "subtitle mrl opened '%s'\n"
msgstr "otevřeno MRL titulků '%s'\n"
-#: src/xine-engine/xine.c:1017
+#: src/xine-engine/xine.c:1019
msgid "xine: error opening subtitle mrl\n"
msgstr "xine: chyba otevírání MRL titulků\n"
-#: src/xine-engine/xine.c:1049
+#: src/xine-engine/xine.c:1051
#, c-format
msgid "xine: error while parsing MRL\n"
msgstr "xine: chyba během zpracování MRL\n"
-#: src/xine-engine/xine.c:1056
+#: src/xine-engine/xine.c:1058
#, c-format
msgid "xine: changing option '%s' from MRL isn't permitted\n"
msgstr "xine: změna volby '%s' z MRL naní povolena\n"
-#: src/xine-engine/xine.c:1076
+#: src/xine-engine/xine.c:1078
#, c-format
msgid "xine: couldn't find demux for >%s<\n"
msgstr "xine: nelze nalézt demultiplexor pro >%s<\n"
-#: src/xine-engine/xine.c:1092
+#: src/xine-engine/xine.c:1094
#, c-format
msgid "xine: found demuxer plugin: %s\n"
msgstr "xine: nalezen demultiplexní modul: %s\n"
-#: src/xine-engine/xine.c:1112
+#: src/xine-engine/xine.c:1114
#, c-format
msgid "xine: demuxer failed to start\n"
msgstr "xine: selhalo spuštění demultiplexoru\n"
-#: src/xine-engine/xine.c:1177
+#: src/xine-engine/xine.c:1179
#, c-format
msgid "xine_play: no demux available\n"
msgstr "xine_play: žádný dostupný demultiplexor\n"
-#: src/xine-engine/xine.c:1247
+#: src/xine-engine/xine.c:1249
#, c-format
msgid "xine_play: demux failed to start\n"
msgstr "xine_play: selhalo spuštění demultiplexoru\n"
-#: src/xine-engine/xine.c:1523
+#: src/xine-engine/xine.c:1527
#, c-format
msgid "xine: The specified save_dir \"%s\" might be a security risk.\n"
msgstr ""
"xine: Uvedený adresář pro ukládání \"%s\" by mohl znamenat bezpeÄnostní "
"riziko.\n"
-#: src/xine-engine/xine.c:1528
+#: src/xine-engine/xine.c:1532
msgid "The specified save_dir might be a security risk."
msgstr "Uvedený adresář pro ukládání by mohl znamenat bezpeÄnostní riziko."
-#: src/xine-engine/xine.c:1554
+#: src/xine-engine/xine.c:1561
msgid "xine: locale not supported by C library\n"
msgstr "xine: locale není podporováno knihovnou C\n"
-#: src/xine-engine/xine.c:1563
+#: src/xine-engine/xine.c:1570
msgid "media format detection strategy"
msgstr "strategie zjištování formátu dat"
-#: src/xine-engine/xine.c:1564
+#: src/xine-engine/xine.c:1571
msgid ""
"xine offers various methods to detect the media format of input to play. The "
"individual values are:\n"
@@ -5723,11 +5545,11 @@ msgstr ""
"extension\n"
"Detekovat pouze podle přípony jména souboru.\n"
-#: src/xine-engine/xine.c:1582
+#: src/xine-engine/xine.c:1589
msgid "directory for saving streams"
msgstr "adresář pro ukládání dat"
-#: src/xine-engine/xine.c:1583
+#: src/xine-engine/xine.c:1590
msgid ""
"When using the stream save feature, files will be written only into this "
"directory.\n"
@@ -5743,11 +5565,11 @@ msgstr ""
"Proto byste si měli být jisti, že je v uvedeném adresáři bezproblémový "
"jakýkoliv obsah v jakémkoliv souboru."
-#: src/xine-engine/xine.c:1594
+#: src/xine-engine/xine.c:1601
msgid "allow implicit changes to the configuration (e.g. by MRL)"
msgstr "povolit implicitní změny v konfiguraci (např. pomocí MRL)"
-#: src/xine-engine/xine.c:1595
+#: src/xine-engine/xine.c:1602
msgid ""
"If enabled, you allow xine to change your configuration without explicit "
"actions from your side. For example configuration changes demanded by MRLs "
@@ -5764,26 +5586,26 @@ msgstr ""
"dovolíte libovolnÄ› mÄ›nit vaÅ¡i konfiguraci, můžete skonÄit s úplnÄ› rozhozeným "
"xine."
-#: src/xine-engine/xine.c:1609
+#: src/xine-engine/xine.c:1616
msgid "Timeout for network stream reading (in seconds)"
msgstr ""
-#: src/xine-engine/xine.c:1610
+#: src/xine-engine/xine.c:1617
msgid ""
"Specifies the timeout when reading from network streams, in seconds. Too low "
"values might stop streaming when the source is slow or the bandwidth is "
"occupied, too high values will freeze the player if the connection is lost."
msgstr ""
-#: src/xine-engine/xine.c:1962
+#: src/xine-engine/xine.c:1969
msgid "messages"
msgstr "zprávy"
-#: src/xine-engine/xine.c:1963
+#: src/xine-engine/xine.c:1970
msgid "plugin"
msgstr "modul"
-#: src/xine-engine/xine.c:1964
+#: src/xine-engine/xine.c:1971
msgid "trace"
msgstr "trasování"
@@ -5865,6 +5687,246 @@ msgstr ""
msgid "Benchmarking memcpy methods (smaller is better):\n"
msgstr "Výkonnostní testování metod memcpy (menší je lepší):\n"
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xcbshm: %s: allocating image\n"
+#~ "video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xshm: %s: alokování obrázku\n"
+#~ "video_out_xshm: => rozšíření MIT Shared Memory se nepoužije.\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xcbshm: shared memory error (address error) when allocating "
+#~ "image \n"
+#~ "video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xshm: chyba sdílené paměti (chyba adresy) během alokování "
+#~ "obrázku\n"
+#~ "video_out_xshm: => rozšíření MIT Shared Memory se nepoužije.\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xcbshm: x11 error during shared memory XImage creation\n"
+#~ "video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xshm: chyba x11 během vytváření XImage ve sdílené paměti\n"
+#~ "video_out_xshm: => rozšíření MIT Shared Memory se nepoužije.\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xcbshm: MIT shared memory extension not present on display.\n"
+#~ msgstr ""
+#~ "video_out_xshm: Rozšíření MIT shared memory není na displeji přítomno.\n"
+
+#, fuzzy
+#~ msgid "video_out_xcbshm: your video mode was not recognized, sorry :-(\n"
+#~ msgstr "video_out_xshm: váš videorežim nebyl rozpoznán, bohužel :-(\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xcbxv: XvShmCreateImage returned a zero size\n"
+#~ "video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xv: funkce XvShmCreateImage vrátila nulovou velikost\n"
+#~ "video_out_xv: => rozšíření MIT Shared Memory se nepoužije.\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xcbxv: shared memory error in shmget: %s\n"
+#~ "video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xv: chyba sdílené paměti v shmget: %s\n"
+#~ "video_out_xv: => rozšíření MIT Shared Memory se nepoužije.\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xcbxv: x11 error during shared memory XImage creation\n"
+#~ "video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xv: chyba x11 během vytváření XImage\n"
+#~ "video_out_xv: => rozšíření MIT Shared Memory se nepoužije.\n"
+
+#, fuzzy
+#~ msgid "video_out_xcbxv: Xv extension not present.\n"
+#~ msgstr "video_out_xv: Rozšíření Xv není přítomno.\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xcbxv: Xv extension is present but I couldn't find a usable "
+#~ "yuv12 port.\n"
+#~ " Looks like your graphics hardware driver doesn't support "
+#~ "Xv?!\n"
+#~ msgstr ""
+#~ "video_out_xv: Rozšíření Xv je přítomno, ale nepodařilo se nalézt "
+#~ "použitelný port yuv12.\n"
+#~ " Vypadá to, jako by váš grafický hardwarový ovladaÄ "
+#~ "nepodporoval Xv?!\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xcbxv: using Xv port %d from adaptor %s for hardware colorspace "
+#~ "conversion and scaling.\n"
+#~ msgstr ""
+#~ "video_out_xv: pro hardwarovou konverzi barevného prostoru a škálování se "
+#~ "použije Xv port %ld z adaptéru %s.\n"
+
+#, fuzzy
+#~ msgid "video_out_xcbxv: this adaptor supports the yv12 format.\n"
+#~ msgstr "video_out_xv: tento adaptér podporuje formát yv12.\n"
+
+#, fuzzy
+#~ msgid "video_out_xcbxv: this adaptor supports the yuy2 format.\n"
+#~ msgstr "video_out_xv: tento adaptér podporuje formát yuy2.\n"
+
+#~ msgid ""
+#~ "video_out_xshm: shared memory error when allocating image\n"
+#~ "video_out_xshm: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xshm: chyba sdílené paměti během alokování obrázku\n"
+#~ "video_out_xshm: => rozšíření MIT Shared Memory se nepoužije.\n"
+
+#~ msgid ""
+#~ "video_out_xshm: %s: allocating image\n"
+#~ "video_out_xshm: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xshm: %s: alokování obrázku\n"
+#~ "video_out_xshm: => rozšíření MIT Shared Memory se nepoužije.\n"
+
+#~ msgid ""
+#~ "video_out_xshm: x11 error during shared memory XImage creation\n"
+#~ "video_out_xshm: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xshm: chyba x11 během vytváření XImage ve sdílené paměti\n"
+#~ "video_out_xshm: => rozšíření MIT Shared Memory se nepoužije.\n"
+
+#~ msgid "video_out_xshm: your video mode was not recognized, sorry :-(\n"
+#~ msgstr "video_out_xshm: váš videorežim nebyl rozpoznán, bohužel :-(\n"
+
+#~ msgid ""
+#~ "video_out_xv: XvShmCreateImage failed\n"
+#~ "video_out_xv: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xv: selhalo XvShmCreateImage\n"
+#~ "video_out_xv: => rozšíření MIT Shared Memory se nepoužije.\n"
+
+#~ msgid ""
+#~ "video_out_xv: XvShmCreateImage returned a zero size\n"
+#~ "video_out_xv: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xv: funkce XvShmCreateImage vrátila nulovou velikost\n"
+#~ "video_out_xv: => rozšíření MIT Shared Memory se nepoužije.\n"
+
+#~ msgid ""
+#~ "video_out_xv: shared memory error in shmget: %s\n"
+#~ "video_out_xv: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xv: chyba sdílené paměti v shmget: %s\n"
+#~ "video_out_xv: => rozšíření MIT Shared Memory se nepoužije.\n"
+
+#~ msgid ""
+#~ "video_out_xv: x11 error during shared memory XImage creation\n"
+#~ "video_out_xv: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xv: chyba x11 během vytváření XImage\n"
+#~ "video_out_xv: => rozšíření MIT Shared Memory se nepoužije.\n"
+
+#~ msgid ""
+#~ "video_out_xxmc: XvShmCreateImage failed\n"
+#~ "video_out_xxmc: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xxmc: selhalo XvShmCreateImage\n"
+#~ "video_out_xxmc: => rozšíření MIT Shared Memory se nepoužije.\n"
+
+#~ msgid ""
+#~ "video_out_xxmc: XvShmCreateImage returned a zero size\n"
+#~ "video_out_xxmc: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xxmc: funkce XvShmCreateImage vrátila nulovou velikost\n"
+#~ "video_out_xxmc: => rozšíření MIT Shared Memory se nepoužije.\n"
+
+#~ msgid ""
+#~ "video_out_xxmc: shared memory error in shmget: %s\n"
+#~ "video_out_xxmc: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xxmc: chyba sdílené paměti v shmget: %s\n"
+#~ "video_out_xxmc: => rozšíření MIT Shared Memory se nepoužije.\n"
+
+#~ msgid ""
+#~ "video_out_xxmc: x11 error during shared memory XImage creation\n"
+#~ "video_out_xxmc: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xxmc: chyba x11 během vytváření XImage ve sdílené paměti\n"
+#~ "video_out_xxmc: => rozšíření MIT Shared Memory se nepoužije.\n"
+
+#~ msgid "video_out_xxmc: Xv extension not present.\n"
+#~ msgstr "video_out_xxmc: rozšíření Xv není přítomno.\n"
+
+#~ msgid ""
+#~ "video_out_xxmc: Xv extension is present but I couldn't find a usable "
+#~ "yuv12 port.\n"
+#~ " Looks like your graphics hardware driver doesn't support "
+#~ "Xv?!\n"
+#~ msgstr ""
+#~ "video_out_xxmc: Rozšíření Xv je přítomno, ale nepodařilo se nalézt "
+#~ "použitelný\n"
+#~ " port yuv12.\n"
+#~ " Vypadá to, jako by váš grafický hardwarový ovladaÄ\n"
+#~ " nepodporoval Xv?!\n"
+
+#~ msgid ""
+#~ "video_out_xxmc: using Xv port %ld from adaptor %s for hardware colorspace "
+#~ "conversion and scaling.\n"
+#~ msgstr ""
+#~ "video_out_xxmc: pro hardwarovou konverzi barevného prostoru a škálování "
+#~ "se použije Xv port %ld z adaptéru %s.\n"
+
+#~ msgid "video_out_xxmc: this adaptor supports the yv12 format.\n"
+#~ msgstr "video_out_xxmc: tento adaptér podporuje formát yv12.\n"
+
+#~ msgid "video_out_xxmc: this adaptor supports the yuy2 format.\n"
+#~ msgstr "video_out_xxmc: tento adaptér podporuje formát yuy2.\n"
+
+#~ msgid "CDDB cache directory"
+#~ msgstr "adresář se záznamy CDDB"
+
+#~ msgid ""
+#~ "The replies from the CDDB server will be cached in this directory.\n"
+#~ "This setting is security critical, because files with uncontrollable "
+#~ "names will be created in this directory. Be sure to use a dedicated "
+#~ "directory not used for anything but CDDB caching."
+#~ msgstr ""
+#~ "Odpovědi z CDDB serveru budou uchovávány v tomto adresáři.\n"
+#~ "Toto nastavení je kritické s ohledem na bezpeÄnost, protože mohou být v "
+#~ "tomto adresáři vytvářeny soubory s nekontrolovatelnými jmény. Ujistěte "
+#~ "se, že daný adresář není používán pro nic jiného než cachování CDDB."
+
+#~ msgid "path to the title key cache"
+#~ msgstr "cesta ke cache klíÄů titulů"
+
+#~ msgid ""
+#~ "Since cracking the copy protection of scrambled DVDs can be quite time "
+#~ "consuming, libdvdcss will cache the cracked keys in this directory.\n"
+#~ "This setting is security critical, because files with uncontrollable "
+#~ "names will be created in this directory. Be sure to use a dedicated "
+#~ "directory not used for anything but DVD key caching."
+#~ msgstr ""
+#~ "Protože crackování ochrany kopírování zaÅ¡ifrovaných DVD může být ÄasovÄ› "
+#~ "celkem nároÄné, libdvdcss bude v tomto adresáři cachovat cracklé klíÄe.\n"
+#~ "Toto nastavení je kritické s ohledem na bezpeÄnost, protože mohou být v "
+#~ "tomto adresáři vytvářeny soubory s nekontrolovatelnými jmény. Ujistěte "
+#~ "se, že daný adresář není kromÄ› cachování DVD klíÄů používán na nic jiného."
+
+#~ msgid ""
+#~ "WARNING: video_out_fb: current display depth is %d. For better "
+#~ "performance\n"
+#~ " a depth of 16 bpp is recommended!\n"
+#~ "\n"
+#~ msgstr ""
+#~ "VAROVÃNÃ: video_out_fb: souÄasná hloubka displeje je %d. Pro lepší výkon\n"
+#~ " je doporuÄována hloubka 16 bitů/bod!\n"
+#~ "\n"
+
#~ msgid "make the overlay behave like a fixed layer (for debugging)"
#~ msgstr "chování overlay jako pevná vrstva (pro ladění)"
diff --git a/po/de.po b/po/de.po
index 03310bf42..492096c2c 100644
--- a/po/de.po
+++ b/po/de.po
@@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: xine-lib 1.1.6\n"
"Report-Msgid-Bugs-To: xine-devel@lists.sourceforge.net\n"
-"POT-Creation-Date: 2007-04-06 15:39+0200\n"
+"POT-Creation-Date: 2007-04-24 21:48+0100\n"
"PO-Revision-Date: 2007-04-18 11:00+0200\n"
"Last-Translator: Philipp Hahn <pmhahn@users.sf.net>\n"
"Language-Team: German <de@li.org>\n"
@@ -39,23 +39,23 @@ msgstr "Namensauflösung schlug fehl"
msgid "Unknown error"
msgstr "Unbekannter Fehler"
-#: src/audio_out/audio_alsa_out.c:354
+#: src/audio_out/audio_alsa_out.c:351
#, c-format
msgid "audio_alsa_out:Already open...WHY!"
msgstr "audio_alsa_out:Bereits geöffnet...WARUM?"
-#: src/audio_out/audio_alsa_out.c:382
+#: src/audio_out/audio_alsa_out.c:379
#, c-format
msgid "audio_alsa_out: snd_pcm_open() of %s failed: %s\n"
msgstr "audio_alsa_out: snd_pcm_open() von %s schlug fehl: %s\n"
-#: src/audio_out/audio_alsa_out.c:384
+#: src/audio_out/audio_alsa_out.c:381
msgid "audio_alsa_out: >>> check if another program already uses PCM <<<\n"
msgstr ""
"audio_alsa_out: >>> Überprüfen Sie, ob ein anderen Programm PCM bereits "
"benutzt<<<\n"
-#: src/audio_out/audio_alsa_out.c:397
+#: src/audio_out/audio_alsa_out.c:394
#, c-format
msgid ""
"audio_alsa_out: broken configuration for this PCM: no configurations "
@@ -64,11 +64,11 @@ msgstr ""
"audio_alsa_out: Kaputte Konfiguration für dieses PCM: Keine Konfiguration "
"verfügbar: %s\n"
-#: src/audio_out/audio_alsa_out.c:1289
+#: src/audio_out/audio_alsa_out.c:1286
msgid "notify changes to the hardware mixer"
msgstr "Änderungen an Hardwaremixer melden"
-#: src/audio_out/audio_alsa_out.c:1290
+#: src/audio_out/audio_alsa_out.c:1287
msgid ""
"When the hardware mixer changes, your application will receive a "
"notification so that it can update its graphical representation of the mixer "
@@ -78,16 +78,16 @@ msgstr ""
"benachrichtigt, damit sie die grafische Darstellung des Mixers direkt "
"aktualisieren kann."
-#: src/audio_out/audio_alsa_out.c:1355
+#: src/audio_out/audio_alsa_out.c:1352
#, c-format
msgid "snd_lib_error_set_handler() failed: %d"
msgstr "snd_lib_error_set_handler() schlug fehl: %d"
-#: src/audio_out/audio_alsa_out.c:1362
+#: src/audio_out/audio_alsa_out.c:1359
msgid "sound card can do mmap"
msgstr "Soundkarte unterstützt mmap "
-#: src/audio_out/audio_alsa_out.c:1363
+#: src/audio_out/audio_alsa_out.c:1360
msgid ""
"Enable this, if your sound card and alsa driver support memory mapped IO.\n"
"You can try enabling it and check, if everything works. If it does, this "
@@ -98,11 +98,11 @@ msgstr ""
"Sie können dies aktivieren und testen, ob alles funktioniert. Falls ja, "
"erhöht es die Leistung."
-#: src/audio_out/audio_alsa_out.c:1372
+#: src/audio_out/audio_alsa_out.c:1369
msgid "device used for mono output"
msgstr "Gerät für Monoausgabe"
-#: src/audio_out/audio_alsa_out.c:1373
+#: src/audio_out/audio_alsa_out.c:1370
msgid ""
"xine will use this alsa device to output mono sound.\n"
"See the alsa documentation for information on alsa devices."
@@ -110,11 +110,11 @@ msgstr ""
"xine benutzt diese ALSA-Gerät für die Monoausgabe.\n"
"Lesen Sie die ALSA-Dokumentation für Informationen zu ALSA-Geräten."
-#: src/audio_out/audio_alsa_out.c:1381
+#: src/audio_out/audio_alsa_out.c:1378
msgid "device used for stereo output"
msgstr "Gerät für Stereoausgabe"
-#: src/audio_out/audio_alsa_out.c:1382
+#: src/audio_out/audio_alsa_out.c:1379
msgid ""
"xine will use this alsa device to output stereo sound.\n"
"See the alsa documentation for information on alsa devices."
@@ -122,11 +122,11 @@ msgstr ""
"xine benutzt diese ALSA-Gerät für die Stereoausgabe.\n"
"Lesen Sie die ALSA-Dokumentation für Informationen zu ALSA-Geräten."
-#: src/audio_out/audio_alsa_out.c:1390
+#: src/audio_out/audio_alsa_out.c:1387
msgid "device used for 4-channel output"
msgstr "Gerät für 4-Kanalausgabe"
-#: src/audio_out/audio_alsa_out.c:1391
+#: src/audio_out/audio_alsa_out.c:1388
msgid ""
"xine will use this alsa device to output 4 channel (4.0) surround sound.\n"
"See the alsa documentation for information on alsa devices."
@@ -134,11 +134,11 @@ msgstr ""
"xine benutzt diese ALSA-Gerät für die 4-Kanalausgabe (4.0 Raumklang).\n"
"Lesen Sie die ALSA-Dokumentation für Informationen zu ALSA-Geräten."
-#: src/audio_out/audio_alsa_out.c:1400 src/audio_out/audio_alsa_out.c:1410
+#: src/audio_out/audio_alsa_out.c:1397 src/audio_out/audio_alsa_out.c:1407
msgid "device used for 5.1-channel output"
msgstr "Gerät für 5.1-Kanalausgabe"
-#: src/audio_out/audio_alsa_out.c:1401
+#: src/audio_out/audio_alsa_out.c:1398
msgid ""
"xine will use this alsa device to output 5 channel plus LFE (5.1) surround "
"sound.\n"
@@ -148,7 +148,7 @@ msgstr ""
"Raumklang).\n"
"Lesen Sie die ALSA-Dokumentation für Informationen zu ALSA-Geräten."
-#: src/audio_out/audio_alsa_out.c:1411
+#: src/audio_out/audio_alsa_out.c:1408
msgid ""
"xine will use this alsa device to output undecoded digital surround sound. "
"This can be used be external surround decoders.\n"
@@ -158,21 +158,21 @@ msgstr ""
"Raumklang. Dies kann von externen Dekodern benutzt werden.\n"
"Lesen Sie die ALSA-Dokumentation für Informationen zu ALSA-Geräten."
-#: src/audio_out/audio_alsa_out.c:1431
+#: src/audio_out/audio_alsa_out.c:1428
#, c-format
msgid "snd_pcm_open() failed:%d:%s\n"
msgstr "snd_pcm_open() schlug fehl:%d:%s\n"
-#: src/audio_out/audio_alsa_out.c:1433
+#: src/audio_out/audio_alsa_out.c:1430
#, c-format
msgid ">>> Check if another program already uses PCM <<<\n"
msgstr ">>> Überprüfen Sie, ob ein anderen Programm bereis PCM benutzt <<<\n"
-#: src/audio_out/audio_alsa_out.c:1464 src/audio_out/audio_oss_out.c:929
+#: src/audio_out/audio_alsa_out.c:1461 src/audio_out/audio_oss_out.c:929
msgid "speaker arrangement"
msgstr "Lautsprecherplazierung"
-#: src/audio_out/audio_alsa_out.c:1465 src/audio_out/audio_oss_out.c:930
+#: src/audio_out/audio_alsa_out.c:1462 src/audio_out/audio_oss_out.c:930
msgid ""
"Select how your speakers are arranged, this determines which speakers xine "
"uses for sound output. The individual values are:\n"
@@ -233,79 +233,79 @@ msgstr ""
"Sie benötigen einen digitalen Raumklangdekoder, der alle Formate dekodieren "
"kann, die Sie über den digitalen Ausgang Ihrer Soundkarte abspielen wollen."
-#: src/audio_out/audio_alsa_out.c:1494
+#: src/audio_out/audio_alsa_out.c:1491
msgid "audio_alsa_out : supported modes are "
msgstr "audio_alsa_out : Unterstützte Modi sind "
-#: src/audio_out/audio_alsa_out.c:1497
+#: src/audio_out/audio_alsa_out.c:1494
msgid "8bit "
msgstr "8Bit "
-#: src/audio_out/audio_alsa_out.c:1502
+#: src/audio_out/audio_alsa_out.c:1499
msgid "16bit "
msgstr "16Bit "
-#: src/audio_out/audio_alsa_out.c:1506
+#: src/audio_out/audio_alsa_out.c:1503
msgid "24bit "
msgstr "24Bit "
-#: src/audio_out/audio_alsa_out.c:1510
+#: src/audio_out/audio_alsa_out.c:1507
msgid "32bit "
msgstr "32Bit "
-#: src/audio_out/audio_alsa_out.c:1521
+#: src/audio_out/audio_alsa_out.c:1518
msgid "mono "
msgstr "Mono "
-#: src/audio_out/audio_alsa_out.c:1525
+#: src/audio_out/audio_alsa_out.c:1522
msgid "stereo "
msgstr "Stereo "
-#: src/audio_out/audio_alsa_out.c:1530
+#: src/audio_out/audio_alsa_out.c:1527
msgid "4-channel "
msgstr "4-Kanal "
-#: src/audio_out/audio_alsa_out.c:1533
+#: src/audio_out/audio_alsa_out.c:1530
msgid "(4-channel not enabled in xine config) "
msgstr "(4-Kanal nicht aktiviert in xine Konfiguration) "
-#: src/audio_out/audio_alsa_out.c:1538
+#: src/audio_out/audio_alsa_out.c:1535
msgid "4.1-channel "
msgstr "4.1-Kanal "
-#: src/audio_out/audio_alsa_out.c:1541
+#: src/audio_out/audio_alsa_out.c:1538
msgid "(4.1-channel not enabled in xine config) "
msgstr "(4.1-Kanal nicht aktiviert in xine Konfiguration) "
-#: src/audio_out/audio_alsa_out.c:1546
+#: src/audio_out/audio_alsa_out.c:1543
msgid "5-channel "
msgstr "5-Kanal "
-#: src/audio_out/audio_alsa_out.c:1549
+#: src/audio_out/audio_alsa_out.c:1546
msgid "(5-channel not enabled in xine config) "
msgstr "(5-Kanal nicht aktiviert in xine Konfiguration) "
-#: src/audio_out/audio_alsa_out.c:1554
+#: src/audio_out/audio_alsa_out.c:1551
msgid "5.1-channel "
msgstr "5.1-Kanal "
-#: src/audio_out/audio_alsa_out.c:1557
+#: src/audio_out/audio_alsa_out.c:1554
msgid "(5.1-channel not enabled in xine config) "
msgstr "(5.1-Kanal nicht aktiviert in xine Konfiguration) "
-#: src/audio_out/audio_alsa_out.c:1580
+#: src/audio_out/audio_alsa_out.c:1577
msgid "a/52 and DTS pass-through\n"
msgstr "a/52 und DTS pass-through\n"
-#: src/audio_out/audio_alsa_out.c:1583
+#: src/audio_out/audio_alsa_out.c:1580
msgid "(a/52 and DTS pass-through not enabled in xine config)\n"
msgstr "(a/52 und DTS pass-through nicht aktiviert in xine Konfiguration)\n"
-#: src/audio_out/audio_alsa_out.c:1590
+#: src/audio_out/audio_alsa_out.c:1587
msgid "alsa mixer device"
msgstr "ALSA Mixergerät"
-#: src/audio_out/audio_alsa_out.c:1591
+#: src/audio_out/audio_alsa_out.c:1588
msgid ""
"xine will use this alsa mixer device to change the volume.\n"
"See the alsa documentation for information on alsa devices."
@@ -313,7 +313,7 @@ msgstr ""
"xine benutzt dieses ALSA Mixergerät, um die Lautstärke zu ändern.\n"
"Lesen Sie die ALSA-Dokumentation für Informationen zu ALSA-Geräten."
-#: src/audio_out/audio_alsa_out.c:1665
+#: src/audio_out/audio_alsa_out.c:1662
msgid "xine audio output plugin using alsa-compliant audio devices/drivers"
msgstr "xine Soundausgabe benutzt ALSA-kompatibles Gerät/Treiber"
@@ -325,201 +325,201 @@ msgstr "xine Soundausgabe benutzt kde artsd"
msgid "xine output plugin for Coreaudio/Mac OS X"
msgstr "xine Soundausgabe benutzt Coreaudio/Mac OS X"
-#: src/audio_out/audio_directx2_out.c:166
+#: src/audio_out/audio_directx2_out.c:163
msgid "Error"
msgstr "Fehler"
-#: src/audio_out/audio_directx2_out.c:173
+#: src/audio_out/audio_directx2_out.c:170
msgid "success"
msgstr "Erfolg"
-#: src/audio_out/audio_directx2_out.c:175
+#: src/audio_out/audio_directx2_out.c:172
msgid "access denied"
msgstr "Zugriff verweigert"
-#: src/audio_out/audio_directx2_out.c:177
+#: src/audio_out/audio_directx2_out.c:174
msgid "resource is already in use"
msgstr "Ressource bereits in Benutzung"
-#: src/audio_out/audio_directx2_out.c:178
+#: src/audio_out/audio_directx2_out.c:175
msgid "object was already initialized"
msgstr "Objekt bereits initialisiert"
-#: src/audio_out/audio_directx2_out.c:179
+#: src/audio_out/audio_directx2_out.c:176
msgid "specified wave format is not supported"
msgstr "Angegebenes wave-Format nicht unterstützt"
-#: src/audio_out/audio_directx2_out.c:180
+#: src/audio_out/audio_directx2_out.c:177
msgid "memory buffer has been lost and must be restored"
msgstr "Speicherpuffer verloren und muß wiederhergesteööt werden"
-#: src/audio_out/audio_directx2_out.c:181
+#: src/audio_out/audio_directx2_out.c:178
msgid "requested buffer control is not available"
msgstr "Angeforderter Puffereinstellung nicht verfügbar"
-#: src/audio_out/audio_directx2_out.c:182
+#: src/audio_out/audio_directx2_out.c:179
msgid "undetermined error inside DirectSound subsystem"
msgstr "Unbestimmter Fehler in DirectSound-System"
-#: src/audio_out/audio_directx2_out.c:184
+#: src/audio_out/audio_directx2_out.c:181
msgid "DirectSound hardware device is unavailable"
msgstr "DirectSound-Hardware nicht verfügbar"
-#: src/audio_out/audio_directx2_out.c:186
+#: src/audio_out/audio_directx2_out.c:183
msgid "function is not valid for the current state of the object"
msgstr "Funktion ist ungültig im aktuellen Zustand des Objekts"
-#: src/audio_out/audio_directx2_out.c:187
+#: src/audio_out/audio_directx2_out.c:184
msgid "invalid parameter was passed"
msgstr "Ungültiger Parameter wurde übergeben"
-#: src/audio_out/audio_directx2_out.c:188
+#: src/audio_out/audio_directx2_out.c:185
msgid "object doesn't support aggregation"
msgstr "Objekt unterstützt keine Aggregation"
-#: src/audio_out/audio_directx2_out.c:189
+#: src/audio_out/audio_directx2_out.c:186
msgid "no sound driver available for use"
msgstr "Kein Sound-Treiber verfügbar"
-#: src/audio_out/audio_directx2_out.c:190
+#: src/audio_out/audio_directx2_out.c:187
msgid "requested COM interface not available"
msgstr "Angeforderte COM-Schnittstelle nicht verfügbar"
-#: src/audio_out/audio_directx2_out.c:191
+#: src/audio_out/audio_directx2_out.c:188
msgid "another application has a higher priority level"
msgstr "Eine andere Anwendung hat eine höhere Priorität"
-#: src/audio_out/audio_directx2_out.c:192
+#: src/audio_out/audio_directx2_out.c:189
msgid "insufficient memory"
msgstr "Ungenügend Speicher"
-#: src/audio_out/audio_directx2_out.c:193
+#: src/audio_out/audio_directx2_out.c:190
msgid "low priority level for this function"
msgstr "Niedrige Priorität für diese Funktion"
-#: src/audio_out/audio_directx2_out.c:194
+#: src/audio_out/audio_directx2_out.c:191
msgid "DirectSound wasn't initialized"
msgstr "DirectSound wurde nicht initialisiert"
-#: src/audio_out/audio_directx2_out.c:195
+#: src/audio_out/audio_directx2_out.c:192
msgid "function is not supported"
msgstr "Funtkion wird nicht unterstützt"
-#: src/audio_out/audio_directx2_out.c:196
+#: src/audio_out/audio_directx2_out.c:193
msgid "unknown error"
msgstr "Unbekannter Fehler"
-#: src/audio_out/audio_directx2_out.c:206
+#: src/audio_out/audio_directx2_out.c:203
#, c-format
msgid "Unable to create direct sound object."
msgstr "Kann DirectSound-Objekt nicht erzeugen."
-#: src/audio_out/audio_directx2_out.c:212
+#: src/audio_out/audio_directx2_out.c:209
#, c-format
msgid "Could not set direct sound cooperative level."
msgstr "Konnte DirectSound-Kooperationslevel nicht setzen."
-#: src/audio_out/audio_directx2_out.c:286
+#: src/audio_out/audio_directx2_out.c:283
msgid "Unable to create secondary direct sound buffer"
msgstr "Konnte keinen sekundären DirectSound-Puffer erzeugen"
-#: src/audio_out/audio_directx2_out.c:310
+#: src/audio_out/audio_directx2_out.c:307
#, c-format
msgid "Unable to create buffer position events."
msgstr "Konnte kein Pufferposition-Ereignis erzeugen."
-#: src/audio_out/audio_directx2_out.c:318
+#: src/audio_out/audio_directx2_out.c:315
msgid "Unable to get notification interface"
msgstr "Konnte Benachrichtigungs-Schnittstelle nicht bekommen "
-#: src/audio_out/audio_directx2_out.c:323
+#: src/audio_out/audio_directx2_out.c:320
msgid "Unable to set notification positions"
msgstr "Konnte Benachrichtigungs-Position nicht setzen"
-#: src/audio_out/audio_directx2_out.c:343
+#: src/audio_out/audio_directx2_out.c:340
msgid "Couldn't play sound buffer"
msgstr "Konnte Soundpuffer nicht wiedergeben"
-#: src/audio_out/audio_directx2_out.c:355
+#: src/audio_out/audio_directx2_out.c:352
msgid "Couldn't stop sound buffer"
msgstr "Konnte Soundpuffer nicht stoppen"
-#: src/audio_out/audio_directx2_out.c:368
+#: src/audio_out/audio_directx2_out.c:365
msgid "Can't get buffer position"
msgstr "Konnte Pufferposition nicht ermitteln"
-#: src/audio_out/audio_directx2_out.c:382
+#: src/audio_out/audio_directx2_out.c:379
msgid "Can't set buffer position"
msgstr "Konnte Pufferposition nicht setzen"
-#: src/audio_out/audio_directx2_out.c:414
+#: src/audio_out/audio_directx2_out.c:411
msgid "Can't set sound volume"
msgstr "Konnte Lautstärke nicht setzen"
-#: src/audio_out/audio_directx2_out.c:432
+#: src/audio_out/audio_directx2_out.c:429
#, c-format
msgid ": buffer lost, tryig to restore\n"
msgstr ": Puffer verloren, versuche wiederherzustellen\n"
-#: src/audio_out/audio_directx2_out.c:436
+#: src/audio_out/audio_directx2_out.c:433
msgid "Couldn't lock direct sound buffer"
msgstr "Konnte DirectSound-Puffer nicht belegen"
-#: src/audio_out/audio_directx2_out.c:447
+#: src/audio_out/audio_directx2_out.c:444
msgid "Couldn't unlock direct sound buffer"
msgstr "Konnte DirectSound-Puffer nicht freigeben"
-#: src/audio_out/audio_directx2_out.c:544
+#: src/audio_out/audio_directx2_out.c:541
#, c-format
msgid "Unable to create primary direct sound buffer."
msgstr "Konnte keinen primären DirectSound-Puffer erzeugen."
-#: src/audio_out/audio_directx2_out.c:637
+#: src/audio_out/audio_directx2_out.c:634
#, c-format
msgid ": play cursor overran, flushing buffers\n"
msgstr ": Wiedergabeposition überrannt, leere Puffer\n"
-#: src/audio_out/audio_directx2_out.c:655
+#: src/audio_out/audio_directx2_out.c:652
#, c-format
msgid ": delayed by %ld msec\n"
msgstr ": %ld msec verzögert\n"
-#: src/audio_out/audio_directx2_out.c:759
+#: src/audio_out/audio_directx2_out.c:756
#, c-format
msgid ": can't create pthread condition: %s\n"
msgstr ": Kann PThread-Bedingung nicht erzeugen: %s\n"
-#: src/audio_out/audio_directx2_out.c:763
+#: src/audio_out/audio_directx2_out.c:760
#, c-format
msgid ": can't create pthread mutex: %s\n"
msgstr ": Kann PThread-Mutex nicht erzeugen: %s\n"
-#: src/audio_out/audio_directx2_out.c:770
+#: src/audio_out/audio_directx2_out.c:767
#, c-format
msgid ": can't create buffer pthread: %s\n"
msgstr ": Kann Puffer-PThread nicht erzeugen: %s\n"
-#: src/audio_out/audio_directx2_out.c:877
+#: src/audio_out/audio_directx2_out.c:874
#, c-format
msgid ": can't destroy buffer pthread: %s\n"
msgstr ": Kann Puffer-PThread nicht freigeben: %s\n"
-#: src/audio_out/audio_directx2_out.c:884
+#: src/audio_out/audio_directx2_out.c:881
#, c-format
msgid ": can't destroy pthread condition: %s\n"
msgstr ": Kann PThread-Bedigung nicht freigeben: %s\n"
-#: src/audio_out/audio_directx2_out.c:887
+#: src/audio_out/audio_directx2_out.c:884
#, c-format
msgid ": can't destroy pthread mutex: %s\n"
msgstr ": Kann PThread-Mutex nicht freigeben: %s\n"
-#: src/audio_out/audio_directx2_out.c:947
+#: src/audio_out/audio_directx2_out.c:944
#, c-format
msgid ": unknown control command %d\n"
msgstr ": Unbekanntes Steuerkommando %d\n"
-#: src/audio_out/audio_directx2_out.c:1003
+#: src/audio_out/audio_directx2_out.c:1000
msgid "second xine audio output plugin using directx"
msgstr "2. xine Soundausgabe benutzt directx"
@@ -991,7 +991,7 @@ msgstr "demux_snd: Ungültige Header-Parameter\n"
msgid "demux_snd: unsupported audio type: %d\n"
msgstr "demux_snd: Unbekannter Audiotyp: %d\n"
-#: src/demuxers/demux_tta.c:88
+#: src/demuxers/demux_tta.c:86
msgid "demux_tta: total frames count too high\n"
msgstr "demux_tta: Gesamt-Bildanzahl zu hoch\n"
@@ -1014,7 +1014,7 @@ msgstr ""
msgid "demux_wc3movie: SHOT chunk referenced invalid palette (%d >= %d)\n"
msgstr "demux_wc3movie: SHOT Paket referenziert ungültige Palette (%d >= %d)\n"
-#: src/demuxers/demux_wc3movie.c:406
+#: src/demuxers/demux_wc3movie.c:404
#, c-format
msgid "demux_wc3movie: There was a problem while loading palette chunks\n"
msgstr "demux_wc3movie: Beim Laden der Palette ist ein Problem aufgetreten\n"
@@ -1489,31 +1489,31 @@ msgstr ""
"video_out_dxr3: Fehler beim Lesen der Überlagerungsdatei. Starten Sie "
"autocal!\n"
-#: src/input/input_cdda.c:1621
+#: src/input/input_cdda.c:1608
#, c-format
msgid "%s: can't connect to %s:%d\n"
msgstr "%s: Kann keine Verbindung zu '%s:%d' aufbauen\n"
-#: src/input/input_cdda.c:1668
+#: src/input/input_cdda.c:1655
#, c-format
msgid "input_cdda: successfuly connected to cddb server '%s:%d'.\n"
msgstr "input_cdda: Verbindung zum CDDB-Server '%s:%d' steht.\n"
-#: src/input/input_cdda.c:1673
+#: src/input/input_cdda.c:1660
#, c-format
msgid "input_cdda: failed to connect to cddb server '%s:%d' (%s).\n"
msgstr ""
"input_cdda: Kann keine Verbindung zum CDDB-Server '%s:%d' (%s) herstellen.\n"
-#: src/input/input_cdda.c:2707
+#: src/input/input_cdda.c:2690
msgid "CD Digital Audio (aka. CDDA)"
msgstr "CD Digital Audio (CDDA)"
-#: src/input/input_cdda.c:2760
+#: src/input/input_cdda.c:2742
msgid "device used for CD audio"
msgstr "Gerät für CD-Audio"
-#: src/input/input_cdda.c:2761
+#: src/input/input_cdda.c:2743
msgid ""
"The path to the device, usually a CD or DVD drive, which you intend to use "
"for playing audio CDs."
@@ -1521,11 +1521,11 @@ msgstr ""
"Pfadangabe zum Gerät (normalerweise CD oder DVD Laufwerk), das zur "
"Wiedergabe von Audio-CDs benutzt werden soll."
-#: src/input/input_cdda.c:2767
+#: src/input/input_cdda.c:2749
msgid "query CDDB"
msgstr "CDDB abfragen"
-#: src/input/input_cdda.c:2767
+#: src/input/input_cdda.c:2749
msgid ""
"Enables CDDB queries, which will give you convenient title and track names "
"for your audio CDs.\n"
@@ -1538,11 +1538,11 @@ msgstr ""
"Informationen von einem Internetserver bezogen werden, der ein Profil Ihrer "
"Hörgewohnheiten erstellen kann."
-#: src/input/input_cdda.c:2775
+#: src/input/input_cdda.c:2757
msgid "CDDB server name"
msgstr "CDDB Servername"
-#: src/input/input_cdda.c:2775
+#: src/input/input_cdda.c:2757
msgid ""
"The CDDB server used to retrieve the title and track information from.\n"
"This setting is security critical, because the sever will receive "
@@ -1554,36 +1554,19 @@ msgstr ""
"Ihren Hörgewohnheiten erhält und bösartige Antworten senden kann. Geben Sie "
"nur einen Server ihres Vertrauens an."
-#: src/input/input_cdda.c:2783
+#: src/input/input_cdda.c:2765
msgid "CDDB server port"
msgstr "CDDB Serverport"
-#: src/input/input_cdda.c:2783
+#: src/input/input_cdda.c:2765
msgid "The server port used to retrieve the title and track information from."
msgstr "Der Serverport, vom dem Titelinformationen bezogen werden sollen."
-#: src/input/input_cdda.c:2789
-msgid "CDDB cache directory"
-msgstr "CDDB Cacheverzeichnis"
-
-#: src/input/input_cdda.c:2789
-msgid ""
-"The replies from the CDDB server will be cached in this directory.\n"
-"This setting is security critical, because files with uncontrollable names "
-"will be created in this directory. Be sure to use a dedicated directory not "
-"used for anything but CDDB caching."
-msgstr ""
-"Die Antworten des CDDB-Servers werden in diesem Verzeichnis "
-"zwischengepuffert.\n"
-"Diese Einstellung ist Sicherheitskritisch, da Dateien mit unkontrollierten "
-"Namen innerhalb dieses Verzeichnises angelegt werden. Stellen Sie sicher, "
-"daß das Verzeichnis nur für CDDB Zwischenpufferung genutzt wird."
-
-#: src/input/input_cdda.c:2797
+#: src/input/input_cdda.c:2771
msgid "slow down disc drive to this speed factor"
msgstr "Laufwerk auf diesen Faktor verlangsamen"
-#: src/input/input_cdda.c:2798
+#: src/input/input_cdda.c:2772
msgid ""
"Since some CD or DVD drives make some really loud noises because of the fast "
"disc rotation, xine will try to slow them down. With standard CD or DVD "
@@ -1598,58 +1581,63 @@ msgstr ""
"auf die Wiedergabeleistung haben sollte.\n"
"Ein Wert von Null deaktiviert das Bremsen."
-#: src/input/input_dvb.c:881
-#, c-format
-msgid "input_dvb: failed to open dvb channel file '%s'\n"
+#: src/input/input_dvb.c:899
+#, fuzzy, c-format
+msgid "input_dvb: failed to open dvb channel file '%s': %s\n"
+msgstr "input_dvb: Öffnen der DVB-Kanaldatei '%s' schlug fehl\n"
+
+#: src/input/input_dvb.c:905
+#, fuzzy, c-format
+msgid "input_dvb: dvb channel file '%s' is not a plain file\n"
msgstr "input_dvb: Öffnen der DVB-Kanaldatei '%s' schlug fehl\n"
-#: src/input/input_dvb.c:2082 src/input/input_dvb.c:2910
+#: src/input/input_dvb.c:2115 src/input/input_dvb.c:2943
msgid "input_dvb: tuner_set_channel failed\n"
msgstr "input_dvb: tuner_set_channel schlug fehl\n"
-#: src/input/input_dvb.c:2710
+#: src/input/input_dvb.c:2743
msgid "input_dvb: cannot open dvb device\n"
msgstr "input_dvb: Kann DVB-Gerät nicht öffnen\n"
-#: src/input/input_dvb.c:2734
+#: src/input/input_dvb.c:2767
#, c-format
msgid "input_dvb: channel %d out of range, defaulting to 0\n"
msgstr "input_dvb: Kanal %d außerhalb des Bereis, benutzt 0\n"
-#: src/input/input_dvb.c:2745
+#: src/input/input_dvb.c:2778
#, c-format
msgid "input_dvb: searching for channel %s\n"
msgstr "input_dvb: Suche nach Kanal %s\n"
-#: src/input/input_dvb.c:2768
+#: src/input/input_dvb.c:2801
#, c-format
msgid "input_dvb: exact match for %s not found: trying partial matches\n"
msgstr ""
"input_dvb: Keine exakte Übereinstimmung für %s gefunden: versuche teilweise "
"Übereinstimmung\n"
-#: src/input/input_dvb.c:2775
+#: src/input/input_dvb.c:2808
#, c-format
msgid "input_dvb: found matching channel %s\n"
msgstr "input_dvb: Übereinstimmung mit Kanal %s gefunden\n"
-#: src/input/input_dvb.c:2788
+#: src/input/input_dvb.c:2821
#, c-format
msgid "input_dvb: channel %s not found in channels.conf, defaulting.\n"
msgstr "input_dvb: Kanal %s nicht in channels.conf gefunden, Standardkanal.\n"
-#: src/input/input_dvb.c:2794
+#: src/input/input_dvb.c:2827
msgid ""
"input_dvb: invalid channel specification, defaulting to last viewed "
"channel.\n"
msgstr ""
"input_dvb: Ungültige Kanalspezifikation, benutze zulest gesehenen Kanal.\n"
-#: src/input/input_dvb.c:2800
+#: src/input/input_dvb.c:2833
msgid "input_dvb: invalid channel specification, defaulting to channel 0\n"
msgstr "input_dvb: Ungültige Kanalspezifikation, benutze Kanal 0\n"
-#: src/input/input_dvb.c:2812
+#: src/input/input_dvb.c:2845
msgid ""
"input_dvb: dvbs mrl specified but the tuner doesn't appear to be QPSK (DVB-"
"S)\n"
@@ -1657,7 +1645,7 @@ msgstr ""
"input_dvb: DVB-S MRL angegeben, aber Tuner scheint kein QPSK (DVB-S) zu "
"sein\n"
-#: src/input/input_dvb.c:2832
+#: src/input/input_dvb.c:2865
msgid ""
"input_dvb: dvbt mrl specified but the tuner doesn't appear to be OFDM (DVB-"
"T)\n"
@@ -1665,27 +1653,27 @@ msgstr ""
"input_dvb: DVB-T MRL angegeben, aber Tuner scheint kein OFDM (DVB-T) zu "
"sein\n"
-#: src/input/input_dvb.c:2855 src/input/input_dvb.c:2881
+#: src/input/input_dvb.c:2888 src/input/input_dvb.c:2914
msgid ""
"input_dvb: dvbc mrl specified but the tuner doesn't appear to be QAM (DVB-"
"C)\n"
msgstr ""
"input_dvb: DVB-C MRL angegeben, aber Tuner scheint kein QAM (DVB-C) zu sein\n"
-#: src/input/input_dvb.c:2916
+#: src/input/input_dvb.c:2949
#, c-format
msgid "input_dvb: cannot open dvr device '%s'\n"
msgstr "input_dvb: Kann DVR-Gerät '%s' nicht öffnen\n"
-#: src/input/input_dvb.c:2938
+#: src/input/input_dvb.c:2971
msgid "input_dvb: cannot create EPG updater thread\n"
msgstr "input_dvb: Kann EPG-Aktualisierungsthread nicht erstellen\n"
-#: src/input/input_dvb.c:3000
+#: src/input/input_dvb.c:3033
msgid "use DVB 'center cutout' (zoom)"
msgstr "Benutze DVB 'center cutout' (Zoom)"
-#: src/input/input_dvb.c:3001
+#: src/input/input_dvb.c:3034
msgid ""
"This will allow fullscreen playback of 4:3 content transmitted in a 16:9 "
"frame."
@@ -1693,15 +1681,15 @@ msgstr ""
"Dies erlaubt Vollbildwiedergabe von 4:3 Inhalten, die in 16:9 übertragen "
"werden."
-#: src/input/input_dvb.c:3094
+#: src/input/input_dvb.c:3127
msgid "DVB (Digital TV) input plugin"
msgstr "DVB (Digital TV) Plugin"
-#: src/input/input_dvb.c:3242
+#: src/input/input_dvb.c:3244
msgid "Remember last DVB channel watched"
msgstr "Zuletzt gesehenen DVB-Kanal vermerken"
-#: src/input/input_dvb.c:3243
+#: src/input/input_dvb.c:3245
msgid ""
"On autoplay, xine will remember and switch to the channel indicated in media."
"dvb.last_channel. "
@@ -1709,19 +1697,19 @@ msgstr ""
"Bei automatischer Widergabe wechselt xine zum zuletztgesehenen Kanal media."
"dvb.last_channel. "
-#: src/input/input_dvb.c:3250
+#: src/input/input_dvb.c:3252
msgid "Last DVB channel viewed"
msgstr "Zuletzt gesehener DVB-Kanal"
-#: src/input/input_dvb.c:3251
+#: src/input/input_dvb.c:3253
msgid "If enabled xine will remember and switch to this channel. "
msgstr "Falls aktiviert vermerkt xine den Kanal und wechselt zu diesem. "
-#: src/input/input_dvb.c:3257
+#: src/input/input_dvb.c:3259
msgid "Number of dvb card to use."
msgstr "Nummer der zu benutzenden DVB-Karte."
-#: src/input/input_dvb.c:3258
+#: src/input/input_dvb.c:3260
msgid ""
"Leave this at zero unless you really have more than 1 card in your system."
msgstr ""
@@ -1752,11 +1740,11 @@ msgstr ""
"Pfadangabe zum Gerät (normalerweise ein DVD Laufwerk), das zur Wiedergabe "
"von DVDs benutzt werden soll."
-#: src/input/input_dvd.c:1800
+#: src/input/input_dvd.c:1799
msgid "raw device set up for DVD access"
msgstr "Pfad zum RAW-Device des DVD-Laufwerks"
-#: src/input/input_dvd.c:1801
+#: src/input/input_dvd.c:1800
msgid ""
"If this points to a raw device connected to your DVD device, xine will use "
"the raw device for playback. This has the advantage of being slightly faster "
@@ -1774,11 +1762,11 @@ msgstr ""
"Lesen Sie die Dokumentation zu RAW-Devices (man raw) für weitere "
"Informationen."
-#: src/input/input_dvd.c:1814
+#: src/input/input_dvd.c:1813
msgid "CSS decryption method"
msgstr "CSS Entschlüsselungsmethode"
-#: src/input/input_dvd.c:1815
+#: src/input/input_dvd.c:1814
msgid ""
"Selects the decryption method libdvdcss will use to descramble copy "
"protected DVDs. Try the various methods, if you have problems playing "
@@ -1789,31 +1777,11 @@ msgstr ""
"Methoden, falls Probleme bei der Wiedergabe von verschlüsselten DVDs "
"auftreten."
-#: src/input/input_dvd.c:1823
-msgid "path to the title key cache"
-msgstr "Pfad zum Titelschlüsselcache"
-
-#: src/input/input_dvd.c:1824
-msgid ""
-"Since cracking the copy protection of scrambled DVDs can be quite time "
-"consuming, libdvdcss will cache the cracked keys in this directory.\n"
-"This setting is security critical, because files with uncontrollable names "
-"will be created in this directory. Be sure to use a dedicated directory not "
-"used for anything but DVD key caching."
-msgstr ""
-"Da das Cracken des Kopierschutzes von verschlüsselten DVDs viel Zeit "
-"erfordern kann, speichert libdvdcss gefundenen Schlüssel in diesem "
-"Verzeichnis zwischen.\n"
-"Diese Einstellung ist Sicherheitskritisch, da Dateien mit unkontrollierten "
-"Namen innerhalb dieses Verzeichnises angelegt werden. Stellen Sie sicher, "
-"daß das Verzeichnis nur für die Zwischenpufferung von DVD Titelschlüssel "
-"genutzt wird."
-
-#: src/input/input_dvd.c:1846
+#: src/input/input_dvd.c:1829
msgid "region the DVD player claims to be in (1 to 8)"
msgstr "Region (1-8), aus der der DVD Player zu kommen scheint"
-#: src/input/input_dvd.c:1847
+#: src/input/input_dvd.c:1830
msgid ""
"This only needs to be changed if your DVD jumps to a screen complaining "
"about a wrong region code. It has nothing to do with the region code set in "
@@ -1823,11 +1791,11 @@ msgstr ""
"sich über ein falscher Regionscode beschwert wird. Dies hat nichts mit dem "
"Regionscode im DVD-Laufwerk zu tun, dies ist nur für die Software."
-#: src/input/input_dvd.c:1853
+#: src/input/input_dvd.c:1836
msgid "default language for DVD playback"
msgstr "Standardsprache für die DVD-Wiedergabe"
-#: src/input/input_dvd.c:1854
+#: src/input/input_dvd.c:1837
msgid ""
"xine tries to use this language as a default for DVD playback. As far as the "
"DVD supports it, menus and audio tracks will be presented in this language.\n"
@@ -1837,11 +1805,11 @@ msgstr ""
"DVD dies unterstützt, werden Menüs und Titel in dieser Sparche angezeigt.\n"
"Der Wert muß ein zweibuchstabiger ISO639-Sprachcode sein."
-#: src/input/input_dvd.c:1860
+#: src/input/input_dvd.c:1843
msgid "read-ahead caching"
msgstr "Vorauseilendes Caching benutzen"
-#: src/input/input_dvd.c:1861
+#: src/input/input_dvd.c:1844
msgid ""
"xine can use a read ahead cache for DVD drive access.\n"
"This may lead to jerky playback on slow drives, but it improves the impact "
@@ -1851,11 +1819,11 @@ msgstr ""
"Dies kann bei langsamen Laufwerken zu einer stotternden Wiedergabe führen, "
"verbessert aber den Einfluß von DVD-Ebenenwechseln bei schnellen Laufwerken."
-#: src/input/input_dvd.c:1867
+#: src/input/input_dvd.c:1850
msgid "unit for the skip action"
msgstr "Einheit für die Überspringen-Aktion"
-#: src/input/input_dvd.c:1868
+#: src/input/input_dvd.c:1851
msgid ""
"You can configure the behaviour when issuing a skip command (using the skip "
"buttons for example). The individual values mean:\n"
@@ -1890,11 +1858,11 @@ msgstr ""
"Überspringt eine DVD-Titel, was eine Struktureinheit ist, die einem "
"kompletten DVD Film entspricht"
-#: src/input/input_dvd.c:1883
+#: src/input/input_dvd.c:1866
msgid "unit for seeking"
msgstr "Einheit beim Suchen"
-#: src/input/input_dvd.c:1884
+#: src/input/input_dvd.c:1867
msgid ""
"You can configure the domain spanned by the seek slider. The individual "
"values mean:\n"
@@ -1918,11 +1886,11 @@ msgstr ""
"Der Suchbereich umfaßt ein DVD-Programm, was eine Navigationseinheit ist, "
"die einem Kapitel des aktuellen Films entspricht"
-#: src/input/input_dvd.c:1895
+#: src/input/input_dvd.c:1878
msgid "play mode when title/chapter is given"
msgstr "Wiedergabemodus falls Titel/Kapitel angegeben"
-#: src/input/input_dvd.c:1896
+#: src/input/input_dvd.c:1879
msgid ""
"You can configure the behaviour when playing a dvd from a given title/"
"chapter (eg. using MRL 'dvd:/1.2'). The individual values mean:\n"
@@ -2676,7 +2644,7 @@ msgstr ""
"1024: Standbilder\n"
"2048: Debugging von VCDINFO\n"
-#: src/liba52/xine_a52_decoder.c:742 src/libdts/xine_dts_decoder.c:546
+#: src/liba52/xine_a52_decoder.c:742 src/libxineadec/xine_dts_decoder.c:524
msgid "HELP! a mono-only audio driver?!\n"
msgstr "HILFE! Ein nur-Mono-Audiogerät?!\n"
@@ -2739,62 +2707,62 @@ msgstr "libfaad: libfaad NeAACDecInit2 schlug fehl.\n"
msgid "libfaad: libfaad NeAACDecInit failed.\n"
msgstr "libfaad: libfaad NeAACDecInit schlug fehl.\n"
-#: src/libffmpeg/ff_audio_decoder.c:120
+#: src/libffmpeg/ff_audio_decoder.c:122
#, c-format
msgid "ffmpeg_audio_dec: increasing buffer to %d to avoid overflow.\n"
msgstr "ffmpeg_audio_dec: Vergrößere Puffer auf %d um Überlauf zu vermeiden.\n"
-#: src/libffmpeg/ff_audio_decoder.c:164
+#: src/libffmpeg/ff_audio_decoder.c:166
#, c-format
msgid "ffmpeg_audio_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"
msgstr ""
"ffmpeg_audio_dec: Konnte keinen ffmpeg-Dekoder für Puffertyp 0x%X finden\n"
-#: src/libffmpeg/ff_audio_decoder.c:256
+#: src/libffmpeg/ff_audio_decoder.c:258
msgid "ffmpeg_audio_dec: trying to open null codec\n"
msgstr "ffmpeg_audio_dec: Besuche NULl-Codec zu öffnen\n"
-#: src/libffmpeg/ff_audio_decoder.c:265
+#: src/libffmpeg/ff_audio_decoder.c:267
msgid "ffmpeg_audio_dec: couldn't open decoder\n"
msgstr "ffmpeg_audio_dec: Konnte Dekoder nicht öffnen\n"
-#: src/libffmpeg/ff_dvaudio_decoder.c:286
+#: src/libffmpeg/ff_dvaudio_decoder.c:280
#, c-format
msgid "dvaudio: increasing buffer to %d to avoid overflow.\n"
msgstr "dvaudio: Vergrößere Puffer auf %d um Überlauf zu vermeiden.\n"
-#: src/libffmpeg/ff_video_decoder.c:157
+#: src/libffmpeg/ff_video_decoder.c:155
msgid "ffmpeg_video_dec: unsupported frame format, DR1 disabled.\n"
msgstr "ffmpeg_video_dec: Nichtunterstütztes Bildformat, DR1 deaktiviert.\n"
-#: src/libffmpeg/ff_video_decoder.c:175
+#: src/libffmpeg/ff_video_decoder.c:173
msgid "ffmpeg_video_dec: unsupported frame dimensions, DR1 disabled.\n"
msgstr "ffmpeg_video_dec: Nichtunterstütztes Bildformat, DR1 deaktiviert.\n"
-#: src/libffmpeg/ff_video_decoder.c:335
+#: src/libffmpeg/ff_video_decoder.c:333
#, c-format
msgid "ffmpeg_video_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"
msgstr ""
"ffmpeg_video_dec: Konnte keinen ffmpeg-Dekoder für Puffertyp 0x%X finden\n"
-#: src/libffmpeg/ff_video_decoder.c:364
+#: src/libffmpeg/ff_video_decoder.c:362
msgid "ffmpeg_video_dec: couldn't open decoder\n"
msgstr "ffmpeg_video_dec: Konnte Dekoder nicht öffnen\n"
-#: src/libffmpeg/ff_video_decoder.c:399
+#: src/libffmpeg/ff_video_decoder.c:397
msgid "ffmpeg_video_dec: direct rendering enabled\n"
msgstr "ffmpeg_video_dec: Direktausgabe aktiviert\n"
-#: src/libffmpeg/ff_video_decoder.c:818
+#: src/libffmpeg/ff_video_decoder.c:816
#, c-format
msgid "ffmpeg_video_dec: increasing buffer to %d to avoid overflow.\n"
msgstr "ffmpeg_video_dec: Vergrößere Puffer auf %d um Überlauf zu vermeiden.\n"
-#: src/libffmpeg/ff_video_decoder.c:1516
+#: src/libffmpeg/ff_video_decoder.c:1514
msgid "MPEG-4 postprocessing quality"
msgstr "Qualität der MPEG-4 Nachbearbeitungsstufe"
-#: src/libffmpeg/ff_video_decoder.c:1517
+#: src/libffmpeg/ff_video_decoder.c:1515
msgid ""
"You can adjust the amount of post processing applied to MPEG-4 video.\n"
"Higher values result in better quality, but need more CPU. Lower values may "
@@ -2808,11 +2776,11 @@ msgstr ""
"kann zu starke Nachbearbeitung das Bild durch zu starkes verwischen "
"verschlechtern."
-#: src/libffmpeg/ffmpeg_encoder.c:167
+#: src/libffmpeg/ffmpeg_encoder.c:163
msgid "libavcodec mpeg output bitrate (kbit/s)"
msgstr "libavcodec MPEG Ausgangsbitrate (kBit/s)"
-#: src/libffmpeg/ffmpeg_encoder.c:168
+#: src/libffmpeg/ffmpeg_encoder.c:164
msgid ""
"The bitrate the libavcodec mpeg encoder should use for DXR3's encoding mode. "
"Higher values will increase quality and CPU usage.\n"
@@ -2823,11 +2791,11 @@ msgstr ""
"Diese Einstellung ist nur wirksam, wenn der Modus für konstante Qualität "
"deaktiviert ist."
-#: src/libffmpeg/ffmpeg_encoder.c:175
+#: src/libffmpeg/ffmpeg_encoder.c:171
msgid "constant quality mode"
msgstr "Modus für konstante Qualität"
-#: src/libffmpeg/ffmpeg_encoder.c:176
+#: src/libffmpeg/ffmpeg_encoder.c:172
msgid ""
"When enabled, libavcodec will use a constant quality mode by dynamically "
"compressing the images based on their complexity. When disabled, libavcodec "
@@ -2837,37 +2805,37 @@ msgstr ""
"der Bilder je nach Komplexität dynamische komprimiert werden. Anderenfalls "
"benutzt libavcodec eine Modus mit konstanter Bitrate."
-#: src/libffmpeg/ffmpeg_encoder.c:183
+#: src/libffmpeg/ffmpeg_encoder.c:179
msgid "minimum compression"
msgstr "Minimale Kompression"
-#: src/libffmpeg/ffmpeg_encoder.c:184
+#: src/libffmpeg/ffmpeg_encoder.c:180
msgid "The minimum compression to apply to an image in constant quality mode."
msgstr "Minimale Kompression für ein Bild im Modus konstanter Qualität"
-#: src/libffmpeg/ffmpeg_encoder.c:189
+#: src/libffmpeg/ffmpeg_encoder.c:185
msgid "maximum quantizer"
msgstr "Maximaler Quantisierer"
-#: src/libffmpeg/ffmpeg_encoder.c:190
+#: src/libffmpeg/ffmpeg_encoder.c:186
msgid "The maximum compression to apply to an image in constant quality mode."
msgstr "Maximale Kompression für ein Bild im Modus konstanter Qualität"
-#: src/libmusepack/xine_musepack_decoder.c:241
+#: src/libxineadec/xine_musepack_decoder.c:249
#, c-format
msgid "libmusepack: mpc_streaminfo_read failed: %d\n"
msgstr "libmusepack: mpc_streaminfo_read schlug fehl: %d\n"
-#: src/libmusepack/xine_musepack_decoder.c:315
+#: src/libxineadec/xine_musepack_decoder.c:323
msgid "libmusepack: data after last frame ignored\n"
msgstr "libmusepack: Daten nach letzem Bild ignoriert\n"
-#: src/libmusepack/xine_musepack_decoder.c:326
+#: src/libxineadec/xine_musepack_decoder.c:334
msgid "libmusepack: mpc_decoder_initialise failed\n"
msgstr "libmusepack: mpc_decoder_initialise schlug fehl\n"
-#: src/libmusepack/xine_musepack_decoder.c:346
-#: src/libmusepack/xine_musepack_decoder.c:361
+#: src/libxineadec/xine_musepack_decoder.c:354
+#: src/libxineadec/xine_musepack_decoder.c:369
#, c-format
msgid "libmusepack: mpc_decoder_decode failed: %d\n"
msgstr "libmusepack: mpc_decoder_decode schlug fehl: %d\n"
@@ -3813,7 +3781,7 @@ msgid "Select the video output layer by its id."
msgstr "Wählt die Ausgabeebene für videos bei Id."
#: src/video_out/video_out_directfb.c:1804
-#: src/video_out/video_out_directfb.c:2013
+#: src/video_out/video_out_directfb.c:2014
#, c-format
msgid "video_out_directfb: using display layer #%d.\n"
msgstr "video_out_directfb: Benutze Anzeigenebene #%d.\n"
@@ -3822,11 +3790,11 @@ msgstr "video_out_directfb: Benutze Anzeigenebene #%d.\n"
msgid "xine video output plugin using DirectFB."
msgstr "xine Videoausgabe benutzt DirectFB"
-#: src/video_out/video_out_directfb.c:2006
+#: src/video_out/video_out_directfb.c:2007
msgid "video_out_directfb: no usable display layer was found!\n"
msgstr "video_out_directfb: Keine benutzbare Anzeigenebene gefunden!\n"
-#: src/video_out/video_out_directfb.c:2095
+#: src/video_out/video_out_directfb.c:2096
msgid "xine video output plugin using DirectFB under XDirectFB."
msgstr "xine Videoausgabe benutzt DirectFB unter XDirectFB"
@@ -3834,7 +3802,7 @@ msgstr "xine Videoausgabe benutzt DirectFB unter XDirectFB"
msgid "xine video output plugin for win32 using directx"
msgstr "xine Videoausgabe benutzt für win32 benutzt directx"
-#: src/video_out/video_out_fb.c:792
+#: src/video_out/video_out_fb.c:780
#, c-format
msgid ""
"video_out_fb: only packed truecolor/directcolor is supported (%d).\n"
@@ -3843,11 +3811,11 @@ msgstr ""
"video_out_fb: Nur packed truecolor/directcolor wird unterstützt (%d).\n"
" Überprüden Sie 'fbset -i' oder versuchen Sie 'fbset -depth 16'.\n"
-#: src/video_out/video_out_fb.c:852 src/video_out/video_out_vidix.c:1239
+#: src/video_out/video_out_fb.c:840 src/video_out/video_out_vidix.c:1239
msgid "framebuffer device name"
msgstr "Framebuffer Gerät"
-#: src/video_out/video_out_fb.c:853 src/video_out/video_out_vidix.c:1240
+#: src/video_out/video_out_fb.c:841 src/video_out/video_out_vidix.c:1240
msgid ""
"Specifies the file name for the framebuffer device to be used.\n"
"This setting is security critical, because when changed to a different file, "
@@ -3860,20 +3828,20 @@ msgstr ""
"sollten sich deshalb sehr sicher sein, daß Ihre Eingabe wirklich das "
"Framebuffer-Gerät bezeichnet."
-#: src/video_out/video_out_fb.c:927
-msgid "video_out_fb: Your video mode was not recognized, sorry.\n"
+#: src/video_out/video_out_fb.c:915
+#, fuzzy, c-format
+msgid "%s: Your video mode was not recognized, sorry.\n"
msgstr "video_out_fb: Ihr Videomodues wurde nicht erkannt, Entschuldigung.\n"
-#: src/video_out/video_out_fb.c:984
-#, c-format
-msgid "video_out_fb: %d video RAM buffers are available.\n"
+#: src/video_out/video_out_fb.c:972
+#, fuzzy, c-format
+msgid "%s: %d video RAM buffers are available.\n"
msgstr "video_out_fb: %d Video-Ram-Puffer sind verfügbar.\n"
-#: src/video_out/video_out_fb.c:990
-#, c-format
+#: src/video_out/video_out_fb.c:978
+#, fuzzy, c-format
msgid ""
-"WARNING: video_out_fb: Zero copy buffers are DISABLED because only %d "
-"buffers\n"
+"WARNING: %s: Zero copy buffers are DISABLED because only %d buffers\n"
" are available which is less than the recommended %d buffers. Lowering\n"
" the frame buffer resolution might help.\n"
msgstr ""
@@ -3883,26 +3851,29 @@ msgstr ""
"Verringern\n"
" der Framebuffer-Auflösung kann helfen.\n"
-#: src/video_out/video_out_fb.c:1001
+#: src/video_out/video_out_fb.c:989
+#, fuzzy, c-format
msgid ""
-"WARNING: video_out_fb: Zero copy buffers are DISABLED because kernel driver\n"
+"WARNING: %s: Zero copy buffers are DISABLED because kernel driver\n"
" do not support screen panning (used for frame flips).\n"
msgstr ""
"WARNUNG: video_out_fb: Null-Kopie-Puffer sind DEAKTIVIERT, weil der Kernel-"
"Treiber\n"
" kein screen-panning unterstützt (benutzt für Bildwechsel).\n"
-#: src/video_out/video_out_fb.c:1070
-#, c-format
+#: src/video_out/video_out_fb.c:1058
+#, fuzzy, c-format
msgid ""
-"WARNING: video_out_fb: current display depth is %d. For better performance\n"
+"WARNING: %s: current display depth is %d. For better performance\n"
" a depth of 16 bpp is recommended!\n"
"\n"
msgstr ""
-"WARNUNG: video_out_fb: Momentane Farbtiefe ist %d. Für bessere Leistung wird "
-"eine Farbtiefe von 16 bpp empfohlen!\n"
+"\n"
+"\n"
+"WARNUNG: Aktuelle Farbtiefe ist %d. Für bessere Leistung wird eine Farbtiefe "
+"von 16 bpp empfohlen!\n"
-#: src/video_out/video_out_fb.c:1101
+#: src/video_out/video_out_fb.c:1090
msgid "Xine video output plugin using the Linux frame buffer device"
msgstr "xine Videoausgabe benutzt Linux Framebuffer"
@@ -3983,8 +3954,8 @@ msgstr ""
"Ignoriert für statische Renderroutinen.\n"
#: src/video_out/video_out_opengl.c:1918 src/video_out/video_out_vidix.c:1015
-#: src/video_out/video_out_xcbxv.c:1472 src/video_out/video_out_xv.c:1486
-#: src/video_out/video_out_xvmc.c:1461 src/video_out/video_out_xxmc.c:2468
+#: src/video_out/video_out_xcbxv.c:1476 src/video_out/video_out_xv.c:1489
+#: src/video_out/video_out_xvmc.c:1461 src/video_out/video_out_xxmc.c:2465
msgid "enable double buffering"
msgstr "Doppelpufferung benutzen"
@@ -4073,9 +4044,9 @@ msgstr ""
msgid "video_out_pgx64: Error: ioctl failed (FBIOGATTR)\n"
msgstr "video_out_pgx64: Fehler: ioctl(FBIOGATTR) schlug fehl\n"
-#: src/video_out/video_out_pgx64.c:1464 src/video_out/video_out_xcbxv.c:1439
-#: src/video_out/video_out_xv.c:1453 src/video_out/video_out_xvmc.c:1446
-#: src/video_out/video_out_xxmc.c:2435
+#: src/video_out/video_out_pgx64.c:1464 src/video_out/video_out_xcbxv.c:1443
+#: src/video_out/video_out_xv.c:1456 src/video_out/video_out_xvmc.c:1446
+#: src/video_out/video_out_xxmc.c:2432
msgid "video overlay colour key"
msgstr "Farbschlüssel für Overlay"
@@ -4249,9 +4220,9 @@ msgstr "Blau-Intensität"
msgid "The intensity of the blue colour components."
msgstr "Die Intensität blauer Farbanteile"
-#: src/video_out/video_out_vidix.c:1016 src/video_out/video_out_xcbxv.c:1473
-#: src/video_out/video_out_xv.c:1487 src/video_out/video_out_xvmc.c:1462
-#: src/video_out/video_out_xxmc.c:2469
+#: src/video_out/video_out_vidix.c:1016 src/video_out/video_out_xcbxv.c:1477
+#: src/video_out/video_out_xv.c:1490 src/video_out/video_out_xvmc.c:1462
+#: src/video_out/video_out_xxmc.c:2466
msgid ""
"Double buffering will synchronize the update of the video image to the "
"repainting of the entire screen (\"vertical retrace\"). This eliminates "
@@ -4287,9 +4258,9 @@ msgid "video overlay colour key red component"
msgstr "Rot-Komponente des Farbschlüssels für Overlays"
#: src/video_out/video_out_vidix.c:1159 src/video_out/video_out_vidix.c:1166
-#: src/video_out/video_out_vidix.c:1173 src/video_out/video_out_xcbxv.c:1440
-#: src/video_out/video_out_xv.c:1454 src/video_out/video_out_xvmc.c:1447
-#: src/video_out/video_out_xxmc.c:2436
+#: src/video_out/video_out_vidix.c:1173 src/video_out/video_out_xcbxv.c:1444
+#: src/video_out/video_out_xv.c:1457 src/video_out/video_out_xvmc.c:1447
+#: src/video_out/video_out_xxmc.c:2433
msgid ""
"The colour key is used to tell the graphics card where to overlay the video "
"image. Try different values, if you experience windows becoming transparent."
@@ -4314,34 +4285,40 @@ msgstr "xine Videoausgabe benutzt libvidix für X11"
msgid "xine video output plugin using libvidix for linux frame buffer"
msgstr "xine Videoausgabe benutzt libvidix für Linux Framebuffer"
-#: src/video_out/video_out_xcbshm.c:157
+#: src/video_out/video_out_xcbshm.c:157 src/video_out/video_out_xshm.c:219
#, c-format
-msgid ""
-"video_out_xcbshm: %s: allocating image\n"
-"video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+msgid "%s: %s: allocating image\n"
msgstr ""
-"video_out_xcbshm: %s: Belege Bild\n"
-"video_out_xcbshm: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
-#: src/video_out/video_out_xcbshm.c:166
-msgid ""
-"video_out_xcbshm: shared memory error (address error) when allocating "
-"image \n"
-"video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbshm.c:159 src/video_out/video_out_xcbshm.c:169
+#: src/video_out/video_out_xcbshm.c:181 src/video_out/video_out_xcbxv.c:272
+#: src/video_out/video_out_xcbxv.c:282 src/video_out/video_out_xcbxv.c:292
+#: src/video_out/video_out_xcbxv.c:304 src/video_out/video_out_xshm.c:204
+#: src/video_out/video_out_xshm.c:221 src/video_out/video_out_xshm.c:232
+#: src/video_out/video_out_xshm.c:251 src/video_out/video_out_xv.c:296
+#: src/video_out/video_out_xv.c:307 src/video_out/video_out_xv.c:316
+#: src/video_out/video_out_xv.c:352 src/video_out/video_out_xxmc.c:648
+#: src/video_out/video_out_xxmc.c:659 src/video_out/video_out_xxmc.c:668
+#: src/video_out/video_out_xxmc.c:704
+#, fuzzy, c-format
+msgid "%s: => not using MIT Shared Memory extension.\n"
+msgstr "xine Videoausgabe benutzt 'MIX X Shared Memory' Erweiterung"
+
+#: src/video_out/video_out_xcbshm.c:167 src/video_out/video_out_xshm.c:230
+#, fuzzy, c-format
+msgid "%s: shared memory error (address error) when allocating image \n"
msgstr ""
-"video_out_xcbshm: Shared-Memory-Fehler (Adressfehler) beim Belegen des "
-"Bilds\n"
-"video_out_xcbshm: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
+"video_out_xshm: Shared-Memory-Fehler (Adressfehler) beim Belegen des Bilds\n"
+"video_out_xshm: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
-#: src/video_out/video_out_xcbshm.c:177
-msgid ""
-"video_out_xcbshm: x11 error during shared memory XImage creation\n"
-"video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbshm.c:179 src/video_out/video_out_xcbxv.c:302
+#: src/video_out/video_out_xshm.c:249 src/video_out/video_out_xv.c:350
+#: src/video_out/video_out_xxmc.c:702
+#, c-format
+msgid "%s: x11 error during shared memory XImage creation\n"
msgstr ""
-"video_out_xcbshm: X11-Fehler bei Shared-Memory-XImage-Erstellung\n"
-"video_out_xcbshm: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
-#: src/video_out/video_out_xcbshm.c:1100 src/video_out/video_out_xshm.c:1157
+#: src/video_out/video_out_xcbshm.c:1103 src/video_out/video_out_xshm.c:1161
#, c-format
msgid ""
"\n"
@@ -4355,87 +4332,81 @@ msgstr ""
"WARNUNG: Aktuelle Farbtiefe ist %d. Für bessere Leistung wird eine Farbtiefe "
"von 16 bpp empfohlen!\n"
-#: src/video_out/video_out_xcbshm.c:1113
-msgid "video_out_xcbshm: MIT shared memory extension not present on display.\n"
+#: src/video_out/video_out_xcbshm.c:1116 src/video_out/video_out_xshm.c:1174
+#, fuzzy, c-format
+msgid "%s: MIT shared memory extension not present on display.\n"
msgstr ""
-"video_out_xcbshm: MIT-Shared-Memory-Erweiterung für Anzeige nicht "
-"vorhanden.\n"
+"video_out_xshm: MIT-Shared-Memory-Erweiterung für Anzeige nicht vorhanden.\n"
-#: src/video_out/video_out_xcbshm.c:1212
-msgid "video_out_xcbshm: your video mode was not recognized, sorry :-(\n"
-msgstr ""
-"video_out_xcbshm: Der Videomodus wurde nicht erkannt, Entschuldigung :-(\n"
+#: src/video_out/video_out_xcbshm.c:1215 src/video_out/video_out_xshm.c:1258
+#, fuzzy, c-format
+msgid "%s: your video mode was not recognized, sorry :-(\n"
+msgstr "video_out_fb: Ihr Videomodues wurde nicht erkannt, Entschuldigung.\n"
-#: src/video_out/video_out_xcbshm.c:1242 src/video_out/video_out_xshm.c:1303
+#: src/video_out/video_out_xcbshm.c:1245 src/video_out/video_out_xshm.c:1307
msgid "xine video output plugin using the MIT X shared memory extension"
msgstr "xine Videoausgabe benutzt 'MIX X Shared Memory' Erweiterung"
-#: src/video_out/video_out_xcbxv.c:272
-msgid ""
-"video_out_xcbxv: XvShmCreateImage returned a zero size\n"
-"video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbxv.c:270 src/video_out/video_out_xv.c:305
+#: src/video_out/video_out_xxmc.c:657
+#, c-format
+msgid "%s: XvShmCreateImage returned a zero size\n"
msgstr ""
-"video_out_xcbv: XvShmCreateImage lieferte Größe 0 zurück\n"
-"video_out_xcbv: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
-#: src/video_out/video_out_xcbxv.c:281
+#: src/video_out/video_out_xcbxv.c:280 src/video_out/video_out_xv.c:314
+#: src/video_out/video_out_xxmc.c:666
#, c-format
-msgid ""
-"video_out_xcbxv: shared memory error in shmget: %s\n"
-"video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+msgid "%s: shared memory error in shmget: %s\n"
msgstr ""
-"video_out_xcbxv: Shared-Memory-Fehler bei shmget: %s\n"
-"video_out_xcbxv: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
-#: src/video_out/video_out_xcbxv.c:300
-msgid ""
-"video_out_xcbxv: x11 error during shared memory XImage creation\n"
-"video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbxv.c:290
+#, c-format
+msgid "%s: shared memory error (address error)\n"
msgstr ""
-"video_out_xcbxv: X11-Fehler bei Shared-Memory-XImage-Erstellung\n"
-"video_out_xcbxv: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
-#: src/video_out/video_out_xcbxv.c:1291
-msgid "video_out_xcbxv: Xv extension not present.\n"
-msgstr "video_out_xcbxv: Xv-Erweiterung nicht vorhanden.\n"
+#: src/video_out/video_out_xcbxv.c:1294 src/video_out/video_out_xv.c:1301
+#: src/video_out/video_out_xxmc.c:2283
+#, fuzzy, c-format
+msgid "%s: Xv extension not present.\n"
+msgstr "video_out_xv: Xv-Erweiterung nicht vorhanden.\n"
-#: src/video_out/video_out_xcbxv.c:1333
+#: src/video_out/video_out_xcbxv.c:1336 src/video_out/video_out_xv.c:1338
+#: src/video_out/video_out_xxmc.c:2320
+#, fuzzy, c-format
msgid ""
-"video_out_xcbxv: Xv extension is present but I couldn't find a usable yuv12 "
-"port.\n"
-" Looks like your graphics hardware driver doesn't support "
-"Xv?!\n"
+"%s: Xv extension is present but I couldn't find a usable yuv12 port.\n"
+"\tLooks like your graphics hardware driver doesn't support Xv?!\n"
msgstr ""
-"video_out_xcbxv: Xv-Erweiterung ist vorhanden, aber es wurde kein "
-"benutzbarer YUV12-Port gefunden.\n"
+"video_out_xv: Xv-Erweiterung ist vorhanden, aber es wurde kein benutzparer "
+"YUV12-Port gefunden.\n"
" Unterstützt die Grafikhardware evtl. kein Xv?!\n"
-#: src/video_out/video_out_xcbxv.c:1341
-#, c-format
+#: src/video_out/video_out_xcbxv.c:1345
+#, fuzzy, c-format
msgid ""
-"video_out_xcbxv: using Xv port %d from adaptor %s for hardware colorspace "
-"conversion and scaling.\n"
+"%s: using Xv port %d from adaptor %s for hardware colorspace conversion and "
+"scaling.\n"
msgstr ""
-"video_out_xcbxv: Benutze Xv-Port %d von Adapter %s for Hardware-"
+"video_out_xv: Benutze Xv-Port %ld von Adapter %s for Hardware-"
"Farbraumtransformation und Skalierung.\n"
-#: src/video_out/video_out_xcbxv.c:1448 src/video_out/video_out_xv.c:1462
-#: src/video_out/video_out_xvmc.c:1455 src/video_out/video_out_xxmc.c:2444
+#: src/video_out/video_out_xcbxv.c:1452 src/video_out/video_out_xv.c:1465
+#: src/video_out/video_out_xvmc.c:1455 src/video_out/video_out_xxmc.c:2441
msgid "autopaint colour key"
msgstr "automatischer Farbschlüssel"
-#: src/video_out/video_out_xcbxv.c:1449 src/video_out/video_out_xv.c:1463
-#: src/video_out/video_out_xvmc.c:1456 src/video_out/video_out_xxmc.c:2445
+#: src/video_out/video_out_xcbxv.c:1453 src/video_out/video_out_xv.c:1466
+#: src/video_out/video_out_xvmc.c:1456 src/video_out/video_out_xxmc.c:2442
msgid "Make Xv autopaint its colorkey."
msgstr "Veranlasst Xv automatisch den Farbschlüssel zu zeichnen."
-#: src/video_out/video_out_xcbxv.c:1456 src/video_out/video_out_xv.c:1470
-#: src/video_out/video_out_xxmc.c:2452
+#: src/video_out/video_out_xcbxv.c:1460 src/video_out/video_out_xv.c:1473
+#: src/video_out/video_out_xxmc.c:2449
msgid "bilinear scaling mode"
msgstr "Bilinearer Skalierungsmodus"
-#: src/video_out/video_out_xcbxv.c:1457 src/video_out/video_out_xv.c:1471
-#: src/video_out/video_out_xxmc.c:2453
+#: src/video_out/video_out_xcbxv.c:1461 src/video_out/video_out_xv.c:1474
+#: src/video_out/video_out_xxmc.c:2450
msgid ""
"Selects the bilinear scaling mode for Permedia cards. The individual values "
"are:\n"
@@ -4461,30 +4432,34 @@ msgstr ""
"1 - horizontales lineares Filtern\n"
"2 - aktiviert volles bilineares Filtern"
-#: src/video_out/video_out_xcbxv.c:1509
-msgid "video_out_xcbxv: this adaptor supports the yv12 format.\n"
-msgstr "video_out_xcbxv: Adapter unterstützt YV12 Format.\n"
+#: src/video_out/video_out_xcbxv.c:1513 src/video_out/video_out_xv.c:1523
+#: src/video_out/video_out_xxmc.c:2506
+#, fuzzy, c-format
+msgid "%s: this adaptor supports the yv12 format.\n"
+msgstr "video_out_xv: Adapter unterstützt YV12 Format.\n"
-#: src/video_out/video_out_xcbxv.c:1514
-msgid "video_out_xcbxv: this adaptor supports the yuy2 format.\n"
-msgstr "video_out_xcbxv: Adapter unterstützt YUY2 Format.\n"
+#: src/video_out/video_out_xcbxv.c:1518 src/video_out/video_out_xv.c:1528
+#: src/video_out/video_out_xxmc.c:2511
+#, fuzzy, c-format
+msgid "%s: this adaptor supports the yuy2 format.\n"
+msgstr "video_out_xv: Adapter unterstützt YUY2 Format.\n"
-#: src/video_out/video_out_xcbxv.c:1522 src/video_out/video_out_xv.c:1547
-#: src/video_out/video_out_xxmc.c:2537
+#: src/video_out/video_out_xcbxv.c:1526 src/video_out/video_out_xv.c:1550
+#: src/video_out/video_out_xxmc.c:2534
msgid "pitch alignment workaround"
msgstr "pitch alignment Abhilfe"
-#: src/video_out/video_out_xcbxv.c:1523 src/video_out/video_out_xv.c:1548
-#: src/video_out/video_out_xxmc.c:2538
+#: src/video_out/video_out_xcbxv.c:1527 src/video_out/video_out_xv.c:1551
+#: src/video_out/video_out_xxmc.c:2535
msgid "Some buggy video drivers need a workaround to function properly."
msgstr "Einige fehlerhafte Videotreiber benötigen dies zur korrekten Funktion."
-#: src/video_out/video_out_xcbxv.c:1529 src/video_out/video_out_xv.c:1554
+#: src/video_out/video_out_xcbxv.c:1533 src/video_out/video_out_xv.c:1557
#: src/video_out/video_out_xvmc.c:1524
msgid "deinterlace method (deprecated)"
msgstr "Deinterlace-Methode (veraltet)"
-#: src/video_out/video_out_xcbxv.c:1530 src/video_out/video_out_xv.c:1555
+#: src/video_out/video_out_xcbxv.c:1534 src/video_out/video_out_xv.c:1558
#: src/video_out/video_out_xvmc.c:1525
msgid ""
"This config setting is deprecated. You should use the new deinterlacing post "
@@ -4556,118 +4531,30 @@ msgstr ""
"Verwischt das Bild vertikal, um Kammartefakte zu entfernen. Gute Resultate "
"bei mittlerer CPU-Auslastung."
-#: src/video_out/video_out_xcbxv.c:1584 src/video_out/video_out_xv.c:1628
-#: src/video_out/video_out_xxmc.c:2618
+#: src/video_out/video_out_xcbxv.c:1588 src/video_out/video_out_xv.c:1631
+#: src/video_out/video_out_xxmc.c:2615
msgid "xine video output plugin using the MIT X video extension"
msgstr "xine Videoausgabe benutzt 'MIX XVideo' Erweiterung"
#: src/video_out/video_out_xshm.c:202
-msgid ""
-"video_out_xshm: shared memory error when allocating image\n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xshm: Shared-Memory-Fehler beim Speicherbelegen\n"
-"video_out_xshm: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
-
-#: src/video_out/video_out_xshm.c:218
#, c-format
-msgid ""
-"video_out_xshm: %s: allocating image\n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
+msgid "%s: shared memory error when allocating image\n"
msgstr ""
-"video_out_xshm: %s: Belege Bild\n"
-"video_out_xshm: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
-#: src/video_out/video_out_xshm.c:228
-msgid ""
-"video_out_xshm: shared memory error (address error) when allocating image \n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xshm: Shared-Memory-Fehler (Adressfehler) beim Belegen des Bilds\n"
-"video_out_xshm: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
-
-#: src/video_out/video_out_xshm.c:245
-msgid ""
-"video_out_xshm: x11 error during shared memory XImage creation\n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xshm: X11-Fehler bei Shared-Memory-XImage-Erstellung\n"
-"video_out_xshm: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
-
-#: src/video_out/video_out_xshm.c:1170
-msgid "video_out_xshm: MIT shared memory extension not present on display.\n"
-msgstr ""
-"video_out_xshm: MIT-Shared-Memory-Erweiterung für Anzeige nicht vorhanden.\n"
-
-#: src/video_out/video_out_xshm.c:1254
-msgid "video_out_xshm: your video mode was not recognized, sorry :-(\n"
-msgstr ""
-"video_out_xshm: Der Videomodus wurde nicht erkannt, Entschuldigung :-(\n"
-
-#: src/video_out/video_out_xv.c:296
-msgid ""
-"video_out_xv: XvShmCreateImage failed\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xv: XvShmCreateImage schlug fehl\n"
-"video_out_xv: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
-
-#: src/video_out/video_out_xv.c:306
-msgid ""
-"video_out_xv: XvShmCreateImage returned a zero size\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xv: XvShmCreateImage lieferte Größe 0 zurück\n"
-"video_out_xv: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
-
-#: src/video_out/video_out_xv.c:314
+#: src/video_out/video_out_xv.c:294 src/video_out/video_out_xxmc.c:646
#, c-format
-msgid ""
-"video_out_xv: shared memory error in shmget: %s\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xv: Shared-Memory-Fehler bei shmget: %s\n"
-"video_out_xv: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
-
-#: src/video_out/video_out_xv.c:346
-msgid ""
-"video_out_xv: x11 error during shared memory XImage creation\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xv: X11-Fehler bei Shared-Memory-XImage-Erstellung\n"
-"video_out_xv: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
-
-#: src/video_out/video_out_xv.c:1299
-msgid "video_out_xv: Xv extension not present.\n"
-msgstr "video_out_xv: Xv-Erweiterung nicht vorhanden.\n"
-
-#: src/video_out/video_out_xv.c:1336
-msgid ""
-"video_out_xv: Xv extension is present but I couldn't find a usable yuv12 "
-"port.\n"
-" Looks like your graphics hardware driver doesn't support Xv?!\n"
+msgid "%s: XvShmCreateImage failed\n"
msgstr ""
-"video_out_xv: Xv-Erweiterung ist vorhanden, aber es wurde kein benutzparer "
-"YUV12-Port gefunden.\n"
-" Unterstützt die Grafikhardware evtl. kein Xv?!\n"
-#: src/video_out/video_out_xv.c:1345
-#, c-format
+#: src/video_out/video_out_xv.c:1348 src/video_out/video_out_xxmc.c:2330
+#, fuzzy, c-format
msgid ""
-"video_out_xv: using Xv port %ld from adaptor %s for hardware colorspace "
-"conversion and scaling.\n"
+"%s: using Xv port %ld from adaptor %s for hardware colorspace conversion and "
+"scaling.\n"
msgstr ""
"video_out_xv: Benutze Xv-Port %ld von Adapter %s for Hardware-"
"Farbraumtransformation und Skalierung.\n"
-#: src/video_out/video_out_xv.c:1520
-msgid "video_out_xv: this adaptor supports the yv12 format.\n"
-msgstr "video_out_xv: Adapter unterstützt YV12 Format.\n"
-
-#: src/video_out/video_out_xv.c:1525
-msgid "video_out_xv: this adaptor supports the yuy2 format.\n"
-msgstr "video_out_xv: Adapter unterstützt YUY2 Format.\n"
-
#: src/video_out/video_out_xvmc.c:1593
msgid "xine video output plugin using the XvMC X video extension"
msgstr "xine Videoausgabe benutzt XvMC XVideo-Erweiterung"
@@ -4710,75 +4597,11 @@ msgstr " Keine XvMC-Unterstützung \n"
msgid " With Overlay = %d; UnsignedIntra = %d.\n"
msgstr " Mit Überlagerung = %d; UnsignedIntra = %d.\n"
-#: src/video_out/video_out_xxmc.c:650
-msgid ""
-"video_out_xxmc: XvShmCreateImage failed\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xxmc: XvShmCreateImage schlug fehl\n"
-"video_out_xxmc: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
-
-#: src/video_out/video_out_xxmc.c:660
-msgid ""
-"video_out_xxmc: XvShmCreateImage returned a zero size\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xv: XvShmCreateImage lieferte Größe 0 zurück\n"
-"video_out_xv: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
-
-#: src/video_out/video_out_xxmc.c:668
-#, c-format
-msgid ""
-"video_out_xxmc: shared memory error in shmget: %s\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xxmc: Shared-Memory-Fehler bei shmget: %s\n"
-"video_out_xxmc: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
-
-#: src/video_out/video_out_xxmc.c:700
-msgid ""
-"video_out_xxmc: x11 error during shared memory XImage creation\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xxmc: X11-Fehler bei Shared-Memory-XImage-Erstellung\n"
-"video_out_xxmc: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
-
-#: src/video_out/video_out_xxmc.c:2287
-msgid "video_out_xxmc: Xv extension not present.\n"
-msgstr "video_out_xxmc: Xv-Erweiterung nicht vorhanden.\n"
-
-#: src/video_out/video_out_xxmc.c:2324
-msgid ""
-"video_out_xxmc: Xv extension is present but I couldn't find a usable yuv12 "
-"port.\n"
-" Looks like your graphics hardware driver doesn't support Xv?!\n"
-msgstr ""
-"video_out_xxmc: Xv-Erweiterung ist vorhanden, aber es wurde kein benutzparer "
-"YUV12-Port gefunden.\n"
-" Unterstützt die Grafikhardware evtl. kein Xv?!\n"
-
-#: src/video_out/video_out_xxmc.c:2333
-#, c-format
-msgid ""
-"video_out_xxmc: using Xv port %ld from adaptor %s for hardware colorspace "
-"conversion and scaling.\n"
-msgstr ""
-"video_out_xxmc: Benutze Xv-Port %ld von Adapter %s for Hardware-"
-"Farbraumtransformation und Skalierung.\n"
-
-#: src/video_out/video_out_xxmc.c:2509
-msgid "video_out_xxmc: this adaptor supports the yv12 format.\n"
-msgstr "video_out_xxmc: Adapter unterstützt YV12 Format.\n"
-
-#: src/video_out/video_out_xxmc.c:2514
-msgid "video_out_xxmc: this adaptor supports the yuy2 format.\n"
-msgstr "video_out_xxmc: Adapter unterstützt YUY2 Format.\n"
-
-#: src/video_out/video_out_xxmc.c:2543
+#: src/video_out/video_out_xxmc.c:2540
msgid "Make XvMC allocate more frames for better buffering."
msgstr "XvMC belegt zur besseren Pufferung mehr Bildspeicher."
-#: src/video_out/video_out_xxmc.c:2544
+#: src/video_out/video_out_xxmc.c:2541
msgid ""
"Some XvMC implementations allow more than 8 frames.\n"
"This option, when turned on, makes the driver try to\n"
@@ -4788,11 +4611,11 @@ msgstr ""
"Diese Option, wenn ausgewählt, veranlasst den Treiber 15\n"
"Bilder zu belegen. Ein Muß für Unichrome oder live VDR.\n"
-#: src/video_out/video_out_xxmc.c:2550
+#: src/video_out/video_out_xxmc.c:2547
msgid "Unichrome cpu save"
msgstr "Unichrome Prozessorschoner"
-#: src/video_out/video_out_xxmc.c:2551
+#: src/video_out/video_out_xxmc.c:2548
msgid ""
"Saves CPU time by sleeping while decoder works.\n"
"Only for Linux kernel 2.6 series or 2.4 with multimedia patch.\n"
@@ -4803,11 +4626,11 @@ msgstr ""
"Patch.\n"
"Experimentell.\n"
-#: src/video_out/video_out_xxmc.c:2557
+#: src/video_out/video_out_xxmc.c:2554
msgid "Fix buggy NVIDIA XvMC subpicture colors"
msgstr "Behebe NVIDIA XvMV Subpicture-Farbfehler"
-#: src/video_out/video_out_xxmc.c:2558
+#: src/video_out/video_out_xxmc.c:2555
msgid ""
"There's a bug in NVIDIA's XvMC lib that makes red OSD colors\n"
"look blue and vice versa. This option provides a workaround.\n"
@@ -4816,11 +4639,11 @@ msgstr ""
"blau darstellt und umgekehrt. Diese Option liefert eine provisorische "
"Lösung.\n"
-#: src/video_out/video_out_xxmc.c:2563
+#: src/video_out/video_out_xxmc.c:2560
msgid "Use bob as accelerated deinterlace method."
msgstr "Benutze BOB als beschleunigte Deinterlacingmethode."
-#: src/video_out/video_out_xxmc.c:2564
+#: src/video_out/video_out_xxmc.c:2561
msgid ""
"When interlacing is enabled for hardware accelerated frames,\n"
"Alternate between top and bottom field at double the frame rate.\n"
@@ -5104,12 +4927,12 @@ msgstr ""
"info_helper: Nichtunterstützte Konvertierung %s -> UTF-8, keine "
"Konvertierung durchgeführt\n"
-#: src/xine-engine/input_cache.c:167
+#: src/xine-engine/input_cache.c:171
#, c-format
msgid ": open() function should never be called\n"
msgstr ": open()-Funktion sollte niemals aufgerufen werden\n"
-#: src/xine-engine/input_cache.c:349
+#: src/xine-engine/input_cache.c:353
#, c-format
msgid ": input plugin not defined!\n"
msgstr ": Input-Plugin nicht definiert!\n"
@@ -5224,12 +5047,12 @@ msgstr "io_helper: Datei nicht gefunden\n"
msgid "io_helper: Connection Refused\n"
msgstr "io_helper: Verbindung verweigert\n"
-#: src/xine-engine/load_plugins.c:212
+#: src/xine-engine/load_plugins.c:215
#, c-format
msgid "map_decoder_list: no space for decoder, skipped.\n"
msgstr "map_decoder_list: Kein Platz für Dekoder, übersprungen.\n"
-#: src/xine-engine/load_plugins.c:327
+#: src/xine-engine/load_plugins.c:330
#, c-format
msgid ""
"load_plugins: ignoring plugin %s, wrong iface version %d (should be %d)\n"
@@ -5237,12 +5060,12 @@ msgstr ""
"load_plugins: Ignoriere Plugin %s, falsche iface-Version %d (sollte %d "
"sein)\n"
-#: src/xine-engine/load_plugins.c:384
+#: src/xine-engine/load_plugins.c:387
#, c-format
msgid "priority for %s decoder"
msgstr "Priorität für Dekoder %s"
-#: src/xine-engine/load_plugins.c:395
+#: src/xine-engine/load_plugins.c:398
msgid ""
"The priority provides a ranking in case some media can be handled by more "
"than one decoder.\n"
@@ -5252,7 +5075,7 @@ msgstr ""
"Dekoder behandelt werden können.\n"
"Eine Priorität von 0 aktiviert den Dekoder mit seiner Standardpriorität."
-#: src/xine-engine/load_plugins.c:423
+#: src/xine-engine/load_plugins.c:426
#, c-format
msgid ""
"load_plugins: demuxer plugin %s does not provide a priority, xine-lib will "
@@ -5261,7 +5084,7 @@ msgstr ""
"load_plugins: Demultiplexer-Plugin %s liefert keine Priorität, xine-lib "
"benutzt die Standardpriorität.\n"
-#: src/xine-engine/load_plugins.c:440
+#: src/xine-engine/load_plugins.c:443
#, c-format
msgid ""
"load_plugins: input plugin %s does not provide a priority, xine-lib will use "
@@ -5270,44 +5093,44 @@ msgstr ""
"load_plugins: Input-Plugin %s liefert keine Priorität, xine-lib benutzt die "
"Standardpriorität.\n"
-#: src/xine-engine/load_plugins.c:496
+#: src/xine-engine/load_plugins.c:499
#, c-format
msgid "load_plugins: plugin %s found\n"
msgstr "load_plugins: Plugin %s gefunden\n"
-#: src/xine-engine/load_plugins.c:499
+#: src/xine-engine/load_plugins.c:502
#, c-format
msgid "load_plugins: static plugin found\n"
msgstr "load_plugins: statisches Plugin gefunden\n"
-#: src/xine-engine/load_plugins.c:506
+#: src/xine-engine/load_plugins.c:509
#, c-format
msgid "load_plugins: plugin limit reached, %s could not be loaded\n"
msgstr "load_plugins: Plugingrenze erreicht, %s konnte nicht geladen werden\n"
-#: src/xine-engine/load_plugins.c:509
+#: src/xine-engine/load_plugins.c:512
#, c-format
msgid "load_plugins: plugin limit reached, static plugin could not be loaded\n"
msgstr ""
"load_plugins: Plugingrenze erreicht, statisches Plugin konnte nicht geladen "
"werden\n"
-#: src/xine-engine/load_plugins.c:526
+#: src/xine-engine/load_plugins.c:529
#, c-format
msgid "load_plugins: unknown plugin type %d in %s\n"
msgstr "load_plugins: Unbekannter Plugintyp %d in %s\n"
-#: src/xine-engine/load_plugins.c:530
+#: src/xine-engine/load_plugins.c:533
#, c-format
msgid "load_plugins: unknown statically linked plugin type %d\n"
msgstr "load_plugins: Unbekannter statisch eingebundener Plugintyp %d\n"
-#: src/xine-engine/load_plugins.c:590
+#: src/xine-engine/load_plugins.c:593
#, c-format
msgid "load_plugins: unable to stat %s\n"
msgstr "load_plugins: Kann %s nicht untersuchen\n"
-#: src/xine-engine/load_plugins.c:631
+#: src/xine-engine/load_plugins.c:634
#, c-format
msgid ""
"load_plugins: cannot open plugin lib %s:\n"
@@ -5316,7 +5139,7 @@ msgstr ""
"load_plugins: Kann Pluginbibliothek %s nicht öffnen:\n"
"%s\n"
-#: src/xine-engine/load_plugins.c:646
+#: src/xine-engine/load_plugins.c:649
#, c-format
msgid ""
"load_plugins: can't get plugin info from %s:\n"
@@ -5325,12 +5148,12 @@ msgstr ""
"load_plugins: Kann Plugininformation von %s nicht lesen:\n"
"%s\n"
-#: src/xine-engine/load_plugins.c:664
+#: src/xine-engine/load_plugins.c:667
#, c-format
msgid "load_plugins: skipping unreadable plugin directory %s.\n"
msgstr "load_plugins: Überspringe unlesbares Pluginverzeichnis %s.\n"
-#: src/xine-engine/load_plugins.c:713
+#: src/xine-engine/load_plugins.c:716
#, c-format
msgid ""
"load_plugins: cannot (stage 2) open plugin lib %s:\n"
@@ -5339,27 +5162,32 @@ msgstr ""
"load_plugins: (Stufe 2) Kann Pluginbibliothek %s nicht öffnen:\n"
"%s\n"
-#: src/xine-engine/load_plugins.c:739
+#: src/xine-engine/load_plugins.c:742
#, c-format
msgid "load_plugins: Yikes! %s doesn't contain plugin info.\n"
msgstr "load_plugins: Dreck! %s enthält keine Plugininformation.\n"
-#: src/xine-engine/load_plugins.c:1305
+#: src/xine-engine/load_plugins.c:1104 src/xine-engine/load_plugins.c:1113
+#, fuzzy, c-format
+msgid "Unable to create %s directory: %s\n"
+msgstr "Kann DirectSound-Objekt nicht erzeugen."
+
+#: src/xine-engine/load_plugins.c:1345
#, c-format
msgid "load_plugins: unknown content detection strategy %d\n"
msgstr "load_plugins: Unbekannte Inhaltserkennungsstrategie %d\n"
-#: src/xine-engine/load_plugins.c:1415
+#: src/xine-engine/load_plugins.c:1455
#, c-format
msgid "load_plugins: using demuxer '%s'\n"
msgstr "load_plugins: Benutze Demultiplexer '%s'\n"
-#: src/xine-engine/load_plugins.c:1726
+#: src/xine-engine/load_plugins.c:1766
#, c-format
msgid "load_plugins: failed to load audio output plugin <%s>\n"
msgstr "load_plugins: Audio-Plugin <%s> konnte nicht geladen werden\n"
-#: src/xine-engine/load_plugins.c:1729
+#: src/xine-engine/load_plugins.c:1769
msgid ""
"load_plugins: audio output auto-probing didn't find any usable audio "
"driver.\n"
@@ -5367,7 +5195,7 @@ msgstr ""
"load_plugins: Suche nach Audio-Ausgabe fand keinen benutzbaren "
"Audiotreiber.\n"
-#: src/xine-engine/load_plugins.c:2033
+#: src/xine-engine/load_plugins.c:2073
#, c-format
msgid ""
"load_plugins: cannot unload plugin lib %s:\n"
@@ -5376,31 +5204,27 @@ msgstr ""
"load_plugins: Kann Pluginbibliothek %s nicht entladen:\n"
"%s\n"
-#: src/xine-engine/osd.c:745
+#: src/xine-engine/osd.c:747
#, c-format
msgid "font '%s-%d' already loaded, weird.\n"
msgstr "Zeichensatz '%s-%d' bereits geladen, seltsam.\n"
-#: src/xine-engine/osd.c:757
+#: src/xine-engine/osd.c:759
#, c-format
msgid "font '%s' loading failed (%d < %d)\n"
msgstr "Laden des Zeichensatzs '%s' schlug fehl (%d <%d)\n"
-#: src/xine-engine/osd.c:767
+#: src/xine-engine/osd.c:769
#, c-format
msgid "wrong version for font '%s'. expected %d found %d.\n"
msgstr "Falsche Version von Zeichensatz '%s'. Erwartet %d gefunden %d.\n"
-#: src/xine-engine/osd.c:834
-msgid "osd: cannot initialize ft2 library\n"
-msgstr "osd: Kann ft2-Bibliothek nicht initialisieren\n"
-
-#: src/xine-engine/osd.c:857
+#: src/xine-engine/osd.c:856
#, c-format
msgid "osd: error matching font %s with FontConfig"
msgstr "osd: Fehler beim Suchen des Zeichensatzes %s mit FontConfig"
-#: src/xine-engine/osd.c:871
+#: src/xine-engine/osd.c:870
#, c-format
msgid "osd: error loading font %s with FontConfig"
msgstr "osd: Fehler beim Laden des Zeichensatzes %s mit FontConfig"
@@ -5410,18 +5234,22 @@ msgstr "osd: Fehler beim Laden des Zeichensatzes %s mit FontConfig"
msgid "osd: error looking up font %s with FontConfig"
msgstr "osd: Fehler beim Zusammenstellen des Zeichensatzes %s mit FontConfig"
-#: src/xine-engine/osd.c:895
-#, c-format
-msgid "osd: error loading font %s with ft2\n"
+#: src/xine-engine/osd.c:914
+#, fuzzy, c-format
+msgid "osd: error loading font %s with in XDG data directories.\n"
msgstr "osd: Fehler beim Laden des Zeichensatzes %s mit ft2\n"
-#: src/xine-engine/osd.c:905
+#: src/xine-engine/osd.c:923
+msgid "osd: cannot initialize ft2 library\n"
+msgstr "osd: Kann ft2-Bibliothek nicht initialisieren\n"
+
+#: src/xine-engine/osd.c:945
msgid "osd: error setting font size (no scalable font?)\n"
msgstr ""
"osd: Fehler beim Setzen der Zeichensatzgröße (kein skalierbarer "
"Zeichensatz?)\n"
-#: src/xine-engine/osd.c:1021
+#: src/xine-engine/osd.c:1061
#, c-format
msgid ""
"osd: unknown sequence starting with byte 0x%02X in encoding \"%s\", "
@@ -5430,43 +5258,43 @@ msgstr ""
"osd: Unbekannte Sequenz startet mit Byte 0x%02X in Kodierung \"%s\", "
"überspringe\n"
-#: src/xine-engine/osd.c:1077
+#: src/xine-engine/osd.c:1117
msgid "osd: can't find out current locale character set\n"
msgstr "osd: Kann locale-Zeichensatz nicht erkennen\n"
-#: src/xine-engine/osd.c:1087
+#: src/xine-engine/osd.c:1127
#, c-format
msgid "osd: unsupported conversion %s -> %s, no conversion performed\n"
msgstr ""
"osd: Nichtunterstützte Konvertierung %s -> %s, keine Konvertierung "
"durchgeführt\n"
-#: src/xine-engine/osd.c:1142 src/xine-engine/osd.c:1310
+#: src/xine-engine/osd.c:1182 src/xine-engine/osd.c:1350
msgid "osd: font isn't defined\n"
msgstr "osd: Zeichensatz nicht definiert\n"
-#: src/xine-engine/osd.c:1181
+#: src/xine-engine/osd.c:1221
msgid "osd: error loading glyph\n"
msgstr "osd: Fehler beim Laden von Bildzeichen\n"
-#: src/xine-engine/osd.c:1187
+#: src/xine-engine/osd.c:1227
msgid "osd: error in rendering glyph\n"
msgstr "osd: Fehler beim Darstellen von Bildzeichen\n"
-#: src/xine-engine/osd.c:1347
+#: src/xine-engine/osd.c:1387
#, c-format
msgid "osd: error loading glyph %i\n"
msgstr "osd: Fehler beim Laden des Bildzeichens %i\n"
-#: src/xine-engine/osd.c:1354
+#: src/xine-engine/osd.c:1394
msgid "osd: error in rendering\n"
msgstr "osd: Fehler beim Darstellen\n"
-#: src/xine-engine/osd.c:1611
+#: src/xine-engine/osd.c:1660
msgid "palette (foreground-border-background) to use for subtitles and OSD"
msgstr "Farbpalette (Vordergrund-Rand-Hintergrund) für Untertitel und OSD"
-#: src/xine-engine/osd.c:1612
+#: src/xine-engine/osd.c:1661
msgid ""
"The palette for on-screen-display and some subtitle formats that do not "
"specify any colouring themselves. The palettes are listed in the form: "
@@ -5614,127 +5442,127 @@ msgstr ""
"einige Videoausgabetreiber wie XShm davon, deren Bildskalierung nicht "
"hardwarebeschleunigt ist, wodurch die CPU-Auslastung drastisch sinkt."
-#: src/xine-engine/xine.c:704 src/xine-engine/xine.c:811
-#: src/xine-engine/xine.c:850 src/xine-engine/xine.c:886
-#: src/xine-engine/xine.c:898 src/xine-engine/xine.c:911
-#: src/xine-engine/xine.c:924 src/xine-engine/xine.c:937
-#: src/xine-engine/xine.c:963 src/xine-engine/xine.c:988
-#: src/xine-engine/xine.c:1023
+#: src/xine-engine/xine.c:706 src/xine-engine/xine.c:813
+#: src/xine-engine/xine.c:852 src/xine-engine/xine.c:888
+#: src/xine-engine/xine.c:900 src/xine-engine/xine.c:913
+#: src/xine-engine/xine.c:926 src/xine-engine/xine.c:939
+#: src/xine-engine/xine.c:965 src/xine-engine/xine.c:990
+#: src/xine-engine/xine.c:1025
msgid "xine: error while parsing mrl\n"
msgstr "xine: Fehler beim Parsen der MRL\n"
-#: src/xine-engine/xine.c:740
+#: src/xine-engine/xine.c:742
#, c-format
msgid "xine: found input plugin : %s\n"
msgstr "xine: Inputplugin gefunden: %s\n"
-#: src/xine-engine/xine.c:758
+#: src/xine-engine/xine.c:760
#, c-format
msgid "xine: input plugin cannot open MRL [%s]\n"
msgstr "xine: Plugin kann MRL [%s] nicht öffnen\n"
-#: src/xine-engine/xine.c:774
+#: src/xine-engine/xine.c:776
#, c-format
msgid "xine: cannot find input plugin for MRL [%s]\n"
msgstr "xine: Kann kein Plugin für MRL [%s] finden\n"
-#: src/xine-engine/xine.c:800
+#: src/xine-engine/xine.c:802
#, c-format
msgid "xine: specified demuxer %s failed to start\n"
msgstr "xine: Demultiplexer-Plugins %s startete nicht\n"
-#: src/xine-engine/xine.c:836
+#: src/xine-engine/xine.c:838
#, c-format
msgid "xine: join rip input plugin\n"
msgstr "xine: Join rip Plugin\n"
-#: src/xine-engine/xine.c:843
+#: src/xine-engine/xine.c:845
msgid "xine: error opening rip input plugin instance\n"
msgstr "xine: Fehler beim Öffnen einer RIP-Plugin-Instanz\n"
-#: src/xine-engine/xine.c:874
+#: src/xine-engine/xine.c:876
#, c-format
msgid "xine: last_probed demuxer %s failed to start\n"
msgstr "xine: Letztes Demultiplexer-Plugins %s startete nicht\n"
-#: src/xine-engine/xine.c:903
+#: src/xine-engine/xine.c:905
msgid "ignoring video\n"
msgstr "Ignoriere Video\n"
-#: src/xine-engine/xine.c:916
+#: src/xine-engine/xine.c:918
msgid "ignoring audio\n"
msgstr "Ignoriere Audio\n"
-#: src/xine-engine/xine.c:929
+#: src/xine-engine/xine.c:931
msgid "ignoring subpicture\n"
msgstr "Ignoriere Untertitel\n"
-#: src/xine-engine/xine.c:942
+#: src/xine-engine/xine.c:944
msgid "input cache plugin disabled\n"
msgstr "Input-Cache Plugin deaktiviert\n"
-#: src/xine-engine/xine.c:1013
+#: src/xine-engine/xine.c:1015
#, c-format
msgid "subtitle mrl opened '%s'\n"
msgstr "Untertitel-MRL öffnet '%s'\n"
-#: src/xine-engine/xine.c:1017
+#: src/xine-engine/xine.c:1019
msgid "xine: error opening subtitle mrl\n"
msgstr "xine: Fehler beim Öffnen der Untertitel-MRL\n"
-#: src/xine-engine/xine.c:1049
+#: src/xine-engine/xine.c:1051
#, c-format
msgid "xine: error while parsing MRL\n"
msgstr "xine: Fehler beim parsen der MRL\n"
-#: src/xine-engine/xine.c:1056
+#: src/xine-engine/xine.c:1058
#, c-format
msgid "xine: changing option '%s' from MRL isn't permitted\n"
msgstr "xine: Das Ändern der Option '%s' per MRL ist verboten\n"
-#: src/xine-engine/xine.c:1076
+#: src/xine-engine/xine.c:1078
#, c-format
msgid "xine: couldn't find demux for >%s<\n"
msgstr "xine: Kann keinen Demultiplexer für >%s< finden\n"
-#: src/xine-engine/xine.c:1092
+#: src/xine-engine/xine.c:1094
#, c-format
msgid "xine: found demuxer plugin: %s\n"
msgstr "xine: Demultiplexer-Plugin gefunden: %s\n"
-#: src/xine-engine/xine.c:1112
+#: src/xine-engine/xine.c:1114
#, c-format
msgid "xine: demuxer failed to start\n"
msgstr "xine: Demultiplexer-Plugins startete nicht\n"
-#: src/xine-engine/xine.c:1177
+#: src/xine-engine/xine.c:1179
#, c-format
msgid "xine_play: no demux available\n"
msgstr "xine_play: Kein Demultiplexer vorhanden\n"
-#: src/xine-engine/xine.c:1247
+#: src/xine-engine/xine.c:1249
#, c-format
msgid "xine_play: demux failed to start\n"
msgstr "xine_play: Demultiplexer startete nicht\n"
-#: src/xine-engine/xine.c:1523
+#: src/xine-engine/xine.c:1527
#, c-format
msgid "xine: The specified save_dir \"%s\" might be a security risk.\n"
msgstr "xine: Das angegebene save_dir '%s' kann ein Sicherheitsproblem sein.\n"
-#: src/xine-engine/xine.c:1528
+#: src/xine-engine/xine.c:1532
msgid "The specified save_dir might be a security risk."
msgstr "Das angegebene save_dir kann ein Sicherheitsproblem sein."
-#: src/xine-engine/xine.c:1554
+#: src/xine-engine/xine.c:1561
msgid "xine: locale not supported by C library\n"
msgstr "xine: Locale wird nicht von C-Bibliothek unterstützt\n"
-#: src/xine-engine/xine.c:1563
+#: src/xine-engine/xine.c:1570
msgid "media format detection strategy"
msgstr "Medienformaterkennungsstrategie"
-#: src/xine-engine/xine.c:1564
+#: src/xine-engine/xine.c:1571
msgid ""
"xine offers various methods to detect the media format of input to play. The "
"individual values are:\n"
@@ -5766,11 +5594,11 @@ msgstr ""
"extension\n"
"Nur anhand der Dateiendung erkennen.\n"
-#: src/xine-engine/xine.c:1582
+#: src/xine-engine/xine.c:1589
msgid "directory for saving streams"
msgstr "Pfad zum Sichen von Datenströmen"
-#: src/xine-engine/xine.c:1583
+#: src/xine-engine/xine.c:1590
msgid ""
"When using the stream save feature, files will be written only into this "
"directory.\n"
@@ -5785,11 +5613,11 @@ msgstr ""
"benutzt werden kann, um Dateien mit beliebigen Inhalt zu füllen. Stellen Sie "
"sicher, daß das Verzeichnis robust ist für beliebige Inhalte in jeder Datei."
-#: src/xine-engine/xine.c:1594
+#: src/xine-engine/xine.c:1601
msgid "allow implicit changes to the configuration (e.g. by MRL)"
msgstr "Erlaube implizierte Änderungen an Konfiguration (z.B. durch MRL)"
-#: src/xine-engine/xine.c:1595
+#: src/xine-engine/xine.c:1602
msgid ""
"If enabled, you allow xine to change your configuration without explicit "
"actions from your side. For example configuration changes demanded by MRLs "
@@ -5805,11 +5633,11 @@ msgstr ""
"unvertrauenswürdigen Stellen empfangen kann. Falls diese willkürlichen "
"Änderungen erlaubt sind, kann dies zu einem verkonfigurierten xine führen."
-#: src/xine-engine/xine.c:1609
+#: src/xine-engine/xine.c:1616
msgid "Timeout for network stream reading (in seconds)"
msgstr "Zeitüberschreitung für Netzwerkdatenströme (in Sekunden)"
-#: src/xine-engine/xine.c:1610
+#: src/xine-engine/xine.c:1617
msgid ""
"Specifies the timeout when reading from network streams, in seconds. Too low "
"values might stop streaming when the source is slow or the bandwidth is "
@@ -5820,15 +5648,15 @@ msgstr ""
"langsam ist oder die Bandbreite erschöpft ist. Zu hohe Werte können xine "
"einfrieren lassen, wenn die Verbindung abbricht."
-#: src/xine-engine/xine.c:1962
+#: src/xine-engine/xine.c:1969
msgid "messages"
msgstr "Nachrichten"
-#: src/xine-engine/xine.c:1963
+#: src/xine-engine/xine.c:1970
msgid "plugin"
msgstr "Plugin"
-#: src/xine-engine/xine.c:1964
+#: src/xine-engine/xine.c:1971
msgid "trace"
msgstr "Programmverfolgung"
@@ -5903,6 +5731,236 @@ msgstr ""
msgid "Benchmarking memcpy methods (smaller is better):\n"
msgstr "Geschwindigkeitsvergleich der memcpy-Methoden (klein ist besser):\n"
+#~ msgid ""
+#~ "video_out_xcbshm: %s: allocating image\n"
+#~ "video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xcbshm: %s: Belege Bild\n"
+#~ "video_out_xcbshm: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
+
+#~ msgid ""
+#~ "video_out_xcbshm: shared memory error (address error) when allocating "
+#~ "image \n"
+#~ "video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xcbshm: Shared-Memory-Fehler (Adressfehler) beim Belegen des "
+#~ "Bilds\n"
+#~ "video_out_xcbshm: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
+
+#~ msgid ""
+#~ "video_out_xcbshm: x11 error during shared memory XImage creation\n"
+#~ "video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xcbshm: X11-Fehler bei Shared-Memory-XImage-Erstellung\n"
+#~ "video_out_xcbshm: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
+
+#~ msgid ""
+#~ "video_out_xcbshm: MIT shared memory extension not present on display.\n"
+#~ msgstr ""
+#~ "video_out_xcbshm: MIT-Shared-Memory-Erweiterung für Anzeige nicht "
+#~ "vorhanden.\n"
+
+#~ msgid "video_out_xcbshm: your video mode was not recognized, sorry :-(\n"
+#~ msgstr ""
+#~ "video_out_xcbshm: Der Videomodus wurde nicht erkannt, Entschuldigung :-(\n"
+
+#~ msgid ""
+#~ "video_out_xcbxv: XvShmCreateImage returned a zero size\n"
+#~ "video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xcbv: XvShmCreateImage lieferte Größe 0 zurück\n"
+#~ "video_out_xcbv: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
+
+#~ msgid ""
+#~ "video_out_xcbxv: shared memory error in shmget: %s\n"
+#~ "video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xcbxv: Shared-Memory-Fehler bei shmget: %s\n"
+#~ "video_out_xcbxv: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
+
+#~ msgid ""
+#~ "video_out_xcbxv: x11 error during shared memory XImage creation\n"
+#~ "video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xcbxv: X11-Fehler bei Shared-Memory-XImage-Erstellung\n"
+#~ "video_out_xcbxv: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
+
+#~ msgid "video_out_xcbxv: Xv extension not present.\n"
+#~ msgstr "video_out_xcbxv: Xv-Erweiterung nicht vorhanden.\n"
+
+#~ msgid ""
+#~ "video_out_xcbxv: Xv extension is present but I couldn't find a usable "
+#~ "yuv12 port.\n"
+#~ " Looks like your graphics hardware driver doesn't support "
+#~ "Xv?!\n"
+#~ msgstr ""
+#~ "video_out_xcbxv: Xv-Erweiterung ist vorhanden, aber es wurde kein "
+#~ "benutzbarer YUV12-Port gefunden.\n"
+#~ " Unterstützt die Grafikhardware evtl. kein Xv?!\n"
+
+#~ msgid ""
+#~ "video_out_xcbxv: using Xv port %d from adaptor %s for hardware colorspace "
+#~ "conversion and scaling.\n"
+#~ msgstr ""
+#~ "video_out_xcbxv: Benutze Xv-Port %d von Adapter %s for Hardware-"
+#~ "Farbraumtransformation und Skalierung.\n"
+
+#~ msgid "video_out_xcbxv: this adaptor supports the yv12 format.\n"
+#~ msgstr "video_out_xcbxv: Adapter unterstützt YV12 Format.\n"
+
+#~ msgid "video_out_xcbxv: this adaptor supports the yuy2 format.\n"
+#~ msgstr "video_out_xcbxv: Adapter unterstützt YUY2 Format.\n"
+
+#~ msgid ""
+#~ "video_out_xshm: shared memory error when allocating image\n"
+#~ "video_out_xshm: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xshm: Shared-Memory-Fehler beim Speicherbelegen\n"
+#~ "video_out_xshm: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
+
+#~ msgid ""
+#~ "video_out_xshm: %s: allocating image\n"
+#~ "video_out_xshm: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xshm: %s: Belege Bild\n"
+#~ "video_out_xshm: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
+
+#~ msgid ""
+#~ "video_out_xshm: x11 error during shared memory XImage creation\n"
+#~ "video_out_xshm: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xshm: X11-Fehler bei Shared-Memory-XImage-Erstellung\n"
+#~ "video_out_xshm: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
+
+#~ msgid "video_out_xshm: your video mode was not recognized, sorry :-(\n"
+#~ msgstr ""
+#~ "video_out_xshm: Der Videomodus wurde nicht erkannt, Entschuldigung :-(\n"
+
+#~ msgid ""
+#~ "video_out_xv: XvShmCreateImage failed\n"
+#~ "video_out_xv: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xv: XvShmCreateImage schlug fehl\n"
+#~ "video_out_xv: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
+
+#~ msgid ""
+#~ "video_out_xv: XvShmCreateImage returned a zero size\n"
+#~ "video_out_xv: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xv: XvShmCreateImage lieferte Größe 0 zurück\n"
+#~ "video_out_xv: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
+
+#~ msgid ""
+#~ "video_out_xv: shared memory error in shmget: %s\n"
+#~ "video_out_xv: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xv: Shared-Memory-Fehler bei shmget: %s\n"
+#~ "video_out_xv: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
+
+#~ msgid ""
+#~ "video_out_xv: x11 error during shared memory XImage creation\n"
+#~ "video_out_xv: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xv: X11-Fehler bei Shared-Memory-XImage-Erstellung\n"
+#~ "video_out_xv: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
+
+#~ msgid ""
+#~ "video_out_xxmc: XvShmCreateImage failed\n"
+#~ "video_out_xxmc: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xxmc: XvShmCreateImage schlug fehl\n"
+#~ "video_out_xxmc: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
+
+#~ msgid ""
+#~ "video_out_xxmc: XvShmCreateImage returned a zero size\n"
+#~ "video_out_xxmc: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xv: XvShmCreateImage lieferte Größe 0 zurück\n"
+#~ "video_out_xv: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
+
+#~ msgid ""
+#~ "video_out_xxmc: shared memory error in shmget: %s\n"
+#~ "video_out_xxmc: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xxmc: Shared-Memory-Fehler bei shmget: %s\n"
+#~ "video_out_xxmc: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
+
+#~ msgid ""
+#~ "video_out_xxmc: x11 error during shared memory XImage creation\n"
+#~ "video_out_xxmc: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xxmc: X11-Fehler bei Shared-Memory-XImage-Erstellung\n"
+#~ "video_out_xxmc: => MIT-Shared-Memory-Erweiterung wird nicht genutzt.\n"
+
+#~ msgid "video_out_xxmc: Xv extension not present.\n"
+#~ msgstr "video_out_xxmc: Xv-Erweiterung nicht vorhanden.\n"
+
+#~ msgid ""
+#~ "video_out_xxmc: Xv extension is present but I couldn't find a usable "
+#~ "yuv12 port.\n"
+#~ " Looks like your graphics hardware driver doesn't support "
+#~ "Xv?!\n"
+#~ msgstr ""
+#~ "video_out_xxmc: Xv-Erweiterung ist vorhanden, aber es wurde kein "
+#~ "benutzparer YUV12-Port gefunden.\n"
+#~ " Unterstützt die Grafikhardware evtl. kein Xv?!\n"
+
+#~ msgid ""
+#~ "video_out_xxmc: using Xv port %ld from adaptor %s for hardware colorspace "
+#~ "conversion and scaling.\n"
+#~ msgstr ""
+#~ "video_out_xxmc: Benutze Xv-Port %ld von Adapter %s for Hardware-"
+#~ "Farbraumtransformation und Skalierung.\n"
+
+#~ msgid "video_out_xxmc: this adaptor supports the yv12 format.\n"
+#~ msgstr "video_out_xxmc: Adapter unterstützt YV12 Format.\n"
+
+#~ msgid "video_out_xxmc: this adaptor supports the yuy2 format.\n"
+#~ msgstr "video_out_xxmc: Adapter unterstützt YUY2 Format.\n"
+
+#~ msgid "CDDB cache directory"
+#~ msgstr "CDDB Cacheverzeichnis"
+
+#~ msgid ""
+#~ "The replies from the CDDB server will be cached in this directory.\n"
+#~ "This setting is security critical, because files with uncontrollable "
+#~ "names will be created in this directory. Be sure to use a dedicated "
+#~ "directory not used for anything but CDDB caching."
+#~ msgstr ""
+#~ "Die Antworten des CDDB-Servers werden in diesem Verzeichnis "
+#~ "zwischengepuffert.\n"
+#~ "Diese Einstellung ist Sicherheitskritisch, da Dateien mit "
+#~ "unkontrollierten Namen innerhalb dieses Verzeichnises angelegt werden. "
+#~ "Stellen Sie sicher, daß das Verzeichnis nur für CDDB Zwischenpufferung "
+#~ "genutzt wird."
+
+#~ msgid "path to the title key cache"
+#~ msgstr "Pfad zum Titelschlüsselcache"
+
+#~ msgid ""
+#~ "Since cracking the copy protection of scrambled DVDs can be quite time "
+#~ "consuming, libdvdcss will cache the cracked keys in this directory.\n"
+#~ "This setting is security critical, because files with uncontrollable "
+#~ "names will be created in this directory. Be sure to use a dedicated "
+#~ "directory not used for anything but DVD key caching."
+#~ msgstr ""
+#~ "Da das Cracken des Kopierschutzes von verschlüsselten DVDs viel Zeit "
+#~ "erfordern kann, speichert libdvdcss gefundenen Schlüssel in diesem "
+#~ "Verzeichnis zwischen.\n"
+#~ "Diese Einstellung ist Sicherheitskritisch, da Dateien mit "
+#~ "unkontrollierten Namen innerhalb dieses Verzeichnises angelegt werden. "
+#~ "Stellen Sie sicher, daß das Verzeichnis nur für die Zwischenpufferung von "
+#~ "DVD Titelschlüssel genutzt wird."
+
+#~ msgid ""
+#~ "WARNING: video_out_fb: current display depth is %d. For better "
+#~ "performance\n"
+#~ " a depth of 16 bpp is recommended!\n"
+#~ "\n"
+#~ msgstr ""
+#~ "WARNUNG: video_out_fb: Momentane Farbtiefe ist %d. Für bessere Leistung "
+#~ "wird eine Farbtiefe von 16 bpp empfohlen!\n"
+
#~ msgid "make the overlay behave like a fixed layer (for debugging)"
#~ msgstr "Überlagerungsebene verhält sich wie feste Ebene (zur Fehlersuche)"
diff --git a/po/es.po b/po/es.po
index 5f565777e..caee6a749 100644
--- a/po/es.po
+++ b/po/es.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: xine-lib-1.1.4\n"
"Report-Msgid-Bugs-To: xine-devel@lists.sourceforge.net\n"
-"POT-Creation-Date: 2007-04-06 15:39+0200\n"
+"POT-Creation-Date: 2007-04-24 21:48+0100\n"
"PO-Revision-Date: 2007-02-28 14:07+0100\n"
"Last-Translator: Carlos E. Robinson M. <carloser@users.sourceforge.net>\n"
"Language-Team: Spanish\n"
@@ -50,21 +50,21 @@ msgstr ""
msgid "Unknown error"
msgstr "error desconocido"
-#: src/audio_out/audio_alsa_out.c:354
+#: src/audio_out/audio_alsa_out.c:351
#, c-format
msgid "audio_alsa_out:Already open...WHY!"
msgstr "audio_alsa_out:Ya está abierto...¡PORQUÉ!"
-#: src/audio_out/audio_alsa_out.c:382
+#: src/audio_out/audio_alsa_out.c:379
#, c-format
msgid "audio_alsa_out: snd_pcm_open() of %s failed: %s\n"
msgstr "audio_alsa_out: snd_pcm_open() de %s falló: %s\n"
-#: src/audio_out/audio_alsa_out.c:384
+#: src/audio_out/audio_alsa_out.c:381
msgid "audio_alsa_out: >>> check if another program already uses PCM <<<\n"
msgstr "audio_alsa_out: >>> comprobar si otro programa ya usa PCM <<<\n"
-#: src/audio_out/audio_alsa_out.c:397
+#: src/audio_out/audio_alsa_out.c:394
#, c-format
msgid ""
"audio_alsa_out: broken configuration for this PCM: no configurations "
@@ -73,11 +73,11 @@ msgstr ""
"audio_alsa_out: configuración rota para éste PCM: no hay configuraciones "
"disponibles: %s\n"
-#: src/audio_out/audio_alsa_out.c:1289
+#: src/audio_out/audio_alsa_out.c:1286
msgid "notify changes to the hardware mixer"
msgstr "notificar cambios al mezclador en hardware"
-#: src/audio_out/audio_alsa_out.c:1290
+#: src/audio_out/audio_alsa_out.c:1287
msgid ""
"When the hardware mixer changes, your application will receive a "
"notification so that it can update its graphical representation of the mixer "
@@ -87,16 +87,16 @@ msgstr ""
"notificiación de modo que pueda actualizar su representación gráfica de los "
"ajustes del mezclador al vuelo."
-#: src/audio_out/audio_alsa_out.c:1355
+#: src/audio_out/audio_alsa_out.c:1352
#, c-format
msgid "snd_lib_error_set_handler() failed: %d"
msgstr "snd_lib_error_set_handler() falló: %d"
-#: src/audio_out/audio_alsa_out.c:1362
+#: src/audio_out/audio_alsa_out.c:1359
msgid "sound card can do mmap"
msgstr "la tarjeta de sonido puede hacer mmap"
-#: src/audio_out/audio_alsa_out.c:1363
+#: src/audio_out/audio_alsa_out.c:1360
msgid ""
"Enable this, if your sound card and alsa driver support memory mapped IO.\n"
"You can try enabling it and check, if everything works. If it does, this "
@@ -107,11 +107,11 @@ msgstr ""
"Puede probar a activarlo y verficar, si todo funciona. Si lo hace, esto "
"aumentará el rendimiento."
-#: src/audio_out/audio_alsa_out.c:1372
+#: src/audio_out/audio_alsa_out.c:1369
msgid "device used for mono output"
msgstr "dispositivo usado para salida mono"
-#: src/audio_out/audio_alsa_out.c:1373
+#: src/audio_out/audio_alsa_out.c:1370
msgid ""
"xine will use this alsa device to output mono sound.\n"
"See the alsa documentation for information on alsa devices."
@@ -119,11 +119,11 @@ msgstr ""
"xine usará éste dispositivo para generar sonido monofónico.\n"
"Vea la documentación de alsa para información de dispositivos alsa."
-#: src/audio_out/audio_alsa_out.c:1381
+#: src/audio_out/audio_alsa_out.c:1378
msgid "device used for stereo output"
msgstr "dispositivo usado para salida estéreo"
-#: src/audio_out/audio_alsa_out.c:1382
+#: src/audio_out/audio_alsa_out.c:1379
msgid ""
"xine will use this alsa device to output stereo sound.\n"
"See the alsa documentation for information on alsa devices."
@@ -131,11 +131,11 @@ msgstr ""
"xine usará este dispositivo alsa para la salida de sonido estereo.\n"
"Vea la documentación de alsa para información de dispositivos alsa."
-#: src/audio_out/audio_alsa_out.c:1390
+#: src/audio_out/audio_alsa_out.c:1387
msgid "device used for 4-channel output"
msgstr "dispositivo usado para salida de cuatro canales"
-#: src/audio_out/audio_alsa_out.c:1391
+#: src/audio_out/audio_alsa_out.c:1388
msgid ""
"xine will use this alsa device to output 4 channel (4.0) surround sound.\n"
"See the alsa documentation for information on alsa devices."
@@ -144,11 +144,11 @@ msgstr ""
"canales (4.0).\n"
"Vea la documentación de alsa para información de dispositivos alsa."
-#: src/audio_out/audio_alsa_out.c:1400 src/audio_out/audio_alsa_out.c:1410
+#: src/audio_out/audio_alsa_out.c:1397 src/audio_out/audio_alsa_out.c:1407
msgid "device used for 5.1-channel output"
msgstr "dispositivo usado para salida de 5.1 canales"
-#: src/audio_out/audio_alsa_out.c:1401
+#: src/audio_out/audio_alsa_out.c:1398
msgid ""
"xine will use this alsa device to output 5 channel plus LFE (5.1) surround "
"sound.\n"
@@ -158,7 +158,7 @@ msgstr ""
"canales más LFE (5.1).\n"
"Vea la documentación de alsa para información de dispositivos alsa."
-#: src/audio_out/audio_alsa_out.c:1411
+#: src/audio_out/audio_alsa_out.c:1408
msgid ""
"xine will use this alsa device to output undecoded digital surround sound. "
"This can be used be external surround decoders.\n"
@@ -168,21 +168,21 @@ msgstr ""
"sin decodificar. Esto puede usarse en decodificadores envolventes externos.\n"
"Vea la documentación de alsa para información de dispositivos alsa."
-#: src/audio_out/audio_alsa_out.c:1431
+#: src/audio_out/audio_alsa_out.c:1428
#, c-format
msgid "snd_pcm_open() failed:%d:%s\n"
msgstr "snd_pcm_open() falló:%d:%s\n"
-#: src/audio_out/audio_alsa_out.c:1433
+#: src/audio_out/audio_alsa_out.c:1430
#, c-format
msgid ">>> Check if another program already uses PCM <<<\n"
msgstr ">>> Comprobar si otro programa está ya usando PCM <<<\n"
-#: src/audio_out/audio_alsa_out.c:1464 src/audio_out/audio_oss_out.c:929
+#: src/audio_out/audio_alsa_out.c:1461 src/audio_out/audio_oss_out.c:929
msgid "speaker arrangement"
msgstr "disposición de altavoces"
-#: src/audio_out/audio_alsa_out.c:1465 src/audio_out/audio_oss_out.c:930
+#: src/audio_out/audio_alsa_out.c:1462 src/audio_out/audio_oss_out.c:930
msgid ""
"Select how your speakers are arranged, this determines which speakers xine "
"uses for sound output. The individual values are:\n"
@@ -246,79 +246,79 @@ msgstr ""
"decodificar los formatos que quiera reproducir mediate la salida digital de "
"su tarjeta de sonido."
-#: src/audio_out/audio_alsa_out.c:1494
+#: src/audio_out/audio_alsa_out.c:1491
msgid "audio_alsa_out : supported modes are "
msgstr "audio_alsa_out : los modos soportados son "
-#: src/audio_out/audio_alsa_out.c:1497
+#: src/audio_out/audio_alsa_out.c:1494
msgid "8bit "
msgstr "8bit "
-#: src/audio_out/audio_alsa_out.c:1502
+#: src/audio_out/audio_alsa_out.c:1499
msgid "16bit "
msgstr "16bit "
-#: src/audio_out/audio_alsa_out.c:1506
+#: src/audio_out/audio_alsa_out.c:1503
msgid "24bit "
msgstr "24bit "
-#: src/audio_out/audio_alsa_out.c:1510
+#: src/audio_out/audio_alsa_out.c:1507
msgid "32bit "
msgstr "32bit "
-#: src/audio_out/audio_alsa_out.c:1521
+#: src/audio_out/audio_alsa_out.c:1518
msgid "mono "
msgstr "mono "
-#: src/audio_out/audio_alsa_out.c:1525
+#: src/audio_out/audio_alsa_out.c:1522
msgid "stereo "
msgstr "estéreo "
-#: src/audio_out/audio_alsa_out.c:1530
+#: src/audio_out/audio_alsa_out.c:1527
msgid "4-channel "
msgstr "4-canales "
-#: src/audio_out/audio_alsa_out.c:1533
+#: src/audio_out/audio_alsa_out.c:1530
msgid "(4-channel not enabled in xine config) "
msgstr "(4-canales no activado en la configuración de xine) "
-#: src/audio_out/audio_alsa_out.c:1538
+#: src/audio_out/audio_alsa_out.c:1535
msgid "4.1-channel "
msgstr "4.1-canales "
-#: src/audio_out/audio_alsa_out.c:1541
+#: src/audio_out/audio_alsa_out.c:1538
msgid "(4.1-channel not enabled in xine config) "
msgstr "(4.1-canales no activado en la configuración de xine) "
-#: src/audio_out/audio_alsa_out.c:1546
+#: src/audio_out/audio_alsa_out.c:1543
msgid "5-channel "
msgstr "5-canales "
-#: src/audio_out/audio_alsa_out.c:1549
+#: src/audio_out/audio_alsa_out.c:1546
msgid "(5-channel not enabled in xine config) "
msgstr "(5-canales no activado en la configuración de xine) "
-#: src/audio_out/audio_alsa_out.c:1554
+#: src/audio_out/audio_alsa_out.c:1551
msgid "5.1-channel "
msgstr "5.1-canales "
-#: src/audio_out/audio_alsa_out.c:1557
+#: src/audio_out/audio_alsa_out.c:1554
msgid "(5.1-channel not enabled in xine config) "
msgstr "(5.1-canales no activado en la configuración de xine) "
-#: src/audio_out/audio_alsa_out.c:1580
+#: src/audio_out/audio_alsa_out.c:1577
msgid "a/52 and DTS pass-through\n"
msgstr "travesía a/52 y DTS\n"
-#: src/audio_out/audio_alsa_out.c:1583
+#: src/audio_out/audio_alsa_out.c:1580
msgid "(a/52 and DTS pass-through not enabled in xine config)\n"
msgstr "(travesía a/52 and DTS no activada en la configuración de xine)\n"
-#: src/audio_out/audio_alsa_out.c:1590
+#: src/audio_out/audio_alsa_out.c:1587
msgid "alsa mixer device"
msgstr "dispositivo mezclador alsa"
-#: src/audio_out/audio_alsa_out.c:1591
+#: src/audio_out/audio_alsa_out.c:1588
msgid ""
"xine will use this alsa mixer device to change the volume.\n"
"See the alsa documentation for information on alsa devices."
@@ -326,7 +326,7 @@ msgstr ""
"xine usará este dispositivo mezclador alsa para cambiar el volumen.\n"
"Vea la documentación de alsa para información de dispositivos alsa."
-#: src/audio_out/audio_alsa_out.c:1665
+#: src/audio_out/audio_alsa_out.c:1662
msgid "xine audio output plugin using alsa-compliant audio devices/drivers"
msgstr ""
"complemento de xine de salida de audio usando dispositvos/drivers "
@@ -340,201 +340,201 @@ msgstr "complemento de xine de salida de audio usando artsd de kde"
msgid "xine output plugin for Coreaudio/Mac OS X"
msgstr "complemento de xine de salida de audio para Coreaudio/Mac OS X"
-#: src/audio_out/audio_directx2_out.c:166
+#: src/audio_out/audio_directx2_out.c:163
msgid "Error"
msgstr "Error"
-#: src/audio_out/audio_directx2_out.c:173
+#: src/audio_out/audio_directx2_out.c:170
msgid "success"
msgstr "éxito"
-#: src/audio_out/audio_directx2_out.c:175
+#: src/audio_out/audio_directx2_out.c:172
msgid "access denied"
msgstr "acceso denegado"
-#: src/audio_out/audio_directx2_out.c:177
+#: src/audio_out/audio_directx2_out.c:174
msgid "resource is already in use"
msgstr "el recurso ya está siendo utilizado"
-#: src/audio_out/audio_directx2_out.c:178
+#: src/audio_out/audio_directx2_out.c:175
msgid "object was already initialized"
msgstr "el objecto ya fué inicializado"
-#: src/audio_out/audio_directx2_out.c:179
+#: src/audio_out/audio_directx2_out.c:176
msgid "specified wave format is not supported"
msgstr "el formato de onda especificado no está soportado"
-#: src/audio_out/audio_directx2_out.c:180
+#: src/audio_out/audio_directx2_out.c:177
msgid "memory buffer has been lost and must be restored"
msgstr "el búfer en memoria se ha perdido y debe ser restaurado"
-#: src/audio_out/audio_directx2_out.c:181
+#: src/audio_out/audio_directx2_out.c:178
msgid "requested buffer control is not available"
msgstr "el control del búfer pedido no está disponible"
-#: src/audio_out/audio_directx2_out.c:182
+#: src/audio_out/audio_directx2_out.c:179
msgid "undetermined error inside DirectSound subsystem"
msgstr "error indeterminado dentro del subsistema DirectSound"
-#: src/audio_out/audio_directx2_out.c:184
+#: src/audio_out/audio_directx2_out.c:181
msgid "DirectSound hardware device is unavailable"
msgstr "dispositivo físico DirectSound no disponible"
-#: src/audio_out/audio_directx2_out.c:186
+#: src/audio_out/audio_directx2_out.c:183
msgid "function is not valid for the current state of the object"
msgstr "función no válida para el estado actual del object"
-#: src/audio_out/audio_directx2_out.c:187
+#: src/audio_out/audio_directx2_out.c:184
msgid "invalid parameter was passed"
msgstr "se ha pasado un parámetro inválido"
-#: src/audio_out/audio_directx2_out.c:188
+#: src/audio_out/audio_directx2_out.c:185
msgid "object doesn't support aggregation"
msgstr "el objeto no soporta agregación"
-#: src/audio_out/audio_directx2_out.c:189
+#: src/audio_out/audio_directx2_out.c:186
msgid "no sound driver available for use"
msgstr "no hay driver de sonido disponible para su uso"
-#: src/audio_out/audio_directx2_out.c:190
+#: src/audio_out/audio_directx2_out.c:187
msgid "requested COM interface not available"
msgstr "interfase COM solicitada no disponible"
-#: src/audio_out/audio_directx2_out.c:191
+#: src/audio_out/audio_directx2_out.c:188
msgid "another application has a higher priority level"
msgstr "otra aplicación tiene un nivel de prioridad más alto"
-#: src/audio_out/audio_directx2_out.c:192
+#: src/audio_out/audio_directx2_out.c:189
msgid "insufficient memory"
msgstr "memoria insuficiente"
-#: src/audio_out/audio_directx2_out.c:193
+#: src/audio_out/audio_directx2_out.c:190
msgid "low priority level for this function"
msgstr "nivel de prioridad bajo para ésta función"
-#: src/audio_out/audio_directx2_out.c:194
+#: src/audio_out/audio_directx2_out.c:191
msgid "DirectSound wasn't initialized"
msgstr "DirectSound no fué inicializado"
-#: src/audio_out/audio_directx2_out.c:195
+#: src/audio_out/audio_directx2_out.c:192
msgid "function is not supported"
msgstr "función no soportada"
-#: src/audio_out/audio_directx2_out.c:196
+#: src/audio_out/audio_directx2_out.c:193
msgid "unknown error"
msgstr "error desconocido"
-#: src/audio_out/audio_directx2_out.c:206
+#: src/audio_out/audio_directx2_out.c:203
#, c-format
msgid "Unable to create direct sound object."
msgstr "Incapaz de crear el objeto de sonido directo."
-#: src/audio_out/audio_directx2_out.c:212
+#: src/audio_out/audio_directx2_out.c:209
#, c-format
msgid "Could not set direct sound cooperative level."
msgstr "No pude poner el nivel cooperativo del sonido directo."
-#: src/audio_out/audio_directx2_out.c:286
+#: src/audio_out/audio_directx2_out.c:283
msgid "Unable to create secondary direct sound buffer"
msgstr "Incapaz de crear búfer secundario de sonido directo"
-#: src/audio_out/audio_directx2_out.c:310
+#: src/audio_out/audio_directx2_out.c:307
#, c-format
msgid "Unable to create buffer position events."
msgstr "Incapaz de crear eventos posicionales de búfer."
-#: src/audio_out/audio_directx2_out.c:318
+#: src/audio_out/audio_directx2_out.c:315
msgid "Unable to get notification interface"
msgstr "Incapaz de conseguir interfase de notificación"
-#: src/audio_out/audio_directx2_out.c:323
+#: src/audio_out/audio_directx2_out.c:320
msgid "Unable to set notification positions"
msgstr "Incapaz de poner posiciones de notificación"
-#: src/audio_out/audio_directx2_out.c:343
+#: src/audio_out/audio_directx2_out.c:340
msgid "Couldn't play sound buffer"
msgstr "No pude tocar el búfer de sonido"
-#: src/audio_out/audio_directx2_out.c:355
+#: src/audio_out/audio_directx2_out.c:352
msgid "Couldn't stop sound buffer"
msgstr "No pude parar el búfer de sonido"
-#: src/audio_out/audio_directx2_out.c:368
+#: src/audio_out/audio_directx2_out.c:365
msgid "Can't get buffer position"
msgstr "No puedo conseguir la posición del búfer"
-#: src/audio_out/audio_directx2_out.c:382
+#: src/audio_out/audio_directx2_out.c:379
msgid "Can't set buffer position"
msgstr "No puedo poner la posición del búfer"
-#: src/audio_out/audio_directx2_out.c:414
+#: src/audio_out/audio_directx2_out.c:411
msgid "Can't set sound volume"
msgstr "No puedo poner el volumen de sonido"
-#: src/audio_out/audio_directx2_out.c:432
+#: src/audio_out/audio_directx2_out.c:429
#, c-format
msgid ": buffer lost, tryig to restore\n"
msgstr ": búfer perdido, intentando restaurar\n"
-#: src/audio_out/audio_directx2_out.c:436
+#: src/audio_out/audio_directx2_out.c:433
msgid "Couldn't lock direct sound buffer"
msgstr "No pude bloquear el búfer de sonido directo"
-#: src/audio_out/audio_directx2_out.c:447
+#: src/audio_out/audio_directx2_out.c:444
msgid "Couldn't unlock direct sound buffer"
msgstr "No pude desbloquear el búfer de sonido directo"
-#: src/audio_out/audio_directx2_out.c:544
+#: src/audio_out/audio_directx2_out.c:541
#, c-format
msgid "Unable to create primary direct sound buffer."
msgstr "Incapaz de crear el búfer primario de sonido directo."
-#: src/audio_out/audio_directx2_out.c:637
+#: src/audio_out/audio_directx2_out.c:634
#, c-format
msgid ": play cursor overran, flushing buffers\n"
msgstr ": cursor de ejecución desbordado, vaciando búffers\n"
-#: src/audio_out/audio_directx2_out.c:655
+#: src/audio_out/audio_directx2_out.c:652
#, c-format
msgid ": delayed by %ld msec\n"
msgstr ": retrasado en %ld msec\n"
-#: src/audio_out/audio_directx2_out.c:759
+#: src/audio_out/audio_directx2_out.c:756
#, c-format
msgid ": can't create pthread condition: %s\n"
msgstr ": no puedo crear condición pthread: %s\n"
-#: src/audio_out/audio_directx2_out.c:763
+#: src/audio_out/audio_directx2_out.c:760
#, c-format
msgid ": can't create pthread mutex: %s\n"
msgstr ": no puedo crear mutex pthread: %s\n"
-#: src/audio_out/audio_directx2_out.c:770
+#: src/audio_out/audio_directx2_out.c:767
#, c-format
msgid ": can't create buffer pthread: %s\n"
msgstr ": no puedo crear búfer pthread: %s\n"
-#: src/audio_out/audio_directx2_out.c:877
+#: src/audio_out/audio_directx2_out.c:874
#, c-format
msgid ": can't destroy buffer pthread: %s\n"
msgstr ": no puedo destruir búfer: %s\n"
-#: src/audio_out/audio_directx2_out.c:884
+#: src/audio_out/audio_directx2_out.c:881
#, c-format
msgid ": can't destroy pthread condition: %s\n"
msgstr ": no puedo crear condición pthread: %s\n"
-#: src/audio_out/audio_directx2_out.c:887
+#: src/audio_out/audio_directx2_out.c:884
#, c-format
msgid ": can't destroy pthread mutex: %s\n"
msgstr ": no puedo destruir mutex pthread: %s\n"
-#: src/audio_out/audio_directx2_out.c:947
+#: src/audio_out/audio_directx2_out.c:944
#, c-format
msgid ": unknown control command %d\n"
msgstr ": comando de control desconocido %d\n"
-#: src/audio_out/audio_directx2_out.c:1003
+#: src/audio_out/audio_directx2_out.c:1000
msgid "second xine audio output plugin using directx"
msgstr "segundo complemento de xine de salida de audio usando directx"
@@ -1024,7 +1024,7 @@ msgstr "demux_snd: parámetros de cabecera malos\n"
msgid "demux_snd: unsupported audio type: %d\n"
msgstr "demux_snd: tipo de audio no soportado: %d\n"
-#: src/demuxers/demux_tta.c:88
+#: src/demuxers/demux_tta.c:86
msgid "demux_tta: total frames count too high\n"
msgstr ""
@@ -1049,7 +1049,7 @@ msgid "demux_wc3movie: SHOT chunk referenced invalid palette (%d >= %d)\n"
msgstr ""
"demux_wc3movie: bloque SHOT referenció una paleta inválida (%d >= %d)\n"
-#: src/demuxers/demux_wc3movie.c:406
+#: src/demuxers/demux_wc3movie.c:404
#, c-format
msgid "demux_wc3movie: There was a problem while loading palette chunks\n"
msgstr ""
@@ -1534,30 +1534,30 @@ msgstr ""
"video_out_dxr3: ERROR leyendo en fichero de inicialización de la "
"superposición. ¡Ejecute autocal!\n"
-#: src/input/input_cdda.c:1621
+#: src/input/input_cdda.c:1608
#, c-format
msgid "%s: can't connect to %s:%d\n"
msgstr "%s: no se puede conectar a %s:%d\n"
-#: src/input/input_cdda.c:1668
+#: src/input/input_cdda.c:1655
#, c-format
msgid "input_cdda: successfuly connected to cddb server '%s:%d'.\n"
msgstr "input_cdda: conectado con éxito al servidor cddb '%s:%d'.\n"
-#: src/input/input_cdda.c:1673
+#: src/input/input_cdda.c:1660
#, c-format
msgid "input_cdda: failed to connect to cddb server '%s:%d' (%s).\n"
msgstr "input_cdda: falló al conectar al servidor cddb '%s:%d' (%s).\n"
-#: src/input/input_cdda.c:2707
+#: src/input/input_cdda.c:2690
msgid "CD Digital Audio (aka. CDDA)"
msgstr "audio CD digital (alias CDDA)"
-#: src/input/input_cdda.c:2760
+#: src/input/input_cdda.c:2742
msgid "device used for CD audio"
msgstr "dispositivo usado para audio CD"
-#: src/input/input_cdda.c:2761
+#: src/input/input_cdda.c:2743
msgid ""
"The path to the device, usually a CD or DVD drive, which you intend to use "
"for playing audio CDs."
@@ -1565,11 +1565,11 @@ msgstr ""
"El camino al dispositivo, normalmente un lector de de CD o DVD, que desea "
"usar para reproducir CDs de audio."
-#: src/input/input_cdda.c:2767
+#: src/input/input_cdda.c:2749
msgid "query CDDB"
msgstr "consultar la CDDB"
-#: src/input/input_cdda.c:2767
+#: src/input/input_cdda.c:2749
msgid ""
"Enables CDDB queries, which will give you convenient title and track names "
"for your audio CDs.\n"
@@ -1583,11 +1583,11 @@ msgstr ""
"información se obtiene de un servidor en Internet que podría sacar un perfil "
"de sus hábitos de escucha."
-#: src/input/input_cdda.c:2775
+#: src/input/input_cdda.c:2757
msgid "CDDB server name"
msgstr "nombre del servidor CDDB"
-#: src/input/input_cdda.c:2775
+#: src/input/input_cdda.c:2757
msgid ""
"The CDDB server used to retrieve the title and track information from.\n"
"This setting is security critical, because the sever will receive "
@@ -1600,37 +1600,20 @@ msgstr ""
"consultas con respuestas maliciosas. Asegúrese de poner un servidor del que "
"se pueda fiar."
-#: src/input/input_cdda.c:2783
+#: src/input/input_cdda.c:2765
msgid "CDDB server port"
msgstr "puerto del servidor CDDB"
-#: src/input/input_cdda.c:2783
+#: src/input/input_cdda.c:2765
msgid "The server port used to retrieve the title and track information from."
msgstr ""
"El puerto del servidor usado para obtener la información de título y pista."
-#: src/input/input_cdda.c:2789
-msgid "CDDB cache directory"
-msgstr "directorio caché del CDDB"
-
-#: src/input/input_cdda.c:2789
-msgid ""
-"The replies from the CDDB server will be cached in this directory.\n"
-"This setting is security critical, because files with uncontrollable names "
-"will be created in this directory. Be sure to use a dedicated directory not "
-"used for anything but CDDB caching."
-msgstr ""
-"Las respuestas del servidor CDDB serán almacenadas temporalmente en este "
-"directorio.\n"
-"Esta configuración es crítica para su seguridad, porque nombres sin control "
-"serán creados en este directorio. Asegúrese de poner un directorio dedicado "
-"que no se use para ninguna otra cosa que el cacheado del CDDB."
-
-#: src/input/input_cdda.c:2797
+#: src/input/input_cdda.c:2771
msgid "slow down disc drive to this speed factor"
msgstr "enlentecer la unidad de disco a este factor de velocidad"
-#: src/input/input_cdda.c:2798
+#: src/input/input_cdda.c:2772
msgid ""
"Since some CD or DVD drives make some really loud noises because of the fast "
"disc rotation, xine will try to slow them down. With standard CD or DVD "
@@ -1645,50 +1628,55 @@ msgstr ""
"que el enlentecimiento no afectaría el rendimiento de la reproducción.\n"
"Un valor de cero desactivará el enlentecimiento."
-#: src/input/input_dvb.c:881
-#, c-format
-msgid "input_dvb: failed to open dvb channel file '%s'\n"
+#: src/input/input_dvb.c:899
+#, fuzzy, c-format
+msgid "input_dvb: failed to open dvb channel file '%s': %s\n"
msgstr "input_dvb: failló al abrir el fichero de canales DVB '%s'\n"
-#: src/input/input_dvb.c:2082 src/input/input_dvb.c:2910
+#: src/input/input_dvb.c:905
+#, fuzzy, c-format
+msgid "input_dvb: dvb channel file '%s' is not a plain file\n"
+msgstr "input_dvb: failló al abrir el fichero de canales DVB '%s'\n"
+
+#: src/input/input_dvb.c:2115 src/input/input_dvb.c:2943
msgid "input_dvb: tuner_set_channel failed\n"
msgstr "input_dvb: falló tuner_set_channel\n"
-#: src/input/input_dvb.c:2710
+#: src/input/input_dvb.c:2743
msgid "input_dvb: cannot open dvb device\n"
msgstr "input_dvb: no puedo abrir dispositivo DVB\n"
-#: src/input/input_dvb.c:2734
+#: src/input/input_dvb.c:2767
#, c-format
msgid "input_dvb: channel %d out of range, defaulting to 0\n"
msgstr "input_dvb: canal %d fuera de rango, poniendo a 0\n"
-#: src/input/input_dvb.c:2745
+#: src/input/input_dvb.c:2778
#, c-format
msgid "input_dvb: searching for channel %s\n"
msgstr "input_dvb: buscando el canal %s\n"
-#: src/input/input_dvb.c:2768
+#: src/input/input_dvb.c:2801
#, c-format
msgid "input_dvb: exact match for %s not found: trying partial matches\n"
msgstr ""
"input_dvb: no encontrada una coincidencia exacta para %s: probando "
"coincidencias parciales\n"
-#: src/input/input_dvb.c:2775
+#: src/input/input_dvb.c:2808
#, c-format
msgid "input_dvb: found matching channel %s\n"
msgstr "input_dvb: encontrado el canal correspondiente %s\n"
# Cer: (temporal) "valores por defecto" no es la traducción exacta
-#: src/input/input_dvb.c:2788
+#: src/input/input_dvb.c:2821
#, fuzzy, c-format
msgid "input_dvb: channel %s not found in channels.conf, defaulting.\n"
msgstr ""
"input_dvb: canal %s no encontrado en channels.conf, yendo a valores por "
"defecto.\n"
-#: src/input/input_dvb.c:2794
+#: src/input/input_dvb.c:2827
msgid ""
"input_dvb: invalid channel specification, defaulting to last viewed "
"channel.\n"
@@ -1696,11 +1684,11 @@ msgstr ""
"input_dvb: especificación de canal inválida, usaremos el ultimo canal "
"visualizado.\n"
-#: src/input/input_dvb.c:2800
+#: src/input/input_dvb.c:2833
msgid "input_dvb: invalid channel specification, defaulting to channel 0\n"
msgstr "input_dvb: especificación de canal inválida, usaremos el canal 0.\n"
-#: src/input/input_dvb.c:2812
+#: src/input/input_dvb.c:2845
msgid ""
"input_dvb: dvbs mrl specified but the tuner doesn't appear to be QPSK (DVB-"
"S)\n"
@@ -1708,7 +1696,7 @@ msgstr ""
"input_dvb: se especificó MRL DVBS pero el sintonizador no aparenta ser QPSK "
"(DVB-S)\n"
-#: src/input/input_dvb.c:2832
+#: src/input/input_dvb.c:2865
msgid ""
"input_dvb: dvbt mrl specified but the tuner doesn't appear to be OFDM (DVB-"
"T)\n"
@@ -1716,7 +1704,7 @@ msgstr ""
"input_dvb: se especificó MRL DVBT pero el sintonizador no aparenta ser OFDM "
"(DVB-T)\n"
-#: src/input/input_dvb.c:2855 src/input/input_dvb.c:2881
+#: src/input/input_dvb.c:2888 src/input/input_dvb.c:2914
msgid ""
"input_dvb: dvbc mrl specified but the tuner doesn't appear to be QAM (DVB-"
"C)\n"
@@ -1724,20 +1712,20 @@ msgstr ""
"input_dvb: se especificó MRL DVBC pero el sintonizador no aparenta ser QAM "
"(DVB-C)\n"
-#: src/input/input_dvb.c:2916
+#: src/input/input_dvb.c:2949
#, c-format
msgid "input_dvb: cannot open dvr device '%s'\n"
msgstr "input_dvb: no se puede abrir el dispositivo DVR '%s'\n"
-#: src/input/input_dvb.c:2938
+#: src/input/input_dvb.c:2971
msgid "input_dvb: cannot create EPG updater thread\n"
msgstr "input_dvb: no se puede crear el hilo actualizador de EPG\n"
-#: src/input/input_dvb.c:3000
+#: src/input/input_dvb.c:3033
msgid "use DVB 'center cutout' (zoom)"
msgstr "usar corte de la zona central del DVB (zoom)"
-#: src/input/input_dvb.c:3001
+#: src/input/input_dvb.c:3034
msgid ""
"This will allow fullscreen playback of 4:3 content transmitted in a 16:9 "
"frame."
@@ -1745,15 +1733,15 @@ msgstr ""
"Esto permitirá reproducción a pantalla completa de contenido en formato 4:3 "
"transmitido en un cuadro 16:9."
-#: src/input/input_dvb.c:3094
+#: src/input/input_dvb.c:3127
msgid "DVB (Digital TV) input plugin"
msgstr "complemento de entrada DVB (TV Digital)"
-#: src/input/input_dvb.c:3242
+#: src/input/input_dvb.c:3244
msgid "Remember last DVB channel watched"
msgstr "Recordar el último canal DVB visto"
-#: src/input/input_dvb.c:3243
+#: src/input/input_dvb.c:3245
msgid ""
"On autoplay, xine will remember and switch to the channel indicated in media."
"dvb.last_channel. "
@@ -1761,19 +1749,19 @@ msgstr ""
"En autoejecución, xine recordará y cambiará al canal indicado en media.dvb."
"last_channel. "
-#: src/input/input_dvb.c:3250
+#: src/input/input_dvb.c:3252
msgid "Last DVB channel viewed"
msgstr "Último canal DVB visto"
-#: src/input/input_dvb.c:3251
+#: src/input/input_dvb.c:3253
msgid "If enabled xine will remember and switch to this channel. "
msgstr "Si se activa xine recordará y cambiará a este canal. "
-#: src/input/input_dvb.c:3257
+#: src/input/input_dvb.c:3259
msgid "Number of dvb card to use."
msgstr "Número de tarjeta DVB a usar."
-#: src/input/input_dvb.c:3258
+#: src/input/input_dvb.c:3260
msgid ""
"Leave this at zero unless you really have more than 1 card in your system."
msgstr ""
@@ -1805,11 +1793,11 @@ msgstr ""
"El camino al dispositivo, usualmente una unidad de DVD, que desea usar para "
"reproducir DVDs."
-#: src/input/input_dvd.c:1800
+#: src/input/input_dvd.c:1799
msgid "raw device set up for DVD access"
msgstr "dispositivo bruto usado para acceso al DVD"
-#: src/input/input_dvd.c:1801
+#: src/input/input_dvd.c:1800
msgid ""
"If this points to a raw device connected to your DVD device, xine will use "
"the raw device for playback. This has the advantage of being slightly faster "
@@ -1828,11 +1816,11 @@ msgstr ""
"Vea la documentación de configuración de dispositivos en bruto (man raw) "
"para más información."
-#: src/input/input_dvd.c:1814
+#: src/input/input_dvd.c:1813
msgid "CSS decryption method"
msgstr "método de desencriptación CSS"
-#: src/input/input_dvd.c:1815
+#: src/input/input_dvd.c:1814
msgid ""
"Selects the decryption method libdvdcss will use to descramble copy "
"protected DVDs. Try the various methods, if you have problems playing "
@@ -1842,29 +1830,11 @@ msgstr ""
"DVDs protegidos de copia. Pruebe los varios métodos, si tiene problemas "
"reproduciendo DVDs cifrados."
-#: src/input/input_dvd.c:1823
-msgid "path to the title key cache"
-msgstr "camino al caché de claves de títulos"
-
-#: src/input/input_dvd.c:1824
-msgid ""
-"Since cracking the copy protection of scrambled DVDs can be quite time "
-"consuming, libdvdcss will cache the cracked keys in this directory.\n"
-"This setting is security critical, because files with uncontrollable names "
-"will be created in this directory. Be sure to use a dedicated directory not "
-"used for anything but DVD key caching."
-msgstr ""
-"Puesto que rompler la protección de copia de DVDs crifrados puede consumir "
-"bastante tiempo, libdvdcss almacenará las claves rotas en éste directorio.\n"
-"Esta configuración es de seguridad crítica, porque en este directorio se "
-"crearán ficheros con nombres incontrolables. Asegúrse de usar un directorio "
-"dedicado que no se use para otra cosa excepto cacheado de claves de DVDs."
-
-#: src/input/input_dvd.c:1846
+#: src/input/input_dvd.c:1829
msgid "region the DVD player claims to be in (1 to 8)"
msgstr "Región a la cual el reproductor de DVDs dice pertenecer (1 a 8)"
-#: src/input/input_dvd.c:1847
+#: src/input/input_dvd.c:1830
msgid ""
"This only needs to be changed if your DVD jumps to a screen complaining "
"about a wrong region code. It has nothing to do with the region code set in "
@@ -1874,11 +1844,11 @@ msgstr ""
"código regional equivocado. No tiene nada ue ver con el código regional "
"puesto en los reproductores de DVD, esto es puramente software."
-#: src/input/input_dvd.c:1853
+#: src/input/input_dvd.c:1836
msgid "default language for DVD playback"
msgstr "idioma por defecto para reproducción de DVD"
-#: src/input/input_dvd.c:1854
+#: src/input/input_dvd.c:1837
msgid ""
"xine tries to use this language as a default for DVD playback. As far as the "
"DVD supports it, menus and audio tracks will be presented in this language.\n"
@@ -1889,11 +1859,11 @@ msgstr ""
"idioma.\n"
"El valor debe ser un código de idioma de dos caracteres según ISO639."
-#: src/input/input_dvd.c:1860
+#: src/input/input_dvd.c:1843
msgid "read-ahead caching"
msgstr "caché de lectura adelantada"
-#: src/input/input_dvd.c:1861
+#: src/input/input_dvd.c:1844
msgid ""
"xine can use a read ahead cache for DVD drive access.\n"
"This may lead to jerky playback on slow drives, but it improves the impact "
@@ -1903,11 +1873,11 @@ msgstr ""
"Esto puede dar lugar a reproducción a golpes en unidades lentas, pero mejora "
"el impacto del cambio de capa del DVD en unidades más rápidas."
-#: src/input/input_dvd.c:1867
+#: src/input/input_dvd.c:1850
msgid "unit for the skip action"
msgstr "unidad para la acción de salto (skip)"
-#: src/input/input_dvd.c:1868
+#: src/input/input_dvd.c:1851
msgid ""
"You can configure the behaviour when issuing a skip command (using the skip "
"buttons for example). The individual values mean:\n"
@@ -1943,11 +1913,11 @@ msgstr ""
"saltará un título del DVD, que es una unidad estructural representando "
"piezas completas en el DVD"
-#: src/input/input_dvd.c:1883
+#: src/input/input_dvd.c:1866
msgid "unit for seeking"
msgstr "unidad para búsqueda"
-#: src/input/input_dvd.c:1884
+#: src/input/input_dvd.c:1867
msgid ""
"You can configure the domain spanned by the seek slider. The individual "
"values mean:\n"
@@ -1972,11 +1942,11 @@ msgstr ""
"la busqueda abarcará un programa del DVD, que es una unidad navigacional "
"representando un capítulo de la feature actual"
-#: src/input/input_dvd.c:1895
+#: src/input/input_dvd.c:1878
msgid "play mode when title/chapter is given"
msgstr "modo de ejecución cuando se da el título/capítulo"
-#: src/input/input_dvd.c:1896
+#: src/input/input_dvd.c:1879
msgid ""
"You can configure the behaviour when playing a dvd from a given title/"
"chapter (eg. using MRL 'dvd:/1.2'). The individual values mean:\n"
@@ -2746,7 +2716,7 @@ msgstr ""
"1024: Cuadro congelado\n"
"2048: Depurando desde VCDINFO\n"
-#: src/liba52/xine_a52_decoder.c:742 src/libdts/xine_dts_decoder.c:546
+#: src/liba52/xine_a52_decoder.c:742 src/libxineadec/xine_dts_decoder.c:524
msgid "HELP! a mono-only audio driver?!\n"
msgstr "¡AYUDA! ¿¡Un manejador de audio exclusivamente mono-aural?!\n"
@@ -2809,72 +2779,72 @@ msgstr "libfaad: libfaad NeAACDecInit2 falló.\n"
msgid "libfaad: libfaad NeAACDecInit failed.\n"
msgstr "libfaad: libfaad NeAACDecInit falló.\n"
-#: src/libffmpeg/ff_audio_decoder.c:120
+#: src/libffmpeg/ff_audio_decoder.c:122
#, c-format
msgid "ffmpeg_audio_dec: increasing buffer to %d to avoid overflow.\n"
msgstr ""
"ffmpeg_audio_dec: incrementando el tamaño de la memoria tampón a %d para "
"evitar el desbordamiento.\n"
-#: src/libffmpeg/ff_audio_decoder.c:164
+#: src/libffmpeg/ff_audio_decoder.c:166
#, c-format
msgid "ffmpeg_audio_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"
msgstr ""
"ffmpeg_audio_dec: no pude encontrar el decodificador ffmpeg para el tipo de "
"tampón 0x%X\n"
-#: src/libffmpeg/ff_audio_decoder.c:256
+#: src/libffmpeg/ff_audio_decoder.c:258
#, fuzzy
msgid "ffmpeg_audio_dec: trying to open null codec\n"
msgstr "ffmpeg_audio_dec: no pude abrir el decodificador\n"
-#: src/libffmpeg/ff_audio_decoder.c:265
+#: src/libffmpeg/ff_audio_decoder.c:267
msgid "ffmpeg_audio_dec: couldn't open decoder\n"
msgstr "ffmpeg_audio_dec: no pude abrir el decodificador\n"
-#: src/libffmpeg/ff_dvaudio_decoder.c:286
+#: src/libffmpeg/ff_dvaudio_decoder.c:280
#, c-format
msgid "dvaudio: increasing buffer to %d to avoid overflow.\n"
msgstr ""
"dvaudio: incrementando el tamaño de la memoria tampón a %d para evitar el "
"desbordamiento.\n"
-#: src/libffmpeg/ff_video_decoder.c:157
+#: src/libffmpeg/ff_video_decoder.c:155
msgid "ffmpeg_video_dec: unsupported frame format, DR1 disabled.\n"
msgstr "ffmpeg_video_dec: formato de cuadro no soportado, DR1 desactivado.\n"
-#: src/libffmpeg/ff_video_decoder.c:175
+#: src/libffmpeg/ff_video_decoder.c:173
msgid "ffmpeg_video_dec: unsupported frame dimensions, DR1 disabled.\n"
msgstr ""
"ffmpeg_video_dec: dimensiones de cuadro no soportadas, DR1 desactivado.\n"
-#: src/libffmpeg/ff_video_decoder.c:335
+#: src/libffmpeg/ff_video_decoder.c:333
#, c-format
msgid "ffmpeg_video_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"
msgstr ""
"ffmpeg_video_dec: no pude encontrar el decodificador ffmpeg para el tipo de "
"tampón 0x%X\n"
-#: src/libffmpeg/ff_video_decoder.c:364
+#: src/libffmpeg/ff_video_decoder.c:362
msgid "ffmpeg_video_dec: couldn't open decoder\n"
msgstr "ffmpeg_video_dec: no pude abrir el decodificador\n"
-#: src/libffmpeg/ff_video_decoder.c:399
+#: src/libffmpeg/ff_video_decoder.c:397
msgid "ffmpeg_video_dec: direct rendering enabled\n"
msgstr "ffmpeg_video_dec: renderizado directo activado\n"
-#: src/libffmpeg/ff_video_decoder.c:818
+#: src/libffmpeg/ff_video_decoder.c:816
#, c-format
msgid "ffmpeg_video_dec: increasing buffer to %d to avoid overflow.\n"
msgstr ""
"ffmpeg_video_dec: incrementando el tamaño de la memoria tampón a %d para "
"evitar el desbordamiento.\n"
-#: src/libffmpeg/ff_video_decoder.c:1516
+#: src/libffmpeg/ff_video_decoder.c:1514
msgid "MPEG-4 postprocessing quality"
msgstr "calidad de postprocesado MPEG-4"
-#: src/libffmpeg/ff_video_decoder.c:1517
+#: src/libffmpeg/ff_video_decoder.c:1515
msgid ""
"You can adjust the amount of post processing applied to MPEG-4 video.\n"
"Higher values result in better quality, but need more CPU. Lower values may "
@@ -2888,11 +2858,11 @@ msgstr ""
"bloque. Para contenido de alta calidad, demasiado postprocesado puede de "
"hecho hacer la imagen peor emborronándola demasiado."
-#: src/libffmpeg/ffmpeg_encoder.c:167
+#: src/libffmpeg/ffmpeg_encoder.c:163
msgid "libavcodec mpeg output bitrate (kbit/s)"
msgstr "tasa de bits salida mpeg de libavcodec (kbit/s)"
-#: src/libffmpeg/ffmpeg_encoder.c:168
+#: src/libffmpeg/ffmpeg_encoder.c:164
msgid ""
"The bitrate the libavcodec mpeg encoder should use for DXR3's encoding mode. "
"Higher values will increase quality and CPU usage.\n"
@@ -2904,11 +2874,11 @@ msgstr ""
"Este ajuste sólo se considera cuando el modo de calidad constante está "
"desactivado."
-#: src/libffmpeg/ffmpeg_encoder.c:175
+#: src/libffmpeg/ffmpeg_encoder.c:171
msgid "constant quality mode"
msgstr "modo de calidad constante"
-#: src/libffmpeg/ffmpeg_encoder.c:176
+#: src/libffmpeg/ffmpeg_encoder.c:172
msgid ""
"When enabled, libavcodec will use a constant quality mode by dynamically "
"compressing the images based on their complexity. When disabled, libavcodec "
@@ -2918,39 +2888,39 @@ msgstr ""
"dinámicamente comprimiendo las imágenes basado en su complejidad. Cuando se "
"desactiva, libavcodec usará el modo de tasa de bits constante."
-#: src/libffmpeg/ffmpeg_encoder.c:183
+#: src/libffmpeg/ffmpeg_encoder.c:179
msgid "minimum compression"
msgstr "compresión mínima"
-#: src/libffmpeg/ffmpeg_encoder.c:184
+#: src/libffmpeg/ffmpeg_encoder.c:180
msgid "The minimum compression to apply to an image in constant quality mode."
msgstr ""
"La mínima compresión a aplicar a una imagen en el modo de calidad constante."
-#: src/libffmpeg/ffmpeg_encoder.c:189
+#: src/libffmpeg/ffmpeg_encoder.c:185
msgid "maximum quantizer"
msgstr "cuantificador máximo"
-#: src/libffmpeg/ffmpeg_encoder.c:190
+#: src/libffmpeg/ffmpeg_encoder.c:186
msgid "The maximum compression to apply to an image in constant quality mode."
msgstr ""
"La máxima compresión a aplicar a una imagen en modo de calidad constante."
-#: src/libmusepack/xine_musepack_decoder.c:241
+#: src/libxineadec/xine_musepack_decoder.c:249
#, c-format
msgid "libmusepack: mpc_streaminfo_read failed: %d\n"
msgstr "libmusepack: falló lectura mpc_streaminfo_read: %d\n"
-#: src/libmusepack/xine_musepack_decoder.c:315
+#: src/libxineadec/xine_musepack_decoder.c:323
msgid "libmusepack: data after last frame ignored\n"
msgstr "libmusepack: datos después de la última trama ignorados\n"
-#: src/libmusepack/xine_musepack_decoder.c:326
+#: src/libxineadec/xine_musepack_decoder.c:334
msgid "libmusepack: mpc_decoder_initialise failed\n"
msgstr "libmusepack: falló mpc_decoder_initialise\n"
-#: src/libmusepack/xine_musepack_decoder.c:346
-#: src/libmusepack/xine_musepack_decoder.c:361
+#: src/libxineadec/xine_musepack_decoder.c:354
+#: src/libxineadec/xine_musepack_decoder.c:369
#, c-format
msgid "libmusepack: mpc_decoder_decode failed: %d\n"
msgstr "libmusepack: falló mpc_decoder_decode: %d\n"
@@ -3914,7 +3884,7 @@ msgid "Select the video output layer by its id."
msgstr "Seleccione la capa de salida de vídeo por su id."
#: src/video_out/video_out_directfb.c:1804
-#: src/video_out/video_out_directfb.c:2013
+#: src/video_out/video_out_directfb.c:2014
#, fuzzy, c-format
msgid "video_out_directfb: using display layer #%d.\n"
msgstr ""
@@ -3924,13 +3894,13 @@ msgstr ""
msgid "xine video output plugin using DirectFB."
msgstr "complemento de xine de salida de vídeo usando DirectFB."
-#: src/video_out/video_out_directfb.c:2006
+#: src/video_out/video_out_directfb.c:2007
#, fuzzy
msgid "video_out_directfb: no usable display layer was found!\n"
msgstr ""
"video_out_directfb: ¡no se encontró una capa de superposición usable!\n"
-#: src/video_out/video_out_directfb.c:2095
+#: src/video_out/video_out_directfb.c:2096
msgid "xine video output plugin using DirectFB under XDirectFB."
msgstr "complemento de xine de salida de vídeo usando DirectFB bajo XDirectFB."
@@ -3938,7 +3908,7 @@ msgstr "complemento de xine de salida de vídeo usando DirectFB bajo XDirectFB."
msgid "xine video output plugin for win32 using directx"
msgstr "complemento de xine de salida de vídeo para win32 usando directx"
-#: src/video_out/video_out_fb.c:792
+#: src/video_out/video_out_fb.c:780
#, c-format
msgid ""
"video_out_fb: only packed truecolor/directcolor is supported (%d).\n"
@@ -3948,11 +3918,11 @@ msgstr ""
"directo) empaquetado (%d).\n"
" Compruebe 'fbset -i' o pruebe 'fbset -depth 16'.\n"
-#: src/video_out/video_out_fb.c:852 src/video_out/video_out_vidix.c:1239
+#: src/video_out/video_out_fb.c:840 src/video_out/video_out_vidix.c:1239
msgid "framebuffer device name"
msgstr "nombre del dispositivo framebuffer"
-#: src/video_out/video_out_fb.c:853 src/video_out/video_out_vidix.c:1240
+#: src/video_out/video_out_fb.c:841 src/video_out/video_out_vidix.c:1240
msgid ""
"Specifies the file name for the framebuffer device to be used.\n"
"This setting is security critical, because when changed to a different file, "
@@ -3966,20 +3936,20 @@ msgstr ""
"arbitrario. De modo que debería ser cuidadoso de que el valor que introduzca "
"es realmente un verdadero dispositivo framebuffer."
-#: src/video_out/video_out_fb.c:927
-msgid "video_out_fb: Your video mode was not recognized, sorry.\n"
+#: src/video_out/video_out_fb.c:915
+#, fuzzy, c-format
+msgid "%s: Your video mode was not recognized, sorry.\n"
msgstr "video_out_fb: Lo sentimos, su modo de vídeo no fue reconocido .\n"
-#: src/video_out/video_out_fb.c:984
-#, c-format
-msgid "video_out_fb: %d video RAM buffers are available.\n"
+#: src/video_out/video_out_fb.c:972
+#, fuzzy, c-format
+msgid "%s: %d video RAM buffers are available.\n"
msgstr "video_out_fb: están disponibles %d tampones de vídeo en RAM.\n"
-#: src/video_out/video_out_fb.c:990
-#, c-format
+#: src/video_out/video_out_fb.c:978
+#, fuzzy, c-format
msgid ""
-"WARNING: video_out_fb: Zero copy buffers are DISABLED because only %d "
-"buffers\n"
+"WARNING: %s: Zero copy buffers are DISABLED because only %d buffers\n"
" are available which is less than the recommended %d buffers. Lowering\n"
" the frame buffer resolution might help.\n"
msgstr ""
@@ -3989,10 +3959,10 @@ msgstr ""
"Disminuyendo\n"
" la resolución del tampón de cuadro podría ayudar.\n"
-#: src/video_out/video_out_fb.c:1001
-#, fuzzy
+#: src/video_out/video_out_fb.c:989
+#, fuzzy, c-format
msgid ""
-"WARNING: video_out_fb: Zero copy buffers are DISABLED because kernel driver\n"
+"WARNING: %s: Zero copy buffers are DISABLED because kernel driver\n"
" do not support screen panning (used for frame flips).\n"
msgstr ""
"AVISO: video_out_fb: Tampones Zero copy (copia Cero) están DESACTIVADOS "
@@ -4000,10 +3970,10 @@ msgstr ""
" no soporta panoramizado (panning) de pantalla (usado para volteos de "
"cuadro (frame flips)).\n"
-#: src/video_out/video_out_fb.c:1070
-#, c-format
+#: src/video_out/video_out_fb.c:1058
+#, fuzzy, c-format
msgid ""
-"WARNING: video_out_fb: current display depth is %d. For better performance\n"
+"WARNING: %s: current display depth is %d. For better performance\n"
" a depth of 16 bpp is recommended!\n"
"\n"
msgstr ""
@@ -4012,7 +3982,7 @@ msgstr ""
" se recomienda una profundidad de 16 bpp!\n"
"\n"
-#: src/video_out/video_out_fb.c:1101
+#: src/video_out/video_out_fb.c:1090
msgid "Xine video output plugin using the Linux frame buffer device"
msgstr ""
"Complemento de xine de salida de vídeo usando el dispositivo Linux tampón de "
@@ -4095,8 +4065,8 @@ msgstr ""
"Ignorado para rutinas estáticas de renderizado.\n"
#: src/video_out/video_out_opengl.c:1918 src/video_out/video_out_vidix.c:1015
-#: src/video_out/video_out_xcbxv.c:1472 src/video_out/video_out_xv.c:1486
-#: src/video_out/video_out_xvmc.c:1461 src/video_out/video_out_xxmc.c:2468
+#: src/video_out/video_out_xcbxv.c:1476 src/video_out/video_out_xv.c:1489
+#: src/video_out/video_out_xvmc.c:1461 src/video_out/video_out_xxmc.c:2465
msgid "enable double buffering"
msgstr "activar doble tamponeado"
@@ -4190,9 +4160,9 @@ msgstr ""
msgid "video_out_pgx64: Error: ioctl failed (FBIOGATTR)\n"
msgstr "video_out_pgx64: Error: falló ioctl (FBIOGATTR)\n"
-#: src/video_out/video_out_pgx64.c:1464 src/video_out/video_out_xcbxv.c:1439
-#: src/video_out/video_out_xv.c:1453 src/video_out/video_out_xvmc.c:1446
-#: src/video_out/video_out_xxmc.c:2435
+#: src/video_out/video_out_pgx64.c:1464 src/video_out/video_out_xcbxv.c:1443
+#: src/video_out/video_out_xv.c:1456 src/video_out/video_out_xvmc.c:1446
+#: src/video_out/video_out_xxmc.c:2432
msgid "video overlay colour key"
msgstr "llave de color de superposición de vídeo"
@@ -4356,9 +4326,9 @@ msgstr ""
msgid "The intensity of the blue colour components."
msgstr ""
-#: src/video_out/video_out_vidix.c:1016 src/video_out/video_out_xcbxv.c:1473
-#: src/video_out/video_out_xv.c:1487 src/video_out/video_out_xvmc.c:1462
-#: src/video_out/video_out_xxmc.c:2469
+#: src/video_out/video_out_vidix.c:1016 src/video_out/video_out_xcbxv.c:1477
+#: src/video_out/video_out_xv.c:1490 src/video_out/video_out_xvmc.c:1462
+#: src/video_out/video_out_xxmc.c:2466
msgid ""
"Double buffering will synchronize the update of the video image to the "
"repainting of the entire screen (\"vertical retrace\"). This eliminates "
@@ -4391,9 +4361,9 @@ msgid "video overlay colour key red component"
msgstr ""
#: src/video_out/video_out_vidix.c:1159 src/video_out/video_out_vidix.c:1166
-#: src/video_out/video_out_vidix.c:1173 src/video_out/video_out_xcbxv.c:1440
-#: src/video_out/video_out_xv.c:1454 src/video_out/video_out_xvmc.c:1447
-#: src/video_out/video_out_xxmc.c:2436
+#: src/video_out/video_out_vidix.c:1173 src/video_out/video_out_xcbxv.c:1444
+#: src/video_out/video_out_xv.c:1457 src/video_out/video_out_xvmc.c:1447
+#: src/video_out/video_out_xxmc.c:2433
msgid ""
"The colour key is used to tell the graphics card where to overlay the video "
"image. Try different values, if you experience windows becoming transparent."
@@ -4415,27 +4385,38 @@ msgstr ""
msgid "xine video output plugin using libvidix for linux frame buffer"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:157
+#: src/video_out/video_out_xcbshm.c:157 src/video_out/video_out_xshm.c:219
#, c-format
-msgid ""
-"video_out_xcbshm: %s: allocating image\n"
-"video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+msgid "%s: %s: allocating image\n"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:166
-msgid ""
-"video_out_xcbshm: shared memory error (address error) when allocating "
-"image \n"
-"video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbshm.c:159 src/video_out/video_out_xcbshm.c:169
+#: src/video_out/video_out_xcbshm.c:181 src/video_out/video_out_xcbxv.c:272
+#: src/video_out/video_out_xcbxv.c:282 src/video_out/video_out_xcbxv.c:292
+#: src/video_out/video_out_xcbxv.c:304 src/video_out/video_out_xshm.c:204
+#: src/video_out/video_out_xshm.c:221 src/video_out/video_out_xshm.c:232
+#: src/video_out/video_out_xshm.c:251 src/video_out/video_out_xv.c:296
+#: src/video_out/video_out_xv.c:307 src/video_out/video_out_xv.c:316
+#: src/video_out/video_out_xv.c:352 src/video_out/video_out_xxmc.c:648
+#: src/video_out/video_out_xxmc.c:659 src/video_out/video_out_xxmc.c:668
+#: src/video_out/video_out_xxmc.c:704
+#, c-format
+msgid "%s: => not using MIT Shared Memory extension.\n"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:177
-msgid ""
-"video_out_xcbshm: x11 error during shared memory XImage creation\n"
-"video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbshm.c:167 src/video_out/video_out_xshm.c:230
+#, c-format
+msgid "%s: shared memory error (address error) when allocating image \n"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:1100 src/video_out/video_out_xshm.c:1157
+#: src/video_out/video_out_xcbshm.c:179 src/video_out/video_out_xcbxv.c:302
+#: src/video_out/video_out_xshm.c:249 src/video_out/video_out_xv.c:350
+#: src/video_out/video_out_xxmc.c:702
+#, c-format
+msgid "%s: x11 error during shared memory XImage creation\n"
+msgstr ""
+
+#: src/video_out/video_out_xcbshm.c:1103 src/video_out/video_out_xshm.c:1161
#, c-format
msgid ""
"\n"
@@ -4445,74 +4426,75 @@ msgid ""
"\n"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:1113
-msgid "video_out_xcbshm: MIT shared memory extension not present on display.\n"
+#: src/video_out/video_out_xcbshm.c:1116 src/video_out/video_out_xshm.c:1174
+#, c-format
+msgid "%s: MIT shared memory extension not present on display.\n"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:1212
-#, fuzzy
-msgid "video_out_xcbshm: your video mode was not recognized, sorry :-(\n"
+#: src/video_out/video_out_xcbshm.c:1215 src/video_out/video_out_xshm.c:1258
+#, fuzzy, c-format
+msgid "%s: your video mode was not recognized, sorry :-(\n"
msgstr "video_out_fb: Lo sentimos, su modo de vídeo no fue reconocido .\n"
-#: src/video_out/video_out_xcbshm.c:1242 src/video_out/video_out_xshm.c:1303
+#: src/video_out/video_out_xcbshm.c:1245 src/video_out/video_out_xshm.c:1307
msgid "xine video output plugin using the MIT X shared memory extension"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:272
-msgid ""
-"video_out_xcbxv: XvShmCreateImage returned a zero size\n"
-"video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbxv.c:270 src/video_out/video_out_xv.c:305
+#: src/video_out/video_out_xxmc.c:657
+#, c-format
+msgid "%s: XvShmCreateImage returned a zero size\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:281
+#: src/video_out/video_out_xcbxv.c:280 src/video_out/video_out_xv.c:314
+#: src/video_out/video_out_xxmc.c:666
#, c-format
-msgid ""
-"video_out_xcbxv: shared memory error in shmget: %s\n"
-"video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+msgid "%s: shared memory error in shmget: %s\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:300
-msgid ""
-"video_out_xcbxv: x11 error during shared memory XImage creation\n"
-"video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbxv.c:290
+#, c-format
+msgid "%s: shared memory error (address error)\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1291
-msgid "video_out_xcbxv: Xv extension not present.\n"
+#: src/video_out/video_out_xcbxv.c:1294 src/video_out/video_out_xv.c:1301
+#: src/video_out/video_out_xxmc.c:2283
+#, c-format
+msgid "%s: Xv extension not present.\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1333
+#: src/video_out/video_out_xcbxv.c:1336 src/video_out/video_out_xv.c:1338
+#: src/video_out/video_out_xxmc.c:2320
+#, c-format
msgid ""
-"video_out_xcbxv: Xv extension is present but I couldn't find a usable yuv12 "
-"port.\n"
-" Looks like your graphics hardware driver doesn't support "
-"Xv?!\n"
+"%s: Xv extension is present but I couldn't find a usable yuv12 port.\n"
+"\tLooks like your graphics hardware driver doesn't support Xv?!\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1341
+#: src/video_out/video_out_xcbxv.c:1345
#, c-format
msgid ""
-"video_out_xcbxv: using Xv port %d from adaptor %s for hardware colorspace "
-"conversion and scaling.\n"
+"%s: using Xv port %d from adaptor %s for hardware colorspace conversion and "
+"scaling.\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1448 src/video_out/video_out_xv.c:1462
-#: src/video_out/video_out_xvmc.c:1455 src/video_out/video_out_xxmc.c:2444
+#: src/video_out/video_out_xcbxv.c:1452 src/video_out/video_out_xv.c:1465
+#: src/video_out/video_out_xvmc.c:1455 src/video_out/video_out_xxmc.c:2441
msgid "autopaint colour key"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1449 src/video_out/video_out_xv.c:1463
-#: src/video_out/video_out_xvmc.c:1456 src/video_out/video_out_xxmc.c:2445
+#: src/video_out/video_out_xcbxv.c:1453 src/video_out/video_out_xv.c:1466
+#: src/video_out/video_out_xvmc.c:1456 src/video_out/video_out_xxmc.c:2442
msgid "Make Xv autopaint its colorkey."
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1456 src/video_out/video_out_xv.c:1470
-#: src/video_out/video_out_xxmc.c:2452
+#: src/video_out/video_out_xcbxv.c:1460 src/video_out/video_out_xv.c:1473
+#: src/video_out/video_out_xxmc.c:2449
msgid "bilinear scaling mode"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1457 src/video_out/video_out_xv.c:1471
-#: src/video_out/video_out_xxmc.c:2453
+#: src/video_out/video_out_xcbxv.c:1461 src/video_out/video_out_xv.c:1474
+#: src/video_out/video_out_xxmc.c:2450
msgid ""
"Selects the bilinear scaling mode for Permedia cards. The individual values "
"are:\n"
@@ -4527,32 +4509,34 @@ msgid ""
"2 - enable full bilinear filtering"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1509
-#, fuzzy
-msgid "video_out_xcbxv: this adaptor supports the yv12 format.\n"
+#: src/video_out/video_out_xcbxv.c:1513 src/video_out/video_out_xv.c:1523
+#: src/video_out/video_out_xxmc.c:2506
+#, fuzzy, c-format
+msgid "%s: this adaptor supports the yv12 format.\n"
msgstr "video_out_directfb: ¡no se encontró una capa de salida usable!\n"
-#: src/video_out/video_out_xcbxv.c:1514
-#, fuzzy
-msgid "video_out_xcbxv: this adaptor supports the yuy2 format.\n"
+#: src/video_out/video_out_xcbxv.c:1518 src/video_out/video_out_xv.c:1528
+#: src/video_out/video_out_xxmc.c:2511
+#, fuzzy, c-format
+msgid "%s: this adaptor supports the yuy2 format.\n"
msgstr "video_out_directfb: ¡no se encontró una capa de salida usable!\n"
-#: src/video_out/video_out_xcbxv.c:1522 src/video_out/video_out_xv.c:1547
-#: src/video_out/video_out_xxmc.c:2537
+#: src/video_out/video_out_xcbxv.c:1526 src/video_out/video_out_xv.c:1550
+#: src/video_out/video_out_xxmc.c:2534
msgid "pitch alignment workaround"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1523 src/video_out/video_out_xv.c:1548
-#: src/video_out/video_out_xxmc.c:2538
+#: src/video_out/video_out_xcbxv.c:1527 src/video_out/video_out_xv.c:1551
+#: src/video_out/video_out_xxmc.c:2535
msgid "Some buggy video drivers need a workaround to function properly."
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1529 src/video_out/video_out_xv.c:1554
+#: src/video_out/video_out_xcbxv.c:1533 src/video_out/video_out_xv.c:1557
#: src/video_out/video_out_xvmc.c:1524
msgid "deinterlace method (deprecated)"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1530 src/video_out/video_out_xv.c:1555
+#: src/video_out/video_out_xcbxv.c:1534 src/video_out/video_out_xv.c:1558
#: src/video_out/video_out_xvmc.c:1525
msgid ""
"This config setting is deprecated. You should use the new deinterlacing post "
@@ -4591,93 +4575,26 @@ msgid ""
"with medium CPU usage."
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1584 src/video_out/video_out_xv.c:1628
-#: src/video_out/video_out_xxmc.c:2618
+#: src/video_out/video_out_xcbxv.c:1588 src/video_out/video_out_xv.c:1631
+#: src/video_out/video_out_xxmc.c:2615
msgid "xine video output plugin using the MIT X video extension"
msgstr ""
#: src/video_out/video_out_xshm.c:202
-msgid ""
-"video_out_xshm: shared memory error when allocating image\n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xshm.c:218
#, c-format
-msgid ""
-"video_out_xshm: %s: allocating image\n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xshm.c:228
-msgid ""
-"video_out_xshm: shared memory error (address error) when allocating image \n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xshm.c:245
-msgid ""
-"video_out_xshm: x11 error during shared memory XImage creation\n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xshm.c:1170
-msgid "video_out_xshm: MIT shared memory extension not present on display.\n"
-msgstr ""
-
-#: src/video_out/video_out_xshm.c:1254
-msgid "video_out_xshm: your video mode was not recognized, sorry :-(\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:296
-msgid ""
-"video_out_xv: XvShmCreateImage failed\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
+msgid "%s: shared memory error when allocating image\n"
msgstr ""
-#: src/video_out/video_out_xv.c:306
-msgid ""
-"video_out_xv: XvShmCreateImage returned a zero size\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:314
+#: src/video_out/video_out_xv.c:294 src/video_out/video_out_xxmc.c:646
#, c-format
-msgid ""
-"video_out_xv: shared memory error in shmget: %s\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:346
-msgid ""
-"video_out_xv: x11 error during shared memory XImage creation\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
+msgid "%s: XvShmCreateImage failed\n"
msgstr ""
-#: src/video_out/video_out_xv.c:1299
-msgid "video_out_xv: Xv extension not present.\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:1336
-msgid ""
-"video_out_xv: Xv extension is present but I couldn't find a usable yuv12 "
-"port.\n"
-" Looks like your graphics hardware driver doesn't support Xv?!\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:1345
+#: src/video_out/video_out_xv.c:1348 src/video_out/video_out_xxmc.c:2330
#, c-format
msgid ""
-"video_out_xv: using Xv port %ld from adaptor %s for hardware colorspace "
-"conversion and scaling.\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:1520
-msgid "video_out_xv: this adaptor supports the yv12 format.\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:1525
-msgid "video_out_xv: this adaptor supports the yuy2 format.\n"
+"%s: using Xv port %ld from adaptor %s for hardware colorspace conversion and "
+"scaling.\n"
msgstr ""
#: src/video_out/video_out_xvmc.c:1593
@@ -4718,94 +4635,43 @@ msgstr ""
msgid " With Overlay = %d; UnsignedIntra = %d.\n"
msgstr ""
-#: src/video_out/video_out_xxmc.c:650
-msgid ""
-"video_out_xxmc: XvShmCreateImage failed\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:660
-msgid ""
-"video_out_xxmc: XvShmCreateImage returned a zero size\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:668
-#, c-format
-msgid ""
-"video_out_xxmc: shared memory error in shmget: %s\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:700
-msgid ""
-"video_out_xxmc: x11 error during shared memory XImage creation\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:2287
-msgid "video_out_xxmc: Xv extension not present.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:2324
-msgid ""
-"video_out_xxmc: Xv extension is present but I couldn't find a usable yuv12 "
-"port.\n"
-" Looks like your graphics hardware driver doesn't support Xv?!\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:2333
-#, c-format
-msgid ""
-"video_out_xxmc: using Xv port %ld from adaptor %s for hardware colorspace "
-"conversion and scaling.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:2509
-msgid "video_out_xxmc: this adaptor supports the yv12 format.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:2514
-msgid "video_out_xxmc: this adaptor supports the yuy2 format.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:2543
+#: src/video_out/video_out_xxmc.c:2540
msgid "Make XvMC allocate more frames for better buffering."
msgstr ""
-#: src/video_out/video_out_xxmc.c:2544
+#: src/video_out/video_out_xxmc.c:2541
msgid ""
"Some XvMC implementations allow more than 8 frames.\n"
"This option, when turned on, makes the driver try to\n"
"allocate 15 frames. A must for unichrome and live VDR.\n"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2550
+#: src/video_out/video_out_xxmc.c:2547
msgid "Unichrome cpu save"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2551
+#: src/video_out/video_out_xxmc.c:2548
msgid ""
"Saves CPU time by sleeping while decoder works.\n"
"Only for Linux kernel 2.6 series or 2.4 with multimedia patch.\n"
"Experimental.\n"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2557
+#: src/video_out/video_out_xxmc.c:2554
msgid "Fix buggy NVIDIA XvMC subpicture colors"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2558
+#: src/video_out/video_out_xxmc.c:2555
msgid ""
"There's a bug in NVIDIA's XvMC lib that makes red OSD colors\n"
"look blue and vice versa. This option provides a workaround.\n"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2563
+#: src/video_out/video_out_xxmc.c:2560
msgid "Use bob as accelerated deinterlace method."
msgstr ""
-#: src/video_out/video_out_xxmc.c:2564
+#: src/video_out/video_out_xxmc.c:2561
msgid ""
"When interlacing is enabled for hardware accelerated frames,\n"
"Alternate between top and bottom field at double the frame rate.\n"
@@ -5031,12 +4897,12 @@ msgid ""
"info_helper: unsupported conversion %s -> UTF-8, no conversion performed\n"
msgstr ""
-#: src/xine-engine/input_cache.c:167
+#: src/xine-engine/input_cache.c:171
#, c-format
msgid ": open() function should never be called\n"
msgstr ""
-#: src/xine-engine/input_cache.c:349
+#: src/xine-engine/input_cache.c:353
#, c-format
msgid ": input plugin not defined!\n"
msgstr ""
@@ -5145,162 +5011,163 @@ msgstr ""
msgid "io_helper: Connection Refused\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:212
+#: src/xine-engine/load_plugins.c:215
#, c-format
msgid "map_decoder_list: no space for decoder, skipped.\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:327
+#: src/xine-engine/load_plugins.c:330
#, c-format
msgid ""
"load_plugins: ignoring plugin %s, wrong iface version %d (should be %d)\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:384
+#: src/xine-engine/load_plugins.c:387
#, c-format
msgid "priority for %s decoder"
msgstr ""
-#: src/xine-engine/load_plugins.c:395
+#: src/xine-engine/load_plugins.c:398
msgid ""
"The priority provides a ranking in case some media can be handled by more "
"than one decoder.\n"
"A priority of 0 enables the decoder's default priority."
msgstr ""
-#: src/xine-engine/load_plugins.c:423
+#: src/xine-engine/load_plugins.c:426
#, c-format
msgid ""
"load_plugins: demuxer plugin %s does not provide a priority, xine-lib will "
"use the default priority.\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:440
+#: src/xine-engine/load_plugins.c:443
#, c-format
msgid ""
"load_plugins: input plugin %s does not provide a priority, xine-lib will use "
"the default priority.\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:496
+#: src/xine-engine/load_plugins.c:499
#, c-format
msgid "load_plugins: plugin %s found\n"
msgstr "load_plugins: encontrado complemento %s\n"
-#: src/xine-engine/load_plugins.c:499
+#: src/xine-engine/load_plugins.c:502
#, c-format
msgid "load_plugins: static plugin found\n"
msgstr "load_plugins: encontrado complemento estático\n"
-#: src/xine-engine/load_plugins.c:506
+#: src/xine-engine/load_plugins.c:509
#, c-format
msgid "load_plugins: plugin limit reached, %s could not be loaded\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:509
+#: src/xine-engine/load_plugins.c:512
#, c-format
msgid "load_plugins: plugin limit reached, static plugin could not be loaded\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:526
+#: src/xine-engine/load_plugins.c:529
#, c-format
msgid "load_plugins: unknown plugin type %d in %s\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:530
+#: src/xine-engine/load_plugins.c:533
#, c-format
msgid "load_plugins: unknown statically linked plugin type %d\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:590
+#: src/xine-engine/load_plugins.c:593
#, c-format
msgid "load_plugins: unable to stat %s\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:631
+#: src/xine-engine/load_plugins.c:634
#, c-format
msgid ""
"load_plugins: cannot open plugin lib %s:\n"
"%s\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:646
+#: src/xine-engine/load_plugins.c:649
#, c-format
msgid ""
"load_plugins: can't get plugin info from %s:\n"
"%s\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:664
+#: src/xine-engine/load_plugins.c:667
#, c-format
msgid "load_plugins: skipping unreadable plugin directory %s.\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:713
+#: src/xine-engine/load_plugins.c:716
#, c-format
msgid ""
"load_plugins: cannot (stage 2) open plugin lib %s:\n"
"%s\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:739
+#: src/xine-engine/load_plugins.c:742
#, c-format
msgid "load_plugins: Yikes! %s doesn't contain plugin info.\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:1305
+#: src/xine-engine/load_plugins.c:1104 src/xine-engine/load_plugins.c:1113
+#, fuzzy, c-format
+msgid "Unable to create %s directory: %s\n"
+msgstr "Incapaz de crear el objeto de sonido directo."
+
+#: src/xine-engine/load_plugins.c:1345
#, c-format
msgid "load_plugins: unknown content detection strategy %d\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:1415
+#: src/xine-engine/load_plugins.c:1455
#, c-format
msgid "load_plugins: using demuxer '%s'\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:1726
+#: src/xine-engine/load_plugins.c:1766
#, c-format
msgid "load_plugins: failed to load audio output plugin <%s>\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:1729
+#: src/xine-engine/load_plugins.c:1769
msgid ""
"load_plugins: audio output auto-probing didn't find any usable audio "
"driver.\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:2033
+#: src/xine-engine/load_plugins.c:2073
#, c-format
msgid ""
"load_plugins: cannot unload plugin lib %s:\n"
"%s\n"
msgstr ""
-#: src/xine-engine/osd.c:745
+#: src/xine-engine/osd.c:747
#, c-format
msgid "font '%s-%d' already loaded, weird.\n"
msgstr ""
-#: src/xine-engine/osd.c:757
+#: src/xine-engine/osd.c:759
#, c-format
msgid "font '%s' loading failed (%d < %d)\n"
msgstr ""
-#: src/xine-engine/osd.c:767
+#: src/xine-engine/osd.c:769
#, c-format
msgid "wrong version for font '%s'. expected %d found %d.\n"
msgstr ""
-#: src/xine-engine/osd.c:834
-msgid "osd: cannot initialize ft2 library\n"
-msgstr ""
-
-#: src/xine-engine/osd.c:857
+#: src/xine-engine/osd.c:856
#, c-format
msgid "osd: error matching font %s with FontConfig"
msgstr ""
-#: src/xine-engine/osd.c:871
+#: src/xine-engine/osd.c:870
#, c-format
msgid "osd: error loading font %s with FontConfig"
msgstr ""
@@ -5310,57 +5177,61 @@ msgstr ""
msgid "osd: error looking up font %s with FontConfig"
msgstr ""
-#: src/xine-engine/osd.c:895
+#: src/xine-engine/osd.c:914
#, c-format
-msgid "osd: error loading font %s with ft2\n"
+msgid "osd: error loading font %s with in XDG data directories.\n"
msgstr ""
-#: src/xine-engine/osd.c:905
+#: src/xine-engine/osd.c:923
+msgid "osd: cannot initialize ft2 library\n"
+msgstr ""
+
+#: src/xine-engine/osd.c:945
msgid "osd: error setting font size (no scalable font?)\n"
msgstr ""
-#: src/xine-engine/osd.c:1021
+#: src/xine-engine/osd.c:1061
#, c-format
msgid ""
"osd: unknown sequence starting with byte 0x%02X in encoding \"%s\", "
"skipping\n"
msgstr ""
-#: src/xine-engine/osd.c:1077
+#: src/xine-engine/osd.c:1117
msgid "osd: can't find out current locale character set\n"
msgstr ""
-#: src/xine-engine/osd.c:1087
+#: src/xine-engine/osd.c:1127
#, c-format
msgid "osd: unsupported conversion %s -> %s, no conversion performed\n"
msgstr ""
-#: src/xine-engine/osd.c:1142 src/xine-engine/osd.c:1310
+#: src/xine-engine/osd.c:1182 src/xine-engine/osd.c:1350
msgid "osd: font isn't defined\n"
msgstr ""
-#: src/xine-engine/osd.c:1181
+#: src/xine-engine/osd.c:1221
msgid "osd: error loading glyph\n"
msgstr ""
-#: src/xine-engine/osd.c:1187
+#: src/xine-engine/osd.c:1227
msgid "osd: error in rendering glyph\n"
msgstr ""
-#: src/xine-engine/osd.c:1347
+#: src/xine-engine/osd.c:1387
#, c-format
msgid "osd: error loading glyph %i\n"
msgstr ""
-#: src/xine-engine/osd.c:1354
+#: src/xine-engine/osd.c:1394
msgid "osd: error in rendering\n"
msgstr ""
-#: src/xine-engine/osd.c:1611
+#: src/xine-engine/osd.c:1660
msgid "palette (foreground-border-background) to use for subtitles and OSD"
msgstr ""
-#: src/xine-engine/osd.c:1612
+#: src/xine-engine/osd.c:1661
msgid ""
"The palette for on-screen-display and some subtitle formats that do not "
"specify any colouring themselves. The palettes are listed in the form: "
@@ -5474,127 +5345,127 @@ msgid ""
"accelerated, this can dramatically reduce CPU usage."
msgstr ""
-#: src/xine-engine/xine.c:704 src/xine-engine/xine.c:811
-#: src/xine-engine/xine.c:850 src/xine-engine/xine.c:886
-#: src/xine-engine/xine.c:898 src/xine-engine/xine.c:911
-#: src/xine-engine/xine.c:924 src/xine-engine/xine.c:937
-#: src/xine-engine/xine.c:963 src/xine-engine/xine.c:988
-#: src/xine-engine/xine.c:1023
+#: src/xine-engine/xine.c:706 src/xine-engine/xine.c:813
+#: src/xine-engine/xine.c:852 src/xine-engine/xine.c:888
+#: src/xine-engine/xine.c:900 src/xine-engine/xine.c:913
+#: src/xine-engine/xine.c:926 src/xine-engine/xine.c:939
+#: src/xine-engine/xine.c:965 src/xine-engine/xine.c:990
+#: src/xine-engine/xine.c:1025
msgid "xine: error while parsing mrl\n"
msgstr ""
-#: src/xine-engine/xine.c:740
+#: src/xine-engine/xine.c:742
#, c-format
msgid "xine: found input plugin : %s\n"
msgstr ""
-#: src/xine-engine/xine.c:758
+#: src/xine-engine/xine.c:760
#, c-format
msgid "xine: input plugin cannot open MRL [%s]\n"
msgstr ""
-#: src/xine-engine/xine.c:774
+#: src/xine-engine/xine.c:776
#, c-format
msgid "xine: cannot find input plugin for MRL [%s]\n"
msgstr "xine: no se puede encontrar el complemento de entrada para MRL [%s]\n"
-#: src/xine-engine/xine.c:800
+#: src/xine-engine/xine.c:802
#, c-format
msgid "xine: specified demuxer %s failed to start\n"
msgstr "xine_play: fallo al iniciar el demultiplexor %s especificado\n"
-#: src/xine-engine/xine.c:836
+#: src/xine-engine/xine.c:838
#, c-format
msgid "xine: join rip input plugin\n"
msgstr ""
-#: src/xine-engine/xine.c:843
+#: src/xine-engine/xine.c:845
msgid "xine: error opening rip input plugin instance\n"
msgstr ""
-#: src/xine-engine/xine.c:874
+#: src/xine-engine/xine.c:876
#, c-format
msgid "xine: last_probed demuxer %s failed to start\n"
msgstr ""
-#: src/xine-engine/xine.c:903
+#: src/xine-engine/xine.c:905
msgid "ignoring video\n"
msgstr ""
-#: src/xine-engine/xine.c:916
+#: src/xine-engine/xine.c:918
msgid "ignoring audio\n"
msgstr ""
-#: src/xine-engine/xine.c:929
+#: src/xine-engine/xine.c:931
msgid "ignoring subpicture\n"
msgstr ""
-#: src/xine-engine/xine.c:942
+#: src/xine-engine/xine.c:944
msgid "input cache plugin disabled\n"
msgstr ""
-#: src/xine-engine/xine.c:1013
+#: src/xine-engine/xine.c:1015
#, c-format
msgid "subtitle mrl opened '%s'\n"
msgstr ""
-#: src/xine-engine/xine.c:1017
+#: src/xine-engine/xine.c:1019
msgid "xine: error opening subtitle mrl\n"
msgstr ""
-#: src/xine-engine/xine.c:1049
+#: src/xine-engine/xine.c:1051
#, c-format
msgid "xine: error while parsing MRL\n"
msgstr ""
-#: src/xine-engine/xine.c:1056
+#: src/xine-engine/xine.c:1058
#, c-format
msgid "xine: changing option '%s' from MRL isn't permitted\n"
msgstr ""
-#: src/xine-engine/xine.c:1076
+#: src/xine-engine/xine.c:1078
#, c-format
msgid "xine: couldn't find demux for >%s<\n"
msgstr "xine: no se pudo encontrar un demultiplexor para >%s<\n"
-#: src/xine-engine/xine.c:1092
+#: src/xine-engine/xine.c:1094
#, c-format
msgid "xine: found demuxer plugin: %s\n"
msgstr "xine: encontrado complemento demultiplexor: %s\n"
-#: src/xine-engine/xine.c:1112
+#: src/xine-engine/xine.c:1114
#, c-format
msgid "xine: demuxer failed to start\n"
msgstr "xine: fallo al iniciar el demultiplexor\n"
-#: src/xine-engine/xine.c:1177
+#: src/xine-engine/xine.c:1179
#, c-format
msgid "xine_play: no demux available\n"
msgstr "xine_play: no hay disponible un demultiplexor\n"
-#: src/xine-engine/xine.c:1247
+#: src/xine-engine/xine.c:1249
#, c-format
msgid "xine_play: demux failed to start\n"
msgstr "xine_play: fallo al iniciar el demultiplexor\n"
-#: src/xine-engine/xine.c:1523
+#: src/xine-engine/xine.c:1527
#, c-format
msgid "xine: The specified save_dir \"%s\" might be a security risk.\n"
msgstr ""
-#: src/xine-engine/xine.c:1528
+#: src/xine-engine/xine.c:1532
msgid "The specified save_dir might be a security risk."
msgstr ""
-#: src/xine-engine/xine.c:1554
+#: src/xine-engine/xine.c:1561
msgid "xine: locale not supported by C library\n"
msgstr ""
-#: src/xine-engine/xine.c:1563
+#: src/xine-engine/xine.c:1570
msgid "media format detection strategy"
msgstr ""
-#: src/xine-engine/xine.c:1564
+#: src/xine-engine/xine.c:1571
msgid ""
"xine offers various methods to detect the media format of input to play. The "
"individual values are:\n"
@@ -5612,11 +5483,11 @@ msgid ""
"Detect by file name extension only.\n"
msgstr ""
-#: src/xine-engine/xine.c:1582
+#: src/xine-engine/xine.c:1589
msgid "directory for saving streams"
msgstr ""
-#: src/xine-engine/xine.c:1583
+#: src/xine-engine/xine.c:1590
msgid ""
"When using the stream save feature, files will be written only into this "
"directory.\n"
@@ -5626,11 +5497,11 @@ msgid ""
"content in any file."
msgstr ""
-#: src/xine-engine/xine.c:1594
+#: src/xine-engine/xine.c:1601
msgid "allow implicit changes to the configuration (e.g. by MRL)"
msgstr ""
-#: src/xine-engine/xine.c:1595
+#: src/xine-engine/xine.c:1602
msgid ""
"If enabled, you allow xine to change your configuration without explicit "
"actions from your side. For example configuration changes demanded by MRLs "
@@ -5640,26 +5511,26 @@ msgid ""
"configuration, you might end with a totally messed up xine."
msgstr ""
-#: src/xine-engine/xine.c:1609
+#: src/xine-engine/xine.c:1616
msgid "Timeout for network stream reading (in seconds)"
msgstr ""
-#: src/xine-engine/xine.c:1610
+#: src/xine-engine/xine.c:1617
msgid ""
"Specifies the timeout when reading from network streams, in seconds. Too low "
"values might stop streaming when the source is slow or the bandwidth is "
"occupied, too high values will freeze the player if the connection is lost."
msgstr ""
-#: src/xine-engine/xine.c:1962
+#: src/xine-engine/xine.c:1969
msgid "messages"
msgstr "mensajes"
-#: src/xine-engine/xine.c:1963
+#: src/xine-engine/xine.c:1970
msgid "plugin"
msgstr "complemento"
-#: src/xine-engine/xine.c:1964
+#: src/xine-engine/xine.c:1971
msgid "trace"
msgstr "traza"
@@ -5734,3 +5605,41 @@ msgstr ""
#: src/xine-utils/memcpy.c:507
msgid "Benchmarking memcpy methods (smaller is better):\n"
msgstr ""
+
+#, fuzzy
+#~ msgid "video_out_xcbshm: your video mode was not recognized, sorry :-(\n"
+#~ msgstr "video_out_fb: Lo sentimos, su modo de vídeo no fue reconocido .\n"
+
+#~ msgid "CDDB cache directory"
+#~ msgstr "directorio caché del CDDB"
+
+#~ msgid ""
+#~ "The replies from the CDDB server will be cached in this directory.\n"
+#~ "This setting is security critical, because files with uncontrollable "
+#~ "names will be created in this directory. Be sure to use a dedicated "
+#~ "directory not used for anything but CDDB caching."
+#~ msgstr ""
+#~ "Las respuestas del servidor CDDB serán almacenadas temporalmente en este "
+#~ "directorio.\n"
+#~ "Esta configuración es crítica para su seguridad, porque nombres sin "
+#~ "control serán creados en este directorio. Asegúrese de poner un "
+#~ "directorio dedicado que no se use para ninguna otra cosa que el cacheado "
+#~ "del CDDB."
+
+#~ msgid "path to the title key cache"
+#~ msgstr "camino al caché de claves de títulos"
+
+#~ msgid ""
+#~ "Since cracking the copy protection of scrambled DVDs can be quite time "
+#~ "consuming, libdvdcss will cache the cracked keys in this directory.\n"
+#~ "This setting is security critical, because files with uncontrollable "
+#~ "names will be created in this directory. Be sure to use a dedicated "
+#~ "directory not used for anything but DVD key caching."
+#~ msgstr ""
+#~ "Puesto que rompler la protección de copia de DVDs crifrados puede "
+#~ "consumir bastante tiempo, libdvdcss almacenará las claves rotas en éste "
+#~ "directorio.\n"
+#~ "Esta configuración es de seguridad crítica, porque en este directorio se "
+#~ "crearán ficheros con nombres incontrolables. Asegúrse de usar un "
+#~ "directorio dedicado que no se use para otra cosa excepto cacheado de "
+#~ "claves de DVDs."
diff --git a/po/eu.po b/po/eu.po
index c148ef600..c9feed8a7 100644
--- a/po/eu.po
+++ b/po/eu.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: xine-lib-1\n"
"Report-Msgid-Bugs-To: xine-devel@lists.sourceforge.net\n"
-"POT-Creation-Date: 2007-04-06 15:39+0200\n"
+"POT-Creation-Date: 2007-04-24 21:48+0100\n"
"PO-Revision-Date: 2005-02-17 14:29+0100\n"
"Last-Translator: Piarres Beobide <pi@beobide.net>\n"
"Language-Team: lubrezale <librezale@librezale.org>\n"
@@ -43,22 +43,22 @@ msgstr "Ostalari izen ebazketak huts egin du"
msgid "Unknown error"
msgstr "Errore ezezaguna"
-#: src/audio_out/audio_alsa_out.c:354
+#: src/audio_out/audio_alsa_out.c:351
#, c-format
msgid "audio_alsa_out:Already open...WHY!"
msgstr "audio_alsa_out:Dagoeneko irekirik...ZERGATIK!"
-#: src/audio_out/audio_alsa_out.c:382
+#: src/audio_out/audio_alsa_out.c:379
#, c-format
msgid "audio_alsa_out: snd_pcm_open() of %s failed: %s\n"
msgstr "%s audio_alsa_out: snd_pcm_open()-ek huts egin du: %s\n"
-#: src/audio_out/audio_alsa_out.c:384
+#: src/audio_out/audio_alsa_out.c:381
msgid "audio_alsa_out: >>> check if another program already uses PCM <<<\n"
msgstr ""
"audio_alsa_out: >>> Egiaztatu beste programa batek PCM darabilkien<<<\n"
-#: src/audio_out/audio_alsa_out.c:397
+#: src/audio_out/audio_alsa_out.c:394
#, c-format
msgid ""
"audio_alsa_out: broken configuration for this PCM: no configurations "
@@ -67,11 +67,11 @@ msgstr ""
"audio_alsa_out: PCM onentzat apurturiko konfigurazioa: Ez dago konfigurazio "
"erabilgarririk: %s\n"
-#: src/audio_out/audio_alsa_out.c:1289
+#: src/audio_out/audio_alsa_out.c:1286
msgid "notify changes to the hardware mixer"
msgstr "hardware nahasleari aldaketen berri eman"
-#: src/audio_out/audio_alsa_out.c:1290
+#: src/audio_out/audio_alsa_out.c:1287
msgid ""
"When the hardware mixer changes, your application will receive a "
"notification so that it can update its graphical representation of the mixer "
@@ -80,16 +80,16 @@ msgstr ""
"Hardware nahaslea aldatzerakoan, zure aplikazioak honen berri jasoko du eta "
"nahaslearen irudi grafikoa denbora errealean eraldatuko du."
-#: src/audio_out/audio_alsa_out.c:1355
+#: src/audio_out/audio_alsa_out.c:1352
#, c-format
msgid "snd_lib_error_set_handler() failed: %d"
msgstr "snd_lib_error_set_handler() hutsa: %d"
-#: src/audio_out/audio_alsa_out.c:1362
+#: src/audio_out/audio_alsa_out.c:1359
msgid "sound card can do mmap"
msgstr "soinu txartelak mmap egin dezake"
-#: src/audio_out/audio_alsa_out.c:1363
+#: src/audio_out/audio_alsa_out.c:1360
msgid ""
"Enable this, if your sound card and alsa driver support memory mapped IO.\n"
"You can try enabling it and check, if everything works. If it does, this "
@@ -100,11 +100,11 @@ msgstr ""
"Gaitu eta frogaru dezakezu beldurrik gabe, denak behar bezala funtzionatu "
"ezkero portamoldea obetuko du."
-#: src/audio_out/audio_alsa_out.c:1372
+#: src/audio_out/audio_alsa_out.c:1369
msgid "device used for mono output"
msgstr "mono irteerarako erabiliko den gailua"
-#: src/audio_out/audio_alsa_out.c:1373
+#: src/audio_out/audio_alsa_out.c:1370
msgid ""
"xine will use this alsa device to output mono sound.\n"
"See the alsa documentation for information on alsa devices."
@@ -113,11 +113,11 @@ msgstr ""
"Irakurri alsa dokumentazioa alsa gailuei buruzko informazio gehiago behar "
"izan ezkero."
-#: src/audio_out/audio_alsa_out.c:1381
+#: src/audio_out/audio_alsa_out.c:1378
msgid "device used for stereo output"
msgstr "Estereo irteerak erabiltzen duen gailua"
-#: src/audio_out/audio_alsa_out.c:1382
+#: src/audio_out/audio_alsa_out.c:1379
msgid ""
"xine will use this alsa device to output stereo sound.\n"
"See the alsa documentation for information on alsa devices."
@@ -126,11 +126,11 @@ msgstr ""
"Irakurri alsa dokumentazioa alsa gailuei buruzko informazio gehiago behar "
"izan ezkero."
-#: src/audio_out/audio_alsa_out.c:1390
+#: src/audio_out/audio_alsa_out.c:1387
msgid "device used for 4-channel output"
msgstr "4 kanaletako irteerak erabiltzen duen gailua"
-#: src/audio_out/audio_alsa_out.c:1391
+#: src/audio_out/audio_alsa_out.c:1388
msgid ""
"xine will use this alsa device to output 4 channel (4.0) surround sound.\n"
"See the alsa documentation for information on alsa devices."
@@ -139,11 +139,11 @@ msgstr ""
"Irakurri alsa dokumentazioa alsa gailei buruzko informazio gehiago behar "
"izan ezkero."
-#: src/audio_out/audio_alsa_out.c:1400 src/audio_out/audio_alsa_out.c:1410
+#: src/audio_out/audio_alsa_out.c:1397 src/audio_out/audio_alsa_out.c:1407
msgid "device used for 5.1-channel output"
msgstr "5.1 kanaletako irteerak erabiltzen duen gailua"
-#: src/audio_out/audio_alsa_out.c:1401
+#: src/audio_out/audio_alsa_out.c:1398
msgid ""
"xine will use this alsa device to output 5 channel plus LFE (5.1) surround "
"sound.\n"
@@ -153,7 +153,7 @@ msgstr ""
"Irakurri alsa dokumentazioa alsa gailei buruzko informazio gehiago behar "
"izan ezkero."
-#: src/audio_out/audio_alsa_out.c:1411
+#: src/audio_out/audio_alsa_out.c:1408
msgid ""
"xine will use this alsa device to output undecoded digital surround sound. "
"This can be used be external surround decoders.\n"
@@ -163,21 +163,21 @@ msgstr ""
"hau kanpo ingurugiro dekodifikatzaileez erabil daiteke.\n"
"Begiratu alsa dokumentazioa argibide gehiagorako."
-#: src/audio_out/audio_alsa_out.c:1431
+#: src/audio_out/audio_alsa_out.c:1428
#, c-format
msgid "snd_pcm_open() failed:%d:%s\n"
msgstr "snd_pcm_open()-ek huts egin du:%d:%s\n"
-#: src/audio_out/audio_alsa_out.c:1433
+#: src/audio_out/audio_alsa_out.c:1430
#, c-format
msgid ">>> Check if another program already uses PCM <<<\n"
msgstr ">>> Egiaztatu beste programa batek PCM darabilkien<<<\n"
-#: src/audio_out/audio_alsa_out.c:1464 src/audio_out/audio_oss_out.c:929
+#: src/audio_out/audio_alsa_out.c:1461 src/audio_out/audio_oss_out.c:929
msgid "speaker arrangement"
msgstr "bozgorailu ordenamendua"
-#: src/audio_out/audio_alsa_out.c:1465 src/audio_out/audio_oss_out.c:930
+#: src/audio_out/audio_alsa_out.c:1462 src/audio_out/audio_oss_out.c:930
msgid ""
"Select how your speakers are arranged, this determines which speakers xine "
"uses for sound output. The individual values are:\n"
@@ -236,79 +236,79 @@ msgstr ""
"xine. You need to connect a digital surround decoder capable of decoding the "
"formats you want to play to your sound card's digital output."
-#: src/audio_out/audio_alsa_out.c:1494
+#: src/audio_out/audio_alsa_out.c:1491
msgid "audio_alsa_out : supported modes are "
msgstr "audio_alsa_out : Onartutako moduak: "
-#: src/audio_out/audio_alsa_out.c:1497
+#: src/audio_out/audio_alsa_out.c:1494
msgid "8bit "
msgstr "8bit "
-#: src/audio_out/audio_alsa_out.c:1502
+#: src/audio_out/audio_alsa_out.c:1499
msgid "16bit "
msgstr "16bit "
-#: src/audio_out/audio_alsa_out.c:1506
+#: src/audio_out/audio_alsa_out.c:1503
msgid "24bit "
msgstr "24bit "
-#: src/audio_out/audio_alsa_out.c:1510
+#: src/audio_out/audio_alsa_out.c:1507
msgid "32bit "
msgstr "32bit "
-#: src/audio_out/audio_alsa_out.c:1521
+#: src/audio_out/audio_alsa_out.c:1518
msgid "mono "
msgstr "mono "
-#: src/audio_out/audio_alsa_out.c:1525
+#: src/audio_out/audio_alsa_out.c:1522
msgid "stereo "
msgstr "estereo "
-#: src/audio_out/audio_alsa_out.c:1530
+#: src/audio_out/audio_alsa_out.c:1527
msgid "4-channel "
msgstr "4-kanal "
-#: src/audio_out/audio_alsa_out.c:1533
+#: src/audio_out/audio_alsa_out.c:1530
msgid "(4-channel not enabled in xine config) "
msgstr "(4-kanal ez dago gaiturik xine konfigruaketan)"
-#: src/audio_out/audio_alsa_out.c:1538
+#: src/audio_out/audio_alsa_out.c:1535
msgid "4.1-channel "
msgstr "4.1-kanal "
-#: src/audio_out/audio_alsa_out.c:1541
+#: src/audio_out/audio_alsa_out.c:1538
msgid "(4.1-channel not enabled in xine config) "
msgstr "(4.1-kanal ez dago gaiturik xine konfigruaketan)"
-#: src/audio_out/audio_alsa_out.c:1546
+#: src/audio_out/audio_alsa_out.c:1543
msgid "5-channel "
msgstr "5-kanal "
-#: src/audio_out/audio_alsa_out.c:1549
+#: src/audio_out/audio_alsa_out.c:1546
msgid "(5-channel not enabled in xine config) "
msgstr "(5-kanal ez dago gaiturik xine konfigruaketan)"
-#: src/audio_out/audio_alsa_out.c:1554
+#: src/audio_out/audio_alsa_out.c:1551
msgid "5.1-channel "
msgstr "5.1-kanal "
-#: src/audio_out/audio_alsa_out.c:1557
+#: src/audio_out/audio_alsa_out.c:1554
msgid "(5.1-channel not enabled in xine config) "
msgstr "(5.1-kanal ez dago gaiturik xine konfigruaketan)"
-#: src/audio_out/audio_alsa_out.c:1580
+#: src/audio_out/audio_alsa_out.c:1577
msgid "a/52 and DTS pass-through\n"
msgstr "a/52 eta DTS pass-through\n"
-#: src/audio_out/audio_alsa_out.c:1583
+#: src/audio_out/audio_alsa_out.c:1580
msgid "(a/52 and DTS pass-through not enabled in xine config)\n"
msgstr "(a/52 eta DTS pass-through ez daude gaiturik xine konfiguraketan)\n"
-#: src/audio_out/audio_alsa_out.c:1590
+#: src/audio_out/audio_alsa_out.c:1587
msgid "alsa mixer device"
msgstr "alsa nahasle gailua"
-#: src/audio_out/audio_alsa_out.c:1591
+#: src/audio_out/audio_alsa_out.c:1588
msgid ""
"xine will use this alsa mixer device to change the volume.\n"
"See the alsa documentation for information on alsa devices."
@@ -316,7 +316,7 @@ msgstr ""
"xinek alsa nahaslea erabiliko du bolumena aldatzeko.\n"
"Begiratu alsa dokumentazioa alsa gailueri buruzko argibideentzat."
-#: src/audio_out/audio_alsa_out.c:1665
+#: src/audio_out/audio_alsa_out.c:1662
msgid "xine audio output plugin using alsa-compliant audio devices/drivers"
msgstr ""
"xine audio irteera plugina alsa-konpilaturiko audio gailu/kontrolatzailea "
@@ -330,206 +330,206 @@ msgstr "xine audio irteera plugina kde artsd erabiliaz"
msgid "xine output plugin for Coreaudio/Mac OS X"
msgstr "xine irteera plugina Coreaudio/Mac OS X-entzat"
-#: src/audio_out/audio_directx2_out.c:166
+#: src/audio_out/audio_directx2_out.c:163
#, fuzzy
msgid "Error"
msgstr "Errorerik ez"
-#: src/audio_out/audio_directx2_out.c:173
+#: src/audio_out/audio_directx2_out.c:170
msgid "success"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:175
+#: src/audio_out/audio_directx2_out.c:172
msgid "access denied"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:177
+#: src/audio_out/audio_directx2_out.c:174
msgid "resource is already in use"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:178
+#: src/audio_out/audio_directx2_out.c:175
msgid "object was already initialized"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:179
+#: src/audio_out/audio_directx2_out.c:176
msgid "specified wave format is not supported"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:180
+#: src/audio_out/audio_directx2_out.c:177
msgid "memory buffer has been lost and must be restored"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:181
+#: src/audio_out/audio_directx2_out.c:178
#, fuzzy
msgid "requested buffer control is not available"
msgstr "eskatutako botoia ez da erabilgarri\n"
-#: src/audio_out/audio_directx2_out.c:182
+#: src/audio_out/audio_directx2_out.c:179
msgid "undetermined error inside DirectSound subsystem"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:184
+#: src/audio_out/audio_directx2_out.c:181
#, fuzzy
msgid "DirectSound hardware device is unavailable"
msgstr "Erabili hardware azelerazioa eskuragarri badago"
-#: src/audio_out/audio_directx2_out.c:186
+#: src/audio_out/audio_directx2_out.c:183
msgid "function is not valid for the current state of the object"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:187
+#: src/audio_out/audio_directx2_out.c:184
msgid "invalid parameter was passed"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:188
+#: src/audio_out/audio_directx2_out.c:185
msgid "object doesn't support aggregation"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:189
+#: src/audio_out/audio_directx2_out.c:186
msgid "no sound driver available for use"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:190
+#: src/audio_out/audio_directx2_out.c:187
#, fuzzy
msgid "requested COM interface not available"
msgstr "eskatutako botoia ez da erabilgarri\n"
-#: src/audio_out/audio_directx2_out.c:191
+#: src/audio_out/audio_directx2_out.c:188
msgid "another application has a higher priority level"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:192
+#: src/audio_out/audio_directx2_out.c:189
msgid "insufficient memory"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:193
+#: src/audio_out/audio_directx2_out.c:190
msgid "low priority level for this function"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:194
+#: src/audio_out/audio_directx2_out.c:191
msgid "DirectSound wasn't initialized"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:195
+#: src/audio_out/audio_directx2_out.c:192
msgid "function is not supported"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:196
+#: src/audio_out/audio_directx2_out.c:193
#, fuzzy
msgid "unknown error"
msgstr "Errore ezezaguna"
-#: src/audio_out/audio_directx2_out.c:206
+#: src/audio_out/audio_directx2_out.c:203
#, c-format
msgid "Unable to create direct sound object."
msgstr ""
-#: src/audio_out/audio_directx2_out.c:212
+#: src/audio_out/audio_directx2_out.c:209
#, c-format
msgid "Could not set direct sound cooperative level."
msgstr ""
-#: src/audio_out/audio_directx2_out.c:286
+#: src/audio_out/audio_directx2_out.c:283
msgid "Unable to create secondary direct sound buffer"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:310
+#: src/audio_out/audio_directx2_out.c:307
#, c-format
msgid "Unable to create buffer position events."
msgstr ""
-#: src/audio_out/audio_directx2_out.c:318
+#: src/audio_out/audio_directx2_out.c:315
msgid "Unable to get notification interface"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:323
+#: src/audio_out/audio_directx2_out.c:320
msgid "Unable to set notification positions"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:343
+#: src/audio_out/audio_directx2_out.c:340
msgid "Couldn't play sound buffer"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:355
+#: src/audio_out/audio_directx2_out.c:352
msgid "Couldn't stop sound buffer"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:368
+#: src/audio_out/audio_directx2_out.c:365
msgid "Can't get buffer position"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:382
+#: src/audio_out/audio_directx2_out.c:379
msgid "Can't set buffer position"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:414
+#: src/audio_out/audio_directx2_out.c:411
msgid "Can't set sound volume"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:432
+#: src/audio_out/audio_directx2_out.c:429
#, c-format
msgid ": buffer lost, tryig to restore\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:436
+#: src/audio_out/audio_directx2_out.c:433
msgid "Couldn't lock direct sound buffer"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:447
+#: src/audio_out/audio_directx2_out.c:444
msgid "Couldn't unlock direct sound buffer"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:544
+#: src/audio_out/audio_directx2_out.c:541
#, c-format
msgid "Unable to create primary direct sound buffer."
msgstr ""
-#: src/audio_out/audio_directx2_out.c:637
+#: src/audio_out/audio_directx2_out.c:634
#, c-format
msgid ": play cursor overran, flushing buffers\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:655
+#: src/audio_out/audio_directx2_out.c:652
#, c-format
msgid ": delayed by %ld msec\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:759
+#: src/audio_out/audio_directx2_out.c:756
#, fuzzy, c-format
msgid ": can't create pthread condition: %s\n"
msgstr "input_rtp: Ezin da hari berria sortu (%s)\n"
-#: src/audio_out/audio_directx2_out.c:763
+#: src/audio_out/audio_directx2_out.c:760
#, fuzzy, c-format
msgid ": can't create pthread mutex: %s\n"
msgstr "input_rtp: Ezin da hari berria sortu (%s)\n"
-#: src/audio_out/audio_directx2_out.c:770
+#: src/audio_out/audio_directx2_out.c:767
#, fuzzy, c-format
msgid ": can't create buffer pthread: %s\n"
msgstr "input_rtp: Ezin da hari berria sortu (%s)\n"
-#: src/audio_out/audio_directx2_out.c:877
+#: src/audio_out/audio_directx2_out.c:874
#, fuzzy, c-format
msgid ": can't destroy buffer pthread: %s\n"
msgstr "input_rtp: Ezin da hari berria sortu (%s)\n"
-#: src/audio_out/audio_directx2_out.c:884
+#: src/audio_out/audio_directx2_out.c:881
#, c-format
msgid ": can't destroy pthread condition: %s\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:887
+#: src/audio_out/audio_directx2_out.c:884
#, c-format
msgid ": can't destroy pthread mutex: %s\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:947
+#: src/audio_out/audio_directx2_out.c:944
#, fuzzy, c-format
msgid ": unknown control command %d\n"
msgstr "iff-ilbm: konpresio ezezaguna: %d\n"
-#: src/audio_out/audio_directx2_out.c:1003
+#: src/audio_out/audio_directx2_out.c:1000
#, fuzzy
msgid "second xine audio output plugin using directx"
msgstr "xine audio irteera plugina win32-arentzat directx erabiliaz"
@@ -1000,7 +1000,7 @@ msgstr "demux_snd: okerreko goiburu parametroa\n"
msgid "demux_snd: unsupported audio type: %d\n"
msgstr "demux_snd: onartzen ez den audio mota: %d\n"
-#: src/demuxers/demux_tta.c:88
+#: src/demuxers/demux_tta.c:86
msgid "demux_tta: total frames count too high\n"
msgstr ""
@@ -1024,7 +1024,7 @@ msgstr ""
msgid "demux_wc3movie: SHOT chunk referenced invalid palette (%d >= %d)\n"
msgstr ""
-#: src/demuxers/demux_wc3movie.c:406
+#: src/demuxers/demux_wc3movie.c:404
#, c-format
msgid "demux_wc3movie: There was a problem while loading palette chunks\n"
msgstr "demux_wc3movie: Arazo bat dago paleta zatiak kargatzerakoan\n"
@@ -1461,30 +1461,30 @@ msgstr ""
"video_out_dxr3: ERROREA gainjarri abiarazte fitxategia irakurtzeab. Run "
"abiarazi!\n"
-#: src/input/input_cdda.c:1621
+#: src/input/input_cdda.c:1608
#, c-format
msgid "%s: can't connect to %s:%d\n"
msgstr "%s: Ezin da %s-ra konektatu: %d\n"
-#: src/input/input_cdda.c:1668
+#: src/input/input_cdda.c:1655
#, c-format
msgid "input_cdda: successfuly connected to cddb server '%s:%d'.\n"
msgstr "input_cdda: arrakastatsuki konektaturik cddb zerbitzarira'%s:%d'.\n"
-#: src/input/input_cdda.c:1673
+#: src/input/input_cdda.c:1660
#, c-format
msgid "input_cdda: failed to connect to cddb server '%s:%d' (%s).\n"
msgstr "input_cdda: huts cddb zerbitzarira konektatzerakoan '%s:%d' (%s).\n"
-#: src/input/input_cdda.c:2707
+#: src/input/input_cdda.c:2690
msgid "CD Digital Audio (aka. CDDA)"
msgstr "CD Audio Digitala (hemen. CDDA)"
-#: src/input/input_cdda.c:2760
+#: src/input/input_cdda.c:2742
msgid "device used for CD audio"
msgstr "CD audio-k erabiliko duen gailua"
-#: src/input/input_cdda.c:2761
+#: src/input/input_cdda.c:2743
msgid ""
"The path to the device, usually a CD or DVD drive, which you intend to use "
"for playing audio CDs."
@@ -1492,11 +1492,11 @@ msgstr ""
"Gailuaren bidea, arruntean audio CD erreproduzitzeko erabili nahi duzun CD "
"edo DVD gailua."
-#: src/input/input_cdda.c:2767
+#: src/input/input_cdda.c:2749
msgid "query CDDB"
msgstr "CDDB galderak"
-#: src/input/input_cdda.c:2767
+#: src/input/input_cdda.c:2749
msgid ""
"Enables CDDB queries, which will give you convenient title and track names "
"for your audio CDs.\n"
@@ -1509,11 +1509,11 @@ msgstr ""
"Izan kontutan zuk ez baduzu CDDB zerbitzari pribatu bat, informazio hau zure "
"ohiturak grabatuko dituen internet ostalari batetatik jasoko da."
-#: src/input/input_cdda.c:2775
+#: src/input/input_cdda.c:2757
msgid "CDDB server name"
msgstr "CDDB zerbitzari izena"
-#: src/input/input_cdda.c:2775
+#: src/input/input_cdda.c:2757
msgid ""
"The CDDB server used to retrieve the title and track information from.\n"
"This setting is security critical, because the sever will receive "
@@ -1525,36 +1525,20 @@ msgstr ""
"entzuteko ohituraz informazioa jaso eta erantzun zitalekin erantzun bait "
"dezake. Ziurtatu konfidantza duzun zerbitzari bat izatea."
-#: src/input/input_cdda.c:2783
+#: src/input/input_cdda.c:2765
msgid "CDDB server port"
msgstr "CDDB zerbitzari ataka"
-#: src/input/input_cdda.c:2783
+#: src/input/input_cdda.c:2765
msgid "The server port used to retrieve the title and track information from."
msgstr ""
"Izenburu eta pista informazioa jasotzeko erabiliko den zerbitzari ataka."
-#: src/input/input_cdda.c:2789
-msgid "CDDB cache directory"
-msgstr "CDDB katxe karpeta"
-
-#: src/input/input_cdda.c:2789
-msgid ""
-"The replies from the CDDB server will be cached in this directory.\n"
-"This setting is security critical, because files with uncontrollable names "
-"will be created in this directory. Be sure to use a dedicated directory not "
-"used for anything but CDDB caching."
-msgstr ""
-"CDDB zarbitzariaren erantzunak karpeta honetan gordeko dira.\n"
-"Ezarpena segurtasun aldetik kritikoa da, kontrolatugabeko fitxategi izenak "
-"sortuko bait dira. Ziurtatu erabiliko den karpeta ez dela honetaz beste "
-"ezertarako erabiliko."
-
-#: src/input/input_cdda.c:2797
+#: src/input/input_cdda.c:2771
msgid "slow down disc drive to this speed factor"
msgstr "gutxitu diska gailua abiadura faktore honetara"
-#: src/input/input_cdda.c:2798
+#: src/input/input_cdda.c:2772
msgid ""
"Since some CD or DVD drives make some really loud noises because of the fast "
"disc rotation, xine will try to slow them down. With standard CD or DVD "
@@ -1568,58 +1552,63 @@ msgstr ""
"geldoarazteak ez du ezertan txikiagotzen erreprodukzio kalitatea.\n"
"Zero balioa poliagotzea ezgaitzen da."
-#: src/input/input_dvb.c:881
-#, c-format
-msgid "input_dvb: failed to open dvb channel file '%s'\n"
+#: src/input/input_dvb.c:899
+#, fuzzy, c-format
+msgid "input_dvb: failed to open dvb channel file '%s': %s\n"
+msgstr "input_dvb: huts '%s' dvb kanal fitxategia irekitzerakoan\n"
+
+#: src/input/input_dvb.c:905
+#, fuzzy, c-format
+msgid "input_dvb: dvb channel file '%s' is not a plain file\n"
msgstr "input_dvb: huts '%s' dvb kanal fitxategia irekitzerakoan\n"
-#: src/input/input_dvb.c:2082 src/input/input_dvb.c:2910
+#: src/input/input_dvb.c:2115 src/input/input_dvb.c:2943
msgid "input_dvb: tuner_set_channel failed\n"
msgstr "input_dvb: irrati_ezarpen_kanalak huts egin du\n"
-#: src/input/input_dvb.c:2710
+#: src/input/input_dvb.c:2743
msgid "input_dvb: cannot open dvb device\n"
msgstr "input_dvb: ezin da dvb gailua ireki\n"
-#: src/input/input_dvb.c:2734
+#: src/input/input_dvb.c:2767
#, c-format
msgid "input_dvb: channel %d out of range, defaulting to 0\n"
msgstr "input_dvb: %d kanala eremutik kanpo, 0-ra lehenesten\n"
-#: src/input/input_dvb.c:2745
+#: src/input/input_dvb.c:2778
#, c-format
msgid "input_dvb: searching for channel %s\n"
msgstr "input_dvb: %s kanala bilatzen\n"
-#: src/input/input_dvb.c:2768
+#: src/input/input_dvb.c:2801
#, c-format
msgid "input_dvb: exact match for %s not found: trying partial matches\n"
msgstr ""
"input_dvb: ez da %s-ren parekatze zehatzik aurkitu: parekatze hurbilduak "
"saiatzen\n"
-#: src/input/input_dvb.c:2775
+#: src/input/input_dvb.c:2808
#, c-format
msgid "input_dvb: found matching channel %s\n"
msgstr "input_dvb: %s kanal parekatzea aurkiturik\n"
-#: src/input/input_dvb.c:2788
+#: src/input/input_dvb.c:2821
#, fuzzy, c-format
msgid "input_dvb: channel %s not found in channels.conf, defaulting.\n"
msgstr "input_dvb: %s kanala ez da kanaletan aurkitu, 0 kanalera lehenesten\n"
-#: src/input/input_dvb.c:2794
+#: src/input/input_dvb.c:2827
#, fuzzy
msgid ""
"input_dvb: invalid channel specification, defaulting to last viewed "
"channel.\n"
msgstr "input_dvb: baliogabeko kanal ezarpena, 0 kanalera lehenesten\n"
-#: src/input/input_dvb.c:2800
+#: src/input/input_dvb.c:2833
msgid "input_dvb: invalid channel specification, defaulting to channel 0\n"
msgstr "input_dvb: baliogabeko kanal ezarpena, 0 kanalera lehenesten\n"
-#: src/input/input_dvb.c:2812
+#: src/input/input_dvb.c:2845
msgid ""
"input_dvb: dvbs mrl specified but the tuner doesn't appear to be QPSK (DVB-"
"S)\n"
@@ -1627,7 +1616,7 @@ msgstr ""
"input_dvb: dvbs mrl ezarririk baina sintonizatzailea ez dirudu QPSK (DVB-S) "
"dagoenik\n"
-#: src/input/input_dvb.c:2832
+#: src/input/input_dvb.c:2865
msgid ""
"input_dvb: dvbt mrl specified but the tuner doesn't appear to be OFDM (DVB-"
"T)\n"
@@ -1635,7 +1624,7 @@ msgstr ""
"input_dvb: dvbt mrl ezarririk baina sintonizatzailea ez dirudu OFDM (DVB-T) "
"dagoenik\n"
-#: src/input/input_dvb.c:2855 src/input/input_dvb.c:2881
+#: src/input/input_dvb.c:2888 src/input/input_dvb.c:2914
msgid ""
"input_dvb: dvbc mrl specified but the tuner doesn't appear to be QAM (DVB-"
"C)\n"
@@ -1643,21 +1632,21 @@ msgstr ""
"input_dvb: dvbc mrl ezarririk baina sintonizatzailea ez dirudu QAM (DVB-C) "
"dagoenik\n"
-#: src/input/input_dvb.c:2916
+#: src/input/input_dvb.c:2949
#, c-format
msgid "input_dvb: cannot open dvr device '%s'\n"
msgstr "input_dvb: ezin da '%s' dvr gailua ireki\n"
-#: src/input/input_dvb.c:2938
+#: src/input/input_dvb.c:2971
#, fuzzy
msgid "input_dvb: cannot create EPG updater thread\n"
msgstr "input_rtp: Ezin da hari berria sortu (%s)\n"
-#: src/input/input_dvb.c:3000
+#: src/input/input_dvb.c:3033
msgid "use DVB 'center cutout' (zoom)"
msgstr ""
-#: src/input/input_dvb.c:3001
+#: src/input/input_dvb.c:3034
msgid ""
"This will allow fullscreen playback of 4:3 content transmitted in a 16:9 "
"frame."
@@ -1665,35 +1654,35 @@ msgstr ""
"Honek pantaila osoko erreprdukzioa 4:3 formatu edukiak 16:9 markotan "
"transmititzea gaitzen du."
-#: src/input/input_dvb.c:3094
+#: src/input/input_dvb.c:3127
msgid "DVB (Digital TV) input plugin"
msgstr "DVB (Telebista Digitala) sarrera plugina"
-#: src/input/input_dvb.c:3242
+#: src/input/input_dvb.c:3244
msgid "Remember last DVB channel watched"
msgstr ""
-#: src/input/input_dvb.c:3243
+#: src/input/input_dvb.c:3245
msgid ""
"On autoplay, xine will remember and switch to the channel indicated in media."
"dvb.last_channel. "
msgstr ""
-#: src/input/input_dvb.c:3250
+#: src/input/input_dvb.c:3252
#, fuzzy
msgid "Last DVB channel viewed"
msgstr "bistaratu DVB kanal izena"
-#: src/input/input_dvb.c:3251
+#: src/input/input_dvb.c:3253
msgid "If enabled xine will remember and switch to this channel. "
msgstr ""
-#: src/input/input_dvb.c:3257
+#: src/input/input_dvb.c:3259
#, fuzzy
msgid "Number of dvb card to use."
msgstr "audio buffer kopurua"
-#: src/input/input_dvb.c:3258
+#: src/input/input_dvb.c:3260
msgid ""
"Leave this at zero unless you really have more than 1 card in your system."
msgstr ""
@@ -1723,11 +1712,11 @@ msgstr ""
"DVD-ak erreproduzitzeko erabli nahi duzun, arruntean DVD gailu bat, gaiuaren "
"bidea."
-#: src/input/input_dvd.c:1800
+#: src/input/input_dvd.c:1799
msgid "raw device set up for DVD access"
msgstr "DVD irakurleantzat gailu gordin (raw) ezarpenak"
-#: src/input/input_dvd.c:1801
+#: src/input/input_dvd.c:1800
msgid ""
"If this points to a raw device connected to your DVD device, xine will use "
"the raw device for playback. This has the advantage of being slightly faster "
@@ -1738,35 +1727,22 @@ msgid ""
"See the documentation on raw device setup (man raw) for further information."
msgstr ""
-#: src/input/input_dvd.c:1814
+#: src/input/input_dvd.c:1813
msgid "CSS decryption method"
msgstr "CSS desenkriptazio metodoa"
-#: src/input/input_dvd.c:1815
+#: src/input/input_dvd.c:1814
msgid ""
"Selects the decryption method libdvdcss will use to descramble copy "
"protected DVDs. Try the various methods, if you have problems playing "
"scrambled DVDs."
msgstr ""
-#: src/input/input_dvd.c:1823
-msgid "path to the title key cache"
-msgstr ""
-
-#: src/input/input_dvd.c:1824
-msgid ""
-"Since cracking the copy protection of scrambled DVDs can be quite time "
-"consuming, libdvdcss will cache the cracked keys in this directory.\n"
-"This setting is security critical, because files with uncontrollable names "
-"will be created in this directory. Be sure to use a dedicated directory not "
-"used for anything but DVD key caching."
-msgstr ""
-
-#: src/input/input_dvd.c:1846
+#: src/input/input_dvd.c:1829
msgid "region the DVD player claims to be in (1 to 8)"
msgstr "DVD erreproduktorean eskatzen duen erregioa (1 - 8)"
-#: src/input/input_dvd.c:1847
+#: src/input/input_dvd.c:1830
msgid ""
"This only needs to be changed if your DVD jumps to a screen complaining "
"about a wrong region code. It has nothing to do with the region code set in "
@@ -1776,11 +1752,11 @@ msgstr ""
"bakarrik behar da hau. Honek ez du zerikusirik DVD gailuetan ezarritako "
"erregio kodearekin, hau software hutsa da."
-#: src/input/input_dvd.c:1853
+#: src/input/input_dvd.c:1836
msgid "default language for DVD playback"
msgstr "DVD erreprodukzioaren lehenetsirako hizkuntza"
-#: src/input/input_dvd.c:1854
+#: src/input/input_dvd.c:1837
msgid ""
"xine tries to use this language as a default for DVD playback. As far as the "
"DVD supports it, menus and audio tracks will be presented in this language.\n"
@@ -1791,22 +1767,22 @@ msgstr ""
"hizkuntza honetan emango dira.\n"
"Balioak bi karaktereko ISO639 kode bat izan behar da."
-#: src/input/input_dvd.c:1860
+#: src/input/input_dvd.c:1843
msgid "read-ahead caching"
msgstr "irakuketa-goiburu gordetzea"
-#: src/input/input_dvd.c:1861
+#: src/input/input_dvd.c:1844
msgid ""
"xine can use a read ahead cache for DVD drive access.\n"
"This may lead to jerky playback on slow drives, but it improves the impact "
"of the DVD layer change on faster drives."
msgstr ""
-#: src/input/input_dvd.c:1867
+#: src/input/input_dvd.c:1850
msgid "unit for the skip action"
msgstr "Ekintza egingo ez den unitatea"
-#: src/input/input_dvd.c:1868
+#: src/input/input_dvd.c:1851
msgid ""
"You can configure the behaviour when issuing a skip command (using the skip "
"buttons for example). The individual values mean:\n"
@@ -1825,11 +1801,11 @@ msgid ""
"features on the DVD"
msgstr ""
-#: src/input/input_dvd.c:1883
+#: src/input/input_dvd.c:1866
msgid "unit for seeking"
msgstr "Bilatuko den untitatea"
-#: src/input/input_dvd.c:1884
+#: src/input/input_dvd.c:1867
msgid ""
"You can configure the domain spanned by the seek slider. The individual "
"values mean:\n"
@@ -1843,11 +1819,11 @@ msgid ""
"chapter of the current feature"
msgstr ""
-#: src/input/input_dvd.c:1895
+#: src/input/input_dvd.c:1878
msgid "play mode when title/chapter is given"
msgstr ""
-#: src/input/input_dvd.c:1896
+#: src/input/input_dvd.c:1879
msgid ""
"You can configure the behaviour when playing a dvd from a given title/"
"chapter (eg. using MRL 'dvd:/1.2'). The individual values mean:\n"
@@ -2570,7 +2546,7 @@ msgid ""
"2048: Debugging from VCDINFO\n"
msgstr ""
-#: src/liba52/xine_a52_decoder.c:742 src/libdts/xine_dts_decoder.c:546
+#: src/liba52/xine_a52_decoder.c:742 src/libxineadec/xine_dts_decoder.c:524
msgid "HELP! a mono-only audio driver?!\n"
msgstr "LAGUNTZA! mono bakarrik audio kontrolatzailea?\n"
@@ -2624,62 +2600,62 @@ msgstr "libfaad: libfaad faacDecInit2-ek huts egin du.\n"
msgid "libfaad: libfaad NeAACDecInit failed.\n"
msgstr "libfaad: libfaad faacDecInit-ek huts egin du.\n"
-#: src/libffmpeg/ff_audio_decoder.c:120
+#: src/libffmpeg/ff_audio_decoder.c:122
#, c-format
msgid "ffmpeg_audio_dec: increasing buffer to %d to avoid overflow.\n"
msgstr "ffmpeg_audio_dec: bufferra%d-ra handitzen askieza sahiesteko.\n"
-#: src/libffmpeg/ff_audio_decoder.c:164
+#: src/libffmpeg/ff_audio_decoder.c:166
#, c-format
msgid "ffmpeg_audio_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"
msgstr ""
-#: src/libffmpeg/ff_audio_decoder.c:256
+#: src/libffmpeg/ff_audio_decoder.c:258
#, fuzzy
msgid "ffmpeg_audio_dec: trying to open null codec\n"
msgstr "ffmpeg_audio_dec: ezin da deskodetzailea ireki\n"
-#: src/libffmpeg/ff_audio_decoder.c:265
+#: src/libffmpeg/ff_audio_decoder.c:267
msgid "ffmpeg_audio_dec: couldn't open decoder\n"
msgstr "ffmpeg_audio_dec: ezin da deskodetzailea ireki\n"
-#: src/libffmpeg/ff_dvaudio_decoder.c:286
+#: src/libffmpeg/ff_dvaudio_decoder.c:280
#, c-format
msgid "dvaudio: increasing buffer to %d to avoid overflow.\n"
msgstr "dvaudio: bufeera %d -ra handitzen askieza sahiesteko.\n"
-#: src/libffmpeg/ff_video_decoder.c:157
+#: src/libffmpeg/ff_video_decoder.c:155
msgid "ffmpeg_video_dec: unsupported frame format, DR1 disabled.\n"
msgstr "ffmpeg_video_dec: marko formatu onartezina, DR1 ezgaiturik.\n"
-#: src/libffmpeg/ff_video_decoder.c:175
+#: src/libffmpeg/ff_video_decoder.c:173
#, fuzzy
msgid "ffmpeg_video_dec: unsupported frame dimensions, DR1 disabled.\n"
msgstr "ffmpeg_video_dec: marko formatu onartezina, DR1 ezgaiturik.\n"
-#: src/libffmpeg/ff_video_decoder.c:335
+#: src/libffmpeg/ff_video_decoder.c:333
#, c-format
msgid "ffmpeg_video_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"
msgstr ""
-#: src/libffmpeg/ff_video_decoder.c:364
+#: src/libffmpeg/ff_video_decoder.c:362
msgid "ffmpeg_video_dec: couldn't open decoder\n"
msgstr "ffmpeg_video_dec: ezin da deskodetzailea ireki\n"
-#: src/libffmpeg/ff_video_decoder.c:399
+#: src/libffmpeg/ff_video_decoder.c:397
msgid "ffmpeg_video_dec: direct rendering enabled\n"
msgstr "ffmpeg_video_dec: direct reenderizazioa gaiturik\n"
-#: src/libffmpeg/ff_video_decoder.c:818
+#: src/libffmpeg/ff_video_decoder.c:816
#, c-format
msgid "ffmpeg_video_dec: increasing buffer to %d to avoid overflow.\n"
msgstr "ffmpeg_video_dec: bufferra %d -ra handitzen askieza saiesteko.\n"
-#: src/libffmpeg/ff_video_decoder.c:1516
+#: src/libffmpeg/ff_video_decoder.c:1514
msgid "MPEG-4 postprocessing quality"
msgstr "MPEG-4 postprozesatze kalitatea"
-#: src/libffmpeg/ff_video_decoder.c:1517
+#: src/libffmpeg/ff_video_decoder.c:1515
msgid ""
"You can adjust the amount of post processing applied to MPEG-4 video.\n"
"Higher values result in better quality, but need more CPU. Lower values may "
@@ -2688,61 +2664,61 @@ msgid ""
"much."
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:167
+#: src/libffmpeg/ffmpeg_encoder.c:163
msgid "libavcodec mpeg output bitrate (kbit/s)"
msgstr "libavcodec mpeg irteera bit tasa (kbit/s)"
-#: src/libffmpeg/ffmpeg_encoder.c:168
+#: src/libffmpeg/ffmpeg_encoder.c:164
msgid ""
"The bitrate the libavcodec mpeg encoder should use for DXR3's encoding mode. "
"Higher values will increase quality and CPU usage.\n"
"This setting is only considered, when constant quality mode is disabled."
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:175
+#: src/libffmpeg/ffmpeg_encoder.c:171
msgid "constant quality mode"
msgstr "kalitate modu iraunkorra"
-#: src/libffmpeg/ffmpeg_encoder.c:176
+#: src/libffmpeg/ffmpeg_encoder.c:172
msgid ""
"When enabled, libavcodec will use a constant quality mode by dynamically "
"compressing the images based on their complexity. When disabled, libavcodec "
"will use constant bitrate mode."
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:183
+#: src/libffmpeg/ffmpeg_encoder.c:179
msgid "minimum compression"
msgstr "konpresio txikiena"
-#: src/libffmpeg/ffmpeg_encoder.c:184
+#: src/libffmpeg/ffmpeg_encoder.c:180
msgid "The minimum compression to apply to an image in constant quality mode."
msgstr ""
"Kalitate iraunkorreko kalitate moduko ezarriko den gutxienezko konpresioa."
-#: src/libffmpeg/ffmpeg_encoder.c:189
+#: src/libffmpeg/ffmpeg_encoder.c:185
msgid "maximum quantizer"
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:190
+#: src/libffmpeg/ffmpeg_encoder.c:186
msgid "The maximum compression to apply to an image in constant quality mode."
msgstr ""
"Kalitate iraunkorreko kalitate moduko ezarriko den gehinezko konpresioa."
-#: src/libmusepack/xine_musepack_decoder.c:241
+#: src/libxineadec/xine_musepack_decoder.c:249
#, c-format
msgid "libmusepack: mpc_streaminfo_read failed: %d\n"
msgstr ""
-#: src/libmusepack/xine_musepack_decoder.c:315
+#: src/libxineadec/xine_musepack_decoder.c:323
msgid "libmusepack: data after last frame ignored\n"
msgstr ""
-#: src/libmusepack/xine_musepack_decoder.c:326
+#: src/libxineadec/xine_musepack_decoder.c:334
msgid "libmusepack: mpc_decoder_initialise failed\n"
msgstr ""
-#: src/libmusepack/xine_musepack_decoder.c:346
-#: src/libmusepack/xine_musepack_decoder.c:361
+#: src/libxineadec/xine_musepack_decoder.c:354
+#: src/libxineadec/xine_musepack_decoder.c:369
#, c-format
msgid "libmusepack: mpc_decoder_decode failed: %d\n"
msgstr ""
@@ -3521,7 +3497,7 @@ msgid "Select the video output layer by its id."
msgstr ""
#: src/video_out/video_out_directfb.c:1804
-#: src/video_out/video_out_directfb.c:2013
+#: src/video_out/video_out_directfb.c:2014
#, fuzzy, c-format
msgid "video_out_directfb: using display layer #%d.\n"
msgstr "video_out_vidix: erabilitako kontrolatzailea: %s, %s-rena\n"
@@ -3531,11 +3507,11 @@ msgstr "video_out_vidix: erabilitako kontrolatzailea: %s, %s-rena\n"
msgid "xine video output plugin using DirectFB."
msgstr "xine bideo irteera plugina DirectFB liburutegia erabiliaz"
-#: src/video_out/video_out_directfb.c:2006
+#: src/video_out/video_out_directfb.c:2007
msgid "video_out_directfb: no usable display layer was found!\n"
msgstr ""
-#: src/video_out/video_out_directfb.c:2095
+#: src/video_out/video_out_directfb.c:2096
#, fuzzy
msgid "xine video output plugin using DirectFB under XDirectFB."
msgstr "xine bideo irteera plugina DirectFB liburutegia erabiliaz"
@@ -3544,18 +3520,18 @@ msgstr "xine bideo irteera plugina DirectFB liburutegia erabiliaz"
msgid "xine video output plugin for win32 using directx"
msgstr "xine bideo irteera plugina win32-rentzat directx erabiliaz"
-#: src/video_out/video_out_fb.c:792
+#: src/video_out/video_out_fb.c:780
#, c-format
msgid ""
"video_out_fb: only packed truecolor/directcolor is supported (%d).\n"
" Check 'fbset -i' or try 'fbset -depth 16'.\n"
msgstr ""
-#: src/video_out/video_out_fb.c:852 src/video_out/video_out_vidix.c:1239
+#: src/video_out/video_out_fb.c:840 src/video_out/video_out_vidix.c:1239
msgid "framebuffer device name"
msgstr "framebuffer gailu izena"
-#: src/video_out/video_out_fb.c:853 src/video_out/video_out_vidix.c:1240
+#: src/video_out/video_out_fb.c:841 src/video_out/video_out_vidix.c:1240
msgid ""
"Specifies the file name for the framebuffer device to be used.\n"
"This setting is security critical, because when changed to a different file, "
@@ -3567,39 +3543,40 @@ msgstr ""
"xinek fitxategia eduki arbitrario bat erabiliaz bete bait dezake. Beraz "
"balioaegiazko framebuffer gailu bat dela ziurtatu behar duzu."
-#: src/video_out/video_out_fb.c:927
-msgid "video_out_fb: Your video mode was not recognized, sorry.\n"
+#: src/video_out/video_out_fb.c:915
+#, fuzzy, c-format
+msgid "%s: Your video mode was not recognized, sorry.\n"
msgstr "video_out_fb: Bideo modua ez da ezagutzen, barkatu.\n"
-#: src/video_out/video_out_fb.c:984
-#, c-format
-msgid "video_out_fb: %d video RAM buffers are available.\n"
+#: src/video_out/video_out_fb.c:972
+#, fuzzy, c-format
+msgid "%s: %d video RAM buffers are available.\n"
msgstr "video_out_fb: %d bideo RAM buffer eskuragarri dira.\n"
-#: src/video_out/video_out_fb.c:990
+#: src/video_out/video_out_fb.c:978
#, c-format
msgid ""
-"WARNING: video_out_fb: Zero copy buffers are DISABLED because only %d "
-"buffers\n"
+"WARNING: %s: Zero copy buffers are DISABLED because only %d buffers\n"
" are available which is less than the recommended %d buffers. Lowering\n"
" the frame buffer resolution might help.\n"
msgstr ""
-#: src/video_out/video_out_fb.c:1001
+#: src/video_out/video_out_fb.c:989
+#, c-format
msgid ""
-"WARNING: video_out_fb: Zero copy buffers are DISABLED because kernel driver\n"
+"WARNING: %s: Zero copy buffers are DISABLED because kernel driver\n"
" do not support screen panning (used for frame flips).\n"
msgstr ""
-#: src/video_out/video_out_fb.c:1070
+#: src/video_out/video_out_fb.c:1058
#, c-format
msgid ""
-"WARNING: video_out_fb: current display depth is %d. For better performance\n"
+"WARNING: %s: current display depth is %d. For better performance\n"
" a depth of 16 bpp is recommended!\n"
"\n"
msgstr ""
-#: src/video_out/video_out_fb.c:1101
+#: src/video_out/video_out_fb.c:1090
msgid "Xine video output plugin using the Linux frame buffer device"
msgstr "Xine bideo irteera plugina Linux framebuffer gailua erabiliaz"
@@ -3651,8 +3628,8 @@ msgid ""
msgstr ""
#: src/video_out/video_out_opengl.c:1918 src/video_out/video_out_vidix.c:1015
-#: src/video_out/video_out_xcbxv.c:1472 src/video_out/video_out_xv.c:1486
-#: src/video_out/video_out_xvmc.c:1461 src/video_out/video_out_xxmc.c:2468
+#: src/video_out/video_out_xcbxv.c:1476 src/video_out/video_out_xv.c:1489
+#: src/video_out/video_out_xvmc.c:1461 src/video_out/video_out_xxmc.c:2465
msgid "enable double buffering"
msgstr "gaitu buffer bikoitza"
@@ -3734,9 +3711,9 @@ msgstr ""
msgid "video_out_pgx64: Error: ioctl failed (FBIOGATTR)\n"
msgstr "video_out_pgx64: Errorea: ioctl hutsa (FBIOGATTR)\n"
-#: src/video_out/video_out_pgx64.c:1464 src/video_out/video_out_xcbxv.c:1439
-#: src/video_out/video_out_xv.c:1453 src/video_out/video_out_xvmc.c:1446
-#: src/video_out/video_out_xxmc.c:2435
+#: src/video_out/video_out_pgx64.c:1464 src/video_out/video_out_xcbxv.c:1443
+#: src/video_out/video_out_xv.c:1456 src/video_out/video_out_xvmc.c:1446
+#: src/video_out/video_out_xxmc.c:2432
msgid "video overlay colour key"
msgstr ""
@@ -3903,9 +3880,9 @@ msgstr "Intentsitate urdina"
msgid "The intensity of the blue colour components."
msgstr "Urdin koloreko osagaien intentsitatea."
-#: src/video_out/video_out_vidix.c:1016 src/video_out/video_out_xcbxv.c:1473
-#: src/video_out/video_out_xv.c:1487 src/video_out/video_out_xvmc.c:1462
-#: src/video_out/video_out_xxmc.c:2469
+#: src/video_out/video_out_vidix.c:1016 src/video_out/video_out_xcbxv.c:1477
+#: src/video_out/video_out_xv.c:1490 src/video_out/video_out_xvmc.c:1462
+#: src/video_out/video_out_xxmc.c:2466
msgid ""
"Double buffering will synchronize the update of the video image to the "
"repainting of the entire screen (\"vertical retrace\"). This eliminates "
@@ -3938,9 +3915,9 @@ msgid "video overlay colour key red component"
msgstr "bideo ingurune kolore teklaren gorri osagaia"
#: src/video_out/video_out_vidix.c:1159 src/video_out/video_out_vidix.c:1166
-#: src/video_out/video_out_vidix.c:1173 src/video_out/video_out_xcbxv.c:1440
-#: src/video_out/video_out_xv.c:1454 src/video_out/video_out_xvmc.c:1447
-#: src/video_out/video_out_xxmc.c:2436
+#: src/video_out/video_out_vidix.c:1173 src/video_out/video_out_xcbxv.c:1444
+#: src/video_out/video_out_xv.c:1457 src/video_out/video_out_xvmc.c:1447
+#: src/video_out/video_out_xxmc.c:2433
msgid ""
"The colour key is used to tell the graphics card where to overlay the video "
"image. Try different values, if you experience windows becoming transparent."
@@ -3963,27 +3940,38 @@ msgid "xine video output plugin using libvidix for linux frame buffer"
msgstr ""
"xine bideo irteera plugina libvidix Linux Frame buffer-arentzat erabiliaz"
-#: src/video_out/video_out_xcbshm.c:157
+#: src/video_out/video_out_xcbshm.c:157 src/video_out/video_out_xshm.c:219
#, c-format
-msgid ""
-"video_out_xcbshm: %s: allocating image\n"
-"video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+msgid "%s: %s: allocating image\n"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:166
-msgid ""
-"video_out_xcbshm: shared memory error (address error) when allocating "
-"image \n"
-"video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbshm.c:159 src/video_out/video_out_xcbshm.c:169
+#: src/video_out/video_out_xcbshm.c:181 src/video_out/video_out_xcbxv.c:272
+#: src/video_out/video_out_xcbxv.c:282 src/video_out/video_out_xcbxv.c:292
+#: src/video_out/video_out_xcbxv.c:304 src/video_out/video_out_xshm.c:204
+#: src/video_out/video_out_xshm.c:221 src/video_out/video_out_xshm.c:232
+#: src/video_out/video_out_xshm.c:251 src/video_out/video_out_xv.c:296
+#: src/video_out/video_out_xv.c:307 src/video_out/video_out_xv.c:316
+#: src/video_out/video_out_xv.c:352 src/video_out/video_out_xxmc.c:648
+#: src/video_out/video_out_xxmc.c:659 src/video_out/video_out_xxmc.c:668
+#: src/video_out/video_out_xxmc.c:704
+#, c-format
+msgid "%s: => not using MIT Shared Memory extension.\n"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:177
-msgid ""
-"video_out_xcbshm: x11 error during shared memory XImage creation\n"
-"video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbshm.c:167 src/video_out/video_out_xshm.c:230
+#, c-format
+msgid "%s: shared memory error (address error) when allocating image \n"
+msgstr ""
+
+#: src/video_out/video_out_xcbshm.c:179 src/video_out/video_out_xcbxv.c:302
+#: src/video_out/video_out_xshm.c:249 src/video_out/video_out_xv.c:350
+#: src/video_out/video_out_xxmc.c:702
+#, c-format
+msgid "%s: x11 error during shared memory XImage creation\n"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:1100 src/video_out/video_out_xshm.c:1157
+#: src/video_out/video_out_xcbshm.c:1103 src/video_out/video_out_xshm.c:1161
#, c-format
msgid ""
"\n"
@@ -3993,81 +3981,79 @@ msgid ""
"\n"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:1113
-#, fuzzy
-msgid "video_out_xcbshm: MIT shared memory extension not present on display.\n"
+#: src/video_out/video_out_xcbshm.c:1116 src/video_out/video_out_xshm.c:1174
+#, fuzzy, c-format
+msgid "%s: MIT shared memory extension not present on display.\n"
msgstr ""
"video_out_xshm: MIT partekatutako memoria luzapena ez dago pantailan.\n"
-#: src/video_out/video_out_xcbshm.c:1212
-#, fuzzy
-msgid "video_out_xcbshm: your video mode was not recognized, sorry :-(\n"
-msgstr "video_out_xshm: bideo modua ez da ezagutzen, barkatu :-(\n"
+#: src/video_out/video_out_xcbshm.c:1215 src/video_out/video_out_xshm.c:1258
+#, fuzzy, c-format
+msgid "%s: your video mode was not recognized, sorry :-(\n"
+msgstr "video_out_fb: Bideo modua ez da ezagutzen, barkatu.\n"
-#: src/video_out/video_out_xcbshm.c:1242 src/video_out/video_out_xshm.c:1303
+#: src/video_out/video_out_xcbshm.c:1245 src/video_out/video_out_xshm.c:1307
msgid "xine video output plugin using the MIT X shared memory extension"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:272
-msgid ""
-"video_out_xcbxv: XvShmCreateImage returned a zero size\n"
-"video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbxv.c:270 src/video_out/video_out_xv.c:305
+#: src/video_out/video_out_xxmc.c:657
+#, c-format
+msgid "%s: XvShmCreateImage returned a zero size\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:281
+#: src/video_out/video_out_xcbxv.c:280 src/video_out/video_out_xv.c:314
+#: src/video_out/video_out_xxmc.c:666
#, c-format
-msgid ""
-"video_out_xcbxv: shared memory error in shmget: %s\n"
-"video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+msgid "%s: shared memory error in shmget: %s\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:300
-msgid ""
-"video_out_xcbxv: x11 error during shared memory XImage creation\n"
-"video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbxv.c:290
+#, c-format
+msgid "%s: shared memory error (address error)\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1291
-#, fuzzy
-msgid "video_out_xcbxv: Xv extension not present.\n"
+#: src/video_out/video_out_xcbxv.c:1294 src/video_out/video_out_xv.c:1301
+#: src/video_out/video_out_xxmc.c:2283
+#, fuzzy, c-format
+msgid "%s: Xv extension not present.\n"
msgstr "video_out_xv: Xv luzapena ez dago.\n"
-#: src/video_out/video_out_xcbxv.c:1333
-#, fuzzy
+#: src/video_out/video_out_xcbxv.c:1336 src/video_out/video_out_xv.c:1338
+#: src/video_out/video_out_xxmc.c:2320
+#, fuzzy, c-format
msgid ""
-"video_out_xcbxv: Xv extension is present but I couldn't find a usable yuv12 "
-"port.\n"
-" Looks like your graphics hardware driver doesn't support "
-"Xv?!\n"
+"%s: Xv extension is present but I couldn't find a usable yuv12 port.\n"
+"\tLooks like your graphics hardware driver doesn't support Xv?!\n"
msgstr ""
"video_out_xv: Xv luzapena dago baina ez da yuv12 ataka "
"erabilgarririkaurkitu.\n"
" Dirudienez zure txartela grafikoak ez du Xv onartzen?!\n"
-#: src/video_out/video_out_xcbxv.c:1341
+#: src/video_out/video_out_xcbxv.c:1345
#, c-format
msgid ""
-"video_out_xcbxv: using Xv port %d from adaptor %s for hardware colorspace "
-"conversion and scaling.\n"
+"%s: using Xv port %d from adaptor %s for hardware colorspace conversion and "
+"scaling.\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1448 src/video_out/video_out_xv.c:1462
-#: src/video_out/video_out_xvmc.c:1455 src/video_out/video_out_xxmc.c:2444
+#: src/video_out/video_out_xcbxv.c:1452 src/video_out/video_out_xv.c:1465
+#: src/video_out/video_out_xvmc.c:1455 src/video_out/video_out_xxmc.c:2441
msgid "autopaint colour key"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1449 src/video_out/video_out_xv.c:1463
-#: src/video_out/video_out_xvmc.c:1456 src/video_out/video_out_xxmc.c:2445
+#: src/video_out/video_out_xcbxv.c:1453 src/video_out/video_out_xv.c:1466
+#: src/video_out/video_out_xvmc.c:1456 src/video_out/video_out_xxmc.c:2442
msgid "Make Xv autopaint its colorkey."
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1456 src/video_out/video_out_xv.c:1470
-#: src/video_out/video_out_xxmc.c:2452
+#: src/video_out/video_out_xcbxv.c:1460 src/video_out/video_out_xv.c:1473
+#: src/video_out/video_out_xxmc.c:2449
msgid "bilinear scaling mode"
msgstr "eskalatze modu bilinearra"
-#: src/video_out/video_out_xcbxv.c:1457 src/video_out/video_out_xv.c:1471
-#: src/video_out/video_out_xxmc.c:2453
+#: src/video_out/video_out_xcbxv.c:1461 src/video_out/video_out_xv.c:1474
+#: src/video_out/video_out_xxmc.c:2450
msgid ""
"Selects the bilinear scaling mode for Permedia cards. The individual values "
"are:\n"
@@ -4082,32 +4068,34 @@ msgid ""
"2 - enable full bilinear filtering"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1509
-#, fuzzy
-msgid "video_out_xcbxv: this adaptor supports the yv12 format.\n"
+#: src/video_out/video_out_xcbxv.c:1513 src/video_out/video_out_xv.c:1523
+#: src/video_out/video_out_xxmc.c:2506
+#, fuzzy, c-format
+msgid "%s: this adaptor supports the yv12 format.\n"
msgstr "video_out_xv: adaptadoreak yv12 formatua onartzen du.\n"
-#: src/video_out/video_out_xcbxv.c:1514
-#, fuzzy
-msgid "video_out_xcbxv: this adaptor supports the yuy2 format.\n"
+#: src/video_out/video_out_xcbxv.c:1518 src/video_out/video_out_xv.c:1528
+#: src/video_out/video_out_xxmc.c:2511
+#, fuzzy, c-format
+msgid "%s: this adaptor supports the yuy2 format.\n"
msgstr "video_out_xv: adaptadoreak yuy2 formatua onartzen du.\n"
-#: src/video_out/video_out_xcbxv.c:1522 src/video_out/video_out_xv.c:1547
-#: src/video_out/video_out_xxmc.c:2537
+#: src/video_out/video_out_xcbxv.c:1526 src/video_out/video_out_xv.c:1550
+#: src/video_out/video_out_xxmc.c:2534
msgid "pitch alignment workaround"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1523 src/video_out/video_out_xv.c:1548
-#: src/video_out/video_out_xxmc.c:2538
+#: src/video_out/video_out_xcbxv.c:1527 src/video_out/video_out_xv.c:1551
+#: src/video_out/video_out_xxmc.c:2535
msgid "Some buggy video drivers need a workaround to function properly."
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1529 src/video_out/video_out_xv.c:1554
+#: src/video_out/video_out_xcbxv.c:1533 src/video_out/video_out_xv.c:1557
#: src/video_out/video_out_xvmc.c:1524
msgid "deinterlace method (deprecated)"
msgstr "ez-elkarlituriko metodoa (zaharkiturik)"
-#: src/video_out/video_out_xcbxv.c:1530 src/video_out/video_out_xv.c:1555
+#: src/video_out/video_out_xcbxv.c:1534 src/video_out/video_out_xv.c:1558
#: src/video_out/video_out_xvmc.c:1525
msgid ""
"This config setting is deprecated. You should use the new deinterlacing post "
@@ -4146,99 +4134,28 @@ msgid ""
"with medium CPU usage."
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1584 src/video_out/video_out_xv.c:1628
-#: src/video_out/video_out_xxmc.c:2618
+#: src/video_out/video_out_xcbxv.c:1588 src/video_out/video_out_xv.c:1631
+#: src/video_out/video_out_xxmc.c:2615
msgid "xine video output plugin using the MIT X video extension"
msgstr "xine bideo irteera plugina MIT X bideo luzapena erabiltzen"
#: src/video_out/video_out_xshm.c:202
-msgid ""
-"video_out_xshm: shared memory error when allocating image\n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xshm.c:218
#, c-format
-msgid ""
-"video_out_xshm: %s: allocating image\n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xshm.c:228
-msgid ""
-"video_out_xshm: shared memory error (address error) when allocating image \n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xshm.c:245
-msgid ""
-"video_out_xshm: x11 error during shared memory XImage creation\n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xshm.c:1170
-msgid "video_out_xshm: MIT shared memory extension not present on display.\n"
-msgstr ""
-"video_out_xshm: MIT partekatutako memoria luzapena ez dago pantailan.\n"
-
-#: src/video_out/video_out_xshm.c:1254
-msgid "video_out_xshm: your video mode was not recognized, sorry :-(\n"
-msgstr "video_out_xshm: bideo modua ez da ezagutzen, barkatu :-(\n"
-
-#: src/video_out/video_out_xv.c:296
-msgid ""
-"video_out_xv: XvShmCreateImage failed\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:306
-msgid ""
-"video_out_xv: XvShmCreateImage returned a zero size\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
+msgid "%s: shared memory error when allocating image\n"
msgstr ""
-#: src/video_out/video_out_xv.c:314
+#: src/video_out/video_out_xv.c:294 src/video_out/video_out_xxmc.c:646
#, c-format
-msgid ""
-"video_out_xv: shared memory error in shmget: %s\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:346
-msgid ""
-"video_out_xv: x11 error during shared memory XImage creation\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
+msgid "%s: XvShmCreateImage failed\n"
msgstr ""
-#: src/video_out/video_out_xv.c:1299
-msgid "video_out_xv: Xv extension not present.\n"
-msgstr "video_out_xv: Xv luzapena ez dago.\n"
-
-#: src/video_out/video_out_xv.c:1336
-msgid ""
-"video_out_xv: Xv extension is present but I couldn't find a usable yuv12 "
-"port.\n"
-" Looks like your graphics hardware driver doesn't support Xv?!\n"
-msgstr ""
-"video_out_xv: Xv luzapena dago baina ez da yuv12 ataka "
-"erabilgarririkaurkitu.\n"
-" Dirudienez zure txartela grafikoak ez du Xv onartzen?!\n"
-
-#: src/video_out/video_out_xv.c:1345
+#: src/video_out/video_out_xv.c:1348 src/video_out/video_out_xxmc.c:2330
#, c-format
msgid ""
-"video_out_xv: using Xv port %ld from adaptor %s for hardware colorspace "
-"conversion and scaling.\n"
+"%s: using Xv port %ld from adaptor %s for hardware colorspace conversion and "
+"scaling.\n"
msgstr ""
-#: src/video_out/video_out_xv.c:1520
-msgid "video_out_xv: this adaptor supports the yv12 format.\n"
-msgstr "video_out_xv: adaptadoreak yv12 formatua onartzen du.\n"
-
-#: src/video_out/video_out_xv.c:1525
-msgid "video_out_xv: this adaptor supports the yuy2 format.\n"
-msgstr "video_out_xv: adaptadoreak yuy2 formatua onartzen du.\n"
-
#: src/video_out/video_out_xvmc.c:1593
msgid "xine video output plugin using the XvMC X video extension"
msgstr "xineo bideo irteera plugina XvMC X bideo luzapena erabiltzen"
@@ -4277,101 +4194,43 @@ msgstr " ez da XvMC onartzen \n"
msgid " With Overlay = %d; UnsignedIntra = %d.\n"
msgstr ""
-#: src/video_out/video_out_xxmc.c:650
-msgid ""
-"video_out_xxmc: XvShmCreateImage failed\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:660
-msgid ""
-"video_out_xxmc: XvShmCreateImage returned a zero size\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:668
-#, c-format
-msgid ""
-"video_out_xxmc: shared memory error in shmget: %s\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:700
-msgid ""
-"video_out_xxmc: x11 error during shared memory XImage creation\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:2287
-#, fuzzy
-msgid "video_out_xxmc: Xv extension not present.\n"
-msgstr "video_out_xvmc: XvMC luzapena ez dago.\n"
-
-#: src/video_out/video_out_xxmc.c:2324
-#, fuzzy
-msgid ""
-"video_out_xxmc: Xv extension is present but I couldn't find a usable yuv12 "
-"port.\n"
-" Looks like your graphics hardware driver doesn't support Xv?!\n"
-msgstr ""
-"video_out_xv: Xv luzapena dago baina ez da yuv12 ataka "
-"erabilgarririkaurkitu.\n"
-" Dirudienez zure txartela grafikoak ez du Xv onartzen?!\n"
-
-#: src/video_out/video_out_xxmc.c:2333
-#, c-format
-msgid ""
-"video_out_xxmc: using Xv port %ld from adaptor %s for hardware colorspace "
-"conversion and scaling.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:2509
-#, fuzzy
-msgid "video_out_xxmc: this adaptor supports the yv12 format.\n"
-msgstr "video_out_xv: adaptadoreak yv12 formatua onartzen du.\n"
-
-#: src/video_out/video_out_xxmc.c:2514
-#, fuzzy
-msgid "video_out_xxmc: this adaptor supports the yuy2 format.\n"
-msgstr "video_out_xv: adaptadoreak yuy2 formatua onartzen du.\n"
-
-#: src/video_out/video_out_xxmc.c:2543
+#: src/video_out/video_out_xxmc.c:2540
msgid "Make XvMC allocate more frames for better buffering."
msgstr ""
-#: src/video_out/video_out_xxmc.c:2544
+#: src/video_out/video_out_xxmc.c:2541
msgid ""
"Some XvMC implementations allow more than 8 frames.\n"
"This option, when turned on, makes the driver try to\n"
"allocate 15 frames. A must for unichrome and live VDR.\n"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2550
+#: src/video_out/video_out_xxmc.c:2547
msgid "Unichrome cpu save"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2551
+#: src/video_out/video_out_xxmc.c:2548
msgid ""
"Saves CPU time by sleeping while decoder works.\n"
"Only for Linux kernel 2.6 series or 2.4 with multimedia patch.\n"
"Experimental.\n"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2557
+#: src/video_out/video_out_xxmc.c:2554
msgid "Fix buggy NVIDIA XvMC subpicture colors"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2558
+#: src/video_out/video_out_xxmc.c:2555
msgid ""
"There's a bug in NVIDIA's XvMC lib that makes red OSD colors\n"
"look blue and vice versa. This option provides a workaround.\n"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2563
+#: src/video_out/video_out_xxmc.c:2560
msgid "Use bob as accelerated deinterlace method."
msgstr ""
-#: src/video_out/video_out_xxmc.c:2564
+#: src/video_out/video_out_xxmc.c:2561
msgid ""
"When interlacing is enabled for hardware accelerated frames,\n"
"Alternate between top and bottom field at double the frame rate.\n"
@@ -4605,12 +4464,12 @@ msgid ""
"info_helper: unsupported conversion %s -> UTF-8, no conversion performed\n"
msgstr "osd: ez da moldatzea onartzen: %s -> %s, ez da moldatuko\n"
-#: src/xine-engine/input_cache.c:167
+#: src/xine-engine/input_cache.c:171
#, fuzzy, c-format
msgid ": open() function should never be called\n"
msgstr "input_rip: open() funtzioa ez zen inoiz deitu beharko\n"
-#: src/xine-engine/input_cache.c:349
+#: src/xine-engine/input_cache.c:353
#, fuzzy, c-format
msgid ": input plugin not defined!\n"
msgstr "input_rip: sarrera pluginia ez ezarririk!\n"
@@ -4723,12 +4582,12 @@ msgstr "io_helper: Fitxategia ez da aurkitu\n"
msgid "io_helper: Connection Refused\n"
msgstr "io_helper: Konexioa Ukaturik\n"
-#: src/xine-engine/load_plugins.c:212
+#: src/xine-engine/load_plugins.c:215
#, c-format
msgid "map_decoder_list: no space for decoder, skipped.\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:327
+#: src/xine-engine/load_plugins.c:330
#, c-format
msgid ""
"load_plugins: ignoring plugin %s, wrong iface version %d (should be %d)\n"
@@ -4736,68 +4595,68 @@ msgstr ""
"load_plugins: %s plugina alde batetara utzi, okerreko iface bertsioa %d (%d "
"espero zen)\n"
-#: src/xine-engine/load_plugins.c:384
+#: src/xine-engine/load_plugins.c:387
#, c-format
msgid "priority for %s decoder"
msgstr "%s deskodetzailearen lehentasuna"
-#: src/xine-engine/load_plugins.c:395
+#: src/xine-engine/load_plugins.c:398
msgid ""
"The priority provides a ranking in case some media can be handled by more "
"than one decoder.\n"
"A priority of 0 enables the decoder's default priority."
msgstr ""
-#: src/xine-engine/load_plugins.c:423
+#: src/xine-engine/load_plugins.c:426
#, c-format
msgid ""
"load_plugins: demuxer plugin %s does not provide a priority, xine-lib will "
"use the default priority.\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:440
+#: src/xine-engine/load_plugins.c:443
#, c-format
msgid ""
"load_plugins: input plugin %s does not provide a priority, xine-lib will use "
"the default priority.\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:496
+#: src/xine-engine/load_plugins.c:499
#, c-format
msgid "load_plugins: plugin %s found\n"
msgstr "load_plugins: %s plugin aurkitu dira\n"
-#: src/xine-engine/load_plugins.c:499
+#: src/xine-engine/load_plugins.c:502
#, fuzzy, c-format
msgid "load_plugins: static plugin found\n"
msgstr "load_plugins: %s plugin aurkitu dira\n"
-#: src/xine-engine/load_plugins.c:506
+#: src/xine-engine/load_plugins.c:509
#, c-format
msgid "load_plugins: plugin limit reached, %s could not be loaded\n"
msgstr "load_plugins: plugin muga gainditu da, %s ezin da kargatu\n"
-#: src/xine-engine/load_plugins.c:509
+#: src/xine-engine/load_plugins.c:512
#, fuzzy, c-format
msgid "load_plugins: plugin limit reached, static plugin could not be loaded\n"
msgstr "load_plugins: plugin muga gainditu da, %s ezin da kargatu\n"
-#: src/xine-engine/load_plugins.c:526
+#: src/xine-engine/load_plugins.c:529
#, c-format
msgid "load_plugins: unknown plugin type %d in %s\n"
msgstr "load_plugins: %d plugin mota ezezaguna %s-n\n"
-#: src/xine-engine/load_plugins.c:530
+#: src/xine-engine/load_plugins.c:533
#, fuzzy, c-format
msgid "load_plugins: unknown statically linked plugin type %d\n"
msgstr "load_plugins: %d plugin mota ezezaguna %s-n\n"
-#: src/xine-engine/load_plugins.c:590
+#: src/xine-engine/load_plugins.c:593
#, c-format
msgid "load_plugins: unable to stat %s\n"
msgstr "load_plugins: ezin da %s identifikatu\n"
-#: src/xine-engine/load_plugins.c:631
+#: src/xine-engine/load_plugins.c:634
#, c-format
msgid ""
"load_plugins: cannot open plugin lib %s:\n"
@@ -4806,7 +4665,7 @@ msgstr ""
"load_plugins: ezin da %s plugin liburutegia ireki:\n"
"%s\n"
-#: src/xine-engine/load_plugins.c:646
+#: src/xine-engine/load_plugins.c:649
#, c-format
msgid ""
"load_plugins: can't get plugin info from %s:\n"
@@ -4815,39 +4674,44 @@ msgstr ""
"load_plugins: ezin da %s-eko plugin informazio eskuratu:\n"
"%s\n"
-#: src/xine-engine/load_plugins.c:664
+#: src/xine-engine/load_plugins.c:667
#, c-format
msgid "load_plugins: skipping unreadable plugin directory %s.\n"
msgstr "load_plugins: alde batetara uzten %s plugin karpeta irakurtezina.\n"
-#: src/xine-engine/load_plugins.c:713
+#: src/xine-engine/load_plugins.c:716
#, c-format
msgid ""
"load_plugins: cannot (stage 2) open plugin lib %s:\n"
"%s\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:739
+#: src/xine-engine/load_plugins.c:742
#, c-format
msgid "load_plugins: Yikes! %s doesn't contain plugin info.\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:1305
+#: src/xine-engine/load_plugins.c:1104 src/xine-engine/load_plugins.c:1113
+#, fuzzy, c-format
+msgid "Unable to create %s directory: %s\n"
+msgstr "Ezin da %s ireki: %s.\n"
+
+#: src/xine-engine/load_plugins.c:1345
#, c-format
msgid "load_plugins: unknown content detection strategy %d\n"
msgstr "load_plugins: %d eduki atzemate estrategia ezezaguna\n"
-#: src/xine-engine/load_plugins.c:1415
+#: src/xine-engine/load_plugins.c:1455
#, c-format
msgid "load_plugins: using demuxer '%s'\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:1726
+#: src/xine-engine/load_plugins.c:1766
#, c-format
msgid "load_plugins: failed to load audio output plugin <%s>\n"
msgstr "load_plugins: huts <%s> audio irteera plugina kargatzerakoan\n"
-#: src/xine-engine/load_plugins.c:1729
+#: src/xine-engine/load_plugins.c:1769
msgid ""
"load_plugins: audio output auto-probing didn't find any usable audio "
"driver.\n"
@@ -4855,7 +4719,7 @@ msgstr ""
"load_plugins: audio irteera auto-frogak ez du adio kontrolatzailerik "
"aurkitu.\n"
-#: src/xine-engine/load_plugins.c:2033
+#: src/xine-engine/load_plugins.c:2073
#, fuzzy, c-format
msgid ""
"load_plugins: cannot unload plugin lib %s:\n"
@@ -4864,32 +4728,28 @@ msgstr ""
"load_plugins: ezin da %s plugin liburutegia ireki:\n"
"%s\n"
-#: src/xine-engine/osd.c:745
+#: src/xine-engine/osd.c:747
#, c-format
msgid "font '%s-%d' already loaded, weird.\n"
msgstr "'%s-%d' letra-tipoa dagoeneko kargaturik, bitxia.\n"
-#: src/xine-engine/osd.c:757
+#: src/xine-engine/osd.c:759
#, c-format
msgid "font '%s' loading failed (%d < %d)\n"
msgstr "huts '%s' letra tipoa kargatzerakoan (%d < %d)\n"
-#: src/xine-engine/osd.c:767
+#: src/xine-engine/osd.c:769
#, c-format
msgid "wrong version for font '%s'. expected %d found %d.\n"
msgstr ""
"'%s' letra tipoaren okerreko bertsioa. %d espero zen baina %d aurkitu da.\n"
-#: src/xine-engine/osd.c:834
-msgid "osd: cannot initialize ft2 library\n"
-msgstr "osd: ezin da ft2 liburutegia abiarazi\n"
-
-#: src/xine-engine/osd.c:857
+#: src/xine-engine/osd.c:856
#, c-format
msgid "osd: error matching font %s with FontConfig"
msgstr ""
-#: src/xine-engine/osd.c:871
+#: src/xine-engine/osd.c:870
#, fuzzy, c-format
msgid "osd: error loading font %s with FontConfig"
msgstr "osd: errorea glyph %i kargatzerakoan\n"
@@ -4899,59 +4759,63 @@ msgstr "osd: errorea glyph %i kargatzerakoan\n"
msgid "osd: error looking up font %s with FontConfig"
msgstr ""
-#: src/xine-engine/osd.c:895
-#, c-format
-msgid "osd: error loading font %s with ft2\n"
-msgstr ""
+#: src/xine-engine/osd.c:914
+#, fuzzy, c-format
+msgid "osd: error loading font %s with in XDG data directories.\n"
+msgstr "osd: errorea glyph %i kargatzerakoan\n"
-#: src/xine-engine/osd.c:905
+#: src/xine-engine/osd.c:923
+msgid "osd: cannot initialize ft2 library\n"
+msgstr "osd: ezin da ft2 liburutegia abiarazi\n"
+
+#: src/xine-engine/osd.c:945
msgid "osd: error setting font size (no scalable font?)\n"
msgstr ""
"osd: errorea letra-tipo tamaina ezarpenean (letra-tipo ez eskalagarria?)\n"
-#: src/xine-engine/osd.c:1021
+#: src/xine-engine/osd.c:1061
#, c-format
msgid ""
"osd: unknown sequence starting with byte 0x%02X in encoding \"%s\", "
"skipping\n"
msgstr ""
-#: src/xine-engine/osd.c:1077
+#: src/xine-engine/osd.c:1117
msgid "osd: can't find out current locale character set\n"
msgstr "osd: ezin da irteera karaktere jokoa aurkitu\n"
-#: src/xine-engine/osd.c:1087
+#: src/xine-engine/osd.c:1127
#, c-format
msgid "osd: unsupported conversion %s -> %s, no conversion performed\n"
msgstr "osd: ez da moldatzea onartzen: %s -> %s, ez da moldatuko\n"
-#: src/xine-engine/osd.c:1142 src/xine-engine/osd.c:1310
+#: src/xine-engine/osd.c:1182 src/xine-engine/osd.c:1350
msgid "osd: font isn't defined\n"
msgstr "osd: letra-tipoa ez dago ezarririk\n"
-#: src/xine-engine/osd.c:1181
+#: src/xine-engine/osd.c:1221
msgid "osd: error loading glyph\n"
msgstr "osd: errorea glyph kargatzerkaoan\n"
-#: src/xine-engine/osd.c:1187
+#: src/xine-engine/osd.c:1227
msgid "osd: error in rendering glyph\n"
msgstr "osd: errorea glyph reenderizatzerakoan\n"
-#: src/xine-engine/osd.c:1347
+#: src/xine-engine/osd.c:1387
#, c-format
msgid "osd: error loading glyph %i\n"
msgstr "osd: errorea glyph %i kargatzerakoan\n"
-#: src/xine-engine/osd.c:1354
+#: src/xine-engine/osd.c:1394
msgid "osd: error in rendering\n"
msgstr "osd: errorea reenderizatzerakoan\n"
-#: src/xine-engine/osd.c:1611
+#: src/xine-engine/osd.c:1660
msgid "palette (foreground-border-background) to use for subtitles and OSD"
msgstr ""
"OSD eta azpitituluetan erabiliko den paleta (aurreko-ertza-atzeko koloreak)"
-#: src/xine-engine/osd.c:1612
+#: src/xine-engine/osd.c:1661
msgid ""
"The palette for on-screen-display and some subtitle formats that do not "
"specify any colouring themselves. The palettes are listed in the form: "
@@ -5066,130 +4930,130 @@ msgid ""
"accelerated, this can dramatically reduce CPU usage."
msgstr ""
-#: src/xine-engine/xine.c:704 src/xine-engine/xine.c:811
-#: src/xine-engine/xine.c:850 src/xine-engine/xine.c:886
-#: src/xine-engine/xine.c:898 src/xine-engine/xine.c:911
-#: src/xine-engine/xine.c:924 src/xine-engine/xine.c:937
-#: src/xine-engine/xine.c:963 src/xine-engine/xine.c:988
-#: src/xine-engine/xine.c:1023
+#: src/xine-engine/xine.c:706 src/xine-engine/xine.c:813
+#: src/xine-engine/xine.c:852 src/xine-engine/xine.c:888
+#: src/xine-engine/xine.c:900 src/xine-engine/xine.c:913
+#: src/xine-engine/xine.c:926 src/xine-engine/xine.c:939
+#: src/xine-engine/xine.c:965 src/xine-engine/xine.c:990
+#: src/xine-engine/xine.c:1025
msgid "xine: error while parsing mrl\n"
msgstr "xine: errorea mrl analizatzerakoan\n"
-#: src/xine-engine/xine.c:740
+#: src/xine-engine/xine.c:742
#, c-format
msgid "xine: found input plugin : %s\n"
msgstr "xine: input plugin-a aurkiturik : %s\n"
-#: src/xine-engine/xine.c:758
+#: src/xine-engine/xine.c:760
#, c-format
msgid "xine: input plugin cannot open MRL [%s]\n"
msgstr "xine: sarrera pluginak ezin du MRL-a [%s] ireki\n"
-#: src/xine-engine/xine.c:774
+#: src/xine-engine/xine.c:776
#, c-format
msgid "xine: cannot find input plugin for MRL [%s]\n"
msgstr "xine: ezin da [%s] MRL-aren plugina aurkitu\n"
-#: src/xine-engine/xine.c:800
+#: src/xine-engine/xine.c:802
#, c-format
msgid "xine: specified demuxer %s failed to start\n"
msgstr ""
-#: src/xine-engine/xine.c:836
+#: src/xine-engine/xine.c:838
#, c-format
msgid "xine: join rip input plugin\n"
msgstr ""
-#: src/xine-engine/xine.c:843
+#: src/xine-engine/xine.c:845
msgid "xine: error opening rip input plugin instance\n"
msgstr ""
-#: src/xine-engine/xine.c:874
+#: src/xine-engine/xine.c:876
#, c-format
msgid "xine: last_probed demuxer %s failed to start\n"
msgstr ""
-#: src/xine-engine/xine.c:903
+#: src/xine-engine/xine.c:905
msgid "ignoring video\n"
msgstr "bidoa alde batetara uzten\n"
-#: src/xine-engine/xine.c:916
+#: src/xine-engine/xine.c:918
msgid "ignoring audio\n"
msgstr "audioa alde batetara uzten\n"
-#: src/xine-engine/xine.c:929
+#: src/xine-engine/xine.c:931
msgid "ignoring subpicture\n"
msgstr "azpi-irudia alde batetara uzten\n"
-#: src/xine-engine/xine.c:942
+#: src/xine-engine/xine.c:944
msgid "input cache plugin disabled\n"
msgstr ""
-#: src/xine-engine/xine.c:1013
+#: src/xine-engine/xine.c:1015
#, c-format
msgid "subtitle mrl opened '%s'\n"
msgstr "'%s' azpititulu mrl-a irekirik\n"
-#: src/xine-engine/xine.c:1017
+#: src/xine-engine/xine.c:1019
msgid "xine: error opening subtitle mrl\n"
msgstr "xine: errorea azpititulu mrl-a irekitzerakoan\n"
-#: src/xine-engine/xine.c:1049
+#: src/xine-engine/xine.c:1051
#, c-format
msgid "xine: error while parsing MRL\n"
msgstr "xine: errorea MRL-analizatzerakoan\n"
-#: src/xine-engine/xine.c:1056
+#: src/xine-engine/xine.c:1058
#, c-format
msgid "xine: changing option '%s' from MRL isn't permitted\n"
msgstr "xine: MRL-ko '%s' aukera aldaketa ez da onartzen\n"
-#: src/xine-engine/xine.c:1076
+#: src/xine-engine/xine.c:1078
#, c-format
msgid "xine: couldn't find demux for >%s<\n"
msgstr ""
-#: src/xine-engine/xine.c:1092
+#: src/xine-engine/xine.c:1094
#, c-format
msgid "xine: found demuxer plugin: %s\n"
msgstr ""
-#: src/xine-engine/xine.c:1112
+#: src/xine-engine/xine.c:1114
#, c-format
msgid "xine: demuxer failed to start\n"
msgstr ""
-#: src/xine-engine/xine.c:1177
+#: src/xine-engine/xine.c:1179
#, c-format
msgid "xine_play: no demux available\n"
msgstr ""
-#: src/xine-engine/xine.c:1247
+#: src/xine-engine/xine.c:1249
#, c-format
msgid "xine_play: demux failed to start\n"
msgstr ""
-#: src/xine-engine/xine.c:1523
+#: src/xine-engine/xine.c:1527
#, c-format
msgid "xine: The specified save_dir \"%s\" might be a security risk.\n"
msgstr ""
"xine: Ezarritako \"%s\" gordetze karpeta (save_dir) segurtasun arrisku bat "
"izan daiteke.\n"
-#: src/xine-engine/xine.c:1528
+#: src/xine-engine/xine.c:1532
msgid "The specified save_dir might be a security risk."
msgstr ""
"Ezarritako gordetze karpeta (save_dir) segurtasun arrisku bat izan daiteke."
-#: src/xine-engine/xine.c:1554
+#: src/xine-engine/xine.c:1561
msgid "xine: locale not supported by C library\n"
msgstr "xine: lokala ez du C liburutegiak onartzen\n"
-#: src/xine-engine/xine.c:1563
+#: src/xine-engine/xine.c:1570
msgid "media format detection strategy"
msgstr "medio formatu atzemate modua"
-#: src/xine-engine/xine.c:1564
+#: src/xine-engine/xine.c:1571
msgid ""
"xine offers various methods to detect the media format of input to play. The "
"individual values are:\n"
@@ -5218,11 +5082,11 @@ msgstr ""
"extension\n"
"Izen luzapen bidez bakarrik atzemna.\n"
-#: src/xine-engine/xine.c:1582
+#: src/xine-engine/xine.c:1589
msgid "directory for saving streams"
msgstr "korronteak gordetzeko karpeta"
-#: src/xine-engine/xine.c:1583
+#: src/xine-engine/xine.c:1590
msgid ""
"When using the stream save feature, files will be written only into this "
"directory.\n"
@@ -5232,11 +5096,11 @@ msgid ""
"content in any file."
msgstr ""
-#: src/xine-engine/xine.c:1594
+#: src/xine-engine/xine.c:1601
msgid "allow implicit changes to the configuration (e.g. by MRL)"
msgstr "Onartu aldaketa inplizitoak konfiguraketan (adib. MRL bidez)"
-#: src/xine-engine/xine.c:1595
+#: src/xine-engine/xine.c:1602
msgid ""
"If enabled, you allow xine to change your configuration without explicit "
"actions from your side. For example configuration changes demanded by MRLs "
@@ -5246,26 +5110,26 @@ msgid ""
"configuration, you might end with a totally messed up xine."
msgstr ""
-#: src/xine-engine/xine.c:1609
+#: src/xine-engine/xine.c:1616
msgid "Timeout for network stream reading (in seconds)"
msgstr ""
-#: src/xine-engine/xine.c:1610
+#: src/xine-engine/xine.c:1617
msgid ""
"Specifies the timeout when reading from network streams, in seconds. Too low "
"values might stop streaming when the source is slow or the bandwidth is "
"occupied, too high values will freeze the player if the connection is lost."
msgstr ""
-#: src/xine-engine/xine.c:1962
+#: src/xine-engine/xine.c:1969
msgid "messages"
msgstr "mezuak"
-#: src/xine-engine/xine.c:1963
+#: src/xine-engine/xine.c:1970
msgid "plugin"
msgstr "plugina"
-#: src/xine-engine/xine.c:1964
+#: src/xine-engine/xine.c:1971
msgid "trace"
msgstr "aztarna"
@@ -5342,6 +5206,79 @@ msgstr ""
msgid "Benchmarking memcpy methods (smaller is better):\n"
msgstr "memcpy metodoak frogatzen (txeikiena obea da)\n"
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xcbshm: MIT shared memory extension not present on display.\n"
+#~ msgstr ""
+#~ "video_out_xshm: MIT partekatutako memoria luzapena ez dago pantailan.\n"
+
+#, fuzzy
+#~ msgid "video_out_xcbshm: your video mode was not recognized, sorry :-(\n"
+#~ msgstr "video_out_xshm: bideo modua ez da ezagutzen, barkatu :-(\n"
+
+#, fuzzy
+#~ msgid "video_out_xcbxv: Xv extension not present.\n"
+#~ msgstr "video_out_xv: Xv luzapena ez dago.\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xcbxv: Xv extension is present but I couldn't find a usable "
+#~ "yuv12 port.\n"
+#~ " Looks like your graphics hardware driver doesn't support "
+#~ "Xv?!\n"
+#~ msgstr ""
+#~ "video_out_xv: Xv luzapena dago baina ez da yuv12 ataka "
+#~ "erabilgarririkaurkitu.\n"
+#~ " Dirudienez zure txartela grafikoak ez du Xv onartzen?!\n"
+
+#, fuzzy
+#~ msgid "video_out_xcbxv: this adaptor supports the yv12 format.\n"
+#~ msgstr "video_out_xv: adaptadoreak yv12 formatua onartzen du.\n"
+
+#, fuzzy
+#~ msgid "video_out_xcbxv: this adaptor supports the yuy2 format.\n"
+#~ msgstr "video_out_xv: adaptadoreak yuy2 formatua onartzen du.\n"
+
+#~ msgid "video_out_xshm: your video mode was not recognized, sorry :-(\n"
+#~ msgstr "video_out_xshm: bideo modua ez da ezagutzen, barkatu :-(\n"
+
+#, fuzzy
+#~ msgid "video_out_xxmc: Xv extension not present.\n"
+#~ msgstr "video_out_xvmc: XvMC luzapena ez dago.\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xxmc: Xv extension is present but I couldn't find a usable "
+#~ "yuv12 port.\n"
+#~ " Looks like your graphics hardware driver doesn't support "
+#~ "Xv?!\n"
+#~ msgstr ""
+#~ "video_out_xv: Xv luzapena dago baina ez da yuv12 ataka "
+#~ "erabilgarririkaurkitu.\n"
+#~ " Dirudienez zure txartela grafikoak ez du Xv onartzen?!\n"
+
+#, fuzzy
+#~ msgid "video_out_xxmc: this adaptor supports the yv12 format.\n"
+#~ msgstr "video_out_xv: adaptadoreak yv12 formatua onartzen du.\n"
+
+#, fuzzy
+#~ msgid "video_out_xxmc: this adaptor supports the yuy2 format.\n"
+#~ msgstr "video_out_xv: adaptadoreak yuy2 formatua onartzen du.\n"
+
+#~ msgid "CDDB cache directory"
+#~ msgstr "CDDB katxe karpeta"
+
+#~ msgid ""
+#~ "The replies from the CDDB server will be cached in this directory.\n"
+#~ "This setting is security critical, because files with uncontrollable "
+#~ "names will be created in this directory. Be sure to use a dedicated "
+#~ "directory not used for anything but CDDB caching."
+#~ msgstr ""
+#~ "CDDB zarbitzariaren erantzunak karpeta honetan gordeko dira.\n"
+#~ "Ezarpena segurtasun aldetik kritikoa da, kontrolatugabeko fitxategi "
+#~ "izenak sortuko bait dira. Ziurtatu erabiliko den karpeta ez dela honetaz "
+#~ "beste ezertarako erabiliko."
+
#~ msgid "avcodec_find_decoder (CODEC_ID_MPEG1VIDEO) failed.\n"
#~ msgstr "avcodec_find_decoder (CODEC_ID_MPEG1VIDEO) hutsa.\n"
diff --git a/po/fr.po b/po/fr.po
index 3239c9078..102ceb203 100644
--- a/po/fr.po
+++ b/po/fr.po
@@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: xine-lib 0.9.13\n"
"Report-Msgid-Bugs-To: xine-devel@lists.sourceforge.net\n"
-"POT-Creation-Date: 2007-04-06 15:39+0200\n"
+"POT-Creation-Date: 2007-04-24 21:48+0100\n"
"PO-Revision-Date: 2002-06-07 15:08 +0200\n"
"Last-Translator: Daniel Caujolle-Bert <segfault@club-internet.fr>\n"
"Language-Team: French <fr@li.org>\n"
@@ -39,117 +39,117 @@ msgstr ""
msgid "Unknown error"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:354
+#: src/audio_out/audio_alsa_out.c:351
#, c-format
msgid "audio_alsa_out:Already open...WHY!"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:382
+#: src/audio_out/audio_alsa_out.c:379
#, c-format
msgid "audio_alsa_out: snd_pcm_open() of %s failed: %s\n"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:384
+#: src/audio_out/audio_alsa_out.c:381
msgid "audio_alsa_out: >>> check if another program already uses PCM <<<\n"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:397
+#: src/audio_out/audio_alsa_out.c:394
#, c-format
msgid ""
"audio_alsa_out: broken configuration for this PCM: no configurations "
"available: %s\n"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1289
+#: src/audio_out/audio_alsa_out.c:1286
msgid "notify changes to the hardware mixer"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1290
+#: src/audio_out/audio_alsa_out.c:1287
msgid ""
"When the hardware mixer changes, your application will receive a "
"notification so that it can update its graphical representation of the mixer "
"settings on the fly."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1355
+#: src/audio_out/audio_alsa_out.c:1352
#, c-format
msgid "snd_lib_error_set_handler() failed: %d"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1362
+#: src/audio_out/audio_alsa_out.c:1359
msgid "sound card can do mmap"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1363
+#: src/audio_out/audio_alsa_out.c:1360
msgid ""
"Enable this, if your sound card and alsa driver support memory mapped IO.\n"
"You can try enabling it and check, if everything works. If it does, this "
"will increase performance."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1372
+#: src/audio_out/audio_alsa_out.c:1369
msgid "device used for mono output"
msgstr "périphérique utilisé pour la sortie mono"
-#: src/audio_out/audio_alsa_out.c:1373
+#: src/audio_out/audio_alsa_out.c:1370
msgid ""
"xine will use this alsa device to output mono sound.\n"
"See the alsa documentation for information on alsa devices."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1381
+#: src/audio_out/audio_alsa_out.c:1378
msgid "device used for stereo output"
msgstr "périphérique utilisé pour la sortie stéréo"
-#: src/audio_out/audio_alsa_out.c:1382
+#: src/audio_out/audio_alsa_out.c:1379
msgid ""
"xine will use this alsa device to output stereo sound.\n"
"See the alsa documentation for information on alsa devices."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1390
+#: src/audio_out/audio_alsa_out.c:1387
msgid "device used for 4-channel output"
msgstr "périphérique utilisé pour la sortie 4 canaux"
-#: src/audio_out/audio_alsa_out.c:1391
+#: src/audio_out/audio_alsa_out.c:1388
msgid ""
"xine will use this alsa device to output 4 channel (4.0) surround sound.\n"
"See the alsa documentation for information on alsa devices."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1400 src/audio_out/audio_alsa_out.c:1410
+#: src/audio_out/audio_alsa_out.c:1397 src/audio_out/audio_alsa_out.c:1407
msgid "device used for 5.1-channel output"
msgstr "périphérique utilisé pour la sortie 5.1 canaux"
-#: src/audio_out/audio_alsa_out.c:1401
+#: src/audio_out/audio_alsa_out.c:1398
msgid ""
"xine will use this alsa device to output 5 channel plus LFE (5.1) surround "
"sound.\n"
"See the alsa documentation for information on alsa devices."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1411
+#: src/audio_out/audio_alsa_out.c:1408
msgid ""
"xine will use this alsa device to output undecoded digital surround sound. "
"This can be used be external surround decoders.\n"
"See the alsa documentation for information on alsa devices."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1431
+#: src/audio_out/audio_alsa_out.c:1428
#, fuzzy, c-format
msgid "snd_pcm_open() failed:%d:%s\n"
msgstr "input_cda: open(%s) a échoué: %s.\n"
-#: src/audio_out/audio_alsa_out.c:1433
+#: src/audio_out/audio_alsa_out.c:1430
#, c-format
msgid ">>> Check if another program already uses PCM <<<\n"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1464 src/audio_out/audio_oss_out.c:929
+#: src/audio_out/audio_alsa_out.c:1461 src/audio_out/audio_oss_out.c:929
msgid "speaker arrangement"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1465 src/audio_out/audio_oss_out.c:930
+#: src/audio_out/audio_alsa_out.c:1462 src/audio_out/audio_oss_out.c:930
msgid ""
"Select how your speakers are arranged, this determines which speakers xine "
"uses for sound output. The individual values are:\n"
@@ -181,89 +181,89 @@ msgid ""
"formats you want to play to your sound card's digital output."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1494
+#: src/audio_out/audio_alsa_out.c:1491
msgid "audio_alsa_out : supported modes are "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1497
+#: src/audio_out/audio_alsa_out.c:1494
msgid "8bit "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1502
+#: src/audio_out/audio_alsa_out.c:1499
msgid "16bit "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1506
+#: src/audio_out/audio_alsa_out.c:1503
msgid "24bit "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1510
+#: src/audio_out/audio_alsa_out.c:1507
msgid "32bit "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1521
+#: src/audio_out/audio_alsa_out.c:1518
msgid "mono "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1525
+#: src/audio_out/audio_alsa_out.c:1522
msgid "stereo "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1530
+#: src/audio_out/audio_alsa_out.c:1527
#, fuzzy
msgid "4-channel "
msgstr "canal"
-#: src/audio_out/audio_alsa_out.c:1533
+#: src/audio_out/audio_alsa_out.c:1530
msgid "(4-channel not enabled in xine config) "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1538
+#: src/audio_out/audio_alsa_out.c:1535
#, fuzzy
msgid "4.1-channel "
msgstr "canal"
-#: src/audio_out/audio_alsa_out.c:1541
+#: src/audio_out/audio_alsa_out.c:1538
msgid "(4.1-channel not enabled in xine config) "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1546
+#: src/audio_out/audio_alsa_out.c:1543
#, fuzzy
msgid "5-channel "
msgstr "canal"
-#: src/audio_out/audio_alsa_out.c:1549
+#: src/audio_out/audio_alsa_out.c:1546
msgid "(5-channel not enabled in xine config) "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1554
+#: src/audio_out/audio_alsa_out.c:1551
#, fuzzy
msgid "5.1-channel "
msgstr "canal"
-#: src/audio_out/audio_alsa_out.c:1557
+#: src/audio_out/audio_alsa_out.c:1554
msgid "(5.1-channel not enabled in xine config) "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1580
+#: src/audio_out/audio_alsa_out.c:1577
msgid "a/52 and DTS pass-through\n"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1583
+#: src/audio_out/audio_alsa_out.c:1580
msgid "(a/52 and DTS pass-through not enabled in xine config)\n"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1590
+#: src/audio_out/audio_alsa_out.c:1587
msgid "alsa mixer device"
msgstr "périphérique du mixeur alsa"
-#: src/audio_out/audio_alsa_out.c:1591
+#: src/audio_out/audio_alsa_out.c:1588
msgid ""
"xine will use this alsa mixer device to change the volume.\n"
"See the alsa documentation for information on alsa devices."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1665
+#: src/audio_out/audio_alsa_out.c:1662
msgid "xine audio output plugin using alsa-compliant audio devices/drivers"
msgstr ""
"plugin de sortie audio de xine utilisant les pilotes/périphériques alsa"
@@ -278,201 +278,201 @@ msgstr "plugin de sortie audio de xine utilisant esd"
msgid "xine output plugin for Coreaudio/Mac OS X"
msgstr "plugin de sortie audio de xine utilisant esd"
-#: src/audio_out/audio_directx2_out.c:166
+#: src/audio_out/audio_directx2_out.c:163
msgid "Error"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:173
+#: src/audio_out/audio_directx2_out.c:170
msgid "success"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:175
+#: src/audio_out/audio_directx2_out.c:172
msgid "access denied"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:177
+#: src/audio_out/audio_directx2_out.c:174
msgid "resource is already in use"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:178
+#: src/audio_out/audio_directx2_out.c:175
msgid "object was already initialized"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:179
+#: src/audio_out/audio_directx2_out.c:176
msgid "specified wave format is not supported"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:180
+#: src/audio_out/audio_directx2_out.c:177
msgid "memory buffer has been lost and must be restored"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:181
+#: src/audio_out/audio_directx2_out.c:178
msgid "requested buffer control is not available"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:182
+#: src/audio_out/audio_directx2_out.c:179
msgid "undetermined error inside DirectSound subsystem"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:184
+#: src/audio_out/audio_directx2_out.c:181
msgid "DirectSound hardware device is unavailable"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:186
+#: src/audio_out/audio_directx2_out.c:183
msgid "function is not valid for the current state of the object"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:187
+#: src/audio_out/audio_directx2_out.c:184
msgid "invalid parameter was passed"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:188
+#: src/audio_out/audio_directx2_out.c:185
msgid "object doesn't support aggregation"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:189
+#: src/audio_out/audio_directx2_out.c:186
msgid "no sound driver available for use"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:190
+#: src/audio_out/audio_directx2_out.c:187
msgid "requested COM interface not available"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:191
+#: src/audio_out/audio_directx2_out.c:188
msgid "another application has a higher priority level"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:192
+#: src/audio_out/audio_directx2_out.c:189
msgid "insufficient memory"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:193
+#: src/audio_out/audio_directx2_out.c:190
msgid "low priority level for this function"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:194
+#: src/audio_out/audio_directx2_out.c:191
msgid "DirectSound wasn't initialized"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:195
+#: src/audio_out/audio_directx2_out.c:192
msgid "function is not supported"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:196
+#: src/audio_out/audio_directx2_out.c:193
msgid "unknown error"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:206
+#: src/audio_out/audio_directx2_out.c:203
#, c-format
msgid "Unable to create direct sound object."
msgstr ""
-#: src/audio_out/audio_directx2_out.c:212
+#: src/audio_out/audio_directx2_out.c:209
#, c-format
msgid "Could not set direct sound cooperative level."
msgstr ""
-#: src/audio_out/audio_directx2_out.c:286
+#: src/audio_out/audio_directx2_out.c:283
msgid "Unable to create secondary direct sound buffer"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:310
+#: src/audio_out/audio_directx2_out.c:307
#, c-format
msgid "Unable to create buffer position events."
msgstr ""
-#: src/audio_out/audio_directx2_out.c:318
+#: src/audio_out/audio_directx2_out.c:315
msgid "Unable to get notification interface"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:323
+#: src/audio_out/audio_directx2_out.c:320
msgid "Unable to set notification positions"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:343
+#: src/audio_out/audio_directx2_out.c:340
msgid "Couldn't play sound buffer"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:355
+#: src/audio_out/audio_directx2_out.c:352
msgid "Couldn't stop sound buffer"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:368
+#: src/audio_out/audio_directx2_out.c:365
msgid "Can't get buffer position"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:382
+#: src/audio_out/audio_directx2_out.c:379
msgid "Can't set buffer position"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:414
+#: src/audio_out/audio_directx2_out.c:411
msgid "Can't set sound volume"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:432
+#: src/audio_out/audio_directx2_out.c:429
#, c-format
msgid ": buffer lost, tryig to restore\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:436
+#: src/audio_out/audio_directx2_out.c:433
msgid "Couldn't lock direct sound buffer"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:447
+#: src/audio_out/audio_directx2_out.c:444
msgid "Couldn't unlock direct sound buffer"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:544
+#: src/audio_out/audio_directx2_out.c:541
#, fuzzy, c-format
msgid "Unable to create primary direct sound buffer."
msgstr "incapable d'allouer le buffer d'entrée.\n"
-#: src/audio_out/audio_directx2_out.c:637
+#: src/audio_out/audio_directx2_out.c:634
#, c-format
msgid ": play cursor overran, flushing buffers\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:655
+#: src/audio_out/audio_directx2_out.c:652
#, c-format
msgid ": delayed by %ld msec\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:759
+#: src/audio_out/audio_directx2_out.c:756
#, fuzzy, c-format
msgid ": can't create pthread condition: %s\n"
msgstr "input_rtp: ne peux pas créer le nouveau thread (%s)\n"
-#: src/audio_out/audio_directx2_out.c:763
+#: src/audio_out/audio_directx2_out.c:760
#, fuzzy, c-format
msgid ": can't create pthread mutex: %s\n"
msgstr "input_rtp: ne peux pas créer le nouveau thread (%s)\n"
-#: src/audio_out/audio_directx2_out.c:770
+#: src/audio_out/audio_directx2_out.c:767
#, fuzzy, c-format
msgid ": can't create buffer pthread: %s\n"
msgstr "input_rtp: ne peux pas créer le nouveau thread (%s)\n"
-#: src/audio_out/audio_directx2_out.c:877
+#: src/audio_out/audio_directx2_out.c:874
#, fuzzy, c-format
msgid ": can't destroy buffer pthread: %s\n"
msgstr "input_rtp: ne peux pas créer le nouveau thread (%s)\n"
-#: src/audio_out/audio_directx2_out.c:884
+#: src/audio_out/audio_directx2_out.c:881
#, c-format
msgid ": can't destroy pthread condition: %s\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:887
+#: src/audio_out/audio_directx2_out.c:884
#, c-format
msgid ": can't destroy pthread mutex: %s\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:947
+#: src/audio_out/audio_directx2_out.c:944
#, c-format
msgid ": unknown control command %d\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:1003
+#: src/audio_out/audio_directx2_out.c:1000
#, fuzzy
msgid "second xine audio output plugin using directx"
msgstr "plugin de sortie audio de xine utilisant esd"
@@ -874,7 +874,7 @@ msgstr ""
msgid "demux_snd: unsupported audio type: %d\n"
msgstr "demus_avi: type audio inconnu 0x%lx\n"
-#: src/demuxers/demux_tta.c:88
+#: src/demuxers/demux_tta.c:86
msgid "demux_tta: total frames count too high\n"
msgstr ""
@@ -894,7 +894,7 @@ msgstr ""
msgid "demux_wc3movie: SHOT chunk referenced invalid palette (%d >= %d)\n"
msgstr ""
-#: src/demuxers/demux_wc3movie.c:406
+#: src/demuxers/demux_wc3movie.c:404
#, c-format
msgid "demux_wc3movie: There was a problem while loading palette chunks\n"
msgstr ""
@@ -1253,41 +1253,41 @@ msgstr ""
msgid "video_out_dxr3: ERROR Reading overlay init file. Run autocal!\n"
msgstr ""
-#: src/input/input_cdda.c:1621
+#: src/input/input_cdda.c:1608
#, fuzzy, c-format
msgid "%s: can't connect to %s:%d\n"
msgstr "input_net: impossible de se connecter à '%s'.\n"
-#: src/input/input_cdda.c:1668
+#: src/input/input_cdda.c:1655
#, fuzzy, c-format
msgid "input_cdda: successfuly connected to cddb server '%s:%d'.\n"
msgstr "input_cda: serveur '%s:%d' connecté avec succés.\n"
-#: src/input/input_cdda.c:1673
+#: src/input/input_cdda.c:1660
#, fuzzy, c-format
msgid "input_cdda: failed to connect to cddb server '%s:%d' (%s).\n"
msgstr "input_net: impossible de se connecter à '%s'.\n"
-#: src/input/input_cdda.c:2707
+#: src/input/input_cdda.c:2690
msgid "CD Digital Audio (aka. CDDA)"
msgstr ""
-#: src/input/input_cdda.c:2760
+#: src/input/input_cdda.c:2742
#, fuzzy
msgid "device used for CD audio"
msgstr "périphérique utilisé pour la sortie 4 canaux"
-#: src/input/input_cdda.c:2761
+#: src/input/input_cdda.c:2743
msgid ""
"The path to the device, usually a CD or DVD drive, which you intend to use "
"for playing audio CDs."
msgstr ""
-#: src/input/input_cdda.c:2767
+#: src/input/input_cdda.c:2749
msgid "query CDDB"
msgstr ""
-#: src/input/input_cdda.c:2767
+#: src/input/input_cdda.c:2749
msgid ""
"Enables CDDB queries, which will give you convenient title and track names "
"for your audio CDs.\n"
@@ -1296,11 +1296,11 @@ msgid ""
"listening habits."
msgstr ""
-#: src/input/input_cdda.c:2775
+#: src/input/input_cdda.c:2757
msgid "CDDB server name"
msgstr ""
-#: src/input/input_cdda.c:2775
+#: src/input/input_cdda.c:2757
msgid ""
"The CDDB server used to retrieve the title and track information from.\n"
"This setting is security critical, because the sever will receive "
@@ -1308,31 +1308,19 @@ msgid ""
"malicious replies. Be sure to enter a server you can trust."
msgstr ""
-#: src/input/input_cdda.c:2783
+#: src/input/input_cdda.c:2765
msgid "CDDB server port"
msgstr ""
-#: src/input/input_cdda.c:2783
+#: src/input/input_cdda.c:2765
msgid "The server port used to retrieve the title and track information from."
msgstr ""
-#: src/input/input_cdda.c:2789
-msgid "CDDB cache directory"
-msgstr ""
-
-#: src/input/input_cdda.c:2789
-msgid ""
-"The replies from the CDDB server will be cached in this directory.\n"
-"This setting is security critical, because files with uncontrollable names "
-"will be created in this directory. Be sure to use a dedicated directory not "
-"used for anything but CDDB caching."
-msgstr ""
-
-#: src/input/input_cdda.c:2797
+#: src/input/input_cdda.c:2771
msgid "slow down disc drive to this speed factor"
msgstr ""
-#: src/input/input_cdda.c:2798
+#: src/input/input_cdda.c:2772
msgid ""
"Since some CD or DVD drives make some really loud noises because of the fast "
"disc rotation, xine will try to slow them down. With standard CD or DVD "
@@ -1341,121 +1329,126 @@ msgid ""
"A value of zero here will disable the slowdown."
msgstr ""
-#: src/input/input_dvb.c:881
+#: src/input/input_dvb.c:899
+#, fuzzy, c-format
+msgid "input_dvb: failed to open dvb channel file '%s': %s\n"
+msgstr "input_file: tente d'ouvrir le fichier de sous-titre '%s'\n"
+
+#: src/input/input_dvb.c:905
#, fuzzy, c-format
-msgid "input_dvb: failed to open dvb channel file '%s'\n"
+msgid "input_dvb: dvb channel file '%s' is not a plain file\n"
msgstr "input_file: tente d'ouvrir le fichier de sous-titre '%s'\n"
-#: src/input/input_dvb.c:2082 src/input/input_dvb.c:2910
+#: src/input/input_dvb.c:2115 src/input/input_dvb.c:2943
#, fuzzy
msgid "input_dvb: tuner_set_channel failed\n"
msgstr "input_cda: fopen(%s) à échoué: %s\n"
-#: src/input/input_dvb.c:2710
+#: src/input/input_dvb.c:2743
#, fuzzy
msgid "input_dvb: cannot open dvb device\n"
msgstr "input_dvd: ne peux pas ouvrir le périphérique dvd >%s<\n"
-#: src/input/input_dvb.c:2734
+#: src/input/input_dvb.c:2767
#, c-format
msgid "input_dvb: channel %d out of range, defaulting to 0\n"
msgstr ""
-#: src/input/input_dvb.c:2745
+#: src/input/input_dvb.c:2778
#, fuzzy, c-format
msgid "input_dvb: searching for channel %s\n"
msgstr "input_file: tente d'ouvrir le fichier de sous-titre '%s'\n"
-#: src/input/input_dvb.c:2768
+#: src/input/input_dvb.c:2801
#, c-format
msgid "input_dvb: exact match for %s not found: trying partial matches\n"
msgstr ""
-#: src/input/input_dvb.c:2775
+#: src/input/input_dvb.c:2808
#, fuzzy, c-format
msgid "input_dvb: found matching channel %s\n"
msgstr "input_file: tente d'ouvrir le fichier de sous-titre '%s'\n"
-#: src/input/input_dvb.c:2788
+#: src/input/input_dvb.c:2821
#, c-format
msgid "input_dvb: channel %s not found in channels.conf, defaulting.\n"
msgstr ""
-#: src/input/input_dvb.c:2794
+#: src/input/input_dvb.c:2827
msgid ""
"input_dvb: invalid channel specification, defaulting to last viewed "
"channel.\n"
msgstr ""
-#: src/input/input_dvb.c:2800
+#: src/input/input_dvb.c:2833
msgid "input_dvb: invalid channel specification, defaulting to channel 0\n"
msgstr ""
-#: src/input/input_dvb.c:2812
+#: src/input/input_dvb.c:2845
msgid ""
"input_dvb: dvbs mrl specified but the tuner doesn't appear to be QPSK (DVB-"
"S)\n"
msgstr ""
-#: src/input/input_dvb.c:2832
+#: src/input/input_dvb.c:2865
msgid ""
"input_dvb: dvbt mrl specified but the tuner doesn't appear to be OFDM (DVB-"
"T)\n"
msgstr ""
-#: src/input/input_dvb.c:2855 src/input/input_dvb.c:2881
+#: src/input/input_dvb.c:2888 src/input/input_dvb.c:2914
msgid ""
"input_dvb: dvbc mrl specified but the tuner doesn't appear to be QAM (DVB-"
"C)\n"
msgstr ""
-#: src/input/input_dvb.c:2916
+#: src/input/input_dvb.c:2949
#, fuzzy, c-format
msgid "input_dvb: cannot open dvr device '%s'\n"
msgstr "input_dvd: ne peux pas ouvrir le périphérique dvd >%s<\n"
-#: src/input/input_dvb.c:2938
+#: src/input/input_dvb.c:2971
#, fuzzy
msgid "input_dvb: cannot create EPG updater thread\n"
msgstr "input_rtp: ne peux pas créer le nouveau thread (%s)\n"
-#: src/input/input_dvb.c:3000
+#: src/input/input_dvb.c:3033
msgid "use DVB 'center cutout' (zoom)"
msgstr ""
-#: src/input/input_dvb.c:3001
+#: src/input/input_dvb.c:3034
msgid ""
"This will allow fullscreen playback of 4:3 content transmitted in a 16:9 "
"frame."
msgstr ""
-#: src/input/input_dvb.c:3094
+#: src/input/input_dvb.c:3127
msgid "DVB (Digital TV) input plugin"
msgstr ""
-#: src/input/input_dvb.c:3242
+#: src/input/input_dvb.c:3244
msgid "Remember last DVB channel watched"
msgstr ""
-#: src/input/input_dvb.c:3243
+#: src/input/input_dvb.c:3245
msgid ""
"On autoplay, xine will remember and switch to the channel indicated in media."
"dvb.last_channel. "
msgstr ""
-#: src/input/input_dvb.c:3250
+#: src/input/input_dvb.c:3252
msgid "Last DVB channel viewed"
msgstr ""
-#: src/input/input_dvb.c:3251
+#: src/input/input_dvb.c:3253
msgid "If enabled xine will remember and switch to this channel. "
msgstr ""
-#: src/input/input_dvb.c:3257
+#: src/input/input_dvb.c:3259
msgid "Number of dvb card to use."
msgstr ""
-#: src/input/input_dvb.c:3258
+#: src/input/input_dvb.c:3260
msgid ""
"Leave this at zero unless you really have more than 1 card in your system."
msgstr ""
@@ -1485,11 +1478,11 @@ msgid ""
"playing DVDs."
msgstr ""
-#: src/input/input_dvd.c:1800
+#: src/input/input_dvd.c:1799
msgid "raw device set up for DVD access"
msgstr ""
-#: src/input/input_dvd.c:1801
+#: src/input/input_dvd.c:1800
msgid ""
"If this points to a raw device connected to your DVD device, xine will use "
"the raw device for playback. This has the advantage of being slightly faster "
@@ -1500,68 +1493,55 @@ msgid ""
"See the documentation on raw device setup (man raw) for further information."
msgstr ""
-#: src/input/input_dvd.c:1814
+#: src/input/input_dvd.c:1813
msgid "CSS decryption method"
msgstr ""
-#: src/input/input_dvd.c:1815
+#: src/input/input_dvd.c:1814
msgid ""
"Selects the decryption method libdvdcss will use to descramble copy "
"protected DVDs. Try the various methods, if you have problems playing "
"scrambled DVDs."
msgstr ""
-#: src/input/input_dvd.c:1823
-msgid "path to the title key cache"
-msgstr ""
-
-#: src/input/input_dvd.c:1824
-msgid ""
-"Since cracking the copy protection of scrambled DVDs can be quite time "
-"consuming, libdvdcss will cache the cracked keys in this directory.\n"
-"This setting is security critical, because files with uncontrollable names "
-"will be created in this directory. Be sure to use a dedicated directory not "
-"used for anything but DVD key caching."
-msgstr ""
-
-#: src/input/input_dvd.c:1846
+#: src/input/input_dvd.c:1829
msgid "region the DVD player claims to be in (1 to 8)"
msgstr ""
-#: src/input/input_dvd.c:1847
+#: src/input/input_dvd.c:1830
msgid ""
"This only needs to be changed if your DVD jumps to a screen complaining "
"about a wrong region code. It has nothing to do with the region code set in "
"DVD drives, this is purely software."
msgstr ""
-#: src/input/input_dvd.c:1853
+#: src/input/input_dvd.c:1836
msgid "default language for DVD playback"
msgstr ""
-#: src/input/input_dvd.c:1854
+#: src/input/input_dvd.c:1837
msgid ""
"xine tries to use this language as a default for DVD playback. As far as the "
"DVD supports it, menus and audio tracks will be presented in this language.\n"
"The value must be a two character ISO639 language code."
msgstr ""
-#: src/input/input_dvd.c:1860
+#: src/input/input_dvd.c:1843
msgid "read-ahead caching"
msgstr ""
-#: src/input/input_dvd.c:1861
+#: src/input/input_dvd.c:1844
msgid ""
"xine can use a read ahead cache for DVD drive access.\n"
"This may lead to jerky playback on slow drives, but it improves the impact "
"of the DVD layer change on faster drives."
msgstr ""
-#: src/input/input_dvd.c:1867
+#: src/input/input_dvd.c:1850
msgid "unit for the skip action"
msgstr ""
-#: src/input/input_dvd.c:1868
+#: src/input/input_dvd.c:1851
msgid ""
"You can configure the behaviour when issuing a skip command (using the skip "
"buttons for example). The individual values mean:\n"
@@ -1580,11 +1560,11 @@ msgid ""
"features on the DVD"
msgstr ""
-#: src/input/input_dvd.c:1883
+#: src/input/input_dvd.c:1866
msgid "unit for seeking"
msgstr ""
-#: src/input/input_dvd.c:1884
+#: src/input/input_dvd.c:1867
msgid ""
"You can configure the domain spanned by the seek slider. The individual "
"values mean:\n"
@@ -1598,11 +1578,11 @@ msgid ""
"chapter of the current feature"
msgstr ""
-#: src/input/input_dvd.c:1895
+#: src/input/input_dvd.c:1878
msgid "play mode when title/chapter is given"
msgstr ""
-#: src/input/input_dvd.c:1896
+#: src/input/input_dvd.c:1879
msgid ""
"You can configure the behaviour when playing a dvd from a given title/"
"chapter (eg. using MRL 'dvd:/1.2'). The individual values mean:\n"
@@ -2294,7 +2274,7 @@ msgid ""
"2048: Debugging from VCDINFO\n"
msgstr ""
-#: src/liba52/xine_a52_decoder.c:742 src/libdts/xine_dts_decoder.c:546
+#: src/liba52/xine_a52_decoder.c:742 src/libxineadec/xine_dts_decoder.c:524
msgid "HELP! a mono-only audio driver?!\n"
msgstr ""
@@ -2345,60 +2325,60 @@ msgstr ""
msgid "libfaad: libfaad NeAACDecInit failed.\n"
msgstr ""
-#: src/libffmpeg/ff_audio_decoder.c:120
+#: src/libffmpeg/ff_audio_decoder.c:122
#, c-format
msgid "ffmpeg_audio_dec: increasing buffer to %d to avoid overflow.\n"
msgstr ""
-#: src/libffmpeg/ff_audio_decoder.c:164
+#: src/libffmpeg/ff_audio_decoder.c:166
#, c-format
msgid "ffmpeg_audio_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"
msgstr ""
-#: src/libffmpeg/ff_audio_decoder.c:256
+#: src/libffmpeg/ff_audio_decoder.c:258
msgid "ffmpeg_audio_dec: trying to open null codec\n"
msgstr ""
-#: src/libffmpeg/ff_audio_decoder.c:265
+#: src/libffmpeg/ff_audio_decoder.c:267
msgid "ffmpeg_audio_dec: couldn't open decoder\n"
msgstr ""
-#: src/libffmpeg/ff_dvaudio_decoder.c:286
+#: src/libffmpeg/ff_dvaudio_decoder.c:280
#, c-format
msgid "dvaudio: increasing buffer to %d to avoid overflow.\n"
msgstr ""
-#: src/libffmpeg/ff_video_decoder.c:157
+#: src/libffmpeg/ff_video_decoder.c:155
msgid "ffmpeg_video_dec: unsupported frame format, DR1 disabled.\n"
msgstr ""
-#: src/libffmpeg/ff_video_decoder.c:175
+#: src/libffmpeg/ff_video_decoder.c:173
msgid "ffmpeg_video_dec: unsupported frame dimensions, DR1 disabled.\n"
msgstr ""
-#: src/libffmpeg/ff_video_decoder.c:335
+#: src/libffmpeg/ff_video_decoder.c:333
#, c-format
msgid "ffmpeg_video_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"
msgstr ""
-#: src/libffmpeg/ff_video_decoder.c:364
+#: src/libffmpeg/ff_video_decoder.c:362
msgid "ffmpeg_video_dec: couldn't open decoder\n"
msgstr ""
-#: src/libffmpeg/ff_video_decoder.c:399
+#: src/libffmpeg/ff_video_decoder.c:397
msgid "ffmpeg_video_dec: direct rendering enabled\n"
msgstr ""
-#: src/libffmpeg/ff_video_decoder.c:818
+#: src/libffmpeg/ff_video_decoder.c:816
#, c-format
msgid "ffmpeg_video_dec: increasing buffer to %d to avoid overflow.\n"
msgstr ""
-#: src/libffmpeg/ff_video_decoder.c:1516
+#: src/libffmpeg/ff_video_decoder.c:1514
msgid "MPEG-4 postprocessing quality"
msgstr ""
-#: src/libffmpeg/ff_video_decoder.c:1517
+#: src/libffmpeg/ff_video_decoder.c:1515
msgid ""
"You can adjust the amount of post processing applied to MPEG-4 video.\n"
"Higher values result in better quality, but need more CPU. Lower values may "
@@ -2407,59 +2387,59 @@ msgid ""
"much."
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:167
+#: src/libffmpeg/ffmpeg_encoder.c:163
msgid "libavcodec mpeg output bitrate (kbit/s)"
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:168
+#: src/libffmpeg/ffmpeg_encoder.c:164
msgid ""
"The bitrate the libavcodec mpeg encoder should use for DXR3's encoding mode. "
"Higher values will increase quality and CPU usage.\n"
"This setting is only considered, when constant quality mode is disabled."
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:175
+#: src/libffmpeg/ffmpeg_encoder.c:171
msgid "constant quality mode"
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:176
+#: src/libffmpeg/ffmpeg_encoder.c:172
msgid ""
"When enabled, libavcodec will use a constant quality mode by dynamically "
"compressing the images based on their complexity. When disabled, libavcodec "
"will use constant bitrate mode."
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:183
+#: src/libffmpeg/ffmpeg_encoder.c:179
msgid "minimum compression"
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:184
+#: src/libffmpeg/ffmpeg_encoder.c:180
msgid "The minimum compression to apply to an image in constant quality mode."
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:189
+#: src/libffmpeg/ffmpeg_encoder.c:185
msgid "maximum quantizer"
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:190
+#: src/libffmpeg/ffmpeg_encoder.c:186
msgid "The maximum compression to apply to an image in constant quality mode."
msgstr ""
-#: src/libmusepack/xine_musepack_decoder.c:241
+#: src/libxineadec/xine_musepack_decoder.c:249
#, c-format
msgid "libmusepack: mpc_streaminfo_read failed: %d\n"
msgstr ""
-#: src/libmusepack/xine_musepack_decoder.c:315
+#: src/libxineadec/xine_musepack_decoder.c:323
msgid "libmusepack: data after last frame ignored\n"
msgstr ""
-#: src/libmusepack/xine_musepack_decoder.c:326
+#: src/libxineadec/xine_musepack_decoder.c:334
msgid "libmusepack: mpc_decoder_initialise failed\n"
msgstr ""
-#: src/libmusepack/xine_musepack_decoder.c:346
-#: src/libmusepack/xine_musepack_decoder.c:361
+#: src/libxineadec/xine_musepack_decoder.c:354
+#: src/libxineadec/xine_musepack_decoder.c:369
#, c-format
msgid "libmusepack: mpc_decoder_decode failed: %d\n"
msgstr ""
@@ -3157,7 +3137,7 @@ msgid "Select the video output layer by its id."
msgstr ""
#: src/video_out/video_out_directfb.c:1804
-#: src/video_out/video_out_directfb.c:2013
+#: src/video_out/video_out_directfb.c:2014
#, c-format
msgid "video_out_directfb: using display layer #%d.\n"
msgstr ""
@@ -3167,11 +3147,11 @@ msgstr ""
msgid "xine video output plugin using DirectFB."
msgstr "plugin de sortie audio de xine utilisant libvidix"
-#: src/video_out/video_out_directfb.c:2006
+#: src/video_out/video_out_directfb.c:2007
msgid "video_out_directfb: no usable display layer was found!\n"
msgstr ""
-#: src/video_out/video_out_directfb.c:2095
+#: src/video_out/video_out_directfb.c:2096
#, fuzzy
msgid "xine video output plugin using DirectFB under XDirectFB."
msgstr "plugin de sortie audio de xine utilisant libvidix"
@@ -3181,19 +3161,19 @@ msgstr "plugin de sortie audio de xine utilisant libvidix"
msgid "xine video output plugin for win32 using directx"
msgstr "plugin de sortie audio de xine utilisant libvidix"
-#: src/video_out/video_out_fb.c:792
+#: src/video_out/video_out_fb.c:780
#, c-format
msgid ""
"video_out_fb: only packed truecolor/directcolor is supported (%d).\n"
" Check 'fbset -i' or try 'fbset -depth 16'.\n"
msgstr ""
-#: src/video_out/video_out_fb.c:852 src/video_out/video_out_vidix.c:1239
+#: src/video_out/video_out_fb.c:840 src/video_out/video_out_vidix.c:1239
#, fuzzy
msgid "framebuffer device name"
msgstr "périphérique framebuffer"
-#: src/video_out/video_out_fb.c:853 src/video_out/video_out_vidix.c:1240
+#: src/video_out/video_out_fb.c:841 src/video_out/video_out_vidix.c:1240
msgid ""
"Specifies the file name for the framebuffer device to be used.\n"
"This setting is security critical, because when changed to a different file, "
@@ -3201,39 +3181,40 @@ msgid ""
"careful that the value you enter really is a proper framebuffer device."
msgstr ""
-#: src/video_out/video_out_fb.c:927
-msgid "video_out_fb: Your video mode was not recognized, sorry.\n"
+#: src/video_out/video_out_fb.c:915
+#, c-format
+msgid "%s: Your video mode was not recognized, sorry.\n"
msgstr ""
-#: src/video_out/video_out_fb.c:984
+#: src/video_out/video_out_fb.c:972
#, c-format
-msgid "video_out_fb: %d video RAM buffers are available.\n"
+msgid "%s: %d video RAM buffers are available.\n"
msgstr ""
-#: src/video_out/video_out_fb.c:990
+#: src/video_out/video_out_fb.c:978
#, c-format
msgid ""
-"WARNING: video_out_fb: Zero copy buffers are DISABLED because only %d "
-"buffers\n"
+"WARNING: %s: Zero copy buffers are DISABLED because only %d buffers\n"
" are available which is less than the recommended %d buffers. Lowering\n"
" the frame buffer resolution might help.\n"
msgstr ""
-#: src/video_out/video_out_fb.c:1001
+#: src/video_out/video_out_fb.c:989
+#, c-format
msgid ""
-"WARNING: video_out_fb: Zero copy buffers are DISABLED because kernel driver\n"
+"WARNING: %s: Zero copy buffers are DISABLED because kernel driver\n"
" do not support screen panning (used for frame flips).\n"
msgstr ""
-#: src/video_out/video_out_fb.c:1070
+#: src/video_out/video_out_fb.c:1058
#, c-format
msgid ""
-"WARNING: video_out_fb: current display depth is %d. For better performance\n"
+"WARNING: %s: current display depth is %d. For better performance\n"
" a depth of 16 bpp is recommended!\n"
"\n"
msgstr ""
-#: src/video_out/video_out_fb.c:1101
+#: src/video_out/video_out_fb.c:1090
#, fuzzy
msgid "Xine video output plugin using the Linux frame buffer device"
msgstr ""
@@ -3288,8 +3269,8 @@ msgid ""
msgstr ""
#: src/video_out/video_out_opengl.c:1918 src/video_out/video_out_vidix.c:1015
-#: src/video_out/video_out_xcbxv.c:1472 src/video_out/video_out_xv.c:1486
-#: src/video_out/video_out_xvmc.c:1461 src/video_out/video_out_xxmc.c:2468
+#: src/video_out/video_out_xcbxv.c:1476 src/video_out/video_out_xv.c:1489
+#: src/video_out/video_out_xvmc.c:1461 src/video_out/video_out_xxmc.c:2465
msgid "enable double buffering"
msgstr ""
@@ -3365,9 +3346,9 @@ msgstr ""
msgid "video_out_pgx64: Error: ioctl failed (FBIOGATTR)\n"
msgstr ""
-#: src/video_out/video_out_pgx64.c:1464 src/video_out/video_out_xcbxv.c:1439
-#: src/video_out/video_out_xv.c:1453 src/video_out/video_out_xvmc.c:1446
-#: src/video_out/video_out_xxmc.c:2435
+#: src/video_out/video_out_pgx64.c:1464 src/video_out/video_out_xcbxv.c:1443
+#: src/video_out/video_out_xv.c:1456 src/video_out/video_out_xvmc.c:1446
+#: src/video_out/video_out_xxmc.c:2432
msgid "video overlay colour key"
msgstr ""
@@ -3519,9 +3500,9 @@ msgstr ""
msgid "The intensity of the blue colour components."
msgstr ""
-#: src/video_out/video_out_vidix.c:1016 src/video_out/video_out_xcbxv.c:1473
-#: src/video_out/video_out_xv.c:1487 src/video_out/video_out_xvmc.c:1462
-#: src/video_out/video_out_xxmc.c:2469
+#: src/video_out/video_out_vidix.c:1016 src/video_out/video_out_xcbxv.c:1477
+#: src/video_out/video_out_xv.c:1490 src/video_out/video_out_xvmc.c:1462
+#: src/video_out/video_out_xxmc.c:2466
msgid ""
"Double buffering will synchronize the update of the video image to the "
"repainting of the entire screen (\"vertical retrace\"). This eliminates "
@@ -3554,9 +3535,9 @@ msgid "video overlay colour key red component"
msgstr ""
#: src/video_out/video_out_vidix.c:1159 src/video_out/video_out_vidix.c:1166
-#: src/video_out/video_out_vidix.c:1173 src/video_out/video_out_xcbxv.c:1440
-#: src/video_out/video_out_xv.c:1454 src/video_out/video_out_xvmc.c:1447
-#: src/video_out/video_out_xxmc.c:2436
+#: src/video_out/video_out_vidix.c:1173 src/video_out/video_out_xcbxv.c:1444
+#: src/video_out/video_out_xv.c:1457 src/video_out/video_out_xvmc.c:1447
+#: src/video_out/video_out_xxmc.c:2433
msgid ""
"The colour key is used to tell the graphics card where to overlay the video "
"image. Try different values, if you experience windows becoming transparent."
@@ -3581,27 +3562,38 @@ msgid "xine video output plugin using libvidix for linux frame buffer"
msgstr ""
"plugin de sortie video de xine utilisant le périphérique framebuffer de linux"
-#: src/video_out/video_out_xcbshm.c:157
+#: src/video_out/video_out_xcbshm.c:157 src/video_out/video_out_xshm.c:219
#, c-format
-msgid ""
-"video_out_xcbshm: %s: allocating image\n"
-"video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+msgid "%s: %s: allocating image\n"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:166
-msgid ""
-"video_out_xcbshm: shared memory error (address error) when allocating "
-"image \n"
-"video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbshm.c:159 src/video_out/video_out_xcbshm.c:169
+#: src/video_out/video_out_xcbshm.c:181 src/video_out/video_out_xcbxv.c:272
+#: src/video_out/video_out_xcbxv.c:282 src/video_out/video_out_xcbxv.c:292
+#: src/video_out/video_out_xcbxv.c:304 src/video_out/video_out_xshm.c:204
+#: src/video_out/video_out_xshm.c:221 src/video_out/video_out_xshm.c:232
+#: src/video_out/video_out_xshm.c:251 src/video_out/video_out_xv.c:296
+#: src/video_out/video_out_xv.c:307 src/video_out/video_out_xv.c:316
+#: src/video_out/video_out_xv.c:352 src/video_out/video_out_xxmc.c:648
+#: src/video_out/video_out_xxmc.c:659 src/video_out/video_out_xxmc.c:668
+#: src/video_out/video_out_xxmc.c:704
+#, c-format
+msgid "%s: => not using MIT Shared Memory extension.\n"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:177
-msgid ""
-"video_out_xcbshm: x11 error during shared memory XImage creation\n"
-"video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbshm.c:167 src/video_out/video_out_xshm.c:230
+#, c-format
+msgid "%s: shared memory error (address error) when allocating image \n"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:1100 src/video_out/video_out_xshm.c:1157
+#: src/video_out/video_out_xcbshm.c:179 src/video_out/video_out_xcbxv.c:302
+#: src/video_out/video_out_xshm.c:249 src/video_out/video_out_xv.c:350
+#: src/video_out/video_out_xxmc.c:702
+#, c-format
+msgid "%s: x11 error during shared memory XImage creation\n"
+msgstr ""
+
+#: src/video_out/video_out_xcbshm.c:1103 src/video_out/video_out_xshm.c:1161
#, c-format
msgid ""
"\n"
@@ -3611,73 +3603,75 @@ msgid ""
"\n"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:1113
-msgid "video_out_xcbshm: MIT shared memory extension not present on display.\n"
+#: src/video_out/video_out_xcbshm.c:1116 src/video_out/video_out_xshm.c:1174
+#, c-format
+msgid "%s: MIT shared memory extension not present on display.\n"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:1212
-msgid "video_out_xcbshm: your video mode was not recognized, sorry :-(\n"
+#: src/video_out/video_out_xcbshm.c:1215 src/video_out/video_out_xshm.c:1258
+#, c-format
+msgid "%s: your video mode was not recognized, sorry :-(\n"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:1242 src/video_out/video_out_xshm.c:1303
+#: src/video_out/video_out_xcbshm.c:1245 src/video_out/video_out_xshm.c:1307
msgid "xine video output plugin using the MIT X shared memory extension"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:272
-msgid ""
-"video_out_xcbxv: XvShmCreateImage returned a zero size\n"
-"video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbxv.c:270 src/video_out/video_out_xv.c:305
+#: src/video_out/video_out_xxmc.c:657
+#, c-format
+msgid "%s: XvShmCreateImage returned a zero size\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:281
+#: src/video_out/video_out_xcbxv.c:280 src/video_out/video_out_xv.c:314
+#: src/video_out/video_out_xxmc.c:666
#, c-format
-msgid ""
-"video_out_xcbxv: shared memory error in shmget: %s\n"
-"video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+msgid "%s: shared memory error in shmget: %s\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:300
-msgid ""
-"video_out_xcbxv: x11 error during shared memory XImage creation\n"
-"video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbxv.c:290
+#, c-format
+msgid "%s: shared memory error (address error)\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1291
-msgid "video_out_xcbxv: Xv extension not present.\n"
+#: src/video_out/video_out_xcbxv.c:1294 src/video_out/video_out_xv.c:1301
+#: src/video_out/video_out_xxmc.c:2283
+#, c-format
+msgid "%s: Xv extension not present.\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1333
+#: src/video_out/video_out_xcbxv.c:1336 src/video_out/video_out_xv.c:1338
+#: src/video_out/video_out_xxmc.c:2320
+#, c-format
msgid ""
-"video_out_xcbxv: Xv extension is present but I couldn't find a usable yuv12 "
-"port.\n"
-" Looks like your graphics hardware driver doesn't support "
-"Xv?!\n"
+"%s: Xv extension is present but I couldn't find a usable yuv12 port.\n"
+"\tLooks like your graphics hardware driver doesn't support Xv?!\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1341
+#: src/video_out/video_out_xcbxv.c:1345
#, c-format
msgid ""
-"video_out_xcbxv: using Xv port %d from adaptor %s for hardware colorspace "
-"conversion and scaling.\n"
+"%s: using Xv port %d from adaptor %s for hardware colorspace conversion and "
+"scaling.\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1448 src/video_out/video_out_xv.c:1462
-#: src/video_out/video_out_xvmc.c:1455 src/video_out/video_out_xxmc.c:2444
+#: src/video_out/video_out_xcbxv.c:1452 src/video_out/video_out_xv.c:1465
+#: src/video_out/video_out_xvmc.c:1455 src/video_out/video_out_xxmc.c:2441
msgid "autopaint colour key"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1449 src/video_out/video_out_xv.c:1463
-#: src/video_out/video_out_xvmc.c:1456 src/video_out/video_out_xxmc.c:2445
+#: src/video_out/video_out_xcbxv.c:1453 src/video_out/video_out_xv.c:1466
+#: src/video_out/video_out_xvmc.c:1456 src/video_out/video_out_xxmc.c:2442
msgid "Make Xv autopaint its colorkey."
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1456 src/video_out/video_out_xv.c:1470
-#: src/video_out/video_out_xxmc.c:2452
+#: src/video_out/video_out_xcbxv.c:1460 src/video_out/video_out_xv.c:1473
+#: src/video_out/video_out_xxmc.c:2449
msgid "bilinear scaling mode"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1457 src/video_out/video_out_xv.c:1471
-#: src/video_out/video_out_xxmc.c:2453
+#: src/video_out/video_out_xcbxv.c:1461 src/video_out/video_out_xv.c:1474
+#: src/video_out/video_out_xxmc.c:2450
msgid ""
"Selects the bilinear scaling mode for Permedia cards. The individual values "
"are:\n"
@@ -3692,30 +3686,34 @@ msgid ""
"2 - enable full bilinear filtering"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1509
-msgid "video_out_xcbxv: this adaptor supports the yv12 format.\n"
+#: src/video_out/video_out_xcbxv.c:1513 src/video_out/video_out_xv.c:1523
+#: src/video_out/video_out_xxmc.c:2506
+#, c-format
+msgid "%s: this adaptor supports the yv12 format.\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1514
-msgid "video_out_xcbxv: this adaptor supports the yuy2 format.\n"
+#: src/video_out/video_out_xcbxv.c:1518 src/video_out/video_out_xv.c:1528
+#: src/video_out/video_out_xxmc.c:2511
+#, c-format
+msgid "%s: this adaptor supports the yuy2 format.\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1522 src/video_out/video_out_xv.c:1547
-#: src/video_out/video_out_xxmc.c:2537
+#: src/video_out/video_out_xcbxv.c:1526 src/video_out/video_out_xv.c:1550
+#: src/video_out/video_out_xxmc.c:2534
msgid "pitch alignment workaround"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1523 src/video_out/video_out_xv.c:1548
-#: src/video_out/video_out_xxmc.c:2538
+#: src/video_out/video_out_xcbxv.c:1527 src/video_out/video_out_xv.c:1551
+#: src/video_out/video_out_xxmc.c:2535
msgid "Some buggy video drivers need a workaround to function properly."
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1529 src/video_out/video_out_xv.c:1554
+#: src/video_out/video_out_xcbxv.c:1533 src/video_out/video_out_xv.c:1557
#: src/video_out/video_out_xvmc.c:1524
msgid "deinterlace method (deprecated)"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1530 src/video_out/video_out_xv.c:1555
+#: src/video_out/video_out_xcbxv.c:1534 src/video_out/video_out_xv.c:1558
#: src/video_out/video_out_xvmc.c:1525
msgid ""
"This config setting is deprecated. You should use the new deinterlacing post "
@@ -3754,93 +3752,26 @@ msgid ""
"with medium CPU usage."
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1584 src/video_out/video_out_xv.c:1628
-#: src/video_out/video_out_xxmc.c:2618
+#: src/video_out/video_out_xcbxv.c:1588 src/video_out/video_out_xv.c:1631
+#: src/video_out/video_out_xxmc.c:2615
msgid "xine video output plugin using the MIT X video extension"
msgstr "plugin de sortie video de xine utilisant l'extension video MIT X"
#: src/video_out/video_out_xshm.c:202
-msgid ""
-"video_out_xshm: shared memory error when allocating image\n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xshm.c:218
#, c-format
-msgid ""
-"video_out_xshm: %s: allocating image\n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xshm.c:228
-msgid ""
-"video_out_xshm: shared memory error (address error) when allocating image \n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xshm.c:245
-msgid ""
-"video_out_xshm: x11 error during shared memory XImage creation\n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xshm.c:1170
-msgid "video_out_xshm: MIT shared memory extension not present on display.\n"
-msgstr ""
-
-#: src/video_out/video_out_xshm.c:1254
-msgid "video_out_xshm: your video mode was not recognized, sorry :-(\n"
+msgid "%s: shared memory error when allocating image\n"
msgstr ""
-#: src/video_out/video_out_xv.c:296
-msgid ""
-"video_out_xv: XvShmCreateImage failed\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:306
-msgid ""
-"video_out_xv: XvShmCreateImage returned a zero size\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:314
+#: src/video_out/video_out_xv.c:294 src/video_out/video_out_xxmc.c:646
#, c-format
-msgid ""
-"video_out_xv: shared memory error in shmget: %s\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:346
-msgid ""
-"video_out_xv: x11 error during shared memory XImage creation\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:1299
-msgid "video_out_xv: Xv extension not present.\n"
+msgid "%s: XvShmCreateImage failed\n"
msgstr ""
-#: src/video_out/video_out_xv.c:1336
-msgid ""
-"video_out_xv: Xv extension is present but I couldn't find a usable yuv12 "
-"port.\n"
-" Looks like your graphics hardware driver doesn't support Xv?!\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:1345
+#: src/video_out/video_out_xv.c:1348 src/video_out/video_out_xxmc.c:2330
#, c-format
msgid ""
-"video_out_xv: using Xv port %ld from adaptor %s for hardware colorspace "
-"conversion and scaling.\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:1520
-msgid "video_out_xv: this adaptor supports the yv12 format.\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:1525
-msgid "video_out_xv: this adaptor supports the yuy2 format.\n"
+"%s: using Xv port %ld from adaptor %s for hardware colorspace conversion and "
+"scaling.\n"
msgstr ""
#: src/video_out/video_out_xvmc.c:1593
@@ -3882,94 +3813,43 @@ msgstr ""
msgid " With Overlay = %d; UnsignedIntra = %d.\n"
msgstr ""
-#: src/video_out/video_out_xxmc.c:650
-msgid ""
-"video_out_xxmc: XvShmCreateImage failed\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:660
-msgid ""
-"video_out_xxmc: XvShmCreateImage returned a zero size\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:668
-#, c-format
-msgid ""
-"video_out_xxmc: shared memory error in shmget: %s\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:700
-msgid ""
-"video_out_xxmc: x11 error during shared memory XImage creation\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:2287
-msgid "video_out_xxmc: Xv extension not present.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:2324
-msgid ""
-"video_out_xxmc: Xv extension is present but I couldn't find a usable yuv12 "
-"port.\n"
-" Looks like your graphics hardware driver doesn't support Xv?!\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:2333
-#, c-format
-msgid ""
-"video_out_xxmc: using Xv port %ld from adaptor %s for hardware colorspace "
-"conversion and scaling.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:2509
-msgid "video_out_xxmc: this adaptor supports the yv12 format.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:2514
-msgid "video_out_xxmc: this adaptor supports the yuy2 format.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:2543
+#: src/video_out/video_out_xxmc.c:2540
msgid "Make XvMC allocate more frames for better buffering."
msgstr ""
-#: src/video_out/video_out_xxmc.c:2544
+#: src/video_out/video_out_xxmc.c:2541
msgid ""
"Some XvMC implementations allow more than 8 frames.\n"
"This option, when turned on, makes the driver try to\n"
"allocate 15 frames. A must for unichrome and live VDR.\n"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2550
+#: src/video_out/video_out_xxmc.c:2547
msgid "Unichrome cpu save"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2551
+#: src/video_out/video_out_xxmc.c:2548
msgid ""
"Saves CPU time by sleeping while decoder works.\n"
"Only for Linux kernel 2.6 series or 2.4 with multimedia patch.\n"
"Experimental.\n"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2557
+#: src/video_out/video_out_xxmc.c:2554
msgid "Fix buggy NVIDIA XvMC subpicture colors"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2558
+#: src/video_out/video_out_xxmc.c:2555
msgid ""
"There's a bug in NVIDIA's XvMC lib that makes red OSD colors\n"
"look blue and vice versa. This option provides a workaround.\n"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2563
+#: src/video_out/video_out_xxmc.c:2560
msgid "Use bob as accelerated deinterlace method."
msgstr ""
-#: src/video_out/video_out_xxmc.c:2564
+#: src/video_out/video_out_xxmc.c:2561
msgid ""
"When interlacing is enabled for hardware accelerated frames,\n"
"Alternate between top and bottom field at double the frame rate.\n"
@@ -4190,12 +4070,12 @@ msgid ""
"info_helper: unsupported conversion %s -> UTF-8, no conversion performed\n"
msgstr ""
-#: src/xine-engine/input_cache.c:167
+#: src/xine-engine/input_cache.c:171
#, c-format
msgid ": open() function should never be called\n"
msgstr ""
-#: src/xine-engine/input_cache.c:349
+#: src/xine-engine/input_cache.c:353
#, fuzzy, c-format
msgid ": input plugin not defined!\n"
msgstr "input_dvd: ne peux pas ouvrir le fichier >%s<\n"
@@ -4304,162 +4184,163 @@ msgstr ""
msgid "io_helper: Connection Refused\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:212
+#: src/xine-engine/load_plugins.c:215
#, c-format
msgid "map_decoder_list: no space for decoder, skipped.\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:327
+#: src/xine-engine/load_plugins.c:330
#, c-format
msgid ""
"load_plugins: ignoring plugin %s, wrong iface version %d (should be %d)\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:384
+#: src/xine-engine/load_plugins.c:387
#, c-format
msgid "priority for %s decoder"
msgstr ""
-#: src/xine-engine/load_plugins.c:395
+#: src/xine-engine/load_plugins.c:398
msgid ""
"The priority provides a ranking in case some media can be handled by more "
"than one decoder.\n"
"A priority of 0 enables the decoder's default priority."
msgstr ""
-#: src/xine-engine/load_plugins.c:423
+#: src/xine-engine/load_plugins.c:426
#, c-format
msgid ""
"load_plugins: demuxer plugin %s does not provide a priority, xine-lib will "
"use the default priority.\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:440
+#: src/xine-engine/load_plugins.c:443
#, c-format
msgid ""
"load_plugins: input plugin %s does not provide a priority, xine-lib will use "
"the default priority.\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:496
+#: src/xine-engine/load_plugins.c:499
#, c-format
msgid "load_plugins: plugin %s found\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:499
+#: src/xine-engine/load_plugins.c:502
#, fuzzy, c-format
msgid "load_plugins: static plugin found\n"
msgstr "input_net: impossible de se connecter à '%s'.\n"
-#: src/xine-engine/load_plugins.c:506
+#: src/xine-engine/load_plugins.c:509
#, c-format
msgid "load_plugins: plugin limit reached, %s could not be loaded\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:509
+#: src/xine-engine/load_plugins.c:512
#, c-format
msgid "load_plugins: plugin limit reached, static plugin could not be loaded\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:526
+#: src/xine-engine/load_plugins.c:529
#, c-format
msgid "load_plugins: unknown plugin type %d in %s\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:530
+#: src/xine-engine/load_plugins.c:533
#, fuzzy, c-format
msgid "load_plugins: unknown statically linked plugin type %d\n"
msgstr "input_net: impossible de se connecter à '%s'.\n"
-#: src/xine-engine/load_plugins.c:590
+#: src/xine-engine/load_plugins.c:593
#, fuzzy, c-format
msgid "load_plugins: unable to stat %s\n"
msgstr "input_net: impossible de se connecter à '%s'.\n"
-#: src/xine-engine/load_plugins.c:631
+#: src/xine-engine/load_plugins.c:634
#, fuzzy, c-format
msgid ""
"load_plugins: cannot open plugin lib %s:\n"
"%s\n"
msgstr "input_net: impossible de se connecter à '%s'.\n"
-#: src/xine-engine/load_plugins.c:646
+#: src/xine-engine/load_plugins.c:649
#, c-format
msgid ""
"load_plugins: can't get plugin info from %s:\n"
"%s\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:664
+#: src/xine-engine/load_plugins.c:667
#, fuzzy, c-format
msgid "load_plugins: skipping unreadable plugin directory %s.\n"
msgstr "input_net: impossible de se connecter à '%s'.\n"
-#: src/xine-engine/load_plugins.c:713
+#: src/xine-engine/load_plugins.c:716
#, c-format
msgid ""
"load_plugins: cannot (stage 2) open plugin lib %s:\n"
"%s\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:739
+#: src/xine-engine/load_plugins.c:742
#, c-format
msgid "load_plugins: Yikes! %s doesn't contain plugin info.\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:1305
+#: src/xine-engine/load_plugins.c:1104 src/xine-engine/load_plugins.c:1113
+#, fuzzy, c-format
+msgid "Unable to create %s directory: %s\n"
+msgstr "incapable d'allouer le buffer d'entrée.\n"
+
+#: src/xine-engine/load_plugins.c:1345
#, fuzzy, c-format
msgid "load_plugins: unknown content detection strategy %d\n"
msgstr "input_net: impossible de se connecter à '%s'.\n"
-#: src/xine-engine/load_plugins.c:1415
+#: src/xine-engine/load_plugins.c:1455
#, fuzzy, c-format
msgid "load_plugins: using demuxer '%s'\n"
msgstr "input_net: impossible de se connecter à '%s'.\n"
-#: src/xine-engine/load_plugins.c:1726
+#: src/xine-engine/load_plugins.c:1766
#, fuzzy, c-format
msgid "load_plugins: failed to load audio output plugin <%s>\n"
msgstr "input_net: impossible de se connecter à '%s'.\n"
-#: src/xine-engine/load_plugins.c:1729
+#: src/xine-engine/load_plugins.c:1769
msgid ""
"load_plugins: audio output auto-probing didn't find any usable audio "
"driver.\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:2033
+#: src/xine-engine/load_plugins.c:2073
#, fuzzy, c-format
msgid ""
"load_plugins: cannot unload plugin lib %s:\n"
"%s\n"
msgstr "input_net: impossible de se connecter à '%s'.\n"
-#: src/xine-engine/osd.c:745
+#: src/xine-engine/osd.c:747
#, c-format
msgid "font '%s-%d' already loaded, weird.\n"
msgstr ""
-#: src/xine-engine/osd.c:757
+#: src/xine-engine/osd.c:759
#, c-format
msgid "font '%s' loading failed (%d < %d)\n"
msgstr ""
-#: src/xine-engine/osd.c:767
+#: src/xine-engine/osd.c:769
#, c-format
msgid "wrong version for font '%s'. expected %d found %d.\n"
msgstr ""
-#: src/xine-engine/osd.c:834
-msgid "osd: cannot initialize ft2 library\n"
-msgstr ""
-
-#: src/xine-engine/osd.c:857
+#: src/xine-engine/osd.c:856
#, c-format
msgid "osd: error matching font %s with FontConfig"
msgstr ""
-#: src/xine-engine/osd.c:871
+#: src/xine-engine/osd.c:870
#, c-format
msgid "osd: error loading font %s with FontConfig"
msgstr ""
@@ -4469,57 +4350,61 @@ msgstr ""
msgid "osd: error looking up font %s with FontConfig"
msgstr ""
-#: src/xine-engine/osd.c:895
+#: src/xine-engine/osd.c:914
#, c-format
-msgid "osd: error loading font %s with ft2\n"
+msgid "osd: error loading font %s with in XDG data directories.\n"
+msgstr ""
+
+#: src/xine-engine/osd.c:923
+msgid "osd: cannot initialize ft2 library\n"
msgstr ""
-#: src/xine-engine/osd.c:905
+#: src/xine-engine/osd.c:945
msgid "osd: error setting font size (no scalable font?)\n"
msgstr ""
-#: src/xine-engine/osd.c:1021
+#: src/xine-engine/osd.c:1061
#, c-format
msgid ""
"osd: unknown sequence starting with byte 0x%02X in encoding \"%s\", "
"skipping\n"
msgstr ""
-#: src/xine-engine/osd.c:1077
+#: src/xine-engine/osd.c:1117
msgid "osd: can't find out current locale character set\n"
msgstr ""
-#: src/xine-engine/osd.c:1087
+#: src/xine-engine/osd.c:1127
#, c-format
msgid "osd: unsupported conversion %s -> %s, no conversion performed\n"
msgstr ""
-#: src/xine-engine/osd.c:1142 src/xine-engine/osd.c:1310
+#: src/xine-engine/osd.c:1182 src/xine-engine/osd.c:1350
msgid "osd: font isn't defined\n"
msgstr ""
-#: src/xine-engine/osd.c:1181
+#: src/xine-engine/osd.c:1221
msgid "osd: error loading glyph\n"
msgstr ""
-#: src/xine-engine/osd.c:1187
+#: src/xine-engine/osd.c:1227
msgid "osd: error in rendering glyph\n"
msgstr ""
-#: src/xine-engine/osd.c:1347
+#: src/xine-engine/osd.c:1387
#, c-format
msgid "osd: error loading glyph %i\n"
msgstr ""
-#: src/xine-engine/osd.c:1354
+#: src/xine-engine/osd.c:1394
msgid "osd: error in rendering\n"
msgstr ""
-#: src/xine-engine/osd.c:1611
+#: src/xine-engine/osd.c:1660
msgid "palette (foreground-border-background) to use for subtitles and OSD"
msgstr ""
-#: src/xine-engine/osd.c:1612
+#: src/xine-engine/osd.c:1661
msgid ""
"The palette for on-screen-display and some subtitle formats that do not "
"specify any colouring themselves. The palettes are listed in the form: "
@@ -4632,129 +4517,129 @@ msgid ""
"accelerated, this can dramatically reduce CPU usage."
msgstr ""
-#: src/xine-engine/xine.c:704 src/xine-engine/xine.c:811
-#: src/xine-engine/xine.c:850 src/xine-engine/xine.c:886
-#: src/xine-engine/xine.c:898 src/xine-engine/xine.c:911
-#: src/xine-engine/xine.c:924 src/xine-engine/xine.c:937
-#: src/xine-engine/xine.c:963 src/xine-engine/xine.c:988
-#: src/xine-engine/xine.c:1023
+#: src/xine-engine/xine.c:706 src/xine-engine/xine.c:813
+#: src/xine-engine/xine.c:852 src/xine-engine/xine.c:888
+#: src/xine-engine/xine.c:900 src/xine-engine/xine.c:913
+#: src/xine-engine/xine.c:926 src/xine-engine/xine.c:939
+#: src/xine-engine/xine.c:965 src/xine-engine/xine.c:990
+#: src/xine-engine/xine.c:1025
msgid "xine: error while parsing mrl\n"
msgstr ""
-#: src/xine-engine/xine.c:740
+#: src/xine-engine/xine.c:742
#, fuzzy, c-format
msgid "xine: found input plugin : %s\n"
msgstr "plugin de sortie video de xine pour cartes dxr3"
-#: src/xine-engine/xine.c:758
+#: src/xine-engine/xine.c:760
#, fuzzy, c-format
msgid "xine: input plugin cannot open MRL [%s]\n"
msgstr "input_dvd: ne peux pas ouvrir le fichier >%s<\n"
-#: src/xine-engine/xine.c:774
+#: src/xine-engine/xine.c:776
#, fuzzy, c-format
msgid "xine: cannot find input plugin for MRL [%s]\n"
msgstr "plugin de sortie video de xine pour cartes dxr3"
-#: src/xine-engine/xine.c:800
+#: src/xine-engine/xine.c:802
#, c-format
msgid "xine: specified demuxer %s failed to start\n"
msgstr ""
-#: src/xine-engine/xine.c:836
+#: src/xine-engine/xine.c:838
#, c-format
msgid "xine: join rip input plugin\n"
msgstr ""
-#: src/xine-engine/xine.c:843
+#: src/xine-engine/xine.c:845
#, fuzzy
msgid "xine: error opening rip input plugin instance\n"
msgstr "input_dvd: erreur de lecture dans le plugin input_dvd\n"
-#: src/xine-engine/xine.c:874
+#: src/xine-engine/xine.c:876
#, c-format
msgid "xine: last_probed demuxer %s failed to start\n"
msgstr ""
-#: src/xine-engine/xine.c:903
+#: src/xine-engine/xine.c:905
msgid "ignoring video\n"
msgstr ""
-#: src/xine-engine/xine.c:916
+#: src/xine-engine/xine.c:918
msgid "ignoring audio\n"
msgstr ""
-#: src/xine-engine/xine.c:929
+#: src/xine-engine/xine.c:931
msgid "ignoring subpicture\n"
msgstr ""
-#: src/xine-engine/xine.c:942
+#: src/xine-engine/xine.c:944
msgid "input cache plugin disabled\n"
msgstr ""
-#: src/xine-engine/xine.c:1013
+#: src/xine-engine/xine.c:1015
#, c-format
msgid "subtitle mrl opened '%s'\n"
msgstr ""
-#: src/xine-engine/xine.c:1017
+#: src/xine-engine/xine.c:1019
#, fuzzy
msgid "xine: error opening subtitle mrl\n"
msgstr "input_dvd: ne peux pas ouvrir le fichier >%s<\n"
-#: src/xine-engine/xine.c:1049
+#: src/xine-engine/xine.c:1051
#, c-format
msgid "xine: error while parsing MRL\n"
msgstr ""
-#: src/xine-engine/xine.c:1056
+#: src/xine-engine/xine.c:1058
#, c-format
msgid "xine: changing option '%s' from MRL isn't permitted\n"
msgstr ""
-#: src/xine-engine/xine.c:1076
+#: src/xine-engine/xine.c:1078
#, c-format
msgid "xine: couldn't find demux for >%s<\n"
msgstr ""
-#: src/xine-engine/xine.c:1092
+#: src/xine-engine/xine.c:1094
#, c-format
msgid "xine: found demuxer plugin: %s\n"
msgstr ""
-#: src/xine-engine/xine.c:1112
+#: src/xine-engine/xine.c:1114
#, c-format
msgid "xine: demuxer failed to start\n"
msgstr ""
-#: src/xine-engine/xine.c:1177
+#: src/xine-engine/xine.c:1179
#, c-format
msgid "xine_play: no demux available\n"
msgstr ""
-#: src/xine-engine/xine.c:1247
+#: src/xine-engine/xine.c:1249
#, c-format
msgid "xine_play: demux failed to start\n"
msgstr ""
-#: src/xine-engine/xine.c:1523
+#: src/xine-engine/xine.c:1527
#, c-format
msgid "xine: The specified save_dir \"%s\" might be a security risk.\n"
msgstr ""
-#: src/xine-engine/xine.c:1528
+#: src/xine-engine/xine.c:1532
msgid "The specified save_dir might be a security risk."
msgstr ""
-#: src/xine-engine/xine.c:1554
+#: src/xine-engine/xine.c:1561
msgid "xine: locale not supported by C library\n"
msgstr ""
-#: src/xine-engine/xine.c:1563
+#: src/xine-engine/xine.c:1570
msgid "media format detection strategy"
msgstr ""
-#: src/xine-engine/xine.c:1564
+#: src/xine-engine/xine.c:1571
msgid ""
"xine offers various methods to detect the media format of input to play. The "
"individual values are:\n"
@@ -4772,11 +4657,11 @@ msgid ""
"Detect by file name extension only.\n"
msgstr ""
-#: src/xine-engine/xine.c:1582
+#: src/xine-engine/xine.c:1589
msgid "directory for saving streams"
msgstr ""
-#: src/xine-engine/xine.c:1583
+#: src/xine-engine/xine.c:1590
msgid ""
"When using the stream save feature, files will be written only into this "
"directory.\n"
@@ -4786,11 +4671,11 @@ msgid ""
"content in any file."
msgstr ""
-#: src/xine-engine/xine.c:1594
+#: src/xine-engine/xine.c:1601
msgid "allow implicit changes to the configuration (e.g. by MRL)"
msgstr ""
-#: src/xine-engine/xine.c:1595
+#: src/xine-engine/xine.c:1602
msgid ""
"If enabled, you allow xine to change your configuration without explicit "
"actions from your side. For example configuration changes demanded by MRLs "
@@ -4800,26 +4685,26 @@ msgid ""
"configuration, you might end with a totally messed up xine."
msgstr ""
-#: src/xine-engine/xine.c:1609
+#: src/xine-engine/xine.c:1616
msgid "Timeout for network stream reading (in seconds)"
msgstr ""
-#: src/xine-engine/xine.c:1610
+#: src/xine-engine/xine.c:1617
msgid ""
"Specifies the timeout when reading from network streams, in seconds. Too low "
"values might stop streaming when the source is slow or the bandwidth is "
"occupied, too high values will freeze the player if the connection is lost."
msgstr ""
-#: src/xine-engine/xine.c:1962
+#: src/xine-engine/xine.c:1969
msgid "messages"
msgstr "messages"
-#: src/xine-engine/xine.c:1963
+#: src/xine-engine/xine.c:1970
msgid "plugin"
msgstr ""
-#: src/xine-engine/xine.c:1964
+#: src/xine-engine/xine.c:1971
msgid "trace"
msgstr ""
diff --git a/po/it.po b/po/it.po
index 51dfcbb6f..096261ca0 100644
--- a/po/it.po
+++ b/po/it.po
@@ -9,7 +9,7 @@ msgid ""
msgstr ""
"Project-Id-Version: it\n"
"Report-Msgid-Bugs-To: xine-devel@lists.sourceforge.net\n"
-"POT-Creation-Date: 2007-04-06 15:39+0200\n"
+"POT-Creation-Date: 2007-04-24 21:48+0100\n"
"PO-Revision-Date: 2006-06-18 23:05+0200\n"
"Last-Translator: Diego 'Flameeyes' Pettenò <flameeyes@gentoo.org>\n"
"Language-Team: Italian\n"
@@ -43,22 +43,22 @@ msgstr "Errore nella ricerca dell'host"
msgid "Unknown error"
msgstr "Errore sconosciuto"
-#: src/audio_out/audio_alsa_out.c:354
+#: src/audio_out/audio_alsa_out.c:351
#, c-format
msgid "audio_alsa_out:Already open...WHY!"
msgstr "audio_alsa_out: già aperto...PERCHÈ!"
-#: src/audio_out/audio_alsa_out.c:382
+#: src/audio_out/audio_alsa_out.c:379
#, c-format
msgid "audio_alsa_out: snd_pcm_open() of %s failed: %s\n"
msgstr "audio_alsa_out: snd_pcm_open() di %s non riuscito: %s\n"
-#: src/audio_out/audio_alsa_out.c:384
+#: src/audio_out/audio_alsa_out.c:381
msgid "audio_alsa_out: >>> check if another program already uses PCM <<<\n"
msgstr ""
"audio_alsa_out: >>> controlla se un altro programma sta già usando PCM <<<\n"
-#: src/audio_out/audio_alsa_out.c:397
+#: src/audio_out/audio_alsa_out.c:394
#, c-format
msgid ""
"audio_alsa_out: broken configuration for this PCM: no configurations "
@@ -67,11 +67,11 @@ msgstr ""
"audio_alsa_out: configurazione errata per questo PCM: nessuna configurazione "
"disponibile: %s\n"
-#: src/audio_out/audio_alsa_out.c:1289
+#: src/audio_out/audio_alsa_out.c:1286
msgid "notify changes to the hardware mixer"
msgstr "notifica modifiche al mixer hardware"
-#: src/audio_out/audio_alsa_out.c:1290
+#: src/audio_out/audio_alsa_out.c:1287
msgid ""
"When the hardware mixer changes, your application will receive a "
"notification so that it can update its graphical representation of the mixer "
@@ -81,16 +81,16 @@ msgstr ""
"una notifica così che possa aggiornare la propria rappresentazione delle "
"impostazioni del mixer al volo."
-#: src/audio_out/audio_alsa_out.c:1355
+#: src/audio_out/audio_alsa_out.c:1352
#, c-format
msgid "snd_lib_error_set_handler() failed: %d"
msgstr "snd_lib_error_set_handler() non riuscita: %d"
-#: src/audio_out/audio_alsa_out.c:1362
+#: src/audio_out/audio_alsa_out.c:1359
msgid "sound card can do mmap"
msgstr "la scheda audio può usare mmap"
-#: src/audio_out/audio_alsa_out.c:1363
+#: src/audio_out/audio_alsa_out.c:1360
msgid ""
"Enable this, if your sound card and alsa driver support memory mapped IO.\n"
"You can try enabling it and check, if everything works. If it does, this "
@@ -101,11 +101,11 @@ msgstr ""
"Si può provare ad abilitarlo e vedere se funziona, in qual caso migliorerà "
"le prestazioni."
-#: src/audio_out/audio_alsa_out.c:1372
+#: src/audio_out/audio_alsa_out.c:1369
msgid "device used for mono output"
msgstr "dispositivo usato per output mono"
-#: src/audio_out/audio_alsa_out.c:1373
+#: src/audio_out/audio_alsa_out.c:1370
msgid ""
"xine will use this alsa device to output mono sound.\n"
"See the alsa documentation for information on alsa devices."
@@ -113,11 +113,11 @@ msgstr ""
"xine utilizzerà questo dispositivo ALSA per riprodurre suono mono.\n"
"Si veda la documentazione ALSA per informazioni sui dispositivi."
-#: src/audio_out/audio_alsa_out.c:1381
+#: src/audio_out/audio_alsa_out.c:1378
msgid "device used for stereo output"
msgstr "dispositivo usato per output stereo"
-#: src/audio_out/audio_alsa_out.c:1382
+#: src/audio_out/audio_alsa_out.c:1379
msgid ""
"xine will use this alsa device to output stereo sound.\n"
"See the alsa documentation for information on alsa devices."
@@ -125,11 +125,11 @@ msgstr ""
"xine utilizzerà questo dispositivo ALSA per riprodurre suono stereo.\n"
"Si veda la documentazione ALSA per informazioni sui dispositivi."
-#: src/audio_out/audio_alsa_out.c:1390
+#: src/audio_out/audio_alsa_out.c:1387
msgid "device used for 4-channel output"
msgstr "dispositivo usato per output a 4 canali"
-#: src/audio_out/audio_alsa_out.c:1391
+#: src/audio_out/audio_alsa_out.c:1388
msgid ""
"xine will use this alsa device to output 4 channel (4.0) surround sound.\n"
"See the alsa documentation for information on alsa devices."
@@ -138,11 +138,11 @@ msgstr ""
"canali (4.0.\n"
"Si veda la documentazione ALSA per informazioni sui dispositivi."
-#: src/audio_out/audio_alsa_out.c:1400 src/audio_out/audio_alsa_out.c:1410
+#: src/audio_out/audio_alsa_out.c:1397 src/audio_out/audio_alsa_out.c:1407
msgid "device used for 5.1-channel output"
msgstr "dispositivo usato per output a canale 5.1"
-#: src/audio_out/audio_alsa_out.c:1401
+#: src/audio_out/audio_alsa_out.c:1398
msgid ""
"xine will use this alsa device to output 5 channel plus LFE (5.1) surround "
"sound.\n"
@@ -152,7 +152,7 @@ msgstr ""
"canali più RFE (5.1).\n"
"Si veda la documentazione ALSA per informazioni sui dispositivi."
-#: src/audio_out/audio_alsa_out.c:1411
+#: src/audio_out/audio_alsa_out.c:1408
msgid ""
"xine will use this alsa device to output undecoded digital surround sound. "
"This can be used be external surround decoders.\n"
@@ -163,21 +163,21 @@ msgstr ""
"surround esterni.\n"
"Si veda la documentazione ALSA per informazioni sui dispositivi."
-#: src/audio_out/audio_alsa_out.c:1431
+#: src/audio_out/audio_alsa_out.c:1428
#, c-format
msgid "snd_pcm_open() failed:%d:%s\n"
msgstr "snd_pcm_open() non riuscito:%d:%s\n"
-#: src/audio_out/audio_alsa_out.c:1433
+#: src/audio_out/audio_alsa_out.c:1430
#, c-format
msgid ">>> Check if another program already uses PCM <<<\n"
msgstr ">>>Controlla se un altro programma sta già usando PCM <<<\n"
-#: src/audio_out/audio_alsa_out.c:1464 src/audio_out/audio_oss_out.c:929
+#: src/audio_out/audio_alsa_out.c:1461 src/audio_out/audio_oss_out.c:929
msgid "speaker arrangement"
msgstr "disposizione degli speaker"
-#: src/audio_out/audio_alsa_out.c:1465 src/audio_out/audio_oss_out.c:930
+#: src/audio_out/audio_alsa_out.c:1462 src/audio_out/audio_oss_out.c:930
msgid ""
"Select how your speakers are arranged, this determines which speakers xine "
"uses for sound output. The individual values are:\n"
@@ -237,80 +237,80 @@ msgstr ""
"scheda audio un decodificatore surround digitale capace di decodificare i "
"formati che si vogliono riprodurre."
-#: src/audio_out/audio_alsa_out.c:1494
+#: src/audio_out/audio_alsa_out.c:1491
msgid "audio_alsa_out : supported modes are "
msgstr "audio_alsa_out : i modi supportati sono "
-#: src/audio_out/audio_alsa_out.c:1497
+#: src/audio_out/audio_alsa_out.c:1494
msgid "8bit "
msgstr "8-bit "
-#: src/audio_out/audio_alsa_out.c:1502
+#: src/audio_out/audio_alsa_out.c:1499
msgid "16bit "
msgstr "16-bit "
-#: src/audio_out/audio_alsa_out.c:1506
+#: src/audio_out/audio_alsa_out.c:1503
msgid "24bit "
msgstr "24-bit"
-#: src/audio_out/audio_alsa_out.c:1510
+#: src/audio_out/audio_alsa_out.c:1507
msgid "32bit "
msgstr "32-bit"
-#: src/audio_out/audio_alsa_out.c:1521
+#: src/audio_out/audio_alsa_out.c:1518
msgid "mono "
msgstr "mono "
-#: src/audio_out/audio_alsa_out.c:1525
+#: src/audio_out/audio_alsa_out.c:1522
msgid "stereo "
msgstr "stereo "
-#: src/audio_out/audio_alsa_out.c:1530
+#: src/audio_out/audio_alsa_out.c:1527
msgid "4-channel "
msgstr "4-canali "
-#: src/audio_out/audio_alsa_out.c:1533
+#: src/audio_out/audio_alsa_out.c:1530
msgid "(4-channel not enabled in xine config) "
msgstr "(4-canali non abilitato nella configurazione di xine) "
-#: src/audio_out/audio_alsa_out.c:1538
+#: src/audio_out/audio_alsa_out.c:1535
msgid "4.1-channel "
msgstr "4.1-canali "
-#: src/audio_out/audio_alsa_out.c:1541
+#: src/audio_out/audio_alsa_out.c:1538
msgid "(4.1-channel not enabled in xine config) "
msgstr "(4.1-canali non abilitati nella configurazione di xine) "
-#: src/audio_out/audio_alsa_out.c:1546
+#: src/audio_out/audio_alsa_out.c:1543
msgid "5-channel "
msgstr "5-canali "
-#: src/audio_out/audio_alsa_out.c:1549
+#: src/audio_out/audio_alsa_out.c:1546
msgid "(5-channel not enabled in xine config) "
msgstr "(5-canali non abilitati nella configurazione di xine) "
-#: src/audio_out/audio_alsa_out.c:1554
+#: src/audio_out/audio_alsa_out.c:1551
msgid "5.1-channel "
msgstr "5.1-canali "
-#: src/audio_out/audio_alsa_out.c:1557
+#: src/audio_out/audio_alsa_out.c:1554
msgid "(5.1-channel not enabled in xine config) "
msgstr "(5.1-canali non abilitati nella configurazione di xine) "
-#: src/audio_out/audio_alsa_out.c:1580
+#: src/audio_out/audio_alsa_out.c:1577
msgid "a/52 and DTS pass-through\n"
msgstr "passaggio diretto a/52 e DTS\n"
-#: src/audio_out/audio_alsa_out.c:1583
+#: src/audio_out/audio_alsa_out.c:1580
msgid "(a/52 and DTS pass-through not enabled in xine config)\n"
msgstr ""
"(passaggio diretto a/53 e DTS non abilitato nella configurazione di xine)\n"
-#: src/audio_out/audio_alsa_out.c:1590
+#: src/audio_out/audio_alsa_out.c:1587
msgid "alsa mixer device"
msgstr "dispositivo mixer di alsa"
-#: src/audio_out/audio_alsa_out.c:1591
+#: src/audio_out/audio_alsa_out.c:1588
msgid ""
"xine will use this alsa mixer device to change the volume.\n"
"See the alsa documentation for information on alsa devices."
@@ -319,7 +319,7 @@ msgstr ""
"volume.\n"
"Si veda la documentazione ALSA per informazioni sui dispositivi."
-#: src/audio_out/audio_alsa_out.c:1665
+#: src/audio_out/audio_alsa_out.c:1662
msgid "xine audio output plugin using alsa-compliant audio devices/drivers"
msgstr ""
"plugin output audio di xine che usa i dispositivi/driver audio compiacenti "
@@ -333,202 +333,202 @@ msgstr "plugin output audio di xine che usa artsd di KDE"
msgid "xine output plugin for Coreaudio/Mac OS X"
msgstr "plugin di uscita audio per xine per Coreaudio/Max OS X"
-#: src/audio_out/audio_directx2_out.c:166
+#: src/audio_out/audio_directx2_out.c:163
msgid "Error"
msgstr "Errore"
-#: src/audio_out/audio_directx2_out.c:173
+#: src/audio_out/audio_directx2_out.c:170
msgid "success"
msgstr "successo"
-#: src/audio_out/audio_directx2_out.c:175
+#: src/audio_out/audio_directx2_out.c:172
msgid "access denied"
msgstr "accesso negato"
-#: src/audio_out/audio_directx2_out.c:177
+#: src/audio_out/audio_directx2_out.c:174
msgid "resource is already in use"
msgstr "risorsa già in uso"
-#: src/audio_out/audio_directx2_out.c:178
+#: src/audio_out/audio_directx2_out.c:175
msgid "object was already initialized"
msgstr "oggetto già inizializzato"
-#: src/audio_out/audio_directx2_out.c:179
+#: src/audio_out/audio_directx2_out.c:176
msgid "specified wave format is not supported"
msgstr "il formato d'onda specificato non è supportato"
-#: src/audio_out/audio_directx2_out.c:180
+#: src/audio_out/audio_directx2_out.c:177
msgid "memory buffer has been lost and must be restored"
msgstr "il buffer in memoria è stato perso e deve essere ripristinato"
-#: src/audio_out/audio_directx2_out.c:181
+#: src/audio_out/audio_directx2_out.c:178
msgid "requested buffer control is not available"
msgstr "il controllo del buffer richiesto non è disponibile"
-#: src/audio_out/audio_directx2_out.c:182
+#: src/audio_out/audio_directx2_out.c:179
msgid "undetermined error inside DirectSound subsystem"
msgstr "errore non determinato nel sistema DirectSound"
-#: src/audio_out/audio_directx2_out.c:184
+#: src/audio_out/audio_directx2_out.c:181
msgid "DirectSound hardware device is unavailable"
msgstr "il dispositivo hardware DirectSound non è disponibile"
-#: src/audio_out/audio_directx2_out.c:186
+#: src/audio_out/audio_directx2_out.c:183
msgid "function is not valid for the current state of the object"
msgstr "la funzione non è valida per l'attuale stato dell'oggetto"
-#: src/audio_out/audio_directx2_out.c:187
+#: src/audio_out/audio_directx2_out.c:184
msgid "invalid parameter was passed"
msgstr "parametro passato non valido"
-#: src/audio_out/audio_directx2_out.c:188
+#: src/audio_out/audio_directx2_out.c:185
msgid "object doesn't support aggregation"
msgstr "l'oggetto non supporta aggregazione"
-#: src/audio_out/audio_directx2_out.c:189
+#: src/audio_out/audio_directx2_out.c:186
msgid "no sound driver available for use"
msgstr "nessun driver sonoro disponibile all'uso"
-#: src/audio_out/audio_directx2_out.c:190
+#: src/audio_out/audio_directx2_out.c:187
msgid "requested COM interface not available"
msgstr "l'interfaccia COM richiesta non è disponibile"
-#: src/audio_out/audio_directx2_out.c:191
+#: src/audio_out/audio_directx2_out.c:188
msgid "another application has a higher priority level"
msgstr "un'altra applicazione ha un livello di priorità maggiore"
-#: src/audio_out/audio_directx2_out.c:192
+#: src/audio_out/audio_directx2_out.c:189
msgid "insufficient memory"
msgstr "memoria insufficiente"
-#: src/audio_out/audio_directx2_out.c:193
+#: src/audio_out/audio_directx2_out.c:190
msgid "low priority level for this function"
msgstr "basso livello di priorità per questa funzione"
-#: src/audio_out/audio_directx2_out.c:194
+#: src/audio_out/audio_directx2_out.c:191
msgid "DirectSound wasn't initialized"
msgstr "DirectSound non inizializzato"
-#: src/audio_out/audio_directx2_out.c:195
+#: src/audio_out/audio_directx2_out.c:192
msgid "function is not supported"
msgstr "la funzione non è supportata"
-#: src/audio_out/audio_directx2_out.c:196
+#: src/audio_out/audio_directx2_out.c:193
msgid "unknown error"
msgstr "errore sconosciuto"
-#: src/audio_out/audio_directx2_out.c:206
+#: src/audio_out/audio_directx2_out.c:203
#, c-format
msgid "Unable to create direct sound object."
msgstr "Impossibile creare l'oggetto DirectSound."
-#: src/audio_out/audio_directx2_out.c:212
+#: src/audio_out/audio_directx2_out.c:209
#, c-format
msgid "Could not set direct sound cooperative level."
msgstr "Impossibile impostare il livello cooperativo DirectSound."
-#: src/audio_out/audio_directx2_out.c:286
+#: src/audio_out/audio_directx2_out.c:283
msgid "Unable to create secondary direct sound buffer"
msgstr "Impossibile creare il buffer DirectSound secondario."
-#: src/audio_out/audio_directx2_out.c:310
+#: src/audio_out/audio_directx2_out.c:307
#, c-format
msgid "Unable to create buffer position events."
msgstr "Impossibile creare gli eventi di posizione del buffer."
-#: src/audio_out/audio_directx2_out.c:318
+#: src/audio_out/audio_directx2_out.c:315
msgid "Unable to get notification interface"
msgstr "Impossibile leggere l'interfaccia di notifica."
-#: src/audio_out/audio_directx2_out.c:323
+#: src/audio_out/audio_directx2_out.c:320
msgid "Unable to set notification positions"
msgstr "Impossibile impostare le posizioni di notifica"
-#: src/audio_out/audio_directx2_out.c:343
+#: src/audio_out/audio_directx2_out.c:340
msgid "Couldn't play sound buffer"
msgstr "Impossibile riprodurre il buffer sonoro"
-#: src/audio_out/audio_directx2_out.c:355
+#: src/audio_out/audio_directx2_out.c:352
msgid "Couldn't stop sound buffer"
msgstr "Impossibile fermare il buffer sonoro"
-#: src/audio_out/audio_directx2_out.c:368
+#: src/audio_out/audio_directx2_out.c:365
msgid "Can't get buffer position"
msgstr "Impossibile leggere la posizione del buffer"
-#: src/audio_out/audio_directx2_out.c:382
+#: src/audio_out/audio_directx2_out.c:379
msgid "Can't set buffer position"
msgstr "Impossibile impostare la posizione del buffer"
-#: src/audio_out/audio_directx2_out.c:414
+#: src/audio_out/audio_directx2_out.c:411
msgid "Can't set sound volume"
msgstr "Impossibile impostare il volume sonoro"
-#: src/audio_out/audio_directx2_out.c:432
+#: src/audio_out/audio_directx2_out.c:429
#, c-format
msgid ": buffer lost, tryig to restore\n"
msgstr ": buffer perso, provando a recuperare\n"
-#: src/audio_out/audio_directx2_out.c:436
+#: src/audio_out/audio_directx2_out.c:433
msgid "Couldn't lock direct sound buffer"
msgstr "Impossibile bloccare il buffer DirectSound"
-#: src/audio_out/audio_directx2_out.c:447
+#: src/audio_out/audio_directx2_out.c:444
msgid "Couldn't unlock direct sound buffer"
msgstr "Impossibile sbloccare il buffer DirectSound"
-#: src/audio_out/audio_directx2_out.c:544
+#: src/audio_out/audio_directx2_out.c:541
#, c-format
msgid "Unable to create primary direct sound buffer."
msgstr "Impossibile creare il buffer DirectSound primario."
-#: src/audio_out/audio_directx2_out.c:637
+#: src/audio_out/audio_directx2_out.c:634
#, c-format
msgid ": play cursor overran, flushing buffers\n"
msgstr ""
": il cursore di riproduzione è uscito dai limiti, svuotamento dei buffer.\n"
-#: src/audio_out/audio_directx2_out.c:655
+#: src/audio_out/audio_directx2_out.c:652
#, c-format
msgid ": delayed by %ld msec\n"
msgstr ": ritardato di %ld msec\n"
-#: src/audio_out/audio_directx2_out.c:759
+#: src/audio_out/audio_directx2_out.c:756
#, c-format
msgid ": can't create pthread condition: %s\n"
msgstr ": impossibile creare la condizione pthread: %s\n"
-#: src/audio_out/audio_directx2_out.c:763
+#: src/audio_out/audio_directx2_out.c:760
#, c-format
msgid ": can't create pthread mutex: %s\n"
msgstr ": impossibile creare il mutex pthread: %s\n"
-#: src/audio_out/audio_directx2_out.c:770
+#: src/audio_out/audio_directx2_out.c:767
#, c-format
msgid ": can't create buffer pthread: %s\n"
msgstr ": impossibile creare il buffer pthread: %s\n"
-#: src/audio_out/audio_directx2_out.c:877
+#: src/audio_out/audio_directx2_out.c:874
#, c-format
msgid ": can't destroy buffer pthread: %s\n"
msgstr ": impossibile cancellare il buffer pthread: %s\n"
-#: src/audio_out/audio_directx2_out.c:884
+#: src/audio_out/audio_directx2_out.c:881
#, c-format
msgid ": can't destroy pthread condition: %s\n"
msgstr ": impossibile cancellare la condizione pthread: %s\n"
-#: src/audio_out/audio_directx2_out.c:887
+#: src/audio_out/audio_directx2_out.c:884
#, c-format
msgid ": can't destroy pthread mutex: %s\n"
msgstr ": impossibile cancellare il mutex pthread: %s\n"
-#: src/audio_out/audio_directx2_out.c:947
+#: src/audio_out/audio_directx2_out.c:944
#, c-format
msgid ": unknown control command %d\n"
msgstr "; comando di controllo sconosciuto %d\n"
-#: src/audio_out/audio_directx2_out.c:1003
+#: src/audio_out/audio_directx2_out.c:1000
msgid "second xine audio output plugin using directx"
msgstr "secondo plugin di uscita audio per xine utilizzante directx"
@@ -1012,7 +1012,7 @@ msgstr "demux_snd: paramentri intestazione errati\n"
msgid "demux_snd: unsupported audio type: %d\n"
msgstr "demux_snd: tipo audio non supportato: %d\n"
-#: src/demuxers/demux_tta.c:88
+#: src/demuxers/demux_tta.c:86
msgid "demux_tta: total frames count too high\n"
msgstr ""
@@ -1038,7 +1038,7 @@ msgstr ""
"demux_wc3movie: parte di SHOT di riferimento con palette non valida (%d >= %"
"d)\n"
-#: src/demuxers/demux_wc3movie.c:406
+#: src/demuxers/demux_wc3movie.c:404
#, c-format
msgid "demux_wc3movie: There was a problem while loading palette chunks\n"
msgstr ""
@@ -1524,30 +1524,30 @@ msgstr ""
"video_out_dxr3: ERRORE leggendo il file di inizializzazione dell'overlay. Si "
"esegua l'autocalibrazione.\n"
-#: src/input/input_cdda.c:1621
+#: src/input/input_cdda.c:1608
#, c-format
msgid "%s: can't connect to %s:%d\n"
msgstr "%s: impossibile connettersi a %s: %d\n"
-#: src/input/input_cdda.c:1668
+#: src/input/input_cdda.c:1655
#, c-format
msgid "input_cdda: successfuly connected to cddb server '%s:%d'.\n"
msgstr "input_cdda: connesso al server CDDB %s:%d con successo.\n"
-#: src/input/input_cdda.c:1673
+#: src/input/input_cdda.c:1660
#, c-format
msgid "input_cdda: failed to connect to cddb server '%s:%d' (%s).\n"
msgstr "input_cdda: connessione al server CDDB '%s:%d' non riuscita (%s).\n"
-#: src/input/input_cdda.c:2707
+#: src/input/input_cdda.c:2690
msgid "CD Digital Audio (aka. CDDA)"
msgstr "CD Audio (CDDA)"
-#: src/input/input_cdda.c:2760
+#: src/input/input_cdda.c:2742
msgid "device used for CD audio"
msgstr "dispositivo utilizzato per CD audio"
-#: src/input/input_cdda.c:2761
+#: src/input/input_cdda.c:2743
msgid ""
"The path to the device, usually a CD or DVD drive, which you intend to use "
"for playing audio CDs."
@@ -1555,11 +1555,11 @@ msgstr ""
"Il percorso al dispositivo, solitamente un lettore CD o DVD, che si intende "
"utilizzare per riprodurre CD audio."
-#: src/input/input_cdda.c:2767
+#: src/input/input_cdda.c:2749
msgid "query CDDB"
msgstr "interroga CDDB"
-#: src/input/input_cdda.c:2767
+#: src/input/input_cdda.c:2749
msgid ""
"Enables CDDB queries, which will give you convenient title and track names "
"for your audio CDs.\n"
@@ -1573,11 +1573,11 @@ msgstr ""
"informazioni sono ricercate su un server internet che può raccogliere un "
"profilo delle proprie abitudini d'ascolto."
-#: src/input/input_cdda.c:2775
+#: src/input/input_cdda.c:2757
msgid "CDDB server name"
msgstr "nome del server CDDB"
-#: src/input/input_cdda.c:2775
+#: src/input/input_cdda.c:2757
msgid ""
"The CDDB server used to retrieve the title and track information from.\n"
"This setting is security critical, because the sever will receive "
@@ -1590,35 +1590,19 @@ msgstr ""
"risposte maliziose. Assicuratevi di inserire un server di cui ci si possa "
"fidare."
-#: src/input/input_cdda.c:2783
+#: src/input/input_cdda.c:2765
msgid "CDDB server port"
msgstr "porta del server CDDB"
-#: src/input/input_cdda.c:2783
+#: src/input/input_cdda.c:2765
msgid "The server port used to retrieve the title and track information from."
msgstr "La porta del server utilizzato per recuperare titoli e tracce."
-#: src/input/input_cdda.c:2789
-msgid "CDDB cache directory"
-msgstr "directory cache CDDB"
-
-#: src/input/input_cdda.c:2789
-msgid ""
-"The replies from the CDDB server will be cached in this directory.\n"
-"This setting is security critical, because files with uncontrollable names "
-"will be created in this directory. Be sure to use a dedicated directory not "
-"used for anything but CDDB caching."
-msgstr ""
-"Le risposte dal server CDDB saranno salvate in questa directory.\n"
-"Questa impostazione è critica, perché in questa directory saranno creati "
-"file con nomi incontrollati. Assicurative di utilizzare una directory "
-"dedicata non utilizzata per altro oltre al caching CDDB. "
-
-#: src/input/input_cdda.c:2797
+#: src/input/input_cdda.c:2771
msgid "slow down disc drive to this speed factor"
msgstr "rallenta il lettore dischi a questa velocità"
-#: src/input/input_cdda.c:2798
+#: src/input/input_cdda.c:2772
msgid ""
"Since some CD or DVD drives make some really loud noises because of the fast "
"disc rotation, xine will try to slow them down. With standard CD or DVD "
@@ -1633,50 +1617,55 @@ msgstr ""
"dovrebbe influenzare le prestazioni di riproduzione.\n"
"Un valore pari a zero disabilita il rallentamento."
-#: src/input/input_dvb.c:881
-#, c-format
-msgid "input_dvb: failed to open dvb channel file '%s'\n"
+#: src/input/input_dvb.c:899
+#, fuzzy, c-format
+msgid "input_dvb: failed to open dvb channel file '%s': %s\n"
+msgstr "input_dvb: apertura file di canale DVB non riuscita '%s'\n"
+
+#: src/input/input_dvb.c:905
+#, fuzzy, c-format
+msgid "input_dvb: dvb channel file '%s' is not a plain file\n"
msgstr "input_dvb: apertura file di canale DVB non riuscita '%s'\n"
-#: src/input/input_dvb.c:2082 src/input/input_dvb.c:2910
+#: src/input/input_dvb.c:2115 src/input/input_dvb.c:2943
msgid "input_dvb: tuner_set_channel failed\n"
msgstr "input_dvb: tuner_set_channel non riuscito\n"
-#: src/input/input_dvb.c:2710
+#: src/input/input_dvb.c:2743
msgid "input_dvb: cannot open dvb device\n"
msgstr "input_dvb: impossibile aprire dispositivo DVB\n"
-#: src/input/input_dvb.c:2734
+#: src/input/input_dvb.c:2767
#, c-format
msgid "input_dvb: channel %d out of range, defaulting to 0\n"
msgstr ""
"input_dvb: canale %d fuori scala, sarà utilizzato il valore predefinito 0\n"
-#: src/input/input_dvb.c:2745
+#: src/input/input_dvb.c:2778
#, c-format
msgid "input_dvb: searching for channel %s\n"
msgstr "input_dvb: ricerca del canale %s\n"
-#: src/input/input_dvb.c:2768
+#: src/input/input_dvb.c:2801
#, c-format
msgid "input_dvb: exact match for %s not found: trying partial matches\n"
msgstr ""
"input_dvb: corrispondenza esatta per %s non trovata: saranno provate le "
"corrispondenze parziali.\n"
-#: src/input/input_dvb.c:2775
+#: src/input/input_dvb.c:2808
#, c-format
msgid "input_dvb: found matching channel %s\n"
msgstr "input_dvb: trovato canale corrispondente %s\n"
-#: src/input/input_dvb.c:2788
+#: src/input/input_dvb.c:2821
#, c-format
msgid "input_dvb: channel %s not found in channels.conf, defaulting.\n"
msgstr ""
"input_dvb: canale %s non trovato in channels.conf, sarà utilizzata un "
"predefinito.\n"
-#: src/input/input_dvb.c:2794
+#: src/input/input_dvb.c:2827
msgid ""
"input_dvb: invalid channel specification, defaulting to last viewed "
"channel.\n"
@@ -1684,13 +1673,13 @@ msgstr ""
"input_dvb: specifica del canale non valida, sarà utilizzato l'ultimo canale "
"visto.\n"
-#: src/input/input_dvb.c:2800
+#: src/input/input_dvb.c:2833
msgid "input_dvb: invalid channel specification, defaulting to channel 0\n"
msgstr ""
"input_dvb: specifica del canale non valida, sarà utilizzato il canale "
"predefinito 0.\n"
-#: src/input/input_dvb.c:2812
+#: src/input/input_dvb.c:2845
msgid ""
"input_dvb: dvbs mrl specified but the tuner doesn't appear to be QPSK (DVB-"
"S)\n"
@@ -1698,7 +1687,7 @@ msgstr ""
"input_dvb: è stato specificato un MRL DVB-S, ma il sintonizzatore non pare "
"essere QPSK (DVB-S)\n"
-#: src/input/input_dvb.c:2832
+#: src/input/input_dvb.c:2865
msgid ""
"input_dvb: dvbt mrl specified but the tuner doesn't appear to be OFDM (DVB-"
"T)\n"
@@ -1706,7 +1695,7 @@ msgstr ""
"input_dvb: è stato specificato un MRL DVB-T ma il sintonizzatore non pare "
"essere OFDM (DVB-T)\n"
-#: src/input/input_dvb.c:2855 src/input/input_dvb.c:2881
+#: src/input/input_dvb.c:2888 src/input/input_dvb.c:2914
msgid ""
"input_dvb: dvbc mrl specified but the tuner doesn't appear to be QAM (DVB-"
"C)\n"
@@ -1714,20 +1703,20 @@ msgstr ""
"input_dvb: è stato specificato un MRL DVB-C ma il sintonizzatore non pare "
"essere QAM (DVB-C)\n"
-#: src/input/input_dvb.c:2916
+#: src/input/input_dvb.c:2949
#, c-format
msgid "input_dvb: cannot open dvr device '%s'\n"
msgstr "input_dvb: impossibile aprire dispositivo DVR '%s'\n"
-#: src/input/input_dvb.c:2938
+#: src/input/input_dvb.c:2971
msgid "input_dvb: cannot create EPG updater thread\n"
msgstr "input_dvb: impossibile creare thread di aggiornamento EPG.\n"
-#: src/input/input_dvb.c:3000
+#: src/input/input_dvb.c:3033
msgid "use DVB 'center cutout' (zoom)"
msgstr "usa il 'taglio centrale' DVB (zoom)"
-#: src/input/input_dvb.c:3001
+#: src/input/input_dvb.c:3034
msgid ""
"This will allow fullscreen playback of 4:3 content transmitted in a 16:9 "
"frame."
@@ -1735,15 +1724,15 @@ msgstr ""
"Questo permetterà la riproduzione a pieno schermo di contenuto 4:3 trasmesso "
"in un frame 16:9."
-#: src/input/input_dvb.c:3094
+#: src/input/input_dvb.c:3127
msgid "DVB (Digital TV) input plugin"
msgstr "plugin di input per DVB (TV Digitale)"
-#: src/input/input_dvb.c:3242
+#: src/input/input_dvb.c:3244
msgid "Remember last DVB channel watched"
msgstr "Ricorda l'ultimo canale DVB visto."
-#: src/input/input_dvb.c:3243
+#: src/input/input_dvb.c:3245
msgid ""
"On autoplay, xine will remember and switch to the channel indicated in media."
"dvb.last_channel. "
@@ -1751,19 +1740,19 @@ msgstr ""
"Durante l'auto riproduzione xine ricorderà e scambierà al canale indicato in "
"media.dvb.last_channel ."
-#: src/input/input_dvb.c:3250
+#: src/input/input_dvb.c:3252
msgid "Last DVB channel viewed"
msgstr "Ultimo canale DVB visto"
-#: src/input/input_dvb.c:3251
+#: src/input/input_dvb.c:3253
msgid "If enabled xine will remember and switch to this channel. "
msgstr "Se abilitato xine ricorderà e scambierà a questo canale."
-#: src/input/input_dvb.c:3257
+#: src/input/input_dvb.c:3259
msgid "Number of dvb card to use."
msgstr "Indice di scheda DVB da utilizzare."
-#: src/input/input_dvb.c:3258
+#: src/input/input_dvb.c:3260
msgid ""
"Leave this at zero unless you really have more than 1 card in your system."
msgstr ""
@@ -1795,11 +1784,11 @@ msgstr ""
"Il percorso al dispositivo, solitamente un lettore DVD, che si intende usare "
"per riprodurre DVD."
-#: src/input/input_dvd.c:1800
+#: src/input/input_dvd.c:1799
msgid "raw device set up for DVD access"
msgstr "dispositivo diretto impostato per l'accesso DVD"
-#: src/input/input_dvd.c:1801
+#: src/input/input_dvd.c:1800
msgid ""
"If this points to a raw device connected to your DVD device, xine will use "
"the raw device for playback. This has the advantage of being slightly faster "
@@ -1819,11 +1808,11 @@ msgstr ""
"Si veda la documentazione sull'impostazione dei dispositivi diretti (man "
"raw) per maggiori informazioni."
-#: src/input/input_dvd.c:1814
+#: src/input/input_dvd.c:1813
msgid "CSS decryption method"
msgstr "Metodo di decifratura CSS"
-#: src/input/input_dvd.c:1815
+#: src/input/input_dvd.c:1814
msgid ""
"Selects the decryption method libdvdcss will use to descramble copy "
"protected DVDs. Try the various methods, if you have problems playing "
@@ -1833,30 +1822,11 @@ msgstr ""
"DVD protetti da copia. Si provino i vari metodi se si hanno problemi nella "
"riproduzione di DVD cifrati."
-#: src/input/input_dvd.c:1823
-msgid "path to the title key cache"
-msgstr "percorso alla cache delle chiavi dei titoli"
-
-#: src/input/input_dvd.c:1824
-msgid ""
-"Since cracking the copy protection of scrambled DVDs can be quite time "
-"consuming, libdvdcss will cache the cracked keys in this directory.\n"
-"This setting is security critical, because files with uncontrollable names "
-"will be created in this directory. Be sure to use a dedicated directory not "
-"used for anything but DVD key caching."
-msgstr ""
-"Poiché rompere la protezione da copia dei DVD cifrati può richiedere diverso "
-"tempo, libdvdcss memorizzerà le chiavi decifrate in questa directory.\n"
-"Questa impostazione è critica, poiché file con nomi incontrollabili saranno "
-"creati in questa directory. Assicuratevi di utilizzare una directory "
-"dedicata non utilizzata per altri scopi oltre alla memorizzazioni delle "
-"chiavi DVD."
-
-#: src/input/input_dvd.c:1846
+#: src/input/input_dvd.c:1829
msgid "region the DVD player claims to be in (1 to 8)"
msgstr "regione a cui il lettore DVD dirà di appartenere (da 1 a 8)"
-#: src/input/input_dvd.c:1847
+#: src/input/input_dvd.c:1830
msgid ""
"This only needs to be changed if your DVD jumps to a screen complaining "
"about a wrong region code. It has nothing to do with the region code set in "
@@ -1867,11 +1837,11 @@ msgstr ""
"nulla a che vedere con il codice regionale settato nei lettori DVD, è "
"interamente software."
-#: src/input/input_dvd.c:1853
+#: src/input/input_dvd.c:1836
msgid "default language for DVD playback"
msgstr "lingua predefinita per la riproduzione DVD"
-#: src/input/input_dvd.c:1854
+#: src/input/input_dvd.c:1837
msgid ""
"xine tries to use this language as a default for DVD playback. As far as the "
"DVD supports it, menus and audio tracks will be presented in this language.\n"
@@ -1882,11 +1852,11 @@ msgstr ""
"questa lingua.\n"
"Questo valore deve essere un codice di lingua di due caratteri ISO639."
-#: src/input/input_dvd.c:1860
+#: src/input/input_dvd.c:1843
msgid "read-ahead caching"
msgstr "read-ahead caching"
-#: src/input/input_dvd.c:1861
+#: src/input/input_dvd.c:1844
msgid ""
"xine can use a read ahead cache for DVD drive access.\n"
"This may lead to jerky playback on slow drives, but it improves the impact "
@@ -1896,11 +1866,11 @@ msgstr ""
"Questo può portare a cattiva riproduzione su lettori lenti, ma migliora "
"l'impatto con il cambio di strato nel DVD sui lettori più veloci."
-#: src/input/input_dvd.c:1867
+#: src/input/input_dvd.c:1850
msgid "unit for the skip action"
msgstr "unità per l'azione di salto"
-#: src/input/input_dvd.c:1868
+#: src/input/input_dvd.c:1851
msgid ""
"You can configure the behaviour when issuing a skip command (using the skip "
"buttons for example). The individual values mean:\n"
@@ -1934,11 +1904,11 @@ msgstr ""
"salterà un titolo DVD, un'unità strutturale che rappresenta intere "
"funzionalità sul DVD."
-#: src/input/input_dvd.c:1883
+#: src/input/input_dvd.c:1866
msgid "unit for seeking"
msgstr "unità per la ricerca"
-#: src/input/input_dvd.c:1884
+#: src/input/input_dvd.c:1867
msgid ""
"You can configure the domain spanned by the seek slider. The individual "
"values mean:\n"
@@ -1963,11 +1933,11 @@ msgstr ""
"la ricerca sarà effettuata su un programma DVD, che è un'unità di "
"navigazione che rappresenta un capitolo della corrente funzionalità."
-#: src/input/input_dvd.c:1895
+#: src/input/input_dvd.c:1878
msgid "play mode when title/chapter is given"
msgstr "modalità di riproduzione quando si fornisce un titolo/capitolo"
-#: src/input/input_dvd.c:1896
+#: src/input/input_dvd.c:1879
msgid ""
"You can configure the behaviour when playing a dvd from a given title/"
"chapter (eg. using MRL 'dvd:/1.2'). The individual values mean:\n"
@@ -2728,7 +2698,7 @@ msgstr ""
"1024: Still-frame\n"
"2048: Debugging from VCDINFO\n"
-#: src/liba52/xine_a52_decoder.c:742 src/libdts/xine_dts_decoder.c:546
+#: src/liba52/xine_a52_decoder.c:742 src/libxineadec/xine_dts_decoder.c:524
msgid "HELP! a mono-only audio driver?!\n"
msgstr "AIUTO! un driver audio solo mono?\n"
@@ -2792,65 +2762,65 @@ msgstr "libfaad: libfaad NeAACDecInit2 fallita.\n"
msgid "libfaad: libfaad NeAACDecInit failed.\n"
msgstr "libfaad: libfaad NeAACDecInit fallita.\n"
-#: src/libffmpeg/ff_audio_decoder.c:120
+#: src/libffmpeg/ff_audio_decoder.c:122
#, c-format
msgid "ffmpeg_audio_dec: increasing buffer to %d to avoid overflow.\n"
msgstr "ffmpeg_audio_dec: aumentando il buffer a %d per evitare overflow.\n"
-#: src/libffmpeg/ff_audio_decoder.c:164
+#: src/libffmpeg/ff_audio_decoder.c:166
#, c-format
msgid "ffmpeg_audio_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"
msgstr ""
"ffmpeg_audio_dec: impossibile trovare il decoder ffmpeg per il tipo di "
"buffer 0x%X\n"
-#: src/libffmpeg/ff_audio_decoder.c:256
+#: src/libffmpeg/ff_audio_decoder.c:258
msgid "ffmpeg_audio_dec: trying to open null codec\n"
msgstr "ffmpeg_audio_dec: provando ad aprire un codec nullo.\n"
-#: src/libffmpeg/ff_audio_decoder.c:265
+#: src/libffmpeg/ff_audio_decoder.c:267
msgid "ffmpeg_audio_dec: couldn't open decoder\n"
msgstr "ffmpeg_audio_dec: impossibile aprire il decoder.\n"
-#: src/libffmpeg/ff_dvaudio_decoder.c:286
+#: src/libffmpeg/ff_dvaudio_decoder.c:280
#, c-format
msgid "dvaudio: increasing buffer to %d to avoid overflow.\n"
msgstr "dvaudio: aumentando il buffer a %d per evitare overflow.\n"
-#: src/libffmpeg/ff_video_decoder.c:157
+#: src/libffmpeg/ff_video_decoder.c:155
msgid "ffmpeg_video_dec: unsupported frame format, DR1 disabled.\n"
msgstr "ffmpeg_video_dec: formato frame non supportato, DR1 disabilitato.\n"
-#: src/libffmpeg/ff_video_decoder.c:175
+#: src/libffmpeg/ff_video_decoder.c:173
msgid "ffmpeg_video_dec: unsupported frame dimensions, DR1 disabled.\n"
msgstr ""
"ffmpeg_video_dec: dimensioni del frame non supportate. DR1 disabilitato.\n"
-#: src/libffmpeg/ff_video_decoder.c:335
+#: src/libffmpeg/ff_video_decoder.c:333
#, c-format
msgid "ffmpeg_video_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"
msgstr ""
"ffmpeg_video_dec: impossibile trovare il decoder ffmpeg per il tipo di "
"buffer 0x%X\n"
-#: src/libffmpeg/ff_video_decoder.c:364
+#: src/libffmpeg/ff_video_decoder.c:362
msgid "ffmpeg_video_dec: couldn't open decoder\n"
msgstr "ffmpeg_video_dec: impossibile aprire il decoder\n"
-#: src/libffmpeg/ff_video_decoder.c:399
+#: src/libffmpeg/ff_video_decoder.c:397
msgid "ffmpeg_video_dec: direct rendering enabled\n"
msgstr "ffmpeg_video_dec: visualizzazione diretta abilitata\n"
-#: src/libffmpeg/ff_video_decoder.c:818
+#: src/libffmpeg/ff_video_decoder.c:816
#, c-format
msgid "ffmpeg_video_dec: increasing buffer to %d to avoid overflow.\n"
msgstr "ffmpeg_video_dec: buffer aumentato a %d per evitare overflow.\n"
-#: src/libffmpeg/ff_video_decoder.c:1516
+#: src/libffmpeg/ff_video_decoder.c:1514
msgid "MPEG-4 postprocessing quality"
msgstr "qualità di post-elaborazione MPEG-4"
-#: src/libffmpeg/ff_video_decoder.c:1517
+#: src/libffmpeg/ff_video_decoder.c:1515
msgid ""
"You can adjust the amount of post processing applied to MPEG-4 video.\n"
"Higher values result in better quality, but need more CPU. Lower values may "
@@ -2864,11 +2834,11 @@ msgstr ""
"otnenuto ad alta qualità, una post elaborazione troppo alta può in realtà "
"rendere l'immagine peggiore sfocandola troppo."
-#: src/libffmpeg/ffmpeg_encoder.c:167
+#: src/libffmpeg/ffmpeg_encoder.c:163
msgid "libavcodec mpeg output bitrate (kbit/s)"
msgstr "bitrate MPEG di uscita per libavcodec (kbit/s)"
-#: src/libffmpeg/ffmpeg_encoder.c:168
+#: src/libffmpeg/ffmpeg_encoder.c:164
msgid ""
"The bitrate the libavcodec mpeg encoder should use for DXR3's encoding mode. "
"Higher values will increase quality and CPU usage.\n"
@@ -2879,11 +2849,11 @@ msgstr ""
"Questa impostazione è considerata solo quando è disabilitata la modalità a "
"qualità costante. "
-#: src/libffmpeg/ffmpeg_encoder.c:175
+#: src/libffmpeg/ffmpeg_encoder.c:171
msgid "constant quality mode"
msgstr "modalità a qualità costante"
-#: src/libffmpeg/ffmpeg_encoder.c:176
+#: src/libffmpeg/ffmpeg_encoder.c:172
msgid ""
"When enabled, libavcodec will use a constant quality mode by dynamically "
"compressing the images based on their complexity. When disabled, libavcodec "
@@ -2893,41 +2863,41 @@ msgstr ""
"comprimendo le immagini a secodna della loro complessità. Quando "
"disabilitata libavcodec utilizzerà una modalità a bitrate costante."
-#: src/libffmpeg/ffmpeg_encoder.c:183
+#: src/libffmpeg/ffmpeg_encoder.c:179
msgid "minimum compression"
msgstr "compressione minima"
-#: src/libffmpeg/ffmpeg_encoder.c:184
+#: src/libffmpeg/ffmpeg_encoder.c:180
msgid "The minimum compression to apply to an image in constant quality mode."
msgstr ""
"La compressione minima da applicare ad un'immagine utilizzando una modalità "
"a qualità costante."
-#: src/libffmpeg/ffmpeg_encoder.c:189
+#: src/libffmpeg/ffmpeg_encoder.c:185
msgid "maximum quantizer"
msgstr "quantizzatore massimo"
-#: src/libffmpeg/ffmpeg_encoder.c:190
+#: src/libffmpeg/ffmpeg_encoder.c:186
msgid "The maximum compression to apply to an image in constant quality mode."
msgstr ""
"La compressione massima da applicare ad un'immagine utilizzando una modalità "
"a qualità costante."
-#: src/libmusepack/xine_musepack_decoder.c:241
+#: src/libxineadec/xine_musepack_decoder.c:249
#, c-format
msgid "libmusepack: mpc_streaminfo_read failed: %d\n"
msgstr "libmusepack: mpc_streaminfo_read fallita: %d\n"
-#: src/libmusepack/xine_musepack_decoder.c:315
+#: src/libxineadec/xine_musepack_decoder.c:323
msgid "libmusepack: data after last frame ignored\n"
msgstr "libmusepack: dati dopo l'ultimo frame ignorati.\n"
-#: src/libmusepack/xine_musepack_decoder.c:326
+#: src/libxineadec/xine_musepack_decoder.c:334
msgid "libmusepack: mpc_decoder_initialise failed\n"
msgstr "libmusepack: mpc_decoder_initialise fallita\n"
-#: src/libmusepack/xine_musepack_decoder.c:346
-#: src/libmusepack/xine_musepack_decoder.c:361
+#: src/libxineadec/xine_musepack_decoder.c:354
+#: src/libxineadec/xine_musepack_decoder.c:369
#, c-format
msgid "libmusepack: mpc_decoder_decode failed: %d\n"
msgstr "libmusepack: mpc_decoder_decode fallita: %d\n"
@@ -3839,7 +3809,7 @@ msgid "Select the video output layer by its id."
msgstr "Selezionate lo strato di uscita video tramite id."
#: src/video_out/video_out_directfb.c:1804
-#: src/video_out/video_out_directfb.c:2013
+#: src/video_out/video_out_directfb.c:2014
#, fuzzy, c-format
msgid "video_out_directfb: using display layer #%d.\n"
msgstr ""
@@ -3849,13 +3819,13 @@ msgstr ""
msgid "xine video output plugin using DirectFB."
msgstr "plugin di output video per xine utilizzante DirectFB"
-#: src/video_out/video_out_directfb.c:2006
+#: src/video_out/video_out_directfb.c:2007
#, fuzzy
msgid "video_out_directfb: no usable display layer was found!\n"
msgstr ""
"video_out_directfb: nessuno strato di sovrimpressione utilizzabile trovato.\n"
-#: src/video_out/video_out_directfb.c:2095
+#: src/video_out/video_out_directfb.c:2096
msgid "xine video output plugin using DirectFB under XDirectFB."
msgstr "plugin di output video per xine utilizzante DirectFB sotto XDirectFB"
@@ -3863,7 +3833,7 @@ msgstr "plugin di output video per xine utilizzante DirectFB sotto XDirectFB"
msgid "xine video output plugin for win32 using directx"
msgstr "plugin di output video per xine per win32 che usa directx"
-#: src/video_out/video_out_fb.c:792
+#: src/video_out/video_out_fb.c:780
#, c-format
msgid ""
"video_out_fb: only packed truecolor/directcolor is supported (%d).\n"
@@ -3872,11 +3842,11 @@ msgstr ""
"video_out_fb: è supportato solo truecolor/directcolor impacchettato (%d).\n"
" Si controlli 'fbset -i' o si provi 'fbset -depth 16'.\n"
-#: src/video_out/video_out_fb.c:852 src/video_out/video_out_vidix.c:1239
+#: src/video_out/video_out_fb.c:840 src/video_out/video_out_vidix.c:1239
msgid "framebuffer device name"
msgstr "nome del dispositivo framebuffer"
-#: src/video_out/video_out_fb.c:853 src/video_out/video_out_vidix.c:1240
+#: src/video_out/video_out_fb.c:841 src/video_out/video_out_vidix.c:1240
msgid ""
"Specifies the file name for the framebuffer device to be used.\n"
"This setting is security critical, because when changed to a different file, "
@@ -3889,20 +3859,20 @@ msgstr ""
"arbitrario, si deve quindi essere attenti che il valore inserito sia "
"veramente un dispositivo framebuffer valido."
-#: src/video_out/video_out_fb.c:927
-msgid "video_out_fb: Your video mode was not recognized, sorry.\n"
+#: src/video_out/video_out_fb.c:915
+#, fuzzy, c-format
+msgid "%s: Your video mode was not recognized, sorry.\n"
msgstr "video_out-fb: la modalità video non è stata riconosciuta.\n"
-#: src/video_out/video_out_fb.c:984
-#, c-format
-msgid "video_out_fb: %d video RAM buffers are available.\n"
+#: src/video_out/video_out_fb.c:972
+#, fuzzy, c-format
+msgid "%s: %d video RAM buffers are available.\n"
msgstr "video_out_fb: sono disponibili %d buffer in RAM video.\n"
-#: src/video_out/video_out_fb.c:990
-#, c-format
+#: src/video_out/video_out_fb.c:978
+#, fuzzy, c-format
msgid ""
-"WARNING: video_out_fb: Zero copy buffers are DISABLED because only %d "
-"buffers\n"
+"WARNING: %s: Zero copy buffers are DISABLED because only %d buffers\n"
" are available which is less than the recommended %d buffers. Lowering\n"
" the frame buffer resolution might help.\n"
msgstr ""
@@ -3911,9 +3881,10 @@ msgstr ""
" sono disponibili, meno dei %d buffer raccomandati.\n"
" Abbassare la risoluzione del frame buffer può aiutare.\n"
-#: src/video_out/video_out_fb.c:1001
+#: src/video_out/video_out_fb.c:989
+#, fuzzy, c-format
msgid ""
-"WARNING: video_out_fb: Zero copy buffers are DISABLED because kernel driver\n"
+"WARNING: %s: Zero copy buffers are DISABLED because kernel driver\n"
" do not support screen panning (used for frame flips).\n"
msgstr ""
"ATTENZIONE: video_out_fb: i buffer a copia zero sono DISABILITATI perché i "
@@ -3921,18 +3892,20 @@ msgstr ""
" del kernel non supportano lo spostamento dello schermo (utilizzati per "
"l'inversione dei frame)\n"
-#: src/video_out/video_out_fb.c:1070
-#, c-format
+#: src/video_out/video_out_fb.c:1058
+#, fuzzy, c-format
msgid ""
-"WARNING: video_out_fb: current display depth is %d. For better performance\n"
+"WARNING: %s: current display depth is %d. For better performance\n"
" a depth of 16 bpp is recommended!\n"
"\n"
msgstr ""
-"ATTENZIONE: video_out_fb: la profondità di colore corrente è %d.\n"
-" per prestazioni migliori è raccomandata una profondità di 16bpp.\n"
+"\n"
+"\n"
+"ATTENZIONE: la profondità corrente è %d. Per migliori prestazioni\n"
+"è raccomandata una profondità di 16bpp.\n"
"\n"
-#: src/video_out/video_out_fb.c:1101
+#: src/video_out/video_out_fb.c:1090
msgid "Xine video output plugin using the Linux frame buffer device"
msgstr ""
"plugin di uscita video per xine usante il dispositivo Framebuffer di Linux"
@@ -4012,8 +3985,8 @@ msgstr ""
"Ignorato per le routine statiche.\n"
#: src/video_out/video_out_opengl.c:1918 src/video_out/video_out_vidix.c:1015
-#: src/video_out/video_out_xcbxv.c:1472 src/video_out/video_out_xv.c:1486
-#: src/video_out/video_out_xvmc.c:1461 src/video_out/video_out_xxmc.c:2468
+#: src/video_out/video_out_xcbxv.c:1476 src/video_out/video_out_xv.c:1489
+#: src/video_out/video_out_xvmc.c:1461 src/video_out/video_out_xxmc.c:2465
msgid "enable double buffering"
msgstr "abilita doppio buffering"
@@ -4105,9 +4078,9 @@ msgstr ""
msgid "video_out_pgx64: Error: ioctl failed (FBIOGATTR)\n"
msgstr "video_out_pgx64: Errore: ioctl fallita (FBIOGATTR)\n"
-#: src/video_out/video_out_pgx64.c:1464 src/video_out/video_out_xcbxv.c:1439
-#: src/video_out/video_out_xv.c:1453 src/video_out/video_out_xvmc.c:1446
-#: src/video_out/video_out_xxmc.c:2435
+#: src/video_out/video_out_pgx64.c:1464 src/video_out/video_out_xcbxv.c:1443
+#: src/video_out/video_out_xv.c:1456 src/video_out/video_out_xvmc.c:1446
+#: src/video_out/video_out_xxmc.c:2432
msgid "video overlay colour key"
msgstr "chiave cromatica per l'overlay video"
@@ -4286,9 +4259,9 @@ msgstr "intensità del colore blu"
msgid "The intensity of the blue colour components."
msgstr "L'intensità dei componenti di colore blu."
-#: src/video_out/video_out_vidix.c:1016 src/video_out/video_out_xcbxv.c:1473
-#: src/video_out/video_out_xv.c:1487 src/video_out/video_out_xvmc.c:1462
-#: src/video_out/video_out_xxmc.c:2469
+#: src/video_out/video_out_vidix.c:1016 src/video_out/video_out_xcbxv.c:1477
+#: src/video_out/video_out_xv.c:1490 src/video_out/video_out_xvmc.c:1462
+#: src/video_out/video_out_xxmc.c:2466
msgid ""
"Double buffering will synchronize the update of the video image to the "
"repainting of the entire screen (\"vertical retrace\"). This eliminates "
@@ -4324,9 +4297,9 @@ msgid "video overlay colour key red component"
msgstr "componente rossa della chiave cromatica di sovraimpressione"
#: src/video_out/video_out_vidix.c:1159 src/video_out/video_out_vidix.c:1166
-#: src/video_out/video_out_vidix.c:1173 src/video_out/video_out_xcbxv.c:1440
-#: src/video_out/video_out_xv.c:1454 src/video_out/video_out_xvmc.c:1447
-#: src/video_out/video_out_xxmc.c:2436
+#: src/video_out/video_out_vidix.c:1173 src/video_out/video_out_xcbxv.c:1444
+#: src/video_out/video_out_xv.c:1457 src/video_out/video_out_xvmc.c:1447
+#: src/video_out/video_out_xxmc.c:2433
msgid ""
"The colour key is used to tell the graphics card where to overlay the video "
"image. Try different values, if you experience windows becoming transparent."
@@ -4352,37 +4325,42 @@ msgid "xine video output plugin using libvidix for linux frame buffer"
msgstr ""
"plugin di output video di xine che usa libvidix per il frame buffer Linux"
-#: src/video_out/video_out_xcbshm.c:157
+#: src/video_out/video_out_xcbshm.c:157 src/video_out/video_out_xshm.c:219
+#, c-format
+msgid "%s: %s: allocating image\n"
+msgstr ""
+
+#: src/video_out/video_out_xcbshm.c:159 src/video_out/video_out_xcbshm.c:169
+#: src/video_out/video_out_xcbshm.c:181 src/video_out/video_out_xcbxv.c:272
+#: src/video_out/video_out_xcbxv.c:282 src/video_out/video_out_xcbxv.c:292
+#: src/video_out/video_out_xcbxv.c:304 src/video_out/video_out_xshm.c:204
+#: src/video_out/video_out_xshm.c:221 src/video_out/video_out_xshm.c:232
+#: src/video_out/video_out_xshm.c:251 src/video_out/video_out_xv.c:296
+#: src/video_out/video_out_xv.c:307 src/video_out/video_out_xv.c:316
+#: src/video_out/video_out_xv.c:352 src/video_out/video_out_xxmc.c:648
+#: src/video_out/video_out_xxmc.c:659 src/video_out/video_out_xxmc.c:668
+#: src/video_out/video_out_xxmc.c:704
#, fuzzy, c-format
-msgid ""
-"video_out_xcbshm: %s: allocating image\n"
-"video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+msgid "%s: => not using MIT Shared Memory extension.\n"
msgstr ""
-"video_out_xshm: %s: riservando l'immagine\n"
-"video_out_xshm: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
+"plugin di output video per xine utilizzante l'estensione MIT X Shared Memory"
-#: src/video_out/video_out_xcbshm.c:166
-#, fuzzy
-msgid ""
-"video_out_xcbshm: shared memory error (address error) when allocating "
-"image \n"
-"video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbshm.c:167 src/video_out/video_out_xshm.c:230
+#, fuzzy, c-format
+msgid "%s: shared memory error (address error) when allocating image \n"
msgstr ""
"video_out_xshm: errore nella memoria condivisa (errore d'indirizzo) "
"riservando l'immagine \n"
"video_out_xshm: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
-#: src/video_out/video_out_xcbshm.c:177
-#, fuzzy
-msgid ""
-"video_out_xcbshm: x11 error during shared memory XImage creation\n"
-"video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbshm.c:179 src/video_out/video_out_xcbxv.c:302
+#: src/video_out/video_out_xshm.c:249 src/video_out/video_out_xv.c:350
+#: src/video_out/video_out_xxmc.c:702
+#, c-format
+msgid "%s: x11 error during shared memory XImage creation\n"
msgstr ""
-"video_Out_xshm: errore X11 durante la creazione dell'oggetto XImage "
-"condiviso\n"
-"video_out_xshm: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
-#: src/video_out/video_out_xcbshm.c:1100 src/video_out/video_out_xshm.c:1157
+#: src/video_out/video_out_xcbshm.c:1103 src/video_out/video_out_xshm.c:1161
#, c-format
msgid ""
"\n"
@@ -4397,93 +4375,82 @@ msgstr ""
"è raccomandata una profondità di 16bpp.\n"
"\n"
-#: src/video_out/video_out_xcbshm.c:1113
-#, fuzzy
-msgid "video_out_xcbshm: MIT shared memory extension not present on display.\n"
+#: src/video_out/video_out_xcbshm.c:1116 src/video_out/video_out_xshm.c:1174
+#, fuzzy, c-format
+msgid "%s: MIT shared memory extension not present on display.\n"
msgstr ""
"video_out_xshm: l'estensione MIT Shared Meory non è presente sul display.\n"
-#: src/video_out/video_out_xcbshm.c:1212
-#, fuzzy
-msgid "video_out_xcbshm: your video mode was not recognized, sorry :-(\n"
-msgstr "video_out_xshm: modalità video non riconosciuta.\n"
+#: src/video_out/video_out_xcbshm.c:1215 src/video_out/video_out_xshm.c:1258
+#, fuzzy, c-format
+msgid "%s: your video mode was not recognized, sorry :-(\n"
+msgstr "video_out-fb: la modalità video non è stata riconosciuta.\n"
-#: src/video_out/video_out_xcbshm.c:1242 src/video_out/video_out_xshm.c:1303
+#: src/video_out/video_out_xcbshm.c:1245 src/video_out/video_out_xshm.c:1307
msgid "xine video output plugin using the MIT X shared memory extension"
msgstr ""
"plugin di output video per xine utilizzante l'estensione MIT X Shared Memory"
-#: src/video_out/video_out_xcbxv.c:272
-#, fuzzy
-msgid ""
-"video_out_xcbxv: XvShmCreateImage returned a zero size\n"
-"video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbxv.c:270 src/video_out/video_out_xv.c:305
+#: src/video_out/video_out_xxmc.c:657
+#, c-format
+msgid "%s: XvShmCreateImage returned a zero size\n"
msgstr ""
-"video_out_xv: XvShmCreateImage ha restituito una dimensione pari a zero.\n"
-"video_out_xv: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
-#: src/video_out/video_out_xcbxv.c:281
-#, fuzzy, c-format
-msgid ""
-"video_out_xcbxv: shared memory error in shmget: %s\n"
-"video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbxv.c:280 src/video_out/video_out_xv.c:314
+#: src/video_out/video_out_xxmc.c:666
+#, c-format
+msgid "%s: shared memory error in shmget: %s\n"
msgstr ""
-"video_out_xv: errore nella memoria condivisa in shmget: %s\n"
-"video_out_xv: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
-#: src/video_out/video_out_xcbxv.c:300
-#, fuzzy
-msgid ""
-"video_out_xcbxv: x11 error during shared memory XImage creation\n"
-"video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbxv.c:290
+#, c-format
+msgid "%s: shared memory error (address error)\n"
msgstr ""
-"video_out_xv: errore X11 durante la creazione dell'oggetto XImage in memoria "
-"condivisa.\n"
-"video_out_xv: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
-#: src/video_out/video_out_xcbxv.c:1291
-#, fuzzy
-msgid "video_out_xcbxv: Xv extension not present.\n"
+#: src/video_out/video_out_xcbxv.c:1294 src/video_out/video_out_xv.c:1301
+#: src/video_out/video_out_xxmc.c:2283
+#, fuzzy, c-format
+msgid "%s: Xv extension not present.\n"
msgstr "video_out_xv: estensione Xv non presente.\n"
-#: src/video_out/video_out_xcbxv.c:1333
-#, fuzzy
+#: src/video_out/video_out_xcbxv.c:1336 src/video_out/video_out_xv.c:1338
+#: src/video_out/video_out_xxmc.c:2320
+#, fuzzy, c-format
msgid ""
-"video_out_xcbxv: Xv extension is present but I couldn't find a usable yuv12 "
-"port.\n"
-" Looks like your graphics hardware driver doesn't support "
-"Xv?!\n"
+"%s: Xv extension is present but I couldn't find a usable yuv12 port.\n"
+"\tLooks like your graphics hardware driver doesn't support Xv?!\n"
msgstr ""
"video_out_xv: estensione XV presente ma non è stato possibile trovare una "
"porta yuv12 utilizzabile. sembrerebbe che l'hardware grafico "
"non supporti Xv.\n"
-#: src/video_out/video_out_xcbxv.c:1341
+#: src/video_out/video_out_xcbxv.c:1345
#, fuzzy, c-format
msgid ""
-"video_out_xcbxv: using Xv port %d from adaptor %s for hardware colorspace "
-"conversion and scaling.\n"
+"%s: using Xv port %d from adaptor %s for hardware colorspace conversion and "
+"scaling.\n"
msgstr ""
"video_out_xv: utilizzando la porta Xv %ld dal dispositivo %s per la "
"conversione di colori e il ridimensionamento hardware.\n"
-#: src/video_out/video_out_xcbxv.c:1448 src/video_out/video_out_xv.c:1462
-#: src/video_out/video_out_xvmc.c:1455 src/video_out/video_out_xxmc.c:2444
+#: src/video_out/video_out_xcbxv.c:1452 src/video_out/video_out_xv.c:1465
+#: src/video_out/video_out_xvmc.c:1455 src/video_out/video_out_xxmc.c:2441
msgid "autopaint colour key"
msgstr "colora automaticamente la chive cromatica"
-#: src/video_out/video_out_xcbxv.c:1449 src/video_out/video_out_xv.c:1463
-#: src/video_out/video_out_xvmc.c:1456 src/video_out/video_out_xxmc.c:2445
+#: src/video_out/video_out_xcbxv.c:1453 src/video_out/video_out_xv.c:1466
+#: src/video_out/video_out_xvmc.c:1456 src/video_out/video_out_xxmc.c:2442
msgid "Make Xv autopaint its colorkey."
msgstr "Fa sì che Xv colori automaticamente la propria chiave cromatica."
-#: src/video_out/video_out_xcbxv.c:1456 src/video_out/video_out_xv.c:1470
-#: src/video_out/video_out_xxmc.c:2452
+#: src/video_out/video_out_xcbxv.c:1460 src/video_out/video_out_xv.c:1473
+#: src/video_out/video_out_xxmc.c:2449
msgid "bilinear scaling mode"
msgstr "modalità di ridimensionamento bilineare"
-#: src/video_out/video_out_xcbxv.c:1457 src/video_out/video_out_xv.c:1471
-#: src/video_out/video_out_xxmc.c:2453
+#: src/video_out/video_out_xcbxv.c:1461 src/video_out/video_out_xv.c:1474
+#: src/video_out/video_out_xxmc.c:2450
msgid ""
"Selects the bilinear scaling mode for Permedia cards. The individual values "
"are:\n"
@@ -4509,34 +4476,36 @@ msgstr ""
"1 - abilita il filtro lineare orizzontale\n"
"2 - abilita il filtro bilineare completo"
-#: src/video_out/video_out_xcbxv.c:1509
-#, fuzzy
-msgid "video_out_xcbxv: this adaptor supports the yv12 format.\n"
+#: src/video_out/video_out_xcbxv.c:1513 src/video_out/video_out_xv.c:1523
+#: src/video_out/video_out_xxmc.c:2506
+#, fuzzy, c-format
+msgid "%s: this adaptor supports the yv12 format.\n"
msgstr "video_out_xv: questo dispositivo supporta il formato yv12\n"
-#: src/video_out/video_out_xcbxv.c:1514
-#, fuzzy
-msgid "video_out_xcbxv: this adaptor supports the yuy2 format.\n"
+#: src/video_out/video_out_xcbxv.c:1518 src/video_out/video_out_xv.c:1528
+#: src/video_out/video_out_xxmc.c:2511
+#, fuzzy, c-format
+msgid "%s: this adaptor supports the yuy2 format.\n"
msgstr "video_out_xv: questo dispositivo supporta il formato yuv2.\n"
-#: src/video_out/video_out_xcbxv.c:1522 src/video_out/video_out_xv.c:1547
-#: src/video_out/video_out_xxmc.c:2537
+#: src/video_out/video_out_xcbxv.c:1526 src/video_out/video_out_xv.c:1550
+#: src/video_out/video_out_xxmc.c:2534
msgid "pitch alignment workaround"
msgstr "pitch alignment workaround"
-#: src/video_out/video_out_xcbxv.c:1523 src/video_out/video_out_xv.c:1548
-#: src/video_out/video_out_xxmc.c:2538
+#: src/video_out/video_out_xcbxv.c:1527 src/video_out/video_out_xv.c:1551
+#: src/video_out/video_out_xxmc.c:2535
msgid "Some buggy video drivers need a workaround to function properly."
msgstr ""
"Alcuni driver video difettosi richiedono un workaround per funzionare "
"correttamente."
-#: src/video_out/video_out_xcbxv.c:1529 src/video_out/video_out_xv.c:1554
+#: src/video_out/video_out_xcbxv.c:1533 src/video_out/video_out_xv.c:1557
#: src/video_out/video_out_xvmc.c:1524
msgid "deinterlace method (deprecated)"
msgstr "metodo di deinterlacciamento (deprecato)"
-#: src/video_out/video_out_xcbxv.c:1530 src/video_out/video_out_xv.c:1555
+#: src/video_out/video_out_xcbxv.c:1534 src/video_out/video_out_xv.c:1558
#: src/video_out/video_out_xvmc.c:1525
msgid ""
"This config setting is deprecated. You should use the new deinterlacing post "
@@ -4610,120 +4579,30 @@ msgstr ""
"Applica un leggero sfocamento verticale per rimuovere gli artefatti di comb. "
"Buoni risultati con un uso di CPU medio."
-#: src/video_out/video_out_xcbxv.c:1584 src/video_out/video_out_xv.c:1628
-#: src/video_out/video_out_xxmc.c:2618
+#: src/video_out/video_out_xcbxv.c:1588 src/video_out/video_out_xv.c:1631
+#: src/video_out/video_out_xxmc.c:2615
msgid "xine video output plugin using the MIT X video extension"
msgstr "plugin di output video di xine che usa l'estensione video MIT X"
#: src/video_out/video_out_xshm.c:202
-msgid ""
-"video_out_xshm: shared memory error when allocating image\n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xshm: errore nella memoria condivisa riservando l'immagine:\n"
-"video_out_xshm: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
-
-#: src/video_out/video_out_xshm.c:218
#, c-format
-msgid ""
-"video_out_xshm: %s: allocating image\n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xshm: %s: riservando l'immagine\n"
-"video_out_xshm: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
-
-#: src/video_out/video_out_xshm.c:228
-msgid ""
-"video_out_xshm: shared memory error (address error) when allocating image \n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xshm: errore nella memoria condivisa (errore d'indirizzo) "
-"riservando l'immagine \n"
-"video_out_xshm: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
-
-#: src/video_out/video_out_xshm.c:245
-msgid ""
-"video_out_xshm: x11 error during shared memory XImage creation\n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_Out_xshm: errore X11 durante la creazione dell'oggetto XImage "
-"condiviso\n"
-"video_out_xshm: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
-
-#: src/video_out/video_out_xshm.c:1170
-msgid "video_out_xshm: MIT shared memory extension not present on display.\n"
-msgstr ""
-"video_out_xshm: l'estensione MIT Shared Meory non è presente sul display.\n"
-
-#: src/video_out/video_out_xshm.c:1254
-msgid "video_out_xshm: your video mode was not recognized, sorry :-(\n"
-msgstr "video_out_xshm: modalità video non riconosciuta.\n"
-
-#: src/video_out/video_out_xv.c:296
-msgid ""
-"video_out_xv: XvShmCreateImage failed\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
+msgid "%s: shared memory error when allocating image\n"
msgstr ""
-"video_out_xv: XvShmCreateImage fallita.\n"
-"video_out_xv: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
-#: src/video_out/video_out_xv.c:306
-msgid ""
-"video_out_xv: XvShmCreateImage returned a zero size\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xv: XvShmCreateImage ha restituito una dimensione pari a zero.\n"
-"video_out_xv: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
-
-#: src/video_out/video_out_xv.c:314
+#: src/video_out/video_out_xv.c:294 src/video_out/video_out_xxmc.c:646
#, c-format
-msgid ""
-"video_out_xv: shared memory error in shmget: %s\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xv: errore nella memoria condivisa in shmget: %s\n"
-"video_out_xv: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
-
-#: src/video_out/video_out_xv.c:346
-msgid ""
-"video_out_xv: x11 error during shared memory XImage creation\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
+msgid "%s: XvShmCreateImage failed\n"
msgstr ""
-"video_out_xv: errore X11 durante la creazione dell'oggetto XImage in memoria "
-"condivisa.\n"
-"video_out_xv: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
-#: src/video_out/video_out_xv.c:1299
-msgid "video_out_xv: Xv extension not present.\n"
-msgstr "video_out_xv: estensione Xv non presente.\n"
-
-#: src/video_out/video_out_xv.c:1336
-msgid ""
-"video_out_xv: Xv extension is present but I couldn't find a usable yuv12 "
-"port.\n"
-" Looks like your graphics hardware driver doesn't support Xv?!\n"
-msgstr ""
-"video_out_xv: estensione XV presente ma non è stato possibile trovare una "
-"porta yuv12 utilizzabile. sembrerebbe che l'hardware grafico "
-"non supporti Xv.\n"
-
-#: src/video_out/video_out_xv.c:1345
-#, c-format
+#: src/video_out/video_out_xv.c:1348 src/video_out/video_out_xxmc.c:2330
+#, fuzzy, c-format
msgid ""
-"video_out_xv: using Xv port %ld from adaptor %s for hardware colorspace "
-"conversion and scaling.\n"
+"%s: using Xv port %ld from adaptor %s for hardware colorspace conversion and "
+"scaling.\n"
msgstr ""
"video_out_xv: utilizzando la porta Xv %ld dal dispositivo %s per la "
"conversione di colori e il ridimensionamento hardware.\n"
-#: src/video_out/video_out_xv.c:1520
-msgid "video_out_xv: this adaptor supports the yv12 format.\n"
-msgstr "video_out_xv: questo dispositivo supporta il formato yv12\n"
-
-#: src/video_out/video_out_xv.c:1525
-msgid "video_out_xv: this adaptor supports the yuy2 format.\n"
-msgstr "video_out_xv: questo dispositivo supporta il formato yuv2.\n"
-
#: src/video_out/video_out_xvmc.c:1593
msgid "xine video output plugin using the XvMC X video extension"
msgstr "plugin di output video per xine utilizzante l'estensione X video XvMC"
@@ -4766,76 +4645,11 @@ msgstr " nessun supporto XvMC \n"
msgid " With Overlay = %d; UnsignedIntra = %d.\n"
msgstr " Con overlay = %d; UnsignedIntra = %d.\n"
-#: src/video_out/video_out_xxmc.c:650
-msgid ""
-"video_out_xxmc: XvShmCreateImage failed\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xxmc: XvShmCreateImage fallita.\n"
-"video_out_xxmc: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
-
-#: src/video_out/video_out_xxmc.c:660
-msgid ""
-"video_out_xxmc: XvShmCreateImage returned a zero size\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xxmc: XvShmCreateImage ha restituito una dimensione pari a zero.\n"
-"video_out_xxmc: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
-
-#: src/video_out/video_out_xxmc.c:668
-#, c-format
-msgid ""
-"video_out_xxmc: shared memory error in shmget: %s\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xxmc: errore nella memoria condivisa in shmget: %s\n"
-"video_out_xxmc: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
-
-#: src/video_out/video_out_xxmc.c:700
-msgid ""
-"video_out_xxmc: x11 error during shared memory XImage creation\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xxmc: errore X11 durante la creazione dell'oggetto XImage in "
-"memoria condivisa.\n"
-"video_out_xxmc: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
-
-#: src/video_out/video_out_xxmc.c:2287
-msgid "video_out_xxmc: Xv extension not present.\n"
-msgstr "video_out_xxmc: estensione Xv non presente.\n"
-
-#: src/video_out/video_out_xxmc.c:2324
-msgid ""
-"video_out_xxmc: Xv extension is present but I couldn't find a usable yuv12 "
-"port.\n"
-" Looks like your graphics hardware driver doesn't support Xv?!\n"
-msgstr ""
-"video_out_xmmc: estensione XV presente ma non è stato possibile trovare una "
-"porta yuv12 utilizzabile. sembrerebbe che l'hardware grafico "
-"non supporti Xv.\n"
-
-#: src/video_out/video_out_xxmc.c:2333
-#, c-format
-msgid ""
-"video_out_xxmc: using Xv port %ld from adaptor %s for hardware colorspace "
-"conversion and scaling.\n"
-msgstr ""
-"video_out_xxmc: utilizzando la porta Xv %ld dal dispositivo %s per la "
-"conversione di colori e il ridimensionamento hardware.\n"
-
-#: src/video_out/video_out_xxmc.c:2509
-msgid "video_out_xxmc: this adaptor supports the yv12 format.\n"
-msgstr "video_out_xxmc: questo dispositivo supporta il formato yv12\n"
-
-#: src/video_out/video_out_xxmc.c:2514
-msgid "video_out_xxmc: this adaptor supports the yuy2 format.\n"
-msgstr "video_out_xxmc: questo dispositivo supporta il formato yuv2.\n"
-
-#: src/video_out/video_out_xxmc.c:2543
+#: src/video_out/video_out_xxmc.c:2540
msgid "Make XvMC allocate more frames for better buffering."
msgstr "Fa sì che XvMC riservi più frame per un miglior buffer."
-#: src/video_out/video_out_xxmc.c:2544
+#: src/video_out/video_out_xxmc.c:2541
msgid ""
"Some XvMC implementations allow more than 8 frames.\n"
"This option, when turned on, makes the driver try to\n"
@@ -4845,11 +4659,11 @@ msgstr ""
"Questa opzione, quando abilitata, fa sì che il drive tenti\n"
"di riservare 15 frame. Necessario per unichrom e VDR istantanei.\n"
-#: src/video_out/video_out_xxmc.c:2550
+#: src/video_out/video_out_xxmc.c:2547
msgid "Unichrome cpu save"
msgstr "Risparmio CPU Unichrome"
-#: src/video_out/video_out_xxmc.c:2551
+#: src/video_out/video_out_xxmc.c:2548
msgid ""
"Saves CPU time by sleeping while decoder works.\n"
"Only for Linux kernel 2.6 series or 2.4 with multimedia patch.\n"
@@ -4859,11 +4673,11 @@ msgstr ""
"Solo per kernel Linux 2.6 o 2.4 con patch multimediale.\n"
"Sperimentale.\n"
-#: src/video_out/video_out_xxmc.c:2557
+#: src/video_out/video_out_xxmc.c:2554
msgid "Fix buggy NVIDIA XvMC subpicture colors"
msgstr "Correggi i colori dei sottotitoli difettosi su NVIDIA XvMC"
-#: src/video_out/video_out_xxmc.c:2558
+#: src/video_out/video_out_xxmc.c:2555
msgid ""
"There's a bug in NVIDIA's XvMC lib that makes red OSD colors\n"
"look blue and vice versa. This option provides a workaround.\n"
@@ -4871,11 +4685,11 @@ msgstr ""
"C'è un errore nella libreria XvMC NVIDIA che rende i colori rossi dell'OSD "
"blu e viceversa. Questa opzione fornisce un workaround.\n"
-#: src/video_out/video_out_xxmc.c:2563
+#: src/video_out/video_out_xxmc.c:2560
msgid "Use bob as accelerated deinterlace method."
msgstr "Utilizza bob come metodo di deinterlacciamento accelerato."
-#: src/video_out/video_out_xxmc.c:2564
+#: src/video_out/video_out_xxmc.c:2561
msgid ""
"When interlacing is enabled for hardware accelerated frames,\n"
"Alternate between top and bottom field at double the frame rate.\n"
@@ -5164,12 +4978,12 @@ msgstr ""
"info_helper: conversione %s -> UTF-8 non supportata, nessuna conversione "
"eseguita\n"
-#: src/xine-engine/input_cache.c:167
+#: src/xine-engine/input_cache.c:171
#, c-format
msgid ": open() function should never be called\n"
msgstr ": la funzione open() non dovrebbe mai essere chiamata.\n"
-#: src/xine-engine/input_cache.c:349
+#: src/xine-engine/input_cache.c:353
#, c-format
msgid ": input plugin not defined!\n"
msgstr ": plugin di ingresso non definito!\n"
@@ -5284,12 +5098,12 @@ msgstr "io_helper: File non trovato\n"
msgid "io_helper: Connection Refused\n"
msgstr "io_helper: Connessionr rifiutata\n"
-#: src/xine-engine/load_plugins.c:212
+#: src/xine-engine/load_plugins.c:215
#, c-format
msgid "map_decoder_list: no space for decoder, skipped.\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:327
+#: src/xine-engine/load_plugins.c:330
#, c-format
msgid ""
"load_plugins: ignoring plugin %s, wrong iface version %d (should be %d)\n"
@@ -5297,12 +5111,12 @@ msgstr ""
"load_plugins: plugin %s ignorato, versione di interfaccia %d errata "
"(dovrebbe essere %d)\n"
-#: src/xine-engine/load_plugins.c:384
+#: src/xine-engine/load_plugins.c:387
#, c-format
msgid "priority for %s decoder"
msgstr "priorità per il decoder %s"
-#: src/xine-engine/load_plugins.c:395
+#: src/xine-engine/load_plugins.c:398
msgid ""
"The priority provides a ranking in case some media can be handled by more "
"than one decoder.\n"
@@ -5312,7 +5126,7 @@ msgstr ""
"contenuto possa essere gestito da più di un decoder.\n"
"Una priorità pari a 0 abilita la priorità predefinita del decoder."
-#: src/xine-engine/load_plugins.c:423
+#: src/xine-engine/load_plugins.c:426
#, c-format
msgid ""
"load_plugins: demuxer plugin %s does not provide a priority, xine-lib will "
@@ -5321,7 +5135,7 @@ msgstr ""
"load_plugins: il plugin demuxer %s non fornisce una priorità, xine-lib "
"utilizzerà la priorità predefinita.\n"
-#: src/xine-engine/load_plugins.c:440
+#: src/xine-engine/load_plugins.c:443
#, c-format
msgid ""
"load_plugins: input plugin %s does not provide a priority, xine-lib will use "
@@ -5330,46 +5144,46 @@ msgstr ""
"load_plugins: il plugin di ingresso %s non fornisce una priorità, xine-lib "
"utilizzerà la priorità predefinita.\n"
-#: src/xine-engine/load_plugins.c:496
+#: src/xine-engine/load_plugins.c:499
#, c-format
msgid "load_plugins: plugin %s found\n"
msgstr "load_plugins: trovato plugin %s\n"
-#: src/xine-engine/load_plugins.c:499
+#: src/xine-engine/load_plugins.c:502
#, fuzzy, c-format
msgid "load_plugins: static plugin found\n"
msgstr "load_plugins: trovato plugin statico %s\n"
-#: src/xine-engine/load_plugins.c:506
+#: src/xine-engine/load_plugins.c:509
#, c-format
msgid "load_plugins: plugin limit reached, %s could not be loaded\n"
msgstr ""
"load_plugins: raggiunto il limite di plugin, non è stato possibile caricare %"
"s.\n"
-#: src/xine-engine/load_plugins.c:509
+#: src/xine-engine/load_plugins.c:512
#, c-format
msgid "load_plugins: plugin limit reached, static plugin could not be loaded\n"
msgstr ""
"load_plugins: raggiunto il limite di plugin, non è stato possibile caricare "
"il plugin statico.\n"
-#: src/xine-engine/load_plugins.c:526
+#: src/xine-engine/load_plugins.c:529
#, c-format
msgid "load_plugins: unknown plugin type %d in %s\n"
msgstr "load_plugins: tipo del plugin sconosciuto %d in %s\n"
-#: src/xine-engine/load_plugins.c:530
+#: src/xine-engine/load_plugins.c:533
#, c-format
msgid "load_plugins: unknown statically linked plugin type %d\n"
msgstr "load_plugins: tipo del plugin statico sconosciuto %d\n"
-#: src/xine-engine/load_plugins.c:590
+#: src/xine-engine/load_plugins.c:593
#, c-format
msgid "load_plugins: unable to stat %s\n"
msgstr "load_plugins: impossibile individuare %s\n"
-#: src/xine-engine/load_plugins.c:631
+#: src/xine-engine/load_plugins.c:634
#, c-format
msgid ""
"load_plugins: cannot open plugin lib %s:\n"
@@ -5378,7 +5192,7 @@ msgstr ""
"load_plugins: impossibile aprire la libreria plugin %s:\n"
"%s\n"
-#: src/xine-engine/load_plugins.c:646
+#: src/xine-engine/load_plugins.c:649
#, c-format
msgid ""
"load_plugins: can't get plugin info from %s:\n"
@@ -5387,12 +5201,12 @@ msgstr ""
"load_plugins: non ottengo informazioni del plugin da %s:\n"
"%s\n"
-#: src/xine-engine/load_plugins.c:664
+#: src/xine-engine/load_plugins.c:667
#, c-format
msgid "load_plugins: skipping unreadable plugin directory %s.\n"
msgstr "load_plugins: directory %s illeggibile ignorata.\n"
-#: src/xine-engine/load_plugins.c:713
+#: src/xine-engine/load_plugins.c:716
#, c-format
msgid ""
"load_plugins: cannot (stage 2) open plugin lib %s:\n"
@@ -5401,27 +5215,32 @@ msgstr ""
"load_plugins: impossibile aprire la libreria plugin %s (stadio 2):\n"
"%s\n"
-#: src/xine-engine/load_plugins.c:739
+#: src/xine-engine/load_plugins.c:742
#, c-format
msgid "load_plugins: Yikes! %s doesn't contain plugin info.\n"
msgstr "load_plugins: Argh! %s non contiene informazioni plugin.\n"
-#: src/xine-engine/load_plugins.c:1305
+#: src/xine-engine/load_plugins.c:1104 src/xine-engine/load_plugins.c:1113
+#, fuzzy, c-format
+msgid "Unable to create %s directory: %s\n"
+msgstr "Impossibile creare l'oggetto DirectSound."
+
+#: src/xine-engine/load_plugins.c:1345
#, c-format
msgid "load_plugins: unknown content detection strategy %d\n"
msgstr "load_plugins: strategia di riconoscimento contenuto sconosciuta %d\n"
-#: src/xine-engine/load_plugins.c:1415
+#: src/xine-engine/load_plugins.c:1455
#, c-format
msgid "load_plugins: using demuxer '%s'\n"
msgstr "load_plugins: utilizzo del demuxer '%s'\n"
-#: src/xine-engine/load_plugins.c:1726
+#: src/xine-engine/load_plugins.c:1766
#, c-format
msgid "load_plugins: failed to load audio output plugin <%s>\n"
msgstr "load_plugins: caricamento del plugin output audio fallito <%s>\n"
-#: src/xine-engine/load_plugins.c:1729
+#: src/xine-engine/load_plugins.c:1769
msgid ""
"load_plugins: audio output auto-probing didn't find any usable audio "
"driver.\n"
@@ -5429,7 +5248,7 @@ msgstr ""
"load_plugins: il riconoscimento automatico dell'output audio non ha trovato "
"alcun driver audio utilizzabile.\n"
-#: src/xine-engine/load_plugins.c:2033
+#: src/xine-engine/load_plugins.c:2073
#, c-format
msgid ""
"load_plugins: cannot unload plugin lib %s:\n"
@@ -5438,31 +5257,27 @@ msgstr ""
"load_plugins: impossibile rimuovere la libreria plugin %s:\n"
"%s\n"
-#: src/xine-engine/osd.c:745
+#: src/xine-engine/osd.c:747
#, c-format
msgid "font '%s-%d' already loaded, weird.\n"
msgstr "il carattere '%s-%d' è già caricato, strano.\n"
-#: src/xine-engine/osd.c:757
+#: src/xine-engine/osd.c:759
#, c-format
msgid "font '%s' loading failed (%d < %d)\n"
msgstr "caricamento del carattere '%s' fallito (%d < %d)\n"
-#: src/xine-engine/osd.c:767
+#: src/xine-engine/osd.c:769
#, c-format
msgid "wrong version for font '%s'. expected %d found %d.\n"
msgstr "versione del font '%s' errata. Richiesto %d trovato %d.\n"
-#: src/xine-engine/osd.c:834
-msgid "osd: cannot initialize ft2 library\n"
-msgstr "osd: impossibile inizializzare la libreria ft2\n"
-
-#: src/xine-engine/osd.c:857
+#: src/xine-engine/osd.c:856
#, fuzzy, c-format
msgid "osd: error matching font %s with FontConfig"
msgstr "osd: errore nel caricamento del carattere %s con ft2\n"
-#: src/xine-engine/osd.c:871
+#: src/xine-engine/osd.c:870
#, fuzzy, c-format
msgid "osd: error loading font %s with FontConfig"
msgstr "osd: errore nel caricamento del carattere %s con ft2\n"
@@ -5472,18 +5287,22 @@ msgstr "osd: errore nel caricamento del carattere %s con ft2\n"
msgid "osd: error looking up font %s with FontConfig"
msgstr "osd: errore nel caricamento del carattere %s con ft2\n"
-#: src/xine-engine/osd.c:895
-#, c-format
-msgid "osd: error loading font %s with ft2\n"
+#: src/xine-engine/osd.c:914
+#, fuzzy, c-format
+msgid "osd: error loading font %s with in XDG data directories.\n"
msgstr "osd: errore nel caricamento del carattere %s con ft2\n"
-#: src/xine-engine/osd.c:905
+#: src/xine-engine/osd.c:923
+msgid "osd: cannot initialize ft2 library\n"
+msgstr "osd: impossibile inizializzare la libreria ft2\n"
+
+#: src/xine-engine/osd.c:945
msgid "osd: error setting font size (no scalable font?)\n"
msgstr ""
"osd: errore impostando la dimensione del carattere (nessun carattere "
"scalabile?)\n"
-#: src/xine-engine/osd.c:1021
+#: src/xine-engine/osd.c:1061
#, c-format
msgid ""
"osd: unknown sequence starting with byte 0x%02X in encoding \"%s\", "
@@ -5492,43 +5311,43 @@ msgstr ""
"osd: sequenza sconosciuta cominciante con byte 0x%02X nella codifica \"%s\", "
"ignorata.\n"
-#: src/xine-engine/osd.c:1077
+#: src/xine-engine/osd.c:1117
msgid "osd: can't find out current locale character set\n"
msgstr "osd: impossibile individuare il set di caratteri locale corrente.\n"
-#: src/xine-engine/osd.c:1087
+#: src/xine-engine/osd.c:1127
#, c-format
msgid "osd: unsupported conversion %s -> %s, no conversion performed\n"
msgstr ""
"osd: conversione %s -> %s non supportata, nessuna conversione eseguita\n"
-#: src/xine-engine/osd.c:1142 src/xine-engine/osd.c:1310
+#: src/xine-engine/osd.c:1182 src/xine-engine/osd.c:1350
msgid "osd: font isn't defined\n"
msgstr "osd: carattere non definito.\n"
-#: src/xine-engine/osd.c:1181
+#: src/xine-engine/osd.c:1221
msgid "osd: error loading glyph\n"
msgstr "osd: errore nel caricamento del glifo.\n"
-#: src/xine-engine/osd.c:1187
+#: src/xine-engine/osd.c:1227
msgid "osd: error in rendering glyph\n"
msgstr "osd: errore nella visualizzazione del glifo.\n"
-#: src/xine-engine/osd.c:1347
+#: src/xine-engine/osd.c:1387
#, c-format
msgid "osd: error loading glyph %i\n"
msgstr "osd: errore nel caricamento del glifo %i.\n"
-#: src/xine-engine/osd.c:1354
+#: src/xine-engine/osd.c:1394
msgid "osd: error in rendering\n"
msgstr "osd: errore nella visualizzazione.\n"
-#: src/xine-engine/osd.c:1611
+#: src/xine-engine/osd.c:1660
msgid "palette (foreground-border-background) to use for subtitles and OSD"
msgstr ""
"palette (primo piano-bordo-sfondo) da utilizzare per i sottotitoli e OSD"
-#: src/xine-engine/osd.c:1612
+#: src/xine-engine/osd.c:1661
msgid ""
"The palette for on-screen-display and some subtitle formats that do not "
"specify any colouring themselves. The palettes are listed in the form: "
@@ -5673,131 +5492,131 @@ msgstr ""
"driver di uscita video come XShm, dove il ridimensionamento non è accelerato "
"in hardware, questo può ridurre drasticamente l'uso di CPU."
-#: src/xine-engine/xine.c:704 src/xine-engine/xine.c:811
-#: src/xine-engine/xine.c:850 src/xine-engine/xine.c:886
-#: src/xine-engine/xine.c:898 src/xine-engine/xine.c:911
-#: src/xine-engine/xine.c:924 src/xine-engine/xine.c:937
-#: src/xine-engine/xine.c:963 src/xine-engine/xine.c:988
-#: src/xine-engine/xine.c:1023
+#: src/xine-engine/xine.c:706 src/xine-engine/xine.c:813
+#: src/xine-engine/xine.c:852 src/xine-engine/xine.c:888
+#: src/xine-engine/xine.c:900 src/xine-engine/xine.c:913
+#: src/xine-engine/xine.c:926 src/xine-engine/xine.c:939
+#: src/xine-engine/xine.c:965 src/xine-engine/xine.c:990
+#: src/xine-engine/xine.c:1025
msgid "xine: error while parsing mrl\n"
msgstr "xine: errore durante l'interpretazione del MRL\n"
-#: src/xine-engine/xine.c:740
+#: src/xine-engine/xine.c:742
#, c-format
msgid "xine: found input plugin : %s\n"
msgstr "xine: plugin di ingresso trovato : %s\n"
-#: src/xine-engine/xine.c:758
+#: src/xine-engine/xine.c:760
#, c-format
msgid "xine: input plugin cannot open MRL [%s]\n"
msgstr "xine: il plugin di ingresso non può aprire il MRL [%s]\n"
-#: src/xine-engine/xine.c:774
+#: src/xine-engine/xine.c:776
#, c-format
msgid "xine: cannot find input plugin for MRL [%s]\n"
msgstr "xine: impossibile trovare il plugin di ingresso per il MRL [%s]\n"
-#: src/xine-engine/xine.c:800
+#: src/xine-engine/xine.c:802
#, c-format
msgid "xine: specified demuxer %s failed to start\n"
msgstr "xine: l'avvio del demuxer %s specificato è fallito.\n"
-#: src/xine-engine/xine.c:836
+#: src/xine-engine/xine.c:838
#, c-format
msgid "xine: join rip input plugin\n"
msgstr "xine: avvio del plugin di estrazione.\n"
-#: src/xine-engine/xine.c:843
+#: src/xine-engine/xine.c:845
msgid "xine: error opening rip input plugin instance\n"
msgstr "xine: errore nell'avvio del plugin di estrazione.\n"
-#: src/xine-engine/xine.c:874
+#: src/xine-engine/xine.c:876
#, c-format
msgid "xine: last_probed demuxer %s failed to start\n"
msgstr "xine: l'avvio dell'ultimo demuxer provato %s è fallito.\n"
-#: src/xine-engine/xine.c:903
+#: src/xine-engine/xine.c:905
msgid "ignoring video\n"
msgstr "video ignorato\n"
-#: src/xine-engine/xine.c:916
+#: src/xine-engine/xine.c:918
msgid "ignoring audio\n"
msgstr "audio ignorato\n"
-#: src/xine-engine/xine.c:929
+#: src/xine-engine/xine.c:931
msgid "ignoring subpicture\n"
msgstr "sottotitoli ignorati\n"
-#: src/xine-engine/xine.c:942
+#: src/xine-engine/xine.c:944
msgid "input cache plugin disabled\n"
msgstr "plugin cache d'ingresso disattivato.\n"
-#: src/xine-engine/xine.c:1013
+#: src/xine-engine/xine.c:1015
#, c-format
msgid "subtitle mrl opened '%s'\n"
msgstr "aperto il MRL sottotitoli '%s'\n"
-#: src/xine-engine/xine.c:1017
+#: src/xine-engine/xine.c:1019
msgid "xine: error opening subtitle mrl\n"
msgstr "xine: errore nell'apertura del MRL dei sottotitoli.\n"
-#: src/xine-engine/xine.c:1049
+#: src/xine-engine/xine.c:1051
#, c-format
msgid "xine: error while parsing MRL\n"
msgstr "xine: errore nell'interpretazione del MRL.\n"
-#: src/xine-engine/xine.c:1056
+#: src/xine-engine/xine.c:1058
#, c-format
msgid "xine: changing option '%s' from MRL isn't permitted\n"
msgstr "xine: modificare l'opzione '%s' da MRL non è consentito.\n"
-#: src/xine-engine/xine.c:1076
+#: src/xine-engine/xine.c:1078
#, c-format
msgid "xine: couldn't find demux for >%s<\n"
msgstr "xine: impossibile trovare il demuxer per >%s<\n"
-#: src/xine-engine/xine.c:1092
+#: src/xine-engine/xine.c:1094
#, c-format
msgid "xine: found demuxer plugin: %s\n"
msgstr "xine: trovato plugin demuxer: %s\n"
-#: src/xine-engine/xine.c:1112
+#: src/xine-engine/xine.c:1114
#, c-format
msgid "xine: demuxer failed to start\n"
msgstr "xine: avvio del demuxer fallito.\n"
-#: src/xine-engine/xine.c:1177
+#: src/xine-engine/xine.c:1179
#, c-format
msgid "xine_play: no demux available\n"
msgstr "xine_play: nessun demux disponibile\n"
-#: src/xine-engine/xine.c:1247
+#: src/xine-engine/xine.c:1249
#, c-format
msgid "xine_play: demux failed to start\n"
msgstr "xine: avvio del demuxer fallito.\n"
-#: src/xine-engine/xine.c:1523
+#: src/xine-engine/xine.c:1527
#, c-format
msgid "xine: The specified save_dir \"%s\" might be a security risk.\n"
msgstr ""
"xine: La directory di salvataggio specificata \"%s\" potrebbe essere un "
"rischio per la sicurezza.\n"
-#: src/xine-engine/xine.c:1528
+#: src/xine-engine/xine.c:1532
msgid "The specified save_dir might be a security risk."
msgstr ""
"La directory di salvataggio specificata potrebbe essere un rischio per la "
"sicurezza."
-#: src/xine-engine/xine.c:1554
+#: src/xine-engine/xine.c:1561
msgid "xine: locale not supported by C library\n"
msgstr "xine: locale non supportarto dalla liberaria C\n"
-#: src/xine-engine/xine.c:1563
+#: src/xine-engine/xine.c:1570
msgid "media format detection strategy"
msgstr "Strategia di riconoscimento del formato di contenuto"
-#: src/xine-engine/xine.c:1564
+#: src/xine-engine/xine.c:1571
msgid ""
"xine offers various methods to detect the media format of input to play. The "
"individual values are:\n"
@@ -5831,11 +5650,11 @@ msgstr ""
"extension\n"
"Riconosce solo tramite estensione del file.\n"
-#: src/xine-engine/xine.c:1582
+#: src/xine-engine/xine.c:1589
msgid "directory for saving streams"
msgstr "Cartella di salvataggio degli stream"
-#: src/xine-engine/xine.c:1583
+#: src/xine-engine/xine.c:1590
msgid ""
"When using the stream save feature, files will be written only into this "
"directory.\n"
@@ -5851,12 +5670,12 @@ msgstr ""
"arbitrario. Per questo si deve essere attenti che la directory che si "
"specifica sia robusta per qualsiasi contenuto di ogni file."
-#: src/xine-engine/xine.c:1594
+#: src/xine-engine/xine.c:1601
msgid "allow implicit changes to the configuration (e.g. by MRL)"
msgstr ""
"permetti modifiche implicite alla configurazione (per esmepio tramite MRL)"
-#: src/xine-engine/xine.c:1595
+#: src/xine-engine/xine.c:1602
msgid ""
"If enabled, you allow xine to change your configuration without explicit "
"actions from your side. For example configuration changes demanded by MRLs "
@@ -5873,26 +5692,26 @@ msgstr ""
"arbitrariamente la propria configurazione si può finire con uno xine "
"completamente caotico."
-#: src/xine-engine/xine.c:1609
+#: src/xine-engine/xine.c:1616
msgid "Timeout for network stream reading (in seconds)"
msgstr ""
-#: src/xine-engine/xine.c:1610
+#: src/xine-engine/xine.c:1617
msgid ""
"Specifies the timeout when reading from network streams, in seconds. Too low "
"values might stop streaming when the source is slow or the bandwidth is "
"occupied, too high values will freeze the player if the connection is lost."
msgstr ""
-#: src/xine-engine/xine.c:1962
+#: src/xine-engine/xine.c:1969
msgid "messages"
msgstr "messaggi"
-#: src/xine-engine/xine.c:1963
+#: src/xine-engine/xine.c:1970
msgid "plugin"
msgstr "plugin"
-#: src/xine-engine/xine.c:1964
+#: src/xine-engine/xine.c:1971
msgid "trace"
msgstr "traccia"
@@ -5965,3 +5784,249 @@ msgstr ""
#: src/xine-utils/memcpy.c:507
msgid "Benchmarking memcpy methods (smaller is better):\n"
msgstr "Test di velocità dei metodi memcpy (più piccolo è migliore):\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xcbshm: %s: allocating image\n"
+#~ "video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xshm: %s: riservando l'immagine\n"
+#~ "video_out_xshm: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xcbshm: shared memory error (address error) when allocating "
+#~ "image \n"
+#~ "video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xshm: errore nella memoria condivisa (errore d'indirizzo) "
+#~ "riservando l'immagine \n"
+#~ "video_out_xshm: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xcbshm: x11 error during shared memory XImage creation\n"
+#~ "video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_Out_xshm: errore X11 durante la creazione dell'oggetto XImage "
+#~ "condiviso\n"
+#~ "video_out_xshm: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xcbshm: MIT shared memory extension not present on display.\n"
+#~ msgstr ""
+#~ "video_out_xshm: l'estensione MIT Shared Meory non è presente sul "
+#~ "display.\n"
+
+#, fuzzy
+#~ msgid "video_out_xcbshm: your video mode was not recognized, sorry :-(\n"
+#~ msgstr "video_out_xshm: modalità video non riconosciuta.\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xcbxv: XvShmCreateImage returned a zero size\n"
+#~ "video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xv: XvShmCreateImage ha restituito una dimensione pari a zero.\n"
+#~ "video_out_xv: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xcbxv: shared memory error in shmget: %s\n"
+#~ "video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xv: errore nella memoria condivisa in shmget: %s\n"
+#~ "video_out_xv: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xcbxv: x11 error during shared memory XImage creation\n"
+#~ "video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xv: errore X11 durante la creazione dell'oggetto XImage in "
+#~ "memoria condivisa.\n"
+#~ "video_out_xv: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
+
+#, fuzzy
+#~ msgid "video_out_xcbxv: Xv extension not present.\n"
+#~ msgstr "video_out_xv: estensione Xv non presente.\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xcbxv: Xv extension is present but I couldn't find a usable "
+#~ "yuv12 port.\n"
+#~ " Looks like your graphics hardware driver doesn't support "
+#~ "Xv?!\n"
+#~ msgstr ""
+#~ "video_out_xv: estensione XV presente ma non è stato possibile trovare una "
+#~ "porta yuv12 utilizzabile. sembrerebbe che l'hardware "
+#~ "grafico non supporti Xv.\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xcbxv: using Xv port %d from adaptor %s for hardware colorspace "
+#~ "conversion and scaling.\n"
+#~ msgstr ""
+#~ "video_out_xv: utilizzando la porta Xv %ld dal dispositivo %s per la "
+#~ "conversione di colori e il ridimensionamento hardware.\n"
+
+#, fuzzy
+#~ msgid "video_out_xcbxv: this adaptor supports the yv12 format.\n"
+#~ msgstr "video_out_xv: questo dispositivo supporta il formato yv12\n"
+
+#, fuzzy
+#~ msgid "video_out_xcbxv: this adaptor supports the yuy2 format.\n"
+#~ msgstr "video_out_xv: questo dispositivo supporta il formato yuv2.\n"
+
+#~ msgid ""
+#~ "video_out_xshm: shared memory error when allocating image\n"
+#~ "video_out_xshm: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xshm: errore nella memoria condivisa riservando l'immagine:\n"
+#~ "video_out_xshm: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
+
+#~ msgid ""
+#~ "video_out_xshm: %s: allocating image\n"
+#~ "video_out_xshm: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xshm: %s: riservando l'immagine\n"
+#~ "video_out_xshm: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
+
+#~ msgid ""
+#~ "video_out_xshm: x11 error during shared memory XImage creation\n"
+#~ "video_out_xshm: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_Out_xshm: errore X11 durante la creazione dell'oggetto XImage "
+#~ "condiviso\n"
+#~ "video_out_xshm: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
+
+#~ msgid "video_out_xshm: your video mode was not recognized, sorry :-(\n"
+#~ msgstr "video_out_xshm: modalità video non riconosciuta.\n"
+
+#~ msgid ""
+#~ "video_out_xv: XvShmCreateImage failed\n"
+#~ "video_out_xv: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xv: XvShmCreateImage fallita.\n"
+#~ "video_out_xv: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
+
+#~ msgid ""
+#~ "video_out_xv: XvShmCreateImage returned a zero size\n"
+#~ "video_out_xv: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xv: XvShmCreateImage ha restituito una dimensione pari a zero.\n"
+#~ "video_out_xv: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
+
+#~ msgid ""
+#~ "video_out_xv: shared memory error in shmget: %s\n"
+#~ "video_out_xv: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xv: errore nella memoria condivisa in shmget: %s\n"
+#~ "video_out_xv: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
+
+#~ msgid ""
+#~ "video_out_xv: x11 error during shared memory XImage creation\n"
+#~ "video_out_xv: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xv: errore X11 durante la creazione dell'oggetto XImage in "
+#~ "memoria condivisa.\n"
+#~ "video_out_xv: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
+
+#~ msgid ""
+#~ "video_out_xxmc: XvShmCreateImage failed\n"
+#~ "video_out_xxmc: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xxmc: XvShmCreateImage fallita.\n"
+#~ "video_out_xxmc: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
+
+#~ msgid ""
+#~ "video_out_xxmc: XvShmCreateImage returned a zero size\n"
+#~ "video_out_xxmc: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xxmc: XvShmCreateImage ha restituito una dimensione pari a "
+#~ "zero.\n"
+#~ "video_out_xxmc: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
+
+#~ msgid ""
+#~ "video_out_xxmc: shared memory error in shmget: %s\n"
+#~ "video_out_xxmc: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xxmc: errore nella memoria condivisa in shmget: %s\n"
+#~ "video_out_xxmc: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
+
+#~ msgid ""
+#~ "video_out_xxmc: x11 error during shared memory XImage creation\n"
+#~ "video_out_xxmc: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xxmc: errore X11 durante la creazione dell'oggetto XImage in "
+#~ "memoria condivisa.\n"
+#~ "video_out_xxmc: => l'estensione MIT Shared Memory non sarà utilizzata.\n"
+
+#~ msgid "video_out_xxmc: Xv extension not present.\n"
+#~ msgstr "video_out_xxmc: estensione Xv non presente.\n"
+
+#~ msgid ""
+#~ "video_out_xxmc: Xv extension is present but I couldn't find a usable "
+#~ "yuv12 port.\n"
+#~ " Looks like your graphics hardware driver doesn't support "
+#~ "Xv?!\n"
+#~ msgstr ""
+#~ "video_out_xmmc: estensione XV presente ma non è stato possibile trovare "
+#~ "una porta yuv12 utilizzabile. sembrerebbe che l'hardware "
+#~ "grafico non supporti Xv.\n"
+
+#~ msgid ""
+#~ "video_out_xxmc: using Xv port %ld from adaptor %s for hardware colorspace "
+#~ "conversion and scaling.\n"
+#~ msgstr ""
+#~ "video_out_xxmc: utilizzando la porta Xv %ld dal dispositivo %s per la "
+#~ "conversione di colori e il ridimensionamento hardware.\n"
+
+#~ msgid "video_out_xxmc: this adaptor supports the yv12 format.\n"
+#~ msgstr "video_out_xxmc: questo dispositivo supporta il formato yv12\n"
+
+#~ msgid "video_out_xxmc: this adaptor supports the yuy2 format.\n"
+#~ msgstr "video_out_xxmc: questo dispositivo supporta il formato yuv2.\n"
+
+#~ msgid "CDDB cache directory"
+#~ msgstr "directory cache CDDB"
+
+#~ msgid ""
+#~ "The replies from the CDDB server will be cached in this directory.\n"
+#~ "This setting is security critical, because files with uncontrollable "
+#~ "names will be created in this directory. Be sure to use a dedicated "
+#~ "directory not used for anything but CDDB caching."
+#~ msgstr ""
+#~ "Le risposte dal server CDDB saranno salvate in questa directory.\n"
+#~ "Questa impostazione è critica, perché in questa directory saranno creati "
+#~ "file con nomi incontrollati. Assicurative di utilizzare una directory "
+#~ "dedicata non utilizzata per altro oltre al caching CDDB. "
+
+#~ msgid "path to the title key cache"
+#~ msgstr "percorso alla cache delle chiavi dei titoli"
+
+#~ msgid ""
+#~ "Since cracking the copy protection of scrambled DVDs can be quite time "
+#~ "consuming, libdvdcss will cache the cracked keys in this directory.\n"
+#~ "This setting is security critical, because files with uncontrollable "
+#~ "names will be created in this directory. Be sure to use a dedicated "
+#~ "directory not used for anything but DVD key caching."
+#~ msgstr ""
+#~ "Poiché rompere la protezione da copia dei DVD cifrati può richiedere "
+#~ "diverso tempo, libdvdcss memorizzerà le chiavi decifrate in questa "
+#~ "directory.\n"
+#~ "Questa impostazione è critica, poiché file con nomi incontrollabili "
+#~ "saranno creati in questa directory. Assicuratevi di utilizzare una "
+#~ "directory dedicata non utilizzata per altri scopi oltre alla "
+#~ "memorizzazioni delle chiavi DVD."
+
+#~ msgid ""
+#~ "WARNING: video_out_fb: current display depth is %d. For better "
+#~ "performance\n"
+#~ " a depth of 16 bpp is recommended!\n"
+#~ "\n"
+#~ msgstr ""
+#~ "ATTENZIONE: video_out_fb: la profondità di colore corrente è %d.\n"
+#~ " per prestazioni migliori è raccomandata una profondità di 16bpp.\n"
+#~ "\n"
diff --git a/po/libxine1.pot b/po/libxine1.pot
index 9a9aebafc..58edd19bf 100644
--- a/po/libxine1.pot
+++ b/po/libxine1.pot
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: xine-devel@lists.sourceforge.net\n"
-"POT-Creation-Date: 2007-04-06 15:39+0200\n"
+"POT-Creation-Date: 2007-04-24 21:48+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -41,117 +41,117 @@ msgstr ""
msgid "Unknown error"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:354
+#: src/audio_out/audio_alsa_out.c:351
#, c-format
msgid "audio_alsa_out:Already open...WHY!"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:382
+#: src/audio_out/audio_alsa_out.c:379
#, c-format
msgid "audio_alsa_out: snd_pcm_open() of %s failed: %s\n"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:384
+#: src/audio_out/audio_alsa_out.c:381
msgid "audio_alsa_out: >>> check if another program already uses PCM <<<\n"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:397
+#: src/audio_out/audio_alsa_out.c:394
#, c-format
msgid ""
"audio_alsa_out: broken configuration for this PCM: no configurations "
"available: %s\n"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1289
+#: src/audio_out/audio_alsa_out.c:1286
msgid "notify changes to the hardware mixer"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1290
+#: src/audio_out/audio_alsa_out.c:1287
msgid ""
"When the hardware mixer changes, your application will receive a "
"notification so that it can update its graphical representation of the mixer "
"settings on the fly."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1355
+#: src/audio_out/audio_alsa_out.c:1352
#, c-format
msgid "snd_lib_error_set_handler() failed: %d"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1362
+#: src/audio_out/audio_alsa_out.c:1359
msgid "sound card can do mmap"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1363
+#: src/audio_out/audio_alsa_out.c:1360
msgid ""
"Enable this, if your sound card and alsa driver support memory mapped IO.\n"
"You can try enabling it and check, if everything works. If it does, this "
"will increase performance."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1372
+#: src/audio_out/audio_alsa_out.c:1369
msgid "device used for mono output"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1373
+#: src/audio_out/audio_alsa_out.c:1370
msgid ""
"xine will use this alsa device to output mono sound.\n"
"See the alsa documentation for information on alsa devices."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1381
+#: src/audio_out/audio_alsa_out.c:1378
msgid "device used for stereo output"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1382
+#: src/audio_out/audio_alsa_out.c:1379
msgid ""
"xine will use this alsa device to output stereo sound.\n"
"See the alsa documentation for information on alsa devices."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1390
+#: src/audio_out/audio_alsa_out.c:1387
msgid "device used for 4-channel output"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1391
+#: src/audio_out/audio_alsa_out.c:1388
msgid ""
"xine will use this alsa device to output 4 channel (4.0) surround sound.\n"
"See the alsa documentation for information on alsa devices."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1400 src/audio_out/audio_alsa_out.c:1410
+#: src/audio_out/audio_alsa_out.c:1397 src/audio_out/audio_alsa_out.c:1407
msgid "device used for 5.1-channel output"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1401
+#: src/audio_out/audio_alsa_out.c:1398
msgid ""
"xine will use this alsa device to output 5 channel plus LFE (5.1) surround "
"sound.\n"
"See the alsa documentation for information on alsa devices."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1411
+#: src/audio_out/audio_alsa_out.c:1408
msgid ""
"xine will use this alsa device to output undecoded digital surround sound. "
"This can be used be external surround decoders.\n"
"See the alsa documentation for information on alsa devices."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1431
+#: src/audio_out/audio_alsa_out.c:1428
#, c-format
msgid "snd_pcm_open() failed:%d:%s\n"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1433
+#: src/audio_out/audio_alsa_out.c:1430
#, c-format
msgid ">>> Check if another program already uses PCM <<<\n"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1464 src/audio_out/audio_oss_out.c:929
+#: src/audio_out/audio_alsa_out.c:1461 src/audio_out/audio_oss_out.c:929
msgid "speaker arrangement"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1465 src/audio_out/audio_oss_out.c:930
+#: src/audio_out/audio_alsa_out.c:1462 src/audio_out/audio_oss_out.c:930
msgid ""
"Select how your speakers are arranged, this determines which speakers xine "
"uses for sound output. The individual values are:\n"
@@ -183,85 +183,85 @@ msgid ""
"formats you want to play to your sound card's digital output."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1494
+#: src/audio_out/audio_alsa_out.c:1491
msgid "audio_alsa_out : supported modes are "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1497
+#: src/audio_out/audio_alsa_out.c:1494
msgid "8bit "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1502
+#: src/audio_out/audio_alsa_out.c:1499
msgid "16bit "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1506
+#: src/audio_out/audio_alsa_out.c:1503
msgid "24bit "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1510
+#: src/audio_out/audio_alsa_out.c:1507
msgid "32bit "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1521
+#: src/audio_out/audio_alsa_out.c:1518
msgid "mono "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1525
+#: src/audio_out/audio_alsa_out.c:1522
msgid "stereo "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1530
+#: src/audio_out/audio_alsa_out.c:1527
msgid "4-channel "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1533
+#: src/audio_out/audio_alsa_out.c:1530
msgid "(4-channel not enabled in xine config) "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1538
+#: src/audio_out/audio_alsa_out.c:1535
msgid "4.1-channel "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1541
+#: src/audio_out/audio_alsa_out.c:1538
msgid "(4.1-channel not enabled in xine config) "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1546
+#: src/audio_out/audio_alsa_out.c:1543
msgid "5-channel "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1549
+#: src/audio_out/audio_alsa_out.c:1546
msgid "(5-channel not enabled in xine config) "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1554
+#: src/audio_out/audio_alsa_out.c:1551
msgid "5.1-channel "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1557
+#: src/audio_out/audio_alsa_out.c:1554
msgid "(5.1-channel not enabled in xine config) "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1580
+#: src/audio_out/audio_alsa_out.c:1577
msgid "a/52 and DTS pass-through\n"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1583
+#: src/audio_out/audio_alsa_out.c:1580
msgid "(a/52 and DTS pass-through not enabled in xine config)\n"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1590
+#: src/audio_out/audio_alsa_out.c:1587
msgid "alsa mixer device"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1591
+#: src/audio_out/audio_alsa_out.c:1588
msgid ""
"xine will use this alsa mixer device to change the volume.\n"
"See the alsa documentation for information on alsa devices."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1665
+#: src/audio_out/audio_alsa_out.c:1662
msgid "xine audio output plugin using alsa-compliant audio devices/drivers"
msgstr ""
@@ -273,201 +273,201 @@ msgstr ""
msgid "xine output plugin for Coreaudio/Mac OS X"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:166
+#: src/audio_out/audio_directx2_out.c:163
msgid "Error"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:173
+#: src/audio_out/audio_directx2_out.c:170
msgid "success"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:175
+#: src/audio_out/audio_directx2_out.c:172
msgid "access denied"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:177
+#: src/audio_out/audio_directx2_out.c:174
msgid "resource is already in use"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:178
+#: src/audio_out/audio_directx2_out.c:175
msgid "object was already initialized"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:179
+#: src/audio_out/audio_directx2_out.c:176
msgid "specified wave format is not supported"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:180
+#: src/audio_out/audio_directx2_out.c:177
msgid "memory buffer has been lost and must be restored"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:181
+#: src/audio_out/audio_directx2_out.c:178
msgid "requested buffer control is not available"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:182
+#: src/audio_out/audio_directx2_out.c:179
msgid "undetermined error inside DirectSound subsystem"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:184
+#: src/audio_out/audio_directx2_out.c:181
msgid "DirectSound hardware device is unavailable"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:186
+#: src/audio_out/audio_directx2_out.c:183
msgid "function is not valid for the current state of the object"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:187
+#: src/audio_out/audio_directx2_out.c:184
msgid "invalid parameter was passed"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:188
+#: src/audio_out/audio_directx2_out.c:185
msgid "object doesn't support aggregation"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:189
+#: src/audio_out/audio_directx2_out.c:186
msgid "no sound driver available for use"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:190
+#: src/audio_out/audio_directx2_out.c:187
msgid "requested COM interface not available"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:191
+#: src/audio_out/audio_directx2_out.c:188
msgid "another application has a higher priority level"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:192
+#: src/audio_out/audio_directx2_out.c:189
msgid "insufficient memory"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:193
+#: src/audio_out/audio_directx2_out.c:190
msgid "low priority level for this function"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:194
+#: src/audio_out/audio_directx2_out.c:191
msgid "DirectSound wasn't initialized"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:195
+#: src/audio_out/audio_directx2_out.c:192
msgid "function is not supported"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:196
+#: src/audio_out/audio_directx2_out.c:193
msgid "unknown error"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:206
+#: src/audio_out/audio_directx2_out.c:203
#, c-format
msgid "Unable to create direct sound object."
msgstr ""
-#: src/audio_out/audio_directx2_out.c:212
+#: src/audio_out/audio_directx2_out.c:209
#, c-format
msgid "Could not set direct sound cooperative level."
msgstr ""
-#: src/audio_out/audio_directx2_out.c:286
+#: src/audio_out/audio_directx2_out.c:283
msgid "Unable to create secondary direct sound buffer"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:310
+#: src/audio_out/audio_directx2_out.c:307
#, c-format
msgid "Unable to create buffer position events."
msgstr ""
-#: src/audio_out/audio_directx2_out.c:318
+#: src/audio_out/audio_directx2_out.c:315
msgid "Unable to get notification interface"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:323
+#: src/audio_out/audio_directx2_out.c:320
msgid "Unable to set notification positions"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:343
+#: src/audio_out/audio_directx2_out.c:340
msgid "Couldn't play sound buffer"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:355
+#: src/audio_out/audio_directx2_out.c:352
msgid "Couldn't stop sound buffer"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:368
+#: src/audio_out/audio_directx2_out.c:365
msgid "Can't get buffer position"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:382
+#: src/audio_out/audio_directx2_out.c:379
msgid "Can't set buffer position"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:414
+#: src/audio_out/audio_directx2_out.c:411
msgid "Can't set sound volume"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:432
+#: src/audio_out/audio_directx2_out.c:429
#, c-format
msgid ": buffer lost, tryig to restore\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:436
+#: src/audio_out/audio_directx2_out.c:433
msgid "Couldn't lock direct sound buffer"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:447
+#: src/audio_out/audio_directx2_out.c:444
msgid "Couldn't unlock direct sound buffer"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:544
+#: src/audio_out/audio_directx2_out.c:541
#, c-format
msgid "Unable to create primary direct sound buffer."
msgstr ""
-#: src/audio_out/audio_directx2_out.c:637
+#: src/audio_out/audio_directx2_out.c:634
#, c-format
msgid ": play cursor overran, flushing buffers\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:655
+#: src/audio_out/audio_directx2_out.c:652
#, c-format
msgid ": delayed by %ld msec\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:759
+#: src/audio_out/audio_directx2_out.c:756
#, c-format
msgid ": can't create pthread condition: %s\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:763
+#: src/audio_out/audio_directx2_out.c:760
#, c-format
msgid ": can't create pthread mutex: %s\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:770
+#: src/audio_out/audio_directx2_out.c:767
#, c-format
msgid ": can't create buffer pthread: %s\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:877
+#: src/audio_out/audio_directx2_out.c:874
#, c-format
msgid ": can't destroy buffer pthread: %s\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:884
+#: src/audio_out/audio_directx2_out.c:881
#, c-format
msgid ": can't destroy pthread condition: %s\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:887
+#: src/audio_out/audio_directx2_out.c:884
#, c-format
msgid ": can't destroy pthread mutex: %s\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:947
+#: src/audio_out/audio_directx2_out.c:944
#, c-format
msgid ": unknown control command %d\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:1003
+#: src/audio_out/audio_directx2_out.c:1000
msgid "second xine audio output plugin using directx"
msgstr ""
@@ -853,7 +853,7 @@ msgstr ""
msgid "demux_snd: unsupported audio type: %d\n"
msgstr ""
-#: src/demuxers/demux_tta.c:88
+#: src/demuxers/demux_tta.c:86
msgid "demux_tta: total frames count too high\n"
msgstr ""
@@ -873,7 +873,7 @@ msgstr ""
msgid "demux_wc3movie: SHOT chunk referenced invalid palette (%d >= %d)\n"
msgstr ""
-#: src/demuxers/demux_wc3movie.c:406
+#: src/demuxers/demux_wc3movie.c:404
#, c-format
msgid "demux_wc3movie: There was a problem while loading palette chunks\n"
msgstr ""
@@ -1232,40 +1232,40 @@ msgstr ""
msgid "video_out_dxr3: ERROR Reading overlay init file. Run autocal!\n"
msgstr ""
-#: src/input/input_cdda.c:1621
+#: src/input/input_cdda.c:1608
#, c-format
msgid "%s: can't connect to %s:%d\n"
msgstr ""
-#: src/input/input_cdda.c:1668
+#: src/input/input_cdda.c:1655
#, c-format
msgid "input_cdda: successfuly connected to cddb server '%s:%d'.\n"
msgstr ""
-#: src/input/input_cdda.c:1673
+#: src/input/input_cdda.c:1660
#, c-format
msgid "input_cdda: failed to connect to cddb server '%s:%d' (%s).\n"
msgstr ""
-#: src/input/input_cdda.c:2707
+#: src/input/input_cdda.c:2690
msgid "CD Digital Audio (aka. CDDA)"
msgstr ""
-#: src/input/input_cdda.c:2760
+#: src/input/input_cdda.c:2742
msgid "device used for CD audio"
msgstr ""
-#: src/input/input_cdda.c:2761
+#: src/input/input_cdda.c:2743
msgid ""
"The path to the device, usually a CD or DVD drive, which you intend to use "
"for playing audio CDs."
msgstr ""
-#: src/input/input_cdda.c:2767
+#: src/input/input_cdda.c:2749
msgid "query CDDB"
msgstr ""
-#: src/input/input_cdda.c:2767
+#: src/input/input_cdda.c:2749
msgid ""
"Enables CDDB queries, which will give you convenient title and track names "
"for your audio CDs.\n"
@@ -1274,11 +1274,11 @@ msgid ""
"listening habits."
msgstr ""
-#: src/input/input_cdda.c:2775
+#: src/input/input_cdda.c:2757
msgid "CDDB server name"
msgstr ""
-#: src/input/input_cdda.c:2775
+#: src/input/input_cdda.c:2757
msgid ""
"The CDDB server used to retrieve the title and track information from.\n"
"This setting is security critical, because the sever will receive "
@@ -1286,31 +1286,19 @@ msgid ""
"malicious replies. Be sure to enter a server you can trust."
msgstr ""
-#: src/input/input_cdda.c:2783
+#: src/input/input_cdda.c:2765
msgid "CDDB server port"
msgstr ""
-#: src/input/input_cdda.c:2783
+#: src/input/input_cdda.c:2765
msgid "The server port used to retrieve the title and track information from."
msgstr ""
-#: src/input/input_cdda.c:2789
-msgid "CDDB cache directory"
-msgstr ""
-
-#: src/input/input_cdda.c:2789
-msgid ""
-"The replies from the CDDB server will be cached in this directory.\n"
-"This setting is security critical, because files with uncontrollable names "
-"will be created in this directory. Be sure to use a dedicated directory not "
-"used for anything but CDDB caching."
-msgstr ""
-
-#: src/input/input_cdda.c:2797
+#: src/input/input_cdda.c:2771
msgid "slow down disc drive to this speed factor"
msgstr ""
-#: src/input/input_cdda.c:2798
+#: src/input/input_cdda.c:2772
msgid ""
"Since some CD or DVD drives make some really loud noises because of the fast "
"disc rotation, xine will try to slow them down. With standard CD or DVD "
@@ -1319,118 +1307,123 @@ msgid ""
"A value of zero here will disable the slowdown."
msgstr ""
-#: src/input/input_dvb.c:881
+#: src/input/input_dvb.c:899
+#, c-format
+msgid "input_dvb: failed to open dvb channel file '%s': %s\n"
+msgstr ""
+
+#: src/input/input_dvb.c:905
#, c-format
-msgid "input_dvb: failed to open dvb channel file '%s'\n"
+msgid "input_dvb: dvb channel file '%s' is not a plain file\n"
msgstr ""
-#: src/input/input_dvb.c:2082 src/input/input_dvb.c:2910
+#: src/input/input_dvb.c:2115 src/input/input_dvb.c:2943
msgid "input_dvb: tuner_set_channel failed\n"
msgstr ""
-#: src/input/input_dvb.c:2710
+#: src/input/input_dvb.c:2743
msgid "input_dvb: cannot open dvb device\n"
msgstr ""
-#: src/input/input_dvb.c:2734
+#: src/input/input_dvb.c:2767
#, c-format
msgid "input_dvb: channel %d out of range, defaulting to 0\n"
msgstr ""
-#: src/input/input_dvb.c:2745
+#: src/input/input_dvb.c:2778
#, c-format
msgid "input_dvb: searching for channel %s\n"
msgstr ""
-#: src/input/input_dvb.c:2768
+#: src/input/input_dvb.c:2801
#, c-format
msgid "input_dvb: exact match for %s not found: trying partial matches\n"
msgstr ""
-#: src/input/input_dvb.c:2775
+#: src/input/input_dvb.c:2808
#, c-format
msgid "input_dvb: found matching channel %s\n"
msgstr ""
-#: src/input/input_dvb.c:2788
+#: src/input/input_dvb.c:2821
#, c-format
msgid "input_dvb: channel %s not found in channels.conf, defaulting.\n"
msgstr ""
-#: src/input/input_dvb.c:2794
+#: src/input/input_dvb.c:2827
msgid ""
"input_dvb: invalid channel specification, defaulting to last viewed "
"channel.\n"
msgstr ""
-#: src/input/input_dvb.c:2800
+#: src/input/input_dvb.c:2833
msgid "input_dvb: invalid channel specification, defaulting to channel 0\n"
msgstr ""
-#: src/input/input_dvb.c:2812
+#: src/input/input_dvb.c:2845
msgid ""
"input_dvb: dvbs mrl specified but the tuner doesn't appear to be QPSK (DVB-"
"S)\n"
msgstr ""
-#: src/input/input_dvb.c:2832
+#: src/input/input_dvb.c:2865
msgid ""
"input_dvb: dvbt mrl specified but the tuner doesn't appear to be OFDM (DVB-"
"T)\n"
msgstr ""
-#: src/input/input_dvb.c:2855 src/input/input_dvb.c:2881
+#: src/input/input_dvb.c:2888 src/input/input_dvb.c:2914
msgid ""
"input_dvb: dvbc mrl specified but the tuner doesn't appear to be QAM (DVB-"
"C)\n"
msgstr ""
-#: src/input/input_dvb.c:2916
+#: src/input/input_dvb.c:2949
#, c-format
msgid "input_dvb: cannot open dvr device '%s'\n"
msgstr ""
-#: src/input/input_dvb.c:2938
+#: src/input/input_dvb.c:2971
msgid "input_dvb: cannot create EPG updater thread\n"
msgstr ""
-#: src/input/input_dvb.c:3000
+#: src/input/input_dvb.c:3033
msgid "use DVB 'center cutout' (zoom)"
msgstr ""
-#: src/input/input_dvb.c:3001
+#: src/input/input_dvb.c:3034
msgid ""
"This will allow fullscreen playback of 4:3 content transmitted in a 16:9 "
"frame."
msgstr ""
-#: src/input/input_dvb.c:3094
+#: src/input/input_dvb.c:3127
msgid "DVB (Digital TV) input plugin"
msgstr ""
-#: src/input/input_dvb.c:3242
+#: src/input/input_dvb.c:3244
msgid "Remember last DVB channel watched"
msgstr ""
-#: src/input/input_dvb.c:3243
+#: src/input/input_dvb.c:3245
msgid ""
"On autoplay, xine will remember and switch to the channel indicated in media."
"dvb.last_channel. "
msgstr ""
-#: src/input/input_dvb.c:3250
+#: src/input/input_dvb.c:3252
msgid "Last DVB channel viewed"
msgstr ""
-#: src/input/input_dvb.c:3251
+#: src/input/input_dvb.c:3253
msgid "If enabled xine will remember and switch to this channel. "
msgstr ""
-#: src/input/input_dvb.c:3257
+#: src/input/input_dvb.c:3259
msgid "Number of dvb card to use."
msgstr ""
-#: src/input/input_dvb.c:3258
+#: src/input/input_dvb.c:3260
msgid ""
"Leave this at zero unless you really have more than 1 card in your system."
msgstr ""
@@ -1458,11 +1451,11 @@ msgid ""
"playing DVDs."
msgstr ""
-#: src/input/input_dvd.c:1800
+#: src/input/input_dvd.c:1799
msgid "raw device set up for DVD access"
msgstr ""
-#: src/input/input_dvd.c:1801
+#: src/input/input_dvd.c:1800
msgid ""
"If this points to a raw device connected to your DVD device, xine will use "
"the raw device for playback. This has the advantage of being slightly faster "
@@ -1473,68 +1466,55 @@ msgid ""
"See the documentation on raw device setup (man raw) for further information."
msgstr ""
-#: src/input/input_dvd.c:1814
+#: src/input/input_dvd.c:1813
msgid "CSS decryption method"
msgstr ""
-#: src/input/input_dvd.c:1815
+#: src/input/input_dvd.c:1814
msgid ""
"Selects the decryption method libdvdcss will use to descramble copy "
"protected DVDs. Try the various methods, if you have problems playing "
"scrambled DVDs."
msgstr ""
-#: src/input/input_dvd.c:1823
-msgid "path to the title key cache"
-msgstr ""
-
-#: src/input/input_dvd.c:1824
-msgid ""
-"Since cracking the copy protection of scrambled DVDs can be quite time "
-"consuming, libdvdcss will cache the cracked keys in this directory.\n"
-"This setting is security critical, because files with uncontrollable names "
-"will be created in this directory. Be sure to use a dedicated directory not "
-"used for anything but DVD key caching."
-msgstr ""
-
-#: src/input/input_dvd.c:1846
+#: src/input/input_dvd.c:1829
msgid "region the DVD player claims to be in (1 to 8)"
msgstr ""
-#: src/input/input_dvd.c:1847
+#: src/input/input_dvd.c:1830
msgid ""
"This only needs to be changed if your DVD jumps to a screen complaining "
"about a wrong region code. It has nothing to do with the region code set in "
"DVD drives, this is purely software."
msgstr ""
-#: src/input/input_dvd.c:1853
+#: src/input/input_dvd.c:1836
msgid "default language for DVD playback"
msgstr ""
-#: src/input/input_dvd.c:1854
+#: src/input/input_dvd.c:1837
msgid ""
"xine tries to use this language as a default for DVD playback. As far as the "
"DVD supports it, menus and audio tracks will be presented in this language.\n"
"The value must be a two character ISO639 language code."
msgstr ""
-#: src/input/input_dvd.c:1860
+#: src/input/input_dvd.c:1843
msgid "read-ahead caching"
msgstr ""
-#: src/input/input_dvd.c:1861
+#: src/input/input_dvd.c:1844
msgid ""
"xine can use a read ahead cache for DVD drive access.\n"
"This may lead to jerky playback on slow drives, but it improves the impact "
"of the DVD layer change on faster drives."
msgstr ""
-#: src/input/input_dvd.c:1867
+#: src/input/input_dvd.c:1850
msgid "unit for the skip action"
msgstr ""
-#: src/input/input_dvd.c:1868
+#: src/input/input_dvd.c:1851
msgid ""
"You can configure the behaviour when issuing a skip command (using the skip "
"buttons for example). The individual values mean:\n"
@@ -1553,11 +1533,11 @@ msgid ""
"features on the DVD"
msgstr ""
-#: src/input/input_dvd.c:1883
+#: src/input/input_dvd.c:1866
msgid "unit for seeking"
msgstr ""
-#: src/input/input_dvd.c:1884
+#: src/input/input_dvd.c:1867
msgid ""
"You can configure the domain spanned by the seek slider. The individual "
"values mean:\n"
@@ -1571,11 +1551,11 @@ msgid ""
"chapter of the current feature"
msgstr ""
-#: src/input/input_dvd.c:1895
+#: src/input/input_dvd.c:1878
msgid "play mode when title/chapter is given"
msgstr ""
-#: src/input/input_dvd.c:1896
+#: src/input/input_dvd.c:1879
msgid ""
"You can configure the behaviour when playing a dvd from a given title/"
"chapter (eg. using MRL 'dvd:/1.2'). The individual values mean:\n"
@@ -2260,7 +2240,7 @@ msgid ""
"2048: Debugging from VCDINFO\n"
msgstr ""
-#: src/liba52/xine_a52_decoder.c:742 src/libdts/xine_dts_decoder.c:546
+#: src/liba52/xine_a52_decoder.c:742 src/libxineadec/xine_dts_decoder.c:524
msgid "HELP! a mono-only audio driver?!\n"
msgstr ""
@@ -2311,60 +2291,60 @@ msgstr ""
msgid "libfaad: libfaad NeAACDecInit failed.\n"
msgstr ""
-#: src/libffmpeg/ff_audio_decoder.c:120
+#: src/libffmpeg/ff_audio_decoder.c:122
#, c-format
msgid "ffmpeg_audio_dec: increasing buffer to %d to avoid overflow.\n"
msgstr ""
-#: src/libffmpeg/ff_audio_decoder.c:164
+#: src/libffmpeg/ff_audio_decoder.c:166
#, c-format
msgid "ffmpeg_audio_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"
msgstr ""
-#: src/libffmpeg/ff_audio_decoder.c:256
+#: src/libffmpeg/ff_audio_decoder.c:258
msgid "ffmpeg_audio_dec: trying to open null codec\n"
msgstr ""
-#: src/libffmpeg/ff_audio_decoder.c:265
+#: src/libffmpeg/ff_audio_decoder.c:267
msgid "ffmpeg_audio_dec: couldn't open decoder\n"
msgstr ""
-#: src/libffmpeg/ff_dvaudio_decoder.c:286
+#: src/libffmpeg/ff_dvaudio_decoder.c:280
#, c-format
msgid "dvaudio: increasing buffer to %d to avoid overflow.\n"
msgstr ""
-#: src/libffmpeg/ff_video_decoder.c:157
+#: src/libffmpeg/ff_video_decoder.c:155
msgid "ffmpeg_video_dec: unsupported frame format, DR1 disabled.\n"
msgstr ""
-#: src/libffmpeg/ff_video_decoder.c:175
+#: src/libffmpeg/ff_video_decoder.c:173
msgid "ffmpeg_video_dec: unsupported frame dimensions, DR1 disabled.\n"
msgstr ""
-#: src/libffmpeg/ff_video_decoder.c:335
+#: src/libffmpeg/ff_video_decoder.c:333
#, c-format
msgid "ffmpeg_video_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"
msgstr ""
-#: src/libffmpeg/ff_video_decoder.c:364
+#: src/libffmpeg/ff_video_decoder.c:362
msgid "ffmpeg_video_dec: couldn't open decoder\n"
msgstr ""
-#: src/libffmpeg/ff_video_decoder.c:399
+#: src/libffmpeg/ff_video_decoder.c:397
msgid "ffmpeg_video_dec: direct rendering enabled\n"
msgstr ""
-#: src/libffmpeg/ff_video_decoder.c:818
+#: src/libffmpeg/ff_video_decoder.c:816
#, c-format
msgid "ffmpeg_video_dec: increasing buffer to %d to avoid overflow.\n"
msgstr ""
-#: src/libffmpeg/ff_video_decoder.c:1516
+#: src/libffmpeg/ff_video_decoder.c:1514
msgid "MPEG-4 postprocessing quality"
msgstr ""
-#: src/libffmpeg/ff_video_decoder.c:1517
+#: src/libffmpeg/ff_video_decoder.c:1515
msgid ""
"You can adjust the amount of post processing applied to MPEG-4 video.\n"
"Higher values result in better quality, but need more CPU. Lower values may "
@@ -2373,59 +2353,59 @@ msgid ""
"much."
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:167
+#: src/libffmpeg/ffmpeg_encoder.c:163
msgid "libavcodec mpeg output bitrate (kbit/s)"
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:168
+#: src/libffmpeg/ffmpeg_encoder.c:164
msgid ""
"The bitrate the libavcodec mpeg encoder should use for DXR3's encoding mode. "
"Higher values will increase quality and CPU usage.\n"
"This setting is only considered, when constant quality mode is disabled."
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:175
+#: src/libffmpeg/ffmpeg_encoder.c:171
msgid "constant quality mode"
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:176
+#: src/libffmpeg/ffmpeg_encoder.c:172
msgid ""
"When enabled, libavcodec will use a constant quality mode by dynamically "
"compressing the images based on their complexity. When disabled, libavcodec "
"will use constant bitrate mode."
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:183
+#: src/libffmpeg/ffmpeg_encoder.c:179
msgid "minimum compression"
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:184
+#: src/libffmpeg/ffmpeg_encoder.c:180
msgid "The minimum compression to apply to an image in constant quality mode."
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:189
+#: src/libffmpeg/ffmpeg_encoder.c:185
msgid "maximum quantizer"
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:190
+#: src/libffmpeg/ffmpeg_encoder.c:186
msgid "The maximum compression to apply to an image in constant quality mode."
msgstr ""
-#: src/libmusepack/xine_musepack_decoder.c:241
+#: src/libxineadec/xine_musepack_decoder.c:249
#, c-format
msgid "libmusepack: mpc_streaminfo_read failed: %d\n"
msgstr ""
-#: src/libmusepack/xine_musepack_decoder.c:315
+#: src/libxineadec/xine_musepack_decoder.c:323
msgid "libmusepack: data after last frame ignored\n"
msgstr ""
-#: src/libmusepack/xine_musepack_decoder.c:326
+#: src/libxineadec/xine_musepack_decoder.c:334
msgid "libmusepack: mpc_decoder_initialise failed\n"
msgstr ""
-#: src/libmusepack/xine_musepack_decoder.c:346
-#: src/libmusepack/xine_musepack_decoder.c:361
+#: src/libxineadec/xine_musepack_decoder.c:354
+#: src/libxineadec/xine_musepack_decoder.c:369
#, c-format
msgid "libmusepack: mpc_decoder_decode failed: %d\n"
msgstr ""
@@ -3121,7 +3101,7 @@ msgid "Select the video output layer by its id."
msgstr ""
#: src/video_out/video_out_directfb.c:1804
-#: src/video_out/video_out_directfb.c:2013
+#: src/video_out/video_out_directfb.c:2014
#, c-format
msgid "video_out_directfb: using display layer #%d.\n"
msgstr ""
@@ -3130,11 +3110,11 @@ msgstr ""
msgid "xine video output plugin using DirectFB."
msgstr ""
-#: src/video_out/video_out_directfb.c:2006
+#: src/video_out/video_out_directfb.c:2007
msgid "video_out_directfb: no usable display layer was found!\n"
msgstr ""
-#: src/video_out/video_out_directfb.c:2095
+#: src/video_out/video_out_directfb.c:2096
msgid "xine video output plugin using DirectFB under XDirectFB."
msgstr ""
@@ -3142,18 +3122,18 @@ msgstr ""
msgid "xine video output plugin for win32 using directx"
msgstr ""
-#: src/video_out/video_out_fb.c:792
+#: src/video_out/video_out_fb.c:780
#, c-format
msgid ""
"video_out_fb: only packed truecolor/directcolor is supported (%d).\n"
" Check 'fbset -i' or try 'fbset -depth 16'.\n"
msgstr ""
-#: src/video_out/video_out_fb.c:852 src/video_out/video_out_vidix.c:1239
+#: src/video_out/video_out_fb.c:840 src/video_out/video_out_vidix.c:1239
msgid "framebuffer device name"
msgstr ""
-#: src/video_out/video_out_fb.c:853 src/video_out/video_out_vidix.c:1240
+#: src/video_out/video_out_fb.c:841 src/video_out/video_out_vidix.c:1240
msgid ""
"Specifies the file name for the framebuffer device to be used.\n"
"This setting is security critical, because when changed to a different file, "
@@ -3161,39 +3141,40 @@ msgid ""
"careful that the value you enter really is a proper framebuffer device."
msgstr ""
-#: src/video_out/video_out_fb.c:927
-msgid "video_out_fb: Your video mode was not recognized, sorry.\n"
+#: src/video_out/video_out_fb.c:915
+#, c-format
+msgid "%s: Your video mode was not recognized, sorry.\n"
msgstr ""
-#: src/video_out/video_out_fb.c:984
+#: src/video_out/video_out_fb.c:972
#, c-format
-msgid "video_out_fb: %d video RAM buffers are available.\n"
+msgid "%s: %d video RAM buffers are available.\n"
msgstr ""
-#: src/video_out/video_out_fb.c:990
+#: src/video_out/video_out_fb.c:978
#, c-format
msgid ""
-"WARNING: video_out_fb: Zero copy buffers are DISABLED because only %d "
-"buffers\n"
+"WARNING: %s: Zero copy buffers are DISABLED because only %d buffers\n"
" are available which is less than the recommended %d buffers. Lowering\n"
" the frame buffer resolution might help.\n"
msgstr ""
-#: src/video_out/video_out_fb.c:1001
+#: src/video_out/video_out_fb.c:989
+#, c-format
msgid ""
-"WARNING: video_out_fb: Zero copy buffers are DISABLED because kernel driver\n"
+"WARNING: %s: Zero copy buffers are DISABLED because kernel driver\n"
" do not support screen panning (used for frame flips).\n"
msgstr ""
-#: src/video_out/video_out_fb.c:1070
+#: src/video_out/video_out_fb.c:1058
#, c-format
msgid ""
-"WARNING: video_out_fb: current display depth is %d. For better performance\n"
+"WARNING: %s: current display depth is %d. For better performance\n"
" a depth of 16 bpp is recommended!\n"
"\n"
msgstr ""
-#: src/video_out/video_out_fb.c:1101
+#: src/video_out/video_out_fb.c:1090
msgid "Xine video output plugin using the Linux frame buffer device"
msgstr ""
@@ -3245,8 +3226,8 @@ msgid ""
msgstr ""
#: src/video_out/video_out_opengl.c:1918 src/video_out/video_out_vidix.c:1015
-#: src/video_out/video_out_xcbxv.c:1472 src/video_out/video_out_xv.c:1486
-#: src/video_out/video_out_xvmc.c:1461 src/video_out/video_out_xxmc.c:2468
+#: src/video_out/video_out_xcbxv.c:1476 src/video_out/video_out_xv.c:1489
+#: src/video_out/video_out_xvmc.c:1461 src/video_out/video_out_xxmc.c:2465
msgid "enable double buffering"
msgstr ""
@@ -3321,9 +3302,9 @@ msgstr ""
msgid "video_out_pgx64: Error: ioctl failed (FBIOGATTR)\n"
msgstr ""
-#: src/video_out/video_out_pgx64.c:1464 src/video_out/video_out_xcbxv.c:1439
-#: src/video_out/video_out_xv.c:1453 src/video_out/video_out_xvmc.c:1446
-#: src/video_out/video_out_xxmc.c:2435
+#: src/video_out/video_out_pgx64.c:1464 src/video_out/video_out_xcbxv.c:1443
+#: src/video_out/video_out_xv.c:1456 src/video_out/video_out_xvmc.c:1446
+#: src/video_out/video_out_xxmc.c:2432
msgid "video overlay colour key"
msgstr ""
@@ -3473,9 +3454,9 @@ msgstr ""
msgid "The intensity of the blue colour components."
msgstr ""
-#: src/video_out/video_out_vidix.c:1016 src/video_out/video_out_xcbxv.c:1473
-#: src/video_out/video_out_xv.c:1487 src/video_out/video_out_xvmc.c:1462
-#: src/video_out/video_out_xxmc.c:2469
+#: src/video_out/video_out_vidix.c:1016 src/video_out/video_out_xcbxv.c:1477
+#: src/video_out/video_out_xv.c:1490 src/video_out/video_out_xvmc.c:1462
+#: src/video_out/video_out_xxmc.c:2466
msgid ""
"Double buffering will synchronize the update of the video image to the "
"repainting of the entire screen (\"vertical retrace\"). This eliminates "
@@ -3508,9 +3489,9 @@ msgid "video overlay colour key red component"
msgstr ""
#: src/video_out/video_out_vidix.c:1159 src/video_out/video_out_vidix.c:1166
-#: src/video_out/video_out_vidix.c:1173 src/video_out/video_out_xcbxv.c:1440
-#: src/video_out/video_out_xv.c:1454 src/video_out/video_out_xvmc.c:1447
-#: src/video_out/video_out_xxmc.c:2436
+#: src/video_out/video_out_vidix.c:1173 src/video_out/video_out_xcbxv.c:1444
+#: src/video_out/video_out_xv.c:1457 src/video_out/video_out_xvmc.c:1447
+#: src/video_out/video_out_xxmc.c:2433
msgid ""
"The colour key is used to tell the graphics card where to overlay the video "
"image. Try different values, if you experience windows becoming transparent."
@@ -3532,27 +3513,38 @@ msgstr ""
msgid "xine video output plugin using libvidix for linux frame buffer"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:157
+#: src/video_out/video_out_xcbshm.c:157 src/video_out/video_out_xshm.c:219
#, c-format
-msgid ""
-"video_out_xcbshm: %s: allocating image\n"
-"video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+msgid "%s: %s: allocating image\n"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:166
-msgid ""
-"video_out_xcbshm: shared memory error (address error) when allocating "
-"image \n"
-"video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbshm.c:159 src/video_out/video_out_xcbshm.c:169
+#: src/video_out/video_out_xcbshm.c:181 src/video_out/video_out_xcbxv.c:272
+#: src/video_out/video_out_xcbxv.c:282 src/video_out/video_out_xcbxv.c:292
+#: src/video_out/video_out_xcbxv.c:304 src/video_out/video_out_xshm.c:204
+#: src/video_out/video_out_xshm.c:221 src/video_out/video_out_xshm.c:232
+#: src/video_out/video_out_xshm.c:251 src/video_out/video_out_xv.c:296
+#: src/video_out/video_out_xv.c:307 src/video_out/video_out_xv.c:316
+#: src/video_out/video_out_xv.c:352 src/video_out/video_out_xxmc.c:648
+#: src/video_out/video_out_xxmc.c:659 src/video_out/video_out_xxmc.c:668
+#: src/video_out/video_out_xxmc.c:704
+#, c-format
+msgid "%s: => not using MIT Shared Memory extension.\n"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:177
-msgid ""
-"video_out_xcbshm: x11 error during shared memory XImage creation\n"
-"video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbshm.c:167 src/video_out/video_out_xshm.c:230
+#, c-format
+msgid "%s: shared memory error (address error) when allocating image \n"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:1100 src/video_out/video_out_xshm.c:1157
+#: src/video_out/video_out_xcbshm.c:179 src/video_out/video_out_xcbxv.c:302
+#: src/video_out/video_out_xshm.c:249 src/video_out/video_out_xv.c:350
+#: src/video_out/video_out_xxmc.c:702
+#, c-format
+msgid "%s: x11 error during shared memory XImage creation\n"
+msgstr ""
+
+#: src/video_out/video_out_xcbshm.c:1103 src/video_out/video_out_xshm.c:1161
#, c-format
msgid ""
"\n"
@@ -3562,73 +3554,75 @@ msgid ""
"\n"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:1113
-msgid "video_out_xcbshm: MIT shared memory extension not present on display.\n"
+#: src/video_out/video_out_xcbshm.c:1116 src/video_out/video_out_xshm.c:1174
+#, c-format
+msgid "%s: MIT shared memory extension not present on display.\n"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:1212
-msgid "video_out_xcbshm: your video mode was not recognized, sorry :-(\n"
+#: src/video_out/video_out_xcbshm.c:1215 src/video_out/video_out_xshm.c:1258
+#, c-format
+msgid "%s: your video mode was not recognized, sorry :-(\n"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:1242 src/video_out/video_out_xshm.c:1303
+#: src/video_out/video_out_xcbshm.c:1245 src/video_out/video_out_xshm.c:1307
msgid "xine video output plugin using the MIT X shared memory extension"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:272
-msgid ""
-"video_out_xcbxv: XvShmCreateImage returned a zero size\n"
-"video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbxv.c:270 src/video_out/video_out_xv.c:305
+#: src/video_out/video_out_xxmc.c:657
+#, c-format
+msgid "%s: XvShmCreateImage returned a zero size\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:281
+#: src/video_out/video_out_xcbxv.c:280 src/video_out/video_out_xv.c:314
+#: src/video_out/video_out_xxmc.c:666
#, c-format
-msgid ""
-"video_out_xcbxv: shared memory error in shmget: %s\n"
-"video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+msgid "%s: shared memory error in shmget: %s\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:300
-msgid ""
-"video_out_xcbxv: x11 error during shared memory XImage creation\n"
-"video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbxv.c:290
+#, c-format
+msgid "%s: shared memory error (address error)\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1291
-msgid "video_out_xcbxv: Xv extension not present.\n"
+#: src/video_out/video_out_xcbxv.c:1294 src/video_out/video_out_xv.c:1301
+#: src/video_out/video_out_xxmc.c:2283
+#, c-format
+msgid "%s: Xv extension not present.\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1333
+#: src/video_out/video_out_xcbxv.c:1336 src/video_out/video_out_xv.c:1338
+#: src/video_out/video_out_xxmc.c:2320
+#, c-format
msgid ""
-"video_out_xcbxv: Xv extension is present but I couldn't find a usable yuv12 "
-"port.\n"
-" Looks like your graphics hardware driver doesn't support "
-"Xv?!\n"
+"%s: Xv extension is present but I couldn't find a usable yuv12 port.\n"
+"\tLooks like your graphics hardware driver doesn't support Xv?!\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1341
+#: src/video_out/video_out_xcbxv.c:1345
#, c-format
msgid ""
-"video_out_xcbxv: using Xv port %d from adaptor %s for hardware colorspace "
-"conversion and scaling.\n"
+"%s: using Xv port %d from adaptor %s for hardware colorspace conversion and "
+"scaling.\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1448 src/video_out/video_out_xv.c:1462
-#: src/video_out/video_out_xvmc.c:1455 src/video_out/video_out_xxmc.c:2444
+#: src/video_out/video_out_xcbxv.c:1452 src/video_out/video_out_xv.c:1465
+#: src/video_out/video_out_xvmc.c:1455 src/video_out/video_out_xxmc.c:2441
msgid "autopaint colour key"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1449 src/video_out/video_out_xv.c:1463
-#: src/video_out/video_out_xvmc.c:1456 src/video_out/video_out_xxmc.c:2445
+#: src/video_out/video_out_xcbxv.c:1453 src/video_out/video_out_xv.c:1466
+#: src/video_out/video_out_xvmc.c:1456 src/video_out/video_out_xxmc.c:2442
msgid "Make Xv autopaint its colorkey."
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1456 src/video_out/video_out_xv.c:1470
-#: src/video_out/video_out_xxmc.c:2452
+#: src/video_out/video_out_xcbxv.c:1460 src/video_out/video_out_xv.c:1473
+#: src/video_out/video_out_xxmc.c:2449
msgid "bilinear scaling mode"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1457 src/video_out/video_out_xv.c:1471
-#: src/video_out/video_out_xxmc.c:2453
+#: src/video_out/video_out_xcbxv.c:1461 src/video_out/video_out_xv.c:1474
+#: src/video_out/video_out_xxmc.c:2450
msgid ""
"Selects the bilinear scaling mode for Permedia cards. The individual values "
"are:\n"
@@ -3643,30 +3637,34 @@ msgid ""
"2 - enable full bilinear filtering"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1509
-msgid "video_out_xcbxv: this adaptor supports the yv12 format.\n"
+#: src/video_out/video_out_xcbxv.c:1513 src/video_out/video_out_xv.c:1523
+#: src/video_out/video_out_xxmc.c:2506
+#, c-format
+msgid "%s: this adaptor supports the yv12 format.\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1514
-msgid "video_out_xcbxv: this adaptor supports the yuy2 format.\n"
+#: src/video_out/video_out_xcbxv.c:1518 src/video_out/video_out_xv.c:1528
+#: src/video_out/video_out_xxmc.c:2511
+#, c-format
+msgid "%s: this adaptor supports the yuy2 format.\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1522 src/video_out/video_out_xv.c:1547
-#: src/video_out/video_out_xxmc.c:2537
+#: src/video_out/video_out_xcbxv.c:1526 src/video_out/video_out_xv.c:1550
+#: src/video_out/video_out_xxmc.c:2534
msgid "pitch alignment workaround"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1523 src/video_out/video_out_xv.c:1548
-#: src/video_out/video_out_xxmc.c:2538
+#: src/video_out/video_out_xcbxv.c:1527 src/video_out/video_out_xv.c:1551
+#: src/video_out/video_out_xxmc.c:2535
msgid "Some buggy video drivers need a workaround to function properly."
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1529 src/video_out/video_out_xv.c:1554
+#: src/video_out/video_out_xcbxv.c:1533 src/video_out/video_out_xv.c:1557
#: src/video_out/video_out_xvmc.c:1524
msgid "deinterlace method (deprecated)"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1530 src/video_out/video_out_xv.c:1555
+#: src/video_out/video_out_xcbxv.c:1534 src/video_out/video_out_xv.c:1558
#: src/video_out/video_out_xvmc.c:1525
msgid ""
"This config setting is deprecated. You should use the new deinterlacing post "
@@ -3705,93 +3703,26 @@ msgid ""
"with medium CPU usage."
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1584 src/video_out/video_out_xv.c:1628
-#: src/video_out/video_out_xxmc.c:2618
+#: src/video_out/video_out_xcbxv.c:1588 src/video_out/video_out_xv.c:1631
+#: src/video_out/video_out_xxmc.c:2615
msgid "xine video output plugin using the MIT X video extension"
msgstr ""
#: src/video_out/video_out_xshm.c:202
-msgid ""
-"video_out_xshm: shared memory error when allocating image\n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xshm.c:218
#, c-format
-msgid ""
-"video_out_xshm: %s: allocating image\n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xshm.c:228
-msgid ""
-"video_out_xshm: shared memory error (address error) when allocating image \n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xshm.c:245
-msgid ""
-"video_out_xshm: x11 error during shared memory XImage creation\n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xshm.c:1170
-msgid "video_out_xshm: MIT shared memory extension not present on display.\n"
-msgstr ""
-
-#: src/video_out/video_out_xshm.c:1254
-msgid "video_out_xshm: your video mode was not recognized, sorry :-(\n"
+msgid "%s: shared memory error when allocating image\n"
msgstr ""
-#: src/video_out/video_out_xv.c:296
-msgid ""
-"video_out_xv: XvShmCreateImage failed\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:306
-msgid ""
-"video_out_xv: XvShmCreateImage returned a zero size\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:314
+#: src/video_out/video_out_xv.c:294 src/video_out/video_out_xxmc.c:646
#, c-format
-msgid ""
-"video_out_xv: shared memory error in shmget: %s\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:346
-msgid ""
-"video_out_xv: x11 error during shared memory XImage creation\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:1299
-msgid "video_out_xv: Xv extension not present.\n"
+msgid "%s: XvShmCreateImage failed\n"
msgstr ""
-#: src/video_out/video_out_xv.c:1336
-msgid ""
-"video_out_xv: Xv extension is present but I couldn't find a usable yuv12 "
-"port.\n"
-" Looks like your graphics hardware driver doesn't support Xv?!\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:1345
+#: src/video_out/video_out_xv.c:1348 src/video_out/video_out_xxmc.c:2330
#, c-format
msgid ""
-"video_out_xv: using Xv port %ld from adaptor %s for hardware colorspace "
-"conversion and scaling.\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:1520
-msgid "video_out_xv: this adaptor supports the yv12 format.\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:1525
-msgid "video_out_xv: this adaptor supports the yuy2 format.\n"
+"%s: using Xv port %ld from adaptor %s for hardware colorspace conversion and "
+"scaling.\n"
msgstr ""
#: src/video_out/video_out_xvmc.c:1593
@@ -3832,94 +3763,43 @@ msgstr ""
msgid " With Overlay = %d; UnsignedIntra = %d.\n"
msgstr ""
-#: src/video_out/video_out_xxmc.c:650
-msgid ""
-"video_out_xxmc: XvShmCreateImage failed\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:660
-msgid ""
-"video_out_xxmc: XvShmCreateImage returned a zero size\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:668
-#, c-format
-msgid ""
-"video_out_xxmc: shared memory error in shmget: %s\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:700
-msgid ""
-"video_out_xxmc: x11 error during shared memory XImage creation\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:2287
-msgid "video_out_xxmc: Xv extension not present.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:2324
-msgid ""
-"video_out_xxmc: Xv extension is present but I couldn't find a usable yuv12 "
-"port.\n"
-" Looks like your graphics hardware driver doesn't support Xv?!\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:2333
-#, c-format
-msgid ""
-"video_out_xxmc: using Xv port %ld from adaptor %s for hardware colorspace "
-"conversion and scaling.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:2509
-msgid "video_out_xxmc: this adaptor supports the yv12 format.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:2514
-msgid "video_out_xxmc: this adaptor supports the yuy2 format.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:2543
+#: src/video_out/video_out_xxmc.c:2540
msgid "Make XvMC allocate more frames for better buffering."
msgstr ""
-#: src/video_out/video_out_xxmc.c:2544
+#: src/video_out/video_out_xxmc.c:2541
msgid ""
"Some XvMC implementations allow more than 8 frames.\n"
"This option, when turned on, makes the driver try to\n"
"allocate 15 frames. A must for unichrome and live VDR.\n"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2550
+#: src/video_out/video_out_xxmc.c:2547
msgid "Unichrome cpu save"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2551
+#: src/video_out/video_out_xxmc.c:2548
msgid ""
"Saves CPU time by sleeping while decoder works.\n"
"Only for Linux kernel 2.6 series or 2.4 with multimedia patch.\n"
"Experimental.\n"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2557
+#: src/video_out/video_out_xxmc.c:2554
msgid "Fix buggy NVIDIA XvMC subpicture colors"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2558
+#: src/video_out/video_out_xxmc.c:2555
msgid ""
"There's a bug in NVIDIA's XvMC lib that makes red OSD colors\n"
"look blue and vice versa. This option provides a workaround.\n"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2563
+#: src/video_out/video_out_xxmc.c:2560
msgid "Use bob as accelerated deinterlace method."
msgstr ""
-#: src/video_out/video_out_xxmc.c:2564
+#: src/video_out/video_out_xxmc.c:2561
msgid ""
"When interlacing is enabled for hardware accelerated frames,\n"
"Alternate between top and bottom field at double the frame rate.\n"
@@ -4140,12 +4020,12 @@ msgid ""
"info_helper: unsupported conversion %s -> UTF-8, no conversion performed\n"
msgstr ""
-#: src/xine-engine/input_cache.c:167
+#: src/xine-engine/input_cache.c:171
#, c-format
msgid ": open() function should never be called\n"
msgstr ""
-#: src/xine-engine/input_cache.c:349
+#: src/xine-engine/input_cache.c:353
#, c-format
msgid ": input plugin not defined!\n"
msgstr ""
@@ -4254,162 +4134,163 @@ msgstr ""
msgid "io_helper: Connection Refused\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:212
+#: src/xine-engine/load_plugins.c:215
#, c-format
msgid "map_decoder_list: no space for decoder, skipped.\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:327
+#: src/xine-engine/load_plugins.c:330
#, c-format
msgid ""
"load_plugins: ignoring plugin %s, wrong iface version %d (should be %d)\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:384
+#: src/xine-engine/load_plugins.c:387
#, c-format
msgid "priority for %s decoder"
msgstr ""
-#: src/xine-engine/load_plugins.c:395
+#: src/xine-engine/load_plugins.c:398
msgid ""
"The priority provides a ranking in case some media can be handled by more "
"than one decoder.\n"
"A priority of 0 enables the decoder's default priority."
msgstr ""
-#: src/xine-engine/load_plugins.c:423
+#: src/xine-engine/load_plugins.c:426
#, c-format
msgid ""
"load_plugins: demuxer plugin %s does not provide a priority, xine-lib will "
"use the default priority.\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:440
+#: src/xine-engine/load_plugins.c:443
#, c-format
msgid ""
"load_plugins: input plugin %s does not provide a priority, xine-lib will use "
"the default priority.\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:496
+#: src/xine-engine/load_plugins.c:499
#, c-format
msgid "load_plugins: plugin %s found\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:499
+#: src/xine-engine/load_plugins.c:502
#, c-format
msgid "load_plugins: static plugin found\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:506
+#: src/xine-engine/load_plugins.c:509
#, c-format
msgid "load_plugins: plugin limit reached, %s could not be loaded\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:509
+#: src/xine-engine/load_plugins.c:512
#, c-format
msgid "load_plugins: plugin limit reached, static plugin could not be loaded\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:526
+#: src/xine-engine/load_plugins.c:529
#, c-format
msgid "load_plugins: unknown plugin type %d in %s\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:530
+#: src/xine-engine/load_plugins.c:533
#, c-format
msgid "load_plugins: unknown statically linked plugin type %d\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:590
+#: src/xine-engine/load_plugins.c:593
#, c-format
msgid "load_plugins: unable to stat %s\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:631
+#: src/xine-engine/load_plugins.c:634
#, c-format
msgid ""
"load_plugins: cannot open plugin lib %s:\n"
"%s\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:646
+#: src/xine-engine/load_plugins.c:649
#, c-format
msgid ""
"load_plugins: can't get plugin info from %s:\n"
"%s\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:664
+#: src/xine-engine/load_plugins.c:667
#, c-format
msgid "load_plugins: skipping unreadable plugin directory %s.\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:713
+#: src/xine-engine/load_plugins.c:716
#, c-format
msgid ""
"load_plugins: cannot (stage 2) open plugin lib %s:\n"
"%s\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:739
+#: src/xine-engine/load_plugins.c:742
#, c-format
msgid "load_plugins: Yikes! %s doesn't contain plugin info.\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:1305
+#: src/xine-engine/load_plugins.c:1104 src/xine-engine/load_plugins.c:1113
+#, c-format
+msgid "Unable to create %s directory: %s\n"
+msgstr ""
+
+#: src/xine-engine/load_plugins.c:1345
#, c-format
msgid "load_plugins: unknown content detection strategy %d\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:1415
+#: src/xine-engine/load_plugins.c:1455
#, c-format
msgid "load_plugins: using demuxer '%s'\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:1726
+#: src/xine-engine/load_plugins.c:1766
#, c-format
msgid "load_plugins: failed to load audio output plugin <%s>\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:1729
+#: src/xine-engine/load_plugins.c:1769
msgid ""
"load_plugins: audio output auto-probing didn't find any usable audio "
"driver.\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:2033
+#: src/xine-engine/load_plugins.c:2073
#, c-format
msgid ""
"load_plugins: cannot unload plugin lib %s:\n"
"%s\n"
msgstr ""
-#: src/xine-engine/osd.c:745
+#: src/xine-engine/osd.c:747
#, c-format
msgid "font '%s-%d' already loaded, weird.\n"
msgstr ""
-#: src/xine-engine/osd.c:757
+#: src/xine-engine/osd.c:759
#, c-format
msgid "font '%s' loading failed (%d < %d)\n"
msgstr ""
-#: src/xine-engine/osd.c:767
+#: src/xine-engine/osd.c:769
#, c-format
msgid "wrong version for font '%s'. expected %d found %d.\n"
msgstr ""
-#: src/xine-engine/osd.c:834
-msgid "osd: cannot initialize ft2 library\n"
-msgstr ""
-
-#: src/xine-engine/osd.c:857
+#: src/xine-engine/osd.c:856
#, c-format
msgid "osd: error matching font %s with FontConfig"
msgstr ""
-#: src/xine-engine/osd.c:871
+#: src/xine-engine/osd.c:870
#, c-format
msgid "osd: error loading font %s with FontConfig"
msgstr ""
@@ -4419,57 +4300,61 @@ msgstr ""
msgid "osd: error looking up font %s with FontConfig"
msgstr ""
-#: src/xine-engine/osd.c:895
+#: src/xine-engine/osd.c:914
#, c-format
-msgid "osd: error loading font %s with ft2\n"
+msgid "osd: error loading font %s with in XDG data directories.\n"
+msgstr ""
+
+#: src/xine-engine/osd.c:923
+msgid "osd: cannot initialize ft2 library\n"
msgstr ""
-#: src/xine-engine/osd.c:905
+#: src/xine-engine/osd.c:945
msgid "osd: error setting font size (no scalable font?)\n"
msgstr ""
-#: src/xine-engine/osd.c:1021
+#: src/xine-engine/osd.c:1061
#, c-format
msgid ""
"osd: unknown sequence starting with byte 0x%02X in encoding \"%s\", "
"skipping\n"
msgstr ""
-#: src/xine-engine/osd.c:1077
+#: src/xine-engine/osd.c:1117
msgid "osd: can't find out current locale character set\n"
msgstr ""
-#: src/xine-engine/osd.c:1087
+#: src/xine-engine/osd.c:1127
#, c-format
msgid "osd: unsupported conversion %s -> %s, no conversion performed\n"
msgstr ""
-#: src/xine-engine/osd.c:1142 src/xine-engine/osd.c:1310
+#: src/xine-engine/osd.c:1182 src/xine-engine/osd.c:1350
msgid "osd: font isn't defined\n"
msgstr ""
-#: src/xine-engine/osd.c:1181
+#: src/xine-engine/osd.c:1221
msgid "osd: error loading glyph\n"
msgstr ""
-#: src/xine-engine/osd.c:1187
+#: src/xine-engine/osd.c:1227
msgid "osd: error in rendering glyph\n"
msgstr ""
-#: src/xine-engine/osd.c:1347
+#: src/xine-engine/osd.c:1387
#, c-format
msgid "osd: error loading glyph %i\n"
msgstr ""
-#: src/xine-engine/osd.c:1354
+#: src/xine-engine/osd.c:1394
msgid "osd: error in rendering\n"
msgstr ""
-#: src/xine-engine/osd.c:1611
+#: src/xine-engine/osd.c:1660
msgid "palette (foreground-border-background) to use for subtitles and OSD"
msgstr ""
-#: src/xine-engine/osd.c:1612
+#: src/xine-engine/osd.c:1661
msgid ""
"The palette for on-screen-display and some subtitle formats that do not "
"specify any colouring themselves. The palettes are listed in the form: "
@@ -4582,127 +4467,127 @@ msgid ""
"accelerated, this can dramatically reduce CPU usage."
msgstr ""
-#: src/xine-engine/xine.c:704 src/xine-engine/xine.c:811
-#: src/xine-engine/xine.c:850 src/xine-engine/xine.c:886
-#: src/xine-engine/xine.c:898 src/xine-engine/xine.c:911
-#: src/xine-engine/xine.c:924 src/xine-engine/xine.c:937
-#: src/xine-engine/xine.c:963 src/xine-engine/xine.c:988
-#: src/xine-engine/xine.c:1023
+#: src/xine-engine/xine.c:706 src/xine-engine/xine.c:813
+#: src/xine-engine/xine.c:852 src/xine-engine/xine.c:888
+#: src/xine-engine/xine.c:900 src/xine-engine/xine.c:913
+#: src/xine-engine/xine.c:926 src/xine-engine/xine.c:939
+#: src/xine-engine/xine.c:965 src/xine-engine/xine.c:990
+#: src/xine-engine/xine.c:1025
msgid "xine: error while parsing mrl\n"
msgstr ""
-#: src/xine-engine/xine.c:740
+#: src/xine-engine/xine.c:742
#, c-format
msgid "xine: found input plugin : %s\n"
msgstr ""
-#: src/xine-engine/xine.c:758
+#: src/xine-engine/xine.c:760
#, c-format
msgid "xine: input plugin cannot open MRL [%s]\n"
msgstr ""
-#: src/xine-engine/xine.c:774
+#: src/xine-engine/xine.c:776
#, c-format
msgid "xine: cannot find input plugin for MRL [%s]\n"
msgstr ""
-#: src/xine-engine/xine.c:800
+#: src/xine-engine/xine.c:802
#, c-format
msgid "xine: specified demuxer %s failed to start\n"
msgstr ""
-#: src/xine-engine/xine.c:836
+#: src/xine-engine/xine.c:838
#, c-format
msgid "xine: join rip input plugin\n"
msgstr ""
-#: src/xine-engine/xine.c:843
+#: src/xine-engine/xine.c:845
msgid "xine: error opening rip input plugin instance\n"
msgstr ""
-#: src/xine-engine/xine.c:874
+#: src/xine-engine/xine.c:876
#, c-format
msgid "xine: last_probed demuxer %s failed to start\n"
msgstr ""
-#: src/xine-engine/xine.c:903
+#: src/xine-engine/xine.c:905
msgid "ignoring video\n"
msgstr ""
-#: src/xine-engine/xine.c:916
+#: src/xine-engine/xine.c:918
msgid "ignoring audio\n"
msgstr ""
-#: src/xine-engine/xine.c:929
+#: src/xine-engine/xine.c:931
msgid "ignoring subpicture\n"
msgstr ""
-#: src/xine-engine/xine.c:942
+#: src/xine-engine/xine.c:944
msgid "input cache plugin disabled\n"
msgstr ""
-#: src/xine-engine/xine.c:1013
+#: src/xine-engine/xine.c:1015
#, c-format
msgid "subtitle mrl opened '%s'\n"
msgstr ""
-#: src/xine-engine/xine.c:1017
+#: src/xine-engine/xine.c:1019
msgid "xine: error opening subtitle mrl\n"
msgstr ""
-#: src/xine-engine/xine.c:1049
+#: src/xine-engine/xine.c:1051
#, c-format
msgid "xine: error while parsing MRL\n"
msgstr ""
-#: src/xine-engine/xine.c:1056
+#: src/xine-engine/xine.c:1058
#, c-format
msgid "xine: changing option '%s' from MRL isn't permitted\n"
msgstr ""
-#: src/xine-engine/xine.c:1076
+#: src/xine-engine/xine.c:1078
#, c-format
msgid "xine: couldn't find demux for >%s<\n"
msgstr ""
-#: src/xine-engine/xine.c:1092
+#: src/xine-engine/xine.c:1094
#, c-format
msgid "xine: found demuxer plugin: %s\n"
msgstr ""
-#: src/xine-engine/xine.c:1112
+#: src/xine-engine/xine.c:1114
#, c-format
msgid "xine: demuxer failed to start\n"
msgstr ""
-#: src/xine-engine/xine.c:1177
+#: src/xine-engine/xine.c:1179
#, c-format
msgid "xine_play: no demux available\n"
msgstr ""
-#: src/xine-engine/xine.c:1247
+#: src/xine-engine/xine.c:1249
#, c-format
msgid "xine_play: demux failed to start\n"
msgstr ""
-#: src/xine-engine/xine.c:1523
+#: src/xine-engine/xine.c:1527
#, c-format
msgid "xine: The specified save_dir \"%s\" might be a security risk.\n"
msgstr ""
-#: src/xine-engine/xine.c:1528
+#: src/xine-engine/xine.c:1532
msgid "The specified save_dir might be a security risk."
msgstr ""
-#: src/xine-engine/xine.c:1554
+#: src/xine-engine/xine.c:1561
msgid "xine: locale not supported by C library\n"
msgstr ""
-#: src/xine-engine/xine.c:1563
+#: src/xine-engine/xine.c:1570
msgid "media format detection strategy"
msgstr ""
-#: src/xine-engine/xine.c:1564
+#: src/xine-engine/xine.c:1571
msgid ""
"xine offers various methods to detect the media format of input to play. The "
"individual values are:\n"
@@ -4720,11 +4605,11 @@ msgid ""
"Detect by file name extension only.\n"
msgstr ""
-#: src/xine-engine/xine.c:1582
+#: src/xine-engine/xine.c:1589
msgid "directory for saving streams"
msgstr ""
-#: src/xine-engine/xine.c:1583
+#: src/xine-engine/xine.c:1590
msgid ""
"When using the stream save feature, files will be written only into this "
"directory.\n"
@@ -4734,11 +4619,11 @@ msgid ""
"content in any file."
msgstr ""
-#: src/xine-engine/xine.c:1594
+#: src/xine-engine/xine.c:1601
msgid "allow implicit changes to the configuration (e.g. by MRL)"
msgstr ""
-#: src/xine-engine/xine.c:1595
+#: src/xine-engine/xine.c:1602
msgid ""
"If enabled, you allow xine to change your configuration without explicit "
"actions from your side. For example configuration changes demanded by MRLs "
@@ -4748,26 +4633,26 @@ msgid ""
"configuration, you might end with a totally messed up xine."
msgstr ""
-#: src/xine-engine/xine.c:1609
+#: src/xine-engine/xine.c:1616
msgid "Timeout for network stream reading (in seconds)"
msgstr ""
-#: src/xine-engine/xine.c:1610
+#: src/xine-engine/xine.c:1617
msgid ""
"Specifies the timeout when reading from network streams, in seconds. Too low "
"values might stop streaming when the source is slow or the bandwidth is "
"occupied, too high values will freeze the player if the connection is lost."
msgstr ""
-#: src/xine-engine/xine.c:1962
+#: src/xine-engine/xine.c:1969
msgid "messages"
msgstr ""
-#: src/xine-engine/xine.c:1963
+#: src/xine-engine/xine.c:1970
msgid "plugin"
msgstr ""
-#: src/xine-engine/xine.c:1964
+#: src/xine-engine/xine.c:1971
msgid "trace"
msgstr ""
diff --git a/po/pl.po b/po/pl.po
index a098befaf..84326748a 100644
--- a/po/pl.po
+++ b/po/pl.po
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: pl_PL\n"
"Report-Msgid-Bugs-To: xine-devel@lists.sourceforge.net\n"
-"POT-Creation-Date: 2007-04-06 15:39+0200\n"
+"POT-Creation-Date: 2007-04-24 21:48+0100\n"
"PO-Revision-Date: 2003-05-24 12:36+0200\n"
"Last-Translator: Bartłomiej Muryn <_4ever_@irc.pl>\n"
"Language-Team: Polish <pl@li.org>\n"
@@ -42,48 +42,48 @@ msgstr ""
msgid "Unknown error"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:354
+#: src/audio_out/audio_alsa_out.c:351
#, c-format
msgid "audio_alsa_out:Already open...WHY!"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:382
+#: src/audio_out/audio_alsa_out.c:379
#, c-format
msgid "audio_alsa_out: snd_pcm_open() of %s failed: %s\n"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:384
+#: src/audio_out/audio_alsa_out.c:381
msgid "audio_alsa_out: >>> check if another program already uses PCM <<<\n"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:397
+#: src/audio_out/audio_alsa_out.c:394
#, c-format
msgid ""
"audio_alsa_out: broken configuration for this PCM: no configurations "
"available: %s\n"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1289
+#: src/audio_out/audio_alsa_out.c:1286
msgid "notify changes to the hardware mixer"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1290
+#: src/audio_out/audio_alsa_out.c:1287
msgid ""
"When the hardware mixer changes, your application will receive a "
"notification so that it can update its graphical representation of the mixer "
"settings on the fly."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1355
+#: src/audio_out/audio_alsa_out.c:1352
#, c-format
msgid "snd_lib_error_set_handler() failed: %d"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1362
+#: src/audio_out/audio_alsa_out.c:1359
msgid "sound card can do mmap"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1363
+#: src/audio_out/audio_alsa_out.c:1360
msgid ""
"Enable this, if your sound card and alsa driver support memory mapped IO.\n"
"You can try enabling it and check, if everything works. If it does, this "
@@ -92,33 +92,33 @@ msgstr ""
# src/audio_out/audio_alsa_out.c:181 src/audio_out/audio_alsa_out.c:728
# src/audio_out/audio_alsa_out.c:913 src/audio_out/audio_alsa_out.c:957
-#: src/audio_out/audio_alsa_out.c:1372
+#: src/audio_out/audio_alsa_out.c:1369
msgid "device used for mono output"
msgstr "urządzenie użyte w trybie mono"
-#: src/audio_out/audio_alsa_out.c:1373
+#: src/audio_out/audio_alsa_out.c:1370
msgid ""
"xine will use this alsa device to output mono sound.\n"
"See the alsa documentation for information on alsa devices."
msgstr ""
# src/audio_out/audio_alsa_out.c:191 src/audio_out/audio_alsa_out.c:920
-#: src/audio_out/audio_alsa_out.c:1381
+#: src/audio_out/audio_alsa_out.c:1378
msgid "device used for stereo output"
msgstr "urządzenie użyte w trybie stereo"
-#: src/audio_out/audio_alsa_out.c:1382
+#: src/audio_out/audio_alsa_out.c:1379
msgid ""
"xine will use this alsa device to output stereo sound.\n"
"See the alsa documentation for information on alsa devices."
msgstr ""
# src/audio_out/audio_alsa_out.c:201 src/audio_out/audio_alsa_out.c:927
-#: src/audio_out/audio_alsa_out.c:1390
+#: src/audio_out/audio_alsa_out.c:1387
msgid "device used for 4-channel output"
msgstr "urządzenie użyte do wyjścia 4-kanałowego"
-#: src/audio_out/audio_alsa_out.c:1391
+#: src/audio_out/audio_alsa_out.c:1388
msgid ""
"xine will use this alsa device to output 4 channel (4.0) surround sound.\n"
"See the alsa documentation for information on alsa devices."
@@ -126,39 +126,39 @@ msgstr ""
# src/audio_out/audio_alsa_out.c:221 src/audio_out/audio_alsa_out.c:232
# src/audio_out/audio_alsa_out.c:941 src/audio_out/audio_alsa_out.c:948
-#: src/audio_out/audio_alsa_out.c:1400 src/audio_out/audio_alsa_out.c:1410
+#: src/audio_out/audio_alsa_out.c:1397 src/audio_out/audio_alsa_out.c:1407
msgid "device used for 5.1-channel output"
msgstr "urządzenie użyte do wyjścia 5.1-kanałowego"
-#: src/audio_out/audio_alsa_out.c:1401
+#: src/audio_out/audio_alsa_out.c:1398
msgid ""
"xine will use this alsa device to output 5 channel plus LFE (5.1) surround "
"sound.\n"
"See the alsa documentation for information on alsa devices."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1411
+#: src/audio_out/audio_alsa_out.c:1408
msgid ""
"xine will use this alsa device to output undecoded digital surround sound. "
"This can be used be external surround decoders.\n"
"See the alsa documentation for information on alsa devices."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1431
+#: src/audio_out/audio_alsa_out.c:1428
#, fuzzy, c-format
msgid "snd_pcm_open() failed:%d:%s\n"
msgstr "osd: zawiodło iconv_open()\n"
-#: src/audio_out/audio_alsa_out.c:1433
+#: src/audio_out/audio_alsa_out.c:1430
#, c-format
msgid ">>> Check if another program already uses PCM <<<\n"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1464 src/audio_out/audio_oss_out.c:929
+#: src/audio_out/audio_alsa_out.c:1461 src/audio_out/audio_oss_out.c:929
msgid "speaker arrangement"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1465 src/audio_out/audio_oss_out.c:930
+#: src/audio_out/audio_alsa_out.c:1462 src/audio_out/audio_oss_out.c:930
msgid ""
"Select how your speakers are arranged, this determines which speakers xine "
"uses for sound output. The individual values are:\n"
@@ -190,87 +190,87 @@ msgid ""
"formats you want to play to your sound card's digital output."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1494
+#: src/audio_out/audio_alsa_out.c:1491
msgid "audio_alsa_out : supported modes are "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1497
+#: src/audio_out/audio_alsa_out.c:1494
msgid "8bit "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1502
+#: src/audio_out/audio_alsa_out.c:1499
msgid "16bit "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1506
+#: src/audio_out/audio_alsa_out.c:1503
msgid "24bit "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1510
+#: src/audio_out/audio_alsa_out.c:1507
msgid "32bit "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1521
+#: src/audio_out/audio_alsa_out.c:1518
msgid "mono "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1525
+#: src/audio_out/audio_alsa_out.c:1522
msgid "stereo "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1530
+#: src/audio_out/audio_alsa_out.c:1527
msgid "4-channel "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1533
+#: src/audio_out/audio_alsa_out.c:1530
msgid "(4-channel not enabled in xine config) "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1538
+#: src/audio_out/audio_alsa_out.c:1535
msgid "4.1-channel "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1541
+#: src/audio_out/audio_alsa_out.c:1538
msgid "(4.1-channel not enabled in xine config) "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1546
+#: src/audio_out/audio_alsa_out.c:1543
msgid "5-channel "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1549
+#: src/audio_out/audio_alsa_out.c:1546
msgid "(5-channel not enabled in xine config) "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1554
+#: src/audio_out/audio_alsa_out.c:1551
msgid "5.1-channel "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1557
+#: src/audio_out/audio_alsa_out.c:1554
msgid "(5.1-channel not enabled in xine config) "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1580
+#: src/audio_out/audio_alsa_out.c:1577
msgid "a/52 and DTS pass-through\n"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1583
+#: src/audio_out/audio_alsa_out.c:1580
msgid "(a/52 and DTS pass-through not enabled in xine config)\n"
msgstr ""
# src/audio_out/audio_alsa_out.c:862 src/audio_out/audio_alsa_out.c:1072
-#: src/audio_out/audio_alsa_out.c:1590
+#: src/audio_out/audio_alsa_out.c:1587
msgid "alsa mixer device"
msgstr "urzÄ…dzenie miksera alsa"
-#: src/audio_out/audio_alsa_out.c:1591
+#: src/audio_out/audio_alsa_out.c:1588
msgid ""
"xine will use this alsa mixer device to change the volume.\n"
"See the alsa documentation for information on alsa devices."
msgstr ""
# src/audio_out/audio_alsa_out.c:1105
-#: src/audio_out/audio_alsa_out.c:1665
+#: src/audio_out/audio_alsa_out.c:1662
msgid "xine audio output plugin using alsa-compliant audio devices/drivers"
msgstr ""
"wtyczka wyjścia dźwięku xine używająca sprzętu/sterowników kompatybilnych z "
@@ -287,207 +287,207 @@ msgstr "wtyczka wyjścia dźwięku używająca kde artsd"
msgid "xine output plugin for Coreaudio/Mac OS X"
msgstr "wtyczka wyjścia dźwięku używająca kde artsd"
-#: src/audio_out/audio_directx2_out.c:166
+#: src/audio_out/audio_directx2_out.c:163
msgid "Error"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:173
+#: src/audio_out/audio_directx2_out.c:170
msgid "success"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:175
+#: src/audio_out/audio_directx2_out.c:172
msgid "access denied"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:177
+#: src/audio_out/audio_directx2_out.c:174
msgid "resource is already in use"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:178
+#: src/audio_out/audio_directx2_out.c:175
msgid "object was already initialized"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:179
+#: src/audio_out/audio_directx2_out.c:176
msgid "specified wave format is not supported"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:180
+#: src/audio_out/audio_directx2_out.c:177
msgid "memory buffer has been lost and must be restored"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:181
+#: src/audio_out/audio_directx2_out.c:178
msgid "requested buffer control is not available"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:182
+#: src/audio_out/audio_directx2_out.c:179
msgid "undetermined error inside DirectSound subsystem"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:184
+#: src/audio_out/audio_directx2_out.c:181
msgid "DirectSound hardware device is unavailable"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:186
+#: src/audio_out/audio_directx2_out.c:183
msgid "function is not valid for the current state of the object"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:187
+#: src/audio_out/audio_directx2_out.c:184
msgid "invalid parameter was passed"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:188
+#: src/audio_out/audio_directx2_out.c:185
msgid "object doesn't support aggregation"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:189
+#: src/audio_out/audio_directx2_out.c:186
msgid "no sound driver available for use"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:190
+#: src/audio_out/audio_directx2_out.c:187
msgid "requested COM interface not available"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:191
+#: src/audio_out/audio_directx2_out.c:188
msgid "another application has a higher priority level"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:192
+#: src/audio_out/audio_directx2_out.c:189
msgid "insufficient memory"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:193
+#: src/audio_out/audio_directx2_out.c:190
msgid "low priority level for this function"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:194
+#: src/audio_out/audio_directx2_out.c:191
msgid "DirectSound wasn't initialized"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:195
+#: src/audio_out/audio_directx2_out.c:192
msgid "function is not supported"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:196
+#: src/audio_out/audio_directx2_out.c:193
msgid "unknown error"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:206
+#: src/audio_out/audio_directx2_out.c:203
#, c-format
msgid "Unable to create direct sound object."
msgstr ""
-#: src/audio_out/audio_directx2_out.c:212
+#: src/audio_out/audio_directx2_out.c:209
#, c-format
msgid "Could not set direct sound cooperative level."
msgstr ""
-#: src/audio_out/audio_directx2_out.c:286
+#: src/audio_out/audio_directx2_out.c:283
msgid "Unable to create secondary direct sound buffer"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:310
+#: src/audio_out/audio_directx2_out.c:307
#, c-format
msgid "Unable to create buffer position events."
msgstr ""
-#: src/audio_out/audio_directx2_out.c:318
+#: src/audio_out/audio_directx2_out.c:315
msgid "Unable to get notification interface"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:323
+#: src/audio_out/audio_directx2_out.c:320
msgid "Unable to set notification positions"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:343
+#: src/audio_out/audio_directx2_out.c:340
msgid "Couldn't play sound buffer"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:355
+#: src/audio_out/audio_directx2_out.c:352
msgid "Couldn't stop sound buffer"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:368
+#: src/audio_out/audio_directx2_out.c:365
msgid "Can't get buffer position"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:382
+#: src/audio_out/audio_directx2_out.c:379
msgid "Can't set buffer position"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:414
+#: src/audio_out/audio_directx2_out.c:411
msgid "Can't set sound volume"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:432
+#: src/audio_out/audio_directx2_out.c:429
#, c-format
msgid ": buffer lost, tryig to restore\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:436
+#: src/audio_out/audio_directx2_out.c:433
msgid "Couldn't lock direct sound buffer"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:447
+#: src/audio_out/audio_directx2_out.c:444
msgid "Couldn't unlock direct sound buffer"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:544
+#: src/audio_out/audio_directx2_out.c:541
#, c-format
msgid "Unable to create primary direct sound buffer."
msgstr ""
-#: src/audio_out/audio_directx2_out.c:637
+#: src/audio_out/audio_directx2_out.c:634
#, c-format
msgid ": play cursor overran, flushing buffers\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:655
+#: src/audio_out/audio_directx2_out.c:652
#, c-format
msgid ": delayed by %ld msec\n"
msgstr ""
# src/xine-engine/video_out.c:890
-#: src/audio_out/audio_directx2_out.c:759
+#: src/audio_out/audio_directx2_out.c:756
#, fuzzy, c-format
msgid ": can't create pthread condition: %s\n"
msgstr "video_out: nie mogę utworzyć wątku (%s)\n"
# src/xine-engine/video_out.c:890
-#: src/audio_out/audio_directx2_out.c:763
+#: src/audio_out/audio_directx2_out.c:760
#, fuzzy, c-format
msgid ": can't create pthread mutex: %s\n"
msgstr "video_out: nie mogę utworzyć wątku (%s)\n"
# src/input/input_rtp.c:339
-#: src/audio_out/audio_directx2_out.c:770
+#: src/audio_out/audio_directx2_out.c:767
#, fuzzy, c-format
msgid ": can't create buffer pthread: %s\n"
msgstr "input_rtp: nie mogę utworzyć nowego wątku (%s)\n"
# src/xine-engine/video_out.c:890
-#: src/audio_out/audio_directx2_out.c:877
+#: src/audio_out/audio_directx2_out.c:874
#, fuzzy, c-format
msgid ": can't destroy buffer pthread: %s\n"
msgstr "video_out: nie mogę utworzyć wątku (%s)\n"
-#: src/audio_out/audio_directx2_out.c:884
+#: src/audio_out/audio_directx2_out.c:881
#, c-format
msgid ": can't destroy pthread condition: %s\n"
msgstr ""
# src/xine-engine/video_out.c:890
-#: src/audio_out/audio_directx2_out.c:887
+#: src/audio_out/audio_directx2_out.c:884
#, fuzzy, c-format
msgid ": can't destroy pthread mutex: %s\n"
msgstr "video_out: nie mogę utworzyć wątku (%s)\n"
-#: src/audio_out/audio_directx2_out.c:947
+#: src/audio_out/audio_directx2_out.c:944
#, c-format
msgid ": unknown control command %d\n"
msgstr ""
# src/audio_out/audio_esd_out.c:441
-#: src/audio_out/audio_directx2_out.c:1003
+#: src/audio_out/audio_directx2_out.c:1000
#, fuzzy
msgid "second xine audio output plugin using directx"
msgstr "wtyczka wyjścia dźwięku używająca kde artsd"
@@ -919,7 +919,7 @@ msgstr "demux_snd: błędne parametry nagłówka\n"
msgid "demux_snd: unsupported audio type: %d\n"
msgstr "demux_snd: niewspierany typ dźwięku %d\n"
-#: src/demuxers/demux_tta.c:88
+#: src/demuxers/demux_tta.c:86
msgid "demux_tta: total frames count too high\n"
msgstr ""
@@ -944,7 +944,7 @@ msgid "demux_wc3movie: SHOT chunk referenced invalid palette (%d >= %d)\n"
msgstr ""
"demux_wc3movie: fragment zrzutu odnosi się do błędnej palety (%d >= %d)\n"
-#: src/demuxers/demux_wc3movie.c:406
+#: src/demuxers/demux_wc3movie.c:404
#, c-format
msgid "demux_wc3movie: There was a problem while loading palette chunks\n"
msgstr "demux_wc3movie: Wystąpił problem przy ładowaniu fragmentów palety\n"
@@ -1342,43 +1342,43 @@ msgid "video_out_dxr3: ERROR Reading overlay init file. Run autocal!\n"
msgstr ""
# src/input/input_http.c:134
-#: src/input/input_cdda.c:1621
+#: src/input/input_cdda.c:1608
#, fuzzy, c-format
msgid "%s: can't connect to %s:%d\n"
msgstr "http: nie mogę się podłączyć do >%s<\n"
-#: src/input/input_cdda.c:1668
+#: src/input/input_cdda.c:1655
#, c-format
msgid "input_cdda: successfuly connected to cddb server '%s:%d'.\n"
msgstr ""
# src/input/input_net.c:138
-#: src/input/input_cdda.c:1673
+#: src/input/input_cdda.c:1660
#, fuzzy, c-format
msgid "input_cdda: failed to connect to cddb server '%s:%d' (%s).\n"
msgstr "input_net: nie mogę podłączyć się do '%s'.\n"
-#: src/input/input_cdda.c:2707
+#: src/input/input_cdda.c:2690
msgid "CD Digital Audio (aka. CDDA)"
msgstr ""
# src/audio_out/audio_alsa_out.c:201 src/audio_out/audio_alsa_out.c:927
-#: src/input/input_cdda.c:2760
+#: src/input/input_cdda.c:2742
#, fuzzy
msgid "device used for CD audio"
msgstr "urządzenie użyte do wyjścia 4-kanałowego"
-#: src/input/input_cdda.c:2761
+#: src/input/input_cdda.c:2743
msgid ""
"The path to the device, usually a CD or DVD drive, which you intend to use "
"for playing audio CDs."
msgstr ""
-#: src/input/input_cdda.c:2767
+#: src/input/input_cdda.c:2749
msgid "query CDDB"
msgstr ""
-#: src/input/input_cdda.c:2767
+#: src/input/input_cdda.c:2749
msgid ""
"Enables CDDB queries, which will give you convenient title and track names "
"for your audio CDs.\n"
@@ -1387,11 +1387,11 @@ msgid ""
"listening habits."
msgstr ""
-#: src/input/input_cdda.c:2775
+#: src/input/input_cdda.c:2757
msgid "CDDB server name"
msgstr ""
-#: src/input/input_cdda.c:2775
+#: src/input/input_cdda.c:2757
msgid ""
"The CDDB server used to retrieve the title and track information from.\n"
"This setting is security critical, because the sever will receive "
@@ -1399,31 +1399,19 @@ msgid ""
"malicious replies. Be sure to enter a server you can trust."
msgstr ""
-#: src/input/input_cdda.c:2783
+#: src/input/input_cdda.c:2765
msgid "CDDB server port"
msgstr ""
-#: src/input/input_cdda.c:2783
+#: src/input/input_cdda.c:2765
msgid "The server port used to retrieve the title and track information from."
msgstr ""
-#: src/input/input_cdda.c:2789
-msgid "CDDB cache directory"
-msgstr ""
-
-#: src/input/input_cdda.c:2789
-msgid ""
-"The replies from the CDDB server will be cached in this directory.\n"
-"This setting is security critical, because files with uncontrollable names "
-"will be created in this directory. Be sure to use a dedicated directory not "
-"used for anything but CDDB caching."
-msgstr ""
-
-#: src/input/input_cdda.c:2797
+#: src/input/input_cdda.c:2771
msgid "slow down disc drive to this speed factor"
msgstr ""
-#: src/input/input_cdda.c:2798
+#: src/input/input_cdda.c:2772
msgid ""
"Since some CD or DVD drives make some really loud noises because of the fast "
"disc rotation, xine will try to slow them down. With standard CD or DVD "
@@ -1433,123 +1421,129 @@ msgid ""
msgstr ""
# src/input/input_http.c:98
-#: src/input/input_dvb.c:881
+#: src/input/input_dvb.c:899
#, fuzzy, c-format
-msgid "input_dvb: failed to open dvb channel file '%s'\n"
+msgid "input_dvb: failed to open dvb channel file '%s': %s\n"
msgstr "input_http: otwarcie gniazda zawiodło\n"
-#: src/input/input_dvb.c:2082 src/input/input_dvb.c:2910
+# src/input/input_http.c:98
+#: src/input/input_dvb.c:905
+#, fuzzy, c-format
+msgid "input_dvb: dvb channel file '%s' is not a plain file\n"
+msgstr "input_http: otwarcie gniazda zawiodło\n"
+
+#: src/input/input_dvb.c:2115 src/input/input_dvb.c:2943
msgid "input_dvb: tuner_set_channel failed\n"
msgstr ""
-#: src/input/input_dvb.c:2710
+#: src/input/input_dvb.c:2743
msgid "input_dvb: cannot open dvb device\n"
msgstr ""
-#: src/input/input_dvb.c:2734
+#: src/input/input_dvb.c:2767
#, c-format
msgid "input_dvb: channel %d out of range, defaulting to 0\n"
msgstr ""
# src/input/input_http.c:98
-#: src/input/input_dvb.c:2745
+#: src/input/input_dvb.c:2778
#, fuzzy, c-format
msgid "input_dvb: searching for channel %s\n"
msgstr "input_http: otwarcie gniazda zawiodło\n"
-#: src/input/input_dvb.c:2768
+#: src/input/input_dvb.c:2801
#, c-format
msgid "input_dvb: exact match for %s not found: trying partial matches\n"
msgstr ""
# src/input/input_http.c:98
-#: src/input/input_dvb.c:2775
+#: src/input/input_dvb.c:2808
#, fuzzy, c-format
msgid "input_dvb: found matching channel %s\n"
msgstr "input_http: otwarcie gniazda zawiodło\n"
-#: src/input/input_dvb.c:2788
+#: src/input/input_dvb.c:2821
#, c-format
msgid "input_dvb: channel %s not found in channels.conf, defaulting.\n"
msgstr ""
-#: src/input/input_dvb.c:2794
+#: src/input/input_dvb.c:2827
msgid ""
"input_dvb: invalid channel specification, defaulting to last viewed "
"channel.\n"
msgstr ""
-#: src/input/input_dvb.c:2800
+#: src/input/input_dvb.c:2833
msgid "input_dvb: invalid channel specification, defaulting to channel 0\n"
msgstr ""
-#: src/input/input_dvb.c:2812
+#: src/input/input_dvb.c:2845
msgid ""
"input_dvb: dvbs mrl specified but the tuner doesn't appear to be QPSK (DVB-"
"S)\n"
msgstr ""
-#: src/input/input_dvb.c:2832
+#: src/input/input_dvb.c:2865
msgid ""
"input_dvb: dvbt mrl specified but the tuner doesn't appear to be OFDM (DVB-"
"T)\n"
msgstr ""
-#: src/input/input_dvb.c:2855 src/input/input_dvb.c:2881
+#: src/input/input_dvb.c:2888 src/input/input_dvb.c:2914
msgid ""
"input_dvb: dvbc mrl specified but the tuner doesn't appear to be QAM (DVB-"
"C)\n"
msgstr ""
-#: src/input/input_dvb.c:2916
+#: src/input/input_dvb.c:2949
#, c-format
msgid "input_dvb: cannot open dvr device '%s'\n"
msgstr ""
# src/input/input_rtp.c:339
-#: src/input/input_dvb.c:2938
+#: src/input/input_dvb.c:2971
#, fuzzy
msgid "input_dvb: cannot create EPG updater thread\n"
msgstr "input_rtp: nie mogę utworzyć nowego wątku (%s)\n"
-#: src/input/input_dvb.c:3000
+#: src/input/input_dvb.c:3033
msgid "use DVB 'center cutout' (zoom)"
msgstr ""
-#: src/input/input_dvb.c:3001
+#: src/input/input_dvb.c:3034
msgid ""
"This will allow fullscreen playback of 4:3 content transmitted in a 16:9 "
"frame."
msgstr ""
-#: src/input/input_dvb.c:3094
+#: src/input/input_dvb.c:3127
#, fuzzy
msgid "DVB (Digital TV) input plugin"
msgstr "wtyczka wejścia pliku"
-#: src/input/input_dvb.c:3242
+#: src/input/input_dvb.c:3244
msgid "Remember last DVB channel watched"
msgstr ""
-#: src/input/input_dvb.c:3243
+#: src/input/input_dvb.c:3245
msgid ""
"On autoplay, xine will remember and switch to the channel indicated in media."
"dvb.last_channel. "
msgstr ""
-#: src/input/input_dvb.c:3250
+#: src/input/input_dvb.c:3252
msgid "Last DVB channel viewed"
msgstr ""
-#: src/input/input_dvb.c:3251
+#: src/input/input_dvb.c:3253
msgid "If enabled xine will remember and switch to this channel. "
msgstr ""
-#: src/input/input_dvb.c:3257
+#: src/input/input_dvb.c:3259
msgid "Number of dvb card to use."
msgstr ""
-#: src/input/input_dvb.c:3258
+#: src/input/input_dvb.c:3260
msgid ""
"Leave this at zero unless you really have more than 1 card in your system."
msgstr ""
@@ -1580,11 +1574,11 @@ msgid ""
"playing DVDs."
msgstr ""
-#: src/input/input_dvd.c:1800
+#: src/input/input_dvd.c:1799
msgid "raw device set up for DVD access"
msgstr ""
-#: src/input/input_dvd.c:1801
+#: src/input/input_dvd.c:1800
msgid ""
"If this points to a raw device connected to your DVD device, xine will use "
"the raw device for playback. This has the advantage of being slightly faster "
@@ -1595,70 +1589,55 @@ msgid ""
"See the documentation on raw device setup (man raw) for further information."
msgstr ""
-#: src/input/input_dvd.c:1814
+#: src/input/input_dvd.c:1813
msgid "CSS decryption method"
msgstr ""
-#: src/input/input_dvd.c:1815
+#: src/input/input_dvd.c:1814
msgid ""
"Selects the decryption method libdvdcss will use to descramble copy "
"protected DVDs. Try the various methods, if you have problems playing "
"scrambled DVDs."
msgstr ""
-# src/input/input_vcd.c:1184
-#: src/input/input_dvd.c:1823
-#, fuzzy
-msgid "path to the title key cache"
-msgstr "ścieżka dostępu do pliku lokalnego urządzenia vcd"
-
-#: src/input/input_dvd.c:1824
-msgid ""
-"Since cracking the copy protection of scrambled DVDs can be quite time "
-"consuming, libdvdcss will cache the cracked keys in this directory.\n"
-"This setting is security critical, because files with uncontrollable names "
-"will be created in this directory. Be sure to use a dedicated directory not "
-"used for anything but DVD key caching."
-msgstr ""
-
-#: src/input/input_dvd.c:1846
+#: src/input/input_dvd.c:1829
msgid "region the DVD player claims to be in (1 to 8)"
msgstr ""
-#: src/input/input_dvd.c:1847
+#: src/input/input_dvd.c:1830
msgid ""
"This only needs to be changed if your DVD jumps to a screen complaining "
"about a wrong region code. It has nothing to do with the region code set in "
"DVD drives, this is purely software."
msgstr ""
-#: src/input/input_dvd.c:1853
+#: src/input/input_dvd.c:1836
msgid "default language for DVD playback"
msgstr ""
-#: src/input/input_dvd.c:1854
+#: src/input/input_dvd.c:1837
msgid ""
"xine tries to use this language as a default for DVD playback. As far as the "
"DVD supports it, menus and audio tracks will be presented in this language.\n"
"The value must be a two character ISO639 language code."
msgstr ""
-#: src/input/input_dvd.c:1860
+#: src/input/input_dvd.c:1843
msgid "read-ahead caching"
msgstr ""
-#: src/input/input_dvd.c:1861
+#: src/input/input_dvd.c:1844
msgid ""
"xine can use a read ahead cache for DVD drive access.\n"
"This may lead to jerky playback on slow drives, but it improves the impact "
"of the DVD layer change on faster drives."
msgstr ""
-#: src/input/input_dvd.c:1867
+#: src/input/input_dvd.c:1850
msgid "unit for the skip action"
msgstr ""
-#: src/input/input_dvd.c:1868
+#: src/input/input_dvd.c:1851
msgid ""
"You can configure the behaviour when issuing a skip command (using the skip "
"buttons for example). The individual values mean:\n"
@@ -1677,11 +1656,11 @@ msgid ""
"features on the DVD"
msgstr ""
-#: src/input/input_dvd.c:1883
+#: src/input/input_dvd.c:1866
msgid "unit for seeking"
msgstr ""
-#: src/input/input_dvd.c:1884
+#: src/input/input_dvd.c:1867
msgid ""
"You can configure the domain spanned by the seek slider. The individual "
"values mean:\n"
@@ -1695,11 +1674,11 @@ msgid ""
"chapter of the current feature"
msgstr ""
-#: src/input/input_dvd.c:1895
+#: src/input/input_dvd.c:1878
msgid "play mode when title/chapter is given"
msgstr ""
-#: src/input/input_dvd.c:1896
+#: src/input/input_dvd.c:1879
msgid ""
"You can configure the behaviour when playing a dvd from a given title/"
"chapter (eg. using MRL 'dvd:/1.2'). The individual values mean:\n"
@@ -2452,7 +2431,7 @@ msgid ""
"2048: Debugging from VCDINFO\n"
msgstr ""
-#: src/liba52/xine_a52_decoder.c:742 src/libdts/xine_dts_decoder.c:546
+#: src/liba52/xine_a52_decoder.c:742 src/libxineadec/xine_dts_decoder.c:524
msgid "HELP! a mono-only audio driver?!\n"
msgstr ""
@@ -2509,61 +2488,61 @@ msgstr ""
msgid "libfaad: libfaad NeAACDecInit failed.\n"
msgstr ""
-#: src/libffmpeg/ff_audio_decoder.c:120
+#: src/libffmpeg/ff_audio_decoder.c:122
#, c-format
msgid "ffmpeg_audio_dec: increasing buffer to %d to avoid overflow.\n"
msgstr ""
-#: src/libffmpeg/ff_audio_decoder.c:164
+#: src/libffmpeg/ff_audio_decoder.c:166
#, c-format
msgid "ffmpeg_audio_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"
msgstr ""
-#: src/libffmpeg/ff_audio_decoder.c:256
+#: src/libffmpeg/ff_audio_decoder.c:258
msgid "ffmpeg_audio_dec: trying to open null codec\n"
msgstr ""
-#: src/libffmpeg/ff_audio_decoder.c:265
+#: src/libffmpeg/ff_audio_decoder.c:267
msgid "ffmpeg_audio_dec: couldn't open decoder\n"
msgstr ""
-#: src/libffmpeg/ff_dvaudio_decoder.c:286
+#: src/libffmpeg/ff_dvaudio_decoder.c:280
#, c-format
msgid "dvaudio: increasing buffer to %d to avoid overflow.\n"
msgstr ""
-#: src/libffmpeg/ff_video_decoder.c:157
+#: src/libffmpeg/ff_video_decoder.c:155
msgid "ffmpeg_video_dec: unsupported frame format, DR1 disabled.\n"
msgstr ""
-#: src/libffmpeg/ff_video_decoder.c:175
+#: src/libffmpeg/ff_video_decoder.c:173
msgid "ffmpeg_video_dec: unsupported frame dimensions, DR1 disabled.\n"
msgstr ""
-#: src/libffmpeg/ff_video_decoder.c:335
+#: src/libffmpeg/ff_video_decoder.c:333
#, c-format
msgid "ffmpeg_video_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"
msgstr ""
-#: src/libffmpeg/ff_video_decoder.c:364
+#: src/libffmpeg/ff_video_decoder.c:362
msgid "ffmpeg_video_dec: couldn't open decoder\n"
msgstr ""
-#: src/libffmpeg/ff_video_decoder.c:399
+#: src/libffmpeg/ff_video_decoder.c:397
msgid "ffmpeg_video_dec: direct rendering enabled\n"
msgstr ""
-#: src/libffmpeg/ff_video_decoder.c:818
+#: src/libffmpeg/ff_video_decoder.c:816
#, c-format
msgid "ffmpeg_video_dec: increasing buffer to %d to avoid overflow.\n"
msgstr ""
-#: src/libffmpeg/ff_video_decoder.c:1516
+#: src/libffmpeg/ff_video_decoder.c:1514
#, fuzzy
msgid "MPEG-4 postprocessing quality"
msgstr "jakość post-przetwarzania ffmpeg mpeg-4"
-#: src/libffmpeg/ff_video_decoder.c:1517
+#: src/libffmpeg/ff_video_decoder.c:1515
msgid ""
"You can adjust the amount of post processing applied to MPEG-4 video.\n"
"Higher values result in better quality, but need more CPU. Lower values may "
@@ -2573,60 +2552,60 @@ msgid ""
msgstr ""
# src/dxr3/dxr3_mpeg_encoders.c:182
-#: src/libffmpeg/ffmpeg_encoder.c:167
+#: src/libffmpeg/ffmpeg_encoder.c:163
#, fuzzy
msgid "libavcodec mpeg output bitrate (kbit/s)"
msgstr "dxr3enc: częstotliwość wyjśćia rte mpeg (kbit/s)"
-#: src/libffmpeg/ffmpeg_encoder.c:168
+#: src/libffmpeg/ffmpeg_encoder.c:164
msgid ""
"The bitrate the libavcodec mpeg encoder should use for DXR3's encoding mode. "
"Higher values will increase quality and CPU usage.\n"
"This setting is only considered, when constant quality mode is disabled."
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:175
+#: src/libffmpeg/ffmpeg_encoder.c:171
msgid "constant quality mode"
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:176
+#: src/libffmpeg/ffmpeg_encoder.c:172
msgid ""
"When enabled, libavcodec will use a constant quality mode by dynamically "
"compressing the images based on their complexity. When disabled, libavcodec "
"will use constant bitrate mode."
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:183
+#: src/libffmpeg/ffmpeg_encoder.c:179
msgid "minimum compression"
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:184
+#: src/libffmpeg/ffmpeg_encoder.c:180
msgid "The minimum compression to apply to an image in constant quality mode."
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:189
+#: src/libffmpeg/ffmpeg_encoder.c:185
msgid "maximum quantizer"
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:190
+#: src/libffmpeg/ffmpeg_encoder.c:186
msgid "The maximum compression to apply to an image in constant quality mode."
msgstr ""
-#: src/libmusepack/xine_musepack_decoder.c:241
+#: src/libxineadec/xine_musepack_decoder.c:249
#, c-format
msgid "libmusepack: mpc_streaminfo_read failed: %d\n"
msgstr ""
-#: src/libmusepack/xine_musepack_decoder.c:315
+#: src/libxineadec/xine_musepack_decoder.c:323
msgid "libmusepack: data after last frame ignored\n"
msgstr ""
-#: src/libmusepack/xine_musepack_decoder.c:326
+#: src/libxineadec/xine_musepack_decoder.c:334
msgid "libmusepack: mpc_decoder_initialise failed\n"
msgstr ""
-#: src/libmusepack/xine_musepack_decoder.c:346
-#: src/libmusepack/xine_musepack_decoder.c:361
+#: src/libxineadec/xine_musepack_decoder.c:354
+#: src/libxineadec/xine_musepack_decoder.c:369
#, c-format
msgid "libmusepack: mpc_decoder_decode failed: %d\n"
msgstr ""
@@ -3359,7 +3338,7 @@ msgid "Select the video output layer by its id."
msgstr ""
#: src/video_out/video_out_directfb.c:1804
-#: src/video_out/video_out_directfb.c:2013
+#: src/video_out/video_out_directfb.c:2014
#, c-format
msgid "video_out_directfb: using display layer #%d.\n"
msgstr ""
@@ -3370,12 +3349,12 @@ msgstr ""
msgid "xine video output plugin using DirectFB."
msgstr "wtyczka wyjścia obrazu xine używająca biblioteki DirectFB"
-#: src/video_out/video_out_directfb.c:2006
+#: src/video_out/video_out_directfb.c:2007
msgid "video_out_directfb: no usable display layer was found!\n"
msgstr ""
# src/video_out/video_out_directfb.c:569
-#: src/video_out/video_out_directfb.c:2095
+#: src/video_out/video_out_directfb.c:2096
#, fuzzy
msgid "xine video output plugin using DirectFB under XDirectFB."
msgstr "wtyczka wyjścia obrazu xine używająca biblioteki DirectFB"
@@ -3386,7 +3365,7 @@ msgstr "wtyczka wyjścia obrazu xine używająca biblioteki DirectFB"
msgid "xine video output plugin for win32 using directx"
msgstr "wtyczka wyjścia obrazu xine używająca libvidix dla X11"
-#: src/video_out/video_out_fb.c:792
+#: src/video_out/video_out_fb.c:780
#, c-format
msgid ""
"video_out_fb: only packed truecolor/directcolor is supported (%d).\n"
@@ -3394,12 +3373,12 @@ msgid ""
msgstr ""
# src/video_out/video_out_fb.c:721
-#: src/video_out/video_out_fb.c:852 src/video_out/video_out_vidix.c:1239
+#: src/video_out/video_out_fb.c:840 src/video_out/video_out_vidix.c:1239
#, fuzzy
msgid "framebuffer device name"
msgstr "urzÄ…dzenie buforu ramki"
-#: src/video_out/video_out_fb.c:853 src/video_out/video_out_vidix.c:1240
+#: src/video_out/video_out_fb.c:841 src/video_out/video_out_vidix.c:1240
msgid ""
"Specifies the file name for the framebuffer device to be used.\n"
"This setting is security critical, because when changed to a different file, "
@@ -3407,40 +3386,41 @@ msgid ""
"careful that the value you enter really is a proper framebuffer device."
msgstr ""
-#: src/video_out/video_out_fb.c:927
-msgid "video_out_fb: Your video mode was not recognized, sorry.\n"
+#: src/video_out/video_out_fb.c:915
+#, c-format
+msgid "%s: Your video mode was not recognized, sorry.\n"
msgstr ""
-#: src/video_out/video_out_fb.c:984
+#: src/video_out/video_out_fb.c:972
#, c-format
-msgid "video_out_fb: %d video RAM buffers are available.\n"
+msgid "%s: %d video RAM buffers are available.\n"
msgstr ""
-#: src/video_out/video_out_fb.c:990
+#: src/video_out/video_out_fb.c:978
#, c-format
msgid ""
-"WARNING: video_out_fb: Zero copy buffers are DISABLED because only %d "
-"buffers\n"
+"WARNING: %s: Zero copy buffers are DISABLED because only %d buffers\n"
" are available which is less than the recommended %d buffers. Lowering\n"
" the frame buffer resolution might help.\n"
msgstr ""
-#: src/video_out/video_out_fb.c:1001
+#: src/video_out/video_out_fb.c:989
+#, c-format
msgid ""
-"WARNING: video_out_fb: Zero copy buffers are DISABLED because kernel driver\n"
+"WARNING: %s: Zero copy buffers are DISABLED because kernel driver\n"
" do not support screen panning (used for frame flips).\n"
msgstr ""
-#: src/video_out/video_out_fb.c:1070
+#: src/video_out/video_out_fb.c:1058
#, c-format
msgid ""
-"WARNING: video_out_fb: current display depth is %d. For better performance\n"
+"WARNING: %s: current display depth is %d. For better performance\n"
" a depth of 16 bpp is recommended!\n"
"\n"
msgstr ""
# src/video_out/video_out_fb.c:885
-#: src/video_out/video_out_fb.c:1101
+#: src/video_out/video_out_fb.c:1090
msgid "Xine video output plugin using the Linux frame buffer device"
msgstr ""
"xtyczka wyjścia obrazu xine używająca linuxowego urządzenia buforu ramki"
@@ -3495,8 +3475,8 @@ msgid ""
msgstr ""
#: src/video_out/video_out_opengl.c:1918 src/video_out/video_out_vidix.c:1015
-#: src/video_out/video_out_xcbxv.c:1472 src/video_out/video_out_xv.c:1486
-#: src/video_out/video_out_xvmc.c:1461 src/video_out/video_out_xxmc.c:2468
+#: src/video_out/video_out_xcbxv.c:1476 src/video_out/video_out_xv.c:1489
+#: src/video_out/video_out_xvmc.c:1461 src/video_out/video_out_xxmc.c:2465
msgid "enable double buffering"
msgstr ""
@@ -3574,9 +3554,9 @@ msgid "video_out_pgx64: Error: ioctl failed (FBIOGATTR)\n"
msgstr ""
# src/dxr3/video_out_dxr3.c:287
-#: src/video_out/video_out_pgx64.c:1464 src/video_out/video_out_xcbxv.c:1439
-#: src/video_out/video_out_xv.c:1453 src/video_out/video_out_xvmc.c:1446
-#: src/video_out/video_out_xxmc.c:2435
+#: src/video_out/video_out_pgx64.c:1464 src/video_out/video_out_xcbxv.c:1443
+#: src/video_out/video_out_xv.c:1456 src/video_out/video_out_xvmc.c:1446
+#: src/video_out/video_out_xxmc.c:2432
#, fuzzy
msgid "video overlay colour key"
msgstr "dxr3: wartość koloru kluczowego dla overlay"
@@ -3732,9 +3712,9 @@ msgstr ""
msgid "The intensity of the blue colour components."
msgstr ""
-#: src/video_out/video_out_vidix.c:1016 src/video_out/video_out_xcbxv.c:1473
-#: src/video_out/video_out_xv.c:1487 src/video_out/video_out_xvmc.c:1462
-#: src/video_out/video_out_xxmc.c:2469
+#: src/video_out/video_out_vidix.c:1016 src/video_out/video_out_xcbxv.c:1477
+#: src/video_out/video_out_xv.c:1490 src/video_out/video_out_xvmc.c:1462
+#: src/video_out/video_out_xxmc.c:2466
msgid ""
"Double buffering will synchronize the update of the video image to the "
"repainting of the entire screen (\"vertical retrace\"). This eliminates "
@@ -3769,9 +3749,9 @@ msgid "video overlay colour key red component"
msgstr "dxr3: zakres koloru kluczowego"
#: src/video_out/video_out_vidix.c:1159 src/video_out/video_out_vidix.c:1166
-#: src/video_out/video_out_vidix.c:1173 src/video_out/video_out_xcbxv.c:1440
-#: src/video_out/video_out_xv.c:1454 src/video_out/video_out_xvmc.c:1447
-#: src/video_out/video_out_xxmc.c:2436
+#: src/video_out/video_out_vidix.c:1173 src/video_out/video_out_xcbxv.c:1444
+#: src/video_out/video_out_xv.c:1457 src/video_out/video_out_xvmc.c:1447
+#: src/video_out/video_out_xxmc.c:2433
msgid ""
"The colour key is used to tell the graphics card where to overlay the video "
"image. Try different values, if you experience windows becoming transparent."
@@ -3801,27 +3781,40 @@ msgstr ""
"wtyczka wyjścia obrazu xine używająca libvidix dla linuxowego urządzenia "
"buforu ramki"
-#: src/video_out/video_out_xcbshm.c:157
+#: src/video_out/video_out_xcbshm.c:157 src/video_out/video_out_xshm.c:219
#, c-format
-msgid ""
-"video_out_xcbshm: %s: allocating image\n"
-"video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+msgid "%s: %s: allocating image\n"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:166
-msgid ""
-"video_out_xcbshm: shared memory error (address error) when allocating "
-"image \n"
-"video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+# src/video_out/video_out_xshm.c:1445
+#: src/video_out/video_out_xcbshm.c:159 src/video_out/video_out_xcbshm.c:169
+#: src/video_out/video_out_xcbshm.c:181 src/video_out/video_out_xcbxv.c:272
+#: src/video_out/video_out_xcbxv.c:282 src/video_out/video_out_xcbxv.c:292
+#: src/video_out/video_out_xcbxv.c:304 src/video_out/video_out_xshm.c:204
+#: src/video_out/video_out_xshm.c:221 src/video_out/video_out_xshm.c:232
+#: src/video_out/video_out_xshm.c:251 src/video_out/video_out_xv.c:296
+#: src/video_out/video_out_xv.c:307 src/video_out/video_out_xv.c:316
+#: src/video_out/video_out_xv.c:352 src/video_out/video_out_xxmc.c:648
+#: src/video_out/video_out_xxmc.c:659 src/video_out/video_out_xxmc.c:668
+#: src/video_out/video_out_xxmc.c:704
+#, fuzzy, c-format
+msgid "%s: => not using MIT Shared Memory extension.\n"
msgstr ""
+"wtyczka wyjścia obrazu xine używajaca rozszerzenie dzielonej pamięci MIT X"
-#: src/video_out/video_out_xcbshm.c:177
-msgid ""
-"video_out_xcbshm: x11 error during shared memory XImage creation\n"
-"video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbshm.c:167 src/video_out/video_out_xshm.c:230
+#, c-format
+msgid "%s: shared memory error (address error) when allocating image \n"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:1100 src/video_out/video_out_xshm.c:1157
+#: src/video_out/video_out_xcbshm.c:179 src/video_out/video_out_xcbxv.c:302
+#: src/video_out/video_out_xshm.c:249 src/video_out/video_out_xv.c:350
+#: src/video_out/video_out_xxmc.c:702
+#, c-format
+msgid "%s: x11 error during shared memory XImage creation\n"
+msgstr ""
+
+#: src/video_out/video_out_xcbshm.c:1103 src/video_out/video_out_xshm.c:1161
#, c-format
msgid ""
"\n"
@@ -3831,79 +3824,81 @@ msgid ""
"\n"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:1113
-msgid "video_out_xcbshm: MIT shared memory extension not present on display.\n"
+#: src/video_out/video_out_xcbshm.c:1116 src/video_out/video_out_xshm.c:1174
+#, c-format
+msgid "%s: MIT shared memory extension not present on display.\n"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:1212
-msgid "video_out_xcbshm: your video mode was not recognized, sorry :-(\n"
+#: src/video_out/video_out_xcbshm.c:1215 src/video_out/video_out_xshm.c:1258
+#, c-format
+msgid "%s: your video mode was not recognized, sorry :-(\n"
msgstr ""
# src/video_out/video_out_xshm.c:1445
-#: src/video_out/video_out_xcbshm.c:1242 src/video_out/video_out_xshm.c:1303
+#: src/video_out/video_out_xcbshm.c:1245 src/video_out/video_out_xshm.c:1307
msgid "xine video output plugin using the MIT X shared memory extension"
msgstr ""
"wtyczka wyjścia obrazu xine używajaca rozszerzenie dzielonej pamięci MIT X"
-#: src/video_out/video_out_xcbxv.c:272
-msgid ""
-"video_out_xcbxv: XvShmCreateImage returned a zero size\n"
-"video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbxv.c:270 src/video_out/video_out_xv.c:305
+#: src/video_out/video_out_xxmc.c:657
+#, c-format
+msgid "%s: XvShmCreateImage returned a zero size\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:281
+#: src/video_out/video_out_xcbxv.c:280 src/video_out/video_out_xv.c:314
+#: src/video_out/video_out_xxmc.c:666
#, c-format
-msgid ""
-"video_out_xcbxv: shared memory error in shmget: %s\n"
-"video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+msgid "%s: shared memory error in shmget: %s\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:300
-msgid ""
-"video_out_xcbxv: x11 error during shared memory XImage creation\n"
-"video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbxv.c:290
+#, c-format
+msgid "%s: shared memory error (address error)\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1291
-msgid "video_out_xcbxv: Xv extension not present.\n"
+#: src/video_out/video_out_xcbxv.c:1294 src/video_out/video_out_xv.c:1301
+#: src/video_out/video_out_xxmc.c:2283
+#, c-format
+msgid "%s: Xv extension not present.\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1333
+#: src/video_out/video_out_xcbxv.c:1336 src/video_out/video_out_xv.c:1338
+#: src/video_out/video_out_xxmc.c:2320
+#, c-format
msgid ""
-"video_out_xcbxv: Xv extension is present but I couldn't find a usable yuv12 "
-"port.\n"
-" Looks like your graphics hardware driver doesn't support "
-"Xv?!\n"
+"%s: Xv extension is present but I couldn't find a usable yuv12 port.\n"
+"\tLooks like your graphics hardware driver doesn't support Xv?!\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1341
+#: src/video_out/video_out_xcbxv.c:1345
#, c-format
msgid ""
-"video_out_xcbxv: using Xv port %d from adaptor %s for hardware colorspace "
-"conversion and scaling.\n"
+"%s: using Xv port %d from adaptor %s for hardware colorspace conversion and "
+"scaling.\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1448 src/video_out/video_out_xv.c:1462
-#: src/video_out/video_out_xvmc.c:1455 src/video_out/video_out_xxmc.c:2444
+#: src/video_out/video_out_xcbxv.c:1452 src/video_out/video_out_xv.c:1465
+#: src/video_out/video_out_xvmc.c:1455 src/video_out/video_out_xxmc.c:2441
#, fuzzy
msgid "autopaint colour key"
msgstr "Auto-tworzenie koloru-klucza przez Xv"
-#: src/video_out/video_out_xcbxv.c:1449 src/video_out/video_out_xv.c:1463
-#: src/video_out/video_out_xvmc.c:1456 src/video_out/video_out_xxmc.c:2445
+#: src/video_out/video_out_xcbxv.c:1453 src/video_out/video_out_xv.c:1466
+#: src/video_out/video_out_xvmc.c:1456 src/video_out/video_out_xxmc.c:2442
#, fuzzy
msgid "Make Xv autopaint its colorkey."
msgstr "Auto-tworzenie koloru-klucza przez Xv"
# src/video_out/video_out_xv.c:1408
-#: src/video_out/video_out_xcbxv.c:1456 src/video_out/video_out_xv.c:1470
-#: src/video_out/video_out_xxmc.c:2452
+#: src/video_out/video_out_xcbxv.c:1460 src/video_out/video_out_xv.c:1473
+#: src/video_out/video_out_xxmc.c:2449
#, fuzzy
msgid "bilinear scaling mode"
msgstr "tryb skalowania bilinearnego (permedia 2/3)"
-#: src/video_out/video_out_xcbxv.c:1457 src/video_out/video_out_xv.c:1471
-#: src/video_out/video_out_xxmc.c:2453
+#: src/video_out/video_out_xcbxv.c:1461 src/video_out/video_out_xv.c:1474
+#: src/video_out/video_out_xxmc.c:2450
msgid ""
"Selects the bilinear scaling mode for Permedia cards. The individual values "
"are:\n"
@@ -3918,30 +3913,34 @@ msgid ""
"2 - enable full bilinear filtering"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1509
-msgid "video_out_xcbxv: this adaptor supports the yv12 format.\n"
+#: src/video_out/video_out_xcbxv.c:1513 src/video_out/video_out_xv.c:1523
+#: src/video_out/video_out_xxmc.c:2506
+#, c-format
+msgid "%s: this adaptor supports the yv12 format.\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1514
-msgid "video_out_xcbxv: this adaptor supports the yuy2 format.\n"
+#: src/video_out/video_out_xcbxv.c:1518 src/video_out/video_out_xv.c:1528
+#: src/video_out/video_out_xxmc.c:2511
+#, c-format
+msgid "%s: this adaptor supports the yuy2 format.\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1522 src/video_out/video_out_xv.c:1547
-#: src/video_out/video_out_xxmc.c:2537
+#: src/video_out/video_out_xcbxv.c:1526 src/video_out/video_out_xv.c:1550
+#: src/video_out/video_out_xxmc.c:2534
msgid "pitch alignment workaround"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1523 src/video_out/video_out_xv.c:1548
-#: src/video_out/video_out_xxmc.c:2538
+#: src/video_out/video_out_xcbxv.c:1527 src/video_out/video_out_xv.c:1551
+#: src/video_out/video_out_xxmc.c:2535
msgid "Some buggy video drivers need a workaround to function properly."
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1529 src/video_out/video_out_xv.c:1554
+#: src/video_out/video_out_xcbxv.c:1533 src/video_out/video_out_xv.c:1557
#: src/video_out/video_out_xvmc.c:1524
msgid "deinterlace method (deprecated)"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1530 src/video_out/video_out_xv.c:1555
+#: src/video_out/video_out_xcbxv.c:1534 src/video_out/video_out_xv.c:1558
#: src/video_out/video_out_xvmc.c:1525
msgid ""
"This config setting is deprecated. You should use the new deinterlacing post "
@@ -3981,93 +3980,26 @@ msgid ""
msgstr ""
# src/video_out/video_out_xv.c:1479
-#: src/video_out/video_out_xcbxv.c:1584 src/video_out/video_out_xv.c:1628
-#: src/video_out/video_out_xxmc.c:2618
+#: src/video_out/video_out_xcbxv.c:1588 src/video_out/video_out_xv.c:1631
+#: src/video_out/video_out_xxmc.c:2615
msgid "xine video output plugin using the MIT X video extension"
msgstr "wtyczka wyjścia obrazu xine używająca rozszerzenia obrazu MIT X"
#: src/video_out/video_out_xshm.c:202
-msgid ""
-"video_out_xshm: shared memory error when allocating image\n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xshm.c:218
#, c-format
-msgid ""
-"video_out_xshm: %s: allocating image\n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xshm.c:228
-msgid ""
-"video_out_xshm: shared memory error (address error) when allocating image \n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xshm.c:245
-msgid ""
-"video_out_xshm: x11 error during shared memory XImage creation\n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xshm.c:1170
-msgid "video_out_xshm: MIT shared memory extension not present on display.\n"
-msgstr ""
-
-#: src/video_out/video_out_xshm.c:1254
-msgid "video_out_xshm: your video mode was not recognized, sorry :-(\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:296
-msgid ""
-"video_out_xv: XvShmCreateImage failed\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
+msgid "%s: shared memory error when allocating image\n"
msgstr ""
-#: src/video_out/video_out_xv.c:306
-msgid ""
-"video_out_xv: XvShmCreateImage returned a zero size\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:314
+#: src/video_out/video_out_xv.c:294 src/video_out/video_out_xxmc.c:646
#, c-format
-msgid ""
-"video_out_xv: shared memory error in shmget: %s\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
+msgid "%s: XvShmCreateImage failed\n"
msgstr ""
-#: src/video_out/video_out_xv.c:346
-msgid ""
-"video_out_xv: x11 error during shared memory XImage creation\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:1299
-msgid "video_out_xv: Xv extension not present.\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:1336
-msgid ""
-"video_out_xv: Xv extension is present but I couldn't find a usable yuv12 "
-"port.\n"
-" Looks like your graphics hardware driver doesn't support Xv?!\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:1345
+#: src/video_out/video_out_xv.c:1348 src/video_out/video_out_xxmc.c:2330
#, c-format
msgid ""
-"video_out_xv: using Xv port %ld from adaptor %s for hardware colorspace "
-"conversion and scaling.\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:1520
-msgid "video_out_xv: this adaptor supports the yv12 format.\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:1525
-msgid "video_out_xv: this adaptor supports the yuy2 format.\n"
+"%s: using Xv port %ld from adaptor %s for hardware colorspace conversion and "
+"scaling.\n"
msgstr ""
# src/video_out/video_out_xv.c:1479
@@ -4110,94 +4042,43 @@ msgstr ""
msgid " With Overlay = %d; UnsignedIntra = %d.\n"
msgstr ""
-#: src/video_out/video_out_xxmc.c:650
-msgid ""
-"video_out_xxmc: XvShmCreateImage failed\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:660
-msgid ""
-"video_out_xxmc: XvShmCreateImage returned a zero size\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:668
-#, c-format
-msgid ""
-"video_out_xxmc: shared memory error in shmget: %s\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:700
-msgid ""
-"video_out_xxmc: x11 error during shared memory XImage creation\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:2287
-msgid "video_out_xxmc: Xv extension not present.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:2324
-msgid ""
-"video_out_xxmc: Xv extension is present but I couldn't find a usable yuv12 "
-"port.\n"
-" Looks like your graphics hardware driver doesn't support Xv?!\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:2333
-#, c-format
-msgid ""
-"video_out_xxmc: using Xv port %ld from adaptor %s for hardware colorspace "
-"conversion and scaling.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:2509
-msgid "video_out_xxmc: this adaptor supports the yv12 format.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:2514
-msgid "video_out_xxmc: this adaptor supports the yuy2 format.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:2543
+#: src/video_out/video_out_xxmc.c:2540
msgid "Make XvMC allocate more frames for better buffering."
msgstr ""
-#: src/video_out/video_out_xxmc.c:2544
+#: src/video_out/video_out_xxmc.c:2541
msgid ""
"Some XvMC implementations allow more than 8 frames.\n"
"This option, when turned on, makes the driver try to\n"
"allocate 15 frames. A must for unichrome and live VDR.\n"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2550
+#: src/video_out/video_out_xxmc.c:2547
msgid "Unichrome cpu save"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2551
+#: src/video_out/video_out_xxmc.c:2548
msgid ""
"Saves CPU time by sleeping while decoder works.\n"
"Only for Linux kernel 2.6 series or 2.4 with multimedia patch.\n"
"Experimental.\n"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2557
+#: src/video_out/video_out_xxmc.c:2554
msgid "Fix buggy NVIDIA XvMC subpicture colors"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2558
+#: src/video_out/video_out_xxmc.c:2555
msgid ""
"There's a bug in NVIDIA's XvMC lib that makes red OSD colors\n"
"look blue and vice versa. This option provides a workaround.\n"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2563
+#: src/video_out/video_out_xxmc.c:2560
msgid "Use bob as accelerated deinterlace method."
msgstr ""
-#: src/video_out/video_out_xxmc.c:2564
+#: src/video_out/video_out_xxmc.c:2561
msgid ""
"When interlacing is enabled for hardware accelerated frames,\n"
"Alternate between top and bottom field at double the frame rate.\n"
@@ -4435,12 +4316,12 @@ msgid ""
"info_helper: unsupported conversion %s -> UTF-8, no conversion performed\n"
msgstr "osd: niewspierana konwersja %s -> UCS-2\n"
-#: src/xine-engine/input_cache.c:167
+#: src/xine-engine/input_cache.c:171
#, c-format
msgid ": open() function should never be called\n"
msgstr ""
-#: src/xine-engine/input_cache.c:349
+#: src/xine-engine/input_cache.c:353
#, fuzzy, c-format
msgid ": input plugin not defined!\n"
msgstr "osd: nie został zdefiniowany font\n"
@@ -4551,37 +4432,37 @@ msgstr ""
msgid "io_helper: Connection Refused\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:212
+#: src/xine-engine/load_plugins.c:215
#, c-format
msgid "map_decoder_list: no space for decoder, skipped.\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:327
+#: src/xine-engine/load_plugins.c:330
#, c-format
msgid ""
"load_plugins: ignoring plugin %s, wrong iface version %d (should be %d)\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:384
+#: src/xine-engine/load_plugins.c:387
#, c-format
msgid "priority for %s decoder"
msgstr ""
-#: src/xine-engine/load_plugins.c:395
+#: src/xine-engine/load_plugins.c:398
msgid ""
"The priority provides a ranking in case some media can be handled by more "
"than one decoder.\n"
"A priority of 0 enables the decoder's default priority."
msgstr ""
-#: src/xine-engine/load_plugins.c:423
+#: src/xine-engine/load_plugins.c:426
#, c-format
msgid ""
"load_plugins: demuxer plugin %s does not provide a priority, xine-lib will "
"use the default priority.\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:440
+#: src/xine-engine/load_plugins.c:443
#, c-format
msgid ""
"load_plugins: input plugin %s does not provide a priority, xine-lib will use "
@@ -4589,49 +4470,49 @@ msgid ""
msgstr ""
# src/xine-engine/load_plugins.c:153
-#: src/xine-engine/load_plugins.c:496
+#: src/xine-engine/load_plugins.c:499
#, c-format
msgid "load_plugins: plugin %s found\n"
msgstr "load_plugins: wtyczka %s znaleziona\n"
# src/xine-engine/load_plugins.c:153
-#: src/xine-engine/load_plugins.c:499
+#: src/xine-engine/load_plugins.c:502
#, fuzzy, c-format
msgid "load_plugins: static plugin found\n"
msgstr "load_plugins: wtyczka %s znaleziona\n"
# src/xine-engine/load_plugins.c:153
-#: src/xine-engine/load_plugins.c:506
+#: src/xine-engine/load_plugins.c:509
#, fuzzy, c-format
msgid "load_plugins: plugin limit reached, %s could not be loaded\n"
msgstr "load_plugins: wtyczka %s znaleziona\n"
# src/xine-engine/load_plugins.c:153
-#: src/xine-engine/load_plugins.c:509
+#: src/xine-engine/load_plugins.c:512
#, fuzzy, c-format
msgid "load_plugins: plugin limit reached, static plugin could not be loaded\n"
msgstr "load_plugins: wtyczka %s znaleziona\n"
# src/xine-engine/load_plugins.c:153
-#: src/xine-engine/load_plugins.c:526
+#: src/xine-engine/load_plugins.c:529
#, c-format
msgid "load_plugins: unknown plugin type %d in %s\n"
msgstr "load_plugins: nieznany typ wtyczki %d w %s\n"
# src/xine-engine/load_plugins.c:153
-#: src/xine-engine/load_plugins.c:530
+#: src/xine-engine/load_plugins.c:533
#, fuzzy, c-format
msgid "load_plugins: unknown statically linked plugin type %d\n"
msgstr "load_plugins: nieznany typ wtyczki %d w %s\n"
# src/xine-engine/load_plugins.c:520
-#: src/xine-engine/load_plugins.c:590
+#: src/xine-engine/load_plugins.c:593
#, c-format
msgid "load_plugins: unable to stat %s\n"
msgstr "load_plugins: nie udał się start %s\n"
# src/xine-engine/load_plugins.c:138
-#: src/xine-engine/load_plugins.c:631
+#: src/xine-engine/load_plugins.c:634
#, fuzzy, c-format
msgid ""
"load_plugins: cannot open plugin lib %s:\n"
@@ -4641,7 +4522,7 @@ msgstr ""
"%s\n"
# src/xine-engine/load_plugins.c:300
-#: src/xine-engine/load_plugins.c:646
+#: src/xine-engine/load_plugins.c:649
#, c-format
msgid ""
"load_plugins: can't get plugin info from %s:\n"
@@ -4651,13 +4532,13 @@ msgstr ""
"%s\n"
# src/xine-engine/load_plugins.c:153
-#: src/xine-engine/load_plugins.c:664
+#: src/xine-engine/load_plugins.c:667
#, c-format
msgid "load_plugins: skipping unreadable plugin directory %s.\n"
msgstr "load_plugins: pomijanie katalogu wtyczek nie do odczytu %s.\n"
# src/xine-engine/load_plugins.c:138
-#: src/xine-engine/load_plugins.c:713
+#: src/xine-engine/load_plugins.c:716
#, c-format
msgid ""
"load_plugins: cannot (stage 2) open plugin lib %s:\n"
@@ -4667,39 +4548,45 @@ msgstr ""
"%s\n"
# src/xine-engine/load_plugins.c:300
-#: src/xine-engine/load_plugins.c:739
+#: src/xine-engine/load_plugins.c:742
#, fuzzy, c-format
msgid "load_plugins: Yikes! %s doesn't contain plugin info.\n"
msgstr ""
"load_plugins: nie mogę pobrać informacji z %s:\n"
"%s\n"
+# src/input/input_rtp.c:205
+#: src/xine-engine/load_plugins.c:1104 src/xine-engine/load_plugins.c:1113
+#, fuzzy, c-format
+msgid "Unable to create %s directory: %s\n"
+msgstr "nie mogę znaleźć IP dla '%s'.\n"
+
# src/xine-engine/load_plugins.c:153
-#: src/xine-engine/load_plugins.c:1305
+#: src/xine-engine/load_plugins.c:1345
#, fuzzy, c-format
msgid "load_plugins: unknown content detection strategy %d\n"
msgstr "load_plugins: nieznany typ wtyczki %d w %s\n"
# src/xine-engine/load_plugins.c:153
-#: src/xine-engine/load_plugins.c:1415
+#: src/xine-engine/load_plugins.c:1455
#, fuzzy, c-format
msgid "load_plugins: using demuxer '%s'\n"
msgstr "load_plugins: wtyczka %s znaleziona\n"
# src/xine-engine/load_plugins.c:520
-#: src/xine-engine/load_plugins.c:1726
+#: src/xine-engine/load_plugins.c:1766
#, fuzzy, c-format
msgid "load_plugins: failed to load audio output plugin <%s>\n"
msgstr "load_plugins: nie udał się start %s\n"
-#: src/xine-engine/load_plugins.c:1729
+#: src/xine-engine/load_plugins.c:1769
msgid ""
"load_plugins: audio output auto-probing didn't find any usable audio "
"driver.\n"
msgstr ""
# src/xine-engine/load_plugins.c:138
-#: src/xine-engine/load_plugins.c:2033
+#: src/xine-engine/load_plugins.c:2073
#, fuzzy, c-format
msgid ""
"load_plugins: cannot unload plugin lib %s:\n"
@@ -4708,31 +4595,27 @@ msgstr ""
"load_plugins: nie mogę (etap 2) otworzyć biblioteki wtyczki %s:\n"
"%s\n"
-#: src/xine-engine/osd.c:745
+#: src/xine-engine/osd.c:747
#, c-format
msgid "font '%s-%d' already loaded, weird.\n"
msgstr ""
-#: src/xine-engine/osd.c:757
+#: src/xine-engine/osd.c:759
#, c-format
msgid "font '%s' loading failed (%d < %d)\n"
msgstr ""
-#: src/xine-engine/osd.c:767
+#: src/xine-engine/osd.c:769
#, c-format
msgid "wrong version for font '%s'. expected %d found %d.\n"
msgstr ""
-#: src/xine-engine/osd.c:834
-msgid "osd: cannot initialize ft2 library\n"
-msgstr ""
-
-#: src/xine-engine/osd.c:857
+#: src/xine-engine/osd.c:856
#, c-format
msgid "osd: error matching font %s with FontConfig"
msgstr ""
-#: src/xine-engine/osd.c:871
+#: src/xine-engine/osd.c:870
#, c-format
msgid "osd: error loading font %s with FontConfig"
msgstr ""
@@ -4742,16 +4625,20 @@ msgstr ""
msgid "osd: error looking up font %s with FontConfig"
msgstr ""
-#: src/xine-engine/osd.c:895
+#: src/xine-engine/osd.c:914
#, c-format
-msgid "osd: error loading font %s with ft2\n"
+msgid "osd: error loading font %s with in XDG data directories.\n"
+msgstr ""
+
+#: src/xine-engine/osd.c:923
+msgid "osd: cannot initialize ft2 library\n"
msgstr ""
-#: src/xine-engine/osd.c:905
+#: src/xine-engine/osd.c:945
msgid "osd: error setting font size (no scalable font?)\n"
msgstr ""
-#: src/xine-engine/osd.c:1021
+#: src/xine-engine/osd.c:1061
#, c-format
msgid ""
"osd: unknown sequence starting with byte 0x%02X in encoding \"%s\", "
@@ -4760,44 +4647,44 @@ msgstr ""
"osd: nieznana sekwencja zaczynajÄ…ca siÄ™ od bajtu 0x%02X w kodowaniu \"%s\", "
"pomijanie\n"
-#: src/xine-engine/osd.c:1077
+#: src/xine-engine/osd.c:1117
msgid "osd: can't find out current locale character set\n"
msgstr "osd: nie można znaleźć zestawu znaków dla aktualnej lokalizacji\n"
-#: src/xine-engine/osd.c:1087
+#: src/xine-engine/osd.c:1127
#, fuzzy, c-format
msgid "osd: unsupported conversion %s -> %s, no conversion performed\n"
msgstr "osd: niewspierana konwersja %s -> UCS-2\n"
-#: src/xine-engine/osd.c:1142 src/xine-engine/osd.c:1310
+#: src/xine-engine/osd.c:1182 src/xine-engine/osd.c:1350
msgid "osd: font isn't defined\n"
msgstr "osd: nie został zdefiniowany font\n"
-#: src/xine-engine/osd.c:1181
+#: src/xine-engine/osd.c:1221
msgid "osd: error loading glyph\n"
msgstr ""
-#: src/xine-engine/osd.c:1187
+#: src/xine-engine/osd.c:1227
msgid "osd: error in rendering glyph\n"
msgstr ""
-#: src/xine-engine/osd.c:1347
+#: src/xine-engine/osd.c:1387
#, c-format
msgid "osd: error loading glyph %i\n"
msgstr ""
-#: src/xine-engine/osd.c:1354
+#: src/xine-engine/osd.c:1394
#, fuzzy
msgid "osd: error in rendering\n"
msgstr "osd: nie został zdefiniowany font\n"
# src/xine-engine/osd.c:863
-#: src/xine-engine/osd.c:1611
+#: src/xine-engine/osd.c:1660
#, fuzzy
msgid "palette (foreground-border-background) to use for subtitles and OSD"
msgstr "paleta użyta przy napisach (tło-napisy-kontur)"
-#: src/xine-engine/osd.c:1612
+#: src/xine-engine/osd.c:1661
msgid ""
"The palette for on-screen-display and some subtitle formats that do not "
"specify any colouring themselves. The palettes are listed in the form: "
@@ -4917,140 +4804,140 @@ msgid ""
"accelerated, this can dramatically reduce CPU usage."
msgstr ""
-#: src/xine-engine/xine.c:704 src/xine-engine/xine.c:811
-#: src/xine-engine/xine.c:850 src/xine-engine/xine.c:886
-#: src/xine-engine/xine.c:898 src/xine-engine/xine.c:911
-#: src/xine-engine/xine.c:924 src/xine-engine/xine.c:937
-#: src/xine-engine/xine.c:963 src/xine-engine/xine.c:988
-#: src/xine-engine/xine.c:1023
+#: src/xine-engine/xine.c:706 src/xine-engine/xine.c:813
+#: src/xine-engine/xine.c:852 src/xine-engine/xine.c:888
+#: src/xine-engine/xine.c:900 src/xine-engine/xine.c:913
+#: src/xine-engine/xine.c:926 src/xine-engine/xine.c:939
+#: src/xine-engine/xine.c:965 src/xine-engine/xine.c:990
+#: src/xine-engine/xine.c:1025
msgid "xine: error while parsing mrl\n"
msgstr ""
# src/xine-engine/xine.c:415
-#: src/xine-engine/xine.c:740
+#: src/xine-engine/xine.c:742
#, fuzzy, c-format
msgid "xine: found input plugin : %s\n"
msgstr "xine: nie mogę znaleźć wtyczki wejścia dla tego MRL\n"
# src/xine-engine/xine.c:415
-#: src/xine-engine/xine.c:758
+#: src/xine-engine/xine.c:760
#, fuzzy, c-format
msgid "xine: input plugin cannot open MRL [%s]\n"
msgstr "xine: nie mogę znaleźć wtyczki wejścia dla tego MRL\n"
# src/xine-engine/xine.c:415
-#: src/xine-engine/xine.c:774
+#: src/xine-engine/xine.c:776
#, fuzzy, c-format
msgid "xine: cannot find input plugin for MRL [%s]\n"
msgstr "xine: nie mogę znaleźć wtyczki wejścia dla tego MRL\n"
# src/xine-engine/xine.c:471
-#: src/xine-engine/xine.c:800
+#: src/xine-engine/xine.c:802
#, c-format
msgid "xine: specified demuxer %s failed to start\n"
msgstr "xine: zawiódł start wybranego demultiplexera %s\n"
# src/input/input_http.c:640
-#: src/xine-engine/xine.c:836
+#: src/xine-engine/xine.c:838
#, fuzzy, c-format
msgid "xine: join rip input plugin\n"
msgstr "wtyczka wejścia VCD"
# src/input/input_http.c:640
-#: src/xine-engine/xine.c:843
+#: src/xine-engine/xine.c:845
#, fuzzy
msgid "xine: error opening rip input plugin instance\n"
msgstr "wtyczka wejścia VCD"
# src/xine-engine/xine.c:471
-#: src/xine-engine/xine.c:874
+#: src/xine-engine/xine.c:876
#, c-format
msgid "xine: last_probed demuxer %s failed to start\n"
msgstr "xine: zawiódł start ostatnio próbowanego demultiplexera %s\n"
-#: src/xine-engine/xine.c:903
+#: src/xine-engine/xine.c:905
msgid "ignoring video\n"
msgstr ""
-#: src/xine-engine/xine.c:916
+#: src/xine-engine/xine.c:918
msgid "ignoring audio\n"
msgstr ""
-#: src/xine-engine/xine.c:929
+#: src/xine-engine/xine.c:931
msgid "ignoring subpicture\n"
msgstr ""
-#: src/xine-engine/xine.c:942
+#: src/xine-engine/xine.c:944
msgid "input cache plugin disabled\n"
msgstr ""
-#: src/xine-engine/xine.c:1013
+#: src/xine-engine/xine.c:1015
#, c-format
msgid "subtitle mrl opened '%s'\n"
msgstr ""
-#: src/xine-engine/xine.c:1017
+#: src/xine-engine/xine.c:1019
msgid "xine: error opening subtitle mrl\n"
msgstr ""
-#: src/xine-engine/xine.c:1049
+#: src/xine-engine/xine.c:1051
#, c-format
msgid "xine: error while parsing MRL\n"
msgstr ""
-#: src/xine-engine/xine.c:1056
+#: src/xine-engine/xine.c:1058
#, c-format
msgid "xine: changing option '%s' from MRL isn't permitted\n"
msgstr ""
# src/xine-engine/xine.c:436
-#: src/xine-engine/xine.c:1076
+#: src/xine-engine/xine.c:1078
#, c-format
msgid "xine: couldn't find demux for >%s<\n"
msgstr "xine: nie mogę znaleźć demultiplexera dla >%s<\n"
# src/xine-engine/xine.c:436
-#: src/xine-engine/xine.c:1092
+#: src/xine-engine/xine.c:1094
#, fuzzy, c-format
msgid "xine: found demuxer plugin: %s\n"
msgstr "xine: nie mogę znaleźć demultiplexera dla >%s<\n"
# src/xine-engine/xine.c:471
-#: src/xine-engine/xine.c:1112
+#: src/xine-engine/xine.c:1114
#, c-format
msgid "xine: demuxer failed to start\n"
msgstr "xine: zawiódł start demultiplexera\n"
# src/xine-engine/xine.c:471
-#: src/xine-engine/xine.c:1177
+#: src/xine-engine/xine.c:1179
#, c-format
msgid "xine_play: no demux available\n"
msgstr "xine_play: brak dostępnego demultiplexera\n"
# src/xine-engine/xine.c:471
-#: src/xine-engine/xine.c:1247
+#: src/xine-engine/xine.c:1249
#, c-format
msgid "xine_play: demux failed to start\n"
msgstr "xine_play: zawiódł start demultiplexera\n"
-#: src/xine-engine/xine.c:1523
+#: src/xine-engine/xine.c:1527
#, c-format
msgid "xine: The specified save_dir \"%s\" might be a security risk.\n"
msgstr ""
-#: src/xine-engine/xine.c:1528
+#: src/xine-engine/xine.c:1532
msgid "The specified save_dir might be a security risk."
msgstr ""
-#: src/xine-engine/xine.c:1554
+#: src/xine-engine/xine.c:1561
msgid "xine: locale not supported by C library\n"
msgstr ""
-#: src/xine-engine/xine.c:1563
+#: src/xine-engine/xine.c:1570
msgid "media format detection strategy"
msgstr ""
-#: src/xine-engine/xine.c:1564
+#: src/xine-engine/xine.c:1571
msgid ""
"xine offers various methods to detect the media format of input to play. The "
"individual values are:\n"
@@ -5068,11 +4955,11 @@ msgid ""
"Detect by file name extension only.\n"
msgstr ""
-#: src/xine-engine/xine.c:1582
+#: src/xine-engine/xine.c:1589
msgid "directory for saving streams"
msgstr ""
-#: src/xine-engine/xine.c:1583
+#: src/xine-engine/xine.c:1590
msgid ""
"When using the stream save feature, files will be written only into this "
"directory.\n"
@@ -5082,11 +4969,11 @@ msgid ""
"content in any file."
msgstr ""
-#: src/xine-engine/xine.c:1594
+#: src/xine-engine/xine.c:1601
msgid "allow implicit changes to the configuration (e.g. by MRL)"
msgstr ""
-#: src/xine-engine/xine.c:1595
+#: src/xine-engine/xine.c:1602
msgid ""
"If enabled, you allow xine to change your configuration without explicit "
"actions from your side. For example configuration changes demanded by MRLs "
@@ -5096,11 +4983,11 @@ msgid ""
"configuration, you might end with a totally messed up xine."
msgstr ""
-#: src/xine-engine/xine.c:1609
+#: src/xine-engine/xine.c:1616
msgid "Timeout for network stream reading (in seconds)"
msgstr ""
-#: src/xine-engine/xine.c:1610
+#: src/xine-engine/xine.c:1617
msgid ""
"Specifies the timeout when reading from network streams, in seconds. Too low "
"values might stop streaming when the source is slow or the bandwidth is "
@@ -5108,16 +4995,16 @@ msgid ""
msgstr ""
# src/xine-engine/xine.c:1025
-#: src/xine-engine/xine.c:1962
+#: src/xine-engine/xine.c:1969
msgid "messages"
msgstr "wiadomości"
# src/xine-engine/xine.c:1026
-#: src/xine-engine/xine.c:1963
+#: src/xine-engine/xine.c:1970
msgid "plugin"
msgstr "wtyczka"
-#: src/xine-engine/xine.c:1964
+#: src/xine-engine/xine.c:1971
msgid "trace"
msgstr ""
@@ -5190,6 +5077,11 @@ msgstr ""
msgid "Benchmarking memcpy methods (smaller is better):\n"
msgstr ""
+# src/input/input_vcd.c:1184
+#, fuzzy
+#~ msgid "path to the title key cache"
+#~ msgstr "ścieżka dostępu do pliku lokalnego urządzenia vcd"
+
# src/audio_out/audio_alsa_out.c:211 src/audio_out/audio_alsa_out.c:934
#, fuzzy
#~ msgid "device used for 5+ channel output"
diff --git a/po/pt_BR.po b/po/pt_BR.po
index 80507b0ed..4b3a55f86 100644
--- a/po/pt_BR.po
+++ b/po/pt_BR.po
@@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: xine-lib 0.9.13\n"
"Report-Msgid-Bugs-To: xine-devel@lists.sourceforge.net\n"
-"POT-Creation-Date: 2007-04-06 15:39+0200\n"
+"POT-Creation-Date: 2007-04-24 21:48+0100\n"
"PO-Revision-Date: 2002-01-22 18:31GMT-3\n"
"Last-Translator: Marcelo Roberto Jimenez <mroberto@cetuc.puc-rio.br>\n"
"Language-Team: Portuguese (Brazilian) <pt_BR@li.org>\n"
@@ -40,117 +40,117 @@ msgstr ""
msgid "Unknown error"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:354
+#: src/audio_out/audio_alsa_out.c:351
#, c-format
msgid "audio_alsa_out:Already open...WHY!"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:382
+#: src/audio_out/audio_alsa_out.c:379
#, c-format
msgid "audio_alsa_out: snd_pcm_open() of %s failed: %s\n"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:384
+#: src/audio_out/audio_alsa_out.c:381
msgid "audio_alsa_out: >>> check if another program already uses PCM <<<\n"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:397
+#: src/audio_out/audio_alsa_out.c:394
#, c-format
msgid ""
"audio_alsa_out: broken configuration for this PCM: no configurations "
"available: %s\n"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1289
+#: src/audio_out/audio_alsa_out.c:1286
msgid "notify changes to the hardware mixer"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1290
+#: src/audio_out/audio_alsa_out.c:1287
msgid ""
"When the hardware mixer changes, your application will receive a "
"notification so that it can update its graphical representation of the mixer "
"settings on the fly."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1355
+#: src/audio_out/audio_alsa_out.c:1352
#, c-format
msgid "snd_lib_error_set_handler() failed: %d"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1362
+#: src/audio_out/audio_alsa_out.c:1359
msgid "sound card can do mmap"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1363
+#: src/audio_out/audio_alsa_out.c:1360
msgid ""
"Enable this, if your sound card and alsa driver support memory mapped IO.\n"
"You can try enabling it and check, if everything works. If it does, this "
"will increase performance."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1372
+#: src/audio_out/audio_alsa_out.c:1369
msgid "device used for mono output"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1373
+#: src/audio_out/audio_alsa_out.c:1370
msgid ""
"xine will use this alsa device to output mono sound.\n"
"See the alsa documentation for information on alsa devices."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1381
+#: src/audio_out/audio_alsa_out.c:1378
msgid "device used for stereo output"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1382
+#: src/audio_out/audio_alsa_out.c:1379
msgid ""
"xine will use this alsa device to output stereo sound.\n"
"See the alsa documentation for information on alsa devices."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1390
+#: src/audio_out/audio_alsa_out.c:1387
msgid "device used for 4-channel output"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1391
+#: src/audio_out/audio_alsa_out.c:1388
msgid ""
"xine will use this alsa device to output 4 channel (4.0) surround sound.\n"
"See the alsa documentation for information on alsa devices."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1400 src/audio_out/audio_alsa_out.c:1410
+#: src/audio_out/audio_alsa_out.c:1397 src/audio_out/audio_alsa_out.c:1407
msgid "device used for 5.1-channel output"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1401
+#: src/audio_out/audio_alsa_out.c:1398
msgid ""
"xine will use this alsa device to output 5 channel plus LFE (5.1) surround "
"sound.\n"
"See the alsa documentation for information on alsa devices."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1411
+#: src/audio_out/audio_alsa_out.c:1408
msgid ""
"xine will use this alsa device to output undecoded digital surround sound. "
"This can be used be external surround decoders.\n"
"See the alsa documentation for information on alsa devices."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1431
+#: src/audio_out/audio_alsa_out.c:1428
#, fuzzy, c-format
msgid "snd_pcm_open() failed:%d:%s\n"
msgstr "input_cda: open(%s) failed: %s.\n"
-#: src/audio_out/audio_alsa_out.c:1433
+#: src/audio_out/audio_alsa_out.c:1430
#, c-format
msgid ">>> Check if another program already uses PCM <<<\n"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1464 src/audio_out/audio_oss_out.c:929
+#: src/audio_out/audio_alsa_out.c:1461 src/audio_out/audio_oss_out.c:929
msgid "speaker arrangement"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1465 src/audio_out/audio_oss_out.c:930
+#: src/audio_out/audio_alsa_out.c:1462 src/audio_out/audio_oss_out.c:930
msgid ""
"Select how your speakers are arranged, this determines which speakers xine "
"uses for sound output. The individual values are:\n"
@@ -182,86 +182,86 @@ msgid ""
"formats you want to play to your sound card's digital output."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1494
+#: src/audio_out/audio_alsa_out.c:1491
msgid "audio_alsa_out : supported modes are "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1497
+#: src/audio_out/audio_alsa_out.c:1494
msgid "8bit "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1502
+#: src/audio_out/audio_alsa_out.c:1499
msgid "16bit "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1506
+#: src/audio_out/audio_alsa_out.c:1503
msgid "24bit "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1510
+#: src/audio_out/audio_alsa_out.c:1507
msgid "32bit "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1521
+#: src/audio_out/audio_alsa_out.c:1518
#, fuzzy
msgid "mono "
msgstr "metronom"
-#: src/audio_out/audio_alsa_out.c:1525
+#: src/audio_out/audio_alsa_out.c:1522
msgid "stereo "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1530
+#: src/audio_out/audio_alsa_out.c:1527
msgid "4-channel "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1533
+#: src/audio_out/audio_alsa_out.c:1530
msgid "(4-channel not enabled in xine config) "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1538
+#: src/audio_out/audio_alsa_out.c:1535
msgid "4.1-channel "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1541
+#: src/audio_out/audio_alsa_out.c:1538
msgid "(4.1-channel not enabled in xine config) "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1546
+#: src/audio_out/audio_alsa_out.c:1543
msgid "5-channel "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1549
+#: src/audio_out/audio_alsa_out.c:1546
msgid "(5-channel not enabled in xine config) "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1554
+#: src/audio_out/audio_alsa_out.c:1551
msgid "5.1-channel "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1557
+#: src/audio_out/audio_alsa_out.c:1554
msgid "(5.1-channel not enabled in xine config) "
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1580
+#: src/audio_out/audio_alsa_out.c:1577
msgid "a/52 and DTS pass-through\n"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1583
+#: src/audio_out/audio_alsa_out.c:1580
msgid "(a/52 and DTS pass-through not enabled in xine config)\n"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1590
+#: src/audio_out/audio_alsa_out.c:1587
msgid "alsa mixer device"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1591
+#: src/audio_out/audio_alsa_out.c:1588
msgid ""
"xine will use this alsa mixer device to change the volume.\n"
"See the alsa documentation for information on alsa devices."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1665
+#: src/audio_out/audio_alsa_out.c:1662
msgid "xine audio output plugin using alsa-compliant audio devices/drivers"
msgstr ""
@@ -273,201 +273,201 @@ msgstr ""
msgid "xine output plugin for Coreaudio/Mac OS X"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:166
+#: src/audio_out/audio_directx2_out.c:163
msgid "Error"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:173
+#: src/audio_out/audio_directx2_out.c:170
msgid "success"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:175
+#: src/audio_out/audio_directx2_out.c:172
msgid "access denied"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:177
+#: src/audio_out/audio_directx2_out.c:174
msgid "resource is already in use"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:178
+#: src/audio_out/audio_directx2_out.c:175
msgid "object was already initialized"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:179
+#: src/audio_out/audio_directx2_out.c:176
msgid "specified wave format is not supported"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:180
+#: src/audio_out/audio_directx2_out.c:177
msgid "memory buffer has been lost and must be restored"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:181
+#: src/audio_out/audio_directx2_out.c:178
msgid "requested buffer control is not available"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:182
+#: src/audio_out/audio_directx2_out.c:179
msgid "undetermined error inside DirectSound subsystem"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:184
+#: src/audio_out/audio_directx2_out.c:181
msgid "DirectSound hardware device is unavailable"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:186
+#: src/audio_out/audio_directx2_out.c:183
msgid "function is not valid for the current state of the object"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:187
+#: src/audio_out/audio_directx2_out.c:184
msgid "invalid parameter was passed"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:188
+#: src/audio_out/audio_directx2_out.c:185
msgid "object doesn't support aggregation"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:189
+#: src/audio_out/audio_directx2_out.c:186
msgid "no sound driver available for use"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:190
+#: src/audio_out/audio_directx2_out.c:187
msgid "requested COM interface not available"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:191
+#: src/audio_out/audio_directx2_out.c:188
msgid "another application has a higher priority level"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:192
+#: src/audio_out/audio_directx2_out.c:189
msgid "insufficient memory"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:193
+#: src/audio_out/audio_directx2_out.c:190
msgid "low priority level for this function"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:194
+#: src/audio_out/audio_directx2_out.c:191
msgid "DirectSound wasn't initialized"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:195
+#: src/audio_out/audio_directx2_out.c:192
msgid "function is not supported"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:196
+#: src/audio_out/audio_directx2_out.c:193
msgid "unknown error"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:206
+#: src/audio_out/audio_directx2_out.c:203
#, c-format
msgid "Unable to create direct sound object."
msgstr ""
-#: src/audio_out/audio_directx2_out.c:212
+#: src/audio_out/audio_directx2_out.c:209
#, c-format
msgid "Could not set direct sound cooperative level."
msgstr ""
-#: src/audio_out/audio_directx2_out.c:286
+#: src/audio_out/audio_directx2_out.c:283
msgid "Unable to create secondary direct sound buffer"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:310
+#: src/audio_out/audio_directx2_out.c:307
#, c-format
msgid "Unable to create buffer position events."
msgstr ""
-#: src/audio_out/audio_directx2_out.c:318
+#: src/audio_out/audio_directx2_out.c:315
msgid "Unable to get notification interface"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:323
+#: src/audio_out/audio_directx2_out.c:320
msgid "Unable to set notification positions"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:343
+#: src/audio_out/audio_directx2_out.c:340
msgid "Couldn't play sound buffer"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:355
+#: src/audio_out/audio_directx2_out.c:352
msgid "Couldn't stop sound buffer"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:368
+#: src/audio_out/audio_directx2_out.c:365
msgid "Can't get buffer position"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:382
+#: src/audio_out/audio_directx2_out.c:379
msgid "Can't set buffer position"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:414
+#: src/audio_out/audio_directx2_out.c:411
msgid "Can't set sound volume"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:432
+#: src/audio_out/audio_directx2_out.c:429
#, c-format
msgid ": buffer lost, tryig to restore\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:436
+#: src/audio_out/audio_directx2_out.c:433
msgid "Couldn't lock direct sound buffer"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:447
+#: src/audio_out/audio_directx2_out.c:444
msgid "Couldn't unlock direct sound buffer"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:544
+#: src/audio_out/audio_directx2_out.c:541
#, fuzzy, c-format
msgid "Unable to create primary direct sound buffer."
msgstr "incapaz de alocar buffer de entrada.\n"
-#: src/audio_out/audio_directx2_out.c:637
+#: src/audio_out/audio_directx2_out.c:634
#, c-format
msgid ": play cursor overran, flushing buffers\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:655
+#: src/audio_out/audio_directx2_out.c:652
#, c-format
msgid ": delayed by %ld msec\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:759
+#: src/audio_out/audio_directx2_out.c:756
#, fuzzy, c-format
msgid ": can't create pthread condition: %s\n"
msgstr "video_out : não consigo criar thread (%s)\n"
-#: src/audio_out/audio_directx2_out.c:763
+#: src/audio_out/audio_directx2_out.c:760
#, fuzzy, c-format
msgid ": can't create pthread mutex: %s\n"
msgstr "video_out : não consigo criar thread (%s)\n"
-#: src/audio_out/audio_directx2_out.c:770
+#: src/audio_out/audio_directx2_out.c:767
#, fuzzy, c-format
msgid ": can't create buffer pthread: %s\n"
msgstr "demux_qt: não consigo criar um novo thread (%s)\n"
-#: src/audio_out/audio_directx2_out.c:877
+#: src/audio_out/audio_directx2_out.c:874
#, fuzzy, c-format
msgid ": can't destroy buffer pthread: %s\n"
msgstr "demux_qt: não consigo criar um novo thread (%s)\n"
-#: src/audio_out/audio_directx2_out.c:884
+#: src/audio_out/audio_directx2_out.c:881
#, c-format
msgid ": can't destroy pthread condition: %s\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:887
+#: src/audio_out/audio_directx2_out.c:884
#, fuzzy, c-format
msgid ": can't destroy pthread mutex: %s\n"
msgstr "video_out : não consigo criar thread (%s)\n"
-#: src/audio_out/audio_directx2_out.c:947
+#: src/audio_out/audio_directx2_out.c:944
#, c-format
msgid ": unknown control command %d\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:1003
+#: src/audio_out/audio_directx2_out.c:1000
#, fuzzy
msgid "second xine audio output plugin using directx"
msgstr "http network stream input plugin"
@@ -861,7 +861,7 @@ msgstr ""
msgid "demux_snd: unsupported audio type: %d\n"
msgstr "demux_asf: tipo de audio desconhecido 0x%x\n"
-#: src/demuxers/demux_tta.c:88
+#: src/demuxers/demux_tta.c:86
msgid "demux_tta: total frames count too high\n"
msgstr ""
@@ -881,7 +881,7 @@ msgstr ""
msgid "demux_wc3movie: SHOT chunk referenced invalid palette (%d >= %d)\n"
msgstr ""
-#: src/demuxers/demux_wc3movie.c:406
+#: src/demuxers/demux_wc3movie.c:404
#, c-format
msgid "demux_wc3movie: There was a problem while loading palette chunks\n"
msgstr ""
@@ -1241,40 +1241,40 @@ msgstr ""
msgid "video_out_dxr3: ERROR Reading overlay init file. Run autocal!\n"
msgstr ""
-#: src/input/input_cdda.c:1621
+#: src/input/input_cdda.c:1608
#, fuzzy, c-format
msgid "%s: can't connect to %s:%d\n"
msgstr "http: unable to connect to >%s<\n"
-#: src/input/input_cdda.c:1668
+#: src/input/input_cdda.c:1655
#, fuzzy, c-format
msgid "input_cdda: successfuly connected to cddb server '%s:%d'.\n"
msgstr "input_cda: server '%s:%d' successfuly connected.\n"
-#: src/input/input_cdda.c:1673
+#: src/input/input_cdda.c:1660
#, fuzzy, c-format
msgid "input_cdda: failed to connect to cddb server '%s:%d' (%s).\n"
msgstr "input_net: incapaz de conectar em '%s'.\n"
-#: src/input/input_cdda.c:2707
+#: src/input/input_cdda.c:2690
msgid "CD Digital Audio (aka. CDDA)"
msgstr ""
-#: src/input/input_cdda.c:2760
+#: src/input/input_cdda.c:2742
msgid "device used for CD audio"
msgstr ""
-#: src/input/input_cdda.c:2761
+#: src/input/input_cdda.c:2743
msgid ""
"The path to the device, usually a CD or DVD drive, which you intend to use "
"for playing audio CDs."
msgstr ""
-#: src/input/input_cdda.c:2767
+#: src/input/input_cdda.c:2749
msgid "query CDDB"
msgstr ""
-#: src/input/input_cdda.c:2767
+#: src/input/input_cdda.c:2749
msgid ""
"Enables CDDB queries, which will give you convenient title and track names "
"for your audio CDs.\n"
@@ -1283,11 +1283,11 @@ msgid ""
"listening habits."
msgstr ""
-#: src/input/input_cdda.c:2775
+#: src/input/input_cdda.c:2757
msgid "CDDB server name"
msgstr ""
-#: src/input/input_cdda.c:2775
+#: src/input/input_cdda.c:2757
msgid ""
"The CDDB server used to retrieve the title and track information from.\n"
"This setting is security critical, because the sever will receive "
@@ -1295,31 +1295,19 @@ msgid ""
"malicious replies. Be sure to enter a server you can trust."
msgstr ""
-#: src/input/input_cdda.c:2783
+#: src/input/input_cdda.c:2765
msgid "CDDB server port"
msgstr ""
-#: src/input/input_cdda.c:2783
+#: src/input/input_cdda.c:2765
msgid "The server port used to retrieve the title and track information from."
msgstr ""
-#: src/input/input_cdda.c:2789
-msgid "CDDB cache directory"
-msgstr ""
-
-#: src/input/input_cdda.c:2789
-msgid ""
-"The replies from the CDDB server will be cached in this directory.\n"
-"This setting is security critical, because files with uncontrollable names "
-"will be created in this directory. Be sure to use a dedicated directory not "
-"used for anything but CDDB caching."
-msgstr ""
-
-#: src/input/input_cdda.c:2797
+#: src/input/input_cdda.c:2771
msgid "slow down disc drive to this speed factor"
msgstr ""
-#: src/input/input_cdda.c:2798
+#: src/input/input_cdda.c:2772
msgid ""
"Since some CD or DVD drives make some really loud noises because of the fast "
"disc rotation, xine will try to slow them down. With standard CD or DVD "
@@ -1328,122 +1316,127 @@ msgid ""
"A value of zero here will disable the slowdown."
msgstr ""
-#: src/input/input_dvb.c:881
+#: src/input/input_dvb.c:899
+#, fuzzy, c-format
+msgid "input_dvb: failed to open dvb channel file '%s': %s\n"
+msgstr "input_file: tentando abrir o arquivo de subtítulos '%s'\n"
+
+#: src/input/input_dvb.c:905
#, fuzzy, c-format
-msgid "input_dvb: failed to open dvb channel file '%s'\n"
+msgid "input_dvb: dvb channel file '%s' is not a plain file\n"
msgstr "input_file: tentando abrir o arquivo de subtítulos '%s'\n"
-#: src/input/input_dvb.c:2082 src/input/input_dvb.c:2910
+#: src/input/input_dvb.c:2115 src/input/input_dvb.c:2943
#, fuzzy
msgid "input_dvb: tuner_set_channel failed\n"
msgstr "input_vcd: read data failed\n"
-#: src/input/input_dvb.c:2710
+#: src/input/input_dvb.c:2743
#, fuzzy
msgid "input_dvb: cannot open dvb device\n"
msgstr "input_dvd: não consigo abrir o acionador de dvd >%s<\n"
-#: src/input/input_dvb.c:2734
+#: src/input/input_dvb.c:2767
#, c-format
msgid "input_dvb: channel %d out of range, defaulting to 0\n"
msgstr ""
-#: src/input/input_dvb.c:2745
+#: src/input/input_dvb.c:2778
#, fuzzy, c-format
msgid "input_dvb: searching for channel %s\n"
msgstr "input_file: tentando abrir o arquivo de subtítulos '%s'\n"
-#: src/input/input_dvb.c:2768
+#: src/input/input_dvb.c:2801
#, c-format
msgid "input_dvb: exact match for %s not found: trying partial matches\n"
msgstr ""
-#: src/input/input_dvb.c:2775
+#: src/input/input_dvb.c:2808
#, fuzzy, c-format
msgid "input_dvb: found matching channel %s\n"
msgstr "input_file: tentando abrir o arquivo de subtítulos '%s'\n"
-#: src/input/input_dvb.c:2788
+#: src/input/input_dvb.c:2821
#, c-format
msgid "input_dvb: channel %s not found in channels.conf, defaulting.\n"
msgstr ""
-#: src/input/input_dvb.c:2794
+#: src/input/input_dvb.c:2827
msgid ""
"input_dvb: invalid channel specification, defaulting to last viewed "
"channel.\n"
msgstr ""
-#: src/input/input_dvb.c:2800
+#: src/input/input_dvb.c:2833
msgid "input_dvb: invalid channel specification, defaulting to channel 0\n"
msgstr ""
-#: src/input/input_dvb.c:2812
+#: src/input/input_dvb.c:2845
msgid ""
"input_dvb: dvbs mrl specified but the tuner doesn't appear to be QPSK (DVB-"
"S)\n"
msgstr ""
-#: src/input/input_dvb.c:2832
+#: src/input/input_dvb.c:2865
msgid ""
"input_dvb: dvbt mrl specified but the tuner doesn't appear to be OFDM (DVB-"
"T)\n"
msgstr ""
-#: src/input/input_dvb.c:2855 src/input/input_dvb.c:2881
+#: src/input/input_dvb.c:2888 src/input/input_dvb.c:2914
msgid ""
"input_dvb: dvbc mrl specified but the tuner doesn't appear to be QAM (DVB-"
"C)\n"
msgstr ""
-#: src/input/input_dvb.c:2916
+#: src/input/input_dvb.c:2949
#, fuzzy, c-format
msgid "input_dvb: cannot open dvr device '%s'\n"
msgstr "input_dvd: não consigo abrir o acionador de dvd >%s<\n"
-#: src/input/input_dvb.c:2938
+#: src/input/input_dvb.c:2971
#, fuzzy
msgid "input_dvb: cannot create EPG updater thread\n"
msgstr "input_rtp: não consigo criar um novo thread (%s)\n"
-#: src/input/input_dvb.c:3000
+#: src/input/input_dvb.c:3033
msgid "use DVB 'center cutout' (zoom)"
msgstr ""
-#: src/input/input_dvb.c:3001
+#: src/input/input_dvb.c:3034
msgid ""
"This will allow fullscreen playback of 4:3 content transmitted in a 16:9 "
"frame."
msgstr ""
-#: src/input/input_dvb.c:3094
+#: src/input/input_dvb.c:3127
#, fuzzy
msgid "DVB (Digital TV) input plugin"
msgstr "http network stream input plugin"
-#: src/input/input_dvb.c:3242
+#: src/input/input_dvb.c:3244
msgid "Remember last DVB channel watched"
msgstr ""
-#: src/input/input_dvb.c:3243
+#: src/input/input_dvb.c:3245
msgid ""
"On autoplay, xine will remember and switch to the channel indicated in media."
"dvb.last_channel. "
msgstr ""
-#: src/input/input_dvb.c:3250
+#: src/input/input_dvb.c:3252
msgid "Last DVB channel viewed"
msgstr ""
-#: src/input/input_dvb.c:3251
+#: src/input/input_dvb.c:3253
msgid "If enabled xine will remember and switch to this channel. "
msgstr ""
-#: src/input/input_dvb.c:3257
+#: src/input/input_dvb.c:3259
msgid "Number of dvb card to use."
msgstr ""
-#: src/input/input_dvb.c:3258
+#: src/input/input_dvb.c:3260
msgid ""
"Leave this at zero unless you really have more than 1 card in your system."
msgstr ""
@@ -1472,11 +1465,11 @@ msgid ""
"playing DVDs."
msgstr ""
-#: src/input/input_dvd.c:1800
+#: src/input/input_dvd.c:1799
msgid "raw device set up for DVD access"
msgstr ""
-#: src/input/input_dvd.c:1801
+#: src/input/input_dvd.c:1800
msgid ""
"If this points to a raw device connected to your DVD device, xine will use "
"the raw device for playback. This has the advantage of being slightly faster "
@@ -1487,68 +1480,55 @@ msgid ""
"See the documentation on raw device setup (man raw) for further information."
msgstr ""
-#: src/input/input_dvd.c:1814
+#: src/input/input_dvd.c:1813
msgid "CSS decryption method"
msgstr ""
-#: src/input/input_dvd.c:1815
+#: src/input/input_dvd.c:1814
msgid ""
"Selects the decryption method libdvdcss will use to descramble copy "
"protected DVDs. Try the various methods, if you have problems playing "
"scrambled DVDs."
msgstr ""
-#: src/input/input_dvd.c:1823
-msgid "path to the title key cache"
-msgstr ""
-
-#: src/input/input_dvd.c:1824
-msgid ""
-"Since cracking the copy protection of scrambled DVDs can be quite time "
-"consuming, libdvdcss will cache the cracked keys in this directory.\n"
-"This setting is security critical, because files with uncontrollable names "
-"will be created in this directory. Be sure to use a dedicated directory not "
-"used for anything but DVD key caching."
-msgstr ""
-
-#: src/input/input_dvd.c:1846
+#: src/input/input_dvd.c:1829
msgid "region the DVD player claims to be in (1 to 8)"
msgstr ""
-#: src/input/input_dvd.c:1847
+#: src/input/input_dvd.c:1830
msgid ""
"This only needs to be changed if your DVD jumps to a screen complaining "
"about a wrong region code. It has nothing to do with the region code set in "
"DVD drives, this is purely software."
msgstr ""
-#: src/input/input_dvd.c:1853
+#: src/input/input_dvd.c:1836
msgid "default language for DVD playback"
msgstr ""
-#: src/input/input_dvd.c:1854
+#: src/input/input_dvd.c:1837
msgid ""
"xine tries to use this language as a default for DVD playback. As far as the "
"DVD supports it, menus and audio tracks will be presented in this language.\n"
"The value must be a two character ISO639 language code."
msgstr ""
-#: src/input/input_dvd.c:1860
+#: src/input/input_dvd.c:1843
msgid "read-ahead caching"
msgstr ""
-#: src/input/input_dvd.c:1861
+#: src/input/input_dvd.c:1844
msgid ""
"xine can use a read ahead cache for DVD drive access.\n"
"This may lead to jerky playback on slow drives, but it improves the impact "
"of the DVD layer change on faster drives."
msgstr ""
-#: src/input/input_dvd.c:1867
+#: src/input/input_dvd.c:1850
msgid "unit for the skip action"
msgstr ""
-#: src/input/input_dvd.c:1868
+#: src/input/input_dvd.c:1851
msgid ""
"You can configure the behaviour when issuing a skip command (using the skip "
"buttons for example). The individual values mean:\n"
@@ -1567,11 +1547,11 @@ msgid ""
"features on the DVD"
msgstr ""
-#: src/input/input_dvd.c:1883
+#: src/input/input_dvd.c:1866
msgid "unit for seeking"
msgstr ""
-#: src/input/input_dvd.c:1884
+#: src/input/input_dvd.c:1867
msgid ""
"You can configure the domain spanned by the seek slider. The individual "
"values mean:\n"
@@ -1585,11 +1565,11 @@ msgid ""
"chapter of the current feature"
msgstr ""
-#: src/input/input_dvd.c:1895
+#: src/input/input_dvd.c:1878
msgid "play mode when title/chapter is given"
msgstr ""
-#: src/input/input_dvd.c:1896
+#: src/input/input_dvd.c:1879
msgid ""
"You can configure the behaviour when playing a dvd from a given title/"
"chapter (eg. using MRL 'dvd:/1.2'). The individual values mean:\n"
@@ -2288,7 +2268,7 @@ msgid ""
"2048: Debugging from VCDINFO\n"
msgstr ""
-#: src/liba52/xine_a52_decoder.c:742 src/libdts/xine_dts_decoder.c:546
+#: src/liba52/xine_a52_decoder.c:742 src/libxineadec/xine_dts_decoder.c:524
msgid "HELP! a mono-only audio driver?!\n"
msgstr ""
@@ -2339,60 +2319,60 @@ msgstr ""
msgid "libfaad: libfaad NeAACDecInit failed.\n"
msgstr ""
-#: src/libffmpeg/ff_audio_decoder.c:120
+#: src/libffmpeg/ff_audio_decoder.c:122
#, c-format
msgid "ffmpeg_audio_dec: increasing buffer to %d to avoid overflow.\n"
msgstr ""
-#: src/libffmpeg/ff_audio_decoder.c:164
+#: src/libffmpeg/ff_audio_decoder.c:166
#, c-format
msgid "ffmpeg_audio_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"
msgstr ""
-#: src/libffmpeg/ff_audio_decoder.c:256
+#: src/libffmpeg/ff_audio_decoder.c:258
msgid "ffmpeg_audio_dec: trying to open null codec\n"
msgstr ""
-#: src/libffmpeg/ff_audio_decoder.c:265
+#: src/libffmpeg/ff_audio_decoder.c:267
msgid "ffmpeg_audio_dec: couldn't open decoder\n"
msgstr ""
-#: src/libffmpeg/ff_dvaudio_decoder.c:286
+#: src/libffmpeg/ff_dvaudio_decoder.c:280
#, c-format
msgid "dvaudio: increasing buffer to %d to avoid overflow.\n"
msgstr ""
-#: src/libffmpeg/ff_video_decoder.c:157
+#: src/libffmpeg/ff_video_decoder.c:155
msgid "ffmpeg_video_dec: unsupported frame format, DR1 disabled.\n"
msgstr ""
-#: src/libffmpeg/ff_video_decoder.c:175
+#: src/libffmpeg/ff_video_decoder.c:173
msgid "ffmpeg_video_dec: unsupported frame dimensions, DR1 disabled.\n"
msgstr ""
-#: src/libffmpeg/ff_video_decoder.c:335
+#: src/libffmpeg/ff_video_decoder.c:333
#, c-format
msgid "ffmpeg_video_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"
msgstr ""
-#: src/libffmpeg/ff_video_decoder.c:364
+#: src/libffmpeg/ff_video_decoder.c:362
msgid "ffmpeg_video_dec: couldn't open decoder\n"
msgstr ""
-#: src/libffmpeg/ff_video_decoder.c:399
+#: src/libffmpeg/ff_video_decoder.c:397
msgid "ffmpeg_video_dec: direct rendering enabled\n"
msgstr ""
-#: src/libffmpeg/ff_video_decoder.c:818
+#: src/libffmpeg/ff_video_decoder.c:816
#, c-format
msgid "ffmpeg_video_dec: increasing buffer to %d to avoid overflow.\n"
msgstr ""
-#: src/libffmpeg/ff_video_decoder.c:1516
+#: src/libffmpeg/ff_video_decoder.c:1514
msgid "MPEG-4 postprocessing quality"
msgstr ""
-#: src/libffmpeg/ff_video_decoder.c:1517
+#: src/libffmpeg/ff_video_decoder.c:1515
msgid ""
"You can adjust the amount of post processing applied to MPEG-4 video.\n"
"Higher values result in better quality, but need more CPU. Lower values may "
@@ -2401,59 +2381,59 @@ msgid ""
"much."
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:167
+#: src/libffmpeg/ffmpeg_encoder.c:163
msgid "libavcodec mpeg output bitrate (kbit/s)"
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:168
+#: src/libffmpeg/ffmpeg_encoder.c:164
msgid ""
"The bitrate the libavcodec mpeg encoder should use for DXR3's encoding mode. "
"Higher values will increase quality and CPU usage.\n"
"This setting is only considered, when constant quality mode is disabled."
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:175
+#: src/libffmpeg/ffmpeg_encoder.c:171
msgid "constant quality mode"
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:176
+#: src/libffmpeg/ffmpeg_encoder.c:172
msgid ""
"When enabled, libavcodec will use a constant quality mode by dynamically "
"compressing the images based on their complexity. When disabled, libavcodec "
"will use constant bitrate mode."
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:183
+#: src/libffmpeg/ffmpeg_encoder.c:179
msgid "minimum compression"
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:184
+#: src/libffmpeg/ffmpeg_encoder.c:180
msgid "The minimum compression to apply to an image in constant quality mode."
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:189
+#: src/libffmpeg/ffmpeg_encoder.c:185
msgid "maximum quantizer"
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:190
+#: src/libffmpeg/ffmpeg_encoder.c:186
msgid "The maximum compression to apply to an image in constant quality mode."
msgstr ""
-#: src/libmusepack/xine_musepack_decoder.c:241
+#: src/libxineadec/xine_musepack_decoder.c:249
#, c-format
msgid "libmusepack: mpc_streaminfo_read failed: %d\n"
msgstr ""
-#: src/libmusepack/xine_musepack_decoder.c:315
+#: src/libxineadec/xine_musepack_decoder.c:323
msgid "libmusepack: data after last frame ignored\n"
msgstr ""
-#: src/libmusepack/xine_musepack_decoder.c:326
+#: src/libxineadec/xine_musepack_decoder.c:334
msgid "libmusepack: mpc_decoder_initialise failed\n"
msgstr ""
-#: src/libmusepack/xine_musepack_decoder.c:346
-#: src/libmusepack/xine_musepack_decoder.c:361
+#: src/libxineadec/xine_musepack_decoder.c:354
+#: src/libxineadec/xine_musepack_decoder.c:369
#, c-format
msgid "libmusepack: mpc_decoder_decode failed: %d\n"
msgstr ""
@@ -3150,7 +3130,7 @@ msgid "Select the video output layer by its id."
msgstr ""
#: src/video_out/video_out_directfb.c:1804
-#: src/video_out/video_out_directfb.c:2013
+#: src/video_out/video_out_directfb.c:2014
#, c-format
msgid "video_out_directfb: using display layer #%d.\n"
msgstr ""
@@ -3160,11 +3140,11 @@ msgstr ""
msgid "xine video output plugin using DirectFB."
msgstr "http network stream input plugin"
-#: src/video_out/video_out_directfb.c:2006
+#: src/video_out/video_out_directfb.c:2007
msgid "video_out_directfb: no usable display layer was found!\n"
msgstr ""
-#: src/video_out/video_out_directfb.c:2095
+#: src/video_out/video_out_directfb.c:2096
#, fuzzy
msgid "xine video output plugin using DirectFB under XDirectFB."
msgstr "http network stream input plugin"
@@ -3173,18 +3153,18 @@ msgstr "http network stream input plugin"
msgid "xine video output plugin for win32 using directx"
msgstr ""
-#: src/video_out/video_out_fb.c:792
+#: src/video_out/video_out_fb.c:780
#, c-format
msgid ""
"video_out_fb: only packed truecolor/directcolor is supported (%d).\n"
" Check 'fbset -i' or try 'fbset -depth 16'.\n"
msgstr ""
-#: src/video_out/video_out_fb.c:852 src/video_out/video_out_vidix.c:1239
+#: src/video_out/video_out_fb.c:840 src/video_out/video_out_vidix.c:1239
msgid "framebuffer device name"
msgstr ""
-#: src/video_out/video_out_fb.c:853 src/video_out/video_out_vidix.c:1240
+#: src/video_out/video_out_fb.c:841 src/video_out/video_out_vidix.c:1240
msgid ""
"Specifies the file name for the framebuffer device to be used.\n"
"This setting is security critical, because when changed to a different file, "
@@ -3192,39 +3172,40 @@ msgid ""
"careful that the value you enter really is a proper framebuffer device."
msgstr ""
-#: src/video_out/video_out_fb.c:927
-msgid "video_out_fb: Your video mode was not recognized, sorry.\n"
+#: src/video_out/video_out_fb.c:915
+#, c-format
+msgid "%s: Your video mode was not recognized, sorry.\n"
msgstr ""
-#: src/video_out/video_out_fb.c:984
+#: src/video_out/video_out_fb.c:972
#, c-format
-msgid "video_out_fb: %d video RAM buffers are available.\n"
+msgid "%s: %d video RAM buffers are available.\n"
msgstr ""
-#: src/video_out/video_out_fb.c:990
+#: src/video_out/video_out_fb.c:978
#, c-format
msgid ""
-"WARNING: video_out_fb: Zero copy buffers are DISABLED because only %d "
-"buffers\n"
+"WARNING: %s: Zero copy buffers are DISABLED because only %d buffers\n"
" are available which is less than the recommended %d buffers. Lowering\n"
" the frame buffer resolution might help.\n"
msgstr ""
-#: src/video_out/video_out_fb.c:1001
+#: src/video_out/video_out_fb.c:989
+#, c-format
msgid ""
-"WARNING: video_out_fb: Zero copy buffers are DISABLED because kernel driver\n"
+"WARNING: %s: Zero copy buffers are DISABLED because kernel driver\n"
" do not support screen panning (used for frame flips).\n"
msgstr ""
-#: src/video_out/video_out_fb.c:1070
+#: src/video_out/video_out_fb.c:1058
#, c-format
msgid ""
-"WARNING: video_out_fb: current display depth is %d. For better performance\n"
+"WARNING: %s: current display depth is %d. For better performance\n"
" a depth of 16 bpp is recommended!\n"
"\n"
msgstr ""
-#: src/video_out/video_out_fb.c:1101
+#: src/video_out/video_out_fb.c:1090
msgid "Xine video output plugin using the Linux frame buffer device"
msgstr ""
@@ -3276,8 +3257,8 @@ msgid ""
msgstr ""
#: src/video_out/video_out_opengl.c:1918 src/video_out/video_out_vidix.c:1015
-#: src/video_out/video_out_xcbxv.c:1472 src/video_out/video_out_xv.c:1486
-#: src/video_out/video_out_xvmc.c:1461 src/video_out/video_out_xxmc.c:2468
+#: src/video_out/video_out_xcbxv.c:1476 src/video_out/video_out_xv.c:1489
+#: src/video_out/video_out_xvmc.c:1461 src/video_out/video_out_xxmc.c:2465
msgid "enable double buffering"
msgstr ""
@@ -3352,9 +3333,9 @@ msgstr ""
msgid "video_out_pgx64: Error: ioctl failed (FBIOGATTR)\n"
msgstr ""
-#: src/video_out/video_out_pgx64.c:1464 src/video_out/video_out_xcbxv.c:1439
-#: src/video_out/video_out_xv.c:1453 src/video_out/video_out_xvmc.c:1446
-#: src/video_out/video_out_xxmc.c:2435
+#: src/video_out/video_out_pgx64.c:1464 src/video_out/video_out_xcbxv.c:1443
+#: src/video_out/video_out_xv.c:1456 src/video_out/video_out_xvmc.c:1446
+#: src/video_out/video_out_xxmc.c:2432
msgid "video overlay colour key"
msgstr ""
@@ -3504,9 +3485,9 @@ msgstr ""
msgid "The intensity of the blue colour components."
msgstr ""
-#: src/video_out/video_out_vidix.c:1016 src/video_out/video_out_xcbxv.c:1473
-#: src/video_out/video_out_xv.c:1487 src/video_out/video_out_xvmc.c:1462
-#: src/video_out/video_out_xxmc.c:2469
+#: src/video_out/video_out_vidix.c:1016 src/video_out/video_out_xcbxv.c:1477
+#: src/video_out/video_out_xv.c:1490 src/video_out/video_out_xvmc.c:1462
+#: src/video_out/video_out_xxmc.c:2466
msgid ""
"Double buffering will synchronize the update of the video image to the "
"repainting of the entire screen (\"vertical retrace\"). This eliminates "
@@ -3539,9 +3520,9 @@ msgid "video overlay colour key red component"
msgstr ""
#: src/video_out/video_out_vidix.c:1159 src/video_out/video_out_vidix.c:1166
-#: src/video_out/video_out_vidix.c:1173 src/video_out/video_out_xcbxv.c:1440
-#: src/video_out/video_out_xv.c:1454 src/video_out/video_out_xvmc.c:1447
-#: src/video_out/video_out_xxmc.c:2436
+#: src/video_out/video_out_vidix.c:1173 src/video_out/video_out_xcbxv.c:1444
+#: src/video_out/video_out_xv.c:1457 src/video_out/video_out_xvmc.c:1447
+#: src/video_out/video_out_xxmc.c:2433
msgid ""
"The colour key is used to tell the graphics card where to overlay the video "
"image. Try different values, if you experience windows becoming transparent."
@@ -3563,27 +3544,38 @@ msgstr ""
msgid "xine video output plugin using libvidix for linux frame buffer"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:157
+#: src/video_out/video_out_xcbshm.c:157 src/video_out/video_out_xshm.c:219
#, c-format
-msgid ""
-"video_out_xcbshm: %s: allocating image\n"
-"video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+msgid "%s: %s: allocating image\n"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:166
-msgid ""
-"video_out_xcbshm: shared memory error (address error) when allocating "
-"image \n"
-"video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbshm.c:159 src/video_out/video_out_xcbshm.c:169
+#: src/video_out/video_out_xcbshm.c:181 src/video_out/video_out_xcbxv.c:272
+#: src/video_out/video_out_xcbxv.c:282 src/video_out/video_out_xcbxv.c:292
+#: src/video_out/video_out_xcbxv.c:304 src/video_out/video_out_xshm.c:204
+#: src/video_out/video_out_xshm.c:221 src/video_out/video_out_xshm.c:232
+#: src/video_out/video_out_xshm.c:251 src/video_out/video_out_xv.c:296
+#: src/video_out/video_out_xv.c:307 src/video_out/video_out_xv.c:316
+#: src/video_out/video_out_xv.c:352 src/video_out/video_out_xxmc.c:648
+#: src/video_out/video_out_xxmc.c:659 src/video_out/video_out_xxmc.c:668
+#: src/video_out/video_out_xxmc.c:704
+#, c-format
+msgid "%s: => not using MIT Shared Memory extension.\n"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:177
-msgid ""
-"video_out_xcbshm: x11 error during shared memory XImage creation\n"
-"video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbshm.c:167 src/video_out/video_out_xshm.c:230
+#, c-format
+msgid "%s: shared memory error (address error) when allocating image \n"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:1100 src/video_out/video_out_xshm.c:1157
+#: src/video_out/video_out_xcbshm.c:179 src/video_out/video_out_xcbxv.c:302
+#: src/video_out/video_out_xshm.c:249 src/video_out/video_out_xv.c:350
+#: src/video_out/video_out_xxmc.c:702
+#, c-format
+msgid "%s: x11 error during shared memory XImage creation\n"
+msgstr ""
+
+#: src/video_out/video_out_xcbshm.c:1103 src/video_out/video_out_xshm.c:1161
#, c-format
msgid ""
"\n"
@@ -3593,73 +3585,75 @@ msgid ""
"\n"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:1113
-msgid "video_out_xcbshm: MIT shared memory extension not present on display.\n"
+#: src/video_out/video_out_xcbshm.c:1116 src/video_out/video_out_xshm.c:1174
+#, c-format
+msgid "%s: MIT shared memory extension not present on display.\n"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:1212
-msgid "video_out_xcbshm: your video mode was not recognized, sorry :-(\n"
+#: src/video_out/video_out_xcbshm.c:1215 src/video_out/video_out_xshm.c:1258
+#, c-format
+msgid "%s: your video mode was not recognized, sorry :-(\n"
msgstr ""
-#: src/video_out/video_out_xcbshm.c:1242 src/video_out/video_out_xshm.c:1303
+#: src/video_out/video_out_xcbshm.c:1245 src/video_out/video_out_xshm.c:1307
msgid "xine video output plugin using the MIT X shared memory extension"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:272
-msgid ""
-"video_out_xcbxv: XvShmCreateImage returned a zero size\n"
-"video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbxv.c:270 src/video_out/video_out_xv.c:305
+#: src/video_out/video_out_xxmc.c:657
+#, c-format
+msgid "%s: XvShmCreateImage returned a zero size\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:281
+#: src/video_out/video_out_xcbxv.c:280 src/video_out/video_out_xv.c:314
+#: src/video_out/video_out_xxmc.c:666
#, c-format
-msgid ""
-"video_out_xcbxv: shared memory error in shmget: %s\n"
-"video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+msgid "%s: shared memory error in shmget: %s\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:300
-msgid ""
-"video_out_xcbxv: x11 error during shared memory XImage creation\n"
-"video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbxv.c:290
+#, c-format
+msgid "%s: shared memory error (address error)\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1291
-msgid "video_out_xcbxv: Xv extension not present.\n"
+#: src/video_out/video_out_xcbxv.c:1294 src/video_out/video_out_xv.c:1301
+#: src/video_out/video_out_xxmc.c:2283
+#, c-format
+msgid "%s: Xv extension not present.\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1333
+#: src/video_out/video_out_xcbxv.c:1336 src/video_out/video_out_xv.c:1338
+#: src/video_out/video_out_xxmc.c:2320
+#, c-format
msgid ""
-"video_out_xcbxv: Xv extension is present but I couldn't find a usable yuv12 "
-"port.\n"
-" Looks like your graphics hardware driver doesn't support "
-"Xv?!\n"
+"%s: Xv extension is present but I couldn't find a usable yuv12 port.\n"
+"\tLooks like your graphics hardware driver doesn't support Xv?!\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1341
+#: src/video_out/video_out_xcbxv.c:1345
#, c-format
msgid ""
-"video_out_xcbxv: using Xv port %d from adaptor %s for hardware colorspace "
-"conversion and scaling.\n"
+"%s: using Xv port %d from adaptor %s for hardware colorspace conversion and "
+"scaling.\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1448 src/video_out/video_out_xv.c:1462
-#: src/video_out/video_out_xvmc.c:1455 src/video_out/video_out_xxmc.c:2444
+#: src/video_out/video_out_xcbxv.c:1452 src/video_out/video_out_xv.c:1465
+#: src/video_out/video_out_xvmc.c:1455 src/video_out/video_out_xxmc.c:2441
msgid "autopaint colour key"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1449 src/video_out/video_out_xv.c:1463
-#: src/video_out/video_out_xvmc.c:1456 src/video_out/video_out_xxmc.c:2445
+#: src/video_out/video_out_xcbxv.c:1453 src/video_out/video_out_xv.c:1466
+#: src/video_out/video_out_xvmc.c:1456 src/video_out/video_out_xxmc.c:2442
msgid "Make Xv autopaint its colorkey."
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1456 src/video_out/video_out_xv.c:1470
-#: src/video_out/video_out_xxmc.c:2452
+#: src/video_out/video_out_xcbxv.c:1460 src/video_out/video_out_xv.c:1473
+#: src/video_out/video_out_xxmc.c:2449
msgid "bilinear scaling mode"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1457 src/video_out/video_out_xv.c:1471
-#: src/video_out/video_out_xxmc.c:2453
+#: src/video_out/video_out_xcbxv.c:1461 src/video_out/video_out_xv.c:1474
+#: src/video_out/video_out_xxmc.c:2450
msgid ""
"Selects the bilinear scaling mode for Permedia cards. The individual values "
"are:\n"
@@ -3674,30 +3668,34 @@ msgid ""
"2 - enable full bilinear filtering"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1509
-msgid "video_out_xcbxv: this adaptor supports the yv12 format.\n"
+#: src/video_out/video_out_xcbxv.c:1513 src/video_out/video_out_xv.c:1523
+#: src/video_out/video_out_xxmc.c:2506
+#, c-format
+msgid "%s: this adaptor supports the yv12 format.\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1514
-msgid "video_out_xcbxv: this adaptor supports the yuy2 format.\n"
+#: src/video_out/video_out_xcbxv.c:1518 src/video_out/video_out_xv.c:1528
+#: src/video_out/video_out_xxmc.c:2511
+#, c-format
+msgid "%s: this adaptor supports the yuy2 format.\n"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1522 src/video_out/video_out_xv.c:1547
-#: src/video_out/video_out_xxmc.c:2537
+#: src/video_out/video_out_xcbxv.c:1526 src/video_out/video_out_xv.c:1550
+#: src/video_out/video_out_xxmc.c:2534
msgid "pitch alignment workaround"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1523 src/video_out/video_out_xv.c:1548
-#: src/video_out/video_out_xxmc.c:2538
+#: src/video_out/video_out_xcbxv.c:1527 src/video_out/video_out_xv.c:1551
+#: src/video_out/video_out_xxmc.c:2535
msgid "Some buggy video drivers need a workaround to function properly."
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1529 src/video_out/video_out_xv.c:1554
+#: src/video_out/video_out_xcbxv.c:1533 src/video_out/video_out_xv.c:1557
#: src/video_out/video_out_xvmc.c:1524
msgid "deinterlace method (deprecated)"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1530 src/video_out/video_out_xv.c:1555
+#: src/video_out/video_out_xcbxv.c:1534 src/video_out/video_out_xv.c:1558
#: src/video_out/video_out_xvmc.c:1525
msgid ""
"This config setting is deprecated. You should use the new deinterlacing post "
@@ -3736,93 +3734,26 @@ msgid ""
"with medium CPU usage."
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1584 src/video_out/video_out_xv.c:1628
-#: src/video_out/video_out_xxmc.c:2618
+#: src/video_out/video_out_xcbxv.c:1588 src/video_out/video_out_xv.c:1631
+#: src/video_out/video_out_xxmc.c:2615
msgid "xine video output plugin using the MIT X video extension"
msgstr ""
#: src/video_out/video_out_xshm.c:202
-msgid ""
-"video_out_xshm: shared memory error when allocating image\n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xshm.c:218
#, c-format
-msgid ""
-"video_out_xshm: %s: allocating image\n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xshm.c:228
-msgid ""
-"video_out_xshm: shared memory error (address error) when allocating image \n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xshm.c:245
-msgid ""
-"video_out_xshm: x11 error during shared memory XImage creation\n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xshm.c:1170
-msgid "video_out_xshm: MIT shared memory extension not present on display.\n"
-msgstr ""
-
-#: src/video_out/video_out_xshm.c:1254
-msgid "video_out_xshm: your video mode was not recognized, sorry :-(\n"
+msgid "%s: shared memory error when allocating image\n"
msgstr ""
-#: src/video_out/video_out_xv.c:296
-msgid ""
-"video_out_xv: XvShmCreateImage failed\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:306
-msgid ""
-"video_out_xv: XvShmCreateImage returned a zero size\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:314
+#: src/video_out/video_out_xv.c:294 src/video_out/video_out_xxmc.c:646
#, c-format
-msgid ""
-"video_out_xv: shared memory error in shmget: %s\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:346
-msgid ""
-"video_out_xv: x11 error during shared memory XImage creation\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:1299
-msgid "video_out_xv: Xv extension not present.\n"
+msgid "%s: XvShmCreateImage failed\n"
msgstr ""
-#: src/video_out/video_out_xv.c:1336
-msgid ""
-"video_out_xv: Xv extension is present but I couldn't find a usable yuv12 "
-"port.\n"
-" Looks like your graphics hardware driver doesn't support Xv?!\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:1345
+#: src/video_out/video_out_xv.c:1348 src/video_out/video_out_xxmc.c:2330
#, c-format
msgid ""
-"video_out_xv: using Xv port %ld from adaptor %s for hardware colorspace "
-"conversion and scaling.\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:1520
-msgid "video_out_xv: this adaptor supports the yv12 format.\n"
-msgstr ""
-
-#: src/video_out/video_out_xv.c:1525
-msgid "video_out_xv: this adaptor supports the yuy2 format.\n"
+"%s: using Xv port %ld from adaptor %s for hardware colorspace conversion and "
+"scaling.\n"
msgstr ""
#: src/video_out/video_out_xvmc.c:1593
@@ -3863,94 +3794,43 @@ msgstr ""
msgid " With Overlay = %d; UnsignedIntra = %d.\n"
msgstr ""
-#: src/video_out/video_out_xxmc.c:650
-msgid ""
-"video_out_xxmc: XvShmCreateImage failed\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:660
-msgid ""
-"video_out_xxmc: XvShmCreateImage returned a zero size\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:668
-#, c-format
-msgid ""
-"video_out_xxmc: shared memory error in shmget: %s\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:700
-msgid ""
-"video_out_xxmc: x11 error during shared memory XImage creation\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:2287
-msgid "video_out_xxmc: Xv extension not present.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:2324
-msgid ""
-"video_out_xxmc: Xv extension is present but I couldn't find a usable yuv12 "
-"port.\n"
-" Looks like your graphics hardware driver doesn't support Xv?!\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:2333
-#, c-format
-msgid ""
-"video_out_xxmc: using Xv port %ld from adaptor %s for hardware colorspace "
-"conversion and scaling.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:2509
-msgid "video_out_xxmc: this adaptor supports the yv12 format.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:2514
-msgid "video_out_xxmc: this adaptor supports the yuy2 format.\n"
-msgstr ""
-
-#: src/video_out/video_out_xxmc.c:2543
+#: src/video_out/video_out_xxmc.c:2540
msgid "Make XvMC allocate more frames for better buffering."
msgstr ""
-#: src/video_out/video_out_xxmc.c:2544
+#: src/video_out/video_out_xxmc.c:2541
msgid ""
"Some XvMC implementations allow more than 8 frames.\n"
"This option, when turned on, makes the driver try to\n"
"allocate 15 frames. A must for unichrome and live VDR.\n"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2550
+#: src/video_out/video_out_xxmc.c:2547
msgid "Unichrome cpu save"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2551
+#: src/video_out/video_out_xxmc.c:2548
msgid ""
"Saves CPU time by sleeping while decoder works.\n"
"Only for Linux kernel 2.6 series or 2.4 with multimedia patch.\n"
"Experimental.\n"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2557
+#: src/video_out/video_out_xxmc.c:2554
msgid "Fix buggy NVIDIA XvMC subpicture colors"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2558
+#: src/video_out/video_out_xxmc.c:2555
msgid ""
"There's a bug in NVIDIA's XvMC lib that makes red OSD colors\n"
"look blue and vice versa. This option provides a workaround.\n"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2563
+#: src/video_out/video_out_xxmc.c:2560
msgid "Use bob as accelerated deinterlace method."
msgstr ""
-#: src/video_out/video_out_xxmc.c:2564
+#: src/video_out/video_out_xxmc.c:2561
msgid ""
"When interlacing is enabled for hardware accelerated frames,\n"
"Alternate between top and bottom field at double the frame rate.\n"
@@ -4174,12 +4054,12 @@ msgid ""
"info_helper: unsupported conversion %s -> UTF-8, no conversion performed\n"
msgstr ""
-#: src/xine-engine/input_cache.c:167
+#: src/xine-engine/input_cache.c:171
#, c-format
msgid ": open() function should never be called\n"
msgstr ""
-#: src/xine-engine/input_cache.c:349
+#: src/xine-engine/input_cache.c:353
#, fuzzy, c-format
msgid ": input plugin not defined!\n"
msgstr "xine: usando plugin de entrada >%s< para este MRL (%s).\n"
@@ -4288,81 +4168,81 @@ msgstr ""
msgid "io_helper: Connection Refused\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:212
+#: src/xine-engine/load_plugins.c:215
#, c-format
msgid "map_decoder_list: no space for decoder, skipped.\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:327
+#: src/xine-engine/load_plugins.c:330
#, c-format
msgid ""
"load_plugins: ignoring plugin %s, wrong iface version %d (should be %d)\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:384
+#: src/xine-engine/load_plugins.c:387
#, c-format
msgid "priority for %s decoder"
msgstr ""
-#: src/xine-engine/load_plugins.c:395
+#: src/xine-engine/load_plugins.c:398
msgid ""
"The priority provides a ranking in case some media can be handled by more "
"than one decoder.\n"
"A priority of 0 enables the decoder's default priority."
msgstr ""
-#: src/xine-engine/load_plugins.c:423
+#: src/xine-engine/load_plugins.c:426
#, c-format
msgid ""
"load_plugins: demuxer plugin %s does not provide a priority, xine-lib will "
"use the default priority.\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:440
+#: src/xine-engine/load_plugins.c:443
#, c-format
msgid ""
"load_plugins: input plugin %s does not provide a priority, xine-lib will use "
"the default priority.\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:496
+#: src/xine-engine/load_plugins.c:499
#, fuzzy, c-format
msgid "load_plugins: plugin %s found\n"
msgstr "load_plugins: achado o plugin de entrada: %s\n"
-#: src/xine-engine/load_plugins.c:499
+#: src/xine-engine/load_plugins.c:502
#, fuzzy, c-format
msgid "load_plugins: static plugin found\n"
msgstr "load_plugins: achado o plugin de entrada: %s\n"
-#: src/xine-engine/load_plugins.c:506
+#: src/xine-engine/load_plugins.c:509
#, fuzzy, c-format
msgid "load_plugins: plugin limit reached, %s could not be loaded\n"
msgstr "load_plugins: achado o plugin de entrada: %s\n"
-#: src/xine-engine/load_plugins.c:509
+#: src/xine-engine/load_plugins.c:512
#, fuzzy, c-format
msgid "load_plugins: plugin limit reached, static plugin could not be loaded\n"
msgstr "load_plugins: achado o plugin de entrada: %s\n"
-#: src/xine-engine/load_plugins.c:526
+#: src/xine-engine/load_plugins.c:529
#, fuzzy, c-format
msgid "load_plugins: unknown plugin type %d in %s\n"
msgstr "load_plugins: achado o plugin de entrada: %s\n"
-#: src/xine-engine/load_plugins.c:530
+#: src/xine-engine/load_plugins.c:533
#, fuzzy, c-format
msgid "load_plugins: unknown statically linked plugin type %d\n"
msgstr "load_plugins: achado o plugin de entrada: %s\n"
-#: src/xine-engine/load_plugins.c:590
+#: src/xine-engine/load_plugins.c:593
#, fuzzy, c-format
msgid "load_plugins: unable to stat %s\n"
msgstr ""
"load_plugins: carga do plugin %s falhou:\n"
"%s\n"
-#: src/xine-engine/load_plugins.c:631
+#: src/xine-engine/load_plugins.c:634
#, fuzzy, c-format
msgid ""
"load_plugins: cannot open plugin lib %s:\n"
@@ -4371,7 +4251,7 @@ msgstr ""
"load_plugins: não consigo abrir o plugin de demux %s:\n"
"%s\n"
-#: src/xine-engine/load_plugins.c:646
+#: src/xine-engine/load_plugins.c:649
#, fuzzy, c-format
msgid ""
"load_plugins: can't get plugin info from %s:\n"
@@ -4380,12 +4260,12 @@ msgstr ""
"load_plugins: não consigo abrir o plugin de entrada %s:\n"
"%s\n"
-#: src/xine-engine/load_plugins.c:664
+#: src/xine-engine/load_plugins.c:667
#, fuzzy, c-format
msgid "load_plugins: skipping unreadable plugin directory %s.\n"
msgstr "load_plugins: achado o plugin de entrada: %s\n"
-#: src/xine-engine/load_plugins.c:713
+#: src/xine-engine/load_plugins.c:716
#, fuzzy, c-format
msgid ""
"load_plugins: cannot (stage 2) open plugin lib %s:\n"
@@ -4394,37 +4274,42 @@ msgstr ""
"load_plugins: não consigo abrir o plugin de demux %s:\n"
"%s\n"
-#: src/xine-engine/load_plugins.c:739
+#: src/xine-engine/load_plugins.c:742
#, fuzzy, c-format
msgid "load_plugins: Yikes! %s doesn't contain plugin info.\n"
msgstr ""
"load_plugins: não consigo abrir o plugin de entrada %s:\n"
"%s\n"
-#: src/xine-engine/load_plugins.c:1305
+#: src/xine-engine/load_plugins.c:1104 src/xine-engine/load_plugins.c:1113
+#, fuzzy, c-format
+msgid "Unable to create %s directory: %s\n"
+msgstr "incapaz de alocar buffer de entrada.\n"
+
+#: src/xine-engine/load_plugins.c:1345
#, fuzzy, c-format
msgid "load_plugins: unknown content detection strategy %d\n"
msgstr "load_plugins: achado o plugin de entrada: %s\n"
-#: src/xine-engine/load_plugins.c:1415
+#: src/xine-engine/load_plugins.c:1455
#, fuzzy, c-format
msgid "load_plugins: using demuxer '%s'\n"
msgstr "load_plugins: achado o plugin de entrada: %s\n"
-#: src/xine-engine/load_plugins.c:1726
+#: src/xine-engine/load_plugins.c:1766
#, fuzzy, c-format
msgid "load_plugins: failed to load audio output plugin <%s>\n"
msgstr ""
"load_plugins: carga do plugin %s falhou:\n"
"%s\n"
-#: src/xine-engine/load_plugins.c:1729
+#: src/xine-engine/load_plugins.c:1769
msgid ""
"load_plugins: audio output auto-probing didn't find any usable audio "
"driver.\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:2033
+#: src/xine-engine/load_plugins.c:2073
#, fuzzy, c-format
msgid ""
"load_plugins: cannot unload plugin lib %s:\n"
@@ -4433,31 +4318,27 @@ msgstr ""
"load_plugins: não consigo abrir o plugin de demux %s:\n"
"%s\n"
-#: src/xine-engine/osd.c:745
+#: src/xine-engine/osd.c:747
#, c-format
msgid "font '%s-%d' already loaded, weird.\n"
msgstr ""
-#: src/xine-engine/osd.c:757
+#: src/xine-engine/osd.c:759
#, c-format
msgid "font '%s' loading failed (%d < %d)\n"
msgstr ""
-#: src/xine-engine/osd.c:767
+#: src/xine-engine/osd.c:769
#, c-format
msgid "wrong version for font '%s'. expected %d found %d.\n"
msgstr ""
-#: src/xine-engine/osd.c:834
-msgid "osd: cannot initialize ft2 library\n"
-msgstr ""
-
-#: src/xine-engine/osd.c:857
+#: src/xine-engine/osd.c:856
#, c-format
msgid "osd: error matching font %s with FontConfig"
msgstr ""
-#: src/xine-engine/osd.c:871
+#: src/xine-engine/osd.c:870
#, c-format
msgid "osd: error loading font %s with FontConfig"
msgstr ""
@@ -4467,57 +4348,61 @@ msgstr ""
msgid "osd: error looking up font %s with FontConfig"
msgstr ""
-#: src/xine-engine/osd.c:895
+#: src/xine-engine/osd.c:914
#, c-format
-msgid "osd: error loading font %s with ft2\n"
+msgid "osd: error loading font %s with in XDG data directories.\n"
+msgstr ""
+
+#: src/xine-engine/osd.c:923
+msgid "osd: cannot initialize ft2 library\n"
msgstr ""
-#: src/xine-engine/osd.c:905
+#: src/xine-engine/osd.c:945
msgid "osd: error setting font size (no scalable font?)\n"
msgstr ""
-#: src/xine-engine/osd.c:1021
+#: src/xine-engine/osd.c:1061
#, c-format
msgid ""
"osd: unknown sequence starting with byte 0x%02X in encoding \"%s\", "
"skipping\n"
msgstr ""
-#: src/xine-engine/osd.c:1077
+#: src/xine-engine/osd.c:1117
msgid "osd: can't find out current locale character set\n"
msgstr ""
-#: src/xine-engine/osd.c:1087
+#: src/xine-engine/osd.c:1127
#, c-format
msgid "osd: unsupported conversion %s -> %s, no conversion performed\n"
msgstr ""
-#: src/xine-engine/osd.c:1142 src/xine-engine/osd.c:1310
+#: src/xine-engine/osd.c:1182 src/xine-engine/osd.c:1350
msgid "osd: font isn't defined\n"
msgstr ""
-#: src/xine-engine/osd.c:1181
+#: src/xine-engine/osd.c:1221
msgid "osd: error loading glyph\n"
msgstr ""
-#: src/xine-engine/osd.c:1187
+#: src/xine-engine/osd.c:1227
msgid "osd: error in rendering glyph\n"
msgstr ""
-#: src/xine-engine/osd.c:1347
+#: src/xine-engine/osd.c:1387
#, c-format
msgid "osd: error loading glyph %i\n"
msgstr ""
-#: src/xine-engine/osd.c:1354
+#: src/xine-engine/osd.c:1394
msgid "osd: error in rendering\n"
msgstr ""
-#: src/xine-engine/osd.c:1611
+#: src/xine-engine/osd.c:1660
msgid "palette (foreground-border-background) to use for subtitles and OSD"
msgstr ""
-#: src/xine-engine/osd.c:1612
+#: src/xine-engine/osd.c:1661
msgid ""
"The palette for on-screen-display and some subtitle formats that do not "
"specify any colouring themselves. The palettes are listed in the form: "
@@ -4635,129 +4520,129 @@ msgid ""
"accelerated, this can dramatically reduce CPU usage."
msgstr ""
-#: src/xine-engine/xine.c:704 src/xine-engine/xine.c:811
-#: src/xine-engine/xine.c:850 src/xine-engine/xine.c:886
-#: src/xine-engine/xine.c:898 src/xine-engine/xine.c:911
-#: src/xine-engine/xine.c:924 src/xine-engine/xine.c:937
-#: src/xine-engine/xine.c:963 src/xine-engine/xine.c:988
-#: src/xine-engine/xine.c:1023
+#: src/xine-engine/xine.c:706 src/xine-engine/xine.c:813
+#: src/xine-engine/xine.c:852 src/xine-engine/xine.c:888
+#: src/xine-engine/xine.c:900 src/xine-engine/xine.c:913
+#: src/xine-engine/xine.c:926 src/xine-engine/xine.c:939
+#: src/xine-engine/xine.c:965 src/xine-engine/xine.c:990
+#: src/xine-engine/xine.c:1025
msgid "xine: error while parsing mrl\n"
msgstr ""
-#: src/xine-engine/xine.c:740
+#: src/xine-engine/xine.c:742
#, fuzzy, c-format
msgid "xine: found input plugin : %s\n"
msgstr "xine: não consigo achar um plugin para este MRL\n"
-#: src/xine-engine/xine.c:758
+#: src/xine-engine/xine.c:760
#, fuzzy, c-format
msgid "xine: input plugin cannot open MRL [%s]\n"
msgstr "xine: usando plugin de entrada >%s< para este MRL (%s).\n"
-#: src/xine-engine/xine.c:774
+#: src/xine-engine/xine.c:776
#, fuzzy, c-format
msgid "xine: cannot find input plugin for MRL [%s]\n"
msgstr "xine: não consigo achar um plugin para este MRL\n"
-#: src/xine-engine/xine.c:800
+#: src/xine-engine/xine.c:802
#, fuzzy, c-format
msgid "xine: specified demuxer %s failed to start\n"
msgstr "xine_play: demuxer falhou em começar\n"
-#: src/xine-engine/xine.c:836
+#: src/xine-engine/xine.c:838
#, fuzzy, c-format
msgid "xine: join rip input plugin\n"
msgstr "http network stream input plugin"
-#: src/xine-engine/xine.c:843
+#: src/xine-engine/xine.c:845
#, fuzzy
msgid "xine: error opening rip input plugin instance\n"
msgstr "http network stream input plugin"
-#: src/xine-engine/xine.c:874
+#: src/xine-engine/xine.c:876
#, fuzzy, c-format
msgid "xine: last_probed demuxer %s failed to start\n"
msgstr "xine_play: demuxer falhou em começar\n"
-#: src/xine-engine/xine.c:903
+#: src/xine-engine/xine.c:905
msgid "ignoring video\n"
msgstr ""
-#: src/xine-engine/xine.c:916
+#: src/xine-engine/xine.c:918
msgid "ignoring audio\n"
msgstr ""
-#: src/xine-engine/xine.c:929
+#: src/xine-engine/xine.c:931
msgid "ignoring subpicture\n"
msgstr ""
-#: src/xine-engine/xine.c:942
+#: src/xine-engine/xine.c:944
msgid "input cache plugin disabled\n"
msgstr ""
-#: src/xine-engine/xine.c:1013
+#: src/xine-engine/xine.c:1015
#, c-format
msgid "subtitle mrl opened '%s'\n"
msgstr ""
-#: src/xine-engine/xine.c:1017
+#: src/xine-engine/xine.c:1019
#, fuzzy
msgid "xine: error opening subtitle mrl\n"
msgstr "input_dvd: não consigo abrir o arquivo >%s<\n"
-#: src/xine-engine/xine.c:1049
+#: src/xine-engine/xine.c:1051
#, c-format
msgid "xine: error while parsing MRL\n"
msgstr ""
-#: src/xine-engine/xine.c:1056
+#: src/xine-engine/xine.c:1058
#, c-format
msgid "xine: changing option '%s' from MRL isn't permitted\n"
msgstr ""
-#: src/xine-engine/xine.c:1076
+#: src/xine-engine/xine.c:1078
#, fuzzy, c-format
msgid "xine: couldn't find demux for >%s<\n"
msgstr "xine: não conseguí achar o demuxer para >%s<\n"
-#: src/xine-engine/xine.c:1092
+#: src/xine-engine/xine.c:1094
#, fuzzy, c-format
msgid "xine: found demuxer plugin: %s\n"
msgstr "xine: usando o plugin de demuxer >%s< para este MRL.\n"
-#: src/xine-engine/xine.c:1112
+#: src/xine-engine/xine.c:1114
#, fuzzy, c-format
msgid "xine: demuxer failed to start\n"
msgstr "xine_play: demuxer falhou em começar\n"
-#: src/xine-engine/xine.c:1177
+#: src/xine-engine/xine.c:1179
#, fuzzy, c-format
msgid "xine_play: no demux available\n"
msgstr "xine_play: demuxer falhou em começar\n"
-#: src/xine-engine/xine.c:1247
+#: src/xine-engine/xine.c:1249
#, fuzzy, c-format
msgid "xine_play: demux failed to start\n"
msgstr "xine_play: demuxer falhou em começar\n"
-#: src/xine-engine/xine.c:1523
+#: src/xine-engine/xine.c:1527
#, c-format
msgid "xine: The specified save_dir \"%s\" might be a security risk.\n"
msgstr ""
-#: src/xine-engine/xine.c:1528
+#: src/xine-engine/xine.c:1532
msgid "The specified save_dir might be a security risk."
msgstr ""
-#: src/xine-engine/xine.c:1554
+#: src/xine-engine/xine.c:1561
msgid "xine: locale not supported by C library\n"
msgstr ""
-#: src/xine-engine/xine.c:1563
+#: src/xine-engine/xine.c:1570
msgid "media format detection strategy"
msgstr ""
-#: src/xine-engine/xine.c:1564
+#: src/xine-engine/xine.c:1571
msgid ""
"xine offers various methods to detect the media format of input to play. The "
"individual values are:\n"
@@ -4775,11 +4660,11 @@ msgid ""
"Detect by file name extension only.\n"
msgstr ""
-#: src/xine-engine/xine.c:1582
+#: src/xine-engine/xine.c:1589
msgid "directory for saving streams"
msgstr ""
-#: src/xine-engine/xine.c:1583
+#: src/xine-engine/xine.c:1590
msgid ""
"When using the stream save feature, files will be written only into this "
"directory.\n"
@@ -4789,11 +4674,11 @@ msgid ""
"content in any file."
msgstr ""
-#: src/xine-engine/xine.c:1594
+#: src/xine-engine/xine.c:1601
msgid "allow implicit changes to the configuration (e.g. by MRL)"
msgstr ""
-#: src/xine-engine/xine.c:1595
+#: src/xine-engine/xine.c:1602
msgid ""
"If enabled, you allow xine to change your configuration without explicit "
"actions from your side. For example configuration changes demanded by MRLs "
@@ -4803,26 +4688,26 @@ msgid ""
"configuration, you might end with a totally messed up xine."
msgstr ""
-#: src/xine-engine/xine.c:1609
+#: src/xine-engine/xine.c:1616
msgid "Timeout for network stream reading (in seconds)"
msgstr ""
-#: src/xine-engine/xine.c:1610
+#: src/xine-engine/xine.c:1617
msgid ""
"Specifies the timeout when reading from network streams, in seconds. Too low "
"values might stop streaming when the source is slow or the bandwidth is "
"occupied, too high values will freeze the player if the connection is lost."
msgstr ""
-#: src/xine-engine/xine.c:1962
+#: src/xine-engine/xine.c:1969
msgid "messages"
msgstr "menssagens"
-#: src/xine-engine/xine.c:1963
+#: src/xine-engine/xine.c:1970
msgid "plugin"
msgstr "plugin"
-#: src/xine-engine/xine.c:1964
+#: src/xine-engine/xine.c:1971
msgid "trace"
msgstr ""
diff --git a/po/sk.po b/po/sk.po
index 9def62362..51a7a18f9 100644
--- a/po/sk.po
+++ b/po/sk.po
@@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: xine-lib 1.0\n"
"Report-Msgid-Bugs-To: xine-devel@lists.sourceforge.net\n"
-"POT-Creation-Date: 2007-04-06 15:39+0200\n"
+"POT-Creation-Date: 2007-04-24 21:48+0100\n"
"PO-Revision-Date: 2004-09-15 13:53+0100\n"
"Last-Translator: \n"
"Language-Team: Slovak <ski18n@lists.isternet.sk>\n"
@@ -45,21 +45,21 @@ msgstr ""
msgid "Unknown error"
msgstr "Udalosť neznámeho typu: "
-#: src/audio_out/audio_alsa_out.c:354
+#: src/audio_out/audio_alsa_out.c:351
#, c-format
msgid "audio_alsa_out:Already open...WHY!"
msgstr "audio_alsa_out:Už otvorené...PREČO!"
-#: src/audio_out/audio_alsa_out.c:382
+#: src/audio_out/audio_alsa_out.c:379
#, c-format
msgid "audio_alsa_out: snd_pcm_open() of %s failed: %s\n"
msgstr "audio_alsa_out: snd_pcm_open() z %s zlyhal: %s\n"
-#: src/audio_out/audio_alsa_out.c:384
+#: src/audio_out/audio_alsa_out.c:381
msgid "audio_alsa_out: >>> check if another program already uses PCM <<<\n"
msgstr "audio_alsa_out: >>> skontrolujte Äi už iný program používa PCM <<<\n"
-#: src/audio_out/audio_alsa_out.c:397
+#: src/audio_out/audio_alsa_out.c:394
#, c-format
msgid ""
"audio_alsa_out: broken configuration for this PCM: no configurations "
@@ -68,96 +68,96 @@ msgstr ""
"audio_alsa_out: poškodená konfigurácia pre toto PCM: konfigurácia "
"nedostupná: %s\n"
-#: src/audio_out/audio_alsa_out.c:1289
+#: src/audio_out/audio_alsa_out.c:1286
msgid "notify changes to the hardware mixer"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1290
+#: src/audio_out/audio_alsa_out.c:1287
msgid ""
"When the hardware mixer changes, your application will receive a "
"notification so that it can update its graphical representation of the mixer "
"settings on the fly."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1355
+#: src/audio_out/audio_alsa_out.c:1352
#, c-format
msgid "snd_lib_error_set_handler() failed: %d"
msgstr "snd_lib_error_set_handler() zlyhal: %d"
-#: src/audio_out/audio_alsa_out.c:1362
+#: src/audio_out/audio_alsa_out.c:1359
msgid "sound card can do mmap"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1363
+#: src/audio_out/audio_alsa_out.c:1360
msgid ""
"Enable this, if your sound card and alsa driver support memory mapped IO.\n"
"You can try enabling it and check, if everything works. If it does, this "
"will increase performance."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1372
+#: src/audio_out/audio_alsa_out.c:1369
msgid "device used for mono output"
msgstr "zariadenie pre mono výstup"
-#: src/audio_out/audio_alsa_out.c:1373
+#: src/audio_out/audio_alsa_out.c:1370
msgid ""
"xine will use this alsa device to output mono sound.\n"
"See the alsa documentation for information on alsa devices."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1381
+#: src/audio_out/audio_alsa_out.c:1378
msgid "device used for stereo output"
msgstr "zariadenie pre stereo výstup"
-#: src/audio_out/audio_alsa_out.c:1382
+#: src/audio_out/audio_alsa_out.c:1379
msgid ""
"xine will use this alsa device to output stereo sound.\n"
"See the alsa documentation for information on alsa devices."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1390
+#: src/audio_out/audio_alsa_out.c:1387
msgid "device used for 4-channel output"
msgstr "zariadenie pre 4-kanálový výstup"
-#: src/audio_out/audio_alsa_out.c:1391
+#: src/audio_out/audio_alsa_out.c:1388
msgid ""
"xine will use this alsa device to output 4 channel (4.0) surround sound.\n"
"See the alsa documentation for information on alsa devices."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1400 src/audio_out/audio_alsa_out.c:1410
+#: src/audio_out/audio_alsa_out.c:1397 src/audio_out/audio_alsa_out.c:1407
msgid "device used for 5.1-channel output"
msgstr "zariadenie pre 5.1-kanálový výstup"
-#: src/audio_out/audio_alsa_out.c:1401
+#: src/audio_out/audio_alsa_out.c:1398
msgid ""
"xine will use this alsa device to output 5 channel plus LFE (5.1) surround "
"sound.\n"
"See the alsa documentation for information on alsa devices."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1411
+#: src/audio_out/audio_alsa_out.c:1408
msgid ""
"xine will use this alsa device to output undecoded digital surround sound. "
"This can be used be external surround decoders.\n"
"See the alsa documentation for information on alsa devices."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1431
+#: src/audio_out/audio_alsa_out.c:1428
#, c-format
msgid "snd_pcm_open() failed:%d:%s\n"
msgstr "snd_pcm_open() zlyhal:%d:%s\n"
-#: src/audio_out/audio_alsa_out.c:1433
+#: src/audio_out/audio_alsa_out.c:1430
#, c-format
msgid ">>> Check if another program already uses PCM <<<\n"
msgstr ">>> Skontrolujte Äi už iný program používa PCM <<<\n"
-#: src/audio_out/audio_alsa_out.c:1464 src/audio_out/audio_oss_out.c:929
+#: src/audio_out/audio_alsa_out.c:1461 src/audio_out/audio_oss_out.c:929
msgid "speaker arrangement"
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1465 src/audio_out/audio_oss_out.c:930
+#: src/audio_out/audio_alsa_out.c:1462 src/audio_out/audio_oss_out.c:930
msgid ""
"Select how your speakers are arranged, this determines which speakers xine "
"uses for sound output. The individual values are:\n"
@@ -189,88 +189,88 @@ msgid ""
"formats you want to play to your sound card's digital output."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1494
+#: src/audio_out/audio_alsa_out.c:1491
msgid "audio_alsa_out : supported modes are "
msgstr "audio_alsa_out : podporované módy sú "
-#: src/audio_out/audio_alsa_out.c:1497
+#: src/audio_out/audio_alsa_out.c:1494
msgid "8bit "
msgstr "8bit "
-#: src/audio_out/audio_alsa_out.c:1502
+#: src/audio_out/audio_alsa_out.c:1499
#, fuzzy
msgid "16bit "
msgstr "8bit "
-#: src/audio_out/audio_alsa_out.c:1506
+#: src/audio_out/audio_alsa_out.c:1503
#, fuzzy
msgid "24bit "
msgstr "8bit "
-#: src/audio_out/audio_alsa_out.c:1510
+#: src/audio_out/audio_alsa_out.c:1507
#, fuzzy
msgid "32bit "
msgstr "8bit "
-#: src/audio_out/audio_alsa_out.c:1521
+#: src/audio_out/audio_alsa_out.c:1518
msgid "mono "
msgstr "mono "
-#: src/audio_out/audio_alsa_out.c:1525
+#: src/audio_out/audio_alsa_out.c:1522
msgid "stereo "
msgstr "stereo "
-#: src/audio_out/audio_alsa_out.c:1530
+#: src/audio_out/audio_alsa_out.c:1527
msgid "4-channel "
msgstr "4-kanály "
-#: src/audio_out/audio_alsa_out.c:1533
+#: src/audio_out/audio_alsa_out.c:1530
msgid "(4-channel not enabled in xine config) "
msgstr "(4-kanály nepovolené v xine konfigu) "
-#: src/audio_out/audio_alsa_out.c:1538
+#: src/audio_out/audio_alsa_out.c:1535
msgid "4.1-channel "
msgstr "4.1-kanálov "
-#: src/audio_out/audio_alsa_out.c:1541
+#: src/audio_out/audio_alsa_out.c:1538
msgid "(4.1-channel not enabled in xine config) "
msgstr "(4.1-kanálov nepovolené v xine konfigu) "
-#: src/audio_out/audio_alsa_out.c:1546
+#: src/audio_out/audio_alsa_out.c:1543
msgid "5-channel "
msgstr "5-kanálov "
-#: src/audio_out/audio_alsa_out.c:1549
+#: src/audio_out/audio_alsa_out.c:1546
msgid "(5-channel not enabled in xine config) "
msgstr "(5-kanálov nepovolené v xine konfigu) "
-#: src/audio_out/audio_alsa_out.c:1554
+#: src/audio_out/audio_alsa_out.c:1551
msgid "5.1-channel "
msgstr "5.1-kanálov "
-#: src/audio_out/audio_alsa_out.c:1557
+#: src/audio_out/audio_alsa_out.c:1554
msgid "(5.1-channel not enabled in xine config) "
msgstr "(5.1-kanálov nepovolené v xine konfigu) "
-#: src/audio_out/audio_alsa_out.c:1580
+#: src/audio_out/audio_alsa_out.c:1577
msgid "a/52 and DTS pass-through\n"
msgstr "a/52 a DTS pass-through\n"
-#: src/audio_out/audio_alsa_out.c:1583
+#: src/audio_out/audio_alsa_out.c:1580
msgid "(a/52 and DTS pass-through not enabled in xine config)\n"
msgstr "(a/52 a DTS pass-through not enabled in xine config)\n"
-#: src/audio_out/audio_alsa_out.c:1590
+#: src/audio_out/audio_alsa_out.c:1587
msgid "alsa mixer device"
msgstr "alsa mixovacie zaridenie"
-#: src/audio_out/audio_alsa_out.c:1591
+#: src/audio_out/audio_alsa_out.c:1588
msgid ""
"xine will use this alsa mixer device to change the volume.\n"
"See the alsa documentation for information on alsa devices."
msgstr ""
-#: src/audio_out/audio_alsa_out.c:1665
+#: src/audio_out/audio_alsa_out.c:1662
msgid "xine audio output plugin using alsa-compliant audio devices/drivers"
msgstr ""
"výstupný xine audio plugin používa alsa-compliant audio zariadenia/ovládaÄe"
@@ -284,204 +284,204 @@ msgstr "výstupný xine audio plugin používa kde artsd"
msgid "xine output plugin for Coreaudio/Mac OS X"
msgstr "výstupný xine audio plugin pre win32 používa directx"
-#: src/audio_out/audio_directx2_out.c:166
+#: src/audio_out/audio_directx2_out.c:163
msgid "Error"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:173
+#: src/audio_out/audio_directx2_out.c:170
msgid "success"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:175
+#: src/audio_out/audio_directx2_out.c:172
msgid "access denied"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:177
+#: src/audio_out/audio_directx2_out.c:174
msgid "resource is already in use"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:178
+#: src/audio_out/audio_directx2_out.c:175
msgid "object was already initialized"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:179
+#: src/audio_out/audio_directx2_out.c:176
msgid "specified wave format is not supported"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:180
+#: src/audio_out/audio_directx2_out.c:177
msgid "memory buffer has been lost and must be restored"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:181
+#: src/audio_out/audio_directx2_out.c:178
#, fuzzy
msgid "requested buffer control is not available"
msgstr "požadované tlaÄidlo nedostupné\n"
-#: src/audio_out/audio_directx2_out.c:182
+#: src/audio_out/audio_directx2_out.c:179
msgid "undetermined error inside DirectSound subsystem"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:184
+#: src/audio_out/audio_directx2_out.c:181
msgid "DirectSound hardware device is unavailable"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:186
+#: src/audio_out/audio_directx2_out.c:183
msgid "function is not valid for the current state of the object"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:187
+#: src/audio_out/audio_directx2_out.c:184
msgid "invalid parameter was passed"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:188
+#: src/audio_out/audio_directx2_out.c:185
msgid "object doesn't support aggregation"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:189
+#: src/audio_out/audio_directx2_out.c:186
msgid "no sound driver available for use"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:190
+#: src/audio_out/audio_directx2_out.c:187
#, fuzzy
msgid "requested COM interface not available"
msgstr "požadované tlaÄidlo nedostupné\n"
-#: src/audio_out/audio_directx2_out.c:191
+#: src/audio_out/audio_directx2_out.c:188
msgid "another application has a higher priority level"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:192
+#: src/audio_out/audio_directx2_out.c:189
msgid "insufficient memory"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:193
+#: src/audio_out/audio_directx2_out.c:190
msgid "low priority level for this function"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:194
+#: src/audio_out/audio_directx2_out.c:191
msgid "DirectSound wasn't initialized"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:195
+#: src/audio_out/audio_directx2_out.c:192
msgid "function is not supported"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:196
+#: src/audio_out/audio_directx2_out.c:193
#, fuzzy
msgid "unknown error"
msgstr "Udalosť neznámeho typu: "
-#: src/audio_out/audio_directx2_out.c:206
+#: src/audio_out/audio_directx2_out.c:203
#, c-format
msgid "Unable to create direct sound object."
msgstr ""
-#: src/audio_out/audio_directx2_out.c:212
+#: src/audio_out/audio_directx2_out.c:209
#, c-format
msgid "Could not set direct sound cooperative level."
msgstr ""
-#: src/audio_out/audio_directx2_out.c:286
+#: src/audio_out/audio_directx2_out.c:283
msgid "Unable to create secondary direct sound buffer"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:310
+#: src/audio_out/audio_directx2_out.c:307
#, c-format
msgid "Unable to create buffer position events."
msgstr ""
-#: src/audio_out/audio_directx2_out.c:318
+#: src/audio_out/audio_directx2_out.c:315
msgid "Unable to get notification interface"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:323
+#: src/audio_out/audio_directx2_out.c:320
msgid "Unable to set notification positions"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:343
+#: src/audio_out/audio_directx2_out.c:340
msgid "Couldn't play sound buffer"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:355
+#: src/audio_out/audio_directx2_out.c:352
msgid "Couldn't stop sound buffer"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:368
+#: src/audio_out/audio_directx2_out.c:365
msgid "Can't get buffer position"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:382
+#: src/audio_out/audio_directx2_out.c:379
msgid "Can't set buffer position"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:414
+#: src/audio_out/audio_directx2_out.c:411
msgid "Can't set sound volume"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:432
+#: src/audio_out/audio_directx2_out.c:429
#, c-format
msgid ": buffer lost, tryig to restore\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:436
+#: src/audio_out/audio_directx2_out.c:433
msgid "Couldn't lock direct sound buffer"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:447
+#: src/audio_out/audio_directx2_out.c:444
msgid "Couldn't unlock direct sound buffer"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:544
+#: src/audio_out/audio_directx2_out.c:541
#, c-format
msgid "Unable to create primary direct sound buffer."
msgstr ""
-#: src/audio_out/audio_directx2_out.c:637
+#: src/audio_out/audio_directx2_out.c:634
#, c-format
msgid ": play cursor overran, flushing buffers\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:655
+#: src/audio_out/audio_directx2_out.c:652
#, c-format
msgid ": delayed by %ld msec\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:759
+#: src/audio_out/audio_directx2_out.c:756
#, fuzzy, c-format
msgid ": can't create pthread condition: %s\n"
msgstr "input_rtp: nemožno vytvoriť nové vlákno (%s)\n"
-#: src/audio_out/audio_directx2_out.c:763
+#: src/audio_out/audio_directx2_out.c:760
#, fuzzy, c-format
msgid ": can't create pthread mutex: %s\n"
msgstr "input_rtp: nemožno vytvoriť nové vlákno (%s)\n"
-#: src/audio_out/audio_directx2_out.c:770
+#: src/audio_out/audio_directx2_out.c:767
#, fuzzy, c-format
msgid ": can't create buffer pthread: %s\n"
msgstr "input_rtp: nemožno vytvoriť nové vlákno (%s)\n"
-#: src/audio_out/audio_directx2_out.c:877
+#: src/audio_out/audio_directx2_out.c:874
#, fuzzy, c-format
msgid ": can't destroy buffer pthread: %s\n"
msgstr "input_rtp: nemožno vytvoriť nové vlákno (%s)\n"
-#: src/audio_out/audio_directx2_out.c:884
+#: src/audio_out/audio_directx2_out.c:881
#, c-format
msgid ": can't destroy pthread condition: %s\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:887
+#: src/audio_out/audio_directx2_out.c:884
#, c-format
msgid ": can't destroy pthread mutex: %s\n"
msgstr ""
-#: src/audio_out/audio_directx2_out.c:947
+#: src/audio_out/audio_directx2_out.c:944
#, fuzzy, c-format
msgid ": unknown control command %d\n"
msgstr "iff-ilbm: neznáma kompresia: %d\n"
-#: src/audio_out/audio_directx2_out.c:1003
+#: src/audio_out/audio_directx2_out.c:1000
#, fuzzy
msgid "second xine audio output plugin using directx"
msgstr "výstupný xine audio plugin pre win32 používa directx"
@@ -911,7 +911,7 @@ msgstr "demux_snd: zlé parametre hlaviÄky\n"
msgid "demux_snd: unsupported audio type: %d\n"
msgstr "demux_snd: nepodporovaný typ zvuku: %d\n"
-#: src/demuxers/demux_tta.c:88
+#: src/demuxers/demux_tta.c:86
msgid "demux_tta: total frames count too high\n"
msgstr ""
@@ -931,7 +931,7 @@ msgstr "neznáma VOC kompresia typu (0x%02X); prosím nahlásiť tvorcom xine\n"
msgid "demux_wc3movie: SHOT chunk referenced invalid palette (%d >= %d)\n"
msgstr "demux_wc3movie: SHOT blok refercoval neznámu paletu (%d >= %d)\n"
-#: src/demuxers/demux_wc3movie.c:406
+#: src/demuxers/demux_wc3movie.c:404
#, c-format
msgid "demux_wc3movie: There was a problem while loading palette chunks\n"
msgstr "demux_wc3movie: Bol problém pri nahrávaní blokov palety\n"
@@ -1328,41 +1328,41 @@ msgid "video_out_dxr3: ERROR Reading overlay init file. Run autocal!\n"
msgstr ""
"video_out_dxr3: CHYBA Čítania init súboru prekrývania. Spustite autocal!\n"
-#: src/input/input_cdda.c:1621
+#: src/input/input_cdda.c:1608
#, fuzzy, c-format
msgid "%s: can't connect to %s:%d\n"
msgstr "rtsp: nemožno sa pripojiť k '%s'\n"
-#: src/input/input_cdda.c:1668
+#: src/input/input_cdda.c:1655
#, c-format
msgid "input_cdda: successfuly connected to cddb server '%s:%d'.\n"
msgstr "input_cdda: úspešne pripojenie na cddb server '%s:%d'.\n"
-#: src/input/input_cdda.c:1673
+#: src/input/input_cdda.c:1660
#, c-format
msgid "input_cdda: failed to connect to cddb server '%s:%d' (%s).\n"
msgstr "input_cdda: nemožno sa pripojiť na cddb server '%s:%d' (%s).\n"
-#: src/input/input_cdda.c:2707
+#: src/input/input_cdda.c:2690
msgid "CD Digital Audio (aka. CDDA)"
msgstr "CD Digital Audio (aka. CDDA)"
-#: src/input/input_cdda.c:2760
+#: src/input/input_cdda.c:2742
#, fuzzy
msgid "device used for CD audio"
msgstr "zariadenie pre cdda mechaniku"
-#: src/input/input_cdda.c:2761
+#: src/input/input_cdda.c:2743
msgid ""
"The path to the device, usually a CD or DVD drive, which you intend to use "
"for playing audio CDs."
msgstr ""
-#: src/input/input_cdda.c:2767
+#: src/input/input_cdda.c:2749
msgid "query CDDB"
msgstr ""
-#: src/input/input_cdda.c:2767
+#: src/input/input_cdda.c:2749
msgid ""
"Enables CDDB queries, which will give you convenient title and track names "
"for your audio CDs.\n"
@@ -1371,12 +1371,12 @@ msgid ""
"listening habits."
msgstr ""
-#: src/input/input_cdda.c:2775
+#: src/input/input_cdda.c:2757
#, fuzzy
msgid "CDDB server name"
msgstr "cddbp meno servera"
-#: src/input/input_cdda.c:2775
+#: src/input/input_cdda.c:2757
msgid ""
"The CDDB server used to retrieve the title and track information from.\n"
"This setting is security critical, because the sever will receive "
@@ -1384,33 +1384,20 @@ msgid ""
"malicious replies. Be sure to enter a server you can trust."
msgstr ""
-#: src/input/input_cdda.c:2783
+#: src/input/input_cdda.c:2765
#, fuzzy
msgid "CDDB server port"
msgstr "cddbp port servra"
-#: src/input/input_cdda.c:2783
+#: src/input/input_cdda.c:2765
msgid "The server port used to retrieve the title and track information from."
msgstr ""
-#: src/input/input_cdda.c:2789
-#, fuzzy
-msgid "CDDB cache directory"
-msgstr "cddbp cache adresár"
-
-#: src/input/input_cdda.c:2789
-msgid ""
-"The replies from the CDDB server will be cached in this directory.\n"
-"This setting is security critical, because files with uncontrollable names "
-"will be created in this directory. Be sure to use a dedicated directory not "
-"used for anything but CDDB caching."
-msgstr ""
-
-#: src/input/input_cdda.c:2797
+#: src/input/input_cdda.c:2771
msgid "slow down disc drive to this speed factor"
msgstr ""
-#: src/input/input_cdda.c:2798
+#: src/input/input_cdda.c:2772
msgid ""
"Since some CD or DVD drives make some really loud noises because of the fast "
"disc rotation, xine will try to slow them down. With standard CD or DVD "
@@ -1419,119 +1406,124 @@ msgid ""
"A value of zero here will disable the slowdown."
msgstr ""
-#: src/input/input_dvb.c:881
-#, c-format
-msgid "input_dvb: failed to open dvb channel file '%s'\n"
+#: src/input/input_dvb.c:899
+#, fuzzy, c-format
+msgid "input_dvb: failed to open dvb channel file '%s': %s\n"
+msgstr "input_dvb: zlyhalo otvorenie súboru dvb kanála '%s'\n"
+
+#: src/input/input_dvb.c:905
+#, fuzzy, c-format
+msgid "input_dvb: dvb channel file '%s' is not a plain file\n"
msgstr "input_dvb: zlyhalo otvorenie súboru dvb kanála '%s'\n"
-#: src/input/input_dvb.c:2082 src/input/input_dvb.c:2910
+#: src/input/input_dvb.c:2115 src/input/input_dvb.c:2943
msgid "input_dvb: tuner_set_channel failed\n"
msgstr "input_dvb: tuner_set_channel zlyhal\n"
-#: src/input/input_dvb.c:2710
+#: src/input/input_dvb.c:2743
msgid "input_dvb: cannot open dvb device\n"
msgstr "input_dvb: nemožno otvoriť dvb zariadenie\n"
-#: src/input/input_dvb.c:2734
+#: src/input/input_dvb.c:2767
#, c-format
msgid "input_dvb: channel %d out of range, defaulting to 0\n"
msgstr ""
-#: src/input/input_dvb.c:2745
+#: src/input/input_dvb.c:2778
#, fuzzy, c-format
msgid "input_dvb: searching for channel %s\n"
msgstr "input_dvb: zlyhalo otvorenie súboru dvb kanála '%s'\n"
-#: src/input/input_dvb.c:2768
+#: src/input/input_dvb.c:2801
#, c-format
msgid "input_dvb: exact match for %s not found: trying partial matches\n"
msgstr ""
-#: src/input/input_dvb.c:2775
+#: src/input/input_dvb.c:2808
#, fuzzy, c-format
msgid "input_dvb: found matching channel %s\n"
msgstr "input_dvb: zlyhalo otvorenie súboru dvb kanála '%s'\n"
-#: src/input/input_dvb.c:2788
+#: src/input/input_dvb.c:2821
#, c-format
msgid "input_dvb: channel %s not found in channels.conf, defaulting.\n"
msgstr ""
-#: src/input/input_dvb.c:2794
+#: src/input/input_dvb.c:2827
msgid ""
"input_dvb: invalid channel specification, defaulting to last viewed "
"channel.\n"
msgstr ""
-#: src/input/input_dvb.c:2800
+#: src/input/input_dvb.c:2833
msgid "input_dvb: invalid channel specification, defaulting to channel 0\n"
msgstr ""
-#: src/input/input_dvb.c:2812
+#: src/input/input_dvb.c:2845
msgid ""
"input_dvb: dvbs mrl specified but the tuner doesn't appear to be QPSK (DVB-"
"S)\n"
msgstr ""
-#: src/input/input_dvb.c:2832
+#: src/input/input_dvb.c:2865
msgid ""
"input_dvb: dvbt mrl specified but the tuner doesn't appear to be OFDM (DVB-"
"T)\n"
msgstr ""
-#: src/input/input_dvb.c:2855 src/input/input_dvb.c:2881
+#: src/input/input_dvb.c:2888 src/input/input_dvb.c:2914
msgid ""
"input_dvb: dvbc mrl specified but the tuner doesn't appear to be QAM (DVB-"
"C)\n"
msgstr ""
-#: src/input/input_dvb.c:2916
+#: src/input/input_dvb.c:2949
#, c-format
msgid "input_dvb: cannot open dvr device '%s'\n"
msgstr "input_dvb: nemožno otvoriť dvr zariadenie '%s'\n"
-#: src/input/input_dvb.c:2938
+#: src/input/input_dvb.c:2971
#, fuzzy
msgid "input_dvb: cannot create EPG updater thread\n"
msgstr "input_rtp: nemožno vytvoriť nové vlákno (%s)\n"
-#: src/input/input_dvb.c:3000
+#: src/input/input_dvb.c:3033
msgid "use DVB 'center cutout' (zoom)"
msgstr ""
-#: src/input/input_dvb.c:3001
+#: src/input/input_dvb.c:3034
msgid ""
"This will allow fullscreen playback of 4:3 content transmitted in a 16:9 "
"frame."
msgstr ""
-#: src/input/input_dvb.c:3094
+#: src/input/input_dvb.c:3127
msgid "DVB (Digital TV) input plugin"
msgstr "DVB (Digital TV) vstupný modul"
-#: src/input/input_dvb.c:3242
+#: src/input/input_dvb.c:3244
msgid "Remember last DVB channel watched"
msgstr ""
-#: src/input/input_dvb.c:3243
+#: src/input/input_dvb.c:3245
msgid ""
"On autoplay, xine will remember and switch to the channel indicated in media."
"dvb.last_channel. "
msgstr ""
-#: src/input/input_dvb.c:3250
+#: src/input/input_dvb.c:3252
msgid "Last DVB channel viewed"
msgstr ""
-#: src/input/input_dvb.c:3251
+#: src/input/input_dvb.c:3253
msgid "If enabled xine will remember and switch to this channel. "
msgstr ""
-#: src/input/input_dvb.c:3257
+#: src/input/input_dvb.c:3259
msgid "Number of dvb card to use."
msgstr ""
-#: src/input/input_dvb.c:3258
+#: src/input/input_dvb.c:3260
msgid ""
"Leave this at zero unless you really have more than 1 card in your system."
msgstr ""
@@ -1560,11 +1552,11 @@ msgid ""
"playing DVDs."
msgstr ""
-#: src/input/input_dvd.c:1800
+#: src/input/input_dvd.c:1799
msgid "raw device set up for DVD access"
msgstr ""
-#: src/input/input_dvd.c:1801
+#: src/input/input_dvd.c:1800
msgid ""
"If this points to a raw device connected to your DVD device, xine will use "
"the raw device for playback. This has the advantage of being slightly faster "
@@ -1575,70 +1567,56 @@ msgid ""
"See the documentation on raw device setup (man raw) for further information."
msgstr ""
-#: src/input/input_dvd.c:1814
+#: src/input/input_dvd.c:1813
msgid "CSS decryption method"
msgstr ""
-#: src/input/input_dvd.c:1815
+#: src/input/input_dvd.c:1814
msgid ""
"Selects the decryption method libdvdcss will use to descramble copy "
"protected DVDs. Try the various methods, if you have problems playing "
"scrambled DVDs."
msgstr ""
-#: src/input/input_dvd.c:1823
-#, fuzzy
-msgid "path to the title key cache"
-msgstr "cesta k video zariadeniu v4l"
-
-#: src/input/input_dvd.c:1824
-msgid ""
-"Since cracking the copy protection of scrambled DVDs can be quite time "
-"consuming, libdvdcss will cache the cracked keys in this directory.\n"
-"This setting is security critical, because files with uncontrollable names "
-"will be created in this directory. Be sure to use a dedicated directory not "
-"used for anything but DVD key caching."
-msgstr ""
-
-#: src/input/input_dvd.c:1846
+#: src/input/input_dvd.c:1829
msgid "region the DVD player claims to be in (1 to 8)"
msgstr ""
-#: src/input/input_dvd.c:1847
+#: src/input/input_dvd.c:1830
msgid ""
"This only needs to be changed if your DVD jumps to a screen complaining "
"about a wrong region code. It has nothing to do with the region code set in "
"DVD drives, this is purely software."
msgstr ""
-#: src/input/input_dvd.c:1853
+#: src/input/input_dvd.c:1836
msgid "default language for DVD playback"
msgstr ""
-#: src/input/input_dvd.c:1854
+#: src/input/input_dvd.c:1837
msgid ""
"xine tries to use this language as a default for DVD playback. As far as the "
"DVD supports it, menus and audio tracks will be presented in this language.\n"
"The value must be a two character ISO639 language code."
msgstr ""
-#: src/input/input_dvd.c:1860
+#: src/input/input_dvd.c:1843
#, fuzzy
msgid "read-ahead caching"
msgstr "Použijeme keÅ¡ovanie predÄítaním?"
-#: src/input/input_dvd.c:1861
+#: src/input/input_dvd.c:1844
msgid ""
"xine can use a read ahead cache for DVD drive access.\n"
"This may lead to jerky playback on slow drives, but it improves the impact "
"of the DVD layer change on faster drives."
msgstr ""
-#: src/input/input_dvd.c:1867
+#: src/input/input_dvd.c:1850
msgid "unit for the skip action"
msgstr ""
-#: src/input/input_dvd.c:1868
+#: src/input/input_dvd.c:1851
msgid ""
"You can configure the behaviour when issuing a skip command (using the skip "
"buttons for example). The individual values mean:\n"
@@ -1657,11 +1635,11 @@ msgid ""
"features on the DVD"
msgstr ""
-#: src/input/input_dvd.c:1883
+#: src/input/input_dvd.c:1866
msgid "unit for seeking"
msgstr ""
-#: src/input/input_dvd.c:1884
+#: src/input/input_dvd.c:1867
msgid ""
"You can configure the domain spanned by the seek slider. The individual "
"values mean:\n"
@@ -1675,11 +1653,11 @@ msgid ""
"chapter of the current feature"
msgstr ""
-#: src/input/input_dvd.c:1895
+#: src/input/input_dvd.c:1878
msgid "play mode when title/chapter is given"
msgstr ""
-#: src/input/input_dvd.c:1896
+#: src/input/input_dvd.c:1879
msgid ""
"You can configure the behaviour when playing a dvd from a given title/"
"chapter (eg. using MRL 'dvd:/1.2'). The individual values mean:\n"
@@ -2409,7 +2387,7 @@ msgid ""
"2048: Debugging from VCDINFO\n"
msgstr ""
-#: src/liba52/xine_a52_decoder.c:742 src/libdts/xine_dts_decoder.c:546
+#: src/liba52/xine_a52_decoder.c:742 src/libxineadec/xine_dts_decoder.c:524
msgid "HELP! a mono-only audio driver?!\n"
msgstr "POMOC! iba mono audio ovládaÄ?!\n"
@@ -2466,63 +2444,63 @@ msgstr "libfaad: libfaad faacDecInit2() zlyhal.\n"
msgid "libfaad: libfaad NeAACDecInit failed.\n"
msgstr "libfaad: libfaad faacDecInit() zlyhal.\n"
-#: src/libffmpeg/ff_audio_decoder.c:120
+#: src/libffmpeg/ff_audio_decoder.c:122
#, c-format
msgid "ffmpeg_audio_dec: increasing buffer to %d to avoid overflow.\n"
msgstr "ffmpeg_audio_dec: zväÄÅ¡ujem buffer na %d aby sa prediÅ¡lo preteÄeniu.\n"
-#: src/libffmpeg/ff_audio_decoder.c:164
+#: src/libffmpeg/ff_audio_decoder.c:166
#, c-format
msgid "ffmpeg_audio_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"
msgstr "ffmpeg_audio_dec: nenašiel ffmpeg dekóder pre buf typu 0x%X\n"
-#: src/libffmpeg/ff_audio_decoder.c:256
+#: src/libffmpeg/ff_audio_decoder.c:258
#, fuzzy
msgid "ffmpeg_audio_dec: trying to open null codec\n"
msgstr "ffmpeg_audio_dec: nemôžem otvoriť dekóder\n"
-#: src/libffmpeg/ff_audio_decoder.c:265
+#: src/libffmpeg/ff_audio_decoder.c:267
msgid "ffmpeg_audio_dec: couldn't open decoder\n"
msgstr "ffmpeg_audio_dec: nemôžem otvoriť dekóder\n"
-#: src/libffmpeg/ff_dvaudio_decoder.c:286
+#: src/libffmpeg/ff_dvaudio_decoder.c:280
#, fuzzy, c-format
msgid "dvaudio: increasing buffer to %d to avoid overflow.\n"
msgstr "ffmpeg_audio_dec: zväÄÅ¡ujem buffer na %d aby sa prediÅ¡lo preteÄeniu.\n"
-#: src/libffmpeg/ff_video_decoder.c:157
+#: src/libffmpeg/ff_video_decoder.c:155
msgid "ffmpeg_video_dec: unsupported frame format, DR1 disabled.\n"
msgstr "ffmpeg_video_dec: nepodporovaný formát snímku, DR1 nepovolený.\n"
-#: src/libffmpeg/ff_video_decoder.c:175
+#: src/libffmpeg/ff_video_decoder.c:173
#, fuzzy
msgid "ffmpeg_video_dec: unsupported frame dimensions, DR1 disabled.\n"
msgstr "ffmpeg_video_dec: nepodporovaný formát snímku, DR1 nepovolený.\n"
-#: src/libffmpeg/ff_video_decoder.c:335
+#: src/libffmpeg/ff_video_decoder.c:333
#, c-format
msgid "ffmpeg_video_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"
msgstr "ffmpeg_video_dec: nenájdený ffmpeg dekóder pre buf typu 0x%X\n"
-#: src/libffmpeg/ff_video_decoder.c:364
+#: src/libffmpeg/ff_video_decoder.c:362
msgid "ffmpeg_video_dec: couldn't open decoder\n"
msgstr "ffmpeg_video_dec: nedá sa otvoriť dekóder\n"
-#: src/libffmpeg/ff_video_decoder.c:399
+#: src/libffmpeg/ff_video_decoder.c:397
msgid "ffmpeg_video_dec: direct rendering enabled\n"
msgstr "ffmpeg_video_dec: priame vykreslovanie zapnuté\n"
-#: src/libffmpeg/ff_video_decoder.c:818
+#: src/libffmpeg/ff_video_decoder.c:816
#, c-format
msgid "ffmpeg_video_dec: increasing buffer to %d to avoid overflow.\n"
msgstr "ffmpeg_video_dec: zväÄÅ¡ujem buffer na %d aby sa prediÅ¡lo preteÄeniu.\n"
-#: src/libffmpeg/ff_video_decoder.c:1516
+#: src/libffmpeg/ff_video_decoder.c:1514
#, fuzzy
msgid "MPEG-4 postprocessing quality"
msgstr "kvalita ffmpeg mpeg-4 postspracovania"
-#: src/libffmpeg/ff_video_decoder.c:1517
+#: src/libffmpeg/ff_video_decoder.c:1515
msgid ""
"You can adjust the amount of post processing applied to MPEG-4 video.\n"
"Higher values result in better quality, but need more CPU. Lower values may "
@@ -2531,62 +2509,62 @@ msgid ""
"much."
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:167
+#: src/libffmpeg/ffmpeg_encoder.c:163
#, fuzzy
msgid "libavcodec mpeg output bitrate (kbit/s)"
msgstr "Dxr3enc: výstupná rýchlosť libavcodec mpeg (kbit/s)"
-#: src/libffmpeg/ffmpeg_encoder.c:168
+#: src/libffmpeg/ffmpeg_encoder.c:164
msgid ""
"The bitrate the libavcodec mpeg encoder should use for DXR3's encoding mode. "
"Higher values will increase quality and CPU usage.\n"
"This setting is only considered, when constant quality mode is disabled."
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:175
+#: src/libffmpeg/ffmpeg_encoder.c:171
msgid "constant quality mode"
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:176
+#: src/libffmpeg/ffmpeg_encoder.c:172
msgid ""
"When enabled, libavcodec will use a constant quality mode by dynamically "
"compressing the images based on their complexity. When disabled, libavcodec "
"will use constant bitrate mode."
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:183
+#: src/libffmpeg/ffmpeg_encoder.c:179
#, fuzzy
msgid "minimum compression"
msgstr "iff-ilbm: neznáma kompresia: %d\n"
-#: src/libffmpeg/ffmpeg_encoder.c:184
+#: src/libffmpeg/ffmpeg_encoder.c:180
msgid "The minimum compression to apply to an image in constant quality mode."
msgstr ""
-#: src/libffmpeg/ffmpeg_encoder.c:189
+#: src/libffmpeg/ffmpeg_encoder.c:185
#, fuzzy
msgid "maximum quantizer"
msgstr "Dxr3enc: Maximálny kvantizér"
-#: src/libffmpeg/ffmpeg_encoder.c:190
+#: src/libffmpeg/ffmpeg_encoder.c:186
msgid "The maximum compression to apply to an image in constant quality mode."
msgstr ""
-#: src/libmusepack/xine_musepack_decoder.c:241
+#: src/libxineadec/xine_musepack_decoder.c:249
#, c-format
msgid "libmusepack: mpc_streaminfo_read failed: %d\n"
msgstr ""
-#: src/libmusepack/xine_musepack_decoder.c:315
+#: src/libxineadec/xine_musepack_decoder.c:323
msgid "libmusepack: data after last frame ignored\n"
msgstr ""
-#: src/libmusepack/xine_musepack_decoder.c:326
+#: src/libxineadec/xine_musepack_decoder.c:334
msgid "libmusepack: mpc_decoder_initialise failed\n"
msgstr ""
-#: src/libmusepack/xine_musepack_decoder.c:346
-#: src/libmusepack/xine_musepack_decoder.c:361
+#: src/libxineadec/xine_musepack_decoder.c:354
+#: src/libxineadec/xine_musepack_decoder.c:369
#, c-format
msgid "libmusepack: mpc_decoder_decode failed: %d\n"
msgstr ""
@@ -3467,7 +3445,7 @@ msgid "Select the video output layer by its id."
msgstr ""
#: src/video_out/video_out_directfb.c:1804
-#: src/video_out/video_out_directfb.c:2013
+#: src/video_out/video_out_directfb.c:2014
#, fuzzy, c-format
msgid "video_out_directfb: using display layer #%d.\n"
msgstr "video_out_vidix: používam ovládaÄ: %s od %s\n"
@@ -3477,11 +3455,11 @@ msgstr "video_out_vidix: používam ovládaÄ: %s od %s\n"
msgid "xine video output plugin using DirectFB."
msgstr "výstupný modul xine s použitím DirectFB knižnice."
-#: src/video_out/video_out_directfb.c:2006
+#: src/video_out/video_out_directfb.c:2007
msgid "video_out_directfb: no usable display layer was found!\n"
msgstr ""
-#: src/video_out/video_out_directfb.c:2095
+#: src/video_out/video_out_directfb.c:2096
#, fuzzy
msgid "xine video output plugin using DirectFB under XDirectFB."
msgstr "výstupný modul xine s použitím DirectFB knižnice."
@@ -3490,7 +3468,7 @@ msgstr "výstupný modul xine s použitím DirectFB knižnice."
msgid "xine video output plugin for win32 using directx"
msgstr "výstupný video modul pre win32 použitím directx"
-#: src/video_out/video_out_fb.c:792
+#: src/video_out/video_out_fb.c:780
#, c-format
msgid ""
"video_out_fb: only packed truecolor/directcolor is supported (%d).\n"
@@ -3499,12 +3477,12 @@ msgstr ""
"video_out_fb: sú podporované iba pravé farby truecolor/directcolor (%d).\n"
" Zkontrolujte 'fbset -i' alebo skúste 'fbset -depth 16'.\n"
-#: src/video_out/video_out_fb.c:852 src/video_out/video_out_vidix.c:1239
+#: src/video_out/video_out_fb.c:840 src/video_out/video_out_vidix.c:1239
#, fuzzy
msgid "framebuffer device name"
msgstr "zariadenie framebufferu"
-#: src/video_out/video_out_fb.c:853 src/video_out/video_out_vidix.c:1240
+#: src/video_out/video_out_fb.c:841 src/video_out/video_out_vidix.c:1240
msgid ""
"Specifies the file name for the framebuffer device to be used.\n"
"This setting is security critical, because when changed to a different file, "
@@ -3512,20 +3490,20 @@ msgid ""
"careful that the value you enter really is a proper framebuffer device."
msgstr ""
-#: src/video_out/video_out_fb.c:927
-msgid "video_out_fb: Your video mode was not recognized, sorry.\n"
+#: src/video_out/video_out_fb.c:915
+#, fuzzy, c-format
+msgid "%s: Your video mode was not recognized, sorry.\n"
msgstr "video_out_fb: Váš video mód nebol rozpoznaný, prepáÄte.\n"
-#: src/video_out/video_out_fb.c:984
-#, c-format
-msgid "video_out_fb: %d video RAM buffers are available.\n"
+#: src/video_out/video_out_fb.c:972
+#, fuzzy, c-format
+msgid "%s: %d video RAM buffers are available.\n"
msgstr "video_out_fb: %d video RAM buffere dostupné.\n"
-#: src/video_out/video_out_fb.c:990
-#, c-format
+#: src/video_out/video_out_fb.c:978
+#, fuzzy, c-format
msgid ""
-"WARNING: video_out_fb: Zero copy buffers are DISABLED because only %d "
-"buffers\n"
+"WARNING: %s: Zero copy buffers are DISABLED because only %d buffers\n"
" are available which is less than the recommended %d buffers. Lowering\n"
" the frame buffer resolution might help.\n"
msgstr ""
@@ -3533,27 +3511,30 @@ msgstr ""
" k dispozícii, Äo je menej neždoporuÄených %d buffrov. Zníženie\n"
" rozlíšenia bufferu snímkov môže pomôcť.\n"
-#: src/video_out/video_out_fb.c:1001
+#: src/video_out/video_out_fb.c:989
+#, fuzzy, c-format
msgid ""
-"WARNING: video_out_fb: Zero copy buffers are DISABLED because kernel driver\n"
+"WARNING: %s: Zero copy buffers are DISABLED because kernel driver\n"
" do not support screen panning (used for frame flips).\n"
msgstr ""
"WARNING: video_out_fb: Buffere s nulami sú ZAKÃZANÉ lebo lebo kernel "
"ovládaÄ\n"
" nepodporuje screen panning (používaný pre prepínanie snímkov).\n"
-#: src/video_out/video_out_fb.c:1070
-#, c-format
+#: src/video_out/video_out_fb.c:1058
+#, fuzzy, c-format
msgid ""
-"WARNING: video_out_fb: current display depth is %d. For better performance\n"
+"WARNING: %s: current display depth is %d. For better performance\n"
" a depth of 16 bpp is recommended!\n"
"\n"
msgstr ""
-"WARNING: video_out_fb: terajšia hĺbka zobrazenia je %d. Pre lepší výkon\n"
-" hĺbka 16 bit/bod je doporuÄená!\n"
+"\n"
+"\n"
+"VAROVANIE: aktuálna hĺbka zobrazenia je %d. Pre lepší výkon\n"
+"je doporuÄená hĺbka 16 bit/bod!\n"
"\n"
-#: src/video_out/video_out_fb.c:1101
+#: src/video_out/video_out_fb.c:1090
msgid "Xine video output plugin using the Linux frame buffer device"
msgstr ""
"výstupný xine video modul s použitím Linux kernelového frame buffer "
@@ -3607,8 +3588,8 @@ msgid ""
msgstr ""
#: src/video_out/video_out_opengl.c:1918 src/video_out/video_out_vidix.c:1015
-#: src/video_out/video_out_xcbxv.c:1472 src/video_out/video_out_xv.c:1486
-#: src/video_out/video_out_xvmc.c:1461 src/video_out/video_out_xxmc.c:2468
+#: src/video_out/video_out_xcbxv.c:1476 src/video_out/video_out_xv.c:1489
+#: src/video_out/video_out_xvmc.c:1461 src/video_out/video_out_xxmc.c:2465
msgid "enable double buffering"
msgstr ""
@@ -3691,9 +3672,9 @@ msgstr ""
msgid "video_out_pgx64: Error: ioctl failed (FBIOGATTR)\n"
msgstr "video_out_pgx64: Chyba: nedostatoÄná veľkosÅ¥ video pamäte\n"
-#: src/video_out/video_out_pgx64.c:1464 src/video_out/video_out_xcbxv.c:1439
-#: src/video_out/video_out_xv.c:1453 src/video_out/video_out_xvmc.c:1446
-#: src/video_out/video_out_xxmc.c:2435
+#: src/video_out/video_out_pgx64.c:1464 src/video_out/video_out_xcbxv.c:1443
+#: src/video_out/video_out_xv.c:1456 src/video_out/video_out_xvmc.c:1446
+#: src/video_out/video_out_xxmc.c:2432
#, fuzzy
msgid "video overlay colour key"
msgstr "Dx3: hodnota kľúÄovej farby prekrývánia"
@@ -3852,9 +3833,9 @@ msgstr ""
msgid "The intensity of the blue colour components."
msgstr ""
-#: src/video_out/video_out_vidix.c:1016 src/video_out/video_out_xcbxv.c:1473
-#: src/video_out/video_out_xv.c:1487 src/video_out/video_out_xvmc.c:1462
-#: src/video_out/video_out_xxmc.c:2469
+#: src/video_out/video_out_vidix.c:1016 src/video_out/video_out_xcbxv.c:1477
+#: src/video_out/video_out_xv.c:1490 src/video_out/video_out_xvmc.c:1462
+#: src/video_out/video_out_xxmc.c:2466
msgid ""
"Double buffering will synchronize the update of the video image to the "
"repainting of the entire screen (\"vertical retrace\"). This eliminates "
@@ -3888,9 +3869,9 @@ msgid "video overlay colour key red component"
msgstr "rozsah kľúÄovej farby prekrývánia"
#: src/video_out/video_out_vidix.c:1159 src/video_out/video_out_vidix.c:1166
-#: src/video_out/video_out_vidix.c:1173 src/video_out/video_out_xcbxv.c:1440
-#: src/video_out/video_out_xv.c:1454 src/video_out/video_out_xvmc.c:1447
-#: src/video_out/video_out_xxmc.c:2436
+#: src/video_out/video_out_vidix.c:1173 src/video_out/video_out_xcbxv.c:1444
+#: src/video_out/video_out_xv.c:1457 src/video_out/video_out_xvmc.c:1447
+#: src/video_out/video_out_xxmc.c:2433
msgid ""
"The colour key is used to tell the graphics card where to overlay the video "
"image. Try different values, if you experience windows becoming transparent."
@@ -3914,35 +3895,40 @@ msgstr "výstupný video modul xine použitím libvidix pre x11"
msgid "xine video output plugin using libvidix for linux frame buffer"
msgstr "výstupný video modul xine použitím libvidix pre linux frame buffer"
-#: src/video_out/video_out_xcbshm.c:157
-#, fuzzy, c-format
-msgid ""
-"video_out_xcbshm: %s: allocating image\n"
-"video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbshm.c:157 src/video_out/video_out_xshm.c:219
+#, c-format
+msgid "%s: %s: allocating image\n"
msgstr ""
-"video_out_xshm: %s: alokácia obrazu\n"
-"video_out_xshm: => nepoužívam rozšírenie MIT Shared Memory.\n"
-#: src/video_out/video_out_xcbshm.c:166
-#, fuzzy
-msgid ""
-"video_out_xcbshm: shared memory error (address error) when allocating "
-"image \n"
-"video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbshm.c:159 src/video_out/video_out_xcbshm.c:169
+#: src/video_out/video_out_xcbshm.c:181 src/video_out/video_out_xcbxv.c:272
+#: src/video_out/video_out_xcbxv.c:282 src/video_out/video_out_xcbxv.c:292
+#: src/video_out/video_out_xcbxv.c:304 src/video_out/video_out_xshm.c:204
+#: src/video_out/video_out_xshm.c:221 src/video_out/video_out_xshm.c:232
+#: src/video_out/video_out_xshm.c:251 src/video_out/video_out_xv.c:296
+#: src/video_out/video_out_xv.c:307 src/video_out/video_out_xv.c:316
+#: src/video_out/video_out_xv.c:352 src/video_out/video_out_xxmc.c:648
+#: src/video_out/video_out_xxmc.c:659 src/video_out/video_out_xxmc.c:668
+#: src/video_out/video_out_xxmc.c:704
+#, fuzzy, c-format
+msgid "%s: => not using MIT Shared Memory extension.\n"
+msgstr "výstupný video xine modul použitím rozšírenia zdielanej pamäte MIT X"
+
+#: src/video_out/video_out_xcbshm.c:167 src/video_out/video_out_xshm.c:230
+#, fuzzy, c-format
+msgid "%s: shared memory error (address error) when allocating image \n"
msgstr ""
"video_out_xshm: chyba dielanej pamäte (chyba adresy) pri alokácii obrazu\n"
"video_out_xshm: => nepoužívam rozšírenie MIT Shared Memory.\n"
-#: src/video_out/video_out_xcbshm.c:177
-#, fuzzy
-msgid ""
-"video_out_xcbshm: x11 error during shared memory XImage creation\n"
-"video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbshm.c:179 src/video_out/video_out_xcbxv.c:302
+#: src/video_out/video_out_xshm.c:249 src/video_out/video_out_xv.c:350
+#: src/video_out/video_out_xxmc.c:702
+#, c-format
+msgid "%s: x11 error during shared memory XImage creation\n"
msgstr ""
-"video_out_xshm: x11 chyba pri vytváraní zdielanej pamäte XImage\n"
-"video_out_xshm: => nepoužívam rozšírenie MIT Shared Memory.\n"
-#: src/video_out/video_out_xcbshm.c:1100 src/video_out/video_out_xshm.c:1157
+#: src/video_out/video_out_xcbshm.c:1103 src/video_out/video_out_xshm.c:1161
#, c-format
msgid ""
"\n"
@@ -3957,94 +3943,84 @@ msgstr ""
"je doporuÄená hĺbka 16 bit/bod!\n"
"\n"
-#: src/video_out/video_out_xcbshm.c:1113
-#, fuzzy
-msgid "video_out_xcbshm: MIT shared memory extension not present on display.\n"
+#: src/video_out/video_out_xcbshm.c:1116 src/video_out/video_out_xshm.c:1174
+#, fuzzy, c-format
+msgid "%s: MIT shared memory extension not present on display.\n"
msgstr ""
"video_out_xshm: rozšírenie zdielanej pamäte MIT neprítomné na obrazovke.\n"
-#: src/video_out/video_out_xcbshm.c:1212
-#, fuzzy
-msgid "video_out_xcbshm: your video mode was not recognized, sorry :-(\n"
-msgstr "video_out_xshm: váš video mód nebol rozoznaný, prepáÄte :-(\n"
+#: src/video_out/video_out_xcbshm.c:1215 src/video_out/video_out_xshm.c:1258
+#, fuzzy, c-format
+msgid "%s: your video mode was not recognized, sorry :-(\n"
+msgstr "video_out_fb: Váš video mód nebol rozpoznaný, prepáÄte.\n"
-#: src/video_out/video_out_xcbshm.c:1242 src/video_out/video_out_xshm.c:1303
+#: src/video_out/video_out_xcbshm.c:1245 src/video_out/video_out_xshm.c:1307
msgid "xine video output plugin using the MIT X shared memory extension"
msgstr "výstupný video xine modul použitím rozšírenia zdielanej pamäte MIT X"
-#: src/video_out/video_out_xcbxv.c:272
-#, fuzzy
-msgid ""
-"video_out_xcbxv: XvShmCreateImage returned a zero size\n"
-"video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbxv.c:270 src/video_out/video_out_xv.c:305
+#: src/video_out/video_out_xxmc.c:657
+#, c-format
+msgid "%s: XvShmCreateImage returned a zero size\n"
msgstr ""
-"video_out_xv: XvShmCreateImage vrátila nulovú veľkosť\n"
-"video_out_xv: => nepoužívam rozšírenie MIT Shared Memory.\n"
-#: src/video_out/video_out_xcbxv.c:281
-#, fuzzy, c-format
-msgid ""
-"video_out_xcbxv: shared memory error in shmget: %s\n"
-"video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbxv.c:280 src/video_out/video_out_xv.c:314
+#: src/video_out/video_out_xxmc.c:666
+#, c-format
+msgid "%s: shared memory error in shmget: %s\n"
msgstr ""
-"video_out_xv: chyba zdielanej pamäte v shmget: %s\n"
-"video_out_xv: => nepoužívam rozšírenie MIT Shared Memory.\n"
-#: src/video_out/video_out_xcbxv.c:300
-#, fuzzy
-msgid ""
-"video_out_xcbxv: x11 error during shared memory XImage creation\n"
-"video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#: src/video_out/video_out_xcbxv.c:290
+#, c-format
+msgid "%s: shared memory error (address error)\n"
msgstr ""
-"video_out_xv: x11 chyba pri vytváraní zdielanej pamäte XImage\n"
-"video_out_xv: => nepoužívam rozšírenie MIT Shared Memory.\n"
-#: src/video_out/video_out_xcbxv.c:1291
-#, fuzzy
-msgid "video_out_xcbxv: Xv extension not present.\n"
+#: src/video_out/video_out_xcbxv.c:1294 src/video_out/video_out_xv.c:1301
+#: src/video_out/video_out_xxmc.c:2283
+#, fuzzy, c-format
+msgid "%s: Xv extension not present.\n"
msgstr "video_out_xv: Xv rozšírenie neprítomné.\n"
-#: src/video_out/video_out_xcbxv.c:1333
-#, fuzzy
+#: src/video_out/video_out_xcbxv.c:1336 src/video_out/video_out_xv.c:1338
+#: src/video_out/video_out_xxmc.c:2320
+#, fuzzy, c-format
msgid ""
-"video_out_xcbxv: Xv extension is present but I couldn't find a usable yuv12 "
-"port.\n"
-" Looks like your graphics hardware driver doesn't support "
-"Xv?!\n"
+"%s: Xv extension is present but I couldn't find a usable yuv12 port.\n"
+"\tLooks like your graphics hardware driver doesn't support Xv?!\n"
msgstr ""
"video_out_xv: rozšírenie Xv je prítomné, ale nenašiel som použiteľný yuv12 "
"port.\n"
" Vyzerá to tak, že vaša grafická karta nepodoruje Xv?!\n"
-#: src/video_out/video_out_xcbxv.c:1341
+#: src/video_out/video_out_xcbxv.c:1345
#, fuzzy, c-format
msgid ""
-"video_out_xcbxv: using Xv port %d from adaptor %s for hardware colorspace "
-"conversion and scaling.\n"
+"%s: using Xv port %d from adaptor %s for hardware colorspace conversion and "
+"scaling.\n"
msgstr ""
"video_out_xv: používam Xv port %ld z adaptéru %s pre hardvérovú konverziu "
"farebného priestoru a škálovania.\n"
-#: src/video_out/video_out_xcbxv.c:1448 src/video_out/video_out_xv.c:1462
-#: src/video_out/video_out_xvmc.c:1455 src/video_out/video_out_xxmc.c:2444
+#: src/video_out/video_out_xcbxv.c:1452 src/video_out/video_out_xv.c:1465
+#: src/video_out/video_out_xvmc.c:1455 src/video_out/video_out_xxmc.c:2441
#, fuzzy
msgid "autopaint colour key"
msgstr "DonútiÅ¥ Xv automaticky kresliÅ¥ svojou kľúÄovou farbou"
-#: src/video_out/video_out_xcbxv.c:1449 src/video_out/video_out_xv.c:1463
-#: src/video_out/video_out_xvmc.c:1456 src/video_out/video_out_xxmc.c:2445
+#: src/video_out/video_out_xcbxv.c:1453 src/video_out/video_out_xv.c:1466
+#: src/video_out/video_out_xvmc.c:1456 src/video_out/video_out_xxmc.c:2442
#, fuzzy
msgid "Make Xv autopaint its colorkey."
msgstr "DonútiÅ¥ Xv automaticky kresliÅ¥ svojou kľúÄovou farbou"
-#: src/video_out/video_out_xcbxv.c:1456 src/video_out/video_out_xv.c:1470
-#: src/video_out/video_out_xxmc.c:2452
+#: src/video_out/video_out_xcbxv.c:1460 src/video_out/video_out_xv.c:1473
+#: src/video_out/video_out_xxmc.c:2449
#, fuzzy
msgid "bilinear scaling mode"
msgstr "bilinearny škálovací mód (permedia 2/3)"
-#: src/video_out/video_out_xcbxv.c:1457 src/video_out/video_out_xv.c:1471
-#: src/video_out/video_out_xxmc.c:2453
+#: src/video_out/video_out_xcbxv.c:1461 src/video_out/video_out_xv.c:1474
+#: src/video_out/video_out_xxmc.c:2450
msgid ""
"Selects the bilinear scaling mode for Permedia cards. The individual values "
"are:\n"
@@ -4059,32 +4035,34 @@ msgid ""
"2 - enable full bilinear filtering"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1509
-#, fuzzy
-msgid "video_out_xcbxv: this adaptor supports the yv12 format.\n"
+#: src/video_out/video_out_xcbxv.c:1513 src/video_out/video_out_xv.c:1523
+#: src/video_out/video_out_xxmc.c:2506
+#, fuzzy, c-format
+msgid "%s: this adaptor supports the yv12 format.\n"
msgstr "video_out_xv: tento adaptér podporuje yv12 formát.\n"
-#: src/video_out/video_out_xcbxv.c:1514
-#, fuzzy
-msgid "video_out_xcbxv: this adaptor supports the yuy2 format.\n"
+#: src/video_out/video_out_xcbxv.c:1518 src/video_out/video_out_xv.c:1528
+#: src/video_out/video_out_xxmc.c:2511
+#, fuzzy, c-format
+msgid "%s: this adaptor supports the yuy2 format.\n"
msgstr "video_out_xv: tento adaptér podporuje yuy2 formát.\n"
-#: src/video_out/video_out_xcbxv.c:1522 src/video_out/video_out_xv.c:1547
-#: src/video_out/video_out_xxmc.c:2537
+#: src/video_out/video_out_xcbxv.c:1526 src/video_out/video_out_xv.c:1550
+#: src/video_out/video_out_xxmc.c:2534
msgid "pitch alignment workaround"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1523 src/video_out/video_out_xv.c:1548
-#: src/video_out/video_out_xxmc.c:2538
+#: src/video_out/video_out_xcbxv.c:1527 src/video_out/video_out_xv.c:1551
+#: src/video_out/video_out_xxmc.c:2535
msgid "Some buggy video drivers need a workaround to function properly."
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1529 src/video_out/video_out_xv.c:1554
+#: src/video_out/video_out_xcbxv.c:1533 src/video_out/video_out_xv.c:1557
#: src/video_out/video_out_xvmc.c:1524
msgid "deinterlace method (deprecated)"
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1530 src/video_out/video_out_xv.c:1555
+#: src/video_out/video_out_xcbxv.c:1534 src/video_out/video_out_xv.c:1558
#: src/video_out/video_out_xvmc.c:1525
msgid ""
"This config setting is deprecated. You should use the new deinterlacing post "
@@ -4123,117 +4101,30 @@ msgid ""
"with medium CPU usage."
msgstr ""
-#: src/video_out/video_out_xcbxv.c:1584 src/video_out/video_out_xv.c:1628
-#: src/video_out/video_out_xxmc.c:2618
+#: src/video_out/video_out_xcbxv.c:1588 src/video_out/video_out_xv.c:1631
+#: src/video_out/video_out_xxmc.c:2615
msgid "xine video output plugin using the MIT X video extension"
msgstr "výstupný video xine modul použitím MIT X video rozšírenia"
#: src/video_out/video_out_xshm.c:202
-msgid ""
-"video_out_xshm: shared memory error when allocating image\n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xshm: chyba dielanej pamäte pri alokácii obrazu\n"
-"video_out_xshm: => nepoužívam rozšírenie MIT Shared Memory.\n"
-
-#: src/video_out/video_out_xshm.c:218
#, c-format
-msgid ""
-"video_out_xshm: %s: allocating image\n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
+msgid "%s: shared memory error when allocating image\n"
msgstr ""
-"video_out_xshm: %s: alokácia obrazu\n"
-"video_out_xshm: => nepoužívam rozšírenie MIT Shared Memory.\n"
-#: src/video_out/video_out_xshm.c:228
-msgid ""
-"video_out_xshm: shared memory error (address error) when allocating image \n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xshm: chyba dielanej pamäte (chyba adresy) pri alokácii obrazu\n"
-"video_out_xshm: => nepoužívam rozšírenie MIT Shared Memory.\n"
-
-#: src/video_out/video_out_xshm.c:245
-msgid ""
-"video_out_xshm: x11 error during shared memory XImage creation\n"
-"video_out_xshm: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xshm: x11 chyba pri vytváraní zdielanej pamäte XImage\n"
-"video_out_xshm: => nepoužívam rozšírenie MIT Shared Memory.\n"
-
-#: src/video_out/video_out_xshm.c:1170
-msgid "video_out_xshm: MIT shared memory extension not present on display.\n"
-msgstr ""
-"video_out_xshm: rozšírenie zdielanej pamäte MIT neprítomné na obrazovke.\n"
-
-#: src/video_out/video_out_xshm.c:1254
-msgid "video_out_xshm: your video mode was not recognized, sorry :-(\n"
-msgstr "video_out_xshm: váš video mód nebol rozoznaný, prepáÄte :-(\n"
-
-#: src/video_out/video_out_xv.c:296
-msgid ""
-"video_out_xv: XvShmCreateImage failed\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xv: XvShmCreateImage zlyhala\n"
-"video_out_xv: => nepoužívam rozšírenie MIT Shared Memory.\n"
-
-#: src/video_out/video_out_xv.c:306
-msgid ""
-"video_out_xv: XvShmCreateImage returned a zero size\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xv: XvShmCreateImage vrátila nulovú veľkosť\n"
-"video_out_xv: => nepoužívam rozšírenie MIT Shared Memory.\n"
-
-#: src/video_out/video_out_xv.c:314
+#: src/video_out/video_out_xv.c:294 src/video_out/video_out_xxmc.c:646
#, c-format
-msgid ""
-"video_out_xv: shared memory error in shmget: %s\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
+msgid "%s: XvShmCreateImage failed\n"
msgstr ""
-"video_out_xv: chyba zdielanej pamäte v shmget: %s\n"
-"video_out_xv: => nepoužívam rozšírenie MIT Shared Memory.\n"
-#: src/video_out/video_out_xv.c:346
-msgid ""
-"video_out_xv: x11 error during shared memory XImage creation\n"
-"video_out_xv: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xv: x11 chyba pri vytváraní zdielanej pamäte XImage\n"
-"video_out_xv: => nepoužívam rozšírenie MIT Shared Memory.\n"
-
-#: src/video_out/video_out_xv.c:1299
-msgid "video_out_xv: Xv extension not present.\n"
-msgstr "video_out_xv: Xv rozšírenie neprítomné.\n"
-
-#: src/video_out/video_out_xv.c:1336
-msgid ""
-"video_out_xv: Xv extension is present but I couldn't find a usable yuv12 "
-"port.\n"
-" Looks like your graphics hardware driver doesn't support Xv?!\n"
-msgstr ""
-"video_out_xv: rozšírenie Xv je prítomné, ale nenašiel som použiteľný yuv12 "
-"port.\n"
-" Vyzerá to tak, že vaša grafická karta nepodoruje Xv?!\n"
-
-#: src/video_out/video_out_xv.c:1345
-#, c-format
+#: src/video_out/video_out_xv.c:1348 src/video_out/video_out_xxmc.c:2330
+#, fuzzy, c-format
msgid ""
-"video_out_xv: using Xv port %ld from adaptor %s for hardware colorspace "
-"conversion and scaling.\n"
+"%s: using Xv port %ld from adaptor %s for hardware colorspace conversion and "
+"scaling.\n"
msgstr ""
"video_out_xv: používam Xv port %ld z adaptéru %s pre hardvérovú konverziu "
"farebného priestoru a škálovania.\n"
-#: src/video_out/video_out_xv.c:1520
-msgid "video_out_xv: this adaptor supports the yv12 format.\n"
-msgstr "video_out_xv: tento adaptér podporuje yv12 formát.\n"
-
-#: src/video_out/video_out_xv.c:1525
-msgid "video_out_xv: this adaptor supports the yuy2 format.\n"
-msgstr "video_out_xv: tento adaptér podporuje yuy2 formát.\n"
-
#: src/video_out/video_out_xvmc.c:1593
msgid "xine video output plugin using the XvMC X video extension"
msgstr "výstupný video xine modul použitím XvMC X video rozšírenia"
@@ -4276,114 +4167,43 @@ msgstr " žiadna XvMC podpora \n"
msgid " With Overlay = %d; UnsignedIntra = %d.\n"
msgstr " S Prekrývaním = %d; UnsignedIntra = %d.\n"
-#: src/video_out/video_out_xxmc.c:650
-#, fuzzy
-msgid ""
-"video_out_xxmc: XvShmCreateImage failed\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xv: XvShmCreateImage zlyhala\n"
-"video_out_xv: => nepoužívam rozšírenie MIT Shared Memory.\n"
-
-#: src/video_out/video_out_xxmc.c:660
-#, fuzzy
-msgid ""
-"video_out_xxmc: XvShmCreateImage returned a zero size\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xv: XvShmCreateImage vrátila nulovú veľkosť\n"
-"video_out_xv: => nepoužívam rozšírenie MIT Shared Memory.\n"
-
-#: src/video_out/video_out_xxmc.c:668
-#, fuzzy, c-format
-msgid ""
-"video_out_xxmc: shared memory error in shmget: %s\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xv: chyba zdielanej pamäte v shmget: %s\n"
-"video_out_xv: => nepoužívam rozšírenie MIT Shared Memory.\n"
-
-#: src/video_out/video_out_xxmc.c:700
-#, fuzzy
-msgid ""
-"video_out_xxmc: x11 error during shared memory XImage creation\n"
-"video_out_xxmc: => not using MIT Shared Memory extension.\n"
-msgstr ""
-"video_out_xshm: x11 chyba pri vytváraní zdielanej pamäte XImage\n"
-"video_out_xshm: => nepoužívam rozšírenie MIT Shared Memory.\n"
-
-#: src/video_out/video_out_xxmc.c:2287
-#, fuzzy
-msgid "video_out_xxmc: Xv extension not present.\n"
-msgstr "video_out_xvmc: XvMC rozšírenie neprítomné.\n"
-
-#: src/video_out/video_out_xxmc.c:2324
-#, fuzzy
-msgid ""
-"video_out_xxmc: Xv extension is present but I couldn't find a usable yuv12 "
-"port.\n"
-" Looks like your graphics hardware driver doesn't support Xv?!\n"
-msgstr ""
-"video_out_xv: rozšírenie Xv je prítomné, ale nenašiel som použiteľný yuv12 "
-"port.\n"
-" Vyzerá to tak, že vaša grafická karta nepodoruje Xv?!\n"
-
-#: src/video_out/video_out_xxmc.c:2333
-#, fuzzy, c-format
-msgid ""
-"video_out_xxmc: using Xv port %ld from adaptor %s for hardware colorspace "
-"conversion and scaling.\n"
-msgstr ""
-"video_out_xv: používam Xv port %ld z adaptéru %s pre hardvérovú konverziu "
-"farebného priestoru a škálovania.\n"
-
-#: src/video_out/video_out_xxmc.c:2509
-#, fuzzy
-msgid "video_out_xxmc: this adaptor supports the yv12 format.\n"
-msgstr "video_out_xv: tento adaptér podporuje yv12 formát.\n"
-
-#: src/video_out/video_out_xxmc.c:2514
-#, fuzzy
-msgid "video_out_xxmc: this adaptor supports the yuy2 format.\n"
-msgstr "video_out_xv: tento adaptér podporuje yuy2 formát.\n"
-
-#: src/video_out/video_out_xxmc.c:2543
+#: src/video_out/video_out_xxmc.c:2540
msgid "Make XvMC allocate more frames for better buffering."
msgstr ""
-#: src/video_out/video_out_xxmc.c:2544
+#: src/video_out/video_out_xxmc.c:2541
msgid ""
"Some XvMC implementations allow more than 8 frames.\n"
"This option, when turned on, makes the driver try to\n"
"allocate 15 frames. A must for unichrome and live VDR.\n"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2550
+#: src/video_out/video_out_xxmc.c:2547
msgid "Unichrome cpu save"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2551
+#: src/video_out/video_out_xxmc.c:2548
msgid ""
"Saves CPU time by sleeping while decoder works.\n"
"Only for Linux kernel 2.6 series or 2.4 with multimedia patch.\n"
"Experimental.\n"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2557
+#: src/video_out/video_out_xxmc.c:2554
msgid "Fix buggy NVIDIA XvMC subpicture colors"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2558
+#: src/video_out/video_out_xxmc.c:2555
msgid ""
"There's a bug in NVIDIA's XvMC lib that makes red OSD colors\n"
"look blue and vice versa. This option provides a workaround.\n"
msgstr ""
-#: src/video_out/video_out_xxmc.c:2563
+#: src/video_out/video_out_xxmc.c:2560
msgid "Use bob as accelerated deinterlace method."
msgstr ""
-#: src/video_out/video_out_xxmc.c:2564
+#: src/video_out/video_out_xxmc.c:2561
msgid ""
"When interlacing is enabled for hardware accelerated frames,\n"
"Alternate between top and bottom field at double the frame rate.\n"
@@ -4616,12 +4436,12 @@ msgid ""
"info_helper: unsupported conversion %s -> UTF-8, no conversion performed\n"
msgstr "osd: nepodporovaná konverzia %s -> %s, nebude vykonaná žiadna\n"
-#: src/xine-engine/input_cache.c:167
+#: src/xine-engine/input_cache.c:171
#, fuzzy, c-format
msgid ": open() function should never be called\n"
msgstr "input_rip: funkcia open() by nikdy nemala byť volaná\n"
-#: src/xine-engine/input_cache.c:349
+#: src/xine-engine/input_cache.c:353
#, fuzzy, c-format
msgid ": input plugin not defined!\n"
msgstr "input_rip: vstupný modul nedefinovaný!\n"
@@ -4735,80 +4555,80 @@ msgstr "Meno tuneru nenájdené\n"
msgid "io_helper: Connection Refused\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:212
+#: src/xine-engine/load_plugins.c:215
#, c-format
msgid "map_decoder_list: no space for decoder, skipped.\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:327
+#: src/xine-engine/load_plugins.c:330
#, c-format
msgid ""
"load_plugins: ignoring plugin %s, wrong iface version %d (should be %d)\n"
msgstr ""
"load_plugins: ignorujem modul %s, zlá verzia rozhrania %d (má byť %d)\n"
-#: src/xine-engine/load_plugins.c:384
+#: src/xine-engine/load_plugins.c:387
#, c-format
msgid "priority for %s decoder"
msgstr ""
-#: src/xine-engine/load_plugins.c:395
+#: src/xine-engine/load_plugins.c:398
msgid ""
"The priority provides a ranking in case some media can be handled by more "
"than one decoder.\n"
"A priority of 0 enables the decoder's default priority."
msgstr ""
-#: src/xine-engine/load_plugins.c:423
+#: src/xine-engine/load_plugins.c:426
#, c-format
msgid ""
"load_plugins: demuxer plugin %s does not provide a priority, xine-lib will "
"use the default priority.\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:440
+#: src/xine-engine/load_plugins.c:443
#, c-format
msgid ""
"load_plugins: input plugin %s does not provide a priority, xine-lib will use "
"the default priority.\n"
msgstr ""
-#: src/xine-engine/load_plugins.c:496
+#: src/xine-engine/load_plugins.c:499
#, c-format
msgid "load_plugins: plugin %s found\n"
msgstr "load_plugins: nájdený modul: %s\n"
-#: src/xine-engine/load_plugins.c:499
+#: src/xine-engine/load_plugins.c:502
#, fuzzy, c-format
msgid "load_plugins: static plugin found\n"
msgstr "load_plugins: nájdený modul: %s\n"
-#: src/xine-engine/load_plugins.c:506
+#: src/xine-engine/load_plugins.c:509
#, fuzzy, c-format
msgid "load_plugins: plugin limit reached, %s could not be loaded\n"
msgstr "load_plugins: nájdený modul: %s\n"
-#: src/xine-engine/load_plugins.c:509
+#: src/xine-engine/load_plugins.c:512
#, fuzzy, c-format
msgid "load_plugins: plugin limit reached, static plugin could not be loaded\n"
msgstr "load_plugins: nájdený modul: %s\n"
-#: src/xine-engine/load_plugins.c:526
+#: src/xine-engine/load_plugins.c:529
#, c-format
msgid "load_plugins: unknown plugin type %d in %s\n"
msgstr "load_plugins: neznámy typ modulu %d v %s\n"
-#: src/xine-engine/load_plugins.c:530
+#: src/xine-engine/load_plugins.c:533
#, fuzzy, c-format
msgid "load_plugins: unknown statically linked plugin type %d\n"
msgstr "load_plugins: neznámy typ modulu %d v %s\n"
-#: src/xine-engine/load_plugins.c:590
+#: src/xine-engine/load_plugins.c:593
#, c-format
msgid "load_plugins: unable to stat %s\n"
msgstr "load_plugins: nemôžem naštartovať %s\n"
-#: src/xine-engine/load_plugins.c:631
+#: src/xine-engine/load_plugins.c:634
#, c-format
msgid ""
"load_plugins: cannot open plugin lib %s:\n"
@@ -4817,7 +4637,7 @@ msgstr ""
"load_plugins: nemožno otvoriť knižnicu modulov %s:\n"
"%s\n"
-#: src/xine-engine/load_plugins.c:646
+#: src/xine-engine/load_plugins.c:649
#, c-format
msgid ""
"load_plugins: can't get plugin info from %s:\n"
@@ -4826,12 +4646,12 @@ msgstr ""
"load_plugins: nemožno získať info modulu z %s:\n"
"%s\n"
-#: src/xine-engine/load_plugins.c:664
+#: src/xine-engine/load_plugins.c:667
#, c-format
msgid "load_plugins: skipping unreadable plugin directory %s.\n"
msgstr "load_plugins: preskakujem neÄitateľný adresár modulov: %s\n"
-#: src/xine-engine/load_plugins.c:713
+#: src/xine-engine/load_plugins.c:716
#, c-format
msgid ""
"load_plugins: cannot (stage 2) open plugin lib %s:\n"
@@ -4840,27 +4660,32 @@ msgstr ""
"load_plugins: nemožno (fáza 2) otvoriť knižnicu modulov %s:\n"
"%s\n"
-#: src/xine-engine/load_plugins.c:739
+#: src/xine-engine/load_plugins.c:742
#, c-format
msgid "load_plugins: Yikes! %s doesn't contain plugin info.\n"
msgstr "load_plugins: Čo! %s neobsahuje informácie modulu.\n"
-#: src/xine-engine/load_plugins.c:1305
+#: src/xine-engine/load_plugins.c:1104 src/xine-engine/load_plugins.c:1113
+#, fuzzy, c-format
+msgid "Unable to create %s directory: %s\n"
+msgstr "nemožno otvoriť %s: %s.\n"
+
+#: src/xine-engine/load_plugins.c:1345
#, c-format
msgid "load_plugins: unknown content detection strategy %d\n"
msgstr "load_plugins: neznáma stratégia %d zisťovánia obsahu\n"
-#: src/xine-engine/load_plugins.c:1415
+#: src/xine-engine/load_plugins.c:1455
#, c-format
msgid "load_plugins: using demuxer '%s'\n"
msgstr "load_plugins: nájdený demultiplexor '%s'\n"
-#: src/xine-engine/load_plugins.c:1726
+#: src/xine-engine/load_plugins.c:1766
#, c-format
msgid "load_plugins: failed to load audio output plugin <%s>\n"
msgstr "load_plugins: zlyhalo naÄítanie výstupného audio modulu <%s>\n"
-#: src/xine-engine/load_plugins.c:1729
+#: src/xine-engine/load_plugins.c:1769
msgid ""
"load_plugins: audio output auto-probing didn't find any usable audio "
"driver.\n"
@@ -4868,7 +4693,7 @@ msgstr ""
"load_plugins: auto-detekcia audio výstupu nenašla žiadne použiteľné audio "
"ovládaÄe.\n"
-#: src/xine-engine/load_plugins.c:2033
+#: src/xine-engine/load_plugins.c:2073
#, fuzzy, c-format
msgid ""
"load_plugins: cannot unload plugin lib %s:\n"
@@ -4877,31 +4702,27 @@ msgstr ""
"load_plugins: nemožno otvoriť knižnicu modulov %s:\n"
"%s\n"
-#: src/xine-engine/osd.c:745
+#: src/xine-engine/osd.c:747
#, c-format
msgid "font '%s-%d' already loaded, weird.\n"
msgstr "font '%s-%d' už naÄítaný, divné.\n"
-#: src/xine-engine/osd.c:757
+#: src/xine-engine/osd.c:759
#, c-format
msgid "font '%s' loading failed (%d < %d)\n"
msgstr "naÄítanie fontu '%s' zlyhalo (%d < %d)\n"
-#: src/xine-engine/osd.c:767
+#: src/xine-engine/osd.c:769
#, c-format
msgid "wrong version for font '%s'. expected %d found %d.\n"
msgstr "zlá verzia fontu '%s'. oÄakávaná %d nájdená %d.\n"
-#: src/xine-engine/osd.c:834
-msgid "osd: cannot initialize ft2 library\n"
-msgstr "osd: nemôžem inicializovať ft2 knižnicu\n"
-
-#: src/xine-engine/osd.c:857
+#: src/xine-engine/osd.c:856
#, fuzzy, c-format
msgid "osd: error matching font %s with FontConfig"
msgstr "osd: chyba naÄítania fontu %s s ft2\n"
-#: src/xine-engine/osd.c:871
+#: src/xine-engine/osd.c:870
#, fuzzy, c-format
msgid "osd: error loading font %s with FontConfig"
msgstr "osd: chyba naÄítania fontu %s s ft2\n"
@@ -4911,16 +4732,20 @@ msgstr "osd: chyba naÄítania fontu %s s ft2\n"
msgid "osd: error looking up font %s with FontConfig"
msgstr "osd: chyba naÄítania fontu %s s ft2\n"
-#: src/xine-engine/osd.c:895
-#, c-format
-msgid "osd: error loading font %s with ft2\n"
+#: src/xine-engine/osd.c:914
+#, fuzzy, c-format
+msgid "osd: error loading font %s with in XDG data directories.\n"
msgstr "osd: chyba naÄítania fontu %s s ft2\n"
-#: src/xine-engine/osd.c:905
+#: src/xine-engine/osd.c:923
+msgid "osd: cannot initialize ft2 library\n"
+msgstr "osd: nemôžem inicializovať ft2 knižnicu\n"
+
+#: src/xine-engine/osd.c:945
msgid "osd: error setting font size (no scalable font?)\n"
msgstr "osd: chyba pri nastavení veľkosti fontu (neškálovateľný font?)\n"
-#: src/xine-engine/osd.c:1021
+#: src/xine-engine/osd.c:1061
#, c-format
msgid ""
"osd: unknown sequence starting with byte 0x%02X in encoding \"%s\", "
@@ -4929,42 +4754,42 @@ msgstr ""
"osd: neznáma sekvencia zaÄínajúca s bytom 0x%02X v kódovaní \"%s\", "
"preskakujem\n"
-#: src/xine-engine/osd.c:1077
+#: src/xine-engine/osd.c:1117
msgid "osd: can't find out current locale character set\n"
msgstr "osd: nemôžem zistiť aktuálnu kódovú stánku\n"
-#: src/xine-engine/osd.c:1087
+#: src/xine-engine/osd.c:1127
#, c-format
msgid "osd: unsupported conversion %s -> %s, no conversion performed\n"
msgstr "osd: nepodporovaná konverzia %s -> %s, nebude vykonaná žiadna\n"
-#: src/xine-engine/osd.c:1142 src/xine-engine/osd.c:1310
+#: src/xine-engine/osd.c:1182 src/xine-engine/osd.c:1350
msgid "osd: font isn't defined\n"
msgstr "osd: font nie je definovaný\n"
-#: src/xine-engine/osd.c:1181
+#: src/xine-engine/osd.c:1221
msgid "osd: error loading glyph\n"
msgstr "osd: chyba zavedenia glyph\n"
-#: src/xine-engine/osd.c:1187
+#: src/xine-engine/osd.c:1227
msgid "osd: error in rendering glyph\n"
msgstr "osd: chyba pri vykreslovaní glyph\n"
-#: src/xine-engine/osd.c:1347
+#: src/xine-engine/osd.c:1387
#, c-format
msgid "osd: error loading glyph %i\n"
msgstr "osd: chyba zavedenia glyph %i\n"
-#: src/xine-engine/osd.c:1354
+#: src/xine-engine/osd.c:1394
msgid "osd: error in rendering\n"
msgstr "osd: chyba pri vykreslovaní\n"
-#: src/xine-engine/osd.c:1611
+#: src/xine-engine/osd.c:1660
#, fuzzy
msgid "palette (foreground-border-background) to use for subtitles and OSD"
msgstr "Paleta (popredie-okraj-pozadie) použitá na titulky"
-#: src/xine-engine/osd.c:1612
+#: src/xine-engine/osd.c:1661
msgid ""
"The palette for on-screen-display and some subtitle formats that do not "
"specify any colouring themselves. The palettes are listed in the form: "
@@ -5080,128 +4905,128 @@ msgid ""
"accelerated, this can dramatically reduce CPU usage."
msgstr ""
-#: src/xine-engine/xine.c:704 src/xine-engine/xine.c:811
-#: src/xine-engine/xine.c:850 src/xine-engine/xine.c:886
-#: src/xine-engine/xine.c:898 src/xine-engine/xine.c:911
-#: src/xine-engine/xine.c:924 src/xine-engine/xine.c:937
-#: src/xine-engine/xine.c:963 src/xine-engine/xine.c:988
-#: src/xine-engine/xine.c:1023
+#: src/xine-engine/xine.c:706 src/xine-engine/xine.c:813
+#: src/xine-engine/xine.c:852 src/xine-engine/xine.c:888
+#: src/xine-engine/xine.c:900 src/xine-engine/xine.c:913
+#: src/xine-engine/xine.c:926 src/xine-engine/xine.c:939
+#: src/xine-engine/xine.c:965 src/xine-engine/xine.c:990
+#: src/xine-engine/xine.c:1025
msgid "xine: error while parsing mrl\n"
msgstr "xine: chyba pri spracovaní mrl\n"
-#: src/xine-engine/xine.c:740
+#: src/xine-engine/xine.c:742
#, c-format
msgid "xine: found input plugin : %s\n"
msgstr "xine: nájdený vstupný modul : %s\n"
-#: src/xine-engine/xine.c:758
+#: src/xine-engine/xine.c:760
#, c-format
msgid "xine: input plugin cannot open MRL [%s]\n"
msgstr "xine: vstupný modul nemôže otvoriť MRL [%s]\n"
-#: src/xine-engine/xine.c:774
+#: src/xine-engine/xine.c:776
#, c-format
msgid "xine: cannot find input plugin for MRL [%s]\n"
msgstr "xine: nemožno nájsť vstupný modul pre MRL [%s]\n"
-#: src/xine-engine/xine.c:800
+#: src/xine-engine/xine.c:802
#, c-format
msgid "xine: specified demuxer %s failed to start\n"
msgstr "xine: špecifikovaný demultiplexor %s nenaštartoval\n"
-#: src/xine-engine/xine.c:836
+#: src/xine-engine/xine.c:838
#, c-format
msgid "xine: join rip input plugin\n"
msgstr "xine: pripojený rip vstupný modul\n"
-#: src/xine-engine/xine.c:843
+#: src/xine-engine/xine.c:845
msgid "xine: error opening rip input plugin instance\n"
msgstr "xine: chyba otvorenia modulu vstupu rip\n"
-#: src/xine-engine/xine.c:874
+#: src/xine-engine/xine.c:876
#, c-format
msgid "xine: last_probed demuxer %s failed to start\n"
msgstr "xine: last_probed demultiplexor %s nenaštartoval\n"
-#: src/xine-engine/xine.c:903
+#: src/xine-engine/xine.c:905
msgid "ignoring video\n"
msgstr "ignorujem video\n"
-#: src/xine-engine/xine.c:916
+#: src/xine-engine/xine.c:918
msgid "ignoring audio\n"
msgstr "ignorujem audio\n"
-#: src/xine-engine/xine.c:929
+#: src/xine-engine/xine.c:931
msgid "ignoring subpicture\n"
msgstr "ignorujem titulky\n"
-#: src/xine-engine/xine.c:942
+#: src/xine-engine/xine.c:944
msgid "input cache plugin disabled\n"
msgstr ""
-#: src/xine-engine/xine.c:1013
+#: src/xine-engine/xine.c:1015
#, c-format
msgid "subtitle mrl opened '%s'\n"
msgstr "mrl titulkov otvorené '%s'\n"
-#: src/xine-engine/xine.c:1017
+#: src/xine-engine/xine.c:1019
msgid "xine: error opening subtitle mrl\n"
msgstr "xine: nemožno otvoriť mrl titulkov\n"
-#: src/xine-engine/xine.c:1049
+#: src/xine-engine/xine.c:1051
#, c-format
msgid "xine: error while parsing MRL\n"
msgstr "xine: chyba pri spracovaní MRL\n"
-#: src/xine-engine/xine.c:1056
+#: src/xine-engine/xine.c:1058
#, c-format
msgid "xine: changing option '%s' from MRL isn't permitted\n"
msgstr "xine: zmeniť voľbu '%s' z MRL nie je dovolené\n"
-#: src/xine-engine/xine.c:1076
+#: src/xine-engine/xine.c:1078
#, c-format
msgid "xine: couldn't find demux for >%s<\n"
msgstr "xine: nemožno nájsť demultiplexor pre >%s<\n"
-#: src/xine-engine/xine.c:1092
+#: src/xine-engine/xine.c:1094
#, c-format
msgid "xine: found demuxer plugin: %s\n"
msgstr "xine: nájdený modul demultiplexora %s\n"
-#: src/xine-engine/xine.c:1112
+#: src/xine-engine/xine.c:1114
#, c-format
msgid "xine: demuxer failed to start\n"
msgstr "xine: demultiplexor nenaštartoval\n"
-#: src/xine-engine/xine.c:1177
+#: src/xine-engine/xine.c:1179
#, c-format
msgid "xine_play: no demux available\n"
msgstr "xine_play: demultiplexor nedostupný\n"
-#: src/xine-engine/xine.c:1247
+#: src/xine-engine/xine.c:1249
#, c-format
msgid "xine_play: demux failed to start\n"
msgstr "xine_play: demultiplexor nenaštartoval\n"
-#: src/xine-engine/xine.c:1523
+#: src/xine-engine/xine.c:1527
#, c-format
msgid "xine: The specified save_dir \"%s\" might be a security risk.\n"
msgstr "xine: Å pecifikovaný save_dir \"%s\" môže byÅ¥ bezpeÄnostným rizikom.\n"
-#: src/xine-engine/xine.c:1528
+#: src/xine-engine/xine.c:1532
msgid "The specified save_dir might be a security risk."
msgstr "Å pecifikovaný save_dir môže byÅ¥ bezpeÄnostným rizikom."
-#: src/xine-engine/xine.c:1554
+#: src/xine-engine/xine.c:1561
msgid "xine: locale not supported by C library\n"
msgstr "xine: locale nepodporované vašou C knižnicou\n"
-#: src/xine-engine/xine.c:1563
+#: src/xine-engine/xine.c:1570
#, fuzzy
msgid "media format detection strategy"
msgstr "Stratégia detekcie formátu médii"
-#: src/xine-engine/xine.c:1564
+#: src/xine-engine/xine.c:1571
msgid ""
"xine offers various methods to detect the media format of input to play. The "
"individual values are:\n"
@@ -5219,12 +5044,12 @@ msgid ""
"Detect by file name extension only.\n"
msgstr ""
-#: src/xine-engine/xine.c:1582
+#: src/xine-engine/xine.c:1589
#, fuzzy
msgid "directory for saving streams"
msgstr "Cesta pre ukladanie prúdov"
-#: src/xine-engine/xine.c:1583
+#: src/xine-engine/xine.c:1590
msgid ""
"When using the stream save feature, files will be written only into this "
"directory.\n"
@@ -5234,11 +5059,11 @@ msgid ""
"content in any file."
msgstr ""
-#: src/xine-engine/xine.c:1594
+#: src/xine-engine/xine.c:1601
msgid "allow implicit changes to the configuration (e.g. by MRL)"
msgstr "dovoliť implicitné zmeny v konfigurácii (napr. cez MRL)"
-#: src/xine-engine/xine.c:1595
+#: src/xine-engine/xine.c:1602
msgid ""
"If enabled, you allow xine to change your configuration without explicit "
"actions from your side. For example configuration changes demanded by MRLs "
@@ -5254,26 +5079,26 @@ msgstr ""
"MRL alebo playlisty z nedôverihodných vzdialených zdrojov. Ak im dovolíte "
"ľubovoľne meniÅ¥ vaÅ¡u konfiguráciu, môžete skonÄiÅ¥ s úplne rozhodeným xine."
-#: src/xine-engine/xine.c:1609
+#: src/xine-engine/xine.c:1616
msgid "Timeout for network stream reading (in seconds)"
msgstr ""
-#: src/xine-engine/xine.c:1610
+#: src/xine-engine/xine.c:1617
msgid ""
"Specifies the timeout when reading from network streams, in seconds. Too low "
"values might stop streaming when the source is slow or the bandwidth is "
"occupied, too high values will freeze the player if the connection is lost."
msgstr ""
-#: src/xine-engine/xine.c:1962
+#: src/xine-engine/xine.c:1969
msgid "messages"
msgstr "správy"
-#: src/xine-engine/xine.c:1963
+#: src/xine-engine/xine.c:1970
msgid "plugin"
msgstr "modul"
-#: src/xine-engine/xine.c:1964
+#: src/xine-engine/xine.c:1971
msgid "trace"
msgstr "trace"
@@ -5349,6 +5174,229 @@ msgstr ""
msgid "Benchmarking memcpy methods (smaller is better):\n"
msgstr "Testovanie výkonnosti memcpy metód (menej je lepšie):\n"
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xcbshm: %s: allocating image\n"
+#~ "video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xshm: %s: alokácia obrazu\n"
+#~ "video_out_xshm: => nepoužívam rozšírenie MIT Shared Memory.\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xcbshm: shared memory error (address error) when allocating "
+#~ "image \n"
+#~ "video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xshm: chyba dielanej pamäte (chyba adresy) pri alokácii obrazu\n"
+#~ "video_out_xshm: => nepoužívam rozšírenie MIT Shared Memory.\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xcbshm: x11 error during shared memory XImage creation\n"
+#~ "video_out_xcbshm: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xshm: x11 chyba pri vytváraní zdielanej pamäte XImage\n"
+#~ "video_out_xshm: => nepoužívam rozšírenie MIT Shared Memory.\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xcbshm: MIT shared memory extension not present on display.\n"
+#~ msgstr ""
+#~ "video_out_xshm: rozšírenie zdielanej pamäte MIT neprítomné na obrazovke.\n"
+
+#, fuzzy
+#~ msgid "video_out_xcbshm: your video mode was not recognized, sorry :-(\n"
+#~ msgstr "video_out_xshm: váš video mód nebol rozoznaný, prepáÄte :-(\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xcbxv: XvShmCreateImage returned a zero size\n"
+#~ "video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xv: XvShmCreateImage vrátila nulovú veľkosť\n"
+#~ "video_out_xv: => nepoužívam rozšírenie MIT Shared Memory.\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xcbxv: shared memory error in shmget: %s\n"
+#~ "video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xv: chyba zdielanej pamäte v shmget: %s\n"
+#~ "video_out_xv: => nepoužívam rozšírenie MIT Shared Memory.\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xcbxv: x11 error during shared memory XImage creation\n"
+#~ "video_out_xcbxv: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xv: x11 chyba pri vytváraní zdielanej pamäte XImage\n"
+#~ "video_out_xv: => nepoužívam rozšírenie MIT Shared Memory.\n"
+
+#, fuzzy
+#~ msgid "video_out_xcbxv: Xv extension not present.\n"
+#~ msgstr "video_out_xv: Xv rozšírenie neprítomné.\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xcbxv: Xv extension is present but I couldn't find a usable "
+#~ "yuv12 port.\n"
+#~ " Looks like your graphics hardware driver doesn't support "
+#~ "Xv?!\n"
+#~ msgstr ""
+#~ "video_out_xv: rozšírenie Xv je prítomné, ale nenašiel som použiteľný "
+#~ "yuv12 port.\n"
+#~ " Vyzerá to tak, že vaša grafická karta nepodoruje Xv?!\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xcbxv: using Xv port %d from adaptor %s for hardware colorspace "
+#~ "conversion and scaling.\n"
+#~ msgstr ""
+#~ "video_out_xv: používam Xv port %ld z adaptéru %s pre hardvérovú konverziu "
+#~ "farebného priestoru a škálovania.\n"
+
+#, fuzzy
+#~ msgid "video_out_xcbxv: this adaptor supports the yv12 format.\n"
+#~ msgstr "video_out_xv: tento adaptér podporuje yv12 formát.\n"
+
+#, fuzzy
+#~ msgid "video_out_xcbxv: this adaptor supports the yuy2 format.\n"
+#~ msgstr "video_out_xv: tento adaptér podporuje yuy2 formát.\n"
+
+#~ msgid ""
+#~ "video_out_xshm: shared memory error when allocating image\n"
+#~ "video_out_xshm: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xshm: chyba dielanej pamäte pri alokácii obrazu\n"
+#~ "video_out_xshm: => nepoužívam rozšírenie MIT Shared Memory.\n"
+
+#~ msgid ""
+#~ "video_out_xshm: %s: allocating image\n"
+#~ "video_out_xshm: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xshm: %s: alokácia obrazu\n"
+#~ "video_out_xshm: => nepoužívam rozšírenie MIT Shared Memory.\n"
+
+#~ msgid ""
+#~ "video_out_xshm: x11 error during shared memory XImage creation\n"
+#~ "video_out_xshm: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xshm: x11 chyba pri vytváraní zdielanej pamäte XImage\n"
+#~ "video_out_xshm: => nepoužívam rozšírenie MIT Shared Memory.\n"
+
+#~ msgid "video_out_xshm: your video mode was not recognized, sorry :-(\n"
+#~ msgstr "video_out_xshm: váš video mód nebol rozoznaný, prepáÄte :-(\n"
+
+#~ msgid ""
+#~ "video_out_xv: XvShmCreateImage failed\n"
+#~ "video_out_xv: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xv: XvShmCreateImage zlyhala\n"
+#~ "video_out_xv: => nepoužívam rozšírenie MIT Shared Memory.\n"
+
+#~ msgid ""
+#~ "video_out_xv: XvShmCreateImage returned a zero size\n"
+#~ "video_out_xv: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xv: XvShmCreateImage vrátila nulovú veľkosť\n"
+#~ "video_out_xv: => nepoužívam rozšírenie MIT Shared Memory.\n"
+
+#~ msgid ""
+#~ "video_out_xv: shared memory error in shmget: %s\n"
+#~ "video_out_xv: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xv: chyba zdielanej pamäte v shmget: %s\n"
+#~ "video_out_xv: => nepoužívam rozšírenie MIT Shared Memory.\n"
+
+#~ msgid ""
+#~ "video_out_xv: x11 error during shared memory XImage creation\n"
+#~ "video_out_xv: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xv: x11 chyba pri vytváraní zdielanej pamäte XImage\n"
+#~ "video_out_xv: => nepoužívam rozšírenie MIT Shared Memory.\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xxmc: XvShmCreateImage failed\n"
+#~ "video_out_xxmc: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xv: XvShmCreateImage zlyhala\n"
+#~ "video_out_xv: => nepoužívam rozšírenie MIT Shared Memory.\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xxmc: XvShmCreateImage returned a zero size\n"
+#~ "video_out_xxmc: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xv: XvShmCreateImage vrátila nulovú veľkosť\n"
+#~ "video_out_xv: => nepoužívam rozšírenie MIT Shared Memory.\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xxmc: shared memory error in shmget: %s\n"
+#~ "video_out_xxmc: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xv: chyba zdielanej pamäte v shmget: %s\n"
+#~ "video_out_xv: => nepoužívam rozšírenie MIT Shared Memory.\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xxmc: x11 error during shared memory XImage creation\n"
+#~ "video_out_xxmc: => not using MIT Shared Memory extension.\n"
+#~ msgstr ""
+#~ "video_out_xshm: x11 chyba pri vytváraní zdielanej pamäte XImage\n"
+#~ "video_out_xshm: => nepoužívam rozšírenie MIT Shared Memory.\n"
+
+#, fuzzy
+#~ msgid "video_out_xxmc: Xv extension not present.\n"
+#~ msgstr "video_out_xvmc: XvMC rozšírenie neprítomné.\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xxmc: Xv extension is present but I couldn't find a usable "
+#~ "yuv12 port.\n"
+#~ " Looks like your graphics hardware driver doesn't support "
+#~ "Xv?!\n"
+#~ msgstr ""
+#~ "video_out_xv: rozšírenie Xv je prítomné, ale nenašiel som použiteľný "
+#~ "yuv12 port.\n"
+#~ " Vyzerá to tak, že vaša grafická karta nepodoruje Xv?!\n"
+
+#, fuzzy
+#~ msgid ""
+#~ "video_out_xxmc: using Xv port %ld from adaptor %s for hardware colorspace "
+#~ "conversion and scaling.\n"
+#~ msgstr ""
+#~ "video_out_xv: používam Xv port %ld z adaptéru %s pre hardvérovú konverziu "
+#~ "farebného priestoru a škálovania.\n"
+
+#, fuzzy
+#~ msgid "video_out_xxmc: this adaptor supports the yv12 format.\n"
+#~ msgstr "video_out_xv: tento adaptér podporuje yv12 formát.\n"
+
+#, fuzzy
+#~ msgid "video_out_xxmc: this adaptor supports the yuy2 format.\n"
+#~ msgstr "video_out_xv: tento adaptér podporuje yuy2 formát.\n"
+
+#, fuzzy
+#~ msgid "CDDB cache directory"
+#~ msgstr "cddbp cache adresár"
+
+#, fuzzy
+#~ msgid "path to the title key cache"
+#~ msgstr "cesta k video zariadeniu v4l"
+
+#~ msgid ""
+#~ "WARNING: video_out_fb: current display depth is %d. For better "
+#~ "performance\n"
+#~ " a depth of 16 bpp is recommended!\n"
+#~ "\n"
+#~ msgstr ""
+#~ "WARNING: video_out_fb: terajšia hĺbka zobrazenia je %d. Pre lepší výkon\n"
+#~ " hĺbka 16 bit/bod je doporuÄená!\n"
+#~ "\n"
+
#~ msgid "avcodec_find_decoder (CODEC_ID_MPEG1VIDEO) failed.\n"
#~ msgstr "avcodec_find_decoder (CODEC_ID_MPEG1VIDEO) zlyhal.\n"
diff --git a/src/Makefile.am b/src/Makefile.am
index 6718b4805..3fa5d7629 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -17,13 +17,11 @@ SUBDIRS = \
libspucmml \
libspudvb \
libsputext \
- libdts \
- libmad \
libw32dll \
libxinevdec \
libxineadec \
libreal \
libfaad \
- libmusepack \
post \
- combined
+ combined \
+ vdr
diff --git a/src/audio_out/Makefile.am b/src/audio_out/Makefile.am
index 20a4e708b..8759b123f 100644
--- a/src/audio_out/Makefile.am
+++ b/src/audio_out/Makefile.am
@@ -1,146 +1,125 @@
include $(top_srcdir)/misc/Makefile.common
-AM_CPPFLAGS = -DXINE_COMPILE
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+AM_LDFLAGS = $(xineplug_ldflags)
+
+##
+# IMPORTANT:
+# ---------
+# all xine audio out plugins should be named like the
+# scheme "xineplug_ao_out_"
+#
EXTRA_DIST = audio_irixal_out.c
-if HAVE_OSS
+if ENABLE_OSS
oss_module = xineplug_ao_out_oss.la
endif
-if HAVE_ALSA
+if ENABLE_ALSA
alsa_module = xineplug_ao_out_alsa.la
endif
-if HAVE_ESD
+if ENABLE_ESD
esd_module = xineplug_ao_out_esd.la
endif
-if HAVE_SUNAUDIO
+if ENABLE_SUNAUDIO
sun_module = xineplug_ao_out_sun.la
endif
-#if HAVE_IRIXAL
+#if ENABLE_IRIXAL
#irixal_module = xineplug_ao_out_irixal.la
#endif
-if HAVE_ARTS
+if ENABLE_ARTS
arts_module = xineplug_ao_out_arts.la
endif
-if HAVE_DIRECTX
+if ENABLE_DIRECTX
directx_module = xineplug_ao_out_directx.la
directx2_module = xineplug_ao_out_directx2.la
endif
-if HAVE_COREAUDIO
+if ENABLE_COREAUDIO
coreaudio_module = xineplug_ao_out_coreaudio.la
endif
-if HAVE_PULSEAUDIO
+if ENABLE_PULSEAUDIO
pulseaudio_module = xineplug_ao_out_pulseaudio.la
endif
-if HAVE_FUSIONSOUND
+if ENABLE_FUSIONSOUND
fusionsound_module = xineplug_ao_out_fusionsound.la
endif
-if HAVE_JACK
+if ENABLE_JACK
jack_module = xineplug_ao_out_jack.la
endif
-##
-# IMPORTANT:
-# ---------
-# all xine audio out plugins should be named like the
-# scheme "xineplug_ao_out_"
-#
-xineplug_LTLIBRARIES = xineplug_ao_out_none.la xineplug_ao_out_file.la \
- $(oss_module) \
- $(alsa_module) \
- $(sun_module) \
- $(arts_module) \
- $(esd_module) \
- $(directx_module) \
- $(coreaudio_module) \
- $(pulseaudio_module) \
+xineplug_LTLIBRARIES = \
+ xineplug_ao_out_none.la \
+ xineplug_ao_out_file.la \
+ $(oss_module) \
+ $(alsa_module) \
+ $(sun_module) \
+ $(arts_module) \
+ $(esd_module) \
+ $(directx_module) \
+ $(coreaudio_module) \
+ $(pulseaudio_module) \
$(directx2_module) \
- $(fusionsound_module) \
+ $(fusionsound_module) \
$(jack_module)
xineplug_ao_out_none_la_SOURCES = audio_none_out.c
xineplug_ao_out_none_la_LIBADD = $(XINE_LIB)
-xineplug_ao_out_none_la_CFLAGS = $(VISIBILITY_FLAG)
-xineplug_ao_out_none_la_LDFLAGS = -avoid-version -module
xineplug_ao_out_file_la_SOURCES = audio_file_out.c
xineplug_ao_out_file_la_LIBADD = $(XINE_LIB)
-xineplug_ao_out_file_la_CFLAGS = $(VISIBILITY_FLAG)
-xineplug_ao_out_file_la_LDFLAGS = -avoid-version -module
xineplug_ao_out_oss_la_SOURCES = audio_oss_out.c
xineplug_ao_out_oss_la_LIBADD = $(XINE_LIB)
-xineplug_ao_out_oss_la_CFLAGS = $(VISIBILITY_FLAG)
-xineplug_ao_out_oss_la_LDFLAGS = -avoid-version -module
xineplug_ao_out_alsa_la_SOURCES = audio_alsa_out.c
xineplug_ao_out_alsa_la_LIBADD = $(ALSA_LIBS) $(XINE_LIB) $(PTHREAD_LIBS)
-xineplug_ao_out_alsa_la_CFLAGS = $(VISIBILITY_FLAG) $(ALSA_CFLAGS)
-xineplug_ao_out_alsa_la_LDFLAGS = -avoid-version -module
+xineplug_ao_out_alsa_la_CFLAGS = $(AM_CFLAGS) $(ALSA_CFLAGS)
xineplug_ao_out_esd_la_SOURCES = audio_esd_out.c
xineplug_ao_out_esd_la_LIBADD = $(ESD_LIBS) $(XINE_LIB)
-xineplug_ao_out_esd_la_CFLAGS = $(VISIBILITY_FLAG) $(ESD_CFLAGS)
-xineplug_ao_out_esd_la_LDFLAGS = -avoid-version -module
+xineplug_ao_out_esd_la_CFLAGS = $(AM_CFLAGS) $(ESD_CFLAGS)
xineplug_ao_out_sun_la_SOURCES = audio_sun_out.c
xineplug_ao_out_sun_la_LIBADD = $(XINE_LIB)
-xineplug_ao_out_sun_la_CFLAGS = $(VISIBILITY_FLAG)
-xineplug_ao_out_sun_la_LDFLAGS = -avoid-version -module
#xineplug_ao_out_irixal_la_SOURCES = audio_irixal_out.c
#xineplug_ao_out_irixal_la_LIBADD = $(IRIXAL_LIBS)
-#xineplug_ao_out_irixal_la_CFLAGS = $(VISIBILITY_FLAG) $(IRIXAL_CFLAGS)
-#xineplug_ao_out_irixal_la_LDFLAGS = -avoid-version -module
+#xineplug_ao_out_irixal_la_CFLAGS = $(AM_CFLAGS) $(IRIXAL_CFLAGS)
xineplug_ao_out_arts_la_SOURCES = audio_arts_out.c
xineplug_ao_out_arts_la_LIBADD = $(ARTS_LIBS) $(XINE_LIB)
-xineplug_ao_out_arts_la_CFLAGS = $(VISIBILITY_FLAG) $(ARTS_CFLAGS)
-xineplug_ao_out_arts_la_LDFLAGS = -avoid-version -module
+xineplug_ao_out_arts_la_CFLAGS = $(AM_CFLAGS) $(ARTS_CFLAGS)
xineplug_ao_out_directx_la_SOURCES = audio_directx_out.c
-xineplug_ao_out_directx_la_CPPFLAGS = $(DIRECTX_CPPFLAGS)
xineplug_ao_out_directx_la_LIBADD = $(DIRECTX_AUDIO_LIBS) $(XINE_LIB)
-xineplug_ao_out_directx_la_CFLAGS = $(VISIBILITY_FLAG)
-xineplug_ao_out_directx_la_LDFLAGS = -avoid-version -module
+xineplug_ao_out_directx_la_CPPFLAGS = $(AM_CPPFLAGS) $(DIRECTX_CPPFLAGS)
xineplug_ao_out_coreaudio_la_SOURCES = audio_coreaudio_out.c
xineplug_ao_out_coreaudio_la_LIBADD = $(XINE_LIB)
-# The "-Wl,-framework -Wl,..." is needed for libtool versions before
-# 1.5.x (1.257): the default version that ships with Mac OS X is 1.5 (1.1220)
-xineplug_ao_out_coreaudio_la_LDFLAGS = \
- -Wl,-framework -Wl,Cocoa -framework CoreAudio \
- -Wl,-framework -Wl,AudioUnit -framework AudioUnit \
- -avoid-version -module
-xineplug_ao_out_coreaudio_la_CFLAGS = -framework CoreAudio -framework AudioUnit $(VISIBILITY_FLAG)
+xineplug_ao_out_coreaudio_la_LDFLAGS = $(AM_LDFLAGS) -framework CoreAudio -framework AudioUnit
xineplug_ao_out_pulseaudio_la_SOURCES = audio_pulse_out.c
xineplug_ao_out_pulseaudio_la_LIBADD = $(PULSEAUDIO_LIBS) $(XINE_LIB)
-xineplug_ao_out_pulseaudio_la_CFLAGS = $(VISIBILITY_FLAG) $(PULSEAUDIO_CFLAGS)
-xineplug_ao_out_pulseaudio_la_LDFLAGS = -avoid-version -module
+xineplug_ao_out_pulseaudio_la_CFLAGS = $(AM_CFLAGS) $(PULSEAUDIO_CFLAGS)
xineplug_ao_out_directx2_la_SOURCES = audio_directx2_out.c
-xineplug_ao_out_directx2_la_CPPFLAGS = $(DIRECTX_CPPFLAGS)
+xineplug_ao_out_directx2_la_CPPFLAGS = $(AM_CPPFLAGS) $(DIRECTX_CPPFLAGS)
xineplug_ao_out_directx2_la_LIBADD = $(XINE_LIB) $(DIRECTX_AUDIO_LIBS) $(PTHREAD_LIBS)
-xineplug_ao_out_directx2_la_CFLAGS = $(VISIBILITY_FLAG)
-xineplug_ao_out_directx2_la_LDFLAGS = -avoid-version -module
xineplug_ao_out_fusionsound_la_SOURCES = audio_fusionsound_out.c
xineplug_ao_out_fusionsound_la_LIBADD = $(FUSIONSOUND_LIBS) $(XINE_LIB)
-xineplug_ao_out_fusionsound_la_CFLAGS = $(VISIBILITY_FLAG) $(FUSIONSOUND_CFLAGS)
-xineplug_ao_out_fusionsound_la_LDFLAGS = -avoid-version -module
+xineplug_ao_out_fusionsound_la_CFLAGS = $(AM_CFLAGS) $(FUSIONSOUND_CFLAGS)
xineplug_ao_out_jack_la_SOURCES = audio_jack_out.c
xineplug_ao_out_jack_la_LIBADD = $(JACK_LIBS) $(XINE_LIB)
-xineplug_ao_out_jack_la_CFLAGS = $(VISIBILITY_FLAG) $(JACK_CFLAGS)
-xineplug_ao_out_jack_la_LDFLAGS = -avoid-version -module
+xineplug_ao_out_jack_la_CFLAGS = $(AM_FLAGS) $(JACK_CFLAGS)
diff --git a/src/audio_out/audio_directx_out.c b/src/audio_out/audio_directx_out.c
index d2147ac52..d2147ac52 100644..100755
--- a/src/audio_out/audio_directx_out.c
+++ b/src/audio_out/audio_directx_out.c
diff --git a/src/combined/Makefile.am b/src/combined/Makefile.am
index 884fcf0cc..cf88795ba 100644
--- a/src/combined/Makefile.am
+++ b/src/combined/Makefile.am
@@ -1,21 +1,34 @@
include $(top_srcdir)/misc/Makefile.common
-if HAVE_WAVPACK
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+AM_LDFLAGS = $(xineplug_ldflags)
+
+if ENABLE_WAVPACK
xineplug_wavpack = xineplug_wavpack.la
endif
-if HAVE_LIBFLAC
+if ENABLE_LIBFLAC
xineplug_flac = xineplug_flac.la
endif
-xineplug_LTLIBRARIES = $(xineplug_wavpack) $(xineplug_flac)
+$(top_builddir)/contrib/nosefart/libnosefart.la:
+ $(MAKE) -C $(top_builddir)/contrib/nosefart
+
+xineplug_LTLIBRARIES = \
+ $(xineplug_wavpack) \
+ $(xineplug_flac) \
+ xineplug_nsf.la
-xineplug_wavpack_la_SOURCES = demux_wavpack.c decoder_wavpack.c combined_wavpack.c combined_wavpack.h
-xineplug_wavpack_la_CFLAGS = $(VISIBILITY_FLAG) $(WAVPACK_CFLAGS) -I$(srcdir)/../demuxers
+xineplug_wavpack_la_SOURCES = wavpack_demuxer.c wavpack_decoder.c wavpack_combined.c wavpack_combined.h
xineplug_wavpack_la_LIBADD = $(XINE_LIB) $(WAVPACK_LIBS)
-xineplug_wavpack_la_LDFLAGS = $(xineplug_ldflags)
+xineplug_wavpack_la_CFLAGS = $(AM_CFLAGS) $(WAVPACK_CFLAGS)
+xineplug_wavpack_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/src/demuxers
-xineplug_flac_la_SOURCES = demux_flac.c decoder_flac.c demux_flac.h
-xineplug_flac_la_CFLAGS = $(VISIBILITY_FLAG) $(LIBFLAC_CFLAGS)
+xineplug_flac_la_SOURCES = flac_demuxer.c flac_decoder.c
xineplug_flac_la_LIBADD = $(XINE_LIB) $(LIBFLAC_LIBS)
-xineplug_flac_la_LDFLAGS = $(xineplug_ldflags)
+xineplug_flac_la_CFLAGS = $(AM_CFLAGS) $(LIBFLAC_CFLAGS)
+
+xineplug_nsf_la_SOURCES = nsf_decoder.c nsf_demuxer.c nsf_combined.c
+xineplug_nsf_la_LIBADD = $(XINE_LIB) $(top_builddir)/contrib/nosefart/libnosefart.la -lm
+xineplug_nsf_la_CFLAGS = $(AM_CFLAGS) -fno-strict-aliasing
+xineplug_nsf_la_CPPFLAGS = $(AM_CPPFLAGS) -DNSF_PLAYER -I$(top_srcdir)/contrib/nosefart -I$(top_srcdir)/src/demuxers
diff --git a/src/combined/combined_wavpack.c b/src/combined/combined_wavpack.c
deleted file mode 100644
index 7a334b15c..000000000
--- a/src/combined/combined_wavpack.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2007 the xine project
- *
- * This file is part of xine, a free video player.
- *
- * xine 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.
- *
- * xine is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- *
- * xine interface to libwavpack by Diego Pettenò <flameeyes@gmail.com>
- *
- * $Id: combined_wavpack.c,v 1.3 2007/03/17 07:34:02 dgp85 Exp $
- */
-
-#include "xine_internal.h"
-#include "combined_wavpack.h"
-
-static const demuxer_info_t demux_info_wv = {
- 0 /* priority */
-};
-
-static uint32_t audio_types[] = {
- BUF_AUDIO_WAVPACK, 0
- };
-
-static const decoder_info_t decoder_info_wv = {
- audio_types, /* supported types */
- 7 /* priority */
-};
-
-const plugin_info_t xine_plugin_info[] EXPORTED = {
- /* type, API, "name", version, special_info, init_function */
- { PLUGIN_DEMUX, 26, "wavpack", XINE_VERSION_CODE, &demux_info_wv, demux_wv_init_plugin },
- { PLUGIN_AUDIO_DECODER, 15, "wavpackdec", XINE_VERSION_CODE, &decoder_info_wv, decoder_wavpack_init_plugin },
- { PLUGIN_NONE, 0, NULL, 0, NULL, NULL }
-};
diff --git a/src/combined/combined_wavpack.h b/src/combined/combined_wavpack.h
deleted file mode 100644
index b7bf32acb..000000000
--- a/src/combined/combined_wavpack.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2007 the xine project
- *
- * This file is part of xine, a free video player.
- *
- * xine 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.
- *
- * xine is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- *
- * xine interface to libwavpack by Diego Pettenò <flameeyes@gmail.com>
- *
- * $Id: combined_wavpack.h,v 1.3 2007/03/17 07:34:02 dgp85 Exp $
- */
-
-#include "os_types.h"
-
-typedef struct {
- uint32_t idcode; /* This should always be the string "wvpk" */
- uint32_t block_size; /* Size of the rest of the frame */
- uint16_t wv_version; /* Version of the wavpack, 0x0403 should be latest */
- uint8_t track; /* Unused, has to be 0 */
- uint8_t index; /* Unused, has to be 0 */
- uint32_t file_samples; /* (uint32_t)-1 if unknown, else the total number
- of samples for the file */
- uint32_t samples_index; /* Index of the first sample in block, from the
- start of the file */
- uint32_t samples_count; /* Count of samples in the current frame */
- uint32_t flags; /* Misc flags */
- uint32_t decoded_crc32; /* CRC32 of the decoded data */
-} __attribute__((packed)) wvheader_t;
-
-#ifdef WORDS_BIGENDIAN
-static const uint32_t wvpk_signature = ('k' + ('p' << 8) + ('v' << 16) + ('w' << 24));
-#else
-static const uint32_t wvpk_signature = ('w' + ('v' << 8) + ('p' << 16) + ('k' << 24));
-#endif
-
-void *demux_wv_init_plugin (xine_t *const xine, void *const data);
-void *decoder_wavpack_init_plugin (xine_t *xine, void *data);
diff --git a/src/combined/decoder_flac.c b/src/combined/decoder_flac.c
deleted file mode 100644
index 9b77cc27d..000000000
--- a/src/combined/decoder_flac.c
+++ /dev/null
@@ -1,435 +0,0 @@
-/*
- * Copyright (C) 2000-2003 the xine project
- *
- * This file is part of xine, a free video player.
- *
- * xine 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.
- *
- * xine is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- *
- * John McCutchan 2003
- * FLAC Decoder (http://flac.sf.net)
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <stdlib.h>
-#include <string.h>
-
-#include <FLAC/stream_decoder.h>
-
-#if !defined FLAC_API_VERSION_CURRENT || FLAC_API_VERSION_CURRENT < 8
-#include <FLAC/seekable_stream_decoder.h>
-#define LEGACY_FLAC
-#else
-#undef LEGACY_FLAC
-#endif
-
-#define LOG_MODULE "flac_decoder"
-#define LOG_VERBOSE
-
-/*
-#define LOG
-*/
-
-#include "xine_internal.h"
-#include "audio_out.h"
-#include "buffer.h"
-
-#include "demux_flac.h"
-
-typedef struct {
- audio_decoder_class_t decoder_class;
-} flac_class_t;
-
-typedef struct flac_decoder_s {
- audio_decoder_t audio_decoder;
-
- int64_t pts;
-
- int output_sampling_rate;
- int output_open;
- int output_mode;
-
- xine_stream_t *stream;
-
- FLAC__StreamDecoder *flac_decoder;
-
- int sample_rate;
- int bits_per_sample;
- int channels;
-
- unsigned char *buf;
- int buf_size;
- int buf_pos;
- int min_size;
-
-} flac_decoder_t;
-
-/*
- * FLAC callback functions
- */
-
-static FLAC__StreamDecoderReadStatus
-flac_read_callback (const FLAC__StreamDecoder *decoder,
- FLAC__byte buffer[],
- unsigned *bytes,
- void *client_data)
-{
- flac_decoder_t *this = (flac_decoder_t *)client_data;
- int number_of_bytes_to_copy;
-
- lprintf("flac_read_callback: %d\n", *bytes);
-
- if (this->buf_pos > *bytes)
- number_of_bytes_to_copy = *bytes;
- else
- number_of_bytes_to_copy = this->buf_pos;
-
- lprintf("number_of_bytes_to_copy: %d\n", number_of_bytes_to_copy);
-
- *bytes = number_of_bytes_to_copy;
-
- xine_fast_memcpy (buffer, this->buf, number_of_bytes_to_copy);
-
- this->buf_pos -= number_of_bytes_to_copy;
- memmove(this->buf, &this->buf[number_of_bytes_to_copy], this->buf_pos );
-
- if(number_of_bytes_to_copy)
- return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
- else
- return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
-}
-
-static FLAC__StreamDecoderWriteStatus
-flac_write_callback (const FLAC__StreamDecoder *decoder,
- const FLAC__Frame *frame,
- const FLAC__int32 *const buffer[],
- void *client_data)
-{
- flac_decoder_t *this = (flac_decoder_t *)client_data;
- audio_buffer_t *audio_buffer = NULL;
- int samples_left = frame->header.blocksize;
- int bytes_per_sample = (frame->header.bits_per_sample == 8)?1:2;
- int buf_samples;
- int8_t *data8;
- int16_t *data16;
- int i,j;
-
- lprintf("flac_write_callback\n");
-
- while( samples_left ) {
-
- audio_buffer = this->stream->audio_out->get_buffer(this->stream->audio_out);
-
- if( audio_buffer->mem_size < samples_left * frame->header.channels * bytes_per_sample )
- buf_samples = audio_buffer->mem_size / (frame->header.channels * bytes_per_sample);
- else
- buf_samples = samples_left;
-
-
- if( frame->header.bits_per_sample == 8 ) {
- data8 = (int8_t *)audio_buffer->mem;
-
- for( j=0; j < buf_samples; j++ )
- for( i=0; i < frame->header.channels; i++ )
- *data8++ = buffer[i][j];
-
- } else {
-
- data16 = (int16_t *)audio_buffer->mem;
-
- for( j=0; j < buf_samples; j++ )
- for( i=0; i < frame->header.channels; i++ )
- *data16++ = buffer[i][j];
- }
-
- audio_buffer->num_frames = buf_samples;
- audio_buffer->vpts = this->pts;
- this->pts = 0;
- this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream);
-
- samples_left -= buf_samples;
- }
- return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
-}
-
-static void
-flac_metadata_callback (const FLAC__StreamDecoder *decoder,
- const FLAC__StreamMetadata *metadata,
- void *client_data)
-{
- /* flac_decoder_t *this = (flac_decoder_t *)client_data; */
-
- lprintf("Metadata callback called!\n");
-
-#ifdef LOG
- if (metadata->type == FLAC__METADATA_TYPE_STREAMINFO) {
- printf("libflac: min_blocksize = %d\n", metadata->data.stream_info.min_blocksize);
- printf("libflac: max_blocksize = %d\n", metadata->data.stream_info.max_blocksize);
- printf("libflac: min_framesize = %d\n", metadata->data.stream_info.min_framesize);
- printf("libflac: max_framesize = %d\n", metadata->data.stream_info.max_framesize);
- /* does not work well:
- this->min_size = 2 * metadata->data.stream_info.max_blocksize; */
- }
-#endif
-
- return;
-}
-
-static void
-flac_error_callback (const FLAC__StreamDecoder *decoder,
- FLAC__StreamDecoderErrorStatus status,
- void *client_data)
-{
- /* This will be called if there is an error in the flac stream */
- lprintf("flac_error_callback\n");
-
-#ifdef LOG
- if (status == FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC)
- printf("libflac: Decoder lost synchronization.\n");
- else if (status == FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER)
- printf("libflac: Decoder encounted a corrupted frame header.\n");
- else if (status == FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH)
- printf("libflac: Frame's data did not match the CRC in the footer.\n");
- else
- printf("libflac: unknown error.\n");
-#endif
-
- return;
-}
-
-
-/*
- * FLAC plugin decoder
- */
-
-static void
-flac_reset (audio_decoder_t *this_gen)
-{
- flac_decoder_t *this = (flac_decoder_t *) this_gen;
-
- this->buf_pos = 0;
-
- if( FLAC__stream_decoder_get_state(this->flac_decoder) !=
- FLAC__STREAM_DECODER_SEARCH_FOR_METADATA )
- FLAC__stream_decoder_flush (this->flac_decoder);
-}
-
-static void
-flac_discontinuity (audio_decoder_t *this_gen)
-{
- flac_decoder_t *this = (flac_decoder_t *) this_gen;
-
- this->pts = 0;
-
- lprintf("Discontinuity!\n");
-}
-
-static void
-flac_decode_data (audio_decoder_t *this_gen, buf_element_t *buf)
-{
- flac_decoder_t *this = (flac_decoder_t *) this_gen;
- int ret = 1;
-
- /* We are getting the stream header, open up the audio
- * device, and collect information about the stream
- */
- if (buf->decoder_flags & BUF_FLAG_STDHEADER)
- {
- int mode = AO_CAP_MODE_MONO;
-
- this->sample_rate = buf->decoder_info[1];
- this->bits_per_sample = buf->decoder_info[2];
- this->channels = buf->decoder_info[3];
-
- mode = _x_ao_channels2mode(this->channels);
-
- if (!this->output_open)
- {
- this->output_open = this->stream->audio_out->open (
- this->stream->audio_out,
- this->stream,
- this->bits_per_sample,
- this->sample_rate,
- mode);
-
-
- }
- this->buf_pos = 0;
- } else if (this->output_open)
- {
- /* This isn't a header frame and we have opened the output device */
-
-
- /* What we have buffered so far, and what is coming in
- * is larger than our buffer
- */
- if (this->buf_pos + buf->size > this->buf_size)
- {
- this->buf_size += 2 * buf->size;
- this->buf = realloc (this->buf, this->buf_size);
- lprintf("reallocating buffer to %d\n", this->buf_size);
- }
-
- xine_fast_memcpy (&this->buf[this->buf_pos], buf->content, buf->size);
- this->buf_pos += buf->size;
-
- if (buf->pts)
- this->pts = buf->pts;
-
- /* We have enough to decode a frame */
- while( ret && this->buf_pos > this->min_size ) {
-
- FLAC__StreamDecoderState state = FLAC__stream_decoder_get_state(this->flac_decoder);
-
- if( state == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA ) {
- lprintf("process_until_end_of_metadata\n");
- ret = FLAC__stream_decoder_process_until_end_of_metadata (this->flac_decoder);
- } else if ( state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC ||
- state == FLAC__STREAM_DECODER_READ_FRAME ) {
- lprintf("process_single\n");
- ret = FLAC__stream_decoder_process_single (this->flac_decoder);
- } else {
- lprintf("aborted.\n");
- FLAC__stream_decoder_flush (this->flac_decoder);
- break;
- }
- }
- } else
- return;
-
-
-}
-
-static void
-flac_dispose (audio_decoder_t *this_gen) {
- flac_decoder_t *this = (flac_decoder_t *) this_gen;
-
- FLAC__stream_decoder_finish (this->flac_decoder);
-
- FLAC__stream_decoder_delete (this->flac_decoder);
-
- if (this->output_open)
- this->stream->audio_out->close (this->stream->audio_out, this->stream);
-
- if (this->buf)
- free(this->buf);
-
- free (this_gen);
-}
-
-static audio_decoder_t *
-open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) {
- flac_decoder_t *this ;
-
- this = (flac_decoder_t *) xine_xmalloc (sizeof (flac_decoder_t));
-
- this->audio_decoder.decode_data = flac_decode_data;
- this->audio_decoder.reset = flac_reset;
- this->audio_decoder.discontinuity = flac_discontinuity;
- this->audio_decoder.dispose = flac_dispose;
- this->stream = stream;
-
- this->output_open = 0;
- this->buf = NULL;
- this->buf_size = 0;
- this->min_size = 65536;
- this->pts = 0;
-
- this->flac_decoder = FLAC__stream_decoder_new();
-
-#ifdef LEGACY_FLAC
- FLAC__stream_decoder_set_read_callback (this->flac_decoder,
- flac_read_callback);
- FLAC__stream_decoder_set_write_callback (this->flac_decoder,
- flac_write_callback);
- FLAC__stream_decoder_set_metadata_callback (this->flac_decoder,
- flac_metadata_callback);
- FLAC__stream_decoder_set_error_callback (this->flac_decoder,
- flac_error_callback);
-
- FLAC__stream_decoder_set_client_data (this->flac_decoder, this);
-
- if (FLAC__stream_decoder_init (this->flac_decoder) != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA) {
- free (this);
- return NULL;
- }
-#else
- if ( FLAC__stream_decoder_init_stream (this->flac_decoder,
- flac_read_callback,
- NULL, /* seek */
- NULL, /* tell */
- NULL, /* length */
- NULL, /* eof */
- flac_write_callback,
- NULL, /* metadata */
- flac_error_callback,
- this
- ) != FLAC__STREAM_DECODER_INIT_STATUS_OK ) {
- free (this);
- return NULL;
- }
-#endif
-
- return (audio_decoder_t *) this;
-}
-
-/*
- * flac plugin class
- */
-
-static char *get_identifier (audio_decoder_class_t *this) {
- return "flacdec";
-}
-
-static char *get_description (audio_decoder_class_t *this) {
- return "flac audio decoder plugin";
-}
-
-static void dispose_class (audio_decoder_class_t *this) {
- free (this);
-}
-
-static void *
-init_plugin (xine_t *xine, void *data) {
- flac_class_t *this;
-
- this = (flac_class_t *) xine_xmalloc (sizeof (flac_class_t));
-
- this->decoder_class.open_plugin = open_plugin;
- this->decoder_class.get_identifier = get_identifier;
- this->decoder_class.get_description = get_description;
- this->decoder_class.dispose = dispose_class;
-
-
- return this;
-}
-
-static uint32_t audio_types[] = {
- BUF_AUDIO_FLAC, 0
- };
-
-static const decoder_info_t dec_info_audio = {
- audio_types, /* supported types */
- 5 /* priority */
-};
-
-const plugin_info_t xine_plugin_info[] EXPORTED = {
- /* type, API, "name", version, special_info, init_function */
- { PLUGIN_DEMUX, 26, "flac", XINE_VERSION_CODE, NULL, demux_flac_init_class },
- { PLUGIN_AUDIO_DECODER, 15, "flacdec", XINE_VERSION_CODE, &dec_info_audio, init_plugin },
- { PLUGIN_NONE, 0, "", 0, NULL, NULL }
-};
diff --git a/src/combined/decoder_wavpack.c b/src/combined/decoder_wavpack.c
deleted file mode 100644
index ec14dfbf5..000000000
--- a/src/combined/decoder_wavpack.c
+++ /dev/null
@@ -1,337 +0,0 @@
-/*
- * Copyright (C) 2007 the xine project
- *
- * This file is part of xine, a free video player.
- *
- * xine 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.
- *
- * xine is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- *
- * xine interface to libwavpack by Diego Pettenò <flameeyes@gmail.com>
- *
- * $Id: decoder_wavpack.c,v 1.14 2007/03/29 19:45:33 dgp85 Exp $
- */
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#define LOG_MODULE "decode_wavpack"
-#define LOG_VERBOSE
-
-#include "xine_internal.h"
-#include "attributes.h"
-#include "bswap.h"
-
-#include <wavpack/wavpack.h>
-#include "combined_wavpack.h"
-
-typedef struct {
- audio_decoder_class_t decoder_class;
-} wavpack_class_t;
-
-typedef struct {
- audio_decoder_t audio_decoder;
-
- xine_stream_t *stream;
-
- uint8_t *buf;
- size_t buf_size;
- size_t buf_pos;
-
- int sample_rate;
- uint16_t bits_per_sample:6;
- uint16_t channels:4;
-
- uint16_t output_open:1;
-
-} wavpack_decoder_t;
-
-/* Wrapper functions for Wavpack */
-static int32_t xine_buffer_read_bytes(void *const this_gen, void *const data,
- int32_t bcount) {
- wavpack_decoder_t *const this = (wavpack_decoder_t*)this_gen;
-
- if ( bcount <= 0 )
- return 0;
-
- if ( bcount > (this->buf_size - this->buf_pos) )
- bcount = (this->buf_size - this->buf_pos);
-
- xine_fast_memcpy(data, this->buf + this->buf_pos, bcount);
- this->buf_pos += bcount;
-
- return bcount;
-}
-
-static uint32_t xine_buffer_get_pos(void *const this_gen) {
- wavpack_decoder_t *const this = (wavpack_decoder_t*)this_gen;
- return this->buf_pos;
-}
-
-static int xine_buffer_set_pos_rel(void *const this_gen, const int32_t delta,
- const int mode) {
- wavpack_decoder_t *const this = (wavpack_decoder_t*)this_gen;
-
- switch(mode) {
- case SEEK_SET:
- if ( delta < 0 || delta > this->buf_size )
- return -1;
-
- this->buf_pos = delta;
- return 0;
- case SEEK_CUR:
- if ( (this->buf_pos+delta) < 0 || (this->buf_pos+delta) > this->buf_size )
- return -1;
-
- this->buf_pos += delta;
- return 0;
- case SEEK_END:
- if ( delta < 0 || delta > this->buf_size )
- return -1;
-
- this->buf_pos = this->buf_size - delta;
-
- return 0;
- }
-}
-
-static int xine_buffer_set_pos_abs(void *const this_gen, const uint32_t pos) {
- return xine_buffer_set_pos_rel(this_gen, pos, SEEK_SET);
-}
-
-static int xine_buffer_push_back_byte(void *const this_gen, const int c) {
- if ( ! xine_buffer_set_pos_rel(this_gen, -1, SEEK_CUR) )
- return EOF;
- return c;
-}
-
-static uint32_t xine_buffer_get_length(void *const this_gen) {
- wavpack_decoder_t *const this = (wavpack_decoder_t*)this_gen;
- return this->buf_size;
-}
-
-static int xine_buffer_can_seek(void *const this_gen) {
- return 1;
-}
-
-static int32_t xine_buffer_write_bytes(__attr_unused void *const id,
- __attr_unused void *const data,
- __attr_unused const int32_t bcount) {
- lprintf("xine_buffer_write_bytes: access is read-only.\n");
- return 0;
-}
-
-/* Wavpack plugin functions */
-static void wavpack_reset (audio_decoder_t *const this_gen)
-{
- wavpack_decoder_t *const this = (wavpack_decoder_t *) this_gen;
-
- this->buf_pos = 0;
-}
-
-static void wavpack_discontinuity (audio_decoder_t *const this_gen)
-{
- /* wavpack_decoder_t *this = (wavpack_decoder_t *) this_gen; */
-
- lprintf("Discontinuity!\n");
-}
-
-static void wavpack_decode_data (audio_decoder_t *const this_gen, buf_element_t *const buf)
-{
- wavpack_decoder_t *const this = (wavpack_decoder_t *) this_gen;
-
- /* We are getting the stream header, open up the audio
- * device, and collect information about the stream
- */
- if (buf->decoder_flags & BUF_FLAG_STDHEADER)
- {
- int mode = AO_CAP_MODE_MONO;
-
- this->sample_rate = buf->decoder_info[1];
- _x_assert(buf->decoder_info[2] <= 32);
- this->bits_per_sample = buf->decoder_info[2];
- _x_assert(buf->decoder_info[3] <= 8);
- this->channels = buf->decoder_info[3];
-
- mode = _x_ao_channels2mode(this->channels);
-
- _x_meta_info_set(this->stream, XINE_META_INFO_AUDIOCODEC,
- "WavPack");
-
- if (!this->output_open)
- {
- this->output_open = this->stream->audio_out->open (
- this->stream->audio_out,
- this->stream,
- this->bits_per_sample,
- this->sample_rate,
- mode) ? 1 : 0;
- }
- this->buf_pos = 0;
- } else if (this->output_open) {
- /* This isn't a header frame and we have opened the output device */
-
- /* What we have buffered so far, and what is coming in
- * is larger than our buffer
- */
- if (this->buf_pos + buf->size > this->buf_size)
- {
- this->buf_size += 2 * buf->size;
- this->buf = realloc (this->buf, this->buf_size);
- lprintf("reallocating buffer to %zd\n", this->buf_size);
- }
-
- xine_fast_memcpy (&this->buf[this->buf_pos], buf->content, buf->size);
- this->buf_pos += buf->size;
-
- if ( buf->decoder_flags & BUF_FLAG_FRAME_END ) {
- static WavpackStreamReader wavpack_buffer_reader = {
- .read_bytes = xine_buffer_read_bytes,
- .get_pos = xine_buffer_get_pos,
- .set_pos_abs = xine_buffer_set_pos_abs,
- .set_pos_rel = xine_buffer_set_pos_rel,
- .push_back_byte = xine_buffer_push_back_byte,
- .get_length = xine_buffer_get_length,
- .can_seek = xine_buffer_can_seek,
- .write_bytes = xine_buffer_write_bytes
- };
-
- WavpackContext *ctx = NULL;
- /* Current version of wavpack (4.40) does not write more than this */
- char error[256] = { 0, };
- int32_t samples_left; uint32_t samples_total;
- const wvheader_t *header = (const wvheader_t*)this->buf;
-
- this->buf_pos = 0;
-
- if ( le2me_32(header->samples_count) == 0 ) return;
-
- ctx = WavpackOpenFileInputEx(&wavpack_buffer_reader, this, NULL, error, OPEN_STREAMING, 0);
- if ( ! ctx ) {
- lprintf("unable to open the stream: %s\n", error);
- this->buf_pos = 0;
- return;
- }
-
- samples_left = samples_total = header->samples_count;
- while ( samples_left > 0 ) {
- uint32_t buf_samples, decoded_count;
- audio_buffer_t *audio_buffer = this->stream->audio_out->get_buffer(this->stream->audio_out);
- int32_t *decoded;
- int i;
-
- buf_samples = audio_buffer->mem_size / (this->channels * (this->bits_per_sample/8));
- if ( buf_samples > samples_left ) buf_samples = samples_left;
-
- decoded = alloca(buf_samples * this->channels * sizeof(int32_t));
-
- decoded_count = WavpackUnpackSamples(ctx, decoded, buf_samples);
- if ( decoded_count == 0 && *error ) {
- lprintf("Error during decode: %s\n", error);
- this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, NULL);
- break;
- }
-
- if ( decoded_count == 0 ) {
- lprintf("Finished decoding, but still %d samples left?\n", samples_left);
- this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, NULL);
- break;
- }
-
- lprintf("Decoded %d samples\n", buf_samples);
-
- samples_left -= decoded_count;
-
- audio_buffer->num_frames = decoded_count;
- audio_buffer->vpts = 0; /* TODO: Fix the pts calculation */
- // audio_buffer->vpts = (buf->pts * (samples_total-samples_left)) / samples_total;
- lprintf("Audio buffer with pts %"PRId64"\n", audio_buffer->vpts);
-
- switch(this->bits_per_sample) {
- case 8: {
- int8_t *data8 = (int8_t*)audio_buffer->mem;
- for(i = 0; i < decoded_count*this->channels; i++)
- data8[i] = decoded[i];
- }
- break;
- case 16: {
- int16_t *data16 = (int16_t*)audio_buffer->mem;
- for(i = 0; i < decoded_count*this->channels; i++)
- data16[i] = decoded[i];
- }
- }
-
- this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream);
- }
-
- WavpackCloseFile(ctx);
- this->buf_pos = 0;
- }
- }
-}
-
-static void wavpack_dispose (audio_decoder_t *this_gen) {
- wavpack_decoder_t *this = (wavpack_decoder_t *) this_gen;
-
- if (this->output_open)
- this->stream->audio_out->close (this->stream->audio_out, this->stream);
-
- free(this->buf);
-
- free (this_gen);
-}
-
-static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) {
- wavpack_decoder_t * const this = (wavpack_decoder_t *) xine_xmalloc (sizeof (wavpack_decoder_t));
-
- this->audio_decoder.decode_data = wavpack_decode_data;
- this->audio_decoder.reset = wavpack_reset;
- this->audio_decoder.discontinuity = wavpack_discontinuity;
- this->audio_decoder.dispose = wavpack_dispose;
- this->stream = stream;
-
- this->buf = NULL;
- this->buf_size = 0;
-
- return (audio_decoder_t *) this;
-}
-
-/*
- * wavpack plugin class
- */
-
-static char *get_identifier (audio_decoder_class_t *this) {
- return "wavpackdec";
-}
-
-static char *get_description (audio_decoder_class_t *this) {
- return "wavpack audio decoder plugin";
-}
-
-static void dispose_class (audio_decoder_class_t *this) {
- free (this);
-}
-
-void *decoder_wavpack_init_plugin (xine_t *xine, void *data) {
- wavpack_class_t *this;
-
- this = (wavpack_class_t *) xine_xmalloc (sizeof (wavpack_class_t));
-
- this->decoder_class.open_plugin = open_plugin;
- this->decoder_class.get_identifier = get_identifier;
- this->decoder_class.get_description = get_description;
- this->decoder_class.dispose = dispose_class;
-
- return this;
-}
diff --git a/src/combined/demux_flac.h b/src/combined/demux_flac.h
deleted file mode 100644
index 6086781d1..000000000
--- a/src/combined/demux_flac.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2000-2003 the xine project
- *
- * This file is part of xine, a free video player.
- *
- * xine 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.
- *
- * xine is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- *
- * $Id: demux_flac.h,v 1.2 2003/12/09 00:02:32 f1rmb Exp $
- */
-
-#ifndef HAVE_DEMUX_FLAC_H
-#define HAVE_DEMUX_FLAC_H
-
-void *demux_flac_init_class (xine_t *xine, void *data);
-
-#endif
diff --git a/src/combined/demux_wavpack.c b/src/combined/demux_wavpack.c
deleted file mode 100644
index 6a0e33e19..000000000
--- a/src/combined/demux_wavpack.c
+++ /dev/null
@@ -1,414 +0,0 @@
-/*
- * Copyright (C) 2006-2007 the xine project
- *
- * This file is part of xine, a free video player.
- *
- * xine 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.
- *
- * xine is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- *
- * xine interface to libwavpack by Diego Pettenò <flameeyes@gmail.com>
- *
- * $Id: demux_wavpack.c,v 1.11 2007/03/17 07:34:02 dgp85 Exp $
- */
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#define LOG_MODULE "demux_wavpack"
-#define LOG_VERBOSE
-
-#include "xine_internal.h"
-#include "xineutils.h"
-#include "demux.h"
-#include "bswap.h"
-#include "attributes.h"
-
-#include <wavpack/wavpack.h>
-#include "combined_wavpack.h"
-
-typedef struct {
- demux_plugin_t demux_plugin;
-
- xine_stream_t *stream;
- fifo_buffer_t *audio_fifo;
- input_plugin_t *input;
- int status;
-
- uint32_t current_sample;
- uint32_t samples;
- uint32_t samplerate;
- uint16_t bits_per_sample:6;
- uint16_t channels:4;
-} demux_wv_t;
-
-typedef struct {
- demux_class_t demux_class;
-} demux_wv_class_t;
-
-static int32_t xine_input_read_bytes(void *const this_gen, void *const data,
- const int32_t bcount) {
- input_plugin_t *const this = (input_plugin_t*)this_gen;
- return this->read(this, data, bcount);
-}
-
-static uint32_t xine_input_get_pos(void *const this_gen) {
- input_plugin_t *const this = (input_plugin_t*)this_gen;
- return this->get_current_pos(this);
-}
-
-static int xine_input_set_pos_abs(void *const this_gen, const uint32_t pos) {
- input_plugin_t *const this = (input_plugin_t*)this_gen;
- return this->seek(this, pos, SEEK_SET);
-}
-
-static int xine_input_set_pos_rel(void *const this_gen, const int32_t delta,
- const int mode) {
- input_plugin_t *const this = (input_plugin_t*)this_gen;
- return this->seek(this, delta, mode);
-}
-
-static int xine_input_push_back_byte(void *const this_gen, const int c) {
- input_plugin_t *const this = (input_plugin_t*)this_gen;
- if ( this->seek(this, -1, SEEK_CUR) ) {
- return c;
- } else {
- lprintf("xine_input_push_back_byte: unable to seek.\n");
- return EOF;
- }
-}
-
-static uint32_t xine_input_get_length(void *const this_gen) {
- input_plugin_t *const this = (input_plugin_t*)this_gen;
- return this->get_length(this);
-}
-
-static int xine_input_can_seek(void *const this_gen) {
- input_plugin_t *const this = (input_plugin_t*)this_gen;
- return INPUT_IS_SEEKABLE(this);
-}
-
-static int32_t xine_input_write_bytes(__attr_unused void *const id,
- __attr_unused void *const data,
- __attr_unused const int32_t bcount) {
- lprintf("xine_input_write_bytes: acces is read-only.\n");
- return 0;
-}
-
-static WavpackStreamReader wavpack_input_reader = {
- .read_bytes = xine_input_read_bytes,
- .get_pos = xine_input_get_pos,
- .set_pos_abs = xine_input_set_pos_abs,
- .set_pos_rel = xine_input_set_pos_rel,
- .push_back_byte = xine_input_push_back_byte,
- .get_length = xine_input_get_length,
- .can_seek = xine_input_can_seek,
- .write_bytes = xine_input_write_bytes
-};
-
-static int open_wv_file(demux_wv_t *const this) {
- WavpackContext *ctx = NULL;
- char error[256]; /* Current version of wavpack (4.31) does not write more than this */
- wvheader_t header;
- uint32_t tmp;
-
- /* Right now we don't support non-seekable streams */
- if (! INPUT_IS_SEEKABLE(this->input) ) {
- lprintf("open_wv_file: non-seekable inputs aren't supported yet.\n");
- return 0;
- }
-
- /* Read the file header */
- if (_x_demux_read_header(this->input, (uint8_t*)(&header), sizeof(wvheader_t)) != sizeof(wvheader_t))
- return 0;
-
- /* Validate header, we currently support only Wavpack 4 */
- if ( header.idcode != wvpk_signature || (le2me_16(header.wv_version) >> 8) != 4 )
- return 0;
-
- /* Rewind */
- this->input->seek(this->input, 0, SEEK_SET);
-
- ctx = WavpackOpenFileInputEx(&wavpack_input_reader, this->input, NULL, error, 0, 0);
- if ( ! ctx ) {
- lprintf("xine_open_wavpack_input: unable to open the stream: %s\n", error);
- return 0;
- }
-
- this->current_sample = 0;
- this->samples = WavpackGetNumSamples(ctx);
- lprintf("number of samples: %u\n", this->samples);
- this->samplerate = WavpackGetSampleRate(ctx);
- lprintf("samplerate: %u Hz\n", this->samplerate);
-
- tmp = WavpackGetBitsPerSample(ctx); _x_assert(tmp <= 32);
- lprintf("bits_per_sample: %u\n", tmp);
- this->bits_per_sample = tmp;
-
- tmp = WavpackGetNumChannels(ctx); _x_assert(tmp <= 8);
- lprintf("channels: %u\n", tmp);
- this->channels = tmp;
-
- _x_stream_info_set(this->stream, XINE_STREAM_INFO_HAS_AUDIO, 1);
- _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_FOURCC,
- wvpk_signature);
- _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_CHANNELS,
- this->channels);
- _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_SAMPLERATE,
- this->samplerate);
- _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITS,
- this->bits_per_sample);
-
- WavpackCloseFile(ctx);
- this->input->seek(this->input, SEEK_SET, 0);
-
- return 1;
-}
-
-static int demux_wv_send_chunk(demux_plugin_t *const this_gen) {
- demux_wv_t *const this = (demux_wv_t *) this_gen;
- uint32_t bytes_to_read; uint8_t header_sent = 0;
- wvheader_t header;
-
- lprintf("new frame\n");
-
- /* Check if we've finished */
- if (this->current_sample >= this->samples) {
- lprintf("all frames read\n");
- this->status = DEMUX_FINISHED;
- return this->status;
- }
-
- lprintf("current sample: %u\n", this->current_sample);
-
- do {
- if ( this->input->read(this->input, (uint8_t*)(&header), sizeof(wvheader_t)) != sizeof(wvheader_t) ) {
- this->status = DEMUX_FINISHED;
- return this->status;
- }
-
- /* The size of the block is «of course» minus 8, and
- it also includes the size of the header.
- */
- bytes_to_read = le2me_32(header.block_size) + 8 - sizeof(wvheader_t);
-
- lprintf("demux_wavpack: going to read %u bytes.\n", bytes_to_read);
-
- while(bytes_to_read) {
- off_t bytes_read = 0, bytes_to_read_now, offset = 0;
- buf_element_t *buf = NULL;
- int64_t input_time_guess;
-
- /* Get a buffer */
- buf = this->audio_fifo->buffer_pool_alloc(this->audio_fifo);
- buf->type = BUF_AUDIO_WAVPACK;
- buf->decoder_flags = 0;
-
- /* Set normalised position */
- buf->extra_info->input_normpos =
- (int) ((double) this->input->get_current_pos(this->input) * 65535 /
- this->input->get_length(this->input));
-
- buf->pts = (((this->current_sample) / this->samplerate))*90000;
- lprintf("Sending buffer with PTS %"PRId64"\n", buf->pts);
-
- /* Set time */
- input_time_guess = this->samples;
- input_time_guess /= this->samplerate;
- input_time_guess *= 1000;
- input_time_guess *= buf->extra_info->input_normpos;
- input_time_guess /= 65535;
- buf->extra_info->input_time = input_time_guess;
-
- bytes_to_read_now = ( bytes_to_read > buf->max_size ) ? buf->max_size : bytes_to_read;
- if ( ! header_sent ) {
- bytes_to_read_now -= (offset = sizeof(wvheader_t));
-
- header_sent = 1;
- xine_fast_memcpy(buf->content, &header, sizeof(wvheader_t));
- }
-
- bytes_read = this->input->read(this->input, &buf->content[offset], bytes_to_read_now);
-
- buf->size = offset + bytes_read;
-
- bytes_to_read -= bytes_read;
-
- if ( bytes_to_read <= 0 && (le2me_32(header.flags) & FINAL_BLOCK) == FINAL_BLOCK)
- buf->decoder_flags |= BUF_FLAG_FRAME_END;
-
- this->audio_fifo->put(this->audio_fifo, buf);
- }
- } while ( (le2me_32(header.flags) & FINAL_BLOCK) != FINAL_BLOCK );
-
- this->current_sample += le2me_32(header.samples_count);
-
- return this->status;
-}
-
-static void demux_wv_send_headers(demux_plugin_t *const this_gen) {
- demux_wv_t *const this = (demux_wv_t *) this_gen;
- buf_element_t *buf;
-
- this->audio_fifo = this->stream->audio_fifo;
-
- this->status = DEMUX_OK;
-
- /* Send start buffers */
- _x_demux_control_start(this->stream);
-
- /* Send header to decoder */
- if (this->audio_fifo) {
- buf = this->audio_fifo->buffer_pool_alloc (this->audio_fifo);
-
- buf->type = BUF_AUDIO_WAVPACK;
- buf->decoder_flags = BUF_FLAG_HEADER|BUF_FLAG_STDHEADER|BUF_FLAG_FRAME_END;
- buf->decoder_info[0] = this->input->get_length(this->input);
- buf->decoder_info[1] = this->samplerate;
- buf->decoder_info[2] = this->bits_per_sample;
- buf->decoder_info[3] = this->channels;
-
- buf->size = 0;
-
- this->audio_fifo->put (this->audio_fifo, buf);
- }
-}
-
-static int demux_wv_seek (demux_plugin_t *this_gen,
- off_t start_pos, int start_time, int playing) {
- demux_wv_t *const this = (demux_wv_t *) this_gen;
-
- /* If thread is not running, initialize demuxer */
- if( !playing ) {
-
- /* send new pts */
- _x_demux_control_newpts(this->stream, 0, 0);
-
- this->status = DEMUX_OK;
-
- }
-
- return this->status;
-}
-
-static void demux_wv_dispose (demux_plugin_t *const this_gen) {
- demux_wv_t *const this = (demux_wv_t *) this_gen;
-
- free(this);
-}
-
-static int demux_wv_get_status (demux_plugin_t *const this_gen) {
- const demux_wv_t *const this = (const demux_wv_t *) this_gen;
-
- return this->status;
-}
-
-static int demux_wv_get_stream_length (demux_plugin_t *const this_gen) {
- const demux_wv_t *const this = (demux_wv_t *) this_gen;
-
- return (this->samples*1000) / this->samplerate;
-}
-
-static uint32_t demux_wv_get_capabilities(demux_plugin_t *const this_gen) {
- return DEMUX_CAP_NOCAP;
-}
-
-static int demux_wv_get_optional_data(demux_plugin_t *const this_gen,
- void *data, const int data_type) {
- return DEMUX_OPTIONAL_UNSUPPORTED;
-}
-
-static demux_plugin_t *open_plugin (demux_class_t *const class_gen,
- xine_stream_t *const stream,
- input_plugin_t *const input) {
- demux_wv_t *const this = xine_xmalloc (sizeof (demux_wv_t));
- this->stream = stream;
- this->input = input;
-
- this->demux_plugin.send_headers = demux_wv_send_headers;
- this->demux_plugin.send_chunk = demux_wv_send_chunk;
- this->demux_plugin.seek = demux_wv_seek;
- this->demux_plugin.dispose = demux_wv_dispose;
- this->demux_plugin.get_status = demux_wv_get_status;
- this->demux_plugin.get_stream_length = demux_wv_get_stream_length;
- this->demux_plugin.get_capabilities = demux_wv_get_capabilities;
- this->demux_plugin.get_optional_data = demux_wv_get_optional_data;
- this->demux_plugin.demux_class = class_gen;
-
- this->status = DEMUX_FINISHED;
- switch (stream->content_detection_method) {
-
- case METHOD_BY_EXTENSION: {
- const char *const mrl = input->get_mrl (input);
- const char *const extensions = class_gen->get_extensions (class_gen);
-
- if (!_x_demux_check_extension (mrl, extensions)) {
- free (this);
- return NULL;
- }
- }
- /* Falling through is intended */
-
- case METHOD_BY_CONTENT:
- case METHOD_EXPLICIT:
-
- if (!open_wv_file(this)) {
- free (this);
- return NULL;
- }
-
- break;
-
- default:
- free (this);
- return NULL;
- }
-
- return &this->demux_plugin;
-}
-
-static const char *get_description (demux_class_t *const this_gen) {
- return "Wavpack demux plugin";
-}
-
-static const char *get_identifier (demux_class_t *const this_gen) {
- return "Wavpack";
-}
-
-static const char *get_extensions (demux_class_t *const this_gen) {
- return "wv";
-}
-
-static const char *get_mimetypes (demux_class_t *const this_gen) {
- return NULL;
-}
-
-static void class_dispose (demux_class_t *const this_gen) {
- demux_wv_class_t *const this = (demux_wv_class_t *) this_gen;
-
- free (this);
-}
-
-void *demux_wv_init_plugin (xine_t *const xine, void *const data) {
- demux_wv_class_t *const this = xine_xmalloc (sizeof (demux_wv_class_t));
-
- this->demux_class.open_plugin = open_plugin;
- this->demux_class.get_description = get_description;
- this->demux_class.get_identifier = get_identifier;
- this->demux_class.get_mimetypes = get_mimetypes;
- this->demux_class.get_extensions = get_extensions;
- this->demux_class.dispose = class_dispose;
-
- return this;
-}
diff --git a/src/combined/flac_decoder.c b/src/combined/flac_decoder.c
new file mode 100644
index 000000000..babfde6ae
--- /dev/null
+++ b/src/combined/flac_decoder.c
@@ -0,0 +1,426 @@
+/*
+ * Copyright (C) 2000-2003 the xine project
+ *
+ * This file is part of xine, a free video player.
+ *
+ * xine 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.
+ *
+ * xine is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * John McCutchan 2003
+ * FLAC Decoder (http://flac.sf.net)
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <FLAC/stream_decoder.h>
+
+#if !defined FLAC_API_VERSION_CURRENT || FLAC_API_VERSION_CURRENT < 8
+#include <FLAC/seekable_stream_decoder.h>
+#define LEGACY_FLAC
+#else
+#undef LEGACY_FLAC
+#endif
+
+#define LOG_MODULE "flac_decoder"
+#define LOG_VERBOSE
+
+/*
+#define LOG
+*/
+
+#include "xine_internal.h"
+#include "audio_out.h"
+#include "buffer.h"
+
+typedef struct {
+ audio_decoder_class_t decoder_class;
+} flac_class_t;
+
+typedef struct flac_decoder_s {
+ audio_decoder_t audio_decoder;
+
+ int64_t pts;
+
+ xine_stream_t *stream;
+
+ FLAC__StreamDecoder *flac_decoder;
+
+ unsigned char *buf;
+ int buf_size;
+ int buf_pos;
+ int min_size;
+
+ int output_open;
+
+} flac_decoder_t;
+
+/*
+ * FLAC callback functions
+ */
+
+static FLAC__StreamDecoderReadStatus
+flac_read_callback (const FLAC__StreamDecoder *decoder,
+ FLAC__byte buffer[],
+ unsigned *bytes,
+ void *client_data)
+{
+ flac_decoder_t *this = (flac_decoder_t *)client_data;
+ int number_of_bytes_to_copy;
+
+ lprintf("flac_read_callback: %d\n", *bytes);
+
+ if (this->buf_pos > *bytes)
+ number_of_bytes_to_copy = *bytes;
+ else
+ number_of_bytes_to_copy = this->buf_pos;
+
+ lprintf("number_of_bytes_to_copy: %d\n", number_of_bytes_to_copy);
+
+ *bytes = number_of_bytes_to_copy;
+
+ xine_fast_memcpy (buffer, this->buf, number_of_bytes_to_copy);
+
+ this->buf_pos -= number_of_bytes_to_copy;
+ memmove(this->buf, &this->buf[number_of_bytes_to_copy], this->buf_pos );
+
+ if(number_of_bytes_to_copy)
+ return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
+ else
+ return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
+}
+
+static FLAC__StreamDecoderWriteStatus
+flac_write_callback (const FLAC__StreamDecoder *decoder,
+ const FLAC__Frame *frame,
+ const FLAC__int32 *const buffer[],
+ void *client_data)
+{
+ flac_decoder_t *this = (flac_decoder_t *)client_data;
+ audio_buffer_t *audio_buffer = NULL;
+ int samples_left = frame->header.blocksize;
+ int bytes_per_sample = (frame->header.bits_per_sample == 8)?1:2;
+ int buf_samples;
+ int8_t *data8;
+ int16_t *data16;
+ int i,j;
+
+ lprintf("flac_write_callback\n");
+
+ while( samples_left ) {
+
+ audio_buffer = this->stream->audio_out->get_buffer(this->stream->audio_out);
+
+ if( audio_buffer->mem_size < samples_left * frame->header.channels * bytes_per_sample )
+ buf_samples = audio_buffer->mem_size / (frame->header.channels * bytes_per_sample);
+ else
+ buf_samples = samples_left;
+
+
+ if( frame->header.bits_per_sample == 8 ) {
+ data8 = (int8_t *)audio_buffer->mem;
+
+ for( j=0; j < buf_samples; j++ )
+ for( i=0; i < frame->header.channels; i++ )
+ *data8++ = buffer[i][j];
+
+ } else {
+
+ data16 = (int16_t *)audio_buffer->mem;
+
+ for( j=0; j < buf_samples; j++ )
+ for( i=0; i < frame->header.channels; i++ )
+ *data16++ = buffer[i][j];
+ }
+
+ audio_buffer->num_frames = buf_samples;
+ audio_buffer->vpts = this->pts;
+ this->pts = 0;
+ this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream);
+
+ samples_left -= buf_samples;
+ }
+ return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
+}
+
+static void
+flac_metadata_callback (const FLAC__StreamDecoder *decoder,
+ const FLAC__StreamMetadata *metadata,
+ void *client_data)
+{
+ /* flac_decoder_t *this = (flac_decoder_t *)client_data; */
+
+ lprintf("Metadata callback called!\n");
+
+#ifdef LOG
+ if (metadata->type == FLAC__METADATA_TYPE_STREAMINFO) {
+ printf("libflac: min_blocksize = %d\n", metadata->data.stream_info.min_blocksize);
+ printf("libflac: max_blocksize = %d\n", metadata->data.stream_info.max_blocksize);
+ printf("libflac: min_framesize = %d\n", metadata->data.stream_info.min_framesize);
+ printf("libflac: max_framesize = %d\n", metadata->data.stream_info.max_framesize);
+ /* does not work well:
+ this->min_size = 2 * metadata->data.stream_info.max_blocksize; */
+ }
+#endif
+
+ return;
+}
+
+static void
+flac_error_callback (const FLAC__StreamDecoder *decoder,
+ FLAC__StreamDecoderErrorStatus status,
+ void *client_data)
+{
+ /* This will be called if there is an error in the flac stream */
+ lprintf("flac_error_callback\n");
+
+#ifdef LOG
+ if (status == FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC)
+ printf("libflac: Decoder lost synchronization.\n");
+ else if (status == FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER)
+ printf("libflac: Decoder encounted a corrupted frame header.\n");
+ else if (status == FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH)
+ printf("libflac: Frame's data did not match the CRC in the footer.\n");
+ else
+ printf("libflac: unknown error.\n");
+#endif
+
+ return;
+}
+
+
+/*
+ * FLAC plugin decoder
+ */
+
+static void
+flac_reset (audio_decoder_t *this_gen)
+{
+ flac_decoder_t *this = (flac_decoder_t *) this_gen;
+
+ this->buf_pos = 0;
+
+ if( FLAC__stream_decoder_get_state(this->flac_decoder) !=
+ FLAC__STREAM_DECODER_SEARCH_FOR_METADATA )
+ FLAC__stream_decoder_flush (this->flac_decoder);
+}
+
+static void
+flac_discontinuity (audio_decoder_t *this_gen)
+{
+ flac_decoder_t *this = (flac_decoder_t *) this_gen;
+
+ this->pts = 0;
+
+ lprintf("Discontinuity!\n");
+}
+
+static void
+flac_decode_data (audio_decoder_t *this_gen, buf_element_t *buf)
+{
+ flac_decoder_t *this = (flac_decoder_t *) this_gen;
+ int ret = 1;
+
+ /* We are getting the stream header, open up the audio
+ * device, and collect information about the stream
+ */
+ if (buf->decoder_flags & BUF_FLAG_STDHEADER)
+ {
+ const int sample_rate = buf->decoder_info[1];
+ const int bits_per_sample = buf->decoder_info[2];
+ const int channels = buf->decoder_info[3];
+ const int mode = _x_ao_channels2mode(channels);
+
+ if (!this->output_open)
+ {
+ this->output_open = this->stream->audio_out->open (
+ this->stream->audio_out,
+ this->stream,
+ bits_per_sample,
+ sample_rate,
+ mode);
+
+
+ }
+ this->buf_pos = 0;
+ } else if (this->output_open)
+ {
+ /* This isn't a header frame and we have opened the output device */
+
+
+ /* What we have buffered so far, and what is coming in
+ * is larger than our buffer
+ */
+ if (this->buf_pos + buf->size > this->buf_size)
+ {
+ this->buf_size += 2 * buf->size;
+ this->buf = realloc (this->buf, this->buf_size);
+ lprintf("reallocating buffer to %d\n", this->buf_size);
+ }
+
+ xine_fast_memcpy (&this->buf[this->buf_pos], buf->content, buf->size);
+ this->buf_pos += buf->size;
+
+ if (buf->pts)
+ this->pts = buf->pts;
+
+ /* We have enough to decode a frame */
+ while( ret && this->buf_pos > this->min_size ) {
+
+ FLAC__StreamDecoderState state = FLAC__stream_decoder_get_state(this->flac_decoder);
+
+ if( state == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA ) {
+ lprintf("process_until_end_of_metadata\n");
+ ret = FLAC__stream_decoder_process_until_end_of_metadata (this->flac_decoder);
+ } else if ( state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC ||
+ state == FLAC__STREAM_DECODER_READ_FRAME ) {
+ lprintf("process_single\n");
+ ret = FLAC__stream_decoder_process_single (this->flac_decoder);
+ } else {
+ lprintf("aborted.\n");
+ FLAC__stream_decoder_flush (this->flac_decoder);
+ break;
+ }
+ }
+ } else
+ return;
+
+
+}
+
+static void
+flac_dispose (audio_decoder_t *this_gen) {
+ flac_decoder_t *this = (flac_decoder_t *) this_gen;
+
+ FLAC__stream_decoder_finish (this->flac_decoder);
+
+ FLAC__stream_decoder_delete (this->flac_decoder);
+
+ if (this->output_open)
+ this->stream->audio_out->close (this->stream->audio_out, this->stream);
+
+ if (this->buf)
+ free(this->buf);
+
+ free (this_gen);
+}
+
+static audio_decoder_t *
+open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) {
+ flac_decoder_t *this ;
+
+ this = (flac_decoder_t *) xine_xmalloc (sizeof (flac_decoder_t));
+
+ this->audio_decoder.decode_data = flac_decode_data;
+ this->audio_decoder.reset = flac_reset;
+ this->audio_decoder.discontinuity = flac_discontinuity;
+ this->audio_decoder.dispose = flac_dispose;
+ this->stream = stream;
+
+ this->output_open = 0;
+ this->buf = NULL;
+ this->buf_size = 0;
+ this->min_size = 65536;
+ this->pts = 0;
+
+ this->flac_decoder = FLAC__stream_decoder_new();
+
+#ifdef LEGACY_FLAC
+ FLAC__stream_decoder_set_read_callback (this->flac_decoder,
+ flac_read_callback);
+ FLAC__stream_decoder_set_write_callback (this->flac_decoder,
+ flac_write_callback);
+ FLAC__stream_decoder_set_metadata_callback (this->flac_decoder,
+ flac_metadata_callback);
+ FLAC__stream_decoder_set_error_callback (this->flac_decoder,
+ flac_error_callback);
+
+ FLAC__stream_decoder_set_client_data (this->flac_decoder, this);
+
+ if (FLAC__stream_decoder_init (this->flac_decoder) != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA) {
+ free (this);
+ return NULL;
+ }
+#else
+ if ( FLAC__stream_decoder_init_stream (this->flac_decoder,
+ flac_read_callback,
+ NULL, /* seek */
+ NULL, /* tell */
+ NULL, /* length */
+ NULL, /* eof */
+ flac_write_callback,
+ NULL, /* metadata */
+ flac_error_callback,
+ this
+ ) != FLAC__STREAM_DECODER_INIT_STATUS_OK ) {
+ free (this);
+ return NULL;
+ }
+#endif
+
+ return (audio_decoder_t *) this;
+}
+
+/*
+ * flac plugin class
+ */
+
+static char *get_identifier (audio_decoder_class_t *this) {
+ return "flacdec";
+}
+
+static char *get_description (audio_decoder_class_t *this) {
+ return "flac audio decoder plugin";
+}
+
+static void dispose_class (audio_decoder_class_t *this) {
+ free (this);
+}
+
+static void *
+init_plugin (xine_t *xine, void *data) {
+ flac_class_t *this;
+
+ this = (flac_class_t *) xine_xmalloc (sizeof (flac_class_t));
+
+ this->decoder_class.open_plugin = open_plugin;
+ this->decoder_class.get_identifier = get_identifier;
+ this->decoder_class.get_description = get_description;
+ this->decoder_class.dispose = dispose_class;
+
+
+ return this;
+}
+
+void *demux_flac_init_class (xine_t *xine, void *data);
+
+static uint32_t audio_types[] = {
+ BUF_AUDIO_FLAC, 0
+ };
+
+static const decoder_info_t dec_info_audio = {
+ audio_types, /* supported types */
+ 5 /* priority */
+};
+
+const plugin_info_t xine_plugin_info[] EXPORTED = {
+ /* type, API, "name", version, special_info, init_function */
+ { PLUGIN_DEMUX, 26, "flac", XINE_VERSION_CODE, NULL, demux_flac_init_class },
+ { PLUGIN_AUDIO_DECODER, 15, "flacdec", XINE_VERSION_CODE, &dec_info_audio, init_plugin },
+ { PLUGIN_NONE, 0, "", 0, NULL, NULL }
+};
diff --git a/src/combined/demux_flac.c b/src/combined/flac_demuxer.c
index 43ee17d5c..43ee17d5c 100644
--- a/src/combined/demux_flac.c
+++ b/src/combined/flac_demuxer.c
diff --git a/src/combined/nsf_combined.c b/src/combined/nsf_combined.c
new file mode 100644
index 000000000..855b8d2a5
--- /dev/null
+++ b/src/combined/nsf_combined.c
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2007 the xine project
+ *
+ * This file is part of xine, a free video player.
+ *
+ * xine 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.
+ *
+ * xine is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * $Id: combined_wavpack.c,v 1.3 2007/03/17 07:34:02 dgp85 Exp $
+ */
+
+#include "xine_internal.h"
+
+void *decoder_nsf_init_plugin (xine_t *xine, void *data);
+void *demux_nsf_init_plugin (xine_t *xine, void *data);
+
+static const demuxer_info_t demux_info_nsf = {
+ 10 /* priority */
+};
+
+static uint32_t audio_types[] = {
+ BUF_AUDIO_NSF,
+ 0
+};
+
+static const decoder_info_t decoder_info_nsf = {
+ audio_types, /* supported types */
+ 5 /* priority */
+};
+
+const plugin_info_t xine_plugin_info[] EXPORTED = {
+ { PLUGIN_DEMUX, 26, "nsfdemux", XINE_VERSION_CODE, &demux_info_nsf, demux_nsf_init_plugin },
+ { PLUGIN_AUDIO_DECODER, 15, "nsfdec", XINE_VERSION_CODE, &decoder_info_nsf, decoder_nsf_init_plugin },
+ { PLUGIN_NONE, 0, NULL, 0, NULL, NULL }
+};
diff --git a/src/combined/nsf_decoder.c b/src/combined/nsf_decoder.c
new file mode 100644
index 000000000..e8b5dd96a
--- /dev/null
+++ b/src/combined/nsf_decoder.c
@@ -0,0 +1,268 @@
+/*
+ * Copyright (C) 2000-2001 the xine project
+ *
+ * This file is part of xine, a free video player.
+ *
+ * xine 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.
+ *
+ * xine is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * NSF Audio "Decoder" using the Nosefart NSF engine by Matt Conte
+ * http://www.baisoku.org/
+ *
+ * $Id: nsf.c,v 1.13 2006/09/25 23:56:31 dgp85 Exp $
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "xine_internal.h"
+#include "audio_out.h"
+#include "buffer.h"
+#include "xineutils.h"
+#include "bswap.h"
+
+/* Nosefart includes */
+#include "types.h"
+#include "nsf.h"
+
+typedef struct {
+ audio_decoder_class_t decoder_class;
+} nsf_class_t;
+
+typedef struct nsf_decoder_s {
+ audio_decoder_t audio_decoder;
+
+ xine_stream_t *stream;
+
+ int sample_rate; /* audio sample rate */
+ int bits_per_sample; /* bits/sample, usually 8 or 16 */
+ int channels; /* 1 or 2, usually */
+
+ int output_open; /* flag to indicate audio is ready */
+
+ int nsf_size;
+ unsigned char *nsf_file;
+ int nsf_index;
+ int song_number;
+
+ /* nsf-specific variables */
+ int64_t last_pts;
+ unsigned int iteration;
+
+ nsf_t *nsf;
+} nsf_decoder_t;
+
+/**************************************************************************
+ * xine audio plugin functions
+ *************************************************************************/
+
+static void nsf_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) {
+
+ nsf_decoder_t *this = (nsf_decoder_t *) this_gen;
+ audio_buffer_t *audio_buffer;
+
+ if (buf->decoder_flags & BUF_FLAG_HEADER) {
+
+ /* When the engine sends a BUF_FLAG_HEADER flag, it is time to initialize
+ * the decoder. The buffer element type has 4 decoder_info fields,
+ * 0..3. Field 1 is the sample rate. Field 2 is the bits/sample. Field
+ * 3 is the number of channels. */
+ this->sample_rate = buf->decoder_info[1];
+ this->bits_per_sample = buf->decoder_info[2];
+ this->channels = buf->decoder_info[3];
+
+ /* take this opportunity to initialize stream/meta information */
+ _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC,
+ "NES Music (Nosefart)");
+
+ this->song_number = buf->content[4];
+ /* allocate a buffer for the file */
+ this->nsf_size = BE_32(&buf->content[0]);
+ this->nsf_file = xine_xmalloc(this->nsf_size);
+ this->nsf_index = 0;
+
+ /* peform any other required initialization */
+ this->last_pts = -1;
+ this->iteration = 0;
+
+ return;
+ }
+
+ /* accumulate chunks from the NSF file until whole file is received */
+ if (this->nsf_index < this->nsf_size) {
+ xine_fast_memcpy(&this->nsf_file[this->nsf_index], buf->content,
+ buf->size);
+ this->nsf_index += buf->size;
+
+ if (this->nsf_index == this->nsf_size) {
+ /* file has been received, proceed to initialize engine */
+ nsf_init();
+ this->nsf = nsf_load(NULL, this->nsf_file, this->nsf_size);
+ if (!this->nsf) {
+ xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "nsf: could not initialize NSF\n");
+ /* make the decoder return on every subsequent buffer */
+ this->nsf_index = 0;
+ return;
+ }
+ this->nsf->current_song = this->song_number;
+ nsf_playtrack(this->nsf, this->nsf->current_song, this->sample_rate,
+ this->bits_per_sample, this->channels);
+ }
+ return;
+ }
+
+ /* if the audio output is not open yet, open the audio output */
+ if (!this->output_open) {
+ this->output_open = this->stream->audio_out->open(
+ this->stream->audio_out,
+ this->stream,
+ this->bits_per_sample,
+ this->sample_rate,
+ _x_ao_channels2mode(this->channels));
+ }
+
+ /* if the audio still isn't open, do not go any further with the decode */
+ if (!this->output_open)
+ return;
+
+ /* check if a song change was requested */
+ if (buf->decoder_info[1]) {
+ this->nsf->current_song = buf->decoder_info[1];
+ nsf_playtrack(this->nsf, this->nsf->current_song, this->sample_rate,
+ this->bits_per_sample, this->channels);
+ }
+
+ /* time to decode a frame */
+ if (this->last_pts != -1) {
+
+ /* process a frame */
+ nsf_frame(this->nsf);
+
+ /* get an audio buffer */
+ audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out);
+ if (audio_buffer->mem_size == 0) {
+ xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "nsf: Help! Allocated audio buffer with nothing in it!\n");
+ return;
+ }
+
+ apu_process(audio_buffer->mem, this->sample_rate / this->nsf->playback_rate);
+ audio_buffer->vpts = buf->pts;
+ audio_buffer->num_frames = this->sample_rate / this->nsf->playback_rate;
+ this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream);
+ }
+ this->last_pts = buf->pts;
+}
+
+/* This function resets the state of the audio decoder. This usually
+ * entails resetting the data accumulation buffer. */
+static void nsf_reset (audio_decoder_t *this_gen) {
+
+ nsf_decoder_t *this = (nsf_decoder_t *) this_gen;
+
+ this->last_pts = -1;
+}
+
+/* This function resets the last pts value of the audio decoder. */
+static void nsf_discontinuity (audio_decoder_t *this_gen) {
+
+ nsf_decoder_t *this = (nsf_decoder_t *) this_gen;
+
+ this->last_pts = -1;
+}
+
+/* This function closes the audio output and frees the private audio decoder
+ * structure. */
+static void nsf_dispose (audio_decoder_t *this_gen) {
+
+ nsf_decoder_t *this = (nsf_decoder_t *) this_gen;
+
+ /* close the audio output */
+ if (this->output_open)
+ this->stream->audio_out->close (this->stream->audio_out, this->stream);
+ this->output_open = 0;
+
+ /* free anything that was allocated during operation */
+ nsf_free(&this->nsf);
+ free(this->nsf_file);
+ free(this);
+}
+
+/* This function allocates, initializes, and returns a private audio
+ * decoder structure. */
+static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) {
+
+ nsf_decoder_t *this ;
+
+ this = (nsf_decoder_t *) xine_xmalloc (sizeof (nsf_decoder_t));
+
+ /* connect the member functions */
+ this->audio_decoder.decode_data = nsf_decode_data;
+ this->audio_decoder.reset = nsf_reset;
+ this->audio_decoder.discontinuity = nsf_discontinuity;
+ this->audio_decoder.dispose = nsf_dispose;
+
+ /* connect the stream */
+ this->stream = stream;
+
+ /* audio output is not open at the start */
+ this->output_open = 0;
+
+ /* initialize the basic audio parameters */
+ this->channels = 0;
+ this->sample_rate = 0;
+ this->bits_per_sample = 0;
+
+ /* return the newly-initialized audio decoder */
+ return &this->audio_decoder;
+}
+
+/* This function returns a brief string that describes (usually with the
+ * decoder's most basic name) the audio decoder plugin. */
+static char *get_identifier (audio_decoder_class_t *this) {
+ return "NSF";
+}
+
+/* This function returns a slightly longer string describing the audio
+ * decoder plugin. */
+static char *get_description (audio_decoder_class_t *this) {
+ return "NES Music audio decoder plugin";
+}
+
+/* This function frees the audio decoder class and any other memory that was
+ * allocated. */
+static void dispose_class (audio_decoder_class_t *this_gen) {
+
+ nsf_class_t *this = (nsf_class_t *)this_gen;
+
+ free (this);
+}
+
+/* This function allocates a private audio decoder class and initializes
+ * the class's member functions. */
+void *decoder_nsf_init_plugin (xine_t *xine, void *data) {
+
+ nsf_class_t *this ;
+
+ this = (nsf_class_t *) xine_xmalloc (sizeof (nsf_class_t));
+
+ this->decoder_class.open_plugin = open_plugin;
+ this->decoder_class.get_identifier = get_identifier;
+ this->decoder_class.get_description = get_description;
+ this->decoder_class.dispose = dispose_class;
+
+ return this;
+}
diff --git a/src/combined/nsf_demuxer.c b/src/combined/nsf_demuxer.c
new file mode 100644
index 000000000..b598b9e1c
--- /dev/null
+++ b/src/combined/nsf_demuxer.c
@@ -0,0 +1,391 @@
+/*
+ * Copyright (C) 2000-2003 the xine project
+ *
+ * This file is part of xine, a free video player.
+ *
+ * xine 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.
+ *
+ * xine is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+/*
+ * NSF File "Demuxer" by Mike Melanson (melanson@pcisys.net)
+ * This is really just a loader for NES Music File Format (extension NSF)
+ * which loads an entire NSF file and passes it over to the NSF audio
+ * decoder.
+ *
+ * After the file is sent over, the demuxer controls the playback by
+ * sending empty buffers with incrementing pts values.
+ *
+ * For more information regarding the NSF format, visit:
+ * http://www.tripoint.org/kevtris/nes/nsfspec.txt
+ *
+ * $Id: demux_nsf.c,v 1.24 2007/03/29 17:03:06 dgp85 Exp $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+
+/********** logging **********/
+#define LOG_MODULE "demux_nsf"
+/* #define LOG_VERBOSE */
+/* #define LOG */
+
+#include "xine_internal.h"
+#include "xineutils.h"
+#include "compat.h"
+#include "demux.h"
+#include "bswap.h"
+
+#define NSF_HEADER_SIZE 0x80
+#define NSF_SAMPLERATE 44100
+#define NSF_BITS 8
+#define NSF_CHANNELS 1
+#define NSF_REFRESH_RATE 60
+#define NSF_PTS_INC (90000 / NSF_REFRESH_RATE)
+
+typedef struct {
+ demux_plugin_t demux_plugin;
+
+ xine_stream_t *stream;
+ fifo_buffer_t *video_fifo;
+ fifo_buffer_t *audio_fifo;
+ input_plugin_t *input;
+ int status;
+
+ int total_songs;
+ int current_song;
+ int new_song; /* indicates song change */
+
+ char *title;
+ char *artist;
+ char *copyright;
+
+ off_t filesize;
+
+ int64_t current_pts;
+ int file_sent;
+} demux_nsf_t;
+
+typedef struct {
+ demux_class_t demux_class;
+} demux_nsf_class_t;
+
+/* returns 1 if the NSF file was opened successfully, 0 otherwise */
+static int open_nsf_file(demux_nsf_t *this) {
+ unsigned char header[NSF_HEADER_SIZE];
+
+ this->input->seek(this->input, 0, SEEK_SET);
+ if (this->input->read(this->input, header, NSF_HEADER_SIZE) !=
+ NSF_HEADER_SIZE)
+ return 0;
+
+ /* check for the signature */
+ if ((header[0] != 'N') ||
+ (header[1] != 'E') ||
+ (header[2] != 'S') ||
+ (header[3] != 'M') ||
+ (header[4] != 0x1A))
+ return 0;
+
+ this->total_songs = header[6];
+ this->current_song = header[7];
+ this->title = strdup(&header[0x0E]);
+ this->artist = strdup(&header[0x2E]);
+ this->copyright = strdup(&header[0x4E]);
+
+ this->filesize = this->input->get_length(this->input);
+
+ return 1;
+}
+
+static int demux_nsf_send_chunk(demux_plugin_t *this_gen) {
+ demux_nsf_t *this = (demux_nsf_t *) this_gen;
+ buf_element_t *buf;
+ int bytes_read;
+ char title[100];
+
+ /* send chunks of the file to the decoder until file is completely
+ * loaded; then send control buffers */
+ if (!this->file_sent) {
+ buf = this->audio_fifo->buffer_pool_alloc (this->audio_fifo);
+ buf->type = BUF_AUDIO_NSF;
+ bytes_read = this->input->read(this->input, buf->content, buf->max_size);
+
+ if (bytes_read == 0) {
+ /* the file has been completely loaded, free the buffer and start
+ * sending control buffers */
+ buf->free_buffer(buf);
+ this->file_sent = 1;
+
+ } else {
+
+ /* keep loading the file */
+ if (bytes_read < buf->max_size)
+ buf->size = bytes_read;
+ else
+ buf->size = buf->max_size;
+
+ buf->extra_info->input_normpos = 0;
+ buf->extra_info->input_time = 0;
+ buf->pts = 0;
+
+ this->audio_fifo->put (this->audio_fifo, buf);
+ }
+ }
+
+ /* this is not an 'else' because control might fall through from above */
+ if (this->file_sent) {
+ /* send a control buffer */
+ buf = this->audio_fifo->buffer_pool_alloc (this->audio_fifo);
+
+ if (this->new_song) {
+
+ buf->decoder_info[1] = this->current_song;
+ this->new_song = 0;
+ sprintf(title, "%s, song %d/%d",
+ this->title, this->current_song, this->total_songs);
+
+ _x_meta_info_set(this->stream, XINE_META_INFO_TITLE, title);
+
+ _x_demux_control_newpts(this->stream, this->current_pts, 0);
+
+ } else
+ buf->decoder_info[1] = 0;
+
+ buf->type = BUF_AUDIO_NSF;
+ if(this->total_songs)
+ buf->extra_info->input_normpos = (this->current_song - 1) * 65535 / this->total_songs;
+ buf->extra_info->input_time = this->current_pts / 90;
+ buf->pts = this->current_pts;
+ buf->size = 0;
+ this->audio_fifo->put (this->audio_fifo, buf);
+
+ this->current_pts += NSF_PTS_INC;
+ }
+
+ return this->status;
+}
+
+static void demux_nsf_send_headers(demux_plugin_t *this_gen) {
+ demux_nsf_t *this = (demux_nsf_t *) this_gen;
+ buf_element_t *buf;
+ char copyright[100];
+
+ this->video_fifo = this->stream->video_fifo;
+ this->audio_fifo = this->stream->audio_fifo;
+
+ this->status = DEMUX_OK;
+
+ /* load stream information */
+ _x_stream_info_set(this->stream, XINE_STREAM_INFO_HAS_VIDEO, 0);
+ _x_stream_info_set(this->stream, XINE_STREAM_INFO_HAS_AUDIO, 1);
+ _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_CHANNELS,
+ NSF_CHANNELS);
+ _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_SAMPLERATE,
+ NSF_SAMPLERATE);
+ _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITS,
+ NSF_BITS);
+
+ _x_meta_info_set(this->stream, XINE_META_INFO_TITLE, this->title);
+ _x_meta_info_set(this->stream, XINE_META_INFO_ARTIST, this->artist);
+ sprintf(copyright, "(C) %s", this->copyright);
+ _x_meta_info_set(this->stream, XINE_META_INFO_COMMENT, copyright);
+
+ /* send start buffers */
+ _x_demux_control_start(this->stream);
+
+ /* send init info to the audio decoder */
+ if (this->audio_fifo) {
+ buf = this->audio_fifo->buffer_pool_alloc (this->audio_fifo);
+ buf->type = BUF_AUDIO_NSF;
+ buf->decoder_flags = BUF_FLAG_HEADER|BUF_FLAG_FRAME_END;
+ buf->decoder_info[0] = 5;
+ buf->decoder_info[1] = NSF_SAMPLERATE;
+ buf->decoder_info[2] = NSF_BITS;
+ buf->decoder_info[3] = NSF_CHANNELS;
+
+ /* send the NSF filesize in the body, big endian format */
+ buf->content[0] = (this->filesize >> 24) & 0xFF;
+ buf->content[1] = (this->filesize >> 16) & 0xFF;
+ buf->content[2] = (this->filesize >> 8) & 0xFF;
+ buf->content[3] = (this->filesize >> 0) & 0xFF;
+ /* send the requested song */
+ buf->content[4] = this->current_song + 5;
+
+ this->audio_fifo->put (this->audio_fifo, buf);
+ }
+}
+
+static int demux_nsf_seek (demux_plugin_t *this_gen,
+ off_t start_pos, int start_time, int playing) {
+
+ demux_nsf_t *this = (demux_nsf_t *) this_gen;
+ start_pos = (off_t) ( (double) start_pos / 65535 *
+ this->total_songs );
+
+ /* if thread is not running, initialize demuxer */
+ if( !playing ) {
+
+ /* send new pts */
+ _x_demux_control_newpts(this->stream, 0, 0);
+
+ this->status = DEMUX_OK;
+
+ /* reposition stream at the start for loading */
+ this->input->seek(this->input, 0, SEEK_SET);
+
+ this->file_sent = 0;
+ this->current_pts = 0;
+ this->new_song = 1;
+ } else {
+ this->current_song = start_pos + 1;
+ this->new_song = 1;
+ this->current_pts = 0;
+ _x_demux_flush_engine(this->stream);
+ }
+
+ return this->status;
+}
+
+static void demux_nsf_dispose (demux_plugin_t *this_gen) {
+ demux_nsf_t *this = (demux_nsf_t *) this_gen;
+
+ free(this->title);
+ free(this->artist);
+ free(this->copyright);
+ free(this);
+}
+
+static int demux_nsf_get_status (demux_plugin_t *this_gen) {
+ demux_nsf_t *this = (demux_nsf_t *) this_gen;
+
+ return this->status;
+}
+
+/* return the approximate length in miliseconds */
+static int demux_nsf_get_stream_length (demux_plugin_t *this_gen) {
+ return 0;
+}
+
+static uint32_t demux_nsf_get_capabilities(demux_plugin_t *this_gen) {
+ return DEMUX_CAP_NOCAP;
+}
+
+static int demux_nsf_get_optional_data(demux_plugin_t *this_gen,
+ void *data, int data_type) {
+ return DEMUX_OPTIONAL_UNSUPPORTED;
+}
+
+static demux_plugin_t *open_plugin (demux_class_t *class_gen, xine_stream_t *stream,
+ input_plugin_t *input) {
+
+ demux_nsf_t *this;
+
+ if (!INPUT_IS_SEEKABLE(input)) {
+ xprintf(stream->xine, XINE_VERBOSITY_DEBUG, "input not seekable, can not handle!\n");
+ return NULL;
+ }
+
+ this = xine_xmalloc (sizeof (demux_nsf_t));
+ this->stream = stream;
+ this->input = input;
+
+ this->demux_plugin.send_headers = demux_nsf_send_headers;
+ this->demux_plugin.send_chunk = demux_nsf_send_chunk;
+ this->demux_plugin.seek = demux_nsf_seek;
+ this->demux_plugin.dispose = demux_nsf_dispose;
+ this->demux_plugin.get_status = demux_nsf_get_status;
+ this->demux_plugin.get_stream_length = demux_nsf_get_stream_length;
+ this->demux_plugin.get_capabilities = demux_nsf_get_capabilities;
+ this->demux_plugin.get_optional_data = demux_nsf_get_optional_data;
+ this->demux_plugin.demux_class = class_gen;
+
+ this->status = DEMUX_FINISHED;
+
+ switch (stream->content_detection_method) {
+
+ case METHOD_BY_EXTENSION: {
+ const char *extensions, *mrl;
+
+ mrl = input->get_mrl (input);
+ extensions = class_gen->get_extensions (class_gen);
+
+ if (!_x_demux_check_extension (mrl, extensions)) {
+ free (this);
+ return NULL;
+ }
+ }
+ /* falling through is intended */
+
+ case METHOD_BY_CONTENT:
+ case METHOD_EXPLICIT:
+
+ if (!open_nsf_file(this)) {
+ free (this);
+ return NULL;
+ }
+
+ break;
+
+ default:
+ free (this);
+ return NULL;
+ }
+
+ return &this->demux_plugin;
+}
+
+static const char *get_description (demux_class_t *this_gen) {
+ return "NES Music file demux plugin";
+}
+
+static const char *get_identifier (demux_class_t *this_gen) {
+ return "NSF";
+}
+
+static const char *get_extensions (demux_class_t *this_gen) {
+ return "nsf";
+}
+
+static const char *get_mimetypes (demux_class_t *this_gen) {
+ return NULL;
+}
+
+static void class_dispose (demux_class_t *this_gen) {
+ demux_nsf_class_t *this = (demux_nsf_class_t *) this_gen;
+
+ free (this);
+}
+
+void *demux_nsf_init_plugin (xine_t *xine, void *data) {
+ demux_nsf_class_t *this;
+
+ this = xine_xmalloc (sizeof (demux_nsf_class_t));
+
+ this->demux_class.open_plugin = open_plugin;
+ this->demux_class.get_description = get_description;
+ this->demux_class.get_identifier = get_identifier;
+ this->demux_class.get_mimetypes = get_mimetypes;
+ this->demux_class.get_extensions = get_extensions;
+ this->demux_class.dispose = class_dispose;
+
+ return this;
+}
diff --git a/src/combined/wavpack_combined.c b/src/combined/wavpack_combined.c
new file mode 100644
index 000000000..110de2b2e
--- /dev/null
+++ b/src/combined/wavpack_combined.c
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2007 the xine project
+ *
+ * This file is part of xine, a free video player.
+ *
+ * xine 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.
+ *
+ * xine is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * xine interface to libwavpack by Diego Pettenò <flameeyes@gmail.com>
+ *
+ * $Id: combined_wavpack.c,v 1.3 2007/03/17 07:34:02 dgp85 Exp $
+ */
+
+#include "xine_internal.h"
+#include "wavpack_combined.h"
+
+static const demuxer_info_t demux_info_wv = {
+ 0 /* priority */
+};
+
+static uint32_t audio_types[] = {
+ BUF_AUDIO_WAVPACK, 0
+ };
+
+static const decoder_info_t decoder_info_wv = {
+ audio_types, /* supported types */
+ 7 /* priority */
+};
+
+const plugin_info_t xine_plugin_info[] EXPORTED = {
+ /* type, API, "name", version, special_info, init_function */
+ { PLUGIN_DEMUX, 26, "wavpack", XINE_VERSION_CODE, &demux_info_wv, demux_wv_init_plugin },
+ { PLUGIN_AUDIO_DECODER, 15, "wavpackdec", XINE_VERSION_CODE, &decoder_info_wv, decoder_wavpack_init_plugin },
+ { PLUGIN_NONE, 0, NULL, 0, NULL, NULL }
+};
diff --git a/src/combined/wavpack_combined.h b/src/combined/wavpack_combined.h
new file mode 100644
index 000000000..7688f91df
--- /dev/null
+++ b/src/combined/wavpack_combined.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2007 the xine project
+ *
+ * This file is part of xine, a free video player.
+ *
+ * xine 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.
+ *
+ * xine is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * xine interface to libwavpack by Diego Pettenò <flameeyes@gmail.com>
+ *
+ * $Id: combined_wavpack.h,v 1.3 2007/03/17 07:34:02 dgp85 Exp $
+ */
+
+#include "os_types.h"
+#include "bswap.h"
+
+typedef struct {
+ uint32_t idcode; /* This should always be the string "wvpk" */
+ uint32_t block_size; /* Size of the rest of the frame */
+ uint16_t wv_version; /* Version of the wavpack, 0x0403 should be latest */
+ uint8_t track; /* Unused, has to be 0 */
+ uint8_t index; /* Unused, has to be 0 */
+ uint32_t file_samples; /* (uint32_t)-1 if unknown, else the total number
+ of samples for the file */
+ uint32_t samples_index; /* Index of the first sample in block, from the
+ start of the file */
+ uint32_t samples_count; /* Count of samples in the current frame */
+ uint32_t flags; /* Misc flags */
+ uint32_t decoded_crc32; /* CRC32 of the decoded data */
+} XINE_PACKED wvheader_t;
+
+static const uint32_t wvpk_signature = ME_FOURCC('w', 'v', 'p', 'k');
+
+void *demux_wv_init_plugin (xine_t *const xine, void *const data);
+void *decoder_wavpack_init_plugin (xine_t *xine, void *data);
diff --git a/src/combined/wavpack_decoder.c b/src/combined/wavpack_decoder.c
new file mode 100644
index 000000000..1fceb3137
--- /dev/null
+++ b/src/combined/wavpack_decoder.c
@@ -0,0 +1,339 @@
+/*
+ * Copyright (C) 2007 the xine project
+ *
+ * This file is part of xine, a free video player.
+ *
+ * xine 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.
+ *
+ * xine is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * xine interface to libwavpack by Diego Pettenò <flameeyes@gmail.com>
+ *
+ * $Id: decoder_wavpack.c,v 1.14 2007/03/29 19:45:33 dgp85 Exp $
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#define LOG_MODULE "decode_wavpack"
+#define LOG_VERBOSE
+
+#include "xine_internal.h"
+#include "attributes.h"
+#include "bswap.h"
+
+#include <wavpack/wavpack.h>
+#include "wavpack_combined.h"
+
+typedef struct {
+ audio_decoder_class_t decoder_class;
+} wavpack_class_t;
+
+typedef struct {
+ audio_decoder_t audio_decoder;
+
+ xine_stream_t *stream;
+
+ uint8_t *buf;
+ size_t buf_size;
+ size_t buf_pos;
+
+ int sample_rate;
+ uint16_t bits_per_sample:6;
+ uint16_t channels:4;
+
+ uint16_t output_open:1;
+
+} wavpack_decoder_t;
+
+/* Wrapper functions for Wavpack */
+static int32_t xine_buffer_read_bytes(void *const this_gen, void *const data,
+ int32_t bcount) {
+ wavpack_decoder_t *const this = (wavpack_decoder_t*)this_gen;
+
+ if ( bcount <= 0 )
+ return 0;
+
+ if ( bcount > (this->buf_size - this->buf_pos) )
+ bcount = (this->buf_size - this->buf_pos);
+
+ xine_fast_memcpy(data, this->buf + this->buf_pos, bcount);
+ this->buf_pos += bcount;
+
+ return bcount;
+}
+
+static uint32_t xine_buffer_get_pos(void *const this_gen) {
+ wavpack_decoder_t *const this = (wavpack_decoder_t*)this_gen;
+ return this->buf_pos;
+}
+
+static int xine_buffer_set_pos_rel(void *const this_gen, const int32_t delta,
+ const int mode) {
+ wavpack_decoder_t *const this = (wavpack_decoder_t*)this_gen;
+
+ switch(mode) {
+ case SEEK_SET:
+ if ( delta < 0 || delta > this->buf_size )
+ return -1;
+
+ this->buf_pos = delta;
+ return 0;
+ case SEEK_CUR:
+ if ( (this->buf_pos+delta) < 0 || (this->buf_pos+delta) > this->buf_size )
+ return -1;
+
+ this->buf_pos += delta;
+ return 0;
+ case SEEK_END:
+ if ( delta < 0 || delta > this->buf_size )
+ return -1;
+
+ this->buf_pos = this->buf_size - delta;
+
+ return 0;
+ }
+
+ return -1;
+}
+
+static int xine_buffer_set_pos_abs(void *const this_gen, const uint32_t pos) {
+ return xine_buffer_set_pos_rel(this_gen, pos, SEEK_SET);
+}
+
+static int xine_buffer_push_back_byte(void *const this_gen, const int c) {
+ if ( ! xine_buffer_set_pos_rel(this_gen, -1, SEEK_CUR) )
+ return EOF;
+ return c;
+}
+
+static uint32_t xine_buffer_get_length(void *const this_gen) {
+ wavpack_decoder_t *const this = (wavpack_decoder_t*)this_gen;
+ return this->buf_size;
+}
+
+static int xine_buffer_can_seek(void *const this_gen) {
+ return 1;
+}
+
+static int32_t xine_buffer_write_bytes(__attr_unused void *const id,
+ __attr_unused void *const data,
+ __attr_unused const int32_t bcount) {
+ lprintf("xine_buffer_write_bytes: access is read-only.\n");
+ return 0;
+}
+
+/* Wavpack plugin functions */
+static void wavpack_reset (audio_decoder_t *const this_gen)
+{
+ wavpack_decoder_t *const this = (wavpack_decoder_t *) this_gen;
+
+ this->buf_pos = 0;
+}
+
+static void wavpack_discontinuity (audio_decoder_t *const this_gen)
+{
+ /* wavpack_decoder_t *this = (wavpack_decoder_t *) this_gen; */
+
+ lprintf("Discontinuity!\n");
+}
+
+static void wavpack_decode_data (audio_decoder_t *const this_gen, buf_element_t *const buf)
+{
+ wavpack_decoder_t *const this = (wavpack_decoder_t *) this_gen;
+
+ /* We are getting the stream header, open up the audio
+ * device, and collect information about the stream
+ */
+ if (buf->decoder_flags & BUF_FLAG_STDHEADER)
+ {
+ int mode = AO_CAP_MODE_MONO;
+
+ this->sample_rate = buf->decoder_info[1];
+ _x_assert(buf->decoder_info[2] <= 32);
+ this->bits_per_sample = buf->decoder_info[2];
+ _x_assert(buf->decoder_info[3] <= 8);
+ this->channels = buf->decoder_info[3];
+
+ mode = _x_ao_channels2mode(this->channels);
+
+ _x_meta_info_set(this->stream, XINE_META_INFO_AUDIOCODEC,
+ "WavPack");
+
+ if (!this->output_open)
+ {
+ this->output_open = this->stream->audio_out->open (
+ this->stream->audio_out,
+ this->stream,
+ this->bits_per_sample,
+ this->sample_rate,
+ mode) ? 1 : 0;
+ }
+ this->buf_pos = 0;
+ } else if (this->output_open) {
+ /* This isn't a header frame and we have opened the output device */
+
+ /* What we have buffered so far, and what is coming in
+ * is larger than our buffer
+ */
+ if (this->buf_pos + buf->size > this->buf_size)
+ {
+ this->buf_size += 2 * buf->size;
+ this->buf = realloc (this->buf, this->buf_size);
+ lprintf("reallocating buffer to %zd\n", this->buf_size);
+ }
+
+ xine_fast_memcpy (&this->buf[this->buf_pos], buf->content, buf->size);
+ this->buf_pos += buf->size;
+
+ if ( buf->decoder_flags & BUF_FLAG_FRAME_END ) {
+ static WavpackStreamReader wavpack_buffer_reader = {
+ .read_bytes = xine_buffer_read_bytes,
+ .get_pos = xine_buffer_get_pos,
+ .set_pos_abs = xine_buffer_set_pos_abs,
+ .set_pos_rel = xine_buffer_set_pos_rel,
+ .push_back_byte = xine_buffer_push_back_byte,
+ .get_length = xine_buffer_get_length,
+ .can_seek = xine_buffer_can_seek,
+ .write_bytes = xine_buffer_write_bytes
+ };
+
+ WavpackContext *ctx = NULL;
+ /* Current version of wavpack (4.40) does not write more than this */
+ char error[256] = { 0, };
+ int32_t samples_left; uint32_t samples_total;
+ const wvheader_t *header = (const wvheader_t*)this->buf;
+
+ this->buf_pos = 0;
+
+ if ( le2me_32(header->samples_count) == 0 ) return;
+
+ ctx = WavpackOpenFileInputEx(&wavpack_buffer_reader, this, NULL, error, OPEN_STREAMING, 0);
+ if ( ! ctx ) {
+ lprintf("unable to open the stream: %s\n", error);
+ this->buf_pos = 0;
+ return;
+ }
+
+ samples_left = samples_total = header->samples_count;
+ while ( samples_left > 0 ) {
+ uint32_t buf_samples, decoded_count;
+ audio_buffer_t *audio_buffer = this->stream->audio_out->get_buffer(this->stream->audio_out);
+ int32_t *decoded;
+ int i;
+
+ buf_samples = audio_buffer->mem_size / (this->channels * (this->bits_per_sample/8));
+ if ( buf_samples > samples_left ) buf_samples = samples_left;
+
+ decoded = alloca(buf_samples * this->channels * sizeof(int32_t));
+
+ decoded_count = WavpackUnpackSamples(ctx, decoded, buf_samples);
+ if ( decoded_count == 0 && *error ) {
+ lprintf("Error during decode: %s\n", error);
+ this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, NULL);
+ break;
+ }
+
+ if ( decoded_count == 0 ) {
+ lprintf("Finished decoding, but still %d samples left?\n", samples_left);
+ this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, NULL);
+ break;
+ }
+
+ lprintf("Decoded %d samples\n", buf_samples);
+
+ samples_left -= decoded_count;
+
+ audio_buffer->num_frames = decoded_count;
+ audio_buffer->vpts = 0; /* TODO: Fix the pts calculation */
+ // audio_buffer->vpts = (buf->pts * (samples_total-samples_left)) / samples_total;
+ lprintf("Audio buffer with pts %"PRId64"\n", audio_buffer->vpts);
+
+ switch(this->bits_per_sample) {
+ case 8: {
+ int8_t *data8 = (int8_t*)audio_buffer->mem;
+ for(i = 0; i < decoded_count*this->channels; i++)
+ data8[i] = decoded[i];
+ }
+ break;
+ case 16: {
+ int16_t *data16 = (int16_t*)audio_buffer->mem;
+ for(i = 0; i < decoded_count*this->channels; i++)
+ data16[i] = decoded[i];
+ }
+ }
+
+ this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream);
+ }
+
+ WavpackCloseFile(ctx);
+ this->buf_pos = 0;
+ }
+ }
+}
+
+static void wavpack_dispose (audio_decoder_t *this_gen) {
+ wavpack_decoder_t *this = (wavpack_decoder_t *) this_gen;
+
+ if (this->output_open)
+ this->stream->audio_out->close (this->stream->audio_out, this->stream);
+
+ free(this->buf);
+
+ free (this_gen);
+}
+
+static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) {
+ wavpack_decoder_t * const this = (wavpack_decoder_t *) xine_xmalloc (sizeof (wavpack_decoder_t));
+
+ this->audio_decoder.decode_data = wavpack_decode_data;
+ this->audio_decoder.reset = wavpack_reset;
+ this->audio_decoder.discontinuity = wavpack_discontinuity;
+ this->audio_decoder.dispose = wavpack_dispose;
+ this->stream = stream;
+
+ this->buf = NULL;
+ this->buf_size = 0;
+
+ return (audio_decoder_t *) this;
+}
+
+/*
+ * wavpack plugin class
+ */
+
+static char *get_identifier (audio_decoder_class_t *this) {
+ return "wavpackdec";
+}
+
+static char *get_description (audio_decoder_class_t *this) {
+ return "wavpack audio decoder plugin";
+}
+
+static void dispose_class (audio_decoder_class_t *this) {
+ free (this);
+}
+
+void *decoder_wavpack_init_plugin (xine_t *xine, void *data) {
+ wavpack_class_t *this;
+
+ this = (wavpack_class_t *) xine_xmalloc (sizeof (wavpack_class_t));
+
+ this->decoder_class.open_plugin = open_plugin;
+ this->decoder_class.get_identifier = get_identifier;
+ this->decoder_class.get_description = get_description;
+ this->decoder_class.dispose = dispose_class;
+
+ return this;
+}
diff --git a/src/combined/wavpack_demuxer.c b/src/combined/wavpack_demuxer.c
new file mode 100644
index 000000000..da69731b1
--- /dev/null
+++ b/src/combined/wavpack_demuxer.c
@@ -0,0 +1,414 @@
+/*
+ * Copyright (C) 2006-2007 the xine project
+ *
+ * This file is part of xine, a free video player.
+ *
+ * xine 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.
+ *
+ * xine is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * xine interface to libwavpack by Diego Pettenò <flameeyes@gmail.com>
+ *
+ * $Id: demux_wavpack.c,v 1.11 2007/03/17 07:34:02 dgp85 Exp $
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#define LOG_MODULE "demux_wavpack"
+#define LOG_VERBOSE
+
+#include "xine_internal.h"
+#include "xineutils.h"
+#include "demux.h"
+#include "bswap.h"
+#include "attributes.h"
+
+#include <wavpack/wavpack.h>
+#include "wavpack_combined.h"
+
+typedef struct {
+ demux_plugin_t demux_plugin;
+
+ xine_stream_t *stream;
+ fifo_buffer_t *audio_fifo;
+ input_plugin_t *input;
+ int status;
+
+ uint32_t current_sample;
+ uint32_t samples;
+ uint32_t samplerate;
+ uint16_t bits_per_sample:6;
+ uint16_t channels:4;
+} demux_wv_t;
+
+typedef struct {
+ demux_class_t demux_class;
+} demux_wv_class_t;
+
+static int32_t xine_input_read_bytes(void *const this_gen, void *const data,
+ const int32_t bcount) {
+ input_plugin_t *const this = (input_plugin_t*)this_gen;
+ return this->read(this, data, bcount);
+}
+
+static uint32_t xine_input_get_pos(void *const this_gen) {
+ input_plugin_t *const this = (input_plugin_t*)this_gen;
+ return this->get_current_pos(this);
+}
+
+static int xine_input_set_pos_abs(void *const this_gen, const uint32_t pos) {
+ input_plugin_t *const this = (input_plugin_t*)this_gen;
+ return this->seek(this, pos, SEEK_SET);
+}
+
+static int xine_input_set_pos_rel(void *const this_gen, const int32_t delta,
+ const int mode) {
+ input_plugin_t *const this = (input_plugin_t*)this_gen;
+ return this->seek(this, delta, mode);
+}
+
+static int xine_input_push_back_byte(void *const this_gen, const int c) {
+ input_plugin_t *const this = (input_plugin_t*)this_gen;
+ if ( this->seek(this, -1, SEEK_CUR) ) {
+ return c;
+ } else {
+ lprintf("xine_input_push_back_byte: unable to seek.\n");
+ return EOF;
+ }
+}
+
+static uint32_t xine_input_get_length(void *const this_gen) {
+ input_plugin_t *const this = (input_plugin_t*)this_gen;
+ return this->get_length(this);
+}
+
+static int xine_input_can_seek(void *const this_gen) {
+ input_plugin_t *const this = (input_plugin_t*)this_gen;
+ return INPUT_IS_SEEKABLE(this);
+}
+
+static int32_t xine_input_write_bytes(__attr_unused void *const id,
+ __attr_unused void *const data,
+ __attr_unused const int32_t bcount) {
+ lprintf("xine_input_write_bytes: acces is read-only.\n");
+ return 0;
+}
+
+static WavpackStreamReader wavpack_input_reader = {
+ .read_bytes = xine_input_read_bytes,
+ .get_pos = xine_input_get_pos,
+ .set_pos_abs = xine_input_set_pos_abs,
+ .set_pos_rel = xine_input_set_pos_rel,
+ .push_back_byte = xine_input_push_back_byte,
+ .get_length = xine_input_get_length,
+ .can_seek = xine_input_can_seek,
+ .write_bytes = xine_input_write_bytes
+};
+
+static int open_wv_file(demux_wv_t *const this) {
+ WavpackContext *ctx = NULL;
+ char error[256]; /* Current version of wavpack (4.31) does not write more than this */
+ wvheader_t header;
+ uint32_t tmp;
+
+ /* Right now we don't support non-seekable streams */
+ if (! INPUT_IS_SEEKABLE(this->input) ) {
+ lprintf("open_wv_file: non-seekable inputs aren't supported yet.\n");
+ return 0;
+ }
+
+ /* Read the file header */
+ if (_x_demux_read_header(this->input, (uint8_t*)(&header), sizeof(wvheader_t)) != sizeof(wvheader_t))
+ return 0;
+
+ /* Validate header, we currently support only Wavpack 4 */
+ if ( header.idcode != wvpk_signature || (le2me_16(header.wv_version) >> 8) != 4 )
+ return 0;
+
+ /* Rewind */
+ this->input->seek(this->input, 0, SEEK_SET);
+
+ ctx = WavpackOpenFileInputEx(&wavpack_input_reader, this->input, NULL, error, 0, 0);
+ if ( ! ctx ) {
+ lprintf("xine_open_wavpack_input: unable to open the stream: %s\n", error);
+ return 0;
+ }
+
+ this->current_sample = 0;
+ this->samples = WavpackGetNumSamples(ctx);
+ lprintf("number of samples: %u\n", this->samples);
+ this->samplerate = WavpackGetSampleRate(ctx);
+ lprintf("samplerate: %u Hz\n", this->samplerate);
+
+ tmp = WavpackGetBitsPerSample(ctx); _x_assert(tmp <= 32);
+ lprintf("bits_per_sample: %u\n", tmp);
+ this->bits_per_sample = tmp;
+
+ tmp = WavpackGetNumChannels(ctx); _x_assert(tmp <= 8);
+ lprintf("channels: %u\n", tmp);
+ this->channels = tmp;
+
+ _x_stream_info_set(this->stream, XINE_STREAM_INFO_HAS_AUDIO, 1);
+ _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_FOURCC,
+ wvpk_signature);
+ _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_CHANNELS,
+ this->channels);
+ _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_SAMPLERATE,
+ this->samplerate);
+ _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITS,
+ this->bits_per_sample);
+
+ WavpackCloseFile(ctx);
+ this->input->seek(this->input, SEEK_SET, 0);
+
+ return 1;
+}
+
+static int demux_wv_send_chunk(demux_plugin_t *const this_gen) {
+ demux_wv_t *const this = (demux_wv_t *) this_gen;
+ uint32_t bytes_to_read; uint8_t header_sent = 0;
+ wvheader_t header;
+
+ lprintf("new frame\n");
+
+ /* Check if we've finished */
+ if (this->current_sample >= this->samples) {
+ lprintf("all frames read\n");
+ this->status = DEMUX_FINISHED;
+ return this->status;
+ }
+
+ lprintf("current sample: %u\n", this->current_sample);
+
+ do {
+ if ( this->input->read(this->input, (uint8_t*)(&header), sizeof(wvheader_t)) != sizeof(wvheader_t) ) {
+ this->status = DEMUX_FINISHED;
+ return this->status;
+ }
+
+ /* The size of the block is «of course» minus 8, and
+ it also includes the size of the header.
+ */
+ bytes_to_read = le2me_32(header.block_size) + 8 - sizeof(wvheader_t);
+
+ lprintf("demux_wavpack: going to read %u bytes.\n", bytes_to_read);
+
+ while(bytes_to_read) {
+ off_t bytes_read = 0, bytes_to_read_now, offset = 0;
+ buf_element_t *buf = NULL;
+ int64_t input_time_guess;
+
+ /* Get a buffer */
+ buf = this->audio_fifo->buffer_pool_alloc(this->audio_fifo);
+ buf->type = BUF_AUDIO_WAVPACK;
+ buf->decoder_flags = 0;
+
+ /* Set normalised position */
+ buf->extra_info->input_normpos =
+ (int) ((double) this->input->get_current_pos(this->input) * 65535 /
+ this->input->get_length(this->input));
+
+ buf->pts = (((this->current_sample) / this->samplerate))*90000;
+ lprintf("Sending buffer with PTS %"PRId64"\n", buf->pts);
+
+ /* Set time */
+ input_time_guess = this->samples;
+ input_time_guess /= this->samplerate;
+ input_time_guess *= 1000;
+ input_time_guess *= buf->extra_info->input_normpos;
+ input_time_guess /= 65535;
+ buf->extra_info->input_time = input_time_guess;
+
+ bytes_to_read_now = ( bytes_to_read > buf->max_size ) ? buf->max_size : bytes_to_read;
+ if ( ! header_sent ) {
+ bytes_to_read_now -= (offset = sizeof(wvheader_t));
+
+ header_sent = 1;
+ xine_fast_memcpy(buf->content, &header, sizeof(wvheader_t));
+ }
+
+ bytes_read = this->input->read(this->input, &buf->content[offset], bytes_to_read_now);
+
+ buf->size = offset + bytes_read;
+
+ bytes_to_read -= bytes_read;
+
+ if ( bytes_to_read <= 0 && (le2me_32(header.flags) & FINAL_BLOCK) == FINAL_BLOCK)
+ buf->decoder_flags |= BUF_FLAG_FRAME_END;
+
+ this->audio_fifo->put(this->audio_fifo, buf);
+ }
+ } while ( (le2me_32(header.flags) & FINAL_BLOCK) != FINAL_BLOCK );
+
+ this->current_sample += le2me_32(header.samples_count);
+
+ return this->status;
+}
+
+static void demux_wv_send_headers(demux_plugin_t *const this_gen) {
+ demux_wv_t *const this = (demux_wv_t *) this_gen;
+ buf_element_t *buf;
+
+ this->audio_fifo = this->stream->audio_fifo;
+
+ this->status = DEMUX_OK;
+
+ /* Send start buffers */
+ _x_demux_control_start(this->stream);
+
+ /* Send header to decoder */
+ if (this->audio_fifo) {
+ buf = this->audio_fifo->buffer_pool_alloc (this->audio_fifo);
+
+ buf->type = BUF_AUDIO_WAVPACK;
+ buf->decoder_flags = BUF_FLAG_HEADER|BUF_FLAG_STDHEADER|BUF_FLAG_FRAME_END;
+ buf->decoder_info[0] = this->input->get_length(this->input);
+ buf->decoder_info[1] = this->samplerate;
+ buf->decoder_info[2] = this->bits_per_sample;
+ buf->decoder_info[3] = this->channels;
+
+ buf->size = 0;
+
+ this->audio_fifo->put (this->audio_fifo, buf);
+ }
+}
+
+static int demux_wv_seek (demux_plugin_t *this_gen,
+ off_t start_pos, int start_time, int playing) {
+ demux_wv_t *const this = (demux_wv_t *) this_gen;
+
+ /* If thread is not running, initialize demuxer */
+ if( !playing ) {
+
+ /* send new pts */
+ _x_demux_control_newpts(this->stream, 0, 0);
+
+ this->status = DEMUX_OK;
+
+ }
+
+ return this->status;
+}
+
+static void demux_wv_dispose (demux_plugin_t *const this_gen) {
+ demux_wv_t *const this = (demux_wv_t *) this_gen;
+
+ free(this);
+}
+
+static int demux_wv_get_status (demux_plugin_t *const this_gen) {
+ const demux_wv_t *const this = (const demux_wv_t *) this_gen;
+
+ return this->status;
+}
+
+static int demux_wv_get_stream_length (demux_plugin_t *const this_gen) {
+ const demux_wv_t *const this = (demux_wv_t *) this_gen;
+
+ return (this->samples*1000) / this->samplerate;
+}
+
+static uint32_t demux_wv_get_capabilities(demux_plugin_t *const this_gen) {
+ return DEMUX_CAP_NOCAP;
+}
+
+static int demux_wv_get_optional_data(demux_plugin_t *const this_gen,
+ void *data, const int data_type) {
+ return DEMUX_OPTIONAL_UNSUPPORTED;
+}
+
+static demux_plugin_t *open_plugin (demux_class_t *const class_gen,
+ xine_stream_t *const stream,
+ input_plugin_t *const input) {
+ demux_wv_t *const this = xine_xmalloc (sizeof (demux_wv_t));
+ this->stream = stream;
+ this->input = input;
+
+ this->demux_plugin.send_headers = demux_wv_send_headers;
+ this->demux_plugin.send_chunk = demux_wv_send_chunk;
+ this->demux_plugin.seek = demux_wv_seek;
+ this->demux_plugin.dispose = demux_wv_dispose;
+ this->demux_plugin.get_status = demux_wv_get_status;
+ this->demux_plugin.get_stream_length = demux_wv_get_stream_length;
+ this->demux_plugin.get_capabilities = demux_wv_get_capabilities;
+ this->demux_plugin.get_optional_data = demux_wv_get_optional_data;
+ this->demux_plugin.demux_class = class_gen;
+
+ this->status = DEMUX_FINISHED;
+ switch (stream->content_detection_method) {
+
+ case METHOD_BY_EXTENSION: {
+ const char *const mrl = input->get_mrl (input);
+ const char *const extensions = class_gen->get_extensions (class_gen);
+
+ if (!_x_demux_check_extension (mrl, extensions)) {
+ free (this);
+ return NULL;
+ }
+ }
+ /* Falling through is intended */
+
+ case METHOD_BY_CONTENT:
+ case METHOD_EXPLICIT:
+
+ if (!open_wv_file(this)) {
+ free (this);
+ return NULL;
+ }
+
+ break;
+
+ default:
+ free (this);
+ return NULL;
+ }
+
+ return &this->demux_plugin;
+}
+
+static const char *get_description (demux_class_t *const this_gen) {
+ return "Wavpack demux plugin";
+}
+
+static const char *get_identifier (demux_class_t *const this_gen) {
+ return "Wavpack";
+}
+
+static const char *get_extensions (demux_class_t *const this_gen) {
+ return "wv";
+}
+
+static const char *get_mimetypes (demux_class_t *const this_gen) {
+ return NULL;
+}
+
+static void class_dispose (demux_class_t *const this_gen) {
+ demux_wv_class_t *const this = (demux_wv_class_t *) this_gen;
+
+ free (this);
+}
+
+void *demux_wv_init_plugin (xine_t *const xine, void *const data) {
+ demux_wv_class_t *const this = xine_xmalloc (sizeof (demux_wv_class_t));
+
+ this->demux_class.open_plugin = open_plugin;
+ this->demux_class.get_description = get_description;
+ this->demux_class.get_identifier = get_identifier;
+ this->demux_class.get_mimetypes = get_mimetypes;
+ this->demux_class.get_extensions = get_extensions;
+ this->demux_class.dispose = class_dispose;
+
+ return this;
+}
diff --git a/src/demuxers/Makefile.am b/src/demuxers/Makefile.am
index 8a931c2d6..aa6bc5d5e 100644
--- a/src/demuxers/Makefile.am
+++ b/src/demuxers/Makefile.am
@@ -1,30 +1,43 @@
include $(top_srcdir)/misc/Makefile.common
-AM_CFLAGS = $(VISIBILITY_FLAG)
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
AM_LDFLAGS = $(xineplug_ldflags)
-if HAVE_VORBIS
+##
+# IMPORTANT:
+# ---------
+# All of xine demuxer plugins should be named like the scheme "xineplug_dmx_"
+
+xineinclude_HEADERS = demux.h
+
+noinst_HEADERS = asfheader.h qtpalette.h group_games.h group_audio.h id3.h ebml.h matroska.h iff.h flacutils.h
+
+if ENABLE_VORBIS
ogg_module = xineplug_dmx_ogg.la
endif
-if BUILD_ASF
+if ENABLE_ASF
asf_module = xineplug_dmx_asf.la
endif
-if HAVE_LIBMNG
+if ENABLE_MNG
mng_module = xineplug_dmx_mng.la
endif
+if ENABLE_MODPLUG
+modplug_module = xineplug_dmx_modplug.la
+endif
+
if BUILD_DMX_IMAGE
image_module = xineplug_dmx_image.la
endif
-##
-# IMPORTANT:
-# ---------
-# All of xine demuxer plugins should be named like the scheme "xineplug_dmx_"
-
-xineplug_LTLIBRARIES = $(ogg_module) $(asf_module) $(mng_module) $(image_module) \
+xineplug_LTLIBRARIES = \
+ $(ogg_module) \
+ $(asf_module) \
+ $(mng_module) \
+ $(image_module) \
+ $(modplug_module) \
xineplug_dmx_games.la \
xineplug_dmx_audio.la \
xineplug_dmx_mpeg_ts.la \
@@ -70,7 +83,7 @@ xineplug_dmx_mpeg_ts_la_LIBADD = $(XINE_LIB)
xineplug_dmx_qt_la_SOURCES = demux_qt.c
xineplug_dmx_qt_la_LIBADD = $(XINE_LIB) $(ZLIB_LIBS)
-xineplug_dmx_qt_la_CPPFLAGS = $(ZLIB_CPPFLAGS)
+xineplug_dmx_qt_la_CPPFLAGS = $(AM_CPPFLAGS) $(ZLIB_CPPFLAGS)
xineplug_dmx_asf_la_SOURCES = demux_asf.c asfheader.c
xineplug_dmx_asf_la_LIBADD = $(XINE_LIB)
@@ -90,7 +103,7 @@ xineplug_dmx_rawdv_la_LIBADD = $(XINE_LIB)
xineplug_dmx_mng_la_SOURCES = demux_mng.c
xineplug_dmx_mng_la_LIBADD = $(XINE_LIB) $(ZLIB_LIBS) $(MNG_LIBS)
-xineplug_dmx_mng_la_CPPFLAGS = $(ZLIB_CPPFLAGS)
+xineplug_dmx_mng_la_CPPFLAGS = $(AM_CPPFLAGS) $(ZLIB_CPPFLAGS)
xineplug_dmx_pva_la_SOURCES = demux_pva.c
xineplug_dmx_pva_la_LIBADD = $(XINE_LIB)
@@ -101,17 +114,19 @@ xineplug_dmx_games_la_SOURCES = group_games.c demux_eawve.c \
demux_film.c demux_smjpeg.c demux_4xm.c \
demux_vmd.c
xineplug_dmx_games_la_LIBADD = $(XINE_LIB)
-xineplug_dmx_games_la_LDFLAGS = -avoid-version -module
xineplug_dmx_audio_la_SOURCES = group_audio.c demux_aud.c demux_aiff.c \
- demux_cdda.c demux_mpgaudio.c demux_nsf.c \
+ demux_cdda.c demux_mpgaudio.c \
demux_realaudio.c demux_snd.c demux_voc.c \
demux_vox.c demux_wav.c demux_ac3.c id3.c \
- demux_aac.c demux_mod.c demux_flac.c \
+ demux_aac.c demux_flac.c \
demux_mpc.c demux_dts.c demux_shn.c \
demux_tta.c
-xineplug_dmx_audio_la_LIBADD = $(XINE_LIB) $(LIBMODPLUG_LIBS)
-xineplug_dmx_audio_la_CFLAGS = $(AM_CFLAGS) $(LIBMODPLUG_CFLAGS)
+xineplug_dmx_audio_la_LIBADD = $(XINE_LIB)
+
+xineplug_dmx_modplug_la_SOURCES = demux_mod.c
+xineplug_dmx_modplug_la_LIBADD = $(XINE_LIB) $(LIBMODPLUG_LIBS)
+xineplug_dmx_modplug_la_CFLAGS = $(LIBMODPLUG_CFLAGS)
xineplug_dmx_yuv_frames_la_SOURCES = demux_yuv_frames.c
xineplug_dmx_yuv_frames_la_LIBADD = $(XINE_LIB)
@@ -127,14 +142,11 @@ xineplug_dmx_nsv_la_LIBADD = $(XINE_LIB)
xineplug_dmx_matroska_la_SOURCES = demux_matroska.c ebml.c
xineplug_dmx_matroska_la_LIBADD = $(XINE_LIB) $(ZLIB_LIBS)
-xineplug_dmx_matroska_la_CPPFLAGS = $(ZLIB_CPPFLAGS)
xineplug_dmx_matroska_la_CFLAGS = $(AM_CFLAGS) -fno-strict-aliasing
+xineplug_dmx_matroska_la_CPPFLAGS = $(AM_CPPFLAGS) $(ZLIB_CPPFLAGS)
xineplug_dmx_iff_la_SOURCES = demux_iff.c
xineplug_dmx_iff_la_LIBADD = $(XINE_LIB)
xineplug_dmx_flv_la_SOURCES = demux_flv.c
xineplug_dmx_flv_la_LIBADD = $(XINE_LIB)
-
-xineinclude_HEADERS = demux.h
-noinst_HEADERS = asfheader.h qtpalette.h group_games.h group_audio.h id3.h ebml.h matroska.h iff.h flacutils.h
diff --git a/src/demuxers/demux_film.c b/src/demuxers/demux_film.c
index d3cedc0e1..69c3eea60 100644
--- a/src/demuxers/demux_film.c
+++ b/src/demuxers/demux_film.c
@@ -258,7 +258,7 @@ static int open_film_file(demux_film_t *film) {
film->frequency = BE_32(&film_header[i + 8]);
film->sample_count = BE_32(&film_header[i + 12]);
film->sample_table =
- xine_xmalloc(film->sample_count * sizeof(film_sample_t));
+ xine_xcalloc(film->sample_count, sizeof(film_sample_t));
for (j = 0; j < film->sample_count; j++) {
film->sample_table[j].sample_offset =
diff --git a/src/demuxers/demux_flac.c b/src/demuxers/demux_flac.c
index 3c343bdf2..ac7458726 100644
--- a/src/demuxers/demux_flac.c
+++ b/src/demuxers/demux_flac.c
@@ -166,8 +166,8 @@ static int open_flac_file(demux_flac_t *flac) {
case 3:
lprintf ("SEEKTABLE metadata, %d bytes\n", block_length);
flac->seekpoint_count = block_length / FLAC_SEEKPOINT_SIZE;
- flac->seekpoints = xine_xmalloc(flac->seekpoint_count *
- sizeof(flac_seekpoint_t));
+ flac->seekpoints = xine_xcalloc(flac->seekpoint_count,
+ sizeof(flac_seekpoint_t));
for (i = 0; i < flac->seekpoint_count; i++) {
if (flac->input->read(flac->input, buffer, FLAC_SEEKPOINT_SIZE) != FLAC_SEEKPOINT_SIZE)
return 0;
diff --git a/src/demuxers/demux_flv.c b/src/demuxers/demux_flv.c
index 0588b408e..5de878b4d 100644
--- a/src/demuxers/demux_flv.c
+++ b/src/demuxers/demux_flv.c
@@ -278,7 +278,7 @@ static int parse_flv_var(demux_flv_t *this,
if (key && keylen == 5 && !strncmp(key, "times", 5)) {
if (this->index)
free (this->index);
- this->index = xine_xmalloc(num*sizeof(flv_index_entry_t));
+ this->index = xine_xcalloc(num, sizeof(flv_index_entry_t));
this->num_indices = num;
for (num = 0; num < this->num_indices && tmp < end; num++) {
if (*tmp++ == FLV_DATA_TYPE_NUMBER) {
diff --git a/src/demuxers/demux_matroska.c b/src/demuxers/demux_matroska.c
index 2bd8f3540..92986bf83 100644
--- a/src/demuxers/demux_matroska.c
+++ b/src/demuxers/demux_matroska.c
@@ -68,13 +68,6 @@
#define MAX(a, b) ((a)>(b)?(a):(b))
#endif
-/* FOURCC will be manipulated using machine endian */
-#ifdef WORDS_BIGENDIAN
-#define meFOURCC BE_FOURCC
-#else
-#define meFOURCC LE_FOURCC
-#endif
-
typedef struct {
int track_num;
off_t *pos;
@@ -1320,7 +1313,7 @@ static int parse_track_entry(demux_matroska_t *this, matroska_track_t *track) {
/* create a bitmap info header struct for MPEG 4 */
bih = malloc(sizeof(xine_bmiheader) + track->codec_private_len);
bih->biSize = sizeof(xine_bmiheader) + track->codec_private_len;
- bih->biCompression = meFOURCC('M', 'P', '4', 'S');
+ bih->biCompression = ME_FOURCC('M', 'P', '4', 'S');
bih->biWidth = track->video_track->pixel_width;
bih->biHeight = track->video_track->pixel_height;
_x_bmiheader_le2me(bih);
@@ -1341,7 +1334,7 @@ static int parse_track_entry(demux_matroska_t *this, matroska_track_t *track) {
/* create a bitmap info header struct for h264 */
bih = malloc(sizeof(xine_bmiheader) + track->codec_private_len);
bih->biSize = sizeof(xine_bmiheader) + track->codec_private_len;
- bih->biCompression = meFOURCC('a', 'v', 'c', '1');
+ bih->biCompression = ME_FOURCC('a', 'v', 'c', '1');
bih->biWidth = track->video_track->pixel_width;
bih->biHeight = track->video_track->pixel_height;
_x_bmiheader_le2me(bih);
diff --git a/src/demuxers/demux_mod.c b/src/demuxers/demux_mod.c
index 37e066b13..9acddd878 100644
--- a/src/demuxers/demux_mod.c
+++ b/src/demuxers/demux_mod.c
@@ -31,8 +31,6 @@
#include "config.h"
#endif
-#ifdef HAVE_MODPLUG
-
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
@@ -48,7 +46,6 @@
#include "xineutils.h"
#include "compat.h"
#include "demux.h"
-#include "group_audio.h"
#include "modplug.h"
#include "bswap.h"
@@ -377,7 +374,7 @@ static void class_dispose (demux_class_t *this_gen) {
free (this);
}
-void *demux_mod_init_plugin (xine_t *xine, void *data) {
+static void *demux_mod_init_plugin (xine_t *xine, void *data) {
demux_mod_class_t *this;
this = xine_xmalloc (sizeof (demux_mod_class_t));
@@ -392,4 +389,11 @@ void *demux_mod_init_plugin (xine_t *xine, void *data) {
return this;
}
-#endif /* HAVE_MODPLUG */
+static const demuxer_info_t demux_info_mod = {
+ 10 /* priority */
+};
+
+const plugin_info_t xine_plugin_info[] EXPORTED = {
+ { PLUGIN_DEMUX, 26, "modplug", XINE_VERSION_CODE, &demux_info_mod, demux_mod_init_plugin },
+ { PLUGIN_NONE, 0, "", 0, NULL, NULL }
+};
diff --git a/src/demuxers/demux_mpgaudio.c b/src/demuxers/demux_mpgaudio.c
index f675e227a..64bae2794 100644
--- a/src/demuxers/demux_mpgaudio.c
+++ b/src/demuxers/demux_mpgaudio.c
@@ -413,7 +413,7 @@ static vbri_header_t* parse_vbri_header(mpg_audio_frame_t *frame,
lprintf("entry_frames: %d\n", vbri->entry_frames);
if ((ptr + (vbri->toc_entries + 1) * vbri->entry_size) >= (buf + bufsize)) return 0;
- vbri->toc = xine_xmalloc (sizeof(int) * (vbri->toc_entries + 1));
+ vbri->toc = xine_xcalloc ((vbri->toc_entries + 1), sizeof(int));
if (!vbri->toc) {
free (vbri);
return NULL;
diff --git a/src/demuxers/demux_nsf.c b/src/demuxers/demux_nsf.c
deleted file mode 100644
index 7408274d5..000000000
--- a/src/demuxers/demux_nsf.c
+++ /dev/null
@@ -1,392 +0,0 @@
-/*
- * Copyright (C) 2000-2003 the xine project
- *
- * This file is part of xine, a free video player.
- *
- * xine 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.
- *
- * xine is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
-
-/*
- * NSF File "Demuxer" by Mike Melanson (melanson@pcisys.net)
- * This is really just a loader for NES Music File Format (extension NSF)
- * which loads an entire NSF file and passes it over to the NSF audio
- * decoder.
- *
- * After the file is sent over, the demuxer controls the playback by
- * sending empty buffers with incrementing pts values.
- *
- * For more information regarding the NSF format, visit:
- * http://www.tripoint.org/kevtris/nes/nsfspec.txt
- *
- * $Id: demux_nsf.c,v 1.24 2007/03/29 17:03:06 dgp85 Exp $
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <stdio.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-
-/********** logging **********/
-#define LOG_MODULE "demux_nsf"
-/* #define LOG_VERBOSE */
-/* #define LOG */
-
-#include "xine_internal.h"
-#include "xineutils.h"
-#include "compat.h"
-#include "demux.h"
-#include "bswap.h"
-#include "group_audio.h"
-
-#define NSF_HEADER_SIZE 0x80
-#define NSF_SAMPLERATE 44100
-#define NSF_BITS 8
-#define NSF_CHANNELS 1
-#define NSF_REFRESH_RATE 60
-#define NSF_PTS_INC (90000 / NSF_REFRESH_RATE)
-
-typedef struct {
- demux_plugin_t demux_plugin;
-
- xine_stream_t *stream;
- fifo_buffer_t *video_fifo;
- fifo_buffer_t *audio_fifo;
- input_plugin_t *input;
- int status;
-
- int total_songs;
- int current_song;
- int new_song; /* indicates song change */
-
- char *title;
- char *artist;
- char *copyright;
-
- off_t filesize;
-
- int64_t current_pts;
- int file_sent;
-} demux_nsf_t;
-
-typedef struct {
- demux_class_t demux_class;
-} demux_nsf_class_t;
-
-/* returns 1 if the NSF file was opened successfully, 0 otherwise */
-static int open_nsf_file(demux_nsf_t *this) {
- unsigned char header[NSF_HEADER_SIZE];
-
- this->input->seek(this->input, 0, SEEK_SET);
- if (this->input->read(this->input, header, NSF_HEADER_SIZE) !=
- NSF_HEADER_SIZE)
- return 0;
-
- /* check for the signature */
- if ((header[0] != 'N') ||
- (header[1] != 'E') ||
- (header[2] != 'S') ||
- (header[3] != 'M') ||
- (header[4] != 0x1A))
- return 0;
-
- this->total_songs = header[6];
- this->current_song = header[7];
- this->title = strdup(&header[0x0E]);
- this->artist = strdup(&header[0x2E]);
- this->copyright = strdup(&header[0x4E]);
-
- this->filesize = this->input->get_length(this->input);
-
- return 1;
-}
-
-static int demux_nsf_send_chunk(demux_plugin_t *this_gen) {
- demux_nsf_t *this = (demux_nsf_t *) this_gen;
- buf_element_t *buf;
- int bytes_read;
- char title[100];
-
- /* send chunks of the file to the decoder until file is completely
- * loaded; then send control buffers */
- if (!this->file_sent) {
- buf = this->audio_fifo->buffer_pool_alloc (this->audio_fifo);
- buf->type = BUF_AUDIO_NSF;
- bytes_read = this->input->read(this->input, buf->content, buf->max_size);
-
- if (bytes_read == 0) {
- /* the file has been completely loaded, free the buffer and start
- * sending control buffers */
- buf->free_buffer(buf);
- this->file_sent = 1;
-
- } else {
-
- /* keep loading the file */
- if (bytes_read < buf->max_size)
- buf->size = bytes_read;
- else
- buf->size = buf->max_size;
-
- buf->extra_info->input_normpos = 0;
- buf->extra_info->input_time = 0;
- buf->pts = 0;
-
- this->audio_fifo->put (this->audio_fifo, buf);
- }
- }
-
- /* this is not an 'else' because control might fall through from above */
- if (this->file_sent) {
- /* send a control buffer */
- buf = this->audio_fifo->buffer_pool_alloc (this->audio_fifo);
-
- if (this->new_song) {
-
- buf->decoder_info[1] = this->current_song;
- this->new_song = 0;
- sprintf(title, "%s, song %d/%d",
- this->title, this->current_song, this->total_songs);
-
- _x_meta_info_set(this->stream, XINE_META_INFO_TITLE, title);
-
- _x_demux_control_newpts(this->stream, this->current_pts, 0);
-
- } else
- buf->decoder_info[1] = 0;
-
- buf->type = BUF_AUDIO_NSF;
- if(this->total_songs)
- buf->extra_info->input_normpos = (this->current_song - 1) * 65535 / this->total_songs;
- buf->extra_info->input_time = this->current_pts / 90;
- buf->pts = this->current_pts;
- buf->size = 0;
- this->audio_fifo->put (this->audio_fifo, buf);
-
- this->current_pts += NSF_PTS_INC;
- }
-
- return this->status;
-}
-
-static void demux_nsf_send_headers(demux_plugin_t *this_gen) {
- demux_nsf_t *this = (demux_nsf_t *) this_gen;
- buf_element_t *buf;
- char copyright[100];
-
- this->video_fifo = this->stream->video_fifo;
- this->audio_fifo = this->stream->audio_fifo;
-
- this->status = DEMUX_OK;
-
- /* load stream information */
- _x_stream_info_set(this->stream, XINE_STREAM_INFO_HAS_VIDEO, 0);
- _x_stream_info_set(this->stream, XINE_STREAM_INFO_HAS_AUDIO, 1);
- _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_CHANNELS,
- NSF_CHANNELS);
- _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_SAMPLERATE,
- NSF_SAMPLERATE);
- _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITS,
- NSF_BITS);
-
- _x_meta_info_set(this->stream, XINE_META_INFO_TITLE, this->title);
- _x_meta_info_set(this->stream, XINE_META_INFO_ARTIST, this->artist);
- sprintf(copyright, "(C) %s", this->copyright);
- _x_meta_info_set(this->stream, XINE_META_INFO_COMMENT, copyright);
-
- /* send start buffers */
- _x_demux_control_start(this->stream);
-
- /* send init info to the audio decoder */
- if (this->audio_fifo) {
- buf = this->audio_fifo->buffer_pool_alloc (this->audio_fifo);
- buf->type = BUF_AUDIO_NSF;
- buf->decoder_flags = BUF_FLAG_HEADER|BUF_FLAG_FRAME_END;
- buf->decoder_info[0] = 5;
- buf->decoder_info[1] = NSF_SAMPLERATE;
- buf->decoder_info[2] = NSF_BITS;
- buf->decoder_info[3] = NSF_CHANNELS;
-
- /* send the NSF filesize in the body, big endian format */
- buf->content[0] = (this->filesize >> 24) & 0xFF;
- buf->content[1] = (this->filesize >> 16) & 0xFF;
- buf->content[2] = (this->filesize >> 8) & 0xFF;
- buf->content[3] = (this->filesize >> 0) & 0xFF;
- /* send the requested song */
- buf->content[4] = this->current_song + 5;
-
- this->audio_fifo->put (this->audio_fifo, buf);
- }
-}
-
-static int demux_nsf_seek (demux_plugin_t *this_gen,
- off_t start_pos, int start_time, int playing) {
-
- demux_nsf_t *this = (demux_nsf_t *) this_gen;
- start_pos = (off_t) ( (double) start_pos / 65535 *
- this->total_songs );
-
- /* if thread is not running, initialize demuxer */
- if( !playing ) {
-
- /* send new pts */
- _x_demux_control_newpts(this->stream, 0, 0);
-
- this->status = DEMUX_OK;
-
- /* reposition stream at the start for loading */
- this->input->seek(this->input, 0, SEEK_SET);
-
- this->file_sent = 0;
- this->current_pts = 0;
- this->new_song = 1;
- } else {
- this->current_song = start_pos + 1;
- this->new_song = 1;
- this->current_pts = 0;
- _x_demux_flush_engine(this->stream);
- }
-
- return this->status;
-}
-
-static void demux_nsf_dispose (demux_plugin_t *this_gen) {
- demux_nsf_t *this = (demux_nsf_t *) this_gen;
-
- free(this->title);
- free(this->artist);
- free(this->copyright);
- free(this);
-}
-
-static int demux_nsf_get_status (demux_plugin_t *this_gen) {
- demux_nsf_t *this = (demux_nsf_t *) this_gen;
-
- return this->status;
-}
-
-/* return the approximate length in miliseconds */
-static int demux_nsf_get_stream_length (demux_plugin_t *this_gen) {
- return 0;
-}
-
-static uint32_t demux_nsf_get_capabilities(demux_plugin_t *this_gen) {
- return DEMUX_CAP_NOCAP;
-}
-
-static int demux_nsf_get_optional_data(demux_plugin_t *this_gen,
- void *data, int data_type) {
- return DEMUX_OPTIONAL_UNSUPPORTED;
-}
-
-static demux_plugin_t *open_plugin (demux_class_t *class_gen, xine_stream_t *stream,
- input_plugin_t *input) {
-
- demux_nsf_t *this;
-
- if (!INPUT_IS_SEEKABLE(input)) {
- xprintf(stream->xine, XINE_VERBOSITY_DEBUG, "input not seekable, can not handle!\n");
- return NULL;
- }
-
- this = xine_xmalloc (sizeof (demux_nsf_t));
- this->stream = stream;
- this->input = input;
-
- this->demux_plugin.send_headers = demux_nsf_send_headers;
- this->demux_plugin.send_chunk = demux_nsf_send_chunk;
- this->demux_plugin.seek = demux_nsf_seek;
- this->demux_plugin.dispose = demux_nsf_dispose;
- this->demux_plugin.get_status = demux_nsf_get_status;
- this->demux_plugin.get_stream_length = demux_nsf_get_stream_length;
- this->demux_plugin.get_capabilities = demux_nsf_get_capabilities;
- this->demux_plugin.get_optional_data = demux_nsf_get_optional_data;
- this->demux_plugin.demux_class = class_gen;
-
- this->status = DEMUX_FINISHED;
-
- switch (stream->content_detection_method) {
-
- case METHOD_BY_EXTENSION: {
- const char *extensions, *mrl;
-
- mrl = input->get_mrl (input);
- extensions = class_gen->get_extensions (class_gen);
-
- if (!_x_demux_check_extension (mrl, extensions)) {
- free (this);
- return NULL;
- }
- }
- /* falling through is intended */
-
- case METHOD_BY_CONTENT:
- case METHOD_EXPLICIT:
-
- if (!open_nsf_file(this)) {
- free (this);
- return NULL;
- }
-
- break;
-
- default:
- free (this);
- return NULL;
- }
-
- return &this->demux_plugin;
-}
-
-static const char *get_description (demux_class_t *this_gen) {
- return "NES Music file demux plugin";
-}
-
-static const char *get_identifier (demux_class_t *this_gen) {
- return "NSF";
-}
-
-static const char *get_extensions (demux_class_t *this_gen) {
- return "nsf";
-}
-
-static const char *get_mimetypes (demux_class_t *this_gen) {
- return NULL;
-}
-
-static void class_dispose (demux_class_t *this_gen) {
- demux_nsf_class_t *this = (demux_nsf_class_t *) this_gen;
-
- free (this);
-}
-
-void *demux_nsf_init_plugin (xine_t *xine, void *data) {
- demux_nsf_class_t *this;
-
- this = xine_xmalloc (sizeof (demux_nsf_class_t));
-
- this->demux_class.open_plugin = open_plugin;
- this->demux_class.get_description = get_description;
- this->demux_class.get_identifier = get_identifier;
- this->demux_class.get_mimetypes = get_mimetypes;
- this->demux_class.get_extensions = get_extensions;
- this->demux_class.dispose = class_dispose;
-
- return this;
-}
diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c
index 23a45c792..1b82a288d 100644
--- a/src/demuxers/demux_qt.c
+++ b/src/demuxers/demux_qt.c
@@ -136,8 +136,10 @@ typedef unsigned int qt_atom;
#define MAX_PTS_DIFF 100000
-/* network bandwidth, cribbed from src/input/input_mms.c */
-const int64_t bandwidths[]={14400,19200,28800,33600,34430,57600,
+/**
+ * @brief Network bandwidth, cribbed from src/input/input_mms.c
+ */
+static const int64_t bandwidths[]={14400,19200,28800,33600,34430,57600,
115200,262200,393216,524300,1544000,10485800};
/* these are things that can go wrong */
@@ -411,10 +413,6 @@ typedef struct {
#define DEBUG_DUMP_MOOV 0
#define RAW_MOOV_FILENAME "moovatom.raw"
-#ifndef __GNUC__
-#define __attribute__(x)
-#endif
-
#if DEBUG_ATOM_LOAD
#define debug_atom_load printf
#else
@@ -936,12 +934,11 @@ static qt_error parse_trak_atom (qt_trak *trak,
/* allocate space for each of the properties unions */
trak->stsd_atoms_count = BE_32(&trak_atom[i + 8]);
- trak->stsd_atoms = xine_xmalloc(trak->stsd_atoms_count * sizeof(properties_t));
+ trak->stsd_atoms = xine_xcalloc(trak->stsd_atoms_count, sizeof(properties_t));
if (!trak->stsd_atoms) {
last_error = QT_NO_MEMORY;
goto free_trak;
}
- memset(trak->stsd_atoms, 0, trak->stsd_atoms_count * sizeof(properties_t));
atom_pos = i + 0x10;
properties_offset = 0x0C;
diff --git a/src/demuxers/demux_real.c b/src/demuxers/demux_real.c
index 11b0dbf38..f0488bc47 100644
--- a/src/demuxers/demux_real.c
+++ b/src/demuxers/demux_real.c
@@ -692,7 +692,7 @@ unknown:
this->video_stream->mdpr->avg_bit_rate);
/* Allocate fragment offset table */
- this->fragment_tab = xine_xmalloc(FRAGMENT_TAB_SIZE*sizeof(uint32_t));
+ this->fragment_tab = xine_xcalloc(FRAGMENT_TAB_SIZE, sizeof(uint32_t));
this->fragment_tab_max = FRAGMENT_TAB_SIZE;
}
@@ -1282,7 +1282,7 @@ static int demux_real_send_chunk(demux_plugin_t *this_gen) {
frames = (stream_read_word(this) & 0xf0) >> 4;
/* 2 bytes per frame size */
- sizes = xine_xmalloc(frames*sizeof(int));
+ sizes = xine_xcalloc(frames, sizeof(int));
for(i = 0; i < frames; i++)
sizes[i] = stream_read_word(this);
diff --git a/src/demuxers/demux_ts.c b/src/demuxers/demux_ts.c
index f2da5f268..b40c7d49f 100644
--- a/src/demuxers/demux_ts.c
+++ b/src/demuxers/demux_ts.c
@@ -2226,9 +2226,7 @@ static demux_plugin_t *open_plugin (demux_class_t *class_gen,
this->status = DEMUX_FINISHED;
#ifdef TS_READ_STATS
- for (i=0; i<=NPKT_PER_READ; i++) {
- this->rstat[i] = 0;
- }
+ memset(this-rstat, 0, sizeof(*this->rstat)*NPKT_PER_READ);
#endif
/* DVBSUB */
diff --git a/src/demuxers/demux_tta.c b/src/demuxers/demux_tta.c
index 2e4808b9c..724404a5b 100644
--- a/src/demuxers/demux_tta.c
+++ b/src/demuxers/demux_tta.c
@@ -65,16 +65,14 @@ typedef struct {
demux_class_t demux_class;
} demux_tta_class_t;
-#define FOURCC_32(a, b, c, d) (d + (c<<8) + (b<<16) + (a<<24))
-
static int open_tta_file(demux_tta_t *this) {
- uint8_t peek[4];
+ uint32_t peek;
uint32_t framelen;
- if (_x_demux_read_header(this->input, peek, 4) != 4)
+ if (_x_demux_read_header(this->input, &peek, 4) != 4)
return 0;
- if ( BE_32(peek) != FOURCC_32('T', 'T', 'A', '1') )
+ if ( peek != ME_FOURCC('T', 'T', 'A', '1') )
return 0;
if ( this->input->read(this->input, this->header.buffer, sizeof(this->header)) != sizeof(this->header) )
@@ -89,7 +87,7 @@ static int open_tta_file(demux_tta_t *this) {
return 0;
}
- this->seektable = xine_xmalloc(sizeof(uint32_t)*this->totalframes);
+ this->seektable = xine_xcalloc(this->totalframes, sizeof(uint32_t));
this->input->read(this->input, this->seektable, sizeof(uint32_t)*this->totalframes);
/* Skip the CRC32 */
diff --git a/src/demuxers/demux_wc3movie.c b/src/demuxers/demux_wc3movie.c
index fa1cfb17d..8645c9189 100644
--- a/src/demuxers/demux_wc3movie.c
+++ b/src/demuxers/demux_wc3movie.c
@@ -380,17 +380,15 @@ static int open_mve_file(demux_mve_t *this) {
this->number_of_shots = LE_32(&preamble[0]);
/* allocate space for the shot offset index and set offsets to 0 */
- this->shot_offsets = xine_xmalloc(this->number_of_shots * sizeof(off_t));
+ this->shot_offsets = xine_xcalloc(this->number_of_shots, sizeof(off_t));
this->current_shot = 0;
- for (i = 0; i < this->number_of_shots; i++)
- this->shot_offsets[i] = 0;
/* skip the SOND chunk */
this->input->seek(this->input, 12, SEEK_CUR);
/* load the palette chunks */
- this->palettes = xine_xmalloc(this->number_of_shots * PALETTE_SIZE *
- sizeof(palette_entry_t));
+ this->palettes = xine_xcalloc(this->number_of_shots, PALETTE_SIZE *
+ sizeof(palette_entry_t));
for (i = 0; i < this->number_of_shots; i++) {
/* make sure there was a valid palette chunk preamble */
if (this->input->read(this->input, preamble, PREAMBLE_SIZE) !=
diff --git a/src/demuxers/group_audio.c b/src/demuxers/group_audio.c
index b8f0e1ed4..8c1efdde6 100644
--- a/src/demuxers/group_audio.c
+++ b/src/demuxers/group_audio.c
@@ -71,10 +71,6 @@ static const demuxer_info_t demux_info_mpc = {
0 /* priority */
};
-static const demuxer_info_t demux_info_nsf = {
- 10 /* priority */
-};
-
static const demuxer_info_t demux_info_realaudio = {
10 /* priority */
};
@@ -103,12 +99,6 @@ static const demuxer_info_t demux_info_wav = {
6 /* priority */
};
-#ifdef HAVE_MODPLUG
-static const demuxer_info_t demux_info_mod = {
- 10 /* priority */
-};
-#endif
-
const plugin_info_t xine_plugin_info[] EXPORTED = {
/* type, API, "name", version, special_info, init_function */
{ PLUGIN_DEMUX, 26, "aac", XINE_VERSION_CODE, &demux_info_aac, demux_aac_init_plugin },
@@ -120,7 +110,6 @@ const plugin_info_t xine_plugin_info[] EXPORTED = {
{ PLUGIN_DEMUX, 26, "flac", XINE_VERSION_CODE, &demux_info_flac, demux_flac_init_plugin },
{ PLUGIN_DEMUX, 26, "mp3", XINE_VERSION_CODE, &demux_info_mpgaudio, demux_mpgaudio_init_class },
{ PLUGIN_DEMUX, 26, "mpc", XINE_VERSION_CODE, &demux_info_mpc, demux_mpc_init_plugin },
- { PLUGIN_DEMUX, 26, "nsf", XINE_VERSION_CODE, &demux_info_nsf, demux_nsf_init_plugin },
{ PLUGIN_DEMUX, 26, "realaudio", XINE_VERSION_CODE, &demux_info_realaudio, demux_realaudio_init_plugin },
{ PLUGIN_DEMUX, 26, "shn", XINE_VERSION_CODE, &demux_info_shn, demux_shn_init_plugin },
{ PLUGIN_DEMUX, 26, "snd", XINE_VERSION_CODE, &demux_info_snd, demux_snd_init_plugin },
@@ -128,8 +117,5 @@ const plugin_info_t xine_plugin_info[] EXPORTED = {
{ PLUGIN_DEMUX, 26, "voc", XINE_VERSION_CODE, &demux_info_voc, demux_voc_init_plugin },
{ PLUGIN_DEMUX, 26, "vox", XINE_VERSION_CODE, &demux_info_vox, demux_vox_init_plugin },
{ PLUGIN_DEMUX, 26, "wav", XINE_VERSION_CODE, &demux_info_wav, demux_wav_init_plugin },
-#ifdef HAVE_MODPLUG
- { PLUGIN_DEMUX, 26, "mod", XINE_VERSION_CODE, &demux_info_mod, demux_mod_init_plugin },
-#endif
{ PLUGIN_NONE, 0, "", 0, NULL, NULL }
};
diff --git a/src/demuxers/group_audio.h b/src/demuxers/group_audio.h
index 7f1fccc5e..984b7c88e 100644
--- a/src/demuxers/group_audio.h
+++ b/src/demuxers/group_audio.h
@@ -34,7 +34,6 @@ void *demux_dts_init_plugin (xine_t *xine, void *data);
void *demux_flac_init_plugin (xine_t *xine, void *data);
void *demux_mpgaudio_init_class (xine_t *xine, void *data);
void *demux_mpc_init_plugin (xine_t *xine, void *data);
-void *demux_nsf_init_plugin (xine_t *xine, void *data);
void *demux_realaudio_init_plugin (xine_t *xine, void *data);
void *demux_shn_init_plugin (xine_t *xine, void *data);
void *demux_snd_init_plugin (xine_t *xine, void *data);
@@ -43,8 +42,4 @@ void *demux_voc_init_plugin (xine_t *xine, void *data);
void *demux_vox_init_plugin (xine_t *xine, void *data);
void *demux_wav_init_plugin (xine_t *xine, void *data);
-#ifdef HAVE_MODPLUG
-void *demux_mod_init_plugin (xine_t *xine, void *data);
-#endif
-
#endif
diff --git a/src/dxr3/Makefile.am b/src/dxr3/Makefile.am
index 5f413f804..26743d43c 100644
--- a/src/dxr3/Makefile.am
+++ b/src/dxr3/Makefile.am
@@ -1,40 +1,41 @@
include $(top_srcdir)/misc/Makefile.common
-AM_CFLAGS = $(X_CFLAGS) $(LIBFAME_CFLAGS)
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+AM_CPPFLAGS =
+AM_LDFLAGS = $(xineplug_ldflags)
-if HAVE_DXR3
-dxr3_modules = xineplug_decode_dxr3_video.la \
- xineplug_decode_dxr3_spu.la \
- xineplug_vo_out_dxr3.la
-endif
if HAVE_X11
+AM_CFLAGS += $(X_CFLAGS)
link_x_libs = $(X_LIBS) -lXext
endif
if HAVE_LIBFAME
-link_fame = $(LIBFAME_LIBS)
+AM_CFLAGS += $(LIBFAME_CFLAGS)
+link_fame = $(LIBFAME_LIBS)
endif
if HAVE_LIBRTE
link_rte = -lrte
endif
-xineplug_LTLIBRARIES = $(dxr3_modules)
+noinst_HEADERS = em8300.h dxr3.h dxr3_scr.h video_out_dxr3.h
+
+if ENABLE_DXR3
+xineplug_LTLIBRARIES = xineplug_decode_dxr3_video.la \
+ xineplug_decode_dxr3_spu.la \
+ xineplug_vo_out_dxr3.la
+endif
xineplug_decode_dxr3_video_la_SOURCES = dxr3_decode_video.c
xineplug_decode_dxr3_video_la_LIBADD = $(XINE_LIB)
-xineplug_decode_dxr3_video_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS)
-xineplug_decode_dxr3_video_la_LDFLAGS = -avoid-version -module
-if HAVE_DVDNAV
-AM_CPPFLAGS = $(DVDNAV_CFLAGS)
+if WITH_EXTERNAL_DVDNAV
xineplug_decode_dxr3_spu_la_SOURCES = dxr3_decode_spu.c
xineplug_decode_dxr3_spu_la_LIBADD = $(XINE_LIB) $(DVDNAV_LIBS)
+xineplug_decode_dxr3_spu_la_CFLAGS = $(AM_CFLAGS) $(DVDNAV_CFLAGS)
else
-AM_CPPFLAGS = -I$(top_srcdir)/src/input/libdvdnav
xineplug_decode_dxr3_spu_la_SOURCES = dxr3_decode_spu.c nav_read.c
xineplug_decode_dxr3_spu_la_LIBADD = $(XINE_LIB)
+xineplug_decode_dxr3_spu_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/src/input/libdvdnav
endif
-xineplug_decode_dxr3_spu_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS)
-xineplug_decode_dxr3_spu_la_LDFLAGS = -avoid-version -module
xineplug_vo_out_dxr3_la_SOURCES = \
dxr3_mpeg_encoders.c \
@@ -43,11 +44,3 @@ xineplug_vo_out_dxr3_la_SOURCES = \
video_out_dxr3.c
xineplug_vo_out_dxr3_la_LIBADD = $(link_fame) $(link_rte) $(link_x_libs) $(XINE_LIB) $(DYNAMIC_LD_LIBS) -lm
-xineplug_vo_out_dxr3_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS)
-xineplug_vo_out_dxr3_la_LDFLAGS = -avoid-version -module
-
-noinst_HEADERS = \
- em8300.h \
- dxr3.h \
- dxr3_scr.h \
- video_out_dxr3.h
diff --git a/src/input/Makefile.am b/src/input/Makefile.am
index a2a1ea3a4..f9f9a9fb8 100644
--- a/src/input/Makefile.am
+++ b/src/input/Makefile.am
@@ -1,12 +1,8 @@
include $(top_srcdir)/misc/Makefile.common
-EXTRA_DIST = input_dvd.c input_vcd.c input_gnome_vfs.c input_rtp.c
-
-if HAVE_DVDNAV
-SUBDIRS = vcd dvb libreal librtsp
-else
-SUBDIRS = vcd dvb libreal librtsp libdvdnav
-endif
+# REVISIT: This second line here bothers me more than just a little bit
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+AM_LDFLAGS = $(xineplug_ldflags)
##
# IMPORTANT:
@@ -14,46 +10,61 @@ endif
# All of xine input plugins should be named like the scheme "xineplug_inp_"
#
-if HAVE_CDROM_IOCTLS
+SUBDIRS = libreal librtsp
+if ENABLE_DVB
+SUBDIRS += dvb
+endif
+if ENABLE_VCD
+SUBDIRS += vcd
+endif
+if !WITH_EXTERNAL_DVDNAV
+SUBDIRS += libdvdnav
+endif
+
+
+xineinclude_HEADERS = input_plugin.h
+noinst_HEADERS = net_buf_ctrl.h mms.h mmsh.h pnm.h media_helper.h videodev2.h http_helper.h
+
+
+if ENABLE_DVB
+in_dvb = xineplug_inp_dvb.la
+endif
+
+if ENABLE_VCDO
in_vcd = xineplug_inp_vcdo.la
endif
-if HAVE_V4L
+if ENABLE_V4L
in_v4l = xineplug_inp_v4l.la
in_pvr = xineplug_inp_pvr.la
endif
-if HAVE_GNOME_VFS
+if ENABLE_GNOME_VFS
in_gnome_vfs = xineplug_inp_gnome_vfs.la
endif
-if HAVE_LIBSMBCLIENT
+if ENABLE_LIBSMBCLIENT
in_smb = xineplug_inp_smb.la
endif
-# For DVD
-in_dvd = xineplug_inp_dvd.la
-if HAVE_DVDNAV
-DVD_CFLAGS = $(DVDNAV_CFLAGS)
+if WITH_EXTERNAL_DVDNAV
+DVD_CFLAGS = $(DVDNAV_CFLAGS)
link_dvdnav = $(DVDNAV_LIBS)
else
-DVD_CFLAGS = -I$(top_srcdir)/src/input/libdvdnav/
+DVD_CFLAGS = -I$(top_srcdir)/src/input/libdvdnav
link_dvdnav = libdvdnav/libdvdnav.la
endif
# not ported to native Windows
-if WIN32
-else
+if !WIN32
in_rtp = xineplug_inp_rtp.la
-in_dvb = xineplug_inp_dvb.la
endif
-AM_CFLAGS = -D_LARGEFILE64_SOURCE $(GNOME_VFS_CFLAGS) $(ALSA_CFLAGS) $(DVD_CFLAGS)
xineplug_LTLIBRARIES = \
xineplug_inp_file.la \
xineplug_inp_http.la \
- $(in_dvd) \
+ xineplug_inp_dvd.la \
$(in_vcd) \
$(in_v4l) \
$(in_gnome_vfs) \
@@ -71,84 +82,55 @@ xineplug_LTLIBRARIES = \
xineplug_inp_file_la_SOURCES = input_file.c
xineplug_inp_file_la_LIBADD = $(XINE_LIB)
-xineplug_inp_file_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS)
-xineplug_inp_file_la_LDFLAGS = -avoid-version -module
xineplug_inp_dvd_la_SOURCES = input_dvd.c media_helper.c
xineplug_inp_dvd_la_LIBADD = $(XINE_LIB) $(link_dvdnav) $(PTHREAD_LIBS) $(DYNAMIC_LD_LIBS)
-xineplug_inp_dvd_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS)
-xineplug_inp_dvd_la_LDFLAGS = -avoid-version -module
+xineplug_inp_dvd_la_CFLAGS = $(AM_CFLAGS) $(DVD_CFLAGS)
xineplug_inp_net_la_SOURCES = input_net.c net_buf_ctrl.c
xineplug_inp_net_la_LIBADD = $(XINE_LIB) $(NET_LIBS) $(PTHREAD_LIBS)
-xineplug_inp_net_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS)
-xineplug_inp_net_la_LDFLAGS = -avoid-version -module
xineplug_inp_mms_la_SOURCES = input_mms.c net_buf_ctrl.c mms.c mmsh.c http_helper.c ../demuxers/asfheader.c
xineplug_inp_mms_la_LIBADD = $(XINE_LIB) @LIBICONV@ $(PTHREAD_LIBS)
-xineplug_inp_mms_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS)
-xineplug_inp_mms_la_LDFLAGS = -avoid-version -module
xineplug_inp_vcdo_la_SOURCES = input_vcd.c media_helper.c
xineplug_inp_vcdo_la_LIBADD = $(XINE_LIB)
-xineplug_inp_vcdo_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS)
-xineplug_inp_vcdo_la_LDFLAGS = -avoid-version -module
xineplug_inp_stdin_fifo_la_SOURCES = input_stdin_fifo.c net_buf_ctrl.c
xineplug_inp_stdin_fifo_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS)
-xineplug_inp_stdin_fifo_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS)
-xineplug_inp_stdin_fifo_la_LDFLAGS = -avoid-version -module
xineplug_inp_rtp_la_SOURCES = input_rtp.c net_buf_ctrl.c
xineplug_inp_rtp_la_LIBADD = $(XINE_LIB) $(NET_LIBS) $(PTHREAD_LIBS)
-xineplug_inp_rtp_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS)
-xineplug_inp_rtp_la_LDFLAGS = -avoid-version -module
xineplug_inp_http_la_SOURCES = input_http.c net_buf_ctrl.c http_helper.c
xineplug_inp_http_la_LIBADD = $(XINE_LIB) $(NET_LIBS) $(PTHREAD_LIBS)
-xineplug_inp_http_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS)
-xineplug_inp_http_la_LDFLAGS = -avoid-version -module
xineplug_inp_pnm_la_SOURCES = input_pnm.c net_buf_ctrl.c pnm.c
xineplug_inp_pnm_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS)
-xineplug_inp_pnm_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS)
-xineplug_inp_pnm_la_LDFLAGS = -avoid-version -module
xineplug_inp_dvb_la_SOURCES = input_dvb.c net_buf_ctrl.c
-xineplug_inp_dvb_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS)
-xineplug_inp_dvb_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS)
-xineplug_inp_dvb_la_LDFLAGS = -avoid-version -module
+xineplug_inp_dvb_la_DEPS = $(XDG_BASEDIR_DEPS)
+xineplug_inp_dvb_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS) $(XDG_BASEDIR_LIBS)
+xineplug_inp_dvb_la_CPPFLAGS = $(AM_CPPFLAGS) $(XDG_BASEDIR_CPPFLAGS)
xineplug_inp_rtsp_la_SOURCES = input_rtsp.c net_buf_ctrl.c
xineplug_inp_rtsp_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS) libreal/libreal.la librtsp/librtsp.la
-xineplug_inp_rtsp_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS)
-xineplug_inp_rtsp_la_LDFLAGS = -avoid-version -module
xineplug_inp_cdda_la_SOURCES = input_cdda.c media_helper.c sha1.c sha1.h base64.c base64.h
-xineplug_inp_cdda_la_LIBADD = $(XINE_LIB)
-xineplug_inp_cdda_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS)
-xineplug_inp_cdda_la_LDFLAGS = -avoid-version -module
+xineplug_inp_cdda_la_DEPS = $(XDG_BASEDIR_DEPS)
+xineplug_inp_cdda_la_LIBADD = $(XINE_LIB) $(XDG_BASEDIR_LIBS)
+xineplug_inp_cdda_la_CPPFLAGS = $(AM_CPPFLAGS) $(XDG_BASEDIR_CPPFLAGS)
xineplug_inp_v4l_la_SOURCES = input_v4l.c
xineplug_inp_v4l_la_LIBADD = $(ALSA_LIBS) $(XINE_LIB)
-xineplug_inp_v4l_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS)
-xineplug_inp_v4l_la_LDFLAGS = -avoid-version -module
+xineplug_inp_v4l_la_CFLAGS = $(AM_CFLAGS) $(ALSA_CFLAGS)
xineplug_inp_gnome_vfs_la_SOURCES = input_gnome_vfs.c net_buf_ctrl.c
xineplug_inp_gnome_vfs_la_LIBADD = $(GNOME_VFS_LIBS) $(XINE_LIB) $(PTHREAD_LIBS)
-xineplug_inp_gnome_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS)
-xineplug_inp_gnome_vfs_la_LDFLAGS = -avoid-version -module
+xineplug_inp_gnome_vfs_la_CFLAGS = $(AM_CFLAGS) $(GNOME_VFS_CFLAGS)
xineplug_inp_smb_la_SOURCES = input_smb.c
xineplug_inp_smb_la_LIBADD = $(LIBSMBCLIENT_LIBS) $(XINE_LIB)
-xineplug_inp_smb_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS)
-xineplug_inp_smb_la_LDFLAGS = -avoid-version -module
xineplug_inp_pvr_la_SOURCES = input_pvr.c
xineplug_inp_pvr_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS)
-xineplug_inp_pvr_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS)
-xineplug_inp_pvr_la_LDFLAGS = -avoid-version -module
-
-xineinclude_HEADERS = input_plugin.h
-noinst_HEADERS = net_buf_ctrl.h mms.h mmsh.h pnm.h media_helper.h videodev2.h http_helper.h
-
diff --git a/src/input/input_cdda.c b/src/input/input_cdda.c
index 0b1f046e8..80f0bda39 100644
--- a/src/input/input_cdda.c
+++ b/src/input/input_cdda.c
@@ -41,6 +41,9 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
+#ifdef HAVE_ALLOCA_H
+# include <alloca.h>
+#endif
#ifdef HAVE_SYS_IOCTL_H
# include <sys/ioctl.h>
@@ -55,6 +58,8 @@
#include <netinet/in.h>
#include <sys/socket.h>
+#include <basedir.h>
+
#define LOG_MODULE "input_cdda"
#define LOG_VERBOSE
/*
@@ -128,7 +133,6 @@ typedef struct {
int enabled;
char *server;
int port;
- char *cache_dir;
char *cdiscid;
char *disc_title;
@@ -1187,15 +1191,6 @@ static void port_changed_cb(void *data, xine_cfg_entry_t *cfg) {
this->cddb.port = cfg->num_value;
}
}
-static void cachedir_changed_cb(void *data, xine_cfg_entry_t *cfg) {
- cdda_input_class_t *class = (cdda_input_class_t *) data;
-
- if(class->ip) {
- cdda_input_plugin_t *this = class->ip;
-
- this->cddb.cache_dir = cfg->str_value;
- }
-}
#ifdef CDROM_SELECT_SPEED
static void speed_changed_cb(void *data, xine_cfg_entry_t *cfg) {
cdda_input_class_t *class = (cdda_input_class_t *) data;
@@ -1337,18 +1332,6 @@ static void _cdda_mkdir_recursive_safe(xine_t *xine, char *path) {
}
/*
- * Where, by default, cddb cache files will be saved
- */
-static char *_cdda_cddb_get_default_location(void) {
- static char buf[XINE_PATH_MAX + XINE_NAME_MAX + 1];
-
- memset(&buf, 0, sizeof(buf));
- snprintf(buf, sizeof(buf), "%s/.xine/cddbcache", (xine_get_homedir()));
-
- return buf;
-}
-
-/*
* Read from socket, fill char *s, return size length.
*/
static int _cdda_cddb_socket_read(cdda_input_plugin_t *this, char *str, int size) {
@@ -1447,15 +1430,18 @@ static int _cdda_cddb_handle_code(char *buf) {
* Try to load cached cddb infos
*/
static int _cdda_load_cached_cddb_infos(cdda_input_plugin_t *this) {
- char cdir[XINE_PATH_MAX + XINE_NAME_MAX + 1];
+ char *cdir = NULL;
DIR *dir;
+ const char *const xdg_cache_home = xdgCacheHome(this->stream->xine->basedir_handle);
+
if(this == NULL)
return 0;
- memset(&cdir, 0, sizeof(cdir));
- snprintf(cdir, sizeof(cdir), "%s", this->cddb.cache_dir);
-
+ cdir = alloca(strlen(xdg_cache_home) + sizeof("/"PACKAGE"/cddb"));
+ strcpy(cdir, xdg_cache_home);
+ strcat(cdir, "/"PACKAGE"/cddb");
+
if((dir = opendir(cdir)) != NULL) {
struct dirent *pdir;
@@ -1579,20 +1565,24 @@ static int _cdda_load_cached_cddb_infos(cdda_input_plugin_t *this) {
* Save cddb grabbed infos.
*/
static void _cdda_save_cached_cddb_infos(cdda_input_plugin_t *this, char *filecontent) {
- char cfile[XINE_PATH_MAX + XINE_NAME_MAX + 1];
FILE *fd;
-
+ DIR *dir;
+ char *cfile;
+
+ const char *const xdg_cache_home = xdgCacheHome(this->stream->xine->basedir_handle);
+
if((this == NULL) || (filecontent == NULL))
return;
- memset(&cfile, 0, sizeof(cfile));
+ /* the filename is always 8 characters */
+ cfile = alloca(strlen(xdg_cache_home) + sizeof("/"PACKAGE"/cddb") + 9);
+ strcpy(cfile, xdg_cache_home);
+ strcat(cfile, "/"PACKAGE"/cddb");
- /* Ensure "~/.xine/cddbcache" exist */
- snprintf(cfile, sizeof(cfile), "%s", this->cddb.cache_dir);
-
+ /* Ensure the cache directory exists */
_cdda_mkdir_recursive_safe(this->stream->xine, cfile);
- snprintf(cfile, sizeof(cfile), "%s/%08lx", this->cddb.cache_dir, this->cddb.disc_id);
+ sprintf(cfile, "%s/%08lx", cfile, this->cddb.disc_id);
if((fd = fopen(cfile, "w")) == NULL) {
xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG,
@@ -2463,7 +2453,7 @@ static int cdda_plugin_open (input_plugin_t *this_gen ) {
if(this->cddb.num_tracks) {
int t;
- this->cddb.track = (trackinfo_t *) xine_xmalloc(sizeof(trackinfo_t) * this->cddb.num_tracks);
+ this->cddb.track = (trackinfo_t *) xine_xcalloc(this->cddb.num_tracks, sizeof(trackinfo_t));
for(t = 0; t < this->cddb.num_tracks; t++) {
int length = (toc->toc_entries[t].first_frame_minute * CD_SECONDS_PER_MINUTE +
@@ -2689,10 +2679,6 @@ static input_plugin_t *cdda_class_get_instance (input_class_t *cls_gen, xine_str
&port_entry))
port_changed_cb(class, &port_entry);
- if(xine_config_lookup_entry(this->stream->xine, "media.audio_cd.cddb_cachedir",
- &cachedir_entry))
- cachedir_changed_cb(class, &cachedir_entry);
-
class->cddb_error = cddb_error;
return (input_plugin_t *)this;
@@ -2715,7 +2701,6 @@ static void cdda_class_dispose (input_class_t *this_gen) {
config->unregister_callback(config, "media.audio_cd.use_cddb");
config->unregister_callback(config, "media.audio_cd.cddb_server");
config->unregister_callback(config, "media.audio_cd.cddb_port");
- config->unregister_callback(config, "media.audio_cd.cddb_cachedir");
#ifdef CDROM_SELECT_SPEED
config->unregister_callback(config, "media.audio_cd.drive_slowdown");
#endif
@@ -2784,14 +2769,6 @@ static void *init_plugin (xine_t *xine, void *data) {
"title and track information from."), XINE_CONFIG_SECURITY,
port_changed_cb, (void *) this);
- config->register_filename(config, "media.audio_cd.cddb_cachedir",
- (_cdda_cddb_get_default_location()), XINE_CONFIG_STRING_IS_DIRECTORY_NAME,
- _("CDDB cache directory"), _("The replies from the CDDB server will be "
- "cached in this directory.\nThis setting is security critical, because files "
- "with uncontrollable names will be created in this directory. Be sure to use "
- "a dedicated directory not used for anything but CDDB caching."), XINE_CONFIG_SECURITY,
- cachedir_changed_cb, (void *) this);
-
#ifdef CDROM_SELECT_SPEED
config->register_num(config, "media.audio_cd.drive_slowdown", 4,
_("slow down disc drive to this speed factor"),
diff --git a/src/input/input_dvb.c b/src/input/input_dvb.c
index 736b4c6d7..efc3a88d8 100644
--- a/src/input/input_dvb.c
+++ b/src/input/input_dvb.c
@@ -66,14 +66,17 @@
* OSD - this will allow for filtering/searching of epg data - useful for automatic recording :)
*/
-/* pthread.h must be included first so rest of the headers are imported
- thread safely (on some systems). */
-#include <pthread.h>
-
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
+/* pthread.h must be included first so rest of the headers are imported
+ thread safely (on some systems).
+ However, including it before config.h causes problems with asprintf not
+ being declared (glibc 2.3.6)
+*/
+#include <pthread.h>
+
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
@@ -97,6 +100,9 @@
#endif
#include <ctype.h>
+/* XDG */
+#include <basedir.h>
+
/* These will eventually be #include <linux/dvb/...> */
#include "dvb/dmx.h"
#include "dvb/frontend.h"
@@ -887,8 +893,8 @@ static channel_t *load_channels(xine_t *xine, xine_stream_t *stream, int *num_ch
int num_alloc = 0;
int i;
struct stat st;
-
- snprintf(filename, BUFSIZE, "%s/.xine/channels.conf", xine_get_homedir());
+
+ snprintf(filename, BUFSIZE, "%s/"PACKAGE"/channels.conf", xdgConfigHome(xine->basedir_handle));
f = fopen(filename, "r");
if (!f) {
@@ -3162,11 +3168,14 @@ static char **dvb_class_get_autoplay_list(input_class_t * this_gen,
num_channels = 0;
if (!(channels = load_channels(class->xine, NULL, &num_channels, 0))) {
+ static char *placefile = NULL;
/* channels.conf not found in .xine */
- class->mrls[0]="Sorry, No channels.conf found";
- class->mrls[1]="Please run the dvbscan utility";
- class->mrls[2]="from the dvb drivers apps package";
- class->mrls[3]="and place the file in ~/.xine/";
+ class->mrls[0]="Sorry, no channels.conf found.";
+ class->mrls[1]="Please run the scan utility from the DVB";
+ class->mrls[2]="drivers apps package and place the file in";
+ if (!placefile)
+ asprintf (&placefile, "%s/"PACKAGE"/", xdgConfigHome(class->xine->basedir_handle));
+ class->mrls[3]=placefile;
*num_files=4;
return class->mrls;
}
diff --git a/src/input/input_dvd.c b/src/input/input_dvd.c
index de47de0d5..1a8861289 100644
--- a/src/input/input_dvd.c
+++ b/src/input/input_dvd.c
@@ -158,7 +158,7 @@
# define lseek64 lseek
#endif
-static const char *dvdnav_menu_table[] = {
+static const char *const dvdnav_menu_table[] = {
NULL,
NULL,
"Title",
@@ -1629,7 +1629,7 @@ static input_plugin_t *dvd_class_get_instance (input_class_t *class_gen, xine_st
this->mem_stack = 0;
this->mem_stack_max = 1024;
- this->mem = xine_xmalloc(sizeof(unsigned char *) * this->mem_stack_max);
+ this->mem = xine_xcalloc(this->mem_stack_max, sizeof(unsigned char *));
if (!this->mem) {
free(this);
return NULL;
@@ -1791,8 +1791,7 @@ static void *init_class (xine_t *xine, void *data) {
{
/* we have found libdvdcss, enable the specific config options */
char *raw_device;
- static const char *decrypt_modes[] = { "key", "disc", "title", NULL };
- char *css_cache_default, *css_cache;
+ static const char *const decrypt_modes[] = { "key", "disc", "title", NULL };
int mode;
raw_device = config->register_filename(config, "media.dvd.raw_device",
@@ -1817,22 +1816,6 @@ static void *init_class (xine_t *xine, void *data) {
"playing scrambled DVDs."), 20, NULL, NULL);
xine_setenv("DVDCSS_METHOD", decrypt_modes[mode], 0);
- css_cache_default = (char *)malloc(strlen(xine_get_homedir()) + 10);
- sprintf(css_cache_default, "%s/.dvdcss/", xine_get_homedir());
- css_cache = config->register_filename(config, "media.dvd.css_cache_path", css_cache_default, XINE_CONFIG_STRING_IS_DIRECTORY_NAME,
- _("path to the title key cache"),
- _("Since cracking the copy protection of scrambled DVDs can "
- "be quite time consuming, libdvdcss will cache the cracked "
- "keys in this directory.\nThis setting is security critical, "
- "because files with uncontrollable names will be created in "
- "this directory. Be sure to use a dedicated directory not "
- "used for anything but DVD key caching."),
- XINE_CONFIG_SECURITY, NULL, NULL);
- if (strlen(css_cache) > 0)
- xine_setenv("DVDCSS_CACHE", css_cache, 0);
- free(css_cache_default);
-
-
if(xine->verbosity > XINE_VERBOSITY_NONE)
xine_setenv("DVDCSS_VERBOSE", "2", 0);
else
diff --git a/src/input/input_file.c b/src/input/input_file.c
index fd2b0e733..0ec25e1f8 100644
--- a/src/input/input_file.c
+++ b/src/input/input_file.c
@@ -723,9 +723,9 @@ static xine_mrl_t **file_class_get_dir (input_class_t *this_gen,
return NULL;
}
- dir_files = (xine_mrl_t *) xine_xmalloc(sizeof(xine_mrl_t) * MAXFILES);
- hide_files = (xine_mrl_t *) xine_xmalloc(sizeof(xine_mrl_t) * MAXFILES);
- norm_files = (xine_mrl_t *) xine_xmalloc(sizeof(xine_mrl_t) * MAXFILES);
+ dir_files = (xine_mrl_t *) xine_xcalloc(MAXFILES, sizeof(xine_mrl_t));
+ hide_files = (xine_mrl_t *) xine_xcalloc(MAXFILES, sizeof(xine_mrl_t));
+ norm_files = (xine_mrl_t *) xine_xcalloc(MAXFILES, sizeof(xine_mrl_t));
while((pdirent = readdir(pdir)) != NULL) {
diff --git a/src/input/input_http.c b/src/input/input_http.c
index 6e8932700..d1202ae14 100644
--- a/src/input/input_http.c
+++ b/src/input/input_http.c
@@ -93,16 +93,18 @@ typedef struct {
char preview[MAX_PREVIEW_SIZE];
off_t preview_size;
-
+
+ /* 2 spare bytes here */
+
+ /* NSV */
+ unsigned char is_nsv; /* bool */
+
/* ShoutCast */
- int shoutcast_mode;
+ unsigned char shoutcast_mode; /* bool */
int shoutcast_metaint;
off_t shoutcast_pos;
char *shoutcast_songtitle;
- /* NSV */
- int is_nsv;
-
/* scratch buffer for forward seeking */
char seek_buf[BUFSIZE];
@@ -829,7 +831,12 @@ static int http_plugin_open (input_plugin_t *this_gen ) {
_("input_http: http status not 2xx: >%d %s<\n"),
httpcode, httpstatus);
return -7;
- } else if (httpcode == 403 || httpcode == 401) {
+ } else if (httpcode == 401) {
+ xine_log (this->stream->xine, XINE_LOG_MSG,
+ _("input_http: http status not 2xx: >%d %s<\n"),
+ httpcode, httpstatus);
+ /* don't return - there may be a WWW-Authenticate header... */
+ } else if (httpcode == 403) {
_x_message(this->stream, XINE_MSG_PERMISSION_ERROR, this->mrl, NULL);
xine_log (this->stream->xine, XINE_LOG_MSG,
_("input_http: http status not 2xx: >%d %s<\n"),
@@ -866,6 +873,10 @@ static int http_plugin_open (input_plugin_t *this_gen ) {
return http_plugin_open(this_gen);
}
+ if (!strncasecmp (this->buf, "WWW-Authenticate: ", 18))
+ strcpy (this->preview, this->buf + 18);
+
+
/* Icecast / ShoutCast Stuff */
if (!strncasecmp(this->buf, TAG_ICY_NAME, sizeof(TAG_ICY_NAME) - 1)) {
_x_meta_info_set(this->stream, XINE_META_INFO_ALBUM,
@@ -925,6 +936,10 @@ static int http_plugin_open (input_plugin_t *this_gen ) {
lprintf ("end of headers\n");
+ if (httpcode == 401)
+ _x_message(this->stream, XINE_MSG_AUTHENTICATION_NEEDED,
+ this->mrl, *this->preview ? this->preview : NULL, NULL);
+
/*
* fill preview buffer
*/
diff --git a/src/input/input_mms.c b/src/input/input_mms.c
index 05c0b168b..739d81a59 100644
--- a/src/input/input_mms.c
+++ b/src/input/input_mms.c
@@ -59,15 +59,15 @@
static const uint32_t mms_bandwidths[]={14400,19200,28800,33600,34430,57600,
115200,262200,393216,524300,1544000,10485800};
-static const char * mms_bandwidth_strs[]={"14.4 Kbps (Modem)", "19.2 Kbps (Modem)",
- "28.8 Kbps (Modem)", "33.6 Kbps (Modem)",
- "34.4 Kbps (Modem)", "57.6 Kbps (Modem)",
- "115.2 Kbps (ISDN)", "262.2 Kbps (Cable/DSL)",
- "393.2 Kbps (Cable/DSL)","524.3 Kbps (Cable/DSL)",
- "1.5 Mbps (T1)", "10.5 Mbps (LAN)", NULL};
+static const char *const mms_bandwidth_strs[]={"14.4 Kbps (Modem)", "19.2 Kbps (Modem)",
+ "28.8 Kbps (Modem)", "33.6 Kbps (Modem)",
+ "34.4 Kbps (Modem)", "57.6 Kbps (Modem)",
+ "115.2 Kbps (ISDN)", "262.2 Kbps (Cable/DSL)",
+ "393.2 Kbps (Cable/DSL)","524.3 Kbps (Cable/DSL)",
+ "1.5 Mbps (T1)", "10.5 Mbps (LAN)", NULL};
/* connection methods */
-static const char *mms_protocol_strs[]={"auto", "TCP", "HTTP", NULL};
+static const char *const mms_protocol_strs[]={"auto", "TCP", "HTTP", NULL};
typedef struct {
input_plugin_t input_plugin;
diff --git a/src/input/input_smb.c b/src/input/input_smb.c
index 1b1f15565..4cacebf89 100644
--- a/src/input/input_smb.c
+++ b/src/input/input_smb.c
@@ -258,8 +258,8 @@ static xine_mrl_t **smb_class_get_dir (input_class_t *this_gen,
}
if ((dir = smbc_opendir(current_path_smb)) >= 0){
- xine_mrl_t *dir_files = (xine_mrl_t *) xine_xmalloc(sizeof(xine_mrl_t) * MAXFILES);
- xine_mrl_t *norm_files = (xine_mrl_t *) xine_xmalloc(sizeof(xine_mrl_t) * MAXFILES);
+ xine_mrl_t *dir_files = (xine_mrl_t *) xine_xcalloc(MAXFILES, sizeof(xine_mrl_t));
+ xine_mrl_t *norm_files = (xine_mrl_t *) xine_xcalloc(MAXFILES, sizeof(xine_mrl_t));
int num_dir_files=0;
int num_norm_files=0;
while ((pdirent = smbc_readdir(dir)) != NULL){
diff --git a/src/input/libdvdnav/Makefile.am b/src/input/libdvdnav/Makefile.am
index 412828261..f741b4f17 100644
--- a/src/input/libdvdnav/Makefile.am
+++ b/src/input/libdvdnav/Makefile.am
@@ -1,6 +1,8 @@
include $(top_srcdir)/misc/Makefile.common
-AM_CPPFLAGS = -D_LARGEFILE64_SOURCE -DDVDNAV_COMPILE -DHAVE_DLFCN_H
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+AM_CPPFLAGS = -DDVDNAV_COMPILE -DHAVE_DLFCN_H
+AM_LDFLAGS = $(xineplug_ldflags)
noinst_LTLIBRARIES = libdvdnav.la
@@ -23,8 +25,6 @@ libdvdnav_la_SOURCES = \
dvd_input.c \
dvd_udf.c
libdvdnav_la_LIBADD = $(PTHREAD_LIBS)
-libdvdnav_la_CFLAGS = $(VISIBILITY_FLAG)
-libdvdnav_la_LDFLAGS = -avoid-version -module
noinst_HEADERS = \
decoder.h \
diff --git a/src/input/libdvdnav/diff_against_cvs.patch b/src/input/libdvdnav/diff_against_cvs.patch
index 202474fef..b9b1dbe8b 100644
--- a/src/input/libdvdnav/diff_against_cvs.patch
+++ b/src/input/libdvdnav/diff_against_cvs.patch
@@ -432,3 +432,36 @@ diff -u -p -u -r1.19 searching.c
if(this->position_current.still != 0) {
printerr("Cannot seek in a still frame.");
+--- src/input/libdvdnav/ifo_types.h Tue Apr 10 13:13:59 2007 +0200
++++ src/input/libdvdnav/ifo_types.h Tue Apr 10 13:38:19 2007 +0200
+@@ -23,2 +25,2 @@
+ #include <inttypes.h>
+ #include "dvd_reader.h"
+
++#include "config.h"
++
+-
+-#undef ATTRIBUTE_PACKED
+-#undef PRAGMA_PACK_BEGIN
+-#undef PRAGMA_PACK_END
+-
+-#if defined(__GNUC__)
+-#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
+-#define ATTRIBUTE_PACKED __attribute__ ((packed))
+-#define PRAGMA_PACK 0
+-#endif
+-#endif
+-
+-#if !defined(ATTRIBUTE_PACKED)
+-#define ATTRIBUTE_PACKED
+-#define PRAGMA_PACK 1
+-#endif
+-
+-#if PRAGMA_PACK
+-#pragma pack(1)
+-#endif
+-
++#define ATTRIBUTE_PACKED XINE_PACKED
+
+ /**
+ * Common
diff --git a/src/input/libdvdnav/ifo_types.h b/src/input/libdvdnav/ifo_types.h
index 5d5124579..0935f75d0 100644
--- a/src/input/libdvdnav/ifo_types.h
+++ b/src/input/libdvdnav/ifo_types.h
@@ -23,27 +23,9 @@
#include <inttypes.h>
#include "dvd_reader.h"
+#include "config.h"
-#undef ATTRIBUTE_PACKED
-#undef PRAGMA_PACK_BEGIN
-#undef PRAGMA_PACK_END
-
-#if defined(__GNUC__)
-#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
-#define ATTRIBUTE_PACKED __attribute__ ((packed))
-#define PRAGMA_PACK 0
-#endif
-#endif
-
-#if !defined(ATTRIBUTE_PACKED)
-#define ATTRIBUTE_PACKED
-#define PRAGMA_PACK 1
-#endif
-
-#if PRAGMA_PACK
-#pragma pack(1)
-#endif
-
+#define ATTRIBUTE_PACKED XINE_PACKED
/**
* Common
diff --git a/src/input/libreal/Makefile.am b/src/input/libreal/Makefile.am
index 5b10d1bca..bd97a7548 100644
--- a/src/input/libreal/Makefile.am
+++ b/src/input/libreal/Makefile.am
@@ -1,19 +1,10 @@
include $(top_srcdir)/misc/Makefile.common
-AM_CPPFLAGS = -D_LARGEFILE64_SOURCE -I$(srcdir)/../librtsp
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+AM_CPPFLAGS = -I$(top_srcdir)/src/input/librtsp
-noinst_LTLIBRARIES = libreal.la
-
-libreal_la_SOURCES = \
- real.c \
- asmrp.c \
- rmff.c \
- sdpplin.c
+noinst_HEADERS = real.h asmrp.h rmff.h sdpplin.h
-libreal_la_CFLAGS = $(VISIBILITY_FLAG)
+noinst_LTLIBRARIES = libreal.la
-noinst_HEADERS = \
- real.h \
- asmrp.h \
- rmff.h \
- sdpplin.h
+libreal_la_SOURCES = real.c asmrp.c rmff.c sdpplin.c
diff --git a/src/input/libreal/real.c b/src/input/libreal/real.c
index dc0c001bd..da7c0c443 100644
--- a/src/input/libreal/real.c
+++ b/src/input/libreal/real.c
@@ -461,7 +461,7 @@ rmff_header_t *real_parse_sdp(char *data, char **stream_rules, uint32_t bandwidt
desc->copyright,
desc->abstract);
header->data=rmff_new_dataheader(0,0);
- header->streams = xine_xmalloc(sizeof(rmff_mdpr_t*)*(desc->stream_count+1));
+ header->streams = xine_xcalloc((desc->stream_count+1), sizeof(rmff_mdpr_t*));
lprintf("number of streams: %u\n", desc->stream_count);
for (i=0; i<desc->stream_count; i++) {
diff --git a/src/input/librtsp/Makefile.am b/src/input/librtsp/Makefile.am
index bb85f9cf4..68d554c2c 100644
--- a/src/input/librtsp/Makefile.am
+++ b/src/input/librtsp/Makefile.am
@@ -1,16 +1,10 @@
include $(top_srcdir)/misc/Makefile.common
-AM_CPPFLAGS = -D_LARGEFILE64_SOURCE -I$(srcdir)/../libreal
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+AM_CPPFLAGS = -I$(top_srcdir)/src/input/libreal
-noinst_LTLIBRARIES = librtsp.la
-
-librtsp_la_SOURCES = \
- rtsp.c \
- rtsp_session.c
+noinst_HEADERS = rtsp.h rtsp_session.h
-librtsp_la_CFLAGS = $(VISIBILITY_FLAG)
-librtsp_la_LDFLAGS = -avoid-version -module
+noinst_LTLIBRARIES = librtsp.la
-noinst_HEADERS = \
- rtsp.h \
- rtsp_session.h
+librtsp_la_SOURCES = rtsp.c rtsp_session.c
diff --git a/src/input/vcd/Makefile.am b/src/input/vcd/Makefile.am
index 16eece779..3de899f7e 100644
--- a/src/input/vcd/Makefile.am
+++ b/src/input/vcd/Makefile.am
@@ -1,24 +1,17 @@
include $(top_srcdir)/misc/Makefile.common
-SUBDIRS = libcdio libvcd
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+AM_LDFLAGS = $(xineplug_ldflags)
-vcd_SRCS = xineplug_inp_vcd.c vcdplayer.c vcdio.c xine-extra.c
+SUBDIRS =
+if !WITH_EXTERNAL_VCDLIBS
+SUBDIRS += libcdio libvcd
+endif
-EXTRA_DIST = $(vcd_SRCS)
+noinst_HEADERS = vcdio.h vcdplayer.h xine-extra.h
-if ENABLE_VCD
xineplug_LTLIBRARIES = xineplug_inp_vcd.la
-AM_CFLAGS = $(LIBCDIO_CFLAGS) $(LIBVCD_CFLAGS)
-
-xineplug_inp_vcd_la_SOURCES = $(vcd_SRCS)
-xineplug_inp_vcd_la_LDFLAGS = -avoid-version -module
-if HAVE_VCDNAV
-xineplug_inp_vcd_la_LIBADD = $(XINE_LIB) $(LIBVCDINFO_LIBS)
-else
-xineplug_inp_vcd_la_LIBADD = $(XINE_LIB) $(LIBVCD_LIBS) $(LIBVCDINFO_LIBS) -lm
-endif
-
-endif
-
-noinst_HEADERS = vcdio.h vcdplayer.h xine-extra.h
+xineplug_inp_vcd_la_SOURCES = xineplug_inp_vcd.c vcdplayer.c vcdio.c xine-extra.c
+xineplug_inp_vcd_la_LIBADD = $(XINE_LIB) $(LIBCDIO_LIBS) $(LIBVCD_LIBS) $(LIBVCDINFO_LIBS) $(LIBISO9660_LIBS) -lm
+xineplug_inp_vcd_la_CFLAGS = $(AM_CFLAGS) $(LIBCDIO_CFLAGS) $(LIBVCD_CFLAGS)
diff --git a/src/input/vcd/libcdio/Makefile.am b/src/input/vcd/libcdio/Makefile.am
index c7415e787..a79525c8f 100644
--- a/src/input/vcd/libcdio/Makefile.am
+++ b/src/input/vcd/libcdio/Makefile.am
@@ -1,10 +1,24 @@
include $(top_srcdir)/misc/Makefile.common
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+AM_LDFLAGS = $(xineplug_ldflags)
+
SUBDIRS = cdio MSWindows image
-INCLUDES = $(LIBCDIO_CFLAGS) -I$(top_srcdir)/include -I$(top_srcdir)/lib -I$(top_builddir)/lib
+INCLUDES = $(LIBCDIO_CFLAGS) -I$(top_srcdir)/include -I$(top_builddir)/include -I$(top_srcdir)/lib -I$(top_builddir)/lib
+
+noinst_HEADERS = \
+ cdio_assert.h \
+ _cdio_stdio.h \
+ scsi_mmc.h \
+ cdio_private.h \
+ _cdio_stream.h \
+ iso9660_private.h \
+ portable.h
+
+noinst_LTLIBRARIES = libcdio.la libiso9660.la
-libcdio_SRCS = \
+libcdio_la_SOURCES = \
_cdio_bsdi.c \
_cdio_generic.c \
_cdio_linux.c \
@@ -41,30 +55,8 @@ libcdio_SRCS = \
sector.c \
util.c
-libiso9660_SRCS = \
+libiso9660_la_SOURCES = \
iso9660.c \
iso9660_private.h \
iso9660_fs.c \
xa.c
-
-EXTRA_DIST = $(libcdio_SRCS) $(libiso9660_SRCS)
-
-if ENABLE_VCD
-if HAVE_VCDNAV
-else
-noinst_LTLIBRARIES = libcdio.la libiso9660.la
-libcdio_la_SOURCES = $(libcdio_SRCS)
-libcdio_la_LDFLAGS = -avoid-version -module
-libiso9660_la_SOURCES = $(libiso9660_SRCS)
-libiso9660_la_LDFLAGS = -avoid-version -module
-endif
-endif
-
-noinst_HEADERS = \
- cdio_assert.h \
- _cdio_stdio.h \
- scsi_mmc.h \
- cdio_private.h \
- _cdio_stream.h \
- iso9660_private.h \
- portable.h
diff --git a/src/input/vcd/libvcd/Makefile.am b/src/input/vcd/libvcd/Makefile.am
index 01b100aa4..c922685e3 100644
--- a/src/input/vcd/libvcd/Makefile.am
+++ b/src/input/vcd/libvcd/Makefile.am
@@ -1,10 +1,35 @@
include $(top_srcdir)/misc/Makefile.common
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+
+INCLUDES = -I$(top_srcdir)/include -I$(top_builddir)/include -I$(top_srcdir)/lib -I$(top_builddir)/lib
+
SUBDIRS = libvcd
-INCLUDES = $(LIBCDIO_CFLAGS) -I$(top_srcdir)/include -I$(top_srcdir)/lib
+noinst_HEADERS = \
+ vcd_assert.h \
+ data_structures.h \
+ info_private.h \
+ pbc.h \
+ stream_stdio.h \
+ bitvec.h \
+ dict.h \
+ mpeg.h \
+ salloc.h \
+ util.h \
+ bytesex_asm.h \
+ directory.h \
+ mpeg_stream.h \
+ sector_private.h \
+ vcd.h \
+ bytesex.h \
+ image_sink.h \
+ obj.h \
+ stream.h \
+ vcd_read.h
-libvcd_SRCS = \
+noinst_LTLIBRARIES = libvcd.la libvcdinfo.la
+libvcd_la_SOURCES = \
vcd.c \
data_structures.c \
directory.c \
@@ -22,45 +47,11 @@ libvcd_SRCS = \
stream.c \
stream_stdio.c \
util.c
+libvcd_la_CFLAGS = $(AM_CFLAGS) $(LIBCDIO_CFLAGS)
-libvcdinfo_SRCS = \
+libvcdinfo_la_SOURCES = \
info.c \
inf.c \
info_private.c \
vcd_read.c
-
-EXTRA_DIST = $(libvcd_SRCS) $(libvcdinfo_SRCS)
-
-if ENABLE_VCD
-if HAVE_VCDNAV
-else
-noinst_LTLIBRARIES = libvcd.la libvcdinfo.la
-libvcd_la_SOURCES = $(libvcd_SRCS)
-libvcd_la_LDFLAGS = -avoid-version -module
-libvcd_la_LIBADD = $(LIBCDIO_LIBS) $(LIBISO9660_LIBS)
-libvcdinfo_la_SOURCES = $(libvcdinfo_SRCS)
-libvcdinfo_la_LDFLAGS = -avoid-version -module
-endif
-endif
-
-noinst_HEADERS = \
- vcd_assert.h \
- data_structures.h \
- info_private.h \
- pbc.h \
- stream_stdio.h \
- bitvec.h \
- dict.h \
- mpeg.h \
- salloc.h \
- util.h \
- bytesex_asm.h \
- directory.h \
- mpeg_stream.h \
- sector_private.h \
- vcd.h \
- bytesex.h \
- image_sink.h \
- obj.h \
- stream.h \
- vcd_read.h
+libvcdinfo_la_CFLAGS = $(AM_CFLAGS) $(LIBCDIO_CFLAGS)
diff --git a/src/input/vcd/xineplug_inp_vcd.c b/src/input/vcd/xineplug_inp_vcd.c
index 9eb9ac996..0f1c9225e 100644
--- a/src/input/vcd/xineplug_inp_vcd.c
+++ b/src/input/vcd/xineplug_inp_vcd.c
@@ -1813,13 +1813,13 @@ vcd_init (xine_t *xine, void *data)
/*Note: these labels have to be listed in the same order as the
enumeration vcdplayer_autoplay_t in vcdplayer.h.
*/
- static const char *autoplay_modes[] =
+ static const char *const autoplay_modes[] =
{ "MPEG track", "entry", "segment", "playback-control item", NULL };
/*Note: these labels have to be listed in the same order as the
enumeration vcdplayer_slider_length_t in vcdplayer.h.
*/
- static const char *length_reporting_modes[] =
+ static const char *const length_reporting_modes[] =
{ "auto", "track", "entry", NULL };
my_vcd.player.default_autoplay =
diff --git a/src/liba52/Makefile.am b/src/liba52/Makefile.am
index 6a0aebe62..1025b373d 100644
--- a/src/liba52/Makefile.am
+++ b/src/liba52/Makefile.am
@@ -1,38 +1,21 @@
include $(top_srcdir)/misc/Makefile.common
-if A52
-a52_module = xineplug_decode_a52.la
-endif
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+AM_LDFLAGS = $(xineplug_ldflags)
-xineplug_LTLIBRARIES = $(a52_module)
+noinst_HEADERS = a52.h a52_internal.h bitstream.h tables.h crc.c
-if EXTERNAL_A52DEC
-internal_sources =
-else
-internal_sources = \
- bitstream.c \
- bit_allocate.c \
- downmix.c \
- imdct.c \
- parse.c
+if ENABLE_A52DEC
+xineplug_LTLIBRARIES = xineplug_decode_a52.la
endif
-xineplug_decode_a52_la_SOURCES = \
- xine_a52_decoder.c \
- $(internal_sources)
-
-if EXTERNAL_A52DEC
-xineplug_decode_a52_la_LIBADD = $(XINE_LIB) -la52 -lm
+if WITH_EXTERNAL_A52DEC
+external_libs = -la52
+internal_sources =
else
-xineplug_decode_a52_la_LIBADD = $(XINE_LIB) -lm
+external_libs =
+internal_sources = bitstream.c bit_allocate.c downmix.c imdct.c parse.c
endif
-xineplug_decode_a52_la_CFLAGS = $(VISIBILITY_FLAG)
-xineplug_decode_a52_la_LDFLAGS = $(xineplug_ldflags)
-
-noinst_HEADERS = \
- a52.h \
- a52_internal.h \
- bitstream.h \
- tables.h \
- crc.c
+xineplug_decode_a52_la_SOURCES = xine_a52_decoder.c $(internal_sources)
+xineplug_decode_a52_la_LIBADD = $(XINE_LIB) $(external_libs) -lm
diff --git a/src/libdts/Makefile.am b/src/libdts/Makefile.am
deleted file mode 100644
index ea09aab2e..000000000
--- a/src/libdts/Makefile.am
+++ /dev/null
@@ -1,28 +0,0 @@
-include $(top_srcdir)/misc/Makefile.common
-
-if DTS
-dts_module = xineplug_decode_dts.la
-endif
-
-xineplug_LTLIBRARIES = $(dts_module)
-
-if EXTERNAL_LIBDTS
-fnsa =
-internal_sources =
-else
-fnsa = -fno-strict-aliasing
-internal_sources = bitstream.c downmix.c parse.c
-endif
-
-xineplug_decode_dts_la_SOURCES = xine_dts_decoder.c $(internal_sources)
-xineplug_decode_dts_la_CFLAGS = $(LIBDTS_CFLAGS) $(VISIBILITY_FLAG) $(fnsa)
-xineplug_decode_dts_la_LDFLAGS = $(xineplug_ldflags)
-
-if EXTERNAL_LIBDTS
-xineplug_decode_dts_la_LIBADD = $(XINE_LIB) $(LIBDTS_LIBS) -lm
-else
-xineplug_decode_dts_la_LIBADD = $(XINE_LIB) -lm
-endif
-
-noinst_HEADERS = bitstream.h internal-dts.h dts_internal.h tables.h tables_adpcm.h \
- tables_fir.h tables_huffman.h tables_quantization.h tables_vq.h
diff --git a/src/libdts/bitstream.c b/src/libdts/bitstream.c
deleted file mode 100644
index 50b2b9fe8..000000000
--- a/src/libdts/bitstream.c
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * bitstream.c
- * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
- * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
- * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
- *
- * This file is part of dtsdec, a free DTS Coherent Acoustics stream decoder.
- * See http://www.videolan.org/dtsdec.html for updates.
- *
- * dtsdec 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.
- *
- * dtsdec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "config.h"
-
-#include <inttypes.h>
-
-#include "internal-dts.h"
-#include "dts_internal.h"
-#include "bitstream.h"
-
-#define BUFFER_SIZE 4096
-
-void dts_bitstream_init (dts_state_t * state, uint8_t * buf, int word_mode,
- int bigendian_mode)
-{
- intptr_t align;
-
- align = (uintptr_t)buf & 3;
- state->buffer_start = (uint32_t *) (buf - align);
- state->bits_left = 0;
- state->current_word = 0;
- state->word_mode = word_mode;
- state->bigendian_mode = bigendian_mode;
- bitstream_get (state, align * 8);
-}
-#include<stdio.h>
-static inline void bitstream_fill_current (dts_state_t * state)
-{
- uint32_t tmp;
-
- tmp = *(state->buffer_start++);
-
- if (state->bigendian_mode)
- state->current_word = swab32 (tmp);
- else
- state->current_word = swable32 (tmp);
-
- if (!state->word_mode)
- {
- state->current_word = (state->current_word & 0x00003FFF) |
- ((state->current_word & 0x3FFF0000 ) >> 2);
- }
-}
-
-/*
- * The fast paths for _get is in the
- * bitstream.h header file so it can be inlined.
- *
- * The "bottom half" of this routine is suffixed _bh
- *
- * -ah
- */
-
-uint32_t dts_bitstream_get_bh (dts_state_t * state, uint32_t num_bits)
-{
- uint32_t result;
-
- num_bits -= state->bits_left;
-
- result = ((state->current_word << (32 - state->bits_left)) >>
- (32 - state->bits_left));
-
- if ( !state->word_mode && num_bits > 28 ) {
- bitstream_fill_current (state);
- result = (result << 28) | state->current_word;
- num_bits -= 28;
- }
-
- bitstream_fill_current (state);
-
- if ( state->word_mode )
- {
- if (num_bits != 0)
- result = (result << num_bits) |
- (state->current_word >> (32 - num_bits));
-
- state->bits_left = 32 - num_bits;
- }
- else
- {
- if (num_bits != 0)
- result = (result << num_bits) |
- (state->current_word >> (28 - num_bits));
-
- state->bits_left = 28 - num_bits;
- }
-
- return result;
-}
diff --git a/src/libdts/bitstream.h b/src/libdts/bitstream.h
deleted file mode 100644
index 105dc0e9b..000000000
--- a/src/libdts/bitstream.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * bitstream.h
- * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
- * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
- * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
- *
- * This file is part of dtsdec, a free DTS Coherent Acoustics stream decoder.
- * See http://www.videolan.org/dtsdec.html for updates.
- *
- * dtsdec 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.
- *
- * dtsdec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifdef WORDS_BIGENDIAN
-
-# define swab32(x) (x)
-
-#else
-
-# define swab32(x)\
-((((uint8_t*)&x)[0] << 24) | (((uint8_t*)&x)[1] << 16) | \
- (((uint8_t*)&x)[2] << 8) | (((uint8_t*)&x)[3]))
-
-#endif
-
-#ifdef WORDS_BIGENDIAN
-
-# define swable32(x)\
-((((uint8_t*)&x)[0] << 16) | (((uint8_t*)&x)[1] << 24) | \
- (((uint8_t*)&x)[2]) | (((uint8_t*)&x)[3] << 8))
-
-#else
-
-# define swable32(x)\
-((((uint16_t*)&x)[0] << 16) | (((uint16_t*)&x)[1]))
-
-#endif
-
-void dts_bitstream_init (dts_state_t * state, uint8_t * buf, int word_mode,
- int endian_mode);
-uint32_t dts_bitstream_get_bh (dts_state_t * state, uint32_t num_bits);
-
-static inline uint32_t bitstream_get (dts_state_t * state, uint32_t num_bits)
-{
- uint32_t result;
-
- if (num_bits < state->bits_left) {
- result = (state->current_word << (32 - state->bits_left))
- >> (32 - num_bits);
-
- state->bits_left -= num_bits;
- return result;
- }
-
- return dts_bitstream_get_bh (state, num_bits);
-}
diff --git a/src/libdts/downmix.c b/src/libdts/downmix.c
deleted file mode 100644
index fe7136a72..000000000
--- a/src/libdts/downmix.c
+++ /dev/null
@@ -1,691 +0,0 @@
-/*
- * downmix.c
- * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
- * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
- * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
- *
- * This file is part of dtsdec, a free DTS Coherent Acoustics stream decoder.
- * See http://www.videolan.org/dtsdec.html for updates.
- *
- * dtsdec 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.
- *
- * dtsdec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "config.h"
-
-#include <string.h>
-#include <inttypes.h>
-
-#include "internal-dts.h"
-#include "dts_internal.h"
-
-#define CONVERT(acmod,output) (((output) << DTS_CHANNEL_BITS) + (acmod))
-
-int dts_downmix_init (int input, int flags, level_t * level,
- level_t clev, level_t slev)
-{
- static uint8_t table[11][10] = {
- /* DTS_MONO */
- {DTS_MONO, DTS_MONO, DTS_MONO, DTS_MONO,
- DTS_MONO, DTS_MONO, DTS_MONO, DTS_MONO,
- DTS_MONO, DTS_MONO},
- /* DTS_CHANNEL */
- {DTS_MONO, DTS_CHANNEL, DTS_STEREO, DTS_STEREO,
- DTS_STEREO, DTS_STEREO, DTS_STEREO, DTS_STEREO,
- DTS_STEREO, DTS_STEREO},
- /* DTS_STEREO */
- {DTS_MONO, DTS_CHANNEL, DTS_STEREO, DTS_STEREO,
- DTS_STEREO, DTS_STEREO, DTS_STEREO, DTS_STEREO,
- DTS_STEREO, DTS_STEREO},
- /* DTS_STEREO_SUMDIFF */
- {DTS_MONO, DTS_CHANNEL, DTS_STEREO, DTS_STEREO,
- DTS_STEREO, DTS_STEREO, DTS_STEREO, DTS_STEREO,
- DTS_STEREO, DTS_STEREO},
- /* DTS_STEREO_TOTAL */
- {DTS_MONO, DTS_CHANNEL, DTS_STEREO, DTS_STEREO,
- DTS_STEREO, DTS_STEREO, DTS_STEREO, DTS_STEREO,
- DTS_STEREO, DTS_STEREO},
- /* DTS_3F */
- {DTS_MONO, DTS_CHANNEL, DTS_STEREO, DTS_STEREO,
- DTS_STEREO, DTS_3F, DTS_3F, DTS_3F,
- DTS_3F, DTS_3F},
- /* DTS_2F1R */
- {DTS_MONO, DTS_CHANNEL, DTS_STEREO, DTS_STEREO,
- DTS_STEREO, DTS_2F1R, DTS_2F1R, DTS_2F1R,
- DTS_2F1R, DTS_2F1R},
- /* DTS_3F1R */
- {DTS_MONO, DTS_CHANNEL, DTS_STEREO, DTS_STEREO,
- DTS_STEREO, DTS_3F, DTS_3F1R, DTS_3F1R,
- DTS_3F1R, DTS_3F1R},
- /* DTS_2F2R */
- {DTS_MONO, DTS_CHANNEL, DTS_STEREO, DTS_STEREO,
- DTS_STEREO, DTS_STEREO, DTS_2F2R, DTS_2F2R,
- DTS_2F2R, DTS_2F2R},
- /* DTS_3F2R */
- {DTS_MONO, DTS_CHANNEL, DTS_STEREO, DTS_STEREO,
- DTS_STEREO, DTS_3F, DTS_3F2R, DTS_3F2R,
- DTS_3F2R, DTS_3F2R},
- /* DTS_4F2R */
- {DTS_MONO, DTS_CHANNEL, DTS_STEREO, DTS_STEREO,
- DTS_STEREO, DTS_4F2R, DTS_4F2R, DTS_4F2R,
- DTS_4F2R, DTS_4F2R},
- };
- int output;
-
- output = flags & DTS_CHANNEL_MASK;
-
- if (output > DTS_CHANNEL_MAX)
- return -1;
-
- output = table[output][input];
-
- if (output == DTS_STEREO &&
- (input == DTS_DOLBY || (input == DTS_3F && clev == LEVEL (LEVEL_3DB))))
- output = DTS_DOLBY;
-
- if (flags & DTS_ADJUST_LEVEL) {
- level_t adjust;
-
- switch (CONVERT (input & 7, output)) {
-
- case CONVERT (DTS_3F, DTS_MONO):
- adjust = DIV (LEVEL_3DB, LEVEL (1) + clev);
- break;
-
- case CONVERT (DTS_STEREO, DTS_MONO):
- case CONVERT (DTS_2F2R, DTS_2F1R):
- case CONVERT (DTS_3F2R, DTS_3F1R):
- level_3db:
- adjust = LEVEL (LEVEL_3DB);
- break;
-
- case CONVERT (DTS_3F2R, DTS_2F1R):
- if (clev < LEVEL (LEVEL_PLUS3DB - 1))
- goto level_3db;
- /* break thru */
- case CONVERT (DTS_3F, DTS_STEREO):
- case CONVERT (DTS_3F1R, DTS_2F1R):
- case CONVERT (DTS_3F1R, DTS_2F2R):
- case CONVERT (DTS_3F2R, DTS_2F2R):
- adjust = DIV (1, LEVEL (1) + clev);
- break;
-
- case CONVERT (DTS_2F1R, DTS_MONO):
- adjust = DIV (LEVEL_PLUS3DB, LEVEL (2) + slev);
- break;
-
- case CONVERT (DTS_2F1R, DTS_STEREO):
- case CONVERT (DTS_3F1R, DTS_3F):
- adjust = DIV (1, LEVEL (1) + MUL_C (slev, LEVEL_3DB));
- break;
-
- case CONVERT (DTS_3F1R, DTS_MONO):
- adjust = DIV (LEVEL_3DB, LEVEL (1) + clev + MUL_C (slev, 0.5));
- break;
-
- case CONVERT (DTS_3F1R, DTS_STEREO):
- adjust = DIV (1, LEVEL (1) + clev + MUL_C (slev, LEVEL_3DB));
- break;
-
- case CONVERT (DTS_2F2R, DTS_MONO):
- adjust = DIV (LEVEL_3DB, LEVEL (1) + slev);
- break;
-
- case CONVERT (DTS_2F2R, DTS_STEREO):
- case CONVERT (DTS_3F2R, DTS_3F):
- adjust = DIV (1, LEVEL (1) + slev);
- break;
-
- case CONVERT (DTS_3F2R, DTS_MONO):
- adjust = DIV (LEVEL_3DB, LEVEL (1) + clev + slev);
- break;
-
- case CONVERT (DTS_3F2R, DTS_STEREO):
- adjust = DIV (1, LEVEL (1) + clev + slev);
- break;
-
- case CONVERT (DTS_MONO, DTS_DOLBY):
- adjust = LEVEL (LEVEL_PLUS3DB);
- break;
-
- case CONVERT (DTS_3F, DTS_DOLBY):
- case CONVERT (DTS_2F1R, DTS_DOLBY):
- adjust = LEVEL (1 / (1 + LEVEL_3DB));
- break;
-
- case CONVERT (DTS_3F1R, DTS_DOLBY):
- case CONVERT (DTS_2F2R, DTS_DOLBY):
- adjust = LEVEL (1 / (1 + 2 * LEVEL_3DB));
- break;
-
- case CONVERT (DTS_3F2R, DTS_DOLBY):
- adjust = LEVEL (1 / (1 + 3 * LEVEL_3DB));
- break;
-
- default:
- return output;
- }
-
- *level = MUL_L (*level, adjust);
- }
-
- return output;
-}
-
-int dts_downmix_coeff (level_t * coeff, int acmod, int output, level_t level,
- level_t clev, level_t slev)
-{
- level_t level_3db;
-
- level_3db = MUL_C (level, LEVEL_3DB);
-
- switch (CONVERT (acmod, output & DTS_CHANNEL_MASK)) {
-
- case CONVERT (DTS_CHANNEL, DTS_CHANNEL):
- case CONVERT (DTS_MONO, DTS_MONO):
- case CONVERT (DTS_STEREO, DTS_STEREO):
- case CONVERT (DTS_3F, DTS_3F):
- case CONVERT (DTS_2F1R, DTS_2F1R):
- case CONVERT (DTS_3F1R, DTS_3F1R):
- case CONVERT (DTS_2F2R, DTS_2F2R):
- case CONVERT (DTS_3F2R, DTS_3F2R):
- case CONVERT (DTS_STEREO, DTS_DOLBY):
- coeff[0] = coeff[1] = coeff[2] = coeff[3] = coeff[4] = level;
- return 0;
-
- case CONVERT (DTS_CHANNEL, DTS_MONO):
- coeff[0] = coeff[1] = MUL_C (level, LEVEL_6DB);
- return 3;
-
- case CONVERT (DTS_STEREO, DTS_MONO):
- coeff[0] = coeff[1] = level_3db;
- return 3;
-
- case CONVERT (DTS_3F, DTS_MONO):
- coeff[0] = coeff[2] = level_3db;
- coeff[1] = MUL_C (MUL_L (level_3db, clev), LEVEL_PLUS6DB);
- return 7;
-
- case CONVERT (DTS_2F1R, DTS_MONO):
- coeff[0] = coeff[1] = level_3db;
- coeff[2] = MUL_L (level_3db, slev);
- return 7;
-
- case CONVERT (DTS_2F2R, DTS_MONO):
- coeff[0] = coeff[1] = level_3db;
- coeff[2] = coeff[3] = MUL_L (level_3db, slev);
- return 15;
-
- case CONVERT (DTS_3F1R, DTS_MONO):
- coeff[0] = coeff[2] = level_3db;
- coeff[1] = MUL_C (MUL_L (level_3db, clev), LEVEL_PLUS6DB);
- coeff[3] = MUL_L (level_3db, slev);
- return 15;
-
- case CONVERT (DTS_3F2R, DTS_MONO):
- coeff[0] = coeff[2] = level_3db;
- coeff[1] = MUL_C (MUL_L (level_3db, clev), LEVEL_PLUS6DB);
- coeff[3] = coeff[4] = MUL_L (level_3db, slev);
- return 31;
-
- case CONVERT (DTS_MONO, DTS_DOLBY):
- coeff[0] = level_3db;
- return 0;
-
- case CONVERT (DTS_3F, DTS_DOLBY):
- coeff[0] = coeff[2] = coeff[3] = coeff[4] = level;
- coeff[1] = level_3db;
- return 7;
-
- case CONVERT (DTS_3F, DTS_STEREO):
- case CONVERT (DTS_3F1R, DTS_2F1R):
- case CONVERT (DTS_3F2R, DTS_2F2R):
- coeff[0] = coeff[2] = coeff[3] = coeff[4] = level;
- coeff[1] = MUL_L (level, clev);
- return 7;
-
- case CONVERT (DTS_2F1R, DTS_DOLBY):
- coeff[0] = coeff[1] = level;
- coeff[2] = level_3db;
- return 7;
-
- case CONVERT (DTS_2F1R, DTS_STEREO):
- coeff[0] = coeff[1] = level;
- coeff[2] = MUL_L (level_3db, slev);
- return 7;
-
- case CONVERT (DTS_3F1R, DTS_DOLBY):
- coeff[0] = coeff[2] = level;
- coeff[1] = coeff[3] = level_3db;
- return 15;
-
- case CONVERT (DTS_3F1R, DTS_STEREO):
- coeff[0] = coeff[2] = level;
- coeff[1] = MUL_L (level, clev);
- coeff[3] = MUL_L (level_3db, slev);
- return 15;
-
- case CONVERT (DTS_2F2R, DTS_DOLBY):
- coeff[0] = coeff[1] = level;
- coeff[2] = coeff[3] = level_3db;
- return 15;
-
- case CONVERT (DTS_2F2R, DTS_STEREO):
- coeff[0] = coeff[1] = level;
- coeff[2] = coeff[3] = MUL_L (level, slev);
- return 15;
-
- case CONVERT (DTS_3F2R, DTS_DOLBY):
- coeff[0] = coeff[2] = level;
- coeff[1] = coeff[3] = coeff[4] = level_3db;
- return 31;
-
- case CONVERT (DTS_3F2R, DTS_2F1R):
- coeff[0] = coeff[2] = level;
- coeff[1] = MUL_L (level, clev);
- coeff[3] = coeff[4] = level_3db;
- return 31;
-
- case CONVERT (DTS_3F2R, DTS_STEREO):
- coeff[0] = coeff[2] = level;
- coeff[1] = MUL_L (level, clev);
- coeff[3] = coeff[4] = MUL_L (level, slev);
- return 31;
-
- case CONVERT (DTS_3F1R, DTS_3F):
- coeff[0] = coeff[1] = coeff[2] = level;
- coeff[3] = MUL_L (level_3db, slev);
- return 13;
-
- case CONVERT (DTS_3F2R, DTS_3F):
- coeff[0] = coeff[1] = coeff[2] = level;
- coeff[3] = coeff[4] = MUL_L (level, slev);
- return 29;
-
- case CONVERT (DTS_2F2R, DTS_2F1R):
- coeff[0] = coeff[1] = level;
- coeff[2] = coeff[3] = level_3db;
- return 12;
-
- case CONVERT (DTS_3F2R, DTS_3F1R):
- coeff[0] = coeff[1] = coeff[2] = level;
- coeff[3] = coeff[4] = level_3db;
- return 24;
-
- case CONVERT (DTS_2F1R, DTS_2F2R):
- coeff[0] = coeff[1] = level;
- coeff[2] = level_3db;
- return 0;
-
- case CONVERT (DTS_3F1R, DTS_2F2R):
- coeff[0] = coeff[2] = level;
- coeff[1] = MUL_L (level, clev);
- coeff[3] = level_3db;
- return 7;
-
- case CONVERT (DTS_3F1R, DTS_3F2R):
- coeff[0] = coeff[1] = coeff[2] = level;
- coeff[3] = level_3db;
- return 0;
- }
-
- return -1; /* NOTREACHED */
-}
-
-static void mix2to1 (sample_t * dest, sample_t * src, sample_t bias)
-{
- int i;
-
- for (i = 0; i < 256; i++)
- dest[i] += BIAS (src[i]);
-}
-
-static void mix3to1 (sample_t * samples, sample_t bias)
-{
- int i;
-
- for (i = 0; i < 256; i++)
- samples[i] += BIAS (samples[i + 256] + samples[i + 512]);
-}
-
-static void mix4to1 (sample_t * samples, sample_t bias)
-{
- int i;
-
- for (i = 0; i < 256; i++)
- samples[i] += BIAS (samples[i + 256] + samples[i + 512] +
- samples[i + 768]);
-}
-
-static void mix5to1 (sample_t * samples, sample_t bias)
-{
- int i;
-
- for (i = 0; i < 256; i++)
- samples[i] += BIAS (samples[i + 256] + samples[i + 512] +
- samples[i + 768] + samples[i + 1024]);
-}
-
-static void mix3to2 (sample_t * samples, sample_t bias)
-{
- int i;
- sample_t common;
-
- for (i = 0; i < 256; i++) {
- common = BIAS (samples[i]);
- samples[i] = samples[i + 256] + common;
- samples[i + 256] = samples[i + 512] + common;
- }
-}
-
-static void mix21to2 (sample_t * left, sample_t * right, sample_t bias)
-{
- int i;
- sample_t common;
-
- for (i = 0; i < 256; i++) {
- common = BIAS (right[i + 256]);
- left[i] += common;
- right[i] += common;
- }
-}
-
-static void mix21toS (sample_t * samples, sample_t bias)
-{
- int i;
- sample_t surround;
-
- for (i = 0; i < 256; i++) {
- surround = samples[i + 512];
- samples[i] += BIAS (-surround);
- samples[i + 256] += BIAS (surround);
- }
-}
-
-static void mix31to2 (sample_t * samples, sample_t bias)
-{
- int i;
- sample_t common;
-
- for (i = 0; i < 256; i++) {
- common = BIAS (samples[i] + samples[i + 768]);
- samples[i] = samples[i + 256] + common;
- samples[i + 256] = samples[i + 512] + common;
- }
-}
-
-static void mix31toS (sample_t * samples, sample_t bias)
-{
- int i;
- sample_t common, surround;
-
- for (i = 0; i < 256; i++) {
- common = BIAS (samples[i]);
- surround = samples[i + 768];
- samples[i] = samples[i + 256] + common - surround;
- samples[i + 256] = samples[i + 512] + common + surround;
- }
-}
-
-static void mix22toS (sample_t * samples, sample_t bias)
-{
- int i;
- sample_t surround;
-
- for (i = 0; i < 256; i++) {
- surround = samples[i + 512] + samples[i + 768];
- samples[i] += BIAS (-surround);
- samples[i + 256] += BIAS (surround);
- }
-}
-
-static void mix32to2 (sample_t * samples, sample_t bias)
-{
- int i;
- sample_t common;
-
- for (i = 0; i < 256; i++) {
- common = BIAS (samples[i]);
- samples[i] = common + samples[i + 256] + samples[i + 768];
- samples[i + 256] = common + samples[i + 512] + samples[i + 1024];
- }
-}
-
-static void mix32toS (sample_t * samples, sample_t bias)
-{
- int i;
- sample_t common, surround;
-
- for (i = 0; i < 256; i++) {
- common = BIAS (samples[i]);
- surround = samples[i + 768] + samples[i + 1024];
- samples[i] = samples[i + 256] + common - surround;
- samples[i + 256] = samples[i + 512] + common + surround;
- }
-}
-
-static void move2to1 (sample_t * src, sample_t * dest, sample_t bias)
-{
- int i;
-
- for (i = 0; i < 256; i++)
- dest[i] = BIAS (src[i] + src[i + 256]);
-}
-
-static void zero (sample_t * samples)
-{
- int i;
-
- for (i = 0; i < 256; i++)
- samples[i] = 0;
-}
-
-void dts_downmix (sample_t * samples, int acmod, int output, sample_t bias,
- level_t clev, level_t slev)
-{
- switch (CONVERT (acmod, output & DTS_CHANNEL_MASK)) {
-
- case CONVERT (DTS_CHANNEL, DTS_MONO):
- case CONVERT (DTS_STEREO, DTS_MONO):
- mix_2to1:
- mix2to1 (samples, samples + 256, bias);
- break;
-
- case CONVERT (DTS_2F1R, DTS_MONO):
- if (slev == 0)
- goto mix_2to1;
- case CONVERT (DTS_3F, DTS_MONO):
- mix_3to1:
- mix3to1 (samples, bias);
- break;
-
- case CONVERT (DTS_3F1R, DTS_MONO):
- if (slev == 0)
- goto mix_3to1;
- case CONVERT (DTS_2F2R, DTS_MONO):
- if (slev == 0)
- goto mix_2to1;
- mix4to1 (samples, bias);
- break;
-
- case CONVERT (DTS_3F2R, DTS_MONO):
- if (slev == 0)
- goto mix_3to1;
- mix5to1 (samples, bias);
- break;
-
- case CONVERT (DTS_MONO, DTS_DOLBY):
- memcpy (samples + 256, samples, 256 * sizeof (sample_t));
- break;
-
- case CONVERT (DTS_3F, DTS_STEREO):
- case CONVERT (DTS_3F, DTS_DOLBY):
- mix_3to2:
- mix3to2 (samples, bias);
- break;
-
- case CONVERT (DTS_2F1R, DTS_STEREO):
- if (slev == 0)
- break;
- mix21to2 (samples, samples + 256, bias);
- break;
-
- case CONVERT (DTS_2F1R, DTS_DOLBY):
- mix21toS (samples, bias);
- break;
-
- case CONVERT (DTS_3F1R, DTS_STEREO):
- if (slev == 0)
- goto mix_3to2;
- mix31to2 (samples, bias);
- break;
-
- case CONVERT (DTS_3F1R, DTS_DOLBY):
- mix31toS (samples, bias);
- break;
-
- case CONVERT (DTS_2F2R, DTS_STEREO):
- if (slev == 0)
- break;
- mix2to1 (samples, samples + 512, bias);
- mix2to1 (samples + 256, samples + 768, bias);
- break;
-
- case CONVERT (DTS_2F2R, DTS_DOLBY):
- mix22toS (samples, bias);
- break;
-
- case CONVERT (DTS_3F2R, DTS_STEREO):
- if (slev == 0)
- goto mix_3to2;
- mix32to2 (samples, bias);
- break;
-
- case CONVERT (DTS_3F2R, DTS_DOLBY):
- mix32toS (samples, bias);
- break;
-
- case CONVERT (DTS_3F1R, DTS_3F):
- if (slev == 0)
- break;
- mix21to2 (samples, samples + 512, bias);
- break;
-
- case CONVERT (DTS_3F2R, DTS_3F):
- if (slev == 0)
- break;
- mix2to1 (samples, samples + 768, bias);
- mix2to1 (samples + 512, samples + 1024, bias);
- break;
-
- case CONVERT (DTS_3F1R, DTS_2F1R):
- mix3to2 (samples, bias);
- memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
- break;
-
- case CONVERT (DTS_2F2R, DTS_2F1R):
- mix2to1 (samples + 512, samples + 768, bias);
- break;
-
- case CONVERT (DTS_3F2R, DTS_2F1R):
- mix3to2 (samples, bias);
- move2to1 (samples + 768, samples + 512, bias);
- break;
-
- case CONVERT (DTS_3F2R, DTS_3F1R):
- mix2to1 (samples + 768, samples + 1024, bias);
- break;
-
- case CONVERT (DTS_2F1R, DTS_2F2R):
- memcpy (samples + 768, samples + 512, 256 * sizeof (sample_t));
- break;
-
- case CONVERT (DTS_3F1R, DTS_2F2R):
- mix3to2 (samples, bias);
- memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
- break;
-
- case CONVERT (DTS_3F2R, DTS_2F2R):
- mix3to2 (samples, bias);
- memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
- memcpy (samples + 768, samples + 1024, 256 * sizeof (sample_t));
- break;
-
- case CONVERT (DTS_3F1R, DTS_3F2R):
- memcpy (samples + 1024, samples + 768, 256 * sizeof (sample_t));
- break;
- }
-}
-
-void dts_upmix (sample_t * samples, int acmod, int output)
-{
- switch (CONVERT (acmod, output & DTS_CHANNEL_MASK)) {
-
- case CONVERT (DTS_3F2R, DTS_MONO):
- zero (samples + 1024);
- case CONVERT (DTS_3F1R, DTS_MONO):
- case CONVERT (DTS_2F2R, DTS_MONO):
- zero (samples + 768);
- case CONVERT (DTS_3F, DTS_MONO):
- case CONVERT (DTS_2F1R, DTS_MONO):
- zero (samples + 512);
- case CONVERT (DTS_CHANNEL, DTS_MONO):
- case CONVERT (DTS_STEREO, DTS_MONO):
- zero (samples + 256);
- break;
-
- case CONVERT (DTS_3F2R, DTS_STEREO):
- case CONVERT (DTS_3F2R, DTS_DOLBY):
- zero (samples + 1024);
- case CONVERT (DTS_3F1R, DTS_STEREO):
- case CONVERT (DTS_3F1R, DTS_DOLBY):
- zero (samples + 768);
- case CONVERT (DTS_3F, DTS_STEREO):
- case CONVERT (DTS_3F, DTS_DOLBY):
- mix_3to2:
- memcpy (samples + 512, samples + 256, 256 * sizeof (sample_t));
- zero (samples + 256);
- break;
-
- case CONVERT (DTS_2F2R, DTS_STEREO):
- case CONVERT (DTS_2F2R, DTS_DOLBY):
- zero (samples + 768);
- case CONVERT (DTS_2F1R, DTS_STEREO):
- case CONVERT (DTS_2F1R, DTS_DOLBY):
- zero (samples + 512);
- break;
-
- case CONVERT (DTS_3F2R, DTS_3F):
- zero (samples + 1024);
- case CONVERT (DTS_3F1R, DTS_3F):
- case CONVERT (DTS_2F2R, DTS_2F1R):
- zero (samples + 768);
- break;
-
- case CONVERT (DTS_3F2R, DTS_3F1R):
- zero (samples + 1024);
- break;
-
- case CONVERT (DTS_3F2R, DTS_2F1R):
- zero (samples + 1024);
- case CONVERT (DTS_3F1R, DTS_2F1R):
- mix_31to21:
- memcpy (samples + 768, samples + 512, 256 * sizeof (sample_t));
- goto mix_3to2;
-
- case CONVERT (DTS_3F2R, DTS_2F2R):
- memcpy (samples + 1024, samples + 768, 256 * sizeof (sample_t));
- goto mix_31to21;
- }
-}
diff --git a/src/libdts/dts_internal.h b/src/libdts/dts_internal.h
deleted file mode 100644
index e834e96a8..000000000
--- a/src/libdts/dts_internal.h
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * dts_internal.h
- * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
- * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
- * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
- *
- * This file is part of dtsdec, a free DTS Coherent Acoustics stream decoder.
- * See http://www.videolan.org/dtsdec.html for updates.
- *
- * dtsdec 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.
- *
- * dtsdec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#define DTS_SUBFRAMES_MAX (16)
-#define DTS_PRIM_CHANNELS_MAX (5)
-#define DTS_SUBBANDS (32)
-#define DTS_ABITS_MAX (32) /* Should be 28 */
-#define DTS_SUBSUBFAMES_MAX (4)
-#define DTS_LFE_MAX (3)
-
-struct dts_state_s {
-
- /* Frame header */
- int frame_type; /* type of the current frame */
- int samples_deficit; /* deficit sample count */
- int crc_present; /* crc is present in the bitstream */
- int sample_blocks; /* number of PCM sample blocks */
- int frame_size; /* primary frame byte size */
- int amode; /* audio channels arrangement */
- int sample_rate; /* audio sampling rate */
- int bit_rate; /* transmission bit rate */
-
- int downmix; /* embedded downmix enabled */
- int dynrange; /* embedded dynamic range flag */
- int timestamp; /* embedded time stamp flag */
- int aux_data; /* auxiliary data flag */
- int hdcd; /* source material is mastered in HDCD */
- int ext_descr; /* extension audio descriptor flag */
- int ext_coding; /* extended coding flag */
- int aspf; /* audio sync word insertion flag */
- int lfe; /* low frequency effects flag */
- int predictor_history; /* predictor history flag */
- int header_crc; /* header crc check bytes */
- int multirate_inter; /* multirate interpolator switch */
- int version; /* encoder software revision */
- int copy_history; /* copy history */
- int source_pcm_res; /* source pcm resolution */
- int front_sum; /* front sum/difference flag */
- int surround_sum; /* surround sum/difference flag */
- int dialog_norm; /* dialog normalisation parameter */
-
- /* Primary audio coding header */
- int subframes; /* number of subframes */
- int prim_channels; /* number of primary audio channels */
- /* subband activity count */
- int subband_activity[DTS_PRIM_CHANNELS_MAX];
- /* high frequency vq start subband */
- int vq_start_subband[DTS_PRIM_CHANNELS_MAX];
- /* joint intensity coding index */
- int joint_intensity[DTS_PRIM_CHANNELS_MAX];
- /* transient mode code book */
- int transient_huffman[DTS_PRIM_CHANNELS_MAX];
- /* scale factor code book */
- int scalefactor_huffman[DTS_PRIM_CHANNELS_MAX];
- /* bit allocation quantizer select */
- int bitalloc_huffman[DTS_PRIM_CHANNELS_MAX];
- /* quantization index codebook select */
- int quant_index_huffman[DTS_PRIM_CHANNELS_MAX][DTS_ABITS_MAX];
- /* scale factor adjustment */
- float scalefactor_adj[DTS_PRIM_CHANNELS_MAX][DTS_ABITS_MAX];
-
- /* Primary audio coding side information */
- int subsubframes; /* number of subsubframes */
- int partial_samples; /* partial subsubframe samples count */
- /* prediction mode (ADPCM used or not) */
- int prediction_mode[DTS_PRIM_CHANNELS_MAX][DTS_SUBBANDS];
- /* prediction VQ coefs */
- int prediction_vq[DTS_PRIM_CHANNELS_MAX][DTS_SUBBANDS];
- /* bit allocation index */
- int bitalloc[DTS_PRIM_CHANNELS_MAX][DTS_SUBBANDS];
- /* transition mode (transients) */
- int transition_mode[DTS_PRIM_CHANNELS_MAX][DTS_SUBBANDS];
- /* scale factors (2 if transient)*/
- int scale_factor[DTS_PRIM_CHANNELS_MAX][DTS_SUBBANDS][2];
- /* joint subband scale factors codebook */
- int joint_huff[DTS_PRIM_CHANNELS_MAX];
- /* joint subband scale factors */
- int joint_scale_factor[DTS_PRIM_CHANNELS_MAX][DTS_SUBBANDS];
- /* stereo downmix coefficients */
- int downmix_coef[DTS_PRIM_CHANNELS_MAX][2];
- /* dynamic range coefficient */
- int dynrange_coef;
-
- /* VQ encoded high frequency subbands */
- int high_freq_vq[DTS_PRIM_CHANNELS_MAX][DTS_SUBBANDS];
-
- /* Low frequency effect data */
- double lfe_data[2*DTS_SUBSUBFAMES_MAX*DTS_LFE_MAX * 2 /*history*/];
- int lfe_scale_factor;
-
- /* Subband samples history (for ADPCM) */
- double subband_samples_hist[DTS_PRIM_CHANNELS_MAX][DTS_SUBBANDS][4];
- double subband_fir_hist[DTS_PRIM_CHANNELS_MAX][512];
- double subband_fir_noidea[DTS_PRIM_CHANNELS_MAX][64];
-
- /* Audio output */
- level_t clev; /* centre channel mix level */
- level_t slev; /* surround channels mix level */
-
- int output; /* type of output */
- level_t level; /* output level */
- sample_t bias; /* output bias */
-
- sample_t * samples; /* pointer to the internal audio samples buffer */
- int downmixed;
-
- int dynrnge; /* apply dynamic range */
- level_t dynrng; /* dynamic range */
- void * dynrngdata; /* dynamic range callback funtion and data */
- level_t (* dynrngcall) (level_t range, void * dynrngdata);
-
- /* Bitstream handling */
- uint32_t * buffer_start;
- uint32_t bits_left;
- uint32_t current_word;
- int word_mode; /* 16/14 bits word format (1 -> 16, 0 -> 14) */
- int bigendian_mode; /* endianness (1 -> be, 0 -> le) */
-
- /* Current position in DTS frame */
- int current_subframe;
- int current_subsubframe;
-
- /* Pre-calculated cosine modulation coefs for the QMF */
- double cos_mod[544];
-
- /* Debug flag */
- int debug_flag;
-};
-
-#define LEVEL_PLUS6DB 2.0
-#define LEVEL_PLUS3DB 1.4142135623730951
-#define LEVEL_3DB 0.7071067811865476
-#define LEVEL_45DB 0.5946035575013605
-#define LEVEL_6DB 0.5
-
-int dts_downmix_init (int input, int flags, level_t * level,
- level_t clev, level_t slev);
-int dts_downmix_coeff (level_t * coeff, int acmod, int output, level_t level,
- level_t clev, level_t slev);
-void dts_downmix (sample_t * samples, int acmod, int output, sample_t bias,
- level_t clev, level_t slev);
-void dts_upmix (sample_t * samples, int acmod, int output);
-
-#define ROUND(x) ((int)((x) + ((x) > 0 ? 0.5 : -0.5)))
-
-#ifndef LIBDTS_FIXED
-
-typedef sample_t quantizer_t;
-#define SAMPLE(x) (x)
-#define LEVEL(x) (x)
-#define MUL(a,b) ((a) * (b))
-#define MUL_L(a,b) ((a) * (b))
-#define MUL_C(a,b) ((a) * (b))
-#define DIV(a,b) ((a) / (b))
-#define BIAS(x) ((x) + bias)
-
-#else /* LIBDTS_FIXED */
-
-typedef int16_t quantizer_t;
-#define SAMPLE(x) (sample_t)((x) * (1 << 30))
-#define LEVEL(x) (level_t)((x) * (1 << 26))
-
-#if 0
-#define MUL(a,b) ((int)(((int64_t)(a) * (b) + (1 << 29)) >> 30))
-#define MUL_L(a,b) ((int)(((int64_t)(a) * (b) + (1 << 25)) >> 26))
-#elif 1
-#define MUL(a,b) \
-({ int32_t _ta=(a), _tb=(b), _tc; \
- _tc=(_ta & 0xffff)*(_tb >> 16)+(_ta >> 16)*(_tb & 0xffff); (int32_t)(((_tc >> 14))+ (((_ta >> 16)*(_tb >> 16)) << 2 )); })
-#define MUL_L(a,b) \
-({ int32_t _ta=(a), _tb=(b), _tc; \
- _tc=(_ta & 0xffff)*(_tb >> 16)+(_ta >> 16)*(_tb & 0xffff); (int32_t)((_tc >> 10) + (((_ta >> 16)*(_tb >> 16)) << 6)); })
-#else
-#define MUL(a,b) (((a) >> 15) * ((b) >> 15))
-#define MUL_L(a,b) (((a) >> 13) * ((b) >> 13))
-#endif
-
-#define MUL_C(a,b) MUL_L (a, LEVEL (b))
-#define DIV(a,b) ((((int64_t)LEVEL (a)) << 26) / (b))
-#define BIAS(x) (x)
-
-#endif
diff --git a/src/libdts/internal-dts.h b/src/libdts/internal-dts.h
deleted file mode 100644
index 30f3a197b..000000000
--- a/src/libdts/internal-dts.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * dts.h
- * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
- *
- * This file is part of dtsdec, a free DTS Coherent Acoustics stream decoder.
- * See http://www.videolan.org/dtsdec.html for updates.
- *
- * dtsdec 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.
- *
- * dtsdec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef DTS_H
-#define DTS_H
-
-/* x86 accelerations */
-#define MM_ACCEL_X86_MMX 0x80000000
-#define MM_ACCEL_X86_3DNOW 0x40000000
-#define MM_ACCEL_X86_MMXEXT 0x20000000
-
-uint32_t mm_accel (void);
-
-#if defined(LIBDTS_FIXED)
-typedef int32_t sample_t;
-typedef int32_t level_t;
-#elif defined(LIBDTS_DOUBLE)
-typedef double sample_t;
-typedef double level_t;
-#else
-typedef float sample_t;
-typedef float level_t;
-#endif
-
-typedef struct dts_state_s dts_state_t;
-
-#define DTS_MONO 0
-#define DTS_CHANNEL 1
-#define DTS_STEREO 2
-#define DTS_STEREO_SUMDIFF 3
-#define DTS_STEREO_TOTAL 4
-#define DTS_3F 5
-#define DTS_2F1R 6
-#define DTS_3F1R 7
-#define DTS_2F2R 8
-#define DTS_3F2R 9
-#define DTS_4F2R 10
-
-#define DTS_DOLBY 101 /* FIXME */
-
-#define DTS_CHANNEL_MAX DTS_3F2R /* We don't handle anything above that */
-#define DTS_CHANNEL_BITS 6
-#define DTS_CHANNEL_MASK 0x3F
-
-#define DTS_LFE 0x80
-#define DTS_ADJUST_LEVEL 0x100
-
-dts_state_t * dts_init (uint32_t mm_accel);
-
-int dts_syncinfo (dts_state_t *state, uint8_t * buf, int * flags,
- int * sample_rate, int * bit_rate, int *frame_length);
-
-int dts_frame (dts_state_t * state, uint8_t * buf, int * flags,
- level_t * level, sample_t bias);
-
-void dts_dynrng (dts_state_t * state,
- level_t (* call) (level_t, void *), void * data);
-
-int dts_blocks_num (dts_state_t * state);
-int dts_block (dts_state_t * state);
-
-sample_t * dts_samples (dts_state_t * state);
-
-void dts_free (dts_state_t * state);
-
-#endif /* DTS_H */
diff --git a/src/libdts/parse.c b/src/libdts/parse.c
deleted file mode 100644
index 67067addb..000000000
--- a/src/libdts/parse.c
+++ /dev/null
@@ -1,1290 +0,0 @@
-/*
- * parse.c
- * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
- *
- * This file is part of dtsdec, a free DTS Coherent Acoustics stream decoder.
- * See http://www.videolan.org/dtsdec.html for updates.
- *
- * dtsdec 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.
- *
- * dtsdec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "config.h"
-
-#include <stdio.h>
-
-#include <stdlib.h>
-#include <string.h>
-#include <inttypes.h>
-
-#include <math.h>
-
-#ifndef M_PI
-#define M_PI 3.1415926535897932384626433832795029
-#endif
-
-#include "internal-dts.h"
-#include "dts_internal.h"
-#include "bitstream.h"
-
-#include "tables.h"
-#include "tables_huffman.h"
-#include "tables_quantization.h"
-#include "tables_adpcm.h"
-#include "tables_fir.h"
-#include "tables_vq.h"
-
-/* #define LOG_DEBUG */
-
-#if defined(HAVE_MEMALIGN) && !defined(__cplusplus)
-/* some systems have memalign() but no declaration for it */
-void * memalign (size_t align, size_t size);
-#else
-/* assume malloc alignment is sufficient */
-#define memalign(align,size) malloc (size)
-#endif
-
-static int decode_blockcode (int code, int levels, int *values);
-
-static void qmf_32_subbands (dts_state_t * state, int chans,
- double samples_in[32][8], sample_t *samples_out,
- double rScale, sample_t bias);
-
-static void lfe_interpolation_fir (int nDecimationSelect, int nNumDeciSample,
- double *samples_in, sample_t *samples_out,
- double rScale, sample_t bias );
-
-static void pre_calc_cosmod( dts_state_t * state );
-
-dts_state_t * dts_init (uint32_t mm_accel)
-{
- dts_state_t * state;
- int i;
-
- state = (dts_state_t *) malloc (sizeof (dts_state_t));
- if (state == NULL)
- return NULL;
-
- memset (state, 0, sizeof(dts_state_t));
-
- state->samples = (sample_t *) memalign (16, 256 * 12 * sizeof (sample_t));
- if (state->samples == NULL) {
- free (state);
- return NULL;
- }
-
- for (i = 0; i < 256 * 12; i++)
- state->samples[i] = 0;
-
- /* Pre-calculate cosine modulation coefficients */
- pre_calc_cosmod( state );
-
- state->downmixed = 1;
-
- return state;
-}
-
-sample_t * dts_samples (dts_state_t * state)
-{
- return state->samples;
-}
-
-int dts_blocks_num (dts_state_t * state)
-{
- /* 8 samples per subsubframe and per subband */
- return state->sample_blocks / 8;
-}
-
-static int syncinfo (dts_state_t * state, int * flags,
- int * sample_rate, int * bit_rate, int * frame_length)
-{
- int frame_size;
-
- /* Sync code */
- bitstream_get (state, 32);
- /* Frame type */
- bitstream_get (state, 1);
- /* Samples deficit */
- bitstream_get (state, 5);
- /* CRC present */
- bitstream_get (state, 1);
-
- *frame_length = (bitstream_get (state, 7) + 1) * 32;
- frame_size = bitstream_get (state, 14) + 1;
- if (!state->word_mode) frame_size = frame_size * 8 / 14 * 2;
-
- /* Audio channel arrangement */
- *flags = bitstream_get (state, 6);
- if (*flags > 63)
- return 0;
-
- *sample_rate = bitstream_get (state, 4);
- if (*sample_rate >= sizeof (dts_sample_rates) / sizeof (int))
- return 0;
- *sample_rate = dts_sample_rates[ *sample_rate ];
- if (!*sample_rate) return 0;
-
- *bit_rate = bitstream_get (state, 5);
- if (*bit_rate >= sizeof (dts_bit_rates) / sizeof (int))
- return 0;
- *bit_rate = dts_bit_rates[ *bit_rate ];
- if (!*bit_rate) return 0;
-
- /* LFE */
- bitstream_get (state, 10);
- if (bitstream_get (state, 2)) *flags |= DTS_LFE;
-
- return frame_size;
-}
-
-int dts_syncinfo (dts_state_t * state, uint8_t * buf, int * flags,
- int * sample_rate, int * bit_rate, int * frame_length)
-{
- /*
- * Look for sync code
- */
-
- /* 14 bits and little endian bitstream */
- if (buf[0] == 0xff && buf[1] == 0x1f &&
- buf[2] == 0x00 && buf[3] == 0xe8 &&
- (buf[4] & 0xf0) == 0xf0 && buf[5] == 0x07)
- {
- int frame_size;
- dts_bitstream_init (state, buf, 0, 0);
- frame_size = syncinfo (state, flags, sample_rate,
- bit_rate, frame_length);
- return frame_size;
- }
-
- /* 14 bits and big endian bitstream */
- if (buf[0] == 0x1f && buf[1] == 0xff &&
- buf[2] == 0xe8 && buf[3] == 0x00 &&
- buf[4] == 0x07 && (buf[5] & 0xf0) == 0xf0)
- {
- int frame_size;
- dts_bitstream_init (state, buf, 0, 1);
- frame_size = syncinfo (state, flags, sample_rate,
- bit_rate, frame_length);
- return frame_size;
- }
-
- /* 16 bits and little endian bitstream */
- if (buf[0] == 0xfe && buf[1] == 0x7f &&
- buf[2] == 0x01 && buf[3] == 0x80)
- {
- int frame_size;
- dts_bitstream_init (state, buf, 1, 0);
- frame_size = syncinfo (state, flags, sample_rate,
- bit_rate, frame_length);
- return frame_size;
- }
-
- /* 16 bits and big endian bitstream */
- if (buf[0] == 0x7f && buf[1] == 0xfe &&
- buf[2] == 0x80 && buf[3] == 0x01)
- {
- int frame_size;
- dts_bitstream_init (state, buf, 1, 1);
- frame_size = syncinfo (state, flags, sample_rate,
- bit_rate, frame_length);
- return frame_size;
- }
-
- return 0;
-}
-
-int dts_frame (dts_state_t * state, uint8_t * buf, int * flags,
- level_t * level, sample_t bias)
-{
- int i, j;
- static float adj_table[] = { 1.0, 1.1250, 1.2500, 1.4375 };
-
- dts_bitstream_init (state, buf, state->word_mode, state->bigendian_mode);
-
- /* Sync code */
- bitstream_get (state, 32);
-
- /* Frame header */
- state->frame_type = bitstream_get (state, 1);
- state->samples_deficit = bitstream_get (state, 5) + 1;
- state->crc_present = bitstream_get (state, 1);
- state->sample_blocks = bitstream_get (state, 7) + 1;
- state->frame_size = bitstream_get (state, 14) + 1;
- state->amode = bitstream_get (state, 6);
- state->sample_rate = bitstream_get (state, 4);
- state->bit_rate = bitstream_get (state, 5);
-
- state->downmix = bitstream_get (state, 1);
- state->dynrange = bitstream_get (state, 1);
- state->timestamp = bitstream_get (state, 1);
- state->aux_data = bitstream_get (state, 1);
- state->hdcd = bitstream_get (state, 1);
- state->ext_descr = bitstream_get (state, 3);
- state->ext_coding = bitstream_get (state, 1);
- state->aspf = bitstream_get (state, 1);
- state->lfe = bitstream_get (state, 2);
- state->predictor_history = bitstream_get (state, 1);
-
- /* TODO: check CRC */
- if (state->crc_present) state->header_crc = bitstream_get (state, 16);
-
- state->multirate_inter = bitstream_get (state, 1);
- state->version = bitstream_get (state, 4);
- state->copy_history = bitstream_get (state, 2);
- state->source_pcm_res = bitstream_get (state, 3);
- state->front_sum = bitstream_get (state, 1);
- state->surround_sum = bitstream_get (state, 1);
- state->dialog_norm = bitstream_get (state, 4);
-
- /* FIME: channels mixing levels */
- state->clev = state->slev = 1;
- state->output = dts_downmix_init (state->amode, *flags, level,
- state->clev, state->slev);
- if (state->output < 0)
- return 1;
-
- if (state->lfe && (*flags & DTS_LFE))
- state->output |= DTS_LFE;
-
- *flags = state->output;
-
- state->dynrng = state->level = MUL_C (*level, 2);
- state->bias = bias;
- state->dynrnge = 1;
- state->dynrngcall = NULL;
-
-#ifdef LOG_DEBUG
- fprintf (stderr, "frame type: %i\n", state->frame_type);
- fprintf (stderr, "samples deficit: %i\n", state->samples_deficit);
- fprintf (stderr, "crc present: %i\n", state->crc_present);
- fprintf (stderr, "sample blocks: %i (%i samples)\n",
- state->sample_blocks, state->sample_blocks * 32);
- fprintf (stderr, "frame size: %i bytes\n", state->frame_size);
- fprintf (stderr, "amode: %i (%i channels)\n",
- state->amode, dts_channels[state->amode]);
- fprintf (stderr, "sample rate: %i (%i Hz)\n",
- state->sample_rate, dts_sample_rates[state->sample_rate]);
- fprintf (stderr, "bit rate: %i (%i bits/s)\n",
- state->bit_rate, dts_bit_rates[state->bit_rate]);
- fprintf (stderr, "downmix: %i\n", state->downmix);
- fprintf (stderr, "dynrange: %i\n", state->dynrange);
- fprintf (stderr, "timestamp: %i\n", state->timestamp);
- fprintf (stderr, "aux_data: %i\n", state->aux_data);
- fprintf (stderr, "hdcd: %i\n", state->hdcd);
- fprintf (stderr, "ext descr: %i\n", state->ext_descr);
- fprintf (stderr, "ext coding: %i\n", state->ext_coding);
- fprintf (stderr, "aspf: %i\n", state->aspf);
- fprintf (stderr, "lfe: %i\n", state->lfe);
- fprintf (stderr, "predictor history: %i\n", state->predictor_history);
- fprintf (stderr, "header crc: %i\n", state->header_crc);
- fprintf (stderr, "multirate inter: %i\n", state->multirate_inter);
- fprintf (stderr, "version number: %i\n", state->version);
- fprintf (stderr, "copy history: %i\n", state->copy_history);
- fprintf (stderr, "source pcm resolution: %i (%i bits/sample)\n",
- state->source_pcm_res,
- dts_bits_per_sample[state->source_pcm_res]);
- fprintf (stderr, "front sum: %i\n", state->front_sum);
- fprintf (stderr, "surround sum: %i\n", state->surround_sum);
- fprintf (stderr, "dialog norm: %i\n", state->dialog_norm);
- fprintf (stderr, "\n");
-#endif
-
- /* Primary audio coding header */
- state->subframes = bitstream_get (state, 4) + 1;
- state->prim_channels = bitstream_get (state, 3) + 1;
-
-#ifdef LOG_DEBUG
- fprintf (stderr, "subframes: %i\n", state->subframes);
- fprintf (stderr, "prim channels: %i\n", state->prim_channels);
-#endif
-
- for (i = 0; i < state->prim_channels; i++)
- {
- state->subband_activity[i] = bitstream_get (state, 5) + 2;
-#ifdef LOG_DEBUG
- fprintf (stderr, "subband activity: %i\n", state->subband_activity[i]);
-#endif
- if (state->subband_activity[i] > DTS_SUBBANDS)
- state->subband_activity[i] = DTS_SUBBANDS;
- }
- for (i = 0; i < state->prim_channels; i++)
- {
- state->vq_start_subband[i] = bitstream_get (state, 5) + 1;
-#ifdef LOG_DEBUG
- fprintf (stderr, "vq start subband: %i\n", state->vq_start_subband[i]);
-#endif
- if (state->vq_start_subband[i] > DTS_SUBBANDS)
- state->vq_start_subband[i] = DTS_SUBBANDS;
- }
- for (i = 0; i < state->prim_channels; i++)
- {
- state->joint_intensity[i] = bitstream_get (state, 3);
-#ifdef LOG_DEBUG
- fprintf (stderr, "joint intensity: %i\n", state->joint_intensity[i]);
- if (state->joint_intensity[i]) {fprintf (stderr, "JOINTINTENSITY\n");}
-#endif
- }
- for (i = 0; i < state->prim_channels; i++)
- {
- state->transient_huffman[i] = bitstream_get (state, 2);
-#ifdef LOG_DEBUG
- fprintf (stderr, "transient mode codebook: %i\n",
- state->transient_huffman[i]);
-#endif
- }
- for (i = 0; i < state->prim_channels; i++)
- {
- state->scalefactor_huffman[i] = bitstream_get (state, 3);
-#ifdef LOG_DEBUG
- fprintf (stderr, "scale factor codebook: %i\n",
- state->scalefactor_huffman[i]);
-#endif
- }
- for (i = 0; i < state->prim_channels; i++)
- {
- state->bitalloc_huffman[i] = bitstream_get (state, 3);
- /* if (state->bitalloc_huffman[i] == 7) bailout */
-#ifdef LOG_DEBUG
- fprintf (stderr, "bit allocation quantizer: %i\n",
- state->bitalloc_huffman[i]);
-#endif
- }
-
- /* Get codebooks quantization indexes */
- for (i = 0; i < state->prim_channels; i++)
- {
- state->quant_index_huffman[i][0] = 0; /* Not transmitted */
- state->quant_index_huffman[i][1] = bitstream_get (state, 1);
- }
- for (j = 2; j < 6; j++)
- for (i = 0; i < state->prim_channels; i++)
- state->quant_index_huffman[i][j] = bitstream_get (state, 2);
- for (j = 6; j < 11; j++)
- for (i = 0; i < state->prim_channels; i++)
- state->quant_index_huffman[i][j] = bitstream_get (state, 3);
- for (j = 11; j < 27; j++)
- for (i = 0; i < state->prim_channels; i++)
- state->quant_index_huffman[i][j] = 0; /* Not transmitted */
-
-#ifdef LOG_DEBUG
- for (i = 0; i < state->prim_channels; i++)
- {
- fprintf( stderr, "quant index huff:" );
- for (j = 0; j < 11; j++)
- fprintf (stderr, " %i", state->quant_index_huffman[i][j]);
- fprintf (stderr, "\n");
- }
-#endif
-
- /* Get scale factor adjustment */
- for (j = 0; j < 11; j++)
- {
- for (i = 0; i < state->prim_channels; i++)
- state->scalefactor_adj[i][j] = 1;
- }
- for (i = 0; i < state->prim_channels; i++)
- {
- if (state->quant_index_huffman[i][1] == 0)
- {
- /* Transmitted only if quant_index_huffman=0 (Huffman code used) */
- state->scalefactor_adj[i][1] = adj_table[bitstream_get (state, 2)];
- }
- }
- for (j = 2; j < 6; j++)
- for (i = 0; i < state->prim_channels; i++)
- if (state->quant_index_huffman[i][j] < 3)
- {
- /* Transmitted only if quant_index_huffman < 3 */
- state->scalefactor_adj[i][j] =
- adj_table[bitstream_get (state, 2)];
- }
- for (j = 6; j < 11; j++)
- for (i = 0; i < state->prim_channels; i++)
- if (state->quant_index_huffman[i][j] < 7)
- {
- /* Transmitted only if quant_index_huffman < 7 */
- state->scalefactor_adj[i][j] =
- adj_table[bitstream_get (state, 2)];
- }
-
-#ifdef LOG_DEBUG
- for (i = 0; i < state->prim_channels; i++)
- {
- fprintf (stderr, "scalefac adj:");
- for (j = 0; j < 11; j++)
- fprintf (stderr, " %1.3f", state->scalefactor_adj[i][j]);
- fprintf (stderr, "\n");
- }
-#endif
-
- if (state->crc_present)
- {
- /* Audio header CRC check */
- bitstream_get (state, 16);
- }
-
- state->current_subframe = 0;
- state->current_subsubframe = 0;
-
- return 0;
-}
-
-static int dts_subframe_header (dts_state_t * state)
-{
- /* Primary audio coding side information */
- int j, k;
-
- /* Subsubframe count */
- state->subsubframes = bitstream_get (state, 2) + 1;
-#ifdef LOG_DEBUG
- fprintf (stderr, "subsubframes: %i\n", state->subsubframes);
-#endif
-
- /* Partial subsubframe sample count */
- state->partial_samples = bitstream_get (state, 3);
-#ifdef LOG_DEBUG
- fprintf (stderr, "partial samples: %i\n", state->partial_samples);
-#endif
-
- /* Get prediction mode for each subband */
- for (j = 0; j < state->prim_channels; j++)
- {
- for (k = 0; k < state->subband_activity[j]; k++)
- state->prediction_mode[j][k] = bitstream_get (state, 1);
-#ifdef LOG_DEBUG
- fprintf (stderr, "prediction mode:");
- for (k = 0; k < state->subband_activity[j]; k++)
- fprintf (stderr, " %i", state->prediction_mode[j][k]);
- fprintf (stderr, "\n");
-#endif
- }
-
- /* Get prediction codebook */
- for (j = 0; j < state->prim_channels; j++)
- {
- for (k = 0; k < state->subband_activity[j]; k++)
- {
- if (state->prediction_mode[j][k] > 0)
- {
- /* (Prediction coefficient VQ address) */
- state->prediction_vq[j][k] = bitstream_get (state, 12);
-#ifdef LOG_DEBUG
- fprintf (stderr, "prediction coefs: %f, %f, %f, %f\n",
- (double)adpcm_vb[state->prediction_vq[j][k]][0]/8192,
- (double)adpcm_vb[state->prediction_vq[j][k]][1]/8192,
- (double)adpcm_vb[state->prediction_vq[j][k]][2]/8192,
- (double)adpcm_vb[state->prediction_vq[j][k]][3]/8192);
-#endif
- }
- }
- }
-
- /* Bit allocation index */
- for (j = 0; j < state->prim_channels; j++)
- {
- for (k = 0; k < state->vq_start_subband[j]; k++)
- {
- if (state->bitalloc_huffman[j] == 6)
- state->bitalloc[j][k] = bitstream_get (state, 5);
- else if (state->bitalloc_huffman[j] == 5)
- state->bitalloc[j][k] = bitstream_get (state, 4);
- else
- {
- state->bitalloc[j][k] = InverseQ (state,
- bitalloc_12[state->bitalloc_huffman[j]]);
- }
-
- if (state->bitalloc[j][k] > 26)
- {
- fprintf (stderr, "bitalloc index [%i][%i] too big (%i)\n",
- j, k, state->bitalloc[j][k]);
- return -1;
- }
- }
-
-#ifdef LOG_DEBUG
- fprintf (stderr, "bitalloc index: ");
- for (k = 0; k < state->vq_start_subband[j]; k++)
- fprintf (stderr, "%2.2i ", state->bitalloc[j][k]);
- fprintf (stderr, "\n");
-#endif
- }
-
- /* Transition mode */
- for (j = 0; j < state->prim_channels; j++)
- {
- for (k = 0; k < state->subband_activity[j]; k++)
- {
- state->transition_mode[j][k] = 0;
- if (state->subsubframes > 1 &&
- k < state->vq_start_subband[j] &&
- state->bitalloc[j][k] > 0)
- {
- state->transition_mode[j][k] = InverseQ (state,
- tmode[state->transient_huffman[j]]);
- }
- }
-#ifdef LOG_DEBUG
- fprintf (stderr, "Transition mode:");
- for (k = 0; k < state->subband_activity[j]; k++)
- fprintf (stderr, " %i", state->transition_mode[j][k]);
- fprintf (stderr, "\n");
-#endif
- }
-
- /* Scale factors */
- for (j = 0; j < state->prim_channels; j++)
- {
- int *scale_table;
- int scale_sum;
-
- for (k = 0; k < state->subband_activity[j]; k++)
- {
- state->scale_factor[j][k][0] = 0;
- state->scale_factor[j][k][1] = 0;
- }
-
- if (state->scalefactor_huffman[j] == 6)
- scale_table = scale_factor_quant7;
- else
- scale_table = scale_factor_quant6;
-
- /* When huffman coded, only the difference is encoded */
- scale_sum = 0;
-
- for (k = 0; k < state->subband_activity[j]; k++)
- {
- if (k >= state->vq_start_subband[j] || state->bitalloc[j][k] > 0)
- {
- if (state->scalefactor_huffman[j] < 5)
- {
- /* huffman encoded */
- scale_sum += InverseQ (state,
- scales_129[state->scalefactor_huffman[j]]);
- }
- else if (state->scalefactor_huffman[j] == 5)
- {
- scale_sum = bitstream_get (state, 6);
- }
- else if (state->scalefactor_huffman[j] == 6)
- {
- scale_sum = bitstream_get (state, 7);
- }
-
- state->scale_factor[j][k][0] = scale_table[scale_sum];
- }
-
- if (k < state->vq_start_subband[j] && state->transition_mode[j][k])
- {
- /* Get second scale factor */
- if (state->scalefactor_huffman[j] < 5)
- {
- /* huffman encoded */
- scale_sum += InverseQ (state,
- scales_129[state->scalefactor_huffman[j]]);
- }
- else if (state->scalefactor_huffman[j] == 5)
- {
- scale_sum = bitstream_get (state, 6);
- }
- else if (state->scalefactor_huffman[j] == 6)
- {
- scale_sum = bitstream_get (state, 7);
- }
-
- state->scale_factor[j][k][1] = scale_table[scale_sum];
- }
- }
-
-#ifdef LOG_DEBUG
- fprintf (stderr, "Scale factor:");
- for (k = 0; k < state->subband_activity[j]; k++)
- {
- if (k >= state->vq_start_subband[j] || state->bitalloc[j][k] > 0)
- fprintf (stderr, " %i", state->scale_factor[j][k][0]);
- if (k < state->vq_start_subband[j] && state->transition_mode[j][k])
- fprintf (stderr, " %i(t)", state->scale_factor[j][k][1]);
- }
- fprintf (stderr, "\n");
-#endif
- }
-
- /* Joint subband scale factor codebook select */
- for (j = 0; j < state->prim_channels; j++)
- {
- /* Transmitted only if joint subband coding enabled */
- if (state->joint_intensity[j] > 0)
- state->joint_huff[j] = bitstream_get (state, 3);
- }
-
- /* Scale factors for joint subband coding */
- for (j = 0; j < state->prim_channels; j++)
- {
- int source_channel;
-
- /* Transmitted only if joint subband coding enabled */
- if (state->joint_intensity[j] > 0)
- {
- int scale = 0;
- source_channel = state->joint_intensity[j] - 1;
-
- /* When huffman coded, only the difference is encoded
- * (is this valid as well for joint scales ???) */
-
- for (k = state->subband_activity[j];
- k < state->subband_activity[source_channel]; k++)
- {
- if (state->joint_huff[j] < 5)
- {
- /* huffman encoded */
- scale = InverseQ (state,
- scales_129[state->joint_huff[j]]);
- }
- else if (state->joint_huff[j] == 5)
- {
- scale = bitstream_get (state, 6);
- }
- else if (state->joint_huff[j] == 6)
- {
- scale = bitstream_get (state, 7);
- }
-
- scale += 64; /* bias */
- state->joint_scale_factor[j][k] = scale;/*joint_scale_table[scale];*/
- }
-
- if (!state->debug_flag & 0x02)
- {
- fprintf (stderr, "Joint stereo coding not supported\n");
- state->debug_flag |= 0x02;
- }
-
-#ifdef LOG_DEBUG
- fprintf (stderr, "Joint scale factor index:\n");
- for (k = state->subband_activity[j];
- k < state->subband_activity[source_channel]; k++)
- fprintf (stderr, " %i", state->joint_scale_factor[j][k]);
- fprintf (stderr, "\n");
-#endif
- }
- }
-
- /* Stereo downmix coefficients */
- if (state->prim_channels > 2 && state->downmix)
- {
- for (j = 0; j < state->prim_channels; j++)
- {
- state->downmix_coef[j][0] = bitstream_get (state, 7);
- state->downmix_coef[j][1] = bitstream_get (state, 7);
- }
- }
-
- /* Dynamic range coefficient */
- if (state->dynrange) state->dynrange_coef = bitstream_get (state, 8);
-
- /* Side information CRC check word */
- if (state->crc_present)
- {
- bitstream_get (state, 16);
- }
-
- /*
- * Primary audio data arrays
- */
-
- /* VQ encoded high frequency subbands */
- for (j = 0; j < state->prim_channels; j++)
- {
- for (k = state->vq_start_subband[j];
- k < state->subband_activity[j]; k++)
- {
- /* 1 vector -> 32 samples */
- state->high_freq_vq[j][k] = bitstream_get (state, 10);
-
-#ifdef LOG_DEBUG
- fprintf( stderr, "VQ index: %i\n", state->high_freq_vq[j][k] );
-#endif
- }
- }
-
- /* Low frequency effect data */
- if (state->lfe)
- {
- /* LFE samples */
- int lfe_samples = 2 * state->lfe * state->subsubframes;
- double lfe_scale;
-
- for (j = lfe_samples; j < lfe_samples * 2; j++)
- {
- /* Signed 8 bits int */
- state->lfe_data[j] =
- (signed int)(signed char)bitstream_get (state, 8);
- }
-
- /* Scale factor index */
- state->lfe_scale_factor =
- scale_factor_quant7[bitstream_get (state, 8)];
-
- /* Quantization step size * scale factor */
- lfe_scale = 0.035 * state->lfe_scale_factor;
-
- for (j = lfe_samples; j < lfe_samples * 2; j++)
- state->lfe_data[j] *= lfe_scale;
-
-#ifdef LOG_DEBUG
- fprintf (stderr, "LFE samples:\n");
- for (j = lfe_samples; j < lfe_samples * 2; j++)
- fprintf (stderr, " %f", state->lfe_data[j]);
- fprintf (stderr, "\n");
-#endif
-
- }
-
- return 0;
-}
-
-static int dts_subsubframe (dts_state_t * state)
-{
- int k, l;
- int subsubframe = state->current_subsubframe;
-
- double *quant_step_table;
-
- /* FIXME */
- double subband_samples[DTS_PRIM_CHANNELS_MAX][DTS_SUBBANDS][8];
-
- /*
- * Audio data
- */
-
- /* Select quantization step size table */
- if (state->bit_rate == 0x1f)
- quant_step_table = lossless_quant_d;
- else
- quant_step_table = lossy_quant_d;
-
- for (k = 0; k < state->prim_channels; k++)
- {
- for (l = 0; l < state->vq_start_subband[k] ; l++)
- {
- int m;
-
- /* Select the mid-tread linear quantizer */
- int abits = state->bitalloc[k][l];
-
- double quant_step_size = quant_step_table[abits];
- double rscale;
-
- /*
- * Determine quantization index code book and its type
- */
-
- /* Select quantization index code book */
- int sel = state->quant_index_huffman[k][abits];
-
- /* Determine its type */
- int q_type = 1; /* (Assume Huffman type by default) */
- if (abits >= 11 || !bitalloc_select[abits][sel])
- {
- /* Not Huffman type */
- if (abits <= 7) q_type = 3; /* Block code */
- else q_type = 2; /* No further encoding */
- }
-
- if (abits == 0) q_type = 0; /* No bits allocated */
-
- /*
- * Extract bits from the bit stream
- */
- switch (q_type)
- {
- case 0: /* No bits allocated */
- for (m=0; m<8; m++)
- subband_samples[k][l][m] = 0;
- break;
-
- case 1: /* Huffman code */
- for (m=0; m<8; m++)
- subband_samples[k][l][m] =
- InverseQ (state, bitalloc_select[abits][sel]);
- break;
-
- case 2: /* No further encoding */
- for (m=0; m<8; m++)
- {
- /* Extract (signed) quantization index */
- int q_index = bitstream_get (state, abits - 3);
- if( q_index & (1 << (abits - 4)) )
- {
- q_index = (1 << (abits - 3)) - q_index;
- q_index = -q_index;
- }
- subband_samples[k][l][m] = q_index;
- }
- break;
-
- case 3: /* Block code */
- {
- int block_code1, block_code2, size, levels;
- int block[8];
-
- switch (abits)
- {
- case 1:
- size = 7;
- levels = 3;
- break;
- case 2:
- size = 10;
- levels = 5;
- break;
- case 3:
- size = 12;
- levels = 7;
- break;
- case 4:
- size = 13;
- levels = 9;
- break;
- case 5:
- size = 15;
- levels = 13;
- break;
- case 6:
- size = 17;
- levels = 17;
- break;
- case 7:
- default:
- size = 19;
- levels = 25;
- break;
- }
-
- block_code1 = bitstream_get (state, size);
- /* Should test return value */
- decode_blockcode (block_code1, levels, block);
- block_code2 = bitstream_get (state, size);
- decode_blockcode (block_code2, levels, &block[4]);
- for (m=0; m<8; m++)
- subband_samples[k][l][m] = block[m];
-
- }
- break;
-
- default: /* Undefined */
- fprintf (stderr, "Unknown quantization index codebook");
- return -1;
- }
-
- /*
- * Account for quantization step and scale factor
- */
-
- /* Deal with transients */
- if (state->transition_mode[k][l] &&
- subsubframe >= state->transition_mode[k][l])
- rscale = quant_step_size * state->scale_factor[k][l][1];
- else
- rscale = quant_step_size * state->scale_factor[k][l][0];
-
- /* Adjustment */
- rscale *= state->scalefactor_adj[k][sel];
- for (m=0; m<8; m++) subband_samples[k][l][m] *= rscale;
-
- /*
- * Inverse ADPCM if in prediction mode
- */
- if (state->prediction_mode[k][l])
- {
- int n;
- for (m=0; m<8; m++)
- {
- for (n=1; n<=4; n++)
- if (m-n >= 0)
- subband_samples[k][l][m] +=
- (adpcm_vb[state->prediction_vq[k][l]][n-1] *
- subband_samples[k][l][m-n]/8192);
- else if (state->predictor_history)
- subband_samples[k][l][m] +=
- (adpcm_vb[state->prediction_vq[k][l]][n-1] *
- state->subband_samples_hist[k][l][m-n+4]/8192);
- }
- }
- }
-
- /*
- * Decode VQ encoded high frequencies
- */
- for (l = state->vq_start_subband[k];
- l < state->subband_activity[k]; l++)
- {
- /* 1 vector -> 32 samples but we only need the 8 samples
- * for this subsubframe. */
- int m;
-
- if (!state->debug_flag & 0x01)
- {
- fprintf (stderr, "Stream with high frequencies VQ coding\n");
- state->debug_flag |= 0x01;
- }
-
- for (m=0; m<8; m++)
- {
- subband_samples[k][l][m] =
- high_freq_vq[state->high_freq_vq[k][l]][subsubframe*8+m]
- * (double)state->scale_factor[k][l][0] / 16.0;
- }
- }
- }
-
- /* Check for DSYNC after subsubframe */
- if (state->aspf || subsubframe == state->subsubframes - 1)
- {
- if (0xFFFF == bitstream_get (state, 16)) /* 0xFFFF */
- {
-#ifdef LOG_DEBUG
- fprintf( stderr, "Got subframe DSYNC\n" );
-#endif
- }
- else
- {
- fprintf( stderr, "Didn't get subframe DSYNC\n" );
- }
- }
-
- /* Backup predictor history for adpcm */
- for (k = 0; k < state->prim_channels; k++)
- {
- for (l = 0; l < state->vq_start_subband[k] ; l++)
- {
- int m;
- for (m = 0; m < 4; m++)
- state->subband_samples_hist[k][l][m] =
- subband_samples[k][l][4+m];
- }
- }
-
- /* 32 subbands QMF */
- for (k = 0; k < state->prim_channels; k++)
- {
- /*static double pcm_to_float[8] =
- {32768.0, 32768.0, 524288.0, 524288.0, 0, 8388608.0, 8388608.0};*/
-
- qmf_32_subbands (state, k,
- subband_samples[k],
- &state->samples[256*k],
- /*WTF ???*/ 32768.0*3/2/*pcm_to_float[state->source_pcm_res]*/,
- 0/*state->bias*/);
- }
-
- /* Down/Up mixing */
- if (state->prim_channels < dts_channels[state->output & DTS_CHANNEL_MASK])
- {
- dts_upmix (state->samples, state->amode, state->output);
- } else
- if (state->prim_channels > dts_channels[state->output & DTS_CHANNEL_MASK])
- {
- dts_downmix (state->samples, state->amode, state->output, state->bias,
- state->clev, state->slev);
- }
-
- /* Generate LFE samples for this subsubframe FIXME!!! */
- if (state->output & DTS_LFE)
- {
- int lfe_samples = 2 * state->lfe * state->subsubframes;
- int i_channels = dts_channels[state->output & DTS_CHANNEL_MASK];
-
- lfe_interpolation_fir (state->lfe, 2 * state->lfe,
- state->lfe_data + lfe_samples +
- 2 * state->lfe * subsubframe,
- &state->samples[256*i_channels],
- 8388608.0, state->bias);
- /* Outputs 20bits pcm samples */
- }
-
- return 0;
-}
-
-static int dts_subframe_footer (dts_state_t * state)
-{
- int aux_data_count = 0, i;
- int lfe_samples;
-
- /*
- * Unpack optional information
- */
-
- /* Time code stamp */
- if (state->timestamp) bitstream_get (state, 32);
-
- /* Auxiliary data byte count */
- if (state->aux_data) aux_data_count = bitstream_get (state, 6);
-
- /* Auxiliary data bytes */
- for(i = 0; i < aux_data_count; i++)
- bitstream_get (state, 8);
-
- /* Optional CRC check bytes */
- if (state->crc_present && (state->downmix || state->dynrange))
- bitstream_get (state, 16);
-
- /* Backup LFE samples history */
- lfe_samples = 2 * state->lfe * state->subsubframes;
- for (i = 0; i < lfe_samples; i++)
- {
- state->lfe_data[i] = state->lfe_data[i+lfe_samples];
- }
-
-#ifdef LOG_DEBUG
- fprintf( stderr, "\n" );
-#endif
-
- return 0;
-}
-
-int dts_block (dts_state_t * state)
-{
- /* Sanity check */
- if (state->current_subframe >= state->subframes)
- {
- fprintf (stderr, "check failed: %i>%i",
- state->current_subframe, state->subframes);
- return -1;
- }
-
- if (!state->current_subsubframe)
- {
-#ifdef LOG_DEBUG
- fprintf (stderr, "DSYNC dts_subframe_header\n");
-#endif
- /* Read subframe header */
- if (dts_subframe_header (state)) return -1;
- }
-
- /* Read subsubframe */
-#ifdef LOG_DEBUG
- fprintf (stderr, "DSYNC dts_subsubframe\n");
-#endif
- if (dts_subsubframe (state)) return -1;
-
- /* Update state */
- state->current_subsubframe++;
- if (state->current_subsubframe >= state->subsubframes)
- {
- state->current_subsubframe = 0;
- state->current_subframe++;
- }
- if (state->current_subframe >= state->subframes)
- {
-#ifdef LOG_DEBUG
- fprintf(stderr, "DSYNC dts_subframe_footer\n");
-#endif
- /* Read subframe footer */
- if (dts_subframe_footer (state)) return -1;
- }
-
- return 0;
-}
-
-/* Very compact version of the block code decoder that does not use table
- * look-up but is slightly slower */
-int decode_blockcode( int code, int levels, int *values )
-{
- int i;
- int offset = (levels - 1) >> 1;
-
- for (i = 0; i < 4; i++)
- {
- values[i] = (code % levels) - offset;
- code /= levels;
- }
-
- if (code == 0)
- return 1;
- else
- {
- fprintf (stderr, "ERROR: block code look-up failed\n");
- return 0;
- }
-}
-
-static void pre_calc_cosmod( dts_state_t * state )
-{
- int i, j, k;
-
- for (j=0,k=0;k<16;k++)
- for (i=0;i<16;i++)
- state->cos_mod[j++] = cos((2*i+1)*(2*k+1)*M_PI/64);
-
- for (k=0;k<16;k++)
- for (i=0;i<16;i++)
- state->cos_mod[j++] = cos((i)*(2*k+1)*M_PI/32);
-
- for (k=0;k<16;k++)
- state->cos_mod[j++] = 0.25/(2*cos((2*k+1)*M_PI/128));
-
- for (k=0;k<16;k++)
- state->cos_mod[j++] = -0.25/(2.0*sin((2*k+1)*M_PI/128));
-}
-
-static void qmf_32_subbands (dts_state_t * state, int chans,
- double samples_in[32][8], sample_t *samples_out,
- double scale, sample_t bias)
-{
- double *prCoeff;
- int i, j, k;
- double raXin[32];
-
- double *subband_fir_hist = state->subband_fir_hist[chans];
- double *subband_fir_hist2 = state->subband_fir_noidea[chans];
-
- int nChIndex = 0, NumSubband = 32, nStart = 0, nEnd = 8, nSubIndex;
-
- /* Select filter */
- if (!state->multirate_inter) /* Non-perfect reconstruction */
- prCoeff = fir_32bands_nonperfect;
- else /* Perfect reconstruction */
- prCoeff = fir_32bands_perfect;
-
- /* Reconstructed channel sample index */
- for (nSubIndex=nStart; nSubIndex<nEnd; nSubIndex++)
- {
- double A[16], B[16], SUM[16], DIFF[16];
-
- /* Load in one sample from each subband */
- for (i=0; i<state->subband_activity[chans]; i++)
- raXin[i] = samples_in[i][nSubIndex];
-
- /* Clear inactive subbands */
- for (i=state->subband_activity[chans]; i<NumSubband; i++)
- raXin[i] = 0.0;
-
- /* Multiply by cosine modulation coefficients and
- * create temporary arrays SUM and DIFF */
- for (j=0,k=0;k<16;k++)
- {
- A[k] = 0.0;
- for (i=0;i<16;i++)
- A[k]+=(raXin[2*i]+raXin[2*i+1])*state->cos_mod[j++];
- }
-
- for (k=0;k<16;k++)
- {
- B[k] = 0.0;
- for (i=0;i<16;i++)
- {
- if(i>0) B[k]+=(raXin[2*i]+raXin[2*i-1])*state->cos_mod[j++];
- else B[k]+=(raXin[2*i])*state->cos_mod[j++];
- }
- SUM[k]=A[k]+B[k];
- DIFF[k]=A[k]-B[k];
- }
-
- /* Store history */
- for (k=0;k<16;k++)
- subband_fir_hist[k]=state->cos_mod[j++]*SUM[k];
- for (k=0;k<16;k++)
- subband_fir_hist[32-k-1]=state->cos_mod[j++]*DIFF[k];
- /* Multiply by filter coefficients */
- for (k=31,i=0;i<32;i++,k--)
- for (j=0;j<512;j+=64)
- subband_fir_hist2[i] += prCoeff[i+j]*
- (subband_fir_hist[i+j] - subband_fir_hist[j+k]);
- for (k=31,i=0;i<32;i++,k--)
- for (j=0;j<512;j+=64)
- subband_fir_hist2[32+i] += prCoeff[32+i+j]*
- (-subband_fir_hist[i+j] - subband_fir_hist[j+k]);
-
- /* Create 32 PCM output samples */
- for (i=0;i<32;i++)
- samples_out[nChIndex++] = subband_fir_hist2[i] / scale + bias;
-
- /* Update working arrays */
- for (i=511;i>=32;i--)
- subband_fir_hist[i] = subband_fir_hist[i-32];
- for (i=0;i<NumSubband;i++)
- subband_fir_hist2[i] = subband_fir_hist2[i+32];
- for (i=0;i<NumSubband;i++)
- subband_fir_hist2[i+32] = 0.0;
- }
-}
-
-static void lfe_interpolation_fir (int nDecimationSelect, int nNumDeciSample,
- double *samples_in, sample_t *samples_out,
- double scale, sample_t bias)
-{
- /* samples_in: An array holding decimated samples.
- * Samples in current subframe starts from samples_in[0],
- * while samples_in[-1], samples_in[-2], ..., stores samples
- * from last subframe as history.
- *
- * samples_out: An array holding interpolated samples
- */
-
- int nDeciFactor, k, J;
- double *prCoeff;
-
- int NumFIRCoef = 512; /* Number of FIR coefficients */
- int nInterpIndex = 0; /* Index to the interpolated samples */
- int nDeciIndex;
-
- /* Select decimation filter */
- if (nDecimationSelect==1)
- {
- /* 128 decimation */
- nDeciFactor = 128;
- /* Pointer to the FIR coefficients array */
- prCoeff = lfe_fir_128;
- } else {
- /* 64 decimation */
- nDeciFactor = 64;
- prCoeff = lfe_fir_64;
- }
-
- /* Interpolation */
- for (nDeciIndex=0; nDeciIndex<nNumDeciSample; nDeciIndex++)
- {
- /* One decimated sample generates nDeciFactor interpolated ones */
- for (k=0; k<nDeciFactor; k++)
- {
- /* Clear accumulation */
- double rTmp = 0.0;
-
- /* Accumulate */
- for (J=0; J<NumFIRCoef/nDeciFactor; J++)
- rTmp += samples_in[nDeciIndex-J]*prCoeff[k+J*nDeciFactor];
-
- /* Save interpolated samples */
- samples_out[nInterpIndex++] = rTmp / scale + bias;
- }
- }
-}
-
-void dts_dynrng (dts_state_t * state,
- level_t (* call) (level_t, void *), void * data)
-{
- state->dynrange = 0;
- if (call) {
- state->dynrange = 1;
- state->dynrngcall = call;
- state->dynrngdata = data;
- }
-}
-
-void dts_free (dts_state_t * state)
-{
- free (state->samples);
- free (state);
-}
diff --git a/src/libdts/tables.h b/src/libdts/tables.h
deleted file mode 100644
index 73d109ea3..000000000
--- a/src/libdts/tables.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * tables.h
- * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
- *
- * This file is part of dtsdec, a free DTS Coherent Acoustics stream decoder.
- * See http://www.videolan.org/dtsdec.html for updates.
- *
- * dtsdec 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.
- *
- * dtsdec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-static const int dts_sample_rates[] =
-{
- 0, 8000, 16000, 32000, 0, 0, 11025, 22050, 44100, 0, 0,
- 12000, 24000, 48000, 96000, 192000
-};
-
-static const int dts_bit_rates[] =
-{
- 32000, 56000, 64000, 96000, 112000, 128000,
- 192000, 224000, 256000, 320000, 384000,
- 448000, 512000, 576000, 640000, 768000,
- 896000, 1024000, 1152000, 1280000, 1344000,
- 1408000, 1411200, 1472000, 1536000, 1920000,
- 2048000, 3072000, 3840000, 1/*open*/, 2/*variable*/, 3/*lossless*/
-};
-
-static const uint8_t dts_channels[] =
-{
- 1, 2, 2, 2, 2, 3, 3, 4, 4, 5, 6, 6, 6, 7, 8, 8
-};
-
-static const uint8_t dts_bits_per_sample[] =
-{
- 16, 16, 20, 20, 0, 24, 24
-};
diff --git a/src/libdts/tables_adpcm.h b/src/libdts/tables_adpcm.h
deleted file mode 100644
index 0c63a6020..000000000
--- a/src/libdts/tables_adpcm.h
+++ /dev/null
@@ -1,4122 +0,0 @@
-/*
- * tables_adpcm.h
- * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
- *
- * This file is part of dtsdec, a free DTS Coherent Acoustics stream decoder.
- * See http://www.videolan.org/dtsdec.html for updates.
- *
- * dtsdec 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.
- *
- * dtsdec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/* 16bits signed fractional Q13 binary codes */
-static int16_t adpcm_vb[4096][4] =
-{
- { 9928, -2618, -1093, -1263 },
- { 11077, -2876, -1747, -308 },
- { 10503, -1082, -1426, -1167 },
- { 9337, -2403, -1495, 274 },
- { 10698, -2529, -532, -1122 },
- { 10368, -3974, -1264, -750 },
- { 10070, -3667, 346, 863 },
- { 10278, -3093, 311, -576 },
- { 9894, -1330, -1428, -860 },
- { 10544, -1923, -1058, -971 },
- { 10996, -1632, -841, -1404 },
- { 11832, -3465, 1658, -1990 },
- { 10852, -688, -2658, -499 },
- { 10546, -1749, -147, -1733 },
- { 10801, -1004, -708, -1453 },
- { 10588, -441, -2113, -952 },
- { 10141, -3331, -582, -1432 },
- { 9608, -2590, 383, 258 },
- { 11422, -3265, 229, -1544 },
- { 10460, -1338, -713, -1568 },
- { 10306, -1721, -1660, -603 },
- { 9580, -1812, -1235, -1061 },
- { 11471, -2285, -1617, -607 },
- { 10081, -2225, -1408, -868 },
- { 10715, -2624, -1367, -704 },
- { 10616, -1871, -2770, -35 },
- { 9352, -2340, -1024, -1566 },
- { 11065, -1458, -1926, -735 },
- { 11334, -2056, -1041, -1144 },
- { 9825, -2048, -794, -1536 },
- { 11850, -2695, -1123, -867 },
- { 10654, -2226, -1891, -373 },
- { 10024, -1557, -808, -1069 },
- { 11142, -1266, -3238, 128 },
- { 11729, -3282, -514, -1011 },
- { 11402, -2094, -2335, -189 },
- { 10195, -3658, 181, -1875 },
- { 11431, -2626, -404, -1377 },
- { 11001, -3868, -619, -1077 },
- { 10894, -2559, 274, -1758 },
- { 9633, -1482, -2253, -773 },
- { 11245, -3321, 830, -1972 },
- { 9768, -2701, -199, -1859 },
- { 10500, -2042, 525, -2043 },
- { 11669, -4069, 293, -1468 },
- { 9192, -1991, -583, -61 },
- { 10057, -3220, -2015, -473 },
- { 9497, -2315, -2490, -467 },
- { 10455, -3069, -1194, -1007 },
- { 9994, -1936, -60, -1225 },
- { 9295, -2156, -1761, -1134 },
- { 10085, -3748, -1026, 197 },
- { 9334, -2360, 804, -351 },
- { 11561, -2553, 1352, -2313 },
- { 12837, -3998, 1195, -1958 },
- { 10114, -1100, -2414, -394 },
- { 9341, -2530, 315, 755 },
- { 10131, -3164, 1411, -674 },
- { 9535, -905, -1551, 579 },
- { 11717, -1519, -3051, 91 },
- { 9824, -2911, -2775, 192 },
- { 9662, -2934, -561, 1450 },
- { 11085, -3392, -1298, -659 },
- { 8955, -2102, -1899, 703 },
- { 8607, -1742, -4348, 814 },
- { 7640, -2063, -3617, 52 },
- { 7074, -826, -4325, 4375 },
- { 7714, 584, -4238, 1927 },
- { 6355, -952, -4912, 3127 },
- { 7069, -660, -6413, 4087 },
- { 8313, -132, -2964, -876 },
- { 6952, -1422, -3962, -24 },
- { 9299, -734, -3088, -263 },
- { 9484, -574, -4513, 466 },
- { 7246, -91, -3735, -704 },
- { 8325, -1417, -3090, -530 },
- { 6469, -1226, -4757, 829 },
- { 6652, -368, -5682, 1393 },
- { 7971, -1278, -2284, 1205 },
- { 7229, -699, -3556, 1840 },
- { 7994, 1284, -2729, 732 },
- { 9005, -698, -4522, 2189 },
- { 6963, 197, -2727, 380 },
- { 8527, 135, -3991, -213 },
- { 8840, 934, -3014, -567 },
- { 10125, 418, -3284, -371 },
- { 6367, 361, -2318, 2554 },
- { 7892, 172, -5247, 4673 },
- { 6674, 387, -5424, 4398 },
- { 6240, 684, -4047, 1219 },
- { 11170, -794, -5081, 1195 },
- { 11765, -648, -6265, 2052 },
- { 10845, -775, -3837, 366 },
- { 12496, -689, -8260, 3562 },
- { 7893, -1166, -4972, 988 },
- { 8592, 1052, -5986, 3087 },
- { 7277, 1874, -5685, 3579 },
- { 6900, 2016, -4809, 3491 },
- { 8530, -2405, -3250, 1986 },
- { 9426, 494, -7067, 5038 },
- { 10285, 564, -8210, 5370 },
- { 8749, -2207, -3980, 2852 },
- { 9653, -2686, -4300, 1400 },
- { 9770, -2286, -5663, 4233 },
- { 8490, -4, -7048, 4496 },
- { 7697, -1209, -5328, 3183 },
- { 6451, 801, -4324, -554 },
- { 7387, 1806, -5265, 545 },
- { 7450, -2302, -4445, 1418 },
- { 8817, -1370, -5827, 2168 },
- { 10324, -2406, -5629, 2579 },
- { 8863, -2578, -3537, 467 },
- { 6901, -1624, -3169, 3392 },
- { 7846, 156, -6948, 3381 },
- { 7928, -1115, -5972, 4816 },
- { 6089, -599, -4368, -320 },
- { 7833, 1246, -3960, -621 },
- { 8931, 2521, -6768, 2052 },
- { 8900, 1944, -4126, 40 },
- { 7661, -34, -2855, 2480 },
- { 5873, 474, -3262, 3712 },
- { 7535, -234, -4699, 216 },
- { 5856, 143, -5142, 73 },
- { 8944, -106, -5874, 3663 },
- { 7134, 426, -5879, 2895 },
- { 10199, 1011, -4762, 369 },
- { 8454, 264, -5971, 1291 },
- { 7822, -2449, -4333, 4540 },
- { 6200, -2758, -2632, 1497 },
- { 6070, -4315, -2699, 414 },
- { 7047, -3739, -3210, 1060 },
- { 5675, -3801, -2717, -407 },
- { 4789, -4063, -2628, -744 },
- { 4023, -3366, -3133, -726 },
- { 4296, -2407, -3381, -513 },
- { 4388, -2931, -2820, 1512 },
- { 4559, -4233, -1941, 1976 },
- { 6702, -3208, -1755, 1680 },
- { 4416, -3521, -1052, 2984 },
- { 7154, -4266, -1203, 3732 },
- { 3625, -4242, -3244, 1395 },
- { 6518, -2856, -1304, 2887 },
- { 6170, -1949, -3014, 3973 },
- { 5189, -2451, -4020, 3477 },
- { 6218, -2988, -1921, 3844 },
- { 4827, -3688, -1928, 3343 },
- { 6668, -3991, -2805, 3095 },
- { 5297, -3115, -3684, 2390 },
- { 5354, -4614, -2662, 1504 },
- { 4196, -3091, -4147, 1135 },
- { 3540, -2893, -4007, 100 },
- { 5569, -1602, -4007, 1909 },
- { 4341, -2091, -4272, 252 },
- { 5559, -2878, -3832, 498 },
- { 4548, -4479, -2898, -27 },
- { 5176, -2494, -4635, 1476 },
- { 3294, -3485, -3738, 716 },
- { 4920, -1229, -4195, -365 },
- { 3257, -3518, -3349, 2862 },
- { 5286, -1948, -3485, -778 },
- { 6502, -3051, -152, 2854 },
- { 5864, -4192, -1076, 3451 },
- { 4656, -3122, -3448, 179 },
- { 5907, -754, -1596, 3116 },
- { 7229, -3680, -1590, 2892 },
- { 5107, -3888, -3364, 806 },
- { 6764, -2635, -3450, 134 },
- { 5258, -2827, -2844, -1052 },
- { 5798, -1725, -4305, 205 },
- { 5404, -1213, -3362, 449 },
- { 6224, -2738, -3046, -581 },
- { 4223, -2438, -2725, 3745 },
- { 4751, -3411, -2123, 116 },
- { 3868, -3000, -3954, 2297 },
- { 6819, -2899, -4277, 2825 },
- { 4207, -4754, -2808, 865 },
- { 4804, -1494, -1997, 4688 },
- { 5282, -2213, -548, 3559 },
- { 5580, -1912, -566, 4370 },
- { 6168, -2857, -672, 4053 },
- { 6583, -4515, -2850, 1670 },
- { 6511, -3093, -3988, 1421 },
- { 4646, -1790, -1443, 3650 },
- { 5915, -924, -2020, 896 },
- { 7814, -4181, -3152, 2007 },
- { 6190, -2238, -4817, 2279 },
- { 4737, -4034, -3288, 1835 },
- { 8161, -3633, -3423, 3137 },
- { 7415, -2351, -2088, 4290 },
- { 4106, -2517, -62, 2905 },
- { 4909, -3145, -614, 4112 },
- { 4938, -3281, -397, 1100 },
- { -173, 919, 1589, -5363 },
- { -13, 796, -295, -6655 },
- { -1860, -829, 1141, -4555 },
- { 2298, -838, -664, -5005 },
- { -884, -1097, 2074, -4613 },
- { -101, 281, 2846, -4535 },
- { 1166, 453, 2429, -5910 },
- { 879, -664, 2370, -5452 },
- { 1415, -370, -1699, -4727 },
- { -1413, 1277, -669, -6649 },
- { 2133, 304, -968, -4624 },
- { 380, 586, -2087, -4892 },
- { 1336, 275, -82, -5789 },
- { -2459, 1057, -34, -5416 },
- { 2278, -1758, 866, -5653 },
- { 1945, -2295, -149, -5302 },
- { 1287, -3525, 996, -5255 },
- { 2297, 803, 1177, -6067 },
- { 187, -180, -619, -6202 },
- { -793, -2537, 1554, -5057 },
- { -2703, -204, -629, -5853 },
- { -1007, -146, 313, -5582 },
- { 830, 357, 869, -6363 },
- { -228, -575, -3177, -4433 },
- { -1001, -1553, -142, -5708 },
- { -1644, 1683, 1721, -4533 },
- { 893, 1924, -15, -5791 },
- { 2195, 2061, -262, -5471 },
- { 3031, 270, 311, -5096 },
- { 1912, 1638, -1523, -4677 },
- { -3142, -55, 253, -4914 },
- { 356, -1680, 343, -6123 },
- { -2241, -1734, -976, -5939 },
- { -2196, -2893, 547, -4938 },
- { -1245, 126, -1916, -5419 },
- { -249, -3755, -1422, -5594 },
- { 575, -2683, -1926, -4566 },
- { -762, 1885, 192, -5880 },
- { -811, -2562, -1068, -6013 },
- { -2264, -3086, -976, -4775 },
- { 70, -1215, 2880, -4410 },
- { 714, -3760, 2916, -4691 },
- { -244, -3404, 1740, -4493 },
- { 684, -5137, -328, -5608 },
- { -529, -3825, -1786, -4535 },
- { -713, -4743, -1118, -5546 },
- { 2718, -3788, 1798, -5708 },
- { -1639, -3679, -1564, -6095 },
- { 1693, -2642, -1389, -4539 },
- { 505, -1573, -1651, -4878 },
- { -835, -2256, -1941, -5352 },
- { 1464, -411, 1993, -6441 },
- { 493, -3184, -145, -6148 },
- { -1413, 499, -1617, -6479 },
- { -294, 1722, -1419, -5725 },
- { -2937, -1528, -175, -4624 },
- { -594, -5911, -56, -6146 },
- { -300, -4275, 1156, -5947 },
- { 552, -2643, 2669, -3959 },
- { 905, -4158, 1789, -5809 },
- { 1336, -2009, 2108, -5903 },
- { 1555, -3600, 1110, -6759 },
- { -1294, -3464, 77, -6084 },
- { -1139, -4006, -1270, -4181 },
- { -5094, -3296, 1092, -2847 },
- { -5503, -2883, 1984, -2067 },
- { -4671, -4218, -1417, -4132 },
- { -3763, -3818, 1262, -3082 },
- { -5132, -3430, 2928, -728 },
- { -5957, -2877, 1251, -2446 },
- { -4425, -2319, -212, -4276 },
- { -6201, -1993, 1774, -2182 },
- { -5500, -3836, 2201, -1396 },
- { -6934, -2334, 2366, -1293 },
- { -6124, -4140, 1337, -1977 },
- { -6553, -4186, 1756, -1325 },
- { -5126, -1258, 744, -3656 },
- { -5167, -1390, 1581, -2895 },
- { -4525, -3398, 2429, -1865 },
- { -4076, -3183, 2027, -2510 },
- { -6191, -3274, 1838, -1814 },
- { -4454, -2753, 2723, -1185 },
- { -6655, -4797, 251, -2595 },
- { -6332, -2232, 1832, 217 },
- { -5869, -1698, 134, 340 },
- { -6614, -1045, 2126, -1932 },
- { -4859, -2107, 2010, -2435 },
- { -6274, -1622, 2808, -1374 },
- { -3119, -3209, 521, -3988 },
- { -5676, -2082, -420, -2711 },
- { -7073, -3623, 696, -2343 },
- { -5986, -4224, 572, -2454 },
- { -4340, -4521, 882, -2771 },
- { -6178, -1933, 535, -1444 },
- { -4923, -4163, 1744, -2066 },
- { -6410, -1519, 1058, -2683 },
- { -5077, -1185, 856, -2216 },
- { -7091, -2444, 687, -2597 },
- { -5284, -2165, 3239, -993 },
- { -4763, -1497, 197, -3179 },
- { -4128, -4958, -396, -3578 },
- { -5054, -3878, -647, -2672 },
- { -7005, -3348, 1679, -1579 },
- { -5767, -1017, 2582, -1915 },
- { -7069, -2787, 1331, -2070 },
- { -5532, -2296, 706, -2950 },
- { -5059, -3543, -821, -3637 },
- { -6639, -1835, 1016, -696 },
- { -5611, -5220, -694, -3371 },
- { -5994, -2803, 2933, -729 },
- { -5948, -619, 1596, -2676 },
- { -5486, -4419, 153, -3265 },
- { -4329, -3440, 1646, -1439 },
- { -4083, -3978, 177, -3569 },
- { -4289, -2599, 1224, -3075 },
- { -5707, -3253, 1912, -759 },
- { -6606, -3437, 2562, -571 },
- { -5254, -2444, 769, -352 },
- { -6545, -3154, 582, -1103 },
- { -5328, -2241, 2566, -1775 },
- { -7216, -1936, 1538, -1983 },
- { -3730, -2451, 426, -3869 },
- { -5110, -1385, 2031, -1169 },
- { -6470, -2715, 269, -3123 },
- { -5806, -2480, -97, -3832 },
- { -3683, -4916, -490, -4330 },
- { -6341, -2083, -669, -115 },
- { -4913, -4079, -837, -4673 },
- { -3274, -2497, 2334, -2652 },
- { -1286, -1731, 2550, -3756 },
- { -3375, -877, 926, -3977 },
- { -2525, -2079, 2879, -2625 },
- { -5308, -504, 3111, -1607 },
- { -4904, 460, 4093, -1232 },
- { -1993, 1616, 4656, -1913 },
- { -3481, -1176, 3119, -2236 },
- { -4132, -1502, 2339, -2545 },
- { -2542, 1151, 3569, -2550 },
- { -4381, 430, 3147, -2082 },
- { -3888, 867, 3899, -1657 },
- { -2861, 1290, 4202, -1979 },
- { -3893, -253, 2363, -2764 },
- { -1705, 688, 3827, -2923 },
- { -2223, 2312, 3700, -3148 },
- { -1986, -720, 5021, -795 },
- { -3177, 242, 1952, -3352 },
- { -1854, 1509, 2528, -3815 },
- { -3173, 97, 5019, -706 },
- { -2689, -145, 1375, -3915 },
- { -4838, -385, 2488, -2427 },
- { -4557, -355, 1603, -3060 },
- { -3522, 1832, 3292, -2674 },
- { -3769, 780, 2378, -2704 },
- { -4323, -1932, 3414, -1169 },
- { -2740, 1158, 2729, -3273 },
- { -3647, 210, 1464, -2892 },
- { -2342, -2097, 1513, -3727 },
- { -4422, -1242, 3130, -1833 },
- { -1308, -1039, 4290, -1875 },
- { -1754, -2535, 3298, -2314 },
- { -4102, -186, 4037, -1094 },
- { -1008, 1570, 3290, 171 },
- { -3322, -2621, 2791, -1536 },
- { -2539, -2597, 3442, -1672 },
- { -3411, -2015, 3670, -1174 },
- { -2097, 730, 5581, -1399 },
- { -1510, -74, 4820, -2004 },
- { -4086, -868, 4425, -771 },
- { -956, -986, 3640, -2925 },
- { -2087, -1250, 3464, -2458 },
- { -3308, -2411, 1334, -3667 },
- { -2264, -389, 4004, -1854 },
- { -680, 239, 4058, -3388 },
- { -1357, 30, 2993, -3658 },
- { -3601, -552, 1177, -1136 },
- { -2641, 442, 4374, -1625 },
- { -2525, 770, 1640, -3895 },
- { -3172, -891, 3893, -1608 },
- { -2996, 13, 3277, -2414 },
- { -899, 1055, 4470, -2501 },
- { -422, -584, 3475, -3787 },
- { -1978, -593, 2566, -3415 },
- { -3150, -1280, 2362, -3047 },
- { -3592, 224, 1026, -3932 },
- { -4840, -1189, 3633, -879 },
- { -3952, -2255, 2916, -1826 },
- { -1695, 28, 1810, -349 },
- { -745, -2484, 3308, -3293 },
- { -1016, 1563, 5365, -1823 },
- { -2172, -1787, 4266, -1287 },
- { -1241, -1951, 3982, -2413 },
- { -2009, -2639, 2330, -3480 },
- { 5105, -1618, -2588, -2015 },
- { 6497, -1523, -3218, -910 },
- { 6526, -2305, -2029, -1790 },
- { 5289, -99, -3436, -400 },
- { 5781, -1623, -1577, -2617 },
- { 5259, -670, -3125, -1700 },
- { 6343, -1256, -331, -3222 },
- { 7967, -678, -2195, -1462 },
- { 6119, -695, -2988, -1538 },
- { 6108, 494, -3359, -1548 },
- { 5067, 969, -2328, -2707 },
- { 7595, -435, -1497, -2056 },
- { 6929, -719, -2420, -1665 },
- { 5190, 584, -2982, -2103 },
- { 6106, -444, -1411, -2739 },
- { 5584, 289, -1804, -2803 },
- { 5276, 227, -1180, -3361 },
- { 7544, -1525, -1834, -1725 },
- { 5986, -1470, -2606, -1701 },
- { 5096, -765, -1712, -3006 },
- { 5423, -149, -3933, -1157 },
- { 7651, 26, -2445, -1507 },
- { 4745, -464, -1735, -2362 },
- { 5352, -1011, -1094, -1999 },
- { 6300, -672, -542, -1950 },
- { 6675, -1020, -1318, -1059 },
- { 7218, -2036, -603, -2462 },
- { 7755, -1514, -2430, -1229 },
- { 5041, 449, -1056, -2405 },
- { 6710, -2277, -1344, -2284 },
- { 6824, -1347, -2254, 251 },
- { 6068, -1857, -983, -1316 },
- { 5603, -2177, -2730, -1477 },
- { 5838, -1059, -3604, -970 },
- { 5076, -789, -335, -2413 },
- { 6191, -1634, -2000, -2129 },
- { 5092, -1292, -2543, -1034 },
- { 5305, 435, -1710, -1850 },
- { 6140, 561, -2176, -2380 },
- { 6752, 348, -2496, -1890 },
- { 6405, 273, -1098, -2778 },
- { 6942, -1340, -496, -1381 },
- { 5238, -687, -2454, -2349 },
- { 6959, -882, -1833, -2061 },
- { 6292, -253, -2125, -2199 },
- { 5838, -574, -759, -3215 },
- { 6954, -1484, -640, -2771 },
- { 7498, -1706, -1210, -2154 },
- { 6772, -1003, -1235, -2532 },
- { 6014, 228, -2154, -1108 },
- { 6943, -2178, -2644, -1122 },
- { 7262, -763, -3056, -1090 },
- { 6273, -1478, -1072, 177 },
- { 4734, 425, -2912, 357 },
- { 7129, 168, -1537, -2327 },
- { 7204, -434, -746, -2660 },
- { 6879, 57, -3087, -1310 },
- { 4623, -610, -718, -3459 },
- { 6565, -543, -1998, -339 },
- { 4752, -277, -2066, -1405 },
- { 7435, -1416, -1904, -505 },
- { 4076, 150, -1222, -3556 },
- { 7082, -28, -1456, -1174 },
- { 5941, -446, -1326, -1158 },
- { 3870, -1648, -2474, -2589 },
- { 858, 37, -3387, -3721 },
- { 3557, -1503, -1664, -3383 },
- { 3336, -1972, -3079, -2216 },
- { 3186, 60, -4185, -863 },
- { 3456, -773, -3066, -2457 },
- { 4131, -913, -2060, -2601 },
- { 4431, -691, -4114, -972 },
- { 3461, -334, -3680, -1751 },
- { 2006, -459, -2214, -3827 },
- { 1322, 32, -2816, -3203 },
- { 4425, -1897, -2791, -1946 },
- { 4504, 23, -3421, -1909 },
- { 3090, -885, -2366, -3264 },
- { 3209, -2363, -3730, -834 },
- { 3312, -1471, -3641, -1579 },
- { 4184, -1669, -3323, -1248 },
- { 2190, -931, -3302, -2944 },
- { 2947, -229, -4791, -1195 },
- { 2020, -1626, -2700, -3125 },
- { 2214, -326, -4352, -1683 },
- { 3286, -2619, -2412, -2458 },
- { 1000, -2571, -4129, -2158 },
- { 2496, -2627, -3611, -1433 },
- { 2043, -2191, -2167, -3827 },
- { 2571, -2544, -1915, -3222 },
- { 2022, -1501, -3856, -2165 },
- { 2685, -1180, -1461, -4038 },
- { 1610, -2313, -4391, -1173 },
- { 2340, -2490, -4215, -516 },
- { 1742, -2615, -3632, -2146 },
- { 523, -1293, -4246, -2442 },
- { 3725, -2723, -3014, -1576 },
- { 3554, -1381, -4200, -824 },
- { 1291, -1594, -4777, -1430 },
- { 1452, 515, -2960, -3830 },
- { 4264, -894, -3305, -1826 },
- { 2606, -1452, -4522, -966 },
- { 1196, -830, -4807, -1816 },
- { 1054, -775, -2616, -4071 },
- { 4206, 415, -4344, -1132 },
- { 3044, 491, -4126, -1934 },
- { 988, -901, -3353, -3443 },
- { 1729, -3063, -2267, -3370 },
- { 3915, 912, -2989, -2387 },
- { 3781, 300, -2457, -3050 },
- { 2712, 924, -1350, -1206 },
- { 4230, 405, -2343, 665 },
- { 1878, -873, -225, -29 },
- { 3510, 56, -1334, -3420 },
- { 2850, 1447, -2651, -3150 },
- { 1510, -706, -4125, -2483 },
- { 3115, 793, -1692, -3894 },
- { 2667, 213, -2973, -2786 },
- { 1184, -2384, -3051, -3173 },
- { 2139, 796, -2079, -3697 },
- { 1464, -1483, -3726, -2754 },
- { 2407, -1148, -3915, -1569 },
- { 2612, -1779, -3217, -2271 },
- { 2406, -2870, -2937, -2496 },
- { 2140, 126, -3646, -2758 },
- { 2952, -1036, 268, -1423 },
- { 93, -1931, -3841, -3535 },
- { 389, -2953, -3383, -3343 },
- { 8652, -5511, -1662, 565 },
- { 7427, -2791, -2535, -842 },
- { 8541, -4253, -1407, -988 },
- { 8018, -3203, -2998, 105 },
- { 7231, -3926, -958, 1308 },
- { 7331, -3690, -363, 2586 },
- { 6803, -3646, -2226, -903 },
- { 8163, -2811, -477, -2235 },
- { 9356, -3818, -1685, -684 },
- { 8466, -2854, -302, -698 },
- { 8458, -3224, 517, 279 },
- { 8074, -2619, -1326, 2596 },
- { 8779, -2761, -2527, -441 },
- { 6533, -2887, -899, -696 },
- { 7394, -2305, -1642, -120 },
- { 8281, -3780, -22, 1305 },
- { 9158, -4413, -779, 901 },
- { 9031, -5240, -1109, 1678 },
- { 8717, -3650, 410, -1075 },
- { 7317, -3197, -818, -2264 },
- { 7934, -2385, -1214, -1886 },
- { 8256, -4441, -291, -587 },
- { 7358, -3395, 1090, -270 },
- { 9446, -4910, -1343, -473 },
- { 8187, -4726, -808, 1166 },
- { 7504, -3845, -47, 267 },
- { 8029, -2146, -1283, -383 },
- { 7461, -2705, -853, 783 },
- { 9367, -3636, -645, -354 },
- { 8955, -3473, -308, -1947 },
- { 8676, -2683, -2099, 1485 },
- { 7481, -3003, -871, -444 },
- { 8015, -2839, -1673, 1175 },
- { 6947, -4643, -1527, -1047 },
- { 7622, -2575, -137, -960 },
- { 9388, -4279, -707, -1322 },
- { 8382, -5259, -1283, -565 },
- { 6856, -4138, -1030, 630 },
- { 8659, -2571, -1124, -1666 },
- { 8763, -3807, -537, 2543 },
- { 8049, -3578, -2186, -604 },
- { 8272, -2351, -1985, -1214 },
- { 6855, -3796, -1527, -1631 },
- { 7178, -2896, -1600, -1756 },
- { 7040, -2888, -89, -1586 },
- { 6261, -3403, -264, 998 },
- { 7756, -4699, -1543, -834 },
- { 7682, -4622, -758, -1721 },
- { 8839, -4232, -2932, 1959 },
- { 9363, -4679, -1956, 39 },
- { 7883, -3616, -1414, -1432 },
- { 8828, -3188, -1356, -1312 },
- { 7746, -3987, -121, -2424 },
- { 9262, -3256, -693, 818 },
- { 7670, -3420, -148, 3504 },
- { 7344, -3183, 608, 1595 },
- { 8976, -4139, -1848, 1304 },
- { 6708, -4131, 33, -852 },
- { 7840, -4429, -2275, 79 },
- { 8980, -3858, -2838, 453 },
- { 7815, -4604, -2563, 944 },
- { 8372, -4422, -1783, 3071 },
- { 8623, -5128, -1754, 2888 },
- { 7462, -3281, 889, 920 },
- { 8416, -59, -1320, -1825 },
- { 7928, -1488, -414, -2499 },
- { 8110, -977, -1047, -2042 },
- { 8278, -687, -1597, -1550 },
- { 7988, -174, -977, -2106 },
- { 8609, -1547, -1628, -1527 },
- { 9000, -1798, -946, -1761 },
- { 8954, -872, -1404, -1594 },
- { 8939, 466, -748, -1212 },
- { 9549, -329, -177, -1360 },
- { 9411, -18, -1126, -1568 },
- { 8859, -782, -488, -1338 },
- { 8955, -218, -43, -1209 },
- { 9131, -69, -453, -1001 },
- { 9069, -1519, -1091, -1199 },
- { 9247, -1309, -566, -1146 },
- { 8528, -1617, -287, -1313 },
- { 7763, -745, -149, -2040 },
- { 8294, -343, 257, -2633 },
- { 10149, -893, -552, -1649 },
- { 9398, -915, 218, -2042 },
- { 9703, -1194, -675, -1592 },
- { 9586, -700, -427, -1710 },
- { 8930, 497, -1445, -1218 },
- { 9285, -1323, -163, -1552 },
- { 8431, -1289, -985, -1404 },
- { 8965, -655, 653, -1483 },
- { 9542, -1001, -951, -1128 },
- { 9205, -647, -37, -882 },
- { 8603, -56, 514, -1793 },
- { 9300, -12, -1324, -567 },
- { 8773, 238, -184, -1456 },
- { 9941, -1306, -69, -1792 },
- { 9360, 279, -376, -1919 },
- { 9180, -285, 95, -2170 },
- { 9922, -501, -970, -1570 },
- { 8341, -1493, -856, -2092 },
- { 8780, -981, -850, -1014 },
- { 9721, -548, -1504, -1094 },
- { 9973, -1493, 482, -2105 },
- { 8707, -333, -1027, -1087 },
- { 9098, -469, -315, -1723 },
- { 8879, -1050, -661, -2020 },
- { 8857, 602, -866, -1918 },
- { 8945, -1025, -2154, -1071 },
- { 8484, -1930, -468, -2179 },
- { 9177, -1903, -224, -2112 },
- { 8652, -137, -2097, -1214 },
- { 9063, -973, -1405, -772 },
- { 9328, -456, 662, -2469 },
- { 10101, -697, 127, -2113 },
- { 9685, 811, -2359, -1024 },
- { 8586, -94, -460, -1982 },
- { 7924, -141, -509, -2513 },
- { 7773, -669, -107, -2835 },
- { 8636, -1064, -46, -2409 },
- { 9748, 596, -1815, -1349 },
- { 8924, 304, 547, -2614 },
- { 9442, 746, -1153, -1679 },
- { 9454, -278, -529, -1976 },
- { 8488, 561, -32, -2160 },
- { 10083, -63, -1544, -1364 },
- { 9390, -1278, 568, -1131 },
- { 9740, -49, -2253, -910 },
- { 3636, -2391, -1115, -3614 },
- { 6014, -3204, -1902, -1808 },
- { 5787, -3497, -1116, -2590 },
- { 4365, -3046, -1632, -2668 },
- { 4733, -2192, -2029, -2468 },
- { 5412, -2753, -1633, -2464 },
- { 4455, -3375, -767, -3399 },
- { 4456, -1644, -983, -2841 },
- { 4039, -2523, 38, -3967 },
- { 3406, -2662, 72, -4757 },
- { 4279, -2005, 1055, -4399 },
- { 4321, -1377, -860, -3786 },
- { 3743, -5739, -651, -3047 },
- { 3528, -5510, 361, -4060 },
- { 6496, -4886, -136, -2689 },
- { 4513, -5254, 551, -4010 },
- { 6557, -3413, -92, -3063 },
- { 4186, -2059, 187, 47 },
- { 6210, -4117, -1256, -1985 },
- { 6038, -4343, 351, -2124 },
- { 4305, -4780, -2077, -1897 },
- { 4480, -3815, -2228, -1533 },
- { 5582, -3689, 1221, -3429 },
- { 5532, -4874, 1195, -2765 },
- { 6518, -2853, -905, -2568 },
- { 5467, -2192, 470, -4115 },
- { 4139, -1577, 240, -3493 },
- { 5281, -1926, -729, -3340 },
- { 5214, -2870, 1359, -4289 },
- { 3046, -3510, -1536, -3214 },
- { 5433, -2881, -1230, -1184 },
- { 4861, -3932, -1071, -2791 },
- { 5693, -4234, -1906, -1502 },
- { 4004, -3935, -1804, -2383 },
- { 3728, -3792, 681, -4773 },
- { 3621, -3030, -1951, -2598 },
- { 5133, -3903, 44, -3700 },
- { 3561, -3451, 1183, -5301 },
- { 5026, -2762, -2341, -1780 },
- { 5841, -2492, -467, -3210 },
- { 5591, -1791, 497, -2472 },
- { 5054, -3898, -1822, -2097 },
- { 5813, -2792, 83, -1469 },
- { 4432, -4497, 1670, -5193 },
- { 5338, -4653, -1109, -2200 },
- { 3239, -4401, -648, -3655 },
- { 2147, -3598, -1200, -4242 },
- { 4417, -2271, -1552, -3210 },
- { 6494, -4360, 852, -3565 },
- { 2393, -6358, -856, -4524 },
- { 4959, -4196, -847, -1403 },
- { 4924, -5438, -226, -3026 },
- { 4254, -5303, -1306, -2424 },
- { 4121, -3126, -2334, -1981 },
- { 3437, -4443, -1464, -2953 },
- { 3203, -3459, -529, -4339 },
- { 5896, -5945, 543, -3246 },
- { 1987, -4733, -220, -4863 },
- { 4358, -4431, -514, -3081 },
- { 4583, -2416, -492, -2287 },
- { 2943, -5035, 419, -4927 },
- { 5358, -5129, 987, -4309 },
- { 4460, -3392, 1752, -5634 },
- { 3415, -4633, 1507, -5945 },
- { 811, -4692, -445, 2333 },
- { 1009, -5613, -1857, 1360 },
- { 1338, -2712, -2720, 3036 },
- { 1002, -3754, -2582, 2344 },
- { 750, -4608, -2334, 714 },
- { 2043, -3207, -2822, 2173 },
- { -140, -4654, -2953, 357 },
- { -54, -4026, -2376, 2695 },
- { 1858, -5022, -717, 2287 },
- { 2064, -3894, -722, 3255 },
- { 2727, -4558, -332, 2603 },
- { 1810, -5378, 283, 1826 },
- { 3935, -4326, 762, 3383 },
- { -767, -4697, -2510, 1922 },
- { 2146, -4312, -3090, 1641 },
- { 54, -5881, -2114, 921 },
- { 1992, -5766, -640, 1574 },
- { 1200, -5371, -1114, 1828 },
- { 2973, -5337, 34, 2266 },
- { 1531, -5018, -2817, 1192 },
- { 3078, -4570, 117, 1990 },
- { 924, -4286, -1388, 2713 },
- { 142, -5058, -2848, 1487 },
- { -106, -6180, -881, 842 },
- { 673, -5433, -229, 1596 },
- { 783, -5710, -2784, 562 },
- { 1935, -5729, -2009, 856 },
- { -410, -3375, -3326, 2734 },
- { 234, -3000, -2628, 3260 },
- { 733, -3405, -3806, 1589 },
- { 771, -4285, -3544, 1314 },
- { 1192, -3563, -3960, 2178 },
- { 206, -5555, -1250, 1546 },
- { -130, -3815, -1210, 3041 },
- { 646, -3940, -393, 2992 },
- { -184, -4931, -1767, 1925 },
- { 2746, -5120, -2275, 1464 },
- { 2440, -3731, -3352, 2729 },
- { -490, -4942, -3779, 997 },
- { 68, -2636, -4167, 3778 },
- { 48, -3986, -4118, 2106 },
- { -978, -5486, -1336, 1390 },
- { 1126, -5297, -855, 640 },
- { -472, -3975, -3622, 1557 },
- { 2456, -5344, -1523, 1648 },
- { -774, -5652, -2417, 1147 },
- { 995, -6122, -812, 1132 },
- { 3282, -4571, -1763, 2175 },
- { 3655, -3862, -676, 3568 },
- { 3038, -3647, -1672, 3381 },
- { 2595, -2964, -2772, 3263 },
- { 4176, -3353, -1148, 4354 },
- { 1603, -3442, -1500, 3444 },
- { 828, -6226, -1783, 678 },
- { 1421, -3333, -3080, 3403 },
- { 1121, -4727, -1924, 1984 },
- { -186, -5083, -682, 1796 },
- { 819, -2778, -3488, 530 },
- { 421, -2873, -3832, 2596 },
- { 2164, -4263, -1605, 2282 },
- { 585, -4437, -682, -491 },
- { -644, -4452, -1157, 2325 },
- { 1991, -4299, 210, 2834 },
- { 2135, -3632, -2113, 665 },
- { -7482, -2724, -2662, -1380 },
- { -6983, -2166, -3756, -3509 },
- { -7085, -1439, -2397, -3112 },
- { -7760, -3049, -3319, -2822 },
- { -8413, -2760, -4406, -3298 },
- { -5995, -3943, -1260, -3750 },
- { -7879, -1554, -3464, -2606 },
- { -6314, -2034, -3878, -1681 },
- { -8849, -2084, -1399, -1231 },
- { -7153, -2602, -1384, -817 },
- { -8041, -2571, -407, -2785 },
- { -7246, -2233, -1578, 260 },
- { -7336, -3883, -4061, -1342 },
- { -7619, -3908, -2342, 382 },
- { -8684, -3724, -1662, -727 },
- { -7850, -2922, -1770, -3449 },
- { -6766, -2034, -1293, -1988 },
- { -6895, -2116, -968, -3744 },
- { -7136, -5147, -2618, -2809 },
- { -8224, -3724, -2519, -1589 },
- { -6711, -2750, -3021, -219 },
- { -8059, -1638, -1102, -3175 },
- { -8710, -4839, -3963, -3143 },
- { -9363, -4965, -3257, -1002 },
- { -6099, -1751, -3157, -395 },
- { -6453, -3216, -4597, -483 },
- { -7879, -5477, -839, -2638 },
- { -7202, -4038, -526, -2856 },
- { -8022, -1228, -1910, -1646 },
- { -9117, -1393, -1582, -2535 },
- { -9095, -2693, -636, -2605 },
- { -9076, -2580, -3481, -2519 },
- { -8327, -4859, -2422, 83 },
- { -8368, -2129, -2324, -2173 },
- { -8554, -4563, -3842, -2007 },
- { -10462, -4261, -1934, -2084 },
- { -9717, -3187, -2294, -1896 },
- { -9625, -3889, -3020, -3224 },
- { -9857, -4955, -4239, -2184 },
- { -9752, -2351, -2277, -3129 },
- { -7219, -1302, -2639, -1603 },
- { -7477, -4360, -3718, -559 },
- { -5680, -2033, -2326, -3078 },
- { -10190, -5548, -4643, -3601 },
- { -9431, -4121, -879, -2479 },
- { -8365, -5450, -2020, -1439 },
- { -6289, -5178, -1605, -3845 },
- { -8319, -3866, -687, -2792 },
- { -8131, -1031, -3608, -3947 },
- { -10510, -2560, -1199, -2082 },
- { -11015, -3640, -2748, -3041 },
- { -8762, -5022, -5231, -1162 },
- { -10153, -2715, -4648, -4859 },
- { -7930, -5205, -1900, -3600 },
- { -9561, -3548, -4812, -3722 },
- { -7663, -4709, -1180, -1475 },
- { -9073, -5707, -1815, -2980 },
- { -8602, -2363, -2675, -3770 },
- { -9967, -5614, -3575, -3838 },
- { -8324, -1005, -2131, -3254 },
- { -10331, -5737, -2550, -2940 },
- { -8234, -3354, -3361, -4479 },
- { -8140, -1951, -4526, -4545 },
- { -6679, -2662, -2284, -4182 },
- { -1122, -1514, -6427, -212 },
- { 54, -1660, -5424, -1404 },
- { 254, -2778, -5222, 846 },
- { -267, -1661, -6577, 814 },
- { -305, -2021, -5759, 1484 },
- { -1791, -2446, -6867, -86 },
- { -2929, -3158, -6603, -1799 },
- { -1391, -3189, -5557, -1053 },
- { -1602, -884, -6767, -1213 },
- { -361, -318, -6219, -44 },
- { -4078, -2635, -5523, -433 },
- { -956, 478, -4382, 1470 },
- { -3300, -2462, -6021, -2721 },
- { 708, -2434, -5085, -540 },
- { -2435, -3607, -5647, -2110 },
- { -491, -1134, -4681, -2886 },
- { 87, -3435, -4641, -1194 },
- { -586, -2927, -4784, 366 },
- { -1394, -2326, -6021, 350 },
- { 97, -2519, -4678, -2120 },
- { -1547, -1907, -5069, -2993 },
- { 268, -3724, -4719, 127 },
- { -827, -1190, -5912, 1144 },
- { -3959, -2322, -6898, -1974 },
- { -2728, -2228, -6426, -562 },
- { -456, -666, -5785, -1609 },
- { 531, -1096, -5731, -656 },
- { -3569, -688, -3915, 110 },
- { -4752, -1725, -4393, -377 },
- { -3210, -3315, -6960, -840 },
- { -688, -3416, -4971, 1221 },
- { -1833, 77, -6491, -2434 },
- { -239, -255, -6850, -886 },
- { -2112, -1490, -6291, -2689 },
- { -1544, -4579, -5198, -1261 },
- { -2771, -4014, -5520, 683 },
- { -1635, -2829, -5512, 1214 },
- { -958, -2582, -4823, 2360 },
- { -2077, -4566, -4642, 365 },
- { -3112, -4214, -5960, -823 },
- { -2467, -2510, -4858, 1467 },
- { -1561, -3399, -5822, 211 },
- { -775, -1081, -4424, 2636 },
- { -1263, 25, -6378, -1392 },
- { -3476, -366, -5417, -1393 },
- { -3176, -1476, -4149, 1466 },
- { -2479, 518, -4448, -257 },
- { -2992, 158, -4660, -1279 },
- { -1320, -3872, -4479, 1147 },
- { -1475, -312, -5318, 539 },
- { -3527, -1679, -5860, -1681 },
- { -3397, -3438, -5593, 1866 },
- { -4089, -2439, -4763, 1275 },
- { -748, -4513, -4687, -48 },
- { -2166, -4531, -4691, -2856 },
- { -2385, -853, -6035, -627 },
- { -1194, -4091, -4472, -1963 },
- { -682, -3234, -4084, -3033 },
- { -3255, -5015, -5328, -12 },
- { -2313, -3436, -4601, -155 },
- { -2792, -1038, -6947, -2019 },
- { -1244, -1526, -5771, -1882 },
- { -4679, -3731, -5506, 283 },
- { -3062, -66, -3558, -758 },
- { -4895, -1187, 4751, 3728 },
- { -7600, -2752, 3320, 4613 },
- { -5703, -2975, 3944, 2659 },
- { -4972, -1257, -246, 2952 },
- { -4221, -2487, 1702, 4295 },
- { -2900, -1529, 2458, 4935 },
- { -5061, 407, 2416, 4050 },
- { -6931, -3478, 2761, 2213 },
- { -6037, -3921, 3192, 1866 },
- { -6113, -811, 2407, 3782 },
- { -5878, -1716, 1207, 3478 },
- { -5953, -2853, 2207, 2712 },
- { -6807, -3223, 2749, 3595 },
- { -3272, -3157, 1389, 3788 },
- { -5368, -1904, 1980, 5077 },
- { -7235, -1398, 3075, 4548 },
- { -4765, -3487, 2755, 2796 },
- { -7658, -4435, 2694, 2582 },
- { -6997, -4282, 456, 3832 },
- { -5563, -3115, -63, 3713 },
- { -4244, -4220, 1450, 2767 },
- { -3801, -2194, 190, 4303 },
- { -5458, -4119, 1958, 2274 },
- { -7300, -3469, 3514, 3193 },
- { -4594, -2067, 775, 4752 },
- { -3389, -1654, 1464, 5412 },
- { -4845, -3483, 964, 3437 },
- { -6007, -2818, 1666, 4659 },
- { -8709, -5007, 1757, 3287 },
- { -5833, -4389, 1025, 3171 },
- { -5788, -1780, 3944, 3661 },
- { -4430, -920, 1938, 4753 },
- { -7066, -1857, 4591, 4538 },
- { -3549, -513, 1427, 5317 },
- { -7517, -1220, 2883, 3049 },
- { -7605, -2687, 1874, 2735 },
- { -8718, -4035, 2676, 3730 },
- { -7990, -3907, 1185, 2607 },
- { -6058, -1744, 3349, 5157 },
- { -5954, 565, 3161, 3250 },
- { -6478, -612, 1930, 2271 },
- { -6535, -1445, -2, 1618 },
- { -8963, -4151, 1192, 4044 },
- { -7227, -3570, 1600, 4234 },
- { -4674, 79, 595, 3015 },
- { -3974, 430, 2727, 5137 },
- { -5299, 9, 3714, 4779 },
- { -6779, -2699, -8, 2436 },
- { -7016, -1145, 1293, 2310 },
- { -6955, -3312, 1534, 1801 },
- { -4025, 740, 1850, 4054 },
- { -9589, -3460, 4154, 5270 },
- { -4404, -1181, 4298, 5173 },
- { -7356, -4583, -18, 2644 },
- { -6516, -1235, 4439, 6234 },
- { -3453, -301, 4344, 4464 },
- { -4643, 1530, 3315, 4340 },
- { -4575, -2557, 3754, 3682 },
- { -3643, -3501, 2051, 2997 },
- { -5412, -2475, 2301, 1579 },
- { -5846, 259, 1360, 2348 },
- { -5258, -1358, 1050, 838 },
- { -5542, -219, 6377, 5750 },
- { -5713, -2952, 922, 899 },
- { -2049, -1135, 5206, 1033 },
- { -1693, -1886, 4835, -106 },
- { -2344, -3504, 4232, -13 },
- { -2475, -2334, 5043, 1126 },
- { -787, -2549, 3880, 2138 },
- { -3159, -2341, 4830, 2887 },
- { -1780, -1009, 6240, 2061 },
- { -4327, -3363, 2818, 886 },
- { -3376, -2743, 4104, 207 },
- { -3250, -4640, 2718, 1498 },
- { -382, -1075, 4382, 3460 },
- { -2416, -4168, 3530, 816 },
- { -1756, -2708, 4861, 622 },
- { -1879, -2097, 5156, 2889 },
- { -2496, -2418, 3722, 2671 },
- { -2717, -3252, 3341, 1944 },
- { -4063, -4091, 3306, 267 },
- { -3549, -3808, 3747, 842 },
- { -2635, 546, 5794, 1894 },
- { -1857, -1121, 4383, 3964 },
- { -2226, -2166, 3489, 3678 },
- { -3492, -660, 5323, 1063 },
- { -3033, -3130, 4382, 1828 },
- { -2703, -625, 6369, 2851 },
- { -1656, -2842, 4584, -528 },
- { -4781, -2622, 4390, 2097 },
- { -413, -2045, 5081, 3035 },
- { -3810, -2662, 4532, 1095 },
- { -3144, -1858, 5215, 1880 },
- { -3562, -1795, 4928, 670 },
- { -4800, -1509, 5189, 1859 },
- { -1085, -3832, 4169, 900 },
- { -1969, -3270, 2857, 2878 },
- { -4267, -4140, 3176, 1805 },
- { -5145, -3727, 3524, 1168 },
- { -1346, -1876, 5501, 1748 },
- { -4998, -2945, 3699, 338 },
- { -3458, -3096, 3406, -635 },
- { -1751, -3209, 3508, 395 },
- { -2507, 170, 5987, 705 },
- { -3756, -1072, 5647, 3536 },
- { -2870, -1439, 5026, 3212 },
- { -3913, -3225, 3669, 2144 },
- { -3739, 226, 5747, 764 },
- { -2052, -820, 5266, 3093 },
- { -3214, -3820, 2409, 2391 },
- { -4398, -2588, 3501, -218 },
- { -4484, -1763, 4180, -198 },
- { -3368, -1525, 4362, -134 },
- { -2407, 224, 4905, 3533 },
- { -1369, -2937, 4728, 1788 },
- { -4848, -1707, 4159, 851 },
- { -3454, -1749, 4281, 3230 },
- { -1990, -3853, 3487, 1735 },
- { -3117, 92, 6155, 4075 },
- { -2676, -2472, 4078, -589 },
- { -1547, -2012, 2626, 1835 },
- { -4275, -588, 4824, 725 },
- { -601, -2249, 3736, 3548 },
- { -4060, -61, 5333, 3097 },
- { -4303, 7, 6551, 3054 },
- { -5003, -1029, 5786, 3319 },
- { -2810, -728, 5392, 199 },
- { -1232, -200, 5228, 3121 },
- { 2621, 165, -6255, 298 },
- { 3669, 537, -6844, 1564 },
- { 1598, -1190, -6235, 2523 },
- { 2164, -32, -6894, 1383 },
- { 853, -1597, -6069, 1449 },
- { 1377, -1661, -5266, 108 },
- { 2660, 48, -5172, -517 },
- { 1903, -391, -5677, 1010 },
- { 3792, 206, -5274, -11 },
- { 1239, 2776, -2929, 2721 },
- { 4071, 149, -7259, 3125 },
- { 1436, -480, -6156, -196 },
- { 1373, -1960, -5005, 3122 },
- { 3413, -1271, -5176, 3283 },
- { 3060, -68, -6495, 2238 },
- { 2700, -2075, -4681, 91 },
- { 2928, -1728, -5168, 1858 },
- { 4424, 828, -4471, 88 },
- { 2672, -2604, -4038, 2753 },
- { 5223, -123, -6749, 2295 },
- { 4237, -420, -5538, 1353 },
- { 4744, -1281, -4097, 4708 },
- { 1103, -2764, -4751, 2024 },
- { 3747, -1913, -3911, 3960 },
- { 2470, -1416, -5542, 615 },
- { 4847, -1354, -5334, 1733 },
- { 5336, 88, -7593, 4007 },
- { 2388, -2880, -4807, 1037 },
- { 4495, 1391, -5685, -139 },
- { 5253, 1637, -6450, 1533 },
- { 1199, 795, -5515, 1261 },
- { 1397, -1259, -4252, 3838 },
- { 746, 70, -6640, 604 },
- { 1584, 166, -4972, 3072 },
- { 380, -999, -5397, 2267 },
- { 2974, 1707, -3242, 5360 },
- { 5202, -403, -5453, 2832 },
- { 3718, -1731, -4760, 714 },
- { 4150, -975, -4792, 61 },
- { 2925, -818, -4841, 15 },
- { 5301, 577, -4006, 3259 },
- { 5265, 1986, -5679, 3028 },
- { 3752, 1928, -4509, 3729 },
- { 3278, 1925, -6370, 1247 },
- { 5107, 1721, -4853, 3127 },
- { 3279, 2982, -2515, 4005 },
- { 4622, 668, -6204, 759 },
- { 6034, 317, -5763, 4818 },
- { -558, 57, -3785, 2817 },
- { 4476, 1616, -3965, 4536 },
- { 5953, 2056, -8215, 2715 },
- { 4387, 2613, -7463, 868 },
- { 5834, 1088, -4736, 4924 },
- { 6473, -856, -6991, 4172 },
- { 4959, -293, -5162, 76 },
- { 2731, -843, -6119, 3847 },
- { 3245, 1202, -6833, 616 },
- { 2553, 1383, -3829, 3859 },
- { 4332, 2099, -3480, 3622 },
- { 2110, 2683, -2728, 3990 },
- { 876, 1167, -3290, 3466 },
- { 3991, 1709, -2410, 4077 },
- { 5105, 939, -2584, 3256 },
- { 4719, 688, -1566, 3040 },
- { -3632, 4335, 1266, -3303 },
- { -4956, 3207, 1312, -2806 },
- { -4669, 2627, 2663, -2435 },
- { -4282, 3708, 2303, -3038 },
- { -4536, 2297, -175, -3350 },
- { -5234, 2503, -139, -880 },
- { -3978, 1512, 1092, -3619 },
- { -4519, 4649, 1363, -2455 },
- { -5118, 3132, 1961, -1577 },
- { -5196, 3379, -182, -1378 },
- { -6420, 4486, 2397, -1993 },
- { -5030, 5046, 1292, -1118 },
- { -4559, 2573, -927, -1406 },
- { -3501, 3730, 691, -4930 },
- { -4364, 2758, 1007, -3909 },
- { -4026, 2839, -1559, -2340 },
- { -5037, 4053, 836, -1571 },
- { -4727, 5136, 1110, -3588 },
- { -5245, 2799, -999, -2164 },
- { -4954, 1501, 422, -3963 },
- { -5994, 2726, 1462, -2833 },
- { -5621, 5159, 2038, -2512 },
- { -4991, 2291, 1917, -3151 },
- { -5469, 4382, -148, -2978 },
- { -5858, 1983, 807, -2720 },
- { -4709, 3556, 952, -467 },
- { -2489, 2362, 1714, -4230 },
- { -4717, 5004, -1180, -3672 },
- { -5914, 3653, 1359, -1317 },
- { -5506, 2995, 780, -1059 },
- { -5287, 3945, 2480, -2293 },
- { -3849, 4358, 322, -1770 },
- { -3911, 3570, 252, -3185 },
- { -3660, 5128, 158, -3719 },
- { -4599, 3277, -503, -2727 },
- { -3673, 3760, -1252, -3339 },
- { -5161, 2337, 388, -1943 },
- { -3529, 2216, 2156, -3080 },
- { -4309, 4331, 1808, -1460 },
- { -4782, 3820, 480, -2504 },
- { -4166, 3544, -378, -1567 },
- { -5572, 2466, -418, -2909 },
- { -6096, 2930, 119, -1878 },
- { -5963, 3554, 1011, -2233 },
- { -6433, 4335, 935, -2930 },
- { -5004, 3314, -1352, -3430 },
- { -6042, 3463, -1008, -3940 },
- { -4671, 2214, -640, -5040 },
- { -2795, 3759, 1412, -3803 },
- { -3647, 4436, 729, -515 },
- { -3594, 1033, 56, -4148 },
- { -2908, 3027, 2889, -3485 },
- { -3338, 2234, 313, -4285 },
- { -3825, 4497, -561, -2634 },
- { -6167, 3012, -48, -3149 },
- { -4828, 3515, -969, -4475 },
- { -5789, 2757, -539, -4173 },
- { -2452, 3067, 564, -4249 },
- { -4921, 1358, 1331, -2889 },
- { -3127, 4239, -1045, -1523 },
- { -4780, 2326, -1118, -3446 },
- { -3908, 5546, 152, -2622 },
- { -6972, 2976, 337, -2809 },
- { -4839, 4613, -35, -4077 },
- { -1408, 4822, -1149, -4997 },
- { -981, 4979, -912, -6304 },
- { -2098, 5689, -888, -2878 },
- { -3343, 4814, -657, -4434 },
- { -2461, 3601, -967, -4869 },
- { -2652, 3944, 87, -5520 },
- { -1104, 6076, 174, -6407 },
- { 355, 5370, -1721, -5869 },
- { 1242, 4497, -1107, -5091 },
- { -89, 4002, -1491, -5182 },
- { 1059, 5693, -1591, -4905 },
- { 1323, 4682, -2078, -4768 },
- { 818, 3996, -549, -5468 },
- { -287, 4529, 929, -5543 },
- { -919, 5519, -2791, -2844 },
- { -1407, 5679, -3289, -3974 },
- { -189, 6530, -3547, -4002 },
- { -900, 7039, -3371, -4855 },
- { -2983, 7211, -363, -4835 },
- { -814, 6503, -104, -5106 },
- { -2386, 6896, 809, -4919 },
- { 845, 4492, 352, -6621 },
- { -1998, 7237, -1646, -4231 },
- { -3380, 6251, 471, -4577 },
- { -1908, 7059, 84, -5726 },
- { -340, 6346, -803, -6265 },
- { -2279, 5834, -47, -4633 },
- { -1532, 5286, -1748, -1901 },
- { -2757, 6188, -453, -3415 },
- { -1255, 6405, -2043, -6357 },
- { 918, 5581, -121, -5667 },
- { 1840, 5336, -821, -5034 },
- { -2475, 4992, -1825, -3104 },
- { -2413, 5606, -1789, -4298 },
- { 132, 5128, -2389, -4442 },
- { 223, 6400, -2653, -4742 },
- { -673, 5012, 680, -4582 },
- { -1657, 6624, -349, -3596 },
- { -755, 6289, -1860, -3978 },
- { -572, 6894, -1946, -5207 },
- { -1141, 4756, -2665, -5586 },
- { -1073, 4269, -431, -4030 },
- { 186, 5761, 916, -5868 },
- { -1907, 4836, 1017, -5106 },
- { -963, 3363, -1248, -6348 },
- { -3262, 4774, -1818, -5858 },
- { 847, 3812, -2538, -4302 },
- { -1223, 5903, 1360, -5479 },
- { -1094, 6923, -1244, -2381 },
- { 267, 6276, -709, -2846 },
- { -157, 5840, 1124, -4266 },
- { 889, 3206, -910, -5305 },
- { -1736, 3344, 582, -4838 },
- { -2357, 5676, -2695, -6277 },
- { -1916, 6901, -986, -5397 },
- { -3062, 6028, -695, -5687 },
- { 1836, 3566, -1357, -5226 },
- { -2176, 4938, 646, -3872 },
- { -2199, 3055, -208, -6124 },
- { -236, 3032, -821, -5325 },
- { -3989, 7277, -565, -3899 },
- { -595, 4362, 74, -5975 },
- { 684, 5874, -841, -4424 },
- { -2731, 6305, -2389, -5465 },
- { -5775, 1325, -56, -2528 },
- { -7029, -534, -1890, -3278 },
- { -5798, -15, -2734, -2210 },
- { -5504, -1198, -353, -3659 },
- { -5079, 960, -894, -4336 },
- { -6073, -36, -133, -3014 },
- { -5782, -259, -1025, -3986 },
- { -6843, 1262, -807, -1639 },
- { -5263, -918, -3290, -579 },
- { -4840, 461, -2158, -533 },
- { -6014, -50, -620, 504 },
- { -5843, 241, -1359, -282 },
- { -5898, 577, 769, -3271 },
- { -6833, -946, -466, -3347 },
- { -6026, 1459, -512, -729 },
- { -7361, 747, -388, -1110 },
- { -6391, 2142, -1160, -2513 },
- { -6995, 304, 498, -2673 },
- { -6757, 679, -386, -433 },
- { -5222, 1688, -1093, -1032 },
- { -5019, 575, 184, -3627 },
- { -4237, 628, -3507, -1243 },
- { -7479, -456, -1722, -1486 },
- { -6464, 713, -1273, -1153 },
- { -6255, 1682, -606, -3607 },
- { -7033, 1497, -71, -1955 },
- { -6694, 1556, -1721, -3214 },
- { -6114, -356, 813, -2575 },
- { -5308, 632, -1851, -1636 },
- { -5742, -911, -1733, 383 },
- { -6083, -387, -2313, -879 },
- { -6535, -530, -1505, -2083 },
- { -4896, 1223, -2750, -1816 },
- { -6392, -463, -3247, -2093 },
- { -5373, 1264, -2706, -3042 },
- { -3894, -1390, -1020, -891 },
- { -6179, 1168, -1966, -1922 },
- { -5162, 1668, -1617, -1916 },
- { -6453, 920, -1169, -2432 },
- { -6130, 2005, -536, -1519 },
- { -6552, -98, -518, -1938 },
- { -7528, 355, -1101, -1772 },
- { -5745, 610, -247, -1360 },
- { -7003, 177, -2064, -1958 },
- { -6956, -570, -2220, -4225 },
- { -7830, 791, -1394, -2774 },
- { -7634, 480, -3171, -4224 },
- { -7913, 1154, -350, -2381 },
- { -5063, 1704, -1804, -2977 },
- { -4887, -524, -2703, 188 },
- { -5551, 406, -1620, -3063 },
- { -7109, 1342, 381, -3021 },
- { -6846, 631, -458, -3398 },
- { -4606, -605, 11, -3930 },
- { -8134, -225, -1738, -2648 },
- { -7043, 402, -2734, -3059 },
- { -7417, 1825, -2545, -4389 },
- { -6971, -236, -1031, -665 },
- { -5752, 2111, -1632, -3808 },
- { -7660, -78, -624, -3135 },
- { -6358, 619, -1951, -3911 },
- { -8134, 408, -1935, -3695 },
- { -6335, 1911, -2368, -4505 },
- { -7116, 2163, -344, -2753 },
- { 2357, 4488, 2220, -5682 },
- { 1385, 3206, 2300, -5305 },
- { 1419, 2557, 5203, -3516 },
- { 262, 4315, 3920, -1847 },
- { 3316, 3187, 1612, -5609 },
- { 1729, 2350, 1673, -6068 },
- { 1603, 6126, 1467, -2839 },
- { -1339, 3316, 3691, -3530 },
- { -563, 4618, 3180, -4548 },
- { 463, 4624, 3111, -5614 },
- { 1246, 5455, 3356, -5720 },
- { 480, 2149, 5422, -2893 },
- { 1768, 4827, 913, -5579 },
- { -149, 5381, 4366, -3297 },
- { 985, 3672, 2644, -92 },
- { -258, 2911, 5817, -2213 },
- { 3428, 3289, 3351, -3541 },
- { -666, 3295, 4727, -2869 },
- { 35, 6641, 4160, -4052 },
- { 623, 6787, 3156, -4560 },
- { 2654, 4360, 4676, -4632 },
- { 1386, 5246, 4834, -4497 },
- { 3488, 4574, 3856, -5946 },
- { 383, 4481, 4168, -4110 },
- { 1753, 3652, 4288, -3326 },
- { 1344, 4905, 2508, -4660 },
- { 1580, 4106, 3104, -2224 },
- { 2027, 5038, 1683, -1554 },
- { 446, 3699, 5872, -3013 },
- { 4637, 4087, 3578, -5018 },
- { 2629, 3560, 5331, -4900 },
- { 1527, 6674, 2523, -4131 },
- { -1437, 2804, 2528, -4464 },
- { -229, 3355, 2016, -5537 },
- { 3666, 3418, 4374, -4581 },
- { 1192, 3799, 923, -6596 },
- { 2040, 2956, 448, -5322 },
- { 2468, 5768, 4029, -5869 },
- { 3438, 6516, 3529, -6667 },
- { 2737, 5495, 680, -5535 },
- { 3896, 5727, 1801, -4958 },
- { 4988, 4957, 3592, -6518 },
- { -542, 4416, 5794, -2787 },
- { 4136, 4354, 2064, -4696 },
- { 3067, 5936, 1207, -3396 },
- { 2789, 4966, 2405, -3854 },
- { 1731, 3270, 3251, -1063 },
- { 1767, 5537, 2084, -2349 },
- { 465, 3116, 4532, -837 },
- { 1499, 2627, 4610, -2212 },
- { 122, 3095, 3642, -3552 },
- { 2542, 2866, 2705, -6402 },
- { 3134, 4323, 698, -4785 },
- { 731, 1859, 3112, -5242 },
- { 2553, 2980, 3241, -4846 },
- { 1329, 5310, 1607, -6624 },
- { 2468, 1858, 3476, -1034 },
- { -172, 4996, 2000, -5562 },
- { 2621, 4220, 1574, -3386 },
- { -333, 1832, 3362, -4117 },
- { 2169, 6762, 3065, -6225 },
- { 2844, 5528, 3223, -4765 },
- { 526, 5175, 1644, -4267 },
- { 2922, 4426, 2414, -2610 },
- { 452, 1399, -4516, -2636 },
- { 2872, 1720, -4667, -1435 },
- { 1279, 702, -5424, -1984 },
- { 2187, 870, -5021, -1341 },
- { 583, -144, -4628, -2464 },
- { 3, 2237, -5284, -2827 },
- { -19, 1005, -5460, -1819 },
- { 2897, 2084, -5885, -515 },
- { -400, 3370, -5527, -2947 },
- { 1505, 2593, -5518, -1802 },
- { 1341, 4534, -5094, -1899 },
- { 3241, 3670, -5493, -1252 },
- { -1287, 921, -5994, -1675 },
- { 627, 408, -6652, -364 },
- { -260, 1127, -4849, -3247 },
- { 371, 3400, -5976, -2285 },
- { 1533, 1566, -6373, -610 },
- { 2462, 4274, -6184, -1254 },
- { 1782, 3363, -6222, -1381 },
- { 572, 4650, -5673, -2754 },
- { 2674, 3414, -4460, -2154 },
- { 3614, 3820, -6883, -398 },
- { 1136, -1, -5511, -1112 },
- { -1773, 1137, -5647, -2377 },
- { -753, 2104, -6085, -2565 },
- { -204, 3025, -4731, -1418 },
- { -1486, 1438, -4380, -216 },
- { 302, 858, -5786, -264 },
- { 3486, 1495, -5234, -783 },
- { 888, 2327, -3423, -3720 },
- { -259, 772, -6596, -1311 },
- { -1197, 2073, -5174, -1826 },
- { 1500, 3470, -4462, -2645 },
- { 3072, 1960, -3277, -2264 },
- { 1841, 952, -4324, -2340 },
- { 1994, 2200, -3940, -2923 },
- { -1782, 1699, -4667, -1075 },
- { -1464, 2906, -3468, -375 },
- { 366, 2380, -3747, 1467 },
- { -545, 1645, -4619, 376 },
- { 1724, 2350, -2374, -3512 },
- { 3184, 2628, -2996, -3275 },
- { 734, 2010, -6239, -1479 },
- { 524, 3756, -4496, -3263 },
- { 1492, 3570, -3494, -3600 },
- { -932, 618, -5389, -2894 },
- { -133, 2161, -4083, -3267 },
- { 786, 774, -3279, -3731 },
- { 1078, 803, -3843, -3007 },
- { -332, 3405, -3347, 40 },
- { -17, 6, -4005, -3690 },
- { -189, 4372, -4488, -2561 },
- { -450, 3846, -3790, -1370 },
- { 362, 2212, -5272, -15 },
- { -1529, 791, -6802, -2296 },
- { 2145, 4241, -4474, 376 },
- { 1813, 2426, -2932, -2726 },
- { -542, 4557, -3140, -1080 },
- { 1192, 3784, -4371, -20 },
- { 2784, 5188, -6399, -1394 },
- { 431, 4561, -3673, -1398 },
- { 1382, 3096, -4083, 1253 },
- { 1209, 4224, -2930, 1500 },
- { 2798, 2684, -6676, -606 },
- { -2396, 1510, -5381, -2713 },
- { -2625, 2542, -4032, -2880 },
- { -1231, 3967, -4098, -2886 },
- { -1393, 2374, -3862, -4525 },
- { -2495, 1665, -1637, -5445 },
- { -3854, 1759, -1750, -4944 },
- { -2373, 1668, -2856, -6251 },
- { -2668, 1981, -886, -4557 },
- { -2927, 4427, -3451, -6172 },
- { -1925, 2596, -4696, -2527 },
- { -3202, 2847, -3928, -5896 },
- { -3332, 1665, -5025, -3412 },
- { -3212, 3115, -4155, -4062 },
- { -1013, 3205, -5133, -3751 },
- { -2022, 4595, -3947, -5611 },
- { -3556, 1755, -3715, -2300 },
- { -1784, 4114, -2723, -1773 },
- { -3586, 4081, -2733, -4942 },
- { -1608, 3685, -4154, -4573 },
- { -3368, 4042, -4452, -6227 },
- { -1407, 3881, -5729, -3719 },
- { -2751, 3281, -5077, -4999 },
- { -3791, 2410, -4906, -5288 },
- { -730, 2303, -4217, -3755 },
- { -1812, 2311, -5492, -3709 },
- { -610, 4336, -3915, -3783 },
- { -2841, 4337, -4278, -4430 },
- { -1662, 4666, -4661, -3964 },
- { -589, 5209, -4923, -3682 },
- { -4155, 2234, -4076, -4218 },
- { -3951, 2770, -2665, -2805 },
- { -2302, 3228, -3717, -1908 },
- { -3129, 4373, -2264, -2851 },
- { -447, 1363, -3578, -4323 },
- { -2648, 4237, -3159, -3071 },
- { -4072, 3241, -3541, -4605 },
- { -4507, 3458, -2339, -3838 },
- { -1646, 997, -4926, -3970 },
- { -3025, 1614, -3940, -1242 },
- { -1337, 1756, -3163, -5529 },
- { -3203, 1865, -3282, -4354 },
- { -1646, 2118, -2203, -6018 },
- { 174, 1871, -2707, -4639 },
- { -2607, 1485, -4778, -4750 },
- { -2199, 3991, -3134, -4879 },
- { -2962, 3323, -2816, -2419 },
- { -5286, 2495, -4548, -5395 },
- { -2810, 3710, -2274, -4211 },
- { -330, 3006, -2993, -4678 },
- { -1187, 2411, -2743, -5196 },
- { -664, 4033, -3101, -5641 },
- { -1458, 3602, -2816, -5371 },
- { -4116, 4923, -3321, -5630 },
- { -4165, 2528, -2592, -4798 },
- { -2759, 3080, -2333, -5719 },
- { -5157, 3011, -5526, -6348 },
- { -3095, 2126, -5881, -4234 },
- { -4377, 3849, -3600, -6099 },
- { -1994, 4947, -5235, -4753 },
- { -1067, 600, -3258, -5133 },
- { -4992, 3302, -2208, -5051 },
- { -3377, 2981, -1655, -4815 },
- { -3325, 2446, -1787, -6116 },
- { -2341, 2737, -3240, -6347 },
- { -2258, -3732, 3710, -1235 },
- { -1558, -3849, 2694, -3012 },
- { -599, -4837, 3050, -2951 },
- { -2246, -5433, 2798, -1910 },
- { -2255, -4989, 3260, 270 },
- { -3026, -5353, 2693, -1036 },
- { -1151, -6097, 1097, -3782 },
- { -3391, -6012, 2130, -1303 },
- { -2850, -4422, 3375, -480 },
- { -1138, -3779, 1491, -4162 },
- { -551, -3892, 3787, -2082 },
- { -3221, -3676, 3144, -1202 },
- { -3023, -5196, 2650, 605 },
- { -1756, -5729, 2646, 321 },
- { -2693, -4409, 494, -4797 },
- { -1913, -4573, 3372, -1730 },
- { -1277, -3604, 4061, -993 },
- { -420, -4993, 1351, -4796 },
- { -3052, -5333, 1435, -1242 },
- { -602, -5034, 3869, -1141 },
- { -2436, -4680, 1665, -3019 },
- { -2657, -3658, 1459, -3391 },
- { -1220, -6246, 2749, -525 },
- { -3838, -4844, 2265, -1735 },
- { -1247, -5679, 3356, -1417 },
- { -917, -5448, 3342, 105 },
- { -1756, -6839, 2276, -2350 },
- { -412, -5206, 1764, -3539 },
- { -1439, -6915, 1442, -3750 },
- { -1381, -4439, 3863, -282 },
- { -3482, -4953, 2726, -336 },
- { -1376, -5931, 1714, -1987 },
- { -1716, -4405, 2608, 105 },
- { -1590, -5191, 2652, -2704 },
- { -2149, -6442, 2453, -1263 },
- { -3426, -3832, 2334, -1829 },
- { -2747, -5948, 2362, -173 },
- { -2435, -3267, 2966, -1710 },
- { -3979, -4282, 2705, -775 },
- { -356, -4238, 2544, -4343 },
- { -1363, -6471, 2817, -1836 },
- { -2878, -5117, 218, -3149 },
- { -3539, -5196, 1710, -2356 },
- { -2888, -4537, 2746, -1701 },
- { -1870, -4439, 1496, -4121 },
- { -1486, -3388, 3349, -2145 },
- { -3333, -4138, 1467, -2876 },
- { -345, -5340, 1012, -1190 },
- { -1672, -4992, 2289, -1029 },
- { -2146, -5528, 3038, -635 },
- { -316, -3656, 3426, -3152 },
- { -2695, -5812, 2336, -2050 },
- { -2067, -6052, 737, -3258 },
- { -2664, -4205, -350, -1266 },
- { -617, -5406, 80, -4853 },
- { -2418, -3825, 1853, -1326 },
- { -1961, -4339, 583, -4315 },
- { -1495, -5141, -133, -5205 },
- { -3208, -6440, 1691, -2069 },
- { -2632, -3633, 2325, -2761 },
- { -2624, -5670, 1252, -3676 },
- { -3687, -5608, 687, -2833 },
- { -3320, -5707, 16, -3877 },
- { -2738, -6112, 84, -5135 },
- { 2277, -5661, 3076, 843 },
- { 1555, -5769, 2821, -5236 },
- { 536, -6381, 603, -4910 },
- { 734, -4609, 3314, -4092 },
- { 1836, -4547, 3267, -4322 },
- { -13, -5976, 3752, -1607 },
- { 1423, -6318, 2336, 398 },
- { 365, -7779, 1498, -534 },
- { 2104, -8366, 2946, -1345 },
- { 143, -5545, 1898, -3756 },
- { 655, -6852, 1430, 148 },
- { 4, -6653, 2397, -59 },
- { 2346, -5996, 4562, -934 },
- { 1229, -7104, 2963, -598 },
- { -528, -7048, 2887, -1790 },
- { 1451, -6857, 3900, -1637 },
- { 554, -6018, 3336, 9 },
- { 3278, -5758, 4034, 129 },
- { 3541, -7145, 4905, -1575 },
- { 2339, -6907, 3464, -301 },
- { 2775, -7301, 1667, -3894 },
- { 539, -7887, 991, -4156 },
- { 2115, -7421, 3131, -3075 },
- { 2803, -8546, 2564, -5836 },
- { 2869, -5833, 1620, -4561 },
- { 2591, -7281, 3215, -4719 },
- { -1228, -8477, 706, -4782 },
- { 1967, -5243, 4813, -1940 },
- { 701, -7010, 2273, -3893 },
- { 915, -8470, 1918, -5620 },
- { -94, -6715, 156, -3873 },
- { 1074, -5607, 4389, -1017 },
- { 2739, -6551, 1227, -3521 },
- { 725, -7835, 2701, -1291 },
- { -493, -7475, 2263, -1075 },
- { -412, -6508, 2984, -744 },
- { 665, -5451, 3725, -2692 },
- { 1499, -8129, 3564, -2072 },
- { 2870, -6333, 4487, -2108 },
- { 706, -5007, 3911, -152 },
- { -482, -8660, 1483, -2900 },
- { 2481, -6596, 2518, -1715 },
- { 1403, -6414, 1398, -5387 },
- { 652, -6267, 583, -5942 },
- { 694, -7540, 646, -6272 },
- { 2275, -7614, 256, -5015 },
- { 1416, -9727, 1900, -3153 },
- { 2760, -6433, 3875, -3771 },
- { 2325, -11196, 2182, -5155 },
- { 1223, -11061, 1377, -5097 },
- { 108, -10603, 307, -4952 },
- { -118, -8268, 1650, -1572 },
- { 1839, -7943, 1755, -612 },
- { 2501, -9056, 981, -2969 },
- { 2902, -8476, 1491, -5780 },
- { 1995, -11175, 1585, -3643 },
- { 696, -8212, 828, -2474 },
- { 1526, -8649, 1380, -1210 },
- { 461, -7253, 3222, -2229 },
- { 2966, -8641, 4121, -3271 },
- { 833, -6039, 2361, -1086 },
- { 3565, -7312, 1980, -5427 },
- { 2850, -8671, 3760, -1846 },
- { 2643, -7281, 2163, -173 },
- { 3463, -3706, -3132, -923 },
- { 1315, -3825, -3443, 2 },
- { 2594, -4083, -3815, 670 },
- { 1826, -4291, -2741, -155 },
- { 868, -3749, -4175, -298 },
- { 2008, -4237, -3897, -517 },
- { 1242, -3493, -4335, -1335 },
- { -88, -4142, -3390, -1529 },
- { 2176, -3488, -3822, -975 },
- { 1706, -5188, -3415, -637 },
- { 2717, -6159, -2333, -882 },
- { 1276, -3978, -4361, 537 },
- { 2471, -5556, -2866, -208 },
- { 799, -4673, -4086, 56 },
- { 1901, -4786, -3533, 270 },
- { 3036, -3902, -3606, -333 },
- { 2249, -3317, -4319, -144 },
- { 2594, -4207, -2105, -2930 },
- { 4008, -4774, -2626, -902 },
- { 1038, -3659, -3496, -2454 },
- { 2725, -3597, -3298, -1535 },
- { 1662, -5803, -2813, 175 },
- { 705, -3757, -3441, -1484 },
- { 1860, -5987, -2821, -886 },
- { 3786, -4918, -2199, -1929 },
- { 3683, -4235, -2547, -1287 },
- { 2531, -4896, -2956, -1593 },
- { 1005, -5585, -3324, -180 },
- { 1625, -5229, -1756, -3642 },
- { 1494, -5041, -2989, -2685 },
- { 2718, -4655, -3224, -867 },
- { 2374, -6640, -1745, -2975 },
- { 2133, -6436, -2477, -1499 },
- { 1833, -4418, -3523, -1512 },
- { 1128, -4910, -2658, -1106 },
- { 689, -4777, -2831, -2085 },
- { 3593, -5280, -2627, -315 },
- { 3264, -3771, -2673, -1861 },
- { 3202, -5602, -2409, 402 },
- { 552, -4618, -2221, -3002 },
- { 3095, -5356, -2666, -1083 },
- { 3401, -4609, -3146, 45 },
- { 3051, -4662, -2192, -2232 },
- { 2798, -5552, -2462, -1941 },
- { 2354, -5815, -2223, -2619 },
- { 192, -3708, -2807, -2658 },
- { 1886, -4226, -1862, -3529 },
- { 2526, -3976, -2819, -2332 },
- { 1577, -3870, -2711, -2806 },
- { 1288, -5588, -3382, -1403 },
- { 2711, -5399, -1564, -3253 },
- { 1459, -5492, -2222, -322 },
- { 2823, -5091, -2886, 776 },
- { 3559, -5821, -2109, -1360 },
- { 1587, -6331, -2760, -1909 },
- { 2139, -5213, -2874, -2120 },
- { 1318, -4337, -3695, -2098 },
- { 821, -4471, -1849, -565 },
- { 3329, -4782, -1725, -89 },
- { 582, -4914, -4105, -1119 },
- { 417, -4144, -4072, -2529 },
- { -199, -3803, -2765, -4042 },
- { 2731, -4283, -2143, 1 },
- { 2911, -6187, -1951, -2116 },
- { 1573, -6094, -493, -2838 },
- { 2081, -6927, -864, -3211 },
- { 1058, -7826, 79, -364 },
- { 3147, -5570, -684, -978 },
- { 3572, -5856, 1060, 1824 },
- { 1143, -6702, -1478, 338 },
- { 2341, -7220, -88, 260 },
- { 3639, -6861, 668, 815 },
- { 2227, -6268, -1706, 446 },
- { 3390, -6082, -353, 1302 },
- { 1123, -7556, -1237, -430 },
- { 1729, -7742, 729, -218 },
- { 1457, -6774, 587, 579 },
- { 505, -6919, -569, 371 },
- { 1106, -7245, 78, 158 },
- { 2755, -6745, -1122, 338 },
- { 3069, -6040, -1415, 986 },
- { 2174, -7064, -1430, -283 },
- { 1390, -8626, -446, -3031 },
- { 3534, -6890, -431, 547 },
- { 2267, -9618, 475, -2994 },
- { 3672, -7673, 75, -115 },
- { 2131, -7560, -1206, -750 },
- { 2972, -7477, -685, -262 },
- { 1604, -6637, -672, 699 },
- { 1666, -7577, -577, -240 },
- { 1591, -6554, -2158, -94 },
- { 2348, -6286, -353, 1123 },
- { 2017, -8810, -412, -1805 },
- { 2892, -6713, -1765, -554 },
- { 2500, -6828, -1995, -1197 },
- { 3877, -6639, -224, -1655 },
- { 2392, -7872, -91, -333 },
- { 3562, -7370, -532, -2836 },
- { 2552, -7614, 164, -1805 },
- { 990, -6104, 218, 438 },
- { 910, -7861, 312, -1195 },
- { 1472, -6327, 372, -640 },
- { 1576, -7143, -1983, -843 },
- { 422, -7625, -457, -278 },
- { 1797, -8532, 405, -1011 },
- { 1088, -7396, -238, -2277 },
- { 3209, -6753, -1431, -2072 },
- { 2617, -6839, 100, -2573 },
- { 2575, -8573, -387, -3188 },
- { 3618, -6971, -1190, -321 },
- { 2205, -7361, -1695, -2008 },
- { 2985, -6297, 1464, 1179 },
- { 2804, -7310, 1053, 338 },
- { 1362, -6074, -1163, -840 },
- { 3336, -6325, -1794, 21 },
- { 2836, -8109, 818, -329 },
- { 2791, -5879, 560, 1546 },
- { 2392, -6064, 135, 100 },
- { 1838, -6194, 596, 1085 },
- { 1926, -7515, -414, -4901 },
- { 3225, -7298, -1202, -1189 },
- { 3960, -7558, -659, -719 },
- { 3442, -6647, -1692, -1095 },
- { 3381, -6441, 262, -886 },
- { 1431, -8150, -1186, -1406 },
- { 340, -8498, -150, -899 },
- { 3004, -8149, -260, -953 },
- { 2749, -6611, 563, 873 },
- { -6647, -1325, -4517, -4691 },
- { -6005, -1657, -4089, -3797 },
- { -3157, 588, -5213, -3068 },
- { -3311, -1425, -6329, -3726 },
- { -5866, -819, -3857, -2744 },
- { -5001, -1799, -1075, -4621 },
- { -5330, -2650, -2672, -4664 },
- { -4930, -539, -2363, -4010 },
- { -2984, 10, -3863, -5749 },
- { -1055, -2106, -3713, -4267 },
- { -5476, -502, -4279, -6504 },
- { -5231, -1543, -5018, -6425 },
- { -5134, -363, -3165, -5109 },
- { -3953, -771, -4107, -6393 },
- { -2159, -563, -3652, -5342 },
- { -3888, -2321, -919, -5057 },
- { -1236, -597, -4235, -4193 },
- { -4053, 675, -3083, -6174 },
- { -2793, -1089, -5396, -3460 },
- { -3000, -44, -2209, -6575 },
- { -3336, -1531, -4313, -5160 },
- { -2127, 128, -4851, -3692 },
- { -3321, 136, -2067, -5660 },
- { -5215, 1404, -4374, -4356 },
- { -2747, 400, -6340, -3691 },
- { -3926, -599, -5361, -5006 },
- { -2875, -2592, -5143, -4092 },
- { -4991, -1958, -5322, -4891 },
- { -4965, -1318, -6652, -5333 },
- { -4920, -1691, -3388, -5561 },
- { -3644, -3354, -2688, -5982 },
- { -5076, -919, -4563, -2984 },
- { -6114, 250, -3884, -3915 },
- { -4014, 744, -3973, -1924 },
- { -5543, -1041, -5557, -3847 },
- { -4711, -1352, -5649, -2603 },
- { -3362, 775, -5305, -4879 },
- { -5001, 107, -3554, -2888 },
- { -6258, -1651, -6356, -6566 },
- { -4529, 407, -5003, -3865 },
- { -5154, 550, -5278, -5465 },
- { -4195, -467, -1894, -3129 },
- { -5022, 1127, -3349, -3314 },
- { -6075, 1250, -4313, -5641 },
- { -2677, -2283, -2312, -5903 },
- { -4113, 193, -1195, -4833 },
- { -3940, -1048, -1389, -5079 },
- { -3703, 917, -4043, -4451 },
- { -3366, -4231, -1534, -5488 },
- { -3326, -3583, -2091, -4903 },
- { -5144, 1254, -2532, -4949 },
- { -5982, -870, -2545, -4555 },
- { -3925, -157, -5367, -2281 },
- { -6419, -746, -5668, -4371 },
- { -5787, 518, -7096, -5805 },
- { -4258, 954, -6453, -4321 },
- { -4771, -695, -4158, -1639 },
- { -7078, -760, -5195, -5877 },
- { -7348, 83, -4101, -4586 },
- { -2430, 184, -2874, -1679 },
- { -2284, -3943, -2924, -5034 },
- { -1804, -1785, -3002, -4710 },
- { -4399, -2772, -1815, -4637 },
- { -6340, -2626, -2824, -5191 },
- { -4998, -5168, -3480, 1905 },
- { -3958, -5492, -1599, 1579 },
- { -2471, -3755, -276, 3182 },
- { -3033, -5779, -1063, 1554 },
- { -2936, -4829, -1290, 2386 },
- { -1835, -5073, -3051, 1299 },
- { -1724, -3771, -3935, 2324 },
- { -5070, -2550, -3692, 768 },
- { -4326, -5333, -297, 1878 },
- { -3472, -5619, -3094, 992 },
- { -3027, -4384, -3038, 2265 },
- { -3201, -5332, 67, 2200 },
- { -1681, -4373, -1947, 2461 },
- { -3221, -3329, -4238, 2564 },
- { -1262, -2968, -2915, 3227 },
- { -3419, -1878, -3373, 2110 },
- { -2244, -5583, -2012, 1288 },
- { -1971, -5266, -990, 1812 },
- { -2975, -2778, -452, 4063 },
- { -2198, -1165, -3298, 2965 },
- { -4782, -4894, -4767, 664 },
- { -6002, -3950, -2806, 2025 },
- { -3142, -3162, -2859, 3295 },
- { -3262, -3340, -4123, 1596 },
- { -4014, -3918, -1955, 3361 },
- { -1700, -3463, -1346, 3449 },
- { -4245, -4445, -4743, 1644 },
- { -4180, -3969, -401, 3281 },
- { -2782, -5240, -4117, 1156 },
- { -5744, -4040, -1439, 3470 },
- { -5063, -4663, -323, 3172 },
- { -4531, -3319, -844, 3988 },
- { -6226, -5125, -2064, 2976 },
- { -3115, -3267, -1531, 3898 },
- { -4628, -4421, -2864, 2808 },
- { -4559, -2989, -3442, 2024 },
- { -1775, -4487, -656, 2477 },
- { -2664, -1865, -1884, 4081 },
- { -1828, -2575, -3894, 3378 },
- { -6441, -3677, -2025, 1677 },
- { -4141, -2156, -1191, 3474 },
- { -4802, -1623, -1727, 2160 },
- { -5474, -2745, -1475, 2498 },
- { -3664, -1056, -1975, 2491 },
- { -4672, -3062, -2235, 2933 },
- { -4205, -5960, -2849, 1517 },
- { -4995, -5708, -1739, 1805 },
- { -4892, -6080, -4793, 872 },
- { -4270, -4172, -4263, 2185 },
- { -4687, -1470, -2905, 1023 },
- { -6446, -5017, -3919, 1000 },
- { -6046, -5538, -3943, 2006 },
- { -6028, -3750, -3953, 771 },
- { -5959, -4582, -5024, 824 },
- { -5818, -2576, -2249, 1326 },
- { -5659, -5345, -1119, 2500 },
- { -3346, -4155, 606, 2749 },
- { -5680, -4827, -2501, 1838 },
- { -6193, -2543, -1295, 840 },
- { -6871, -4925, -3512, 1801 },
- { -5605, -1788, -1895, 779 },
- { -3922, -5712, -4644, 510 },
- { -4745, -3869, -4533, 99 },
- { -2984, -4907, -399, 1497 },
- { 1847, -478, 3061, -5812 },
- { 4450, -1116, 3609, -6570 },
- { 3139, 99, 3007, -5532 },
- { 2590, -3782, 3138, -4770 },
- { 1881, 1204, 5778, -3404 },
- { 3631, 2060, 5566, -5038 },
- { 3461, 1961, 5167, -3800 },
- { 2947, 273, 4536, -4389 },
- { 4453, -1730, 5788, -4370 },
- { 4032, 1805, 2666, -4534 },
- { 3487, -944, 2313, -6028 },
- { 1313, 34, 4210, -4067 },
- { 5632, -1502, 5825, -5855 },
- { 7736, -547, 4879, -5476 },
- { 4906, -1512, 4760, -5760 },
- { 3843, 447, 1091, -4958 },
- { 2982, -1135, 5442, -4386 },
- { 3579, 271, 3031, -6770 },
- { 3932, -211, 4688, -5507 },
- { 4411, 1720, 2387, -5584 },
- { 5379, -479, 4575, -6280 },
- { 3613, -362, 2012, -4885 },
- { 3744, -2013, 4493, -5073 },
- { 5693, 109, 4379, -3362 },
- { 5475, -621, 5317, -3985 },
- { 6411, -673, 5708, -4752 },
- { 4933, -796, 7262, -4290 },
- { 2804, 444, 6276, -3655 },
- { 4120, -517, 6078, -4531 },
- { 5119, 841, 3486, -3910 },
- { 4738, 1539, 3525, -2970 },
- { 5086, 370, 5895, -5640 },
- { 4235, 2716, 4589, -5044 },
- { 3691, 682, 6199, -4700 },
- { 6111, -570, 6271, -6528 },
- { 2611, 1277, 3756, -4802 },
- { 4395, 970, 3807, -5879 },
- { 5225, 2299, 3242, -4333 },
- { 5144, 1778, 4946, -5545 },
- { 2989, -3016, 3247, -5495 },
- { 2983, 920, 2071, -6059 },
- { 5270, -903, 4434, -2350 },
- { 6415, -585, 3970, -3554 },
- { 3866, -197, 5216, -2884 },
- { 3767, -1298, 6702, -3315 },
- { 6299, 2620, 5284, -6824 },
- { 6654, 646, 3653, -4927 },
- { 4770, 3047, 5160, -6287 },
- { 5364, 434, 2919, -5207 },
- { 2998, 1344, 4801, -2456 },
- { 3896, 1013, 3773, -1864 },
- { 2115, 655, 2999, -6344 },
- { 5170, -981, 2849, -4464 },
- { 2735, -2159, 2717, -5776 },
- { 2430, -1952, 4392, -4559 },
- { 6143, -1180, 3659, -4746 },
- { 4978, -1483, 1726, -4875 },
- { 3486, -2383, 3306, -4301 },
- { 1434, -1372, 4171, -4770 },
- { 3354, -2627, 1525, -5093 },
- { 6790, 2386, 3995, -5909 },
- { 1475, -2674, 3451, -4204 },
- { 1999, -3494, 3693, -5556 },
- { 4764, -2848, 2856, -5589 },
- { -3677, 5131, 2827, -2934 },
- { -2844, 7078, 2852, -3580 },
- { -3902, 6434, 4118, -1911 },
- { -1769, 7530, 3492, -3541 },
- { -1937, 5679, -447, -1127 },
- { -2456, 4680, 4196, -2407 },
- { -2778, 8241, 1698, -4288 },
- { -2876, 6104, 5182, -2387 },
- { -2802, 7341, 4463, -2938 },
- { -1025, 6267, 4752, -3201 },
- { -2349, 5413, 2041, -3794 },
- { -2252, 8225, 2856, -4269 },
- { -1465, 4967, 4976, -2500 },
- { -636, 7565, 3517, -4233 },
- { -1905, 5618, 3904, -2942 },
- { -302, 6816, 3343, -3316 },
- { -2210, 4156, 2817, -3511 },
- { -717, 6568, 1863, -2951 },
- { -3873, 5682, 2164, -575 },
- { -2878, 5835, 440, -2597 },
- { -3228, 7701, 2610, -2514 },
- { -3608, 8888, 3377, -2468 },
- { -2582, 9717, 2519, -3126 },
- { -5238, 6202, 2866, -2831 },
- { -3428, 7370, 3056, -335 },
- { -1681, 8836, 1210, -2010 },
- { -3276, 6724, 1156, -3930 },
- { -894, 8149, 827, -1258 },
- { -2965, 8631, 2549, -1320 },
- { -3961, 6902, 3581, 55 },
- { -1894, 7745, 1750, -841 },
- { -821, 6844, 850, -676 },
- { -608, 6948, -4, -1376 },
- { 615, 6524, 1089, -1147 },
- { -2972, 5668, 1091, -489 },
- { -157, 4649, 2904, -413 },
- { 673, 5121, 1498, -66 },
- { -390, 5902, 1611, -245 },
- { -2349, 5478, 4772, -1320 },
- { 88, 6798, 1972, -1859 },
- { -1213, 5120, 2991, 200 },
- { -2347, 6040, 2839, 376 },
- { -578, 5976, 3364, -1796 },
- { -1391, 5872, 3002, -965 },
- { -564, 4496, 3946, -1186 },
- { -2299, 6386, 3135, -2176 },
- { -2131, 5641, 2011, 1223 },
- { -772, 5807, 1124, 895 },
- { -2837, 6758, 2297, -740 },
- { -3091, 6298, 1415, -2126 },
- { -4197, 6036, 1843, -3022 },
- { -41, 6459, 92, 344 },
- { -2241, 6860, 2095, -4396 },
- { -1931, 7088, 2117, -2135 },
- { -2375, 4422, 1688, -3169 },
- { -1742, 6674, 1538, -119 },
- { -4818, 7749, 4192, -1577 },
- { -2004, 5672, 193, -430 },
- { -3825, 6042, 2128, -1898 },
- { -1108, 8033, 2119, -3013 },
- { -2370, 5453, 1721, 266 },
- { -1570, 7134, 614, -2638 },
- { -1519, 8752, 3503, -4330 },
- { -2050, 3845, 2907, -1126 },
- { 5085, 4412, -335, -1923 },
- { 3618, 1423, -613, -4012 },
- { 4481, 3729, 589, -4631 },
- { 4270, 3216, -1763, -3168 },
- { 4241, 1796, -1701, -2796 },
- { 4787, 2338, -487, -3639 },
- { 2915, 3429, -621, -4753 },
- { 5175, 1660, -1265, -3223 },
- { 4280, 4057, -684, -4079 },
- { 4980, 4419, -1455, -2719 },
- { 5436, 2464, 387, -4197 },
- { 4507, 4018, 1121, -3314 },
- { 6020, 2401, -413, -3201 },
- { 4200, 3789, -333, -2813 },
- { 5229, 2493, -1194, -1878 },
- { 5851, 2695, -492, -2292 },
- { 5743, 3288, -697, -1221 },
- { 5692, 2612, 979, -2227 },
- { 5085, 2067, 1046, -1214 },
- { 3163, 2240, -2098, -3435 },
- { 5228, 1898, 145, -2397 },
- { 5860, 3976, -418, -2872 },
- { 6008, 3399, 1027, -3506 },
- { 4126, 2035, 1865, -893 },
- { 5375, 3596, 511, -2362 },
- { 1937, 1493, -852, -122 },
- { 3473, 4849, 547, -2603 },
- { 4631, 2977, 1141, -1768 },
- { 6149, 3050, -71, -1886 },
- { 4069, 4353, -289, -1429 },
- { 2884, 1225, -1388, 365 },
- { 5485, 2518, -235, -571 },
- { 1216, 4375, 1443, 398 },
- { 4988, 3106, 107, -1435 },
- { 4511, 2801, 307, -444 },
- { 3235, 4386, 327, -676 },
- { 2055, 3708, 1657, -305 },
- { 5839, 2374, 290, -1385 },
- { 5110, 3305, 1936, -4206 },
- { 6416, 2920, 338, -2736 },
- { 3350, 2824, -1269, -3881 },
- { 4840, 1815, 464, 186 },
- { 2399, 3332, 238, 1238 },
- { 3516, 1363, 1582, 688 },
- { 3582, 1874, 154, -4770 },
- { 3261, 2878, 886, 283 },
- { 3877, 2658, -327, 884 },
- { 4151, 3436, 2173, -2923 },
- { 3592, 3674, 1281, -1295 },
- { 4561, 3730, -1114, -1747 },
- { 4595, 3625, -558, -575 },
- { 2577, 2348, 2267, 120 },
- { 5242, 3299, 32, -3412 },
- { 4264, 3637, 709, -2320 },
- { 6556, 3570, -838, -2472 },
- { 5745, 4014, -940, -1973 },
- { 5629, 4475, 477, -3328 },
- { 5269, 3199, 1682, -3085 },
- { 4432, 2416, 1145, -3299 },
- { 4465, 2505, 2162, -2186 },
- { 4643, 4941, -88, -2885 },
- { 4568, 5231, 552, -3915 },
- { 5667, 3075, -1406, -2963 },
- { 5418, 5259, -771, -2818 },
- { -256, -7875, 511, -471 },
- { -1813, -7971, -424, -396 },
- { -306, -7006, 862, 282 },
- { -2306, -6422, -1440, 508 },
- { -245, -6787, 375, -100 },
- { -1309, -6065, -20, 779 },
- { -1656, -6047, -641, 1307 },
- { -1496, -6522, 964, 726 },
- { -2291, -6588, -202, 795 },
- { -762, -7522, 1454, -558 },
- { -2270, -7004, -834, -580 },
- { -1139, -7078, 259, 362 },
- { -2535, -7568, -1040, 49 },
- { -3786, -7280, 934, -476 },
- { -3336, -6368, 606, 1056 },
- { -3602, -6924, 52, 714 },
- { -2278, -6550, 1674, 204 },
- { -2855, -5765, 930, 1530 },
- { -2889, -7325, -215, 305 },
- { -2749, -6080, -237, 1452 },
- { -985, -6667, 1577, 400 },
- { -2036, -6083, 380, 1267 },
- { -2077, -7460, 380, -30 },
- { -1775, -7175, 1540, -386 },
- { -3065, -6927, 989, 168 },
- { -2836, -7602, 117, -3392 },
- { -1058, -6396, 593, -3078 },
- { -844, -6062, 999, -236 },
- { -3261, -6951, 1491, -720 },
- { -2186, -8484, 75, -1287 },
- { -2882, -7756, 456, -510 },
- { -1800, -6879, 960, -1183 },
- { -2554, -7241, 1614, -1474 },
- { -2608, -5305, 392, 851 },
- { -2973, -6562, -859, 858 },
- { -2640, -5989, 1031, -416 },
- { -977, -8366, 705, -1434 },
- { -1213, -7409, -77, -1390 },
- { -1335, -6657, 2125, -123 },
- { -2544, -6862, 1852, -737 },
- { -3235, -6422, 1752, -103 },
- { -1300, -7557, 939, -348 },
- { -3476, -7579, 202, -109 },
- { -2482, -6572, 753, 619 },
- { -2554, -8136, -648, -429 },
- { -1012, -7870, -3, -421 },
- { -3604, -6247, 32, -3102 },
- { -1486, -7271, 2013, -1021 },
- { -578, -6799, -523, 405 },
- { -2841, -5948, 1644, 911 },
- { -2411, -7473, 1084, -484 },
- { -2238, -6033, 294, -1059 },
- { -3459, -6470, -201, -790 },
- { -2027, -6009, 1833, 805 },
- { -1433, -8047, 1531, -1754 },
- { -3258, -7884, 763, -1422 },
- { -1544, -6928, -729, 478 },
- { -2314, -8415, 74, -3757 },
- { -3201, -5684, 95, -2214 },
- { -2423, -8694, 725, -3631 },
- { -3545, -7071, 1162, -1798 },
- { -294, -9662, 403, -2274 },
- { -2290, -5460, 1196, 402 },
- { -1603, -6713, 903, -2363 },
- { 4121, 2491, -3142, -2482 },
- { 4500, 3305, -3671, -1567 },
- { 5973, 3172, -1348, -534 },
- { 4830, 3379, -1549, 643 },
- { 5214, 3938, -2641, -2302 },
- { 4639, 4826, -5532, -847 },
- { 5639, 2731, -2170, -963 },
- { 6084, 3487, -3525, -1346 },
- { 5971, 3154, -2190, -2316 },
- { 5618, 4865, -6927, 116 },
- { 5345, 3568, -7391, 709 },
- { 5429, 5078, -3811, -1524 },
- { 6960, 2037, -3515, -1096 },
- { 7092, 2531, -4557, -588 },
- { 6061, 4247, -5651, -478 },
- { 4595, 3684, -4907, -827 },
- { 7497, 3213, -3048, -424 },
- { 5996, 2137, -3098, -1745 },
- { 6198, 5199, -2223, -2274 },
- { 6888, 2851, -2768, -1675 },
- { 6114, 4210, -2316, -954 },
- { 7127, 4242, -3041, -1408 },
- { 6126, 3668, -1517, -1427 },
- { 6245, 6129, -4225, -1186 },
- { 6816, 3213, -2101, -964 },
- { 5345, 5276, -2643, -847 },
- { 6592, 4665, -4338, 484 },
- { 6746, 3751, -3443, 124 },
- { 5453, 1980, -2738, 2606 },
- { 4662, 2179, -4226, -1059 },
- { 5571, 3208, -3554, 174 },
- { 5256, 4447, -1815, -1481 },
- { 5400, 2570, -1210, 235 },
- { 7056, 2549, -2674, 318 },
- { 4574, 4340, -2892, -130 },
- { 6203, 4587, -3273, -305 },
- { 5103, 1925, -2715, -2137 },
- { 3905, 4296, -1700, 247 },
- { 4421, 4605, -3299, 811 },
- { 5671, 1273, -3870, -924 },
- { 5486, 1805, -4901, 133 },
- { 6437, 2578, -1828, -106 },
- { 5530, 5253, -5058, 1223 },
- { 4816, 2025, -1215, 1443 },
- { 3457, 3525, -2456, 3217 },
- { 3316, 2595, -1108, 2459 },
- { 3068, 3810, -2207, 1926 },
- { 6351, 5436, -6470, 600 },
- { 6324, 4240, -5365, 2416 },
- { 4851, 4774, -4075, 1878 },
- { 4900, 3679, -5198, 1078 },
- { 8347, 3633, -4565, -171 },
- { 5244, 5718, -3853, 173 },
- { 3960, 3492, -2939, 2105 },
- { 6070, 3473, -2351, 161 },
- { 8228, 3034, -3360, -901 },
- { 7006, 3985, -1940, -1926 },
- { 7123, 4681, -4301, -878 },
- { 5122, 4097, -1851, -449 },
- { 6200, 2060, -2251, 1049 },
- { 7106, 3844, -7209, 2625 },
- { 7108, 3370, -6734, 533 },
- { 6859, 2849, -3992, 1360 },
- { 5458, 2278, -3253, 1131 },
- { -1072, -2109, 4783, -1073 },
- { -319, -2604, 4257, -2418 },
- { 2466, 1300, 3476, -314 },
- { 2847, -1502, 5296, -141 },
- { 1667, -1273, 5559, -2725 },
- { 2877, -3402, 6434, 204 },
- { 53, -2637, 5275, -1181 },
- { 1091, -2215, 5803, -1549 },
- { 2397, -922, 4327, 1182 },
- { 219, -3747, 4647, -1564 },
- { -29, -2705, 4812, 1277 },
- { 1499, -2608, 5648, 1407 },
- { 2139, -2399, 4202, 2791 },
- { -426, -2064, 5528, 151 },
- { 2560, -2803, 6179, -2806 },
- { 4537, -2479, 3797, 1095 },
- { 888, -3357, 5341, -415 },
- { 4460, -1814, 5388, -1227 },
- { 3920, -3268, 6364, -703 },
- { 3343, -4698, 4410, 784 },
- { 309, -1897, 6306, 1223 },
- { 958, -3318, 4254, -3167 },
- { -99, 1596, 6018, -1983 },
- { -429, -853, 6407, 878 },
- { 1170, -1322, 6290, -417 },
- { 2288, -505, 6303, -1999 },
- { 3312, -1674, 6749, -2494 },
- { -415, -3401, 4721, -371 },
- { -189, -1210, 4844, -2002 },
- { 888, -4142, 4377, 130 },
- { 2469, -4381, 5398, -2492 },
- { 2879, -2912, 5094, -2598 },
- { -717, -617, 5650, -685 },
- { 1470, -3863, 5352, -1684 },
- { 3935, -96, 3823, -730 },
- { 3769, -430, 3168, 694 },
- { 2556, 385, 3539, 512 },
- { 77, -1415, 5111, 2655 },
- { 2724, -2158, 6715, -822 },
- { 1832, 1001, 5385, -1900 },
- { 900, 2198, 4464, -559 },
- { 441, 69, 5921, -1743 },
- { -1161, 738, 6732, -308 },
- { 257, 2035, 4091, 736 },
- { 1607, 1288, 4355, -23 },
- { -13, 1316, 4180, 1672 },
- { 1511, 1336, 3057, 1435 },
- { 2189, -3813, 4530, 939 },
- { 3632, -706, 2646, 1375 },
- { 4266, -3761, 4241, 1077 },
- { 3101, -427, 5273, -1202 },
- { 2293, 276, 4810, -313 },
- { 3430, -1851, 3101, 2045 },
- { 3453, -2979, 5142, 942 },
- { 1683, -3281, 4802, 2002 },
- { 3954, -4715, 5611, 578 },
- { 1272, -155, 5085, 454 },
- { 128, -194, 5095, 1409 },
- { 820, 880, 5797, -2658 },
- { -1095, 656, 5774, 1095 },
- { 813, -1669, 4320, -3251 },
- { -119, 518, 6372, -651 },
- { 2922, -4299, 6115, -877 },
- { 4205, -4273, 4004, 2642 },
- { -1211, -3892, 224, 3127 },
- { -34, -4371, 1321, 2318 },
- { 77, -6326, 1201, 828 },
- { 3995, -3775, 1958, 3233 },
- { 178, -3301, 1985, 3318 },
- { 2330, -3801, 1033, 3195 },
- { 1413, -5536, 826, 1709 },
- { 2468, -3499, 3653, 3631 },
- { 741, -4617, 1723, 2008 },
- { 1246, -3043, 2978, 3949 },
- { -343, -4308, 2258, 2189 },
- { -682, -4640, 454, 2272 },
- { 1236, -4829, 2491, 1642 },
- { -512, -3766, 1182, 3052 },
- { 119, -3939, 3712, 971 },
- { -1145, -4624, 1360, 2281 },
- { 101, -4746, 2866, 1255 },
- { -1500, -5455, 539, 1637 },
- { -969, -5909, 1414, 1128 },
- { -1261, -4939, -231, 2022 },
- { -226, -5345, 1207, 705 },
- { 2712, -5109, 3205, 1866 },
- { -476, -5913, 273, 1208 },
- { -2039, -4464, 624, 2545 },
- { -2351, -3930, 2019, 2673 },
- { -2675, -4849, 1522, 1990 },
- { -1524, -3461, 1446, 3204 },
- { 477, -5314, 1710, 1577 },
- { 656, -3729, 2346, 2511 },
- { 550, -5917, 1975, 1040 },
- { 1728, -4704, 3067, 1058 },
- { -9, -5247, 506, 1760 },
- { -574, -5135, 1675, 1672 },
- { 2129, -3781, 3444, 2313 },
- { 1144, -4439, 2214, 2529 },
- { 1292, -4160, 3185, 1833 },
- { 2445, -3262, 2534, 3227 },
- { 2266, -4401, 2023, 2400 },
- { -587, -3602, 3408, 2067 },
- { -885, -4951, 3228, 1174 },
- { -728, -2711, 2807, 3552 },
- { 1019, -3043, 3195, 2954 },
- { 1888, -4615, 1140, 2454 },
- { 660, -5616, 754, 800 },
- { -1975, -5371, 1649, 1585 },
- { -1544, -5436, 2422, 1081 },
- { -422, -5882, 2390, 750 },
- { 1336, -5557, 2441, 1230 },
- { 136, -4001, 267, 2854 },
- { -522, -3289, 2226, 2728 },
- { -971, -4580, 2471, 708 },
- { 704, -5306, 3300, 1001 },
- { 325, -3464, 3555, 2398 },
- { 794, -3686, 848, 3169 },
- { 660, -3017, 4584, 3242 },
- { -1486, -3978, 2170, 1644 },
- { -1615, -4650, 2688, 1844 },
- { 750, -4578, 538, 2239 },
- { 1668, -5849, 1455, 1031 },
- { 3486, -4681, 2030, 2183 },
- { 2642, -5429, 1696, 1761 },
- { 4491, -4502, 3538, 2767 },
- { 3545, -4528, 3514, 2982 },
- { 3269, -3676, 2758, 3966 },
- { 5572, 1146, 209, -3379 },
- { 7459, 1053, 593, -1896 },
- { 4480, 200, -310, -4259 },
- { 5577, -939, 242, -3992 },
- { 8142, 442, 1257, -3083 },
- { 5442, 1261, 1424, -3236 },
- { 6260, -183, 3125, -2532 },
- { 7179, 889, 1618, -2548 },
- { 6416, 932, 2379, -2487 },
- { 7094, 2560, 961, -3392 },
- { 7322, 463, 2732, -3735 },
- { 6632, 1577, 1912, -3272 },
- { 6312, 1349, 3028, -3460 },
- { 6105, 386, 1213, -977 },
- { 5478, 1158, 1114, -486 },
- { 6493, 410, 1686, -2180 },
- { 6378, 1881, 1333, -2240 },
- { 5711, 812, 1958, -1300 },
- { 6844, 877, 730, -1189 },
- { 6824, -245, 2249, -2000 },
- { 7515, 1521, 1251, -3058 },
- { 6697, 1051, 1300, -1749 },
- { 6476, 1425, 811, -2773 },
- { 7350, 465, -76, -2849 },
- { 6975, 2095, 567, -2492 },
- { 4691, 1736, 2660, -2289 },
- { 7837, 1456, 340, -2767 },
- { 7930, 507, 838, -2074 },
- { 6106, 1502, 766, -1110 },
- { 4891, -659, 835, -3954 },
- { 7250, 141, 1369, -1523 },
- { 7651, 67, 1651, -2298 },
- { 7364, -305, 601, -3132 },
- { 7179, 193, 2491, -2871 },
- { 6504, -272, 2167, -1322 },
- { 4456, 983, 2300, -421 },
- { 4817, 457, 1695, 371 },
- { 6914, 555, 850, -3159 },
- { 5904, 1030, 202, -1959 },
- { 6258, 880, 2233, -4503 },
- { 6029, 10, 2130, -3600 },
- { 6449, 985, 1129, -3963 },
- { 6616, -18, -111, -3285 },
- { 4496, 775, 817, -4276 },
- { 6134, 2338, 1470, -2973 },
- { 6911, 152, 430, -1946 },
- { 4053, 991, 3218, -1193 },
- { 5435, 1285, 3124, -2412 },
- { 5507, 1836, 1935, -1988 },
- { 5240, 689, 2189, -2670 },
- { 6638, 1719, 606, -1799 },
- { 5556, -180, 129, -2595 },
- { 5644, 1918, 1281, -4316 },
- { 6410, 1088, -282, -3117 },
- { 6503, 1841, 312, -3514 },
- { 6947, 20, 1358, -3886 },
- { 5464, 2109, 2398, -3194 },
- { 5616, -407, 2140, -498 },
- { 6121, 2707, 2379, -4096 },
- { 7303, 1846, 2266, -4095 },
- { 5444, 470, 2718, -1553 },
- { 5817, -645, 3285, -1349 },
- { 5625, 1427, 1103, -1991 },
- { 6041, -806, 1196, -2943 },
- { 3050, -5722, 4070, -5460 },
- { 3420, -4386, 4078, -5155 },
- { 6020, -3982, 7268, -2689 },
- { 7502, -4317, 7894, -3973 },
- { 4156, -3558, 5247, -4316 },
- { 4725, -4401, 7290, -1540 },
- { 6688, -5122, 8216, -3210 },
- { 9176, -6576, 9276, -4963 },
- { 8706, -5708, 7987, -4621 },
- { 7060, -3535, 6532, -3308 },
- { 5600, -2719, 5363, -1568 },
- { 4661, -2803, 6263, -4716 },
- { 3673, -3636, 6147, -3433 },
- { 5305, -2585, 6073, -2638 },
- { 7614, -1962, 6079, -5266 },
- { 6760, -3366, 7382, -4322 },
- { 6385, -3883, 4797, -1353 },
- { 8182, -5120, 4298, -4641 },
- { 9130, -6198, 4975, -3063 },
- { 7421, -5436, 5576, -3713 },
- { 3483, -4898, 5443, -2745 },
- { 4907, -5643, 6390, -4105 },
- { 8119, -7008, 7992, -6764 },
- { 6528, -6122, 6967, -5590 },
- { 5890, -4190, 6624, -5688 },
- { 6815, -7934, 7275, -5456 },
- { 5434, -4306, 5169, -5378 },
- { 4364, -6436, 5376, -2604 },
- { 8152, -3404, 5913, -5048 },
- { 7983, -4863, 4262, -2461 },
- { 8023, -6188, 6238, -5062 },
- { 6753, -3692, 3935, -3723 },
- { 6826, -4760, 3284, -4051 },
- { 7224, -7423, 4492, -3875 },
- { 6904, -2590, 6587, -6248 },
- { 6106, -1944, 7345, -5506 },
- { 4956, -2990, 7808, -3146 },
- { 6908, -6885, 5949, -1288 },
- { 7162, -6058, 3419, -3401 },
- { 7015, -7080, 6907, -3018 },
- { 6971, -6832, 5646, -3273 },
- { 8014, -5546, 5471, -1544 },
- { 6792, -2220, 5105, -2879 },
- { 8494, -3974, 4408, -3999 },
- { 9591, -4866, 6027, -4558 },
- { 5264, -5161, 6101, -738 },
- { 5803, -6141, 5197, -5231 },
- { 4657, -6822, 3232, -5189 },
- { 4791, -5135, 3809, -4665 },
- { 6108, -5103, 2379, -3873 },
- { 4680, -3909, 3234, -5093 },
- { 5802, -3853, 3795, -4984 },
- { 4360, -7483, 4802, -3877 },
- { 5429, -7517, 5911, -3717 },
- { 6866, -2280, 4880, -4634 },
- { 10131, -4628, 4414, -4092 },
- { 10811, -5189, 7746, -5337 },
- { 5663, -8941, 5287, -5680 },
- { 8023, -5991, 7403, -2796 },
- { 9669, -6919, 6525, -4932 },
- { 7275, -3796, 4962, -2547 },
- { 8848, -4806, 5677, -3080 },
- { 8128, -4308, 7749, -6569 },
- { 4032, -5196, 2282, -6239 },
- { 6593, 700, -229, 304 },
- { 8260, 539, -66, -1259 },
- { 6605, 176, -814, -109 },
- { 8057, 0, -1, -136 },
- { 7382, -38, -484, -1129 },
- { 8373, -929, 682, -454 },
- { 7674, 690, -1278, 546 },
- { 7326, -517, 406, -1283 },
- { 7612, -1715, -1167, 1175 },
- { 8590, 441, -782, -710 },
- { 8572, -1202, -291, 260 },
- { 7308, -147, -1785, 414 },
- { 6787, -353, -672, 934 },
- { 5177, -133, 179, 82 },
- { 4161, -34, 447, 1497 },
- { 5997, -902, 1533, -121 },
- { 5727, -871, -1370, 945 },
- { 8386, -252, 293, -823 },
- { 6573, -1354, 682, 616 },
- { 7650, -2096, 725, 457 },
- { 8122, 78, 636, -1400 },
- { 8421, 428, -1620, 131 },
- { 7341, -1292, -717, 186 },
- { 7998, -49, -720, 266 },
- { 5987, -351, 669, 844 },
- { 7314, -1620, 250, -603 },
- { 7219, -1562, -572, 1994 },
- { 8682, -358, -290, -388 },
- { 5810, 155, -178, 1199 },
- { 7246, -12, 1042, -786 },
- { 7357, -923, 1468, -475 },
- { 7801, 621, -212, -724 },
- { 5346, -514, 1210, 1356 },
- { 8459, 36, -127, -779 },
- { 6878, -2429, 854, 1750 },
- { 7280, -1401, -1353, 2845 },
- { 7579, -2148, -1463, 2087 },
- { 6637, 946, -872, 750 },
- { 4807, -1100, 1289, 2602 },
- { 4495, 219, 1551, 1128 },
- { 7639, 506, 446, -1107 },
- { 6359, 188, 1009, -115 },
- { 6641, -1820, 1655, 723 },
- { 5394, -2382, 1604, 2542 },
- { 6021, -2644, 2396, 1407 },
- { 4698, 882, 245, 1525 },
- { 8103, 573, -798, -349 },
- { 8045, -519, 997, -1092 },
- { 7571, -122, 227, -338 },
- { 5347, -1200, 630, 1718 },
- { 7070, 790, 218, -544 },
- { 7440, 728, -527, -20 },
- { 6402, -355, 197, -736 },
- { 4031, 771, 866, 1895 },
- { 6009, 896, 445, -31 },
- { 5160, 1098, -856, 1784 },
- { 7980, -886, -1293, 1396 },
- { 6318, -1361, 2423, 252 },
- { 7547, -699, 133, 506 },
- { 8562, -2344, 940, 264 },
- { 5890, 1187, -1425, 2194 },
- { 6558, -645, -1311, 2621 },
- { 4634, -1671, 2075, 1623 },
- { 5614, 105, -816, 2376 },
- { 6646, 1558, -1365, 630 },
- { 6998, 1150, -2117, -990 },
- { 6555, 2311, -1093, -1783 },
- { 6682, 1430, -2391, -1940 },
- { 7861, 1555, -2977, -1188 },
- { 6745, 1723, -459, -2085 },
- { 7504, 1229, -1666, -2060 },
- { 7937, 671, -2128, -1529 },
- { 7139, 991, -735, -2632 },
- { 6867, 1592, -1303, -2324 },
- { 6401, 2230, -1732, -2508 },
- { 7201, 2184, -2169, -1988 },
- { 6636, 2190, -995, -2840 },
- { 7620, 2306, -2089, -651 },
- { 7584, 1875, -1438, -631 },
- { 9214, 1561, -2464, -1139 },
- { 6154, 1318, -1237, -2917 },
- { 7917, 2847, -1797, -1599 },
- { 8309, 2029, -2555, -465 },
- { 8204, 1282, -584, -2405 },
- { 8440, 1035, -1147, -1137 },
- { 7107, 1858, -60, -1568 },
- { 6781, 2912, -873, -1463 },
- { 7603, 1316, -319, -1249 },
- { 7833, 1335, -78, -1849 },
- { 7930, 1141, -1016, -695 },
- { 7883, 1610, -1017, -1314 },
- { 8069, 1409, -1811, -196 },
- { 8319, 1031, -582, -1590 },
- { 5948, 1537, -2153, -2373 },
- { 8684, 1171, -1871, -850 },
- { 8357, 2484, -2411, -1292 },
- { 6516, 2092, -193, -1167 },
- { 6112, 1697, 22, -525 },
- { 7161, 703, -602, -1879 },
- { 6047, 2351, -807, -219 },
- { 8072, 1854, -1817, -1553 },
- { 6956, 1304, 76, -1011 },
- { 6607, 1481, -544, -162 },
- { 6958, 2541, -265, -1938 },
- { 6416, 2514, -777, -850 },
- { 7272, 2110, -899, -1171 },
- { 7741, 2153, -283, -2614 },
- { 6482, 2041, -1758, -1221 },
- { 6762, 940, -1862, -2281 },
- { 5610, 1194, -1691, -1561 },
- { 7833, 2164, -823, -1952 },
- { 5460, 1438, -848, 1189 },
- { 6011, 1377, -771, -1557 },
- { 7679, 544, -1134, -2214 },
- { 7209, 1292, -2714, -1564 },
- { 5567, 1200, -404, -169 },
- { 5853, 1461, -1465, -518 },
- { 6782, 689, -844, -860 },
- { 7330, 1337, -1152, -71 },
- { 7189, 1506, -653, -685 },
- { 6860, 2116, -1403, -240 },
- { 8804, 1516, -1391, -1760 },
- { 7210, 2689, -1498, -989 },
- { 7030, 3022, -1441, -2083 },
- { 5649, 1836, -407, 525 },
- { 7451, 3099, -717, -2464 },
- { 7384, 1656, -2007, 398 },
- { 6504, 707, -1919, -134 },
- { -1851, 3639, -2279, -695 },
- { -4037, 1644, -77, 1329 },
- { -4025, 1960, -1565, -567 },
- { -3430, 2495, -795, 368 },
- { -4771, 2480, 993, 756 },
- { -3431, 2058, -2539, -971 },
- { -3802, 3418, 380, 217 },
- { -3074, 3350, -1652, -1056 },
- { -3705, 326, -1650, 1535 },
- { -3122, 1281, -1192, 1607 },
- { -4601, 1367, -968, 53 },
- { -3808, 958, 44, 2560 },
- { -2079, 2530, -1485, 1166 },
- { -3707, 343, -2889, 180 },
- { -5249, 1431, -31, 688 },
- { -4990, 125, -704, 1270 },
- { -2771, 1334, -2446, 746 },
- { -2292, 994, -1527, 2630 },
- { -1261, 3070, -2519, 268 },
- { -2544, 3890, -1057, -552 },
- { -4421, 255, -1980, 530 },
- { -2951, 454, -13, 3643 },
- { -2262, 1815, -370, 2880 },
- { -2383, 3657, -649, 576 },
- { -3541, -161, -1389, 2550 },
- { -4241, 1575, 1325, 2561 },
- { -2767, 4037, 1221, 1578 },
- { -3748, 2697, 1148, 1801 },
- { -4686, 2385, -220, 0 },
- { -1531, 1645, -2751, 1327 },
- { -45, 4032, -799, 2298 },
- { -2915, 2280, 709, 2495 },
- { -1199, 3278, -406, 2346 },
- { -2471, 116, -2706, 2060 },
- { -2440, 2173, -2894, -344 },
- { -3375, 2287, 1781, 3226 },
- { -2153, 3568, 1827, 2918 },
- { -862, 2267, -1626, 2527 },
- { -2698, 1135, 301, 4239 },
- { -2364, 2123, 1010, 3710 },
- { -2447, 3281, -81, 1408 },
- { -2660, 4735, 472, 258 },
- { -1053, 3097, 2682, 2398 },
- { -3366, -1037, -1152, -868 },
- { -643, 4242, 2212, 1259 },
- { 971, 3991, 934, 643 },
- { -1617, 2002, 2139, 2195 },
- { -4897, 972, 784, 1719 },
- { -1275, 2992, 1039, 3821 },
- { -392, 4973, -209, 1821 },
- { -1028, 4718, -1479, -137 },
- { 50, 3914, 553, 2210 },
- { 678, 4364, 359, 1303 },
- { -582, 4911, 514, 1671 },
- { 1276, 3914, -1252, 2934 },
- { -1496, 3984, 857, 2330 },
- { 772, 4744, -655, 2332 },
- { -799, 5283, -439, 624 },
- { 1341, 2937, 650, 2027 },
- { -1739, 4892, 1275, 1702 },
- { -892, 2596, -151, 3951 },
- { -3532, 1090, 1292, 32 },
- { 321, 3146, 2647, 1475 },
- { 264, 4199, -1591, 1317 },
- { -452, -2357, 2266, 4192 },
- { 3022, -1033, -2389, 5678 },
- { -1162, -1342, 3543, 4990 },
- { -474, -1477, -1223, 5016 },
- { -699, -2857, 900, 3835 },
- { -461, -2255, -117, 4626 },
- { 1204, -2062, -1211, 4403 },
- { 2192, -3035, -337, 3966 },
- { 108, -831, 279, 5643 },
- { 1457, -620, -2908, 5276 },
- { -2527, -78, 1085, 5460 },
- { -1978, -1918, -949, 4733 },
- { 32, 367, -1904, 5166 },
- { 1890, -1665, 440, 4752 },
- { -518, -348, 2816, 4891 },
- { 3695, -2490, -1374, 4603 },
- { 246, -1965, 3549, 3969 },
- { 1100, -3111, 656, 3737 },
- { -1379, 870, -414, 4575 },
- { 628, -357, -1227, 6179 },
- { -1129, -1318, -2457, 4576 },
- { -425, -98, -73, 6336 },
- { 367, -887, 2990, 4207 },
- { 2091, -1251, 2444, 3557 },
- { -1759, -1610, 2046, 5273 },
- { 3210, 1414, -20, 2616 },
- { 3303, -2636, 1005, 4237 },
- { -327, -3107, -640, 3687 },
- { -197, 764, 572, 5486 },
- { 646, -767, 1388, 5464 },
- { 104, 2742, -228, 3907 },
- { -236, 1829, -579, 4585 },
- { -2150, -474, -1525, 4006 },
- { -23, -2632, -2400, 3892 },
- { -12, -1739, -2910, 4867 },
- { -2310, -368, -102, 4583 },
- { -1991, -2061, 533, 4531 },
- { 3884, -1446, -153, 4393 },
- { 1568, 14, -289, 5268 },
- { -1376, -253, -2797, 3417 },
- { 3193, -2577, 2475, 3566 },
- { 3418, 617, 1350, 1857 },
- { 3792, -24, -272, 3370 },
- { 153, 1159, 2906, 2877 },
- { 511, 2162, 1548, 2741 },
- { 262, 819, -2791, 3734 },
- { 4232, -2015, 1486, 3477 },
- { 2943, -1110, -1014, 5480 },
- { 2842, 369, 703, 3476 },
- { 3011, 1634, -933, 3553 },
- { 4412, -1548, -942, 5021 },
- { -1405, 593, 2372, 5267 },
- { 2093, 2129, 896, 2365 },
- { 4845, -1980, 0, 3823 },
- { -2140, 81, 3278, 5637 },
- { 1484, 2665, -324, 3653 },
- { 10, 192, 1620, 5291 },
- { 2152, 738, -2269, 5000 },
- { 2102, 2748, -1652, 4707 },
- { 2855, -2131, -387, 5188 },
- { 1173, 676, 1338, 3277 },
- { 2340, -2329, -2064, 4095 },
- { 861, -2024, 1296, 5055 },
- { 2189, 3225, -695, 2626 },
- { 6196, -7079, 1943, -822 },
- { 4547, -4813, 3261, 1856 },
- { 4243, -6904, 3443, 448 },
- { 4581, -7503, 946, 506 },
- { 6626, -7754, 3427, 470 },
- { 3407, -9088, 3269, -1496 },
- { 4079, -6464, 2304, 777 },
- { 5621, -9336, 2684, -768 },
- { 5351, -6464, 5238, -214 },
- { 5961, -8007, 1724, -3091 },
- { 4213, -8067, 603, -246 },
- { 7208, -7403, 3168, -1738 },
- { 6098, -7700, 329, -1379 },
- { 6525, -6735, 4248, -1072 },
- { 6073, -6241, 2167, -2378 },
- { 4609, -9218, 3051, -1033 },
- { 6813, -7283, 1581, -1897 },
- { 6126, -6275, 2789, 681 },
- { 4423, -6538, 1621, -1692 },
- { 6272, -8298, 3167, -1855 },
- { 6172, -8558, 4498, -1169 },
- { 4844, -8588, 1647, -366 },
- { 6209, -8807, 1581, -369 },
- { 5389, -8059, 550, -192 },
- { 6654, -9775, 2504, -1063 },
- { 7103, -7998, 806, 530 },
- { 5662, -6736, 1565, -3620 },
- { 4165, -9564, 4191, -2131 },
- { 4526, -7181, 576, -2875 },
- { 4633, -8623, 2807, -4742 },
- { 3709, -7794, 1815, 34 },
- { 3634, -8622, 2313, -826 },
- { 6991, -8447, 2063, -3198 },
- { 7757, -9486, 2255, -558 },
- { 4149, -7778, 4728, -1696 },
- { 5767, -7427, 1113, 707 },
- { 4592, -6261, 2329, 1864 },
- { 3159, -10498, 1677, -4273 },
- { 3534, -9010, 2437, -3565 },
- { 4479, -10821, 2715, -4942 },
- { 3207, -9805, 3054, -3886 },
- { 4627, -8189, 3018, -2354 },
- { 5527, -10566, 3244, -2749 },
- { 4346, -10127, 3335, -3084 },
- { 6132, -10085, 3316, -1308 },
- { 5629, -9704, 2178, -3058 },
- { 3603, -8538, 1246, -624 },
- { 3737, -8488, 395, -3167 },
- { 5465, -11414, 2810, -4640 },
- { 5306, -7745, 2721, -3988 },
- { 7000, -9111, 1695, -1409 },
- { 6663, -7741, 2466, -4079 },
- { 4083, -7175, 1836, -4831 },
- { 3613, -9926, 1342, -3455 },
- { 6588, -8033, 457, -258 },
- { 4720, -8102, 17, -1209 },
- { 7414, -8709, 1294, -344 },
- { 5437, -10030, 4043, -1704 },
- { 4862, -9281, 1558, -1431 },
- { 6800, -6403, 5113, 862 },
- { 4623, -8242, 2667, -228 },
- { 5919, -5083, 3348, 2135 },
- { 5985, -8889, 2733, -5105 },
- { 5029, -5767, 4407, 719 },
- { 354, -6158, -838, -3001 },
- { 351, -5943, -2104, -1534 },
- { -633, -7190, -25, -4798 },
- { -1595, -7235, -3812, -1400 },
- { 103, -6197, -2933, -78 },
- { -1722, -5020, -3441, -4333 },
- { -1963, -5644, -4365, -270 },
- { -846, -5743, -3477, 196 },
- { -191, -5348, -4054, -469 },
- { -2515, -7754, -3495, -818 },
- { -2090, -6710, -2701, 117 },
- { -546, -7036, -1398, 163 },
- { -278, -7091, -2662, -536 },
- { -622, -7962, -2731, -1464 },
- { -1555, -8118, -3612, -2057 },
- { -1094, -6280, -2314, 505 },
- { -2556, -8538, -4024, -2247 },
- { 109, -7134, -3107, -1823 },
- { -900, -6954, -3340, -717 },
- { -605, -7113, -3656, -2154 },
- { 837, -6263, -3211, -2177 },
- { -417, -5810, -3871, -1469 },
- { -1318, -5649, -4207, -3198 },
- { 413, -6765, -2082, -33 },
- { -3101, -6450, -4362, -766 },
- { 755, -6489, -2967, -846 },
- { 1117, -7106, -2452, -1352 },
- { -1202, -8387, -3072, -2897 },
- { -365, -4894, -3561, -2937 },
- { -2372, -8776, -265, -4441 },
- { -1224, -8678, -896, -5074 },
- { -755, -10096, -600, -6623 },
- { 300, -8206, -225, -4568 },
- { -1176, -6824, -2633, -3527 },
- { -2006, -5443, -1526, -5849 },
- { -1115, -5540, -2363, -4785 },
- { 1059, -6812, -2543, -2654 },
- { -1976, -6861, -3062, -5508 },
- { -379, -5328, -2321, -3624 },
- { -2108, -5860, -4518, -1915 },
- { -379, -7885, -1329, -594 },
- { 774, -5389, -581, -5213 },
- { -2601, -5083, -1849, -4921 },
- { -176, -5580, 74, -5075 },
- { -204, -6780, -190, -6232 },
- { 418, -7594, -1987, -820 },
- { -1873, -8529, -2926, -1609 },
- { 1340, -6362, -919, -4975 },
- { 577, -7990, -2044, -1873 },
- { -2572, -7413, -1745, -2224 },
- { -2037, -7030, -1461, -7138 },
- { -2559, -8756, -2039, -5836 },
- { -2079, -6764, -1209, -5669 },
- { -1613, -7801, -2006, -685 },
- { -1865, -6583, -722, -3529 },
- { -589, -6358, -1377, -1003 },
- { -540, -7514, -1331, -3542 },
- { 419, -6192, -1677, -4927 },
- { -2786, -8763, -2966, -5065 },
- { -2172, -8411, -1726, -4675 },
- { -3382, -9833, -3497, -5722 },
- { -2433, -10169, -2077, -5775 },
- { -424, -9451, -1096, -3658 },
- { -537, -8522, -910, -1897 },
- { -5550, 2807, 1683, -693 },
- { -6395, 635, 3573, -1246 },
- { -7544, 2280, 2140, 44 },
- { -8751, 1136, 2951, -794 },
- { -5605, 2709, 2052, 916 },
- { -7650, 654, 869, 135 },
- { -6939, 967, 1409, 870 },
- { -7834, 2123, 3310, 974 },
- { -6935, 2818, 1274, -1678 },
- { -5605, 2233, 1013, 471 },
- { -7095, 1849, 1648, 198 },
- { -6636, 1634, 712, -37 },
- { -7279, 978, 296, -315 },
- { -7664, 3504, 3292, -216 },
- { -7836, 1209, 1221, -257 },
- { -7913, 2201, 1765, -1529 },
- { -7077, 3783, 2632, -1407 },
- { -5565, 1645, 1410, -622 },
- { -6494, 2879, 1181, -759 },
- { -7073, 3137, 3010, 550 },
- { -7249, 1839, 847, -805 },
- { -6630, 2197, 282, -1096 },
- { -8836, 1573, 1988, -1090 },
- { -7809, 1274, 836, -1198 },
- { -7895, 2970, 3511, -1097 },
- { -6960, 1664, 1356, -2442 },
- { -6582, 2866, 2273, 307 },
- { -7221, 821, 2851, -1435 },
- { -6015, 1703, 2001, -2367 },
- { -8082, 1034, 2103, 239 },
- { -5952, 1912, 301, -465 },
- { -6099, 841, 379, 567 },
- { -6343, 50, 494, 658 },
- { -6586, 983, 591, -893 },
- { -5500, 869, 2187, -2479 },
- { -6482, 60, 1545, -979 },
- { -6705, 515, 1974, -53 },
- { -6460, 1755, 1325, -1275 },
- { -6093, 2617, 2465, -623 },
- { -7330, 2161, 594, -2115 },
- { -7324, 762, 1593, -2004 },
- { -6385, 679, 1510, -2514 },
- { -6159, 241, 2976, -1631 },
- { -8583, 3030, 4045, -162 },
- { -6299, 66, 2209, -2103 },
- { -5428, 1279, 3267, -1846 },
- { -6438, 1335, 2728, -1631 },
- { -8012, 1070, 2428, -1151 },
- { -6201, 2781, 2349, -1918 },
- { -5918, 1139, 3121, -148 },
- { -6314, 2481, 3137, -1808 },
- { -7180, 1722, 2435, -1602 },
- { -6750, 1829, 3763, -1145 },
- { -6713, 1777, 2221, 1212 },
- { -7479, 1835, 3627, -479 },
- { -7299, 10, 2406, -1593 },
- { -8249, 3129, 996, -2870 },
- { -8374, 1534, 1333, -1882 },
- { -7507, 3353, 1598, -2299 },
- { -7379, 2701, 2326, -1167 },
- { -8440, 2276, 2796, -542 },
- { -10348, 1527, 2649, -1165 },
- { -8184, 3614, 2574, -1738 },
- { -5539, 1574, 1733, 1138 },
- { 9404, -7652, 67, 79 },
- { 8654, -3972, 1358, -60 },
- { 8617, -4794, 117, 2318 },
- { 7886, -4505, 1784, 1200 },
- { 8636, -6125, 3879, -1003 },
- { 9654, -6836, 1816, 205 },
- { 9374, -6553, 913, 1875 },
- { 8020, -6150, 1134, 2390 },
- { 7786, -4970, 2078, -1857 },
- { 8691, -6119, 711, 708 },
- { 9039, -5568, 2944, -1902 },
- { 9955, -5048, 1433, -601 },
- { 8089, -6927, 3093, -2846 },
- { 8487, -7024, 2415, 19 },
- { 9388, -5287, 3577, -2655 },
- { 8591, -7371, 2300, -996 },
- { 9104, -4763, 1453, -2558 },
- { 7615, -5457, 596, 164 },
- { 9860, -7047, 3433, -614 },
- { 8756, -4404, 2235, -964 },
- { 9462, -4660, 299, -1822 },
- { 10119, -5550, 2689, -1273 },
- { 10915, -7471, 2705, -1007 },
- { 11433, -7090, 1410, -1198 },
- { 9882, -7431, 2965, -1895 },
- { 7628, -5219, 769, -2661 },
- { 8169, -5318, 2262, 70 },
- { 8846, -6320, 1939, -754 },
- { 7147, -5593, 1248, -971 },
- { 10652, -5485, 935, 137 },
- { 7778, -6533, 2564, -1932 },
- { 8878, -5173, 1214, -361 },
- { 9828, -4943, 282, 510 },
- { 10042, -6134, 3895, -1914 },
- { 7965, -6630, 3566, -433 },
- { 8573, -4502, 3574, -1209 },
- { 8398, -4801, 1031, -1347 },
- { 10136, -7772, 2612, 1547 },
- { 9890, -7280, 1768, -1083 },
- { 8407, -6585, -706, -58 },
- { 7976, -7582, 229, -131 },
- { 10481, -8866, 1166, -147 },
- { 10914, -4342, 3189, -2412 },
- { 10440, -5198, -104, -1109 },
- { 11227, -6530, 2381, -2449 },
- { 8487, -8064, 1086, 230 },
- { 9975, -6123, -857, -134 },
- { 8339, -6498, 1232, -2337 },
- { 11042, -4506, 1119, -2098 },
- { 12563, -5592, 1837, -2062 },
- { 11801, -5590, 632, -1296 },
- { 10152, -5617, 1511, -1917 },
- { 7800, -6473, 51, -1337 },
- { 7941, -5560, 2438, -3270 },
- { 6554, -3834, 2100, 1476 },
- { 9065, -5520, -226, -1120 },
- { 10794, -7120, -243, 122 },
- { 10429, -6968, 272, -806 },
- { 8942, -8914, 1442, -392 },
- { 9969, -5051, 2033, -2953 },
- { 7275, -4152, 3058, -64 },
- { 11127, -5488, 4589, -3227 },
- { 9626, -6666, 2739, -2958 },
- { 6943, -5362, 4470, 1008 },
- { -7456, -967, 2936, -1002 },
- { -8622, -333, 6962, 2606 },
- { -7486, -3392, 3668, 1287 },
- { -8053, -827, 5148, 1097 },
- { -6610, 454, 4952, 96 },
- { -7701, -1982, 3161, -468 },
- { -7307, -1132, 4071, -36 },
- { -8125, -271, 5199, 3862 },
- { -9182, -1950, 2813, 1878 },
- { -9855, -952, 4794, 3010 },
- { -7241, 1431, 4202, 2468 },
- { -9646, 157, 4766, 1046 },
- { -9371, 1230, 6009, 2958 },
- { -11514, -64, 8630, 5248 },
- { -6766, 565, 2766, 2140 },
- { -8426, -9, 2852, 1271 },
- { -11291, -1113, 5087, 2937 },
- { -8297, 2092, 4495, 1264 },
- { -9983, 735, 3809, -51 },
- { -9048, -1000, 3191, -308 },
- { -7331, -1987, 2655, 1391 },
- { -7144, -21, 4333, 2161 },
- { -6032, -1540, 3543, 896 },
- { -7987, -1036, 1985, 1529 },
- { -9264, 2004, 5194, 290 },
- { -11308, -840, 5754, 1654 },
- { -9130, -2398, 4292, 2973 },
- { -6248, 838, 3563, 1223 },
- { -6819, -2760, 3511, 119 },
- { -7213, -2006, 4364, 762 },
- { -5431, -1047, 4533, 166 },
- { -7098, -641, 2021, 639 },
- { -8628, -2249, 3588, 399 },
- { -6352, -1498, 3560, -648 },
- { -7033, -2190, 4870, 2562 },
- { -7405, -46, 3772, -581 },
- { -6104, 796, 5143, 1965 },
- { -5787, 943, 5784, 3030 },
- { -8367, 1465, 7192, 4097 },
- { -8259, 789, 5694, 1963 },
- { -10614, -1899, 5748, 2645 },
- { -8258, -805, 3698, 2275 },
- { -6877, -972, 6431, 3160 },
- { -6483, 363, 7018, 3129 },
- { -6283, -1358, 5191, 1524 },
- { -8853, -3157, 4119, 1741 },
- { -6086, -267, 3883, -835 },
- { -7254, 1032, 6613, 4017 },
- { -11470, -3350, 4649, 3426 },
- { -6743, 481, 6148, 1239 },
- { -5394, -166, 5309, 3165 },
- { -7958, 1068, 4268, -240 },
- { -10520, 2256, 7916, 2828 },
- { -5132, -4, 5739, 1176 },
- { -8643, 120, 3255, -629 },
- { -9631, 1974, 8870, 4362 },
- { -10663, -1221, 3733, 589 },
- { -8224, -1843, 5806, 2655 },
- { -8282, 1255, 8647, 3478 },
- { -12311, -1505, 9043, 6256 },
- { -11312, -856, 7136, 4681 },
- { -11944, -722, 7941, 3309 },
- { -7868, -463, 6846, 4196 },
- { -8679, -241, 7410, 5347 },
- { 6759, -4680, -508, 1220 },
- { 5176, -6111, 944, 121 },
- { 6843, -5667, -1368, -533 },
- { 5616, -5884, -1471, -695 },
- { 6030, -5089, -1808, -940 },
- { 7444, -5463, -52, 1881 },
- { 4207, -6079, -506, 1571 },
- { 6785, -4410, -649, 3084 },
- { 4838, -5214, 2026, 2998 },
- { 4201, -5790, 645, 1811 },
- { 6930, -5129, -1940, 1698 },
- { 6332, -4627, 692, 3027 },
- { 6285, -4314, -106, 3644 },
- { 6255, -5450, -1975, 742 },
- { 4199, -4676, -459, 1796 },
- { 5592, -5500, 1345, 1300 },
- { 4358, -5556, -2236, 114 },
- { 4620, -5875, -1563, 888 },
- { 4892, -7550, -327, -419 },
- { 4734, -7085, 7, 613 },
- { 3883, -5562, -1969, 1080 },
- { 5610, -4990, -204, 834 },
- { 4117, -6482, -1271, 341 },
- { 6585, -5107, 892, 1169 },
- { 6632, -3683, 302, 3002 },
- { 6326, -5351, -983, -1250 },
- { 4382, -7192, -730, -158 },
- { 5227, -6540, -451, 1123 },
- { 5468, -6472, -870, -1471 },
- { 5191, -6402, -1365, -127 },
- { 7407, -6317, -973, -336 },
- { 4611, -6530, -820, -1980 },
- { 4963, -5159, -2050, -966 },
- { 4414, -5691, -211, -998 },
- { 5954, -5873, 750, -1749 },
- { 4394, -4796, -1268, 254 },
- { 7161, -6214, -1010, 689 },
- { 4965, -3598, 2372, 1711 },
- { 6248, -6180, 981, 864 },
- { 6473, -5336, 525, -600 },
- { 4591, -6864, -1131, -900 },
- { 6314, -6440, -1021, -375 },
- { 5838, -6209, -1199, 944 },
- { 5308, -5283, -2100, 1267 },
- { 4342, -5860, -1637, -1356 },
- { 5680, -4388, -1227, -104 },
- { 4900, -4098, 1449, 4046 },
- { 4677, -4284, -106, 3190 },
- { 7574, -6173, -848, 1859 },
- { 6493, -7207, -131, 726 },
- { 5513, -5261, -2117, 4 },
- { 6191, -7352, -193, -505 },
- { 5885, -4333, 324, -134 },
- { 6162, -6081, -312, -2044 },
- { 4216, -6200, -1810, -572 },
- { 5652, -7035, -696, -197 },
- { 7131, -7189, -366, -60 },
- { 5032, -4803, -1514, 2832 },
- { 7386, -4610, -606, 3489 },
- { 4211, -5031, 1221, 3047 },
- { 4050, -4653, 1584, 1469 },
- { 6852, -5302, -1861, 206 },
- { 7736, -4816, -1794, 3359 },
- { 6290, -3439, 1522, 2454 },
- { 1768, 5990, -5560, -2594 },
- { 3903, 5326, -1530, -1501 },
- { 2472, 3738, -2117, -4240 },
- { 3260, 5448, -904, -4733 },
- { 1435, 7297, -3676, -4102 },
- { 4096, 5951, -656, -3312 },
- { 2178, 6009, -3146, -3724 },
- { 3787, 5493, -5473, -1633 },
- { 2998, 7286, -3334, -3571 },
- { 2894, 6576, -4708, -2804 },
- { 830, 6163, -4286, -3348 },
- { 4755, 5569, -1730, -2739 },
- { 4604, 6065, -3562, -2605 },
- { 2749, 5141, -3986, -2775 },
- { 3942, 4875, -2143, -3340 },
- { 2819, 8517, -2004, -2724 },
- { 2146, 6298, -689, -3093 },
- { 5196, 6504, -3393, -1475 },
- { 1851, 8386, -1748, -1420 },
- { 3474, 8572, -3534, -2688 },
- { 4503, 7560, -3561, -2245 },
- { 4433, 6219, -2393, -1575 },
- { 3506, 7248, -2275, -1977 },
- { 3490, 7409, -3147, -604 },
- { 4214, 6447, -3520, 516 },
- { 619, 7034, -829, -1705 },
- { 1732, 7395, -356, -2208 },
- { 1226, 5204, -3294, -3732 },
- { 2027, 5619, -1813, -4146 },
- { 3078, 5877, 47, -2651 },
- { 1654, 5458, 424, -682 },
- { 3163, 5464, -2026, -270 },
- { 2884, 5375, -685, -530 },
- { 2950, 7286, -35, -2967 },
- { 1986, 5066, -597, 482 },
- { 3459, 4308, -3845, -2333 },
- { 3155, 7037, -1346, -4345 },
- { 2193, 6696, -717, -1319 },
- { 3677, 5089, -3892, -487 },
- { 2186, 5136, -4186, -1492 },
- { 773, 5796, -917, 817 },
- { 2489, 6546, -3570, -2117 },
- { 1223, 6469, -1362, -33 },
- { 271, 6061, -1466, -1725 },
- { 2540, 5171, -1847, 1032 },
- { 2548, 5251, -2697, 1677 },
- { 771, 7600, -768, -632 },
- { 4710, 6647, -4736, -1275 },
- { 1369, 5917, -2971, -1056 },
- { 163, 5239, -3499, -2275 },
- { 2104, 4285, -3211, -3286 },
- { 1107, 7411, -1972, -1671 },
- { 2196, 7262, -2310, -1926 },
- { -244, 6439, -1745, -839 },
- { 3293, 3832, -2890, -3000 },
- { 419, 6443, -379, -407 },
- { 3077, 4930, -1156, -2869 },
- { 2131, 5874, -2330, 224 },
- { 690, 6538, -2212, -2841 },
- { 1602, 4421, -2515, 1542 },
- { 3318, 9373, -3032, -3477 },
- { 5646, 7462, -5153, -1463 },
- { 4139, 7137, -1539, -3321 },
- { 3481, 9077, -1645, -3653 },
- { -7747, 375, -106, -543 },
- { -8587, -1379, -586, -461 },
- { -10146, -892, 2094, 694 },
- { -8103, 382, 504, -325 },
- { -8548, -92, 94, -656 },
- { -7460, 38, 152, 388 },
- { -8266, -271, -459, -883 },
- { -7935, -664, -1026, -802 },
- { -8341, -109, 853, 161 },
- { -8802, -1355, 1099, 630 },
- { -8957, -6, 1108, -669 },
- { -7260, -1520, -43, -407 },
- { -7555, -174, 668, -2562 },
- { -9014, -126, 227, -1191 },
- { -8184, 769, 290, -1375 },
- { -9476, 55, 962, -1528 },
- { -8679, 541, 755, -1030 },
- { -9842, -1626, 838, -1588 },
- { -8513, -702, 788, -1998 },
- { -10101, -1558, -366, -1841 },
- { -8135, 78, 1479, -1813 },
- { -9128, -454, 313, -1786 },
- { -7554, -1084, 831, -2442 },
- { -7576, -701, 2068, -1665 },
- { -7791, -1481, 1587, -1808 },
- { -6701, -596, -97, 802 },
- { -7418, -15, 684, -963 },
- { -7127, -477, -139, -426 },
- { -8097, -110, -36, -264 },
- { -7620, -1922, -590, -101 },
- { -7647, -1201, 279, 660 },
- { -7856, -1974, 758, -2271 },
- { -8496, -167, 2232, -1143 },
- { -8506, -1359, 624, -740 },
- { -7274, -1052, 1062, -139 },
- { -7800, -217, 91, -1794 },
- { -7030, -1694, -955, 615 },
- { -9020, -1864, 101, -2182 },
- { -9400, -740, 598, -667 },
- { -8448, -1184, 2024, -1272 },
- { -8812, -570, -897, -2384 },
- { -10559, -1286, 538, -1536 },
- { -8728, -888, -1089, -1397 },
- { -7080, -1185, 636, -1252 },
- { -9880, 233, 2344, -782 },
- { -7952, -1326, -378, -1947 },
- { -7207, -378, 1408, -2237 },
- { -8467, -1545, 902, -1987 },
- { -9163, -1474, 924, -1739 },
- { -8159, -992, -77, -2744 },
- { -8343, 148, -423, -1573 },
- { -9105, -649, -254, -1214 },
- { -8939, 456, 281, -1905 },
- { -8837, 179, -394, -2634 },
- { -9145, 757, 1547, -1319 },
- { -9775, -723, 441, -1680 },
- { -8910, -686, 1529, -1525 },
- { -9492, -1134, 2064, -938 },
- { -6111, -943, 677, -31 },
- { -7411, -613, -814, 46 },
- { -9479, -922, -430, -2061 },
- { -11298, -1268, 1318, -1117 },
- { -8190, 832, 671, -2214 },
- { -10453, -550, 1672, -886 },
- { 1044, 9353, -1651, -5423 },
- { 1034, 8149, -455, -6166 },
- { 761, 8293, -3214, -4838 },
- { 938, 8077, 164, -5130 },
- { 1295, 8673, 2582, -5490 },
- { -314, 7973, -2395, -5231 },
- { -507, 9012, -2497, -5775 },
- { 2396, 8314, -1022, -4673 },
- { -1516, 8501, 1950, -4969 },
- { -308, 7401, 1549, -4866 },
- { -112, 8340, 3003, -4920 },
- { -50, 9315, 1371, -5666 },
- { -659, 9449, 2496, -5547 },
- { 2573, 9148, -2270, -4783 },
- { 830, 7104, -438, -3907 },
- { 522, 10672, -677, -6483 },
- { -1190, 10108, -510, -6518 },
- { -427, 8271, -579, -6315 },
- { 1602, 8113, -1927, -4418 },
- { -2266, 8180, 448, -5190 },
- { -1633, 8816, -226, -5771 },
- { 759, 9481, -105, -5813 },
- { 2254, 6679, -466, -5662 },
- { -88, 6946, 895, -5958 },
- { -1705, 10009, 1394, -5574 },
- { 748, 7943, 540, -6692 },
- { 1411, 7009, 232, -6145 },
- { 697, 7290, -1221, -5342 },
- { -1764, 10580, 1944, -3981 },
- { -1334, 9124, 1195, -3903 },
- { -905, 10067, 635, -5039 },
- { 664, 10680, 49, -4625 },
- { 1374, 9536, -777, -3591 },
- { 252, 9698, -597, -2931 },
- { 824, 9164, -1014, -2144 },
- { 2438, 10569, -2289, -4424 },
- { 2101, 7102, 507, -3614 },
- { 294, 8051, -432, -1518 },
- { -665, 10337, 547, -2852 },
- { 1168, 11989, -492, -5427 },
- { 1344, 6416, 302, -5061 },
- { -1727, 12264, 1507, -4543 },
- { 674, 10889, -902, -3605 },
- { -582, 9504, 300, -3618 },
- { 641, 7654, 689, -2109 },
- { 2065, 9243, 508, -4367 },
- { 1055, 8373, 688, -3144 },
- { -641, 8185, 986, -3307 },
- { 1120, 7426, 1785, -3757 },
- { 1660, 8070, -593, -3104 },
- { 2002, 9467, -1722, -3475 },
- { 2361, 8368, 100, -3709 },
- { -772, 7845, -613, -4988 },
- { 1485, 7430, 1896, -6127 },
- { -432, 7823, -947, -2882 },
- { 313, 11122, -760, -4871 },
- { 412, 8412, -283, -4231 },
- { 1585, 10402, -1884, -3267 },
- { 321, 6952, 773, -3016 },
- { -105, 9014, 121, -2249 },
- { 1585, 10313, -977, -4812 },
- { 1619, 11869, 1306, -6876 },
- { -1168, 8886, -81, -2500 },
- { -395, 10886, 733, -6490 },
- { -4949, 4274, 3992, -1054 },
- { -4241, 5299, 4262, -1584 },
- { -2710, 3862, 4552, -1673 },
- { -4608, 2472, 3672, -1715 },
- { -2843, 2816, 4003, -2326 },
- { -5229, 2964, 5636, 90 },
- { -4924, 3442, 5015, -1096 },
- { -1281, 3313, 5537, -2066 },
- { -3808, 1939, 4351, -919 },
- { -1915, 2585, 4939, -1614 },
- { -3470, 1843, 5562, -682 },
- { -3800, 870, 5827, 144 },
- { -4985, 1452, 4728, -709 },
- { -3745, 2750, 7220, 259 },
- { -1875, 1900, 6514, -826 },
- { -4329, 1574, 7192, 1304 },
- { -5408, 1444, 6208, 631 },
- { -3327, 5312, 5707, -1541 },
- { -6966, 3334, 4034, 1028 },
- { -7484, 4245, 4218, -212 },
- { -6567, 5839, 4539, -512 },
- { -5715, 5935, 3747, -1186 },
- { -6410, 4881, 3356, -1610 },
- { -5146, 2590, 2850, 2172 },
- { -5196, 4095, 2569, -373 },
- { -5043, 6025, 4318, 692 },
- { -5525, 4884, 3513, 370 },
- { -6804, 7533, 5812, -488 },
- { -5657, 2480, 4061, 1234 },
- { -3155, 1472, 6071, 1188 },
- { -3427, 5217, 3442, 858 },
- { -4698, 3013, 5517, 2586 },
- { -4449, 2226, 5418, 3580 },
- { -6395, 3547, 5487, 2028 },
- { -3500, 5019, 4787, 1 },
- { -4038, 2578, 3073, 3151 },
- { -2750, 1955, 4469, 3856 },
- { -5696, 1659, 6118, 2469 },
- { -4350, 1241, 6840, 3126 },
- { -5565, 5058, 5196, 1314 },
- { -1642, 4190, 3948, 607 },
- { -1233, 4108, 4850, -640 },
- { -997, 3428, 3239, 1378 },
- { -6488, 2741, 6926, 2792 },
- { -4188, 3763, 4235, 2018 },
- { -3210, 3224, 5646, 1427 },
- { -5526, 6909, 5070, -627 },
- { -2815, 3994, 3425, 1903 },
- { -2163, 2734, 5423, 145 },
- { -4149, 4247, 2355, 734 },
- { -410, 2521, 4138, -16 },
- { -2411, 2385, 4927, 2105 },
- { -6077, 3591, 3114, 594 },
- { -4186, 4834, 5926, -1004 },
- { -7315, 3369, 5966, 448 },
- { -7042, 5721, 5771, 238 },
- { -4466, 3907, 3535, -1751 },
- { -2116, 3970, 6163, -1392 },
- { -7239, 2143, 8407, 3630 },
- { -5431, 4486, 6486, -42 },
- { -1874, 1617, 6333, 519 },
- { -6478, 2629, 4634, -505 },
- { -7784, 2342, 7216, 1365 },
- { -1154, 1432, 4831, 1544 },
- { -4964, -5801, 1797, 506 },
- { -4436, -6905, 1059, -1237 },
- { -5400, -6886, 884, -290 },
- { -6259, -7103, 523, -227 },
- { -4819, -6450, 1412, -450 },
- { -4056, -6213, 1725, -943 },
- { -5642, -6091, 1357, 605 },
- { -4196, -5678, 2187, -173 },
- { -4726, -5126, 2470, 321 },
- { -6642, -5091, 1507, -1005 },
- { -5304, -5250, 1944, 1579 },
- { -7179, -5520, 1468, -425 },
- { -6033, -4895, 1876, -955 },
- { -6595, -5143, 2207, 1291 },
- { -4224, -4943, 1846, 1792 },
- { -7128, -6950, 539, 724 },
- { -4369, -4901, 2590, 1103 },
- { -7413, -5696, 1712, 1440 },
- { -5885, -6821, 418, 871 },
- { -6828, -5599, 710, -1563 },
- { -6123, -5817, 1358, 1631 },
- { -5291, -5622, 578, 2138 },
- { -7171, -6004, 347, 2208 },
- { -6083, -5251, 2132, 425 },
- { -4329, -5721, 407, -2993 },
- { -5326, -5056, 1119, -1837 },
- { -5485, -5856, 185, -2389 },
- { -6529, -5178, 403, -697 },
- { -6719, -4412, 2726, 871 },
- { -5126, -5629, 1835, -771 },
- { -5622, -4361, 2973, 858 },
- { -5282, -5895, 45, -335 },
- { -4357, -5656, 1696, -1558 },
- { -7139, -6659, 627, -409 },
- { -4415, -6328, 35, 1306 },
- { -7639, -6110, 1134, 197 },
- { -3626, -5592, 2019, 901 },
- { -3547, -5064, 1176, 1738 },
- { -5075, -3899, 2087, 266 },
- { -4086, -6311, 1479, 360 },
- { -6210, -5220, -199, -1477 },
- { -3910, -5063, 1356, -15 },
- { -7616, -4977, 461, 2401 },
- { -6118, -6131, 1258, -563 },
- { -6127, -4968, 1286, -27 },
- { -4121, -5852, 1113, 1476 },
- { -5157, -4881, 1162, -662 },
- { -4637, -5031, 1179, 709 },
- { -5509, -5452, -397, 1224 },
- { -4597, -6861, 646, 467 },
- { -6247, -4043, 468, 278 },
- { -5336, -6465, 874, -1472 },
- { -6998, -6346, 78, -1798 },
- { -4915, -4530, 2756, -203 },
- { -6048, -4373, 1468, 1052 },
- { -4273, -7100, 942, -323 },
- { -6552, -4287, 2351, 69 },
- { -6954, -4613, 722, 1521 },
- { -4201, -5361, 763, -1562 },
- { -6881, -5596, -748, 669 },
- { -6695, -3547, -34, 1299 },
- { -3981, -5728, 84, 111 },
- { -4663, -4809, 2173, -1031 },
- { -6599, -6077, 1303, 256 },
- { -7596, -4265, -5791, -4140 },
- { -6610, -2758, -5288, -3936 },
- { -5880, -3865, -6563, -3088 },
- { -7228, -5510, -7677, -3912 },
- { -8854, -6553, -8318, -5361 },
- { -9362, -5249, -6413, -4319 },
- { -4418, -3110, -6368, -4358 },
- { -5544, -4203, -6863, -5013 },
- { -3056, -4316, -5567, -3181 },
- { -3078, -5999, -5051, -2657 },
- { -5884, -6292, -5756, -4013 },
- { -4825, -4549, -5535, -4053 },
- { -4443, -6126, -5316, -1368 },
- { -3972, -6341, -6098, -2686 },
- { -5751, -2781, -5398, -6230 },
- { -4466, -6135, -5570, -3679 },
- { -4291, -5992, -3564, -5189 },
- { -7189, -4429, -7279, -6082 },
- { -5076, -4433, -2748, -5366 },
- { -6225, -2825, -6833, -5663 },
- { -2989, -4792, -3960, -4492 },
- { -7836, -7773, -7722, -5741 },
- { -6559, -5703, -5844, -5589 },
- { -7612, -5438, -4136, -3774 },
- { -4218, -4176, -6591, -2333 },
- { -4837, -5063, -6581, 322 },
- { -6590, -5990, -2980, -3847 },
- { -5558, -2971, -5489, -1932 },
- { -7001, -5323, -4975, -1697 },
- { -4694, -2688, -6904, -3044 },
- { -8511, -5379, -5767, -2549 },
- { -7548, -5412, -6522, -2572 },
- { -6597, -4973, -6423, -1274 },
- { -6415, -4022, -5168, -1072 },
- { -5528, -5530, -7218, -2345 },
- { -4845, -4805, -5943, -1227 },
- { -6049, -7150, -6744, -2161 },
- { -9061, -7299, -8542, -4375 },
- { -5010, -5546, -5416, -82 },
- { -4135, -4205, -5109, -3373 },
- { -3311, -5869, -4007, -5061 },
- { -5993, -6472, -3962, -4718 },
- { -2966, -5832, -2821, -6305 },
- { -4851, -5152, -2067, -3930 },
- { -3620, -4441, -3362, -5836 },
- { -4469, -5221, -4534, -5592 },
- { -4022, -6335, -4321, -6107 },
- { -4899, -4503, -3084, -3725 },
- { -4490, -8276, -4620, -6236 },
- { -6591, -4342, -7365, -4063 },
- { -6498, -5057, -5553, 485 },
- { -6060, -2714, -7093, -4144 },
- { -6199, -7774, -7094, -4057 },
- { -7536, -6424, -6415, -4265 },
- { -7439, -2454, -6348, -4827 },
- { -5333, -7565, -4417, -4639 },
- { -4353, -7103, -4197, -2689 },
- { -5229, -6549, -5129, -6804 },
- { -6129, -7701, -5236, -4836 },
- { -6797, -3983, -3884, -4406 },
- { -6624, -4467, -4745, -5052 },
- { -3324, -7596, -2720, -6553 },
- { -5473, -6284, -1704, -4511 },
- { -4131, -7263, -3180, -5196 },
- { -7116, -5565, -3469, 685 },
- { -6002, -6021, -3858, 576 },
- { -3144, -8203, -1291, -434 },
- { -6096, -7027, -4004, 1353 },
- { -3943, -7709, -2344, -36 },
- { -4510, -6767, -2642, 631 },
- { -3657, -11541, -2570, -3984 },
- { -5959, -8854, -1333, -867 },
- { -6699, -8866, -1606, -344 },
- { -3836, -7961, -2334, -2028 },
- { -3430, -8045, -3037, -672 },
- { -3868, -9184, -3635, -1819 },
- { -4258, -9060, -2621, -1008 },
- { -3595, -8693, -2022, -752 },
- { -4573, -8048, -3166, -2622 },
- { -4852, -7903, -1405, 256 },
- { -4591, -7057, -1560, 965 },
- { -6963, -7655, -980, 808 },
- { -5179, -6641, -3356, 1196 },
- { -7102, -6941, -2798, 2123 },
- { -6867, -5834, -3320, -770 },
- { -5977, -7369, -2500, -778 },
- { -6160, -6400, -934, -2543 },
- { -6741, -7608, -355, -1289 },
- { -6856, -6466, -1433, -1643 },
- { -4786, -6292, -4970, 376 },
- { -5407, -8866, -2255, -400 },
- { -3814, -6506, -1387, -3620 },
- { -4998, -6137, -1200, -4092 },
- { -5123, -9557, -2849, -1306 },
- { -4259, -6444, -4395, -338 },
- { -5221, -6810, -883, 1225 },
- { -6137, -6215, -2165, 554 },
- { -3895, -6557, -3176, -1829 },
- { -3886, -8188, -87, -954 },
- { -7243, -6707, -2216, -316 },
- { -5592, -7606, 85, -432 },
- { -3957, -7945, -504, -144 },
- { -4617, -7624, 218, -312 },
- { -4797, -8737, -844, -1051 },
- { -4478, -8516, -1401, -454 },
- { -4557, -7058, -302, -2332 },
- { -6623, -7736, -271, -50 },
- { -3157, -7532, -1111, -2207 },
- { -3590, -7300, -1271, 517 },
- { -4442, -7306, -507, 590 },
- { -6458, -7524, -2807, 666 },
- { -4991, -8466, -3363, -785 },
- { -7474, -7541, -1056, -1839 },
- { -7501, -8316, -938, -180 },
- { -5329, -7739, -579, -2341 },
- { -4549, -7063, -176, -3539 },
- { -5191, -8612, -1504, -4250 },
- { -3083, -7058, -2251, 32 },
- { -4003, -7043, -1093, -791 },
- { -5523, -8093, -678, -114 },
- { -3022, -10265, -2070, -3109 },
- { -3905, -6274, -182, -3652 },
- { -3269, -9217, -551, -2650 },
- { -3138, -9314, -1726, -1704 },
- { -4420, -10339, -1744, -3459 },
- { -4163, -8609, -2298, -4113 },
- { -5566, -6505, -1241, -463 },
- { -3130, -9746, -2352, -4884 },
- { -7825, -3439, 1451, -1468 },
- { -8451, -3318, 2360, -435 },
- { -8462, -4130, 1438, -1024 },
- { -9425, -4564, 1328, -689 },
- { -11014, -3202, 2278, 2080 },
- { -8269, -2761, -146, -440 },
- { -7497, -2618, -166, 413 },
- { -8250, -3060, 522, -2133 },
- { -8365, -5366, 1347, -451 },
- { -8589, -3979, 2943, 714 },
- { -8111, -2572, 1272, -1748 },
- { -7830, -5193, 605, -1484 },
- { -8119, -4736, 2141, 256 },
- { -7724, -4769, 1463, -812 },
- { -7363, -3911, 2540, 4 },
- { -7974, -3397, 2363, 1366 },
- { -7359, -4204, 1752, -958 },
- { -7622, -3505, 660, 916 },
- { -9934, -3665, 3165, 828 },
- { -8721, -4162, 62, 1718 },
- { -9433, -4768, 2722, 1234 },
- { -7960, -4496, 138, 1528 },
- { -8198, -3454, -443, 631 },
- { -7756, -2246, 655, 1137 },
- { -8841, -3145, 1113, 829 },
- { -7817, -3298, 1251, 230 },
- { -9413, -2733, 323, -1862 },
- { -9408, -4168, 1270, 1549 },
- { -9037, -3892, -942, 283 },
- { -8255, -3849, 1301, 1762 },
- { -9057, -3987, -41, -682 },
- { -9441, -4187, 2019, -111 },
- { -9740, -3178, 1602, -871 },
- { -8344, -2474, 1461, 1506 },
- { -9752, -2925, 1996, 1243 },
- { -9199, -3796, 180, 537 },
- { -9060, -2405, 1140, -1562 },
- { -9348, -2376, 309, -162 },
- { -10786, -3182, -5, -1500 },
- { -8142, -4540, -434, -826 },
- { -7528, -2341, 1104, -73 },
- { -9360, -2658, 3062, 56 },
- { -8267, -2335, 2000, -1193 },
- { -12169, -3154, 1287, -640 },
- { -11398, -2120, 946, -1163 },
- { -8940, -4559, 328, -1696 },
- { -11025, -4213, 2813, 840 },
- { -9224, -3581, 2224, 2039 },
- { -8943, -3337, 1248, -1298 },
- { -7900, -4042, 485, -2080 },
- { -9221, -1947, 2191, -880 },
- { -10762, -1800, 2516, -324 },
- { -10095, -2238, 981, -1335 },
- { -11908, -2808, 3255, 645 },
- { -10640, -4105, 1283, -595 },
- { -7663, -2863, 2467, -797 },
- { -10712, -3854, 3710, 1538 },
- { -10823, -2893, 1408, -801 },
- { -9874, -3832, 256, -1638 },
- { -10394, -3391, 2315, -94 },
- { -11525, -4079, 4153, 2122 },
- { -9546, -2088, 1541, 481 },
- { -8731, -2433, 1042, 2160 },
- { -7852, -3977, -1370, 1677 },
- { 7072, -3420, 1398, -1741 },
- { 6180, -1976, 1280, -3557 },
- { 7692, -1793, 2844, -1700 },
- { 8363, -1773, 3104, -2679 },
- { 9213, -3266, 3756, -3542 },
- { 9650, -2644, 1426, -1318 },
- { 7712, -2796, 3686, -1975 },
- { 7316, -3517, 2821, -622 },
- { 7434, -2594, 2305, -2264 },
- { 7237, -1797, 255, -3114 },
- { 8663, -1983, 1338, -3056 },
- { 6616, -952, 4059, -2652 },
- { 8823, -1327, 1362, -1356 },
- { 9938, -1722, 1287, -2362 },
- { 7207, -1057, 1913, -1315 },
- { 7508, -1585, 870, -1982 },
- { 8217, -3680, 1417, -3170 },
- { 8329, -2541, 1684, -585 },
- { 8062, -2335, 252, -2800 },
- { 8204, -4108, 3097, -2569 },
- { 7701, -3367, 576, -3008 },
- { 7350, -786, 2414, -2129 },
- { 6948, -2568, 1607, -225 },
- { 7684, -2387, 1308, -3449 },
- { 8306, -3458, 2394, -1454 },
- { 8438, -2781, 1043, -1362 },
- { 9175, -2076, 2144, -1987 },
- { 8347, -2709, 3489, -4301 },
- { 5696, -2377, 2870, 851 },
- { 8825, -1243, 2219, -2603 },
- { 8801, -1614, 584, -2513 },
- { 8413, -384, 1421, -2244 },
- { 9228, -3050, 3279, -2164 },
- { 6342, -2698, 3547, -107 },
- { 10053, -2476, 2837, -3168 },
- { 7439, -604, 3177, -3991 },
- { 7749, -1064, 4329, -4855 },
- { 8655, -2177, 2252, -3519 },
- { 8490, -228, 1958, -3233 },
- { 10513, -2968, 1911, -2340 },
- { 8146, -862, 1884, -1723 },
- { 7788, -666, 3004, -2891 },
- { 7785, -1620, 4133, -3417 },
- { 10262, -3731, 3455, -2971 },
- { 8570, -905, 4519, -4649 },
- { 9129, -2562, 463, -2465 },
- { 9451, -3587, 1904, -3056 },
- { 6549, -2236, 3010, -4523 },
- { 7175, -2684, 2967, -3458 },
- { 9872, -3278, 1054, -2472 },
- { 9153, -931, 1217, -2565 },
- { 8789, -3469, 753, -2568 },
- { 6683, -3791, 1797, -3968 },
- { 6801, -1977, 2311, -452 },
- { 6336, -1572, 2612, -3264 },
- { 7996, -1008, 730, -2964 },
- { 7521, -1059, 1573, -3694 },
- { 8148, -3973, 2600, -3572 },
- { 7765, -1532, 2528, -3856 },
- { 7404, -3918, 4472, -143 },
- { 8894, -1398, 3299, -3685 },
- { 5768, -2041, 1487, -637 },
- { 5131, -2865, 2463, -811 },
- { 6439, -1568, 3500, -1550 },
- { -8878, -6798, -5319, -1452 },
- { -6332, -9713, -3112, -990 },
- { -8444, -6316, -3694, -687 },
- { -6123, -10840, -3637, -4358 },
- { -4784, -9580, -4577, -2581 },
- { -6108, -10515, -4859, -2524 },
- { -7605, -7518, -2327, -2797 },
- { -9662, -8775, -2467, -2010 },
- { -6494, -7523, -4715, -118 },
- { -8290, -8982, -1672, -317 },
- { -8798, -11051, -3888, -1426 },
- { -6273, -6623, -6791, -142 },
- { -8313, -7668, -2141, -1275 },
- { -6453, -8412, -3589, -4102 },
- { -6747, -7750, -5690, -2498 },
- { -7814, -6693, -3174, -2446 },
- { -10383, -10130, -3931, -2364 },
- { -10606, -8467, -5539, -2772 },
- { -9475, -6671, -3305, -2271 },
- { -8982, -9457, -5635, -4005 },
- { -10111, -7965, -6515, -4180 },
- { -7301, -6479, -5364, 720 },
- { -9543, -8999, -7921, -912 },
- { -9534, -8562, -3469, -384 },
- { -7601, -10344, -3205, -1127 },
- { -8088, -8620, -4954, -2888 },
- { -8202, -8406, -7038, -3775 },
- { -7312, -8324, -3334, -1775 },
- { -8566, -9262, -8071, -4174 },
- { -7068, -11300, -5573, -2907 },
- { -8295, -8952, -4366, -1544 },
- { -11104, -10210, -2285, -384 },
- { -5213, -7520, -5008, -1339 },
- { -5889, -7940, -5987, -1385 },
- { -10816, -8201, -4153, -1485 },
- { -10277, -8919, -6315, -1652 },
- { -5888, -10320, -3821, -1733 },
- { -10497, -7181, -6083, -3032 },
- { -7721, -9724, -6591, -5336 },
- { -5688, -7894, -3486, -2552 },
- { -10014, -10500, -3247, -820 },
- { -6301, -8765, -4506, -2923 },
- { -8261, -7847, -6213, -1552 },
- { -10212, -7481, -8113, -3954 },
- { -6938, -10874, -6074, -4703 },
- { -7183, -10968, -4446, -1773 },
- { -7120, -9193, -1966, -2509 },
- { -6234, -9263, -2313, -4284 },
- { -8503, -9857, -2429, -608 },
- { -9372, -7844, -8391, -2120 },
- { -7951, -7157, -6535, -11 },
- { -7256, -9473, -2172, -660 },
- { -10063, -9612, -2515, -15 },
- { -6684, -9134, -6109, -4206 },
- { -8204, -11932, -5220, -2306 },
- { -9710, -6706, -4115, -3275 },
- { -6855, -7078, -2409, -4447 },
- { -7344, -7673, -4479, -4116 },
- { -8851, -6842, -4927, -2948 },
- { -8927, -10452, -5633, -2194 },
- { -8627, -9002, -7176, -1575 },
- { -8209, -9722, -7021, -3324 },
- { -3770, -10249, -3623, -4816 },
- { -8183, -7465, -4090, 646 },
- { -8163, -7149, 200, 498 },
- { -8289, -6266, 686, -206 },
- { -10030, -6241, -1032, -1864 },
- { -8793, -8327, -773, -169 },
- { -9149, -6215, 969, -15 },
- { -8303, -5859, -7, 2006 },
- { -9682, -7283, 255, 1322 },
- { -9293, -7227, 71, -231 },
- { -8525, -6215, 287, -837 },
- { -10477, -5379, 1159, 1449 },
- { -10726, -7856, -130, 102 },
- { -8694, -7461, -1210, 690 },
- { -9367, -5324, 1103, 3170 },
- { -10686, -8055, -831, 1633 },
- { -9201, -6873, -2704, 2258 },
- { -8421, -5358, -1405, 226 },
- { -9066, -5830, -307, -1571 },
- { -11150, -7381, -2746, -900 },
- { -9978, -5925, -2006, -437 },
- { -9464, -4741, -273, 1061 },
- { -10543, -6684, -1113, 1660 },
- { -10073, -5576, 1083, -269 },
- { -8826, -5763, 1600, 1486 },
- { -10445, -9071, -1253, -64 },
- { -12085, -5799, 2, 769 },
- { -12939, -6663, 1650, 1437 },
- { -10932, -6434, -1252, -649 },
- { -11650, -7826, -2053, 710 },
- { -12122, -6733, -1889, -731 },
- { -9093, -6095, -2463, -842 },
- { -10977, -4364, 469, 420 },
- { -11488, -6908, -521, 893 },
- { -9669, -5478, -842, 337 },
- { -10606, -5203, -632, -1361 },
- { -10198, -6284, 1662, 1277 },
- { -10135, -5292, 2435, 3493 },
- { -11027, -6561, 655, 56 },
- { -10977, -5030, 1127, -358 },
- { -12766, -3986, 1348, -335 },
- { -14244, -7731, 264, 317 },
- { -15124, -10309, -508, 1447 },
- { -12821, -8638, -608, 137 },
- { -13076, -8693, -2852, -431 },
- { -11156, -5546, -2252, -1600 },
- { -8692, -7366, -819, -1223 },
- { -12507, -9816, -1714, -121 },
- { -10712, -6666, 544, 3349 },
- { -12462, -5890, -2491, -2318 },
- { -12468, -7226, 437, 232 },
- { -11300, -5226, 2068, 687 },
- { -11994, -8320, -626, 2728 },
- { -12222, -5476, 1142, 18 },
- { -10277, -8122, -2418, 2003 },
- { -13418, -6115, -3563, -2802 },
- { -14759, -9834, -1243, 21 },
- { -13699, -5665, 1525, 507 },
- { -16269, -9476, -701, 163 },
- { -12677, -5437, -247, -1019 },
- { -11827, -4295, -181, -1243 },
- { -12847, -4496, 2984, 1123 },
- { -13860, -7915, -1166, -547 },
- { -12276, -8145, -2290, -1527 },
- { -11417, -4830, 2983, 1854 },
- { -11793, -6002, 1163, 1940 },
- { 11443, -4920, -3235, 3151 },
- { 11300, -6616, -1506, 1175 },
- { 9198, -4628, -2060, 2390 },
- { 10532, -4027, -643, 912 },
- { 9902, -3573, -1606, 1327 },
- { 9653, -3536, -2240, 1869 },
- { 9948, -5171, -423, 2662 },
- { 12316, -4004, -1989, 281 },
- { 12125, -4800, -1265, -163 },
- { 10650, -2617, -2337, 1462 },
- { 9909, -4968, -2376, 916 },
- { 12944, -4647, -1958, 460 },
- { 12988, -5283, -1141, 41 },
- { 12321, -2915, -3621, 1025 },
- { 11449, -2894, -2728, 351 },
- { 12087, -3041, -2002, -32 },
- { 11558, -4031, -1343, -399 },
- { 12983, -3740, -3516, 1245 },
- { 12099, -2515, -2752, 225 },
- { 12515, -3465, -2701, 550 },
- { 14683, -5022, -5272, 2996 },
- { 12260, -3383, -1215, -528 },
- { 13810, -5422, -2443, 1166 },
- { 13421, -5378, -1886, 721 },
- { 12961, -4259, -2594, 796 },
- { 12266, -2104, -4768, 1591 },
- { 13523, -4710, -3045, 1342 },
- { 12437, -2099, -5610, 2117 },
- { 11850, -2183, -3497, 661 },
- { 12275, -3936, -597, -697 },
- { 12459, -5253, -517, -544 },
- { 12835, -4094, -1322, -168 },
- { 14360, -5677, -3305, 1859 },
- { 13905, -4552, -4309, 2117 },
- { 11559, -3412, -1847, -81 },
- { 13379, -3167, -5764, 2746 },
- { 11910, -1634, -4342, 1052 },
- { 12662, -4742, 71, -974 },
- { 13057, -3254, -4424, 1705 },
- { 15046, -5706, -4851, 3019 },
- { 14162, -4142, -5514, 2843 },
- { 12764, -1845, -6684, 2888 },
- { 13714, -2374, -7838, 3857 },
- { 13295, -1663, -8293, 4073 },
- { 10032, -4152, -3403, 1421 },
- { 10942, -5386, -2222, 950 },
- { 10532, -6385, -1750, 1925 },
- { 10273, -5972, -1534, 643 },
- { 10605, -4782, -1695, 27 },
- { 10988, -5153, -1123, -341 },
- { 11629, -5884, -1060, 48 },
- { 10441, -4045, -2431, 311 },
- { 10788, -3595, -4171, 1807 },
- { 12110, -5686, -2127, 976 },
- { 11746, -4773, -2639, 891 },
- { 11541, -5299, -3031, 1732 },
- { 11416, -2559, -5359, 2198 },
- { 11583, -5376, -704, 677 },
- { 10416, -3214, -3516, 872 },
- { 9651, -5435, -1618, 3255 },
- { 9973, -5133, -996, 3923 },
- { 11707, -4643, -430, -796 },
- { 10994, -2709, -3587, 2302 },
- { 10716, -5118, -645, 270 },
- { 14100, -10314, 1095, 1531 },
- { 12944, -8049, 1105, -741 },
- { 13276, -7035, -511, 274 },
- { 14008, -7254, -283, 139 },
- { 11594, -6536, -91, 1671 },
- { 11732, -8645, 746, 15 },
- { 14613, -7085, -1578, 1183 },
- { 13083, -6224, -750, -4 },
- { 13988, -6256, -1592, 820 },
- { 14678, -8683, 441, 126 },
- { 15571, -8872, -521, 1139 },
- { 15642, -9533, 341, 697 },
- { 15960, -9586, -168, 1121 },
- { 15464, -10239, 1433, -1 },
- { 14934, -7887, -1046, 1080 },
- { 15252, -7630, -1899, 1628 },
- { 15485, -8384, -1234, 1484 },
- { 15962, -8638, -1815, 1931 },
- { 16501, -10664, 398, 1167 },
- { 16146, -10145, 411, 918 },
- { 14573, -7475, -697, 601 },
- { 14302, -7996, 28, 257 },
- { 14769, -6792, -2286, 1574 },
- { 14144, -6137, -2169, 1257 },
- { 14770, -6271, -3111, 1933 },
- { 14110, -8312, 1083, -531 },
- { 15235, -6991, -2993, 2174 },
- { 13222, -5805, 547, -891 },
- { 14796, -8762, 1254, -246 },
- { 16040, -9181, -1005, 1551 },
- { 16487, -10086, -373, 1420 },
- { 15077, -9479, 966, 51 },
- { 13026, -6468, 932, -1080 },
- { 12703, -6152, -33, -573 },
- { 15641, -6810, -4128, 2874 },
- { 13282, -7673, 1583, -1283 },
- { 12373, -7150, 1512, -917 },
- { 12992, -7751, -678, 783 },
- { 10907, -6858, -313, 2597 },
- { 13026, -8963, 125, 2152 },
- { 12770, -9946, 1957, -505 },
- { 12482, -6849, -1268, 833 },
- { 13790, -6181, -138, -279 },
- { 12709, -8382, 2044, 227 },
- { 12244, -6630, 203, -457 },
- { 14209, -6816, -1032, 632 },
- { 15134, -8267, -288, 640 },
- { 13619, -6157, -1090, 356 },
- { 14044, -7413, 725, -484 },
- { 12958, -7753, 2585, -1980 },
- { 13188, -8396, 2306, -1558 },
- { 14379, -9980, 2132, -688 },
- { 14275, -9857, 1162, 179 },
- { 13690, -8648, 1621, -889 },
- { 11770, -6829, -746, 278 },
- { 12732, -8202, 286, 90 },
- { 13630, -10146, 1867, -207 },
- { 12072, -8740, 1299, -645 },
- { 12852, -9492, 1226, 62 },
- { 11792, -7382, -54, -116 },
- { 13779, -9014, 487, 351 },
- { 11951, -7729, 121, 834 },
- { 11970, -9781, 2276, -4 },
- { 12680, -7984, 2787, -787 },
- { 13300, -14488, 6408, -1927 },
- { 13635, -15355, 9153, -3073 },
- { 12804, -13566, 5517, -1625 },
- { 16624, -10854, 1690, 28 },
- { 20387, -18532, 6162, -261 },
- { 16515, -12642, 3392, -519 },
- { 15800, -11095, 2151, -202 },
- { 16824, -11790, 1651, 599 },
- { 17604, -13213, 2563, 538 },
- { 17892, -14177, 3562, 147 },
- { 16987, -11399, 869, 1052 },
- { 17003, -12456, 2442, 265 },
- { 21657, -21806, 9198, -1250 },
- { 16825, -13341, 3980, -686 },
- { 17525, -12714, 1887, 805 },
- { 16419, -11034, 1216, 617 },
- { 20931, -19939, 7469, -684 },
- { 18452, -15390, 4573, -191 },
- { 14778, -10077, 2841, -1209 },
- { 17402, -13319, 3042, 160 },
- { 19365, -17922, 7087, -1061 },
- { 16298, -11941, 2810, -351 },
- { 19087, -16176, 4775, -84 },
- { 17666, -12289, 938, 1224 },
- { 18581, -15894, 5132, -430 },
- { 19823, -16717, 4142, 545 },
- { 19960, -19423, 8400, -1492 },
- { 18973, -16817, 5906, -594 },
- { 19079, -15431, 3528, 503 },
- { 16667, -12485, 4467, -1302 },
- { 19791, -17797, 6196, -529 },
- { 20005, -17606, 5354, -20 },
- { 20123, -18599, 6886, -728 },
- { 19068, -14805, 2394, 1105 },
- { 14443, -13723, 5631, -2029 },
- { 14730, -14231, 5631, -1450 },
- { 16089, -15959, 7271, -2029 },
- { 13473, -11200, 3236, -924 },
- { 14413, -10902, 2347, -267 },
- { 17666, -18662, 11381, -3496 },
- { 14749, -11042, 3305, -275 },
- { 15304, -10486, 1869, -240 },
- { 14809, -12126, 3369, -616 },
- { 16896, -16561, 7307, -1845 },
- { 15782, -14336, 5380, -1264 },
- { 16395, -15520, 6415, -1588 },
- { 13681, -11114, 2584, -320 },
- { 14244, -12326, 4480, -1632 },
- { 15247, -13119, 4265, -898 },
- { 13987, -12091, 3469, -597 },
- { 13941, -12770, 4240, -839 },
- { 13771, -13627, 5252, -1384 },
- { 15010, -16074, 7592, -2249 },
- { 15852, -17226, 8619, -2655 },
- { 18921, -16916, 6875, -1501 },
- { 14909, -11678, 2768, -295 },
- { 18988, -18353, 8424, -2070 },
- { 15457, -15080, 6218, -1513 },
- { 14916, -15512, 6949, -1883 },
- { 18108, -14702, 4681, -701 },
- { 17600, -15733, 5616, -775 },
- { 14070, -13683, 6472, -2626 },
- { 13832, -11914, 5201, -2232 },
- { 18846, -19009, 9192, -1961 },
- { -11981, -10994, -6324, -2264 },
- { -10976, -9047, -6546, -3828 },
- { -11288, -10532, -7014, -4191 },
- { -10139, -10189, -7799, -2688 },
- { -10555, -9988, -9181, -2040 },
- { -11596, -11339, -10022, -2707 },
- { -13400, -13395, -11306, -4206 },
- { -9774, -12281, -7466, -4133 },
- { -10842, -13125, -8777, -4956 },
- { -11964, -15082, -9779, -5095 },
- { -9382, -10188, -9053, -4927 },
- { -11562, -11296, -3651, -985 },
- { -9287, -10083, -7918, -4069 },
- { -12821, -16556, -11410, -6195 },
- { -12628, -8959, -4521, -1113 },
- { -13845, -11581, -3649, -681 },
- { -12685, -10269, -5483, -1275 },
- { -14988, -12874, -5107, -1189 },
- { -13761, -11367, -6202, -1804 },
- { -13225, -11249, -7820, -3354 },
- { -14809, -11992, -3202, -312 },
- { -15620, -15519, -10210, -3433 },
- { -12954, -10200, -3139, -611 },
- { -11536, -9981, -5284, -923 },
- { -13034, -12417, -4612, -1098 },
- { -16911, -15505, -6123, -1352 },
- { -17396, -17685, -8330, -2171 },
- { -14120, -10764, -2265, -99 },
- { -12598, -7367, -5406, -3530 },
- { -14143, -12793, -10909, -5226 },
- { -14692, -16871, -11626, -5554 },
- { -12581, -11197, -9194, -3837 },
- { -16752, -16726, -9746, -2808 },
- { -10600, -10358, -6560, -1227 },
- { -14573, -13312, -8957, -3393 },
- { -10172, -8463, -8579, -3387 },
- { -11418, -12421, -5522, -1842 },
- { -11855, -14204, -6669, -2625 },
- { -13308, -8191, -3941, -2194 },
- { -10007, -12266, -5022, -1811 },
- { -13532, -15771, -9497, -3175 },
- { -11760, -11148, -10339, -5529 },
- { -12149, -12763, -11198, -3697 },
- { -12029, -12119, -8555, -1792 },
- { -16995, -19957, -11447, -3471 },
- { -13144, -14504, -9988, -3191 },
- { -9938, -11064, -6139, -3162 },
- { -8873, -11550, -8294, -6550 },
- { -9303, -13010, -6150, -2711 },
- { -15463, -10469, -1766, -170 },
- { -15985, -11693, -3007, -650 },
- { -17142, -10671, -1434, 47 },
- { -16063, -13858, -4817, -1058 },
- { -19446, -19599, -9594, -2464 },
- { -20076, -18744, -8313, -1889 },
- { -15047, -16085, -7590, -2250 },
- { -13481, -16195, -8552, -2998 },
- { -13829, -14869, -6704, -1932 },
- { -16357, -18484, -9802, -2959 },
- { -10551, -8393, -9303, -5070 },
- { -11345, -9156, -5641, -3107 },
- { -13217, -13449, -9270, -4541 },
- { -11988, -13732, -9995, -6374 },
- { -11007, -9519, -5168, -4107 },
- { 9930, -7858, 8061, -4375 },
- { 8274, -7867, 5992, -2096 },
- { 9692, -9675, 7621, -3670 },
- { 9589, -8110, 6509, -3010 },
- { 12617, -11976, 10122, -5360 },
- { 11867, -8895, 7948, -5323 },
- { 10388, -10482, 9234, -4324 },
- { 8188, -8220, 7810, -2737 },
- { 10407, -8787, 4806, -1930 },
- { 10348, -8845, 9233, -6614 },
- { 9422, -7091, 4820, -2878 },
- { 9758, -9796, 5584, -2256 },
- { 10188, -7994, 5347, -3343 },
- { 11133, -7455, 4015, -2306 },
- { 10676, -10744, 6093, -2629 },
- { 11522, -12184, 7848, -3375 },
- { 8805, -9883, 5317, -3071 },
- { 9498, -9654, 6555, -3592 },
- { 10488, -8008, 4066, -1252 },
- { 11261, -8930, 6068, -2738 },
- { 12180, -10397, 5027, -1531 },
- { 9138, -8531, 3601, -1959 },
- { 8107, -8380, 4970, -2061 },
- { 9737, -13248, 6438, -2617 },
- { 11178, -10423, 2622, -522 },
- { 9572, -12372, 5199, -2019 },
- { 12057, -12144, 4147, -1099 },
- { 9047, -9925, 2516, -665 },
- { 10790, -8030, 5882, -4386 },
- { 7199, -8426, 6337, -2841 },
- { 7778, -8285, 3529, -3442 },
- { 7559, -10569, 3484, -1332 },
- { 9404, -8115, 7484, -5541 },
- { 7792, -11976, 5546, -2573 },
- { 9313, -10264, 7661, -5195 },
- { 6701, -10725, 4370, -1784 },
- { 4918, -11361, 4507, -4527 },
- { 5147, -12305, 3978, -5556 },
- { 6525, -9899, 4481, -3129 },
- { 7538, -12855, 6060, -4826 },
- { 8659, -12111, 7159, -4430 },
- { 8440, -11304, 4547, -1747 },
- { 9216, -10918, 3507, -1195 },
- { 6165, -9254, 4771, -4677 },
- { 9163, -11019, 5637, -4935 },
- { 13441, -11509, 6676, -2434 },
- { 7912, -9398, 6663, -4048 },
- { 11723, -13745, 8131, -4148 },
- { 6065, -10257, 5005, -6327 },
- { 11618, -12417, 5336, -1894 },
- { 8891, -13924, 8407, -6131 },
- { 9622, -12563, 7908, -5109 },
- { 11479, -10315, 8349, -3991 },
- { 11676, -14103, 6611, -2330 },
- { 11951, -8953, 3829, -1550 },
- { 10486, -8044, 10493, -5920 },
- { 11801, -10769, 9763, -5305 },
- { 6109, -8676, 5827, -1346 },
- { 7030, -9611, 5624, -5761 },
- { 12808, -12886, 8683, -4148 },
- { 13213, -10464, 6381, -3189 },
- { 11796, -13681, 10703, -6075 },
- { 9639, -7949, 9625, -3944 },
- { 8538, -6997, 5309, 453 }
-};
diff --git a/src/libdts/tables_fir.h b/src/libdts/tables_fir.h
deleted file mode 100644
index 892a93204..000000000
--- a/src/libdts/tables_fir.h
+++ /dev/null
@@ -1,2085 +0,0 @@
-/*
- * fir.h
- * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
- *
- * This file is part of dtsdec, a free DTS Coherent Acoustics stream decoder.
- * See http://www.videolan.org/dtsdec.html for updates.
- *
- * dtsdec 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.
- *
- * dtsdec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-double fir_32bands_perfect[] =
-{
-+1.135985195E-010,
--6.022448247E-007,
-+9.742954035E-007,
-+7.018770981E-011,
--6.628192182E-007,
-+1.085227950E-006,
--1.608403011E-008,
--6.982898526E-007,
-+1.162929266E-006,
--5.083275667E-008,
--7.020648809E-007,
-+1.194632091E-006,
--1.543309907E-007,
--6.767839409E-007,
-+1.179182050E-006,
--3.961981463E-007,
--6.262345096E-007,
-+1.033426656E-006,
--7.342250683E-007,
--5.564140224E-007,
-+9.451737242E-007,
--3.970030775E-007,
-+7.003467317E-007,
-+1.975324267E-006,
--4.741137047E-007,
-+8.419976893E-007,
-+1.190443072E-006,
-+5.234479659E-007,
-+6.402664354E-008,
--1.470520488E-006,
-+2.014677420E-007,
--3.246264413E-008,
--1.853591357E-006,
-+7.834767501E-008,
--3.809887872E-008,
-+7.198007665E-007,
-+8.434094667E-008,
-+3.086857760E-006,
--6.702406963E-010,
-+6.437721822E-008,
-+6.084746474E-006,
--1.613285505E-009,
-+1.189317118E-006,
-+9.561075785E-006,
--2.682709610E-009,
-+2.497214155E-006,
-+1.309637537E-005,
--3.399493131E-009,
-+3.617151151E-006,
-+2.263354872E-005,
-+1.314406006E-008,
-+3.157242645E-006,
-+2.847247197E-005,
-+7.506701927E-009,
-+2.319611212E-006,
-+3.415624451E-005,
-+2.788728892E-008,
-+7.869333785E-006,
-+3.946387005E-005,
-+1.444918922E-007,
-+9.826449968E-006,
-+4.425736552E-005,
-+3.132386439E-007,
-+1.177108606E-005,
-+4.839275425E-005,
-+1.399798180E-006,
-+1.379448349E-005,
-+5.176846025E-005,
-+2.032118118E-006,
-+1.571428584E-005,
-+5.429694284E-005,
-+2.715013807E-006,
-+1.743183020E-005,
-+5.595519906E-005,
-+3.453840463E-006,
-+1.884208177E-005,
-+4.916387297E-006,
-+4.195037945E-006,
-+1.987093310E-005,
-+9.299508747E-006,
-+4.896494374E-006,
-+2.042970118E-005,
-+1.356193479E-005,
-+5.516381407E-006,
--3.144468428E-005,
-+1.751866148E-005,
-+6.015239251E-006,
--3.334947178E-005,
-+2.093936746E-005,
-+6.361419310E-006,
--3.460439257E-005,
-+2.362549276E-005,
-+8.006985809E-006,
--3.515914432E-005,
-+2.537086584E-005,
-+8.087732567E-006,
--3.495384954E-005,
-+2.618136386E-005,
-+7.941360309E-006,
--3.397853652E-005,
-+2.554462844E-005,
-+7.568834008E-006,
--3.225446198E-005,
-+3.018750249E-005,
-+6.986399967E-006,
--2.978993689E-005,
-+2.570833203E-005,
-+6.225028756E-006,
--2.677291741E-005,
-+1.985177369E-005,
-+5.315936960E-006,
--1.806914770E-005,
-+1.191342653E-005,
-+4.429412002E-006,
--1.776598037E-005,
-+2.525620175E-006,
-+3.332600045E-006,
--1.661818715E-005,
--1.521241393E-005,
-+8.427224429E-007,
--1.207003334E-005,
--1.617751332E-005,
-+4.341498823E-007,
--6.993315310E-006,
-+1.992636317E-005,
-+9.458596395E-008,
--5.633860383E-007,
-+1.774702469E-005,
-+2.975164826E-008,
--9.984935332E-007,
-+4.624524081E-005,
-+5.610509834E-005,
--5.729619297E-004,
-+4.244441516E-004,
-+6.568001118E-005,
--6.358824321E-004,
-+2.206075296E-004,
-+7.513730816E-005,
--7.021900383E-004,
--2.719412748E-007,
-+8.413690375E-005,
--7.698345580E-004,
--2.382978710E-004,
-+8.757545584E-005,
--8.385353722E-004,
--4.935106263E-004,
-+9.517164290E-005,
--9.078957955E-004,
--7.658848190E-004,
-+1.020687996E-004,
--9.775133803E-004,
--1.055365428E-003,
-+1.084438481E-004,
--1.046945457E-003,
--1.361547387E-003,
-+1.140582463E-004,
--1.115717343E-003,
--1.684492454E-003,
-+1.187910311E-004,
--1.183370827E-003,
--2.023874084E-003,
-+1.224978914E-004,
--1.252829796E-003,
--2.379294252E-003,
-+1.250260248E-004,
--1.316190348E-003,
--2.750317100E-003,
-+1.262027217E-004,
--1.376571832E-003,
--3.136433195E-003,
-+1.226499153E-004,
--1.433344092E-003,
--3.537061159E-003,
-+1.213575742E-004,
--1.485876855E-003,
--3.951539751E-003,
-+1.180980107E-004,
--1.533520175E-003,
--4.379155114E-003,
-+1.126275165E-004,
--1.575609902E-003,
--4.819062538E-003,
-+1.047207043E-004,
--1.611457788E-003,
--5.270531867E-003,
-+9.417100227E-005,
--1.640390139E-003,
--5.732392892E-003,
-+8.078388782E-005,
--1.661288203E-003,
--6.203945260E-003,
-+6.447290798E-005,
--1.674512983E-003,
--6.683901884E-003,
-+4.491530854E-005,
--1.678415807E-003,
--7.170005701E-003,
-+2.470704203E-005,
--1.672798418E-003,
--7.664063945E-003,
--1.714242217E-006,
--1.656501088E-003,
--8.162760176E-003,
--3.193307566E-005,
--1.633993932E-003,
--8.665001951E-003,
--6.541742187E-005,
--1.593449386E-003,
--9.170533158E-003,
--1.024175072E-004,
-+1.542080659E-003,
--9.676489048E-003,
--1.312203676E-004,
-+1.479332102E-003,
--1.018219907E-002,
--1.774113771E-004,
-+1.395521569E-003,
--1.068630442E-002,
--2.233728592E-004,
-+1.303116791E-003,
--1.118756086E-002,
--2.682086197E-004,
-+1.196175464E-003,
--1.168460958E-002,
--3.347633174E-004,
-+1.073757303E-003,
--1.217562053E-002,
--3.906481725E-004,
-+9.358961834E-004,
--1.265939046E-002,
--4.490280990E-004,
-+7.817269652E-004,
--1.313448418E-002,
--5.099929986E-004,
-+6.114174030E-004,
--1.359948888E-002,
--1.405300573E-002,
-+1.572482102E-002,
-+4.935106263E-004,
--1.449365262E-002,
-+1.533095632E-002,
-+2.382978710E-004,
--1.492007636E-002,
-+1.492007636E-002,
-+2.719412748E-007,
--1.533095632E-002,
-+1.449365262E-002,
--2.206075296E-004,
--1.572482102E-002,
-+1.405300573E-002,
--4.244441516E-004,
--1.610082202E-002,
-+1.359948888E-002,
--6.114174030E-004,
--1.645756140E-002,
-+1.313448418E-002,
--7.817269652E-004,
--1.679391414E-002,
-+1.265939046E-002,
--9.358961834E-004,
--1.710879989E-002,
-+1.217562053E-002,
--1.073757303E-003,
--1.740120351E-002,
-+1.168460958E-002,
--1.196175464E-003,
--1.767017506E-002,
-+1.118756086E-002,
--1.303116791E-003,
--1.791484281E-002,
-+1.068630442E-002,
--1.395521569E-003,
--1.813439466E-002,
-+1.018219907E-002,
--1.479332102E-003,
--1.832821220E-002,
-+9.676489048E-003,
--1.542080659E-003,
--1.849545911E-002,
-+9.170533158E-003,
-+1.593449386E-003,
--1.863567345E-002,
-+8.665001951E-003,
-+1.633993932E-003,
--1.874836907E-002,
-+8.162760176E-003,
-+1.656501088E-003,
--1.883326657E-002,
-+7.664063945E-003,
-+1.672798418E-003,
--1.889026538E-002,
-+7.170005701E-003,
-+1.678415807E-003,
--1.891860925E-002,
-+6.683901884E-003,
-+1.674512983E-003,
-+1.891860925E-002,
-+6.203945260E-003,
-+1.661288203E-003,
-+1.889026538E-002,
-+5.732392892E-003,
-+1.640390139E-003,
-+1.883326657E-002,
-+5.270531867E-003,
-+1.611457788E-003,
-+1.874836907E-002,
-+4.819062538E-003,
-+1.575609902E-003,
-+1.863567345E-002,
-+4.379155114E-003,
-+1.533520175E-003,
-+1.849545911E-002,
-+3.951539751E-003,
-+1.485876855E-003,
-+1.832821220E-002,
-+3.537061159E-003,
-+1.433344092E-003,
-+1.813439466E-002,
-+3.136433195E-003,
-+1.376571832E-003,
-+1.791484281E-002,
-+2.750317100E-003,
-+1.316190348E-003,
-+1.767017506E-002,
-+2.379294252E-003,
-+1.252829796E-003,
-+1.740120351E-002,
-+2.023874084E-003,
-+1.183370827E-003,
-+1.710879989E-002,
-+1.684492454E-003,
-+1.115717343E-003,
-+1.679391414E-002,
-+1.361547387E-003,
-+1.046945457E-003,
-+1.645756140E-002,
-+1.055365428E-003,
-+9.775133803E-004,
-+1.610082202E-002,
-+7.658848190E-004,
-+9.078957955E-004,
-+8.385353722E-004,
--8.757545584E-005,
--6.084746474E-006,
-+7.698345580E-004,
--8.413690375E-005,
--3.086857760E-006,
-+7.021900383E-004,
--7.513730816E-005,
--7.198007665E-007,
-+6.358824321E-004,
--6.568001118E-005,
-+1.853591357E-006,
-+5.729619297E-004,
--5.610509834E-005,
-+1.470520488E-006,
-+5.099929986E-004,
--4.624524081E-005,
-+9.984935332E-007,
-+4.490280990E-004,
--1.774702469E-005,
-+5.633860383E-007,
-+3.906481725E-004,
--1.992636317E-005,
-+6.993315310E-006,
-+3.347633174E-004,
-+1.617751332E-005,
-+1.207003334E-005,
-+2.682086197E-004,
-+1.521241393E-005,
-+1.661818715E-005,
-+2.233728592E-004,
--2.525620175E-006,
-+1.776598037E-005,
-+1.774113771E-004,
--1.191342653E-005,
-+1.806914770E-005,
-+1.312203676E-004,
--1.985177369E-005,
-+2.677291741E-005,
-+1.024175072E-004,
--2.570833203E-005,
-+2.978993689E-005,
-+6.541742187E-005,
--3.018750249E-005,
-+3.225446198E-005,
-+3.193307566E-005,
--2.554462844E-005,
-+3.397853652E-005,
-+1.714242217E-006,
--2.618136386E-005,
-+3.495384954E-005,
--2.470704203E-005,
--2.537086584E-005,
-+3.515914432E-005,
--4.491530854E-005,
--2.362549276E-005,
-+3.460439257E-005,
--6.447290798E-005,
--2.093936746E-005,
-+3.334947178E-005,
--8.078388782E-005,
--1.751866148E-005,
-+3.144468428E-005,
--9.417100227E-005,
--1.356193479E-005,
--2.042970118E-005,
--1.047207043E-004,
--9.299508747E-006,
--1.987093310E-005,
--1.126275165E-004,
--4.916387297E-006,
--1.884208177E-005,
--1.180980107E-004,
--5.595519906E-005,
--1.743183020E-005,
--1.213575742E-004,
--5.429694284E-005,
--1.571428584E-005,
--1.226499153E-004,
--5.176846025E-005,
--1.379448349E-005,
--1.262027217E-004,
--4.839275425E-005,
--1.177108606E-005,
--1.250260248E-004,
--4.425736552E-005,
--9.826449968E-006,
--1.224978914E-004,
--3.946387005E-005,
--7.869333785E-006,
--1.187910311E-004,
--3.415624451E-005,
--2.319611212E-006,
--1.140582463E-004,
--2.847247197E-005,
--3.157242645E-006,
--1.084438481E-004,
--2.263354872E-005,
--3.617151151E-006,
--1.020687996E-004,
--1.309637537E-005,
--2.497214155E-006,
--9.517164290E-005,
--9.561075785E-006,
--1.189317118E-006,
--6.437721822E-008,
--4.195037945E-006,
--1.194632091E-006,
--8.434094667E-008,
--3.453840463E-006,
--1.162929266E-006,
-+3.809887872E-008,
--2.715013807E-006,
--1.085227950E-006,
-+3.246264413E-008,
--2.032118118E-006,
--9.742954035E-007,
--6.402664354E-008,
--1.399798180E-006,
--8.419976893E-007,
--2.975164826E-008,
--3.132386439E-007,
--7.003467317E-007,
--9.458596395E-008,
--1.444918922E-007,
-+5.564140224E-007,
--4.341498823E-007,
--2.788728892E-008,
-+6.262345096E-007,
--8.427224429E-007,
--7.506701927E-009,
-+6.767839409E-007,
--3.332600045E-006,
--1.314406006E-008,
-+7.020648809E-007,
--4.429412002E-006,
-+3.399493131E-009,
-+6.982898526E-007,
--5.315936960E-006,
-+2.682709610E-009,
-+6.628192182E-007,
--6.225028756E-006,
-+1.613285505E-009,
-+6.022448247E-007,
--6.986399967E-006,
-+6.702406963E-010,
-+4.741137047E-007,
--7.568834008E-006,
--7.834767501E-008,
-+3.970030775E-007,
--7.941360309E-006,
--2.014677420E-007,
-+7.342250683E-007,
--8.087732567E-006,
--5.234479659E-007,
-+3.961981463E-007,
--8.006985809E-006,
--1.190443072E-006,
-+1.543309907E-007,
--6.361419310E-006,
--1.975324267E-006,
-+5.083275667E-008,
--6.015239251E-006,
--9.451737242E-007,
-+1.608403011E-008,
--5.516381407E-006,
--1.033426656E-006,
--7.018770981E-011,
--4.896494374E-006,
--1.179182050E-006,
--1.135985195E-010
-};
-
-double fir_32bands_nonperfect[] =
-{
--1.390191784E-007,
--1.693738625E-007,
--2.030677564E-007,
--2.404238444E-007,
--2.818143514E-007,
--3.276689142E-007,
--3.784752209E-007,
--4.347855338E-007,
--4.972276315E-007,
--5.665120852E-007,
--6.434325428E-007,
--7.288739425E-007,
--8.238164355E-007,
--9.293416952E-007,
--1.046637067E-006,
--1.176999604E-006,
--1.321840614E-006,
--1.482681114E-006,
--1.661159786E-006,
--1.859034001E-006,
--2.078171747E-006,
--2.320550948E-006,
--2.588257530E-006,
--2.883470643E-006,
--3.208459020E-006,
--3.565570978E-006,
--3.957220997E-006,
--4.385879038E-006,
--4.854050530E-006,
--5.364252502E-006,
--5.918994248E-006,
--6.520755960E-006,
--7.171964626E-006,
--7.874960829E-006,
--8.631964192E-006,
--9.445050637E-006,
--1.031611009E-005,
--1.124680875E-005,
--1.223855270E-005,
--1.329243969E-005,
--1.440921824E-005,
--1.558924305E-005,
--1.683242772E-005,
--1.813820381E-005,
--1.950545993E-005,
--2.093250441E-005,
--2.241701623E-005,
--2.395598858E-005,
--2.554569073E-005,
--2.718161704E-005,
--2.885844333E-005,
--3.056998685E-005,
--3.230916263E-005,
--3.406793985E-005,
--3.583733633E-005,
--3.760734762E-005,
--3.936696885E-005,
--4.110412556E-005,
--4.280570283E-005,
--4.445751256E-005,
--4.604430433E-005,
--4.754976908E-005,
--4.895655002E-005,
--5.024627535E-005,
-+5.139957648E-005,
-+5.239612074E-005,
-+5.321469871E-005,
-+5.383323878E-005,
-+5.422891263E-005,
-+5.437819709E-005,
-+5.425697600E-005,
-+5.384063843E-005,
-+5.310418419E-005,
-+5.202236207E-005,
-+5.056979353E-005,
-+4.872112549E-005,
-+4.645117951E-005,
-+4.373511547E-005,
-+4.054862075E-005,
-+3.686808850E-005,
-+3.267079956E-005,
-+2.793515523E-005,
-+2.264085742E-005,
-+1.676913780E-005,
-+1.030297699E-005,
-+3.227306706E-006,
--4.470633485E-006,
--1.280130618E-005,
--2.177240640E-005,
--3.138873581E-005,
--4.165195787E-005,
--5.256036457E-005,
--6.410864444E-005,
--7.628766616E-005,
--8.908427117E-005,
--1.024810626E-004,
--1.164562127E-004,
--1.309833024E-004,
--1.460311323E-004,
--1.615635992E-004,
--1.775395358E-004,
--1.939126523E-004,
--2.106313768E-004,
--2.276388550E-004,
--2.448728774E-004,
--2.622658503E-004,
--2.797449124E-004,
--2.972317743E-004,
--3.146430245E-004,
--3.318900708E-004,
--3.488793736E-004,
--3.655125911E-004,
--3.816867538E-004,
--3.972945851E-004,
--4.122247046E-004,
--4.263620067E-004,
--4.395879805E-004,
--4.517810594E-004,
--4.628172028E-004,
--4.725702747E-004,
--4.809123348E-004,
--4.877146275E-004,
--4.928477574E-004,
--4.961824161E-004,
--4.975944757E-004,
--4.969481961E-004,
--4.941228544E-004,
--4.889960401E-004,
-+4.814492422E-004,
-+4.713678791E-004,
-+4.586426076E-004,
-+4.431701091E-004,
-+4.248536134E-004,
-+4.036037717E-004,
-+3.793396754E-004,
-+3.519894381E-004,
-+3.214911267E-004,
-+2.877934603E-004,
-+2.508567995E-004,
-+2.106537577E-004,
-+1.671699720E-004,
-+1.204049113E-004,
-+7.037253090E-005,
-+1.710198012E-005,
--3.936182839E-005,
--9.895755647E-005,
--1.616069785E-004,
--2.272142592E-004,
--2.956659591E-004,
--3.668301215E-004,
--4.405563814E-004,
--5.166754709E-004,
--5.949990009E-004,
--6.753197522E-004,
--7.574109477E-004,
--8.410271257E-004,
--9.259034996E-004,
--1.011756598E-003,
--1.098284614E-003,
--1.185167348E-003,
--1.272067428E-003,
--1.358630019E-003,
--1.444484224E-003,
--1.529243193E-003,
--1.612505526E-003,
--1.693855622E-003,
--1.772865304E-003,
--1.849094522E-003,
--1.922092517E-003,
--1.991399564E-003,
--2.056547208E-003,
--2.117061289E-003,
--2.172462177E-003,
--2.222266514E-003,
--2.265989315E-003,
--2.303145360E-003,
--2.333251061E-003,
--2.355825622E-003,
--2.370394068E-003,
--2.376487479E-003,
--2.373647178E-003,
--2.361423569E-003,
--2.339380793E-003,
--2.307097195E-003,
--2.264167881E-003,
--2.210205887E-003,
--2.144844970E-003,
--2.067740774E-003,
--1.978572691E-003,
--1.877046190E-003,
--1.762894331E-003,
--1.635878929E-003,
-+1.495792647E-003,
-+1.342460280E-003,
-+1.175740734E-003,
-+9.955273708E-004,
-+8.017504588E-004,
-+5.943773431E-004,
-+3.734139318E-004,
-+1.389056415E-004,
--1.090620208E-004,
--3.703625989E-004,
--6.448282511E-004,
--9.322494152E-004,
--1.232374110E-003,
--1.544908970E-003,
--1.869517611E-003,
--2.205822384E-003,
--2.553403843E-003,
--2.911801683E-003,
--3.280514618E-003,
--3.659002949E-003,
--4.046686925E-003,
--4.442950245E-003,
--4.847140983E-003,
--5.258570891E-003,
--5.676518660E-003,
--6.100233644E-003,
--6.528933067E-003,
--6.961807609E-003,
--7.398022339E-003,
--7.836719044E-003,
--8.277016692E-003,
--8.718019351E-003,
--9.158811532E-003,
--9.598465636E-003,
--1.003604382E-002,
--1.047059800E-002,
--1.090117730E-002,
--1.132682897E-002,
--1.174659748E-002,
--1.215953380E-002,
--1.256469358E-002,
--1.296114177E-002,
--1.334795821E-002,
--1.372423489E-002,
--1.408908330E-002,
--1.444163360E-002,
--1.478104480E-002,
--1.510649733E-002,
--1.541720331E-002,
--1.571240649E-002,
--1.599138230E-002,
--1.625344716E-002,
--1.649795473E-002,
--1.672429405E-002,
--1.693190821E-002,
--1.712027565E-002,
--1.728892699E-002,
--1.743743755E-002,
--1.756543480E-002,
--1.767260395E-002,
--1.775865816E-002,
--1.782339066E-002,
--1.786663756E-002,
--1.788828894E-002,
-+1.788828894E-002,
-+1.786663756E-002,
-+1.782339066E-002,
-+1.775865816E-002,
-+1.767260395E-002,
-+1.756543480E-002,
-+1.743743755E-002,
-+1.728892699E-002,
-+1.712027565E-002,
-+1.693190821E-002,
-+1.672429405E-002,
-+1.649795473E-002,
-+1.625344716E-002,
-+1.599138230E-002,
-+1.571240649E-002,
-+1.541720331E-002,
-+1.510649733E-002,
-+1.478104480E-002,
-+1.444163360E-002,
-+1.408908330E-002,
-+1.372423489E-002,
-+1.334795821E-002,
-+1.296114177E-002,
-+1.256469358E-002,
-+1.215953380E-002,
-+1.174659748E-002,
-+1.132682897E-002,
-+1.090117730E-002,
-+1.047059800E-002,
-+1.003604382E-002,
-+9.598465636E-003,
-+9.158811532E-003,
-+8.718019351E-003,
-+8.277016692E-003,
-+7.836719044E-003,
-+7.398022339E-003,
-+6.961807609E-003,
-+6.528933067E-003,
-+6.100233644E-003,
-+5.676518660E-003,
-+5.258570891E-003,
-+4.847140983E-003,
-+4.442950245E-003,
-+4.046686925E-003,
-+3.659002949E-003,
-+3.280514618E-003,
-+2.911801683E-003,
-+2.553403843E-003,
-+2.205822384E-003,
-+1.869517611E-003,
-+1.544908970E-003,
-+1.232374110E-003,
-+9.322494152E-004,
-+6.448282511E-004,
-+3.703625989E-004,
-+1.090620208E-004,
--1.389056415E-004,
--3.734139318E-004,
--5.943773431E-004,
--8.017504588E-004,
--9.955273708E-004,
--1.175740734E-003,
--1.342460280E-003,
--1.495792647E-003,
-+1.635878929E-003,
-+1.762894331E-003,
-+1.877046190E-003,
-+1.978572691E-003,
-+2.067740774E-003,
-+2.144844970E-003,
-+2.210205887E-003,
-+2.264167881E-003,
-+2.307097195E-003,
-+2.339380793E-003,
-+2.361423569E-003,
-+2.373647178E-003,
-+2.376487479E-003,
-+2.370394068E-003,
-+2.355825622E-003,
-+2.333251061E-003,
-+2.303145360E-003,
-+2.265989315E-003,
-+2.222266514E-003,
-+2.172462177E-003,
-+2.117061289E-003,
-+2.056547208E-003,
-+1.991399564E-003,
-+1.922092517E-003,
-+1.849094522E-003,
-+1.772865304E-003,
-+1.693855622E-003,
-+1.612505526E-003,
-+1.529243193E-003,
-+1.444484224E-003,
-+1.358630019E-003,
-+1.272067428E-003,
-+1.185167348E-003,
-+1.098284614E-003,
-+1.011756598E-003,
-+9.259034996E-004,
-+8.410271257E-004,
-+7.574109477E-004,
-+6.753197522E-004,
-+5.949990009E-004,
-+5.166754709E-004,
-+4.405563814E-004,
-+3.668301215E-004,
-+2.956659591E-004,
-+2.272142592E-004,
-+1.616069785E-004,
-+9.895755647E-005,
-+3.936182839E-005,
--1.710198012E-005,
--7.037253090E-005,
--1.204049113E-004,
--1.671699720E-004,
--2.106537577E-004,
--2.508567995E-004,
--2.877934603E-004,
--3.214911267E-004,
--3.519894381E-004,
--3.793396754E-004,
--4.036037717E-004,
--4.248536134E-004,
--4.431701091E-004,
--4.586426076E-004,
--4.713678791E-004,
--4.814492422E-004,
-+4.889960401E-004,
-+4.941228544E-004,
-+4.969481961E-004,
-+4.975944757E-004,
-+4.961824161E-004,
-+4.928477574E-004,
-+4.877146275E-004,
-+4.809123348E-004,
-+4.725702747E-004,
-+4.628172028E-004,
-+4.517810594E-004,
-+4.395879805E-004,
-+4.263620067E-004,
-+4.122247046E-004,
-+3.972945851E-004,
-+3.816867538E-004,
-+3.655125911E-004,
-+3.488793736E-004,
-+3.318900708E-004,
-+3.146430245E-004,
-+2.972317743E-004,
-+2.797449124E-004,
-+2.622658503E-004,
-+2.448728774E-004,
-+2.276388550E-004,
-+2.106313768E-004,
-+1.939126523E-004,
-+1.775395358E-004,
-+1.615635992E-004,
-+1.460311323E-004,
-+1.309833024E-004,
-+1.164562127E-004,
-+1.024810626E-004,
-+8.908427117E-005,
-+7.628766616E-005,
-+6.410864444E-005,
-+5.256036457E-005,
-+4.165195787E-005,
-+3.138873581E-005,
-+2.177240640E-005,
-+1.280130618E-005,
-+4.470633485E-006,
--3.227306706E-006,
--1.030297699E-005,
--1.676913780E-005,
--2.264085742E-005,
--2.793515523E-005,
--3.267079956E-005,
--3.686808850E-005,
--4.054862075E-005,
--4.373511547E-005,
--4.645117951E-005,
--4.872112549E-005,
--5.056979353E-005,
--5.202236207E-005,
--5.310418419E-005,
--5.384063843E-005,
--5.425697600E-005,
--5.437819709E-005,
--5.422891263E-005,
--5.383323878E-005,
--5.321469871E-005,
--5.239612074E-005,
--5.139957648E-005,
-+5.024627535E-005,
-+4.895655002E-005,
-+4.754976908E-005,
-+4.604430433E-005,
-+4.445751256E-005,
-+4.280570283E-005,
-+4.110412556E-005,
-+3.936696885E-005,
-+3.760734762E-005,
-+3.583733633E-005,
-+3.406793985E-005,
-+3.230916263E-005,
-+3.056998685E-005,
-+2.885844333E-005,
-+2.718161704E-005,
-+2.554569073E-005,
-+2.395598858E-005,
-+2.241701623E-005,
-+2.093250441E-005,
-+1.950545993E-005,
-+1.813820381E-005,
-+1.683242772E-005,
-+1.558924305E-005,
-+1.440921824E-005,
-+1.329243969E-005,
-+1.223855270E-005,
-+1.124680875E-005,
-+1.031611009E-005,
-+9.445050637E-006,
-+8.631964192E-006,
-+7.874960829E-006,
-+7.171964626E-006,
-+6.520755960E-006,
-+5.918994248E-006,
-+5.364252502E-006,
-+4.854050530E-006,
-+4.385879038E-006,
-+3.957220997E-006,
-+3.565570978E-006,
-+3.208459020E-006,
-+2.883470643E-006,
-+2.588257530E-006,
-+2.320550948E-006,
-+2.078171747E-006,
-+1.859034001E-006,
-+1.661159786E-006,
-+1.482681114E-006,
-+1.321840614E-006,
-+1.176999604E-006,
-+1.046637067E-006,
-+9.293416952E-007,
-+8.238164355E-007,
-+7.288739425E-007,
-+6.434325428E-007,
-+5.665120852E-007,
-+4.972276315E-007,
-+4.347855338E-007,
-+3.784752209E-007,
-+3.276689142E-007,
-+2.818143514E-007,
-+2.404238444E-007,
-+2.030677564E-007,
-+1.693738625E-007,
-+1.390191784E-007
-};
-
-double 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
-};
-
-double 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
-};
diff --git a/src/libdts/tables_huffman.h b/src/libdts/tables_huffman.h
deleted file mode 100644
index 6690d356c..000000000
--- a/src/libdts/tables_huffman.h
+++ /dev/null
@@ -1,1070 +0,0 @@
-/*
- * huffman_tables.h
- * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
- *
- * This file is part of dtsdec, a free DTS Coherent Acoustics stream decoder.
- * See http://www.videolan.org/dtsdec.html for updates.
- *
- * dtsdec 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.
- *
- * dtsdec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-typedef struct huff_entry_s
-{
- int length;
- int code;
- int value;
-
-} huff_entry_t;
-
-huff_entry_t bitalloc_a_12[] =
-{
- { 1, 0, 1}, { 2, 2, 2}, { 3, 6, 3}, { 4, 14, 4},
- { 5, 30, 5}, { 6, 62, 6}, { 8, 255, 7}, { 8, 254, 8},
- { 9, 507, 9}, { 9, 506, 10}, { 9, 505, 11}, { 9, 504, 12},
- { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_b_12[] =
-{
- { 1, 1, 1}, { 2, 0, 2}, { 3, 2, 3}, { 5, 15, 4},
- { 5, 12, 5}, { 6, 29, 6}, { 7, 57, 7}, { 7, 56, 8},
- { 7, 55, 9}, { 7, 54, 10}, { 7, 53, 11}, { 7, 52, 12},
- { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_c_12[] =
-{
- { 2, 0, 1}, { 3, 7, 2}, { 3, 5, 3}, { 3, 4, 4},
- { 3, 2, 5}, { 4, 13, 6}, { 4, 12, 7}, { 4, 6, 8},
- { 5, 15, 9}, { 6, 29, 10}, { 7, 57, 11}, { 7, 56, 12},
- { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_d_12[] =
-{
- { 2, 3, 1}, { 2, 2, 2}, { 2, 0, 3}, { 3, 2, 4},
- { 4, 6, 5}, { 5, 14, 6}, { 6, 30, 7}, { 7, 62, 8},
- { 8, 126, 9}, { 9, 254, 10}, {10, 511, 11}, {10, 510, 12},
- { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_e_12[] =
-{
- { 1, 1, 1}, { 2, 0, 2}, { 3, 2, 3}, { 4, 6, 4},
- { 5, 14, 5}, { 7, 63, 6}, { 7, 61, 7}, { 8, 124, 8},
- { 8, 121, 9}, { 8, 120, 10}, { 9, 251, 11}, { 9, 250, 12},
- { 0, 0, 0}
-};
-
-huff_entry_t *bitalloc_12[] =
-{
- bitalloc_a_12,
- bitalloc_b_12,
- bitalloc_c_12,
- bitalloc_d_12,
- bitalloc_e_12
-};
-
-huff_entry_t scales_a_129[] =
-{
- { 2, 1, 0}, { 3, 6, 1}, { 3, 5, -1}, { 3, 0, 2},
- { 4, 15, -2}, { 4, 8, 3}, { 4, 3, -3}, { 5, 28, 4},
- { 5, 19, -4}, { 5, 4, 5}, { 6, 59, -5}, { 6, 36, 6},
- { 6, 11, -6}, { 7, 75, 7}, { 7, 74, -7}, { 8, 233, 8},
- { 8, 232, -8}, { 8, 41, 9}, { 8, 40, -9}, { 9, 87, 10},
- { 9, 86,-10}, {10, 937, 11}, {10, 936,-11}, {11, 1877, 12},
- {11, 1876,-12}, {11, 341, 13}, {11, 340,-13}, {12, 686, 14},
- {12, 685,-14}, {13, 1375, 15}, {13, 1374,-15}, {13, 1369, 16},
- {13, 1368,-16}, {13, 1359, 17}, {13, 1358,-17}, {13, 1357, 18},
- {13, 1356,-18}, {13, 1355, 19}, {13, 1354,-19}, {13, 1353, 20},
- {13, 1352,-20}, {13, 1351, 21}, {13, 1350,-21}, {13, 1349, 22},
- {13, 1348,-22}, {13, 1347, 23}, {13, 1346,-23}, {13, 1345, 24},
- {13, 1344,-24}, {14, 15103, 25}, {14, 15102,-25}, {14, 15101, 26},
- {14, 15100,-26}, {14, 15099, 27}, {14, 15098,-27}, {14, 15097, 28},
- {14, 15096,-28}, {14, 15095, 29}, {14, 15094,-29}, {14, 15093, 30},
- {14, 15092,-30}, {14, 15091, 31}, {14, 15090,-31}, {14, 15089, 32},
- {14, 15088,-32}, {14, 15087, 33}, {14, 15086,-33}, {14, 15085, 34},
- {14, 15084,-34}, {14, 15083, 35}, {14, 15082,-35}, {14, 15081, 36},
- {14, 15080,-36}, {14, 15079, 37}, {14, 15078,-37}, {14, 15077, 38},
- {14, 15076,-38}, {14, 15075, 39}, {14, 15074,-39}, {14, 15073, 40},
- {14, 15072,-40}, {14, 15071, 41}, {14, 15070,-41}, {14, 15069, 42},
- {14, 15068,-42}, {14, 15067, 43}, {14, 15066,-43}, {14, 15065, 44},
- {14, 15064,-44}, {14, 15063, 45}, {14, 15062,-45}, {14, 15061, 46},
- {14, 15060,-46}, {14, 15059, 47}, {14, 15058,-47}, {14, 15057, 48},
- {14, 15056,-48}, {14, 15055, 49}, {14, 15054,-49}, {14, 15053, 50},
- {14, 15052,-50}, {14, 15051, 51}, {14, 15050,-51}, {14, 15049, 52},
- {14, 15048,-52}, {14, 15047, 53}, {14, 15046,-53}, {14, 15045, 54},
- {14, 15044,-54}, {14, 15043, 55}, {14, 15042,-55}, {14, 15041, 56},
- {14, 15040,-56}, {14, 15039, 57}, {14, 15038,-57}, {14, 15037, 58},
- {14, 15036,-58}, {14, 15035, 59}, {14, 15034,-59}, {14, 15033, 60},
- {14, 15032,-60}, {14, 15031, 61}, {14, 15030,-61}, {14, 15029, 62},
- {14, 15028,-62}, {14, 15027, 63}, {14, 15026,-63}, {14, 15025, 64},
- {14, 15024,-64}, { 0, 0, 0}
-};
-
-huff_entry_t scales_b_129[] =
-{
- { 3, 3, 0}, { 3, 2, 1}, { 3, 1, -1}, { 4, 15, 2},
- { 4, 14, -2}, { 4, 12, 3}, { 4, 11, -3}, { 4, 10, 4},
- { 4, 9, -4}, { 4, 0, 5}, { 5, 27, -5}, { 5, 17, 6},
- { 5, 16, -6}, { 6, 53, 7}, { 6, 52, -7}, { 6, 5, 8},
- { 6, 4, -8}, { 7, 13, 9}, { 7, 12, -9}, { 8, 29, 10},
- { 8, 28,-10}, { 9, 60, 11}, {10, 127,-11}, {11, 253, 12},
- {11, 252,-12}, {12, 491, 13}, {12, 490,-13}, {13, 979, 14},
- {13, 978,-14}, {14, 1955, 15}, {14, 1954,-15}, {14, 1953, 16},
- {14, 1952,-16}, {15, 4031, 17}, {15, 4030,-17}, {15, 4029, 18},
- {15, 4028,-18}, {15, 4027, 19}, {15, 4026,-19}, {15, 4025, 20},
- {15, 4024,-20}, {15, 4023, 21}, {15, 4022,-21}, {15, 4021, 22},
- {15, 4020,-22}, {15, 4019, 23}, {15, 4018,-23}, {15, 4017, 24},
- {15, 4016,-24}, {15, 4015, 25}, {15, 4014,-25}, {15, 4013, 26},
- {15, 4012,-26}, {15, 4011, 27}, {15, 4010,-27}, {15, 4009, 28},
- {15, 4008,-28}, {15, 4007, 29}, {15, 4006,-29}, {15, 4005, 30},
- {15, 4004,-30}, {15, 4003, 31}, {15, 4002,-31}, {15, 4001, 32},
- {15, 4000,-32}, {15, 3999, 33}, {15, 3998,-33}, {15, 3997, 34},
- {15, 3996,-34}, {15, 3995, 35}, {15, 3994,-35}, {15, 3993, 36},
- {15, 3992,-36}, {15, 3991, 37}, {15, 3990,-37}, {15, 3989, 38},
- {15, 3988,-38}, {15, 3987, 39}, {15, 3986,-39}, {15, 3985, 40},
- {15, 3984,-40}, {15, 3983, 41}, {15, 3982,-41}, {15, 3981, 42},
- {15, 3980,-42}, {15, 3979, 43}, {15, 3978,-43}, {15, 3977, 44},
- {15, 3976,-44}, {15, 3975, 45}, {15, 3974,-45}, {15, 3973, 46},
- {15, 3972,-46}, {15, 3971, 47}, {15, 3970,-47}, {15, 3969, 48},
- {15, 3968,-48}, {15, 3967, 49}, {15, 3966,-49}, {15, 3965, 50},
- {15, 3964,-50}, {15, 3963, 51}, {15, 3962,-51}, {15, 3961, 52},
- {15, 3960,-52}, {15, 3959, 53}, {15, 3958,-53}, {15, 3957, 54},
- {15, 3956,-54}, {15, 3955, 55}, {15, 3954,-55}, {15, 3953, 56},
- {15, 3952,-56}, {15, 3951, 57}, {15, 3950,-57}, {15, 3949, 58},
- {15, 3948,-58}, {15, 3947, 59}, {15, 3946,-59}, {15, 3945, 60},
- {15, 3944,-60}, {15, 3943, 61}, {15, 3942,-61}, {15, 3941, 62},
- {15, 3940,-62}, {15, 3939, 63}, {15, 3938,-63}, {15, 3937, 64},
- {15, 3936,-64}, { 0, 0, 0}
-};
-
-huff_entry_t scales_c_129[] =
-{
- { 3, 4, 0}, { 3, 1, 1}, { 3, 0, -1}, { 4, 13, 2},
- { 4, 12, -2}, { 4, 7, 3}, { 4, 6, -3}, { 5, 31, 4},
- { 5, 30, -4}, { 5, 23, 5}, { 5, 22, -5}, { 5, 11, 6},
- { 5, 10, -6}, { 6, 59, 7}, { 6, 58, -7}, { 6, 43, 8},
- { 6, 42, -8}, { 6, 19, 9}, { 6, 18, -9}, { 7, 115, 10},
- { 7, 114,-10}, { 7, 83, 11}, { 7, 82,-11}, { 7, 35, 12},
- { 7, 34,-12}, { 8, 227, 13}, { 8, 226,-13}, { 8, 162, 14},
- { 8, 161,-14}, { 8, 66, 15}, { 8, 65,-15}, { 9, 450, 16},
- { 9, 449,-16}, { 9, 321, 17}, { 9, 320,-17}, { 9, 129, 18},
- { 9, 128,-18}, {10, 897, 19}, {10, 896,-19}, {10, 652, 20},
- {10, 271,-20}, {10, 268, 21}, {11, 1807,-21}, {11, 1308, 22},
- {11, 1307,-22}, {11, 540, 23}, {11, 539,-23}, {12, 3612, 24},
- {12, 3611,-24}, {12, 2613, 25}, {12, 2612,-25}, {12, 1077, 26},
- {12, 1076,-26}, {13, 7226, 27}, {13, 7221,-27}, {13, 2167, 28},
- {13, 2166,-28}, {13, 2164, 29}, {14, 14455,-29}, {14, 14441, 30},
- {14, 14440,-30}, {14, 4331, 31}, {14, 4330,-31}, {15, 28909, 32},
- {15, 28908,-32}, {15, 28879, 33}, {15, 28878,-33}, {15, 28877, 34},
- {15, 28876,-34}, {15, 28875, 35}, {15, 28874,-35}, {15, 28873, 36},
- {15, 28872,-36}, {15, 28871, 37}, {15, 28870,-37}, {15, 28869, 38},
- {15, 28868,-38}, {15, 28867, 39}, {15, 28866,-39}, {15, 28865, 40},
- {15, 28864,-40}, {15, 20991, 41}, {15, 20990,-41}, {15, 20989, 42},
- {15, 20988,-42}, {15, 20987, 43}, {15, 20986,-43}, {15, 20985, 44},
- {15, 20984,-44}, {15, 20983, 45}, {15, 20982,-45}, {15, 20981, 46},
- {15, 20980,-46}, {15, 20979, 47}, {15, 20978,-47}, {15, 20977, 48},
- {15, 20976,-48}, {15, 20975, 49}, {15, 20974,-49}, {15, 20973, 50},
- {15, 20972,-50}, {15, 20971, 51}, {15, 20970,-51}, {15, 20969, 52},
- {15, 20968,-52}, {15, 20967, 53}, {15, 20966,-53}, {15, 20965, 54},
- {15, 20964,-54}, {15, 20963, 55}, {15, 20962,-55}, {15, 20961, 56},
- {15, 20960,-56}, {15, 20959, 57}, {15, 20958,-57}, {15, 20957, 58},
- {15, 20956,-58}, {15, 20955, 59}, {15, 20954,-59}, {15, 20953, 60},
- {15, 20952,-60}, {15, 20951, 61}, {15, 20950,-61}, {15, 20949, 62},
- {15, 20948,-62}, {15, 20947, 63}, {15, 20946,-63}, {15, 20945, 64},
- {15, 20944,-64}, { 0, 0, 0}
-};
-
-huff_entry_t scales_d_129[] =
-{
- { 2, 0, 0}, { 3, 5, 1}, { 3, 4, -1}, { 4, 15, 2},
- { 4, 14, -2}, { 4, 7, 3}, { 4, 6, -3}, { 5, 26, 4},
- { 5, 25, -4}, { 5, 10, 5}, { 5, 9, -5}, { 6, 54, 6},
- { 6, 49, -6}, { 6, 22, 7}, { 6, 17, -7}, { 7, 110, 8},
- { 7, 97, -8}, { 7, 46, 9}, { 7, 33, -9}, { 8, 193, 10},
- { 8, 192,-10}, { 8, 65, 11}, { 8, 64,-11}, { 9, 444, 12},
- { 9, 191,-12}, { 9, 188, 13}, {10, 895,-13}, {10, 890, 14},
- {10, 381,-14}, {10, 378, 15}, {11, 1789,-15}, {11, 761, 16},
- {11, 760,-16}, {12, 3577, 17}, {12, 3576,-17}, {12, 1519, 18},
- {12, 1518,-18}, {12, 1516, 19}, {13, 7151,-19}, {13, 7128, 20},
- {13, 3035,-20}, {14, 14301, 21}, {14, 14300,-21}, {14, 6069, 22},
- {14, 6068,-22}, {15, 28599, 23}, {15, 28598,-23}, {15, 28597, 24},
- {15, 28596,-24}, {15, 28595, 25}, {15, 28594,-25}, {15, 28593, 26},
- {15, 28592,-26}, {15, 28591, 27}, {15, 28590,-27}, {15, 28589, 28},
- {15, 28588,-28}, {15, 28587, 29}, {15, 28586,-29}, {15, 28585, 30},
- {15, 28584,-30}, {15, 28583, 31}, {15, 28582,-31}, {15, 28581, 32},
- {15, 28580,-32}, {15, 28579, 33}, {15, 28578,-33}, {15, 28577, 34},
- {15, 28576,-34}, {15, 28575, 35}, {15, 28574,-35}, {15, 28573, 36},
- {15, 28572,-36}, {15, 28571, 37}, {15, 28570,-37}, {15, 28569, 38},
- {15, 28568,-38}, {15, 28567, 39}, {15, 28566,-39}, {15, 28565, 40},
- {15, 28564,-40}, {15, 28563, 41}, {15, 28562,-41}, {15, 28561, 42},
- {15, 28560,-42}, {15, 28559, 43}, {15, 28558,-43}, {15, 28557, 44},
- {15, 28556,-44}, {15, 28555, 45}, {15, 28554,-45}, {15, 28553, 46},
- {15, 28552,-46}, {15, 28551, 47}, {15, 28550,-47}, {15, 28549, 48},
- {15, 28548,-48}, {15, 28547, 49}, {15, 28546,-49}, {15, 28545, 50},
- {15, 28544,-50}, {15, 28543, 51}, {15, 28542,-51}, {15, 28541, 52},
- {15, 28540,-52}, {15, 28539, 53}, {15, 28538,-53}, {15, 28537, 54},
- {15, 28536,-54}, {15, 28535, 55}, {15, 28534,-55}, {15, 28533, 56},
- {15, 28532,-56}, {15, 28531, 57}, {15, 28530,-57}, {15, 28529, 58},
- {15, 28528,-58}, {15, 28527, 59}, {15, 28526,-59}, {15, 28525, 60},
- {15, 28524,-60}, {15, 28523, 61}, {15, 28522,-61}, {15, 28521, 62},
- {15, 28520,-62}, {15, 28519, 63}, {15, 28518,-63}, {15, 28517, 64},
- {15, 28516,-64}, { 0, 0, 0}
-};
-
-huff_entry_t scales_e_129[] =
-{
- { 4, 14, 0}, { 4, 11, 1}, { 4, 10, -1}, { 4, 7, 2},
- { 4, 6, -2}, { 4, 3, 3}, { 4, 2, -3}, { 5, 31, 4},
- { 5, 30, -4}, { 5, 25, 5}, { 5, 24, -5}, { 5, 17, 6},
- { 5, 16, -6}, { 5, 9, 7}, { 5, 8, -7}, { 5, 1, 8},
- { 5, 0, -8}, { 6, 53, 9}, { 6, 52, -9}, { 6, 37, 10},
- { 6, 36,-10}, { 6, 21, 11}, { 6, 20,-11}, { 6, 5, 12},
- { 6, 4,-12}, { 7, 109, 13}, { 7, 108,-13}, { 7, 77, 14},
- { 7, 76,-14}, { 7, 45, 15}, { 7, 44,-15}, { 7, 13, 16},
- { 7, 12,-16}, { 8, 221, 17}, { 8, 220,-17}, { 8, 157, 18},
- { 8, 156,-18}, { 8, 93, 19}, { 8, 92,-19}, { 8, 29, 20},
- { 8, 28,-20}, { 9, 445, 21}, { 9, 444,-21}, { 9, 317, 22},
- { 9, 316,-22}, { 9, 189, 23}, { 9, 188,-23}, { 9, 61, 24},
- { 9, 60,-24}, {10, 892, 25}, {10, 639,-25}, {10, 637, 26},
- {10, 636,-26}, {10, 381, 27}, {10, 380,-27}, {10, 125, 28},
- {10, 124,-28}, {11, 1788, 29}, {11, 1787,-29}, {11, 1276, 30},
- {11, 767,-30}, {11, 764, 31}, {11, 255,-31}, {11, 252, 32},
- {12, 3583,-32}, {12, 3579, 33}, {12, 3578,-33}, {12, 2555, 34},
- {12, 2554,-34}, {12, 1531, 35}, {12, 1530,-35}, {12, 507, 36},
- {12, 506,-36}, {13, 7160, 37}, {13, 7147,-37}, {13, 7144, 38},
- {13, 3067,-38}, {13, 3065, 39}, {13, 3064,-39}, {13, 1017, 40},
- {13, 1016,-40}, {14, 14330, 41}, {14, 14329,-41}, {14, 14291, 42},
- {14, 14290,-42}, {14, 6132, 43}, {14, 2039,-43}, {14, 2038, 44},
- {14, 2037,-44}, {15, 28663, 45}, {15, 28662,-45}, {15, 28585, 46},
- {15, 28584,-46}, {15, 12267, 47}, {15, 12266,-47}, {15, 4073, 48},
- {15, 4072,-48}, {16, 57315, 49}, {16, 57314,-49}, {16, 57313, 50},
- {16, 57312,-50}, {16, 57311, 51}, {16, 57310,-51}, {16, 57309, 52},
- {16, 57308,-52}, {16, 57307, 53}, {16, 57306,-53}, {16, 57305, 54},
- {16, 57304,-54}, {16, 57303, 55}, {16, 57302,-55}, {16, 57301, 56},
- {16, 57300,-56}, {16, 57299, 57}, {16, 57298,-57}, {16, 57297, 58},
- {16, 57296,-58}, {16, 57295, 59}, {16, 57294,-59}, {16, 57293, 60},
- {16, 57292,-60}, {16, 57291, 61}, {16, 57290,-61}, {16, 57289, 62},
- {16, 57288,-62}, {16, 57175, 63}, {16, 57174,-63}, {16, 57173, 64},
- {16, 57172,-64}, { 0, 0, 0}
-};
-
-huff_entry_t *scales_129[] =
-{
- scales_a_129,
- scales_b_129,
- scales_c_129,
- scales_d_129,
- scales_e_129
-};
-
-huff_entry_t bitalloc_a_3[] =
-{
- { 1, 0, 0}, { 2, 2, 1}, { 2, 3, -1}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_a_4[] =
-{
- { 1, 0, 0}, { 2, 2, 1}, { 3, 6, 2}, { 3, 7, 3},
- { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_b_4[] =
-{
- { 2, 2, 0}, { 3, 6, 1}, { 3, 7, 2}, { 1, 0, 3},
- { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_c_4[] =
-{
- { 3, 6, 0}, { 3, 7, 1}, { 1, 0, 2}, { 2, 2, 3},
- { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_d_4[] =
-{
- { 2, 0, 0}, { 2, 1, 1}, { 2, 2, 2}, { 2, 3, 3},
- { 0, 0, 0}
-};
-
-huff_entry_t *tmode[] =
-{
- bitalloc_a_4,
- bitalloc_b_4,
- bitalloc_c_4,
- bitalloc_d_4
-};
-
-huff_entry_t bitalloc_a_5[] =
-{
- { 1, 0, 0}, { 2, 2, 1}, { 3, 6, -1}, { 4, 14, 2},
- { 4, 15, -2}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_b_5[] =
-{
- { 2, 2, 0}, { 2, 0, 1}, { 2, 1, -1}, { 3, 6, 2},
- { 3, 7, -2}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_c_5[] =
-{
- { 1, 0, 0}, { 3, 4, 1}, { 3, 5, -1}, { 3, 6, 2},
- { 3, 7, -2}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_a_7[] =
-{
- { 1, 0, 0}, { 3, 6, 1}, { 3, 5, -1}, { 3, 4, 2},
- { 4, 14, -2}, { 5, 31, 3}, { 5, 30, -3}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_b_7[] =
-{
- { 2, 3, 0}, { 2, 1, 1}, { 2, 0, -1}, { 3, 4, 2},
- { 4, 11, -2}, { 5, 21, 3}, { 5, 20, -3}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_c_7[] =
-{
- { 2, 3, 0}, { 2, 2, 1}, { 2, 1, -1}, { 4, 3, 2},
- { 4, 2, -2}, { 4, 1, 3}, { 4, 0, -3}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_a_9[] =
-{
- { 1, 0, 0}, { 3, 7, 1}, { 3, 5, -1}, { 4, 13, 2},
- { 4, 9, -2}, { 4, 8, 3}, { 5, 25, -3}, { 6, 49, 4},
- { 6, 48, -4}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_b_9[] =
-{
- { 2, 2, 0}, { 2, 0, 1}, { 3, 7, -1}, { 3, 3, 2},
- { 3, 2, -2}, { 5, 27, 3}, { 5, 26, -3}, { 5, 25, 4},
- { 5, 24, -4}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_c_9[] =
-{
- { 2, 2, 0}, { 2, 0, 1}, { 3, 7, -1}, { 3, 6, 2},
- { 3, 2, -2}, { 4, 6, 3}, { 5, 15, -3}, { 6, 29, 4},
- { 6, 28, -4}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_a_13[] =
-{
- { 1, 0, 0}, { 3, 4, 1}, { 4, 15, -1}, { 4, 13, 2},
- { 4, 12, -2}, { 4, 10, 3}, { 5, 29, -3}, { 5, 22, 4},
- { 6, 57, -4}, { 6, 47, 5}, { 6, 46, -5}, { 7, 113, 6},
- { 7, 112, -6}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_b_13[] =
-{
- { 2, 0, 0}, { 3, 6, 1}, { 3, 5, -1}, { 3, 2, 2},
- { 4, 15, -2}, { 4, 9, 3}, { 4, 7, -3}, { 4, 6, 4},
- { 5, 29, -4}, { 5, 17, 5}, { 5, 16, -5}, { 6, 57, 6},
- { 6, 56, -6}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_c_13[] =
-{
- { 3, 5, 0}, { 3, 4, 1}, { 3, 3, -1}, { 3, 2, 2},
- { 3, 0, -2}, { 4, 15, 3}, { 4, 14, -3}, { 4, 12, 4},
- { 4, 3, -4}, { 5, 27, 5}, { 5, 26, -5}, { 5, 5, 6},
- { 5, 4, -6}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_a_17[] =
-{
- { 2, 1, 0}, { 3, 7, 1}, { 3, 6, -1}, { 3, 4, 2},
- { 3, 1, -2}, { 4, 11, 3}, { 4, 10, -3}, { 4, 0, 4},
- { 5, 3, -4}, { 6, 4, 5}, { 7, 11, -5}, { 8, 20, 6},
- { 9, 43, -6}, {10, 84, 7}, {11, 171, -7}, {12, 341, 8},
- {12, 340, -8}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_b_17[] =
-{
- { 2, 0, 0}, { 3, 6, 1}, { 3, 5, -1}, { 3, 2, 2},
- { 4, 15, -2}, { 4, 9, 3}, { 4, 8, -3}, { 5, 29, 4},
- { 5, 28, -4}, { 5, 14, 5}, { 5, 13, -5}, { 6, 30, 6},
- { 6, 25, -6}, { 6, 24, 7}, { 7, 63, -7}, { 8, 125, 8},
- { 8, 124, -8}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_c_17[] =
-{
- { 3, 6, 0}, { 3, 4, 1}, { 3, 3, -1}, { 3, 0, 2},
- { 4, 15, -2}, { 4, 11, 3}, { 4, 10, -3}, { 4, 4, 4},
- { 4, 3, -4}, { 5, 29, 5}, { 5, 28, -5}, { 5, 10, 6},
- { 5, 5, -6}, { 5, 4, 7}, { 6, 23, -7}, { 7, 45, 8},
- { 7, 44, -8}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_d_17[] =
-{
- { 1, 0, 0}, { 3, 7, 1}, { 3, 6, -1}, { 4, 11, 2},
- { 4, 10, -2}, { 5, 19, 3}, { 5, 18, -3}, { 6, 35, 4},
- { 6, 34, -4}, { 7, 67, 5}, { 7, 66, -5}, { 8, 131, 6},
- { 8, 130, -6}, { 9, 259, 7}, { 9, 258, -7}, { 9, 257, 8},
- { 9, 256, -8}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_e_17[] =
-{
- { 1, 0, 0}, { 3, 5, 1}, { 3, 4, -1}, { 4, 12, 2},
- { 5, 31, -2}, { 5, 28, 3}, { 5, 27, -3}, { 6, 60, 4},
- { 6, 59, -4}, { 6, 53, 5}, { 6, 52, -5}, { 7, 122, 6},
- { 7, 117, -6}, { 8, 247, 7}, { 8, 246, -7}, { 8, 233, 8},
- { 8, 232, -8}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_f_17[] =
-{
- { 3, 6, 0}, { 3, 5, 1}, { 3, 4, -1}, { 3, 2, 2},
- { 3, 1, -2}, { 4, 15, 3}, { 4, 14, -3}, { 4, 6, 4},
- { 4, 1, -4}, { 5, 14, 5}, { 5, 1, -5}, { 6, 31, 6},
- { 6, 30, -6}, { 6, 0, 7}, { 7, 3, -7}, { 8, 5, 8},
- { 8, 4, -8}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_g_17[] =
-{
- { 2, 2, 0}, { 3, 7, 1}, { 3, 6, -1}, { 3, 1, 2},
- { 3, 0, -2}, { 4, 5, 3}, { 4, 4, -3}, { 5, 14, 4},
- { 5, 13, -4}, { 6, 30, 5}, { 6, 25, -5}, { 7, 62, 6},
- { 7, 49, -6}, { 8, 127, 7}, { 8, 126, -7}, { 8, 97, 8},
- { 8, 96, -8}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_a_25[] =
-{
- { 3, 6, 0}, { 3, 4, 1}, { 3, 3, -1}, { 3, 1, 2},
- { 3, 0, -2}, { 4, 15, 3}, { 4, 14, -3}, { 4, 5, 4},
- { 4, 4, -4}, { 5, 22, 5}, { 5, 21, -5}, { 6, 47, 6},
- { 6, 46, -6}, { 7, 83, 7}, { 7, 82, -7}, { 8, 163, 8},
- { 8, 162, -8}, { 8, 160, 9}, { 9, 323, -9}, {10, 644, 10},
- {11, 1291,-10}, {12, 2580, 11}, {13, 5163,-11}, {14, 10325, 12},
- {14, 10324,-12}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_b_25[] =
-{
- { 3, 5, 0}, { 3, 2, 1}, { 3, 1, -1}, { 4, 15, 2},
- { 4, 14, -2}, { 4, 9, 3}, { 4, 8, -3}, { 4, 6, 4},
- { 4, 1, -4}, { 5, 26, 5}, { 5, 25, -5}, { 5, 15, 6},
- { 5, 14, -6}, { 6, 55, 7}, { 6, 54, -7}, { 6, 49, 8},
- { 6, 48, -8}, { 6, 1, 9}, { 6, 0, -9}, { 7, 6, 10},
- { 7, 5,-10}, { 7, 4, 11}, { 8, 15,-11}, { 9, 29, 12},
- { 9, 28,-12}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_c_25[] =
-{
- { 3, 1, 0}, { 4, 15, 1}, { 4, 14, -1}, { 4, 12, 2},
- { 4, 11, -2}, { 4, 9, 3}, { 4, 8, -3}, { 4, 6, 4},
- { 4, 5, -4}, { 4, 1, 5}, { 4, 0, -5}, { 5, 26, 6},
- { 5, 21, -6}, { 5, 15, 7}, { 5, 14, -7}, { 5, 8, 8},
- { 6, 55, -8}, { 6, 41, 9}, { 6, 40, -9}, { 6, 18, 10},
- { 7, 109,-10}, { 7, 108, 11}, { 7, 39,-11}, { 8, 77, 12},
- { 8, 76,-12}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_d_25[] =
-{
- { 2, 2, 0}, { 3, 7, 1}, { 3, 6, -1}, { 3, 1, 2},
- { 3, 0, -2}, { 4, 5, 3}, { 4, 4, -3}, { 5, 13, 4},
- { 5, 12, -4}, { 6, 29, 5}, { 6, 28, -5}, { 7, 62, 6},
- { 7, 61, -6}, { 8, 126, 7}, { 8, 121, -7}, { 9, 255, 8},
- { 9, 254, -8}, {10, 483, 9}, {10, 482, -9}, {11, 963, 10},
- {11, 962,-10}, {12, 1923, 11}, {12, 1922,-11}, {12, 1921, 12},
- {12, 1920,-12}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_e_25[] =
-{
- { 2, 3, 0}, { 3, 3, 1}, { 3, 2, -1}, { 4, 11, 2},
- { 4, 10, -2}, { 4, 1, 3}, { 4, 0, -3}, { 5, 17, 4},
- { 5, 16, -4}, { 5, 5, 5}, { 5, 4, -5}, { 6, 38, 6},
- { 6, 37, -6}, { 6, 14, 7}, { 6, 13, -7}, { 7, 79, 8},
- { 7, 78, -8}, { 7, 72, 9}, { 7, 31, -9}, { 7, 25, 10},
- { 7, 24,-10}, { 8, 147, 11}, { 8, 146,-11}, { 8, 61, 12},
- { 8, 60,-12}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_f_25[] =
-{
- { 3, 1, 0}, { 3, 0, 1}, { 4, 15, -1}, { 4, 14, 2},
- { 4, 13, -2}, { 4, 11, 3}, { 4, 10, -3}, { 4, 8, 4},
- { 4, 7, -4}, { 4, 5, 5}, { 4, 4, -5}, { 5, 24, 6},
- { 5, 19, -6}, { 5, 13, 7}, { 5, 12, -7}, { 6, 37, 8},
- { 6, 36, -8}, { 7, 102, 9}, { 7, 101, -9}, { 8, 207, 10},
- { 8, 206,-10}, { 8, 200, 11}, { 9, 403,-11}, {10, 805, 12},
- {10, 804,-12}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_g_25[] =
-{
- { 2, 1, 0}, { 3, 6, 1}, { 3, 5, -1}, { 3, 0, 2},
- { 4, 15, -2}, { 4, 8, 3}, { 4, 3, -3}, { 5, 28, 4},
- { 5, 19, -4}, { 5, 4, 5}, { 6, 59, -5}, { 6, 36, 6},
- { 6, 11, -6}, { 7, 116, 7}, { 7, 75, -7}, { 7, 21, 8},
- { 7, 20, -8}, { 8, 149, 9}, { 8, 148, -9}, { 9, 470, 10},
- { 9, 469,-10}, {10, 943, 11}, {10, 942,-11}, {10, 937, 12},
- {10, 936,-12}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_a_33[] =
-{
- { 3, 2, 0}, { 3, 1, 1}, { 3, 0, -1}, { 4, 14, 2},
- { 4, 13, -2}, { 4, 12, 3}, { 4, 11, -3}, { 4, 9, 4},
- { 4, 8, -4}, { 4, 6, 5}, { 5, 31, -5}, { 5, 20, 6},
- { 5, 15, -6}, { 6, 61, 7}, { 6, 60, -7}, { 6, 29, 8},
- { 6, 28, -8}, { 7, 85, 9}, { 7, 84, -9}, { 8, 174, 10},
- { 8, 173,-10}, { 9, 351, 11}, { 9, 350,-11}, {10, 691, 12},
- {10, 690,-12}, {11, 1379, 13}, {11, 1378,-13}, {12, 2755, 14},
- {12, 2754,-14}, {13, 5507, 15}, {13, 5506,-15}, {13, 5505, 16},
- {13, 5504,-16}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_b_33[] =
-{
- { 3, 1, 0}, { 4, 15, 1}, { 4, 14, -1}, { 4, 11, 2},
- { 4, 10, -2}, { 4, 8, 3}, { 4, 7, -3}, { 4, 4, 4},
- { 4, 1, -4}, { 5, 27, 5}, { 5, 26, -5}, { 5, 19, 6},
- { 5, 18, -6}, { 5, 12, 7}, { 5, 11, -7}, { 5, 1, 8},
- { 5, 0, -8}, { 6, 50, 9}, { 6, 49, -9}, { 6, 26, 10},
- { 6, 21,-10}, { 7, 103, 11}, { 7, 102,-11}, { 7, 96, 12},
- { 7, 55,-12}, { 7, 41, 13}, { 7, 40,-13}, { 8, 194, 14},
- { 8, 109,-14}, { 8, 108, 15}, { 9, 391,-15}, {10, 781, 16},
- {10, 780,-16}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_c_33[] =
-{
- { 4, 13, 0}, { 4, 11, 1}, { 4, 10, -1}, { 4, 8, 2},
- { 4, 7, -2}, { 4, 4, 3}, { 4, 3, -3}, { 4, 2, 4},
- { 4, 1, -4}, { 5, 30, 5}, { 5, 29, -5}, { 5, 25, 6},
- { 5, 24, -6}, { 5, 19, 7}, { 5, 18, -7}, { 5, 11, 8},
- { 5, 10, -8}, { 5, 0, 9}, { 6, 63, -9}, { 6, 62, 10},
- { 6, 57,-10}, { 6, 27, 11}, { 6, 26,-11}, { 6, 24, 12},
- { 6, 3,-12}, { 7, 113, 13}, { 7, 112,-13}, { 7, 50, 14},
- { 7, 5,-14}, { 7, 4, 15}, { 8, 103,-15}, { 9, 205, 16},
- { 9, 204,-16}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_d_33[] =
-{
- { 2, 1, 0}, { 3, 6, 1}, { 3, 5, -1}, { 3, 0, 2},
- { 4, 15, -2}, { 4, 8, 3}, { 4, 3, -3}, { 5, 28, 4},
- { 5, 19, -4}, { 5, 4, 5}, { 6, 59, -5}, { 6, 36, 6},
- { 6, 11, -6}, { 7, 116, 7}, { 7, 75, -7}, { 7, 21, 8},
- { 7, 20, -8}, { 8, 149, 9}, { 8, 148, -9}, { 9, 469, 10},
- { 9, 468,-10}, {10, 941, 11}, {10, 940,-11}, {11, 1885, 12},
- {11, 1884,-12}, {12, 3773, 13}, {12, 3772,-13}, {13, 7551, 14},
- {13, 7550,-14}, {14, 15099, 15}, {14, 15098,-15}, {14, 15097, 16},
- {14, 15096,-16}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_e_33[] =
-{
- { 2, 2, 0}, { 3, 2, 1}, { 3, 1, -1}, { 4, 12, 2},
- { 4, 7, -2}, { 4, 0, 3}, { 5, 31, -3}, { 5, 27, 4},
- { 5, 26, -4}, { 5, 3, 5}, { 5, 2, -5}, { 6, 59, 6},
- { 6, 58, -6}, { 6, 27, 7}, { 6, 26, -7}, { 7, 123, 8},
- { 7, 122, -8}, { 7, 120, 9}, { 7, 115, -9}, { 7, 112, 10},
- { 7, 51,-10}, { 7, 49, 11}, { 7, 48,-11}, { 8, 242, 12},
- { 8, 229,-12}, { 8, 227, 13}, { 8, 226,-13}, { 8, 101, 14},
- { 8, 100,-14}, { 9, 487, 15}, { 9, 486,-15}, { 9, 457, 16},
- { 9, 456,-16}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_f_33[] =
-{
- { 4, 13, 0}, { 4, 12, 1}, { 4, 11, -1}, { 4, 9, 2},
- { 4, 8, -2}, { 4, 7, 3}, { 4, 6, -3}, { 4, 4, 4},
- { 4, 3, -4}, { 4, 1, 5}, { 4, 0, -5}, { 5, 30, 6},
- { 5, 29, -6}, { 5, 21, 7}, { 5, 20, -7}, { 5, 10, 8},
- { 5, 5, -8}, { 6, 63, 9}, { 6, 62, -9}, { 6, 56, 10},
- { 6, 23,-10}, { 6, 9, 11}, { 6, 8,-11}, { 7, 45, 12},
- { 7, 44,-12}, { 8, 230, 13}, { 8, 229,-13}, { 9, 463, 14},
- { 9, 462,-14}, { 9, 456, 15}, {10, 915,-15}, {11, 1829, 16},
- {11, 1828,-16}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_g_33[] =
-{
- { 3, 6, 0}, { 3, 3, 1}, { 3, 2, -1}, { 4, 15, 2},
- { 4, 14, -2}, { 4, 9, 3}, { 4, 8, -3}, { 4, 1, 4},
- { 4, 0, -4}, { 5, 22, 5}, { 5, 21, -5}, { 5, 6, 6},
- { 5, 5, -6}, { 6, 46, 7}, { 6, 41, -7}, { 6, 14, 8},
- { 6, 9, -8}, { 7, 94, 9}, { 7, 81, -9}, { 7, 30, 10},
- { 7, 17,-10}, { 8, 191, 11}, { 8, 190,-11}, { 8, 63, 12},
- { 8, 62,-12}, { 8, 32, 13}, { 9, 323,-13}, { 9, 321, 14},
- { 9, 320,-14}, { 9, 67, 15}, { 9, 66,-15}, {10, 645, 16},
- {10, 644,-16}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_a_65[] =
-{
- { 4, 6, 0}, { 4, 5, 1}, { 4, 4, -1}, { 4, 2, 2},
- { 4, 1, -2}, { 4, 0, 3}, { 5, 31, -3}, { 5, 29, 4},
- { 5, 28, -4}, { 5, 27, 5}, { 5, 26, -5}, { 5, 24, 6},
- { 5, 23, -6}, { 5, 21, 7}, { 5, 20, -7}, { 5, 18, 8},
- { 5, 17, -8}, { 5, 14, 9}, { 5, 7, -9}, { 5, 6, 10},
- { 6, 61,-10}, { 6, 50, 11}, { 6, 45,-11}, { 6, 38, 12},
- { 6, 33,-12}, { 6, 31, 13}, { 6, 30,-13}, { 7, 120, 14},
- { 7, 103,-14}, { 7, 89, 15}, { 7, 88,-15}, { 7, 65, 16},
- { 7, 64,-16}, { 8, 205, 17}, { 8, 204,-17}, { 8, 157, 18},
- { 8, 156,-18}, { 9, 486, 19}, { 9, 485,-19}, { 9, 318, 20},
- { 9, 317,-20}, {10, 975, 21}, {10, 974,-21}, {10, 639, 22},
- {10, 638,-22}, {11, 1939, 23}, {11, 1938,-23}, {11, 1936, 24},
- {11, 1267,-24}, {11, 1264, 25}, {12, 3875,-25}, {12, 2532, 26},
- {12, 2531,-26}, {13, 7749, 27}, {13, 7748,-27}, {13, 5061, 28},
- {13, 5060,-28}, {14, 10133, 29}, {14, 10132,-29}, {15, 20269, 30},
- {15, 20268,-30}, {16, 40543, 31}, {16, 40542,-31}, {16, 40541, 32},
- {16, 40540,-32}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_b_65[] =
-{
- { 4, 4, 0}, { 4, 2, 1}, { 4, 1, -1}, { 5, 30, 2},
- { 5, 29, -2}, { 5, 26, 3}, { 5, 25, -3}, { 5, 23, 4},
- { 5, 22, -4}, { 5, 19, 5}, { 5, 18, -5}, { 5, 16, 6},
- { 5, 15, -6}, { 5, 12, 7}, { 5, 11, -7}, { 5, 7, 8},
- { 5, 6, -8}, { 6, 63, 9}, { 6, 62, -9}, { 6, 56, 10},
- { 6, 55,-10}, { 6, 49, 11}, { 6, 48,-11}, { 6, 41, 12},
- { 6, 40,-12}, { 6, 34, 13}, { 6, 29,-13}, { 6, 26, 14},
- { 6, 21,-14}, { 6, 20, 15}, { 6, 3,-15}, { 6, 0, 16},
- { 7, 115,-16}, { 7, 109, 17}, { 7, 108,-17}, { 7, 86, 18},
- { 7, 85,-18}, { 7, 70, 19}, { 7, 57,-19}, { 7, 56, 20},
- { 7, 55,-20}, { 7, 4, 21}, { 7, 3,-21}, { 8, 229, 22},
- { 8, 228,-22}, { 8, 175, 23}, { 8, 174,-23}, { 8, 143, 24},
- { 8, 142,-24}, { 8, 108, 25}, { 8, 11,-25}, { 8, 10, 26},
- { 8, 5,-26}, { 9, 339, 27}, { 9, 338,-27}, { 9, 336, 28},
- { 9, 219,-28}, { 9, 9, 29}, { 9, 8,-29}, {10, 674, 30},
- {10, 437,-30}, {10, 436, 31}, {11, 1351,-31}, {12, 2701, 32},
- {12, 2700,-32}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_c_65[] =
-{
- { 5, 28, 0}, { 5, 25, 1}, { 5, 24, -1}, { 5, 23, 2},
- { 5, 22, -2}, { 5, 19, 3}, { 5, 18, -3}, { 5, 16, 4},
- { 5, 15, -4}, { 5, 13, 5}, { 5, 12, -5}, { 5, 10, 6},
- { 5, 9, -6}, { 5, 7, 7}, { 5, 6, -7}, { 5, 4, 8},
- { 5, 3, -8}, { 5, 1, 9}, { 5, 0, -9}, { 6, 62, 10},
- { 6, 61,-10}, { 6, 59, 11}, { 6, 58,-11}, { 6, 54, 12},
- { 6, 53,-12}, { 6, 43, 13}, { 6, 42,-13}, { 6, 40, 14},
- { 6, 35,-14}, { 6, 29, 15}, { 6, 28,-15}, { 6, 17, 16},
- { 6, 16,-16}, { 6, 11, 17}, { 6, 10,-17}, { 6, 4, 18},
- { 7, 127,-18}, { 7, 121, 19}, { 7, 120,-19}, { 7, 110, 20},
- { 7, 105,-20}, { 7, 83, 21}, { 7, 82,-21}, { 7, 68, 22},
- { 7, 47,-22}, { 7, 46, 23}, { 7, 45,-23}, { 7, 11, 24},
- { 7, 10,-24}, { 8, 252, 25}, { 8, 223,-25}, { 8, 209, 26},
- { 8, 208,-26}, { 8, 138, 27}, { 8, 89,-27}, { 8, 88, 28},
- { 9, 507,-28}, { 9, 445, 29}, { 9, 444,-29}, { 9, 278, 30},
- {10, 1013,-30}, {10, 1012, 31}, {10, 559,-31}, {11, 1117, 32},
- {11, 1116,-32}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_d_65[] =
-{
- { 3, 4, 0}, { 3, 1, 1}, { 3, 0, -1}, { 4, 13, 2},
- { 4, 12, -2}, { 4, 7, 3}, { 4, 6, -3}, { 5, 31, 4},
- { 5, 30, -4}, { 5, 23, 5}, { 5, 22, -5}, { 5, 11, 6},
- { 5, 10, -6}, { 6, 59, 7}, { 6, 58, -7}, { 6, 43, 8},
- { 6, 42, -8}, { 6, 19, 9}, { 6, 18, -9}, { 7, 115, 10},
- { 7, 114,-10}, { 7, 83, 11}, { 7, 82,-11}, { 7, 35, 12},
- { 7, 34,-12}, { 8, 227, 13}, { 8, 226,-13}, { 8, 163, 14},
- { 8, 162,-14}, { 8, 160, 15}, { 8, 67,-15}, { 8, 64, 16},
- { 9, 451,-16}, { 9, 448, 17}, { 9, 323,-17}, { 9, 132, 18},
- { 9, 131,-18}, {10, 900, 19}, {10, 899,-19}, {10, 644, 20},
- {10, 267,-20}, {10, 261, 21}, {10, 260,-21}, {11, 1797, 22},
- {11, 1796,-22}, {11, 533, 23}, {11, 532,-23}, {12, 3605, 24},
- {12, 3604,-24}, {12, 2582, 25}, {12, 2581,-25}, {13, 7215, 26},
- {13, 7214,-26}, {13, 5167, 27}, {13, 5166,-27}, {13, 5160, 28},
- {14, 14427,-28}, {14, 10323, 29}, {14, 10322,-29}, {15, 28853, 30},
- {15, 28852,-30}, {15, 28851, 31}, {15, 28850,-31}, {15, 28849, 32},
- {15, 28848,-32}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_e_65[] =
-{
- { 3, 4, 0}, { 3, 0, 1}, { 4, 15, -1}, { 4, 7, 2},
- { 4, 6, -2}, { 5, 29, 3}, { 5, 28, -3}, { 5, 23, 4},
- { 5, 22, -4}, { 5, 10, 5}, { 5, 9, -5}, { 5, 6, 6},
- { 5, 5, -6}, { 6, 54, 7}, { 6, 53, -7}, { 6, 48, 8},
- { 6, 43, -8}, { 6, 40, 9}, { 6, 23, -9}, { 6, 16, 10},
- { 6, 15,-10}, { 6, 9, 11}, { 6, 8,-11}, { 7, 105, 12},
- { 7, 104,-12}, { 7, 100, 13}, { 7, 99,-13}, { 7, 84, 14},
- { 7, 83,-14}, { 7, 45, 15}, { 7, 44,-15}, { 7, 29, 16},
- { 7, 28,-16}, { 8, 221, 17}, { 8, 220,-17}, { 8, 206, 18},
- { 8, 205,-18}, { 8, 202, 19}, { 8, 197,-19}, { 8, 171, 20},
- { 8, 170,-20}, { 8, 164, 21}, { 8, 71,-21}, { 8, 69, 22},
- { 8, 68,-22}, { 9, 446, 23}, { 9, 445,-23}, { 9, 415, 24},
- { 9, 414,-24}, { 9, 408, 25}, { 9, 407,-25}, { 9, 393, 26},
- { 9, 392,-26}, { 9, 331, 27}, { 9, 330,-27}, { 9, 141, 28},
- { 9, 140,-28}, {10, 895, 29}, {10, 894,-29}, {10, 889, 30},
- {10, 888,-30}, {10, 819, 31}, {10, 818,-31}, {10, 813, 32},
- {10, 812,-32}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_f_65[] =
-{
- { 3, 6, 0}, { 3, 3, 1}, { 3, 2, -1}, { 4, 15, 2},
- { 4, 14, -2}, { 4, 9, 3}, { 4, 8, -3}, { 4, 1, 4},
- { 4, 0, -4}, { 5, 21, 5}, { 5, 20, -5}, { 5, 5, 6},
- { 5, 4, -6}, { 6, 45, 7}, { 6, 44, -7}, { 6, 13, 8},
- { 6, 12, -8}, { 7, 93, 9}, { 7, 92, -9}, { 7, 29, 10},
- { 7, 28,-10}, { 8, 189, 11}, { 8, 188,-11}, { 8, 61, 12},
- { 8, 60,-12}, { 9, 381, 13}, { 9, 380,-13}, { 9, 125, 14},
- { 9, 124,-14}, {10, 765, 15}, {10, 764,-15}, {10, 252, 16},
- {11, 1535,-16}, {11, 1532, 17}, {11, 511,-17}, {11, 506, 18},
- {12, 3069,-18}, {12, 3067, 19}, {12, 3066,-19}, {12, 1015, 20},
- {12, 1014,-20}, {13, 6136, 21}, {13, 2043,-21}, {13, 2035, 22},
- {13, 2034,-22}, {14, 12275, 23}, {14, 12274,-23}, {14, 4085, 24},
- {14, 4084,-24}, {14, 4083, 25}, {14, 4082,-25}, {14, 4081, 26},
- {14, 4080,-26}, {14, 4079, 27}, {14, 4078,-27}, {14, 4077, 28},
- {14, 4076,-28}, {14, 4075, 29}, {14, 4074,-29}, {14, 4073, 30},
- {14, 4072,-30}, {14, 4067, 31}, {14, 4066,-31}, {14, 4065, 32},
- {14, 4064,-32}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_g_65[] =
-{
- { 4, 14, 0}, { 4, 11, 1}, { 4, 10, -1}, { 4, 8, 2},
- { 4, 6, -2}, { 4, 4, 3}, { 4, 3, -3}, { 4, 0, 4},
- { 5, 31, -4}, { 5, 26, 5}, { 5, 25, -5}, { 5, 18, 6},
- { 5, 15, -6}, { 5, 10, 7}, { 5, 5, -7}, { 5, 2, 8},
- { 6, 61, -8}, { 6, 54, 9}, { 6, 49, -9}, { 6, 38, 10},
- { 6, 29,-10}, { 6, 22, 11}, { 6, 9,-11}, { 6, 6, 12},
- { 7, 121,-12}, { 7, 110, 13}, { 7, 97,-13}, { 7, 78, 14},
- { 7, 57,-14}, { 7, 46, 15}, { 7, 17,-15}, { 7, 14, 16},
- { 8, 241,-16}, { 8, 223, 17}, { 8, 222,-17}, { 8, 159, 18},
- { 8, 158,-18}, { 8, 95, 19}, { 8, 94,-19}, { 8, 31, 20},
- { 8, 30,-20}, { 9, 480, 21}, { 9, 387,-21}, { 9, 384, 22},
- { 9, 227,-22}, { 9, 225, 23}, { 9, 224,-23}, { 9, 65, 24},
- { 9, 64,-24}, {10, 962, 25}, {10, 773,-25}, {10, 771, 26},
- {10, 770,-26}, {10, 452, 27}, {10, 135,-27}, {10, 133, 28},
- {10, 132,-28}, {11, 1927, 29}, {11, 1926,-29}, {11, 1545, 30},
- {11, 1544,-30}, {11, 907, 31}, {11, 906,-31}, {11, 269, 32},
- {11, 268,-32}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_a_129[] =
-{
- { 4, 8, 0}, { 4, 10, 1}, { 4, 9, -1}, { 4, 0, 2},
- { 5, 31, -2}, { 5, 24, 3}, { 5, 23, -3}, { 5, 12, 4},
- { 5, 11, -4}, { 5, 5, 5}, { 5, 4, -5}, { 6, 60, 6},
- { 6, 58, -6}, { 6, 54, 7}, { 6, 53, -7}, { 6, 45, 8},
- { 6, 44, -8}, { 6, 28, 9}, { 6, 27, -9}, { 6, 19, 10},
- { 6, 18,-10}, { 6, 14, 11}, { 6, 13,-11}, { 6, 6, 12},
- { 6, 5,-12}, { 7, 122, 13}, { 7, 119,-13}, { 7, 113, 14},
- { 7, 112,-14}, { 7, 104, 15}, { 7, 103,-15}, { 7, 100, 16},
- { 7, 63,-16}, { 7, 60, 17}, { 7, 59,-17}, { 7, 52, 18},
- { 7, 43,-18}, { 7, 40, 19}, { 7, 35,-19}, { 7, 32, 20},
- { 7, 31,-20}, { 7, 15, 21}, { 7, 14,-21}, { 8, 247, 22},
- { 8, 246,-22}, { 8, 231, 23}, { 8, 230,-23}, { 8, 223, 24},
- { 8, 222,-24}, { 8, 211, 25}, { 8, 210,-25}, { 8, 203, 26},
- { 8, 202,-26}, { 8, 123, 27}, { 8, 122,-27}, { 8, 116, 28},
- { 8, 107,-28}, { 8, 84, 29}, { 8, 83,-29}, { 8, 68, 30},
- { 8, 67,-30}, { 8, 60, 31}, { 8, 51,-31}, { 8, 49, 32},
- { 8, 48,-32}, { 8, 17, 33}, { 8, 16,-33}, { 9, 474, 34},
- { 9, 473,-34}, { 9, 458, 35}, { 9, 457,-35}, { 9, 442, 36},
- { 9, 441,-36}, { 9, 411, 37}, { 9, 410,-37}, { 9, 251, 38},
- { 9, 250,-38}, { 9, 248, 39}, { 9, 235,-39}, { 9, 213, 40},
- { 9, 212,-40}, { 9, 170, 41}, { 9, 165,-41}, { 9, 139, 42},
- { 9, 138,-42}, { 9, 132, 43}, { 9, 123,-43}, { 9, 101, 44},
- { 9, 100,-44}, { 9, 37, 45}, { 9, 36,-45}, {10, 950, 46},
- {10, 945,-46}, {10, 919, 47}, {10, 918,-47}, {10, 912, 48},
- {10, 887,-48}, {10, 881, 49}, {10, 880,-49}, {10, 818, 50},
- {10, 817,-50}, {10, 499, 51}, {10, 498,-51}, {10, 469, 52},
- {10, 468,-52}, {10, 343, 53}, {10, 342,-53}, {10, 329, 54},
- {10, 328,-54}, {10, 267, 55}, {10, 266,-55}, {10, 245, 56},
- {10, 244,-56}, {10, 79, 57}, {10, 78,-57}, {10, 77, 58},
- {10, 76,-58}, {11, 1903, 59}, {11, 1902,-59}, {11, 1889, 60},
- {11, 1888,-60}, {11, 1827, 61}, {11, 1826,-61}, {11, 1773, 62},
- {11, 1772,-62}, {11, 1639, 63}, {11, 1638,-63}, {11, 1633, 64},
- {11, 1632,-64}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_b_129[] =
-{
- { 5, 10, 0}, { 5, 7, 1}, { 5, 6, -1}, { 5, 4, 2},
- { 5, 3, -2}, { 5, 0, 3}, { 6, 63, -3}, { 6, 60, 4},
- { 6, 59, -4}, { 6, 57, 5}, { 6, 56, -5}, { 6, 53, 6},
- { 6, 52, -6}, { 6, 50, 7}, { 6, 49, -7}, { 6, 46, 8},
- { 6, 45, -8}, { 6, 43, 9}, { 6, 42, -9}, { 6, 39, 10},
- { 6, 38,-10}, { 6, 35, 11}, { 6, 34,-11}, { 6, 32, 12},
- { 6, 31,-12}, { 6, 28, 13}, { 6, 27,-13}, { 6, 25, 14},
- { 6, 24,-14}, { 6, 22, 15}, { 6, 19,-15}, { 6, 16, 16},
- { 6, 11,-16}, { 6, 5, 17}, { 6, 4,-17}, { 7, 125, 18},
- { 7, 124,-18}, { 7, 122, 19}, { 7, 117,-19}, { 7, 110, 20},
- { 7, 109,-20}, { 7, 103, 21}, { 7, 102,-21}, { 7, 96, 22},
- { 7, 95,-22}, { 7, 89, 23}, { 7, 88,-23}, { 7, 81, 24},
- { 7, 80,-24}, { 7, 74, 25}, { 7, 73,-25}, { 7, 66, 26},
- { 7, 61,-26}, { 7, 59, 27}, { 7, 58,-27}, { 7, 52, 28},
- { 7, 47,-28}, { 7, 37, 29}, { 7, 36,-29}, { 7, 21, 30},
- { 7, 20,-30}, { 7, 6, 31}, { 7, 5,-31}, { 8, 247, 32},
- { 8, 246,-32}, { 8, 223, 33}, { 8, 222,-33}, { 8, 217, 34},
- { 8, 216,-34}, { 8, 189, 35}, { 8, 188,-35}, { 8, 166, 36},
- { 8, 165,-36}, { 8, 151, 37}, { 8, 150,-37}, { 8, 144, 38},
- { 8, 135,-38}, { 8, 121, 39}, { 8, 120,-39}, { 8, 106, 40},
- { 8, 93,-40}, { 8, 71, 41}, { 8, 70,-41}, { 8, 68, 42},
- { 8, 15,-42}, { 8, 9, 43}, { 8, 8,-43}, { 9, 466, 44},
- { 9, 465,-44}, { 9, 391, 45}, { 9, 390,-45}, { 9, 388, 46},
- { 9, 335,-46}, { 9, 329, 47}, { 9, 328,-47}, { 9, 269, 48},
- { 9, 268,-48}, { 9, 215, 49}, { 9, 214,-49}, { 9, 184, 50},
- { 9, 139,-50}, { 9, 29, 51}, { 9, 28,-51}, {10, 934, 52},
- {10, 929,-52}, {10, 779, 53}, {10, 778,-53}, {10, 668, 54},
- {10, 583,-54}, {10, 582, 55}, {10, 581,-55}, {10, 371, 56},
- {10, 370,-56}, {10, 276, 57}, {11, 1871,-57}, {11, 1857, 58},
- {11, 1856,-58}, {11, 1338, 59}, {11, 1161,-59}, {11, 1160, 60},
- {11, 555,-60}, {12, 3741, 61}, {12, 3740,-61}, {12, 2678, 62},
- {12, 1109,-62}, {12, 1108, 63}, {13, 5359,-63}, {14, 10717, 64},
- {14, 10716,-64}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_c_129[] =
-{
- { 6, 58, 0}, { 6, 55, 1}, { 6, 54, -1}, { 6, 52, 2},
- { 6, 51, -2}, { 6, 49, 3}, { 6, 48, -3}, { 6, 46, 4},
- { 6, 45, -4}, { 6, 43, 5}, { 6, 42, -5}, { 6, 40, 6},
- { 6, 39, -6}, { 6, 37, 7}, { 6, 36, -7}, { 6, 34, 8},
- { 6, 33, -8}, { 6, 30, 9}, { 6, 29, -9}, { 6, 27, 10},
- { 6, 26,-10}, { 6, 24, 11}, { 6, 23,-11}, { 6, 21, 12},
- { 6, 20,-12}, { 6, 18, 13}, { 6, 17,-13}, { 6, 14, 14},
- { 6, 13,-14}, { 6, 12, 15}, { 6, 11,-15}, { 6, 8, 16},
- { 6, 7,-16}, { 6, 6, 17}, { 6, 5,-17}, { 6, 3, 18},
- { 6, 2,-18}, { 7, 127, 19}, { 7, 126,-19}, { 7, 124, 20},
- { 7, 123,-20}, { 7, 121, 21}, { 7, 120,-21}, { 7, 118, 22},
- { 7, 115,-22}, { 7, 113, 23}, { 7, 112,-23}, { 7, 106, 24},
- { 7, 101,-24}, { 7, 95, 25}, { 7, 94,-25}, { 7, 88, 26},
- { 7, 83,-26}, { 7, 77, 27}, { 7, 76,-27}, { 7, 70, 28},
- { 7, 65,-28}, { 7, 64, 29}, { 7, 63,-29}, { 7, 56, 30},
- { 7, 51,-30}, { 7, 45, 31}, { 7, 44,-31}, { 7, 39, 32},
- { 7, 38,-32}, { 7, 31, 33}, { 7, 30,-33}, { 7, 20, 34},
- { 7, 19,-34}, { 7, 18, 35}, { 7, 9,-35}, { 7, 3, 36},
- { 7, 2,-36}, { 7, 0, 37}, { 8, 251,-37}, { 8, 245, 38},
- { 8, 244,-38}, { 8, 238, 39}, { 8, 229,-39}, { 8, 215, 40},
- { 8, 214,-40}, { 8, 200, 41}, { 8, 179,-41}, { 8, 165, 42},
- { 8, 164,-42}, { 8, 143, 43}, { 8, 142,-43}, { 8, 124, 44},
- { 8, 115,-44}, { 8, 101, 45}, { 8, 100,-45}, { 8, 66, 46},
- { 8, 65,-46}, { 8, 43, 47}, { 8, 42,-47}, { 8, 17, 48},
- { 8, 16,-48}, { 8, 2, 49}, { 9, 501,-49}, { 9, 479, 50},
- { 9, 478,-50}, { 9, 456, 51}, { 9, 403,-51}, { 9, 357, 52},
- { 9, 356,-52}, { 9, 251, 53}, { 9, 250,-53}, { 9, 228, 54},
- { 9, 135,-54}, { 9, 129, 55}, { 9, 128,-55}, { 9, 6, 56},
- {10, 1001,-56}, {10, 1000, 57}, {10, 915,-57}, {10, 805, 58},
- {10, 804,-58}, {10, 458, 59}, {10, 269,-59}, {10, 268, 60},
- {10, 15,-60}, {11, 1829, 61}, {11, 1828,-61}, {11, 918, 62},
- {11, 29,-62}, {11, 28, 63}, {12, 1839,-63}, {13, 3677, 64},
- {13, 3676,-64}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_d_129[] =
-{
- { 4, 9, 0}, { 4, 6, 1}, { 4, 5, -1}, { 4, 2, 2},
- { 4, 1, -2}, { 5, 30, 3}, { 5, 29, -3}, { 5, 26, 4},
- { 5, 25, -4}, { 5, 22, 5}, { 5, 21, -5}, { 5, 16, 6},
- { 5, 15, -6}, { 5, 8, 7}, { 5, 7, -7}, { 5, 0, 8},
- { 6, 63, -8}, { 6, 56, 9}, { 6, 55, -9}, { 6, 48, 10},
- { 6, 47,-10}, { 6, 40, 11}, { 6, 35,-11}, { 6, 28, 12},
- { 6, 19,-12}, { 6, 12, 13}, { 6, 3,-13}, { 7, 124, 14},
- { 7, 115,-14}, { 7, 108, 15}, { 7, 99,-15}, { 7, 92, 16},
- { 7, 83,-16}, { 7, 68, 17}, { 7, 59,-17}, { 7, 36, 18},
- { 7, 27,-18}, { 7, 4, 19}, { 8, 251,-19}, { 8, 228, 20},
- { 8, 219,-20}, { 8, 196, 21}, { 8, 187,-21}, { 8, 164, 22},
- { 8, 139,-22}, { 8, 116, 23}, { 8, 75,-23}, { 8, 52, 24},
- { 8, 11,-24}, { 9, 501, 25}, { 9, 500,-25}, { 9, 437, 26},
- { 9, 436,-26}, { 9, 373, 27}, { 9, 372,-27}, { 9, 277, 28},
- { 9, 276,-28}, { 9, 149, 29}, { 9, 148,-29}, { 9, 21, 30},
- { 9, 20,-30}, {10, 917, 31}, {10, 916,-31}, {10, 789, 32},
- {10, 788,-32}, {10, 661, 33}, {10, 660,-33}, {10, 469, 34},
- {10, 468,-34}, {10, 214, 35}, {10, 213,-35}, {11, 1838, 36},
- {11, 1837,-36}, {11, 1582, 37}, {11, 1581,-37}, {11, 1326, 38},
- {11, 1325,-38}, {11, 942, 39}, {11, 941,-39}, {11, 431, 40},
- {11, 430,-40}, {12, 3679, 41}, {12, 3678,-41}, {12, 3167, 42},
- {12, 3166,-42}, {12, 3160, 43}, {12, 2655,-43}, {12, 2648, 44},
- {12, 1887,-44}, {12, 1880, 45}, {12, 851,-45}, {12, 849, 46},
- {12, 848,-46}, {13, 7346, 47}, {13, 7345,-47}, {13, 6322, 48},
- {13, 5309,-48}, {13, 3773, 49}, {13, 3772,-49}, {13, 3762, 50},
- {13, 1701,-50}, {14, 14695, 51}, {14, 14694,-51}, {14, 14688, 52},
- {14, 12647,-52}, {14, 10617, 53}, {14, 10616,-53}, {14, 10596, 54},
- {14, 7527,-54}, {14, 3401, 55}, {14, 3400,-55}, {15, 29378, 56},
- {15, 25293,-56}, {15, 21195, 57}, {15, 21194,-57}, {15, 15053, 58},
- {15, 15052,-58}, {16, 58759, 59}, {16, 58758,-59}, {16, 50585, 60},
- {16, 50584,-60}, {16, 42399, 61}, {16, 42398,-61}, {16, 42397, 62},
- {16, 42396,-62}, {16, 42395, 63}, {16, 42394,-63}, {16, 42393, 64},
- {16, 42392,-64}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_e_129[] =
-{
- { 5, 12, 0}, { 5, 11, 1}, { 5, 10, -1}, { 5, 9, 2},
- { 5, 8, -2}, { 5, 7, 3}, { 5, 6, -3}, { 5, 4, 4},
- { 5, 3, -4}, { 5, 2, 5}, { 5, 1, -5}, { 5, 0, 6},
- { 6, 63, -6}, { 6, 61, 7}, { 6, 60, -7}, { 6, 59, 8},
- { 6, 58, -8}, { 6, 56, 9}, { 6, 55, -9}, { 6, 53, 10},
- { 6, 52,-10}, { 6, 51, 11}, { 6, 50,-11}, { 6, 47, 12},
- { 6, 46,-12}, { 6, 45, 13}, { 6, 44,-13}, { 6, 42, 14},
- { 6, 41,-14}, { 6, 38, 15}, { 6, 37,-15}, { 6, 36, 16},
- { 6, 35,-16}, { 6, 32, 17}, { 6, 31,-17}, { 6, 29, 18},
- { 6, 28,-18}, { 6, 26, 19}, { 6, 11,-19}, { 7, 125, 20},
- { 7, 124,-20}, { 7, 109, 21}, { 7, 108,-21}, { 7, 98, 22},
- { 7, 97,-22}, { 7, 87, 23}, { 7, 86,-23}, { 7, 79, 24},
- { 7, 78,-24}, { 7, 68, 25}, { 7, 67,-25}, { 7, 60, 26},
- { 7, 55,-26}, { 7, 21, 27}, { 7, 20,-27}, { 8, 230, 28},
- { 8, 229,-28}, { 8, 198, 29}, { 8, 193,-29}, { 8, 163, 30},
- { 8, 162,-30}, { 8, 139, 31}, { 8, 138,-31}, { 8, 123, 32},
- { 8, 122,-32}, { 8, 108, 33}, { 9, 463,-33}, { 9, 457, 34},
- { 9, 456,-34}, { 9, 385, 35}, { 9, 384,-35}, { 9, 321, 36},
- { 9, 320,-36}, { 9, 266, 37}, { 9, 265,-37}, { 9, 218, 38},
- {10, 925,-38}, {10, 798, 39}, {10, 797,-39}, {10, 646, 40},
- {10, 645,-40}, {10, 535, 41}, {10, 534,-41}, {10, 528, 42},
- {10, 439,-42}, {11, 1848, 43}, {11, 1599,-43}, {11, 1592, 44},
- {11, 1295,-44}, {11, 1288, 45}, {11, 1059,-45}, {11, 877, 46},
- {11, 876,-46}, {12, 3197, 47}, {12, 3196,-47}, {12, 2589, 48},
- {12, 2588,-48}, {12, 2117, 49}, {12, 2116,-49}, {13, 7398, 50},
- {13, 7397,-50}, {13, 6374, 51}, {13, 6373,-51}, {13, 5158, 52},
- {13, 5157,-52}, {14, 14799, 53}, {14, 14798,-53}, {14, 12751, 54},
- {14, 12750,-54}, {14, 10318, 55}, {14, 10313,-55}, {15, 29587, 56},
- {15, 29586,-56}, {15, 29584, 57}, {15, 25491,-57}, {15, 20625, 58},
- {15, 20624,-58}, {16, 59171, 59}, {16, 59170,-59}, {16, 50980, 60},
- {16, 41277,-60}, {16, 50981, 61}, {16, 41278,-61}, {16, 50978, 62},
- {16, 41279,-62}, {16, 50979, 63}, {16, 50976,-63}, {16, 50977, 64},
- {16, 41276,-64}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_f_129[] =
-{
- { 6, 56, 0}, { 6, 55, 1}, { 6, 54, -1}, { 6, 52, 2},
- { 6, 51, -2}, { 6, 50, 3}, { 6, 49, -3}, { 6, 48, 4},
- { 6, 47, -4}, { 6, 46, 5}, { 6, 45, -5}, { 6, 44, 6},
- { 6, 43, -6}, { 6, 41, 7}, { 6, 40, -7}, { 6, 39, 8},
- { 6, 38, -8}, { 6, 36, 9}, { 6, 35, -9}, { 6, 34, 10},
- { 6, 33,-10}, { 6, 31, 11}, { 6, 30,-11}, { 6, 29, 12},
- { 6, 28,-12}, { 6, 26, 13}, { 6, 25,-13}, { 6, 23, 14},
- { 6, 22,-14}, { 6, 21, 15}, { 6, 20,-15}, { 6, 18, 16},
- { 6, 17,-16}, { 6, 15, 17}, { 6, 14,-17}, { 6, 12, 18},
- { 6, 11,-18}, { 6, 9, 19}, { 6, 8,-19}, { 6, 7, 20},
- { 6, 6,-20}, { 6, 3, 21}, { 6, 2,-21}, { 6, 1, 22},
- { 6, 0,-22}, { 7, 125, 23}, { 7, 124,-23}, { 7, 123, 24},
- { 7, 122,-24}, { 7, 120, 25}, { 7, 119,-25}, { 7, 116, 26},
- { 7, 115,-26}, { 7, 114, 27}, { 7, 107,-27}, { 7, 84, 28},
- { 7, 75,-28}, { 7, 65, 29}, { 7, 64,-29}, { 7, 54, 30},
- { 7, 49,-30}, { 7, 39, 31}, { 7, 38,-31}, { 7, 27, 32},
- { 7, 26,-32}, { 7, 20, 33}, { 7, 11,-33}, { 7, 10, 34},
- { 7, 9,-34}, { 8, 254, 35}, { 8, 253,-35}, { 8, 243, 36},
- { 8, 242,-36}, { 8, 235, 37}, { 8, 234,-37}, { 8, 213, 38},
- { 8, 212,-38}, { 8, 149, 39}, { 8, 148,-39}, { 8, 110, 40},
- { 8, 97,-40}, { 8, 66, 41}, { 8, 65,-41}, { 8, 43, 42},
- { 8, 42,-42}, { 8, 16, 43}, { 9, 511,-43}, { 9, 505, 44},
- { 9, 504,-44}, { 9, 474, 45}, { 9, 473,-45}, { 9, 343, 46},
- { 9, 342,-46}, { 9, 340, 47}, { 9, 223,-47}, { 9, 192, 48},
- { 9, 135,-48}, { 9, 129, 49}, { 9, 128,-49}, { 9, 34, 50},
- {10, 1021,-50}, {10, 951, 51}, {10, 950,-51}, {10, 944, 52},
- {10, 683,-52}, {10, 445, 53}, {10, 444,-53}, {10, 269, 54},
- {10, 268,-54}, {10, 71, 55}, {10, 70,-55}, {11, 2040, 56},
- {11, 1891,-56}, {11, 1364, 57}, {11, 775,-57}, {11, 774, 58},
- {11, 773,-58}, {12, 4083, 59}, {12, 4082,-59}, {12, 3780, 60},
- {12, 2731,-60}, {12, 1545, 61}, {12, 1544,-61}, {13, 7562, 62},
- {13, 5461,-62}, {13, 5460, 63}, {14, 15127,-63}, {15, 30253, 64},
- {15, 30252,-64}, { 0, 0, 0}
-};
-
-huff_entry_t bitalloc_g_129[] =
-{
- { 4, 0, 0}, { 5, 29, 1}, { 5, 28, -1}, { 5, 25, 2},
- { 5, 24, -2}, { 5, 21, 3}, { 5, 20, -3}, { 5, 17, 4},
- { 5, 16, -4}, { 5, 13, 5}, { 5, 12, -5}, { 5, 9, 6},
- { 5, 8, -6}, { 5, 5, 7}, { 5, 4, -7}, { 6, 63, 8},
- { 6, 62, -8}, { 6, 55, 9}, { 6, 54, -9}, { 6, 47, 10},
- { 6, 46,-10}, { 6, 39, 11}, { 6, 38,-11}, { 6, 31, 12},
- { 6, 30,-12}, { 6, 23, 13}, { 6, 22,-13}, { 6, 15, 14},
- { 6, 14,-14}, { 6, 7, 15}, { 6, 6,-15}, { 7, 123, 16},
- { 7, 122,-16}, { 7, 107, 17}, { 7, 106,-17}, { 7, 91, 18},
- { 7, 90,-18}, { 7, 75, 19}, { 7, 74,-19}, { 7, 59, 20},
- { 7, 58,-20}, { 7, 43, 21}, { 7, 42,-21}, { 7, 27, 22},
- { 7, 26,-22}, { 7, 11, 23}, { 7, 10,-23}, { 7, 8, 24},
- { 8, 243,-24}, { 8, 240, 25}, { 8, 211,-25}, { 8, 208, 26},
- { 8, 179,-26}, { 8, 176, 27}, { 8, 147,-27}, { 8, 144, 28},
- { 8, 115,-28}, { 8, 112, 29}, { 8, 83,-29}, { 8, 80, 30},
- { 8, 51,-30}, { 8, 48, 31}, { 8, 19,-31}, { 9, 484, 32},
- { 9, 483,-32}, { 9, 421, 33}, { 9, 420,-33}, { 9, 357, 34},
- { 9, 356,-34}, { 9, 293, 35}, { 9, 292,-35}, { 9, 229, 36},
- { 9, 228,-36}, { 9, 226, 37}, { 9, 165,-37}, { 9, 162, 38},
- { 9, 101,-38}, { 9, 98, 39}, { 9, 37,-39}, {10, 970, 40},
- {10, 965,-40}, {10, 839, 41}, {10, 838,-41}, {10, 711, 42},
- {10, 710,-42}, {10, 708, 43}, {10, 583,-43}, {10, 580, 44},
- {10, 455,-44}, {10, 329, 45}, {10, 328,-45}, {10, 201, 46},
- {10, 200,-46}, {10, 198, 47}, {10, 73,-47}, {11, 1942, 48},
- {11, 1929,-48}, {11, 1675, 49}, {11, 1674,-49}, {11, 1672, 50},
- {11, 1419,-50}, {11, 1165, 51}, {11, 1164,-51}, {11, 1162, 52},
- {11, 909,-52}, {11, 655, 53}, {11, 654,-53}, {11, 652, 54},
- {11, 399,-54}, {11, 145, 55}, {11, 144,-55}, {12, 3886, 56},
- {12, 3857,-56}, {12, 3347, 57}, {12, 3346,-57}, {12, 2837, 58},
- {12, 2836,-58}, {12, 2327, 59}, {12, 2326,-59}, {12, 1817, 60},
- {12, 1816,-60}, {12, 1307, 61}, {12, 1306,-61}, {12, 797, 62},
- {12, 796,-62}, {13, 7775, 63}, {13, 7774,-63}, {13, 7713, 64},
- {13, 7712,-64}, { 0, 0, 0}
-};
-
-huff_entry_t *bitalloc_select[11][8] =
-{
- { 0 },
- { bitalloc_a_3, 0 },
- { bitalloc_a_5, bitalloc_b_5, bitalloc_c_5, 0 },
- { bitalloc_a_7, bitalloc_b_7, bitalloc_c_7, 0 },
- { bitalloc_a_9, bitalloc_b_9, bitalloc_c_9, 0 },
- { bitalloc_a_13, bitalloc_b_13, bitalloc_c_13, 0 },
- { bitalloc_a_17, bitalloc_b_17, bitalloc_c_17, bitalloc_d_17,
- bitalloc_e_17, bitalloc_f_17, bitalloc_g_17, 0 },
- { bitalloc_a_25, bitalloc_b_25, bitalloc_c_25, bitalloc_d_25,
- bitalloc_e_25, bitalloc_f_25, bitalloc_g_25, 0 },
- { bitalloc_a_33, bitalloc_b_33, bitalloc_c_33, bitalloc_d_33,
- bitalloc_e_33, bitalloc_f_33, bitalloc_g_33, 0 },
- { bitalloc_a_65, bitalloc_b_65, bitalloc_c_65, bitalloc_d_65,
- bitalloc_e_65, bitalloc_f_65, bitalloc_g_65, 0 },
- { bitalloc_a_129, bitalloc_b_129, bitalloc_c_129, bitalloc_d_129,
- bitalloc_e_129, bitalloc_f_129, bitalloc_g_129, 0 },
-};
-
-static int InverseQ( dts_state_t * state, huff_entry_t * huff )
-{
- int value = 0;
- int length = 0, j;
-
- while( 1 )
- {
- length++;
- value <<= 1;
- value |= bitstream_get (state, 1);
-
- for( j = 0; huff[j].length != 0 && huff[j].length < length; j++ );
-
- if( huff[j].length == 0 ) break;
-
- for( ; huff[j].length == length; j++ )
- {
- if( huff[j].code == value ) return huff[j].value;
- }
- }
-
- return 0;
-}
diff --git a/src/libdts/tables_quantization.h b/src/libdts/tables_quantization.h
deleted file mode 100644
index 904b1014e..000000000
--- a/src/libdts/tables_quantization.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * tables_quantization.h
- * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
- *
- * This file is part of dtsdec, a free DTS Coherent Acoustics stream decoder.
- * See http://www.videolan.org/dtsdec.html for updates.
- *
- * dtsdec 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.
- *
- * dtsdec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-int scale_factor_quant6[] =
-{
- 1, 2, 2, 3, 3, 4, 6, 7,
- 10, 12, 16, 20, 26, 34, 44, 56,
- 72, 93, 120, 155, 200, 257, 331, 427,
- 550, 708, 912, 1175, 1514, 1950, 2512, 3236,
- 4169, 5370, 6918, 8913, 11482, 14791, 19055, 24547,
- 31623, 40738, 52481, 67608, 87096, 112202, 144544, 186209,
- 239883, 309030, 398107, 512861, 660693, 851138, 1096478, 1412538,
- 1819701, 2344229, 3019952, 3890451, 5011872, 6456542, 8317638, 0
-};
-
-int scale_factor_quant7[] =
-{
- 1, 1, 2, 2, 2, 2, 3, 3,
- 3, 4, 4, 5, 6, 7, 7, 8,
- 10, 11, 12, 14, 16, 18, 20, 23,
- 26, 30, 34, 38, 44, 50, 56, 64,
- 72, 82, 93, 106, 120, 136, 155, 176,
- 200, 226, 257, 292, 331, 376, 427, 484,
- 550, 624, 708, 804, 912, 1035, 1175, 1334,
- 1514, 1718, 1950, 2213, 2512, 2851, 3236, 3673,
- 4169, 4732, 5370, 6095, 6918, 7852, 8913, 10116,
- 11482, 13032, 14791, 16788, 19055, 21627, 24547, 27861,
- 31623, 35892, 40738, 46238, 52481, 59566, 67608, 76736,
- 87096, 98855, 112202, 127350, 144544, 164059, 186209, 211349,
- 239883, 272270, 309030, 350752, 398107, 451856, 512861, 582103,
- 660693, 749894, 851138, 966051, 1096478, 1244515, 1412538, 1603245,
- 1819701, 2065380, 2344229, 2660725, 3019952, 3427678, 3890451, 4415704,
- 5011872, 5688529, 6456542, 7328245, 8317638, 0, 0, 0
-};
-
-/* 20bits unsigned fractional binary codes */
-int lossy_quant[] =
-{
- 0, 6710886, 4194304, 3355443, 2474639, 2097152, 1761608, 1426063,
- 796918, 461373, 251658, 146801, 79692, 46137, 27263, 16777,
- 10486, 5872, 3355, 1887, 1258, 713, 336, 168,
- 84, 42, 21, 0, 0, 0, 0, 0
-};
-
-double lossy_quant_d[] =
-{
- 0, 1.6, 1.0, 0.8, 0.59, 0.50, 0.42, 0.34,
- 0.19, 0.11, 0.06, 0.035, 0.019, 0.011, 0.0065, 0.0040,
- 0.0025, 0.0014, 0.0008, 0.00045, 0.00030, 0.00017, 0.00008, 0.00004,
- 0.00002, 0.00001, 0.000005, 0, 0, 0, 0, 0
-};
-
-/* 20bits unsigned fractional binary codes */
-int lossless_quant[] =
-{
- 0, 4194304, 2097152, 1384120, 1048576, 696254, 524288, 348127,
- 262144, 131072, 65431, 33026, 16450, 8208, 4100, 2049,
- 1024, 512, 256, 128, 64, 32, 16, 8,
- 4, 2, 1, 0, 0, 0, 0, 0
-};
-
-double lossless_quant_d[] =
-{
- 0, 1.0, 0.5, 0.33, 0.25, 0.166, 0.125,
- 0.083, 0.0625, 0.03125, 0.0156, 7.874E-3, 3.922E-3, 1.957E-3,
- 9.775E-4, 4.885E-4, 2.442E-4, 1.221E-4, 6.104E-5, 3.052E-5, 1.526E-5,
- 7.629E-6, 3.815E-6, 1.907E-6, 9.537E-7, 4.768E-7, 2.384E-7, 0,
- 0, 0, 0, 0
-};
diff --git a/src/libdts/tables_vq.h b/src/libdts/tables_vq.h
deleted file mode 100644
index eae1ed94c..000000000
--- a/src/libdts/tables_vq.h
+++ /dev/null
@@ -1,2075 +0,0 @@
-/*
- * tables_vq.h
- * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
- *
- * This file is part of dtsdec, a free DTS Coherent Acoustics stream decoder.
- * See http://www.videolan.org/dtsdec.html for updates.
- *
- * dtsdec 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.
- *
- * dtsdec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/* 8bits signed fractional Q4 binary codes */
-
-static int8_t high_freq_vq[1024][32] =
-{
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
- { -4, -2, 2, 1, -16, -10, 1, 3, 1, 0, 6, 1, -3, 7, 1, -22,
- 2, -4, -3, 11, 14, 6, -1, 1, -13, 29, -28, 10, 10, -8, 0, -9 },
- { -8, 8, -7, 10, -3, -12, -5, -8, 1, -2, 9, -2, -5, -18, 1, 9,
- -8, -8, 3, 41, 7, -9, -9, 22, -42, -29, 14, -18, -14, -32, 1, -15 },
- { -16, 8, 15, 16, -16, 5, 2, 7, -6, -16, -7, 1, 1, -3, -2, 0,
- 8, 20, -26, -11, 2, -17, 0, -3, -34, -37, 10, 44, -2, 22, 2, -4 },
- { 7, 14, 5, 6, 15, -1, 3, -3, -9, -23, -5, -14, 8, -1, -14, -6,
- -5, -8, 54, 31, -6, 18, 2, -19, -2, -11, -30, -6, -19, 2, -2, -14 },
- { 1, 2, -2, -1, -3, -3, 1, -5, 1, -3, -4, -8, 5, -4, 0, 1,
- 3, 7, -5, -4, -3, -12, 3, -2, -3, 12, -53, -51, 6, -1, 6, 8 },
- { 0, -1, 5, 1, -6, -8, 7, 5, -18, -4, -1, 1, 0, -3, -3, -14,
- -1, -6, 0, -14, -1, -1, 5, -3, -11, 1, -20, 10, 2, 19, -2, -2 },
- { 2, 4, 3, 0, 5, 0, 3, 1, -2, 0, -6, -3, -4, -5, -3, -3,
- -7, 0, -34, 4, -43, 17, 0, -53, -13, -7, 24, 14, 5, -18, 9, -20 },
- { 1, 0, -3, 2, 3, -5, -2, 7, -21, 5, -25, 23, 11, -28, 2, 1,
- -11, 9, 13, -6, -12, 5, 7, 2, 4, -11, -6, -1, 8, 0, 1, -2 },
- { 2, -4, -6, -4, 0, -5, -29, 13, -6, -22, -3, -43, 12, -41, 5, 24,
- 18, -9, -36, -6, 4, -7, -4, 13, 4, -15, -1, -5, 1, 2, -5, 4 },
- { 0, -1, 13, -6, -5, 1, 0, -3, 1, -5, 19, -22, 31, -27, 4, -15,
- -6, 15, 9, -13, 1, -9, 10, -17, 4, -1, -1, 4, 2, 0, -3, -5 },
- { -7, 3, -8, 13, 19, -12, 8, -19, -3, -2, -24, 31, 14, 0, 7, -13,
- -18, 0, 3, 6, 13, -2, 1, -12, -21, 9, -2, 30, 21, -14, 2, -14 },
- { -3, -7, 8, -1, -2, -9, 6, 1, -7, 7, 13, 3, -1, -10, 30, 4,
- -10, 12, 5, 6, -13, -7, -4, -2, -2, 7, -3, -6, 3, 4, 1, 2 },
- { -8, 9, 2, -3, -5, 2, 0, 9, 3, 7, -4, -16, -13, 3, 23, -27,
- 18, 46, -38, 6, 4, 43, -1, 0, 8, -7, -4, -1, 11, -7, 6, -3 },
- { 1, 1, 18, -8, -6, 0, 3, 4, 22, -3, -4, -2, -4, -11, 40, -7,
- -3, -13, -14, -7, -10, 14, 7, 5, -14, 11, -5, 7, 21, -2, 9, -3 },
- { 0, 0, -2, 4, -2, 0, 2, 0, -1, 2, -1, 0, 0, 2, 2, 2,
- -1, 1, -3, -1, -15, -2, -63, -27, -21, -47, -14, 1, -14, 10, 0, 2 },
- { 1, 0, -4, 0, -3, -9, 4, 2, 6, -6, 0, -5, 11, -7, -15, 6,
- -7, -6, 3, 7, -15, -5, 23, -13, -6, 12, -8, 9, 2, -3, 3, 4 },
- { 6, 0, 3, 0, -2, -4, 2, 1, 1, -1, 1, -2, -1, -4, -22, -15,
- -46, -66, 10, 20, 2, -17, 12, -6, 1, -2, -2, 0, 1, -5, 1, 2 },
- { -1, 0, 0, 1, 0, -4, 0, 1, -10, -3, -8, 5, 7, -11, 2, -11,
- 29, -25, 11, 10, 0, -1, 5, -7, -2, -5, -2, 4, 4, -3, 5, -2 },
- { 1, -1, -1, -3, -2, 1, -8, -3, 2, -2, 4, -5, -1, -7, -2, 1,
- -14, -7, 3, -30, -15, -14, 3, -4, -1, 3, -13, -1, -3, 1, 2, 3 },
- { -1, -2, -3, 2, 2, -3, 3, 1, -3, 2, 0, -4, 6, 5, -5, 10,
- -57, 3, 22, -50, 1, -2, -5, -6, -1, 5, 1, 2, 2, 1, -2, 2 },
- { 2, 0, -1, -7, 2, 1, 3, 2, 0, 4, 3, -2, 3, -3, 4, -4,
- 24, -35, -3, 38, -6, -5, 15, 20, 3, 16, -7, -5, 0, -4, -5, 0 },
- { 0, 1, 0, 0, 0, -1, -1, 1, 1, -1, 1, -2, 0, 0, 0, 0,
- 0, -1, -2, -1, -5, -2, -43, -3, 46, -52, -10, 7, -8, 11, -2, -1 },
- { 0, 0, -1, 0, -1, 2, -41, 33, -44, -48, -15, -26, -9, 6, 3, 3,
- -3, 2, 2, 2, 2, -1, -1, -2, 1, 3, 0, 0, 5, 2, 3, 1 },
- { -4, 1, 6, 1, -6, -1, -2, 1, -14, -4, 0, -5, -2, 2, -2, 0,
- -6, 1, 0, 8, -21, 32, -3, -36, -6, -2, -1, -7, 3, 0, 1, -6 },
- { -3, -2, 3, 0, 2, 2, 8, -4, -4, 6, 2, 1, 3, -6, 4, 3,
- 13, 0, -12, -1, 25, -20, -2, -23, -15, 7, -3, -11, -3, 6, -1, 0 },
- { 0, 0, -3, -1, 0, 0, -2, -1, -2, -2, 1, -1, 0, 0, 10, 3,
- -2, 3, 3, -7, -6, -5, 0, -4, -60, -16, -6, 38, 5, 6, -5, 0 },
- { 0, 1, 0, 0, 0, 0, 0, 0, 1, -1, -1, 0, 1, 0, 0, 1,
- 0, 0, -1, 0, -8, 2, -9, 10, 40, 31, -56, -21, 4, 20, -4, 7 },
- { -2, -2, 0, 4, -3, -1, 7, 3, 1, 3, -8, 0, 3, 1, 2, 5,
- 1, -2, 14, 5, 4, 5, 5, 5, -5, 9, -66, 0, -20, -2, -8, 4 },
- { -2, -1, 4, -1, -8, -2, -4, -1, -3, -3, 2, -7, -3, 5, 7, -2,
- 45, 31, -17, -16, -2, -2, -1, -22, 1, -1, -3, 3, 5, -3, 5, -1 },
- { -4, 0, 7, 5, 8, 7, 2, 9, -9, -9, -7, -11, -3, -8, 17, -4,
- 34, 32, 18, 22, 1, 2, 1, -7, -5, 6, -1, 6, 4, 10, -2, -7 },
- { 6, 0, 14, 9, 6, -1, -2, -3, 4, -6, -8, 4, 7, -1, 28, 38,
- 15, -1, 16, -11, 5, 8, 4, -10, 3, -10, -17, 5, 3, 3, 3, 1 },
- { 1, 1, 2, -1, 2, 1, 0, 0, -1, 0, 0, -2, 1, -3, 0, 1,
- 2, -2, -4, -2, 0, -1, 1, -3, 1, 1, 1, -1, 8, 8, 66, 33 },
- { -5, 2, -3, -7, 2, -8, -4, 10, 17, -18, -7, 4, -4, -7, -6, -6,
- -5, 5, -12, 2, 0, 6, 8, -2, 1, 4, -11, 2, 1, 8, 31, 19 },
- { 6, 9, 16, -6, -6, -1, -2, -3, -11, -2, 7, 7, 17, 3, 4, 10,
- 2, 5, -13, 8, 7, 1, 4, 5, 7, 6, 7, -8, 9, -8, 33, 6 },
- { 3, -1, 1, 0, -7, -5, 0, 14, -7, 1, -7, 1, 2, -4, 7, 10,
- -16, 12, 1, -6, 3, 8, -1, 10, -13, -6, -12, -23, 12, -3, 30, 14 },
- { -2, -15, 0, 8, 3, -19, 5, -3, 2, 3, 13, 7, 14, -3, -10, 0,
- 8, 5, -6, -16, -8, -8, 14, 2, -1, 1, -9, -11, 11, -5, 27, 9 },
- { -8, 6, -4, 4, -4, -1, 5, 4, 1, -7, -5, -4, -15, 1, 9, 0,
- 8, 4, 1, -17, 11, -2, -19, -1, -6, -8, 3, -12, 3, -17, 33, -10 },
- { -3, -1, 2, 7, 7, -2, 9, 8, -18, -1, -13, -10, -3, -3, 11, 8,
- -2, -12, -8, 1, 4, 9, 14, 10, -3, 0, 2, 1, -2, 3, 31, 10 },
- { -3, -10, 8, -1, -5, -11, 7, -5, 3, 6, 1, 4, -16, 10, 5, -4,
- -2, -10, -1, 13, 6, -5, -7, 12, 7, -3, -17, 1, 12, -4, 29, 8 },
- { 1, 2, 5, 2, -6, -7, 0, -1, 6, -1, 10, 6, -4, 5, 2, 2,
- -2, -8, -6, -11, 14, -13, 27, 3, -2, -12, 5, -16, 2, -26, 20, 15 },
- { -1, -3, -5, -3, -3, 6, -1, 3, -5, 1, 7, 2, 1, 0, -1, -1,
- 0, -1, 9, 7, -6, -3, 4, -5, -4, 8, -8, -25, -8, -4, 34, 23 },
- { -1, -2, 1, 1, -1, -2, -1, 1, -1, 0, 0, 0, 0, -2, -1, 1,
- 0, 2, 1, -1, 4, 0, 0, 1, -1, 0, 5, 3, 12, -9, 68, -16 },
- { 10, 0, -8, 14, -6, 1, -12, 0, 0, -3, -5, -11, -6, 12, 9, -10,
- -3, 5, 0, 7, 11, 2, 4, -3, -8, -3, 7, 4, 3, -3, 34, 4 },
- { -12, 13, -5, 7, -11, -2, -1, 1, -4, -14, -21, 3, -3, -3, -4, -7,
- -9, -4, 3, -17, -2, -13, 10, -2, 12, -4, 0, -9, 1, -5, 31, 10 },
- { -10, 6, 5, 6, 4, -7, 10, 0, -28, -3, 0, -11, -1, -5, 16, -10,
- -16, 7, 20, 2, -4, 2, -5, 0, 15, 6, 5, -10, 7, -9, 20, 4 },
- { 1, -7, -2, -7, 4, -3, -2, -7, -1, -14, 6, -16, 4, -5, -4, -6,
- -5, 0, -2, 2, -6, 9, -5, 4, -18, 8, -10, 8, 15, 0, 32, 1 },
- { -5, 7, -3, 7, 15, -4, 0, -16, 9, 5, -5, 5, 4, -3, -12, -9,
- -18, 10, 2, 2, -3, 7, 3, -1, 6, -9, -10, 3, 15, -4, 35, -7 },
- { -1, -10, 2, 2, -4, -2, 10, 2, -1, 2, -2, 1, -1, -14, -11, 3,
- -8, 5, -8, -2, 6, -1, -7, 1, 7, 5, 7, 8, 30, -4, 30, 14 },
- { 2, -2, 1, 2, 3, -8, 3, 0, -2, 0, -9, 2, 1, 4, -6, -1,
- -2, 5, 0, 1, -2, 12, 6, -3, 9, -3, 4, -12, 21, -39, 24, -2 },
- { 3, 5, 1, -2, -2, -2, -3, 6, -8, -2, -11, -8, -1, 4, 2, 2,
- -4, -10, 12, -5, -11, 1, -15, -34, -11, -7, -11, -1, 7, -14, 38, -1 },
- { -4, 4, 8, 9, 8, 1, -5, -9, 4, -2, 15, -4, 11, -15, 20, -1,
- -1, -3, 4, -9, -2, -2, -2, 8, 6, 12, -5, 0, 11, -12, 27, -4 },
- { 0, 8, -4, 3, -11, 6, -11, 2, 3, 0, 5, -8, -7, -6, -9, -21,
- 4, -11, -1, -16, -7, 16, -3, 7, -7, 4, -5, 0, 11, -7, 31, 3 },
- { 1, 3, 4, 11, -11, -2, -3, -6, 6, 5, 0, 3, -9, -6, 4, -4,
- 0, 4, -8, 13, -6, -13, -1, -5, -1, 4, 0, 0, 9, -22, 24, 18 },
- { -7, 3, 10, -13, -6, 6, -6, 6, 22, 1, 0, -14, 2, 3, 7, -1,
- 8, 20, -1, 5, -4, 13, 9, -9, -9, 6, 0, -4, 0, -8, 31, -4 },
- { -3, -4, 0, 1, 7, 3, -7, 0, 5, -2, 1, 3, 3, 1, -5, -2,
- 5, 2, -11, 4, 0, -1, 12, 0, -3, -13, 15, 8, -6, -27, 34, 0 },
- { -3, -3, 10, -4, 2, -1, -3, 0, -1, -1, -4, 2, 6, -2, 12, 1,
- 3, -6, -7, -6, -5, 4, -19, -6, -8, -34, -4, -8, 10, -7, 23, 10 },
- { -7, 0, -1, -6, 8, 4, -4, 2, -5, -8, -7, -9, -8, 5, 9, 7,
- -6, 1, -12, -12, -1, -16, 5, 0, 16, 3, -7, -8, 27, -4, 23, 15 },
- { -8, 4, 8, 5, 6, 11, -3, 5, 3, -1, -11, 6, -5, 0, 2, -6,
- -3, -6, 4, -1, 5, -5, -12, -6, 7, -5, 9, 3, 6, -7, 29, 1 },
- { 1, 3, -2, -2, -6, -2, 1, 6, -6, -3, 1, 2, 3, 4, 1, 5,
- -1, 0, 4, 2, 11, 6, 2, -3, 13, -9, -19, 18, -15, -10, 36, 21 },
- { -3, -3, 2, -1, -7, 6, -4, 1, -3, -1, -2, 2, 3, -7, -3, 0,
- -2, 0, -2, 6, -19, 3, -8, 2, -6, 7, -1, 0, 29, -6, 28, -10 },
- { -5, 1, -3, -7, -12, -4, 1, 1, -1, 13, -10, -1, -9, -5, -13, 6,
- 13, 3, -4, 2, 3, 11, 2, 6, -25, -16, -6, 0, 14, -1, 27, 16 },
- { -6, -1, -7, -5, -2, -5, -5, -1, 9, 1, 0, 3, -8, -12, -6, 5,
- -6, 5, 3, -9, 1, 4, -7, -10, -9, -7, -17, -5, -15, -23, 25, 3 },
- { -8, -2, 9, -3, -4, 3, -1, 8, -7, -7, -5, -4, -2, 9, 4, -1,
- -7, -4, -5, -16, 3, -6, 18, -13, -9, 16, -15, 8, 15, -10, 24, 5 },
- { 1, -38, 2, 34, 9, 10, 11, 2, 2, -6, 3, 2, -2, 5, 4, -7,
- -1, 1, 4, 0, 3, 1, -8, -1, -6, 5, 4, 2, -4, 5, 2, -1 },
- { 1, -22, 15, 18, -2, 10, -16, -9, -8, -11, 8, 4, 0, 7, -14, -5,
- -1, -7, 12, 17, 9, 5, -7, -4, -12, -6, 7, 0, 7, 2, -2, 1 },
- { -11, -29, 7, 10, 19, -1, -8, -9, 7, 1, 9, 6, 8, -7, -14, 8,
- -3, -11, -13, 0, -7, -23, -2, -8, 12, 9, 2, 14, 19, 1, -1, 5 },
- { -24, -27, -11, 36, 2, 6, -3, 4, -6, 8, 0, 12, -1, -4, -6, 3,
- 4, -1, 2, -3, -2, 3, 2, -1, -2, -4, 0, -1, -2, 7, 2, 3 },
- { -9, -24, 11, 13, -10, -12, 12, -2, 7, 4, 8, 13, -3, -3, 2, 9,
- -3, -4, 4, 13, 5, 13, -6, -3, 1, 15, 7, -3, 0, 19, -2, -9 },
- { -8, -15, 7, 14, -4, -5, 2, -18, -19, -2, 2, 17, 16, 6, -10, 10,
- -9, 14, -1, -5, -1, -6, -7, 2, 9, 11, 13, 6, -5, -12, 3, 2 },
- { -10, -37, 13, 1, 3, -14, 0, -20, 4, -3, 8, 2, -2, -3, -9, -5,
- -3, -17, -1, 13, -11, 2, -6, 4, 4, 0, 3, 1, -9, -4, -5, -4 },
- { -2, -22, -5, 46, -8, 5, 9, -11, 8, 7, 7, -1, -1, -2, -7, 2,
- -3, 3, -1, -2, 7, 0, 2, -1, 1, -2, -2, -3, 6, 0, -4, -6 },
- { -16, -27, 15, 16, -4, 14, -7, -26, 2, -2, 6, 5, -3, 11, 0, 2,
- 3, 9, -7, -1, 2, -4, -4, -1, 6, 10, 1, 1, -3, -2, 3, 0 },
- { -3, -22, 10, 26, 1, 2, -3, 3, 17, -3, -7, 9, 1, -21, -4, 5,
- 3, 0, -7, -6, 3, 3, -8, -7, -9, 3, 7, 1, -8, 12, 6, -7 },
- { -9, -25, 3, 18, 9, -6, -11, 0, -5, -12, 9, -8, -7, -6, -6, 22,
- 2, -6, -3, 15, 3, 2, -2, 9, 14, -10, -7, 15, 13, 6, -2, 11 },
- { 5, -20, -5, 28, 11, 10, -4, -4, 0, -7, 3, 5, 2, -5, -8, 2,
- 6, 10, 9, -9, -18, 3, 14, 1, 3, -3, -1, -6, 7, 7, 2, -1 },
- { -8, -30, 7, 12, 10, 8, 7, -13, -16, 0, 1, -1, -6, -11, -15, 4,
- 1, -2, 10, -15, 1, 11, -2, 8, 9, -7, -7, 9, -5, 2, 7, -18 },
- { -10, -32, 10, 11, 3, -1, 3, -5, 5, 2, 14, -6, 3, 1, 5, -15,
- -11, 6, 20, 4, 0, -12, -7, 3, 1, -1, 10, 6, -1, -9, -4, -1 },
- { 1, -25, -14, 12, -11, 9, 9, -16, -24, -17, 22, -9, 11, -30, -3, -4,
- 6, -7, 9, 2, -1, -5, -6, 2, -1, -1, 10, 1, -3, 3, 4, 8 },
- { -14, -26, -6, 9, 8, 17, -11, -24, -7, -4, -8, -2, 10, 2, 2, -1,
- 2, 13, 12, -7, 4, -6, -10, 6, 6, -13, -11, -7, -16, 0, -2, 5 },
- { -4, -30, -13, 12, 16, -6, 12, -16, -13, 5, 15, -2, -2, -10, -7, 7,
- 11, -1, -4, -2, -4, 7, 4, -8, 1, 3, 0, 11, 3, -2, -5, 4 },
- { -4, -21, 20, 22, 2, 20, -8, 1, -12, -5, -9, 4, -10, -17, -3, -8,
- -3, 3, -12, 1, -3, 0, 7, 4, 7, 7, -3, 7, 5, 3, 1, -5 },
- { -12, -20, 2, 29, 11, -6, 9, -7, -6, -4, 0, 6, 17, -13, -2, -10,
- -17, -1, -18, 2, 0, 14, -6, 1, 0, 3, 2, -10, 1, -5, -2, 5 },
- { 16, -37, -1, 26, -2, -14, 1, -5, -14, 2, 2, 3, 6, 1, 1, 4,
- 0, -1, 0, -2, -2, 4, 9, -6, 0, -2, 10, -7, -2, 4, 1, 0 },
- { -9, -24, -12, 5, 5, 3, -17, -14, 4, 3, 2, -4, 10, -22, -8, -3,
- 6, 1, 12, -8, 4, 1, 9, -1, 18, -3, 6, 5, 3, -5, 9, -5 },
- { -14, -33, -2, 20, -13, -10, 2, -7, -1, 11, -9, -8, 18, -3, 1, 8,
- 0, -2, 10, 7, -2, -13, 9, -3, -4, 5, -2, -2, -1, -5, 1, -7 },
- { -10, -23, 8, 14, 1, 7, 1, -3, -7, 4, 1, 1, 8, -7, 15, -14,
- 13, 14, 2, 5, -13, -5, -8, -1, 6, 3, 6, 9, 6, 15, 14, 5 },
- { -13, -25, -10, 13, -17, -24, -7, -13, -6, -10, -8, 2, 0, -13, -10, -4,
- -8, 4, -9, 9, -4, 4, -3, -3, 3, 3, -5, -9, 1, -2, 11, 2 },
- { -12, -23, 1, 18, -11, -2, 5, 9, -5, 5, 14, -9, -3, -2, -6, 2,
- -2, 11, -13, 1, -3, 11, -9, -4, -2, -6, 8, 10, 1, 4, 2, 1 },
- { -5, -18, 16, 22, 2, 0, 8, -6, -9, -7, 10, -16, 23, 10, -11, -1,
- 7, 2, 7, 2, 1, -5, 6, 1, 0, -4, 9, 2, -3, 1, 0, -4 },
- { -3, -26, 14, 11, 2, -9, 17, -2, -1, -5, -16, -9, -5, 10, -13, 1,
- 6, 12, 10, 11, 0, 0, -3, -14, 6, -2, 0, 4, -5, -1, -7, -1 },
- { -10, -33, 1, 8, 11, -5, 1, -6, 7, 4, 5, 6, 1, -2, -10, -5,
- -6, 12, -11, 5, -10, 4, 12, -1, -1, -3, 4, -1, 9, 0, 16, -17 },
- { -14, -37, 7, 7, -2, 5, -8, -11, 2, -13, 4, -19, 1, 8, 8, 4,
- -9, 2, -4, 3, 12, 2, 4, -4, -8, 8, 1, 4, 8, -1, 6, -2 },
- { -6, -30, 18, 17, 1, -22, -3, 4, -7, -10, 7, 0, -8, 8, -1, 4,
- 2, 8, 6, -2, 2, 7, 4, 4, 3, -6, 2, 1, -3, 1, -1, -5 },
- { -17, -18, -3, 22, -8, 1, 9, -2, -17, 20, -5, -5, -12, -5, 4, -5,
- -9, 8, -2, 16, -3, 0, 19, -8, 8, 1, 2, -4, 0, 11, 0, -3 },
- { -9, -23, 3, 10, 4, 4, -3, -2, -2, -2, 1, -22, 11, 0, -2, 5,
- -2, 14, -9, -11, -4, 7, 5, 32, 1, -3, -7, 0, 21, -9, 7, -6 },
- { 0, 0, 0, 2, -1, 1, 0, 1, 3, 0, 0, 1, 0, 1, 0, 1,
- -3, 0, -1, -2, 0, -1, -1, -3, -1, 1, -4, 1, -1, -5, -69, -19 },
- { -3, -5, -8, -12, 4, -3, -19, -11, -5, 0, -14, 7, 18, -6, 7, 22,
- 8, 14, 15, 10, 3, -1, -3, 5, -1, 7, -7, 1, -6, 3, -26, -11 },
- { -1, -6, 4, -4, -5, -16, 0, -6, -3, 11, 1, 0, 9, 5, 16, 3,
- -4, -33, -4, 4, -7, 0, 1, 6, -11, -2, -13, -2, -18, 20, -25, -16 },
- { 4, 0, -1, 0, -5, 1, 0, 2, 0, 11, -10, 4, -10, 7, 16, 2,
- 16, 15, 2, -1, 2, 9, 2, 8, -3, -5, -2, 0, -3, 0, -33, -2 },
- { -3, -15, 10, 10, -9, -1, 7, 3, 5, -5, -8, -8, -3, 15, -9, 4,
- 12, 13, -13, -14, 10, -6, 9, 22, -27, 23, -1, 5, -24, 2, -30, 5 },
- { 0, -2, 7, -5, -5, 3, 5, 3, -3, -5, 2, 1, -4, 3, -3, -1,
- 1, -2, 10, 22, -3, -4, -2, -2, -7, 3, 8, 1, 14, 4, -37, 9 },
- { -3, -4, -1, 1, -4, 0, 6, 2, 6, -7, -10, -10, -1, -4, 11, -3,
- 7, -6, 4, -12, -1, 5, 1, -7, 10, -6, 17, -4, 8, 3, -40, 13 },
- { 2, 12, 4, -7, 14, -3, 16, -2, 18, 2, 13, 5, 5, 1, 11, -1,
- 0, 9, 2, -6, -1, 2, -6, 2, -5, 3, 5, 1, -1, 1, -32, -7 },
- { -16, 11, 7, -4, 2, -5, -9, 9, 11, 11, 15, -13, -11, 11, 9, 4,
- 3, -8, -10, 12, 12, 0, 0, -16, -9, 13, 2, 9, 4, -13, -33, 3 },
- { 6, 4, 5, 4, 3, -1, 5, 6, 4, 2, -11, -1, -15, -11, -1, 1,
- 11, -3, -2, 24, -4, -6, -25, -10, -15, -8, 0, 0, -5, 4, -30, 2 },
- { 10, -3, -6, 1, -9, -5, 6, 9, -10, -3, 8, -1, 4, -1, 11, -11,
- 3, 9, 11, -3, 6, -17, 5, -8, -33, 9, -13, 19, -2, 9, -25, 2 },
- { 0, 0, -1, -3, 0, -2, 1, 0, 0, 2, 1, 0, -2, 0, -1, 2,
- 0, -1, 4, -1, 2, -3, 4, -2, 3, 3, 1, 0, -15, 12, -63, 27 },
- { -2, 14, 9, -1, 3, 0, 1, 1, -19, 15, 3, 4, 0, -10, 1, -5,
- 3, 0, -5, -10, 2, -16, -4, 8, -12, -6, 7, -5, -10, -1, -33, -4 },
- { 0, 3, 1, 3, 1, 2, 4, 4, 9, -6, -8, -5, 1, -12, 3, 8,
- -10, 6, -1, 1, 13, -5, -5, 2, -4, 13, -18, -10, -7, -9, -33, 10 },
- { -6, -3, -12, 5, -1, 11, -6, 0, -2, 1, 2, -7, 3, 1, 3, -2,
- 1, 8, -10, 7, -1, -3, 3, 0, 13, 1, 6, 7, -16, -7, -39, 8 },
- { -6, -1, 11, 6, -3, 8, 3, -5, 3, 0, -5, -2, -6, -3, -4, 2,
- -3, 13, -11, 1, 7, 5, 19, -5, -3, -15, -1, 7, -1, 6, -33, 8 },
- { -7, 3, -4, -3, -4, 1, 6, -5, -5, 6, -8, -1, -7, 4, -1, -6,
- -2, 1, 7, 0, 1, 1, -5, 2, -2, 0, -13, -2, -31, -14, -39, -12 },
- { -10, 9, 0, -3, 1, -1, -1, 0, 1, -5, -1, -4, -2, 5, 2, -7,
- 18, -8, -2, -19, -7, -7, -12, -14, -11, -1, -9, -13, -7, -12, -31, -9 },
- { -3, -16, 10, 9, 1, -10, -12, 2, -2, 2, 7, -3, -3, 1, -4, -5,
- -9, 5, 7, 3, -1, 4, -11, -8, 4, 13, -10, 13, 10, -4, -36, 1 },
- { -7, -12, 4, -20, -7, -7, 2, 11, -1, -2, 3, -12, 1, 0, -6, -7,
- 6, 4, 13, 3, -3, 4, 3, -6, -12, 5, -5, -22, -13, -8, -37, -6 },
- { -7, 5, 3, 5, 7, 9, -14, -3, 10, 17, -1, 1, -12, 5, -6, 0,
- -4, -9, 0, -11, -14, 3, 13, 6, -25, -8, -12, 4, -10, 18, -30, -1 },
- { -10, 6, -10, 6, 6, 1, -10, 0, -7, 5, -2, 17, -18, -4, 0, -3,
- -16, -6, -3, -8, 5, 1, -4, 6, -7, 16, 6, 10, -1, 0, -32, -11 },
- { -1, 9, 9, -5, 4, 9, 6, 9, -4, -2, 7, 11, 4, 2, -5, -4,
- -6, 0, 2, -3, -1, 5, 10, 0, 12, -10, -18, -3, -1, 14, -33, 2 },
- { 4, -8, -18, -4, -5, -11, 4, -10, -4, 9, 13, -12, 1, -6, 1, 2,
- 4, -9, 8, 3, -6, 21, 13, -1, -2, 1, -2, 6, -7, 0, -30, 1 },
- { 6, -1, 2, -3, -1, -4, 6, -4, 0, 4, 2, 2, -9, 2, 6, 3,
- -2, 4, -1, 9, -6, 0, 7, -8, 5, 19, -2, 9, -5, 2, -33, -8 },
- { 2, 1, 12, -5, -8, 8, 3, -2, -4, 1, -2, 5, -4, -9, -8, -8,
- 7, -11, -4, 6, -10, 7, -1, -1, -2, -1, 16, 32, -7, 20, -33, -6 },
- { -18, 2, 6, 13, 9, 9, -1, 3, -17, 24, -2, -6, 28, 8, -2, 6,
- 3, -10, -34, -16, -13, -4, -15, -11, -12, -3, -10, 4, -8, 4, -31, -4 },
- { -11, 0, 18, 2, -16, -9, -13, -2, -2, -12, -3, -22, 30, 0, 8, 3,
- 9, -4, -16, 1, 0, -11, 15, -2, -4, 6, -5, 6, 1, 2, -25, -12 },
- { 14, -1, 5, 7, 3, -15, -8, 1, 5, -2, 12, 13, 11, -25, 3, 1,
- 0, -2, -4, -16, -23, 0, -5, -17, 7, 5, -9, 6, -5, 2, -32, -7 },
- { 3, -1, 6, 14, 2, -12, -9, -9, 4, 7, 4, 6, 5, -8, 4, 2,
- 4, 5, -2, 8, 8, -6, 0, 10, -20, -1, 3, -1, 8, 23, -33, -5 },
- { -3, 11, -6, 3, -4, 5, 7, 3, 4, 5, -2, 3, -1, 30, 6, 1,
- 8, -6, 0, 0, -9, 6, -9, 4, 2, 9, -6, 1, -12, 0, -34, 18 },
- { -17, 13, 0, 1, 9, -4, -11, 0, 7, 0, -10, -4, -1, 6, -6, 4,
- 1, 6, -9, 3, -5, -6, -11, 2, -4, 14, 23, -3, 2, 5, -30, 12 },
- { -14, 5, -27, 2, 0, 7, 1, 4, 30, 8, 7, 5, 1, -1, 0, 5,
- 8, -10, 48, -11, 12, 33, 6, 8, -15, 20, -2, -5, 32, 5, -19, 10 },
- { -16, -4, -12, -7, -2, 0, 8, -6, -20, -18, 16, -3, 0, 31, -2, 11,
- 2, -9, 49, -19, -12, -23, 10, 26, 16, -2, 4, -21, -14, 13, -11, -9 },
- { -5, -9, -1, 3, -5, -21, 2, 10, 0, 0, 10, -21, -7, 7, -26, -9,
- 22, 32, 58, 11, -3, 11, -5, -8, -13, 6, -5, -9, 1, 10, 14, -8 },
- { 7, 7, 10, 3, -2, -1, -11, -11, -6, -43, -3, 14, -19, -18, 19, 18,
- -32, 10, 45, -6, 6, 21, -20, -12, 2, 4, 6, 6, -4, 3, 3, 1 },
- { 21, 22, -3, -2, -11, -6, -1, -2, 8, 8, 32, -21, 7, 28, -4, -6,
- -3, -2, 50, 2, 2, 27, -5, -8, 12, 7, -5, -1, -4, -17, 27, 6 },
- { 13, 7, 2, -6, -12, 2, -10, -5, -17, 11, 4, 17, -12, -2, 5, -17,
- 37, -16, 48, -14, -18, 29, 8, 24, 11, -5, -9, 11, -1, 1, -13, -3 },
- { 1, 1, -1, 2, 0, 0, 0, -1, 1, -1, 7, 2, -3, 3, 0, 6,
- 2, 10, 54, -25, 7, 54, -5, -6, -1, -15, 9, 13, -24, -15, -12, 3 },
- { 21, 5, 8, 3, -3, -4, -2, -4, 3, -11, -5, -8, 9, 16, 8, -9,
- -10, -3, 46, -46, 2, 1, -10, 10, 17, 11, -20, -36, 10, 14, 0, -5 },
- { 7, -13, -6, -9, -24, 45, 2, 8, 8, 0, 17, 20, 12, -24, 1, -7,
- -15, -3, 46, -13, -2, 20, 1, -13, -11, -13, 2, 15, 1, 10, -1, 3 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -2, -1,
- -16, -9, 31, -69, -34, 26, 7, 17, -1, -6, -1, 0, 0, 0, 0, 0 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -4,
- -5, -20, 18, -82, 22, 3, -7, 9, 4, 6, 2, -4, -1, 0, -2, 2 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 4, -1,
- 15, -5, 62, -36, 4, 52, -7, 5, 0, 6, 1, 2, 1, 1, -1, 0 },
- { 3, -19, 19, -20, 13, -4, -11, 8, 8, -16, 10, 1, -14, 30, 1, -33,
- 10, -11, 45, -30, 3, -4, -3, -13, 7, 12, 3, -22, 3, -2, -4, -2 },
- { -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 1,
- 11, 8, 70, 48, -10, 21, 4, 9, -9, -9, -4, -6, 0, -1, 0, 0 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0,
- 2, -1, 80, 2, -15, -36, -10, -5, -2, 8, -2, 2, 0, 0, 0, 0 },
- { 10, 8, -8, -8, -24, 12, -1, 0, 20, 9, -1, -2, 2, -2, 12, -10,
- -2, -13, 35, -43, 44, 15, -10, -25, 4, 10, -3, -5, -5, 7, -1, 3 },
- { 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, -2, -1,
- -18, 9, 49, -72, 7, -8, 7, -5, 2, 3, 2, -2, 1, -2, -3, 1 },
- { -1, 4, -3, 10, 19, 4, 3, 20, 6, -24, 6, 9, 8, 15, 18, 18,
- -36, 19, 57, -11, 4, -3, 8, 7, 2, -3, -2, -9, -15, -2, 12, -4 },
- { 20, 3, 11, -9, -4, 22, 42, -25, 1, 5, -10, -19, 0, 9, -16, 5,
- 2, 10, 44, -29, 17, -3, -9, -2, -1, 8, 14, -7, -1, 16, -5, 1 },
- { -7, 16, -11, 12, 6, 33, -15, 14, -23, 2, -26, 8, 2, 10, 0, -5,
- 8, -8, 38, -38, -4, 5, 5, 5, 1, 22, -15, 7, 6, 0, 4, 28 },
- { -1, -12, 2, 10, -2, 0, 7, 17, 12, 22, -4, 10, 25, 29, 5, 18,
- 4, 1, 27, -39, 31, 17, 2, 2, 22, -23, 13, 16, 1, -7, -4, -5 },
- { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -2, 0, -14, 0,
- -7, -11, 49, -22, -4, 19, 17, -39, 4, -29, 10, 2, 36, -4, 23, -1 },
- { -2, -2, -2, -2, 1, 15, -5, -7, -16, -8, -19, 16, -3, -20, 36, -9,
- -3, 20, 39, -20, 0, 2, 27, -16, 10, 10, -14, -22, -16, -3, 13, -8 },
- { 5, -9, 6, -25, 7, 37, 13, -10, -5, 3, -5, 7, 18, -22, -7, 9,
- -5, -4, 50, -11, -4, -5, -5, 8, -4, -2, -4, -27, 14, 20, 7, -9 },
- { 0, -14, -10, -27, -14, -17, -6, 26, 10, 2, 14, -12, -5, 0, 8, 9,
- 0, -28, 55, -7, -12, -7, 4, -10, 10, 7, -12, 11, 3, 5, 9, -8 },
- { 2, 23, 4, -2, -1, -20, -2, 14, 10, -9, -9, -24, 10, 0, 11, -12,
- 12, 11, 49, -25, -2, 29, 7, -13, 21, -10, 11, -17, 3, 1, -8, 5 },
- { 3, 0, -14, -6, 18, -2, 17, -9, -19, 9, -5, 9, 14, 6, 19, -3,
- 27, 1, 41, -21, 20, -15, 33, 0, 26, 14, 7, 10, 3, 20, -3, -12 },
- { -1, 16, 15, -8, 3, -8, -8, 21, -5, -16, -29, 4, 1, -6, -4, -28,
- 2, 31, 37, -26, -2, 13, 24, 8, -9, -6, -29, 10, 7, 2, 7, 8 },
- { -10, -10, 11, 13, -32, 2, 16, 9, 14, 23, -15, -13, 24, 13, 4, -27,
- 14, 12, 31, -18, 17, 23, -2, -7, -14, 9, -17, -6, -10, 20, 9, 6 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0,
- 5, 1, 89, 8, 10, -6, 2, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, -1,
- 4, -7, 64, -50, 7, 37, 2, 5, 0, 0, 0, 0, 0, 0, 0, 0 },
- { -2, 5, 3, -4, -4, -3, 2, -3, 3, -3, 5, 4, 1, -6, -1, 1,
- 6, -2, 50, -35, -7, 43, 7, -7, -5, -26, 24, 21, 3, -15, 5, 6 },
- { -8, 21, -19, 33, -8, 22, -11, 17, 3, 0, 0, -2, 1, -3, 6, -1,
- 10, -8, 4, -11, -4, -5, 0, 8, -4, 3, 1, -4, 4, 2, 8, 4 },
- { -7, 5, -20, 9, -22, 3, -14, 1, 6, 13, 23, -2, -4, -7, 2, 0,
- 11, 4, 6, 3, -7, -11, -7, 4, 5, 5, -12, 8, 2, 4, 7, -3 },
- { -7, 6, -4, 20, -20, 16, -2, 7, 6, 16, 11, 12, -7, -7, 5, 3,
- -9, -4, 1, 2, 5, 2, 1, -9, -2, -17, -4, 6, -10, 7, -7, -6 },
- { -9, 18, -17, 12, -24, 1, -1, 4, 14, 9, 4, 3, 2, 8, -12, -14,
- 4, -8, -4, 7, 7, 6, -1, 13, -9, -4, -1, 1, 0, -4, 15, 8 },
- { -25, 2, -11, 6, -5, 24, -28, -5, 8, 12, -2, 6, 8, -3, 8, -9,
- -1, -5, -1, -5, 6, -1, -1, -1, -4, 8, -12, -2, -13, 7, 2, 1 },
- { -14, 14, -18, 20, -10, 12, -2, 9, 1, 0, 12, -2, 15, -10, 26, -17,
- 16, -11, 10, -10, 9, -2, 4, -8, 2, -3, 4, 4, 2, -3, -5, 1 },
- { -18, 12, -18, 21, -6, 12, -6, 13, -25, 18, 1, 11, -9, -5, 0, 10,
- -5, 3, -3, 8, -9, 7, 4, 2, -9, 0, 5, 0, 2, -3, 9, -8 },
- { -4, 16, 1, 18, -30, 9, 1, 6, -8, 13, 13, -12, -6, -1, 13, 7,
- 6, 2, -15, -3, 5, 5, 1, -6, 1, -5, 0, 2, -16, 0, 3, -4 },
- { -21, 1, -2, 6, -43, 18, -1, 5, -1, 4, 6, -2, -1, -3, -1, -3,
- 0, 1, 2, -9, 0, -1, 0, -2, 0, -1, -1, -2, 6, 0, 1, -2 },
- { -23, 10, 4, 7, -32, -11, -18, 2, -2, -7, -6, -3, -3, -12, 19, 3,
- -5, -6, 16, -6, 16, 2, 16, 16, 8, -2, 13, 8, -15, -11, 2, 10 },
- { -8, 2, -13, 2, -29, 24, -20, 19, 1, 10, -4, 10, 1, 2, -9, 11,
- -1, -2, 9, -5, 19, -7, 16, -9, -2, -18, 11, 1, 1, 0, 7, -3 },
- { -6, 3, 4, 13, -26, 10, -10, 28, -7, 28, 1, 7, 0, -14, 5, 7,
- 4, -4, 3, -2, 3, 3, -11, 7, 6, 4, 0, -1, 2, -1, -3, 2 },
- { -6, 16, -31, 13, -10, 17, -6, 4, -14, 4, 4, -1, -10, 12, -5, 1,
- -14, 15, 0, -8, 1, -5, 3, 3, 9, -5, 7, -20, 7, 4, 11, -5 },
- { -19, 3, -17, 14, -12, 16, -22, 18, 14, 8, -2, 4, 10, 12, -14, 4,
- -3, 2, 3, 7, -7, 7, -6, 2, -2, -4, -5, 0, -5, -2, 2, 1 },
- { -9, -7, -11, 24, -36, -9, -11, 5, 7, -12, -13, 18, -2, 20, 1, -4,
- -1, -10, 15, -6, 14, 1, 0, 2, 1, 2, -9, -16, -11, 7, 13, 0 },
- { -24, 24, -18, 18, -22, 14, -11, 13, -12, 11, -10, 11, -7, 11, -5, -4,
- -1, 1, 5, 2, 3, -1, 1, -5, 7, -4, 5, -6, 8, -7, 8, -6 },
- { -6, 18, -22, 22, 5, 11, -1, 6, 19, 22, 8, 4, -8, 20, -2, 15,
- -6, -18, 0, -33, -9, -12, -1, 6, 5, 2, 5, 5, -5, -17, -3, -3 },
- { 1, 11, -16, 9, -18, 11, -4, 18, 20, 26, -10, 8, 1, -11, 8, -4,
- 0, 7, 3, 5, 2, 2, 10, -2, -4, 4, -4, -2, 1, -4, -5, -1 },
- { -10, 6, -1, 18, -17, 27, -3, 10, -2, 12, -7, -9, 1, 1, -1, 7,
- -12, -1, -7, -6, -1, 8, 3, -15, 8, 9, 3, -7, 4, -1, 1, -1 },
- { -14, 6, -16, 22, 2, 5, 0, 5, -18, 11, 6, -3, 22, -20, -9, -3,
- 6, -6, -7, -15, 1, 15, -8, 11, 8, -3, -8, 1, -8, 2, 6, -2 },
- { -21, 5, -19, 19, -7, 4, -7, 0, -8, 6, 12, 5, -3, -22, -13, -6,
- -1, -3, -2, -14, 6, -3, 1, -8, -7, -5, -6, 11, -3, -10, -5, 2 },
- { -1, 9, -12, 15, -6, 6, -19, 14, -9, 11, 3, 12, -17, -3, 8, -4,
- -3, -4, 1, -5, 4, 5, -7, -15, -7, 15, -6, -5, 1, -5, -3, 1 },
- { -12, 20, -15, 20, -14, 3, -14, 9, -6, 33, -13, 6, -2, 8, -6, 7,
- -5, -6, -3, -3, 0, 8, -3, -3, 1, -2, 2, 2, 6, -5, -5, -2 },
- { -7, 12, -18, 12, -18, 10, -4, 8, 2, 4, 8, 9, 0, 3, -8, 3,
- 6, -12, -4, 1, 25, -5, -9, 6, -7, 0, -9, -7, 3, -5, -4, -4 },
- { -18, 12, -10, 11, -22, 0, -15, 5, -2, 2, -3, 6, -4, -4, -3, -15,
- -2, -3, 21, 6, -12, -11, 19, 3, 3, -14, 7, 0, -11, -22, -10, 0 },
- { -15, 2, -30, 15, -17, 13, -16, 8, -7, 10, -8, 2, 11, 3, 10, -7,
- 7, -22, 12, -10, 3, -12, 6, -10, 12, -10, 7, -8, 5, 2, 9, 1 },
- { -9, 11, -14, 6, -10, 21, 5, 12, -5, 5, 7, 21, 6, 2, -2, -1,
- -1, 4, 2, -20, -18, -1, -14, 3, -1, 4, -7, 10, 1, 11, 4, -4 },
- { -22, 8, -30, 13, -21, -4, 4, -1, 12, 9, -2, -3, 2, -6, 4, -13,
- -2, 8, 8, 1, -7, 3, -4, -5, -1, -7, -2, 8, 8, 7, 8, 0 },
- { -6, -4, -35, 16, -13, 15, -11, 14, -7, 9, -1, 11, 7, 0, 13, 10,
- -1, 8, 1, 1, -2, 8, -1, 2, 2, 3, -10, -1, 7, -13, -3, -7 },
- { -15, 7, -16, 14, -18, 17, -6, 14, 3, 4, 7, -3, 10, -22, 5, -15,
- 4, -4, -11, 15, -15, 11, -11, 20, 1, 0, 2, 1, 11, -3, 11, -7 },
- { -12, 3, 5, 16, -37, -1, 15, 15, -15, 10, 3, -10, 1, 15, 7, -15,
- -13, 8, 9, -3, 2, 12, -8, 2, -5, 0, -3, 4, 5, -9, -4, 5 },
- { -16, 26, -4, 14, -22, 26, 6, -3, -8, 4, 21, 6, 16, -4, -11, 7,
- -10, 3, 3, 7, -4, 2, -9, 8, -2, 2, 5, -2, -4, -2, 7, -1 },
- { -7, -10, 4, 3, 2, -4, -12, -10, -4, -5, 16, 19, -16, 1, 2, -9,
- -10, 0, 9, 7, -8, 3, 12, 8, -6, -11, -13, -1, -3, -20, 6, -5 },
- { -14, -17, 3, -5, 14, -12, -12, 8, -6, -25, 21, 21, 10, -8, -12, 4,
- 10, -4, 3, -9, 11, 9, 0, 4, 2, -15, 1, -14, 4, 1, 0, -4 },
- { -4, -9, -3, -1, 6, 3, -6, 6, -10, -4, 14, 8, 2, -3, -12, -19,
- 0, 11, -20, 1, 6, -2, -27, -6, 10, -17, -14, -17, -9, 8, -8, 3 },
- { -12, -13, 16, -4, -2, 12, -7, -11, 2, -13, 3, 7, -16, -18, -1, -12,
- -2, 1, -12, -9, -2, -6, 2, 9, -22, -3, -4, -14, -7, 7, -1, 2 },
- { -7, -8, -8, 15, 15, 18, 15, 16, -4, -37, 11, 15, -12, -1, -3, 3,
- 6, 6, 0, -5, -3, -5, 9, 1, 1, -11, -1, -8, -6, 2, 3, 0 },
- { -6, 7, -5, -12, 13, 10, -18, -4, -3, -21, 6, 16, -15, -7, -12, -9,
- 1, -12, -1, 10, -2, -1, -3, 4, -4, 1, -16, -1, 12, -9, 5, 9 },
- { -14, -5, 9, 3, 4, 26, -28, 3, -6, -24, 4, 5, 3, 13, 5, -1,
- 3, -1, 3, 1, 1, -5, 3, 0, -7, -8, -7, -3, 3, -5, 4, 0 },
- { -4, 2, -10, -6, 25, 26, -6, 10, -6, -8, 15, 11, -6, -3, 2, -7,
- 5, 14, 9, -1, 0, -12, 4, -4, -10, 1, -3, 3, -2, -2, -6, -1 },
- { -10, 8, -15, -10, 19, 17, -8, 0, -3, -7, 7, 5, -13, -1, 7, -7,
- 1, 13, -12, -13, 17, -12, 1, 26, -18, -3, -5, -6, 4, 5, 8, 1 },
- { 2, -5, 3, 0, 0, 0, 2, -3, -2, -5, 7, 13, -4, 9, 0, -5,
- 4, -1, -11, -8, -4, 0, -13, 2, -47, -23, -8, -11, -4, 4, -2, -3 },
- { -18, -4, 4, 5, -1, 17, -12, -8, 1, -12, 7, 20, -12, 3, -2, -11,
- 16, 12, -6, 1, -13, -16, -6, -3, -3, -5, 4, -12, -5, -9, 10, 1 },
- { -11, 0, 4, 7, 7, 8, 3, -1, 3, -19, 32, 8, -19, -8, 2, 4,
- -12, 15, -16, 3, 1, 9, -2, 1, -2, 8, 5, 6, -4, -1, 11, -8 },
- { 3, -1, 4, -2, 14, 32, -9, -23, -10, -12, 22, 15, -1, -2, 10, 0,
- 4, 6, -8, 4, -15, -2, -1, -4, 0, -8, 4, 1, -8, 3, 4, 1 },
- { -17, -12, 6, -8, 16, 13, -20, -8, -1, -16, 10, 21, -19, 11, -9, -5,
- 7, 18, -6, 7, -7, -18, 13, 2, -2, 8, -12, -9, 2, 4, -5, 16 },
- { 4, 0, 17, -11, 12, 7, -12, 5, -1, -25, 30, -8, -7, -6, -4, -7,
- 9, 8, 7, 3, 3, -16, 8, 0, -2, -2, -18, -3, -4, -5, 1, 4 },
- { -3, -6, 6, -16, 17, 6, -3, 2, -9, -17, 12, 11, 11, 2, -20, 8,
- 1, 1, 0, 2, -2, -6, -21, -13, -9, -15, -1, -8, -6, -8, 0, -2 },
- { -11, -7, 6, -9, 3, 6, 8, 16, 4, -5, 23, 26, -10, -3, 4, 0,
- 2, 2, -4, 4, -2, -12, 12, 10, -11, 0, -10, -16, 3, 0, 0, -10 },
- { -5, -16, 10, -6, 27, 13, -3, 4, -2, -13, 15, 5, 2, 5, 3, -4,
- 13, 12, -11, -7, 0, 1, 11, 12, 2, 13, -15, -8, 9, -2, 3, 8 },
- { -5, -8, 4, 3, 9, 3, -11, 10, 14, -25, 14, 8, -2, 5, -12, -21,
- 2, 10, -7, 2, -3, 2, 0, 2, -1, -3, -5, -6, -1, -16, 2, 8 },
- { -1, 5, 1, -11, 5, 9, -7, 8, -13, -12, 4, 12, -4, 1, -1, -1,
- 27, 29, 10, 15, 2, -6, -3, 4, -21, 10, -9, -11, -6, -1, -9, -3 },
- { -6, -3, -1, -6, 11, -5, 0, -2, -5, -31, 11, 3, -1, 5, -3, 4,
- 5, 7, -10, 5, -10, -13, 4, 12, -15, -2, 2, -7, 1, -9, -3, -10 },
- { -3, -7, 17, -8, -5, 36, 8, -7, -8, -20, 12, 8, 1, -1, 3, 0,
- 1, 4, -10, 3, 1, 4, -2, -3, -2, -3, -10, 4, -1, -7, 3, 2 },
- { -13, -3, -5, 9, 22, 6, -23, 3, -10, -7, 17, 17, 18, -14, -8, -8,
- 2, 4, -8, 2, -3, -8, 6, 4, -1, 7, 0, 0, -3, 0, -12, -3 },
- { -3, -10, -15, -3, 9, 3, -23, -9, -13, -18, 12, 13, -2, 0, 1, 8,
- -1, 2, -7, -12, -5, 14, 2, 1, -22, 6, -10, -8, -9, 28, -7, -14 },
- { -3, 1, 2, -1, 13, 7, -2, -7, 1, -3, 6, 9, -3, -2, 4, -2,
- 2, 1, -10, -2, -2, -22, -2, -7, -10, -5, -11, -27, -12, -16, 4, -7 },
- { 2, -6, -3, 1, 8, 0, -2, 12, -3, -4, 58, 15, -10, -4, -2, 2,
- -2, 0, -2, -6, 2, 4, -1, 1, -4, 1, -1, -5, -4, -3, 3, 1 },
- { 10, -1, 0, 5, 21, 7, -14, 6, -3, -16, 15, 17, -16, 13, 3, -6,
- -4, 6, -12, -5, 1, -4, -7, -8, 2, 3, -6, 6, -1, -8, 5, 4 },
- { -6, -2, -8, -11, 15, 10, 0, 8, -6, -15, 33, 8, -2, 18, -15, -11,
- 5, -1, 0, 15, -15, -4, -4, -1, 10, 7, -13, 4, -4, 0, 8, 3 },
- { -7, -2, 0, -2, 0, -2, -4, -5, -14, -16, 12, 38, 7, 12, 6, -4,
- 0, -1, 0, 3, -2, -6, 0, 2, -9, 1, 0, -1, 0, -2, 4, 1 },
- { -8, -4, 18, 1, 14, 5, -12, -3, 20, -17, 5, 19, -11, -8, 11, -3,
- 3, 9, -7, -8, 9, -17, 2, 15, -10, -11, 5, -5, 7, 15, -6, -2 },
- { -7, 2, 38, 5, 19, 16, -5, 4, -13, -20, 0, 4, -4, 6, 4, 2,
- -7, 6, -8, -2, -5, -7, 6, 3, -4, -3, -2, -3, 7, -6, -4, 0 },
- { -11, -12, 8, -15, -3, 14, -7, -22, -11, 2, 22, 14, -19, 2, -19, -6,
- 1, 3, -18, 14, 2, -6, -2, -8, -3, -6, 5, -7, -8, -4, 1, 1 },
- { 8, 7, 25, -21, 12, -6, -5, -4, -10, 6, 0, 10, 1, -12, 18, -5,
- -15, 4, 1, 14, -1, 5, 8, -7, 1, -7, -3, 9, 10, 1, -1, 0 },
- { 9, 10, 32, -15, 8, 2, 11, -7, -18, -8, 2, -6, -9, -16, -3, 3,
- -1, 3, 1, -5, 4, -2, 1, -8, 0, -6, -3, -11, 1, 5, 0, 0 },
- { 14, 0, 23, -25, 22, 3, 7, 10, 0, -2, 7, 8, 0, 10, 0, 0,
- 3, 2, 3, -10, 0, 10, 0, -7, 0, 10, -1, -5, -7, 1, -1, 2 },
- { 12, 0, 25, -18, -5, -4, 13, -10, 3, -6, 7, 21, 0, -16, 3, -10,
- -6, 5, -7, -3, 2, 5, 3, -6, 4, 9, -8, 12, -2, 3, 2, 4 },
- { 31, 15, 27, -20, 10, -7, 15, -10, 9, -8, 4, -5, 3, -3, 5, 6,
- 11, -2, -12, -2, 6, -2, 1, 2, -1, -1, 1, 1, 3, 1, 1, 2 },
- { 12, -4, 13, -23, 12, -6, 2, 4, -3, 13, 6, -7, 5, -19, -7, 18,
- 1, -7, 7, 1, 16, -7, 3, 0, 3, 0, -12, 8, -11, 9, 4, 7 },
- { 29, 1, 3, -22, -5, 6, 0, 12, -14, 11, 1, 6, -3, 4, 6, -2,
- 4, -13, 12, 1, 1, 3, -11, 9, -10, -1, -7, 16, -11, -1, 3, 9 },
- { 4, 4, 36, -23, -5, -8, -15, 1, -6, 3, 13, -1, -5, -7, 4, 9,
- 2, -11, -3, 5, 1, 3, -6, -1, -4, -4, -2, 2, 3, -1, -5, -2 },
- { 19, 10, 6, -17, 2, -4, -2, -4, -3, 13, 2, 2, -13, -7, -3, -11,
- 9, -6, 1, -9, -5, 4, -5, -9, -18, -7, -11, 9, 4, -11, 8, 4 },
- { 16, -3, 9, -16, 18, -2, -12, -16, -11, 11, -18, 16, -13, 6, 2, 8,
- 3, 8, -4, -16, 10, -11, -1, -3, -8, 5, -9, -4, 9, -4, 0, -3 },
- { 14, 15, 3, -23, -5, 7, -8, -6, 2, 17, 2, 12, -8, -12, 13, -1,
- -9, 3, 1, 1, 19, 15, 4, -1, 1, 2, -3, 2, -3, 1, 5, 3 },
- { 32, 5, -10, -47, -5, -1, 4, 11, -7, 0, 2, -2, 1, -7, 6, -4,
- 6, 2, -4, -2, 2, -2, 0, -4, 1, -6, -5, 2, -2, -1, -3, -4 },
- { 20, 8, 10, -21, -7, -9, -16, 12, 1, 4, 6, -5, 9, -11, -7, 4,
- -11, 28, -3, 2, 4, -6, 10, -8, -5, -5, -9, 9, -2, -1, 6, -5 },
- { 38, 3, 23, -25, -6, -18, 3, -10, -8, 6, -10, 1, -10, 2, 2, 0,
- -7, 2, -4, 5, -1, 8, -3, 0, 3, 3, -1, 1, 0, -4, -4, 0 },
- { 20, 5, 16, -22, 24, -18, 2, -12, -14, -7, -3, 10, 2, 7, -10, 2,
- -8, 1, 8, -1, 4, 1, 4, -2, 5, -9, -18, -8, -13, 5, -11, 10 },
- { 14, 8, -12, -16, 9, -11, -3, -6, -25, -7, 6, 5, -7, -16, 10, 2,
- -7, -1, -9, -3, 16, 4, 3, 3, -3, -3, -15, 13, -3, 4, 13, -7 },
- { 16, -9, 19, -23, 7, -19, -3, -5, -15, 11, -21, 21, -16, 18, -1, 6,
- 10, -10, 18, -14, 16, -15, 6, -5, -9, 5, -17, 13, -10, 13, 0, 10 },
- { 8, -4, 4, -24, 8, -21, -18, 9, -11, 4, -6, 17, 5, -9, -2, -2,
- 2, 15, -2, -3, -2, 1, 7, -13, 15, -10, -8, -11, 3, 3, -1, -1 },
- { 14, 17, 6, -32, 5, -17, -2, 0, 15, -1, -5, 16, 1, -5, -2, 9,
- -3, 8, 4, -2, -2, -4, -3, 1, 0, 7, -3, 4, -5, 0, -7, 2 },
- { 24, 6, 22, -12, 8, 3, -14, 4, -7, 8, 6, 5, 6, 1, 6, -12,
- 15, 10, 4, 11, 9, 6, -7, -4, 10, -9, 2, -1, -5, 11, 15, 3 },
- { 17, 12, 3, -23, 5, -1, -2, 1, -9, -1, -3, 1, 8, 1, -5, 17,
- 11, 0, -2, -11, 7, 4, 0, -27, -7, 1, 2, -8, 9, 7, 5, 3 },
- { 12, 10, 12, -10, -4, 5, -1, 2, -24, 5, -8, 2, 6, -17, 19, 5,
- 12, -2, 16, -7, -6, -14, 4, 1, -3, 13, -16, 5, -1, 4, 1, 1 },
- { 31, 9, 11, -17, 10, -3, -7, 7, 1, 2, 2, 4, -3, -1, 11, 4,
- -5, -8, 1, 4, 15, -6, -28, 1, 8, 3, -6, 5, 17, -2, 2, -4 },
- { 11, 19, 16, -26, 0, -7, -7, 2, -13, -15, -12, 9, -3, 27, 8, 4,
- -6, 1, 4, -6, 11, -1, -6, -7, -3, 0, -6, 4, -6, -7, -3, -1 },
- { 10, 18, 16, -32, 19, -9, -4, -3, -7, 8, 8, -3, -11, -2, -6, -16,
- 13, 13, -6, -1, 10, -2, -2, -9, 0, -3, 9, 4, 11, -2, -6, 6 },
- { 9, 4, 19, -33, 4, 7, -12, 36, -3, -1, 8, -2, 2, -8, -9, -4,
- -8, 0, 1, -1, 0, -4, -4, 3, 0, 3, 6, 0, -6, 2, 0, -2 },
- { 25, 7, 15, -12, 2, -24, -1, 24, -4, 4, 9, 0, -2, -9, 4, 6,
- 3, 13, -3, 1, 5, -1, -3, -5, -1, 7, -2, 3, 4, 4, 1, 0 },
- { 19, 6, 8, -20, 9, -9, 5, -4, -13, 7, 11, -3, 5, -13, -9, 6,
- -11, -1, 0, 4, 11, 26, 3, 6, -7, 12, 6, -3, 1, -9, 7, 1 },
- { 15, 6, 19, -23, -3, -9, 3, 16, -6, -4, 6, -5, -10, 1, 16, -14,
- 2, 0, 2, -13, -3, 8, -6, 3, 1, 1, 2, -5, 12, -4, -8, -3 },
- { 14, 4, 16, -20, 1, 12, 0, 6, -3, 9, 4, 16, 10, -16, 5, 7,
- 5, -4, -4, -18, -3, -11, -4, 4, -7, 3, 13, 7, 3, 3, 2, -7 },
- { 22, 3, -1, -30, 18, -3, -9, 9, -2, 11, -16, -2, -14, 12, 0, 4,
- -5, 4, -1, 3, -20, 12, 4, -10, -2, -2, -12, -12, 10, 6, 11, -3 },
- { 15, 7, 2, -21, 5, 4, 9, -9, -33, 7, 7, 3, -6, -14, -8, 10,
- 12, 0, 2, -1, 5, 4, -2, 0, -7, 0, 2, 4, 0, 1, -3, 8 },
- { -7, 0, 12, 3, 0, -6, 8, -4, 0, 2, 14, -15, 2, -7, -31, -3,
- 14, 0, 14, -15, -1, -4, -15, 10, 1, -3, 1, 2, 5, 2, -8, 1 },
- { -2, 5, 1, 0, -3, 3, 3, -6, -1, 2, -4, 1, -19, 0, -11, 18,
- 11, 10, 21, 5, 6, 2, 10, 3, -6, 0, -2, 13, 5, -1, -2, 9 },
- { -9, 1, -5, 0, 0, -15, 8, 4, 8, 3, 8, 12, -13, -2, -39, -2,
- 4, -4, 5, -3, -4, 3, -3, 3, 10, 5, 3, 2, -3, 5, -2, 8 },
- { -9, 6, 6, -8, 12, -12, 23, -18, 4, -15, -5, 2, -20, 13, -7, 7,
- 7, -12, 14, -12, 6, 1, 1, -3, -8, 9, 0, 1, -7, 3, 7, -6 },
- { -18, 13, 4, 3, -10, -30, -10, -6, -14, 1, -7, -4, -35, 5, -25, 11,
- 9, 8, 19, -4, -7, -3, -18, -8, 1, 5, 10, -4, -14, -9, 3, -4 },
- { -6, -1, 4, -9, -9, 4, 20, 0, 0, 3, 11, 7, -16, -17, -20, 11,
- -6, -14, 1, 4, 19, 2, -8, 6, -15, 3, 6, -5, -14, 3, 7, 2 },
- { 1, 6, -2, -8, -5, -3, 3, -8, 21, 1, 3, 16, -14, -2, -9, -4,
- 13, -2, 18, 14, 14, 19, -13, 5, -10, 2, -3, 3, 5, 5, 1, -1 },
- { -1, -5, -6, -2, -11, -7, 5, -4, 5, -1, 0, 3, -3, 2, -19, 18,
- 16, 4, 14, -22, -2, -11, -22, 1, -1, 11, 1, 2, 11, -10, 7, -12 },
- { 1, 4, 5, -1, -9, -5, 1, 12, 5, 6, 12, 9, -24, 23, 1, 20,
- 14, -11, 13, 5, -2, -2, 5, 6, 2, 1, -9, 6, 10, 5, -4, 11 },
- { -1, -1, 1, 7, -3, -4, 8, -16, 15, -1, -7, 9, -22, -11, -11, 10,
- 16, 9, -2, 4, 13, 10, 6, 16, 4, 7, 1, -8, -7, -14, -7, 4 },
- { 1, 3, -6, 0, 15, -9, -4, 0, 4, 6, 12, 9, -6, -5, -22, 17,
- 7, -11, 15, -5, 1, 3, -19, 0, -15, -3, 16, 5, 5, -7, -11, 12 },
- { -2, -1, 13, 2, 4, -24, 37, -5, -2, -6, 12, 7, -2, -23, -4, 9,
- 2, -3, 3, 2, 3, 3, -14, 11, 0, -4, -2, -2, 3, 10, -10, 4 },
- { 2, 9, 8, -6, -28, 14, 28, -11, 18, -11, 0, 2, -2, 4, -12, 3,
- 6, 0, 7, -7, -6, 2, 5, -1, -1, -1, 5, 2, 3, 0, -3, 9 },
- { -7, 14, 5, -10, -3, 7, 4, -5, 7, -8, -7, 4, -12, 14, -16, 25,
- 3, 0, 1, -5, 12, -10, 0, -10, 0, 12, 12, 17, 12, 10, -1, 0 },
- { -4, -2, 5, -2, -17, -3, 5, -5, 7, -17, 1, 5, -4, 4, -20, 0,
- 11, -15, 13, -8, 10, 1, 1, 5, -12, 9, -8, 0, 6, -1, -11, 4 },
- { -3, 12, 13, -15, -7, -7, 0, 5, 33, 3, 3, -6, -13, -7, -15, 10,
- 3, 3, 3, -5, 2, 7, -1, 0, -12, 2, 11, -6, -9, 0, 5, 11 },
- { -8, 5, 10, -7, -14, -4, 13, 0, 18, -3, -6, 7, 1, -6, 0, 21,
- 8, -7, 10, -8, -3, 17, -9, 0, -5, 1, 4, 8, -3, 11, -5, 0 },
- { -8, 8, -3, -8, 8, -11, 16, -16, 17, 0, 8, 16, -17, 10, -16, 10,
- -8, 6, 11, 0, 10, 7, 4, 5, 7, -5, -5, -6, -7, -5, -1, 16 },
- { -6, 0, 6, 1, -8, -8, 8, -7, -5, -10, -11, 8, -19, 6, -7, 13,
- 5, -3, 4, -8, 7, -1, -18, 9, 0, -5, 6, 26, 3, 8, 2, 4 },
- { -2, -2, 23, -2, -20, 2, 7, -7, -6, -15, 3, 9, -19, -2, -10, 7,
- -2, 7, 9, 11, 0, 4, -4, 6, 9, -2, 4, -3, 4, 3, 2, 8 },
- { -6, 12, 10, -10, -7, 4, 17, 11, -6, 1, 12, 11, -18, 8, -12, 4,
- 1, 13, 6, -13, 23, 9, -5, 8, -2, -5, 1, 3, 0, -2, -4, 4 },
- { 7, 1, 7, -17, -8, 8, -1, -7, 5, -6, 4, -3, -16, 9, -24, 18,
- -3, 10, 13, -11, -6, -11, -4, 10, 0, 11, 8, 2, 6, -5, -11, 4 },
- { -4, 1, -5, -10, 0, -3, 9, -2, 4, -1, 1, 5, -41, -10, -7, 4,
- -3, 3, 1, 0, -12, 4, -3, 0, 2, -1, -2, -5, 3, 2, -7, 5 },
- { -2, 1, 4, 4, -3, -6, 1, 0, 12, -5, 11, 0, -17, -3, -1, 11,
- 4, 1, 27, -12, 0, -14, 2, -15, -3, -9, 0, -7, -3, 15, -8, 6 },
- { -6, 4, 9, 2, 4, 3, 7, -10, 28, 1, -2, 48, 7, 0, -10, 10,
- 1, -9, 2, -1, 0, 3, -5, 5, -4, -2, 7, 7, 1, 3, 2, 5 },
- { -3, 3, -1, 3, -9, 0, -1, 3, 2, -6, 39, -14, -12, 5, -19, 21,
- 7, -6, 4, -1, -4, 0, -4, 1, 0, -9, 1, 10, 0, -2, 0, 7 },
- { 4, 2, -29, 12, 5, -3, 16, -6, 15, -13, -4, -1, -13, 22, -16, 17,
- 16, 4, 9, -4, 4, -6, -4, 11, -8, 7, 8, 4, 3, -3, -7, -13 },
- { 0, 3, 3, -6, -4, 0, 9, 0, 5, 0, 10, 10, 4, -13, -12, 16,
- 23, -4, -12, -6, -4, 20, 2, 0, -4, 23, 1, 8, 11, -4, -5, 15 },
- { -6, 4, -15, -9, -1, -19, 12, -30, -17, -4, 1, -13, -13, 4, -3, 26,
- 5, -25, 11, -14, -6, -13, 0, -7, 9, 2, 8, -1, -8, 1, -8, 13 },
- { 1, 6, 1, -4, -4, 1, 2, 0, -3, 2, 10, 6, -6, -2, -11, 4,
- 32, 15, 15, -47, -8, 3, -12, 4, -5, 4, -1, 0, -5, 5, 1, -7 },
- { 2, -1, 0, 0, -1, -6, 0, -6, 4, -4, 5, 9, -5, 1, -3, 51,
- 4, -5, 4, -14, -1, -4, -3, 1, -4, -1, 0, 2, -8, 0, 1, 2 },
- { 0, 4, -2, -7, -2, -9, 6, -8, 11, -3, -6, 3, -11, -8, -12, 8,
- 11, 5, 19, 3, -24, 19, -14, 11, -5, -18, -8, -12, -5, -4, -1, 4 },
- { 16, 9, 10, 14, -18, -2, -18, -27, 10, -5, 12, 14, 4, 0, -2, -6,
- -12, -7, -1, 3, 4, 7, 11, 10, 5, -5, -7, -16, -3, -6, 6, 9 },
- { 7, 15, -9, 10, -19, 4, -5, -37, -2, -4, 8, 2, 4, -1, 1, 9,
- -5, -5, -12, 1, -1, -8, 3, -3, 4, 6, 9, 3, 3, -1, 2, 4 },
- { 13, 17, 3, 9, -7, -7, -15, -17, -8, -13, -4, -8, 19, 2, 16, 25,
- 7, 15, 2, 16, -5, -6, -10, -9, -7, -6, -2, -7, 7, 2, 4, 5 },
- { 24, 7, 9, 8, -13, -2, 0, -4, 1, -13, 3, 6, 7, 10, -4, 15,
- 5, 7, -4, 5, -5, 3, 13, -7, 5, 15, -11, -2, 7, 5, 8, 6 },
- { 17, 6, -15, 23, -2, -1, -6, -2, 0, -4, 11, -3, 12, 15, 6, -8,
- -15, 10, -9, 7, -1, -11, 2, -8, -4, 3, 4, -10, 4, 4, 11, 1 },
- { 21, 12, -3, 6, -8, 8, -11, -8, -5, -5, 3, 7, -1, -5, 12, 15,
- -10, -11, 3, 15, 8, 4, 2, -15, 0, 14, 1, -8, -1, 3, 10, -7 },
- { 16, 12, 5, 13, -6, 15, -23, 0, -17, -9, 0, 4, -9, 13, 6, 18,
- 0, 0, -4, -1, 0, 14, 5, -1, 8, -4, -8, -6, 5, -2, -2, 0 },
- { 14, 16, -1, 12, -15, -9, -6, -20, 4, 6, 8, 9, 3, 1, -9, -4,
- -1, -11, 9, 11, -12, 1, -14, -7, 2, -8, 11, 9, -4, 10, 4, -16 },
- { 13, 10, 3, 7, 0, -8, -33, -6, 4, -4, 19, -2, 14, 6, 5, 7,
- 6, -3, -1, -10, -10, -9, 4, -3, 5, 9, 2, 2, 10, 9, -2, -3 },
- { 11, 10, 25, 18, -1, -6, -21, -21, -11, -16, 6, 5, 14, 4, 8, 7,
- 0, -10, -7, -9, -5, -4, 3, -1, 1, 6, -1, 6, -2, 2, -3, -9 },
- { 15, 9, 5, 22, -17, 15, -9, 7, 7, -9, 13, 9, 10, -1, 8, -3,
- -2, 6, 1, 17, 8, -14, 7, -3, 12, 9, 1, 0, 1, -5, 17, -18 },
- { 25, 19, -17, 12, -4, -10, 1, -13, -19, -7, -3, 9, 6, -2, 3, 1,
- 4, -2, -11, -14, -1, -7, -5, -9, 7, -1, -3, 4, -5, 1, 0, -1 },
- { 20, 8, -3, -10, -24, 3, -6, -2, 0, -12, 14, 6, 7, 11, 4, 7,
- -12, -5, -8, -10, 5, -1, -4, 4, 16, 7, -14, 6, -1, -2, -7, -11 },
- { 16, 18, 17, 1, -15, -6, -5, -3, -1, -19, 8, -2, 2, 8, 12, -19,
- -12, 8, 0, -3, -1, -1, 4, -14, 9, -1, -12, -1, -7, 10, -3, 5 },
- { 18, 12, -7, 7, 0, -3, -13, 0, -1, -4, 9, -2, 6, -1, 0, 1,
- 15, -21, 1, -8, 25, -19, 13, -9, 2, 12, 5, -7, -3, -1, -3, 1 },
- { 13, 16, -4, 9, -2, 2, -1, -19, -7, -4, 18, -6, 14, 18, -5, 4,
- -6, -3, -19, -14, -1, -12, 10, 6, 7, 17, -12, -13, -10, -4, 5, 4 },
- { 27, 17, 4, 14, -9, -2, -4, -8, 0, -6, 14, -11, -7, 2, -3, -3,
- -2, -3, -13, 12, 16, 1, -5, -9, -10, -11, -2, 3, -7, 5, 11, -7 },
- { 7, 17, -16, -2, -14, -28, -7, -8, 15, -10, 7, 15, 8, 17, 13, -1,
- 4, -7, -12, -11, 0, 0, 2, 3, -3, 7, -6, 6, 1, -16, 1, -2 },
- { 23, 11, -9, 15, -23, -4, -6, -4, 2, -9, -7, 9, -8, 3, -13, -4,
- 8, 18, -6, -2, 1, -5, 6, -14, -5, -2, -6, -5, -3, -2, 4, -5 },
- { 12, 13, 18, 18, -35, 2, 7, -17, 3, -11, 6, 9, -3, -2, 10, -4,
- 3, 3, -2, -7, 0, 2, -4, 0, -4, 0, -6, 5, 10, 4, -3, -1 },
- { 19, 11, 1, 20, -14, 4, -9, -13, -2, 11, 0, 17, -1, -1, -1, -1,
- -5, -8, 0, 5, -1, -8, 5, -1, 3, 2, -12, 21, -2, -24, 5, 7 },
- { 15, 15, -15, 17, -14, -22, 3, -4, -11, -3, -7, 1, 18, 10, 1, 10,
- -6, -3, 8, 2, -7, 0, -2, 1, 1, 2, -9, -2, 1, 2, -3, 4 },
- { 45, 13, 8, 17, -5, 2, -16, 2, 8, -2, 8, -15, 4, 5, -1, 7,
- -6, -2, -6, 2, -3, 0, 0, -9, -1, 7, 2, 3, -3, -3, -1, 5 },
- { 1, 18, -8, 18, -12, -10, 3, 4, -22, -12, 20, 8, -3, 9, 2, 10,
- -10, -3, 9, 3, 6, -3, 10, -1, -3, 2, -2, 4, 2, 3, -3, -18 },
- { 9, 10, -5, 9, -35, -21, -18, -16, -1, -12, -6, -7, -15, -19, 12, 4,
- 4, 9, -7, 2, 14, 1, 4, 0, -1, 6, -7, 2, 1, 1, -4, 4 },
- { 31, 8, -17, 35, -8, 1, -5, -6, -7, -6, 10, -2, -3, 6, 9, 3,
- -6, -2, 3, 3, 5, -3, 0, 6, 0, 1, -5, -3, -2, -4, -1, 0 },
- { 18, 4, -8, 7, -8, -15, -1, -16, 12, 18, 3, 19, 2, 4, 8, 8,
- 0, -5, -8, -12, 10, -5, 0, 1, 0, 4, -3, 16, 11, 11, -2, -6 },
- { 27, 15, -17, -10, -23, -22, -1, -14, -4, -7, 20, -2, -7, 6, 15, -5,
- 32, 4, 9, -11, -3, -8, 11, -4, -1, -4, -8, -6, -4, -5, -2, -7 },
- { 22, 4, -7, 2, -15, -11, -17, -10, 2, 0, 15, 11, 7, 12, -8, 6,
- -10, -18, -6, -12, 7, 3, 22, 3, -7, 14, -5, -2, -13, -7, -1, -7 },
- { 18, 13, 9, 24, -4, -19, -9, -11, 13, 8, 2, 4, -1, 8, 14, 10,
- -12, 0, 0, 5, 10, 5, 4, -1, 5, 1, -1, 11, 2, -4, 0, -9 },
- { 15, 19, -5, 1, -4, -10, -8, -27, 6, 8, 5, 10, 4, 11, 5, -5,
- -11, 0, -11, -14, -4, -9, -8, -8, 6, -9, 4, -5, -1, 1, 5, -4 },
- { 18, 1, -13, 14, -14, 9, -15, -7, 12, 1, 13, -4, -20, 12, 10, 12,
- -12, 7, 1, -13, 10, -6, 5, -3, 4, 8, 10, -13, -3, -6, 9, -3 },
- { 19, -14, 5, -8, -6, 2, -5, 5, -3, -1, -28, 11, 18, -6, -4, -2,
- 11, 14, -43, -42, 9, 2, 20, -23, 6, 32, 0, 5, 0, 6, 9, 5 },
- { 8, 11, -14, -1, 7, 12, -7, 2, -16, 2, 10, -3, -1, -7, -7, -1,
- 1, -10, -60, -23, -18, 42, -13, 9, 18, -11, 0, 1, 0, 2, -5, 1 },
- { -5, -1, 2, 0, 3, -3, 3, -2, -6, 0, -3, -3, 7, 2, 0, -2,
- -2, 3, -34, -15, 37, 47, 10, 20, 9, 1, 3, -21, -25, -33, -14, 8 },
- { 5, 6, 2, -2, -2, -2, 6, 5, -5, 7, -3, 1, -5, -13, 9, 3,
- -17, -19, -2, -79, -12, -7, -8, -6, -2, -2, -1, -1, -7, -13, 6, -1 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1,
- 0, 3, 4, -87, 6, -11, 16, -9, -1, 8, 0, 5, 0, 1, 2, 1 },
- { -5, 6, 2, -24, 5, -9, -7, 0, 7, 3, -3, 16, -14, -16, 0, 18,
- 15, -9, -14, -28, -17, 53, 14, -6, -28, -1, -3, -10, -7, -14, 19, -15 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -3, 0,
- -13, 0, -53, 3, -22, 63, 19, 16, 1, -11, 0, -3, 0, -3, 0, 1 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1,
- -1, -6, -43, -43, -2, 65, -13, -4, 9, 1, 1, 2, 1, 0, 0, 1 },
- { 0, 1, 0, 0, -1, 0, 1, 1, 0, 0, 1, 2, -1, -1, -3, -1,
- -23, 1, -61, -55, 3, -28, -6, -4, -4, 8, 2, 1, 1, -1, 0, 0 },
- { 0, 1, -1, 1, -1, 0, -1, 0, 1, -1, 0, 1, -1, 0, -9, -4,
- -48, -19, -52, -46, 11, -12, 5, -14, 0, -10, 0, 0, -1, -2, -1, 0 },
- { 0, -3, -1, -4, 2, -1, -7, 3, 1, 3, -1, 1, -3, 0, -7, 0,
- 3, -7, -61, -51, -4, -21, -16, -21, -11, 14, -7, 8, 3, -5, 1, 2 },
- { 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, -1, 9, -3,
- 56, -11, -6, -67, -1, 13, 0, 7, 1, -9, -1, -1, 0, 0, 1, 0 },
- { 14, 9, -2, 14, -10, -10, 9, -5, 1, -8, -23, 30, 8, -7, 23, 8,
- 2, 10, -1, -27, -17, 57, 22, 4, -5, 2, -12, -6, 2, -7, -4, -9 },
- { 1, 5, 12, -2, -2, -3, 2, -3, 6, 0, 4, -2, -8, -6, 0, 16,
- -15, 29, -55, -29, -24, 29, 3, 10, 6, 13, 10, -5, 21, 11, -14, 5 },
- { 4, 2, 26, -6, 10, 11, -23, -10, -27, -20, 3, -24, -11, -10, -13, 25,
- -10, 5, -9, -36, -7, 43, 3, -13, 6, 13, -2, 0, 1, 3, -3, -4 },
- { -1, 0, -1, 0, 0, 0, 0, -1, 1, 0, -1, 0, 0, 0, -1, 1,
- -12, 12, -26, -64, -15, 29, 37, -7, -3, -12, -5, 14, 8, -8, -10, -2 },
- { 19, -4, -11, -16, 8, 14, 5, 19, 3, 22, -11, -21, -1, -6, -11, 11,
- 10, -24, -23, -40, -8, 20, 17, 5, 13, -6, 3, 14, -20, -8, 3, 28 },
- { 2, -12, 10, -14, -18, 26, -22, 4, -2, 5, -21, 8, 3, 1, 19, 0,
- -12, 24, -14, -40, 15, 29, -15, 6, 15, 1, -19, 2, 4, 7, -12, -3 },
- { 0, 17, 13, 7, -5, -11, 2, -19, 3, 38, -21, -3, -6, -4, 7, 1,
- 1, -5, -40, -10, -2, 35, 8, 8, -10, -8, -9, 33, 4, 4, 0, -2 },
- { -2, -12, 7, 29, -24, 2, 16, -1, -7, 16, 10, -2, -2, -2, 13, -2,
- -37, 15, -22, -40, -11, 33, 10, -1, 8, 10, 6, 8, 9, 0, -12, 2 },
- { 15, -8, -9, -2, 7, -17, 7, 19, 14, 4, 12, 27, 11, 10, 4, 11,
- -15, 14, -13, -48, 5, 18, 0, -9, -36, -11, 2, 4, 5, 5, -15, -12 },
- { -12, 0, 3, 4, 7, -5, 5, -14, -24, -18, -6, -15, -8, -20, 1, -7,
- -33, -28, -40, -38, -18, -10, -5, 17, -12, 4, 3, -5, 5, -13, 4, -7 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1,
- -3, -9, -49, -60, -5, 45, -1, 6, 0, 0, 0, 0, 0, 0, 0, 0 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1,
- -3, -9, -49, -60, -5, 45, -1, 6, 0, 0, 0, 0, 0, 0, 0, 0 },
- { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0,
- 3, -2, 9, -29, -11, 55, 8, 32, -36, -13, -7, 37, 4, 11, 0, 3 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 4, -1, -39, -4, -30, 63, 28, -17, -6, 10, 7, -14, -9, 11, 9, 7 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
- 13, -2, -50, -32, 22, 51, 4, 7, 6, 11, -20, -13, 9, -5, 21, -4 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1,
- -3, -9, -49, -60, -5, 45, -1, 6, 0, 0, 0, 0, 0, 0, 0, 0 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1,
- -3, -9, -49, -60, -5, 45, -1, 6, 0, 0, 0, 0, 0, 0, 0, 0 },
- { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0,
- 3, -2, 9, -29, -11, 55, 8, 32, -36, -13, -7, 37, 4, 11, 0, 3 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 4, -1, -39, -4, -30, 63, 28, -17, -6, 10, 7, -14, -9, 11, 9, 7 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
- 13, -2, -50, -32, 22, 51, 4, 7, 6, 11, -20, -13, 9, -5, 21, -4 },
- { -8, 2, 1, 22, -31, -6, -25, -3, -3, 1, -15, -11, -2, -3, 4, -13,
- -9, 15, -18, 37, -7, -37, 12, -13, -11, -25, -10, -11, -22, 7, 16, 7 },
- { 14, 10, 4, -10, -1, -5, -7, -3, 16, 13, -5, -15, 5, 11, -1, 8,
- -27, 7, -12, 49, 17, -22, 9, -2, -9, -1, 2, -15, -1, 41, -18, -17 },
- { -4, -9, -15, -3, 3, 4, 4, 2, 7, -3, -7, -8, -5, 17, -19, -7,
- 36, -9, -38, 17, 1, -48, 11, -18, -13, -2, -8, 4, -10, -5, 21, 11 },
- { 15, -13, 4, 2, 1, -5, -2, 1, -10, 7, -1, 3, -6, 0, 11, -11,
- 8, 20, -17, 51, -17, -41, 2, 15, 4, 8, -2, 16, -32, -1, 17, 6 },
- { -8, 8, -18, -5, 4, 6, -3, 8, 0, -4, 2, 0, -1, -4, 5, 8,
- 30, 30, -8, 70, 2, 8, 2, 0, 7, 1, 13, -1, -6, -7, -11, 2 },
- { -8, -7, 9, -10, -13, 6, -11, -14, 13, 25, -26, 5, 2, -5, -5, 5,
- -8, 4, 0, 33, 12, -38, -4, 6, 13, 6, 25, 34, -1, 25, -19, -5 },
- { 18, 3, -17, 4, -8, 7, 20, 1, -1, 5, -5, -2, -8, 8, -35, 15,
- 24, 43, -5, 51, 5, -12, -3, 1, -2, 3, -3, -3, -9, 8, -9, 2 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
- 2, 10, 24, 76, -2, -22, 11, -1, 4, 33, 4, 1, -1, 1, 2, 0 },
- { 0, -1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 2, 0,
- 24, 13, 32, 70, 26, 5, -21, -9, -6, -15, 2, -2, 2, 4, 1, 1 },
- { 5, -4, -11, 4, -4, 22, 10, -2, 13, -11, -4, -21, -17, 0, -7, 4,
- 10, -34, 11, 52, 2, -46, -5, 0, 0, -1, 2, 4, -9, 1, 1, -7 },
- { 0, 1, 1, 0, -1, 0, 1, 0, 1, 1, 0, 1, 0, 0, -3, 1,
- -8, 9, -1, 64, -13, -61, -3, 3, -5, 10, 1, 3, -1, -1, -1, -1 },
- { 0, 1, 0, -1, 0, -1, 0, 0, 1, 0, 0, 0, 1, 1, 2, 1,
- 10, -2, -31, 79, -10, 27, 0, -1, 3, 8, 1, 1, 0, -1, 0, -1 },
- { 3, 12, 10, 26, -19, 10, -9, 6, -4, -15, 10, 3, -16, 6, 11, -19,
- 3, 10, 18, 44, 5, -30, 5, -9, 21, 4, 20, 10, 14, -25, 8, -17 },
- { 0, 0, 0, 1, -1, 0, -1, 0, 1, 0, 1, 1, 0, 0, -6, -2,
- 8, -8, 13, 69, 26, -19, -25, -17, 16, 6, -12, 22, 2, -6, 9, 5 },
- { 0, -1, 0, 1, 0, -1, -1, 0, 0, 1, -2, 1, 0, 0, -4, -1,
- -34, -15, -33, 56, 9, -42, 9, 10, 6, 9, -8, -11, 0, -6, 15, 5 },
- { 10, 2, -14, -3, -15, -35, -1, 7, -18, 14, 8, -1, -15, -26, 6, -15,
- -18, 22, 9, 33, 0, -32, -9, 3, -11, 7, 4, -1, 5, 30, 9, 1 },
- { 4, 15, 0, 6, -5, -11, 9, 6, 6, 6, 14, 2, -1, 10, -24, -25,
- -2, -4, -1, 37, 2, -29, 14, -9, 22, 17, -2, 33, 10, -25, 11, -11 },
- { 0, 5, 2, 18, -12, 21, 22, 33, -7, 21, -9, -7, 7, -15, -7, 16,
- 7, 0, -14, 44, 10, -25, 5, -4, 15, -8, 10, -4, 5, 9, -1, 16 },
- { 3, 13, 12, 12, 8, 25, -23, 8, -22, -3, -18, -8, 15, 12, 9, 19,
- 0, 0, -9, 49, -27, -15, -9, -15, 12, -8, -16, -7, 13, 5, 13, 2 },
- { 12, -6, 7, -2, 20, -9, -14, 12, 13, -5, -17, 22, -8, -4, 2, 7,
- -13, -2, -15, 43, -5, -30, 27, 4, 10, -27, 5, 27, -10, -10, -18, 0 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
- -1, 10, -18, 70, -2, -52, -1, -7, 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, 10, -18, 70, -2, -52, -1, -7, 0, 0, 0, 0, 0, 0, 0, 0 },
- { 15, -13, -20, 16, 2, 13, 5, -11, -8, -5, -3, 2, 24, -23, 30, -7,
- 11, 30, -15, 43, 5, -15, 15, -3, -14, 1, -23, 8, 3, 9, 4, -11 },
- { 0, -1, 0, 1, 0, -1, -1, 0, 0, 1, -2, 1, 0, 0, -4, -1,
- -34, -15, -33, 56, 9, -42, 9, 10, 6, 9, -8, -11, 0, -6, 15, 5 },
- { 10, 2, -14, -3, -15, -35, -1, 7, -18, 14, 8, -1, -15, -26, 6, -15,
- -18, 22, 9, 33, 0, -32, -9, 3, -11, 7, 4, -1, 5, 30, 9, 1 },
- { 4, 15, 0, 6, -5, -11, 9, 6, 6, 6, 14, 2, -1, 10, -24, -25,
- -2, -4, -1, 37, 2, -29, 14, -9, 22, 17, -2, 33, 10, -25, 11, -11 },
- { 0, 5, 2, 18, -12, 21, 22, 33, -7, 21, -9, -7, 7, -15, -7, 16,
- 7, 0, -14, 44, 10, -25, 5, -4, 15, -8, 10, -4, 5, 9, -1, 16 },
- { 3, 13, 12, 12, 8, 25, -23, 8, -22, -3, -18, -8, 15, 12, 9, 19,
- 0, 0, -9, 49, -27, -15, -9, -15, 12, -8, -16, -7, 13, 5, 13, 2 },
- { 12, -6, 7, -2, 20, -9, -14, 12, 13, -5, -17, 22, -8, -4, 2, 7,
- -13, -2, -15, 43, -5, -30, 27, 4, 10, -27, 5, 27, -10, -10, -18, 0 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
- -1, 10, -18, 70, -2, -52, -1, -7, 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, 10, -18, 70, -2, -52, -1, -7, 0, 0, 0, 0, 0, 0, 0, 0 },
- { 15, -13, -20, 16, 2, 13, 5, -11, -8, -5, -3, 2, 24, -23, 30, -7,
- 11, 30, -15, 43, 5, -15, 15, -3, -14, 1, -23, 8, 3, 9, 4, -11 },
- { 16, -18, 7, -4, 31, -15, -9, -13, 20, -12, -6, 0, 12, -6, -2, 4,
- 3, -3, -1, 0, 1, 3, 3, -2, 1, 6, 4, 0, -3, 2, -5, 1 },
- { 38, -5, -13, -4, 8, -15, 11, 1, 2, -4, -1, 9, 13, 4, -12, -7,
- 0, -2, 7, 2, -6, -2, -3, -2, 3, -4, 6, 15, 1, 1, -11, -2 },
- { 47, -22, 9, -26, 3, -5, 2, -7, 4, -2, 2, -2, 3, 0, 3, -4,
- 3, -3, 2, -3, 7, -3, -1, 1, 1, -5, 5, 0, 2, -5, -3, -2 },
- { 14, -16, 2, -6, 7, -2, -7, -4, -4, -7, 14, -3, 7, -19, -14, -17,
- -29, 6, 26, 16, -5, 13, -4, -1, 21, 14, 1, 3, -6, 0, -7, -1 },
- { 29, -11, 5, -3, 4, 11, 4, -10, 1, -22, -3, -10, 5, 4, 2, 8,
- -2, -7, -12, -12, -8, -3, -18, -2, -9, -5, -1, -3, 2, -14, -14, 7 },
- { 28, -12, 5, 3, 9, -7, 0, -2, 2, 1, 4, 0, -7, -3, -2, 4,
- 4, 14, 8, -1, -4, 14, -7, 17, -2, -2, -9, 2, 19, -7, 9, -8 },
- { 31, -18, -22, 8, 15, -5, -10, -15, 1, 10, 6, 7, 6, -8, 2, -1,
- 12, -3, 3, -1, 1, 5, -6, -4, 0, 1, 7, -10, -2, 4, -3, -4 },
- { 53, -30, -4, 12, 2, 3, -3, -3, 0, 1, 6, 5, -5, -4, -7, 1,
- 0, 2, 1, 3, 1, 5, 0, 2, 2, -1, 0, 4, 2, 0, -2, 0 },
- { 27, -18, -3, -2, 4, -8, 3, -2, -11, 2, 10, -8, -8, -4, 0, -2,
- 8, 0, 9, 0, -16, 11, 1, -6, 13, -3, -10, -13, -15, 25, 1, 0 },
- { 35, -5, -1, -8, 23, 11, -14, -3, 2, -2, 8, -6, 17, -2, 7, 0,
- -2, 10, -17, 13, -2, -2, 11, 11, -14, 2, -2, -3, -8, -1, -12, -5 },
- { 29, -9, 7, 3, 2, -10, 0, 3, 9, 0, -3, 5, 1, -10, 10, -5,
- 3, 6, -20, -9, -6, -4, 1, 0, 12, 17, -8, 9, 3, -1, -9, 0 },
- { 15, -16, 18, -19, 16, -15, 17, -18, 13, -16, 17, -14, 15, -9, 13, -17,
- 9, -7, 4, -5, 3, -4, -3, 0, -6, 7, -9, 7, -2, 7, -9, 9 },
- { 21, -10, 7, -2, 12, -7, 13, -17, 11, -2, 20, 3, 5, -11, -6, -6,
- -15, 0, -9, 5, -11, 7, -1, 7, 8, -10, -9, 3, -5, 9, -8, -2 },
- { 23, -22, 15, -5, 16, -4, -3, -12, 9, 3, -1, -2, -8, 2, -2, -16,
- 3, 4, -2, -6, -7, 12, -8, 2, -14, 2, -7, 11, -2, 6, -4, -1 },
- { 34, -17, -4, 8, 4, -6, 1, 8, 4, 16, 3, 6, 12, -1, -1, -15,
- 6, 4, -7, -6, 6, 0, 2, 1, -2, 2, 3, 3, -3, -2, 8, -6 },
- { 18, -18, 2, -2, 10, 1, 18, -23, -3, -10, 0, 4, 20, -19, -3, -4,
- 2, 8, 6, 1, -3, 1, 1, 3, 5, -1, -11, 3, -7, 5, -1, 1 },
- { 15, -14, 2, 3, 10, -8, 12, -13, 13, -15, 6, -8, -4, -10, 14, -9,
- 24, 2, -7, -18, 13, -11, 8, 14, -6, -2, 3, -1, -4, 7, -7, -4 },
- { 20, -12, 13, 5, -1, -10, 15, -6, 8, -1, -3, -10, 17, 0, -6, -19,
- 2, -1, 8, -3, -16, 0, -3, 2, -2, 0, 8, -9, 0, 1, -10, -9 },
- { 32, 0, -9, -5, -1, 5, 13, -11, 8, 3, 11, -11, 0, -8, -2, -14,
- 7, 10, 6, -5, 1, 10, 2, 12, -10, 4, 4, 6, 4, 0, -7, -10 },
- { 16, -14, 10, -7, 11, -11, 11, -11, 18, -13, 8, -15, 16, -11, 13, -9,
- 8, -7, 12, -11, 7, -6, 3, -5, 9, -5, 4, -1, 7, -4, 8, -3 },
- { 24, -27, -1, 5, 8, -5, 12, 7, 4, -3, 3, -1, -9, -11, -13, -5,
- 10, 0, -13, 7, 1, -5, 4, -9, 7, -3, 13, 2, -5, -3, -17, -2 },
- { 23, -19, 15, 1, -10, -18, -12, -6, 8, -3, 12, 0, -12, -10, -4, -4,
- 8, -10, 4, 2, -2, -8, 13, -3, -2, -6, 2, -3, 5, -2, 2, 11 },
- { 25, -12, 4, 2, 24, -3, 3, -6, 14, 11, 0, -21, -3, -3, 1, -8,
- 7, 0, 0, 3, 3, -6, -7, 6, 2, 1, -4, 5, -1, 10, -2, 9 },
- { 24, -8, -6, 7, 16, -12, 13, -1, 11, -21, 2, -6, 3, -12, 0, 9,
- 4, 11, -7, 1, 4, 1, -8, 3, 3, -6, 3, 3, 0, -8, 8, 4 },
- { 25, -21, 13, 14, 13, -18, 4, -3, 0, -5, -4, 5, -3, 0, 4, 12,
- 7, 3, 5, -5, 2, -2, 3, -10, 2, -9, -15, 6, 1, 7, -5, 1 },
- { 23, -16, -2, 10, 4, -1, 3, 1, 32, 3, -5, -2, 9, 10, -1, -4,
- -6, 2, 9, -1, 14, 12, -6, -1, -17, -2, -4, -9, -7, -6, -8, 3 },
- { 50, -8, 5, 2, -11, 10, 0, 0, 6, -3, 7, 0, -3, -2, -3, 0,
- 6, -4, 2, -5, -9, 0, 3, 10, 1, -7, -2, -3, -6, -9, 1, -2 },
- { 28, -17, 0, -2, 2, -9, 1, 5, -4, -1, 0, 0, 19, -27, 5, -12,
- 7, -14, -3, -6, 10, -2, -4, -2, 4, -5, -2, -7, 1, 7, -9, 4 },
- { 22, -19, -6, -6, 3, -22, 3, 5, 20, -8, -14, -5, 1, 1, 20, 2,
- 16, 6, 3, 14, 4, 3, 5, 1, 5, -7, -10, -6, 3, -6, 1, -14 },
- { 29, -14, -8, 13, 8, -10, -6, 4, 4, -6, 5, -7, 1, 12, 14, 11,
- -7, 1, 2, -9, -11, -9, 0, 4, -1, 7, 10, 4, 4, 20, -1, -11 },
- { 18, -9, 4, 1, 7, -29, 12, 1, -1, -9, -2, -1, -2, 2, 9, -8,
- -13, 5, 4, -13, -4, 2, -5, -7, -6, 14, -10, -34, -3, 1, -3, -13 },
- { 38, -9, 24, 8, 11, 4, -6, -11, -2, -12, 1, 1, -11, -8, -5, -2,
- -15, -8, 8, 0, 1, -7, 5, 4, -1, 8, -2, 11, -3, -1, -5, -5 },
- { -20, 11, -4, 24, -11, 1, 15, 4, 0, -28, -10, -1, 10, 10, -6, 5,
- -6, 2, 7, -2, 1, -2, -6, -3, -7, 1, 2, 12, -1, 7, 0, -2 },
- { -9, 10, -23, 27, -4, -17, 20, -6, 14, -17, 5, -1, 5, -9, -7, 5,
- -6, 4, -2, 9, 0, 8, 0, 1, -3, -3, -5, -8, 5, -2, -2, 12 },
- { -10, 19, 4, 9, 1, -16, 17, -2, 9, -29, -16, -11, -4, 7, -5, 4,
- -1, -3, 3, 2, 3, -4, 5, -12, -2, 6, 5, -4, 4, 1, 4, 10 },
- { -20, 10, -24, 14, -5, 11, 9, 0, 16, -20, 10, -5, -6, -6, -1, 2,
- -4, 5, -16, 8, -2, 5, 5, -11, 9, -11, 4, -11, -1, -1, 4, 3 },
- { -9, 11, 3, 19, 24, 4, 5, -14, 30, -17, -4, -2, -17, 7, 2, 3,
- 1, 3, -7, -4, 2, -3, 1, 4, -1, -1, 3, -12, -2, 3, -3, 10 },
- { -19, 18, 11, 19, 19, 19, 10, 4, 13, 6, 5, 4, 8, 3, -2, 12,
- -6, -2, 7, -6, 15, 12, 16, 16, 18, -3, -4, -20, 0, 10, -9, -3 },
- { -21, 9, 20, 12, 0, -3, 5, -9, 15, -13, 5, -5, -6, 24, 2, 9,
- -5, 2, -7, 2, 5, 7, -5, 2, 15, 3, 1, -1, -4, -2, 7, 0 },
- { -18, 16, 13, 15, 2, -10, 14, -11, 4, -11, 5, 12, 12, 20, 8, 30,
- 2, 11, -9, 7, 0, -3, -16, -5, -6, 5, -4, -21, 0, 5, 6, 1 },
- { -26, 8, -13, 9, 6, -10, 2, -11, 7, -4, 6, -19, -11, -6, -12, 16,
- 0, 5, -7, 8, 5, 6, 17, -9, 10, -10, 5, -3, -11, 2, 4, 10 },
- { -11, 17, -3, 22, -5, 18, 3, 1, 4, -5, 14, -27, 5, -7, -4, -5,
- -10, 11, 1, 15, 1, 1, -6, -5, 10, -22, -7, -7, -15, 13, -4, 5 },
- { -17, 14, -7, 13, 3, 0, 13, -6, 9, -14, -22, -1, 1, 19, 14, -3,
- 4, -13, -13, 2, -4, 8, -2, -2, 13, -12, 13, -12, -7, -5, -3, 6 },
- { -17, 17, -1, 33, 6, 3, 9, -16, 3, -14, -8, 6, -17, 8, 3, 13,
- 8, -6, 3, 1, -2, 0, -2, 8, 4, 9, 13, -10, 4, -17, 0, -6 },
- { -20, 7, 7, 21, 1, -3, 7, -3, -2, -12, 9, -7, 2, -3, 14, 1,
- -1, -7, 12, -10, 5, -20, 11, -2, 0, -24, -17, 6, 6, -4, 3, -1 },
- { -8, 10, 6, 7, -1, -6, 28, -6, 10, -33, 1, -20, 0, -12, 10, 1,
- -6, 8, -3, -1, -10, 8, 5, 0, 10, -2, 8, 16, -5, -3, -7, 4 },
- { -17, 13, 3, 15, 1, -5, 27, -5, 6, -6, 12, 2, -4, 8, -1, -3,
- -2, 12, -15, 3, 4, 1, 2, -9, 0, -16, -21, 2, -4, 16, -7, 4 },
- { -15, 20, 8, 17, 5, -14, 15, -11, 21, -11, 13, -13, 2, -15, -13, 1,
- -5, 5, 2, 10, -9, 4, -1, 3, 2, -4, 13, -5, 1, -4, 5, -3 },
- { -21, 8, 2, 16, -1, 2, 15, -16, 13, -12, -12, -7, -8, 2, -7, 11,
- -8, 5, 2, -7, 16, -4, 1, -7, 3, -15, 6, -5, -8, 2, -8, 5 },
- { -15, 17, -6, 3, -3, 3, 9, -7, 14, -23, 11, 1, -1, 4, 7, 6,
- -1, -14, 7, 6, -8, 5, 1, -15, 10, -9, 2, -3, -1, 4, -10, -4 },
- { -10, 18, 3, 11, 1, 4, 14, -14, 7, -4, 15, -10, 10, -11, 10, -4,
- 5, -14, 10, 4, 15, -12, 15, -13, 20, -15, 14, -15, 8, -11, 4, -6 },
- { -7, 23, 2, 20, 7, 8, 19, -5, 9, -16, -8, -17, -5, 1, 5, -6,
- -8, 1, -6, -4, 10, 6, 6, 2, -11, -4, 0, 2, 4, 7, 9, -4 },
- { -15, 20, -5, 22, 11, -8, 9, -5, 10, -13, -8, 8, 2, -2, -3, 7,
- 6, 10, 1, 2, -5, -9, 1, 10, 16, -22, -7, 0, 7, 7, 6, 1 },
- { -26, 19, -5, 3, 5, 25, 18, -5, 9, -14, -8, -6, -2, -6, 2, 3,
- -8, -2, -7, 7, -3, 7, 3, 4, -8, 0, 1, -8, -4, -2, -2, 1 },
- { -20, 14, -10, 6, -3, 7, 8, -32, -2, -7, -2, -10, 16, -12, -9, 15,
- -2, -5, -6, 2, -7, 5, 9, 1, 6, -7, -1, 0, -2, -4, -7, 3 },
- { -14, 16, 4, 11, -8, 1, 23, -4, 17, -13, -10, 1, 12, 9, 12, -4,
- 7, -1, -1, 5, -8, -6, 3, 3, -6, -3, -18, 0, 18, 20, 4, -2 },
- { -33, 19, -10, 30, 15, 2, -3, -1, -4, -14, 7, -7, -1, 7, -8, 9,
- -1, -3, -5, 2, 2, 4, 0, 5, 0, 0, 2, 3, 3, -3, -3, 4 },
- { -6, 20, 0, 5, 17, -10, 18, -17, 9, -16, 4, -13, -6, 2, -14, 14,
- -28, 9, -12, 25, -4, 7, 7, -8, 6, -6, -2, -10, 2, -11, -1, 2 },
- { -12, 14, 12, 52, -3, 5, -5, 4, 8, -13, 2, -5, -4, 2, -2, -1,
- -2, 3, 3, 5, 2, 3, 0, 1, -5, 2, -4, -3, 1, -5, -2, 0 },
- { -13, 6, 9, 24, 0, 8, 14, -15, 18, -9, -11, -8, 3, 15, -2, -4,
- -9, 4, -3, 12, 14, -13, 11, -4, 2, -4, 0, -6, -6, -6, -14, -1 },
- { -10, 28, 3, 12, 9, 3, 11, -28, 6, -11, -7, 4, 0, 7, 8, -9,
- 0, -6, 0, -16, 4, 7, 4, 4, 7, 3, 4, -7, 0, -3, -10, 6 },
- { -11, 14, -2, 19, -1, -1, 7, 9, -2, -27, 10, -14, 15, -4, 12, -4,
- 2, -2, -6, 12, -6, 0, -5, -4, -5, 1, 3, -11, 5, -9, 3, -8 },
- { -18, 7, 13, 16, -4, 3, 9, -10, 10, -10, -3, -22, -4, -12, 3, -16,
- 0, -3, -16, 8, -11, 1, 10, -7, 15, 3, 0, -1, -13, 8, 1, 6 },
- { -20, 10, -10, 10, 8, -1, 6, 0, 16, -12, 9, -10, -1, -5, -4, -13,
- 13, 16, -8, 12, -2, 14, 18, 13, 0, -16, 2, -5, -5, -5, -4, 3 },
- { -14, 5, -7, -17, 5, -13, 23, 20, -4, -1, 1, -6, 13, 5, -1, 4,
- -14, -2, -7, 8, 3, 2, 2, -7, 2, -1, 4, 7, 3, -9, -1, -5 },
- { -19, 3, -24, -28, -9, -7, 19, 3, 2, 19, 7, 5, -13, 8, -15, -17,
- 3, -11, 4, 13, 3, 2, -1, -3, -4, -4, 2, 0, -5, -6, 6, 2 },
- { -17, 18, -30, -20, -2, -3, 1, 15, -1, -11, 6, -4, 11, 11, -4, -5,
- -10, 0, 0, 1, 3, -7, 8, 2, 5, 1, 5, -5, 1, 6, 4, 1 },
- { -6, 1, -30, -25, -1, -8, -2, -9, -17, 16, 3, -1, -2, -9, -6, -7,
- -3, 12, 6, -4, -10, 0, 10, -8, -6, -5, -3, -11, -4, 0, -1, -3 },
- { -1, -1, -34, -28, 1, -10, 2, 9, 4, 16, 2, 6, 14, 17, 0, 7,
- -4, 4, 4, 4, 0, 1, -1, -5, 8, 1, -4, 1, -9, -2, 5, 6 },
- { -11, 14, 1, -31, -7, -24, 9, 7, 6, 5, -13, 1, -1, 3, 4, -1,
- -2, -8, -6, 3, 5, -4, -6, 7, -2, 5, 3, 3, 0, 0, -5, 2 },
- { -25, 8, -11, -18, 1, -4, 8, -3, -4, 15, 6, -5, 8, 2, 3, 4,
- -4, 5, 6, 8, -7, 6, 1, -11, -15, -13, 9, -4, -14, 10, 12, 7 },
- { -20, 11, -15, -25, 3, 4, 18, 13, -4, -5, -9, -1, -5, -2, -2, -7,
- 16, 5, -4, -5, -7, -2, -3, -9, 11, -2, 0, -7, -17, -6, -11, 6 },
- { -11, 18, -5, -20, -15, -3, 9, 11, -20, 12, 5, 5, 11, -3, 7, 1,
- 10, -6, -3, -3, 3, 3, 14, -7, 10, -17, 9, -11, -2, -6, 7, -12 },
- { -20, 8, -14, -17, -9, -13, -3, 0, -27, -14, -3, -14, 4, 3, 6, -6,
- 7, 4, 23, 9, 11, 9, 3, -4, 9, 2, 4, -1, -6, 1, -8, -11 },
- { -9, 14, 2, -37, -7, 13, 6, -11, -6, 9, 18, -11, -6, 2, 12, 4,
- -1, 3, 1, -2, -2, 1, -9, -4, -2, -3, 3, 5, -6, 0, -2, -8 },
- { -29, 8, -1, -13, -2, 8, 23, 2, -10, 7, 13, -6, -5, 11, 13, 0,
- -10, -13, 11, -12, -10, 6, 4, 6, 4, 3, 6, -5, -9, -2, -1, 3 },
- { -18, 6, -10, -55, -4, -11, -2, 0, 1, -3, -9, -6, 3, -2, -1, 6,
- 3, -1, 3, 1, -4, -7, -2, 6, 3, -2, -1, -3, -2, 0, 4, 1 },
- { -14, 5, 3, -21, -8, -16, -4, -2, -11, 27, 15, -20, 3, 0, 1, 1,
- 2, -5, -5, 4, 1, -9, 5, -3, 3, 0, -4, -2, -11, -4, -3, 7 },
- { -17, -1, -9, -17, -8, -18, 12, -13, -9, 13, -3, 3, 3, -3, 1, -2,
- 0, 16, -9, 6, 12, 9, 5, 11, 2, -15, 1, -4, -16, 7, -4, -12 },
- { -18, 8, -6, -11, -8, -7, 13, 7, 1, 6, 8, -1, 21, -4, 14, 15,
- 18, -4, -3, 15, 0, 9, 4, 7, 3, -1, 9, -2, 0, 7, -8, 2 },
- { -10, 7, -18, -29, 3, 12, 12, 9, 11, 4, -1, -15, 1, -1, 8, -2,
- -2, 10, -15, -1, 0, 6, 12, -6, -1, 10, -6, -3, -11, -4, 9, -6 },
- { -14, 14, -9, -21, -12, -2, -1, -7, -5, -10, 5, -8, 0, 6, 9, -11,
- 11, -3, -5, 3, 8, 15, -2, -4, -22, 4, -6, 12, 2, 13, 6, -7 },
- { -12, 11, -5, -29, -25, 4, 12, -13, -11, -7, 4, 2, 2, -5, 5, 8,
- 7, -5, -5, 6, 3, -10, 1, -6, 6, -6, -5, -1, -2, -4, 7, 6 },
- { -15, 11, -5, -16, 0, -13, 26, -23, -6, -3, 5, -2, -2, 21, -6, -3,
- -5, -1, 6, -1, 0, -13, 2, -3, -9, -1, -4, -3, 5, -4, 12, -16 },
- { -9, 9, -1, -17, -3, -6, 12, 6, -18, -2, 11, -14, -6, 3, 14, -12,
- -11, -5, 14, 2, 5, -8, -4, -11, 2, -5, 16, 6, -7, -4, 8, 13 },
- { -13, 5, 3, -28, -14, 0, 6, 23, 5, 4, -1, -17, 1, -3, 0, 0,
- 5, 4, 0, -18, 14, 10, 4, 2, 5, -2, 4, -3, 2, 0, 2, 0 },
- { -15, 4, -13, -16, -3, -12, -2, 2, 7, 10, 9, 3, 11, 4, 23, 14,
- 9, 16, 4, 1, -12, -3, 4, -7, -15, -7, -10, -14, -6, -8, -1, -6 },
- { -7, 10, -5, -10, -3, -13, 16, -1, -12, 7, -3, -12, 2, 13, 13, 2,
- 17, 15, -13, 1, -5, -2, 3, -1, 1, -3, 6, -3, -12, -16, 7, -7 },
- { -11, -5, -12, -30, -6, -22, 1, 4, -6, -3, 12, 6, 7, 0, 16, 6,
- -2, 0, -22, -2, -9, 2, -13, 8, 6, -8, 4, -7, -1, -6, 4, 6 },
- { -14, 5, 1, -27, -4, 2, 1, 14, -11, -7, -8, -4, 1, 8, 0, -6,
- -13, 11, -12, -7, -5, 1, 10, 7, 3, -2, 0, 6, -8, 2, 10, -1 },
- { -10, 10, -25, -13, -20, -4, 19, 3, 13, 5, 5, 7, -8, 2, 4, 2,
- 3, -1, -1, -9, 14, 10, 9, 14, 3, 3, -6, 0, -5, 4, 1, -1 },
- { -9, 15, -18, -17, 4, -11, 6, 7, -12, 8, -1, -11, 2, 3, 7, 16,
- -3, -9, 7, -12, 23, 0, 6, 7, -14, -9, 8, 1, -2, 6, -2, -1 },
- { -6, 9, -16, -26, -14, -11, 9, -6, 5, -2, 13, 17, 21, 7, 18, -19,
- 6, -23, -2, -15, -2, 2, -10, -8, 2, 1, -2, 4, -3, -4, -5, -4 },
- { 0, 6, -5, -28, -17, -32, 2, -10, 11, 3, -5, 9, 10, 3, 11, 11,
- -3, 12, -2, 2, 4, -6, 9, -4, -4, -4, -4, -9, 2, 0, 2, 4 },
- { 0, -8, -18, -34, -9, -7, -4, -11, 10, 15, 11, -1, -8, 15, 6, -13,
- 9, 2, -4, -12, 0, -1, 19, 12, 6, 5, 0, -3, -10, -12, 3, -5 },
- { -10, 6, -9, -17, -12, -11, 9, -6, 11, 11, 18, -7, 0, 16, 4, 2,
- -6, 3, -12, -1, 0, 1, -5, -22, -2, -12, 0, 6, 17, 5, 5, 6 },
- { 12, -5, 7, 1, -5, -2, -1, 2, 2, -4, -3, -3, -3, -2, -29, 11,
- 5, -13, -73, 24, 12, 4, -14, -10, 5, 1, 0, -11, -7, -7, 7, 3 },
- { 10, -3, -1, -3, 4, -11, -5, -2, -8, 7, 9, 2, -8, -6, 6, 7,
- 21, 17, -54, 47, -14, -10, 14, 19, 13, 21, -4, 3, 1, 2, -4, 2 },
- { -12, 4, -16, -12, 5, -9, -4, 19, -7, -22, -22, -17, 3, 0, -6, 8,
- 23, -4, -55, -28, 2, -26, 2, 1, 4, 0, -13, 6, 0, 10, -7, -11 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -1,
- 35, -1, -67, -35, -24, -24, -6, 2, 2, -2, 1, 3, 2, 0, -1, 1 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 5, 0,
- 41, -4, -73, -15, 18, 4, 17, 8, -1, -16, -1, -2, 1, 0, 0, 0 },
- { -4, -4, 4, 6, -1, 2, -16, -10, -15, -10, 21, -2, -6, -2, 14, -7,
- 10, -5, -55, 34, -12, 11, -13, -2, 2, 28, -26, 0, 7, 4, 21, -7 },
- { 2, 1, 15, -22, 10, -3, 14, -6, -2, 15, -2, -7, 20, 6, -15, -7,
- 23, 10, -60, 8, -4, 29, -22, 2, -13, 9, -10, 12, -1, -3, 4, 7 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -1, -2, 11, -5,
- -21, -11, -60, -27, -17, -39, 6, 36, 0, -8, 2, 2, 0, 0, -2, 3 },
- { 2, -5, 9, -17, -1, 2, -3, -6, 8, 12, 7, -6, -33, -11, -14, -40,
- 10, 36, -46, 0, -19, 5, 0, -10, 3, 12, -6, -8, 6, -12, -7, 1 },
- { 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, -1, 0, 1, 0, -2, 0,
- 4, -2, -87, -3, -2, 2, -2, 20, 2, 6, -1, 6, 0, 0, 2, -1 },
- { 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, -1, 0, 0, 1,
- 1, 7, -76, 41, -7, -24, 0, -6, 3, 6, 0, -2, -1, 1, 0, 0 },
- { 0, -3, 4, 2, 3, 2, 2, 0, 3, -1, 4, 0, -1, 4, -2, -4,
- -32, -11, -64, -29, -9, -43, 2, -11, -1, -7, 0, -4, -2, -2, -2, 2 },
- { 10, -20, 3, -3, 13, 13, 0, -4, 2, 7, -8, 7, -2, 2, -20, -20,
- -19, 3, -47, -18, -16, -6, -15, -42, -17, 14, -6, 8, 12, -10, 11, -12 },
- { -3, -2, -2, -1, -1, 4, -3, -1, -6, -2, 3, 2, -3, 6, -1, -9,
- 10, 13, -68, -9, 26, 3, 5, 3, -21, 10, -15, 21, -22, 19, 11, -14 },
- { 1, 5, 18, -19, -29, -13, -2, 18, -10, 20, 2, 10, -10, 11, 1, 8,
- -16, -17, -41, 10, -14, -25, 0, -14, -19, 17, 7, -12, 14, -11, 14, 5 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -1, -43, 5,
- 6, -12, -48, 19, 8, -38, -8, -3, 22, -21, -10, 15, 20, -9, -5, 8 },
- { 0, 0, 0, 0, -1, 1, -1, 0, 0, 0, 0, 0, 0, 0, 6, -3,
- 22, -14, -71, -24, -2, -33, 23, 7, -8, 7, -3, 2, -4, 1, -8, -2 },
- { 1, 0, -1, 2, 0, -2, 0, 0, -1, 0, 4, 0, 26, -1, 10, -11,
- -17, -32, -58, 14, -14, -11, -2, 15, 2, -8, 12, 10, -9, 13, -33, -14 },
- { 15, -17, -19, 7, -8, -15, -32, -22, 7, 12, 18, 0, 0, -15, -4, 16,
- 37, -2, -46, 11, 2, -8, -10, -8, 14, 9, -4, 5, 7, -17, 4, 3 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, 0,
- -5, 3, -85, 23, -9, -17, -2, -2, 0, 0, 0, 0, 0, 0, 0, 0 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, 0,
- -5, 3, -85, 23, -9, -17, -2, -2, 0, 0, 0, 0, 0, 0, 0, 0 },
- { 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, -1, 0, 0, 1,
- 1, 7, -76, 41, -7, -24, 0, -6, 3, 6, 0, -2, -1, 1, 0, 0 },
- { 0, -3, 4, 2, 3, 2, 2, 0, 3, -1, 4, 0, -1, 4, -2, -4,
- -32, -11, -64, -29, -9, -43, 2, -11, -1, -7, 0, -4, -2, -2, -2, 2 },
- { 10, -20, 3, -3, 13, 13, 0, -4, 2, 7, -8, 7, -2, 2, -20, -20,
- -19, 3, -47, -18, -16, -6, -15, -42, -17, 14, -6, 8, 12, -10, 11, -12 },
- { -3, -2, -2, -1, -1, 4, -3, -1, -6, -2, 3, 2, -3, 6, -1, -9,
- 10, 13, -68, -9, 26, 3, 5, 3, -21, 10, -15, 21, -22, 19, 11, -14 },
- { 1, 5, 18, -19, -29, -13, -2, 18, -10, 20, 2, 10, -10, 11, 1, 8,
- -16, -17, -41, 10, -14, -25, 0, -14, -19, 17, 7, -12, 14, -11, 14, 5 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -1, -43, 5,
- 6, -12, -48, 19, 8, -38, -8, -3, 22, -21, -10, 15, 20, -9, -5, 8 },
- { 0, 0, 0, 0, -1, 1, -1, 0, 0, 0, 0, 0, 0, 0, 6, -3,
- 22, -14, -71, -24, -2, -33, 23, 7, -8, 7, -3, 2, -4, 1, -8, -2 },
- { 1, 0, -1, 2, 0, -2, 0, 0, -1, 0, 4, 0, 26, -1, 10, -11,
- -17, -32, -58, 14, -14, -11, -2, 15, 2, -8, 12, 10, -9, 13, -33, -14 },
- { 15, -17, -19, 7, -8, -15, -32, -22, 7, 12, 18, 0, 0, -15, -4, 16,
- 37, -2, -46, 11, 2, -8, -10, -8, 14, 9, -4, 5, 7, -17, 4, 3 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, 0,
- -5, 3, -85, 23, -9, -17, -2, -2, 0, 0, 0, 0, 0, 0, 0, 0 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, 0,
- -5, 3, -85, 23, -9, -17, -2, -2, 0, 0, 0, 0, 0, 0, 0, 0 },
- { 16, 65, -2, -2, 4, 3, 0, -7, 3, 1, 3, 1, 0, 5, 1, -5,
- 0, 2, -1, 3, 0, 0, -1, -2, 6, 0, -2, 0, 0, -1, 1, 1 },
- { 5, 37, -4, 8, -4, -1, 9, 17, 6, -7, 5, -1, 11, 6, -4, 7,
- -2, 4, 1, -3, 11, 3, 3, -9, 6, 0, -2, -4, -5, 4, -12, -11 },
- { 15, 24, -14, 2, 6, 17, 26, 5, 8, 11, -9, -7, -6, -8, 3, -5,
- 9, 10, -3, 10, 0, 1, 4, -9, 4, 9, 3, 0, 4, 0, -5, 3 },
- { 9, 36, -9, -8, 7, 7, 4, 3, -1, -16, -2, 7, -5, -6, 6, 12,
- -11, -12, 9, -1, -3, -9, 12, 6, -6, 2, 2, 5, 0, 5, 6, -6 },
- { 25, 39, -5, 24, 3, 10, 3, -6, 13, -8, 3, -7, 2, -10, -5, 2,
- -2, 3, 5, -2, 1, 5, -2, 3, -4, 1, -5, -4, 0, 1, -2, 0 },
- { 16, 27, -1, 0, -14, 6, 4, -5, 7, -2, -6, 0, -3, -5, 2, -1,
- -1, -19, 5, -8, 0, 11, 12, 5, 0, 3, 10, 6, -14, 14, -13, -15 },
- { 12, 23, -14, 2, 1, 4, -3, 16, 7, -8, 2, -8, 8, 6, -8, -7,
- -3, 0, 2, 8, -13, 7, 13, -6, -4, 6, -13, -16, 14, 11, -7, 5 },
- { 16, 28, -7, -1, 6, -3, 9, 0, -7, 3, 0, 3, -12, 20, 8, 9,
- 8, 23, 8, -13, -2, 4, 9, 3, -5, 13, 5, -2, 12, 14, 5, -1 },
- { 19, 37, 19, 5, 7, 5, 10, 5, 19, 10, 14, 0, 2, 5, 1, -4,
- -4, 2, 2, -5, -2, -1, 2, -6, -4, -4, -5, -3, 2, -2, -2, -2 },
- { 24, 21, 1, -11, -10, 17, -14, 14, 6, -1, -6, -1, 0, -13, -1, -12,
- -2, -5, 6, -4, -12, 14, 5, -2, -8, -8, 15, -7, -30, -12, 4, 0 },
- { 11, 26, -3, 3, 5, -1, -2, 3, -2, 10, 15, -4, 10, -28, 10, -17,
- -8, 1, 2, -7, -1, -6, -15, -1, 4, 5, -7, 9, 0, -5, -4, 4 },
- { 18, 32, 1, 2, -7, 4, 15, 2, -9, -2, 12, -11, 7, 11, 13, 2,
- 0, 5, 9, -10, 16, 3, -3, 5, -9, -23, 2, -2, -1, 5, 2, 11 },
- { 35, 24, -20, 2, 4, -1, 5, 14, -10, -9, 8, -7, 0, 5, -7, -7,
- 11, 1, 5, 3, 2, 0, -2, 3, 0, 1, 4, 0, -2, -8, 0, -4 },
- { 9, 35, -1, 2, -1, -19, -3, 12, -1, 8, 8, -13, -1, -2, 2, 5,
- -8, -1, 13, -2, 11, 1, 0, -10, 0, -3, -7, 2, 1, -12, 3, 12 },
- { 20, 27, -12, -12, 7, 4, -1, -13, -1, -9, 2, 13, -11, 5, 7, -9,
- 9, 1, 1, 8, -9, 0, -6, 7, 4, 2, -2, 7, 3, -2, 1, -9 },
- { 8, 37, -20, -5, 0, -21, 10, -8, 3, 19, -9, 7, -3, -8, 10, -2,
- 0, 5, 6, -4, -2, -1, 0, -7, 6, 1, 0, 4, -5, 6, -8, 2 },
- { 8, 27, 1, -3, -5, 1, 6, 0, 15, 2, 17, -1, 3, -17, 10, 5,
- 5, -6, -6, 6, -10, 18, -5, 0, 0, 13, 7, 10, -5, -6, -2, -4 },
- { 14, 29, -20, -4, -3, 1, -5, -1, 2, 12, -10, -3, 4, -18, 4, 14,
- -4, -1, -9, 15, -2, 2, -5, -3, 2, 9, -2, -14, -3, 4, -4, -7 },
- { 23, 23, -23, -11, 27, 4, 4, -1, 7, 0, -5, 9, 2, -11, 3, 7,
- -2, -5, 2, -7, -7, 13, -3, -6, 2, 3, 3, -4, -1, -8, 5, -2 },
- { 16, 26, -6, 8, -9, -1, -2, -1, -8, 4, -2, 0, -12, 9, -1, 0,
- -17, -9, 30, -5, -15, -16, -13, 0, 10, -11, -7, -3, -1, 0, -11, -2 },
- { 12, 32, -4, -5, 10, 19, -10, 4, -12, 5, -6, 9, -12, -6, -6, -8,
- 4, 1, 3, 0, 8, 0, -3, -4, -7, -4, 10, 8, 6, 5, -1, 4 },
- { 46, 42, -3, -14, -2, -6, 6, -2, -5, -1, -3, -3, 1, -1, 3, 1,
- 1, 4, -1, 2, 3, 1, -2, 6, 0, -1, -2, 4, -2, -1, 2, 2 },
- { 9, 33, -13, 4, -11, 3, -8, 22, 12, -2, 4, 0, -16, 5, 4, -1,
- 7, -6, -9, 1, 7, 5, 0, -5, 5, -1, 10, 3, -2, -1, 3, -2 },
- { 9, 30, 6, -3, 6, 1, -7, 5, 11, 14, 7, 1, 0, 2, 2, -1,
- 8, 7, -6, -13, -10, -2, 1, -6, 10, 7, 6, 5, -2, -5, -1, -16 },
- { 9, 28, -11, -10, 9, -10, 15, 8, 4, 9, -4, -7, 0, -5, 9, 8,
- -7, 2, -15, -23, 4, -4, 4, 16, -8, -3, 0, -8, 14, 5, -3, 15 },
- { 17, 26, -5, -5, -1, -8, 20, 18, -7, -2, 4, -7, -8, -5, -4, 16,
- 0, 0, -7, -2, -13, -5, -2, 3, 12, 1, 3, -5, 2, 2, 0, -1 },
- { 11, 37, 7, -23, 6, -1, 15, 13, 4, -9, 7, 5, 3, -3, -5, -8,
- -2, 3, -5, -1, -8, 7, 2, 13, 1, 3, 0, -3, -1, 2, 0, -2 },
- { 21, 33, 7, 20, 21, -10, 6, -5, -5, -6, -9, 2, 10, 0, 8, -4,
- 10, 2, -2, -2, 0, -10, -6, -2, 0, -5, 3, -11, 3, -9, -3, 1 },
- { 6, 30, -15, -8, 16, 1, 4, 6, 4, 5, 8, -3, 8, -9, -1, -6,
- 8, 2, -2, 4, -2, 5, 11, -21, 3, -10, 16, -11, 24, 10, 14, -6 },
- { 15, 36, -3, -9, -20, 12, 0, -7, -18, -4, -8, -9, 9, -7, -3, -1,
- 2, 7, -5, -8, 6, 2, 2, -1, 7, 1, 1, -3, 3, -4, -8, 1 },
- { 16, 34, 21, 3, -9, 10, 7, 9, -7, 1, -4, -9, -4, -5, -5, 3,
- 3, -19, 1, 5, 4, -2, -6, -5, -10, -11, -8, -2, 2, -5, -8, -7 },
- { 28, 29, -3, 18, -2, 0, -6, 12, -2, 10, -11, -4, -13, -12, -6, -4,
- 0, 4, -1, -8, 6, 4, 12, 11, 10, 10, -3, -6, 1, 2, 1, 7 },
- { 3, 8, 22, -8, 3, 36, -8, -1, 9, 6, -13, -14, 8, -1, 1, 2,
- -2, -8, 0, 3, 1, 2, -1, 5, -1, -8, 0, -2, 2, 2, -1, 1 },
- { 0, 6, 0, 0, 4, 13, -7, -16, -6, 15, -14, -21, -9, -10, -10, -6,
- -21, 5, 4, 2, 12, 4, 12, 11, -4, -6, -6, -10, -7, -18, 1, 4 },
- { -1, 3, 10, 1, -1, 15, 4, -7, -16, 3, 0, -22, 10, 2, -3, -2,
- 13, 5, -8, 16, -5, 4, 0, -11, -10, -22, 0, -4, -17, 5, 2, 1 },
- { 12, 8, -4, -9, 14, 40, -21, 0, 1, -15, -10, -12, 12, 6, -10, 2,
- 8, 6, -12, -10, -11, 1, 0, -11, 2, 1, 13, 0, 6, 3, 8, 4 },
- { -10, 3, 5, -4, -3, 3, 0, -9, 2, 8, -22, -23, 17, 8, -17, -3,
- 14, -8, -4, 1, -8, 3, 0, 5, -1, -3, -2, -4, 1, -10, 0, -2 },
- { 0, -1, 5, -7, 4, 12, -2, 0, -7, 2, -16, -15, 12, 21, -7, -4,
- 7, -7, -11, -15, -7, -9, -5, -8, 0, -6, 8, -3, -8, 22, -7, -9 },
- { 7, 19, 4, -9, 24, 22, 2, -6, 8, 13, -14, -20, -4, 11, 8, -4,
- -1, 2, 0, -7, 5, -17, -3, 3, -6, 5, 3, 4, -5, -7, -3, 14 },
- { -2, 6, 2, 8, -2, 5, -4, -2, -10, 3, -45, -30, -3, -3, -12, -4,
- -3, -3, -1, 9, -6, -6, 5, -4, 0, 5, -1, -2, -1, 0, -6, -1 },
- { -3, 14, -16, -10, 10, 0, -2, -40, -9, 12, 2, -19, 15, -4, 4, 3,
- 3, -4, 7, 1, -4, -5, 0, 4, -1, 0, -9, -2, -4, -1, -2, 0 },
- { 7, 16, 2, -7, 8, 2, 0, 1, 5, 21, -10, -26, 7, 2, -9, -7,
- -3, -16, 8, 5, 5, -6, 10, 4, -14, -6, 5, 3, -2, -2, -4, 1 },
- { -9, 14, -1, 3, 3, 11, 1, -5, -3, 13, -16, -18, 20, 6, -5, 0,
- -3, 2, 8, 4, -19, -9, 12, 0, -8, 2, 2, 1, 6, 13, -7, -11 },
- { 2, 5, 16, -4, 19, 15, 4, 0, -11, 7, -10, -10, -16, 18, -11, -12,
- -9, -4, 7, -4, -4, -17, 1, 1, -8, -3, -3, 5, -2, -6, -11, -5 },
- { 2, 12, 0, -9, -10, 14, 6, 2, -3, 2, -12, -28, 12, 1, -1, 2,
- 0, -3, -4, 7, 16, 5, -7, 8, -4, -3, -1, 3, -12, 4, -17, -5 },
- { -4, 7, 11, 6, 1, 14, -4, -6, 5, 5, -6, -24, 23, -9, -15, 13,
- -7, -9, -15, 10, -1, 8, -5, 1, 12, 6, 2, 0, 4, -2, 9, -10 },
- { 1, 5, 11, 3, 6, 12, -3, 8, -21, 5, -7, -20, 12, -2, -9, -3,
- 17, -7, -8, -9, -14, 3, -13, 18, -8, 9, 2, -8, 4, -8, -5, -2 },
- { -3, -3, -1, 5, -2, 15, 3, 2, 1, -8, 1, -39, -6, 13, -13, 0,
- -2, -5, -6, -3, 0, -5, -2, 15, -9, 5, -3, -6, -2, 7, 0, -13 },
- { 2, 8, 5, -12, -13, 22, 8, -16, 11, 5, -2, -32, -2, -4, 11, 5,
- 5, -6, 1, 3, 1, 5, 3, 6, -5, 4, 4, -8, 8, 4, 1, 3 },
- { 13, 9, 5, -4, 9, 18, -11, 2, -1, 15, -10, -19, -2, 14, 0, -10,
- 1, 1, -18, 3, 2, -6, -8, 20, 7, -8, 16, 9, 9, -13, -3, -2 },
- { -13, 11, 11, -9, -10, 13, -3, -18, 2, 10, 5, -21, 6, 15, -11, -21,
- 3, 14, 0, -12, 9, -1, -2, -4, 3, -3, -9, -8, -5, -2, -8, 2 },
- { 3, 3, 11, 4, 0, 13, 1, -8, 10, 13, -6, -26, 2, 12, -3, -5,
- 12, -2, 1, 8, -7, -17, -19, 5, 10, 7, -3, 2, -3, 0, 5, 0 },
- { 5, 0, 3, -3, -9, 5, -15, -5, -5, 17, -5, -31, 0, 13, 13, 5,
- -1, -6, -14, 7, -8, 9, -14, -2, -16, -4, -4, -6, 6, -6, -10, 6 },
- { 13, 3, 1, 7, -3, 4, -1, -2, -1, 4, -8, -32, -1, -4, 0, 3,
- -10, 7, 10, -10, 4, -1, 6, 2, -16, -9, 4, 3, 13, -23, -3, -4 },
- { 4, 11, -4, -9, 4, 11, -12, -12, -12, 6, 1, -28, -3, 14, 18, -2,
- -12, 7, 15, -3, -5, -7, -3, 2, -6, 4, 4, -2, -5, -3, 2, -13 },
- { 8, 7, -7, 0, 13, 7, -8, -7, 8, 36, -10, -22, 3, 23, -3, -10,
- -3, 11, 1, -7, 3, 3, -1, -7, -4, 2, 3, 2, 5, 3, -4, -1 },
- { -1, 1, 13, 1, -6, -1, -6, -9, -18, 17, -5, -37, -1, -1, -6, -4,
- 1, -6, -15, 2, 17, -9, 0, -3, 0, 4, 0, -5, 0, 4, 1, -5 },
- { 0, 14, 5, 0, -7, 2, -6, 17, -6, -9, 7, -16, -5, 23, -14, -13,
- 8, -15, 11, 10, -11, -13, -33, -5, -2, 1, 6, 8, 0, -13, -9, 5 },
- { 11, 7, -2, -8, 9, 11, 25, -14, 7, 3, -1, -33, 14, 8, -6, -19,
- 3, 3, 2, -1, -3, -1, -2, -10, -3, 1, 2, 1, 4, 2, -3, 4 },
- { -2, 8, 4, -2, 9, 13, -4, -2, -15, -3, 19, -37, 9, 25, -9, 2,
- -5, -2, -2, -4, 4, 2, 2, 0, 3, 3, 3, 5, -2, -3, -4, -3 },
- { 10, 13, -1, -15, 4, 6, -18, -4, 25, 1, -23, -17, 15, 13, -8, -8,
- 7, 4, -5, 3, 6, 9, -7, 6, 0, -5, 8, 0, -6, -1, -2, -2 },
- { 1, 3, 9, -5, 27, 15, -9, -31, -1, 23, -2, -9, 1, 8, -1, -7,
- -2, -8, -4, -4, -2, -1, 3, 5, 0, 0, -1, 1, -7, 7, -3, -3 },
- { -8, 7, 3, -6, 8, 3, -11, -2, 36, 14, 1, -30, 6, 10, -12, -6,
- -6, -2, -4, -3, -5, 0, 9, 4, -5, -5, -8, 12, 4, -3, 1, -8 },
- { -2, 9, 33, 0, 12, -3, -7, -4, -4, -1, 6, -25, 11, -6, -9, -11,
- -2, -4, -2, 6, -1, -3, -6, 15, -6, 3, 10, -4, 1, 0, 5, 8 },
- { -22, -21, -9, -19, -5, -7, -12, -15, -8, 9, -19, 14, -7, -4, 5, -8,
- -2, 7, 1, -3, 4, -4, 6, 11, 2, 6, -3, -5, 2, -2, 0, -3 },
- { -32, -13, 3, -24, 3, -8, 4, 1, -10, 14, -15, 0, 4, 6, -1, 6,
- 7, -1, 6, 4, -3, -17, 1, 4, -6, -1, 1, 0, 3, 3, -7, -4 },
- { -32, -11, 7, -8, -12, 13, -5, -22, -4, 12, -16, 2, 0, 4, 0, 1,
- 0, 6, -5, -8, 2, 6, 5, 0, -3, -6, 5, 6, 5, 5, 13, -4 },
- { -44, -33, 6, -4, 2, 0, -9, 10, 3, 4, 7, 0, -1, 7, 5, 1,
- 1, -3, 1, 6, -1, 0, 2, 3, -4, 0, 0, 1, 0, -1, -2, -1 },
- { -30, -18, -24, -8, 5, 0, -2, 14, 7, 0, 1, 12, 6, 4, -9, 7,
- 5, 7, -11, -5, 1, -8, -1, 2, 2, -9, 7, -1, 7, 5, 6, 6 },
- { -22, -20, -13, -9, 20, -3, 10, -8, 6, -4, 2, -7, 10, 8, 0, -1,
- 2, -3, 6, -19, 2, 4, 3, 3, -7, 2, -1, -6, 1, 1, 6, -2 },
- { -27, -8, -1, 3, -1, -11, 24, 4, -1, 1, -8, 8, 5, -11, 15, -3,
- -15, -1, -1, -13, -1, 1, -5, 5, 2, 3, -9, 0, 4, 3, -7, 6 },
- { -33, -16, -1, -8, 10, -23, 6, 13, -1, -3, -9, 0, 5, -7, -5, -12,
- -2, 3, 3, 6, -2, -3, 2, -3, 9, -6, -3, -2, 0, 5, -3, -4 },
- { -22, -17, 11, -3, 3, 1, -1, -5, 17, 2, -15, -2, 10, -9, 6, 14,
- -16, -12, 20, -1, -7, 6, -3, -12, 1, 10, -10, -1, 7, -3, -1, 10 },
- { -28, -13, 1, -3, -1, -1, 0, 3, 3, 5, 1, 10, -10, -3, 7, 2,
- 4, 19, -1, -1, 10, 5, -8, 1, 11, -15, -4, -3, -5, 4, -13, 3 },
- { -22, -13, 42, -20, 5, -13, 7, -11, 1, 1, -1, 1, 6, 3, 6, -11,
- 3, 3, -2, 0, -4, 4, -3, -1, -5, 2, 0, 0, -9, -1, 4, 4 },
- { -26, -15, -2, -6, -4, -2, 16, 8, 21, 8, 1, -3, -10, 7, -8, -12,
- -5, 12, -9, 3, -2, -3, 18, 1, -12, -15, -4, 5, -3, 0, 12, 7 },
- { -26, -16, 5, 6, 14, -3, 15, 6, 1, -7, -13, 16, -15, 5, 11, -2,
- 9, -7, -4, -2, 0, 0, -2, 7, -8, -6, -5, 2, 7, -3, 2, 12 },
- { -31, -17, -8, -30, 4, 14, 6, -6, 6, -11, 0, 3, -4, 0, 0, -4,
- 0, -4, 1, 4, 3, 4, 0, -5, 3, 2, 2, 0, 2, 1, 3, 5 },
- { -61, -10, 4, 10, 4, 7, 0, -3, 0, 1, 0, -3, 0, 1, 0, -2,
- -1, 1, 2, -2, 4, -3, 1, 1, -1, 1, -2, -4, -4, 4, 0, 0 },
- { -28, -13, -8, -4, 3, -3, 2, 1, 11, 14, 3, 9, 1, 13, 3, 5,
- -3, -2, -2, -12, -14, -9, -11, -15, -12, -5, -4, -12, 3, -3, 0, -5 },
- { -41, 0, 12, -24, 13, 4, 5, 16, -5, -4, 0, 0, 13, -4, 1, -9,
- 9, -6, -1, 6, -2, 5, 2, 9, 6, -9, -8, 8, -2, -3, -6, -4 },
- { -26, -19, -2, -15, 4, -14, 6, 0, 26, 20, 8, 9, 9, 3, -4, -5,
- -8, 1, 0, -1, 5, 9, 3, 4, 4, 7, 1, 3, -2, -2, -10, 0 },
- { -29, -18, 9, -4, 1, -5, -14, -12, 5, -10, -5, 4, -5, 0, -1, -1,
- 4, -5, 7, -16, -11, 2, 7, -15, 2, -4, 6, -4, -6, 7, -3, 7 },
- { -27, -16, 9, -14, 3, -8, 9, 0, 7, -4, -3, -7, 0, -10, -1, 2,
- 1, -2, 15, -10, 14, 7, 6, 17, 3, -4, 3, -10, 8, -8, 3, 11 },
- { -21, -20, -8, -8, 4, 5, -3, -2, 0, -5, 14, -10, 11, -4, 13, 0,
- 5, -11, 19, -18, 18, 3, -5, -3, -4, -8, 11, -10, 10, 3, 4, -9 },
- { -35, -15, 13, -12, 4, 0, -2, -4, -12, -3, -8, -24, -7, 1, 7, 8,
- -3, 0, -2, -1, 3, -2, -2, -6, 8, 1, 0, 1, -6, -1, 2, -6 },
- { -19, -14, 13, -10, 9, -1, 1, 3, -12, 5, -16, 7, 13, 9, 4, -4,
- 6, -5, 4, 9, -3, 17, -4, 12, -11, -6, -5, -6, 13, 2, 7, -9 },
- { -34, -8, -4, 1, 2, -1, 3, 6, -20, -11, 8, -1, 4, 2, -9, 4,
- -4, -5, 16, 10, -4, 14, -13, 1, -6, 0, 2, -10, 0, -3, -3, 7 },
- { -36, -10, -8, -3, 2, -2, 14, -4, -1, -7, -4, 10, -1, -3, 15, -11,
- 0, 2, 3, -1, 4, 0, 8, -1, 0, 18, -11, -5, 15, -5, 13, -12 },
- { -22, -13, 14, -20, 15, 25, 16, 10, 8, -2, -10, -5, -1, -8, 11, 8,
- -1, -2, -4, 1, 2, -1, -7, 0, 0, 0, -3, 0, 2, -1, 0, 2 },
- { -31, -22, 7, 6, -2, 5, -20, 14, -6, 7, 0, 14, 3, -7, 3, -6,
- -2, 1, -3, -5, 1, -10, 1, -24, 6, -2, 3, -7, 1, -7, 8, 7 },
- { -25, -20, -3, -9, 10, 6, 12, 7, 5, 4, -3, 6, -1, -5, -6, -8,
- 3, 5, 6, 5, -10, 10, -4, -15, -15, -2, -9, 2, 18, 1, 8, 12 },
- { -24, -19, -2, -4, -7, 11, 6, 9, 16, 2, -7, 18, 6, -7, 6, 6,
- -2, -9, 3, 12, -2, 3, -1, 6, 7, 8, 0, 8, -11, 8, 4, 2 },
- { -26, -20, -12, -12, -2, -3, 1, -5, -1, -2, 0, 3, 7, 9, -2, 2,
- 9, 22, 13, 4, -4, -1, -2, -14, 5, 15, -8, -5, -7, -11, -14, -6 },
- { -21, -18, -1, -4, 0, 3, 7, -2, 10, 8, -8, -1, 15, 1, -9, 3,
- 1, 3, -5, -2, 2, 4, 0, -1, 10, 2, -19, -8, 8, 30, -7, 8 },
- { -25, -6, 26, 4, -8, 4, -2, 21, 5, -4, -16, 5, 13, 4, -10, -1,
- -6, -2, 2, -10, -13, 1, 3, -3, -6, -8, 2, 11, 1, -7, 0, 5 },
- { 0, -1, -2, 19, -12, -48, -6, 11, 8, -2, -4, -2, -7, 5, -3, 2,
- -2, -1, -1, -7, 0, -3, -3, -4, -4, 4, 1, 3, -3, -1, -2, -5 },
- { -11, -8, -28, 18, 16, -24, -8, 19, 4, 8, -12, 9, -4, -2, 4, -7,
- 6, 2, 3, 3, -4, 0, 1, -6, -4, -2, 2, 6, 0, -3, 1, -16 },
- { -9, -5, -26, 7, -3, -37, -16, -2, 2, -7, 4, -13, 0, -4, -6, -5,
- -6, -4, 0, 3, 4, -3, -4, -4, 4, -3, 9, -4, -2, 2, 7, -4 },
- { 2, 9, -18, 7, 29, -24, -1, 7, 14, 10, 3, -3, -2, -5, 6, -10,
- -6, -3, -8, 0, 5, 1, 4, 3, -12, 2, 6, 1, 3, 4, 1, -3 },
- { -20, 2, 8, 20, -9, -24, -4, 18, 3, 11, -1, -11, 6, 9, -1, -3,
- 1, -1, -15, 3, 15, 9, 3, 2, -13, 2, -8, 8, 1, -1, 1, -8 },
- { -12, 5, -11, 6, 19, -26, -17, -6, 4, 14, 6, -8, 9, 5, -6, -5,
- 2, -1, 20, 1, -11, -10, -18, 20, -7, 0, -3, 4, 2, 0, 10, 4 },
- { -15, 1, -2, 13, -8, -21, -22, 4, 4, 3, 3, -7, -31, 4, -10, -14,
- 0, 8, 4, 5, 8, 11, 2, -8, 6, 7, 0, -2, 6, 8, 8, 7 },
- { -13, -10, -9, 12, 19, -16, -3, -2, 9, 2, 11, -29, -1, 9, 4, -3,
- 1, -10, -10, 16, 1, 7, -7, -6, -4, -1, -5, 3, 6, 0, 3, 1 },
- { -17, -1, -5, 19, 12, -9, -21, -5, 2, 12, -7, -7, -3, 8, 7, -2,
- 6, -9, -9, 1, -4, 1, 1, 3, -14, 2, -8, 0, 10, 1, -12, -6 },
- { -13, -5, 8, 15, 0, -20, -2, 20, 8, -8, 8, -19, 12, 10, 2, -11,
- 0, 12, 1, -11, 0, -11, -15, 5, -11, 2, 4, -4, -11, 5, -4, -5 },
- { 3, -11, -7, 8, 0, -17, -26, 15, 19, -7, 10, -9, -5, -5, 14, -25,
- 0, -8, 2, -9, -3, 9, 1, -6, 4, -4, 3, -9, -1, 6, 2, 2 },
- { -12, 5, 5, 9, 14, -18, -19, 4, 2, 16, 14, -21, -15, -9, -1, 16,
- 12, -11, -10, -5, -7, 4, 15, -8, -5, -1, 1, 14, 13, -7, -1, -4 },
- { -10, -5, -1, 8, 7, -23, -10, 14, 6, 11, 10, -16, -3, 16, 6, 0,
- 0, 9, 6, -2, -7, 1, 22, 5, 3, -8, 0, 3, -2, -10, 3, 0 },
- { -2, -14, 2, 16, 15, -17, -17, 6, 19, 4, -10, -15, -1, 15, 11, -14,
- -8, 5, 8, 8, -2, -8, -11, 10, 10, -8, -14, 2, 13, 4, -2, -12 },
- { -10, 3, 6, 4, 19, -23, -19, 1, 4, -9, -30, 3, -6, 18, 0, 2,
- 0, -11, 0, 3, 7, -2, 8, 5, 2, -3, 6, -9, 1, -4, 7, -6 },
- { 9, 5, -2, 21, 20, -33, -13, 7, -10, 8, 8, -15, -6, -4, 1, 5,
- 3, 7, -2, -9, -1, 4, -6, 1, 0, 9, -1, -5, 2, 1, -3, 3 },
- { -9, -3, 3, 15, -3, -30, -7, -7, -25, 6, 2, -6, 1, 19, 1, -12,
- 1, -8, -13, 9, 13, 1, 8, 2, 5, 15, -2, 3, -9, 0, -4, 4 },
- { -6, -12, -17, 25, 22, -13, -10, 9, 2, 11, -7, -16, 4, 6, 1, 0,
- 0, 18, -4, -5, 4, -2, -1, -5, 0, -4, 6, 1, 6, -1, 7, 0 },
- { -1, 0, -10, 8, 8, -27, 0, -2, 29, 16, -2, -4, 9, -1, 2, 0,
- 6, 10, 6, 4, 2, -7, 9, -18, 3, 3, 3, -10, 17, 10, 9, -6 },
- { -3, -12, -6, 11, 20, -32, 5, 21, 3, -4, -9, 2, -10, 1, 7, -4,
- 5, 0, 0, -1, -8, -9, -7, 4, -10, 5, 0, 2, -5, 4, 9, 1 },
- { -5, -1, -5, 1, 2, -19, -13, 1, 6, 12, 2, -16, -17, 11, 10, 13,
- 16, -12, -11, 3, -6, 0, 6, 4, -3, 1, 8, 2, 5, -11, 3, -14 },
- { -19, 5, 10, 11, 2, -23, -9, 16, -2, 7, 0, -11, -7, 10, 6, -7,
- 26, -15, -4, 8, 6, -4, 7, -9, -15, 1, 8, -4, 4, 2, -12, 16 },
- { -11, 1, 11, -4, 1, -31, -13, -1, 8, 5, 4, -2, 0, 13, 7, -17,
- 7, -10, -6, 1, 4, -1, 2, -9, -4, 9, 3, 3, -4, -5, 3, 4 },
- { -3, 1, 10, -1, 0, -15, -22, 4, 40, -11, -4, -3, -14, 9, 11, -1,
- 9, -1, -6, 6, 3, -6, 0, 0, -12, 7, -2, 0, 9, 3, 1, 3 },
- { -1, -1, -1, 14, 8, -24, -14, -8, 5, 8, 5, -12, -17, 8, 2, 7,
- 10, -8, 0, 4, -6, -6, -10, 8, 4, -12, 3, -9, -12, 5, 4, -3 },
- { -5, 1, -11, 8, 9, -24, 0, 2, 2, 14, -12, -13, 1, 6, 7, 0,
- 7, -6, 9, 26, 11, -14, 8, 10, 1, 9, 0, 11, -2, 6, 2, -10 },
- { -13, 1, 4, 34, 19, -17, -15, 0, 3, -2, -7, -1, 0, -3, -3, -1,
- 1, -1, -10, 8, 5, 0, -8, 4, -17, 9, -2, 0, 0, 6, 2, -3 },
- { -6, -4, 1, 2, 2, -14, -29, 0, 9, 34, -3, -5, -14, 6, -10, -9,
- -5, -1, 0, 3, 3, 0, 1, -1, -2, -1, -1, -3, -3, -4, 3, -3 },
- { -4, 6, 3, 14, 14, -8, -29, 31, 11, 14, -4, -5, -6, 10, 6, -9,
- -1, -11, -7, 1, 7, 4, 1, -6, 4, 0, 10, -7, -5, -1, 2, 4 },
- { -4, -4, -2, 14, 6, -32, -6, -14, 14, -5, -11, 10, -18, -4, 6, -8,
- 9, 5, -4, 1, -4, 5, -2, -9, 3, 5, 2, -10, -6, -17, 3, 17 },
- { -16, 9, 21, 19, 4, -20, -17, 14, 9, 15, -6, -17, -1, 1, 6, -3,
- 1, 1, 8, -3, -6, 6, 9, 4, 9, -9, -5, 1, -1, 0, -1, 2 },
- { -7, -5, 3, 19, 1, -20, -9, 14, 21, -7, -18, -9, 26, -7, -17, -7,
- 12, 6, 0, -9, -6, 14, 9, -9, -8, 4, 15, -7, -9, -1, 9, 1 },
- { -20, 30, -6, 11, 24, -4, 0, -6, -2, 8, -4, 12, -8, -17, 0, 5,
- -4, 1, -1, 3, -3, 5, 3, 3, 7, -2, -3, -2, 4, 0, 0, -1 },
- { -35, 17, 6, 1, -9, -1, -16, 3, -20, -13, 8, 7, -4, -7, -4, -20,
- 7, 12, -5, 5, -5, -11, 12, -1, 15, -9, -6, 16, -4, -9, -13, 4 },
- { -21, 36, -19, 9, 0, -7, -8, 9, -4, -3, 3, 0, 7, -8, -2, -2,
- -11, 13, -1, 5, -3, 7, 2, 3, -1, -2, -5, 1, -1, -2, -5, -3 },
- { -12, 33, -4, 1, -12, -9, 0, -13, -1, 2, -8, 4, -10, 6, -16, -7,
- -1, -4, -10, 15, -1, 0, -5, -8, 5, 5, -3, 0, 2, -7, 1, -7 },
- { -14, 32, 5, -7, -15, 3, -5, 8, 14, 5, 9, 13, 3, 18, -3, 7,
- 4, -10, -10, 10, -1, 2, 0, -2, -11, 5, -3, -4, 2, 2, 7, 4 },
- { -14, 34, 1, 20, -1, -12, 0, -3, -7, -4, 7, 18, 9, -3, 14, -7,
- -9, -20, -7, -4, -13, 12, 1, 12, 5, -6, 2, -4, 0, -15, 1, 3 },
- { -21, 23, 7, -8, 3, -13, -3, 0, -6, -2, -7, 6, -12, 9, -6, -2,
- -2, -4, -1, 6, 9, 5, -9, 15, 0, 8, -8, 7, 6, -15, 3, -5 },
- { -27, 32, -1, -4, -2, 4, -10, 12, -3, 8, 13, 7, 0, -15, 4, -2,
- 3, 5, 7, -4, 9, -12, -1, -2, -1, -4, 0, -4, 2, -5, 6, -6 },
- { -17, 29, 15, 0, -1, -4, -10, 13, 12, -1, -8, -10, -10, 4, 7, -2,
- 6, -5, -13, 19, 6, 1, -7, 2, -9, -2, 12, -4, -8, -3, 2, 4 },
- { -38, 27, 16, -15, -6, 3, -7, -4, 0, -1, 6, -2, -3, -6, 6, -6,
- -3, 0, 2, 0, -4, 6, 1, -1, 0, 4, -1, 3, 4, 1, -2, 5 },
- { -33, 40, -4, 2, 1, 0, 0, -10, -14, 0, -7, 4, -1, 3, -2, 5,
- 7, 6, -1, 4, 1, 3, 1, -7, 1, -4, 5, 7, 0, 4, 3, -4 },
- { -20, 25, 12, -4, 16, -4, 2, 2, -14, -2, -3, 29, -1, 1, 3, 1,
- 9, -5, 2, -8, -3, 1, -7, -2, -7, 1, 0, 4, 16, -2, -1, -1 },
- { -10, 30, 17, 3, -5, -2, 0, -5, -22, 4, 5, 5, -3, -18, -6, 10,
- -5, -7, 2, 8, 7, -7, -11, -2, 0, -3, 3, 2, 11, -4, 4, -4 },
- { -11, 30, 11, 4, -3, -8, 1, -2, 4, 18, 3, 1, -1, 0, -8, -4,
- -3, 10, 13, 14, 5, -5, 1, 1, -10, 2, 15, 4, 9, -1, -5, -3 },
- { -17, 32, 18, -18, -3, -5, 6, 10, 1, -15, -5, 9, 8, -12, -10, -6,
- 11, 9, -5, -8, -7, 10, 5, -10, -14, -4, -3, 1, 9, -11, 2, 1 },
- { -13, 28, -11, -1, 2, -16, -2, 7, -24, 0, 3, 6, 3, -1, -8, -7,
- -12, 2, 2, -20, 10, 4, 0, -13, -2, -2, 1, 8, -14, 0, 4, 1 },
- { -14, 23, 12, 8, 8, -26, 2, -4, -14, 13, -14, 15, 3, -9, -1, -13,
- -10, -2, -10, 6, -16, 12, 8, 0, 9, -10, -7, -4, -4, 7, -8, 8 },
- { -20, 45, 10, -14, 4, 16, 8, -9, 1, -8, 10, 5, -7, -2, 2, -5,
- -1, 0, -5, 4, -6, -2, 4, 1, 3, 4, -4, 2, -2, -2, 5, 1 },
- { -20, 26, -4, 1, 7, 4, -8, 1, -5, -13, 2, 13, -7, -3, 6, -6,
- 22, 0, 5, 11, -4, -11, 8, -9, 2, -2, -4, -2, 2, -13, -4, -8 },
- { -28, 18, 17, 3, -8, -23, -16, -6, 5, -10, 14, 10, 5, -1, -8, 4,
- -2, 13, -3, -2, 3, 4, 3, -2, -3, -4, 0, 1, 3, 4, 0, 4 },
- { -12, 32, -6, -16, 18, 12, -16, 0, 7, 13, -4, 5, -8, -1, -3, 4,
- 6, -2, -1, -13, 4, -1, 3, 12, -3, -10, 1, 6, 8, -11, -2, 4 },
- { -18, 26, 2, 5, 0, -9, -17, 14, 5, 1, 7, -3, -8, -3, 11, 7,
- -5, -12, -8, 7, 0, -7, 2, -12, -9, 13, -11, 9, 6, -11, -5, 11 },
- { -24, 22, -15, -9, 8, 1, -7, -12, -9, 3, 11, 15, 14, -11, 12, -15,
- -5, 7, -2, 0, -8, 3, 3, -1, 2, 11, -11, 14, -6, 13, 1, -6 },
- { -20, 28, 18, -4, -6, -5, 12, 14, 2, 10, -13, -6, -8, -6, -13, -1,
- -26, 22, -3, -14, 6, 0, 10, -15, -13, -9, 6, -7, 1, -5, -4, -1 },
- { -19, 26, -8, -3, -14, -6, -9, -4, -8, 15, -8, 3, -12, -4, -2, -7,
- -5, 3, 13, -3, -4, -25, 4, -1, 5, -12, -1, -13, 5, 2, 0, 6 },
- { -18, 43, 14, -8, 1, -23, -2, -2, 1, 3, -7, 0, 0, 8, -1, -3,
- -5, 1, 5, 2, 0, -2, -2, -2, 1, -1, -1, -7, 0, 3, -3, 9 },
- { -11, 30, 10, -14, 3, 1, 10, -11, 1, -7, -4, 14, 2, 1, -9, 1,
- -11, -2, -7, 5, -11, 1, 3, 14, 1, -16, -8, 3, -5, 7, -4, 4 },
- { -18, 24, 6, 3, 8, 7, -22, -7, -7, 3, -8, 4, 23, 9, 3, -1,
- 3, 6, 7, -1, -7, 6, 4, 1, -3, 1, -6, -1, 2, -7, 3, 3 },
- { -15, 38, -7, -1, -11, 2, -17, -24, 24, 8, 7, -4, -5, 2, 2, -7,
- 1, 4, 0, -9, 5, 0, -1, 1, -1, -5, -6, 3, 0, 7, 8, -3 },
- { -14, 22, 1, -5, 9, -12, -9, -5, -6, 5, 7, 8, -1, -4, -9, -3,
- -33, -16, -9, -1, 12, -11, 17, -7, -3, -1, -7, 3, 2, -3, 16, -4 },
- { -14, 20, 6, 4, -10, -4, -4, -4, 1, -7, 2, 6, 8, -12, 4, 1,
- -1, 12, 10, 3, -14, -10, -3, 18, -2, 33, -5, -17, 17, -5, 9, 7 },
- { -12, 23, 13, 0, -11, -8, -11, 12, -5, -9, -16, 11, 6, 4, 12, -5,
- 5, -13, 7, -12, -3, 1, 2, 12, 1, -4, -1, 5, 4, 11, -12, -3 },
- { 15, 2, 14, 7, 1, 2, 1, 12, 10, 23, 4, 6, -20, -10, 4, 26,
- -6, 13, 4, 3, 2, -11, 5, -7, -10, 4, 9, 1, 10, -4, 11, 4 },
- { 17, 15, 31, 17, 18, 16, 11, 24, 2, 4, 2, 3, -8, -3, 7, -3,
- -5, -7, -2, -6, -4, -5, -4, -1, -4, -2, -5, -6, 2, -1, 4, -2 },
- { 16, 8, 15, 14, 3, 7, 21, 9, 8, 15, 21, 6, 8, 12, 5, -5,
- 7, -3, 10, 2, -3, 8, 6, 0, 5, 5, 6, -3, 2, 4, 0, -5 },
- { 5, -4, 6, 12, 6, 13, 24, 17, -5, 17, -1, -6, -7, -10, -8, -18,
- 3, -2, 2, 7, -15, -11, 12, -3, -2, -2, -4, -7, 2, 0, 5, 5 },
- { 10, -6, 8, 11, 12, 20, 22, -11, -3, 15, -3, 15, -2, -2, 0, 2,
- 5, -8, 4, -5, -9, -4, -1, 2, -1, -3, 1, 3, 13, -1, 9, 7 },
- { -5, 8, 5, 11, 14, -5, 14, -9, 2, 35, 8, 15, 1, -2, 2, -2,
- 4, -9, -3, -14, -12, -2, -2, -4, -2, -8, -3, 1, -6, 3, 10, 0 },
- { 16, 0, -6, 15, -3, 4, 4, 3, 3, 20, 5, -4, 10, 9, -9, -3,
- -10, -2, -7, 11, -11, -10, 17, -1, 3, -15, 2, 9, -15, -10, 16, 10 },
- { 14, 4, -7, 19, 3, 0, 19, 8, 16, 34, -9, 6, -13, -1, 6, 5,
- -1, -2, 4, 3, 2, 1, 1, -1, 0, -7, 2, -1, 1, 0, 6, -1 },
- { 1, 6, 9, 13, 9, 10, 15, 16, 10, 18, 13, 17, 3, -1, -7, 2,
- -15, -11, -10, -4, -13, -6, -17, -13, -6, -14, 1, -10, 6, 4, -1, -1 },
- { 13, 1, 7, 10, 14, 13, -7, 5, 5, 28, 14, 14, -2, 2, 3, -3,
- -13, -4, 10, -9, 19, -4, -3, 4, -5, -5, 0, 5, -5, 0, 3, -4 },
- { 1, 0, 6, 22, 9, 18, 18, -3, 5, 10, 12, -2, 1, -3, -8, -12,
- 9, -10, -7, 1, -1, 19, 0, 2, -8, -11, -10, 9, 6, 11, 0, 3 },
- { 10, 11, 19, 44, 0, 14, 1, -7, 6, 22, 2, -1, 9, 2, 0, -4,
- 4, 0, -6, -6, 3, 0, 0, -2, 2, -5, 1, -2, 0, 1, 1, 1 },
- { 5, 7, 0, 32, 30, 26, 5, 4, -7, -3, 15, -6, 3, -10, 7, 6,
- -8, -7, 2, -13, -5, -1, -3, 7, 3, -2, -8, 0, 6, 4, 5, 0 },
- { 9, 8, -2, 4, 2, 11, 4, 29, -5, 14, 8, -5, -14, 8, 0, 9,
- 8, -10, 5, -15, -6, -9, 9, -1, 18, -16, 9, -21, -3, -13, -2, 8 },
- { 25, 7, -9, 23, 20, 18, 6, 16, -9, 8, 8, -5, 11, 13, -8, 7,
- 4, 10, -2, -1, -7, -9, -7, -9, -4, 1, 1, -5, -10, 8, 4, -5 },
- { 9, 2, 16, 14, -5, 14, 1, 0, -21, 17, -1, 9, 12, -3, -3, 4,
- -4, 14, 10, 3, 0, -10, 7, 4, 4, -11, 2, 4, -1, -3, 9, -1 },
- { 17, 8, 11, 26, 15, -3, 14, -1, 12, 9, 10, -8, 8, -18, -11, -3,
- -14, -7, 7, -3, -3, -4, 1, -7, -3, 2, -3, 16, 10, 0, 9, 6 },
- { 9, 8, 3, 8, 18, 14, 11, 1, 10, 6, 1, -4, -16, -2, 14, -2,
- 1, 8, 12, 14, 3, -3, 8, 8, 12, -15, 3, -3, 3, -2, 14, 10 },
- { 22, -3, -11, 13, -7, 11, 4, 11, 3, 14, 0, -6, -2, -9, 4, 2,
- -2, 0, -5, -27, -10, 3, -1, 5, 8, -24, -3, -11, -3, 2, 11, -1 },
- { 19, 2, 8, 36, 5, -6, 3, 15, -3, -4, -5, 14, -10, 1, -12, -10,
- -3, -4, 3, -2, 1, -8, 4, 3, 5, -3, 0, 4, 8, -2, 8, 4 },
- { 8, 14, 15, 9, -4, 10, 5, 11, 9, 10, 8, 9, -15, 15, 6, -8,
- -10, -13, 5, -8, -20, -13, -6, -11, -1, -3, -6, -4, -1, 0, 13, 15 },
- { -2, -1, 9, 12, 2, 2, 13, 3, -23, 33, 15, 2, -4, -1, 3, 8,
- 8, 6, 6, -7, 8, 6, 9, -1, 3, -8, 0, -4, 1, -8, 11, -1 },
- { 6, 5, -6, 16, 2, -3, 31, 21, -9, 12, 0, -1, -4, 1, -12, 3,
- -13, -18, 2, -11, -9, 2, -8, -6, 11, -3, -1, 0, -1, 0, 13, 5 },
- { 5, -1, 2, 0, 25, 5, 10, 16, -5, 21, 14, 12, 13, 2, -5, 5,
- 5, -3, -2, -14, 0, -12, 7, 11, -1, -7, 19, -1, -1, -1, 8, -1 },
- { 10, 7, 3, 11, 0, 8, 22, 3, 3, 19, -4, 12, 15, 9, 5, 15,
- 2, 1, 2, -10, -10, 0, 2, -1, 0, 1, -12, -1, 21, 16, 9, -7 },
- { 11, -4, -5, 24, -7, 11, 20, 11, -15, 18, 5, -13, -15, 0, -5, 9,
- 1, 0, -1, -9, 4, -8, 6, -8, 1, -2, -7, 20, 9, 3, 9, 3 },
- { 20, 0, -12, -6, 9, 31, 9, 12, 8, 27, 15, 7, -16, 5, -3, -7,
- -1, -9, -2, -7, -3, 4, -8, -3, 3, -6, -2, -2, -3, -6, -1, 2 },
- { 6, -6, 48, 8, -3, 19, 12, 11, -7, 2, 3, 0, -1, 1, 8, -4,
- 4, -6, 0, -4, -4, -3, 3, 6, 3, -13, -8, 5, -3, -7, 8, 5 },
- { 7, -2, 6, 11, 12, 2, 14, 4, -5, 12, 2, 9, 4, 2, 0, -1,
- 2, 0, -15, -9, -16, -2, 8, -17, -5, -22, -19, -5, -1, -10, 1, -2 },
- { 11, -9, 3, 12, 6, 6, 1, 17, -6, 19, 14, 7, -7, -1, -1, -9,
- 9, -11, -17, 0, -6, 16, 0, 1, 9, -24, 3, 3, -9, -3, 3, -2 },
- { 9, 0, 1, 8, 1, 7, 2, -5, -3, 8, -1, 7, 2, 6, -3, -6,
- 5, -2, 6, -2, -4, -3, 0, -3, 13, -50, 1, -2, 2, 4, 4, 3 },
- { 7, 0, 26, 21, -4, 2, 17, 8, 7, 11, -7, 1, -1, -15, -1, -15,
- -11, -4, -17, -4, 1, -7, 3, 6, 3, -9, 2, 3, 6, 10, 6, 12 },
- { 1, -2, 2, -1, -10, -4, 6, -3, -5, -2, -8, 2, 2, 2, 8, 0,
- 1, 1, 6, 0, 11, 13, 3, 4, 0, -12, 11, -5, 19, 20, 2, 5 },
- { 5, 3, -13, -2, 1, -12, 11, -7, -12, 7, 10, 0, 7, 0, -2, 4,
- -6, -9, -11, -12, -23, 12, 10, -3, 0, 6, 19, -1, 24, 18, 9, 12 },
- { 6, -3, 2, 5, 2, 2, -2, -5, -8, -11, -4, 3, -8, -4, 5, -3,
- -16, -4, 3, -12, -4, 3, 32, 7, 2, 8, 32, -18, -1, 12, 1, 7 },
- { 0, -8, -1, 0, -8, 7, -8, -1, -1, 4, -12, -1, 3, 0, 1, -18,
- 8, 8, -14, -10, -11, 19, 9, 5, -7, 6, 8, -4, 26, 12, -1, 6 },
- { 3, 5, -14, 7, 14, 8, 20, -13, -16, -10, -2, 17, -7, 4, -8, -9,
- 14, -5, 3, -4, -12, 7, 14, -10, -19, -20, 35, 8, 13, 14, -2, 9 },
- { -2, -4, -1, 1, -3, 0, -1, 1, 2, 2, 6, 0, 0, 4, 5, -2,
- 3, 3, 3, -2, -7, -3, -3, -1, 6, -2, 29, 22, 13, 34, 0, 14 },
- { -3, -9, 3, 1, 5, -4, 2, 0, 7, -9, 0, 2, -5, -3, 0, 6,
- -1, -1, -1, 2, 2, 4, 8, 7, 20, -6, 7, 16, 33, 20, 6, -1 },
- { -11, 1, -3, -3, -11, 3, -9, -25, -1, -16, 4, -8, 15, 1, -2, 7,
- 8, 23, 2, 18, -13, 16, 3, -7, 6, 3, 16, -8, 12, 16, 3, 4 },
- { 0, 5, 5, -5, 1, -1, 2, -3, -2, 1, -13, 2, 2, 10, 6, 7,
- 18, 18, 7, 9, 8, 9, 21, 14, 7, 12, 15, 14, 15, 12, 11, 5 },
- { 1, -5, 11, -2, 17, 8, 3, 0, -1, 6, 11, -7, 6, 6, 7, 5,
- -15, 14, 1, 11, 4, 10, 12, 1, 2, 4, 30, 1, 11, 1, 6, 13 },
- { 2, 4, 3, -7, 5, 8, -11, 7, -5, 9, -10, 6, 8, -10, -3, 10,
- 1, -29, -4, -26, 5, -8, 13, 4, 3, 6, 35, 1, 3, 6, 3, 0 },
- { -2, 1, 0, 0, -1, -3, -7, -3, -9, -3, -1, -6, 3, 4, 4, 0,
- 5, -1, -2, -2, -1, -4, -10, 8, 0, -6, 10, -4, 46, 12, 2, 28 },
- { 4, -1, 4, 1, 0, 4, -2, -2, -2, -1, 2, -4, 1, 5, 0, -3,
- 1, 1, -2, 0, 1, -2, -1, -1, 3, -6, 35, -11, 13, 53, -3, -1 },
- { -5, -2, 0, -13, -16, 5, -12, -11, 1, -30, 3, -18, -24, -8, -5, -19,
- 1, -3, -8, 7, -7, -8, 15, -19, 4, 10, 30, 24, 6, 1, -9, 10 },
- { -4, 8, -7, -4, -6, 12, -1, -9, -4, 2, -9, 3, 2, -2, 4, 2,
- 22, 9, 4, -5, 0, 5, -2, -9, -3, 1, 18, -12, 18, 16, 4, 16 },
- { -5, -8, -3, -5, -3, 6, -7, -3, -2, -5, -3, 1, 2, 2, 4, -6,
- 10, 3, 12, -3, 20, 0, 27, -4, 16, 5, 18, -3, 23, 4, 12, 11 },
- { 0, 1, 0, 1, -2, 1, 2, 1, -1, 0, -2, 2, -2, -4, 1, -2,
- -2, -1, -5, -2, 0, 0, -2, 2, 9, 7, 63, 5, 12, -1, 1, 0 },
- { 4, -3, -7, -5, -11, -5, -12, -10, -10, -12, -15, -12, -14, -14, 1, 1,
- 10, -10, 16, 6, 2, 9, 11, 9, 9, 8, 12, -1, 13, 12, 6, 3 },
- { 7, -3, -2, 4, 6, -8, 2, -3, -12, -5, -9, -8, -10, 15, -2, -4,
- 8, 9, 7, -13, -18, 34, -5, 7, 12, 22, 16, -11, 13, 25, -15, -11 },
- { -3, -2, 0, -4, 1, 0, -3, -13, -7, 13, 12, -7, -10, 13, 19, 6,
- 16, 15, -12, -15, -3, 34, 1, 5, 1, -9, 11, 21, 8, 17, -5, -6 },
- { 3, -5, 0, -4, 0, 4, -11, 4, -7, -3, -1, -8, 3, -2, 2, 1,
- 11, 5, 6, 14, -3, 2, -4, -7, 0, 31, 15, -2, 24, 11, 5, 4 },
- { -1, -4, -9, 5, -8, -18, -4, -9, -20, -18, 7, -14, -16, 3, 8, -3,
- 29, 11, -13, -13, 7, 1, 17, 6, 6, 21, 11, 1, 14, -8, 2, 5 },
- { -3, 8, -10, -6, 12, 2, 1, 3, 3, 3, 3, -6, -8, -14, 15, -5,
- 16, 4, 16, 0, 7, -1, 0, 16, 2, 1, 22, 4, 19, 13, -11, 1 },
- { 2, -3, 10, 20, -4, -1, -8, 5, -8, -9, -6, -2, -4, -7, 8, -10,
- 0, 8, -6, 1, -8, 14, 13, 5, 17, -6, 26, -1, 7, -1, 0, 12 },
- { -4, -7, -31, -2, -7, -1, 5, -5, -5, -12, 4, -7, -6, 3, 15, -2,
- 5, -2, 7, -1, 10, 7, 8, -1, 14, 20, 14, 9, 16, 16, 8, 24 },
- { -7, 0, -3, -6, 1, 3, -13, -6, -4, -4, -5, -9, -1, -10, -4, -8,
- 2, 0, -1, 1, 24, 24, 21, 31, 5, 2, 11, 12, 7, 4, 3, 6 },
- { -3, -5, 6, -4, -3, -1, 2, -1, -2, 1, 0, -8, -1, 2, 0, -4,
- 6, 22, -1, -5, 8, 12, -1, -2, 28, 27, 20, -27, 14, 1, 2, -3 },
- { 1, -5, -2, -2, 6, -2, 9, 1, -2, -5, 3, 4, 11, 5, 2, 8,
- -3, -1, 1, -2, -3, -5, 5, 8, 49, 12, 8, -3, 9, 20, 12, 17 },
- { -6, 0, 1, 7, 0, 9, -2, -4, 8, 0, -2, -10, 0, 7, 21, -1,
- 0, 1, 17, -7, -5, 2, 4, 16, -2, 17, 14, -20, 15, 14, 4, 15 },
- { 0, 3, -4, 9, -4, 0, 6, 4, -6, -6, -5, -7, 2, -9, -10, -2,
- -5, 0, -3, -21, 9, 14, -11, 13, 29, 2, 25, 4, 22, -1, 2, -3 },
- { 2, 12, -11, 2, 16, 9, -4, 7, 1, -10, -15, 11, -4, 3, -2, 4,
- 4, -5, -10, 1, 4, 19, -15, 6, -4, -2, 30, -7, 11, 21, -12, 5 },
- { -2, -3, -2, 4, -1, -5, -3, -7, -5, 1, 0, -6, 1, -6, 7, 0,
- 8, -7, -3, -2, 2, 14, 2, -3, -26, -1, 26, 22, 32, 1, -2, 6 },
- { 1, -38, -1, -20, -2, -3, -6, -4, 2, 2, 7, 0, 3, 5, 3, 10,
- 6, 1, -3, -5, 7, 5, -5, -4, 8, 3, 1, -14, -1, -9, -5, -4 },
- { -5, -26, -7, -19, -10, -5, -11, 5, -11, -25, -8, -14, -9, -16, -8, -6,
- -17, -14, -1, -1, 6, 2, 2, 2, 3, 0, 2, 8, -8, 3, 0, -3 },
- { 17, -49, -3, -23, -1, 11, 7, 3, 4, -4, 0, 0, -1, 4, 2, 4,
- -2, -4, 2, -2, -1, -2, 2, 0, 0, -1, 0, 0, 1, 2, 0, 0 },
- { 4, -34, -6, -9, 1, 21, -7, 3, -2, -1, -3, 18, 2, -16, 7, -3,
- 8, 7, -5, 7, 2, 4, 8, -6, -7, -2, -5, -1, 4, 1, 2, -4 },
- { 5, -29, 13, -2, -14, 3, 1, 18, -15, 4, -8, 8, -10, 8, 2, 1,
- -8, 15, 3, -10, -4, -4, -2, 0, -3, -4, 2, -3, -4, -3, 12, -6 },
- { 13, -20, 3, -18, -17, 4, -14, 13, 28, 11, -8, -6, 16, 6, 0, 10,
- 3, 4, -9, 13, 5, -7, 12, -5, 0, -7, 5, 1, 3, 3, 2, 1 },
- { 3, -27, -5, -11, -21, -11, -12, 0, -5, 7, -22, 1, 3, 5, 0, -5,
- 8, 7, 1, -5, -7, 2, -5, 4, 1, 3, -8, -2, 0, 4, -2, 6 },
- { 31, -45, 0, -1, -12, 1, 2, -6, 4, 3, -1, 3, 3, 0, 5, 3,
- -5, 12, 4, 6, 2, 1, -2, 1, 3, 2, 5, 2, 2, 2, 3, -1 },
- { 9, -45, 6, 5, -1, -17, -2, 18, -3, 2, 0, 1, 0, -1, 10, 8,
- -7, -2, -5, -8, 6, -1, 0, 4, 6, -3, 12, -1, -2, 0, 5, -7 },
- { 3, -26, -2, -12, -12, 2, -10, 16, -3, 12, 4, 5, 11, 8, -16, -17,
- -2, -3, -3, 2, 5, -9, 13, 1, 10, 11, 3, 5, -2, 2, 2, -7 },
- { 8, -26, 32, -7, -5, 22, 2, 14, -10, -8, -7, 3, 3, 7, 0, -5,
- 0, -1, -3, 0, 8, 4, -5, -7, 6, -1, 4, 8, 1, 1, 7, -6 },
- { 4, -31, 2, -14, 2, 0, 1, 8, -6, -1, 17, -3, 13, -6, 5, -10,
- -2, -10, -2, -10, -3, 7, 1, 5, -8, 8, -14, -3, -15, 7, -10, -6 },
- { 16, -27, 13, -4, -23, 7, -9, 6, -7, 5, 4, 2, -1, -3, 23, -18,
- 7, 0, -3, 4, -3, 9, -6, -2, -1, 8, -6, 2, 6, -3, 2, -2 },
- { -1, -35, -2, -8, 11, -1, -7, -3, -2, 11, 7, 6, -6, -10, 9, 6,
- -3, -5, -6, -3, 9, 16, -16, -9, -20, 12, 3, 5, -3, 1, -9, 4 },
- { 2, -24, 1, -12, -16, 5, -4, 3, -4, -1, -11, -11, -8, -14, 14, 10,
- -8, 20, 8, -3, -11, 1, 1, -4, -4, -7, -3, 15, 2, -6, -2, 7 },
- { 9, -21, 2, -19, -7, -5, -8, 25, 3, 17, 5, -3, 9, -12, 8, 2,
- -4, 3, 3, 1, 11, -9, -4, -3, 4, 3, -22, 6, 4, 6, 11, -5 },
- { 16, -23, 13, -17, -21, -12, 5, 9, -20, 7, 6, -6, 0, 2, -9, 6,
- -6, -13, -7, -1, 5, -3, 5, -7, -10, 1, 0, 8, -9, 11, 0, -8 },
- { 10, -26, -9, -7, -19, -4, 6, 16, -7, 5, -4, 4, 8, 0, 4, -1,
- 6, -7, 1, -8, -11, 10, -14, 0, -16, 6, -3, 5, -1, 14, 12, 1 },
- { 8, -27, 12, -14, -1, -1, -19, 10, -11, 21, -14, 9, -8, -3, 8, -1,
- 12, -13, 3, -4, -2, 0, -9, 0, -7, 2, -3, 12, 1, -3, 3, 1 },
- { 18, -20, -14, -14, -16, -3, -24, 6, -17, 2, -3, -11, 2, -3, 12, 10,
- 10, 1, 10, 7, 8, 5, 5, 4, -1, 7, 2, 2, 0, 4, 7, 0 },
- { 0, -30, 9, -16, -18, 15, 12, -3, 4, -4, -5, -11, -4, -12, -10, 0,
- 2, -2, -4, -1, 2, 0, -1, -6, 2, -3, 4, -5, 7, 3, 5, 7 },
- { 25, -24, -1, -6, -9, 6, -13, -2, 3, 15, -3, 11, 4, -8, -11, 2,
- 0, -9, -2, 7, 4, 8, 5, -8, 5, 6, -1, -11, -15, -5, 0, 11 },
- { 0, -34, -7, -11, -7, 9, -3, 19, 4, -8, 3, -11, 11, -3, -9, 12,
- 9, 9, 2, 1, -7, 1, -3, 0, -6, -2, -1, 3, 0, -7, -2, -5 },
- { 6, -34, -4, -5, -3, -9, 2, 9, -1, 9, -5, -3, -26, -12, 8, -6,
- -7, 11, -8, 4, 4, 1, -1, 0, 8, 9, -4, 7, -1, 1, -3, -1 },
- { 3, -30, 5, 6, -10, 3, -7, 6, 3, 3, -26, -19, -3, 1, 7, 5,
- -4, -5, 6, 10, 13, -10, 4, -7, -4, 5, -3, 9, -6, 3, 9, 5 },
- { 4, -24, 9, -19, 2, -4, -5, 8, -3, 2, 0, -15, -1, 9, -4, 22,
- 6, 9, 3, 7, 11, -9, 0, -3, 4, 5, -5, 10, -8, 5, -7, -3 },
- { 8, -27, 7, -3, -1, 2, -9, 13, 7, 12, -4, -6, -6, 5, 0, 7,
- 5, 1, 15, -3, -4, 0, -5, -2, 7, -5, -7, 1, -2, 13, -8, 13 },
- { 17, -22, -15, -11, -8, 16, -14, 18, 2, -1, 14, -7, 14, -6, -6, -7,
- -8, 17, 6, 4, 4, -7, -5, -9, -14, -6, -1, 9, -3, 1, 6, -5 },
- { 25, -30, 2, -12, -13, 18, -18, 16, 8, -3, 10, -8, -3, -1, -6, 3,
- -5, -7, 4, 6, 7, 1, 1, -11, -5, 6, 2, -4, 9, -1, -5, -2 },
- { 7, -23, 7, -15, -1, -3, -1, 0, -10, 12, 2, 5, -4, 0, 4, 6,
- -1, 5, -9, -1, -1, -7, 1, 17, 9, -17, -16, 8, 4, -14, 11, 14 },
- { 0, -31, 7, -13, 3, -11, -7, 6, 1, -11, 8, -7, 15, -3, 16, -11,
- -1, -15, 16, -3, 5, 0, -2, -2, -6, 11, 5, 6, 5, -5, 6, 3 },
- { 13, -24, -2, -20, -10, 7, -3, -1, 15, 2, 6, -5, -7, -10, -20, 1,
- -4, 14, 8, -2, 3, -13, -3, 1, -4, 1, -3, 2, 8, -7, 16, -4 },
- { 1, -2, -2, -3, -4, -7, 0, 3, 6, 7, 3, 2, 1, -2, -1, 0,
- -6, 4, 2, -4, -3, -4, 5, 9, 5, 0, -3, -3, -4, -7, -31, -50 },
- { -1, -3, 7, 2, -1, 2, 4, 6, 0, 10, -2, 0, -20, -6, -3, 9,
- -20, -22, -1, -1, 15, 9, -12, 10, -13, -20, 12, 3, 5, 6, -7, -26 },
- { 0, 4, -2, -14, -12, 6, -13, 11, -10, 3, 22, 6, 16, -2, -5, 1,
- -3, -11, 0, -7, 5, -5, 0, 1, -1, -6, 8, 8, 10, 9, -5, -27 },
- { -5, 10, -2, 7, 9, -9, 5, -9, 5, 4, -15, 14, 1, 3, -10, 5,
- 0, -2, 7, 3, -13, 6, 9, -6, 5, -14, -17, -1, 11, 14, -2, -26 },
- { 0, 6, -3, 0, -8, 6, 0, 1, 4, -8, 2, -5, 4, 7, 15, 11,
- 9, 19, -2, 14, -8, 7, -1, 3, -3, -3, -10, -2, 12, -2, -12, -29 },
- { -12, -5, 0, -3, -2, 6, 3, -3, 2, -2, 1, 11, 2, -7, 5, 1,
- 2, -2, -14, 0, -1, -5, 3, 8, -28, -26, 6, -6, 3, 8, -10, -27 },
- { -1, -3, 6, 2, 4, 15, 1, 0, 2, -2, -2, 13, 3, 6, 0, 6,
- -1, -4, -1, -5, 8, -1, 5, -5, -15, 11, -8, -5, 14, -6, -14, -29 },
- { -5, -6, 0, 1, 0, 6, -3, 2, -5, -1, 5, -3, 2, -10, 3, 4,
- 3, 0, 13, -3, -1, 4, -4, -6, 2, 9, 8, 2, -3, 28, -11, -31 },
- { 1, -4, -10, -9, -4, -3, -15, -6, 1, 5, -3, -6, 5, -6, -22, 27,
- -13, 5, 3, -7, -4, 20, -7, -12, -1, -24, -4, -13, -8, -11, -15, -21 },
- { -6, -4, 19, -6, 2, 11, -6, 1, -3, -10, 9, -9, 12, -10, 2, 1,
- -9, 1, 15, 7, -5, 5, -29, -35, 4, -30, 9, 9, 19, 17, 2, -17 },
- { -3, 3, -3, 1, 2, 5, -1, 5, -2, -3, 1, -3, -8, 3, -4, -2,
- -4, -1, 12, 0, 2, -8, -6, -4, 16, -1, -14, -2, 25, -6, -15, -36 },
- { 0, -1, 3, -4, -4, -1, 7, -4, 8, 0, 10, 9, -4, 1, 10, -1,
- -3, -13, -5, -4, -1, -4, 8, 11, 14, -7, -5, 16, 12, 13, -1, -28 },
- { 1, -2, 2, -3, -8, 10, 4, 9, 12, 3, 5, 0, 8, -3, -6, 2,
- 16, -11, 11, 0, 1, 6, 1, 18, -10, -16, -1, -4, 5, -14, -15, -20 },
- { 1, -12, 5, 4, -7, 8, -1, -17, -2, -9, -14, -11, 6, -9, 5, -4,
- 3, -2, 7, 18, -5, 5, 6, -1, -11, -2, -10, -3, 8, -3, -2, -32 },
- { -12, 5, 20, -5, -6, -11, -6, -6, -13, 4, -6, 19, -8, 2, 3, -9,
- -4, -4, -1, 9, -1, 21, -1, 7, 15, -10, -1, -3, 9, -3, 2, -24 },
- { 0, -3, 2, -6, 4, -1, -9, -2, -1, -3, 6, -1, -5, -6, -5, -8,
- 0, -2, -6, 9, -4, 3, 2, -13, 1, -7, 23, -13, 4, -3, -15, -33 },
- { -7, 2, -15, 11, -10, 14, 0, -11, 3, -1, 12, -4, -4, 9, 11, -13,
- -13, -3, -14, 1, 3, 6, -5, 8, 0, 5, 5, -10, 4, 5, -6, -30 },
- { -6, 4, 0, -5, 4, 1, -1, -1, 3, 6, 5, -2, -5, 0, -2, 5,
- -4, -2, -4, -2, 4, 7, -7, -1, 1, -4, -3, -19, 37, 12, 10, -40 },
- { -7, 2, -7, -12, 17, 11, -7, 2, 2, 3, 1, -1, 3, 4, -2, -5,
- 9, -9, 6, 4, 9, 12, 11, -5, 2, -1, 0, 9, 5, -7, -2, -24 },
- { -7, 6, 1, 3, 1, 0, 6, 0, 4, -12, -2, -2, 1, -9, 10, -2,
- 11, -1, 21, -12, 15, -5, 10, -5, 5, -5, 14, -6, 5, -7, -3, -29 },
- { -2, 0, -5, -2, -3, 1, -3, 0, 4, 2, 3, 0, 2, -2, 7, -2,
- 3, -5, 2, -1, 6, -4, 0, -3, 8, -11, 19, -8, 22, -34, 13, -35 },
- { -1, -3, -1, 9, 11, -3, -3, -1, 7, 18, 11, -5, 2, -12, -11, 18,
- 9, -5, 1, -6, -9, 12, 1, -3, -3, -9, -14, 9, 9, 8, -6, -26 },
- { 0, 5, -5, -1, -1, -2, 4, 6, 8, 2, -1, -2, 5, 1, -5, -4,
- 1, 1, 18, 1, 7, -10, 3, -2, 12, -1, -15, 9, 12, -14, 13, -38 },
- { 3, 0, -8, -1, 0, 8, -9, -3, -8, 16, 3, 16, -5, -9, 0, -1,
- -7, -1, -4, 13, 7, 0, 1, 2, -1, -16, 0, -2, 1, 8, -8, -28 },
- { 7, 9, -5, -3, -2, 2, 0, 3, 11, -6, -4, -2, -2, -5, 28, -18,
- -6, 2, 15, -10, -15, -10, -2, 0, -2, -2, 4, -3, 7, 11, 5, -30 },
- { 9, 0, -7, -1, -4, -7, 2, 2, 9, -2, 2, 3, -8, -6, -6, 3,
- -10, 4, 10, 5, 21, -4, 14, -18, 1, 3, -10, -2, 6, 14, -8, -26 },
- { -14, -1, 2, 3, -3, 7, 1, -22, -1, -1, 0, 1, 12, -14, 3, -5,
- 0, 10, -3, 1, -5, 12, -3, 10, -8, -22, -11, -13, -7, -10, -13, -25 },
- { -2, -5, -4, -4, -9, -18, 9, -3, -5, 17, 13, 5, 6, 11, 3, 8,
- 20, 4, 2, 9, 8, 5, 6, 1, 7, -7, -6, -2, -7, 0, -17, -23 },
- { -5, -5, 2, 0, 6, 2, -2, 2, -3, 4, 4, 0, -5, -2, -4, 6,
- 8, 10, -1, 1, -5, 5, -14, -2, -11, 8, 6, 25, 7, -1, 0, -43 },
- { -4, 0, 4, -2, 7, 0, 3, 17, 5, 2, -5, 1, 21, 3, -2, -10,
- -16, -9, 7, -12, 9, -8, 2, 5, -5, -10, -2, -11, -5, -1, -9, -30 },
- { -2, 3, 1, -4, -1, 0, 8, 1, 12, 4, -1, -1, 3, -17, 13, 9,
- 0, 7, -6, -5, 9, 1, 5, 4, -10, -18, 0, 14, 11, -4, -16, -28 },
- { -1, 0, 2, -1, 4, 1, -1, 1, -1, -2, -1, -2, 3, 0, 0, -1,
- -1, 1, 2, -2, 3, 3, -2, 4, -2, -1, -6, 1, -1, -1, 6, -70 },
- { 7, 3, -11, -1, 12, -4, -14, 4, 4, -4, 4, -2, 2, -12, -4, 15,
- -17, -4, -3, 6, 8, -5, 22, -22, 5, -11, 15, -4, 4, -1, -21, -1 },
- { 10, -2, -13, 11, 4, 14, 4, 9, 8, 8, 19, 15, 14, 15, 5, 10,
- 8, 15, -5, 4, 14, -8, 1, 1, 2, 1, -1, -3, 21, 8, -29, 13 },
- { -6, 0, -6, 6, -1, 2, 8, -4, -5, 4, -4, -5, 0, -2, -4, 0,
- 9, -2, 1, -2, 26, -19, 21, -10, 4, 1, -8, 5, 22, -10, -13, 15 },
- { 11, -5, 1, 0, 6, 3, 7, -2, -2, -3, -5, -1, -2, -6, 1, 1,
- -8, -5, -13, 13, -2, -3, -1, -9, -28, 4, 2, -11, 18, -20, -24, 9 },
- { 7, 4, -3, 6, 6, -6, -7, -5, -7, -4, -4, 0, -7, -5, -6, -5,
- 2, -13, -12, 2, 0, 5, 18, 15, -13, -7, 13, -20, 16, -10, -19, 6 },
- { 5, -8, -1, 5, 10, 2, -1, -10, -11, 23, 8, -5, -8, 4, -5, -4,
- -5, -5, -11, -8, 5, 1, 7, -9, -9, -6, 12, 14, 17, -12, -22, 3 },
- { -5, -8, -3, 3, 12, -1, 0, -4, -5, 1, 1, 6, 1, 5, -5, 7,
- -2, 7, 1, 6, 6, 2, 0, -5, 17, -4, -5, -24, 13, -20, -27, 14 },
- { -1, 2, -3, 1, -3, 1, -3, 0, -2, 3, -2, 1, 2, -1, -2, -1,
- -2, -5, 5, -2, 0, -7, 1, -6, 8, 8, 11, -5, 24, -43, -13, 2 },
- { -2, 4, 7, -3, -4, 4, 13, -4, 0, 0, -2, 9, 0, -3, -6, 1,
- -7, 1, -1, 10, 0, 5, -1, -24, 25, -15, 7, 2, 22, -10, -21, 0 },
- { -5, 2, 6, -2, 13, 3, 5, -12, -11, 16, 6, 10, -5, 0, -3, 6,
- 5, -5, -5, 10, 12, 10, 11, -7, 8, -14, 2, -15, 13, -14, -8, -3 },
- { 5, 6, -7, -5, 5, 2, 9, 5, 0, -1, -4, 2, 8, 0, 3, 5,
- -12, 3, -3, -6, 2, -1, -5, 14, 11, -20, -21, -25, 24, -1, -10, 6 },
- { -5, 5, -2, 9, 4, -4, -1, -6, 11, -6, 5, 0, 2, -3, 6, -1,
- -17, -18, -4, -13, 9, -1, 9, -7, -4, -8, 2, -3, 12, -31, -18, 5 },
- { -7, -11, 6, -8, 4, -3, -12, 0, -1, -6, -3, 0, 5, 9, 7, 2,
- 1, -8, -6, 8, 2, -5, 7, -1, 16, -10, 16, -12, 18, -1, -25, -12 },
- { 3, -12, 1, 2, -2, -18, -8, -15, -10, -9, 2, -7, 11, -11, 2, -1,
- -1, -1, -9, -6, 3, -14, -2, -1, 2, -13, -7, -9, 19, -5, -17, 2 },
- { 7, 1, -8, 7, 17, -13, -10, 5, 7, 1, -6, 4, 9, -4, 0, 3,
- 8, 1, -14, -9, 4, 7, -9, 0, 6, -5, -12, -2, 25, -2, -19, 1 },
- { 7, -3, 6, -3, 1, 6, -7, 0, 10, 0, 4, -5, -17, -4, 4, -1,
- 0, -3, -7, 19, 24, -1, 21, 8, 10, 9, 8, -1, 23, -2, -18, -2 },
- { 3, -3, 0, 5, 8, -2, -9, 2, 9, 6, 19, 8, 2, 6, -9, -2,
- -4, -3, -8, 7, -7, -8, 5, 4, 26, -6, 7, 18, 24, 0, -13, 4 },
- { 0, -13, -11, -1, 3, -9, 5, 4, -7, 3, 0, 2, -1, 4, -5, 2,
- 9, -2, -11, 15, 1, -21, 1, -1, 0, 4, -14, -4, 24, -16, -13, 1 },
- { 1, -9, -8, 0, 0, -4, 11, -1, 14, 16, 0, 17, -2, -9, -12, 0,
- -1, -14, -9, -14, 0, -2, 19, 4, 6, 4, 4, -11, 8, -17, -19, -5 },
- { -3, 1, 2, 12, -4, -18, -1, -4, -7, 14, -3, 2, 0, -7, -8, 12,
- -5, -9, 14, 12, -9, -2, 4, -6, 4, 18, -1, -25, 22, 2, -23, -5 },
- { -2, 0, 0, 0, 1, 3, 5, -1, 5, -2, -2, 2, -3, 0, 1, 2,
- 0, -1, 2, -1, -9, -6, -7, -4, -2, 4, -7, -5, 64, -3, -25, 4 },
- { 12, -2, -3, 0, 8, -9, 13, -7, 6, -3, -12, 12, 15, -9, -4, 2,
- 9, -4, -12, 3, 14, 1, 7, -15, 15, 0, -6, -12, 0, -3, -20, 6 },
- { 2, -1, -4, 5, 9, 6, -7, 2, -2, -7, -2, 0, -1, -18, -4, -6,
- -15, -5, 11, 5, -10, -1, 2, 7, 12, -19, -7, 8, 21, -4, -15, 4 },
- { 4, 2, 5, 5, -5, 1, 3, 2, -8, 13, 0, -5, -2, -14, -11, 6,
- 2, 17, 8, -13, 26, -2, 5, -15, -4, -14, 12, -9, 13, -21, -23, -4 },
- { 2, -3, -2, -3, 3, -2, 6, 9, -9, 13, 4, 2, 12, -3, -3, 1,
- -17, -22, -3, 4, 3, -2, 1, -9, 1, -6, 11, -13, 14, 0, -15, 6 },
- { -16, -4, 17, -2, -20, -11, 11, 10, 5, -8, 16, 2, -17, -14, 11, 11,
- -6, -11, -7, 12, 12, -10, -6, 5, 8, -4, -2, -5, 28, 3, -13, 4 },
- { 0, -3, 3, -7, 6, 8, -12, 20, -19, 18, -11, 10, -5, 0, -9, 11,
- 3, 0, -2, 9, -7, -5, 18, 3, -2, -16, 1, 6, 12, -7, -16, 1 },
- { 4, 1, 5, -5, 15, 2, -8, 3, 5, -11, 15, -3, 8, -8, -1, 7,
- 4, 7, -2, 6, -9, 5, 12, 2, 33, -2, -6, -18, 4, 0, -18, 11 },
- { 3, -1, 1, -1, 0, 1, 4, -1, -5, 0, 1, 0, 4, 2, -1, 4,
- -3, 2, 0, -2, 4, 6, -1, 6, 42, 19, -4, -37, 19, 1, -15, -4 },
- { 2, 0, -5, 0, 10, 0, 0, -5, 3, 0, 0, -3, -3, 0, 2, -4,
- -10, 2, -6, 4, 4, 1, 27, -7, 17, -34, 5, -9, 15, -16, -7, -5 },
- { -2, 7, 7, -2, 9, -2, -15, 11, 11, 7, 5, 1, 15, 1, -9, 31,
- 2, -15, 2, 4, 3, 4, -1, -8, 2, -7, 6, -17, 11, -14, -11, 2 },
- { 1, 1, -11, 9, 9, -6, -14, -11, -10, 8, -3, 11, 16, -9, -8, -13,
- -8, 9, 0, 6, 6, -2, 13, -8, -2, 3, 13, -3, 10, -6, -17, 4 },
- { 14, 5, 4, -6, -12, 10, -7, 8, 21, -8, -30, 15, -2, 1, 11, -9,
- -5, 1, 0, -1, -1, -6, -2, 3, -5, 7, 9, 5, -5, 2, 0, 1 },
- { -1, 2, 20, -17, -15, 3, 3, 7, 11, -17, -13, -6, -3, 18, 17, -15,
- -4, -4, -5, 22, 14, -14, -2, -10, -7, 11, 8, -7, -3, 0, -7, 11 },
- { 7, -11, -7, -8, -14, 22, 5, 2, 6, 13, -12, -2, 10, 3, 0, -21,
- -4, 20, 3, 10, 21, -10, -12, 8, 11, 2, -5, 2, 1, 3, -1, 15 },
- { -1, -2, -1, -2, -13, 8, -4, 0, 7, -2, -17, 8, 18, 5, 3, 8,
- -8, -2, 3, -4, 14, -18, -13, 14, 15, -13, -1, -2, 4, 11, 1, 12 },
- { 13, -6, -4, -16, -17, 16, 21, -2, 5, -11, -9, 19, 21, -17, -3, -17,
- 3, 12, 8, -12, -6, 1, -7, 9, 9, -7, -5, -1, -3, 5, -6, -4 },
- { 11, 5, 12, -20, -6, 10, 4, 12, 8, -5, -10, 15, 13, 14, 10, -15,
- -13, 1, 6, 14, 15, -17, -13, 4, -5, 10, 7, -6, -8, -3, -4, 12 },
- { 25, -1, 7, -5, -7, 11, 1, 17, 13, -15, -14, -4, 5, 3, 8, -3,
- -2, 2, 0, 6, 16, -12, -6, -4, 4, -3, 7, -10, -3, -7, -13, 7 },
- { -8, 10, -3, -13, 5, 2, 4, 9, 9, -17, -13, 2, 11, 1, 6, -4,
- 8, -10, 4, 1, 19, -15, -4, 12, 31, 7, -5, -17, -4, 9, -2, 7 },
- { 14, -6, -6, -6, -14, 13, 17, -5, 4, -14, -9, 7, 7, -9, 3, -16,
- -15, 11, 11, 6, 4, -11, -19, 3, 5, 8, 13, -14, -14, 3, -4, 12 },
- { -2, -4, 10, -4, -7, -1, 27, 5, 2, -16, -18, 4, 12, -2, -3, -2,
- -1, 1, -8, -12, 3, -4, 8, 15, 2, 4, 9, -13, -14, 9, -7, 5 },
- { 4, 2, -10, -5, -7, 2, 1, 4, -1, -6, -15, 6, 1, 10, 5, -10,
- -9, -1, 13, -3, 5, -21, -11, 8, 8, 5, 27, -21, -18, -5, -1, 15 },
- { 11, 1, -16, -8, -11, 0, 5, -8, -12, -13, -17, 22, 4, -6, -1, -18,
- -10, 0, 19, 2, -2, -8, -7, -3, 2, -2, -9, -17, -5, 4, 4, 10 },
- { 8, -6, -19, -5, -4, 12, 14, 15, 10, -9, -1, -9, 19, 12, 0, -1,
- 2, 4, 7, 9, 16, -16, -14, 9, -4, 3, 1, 0, -2, 10, -1, -1 },
- { 12, -8, 12, -9, 0, 25, 7, 9, 2, -31, -9, -4, 15, 4, -5, 1,
- -10, 11, 8, 10, 0, -6, 5, 11, -1, -6, 4, -10, -9, 6, 4, 5 },
- { 14, 6, -17, -2, 17, 12, -9, 2, 0, -25, -14, 5, 20, 14, 8, -20,
- 5, 2, -2, -3, 9, -13, -3, -1, -6, 3, 7, -6, 0, 2, 3, 1 },
- { 8, 4, -15, -3, 10, 18, -4, 13, 8, -22, -10, 9, 19, -15, 7, -5,
- -13, 12, -4, 9, 2, -9, -6, 0, 2, 1, -9, -6, 6, 1, -1, 11 },
- { 4, 1, 4, -5, -10, 18, 7, 2, -4, -9, -11, 0, 32, -7, 4, -16,
- -1, 0, 6, 3, 6, -3, -14, 16, 9, -2, 7, -1, 0, -5, 5, -3 },
- { -3, 2, 3, -8, -6, 4, 6, 2, 4, -12, -15, 2, 8, 8, 9, -3,
- -18, 6, 34, 11, 12, -15, -1, 2, 9, 2, -4, -4, 2, 4, 2, -3 },
- { 18, -6, -12, -8, -1, 15, 20, -4, -1, -11, -5, 6, 6, -11, -15, -7,
- 3, 7, 10, 2, 8, -10, -5, 8, 15, -5, 5, -17, -13, 13, 11, 7 },
- { 8, -4, -6, -1, -14, -3, 6, -2, 1, -5, -1, 10, 10, -15, 5, 0,
- -10, -4, -3, 7, -4, -19, -15, 27, 11, 18, 3, -19, -2, 6, 0, 12 },
- { 12, 0, -5, 0, 4, -5, 1, 5, 10, -7, -11, 21, 29, 1, -2, 1,
- -4, -11, -1, 13, 11, -20, -1, 4, 4, 4, -5, 6, -13, -2, 11, 9 },
- { 2, -7, -7, -3, -10, -1, 20, 12, 1, -19, -19, -1, 5, 4, -7, -25,
- 14, 1, -3, 2, 12, -4, -3, -3, -2, 6, 1, 0, 3, 2, 5, -1 },
- { 12, -8, 3, -12, -10, 10, 13, 0, 23, -14, -18, 10, 0, 15, 3, -12,
- -3, -5, 5, -4, 2, -14, -10, 8, 2, 9, -1, -11, -3, 5, 13, 2 },
- { 9, -6, 7, -7, -30, 17, 6, 13, 1, -14, 0, -1, 6, -9, 8, 3,
- -4, 0, -1, -7, -5, -13, -19, -3, -4, 4, -6, -2, -13, 1, -2, 3 },
- { 10, 1, 3, -18, -26, 17, 4, -16, 4, -3, -13, -4, -6, -11, -4, -21,
- 7, 8, 2, 5, 13, -6, 1, 5, 8, 7, 9, -6, -6, 1, -1, 2 },
- { -3, -1, 0, -2, -2, 0, -1, 3, 4, -14, -8, -9, 13, 2, 50, -23,
- -8, 8, 7, 11, 16, 3, -7, 0, -2, 6, 5, -1, 1, -2, 4, 3 },
- { 1, 3, 1, 1, -6, 3, 6, 6, 2, -2, -3, 10, 2, -8, -5, -5,
- 5, 4, 4, -2, 10, -8, -40, -1, 21, 8, 3, -4, -1, 13, 4, 7 },
- { 2, 0, -4, -8, 5, 2, 7, -5, 5, -8, -4, -1, 12, 2, 12, -13,
- -9, 0, 1, -12, 9, -43, 1, -5, 12, 1, 3, 6, 1, -1, 3, -2 },
- { 6, -2, -1, 1, 0, 4, 8, 14, 4, -7, -23, -5, 23, -17, -6, -15,
- -8, 7, 10, -1, 7, -16, 4, -6, 2, 3, -3, -3, -1, 8, -1, 4 },
- { 10, 4, -4, 1, 7, -3, 2, 11, 4, -6, -3, 8, 5, 4, 1, -45,
- -6, -4, 4, 2, 1, -14, -10, 1, 1, 6, 2, -8, -1, -3, 3, 3 },
- { 1, -1, 2, -3, -8, 9, 3, 3, -2, -5, -8, 8, 7, -7, -4, -6,
- 5, -9, 11, -2, 46, -5, -1, 9, -2, 0, 3, -5, -3, -5, 7, 0 },
- { -4, 1, -2, -1, -11, 11, 8, -3, -2, -10, 0, 4, 9, 9, -17, -17,
- -34, -4, -5, -7, -3, -12, -3, 11, 18, 3, -2, -5, -18, -5, -3, 6 },
- { 7, -5, -3, 1, -4, -3, -5, -1, 2, 5, -2, 3, -10, 12, -18, -5,
- -10, 12, -9, 4, -6, 2, 0, 16, -17, 15, 14, -12, -10, -2, -9, -1 },
- { 4, -5, -3, -5, -3, -1, 7, 18, -7, 12, 3, 5, -8, -4, -20, 1,
- -25, 1, -8, 13, -10, 8, -19, -1, -8, 10, 6, -9, -1, 0, 12, 4 },
- { -4, 5, 0, -1, 2, 5, -8, -2, -6, 4, -8, 9, 3, 2, -7, 4,
- -25, 13, -23, 10, 14, 15, -11, 3, -18, 4, 16, -4, 1, -10, -10, 3 },
- { 5, -3, -1, -3, 4, 1, -3, -4, -5, 1, -12, 14, -7, 11, -15, 6,
- -6, 24, -4, 13, -1, 15, -13, 8, 3, 7, -5, 2, 2, 0, 3, -7 },
- { -3, 1, 0, 8, 6, -1, 6, 5, -5, -2, -12, 4, 0, -2, -3, 5,
- -6, 0, -8, 9, -10, 4, -28, 12, -20, 11, -13, 7, -18, 1, -11, 1 },
- { 1, -4, -15, 5, 0, -13, -5, 13, -11, 4, -4, -5, 5, -14, -16, 0,
- -14, 5, -20, 12, 10, -7, -5, 6, 6, 22, 6, -4, -2, 3, 8, 11 },
- { 13, -11, -2, 16, 16, -7, 0, 20, -7, -1, 0, 5, -9, 12, -2, -5,
- -22, 5, -10, 12, -6, 11, 9, 21, -8, 15, 4, 0, -8, -4, -4, 10 },
- { 18, -4, -13, 0, 1, -15, -1, -3, 2, 10, -1, 6, 1, -4, -20, -5,
- -8, 6, -8, 17, -5, 5, -10, 8, -22, 6, -5, -2, 8, -17, 8, 2 },
- { 1, -2, -9, 6, -31, -8, -8, 8, 0, 5, -9, -4, 2, 3, -12, 11,
- -18, 10, -5, 3, -11, 13, -6, 11, -3, 12, -7, 3, -9, -1, 2, 11 },
- { -9, -6, 21, -8, -15, 4, -11, 12, -11, 17, -1, 2, -6, 0, -15, 13,
- -12, 19, 0, 2, -6, -3, -9, 10, 3, 17, -2, 5, -10, -3, 0, 1 },
- { 4, -6, 5, -10, 1, -5, 1, 0, 0, 0, 2, 7, -2, 2, -2, 0,
- -4, 3, -4, 1, -12, 6, -49, 16, -10, 13, 0, -2, 8, 6, 1, 8 },
- { 5, -8, -7, 9, 13, -5, 7, 0, 10, 11, -4, -3, -1, 13, -14, 6,
- -15, -6, -14, 16, 15, 1, -18, -4, -20, 20, -7, -1, -9, -2, -10, 10 },
- { -12, 4, 0, 10, 0, 3, 8, 4, -27, -1, -2, 19, -4, 2, -13, 3,
- 1, 9, -12, 1, -22, 19, -5, 4, -9, 12, 2, -9, -8, 11, -3, 7 },
- { 4, -5, 11, -6, 17, -17, 5, -4, -2, -6, 1, -5, 2, 4, -14, 6,
- -20, 19, -20, 12, -21, 5, -14, 13, -2, 11, 4, -3, 0, -10, -4, -2 },
- { -2, -1, -3, 8, -9, -7, -22, -3, -24, 13, -2, 10, -15, 5, -9, 4,
- -7, 0, -5, 15, -8, 11, -13, 6, -4, 19, -8, 12, -4, 6, 9, 7 },
- { 2, -3, 2, -1, 0, 3, 1, 2, 1, -4, -2, -3, 1, 5, -12, 6,
- -16, 14, -23, 10, -14, 17, -15, 16, -2, 9, -25, 9, -10, 16, 4, 9 },
- { -3, 7, -8, -3, 2, 2, -4, -8, -9, 10, 3, -11, 25, -10, -28, 27,
- -9, 7, -13, 9, -2, 4, -12, -8, -14, 6, 7, -10, 3, 3, -3, 5 },
- { -8, -3, 1, -10, 8, -3, -9, -4, 13, 7, 2, 4, -10, 4, 3, 7,
- -18, 2, -22, 15, 4, 20, -7, 5, -6, 13, -1, 4, -7, -6, 6, 13 },
- { -2, 3, 0, 2, -4, -2, 0, 0, 1, 2, -2, -5, 0, 1, -4, 0,
- -2, -3, 1, 2, -1, 2, -8, -1, -24, 68, -3, 8, 3, 3, -1, -1 },
- { -15, -2, -9, -7, -1, 8, -14, 8, 3, 6, 0, -1, -8, 8, -23, 2,
- -14, 17, -15, 8, -4, 7, -18, 0, -8, -3, -1, -4, -10, 4, -1, 4 },
- { 8, 0, 2, -7, 0, 5, 1, 3, -11, 4, -8, 14, 3, 20, 1, 26,
- -11, 13, -13, 20, -2, 0, -8, 2, -6, 6, -1, 9, 3, -6, -3, 10 },
- { 5, 0, -1, -7, 10, 1, -3, 5, 4, 7, -5, -1, -3, -1, 12, -3,
- -15, 7, -9, 22, -19, 8, -9, 4, -23, 13, -14, 6, -6, -14, -4, 7 },
- { 14, -5, -8, -10, 25, 3, -23, -7, -28, 0, -1, -9, 4, 1, -13, 20,
- -8, 10, -16, 8, 12, -13, -21, 5, -13, 11, -2, 1, 12, -7, 2, -10 },
- { -5, -4, 9, 5, -6, 35, -7, 8, 15, 2, -1, -9, -6, 2, -18, 7,
- -15, 6, -3, 2, 8, 12, -30, 7, -4, 20, 2, 6, 13, -6, -4, 0 },
- { 1, 8, -9, 9, -5, 12, -9, 16, -9, 16, -17, 14, -13, 15, -18, 14,
- -15, 17, -12, 14, -13, 7, -16, 13, -9, 5, -11, 10, -9, 6, -12, 13 },
- { -10, -4, 5, 3, 1, 6, 8, -14, -5, 15, 7, 4, 8, 7, -22, 8,
- -7, -8, -15, 26, 1, 13, -3, 17, -5, 9, -2, 4, -6, 3, -8, 9 },
- { 8, -3, 2, 3, 3, 1, -2, -1, -11, 8, -4, 0, -6, -5, -1, 13,
- -37, 9, 1, -6, -10, -2, -10, 11, 8, 13, -3, -2, -6, 8, -4, 13 },
- { 3, 2, -3, -4, -4, 7, -8, 9, -8, 9, -20, 12, -19, 15, -18, 17,
- -15, 7, -1, 20, -11, 6, -6, 3, 1, 9, 2, -14, -2, -2, 2, 1 },
- { -7, 1, -1, -3, -6, 4, 4, -3, 3, -1, 5, -4, 3, 2, -1, 9,
- -59, 5, -4, 30, 3, 3, -2, -3, -1, 2, 2, 1, -1, -1, -2, 1 },
- { 0, -3, 2, 0, -1, -8, 0, 2, -3, 4, -4, 1, 10, 6, -6, 8,
- -7, 4, 10, 11, -41, 27, -20, 3, -3, 8, 1, 11, -5, -8, 0, 4 },
- { 5, 1, 4, -2, 1, 2, -1, 6, -7, 2, 11, 4, 0, 0, -8, 7,
- -10, 0, 0, 8, 2, 10, -1, 1, -2, 44, -2, -21, -12, -3, -1, 2 },
- { -4, 4, -2, -2, 6, -8, 2, 1, -10, 14, 8, 6, 5, 1, -2, 4,
- -13, 4, 2, 5, 10, -2, -21, 32, -3, 18, 9, -6, -9, -9, 10, 2 },
- { 9, -16, -6, -2, 1, 4, 22, 2, -2, 1, -3, -2, -9, 3, 16, 19,
- -24, -6, -6, -5, -8, -7, 8, -7, -1, -12, 5, -3, 0, 4, 2, -3 },
- { 10, 3, -16, -4, -1, 13, 4, 4, 1, -3, 1, -6, -14, 18, 3, 8,
- -8, -28, -16, 4, 4, 2, 12, 7, 9, -4, -4, 5, -1, -1, 2, 2 },
- { -5, -13, -22, -3, -8, 21, -2, -9, 21, -4, -9, 5, -8, 15, 5, 1,
- -5, -9, -7, -2, -5, -5, -1, -5, -5, -5, 3, 10, -4, 0, -7, -2 },
- { 5, -10, -18, 2, 20, 4, 13, -10, 8, -15, -11, -3, -1, 16, 10, 9,
- -8, 6, 7, -5, 6, 11, 5, 17, -4, 7, -11, 5, -3, -6, 2, 1 },
- { 3, -5, -19, 1, 1, -3, -2, -25, -11, -17, 0, -13, -4, 10, 10, 2,
- -5, 4, 0, 3, -3, -5, -10, -2, 13, -22, 0, 3, -11, -5, 7, -1 },
- { 12, -14, -29, 6, -1, 10, 7, -17, -12, 14, 3, 9, -9, 9, 7, 6,
- -3, -13, 0, 5, 3, -1, -6, -1, 0, 2, 4, -12, -5, -1, 2, 11 },
- { 12, -15, -7, -2, -12, 17, 20, -16, -2, -12, -6, 15, -6, 12, 11, 9,
- 7, -6, 7, -4, -19, 6, 2, 2, 3, -11, -10, -4, -5, -3, 3, 2 },
- { 11, -22, -6, 0, 8, 18, 3, -11, -4, -7, -15, -17, -12, 6, 16, 4,
- -9, 4, -5, 3, 6, -16, 10, -7, -7, -3, 5, 0, 1, -15, -4, 5 },
- { 12, -22, -16, 5, -6, 8, 12, -4, -9, -17, -11, 3, 5, 8, -17, 0,
- 11, -4, -13, -6, 2, -1, -1, 3, 3, -11, -12, -1, 1, 1, 12, -2 },
- { 8, -10, -33, -5, -3, -6, 1, -7, -8, -4, -6, -1, 5, -4, -6, -12,
- -16, -8, 11, 8, -14, 7, 12, 11, 4, -14, -3, 6, -7, -5, -3, 3 },
- { 0, -8, -7, 2, -4, 24, 2, -9, -11, -3, -7, 11, -12, 17, 1, -1,
- 3, -5, -7, 12, 4, 11, 0, 3, 2, -18, -3, 4, 7, -6, 3, 15 },
- { 10, -15, -16, -2, -4, -9, 7, -15, -6, 2, -16, 13, -8, 7, 19, -21,
- -4, -12, -9, -3, -3, 6, 11, -3, -1, -19, 3, -7, -9, -4, 3, -6 },
- { -5, -10, -21, 0, -3, -7, 18, -21, 15, -5, -12, -4, -13, 2, 6, -9,
- -9, -11, -4, 13, -3, 6, 4, -1, 7, -9, -4, 9, 5, 2, 6, 3 },
- { 15, -1, -27, -2, 10, 3, 7, -8, 9, -2, 7, 1, -2, -5, 18, 9,
- -11, -17, -2, 7, -9, 11, 10, 0, -8, 6, -16, -3, 2, -7, 3, 11 },
- { 4, -9, -39, 19, 6, -13, 13, -5, -5, -15, -2, 9, 0, 4, 14, 6,
- -10, -4, -5, 2, -4, -2, 5, -11, 3, 3, -2, -2, -7, 9, 7, -10 },
- { 5, -11, -8, 10, -2, 12, 16, 0, 12, -2, -6, 8, 14, 8, 7, 1,
- 18, -30, 4, 10, -4, -6, 2, -11, 9, -10, -8, 5, 0, 0, -7, 6 },
- { -1, -16, -10, 11, 0, 13, 12, -4, -4, -5, -21, 12, 4, 13, 14, -7,
- 6, -16, -13, 8, 2, 9, 15, -12, 1, -9, -22, 10, -9, 9, 9, -7 },
- { 4, -12, -27, 1, -2, 11, 15, 3, 14, -14, -9, 0, -9, 16, 22, 10,
- 16, -10, 5, -5, -9, 1, 1, 6, 6, -4, 2, -17, -5, -6, -15, -1 },
- { 7, -12, -17, 1, -9, 5, 20, -7, 3, 23, -8, -8, -8, -1, 13, 17,
- -7, -13, 4, -4, 7, 14, 8, 11, -3, -3, 4, 0, 4, 6, -1, -9 },
- { 7, -15, -15, -4, 10, 12, 3, -13, 6, 14, 9, -8, -15, 14, 23, -5,
- -10, -5, 1, 15, -10, -7, 1, 9, 4, -13, -10, 10, 7, -3, 2, 3 },
- { 4, -10, -14, 0, 3, 4, 0, -9, -3, -4, -11, 2, -17, 8, 2, 15,
- 6, -12, -12, 15, -5, 17, 18, 3, -3, -3, -4, -6, -8, 13, 4, 10 },
- { -2, -18, -26, 10, -4, 10, 13, 4, -4, -16, -7, -17, -3, 5, -4, 2,
- -15, -10, -1, -8, -7, -3, 2, 2, 8, -10, -7, 2, 2, -4, 4, -1 },
- { 4, -19, -5, -1, -1, -6, 2, -8, 10, -16, -28, -6, 8, -1, 11, 28,
- 2, -10, -4, 6, -6, 6, 11, 15, -4, -2, 7, 3, 7, -7, 4, 1 },
- { -3, -6, -10, -5, 13, 18, 10, -15, -5, -3, -13, 5, 1, 2, 18, -5,
- -10, -10, -7, 4, 2, 1, 5, 4, 2, 5, 4, 8, -9, -17, 7, 7 },
- { 20, -12, -2, -4, 5, 14, 7, -11, -1, -16, -6, -4, -11, 17, 14, 0,
- -8, -10, -8, 10, 3, 5, 10, -16, 3, -8, -14, 10, 3, 9, 0, 3 },
- { 12, -10, -36, 0, 7, 15, 2, -16, 2, -1, 0, -1, 5, 4, 5, -3,
- 1, -10, 5, -1, -15, -3, -12, 12, 2, 5, -1, 5, 6, -3, -2, 2 },
- { 17, -15, -31, 23, -4, 15, -2, -3, 6, -7, -5, 1, -12, 4, 6, 8,
- -10, 8, 3, 5, -4, 1, 5, 3, -1, -4, -3, 1, 10, -4, -2, -2 },
- { 6, -18, -5, 12, 10, 12, 14, -11, 15, 2, -9, -6, -5, -2, -9, 4,
- -5, -28, -4, 14, 0, -16, 9, 14, -1, 3, -4, -4, 2, 1, 0, 4 },
- { -5, -14, -31, 8, 16, 7, 13, -13, 5, 6, -16, 10, -5, 2, -2, 2,
- 14, -5, 8, -5, 7, -16, 6, -13, -5, 0, -5, 8, -3, -1, 4, 3 },
- { 1, -2, -1, 0, 6, 5, 2, -4, -3, -1, 0, 1, 4, 2, 43, 28,
- -12, -35, -2, -2, -7, -1, 0, 2, -1, -2, -2, 1, -4, 0, -2, 3 },
- { 2, -9, -22, 12, 3, 3, -7, -4, -19, -22, -14, -4, -1, 21, 9, -3,
- -15, -16, -13, 1, -11, 4, -9, 1, -7, -1, -1, 0, -2, 9, -13, -3 },
- { -1, -3, -23, 0, 2, 12, 3, -9, -4, 7, 3, 9, -10, 1, 27, 28,
- 0, 9, -15, -2, -2, 1, 6, 8, -8, 7, -3, 20, 0, 0, -1, -6 },
- { -1, 11, 8, -2, 1, 5, -6, -1, 4, 2, -4, 0, -1, -5, 4, -6,
- -10, -12, 19, 1, -7, 9, -8, -9, -16, -11, -2, 12, 14, 4, 4, 34 },
- { 17, 7, -6, 1, 4, -10, -5, 4, -11, 3, -18, 4, 14, -13, -3, 1,
- 0, 0, -11, 0, 7, -17, -4, 4, -11, -6, -8, 18, 0, 0, 0, 26 },
- { -6, -7, -1, -1, 11, -8, 1, 3, 2, 11, -6, -6, 10, -3, 1, -3,
- 7, 4, -12, -8, 0, -9, 8, -22, -5, 0, -6, 22, -2, 11, -13, 24 },
- { -3, 4, 0, 3, 9, 10, -1, 3, -9, -12, 1, -5, 18, 0, -3, 8,
- 25, 15, -8, 2, 2, -2, 4, 8, 9, -1, -5, 10, -3, 1, -1, 23 },
- { -5, 2, -9, -1, -3, 0, 3, -1, -10, -4, 0, -13, 16, 9, -1, -14,
- 2, 6, -2, -6, -5, -2, -7, 7, 5, 3, 11, -2, -14, 0, -9, 30 },
- { 4, 6, 6, 5, -3, -1, 4, 5, 10, 0, 5, -4, 7, -11, 14, 14,
- 7, 34, -9, 0, -10, 22, -7, -1, 7, -9, 2, -8, 0, -7, -5, 29 },
- { -4, 3, -1, -4, -3, 5, 1, -4, 0, 2, 4, 2, 1, -1, -10, 1,
- 6, -6, -4, 1, 4, -3, -3, -5, 0, 3, 7, -12, 0, -2, -10, 55 },
- { 5, 9, -1, 0, 4, 9, -21, -9, 4, 2, 6, -7, 11, -7, 1, -5,
- 0, -4, 2, -3, -13, -8, 0, -9, -4, 2, 16, -2, -15, -7, -11, 31 },
- { 8, 2, -1, 0, 3, -5, -5, 5, 1, -1, -9, 1, 0, -6, -2, -1,
- 5, 2, 0, 0, 12, 20, -19, 1, 8, -12, -11, 0, 6, -5, 2, 31 },
- { -1, -1, -2, 1, -1, 3, -9, -5, 8, -2, 5, -1, 0, -2, 4, -2,
- -3, -12, 0, -2, 3, 0, 9, 4, -1, 21, -8, 3, -4, 9, -6, 30 },
- { -4, 0, -7, 17, 10, -12, -2, -10, -12, -3, 10, 0, 11, -4, -13, -3,
- 5, 6, 10, 7, -8, 0, -7, -13, 1, 0, -2, 7, -12, 4, -3, 24 },
- { -13, 9, 4, -2, 2, -4, -14, -1, -3, -5, -10, 4, 13, -2, 5, 13,
- 8, 3, -2, 1, 5, -6, 7, -18, -10, 1, -1, 5, 4, 1, 0, 25 },
- { -5, -1, 18, 12, 8, 8, -16, -1, 1, 1, 1, -4, -5, 3, 3, 4,
- 4, -11, -12, -16, -6, 2, 12, -13, 0, 9, 7, 9, -9, 0, -10, 24 },
- { -4, 1, -3, 0, 2, -4, 4, 1, 5, 0, -3, 2, -3, -2, 2, -1,
- 1, 4, -1, -2, -2, 1, -1, -1, -4, -1, -4, -2, -6, 6, 12, 69 },
- { 8, 5, 11, 0, -15, -4, 13, 6, 0, -4, 9, 1, -5, -3, 15, 0,
- 1, 6, -5, 0, 1, 6, 5, 8, 0, 7, 1, -1, -4, -11, -9, 41 },
- { -4, -9, 32, -6, 0, 7, -4, 6, -6, 1, -6, -2, 4, -8, -5, -3,
- -16, -1, -2, -6, 1, 15, 0, 21, 3, -3, -4, 3, -12, 16, 2, 27 },
- { -6, -5, 1, -9, -5, 3, 7, -3, 5, 5, 14, 13, 20, -7, -1, 12,
- -1, 10, -11, -11, -7, -4, -14, 7, -14, 13, 22, 18, -1, 0, 14, 28 },
- { -8, 3, -2, 0, 5, 6, -1, -4, 1, 3, -7, 3, 1, -15, 4, -9,
- 22, -10, -9, -4, 1, 8, -4, 9, -15, 2, -6, -4, -16, 12, -10, 23 },
- { 0, 0, 2, 0, -1, 3, -3, -1, 3, -5, 7, 1, 5, -5, -8, 1,
- 13, -15, -5, -7, 12, -6, -2, 3, 10, -5, -8, 17, -5, -11, -14, 23 },
- { -7, -4, 6, -4, 5, -6, -5, 2, -4, 11, 9, -4, 2, -2, -4, 6,
- 15, 3, -3, 18, -15, -2, -6, 3, 3, -20, 17, 11, -4, 2, 3, 29 },
- { 6, 1, -6, 2, 3, 0, 0, -3, 3, 3, -1, 3, -4, -6, -6, -7,
- -3, -2, -7, -2, -4, 5, 3, -5, -20, -13, -4, 10, -14, -29, 14, 37 },
- { 3, 4, 3, -6, -4, 5, 0, 3, 2, 3, 0, -2, 4, 0, -3, -5,
- -4, 4, -4, 4, 4, 3, 1, -4, -4, -9, -14, 20, -30, 3, -18, 33 },
- { 0, 2, 5, -2, -4, -2, -1, 2, -6, -3, -2, -2, 2, -5, -1, 4,
- 3, 2, -3, 0, -1, -1, -10, -7, 2, -4, -18, 2, -37, -1, 12, 40 },
- { -7, 2, -1, 0, -2, 4, -8, 1, -4, 12, 7, 4, 15, -7, 1, -9,
- 18, 0, 12, -17, -3, -1, 0, 0, 0, 2, -6, 0, -4, -3, -1, 26 },
- { -6, 4, 8, -5, -6, -2, 2, -1, 1, -1, -15, 8, 7, -1, -17, -4,
- 1, 5, 6, -11, -6, 14, 17, -5, -15, 11, 8, 0, -3, -15, -6, 28 },
- { -1, 0, 0, 0, 1, 0, -1, 0, 1, 3, 2, -2, 3, -1, -1, 2,
- 2, -1, -1, -7, 1, 2, -9, 0, -1, -4, -18, 7, -10, 49, -13, 32 },
- { -1, -3, 4, 1, 2, -5, 1, -7, -1, 5, -9, 4, 4, 25, 1, -1,
- 2, -5, 2, -7, 17, -2, 10, -5, 0, 2, -15, 3, -9, 7, -9, 30 },
- { -5, -1, 0, 2, 1, -1, 2, 5, -33, 3, -5, 14, 11, 7, 5, -3,
- 2, -8, -4, -2, -7, -6, 4, -8, -1, -8, 2, -2, -8, -1, -4, 27 },
- { -1, 0, -1, -2, 1, -1, -2, -1, 2, 0, 1, 2, 2, 4, 1, 3,
- 4, 2, 1, -7, -4, 1, -3, -4, -35, -25, 17, 10, -3, -26, -7, 32 },
- { -5, 1, 6, -2, 6, 6, -9, 3, -1, -4, 5, -4, -2, -2, -9, 2,
- -5, 2, 2, 4, 3, 5, -5, -16, -31, -12, -11, 2, -19, 20, -2, 21 },
- { -5, 2, 7, -7, -7, 5, -7, 2, 0, 0, -4, 3, -1, 0, -1, -2,
- 0, -3, 5, -11, -8, -3, -7, -7, 28, -11, -7, 0, -16, -11, -4, 29 },
- { 2, 1, -3, -2, -1, 3, 4, 0, 1, 0, -1, -5, 4, -5, -12, 2,
- -2, -5, -22, -2, -1, 11, 8, -7, -12, 0, -34, 6, -5, 11, -8, 19 },
- { -1, -3, 5, 11, 18, -2, -2, -5, -2, 4, -1, 8, 5, -6, 1, -1,
- 2, 8, 4, -5, -8, -2, 5, -18, 7, 12, 7, 19, -18, 2, -6, -13 },
- { 9, 0, 0, 5, 4, 3, -6, 4, 1, -4, 5, -1, -4, 8, 8, 6,
- -8, -6, 0, 6, -3, 3, 5, -3, 17, 31, 16, 10, -13, 0, -9, -19 },
- { 12, -10, 2, -2, -2, -1, -3, 6, -12, -5, -2, 14, -16, 4, 12, 12,
- 17, 4, 7, -16, 7, -6, 11, 7, 7, 2, -25, 23, -24, 5, -7, -9 },
- { 10, 4, 13, 10, 10, 3, -6, 3, 3, 2, -1, -6, 8, 4, 10, 0,
- 1, 2, -4, 2, -3, -8, 0, -1, 9, 9, -10, -3, -29, 1, -1, -27 },
- { 2, 2, 0, 7, 9, -2, -10, -1, -1, 1, -9, -5, 8, 4, 1, 2,
- -10, 1, 13, 12, -3, 15, -9, 2, -7, 1, -10, 23, -20, -18, -9, -15 },
- { -3, -5, -1, 8, 0, -5, -1, 4, 7, -1, -7, 2, -8, -5, 11, 7,
- -6, 3, -3, -9, 7, 9, -22, 1, 6, -4, 14, 27, -25, -14, 3, -5 },
- { 1, 3, 8, 4, 7, 6, 12, -17, -15, 1, -8, -10, 7, -14, -8, 6,
- -2, -2, -11, -11, -7, 13, -2, -2, 4, 5, -5, 13, -23, -6, -17, -8 },
- { -5, 4, -14, -5, -4, -5, 6, 5, -8, -5, -2, -11, -7, -12, 3, -11,
- 2, -6, 4, -10, -5, -7, 14, 5, 23, 11, 7, 12, -16, -6, -4, -16 },
- { 5, 6, 2, 5, -2, -5, -5, -6, -5, -19, -13, -1, -3, -13, 5, 0,
- 6, -2, -2, -6, -7, -7, -1, -9, 4, 14, 17, -12, -27, 3, 0, -1 },
- { 7, -1, 9, -10, 8, 2, -7, -2, 5, 2, -3, -7, 3, 0, 6, 4,
- 12, 5, 11, 14, -13, -1, 8, 1, 13, 9, 12, 12, -18, -14, -11, -16 },
- { -7, -5, -6, -5, 0, -1, -3, 2, 2, 1, 4, 9, 2, 3, 5, -2,
- 2, 1, 8, 0, 3, 0, -2, 2, 1, 7, 29, 0, -36, -5, -9, -21 },
- { 14, -6, -9, 0, -1, -8, -8, -11, 2, 2, -9, -12, 12, -4, 5, 3,
- -5, -9, 11, -1, -3, 12, -21, -3, 12, 5, 3, 11, -18, -15, 1, -2 },
- { -1, 3, -9, -3, 7, -7, -18, 2, 4, 12, -10, 2, 8, -3, -14, 13,
- 17, -5, 5, -9, 13, -3, -7, -18, 17, -2, 5, 7, -20, -3, -6, -11 },
- { -3, 3, 3, -1, 1, -6, -5, 1, 5, -3, -14, -6, -5, -8, 14, -6,
- 7, -1, 5, 1, 15, -1, -7, -4, 6, -11, 9, -2, -37, 16, -7, -3 },
- { -1, 0, 6, 1, -3, -9, 0, 11, -8, 2, -2, 0, 5, 2, 12, -10,
- 10, 13, 2, 7, -6, 2, -10, -10, 21, -5, 5, 5, -12, -23, 3, -14 },
- { 6, 0, -2, 1, 0, 1, 0, -4, 1, 1, 8, -2, 2, -5, -2, 1,
- 8, -4, -1, -1, 4, -1, 2, 6, 32, 1, -5, -20, -40, -4, -18, -14 },
- { 2, 2, -7, -2, 4, 4, -1, 2, 0, -2, -4, -7, 3, 5, 0, -5,
- 1, 2, -6, 4, -1, -2, -1, -15, 8, 3, 9, 46, -7, -18, 6, -11 },
- { 5, 5, 16, 21, 3, -11, -4, 11, -12, 2, 4, -12, -1, 11, 8, 1,
- -4, 11, -11, -21, 1, 1, -11, 3, 13, 1, 5, 12, -25, 1, -3, -2 },
- { 1, 6, -7, 4, 2, 3, 1, -5, 8, 9, -15, 3, -3, -14, 17, 4,
- -8, 14, -2, -8, -4, 5, 8, -7, 8, 9, 7, 6, -29, -17, 8, 4 },
- { -7, -7, 4, 0, 13, 1, 0, 4, 4, -16, -10, -7, 5, 9, -15, -10,
- -10, 8, -4, -1, -11, -1, -10, -15, 3, 3, 14, 10, -19, 2, -18, -12 },
- { -4, 0, 2, 0, 5, -2, -9, 0, 4, -4, 2, -1, -2, 2, -4, 9,
- 2, -6, -4, -2, -1, -3, -3, -1, 2, 5, -1, 11, -24, -44, -9, -15 },
- { -1, -10, 6, 21, 11, 15, -7, 10, -14, -9, -8, -8, 4, 6, 19, 1,
- -6, 1, -5, -17, -8, -10, 9, 5, 11, 18, -1, 10, -16, -7, -9, -8 },
- { 3, -5, 0, 0, -2, -2, -6, 4, -4, 1, -1, 0, 7, -3, 4, -4,
- -7, 7, 17, -20, 6, 4, 1, -6, -12, 31, 13, 19, -14, -10, -7, -2 },
- { -2, 6, -10, 3, 9, 6, -14, 15, 2, -5, 2, -11, 9, -8, 4, 6,
- 20, -15, -3, -3, -1, 32, -21, 6, 1, 9, 11, 17, -19, 6, -1, -3 },
- { 8, 10, -2, 0, -8, -16, 7, 7, 6, 10, 4, -14, 7, -6, 21, -7,
- 10, 5, 5, 0, -7, 2, -6, 0, -7, 11, -9, 15, -20, -7, -11, 2 },
- { 0, -7, 5, 2, 0, -3, -6, -4, -2, -1, -4, -5, -13, -1, 27, -9,
- -6, -11, -7, 1, 11, -4, -4, -14, -2, 11, 6, 10, -19, -6, -15, 2 },
- { 0, 7, -1, 2, -7, -15, -2, -3, 13, -5, -5, 12, 3, 0, 5, -5,
- -22, 2, 7, 22, 13, 0, -1, 2, 3, 2, -7, 7, -27, -4, -4, -12 },
- { 11, 1, -16, 6, -15, 1, 3, 2, 0, 2, -3, 2, 5, -2, -5, 9,
- 5, -3, 3, -2, -11, 3, 9, 6, 9, 3, -1, 12, -41, 8, -6, 9 },
- { 3, -7, 3, 2, 5, 5, 0, -1, 1, 3, -5, -2, -13, 7, -1, -2,
- -2, -6, 4, -6, 0, 2, -2, 2, 4, 1, -4, 1, -47, -21, 7, -6 },
- { 3, 16, -7, 13, -4, -2, 10, -3, -1, 18, -13, 7, -13, -4, 8, 4,
- 8, 9, -5, 13, 8, -5, 3, -6, 7, 18, -8, 10, -25, -3, -12, -12 },
- { 1, -1, -1, 0, 2, 5, -5, -3, 0, -5, -1, 0, -4, -8, -2, 3,
- 2, -2, -17, -6, -4, 1, 33, -6, -20, -6, 8, 31, -26, -8, -1, -4 },
- { 3, -3, -3, 5, -3, -2, 1, 7, 0, 3, 6, 3, 6, -2, 9, 15,
- -10, -3, -15, -5, -3, -4, -6, -30, 17, -8, -2, 2, -20, 0, -8, -2 },
- { -2, -1, -1, -1, 3, -5, -2, -3, 4, -2, 0, 5, 8, -3, 1, -4,
- 1, 1, -3, 4, 4, -14, 3, 11, -5, 3, -3, 7, -3, 13, 23, -16 },
- { 2, -6, 1, -3, 5, 0, -6, -11, -7, -4, -1, 2, -7, -1, -1, 7,
- 1, -2, 6, 12, -6, 8, -13, 17, 25, -23, -19, -7, -12, 9, 16, -17 },
- { 9, 4, 4, 4, -3, -1, 6, -2, -3, 0, 13, -4, -7, 14, 1, -7,
- 0, -5, 3, -19, -3, 5, 3, 9, -1, 9, -13, 13, -17, 4, 21, -26 },
- { 0, -5, 0, 0, -4, -5, 2, -6, -4, 5, -7, 10, 0, 2, 0, -2,
- -2, 0, 4, -6, 7, -2, 6, 5, -5, 2, -12, 1, -29, 29, 27, 12 },
- { 9, -10, -22, 6, -1, -1, 9, -14, -12, -2, 1, -1, 10, -11, -16, 0,
- 3, 11, 13, -14, -9, -2, -1, 6, 4, -14, 0, -10, -2, 16, 17, -11 },
- { 2, 0, -1, -2, 4, 3, -6, -2, 1, -1, 1, 3, -4, 1, 3, -4,
- -1, -1, 4, -1, 1, 0, 1, 6, -5, -7, 2, 1, -47, -3, 50, -17 },
- { 8, -4, -11, -7, 11, 11, 14, -7, 12, -7, 6, 2, 13, -6, -3, -2,
- -14, 6, 6, 6, 0, 2, -1, 5, -20, 2, -1, 4, -5, 6, 21, -11 },
- { -2, -9, 3, 0, -6, 7, 8, -8, 1, -3, 4, 1, 5, -2, -3, -7,
- 4, 7, -12, -9, -2, 10, -6, 13, 6, 5, 20, 2, -15, 9, 28, -7 },
- { 0, -5, -6, -6, -6, 1, -6, 6, -2, 4, 8, -3, 12, -1, -4, -2,
- 6, 16, -14, 9, -14, -2, -8, -27, -3, 18, -1, -7, -3, 8, 23, -23 },
- { 1, 4, -9, -1, -5, 10, -2, 1, -11, 1, -9, 4, 7, 14, -9, -2,
- -3, 2, -5, -1, -6, -10, -7, 11, 20, 2, 3, -19, 3, 15, 30, -9 },
- { 7, 2, -14, -4, 0, -2, 5, 2, 5, -2, 8, -3, -7, 6, 6, -11,
- -14, 1, 10, -1, -7, -8, 1, 10, 3, -6, -15, -12, -17, 4, 30, -6 },
- { 4, 2, 1, -2, 3, 0, 1, 0, 2, 0, 1, 6, -7, 0, 3, 4,
- 4, -4, -2, -5, -2, 2, -1, -2, 0, -2, -11, -7, -3, 42, 24, -14 },
- { 4, 1, 3, 2, 0, -2, -3, -2, 2, -1, 4, 11, -2, 2, 3, -4,
- -5, 9, 2, -4, -9, 5, 8, -1, -7, 1, 24, -13, -28, 20, 15, -22 },
- { -3, 7, 6, 3, -2, -5, -10, -2, -2, -1, -6, -6, -2, -14, -16, -6,
- -5, 0, 18, 0, 9, 1, 7, -13, -5, -6, -9, 11, -15, 9, 22, -11 },
- { 9, -2, 6, 5, 2, 9, -10, 1, 1, 5, -4, 12, 2, 2, -10, -7,
- -4, -6, 7, 9, 6, 15, 6, 6, -10, 10, 5, -13, -5, 6, 24, -12 },
- { 1, 3, -3, -3, 8, 1, -6, 2, -5, -3, 7, 2, 14, 6, 9, -6,
- -5, -4, 27, 7, -3, 8, -6, 3, -8, 8, 22, -5, -6, -2, 22, -17 },
- { -2, -2, 3, 10, 9, 9, 12, -15, -1, -11, -13, 3, -2, 1, -3, -11,
- 7, 9, 16, -3, -10, -5, -5, 1, 8, -3, 9, 9, -5, 3, 31, -12 },
- { 7, -5, 10, -4, -8, 2, 16, -2, 10, 10, -3, -2, 3, -8, -3, 3,
- -13, -6, 15, 20, -9, -3, -12, 1, -2, -16, 8, 8, -1, 16, 22, -5 },
- { 5, -3, -15, -2, 12, -8, 8, -5, 2, -8, 20, -18, 14, -4, 3, 3,
- 7, -13, -16, 1, -10, 7, 16, 7, 4, -14, -4, -5, -9, 8, 23, -6 },
- { 5, -4, -5, -4, 1, 8, 4, -7, -5, 8, 10, 6, -6, -10, -2, 6,
- 9, -17, -14, 11, 12, -3, -13, -7, 2, 18, 3, -25, -16, 18, 22, -5 },
- { 5, 6, -7, -20, -4, 2, 8, 4, -24, -4, 1, 4, -5, -2, 1, -10,
- -2, 9, 3, -4, -3, -4, -4, -4, 10, 10, 3, 0, -6, 25, 21, -11 },
- { 0, 7, -1, 14, -6, -4, -10, 5, 4, 4, 4, -5, 3, 4, -1, -7,
- 8, -19, 0, 6, 2, 3, -18, -3, -6, 2, 8, 14, -26, 22, 27, -13 },
- { -2, -6, 7, -5, 12, -7, 8, -1, 3, -2, 4, 1, 8, -2, 0, 14,
- 6, -5, 6, -4, -7, 7, -21, 8, 1, 8, -9, -4, -3, 11, 25, -13 },
- { 4, 4, -1, -6, 4, 9, -8, 1, -3, -10, -2, 0, 15, -9, -16, 11,
- 1, 1, 6, 3, -9, -5, 16, 26, 1, -14, 1, -3, -14, 7, 15, -9 },
- { -12, -2, -9, -13, 2, 6, 14, 0, 1, 0, -1, -13, 0, 10, -1, 6,
- 9, -7, 8, 8, 19, 6, -1, 9, 10, -4, 1, -7, -22, -2, 29, -7 },
- { 2, 4, 13, -12, -8, -4, -5, 13, 12, -5, -3, -3, -4, 1, -1, 10,
- 15, -6, -1, -11, -30, 4, 15, -1, 9, -7, 0, -2, -7, 10, 25, -16 },
- { 7, -15, -7, -7, -1, -5, -5, -11, -20, 10, 3, -10, -3, 5, 20, -4,
- 0, -2, -2, 17, 2, 0, -3, 3, 6, 5, -1, -12, -3, 15, 22, -16 },
- { 4, -1, 3, 4, -5, 0, -1, -5, -24, -29, 4, -9, 1, -3, 0, 0,
- 0, -4, 7, -4, -4, -4, 3, 1, -6, 5, -3, -5, -10, 3, 25, -10 },
- { -2, -1, -1, 4, 4, -1, 2, 0, -4, -4, 2, -1, -3, -1, -2, -2,
- 1, -3, -5, -1, 2, -3, -4, -4, -3, 5, -9, 1, -11, 7, 46, -46 },
- { 0, -9, 3, 4, 4, 3, -5, -6, 5, -4, 4, -2, 1, 7, -4, -10,
- 13, 1, 3, -6, 4, -4, 7, 2, -19, -25, -3, -16, -12, 16, 20, -1 },
- { 18, 6, 4, -12, 0, -14, 9, -6, -1, -4, -5, 2, 1, 12, 4, 2,
- 7, 0, 2, 5, -11, -5, -2, 2, -4, 10, 0, -9, -7, 9, 25, -8 },
- { 5, 0, -6, 5, 6, 3, 3, -10, -5, 1, -1, 4, 3, -11, -8, 5,
- 4, -5, 5, -5, -7, -5, 11, 5, 20, -8, -16, 21, -4, 27, 23, -5 }
-};
diff --git a/src/libdts/xine_dts_decoder.c b/src/libdts/xine_dts_decoder.c
deleted file mode 100644
index 0ef9afa17..000000000
--- a/src/libdts/xine_dts_decoder.c
+++ /dev/null
@@ -1,619 +0,0 @@
-/*
- * Copyright (C) 2000-2005 the xine project
- *
- * This file is part of xine, a unix video player.
- *
- * xine 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.
- *
- * xine is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- *
- * $Id: xine_decoder.c,v 1.67 2007/02/20 00:34:57 dgp85 Exp $
- *
- * 04-09-2001 DTS passtrough (C) Joachim Koenig
- * 09-12-2001 DTS passthrough inprovements (C) James Courtier-Dutton
- *
- */
-
-#ifndef __sun
-/* required for swab() */
-#define _XOPEN_SOURCE 500
-#endif
-/* avoid compiler warnings */
-#define _BSD_SOURCE 1
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <assert.h>
-
-#define LOG_MODULE "libdts"
-#define LOG_VERBOSE
-/*
-#define LOG
-*/
-
-#include "xine_internal.h"
-#include "xineutils.h"
-#include "audio_out.h"
-#include "buffer.h"
-
-#ifdef HAVE_DTS_H
-# include <dts.h>
-#else
-# include "internal-dts.h"
-#endif
-
-#define MAX_AC5_FRAME 4096
-
-typedef struct {
- audio_decoder_class_t decoder_class;
-} dts_class_t;
-
-typedef struct {
- audio_decoder_t audio_decoder;
-
- xine_stream_t *stream;
- audio_decoder_class_t *class;
-
- dts_state_t *dts_state;
- int64_t pts;
-
- int audio_caps;
- int sync_state;
- int ac5_length, ac5_pcm_length, frame_todo;
- uint32_t syncdword;
- uint8_t frame_buffer[MAX_AC5_FRAME];
- uint8_t *frame_ptr;
-
- int output_open;
-
- int bypass_mode;
- int dts_flags;
- int dts_sample_rate;
- int dts_bit_rate;
- int dts_flags_map[11]; /* Convert from stream dts_flags to the dts_flags we want from the dts downmixer */
- int ao_flags_map[11]; /* Convert from the xine AO_CAP's to dts_flags. */
- int have_lfe;
-
-
-} dts_decoder_t;
-
-static void dts_reset (audio_decoder_t *this_gen);
-static void dts_discontinuity (audio_decoder_t *this_gen);
-
-static void dts_reset (audio_decoder_t *this_gen) {
-
- /* dts_decoder_t *this = (dts_decoder_t *) this_gen; */
-
-}
-
-static void dts_discontinuity (audio_decoder_t *this_gen) {
-}
-
-#if 0
-static inline int16_t blah (int32_t i) {
-
- if (i > 0x43c07fff)
- return 32767;
- else if (i < 0x43bf8000)
- return -32768;
- else
- return i - 0x43c00000;
-}
-static inline void float_to_int (float * _f, int16_t * s16, int num_channels) {
- int i;
- int32_t * f = (int32_t *) _f; /* XXX assumes IEEE float format */
-
- for (i = 0; i < 256; i++) {
- s16[num_channels*i] = blah (f[i]);
- }
-}
-#endif
-
-static inline void float_to_int (float * _f, int16_t * s16, int num_channels) {
- int i;
- float f;
- for (i = 0; i < 256; i++) {
- f = _f[i] * 32767;
- if (f > INT16_MAX) f = INT16_MAX;
- if (f < INT16_MIN) f = INT16_MIN;
- s16[num_channels*i] = f;
- /* printf("samples[%d] = %f, %d\n", i, _f[i], s16[num_channels*i]); */
- }
-}
-
-static inline void mute_channel (int16_t * s16, int num_channels) {
- int i;
-
- for (i = 0; i < 256; i++) {
- s16[num_channels*i] = 0;
- }
-}
-
-static void dts_decode_frame (dts_decoder_t *this, int64_t pts, int preview_mode) {
-
- audio_buffer_t *audio_buffer;
- uint32_t ac5_spdif_type=0;
- int output_mode = AO_CAP_MODE_STEREO;
- uint8_t *data_out;
- uint8_t *data_in = this->frame_buffer;
-
- lprintf("decode_frame\n");
- audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out);
- audio_buffer->vpts = pts;
-
- if(this->bypass_mode) {
- /* SPDIF digital output */
- if (!this->output_open) {
- this->output_open = (this->stream->audio_out->open (this->stream->audio_out, this->stream,
- 16, this->dts_sample_rate,
- AO_CAP_MODE_AC5));
- }
-
- if (!this->output_open)
- return;
-
- data_out=(uint8_t *) audio_buffer->mem;
- if (this->ac5_length > 8191) {
- xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "libdts: ac5_length too long\n");
- this->ac5_pcm_length = 0;
- }
-
- switch (this->ac5_pcm_length) {
- case 512:
- ac5_spdif_type = 0x0b; /* DTS-1 (512-sample bursts) */
- break;
- case 1024:
- ac5_spdif_type = 0x0c; /* DTS-1 (1024-sample bursts) */
- break;
- case 2048:
- ac5_spdif_type = 0x0d; /* DTS-1 (2048-sample bursts) */
- break;
- default:
- xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG,
- "libdts: DTS %i-sample bursts not supported\n", this->ac5_pcm_length);
- return;
- }
-
-#ifdef LOG_DEBUG
- {
- int i;
- printf("libdts: DTS frame type=%d\n",data_in[4] >> 7);
- printf("libdts: DTS deficit frame count=%d\n",(data_in[4] & 0x7f) >> 2);
- printf("libdts: DTS AC5 PCM samples=%d\n",ac5_pcm_samples);
- printf("libdts: DTS AC5 length=%d\n",this->ac5_length);
- printf("libdts: DTS AC5 bitrate=%d\n",((data_in[8] & 0x03) << 4) | (data_in[8] >> 4));
- printf("libdts: DTS AC5 spdif type=%d\n", ac5_spdif_type);
-
- printf("libdts: ");
- for(i=2000;i<2048;i++) {
- printf("%02x ",data_in[i]);
- }
- printf("\n");
- }
-#endif
-
- lprintf("length=%d pts=%"PRId64"\n",this->ac5_pcm_length,audio_buffer->vpts);
-
- audio_buffer->num_frames = this->ac5_pcm_length;
-
- data_out[0] = 0x72; data_out[1] = 0xf8; /* spdif syncword */
- data_out[2] = 0x1f; data_out[3] = 0x4e; /* .............. */
- data_out[4] = ac5_spdif_type; /* DTS data */
- data_out[5] = 0; /* Unknown */
- data_out[6] = (this->ac5_length << 3) & 0xff; /* ac5_length * 8 */
- data_out[7] = ((this->ac5_length ) >> 5) & 0xff;
-
- if( this->ac5_pcm_length ) {
- if( this->ac5_pcm_length % 2) {
- swab(data_in, &data_out[8], this->ac5_length );
- } else {
- swab(data_in, &data_out[8], this->ac5_length + 1);
- }
- }
- } else {
- /* Software decode */
- int i, dts_output_flags;
- int16_t *int_samples = audio_buffer->mem;
- int number_of_dts_blocks;
-
- level_t level = 1.0;
- sample_t *samples;
-
- dts_output_flags = this->dts_flags_map[this->dts_flags & DTS_CHANNEL_MASK];
-
- if(dts_frame(this->dts_state, data_in, &dts_output_flags, &level, 0)) {
- xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libdts: dts_frame error\n");
- return;
- }
-
- this->have_lfe = dts_output_flags & DTS_LFE;
- if (this->have_lfe)
- if (this->audio_caps & AO_CAP_MODE_5_1CHANNEL) {
- output_mode = AO_CAP_MODE_5_1CHANNEL;
- } else if (this->audio_caps & AO_CAP_MODE_4_1CHANNEL) {
- output_mode = AO_CAP_MODE_4_1CHANNEL;
- } else {
- xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "libdts: WHAT DO I DO!!!\n");
- output_mode = this->ao_flags_map[dts_output_flags & DTS_CHANNEL_MASK];
- }
- else
- output_mode = this->ao_flags_map[dts_output_flags & DTS_CHANNEL_MASK];
-
- if (!this->output_open) {
- this->output_open = this->stream->audio_out->open (this->stream->audio_out, this->stream,
- 16, this->dts_sample_rate,
- output_mode);
- }
-
- if (!this->output_open)
- return;
- number_of_dts_blocks = dts_blocks_num (this->dts_state);
- audio_buffer->num_frames = 256*number_of_dts_blocks;
- for(i = 0; i < number_of_dts_blocks; i++) {
- if(dts_block(this->dts_state)) {
- xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG,
- "libdts: dts_block error on audio channel %d\n", i);
- audio_buffer->num_frames = 0;
- break;
- }
-
- samples = dts_samples(this->dts_state);
- switch (output_mode) {
- case AO_CAP_MODE_MONO:
- float_to_int (&samples[0], int_samples+(i*256), 1);
- break;
- case AO_CAP_MODE_STEREO:
- /* Tested, working. */
- float_to_int (&samples[0*256], int_samples+(i*256*2), 2); /* L */
- float_to_int (&samples[1*256], int_samples+(i*256*2)+1, 2); /* R */
- break;
- case AO_CAP_MODE_4CHANNEL:
- /* Tested, working */
- float_to_int (&samples[0*256], int_samples+(i*256*4), 4); /* L */
- float_to_int (&samples[1*256], int_samples+(i*256*4)+1, 4); /* R */
- float_to_int (&samples[2*256], int_samples+(i*256*4)+2, 4); /* RL */
- float_to_int (&samples[3*256], int_samples+(i*256*4)+3, 4); /* RR */
- break;
- case AO_CAP_MODE_4_1CHANNEL:
- /* Tested, working */
- float_to_int (&samples[0*256], int_samples+(i*256*6)+0, 6); /* L */
- float_to_int (&samples[1*256], int_samples+(i*256*6)+1, 6); /* R */
- float_to_int (&samples[2*256], int_samples+(i*256*6)+2, 6); /* RL */
- float_to_int (&samples[3*256], int_samples+(i*256*6)+3, 6); /* RR */
- float_to_int (&samples[4*256], int_samples+(i*256*6)+5, 6); /* LFE */
- mute_channel ( int_samples+(i*256*6)+4, 6); /* C */
- break;
- case AO_CAP_MODE_5CHANNEL:
- /* Tested, working */
- float_to_int (&samples[0*256], int_samples+(i*256*6)+4, 6); /* C */
- float_to_int (&samples[1*256], int_samples+(i*256*6)+0, 6); /* L */
- float_to_int (&samples[2*256], int_samples+(i*256*6)+1, 6); /* R */
- float_to_int (&samples[3*256], int_samples+(i*256*6)+2, 6); /* RL */
- float_to_int (&samples[4*256], int_samples+(i*256*6)+3, 6); /* RR */
- mute_channel ( int_samples+(i*256*6)+5, 6); /* LFE */
- break;
- case AO_CAP_MODE_5_1CHANNEL:
- float_to_int (&samples[0*256], int_samples+(i*256*6)+4, 6); /* C */
- float_to_int (&samples[1*256], int_samples+(i*256*6)+0, 6); /* L */
- float_to_int (&samples[2*256], int_samples+(i*256*6)+1, 6); /* R */
- float_to_int (&samples[3*256], int_samples+(i*256*6)+2, 6); /* RL */
- float_to_int (&samples[4*256], int_samples+(i*256*6)+3, 6); /* RR */
- float_to_int (&samples[5*256], int_samples+(i*256*6)+5, 6); /* LFE */ /* Not working yet */
- break;
- default:
- xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libdts: help - unsupported mode %08x\n", output_mode);
- }
- }
- }
-
- this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream);
-
-
-}
-
-static void dts_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) {
-
- dts_decoder_t *this = (dts_decoder_t *) this_gen;
- uint8_t *current = (uint8_t *)buf->content;
- uint8_t *sync_start=current + 1;
- uint8_t *end = buf->content + buf->size;
-
- lprintf("decode_data\n");
-
- if (buf->decoder_flags & BUF_FLAG_PREVIEW)
- return;
- if (buf->decoder_flags & BUF_FLAG_STDHEADER)
- return;
-
- lprintf ("processing...state %d\n", this->sync_state);
-
- while (current < end) {
- switch (this->sync_state) {
- case 0: /* Looking for sync header */
- this->syncdword = (this->syncdword << 8) | *current++;
-/*
- if ((this->syncdword == 0xff1f00e8) ||
- (this->syncdword == 0x1fffe800) ||
- (this->syncdword == 0xfe7f0180) ||
- (this->syncdword == 0x7ffe8001) ) {
-*/
- if ((this->syncdword == 0x7ffe8001)) {
-
- lprintf ("sync found: syncdword=0x%x\n", this->syncdword);
- this->frame_buffer[0] = 0x7f;
- this->frame_buffer[1] = 0xfe;
- this->frame_buffer[2] = 0x80;
- this->frame_buffer[3] = 0x01;
-
- this->sync_state = 1;
- this->frame_ptr = this->frame_buffer+4;
- this->pts = buf->pts;
- break;
- }
- if ((this->syncdword == 0xff1f00e8)) {
-
- lprintf ("sync found: syncdword=0x%x\n", this->syncdword);
- this->frame_buffer[0] = 0xff;
- this->frame_buffer[1] = 0x1f;
- this->frame_buffer[2] = 0x00;
- this->frame_buffer[3] = 0xe8;
-
- this->sync_state = 1;
- this->frame_ptr = this->frame_buffer+4;
- this->pts = buf->pts;
- break;
- }
- break;
-
- case 1: /* Looking for enough bytes for sync_info. */
- sync_start = current - 1;
- *this->frame_ptr++ = *current++;
- if ((this->frame_ptr - this->frame_buffer) > 19) {
- int old_dts_flags = this->dts_flags;
- int old_dts_sample_rate = this->dts_sample_rate;
- int old_dts_bit_rate = this->dts_bit_rate;
-
- this->ac5_length = dts_syncinfo (this->dts_state, this->frame_buffer,
- &this->dts_flags,
- &this->dts_sample_rate,
- &this->dts_bit_rate, &(this->ac5_pcm_length));
- lprintf("ac5_length=%d\n",this->ac5_length);
- lprintf("dts_sample_rate=%d\n",this->dts_sample_rate);
-
- if ( (this->ac5_length < 80) || (this->ac5_length > MAX_AC5_FRAME) ) { /* Invalid dts ac5_pcm_length */
- this->syncdword = 0;
- current = sync_start;
- this->sync_state = 0;
- break;
- }
-
- lprintf("Frame length = %d\n",this->ac5_pcm_length);
-
- this->frame_todo = this->ac5_length - 20;
- this->sync_state = 2;
- if (!_x_meta_info_get(this->stream, XINE_META_INFO_AUDIOCODEC) ||
- old_dts_flags != this->dts_flags ||
- old_dts_sample_rate != this->dts_sample_rate ||
- old_dts_bit_rate != this->dts_bit_rate) {
-
- switch (this->dts_flags & DTS_CHANNEL_MASK) {
- case DTS_3F2R:
- if (this->dts_flags & DTS_LFE)
- _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 5.1");
- else
- _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 5.0");
- break;
- case DTS_3F1R:
- case DTS_2F2R:
- if (this->dts_flags & DTS_LFE)
- _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 4.1");
- else
- _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 4.0");
- break;
- case DTS_2F1R:
- case DTS_3F:
- _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 3.0");
- break;
- case DTS_STEREO:
- _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 2.0 (stereo)");
- break;
- case DTS_MONO:
- _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 1.0");
- break;
- default:
- _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS");
- break;
- }
-
- _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITRATE, this->dts_bit_rate);
- _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_SAMPLERATE, this->dts_sample_rate);
- }
- }
- break;
-
- case 2: /* Filling frame_buffer with sync_info bytes */
- *this->frame_ptr++ = *current++;
- this->frame_todo--;
- if (this->frame_todo < 1) {
- this->sync_state = 3;
- } else break;
-
- case 3: /* Ready for decode */
-#if 0
- dtsdec_decode_frame (this, this->pts_list[0], buf->decoder_flags & BUF_FLAG_PREVIEW);
-#else
- dts_decode_frame (this, this->pts, buf->decoder_flags & BUF_FLAG_PREVIEW);
-#endif
- case 4: /* Clear up ready for next frame */
- this->pts = 0;
- this->syncdword = 0;
- this->sync_state = 0;
- break;
- default: /* No come here */
- break;
- }
- }
-}
-
-static void dts_dispose (audio_decoder_t *this_gen) {
- dts_decoder_t *this = (dts_decoder_t *) this_gen;
-
- if (this->output_open)
- this->stream->audio_out->close (this->stream->audio_out, this->stream);
- this->output_open = 0;
-
- free (this);
-}
-
-static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) {
- dts_decoder_t *this ;
-
- lprintf("open_plugin\n");
-
- this = (dts_decoder_t *) xine_xmalloc (sizeof (dts_decoder_t));
-
- this->audio_decoder.decode_data = dts_decode_data;
- this->audio_decoder.reset = dts_reset;
- this->audio_decoder.discontinuity = dts_discontinuity;
- this->audio_decoder.dispose = dts_dispose;
-
- this->dts_state = dts_init(0);
- this->audio_caps = stream->audio_out->get_capabilities(stream->audio_out);
- if(this->audio_caps & AO_CAP_MODE_AC5)
- this->bypass_mode = 1;
- else {
- this->bypass_mode = 0;
- /* FIXME: Leave "DOLBY pro logic" downmix out for now. */
-
- this->dts_flags_map[DTS_MONO] = DTS_MONO;
- this->dts_flags_map[DTS_STEREO] = DTS_STEREO;
- this->dts_flags_map[DTS_3F] = DTS_STEREO;
- this->dts_flags_map[DTS_2F1R] = DTS_STEREO;
- this->dts_flags_map[DTS_3F1R] = DTS_STEREO;
- this->dts_flags_map[DTS_2F2R] = DTS_STEREO;
- this->dts_flags_map[DTS_3F2R] = DTS_STEREO;
-
- this->ao_flags_map[DTS_MONO] = AO_CAP_MODE_MONO;
- this->ao_flags_map[DTS_STEREO] = AO_CAP_MODE_STEREO;
- this->ao_flags_map[DTS_3F] = AO_CAP_MODE_STEREO;
- this->ao_flags_map[DTS_2F1R] = AO_CAP_MODE_STEREO;
- this->ao_flags_map[DTS_3F1R] = AO_CAP_MODE_STEREO;
- this->ao_flags_map[DTS_2F2R] = AO_CAP_MODE_STEREO;
- this->ao_flags_map[DTS_3F2R] = AO_CAP_MODE_STEREO;
-
- /* find best mode */
- if (this->audio_caps & AO_CAP_MODE_5_1CHANNEL) {
-
- this->dts_flags_map[DTS_2F2R] = DTS_2F2R;
- this->dts_flags_map[DTS_3F2R] = DTS_3F2R | DTS_LFE;
- this->ao_flags_map[DTS_2F2R] = AO_CAP_MODE_4CHANNEL;
- this->ao_flags_map[DTS_3F2R] = AO_CAP_MODE_5CHANNEL;
-
- } else if (this->audio_caps & AO_CAP_MODE_5CHANNEL) {
-
- this->dts_flags_map[DTS_2F2R] = DTS_2F2R;
- this->dts_flags_map[DTS_3F2R] = DTS_3F2R;
- this->ao_flags_map[DTS_2F2R] = AO_CAP_MODE_4CHANNEL;
- this->ao_flags_map[DTS_3F2R] = AO_CAP_MODE_5CHANNEL;
-
- } else if (this->audio_caps & AO_CAP_MODE_4_1CHANNEL) {
-
- this->dts_flags_map[DTS_2F2R] = DTS_2F2R;
- this->dts_flags_map[DTS_3F2R] = DTS_2F2R | DTS_LFE;
- this->ao_flags_map[DTS_2F2R] = AO_CAP_MODE_4CHANNEL;
- this->ao_flags_map[DTS_3F2R] = AO_CAP_MODE_4CHANNEL;
-
- } else if (this->audio_caps & AO_CAP_MODE_4CHANNEL) {
-
- this->dts_flags_map[DTS_2F2R] = DTS_2F2R;
- this->dts_flags_map[DTS_3F2R] = DTS_2F2R;
-
- this->ao_flags_map[DTS_2F2R] = AO_CAP_MODE_4CHANNEL;
- this->ao_flags_map[DTS_3F2R] = AO_CAP_MODE_4CHANNEL;
-
- /* else if (this->audio_caps & AO_CAP_MODE_STEREO)
- defaults are ok */
- } else if (!(this->audio_caps & AO_CAP_MODE_STEREO)) {
- xprintf (this->stream->xine, XINE_VERBOSITY_LOG, _("HELP! a mono-only audio driver?!\n"));
-
- this->dts_flags_map[DTS_MONO] = DTS_MONO;
- this->dts_flags_map[DTS_STEREO] = DTS_MONO;
- this->dts_flags_map[DTS_3F] = DTS_MONO;
- this->dts_flags_map[DTS_2F1R] = DTS_MONO;
- this->dts_flags_map[DTS_3F1R] = DTS_MONO;
- this->dts_flags_map[DTS_2F2R] = DTS_MONO;
- this->dts_flags_map[DTS_3F2R] = DTS_MONO;
-
- this->ao_flags_map[DTS_MONO] = AO_CAP_MODE_MONO;
- this->ao_flags_map[DTS_STEREO] = AO_CAP_MODE_MONO;
- this->ao_flags_map[DTS_3F] = AO_CAP_MODE_MONO;
- this->ao_flags_map[DTS_2F1R] = AO_CAP_MODE_MONO;
- this->ao_flags_map[DTS_3F1R] = AO_CAP_MODE_MONO;
- this->ao_flags_map[DTS_2F2R] = AO_CAP_MODE_MONO;
- this->ao_flags_map[DTS_3F2R] = AO_CAP_MODE_MONO;
- }
- }
- this->stream = stream;
- this->class = class_gen;
- this->output_open = 0;
-
- return &this->audio_decoder;
-}
-
-static char *get_identifier (audio_decoder_class_t *this) {
- return "DTS";
-}
-
-static char *get_description (audio_decoder_class_t *this) {
- return "DTS passthru audio format decoder plugin";
-}
-
-static void dispose_class (audio_decoder_class_t *this) {
- lprintf("dispose_class\n");
-
- free (this);
-}
-
-static void *init_plugin (xine_t *xine, void *data) {
- dts_class_t *this ;
-
- lprintf("init_plugin\n");
-
- this = (dts_class_t *) xine_xmalloc (sizeof (dts_class_t));
-
- this->decoder_class.open_plugin = open_plugin;
- this->decoder_class.get_identifier = get_identifier;
- this->decoder_class.get_description = get_description;
- this->decoder_class.dispose = dispose_class;
-
- return this;
-}
-
-static uint32_t audio_types[] = {
- BUF_AUDIO_DTS, 0
- };
-
-static const decoder_info_t dec_info_audio = {
- audio_types, /* supported types */
- 1 /* priority */
-};
-
-const plugin_info_t xine_plugin_info[] EXPORTED = {
- /* type, API, "name", version, special_info, init_function */
- { PLUGIN_AUDIO_DECODER, 15, "dts", XINE_VERSION_CODE, &dec_info_audio, init_plugin },
- { PLUGIN_NONE, 0, "", 0, NULL, NULL }
-};
diff --git a/src/libfaad/Makefile.am b/src/libfaad/Makefile.am
index d1a4ed865..379033b15 100644
--- a/src/libfaad/Makefile.am
+++ b/src/libfaad/Makefile.am
@@ -1,59 +1,11 @@
include $(top_srcdir)/misc/Makefile.common
-SUBDIRS = codebook
-
-if BUILD_FAAD
-faad_module = xineplug_decode_faad.la
-endif
-
-xineplug_LTLIBRARIES = $(faad_module)
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+AM_LDFLAGS = $(xineplug_ldflags)
VPATH = @srcdir@:@srcdir@/codebook:
-xineplug_decode_faad_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS) -fno-strict-aliasing
-xineplug_decode_faad_la_SOURCES = \
- bits.c \
- cfft.c \
- common.c \
- decoder.c \
- drc.c \
- drm_dec.c \
- error.c \
- filtbank.c \
- hcr.c \
- huffman.c \
- ic_predict.c \
- is.c \
- lt_predict.c \
- mdct.c \
- mp4.c \
- ms.c \
- output.c \
- pns.c \
- ps_dec.c \
- ps_syntax.c \
- pulse.c \
- rvlc.c \
- sbr_dct.c \
- sbr_dec.c \
- sbr_e_nf.c \
- sbr_fbt.c \
- sbr_hfadj.c \
- sbr_hfgen.c \
- sbr_huff.c \
- sbr_qmf.c \
- sbr_syntax.c \
- sbr_tf_grid.c \
- specrec.c \
- ssr.c \
- ssr_fb.c \
- ssr_ipqf.c \
- syntax.c \
- tns.c \
- xine_faad_decoder.c
-
-xineplug_decode_faad_la_LDFLAGS = $(xineplug_ldflags)
-xineplug_decode_faad_la_LIBADD = -lm $(XINE_LIB)
+SUBDIRS = codebook
noinst_HEADERS = \
analysis.h \
@@ -104,3 +56,51 @@ noinst_HEADERS = \
structs.h \
syntax.h \
tns.h
+
+if ENABLE_FAAD
+xineplug_LTLIBRARIES = xineplug_decode_faad.la
+endif
+
+xineplug_decode_faad_la_SOURCES = \
+ bits.c \
+ cfft.c \
+ common.c \
+ decoder.c \
+ drc.c \
+ drm_dec.c \
+ error.c \
+ filtbank.c \
+ hcr.c \
+ huffman.c \
+ ic_predict.c \
+ is.c \
+ lt_predict.c \
+ mdct.c \
+ mp4.c \
+ ms.c \
+ output.c \
+ pns.c \
+ ps_dec.c \
+ ps_syntax.c \
+ pulse.c \
+ rvlc.c \
+ sbr_dct.c \
+ sbr_dec.c \
+ sbr_e_nf.c \
+ sbr_fbt.c \
+ sbr_hfadj.c \
+ sbr_hfgen.c \
+ sbr_huff.c \
+ sbr_qmf.c \
+ sbr_syntax.c \
+ sbr_tf_grid.c \
+ specrec.c \
+ ssr.c \
+ ssr_fb.c \
+ ssr_ipqf.c \
+ syntax.c \
+ tns.c \
+ xine_faad_decoder.c
+
+xineplug_decode_faad_la_LIBADD = -lm $(XINE_LIB)
+xineplug_decode_faad_la_CFLAGS = $(AM_CFLAGS) -fno-strict-aliasing
diff --git a/src/libfaad/xine_faad_decoder.c b/src/libfaad/xine_faad_decoder.c
index aa528a34d..169874a44 100644
--- a/src/libfaad/xine_faad_decoder.c
+++ b/src/libfaad/xine_faad_decoder.c
@@ -75,7 +75,6 @@ typedef struct faad_decoder_s {
int bits_per_sample;
unsigned char num_channels;
int sbr;
- uint32_t ao_cap_mode;
int output_open;
@@ -177,16 +176,18 @@ static int faad_open_dec( faad_decoder_t *this ) {
}
static int faad_open_output( faad_decoder_t *this ) {
+ int ao_cap_mode;
+
this->rec_audio_src_size = this->num_channels * FAAD_MIN_STREAMSIZE;
switch( this->num_channels ) {
case 1:
- this->ao_cap_mode=AO_CAP_MODE_MONO;
+ ao_cap_mode=AO_CAP_MODE_MONO;
break;
case 6:
if(this->stream->audio_out->get_capabilities(this->stream->audio_out) &
AO_CAP_MODE_5_1CHANNEL) {
- this->ao_cap_mode = AO_CAP_MODE_5_1CHANNEL;
+ ao_cap_mode = AO_CAP_MODE_5_1CHANNEL;
break;
} else {
this->faac_cfg = NeAACDecGetCurrentConfiguration(this->faac_dec);
@@ -195,7 +196,7 @@ static int faad_open_output( faad_decoder_t *this ) {
this->num_channels = 2;
}
case 2:
- this->ao_cap_mode=AO_CAP_MODE_STEREO;
+ ao_cap_mode=AO_CAP_MODE_STEREO;
break;
}
@@ -203,7 +204,7 @@ static int faad_open_output( faad_decoder_t *this ) {
this->stream,
this->bits_per_sample,
this->rate,
- this->ao_cap_mode) ;
+ ao_cap_mode) ;
return this->output_open;
}
diff --git a/src/libffmpeg/Makefile.am b/src/libffmpeg/Makefile.am
index 19ea72b5e..ab866706c 100644
--- a/src/libffmpeg/Makefile.am
+++ b/src/libffmpeg/Makefile.am
@@ -1,45 +1,62 @@
include $(top_srcdir)/misc/Makefile.common
-if HAVE_FFMPEG
-AM_CFLAGS = $(FFMPEG_CFLAGS) $(FFMPEG_POSTPROC_CFLAGS)
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+AM_CPPFLAGS = $(ZLIB_CPPFLAGS)
+AM_LDFLAGS = $(xineplug_ldflags)
+
+if WITH_EXTERNAL_FFMPEG
+AM_CFLAGS += $(FFMPEG_CFLAGS) $(FFMPEG_POSTPROC_CFLAGS)
link_ffmpeg = $(FFMPEG_LIBS) $(FFMPEG_POSTPROC_LIBS)
else
-ff_cppflags = -I$(top_srcdir)/src/libffmpeg/libavutil
-link_ffmpeg = \
- $(top_builddir)/src/libffmpeg/libavcodec/libavcodec.la \
- $(top_builddir)/src/libffmpeg/libavutil/libavutil.la \
- $(top_builddir)/src/libffmpeg/libavcodec/libpostproc/libpostprocess.la
-SUBDIRS = libavcodec libavutil
-endif
+AM_CPPFLAGS += -I$(top_srcdir)/contrib/ffmpeg/libavutil \
+ -I$(top_srcdir)/contrib/ffmpeg/libavcodec \
+ -I$(top_srcdir)/contrib/ffmpeg/libpostproc
+link_ffmpeg = $(top_builddir)/contrib/ffmpeg/libavcodec/libavcodec.a \
+ $(top_builddir)/contrib/ffmpeg/libavutil/libavutil.a \
+ $(top_builddir)/contrib/ffmpeg/libpostproc/libpostproc.a
-# ffmpeg_config.h is generated by configure
-DISTCLEANFILES = ffmpeg_config.h
+$(top_builddir)/contrib/ffmpeg/libavcodec/libavcodec.a:
+ $(MAKE) -C $(top_builddir)/contrib/ ffmpeg/libavcodec/libavcodec.a
-# this must always be included, even if the current machine has no DXR3...
-EXTRA_DIST = ffmpeg_encoder.c diff_to_ffmpeg_cvs.txt
+$(top_builddir)/contrib/ffmpeg/libavutil/libavutil.a:
+ $(MAKE) -C $(top_builddir)/contrib/ ffmpeg/libavutil/libavutil.a
+
+$(top_builddir)/contrib/ffmpeg/libpostproc/libpostproc.a:
+ $(MAKE) -C $(top_builddir)/contrib/ ffmpeg/libpostproc/libpostproc.a
+
+$(top_builddir)/contrib/ffmpeg/config.h:
+ $(MAKE) -C $(top_builddir)/contrib/ ffmpeg/config.mak
+
+ffmpeg_config.h: $(top_builddir)/contrib/ffmpeg/config.h
+ cp $(top_builddir)/contrib/ffmpeg/config.h ffmpeg_config.h
-INTERNAL_DOCS = diff_to_ffmpeg_cvs.txt
+BUILT_SOURCES = ffmpeg_config.h
+CLEANFILES = $(BUILT_SOURCES)
+
+endif
+
+# this must always be included, even if the current machine has no DXR3...
+EXTRA_DIST = ffmpeg_encoder.c
xineplug_LTLIBRARIES = xineplug_decode_ff.la xineplug_decode_dvaudio.la
-if HAVE_DXR3
-AM_CPPFLAGS = -I$(top_srcdir)/src/dxr3 $(X_CFLAGS) $(ff_cppflags) \
- $(ZLIB_CPPFLAGS)
+if ENABLE_DXR3
+AM_CFLAGS += $(X_CFLAGS)
+AM_CPPFLAGS += -I$(top_srcdir)/src/dxr3
xineplug_decode_ff_la_SOURCES = ffmpeg_decoder.c ff_audio_decoder.c ff_video_decoder.c \
ffmpeg_encoder.c ff_mpeg_parser.c ffmpeg_decoder.h \
ff_mpeg_parser.h
else
-AM_CPPFLAGS = $(ff_cppflags) $(ZLIB_CPPFLAGS)
xineplug_decode_ff_la_SOURCES = ffmpeg_decoder.c ff_audio_decoder.c ff_video_decoder.c \
ff_mpeg_parser.c ffmpeg_decoder.h ff_mpeg_parser.h
endif
-xineplug_decode_ff_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS)
-xineplug_decode_ff_la_LDFLAGS = $(xineplug_ldflags) $(IMPURE_TEXT_LDFLAGS)
+nodist_xineplug_decode_ff_la_SOURCES = ffmpeg_config.h
+
xineplug_decode_ff_la_LIBADD = $(MLIB_LIBS) $(XINE_LIB) -lm $(ZLIB_LIBS) \
$(link_ffmpeg) $(PTHREAD_LIBS)
+xineplug_decode_ff_la_LDFLAGS = $(AM_LDFLAGS) $(IMPURE_TEXT_LDFLAGS)
-xineplug_decode_dvaudio_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS)
-xineplug_decode_dvaudio_la_LDFLAGS = $(xineplug_ldflags)
-xineplug_decode_dvaudio_la_SOURCES = ff_dvaudio_decoder.c
-xineplug_decode_dvaudio_la_LIBADD = $(XINE_LIB)
+xineplug_decode_dvaudio_la_SOURCES = ff_dvaudio_decoder.c
+xineplug_decode_dvaudio_la_LIBADD = $(XINE_LIB)
+xineplug_decode_dvaudio_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/contrib/ffmpeg/libavcodec
diff --git a/src/libffmpeg/diff_to_ffmpeg_cvs.txt b/src/libffmpeg/diff_to_ffmpeg_cvs.txt
deleted file mode 100644
index 2e374cfd0..000000000
--- a/src/libffmpeg/diff_to_ffmpeg_cvs.txt
+++ /dev/null
@@ -1,619 +0,0 @@
-Index: libavutil/internal.h
-===================================================================
---- libavutil/internal.h (revision 7433)
-+++ libavutil/internal.h (working copy)
-@@ -181,11 +181,15 @@
- #include <assert.h>
-
- /* dprintf macros */
--#ifdef DEBUG
--# define dprintf(fmt,...) av_log(NULL, AV_LOG_DEBUG, fmt, __VA_ARGS__)
--#else
--# define dprintf(fmt,...)
--#endif
-+# ifdef DEBUG
-+# ifdef __GNUC__
-+# define dprintf(fmt,args...) av_log(NULL, AV_LOG_DEBUG, fmt, ##args)
-+# else
-+# define dprintf(fmt,...) av_log(NULL, AV_LOG_DEBUG, fmt, __VA_ARGS__)
-+# endif
-+# else
-+# define dprintf(fmt,...)
-+# endif
-
- #define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0)
-
-Index: libavutil/integer.c
-===================================================================
---- libavutil/integer.c (revision 7433)
-+++ libavutil/integer.c (working copy)
-@@ -126,8 +126,8 @@
- AVInteger quot_temp;
- if(!quot) quot = &quot_temp;
-
-- assert((int16_t)a[AV_INTEGER_SIZE-1] >= 0 && (int16_t)b[AV_INTEGER_SIZE-1] >= 0);
-- assert(av_log2(b)>=0);
-+ assert((int16_t)a.v[AV_INTEGER_SIZE-1] >= 0 && (int16_t)b.v[AV_INTEGER_SIZE-1] >= 0);
-+ assert(av_log2_i(b)>=0);
-
- if(i > 0)
- b= av_shr_i(b, -i);
-Index: libavutil/common.h
-===================================================================
---- libavutil/common.h (revision 7433)
-+++ libavutil/common.h (working copy)
-@@ -345,4 +345,20 @@
- char *av_strdup(const char *s);
- void av_freep(void *ptr);
-
-+/* xine: inline causes trouble for debug compiling */
-+#ifdef DISABLE_INLINE
-+# ifdef inline
-+# undef inline
-+# endif
-+# ifdef always_inline
-+# undef always_inline
-+# endif
-+# define inline
-+# define always_inline
-+#endif
-+
-+/* xine: another config.h with codecs to use */
-+#include "ffmpeg_config.h"
-+
- #endif /* COMMON_H */
-+
-Index: libavcodec/mjpeg.c
-===================================================================
---- libavcodec/mjpeg.c (revision 7433)
-+++ libavcodec/mjpeg.c (working copy)
-@@ -38,6 +38,13 @@
- #include "mpegvideo.h"
- #include "bytestream.h"
-
-+/* if xine's MPEG encoder is enabled, enable the encoding features in
-+ * this particular module */
-+#if defined(XINE_MPEG_ENCODER) && !defined(CONFIG_ENCODERS)
-+#define CONFIG_ENCODERS
-+#endif
-+
-+
- /* use two quantizer tables (one for luminance and one for chrominance) */
- /* not yet working */
- #undef TWOMATRIXES
-Index: libavcodec/i386/dsputil_mmx.c
-===================================================================
---- libavcodec/i386/dsputil_mmx.c (revision 7433)
-+++ libavcodec/i386/dsputil_mmx.c (working copy)
-@@ -2545,33 +2545,39 @@
- "pmullw %%mm5, %%mm2 \n\t" // (s-dx)*dy
- "pmullw %%mm4, %%mm1 \n\t" // dx*(s-dy)
-
-- "movd %4, %%mm5 \n\t"
-- "movd %3, %%mm4 \n\t"
-+ "movd %3, %%mm5 \n\t"
-+ "movd %2, %%mm4 \n\t"
- "punpcklbw %%mm7, %%mm5 \n\t"
- "punpcklbw %%mm7, %%mm4 \n\t"
- "pmullw %%mm5, %%mm3 \n\t" // src[1,1] * dx*dy
- "pmullw %%mm4, %%mm2 \n\t" // src[0,1] * (s-dx)*dy
-
-- "movd %2, %%mm5 \n\t"
-- "movd %1, %%mm4 \n\t"
-+ "movd %1, %%mm5 \n\t"
-+ "movd %0, %%mm4 \n\t"
- "punpcklbw %%mm7, %%mm5 \n\t"
- "punpcklbw %%mm7, %%mm4 \n\t"
- "pmullw %%mm5, %%mm1 \n\t" // src[1,0] * dx*(s-dy)
- "pmullw %%mm4, %%mm0 \n\t" // src[0,0] * (s-dx)*(s-dy)
-- "paddw %5, %%mm1 \n\t"
-+ "paddw %4, %%mm1 \n\t"
- "paddw %%mm3, %%mm2 \n\t"
- "paddw %%mm1, %%mm0 \n\t"
- "paddw %%mm2, %%mm0 \n\t"
-
-- "psrlw %6, %%mm0 \n\t"
-+ "psrlw %5, %%mm0 \n\t"
- "packuswb %%mm0, %%mm0 \n\t"
-- "movd %%mm0, %0 \n\t"
-
-- : "=m"(dst[x+y*stride])
-+ :
- : "m"(src[0]), "m"(src[1]),
- "m"(src[stride]), "m"(src[stride+1]),
- "m"(*r4), "m"(shift2)
- );
-+
-+ asm volatile(
-+ "movd %%mm0, %0 \n\t"
-+
-+ : "=m"(dst[x+y*stride])
-+ :
-+ );
- src += stride;
- }
- src += 4-h*stride;
-Index: libavcodec/mpegvideo.c
-===================================================================
---- libavcodec/mpegvideo.c (revision 7433)
-+++ libavcodec/mpegvideo.c (working copy)
-@@ -40,6 +40,14 @@
- //#undef NDEBUG
- //#include <assert.h>
-
-+
-+/* if xine's MPEG encoder is enabled, enable the encoding features in
-+ * this particular module */
-+#if defined(XINE_MPEG_ENCODER) && !defined(CONFIG_ENCODERS)
-+#define CONFIG_ENCODERS
-+#endif
-+
-+
- #ifdef CONFIG_ENCODERS
- static int encode_picture(MpegEncContext *s, int picture_number);
- #endif //CONFIG_ENCODERS
-@@ -1345,6 +1353,8 @@
- ff_set_cmp(&s->dsp, s->dsp.ildct_cmp, s->avctx->ildct_cmp);
- ff_set_cmp(&s->dsp, s->dsp.frame_skip_cmp, s->avctx->frame_skip_cmp);
-
-+/* xine: do not need this for decode or MPEG-1 encoding modes */
-+#if 0
- #ifdef CONFIG_H261_ENCODER
- if (s->out_format == FMT_H261)
- ff_h261_encode_init(s);
-@@ -1353,6 +1363,8 @@
- h263_encode_init(s);
- if(s->msmpeg4_version)
- ff_msmpeg4_encode_init(s);
-+#endif /* #if 0 */
-+/* xine: we DO want this for MPEG-1 encoding */
- if (s->out_format == FMT_MPEG1)
- ff_mpeg1_encode_init(s);
-
-@@ -1397,9 +1409,12 @@
-
- ff_rate_control_uninit(s);
-
-+/* xine: do not need this for decode or MPEG-1 encoding modes */
-+#if 0
- MPV_common_end(s);
- if (s->out_format == FMT_MJPEG)
- mjpeg_close(s);
-+#endif /* #if 0 */
-
- av_freep(&avctx->extradata);
-
-@@ -2545,8 +2560,11 @@
-
- MPV_frame_end(s);
-
-+/* xine: do not need this for decode or MPEG-1 encoding modes */
-+#if 0
- if (s->out_format == FMT_MJPEG)
- mjpeg_picture_trailer(s);
-+#endif /* #if 0 */
-
- if(avctx->rc_buffer_size){
- RateControlContext *rcc= &s->rc_context;
-@@ -4574,6 +4592,8 @@
- case CODEC_ID_MPEG1VIDEO:
- case CODEC_ID_MPEG2VIDEO:
- mpeg1_encode_mb(s, s->block, motion_x, motion_y); break;
-+/* xine: do not need this for decode or MPEG-1 encoding modes */
-+#if 0
- case CODEC_ID_MPEG4:
- mpeg4_encode_mb(s, s->block, motion_x, motion_y); break;
- case CODEC_ID_MSMPEG4V2:
-@@ -4594,6 +4614,7 @@
- h263_encode_mb(s, s->block, motion_x, motion_y); break;
- case CODEC_ID_MJPEG:
- mjpeg_encode_mb(s, s->block); break;
-+#endif /* #if 0 */
- default:
- assert(0);
- }
-@@ -4815,6 +4836,8 @@
- +sse(s, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], w>>1, h>>1, s->uvlinesize);
- }
-
-+/* xine: do not need this for decode or MPEG-1 encoding modes */
-+#if 0
- static int pre_estimate_motion_thread(AVCodecContext *c, void *arg){
- MpegEncContext *s= arg;
-
-@@ -4860,6 +4883,7 @@
- }
- return 0;
- }
-+#endif /* #if 0 */
-
- static int mb_var_thread(AVCodecContext *c, void *arg){
- MpegEncContext *s= arg;
-@@ -4886,6 +4910,8 @@
- }
-
- static void write_slice_end(MpegEncContext *s){
-+/* xine: do not need this for decode or MPEG-1 encoding modes */
-+#if 0
- if(s->codec_id==CODEC_ID_MPEG4){
- if(s->partitioned_frame){
- ff_mpeg4_merge_partitions(s);
-@@ -4895,6 +4921,7 @@
- }else if(s->out_format == FMT_MJPEG){
- ff_mjpeg_stuffing(&s->pb);
- }
-+#endif /* #if 0 */
-
- align_put_bits(&s->pb);
- flush_put_bits(&s->pb);
-@@ -4950,10 +4977,13 @@
- case CODEC_ID_FLV1:
- s->gob_index = ff_h263_get_gob_height(s);
- break;
-+/* xine: do not need this for decode or MPEG-1 encoding modes */
-+#if 0
- case CODEC_ID_MPEG4:
- if(s->partitioned_frame)
- ff_mpeg4_init_partitions(s);
- break;
-+#endif /* #if 0 */
- }
-
- s->resync_mb_x=0;
-@@ -5026,9 +5056,12 @@
- if(s->start_mb_y != mb_y || mb_x!=0){
- write_slice_end(s);
-
-+/* xine: do not need this for decode or MPEG-1 encoding modes */
-+#if 0
- if(s->codec_id==CODEC_ID_MPEG4 && s->partitioned_frame){
- ff_mpeg4_init_partitions(s);
- }
-+#endif /* #if 0 */
- }
-
- assert((put_bits_count(&s->pb)&7) == 0);
-@@ -5052,19 +5085,25 @@
- }
-
- switch(s->codec_id){
-+/* xine: do not need this for decode or MPEG-1 encoding modes */
-+#if 0
- case CODEC_ID_MPEG4:
- ff_mpeg4_encode_video_packet_header(s);
- ff_mpeg4_clean_buffers(s);
- break;
-+#endif /* #if 0 */
- case CODEC_ID_MPEG1VIDEO:
- case CODEC_ID_MPEG2VIDEO:
- ff_mpeg1_encode_slice_header(s);
- ff_mpeg1_clean_buffers(s);
- break;
-+/* xine: do not need this for decode or MPEG-1 encoding modes */
-+#if 0
- case CODEC_ID_H263:
- case CODEC_ID_H263P:
- h263_encode_gob_header(s, mb_y);
- break;
-+#endif /* #if 0 */
- }
-
- if(s->flags&CODEC_FLAG_PASS1){
-@@ -5286,7 +5325,10 @@
- backup_s.dquant = 0;
- s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
- s->mb_intra= 0;
-+/* xine: do not need this for decode or MPEG-1 encoding modes */
-+#if 0
- ff_mpeg4_set_direct_mv(s, 0, 0);
-+#endif /* #if 0 */
- encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_DIRECT, pb, pb2, tex_pb,
- &dmin, &next_block, 0, 0);
- }
-@@ -5400,7 +5442,10 @@
- s->mb_intra= 0;
- motion_x=s->b_direct_mv_table[xy][0];
- motion_y=s->b_direct_mv_table[xy][1];
-+/* xine: do not need this for decode or MPEG-1 encoding modes */
-+#if 0
- ff_mpeg4_set_direct_mv(s, motion_x, motion_y);
-+#endif /* #if 0 */
- break;
- case CANDIDATE_MB_TYPE_DIRECT0:
- s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
-@@ -5513,8 +5558,11 @@
- }
-
- //not beautiful here but we must write it before flushing so it has to be here
-+/* xine: do not need this for decode or MPEG-1 encoding modes */
-+#if 0
- if (s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type == I_TYPE)
- msmpeg4_encode_ext_header(s);
-+#endif /* #if 0 */
-
- write_slice_end(s);
-
-@@ -5582,6 +5630,8 @@
- }
-
- if(s->adaptive_quant){
-+/* xine: do not need this for decode or MPEG-1 encoding modes */
-+#if 0
- switch(s->codec_id){
- case CODEC_ID_MPEG4:
- ff_clean_mpeg4_qscales(s);
-@@ -5592,6 +5642,7 @@
- ff_clean_h263_qscales(s);
- break;
- }
-+#endif /* #if 0 */
-
- s->lambda= s->lambda_table[0];
- //FIXME broken
-@@ -5613,10 +5664,13 @@
- s->me.mb_var_sum_temp =
- s->me.mc_mb_var_sum_temp = 0;
-
-+/* xine: do not need this for decode or MPEG-1 encoding modes */
-+#if 0
- /* we need to initialize some time vars before we can encode b-frames */
- // RAL: Condition added for MPEG1VIDEO
- if (s->codec_id == CODEC_ID_MPEG1VIDEO || s->codec_id == CODEC_ID_MPEG2VIDEO || (s->h263_pred && !s->h263_msmpeg4))
- ff_set_mpeg4_time(s, s->picture_number); //FIXME rename and use has_b_frames or similar
-+#endif /* #if 0 */
-
- s->me.scene_change_score=0;
-
-@@ -5647,6 +5701,8 @@
- ff_update_duplicate_context(s->thread_context[i], s);
- }
-
-+/* xine: do not need this for decode or MPEG-1 encoding modes */
-+#if 0
- ff_init_me(s);
-
- /* Estimate motion for every MB */
-@@ -5661,6 +5717,8 @@
-
- s->avctx->execute(s->avctx, estimate_motion_thread, (void**)&(s->thread_context[0]), NULL, s->avctx->thread_count);
- }else /* if(s->pict_type == I_TYPE) */{
-+#endif /* #if 0 */
-+ {
- /* I-Frame */
- for(i=0; i<s->mb_stride*s->mb_height; i++)
- s->mb_type[i]= CANDIDATE_MB_TYPE_INTRA;
-@@ -5684,6 +5742,8 @@
- //printf("Scene change detected, encoding as I Frame %d %d\n", s->current_picture.mb_var_sum, s->current_picture.mc_mb_var_sum);
- }
-
-+/* xine: do not need this for decode or MPEG-1 encoding modes */
-+#if 0
- if(!s->umvplus){
- if(s->pict_type==P_TYPE || s->pict_type==S_TYPE) {
- s->f_code= ff_get_best_fcode(s, s->p_mv_table, CANDIDATE_MB_TYPE_INTER);
-@@ -5737,6 +5797,7 @@
- }
- }
- }
-+#endif /* #if 0 */
-
- if (estimate_qp(s, 0) < 0)
- return -1;
-@@ -5768,6 +5829,8 @@
-
- s->last_bits= put_bits_count(&s->pb);
- switch(s->out_format) {
-+/* xine: do not need this for decode or MPEG-1 encoding modes */
-+#if 0
- case FMT_MJPEG:
- mjpeg_picture_header(s);
- break;
-@@ -5796,11 +5859,15 @@
- else
- h263_encode_picture_header(s, picture_number);
- break;
-+#endif /* #if 0 */
- case FMT_MPEG1:
- mpeg1_encode_picture_header(s, picture_number);
- break;
-+/* xine: do not need this for decode or MPEG-1 encoding modes */
-+#if 0
- case FMT_H264:
- break;
-+#endif /* #if 0 */
- default:
- assert(0);
- }
-Index: libavcodec/mpeg12.c
-===================================================================
---- libavcodec/mpeg12.c (revision 7433)
-+++ libavcodec/mpeg12.c (working copy)
-@@ -36,6 +36,13 @@
- //#include <assert.h>
-
-
-+/* if xine's MPEG encoder is enabled, enable the encoding features in
-+ * this particular module */
-+#if defined(XINE_MPEG_ENCODER) && !defined(CONFIG_ENCODERS)
-+#define CONFIG_ENCODERS
-+#endif
-+
-+
- /* Start codes. */
- #define SEQ_END_CODE 0x000001b7
- #define SEQ_START_CODE 0x000001b3
-Index: libavcodec/motion_est.c
-===================================================================
---- libavcodec/motion_est.c (revision 7433)
-+++ libavcodec/motion_est.c (working copy)
-@@ -23,6 +23,9 @@
- * new Motion Estimation (X1/EPZS) by Michael Niedermayer <michaelni@gmx.at>
- */
-
-+/* motion estimation only needed for encoders */
-+#ifdef CONFIG_ENCODERS
-+
- /**
- * @file motion_est.c
- * Motion estimation.
-@@ -2142,3 +2145,5 @@
- }
- }
- }
-+
-+#endif /* CONFIG_ENCODERS */
-Index: libavcodec/snow.c
-===================================================================
---- libavcodec/snow.c (revision 7433)
-+++ libavcodec/snow.c (working copy)
-@@ -487,7 +487,9 @@
- #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)))
-
-+#ifdef CONFIG_ENCODERS
- static void iterative_me(SnowContext *s);
-+#endif
-
- static void slice_buffer_init(slice_buffer * buf, int line_count, int max_allocated_lines, int line_width, DWTELEM * base_buffer)
- {
-@@ -1982,6 +1982,7 @@
- #define P_MV1 P[9]
- #define FLAG_QPEL 1 //must be 1
-
-+#ifdef CONFIG_ENCODERS
- static int encode_q_branch(SnowContext *s, int level, int x, int y){
- uint8_t p_buffer[1024];
- uint8_t i_buffer[1024];
-@@ -2210,6 +2211,7 @@
- return score;
- }
- }
-+#endif
-
- static av_always_inline int same_block(BlockNode *a, BlockNode *b){
- if((a->type&BLOCK_INTRA) && (b->type&BLOCK_INTRA)){
-@@ -2322,6 +2324,7 @@
- }
- }
-
-+#ifdef CONFIG_ENCODERS
- static void encode_blocks(SnowContext *s, int search){
- int x, y;
- int w= s->b_width;
-@@ -2343,6 +2346,7 @@
- }
- }
- }
-+#endif
-
- static void decode_blocks(SnowContext *s){
- int x, y;
-@@ -3182,6 +3184,7 @@
- }
- }
-
-+#ifdef CONFIG_ENCODERS
- static void iterative_me(SnowContext *s){
- int pass, mb_x, mb_y;
- const int b_width = s->b_width << s->block_max_depth;
-@@ -3406,6 +3409,7 @@
- av_log(NULL, AV_LOG_ERROR, "pass:4mv changed:%d\n", change*4);
- }
- }
-+#endif
-
- static void quantize(SnowContext *s, SubBand *b, DWTELEM *src, int stride, int bias){
- const int level= b->level;
-@@ -3931,6 +3935,7 @@
- }
- }
-
-+#ifdef CONFIG_ENCODERS
- static int encode_init(AVCodecContext *avctx)
- {
- SnowContext *s = avctx->priv_data;
-@@ -4018,6 +4023,7 @@
-
- return 0;
- }
-+#endif
-
- static int frame_start(SnowContext *s){
- AVFrame tmp;
-@@ -4056,6 +4062,7 @@
- return 0;
- }
-
-+#ifdef CONFIG_ENCODERS
- static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
- SnowContext *s = avctx->priv_data;
- RangeCoder * const c= &s->c;
-@@ -4308,6 +4315,7 @@
-
- return ff_rac_terminate(c);
- }
-+#endif
-
- static void common_end(SnowContext *s){
- int plane_index, level, orientation, i;
-@@ -4339,6 +4347,7 @@
- }
- }
-
-+#ifdef CONFIG_ENCODERS
- static int encode_end(AVCodecContext *avctx)
- {
- SnowContext *s = avctx->priv_data;
-@@ -4348,6 +4357,7 @@
-
- return 0;
- }
-+#endif
-
- static int decode_init(AVCodecContext *avctx)
- {
-Index: libavcodec/mlib/dsputil_mlib.c
-===================================================================
---- libavcodec/mlib/dsputil_mlib.c (revision 7433)
-+++ libavcodec/mlib/dsputil_mlib.c (working copy)
-@@ -22,6 +22,8 @@
- #include "../dsputil.h"
- #include "../mpegvideo.h"
-
-+#include "../../../xine-utils/xineutils.h"
-+
- #include <mlib_types.h>
- #include <mlib_status.h>
- #include <mlib_sys.h>
-Index: libavcodec/avcodec.h
-===================================================================
---- libavcodec/avcodec.h (revision 7433)
-+++ libavcodec/avcodec.h (working copy)
-@@ -47,6 +47,13 @@
- #define AV_TIME_BASE 1000000
- #define AV_TIME_BASE_Q (AVRational){1, AV_TIME_BASE}
-
-+/* FIXME: We cannot use ffmpeg's XvMC capabilities, since that would require
-+ * linking the ffmpeg plugin against XvMC libraries, which is a bad thing,
-+ * since they are output dependend.
-+ * The correct fix would be to reimplement the XvMC functions libavcodec uses
-+ * and do the necessary talking with our XvMC output plugin there. */
-+#undef HAVE_XVMC
-+
- enum CodecID {
- CODEC_ID_NONE,
- CODEC_ID_MPEG1VIDEO,
-@@ -2688,6 +2695,13 @@
-
- extern unsigned int av_xiphlacing(unsigned char *s, unsigned int v);
-
-+/* unused static macro */
-+#if defined(__GNUC__) && !defined(DEBUG)
-+/* since we do not compile the encoder part of ffmpeg, some static
-+ * functions will be unused; this is ok, the compiler will take care */
-+# define static static __attribute__((__unused__))
-+#endif
-+
- #ifdef __cplusplus
- }
- #endif
diff --git a/src/libffmpeg/ff_audio_decoder.c b/src/libffmpeg/ff_audio_decoder.c
index e0d6e5cab..0e7fab9ce 100644
--- a/src/libffmpeg/ff_audio_decoder.c
+++ b/src/libffmpeg/ff_audio_decoder.c
@@ -25,7 +25,9 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
-#include "ffmpeg_config.h"
+# ifndef HAVE_FFMPEG
+# include "ffmpeg_config.h"
+# endif
#endif
#include <stdlib.h>
@@ -445,105 +447,105 @@ void *init_audio_plugin (xine_t *xine, void *data) {
}
static uint32_t supported_audio_types[] = {
- #ifdef CONFIG_WMAV1_DECODER
+#if defined(HAVE_FFMPEG) || CONFIG_WMAV1_DECODER
BUF_AUDIO_WMAV1,
- #endif
- #ifdef CONFIG_WMAV2_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_WMAV2_DECODER
BUF_AUDIO_WMAV2,
- #endif
- #ifdef CONFIG_RA_144_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_RA_144_DECODER
BUF_AUDIO_14_4,
- #endif
- #ifdef CONFIG_RA_288_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_RA_288_DECODER
BUF_AUDIO_28_8,
- #endif
- #ifdef CONFIG_MP3_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_MP3_DECODER
BUF_AUDIO_MPEG,
- #endif
- #ifdef CONFIG_ADPCM_MS_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_ADPCM_MS_DECODER
BUF_AUDIO_MSADPCM,
- #endif
- #ifdef CONFIG_ADPCM_IMA_QT_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_ADPCM_IMA_QT_DECODER
BUF_AUDIO_QTIMAADPCM,
- #endif
- #ifdef CONFIG_ADPCM_IMA_WAV_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_ADPCM_IMA_WAV_DECODER
BUF_AUDIO_MSIMAADPCM,
- #endif
- #ifdef CONFIG_ADPCM_IMA_DK3_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_ADPCM_IMA_DK3_DECODER
BUF_AUDIO_DK3ADPCM,
- #endif
- #ifdef CONFIG_ADPCM_IMA_DK4_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_ADPCM_IMA_DK4_DECODER
BUF_AUDIO_DK4ADPCM,
- #endif
- #ifdef CONFIG_ADPCM_IMA_WS_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_ADPCM_IMA_WS_DECODER
BUF_AUDIO_VQA_IMA,
- #endif
- #ifdef CONFIG_ADPCM_IMA_SMJPEG_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_ADPCM_IMA_SMJPEG_DECODER
BUF_AUDIO_SMJPEG_IMA,
- #endif
- #ifdef CONFIG_ADPCM_XA_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_ADPCM_XA_DECODER
BUF_AUDIO_XA_ADPCM,
- #endif
- #ifdef CONFIG_ADPCM_4XM_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_ADPCM_4XM_DECODER
BUF_AUDIO_4X_ADPCM,
- #endif
- #ifdef CONFIG_ADPCM_EA_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_ADPCM_EA_DECODER
BUF_AUDIO_EA_ADPCM,
- #endif
- #ifdef CONFIG_PCM_MULAW_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_PCM_MULAW_DECODER
BUF_AUDIO_MULAW,
- #endif
- #ifdef CONFIG_PCM_ALAW_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_PCM_ALAW_DECODER
BUF_AUDIO_ALAW,
- #endif
- #ifdef CONFIG_ROQ_DPCM_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_ROQ_DPCM_DECODER
BUF_AUDIO_ROQ,
- #endif
- #ifdef CONFIG_INTERPLAY_DPCM_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_INTERPLAY_DPCM_DECODER
BUF_AUDIO_INTERPLAY,
- #endif
- #ifdef CONFIG_MACE3_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_MACE3_DECODER
BUF_AUDIO_MAC3,
- #endif
- #ifdef CONFIG_MACE6_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_MACE6_DECODER
BUF_AUDIO_MAC6,
- #endif
- #ifdef CONFIG_XAN_DPCM_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_XAN_DPCM_DECODER
BUF_AUDIO_XAN_DPCM,
- #endif
- #ifdef CONFIG_VMDAUDIO_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_VMDAUDIO_DECODER
BUF_AUDIO_VMD,
- #endif
- #ifdef CONFIG_FLAC_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_FLAC_DECODER
BUF_AUDIO_FLAC,
- #endif
- #ifdef CONFIG_SHORTEN_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_SHORTEN_DECODER
BUF_AUDIO_SHORTEN,
- #endif
- #ifdef CONFIG_ALAC_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_ALAC_DECODER
BUF_AUDIO_ALAC,
- #endif
- #ifdef CONFIG_QDM2_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_QDM2_DECODER
BUF_AUDIO_QDESIGN2,
- #endif
- #ifdef CONFIG_COOK_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_COOK_DECODER
BUF_AUDIO_COOK,
- #endif
- #ifdef CONFIG_TRUESPEECH_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_TRUESPEECH_DECODER
BUF_AUDIO_TRUESPEECH,
- #endif
- #ifdef CONFIG_TTA_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_TTA_DECODER
BUF_AUDIO_TTA,
- #endif
- #ifdef CONFIG_SMACKAUDIO_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_SMACKAUDIO_DECODER
BUF_AUDIO_SMACKER,
- #endif
- #ifdef CONFIG_ADPCM_SWF_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_ADPCM_SWF_DECODER
BUF_AUDIO_FLVADPCM,
- #endif
- #ifdef CONFIG_WAVPACK_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_WAVPACK_DECODER
BUF_AUDIO_WAVPACK,
- #endif
+#endif
0
};
diff --git a/src/libffmpeg/ff_dvaudio_decoder.c b/src/libffmpeg/ff_dvaudio_decoder.c
index 2c851bae1..985165611 100644
--- a/src/libffmpeg/ff_dvaudio_decoder.c
+++ b/src/libffmpeg/ff_dvaudio_decoder.c
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
- * $Id: dvaudio_decoder.c,v 1.12 2006/12/04 22:25:13 miguelfreitas Exp $
+ * $Id: dvaudio_decoder.c,v 1.11 2006/07/10 22:08:29 dgp85 Exp $
*
* dv audio decoder based on patch by Dan Dennedy <dan@dennedy.org>
*
@@ -55,13 +55,8 @@
# undef uint64_t
#endif
-#ifdef HAVE_FFMPEG
-# include <avcodec.h>
-# include "libavcodec/dvdata.h"
-#else
-# include "libavcodec/avcodec.h"
-# include "libavcodec/dvdata.h"
-#endif
+#include <avcodec.h>
+#include <dvdata.h> /* This is not installed by FFmpeg, its usage has to be cleared up */
#ifdef _MSC_VER
# undef malloc
@@ -96,7 +91,6 @@ typedef struct dvaudio_decoder_s {
} dvaudio_decoder_t;
-
/*
* This is the dumbest implementation of all -- it simply looks at
* a fixed offset and if pack isn't there -- fails. We might want
diff --git a/src/libffmpeg/ff_video_decoder.c b/src/libffmpeg/ff_video_decoder.c
index 3943fd05d..d7d162387 100644
--- a/src/libffmpeg/ff_video_decoder.c
+++ b/src/libffmpeg/ff_video_decoder.c
@@ -25,7 +25,9 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
-#include "ffmpeg_config.h"
+# ifndef HAVE_FFMPEG
+# include "ffmpeg_config.h"
+# endif
#endif
#include <stdlib.h>
@@ -48,11 +50,7 @@
#include "ffmpeg_decoder.h"
#include "ff_mpeg_parser.h"
-#ifdef HAVE_FFMPEG
-# include <postprocess.h>
-#else
-# include "libavcodec/libpostproc/postprocess.h"
-#endif
+#include <postprocess.h>
#define VIDEOBUFSIZE (128*1024)
#define SLICE_BUFFER_SIZE (1194*1024)
@@ -1530,223 +1528,223 @@ void *init_video_plugin (xine_t *xine, void *data) {
}
static uint32_t supported_video_types[] = {
- #ifdef CONFIG_MSMPEG4V1_DECODER
+#if defined(HAVE_FFMPEG) || CONFIG_MSMPEG4V1_DECODER
BUF_VIDEO_MSMPEG4_V1,
- #endif
- #ifdef CONFIG_MSMPEG4V2_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_MSMPEG4V2_DECODER
BUF_VIDEO_MSMPEG4_V2,
- #endif
- #ifdef CONFIG_MSMPEG4V3_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_MSMPEG4V3_DECODER
BUF_VIDEO_MSMPEG4_V3,
- #endif
- #ifdef CONFIG_WMV1_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_WMV1_DECODER
BUF_VIDEO_WMV7,
- #endif
- #ifdef CONFIG_WMV2_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_WMV2_DECODER
BUF_VIDEO_WMV8,
- #endif
- #ifdef CONFIG_WMV3_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_WMV3_DECODER
BUF_VIDEO_WMV9,
- #endif
- #ifdef CONFIG_MPEG4_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_MPEG4_DECODER
BUF_VIDEO_MPEG4,
- #endif
- #ifdef CONFIG_MPEG4_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_MPEG4_DECODER
BUF_VIDEO_XVID,
- #endif
- #ifdef CONFIG_MPEG4_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_MPEG4_DECODER
BUF_VIDEO_DIVX5,
- #endif
- #ifdef CONFIG_MPEG4_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_MPEG4_DECODER
BUF_VIDEO_3IVX,
- #endif
- #ifdef CONFIG_MJPEG_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_MJPEG_DECODER
BUF_VIDEO_JPEG,
- #endif
- #ifdef CONFIG_MJPEG_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_MJPEG_DECODER
BUF_VIDEO_MJPEG,
- #endif
- #ifdef CONFIG_MJPEGB_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_MJPEGB_DECODER
BUF_VIDEO_MJPEG_B,
- #endif
- #ifdef CONFIG_H263I_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_H263I_DECODER
BUF_VIDEO_I263,
- #endif
- #ifdef CONFIG_H263_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_H263_DECODER
BUF_VIDEO_H263,
- #endif
- #ifdef CONFIG_RV10_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_RV10_DECODER
BUF_VIDEO_RV10,
- #endif
- #ifdef CONFIG_RV20_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_RV20_DECODER
BUF_VIDEO_RV20,
- #endif
- #ifdef CONFIG_INDEO3_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_INDEO3_DECODER
BUF_VIDEO_IV31,
- #endif
- #ifdef CONFIG_INDEO3_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_INDEO3_DECODER
BUF_VIDEO_IV32,
- #endif
- #ifdef CONFIG_SVQ1_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_SVQ1_DECODER
BUF_VIDEO_SORENSON_V1,
- #endif
- #ifdef CONFIG_SVQ3_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_SVQ3_DECODER
BUF_VIDEO_SORENSON_V3,
- #endif
- #ifdef CONFIG_DVVIDEO_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_DVVIDEO_DECODER
BUF_VIDEO_DV,
- #endif
- #ifdef CONFIG_HUFFYUV_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_HUFFYUV_DECODER
BUF_VIDEO_HUFFYUV,
- #endif
- #ifdef CONFIG_VP3_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_VP3_DECODER
BUF_VIDEO_VP31,
- #endif
- #ifdef CONFIG_VP5_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_VP5_DECODER
BUF_VIDEO_VP5,
- #endif
- #ifdef CONFIG_VP6_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_VP6_DECODER
BUF_VIDEO_VP6,
BUF_VIDEO_VP6F,
- #endif
- #ifdef CONFIG_4XM_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_4XM_DECODER
BUF_VIDEO_4XM,
- #endif
- #ifdef CONFIG_CINEPAK_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_CINEPAK_DECODER
BUF_VIDEO_CINEPAK,
- #endif
- #ifdef CONFIG_MSVIDEO1_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_MSVIDEO1_DECODER
BUF_VIDEO_MSVC,
- #endif
- #ifdef CONFIG_MSRLE_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_MSRLE_DECODER
BUF_VIDEO_MSRLE,
- #endif
- #ifdef CONFIG_RPZA_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_RPZA_DECODER
BUF_VIDEO_RPZA,
- #endif
- #ifdef CONFIG_CYUV_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_CYUV_DECODER
BUF_VIDEO_CYUV,
- #endif
- #ifdef CONFIG_ROQ_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_ROQ_DECODER
BUF_VIDEO_ROQ,
- #endif
- #ifdef CONFIG_IDCIN_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_IDCIN_DECODER
BUF_VIDEO_IDCIN,
- #endif
- #ifdef CONFIG_XAN_WC3_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_XAN_WC3_DECODER
BUF_VIDEO_WC3,
- #endif
- #ifdef CONFIG_WS_VQA_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_WS_VQA_DECODER
BUF_VIDEO_VQA,
- #endif
- #ifdef CONFIG_INTERPLAY_VIDEO_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_INTERPLAY_VIDEO_DECODER
BUF_VIDEO_INTERPLAY,
- #endif
- #ifdef CONFIG_FLIC_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_FLIC_DECODER
BUF_VIDEO_FLI,
- #endif
- #ifdef CONFIG_8BPS_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_8BPS_DECODER
BUF_VIDEO_8BPS,
- #endif
- #ifdef CONFIG_SMC_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_SMC_DECODER
BUF_VIDEO_SMC,
- #endif
- #ifdef CONFIG_TRUEMOTION1_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_TRUEMOTION1_DECODER
BUF_VIDEO_DUCKTM1,
- #endif
- #ifdef CONFIG_TRUEMOTION2_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_TRUEMOTION2_DECODER
BUF_VIDEO_DUCKTM2,
- #endif
- #ifdef CONFIG_VMDVIDEO_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_VMDVIDEO_DECODER
BUF_VIDEO_VMD,
- #endif
- #ifdef CONFIG_ZLIB_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_ZLIB_DECODER
BUF_VIDEO_ZLIB,
- #endif
- #ifdef CONFIG_MSZH_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_MSZH_DECODER
BUF_VIDEO_MSZH,
- #endif
- #ifdef CONFIG_ASV1_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_ASV1_DECODER
BUF_VIDEO_ASV1,
- #endif
- #ifdef CONFIG_ASV2_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_ASV2_DECODER
BUF_VIDEO_ASV2,
- #endif
- #ifdef CONFIG_VCR1_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_VCR1_DECODER
BUF_VIDEO_ATIVCR1,
- #endif
- #ifdef CONFIG_FLV_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_FLV_DECODER
BUF_VIDEO_FLV1,
- #endif
- #ifdef CONFIG_QTRLE_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_QTRLE_DECODER
BUF_VIDEO_QTRLE,
- #endif
- #ifdef CONFIG_H264_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_H264_DECODER
BUF_VIDEO_H264,
- #endif
- #ifdef CONFIG_H261_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_H261_DECODER
BUF_VIDEO_H261,
- #endif
- #ifdef CONFIG_AASC_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_AASC_DECODER
BUF_VIDEO_AASC,
- #endif
- #ifdef CONFIG_LOCO_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_LOCO_DECODER
BUF_VIDEO_LOCO,
- #endif
- #ifdef CONFIG_QDRAW_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_QDRAW_DECODER
BUF_VIDEO_QDRW,
- #endif
- #ifdef CONFIG_QPEG_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_QPEG_DECODER
BUF_VIDEO_QPEG,
- #endif
- #ifdef CONFIG_TSCC_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_TSCC_DECODER
BUF_VIDEO_TSCC,
- #endif
- #ifdef CONFIG_ULTI_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_ULTI_DECODER
BUF_VIDEO_ULTI,
- #endif
- #ifdef CONFIG_WNV1_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_WNV1_DECODER
BUF_VIDEO_WNV1,
- #endif
- #ifdef CONFIG_VIXL_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_VIXL_DECODER
BUF_VIDEO_XL,
- #endif
- #ifdef CONFIG_INDEO2_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_INDEO2_DECODER
BUF_VIDEO_RT21,
- #endif
- #ifdef CONFIG_FRAPS_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_FRAPS_DECODER
BUF_VIDEO_FPS1,
- #endif
- #ifdef CONFIG_MPEG1VIDEO_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_MPEG1VIDEO_DECODER
BUF_VIDEO_MPEG,
- #endif
- #ifdef CONFIG_CSCD_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_CSCD_DECODER
BUF_VIDEO_CSCD,
- #endif
- #ifdef CONFIG_AVS_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_AVS_DECODER
BUF_VIDEO_AVS,
- #endif
- #ifdef CONFIG_MMVIDEO_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_MMVIDEO_DECODER
BUF_VIDEO_ALGMM,
- #endif
- #ifdef CONFIG_ZMBV_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_ZMBV_DECODER
BUF_VIDEO_ZMBV,
- #endif
- #ifdef CONFIG_SMACKVIDEO_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_SMACKVIDEO_DECODER
BUF_VIDEO_SMACKER,
- #endif
- #ifdef CONFIG_NUV_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_NUV_DECODER
BUF_VIDEO_NUV,
- #endif
- #ifdef CONFIG_KMVC_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_KMVC_DECODER
BUF_VIDEO_KMVC,
- #endif
- #ifdef CONFIG_FLASHSV_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_FLASHSV_DECODER
BUF_VIDEO_FLASHSV,
- #endif
- #ifdef CONFIG_CAVS_DECODER
+#endif
+#if defined(HAVE_FFMPEG) || CONFIG_CAVS_DECODER
BUF_VIDEO_CAVS,
- #endif
+#endif
0
};
diff --git a/src/libffmpeg/ffmpeg_decoder.c b/src/libffmpeg/ffmpeg_decoder.c
index 6f85cc1fa..9f1db0c6d 100644
--- a/src/libffmpeg/ffmpeg_decoder.c
+++ b/src/libffmpeg/ffmpeg_decoder.c
@@ -25,7 +25,6 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
-#include "ffmpeg_config.h"
#endif
#include "xine_internal.h"
@@ -39,276 +38,6 @@
pthread_once_t once_control = PTHREAD_ONCE_INIT;
pthread_mutex_t ffmpeg_lock;
-#ifndef HAVE_FFMPEG
-
-#define REGISTER_ENCODER(X,x) \
- if(ENABLE_##X##_ENCODER) register_avcodec(&x##_encoder)
-#define REGISTER_DECODER(X,x) \
- if(ENABLE_##X##_DECODER) register_avcodec(&x##_decoder)
-#define REGISTER_ENCDEC(X,x) REGISTER_ENCODER(X,x); REGISTER_DECODER(X,x)
-
-#define REGISTER_PARSER(X,x) \
- if(ENABLE_##X##_PARSER) av_register_codec_parser(&x##_parser)
-
-/* If you do not call this function, then you can select exactly which
- formats you want to support */
-
-/**
- * simple call to register all the codecs.
- */
-void avcodec_register_all(void)
-{
- static int inited = 0;
-
- if (inited != 0)
- return;
- inited = 1;
-
- /* video codecs */
- REGISTER_DECODER(AASC, aasc);
- REGISTER_ENCDEC (ASV1, asv1);
- REGISTER_ENCDEC (ASV2, asv2);
- REGISTER_DECODER(AVS, avs);
- REGISTER_DECODER(BMP, bmp);
- REGISTER_DECODER(CAVS, cavs);
- REGISTER_DECODER(CINEPAK, cinepak);
- REGISTER_DECODER(CLJR, cljr);
- REGISTER_DECODER(CSCD, cscd);
- REGISTER_DECODER(CYUV, cyuv);
- REGISTER_DECODER(DSICINVIDEO, dsicinvideo);
- REGISTER_ENCDEC (DVVIDEO, dvvideo);
- REGISTER_DECODER(EIGHTBPS, eightbps);
- REGISTER_ENCDEC (FFV1, ffv1);
- REGISTER_ENCDEC (FFVHUFF, ffvhuff);
- REGISTER_DECODER(FLASHSV, flashsv);
- REGISTER_DECODER(FLIC, flic);
- REGISTER_ENCDEC (FLV, flv);
- REGISTER_DECODER(FOURXM, fourxm);
- REGISTER_DECODER(FRAPS, fraps);
- REGISTER_ENCDEC (GIF, gif);
- REGISTER_ENCDEC (H261, h261);
- REGISTER_ENCDEC (H263, h263);
- REGISTER_DECODER(H263I, h263i);
- REGISTER_ENCODER(H263P, h263p);
- REGISTER_DECODER(H264, h264);
- REGISTER_ENCDEC (HUFFYUV, huffyuv);
- REGISTER_DECODER(IDCIN, idcin);
- REGISTER_DECODER(INDEO2, indeo2);
- REGISTER_DECODER(INDEO3, indeo3);
- REGISTER_DECODER(INTERPLAY_VIDEO, interplay_video);
- REGISTER_ENCODER(JPEGLS, jpegls);
- REGISTER_DECODER(KMVC, kmvc);
- REGISTER_ENCODER(LJPEG, ljpeg);
- REGISTER_DECODER(LOCO, loco);
- REGISTER_DECODER(MDEC, mdec);
- REGISTER_ENCDEC (MJPEG, mjpeg);
- REGISTER_DECODER(MJPEGB, mjpegb);
- REGISTER_DECODER(MMVIDEO, mmvideo);
-#ifdef HAVE_XVMC
- REGISTER_DECODER(MPEG_XVMC, mpeg_xvmc);
-#endif
- REGISTER_ENCDEC (MPEG1VIDEO, mpeg1video);
- REGISTER_ENCDEC (MPEG2VIDEO, mpeg2video);
- REGISTER_ENCDEC (MPEG4, mpeg4);
- REGISTER_DECODER(MPEGVIDEO, mpegvideo);
- REGISTER_ENCDEC (MSMPEG4V1, msmpeg4v1);
- REGISTER_ENCDEC (MSMPEG4V2, msmpeg4v2);
- REGISTER_ENCDEC (MSMPEG4V3, msmpeg4v3);
- REGISTER_DECODER(MSRLE, msrle);
- REGISTER_DECODER(MSVIDEO1, msvideo1);
- REGISTER_DECODER(MSZH, mszh);
- REGISTER_DECODER(NUV, nuv);
- REGISTER_ENCODER(PAM, pam);
- REGISTER_ENCODER(PBM, pbm);
- REGISTER_ENCODER(PGM, pgm);
- REGISTER_ENCODER(PGMYUV, pgmyuv);
-#ifdef CONFIG_ZLIB
- REGISTER_ENCDEC (PNG, png);
-#endif
- REGISTER_ENCODER(PPM, ppm);
- REGISTER_DECODER(QDRAW, qdraw);
- REGISTER_DECODER(QPEG, qpeg);
- REGISTER_DECODER(QTRLE, qtrle);
- REGISTER_ENCDEC (RAWVIDEO, rawvideo);
- REGISTER_DECODER(ROQ, roq);
- REGISTER_DECODER(RPZA, rpza);
- REGISTER_ENCDEC (RV10, rv10);
- REGISTER_ENCDEC (RV20, rv20);
- REGISTER_DECODER(SMACKER, smacker);
- REGISTER_DECODER(SMC, smc);
- REGISTER_ENCDEC (SNOW, snow);
- REGISTER_DECODER(SP5X, sp5x);
- REGISTER_ENCDEC (SVQ1, svq1);
- REGISTER_DECODER(SVQ3, svq3);
- REGISTER_DECODER(TARGA, targa);
- REGISTER_DECODER(THEORA, theora);
- REGISTER_DECODER(TIERTEXSEQVIDEO, tiertexseqvideo);
- REGISTER_DECODER(TIFF, tiff);
- REGISTER_DECODER(TRUEMOTION1, truemotion1);
- REGISTER_DECODER(TRUEMOTION2, truemotion2);
- REGISTER_DECODER(TSCC, tscc);
- REGISTER_DECODER(ULTI, ulti);
- REGISTER_DECODER(VC1, vc1);
- REGISTER_DECODER(VCR1, vcr1);
- REGISTER_DECODER(VMDVIDEO, vmdvideo);
- REGISTER_DECODER(VMNC, vmnc);
- REGISTER_DECODER(VP3, vp3);
- REGISTER_DECODER(VP5, vp5);
- REGISTER_DECODER(VP6, vp6);
- REGISTER_DECODER(VP6F, vp6f);
- REGISTER_DECODER(VQA, vqa);
- REGISTER_ENCDEC (WMV1, wmv1);
- REGISTER_ENCDEC (WMV2, wmv2);
- REGISTER_DECODER(WMV3, wmv3);
- REGISTER_DECODER(WNV1, wnv1);
-#ifdef CONFIG_X264
- REGISTER_ENCODER(X264, x264);
-#endif
- REGISTER_DECODER(XAN_WC3, xan_wc3);
- REGISTER_DECODER(XL, xl);
-#ifdef CONFIG_XVID
- REGISTER_ENCODER(XVID, xvid);
-#endif
- REGISTER_ENCDEC (ZLIB, zlib);
-#ifdef CONFIG_ZLIB
- REGISTER_ENCDEC (ZMBV, zmbv);
-#endif
-
- /* audio codecs */
-#ifdef CONFIG_LIBFAAD
- REGISTER_DECODER(AAC, aac);
- REGISTER_DECODER(MPEG4AAC, mpeg4aac);
-#endif
-#ifdef CONFIG_LIBA52
- REGISTER_DECODER(AC3, ac3);
-#endif
- REGISTER_ENCODER(AC3, ac3);
- REGISTER_DECODER(ALAC, alac);
-#if defined(CONFIG_AMR_NB) || defined(CONFIG_AMR_NB_FIXED)
- REGISTER_ENCDEC (AMR_NB, amr_nb);
-#endif
-#ifdef CONFIG_AMR_WB
- REGISTER_ENCDEC (AMR_WB, amr_wb);
-#endif
- REGISTER_DECODER(COOK, cook);
- REGISTER_DECODER(DSICINAUDIO, dsicinaudio);
-#ifdef CONFIG_LIBDTS
- REGISTER_DECODER(DTS, dts);
-#endif
-#ifdef CONFIG_LIBFAAC
- REGISTER_ENCODER(FAAC, faac);
-#endif
- REGISTER_ENCDEC (FLAC, flac);
- REGISTER_DECODER(IMC, imc);
-#ifdef CONFIG_LIBGSM
- REGISTER_ENCDEC (LIBGSM, libgsm);
-#endif
- REGISTER_DECODER(MACE3, mace3);
- REGISTER_DECODER(MACE6, mace6);
- REGISTER_ENCDEC (MP2, mp2);
- REGISTER_DECODER(MP3, mp3);
- REGISTER_DECODER(MP3ADU, mp3adu);
-#ifdef CONFIG_LIBMP3LAME
- REGISTER_ENCODER(MP3LAME, mp3lame);
-#endif
- REGISTER_DECODER(MP3ON4, mp3on4);
- REGISTER_DECODER(MPC7, mpc7);
-#ifdef CONFIG_LIBVORBIS
- if (!ENABLE_VORBIS_ENCODER) REGISTER_ENCODER(OGGVORBIS, oggvorbis);
- if (!ENABLE_VORBIS_DECODER) REGISTER_DECODER(OGGVORBIS, oggvorbis);
-#endif
- REGISTER_DECODER(QDM2, qdm2);
- REGISTER_DECODER(RA_144, ra_144);
- REGISTER_DECODER(RA_288, ra_288);
- REGISTER_DECODER(SHORTEN, shorten);
- REGISTER_DECODER(SMACKAUD, smackaud);
- REGISTER_ENCDEC (SONIC, sonic);
- REGISTER_ENCODER(SONIC_LS, sonic_ls);
- REGISTER_DECODER(TRUESPEECH, truespeech);
- REGISTER_DECODER(TTA, tta);
- REGISTER_DECODER(VMDAUDIO, vmdaudio);
- REGISTER_ENCDEC (VORBIS, vorbis);
- REGISTER_DECODER(WAVPACK, wavpack);
- REGISTER_DECODER(WMAV1, wmav1);
- REGISTER_DECODER(WMAV2, wmav2);
- REGISTER_DECODER(WS_SND1, ws_snd1);
-
- /* pcm codecs */
- REGISTER_ENCDEC (PCM_ALAW, pcm_alaw);
- REGISTER_ENCDEC (PCM_MULAW, pcm_mulaw);
- REGISTER_ENCDEC (PCM_S8, pcm_s8);
- REGISTER_ENCDEC (PCM_S16BE, pcm_s16be);
- REGISTER_ENCDEC (PCM_S16LE, pcm_s16le);
- REGISTER_ENCDEC (PCM_S24BE, pcm_s24be);
- REGISTER_ENCDEC (PCM_S24DAUD, pcm_s24daud);
- REGISTER_ENCDEC (PCM_S24LE, pcm_s24le);
- REGISTER_ENCDEC (PCM_S32BE, pcm_s32be);
- REGISTER_ENCDEC (PCM_S32LE, pcm_s32le);
- REGISTER_ENCDEC (PCM_U8, pcm_u8);
- REGISTER_ENCDEC (PCM_U16BE, pcm_u16be);
- REGISTER_ENCDEC (PCM_U16LE, pcm_u16le);
- REGISTER_ENCDEC (PCM_U24BE, pcm_u24be);
- REGISTER_ENCDEC (PCM_U24LE, pcm_u24le);
- REGISTER_ENCDEC (PCM_U32BE, pcm_u32be);
- REGISTER_ENCDEC (PCM_U32LE, pcm_u32le);
-
- /* dpcm codecs */
- REGISTER_DECODER(INTERPLAY_DPCM, interplay_dpcm);
- REGISTER_DECODER(ROQ_DPCM, roq_dpcm);
- REGISTER_DECODER(SOL_DPCM, sol_dpcm);
- REGISTER_DECODER(XAN_DPCM, xan_dpcm);
-
- /* adpcm codecs */
- REGISTER_ENCDEC (ADPCM_4XM, adpcm_4xm);
- REGISTER_ENCDEC (ADPCM_ADX, adpcm_adx);
- REGISTER_ENCDEC (ADPCM_CT, adpcm_ct);
- REGISTER_ENCDEC (ADPCM_EA, adpcm_ea);
- REGISTER_ENCDEC (ADPCM_G726, adpcm_g726);
- REGISTER_ENCDEC (ADPCM_IMA_DK3, adpcm_ima_dk3);
- REGISTER_ENCDEC (ADPCM_IMA_DK4, adpcm_ima_dk4);
- REGISTER_ENCDEC (ADPCM_IMA_QT, adpcm_ima_qt);
- REGISTER_ENCDEC (ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg);
- REGISTER_ENCDEC (ADPCM_IMA_WAV, adpcm_ima_wav);
- REGISTER_ENCDEC (ADPCM_IMA_WS, adpcm_ima_ws);
- REGISTER_ENCDEC (ADPCM_MS, adpcm_ms);
- REGISTER_ENCDEC (ADPCM_SBPRO_2, adpcm_sbpro_2);
- REGISTER_ENCDEC (ADPCM_SBPRO_3, adpcm_sbpro_3);
- REGISTER_ENCDEC (ADPCM_SBPRO_4, adpcm_sbpro_4);
- REGISTER_ENCDEC (ADPCM_SWF, adpcm_swf);
- REGISTER_ENCDEC (ADPCM_XA, adpcm_xa);
- REGISTER_ENCDEC (ADPCM_YAMAHA, adpcm_yamaha);
-
- /* subtitles */
- REGISTER_ENCDEC (DVBSUB, dvbsub);
- REGISTER_ENCDEC (DVDSUB, dvdsub);
-
- /* parsers */
- REGISTER_PARSER (AAC, aac);
- REGISTER_PARSER (AC3, ac3);
- REGISTER_PARSER (CAVSVIDEO, cavsvideo);
- REGISTER_PARSER (DVBSUB, dvbsub);
- REGISTER_PARSER (DVDSUB, dvdsub);
- REGISTER_PARSER (H261, h261);
- REGISTER_PARSER (H263, h263);
- REGISTER_PARSER (H264, h264);
- REGISTER_PARSER (MJPEG, mjpeg);
- REGISTER_PARSER (MPEG4VIDEO, mpeg4video);
- REGISTER_PARSER (MPEGAUDIO, mpegaudio);
- REGISTER_PARSER (MPEGVIDEO, mpegvideo);
- REGISTER_PARSER (PNM, pnm);
-
- /*
- av_register_bitstream_filter(&dump_extradata_bsf);
- av_register_bitstream_filter(&remove_extradata_bsf);
- av_register_bitstream_filter(&noise_bsf);
- av_register_bitstream_filter(&mp3_header_compress_bsf);
- av_register_bitstream_filter(&mp3_header_decompress_bsf);
- av_register_bitstream_filter(&mjpega_dump_header_bsf);
- */
-}
-
-#endif
-
void init_once_routine(void) {
pthread_mutex_init(&ffmpeg_lock, NULL);
avcodec_init();
diff --git a/src/libffmpeg/ffmpeg_decoder.h b/src/libffmpeg/ffmpeg_decoder.h
index 879ee3175..f005f09e5 100644
--- a/src/libffmpeg/ffmpeg_decoder.h
+++ b/src/libffmpeg/ffmpeg_decoder.h
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
- * $Id: xine_decoder.h,v 1.7 2006/08/02 07:15:27 tmmm Exp $
+ * $Id: xine_decoder.h,v 1.7.2.1 2006/12/02 01:20:07 dgp85 Exp $
*
*/
@@ -28,11 +28,7 @@
#include "config.h"
#endif
-#ifdef HAVE_FFMPEG
-# include <avcodec.h>
-#else
-# include "libavcodec/avcodec.h"
-#endif
+#include <avcodec.h>
typedef struct ff_codec_s {
uint32_t type;
diff --git a/src/libffmpeg/ffmpeg_encoder.c b/src/libffmpeg/ffmpeg_encoder.c
index e234b4ddc..8db721002 100644
--- a/src/libffmpeg/ffmpeg_encoder.c
+++ b/src/libffmpeg/ffmpeg_encoder.c
@@ -40,11 +40,7 @@
#include "video_out_dxr3.h"
-#ifdef HAVE_FFMPEG
-# include <avcodec.h>
-#else
-# include "libavcodec/avcodec.h"
-#endif
+#include <avcodec.h>
/* buffer size for encoded mpeg1 stream; will hold one intra frame
* at 640x480 typical sizes are <50 kB. 512 kB should be plenty */
diff --git a/src/libffmpeg/libavcodec/4xm.c b/src/libffmpeg/libavcodec/4xm.c
deleted file mode 100644
index ea60e9bf2..000000000
--- a/src/libffmpeg/libavcodec/4xm.c
+++ /dev/null
@@ -1,759 +0,0 @@
-/*
- * 4XM codec
- * 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 4xm.c
- * 4XM codec.
- */
-
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-
-//#undef NDEBUG
-//#include <assert.h>
-
-#define BLOCK_TYPE_VLC_BITS 5
-#define ACDC_VLC_BITS 9
-
-#define CFRAME_BUFFER_COUNT 100
-
-static const uint8_t block_type_tab[4][8][2]={
- { //{8,4,2}x{8,4,2}
- { 0,1}, { 2,2}, { 6,3}, {14,4}, {30,5}, {31,5}, { 0,0}
- },{ //{8,4}x1
- { 0,1}, { 0,0}, { 2,2}, { 6,3}, {14,4}, {15,4}, { 0,0}
- },{ //1x{8,4}
- { 0,1}, { 2,2}, { 0,0}, { 6,3}, {14,4}, {15,4}, { 0,0}
- },{ //1x2, 2x1
- { 0,1}, { 0,0}, { 0,0}, { 2,2}, { 6,3}, {14,4}, {15,4}
- }
-};
-
-static const uint8_t size2index[4][4]={
- {-1, 3, 1, 1},
- { 3, 0, 0, 0},
- { 2, 0, 0, 0},
- { 2, 0, 0, 0},
-};
-
-static const int8_t mv[256][2]={
-{ 0, 0},{ 0, -1},{ -1, 0},{ 1, 0},{ 0, 1},{ -1, -1},{ 1, -1},{ -1, 1},
-{ 1, 1},{ 0, -2},{ -2, 0},{ 2, 0},{ 0, 2},{ -1, -2},{ 1, -2},{ -2, -1},
-{ 2, -1},{ -2, 1},{ 2, 1},{ -1, 2},{ 1, 2},{ -2, -2},{ 2, -2},{ -2, 2},
-{ 2, 2},{ 0, -3},{ -3, 0},{ 3, 0},{ 0, 3},{ -1, -3},{ 1, -3},{ -3, -1},
-{ 3, -1},{ -3, 1},{ 3, 1},{ -1, 3},{ 1, 3},{ -2, -3},{ 2, -3},{ -3, -2},
-{ 3, -2},{ -3, 2},{ 3, 2},{ -2, 3},{ 2, 3},{ 0, -4},{ -4, 0},{ 4, 0},
-{ 0, 4},{ -1, -4},{ 1, -4},{ -4, -1},{ 4, -1},{ 4, 1},{ -1, 4},{ 1, 4},
-{ -3, -3},{ -3, 3},{ 3, 3},{ -2, -4},{ -4, -2},{ 4, -2},{ -4, 2},{ -2, 4},
-{ 2, 4},{ -3, -4},{ 3, -4},{ 4, -3},{ -5, 0},{ -4, 3},{ -3, 4},{ 3, 4},
-{ -1, -5},{ -5, -1},{ -5, 1},{ -1, 5},{ -2, -5},{ 2, -5},{ 5, -2},{ 5, 2},
-{ -4, -4},{ -4, 4},{ -3, -5},{ -5, -3},{ -5, 3},{ 3, 5},{ -6, 0},{ 0, 6},
-{ -6, -1},{ -6, 1},{ 1, 6},{ 2, -6},{ -6, 2},{ 2, 6},{ -5, -4},{ 5, 4},
-{ 4, 5},{ -6, -3},{ 6, 3},{ -7, 0},{ -1, -7},{ 5, -5},{ -7, 1},{ -1, 7},
-{ 4, -6},{ 6, 4},{ -2, -7},{ -7, 2},{ -3, -7},{ 7, -3},{ 3, 7},{ 6, -5},
-{ 0, -8},{ -1, -8},{ -7, -4},{ -8, 1},{ 4, 7},{ 2, -8},{ -2, 8},{ 6, 6},
-{ -8, 3},{ 5, -7},{ -5, 7},{ 8, -4},{ 0, -9},{ -9, -1},{ 1, 9},{ 7, -6},
-{ -7, 6},{ -5, -8},{ -5, 8},{ -9, 3},{ 9, -4},{ 7, -7},{ 8, -6},{ 6, 8},
-{ 10, 1},{-10, 2},{ 9, -5},{ 10, -3},{ -8, -7},{-10, -4},{ 6, -9},{-11, 0},
-{ 11, 1},{-11, -2},{ -2, 11},{ 7, -9},{ -7, 9},{ 10, 6},{ -4, 11},{ 8, -9},
-{ 8, 9},{ 5, 11},{ 7,-10},{ 12, -3},{ 11, 6},{ -9, -9},{ 8, 10},{ 5, 12},
-{-11, 7},{ 13, 2},{ 6,-12},{ 10, 9},{-11, 8},{ -7, 12},{ 0, 14},{ 14, -2},
-{ -9, 11},{ -6, 13},{-14, -4},{ -5,-14},{ 5, 14},{-15, -1},{-14, -6},{ 3,-15},
-{ 11,-11},{ -7, 14},{ -5, 15},{ 8,-14},{ 15, 6},{ 3, 16},{ 7,-15},{-16, 5},
-{ 0, 17},{-16, -6},{-10, 14},{-16, 7},{ 12, 13},{-16, 8},{-17, 6},{-18, 3},
-{ -7, 17},{ 15, 11},{ 16, 10},{ 2,-19},{ 3,-19},{-11,-16},{-18, 8},{-19, -6},
-{ 2,-20},{-17,-11},{-10,-18},{ 8, 19},{-21, -1},{-20, 7},{ -4, 21},{ 21, 5},
-{ 15, 16},{ 2,-22},{-10,-20},{-22, 5},{ 20,-11},{ -7,-22},{-12, 20},{ 23, -5},
-{ 13,-20},{ 24, -2},{-15, 19},{-11, 22},{ 16, 19},{ 23,-10},{-18,-18},{ -9,-24},
-{ 24,-10},{ -3, 26},{-23, 13},{-18,-20},{ 17, 21},{ -4, 27},{ 27, 6},{ 1,-28},
-{-11, 26},{-17,-23},{ 7, 28},{ 11,-27},{ 29, 5},{-23,-19},{-28,-11},{-21, 22},
-{-30, 7},{-17, 26},{-27, 16},{ 13, 29},{ 19,-26},{ 10,-31},{-14,-30},{ 20,-27},
-{-29, 18},{-16,-31},{-28,-22},{ 21,-30},{-25, 28},{ 26,-29},{ 25,-32},{-32,-32}
-};
-
-// this is simply the scaled down elementwise product of the standard jpeg quantizer table and the AAN premul table
-static const uint8_t dequant_table[64]={
- 16, 15, 13, 19, 24, 31, 28, 17,
- 17, 23, 25, 31, 36, 63, 45, 21,
- 18, 24, 27, 37, 52, 59, 49, 20,
- 16, 28, 34, 40, 60, 80, 51, 20,
- 18, 31, 48, 66, 68, 86, 56, 21,
- 19, 38, 56, 59, 64, 64, 48, 20,
- 27, 48, 55, 55, 56, 51, 35, 15,
- 20, 35, 34, 32, 31, 22, 15, 8,
-};
-
-static VLC block_type_vlc[4];
-
-
-typedef struct CFrameBuffer{
- unsigned int allocated_size;
- unsigned int size;
- int id;
- uint8_t *data;
-}CFrameBuffer;
-
-typedef struct FourXContext{
- AVCodecContext *avctx;
- DSPContext dsp;
- AVFrame current_picture, last_picture;
- GetBitContext pre_gb; ///< ac/dc prefix
- GetBitContext gb;
- uint8_t *bytestream;
- uint16_t *wordstream;
- int mv[256];
- VLC pre_vlc;
- int last_dc;
- DECLARE_ALIGNED_8(DCTELEM, block[6][64]);
- uint8_t *bitstream_buffer;
- unsigned int bitstream_buffer_size;
- CFrameBuffer cfrm[CFRAME_BUFFER_COUNT];
-} FourXContext;
-
-
-#define FIX_1_082392200 70936
-#define FIX_1_414213562 92682
-#define FIX_1_847759065 121095
-#define FIX_2_613125930 171254
-
-#define MULTIPLY(var,const) (((var)*(const)) >> 16)
-
-static void idct(DCTELEM block[64]){
- int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
- int tmp10, tmp11, tmp12, tmp13;
- int z5, z10, z11, z12, z13;
- int i;
- int temp[64];
-
- for(i=0; i<8; i++){
- tmp10 = block[8*0 + i] + block[8*4 + i];
- tmp11 = block[8*0 + i] - block[8*4 + i];
-
- tmp13 = block[8*2 + i] + block[8*6 + i];
- tmp12 = MULTIPLY(block[8*2 + i] - block[8*6 + i], FIX_1_414213562) - tmp13;
-
- tmp0 = tmp10 + tmp13;
- tmp3 = tmp10 - tmp13;
- tmp1 = tmp11 + tmp12;
- tmp2 = tmp11 - tmp12;
-
- z13 = block[8*5 + i] + block[8*3 + i];
- z10 = block[8*5 + i] - block[8*3 + i];
- z11 = block[8*1 + i] + block[8*7 + i];
- z12 = block[8*1 + i] - block[8*7 + i];
-
- tmp7 = z11 + z13;
- tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562);
-
- z5 = MULTIPLY(z10 + z12, FIX_1_847759065);
- tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5;
- tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5;
-
- tmp6 = tmp12 - tmp7;
- tmp5 = tmp11 - tmp6;
- tmp4 = tmp10 + tmp5;
-
- temp[8*0 + i] = tmp0 + tmp7;
- temp[8*7 + i] = tmp0 - tmp7;
- temp[8*1 + i] = tmp1 + tmp6;
- temp[8*6 + i] = tmp1 - tmp6;
- temp[8*2 + i] = tmp2 + tmp5;
- temp[8*5 + i] = tmp2 - tmp5;
- temp[8*4 + i] = tmp3 + tmp4;
- temp[8*3 + i] = tmp3 - tmp4;
- }
-
- for(i=0; i<8*8; i+=8){
- tmp10 = temp[0 + i] + temp[4 + i];
- tmp11 = temp[0 + i] - temp[4 + i];
-
- tmp13 = temp[2 + i] + temp[6 + i];
- tmp12 = MULTIPLY(temp[2 + i] - temp[6 + i], FIX_1_414213562) - tmp13;
-
- tmp0 = tmp10 + tmp13;
- tmp3 = tmp10 - tmp13;
- tmp1 = tmp11 + tmp12;
- tmp2 = tmp11 - tmp12;
-
- z13 = temp[5 + i] + temp[3 + i];
- z10 = temp[5 + i] - temp[3 + i];
- z11 = temp[1 + i] + temp[7 + i];
- z12 = temp[1 + i] - temp[7 + i];
-
- tmp7 = z11 + z13;
- tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562);
-
- z5 = MULTIPLY(z10 + z12, FIX_1_847759065);
- tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5;
- tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5;
-
- tmp6 = tmp12 - tmp7;
- tmp5 = tmp11 - tmp6;
- tmp4 = tmp10 + tmp5;
-
- block[0 + i] = (tmp0 + tmp7)>>6;
- block[7 + i] = (tmp0 - tmp7)>>6;
- block[1 + i] = (tmp1 + tmp6)>>6;
- block[6 + i] = (tmp1 - tmp6)>>6;
- block[2 + i] = (tmp2 + tmp5)>>6;
- block[5 + i] = (tmp2 - tmp5)>>6;
- block[4 + i] = (tmp3 + tmp4)>>6;
- block[3 + i] = (tmp3 - tmp4)>>6;
- }
-}
-
-static void init_vlcs(FourXContext *f){
- int i;
-
- for(i=0; i<4; i++){
- init_vlc(&block_type_vlc[i], BLOCK_TYPE_VLC_BITS, 7,
- &block_type_tab[i][0][1], 2, 1,
- &block_type_tab[i][0][0], 2, 1, 1);
- }
-}
-
-static void init_mv(FourXContext *f){
- int i;
-
- for(i=0; i<256; i++){
- f->mv[i] = mv[i][0] + mv[i][1]*f->current_picture.linesize[0]/2;
- }
-}
-
-static inline void mcdc(uint16_t *dst, uint16_t *src, int log2w, int h, int stride, int scale, int dc){
- int i;
- dc*= 0x10001;
-
- switch(log2w){
- case 0:
- for(i=0; i<h; i++){
- dst[0] = scale*src[0] + dc;
- if(scale) src += stride;
- dst += stride;
- }
- break;
- case 1:
- for(i=0; i<h; i++){
- ((uint32_t*)dst)[0] = scale*((uint32_t*)src)[0] + dc;
- if(scale) src += stride;
- dst += stride;
- }
- break;
- case 2:
- for(i=0; i<h; i++){
- ((uint32_t*)dst)[0] = scale*((uint32_t*)src)[0] + dc;
- ((uint32_t*)dst)[1] = scale*((uint32_t*)src)[1] + dc;
- if(scale) src += stride;
- dst += stride;
- }
- break;
- case 3:
- for(i=0; i<h; i++){
- ((uint32_t*)dst)[0] = scale*((uint32_t*)src)[0] + dc;
- ((uint32_t*)dst)[1] = scale*((uint32_t*)src)[1] + dc;
- ((uint32_t*)dst)[2] = scale*((uint32_t*)src)[2] + dc;
- ((uint32_t*)dst)[3] = scale*((uint32_t*)src)[3] + dc;
- if(scale) src += stride;
- dst += stride;
- }
- break;
- default: assert(0);
- }
-}
-
-static void decode_p_block(FourXContext *f, uint16_t *dst, uint16_t *src, int log2w, int log2h, int stride){
- const int index= size2index[log2h][log2w];
- const int h= 1<<log2h;
- int code= get_vlc2(&f->gb, block_type_vlc[index].table, BLOCK_TYPE_VLC_BITS, 1);
-
- assert(code>=0 && code<=6);
-
- if(code == 0){
- src += f->mv[ *f->bytestream++ ];
- mcdc(dst, src, log2w, h, stride, 1, 0);
- }else if(code == 1){
- log2h--;
- decode_p_block(f, dst , src , log2w, log2h, stride);
- decode_p_block(f, dst + (stride<<log2h), src + (stride<<log2h), log2w, log2h, stride);
- }else if(code == 2){
- log2w--;
- decode_p_block(f, dst , src , log2w, log2h, stride);
- decode_p_block(f, dst + (1<<log2w), src + (1<<log2w), log2w, log2h, stride);
- }else if(code == 4){
- src += f->mv[ *f->bytestream++ ];
- mcdc(dst, src, log2w, h, stride, 1, le2me_16(*f->wordstream++));
- }else if(code == 5){
- mcdc(dst, src, log2w, h, stride, 0, le2me_16(*f->wordstream++));
- }else if(code == 6){
- if(log2w){
- dst[0] = le2me_16(*f->wordstream++);
- dst[1] = le2me_16(*f->wordstream++);
- }else{
- dst[0 ] = le2me_16(*f->wordstream++);
- dst[stride] = le2me_16(*f->wordstream++);
- }
- }
-}
-
-static int get32(void *p){
- return le2me_32(*(uint32_t*)p);
-}
-
-static int decode_p_frame(FourXContext *f, uint8_t *buf, int length){
- int x, y;
- const int width= f->avctx->width;
- const int height= f->avctx->height;
- uint16_t *src= (uint16_t*)f->last_picture.data[0];
- uint16_t *dst= (uint16_t*)f->current_picture.data[0];
- const int stride= f->current_picture.linesize[0]>>1;
- const unsigned int bitstream_size= get32(buf+8);
- const unsigned int bytestream_size= get32(buf+16);
- const unsigned int wordstream_size= get32(buf+12);
-
- if(bitstream_size+ bytestream_size+ wordstream_size + 20 != length
- || bitstream_size > (1<<26)
- || bytestream_size > (1<<26)
- || wordstream_size > (1<<26)
- ){
- av_log(f->avctx, AV_LOG_ERROR, "lengths %d %d %d %d\n", bitstream_size, bytestream_size, wordstream_size,
- bitstream_size+ bytestream_size+ wordstream_size - length);
- return -1;
- }
-
- f->bitstream_buffer= av_fast_realloc(f->bitstream_buffer, &f->bitstream_buffer_size, bitstream_size + FF_INPUT_BUFFER_PADDING_SIZE);
- f->dsp.bswap_buf((uint32_t*)f->bitstream_buffer, (uint32_t*)(buf + 20), bitstream_size/4);
- init_get_bits(&f->gb, f->bitstream_buffer, 8*bitstream_size);
-
- f->wordstream= (uint16_t*)(buf + 20 + bitstream_size);
- f->bytestream= buf + 20 + bitstream_size + wordstream_size;
-
- init_mv(f);
-
- for(y=0; y<height; y+=8){
- for(x=0; x<width; x+=8){
- decode_p_block(f, dst + x, src + x, 3, 3, stride);
- }
- src += 8*stride;
- dst += 8*stride;
- }
-
- if(bitstream_size != (get_bits_count(&f->gb)+31)/32*4)
- av_log(f->avctx, AV_LOG_ERROR, " %d %td %td bytes left\n",
- bitstream_size - (get_bits_count(&f->gb)+31)/32*4,
- bytestream_size - (f->bytestream - (buf + 20 + bitstream_size + wordstream_size)),
- wordstream_size - (((uint8_t*)f->wordstream) - (buf + 20 + bitstream_size))
- );
-
- return 0;
-}
-
-/**
- * decode block and dequantize.
- * Note this is allmost identical to mjpeg
- */
-static int decode_i_block(FourXContext *f, DCTELEM *block){
- int code, i, j, level, val;
-
- /* DC coef */
- val = get_vlc2(&f->pre_gb, f->pre_vlc.table, ACDC_VLC_BITS, 3);
- if (val>>4){
- av_log(f->avctx, AV_LOG_ERROR, "error dc run != 0\n");
- }
-
- if(val)
- val = get_xbits(&f->gb, val);
-
- val = val * dequant_table[0] + f->last_dc;
- f->last_dc =
- block[0] = val;
- /* AC coefs */
- i = 1;
- for(;;) {
- code = get_vlc2(&f->pre_gb, f->pre_vlc.table, ACDC_VLC_BITS, 3);
-
- /* EOB */
- if (code == 0)
- break;
- if (code == 0xf0) {
- i += 16;
- } else {
- level = get_xbits(&f->gb, code & 0xf);
- i += code >> 4;
- if (i >= 64) {
- av_log(f->avctx, AV_LOG_ERROR, "run %d oveflow\n", i);
- return 0;
- }
-
- j= ff_zigzag_direct[i];
- block[j] = level * dequant_table[j];
- i++;
- if (i >= 64)
- break;
- }
- }
-
- return 0;
-}
-
-static inline void idct_put(FourXContext *f, int x, int y){
- DCTELEM (*block)[64]= f->block;
- int stride= f->current_picture.linesize[0]>>1;
- int i;
- uint16_t *dst = ((uint16_t*)f->current_picture.data[0]) + y * stride + x;
-
- for(i=0; i<4; i++){
- block[i][0] += 0x80*8*8;
- idct(block[i]);
- }
-
- if(!(f->avctx->flags&CODEC_FLAG_GRAY)){
- for(i=4; i<6; i++) idct(block[i]);
- }
-
-/* Note transform is:
-y= ( 1b + 4g + 2r)/14
-cb=( 3b - 2g - 1r)/14
-cr=(-1b - 4g + 5r)/14
-*/
- for(y=0; y<8; y++){
- for(x=0; x<8; x++){
- DCTELEM *temp= block[(x>>2) + 2*(y>>2)] + 2*(x&3) + 2*8*(y&3); //FIXME optimize
- int cb= block[4][x + 8*y];
- int cr= block[5][x + 8*y];
- int cg= (cb + cr)>>1;
- int y;
-
- cb+=cb;
-
- y = temp[0];
- dst[0 ]= ((y+cb)>>3) + (((y-cg)&0xFC)<<3) + (((y+cr)&0xF8)<<8);
- y = temp[1];
- dst[1 ]= ((y+cb)>>3) + (((y-cg)&0xFC)<<3) + (((y+cr)&0xF8)<<8);
- y = temp[8];
- dst[ stride]= ((y+cb)>>3) + (((y-cg)&0xFC)<<3) + (((y+cr)&0xF8)<<8);
- y = temp[9];
- dst[1+stride]= ((y+cb)>>3) + (((y-cg)&0xFC)<<3) + (((y+cr)&0xF8)<<8);
- dst += 2;
- }
- dst += 2*stride - 2*8;
- }
-}
-
-static int decode_i_mb(FourXContext *f){
- int i;
-
- f->dsp.clear_blocks(f->block[0]);
-
- for(i=0; i<6; i++){
- if(decode_i_block(f, f->block[i]) < 0)
- return -1;
- }
-
- return 0;
-}
-
-static uint8_t *read_huffman_tables(FourXContext *f, uint8_t * const buf){
- int frequency[512];
- uint8_t flag[512];
- int up[512];
- uint8_t len_tab[257];
- int bits_tab[257];
- int start, end;
- uint8_t *ptr= buf;
- int j;
-
- memset(frequency, 0, sizeof(frequency));
- memset(up, -1, sizeof(up));
-
- start= *ptr++;
- end= *ptr++;
- for(;;){
- int i;
-
- for(i=start; i<=end; i++){
- frequency[i]= *ptr++;
-// printf("%d %d %d\n", start, end, frequency[i]);
- }
- start= *ptr++;
- if(start==0) break;
-
- end= *ptr++;
- }
- frequency[256]=1;
-
- while((ptr - buf)&3) ptr++; // 4byte align
-
-// for(j=0; j<16; j++)
-// printf("%2X", ptr[j]);
-
- for(j=257; j<512; j++){
- int min_freq[2]= {256*256, 256*256};
- int smallest[2]= {0, 0};
- int i;
- for(i=0; i<j; i++){
- if(frequency[i] == 0) continue;
- if(frequency[i] < min_freq[1]){
- if(frequency[i] < min_freq[0]){
- min_freq[1]= min_freq[0]; smallest[1]= smallest[0];
- min_freq[0]= frequency[i];smallest[0]= i;
- }else{
- min_freq[1]= frequency[i];smallest[1]= i;
- }
- }
- }
- if(min_freq[1] == 256*256) break;
-
- frequency[j]= min_freq[0] + min_freq[1];
- flag[ smallest[0] ]= 0;
- flag[ smallest[1] ]= 1;
- up[ smallest[0] ]=
- up[ smallest[1] ]= j;
- frequency[ smallest[0] ]= frequency[ smallest[1] ]= 0;
- }
-
- for(j=0; j<257; j++){
- int node;
- int len=0;
- int bits=0;
-
- for(node= j; up[node] != -1; node= up[node]){
- bits += flag[node]<<len;
- len++;
- if(len > 31) av_log(f->avctx, AV_LOG_ERROR, "vlc length overflow\n"); //can this happen at all ?
- }
-
- bits_tab[j]= bits;
- len_tab[j]= len;
- }
-
- init_vlc(&f->pre_vlc, ACDC_VLC_BITS, 257,
- len_tab , 1, 1,
- bits_tab, 4, 4, 0);
-
- return ptr;
-}
-
-static int decode_i_frame(FourXContext *f, uint8_t *buf, int length){
- int x, y;
- const int width= f->avctx->width;
- const int height= f->avctx->height;
- uint16_t *dst= (uint16_t*)f->current_picture.data[0];
- const int stride= f->current_picture.linesize[0]>>1;
- const unsigned int bitstream_size= get32(buf);
- const int token_count __attribute__((unused)) = get32(buf + bitstream_size + 8);
- unsigned int prestream_size= 4*get32(buf + bitstream_size + 4);
- uint8_t *prestream= buf + bitstream_size + 12;
-
- if(prestream_size + bitstream_size + 12 != length
- || bitstream_size > (1<<26)
- || prestream_size > (1<<26)){
- av_log(f->avctx, AV_LOG_ERROR, "size mismatch %d %d %d\n", prestream_size, bitstream_size, length);
- return -1;
- }
-
- prestream= read_huffman_tables(f, prestream);
-
- init_get_bits(&f->gb, buf + 4, 8*bitstream_size);
-
- prestream_size= length + buf - prestream;
-
- f->bitstream_buffer= av_fast_realloc(f->bitstream_buffer, &f->bitstream_buffer_size, prestream_size + FF_INPUT_BUFFER_PADDING_SIZE);
- f->dsp.bswap_buf((uint32_t*)f->bitstream_buffer, (uint32_t*)prestream, prestream_size/4);
- init_get_bits(&f->pre_gb, f->bitstream_buffer, 8*prestream_size);
-
- f->last_dc= 0*128*8*8;
-
- for(y=0; y<height; y+=16){
- for(x=0; x<width; x+=16){
- if(decode_i_mb(f) < 0)
- return -1;
-
- idct_put(f, x, y);
- }
- dst += 16*stride;
- }
-
- if(get_vlc2(&f->pre_gb, f->pre_vlc.table, ACDC_VLC_BITS, 3) != 256)
- av_log(f->avctx, AV_LOG_ERROR, "end mismatch\n");
-
- return 0;
-}
-
-static int decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- FourXContext * const f = avctx->priv_data;
- AVFrame *picture = data;
- AVFrame *p, temp;
- int i, frame_4cc, frame_size;
-
- frame_4cc= get32(buf);
- if(buf_size != get32(buf+4)+8 || buf_size < 20){
- av_log(f->avctx, AV_LOG_ERROR, "size mismatch %d %d\n", buf_size, get32(buf+4));
- }
-
- if(frame_4cc == ff_get_fourcc("cfrm")){
- int free_index=-1;
- const int data_size= buf_size - 20;
- const int id= get32(buf+12);
- const int whole_size= get32(buf+16);
- CFrameBuffer *cfrm;
-
- for(i=0; i<CFRAME_BUFFER_COUNT; i++){
- if(f->cfrm[i].id && f->cfrm[i].id < avctx->frame_number)
- av_log(f->avctx, AV_LOG_ERROR, "lost c frame %d\n", f->cfrm[i].id);
- }
-
- for(i=0; i<CFRAME_BUFFER_COUNT; i++){
- if(f->cfrm[i].id == id) break;
- if(f->cfrm[i].size == 0 ) free_index= i;
- }
-
- if(i>=CFRAME_BUFFER_COUNT){
- i= free_index;
- f->cfrm[i].id= id;
- }
- cfrm= &f->cfrm[i];
-
- cfrm->data= av_fast_realloc(cfrm->data, &cfrm->allocated_size, cfrm->size + data_size + FF_INPUT_BUFFER_PADDING_SIZE);
- if(!cfrm->data){ //explicit check needed as memcpy below might not catch a NULL
- av_log(f->avctx, AV_LOG_ERROR, "realloc falure");
- return -1;
- }
-
- memcpy(cfrm->data + cfrm->size, buf+20, data_size);
- cfrm->size += data_size;
-
- if(cfrm->size >= whole_size){
- buf= cfrm->data;
- frame_size= cfrm->size;
-
- if(id != avctx->frame_number){
- av_log(f->avctx, AV_LOG_ERROR, "cframe id mismatch %d %d\n", id, avctx->frame_number);
- }
-
- cfrm->size= cfrm->id= 0;
- frame_4cc= ff_get_fourcc("pfrm");
- }else
- return buf_size;
- }else{
- buf= buf + 12;
- frame_size= buf_size - 12;
- }
-
- temp= f->current_picture;
- f->current_picture= f->last_picture;
- f->last_picture= temp;
-
- p= &f->current_picture;
- avctx->coded_frame= p;
-
- avctx->flags |= CODEC_FLAG_EMU_EDGE; // alternatively we would have to use our own buffer management
-
- if(p->data[0])
- avctx->release_buffer(avctx, p);
-
- p->reference= 1;
- if(avctx->get_buffer(avctx, p) < 0){
- av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
- return -1;
- }
-
- if(frame_4cc == ff_get_fourcc("ifrm")){
- p->pict_type= I_TYPE;
- if(decode_i_frame(f, buf, frame_size) < 0)
- return -1;
- }else if(frame_4cc == ff_get_fourcc("pfrm")){
- p->pict_type= P_TYPE;
- if(decode_p_frame(f, buf, frame_size) < 0)
- return -1;
- }else if(frame_4cc == ff_get_fourcc("snd_")){
- av_log(avctx, AV_LOG_ERROR, "ignoring snd_ chunk length:%d\n", buf_size);
- }else{
- av_log(avctx, AV_LOG_ERROR, "ignoring unknown chunk length:%d\n", buf_size);
- }
-
-#if 0
-for(i=0; i<20; i++){
- printf("%2X %c ", buf[i], clip(buf[i],16,126));
-}
-#endif
-
- p->key_frame= p->pict_type == I_TYPE;
-
- *picture= *p;
- *data_size = sizeof(AVPicture);
-
- emms_c();
-
- return buf_size;
-}
-
-
-static void common_init(AVCodecContext *avctx){
- FourXContext * const f = avctx->priv_data;
-
- dsputil_init(&f->dsp, avctx);
-
- f->avctx= avctx;
-}
-
-static int decode_init(AVCodecContext *avctx){
- FourXContext * const f = avctx->priv_data;
-
- common_init(avctx);
- init_vlcs(f);
-
- avctx->pix_fmt= PIX_FMT_RGB565;
-
- return 0;
-}
-
-
-static int decode_end(AVCodecContext *avctx){
- FourXContext * const f = avctx->priv_data;
- int i;
-
- av_freep(&f->bitstream_buffer);
- f->bitstream_buffer_size=0;
- for(i=0; i<CFRAME_BUFFER_COUNT; i++){
- av_freep(&f->cfrm[i].data);
- f->cfrm[i].allocated_size= 0;
- }
- free_vlc(&f->pre_vlc);
-
- return 0;
-}
-
-AVCodec fourxm_decoder = {
- "4xm",
- CODEC_TYPE_VIDEO,
- CODEC_ID_4XM,
- sizeof(FourXContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- /*CODEC_CAP_DR1,*/
-};
-
diff --git a/src/libffmpeg/libavcodec/8bps.c b/src/libffmpeg/libavcodec/8bps.c
deleted file mode 100644
index 297465043..000000000
--- a/src/libffmpeg/libavcodec/8bps.c
+++ /dev/null
@@ -1,236 +0,0 @@
-/*
- * Quicktime Planar RGB (8BPS) Video Decoder
- * Copyright (C) 2003 Roberto Togni
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General 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 8bps.c
- * QT 8BPS Video Decoder by Roberto Togni <rtogni at bresciaonline dot it>
- * For more information about the 8BPS format, visit:
- * http://www.pcisys.net/~melanson/codecs/
- *
- * Supports: PAL8 (RGB 8bpp, paletted)
- * : BGR24 (RGB 24bpp) (can also output it as RGBA32)
- * : RGBA32 (RGB 32bpp, 4th plane is probably alpha and it's ignored)
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "common.h"
-#include "avcodec.h"
-
-
-static const enum PixelFormat pixfmt_rgb24[] = {PIX_FMT_BGR24, PIX_FMT_RGBA32, -1};
-
-/*
- * Decoder context
- */
-typedef struct EightBpsContext {
-
- AVCodecContext *avctx;
- AVFrame pic;
-
- unsigned char planes;
- unsigned char planemap[4];
-} EightBpsContext;
-
-
-/*
- *
- * Decode a frame
- *
- */
-static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size)
-{
- EightBpsContext * const c = (EightBpsContext *)avctx->priv_data;
- unsigned char *encoded = (unsigned char *)buf;
- unsigned char *pixptr, *pixptr_end;
- unsigned int height = avctx->height; // Real image height
- unsigned int dlen, p, row;
- unsigned char *lp, *dp;
- unsigned char count;
- unsigned int px_inc;
- unsigned int planes = c->planes;
- unsigned char *planemap = c->planemap;
-
- if(c->pic.data[0])
- avctx->release_buffer(avctx, &c->pic);
-
- c->pic.reference = 0;
- c->pic.buffer_hints = FF_BUFFER_HINTS_VALID;
- if(avctx->get_buffer(avctx, &c->pic) < 0){
- av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
- return -1;
- }
-
- /* Set data pointer after line lengths */
- dp = encoded + planes * (height << 1);
-
- /* Ignore alpha plane, don't know what to do with it */
- if (planes == 4)
- planes--;
-
- px_inc = planes + (avctx->pix_fmt == PIX_FMT_RGBA32);
-
- for (p = 0; p < planes; p++) {
- /* Lines length pointer for this plane */
- lp = encoded + p * (height << 1);
-
- /* Decode a plane */
- for(row = 0; row < height; row++) {
- pixptr = c->pic.data[0] + row * c->pic.linesize[0] + planemap[p];
- pixptr_end = pixptr + c->pic.linesize[0];
- dlen = be2me_16(*(unsigned short *)(lp+row*2));
- /* Decode a row of this plane */
- while(dlen > 0) {
- if(dp + 1 >= buf+buf_size) return -1;
- if ((count = *dp++) <= 127) {
- count++;
- dlen -= count + 1;
- if (pixptr + count * px_inc > pixptr_end)
- break;
- if(dp + count > buf+buf_size) return -1;
- while(count--) {
- *pixptr = *dp++;
- pixptr += px_inc;
- }
- } else {
- count = 257 - count;
- if (pixptr + count * px_inc > pixptr_end)
- break;
- while(count--) {
- *pixptr = *dp;
- pixptr += px_inc;
- }
- dp++;
- dlen -= 2;
- }
- }
- }
- }
-
- if (avctx->palctrl) {
- memcpy (c->pic.data[1], avctx->palctrl->palette, AVPALETTE_SIZE);
- if (avctx->palctrl->palette_changed) {
- c->pic.palette_has_changed = 1;
- avctx->palctrl->palette_changed = 0;
- } else
- c->pic.palette_has_changed = 0;
- }
-
- *data_size = sizeof(AVFrame);
- *(AVFrame*)data = c->pic;
-
- /* always report that the buffer was completely consumed */
- return buf_size;
-}
-
-
-/*
- *
- * Init 8BPS decoder
- *
- */
-static int decode_init(AVCodecContext *avctx)
-{
- EightBpsContext * const c = (EightBpsContext *)avctx->priv_data;
-
- c->avctx = avctx;
- avctx->has_b_frames = 0;
-
- c->pic.data[0] = NULL;
-
- if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) {
- return 1;
- }
-
- switch (avctx->bits_per_sample) {
- case 8:
- avctx->pix_fmt = PIX_FMT_PAL8;
- c->planes = 1;
- c->planemap[0] = 0; // 1st plane is palette indexes
- if (avctx->palctrl == NULL) {
- av_log(avctx, AV_LOG_ERROR, "Error: PAL8 format but no palette from demuxer.\n");
- return -1;
- }
- break;
- case 24:
- avctx->pix_fmt = avctx->get_format(avctx, pixfmt_rgb24);
- c->planes = 3;
- c->planemap[0] = 2; // 1st plane is red
- c->planemap[1] = 1; // 2nd plane is green
- c->planemap[2] = 0; // 3rd plane is blue
- break;
- case 32:
- avctx->pix_fmt = PIX_FMT_RGBA32;
- c->planes = 4;
-#ifdef WORDS_BIGENDIAN
- c->planemap[0] = 1; // 1st plane is red
- c->planemap[1] = 2; // 2nd plane is green
- c->planemap[2] = 3; // 3rd plane is blue
- c->planemap[3] = 0; // 4th plane is alpha???
-#else
- c->planemap[0] = 2; // 1st plane is red
- c->planemap[1] = 1; // 2nd plane is green
- c->planemap[2] = 0; // 3rd plane is blue
- c->planemap[3] = 3; // 4th plane is alpha???
-#endif
- break;
- default:
- av_log(avctx, AV_LOG_ERROR, "Error: Unsupported color depth: %u.\n", avctx->bits_per_sample);
- return -1;
- }
-
- return 0;
-}
-
-
-
-
-/*
- *
- * Uninit 8BPS decoder
- *
- */
-static int decode_end(AVCodecContext *avctx)
-{
- EightBpsContext * const c = (EightBpsContext *)avctx->priv_data;
-
- if (c->pic.data[0])
- avctx->release_buffer(avctx, &c->pic);
-
- return 0;
-}
-
-
-
-AVCodec eightbps_decoder = {
- "8bps",
- CODEC_TYPE_VIDEO,
- CODEC_ID_8BPS,
- sizeof(EightBpsContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
-};
diff --git a/src/libffmpeg/libavcodec/Makefile.am b/src/libffmpeg/libavcodec/Makefile.am
deleted file mode 100644
index a5e6cd650..000000000
--- a/src/libffmpeg/libavcodec/Makefile.am
+++ /dev/null
@@ -1,190 +0,0 @@
-include $(top_srcdir)/misc/Makefile.common
-
-SUBDIRS = armv4l i386 mlib alpha ppc sparc libpostproc
-
-# some of ffmpeg's decoders are not used by xine yet
-EXTRA_DIST = motion_est_template.c \
- adx.c cljr.c fdctref.c ffv1.c g726.c jpeg_ls.c mdec.c raw.c svq3.c wmv2.c
-
-# we need to compile everything in debug mode, including the encoders,
-# otherwise we get unresolved symbols, because some unsatisfied function calls
-# are not optimized away with debug optimization
-#AM_CFLAGS = `test "$(CFLAGS)" = "$(DEBUG_CFLAGS)" && echo -DCONFIG_ENCODERS` -fno-strict-aliasing
-AM_CFLAGS = `test "$(CFLAGS)" = "$(DEBUG_CFLAGS)"` -fno-strict-aliasing
-AM_CPPFLAGS = $(ZLIB_CPPFLAGS) $(LIBFFMPEG_CPPFLAGS) \
- -I$(top_srcdir)/src/libffmpeg/libavutil -I$(top_srcdir)/src/libffmpeg \
- -I$(top_builddir)/src/libffmpeg
-ASFLAGS =
-
-noinst_LTLIBRARIES = libavcodec.la
-
-libavcodec_la_SOURCES = \
- 4xm.c \
- 8bps.c \
- aasc.c \
- adpcm.c \
- alac.c \
- asv1.c \
- avs.c \
- bitstream.c \
- cabac.c \
- cavs.c \
- cinepak.c \
- cook.c \
- cscd.c \
- cyuv.c \
- dpcm.c \
- dsputil.c \
- dv.c \
- error_resilience.c \
- eval.c \
- faandct.c \
- flac.c \
- flashsv.c \
- flicvideo.c \
- fraps.c \
- fft.c \
- golomb.c \
- h261.c \
- h263.c \
- h263dec.c \
- h264.c \
- h264idct.c \
- huffyuv.c \
- idcinvideo.c \
- imgconvert.c \
- imgresample.c \
- indeo2.c \
- indeo3.c \
- interplayvideo.c \
- jfdctfst.c \
- jfdctint.c \
- jrevdct.c \
- kmvc.c \
- lcl.c \
- loco.c \
- lzo.c \
- mdct.c \
- mace.c \
- mjpeg.c \
- mmvideo.c \
- motion_est.c \
- mpeg12.c \
- mpegaudiodec.c \
- mpegvideo.c \
- msmpeg4.c \
- msrle.c \
- msvideo1.c \
- nuv.c \
- opt.c \
- parser.c \
- pcm.c \
- qdm2.c \
- qdrw.c \
- qpeg.c \
- qtrle.c \
- ra144.c \
- ra288.c \
- rangecoder.c \
- ratecontrol.c \
- resample2.c \
- roqvideo.c \
- rpza.c \
- rtjpeg.c \
- rv10.c \
- shorten.c \
- simple_idct.c \
- smacker.c \
- smc.c \
- snow.c \
- svq1.c \
- tscc.c \
- truemotion1.c \
- truemotion2.c \
- truespeech.c \
- tta.c \
- ulti.c \
- utils.c \
- vc1.c \
- vc1dsp.c \
- vcr1.c \
- vmdav.c \
- vorbis.c \
- vorbis_data.c \
- vp3.c \
- vp3dsp.c \
- vp5.c \
- vp56.c \
- vp56data.c \
- vp6.c \
- vqavideo.c \
- wavpack.c \
- wmadec.c \
- wnv1.c \
- xan.c \
- xl.c \
- zmbv.c
-
-libavcodec_la_LDFLAGS = \
- $(top_builddir)/src/libffmpeg/libavcodec/armv4l/libavcodec_armv4l.la \
- $(top_builddir)/src/libffmpeg/libavcodec/i386/libavcodec_mmx.la \
- $(top_builddir)/src/libffmpeg/libavcodec/mlib/libavcodec_mlib.la \
- $(top_builddir)/src/libffmpeg/libavcodec/ppc/libavcodec_ppc.la \
- $(top_builddir)/src/libffmpeg/libavcodec/sparc/libavcodec_sparc.la \
- -avoid-version -module
-
-
-noinst_HEADERS = \
- avcodec.h \
- bitstream.h \
- bytestream.h \
- cabac.h \
- cavsdata.h \
- cookdata.h \
- dsputil.h \
- dvdata.h \
- eval.h \
- faandct.h \
- fastmemcpy.h \
- golomb.h \
- imgconvert_template.h \
- indeo2data.h \
- indeo3data.h \
- h261data.h \
- h263data.h \
- h264data.h \
- lzo.h \
- mathops.h \
- mpeg4data.h \
- mpeg12data.h \
- mpegaudio.h \
- mpegaudiodectab.h \
- mpegaudiotab.h \
- mpegvideo.h \
- msmpeg4data.h \
- opt.h \
- parser.h \
- qdm2data.h \
- ra144.h \
- ra288.h \
- rangecoder.h \
- ratecontrol.h \
- rtjpeg.h \
- simple_idct.h \
- snow.h \
- sp5x.h \
- svq1_cb.h \
- svq1_vlc.h \
- swscale.h \
- truemotion1data.h \
- truespeech_data.h \
- ulti_cb.h \
- vorbis.h \
- vc1acdata.h \
- vc1data.h \
- vp3data.h \
- vp56.h \
- vp56data.h \
- vp5data.h \
- vp6data.h \
- wmadata.h
diff --git a/src/libffmpeg/libavcodec/aasc.c b/src/libffmpeg/libavcodec/aasc.c
deleted file mode 100644
index 6c8e3166e..000000000
--- a/src/libffmpeg/libavcodec/aasc.c
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * Autodesc RLE Decoder
- * Copyright (C) 2005 the ffmpeg project
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/**
- * @file aasc.c
- * Autodesc RLE Video Decoder by Konstantin Shishkov
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "common.h"
-#include "avcodec.h"
-#include "dsputil.h"
-
-typedef struct AascContext {
- AVCodecContext *avctx;
- AVFrame frame;
-} AascContext;
-
-#define FETCH_NEXT_STREAM_BYTE() \
- if (stream_ptr >= buf_size) \
- { \
- av_log(s->avctx, AV_LOG_ERROR, " AASC: stream ptr just went out of bounds (fetch)\n"); \
- break; \
- } \
- stream_byte = buf[stream_ptr++];
-
-static int aasc_decode_init(AVCodecContext *avctx)
-{
- AascContext *s = (AascContext *)avctx->priv_data;
-
- s->avctx = avctx;
-
- avctx->pix_fmt = PIX_FMT_BGR24;
- avctx->has_b_frames = 0;
- s->frame.data[0] = NULL;
-
- return 0;
-}
-
-static int aasc_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- AascContext *s = (AascContext *)avctx->priv_data;
- int stream_ptr = 4;
- unsigned char rle_code;
- unsigned char stream_byte;
- int pixel_ptr = 0;
- int row_dec, row_ptr;
- int frame_size;
- int i;
-
- s->frame.reference = 1;
- s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
- if (avctx->reget_buffer(avctx, &s->frame)) {
- av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
- return -1;
- }
-
- row_dec = s->frame.linesize[0];
- row_ptr = (s->avctx->height - 1) * row_dec;
- frame_size = row_dec * s->avctx->height;
-
- while (row_ptr >= 0) {
- FETCH_NEXT_STREAM_BYTE();
- rle_code = stream_byte;
- if (rle_code == 0) {
- /* fetch the next byte to see how to handle escape code */
- FETCH_NEXT_STREAM_BYTE();
- if (stream_byte == 0) {
- /* line is done, goto the next one */
- row_ptr -= row_dec;
- pixel_ptr = 0;
- } else if (stream_byte == 1) {
- /* decode is done */
- break;
- } else if (stream_byte == 2) {
- /* reposition frame decode coordinates */
- FETCH_NEXT_STREAM_BYTE();
- pixel_ptr += stream_byte;
- FETCH_NEXT_STREAM_BYTE();
- row_ptr -= stream_byte * row_dec;
- } else {
- /* copy pixels from encoded stream */
- if ((pixel_ptr + stream_byte > avctx->width * 3) ||
- (row_ptr < 0)) {
- av_log(s->avctx, AV_LOG_ERROR, " AASC: frame ptr just went out of bounds (copy1)\n");
- break;
- }
-
- rle_code = stream_byte;
- if (stream_ptr + rle_code > buf_size) {
- av_log(s->avctx, AV_LOG_ERROR, " AASC: stream ptr just went out of bounds (copy2)\n");
- break;
- }
-
- for (i = 0; i < rle_code; i++) {
- FETCH_NEXT_STREAM_BYTE();
- s->frame.data[0][row_ptr + pixel_ptr] = stream_byte;
- pixel_ptr++;
- }
- if (rle_code & 1)
- stream_ptr++;
- }
- } else {
- /* decode a run of data */
- if ((pixel_ptr + rle_code > avctx->width * 3) ||
- (row_ptr < 0)) {
- av_log(s->avctx, AV_LOG_ERROR, " AASC: frame ptr just went out of bounds (run1)\n");
- break;
- }
-
- FETCH_NEXT_STREAM_BYTE();
-
- while(rle_code--) {
- s->frame.data[0][row_ptr + pixel_ptr] = stream_byte;
- pixel_ptr++;
- }
- }
- }
-
- /* one last sanity check on the way out */
- if (stream_ptr < buf_size)
- av_log(s->avctx, AV_LOG_ERROR, " AASC: ended frame decode with bytes left over (%d < %d)\n",
- stream_ptr, buf_size);
-
- *data_size = sizeof(AVFrame);
- *(AVFrame*)data = s->frame;
-
- /* report that the buffer was completely consumed */
- return buf_size;
-}
-
-static int aasc_decode_end(AVCodecContext *avctx)
-{
- AascContext *s = (AascContext *)avctx->priv_data;
-
- /* release the last frame */
- if (s->frame.data[0])
- avctx->release_buffer(avctx, &s->frame);
-
- return 0;
-}
-
-AVCodec aasc_decoder = {
- "aasc",
- CODEC_TYPE_VIDEO,
- CODEC_ID_AASC,
- sizeof(AascContext),
- aasc_decode_init,
- NULL,
- aasc_decode_end,
- aasc_decode_frame,
- CODEC_CAP_DR1,
-};
diff --git a/src/libffmpeg/libavcodec/adpcm.c b/src/libffmpeg/libavcodec/adpcm.c
deleted file mode 100644
index 9be4c2274..000000000
--- a/src/libffmpeg/libavcodec/adpcm.c
+++ /dev/null
@@ -1,1370 +0,0 @@
-/*
- * ADPCM codecs
- * Copyright (c) 2001-2003 The ffmpeg Project
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-#include "avcodec.h"
-#include "bitstream.h"
-
-/**
- * @file adpcm.c
- * ADPCM codecs.
- * First version by Francois Revol (revol@free.fr)
- * Fringe ADPCM codecs (e.g., DK3, DK4, Westwood)
- * by Mike Melanson (melanson@pcisys.net)
- * CD-ROM XA ADPCM codec by BERO
- * EA ADPCM decoder by Robin Kay (komadori@myrealbox.com)
- *
- * Features and limitations:
- *
- * Reference documents:
- * http://www.pcisys.net/~melanson/codecs/simpleaudio.html
- * http://www.geocities.com/SiliconValley/8682/aud3.txt
- * http://openquicktime.sourceforge.net/plugins.htm
- * XAnim sources (xa_codec.c) http://www.rasnaimaging.com/people/lapus/download.html
- * http://www.cs.ucla.edu/~leec/mediabench/applications.html
- * SoX source code http://home.sprynet.com/~cbagwell/sox.html
- *
- * CD-ROM XA:
- * http://ku-www.ss.titech.ac.jp/~yatsushi/xaadpcm.html
- * vagpack & depack http://homepages.compuserve.de/bITmASTER32/psx-index.html
- * readstr http://www.geocities.co.jp/Playtown/2004/
- */
-
-#define BLKSIZE 1024
-
-#define CLAMP_TO_SHORT(value) \
-if (value > 32767) \
- value = 32767; \
-else if (value < -32768) \
- value = -32768; \
-
-/* step_table[] and index_table[] are from the ADPCM reference source */
-/* This is the index table: */
-static const int index_table[16] = {
- -1, -1, -1, -1, 2, 4, 6, 8,
- -1, -1, -1, -1, 2, 4, 6, 8,
-};
-
-/**
- * This is the step table. Note that many programs use slight deviations from
- * this table, but such deviations are negligible:
- */
-static const int step_table[89] = {
- 7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
- 19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
- 50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
- 130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
- 337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
- 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
- 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
- 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
- 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
-};
-
-/* These are for MS-ADPCM */
-/* AdaptationTable[], AdaptCoeff1[], and AdaptCoeff2[] are from libsndfile */
-static const int AdaptationTable[] = {
- 230, 230, 230, 230, 307, 409, 512, 614,
- 768, 614, 512, 409, 307, 230, 230, 230
-};
-
-static const int AdaptCoeff1[] = {
- 256, 512, 0, 192, 240, 460, 392
-};
-
-static const int AdaptCoeff2[] = {
- 0, -256, 0, 64, 0, -208, -232
-};
-
-/* These are for CD-ROM XA ADPCM */
-static const int xa_adpcm_table[5][2] = {
- { 0, 0 },
- { 60, 0 },
- { 115, -52 },
- { 98, -55 },
- { 122, -60 }
-};
-
-static const int ea_adpcm_table[] = {
- 0, 240, 460, 392, 0, 0, -208, -220, 0, 1,
- 3, 4, 7, 8, 10, 11, 0, -1, -3, -4
-};
-
-static const int ct_adpcm_table[8] = {
- 0x00E6, 0x00E6, 0x00E6, 0x00E6,
- 0x0133, 0x0199, 0x0200, 0x0266
-};
-
-// padded to zero where table size is less then 16
-static const int swf_index_tables[4][16] = {
- /*2*/ { -1, 2 },
- /*3*/ { -1, -1, 2, 4 },
- /*4*/ { -1, -1, -1, -1, 2, 4, 6, 8 },
- /*5*/ { -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16 }
-};
-
-static const int yamaha_indexscale[] = {
- 230, 230, 230, 230, 307, 409, 512, 614,
- 230, 230, 230, 230, 307, 409, 512, 614
-};
-
-static const int yamaha_difflookup[] = {
- 1, 3, 5, 7, 9, 11, 13, 15,
- -1, -3, -5, -7, -9, -11, -13, -15
-};
-
-/* end of tables */
-
-typedef struct ADPCMChannelStatus {
- int predictor;
- short int step_index;
- int step;
- /* for encoding */
- int prev_sample;
-
- /* MS version */
- short sample1;
- short sample2;
- int coeff1;
- int coeff2;
- int idelta;
-} ADPCMChannelStatus;
-
-typedef struct ADPCMContext {
- int channel; /* for stereo MOVs, decode left, then decode right, then tell it's decoded */
- ADPCMChannelStatus status[2];
- short sample_buffer[32]; /* hold left samples while waiting for right samples */
-
- /* SWF only */
- int nb_bits;
- int nb_samples;
-} ADPCMContext;
-
-/* XXX: implement encoding */
-
-#ifdef CONFIG_ENCODERS
-static int adpcm_encode_init(AVCodecContext *avctx)
-{
- if (avctx->channels > 2)
- return -1; /* only stereo or mono =) */
- switch(avctx->codec->id) {
- case CODEC_ID_ADPCM_IMA_QT:
- av_log(avctx, AV_LOG_ERROR, "ADPCM: codec adpcm_ima_qt unsupported for encoding !\n");
- avctx->frame_size = 64; /* XXX: can multiple of avctx->channels * 64 (left and right blocks are interleaved) */
- return -1;
- break;
- case CODEC_ID_ADPCM_IMA_WAV:
- avctx->frame_size = (BLKSIZE - 4 * avctx->channels) * 8 / (4 * avctx->channels) + 1; /* each 16 bits sample gives one nibble */
- /* and we have 4 bytes per channel overhead */
- avctx->block_align = BLKSIZE;
- /* seems frame_size isn't taken into account... have to buffer the samples :-( */
- break;
- case CODEC_ID_ADPCM_MS:
- avctx->frame_size = (BLKSIZE - 7 * avctx->channels) * 2 / avctx->channels + 2; /* each 16 bits sample gives one nibble */
- /* and we have 7 bytes per channel overhead */
- avctx->block_align = BLKSIZE;
- break;
- case CODEC_ID_ADPCM_YAMAHA:
- avctx->frame_size = BLKSIZE * avctx->channels;
- avctx->block_align = BLKSIZE;
- break;
- default:
- return -1;
- break;
- }
-
- avctx->coded_frame= avcodec_alloc_frame();
- avctx->coded_frame->key_frame= 1;
-
- return 0;
-}
-
-static int adpcm_encode_close(AVCodecContext *avctx)
-{
- av_freep(&avctx->coded_frame);
-
- return 0;
-}
-
-
-static inline unsigned char adpcm_ima_compress_sample(ADPCMChannelStatus *c, short sample)
-{
- int delta = sample - c->prev_sample;
- int nibble = FFMIN(7, abs(delta)*4/step_table[c->step_index]) + (delta<0)*8;
- c->prev_sample = c->prev_sample + ((step_table[c->step_index] * yamaha_difflookup[nibble]) / 8);
- CLAMP_TO_SHORT(c->prev_sample);
- c->step_index = clip(c->step_index + index_table[nibble], 0, 88);
- return nibble;
-}
-
-static inline unsigned char adpcm_ms_compress_sample(ADPCMChannelStatus *c, short sample)
-{
- int predictor, nibble, bias;
-
- predictor = (((c->sample1) * (c->coeff1)) + ((c->sample2) * (c->coeff2))) / 256;
-
- nibble= sample - predictor;
- if(nibble>=0) bias= c->idelta/2;
- else bias=-c->idelta/2;
-
- nibble= (nibble + bias) / c->idelta;
- nibble= clip(nibble, -8, 7)&0x0F;
-
- predictor += (signed)((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->idelta;
- CLAMP_TO_SHORT(predictor);
-
- c->sample2 = c->sample1;
- c->sample1 = predictor;
-
- c->idelta = (AdaptationTable[(int)nibble] * c->idelta) >> 8;
- if (c->idelta < 16) c->idelta = 16;
-
- return nibble;
-}
-
-static inline unsigned char adpcm_yamaha_compress_sample(ADPCMChannelStatus *c, short sample)
-{
- int nibble, delta;
-
- if(!c->step) {
- c->predictor = 0;
- c->step = 127;
- }
-
- delta = sample - c->predictor;
-
- nibble = FFMIN(7, abs(delta)*4/c->step) + (delta<0)*8;
-
- c->predictor = c->predictor + ((c->step * yamaha_difflookup[nibble]) / 8);
- CLAMP_TO_SHORT(c->predictor);
- c->step = (c->step * yamaha_indexscale[nibble]) >> 8;
- c->step = clip(c->step, 127, 24567);
-
- return nibble;
-}
-
-typedef struct TrellisPath {
- int nibble;
- int prev;
-} TrellisPath;
-
-typedef struct TrellisNode {
- uint32_t ssd;
- int path;
- int sample1;
- int sample2;
- int step;
-} TrellisNode;
-
-static void adpcm_compress_trellis(AVCodecContext *avctx, const short *samples,
- uint8_t *dst, ADPCMChannelStatus *c, int n)
-{
-#define FREEZE_INTERVAL 128
- //FIXME 6% faster if frontier is a compile-time constant
- const int frontier = 1 << avctx->trellis;
- const int stride = avctx->channels;
- const int version = avctx->codec->id;
- const int max_paths = frontier*FREEZE_INTERVAL;
- TrellisPath paths[max_paths], *p;
- TrellisNode node_buf[2][frontier];
- TrellisNode *nodep_buf[2][frontier];
- TrellisNode **nodes = nodep_buf[0]; // nodes[] is always sorted by .ssd
- TrellisNode **nodes_next = nodep_buf[1];
- int pathn = 0, froze = -1, i, j, k;
-
- assert(!(max_paths&(max_paths-1)));
-
- memset(nodep_buf, 0, sizeof(nodep_buf));
- nodes[0] = &node_buf[1][0];
- nodes[0]->ssd = 0;
- nodes[0]->path = 0;
- nodes[0]->step = c->step_index;
- nodes[0]->sample1 = c->sample1;
- nodes[0]->sample2 = c->sample2;
- if(version == CODEC_ID_ADPCM_IMA_WAV)
- nodes[0]->sample1 = c->prev_sample;
- if(version == CODEC_ID_ADPCM_MS)
- nodes[0]->step = c->idelta;
- if(version == CODEC_ID_ADPCM_YAMAHA) {
- if(c->step == 0) {
- nodes[0]->step = 127;
- nodes[0]->sample1 = 0;
- } else {
- nodes[0]->step = c->step;
- nodes[0]->sample1 = c->predictor;
- }
- }
-
- for(i=0; i<n; i++) {
- TrellisNode *t = node_buf[i&1];
- TrellisNode **u;
- int sample = samples[i*stride];
- memset(nodes_next, 0, frontier*sizeof(TrellisNode*));
- for(j=0; j<frontier && nodes[j]; j++) {
- // higher j have higher ssd already, so they're unlikely to use a suboptimal next sample too
- const int range = (j < frontier/2) ? 1 : 0;
- const int step = nodes[j]->step;
- int nidx;
- if(version == CODEC_ID_ADPCM_MS) {
- const int predictor = ((nodes[j]->sample1 * c->coeff1) + (nodes[j]->sample2 * c->coeff2)) / 256;
- const int div = (sample - predictor) / step;
- const int nmin = clip(div-range, -8, 6);
- const int nmax = clip(div+range, -7, 7);
- for(nidx=nmin; nidx<=nmax; nidx++) {
- const int nibble = nidx & 0xf;
- int dec_sample = predictor + nidx * step;
-#define STORE_NODE(NAME, STEP_INDEX)\
- int d;\
- uint32_t ssd;\
- CLAMP_TO_SHORT(dec_sample);\
- d = sample - dec_sample;\
- ssd = nodes[j]->ssd + d*d;\
- if(nodes_next[frontier-1] && ssd >= nodes_next[frontier-1]->ssd)\
- continue;\
- /* Collapse any two states with the same previous sample value. \
- * One could also distinguish states by step and by 2nd to last
- * sample, but the effects of that are negligible. */\
- for(k=0; k<frontier && nodes_next[k]; k++) {\
- if(dec_sample == nodes_next[k]->sample1) {\
- assert(ssd >= nodes_next[k]->ssd);\
- goto next_##NAME;\
- }\
- }\
- for(k=0; k<frontier; k++) {\
- if(!nodes_next[k] || ssd < nodes_next[k]->ssd) {\
- TrellisNode *u = nodes_next[frontier-1];\
- if(!u) {\
- assert(pathn < max_paths);\
- u = t++;\
- u->path = pathn++;\
- }\
- u->ssd = ssd;\
- u->step = STEP_INDEX;\
- u->sample2 = nodes[j]->sample1;\
- u->sample1 = dec_sample;\
- paths[u->path].nibble = nibble;\
- paths[u->path].prev = nodes[j]->path;\
- memmove(&nodes_next[k+1], &nodes_next[k], (frontier-k-1)*sizeof(TrellisNode*));\
- nodes_next[k] = u;\
- break;\
- }\
- }\
- next_##NAME:;
- STORE_NODE(ms, FFMAX(16, (AdaptationTable[nibble] * step) >> 8));
- }
- } else if(version == CODEC_ID_ADPCM_IMA_WAV) {
-#define LOOP_NODES(NAME, STEP_TABLE, STEP_INDEX)\
- const int predictor = nodes[j]->sample1;\
- const int div = (sample - predictor) * 4 / STEP_TABLE;\
- int nmin = clip(div-range, -7, 6);\
- int nmax = clip(div+range, -6, 7);\
- if(nmin<=0) nmin--; /* distinguish -0 from +0 */\
- if(nmax<0) nmax--;\
- for(nidx=nmin; nidx<=nmax; nidx++) {\
- const int nibble = nidx<0 ? 7-nidx : nidx;\
- int dec_sample = predictor + (STEP_TABLE * yamaha_difflookup[nibble]) / 8;\
- STORE_NODE(NAME, STEP_INDEX);\
- }
- LOOP_NODES(ima, step_table[step], clip(step + index_table[nibble], 0, 88));
- } else { //CODEC_ID_ADPCM_YAMAHA
- LOOP_NODES(yamaha, step, clip((step * yamaha_indexscale[nibble]) >> 8, 127, 24567));
-#undef LOOP_NODES
-#undef STORE_NODE
- }
- }
-
- u = nodes;
- nodes = nodes_next;
- nodes_next = u;
-
- // prevent overflow
- if(nodes[0]->ssd > (1<<28)) {
- for(j=1; j<frontier && nodes[j]; j++)
- nodes[j]->ssd -= nodes[0]->ssd;
- nodes[0]->ssd = 0;
- }
-
- // merge old paths to save memory
- if(i == froze + FREEZE_INTERVAL) {
- p = &paths[nodes[0]->path];
- for(k=i; k>froze; k--) {
- dst[k] = p->nibble;
- p = &paths[p->prev];
- }
- froze = i;
- pathn = 0;
- // other nodes might use paths that don't coincide with the frozen one.
- // checking which nodes do so is too slow, so just kill them all.
- // this also slightly improves quality, but I don't know why.
- memset(nodes+1, 0, (frontier-1)*sizeof(TrellisNode*));
- }
- }
-
- p = &paths[nodes[0]->path];
- for(i=n-1; i>froze; i--) {
- dst[i] = p->nibble;
- p = &paths[p->prev];
- }
-
- c->predictor = nodes[0]->sample1;
- c->sample1 = nodes[0]->sample1;
- c->sample2 = nodes[0]->sample2;
- c->step_index = nodes[0]->step;
- c->step = nodes[0]->step;
- c->idelta = nodes[0]->step;
-}
-
-static int adpcm_encode_frame(AVCodecContext *avctx,
- unsigned char *frame, int buf_size, void *data)
-{
- int n, i, st;
- short *samples;
- unsigned char *dst;
- ADPCMContext *c = avctx->priv_data;
-
- dst = frame;
- samples = (short *)data;
- st= avctx->channels == 2;
-/* n = (BLKSIZE - 4 * avctx->channels) / (2 * 8 * avctx->channels); */
-
- switch(avctx->codec->id) {
- case CODEC_ID_ADPCM_IMA_QT: /* XXX: can't test until we get .mov writer */
- break;
- case CODEC_ID_ADPCM_IMA_WAV:
- n = avctx->frame_size / 8;
- c->status[0].prev_sample = (signed short)samples[0]; /* XXX */
-/* c->status[0].step_index = 0; *//* XXX: not sure how to init the state machine */
- *dst++ = (c->status[0].prev_sample) & 0xFF; /* little endian */
- *dst++ = (c->status[0].prev_sample >> 8) & 0xFF;
- *dst++ = (unsigned char)c->status[0].step_index;
- *dst++ = 0; /* unknown */
- samples++;
- if (avctx->channels == 2) {
- c->status[1].prev_sample = (signed short)samples[1];
-/* c->status[1].step_index = 0; */
- *dst++ = (c->status[1].prev_sample) & 0xFF;
- *dst++ = (c->status[1].prev_sample >> 8) & 0xFF;
- *dst++ = (unsigned char)c->status[1].step_index;
- *dst++ = 0;
- samples++;
- }
-
- /* stereo: 4 bytes (8 samples) for left, 4 bytes for right, 4 bytes left, ... */
- if(avctx->trellis > 0) {
- uint8_t buf[2][n*8];
- adpcm_compress_trellis(avctx, samples, buf[0], &c->status[0], n*8);
- if(avctx->channels == 2)
- adpcm_compress_trellis(avctx, samples+1, buf[1], &c->status[1], n*8);
- for(i=0; i<n; i++) {
- *dst++ = buf[0][8*i+0] | (buf[0][8*i+1] << 4);
- *dst++ = buf[0][8*i+2] | (buf[0][8*i+3] << 4);
- *dst++ = buf[0][8*i+4] | (buf[0][8*i+5] << 4);
- *dst++ = buf[0][8*i+6] | (buf[0][8*i+7] << 4);
- if (avctx->channels == 2) {
- *dst++ = buf[1][8*i+0] | (buf[1][8*i+1] << 4);
- *dst++ = buf[1][8*i+2] | (buf[1][8*i+3] << 4);
- *dst++ = buf[1][8*i+4] | (buf[1][8*i+5] << 4);
- *dst++ = buf[1][8*i+6] | (buf[1][8*i+7] << 4);
- }
- }
- } else
- for (; n>0; n--) {
- *dst = adpcm_ima_compress_sample(&c->status[0], samples[0]) & 0x0F;
- *dst |= (adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels]) << 4) & 0xF0;
- dst++;
- *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 2]) & 0x0F;
- *dst |= (adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 3]) << 4) & 0xF0;
- dst++;
- *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 4]) & 0x0F;
- *dst |= (adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 5]) << 4) & 0xF0;
- dst++;
- *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 6]) & 0x0F;
- *dst |= (adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 7]) << 4) & 0xF0;
- dst++;
- /* right channel */
- if (avctx->channels == 2) {
- *dst = adpcm_ima_compress_sample(&c->status[1], samples[1]);
- *dst |= adpcm_ima_compress_sample(&c->status[1], samples[3]) << 4;
- dst++;
- *dst = adpcm_ima_compress_sample(&c->status[1], samples[5]);
- *dst |= adpcm_ima_compress_sample(&c->status[1], samples[7]) << 4;
- dst++;
- *dst = adpcm_ima_compress_sample(&c->status[1], samples[9]);
- *dst |= adpcm_ima_compress_sample(&c->status[1], samples[11]) << 4;
- dst++;
- *dst = adpcm_ima_compress_sample(&c->status[1], samples[13]);
- *dst |= adpcm_ima_compress_sample(&c->status[1], samples[15]) << 4;
- dst++;
- }
- samples += 8 * avctx->channels;
- }
- break;
- case CODEC_ID_ADPCM_MS:
- for(i=0; i<avctx->channels; i++){
- int predictor=0;
-
- *dst++ = predictor;
- c->status[i].coeff1 = AdaptCoeff1[predictor];
- c->status[i].coeff2 = AdaptCoeff2[predictor];
- }
- for(i=0; i<avctx->channels; i++){
- if (c->status[i].idelta < 16)
- c->status[i].idelta = 16;
-
- *dst++ = c->status[i].idelta & 0xFF;
- *dst++ = c->status[i].idelta >> 8;
- }
- for(i=0; i<avctx->channels; i++){
- c->status[i].sample1= *samples++;
-
- *dst++ = c->status[i].sample1 & 0xFF;
- *dst++ = c->status[i].sample1 >> 8;
- }
- for(i=0; i<avctx->channels; i++){
- c->status[i].sample2= *samples++;
-
- *dst++ = c->status[i].sample2 & 0xFF;
- *dst++ = c->status[i].sample2 >> 8;
- }
-
- if(avctx->trellis > 0) {
- int n = avctx->block_align - 7*avctx->channels;
- uint8_t buf[2][n];
- if(avctx->channels == 1) {
- n *= 2;
- adpcm_compress_trellis(avctx, samples, buf[0], &c->status[0], n);
- for(i=0; i<n; i+=2)
- *dst++ = (buf[0][i] << 4) | buf[0][i+1];
- } else {
- adpcm_compress_trellis(avctx, samples, buf[0], &c->status[0], n);
- adpcm_compress_trellis(avctx, samples+1, buf[1], &c->status[1], n);
- for(i=0; i<n; i++)
- *dst++ = (buf[0][i] << 4) | buf[1][i];
- }
- } else
- for(i=7*avctx->channels; i<avctx->block_align; i++) {
- int nibble;
- nibble = adpcm_ms_compress_sample(&c->status[ 0], *samples++)<<4;
- nibble|= adpcm_ms_compress_sample(&c->status[st], *samples++);
- *dst++ = nibble;
- }
- break;
- case CODEC_ID_ADPCM_YAMAHA:
- n = avctx->frame_size / 2;
- if(avctx->trellis > 0) {
- uint8_t buf[2][n*2];
- n *= 2;
- if(avctx->channels == 1) {
- adpcm_compress_trellis(avctx, samples, buf[0], &c->status[0], n);
- for(i=0; i<n; i+=2)
- *dst++ = buf[0][i] | (buf[0][i+1] << 4);
- } else {
- adpcm_compress_trellis(avctx, samples, buf[0], &c->status[0], n);
- adpcm_compress_trellis(avctx, samples+1, buf[1], &c->status[1], n);
- for(i=0; i<n; i++)
- *dst++ = buf[0][i] | (buf[1][i] << 4);
- }
- } else
- for (; n>0; n--) {
- for(i = 0; i < avctx->channels; i++) {
- int nibble;
- nibble = adpcm_yamaha_compress_sample(&c->status[i], samples[i]);
- nibble |= adpcm_yamaha_compress_sample(&c->status[i], samples[i+avctx->channels]) << 4;
- *dst++ = nibble;
- }
- samples += 2 * avctx->channels;
- }
- break;
- default:
- return -1;
- }
- return dst - frame;
-}
-#endif //CONFIG_ENCODERS
-
-static int adpcm_decode_init(AVCodecContext * avctx)
-{
- ADPCMContext *c = avctx->priv_data;
-
- c->channel = 0;
- c->status[0].predictor = c->status[1].predictor = 0;
- c->status[0].step_index = c->status[1].step_index = 0;
- c->status[0].step = c->status[1].step = 0;
-
- switch(avctx->codec->id) {
- case CODEC_ID_ADPCM_CT:
- c->status[0].step = c->status[1].step = 511;
- break;
- default:
- break;
- }
- return 0;
-}
-
-static inline short adpcm_ima_expand_nibble(ADPCMChannelStatus *c, char nibble, int shift)
-{
- int step_index;
- int predictor;
- int sign, delta, diff, step;
-
- step = step_table[c->step_index];
- step_index = c->step_index + index_table[(unsigned)nibble];
- if (step_index < 0) step_index = 0;
- else if (step_index > 88) step_index = 88;
-
- sign = nibble & 8;
- delta = nibble & 7;
- /* perform direct multiplication instead of series of jumps proposed by
- * the reference ADPCM implementation since modern CPUs can do the mults
- * quickly enough */
- diff = ((2 * delta + 1) * step) >> shift;
- predictor = c->predictor;
- if (sign) predictor -= diff;
- else predictor += diff;
-
- CLAMP_TO_SHORT(predictor);
- c->predictor = predictor;
- c->step_index = step_index;
-
- return (short)predictor;
-}
-
-static inline short adpcm_ms_expand_nibble(ADPCMChannelStatus *c, char nibble)
-{
- int predictor;
-
- predictor = (((c->sample1) * (c->coeff1)) + ((c->sample2) * (c->coeff2))) / 256;
- predictor += (signed)((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->idelta;
- CLAMP_TO_SHORT(predictor);
-
- c->sample2 = c->sample1;
- c->sample1 = predictor;
- c->idelta = (AdaptationTable[(int)nibble] * c->idelta) >> 8;
- if (c->idelta < 16) c->idelta = 16;
-
- return (short)predictor;
-}
-
-static inline short adpcm_ct_expand_nibble(ADPCMChannelStatus *c, char nibble)
-{
- int predictor;
- int sign, delta, diff;
- int new_step;
-
- sign = nibble & 8;
- delta = nibble & 7;
- /* perform direct multiplication instead of series of jumps proposed by
- * the reference ADPCM implementation since modern CPUs can do the mults
- * quickly enough */
- diff = ((2 * delta + 1) * c->step) >> 3;
- predictor = c->predictor;
- /* predictor update is not so trivial: predictor is multiplied on 254/256 before updating */
- if(sign)
- predictor = ((predictor * 254) >> 8) - diff;
- else
- predictor = ((predictor * 254) >> 8) + diff;
- /* calculate new step and clamp it to range 511..32767 */
- new_step = (ct_adpcm_table[nibble & 7] * c->step) >> 8;
- c->step = new_step;
- if(c->step < 511)
- c->step = 511;
- if(c->step > 32767)
- c->step = 32767;
-
- CLAMP_TO_SHORT(predictor);
- c->predictor = predictor;
- return (short)predictor;
-}
-
-static inline short adpcm_sbpro_expand_nibble(ADPCMChannelStatus *c, char nibble, int size, int shift)
-{
- int sign, delta, diff;
-
- sign = nibble & (1<<(size-1));
- delta = nibble & ((1<<(size-1))-1);
- diff = delta << (7 + c->step + shift);
-
- if (sign)
- c->predictor -= diff;
- else
- c->predictor += diff;
-
- /* clamp result */
- if (c->predictor > 16256)
- c->predictor = 16256;
- else if (c->predictor < -16384)
- c->predictor = -16384;
-
- /* calculate new step */
- if (delta >= (2*size - 3) && c->step < 3)
- c->step++;
- else if (delta == 0 && c->step > 0)
- c->step--;
-
- return (short) c->predictor;
-}
-
-static inline short adpcm_yamaha_expand_nibble(ADPCMChannelStatus *c, unsigned char nibble)
-{
- if(!c->step) {
- c->predictor = 0;
- c->step = 127;
- }
-
- c->predictor += (c->step * yamaha_difflookup[nibble]) / 8;
- CLAMP_TO_SHORT(c->predictor);
- c->step = (c->step * yamaha_indexscale[nibble]) >> 8;
- c->step = clip(c->step, 127, 24567);
- return c->predictor;
-}
-
-static void xa_decode(short *out, const unsigned char *in,
- ADPCMChannelStatus *left, ADPCMChannelStatus *right, int inc)
-{
- int i, j;
- int shift,filter,f0,f1;
- int s_1,s_2;
- int d,s,t;
-
- for(i=0;i<4;i++) {
-
- shift = 12 - (in[4+i*2] & 15);
- filter = in[4+i*2] >> 4;
- f0 = xa_adpcm_table[filter][0];
- f1 = xa_adpcm_table[filter][1];
-
- s_1 = left->sample1;
- s_2 = left->sample2;
-
- for(j=0;j<28;j++) {
- d = in[16+i+j*4];
-
- t = (signed char)(d<<4)>>4;
- s = ( t<<shift ) + ((s_1*f0 + s_2*f1+32)>>6);
- CLAMP_TO_SHORT(s);
- *out = s;
- out += inc;
- s_2 = s_1;
- s_1 = s;
- }
-
- if (inc==2) { /* stereo */
- left->sample1 = s_1;
- left->sample2 = s_2;
- s_1 = right->sample1;
- s_2 = right->sample2;
- out = out + 1 - 28*2;
- }
-
- shift = 12 - (in[5+i*2] & 15);
- filter = in[5+i*2] >> 4;
-
- f0 = xa_adpcm_table[filter][0];
- f1 = xa_adpcm_table[filter][1];
-
- for(j=0;j<28;j++) {
- d = in[16+i+j*4];
-
- t = (signed char)d >> 4;
- s = ( t<<shift ) + ((s_1*f0 + s_2*f1+32)>>6);
- CLAMP_TO_SHORT(s);
- *out = s;
- out += inc;
- s_2 = s_1;
- s_1 = s;
- }
-
- if (inc==2) { /* stereo */
- right->sample1 = s_1;
- right->sample2 = s_2;
- out -= 1;
- } else {
- left->sample1 = s_1;
- left->sample2 = s_2;
- }
- }
-}
-
-
-/* DK3 ADPCM support macro */
-#define DK3_GET_NEXT_NIBBLE() \
- if (decode_top_nibble_next) \
- { \
- nibble = (last_byte >> 4) & 0x0F; \
- decode_top_nibble_next = 0; \
- } \
- else \
- { \
- last_byte = *src++; \
- if (src >= buf + buf_size) break; \
- nibble = last_byte & 0x0F; \
- decode_top_nibble_next = 1; \
- }
-
-static int adpcm_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- ADPCMContext *c = avctx->priv_data;
- ADPCMChannelStatus *cs;
- int n, m, channel, i;
- int block_predictor[2];
- short *samples;
- uint8_t *src;
- int st; /* stereo */
-
- /* DK3 ADPCM accounting variables */
- unsigned char last_byte = 0;
- unsigned char nibble;
- int decode_top_nibble_next = 0;
- int diff_channel;
-
- /* EA ADPCM state variables */
- uint32_t samples_in_chunk;
- int32_t previous_left_sample, previous_right_sample;
- int32_t current_left_sample, current_right_sample;
- int32_t next_left_sample, next_right_sample;
- int32_t coeff1l, coeff2l, coeff1r, coeff2r;
- uint8_t shift_left, shift_right;
- int count1, count2;
-
- if (!buf_size)
- return 0;
-
- samples = data;
- src = buf;
-
- st = avctx->channels == 2 ? 1 : 0;
-
- switch(avctx->codec->id) {
- case CODEC_ID_ADPCM_IMA_QT:
- n = (buf_size - 2);/* >> 2*avctx->channels;*/
- channel = c->channel;
- cs = &(c->status[channel]);
- /* (pppppp) (piiiiiii) */
-
- /* Bits 15-7 are the _top_ 9 bits of the 16-bit initial predictor value */
- cs->predictor = (*src++) << 8;
- cs->predictor |= (*src & 0x80);
- cs->predictor &= 0xFF80;
-
- /* sign extension */
- if(cs->predictor & 0x8000)
- cs->predictor -= 0x10000;
-
- CLAMP_TO_SHORT(cs->predictor);
-
- cs->step_index = (*src++) & 0x7F;
-
- if (cs->step_index > 88){
- av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n", cs->step_index);
- cs->step_index = 88;
- }
-
- cs->step = step_table[cs->step_index];
-
- if (st && channel)
- samples++;
-
- for(m=32; n>0 && m>0; n--, m--) { /* in QuickTime, IMA is encoded by chuncks of 34 bytes (=64 samples) */
- *samples = adpcm_ima_expand_nibble(cs, src[0] & 0x0F, 3);
- samples += avctx->channels;
- *samples = adpcm_ima_expand_nibble(cs, (src[0] >> 4) & 0x0F, 3);
- samples += avctx->channels;
- src ++;
- }
-
- if(st) { /* handle stereo interlacing */
- c->channel = (channel + 1) % 2; /* we get one packet for left, then one for right data */
- if(channel == 1) { /* wait for the other packet before outputing anything */
- return src - buf;
- }
- }
- break;
- case CODEC_ID_ADPCM_IMA_WAV:
- if (avctx->block_align != 0 && buf_size > avctx->block_align)
- buf_size = avctx->block_align;
-
-// samples_per_block= (block_align-4*chanels)*8 / (bits_per_sample * chanels) + 1;
-
- for(i=0; i<avctx->channels; i++){
- cs = &(c->status[i]);
- cs->predictor = (int16_t)(src[0] + (src[1]<<8));
- src+=2;
-
- // XXX: is this correct ??: *samples++ = cs->predictor;
-
- cs->step_index = *src++;
- if (cs->step_index > 88){
- av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n", cs->step_index);
- cs->step_index = 88;
- }
- if (*src++) av_log(avctx, AV_LOG_ERROR, "unused byte should be null but is %d!!\n", src[-1]); /* unused */
- }
-
- while(src < buf + buf_size){
- for(m=0; m<4; m++){
- for(i=0; i<=st; i++)
- *samples++ = adpcm_ima_expand_nibble(&c->status[i], src[4*i] & 0x0F, 3);
- for(i=0; i<=st; i++)
- *samples++ = adpcm_ima_expand_nibble(&c->status[i], src[4*i] >> 4 , 3);
- src++;
- }
- src += 4*st;
- }
- break;
- case CODEC_ID_ADPCM_4XM:
- cs = &(c->status[0]);
- c->status[0].predictor= (int16_t)(src[0] + (src[1]<<8)); src+=2;
- if(st){
- c->status[1].predictor= (int16_t)(src[0] + (src[1]<<8)); src+=2;
- }
- c->status[0].step_index= (int16_t)(src[0] + (src[1]<<8)); src+=2;
- if(st){
- c->status[1].step_index= (int16_t)(src[0] + (src[1]<<8)); src+=2;
- }
- if (cs->step_index < 0) cs->step_index = 0;
- if (cs->step_index > 88) cs->step_index = 88;
-
- m= (buf_size - (src - buf))>>st;
- for(i=0; i<m; i++) {
- *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[i] & 0x0F, 4);
- if (st)
- *samples++ = adpcm_ima_expand_nibble(&c->status[1], src[i+m] & 0x0F, 4);
- *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[i] >> 4, 4);
- if (st)
- *samples++ = adpcm_ima_expand_nibble(&c->status[1], src[i+m] >> 4, 4);
- }
-
- src += m<<st;
-
- break;
- case CODEC_ID_ADPCM_MS:
- if (avctx->block_align != 0 && buf_size > avctx->block_align)
- buf_size = avctx->block_align;
- n = buf_size - 7 * avctx->channels;
- if (n < 0)
- return -1;
- block_predictor[0] = clip(*src++, 0, 7);
- block_predictor[1] = 0;
- if (st)
- block_predictor[1] = clip(*src++, 0, 7);
- c->status[0].idelta = (int16_t)((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
- src+=2;
- if (st){
- c->status[1].idelta = (int16_t)((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
- src+=2;
- }
- c->status[0].coeff1 = AdaptCoeff1[block_predictor[0]];
- c->status[0].coeff2 = AdaptCoeff2[block_predictor[0]];
- c->status[1].coeff1 = AdaptCoeff1[block_predictor[1]];
- c->status[1].coeff2 = AdaptCoeff2[block_predictor[1]];
-
- c->status[0].sample1 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
- src+=2;
- if (st) c->status[1].sample1 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
- if (st) src+=2;
- c->status[0].sample2 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
- src+=2;
- if (st) c->status[1].sample2 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
- if (st) src+=2;
-
- *samples++ = c->status[0].sample1;
- if (st) *samples++ = c->status[1].sample1;
- *samples++ = c->status[0].sample2;
- if (st) *samples++ = c->status[1].sample2;
- for(;n>0;n--) {
- *samples++ = adpcm_ms_expand_nibble(&c->status[0], (src[0] >> 4) & 0x0F);
- *samples++ = adpcm_ms_expand_nibble(&c->status[st], src[0] & 0x0F);
- src ++;
- }
- break;
- case CODEC_ID_ADPCM_IMA_DK4:
- if (avctx->block_align != 0 && buf_size > avctx->block_align)
- buf_size = avctx->block_align;
-
- c->status[0].predictor = (int16_t)(src[0] | (src[1] << 8));
- c->status[0].step_index = src[2];
- src += 4;
- *samples++ = c->status[0].predictor;
- if (st) {
- c->status[1].predictor = (int16_t)(src[0] | (src[1] << 8));
- c->status[1].step_index = src[2];
- src += 4;
- *samples++ = c->status[1].predictor;
- }
- while (src < buf + buf_size) {
-
- /* take care of the top nibble (always left or mono channel) */
- *samples++ = adpcm_ima_expand_nibble(&c->status[0],
- (src[0] >> 4) & 0x0F, 3);
-
- /* take care of the bottom nibble, which is right sample for
- * stereo, or another mono sample */
- if (st)
- *samples++ = adpcm_ima_expand_nibble(&c->status[1],
- src[0] & 0x0F, 3);
- else
- *samples++ = adpcm_ima_expand_nibble(&c->status[0],
- src[0] & 0x0F, 3);
-
- src++;
- }
- break;
- case CODEC_ID_ADPCM_IMA_DK3:
- if (avctx->block_align != 0 && buf_size > avctx->block_align)
- buf_size = avctx->block_align;
-
- c->status[0].predictor = (int16_t)(src[10] | (src[11] << 8));
- c->status[1].predictor = (int16_t)(src[12] | (src[13] << 8));
- c->status[0].step_index = src[14];
- c->status[1].step_index = src[15];
- /* sign extend the predictors */
- src += 16;
- diff_channel = c->status[1].predictor;
-
- /* the DK3_GET_NEXT_NIBBLE macro issues the break statement when
- * the buffer is consumed */
- while (1) {
-
- /* for this algorithm, c->status[0] is the sum channel and
- * c->status[1] is the diff channel */
-
- /* process the first predictor of the sum channel */
- DK3_GET_NEXT_NIBBLE();
- adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
-
- /* process the diff channel predictor */
- DK3_GET_NEXT_NIBBLE();
- adpcm_ima_expand_nibble(&c->status[1], nibble, 3);
-
- /* process the first pair of stereo PCM samples */
- diff_channel = (diff_channel + c->status[1].predictor) / 2;
- *samples++ = c->status[0].predictor + c->status[1].predictor;
- *samples++ = c->status[0].predictor - c->status[1].predictor;
-
- /* process the second predictor of the sum channel */
- DK3_GET_NEXT_NIBBLE();
- adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
-
- /* process the second pair of stereo PCM samples */
- diff_channel = (diff_channel + c->status[1].predictor) / 2;
- *samples++ = c->status[0].predictor + c->status[1].predictor;
- *samples++ = c->status[0].predictor - c->status[1].predictor;
- }
- break;
- case CODEC_ID_ADPCM_IMA_WS:
- /* no per-block initialization; just start decoding the data */
- while (src < buf + buf_size) {
-
- if (st) {
- *samples++ = adpcm_ima_expand_nibble(&c->status[0],
- (src[0] >> 4) & 0x0F, 3);
- *samples++ = adpcm_ima_expand_nibble(&c->status[1],
- src[0] & 0x0F, 3);
- } else {
- *samples++ = adpcm_ima_expand_nibble(&c->status[0],
- (src[0] >> 4) & 0x0F, 3);
- *samples++ = adpcm_ima_expand_nibble(&c->status[0],
- src[0] & 0x0F, 3);
- }
-
- src++;
- }
- break;
- case CODEC_ID_ADPCM_XA:
- c->status[0].sample1 = c->status[0].sample2 =
- c->status[1].sample1 = c->status[1].sample2 = 0;
- while (buf_size >= 128) {
- xa_decode(samples, src, &c->status[0], &c->status[1],
- avctx->channels);
- src += 128;
- samples += 28 * 8;
- buf_size -= 128;
- }
- break;
- case CODEC_ID_ADPCM_EA:
- samples_in_chunk = AV_RL32(src);
- if (samples_in_chunk >= ((buf_size - 12) * 2)) {
- src += buf_size;
- break;
- }
- src += 4;
- current_left_sample = (int16_t)AV_RL16(src);
- src += 2;
- previous_left_sample = (int16_t)AV_RL16(src);
- src += 2;
- current_right_sample = (int16_t)AV_RL16(src);
- src += 2;
- previous_right_sample = (int16_t)AV_RL16(src);
- src += 2;
-
- for (count1 = 0; count1 < samples_in_chunk/28;count1++) {
- coeff1l = ea_adpcm_table[(*src >> 4) & 0x0F];
- coeff2l = ea_adpcm_table[((*src >> 4) & 0x0F) + 4];
- coeff1r = ea_adpcm_table[*src & 0x0F];
- coeff2r = ea_adpcm_table[(*src & 0x0F) + 4];
- src++;
-
- shift_left = ((*src >> 4) & 0x0F) + 8;
- shift_right = (*src & 0x0F) + 8;
- src++;
-
- for (count2 = 0; count2 < 28; count2++) {
- next_left_sample = (((*src & 0xF0) << 24) >> shift_left);
- next_right_sample = (((*src & 0x0F) << 28) >> shift_right);
- src++;
-
- next_left_sample = (next_left_sample +
- (current_left_sample * coeff1l) +
- (previous_left_sample * coeff2l) + 0x80) >> 8;
- next_right_sample = (next_right_sample +
- (current_right_sample * coeff1r) +
- (previous_right_sample * coeff2r) + 0x80) >> 8;
- CLAMP_TO_SHORT(next_left_sample);
- CLAMP_TO_SHORT(next_right_sample);
-
- previous_left_sample = current_left_sample;
- current_left_sample = next_left_sample;
- previous_right_sample = current_right_sample;
- current_right_sample = next_right_sample;
- *samples++ = (unsigned short)current_left_sample;
- *samples++ = (unsigned short)current_right_sample;
- }
- }
- break;
- case CODEC_ID_ADPCM_IMA_SMJPEG:
- c->status[0].predictor = *src;
- src += 2;
- c->status[0].step_index = *src++;
- src++; /* skip another byte before getting to the meat */
- while (src < buf + buf_size) {
- *samples++ = adpcm_ima_expand_nibble(&c->status[0],
- *src & 0x0F, 3);
- *samples++ = adpcm_ima_expand_nibble(&c->status[0],
- (*src >> 4) & 0x0F, 3);
- src++;
- }
- break;
- case CODEC_ID_ADPCM_CT:
- while (src < buf + buf_size) {
- if (st) {
- *samples++ = adpcm_ct_expand_nibble(&c->status[0],
- (src[0] >> 4) & 0x0F);
- *samples++ = adpcm_ct_expand_nibble(&c->status[1],
- src[0] & 0x0F);
- } else {
- *samples++ = adpcm_ct_expand_nibble(&c->status[0],
- (src[0] >> 4) & 0x0F);
- *samples++ = adpcm_ct_expand_nibble(&c->status[0],
- src[0] & 0x0F);
- }
- src++;
- }
- break;
- case CODEC_ID_ADPCM_SBPRO_4:
- case CODEC_ID_ADPCM_SBPRO_3:
- case CODEC_ID_ADPCM_SBPRO_2:
- if (!c->status[0].step_index) {
- /* the first byte is a raw sample */
- *samples++ = 128 * (*src++ - 0x80);
- if (st)
- *samples++ = 128 * (*src++ - 0x80);
- c->status[0].step_index = 1;
- }
- if (avctx->codec->id == CODEC_ID_ADPCM_SBPRO_4) {
- while (src < buf + buf_size) {
- *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
- (src[0] >> 4) & 0x0F, 4, 0);
- *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
- src[0] & 0x0F, 4, 0);
- src++;
- }
- } else if (avctx->codec->id == CODEC_ID_ADPCM_SBPRO_3) {
- while (src < buf + buf_size) {
- *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
- (src[0] >> 5) & 0x07, 3, 0);
- *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
- (src[0] >> 2) & 0x07, 3, 0);
- *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
- src[0] & 0x03, 2, 0);
- src++;
- }
- } else {
- while (src < buf + buf_size) {
- *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
- (src[0] >> 6) & 0x03, 2, 2);
- *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
- (src[0] >> 4) & 0x03, 2, 2);
- *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
- (src[0] >> 2) & 0x03, 2, 2);
- *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
- src[0] & 0x03, 2, 2);
- src++;
- }
- }
- break;
- case CODEC_ID_ADPCM_SWF:
- {
- GetBitContext gb;
- const int *table;
- int k0, signmask;
- int size = buf_size*8;
-
- init_get_bits(&gb, buf, size);
-
- // first frame, read bits & inital values
- if (!c->nb_bits)
- {
- c->nb_bits = get_bits(&gb, 2)+2;
-// av_log(NULL,AV_LOG_INFO,"nb_bits: %d\n", c->nb_bits);
- }
-
- table = swf_index_tables[c->nb_bits-2];
- k0 = 1 << (c->nb_bits-2);
- signmask = 1 << (c->nb_bits-1);
-
- while (get_bits_count(&gb) <= size)
- {
- int i;
-
- c->nb_samples++;
- // wrap around at every 4096 samples...
- if ((c->nb_samples & 0xfff) == 1)
- {
- for (i = 0; i <= st; i++)
- {
- *samples++ = c->status[i].predictor = get_sbits(&gb, 16);
- c->status[i].step_index = get_bits(&gb, 6);
- }
- }
-
- // similar to IMA adpcm
- for (i = 0; i <= st; i++)
- {
- int delta = get_bits(&gb, c->nb_bits);
- int step = step_table[c->status[i].step_index];
- long vpdiff = 0; // vpdiff = (delta+0.5)*step/4
- int k = k0;
-
- do {
- if (delta & k)
- vpdiff += step;
- step >>= 1;
- k >>= 1;
- } while(k);
- vpdiff += step;
-
- if (delta & signmask)
- c->status[i].predictor -= vpdiff;
- else
- c->status[i].predictor += vpdiff;
-
- c->status[i].step_index += table[delta & (~signmask)];
-
- c->status[i].step_index = clip(c->status[i].step_index, 0, 88);
- c->status[i].predictor = clip(c->status[i].predictor, -32768, 32767);
-
- *samples++ = c->status[i].predictor;
- }
- }
-
-// src += get_bits_count(&gb)*8;
- src += size;
-
- break;
- }
- case CODEC_ID_ADPCM_YAMAHA:
- while (src < buf + buf_size) {
- if (st) {
- *samples++ = adpcm_yamaha_expand_nibble(&c->status[0],
- src[0] & 0x0F);
- *samples++ = adpcm_yamaha_expand_nibble(&c->status[1],
- (src[0] >> 4) & 0x0F);
- } else {
- *samples++ = adpcm_yamaha_expand_nibble(&c->status[0],
- src[0] & 0x0F);
- *samples++ = adpcm_yamaha_expand_nibble(&c->status[0],
- (src[0] >> 4) & 0x0F);
- }
- src++;
- }
- break;
- default:
- return -1;
- }
- *data_size = (uint8_t *)samples - (uint8_t *)data;
- return src - buf;
-}
-
-
-
-#ifdef CONFIG_ENCODERS
-#define ADPCM_ENCODER(id,name) \
-AVCodec name ## _encoder = { \
- #name, \
- CODEC_TYPE_AUDIO, \
- id, \
- sizeof(ADPCMContext), \
- adpcm_encode_init, \
- adpcm_encode_frame, \
- adpcm_encode_close, \
- NULL, \
-};
-#else
-#define ADPCM_ENCODER(id,name)
-#endif
-
-#ifdef CONFIG_DECODERS
-#define ADPCM_DECODER(id,name) \
-AVCodec name ## _decoder = { \
- #name, \
- CODEC_TYPE_AUDIO, \
- id, \
- sizeof(ADPCMContext), \
- adpcm_decode_init, \
- NULL, \
- NULL, \
- adpcm_decode_frame, \
-};
-#else
-#define ADPCM_DECODER(id,name)
-#endif
-
-#define ADPCM_CODEC(id, name) \
-ADPCM_ENCODER(id,name) ADPCM_DECODER(id,name)
-
-ADPCM_CODEC(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt);
-ADPCM_CODEC(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav);
-ADPCM_CODEC(CODEC_ID_ADPCM_IMA_DK3, adpcm_ima_dk3);
-ADPCM_CODEC(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4);
-ADPCM_CODEC(CODEC_ID_ADPCM_IMA_WS, adpcm_ima_ws);
-ADPCM_CODEC(CODEC_ID_ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg);
-ADPCM_CODEC(CODEC_ID_ADPCM_MS, adpcm_ms);
-ADPCM_CODEC(CODEC_ID_ADPCM_4XM, adpcm_4xm);
-ADPCM_CODEC(CODEC_ID_ADPCM_XA, adpcm_xa);
-ADPCM_CODEC(CODEC_ID_ADPCM_EA, adpcm_ea);
-ADPCM_CODEC(CODEC_ID_ADPCM_CT, adpcm_ct);
-ADPCM_CODEC(CODEC_ID_ADPCM_SWF, adpcm_swf);
-ADPCM_CODEC(CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha);
-ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_4, adpcm_sbpro_4);
-ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_3, adpcm_sbpro_3);
-ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_2, adpcm_sbpro_2);
-
-#undef ADPCM_CODEC
diff --git a/src/libffmpeg/libavcodec/alpha/Makefile.am b/src/libffmpeg/libavcodec/alpha/Makefile.am
deleted file mode 100644
index c69106ad3..000000000
--- a/src/libffmpeg/libavcodec/alpha/Makefile.am
+++ /dev/null
@@ -1,13 +0,0 @@
-include $(top_srcdir)/misc/Makefile.common
-
-AM_CPPFLAGS = $(LIBFFMPEG_CPPFLAGS)
-AM_CFLAGS = -fno-strict-aliasing
-
-EXTRA_DIST = asm.h \
- dsputil_alpha.c \
- mpegvideo_alpha.c \
- motion_est_alpha.c \
- motion_est_mvi_asm.S \
- regdef.h \
- dsputil_alpha_asm.S \
- simple_idct_alpha.c
diff --git a/src/libffmpeg/libavcodec/alpha/dsputil_alpha_asm.S b/src/libffmpeg/libavcodec/alpha/dsputil_alpha_asm.S
deleted file mode 100644
index 367f2d743..000000000
--- a/src/libffmpeg/libavcodec/alpha/dsputil_alpha_asm.S
+++ /dev/null
@@ -1,285 +0,0 @@
-/*
- * Alpha optimized DSP utils
- * Copyright (c) 2002 Falk Hueffner <falk@debian.org>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * These functions are scheduled for pca56. They should work
- * reasonably on ev6, though.
- */
-
-#include "regdef.h"
-
-/* Some nicer register names. */
-#define ta t10
-#define tb t11
-#define tc t12
-#define td AT
-/* Danger: these overlap with the argument list and the return value */
-#define te a5
-#define tf a4
-#define tg a3
-#define th v0
-
- .set noat
- .set noreorder
- .arch pca56
- .text
-
-/************************************************************************
- * void put_pixels_axp_asm(uint8_t *block, const uint8_t *pixels,
- * int line_size, int h)
- */
- .align 6
- .globl put_pixels_axp_asm
- .ent put_pixels_axp_asm
-put_pixels_axp_asm:
- .frame sp, 0, ra
- .prologue 0
-
-#ifdef HAVE_GPROF
- lda AT, _mcount
- jsr AT, (AT), _mcount
-#endif
-
- and a1, 7, t0
- beq t0, $aligned
-
- .align 4
-$unaligned:
- ldq_u t0, 0(a1)
- ldq_u t1, 8(a1)
- addq a1, a2, a1
- nop
-
- ldq_u t2, 0(a1)
- ldq_u t3, 8(a1)
- addq a1, a2, a1
- nop
-
- ldq_u t4, 0(a1)
- ldq_u t5, 8(a1)
- addq a1, a2, a1
- nop
-
- ldq_u t6, 0(a1)
- ldq_u t7, 8(a1)
- extql t0, a1, t0
- addq a1, a2, a1
-
- extqh t1, a1, t1
- addq a0, a2, t8
- extql t2, a1, t2
- addq t8, a2, t9
-
- extqh t3, a1, t3
- addq t9, a2, ta
- extql t4, a1, t4
- or t0, t1, t0
-
- extqh t5, a1, t5
- or t2, t3, t2
- extql t6, a1, t6
- or t4, t5, t4
-
- extqh t7, a1, t7
- or t6, t7, t6
- stq t0, 0(a0)
- stq t2, 0(t8)
-
- stq t4, 0(t9)
- subq a3, 4, a3
- stq t6, 0(ta)
- addq ta, a2, a0
-
- bne a3, $unaligned
- ret
-
- .align 4
-$aligned:
- ldq t0, 0(a1)
- addq a1, a2, a1
- ldq t1, 0(a1)
- addq a1, a2, a1
-
- ldq t2, 0(a1)
- addq a1, a2, a1
- ldq t3, 0(a1)
-
- addq a0, a2, t4
- addq a1, a2, a1
- addq t4, a2, t5
- subq a3, 4, a3
-
- stq t0, 0(a0)
- addq t5, a2, t6
- stq t1, 0(t4)
- addq t6, a2, a0
-
- stq t2, 0(t5)
- stq t3, 0(t6)
-
- bne a3, $aligned
- ret
- .end put_pixels_axp_asm
-
-/************************************************************************
- * void put_pixels_clamped_mvi_asm(const DCTELEM *block, uint8_t *pixels,
- * int line_size)
- */
- .align 6
- .globl put_pixels_clamped_mvi_asm
- .ent put_pixels_clamped_mvi_asm
-put_pixels_clamped_mvi_asm:
- .frame sp, 0, ra
- .prologue 0
-
-#ifdef HAVE_GPROF
- lda AT, _mcount
- jsr AT, (AT), _mcount
-#endif
-
- lda t8, -1
- lda t9, 8 # loop counter
- zap t8, 0xaa, t8 # 00ff00ff00ff00ff
-
- .align 4
-1: ldq t0, 0(a0)
- ldq t1, 8(a0)
- ldq t2, 16(a0)
- ldq t3, 24(a0)
-
- maxsw4 t0, zero, t0
- subq t9, 2, t9
- maxsw4 t1, zero, t1
- lda a0, 32(a0)
-
- maxsw4 t2, zero, t2
- addq a1, a2, ta
- maxsw4 t3, zero, t3
- minsw4 t0, t8, t0
-
- minsw4 t1, t8, t1
- minsw4 t2, t8, t2
- minsw4 t3, t8, t3
- pkwb t0, t0
-
- pkwb t1, t1
- pkwb t2, t2
- pkwb t3, t3
- stl t0, 0(a1)
-
- stl t1, 4(a1)
- addq ta, a2, a1
- stl t2, 0(ta)
- stl t3, 4(ta)
-
- bne t9, 1b
- ret
- .end put_pixels_clamped_mvi_asm
-
-/************************************************************************
- * void add_pixels_clamped_mvi_asm(const DCTELEM *block, uint8_t *pixels,
- * int line_size)
- */
- .align 6
- .globl add_pixels_clamped_mvi_asm
- .ent add_pixels_clamped_mvi_asm
-add_pixels_clamped_mvi_asm:
- .frame sp, 0, ra
- .prologue 0
-
-#ifdef HAVE_GPROF
- lda AT, _mcount
- jsr AT, (AT), _mcount
-#endif
-
- lda t1, -1
- lda th, 8
- zap t1, 0x33, tg
- nop
-
- srl tg, 1, t0
- xor tg, t0, tg # 0x8000800080008000
- zap t1, 0xaa, tf # 0x00ff00ff00ff00ff
-
- .align 4
-1: ldl t1, 0(a1) # pix0 (try to hit cache line soon)
- ldl t4, 4(a1) # pix1
- addq a1, a2, te # pixels += line_size
- ldq t0, 0(a0) # shorts0
-
- ldl t7, 0(te) # pix2 (try to hit cache line soon)
- ldl ta, 4(te) # pix3
- ldq t3, 8(a0) # shorts1
- ldq t6, 16(a0) # shorts2
-
- ldq t9, 24(a0) # shorts3
- unpkbw t1, t1 # 0 0 (quarter/op no.)
- and t0, tg, t2 # 0 1
- unpkbw t4, t4 # 1 0
-
- bic t0, tg, t0 # 0 2
- unpkbw t7, t7 # 2 0
- and t3, tg, t5 # 1 1
- addq t0, t1, t0 # 0 3
-
- xor t0, t2, t0 # 0 4
- unpkbw ta, ta # 3 0
- and t6, tg, t8 # 2 1
- maxsw4 t0, zero, t0 # 0 5
-
- bic t3, tg, t3 # 1 2
- bic t6, tg, t6 # 2 2
- minsw4 t0, tf, t0 # 0 6
- addq t3, t4, t3 # 1 3
-
- pkwb t0, t0 # 0 7
- xor t3, t5, t3 # 1 4
- maxsw4 t3, zero, t3 # 1 5
- addq t6, t7, t6 # 2 3
-
- xor t6, t8, t6 # 2 4
- and t9, tg, tb # 3 1
- minsw4 t3, tf, t3 # 1 6
- bic t9, tg, t9 # 3 2
-
- maxsw4 t6, zero, t6 # 2 5
- addq t9, ta, t9 # 3 3
- stl t0, 0(a1) # 0 8
- minsw4 t6, tf, t6 # 2 6
-
- xor t9, tb, t9 # 3 4
- maxsw4 t9, zero, t9 # 3 5
- lda a0, 32(a0) # block += 16;
- pkwb t3, t3 # 1 7
-
- minsw4 t9, tf, t9 # 3 6
- subq th, 2, th
- pkwb t6, t6 # 2 7
- pkwb t9, t9 # 3 7
-
- stl t3, 4(a1) # 1 8
- addq te, a2, a1 # pixels += line_size
- stl t6, 0(te) # 2 8
- stl t9, 4(te) # 3 8
-
- bne th, 1b
- ret
- .end add_pixels_clamped_mvi_asm
diff --git a/src/libffmpeg/libavcodec/alpha/motion_est_mvi_asm.S b/src/libffmpeg/libavcodec/alpha/motion_est_mvi_asm.S
deleted file mode 100644
index 6015a7824..000000000
--- a/src/libffmpeg/libavcodec/alpha/motion_est_mvi_asm.S
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- * Alpha optimized DSP utils
- * Copyright (c) 2002 Falk Hueffner <falk@debian.org>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include "regdef.h"
-
-/* Some nicer register names. */
-#define ta t10
-#define tb t11
-#define tc t12
-#define td AT
-/* Danger: these overlap with the argument list and the return value */
-#define te a5
-#define tf a4
-#define tg a3
-#define th v0
-
- .set noat
- .set noreorder
- .arch pca56
- .text
-
-/*****************************************************************************
- * int pix_abs16x16_mvi_asm(uint8_t *pix1, uint8_t *pix2, int line_size)
- *
- * This code is written with a pca56 in mind. For ev6, one should
- * really take the increased latency of 3 cycles for MVI instructions
- * into account.
- *
- * It is important to keep the loading and first use of a register as
- * far apart as possible, because if a register is accessed before it
- * has been fetched from memory, the CPU will stall.
- */
- .align 4
- .globl pix_abs16x16_mvi_asm
- .ent pix_abs16x16_mvi_asm
-pix_abs16x16_mvi_asm:
- .frame sp, 0, ra, 0
- .prologue 0
-
-#ifdef HAVE_GPROF
- lda AT, _mcount
- jsr AT, (AT), _mcount
-#endif
-
- and a1, 7, t0
- clr v0
- lda a3, 16
- beq t0, $aligned
- .align 4
-$unaligned:
- /* Registers:
- line 0:
- t0: left_u -> left lo -> left
- t1: mid
- t2: right_u -> right hi -> right
- t3: ref left
- t4: ref right
- line 1:
- t5: left_u -> left lo -> left
- t6: mid
- t7: right_u -> right hi -> right
- t8: ref left
- t9: ref right
- temp:
- ta: left hi
- tb: right lo
- tc: error left
- td: error right */
-
- /* load line 0 */
- ldq_u t0, 0(a1) # left_u
- ldq_u t1, 8(a1) # mid
- ldq_u t2, 16(a1) # right_u
- ldq t3, 0(a0) # ref left
- ldq t4, 8(a0) # ref right
- addq a0, a2, a0 # pix1
- addq a1, a2, a1 # pix2
- /* load line 1 */
- ldq_u t5, 0(a1) # left_u
- ldq_u t6, 8(a1) # mid
- ldq_u t7, 16(a1) # right_u
- ldq t8, 0(a0) # ref left
- ldq t9, 8(a0) # ref right
- addq a0, a2, a0 # pix1
- addq a1, a2, a1 # pix2
- /* calc line 0 */
- extql t0, a1, t0 # left lo
- extqh t1, a1, ta # left hi
- extql t1, a1, tb # right lo
- or t0, ta, t0 # left
- extqh t2, a1, t2 # right hi
- perr t3, t0, tc # error left
- or t2, tb, t2 # right
- perr t4, t2, td # error right
- addq v0, tc, v0 # add error left
- addq v0, td, v0 # add error left
- /* calc line 1 */
- extql t5, a1, t5 # left lo
- extqh t6, a1, ta # left hi
- extql t6, a1, tb # right lo
- or t5, ta, t5 # left
- extqh t7, a1, t7 # right hi
- perr t8, t5, tc # error left
- or t7, tb, t7 # right
- perr t9, t7, td # error right
- addq v0, tc, v0 # add error left
- addq v0, td, v0 # add error left
- /* loop */
- subq a3, 2, a3 # h -= 2
- bne a3, $unaligned
- ret
-
- .align 4
-$aligned:
- /* load line 0 */
- ldq t0, 0(a1) # left
- ldq t1, 8(a1) # right
- addq a1, a2, a1 # pix2
- ldq t2, 0(a0) # ref left
- ldq t3, 8(a0) # ref right
- addq a0, a2, a0 # pix1
- /* load line 1 */
- ldq t4, 0(a1) # left
- ldq t5, 8(a1) # right
- addq a1, a2, a1 # pix2
- ldq t6, 0(a0) # ref left
- ldq t7, 8(a0) # ref right
- addq a0, a2, a0 # pix1
- /* load line 2 */
- ldq t8, 0(a1) # left
- ldq t9, 8(a1) # right
- addq a1, a2, a1 # pix2
- ldq ta, 0(a0) # ref left
- ldq tb, 8(a0) # ref right
- addq a0, a2, a0 # pix1
- /* load line 3 */
- ldq tc, 0(a1) # left
- ldq td, 8(a1) # right
- addq a1, a2, a1 # pix2
- ldq te, 0(a0) # ref left
- ldq tf, 8(a0) # ref right
- /* calc line 0 */
- perr t0, t2, t0 # error left
- addq a0, a2, a0 # pix1
- perr t1, t3, t1 # error right
- addq v0, t0, v0 # add error left
- /* calc line 1 */
- perr t4, t6, t0 # error left
- addq v0, t1, v0 # add error right
- perr t5, t7, t1 # error right
- addq v0, t0, v0 # add error left
- /* calc line 2 */
- perr t8, ta, t0 # error left
- addq v0, t1, v0 # add error right
- perr t9, tb, t1 # error right
- addq v0, t0, v0 # add error left
- /* calc line 3 */
- perr tc, te, t0 # error left
- addq v0, t1, v0 # add error right
- perr td, tf, t1 # error right
- addq v0, t0, v0 # add error left
- addq v0, t1, v0 # add error right
- /* loop */
- subq a3, 4, a3 # h -= 4
- bne a3, $aligned
- ret
- .end pix_abs16x16_mvi_asm
diff --git a/src/libffmpeg/libavcodec/alpha/simple_idct_alpha.c b/src/libffmpeg/libavcodec/alpha/simple_idct_alpha.c
deleted file mode 100644
index 111387ef0..000000000
--- a/src/libffmpeg/libavcodec/alpha/simple_idct_alpha.c
+++ /dev/null
@@ -1,308 +0,0 @@
-/*
- * Simple IDCT (Alpha optimized)
- *
- * Copyright (c) 2001 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * based upon some outcommented c code from mpeg2dec (idct_mmx.c
- * written by Aaron Holtzman <aholtzma@ess.engr.uvic.ca>)
- *
- * Alpha optimiziations by Måns Rullgård <mru@users.sourceforge.net>
- * and Falk Hueffner <falk@debian.org>
- */
-
-#include "asm.h"
-#include "../dsputil.h"
-
-extern void (*put_pixels_clamped_axp_p)(const DCTELEM *block, uint8_t *pixels,
- int line_size);
-extern void (*add_pixels_clamped_axp_p)(const DCTELEM *block, uint8_t *pixels,
- int line_size);
-
-// cos(i * M_PI / 16) * sqrt(2) * (1 << 14)
-// W4 is actually exactly 16384, but using 16383 works around
-// accumulating rounding errors for some encoders
-#define W1 ((int_fast32_t) 22725)
-#define W2 ((int_fast32_t) 21407)
-#define W3 ((int_fast32_t) 19266)
-#define W4 ((int_fast32_t) 16383)
-#define W5 ((int_fast32_t) 12873)
-#define W6 ((int_fast32_t) 8867)
-#define W7 ((int_fast32_t) 4520)
-#define ROW_SHIFT 11
-#define COL_SHIFT 20
-
-/* 0: all entries 0, 1: only first entry nonzero, 2: otherwise */
-static inline int idct_row(DCTELEM *row)
-{
- int_fast32_t a0, a1, a2, a3, b0, b1, b2, b3, t;
- uint64_t l, r, t2;
- l = ldq(row);
- r = ldq(row + 4);
-
- if (l == 0 && r == 0)
- return 0;
-
- a0 = W4 * sextw(l) + (1 << (ROW_SHIFT - 1));
-
- if (((l & ~0xffffUL) | r) == 0) {
- a0 >>= ROW_SHIFT;
- t2 = (uint16_t) a0;
- t2 |= t2 << 16;
- t2 |= t2 << 32;
-
- stq(t2, row);
- stq(t2, row + 4);
- return 1;
- }
-
- a1 = a0;
- a2 = a0;
- a3 = a0;
-
- t = extwl(l, 4); /* row[2] */
- if (t != 0) {
- t = sextw(t);
- a0 += W2 * t;
- a1 += W6 * t;
- a2 -= W6 * t;
- a3 -= W2 * t;
- }
-
- t = extwl(r, 0); /* row[4] */
- if (t != 0) {
- t = sextw(t);
- a0 += W4 * t;
- a1 -= W4 * t;
- a2 -= W4 * t;
- a3 += W4 * t;
- }
-
- t = extwl(r, 4); /* row[6] */
- if (t != 0) {
- t = sextw(t);
- a0 += W6 * t;
- a1 -= W2 * t;
- a2 += W2 * t;
- a3 -= W6 * t;
- }
-
- t = extwl(l, 2); /* row[1] */
- if (t != 0) {
- t = sextw(t);
- b0 = W1 * t;
- b1 = W3 * t;
- b2 = W5 * t;
- b3 = W7 * t;
- } else {
- b0 = 0;
- b1 = 0;
- b2 = 0;
- b3 = 0;
- }
-
- t = extwl(l, 6); /* row[3] */
- if (t) {
- t = sextw(t);
- b0 += W3 * t;
- b1 -= W7 * t;
- b2 -= W1 * t;
- b3 -= W5 * t;
- }
-
-
- t = extwl(r, 2); /* row[5] */
- if (t) {
- t = sextw(t);
- b0 += W5 * t;
- b1 -= W1 * t;
- b2 += W7 * t;
- b3 += W3 * t;
- }
-
- t = extwl(r, 6); /* row[7] */
- if (t) {
- t = sextw(t);
- b0 += W7 * t;
- b1 -= W5 * t;
- b2 += W3 * t;
- b3 -= W1 * t;
- }
-
- row[0] = (a0 + b0) >> ROW_SHIFT;
- row[1] = (a1 + b1) >> ROW_SHIFT;
- row[2] = (a2 + b2) >> ROW_SHIFT;
- row[3] = (a3 + b3) >> ROW_SHIFT;
- row[4] = (a3 - b3) >> ROW_SHIFT;
- row[5] = (a2 - b2) >> ROW_SHIFT;
- row[6] = (a1 - b1) >> ROW_SHIFT;
- row[7] = (a0 - b0) >> ROW_SHIFT;
-
- return 2;
-}
-
-static inline void idct_col(DCTELEM *col)
-{
- int_fast32_t a0, a1, a2, a3, b0, b1, b2, b3;
-
- col[0] += (1 << (COL_SHIFT - 1)) / W4;
-
- a0 = W4 * col[8 * 0];
- a1 = W4 * col[8 * 0];
- a2 = W4 * col[8 * 0];
- a3 = W4 * col[8 * 0];
-
- if (col[8 * 2]) {
- a0 += W2 * col[8 * 2];
- a1 += W6 * col[8 * 2];
- a2 -= W6 * col[8 * 2];
- a3 -= W2 * col[8 * 2];
- }
-
- if (col[8 * 4]) {
- a0 += W4 * col[8 * 4];
- a1 -= W4 * col[8 * 4];
- a2 -= W4 * col[8 * 4];
- a3 += W4 * col[8 * 4];
- }
-
- if (col[8 * 6]) {
- a0 += W6 * col[8 * 6];
- a1 -= W2 * col[8 * 6];
- a2 += W2 * col[8 * 6];
- a3 -= W6 * col[8 * 6];
- }
-
- if (col[8 * 1]) {
- b0 = W1 * col[8 * 1];
- b1 = W3 * col[8 * 1];
- b2 = W5 * col[8 * 1];
- b3 = W7 * col[8 * 1];
- } else {
- b0 = 0;
- b1 = 0;
- b2 = 0;
- b3 = 0;
- }
-
- if (col[8 * 3]) {
- b0 += W3 * col[8 * 3];
- b1 -= W7 * col[8 * 3];
- b2 -= W1 * col[8 * 3];
- b3 -= W5 * col[8 * 3];
- }
-
- if (col[8 * 5]) {
- b0 += W5 * col[8 * 5];
- b1 -= W1 * col[8 * 5];
- b2 += W7 * col[8 * 5];
- b3 += W3 * col[8 * 5];
- }
-
- if (col[8 * 7]) {
- b0 += W7 * col[8 * 7];
- b1 -= W5 * col[8 * 7];
- b2 += W3 * col[8 * 7];
- b3 -= W1 * col[8 * 7];
- }
-
- col[8 * 0] = (a0 + b0) >> COL_SHIFT;
- col[8 * 7] = (a0 - b0) >> COL_SHIFT;
- col[8 * 1] = (a1 + b1) >> COL_SHIFT;
- col[8 * 6] = (a1 - b1) >> COL_SHIFT;
- col[8 * 2] = (a2 + b2) >> COL_SHIFT;
- col[8 * 5] = (a2 - b2) >> COL_SHIFT;
- col[8 * 3] = (a3 + b3) >> COL_SHIFT;
- col[8 * 4] = (a3 - b3) >> COL_SHIFT;
-}
-
-/* If all rows but the first one are zero after row transformation,
- all rows will be identical after column transformation. */
-static inline void idct_col2(DCTELEM *col)
-{
- int i;
- uint64_t l, r;
-
- for (i = 0; i < 8; ++i) {
- int_fast32_t a0 = col[i] + (1 << (COL_SHIFT - 1)) / W4;
-
- a0 *= W4;
- col[i] = a0 >> COL_SHIFT;
- }
-
- l = ldq(col + 0 * 4); r = ldq(col + 1 * 4);
- stq(l, col + 2 * 4); stq(r, col + 3 * 4);
- stq(l, col + 4 * 4); stq(r, col + 5 * 4);
- stq(l, col + 6 * 4); stq(r, col + 7 * 4);
- stq(l, col + 8 * 4); stq(r, col + 9 * 4);
- stq(l, col + 10 * 4); stq(r, col + 11 * 4);
- stq(l, col + 12 * 4); stq(r, col + 13 * 4);
- stq(l, col + 14 * 4); stq(r, col + 15 * 4);
-}
-
-void simple_idct_axp(DCTELEM *block)
-{
-
- int i;
- int rowsZero = 1; /* all rows except row 0 zero */
- int rowsConstant = 1; /* all rows consist of a constant value */
-
- for (i = 0; i < 8; i++) {
- int sparseness = idct_row(block + 8 * i);
-
- if (i > 0 && sparseness > 0)
- rowsZero = 0;
- if (sparseness == 2)
- rowsConstant = 0;
- }
-
- if (rowsZero) {
- idct_col2(block);
- } else if (rowsConstant) {
- idct_col(block);
- for (i = 0; i < 8; i += 2) {
- uint64_t v = (uint16_t) block[0];
- uint64_t w = (uint16_t) block[8];
-
- v |= v << 16;
- w |= w << 16;
- v |= v << 32;
- w |= w << 32;
- stq(v, block + 0 * 4);
- stq(v, block + 1 * 4);
- stq(w, block + 2 * 4);
- stq(w, block + 3 * 4);
- block += 4 * 4;
- }
- } else {
- for (i = 0; i < 8; i++)
- idct_col(block + i);
- }
-}
-
-void simple_idct_put_axp(uint8_t *dest, int line_size, DCTELEM *block)
-{
- simple_idct_axp(block);
- put_pixels_clamped_axp_p(block, dest, line_size);
-}
-
-void simple_idct_add_axp(uint8_t *dest, int line_size, DCTELEM *block)
-{
- simple_idct_axp(block);
- add_pixels_clamped_axp_p(block, dest, line_size);
-}
diff --git a/src/libffmpeg/libavcodec/armv4l/Makefile.am b/src/libffmpeg/libavcodec/armv4l/Makefile.am
deleted file mode 100644
index 33e0882c9..000000000
--- a/src/libffmpeg/libavcodec/armv4l/Makefile.am
+++ /dev/null
@@ -1,23 +0,0 @@
-include $(top_srcdir)/misc/Makefile.common
-
-AM_CFLAGS = -O2 -fno-strict-aliasing
-AM_CPPFLAGS = $(LIBFFMPEG_CPPFLAGS)
-ASFLAGS =
-
-noinst_LTLIBRARIES = libavcodec_armv4l.la
-
-libavcodec_armv4l_src = dsputil_arm.c jrevdct_arm.S mpegvideo_arm.c simple_idct_arm.S \
- dsputil_arm_s.S dsputil_iwmmxt.c dsputil_iwmmxt_rnd.h \
- mpegvideo_armv5te.c mpegvideo_iwmmxt.c simple_idct_armv5te.S
-
-noinst_HEADERS = mathops.h
-
-libavcodec_armv4l_dummy = libavcodec_armv4l_dummy.c
-EXTRA_DIST = $(libavcodec_armv4l_src) $(libavcodec_armv4l_dummy)
-
-#if HAVE_ARMV4L
-#armv4l_modules = $(libavcodec_armv4l_src)
-#endif
-armv4l_modules =
-
-libavcodec_armv4l_la_SOURCES = $(armv4l_modules) $(libavcodec_armv4l_dummy)
diff --git a/src/libffmpeg/libavcodec/armv4l/dsputil_arm.c b/src/libffmpeg/libavcodec/armv4l/dsputil_arm.c
deleted file mode 100644
index 9f0bfa2af..000000000
--- a/src/libffmpeg/libavcodec/armv4l/dsputil_arm.c
+++ /dev/null
@@ -1,262 +0,0 @@
-/*
- * ARMv4L optimized DSP utils
- * Copyright (c) 2001 Lionel Ulmer.
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General 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 "../dsputil.h"
-#ifdef HAVE_IPP
-#include "ipp.h"
-#endif
-
-extern void dsputil_init_iwmmxt(DSPContext* c, AVCodecContext *avctx);
-
-extern void j_rev_dct_ARM(DCTELEM *data);
-extern void simple_idct_ARM(DCTELEM *data);
-
-extern void simple_idct_armv5te(DCTELEM *data);
-extern void simple_idct_put_armv5te(uint8_t *dest, int line_size,
- DCTELEM *data);
-extern void simple_idct_add_armv5te(uint8_t *dest, int line_size,
- DCTELEM *data);
-
-/* XXX: local hack */
-static void (*ff_put_pixels_clamped)(const DCTELEM *block, uint8_t *pixels, int line_size);
-static void (*ff_add_pixels_clamped)(const DCTELEM *block, uint8_t *pixels, int line_size);
-
-void put_pixels8_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h);
-void put_pixels8_x2_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h);
-void put_pixels8_y2_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h);
-void put_pixels8_xy2_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h);
-
-void put_no_rnd_pixels8_x2_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h);
-void put_no_rnd_pixels8_y2_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h);
-void put_no_rnd_pixels8_xy2_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h);
-
-void put_pixels16_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h);
-
-CALL_2X_PIXELS(put_pixels16_x2_arm , put_pixels8_x2_arm , 8)
-CALL_2X_PIXELS(put_pixels16_y2_arm , put_pixels8_y2_arm , 8)
-CALL_2X_PIXELS(put_pixels16_xy2_arm, put_pixels8_xy2_arm, 8)
-CALL_2X_PIXELS(put_no_rnd_pixels16_x2_arm , put_no_rnd_pixels8_x2_arm , 8)
-CALL_2X_PIXELS(put_no_rnd_pixels16_y2_arm , put_no_rnd_pixels8_y2_arm , 8)
-CALL_2X_PIXELS(put_no_rnd_pixels16_xy2_arm, put_no_rnd_pixels8_xy2_arm, 8)
-
-static void add_pixels_clamped_ARM(short *block, unsigned char *dest, int line_size)
-{
- asm volatile (
- "mov r10, #8 \n\t"
-
- "1: \n\t"
-
- /* load dest */
- "ldr r4, [%1] \n\t"
- /* block[0] and block[1]*/
- "ldrsh r5, [%0] \n\t"
- "ldrsh r7, [%0, #2] \n\t"
- "and r6, r4, #0xFF \n\t"
- "and r8, r4, #0xFF00 \n\t"
- "add r6, r5, r6 \n\t"
- "add r8, r7, r8, lsr #8 \n\t"
- "mvn r5, r5 \n\t"
- "mvn r7, r7 \n\t"
- "tst r6, #0x100 \n\t"
- "movne r6, r5, lsr #24 \n\t"
- "tst r8, #0x100 \n\t"
- "movne r8, r7, lsr #24 \n\t"
- "mov r9, r6 \n\t"
- "ldrsh r5, [%0, #4] \n\t" /* moved form [A] */
- "orr r9, r9, r8, lsl #8 \n\t"
- /* block[2] and block[3] */
- /* [A] */
- "ldrsh r7, [%0, #6] \n\t"
- "and r6, r4, #0xFF0000 \n\t"
- "and r8, r4, #0xFF000000 \n\t"
- "add r6, r5, r6, lsr #16 \n\t"
- "add r8, r7, r8, lsr #24 \n\t"
- "mvn r5, r5 \n\t"
- "mvn r7, r7 \n\t"
- "tst r6, #0x100 \n\t"
- "movne r6, r5, lsr #24 \n\t"
- "tst r8, #0x100 \n\t"
- "movne r8, r7, lsr #24 \n\t"
- "orr r9, r9, r6, lsl #16 \n\t"
- "ldr r4, [%1, #4] \n\t" /* moved form [B] */
- "orr r9, r9, r8, lsl #24 \n\t"
- /* store dest */
- "ldrsh r5, [%0, #8] \n\t" /* moved form [C] */
- "str r9, [%1] \n\t"
-
- /* load dest */
- /* [B] */
- /* block[4] and block[5] */
- /* [C] */
- "ldrsh r7, [%0, #10] \n\t"
- "and r6, r4, #0xFF \n\t"
- "and r8, r4, #0xFF00 \n\t"
- "add r6, r5, r6 \n\t"
- "add r8, r7, r8, lsr #8 \n\t"
- "mvn r5, r5 \n\t"
- "mvn r7, r7 \n\t"
- "tst r6, #0x100 \n\t"
- "movne r6, r5, lsr #24 \n\t"
- "tst r8, #0x100 \n\t"
- "movne r8, r7, lsr #24 \n\t"
- "mov r9, r6 \n\t"
- "ldrsh r5, [%0, #12] \n\t" /* moved from [D] */
- "orr r9, r9, r8, lsl #8 \n\t"
- /* block[6] and block[7] */
- /* [D] */
- "ldrsh r7, [%0, #14] \n\t"
- "and r6, r4, #0xFF0000 \n\t"
- "and r8, r4, #0xFF000000 \n\t"
- "add r6, r5, r6, lsr #16 \n\t"
- "add r8, r7, r8, lsr #24 \n\t"
- "mvn r5, r5 \n\t"
- "mvn r7, r7 \n\t"
- "tst r6, #0x100 \n\t"
- "movne r6, r5, lsr #24 \n\t"
- "tst r8, #0x100 \n\t"
- "movne r8, r7, lsr #24 \n\t"
- "orr r9, r9, r6, lsl #16 \n\t"
- "add %0, %0, #16 \n\t" /* moved from [E] */
- "orr r9, r9, r8, lsl #24 \n\t"
- "subs r10, r10, #1 \n\t" /* moved from [F] */
- /* store dest */
- "str r9, [%1, #4] \n\t"
-
- /* [E] */
- /* [F] */
- "add %1, %1, %2 \n\t"
- "bne 1b \n\t"
- : "+r"(block),
- "+r"(dest)
- : "r"(line_size)
- : "r4", "r5", "r6", "r7", "r8", "r9", "r10", "cc", "memory" );
-}
-
-/* XXX: those functions should be suppressed ASAP when all IDCTs are
- converted */
-static void j_rev_dct_ARM_put(uint8_t *dest, int line_size, DCTELEM *block)
-{
- j_rev_dct_ARM (block);
- ff_put_pixels_clamped(block, dest, line_size);
-}
-static void j_rev_dct_ARM_add(uint8_t *dest, int line_size, DCTELEM *block)
-{
- j_rev_dct_ARM (block);
- ff_add_pixels_clamped(block, dest, line_size);
-}
-static void simple_idct_ARM_put(uint8_t *dest, int line_size, DCTELEM *block)
-{
- simple_idct_ARM (block);
- ff_put_pixels_clamped(block, dest, line_size);
-}
-static void simple_idct_ARM_add(uint8_t *dest, int line_size, DCTELEM *block)
-{
- simple_idct_ARM (block);
- ff_add_pixels_clamped(block, dest, line_size);
-}
-
-#ifdef HAVE_IPP
-static void simple_idct_ipp(DCTELEM *block)
-{
- ippiDCT8x8Inv_Video_16s_C1I(block);
-}
-static void simple_idct_ipp_put(uint8_t *dest, int line_size, DCTELEM *block)
-{
- ippiDCT8x8Inv_Video_16s8u_C1R(block, dest, line_size);
-}
-
-void add_pixels_clamped_iwmmxt(const DCTELEM *block, uint8_t *pixels, int line_size);
-
-static void simple_idct_ipp_add(uint8_t *dest, int line_size, DCTELEM *block)
-{
- ippiDCT8x8Inv_Video_16s_C1I(block);
-#ifdef HAVE_IWMMXT
- add_pixels_clamped_iwmmxt(block, dest, line_size);
-#else
- add_pixels_clamped_ARM(block, dest, line_size);
-#endif
-}
-#endif
-
-void dsputil_init_armv4l(DSPContext* c, AVCodecContext *avctx)
-{
- int idct_algo= avctx->idct_algo;
-
- ff_put_pixels_clamped = c->put_pixels_clamped;
- ff_add_pixels_clamped = c->add_pixels_clamped;
-
- if(idct_algo == FF_IDCT_AUTO){
-#if defined(HAVE_IPP)
- idct_algo = FF_IDCT_IPP;
-#elif defined(HAVE_ARMV5TE)
- idct_algo = FF_IDCT_SIMPLEARMV5TE;
-#else
- idct_algo = FF_IDCT_ARM;
-#endif
- }
-
- if(idct_algo==FF_IDCT_ARM){
- c->idct_put= j_rev_dct_ARM_put;
- c->idct_add= j_rev_dct_ARM_add;
- c->idct = j_rev_dct_ARM;
- c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;/* FF_NO_IDCT_PERM */
- } else if (idct_algo==FF_IDCT_SIMPLEARM){
- c->idct_put= simple_idct_ARM_put;
- c->idct_add= simple_idct_ARM_add;
- c->idct = simple_idct_ARM;
- c->idct_permutation_type= FF_NO_IDCT_PERM;
-#ifdef HAVE_ARMV5TE
- } else if (idct_algo==FF_IDCT_SIMPLEARMV5TE){
- c->idct_put= simple_idct_put_armv5te;
- c->idct_add= simple_idct_add_armv5te;
- c->idct = simple_idct_armv5te;
- c->idct_permutation_type = FF_NO_IDCT_PERM;
-#endif
-#ifdef HAVE_IPP
- } else if (idct_algo==FF_IDCT_IPP){
- c->idct_put= simple_idct_ipp_put;
- c->idct_add= simple_idct_ipp_add;
- c->idct = simple_idct_ipp;
- c->idct_permutation_type= FF_NO_IDCT_PERM;
-#endif
- }
-
-/* c->put_pixels_tab[0][0] = put_pixels16_arm; */ // NG!
- c->put_pixels_tab[0][1] = put_pixels16_x2_arm; //OK!
- c->put_pixels_tab[0][2] = put_pixels16_y2_arm; //OK!
-/* c->put_pixels_tab[0][3] = put_pixels16_xy2_arm; /\* NG *\/ */
-/* c->put_no_rnd_pixels_tab[0][0] = put_pixels16_arm; */
- c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_arm; // OK
- c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_arm; //OK
-/* c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy2_arm; //NG */
- c->put_pixels_tab[1][0] = put_pixels8_arm; //OK
- c->put_pixels_tab[1][1] = put_pixels8_x2_arm; //OK
-/* c->put_pixels_tab[1][2] = put_pixels8_y2_arm; //NG */
-/* c->put_pixels_tab[1][3] = put_pixels8_xy2_arm; //NG */
- c->put_no_rnd_pixels_tab[1][0] = put_pixels8_arm;//OK
- c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_arm; //OK
- c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_arm; //OK
-/* c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels8_xy2_arm;//NG */
-
-#ifdef HAVE_IWMMXT
- dsputil_init_iwmmxt(c, avctx);
-#endif
-}
diff --git a/src/libffmpeg/libavcodec/armv4l/dsputil_iwmmxt.c b/src/libffmpeg/libavcodec/armv4l/dsputil_iwmmxt.c
deleted file mode 100644
index d7401e760..000000000
--- a/src/libffmpeg/libavcodec/armv4l/dsputil_iwmmxt.c
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * iWMMXt optimized DSP utils
- * Copyright (c) 2004 AGAWA Koji
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General 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 "../dsputil.h"
-
-#define DEF(x, y) x ## _no_rnd_ ## y ##_iwmmxt
-#define SET_RND(regd) __asm__ __volatile__ ("mov r12, #1 \n\t tbcsth " #regd ", r12":::"r12");
-#define WAVG2B "wavg2b"
-#include "dsputil_iwmmxt_rnd.h"
-#undef DEF
-#undef SET_RND
-#undef WAVG2B
-
-#define DEF(x, y) x ## _ ## y ##_iwmmxt
-#define SET_RND(regd) __asm__ __volatile__ ("mov r12, #2 \n\t tbcsth " #regd ", r12":::"r12");
-#define WAVG2B "wavg2br"
-#include "dsputil_iwmmxt_rnd.h"
-#undef DEF
-#undef SET_RND
-#undef WAVG2BR
-
-// need scheduling
-#define OP(AVG) \
- asm volatile ( \
- /* alignment */ \
- "and r12, %[pixels], #7 \n\t" \
- "bic %[pixels], %[pixels], #7 \n\t" \
- "tmcr wcgr1, r12 \n\t" \
- \
- "wldrd wr0, [%[pixels]] \n\t" \
- "wldrd wr1, [%[pixels], #8] \n\t" \
- "add %[pixels], %[pixels], %[line_size] \n\t" \
- "walignr1 wr4, wr0, wr1 \n\t" \
- \
- "1: \n\t" \
- \
- "wldrd wr2, [%[pixels]] \n\t" \
- "wldrd wr3, [%[pixels], #8] \n\t" \
- "add %[pixels], %[pixels], %[line_size] \n\t" \
- "pld [%[pixels]] \n\t" \
- "walignr1 wr5, wr2, wr3 \n\t" \
- AVG " wr6, wr4, wr5 \n\t" \
- "wstrd wr6, [%[block]] \n\t" \
- "add %[block], %[block], %[line_size] \n\t" \
- \
- "wldrd wr0, [%[pixels]] \n\t" \
- "wldrd wr1, [%[pixels], #8] \n\t" \
- "add %[pixels], %[pixels], %[line_size] \n\t" \
- "walignr1 wr4, wr0, wr1 \n\t" \
- "pld [%[pixels]] \n\t" \
- AVG " wr6, wr4, wr5 \n\t" \
- "wstrd wr6, [%[block]] \n\t" \
- "add %[block], %[block], %[line_size] \n\t" \
- \
- "subs %[h], %[h], #2 \n\t" \
- "bne 1b \n\t" \
- : [block]"+r"(block), [pixels]"+r"(pixels), [h]"+r"(h) \
- : [line_size]"r"(line_size) \
- : "memory", "r12");
-void put_pixels8_y2_iwmmxt(uint8_t *block, const uint8_t *pixels, const int line_size, int h)
-{
- OP("wavg2br");
-}
-void put_no_rnd_pixels8_y2_iwmmxt(uint8_t *block, const uint8_t *pixels, const int line_size, int h)
-{
- OP("wavg2b");
-}
-#undef OP
-
-void add_pixels_clamped_iwmmxt(const DCTELEM *block, uint8_t *pixels, int line_size)
-{
- uint8_t *pixels2 = pixels + line_size;
-
- __asm__ __volatile__ (
- "mov r12, #4 \n\t"
- "1: \n\t"
- "pld [%[pixels], %[line_size2]] \n\t"
- "pld [%[pixels2], %[line_size2]] \n\t"
- "wldrd wr4, [%[pixels]] \n\t"
- "wldrd wr5, [%[pixels2]] \n\t"
- "pld [%[block], #32] \n\t"
- "wunpckelub wr6, wr4 \n\t"
- "wldrd wr0, [%[block]] \n\t"
- "wunpckehub wr7, wr4 \n\t"
- "wldrd wr1, [%[block], #8] \n\t"
- "wunpckelub wr8, wr5 \n\t"
- "wldrd wr2, [%[block], #16] \n\t"
- "wunpckehub wr9, wr5 \n\t"
- "wldrd wr3, [%[block], #24] \n\t"
- "add %[block], %[block], #32 \n\t"
- "waddhss wr10, wr0, wr6 \n\t"
- "waddhss wr11, wr1, wr7 \n\t"
- "waddhss wr12, wr2, wr8 \n\t"
- "waddhss wr13, wr3, wr9 \n\t"
- "wpackhus wr14, wr10, wr11 \n\t"
- "wpackhus wr15, wr12, wr13 \n\t"
- "wstrd wr14, [%[pixels]] \n\t"
- "add %[pixels], %[pixels], %[line_size2] \n\t"
- "subs r12, r12, #1 \n\t"
- "wstrd wr15, [%[pixels2]] \n\t"
- "add %[pixels2], %[pixels2], %[line_size2] \n\t"
- "bne 1b \n\t"
- : [block]"+r"(block), [pixels]"+r"(pixels), [pixels2]"+r"(pixels2)
- : [line_size2]"r"(line_size << 1)
- : "cc", "memory", "r12");
-}
-
-static void nop(uint8_t *block, const uint8_t *pixels, int line_size, int h)
-{
- return;
-}
-
-int mm_flags; /* multimedia extension flags */
-
-int mm_support(void)
-{
- return 0; /* TODO, implement proper detection */
-}
-
-void dsputil_init_iwmmxt(DSPContext* c, AVCodecContext *avctx)
-{
- mm_flags = mm_support();
-
- if (avctx->dsp_mask) {
- if (avctx->dsp_mask & FF_MM_FORCE)
- mm_flags |= (avctx->dsp_mask & 0xffff);
- else
- mm_flags &= ~(avctx->dsp_mask & 0xffff);
- }
-
- if (!(mm_flags & MM_IWMMXT)) return;
-
- c->add_pixels_clamped = add_pixels_clamped_iwmmxt;
-
- c->put_pixels_tab[0][0] = put_pixels16_iwmmxt;
- c->put_pixels_tab[0][1] = put_pixels16_x2_iwmmxt;
- c->put_pixels_tab[0][2] = put_pixels16_y2_iwmmxt;
- c->put_pixels_tab[0][3] = put_pixels16_xy2_iwmmxt;
- c->put_no_rnd_pixels_tab[0][0] = put_pixels16_iwmmxt;
- c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_iwmmxt;
- c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_iwmmxt;
- c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy2_iwmmxt;
-
- c->put_pixels_tab[1][0] = put_pixels8_iwmmxt;
- c->put_pixels_tab[1][1] = put_pixels8_x2_iwmmxt;
- c->put_pixels_tab[1][2] = put_pixels8_y2_iwmmxt;
- c->put_pixels_tab[1][3] = put_pixels8_xy2_iwmmxt;
- c->put_no_rnd_pixels_tab[1][0] = put_pixels8_iwmmxt;
- c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_iwmmxt;
- c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_iwmmxt;
- c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels8_xy2_iwmmxt;
-
- c->avg_pixels_tab[0][0] = avg_pixels16_iwmmxt;
- c->avg_pixels_tab[0][1] = avg_pixels16_x2_iwmmxt;
- c->avg_pixels_tab[0][2] = avg_pixels16_y2_iwmmxt;
- c->avg_pixels_tab[0][3] = avg_pixels16_xy2_iwmmxt;
- c->avg_no_rnd_pixels_tab[0][0] = avg_pixels16_iwmmxt;
- c->avg_no_rnd_pixels_tab[0][1] = avg_no_rnd_pixels16_x2_iwmmxt;
- c->avg_no_rnd_pixels_tab[0][2] = avg_no_rnd_pixels16_y2_iwmmxt;
- c->avg_no_rnd_pixels_tab[0][3] = avg_no_rnd_pixels16_xy2_iwmmxt;
-
- c->avg_pixels_tab[1][0] = avg_pixels8_iwmmxt;
- c->avg_pixels_tab[1][1] = avg_pixels8_x2_iwmmxt;
- c->avg_pixels_tab[1][2] = avg_pixels8_y2_iwmmxt;
- c->avg_pixels_tab[1][3] = avg_pixels8_xy2_iwmmxt;
- c->avg_no_rnd_pixels_tab[1][0] = avg_no_rnd_pixels8_iwmmxt;
- c->avg_no_rnd_pixels_tab[1][1] = avg_no_rnd_pixels8_x2_iwmmxt;
- c->avg_no_rnd_pixels_tab[1][2] = avg_no_rnd_pixels8_y2_iwmmxt;
- c->avg_no_rnd_pixels_tab[1][3] = avg_no_rnd_pixels8_xy2_iwmmxt;
-}
diff --git a/src/libffmpeg/libavcodec/armv4l/libavcodec_armv4l_dummy.c b/src/libffmpeg/libavcodec/armv4l/libavcodec_armv4l_dummy.c
deleted file mode 100644
index ebe4c235c..000000000
--- a/src/libffmpeg/libavcodec/armv4l/libavcodec_armv4l_dummy.c
+++ /dev/null
@@ -1,2 +0,0 @@
-
-char libavcodec_armv4l_dummy;
diff --git a/src/libffmpeg/libavcodec/armv4l/mpegvideo_arm.c b/src/libffmpeg/libavcodec/armv4l/mpegvideo_arm.c
deleted file mode 100644
index ca972e6ed..000000000
--- a/src/libffmpeg/libavcodec/armv4l/mpegvideo_arm.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (c) 2002 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 "../dsputil.h"
-#include "../mpegvideo.h"
-#include "../avcodec.h"
-
-extern void MPV_common_init_iwmmxt(MpegEncContext *s);
-extern void MPV_common_init_armv5te(MpegEncContext *s);
-
-void MPV_common_init_armv4l(MpegEncContext *s)
-{
-#ifdef HAVE_IWMMXT
- MPV_common_init_iwmmxt(s);
-#elif defined(HAVE_ARMV5TE)
- MPV_common_init_armv5te(s);
-#endif
-}
diff --git a/src/libffmpeg/libavcodec/armv4l/mpegvideo_armv5te.c b/src/libffmpeg/libavcodec/armv4l/mpegvideo_armv5te.c
deleted file mode 100644
index a8d09b8ce..000000000
--- a/src/libffmpeg/libavcodec/armv4l/mpegvideo_armv5te.c
+++ /dev/null
@@ -1,213 +0,0 @@
-/*
- * Optimization of some functions from mpegvideo.c for armv5te
- * Copyright (c) 2007 Siarhei Siamashka <ssvb@users.sourceforge.net>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * Some useful links for those who may be interested in optimizing code for ARM.
- * ARM Architecture Reference Manual: http://www.arm.com/community/academy/resources.html
- * Instructions timings and optimization guide for ARM9E: http://www.arm.com/pdfs/DDI0222B_9EJS_r1p2.pdf
- */
-
-#include "../dsputil.h"
-#include "../mpegvideo.h"
-#include "../avcodec.h"
-
-
-#ifdef ENABLE_ARM_TESTS
-/**
- * h263 dequantizer supplementary function, it is performance critical and needs to
- * have optimized implementations for each architecture. Is also used as a reference
- * implementation in regression tests
- */
-static inline void dct_unquantize_h263_helper_c(DCTELEM *block, int qmul, int qadd, int count)
-{
- int i, level;
- for (i = 0; i < count; i++) {
- level = block[i];
- if (level) {
- if (level < 0) {
- level = level * qmul - qadd;
- } else {
- level = level * qmul + qadd;
- }
- block[i] = level;
- }
- }
-}
-#endif
-
-/* GCC 3.1 or higher is required to support symbolic names in assembly code */
-#if (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))
-
-/**
- * Special optimized version of dct_unquantize_h263_helper_c, it requires the block
- * to be at least 8 bytes aligned, and may process more elements than requested.
- * But it is guaranteed to never process more than 64 elements provided that
- * xxcount argument is <= 64, so it is safe. This macro is optimized for a common
- * distribution of values for nCoeffs (they are mostly multiple of 8 plus one or
- * two extra elements). So this macro processes data as 8 elements per loop iteration
- * and contains optional 2 elements processing in the end.
- *
- * Inner loop should take 6 cycles per element on arm926ej-s (Nokia 770)
- */
-#define dct_unquantize_h263_special_helper_armv5te(xxblock, xxqmul, xxqadd, xxcount) \
-({ DCTELEM *xblock = xxblock; \
- int xqmul = xxqmul, xqadd = xxqadd, xcount = xxcount, xtmp; \
- int xdata1, xdata2; \
-__asm__ __volatile__( \
- "subs %[count], #2 \n\t" \
- "ble 2f \n\t" \
- "ldrd r4, [%[block], #0] \n\t" \
- "1: \n\t" \
- "ldrd r6, [%[block], #8] \n\t" \
-\
- "rsbs %[data1], %[zero], r4, asr #16 \n\t" \
- "addgt %[data1], %[qadd], #0 \n\t" \
- "rsblt %[data1], %[qadd], #0 \n\t" \
- "smlatbne %[data1], r4, %[qmul], %[data1] \n\t" \
-\
- "rsbs %[data2], %[zero], r5, asr #16 \n\t" \
- "addgt %[data2], %[qadd], #0 \n\t" \
- "rsblt %[data2], %[qadd], #0 \n\t" \
- "smlatbne %[data2], r5, %[qmul], %[data2] \n\t" \
-\
- "rsbs %[tmp], %[zero], r4, asl #16 \n\t" \
- "addgt %[tmp], %[qadd], #0 \n\t" \
- "rsblt %[tmp], %[qadd], #0 \n\t" \
- "smlabbne r4, r4, %[qmul], %[tmp] \n\t" \
-\
- "rsbs %[tmp], %[zero], r5, asl #16 \n\t" \
- "addgt %[tmp], %[qadd], #0 \n\t" \
- "rsblt %[tmp], %[qadd], #0 \n\t" \
- "smlabbne r5, r5, %[qmul], %[tmp] \n\t" \
-\
- "strh r4, [%[block]], #2 \n\t" \
- "strh %[data1], [%[block]], #2 \n\t" \
- "strh r5, [%[block]], #2 \n\t" \
- "strh %[data2], [%[block]], #2 \n\t" \
-\
- "rsbs %[data1], %[zero], r6, asr #16 \n\t" \
- "addgt %[data1], %[qadd], #0 \n\t" \
- "rsblt %[data1], %[qadd], #0 \n\t" \
- "smlatbne %[data1], r6, %[qmul], %[data1] \n\t" \
-\
- "rsbs %[data2], %[zero], r7, asr #16 \n\t" \
- "addgt %[data2], %[qadd], #0 \n\t" \
- "rsblt %[data2], %[qadd], #0 \n\t" \
- "smlatbne %[data2], r7, %[qmul], %[data2] \n\t" \
-\
- "rsbs %[tmp], %[zero], r6, asl #16 \n\t" \
- "addgt %[tmp], %[qadd], #0 \n\t" \
- "rsblt %[tmp], %[qadd], #0 \n\t" \
- "smlabbne r6, r6, %[qmul], %[tmp] \n\t" \
-\
- "rsbs %[tmp], %[zero], r7, asl #16 \n\t" \
- "addgt %[tmp], %[qadd], #0 \n\t" \
- "rsblt %[tmp], %[qadd], #0 \n\t" \
- "smlabbne r7, r7, %[qmul], %[tmp] \n\t" \
-\
- "strh r6, [%[block]], #2 \n\t" \
- "strh %[data1], [%[block]], #2 \n\t" \
- "strh r7, [%[block]], #2 \n\t" \
- "strh %[data2], [%[block]], #2 \n\t" \
-\
- "subs %[count], #8 \n\t" \
- "ldrgtd r4, [%[block], #0] \n\t" /* load data early to avoid load/use pipeline stall */ \
- "bgt 1b \n\t" \
-\
- "adds %[count], #2 \n\t" \
- "ble 3f \n\t" \
- "2: \n\t" \
- "ldrsh %[data1], [%[block], #0] \n\t" \
- "ldrsh %[data2], [%[block], #2] \n\t" \
- "mov %[tmp], %[qadd] \n\t" \
- "cmp %[data1], #0 \n\t" \
- "rsblt %[tmp], %[qadd], #0 \n\t" \
- "smlabbne %[data1], %[data1], %[qmul], %[tmp] \n\t" \
- "mov %[tmp], %[qadd] \n\t" \
- "cmp %[data2], #0 \n\t" \
- "rsblt %[tmp], %[qadd], #0 \n\t" \
- "smlabbne %[data2], %[data2], %[qmul], %[tmp] \n\t" \
- "strh %[data1], [%[block]], #2 \n\t" \
- "strh %[data2], [%[block]], #2 \n\t" \
- "3: \n\t" \
- : [block] "+&r" (xblock), [count] "+&r" (xcount), [tmp] "=&r" (xtmp), \
- [data1] "=&r" (xdata1), [data2] "=&r" (xdata2) \
- : [qmul] "r" (xqmul), [qadd] "r" (xqadd), [zero] "r" (0) \
- : "r4", "r5", "r6", "r7", "cc", "memory" \
-); \
-})
-
-static void dct_unquantize_h263_intra_armv5te(MpegEncContext *s,
- DCTELEM *block, int n, int qscale)
-{
- int i, level, qmul, qadd;
- int nCoeffs;
-
- assert(s->block_last_index[n]>=0);
-
- qmul = qscale << 1;
-
- if (!s->h263_aic) {
- if (n < 4)
- level = block[0] * s->y_dc_scale;
- else
- level = block[0] * s->c_dc_scale;
- qadd = (qscale - 1) | 1;
- }else{
- qadd = 0;
- level = block[0];
- }
- if(s->ac_pred)
- nCoeffs=63;
- else
- nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];
-
- dct_unquantize_h263_special_helper_armv5te(block, qmul, qadd, nCoeffs + 1);
- block[0] = level;
-}
-
-static void dct_unquantize_h263_inter_armv5te(MpegEncContext *s,
- DCTELEM *block, int n, int qscale)
-{
- int i, level, qmul, qadd;
- int nCoeffs;
-
- assert(s->block_last_index[n]>=0);
-
- qadd = (qscale - 1) | 1;
- qmul = qscale << 1;
-
- nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];
-
- dct_unquantize_h263_special_helper_armv5te(block, qmul, qadd, nCoeffs + 1);
-}
-
-#define HAVE_DCT_UNQUANTIZE_H263_ARMV5TE_OPTIMIZED
-
-#endif
-
-void MPV_common_init_armv5te(MpegEncContext *s)
-{
-#ifdef HAVE_DCT_UNQUANTIZE_H263_ARMV5TE_OPTIMIZED
- s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_armv5te;
- s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_armv5te;
-#endif
-}
diff --git a/src/libffmpeg/libavcodec/avcodec.h b/src/libffmpeg/libavcodec/avcodec.h
deleted file mode 100644
index ee4eb0122..000000000
--- a/src/libffmpeg/libavcodec/avcodec.h
+++ /dev/null
@@ -1,2714 +0,0 @@
-/*
- * copyright (c) 2001 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 St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef AVCODEC_H
-#define AVCODEC_H
-
-/**
- * @file avcodec.h
- * external api header.
- */
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "avutil.h"
-#include <sys/types.h> /* size_t */
-
-#define AV_STRINGIFY(s) AV_TOSTRING(s)
-#define AV_TOSTRING(s) #s
-
-#define LIBAVCODEC_VERSION_INT ((51<<16)+(29<<8)+0)
-#define LIBAVCODEC_VERSION 51.29.0
-#define LIBAVCODEC_BUILD LIBAVCODEC_VERSION_INT
-
-#define LIBAVCODEC_IDENT "Lavc" AV_STRINGIFY(LIBAVCODEC_VERSION)
-
-#define AV_NOPTS_VALUE INT64_C(0x8000000000000000)
-#define AV_TIME_BASE 1000000
-#define AV_TIME_BASE_Q (AVRational){1, AV_TIME_BASE}
-
-/* FIXME: We cannot use ffmpeg's XvMC capabilities, since that would require
- * linking the ffmpeg plugin against XvMC libraries, which is a bad thing,
- * since they are output dependend.
- * The correct fix would be to reimplement the XvMC functions libavcodec uses
- * and do the necessary talking with our XvMC output plugin there. */
-#undef HAVE_XVMC
-
-enum CodecID {
- CODEC_ID_NONE,
- CODEC_ID_MPEG1VIDEO,
- CODEC_ID_MPEG2VIDEO, /* prefered ID for MPEG Video 1 or 2 decoding */
- CODEC_ID_MPEG2VIDEO_XVMC,
- CODEC_ID_H261,
- CODEC_ID_H263,
- CODEC_ID_RV10,
- CODEC_ID_RV20,
- CODEC_ID_MJPEG,
- CODEC_ID_MJPEGB,
- CODEC_ID_LJPEG,
- CODEC_ID_SP5X,
- CODEC_ID_JPEGLS,
- CODEC_ID_MPEG4,
- CODEC_ID_RAWVIDEO,
- CODEC_ID_MSMPEG4V1,
- CODEC_ID_MSMPEG4V2,
- CODEC_ID_MSMPEG4V3,
- CODEC_ID_WMV1,
- CODEC_ID_WMV2,
- CODEC_ID_H263P,
- CODEC_ID_H263I,
- CODEC_ID_FLV1,
- CODEC_ID_SVQ1,
- CODEC_ID_SVQ3,
- CODEC_ID_DVVIDEO,
- CODEC_ID_HUFFYUV,
- CODEC_ID_CYUV,
- CODEC_ID_H264,
- CODEC_ID_INDEO3,
- CODEC_ID_VP3,
- CODEC_ID_THEORA,
- CODEC_ID_ASV1,
- CODEC_ID_ASV2,
- CODEC_ID_FFV1,
- CODEC_ID_4XM,
- CODEC_ID_VCR1,
- CODEC_ID_CLJR,
- CODEC_ID_MDEC,
- CODEC_ID_ROQ,
- CODEC_ID_INTERPLAY_VIDEO,
- CODEC_ID_XAN_WC3,
- CODEC_ID_XAN_WC4,
- CODEC_ID_RPZA,
- CODEC_ID_CINEPAK,
- CODEC_ID_WS_VQA,
- CODEC_ID_MSRLE,
- CODEC_ID_MSVIDEO1,
- CODEC_ID_IDCIN,
- CODEC_ID_8BPS,
- CODEC_ID_SMC,
- CODEC_ID_FLIC,
- CODEC_ID_TRUEMOTION1,
- CODEC_ID_VMDVIDEO,
- CODEC_ID_MSZH,
- CODEC_ID_ZLIB,
- CODEC_ID_QTRLE,
- CODEC_ID_SNOW,
- CODEC_ID_TSCC,
- CODEC_ID_ULTI,
- CODEC_ID_QDRAW,
- CODEC_ID_VIXL,
- CODEC_ID_QPEG,
- CODEC_ID_XVID,
- CODEC_ID_PNG,
- CODEC_ID_PPM,
- CODEC_ID_PBM,
- CODEC_ID_PGM,
- CODEC_ID_PGMYUV,
- CODEC_ID_PAM,
- CODEC_ID_FFVHUFF,
- CODEC_ID_RV30,
- CODEC_ID_RV40,
- CODEC_ID_VC1,
- CODEC_ID_WMV3,
- CODEC_ID_LOCO,
- CODEC_ID_WNV1,
- CODEC_ID_AASC,
- CODEC_ID_INDEO2,
- CODEC_ID_FRAPS,
- CODEC_ID_TRUEMOTION2,
- CODEC_ID_BMP,
- CODEC_ID_CSCD,
- CODEC_ID_MMVIDEO,
- CODEC_ID_ZMBV,
- CODEC_ID_AVS,
- CODEC_ID_SMACKVIDEO,
- CODEC_ID_NUV,
- CODEC_ID_KMVC,
- CODEC_ID_FLASHSV,
- CODEC_ID_CAVS,
- CODEC_ID_JPEG2000,
- CODEC_ID_VMNC,
- CODEC_ID_VP5,
- CODEC_ID_VP6,
- CODEC_ID_VP6F,
- CODEC_ID_TARGA,
- CODEC_ID_DSICINVIDEO,
- CODEC_ID_TIERTEXSEQVIDEO,
- CODEC_ID_TIFF,
- CODEC_ID_GIF,
- CODEC_ID_FFH264,
-
- /* various pcm "codecs" */
- CODEC_ID_PCM_S16LE= 0x10000,
- CODEC_ID_PCM_S16BE,
- CODEC_ID_PCM_U16LE,
- CODEC_ID_PCM_U16BE,
- CODEC_ID_PCM_S8,
- CODEC_ID_PCM_U8,
- CODEC_ID_PCM_MULAW,
- CODEC_ID_PCM_ALAW,
- CODEC_ID_PCM_S32LE,
- CODEC_ID_PCM_S32BE,
- CODEC_ID_PCM_U32LE,
- CODEC_ID_PCM_U32BE,
- CODEC_ID_PCM_S24LE,
- CODEC_ID_PCM_S24BE,
- CODEC_ID_PCM_U24LE,
- CODEC_ID_PCM_U24BE,
- CODEC_ID_PCM_S24DAUD,
-
- /* various adpcm codecs */
- CODEC_ID_ADPCM_IMA_QT= 0x11000,
- CODEC_ID_ADPCM_IMA_WAV,
- CODEC_ID_ADPCM_IMA_DK3,
- CODEC_ID_ADPCM_IMA_DK4,
- CODEC_ID_ADPCM_IMA_WS,
- CODEC_ID_ADPCM_IMA_SMJPEG,
- CODEC_ID_ADPCM_MS,
- CODEC_ID_ADPCM_4XM,
- CODEC_ID_ADPCM_XA,
- CODEC_ID_ADPCM_ADX,
- CODEC_ID_ADPCM_EA,
- CODEC_ID_ADPCM_G726,
- CODEC_ID_ADPCM_CT,
- CODEC_ID_ADPCM_SWF,
- CODEC_ID_ADPCM_YAMAHA,
- CODEC_ID_ADPCM_SBPRO_4,
- CODEC_ID_ADPCM_SBPRO_3,
- CODEC_ID_ADPCM_SBPRO_2,
-
- /* AMR */
- CODEC_ID_AMR_NB= 0x12000,
- CODEC_ID_AMR_WB,
-
- /* RealAudio codecs*/
- CODEC_ID_RA_144= 0x13000,
- CODEC_ID_RA_288,
-
- /* various DPCM codecs */
- CODEC_ID_ROQ_DPCM= 0x14000,
- CODEC_ID_INTERPLAY_DPCM,
- CODEC_ID_XAN_DPCM,
- CODEC_ID_SOL_DPCM,
-
- CODEC_ID_MP2= 0x15000,
- CODEC_ID_MP3, /* prefered ID for MPEG Audio layer 1, 2 or3 decoding */
- CODEC_ID_AAC,
-#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
- CODEC_ID_MPEG4AAC,
-#endif
- CODEC_ID_AC3,
- CODEC_ID_DTS,
- CODEC_ID_VORBIS,
- CODEC_ID_DVAUDIO,
- CODEC_ID_WMAV1,
- CODEC_ID_WMAV2,
- CODEC_ID_MACE3,
- CODEC_ID_MACE6,
- CODEC_ID_VMDAUDIO,
- CODEC_ID_SONIC,
- CODEC_ID_SONIC_LS,
- CODEC_ID_FLAC,
- CODEC_ID_MP3ADU,
- CODEC_ID_MP3ON4,
- CODEC_ID_SHORTEN,
- CODEC_ID_ALAC,
- CODEC_ID_WESTWOOD_SND1,
- CODEC_ID_GSM,
- CODEC_ID_QDM2,
- CODEC_ID_COOK,
- CODEC_ID_TRUESPEECH,
- CODEC_ID_TTA,
- CODEC_ID_SMACKAUDIO,
- CODEC_ID_QCELP,
- CODEC_ID_WAVPACK,
- CODEC_ID_DSICINAUDIO,
- CODEC_ID_IMC,
- CODEC_ID_MUSEPACK7,
-
- /* subtitle codecs */
- CODEC_ID_DVD_SUBTITLE= 0x17000,
- CODEC_ID_DVB_SUBTITLE,
-
- CODEC_ID_MPEG2TS= 0x20000, /* _FAKE_ codec to indicate a raw MPEG2 transport
- stream (only used by libavformat) */
-};
-
-/* CODEC_ID_MP3LAME is absolete */
-#define CODEC_ID_MP3LAME CODEC_ID_MP3
-
-enum CodecType {
- CODEC_TYPE_UNKNOWN = -1,
- CODEC_TYPE_VIDEO,
- CODEC_TYPE_AUDIO,
- CODEC_TYPE_DATA,
- CODEC_TYPE_SUBTITLE,
-};
-
-/* currently unused, may be used if 24/32 bits samples ever supported */
-/* all in native endian */
-enum SampleFormat {
- SAMPLE_FMT_NONE = -1,
- SAMPLE_FMT_U8, ///< unsigned 8 bits
- SAMPLE_FMT_S16, ///< signed 16 bits
- SAMPLE_FMT_S24, ///< signed 24 bits
- SAMPLE_FMT_S32, ///< signed 32 bits
- SAMPLE_FMT_FLT, ///< float
-};
-
-/* in bytes */
-#define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000 // 1 second of 48khz 32bit audio
-
-/**
- * Required number of additionally allocated bytes at the end of the input bitstream for decoding.
- * this is mainly needed because some optimized bitstream readers read
- * 32 or 64 bit at once and could read over the end<br>
- * Note, if the first 23 bits of the additional bytes are not 0 then damaged
- * MPEG bitstreams could cause overread and segfault
- */
-#define FF_INPUT_BUFFER_PADDING_SIZE 8
-
-/**
- * minimum encoding buffer size.
- * used to avoid some checks during header writing
- */
-#define FF_MIN_BUFFER_SIZE 16384
-
-/* motion estimation type, EPZS by default */
-enum Motion_Est_ID {
- ME_ZERO = 1,
- ME_FULL,
- ME_LOG,
- ME_PHODS,
- ME_EPZS,
- ME_X1,
- ME_HEX,
- ME_UMH,
- ME_ITER,
-};
-
-enum AVDiscard{
-//we leave some space between them for extensions (drop some keyframes for intra only or drop just some bidir frames)
- AVDISCARD_NONE =-16, ///< discard nothing
- AVDISCARD_DEFAULT= 0, ///< discard useless packets like 0 size packets in avi
- AVDISCARD_NONREF = 8, ///< discard all non reference
- AVDISCARD_BIDIR = 16, ///< discard all bidirectional frames
- AVDISCARD_NONKEY = 32, ///< discard all frames except keyframes
- AVDISCARD_ALL = 48, ///< discard all
-};
-
-typedef struct RcOverride{
- int start_frame;
- int end_frame;
- int qscale; // if this is 0 then quality_factor will be used instead
- float quality_factor;
-} RcOverride;
-
-#define FF_MAX_B_FRAMES 16
-
-/* encoding support
- these flags can be passed in AVCodecContext.flags before initing
- Note: not everything is supported yet.
-*/
-
-#define CODEC_FLAG_QSCALE 0x0002 ///< use fixed qscale
-#define CODEC_FLAG_4MV 0x0004 ///< 4 MV per MB allowed / Advanced prediction for H263
-#define CODEC_FLAG_QPEL 0x0010 ///< use qpel MC
-#define CODEC_FLAG_GMC 0x0020 ///< use GMC
-#define CODEC_FLAG_MV0 0x0040 ///< always try a MB with MV=<0,0>
-#define CODEC_FLAG_PART 0x0080 ///< use data partitioning
-/* parent program gurantees that the input for b-frame containing streams is not written to
- for at least s->max_b_frames+1 frames, if this is not set than the input will be copied */
-#define CODEC_FLAG_INPUT_PRESERVED 0x0100
-#define CODEC_FLAG_PASS1 0x0200 ///< use internal 2pass ratecontrol in first pass mode
-#define CODEC_FLAG_PASS2 0x0400 ///< use internal 2pass ratecontrol in second pass mode
-#define CODEC_FLAG_EXTERN_HUFF 0x1000 ///< use external huffman table (for mjpeg)
-#define CODEC_FLAG_GRAY 0x2000 ///< only decode/encode grayscale
-#define CODEC_FLAG_EMU_EDGE 0x4000///< don't draw edges
-#define CODEC_FLAG_PSNR 0x8000 ///< error[?] variables will be set during encoding
-#define CODEC_FLAG_TRUNCATED 0x00010000 /** input bitstream might be truncated at a random location instead
- of only at frame boundaries */
-#define CODEC_FLAG_NORMALIZE_AQP 0x00020000 ///< normalize adaptive quantization
-#define CODEC_FLAG_INTERLACED_DCT 0x00040000 ///< use interlaced dct
-#define CODEC_FLAG_LOW_DELAY 0x00080000 ///< force low delay
-#define CODEC_FLAG_ALT_SCAN 0x00100000 ///< use alternate scan
-#define CODEC_FLAG_TRELLIS_QUANT 0x00200000 ///< use trellis quantization
-#define CODEC_FLAG_GLOBAL_HEADER 0x00400000 ///< place global headers in extradata instead of every keyframe
-#define CODEC_FLAG_BITEXACT 0x00800000 ///< use only bitexact stuff (except (i)dct)
-/* Fx : Flag for h263+ extra options */
-#define CODEC_FLAG_H263P_AIC 0x01000000 ///< H263 Advanced intra coding / MPEG4 AC prediction (remove this)
-#define CODEC_FLAG_AC_PRED 0x01000000 ///< H263 Advanced intra coding / MPEG4 AC prediction
-#define CODEC_FLAG_H263P_UMV 0x02000000 ///< Unlimited motion vector
-#define CODEC_FLAG_CBP_RD 0x04000000 ///< use rate distortion optimization for cbp
-#define CODEC_FLAG_QP_RD 0x08000000 ///< use rate distortion optimization for qp selectioon
-#define CODEC_FLAG_H263P_AIV 0x00000008 ///< H263 Alternative inter vlc
-#define CODEC_FLAG_OBMC 0x00000001 ///< OBMC
-#define CODEC_FLAG_LOOP_FILTER 0x00000800 ///< loop filter
-#define CODEC_FLAG_H263P_SLICE_STRUCT 0x10000000
-#define CODEC_FLAG_INTERLACED_ME 0x20000000 ///< interlaced motion estimation
-#define CODEC_FLAG_SVCD_SCAN_OFFSET 0x40000000 ///< will reserve space for SVCD scan offset user data
-#define CODEC_FLAG_CLOSED_GOP ((int)0x80000000)
-#define CODEC_FLAG2_FAST 0x00000001 ///< allow non spec compliant speedup tricks
-#define CODEC_FLAG2_STRICT_GOP 0x00000002 ///< strictly enforce GOP size
-#define CODEC_FLAG2_NO_OUTPUT 0x00000004 ///< skip bitstream encoding
-#define CODEC_FLAG2_LOCAL_HEADER 0x00000008 ///< place global headers at every keyframe instead of in extradata
-#define CODEC_FLAG2_BPYRAMID 0x00000010 ///< H.264 allow b-frames to be used as references
-#define CODEC_FLAG2_WPRED 0x00000020 ///< H.264 weighted biprediction for b-frames
-#define CODEC_FLAG2_MIXED_REFS 0x00000040 ///< H.264 one reference per partition, as opposed to one reference per macroblock
-#define CODEC_FLAG2_8X8DCT 0x00000080 ///< H.264 high profile 8x8 transform
-#define CODEC_FLAG2_FASTPSKIP 0x00000100 ///< H.264 fast pskip
-#define CODEC_FLAG2_AUD 0x00000200 ///< H.264 access unit delimiters
-#define CODEC_FLAG2_BRDO 0x00000400 ///< b-frame rate-distortion optimization
-#define CODEC_FLAG2_INTRA_VLC 0x00000800 ///< use MPEG-2 intra VLC table
-#define CODEC_FLAG2_MEMC_ONLY 0x00001000 ///< only do ME/MC (I frames -> ref, P frame -> ME+MC)
-#define CODEC_FLAG2_DROP_FRAME_TIMECODE 0x00002000 ///< timecode is in drop frame format
-#define CODEC_FLAG2_SKIP_RD 0x00004000 ///< RD optimal MB level residual skiping
-
-/* Unsupported options :
- * Syntax Arithmetic coding (SAC)
- * Reference Picture Selection
- * Independant Segment Decoding */
-/* /Fx */
-/* codec capabilities */
-
-#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
- */
-#define CODEC_CAP_DR1 0x0002
-/* if 'parse_only' field is true, then avcodec_parse_frame() can be
- used */
-#define CODEC_CAP_PARSE_ONLY 0x0004
-#define CODEC_CAP_TRUNCATED 0x0008
-/* codec can export data for HW decoding (XvMC) */
-#define CODEC_CAP_HWACCEL 0x0010
-/**
- * codec has a non zero delay and needs to be feeded with NULL at the end to get the delayed data.
- * if this is not set, the codec is guranteed to never be feeded with NULL data
- */
-#define CODEC_CAP_DELAY 0x0020
-/**
- * Codec can be fed a final frame with a smaller size.
- * This can be used to prevent truncation of the last audio samples.
- */
-#define CODEC_CAP_SMALL_LAST_FRAME 0x0040
-
-//the following defines may change, don't expect compatibility if you use them
-#define MB_TYPE_INTRA4x4 0x0001
-#define MB_TYPE_INTRA16x16 0x0002 //FIXME h264 specific
-#define MB_TYPE_INTRA_PCM 0x0004 //FIXME h264 specific
-#define MB_TYPE_16x16 0x0008
-#define MB_TYPE_16x8 0x0010
-#define MB_TYPE_8x16 0x0020
-#define MB_TYPE_8x8 0x0040
-#define MB_TYPE_INTERLACED 0x0080
-#define MB_TYPE_DIRECT2 0x0100 //FIXME
-#define MB_TYPE_ACPRED 0x0200
-#define MB_TYPE_GMC 0x0400
-#define MB_TYPE_SKIP 0x0800
-#define MB_TYPE_P0L0 0x1000
-#define MB_TYPE_P1L0 0x2000
-#define MB_TYPE_P0L1 0x4000
-#define MB_TYPE_P1L1 0x8000
-#define MB_TYPE_L0 (MB_TYPE_P0L0 | MB_TYPE_P1L0)
-#define MB_TYPE_L1 (MB_TYPE_P0L1 | MB_TYPE_P1L1)
-#define MB_TYPE_L0L1 (MB_TYPE_L0 | MB_TYPE_L1)
-#define MB_TYPE_QUANT 0x00010000
-#define MB_TYPE_CBP 0x00020000
-//Note bits 24-31 are reserved for codec specific use (h264 ref0, mpeg1 0mv, ...)
-
-/**
- * Pan Scan area.
- * this specifies the area which should be displayed. Note there may be multiple such areas for one frame
- */
-typedef struct AVPanScan{
- /**
- * id.
- * - encoding: set by user.
- * - decoding: set by lavc
- */
- int id;
-
- /**
- * width and height in 1/16 pel
- * - encoding: set by user.
- * - decoding: set by lavc
- */
- int width;
- int height;
-
- /**
- * position of the top left corner in 1/16 pel for up to 3 fields/frames.
- * - encoding: set by user.
- * - decoding: set by lavc
- */
- int16_t position[3][2];
-}AVPanScan;
-
-#define FF_COMMON_FRAME \
- /**\
- * pointer to the picture planes.\
- * this might be different from the first allocated byte\
- * - encoding: \
- * - decoding: \
- */\
- uint8_t *data[4];\
- int linesize[4];\
- /**\
- * pointer to the first allocated byte of the picture. can be used in get_buffer/release_buffer\
- * this isn't used by lavc unless the default get/release_buffer() is used\
- * - encoding: \
- * - decoding: \
- */\
- uint8_t *base[4];\
- /**\
- * 1 -> keyframe, 0-> not\
- * - encoding: set by lavc\
- * - decoding: set by lavc\
- */\
- int key_frame;\
-\
- /**\
- * picture type of the frame, see ?_TYPE below.\
- * - encoding: set by lavc for coded_picture (and set by user for input)\
- * - decoding: set by lavc\
- */\
- int pict_type;\
-\
- /**\
- * presentation timestamp in time_base units (time when frame should be shown to user)\
- * if AV_NOPTS_VALUE then frame_rate = 1/time_base will be assumed\
- * - encoding: MUST be set by user\
- * - decoding: set by lavc\
- */\
- int64_t pts;\
-\
- /**\
- * picture number in bitstream order.\
- * - encoding: set by\
- * - decoding: set by lavc\
- */\
- int coded_picture_number;\
- /**\
- * picture number in display order.\
- * - encoding: set by\
- * - decoding: set by lavc\
- */\
- int display_picture_number;\
-\
- /**\
- * quality (between 1 (good) and FF_LAMBDA_MAX (bad)) \
- * - encoding: set by lavc for coded_picture (and set by user for input)\
- * - decoding: set by lavc\
- */\
- int quality; \
-\
- /**\
- * buffer age (1->was last buffer and dint change, 2->..., ...).\
- * set to INT_MAX if the buffer has not been used yet \
- * - encoding: unused\
- * - decoding: MUST be set by get_buffer()\
- */\
- int age;\
-\
- /**\
- * is this picture used as reference\
- * - encoding: unused\
- * - decoding: set by lavc (before get_buffer() call))\
- */\
- int reference;\
-\
- /**\
- * QP table\
- * - encoding: unused\
- * - decoding: set by lavc\
- */\
- int8_t *qscale_table;\
- /**\
- * QP store stride\
- * - encoding: unused\
- * - decoding: set by lavc\
- */\
- int qstride;\
-\
- /**\
- * mbskip_table[mb]>=1 if MB didnt change\
- * stride= mb_width = (width+15)>>4\
- * - encoding: unused\
- * - decoding: set by lavc\
- */\
- uint8_t *mbskip_table;\
-\
- /**\
- * Motion vector table.\
- * @code\
- * example:\
- * int mv_sample_log2= 4 - motion_subsample_log2;\
- * int mb_width= (width+15)>>4;\
- * int mv_stride= (mb_width << mv_sample_log2) + 1;\
- * motion_val[direction][x + y*mv_stride][0->mv_x, 1->mv_y];\
- * @endcode\
- * - encoding: set by user\
- * - decoding: set by lavc\
- */\
- int16_t (*motion_val[2])[2];\
-\
- /**\
- * Macroblock type table\
- * mb_type_base + mb_width + 2\
- * - encoding: set by user\
- * - decoding: set by lavc\
- */\
- uint32_t *mb_type;\
-\
- /**\
- * log2 of the size of the block which a single vector in motion_val represents: \
- * (4->16x16, 3->8x8, 2-> 4x4, 1-> 2x2)\
- * - encoding: unused\
- * - decoding: set by lavc\
- */\
- uint8_t motion_subsample_log2;\
-\
- /**\
- * for some private data of the user\
- * - encoding: unused\
- * - decoding: set by user\
- */\
- void *opaque;\
-\
- /**\
- * error\
- * - encoding: set by lavc if flags&CODEC_FLAG_PSNR\
- * - decoding: unused\
- */\
- uint64_t error[4];\
-\
- /**\
- * type of the buffer (to keep track of who has to dealloc data[*])\
- * - encoding: set by the one who allocs it\
- * - decoding: set by the one who allocs it\
- * Note: user allocated (direct rendering) & internal buffers can not coexist currently\
- */\
- int type;\
- \
- /**\
- * when decoding, this signal how much the picture must be delayed.\
- * extra_delay = repeat_pict / (2*fps)\
- * - encoding: unused\
- * - decoding: set by lavc\
- */\
- int repeat_pict;\
- \
- /**\
- * \
- */\
- int qscale_type;\
- \
- /**\
- * The content of the picture is interlaced.\
- * - encoding: set by user\
- * - decoding: set by lavc (default 0)\
- */\
- int interlaced_frame;\
- \
- /**\
- * if the content is interlaced, is top field displayed first.\
- * - encoding: set by user\
- * - decoding: set by lavc\
- */\
- int top_field_first;\
- \
- /**\
- * Pan scan.\
- * - encoding: set by user\
- * - decoding: set by lavc\
- */\
- AVPanScan *pan_scan;\
- \
- /**\
- * tell user application that palette has changed from previous frame.\
- * - encoding: ??? (no palette-enabled encoder yet)\
- * - decoding: set by lavc (default 0)\
- */\
- int palette_has_changed;\
- \
- /**\
- * Codec suggestion on buffer type if != 0\
- * - encoding: unused\
- * - decoding: set by lavc (before get_buffer() call))\
- */\
- int buffer_hints;\
-\
- /**\
- * DCT coeffitients\
- * - encoding: unused\
- * - decoding: set by lavc\
- */\
- short *dct_coeff;\
-\
- /**\
- * Motion referece frame index\
- * - encoding: set by user\
- * - decoding: set by lavc\
- */\
- int8_t *ref_index[2];
-
-#define FF_QSCALE_TYPE_MPEG1 0
-#define FF_QSCALE_TYPE_MPEG2 1
-#define FF_QSCALE_TYPE_H264 2
-
-#define FF_BUFFER_TYPE_INTERNAL 1
-#define FF_BUFFER_TYPE_USER 2 ///< Direct rendering buffers (image is (de)allocated by user)
-#define FF_BUFFER_TYPE_SHARED 4 ///< buffer from somewhere else, don't dealloc image (data/base), all other tables are not shared
-#define FF_BUFFER_TYPE_COPY 8 ///< just a (modified) copy of some other buffer, don't dealloc anything
-
-
-#define FF_I_TYPE 1 // Intra
-#define FF_P_TYPE 2 // Predicted
-#define FF_B_TYPE 3 // Bi-dir predicted
-#define FF_S_TYPE 4 // S(GMC)-VOP MPEG4
-#define FF_SI_TYPE 5
-#define FF_SP_TYPE 6
-
-#define FF_BUFFER_HINTS_VALID 0x01 // Buffer hints value is meaningful (if 0 ignore)
-#define FF_BUFFER_HINTS_READABLE 0x02 // Codec will read from buffer
-#define FF_BUFFER_HINTS_PRESERVE 0x04 // User must not alter buffer content
-#define FF_BUFFER_HINTS_REUSABLE 0x08 // Codec will reuse the buffer (update)
-
-/**
- * Audio Video Frame.
- */
-typedef struct AVFrame {
- FF_COMMON_FRAME
-} AVFrame;
-
-#define DEFAULT_FRAME_RATE_BASE 1001000
-
-/**
- * main external api structure.
- */
-typedef struct AVCodecContext {
- /**
- * Info on struct for av_log
- * - set by avcodec_alloc_context
- */
- AVClass *av_class;
- /**
- * the average bitrate.
- * - encoding: set by user. unused for constant quantizer encoding
- * - decoding: set by lavc. 0 or some bitrate if this info is available in the stream
- */
- int bit_rate;
-
- /**
- * number of bits the bitstream is allowed to diverge from the reference.
- * the reference can be CBR (for CBR pass1) or VBR (for pass2)
- * - encoding: set by user. unused for constant quantizer encoding
- * - decoding: unused
- */
- int bit_rate_tolerance;
-
- /**
- * CODEC_FLAG_*.
- * - encoding: set by user.
- * - decoding: set by user.
- */
- int flags;
-
- /**
- * some codecs needs additionnal format info. It is stored here
- * - encoding: set by user.
- * - decoding: set by lavc. (FIXME is this ok?)
- */
- int sub_id;
-
- /**
- * motion estimation algorithm used for video coding.
- * 1 (zero), 2 (full), 3 (log), 4 (phods), 5 (epzs), 6 (x1), 7 (hex),
- * 8 (umh), 9 (iter) [7, 8 are x264 specific, 9 is snow specific]
- * - encoding: MUST be set by user.
- * - decoding: unused
- */
- int me_method;
-
- /**
- * some codecs need / can use extra-data like huffman tables.
- * mjpeg: huffman tables
- * rv10: additional flags
- * mpeg4: global headers (they can be in the bitstream or here)
- * the allocated memory should be FF_INPUT_BUFFER_PADDING_SIZE bytes larger
- * then extradata_size to avoid prolems if its read with the bitstream reader
- * the bytewise contents of extradata must not depend on the architecture or cpu endianness
- * - encoding: set/allocated/freed by lavc.
- * - decoding: set/allocated/freed by user.
- */
- uint8_t *extradata;
- int extradata_size;
-
- /**
- * this is the fundamental unit of time (in seconds) in terms
- * of which frame timestamps are represented. for fixed-fps content,
- * timebase should be 1/framerate and timestamp increments should be
- * identically 1.
- * - encoding: MUST be set by user
- * - decoding: set by lavc.
- */
- AVRational time_base;
-
- /* video only */
- /**
- * picture width / height.
- * - encoding: MUST be set by user.
- * - decoding: set by lavc.
- * Note, for compatibility its possible to set this instead of
- * coded_width/height before decoding
- */
- int width, height;
-
-#define FF_ASPECT_EXTENDED 15
-
- /**
- * the number of pictures in a group of pitures, or 0 for intra_only.
- * - encoding: set by user.
- * - decoding: unused
- */
- int gop_size;
-
- /**
- * pixel format, see PIX_FMT_xxx.
- * - encoding: set by user.
- * - decoding: set by lavc.
- */
- enum PixelFormat pix_fmt;
-
- /**
- * Frame rate emulation. If not zero lower layer (i.e. format handler)
- * has to read frames at native frame rate.
- * - encoding: set by user.
- * - decoding: unused.
- */
- int rate_emu;
-
- /**
- * if non NULL, 'draw_horiz_band' is called by the libavcodec
- * decoder to draw an horizontal band. It improve cache usage. Not
- * all codecs can do that. You must check the codec capabilities
- * before
- * - encoding: unused
- * - decoding: set by user.
- * @param height the height of the slice
- * @param y the y position of the slice
- * @param type 1->top field, 2->bottom field, 3->frame
- * @param offset offset into the AVFrame.data from which the slice should be read
- */
- void (*draw_horiz_band)(struct AVCodecContext *s,
- const AVFrame *src, int offset[4],
- int y, int type, int height);
-
- /* audio only */
- int sample_rate; ///< samples per sec
- int channels;
-
- /**
- * audio sample format.
- * - encoding: set by user.
- * - decoding: set by lavc.
- */
- enum SampleFormat sample_fmt; ///< sample format, currenly unused
-
- /* the following data should not be initialized */
- /**
- * samples per packet. initialized when calling 'init'
- */
- int frame_size;
- int frame_number; ///< audio or video frame number
- int real_pict_num; ///< returns the real picture number of previous encoded frame
-
- /**
- * number of frames the decoded output will be delayed relative to
- * the encoded input.
- * - encoding: set by lavc.
- * - decoding: unused
- */
- int delay;
-
- /* - encoding parameters */
- float qcompress; ///< amount of qscale change between easy & hard scenes (0.0-1.0)
- float qblur; ///< amount of qscale smoothing over time (0.0-1.0)
-
- /**
- * minimum quantizer.
- * - encoding: set by user.
- * - decoding: unused
- */
- int qmin;
-
- /**
- * maximum quantizer.
- * - encoding: set by user.
- * - decoding: unused
- */
- int qmax;
-
- /**
- * maximum quantizer difference between frames.
- * - encoding: set by user.
- * - decoding: unused
- */
- int max_qdiff;
-
- /**
- * maximum number of b frames between non b frames.
- * note: the output will be delayed by max_b_frames+1 relative to the input
- * - encoding: set by user.
- * - decoding: unused
- */
- int max_b_frames;
-
- /**
- * qscale factor between ip and b frames.
- * - encoding: set by user.
- * - decoding: unused
- */
- float b_quant_factor;
-
- /** obsolete FIXME remove */
- int rc_strategy;
-#define FF_RC_STRATEGY_XVID 1
-
- int b_frame_strategy;
-
- /**
- * hurry up amount.
- * deprecated in favor of skip_idct and skip_frame
- * - encoding: unused
- * - decoding: set by user. 1-> skip b frames, 2-> skip idct/dequant too, 5-> skip everything except header
- */
- int hurry_up;
-
- struct AVCodec *codec;
-
- void *priv_data;
-
- /* unused, FIXME remove*/
- int rtp_mode;
-
- int rtp_payload_size; /* The size of the RTP payload: the coder will */
- /* do it's best to deliver a chunk with size */
- /* below rtp_payload_size, the chunk will start */
- /* with a start code on some codecs like H.263 */
- /* This doesn't take account of any particular */
- /* headers inside the transmited RTP payload */
-
-
- /* The RTP callback: This function is called */
- /* every time the encoder has a packet to send */
- /* Depends on the encoder if the data starts */
- /* with a Start Code (it should) H.263 does. */
- /* mb_nb contains the number of macroblocks */
- /* encoded in the RTP payload */
- void (*rtp_callback)(struct AVCodecContext *avctx, void *data, int size, int mb_nb);
-
- /* statistics, used for 2-pass encoding */
- int mv_bits;
- int header_bits;
- int i_tex_bits;
- int p_tex_bits;
- int i_count;
- int p_count;
- int skip_count;
- int misc_bits;
-
- /**
- * number of bits used for the previously encoded frame.
- * - encoding: set by lavc
- * - decoding: unused
- */
- int frame_bits;
-
- /**
- * private data of the user, can be used to carry app specific stuff.
- * - encoding: set by user
- * - decoding: set by user
- */
- void *opaque;
-
- char codec_name[32];
- enum CodecType codec_type; /* see CODEC_TYPE_xxx */
- enum CodecID codec_id; /* see CODEC_ID_xxx */
-
- /**
- * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
- * this is used to workaround some encoder bugs
- * - encoding: set by user, if not then the default based on codec_id will be used
- * - decoding: set by user, will be converted to upper case by lavc during init
- */
- unsigned int codec_tag;
-
- /**
- * workaround bugs in encoders which sometimes cannot be detected automatically.
- * - encoding: set by user
- * - decoding: set by user
- */
- int workaround_bugs;
-#define FF_BUG_AUTODETECT 1 ///< autodetection
-#define FF_BUG_OLD_MSMPEG4 2
-#define FF_BUG_XVID_ILACE 4
-#define FF_BUG_UMP4 8
-#define FF_BUG_NO_PADDING 16
-#define FF_BUG_AMV 32
-#define FF_BUG_AC_VLC 0 ///< will be removed, libavcodec can now handle these non compliant files by default
-#define FF_BUG_QPEL_CHROMA 64
-#define FF_BUG_STD_QPEL 128
-#define FF_BUG_QPEL_CHROMA2 256
-#define FF_BUG_DIRECT_BLOCKSIZE 512
-#define FF_BUG_EDGE 1024
-#define FF_BUG_HPEL_CHROMA 2048
-#define FF_BUG_DC_CLIP 4096
-#define FF_BUG_MS 8192 ///< workaround various bugs in microsofts broken decoders
-//#define FF_BUG_FAKE_SCALABILITY 16 //autodetection should work 100%
-
- /**
- * luma single coeff elimination threshold.
- * - encoding: set by user
- * - decoding: unused
- */
- int luma_elim_threshold;
-
- /**
- * chroma single coeff elimination threshold.
- * - encoding: set by user
- * - decoding: unused
- */
- int chroma_elim_threshold;
-
- /**
- * strictly follow the std (MPEG4, ...).
- * - encoding: set by user
- * - decoding: unused
- */
- int strict_std_compliance;
-#define FF_COMPLIANCE_VERY_STRICT 2 ///< strictly conform to a older more strict version of the spec or reference software
-#define FF_COMPLIANCE_STRICT 1 ///< strictly conform to all the things in the spec no matter what consequences
-#define FF_COMPLIANCE_NORMAL 0
-#define FF_COMPLIANCE_INOFFICIAL -1 ///< allow inofficial extensions
-#define FF_COMPLIANCE_EXPERIMENTAL -2 ///< allow non standarized experimental things
-
- /**
- * qscale offset between ip and b frames.
- * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset)
- * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset)
- * - encoding: set by user.
- * - decoding: unused
- */
- float b_quant_offset;
-
- /**
- * error resilience higher values will detect more errors but may missdetect
- * some more or less valid parts as errors.
- * - encoding: unused
- * - decoding: set by user
- */
- int error_resilience;
-#define FF_ER_CAREFUL 1
-#define FF_ER_COMPLIANT 2
-#define FF_ER_AGGRESSIVE 3
-#define FF_ER_VERY_AGGRESSIVE 4
-
- /**
- * 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 lavc
- * avcodec_align_dimensions() should be used to find the required width and
- * height, as they normally need to be rounded up to the next multiple of 16
- * - encoding: unused
- * - decoding: set by lavc, user can override
- */
- int (*get_buffer)(struct AVCodecContext *c, AVFrame *pic);
-
- /**
- * called to release buffers which where allocated with get_buffer.
- * a released buffer can be reused in get_buffer()
- * pic.data[*] must be set to NULL
- * - encoding: unused
- * - decoding: set by lavc, user can override
- */
- void (*release_buffer)(struct AVCodecContext *c, AVFrame *pic);
-
- /**
- * if 1 the stream has a 1 frame delay during decoding.
- * - encoding: set by lavc
- * - decoding: set by lavc
- */
- int has_b_frames;
-
- /**
- * number of bytes per packet if constant and known or 0
- * used by some WAV based audio codecs
- */
- int block_align;
-
- int parse_only; /* - decoding only: if true, only parsing is done
- (function avcodec_parse_frame()). The frame
- data is returned. Only MPEG codecs support this now. */
-
- /**
- * 0-> h263 quant 1-> mpeg quant.
- * - encoding: set by user.
- * - decoding: unused
- */
- int mpeg_quant;
-
- /**
- * pass1 encoding statistics output buffer.
- * - encoding: set by lavc
- * - decoding: unused
- */
- char *stats_out;
-
- /**
- * pass2 encoding statistics input buffer.
- * concatenated stuff from stats_out of pass1 should be placed here
- * - encoding: allocated/set/freed by user
- * - decoding: unused
- */
- char *stats_in;
-
- /**
- * ratecontrol qmin qmax limiting method.
- * 0-> clipping, 1-> use a nice continous function to limit qscale wthin qmin/qmax
- * - encoding: set by user.
- * - decoding: unused
- */
- float rc_qsquish;
-
- float rc_qmod_amp;
- int rc_qmod_freq;
-
- /**
- * ratecontrol override, see RcOverride.
- * - encoding: allocated/set/freed by user.
- * - decoding: unused
- */
- RcOverride *rc_override;
- int rc_override_count;
-
- /**
- * rate control equation.
- * - encoding: set by user
- * - decoding: unused
- */
- char *rc_eq;
-
- /**
- * maximum bitrate.
- * - encoding: set by user.
- * - decoding: unused
- */
- int rc_max_rate;
-
- /**
- * minimum bitrate.
- * - encoding: set by user.
- * - decoding: unused
- */
- int rc_min_rate;
-
- /**
- * decoder bitstream buffer size.
- * - encoding: set by user.
- * - decoding: unused
- */
- int rc_buffer_size;
- float rc_buffer_aggressivity;
-
- /**
- * qscale factor between p and i frames.
- * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset)
- * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset)
- * - encoding: set by user.
- * - decoding: unused
- */
- float i_quant_factor;
-
- /**
- * qscale offset between p and i frames.
- * - encoding: set by user.
- * - decoding: unused
- */
- float i_quant_offset;
-
- /**
- * initial complexity for pass1 ratecontrol.
- * - encoding: set by user.
- * - decoding: unused
- */
- float rc_initial_cplx;
-
- /**
- * dct algorithm, see FF_DCT_* below.
- * - encoding: set by user
- * - decoding: unused
- */
- int dct_algo;
-#define FF_DCT_AUTO 0
-#define FF_DCT_FASTINT 1
-#define FF_DCT_INT 2
-#define FF_DCT_MMX 3
-#define FF_DCT_MLIB 4
-#define FF_DCT_ALTIVEC 5
-#define FF_DCT_FAAN 6
-
- /**
- * luminance masking (0-> disabled).
- * - encoding: set by user
- * - decoding: unused
- */
- float lumi_masking;
-
- /**
- * temporary complexity masking (0-> disabled).
- * - encoding: set by user
- * - decoding: unused
- */
- float temporal_cplx_masking;
-
- /**
- * spatial complexity masking (0-> disabled).
- * - encoding: set by user
- * - decoding: unused
- */
- float spatial_cplx_masking;
-
- /**
- * p block masking (0-> disabled).
- * - encoding: set by user
- * - decoding: unused
- */
- float p_masking;
-
- /**
- * darkness masking (0-> disabled).
- * - encoding: set by user
- * - decoding: unused
- */
- float dark_masking;
-
-
- /* for binary compatibility */
- int unused;
-
- /**
- * idct algorithm, see FF_IDCT_* below.
- * - encoding: set by user
- * - decoding: set by user
- */
- int idct_algo;
-#define FF_IDCT_AUTO 0
-#define FF_IDCT_INT 1
-#define FF_IDCT_SIMPLE 2
-#define FF_IDCT_SIMPLEMMX 3
-#define FF_IDCT_LIBMPEG2MMX 4
-#define FF_IDCT_PS2 5
-#define FF_IDCT_MLIB 6
-#define FF_IDCT_ARM 7
-#define FF_IDCT_ALTIVEC 8
-#define FF_IDCT_SH4 9
-#define FF_IDCT_SIMPLEARM 10
-#define FF_IDCT_H264 11
-#define FF_IDCT_VP3 12
-#define FF_IDCT_IPP 13
-#define FF_IDCT_XVIDMMX 14
-#define FF_IDCT_CAVS 15
-#define FF_IDCT_SIMPLEARMV5TE 16
-
- /**
- * slice count.
- * - encoding: set by lavc
- * - decoding: set by user (or 0)
- */
- int slice_count;
- /**
- * slice offsets in the frame in bytes.
- * - encoding: set/allocated by lavc
- * - decoding: set/allocated by user (or NULL)
- */
- int *slice_offset;
-
- /**
- * error concealment flags.
- * - encoding: unused
- * - decoding: set by user
- */
- int error_concealment;
-#define FF_EC_GUESS_MVS 1
-#define FF_EC_DEBLOCK 2
-
- /**
- * dsp_mask could be add used to disable unwanted CPU features
- * CPU features (i.e. MMX, SSE. ...)
- *
- * with FORCE flag you may instead enable given CPU features
- * (Dangerous: usable in case of misdetection, improper usage however will
- * result into program crash)
- */
- unsigned dsp_mask;
-#define FF_MM_FORCE 0x80000000 /* force usage of selected flags (OR) */
- /* lower 16 bits - CPU features */
-#ifdef HAVE_MMX
-#define FF_MM_MMX 0x0001 /* standard MMX */
-#define FF_MM_3DNOW 0x0004 /* AMD 3DNOW */
-#define FF_MM_MMXEXT 0x0002 /* SSE integer functions or AMD MMX ext */
-#define FF_MM_SSE 0x0008 /* SSE functions */
-#define FF_MM_SSE2 0x0010 /* PIV SSE2 functions */
-#define FF_MM_3DNOWEXT 0x0020 /* AMD 3DNowExt */
-#endif /* HAVE_MMX */
-#ifdef HAVE_IWMMXT
-#define FF_MM_IWMMXT 0x0100 /* XScale IWMMXT */
-#endif /* HAVE_IWMMXT */
-
- /**
- * bits per sample/pixel from the demuxer (needed for huffyuv).
- * - encoding: set by lavc
- * - decoding: set by user
- */
- int bits_per_sample;
-
- /**
- * prediction method (needed for huffyuv).
- * - encoding: set by user
- * - decoding: unused
- */
- int prediction_method;
-#define FF_PRED_LEFT 0
-#define FF_PRED_PLANE 1
-#define FF_PRED_MEDIAN 2
-
- /**
- * sample aspect ratio (0 if unknown).
- * numerator and denominator must be relative prime and smaller then 256 for some video standards
- * - encoding: set by user.
- * - decoding: set by lavc.
- */
- AVRational sample_aspect_ratio;
-
- /**
- * the picture in the bitstream.
- * - encoding: set by lavc
- * - decoding: set by lavc
- */
- AVFrame *coded_frame;
-
- /**
- * debug.
- * - encoding: set by user.
- * - decoding: set by user.
- */
- int debug;
-#define FF_DEBUG_PICT_INFO 1
-#define FF_DEBUG_RC 2
-#define FF_DEBUG_BITSTREAM 4
-#define FF_DEBUG_MB_TYPE 8
-#define FF_DEBUG_QP 16
-#define FF_DEBUG_MV 32
-#define FF_DEBUG_DCT_COEFF 0x00000040
-#define FF_DEBUG_SKIP 0x00000080
-#define FF_DEBUG_STARTCODE 0x00000100
-#define FF_DEBUG_PTS 0x00000200
-#define FF_DEBUG_ER 0x00000400
-#define FF_DEBUG_MMCO 0x00000800
-#define FF_DEBUG_BUGS 0x00001000
-#define FF_DEBUG_VIS_QP 0x00002000
-#define FF_DEBUG_VIS_MB_TYPE 0x00004000
-
- /**
- * debug.
- * - encoding: set by user.
- * - decoding: set by user.
- */
- int debug_mv;
-#define FF_DEBUG_VIS_MV_P_FOR 0x00000001 //visualize forward predicted MVs of P frames
-#define FF_DEBUG_VIS_MV_B_FOR 0x00000002 //visualize forward predicted MVs of B frames
-#define FF_DEBUG_VIS_MV_B_BACK 0x00000004 //visualize backward predicted MVs of B frames
-
- /**
- * error.
- * - encoding: set by lavc if flags&CODEC_FLAG_PSNR
- * - decoding: unused
- */
- uint64_t error[4];
-
- /**
- * minimum MB quantizer.
- * - encoding: unused
- * - decoding: unused
- */
- int mb_qmin;
-
- /**
- * maximum MB quantizer.
- * - encoding: unused
- * - decoding: unused
- */
- int mb_qmax;
-
- /**
- * motion estimation compare function.
- * - encoding: set by user.
- * - decoding: unused
- */
- int me_cmp;
- /**
- * subpixel motion estimation compare function.
- * - encoding: set by user.
- * - decoding: unused
- */
- int me_sub_cmp;
- /**
- * macroblock compare function (not supported yet).
- * - encoding: set by user.
- * - decoding: unused
- */
- int mb_cmp;
- /**
- * interlaced dct compare function
- * - encoding: set by user.
- * - decoding: unused
- */
- int ildct_cmp;
-#define FF_CMP_SAD 0
-#define FF_CMP_SSE 1
-#define FF_CMP_SATD 2
-#define FF_CMP_DCT 3
-#define FF_CMP_PSNR 4
-#define FF_CMP_BIT 5
-#define FF_CMP_RD 6
-#define FF_CMP_ZERO 7
-#define FF_CMP_VSAD 8
-#define FF_CMP_VSSE 9
-#define FF_CMP_NSSE 10
-#define FF_CMP_W53 11
-#define FF_CMP_W97 12
-#define FF_CMP_DCTMAX 13
-#define FF_CMP_DCT264 14
-#define FF_CMP_CHROMA 256
-
- /**
- * ME diamond size & shape.
- * - encoding: set by user.
- * - decoding: unused
- */
- int dia_size;
-
- /**
- * amount of previous MV predictors (2a+1 x 2a+1 square).
- * - encoding: set by user.
- * - decoding: unused
- */
- int last_predictor_count;
-
- /**
- * pre pass for motion estimation.
- * - encoding: set by user.
- * - decoding: unused
- */
- int pre_me;
-
- /**
- * motion estimation pre pass compare function.
- * - encoding: set by user.
- * - decoding: unused
- */
- int me_pre_cmp;
-
- /**
- * ME pre pass diamond size & shape.
- * - encoding: set by user.
- * - decoding: unused
- */
- int pre_dia_size;
-
- /**
- * subpel ME quality.
- * - encoding: set by user.
- * - decoding: unused
- */
- int me_subpel_quality;
-
- /**
- * callback to negotiate the pixelFormat.
- * @param fmt is the list of formats which are supported by the codec,
- * its terminated by -1 as 0 is a valid format, the formats are ordered by quality
- * the first is allways the native one
- * @return the choosen format
- * - encoding: unused
- * - decoding: set by user, if not set then the native format will always be choosen
- */
- enum PixelFormat (*get_format)(struct AVCodecContext *s, const enum PixelFormat * fmt);
-
- /**
- * DTG active format information (additionnal aspect ratio
- * information only used in DVB MPEG2 transport streams). 0 if
- * not set.
- *
- * - encoding: unused.
- * - decoding: set by decoder
- */
- int dtg_active_format;
-#define FF_DTG_AFD_SAME 8
-#define FF_DTG_AFD_4_3 9
-#define FF_DTG_AFD_16_9 10
-#define FF_DTG_AFD_14_9 11
-#define FF_DTG_AFD_4_3_SP_14_9 13
-#define FF_DTG_AFD_16_9_SP_14_9 14
-#define FF_DTG_AFD_SP_4_3 15
-
- /**
- * Maximum motion estimation search range in subpel units.
- * if 0 then no limit
- *
- * - encoding: set by user.
- * - decoding: unused.
- */
- int me_range;
-
- /**
- * intra quantizer bias.
- * - encoding: set by user.
- * - decoding: unused
- */
- int intra_quant_bias;
-#define FF_DEFAULT_QUANT_BIAS 999999
-
- /**
- * inter quantizer bias.
- * - encoding: set by user.
- * - decoding: unused
- */
- int inter_quant_bias;
-
- /**
- * color table ID.
- * - encoding: unused.
- * - decoding: which clrtable should be used for 8bit RGB images
- * table have to be stored somewhere FIXME
- */
- int color_table_id;
-
- /**
- * internal_buffer count.
- * Don't touch, used by lavc default_get_buffer()
- */
- int internal_buffer_count;
-
- /**
- * internal_buffers.
- * Don't touch, used by lavc default_get_buffer()
- */
- void *internal_buffer;
-
-#define FF_LAMBDA_SHIFT 7
-#define FF_LAMBDA_SCALE (1<<FF_LAMBDA_SHIFT)
-#define FF_QP2LAMBDA 118 ///< factor to convert from H.263 QP to lambda
-#define FF_LAMBDA_MAX (256*128-1)
-
-#define FF_QUALITY_SCALE FF_LAMBDA_SCALE //FIXME maybe remove
- /**
- * global quality for codecs which cannot change it per frame.
- * this should be proportional to MPEG1/2/4 qscale.
- * - encoding: set by user.
- * - decoding: unused
- */
- int global_quality;
-
-#define FF_CODER_TYPE_VLC 0
-#define FF_CODER_TYPE_AC 1
- /**
- * coder type
- * - encoding: set by user.
- * - decoding: unused
- */
- int coder_type;
-
- /**
- * context model
- * - encoding: set by user.
- * - decoding: unused
- */
- int context_model;
-#if 0
- /**
- *
- * - encoding: unused
- * - decoding: set by user.
- */
- uint8_t * (*realloc)(struct AVCodecContext *s, uint8_t *buf, int buf_size);
-#endif
-
- /**
- * slice flags
- * - encoding: unused
- * - decoding: set by user.
- */
- int slice_flags;
-#define SLICE_FLAG_CODED_ORDER 0x0001 ///< draw_horiz_band() is called in coded order instead of display
-#define SLICE_FLAG_ALLOW_FIELD 0x0002 ///< allow draw_horiz_band() with field slices (MPEG2 field pics)
-#define SLICE_FLAG_ALLOW_PLANE 0x0004 ///< allow draw_horiz_band() with 1 component at a time (SVQ1)
-
- /**
- * XVideo Motion Acceleration
- * - encoding: forbidden
- * - decoding: set by decoder
- */
- int xvmc_acceleration;
-
- /**
- * macroblock decision mode
- * - encoding: set by user.
- * - decoding: unused
- */
- int mb_decision;
-#define FF_MB_DECISION_SIMPLE 0 ///< uses mb_cmp
-#define FF_MB_DECISION_BITS 1 ///< chooses the one which needs the fewest bits
-#define FF_MB_DECISION_RD 2 ///< rate distoration
-
- /**
- * custom intra quantization matrix
- * - encoding: set by user, can be NULL
- * - decoding: set by lavc
- */
- uint16_t *intra_matrix;
-
- /**
- * custom inter quantization matrix
- * - encoding: set by user, can be NULL
- * - decoding: set by lavc
- */
- uint16_t *inter_matrix;
-
- /**
- * fourcc from the AVI stream header (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
- * this is used to workaround some encoder bugs
- * - encoding: unused
- * - decoding: set by user, will be converted to upper case by lavc during init
- */
- unsigned int stream_codec_tag;
-
- /**
- * scene change detection threshold.
- * 0 is default, larger means fewer detected scene changes
- * - encoding: set by user.
- * - decoding: unused
- */
- int scenechange_threshold;
-
- /**
- * minimum lagrange multipler
- * - encoding: set by user.
- * - decoding: unused
- */
- int lmin;
-
- /**
- * maximum lagrange multipler
- * - encoding: set by user.
- * - decoding: unused
- */
- int lmax;
-
- /**
- * Palette control structure
- * - encoding: ??? (no palette-enabled encoder yet)
- * - decoding: set by user.
- */
- struct AVPaletteControl *palctrl;
-
- /**
- * noise reduction strength
- * - encoding: set by user.
- * - decoding: unused
- */
- int noise_reduction;
-
- /**
- * called at the beginning of a frame to get cr buffer for it.
- * buffer type (size, hints) must be the same. lavc won't check it.
- * lavc will pass previous buffer in pic, function should return
- * same buffer or new buffer with old frame "painted" into it.
- * if pic.data[0] == NULL must behave like get_buffer().
- * - encoding: unused
- * - decoding: set by lavc, user can override
- */
- int (*reget_buffer)(struct AVCodecContext *c, AVFrame *pic);
-
- /**
- * number of bits which should be loaded into the rc buffer before decoding starts
- * - encoding: set by user.
- * - decoding: unused
- */
- int rc_initial_buffer_occupancy;
-
- /**
- *
- * - encoding: set by user.
- * - decoding: unused
- */
- int inter_threshold;
-
- /**
- * CODEC_FLAG2_*.
- * - encoding: set by user.
- * - decoding: set by user.
- */
- int flags2;
-
- /**
- * simulates errors in the bitstream to test error concealment.
- * - encoding: set by user.
- * - decoding: unused.
- */
- int error_rate;
-
- /**
- * MP3 antialias algorithm, see FF_AA_* below.
- * - encoding: unused
- * - decoding: set by user
- */
- int antialias_algo;
-#define FF_AA_AUTO 0
-#define FF_AA_FASTINT 1 //not implemented yet
-#define FF_AA_INT 2
-#define FF_AA_FLOAT 3
- /**
- * Quantizer noise shaping.
- * - encoding: set by user
- * - decoding: unused
- */
- int quantizer_noise_shaping;
-
- /**
- * Thread count.
- * is used to decide how many independant tasks should be passed to execute()
- * - encoding: set by user
- * - decoding: set by user
- */
- int thread_count;
-
- /**
- * the codec may call this to execute several independant 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
- * @param count the number of things to execute
- * - encoding: set by lavc, user can override
- * - decoding: set by lavc, user can override
- */
- int (*execute)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg), void **arg2, int *ret, int count);
-
- /**
- * Thread opaque.
- * can be used by execute() to store some per AVCodecContext stuff.
- * - encoding: set by execute()
- * - decoding: set by execute()
- */
- void *thread_opaque;
-
- /**
- * Motion estimation threshold. under which no motion estimation is
- * performed, but instead the user specified motion vectors are used
- *
- * - encoding: set by user
- * - decoding: unused
- */
- int me_threshold;
-
- /**
- * Macroblock threshold. under which the user specified macroblock types will be used
- * - encoding: set by user
- * - decoding: unused
- */
- int mb_threshold;
-
- /**
- * precision of the intra dc coefficient - 8.
- * - encoding: set by user
- * - decoding: unused
- */
- int intra_dc_precision;
-
- /**
- * noise vs. sse weight for the nsse comparsion function.
- * - encoding: set by user
- * - decoding: unused
- */
- int nsse_weight;
-
- /**
- * number of macroblock rows at the top which are skipped.
- * - encoding: unused
- * - decoding: set by user
- */
- int skip_top;
-
- /**
- * number of macroblock rows at the bottom which are skipped.
- * - encoding: unused
- * - decoding: set by user
- */
- int skip_bottom;
-
- /**
- * profile
- * - encoding: set by user
- * - decoding: set by lavc
- */
- int profile;
-#define FF_PROFILE_UNKNOWN -99
-
- /**
- * level
- * - encoding: set by user
- * - decoding: set by lavc
- */
- int level;
-#define FF_LEVEL_UNKNOWN -99
-
- /**
- * low resolution decoding. 1-> 1/2 size, 2->1/4 size
- * - encoding: unused
- * - decoding: set by user
- */
- int lowres;
-
- /**
- * bitsream width / height. may be different from width/height if lowres
- * or other things are used
- * - encoding: unused
- * - decoding: set by user before init if known, codec should override / dynamically change if needed
- */
- int coded_width, coded_height;
-
- /**
- * frame skip threshold
- * - encoding: set by user
- * - decoding: unused
- */
- int frame_skip_threshold;
-
- /**
- * frame skip factor
- * - encoding: set by user
- * - decoding: unused
- */
- int frame_skip_factor;
-
- /**
- * frame skip exponent
- * - encoding: set by user
- * - decoding: unused
- */
- int frame_skip_exp;
-
- /**
- * frame skip comparission function
- * - encoding: set by user.
- * - decoding: unused
- */
- int frame_skip_cmp;
-
- /**
- * border processing masking. raises the quantizer for mbs on the borders
- * of the picture.
- * - encoding: set by user
- * - decoding: unused
- */
- float border_masking;
-
- /**
- * minimum MB lagrange multipler.
- * - encoding: set by user.
- * - decoding: unused
- */
- int mb_lmin;
-
- /**
- * maximum MB lagrange multipler.
- * - encoding: set by user.
- * - decoding: unused
- */
- int mb_lmax;
-
- /**
- *
- * - encoding: set by user.
- * - decoding: unused
- */
- int me_penalty_compensation;
-
- /**
- *
- * - encoding: unused
- * - decoding: set by user.
- */
- enum AVDiscard skip_loop_filter;
-
- /**
- *
- * - encoding: unused
- * - decoding: set by user.
- */
- enum AVDiscard skip_idct;
-
- /**
- *
- * - encoding: unused
- * - decoding: set by user.
- */
- enum AVDiscard skip_frame;
-
- /**
- *
- * - encoding: set by user.
- * - decoding: unused
- */
- int bidir_refine;
-
- /**
- *
- * - encoding: set by user.
- * - decoding: unused
- */
- int brd_scale;
-
- /**
- * constant rate factor - quality-based VBR - values ~correspond to qps
- * - encoding: set by user.
- * - decoding: unused
- */
- float crf;
-
- /**
- * constant quantization parameter rate control method
- * - encoding: set by user.
- * - decoding: unused
- */
- int cqp;
-
- /**
- * minimum gop size
- * - encoding: set by user.
- * - decoding: unused
- */
- int keyint_min;
-
- /**
- * number of reference frames
- * - encoding: set by user.
- * - decoding: unused
- */
- int refs;
-
- /**
- * chroma qp offset from luma
- * - encoding: set by user.
- * - decoding: unused
- */
- int chromaoffset;
-
- /**
- * influences how often b-frames are used
- * - encoding: set by user.
- * - decoding: unused
- */
- int bframebias;
-
- /**
- * trellis RD quantization
- * - encoding: set by user.
- * - decoding: unused
- */
- int trellis;
-
- /**
- * reduce fluctuations in qp (before curve compression)
- * - encoding: set by user.
- * - decoding: unused
- */
- float complexityblur;
-
- /**
- * in-loop deblocking filter alphac0 parameter
- * alpha is in the range -6...6
- * - encoding: set by user.
- * - decoding: unused
- */
- int deblockalpha;
-
- /**
- * in-loop deblocking filter beta parameter
- * beta is in the range -6...6
- * - encoding: set by user.
- * - decoding: unused
- */
- int deblockbeta;
-
- /**
- * macroblock subpartition sizes to consider - p8x8, p4x4, b8x8, i8x8, i4x4
- * - encoding: set by user.
- * - decoding: unused
- */
- int partitions;
-#define X264_PART_I4X4 0x001 /* Analyse i4x4 */
-#define X264_PART_I8X8 0x002 /* Analyse i8x8 (requires 8x8 transform) */
-#define X264_PART_P8X8 0x010 /* Analyse p16x8, p8x16 and p8x8 */
-#define X264_PART_P4X4 0x020 /* Analyse p8x4, p4x8, p4x4 */
-#define X264_PART_B8X8 0x100 /* Analyse b16x8, b8x16 and b8x8 */
-
- /**
- * direct mv prediction mode - 0 (none), 1 (spatial), 2 (temporal)
- * - encoding: set by user.
- * - decoding: unused
- */
- int directpred;
-
- /**
- * audio cutoff bandwidth (0 means "automatic") . Currently used only by FAAC
- * - encoding: set by user.
- * - decoding: unused
- */
- int cutoff;
-
- /**
- * multiplied by qscale for each frame and added to scene_change_score
- * - encoding: set by user.
- * - decoding: unused
- */
- int scenechange_factor;
-
- /**
- *
- * note: value depends upon the compare functin used for fullpel ME
- * - encoding: set by user.
- * - decoding: unused
- */
- int mv0_threshold;
-
- /**
- * adjusts sensitivity of b_frame_strategy 1
- * - encoding: set by user.
- * - decoding: unused
- */
- int b_sensitivity;
-
- /**
- * - encoding: set by user.
- * - decoding: unused
- */
- int compression_level;
-#define FF_COMPRESSION_DEFAULT -1
-
- /**
- * sets whether to use LPC mode - used by FLAC encoder
- * - encoding: set by user.
- * - decoding: unused.
- */
- int use_lpc;
-
- /**
- * LPC coefficient precision - used by FLAC encoder
- * - encoding: set by user.
- * - decoding: unused.
- */
- int lpc_coeff_precision;
-
- /**
- * - encoding: set by user.
- * - decoding: unused.
- */
- int min_prediction_order;
-
- /**
- * - encoding: set by user.
- * - decoding: unused.
- */
- int max_prediction_order;
-
- /**
- * search method for selecting prediction order
- * - encoding: set by user.
- * - decoding: unused.
- */
- int prediction_order_method;
-
- /**
- * - encoding: set by user.
- * - decoding: unused.
- */
- int min_partition_order;
-
- /**
- * - encoding: set by user.
- * - decoding: unused.
- */
- int max_partition_order;
-
- /**
- * GOP timecode frame start number, in non drop frame format
- * - encoding: set by user.
- * - decoding: unused.
- */
- int64_t timecode_frame_start;
-} AVCodecContext;
-
-/**
- * AVCodec.
- */
-typedef struct AVCodec {
- const char *name;
- enum CodecType type;
- enum CodecID id;
- int priv_data_size;
- int (*init)(AVCodecContext *);
- int (*encode)(AVCodecContext *, uint8_t *buf, int buf_size, void *data);
- int (*close)(AVCodecContext *);
- int (*decode)(AVCodecContext *, void *outdata, int *outdata_size,
- uint8_t *buf, int buf_size);
- int capabilities;
- struct AVCodec *next;
- void (*flush)(AVCodecContext *);
- const AVRational *supported_framerates; ///array of supported framerates, or NULL if any, array is terminated by {0,0}
- const enum PixelFormat *pix_fmts; ///array of supported pixel formats, or NULL if unknown, array is terminanted by -1
-} AVCodec;
-
-/**
- * four components are given, that's all.
- * the last component is alpha
- */
-typedef struct AVPicture {
- uint8_t *data[4];
- int linesize[4]; ///< number of bytes per line
-} AVPicture;
-
-/**
- * AVPaletteControl
- * This structure defines a method for communicating palette changes
- * between and demuxer and a decoder.
- * this is totally broken, palette changes should be sent as AVPackets
- */
-#define AVPALETTE_SIZE 1024
-#define AVPALETTE_COUNT 256
-typedef struct AVPaletteControl {
-
- /* demuxer sets this to 1 to indicate the palette has changed;
- * decoder resets to 0 */
- int palette_changed;
-
- /* 4-byte ARGB palette entries, stored in native byte order; note that
- * the individual palette components should be on a 8-bit scale; if
- * the palette data comes from a IBM VGA native format, the component
- * data is probably 6 bits in size and needs to be scaled */
- unsigned int palette[AVPALETTE_COUNT];
-
-} AVPaletteControl attribute_deprecated;
-
-typedef struct AVSubtitleRect {
- uint16_t x;
- uint16_t y;
- uint16_t w;
- uint16_t h;
- uint16_t nb_colors;
- int linesize;
- uint32_t *rgba_palette;
- uint8_t *bitmap;
-} AVSubtitleRect;
-
-typedef struct AVSubtitle {
- uint16_t format; /* 0 = graphics */
- uint32_t start_display_time; /* relative to packet pts, in ms */
- uint32_t end_display_time; /* relative to packet pts, in ms */
- uint32_t num_rects;
- AVSubtitleRect *rects;
-} AVSubtitle;
-
-extern AVCodec ac3_encoder;
-extern AVCodec amr_nb_encoder;
-extern AVCodec amr_wb_encoder;
-extern AVCodec asv1_encoder;
-extern AVCodec asv2_encoder;
-extern AVCodec dvvideo_encoder;
-extern AVCodec faac_encoder;
-extern AVCodec ffv1_encoder;
-extern AVCodec ffvhuff_encoder;
-extern AVCodec flac_encoder;
-extern AVCodec flashsv_encoder;
-extern AVCodec flv_encoder;
-extern AVCodec gif_encoder;
-extern AVCodec h261_encoder;
-extern AVCodec h263_encoder;
-extern AVCodec h263p_encoder;
-extern AVCodec h264_encoder;
-extern AVCodec huffyuv_encoder;
-extern AVCodec jpegls_encoder;
-extern AVCodec libgsm_encoder;
-extern AVCodec libtheora_encoder;
-extern AVCodec ljpeg_encoder;
-extern AVCodec mdec_encoder;
-extern AVCodec mjpeg_encoder;
-extern AVCodec mp2_encoder;
-extern AVCodec mp3lame_encoder;
-extern AVCodec mpeg1video_encoder;
-extern AVCodec mpeg2video_encoder;
-extern AVCodec mpeg4_encoder;
-extern AVCodec msmpeg4v1_encoder;
-extern AVCodec msmpeg4v2_encoder;
-extern AVCodec msmpeg4v3_encoder;
-extern AVCodec oggvorbis_encoder;
-extern AVCodec pam_encoder;
-extern AVCodec pbm_encoder;
-extern AVCodec pgm_encoder;
-extern AVCodec pgmyuv_encoder;
-extern AVCodec png_encoder;
-extern AVCodec ppm_encoder;
-extern AVCodec rv10_encoder;
-extern AVCodec rv20_encoder;
-extern AVCodec snow_encoder;
-extern AVCodec sonic_encoder;
-extern AVCodec sonic_ls_encoder;
-extern AVCodec svq1_encoder;
-extern AVCodec vcr1_encoder;
-extern AVCodec vorbis_encoder;
-extern AVCodec wmv1_encoder;
-extern AVCodec wmv2_encoder;
-extern AVCodec x264_encoder;
-extern AVCodec xvid_encoder;
-extern AVCodec zlib_encoder;
-extern AVCodec zmbv_encoder;
-
-extern AVCodec aac_decoder;
-extern AVCodec aasc_decoder;
-extern AVCodec alac_decoder;
-extern AVCodec amr_nb_decoder;
-extern AVCodec amr_wb_decoder;
-extern AVCodec asv1_decoder;
-extern AVCodec asv2_decoder;
-extern AVCodec avs_decoder;
-extern AVCodec bmp_decoder;
-extern AVCodec cavs_decoder;
-extern AVCodec cinepak_decoder;
-extern AVCodec cljr_decoder;
-extern AVCodec cook_decoder;
-extern AVCodec cscd_decoder;
-extern AVCodec cyuv_decoder;
-extern AVCodec dsicinaudio_decoder;
-extern AVCodec dsicinvideo_decoder;
-extern AVCodec dvvideo_decoder;
-extern AVCodec eightbps_decoder;
-extern AVCodec ffv1_decoder;
-extern AVCodec ffvhuff_decoder;
-extern AVCodec flac_decoder;
-extern AVCodec flashsv_decoder;
-extern AVCodec flic_decoder;
-extern AVCodec flv_decoder;
-extern AVCodec fourxm_decoder;
-extern AVCodec fraps_decoder;
-extern AVCodec gif_decoder;
-extern AVCodec h261_decoder;
-extern AVCodec h263_decoder;
-extern AVCodec h263i_decoder;
-extern AVCodec h264_decoder;
-extern AVCodec huffyuv_decoder;
-extern AVCodec idcin_decoder;
-extern AVCodec imc_decoder;
-extern AVCodec indeo2_decoder;
-extern AVCodec indeo3_decoder;
-extern AVCodec interplay_dpcm_decoder;
-extern AVCodec interplay_video_decoder;
-extern AVCodec kmvc_decoder;
-extern AVCodec libgsm_decoder;
-extern AVCodec loco_decoder;
-extern AVCodec mace3_decoder;
-extern AVCodec mace6_decoder;
-extern AVCodec mdec_decoder;
-extern AVCodec mjpeg_decoder;
-extern AVCodec mjpegb_decoder;
-extern AVCodec mmvideo_decoder;
-extern AVCodec mp2_decoder;
-extern AVCodec mp3_decoder;
-extern AVCodec mp3adu_decoder;
-extern AVCodec mp3on4_decoder;
-extern AVCodec mpc7_decoder;
-extern AVCodec mpeg1video_decoder;
-extern AVCodec mpeg2video_decoder;
-extern AVCodec mpeg4_decoder;
-extern AVCodec mpeg4aac_decoder;
-extern AVCodec mpeg_xvmc_decoder;
-extern AVCodec mpegvideo_decoder;
-extern AVCodec msmpeg4v1_decoder;
-extern AVCodec msmpeg4v2_decoder;
-extern AVCodec msmpeg4v3_decoder;
-extern AVCodec msrle_decoder;
-extern AVCodec msvideo1_decoder;
-extern AVCodec mszh_decoder;
-extern AVCodec nuv_decoder;
-extern AVCodec oggvorbis_decoder;
-extern AVCodec png_decoder;
-extern AVCodec qdm2_decoder;
-extern AVCodec qdraw_decoder;
-extern AVCodec qpeg_decoder;
-extern AVCodec qtrle_decoder;
-extern AVCodec ra_144_decoder;
-extern AVCodec ra_288_decoder;
-extern AVCodec roq_decoder;
-extern AVCodec roq_dpcm_decoder;
-extern AVCodec rpza_decoder;
-extern AVCodec rv10_decoder;
-extern AVCodec rv20_decoder;
-extern AVCodec rv30_decoder;
-extern AVCodec rv40_decoder;
-extern AVCodec shorten_decoder;
-extern AVCodec smackaud_decoder;
-extern AVCodec smacker_decoder;
-extern AVCodec smc_decoder;
-extern AVCodec snow_decoder;
-extern AVCodec sol_dpcm_decoder;
-extern AVCodec sonic_decoder;
-extern AVCodec sp5x_decoder;
-extern AVCodec svq1_decoder;
-extern AVCodec svq3_decoder;
-extern AVCodec targa_decoder;
-extern AVCodec theora_decoder;
-extern AVCodec tiertexseqvideo_decoder;
-extern AVCodec tiff_decoder;
-extern AVCodec truemotion1_decoder;
-extern AVCodec truemotion2_decoder;
-extern AVCodec truespeech_decoder;
-extern AVCodec tscc_decoder;
-extern AVCodec tta_decoder;
-extern AVCodec ulti_decoder;
-extern AVCodec vc1_decoder;
-extern AVCodec vcr1_decoder;
-extern AVCodec vmdaudio_decoder;
-extern AVCodec vmdvideo_decoder;
-extern AVCodec vmnc_decoder;
-extern AVCodec vorbis_decoder;
-extern AVCodec vp3_decoder;
-extern AVCodec vp5_decoder;
-extern AVCodec vp6_decoder;
-extern AVCodec vp6f_decoder;
-extern AVCodec vqa_decoder;
-extern AVCodec wavpack_decoder;
-extern AVCodec wmav1_decoder;
-extern AVCodec wmav2_decoder;
-extern AVCodec wmv1_decoder;
-extern AVCodec wmv2_decoder;
-extern AVCodec wmv3_decoder;
-extern AVCodec wnv1_decoder;
-extern AVCodec ws_snd1_decoder;
-extern AVCodec xan_dpcm_decoder;
-extern AVCodec xan_wc3_decoder;
-extern AVCodec xl_decoder;
-extern AVCodec zlib_decoder;
-extern AVCodec zmbv_decoder;
-
-/* pcm codecs */
-#define PCM_CODEC(id, name) \
-extern AVCodec name ## _decoder; \
-extern AVCodec name ## _encoder
-
-PCM_CODEC(CODEC_ID_PCM_ALAW, pcm_alaw);
-PCM_CODEC(CODEC_ID_PCM_MULAW, pcm_mulaw);
-PCM_CODEC(CODEC_ID_PCM_S8, pcm_s8);
-PCM_CODEC(CODEC_ID_PCM_S16BE, pcm_s16be);
-PCM_CODEC(CODEC_ID_PCM_S16LE, pcm_s16le);
-PCM_CODEC(CODEC_ID_PCM_S24BE, pcm_s24be);
-PCM_CODEC(CODEC_ID_PCM_S24DAUD, pcm_s24daud);
-PCM_CODEC(CODEC_ID_PCM_S24LE, pcm_s24le);
-PCM_CODEC(CODEC_ID_PCM_S32BE, pcm_s32be);
-PCM_CODEC(CODEC_ID_PCM_S32LE, pcm_s32le);
-PCM_CODEC(CODEC_ID_PCM_U8, pcm_u8);
-PCM_CODEC(CODEC_ID_PCM_U16BE, pcm_u16be);
-PCM_CODEC(CODEC_ID_PCM_U16LE, pcm_u16le);
-PCM_CODEC(CODEC_ID_PCM_U24BE, pcm_u24be);
-PCM_CODEC(CODEC_ID_PCM_U24LE, pcm_u24le);
-PCM_CODEC(CODEC_ID_PCM_U32BE, pcm_u32be);
-PCM_CODEC(CODEC_ID_PCM_U32LE, pcm_u32le);
-
-/* adpcm codecs */
-
-PCM_CODEC(CODEC_ID_ADPCM_4XM, adpcm_4xm);
-PCM_CODEC(CODEC_ID_ADPCM_ADX, adpcm_adx);
-PCM_CODEC(CODEC_ID_ADPCM_CT, adpcm_ct);
-PCM_CODEC(CODEC_ID_ADPCM_EA, adpcm_ea);
-PCM_CODEC(CODEC_ID_ADPCM_G726, adpcm_g726);
-PCM_CODEC(CODEC_ID_ADPCM_IMA_DK3, adpcm_ima_dk3);
-PCM_CODEC(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4);
-PCM_CODEC(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt);
-PCM_CODEC(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav);
-PCM_CODEC(CODEC_ID_ADPCM_IMA_WS, adpcm_ima_ws);
-PCM_CODEC(CODEC_ID_ADPCM_MS, adpcm_ms);
-PCM_CODEC(CODEC_ID_ADPCM_SBPRO_2, adpcm_sbpro_2);
-PCM_CODEC(CODEC_ID_ADPCM_SBPRO_3, adpcm_sbpro_3);
-PCM_CODEC(CODEC_ID_ADPCM_SBPRO_4, adpcm_sbpro_4);
-PCM_CODEC(CODEC_ID_ADPCM_SMJPEG, adpcm_ima_smjpeg);
-PCM_CODEC(CODEC_ID_ADPCM_SWF, adpcm_swf);
-PCM_CODEC(CODEC_ID_ADPCM_XA, adpcm_xa);
-PCM_CODEC(CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha);
-
-#undef PCM_CODEC
-
-/* dummy raw video codec */
-extern AVCodec rawvideo_decoder;
-extern AVCodec rawvideo_encoder;
-
-/* the following codecs use external GPL libs */
-extern AVCodec ac3_decoder;
-extern AVCodec dts_decoder;
-
-/* subtitles */
-extern AVCodec dvbsub_decoder;
-extern AVCodec dvbsub_encoder;
-extern AVCodec dvdsub_decoder;
-extern AVCodec dvdsub_encoder;
-
-/* resample.c */
-
-struct ReSampleContext;
-struct AVResampleContext;
-
-typedef struct ReSampleContext ReSampleContext;
-
-ReSampleContext *audio_resample_init(int output_channels, int input_channels,
- int output_rate, int input_rate);
-int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
-void audio_resample_close(ReSampleContext *s);
-
-struct AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_length, int log2_phase_count, int linear, double cutoff);
-int av_resample(struct AVResampleContext *c, short *dst, short *src, int *consumed, int src_size, int dst_size, int update_ctx);
-void av_resample_compensate(struct AVResampleContext *c, int sample_delta, int compensation_distance);
-void av_resample_close(struct AVResampleContext *c);
-
-/* YUV420 format is assumed ! */
-
-struct ImgReSampleContext;
-
-typedef struct ImgReSampleContext ImgReSampleContext;
-
-ImgReSampleContext *img_resample_init(int output_width, int output_height,
- int input_width, int input_height);
-
-ImgReSampleContext *img_resample_full_init(int owidth, int oheight,
- int iwidth, int iheight,
- int topBand, int bottomBand,
- int leftBand, int rightBand,
- int padtop, int padbottom,
- int padleft, int padright);
-
-
-void img_resample(ImgReSampleContext *s,
- AVPicture *output, const AVPicture *input);
-
-void img_resample_close(ImgReSampleContext *s);
-
-/**
- * Allocate memory for a picture. Call avpicture_free to free it.
- *
- * @param picture the picture to be filled in.
- * @param pix_fmt the format of the picture.
- * @param width the width of the picture.
- * @param height the height of the picture.
- * @return 0 if successful, -1 if not.
- */
-int avpicture_alloc(AVPicture *picture, int pix_fmt, int width, int height);
-
-/* Free a picture previously allocated by avpicture_alloc. */
-void avpicture_free(AVPicture *picture);
-
-int avpicture_fill(AVPicture *picture, uint8_t *ptr,
- int pix_fmt, int width, int height);
-int avpicture_layout(const AVPicture* src, int pix_fmt, int width, int height,
- unsigned char *dest, int dest_size);
-int avpicture_get_size(int pix_fmt, int width, int height);
-void avcodec_get_chroma_sub_sample(int pix_fmt, int *h_shift, int *v_shift);
-const char *avcodec_get_pix_fmt_name(int pix_fmt);
-void avcodec_set_dimensions(AVCodecContext *s, int width, int height);
-enum PixelFormat avcodec_get_pix_fmt(const char* name);
-unsigned int avcodec_pix_fmt_to_codec_tag(enum PixelFormat p);
-
-#define FF_LOSS_RESOLUTION 0x0001 /* loss due to resolution change */
-#define FF_LOSS_DEPTH 0x0002 /* loss due to color depth change */
-#define FF_LOSS_COLORSPACE 0x0004 /* loss due to color space conversion */
-#define FF_LOSS_ALPHA 0x0008 /* loss of alpha bits */
-#define FF_LOSS_COLORQUANT 0x0010 /* loss due to color quantization */
-#define FF_LOSS_CHROMA 0x0020 /* loss of chroma (e.g. rgb to gray conversion) */
-
-int avcodec_get_pix_fmt_loss(int dst_pix_fmt, int src_pix_fmt,
- int has_alpha);
-int avcodec_find_best_pix_fmt(int pix_fmt_mask, int src_pix_fmt,
- int has_alpha, int *loss_ptr);
-
-#define FF_ALPHA_TRANSP 0x0001 /* image has some totally transparent pixels */
-#define FF_ALPHA_SEMI_TRANSP 0x0002 /* image has some transparent pixels */
-int img_get_alpha_info(const AVPicture *src,
- int pix_fmt, int width, int height);
-
-/* convert among pixel formats */
-int img_convert(AVPicture *dst, int dst_pix_fmt,
- const AVPicture *src, int pix_fmt,
- int width, int height);
-
-/* deinterlace a picture */
-int avpicture_deinterlace(AVPicture *dst, const AVPicture *src,
- int pix_fmt, int width, int height);
-
-/* external high level API */
-
-extern AVCodec *first_avcodec;
-
-/* returns LIBAVCODEC_VERSION_INT constant */
-unsigned avcodec_version(void);
-/* returns LIBAVCODEC_BUILD constant */
-unsigned avcodec_build(void);
-void avcodec_init(void);
-
-void register_avcodec(AVCodec *format);
-AVCodec *avcodec_find_encoder(enum CodecID id);
-AVCodec *avcodec_find_encoder_by_name(const char *name);
-AVCodec *avcodec_find_decoder(enum CodecID id);
-AVCodec *avcodec_find_decoder_by_name(const char *name);
-void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
-
-void avcodec_get_context_defaults(AVCodecContext *s);
-AVCodecContext *avcodec_alloc_context(void);
-void avcodec_get_frame_defaults(AVFrame *pic);
-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);
-void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height);
-int avcodec_check_dimensions(void *av_log_ctx, unsigned int w, unsigned int h);
-enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat * fmt);
-
-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 avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count);
-//FIXME func typedef
-
-/**
- * opens / inits the AVCodecContext.
- * not thread save!
- */
-int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
-
-
-attribute_deprecated int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples,
- int *frame_size_ptr,
- uint8_t *buf, int buf_size);
-/**
- * Decode an audio frame.
- *
- * @param avctx the codec context.
- * @param samples output buffer, 16 byte aligned
- * @param frame_size_ptr the output buffer size in bytes (you MUST set this to the allocated size before calling avcodec_decode_audio2()), zero if no frame could be compressed
- * @param buf input buffer, 16 byte aligned
- * @param buf_size the input buffer size
- * @return 0 if successful, -1 if not.
- */
-int avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples,
- int *frame_size_ptr,
- uint8_t *buf, int buf_size);
-int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
- int *got_picture_ptr,
- uint8_t *buf, int buf_size);
-int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub,
- int *got_sub_ptr,
- const uint8_t *buf, int buf_size);
-int avcodec_parse_frame(AVCodecContext *avctx, uint8_t **pdata,
- int *data_size_ptr,
- uint8_t *buf, int buf_size);
-int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
- const short *samples);
-int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
- const AVFrame *pict);
-int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
- const AVSubtitle *sub);
-
-int avcodec_close(AVCodecContext *avctx);
-
-void avcodec_register_all(void);
-
-void avcodec_flush_buffers(AVCodecContext *avctx);
-
-void avcodec_default_free_buffers(AVCodecContext *s);
-
-/* misc usefull functions */
-
-/**
- * returns a single letter to describe the picture type
- */
-char av_get_pict_type_char(int pict_type);
-
-/**
- * returns codec bits per sample
- */
-int av_get_bits_per_sample(enum CodecID codec_id);
-
-/* frame parsing */
-typedef struct AVCodecParserContext {
- void *priv_data;
- struct AVCodecParser *parser;
- int64_t frame_offset; /* offset of the current frame */
- int64_t cur_offset; /* current offset
- (incremented by each av_parser_parse()) */
- int64_t last_frame_offset; /* offset of the last frame */
- /* video info */
- int pict_type; /* XXX: put it back in AVCodecContext */
- int repeat_pict; /* XXX: put it back in AVCodecContext */
- int64_t pts; /* pts of the current frame */
- int64_t dts; /* dts of the current frame */
-
- /* private data */
- int64_t last_pts;
- int64_t last_dts;
- int fetch_timestamp;
-
-#define AV_PARSER_PTS_NB 4
- int cur_frame_start_index;
- int64_t cur_frame_offset[AV_PARSER_PTS_NB];
- int64_t cur_frame_pts[AV_PARSER_PTS_NB];
- int64_t cur_frame_dts[AV_PARSER_PTS_NB];
-
- int flags;
-#define PARSER_FLAG_COMPLETE_FRAMES 0x0001
-} AVCodecParserContext;
-
-typedef struct AVCodecParser {
- int codec_ids[5]; /* several codec IDs are permitted */
- int priv_data_size;
- int (*parser_init)(AVCodecParserContext *s);
- int (*parser_parse)(AVCodecParserContext *s,
- AVCodecContext *avctx,
- uint8_t **poutbuf, int *poutbuf_size,
- const uint8_t *buf, int buf_size);
- void (*parser_close)(AVCodecParserContext *s);
- int (*split)(AVCodecContext *avctx, const uint8_t *buf, int buf_size);
- struct AVCodecParser *next;
-} AVCodecParser;
-
-extern AVCodecParser *av_first_parser;
-
-void av_register_codec_parser(AVCodecParser *parser);
-AVCodecParserContext *av_parser_init(int codec_id);
-int av_parser_parse(AVCodecParserContext *s,
- AVCodecContext *avctx,
- uint8_t **poutbuf, int *poutbuf_size,
- const uint8_t *buf, int buf_size,
- int64_t pts, int64_t dts);
-int av_parser_change(AVCodecParserContext *s,
- AVCodecContext *avctx,
- uint8_t **poutbuf, int *poutbuf_size,
- const uint8_t *buf, int buf_size, int keyframe);
-void av_parser_close(AVCodecParserContext *s);
-
-extern AVCodecParser aac_parser;
-extern AVCodecParser ac3_parser;
-extern AVCodecParser cavsvideo_parser;
-extern AVCodecParser dvbsub_parser;
-extern AVCodecParser dvdsub_parser;
-extern AVCodecParser h261_parser;
-extern AVCodecParser h263_parser;
-extern AVCodecParser h264_parser;
-extern AVCodecParser mjpeg_parser;
-extern AVCodecParser mpeg4video_parser;
-extern AVCodecParser mpegaudio_parser;
-extern AVCodecParser mpegvideo_parser;
-extern AVCodecParser pnm_parser;
-
-
-typedef struct AVBitStreamFilterContext {
- void *priv_data;
- struct AVBitStreamFilter *filter;
- AVCodecParserContext *parser;
- struct AVBitStreamFilterContext *next;
-} AVBitStreamFilterContext;
-
-
-typedef struct AVBitStreamFilter {
- const char *name;
- int priv_data_size;
- int (*filter)(AVBitStreamFilterContext *bsfc,
- AVCodecContext *avctx, const char *args,
- uint8_t **poutbuf, int *poutbuf_size,
- const uint8_t *buf, int buf_size, int keyframe);
- struct AVBitStreamFilter *next;
-} AVBitStreamFilter;
-
-extern AVBitStreamFilter *av_first_bitstream_filter;
-
-void av_register_bitstream_filter(AVBitStreamFilter *bsf);
-AVBitStreamFilterContext *av_bitstream_filter_init(const char *name);
-int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc,
- AVCodecContext *avctx, const char *args,
- uint8_t **poutbuf, int *poutbuf_size,
- const uint8_t *buf, int buf_size, int keyframe);
-void av_bitstream_filter_close(AVBitStreamFilterContext *bsf);
-
-extern AVBitStreamFilter dump_extradata_bsf;
-extern AVBitStreamFilter remove_extradata_bsf;
-extern AVBitStreamFilter noise_bsf;
-extern AVBitStreamFilter mp3_header_compress_bsf;
-extern AVBitStreamFilter mp3_header_decompress_bsf;
-extern AVBitStreamFilter mjpega_dump_header_bsf;
-
-
-/* memory */
-void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size);
-/* for static data only */
-/* call av_free_static to release all staticaly allocated tables */
-void av_free_static(void);
-void *av_mallocz_static(unsigned int size);
-void *av_realloc_static(void *ptr, unsigned int size);
-
-void img_copy(AVPicture *dst, const AVPicture *src,
- int pix_fmt, int width, int height);
-
-int img_crop(AVPicture *dst, const AVPicture *src,
- int pix_fmt, int top_band, int left_band);
-
-int img_pad(AVPicture *dst, const AVPicture *src, int height, int width, int pix_fmt,
- int padtop, int padbottom, int padleft, int padright, int *color);
-
-extern unsigned int av_xiphlacing(unsigned char *s, unsigned int v);
-
-/* unused static macro */
-#if defined(__GNUC__) && !defined(DEBUG)
-/* since we do not compile the encoder part of ffmpeg, some static
- * functions will be unused; this is ok, the compiler will take care */
-# define static static __attribute__((__unused__))
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* AVCODEC_H */
diff --git a/src/libffmpeg/libavcodec/bitstream.c b/src/libffmpeg/libavcodec/bitstream.c
deleted file mode 100644
index 22d256df5..000000000
--- a/src/libffmpeg/libavcodec/bitstream.c
+++ /dev/null
@@ -1,254 +0,0 @@
-/*
- * Common bit i/o utils
- * Copyright (c) 2000, 2001 Fabrice Bellard.
- * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * alternative bitstream reader & writer by Michael Niedermayer <michaelni@gmx.at>
- */
-
-/**
- * @file bitstream.c
- * bitstream api.
- */
-
-#include "avcodec.h"
-#include "bitstream.h"
-
-void align_put_bits(PutBitContext *s)
-{
-#ifdef ALT_BITSTREAM_WRITER
- put_bits(s,( - s->index) & 7,0);
-#else
- put_bits(s,s->bit_left & 7,0);
-#endif
-}
-
-void ff_put_string(PutBitContext * pbc, char *s, int put_zero)
-{
- while(*s){
- put_bits(pbc, 8, *s);
- s++;
- }
- if(put_zero)
- put_bits(pbc, 8, 0);
-}
-
-/* VLC decoding */
-
-//#define DEBUG_VLC
-
-#define GET_DATA(v, table, i, wrap, size) \
-{\
- const uint8_t *ptr = (const uint8_t *)table + i * wrap;\
- switch(size) {\
- case 1:\
- v = *(const uint8_t *)ptr;\
- break;\
- case 2:\
- v = *(const uint16_t *)ptr;\
- break;\
- default:\
- v = *(const uint32_t *)ptr;\
- break;\
- }\
-}
-
-
-static int alloc_table(VLC *vlc, int size, int use_static)
-{
- int index;
- index = vlc->table_size;
- vlc->table_size += size;
- if (vlc->table_size > vlc->table_allocated) {
- vlc->table_allocated += (1 << vlc->bits);
- if(use_static)
- vlc->table = av_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);
- 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,
- uint32_t code_prefix, int n_prefix, int flags)
-{
- int i, j, k, n, table_size, table_index, nb, n1, index, code_prefix2;
- 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);
-#ifdef DEBUG_VLC
- printf("new table index=%d size=%d code_prefix=%x n=%d\n",
- table_index, table_size, code_prefix, n_prefix);
-#endif
- if (table_index < 0)
- return -1;
- table = &vlc->table[table_index];
-
- for(i=0;i<table_size;i++) {
- table[i][1] = 0; //bits
- table[i][0] = -1; //codes
- }
-
- /* first pass: map codes and compute auxillary table sizes */
- for(i=0;i<nb_codes;i++) {
- GET_DATA(n, bits, i, bits_wrap, bits_size);
- GET_DATA(code, codes, i, codes_wrap, codes_size);
- /* we accept tables with holes */
- if (n <= 0)
- continue;
-#if defined(DEBUG_VLC) && 0
- printf("i=%d n=%d code=0x%x\n", i, n, code);
-#endif
- /* if code matches the prefix, it is in the table */
- n -= n_prefix;
- if(flags & INIT_VLC_LE)
- code_prefix2= code & (n_prefix>=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<nb;k++) {
- if(flags & INIT_VLC_LE)
- j = (code >> n_prefix) + (k<<n);
-#ifdef DEBUG_VLC
- 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] = i; //code
- j++;
- }
- } else {
- n -= table_nb_bits;
- j = (code >> ((flags & INIT_VLC_LE) ? n_prefix : n)) & ((1 << table_nb_bits) - 1);
-#ifdef DEBUG_VLC
- printf("%4x: n=%d (subtable)\n",
- j, n);
-#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_size;i++) {
- n = table[i][1]; //bits
- if (n < 0) {
- n = -n;
- if (n > 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,
- (flags & INIT_VLC_LE) ? (code_prefix | (i << n_prefix)) : ((code_prefix << table_nb_bits) | i),
- n_prefix + table_nb_bits, flags);
- if (index < 0)
- return -1;
- /* note: realloc has been done, so reload tables */
- table = &vlc->table[table_index];
- table[i][0] = index; //code
- }
- }
- return table_index;
-}
-
-
-/* Build VLC decoding tables suitable for use with get_vlc().
-
- 'nb_bits' set thee decoding table size (2^nb_bits) entries. The
- bigger it is, the faster is the decoding. But it should not be too
- big to save memory and L1 cache. '9' is a good compromise.
-
- 'nb_codes' : number of vlcs codes
-
- 'bits' : table which gives the size (in bits) of each vlc code.
-
- 'codes' : table which gives the bit pattern of of each vlc code.
-
- 'xxx_wrap' : give the number of bytes between each entry of the
- 'bits' or 'codes' tables.
-
- 'xxx_size' : gives the number of bytes of each entry of the 'bits'
- or 'codes' tables.
-
- 'wrap' and 'size' allows to use any memory configuration and types
- (byte/word/long) to store the 'bits' and 'codes' tables.
-
- 'use_static' should be set to 1 for tables, which should be freed
- with av_free_static(), 0 if free_vlc() will be used.
-*/
-int init_vlc(VLC *vlc, int nb_bits, int nb_codes,
- const void *bits, int bits_wrap, int bits_size,
- const void *codes, int codes_wrap, int codes_size,
- int use_static)
-{
- vlc->bits = nb_bits;
- if(!use_static) {
- 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
- printf("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,
- 0, 0, use_static) < 0) {
- av_free(vlc->table);
- return -1;
- }
- return 0;
-}
-
-
-void free_vlc(VLC *vlc)
-{
- av_free(vlc->table);
-}
-
diff --git a/src/libffmpeg/libavcodec/bitstream.h b/src/libffmpeg/libavcodec/bitstream.h
deleted file mode 100644
index 29e0f441e..000000000
--- a/src/libffmpeg/libavcodec/bitstream.h
+++ /dev/null
@@ -1,956 +0,0 @@
-/*
- * copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/**
- * @file bitstream.h
- * bitstream api header.
- */
-
-#ifndef BITSTREAM_H
-#define BITSTREAM_H
-
-#include "log.h"
-
-#if defined(ALT_BITSTREAM_READER_LE) && !defined(ALT_BITSTREAM_READER)
-#define ALT_BITSTREAM_READER
-#endif
-
-//#define ALT_BITSTREAM_WRITER
-//#define ALIGNED_BITSTREAM_WRITER
-#if !defined(LIBMPEG2_BITSTREAM_READER) && !defined(A32_BITSTREAM_READER) && !defined(ALT_BITSTREAM_READER)
-# ifdef ARCH_ARMV4L
-# define A32_BITSTREAM_READER
-# else
-#define ALT_BITSTREAM_READER
-//#define LIBMPEG2_BITSTREAM_READER
-//#define A32_BITSTREAM_READER
-# endif
-#endif
-#define LIBMPEG2_BITSTREAM_READER_HACK //add BERO
-
-extern const uint8_t ff_reverse[256];
-
-#if defined(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 output */
-
-/* buf and buf_end must be present and used by every alternative writer. */
-typedef struct PutBitContext {
-#ifdef ALT_BITSTREAM_WRITER
- uint8_t *buf, *buf_end;
- int index;
-#else
- uint32_t bit_buf;
- int bit_left;
- uint8_t *buf, *buf_ptr, *buf_end;
-#endif
-} PutBitContext;
-
-static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
-{
- if(buffer_size < 0) {
- buffer_size = 0;
- buffer = NULL;
- }
-
- s->buf = buffer;
- s->buf_end = s->buf + buffer_size;
-#ifdef ALT_BITSTREAM_WRITER
- s->index=0;
- ((uint32_t*)(s->buf))[0]=0;
-// memset(buffer, 0, buffer_size);
-#else
- s->buf_ptr = s->buf;
- s->bit_left=32;
- s->bit_buf=0;
-#endif
-}
-
-/* return the number of bits output */
-static inline int put_bits_count(PutBitContext *s)
-{
-#ifdef ALT_BITSTREAM_WRITER
- return s->index;
-#else
- return (s->buf_ptr - s->buf) * 8 + 32 - s->bit_left;
-#endif
-}
-
-/* pad the end of the output stream with zeros */
-static inline void flush_put_bits(PutBitContext *s)
-{
-#ifdef ALT_BITSTREAM_WRITER
- align_put_bits(s);
-#else
- s->bit_buf<<= s->bit_left;
- while (s->bit_left < 32) {
- /* XXX: should test end of buffer */
- *s->buf_ptr++=s->bit_buf >> 24;
- s->bit_buf<<=8;
- s->bit_left+=8;
- }
- s->bit_left=32;
- s->bit_buf=0;
-#endif
-}
-
-void align_put_bits(PutBitContext *s);
-void ff_put_string(PutBitContext * pbc, char *s, int put_zero);
-
-/* bit input */
-/* buffer, buffer_end and size_in_bits must be present and used by every reader */
-typedef struct GetBitContext {
- const uint8_t *buffer, *buffer_end;
-#ifdef ALT_BITSTREAM_READER
- int index;
-#elif defined LIBMPEG2_BITSTREAM_READER
- uint8_t *buffer_ptr;
- uint32_t cache;
- int bit_count;
-#elif defined A32_BITSTREAM_READER
- uint32_t *buffer_ptr;
- uint32_t cache0;
- uint32_t cache1;
- int bit_count;
-#endif
- int size_in_bits;
-} GetBitContext;
-
-#define VLC_TYPE int16_t
-
-typedef struct VLC {
- int bits;
- VLC_TYPE (*table)[2]; ///< code, bits
- int table_size, table_allocated;
-} VLC;
-
-typedef struct RL_VLC_ELEM {
- int16_t level;
- int8_t len;
- uint8_t run;
-} RL_VLC_ELEM;
-
-#if defined(ARCH_SPARC) || defined(ARCH_ARMV4L) || defined(ARCH_MIPS)
-#define UNALIGNED_STORES_ARE_BAD
-#endif
-
-/* used to avoid missaligned exceptions on some archs (alpha, ...) */
-#if defined(ARCH_X86)
-# define unaligned16(a) (*(const uint16_t*)(a))
-# define unaligned32(a) (*(const uint32_t*)(a))
-# define unaligned64(a) (*(const uint64_t*)(a))
-#else
-# ifdef __GNUC__
-# define unaligned(x) \
-static inline uint##x##_t unaligned##x(const void *v) { \
- struct Unaligned { \
- uint##x##_t i; \
- } __attribute__((packed)); \
- \
- return ((const struct Unaligned *) v)->i; \
-}
-# elif defined(__DECC)
-# define unaligned(x) \
-static inline uint##x##_t unaligned##x(const void *v) { \
- return *(const __unaligned uint##x##_t *) v; \
-}
-# else
-# define unaligned(x) \
-static inline uint##x##_t unaligned##x(const void *v) { \
- return *(const uint##x##_t *) v; \
-}
-# endif
-unaligned(16)
-unaligned(32)
-unaligned(64)
-#undef unaligned
-#endif /* defined(ARCH_X86) */
-
-#ifndef ALT_BITSTREAM_WRITER
-static inline void put_bits(PutBitContext *s, int n, unsigned int value)
-{
- unsigned int bit_buf;
- int bit_left;
-
- // printf("put_bits=%d %x\n", n, value);
- assert(n == 32 || value < (1U << n));
-
- bit_buf = s->bit_buf;
- bit_left = s->bit_left;
-
- // printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf);
- /* XXX: optimize */
- if (n < bit_left) {
- bit_buf = (bit_buf<<n) | value;
- bit_left-=n;
- } else {
- bit_buf<<=bit_left;
- bit_buf |= value >> (n - bit_left);
-#ifdef UNALIGNED_STORES_ARE_BAD
- if (3 & (intptr_t) s->buf_ptr) {
- s->buf_ptr[0] = bit_buf >> 24;
- s->buf_ptr[1] = bit_buf >> 16;
- s->buf_ptr[2] = bit_buf >> 8;
- s->buf_ptr[3] = bit_buf ;
- } else
-#endif
- *(uint32_t *)s->buf_ptr = be2me_32(bit_buf);
- //printf("bitbuf = %08x\n", bit_buf);
- s->buf_ptr+=4;
- bit_left+=32 - n;
- bit_buf = value;
- }
-
- s->bit_buf = bit_buf;
- s->bit_left = bit_left;
-}
-#endif
-
-
-#ifdef ALT_BITSTREAM_WRITER
-static inline void put_bits(PutBitContext *s, int n, unsigned int value)
-{
-# ifdef ALIGNED_BITSTREAM_WRITER
-# if defined(ARCH_X86)
- asm volatile(
- "movl %0, %%ecx \n\t"
- "xorl %%eax, %%eax \n\t"
- "shrdl %%cl, %1, %%eax \n\t"
- "shrl %%cl, %1 \n\t"
- "movl %0, %%ecx \n\t"
- "shrl $3, %%ecx \n\t"
- "andl $0xFFFFFFFC, %%ecx \n\t"
- "bswapl %1 \n\t"
- "orl %1, (%2, %%ecx) \n\t"
- "bswapl %%eax \n\t"
- "addl %3, %0 \n\t"
- "movl %%eax, 4(%2, %%ecx) \n\t"
- : "=&r" (s->index), "=&r" (value)
- : "r" (s->buf), "r" (n), "0" (s->index), "1" (value<<(-n))
- : "%eax", "%ecx"
- );
-# else
- int index= s->index;
- uint32_t *ptr= ((uint32_t *)s->buf)+(index>>5);
-
- value<<= 32-n;
-
- ptr[0] |= be2me_32(value>>(index&31));
- ptr[1] = be2me_32(value<<(32-(index&31)));
-//if(n>24) printf("%d %d\n", n, value);
- index+= n;
- s->index= index;
-# endif
-# else //ALIGNED_BITSTREAM_WRITER
-# if defined(ARCH_X86)
- asm volatile(
- "movl $7, %%ecx \n\t"
- "andl %0, %%ecx \n\t"
- "addl %3, %%ecx \n\t"
- "negl %%ecx \n\t"
- "shll %%cl, %1 \n\t"
- "bswapl %1 \n\t"
- "movl %0, %%ecx \n\t"
- "shrl $3, %%ecx \n\t"
- "orl %1, (%%ecx, %2) \n\t"
- "addl %3, %0 \n\t"
- "movl $0, 4(%%ecx, %2) \n\t"
- : "=&r" (s->index), "=&r" (value)
- : "r" (s->buf), "r" (n), "0" (s->index), "1" (value)
- : "%ecx"
- );
-# else
- int index= s->index;
- uint32_t *ptr= (uint32_t*)(((uint8_t *)s->buf)+(index>>3));
-
- ptr[0] |= be2me_32(value<<(32-n-(index&7) ));
- ptr[1] = 0;
-//if(n>24) printf("%d %d\n", n, value);
- index+= n;
- s->index= index;
-# endif
-# endif //!ALIGNED_BITSTREAM_WRITER
-}
-#endif
-
-
-static inline uint8_t* pbBufPtr(PutBitContext *s)
-{
-#ifdef ALT_BITSTREAM_WRITER
- return s->buf + (s->index>>3);
-#else
- return s->buf_ptr;
-#endif
-}
-
-/**
- *
- * PutBitContext must be flushed & aligned to a byte boundary before calling this.
- */
-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
- s->index += n<<3;
-#else
- assert(s->bit_left==32);
- s->buf_ptr += n;
-#endif
-}
-
-/**
- * skips the given number of bits.
- * must only be used if the actual values in the bitstream dont matter
- */
-static inline void skip_put_bits(PutBitContext *s, int n){
-#ifdef ALT_BITSTREAM_WRITER
- s->index += n;
-#else
- s->bit_left -= n;
- s->buf_ptr-= s->bit_left>>5;
- s->bit_left &= 31;
-#endif
-}
-
-/**
- * Changes the end of the buffer.
- */
-static inline void set_put_bits_buffer_size(PutBitContext *s, int size){
- s->buf_end= s->buf + size;
-}
-
-/* Bitstream reader API docs:
-name
- abritary name which is used as prefix for the internal variables
-
-gb
- getbitcontext
-
-OPEN_READER(name, gb)
- loads gb into local variables
-
-CLOSE_READER(name, gb)
- stores local vars in gb
-
-UPDATE_CACHE(name, gb)
- refills the internal cache from the bitstream
- after this call at least MIN_CACHE_BITS will be available,
-
-GET_CACHE(name, gb)
- will output the contents of the internal cache, next bit is MSB of 32 or 64 bit (FIXME 64bit)
-
-SHOW_UBITS(name, gb, num)
- will return the next num bits
-
-SHOW_SBITS(name, gb, num)
- will return the next num bits and do sign extension
-
-SKIP_BITS(name, gb, num)
- will skip over the next num bits
- note, this is equivalent to SKIP_CACHE; SKIP_COUNTER
-
-SKIP_CACHE(name, gb, num)
- will remove the next num bits from the cache (note SKIP_COUNTER MUST be called before UPDATE_CACHE / CLOSE_READER)
-
-SKIP_COUNTER(name, gb, num)
- will increment the internal bit counter (see SKIP_CACHE & SKIP_BITS)
-
-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
-
-for examples see get_bits, show_bits, skip_bits, get_vlc
-*/
-
-static inline int unaligned32_be(const void *v)
-{
-#ifdef CONFIG_ALIGN
- const uint8_t *p=v;
- return (((p[0]<<8) | p[1])<<16) | (p[2]<<8) | (p[3]);
-#else
- return be2me_32( unaligned32(v)); //original
-#endif
-}
-
-static inline int unaligned32_le(const void *v)
-{
-#ifdef CONFIG_ALIGN
- const uint8_t *p=v;
- return (((p[3]<<8) | p[2])<<16) | (p[1]<<8) | (p[0]);
-#else
- return le2me_32( unaligned32(v)); //original
-#endif
-}
-
-#ifdef ALT_BITSTREAM_READER
-# define MIN_CACHE_BITS 25
-
-# define OPEN_READER(name, gb)\
- int name##_index= (gb)->index;\
- int name##_cache= 0;\
-
-# define CLOSE_READER(name, gb)\
- (gb)->index= name##_index;\
-
-# ifdef ALT_BITSTREAM_READER_LE
-# define UPDATE_CACHE(name, gb)\
- name##_cache= unaligned32_le( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) >> (name##_index&0x07);\
-
-# define SKIP_CACHE(name, gb, num)\
- name##_cache >>= (num);
-# else
-# define UPDATE_CACHE(name, gb)\
- name##_cache= unaligned32_be( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) << (name##_index&0x07);\
-
-# define SKIP_CACHE(name, gb, num)\
- name##_cache <<= (num);
-# endif
-
-// FIXME name?
-# define SKIP_COUNTER(name, gb, num)\
- name##_index += (num);\
-
-# define SKIP_BITS(name, gb, num)\
- {\
- SKIP_CACHE(name, gb, num)\
- SKIP_COUNTER(name, gb, num)\
- }\
-
-# define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num)
-# define LAST_SKIP_CACHE(name, gb, num) ;
-
-# ifdef ALT_BITSTREAM_READER_LE
-# define SHOW_UBITS(name, gb, num)\
- ((name##_cache) & (NEG_USR32(0xffffffff,num)))
-
-# define SHOW_SBITS(name, gb, num)\
- NEG_SSR32((name##_cache)<<(32-(num)), num)
-# else
-# define SHOW_UBITS(name, gb, num)\
- NEG_USR32(name##_cache, num)
-
-# define SHOW_SBITS(name, gb, num)\
- NEG_SSR32(name##_cache, num)
-# endif
-
-# define GET_CACHE(name, gb)\
- ((uint32_t)name##_cache)
-
-static inline int get_bits_count(GetBitContext *s){
- return s->index;
-}
-
-static inline void skip_bits_long(GetBitContext *s, int n){
- s->index += n;
-}
-
-#elif defined LIBMPEG2_BITSTREAM_READER
-//libmpeg2 like reader
-
-# define MIN_CACHE_BITS 17
-
-# define OPEN_READER(name, gb)\
- int name##_bit_count=(gb)->bit_count;\
- int name##_cache= (gb)->cache;\
- uint8_t * name##_buffer_ptr=(gb)->buffer_ptr;\
-
-# define CLOSE_READER(name, gb)\
- (gb)->bit_count= name##_bit_count;\
- (gb)->cache= name##_cache;\
- (gb)->buffer_ptr= name##_buffer_ptr;\
-
-#ifdef LIBMPEG2_BITSTREAM_READER_HACK
-
-# define UPDATE_CACHE(name, gb)\
- if(name##_bit_count >= 0){\
- name##_cache+= (int)be2me_16(*(uint16_t*)name##_buffer_ptr) << name##_bit_count;\
- name##_buffer_ptr += 2;\
- name##_bit_count-= 16;\
- }\
-
-#else
-
-# define UPDATE_CACHE(name, gb)\
- if(name##_bit_count >= 0){\
- name##_cache+= ((name##_buffer_ptr[0]<<8) + name##_buffer_ptr[1]) << name##_bit_count;\
- name##_buffer_ptr+=2;\
- name##_bit_count-= 16;\
- }\
-
-#endif
-
-# define SKIP_CACHE(name, gb, num)\
- name##_cache <<= (num);\
-
-# define SKIP_COUNTER(name, gb, num)\
- name##_bit_count += (num);\
-
-# define SKIP_BITS(name, gb, num)\
- {\
- SKIP_CACHE(name, gb, num)\
- SKIP_COUNTER(name, gb, num)\
- }\
-
-# define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num)
-# define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num)
-
-# define SHOW_UBITS(name, gb, num)\
- NEG_USR32(name##_cache, num)
-
-# define SHOW_SBITS(name, gb, num)\
- NEG_SSR32(name##_cache, num)
-
-# define GET_CACHE(name, gb)\
- ((uint32_t)name##_cache)
-
-static inline int get_bits_count(GetBitContext *s){
- return (s->buffer_ptr - s->buffer)*8 - 16 + s->bit_count;
-}
-
-static inline void skip_bits_long(GetBitContext *s, int n){
- OPEN_READER(re, s)
- re_bit_count += n;
- re_buffer_ptr += 2*(re_bit_count>>4);
- re_bit_count &= 15;
- re_cache = ((re_buffer_ptr[-2]<<8) + re_buffer_ptr[-1]) << (16+re_bit_count);
- UPDATE_CACHE(re, s)
- CLOSE_READER(re, s)
-}
-
-#elif defined A32_BITSTREAM_READER
-
-# define MIN_CACHE_BITS 32
-
-# define OPEN_READER(name, gb)\
- int name##_bit_count=(gb)->bit_count;\
- uint32_t name##_cache0= (gb)->cache0;\
- uint32_t name##_cache1= (gb)->cache1;\
- uint32_t * name##_buffer_ptr=(gb)->buffer_ptr;\
-
-# define CLOSE_READER(name, gb)\
- (gb)->bit_count= name##_bit_count;\
- (gb)->cache0= name##_cache0;\
- (gb)->cache1= name##_cache1;\
- (gb)->buffer_ptr= name##_buffer_ptr;\
-
-# define UPDATE_CACHE(name, gb)\
- if(name##_bit_count > 0){\
- const uint32_t next= be2me_32( *name##_buffer_ptr );\
- name##_cache0 |= NEG_USR32(next,name##_bit_count);\
- name##_cache1 |= next<<name##_bit_count;\
- name##_buffer_ptr++;\
- name##_bit_count-= 32;\
- }\
-
-#if defined(ARCH_X86)
-# define SKIP_CACHE(name, gb, num)\
- asm(\
- "shldl %2, %1, %0 \n\t"\
- "shll %2, %1 \n\t"\
- : "+r" (name##_cache0), "+r" (name##_cache1)\
- : "Ic" ((uint8_t)(num))\
- );
-#else
-# define SKIP_CACHE(name, gb, num)\
- name##_cache0 <<= (num);\
- name##_cache0 |= NEG_USR32(name##_cache1,num);\
- name##_cache1 <<= (num);
-#endif
-
-# define SKIP_COUNTER(name, gb, num)\
- name##_bit_count += (num);\
-
-# define SKIP_BITS(name, gb, num)\
- {\
- SKIP_CACHE(name, gb, num)\
- SKIP_COUNTER(name, gb, num)\
- }\
-
-# define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num)
-# define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num)
-
-# define SHOW_UBITS(name, gb, num)\
- NEG_USR32(name##_cache0, num)
-
-# define SHOW_SBITS(name, gb, num)\
- NEG_SSR32(name##_cache0, num)
-
-# define GET_CACHE(name, gb)\
- (name##_cache0)
-
-static inline int get_bits_count(GetBitContext *s){
- return ((uint8_t*)s->buffer_ptr - s->buffer)*8 - 32 + s->bit_count;
-}
-
-static inline void skip_bits_long(GetBitContext *s, int n){
- OPEN_READER(re, s)
- re_bit_count += n;
- re_buffer_ptr += re_bit_count>>5;
- re_bit_count &= 31;
- re_cache0 = be2me_32( re_buffer_ptr[-1] ) << re_bit_count;
- re_cache1 = 0;
- UPDATE_CACHE(re, s)
- CLOSE_READER(re, s)
-}
-
-#endif
-
-/**
- * read mpeg1 dc style vlc (sign bit + mantisse with no MSB).
- * if MSB not set it is negative
- * @param n length in bits
- * @author BERO
- */
-static inline int get_xbits(GetBitContext *s, int n){
- register int sign;
- register int32_t cache;
- OPEN_READER(re, s)
- UPDATE_CACHE(re, s)
- cache = GET_CACHE(re,s);
- sign=(~cache)>>31;
- LAST_SKIP_BITS(re, s, n)
- CLOSE_READER(re, s)
- return (NEG_USR32(sign ^ cache, n) ^ sign) - sign;
-}
-
-static inline int get_sbits(GetBitContext *s, int n){
- register int tmp;
- OPEN_READER(re, s)
- UPDATE_CACHE(re, s)
- tmp= SHOW_SBITS(re, s, n);
- LAST_SKIP_BITS(re, s, n)
- CLOSE_READER(re, s)
- return tmp;
-}
-
-/**
- * reads 0-17 bits.
- * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't
- */
-static inline unsigned int get_bits(GetBitContext *s, int n){
- register int tmp;
- OPEN_READER(re, s)
- UPDATE_CACHE(re, s)
- tmp= SHOW_UBITS(re, s, n);
- LAST_SKIP_BITS(re, s, n)
- CLOSE_READER(re, s)
- return tmp;
-}
-
-/**
- * shows 0-17 bits.
- * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't
- */
-static inline unsigned int show_bits(GetBitContext *s, int n){
- register int tmp;
- OPEN_READER(re, s)
- UPDATE_CACHE(re, s)
- tmp= SHOW_UBITS(re, s, n);
-// CLOSE_READER(re, s)
- return tmp;
-}
-
-static inline void skip_bits(GetBitContext *s, int n){
- //Note gcc seems to optimize this to s->index+=n for the ALT_READER :))
- OPEN_READER(re, s)
- UPDATE_CACHE(re, s)
- LAST_SKIP_BITS(re, s, n)
- CLOSE_READER(re, s)
-}
-
-static inline unsigned int get_bits1(GetBitContext *s){
-#ifdef ALT_BITSTREAM_READER
- int index= s->index;
- uint8_t result= s->buffer[ index>>3 ];
-#ifdef ALT_BITSTREAM_READER_LE
- result>>= (index&0x07);
- result&= 1;
-#else
- result<<= (index&0x07);
- result>>= 8 - 1;
-#endif
- index++;
- s->index= index;
-
- return result;
-#else
- return get_bits(s, 1);
-#endif
-}
-
-static inline unsigned int show_bits1(GetBitContext *s){
- return show_bits(s, 1);
-}
-
-static inline void skip_bits1(GetBitContext *s){
- skip_bits(s, 1);
-}
-
-/**
- * reads 0-32 bits.
- */
-static inline unsigned int get_bits_long(GetBitContext *s, int n){
- if(n<=17) return get_bits(s, n);
- else{
-#ifdef ALT_BITSTREAM_READER_LE
- int ret= get_bits(s, 16);
- return ret | (get_bits(s, n-16) << 16);
-#else
- int ret= get_bits(s, 16) << (n-16);
- return ret | get_bits(s, n-16);
-#endif
- }
-}
-
-/**
- * shows 0-32 bits.
- */
-static inline unsigned int show_bits_long(GetBitContext *s, int n){
- if(n<=17) return show_bits(s, n);
- else{
- GetBitContext gb= *s;
- int ret= get_bits_long(s, n);
- *s= gb;
- return ret;
- }
-}
-
-static inline int check_marker(GetBitContext *s, const char *msg)
-{
- int bit= get_bits1(s);
- if(!bit)
- av_log(NULL, AV_LOG_INFO, "Marker bit missing %s\n", msg);
-
- return bit;
-}
-
-/**
- * init GetBitContext.
- * @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
- */
-static inline void init_get_bits(GetBitContext *s,
- const uint8_t *buffer, int bit_size)
-{
- int buffer_size= (bit_size+7)>>3;
- if(buffer_size < 0 || bit_size < 0) {
- buffer_size = bit_size = 0;
- buffer = NULL;
- }
-
- s->buffer= buffer;
- s->size_in_bits= bit_size;
- s->buffer_end= buffer + buffer_size;
-#ifdef ALT_BITSTREAM_READER
- s->index=0;
-#elif defined LIBMPEG2_BITSTREAM_READER
- s->buffer_ptr = (uint8_t*)((intptr_t)buffer&(~1));
- s->bit_count = 16 + 8*((intptr_t)buffer&1);
- skip_bits_long(s, 0);
-#elif defined A32_BITSTREAM_READER
- s->buffer_ptr = (uint32_t*)((intptr_t)buffer&(~3));
- s->bit_count = 32 + 8*((intptr_t)buffer&3);
- skip_bits_long(s, 0);
-#endif
-}
-
-static inline void align_get_bits(GetBitContext *s)
-{
- int n= (-get_bits_count(s)) & 7;
- if(n) skip_bits(s, n);
-}
-
-int init_vlc(VLC *vlc, int nb_bits, int nb_codes,
- const void *bits, int bits_wrap, int bits_size,
- const void *codes, int codes_wrap, int codes_size,
- int flags);
-#define INIT_VLC_USE_STATIC 1
-#define INIT_VLC_LE 2
-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
- */
-#define GET_VLC(code, name, gb, table, bits, max_depth)\
-{\
- int n, index, nb_bits;\
-\
- index= SHOW_UBITS(name, gb, bits);\
- code = table[index][0];\
- n = table[index][1];\
-\
- if(max_depth > 1 && n < 0){\
- LAST_SKIP_BITS(name, gb, bits)\
- UPDATE_CACHE(name, gb)\
-\
- nb_bits = -n;\
-\
- index= SHOW_UBITS(name, gb, nb_bits) + code;\
- code = table[index][0];\
- n = table[index][1];\
- if(max_depth > 2 && n < 0){\
- LAST_SKIP_BITS(name, gb, nb_bits)\
- UPDATE_CACHE(name, gb)\
-\
- nb_bits = -n;\
-\
- index= SHOW_UBITS(name, gb, nb_bits) + code;\
- code = table[index][0];\
- n = table[index][1];\
- }\
- }\
- SKIP_BITS(name, gb, n)\
-}
-
-#define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)\
-{\
- int n, index, nb_bits;\
-\
- index= SHOW_UBITS(name, gb, bits);\
- level = table[index].level;\
- n = table[index].len;\
-\
- if(max_depth > 1 && n < 0){\
- SKIP_BITS(name, gb, bits)\
- if(need_update){\
- UPDATE_CACHE(name, gb)\
- }\
-\
- nb_bits = -n;\
-\
- index= SHOW_UBITS(name, gb, nb_bits) + level;\
- level = table[index].level;\
- n = table[index].len;\
- }\
- run= table[index].run;\
- SKIP_BITS(name, gb, n)\
-}
-
-
-/**
- * parses a vlc code, faster then get_vlc()
- * @param bits is the number of bits which will be read at once, must be
- * identical to nb_bits in init_vlc()
- * @param max_depth is the number of times bits bits must be readed to completly
- * read the longest vlc code
- * = (max_vlc_length + bits - 1) / bits
- */
-static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2],
- int bits, int max_depth)
-{
- int code;
-
- OPEN_READER(re, s)
- UPDATE_CACHE(re, s)
-
- GET_VLC(code, re, s, table, bits, max_depth)
-
- CLOSE_READER(re, s)
- return code;
-}
-
-//#define TRACE
-
-#ifdef TRACE
-static inline void print_bin(int bits, int n){
- int i;
-
- for(i=n-1; i>=0; i--){
- av_log(NULL, AV_LOG_DEBUG, "%d", (bits>>i)&1);
- }
- for(i=n; i<24; i++)
- av_log(NULL, AV_LOG_DEBUG, " ");
-}
-
-static inline int get_bits_trace(GetBitContext *s, int n, char *file, const char *func, int line){
- int r= get_bits(s, n);
-
- print_bin(r, n);
- av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d bit @%5d in %s %s:%d\n", r, n, r, get_bits_count(s)-n, file, func, line);
- return r;
-}
-static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2], int bits, int max_depth, char *file, const char *func, int line){
- int show= show_bits(s, 24);
- int pos= get_bits_count(s);
- int r= get_vlc2(s, table, bits, max_depth);
- int len= get_bits_count(s) - pos;
- int bits2= show>>(24-len);
-
- print_bin(bits2, len);
-
- av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d vlc @%5d in %s %s:%d\n", bits2, len, r, pos, file, func, line);
- return r;
-}
-static inline int get_xbits_trace(GetBitContext *s, int n, char *file, const char *func, int line){
- int show= show_bits(s, n);
- int r= get_xbits(s, n);
-
- print_bin(show, n);
- av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d xbt @%5d in %s %s:%d\n", show, n, r, get_bits_count(s)-n, file, func, line);
- return r;
-}
-
-#define get_bits(s, n) get_bits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__)
-#define get_bits1(s) get_bits_trace(s, 1, __FILE__, __PRETTY_FUNCTION__, __LINE__)
-#define get_xbits(s, n) get_xbits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__)
-#define get_vlc(s, vlc) get_vlc_trace(s, (vlc)->table, (vlc)->bits, 3, __FILE__, __PRETTY_FUNCTION__, __LINE__)
-#define get_vlc2(s, tab, bits, max) get_vlc_trace(s, tab, bits, max, __FILE__, __PRETTY_FUNCTION__, __LINE__)
-
-#define tprintf(...) av_log(NULL, AV_LOG_DEBUG, __VA_ARGS__)
-
-#else //TRACE
-#define tprintf(...) {}
-#endif
-
-static inline int decode012(GetBitContext *gb){
- int n;
- n = get_bits1(gb);
- if (n == 0)
- return 0;
- else
- return get_bits1(gb) + 1;
-}
-
-#endif /* BITSTREAM_H */
diff --git a/src/libffmpeg/libavcodec/bytestream.h b/src/libffmpeg/libavcodec/bytestream.h
deleted file mode 100644
index ae5438b49..000000000
--- a/src/libffmpeg/libavcodec/bytestream.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Bytestream functions
- * copyright (c) 2006 Baptiste Coudurier <baptiste.coudurier@free.fr>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef FFMPEG_BYTESTREAM_H
-#define FFMPEG_BYTESTREAM_H
-
-static av_always_inline unsigned int bytestream_get_le32(uint8_t **b)
-{
- (*b) += 4;
- return AV_RL32(*b - 4);
-}
-
-static av_always_inline unsigned int bytestream_get_le16(uint8_t **b)
-{
- (*b) += 2;
- return AV_RL16(*b - 2);
-}
-
-static av_always_inline unsigned int bytestream_get_byte(uint8_t **b)
-{
- (*b)++;
- return (*b)[-1];
-}
-
-static av_always_inline unsigned int bytestream_get_buffer(uint8_t **b, uint8_t *dst, unsigned int size)
-{
- memcpy(dst, *b, size);
- (*b) += size;
- return size;
-}
-
-static av_always_inline void bytestream_put_be32(uint8_t **b, const unsigned int value)
-{
- *(*b)++ = value >> 24;
- *(*b)++ = value >> 16;
- *(*b)++ = value >> 8;
- *(*b)++ = value;
-};
-
-static av_always_inline void bytestream_put_be16(uint8_t **b, const unsigned int value)
-{
- *(*b)++ = value >> 8;
- *(*b)++ = value;
-}
-
-static av_always_inline void bytestream_put_le32(uint8_t **b, const unsigned int value)
-{
- *(*b)++ = value;
- *(*b)++ = value >> 8;
- *(*b)++ = value >> 16;
- *(*b)++ = value >> 24;
-}
-
-static av_always_inline void bytestream_put_le16(uint8_t **b, const unsigned int value)
-{
- *(*b)++ = value;
- *(*b)++ = value >> 8;
-}
-
-static av_always_inline void bytestream_put_byte(uint8_t **b, const unsigned int value)
-{
- *(*b)++ = value;
-}
-
-static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
-{
- memcpy(*b, src, size);
- (*b) += size;
-}
-
-#endif /* FFMPEG_BYTESTREAM_H */
diff --git a/src/libffmpeg/libavcodec/cabac.h b/src/libffmpeg/libavcodec/cabac.h
deleted file mode 100644
index b990014f6..000000000
--- a/src/libffmpeg/libavcodec/cabac.h
+++ /dev/null
@@ -1,859 +0,0 @@
-/*
- * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder
- * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-/**
- * @file cabac.h
- * Context Adaptive Binary Arithmetic Coder.
- */
-
-
-//#undef NDEBUG
-#include <assert.h>
-#ifdef ARCH_X86
-#include "x86_cpu.h"
-#endif
-
-#define CABAC_BITS 16
-#define CABAC_MASK ((1<<CABAC_BITS)-1)
-#define BRANCHLESS_CABAC_DECODER 1
-//#define ARCH_X86_DISABLED 1
-
-typedef struct CABACContext{
- int low;
- int range;
- int outstanding_count;
-#ifdef STRICT_LIMITS
- int symCount;
-#endif
- const uint8_t *bytestream_start;
- const uint8_t *bytestream;
- const uint8_t *bytestream_end;
- PutBitContext pb;
-}CABACContext;
-
-extern uint8_t ff_h264_mlps_state[4*64];
-extern uint8_t ff_h264_lps_range[4*2*64]; ///< rangeTabLPS
-extern uint8_t ff_h264_mps_state[2*64]; ///< transIdxMPS
-extern uint8_t ff_h264_lps_state[2*64]; ///< transIdxLPS
-extern const uint8_t ff_h264_norm_shift[512];
-
-
-void ff_init_cabac_encoder(CABACContext *c, uint8_t *buf, int buf_size);
-void ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size);
-void ff_init_cabac_states(CABACContext *c);
-
-
-static inline void put_cabac_bit(CABACContext *c, int b){
- put_bits(&c->pb, 1, b);
- for(;c->outstanding_count; c->outstanding_count--){
- put_bits(&c->pb, 1, 1-b);
- }
-}
-
-static inline void renorm_cabac_encoder(CABACContext *c){
- while(c->range < 0x100){
- //FIXME optimize
- if(c->low<0x100){
- put_cabac_bit(c, 0);
- }else if(c->low<0x200){
- c->outstanding_count++;
- c->low -= 0x100;
- }else{
- put_cabac_bit(c, 1);
- c->low -= 0x200;
- }
-
- c->range+= c->range;
- c->low += c->low;
- }
-}
-
-static void put_cabac(CABACContext *c, uint8_t * const state, int bit){
- int RangeLPS= ff_h264_lps_range[2*(c->range&0xC0) + *state];
-
- if(bit == ((*state)&1)){
- c->range -= RangeLPS;
- *state= ff_h264_mps_state[*state];
- }else{
- c->low += c->range - RangeLPS;
- c->range = RangeLPS;
- *state= ff_h264_lps_state[*state];
- }
-
- renorm_cabac_encoder(c);
-
-#ifdef STRICT_LIMITS
- c->symCount++;
-#endif
-}
-
-static void put_cabac_static(CABACContext *c, int RangeLPS, int bit){
- assert(c->range > RangeLPS);
-
- if(!bit){
- c->range -= RangeLPS;
- }else{
- c->low += c->range - RangeLPS;
- c->range = RangeLPS;
- }
-
- renorm_cabac_encoder(c);
-
-#ifdef STRICT_LIMITS
- c->symCount++;
-#endif
-}
-
-/**
- * @param bit 0 -> write zero bit, !=0 write one bit
- */
-static void put_cabac_bypass(CABACContext *c, int bit){
- c->low += c->low;
-
- if(bit){
- c->low += c->range;
- }
-//FIXME optimize
- if(c->low<0x200){
- put_cabac_bit(c, 0);
- }else if(c->low<0x400){
- c->outstanding_count++;
- c->low -= 0x200;
- }else{
- put_cabac_bit(c, 1);
- c->low -= 0x400;
- }
-
-#ifdef STRICT_LIMITS
- c->symCount++;
-#endif
-}
-
-/**
- *
- * @return the number of bytes written
- */
-static int put_cabac_terminate(CABACContext *c, int bit){
- c->range -= 2;
-
- if(!bit){
- renorm_cabac_encoder(c);
- }else{
- c->low += c->range;
- c->range= 2;
-
- renorm_cabac_encoder(c);
-
- assert(c->low <= 0x1FF);
- put_cabac_bit(c, c->low>>9);
- put_bits(&c->pb, 2, ((c->low>>7)&3)|1);
-
- flush_put_bits(&c->pb); //FIXME FIXME FIXME XXX wrong
- }
-
-#ifdef STRICT_LIMITS
- c->symCount++;
-#endif
-
- return (put_bits_count(&c->pb)+7)>>3;
-}
-
-/**
- * put (truncated) unary binarization.
- */
-static void put_cabac_u(CABACContext *c, uint8_t * state, int v, int max, int max_index, int truncated){
- int i;
-
- assert(v <= max);
-
-#if 1
- for(i=0; i<v; i++){
- put_cabac(c, state, 1);
- if(i < max_index) state++;
- }
- if(truncated==0 || v<max)
- put_cabac(c, state, 0);
-#else
- if(v <= max_index){
- for(i=0; i<v; i++){
- put_cabac(c, state+i, 1);
- }
- if(truncated==0 || v<max)
- put_cabac(c, state+i, 0);
- }else{
- for(i=0; i<=max_index; i++){
- put_cabac(c, state+i, 1);
- }
- for(; i<v; i++){
- put_cabac(c, state+max_index, 1);
- }
- if(truncated==0 || v<max)
- put_cabac(c, state+max_index, 0);
- }
-#endif
-}
-
-/**
- * put unary exp golomb k-th order binarization.
- */
-static void put_cabac_ueg(CABACContext *c, uint8_t * state, int v, int max, int is_signed, int k, int max_index){
- int i;
-
- if(v==0)
- put_cabac(c, state, 0);
- else{
- const int sign= v < 0;
-
- if(is_signed) v= FFABS(v);
-
- if(v<max){
- for(i=0; i<v; i++){
- put_cabac(c, state, 1);
- if(i < max_index) state++;
- }
-
- put_cabac(c, state, 0);
- }else{
- int m= 1<<k;
-
- for(i=0; i<max; i++){
- put_cabac(c, state, 1);
- if(i < max_index) state++;
- }
-
- v -= max;
- while(v >= m){ //FIXME optimize
- put_cabac_bypass(c, 1);
- v-= m;
- m+= m;
- }
- put_cabac_bypass(c, 0);
- while(m>>=1){
- put_cabac_bypass(c, v&m);
- }
- }
-
- if(is_signed)
- put_cabac_bypass(c, sign);
- }
-}
-
-static void refill(CABACContext *c){
-#if CABAC_BITS == 16
- c->low+= (c->bytestream[0]<<9) + (c->bytestream[1]<<1);
-#else
- c->low+= c->bytestream[0]<<1;
-#endif
- c->low -= CABAC_MASK;
- c->bytestream+= CABAC_BITS/8;
-}
-
-static void refill2(CABACContext *c){
- int i, x;
-
- x= c->low ^ (c->low-1);
- i= 7 - ff_h264_norm_shift[x>>(CABAC_BITS-1)];
-
- x= -CABAC_MASK;
-
-#if CABAC_BITS == 16
- x+= (c->bytestream[0]<<9) + (c->bytestream[1]<<1);
-#else
- x+= c->bytestream[0]<<1;
-#endif
-
- c->low += x<<i;
- c->bytestream+= CABAC_BITS/8;
-}
-
-static inline void renorm_cabac_decoder(CABACContext *c){
- while(c->range < 0x100){
- c->range+= c->range;
- c->low+= c->low;
- if(!(c->low & CABAC_MASK))
- refill(c);
- }
-}
-
-static inline void renorm_cabac_decoder_once(CABACContext *c){
-#ifdef ARCH_X86_DISABLED
- int temp;
-#if 0
- //P3:683 athlon:475
- asm(
- "lea -0x100(%0), %2 \n\t"
- "shr $31, %2 \n\t" //FIXME 31->63 for x86-64
- "shl %%cl, %0 \n\t"
- "shl %%cl, %1 \n\t"
- : "+r"(c->range), "+r"(c->low), "+c"(temp)
- );
-#elif 0
- //P3:680 athlon:474
- asm(
- "cmp $0x100, %0 \n\t"
- "setb %%cl \n\t" //FIXME 31->63 for x86-64
- "shl %%cl, %0 \n\t"
- "shl %%cl, %1 \n\t"
- : "+r"(c->range), "+r"(c->low), "+c"(temp)
- );
-#elif 1
- int temp2;
- //P3:665 athlon:517
- asm(
- "lea -0x100(%0), %%eax \n\t"
- "cdq \n\t"
- "mov %0, %%eax \n\t"
- "and %%edx, %0 \n\t"
- "and %1, %%edx \n\t"
- "add %%eax, %0 \n\t"
- "add %%edx, %1 \n\t"
- : "+r"(c->range), "+r"(c->low), "+a"(temp), "+d"(temp2)
- );
-#elif 0
- int temp2;
- //P3:673 athlon:509
- asm(
- "cmp $0x100, %0 \n\t"
- "sbb %%edx, %%edx \n\t"
- "mov %0, %%eax \n\t"
- "and %%edx, %0 \n\t"
- "and %1, %%edx \n\t"
- "add %%eax, %0 \n\t"
- "add %%edx, %1 \n\t"
- : "+r"(c->range), "+r"(c->low), "+a"(temp), "+d"(temp2)
- );
-#else
- int temp2;
- //P3:677 athlon:511
- asm(
- "cmp $0x100, %0 \n\t"
- "lea (%0, %0), %%eax \n\t"
- "lea (%1, %1), %%edx \n\t"
- "cmovb %%eax, %0 \n\t"
- "cmovb %%edx, %1 \n\t"
- : "+r"(c->range), "+r"(c->low), "+a"(temp), "+d"(temp2)
- );
-#endif
-#else
- //P3:675 athlon:476
- int shift= (uint32_t)(c->range - 0x100)>>31;
- c->range<<= shift;
- c->low <<= shift;
-#endif
- if(!(c->low & CABAC_MASK))
- refill(c);
-}
-
-static int av_always_inline get_cabac_inline(CABACContext *c, uint8_t * const state){
- //FIXME gcc generates duplicate load/stores for c->low and c->range
-#define LOW "0"
-#define RANGE "4"
-#ifdef ARCH_X86_64
-#define BYTESTART "16"
-#define BYTE "24"
-#define BYTEEND "32"
-#else
-#define BYTESTART "12"
-#define BYTE "16"
-#define BYTEEND "20"
-#endif
-#if defined(ARCH_X86) && !(defined(PIC) && defined(__GNUC__))
- int bit;
-
-#ifndef BRANCHLESS_CABAC_DECODER
- asm volatile(
- "movzbl (%1), %0 \n\t"
- "movl "RANGE "(%2), %%ebx \n\t"
- "movl "RANGE "(%2), %%edx \n\t"
- "andl $0xC0, %%ebx \n\t"
- "movzbl "MANGLE(ff_h264_lps_range)"(%0, %%ebx, 2), %%esi\n\t"
- "movl "LOW "(%2), %%ebx \n\t"
-//eax:state ebx:low, edx:range, esi:RangeLPS
- "subl %%esi, %%edx \n\t"
- "movl %%edx, %%ecx \n\t"
- "shll $17, %%ecx \n\t"
- "cmpl %%ecx, %%ebx \n\t"
- " ja 1f \n\t"
-
-#if 1
- //athlon:4067 P3:4110
- "lea -0x100(%%edx), %%ecx \n\t"
- "shr $31, %%ecx \n\t"
- "shl %%cl, %%edx \n\t"
- "shl %%cl, %%ebx \n\t"
-#else
- //athlon:4057 P3:4130
- "cmp $0x100, %%edx \n\t" //FIXME avoidable
- "setb %%cl \n\t"
- "shl %%cl, %%edx \n\t"
- "shl %%cl, %%ebx \n\t"
-#endif
- "movzbl "MANGLE(ff_h264_mps_state)"(%0), %%ecx \n\t"
- "movb %%cl, (%1) \n\t"
-//eax:state ebx:low, edx:range, esi:RangeLPS
- "test %%bx, %%bx \n\t"
- " jnz 2f \n\t"
- "mov "BYTE "(%2), %%"REG_S" \n\t"
- "subl $0xFFFF, %%ebx \n\t"
- "movzwl (%%"REG_S"), %%ecx \n\t"
- "bswap %%ecx \n\t"
- "shrl $15, %%ecx \n\t"
- "add $2, %%"REG_S" \n\t"
- "addl %%ecx, %%ebx \n\t"
- "mov %%"REG_S", "BYTE "(%2) \n\t"
- "jmp 2f \n\t"
- "1: \n\t"
-//eax:state ebx:low, edx:range, esi:RangeLPS
- "subl %%ecx, %%ebx \n\t"
- "movl %%esi, %%edx \n\t"
- "movzbl " MANGLE(ff_h264_norm_shift) "(%%esi), %%ecx \n\t"
- "shll %%cl, %%ebx \n\t"
- "shll %%cl, %%edx \n\t"
- "movzbl "MANGLE(ff_h264_lps_state)"(%0), %%ecx \n\t"
- "movb %%cl, (%1) \n\t"
- "add $1, %0 \n\t"
- "test %%bx, %%bx \n\t"
- " jnz 2f \n\t"
-
- "mov "BYTE "(%2), %%"REG_c" \n\t"
- "movzwl (%%"REG_c"), %%esi \n\t"
- "bswap %%esi \n\t"
- "shrl $15, %%esi \n\t"
- "subl $0xFFFF, %%esi \n\t"
- "add $2, %%"REG_c" \n\t"
- "mov %%"REG_c", "BYTE "(%2) \n\t"
-
- "leal -1(%%ebx), %%ecx \n\t"
- "xorl %%ebx, %%ecx \n\t"
- "shrl $15, %%ecx \n\t"
- "movzbl " MANGLE(ff_h264_norm_shift) "(%%ecx), %%ecx \n\t"
- "neg %%ecx \n\t"
- "add $7, %%ecx \n\t"
-
- "shll %%cl , %%esi \n\t"
- "addl %%esi, %%ebx \n\t"
- "2: \n\t"
- "movl %%edx, "RANGE "(%2) \n\t"
- "movl %%ebx, "LOW "(%2) \n\t"
- :"=&a"(bit) //FIXME this is fragile gcc either runs out of registers or misscompiles it (for example if "+a"(bit) or "+m"(*state) is used
- :"r"(state), "r"(c)
- : "%"REG_c, "%ebx", "%edx", "%"REG_S, "memory"
- );
- bit&=1;
-#else /* BRANCHLESS_CABAC_DECODER */
-
-
-#if defined HAVE_FAST_CMOV
-#define BRANCHLESS_GET_CABAC_UPDATE(ret, cabac, statep, low, lowword, range, tmp, tmpbyte)\
- "mov "tmp" , %%ecx \n\t"\
- "shl $17 , "tmp" \n\t"\
- "cmp "low" , "tmp" \n\t"\
- "cmova %%ecx , "range" \n\t"\
- "sbb %%ecx , %%ecx \n\t"\
- "and %%ecx , "tmp" \n\t"\
- "sub "tmp" , "low" \n\t"\
- "xor %%ecx , "ret" \n\t"
-#else /* HAVE_FAST_CMOV */
-#define BRANCHLESS_GET_CABAC_UPDATE(ret, cabac, statep, low, lowword, range, tmp, tmpbyte)\
- "mov "tmp" , %%ecx \n\t"\
- "shl $17 , "tmp" \n\t"\
- "sub "low" , "tmp" \n\t"\
- "sar $31 , "tmp" \n\t" /*lps_mask*/\
- "sub %%ecx , "range" \n\t" /*RangeLPS - range*/\
- "and "tmp" , "range" \n\t" /*(RangeLPS - range)&lps_mask*/\
- "add %%ecx , "range" \n\t" /*new range*/\
- "shl $17 , %%ecx \n\t"\
- "and "tmp" , %%ecx \n\t"\
- "sub %%ecx , "low" \n\t"\
- "xor "tmp" , "ret" \n\t"
-#endif /* HAVE_FAST_CMOV */
-
-
-#define BRANCHLESS_GET_CABAC(ret, cabac, statep, low, lowword, range, tmp, tmpbyte)\
- "movzbl "statep" , "ret" \n\t"\
- "mov "range" , "tmp" \n\t"\
- "and $0xC0 , "range" \n\t"\
- "movzbl "MANGLE(ff_h264_lps_range)"("ret", "range", 2), "range" \n\t"\
- "sub "range" , "tmp" \n\t"\
- BRANCHLESS_GET_CABAC_UPDATE(ret, cabac, statep, low, lowword, range, tmp, tmpbyte)\
- "movzbl " MANGLE(ff_h264_norm_shift) "("range"), %%ecx \n\t"\
- "shl %%cl , "range" \n\t"\
- "movzbl "MANGLE(ff_h264_mlps_state)"+128("ret"), "tmp" \n\t"\
- "mov "tmpbyte" , "statep" \n\t"\
- "shl %%cl , "low" \n\t"\
- "test "lowword" , "lowword" \n\t"\
- " jnz 1f \n\t"\
- "mov "BYTE"("cabac"), %%"REG_c" \n\t"\
- "movzwl (%%"REG_c") , "tmp" \n\t"\
- "bswap "tmp" \n\t"\
- "shr $15 , "tmp" \n\t"\
- "sub $0xFFFF , "tmp" \n\t"\
- "add $2 , %%"REG_c" \n\t"\
- "mov %%"REG_c" , "BYTE "("cabac") \n\t"\
- "lea -1("low") , %%ecx \n\t"\
- "xor "low" , %%ecx \n\t"\
- "shr $15 , %%ecx \n\t"\
- "movzbl " MANGLE(ff_h264_norm_shift) "(%%ecx), %%ecx \n\t"\
- "neg %%ecx \n\t"\
- "add $7 , %%ecx \n\t"\
- "shl %%cl , "tmp" \n\t"\
- "add "tmp" , "low" \n\t"\
- "1: \n\t"
-
- asm volatile(
- "movl "RANGE "(%2), %%esi \n\t"
- "movl "LOW "(%2), %%ebx \n\t"
- BRANCHLESS_GET_CABAC("%0", "%2", "(%1)", "%%ebx", "%%bx", "%%esi", "%%edx", "%%dl")
- "movl %%esi, "RANGE "(%2) \n\t"
- "movl %%ebx, "LOW "(%2) \n\t"
-
- :"=&a"(bit)
- :"r"(state), "r"(c)
- : "%"REG_c, "%ebx", "%edx", "%esi", "memory"
- );
- bit&=1;
-#endif /* BRANCHLESS_CABAC_DECODER */
-#else /* defined(ARCH_X86) && !(defined(PIC) && defined(__GNUC__)) */
- int s = *state;
- int RangeLPS= ff_h264_lps_range[2*(c->range&0xC0) + s];
- int bit, lps_mask attribute_unused;
-
- c->range -= RangeLPS;
-#ifndef BRANCHLESS_CABAC_DECODER
- if(c->low < (c->range<<(CABAC_BITS+1))){
- bit= s&1;
- *state= ff_h264_mps_state[s];
- renorm_cabac_decoder_once(c);
- }else{
- bit= ff_h264_norm_shift[RangeLPS];
- c->low -= (c->range<<(CABAC_BITS+1));
- *state= ff_h264_lps_state[s];
- c->range = RangeLPS<<bit;
- c->low <<= bit;
- bit= (s&1)^1;
-
- if(!(c->low & CABAC_MASK)){
- refill2(c);
- }
- }
-#else /* BRANCHLESS_CABAC_DECODER */
- lps_mask= ((c->range<<(CABAC_BITS+1)) - c->low)>>31;
-
- c->low -= (c->range<<(CABAC_BITS+1)) & lps_mask;
- c->range += (RangeLPS - c->range) & lps_mask;
-
- s^=lps_mask;
- *state= (ff_h264_mlps_state+128)[s];
- bit= s&1;
-
- lps_mask= ff_h264_norm_shift[c->range];
- c->range<<= lps_mask;
- c->low <<= lps_mask;
- if(!(c->low & CABAC_MASK))
- refill2(c);
-#endif /* BRANCHLESS_CABAC_DECODER */
-#endif /* defined(ARCH_X86) && !(defined(PIC) && defined(__GNUC__)) */
- return bit;
-}
-
-static int __attribute((noinline)) get_cabac_noinline(CABACContext *c, uint8_t * const state){
- return get_cabac_inline(c,state);
-}
-
-static int get_cabac(CABACContext *c, uint8_t * const state){
- return get_cabac_inline(c,state);
-}
-
-static int get_cabac_bypass(CABACContext *c){
-#if 0 //not faster
- int bit;
- asm volatile(
- "movl "RANGE "(%1), %%ebx \n\t"
- "movl "LOW "(%1), %%eax \n\t"
- "shl $17, %%ebx \n\t"
- "add %%eax, %%eax \n\t"
- "sub %%ebx, %%eax \n\t"
- "cdq \n\t"
- "and %%edx, %%ebx \n\t"
- "add %%ebx, %%eax \n\t"
- "test %%ax, %%ax \n\t"
- " jnz 1f \n\t"
- "movl "BYTE "(%1), %%"REG_b" \n\t"
- "subl $0xFFFF, %%eax \n\t"
- "movzwl (%%"REG_b"), %%ecx \n\t"
- "bswap %%ecx \n\t"
- "shrl $15, %%ecx \n\t"
- "addl $2, %%"REG_b" \n\t"
- "addl %%ecx, %%eax \n\t"
- "movl %%"REG_b", "BYTE "(%1) \n\t"
- "1: \n\t"
- "movl %%eax, "LOW "(%1) \n\t"
-
- :"=&d"(bit)
- :"r"(c)
- : "%eax", "%"REG_b, "%ecx", "memory"
- );
- return bit+1;
-#else
- int range;
- c->low += c->low;
-
- if(!(c->low & CABAC_MASK))
- refill(c);
-
- range= c->range<<(CABAC_BITS+1);
- if(c->low < range){
- return 0;
- }else{
- c->low -= range;
- return 1;
- }
-#endif
-}
-
-
-static av_always_inline int get_cabac_bypass_sign(CABACContext *c, int val){
-#if defined(ARCH_X86) && !(defined(PIC) && defined(__GNUC__))
- asm volatile(
- "movl "RANGE "(%1), %%ebx \n\t"
- "movl "LOW "(%1), %%eax \n\t"
- "shl $17, %%ebx \n\t"
- "add %%eax, %%eax \n\t"
- "sub %%ebx, %%eax \n\t"
- "cdq \n\t"
- "and %%edx, %%ebx \n\t"
- "add %%ebx, %%eax \n\t"
- "xor %%edx, %%ecx \n\t"
- "sub %%edx, %%ecx \n\t"
- "test %%ax, %%ax \n\t"
- " jnz 1f \n\t"
- "mov "BYTE "(%1), %%"REG_b" \n\t"
- "subl $0xFFFF, %%eax \n\t"
- "movzwl (%%"REG_b"), %%edx \n\t"
- "bswap %%edx \n\t"
- "shrl $15, %%edx \n\t"
- "add $2, %%"REG_b" \n\t"
- "addl %%edx, %%eax \n\t"
- "mov %%"REG_b", "BYTE "(%1) \n\t"
- "1: \n\t"
- "movl %%eax, "LOW "(%1) \n\t"
-
- :"+c"(val)
- :"r"(c)
- : "%eax", "%"REG_b, "%edx", "memory"
- );
- return val;
-#else
- int range, mask;
- c->low += c->low;
-
- if(!(c->low & CABAC_MASK))
- refill(c);
-
- range= c->range<<(CABAC_BITS+1);
- c->low -= range;
- mask= c->low >> 31;
- range &= mask;
- c->low += range;
- return (val^mask)-mask;
-#endif
-}
-
-//FIXME the x86 code from this file should be moved into i386/h264 or cabac something.c/h (note ill kill you if you move my code away from under my fingers before iam finished with it!)
-//FIXME use some macros to avoid duplicatin get_cabac (cant be done yet as that would make optimization work hard)
-#if defined(ARCH_X86) && !(defined(PIC) && defined(__GNUC__))
-static int decode_significance_x86(CABACContext *c, int max_coeff, uint8_t *significant_coeff_ctx_base, int *index){
- void *end= significant_coeff_ctx_base + max_coeff - 1;
- int minusstart= -(int)significant_coeff_ctx_base;
- int minusindex= 4-(int)index;
- int coeff_count;
- asm volatile(
- "movl "RANGE "(%3), %%esi \n\t"
- "movl "LOW "(%3), %%ebx \n\t"
-
- "2: \n\t"
-
- BRANCHLESS_GET_CABAC("%%edx", "%3", "(%1)", "%%ebx", "%%bx", "%%esi", "%%eax", "%%al")
-
- "test $1, %%edx \n\t"
- " jz 3f \n\t"
-
- BRANCHLESS_GET_CABAC("%%edx", "%3", "61(%1)", "%%ebx", "%%bx", "%%esi", "%%eax", "%%al")
-
- "mov %2, %%"REG_a" \n\t"
- "movl %4, %%ecx \n\t"
- "add %1, %%"REG_c" \n\t"
- "movl %%ecx, (%%"REG_a") \n\t"
-
- "test $1, %%edx \n\t"
- " jnz 4f \n\t"
-
- "add $4, %%"REG_a" \n\t"
- "mov %%"REG_a", %2 \n\t"
-
- "3: \n\t"
- "add $1, %1 \n\t"
- "cmp %5, %1 \n\t"
- " jb 2b \n\t"
- "mov %2, %%"REG_a" \n\t"
- "movl %4, %%ecx \n\t"
- "add %1, %%"REG_c" \n\t"
- "movl %%ecx, (%%"REG_a") \n\t"
- "4: \n\t"
- "add %6, %%eax \n\t"
- "shr $2, %%eax \n\t"
-
- "movl %%esi, "RANGE "(%3) \n\t"
- "movl %%ebx, "LOW "(%3) \n\t"
- :"=&a"(coeff_count), "+r"(significant_coeff_ctx_base), "+m"(index)\
- :"r"(c), "m"(minusstart), "m"(end), "m"(minusindex)\
- : "%"REG_c, "%ebx", "%edx", "%esi", "memory"\
- );
- return coeff_count;
-}
-
-static int decode_significance_8x8_x86(CABACContext *c, uint8_t *significant_coeff_ctx_base, int *index, uint8_t *sig_off){
- int minusindex= 4-(int)index;
- int coeff_count;
- long last=0;
- asm volatile(
- "movl "RANGE "(%3), %%esi \n\t"
- "movl "LOW "(%3), %%ebx \n\t"
-
- "mov %1, %%"REG_D" \n\t"
- "2: \n\t"
-
- "mov %6, %%"REG_a" \n\t"
- "movzbl (%%"REG_a", %%"REG_D"), %%edi \n\t"
- "add %5, %%"REG_D" \n\t"
-
- BRANCHLESS_GET_CABAC("%%edx", "%3", "(%%"REG_D")", "%%ebx", "%%bx", "%%esi", "%%eax", "%%al")
-
- "mov %1, %%edi \n\t"
- "test $1, %%edx \n\t"
- " jz 3f \n\t"
-
- "movzbl "MANGLE(last_coeff_flag_offset_8x8)"(%%edi), %%edi\n\t"
- "add %5, %%"REG_D" \n\t"
-
- BRANCHLESS_GET_CABAC("%%edx", "%3", "15(%%"REG_D")", "%%ebx", "%%bx", "%%esi", "%%eax", "%%al")
-
- "mov %2, %%"REG_a" \n\t"
- "mov %1, %%edi \n\t"
- "movl %%edi, (%%"REG_a") \n\t"
-
- "test $1, %%edx \n\t"
- " jnz 4f \n\t"
-
- "add $4, %%"REG_a" \n\t"
- "mov %%"REG_a", %2 \n\t"
-
- "3: \n\t"
- "addl $1, %%edi \n\t"
- "mov %%edi, %1 \n\t"
- "cmpl $63, %%edi \n\t"
- " jb 2b \n\t"
- "mov %2, %%"REG_a" \n\t"
- "movl %%edi, (%%"REG_a") \n\t"
- "4: \n\t"
- "addl %4, %%eax \n\t"
- "shr $2, %%eax \n\t"
-
- "movl %%esi, "RANGE "(%3) \n\t"
- "movl %%ebx, "LOW "(%3) \n\t"
- :"=&a"(coeff_count),"+m"(last), "+m"(index)\
- :"r"(c), "m"(minusindex), "m"(significant_coeff_ctx_base), "m"(sig_off)\
- : "%"REG_c, "%ebx", "%edx", "%esi", "%"REG_D, "memory"\
- );
- return coeff_count;
-}
-#endif /* defined(ARCH_X86) && !(defined(PIC) && defined(__GNUC__)) */
-
-/**
- *
- * @return the number of bytes read or 0 if no end
- */
-static int get_cabac_terminate(CABACContext *c){
- c->range -= 2;
- if(c->low < c->range<<(CABAC_BITS+1)){
- renorm_cabac_decoder_once(c);
- return 0;
- }else{
- return c->bytestream - c->bytestream_start;
- }
-}
-
-/**
- * get (truncated) unnary binarization.
- */
-static int get_cabac_u(CABACContext *c, uint8_t * state, int max, int max_index, int truncated){
- int i;
-
- for(i=0; i<max; i++){
- if(get_cabac(c, state)==0)
- return i;
-
- if(i< max_index) state++;
- }
-
- return truncated ? max : -1;
-}
-
-/**
- * get unary exp golomb k-th order binarization.
- */
-static int get_cabac_ueg(CABACContext *c, uint8_t * state, int max, int is_signed, int k, int max_index){
- int i, v;
- int m= 1<<k;
-
- if(get_cabac(c, state)==0)
- return 0;
-
- if(0 < max_index) state++;
-
- for(i=1; i<max; i++){
- if(get_cabac(c, state)==0){
- if(is_signed && get_cabac_bypass(c)){
- return -i;
- }else
- return i;
- }
-
- if(i < max_index) state++;
- }
-
- while(get_cabac_bypass(c)){
- i+= m;
- m+= m;
- }
-
- v=0;
- while(m>>=1){
- v+= v + get_cabac_bypass(c);
- }
- i += v;
-
- if(is_signed && get_cabac_bypass(c)){
- return -i;
- }else
- return i;
-}
diff --git a/src/libffmpeg/libavcodec/cavs.c b/src/libffmpeg/libavcodec/cavs.c
deleted file mode 100644
index ee862bbc7..000000000
--- a/src/libffmpeg/libavcodec/cavs.c
+++ /dev/null
@@ -1,1540 +0,0 @@
-/*
- * Chinese AVS video (AVS1-P2, JiZhun profile) decoder.
- * Copyright (c) 2006 Stefan Gehrer <stefan.gehrer@gmx.de>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have 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 cavs.c
- * Chinese AVS video (AVS1-P2, JiZhun profile) decoder
- * @author Stefan Gehrer <stefan.gehrer@gmx.de>
- */
-
-#include "avcodec.h"
-#include "bitstream.h"
-#include "golomb.h"
-#include "mpegvideo.h"
-#include "cavsdata.h"
-
-#ifdef CONFIG_CAVS_DECODER
-typedef struct {
- MpegEncContext s;
- Picture picture; ///< currently decoded frame
- Picture DPB[2]; ///< reference frames
- int dist[2]; ///< temporal distances from current frame to ref frames
- int profile, level;
- int aspect_ratio;
- int mb_width, mb_height;
- int pic_type;
- int progressive;
- int pic_structure;
- int skip_mode_flag; ///< select between skip_count or one skip_flag per MB
- int loop_filter_disable;
- int alpha_offset, beta_offset;
- int ref_flag;
- int mbx, mby; ///< macroblock coordinates
- int flags; ///< availability flags of neighbouring macroblocks
- int stc; ///< last start code
- uint8_t *cy, *cu, *cv; ///< current MB sample pointers
- int left_qp;
- uint8_t *top_qp;
-
- /** mv motion vector cache
- 0: D3 B2 B3 C2
- 4: A1 X0 X1 -
- 8: A3 X2 X3 -
-
- X are the vectors in the current macroblock (5,6,9,10)
- A is the macroblock to the left (4,8)
- B is the macroblock to the top (1,2)
- C is the macroblock to the top-right (3)
- D is the macroblock to the top-left (0)
-
- the same is repeated for backward motion vectors */
- vector_t mv[2*4*3];
- vector_t *top_mv[2];
- vector_t *col_mv;
-
- /** luma pred mode cache
- 0: -- B2 B3
- 3: A1 X0 X1
- 6: A3 X2 X3 */
- int pred_mode_Y[3*3];
- int *top_pred_Y;
- int l_stride, c_stride;
- int luma_scan[4];
- int qp;
- int qp_fixed;
- int cbp;
- ScanTable scantable;
-
- /** intra prediction is done with un-deblocked samples
- they are saved here before deblocking the MB */
- uint8_t *top_border_y, *top_border_u, *top_border_v;
- uint8_t left_border_y[26], left_border_u[10], left_border_v[10];
- uint8_t intern_border_y[26];
- uint8_t topleft_border_y, topleft_border_u, topleft_border_v;
-
- void (*intra_pred_l[8])(uint8_t *d,uint8_t *top,uint8_t *left,int stride);
- void (*intra_pred_c[7])(uint8_t *d,uint8_t *top,uint8_t *left,int stride);
- uint8_t *col_type_base;
- uint8_t *col_type;
-
- /* scaling factors for MV prediction */
- int sym_factor; ///< for scaling in symmetrical B block
- int direct_den[2]; ///< for scaling in direct B block
- int scale_den[2]; ///< for scaling neighbouring MVs
-
- int got_keyframe;
- DCTELEM *block;
-} AVSContext;
-
-/*****************************************************************************
- *
- * in-loop deblocking filter
- *
- ****************************************************************************/
-
-static inline int get_bs(vector_t *mvP, vector_t *mvQ, int b) {
- if((mvP->ref == REF_INTRA) || (mvQ->ref == REF_INTRA))
- return 2;
- if( (abs(mvP->x - mvQ->x) >= 4) || (abs(mvP->y - mvQ->y) >= 4) )
- return 1;
- if(b){
- mvP += MV_BWD_OFFS;
- mvQ += MV_BWD_OFFS;
- if( (abs(mvP->x - mvQ->x) >= 4) || (abs(mvP->y - mvQ->y) >= 4) )
- return 1;
- }else{
- if(mvP->ref != mvQ->ref)
- return 1;
- }
- return 0;
-}
-
-#define SET_PARAMS \
- alpha = alpha_tab[clip(qp_avg + h->alpha_offset,0,63)]; \
- beta = beta_tab[clip(qp_avg + h->beta_offset, 0,63)]; \
- tc = tc_tab[clip(qp_avg + h->alpha_offset,0,63)];
-
-/**
- * in-loop deblocking filter for a single macroblock
- *
- * boundary strength (bs) mapping:
- *
- * --4---5--
- * 0 2 |
- * | 6 | 7 |
- * 1 3 |
- * ---------
- *
- */
-static void filter_mb(AVSContext *h, enum mb_t mb_type) {
- DECLARE_ALIGNED_8(uint8_t, bs[8]);
- int qp_avg, alpha, beta, tc;
- int i;
-
- /* save un-deblocked lines */
- h->topleft_border_y = h->top_border_y[h->mbx*16+15];
- h->topleft_border_u = h->top_border_u[h->mbx*10+8];
- h->topleft_border_v = h->top_border_v[h->mbx*10+8];
- memcpy(&h->top_border_y[h->mbx*16], h->cy + 15* h->l_stride,16);
- memcpy(&h->top_border_u[h->mbx*10+1], h->cu + 7* h->c_stride,8);
- memcpy(&h->top_border_v[h->mbx*10+1], h->cv + 7* h->c_stride,8);
- for(i=0;i<8;i++) {
- h->left_border_y[i*2+1] = *(h->cy + 15 + (i*2+0)*h->l_stride);
- h->left_border_y[i*2+2] = *(h->cy + 15 + (i*2+1)*h->l_stride);
- h->left_border_u[i+1] = *(h->cu + 7 + i*h->c_stride);
- h->left_border_v[i+1] = *(h->cv + 7 + i*h->c_stride);
- }
- if(!h->loop_filter_disable) {
- /* determine bs */
- if(mb_type == I_8X8)
- *((uint64_t *)bs) = 0x0202020202020202ULL;
- else{
- *((uint64_t *)bs) = 0;
- if(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);
- }
- if(partition_flags[mb_type] & SPLITH){
- bs[6] = get_bs(&h->mv[MV_FWD_X0], &h->mv[MV_FWD_X2], mb_type > P_8X8);
- bs[7] = get_bs(&h->mv[MV_FWD_X1], &h->mv[MV_FWD_X3], mb_type > P_8X8);
- }
- bs[0] = get_bs(&h->mv[MV_FWD_A1], &h->mv[MV_FWD_X0], mb_type > P_8X8);
- bs[1] = get_bs(&h->mv[MV_FWD_A3], &h->mv[MV_FWD_X2], mb_type > P_8X8);
- 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(h->flags & A_AVAIL) {
- qp_avg = (h->qp + h->left_qp + 1) >> 1;
- SET_PARAMS;
- h->s.dsp.cavs_filter_lv(h->cy,h->l_stride,alpha,beta,tc,bs[0],bs[1]);
- h->s.dsp.cavs_filter_cv(h->cu,h->c_stride,alpha,beta,tc,bs[0],bs[1]);
- h->s.dsp.cavs_filter_cv(h->cv,h->c_stride,alpha,beta,tc,bs[0],bs[1]);
- }
- qp_avg = h->qp;
- SET_PARAMS;
- h->s.dsp.cavs_filter_lv(h->cy + 8,h->l_stride,alpha,beta,tc,bs[2],bs[3]);
- h->s.dsp.cavs_filter_lh(h->cy + 8*h->l_stride,h->l_stride,alpha,beta,tc,
- bs[6],bs[7]);
-
- if(h->flags & B_AVAIL) {
- qp_avg = (h->qp + h->top_qp[h->mbx] + 1) >> 1;
- SET_PARAMS;
- h->s.dsp.cavs_filter_lh(h->cy,h->l_stride,alpha,beta,tc,bs[4],bs[5]);
- h->s.dsp.cavs_filter_ch(h->cu,h->c_stride,alpha,beta,tc,bs[4],bs[5]);
- h->s.dsp.cavs_filter_ch(h->cv,h->c_stride,alpha,beta,tc,bs[4],bs[5]);
- }
- }
- }
- h->left_qp = h->qp;
- h->top_qp[h->mbx] = h->qp;
-}
-
-#undef SET_PARAMS
-
-/*****************************************************************************
- *
- * spatial intra prediction
- *
- ****************************************************************************/
-
-static inline void load_intra_pred_luma(AVSContext *h, uint8_t *top,
- uint8_t **left, int block) {
- int i;
-
- switch(block) {
- case 0:
- *left = h->left_border_y;
- h->left_border_y[0] = h->left_border_y[1];
- memset(&h->left_border_y[17],h->left_border_y[16],9);
- memcpy(&top[1],&h->top_border_y[h->mbx*16],16);
- top[17] = top[16];
- top[0] = top[1];
- if((h->flags & A_AVAIL) && (h->flags & B_AVAIL))
- h->left_border_y[0] = top[0] = h->topleft_border_y;
- break;
- case 1:
- *left = h->intern_border_y;
- for(i=0;i<8;i++)
- h->intern_border_y[i+1] = *(h->cy + 7 + i*h->l_stride);
- memset(&h->intern_border_y[9],h->intern_border_y[8],9);
- h->intern_border_y[0] = h->intern_border_y[1];
- memcpy(&top[1],&h->top_border_y[h->mbx*16+8],8);
- if(h->flags & C_AVAIL)
- memcpy(&top[9],&h->top_border_y[(h->mbx + 1)*16],8);
- else
- memset(&top[9],top[8],9);
- top[17] = top[16];
- top[0] = top[1];
- if(h->flags & B_AVAIL)
- h->intern_border_y[0] = top[0] = h->top_border_y[h->mbx*16+7];
- break;
- case 2:
- *left = &h->left_border_y[8];
- memcpy(&top[1],h->cy + 7*h->l_stride,16);
- top[17] = top[16];
- top[0] = top[1];
- if(h->flags & A_AVAIL)
- top[0] = h->left_border_y[8];
- break;
- case 3:
- *left = &h->intern_border_y[8];
- for(i=0;i<8;i++)
- h->intern_border_y[i+9] = *(h->cy + 7 + (i+8)*h->l_stride);
- memset(&h->intern_border_y[17],h->intern_border_y[16],9);
- memcpy(&top[0],h->cy + 7 + 7*h->l_stride,9);
- memset(&top[9],top[8],9);
- break;
- }
-}
-
-static void intra_pred_vert(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
- int y;
- uint64_t a = unaligned64(&top[1]);
- for(y=0;y<8;y++) {
- *((uint64_t *)(d+y*stride)) = a;
- }
-}
-
-static void intra_pred_horiz(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
- int y;
- uint64_t a;
- for(y=0;y<8;y++) {
- a = left[y+1] * 0x0101010101010101ULL;
- *((uint64_t *)(d+y*stride)) = a;
- }
-}
-
-static void intra_pred_dc_128(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
- int y;
- uint64_t a = 0x8080808080808080ULL;
- for(y=0;y<8;y++)
- *((uint64_t *)(d+y*stride)) = a;
-}
-
-static void intra_pred_plane(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
- int x,y,ia;
- int ih = 0;
- int iv = 0;
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
-
- for(x=0; x<4; x++) {
- ih += (x+1)*(top[5+x]-top[3-x]);
- iv += (x+1)*(left[5+x]-left[3-x]);
- }
- ia = (top[8]+left[8])<<4;
- ih = (17*ih+16)>>5;
- iv = (17*iv+16)>>5;
- for(y=0; y<8; y++)
- for(x=0; x<8; x++)
- d[y*stride+x] = cm[(ia+(x-3)*ih+(y-3)*iv+16)>>5];
-}
-
-#define LOWPASS(ARRAY,INDEX) \
- (( ARRAY[(INDEX)-1] + 2*ARRAY[(INDEX)] + ARRAY[(INDEX)+1] + 2) >> 2)
-
-static void intra_pred_lp(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
- int x,y;
- for(y=0; y<8; y++)
- for(x=0; x<8; x++)
- d[y*stride+x] = (LOWPASS(top,x+1) + LOWPASS(left,y+1)) >> 1;
-}
-
-static void intra_pred_down_left(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
- int x,y;
- for(y=0; y<8; y++)
- for(x=0; x<8; x++)
- d[y*stride+x] = (LOWPASS(top,x+y+2) + LOWPASS(left,x+y+2)) >> 1;
-}
-
-static void intra_pred_down_right(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
- int x,y;
- for(y=0; y<8; y++)
- for(x=0; x<8; x++)
- if(x==y)
- d[y*stride+x] = (left[1]+2*top[0]+top[1]+2)>>2;
- else if(x>y)
- d[y*stride+x] = LOWPASS(top,x-y);
- else
- d[y*stride+x] = LOWPASS(left,y-x);
-}
-
-static void intra_pred_lp_left(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
- int x,y;
- for(y=0; y<8; y++)
- for(x=0; x<8; x++)
- d[y*stride+x] = LOWPASS(left,y+1);
-}
-
-static void intra_pred_lp_top(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
- int x,y;
- for(y=0; y<8; y++)
- for(x=0; x<8; x++)
- d[y*stride+x] = LOWPASS(top,x+1);
-}
-
-#undef LOWPASS
-
-static inline void modify_pred(const int_fast8_t *mod_table, int *mode) {
- *mode = mod_table[*mode];
- if(*mode < 0) {
- av_log(NULL, AV_LOG_ERROR, "Illegal intra prediction mode\n");
- *mode = 0;
- }
-}
-
-/*****************************************************************************
- *
- * motion compensation
- *
- ****************************************************************************/
-
-static inline void mc_dir_part(AVSContext *h,Picture *pic,int square,
- int chroma_height,int delta,int list,uint8_t *dest_y,
- uint8_t *dest_cb,uint8_t *dest_cr,int src_x_offset,
- int src_y_offset,qpel_mc_func *qpix_op,
- h264_chroma_mc_func chroma_op,vector_t *mv){
- MpegEncContext * const s = &h->s;
- const int mx= mv->x + src_x_offset*8;
- const int my= mv->y + src_y_offset*8;
- const int luma_xy= (mx&3) + ((my&3)<<2);
- uint8_t * src_y = pic->data[0] + (mx>>2) + (my>>2)*h->l_stride;
- uint8_t * src_cb= pic->data[1] + (mx>>3) + (my>>3)*h->c_stride;
- uint8_t * src_cr= pic->data[2] + (mx>>3) + (my>>3)*h->c_stride;
- int extra_width= 0; //(s->flags&CODEC_FLAG_EMU_EDGE) ? 0 : 16;
- int extra_height= extra_width;
- int emu=0;
- const int full_mx= mx>>2;
- const int full_my= my>>2;
- const int pic_width = 16*h->mb_width;
- const int pic_height = 16*h->mb_height;
-
- if(!pic->data[0])
- return;
- if(mx&7) extra_width -= 3;
- if(my&7) extra_height -= 3;
-
- if( full_mx < 0-extra_width
- || full_my < 0-extra_height
- || full_mx + 16/*FIXME*/ > pic_width + extra_width
- || full_my + 16/*FIXME*/ > pic_height + extra_height){
- ff_emulated_edge_mc(s->edge_emu_buffer, src_y - 2 - 2*h->l_stride, h->l_stride,
- 16+5, 16+5/*FIXME*/, full_mx-2, full_my-2, pic_width, pic_height);
- src_y= s->edge_emu_buffer + 2 + 2*h->l_stride;
- emu=1;
- }
-
- qpix_op[luma_xy](dest_y, src_y, h->l_stride); //FIXME try variable height perhaps?
- if(!square){
- qpix_op[luma_xy](dest_y + delta, src_y + delta, h->l_stride);
- }
-
- if(emu){
- ff_emulated_edge_mc(s->edge_emu_buffer, src_cb, h->c_stride,
- 9, 9/*FIXME*/, (mx>>3), (my>>3), pic_width>>1, pic_height>>1);
- src_cb= s->edge_emu_buffer;
- }
- chroma_op(dest_cb, src_cb, h->c_stride, chroma_height, mx&7, my&7);
-
- if(emu){
- ff_emulated_edge_mc(s->edge_emu_buffer, src_cr, h->c_stride,
- 9, 9/*FIXME*/, (mx>>3), (my>>3), pic_width>>1, pic_height>>1);
- src_cr= s->edge_emu_buffer;
- }
- chroma_op(dest_cr, src_cr, h->c_stride, chroma_height, mx&7, my&7);
-}
-
-static inline void mc_part_std(AVSContext *h,int square,int chroma_height,int delta,
- uint8_t *dest_y,uint8_t *dest_cb,uint8_t *dest_cr,
- int x_offset, int y_offset,qpel_mc_func *qpix_put,
- h264_chroma_mc_func chroma_put,qpel_mc_func *qpix_avg,
- h264_chroma_mc_func chroma_avg, vector_t *mv){
- qpel_mc_func *qpix_op= qpix_put;
- h264_chroma_mc_func chroma_op= chroma_put;
-
- dest_y += 2*x_offset + 2*y_offset*h->l_stride;
- dest_cb += x_offset + y_offset*h->c_stride;
- dest_cr += x_offset + y_offset*h->c_stride;
- x_offset += 8*h->mbx;
- y_offset += 8*h->mby;
-
- if(mv->ref >= 0){
- Picture *ref= &h->DPB[mv->ref];
- mc_dir_part(h, ref, square, chroma_height, delta, 0,
- dest_y, dest_cb, dest_cr, x_offset, y_offset,
- qpix_op, chroma_op, mv);
-
- qpix_op= qpix_avg;
- chroma_op= chroma_avg;
- }
-
- if((mv+MV_BWD_OFFS)->ref >= 0){
- Picture *ref= &h->DPB[0];
- mc_dir_part(h, ref, square, chroma_height, delta, 1,
- dest_y, dest_cb, dest_cr, x_offset, y_offset,
- qpix_op, chroma_op, mv+MV_BWD_OFFS);
- }
-}
-
-static void inter_pred(AVSContext *h, enum mb_t mb_type) {
- if(partition_flags[mb_type] == 0){ // 16x16
- mc_part_std(h, 1, 8, 0, h->cy, h->cu, h->cv, 0, 0,
- h->s.dsp.put_cavs_qpel_pixels_tab[0],
- h->s.dsp.put_h264_chroma_pixels_tab[0],
- h->s.dsp.avg_cavs_qpel_pixels_tab[0],
- h->s.dsp.avg_h264_chroma_pixels_tab[0],&h->mv[MV_FWD_X0]);
- }else{
- mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 0, 0,
- h->s.dsp.put_cavs_qpel_pixels_tab[1],
- h->s.dsp.put_h264_chroma_pixels_tab[1],
- h->s.dsp.avg_cavs_qpel_pixels_tab[1],
- h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X0]);
- mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 4, 0,
- h->s.dsp.put_cavs_qpel_pixels_tab[1],
- h->s.dsp.put_h264_chroma_pixels_tab[1],
- h->s.dsp.avg_cavs_qpel_pixels_tab[1],
- h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X1]);
- mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 0, 4,
- h->s.dsp.put_cavs_qpel_pixels_tab[1],
- h->s.dsp.put_h264_chroma_pixels_tab[1],
- h->s.dsp.avg_cavs_qpel_pixels_tab[1],
- h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X2]);
- mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 4, 4,
- h->s.dsp.put_cavs_qpel_pixels_tab[1],
- h->s.dsp.put_h264_chroma_pixels_tab[1],
- h->s.dsp.avg_cavs_qpel_pixels_tab[1],
- h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X3]);
- }
- /* set intra prediction modes to default values */
- 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;
-}
-
-/*****************************************************************************
- *
- * motion vector prediction
- *
- ****************************************************************************/
-
-static inline void set_mvs(vector_t *mv, enum block_t size) {
- switch(size) {
- case BLK_16X16:
- mv[MV_STRIDE ] = mv[0];
- mv[MV_STRIDE+1] = mv[0];
- case BLK_16X8:
- mv[1] = mv[0];
- break;
- case BLK_8X16:
- mv[MV_STRIDE] = mv[0];
- break;
- }
-}
-
-static inline void store_mvs(AVSContext *h) {
- h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + 0] = h->mv[MV_FWD_X0];
- h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + 1] = h->mv[MV_FWD_X1];
- h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + 2] = h->mv[MV_FWD_X2];
- h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + 3] = h->mv[MV_FWD_X3];
-}
-
-static inline void scale_mv(AVSContext *h, int *d_x, int *d_y, vector_t *src, int distp) {
- int den = h->scale_den[src->ref];
-
- *d_x = (src->x*distp*den + 256 + (src->x>>31)) >> 9;
- *d_y = (src->y*distp*den + 256 + (src->y>>31)) >> 9;
-}
-
-static inline void mv_pred_median(AVSContext *h, vector_t *mvP, vector_t *mvA, vector_t *mvB, vector_t *mvC) {
- int ax, ay, bx, by, cx, cy;
- int len_ab, len_bc, len_ca, len_mid;
-
- /* scale candidates according to their temporal span */
- scale_mv(h, &ax, &ay, mvA, mvP->dist);
- scale_mv(h, &bx, &by, mvB, mvP->dist);
- scale_mv(h, &cx, &cy, mvC, mvP->dist);
- /* find the geometrical median of the three candidates */
- len_ab = abs(ax - bx) + abs(ay - by);
- len_bc = abs(bx - cx) + abs(by - cy);
- len_ca = abs(cx - ax) + abs(cy - ay);
- len_mid = mid_pred(len_ab, len_bc, len_ca);
- if(len_mid == len_ab) {
- mvP->x = cx;
- mvP->y = cy;
- } else if(len_mid == len_bc) {
- mvP->x = ax;
- mvP->y = ay;
- } else {
- mvP->x = bx;
- mvP->y = by;
- }
-}
-
-static inline void mv_pred_direct(AVSContext *h, vector_t *pmv_fw,
- vector_t *col_mv) {
- vector_t *pmv_bw = pmv_fw + MV_BWD_OFFS;
- int den = h->direct_den[col_mv->ref];
- int m = col_mv->x >> 31;
-
- pmv_fw->dist = h->dist[1];
- pmv_bw->dist = h->dist[0];
- pmv_fw->ref = 1;
- pmv_bw->ref = 0;
- /* scale the co-located motion vector according to its temporal span */
- pmv_fw->x = (((den+(den*col_mv->x*pmv_fw->dist^m)-m-1)>>14)^m)-m;
- pmv_bw->x = m-(((den+(den*col_mv->x*pmv_bw->dist^m)-m-1)>>14)^m);
- m = col_mv->y >> 31;
- pmv_fw->y = (((den+(den*col_mv->y*pmv_fw->dist^m)-m-1)>>14)^m)-m;
- pmv_bw->y = m-(((den+(den*col_mv->y*pmv_bw->dist^m)-m-1)>>14)^m);
-}
-
-static inline void mv_pred_sym(AVSContext *h, vector_t *src, enum block_t size) {
- vector_t *dst = src + MV_BWD_OFFS;
-
- /* backward mv is the scaled and negated forward mv */
- dst->x = -((src->x * h->sym_factor + 256) >> 9);
- dst->y = -((src->y * h->sym_factor + 256) >> 9);
- dst->ref = 0;
- dst->dist = h->dist[0];
- set_mvs(dst, size);
-}
-
-static void mv_pred(AVSContext *h, enum mv_loc_t nP, enum mv_loc_t nC,
- enum mv_pred_t mode, enum block_t size, int ref) {
- vector_t *mvP = &h->mv[nP];
- vector_t *mvA = &h->mv[nP-1];
- vector_t *mvB = &h->mv[nP-4];
- vector_t *mvC = &h->mv[nC];
- const vector_t *mvP2 = NULL;
-
- mvP->ref = ref;
- mvP->dist = h->dist[mvP->ref];
- if(mvC->ref == NOT_AVAIL)
- mvC = &h->mv[nP-5]; // set to top-left (mvD)
- if((mode == MV_PRED_PSKIP) &&
- ((mvA->ref == NOT_AVAIL) || (mvB->ref == NOT_AVAIL) ||
- ((mvA->x | mvA->y | mvA->ref) == 0) ||
- ((mvB->x | mvB->y | mvB->ref) == 0) )) {
- mvP2 = &un_mv;
- /* if there is only one suitable candidate, take it */
- } else if((mvA->ref >= 0) && (mvB->ref < 0) && (mvC->ref < 0)) {
- mvP2= mvA;
- } else if((mvA->ref < 0) && (mvB->ref >= 0) && (mvC->ref < 0)) {
- mvP2= mvB;
- } else if((mvA->ref < 0) && (mvB->ref < 0) && (mvC->ref >= 0)) {
- mvP2= mvC;
- } else if(mode == MV_PRED_LEFT && mvA->ref == ref){
- mvP2= mvA;
- } else if(mode == MV_PRED_TOP && mvB->ref == ref){
- mvP2= mvB;
- } else if(mode == MV_PRED_TOPRIGHT && mvC->ref == ref){
- mvP2= mvC;
- }
- if(mvP2){
- mvP->x = mvP2->x;
- mvP->y = mvP2->y;
- }else
- mv_pred_median(h, mvP, mvA, mvB, mvC);
-
- if(mode < MV_PRED_PSKIP) {
- mvP->x += get_se_golomb(&h->s.gb);
- mvP->y += get_se_golomb(&h->s.gb);
- }
- set_mvs(mvP,size);
-}
-
-/*****************************************************************************
- *
- * residual data decoding
- *
- ****************************************************************************/
-
-/** kth-order exponential golomb code */
-static inline int get_ue_code(GetBitContext *gb, int order) {
- if(order) {
- int ret = get_ue_golomb(gb) << order;
- return ret + get_bits(gb,order);
- }
- return get_ue_golomb(gb);
-}
-
-/**
- * decode coefficients from one 8x8 block, dequantize, inverse transform
- * and add them to sample block
- * @param r pointer to 2D VLC table
- * @param esc_golomb_order escape codes are k-golomb with this order k
- * @param qp quantizer
- * @param dst location of sample block
- * @param stride line stride in frame buffer
- */
-static int decode_residual_block(AVSContext *h, GetBitContext *gb,
- const residual_vlc_t *r, int esc_golomb_order,
- int qp, uint8_t *dst, int stride) {
- int i,pos = -1;
- int level_code, esc_code, level, run, mask;
- int level_buf[64];
- int run_buf[64];
- int dqm = dequant_mul[qp];
- int dqs = dequant_shift[qp];
- int dqa = 1 << (dqs - 1);
- const uint8_t *scantab = h->scantable.permutated;
- DCTELEM *block = h->block;
-
- for(i=0;i<65;i++) {
- level_code = get_ue_code(gb,r->golomb_order);
- if(level_code >= ESCAPE_CODE) {
- run = ((level_code - ESCAPE_CODE) >> 1) + 1;
- esc_code = get_ue_code(gb,esc_golomb_order);
- level = esc_code + (run > r->max_run ? 1 : r->level_add[run]);
- while(level > r->inc_limit)
- r++;
- mask = -(level_code & 1);
- level = (level^mask) - mask;
- } else {
- level = r->rltab[level_code][0];
- if(!level) //end of block signal
- break;
- run = r->rltab[level_code][1];
- r += r->rltab[level_code][2];
- }
- level_buf[i] = level;
- run_buf[i] = run;
- }
- /* inverse scan and dequantization */
- while(--i >= 0){
- pos += run_buf[i];
- if(pos > 63) {
- av_log(h->s.avctx, AV_LOG_ERROR,
- "position out of block bounds at pic %d MB(%d,%d)\n",
- h->picture.poc, h->mbx, h->mby);
- return -1;
- }
- block[scantab[pos]] = (level_buf[i]*dqm + dqa) >> dqs;
- }
- h->s.dsp.cavs_idct8_add(dst,block,stride);
- return 0;
-}
-
-
-static inline void decode_residual_chroma(AVSContext *h) {
- if(h->cbp & (1<<4))
- decode_residual_block(h,&h->s.gb,chroma_2dvlc,0, chroma_qp[h->qp],
- h->cu,h->c_stride);
- if(h->cbp & (1<<5))
- decode_residual_block(h,&h->s.gb,chroma_2dvlc,0, chroma_qp[h->qp],
- h->cv,h->c_stride);
-}
-
-static inline int decode_residual_inter(AVSContext *h) {
- int block;
-
- /* get coded block pattern */
- int cbp= get_ue_golomb(&h->s.gb);
- if(cbp > 63){
- av_log(h->s.avctx, AV_LOG_ERROR, "illegal inter cbp\n");
- return -1;
- }
- h->cbp = cbp_tab[cbp][1];
-
- /* get quantizer */
- if(h->cbp && !h->qp_fixed)
- h->qp = (h->qp + get_se_golomb(&h->s.gb)) & 63;
- for(block=0;block<4;block++)
- if(h->cbp & (1<<block))
- decode_residual_block(h,&h->s.gb,inter_2dvlc,0,h->qp,
- h->cy + h->luma_scan[block], h->l_stride);
- decode_residual_chroma(h);
-
- return 0;
-}
-
-/*****************************************************************************
- *
- * macroblock level
- *
- ****************************************************************************/
-
-/**
- * initialise predictors for motion vectors and intra prediction
- */
-static inline void init_mb(AVSContext *h) {
- int i;
-
- /* copy predictors from top line (MB B and C) into cache */
- for(i=0;i<3;i++) {
- h->mv[MV_FWD_B2+i] = h->top_mv[0][h->mbx*2+i];
- h->mv[MV_BWD_B2+i] = h->top_mv[1][h->mbx*2+i];
- }
- h->pred_mode_Y[1] = h->top_pred_Y[h->mbx*2+0];
- h->pred_mode_Y[2] = h->top_pred_Y[h->mbx*2+1];
- /* clear top predictors if MB B is not available */
- if(!(h->flags & B_AVAIL)) {
- h->mv[MV_FWD_B2] = un_mv;
- h->mv[MV_FWD_B3] = un_mv;
- h->mv[MV_BWD_B2] = un_mv;
- h->mv[MV_BWD_B3] = un_mv;
- h->pred_mode_Y[1] = h->pred_mode_Y[2] = NOT_AVAIL;
- h->flags &= ~(C_AVAIL|D_AVAIL);
- } else if(h->mbx) {
- h->flags |= D_AVAIL;
- }
- if(h->mbx == h->mb_width-1) //MB C not available
- h->flags &= ~C_AVAIL;
- /* clear top-right predictors if MB C is not available */
- if(!(h->flags & C_AVAIL)) {
- h->mv[MV_FWD_C2] = un_mv;
- h->mv[MV_BWD_C2] = un_mv;
- }
- /* clear top-left predictors if MB D is not available */
- if(!(h->flags & D_AVAIL)) {
- h->mv[MV_FWD_D3] = un_mv;
- h->mv[MV_BWD_D3] = un_mv;
- }
- /* set pointer for co-located macroblock type */
- h->col_type = &h->col_type_base[h->mby*h->mb_width + h->mbx];
-}
-
-static inline void check_for_slice(AVSContext *h);
-
-/**
- * save predictors for later macroblocks and increase
- * macroblock address
- * @returns 0 if end of frame is reached, 1 otherwise
- */
-static inline int next_mb(AVSContext *h) {
- int i;
-
- h->flags |= A_AVAIL;
- h->cy += 16;
- h->cu += 8;
- h->cv += 8;
- /* copy mvs as predictors to the left */
- for(i=0;i<=20;i+=4)
- h->mv[i] = h->mv[i+2];
- /* copy bottom mvs from cache to top line */
- h->top_mv[0][h->mbx*2+0] = h->mv[MV_FWD_X2];
- h->top_mv[0][h->mbx*2+1] = h->mv[MV_FWD_X3];
- h->top_mv[1][h->mbx*2+0] = h->mv[MV_BWD_X2];
- h->top_mv[1][h->mbx*2+1] = h->mv[MV_BWD_X3];
- /* next MB address */
- h->mbx++;
- if(h->mbx == h->mb_width) { //new mb line
- h->flags = B_AVAIL|C_AVAIL;
- /* clear left pred_modes */
- h->pred_mode_Y[3] = h->pred_mode_Y[6] = NOT_AVAIL;
- /* clear left mv predictors */
- for(i=0;i<=20;i+=4)
- h->mv[i] = un_mv;
- h->mbx = 0;
- h->mby++;
- /* re-calculate sample pointers */
- h->cy = h->picture.data[0] + h->mby*16*h->l_stride;
- h->cu = h->picture.data[1] + h->mby*8*h->c_stride;
- h->cv = h->picture.data[2] + h->mby*8*h->c_stride;
- if(h->mby == h->mb_height) { //frame end
- return 0;
- } else {
- //check_for_slice(h);
- }
- }
- return 1;
-}
-
-static int decode_mb_i(AVSContext *h, int cbp_code) {
- GetBitContext *gb = &h->s.gb;
- int block, pred_mode_uv;
- uint8_t top[18];
- uint8_t *left = NULL;
- uint8_t *d;
-
- init_mb(h);
-
- /* get intra prediction modes from stream */
- for(block=0;block<4;block++) {
- int nA,nB,predpred;
- int pos = scan3x3[block];
-
- nA = h->pred_mode_Y[pos-1];
- nB = h->pred_mode_Y[pos-3];
- predpred = FFMIN(nA,nB);
- if(predpred == NOT_AVAIL) // if either is not available
- predpred = INTRA_L_LP;
- if(!get_bits1(gb)){
- int rem_mode= get_bits(gb, 2);
- predpred = rem_mode + (rem_mode >= predpred);
- }
- h->pred_mode_Y[pos] = predpred;
- }
- pred_mode_uv = get_ue_golomb(gb);
- if(pred_mode_uv > 6) {
- av_log(h->s.avctx, AV_LOG_ERROR, "illegal intra chroma pred mode\n");
- return -1;
- }
-
- /* save pred modes before they get modified */
- h->pred_mode_Y[3] = h->pred_mode_Y[5];
- h->pred_mode_Y[6] = h->pred_mode_Y[8];
- h->top_pred_Y[h->mbx*2+0] = h->pred_mode_Y[7];
- h->top_pred_Y[h->mbx*2+1] = h->pred_mode_Y[8];
-
- /* modify pred modes according to availability of neighbour samples */
- if(!(h->flags & A_AVAIL)) {
- modify_pred(left_modifier_l, &h->pred_mode_Y[4] );
- modify_pred(left_modifier_l, &h->pred_mode_Y[7] );
- modify_pred(left_modifier_c, &pred_mode_uv );
- }
- if(!(h->flags & B_AVAIL)) {
- modify_pred(top_modifier_l, &h->pred_mode_Y[4] );
- modify_pred(top_modifier_l, &h->pred_mode_Y[5] );
- modify_pred(top_modifier_c, &pred_mode_uv );
- }
-
- /* get coded block pattern */
- if(h->pic_type == FF_I_TYPE)
- cbp_code = get_ue_golomb(gb);
- if(cbp_code > 63){
- av_log(h->s.avctx, AV_LOG_ERROR, "illegal intra cbp\n");
- return -1;
- }
- h->cbp = cbp_tab[cbp_code][0];
- if(h->cbp && !h->qp_fixed)
- h->qp = (h->qp + get_se_golomb(gb)) & 63; //qp_delta
-
- /* luma intra prediction interleaved with residual decode/transform/add */
- for(block=0;block<4;block++) {
- d = h->cy + h->luma_scan[block];
- load_intra_pred_luma(h, top, &left, block);
- h->intra_pred_l[h->pred_mode_Y[scan3x3[block]]]
- (d, top, left, h->l_stride);
- if(h->cbp & (1<<block))
- decode_residual_block(h,gb,intra_2dvlc,1,h->qp,d,h->l_stride);
- }
-
- /* chroma intra prediction */
- /* extend borders by one pixel */
- h->left_border_u[9] = h->left_border_u[8];
- h->left_border_v[9] = h->left_border_v[8];
- h->top_border_u[h->mbx*10+9] = h->top_border_u[h->mbx*10+8];
- h->top_border_v[h->mbx*10+9] = h->top_border_v[h->mbx*10+8];
- if(h->mbx && h->mby) {
- h->top_border_u[h->mbx*10] = h->left_border_u[0] = h->topleft_border_u;
- h->top_border_v[h->mbx*10] = h->left_border_v[0] = h->topleft_border_v;
- } else {
- h->left_border_u[0] = h->left_border_u[1];
- h->left_border_v[0] = h->left_border_v[1];
- h->top_border_u[h->mbx*10] = h->top_border_u[h->mbx*10+1];
- h->top_border_v[h->mbx*10] = h->top_border_v[h->mbx*10+1];
- }
- h->intra_pred_c[pred_mode_uv](h->cu, &h->top_border_u[h->mbx*10],
- h->left_border_u, h->c_stride);
- h->intra_pred_c[pred_mode_uv](h->cv, &h->top_border_v[h->mbx*10],
- h->left_border_v, h->c_stride);
-
- decode_residual_chroma(h);
- filter_mb(h,I_8X8);
-
- /* mark motion vectors as intra */
- h->mv[MV_FWD_X0] = intra_mv;
- set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);
- h->mv[MV_BWD_X0] = intra_mv;
- set_mvs(&h->mv[MV_BWD_X0], BLK_16X16);
- if(h->pic_type != FF_B_TYPE)
- *h->col_type = I_8X8;
-
- return 0;
-}
-
-static void decode_mb_p(AVSContext *h, enum mb_t mb_type) {
- GetBitContext *gb = &h->s.gb;
- int ref[4];
-
- init_mb(h);
- switch(mb_type) {
- case P_SKIP:
- mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_PSKIP, BLK_16X16, 0);
- break;
- case P_16X16:
- ref[0] = h->ref_flag ? 0 : get_bits1(gb);
- mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_MEDIAN, BLK_16X16,ref[0]);
- break;
- case P_16X8:
- ref[0] = h->ref_flag ? 0 : get_bits1(gb);
- ref[2] = h->ref_flag ? 0 : get_bits1(gb);
- mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_TOP, BLK_16X8, ref[0]);
- mv_pred(h, MV_FWD_X2, MV_FWD_A1, MV_PRED_LEFT, BLK_16X8, ref[2]);
- break;
- case P_8X16:
- ref[0] = h->ref_flag ? 0 : get_bits1(gb);
- ref[1] = h->ref_flag ? 0 : get_bits1(gb);
- mv_pred(h, MV_FWD_X0, MV_FWD_B3, MV_PRED_LEFT, BLK_8X16, ref[0]);
- mv_pred(h, MV_FWD_X1, MV_FWD_C2, MV_PRED_TOPRIGHT, BLK_8X16, ref[1]);
- break;
- case P_8X8:
- ref[0] = h->ref_flag ? 0 : get_bits1(gb);
- ref[1] = h->ref_flag ? 0 : get_bits1(gb);
- ref[2] = h->ref_flag ? 0 : get_bits1(gb);
- ref[3] = h->ref_flag ? 0 : get_bits1(gb);
- mv_pred(h, MV_FWD_X0, MV_FWD_B3, MV_PRED_MEDIAN, BLK_8X8, ref[0]);
- mv_pred(h, MV_FWD_X1, MV_FWD_C2, MV_PRED_MEDIAN, BLK_8X8, ref[1]);
- mv_pred(h, MV_FWD_X2, MV_FWD_X1, MV_PRED_MEDIAN, BLK_8X8, ref[2]);
- mv_pred(h, MV_FWD_X3, MV_FWD_X0, MV_PRED_MEDIAN, BLK_8X8, ref[3]);
- }
- inter_pred(h, mb_type);
- store_mvs(h);
- if(mb_type != P_SKIP)
- decode_residual_inter(h);
- filter_mb(h,mb_type);
- *h->col_type = mb_type;
-}
-
-static void decode_mb_b(AVSContext *h, enum mb_t mb_type) {
- int block;
- enum sub_mb_t sub_type[4];
- int flags;
-
- init_mb(h);
-
- /* reset all MVs */
- h->mv[MV_FWD_X0] = dir_mv;
- set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);
- h->mv[MV_BWD_X0] = dir_mv;
- set_mvs(&h->mv[MV_BWD_X0], BLK_16X16);
- switch(mb_type) {
- case B_SKIP:
- case B_DIRECT:
- if(!(*h->col_type)) {
- /* intra MB at co-location, do in-plane prediction */
- mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_BSKIP, BLK_16X16, 1);
- mv_pred(h, MV_BWD_X0, MV_BWD_C2, MV_PRED_BSKIP, BLK_16X16, 0);
- } else
- /* direct prediction from co-located P MB, block-wise */
- for(block=0;block<4;block++)
- mv_pred_direct(h,&h->mv[mv_scan[block]],
- &h->col_mv[(h->mby*h->mb_width+h->mbx)*4 + block]);
- break;
- case B_FWD_16X16:
- mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_MEDIAN, BLK_16X16, 1);
- break;
- case B_SYM_16X16:
- mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_MEDIAN, BLK_16X16, 1);
- mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_16X16);
- break;
- case B_BWD_16X16:
- mv_pred(h, MV_BWD_X0, MV_BWD_C2, MV_PRED_MEDIAN, BLK_16X16, 0);
- break;
- case B_8X8:
- for(block=0;block<4;block++)
- sub_type[block] = get_bits(&h->s.gb,2);
- for(block=0;block<4;block++) {
- switch(sub_type[block]) {
- case B_SUB_DIRECT:
- if(!(*h->col_type)) {
- /* intra MB at co-location, do in-plane prediction */
- mv_pred(h, mv_scan[block], mv_scan[block]-3,
- MV_PRED_BSKIP, BLK_8X8, 1);
- mv_pred(h, mv_scan[block]+MV_BWD_OFFS,
- mv_scan[block]-3+MV_BWD_OFFS,
- MV_PRED_BSKIP, BLK_8X8, 0);
- } else
- mv_pred_direct(h,&h->mv[mv_scan[block]],
- &h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + block]);
- break;
- case B_SUB_FWD:
- mv_pred(h, mv_scan[block], mv_scan[block]-3,
- MV_PRED_MEDIAN, BLK_8X8, 1);
- break;
- case B_SUB_SYM:
- mv_pred(h, mv_scan[block], mv_scan[block]-3,
- MV_PRED_MEDIAN, BLK_8X8, 1);
- mv_pred_sym(h, &h->mv[mv_scan[block]], BLK_8X8);
- break;
- }
- }
- for(block=0;block<4;block++) {
- if(sub_type[block] == B_SUB_BWD)
- mv_pred(h, mv_scan[block]+MV_BWD_OFFS,
- mv_scan[block]+MV_BWD_OFFS-3,
- MV_PRED_MEDIAN, BLK_8X8, 0);
- }
- break;
- default:
- assert((mb_type > B_SYM_16X16) && (mb_type < B_8X8));
- flags = partition_flags[mb_type];
- if(mb_type & 1) { /* 16x8 macroblock types */
- if(flags & FWD0)
- mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_TOP, BLK_16X8, 1);
- if(flags & SYM0)
- mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_16X8);
- if(flags & FWD1)
- mv_pred(h, MV_FWD_X2, MV_FWD_A1, MV_PRED_LEFT, BLK_16X8, 1);
- if(flags & SYM1)
- mv_pred_sym(h, &h->mv[MV_FWD_X2], BLK_16X8);
- if(flags & BWD0)
- mv_pred(h, MV_BWD_X0, MV_BWD_C2, MV_PRED_TOP, BLK_16X8, 0);
- if(flags & BWD1)
- mv_pred(h, MV_BWD_X2, MV_BWD_A1, MV_PRED_LEFT, BLK_16X8, 0);
- } else { /* 8x16 macroblock types */
- if(flags & FWD0)
- mv_pred(h, MV_FWD_X0, MV_FWD_B3, MV_PRED_LEFT, BLK_8X16, 1);
- if(flags & SYM0)
- mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_8X16);
- if(flags & FWD1)
- mv_pred(h, MV_FWD_X1, MV_FWD_C2, MV_PRED_TOPRIGHT,BLK_8X16, 1);
- if(flags & SYM1)
- mv_pred_sym(h, &h->mv[MV_FWD_X1], BLK_8X16);
- if(flags & BWD0)
- mv_pred(h, MV_BWD_X0, MV_BWD_B3, MV_PRED_LEFT, BLK_8X16, 0);
- if(flags & BWD1)
- mv_pred(h, MV_BWD_X1, MV_BWD_C2, MV_PRED_TOPRIGHT,BLK_8X16, 0);
- }
- }
- inter_pred(h, mb_type);
- if(mb_type != B_SKIP)
- decode_residual_inter(h);
- filter_mb(h,mb_type);
-}
-
-/*****************************************************************************
- *
- * slice level
- *
- ****************************************************************************/
-
-static inline int decode_slice_header(AVSContext *h, GetBitContext *gb) {
- if(h->stc > 0xAF)
- av_log(h->s.avctx, AV_LOG_ERROR, "unexpected start code 0x%02x\n", h->stc);
- h->mby = h->stc;
- if((h->mby == 0) && (!h->qp_fixed)){
- h->qp_fixed = get_bits1(gb);
- h->qp = get_bits(gb,6);
- }
- /* inter frame or second slice can have weighting params */
- if((h->pic_type != FF_I_TYPE) || (!h->pic_structure && h->mby >= h->mb_width/2))
- if(get_bits1(gb)) { //slice_weighting_flag
- av_log(h->s.avctx, AV_LOG_ERROR,
- "weighted prediction not yet supported\n");
- }
- return 0;
-}
-
-static inline void check_for_slice(AVSContext *h) {
- GetBitContext *gb = &h->s.gb;
- int align;
- align = (-get_bits_count(gb)) & 7;
- if((show_bits_long(gb,24+align) & 0xFFFFFF) == 0x000001) {
- get_bits_long(gb,24+align);
- h->stc = get_bits(gb,8);
- decode_slice_header(h,gb);
- }
-}
-
-/*****************************************************************************
- *
- * frame level
- *
- ****************************************************************************/
-
-static void init_pic(AVSContext *h) {
- int i;
-
- /* clear some predictors */
- for(i=0;i<=20;i+=4)
- h->mv[i] = un_mv;
- h->mv[MV_BWD_X0] = dir_mv;
- set_mvs(&h->mv[MV_BWD_X0], BLK_16X16);
- h->mv[MV_FWD_X0] = dir_mv;
- set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);
- h->pred_mode_Y[3] = h->pred_mode_Y[6] = NOT_AVAIL;
- h->cy = h->picture.data[0];
- h->cu = h->picture.data[1];
- h->cv = h->picture.data[2];
- h->l_stride = h->picture.linesize[0];
- h->c_stride = h->picture.linesize[1];
- h->luma_scan[2] = 8*h->l_stride;
- h->luma_scan[3] = 8*h->l_stride+8;
- h->mbx = h->mby = 0;
- h->flags = 0;
-}
-
-static int decode_pic(AVSContext *h) {
- MpegEncContext *s = &h->s;
- int skip_count;
- enum mb_t mb_type;
-
- if (!s->context_initialized) {
- s->avctx->idct_algo = FF_IDCT_CAVS;
- if (MPV_common_init(s) < 0)
- return -1;
- ff_init_scantable(s->dsp.idct_permutation,&h->scantable,ff_zigzag_direct);
- }
- get_bits(&s->gb,16);//bbv_dwlay
- if(h->stc == PIC_PB_START_CODE) {
- h->pic_type = get_bits(&s->gb,2) + FF_I_TYPE;
- if(h->pic_type > FF_B_TYPE) {
- av_log(s->avctx, AV_LOG_ERROR, "illegal picture type\n");
- return -1;
- }
- /* make sure we have the reference frames we need */
- if(!h->DPB[0].data[0] ||
- (!h->DPB[1].data[0] && h->pic_type == FF_B_TYPE))
- return -1;
- } else {
- h->pic_type = FF_I_TYPE;
- if(get_bits1(&s->gb))
- get_bits(&s->gb,16);//time_code
- }
- /* release last B frame */
- if(h->picture.data[0])
- s->avctx->release_buffer(s->avctx, (AVFrame *)&h->picture);
-
- s->avctx->get_buffer(s->avctx, (AVFrame *)&h->picture);
- init_pic(h);
- h->picture.poc = get_bits(&s->gb,8)*2;
-
- /* get temporal distances and MV scaling factors */
- if(h->pic_type != FF_B_TYPE) {
- h->dist[0] = (h->picture.poc - h->DPB[0].poc + 512) % 512;
- } else {
- h->dist[0] = (h->DPB[0].poc - h->picture.poc + 512) % 512;
- }
- h->dist[1] = (h->picture.poc - h->DPB[1].poc + 512) % 512;
- h->scale_den[0] = h->dist[0] ? 512/h->dist[0] : 0;
- h->scale_den[1] = h->dist[1] ? 512/h->dist[1] : 0;
- if(h->pic_type == FF_B_TYPE) {
- h->sym_factor = h->dist[0]*h->scale_den[1];
- } else {
- h->direct_den[0] = h->dist[0] ? 16384/h->dist[0] : 0;
- h->direct_den[1] = h->dist[1] ? 16384/h->dist[1] : 0;
- }
-
- if(s->low_delay)
- get_ue_golomb(&s->gb); //bbv_check_times
- h->progressive = get_bits1(&s->gb);
- if(h->progressive)
- h->pic_structure = 1;
- else if(!(h->pic_structure = get_bits1(&s->gb) && (h->stc == PIC_PB_START_CODE)) )
- get_bits1(&s->gb); //advanced_pred_mode_disable
- skip_bits1(&s->gb); //top_field_first
- skip_bits1(&s->gb); //repeat_first_field
- h->qp_fixed = get_bits1(&s->gb);
- h->qp = get_bits(&s->gb,6);
- if(h->pic_type == FF_I_TYPE) {
- if(!h->progressive && !h->pic_structure)
- skip_bits1(&s->gb);//what is this?
- skip_bits(&s->gb,4); //reserved bits
- } else {
- if(!(h->pic_type == FF_B_TYPE && h->pic_structure == 1))
- h->ref_flag = get_bits1(&s->gb);
- skip_bits(&s->gb,4); //reserved bits
- h->skip_mode_flag = get_bits1(&s->gb);
- }
- h->loop_filter_disable = get_bits1(&s->gb);
- if(!h->loop_filter_disable && get_bits1(&s->gb)) {
- h->alpha_offset = get_se_golomb(&s->gb);
- h->beta_offset = get_se_golomb(&s->gb);
- } else {
- h->alpha_offset = h->beta_offset = 0;
- }
- check_for_slice(h);
- if(h->pic_type == FF_I_TYPE) {
- do {
- decode_mb_i(h, 0);
- } while(next_mb(h));
- } else if(h->pic_type == FF_P_TYPE) {
- do {
- if(h->skip_mode_flag) {
- skip_count = get_ue_golomb(&s->gb);
- while(skip_count--) {
- decode_mb_p(h,P_SKIP);
- if(!next_mb(h))
- goto done;
- }
- mb_type = get_ue_golomb(&s->gb) + P_16X16;
- } else
- mb_type = get_ue_golomb(&s->gb) + P_SKIP;
- if(mb_type > P_8X8) {
- decode_mb_i(h, mb_type - P_8X8 - 1);
- } else
- decode_mb_p(h,mb_type);
- } while(next_mb(h));
- } else { /* FF_B_TYPE */
- do {
- if(h->skip_mode_flag) {
- skip_count = get_ue_golomb(&s->gb);
- while(skip_count--) {
- decode_mb_b(h,B_SKIP);
- if(!next_mb(h))
- goto done;
- }
- mb_type = get_ue_golomb(&s->gb) + B_DIRECT;
- } else
- mb_type = get_ue_golomb(&s->gb) + B_SKIP;
- if(mb_type > B_8X8) {
- decode_mb_i(h, mb_type - B_8X8 - 1);
- } else
- decode_mb_b(h,mb_type);
- } while(next_mb(h));
- }
- done:
- if(h->pic_type != FF_B_TYPE) {
- if(h->DPB[1].data[0])
- s->avctx->release_buffer(s->avctx, (AVFrame *)&h->DPB[1]);
- memcpy(&h->DPB[1], &h->DPB[0], sizeof(Picture));
- memcpy(&h->DPB[0], &h->picture, sizeof(Picture));
- memset(&h->picture,0,sizeof(Picture));
- }
- return 0;
-}
-
-/*****************************************************************************
- *
- * headers and interface
- *
- ****************************************************************************/
-
-/**
- * some predictions require data from the top-neighbouring macroblock.
- * this data has to be stored for one complete row of macroblocks
- * and this storage space is allocated here
- */
-static void init_top_lines(AVSContext *h) {
- /* alloc top line of predictors */
- h->top_qp = av_malloc( h->mb_width);
- h->top_mv[0] = av_malloc((h->mb_width*2+1)*sizeof(vector_t));
- h->top_mv[1] = av_malloc((h->mb_width*2+1)*sizeof(vector_t));
- h->top_pred_Y = av_malloc( h->mb_width*2*sizeof(*h->top_pred_Y));
- h->top_border_y = av_malloc((h->mb_width+1)*16);
- h->top_border_u = av_malloc((h->mb_width)*10);
- h->top_border_v = av_malloc((h->mb_width)*10);
-
- /* alloc space for co-located MVs and types */
- h->col_mv = av_malloc( h->mb_width*h->mb_height*4*sizeof(vector_t));
- h->col_type_base = av_malloc(h->mb_width*h->mb_height);
- h->block = av_mallocz(64*sizeof(DCTELEM));
-}
-
-static int decode_seq_header(AVSContext *h) {
- MpegEncContext *s = &h->s;
- extern const AVRational ff_frame_rate_tab[];
- int frame_rate_code;
-
- h->profile = get_bits(&s->gb,8);
- h->level = get_bits(&s->gb,8);
- skip_bits1(&s->gb); //progressive sequence
- s->width = get_bits(&s->gb,14);
- s->height = get_bits(&s->gb,14);
- skip_bits(&s->gb,2); //chroma format
- skip_bits(&s->gb,3); //sample_precision
- h->aspect_ratio = get_bits(&s->gb,4);
- frame_rate_code = get_bits(&s->gb,4);
- skip_bits(&s->gb,18);//bit_rate_lower
- skip_bits1(&s->gb); //marker_bit
- skip_bits(&s->gb,12);//bit_rate_upper
- s->low_delay = get_bits1(&s->gb);
- h->mb_width = (s->width + 15) >> 4;
- h->mb_height = (s->height + 15) >> 4;
- h->s.avctx->time_base.den = ff_frame_rate_tab[frame_rate_code].num;
- h->s.avctx->time_base.num = ff_frame_rate_tab[frame_rate_code].den;
- h->s.avctx->width = s->width;
- h->s.avctx->height = s->height;
- if(!h->top_qp)
- init_top_lines(h);
- return 0;
-}
-
-static void cavs_flush(AVCodecContext * avctx) {
- AVSContext *h = avctx->priv_data;
- h->got_keyframe = 0;
-}
-
-static int cavs_decode_frame(AVCodecContext * avctx,void *data, int *data_size,
- uint8_t * buf, int buf_size) {
- AVSContext *h = avctx->priv_data;
- MpegEncContext *s = &h->s;
- int input_size;
- const uint8_t *buf_end;
- const uint8_t *buf_ptr;
- AVFrame *picture = data;
- uint32_t stc;
-
- s->avctx = avctx;
-
- if (buf_size == 0) {
- if(!s->low_delay && h->DPB[0].data[0]) {
- *data_size = sizeof(AVPicture);
- *picture = *(AVFrame *) &h->DPB[0];
- }
- return 0;
- }
-
- buf_ptr = buf;
- buf_end = buf + buf_size;
- for(;;) {
- buf_ptr = ff_find_start_code(buf_ptr,buf_end, &stc);
- if(stc & 0xFFFFFE00)
- return FFMAX(0, buf_ptr - buf - s->parse_context.last_index);
- input_size = (buf_end - buf_ptr)*8;
- switch(stc) {
- case SEQ_START_CODE:
- init_get_bits(&s->gb, buf_ptr, input_size);
- decode_seq_header(h);
- break;
- case PIC_I_START_CODE:
- if(!h->got_keyframe) {
- if(h->DPB[0].data[0])
- avctx->release_buffer(avctx, (AVFrame *)&h->DPB[0]);
- if(h->DPB[1].data[0])
- avctx->release_buffer(avctx, (AVFrame *)&h->DPB[1]);
- h->got_keyframe = 1;
- }
- case PIC_PB_START_CODE:
- *data_size = 0;
- if(!h->got_keyframe)
- break;
- init_get_bits(&s->gb, buf_ptr, input_size);
- h->stc = stc;
- if(decode_pic(h))
- break;
- *data_size = sizeof(AVPicture);
- if(h->pic_type != FF_B_TYPE) {
- if(h->DPB[1].data[0]) {
- *picture = *(AVFrame *) &h->DPB[1];
- } else {
- *data_size = 0;
- }
- } else
- *picture = *(AVFrame *) &h->picture;
- break;
- case EXT_START_CODE:
- //mpeg_decode_extension(avctx,buf_ptr, input_size);
- break;
- case USER_START_CODE:
- //mpeg_decode_user_data(avctx,buf_ptr, input_size);
- break;
- default:
- if (stc >= SLICE_MIN_START_CODE &&
- stc <= SLICE_MAX_START_CODE) {
- init_get_bits(&s->gb, buf_ptr, input_size);
- decode_slice_header(h, &s->gb);
- }
- break;
- }
- }
-}
-
-static int cavs_decode_init(AVCodecContext * avctx) {
- AVSContext *h = avctx->priv_data;
- MpegEncContext * const s = &h->s;
-
- MPV_decode_defaults(s);
- s->avctx = avctx;
-
- avctx->pix_fmt= PIX_FMT_YUV420P;
-
- h->luma_scan[0] = 0;
- h->luma_scan[1] = 8;
- h->intra_pred_l[ INTRA_L_VERT] = intra_pred_vert;
- h->intra_pred_l[ INTRA_L_HORIZ] = intra_pred_horiz;
- h->intra_pred_l[ INTRA_L_LP] = intra_pred_lp;
- h->intra_pred_l[ INTRA_L_DOWN_LEFT] = intra_pred_down_left;
- h->intra_pred_l[INTRA_L_DOWN_RIGHT] = intra_pred_down_right;
- h->intra_pred_l[ INTRA_L_LP_LEFT] = intra_pred_lp_left;
- h->intra_pred_l[ INTRA_L_LP_TOP] = intra_pred_lp_top;
- h->intra_pred_l[ INTRA_L_DC_128] = intra_pred_dc_128;
- h->intra_pred_c[ INTRA_C_LP] = intra_pred_lp;
- h->intra_pred_c[ INTRA_C_HORIZ] = intra_pred_horiz;
- h->intra_pred_c[ INTRA_C_VERT] = intra_pred_vert;
- h->intra_pred_c[ INTRA_C_PLANE] = intra_pred_plane;
- h->intra_pred_c[ INTRA_C_LP_LEFT] = intra_pred_lp_left;
- h->intra_pred_c[ INTRA_C_LP_TOP] = intra_pred_lp_top;
- h->intra_pred_c[ INTRA_C_DC_128] = intra_pred_dc_128;
- h->mv[ 7] = un_mv;
- h->mv[19] = un_mv;
- return 0;
-}
-
-static int cavs_decode_end(AVCodecContext * avctx) {
- AVSContext *h = avctx->priv_data;
-
- av_free(h->top_qp);
- av_free(h->top_mv[0]);
- av_free(h->top_mv[1]);
- av_free(h->top_pred_Y);
- av_free(h->top_border_y);
- av_free(h->top_border_u);
- av_free(h->top_border_v);
- av_free(h->col_mv);
- av_free(h->col_type_base);
- av_free(h->block);
- return 0;
-}
-
-AVCodec cavs_decoder = {
- "cavs",
- CODEC_TYPE_VIDEO,
- CODEC_ID_CAVS,
- sizeof(AVSContext),
- cavs_decode_init,
- NULL,
- cavs_decode_end,
- cavs_decode_frame,
- CODEC_CAP_DR1 | CODEC_CAP_DELAY,
- .flush= cavs_flush,
-};
-#endif /* CONFIG_CAVS_DECODER */
-
-#ifdef CONFIG_CAVSVIDEO_PARSER
-/**
- * finds the end of the current frame in the bitstream.
- * @return the position of the first byte of the next frame, or -1
- */
-static int cavs_find_frame_end(ParseContext *pc, const uint8_t *buf,
- int buf_size) {
- int pic_found, i;
- uint32_t state;
-
- pic_found= pc->frame_start_found;
- state= pc->state;
-
- i=0;
- if(!pic_found){
- for(i=0; i<buf_size; i++){
- state= (state<<8) | buf[i];
- if(state == PIC_I_START_CODE || state == PIC_PB_START_CODE){
- i++;
- pic_found=1;
- break;
- }
- }
- }
-
- if(pic_found){
- /* EOF considered as end of frame */
- if (buf_size == 0)
- return 0;
- for(; i<buf_size; i++){
- state= (state<<8) | buf[i];
- if((state&0xFFFFFF00) == 0x100){
- if(state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE){
- pc->frame_start_found=0;
- pc->state=-1;
- return i-3;
- }
- }
- }
- }
- pc->frame_start_found= pic_found;
- pc->state= state;
- return END_NOT_FOUND;
-}
-
-static int cavsvideo_parse(AVCodecParserContext *s,
- AVCodecContext *avctx,
- uint8_t **poutbuf, int *poutbuf_size,
- const uint8_t *buf, int buf_size)
-{
- ParseContext *pc = s->priv_data;
- int next;
-
- if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){
- next= buf_size;
- }else{
- next= cavs_find_frame_end(pc, buf, buf_size);
-
- if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
- *poutbuf = NULL;
- *poutbuf_size = 0;
- return buf_size;
- }
- }
- *poutbuf = (uint8_t *)buf;
- *poutbuf_size = buf_size;
- return next;
-}
-
-AVCodecParser cavsvideo_parser = {
- { CODEC_ID_CAVS },
- sizeof(ParseContext1),
- NULL,
- cavsvideo_parse,
- ff_parse1_close,
- ff_mpeg4video_split,
-};
-#endif /* CONFIG_CAVSVIDEO_PARSER */
diff --git a/src/libffmpeg/libavcodec/cook.c b/src/libffmpeg/libavcodec/cook.c
deleted file mode 100644
index a5bd0a26a..000000000
--- a/src/libffmpeg/libavcodec/cook.c
+++ /dev/null
@@ -1,1362 +0,0 @@
-/*
- * COOK compatible decoder
- * Copyright (c) 2003 Sascha Sommer
- * Copyright (c) 2005 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 cook.c
- * Cook compatible decoder.
- * This decoder handles RealNetworks, RealAudio G2 data.
- * Cook is identified by the codec name cook in RM files.
- *
- * To use this decoder, a calling application must supply the extradata
- * bytes provided from the RM container; 8+ bytes for mono streams and
- * 16+ for stereo streams (maybe more).
- *
- * Codec technicalities (all this assume a buffer length of 1024):
- * Cook works with several different techniques to achieve its compression.
- * In the timedomain the buffer is divided into 8 pieces and quantized. If
- * two neighboring pieces have different quantization index a smooth
- * quantization curve is used to get a smooth overlap between the different
- * pieces.
- * To get to the transformdomain Cook uses a modulated lapped transform.
- * The transform domain has 50 subbands with 20 elements each. This
- * means only a maximum of 50*20=1000 coefficients are used out of the 1024
- * available.
- */
-
-#include <math.h>
-#include <stddef.h>
-#include <stdio.h>
-
-#include "avcodec.h"
-#include "bitstream.h"
-#include "dsputil.h"
-
-#include "cookdata.h"
-
-/* the different Cook versions */
-#define MONO 0x1000001
-#define STEREO 0x1000002
-#define JOINT_STEREO 0x1000003
-#define MC_COOK 0x2000000 //multichannel Cook, not supported
-
-#define SUBBAND_SIZE 20
-//#define COOKDEBUG
-
-typedef struct {
- int size;
- int qidx_table1[8];
- int qidx_table2[8];
-} COOKgain;
-
-typedef struct __attribute__((__packed__)){
- /* codec data start */
- uint32_t cookversion; //in network order, bigendian
- uint16_t samples_per_frame; //amount of samples per frame per channel, bigendian
- uint16_t subbands; //amount of bands used in the frequency domain, bigendian
- /* Mono extradata ends here. */
- uint32_t unused;
- uint16_t js_subband_start; //bigendian
- uint16_t js_vlc_bits; //bigendian
- /* Stereo extradata ends here. */
-} COOKextradata;
-
-
-typedef struct {
- GetBitContext gb;
- /* stream data */
- int nb_channels;
- int joint_stereo;
- int bit_rate;
- int sample_rate;
- int samples_per_channel;
- int samples_per_frame;
- int subbands;
- int log2_numvector_size;
- int numvector_size; //1 << log2_numvector_size;
- int js_subband_start;
- int total_subbands;
- int num_vectors;
- int bits_per_subpacket;
- /* states */
- int random_state;
-
- /* transform data */
- FFTContext fft_ctx;
- FFTSample mlt_tmp[1024] __attribute__((aligned(16))); /* temporary storage for imlt */
- float* mlt_window;
- float* mlt_precos;
- float* mlt_presin;
- float* mlt_postcos;
- int fft_size;
- int fft_order;
- int mlt_size; //modulated lapped transform size
-
- /* gain buffers */
- COOKgain* gain_now_ptr;
- COOKgain* gain_previous_ptr;
- COOKgain gain_current;
- COOKgain gain_now;
- COOKgain gain_previous;
- COOKgain gain_channel1[2];
- COOKgain gain_channel2[2];
-
- /* VLC data */
- int js_vlc_bits;
- VLC envelope_quant_index[13];
- VLC sqvh[7]; //scalar quantization
- VLC ccpl; //channel coupling
-
- /* generatable tables and related variables */
- int gain_size_factor;
- float gain_table[23];
- float pow2tab[127];
- float rootpow2tab[127];
-
- /* data buffers */
-
- uint8_t* decoded_bytes_buffer;
- float mono_mdct_output[2048] __attribute__((aligned(16)));
- float* previous_buffer_ptr[2];
- float mono_previous_buffer1[1024];
- float mono_previous_buffer2[1024];
- float* decode_buf_ptr[4];
- float* decode_buf_ptr2[2];
- float decode_buffer_1[1024];
- float decode_buffer_2[1024];
- float decode_buffer_3[1024];
- float decode_buffer_4[1024];
-} COOKContext;
-
-/* debug functions */
-
-#ifdef COOKDEBUG
-static void dump_float_table(float* table, int size, int delimiter) {
- int i=0;
- av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i);
- for (i=0 ; i<size ; i++) {
- av_log(NULL, AV_LOG_ERROR, "%5.1f, ", table[i]);
- if ((i+1)%delimiter == 0) av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i+1);
- }
-}
-
-static void dump_int_table(int* table, int size, int delimiter) {
- int i=0;
- av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i);
- for (i=0 ; i<size ; i++) {
- av_log(NULL, AV_LOG_ERROR, "%d, ", table[i]);
- if ((i+1)%delimiter == 0) av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i+1);
- }
-}
-
-static void dump_short_table(short* table, int size, int delimiter) {
- int i=0;
- av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i);
- for (i=0 ; i<size ; i++) {
- av_log(NULL, AV_LOG_ERROR, "%d, ", table[i]);
- if ((i+1)%delimiter == 0) av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i+1);
- }
-}
-
-#endif
-
-/*************** init functions ***************/
-
-/* table generator */
-static void init_pow2table(COOKContext *q){
- int i;
- q->pow2tab[63] = 1.0;
- for (i=1 ; i<64 ; i++){
- q->pow2tab[63+i]=(float)((uint64_t)1<<i);
- q->pow2tab[63-i]=1.0/(float)((uint64_t)1<<i);
- }
-}
-
-/* table generator */
-static void init_rootpow2table(COOKContext *q){
- int i;
- q->rootpow2tab[63] = 1.0;
- for (i=1 ; i<64 ; i++){
- q->rootpow2tab[63+i]=sqrt((float)((uint64_t)1<<i));
- q->rootpow2tab[63-i]=sqrt(1.0/(float)((uint64_t)1<<i));
- }
-}
-
-/* table generator */
-static void init_gain_table(COOKContext *q) {
- int i;
- q->gain_size_factor = q->samples_per_channel/8;
- for (i=0 ; i<23 ; i++) {
- q->gain_table[i] = pow((double)q->pow2tab[i+52] ,
- (1.0/(double)q->gain_size_factor));
- }
-}
-
-
-static int init_cook_vlc_tables(COOKContext *q) {
- int i, result;
-
- result = 0;
- for (i=0 ; i<13 ; i++) {
- result &= init_vlc (&q->envelope_quant_index[i], 9, 24,
- envelope_quant_index_huffbits[i], 1, 1,
- envelope_quant_index_huffcodes[i], 2, 2, 0);
- }
- av_log(NULL,AV_LOG_DEBUG,"sqvh VLC init\n");
- for (i=0 ; i<7 ; i++) {
- result &= init_vlc (&q->sqvh[i], vhvlcsize_tab[i], vhsize_tab[i],
- cvh_huffbits[i], 1, 1,
- cvh_huffcodes[i], 2, 2, 0);
- }
-
- if (q->nb_channels==2 && q->joint_stereo==1){
- result &= init_vlc (&q->ccpl, 6, (1<<q->js_vlc_bits)-1,
- ccpl_huffbits[q->js_vlc_bits-2], 1, 1,
- ccpl_huffcodes[q->js_vlc_bits-2], 2, 2, 0);
- av_log(NULL,AV_LOG_DEBUG,"Joint-stereo VLC used.\n");
- }
-
- av_log(NULL,AV_LOG_DEBUG,"VLC tables initialized.\n");
- return result;
-}
-
-static int init_cook_mlt(COOKContext *q) {
- int j;
- float alpha;
-
- /* Allocate the buffers, could be replaced with a static [512]
- array if needed. */
- q->mlt_size = q->samples_per_channel;
- q->mlt_window = av_malloc(sizeof(float)*q->mlt_size);
- q->mlt_precos = av_malloc(sizeof(float)*q->mlt_size/2);
- q->mlt_presin = av_malloc(sizeof(float)*q->mlt_size/2);
- q->mlt_postcos = av_malloc(sizeof(float)*q->mlt_size/2);
-
- /* Initialize the MLT window: simple sine window. */
- alpha = M_PI / (2.0 * (float)q->mlt_size);
- for(j=0 ; j<q->mlt_size ; j++) {
- q->mlt_window[j] = sin((j + 512.0/(float)q->mlt_size) * alpha);
- }
-
- /* pre/post twiddle factors */
- for (j=0 ; j<q->mlt_size/2 ; j++){
- q->mlt_precos[j] = cos( ((j+0.25)*M_PI)/q->mlt_size);
- q->mlt_presin[j] = sin( ((j+0.25)*M_PI)/q->mlt_size);
- q->mlt_postcos[j] = (float)sqrt(2.0/(float)q->mlt_size)*cos( ((float)j*M_PI) /q->mlt_size); //sqrt(2/MLT_size) = scalefactor
- }
-
- /* Initialize the FFT. */
- ff_fft_init(&q->fft_ctx, av_log2(q->mlt_size)-1, 0);
- av_log(NULL,AV_LOG_DEBUG,"FFT initialized, order = %d.\n",
- av_log2(q->samples_per_channel)-1);
-
- return (int)(q->mlt_window && q->mlt_precos && q->mlt_presin && q->mlt_postcos);
-}
-
-/*************** init functions end ***********/
-
-/**
- * Cook indata decoding, every 32 bits are XORed with 0x37c511f2.
- * Why? No idea, some checksum/error detection method maybe.
- *
- * Out buffer size: extra bytes are needed to cope with
- * padding/missalignment.
- * Subpackets passed to the decoder can contain two, consecutive
- * half-subpackets, of identical but arbitrary size.
- * 1234 1234 1234 1234 extraA extraB
- * Case 1: AAAA BBBB 0 0
- * Case 2: AAAA ABBB BB-- 3 3
- * Case 3: AAAA AABB BBBB 2 2
- * Case 4: AAAA AAAB BBBB BB-- 1 5
- *
- * Nice way to waste CPU cycles.
- *
- * @param inbuffer pointer to byte array of indata
- * @param out pointer to byte array of outdata
- * @param bytes number of bytes
- */
-#define DECODE_BYTES_PAD1(bytes) (3 - ((bytes)+3) % 4)
-#define DECODE_BYTES_PAD2(bytes) ((bytes) % 4 + DECODE_BYTES_PAD1(2 * (bytes)))
-
-static inline int decode_bytes(uint8_t* inbuffer, uint8_t* out, int bytes){
- int i, off;
- uint32_t c;
- uint32_t* buf;
- uint32_t* obuf = (uint32_t*) out;
- /* FIXME: 64 bit platforms would be able to do 64 bits at a time.
- * I'm too lazy though, should be something like
- * for(i=0 ; i<bitamount/64 ; i++)
- * (int64_t)out[i] = 0x37c511f237c511f2^be2me_64(int64_t)in[i]);
- * Buffer alignment needs to be checked. */
-
- off = (uint32_t)inbuffer % 4;
- buf = (uint32_t*) (inbuffer - off);
- c = be2me_32((0x37c511f2 >> (off*8)) | (0x37c511f2 << (32-(off*8))));
- bytes += 3 + off;
- for (i = 0; i < bytes/4; i++)
- obuf[i] = c ^ buf[i];
-
- return off;
-}
-
-/**
- * Cook uninit
- */
-
-static int cook_decode_close(AVCodecContext *avctx)
-{
- int i;
- COOKContext *q = avctx->priv_data;
- av_log(avctx,AV_LOG_DEBUG, "Deallocating memory.\n");
-
- /* Free allocated memory buffers. */
- av_free(q->mlt_window);
- av_free(q->mlt_precos);
- av_free(q->mlt_presin);
- av_free(q->mlt_postcos);
- av_free(q->decoded_bytes_buffer);
-
- /* Free the transform. */
- ff_fft_end(&q->fft_ctx);
-
- /* Free the VLC tables. */
- for (i=0 ; i<13 ; i++) {
- free_vlc(&q->envelope_quant_index[i]);
- }
- for (i=0 ; i<7 ; i++) {
- free_vlc(&q->sqvh[i]);
- }
- if(q->nb_channels==2 && q->joint_stereo==1 ){
- free_vlc(&q->ccpl);
- }
-
- av_log(NULL,AV_LOG_DEBUG,"Memory deallocated.\n");
-
- return 0;
-}
-
-/**
- * Fill the COOKgain structure for the timedomain quantization.
- *
- * @param q pointer to the COOKContext
- * @param gaininfo pointer to the COOKgain
- */
-
-static void decode_gain_info(GetBitContext *gb, COOKgain* gaininfo) {
- int i;
-
- while (get_bits1(gb)) {}
-
- gaininfo->size = get_bits_count(gb) - 1; //amount of elements*2 to update
-
- if (get_bits_count(gb) - 1 <= 0) return;
-
- for (i=0 ; i<gaininfo->size ; i++){
- gaininfo->qidx_table1[i] = get_bits(gb,3);
- if (get_bits1(gb)) {
- gaininfo->qidx_table2[i] = get_bits(gb,4) - 7; //convert to signed
- } else {
- gaininfo->qidx_table2[i] = -1;
- }
- }
-}
-
-/**
- * Create the quant index table needed for the envelope.
- *
- * @param q pointer to the COOKContext
- * @param quant_index_table pointer to the array
- */
-
-static void decode_envelope(COOKContext *q, int* quant_index_table) {
- int i,j, vlc_index;
- int bitbias;
-
- bitbias = get_bits_count(&q->gb);
- quant_index_table[0]= get_bits(&q->gb,6) - 6; //This is used later in categorize
-
- for (i=1 ; i < q->total_subbands ; i++){
- vlc_index=i;
- if (i >= q->js_subband_start * 2) {
- vlc_index-=q->js_subband_start;
- } else {
- vlc_index/=2;
- if(vlc_index < 1) vlc_index = 1;
- }
- if (vlc_index>13) vlc_index = 13; //the VLC tables >13 are identical to No. 13
-
- j = get_vlc2(&q->gb, q->envelope_quant_index[vlc_index-1].table,
- q->envelope_quant_index[vlc_index-1].bits,2);
- quant_index_table[i] = quant_index_table[i-1] + j - 12; //differential encoding
- }
-}
-
-/**
- * Create the quant value table.
- *
- * @param q pointer to the COOKContext
- * @param quant_value_table pointer to the array
- */
-
-static void inline dequant_envelope(COOKContext *q, int* quant_index_table,
- float* quant_value_table){
-
- int i;
- for(i=0 ; i < q->total_subbands ; i++){
- quant_value_table[i] = q->rootpow2tab[quant_index_table[i]+63];
- }
-}
-
-/**
- * Calculate the category and category_index vector.
- *
- * @param q pointer to the COOKContext
- * @param quant_index_table pointer to the array
- * @param category pointer to the category array
- * @param category_index pointer to the category_index array
- */
-
-static void categorize(COOKContext *q, int* quant_index_table,
- int* category, int* category_index){
- int exp_idx, bias, tmpbias, bits_left, num_bits, index, v, i, j;
- int exp_index2[102];
- int exp_index1[102];
-
- int tmp_categorize_array1[128];
- int tmp_categorize_array1_idx=0;
- int tmp_categorize_array2[128];
- int tmp_categorize_array2_idx=0;
- int category_index_size=0;
-
- bits_left = q->bits_per_subpacket - get_bits_count(&q->gb);
-
- if(bits_left > q->samples_per_channel) {
- bits_left = q->samples_per_channel +
- ((bits_left - q->samples_per_channel)*5)/8;
- //av_log(NULL, AV_LOG_ERROR, "bits_left = %d\n",bits_left);
- }
-
- memset(&exp_index1,0,102*sizeof(int));
- memset(&exp_index2,0,102*sizeof(int));
- memset(&tmp_categorize_array1,0,128*sizeof(int));
- memset(&tmp_categorize_array2,0,128*sizeof(int));
-
- bias=-32;
-
- /* Estimate bias. */
- for (i=32 ; i>0 ; i=i/2){
- num_bits = 0;
- index = 0;
- for (j=q->total_subbands ; j>0 ; j--){
- exp_idx = (i - quant_index_table[index] + bias) / 2;
- if (exp_idx<0){
- exp_idx=0;
- } else if(exp_idx >7) {
- exp_idx=7;
- }
- index++;
- num_bits+=expbits_tab[exp_idx];
- }
- if(num_bits >= bits_left - 32){
- bias+=i;
- }
- }
-
- /* Calculate total number of bits. */
- num_bits=0;
- for (i=0 ; i<q->total_subbands ; i++) {
- exp_idx = (bias - quant_index_table[i]) / 2;
- if (exp_idx<0) {
- exp_idx=0;
- } else if(exp_idx >7) {
- exp_idx=7;
- }
- num_bits += expbits_tab[exp_idx];
- exp_index1[i] = exp_idx;
- exp_index2[i] = exp_idx;
- }
- tmpbias = bias = num_bits;
-
- for (j = 1 ; j < q->numvector_size ; j++) {
- if (tmpbias + bias > 2*bits_left) { /* ---> */
- int max = -999999;
- index=-1;
- for (i=0 ; i<q->total_subbands ; i++){
- if (exp_index1[i] < 7) {
- v = (-2*exp_index1[i]) - quant_index_table[i] - 32;
- if ( v >= max) {
- max = v;
- index = i;
- }
- }
- }
- if(index==-1)break;
- tmp_categorize_array1[tmp_categorize_array1_idx++] = index;
- tmpbias -= expbits_tab[exp_index1[index]] -
- expbits_tab[exp_index1[index]+1];
- ++exp_index1[index];
- } else { /* <--- */
- int min = 999999;
- index=-1;
- for (i=0 ; i<q->total_subbands ; i++){
- if(exp_index2[i] > 0){
- v = (-2*exp_index2[i])-quant_index_table[i];
- if ( v < min) {
- min = v;
- index = i;
- }
- }
- }
- if(index == -1)break;
- tmp_categorize_array2[tmp_categorize_array2_idx++] = index;
- tmpbias -= expbits_tab[exp_index2[index]] -
- expbits_tab[exp_index2[index]-1];
- --exp_index2[index];
- }
- }
-
- for(i=0 ; i<q->total_subbands ; i++)
- category[i] = exp_index2[i];
-
- /* Concatenate the two arrays. */
- for(i=tmp_categorize_array2_idx-1 ; i >= 0; i--)
- category_index[category_index_size++] = tmp_categorize_array2[i];
-
- for(i=0;i<tmp_categorize_array1_idx;i++)
- category_index[category_index_size++ ] = tmp_categorize_array1[i];
-
- /* FIXME: mc_sich_ra8_20.rm triggers this, not sure with what we
- should fill the remaining bytes. */
- for(i=category_index_size;i<q->numvector_size;i++)
- category_index[i]=0;
-
-}
-
-
-/**
- * Expand the category vector.
- *
- * @param q pointer to the COOKContext
- * @param category pointer to the category array
- * @param category_index pointer to the category_index array
- */
-
-static void inline expand_category(COOKContext *q, int* category,
- int* category_index){
- int i;
- for(i=0 ; i<q->num_vectors ; i++){
- ++category[category_index[i]];
- }
-}
-
-/**
- * The real requantization of the mltcoefs
- *
- * @param q pointer to the COOKContext
- * @param index index
- * @param band current subband
- * @param quant_value_table pointer to the array
- * @param subband_coef_index array of indexes to quant_centroid_tab
- * @param subband_coef_noise use random noise instead of predetermined value
- * @param mlt_buffer pointer to the mlt buffer
- */
-
-
-static void scalar_dequant(COOKContext *q, int index, int band,
- float* quant_value_table, int* subband_coef_index,
- int* subband_coef_noise, float* mlt_buffer){
- int i;
- float f1;
-
- for(i=0 ; i<SUBBAND_SIZE ; i++) {
- if (subband_coef_index[i]) {
- if (subband_coef_noise[i]) {
- f1 = -quant_centroid_tab[index][subband_coef_index[i]];
- } else {
- f1 = quant_centroid_tab[index][subband_coef_index[i]];
- }
- } else {
- /* noise coding if subband_coef_noise[i] == 0 */
- q->random_state = q->random_state * 214013 + 2531011; //typical RNG numbers
- f1 = randsign[(q->random_state/0x1000000)&1] * dither_tab[index]; //>>31
- }
- mlt_buffer[band*20+ i] = f1 * quant_value_table[band];
- }
-}
-/**
- * Unpack the subband_coef_index and subband_coef_noise vectors.
- *
- * @param q pointer to the COOKContext
- * @param category pointer to the category array
- * @param subband_coef_index array of indexes to quant_centroid_tab
- * @param subband_coef_noise use random noise instead of predetermined value
- */
-
-static int unpack_SQVH(COOKContext *q, int category, int* subband_coef_index,
- int* subband_coef_noise) {
- int i,j;
- int vlc, vd ,tmp, result;
- int ub;
- int cb;
-
- vd = vd_tab[category];
- result = 0;
- for(i=0 ; i<vpr_tab[category] ; i++){
- ub = get_bits_count(&q->gb);
- vlc = get_vlc2(&q->gb, q->sqvh[category].table, q->sqvh[category].bits, 3);
- cb = get_bits_count(&q->gb);
- if (q->bits_per_subpacket < get_bits_count(&q->gb)){
- vlc = 0;
- result = 1;
- }
- for(j=vd-1 ; j>=0 ; j--){
- tmp = (vlc * invradix_tab[category])/0x100000;
- subband_coef_index[vd*i+j] = vlc - tmp * (kmax_tab[category]+1);
- vlc = tmp;
- }
- for(j=0 ; j<vd ; j++){
- if (subband_coef_index[i*vd + j]) {
- if(get_bits_count(&q->gb) < q->bits_per_subpacket){
- subband_coef_noise[i*vd+j] = get_bits1(&q->gb);
- } else {
- result=1;
- subband_coef_noise[i*vd+j]=0;
- }
- } else {
- subband_coef_noise[i*vd+j]=0;
- }
- }
- }
- return result;
-}
-
-
-/**
- * Fill the mlt_buffer with mlt coefficients.
- *
- * @param q pointer to the COOKContext
- * @param category pointer to the category array
- * @param quant_value_table pointer to the array
- * @param mlt_buffer pointer to mlt coefficients
- */
-
-
-static void decode_vectors(COOKContext* q, int* category,
- float* quant_value_table, float* mlt_buffer){
- /* A zero in this table means that the subband coefficient is
- random noise coded. */
- int subband_coef_noise[SUBBAND_SIZE];
- /* A zero in this table means that the subband coefficient is a
- positive multiplicator. */
- int subband_coef_index[SUBBAND_SIZE];
- int band, j;
- int index=0;
-
- for(band=0 ; band<q->total_subbands ; band++){
- index = category[band];
- if(category[band] < 7){
- if(unpack_SQVH(q, category[band], subband_coef_index, subband_coef_noise)){
- index=7;
- for(j=0 ; j<q->total_subbands ; j++) category[band+j]=7;
- }
- }
- if(index==7) {
- memset(subband_coef_index, 0, sizeof(subband_coef_index));
- memset(subband_coef_noise, 0, sizeof(subband_coef_noise));
- }
- scalar_dequant(q, index, band, quant_value_table, subband_coef_index,
- subband_coef_noise, mlt_buffer);
- }
-
- if(q->total_subbands*SUBBAND_SIZE >= q->samples_per_channel){
- return;
- }
-}
-
-
-/**
- * function for decoding mono data
- *
- * @param q pointer to the COOKContext
- * @param mlt_buffer1 pointer to left channel mlt coefficients
- * @param mlt_buffer2 pointer to right channel mlt coefficients
- */
-
-static void mono_decode(COOKContext *q, float* mlt_buffer) {
-
- int category_index[128];
- float quant_value_table[102];
- int quant_index_table[102];
- int category[128];
-
- memset(&category, 0, 128*sizeof(int));
- memset(&quant_value_table, 0, 102*sizeof(int));
- memset(&category_index, 0, 128*sizeof(int));
-
- decode_envelope(q, quant_index_table);
- q->num_vectors = get_bits(&q->gb,q->log2_numvector_size);
- dequant_envelope(q, quant_index_table, quant_value_table);
- categorize(q, quant_index_table, category, category_index);
- expand_category(q, category, category_index);
- decode_vectors(q, category, quant_value_table, mlt_buffer);
-}
-
-
-/**
- * The modulated lapped transform, this takes transform coefficients
- * and transforms them into timedomain samples. This is done through
- * an FFT-based algorithm with pre- and postrotation steps.
- * A window and reorder step is also included.
- *
- * @param q pointer to the COOKContext
- * @param inbuffer pointer to the mltcoefficients
- * @param outbuffer pointer to the timedomain buffer
- * @param mlt_tmp pointer to temporary storage space
- */
-
-static void cook_imlt(COOKContext *q, float* inbuffer, float* outbuffer,
- float* mlt_tmp){
- int i;
-
- /* prerotation */
- for(i=0 ; i<q->mlt_size ; i+=2){
- outbuffer[i] = (q->mlt_presin[i/2] * inbuffer[q->mlt_size-1-i]) +
- (q->mlt_precos[i/2] * inbuffer[i]);
- outbuffer[i+1] = (q->mlt_precos[i/2] * inbuffer[q->mlt_size-1-i]) -
- (q->mlt_presin[i/2] * inbuffer[i]);
- }
-
- /* FFT */
- ff_fft_permute(&q->fft_ctx, (FFTComplex *) outbuffer);
- ff_fft_calc (&q->fft_ctx, (FFTComplex *) outbuffer);
-
- /* postrotation */
- for(i=0 ; i<q->mlt_size ; i+=2){
- mlt_tmp[i] = (q->mlt_postcos[(q->mlt_size-1-i)/2] * outbuffer[i+1]) +
- (q->mlt_postcos[i/2] * outbuffer[i]);
- mlt_tmp[q->mlt_size-1-i] = (q->mlt_postcos[(q->mlt_size-1-i)/2] * outbuffer[i]) -
- (q->mlt_postcos[i/2] * outbuffer[i+1]);
- }
-
- /* window and reorder */
- for(i=0 ; i<q->mlt_size/2 ; i++){
- outbuffer[i] = mlt_tmp[q->mlt_size/2-1-i] * q->mlt_window[i];
- outbuffer[q->mlt_size-1-i]= mlt_tmp[q->mlt_size/2-1-i] *
- q->mlt_window[q->mlt_size-1-i];
- outbuffer[q->mlt_size+i]= mlt_tmp[q->mlt_size/2+i] *
- q->mlt_window[q->mlt_size-1-i];
- outbuffer[2*q->mlt_size-1-i]= -(mlt_tmp[q->mlt_size/2+i] *
- q->mlt_window[i]);
- }
-}
-
-
-/**
- * the actual requantization of the timedomain samples
- *
- * @param q pointer to the COOKContext
- * @param buffer pointer to the timedomain buffer
- * @param gain_index index for the block multiplier
- * @param gain_index_next index for the next block multiplier
- */
-
-static void interpolate(COOKContext *q, float* buffer,
- int gain_index, int gain_index_next){
- int i;
- float fc1, fc2;
- fc1 = q->pow2tab[gain_index+63];
-
- if(gain_index == gain_index_next){ //static gain
- for(i=0 ; i<q->gain_size_factor ; i++){
- buffer[i]*=fc1;
- }
- return;
- } else { //smooth gain
- fc2 = q->gain_table[11 + (gain_index_next-gain_index)];
- for(i=0 ; i<q->gain_size_factor ; i++){
- buffer[i]*=fc1;
- fc1*=fc2;
- }
- return;
- }
-}
-
-/**
- * timedomain requantization of the timedomain samples
- *
- * @param q pointer to the COOKContext
- * @param buffer pointer to the timedomain buffer
- * @param gain_now current gain structure
- * @param gain_previous previous gain structure
- */
-
-static void gain_window(COOKContext *q, float* buffer, COOKgain* gain_now,
- COOKgain* gain_previous){
- int i, index;
- int gain_index[9];
- int tmp_gain_index;
-
- gain_index[8]=0;
- index = gain_previous->size;
- for (i=7 ; i>=0 ; i--) {
- if(index && gain_previous->qidx_table1[index-1]==i) {
- gain_index[i] = gain_previous->qidx_table2[index-1];
- index--;
- } else {
- gain_index[i]=gain_index[i+1];
- }
- }
- /* This is applied to the to be previous data buffer. */
- for(i=0;i<8;i++){
- interpolate(q, &buffer[q->samples_per_channel+q->gain_size_factor*i],
- gain_index[i], gain_index[i+1]);
- }
-
- tmp_gain_index = gain_index[0];
- index = gain_now->size;
- for (i=7 ; i>=0 ; i--) {
- if(index && gain_now->qidx_table1[index-1]==i) {
- gain_index[i]= gain_now->qidx_table2[index-1];
- index--;
- } else {
- gain_index[i]=gain_index[i+1];
- }
- }
-
- /* This is applied to the to be current block. */
- for(i=0;i<8;i++){
- interpolate(q, &buffer[i*q->gain_size_factor],
- tmp_gain_index+gain_index[i],
- tmp_gain_index+gain_index[i+1]);
- }
-}
-
-
-/**
- * mlt overlapping and buffer management
- *
- * @param q pointer to the COOKContext
- * @param buffer pointer to the timedomain buffer
- * @param gain_now current gain structure
- * @param gain_previous previous gain structure
- * @param previous_buffer pointer to the previous buffer to be used for overlapping
- *
- */
-
-static void gain_compensate(COOKContext *q, float* buffer, COOKgain* gain_now,
- COOKgain* gain_previous, float* previous_buffer) {
- int i;
- if((gain_now->size || gain_previous->size)) {
- gain_window(q, buffer, gain_now, gain_previous);
- }
-
- /* Overlap with the previous block. */
- for(i=0 ; i<q->samples_per_channel ; i++) buffer[i]+=previous_buffer[i];
-
- /* Save away the current to be previous block. */
- memcpy(previous_buffer, buffer+q->samples_per_channel,
- sizeof(float)*q->samples_per_channel);
-}
-
-
-/**
- * function for getting the jointstereo coupling information
- *
- * @param q pointer to the COOKContext
- * @param decouple_tab decoupling array
- *
- */
-
-static void decouple_info(COOKContext *q, int* decouple_tab){
- int length, i;
-
- if(get_bits1(&q->gb)) {
- if(cplband[q->js_subband_start] > cplband[q->subbands-1]) return;
-
- length = cplband[q->subbands-1] - cplband[q->js_subband_start] + 1;
- for (i=0 ; i<length ; i++) {
- decouple_tab[cplband[q->js_subband_start] + i] = get_vlc2(&q->gb, q->ccpl.table, q->ccpl.bits, 2);
- }
- return;
- }
-
- if(cplband[q->js_subband_start] > cplband[q->subbands-1]) return;
-
- length = cplband[q->subbands-1] - cplband[q->js_subband_start] + 1;
- for (i=0 ; i<length ; i++) {
- decouple_tab[cplband[q->js_subband_start] + i] = get_bits(&q->gb, q->js_vlc_bits);
- }
- return;
-}
-
-
-/**
- * function for decoding joint stereo data
- *
- * @param q pointer to the COOKContext
- * @param mlt_buffer1 pointer to left channel mlt coefficients
- * @param mlt_buffer2 pointer to right channel mlt coefficients
- */
-
-static void joint_decode(COOKContext *q, float* mlt_buffer1,
- float* mlt_buffer2) {
- int i,j;
- int decouple_tab[SUBBAND_SIZE];
- float decode_buffer[1060];
- int idx, cpl_tmp,tmp_idx;
- float f1,f2;
- float* cplscale;
-
- memset(decouple_tab, 0, sizeof(decouple_tab));
- memset(decode_buffer, 0, sizeof(decode_buffer));
-
- /* Make sure the buffers are zeroed out. */
- memset(mlt_buffer1,0, 1024*sizeof(float));
- memset(mlt_buffer2,0, 1024*sizeof(float));
- decouple_info(q, decouple_tab);
- mono_decode(q, decode_buffer);
-
- /* The two channels are stored interleaved in decode_buffer. */
- for (i=0 ; i<q->js_subband_start ; i++) {
- for (j=0 ; j<SUBBAND_SIZE ; j++) {
- mlt_buffer1[i*20+j] = decode_buffer[i*40+j];
- mlt_buffer2[i*20+j] = decode_buffer[i*40+20+j];
- }
- }
-
- /* When we reach js_subband_start (the higher frequencies)
- the coefficients are stored in a coupling scheme. */
- idx = (1 << q->js_vlc_bits) - 1;
- for (i=q->js_subband_start ; i<q->subbands ; i++) {
- cpl_tmp = cplband[i];
- idx -=decouple_tab[cpl_tmp];
- cplscale = (float*)cplscales[q->js_vlc_bits-2]; //choose decoupler table
- f1 = cplscale[decouple_tab[cpl_tmp]];
- f2 = cplscale[idx-1];
- for (j=0 ; j<SUBBAND_SIZE ; j++) {
- tmp_idx = ((q->js_subband_start + i)*20)+j;
- mlt_buffer1[20*i + j] = f1 * decode_buffer[tmp_idx];
- mlt_buffer2[20*i + j] = f2 * decode_buffer[tmp_idx];
- }
- idx = (1 << q->js_vlc_bits) - 1;
- }
-}
-
-/**
- * First part of subpacket decoding:
- * decode raw stream bytes and read gain info.
- *
- * @param q pointer to the COOKContext
- * @param inbuffer pointer to raw stream data
- * @param gain_ptr array of current/prev gain pointers
- */
-
-static inline void
-decode_bytes_and_gain(COOKContext *q, uint8_t *inbuffer, COOKgain *gain_ptr)
-{
- int offset;
-
- offset = decode_bytes(inbuffer, q->decoded_bytes_buffer,
- q->bits_per_subpacket/8);
- init_get_bits(&q->gb, q->decoded_bytes_buffer + offset,
- q->bits_per_subpacket);
- decode_gain_info(&q->gb, gain_ptr);
-}
-
-
-/**
- * Cook subpacket decoding. This function returns one decoded subpacket,
- * usually 1024 samples per channel.
- *
- * @param q pointer to the COOKContext
- * @param inbuffer pointer to the inbuffer
- * @param sub_packet_size subpacket size
- * @param outbuffer pointer to the outbuffer
- */
-
-
-static int decode_subpacket(COOKContext *q, uint8_t *inbuffer,
- int sub_packet_size, int16_t *outbuffer) {
- int i,j;
- int value;
- float* tmp_ptr;
-
- /* packet dump */
-// for (i=0 ; i<sub_packet_size ; i++) {
-// av_log(NULL, AV_LOG_ERROR, "%02x", inbuffer[i]);
-// }
-// av_log(NULL, AV_LOG_ERROR, "\n");
-
- if(q->nb_channels==2 && q->joint_stereo==1){
- decode_bytes_and_gain(q, inbuffer, &q->gain_current);
-
- joint_decode(q, q->decode_buf_ptr[0], q->decode_buf_ptr[2]);
-
- /* Swap buffer pointers. */
- tmp_ptr = q->decode_buf_ptr[1];
- q->decode_buf_ptr[1] = q->decode_buf_ptr[0];
- q->decode_buf_ptr[0] = tmp_ptr;
- tmp_ptr = q->decode_buf_ptr[3];
- q->decode_buf_ptr[3] = q->decode_buf_ptr[2];
- q->decode_buf_ptr[2] = tmp_ptr;
-
- /* FIXME: Rethink the gainbuffer handling, maybe a rename?
- now/previous swap */
- q->gain_now_ptr = &q->gain_now;
- q->gain_previous_ptr = &q->gain_previous;
- for (i=0 ; i<q->nb_channels ; i++){
-
- cook_imlt(q, q->decode_buf_ptr[i*2], q->mono_mdct_output, q->mlt_tmp);
- gain_compensate(q, q->mono_mdct_output, q->gain_now_ptr,
- q->gain_previous_ptr, q->previous_buffer_ptr[0]);
-
- /* Swap out the previous buffer. */
- tmp_ptr = q->previous_buffer_ptr[0];
- q->previous_buffer_ptr[0] = q->previous_buffer_ptr[1];
- q->previous_buffer_ptr[1] = tmp_ptr;
-
- /* Clip and convert the floats to 16 bits. */
- for (j=0 ; j<q->samples_per_frame ; j++){
- value = lrintf(q->mono_mdct_output[j]);
- if(value < -32768) value = -32768;
- else if(value > 32767) value = 32767;
- outbuffer[2*j+i] = value;
- }
- }
-
- memcpy(&q->gain_now, &q->gain_previous, sizeof(COOKgain));
- memcpy(&q->gain_previous, &q->gain_current, sizeof(COOKgain));
-
- } else if (q->nb_channels==2 && q->joint_stereo==0) {
- /* channel 0 */
- decode_bytes_and_gain(q, inbuffer, &q->gain_current);
-
- mono_decode(q, q->decode_buf_ptr2[0]);
-
- tmp_ptr = q->decode_buf_ptr2[0];
- q->decode_buf_ptr2[0] = q->decode_buf_ptr2[1];
- q->decode_buf_ptr2[1] = tmp_ptr;
-
- memcpy(&q->gain_channel1[0], &q->gain_current ,sizeof(COOKgain));
- q->gain_now_ptr = &q->gain_channel1[0];
- q->gain_previous_ptr = &q->gain_channel1[1];
-
- cook_imlt(q, q->decode_buf_ptr2[0], q->mono_mdct_output,q->mlt_tmp);
- gain_compensate(q, q->mono_mdct_output, q->gain_now_ptr,
- q->gain_previous_ptr, q->mono_previous_buffer1);
-
- memcpy(&q->gain_channel1[1], &q->gain_channel1[0],sizeof(COOKgain));
-
-
- for (j=0 ; j<q->samples_per_frame ; j++){
- value = lrintf(q->mono_mdct_output[j]);
- if(value < -32768) value = -32768;
- else if(value > 32767) value = 32767;
- outbuffer[2*j] = value;
- }
-
- /* channel 1 */
- //av_log(NULL,AV_LOG_ERROR,"bits = %d\n",get_bits_count(&q->gb));
- decode_bytes_and_gain(q, inbuffer + sub_packet_size/2,
- &q->gain_channel2[0]);
-
- q->gain_now_ptr = &q->gain_channel2[0];
- q->gain_previous_ptr = &q->gain_channel2[1];
-
- mono_decode(q, q->decode_buf_ptr[0]);
-
- tmp_ptr = q->decode_buf_ptr[0];
- q->decode_buf_ptr[0] = q->decode_buf_ptr[1];
- q->decode_buf_ptr[1] = tmp_ptr;
-
- cook_imlt(q, q->decode_buf_ptr[0], q->mono_mdct_output,q->mlt_tmp);
- gain_compensate(q, q->mono_mdct_output, q->gain_now_ptr,
- q->gain_previous_ptr, q->mono_previous_buffer2);
-
- /* Swap out the previous buffer. */
- tmp_ptr = q->previous_buffer_ptr[0];
- q->previous_buffer_ptr[0] = q->previous_buffer_ptr[1];
- q->previous_buffer_ptr[1] = tmp_ptr;
-
- memcpy(&q->gain_channel2[1], &q->gain_channel2[0] ,sizeof(COOKgain));
-
- for (j=0 ; j<q->samples_per_frame ; j++){
- value = lrintf(q->mono_mdct_output[j]);
- if(value < -32768) value = -32768;
- else if(value > 32767) value = 32767;
- outbuffer[2*j+1] = value;
- }
-
- } else {
- decode_bytes_and_gain(q, inbuffer, &q->gain_current);
-
- mono_decode(q, q->decode_buf_ptr[0]);
-
- /* Swap buffer pointers. */
- tmp_ptr = q->decode_buf_ptr[1];
- q->decode_buf_ptr[1] = q->decode_buf_ptr[0];
- q->decode_buf_ptr[0] = tmp_ptr;
-
- /* FIXME: Rethink the gainbuffer handling, maybe a rename?
- now/previous swap */
- q->gain_now_ptr = &q->gain_now;
- q->gain_previous_ptr = &q->gain_previous;
-
- cook_imlt(q, q->decode_buf_ptr[0], q->mono_mdct_output,q->mlt_tmp);
- gain_compensate(q, q->mono_mdct_output, q->gain_now_ptr,
- q->gain_previous_ptr, q->mono_previous_buffer1);
-
- /* Clip and convert the floats to 16 bits */
- for (j=0 ; j<q->samples_per_frame ; j++){
- value = lrintf(q->mono_mdct_output[j]);
- if(value < -32768) value = -32768;
- else if(value > 32767) value = 32767;
- outbuffer[j] = value;
- }
- memcpy(&q->gain_now, &q->gain_previous, sizeof(COOKgain));
- memcpy(&q->gain_previous, &q->gain_current, sizeof(COOKgain));
- }
- return q->samples_per_frame * sizeof(int16_t);
-}
-
-
-/**
- * Cook frame decoding
- *
- * @param avctx pointer to the AVCodecContext
- */
-
-static int cook_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size) {
- COOKContext *q = avctx->priv_data;
-
- if (buf_size < avctx->block_align)
- return buf_size;
-
- *data_size = decode_subpacket(q, buf, avctx->block_align, data);
-
- return avctx->block_align;
-}
-
-#ifdef COOKDEBUG
-static void dump_cook_context(COOKContext *q, COOKextradata *e)
-{
- //int i=0;
-#define PRINT(a,b) av_log(NULL,AV_LOG_ERROR," %s = %d\n", a, b);
- av_log(NULL,AV_LOG_ERROR,"COOKextradata\n");
- av_log(NULL,AV_LOG_ERROR,"cookversion=%x\n",e->cookversion);
- if (e->cookversion > STEREO) {
- PRINT("js_subband_start",e->js_subband_start);
- PRINT("js_vlc_bits",e->js_vlc_bits);
- }
- av_log(NULL,AV_LOG_ERROR,"COOKContext\n");
- PRINT("nb_channels",q->nb_channels);
- PRINT("bit_rate",q->bit_rate);
- PRINT("sample_rate",q->sample_rate);
- PRINT("samples_per_channel",q->samples_per_channel);
- PRINT("samples_per_frame",q->samples_per_frame);
- PRINT("subbands",q->subbands);
- PRINT("random_state",q->random_state);
- PRINT("mlt_size",q->mlt_size);
- PRINT("js_subband_start",q->js_subband_start);
- PRINT("log2_numvector_size",q->log2_numvector_size);
- PRINT("numvector_size",q->numvector_size);
- PRINT("total_subbands",q->total_subbands);
-}
-#endif
-
-/**
- * Cook initialization
- *
- * @param avctx pointer to the AVCodecContext
- */
-
-static int cook_decode_init(AVCodecContext *avctx)
-{
- COOKextradata *e = (COOKextradata *)avctx->extradata;
- COOKContext *q = avctx->priv_data;
-
- /* Take care of the codec specific extradata. */
- if (avctx->extradata_size <= 0) {
- av_log(avctx,AV_LOG_ERROR,"Necessary extradata missing!\n");
- return -1;
- } else {
- /* 8 for mono, 16 for stereo, ? for multichannel
- Swap to right endianness so we don't need to care later on. */
- av_log(avctx,AV_LOG_DEBUG,"codecdata_length=%d\n",avctx->extradata_size);
- if (avctx->extradata_size >= 8){
- e->cookversion = be2me_32(e->cookversion);
- e->samples_per_frame = be2me_16(e->samples_per_frame);
- e->subbands = be2me_16(e->subbands);
- }
- if (avctx->extradata_size >= 16){
- e->js_subband_start = be2me_16(e->js_subband_start);
- e->js_vlc_bits = be2me_16(e->js_vlc_bits);
- }
- }
-
- /* Take data from the AVCodecContext (RM container). */
- q->sample_rate = avctx->sample_rate;
- q->nb_channels = avctx->channels;
- q->bit_rate = avctx->bit_rate;
-
- /* Initialize state. */
- q->random_state = 1;
-
- /* Initialize extradata related variables. */
- q->samples_per_channel = e->samples_per_frame / q->nb_channels;
- q->samples_per_frame = e->samples_per_frame;
- q->subbands = e->subbands;
- q->bits_per_subpacket = avctx->block_align * 8;
-
- /* Initialize default data states. */
- q->js_subband_start = 0;
- q->log2_numvector_size = 5;
- q->total_subbands = q->subbands;
-
- /* Initialize version-dependent variables */
- av_log(NULL,AV_LOG_DEBUG,"e->cookversion=%x\n",e->cookversion);
- switch (e->cookversion) {
- case MONO:
- if (q->nb_channels != 1) {
- av_log(avctx,AV_LOG_ERROR,"Container channels != 1, report sample!\n");
- return -1;
- }
- av_log(avctx,AV_LOG_DEBUG,"MONO\n");
- break;
- case STEREO:
- if (q->nb_channels != 1) {
- q->joint_stereo = 0;
- q->bits_per_subpacket = q->bits_per_subpacket/2;
- }
- av_log(avctx,AV_LOG_DEBUG,"STEREO\n");
- break;
- case JOINT_STEREO:
- if (q->nb_channels != 2) {
- av_log(avctx,AV_LOG_ERROR,"Container channels != 2, report sample!\n");
- return -1;
- }
- av_log(avctx,AV_LOG_DEBUG,"JOINT_STEREO\n");
- if (avctx->extradata_size >= 16){
- q->total_subbands = q->subbands + e->js_subband_start;
- q->js_subband_start = e->js_subband_start;
- q->joint_stereo = 1;
- q->js_vlc_bits = e->js_vlc_bits;
- }
- if (q->samples_per_channel > 256) {
- q->log2_numvector_size = 6;
- }
- if (q->samples_per_channel > 512) {
- q->log2_numvector_size = 7;
- }
- break;
- case MC_COOK:
- av_log(avctx,AV_LOG_ERROR,"MC_COOK not supported!\n");
- return -1;
- break;
- default:
- av_log(avctx,AV_LOG_ERROR,"Unknown Cook version, report sample!\n");
- return -1;
- break;
- }
-
- /* Initialize variable relations */
- q->mlt_size = q->samples_per_channel;
- q->numvector_size = (1 << q->log2_numvector_size);
-
- /* Generate tables */
- init_rootpow2table(q);
- init_pow2table(q);
- init_gain_table(q);
-
- if (init_cook_vlc_tables(q) != 0)
- return -1;
-
-
- if(avctx->block_align >= UINT_MAX/2)
- return -1;
-
- /* Pad the databuffer with:
- DECODE_BYTES_PAD1 or DECODE_BYTES_PAD2 for decode_bytes(),
- FF_INPUT_BUFFER_PADDING_SIZE, for the bitstreamreader. */
- if (q->nb_channels==2 && q->joint_stereo==0) {
- q->decoded_bytes_buffer =
- av_mallocz(avctx->block_align/2
- + DECODE_BYTES_PAD2(avctx->block_align/2)
- + FF_INPUT_BUFFER_PADDING_SIZE);
- } else {
- q->decoded_bytes_buffer =
- av_mallocz(avctx->block_align
- + DECODE_BYTES_PAD1(avctx->block_align)
- + FF_INPUT_BUFFER_PADDING_SIZE);
- }
- if (q->decoded_bytes_buffer == NULL)
- return -1;
-
- q->decode_buf_ptr[0] = q->decode_buffer_1;
- q->decode_buf_ptr[1] = q->decode_buffer_2;
- q->decode_buf_ptr[2] = q->decode_buffer_3;
- q->decode_buf_ptr[3] = q->decode_buffer_4;
-
- q->decode_buf_ptr2[0] = q->decode_buffer_3;
- q->decode_buf_ptr2[1] = q->decode_buffer_4;
-
- q->previous_buffer_ptr[0] = q->mono_previous_buffer1;
- q->previous_buffer_ptr[1] = q->mono_previous_buffer2;
-
- /* Initialize transform. */
- if ( init_cook_mlt(q) == 0 )
- return -1;
-
- /* Try to catch some obviously faulty streams, othervise it might be exploitable */
- if (q->total_subbands > 53) {
- av_log(avctx,AV_LOG_ERROR,"total_subbands > 53, report sample!\n");
- return -1;
- }
- if (q->subbands > 50) {
- av_log(avctx,AV_LOG_ERROR,"subbands > 50, report sample!\n");
- return -1;
- }
- if ((q->samples_per_channel == 256) || (q->samples_per_channel == 512) || (q->samples_per_channel == 1024)) {
- } else {
- av_log(avctx,AV_LOG_ERROR,"unknown amount of samples_per_channel = %d, report sample!\n",q->samples_per_channel);
- return -1;
- }
-
-#ifdef COOKDEBUG
- dump_cook_context(q,e);
-#endif
- return 0;
-}
-
-
-AVCodec cook_decoder =
-{
- .name = "cook",
- .type = CODEC_TYPE_AUDIO,
- .id = CODEC_ID_COOK,
- .priv_data_size = sizeof(COOKContext),
- .init = cook_decode_init,
- .close = cook_decode_close,
- .decode = cook_decode_frame,
-};
diff --git a/src/libffmpeg/libavcodec/cscd.c b/src/libffmpeg/libavcodec/cscd.c
deleted file mode 100644
index d8733d6dd..000000000
--- a/src/libffmpeg/libavcodec/cscd.c
+++ /dev/null
@@ -1,264 +0,0 @@
-/*
- * CamStudio decoder
- * Copyright (c) 2006 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 <stdio.h>
-#include <stdlib.h>
-
-#include "common.h"
-#include "avcodec.h"
-
-#ifdef CONFIG_ZLIB
-#include <zlib.h>
-#endif
-#include "lzo.h"
-
-typedef struct {
- AVFrame pic;
- int linelen, height, bpp;
- unsigned int decomp_size;
- unsigned char* decomp_buf;
-} CamStudioContext;
-
-static void copy_frame_default(AVFrame *f, uint8_t *src,
- int linelen, int height) {
- int i;
- uint8_t *dst = f->data[0];
- dst += (height - 1) * f->linesize[0];
- for (i = height; i; i--) {
- memcpy(dst, src, linelen);
- src += linelen;
- dst -= f->linesize[0];
- }
-}
-
-static void add_frame_default(AVFrame *f, uint8_t *src,
- int linelen, int height) {
- int i, j;
- uint8_t *dst = f->data[0];
- dst += (height - 1) * f->linesize[0];
- for (i = height; i; i--) {
- for (j = linelen; j; j--)
- *dst++ += *src++;
- dst -= f->linesize[0] + linelen;
- }
-}
-
-#ifndef WORDS_BIGENDIAN
-#define copy_frame_16 copy_frame_default
-#define copy_frame_32 copy_frame_default
-#define add_frame_16 add_frame_default
-#define add_frame_32 add_frame_default
-#else
-static void copy_frame_16(AVFrame *f, uint8_t *src,
- int linelen, int height) {
- int i, j;
- uint8_t *dst = f->data[0];
- dst += (height - 1) * f->linesize[0];
- for (i = height; i; i--) {
- for (j = linelen / 2; j; j--) {
- dst[0] = src[1];
- dst[1] = src[0];
- src += 2;
- dst += 2;
- }
- dst -= f->linesize[0] + linelen;
- }
-}
-
-static void copy_frame_32(AVFrame *f, uint8_t *src,
- int linelen, int height) {
- int i, j;
- uint8_t *dst = f->data[0];
- dst += (height - 1) * f->linesize[0];
- for (i = height; i; i--) {
- for (j = linelen / 4; j; j--) {
- dst[0] = src[3];
- dst[1] = src[2];
- dst[2] = src[1];
- dst[3] = src[0];
- src += 4;
- dst += 4;
- }
- dst -= f->linesize[0] + linelen;
- }
-}
-
-static void add_frame_16(AVFrame *f, uint8_t *src,
- int linelen, int height) {
- int i, j;
- uint8_t *dst = f->data[0];
- dst += (height - 1) * f->linesize[0];
- for (i = height; i; i--) {
- for (j = linelen / 2; j; j--) {
- dst[0] += src[1];
- dst[1] += src[0];
- src += 2;
- dst += 2;
- }
- dst -= f->linesize[0] + linelen;
- }
-}
-
-static void add_frame_32(AVFrame *f, uint8_t *src,
- int linelen, int height) {
- int i, j;
- uint8_t *dst = f->data[0];
- dst += (height - 1) * f->linesize[0];
- for (i = height; i; i--) {
- for (j = linelen / 4; j; j--) {
- dst[0] += src[3];
- dst[1] += src[2];
- dst[2] += src[1];
- dst[3] += src[0];
- src += 4;
- dst += 4;
- }
- dst -= f->linesize[0] + linelen;
- }
-}
-#endif
-
-static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
- uint8_t *buf, int buf_size) {
- CamStudioContext *c = (CamStudioContext *)avctx->priv_data;
- AVFrame *picture = data;
-
- if (buf_size < 2) {
- av_log(avctx, AV_LOG_ERROR, "coded frame too small\n");
- return -1;
- }
-
- if (c->pic.data[0])
- avctx->release_buffer(avctx, &c->pic);
- c->pic.reference = 1;
- c->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_READABLE |
- FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
- if (avctx->get_buffer(avctx, &c->pic) < 0) {
- av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
- return -1;
- }
-
- // decompress data
- switch ((buf[0] >> 1) & 7) {
- case 0: { // lzo compression
- int outlen = c->decomp_size, inlen = buf_size - 2;
- if (lzo1x_decode(c->decomp_buf, &outlen, &buf[2], &inlen))
- av_log(avctx, AV_LOG_ERROR, "error during lzo decompression\n");
- break;
- }
- case 1: { // zlib compression
-#ifdef CONFIG_ZLIB
- unsigned long dlen = c->decomp_size;
- if (uncompress(c->decomp_buf, &dlen, &buf[2], buf_size - 2) != Z_OK)
- av_log(avctx, AV_LOG_ERROR, "error during zlib decompression\n");
- break;
-#else
- av_log(avctx, AV_LOG_ERROR, "compiled without zlib support\n");
- return -1;
-#endif
- }
- default:
- av_log(avctx, AV_LOG_ERROR, "unknown compression\n");
- return -1;
- }
-
- // flip upside down, add difference frame
- if (buf[0] & 1) { // keyframe
- c->pic.pict_type = FF_I_TYPE;
- c->pic.key_frame = 1;
- switch (c->bpp) {
- case 16:
- copy_frame_16(&c->pic, c->decomp_buf, c->linelen, c->height);
- break;
- case 32:
- copy_frame_32(&c->pic, c->decomp_buf, c->linelen, c->height);
- break;
- default:
- copy_frame_default(&c->pic, c->decomp_buf, c->linelen, c->height);
- }
- } else {
- c->pic.pict_type = FF_P_TYPE;
- c->pic.key_frame = 0;
- switch (c->bpp) {
- case 16:
- add_frame_16(&c->pic, c->decomp_buf, c->linelen, c->height);
- break;
- case 32:
- add_frame_32(&c->pic, c->decomp_buf, c->linelen, c->height);
- break;
- default:
- add_frame_default(&c->pic, c->decomp_buf, c->linelen, c->height);
- }
- }
-
- *picture = c->pic;
- *data_size = sizeof(AVFrame);
- return buf_size;
-}
-
-static int decode_init(AVCodecContext *avctx) {
- CamStudioContext *c = (CamStudioContext *)avctx->priv_data;
- if (avcodec_check_dimensions(avctx, avctx->height, avctx->width) < 0) {
- return 1;
- }
- avctx->has_b_frames = 0;
- switch (avctx->bits_per_sample) {
- case 16: avctx->pix_fmt = PIX_FMT_RGB555; break;
- case 24: avctx->pix_fmt = PIX_FMT_BGR24; break;
- case 32: avctx->pix_fmt = PIX_FMT_RGBA32; break;
- default:
- av_log(avctx, AV_LOG_ERROR,
- "CamStudio codec error: invalid depth %i bpp\n",
- avctx->bits_per_sample);
- return 1;
- }
- c->bpp = avctx->bits_per_sample;
- c->pic.data[0] = NULL;
- c->linelen = avctx->width * avctx->bits_per_sample / 8;
- c->height = avctx->height;
- c->decomp_size = c->height * c->linelen;
- c->decomp_buf = av_malloc(c->decomp_size + LZO_OUTPUT_PADDING);
- if (!c->decomp_buf) {
- av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
- return 1;
- }
- return 0;
-}
-
-static int decode_end(AVCodecContext *avctx) {
- CamStudioContext *c = (CamStudioContext *)avctx->priv_data;
- av_freep(&c->decomp_buf);
- if (c->pic.data[0])
- avctx->release_buffer(avctx, &c->pic);
- return 0;
-}
-
-AVCodec cscd_decoder = {
- "camstudio",
- CODEC_TYPE_VIDEO,
- CODEC_ID_CSCD,
- sizeof(CamStudioContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
-};
-
diff --git a/src/libffmpeg/libavcodec/dsputil.c b/src/libffmpeg/libavcodec/dsputil.c
deleted file mode 100644
index 916d8658c..000000000
--- a/src/libffmpeg/libavcodec/dsputil.c
+++ /dev/null
@@ -1,4184 +0,0 @@
-/*
- * DSP utils
- * Copyright (c) 2000, 2001 Fabrice Bellard.
- * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * gmc & q-pel & 32/64 bit based MC by Michael Niedermayer <michaelni@gmx.at>
- */
-
-/**
- * @file dsputil.c
- * DSP utils
- */
-
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-#include "simple_idct.h"
-#include "faandct.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);
-
-uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP] = {0, };
-uint32_t ff_squareTbl[512] = {0, };
-
-const uint8_t ff_zigzag_direct[64] = {
- 0, 1, 8, 16, 9, 2, 3, 10,
- 17, 24, 32, 25, 18, 11, 4, 5,
- 12, 19, 26, 33, 40, 48, 41, 34,
- 27, 20, 13, 6, 7, 14, 21, 28,
- 35, 42, 49, 56, 57, 50, 43, 36,
- 29, 22, 15, 23, 30, 37, 44, 51,
- 58, 59, 52, 45, 38, 31, 39, 46,
- 53, 60, 61, 54, 47, 55, 62, 63
-};
-
-/* Specific zigzag scan for 248 idct. NOTE that unlike the
- specification, we interleave the fields */
-const uint8_t ff_zigzag248_direct[64] = {
- 0, 8, 1, 9, 16, 24, 2, 10,
- 17, 25, 32, 40, 48, 56, 33, 41,
- 18, 26, 3, 11, 4, 12, 19, 27,
- 34, 42, 49, 57, 50, 58, 35, 43,
- 20, 28, 5, 13, 6, 14, 21, 29,
- 36, 44, 51, 59, 52, 60, 37, 45,
- 22, 30, 7, 15, 23, 31, 38, 46,
- 53, 61, 54, 62, 39, 47, 55, 63,
-};
-
-/* not permutated inverse zigzag_direct + 1 for MMX quantizer */
-DECLARE_ALIGNED_8(uint16_t, inv_zigzag_direct16[64]) = {0, };
-
-const uint8_t ff_alternate_horizontal_scan[64] = {
- 0, 1, 2, 3, 8, 9, 16, 17,
- 10, 11, 4, 5, 6, 7, 15, 14,
- 13, 12, 19, 18, 24, 25, 32, 33,
- 26, 27, 20, 21, 22, 23, 28, 29,
- 30, 31, 34, 35, 40, 41, 48, 49,
- 42, 43, 36, 37, 38, 39, 44, 45,
- 46, 47, 50, 51, 56, 57, 58, 59,
- 52, 53, 54, 55, 60, 61, 62, 63,
-};
-
-const uint8_t ff_alternate_vertical_scan[64] = {
- 0, 8, 16, 24, 1, 9, 2, 10,
- 17, 25, 32, 40, 48, 56, 57, 49,
- 41, 33, 26, 18, 3, 11, 4, 12,
- 19, 27, 34, 42, 50, 58, 35, 43,
- 51, 59, 20, 28, 5, 13, 6, 14,
- 21, 29, 36, 44, 52, 60, 37, 45,
- 53, 61, 22, 30, 7, 15, 23, 31,
- 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]={
- 0, 4294967295U,2147483648U,1431655766, 1073741824, 858993460, 715827883, 613566757,
- 536870912, 477218589, 429496730, 390451573, 357913942, 330382100, 306783379, 286331154,
- 268435456, 252645136, 238609295, 226050911, 214748365, 204522253, 195225787, 186737709,
- 178956971, 171798692, 165191050, 159072863, 153391690, 148102321, 143165577, 138547333,
- 134217728, 130150525, 126322568, 122713352, 119304648, 116080198, 113025456, 110127367,
- 107374183, 104755300, 102261127, 99882961, 97612894, 95443718, 93368855, 91382283,
- 89478486, 87652394, 85899346, 84215046, 82595525, 81037119, 79536432, 78090315,
- 76695845, 75350304, 74051161, 72796056, 71582789, 70409300, 69273667, 68174085,
- 67108864, 66076420, 65075263, 64103990, 63161284, 62245903, 61356676, 60492498,
- 59652324, 58835169, 58040099, 57266231, 56512728, 55778797, 55063684, 54366675,
- 53687092, 53024288, 52377650, 51746594, 51130564, 50529028, 49941481, 49367441,
- 48806447, 48258060, 47721859, 47197443, 46684428, 46182445, 45691142, 45210183,
- 44739243, 44278014, 43826197, 43383509, 42949673, 42524429, 42107523, 41698712,
- 41297763, 40904451, 40518560, 40139882, 39768216, 39403370, 39045158, 38693400,
- 38347923, 38008561, 37675152, 37347542, 37025581, 36709123, 36398028, 36092163,
- 35791395, 35495598, 35204650, 34918434, 34636834, 34359739, 34087043, 33818641,
- 33554432, 33294321, 33038210, 32786010, 32537632, 32292988, 32051995, 31814573,
- 31580642, 31350127, 31122952, 30899046, 30678338, 30460761, 30246249, 30034737,
- 29826162, 29620465, 29417585, 29217465, 29020050, 28825284, 28633116, 28443493,
- 28256364, 28071682, 27889399, 27709467, 27531842, 27356480, 27183338, 27012373,
- 26843546, 26676816, 26512144, 26349493, 26188825, 26030105, 25873297, 25718368,
- 25565282, 25414008, 25264514, 25116768, 24970741, 24826401, 24683721, 24542671,
- 24403224, 24265352, 24129030, 23994231, 23860930, 23729102, 23598722, 23469767,
- 23342214, 23216040, 23091223, 22967740, 22845571, 22724695, 22605092, 22486740,
- 22369622, 22253717, 22139007, 22025474, 21913099, 21801865, 21691755, 21582751,
- 21474837, 21367997, 21262215, 21157475, 21053762, 20951060, 20849356, 20748635,
- 20648882, 20550083, 20452226, 20355296, 20259280, 20164166, 20069941, 19976593,
- 19884108, 19792477, 19701685, 19611723, 19522579, 19434242, 19346700, 19259944,
- 19173962, 19088744, 19004281, 18920561, 18837576, 18755316, 18673771, 18592933,
- 18512791, 18433337, 18354562, 18276457, 18199014, 18122225, 18046082, 17970575,
- 17895698, 17821442, 17747799, 17674763, 17602325, 17530479, 17459217, 17388532,
- 17318417, 17248865, 17179870, 17111424, 17043522, 16976156, 16909321, 16843010,
-};
-
-/* Input permutation for the simple_idct_mmx */
-static const uint8_t simple_mmx_permutation[64]={
- 0x00, 0x08, 0x04, 0x09, 0x01, 0x0C, 0x05, 0x0D,
- 0x10, 0x18, 0x14, 0x19, 0x11, 0x1C, 0x15, 0x1D,
- 0x20, 0x28, 0x24, 0x29, 0x21, 0x2C, 0x25, 0x2D,
- 0x12, 0x1A, 0x16, 0x1B, 0x13, 0x1E, 0x17, 0x1F,
- 0x02, 0x0A, 0x06, 0x0B, 0x03, 0x0E, 0x07, 0x0F,
- 0x30, 0x38, 0x34, 0x39, 0x31, 0x3C, 0x35, 0x3D,
- 0x22, 0x2A, 0x26, 0x2B, 0x23, 0x2E, 0x27, 0x2F,
- 0x32, 0x3A, 0x36, 0x3B, 0x33, 0x3E, 0x37, 0x3F,
-};
-
-static int pix_sum_c(uint8_t * pix, int line_size)
-{
- int s, i, j;
-
- s = 0;
- for (i = 0; i < 16; i++) {
- for (j = 0; j < 16; j += 8) {
- s += pix[0];
- s += pix[1];
- s += pix[2];
- s += pix[3];
- s += pix[4];
- s += pix[5];
- s += pix[6];
- s += pix[7];
- pix += 8;
- }
- pix += line_size - 16;
- }
- return s;
-}
-
-static int pix_norm1_c(uint8_t * pix, int line_size)
-{
- int s, i, j;
- uint32_t *sq = ff_squareTbl + 256;
-
- s = 0;
- for (i = 0; i < 16; i++) {
- for (j = 0; j < 16; j += 8) {
-#if 0
- s += sq[pix[0]];
- s += sq[pix[1]];
- s += sq[pix[2]];
- s += sq[pix[3]];
- s += sq[pix[4]];
- s += sq[pix[5]];
- s += sq[pix[6]];
- s += sq[pix[7]];
-#else
-#if LONG_MAX > 2147483647
- register uint64_t x=*(uint64_t*)pix;
- s += sq[x&0xff];
- s += sq[(x>>8)&0xff];
- s += sq[(x>>16)&0xff];
- s += sq[(x>>24)&0xff];
- s += sq[(x>>32)&0xff];
- s += sq[(x>>40)&0xff];
- s += sq[(x>>48)&0xff];
- s += sq[(x>>56)&0xff];
-#else
- register uint32_t x=*(uint32_t*)pix;
- s += sq[x&0xff];
- s += sq[(x>>8)&0xff];
- s += sq[(x>>16)&0xff];
- s += sq[(x>>24)&0xff];
- x=*(uint32_t*)(pix+4);
- s += sq[x&0xff];
- s += sq[(x>>8)&0xff];
- s += sq[(x>>16)&0xff];
- s += sq[(x>>24)&0xff];
-#endif
-#endif
- pix += 8;
- }
- pix += line_size - 16;
- }
- return s;
-}
-
-static void bswap_buf(uint32_t *dst, uint32_t *src, int w){
- int i;
-
- for(i=0; i+8<=w; i+=8){
- dst[i+0]= bswap_32(src[i+0]);
- dst[i+1]= bswap_32(src[i+1]);
- dst[i+2]= bswap_32(src[i+2]);
- dst[i+3]= bswap_32(src[i+3]);
- dst[i+4]= bswap_32(src[i+4]);
- dst[i+5]= bswap_32(src[i+5]);
- dst[i+6]= bswap_32(src[i+6]);
- dst[i+7]= bswap_32(src[i+7]);
- }
- for(;i<w; i++){
- dst[i+0]= bswap_32(src[i+0]);
- }
-}
-
-static int sse4_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h)
-{
- int s, i;
- uint32_t *sq = ff_squareTbl + 256;
-
- s = 0;
- for (i = 0; i < h; i++) {
- s += sq[pix1[0] - pix2[0]];
- s += sq[pix1[1] - pix2[1]];
- s += sq[pix1[2] - pix2[2]];
- s += sq[pix1[3] - pix2[3]];
- pix1 += line_size;
- pix2 += line_size;
- }
- return s;
-}
-
-static int sse8_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h)
-{
- int s, i;
- uint32_t *sq = ff_squareTbl + 256;
-
- s = 0;
- for (i = 0; i < h; i++) {
- s += sq[pix1[0] - pix2[0]];
- s += sq[pix1[1] - pix2[1]];
- s += sq[pix1[2] - pix2[2]];
- s += sq[pix1[3] - pix2[3]];
- s += sq[pix1[4] - pix2[4]];
- s += sq[pix1[5] - pix2[5]];
- s += sq[pix1[6] - pix2[6]];
- s += sq[pix1[7] - pix2[7]];
- pix1 += line_size;
- pix2 += line_size;
- }
- return s;
-}
-
-static int sse16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
-{
- int s, i;
- uint32_t *sq = ff_squareTbl + 256;
-
- s = 0;
- for (i = 0; i < h; i++) {
- s += sq[pix1[ 0] - pix2[ 0]];
- s += sq[pix1[ 1] - pix2[ 1]];
- s += sq[pix1[ 2] - pix2[ 2]];
- s += sq[pix1[ 3] - pix2[ 3]];
- s += sq[pix1[ 4] - pix2[ 4]];
- s += sq[pix1[ 5] - pix2[ 5]];
- s += sq[pix1[ 6] - pix2[ 6]];
- s += sq[pix1[ 7] - pix2[ 7]];
- s += sq[pix1[ 8] - pix2[ 8]];
- s += sq[pix1[ 9] - pix2[ 9]];
- s += sq[pix1[10] - pix2[10]];
- s += sq[pix1[11] - pix2[11]];
- s += sq[pix1[12] - pix2[12]];
- s += sq[pix1[13] - pix2[13]];
- s += sq[pix1[14] - pix2[14]];
- s += sq[pix1[15] - pix2[15]];
-
- pix1 += line_size;
- pix2 += line_size;
- }
- return s;
-}
-
-
-#ifdef 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++){
- for(ori= level ? 1 : 0; ori<4; ori++){
- int size= w>>(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<size; i++){
- for(j=0; j<size; j++){
- int v= tmp[sx + sy + i*stride + j] * scale[type][dec_count-3][level][ori];
- s += FFABS(v);
- }
- }
- }
- }
- assert(s>=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
-
-static void get_pixels_c(DCTELEM *restrict block, const uint8_t *pixels, int line_size)
-{
- int i;
-
- /* read the pixels */
- for(i=0;i<8;i++) {
- block[0] = pixels[0];
- block[1] = pixels[1];
- block[2] = pixels[2];
- block[3] = pixels[3];
- block[4] = pixels[4];
- block[5] = pixels[5];
- block[6] = pixels[6];
- block[7] = pixels[7];
- pixels += line_size;
- block += 8;
- }
-}
-
-static void diff_pixels_c(DCTELEM *restrict block, const uint8_t *s1,
- const uint8_t *s2, int stride){
- int i;
-
- /* read the pixels */
- for(i=0;i<8;i++) {
- block[0] = s1[0] - s2[0];
- block[1] = s1[1] - s2[1];
- block[2] = s1[2] - s2[2];
- block[3] = s1[3] - s2[3];
- block[4] = s1[4] - s2[4];
- block[5] = s1[5] - s2[5];
- block[6] = s1[6] - s2[6];
- block[7] = s1[7] - s2[7];
- s1 += stride;
- s2 += stride;
- block += 8;
- }
-}
-
-
-static void put_pixels_clamped_c(const DCTELEM *block, uint8_t *restrict pixels,
- int line_size)
-{
- int i;
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
-
- /* read the pixels */
- for(i=0;i<8;i++) {
- pixels[0] = cm[block[0]];
- pixels[1] = cm[block[1]];
- pixels[2] = cm[block[2]];
- pixels[3] = cm[block[3]];
- pixels[4] = cm[block[4]];
- pixels[5] = cm[block[5]];
- pixels[6] = cm[block[6]];
- pixels[7] = cm[block[7]];
-
- pixels += line_size;
- block += 8;
- }
-}
-
-static void put_pixels_clamped4_c(const DCTELEM *block, uint8_t *restrict pixels,
- int line_size)
-{
- int i;
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
-
- /* read the pixels */
- for(i=0;i<4;i++) {
- pixels[0] = cm[block[0]];
- pixels[1] = cm[block[1]];
- pixels[2] = cm[block[2]];
- pixels[3] = cm[block[3]];
-
- pixels += line_size;
- block += 8;
- }
-}
-
-static void put_pixels_clamped2_c(const DCTELEM *block, uint8_t *restrict pixels,
- int line_size)
-{
- int i;
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
-
- /* read the pixels */
- for(i=0;i<2;i++) {
- pixels[0] = cm[block[0]];
- pixels[1] = cm[block[1]];
-
- pixels += line_size;
- block += 8;
- }
-}
-
-static void put_signed_pixels_clamped_c(const DCTELEM *block,
- uint8_t *restrict pixels,
- int line_size)
-{
- int i, j;
-
- for (i = 0; i < 8; i++) {
- for (j = 0; j < 8; j++) {
- if (*block < -128)
- *pixels = 0;
- else if (*block > 127)
- *pixels = 255;
- else
- *pixels = (uint8_t)(*block + 128);
- block++;
- pixels++;
- }
- pixels += (line_size - 8);
- }
-}
-
-static void add_pixels_clamped_c(const DCTELEM *block, uint8_t *restrict pixels,
- int line_size)
-{
- int i;
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
-
- /* read the pixels */
- for(i=0;i<8;i++) {
- pixels[0] = cm[pixels[0] + block[0]];
- pixels[1] = cm[pixels[1] + block[1]];
- pixels[2] = cm[pixels[2] + block[2]];
- pixels[3] = cm[pixels[3] + block[3]];
- pixels[4] = cm[pixels[4] + block[4]];
- pixels[5] = cm[pixels[5] + block[5]];
- pixels[6] = cm[pixels[6] + block[6]];
- pixels[7] = cm[pixels[7] + block[7]];
- pixels += line_size;
- block += 8;
- }
-}
-
-static void add_pixels_clamped4_c(const DCTELEM *block, uint8_t *restrict pixels,
- int line_size)
-{
- int i;
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
-
- /* read the pixels */
- for(i=0;i<4;i++) {
- pixels[0] = cm[pixels[0] + block[0]];
- pixels[1] = cm[pixels[1] + block[1]];
- pixels[2] = cm[pixels[2] + block[2]];
- pixels[3] = cm[pixels[3] + block[3]];
- pixels += line_size;
- block += 8;
- }
-}
-
-static void add_pixels_clamped2_c(const DCTELEM *block, uint8_t *restrict pixels,
- int line_size)
-{
- int i;
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
-
- /* read the pixels */
- for(i=0;i<2;i++) {
- pixels[0] = cm[pixels[0] + block[0]];
- pixels[1] = cm[pixels[1] + block[1]];
- pixels += line_size;
- block += 8;
- }
-}
-
-static void add_pixels8_c(uint8_t *restrict pixels, DCTELEM *block, int line_size)
-{
- int i;
- 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_pixels4_c(uint8_t *restrict pixels, DCTELEM *block, int line_size)
-{
- int i;
- for(i=0;i<4;i++) {
- pixels[0] += block[0];
- pixels[1] += block[1];
- pixels[2] += block[2];
- pixels[3] += block[3];
- pixels += line_size;
- block += 4;
- }
-}
-
-#if 0
-
-#define PIXOP2(OPNAME, OP) \
-static void OPNAME ## _pixels(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
-{\
- int i;\
- for(i=0; i<h; i++){\
- OP(*((uint64_t*)block), LD64(pixels));\
- pixels+=line_size;\
- block +=line_size;\
- }\
-}\
-\
-static void OPNAME ## _no_rnd_pixels_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
-{\
- int i;\
- for(i=0; i<h; i++){\
- const uint64_t a= LD64(pixels );\
- const uint64_t b= LD64(pixels+1);\
- OP(*((uint64_t*)block), (a&b) + (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
- pixels+=line_size;\
- block +=line_size;\
- }\
-}\
-\
-static void OPNAME ## _pixels_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
-{\
- int i;\
- for(i=0; i<h; i++){\
- const uint64_t a= LD64(pixels );\
- const uint64_t b= LD64(pixels+1);\
- OP(*((uint64_t*)block), (a|b) - (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
- pixels+=line_size;\
- block +=line_size;\
- }\
-}\
-\
-static void OPNAME ## _no_rnd_pixels_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
-{\
- int i;\
- for(i=0; i<h; i++){\
- const uint64_t a= LD64(pixels );\
- const uint64_t b= LD64(pixels+line_size);\
- OP(*((uint64_t*)block), (a&b) + (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
- pixels+=line_size;\
- block +=line_size;\
- }\
-}\
-\
-static void OPNAME ## _pixels_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
-{\
- int i;\
- for(i=0; i<h; i++){\
- const uint64_t a= LD64(pixels );\
- const uint64_t b= LD64(pixels+line_size);\
- OP(*((uint64_t*)block), (a|b) - (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
- pixels+=line_size;\
- block +=line_size;\
- }\
-}\
-\
-static void OPNAME ## _pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
-{\
- int i;\
- const uint64_t a= LD64(pixels );\
- const uint64_t b= LD64(pixels+1);\
- uint64_t l0= (a&0x0303030303030303ULL)\
- + (b&0x0303030303030303ULL)\
- + 0x0202020202020202ULL;\
- uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
- + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
- uint64_t l1,h1;\
-\
- pixels+=line_size;\
- for(i=0; i<h; i+=2){\
- uint64_t a= LD64(pixels );\
- uint64_t b= LD64(pixels+1);\
- l1= (a&0x0303030303030303ULL)\
- + (b&0x0303030303030303ULL);\
- h1= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
- + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
- OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
- pixels+=line_size;\
- block +=line_size;\
- a= LD64(pixels );\
- b= LD64(pixels+1);\
- l0= (a&0x0303030303030303ULL)\
- + (b&0x0303030303030303ULL)\
- + 0x0202020202020202ULL;\
- h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
- + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
- OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
- pixels+=line_size;\
- block +=line_size;\
- }\
-}\
-\
-static void OPNAME ## _no_rnd_pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
-{\
- int i;\
- const uint64_t a= LD64(pixels );\
- const uint64_t b= LD64(pixels+1);\
- uint64_t l0= (a&0x0303030303030303ULL)\
- + (b&0x0303030303030303ULL)\
- + 0x0101010101010101ULL;\
- uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
- + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
- uint64_t l1,h1;\
-\
- pixels+=line_size;\
- for(i=0; i<h; i+=2){\
- uint64_t a= LD64(pixels );\
- uint64_t b= LD64(pixels+1);\
- l1= (a&0x0303030303030303ULL)\
- + (b&0x0303030303030303ULL);\
- h1= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
- + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
- OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
- pixels+=line_size;\
- block +=line_size;\
- a= LD64(pixels );\
- b= LD64(pixels+1);\
- l0= (a&0x0303030303030303ULL)\
- + (b&0x0303030303030303ULL)\
- + 0x0101010101010101ULL;\
- h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
- + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
- OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
- pixels+=line_size;\
- block +=line_size;\
- }\
-}\
-\
-CALL_2X_PIXELS(OPNAME ## _pixels16_c , OPNAME ## _pixels_c , 8)\
-CALL_2X_PIXELS(OPNAME ## _pixels16_x2_c , OPNAME ## _pixels_x2_c , 8)\
-CALL_2X_PIXELS(OPNAME ## _pixels16_y2_c , OPNAME ## _pixels_y2_c , 8)\
-CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_c, OPNAME ## _pixels_xy2_c, 8)\
-CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2_c , OPNAME ## _no_rnd_pixels_x2_c , 8)\
-CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2_c , OPNAME ## _no_rnd_pixels_y2_c , 8)\
-CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_c, OPNAME ## _no_rnd_pixels_xy2_c, 8)
-
-#define op_avg(a, b) a = ( ((a)|(b)) - ((((a)^(b))&0xFEFEFEFEFEFEFEFEULL)>>1) )
-#else // 64 bit variant
-
-#define PIXOP2(OPNAME, OP) \
-static void OPNAME ## _pixels2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
- int i;\
- for(i=0; i<h; i++){\
- OP(*((uint16_t*)(block )), LD16(pixels ));\
- pixels+=line_size;\
- block +=line_size;\
- }\
-}\
-static void OPNAME ## _pixels4_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
- int i;\
- for(i=0; i<h; i++){\
- OP(*((uint32_t*)(block )), LD32(pixels ));\
- pixels+=line_size;\
- block +=line_size;\
- }\
-}\
-static void OPNAME ## _pixels8_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
- int i;\
- for(i=0; i<h; i++){\
- OP(*((uint32_t*)(block )), LD32(pixels ));\
- OP(*((uint32_t*)(block+4)), LD32(pixels+4));\
- pixels+=line_size;\
- block +=line_size;\
- }\
-}\
-static inline void OPNAME ## _no_rnd_pixels8_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
- OPNAME ## _pixels8_c(block, pixels, line_size, h);\
-}\
-\
-static inline void OPNAME ## _no_rnd_pixels8_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
- int src_stride1, int src_stride2, int h){\
- int i;\
- for(i=0; i<h; i++){\
- uint32_t a,b;\
- a= LD32(&src1[i*src_stride1 ]);\
- b= LD32(&src2[i*src_stride2 ]);\
- OP(*((uint32_t*)&dst[i*dst_stride ]), no_rnd_avg32(a, b));\
- a= LD32(&src1[i*src_stride1+4]);\
- b= LD32(&src2[i*src_stride2+4]);\
- OP(*((uint32_t*)&dst[i*dst_stride+4]), no_rnd_avg32(a, b));\
- }\
-}\
-\
-static inline void OPNAME ## _pixels8_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
- int src_stride1, int src_stride2, int h){\
- int i;\
- for(i=0; i<h; i++){\
- uint32_t a,b;\
- a= LD32(&src1[i*src_stride1 ]);\
- b= LD32(&src2[i*src_stride2 ]);\
- OP(*((uint32_t*)&dst[i*dst_stride ]), rnd_avg32(a, b));\
- a= LD32(&src1[i*src_stride1+4]);\
- b= LD32(&src2[i*src_stride2+4]);\
- OP(*((uint32_t*)&dst[i*dst_stride+4]), rnd_avg32(a, b));\
- }\
-}\
-\
-static inline void OPNAME ## _pixels4_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
- int src_stride1, int src_stride2, int h){\
- int i;\
- for(i=0; i<h; i++){\
- uint32_t a,b;\
- a= LD32(&src1[i*src_stride1 ]);\
- b= LD32(&src2[i*src_stride2 ]);\
- OP(*((uint32_t*)&dst[i*dst_stride ]), rnd_avg32(a, b));\
- }\
-}\
-\
-static inline void OPNAME ## _pixels2_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
- int src_stride1, int src_stride2, int h){\
- int i;\
- for(i=0; i<h; i++){\
- uint32_t a,b;\
- a= LD16(&src1[i*src_stride1 ]);\
- b= LD16(&src2[i*src_stride2 ]);\
- OP(*((uint16_t*)&dst[i*dst_stride ]), rnd_avg32(a, b));\
- }\
-}\
-\
-static inline void OPNAME ## _pixels16_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
- int src_stride1, int src_stride2, int h){\
- OPNAME ## _pixels8_l2(dst , src1 , src2 , dst_stride, src_stride1, src_stride2, h);\
- OPNAME ## _pixels8_l2(dst+8, src1+8, src2+8, dst_stride, src_stride1, src_stride2, h);\
-}\
-\
-static inline void OPNAME ## _no_rnd_pixels16_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
- int src_stride1, int src_stride2, int h){\
- OPNAME ## _no_rnd_pixels8_l2(dst , src1 , src2 , dst_stride, src_stride1, src_stride2, h);\
- OPNAME ## _no_rnd_pixels8_l2(dst+8, src1+8, src2+8, dst_stride, src_stride1, src_stride2, h);\
-}\
-\
-static inline void OPNAME ## _no_rnd_pixels8_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
- OPNAME ## _no_rnd_pixels8_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
-}\
-\
-static inline void OPNAME ## _pixels8_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
- OPNAME ## _pixels8_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
-}\
-\
-static inline void OPNAME ## _no_rnd_pixels8_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
- OPNAME ## _no_rnd_pixels8_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
-}\
-\
-static inline void OPNAME ## _pixels8_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
- OPNAME ## _pixels8_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
-}\
-\
-static inline void OPNAME ## _pixels8_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
- int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
- int i;\
- for(i=0; i<h; i++){\
- uint32_t a, b, c, d, l0, l1, h0, h1;\
- a= LD32(&src1[i*src_stride1]);\
- b= LD32(&src2[i*src_stride2]);\
- c= LD32(&src3[i*src_stride3]);\
- d= LD32(&src4[i*src_stride4]);\
- l0= (a&0x03030303UL)\
- + (b&0x03030303UL)\
- + 0x02020202UL;\
- h0= ((a&0xFCFCFCFCUL)>>2)\
- + ((b&0xFCFCFCFCUL)>>2);\
- l1= (c&0x03030303UL)\
- + (d&0x03030303UL);\
- h1= ((c&0xFCFCFCFCUL)>>2)\
- + ((d&0xFCFCFCFCUL)>>2);\
- OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
- a= LD32(&src1[i*src_stride1+4]);\
- b= LD32(&src2[i*src_stride2+4]);\
- c= LD32(&src3[i*src_stride3+4]);\
- d= LD32(&src4[i*src_stride4+4]);\
- l0= (a&0x03030303UL)\
- + (b&0x03030303UL)\
- + 0x02020202UL;\
- h0= ((a&0xFCFCFCFCUL)>>2)\
- + ((b&0xFCFCFCFCUL)>>2);\
- l1= (c&0x03030303UL)\
- + (d&0x03030303UL);\
- h1= ((c&0xFCFCFCFCUL)>>2)\
- + ((d&0xFCFCFCFCUL)>>2);\
- OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
- }\
-}\
-\
-static inline void OPNAME ## _pixels4_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
- OPNAME ## _pixels4_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
-}\
-\
-static inline void OPNAME ## _pixels4_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
- OPNAME ## _pixels4_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
-}\
-\
-static inline void OPNAME ## _pixels2_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
- OPNAME ## _pixels2_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
-}\
-\
-static inline void OPNAME ## _pixels2_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
- OPNAME ## _pixels2_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
-}\
-\
-static inline void OPNAME ## _no_rnd_pixels8_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
- int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
- int i;\
- for(i=0; i<h; i++){\
- uint32_t a, b, c, d, l0, l1, h0, h1;\
- a= LD32(&src1[i*src_stride1]);\
- b= LD32(&src2[i*src_stride2]);\
- c= LD32(&src3[i*src_stride3]);\
- d= LD32(&src4[i*src_stride4]);\
- l0= (a&0x03030303UL)\
- + (b&0x03030303UL)\
- + 0x01010101UL;\
- h0= ((a&0xFCFCFCFCUL)>>2)\
- + ((b&0xFCFCFCFCUL)>>2);\
- l1= (c&0x03030303UL)\
- + (d&0x03030303UL);\
- h1= ((c&0xFCFCFCFCUL)>>2)\
- + ((d&0xFCFCFCFCUL)>>2);\
- OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
- a= LD32(&src1[i*src_stride1+4]);\
- b= LD32(&src2[i*src_stride2+4]);\
- c= LD32(&src3[i*src_stride3+4]);\
- d= LD32(&src4[i*src_stride4+4]);\
- l0= (a&0x03030303UL)\
- + (b&0x03030303UL)\
- + 0x01010101UL;\
- h0= ((a&0xFCFCFCFCUL)>>2)\
- + ((b&0xFCFCFCFCUL)>>2);\
- l1= (c&0x03030303UL)\
- + (d&0x03030303UL);\
- h1= ((c&0xFCFCFCFCUL)>>2)\
- + ((d&0xFCFCFCFCUL)>>2);\
- OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
- }\
-}\
-static inline void OPNAME ## _pixels16_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
- int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
- OPNAME ## _pixels8_l4(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
- OPNAME ## _pixels8_l4(dst+8, src1+8, src2+8, src3+8, src4+8, dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
-}\
-static inline void OPNAME ## _no_rnd_pixels16_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
- int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
- OPNAME ## _no_rnd_pixels8_l4(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
- OPNAME ## _no_rnd_pixels8_l4(dst+8, src1+8, src2+8, src3+8, src4+8, dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
-}\
-\
-static inline void OPNAME ## _pixels2_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
-{\
- int i, a0, b0, a1, b1;\
- a0= pixels[0];\
- b0= pixels[1] + 2;\
- a0 += b0;\
- b0 += pixels[2];\
-\
- pixels+=line_size;\
- for(i=0; i<h; i+=2){\
- a1= pixels[0];\
- b1= pixels[1];\
- a1 += b1;\
- b1 += pixels[2];\
-\
- block[0]= (a1+a0)>>2; /* FIXME non put */\
- block[1]= (b1+b0)>>2;\
-\
- pixels+=line_size;\
- block +=line_size;\
-\
- a0= pixels[0];\
- b0= pixels[1] + 2;\
- a0 += b0;\
- b0 += pixels[2];\
-\
- block[0]= (a1+a0)>>2;\
- block[1]= (b1+b0)>>2;\
- pixels+=line_size;\
- block +=line_size;\
- }\
-}\
-\
-static inline void OPNAME ## _pixels4_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
-{\
- int i;\
- const uint32_t a= LD32(pixels );\
- const uint32_t b= LD32(pixels+1);\
- uint32_t l0= (a&0x03030303UL)\
- + (b&0x03030303UL)\
- + 0x02020202UL;\
- uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
- + ((b&0xFCFCFCFCUL)>>2);\
- uint32_t l1,h1;\
-\
- pixels+=line_size;\
- for(i=0; i<h; i+=2){\
- uint32_t a= LD32(pixels );\
- uint32_t b= LD32(pixels+1);\
- l1= (a&0x03030303UL)\
- + (b&0x03030303UL);\
- h1= ((a&0xFCFCFCFCUL)>>2)\
- + ((b&0xFCFCFCFCUL)>>2);\
- OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
- pixels+=line_size;\
- block +=line_size;\
- a= LD32(pixels );\
- b= LD32(pixels+1);\
- l0= (a&0x03030303UL)\
- + (b&0x03030303UL)\
- + 0x02020202UL;\
- h0= ((a&0xFCFCFCFCUL)>>2)\
- + ((b&0xFCFCFCFCUL)>>2);\
- OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
- pixels+=line_size;\
- block +=line_size;\
- }\
-}\
-\
-static inline void OPNAME ## _pixels8_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
-{\
- int j;\
- for(j=0; j<2; j++){\
- int i;\
- const uint32_t a= LD32(pixels );\
- const uint32_t b= LD32(pixels+1);\
- uint32_t l0= (a&0x03030303UL)\
- + (b&0x03030303UL)\
- + 0x02020202UL;\
- uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
- + ((b&0xFCFCFCFCUL)>>2);\
- uint32_t l1,h1;\
-\
- pixels+=line_size;\
- for(i=0; i<h; i+=2){\
- uint32_t a= LD32(pixels );\
- uint32_t b= LD32(pixels+1);\
- l1= (a&0x03030303UL)\
- + (b&0x03030303UL);\
- h1= ((a&0xFCFCFCFCUL)>>2)\
- + ((b&0xFCFCFCFCUL)>>2);\
- OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
- pixels+=line_size;\
- block +=line_size;\
- a= LD32(pixels );\
- b= LD32(pixels+1);\
- l0= (a&0x03030303UL)\
- + (b&0x03030303UL)\
- + 0x02020202UL;\
- h0= ((a&0xFCFCFCFCUL)>>2)\
- + ((b&0xFCFCFCFCUL)>>2);\
- OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
- pixels+=line_size;\
- block +=line_size;\
- }\
- pixels+=4-line_size*(h+1);\
- block +=4-line_size*h;\
- }\
-}\
-\
-static inline void OPNAME ## _no_rnd_pixels8_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
-{\
- int j;\
- for(j=0; j<2; j++){\
- int i;\
- const uint32_t a= LD32(pixels );\
- const uint32_t b= LD32(pixels+1);\
- uint32_t l0= (a&0x03030303UL)\
- + (b&0x03030303UL)\
- + 0x01010101UL;\
- uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
- + ((b&0xFCFCFCFCUL)>>2);\
- uint32_t l1,h1;\
-\
- pixels+=line_size;\
- for(i=0; i<h; i+=2){\
- uint32_t a= LD32(pixels );\
- uint32_t b= LD32(pixels+1);\
- l1= (a&0x03030303UL)\
- + (b&0x03030303UL);\
- h1= ((a&0xFCFCFCFCUL)>>2)\
- + ((b&0xFCFCFCFCUL)>>2);\
- OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
- pixels+=line_size;\
- block +=line_size;\
- a= LD32(pixels );\
- b= LD32(pixels+1);\
- l0= (a&0x03030303UL)\
- + (b&0x03030303UL)\
- + 0x01010101UL;\
- h0= ((a&0xFCFCFCFCUL)>>2)\
- + ((b&0xFCFCFCFCUL)>>2);\
- OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
- pixels+=line_size;\
- block +=line_size;\
- }\
- pixels+=4-line_size*(h+1);\
- block +=4-line_size*h;\
- }\
-}\
-\
-CALL_2X_PIXELS(OPNAME ## _pixels16_c , OPNAME ## _pixels8_c , 8)\
-CALL_2X_PIXELS(OPNAME ## _pixels16_x2_c , OPNAME ## _pixels8_x2_c , 8)\
-CALL_2X_PIXELS(OPNAME ## _pixels16_y2_c , OPNAME ## _pixels8_y2_c , 8)\
-CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_c, OPNAME ## _pixels8_xy2_c, 8)\
-CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_c , OPNAME ## _pixels8_c , 8)\
-CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2_c , OPNAME ## _no_rnd_pixels8_x2_c , 8)\
-CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2_c , OPNAME ## _no_rnd_pixels8_y2_c , 8)\
-CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_c, OPNAME ## _no_rnd_pixels8_xy2_c, 8)\
-
-#define op_avg(a, b) a = rnd_avg32(a, b)
-#endif
-#define op_put(a, b) a = b
-
-PIXOP2(avg, op_avg)
-PIXOP2(put, op_put)
-#undef op_avg
-#undef op_put
-
-#define avg2(a,b) ((a+b+1)>>1)
-#define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
-
-static void put_no_rnd_pixels16_l2_c(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h){
- put_no_rnd_pixels16_l2(dst, a, b, stride, stride, stride, h);
-}
-
-static void put_no_rnd_pixels8_l2_c(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h){
- put_no_rnd_pixels8_l2(dst, a, b, stride, stride, stride, h);
-}
-
-static void gmc1_c(uint8_t *dst, uint8_t *src, int stride, int h, int x16, int y16, int rounder)
-{
- const int A=(16-x16)*(16-y16);
- const int B=( x16)*(16-y16);
- const int C=(16-x16)*( y16);
- const int D=( x16)*( y16);
- int i;
-
- for(i=0; i<h; i++)
- {
- dst[0]= (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + rounder)>>8;
- dst[1]= (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + rounder)>>8;
- dst[2]= (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + rounder)>>8;
- dst[3]= (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + rounder)>>8;
- dst[4]= (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + rounder)>>8;
- dst[5]= (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + rounder)>>8;
- dst[6]= (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + rounder)>>8;
- dst[7]= (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + rounder)>>8;
- dst+= stride;
- src+= stride;
- }
-}
-
-void ff_gmc_c(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)
-{
- int y, vx, vy;
- const int s= 1<<shift;
-
- width--;
- height--;
-
- for(y=0; y<h; y++){
- int x;
-
- vx= ox;
- vy= oy;
- for(x=0; x<8; x++){ //XXX FIXME optimize
- int src_x, src_y, frac_x, frac_y, index;
-
- src_x= vx>>16;
- src_y= vy>>16;
- frac_x= src_x&(s-1);
- frac_y= src_y&(s-1);
- src_x>>=shift;
- src_y>>=shift;
-
- if((unsigned)src_x < width){
- if((unsigned)src_y < height){
- index= src_x + src_y*stride;
- dst[y*stride + x]= ( ( src[index ]*(s-frac_x)
- + src[index +1]* frac_x )*(s-frac_y)
- + ( src[index+stride ]*(s-frac_x)
- + src[index+stride+1]* frac_x )* frac_y
- + r)>>(shift*2);
- }else{
- index= src_x + clip(src_y, 0, height)*stride;
- dst[y*stride + x]= ( ( src[index ]*(s-frac_x)
- + src[index +1]* frac_x )*s
- + r)>>(shift*2);
- }
- }else{
- if((unsigned)src_y < height){
- index= clip(src_x, 0, width) + src_y*stride;
- dst[y*stride + x]= ( ( src[index ]*(s-frac_y)
- + src[index+stride ]* frac_y )*s
- + r)>>(shift*2);
- }else{
- index= clip(src_x, 0, width) + clip(src_y, 0, height)*stride;
- dst[y*stride + x]= src[index ];
- }
- }
-
- vx+= dxx;
- vy+= dyx;
- }
- ox += dxy;
- oy += dyy;
- }
-}
-
-static inline void put_tpel_pixels_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- switch(width){
- case 2: put_pixels2_c (dst, src, stride, height); break;
- case 4: put_pixels4_c (dst, src, stride, height); break;
- case 8: put_pixels8_c (dst, src, stride, height); break;
- case 16:put_pixels16_c(dst, src, stride, height); break;
- }
-}
-
-static inline void put_tpel_pixels_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- int i,j;
- for (i=0; i < height; i++) {
- for (j=0; j < width; j++) {
- dst[j] = (683*(2*src[j] + src[j+1] + 1)) >> 11;
- }
- src += stride;
- dst += stride;
- }
-}
-
-static inline void put_tpel_pixels_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- int i,j;
- for (i=0; i < height; i++) {
- for (j=0; j < width; j++) {
- dst[j] = (683*(src[j] + 2*src[j+1] + 1)) >> 11;
- }
- src += stride;
- dst += stride;
- }
-}
-
-static inline void put_tpel_pixels_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- int i,j;
- for (i=0; i < height; i++) {
- for (j=0; j < width; j++) {
- dst[j] = (683*(2*src[j] + src[j+stride] + 1)) >> 11;
- }
- src += stride;
- dst += stride;
- }
-}
-
-static inline void put_tpel_pixels_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- int i,j;
- for (i=0; i < height; i++) {
- for (j=0; j < width; j++) {
- dst[j] = (2731*(4*src[j] + 3*src[j+1] + 3*src[j+stride] + 2*src[j+stride+1] + 6)) >> 15;
- }
- src += stride;
- dst += stride;
- }
-}
-
-static inline void put_tpel_pixels_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- int i,j;
- for (i=0; i < height; i++) {
- for (j=0; j < width; j++) {
- dst[j] = (2731*(3*src[j] + 2*src[j+1] + 4*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15;
- }
- src += stride;
- dst += stride;
- }
-}
-
-static inline void put_tpel_pixels_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- int i,j;
- for (i=0; i < height; i++) {
- for (j=0; j < width; j++) {
- dst[j] = (683*(src[j] + 2*src[j+stride] + 1)) >> 11;
- }
- src += stride;
- dst += stride;
- }
-}
-
-static inline void put_tpel_pixels_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- int i,j;
- for (i=0; i < height; i++) {
- for (j=0; j < width; j++) {
- dst[j] = (2731*(3*src[j] + 4*src[j+1] + 2*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15;
- }
- src += stride;
- dst += stride;
- }
-}
-
-static inline void put_tpel_pixels_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- int i,j;
- for (i=0; i < height; i++) {
- for (j=0; j < width; j++) {
- dst[j] = (2731*(2*src[j] + 3*src[j+1] + 3*src[j+stride] + 4*src[j+stride+1] + 6)) >> 15;
- }
- src += stride;
- dst += stride;
- }
-}
-
-static inline void avg_tpel_pixels_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- switch(width){
- case 2: avg_pixels2_c (dst, src, stride, height); break;
- case 4: avg_pixels4_c (dst, src, stride, height); break;
- case 8: avg_pixels8_c (dst, src, stride, height); break;
- case 16:avg_pixels16_c(dst, src, stride, height); break;
- }
-}
-
-static inline void avg_tpel_pixels_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- int i,j;
- for (i=0; i < height; i++) {
- for (j=0; j < width; j++) {
- dst[j] = (dst[j] + ((683*(2*src[j] + src[j+1] + 1)) >> 11) + 1) >> 1;
- }
- src += stride;
- dst += stride;
- }
-}
-
-static inline void avg_tpel_pixels_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- int i,j;
- for (i=0; i < height; i++) {
- for (j=0; j < width; j++) {
- dst[j] = (dst[j] + ((683*(src[j] + 2*src[j+1] + 1)) >> 11) + 1) >> 1;
- }
- src += stride;
- dst += stride;
- }
-}
-
-static inline void avg_tpel_pixels_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- int i,j;
- for (i=0; i < height; i++) {
- for (j=0; j < width; j++) {
- dst[j] = (dst[j] + ((683*(2*src[j] + src[j+stride] + 1)) >> 11) + 1) >> 1;
- }
- src += stride;
- dst += stride;
- }
-}
-
-static inline void avg_tpel_pixels_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- int i,j;
- for (i=0; i < height; i++) {
- for (j=0; j < width; j++) {
- dst[j] = (dst[j] + ((2731*(4*src[j] + 3*src[j+1] + 3*src[j+stride] + 2*src[j+stride+1] + 6)) >> 15) + 1) >> 1;
- }
- src += stride;
- dst += stride;
- }
-}
-
-static inline void avg_tpel_pixels_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- int i,j;
- for (i=0; i < height; i++) {
- for (j=0; j < width; j++) {
- dst[j] = (dst[j] + ((2731*(3*src[j] + 2*src[j+1] + 4*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15) + 1) >> 1;
- }
- src += stride;
- dst += stride;
- }
-}
-
-static inline void avg_tpel_pixels_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- int i,j;
- for (i=0; i < height; i++) {
- for (j=0; j < width; j++) {
- dst[j] = (dst[j] + ((683*(src[j] + 2*src[j+stride] + 1)) >> 11) + 1) >> 1;
- }
- src += stride;
- dst += stride;
- }
-}
-
-static inline void avg_tpel_pixels_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- int i,j;
- for (i=0; i < height; i++) {
- for (j=0; j < width; j++) {
- dst[j] = (dst[j] + ((2731*(3*src[j] + 4*src[j+1] + 2*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15) + 1) >> 1;
- }
- src += stride;
- dst += stride;
- }
-}
-
-static inline void avg_tpel_pixels_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- int i,j;
- for (i=0; i < height; i++) {
- for (j=0; j < width; j++) {
- dst[j] = (dst[j] + ((2731*(2*src[j] + 3*src[j+1] + 3*src[j+stride] + 4*src[j+stride+1] + 6)) >> 15) + 1) >> 1;
- }
- src += stride;
- dst += stride;
- }
-}
-#if 0
-#define TPEL_WIDTH(width)\
-static void put_tpel_pixels ## width ## _mc00_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
- void put_tpel_pixels_mc00_c(dst, src, stride, width, height);}\
-static void put_tpel_pixels ## width ## _mc10_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
- void put_tpel_pixels_mc10_c(dst, src, stride, width, height);}\
-static void put_tpel_pixels ## width ## _mc20_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
- void put_tpel_pixels_mc20_c(dst, src, stride, width, height);}\
-static void put_tpel_pixels ## width ## _mc01_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
- void put_tpel_pixels_mc01_c(dst, src, stride, width, height);}\
-static void put_tpel_pixels ## width ## _mc11_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
- void put_tpel_pixels_mc11_c(dst, src, stride, width, height);}\
-static void put_tpel_pixels ## width ## _mc21_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
- void put_tpel_pixels_mc21_c(dst, src, stride, width, height);}\
-static void put_tpel_pixels ## width ## _mc02_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
- void put_tpel_pixels_mc02_c(dst, src, stride, width, height);}\
-static void put_tpel_pixels ## width ## _mc12_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
- void put_tpel_pixels_mc12_c(dst, src, stride, width, height);}\
-static void put_tpel_pixels ## width ## _mc22_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
- void put_tpel_pixels_mc22_c(dst, src, stride, width, height);}
-#endif
-
-#define H264_CHROMA_MC(OPNAME, OP)\
-static void OPNAME ## h264_chroma_mc2_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
- const int A=(8-x)*(8-y);\
- const int B=( x)*(8-y);\
- const int C=(8-x)*( y);\
- const int D=( x)*( y);\
- int i;\
- \
- assert(x<8 && y<8 && x>=0 && y>=0);\
-\
- for(i=0; i<h; i++)\
- {\
- OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
- OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
- dst+= stride;\
- src+= stride;\
- }\
-}\
-\
-static void OPNAME ## h264_chroma_mc4_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
- const int A=(8-x)*(8-y);\
- const int B=( x)*(8-y);\
- const int C=(8-x)*( y);\
- const int D=( x)*( y);\
- int i;\
- \
- assert(x<8 && y<8 && x>=0 && y>=0);\
-\
- for(i=0; i<h; i++)\
- {\
- OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
- OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
- OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\
- OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\
- dst+= stride;\
- src+= stride;\
- }\
-}\
-\
-static void OPNAME ## h264_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
- const int A=(8-x)*(8-y);\
- const int B=( x)*(8-y);\
- const int C=(8-x)*( y);\
- const int D=( x)*( y);\
- int i;\
- \
- assert(x<8 && y<8 && x>=0 && y>=0);\
-\
- for(i=0; i<h; i++)\
- {\
- OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
- OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
- OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\
- OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\
- OP(dst[4], (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5]));\
- OP(dst[5], (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6]));\
- OP(dst[6], (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7]));\
- OP(dst[7], (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8]));\
- dst+= stride;\
- src+= stride;\
- }\
-}
-
-#define op_avg(a, b) a = (((a)+(((b) + 32)>>6)+1)>>1)
-#define op_put(a, b) a = (((b) + 32)>>6)
-
-H264_CHROMA_MC(put_ , op_put)
-H264_CHROMA_MC(avg_ , op_avg)
-#undef op_avg
-#undef op_put
-
-static void put_no_rnd_h264_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){
- const int A=(8-x)*(8-y);
- const int B=( x)*(8-y);
- const int C=(8-x)*( y);
- const int D=( x)*( y);
- int i;
-
- assert(x<8 && y<8 && x>=0 && y>=0);
-
- for(i=0; i<h; i++)
- {
- dst[0] = (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + 32 - 4) >> 6;
- dst[1] = (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6;
- dst[2] = (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6;
- dst[3] = (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6;
- dst[4] = (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + 32 - 4) >> 6;
- dst[5] = (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + 32 - 4) >> 6;
- dst[6] = (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + 32 - 4) >> 6;
- dst[7] = (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + 32 - 4) >> 6;
- dst+= stride;
- src+= stride;
- }
-}
-
-#define QPEL_MC(r, OPNAME, RND, OP) \
-static void OPNAME ## mpeg4_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
- int i;\
- for(i=0; i<h; i++)\
- {\
- OP(dst[0], (src[0]+src[1])*20 - (src[0]+src[2])*6 + (src[1]+src[3])*3 - (src[2]+src[4]));\
- OP(dst[1], (src[1]+src[2])*20 - (src[0]+src[3])*6 + (src[0]+src[4])*3 - (src[1]+src[5]));\
- OP(dst[2], (src[2]+src[3])*20 - (src[1]+src[4])*6 + (src[0]+src[5])*3 - (src[0]+src[6]));\
- OP(dst[3], (src[3]+src[4])*20 - (src[2]+src[5])*6 + (src[1]+src[6])*3 - (src[0]+src[7]));\
- OP(dst[4], (src[4]+src[5])*20 - (src[3]+src[6])*6 + (src[2]+src[7])*3 - (src[1]+src[8]));\
- OP(dst[5], (src[5]+src[6])*20 - (src[4]+src[7])*6 + (src[3]+src[8])*3 - (src[2]+src[8]));\
- OP(dst[6], (src[6]+src[7])*20 - (src[5]+src[8])*6 + (src[4]+src[8])*3 - (src[3]+src[7]));\
- OP(dst[7], (src[7]+src[8])*20 - (src[6]+src[8])*6 + (src[5]+src[7])*3 - (src[4]+src[6]));\
- dst+=dstStride;\
- src+=srcStride;\
- }\
-}\
-\
-static void OPNAME ## mpeg4_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
- const int w=8;\
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
- int i;\
- for(i=0; i<w; i++)\
- {\
- const int src0= src[0*srcStride];\
- const int src1= src[1*srcStride];\
- const int src2= src[2*srcStride];\
- const int src3= src[3*srcStride];\
- const int src4= src[4*srcStride];\
- const int src5= src[5*srcStride];\
- const int src6= src[6*srcStride];\
- const int src7= src[7*srcStride];\
- const int src8= src[8*srcStride];\
- OP(dst[0*dstStride], (src0+src1)*20 - (src0+src2)*6 + (src1+src3)*3 - (src2+src4));\
- OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*6 + (src0+src4)*3 - (src1+src5));\
- OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*6 + (src0+src5)*3 - (src0+src6));\
- OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*6 + (src1+src6)*3 - (src0+src7));\
- OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*6 + (src2+src7)*3 - (src1+src8));\
- OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*6 + (src3+src8)*3 - (src2+src8));\
- OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*6 + (src4+src8)*3 - (src3+src7));\
- OP(dst[7*dstStride], (src7+src8)*20 - (src6+src8)*6 + (src5+src7)*3 - (src4+src6));\
- dst++;\
- src++;\
- }\
-}\
-\
-static void OPNAME ## mpeg4_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
- int i;\
- \
- for(i=0; i<h; i++)\
- {\
- OP(dst[ 0], (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]));\
- OP(dst[ 1], (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]));\
- OP(dst[ 2], (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]));\
- OP(dst[ 3], (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]));\
- OP(dst[ 4], (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]));\
- OP(dst[ 5], (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]));\
- OP(dst[ 6], (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]));\
- OP(dst[ 7], (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]));\
- OP(dst[ 8], (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]));\
- OP(dst[ 9], (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]));\
- OP(dst[10], (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]));\
- OP(dst[11], (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]));\
- OP(dst[12], (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]));\
- OP(dst[13], (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]));\
- OP(dst[14], (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]));\
- OP(dst[15], (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]));\
- dst+=dstStride;\
- src+=srcStride;\
- }\
-}\
-\
-static void OPNAME ## mpeg4_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
- int i;\
- const int w=16;\
- for(i=0; i<w; i++)\
- {\
- const int src0= src[0*srcStride];\
- const int src1= src[1*srcStride];\
- const int src2= src[2*srcStride];\
- const int src3= src[3*srcStride];\
- const int src4= src[4*srcStride];\
- const int src5= src[5*srcStride];\
- const int src6= src[6*srcStride];\
- const int src7= src[7*srcStride];\
- const int src8= src[8*srcStride];\
- const int src9= src[9*srcStride];\
- const int src10= src[10*srcStride];\
- const int src11= src[11*srcStride];\
- const int src12= src[12*srcStride];\
- const int src13= src[13*srcStride];\
- const int src14= src[14*srcStride];\
- const int src15= src[15*srcStride];\
- const int src16= src[16*srcStride];\
- OP(dst[ 0*dstStride], (src0 +src1 )*20 - (src0 +src2 )*6 + (src1 +src3 )*3 - (src2 +src4 ));\
- OP(dst[ 1*dstStride], (src1 +src2 )*20 - (src0 +src3 )*6 + (src0 +src4 )*3 - (src1 +src5 ));\
- OP(dst[ 2*dstStride], (src2 +src3 )*20 - (src1 +src4 )*6 + (src0 +src5 )*3 - (src0 +src6 ));\
- OP(dst[ 3*dstStride], (src3 +src4 )*20 - (src2 +src5 )*6 + (src1 +src6 )*3 - (src0 +src7 ));\
- OP(dst[ 4*dstStride], (src4 +src5 )*20 - (src3 +src6 )*6 + (src2 +src7 )*3 - (src1 +src8 ));\
- OP(dst[ 5*dstStride], (src5 +src6 )*20 - (src4 +src7 )*6 + (src3 +src8 )*3 - (src2 +src9 ));\
- OP(dst[ 6*dstStride], (src6 +src7 )*20 - (src5 +src8 )*6 + (src4 +src9 )*3 - (src3 +src10));\
- OP(dst[ 7*dstStride], (src7 +src8 )*20 - (src6 +src9 )*6 + (src5 +src10)*3 - (src4 +src11));\
- OP(dst[ 8*dstStride], (src8 +src9 )*20 - (src7 +src10)*6 + (src6 +src11)*3 - (src5 +src12));\
- OP(dst[ 9*dstStride], (src9 +src10)*20 - (src8 +src11)*6 + (src7 +src12)*3 - (src6 +src13));\
- OP(dst[10*dstStride], (src10+src11)*20 - (src9 +src12)*6 + (src8 +src13)*3 - (src7 +src14));\
- OP(dst[11*dstStride], (src11+src12)*20 - (src10+src13)*6 + (src9 +src14)*3 - (src8 +src15));\
- OP(dst[12*dstStride], (src12+src13)*20 - (src11+src14)*6 + (src10+src15)*3 - (src9 +src16));\
- OP(dst[13*dstStride], (src13+src14)*20 - (src12+src15)*6 + (src11+src16)*3 - (src10+src16));\
- OP(dst[14*dstStride], (src14+src15)*20 - (src13+src16)*6 + (src12+src16)*3 - (src11+src15));\
- OP(dst[15*dstStride], (src15+src16)*20 - (src14+src16)*6 + (src13+src15)*3 - (src12+src14));\
- dst++;\
- src++;\
- }\
-}\
-\
-static void OPNAME ## qpel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## pixels8_c(dst, src, stride, 8);\
-}\
-\
-static void OPNAME ## qpel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t half[64];\
- put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
- OPNAME ## pixels8_l2(dst, src, half, stride, stride, 8, 8);\
-}\
-\
-static void OPNAME ## qpel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## mpeg4_qpel8_h_lowpass(dst, src, stride, stride, 8);\
-}\
-\
-static void OPNAME ## qpel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t half[64];\
- put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
- OPNAME ## pixels8_l2(dst, src+1, half, stride, stride, 8, 8);\
-}\
-\
-static void OPNAME ## qpel8_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[16*9];\
- uint8_t half[64];\
- copy_block9(full, src, 16, stride, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
- OPNAME ## pixels8_l2(dst, full, half, stride, 16, 8, 8);\
-}\
-\
-static void OPNAME ## qpel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[16*9];\
- copy_block9(full, src, 16, stride, 9);\
- OPNAME ## mpeg4_qpel8_v_lowpass(dst, full, stride, 16);\
-}\
-\
-static void OPNAME ## qpel8_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[16*9];\
- uint8_t half[64];\
- copy_block9(full, src, 16, stride, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
- OPNAME ## pixels8_l2(dst, full+16, half, stride, 16, 8, 8);\
-}\
-void ff_ ## OPNAME ## qpel8_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[16*9];\
- uint8_t halfH[72];\
- uint8_t halfV[64];\
- uint8_t halfHV[64];\
- copy_block9(full, src, 16, stride, 9);\
- put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l4(dst, full, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
-}\
-static void OPNAME ## qpel8_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[16*9];\
- uint8_t halfH[72];\
- uint8_t halfHV[64];\
- copy_block9(full, src, 16, stride, 9);\
- put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
- put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
-}\
-void ff_ ## OPNAME ## qpel8_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[16*9];\
- uint8_t halfH[72];\
- uint8_t halfV[64];\
- uint8_t halfHV[64];\
- copy_block9(full, src, 16, stride, 9);\
- put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l4(dst, full+1, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
-}\
-static void OPNAME ## qpel8_mc31_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[16*9];\
- uint8_t halfH[72];\
- uint8_t halfHV[64];\
- copy_block9(full, src, 16, stride, 9);\
- put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
- put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
-}\
-void ff_ ## OPNAME ## qpel8_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[16*9];\
- uint8_t halfH[72];\
- uint8_t halfV[64];\
- uint8_t halfHV[64];\
- copy_block9(full, src, 16, stride, 9);\
- put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l4(dst, full+16, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
-}\
-static void OPNAME ## qpel8_mc13_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[16*9];\
- uint8_t halfH[72];\
- uint8_t halfHV[64];\
- copy_block9(full, src, 16, stride, 9);\
- put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
- put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
-}\
-void ff_ ## OPNAME ## qpel8_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[16*9];\
- uint8_t halfH[72];\
- uint8_t halfV[64];\
- uint8_t halfHV[64];\
- copy_block9(full, src, 16, stride, 9);\
- put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full , 8, 16, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l4(dst, full+17, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
-}\
-static void OPNAME ## qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[16*9];\
- uint8_t halfH[72];\
- uint8_t halfHV[64];\
- copy_block9(full, src, 16, stride, 9);\
- put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
- put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
-}\
-static void OPNAME ## qpel8_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t halfH[72];\
- uint8_t halfHV[64];\
- put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
-}\
-static void OPNAME ## qpel8_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t halfH[72];\
- uint8_t halfHV[64];\
- put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
-}\
-void ff_ ## OPNAME ## qpel8_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[16*9];\
- uint8_t halfH[72];\
- uint8_t halfV[64];\
- uint8_t halfHV[64];\
- copy_block9(full, src, 16, stride, 9);\
- put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\
-}\
-static void OPNAME ## qpel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[16*9];\
- uint8_t halfH[72];\
- copy_block9(full, src, 16, stride, 9);\
- put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
- put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
- OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
-}\
-void ff_ ## OPNAME ## qpel8_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[16*9];\
- uint8_t halfH[72];\
- uint8_t halfV[64];\
- uint8_t halfHV[64];\
- copy_block9(full, src, 16, stride, 9);\
- put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\
-}\
-static void OPNAME ## qpel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[16*9];\
- uint8_t halfH[72];\
- copy_block9(full, src, 16, stride, 9);\
- put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
- put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
- OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
-}\
-static void OPNAME ## qpel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t halfH[72];\
- put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
- OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
-}\
-static void OPNAME ## qpel16_mc00_c (uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## pixels16_c(dst, src, stride, 16);\
-}\
-\
-static void OPNAME ## qpel16_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t half[256];\
- put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
- OPNAME ## pixels16_l2(dst, src, half, stride, stride, 16, 16);\
-}\
-\
-static void OPNAME ## qpel16_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## mpeg4_qpel16_h_lowpass(dst, src, stride, stride, 16);\
-}\
-\
-static void OPNAME ## qpel16_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t half[256];\
- put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
- OPNAME ## pixels16_l2(dst, src+1, half, stride, stride, 16, 16);\
-}\
-\
-static void OPNAME ## qpel16_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[24*17];\
- uint8_t half[256];\
- copy_block17(full, src, 24, stride, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
- OPNAME ## pixels16_l2(dst, full, half, stride, 24, 16, 16);\
-}\
-\
-static void OPNAME ## qpel16_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[24*17];\
- copy_block17(full, src, 24, stride, 17);\
- OPNAME ## mpeg4_qpel16_v_lowpass(dst, full, stride, 24);\
-}\
-\
-static void OPNAME ## qpel16_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[24*17];\
- uint8_t half[256];\
- copy_block17(full, src, 24, stride, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
- OPNAME ## pixels16_l2(dst, full+24, half, stride, 24, 16, 16);\
-}\
-void ff_ ## OPNAME ## qpel16_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[24*17];\
- uint8_t halfH[272];\
- uint8_t halfV[256];\
- uint8_t halfHV[256];\
- copy_block17(full, src, 24, stride, 17);\
- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l4(dst, full, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
-}\
-static void OPNAME ## qpel16_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[24*17];\
- uint8_t halfH[272];\
- uint8_t halfHV[256];\
- copy_block17(full, src, 24, stride, 17);\
- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
- put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
-}\
-void ff_ ## OPNAME ## qpel16_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[24*17];\
- uint8_t halfH[272];\
- uint8_t halfV[256];\
- uint8_t halfHV[256];\
- copy_block17(full, src, 24, stride, 17);\
- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l4(dst, full+1, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
-}\
-static void OPNAME ## qpel16_mc31_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[24*17];\
- uint8_t halfH[272];\
- uint8_t halfHV[256];\
- copy_block17(full, src, 24, stride, 17);\
- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
- put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
-}\
-void ff_ ## OPNAME ## qpel16_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[24*17];\
- uint8_t halfH[272];\
- uint8_t halfV[256];\
- uint8_t halfHV[256];\
- copy_block17(full, src, 24, stride, 17);\
- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l4(dst, full+24, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
-}\
-static void OPNAME ## qpel16_mc13_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[24*17];\
- uint8_t halfH[272];\
- uint8_t halfHV[256];\
- copy_block17(full, src, 24, stride, 17);\
- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
- put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
-}\
-void ff_ ## OPNAME ## qpel16_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[24*17];\
- uint8_t halfH[272];\
- uint8_t halfV[256];\
- uint8_t halfHV[256];\
- copy_block17(full, src, 24, stride, 17);\
- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full , 16, 24, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l4(dst, full+25, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
-}\
-static void OPNAME ## qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[24*17];\
- uint8_t halfH[272];\
- uint8_t halfHV[256];\
- copy_block17(full, src, 24, stride, 17);\
- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
- put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
-}\
-static void OPNAME ## qpel16_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t halfH[272];\
- uint8_t halfHV[256];\
- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
-}\
-static void OPNAME ## qpel16_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t halfH[272];\
- uint8_t halfHV[256];\
- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
-}\
-void ff_ ## OPNAME ## qpel16_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[24*17];\
- uint8_t halfH[272];\
- uint8_t halfV[256];\
- uint8_t halfHV[256];\
- copy_block17(full, src, 24, stride, 17);\
- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\
-}\
-static void OPNAME ## qpel16_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[24*17];\
- uint8_t halfH[272];\
- copy_block17(full, src, 24, stride, 17);\
- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
- put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
- OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
-}\
-void ff_ ## OPNAME ## qpel16_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[24*17];\
- uint8_t halfH[272];\
- uint8_t halfV[256];\
- uint8_t halfHV[256];\
- copy_block17(full, src, 24, stride, 17);\
- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\
-}\
-static void OPNAME ## qpel16_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[24*17];\
- uint8_t halfH[272];\
- copy_block17(full, src, 24, stride, 17);\
- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
- put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
- OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
-}\
-static void OPNAME ## qpel16_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t halfH[272];\
- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
- OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
-}
-
-#define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
-#define op_avg_no_rnd(a, b) a = (((a)+cm[((b) + 15)>>5])>>1)
-#define op_put(a, b) a = cm[((b) + 16)>>5]
-#define op_put_no_rnd(a, b) a = cm[((b) + 15)>>5]
-
-QPEL_MC(0, put_ , _ , op_put)
-QPEL_MC(1, put_no_rnd_, _no_rnd_, op_put_no_rnd)
-QPEL_MC(0, avg_ , _ , op_avg)
-//QPEL_MC(1, avg_no_rnd , _ , op_avg)
-#undef op_avg
-#undef op_avg_no_rnd
-#undef op_put
-#undef op_put_no_rnd
-
-#if 1
-#define H264_LOWPASS(OPNAME, OP, OP2) \
-static void OPNAME ## h264_qpel2_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
- const int h=2;\
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
- int i;\
- for(i=0; i<h; i++)\
- {\
- OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\
- OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]));\
- dst+=dstStride;\
- src+=srcStride;\
- }\
-}\
-\
-static void OPNAME ## h264_qpel2_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
- const int w=2;\
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
- int i;\
- for(i=0; i<w; i++)\
- {\
- const int srcB= src[-2*srcStride];\
- const int srcA= src[-1*srcStride];\
- const int src0= src[0 *srcStride];\
- const int src1= src[1 *srcStride];\
- const int src2= src[2 *srcStride];\
- const int src3= src[3 *srcStride];\
- const int src4= src[4 *srcStride];\
- OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
- OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
- dst++;\
- src++;\
- }\
-}\
-\
-static void OPNAME ## h264_qpel2_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
- const int h=2;\
- const int w=2;\
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
- int i;\
- src -= 2*srcStride;\
- for(i=0; i<h+5; i++)\
- {\
- tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]);\
- tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]);\
- tmp+=tmpStride;\
- src+=srcStride;\
- }\
- tmp -= tmpStride*(h+5-2);\
- for(i=0; i<w; i++)\
- {\
- const int tmpB= tmp[-2*tmpStride];\
- const int tmpA= tmp[-1*tmpStride];\
- const int tmp0= tmp[0 *tmpStride];\
- const int tmp1= tmp[1 *tmpStride];\
- const int tmp2= tmp[2 *tmpStride];\
- const int tmp3= tmp[3 *tmpStride];\
- const int tmp4= tmp[4 *tmpStride];\
- OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
- OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
- dst++;\
- tmp++;\
- }\
-}\
-static void OPNAME ## h264_qpel4_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
- const int h=4;\
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
- int i;\
- for(i=0; i<h; i++)\
- {\
- OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\
- OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]));\
- OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]));\
- OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]));\
- dst+=dstStride;\
- src+=srcStride;\
- }\
-}\
-\
-static void OPNAME ## h264_qpel4_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
- const int w=4;\
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
- int i;\
- for(i=0; i<w; i++)\
- {\
- const int srcB= src[-2*srcStride];\
- const int srcA= src[-1*srcStride];\
- const int src0= src[0 *srcStride];\
- const int src1= src[1 *srcStride];\
- const int src2= src[2 *srcStride];\
- const int src3= src[3 *srcStride];\
- const int src4= src[4 *srcStride];\
- const int src5= src[5 *srcStride];\
- const int src6= src[6 *srcStride];\
- OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
- OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
- OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
- OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
- dst++;\
- src++;\
- }\
-}\
-\
-static void OPNAME ## h264_qpel4_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
- const int h=4;\
- const int w=4;\
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
- int i;\
- src -= 2*srcStride;\
- for(i=0; i<h+5; i++)\
- {\
- tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]);\
- tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]);\
- tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]);\
- tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]);\
- tmp+=tmpStride;\
- src+=srcStride;\
- }\
- tmp -= tmpStride*(h+5-2);\
- for(i=0; i<w; i++)\
- {\
- const int tmpB= tmp[-2*tmpStride];\
- const int tmpA= tmp[-1*tmpStride];\
- const int tmp0= tmp[0 *tmpStride];\
- const int tmp1= tmp[1 *tmpStride];\
- const int tmp2= tmp[2 *tmpStride];\
- const int tmp3= tmp[3 *tmpStride];\
- const int tmp4= tmp[4 *tmpStride];\
- const int tmp5= tmp[5 *tmpStride];\
- const int tmp6= tmp[6 *tmpStride];\
- OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
- OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
- OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
- OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
- dst++;\
- tmp++;\
- }\
-}\
-\
-static void OPNAME ## h264_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
- const int h=8;\
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
- int i;\
- for(i=0; i<h; i++)\
- {\
- OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]));\
- OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]));\
- OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]));\
- OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]));\
- OP(dst[4], (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]));\
- OP(dst[5], (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]));\
- OP(dst[6], (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]));\
- OP(dst[7], (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]));\
- dst+=dstStride;\
- src+=srcStride;\
- }\
-}\
-\
-static void OPNAME ## h264_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
- const int w=8;\
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
- int i;\
- for(i=0; i<w; i++)\
- {\
- const int srcB= src[-2*srcStride];\
- const int srcA= src[-1*srcStride];\
- const int src0= src[0 *srcStride];\
- const int src1= src[1 *srcStride];\
- const int src2= src[2 *srcStride];\
- const int src3= src[3 *srcStride];\
- const int src4= src[4 *srcStride];\
- const int src5= src[5 *srcStride];\
- const int src6= src[6 *srcStride];\
- const int src7= src[7 *srcStride];\
- const int src8= src[8 *srcStride];\
- const int src9= src[9 *srcStride];\
- const int src10=src[10*srcStride];\
- OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
- OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
- OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
- OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
- OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*5 + (src2+src7));\
- OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*5 + (src3+src8));\
- OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*5 + (src4+src9));\
- OP(dst[7*dstStride], (src7+src8)*20 - (src6+src9)*5 + (src5+src10));\
- dst++;\
- src++;\
- }\
-}\
-\
-static void OPNAME ## h264_qpel8_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
- const int h=8;\
- const int w=8;\
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
- int i;\
- src -= 2*srcStride;\
- for(i=0; i<h+5; i++)\
- {\
- tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]);\
- tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]);\
- tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]);\
- tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]);\
- tmp[4]= (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]);\
- tmp[5]= (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]);\
- tmp[6]= (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]);\
- tmp[7]= (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]);\
- tmp+=tmpStride;\
- src+=srcStride;\
- }\
- tmp -= tmpStride*(h+5-2);\
- for(i=0; i<w; i++)\
- {\
- const int tmpB= tmp[-2*tmpStride];\
- const int tmpA= tmp[-1*tmpStride];\
- const int tmp0= tmp[0 *tmpStride];\
- const int tmp1= tmp[1 *tmpStride];\
- const int tmp2= tmp[2 *tmpStride];\
- const int tmp3= tmp[3 *tmpStride];\
- const int tmp4= tmp[4 *tmpStride];\
- const int tmp5= tmp[5 *tmpStride];\
- const int tmp6= tmp[6 *tmpStride];\
- const int tmp7= tmp[7 *tmpStride];\
- const int tmp8= tmp[8 *tmpStride];\
- const int tmp9= tmp[9 *tmpStride];\
- const int tmp10=tmp[10*tmpStride];\
- OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
- OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
- OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
- OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
- OP2(dst[4*dstStride], (tmp4+tmp5)*20 - (tmp3+tmp6)*5 + (tmp2+tmp7));\
- OP2(dst[5*dstStride], (tmp5+tmp6)*20 - (tmp4+tmp7)*5 + (tmp3+tmp8));\
- OP2(dst[6*dstStride], (tmp6+tmp7)*20 - (tmp5+tmp8)*5 + (tmp4+tmp9));\
- OP2(dst[7*dstStride], (tmp7+tmp8)*20 - (tmp6+tmp9)*5 + (tmp5+tmp10));\
- dst++;\
- tmp++;\
- }\
-}\
-\
-static void OPNAME ## h264_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
- OPNAME ## h264_qpel8_v_lowpass(dst , src , dstStride, srcStride);\
- OPNAME ## h264_qpel8_v_lowpass(dst+8, src+8, dstStride, srcStride);\
- src += 8*srcStride;\
- dst += 8*dstStride;\
- OPNAME ## h264_qpel8_v_lowpass(dst , src , dstStride, srcStride);\
- OPNAME ## h264_qpel8_v_lowpass(dst+8, src+8, dstStride, srcStride);\
-}\
-\
-static void OPNAME ## h264_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
- OPNAME ## h264_qpel8_h_lowpass(dst , src , dstStride, srcStride);\
- OPNAME ## h264_qpel8_h_lowpass(dst+8, src+8, dstStride, srcStride);\
- src += 8*srcStride;\
- dst += 8*dstStride;\
- OPNAME ## h264_qpel8_h_lowpass(dst , src , dstStride, srcStride);\
- OPNAME ## h264_qpel8_h_lowpass(dst+8, src+8, dstStride, srcStride);\
-}\
-\
-static void OPNAME ## h264_qpel16_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
- OPNAME ## h264_qpel8_hv_lowpass(dst , tmp , src , dstStride, tmpStride, srcStride);\
- OPNAME ## h264_qpel8_hv_lowpass(dst+8, tmp+8, src+8, dstStride, tmpStride, srcStride);\
- src += 8*srcStride;\
- dst += 8*dstStride;\
- OPNAME ## h264_qpel8_hv_lowpass(dst , tmp , src , dstStride, tmpStride, srcStride);\
- OPNAME ## h264_qpel8_hv_lowpass(dst+8, tmp+8, src+8, dstStride, tmpStride, srcStride);\
-}\
-
-#define H264_MC(OPNAME, SIZE) \
-static void OPNAME ## h264_qpel ## SIZE ## _mc00_c (uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## pixels ## SIZE ## _c(dst, src, stride, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc10_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t half[SIZE*SIZE];\
- put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\
- OPNAME ## pixels ## SIZE ## _l2(dst, src, half, stride, stride, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc20_c(uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## h264_qpel ## SIZE ## _h_lowpass(dst, src, stride, stride);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc30_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t half[SIZE*SIZE];\
- put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\
- OPNAME ## pixels ## SIZE ## _l2(dst, src+1, half, stride, stride, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc01_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[SIZE*(SIZE+5)];\
- uint8_t * const full_mid= full + SIZE*2;\
- uint8_t half[SIZE*SIZE];\
- copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
- put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\
- OPNAME ## pixels ## SIZE ## _l2(dst, full_mid, half, stride, SIZE, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc02_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[SIZE*(SIZE+5)];\
- uint8_t * const full_mid= full + SIZE*2;\
- copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
- OPNAME ## h264_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc03_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[SIZE*(SIZE+5)];\
- uint8_t * const full_mid= full + SIZE*2;\
- uint8_t half[SIZE*SIZE];\
- copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
- put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\
- OPNAME ## pixels ## SIZE ## _l2(dst, full_mid+SIZE, half, stride, SIZE, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc11_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[SIZE*(SIZE+5)];\
- uint8_t * const full_mid= full + SIZE*2;\
- uint8_t halfH[SIZE*SIZE];\
- uint8_t halfV[SIZE*SIZE];\
- put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
- copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
- put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
- OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc31_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[SIZE*(SIZE+5)];\
- uint8_t * const full_mid= full + SIZE*2;\
- uint8_t halfH[SIZE*SIZE];\
- uint8_t halfV[SIZE*SIZE];\
- put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
- copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
- put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
- OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc13_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[SIZE*(SIZE+5)];\
- uint8_t * const full_mid= full + SIZE*2;\
- uint8_t halfH[SIZE*SIZE];\
- uint8_t halfV[SIZE*SIZE];\
- put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
- copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
- put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
- OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc33_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[SIZE*(SIZE+5)];\
- uint8_t * const full_mid= full + SIZE*2;\
- uint8_t halfH[SIZE*SIZE];\
- uint8_t halfV[SIZE*SIZE];\
- put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
- copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
- put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
- OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc22_c(uint8_t *dst, uint8_t *src, int stride){\
- int16_t tmp[SIZE*(SIZE+5)];\
- OPNAME ## h264_qpel ## SIZE ## _hv_lowpass(dst, tmp, src, stride, SIZE, stride);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc21_c(uint8_t *dst, uint8_t *src, int stride){\
- int16_t tmp[SIZE*(SIZE+5)];\
- uint8_t halfH[SIZE*SIZE];\
- uint8_t halfHV[SIZE*SIZE];\
- put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
- put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
- OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc23_c(uint8_t *dst, uint8_t *src, int stride){\
- int16_t tmp[SIZE*(SIZE+5)];\
- uint8_t halfH[SIZE*SIZE];\
- uint8_t halfHV[SIZE*SIZE];\
- put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
- put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
- OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc12_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[SIZE*(SIZE+5)];\
- uint8_t * const full_mid= full + SIZE*2;\
- int16_t tmp[SIZE*(SIZE+5)];\
- uint8_t halfV[SIZE*SIZE];\
- uint8_t halfHV[SIZE*SIZE];\
- copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
- put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
- put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
- OPNAME ## pixels ## SIZE ## _l2(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc32_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[SIZE*(SIZE+5)];\
- uint8_t * const full_mid= full + SIZE*2;\
- int16_t tmp[SIZE*(SIZE+5)];\
- uint8_t halfV[SIZE*SIZE];\
- uint8_t halfHV[SIZE*SIZE];\
- copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
- put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
- put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
- OPNAME ## pixels ## SIZE ## _l2(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\
-}\
-
-#define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
-//#define op_avg2(a, b) a = (((a)*w1+cm[((b) + 16)>>5]*w2 + o + 64)>>7)
-#define op_put(a, b) a = cm[((b) + 16)>>5]
-#define op2_avg(a, b) a = (((a)+cm[((b) + 512)>>10]+1)>>1)
-#define op2_put(a, b) a = cm[((b) + 512)>>10]
-
-H264_LOWPASS(put_ , op_put, op2_put)
-H264_LOWPASS(avg_ , op_avg, op2_avg)
-H264_MC(put_, 2)
-H264_MC(put_, 4)
-H264_MC(put_, 8)
-H264_MC(put_, 16)
-H264_MC(avg_, 4)
-H264_MC(avg_, 8)
-H264_MC(avg_, 16)
-
-#undef op_avg
-#undef op_put
-#undef op2_avg
-#undef op2_put
-#endif
-
-#define op_scale1(x) block[x] = clip_uint8( (block[x]*weight + offset) >> log2_denom )
-#define op_scale2(x) dst[x] = 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<H; y++, block += stride){ \
- op_scale1(0); \
- op_scale1(1); \
- if(W==2) continue; \
- op_scale1(2); \
- op_scale1(3); \
- if(W==4) continue; \
- op_scale1(4); \
- op_scale1(5); \
- op_scale1(6); \
- op_scale1(7); \
- if(W==8) continue; \
- op_scale1(8); \
- op_scale1(9); \
- op_scale1(10); \
- op_scale1(11); \
- op_scale1(12); \
- op_scale1(13); \
- op_scale1(14); \
- op_scale1(15); \
- } \
-} \
-static void biweight_h264_pixels ## W ## x ## H ## _c(uint8_t *dst, uint8_t *src, int stride, int log2_denom, int weightd, int weights, int offset){ \
- int y; \
- offset = ((offset + 1) | 1) << log2_denom; \
- for(y=0; y<H; y++, dst += stride, src += stride){ \
- op_scale2(0); \
- op_scale2(1); \
- if(W==2) continue; \
- op_scale2(2); \
- op_scale2(3); \
- if(W==4) continue; \
- op_scale2(4); \
- op_scale2(5); \
- op_scale2(6); \
- op_scale2(7); \
- if(W==8) continue; \
- op_scale2(8); \
- op_scale2(9); \
- op_scale2(10); \
- op_scale2(11); \
- op_scale2(12); \
- op_scale2(13); \
- op_scale2(14); \
- op_scale2(15); \
- } \
-}
-
-H264_WEIGHT(16,16)
-H264_WEIGHT(16,8)
-H264_WEIGHT(8,16)
-H264_WEIGHT(8,8)
-H264_WEIGHT(8,4)
-H264_WEIGHT(4,8)
-H264_WEIGHT(4,4)
-H264_WEIGHT(4,2)
-H264_WEIGHT(2,4)
-H264_WEIGHT(2,2)
-
-#undef op_scale1
-#undef op_scale2
-#undef H264_WEIGHT
-
-static void wmv2_mspel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
- int i;
-
- for(i=0; i<h; i++){
- dst[0]= cm[(9*(src[0] + src[1]) - (src[-1] + src[2]) + 8)>>4];
- dst[1]= cm[(9*(src[1] + src[2]) - (src[ 0] + src[3]) + 8)>>4];
- dst[2]= cm[(9*(src[2] + src[3]) - (src[ 1] + src[4]) + 8)>>4];
- dst[3]= cm[(9*(src[3] + src[4]) - (src[ 2] + src[5]) + 8)>>4];
- dst[4]= cm[(9*(src[4] + src[5]) - (src[ 3] + src[6]) + 8)>>4];
- dst[5]= cm[(9*(src[5] + src[6]) - (src[ 4] + src[7]) + 8)>>4];
- dst[6]= cm[(9*(src[6] + src[7]) - (src[ 5] + src[8]) + 8)>>4];
- dst[7]= cm[(9*(src[7] + src[8]) - (src[ 6] + src[9]) + 8)>>4];
- dst+=dstStride;
- src+=srcStride;
- }
-}
-
-#ifdef CONFIG_CAVS_DECODER
-/* AVS specific */
-void ff_cavsdsp_init(DSPContext* c, AVCodecContext *avctx);
-
-void ff_put_cavs_qpel8_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
- put_pixels8_c(dst, src, stride, 8);
-}
-void ff_avg_cavs_qpel8_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
- avg_pixels8_c(dst, src, stride, 8);
-}
-void ff_put_cavs_qpel16_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
- put_pixels16_c(dst, src, stride, 16);
-}
-void ff_avg_cavs_qpel16_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
- avg_pixels16_c(dst, src, stride, 16);
-}
-#endif /* CONFIG_CAVS_DECODER */
-
-#if defined(CONFIG_VC1_DECODER) || defined(CONFIG_WMV3_DECODER)
-/* VC-1 specific */
-void ff_vc1dsp_init(DSPContext* c, AVCodecContext *avctx);
-
-void ff_put_vc1_mspel_mc00_c(uint8_t *dst, uint8_t *src, int stride, int rnd) {
- put_pixels8_c(dst, src, stride, 8);
-}
-#endif /* CONFIG_VC1_DECODER||CONFIG_WMV3_DECODER */
-
-#if defined(CONFIG_H264_ENCODER)
-/* H264 specific */
-void ff_h264dsp_init(DSPContext* c, AVCodecContext *avctx);
-#endif /* CONFIG_H264_ENCODER */
-
-static void wmv2_mspel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int w){
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
- int i;
-
- for(i=0; i<w; i++){
- const int src_1= src[ -srcStride];
- const int src0 = src[0 ];
- const int src1 = src[ srcStride];
- const int src2 = src[2*srcStride];
- const int src3 = src[3*srcStride];
- const int src4 = src[4*srcStride];
- const int src5 = src[5*srcStride];
- const int src6 = src[6*srcStride];
- const int src7 = src[7*srcStride];
- const int src8 = src[8*srcStride];
- const int src9 = src[9*srcStride];
- dst[0*dstStride]= cm[(9*(src0 + src1) - (src_1 + src2) + 8)>>4];
- dst[1*dstStride]= cm[(9*(src1 + src2) - (src0 + src3) + 8)>>4];
- dst[2*dstStride]= cm[(9*(src2 + src3) - (src1 + src4) + 8)>>4];
- dst[3*dstStride]= cm[(9*(src3 + src4) - (src2 + src5) + 8)>>4];
- dst[4*dstStride]= cm[(9*(src4 + src5) - (src3 + src6) + 8)>>4];
- dst[5*dstStride]= cm[(9*(src5 + src6) - (src4 + src7) + 8)>>4];
- dst[6*dstStride]= cm[(9*(src6 + src7) - (src5 + src8) + 8)>>4];
- dst[7*dstStride]= cm[(9*(src7 + src8) - (src6 + src9) + 8)>>4];
- src++;
- dst++;
- }
-}
-
-static void put_mspel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){
- put_pixels8_c(dst, src, stride, 8);
-}
-
-static void put_mspel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){
- uint8_t half[64];
- wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
- put_pixels8_l2(dst, src, half, stride, stride, 8, 8);
-}
-
-static void put_mspel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){
- wmv2_mspel8_h_lowpass(dst, src, stride, stride, 8);
-}
-
-static void put_mspel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){
- uint8_t half[64];
- wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
- put_pixels8_l2(dst, src+1, half, stride, stride, 8, 8);
-}
-
-static void put_mspel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){
- wmv2_mspel8_v_lowpass(dst, src, stride, stride, 8);
-}
-
-static void put_mspel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){
- uint8_t halfH[88];
- uint8_t halfV[64];
- uint8_t halfHV[64];
- wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
- wmv2_mspel8_v_lowpass(halfV, src, 8, stride, 8);
- wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
- put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);
-}
-static void put_mspel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){
- uint8_t halfH[88];
- uint8_t halfV[64];
- uint8_t halfHV[64];
- wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
- wmv2_mspel8_v_lowpass(halfV, src+1, 8, stride, 8);
- wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
- put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);
-}
-static void put_mspel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){
- uint8_t halfH[88];
- wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
- wmv2_mspel8_v_lowpass(dst, halfH+8, stride, 8, 8);
-}
-
-static void h263_v_loop_filter_c(uint8_t *src, int stride, int qscale){
- int x;
- const int strength= ff_h263_loop_filter_strength[qscale];
-
- for(x=0; x<8; x++){
- int d1, d2, ad1;
- int p0= src[x-2*stride];
- int p1= src[x-1*stride];
- int p2= src[x+0*stride];
- int p3= src[x+1*stride];
- int d = (p0 - p3 + 4*(p2 - p1)) / 8;
-
- if (d<-2*strength) d1= 0;
- else if(d<- strength) d1=-2*strength - d;
- else if(d< strength) d1= d;
- else if(d< 2*strength) d1= 2*strength - d;
- else d1= 0;
-
- p1 += d1;
- p2 -= d1;
- if(p1&256) p1= ~(p1>>31);
- if(p2&256) p2= ~(p2>>31);
-
- src[x-1*stride] = p1;
- src[x+0*stride] = p2;
-
- ad1= FFABS(d1)>>1;
-
- d2= clip((p0-p3)/4, -ad1, ad1);
-
- src[x-2*stride] = p0 - d2;
- src[x+ stride] = p3 + d2;
- }
-}
-
-static void h263_h_loop_filter_c(uint8_t *src, int stride, int qscale){
- int y;
- const int strength= ff_h263_loop_filter_strength[qscale];
-
- for(y=0; y<8; y++){
- int d1, d2, ad1;
- int p0= src[y*stride-2];
- int p1= src[y*stride-1];
- int p2= src[y*stride+0];
- int p3= src[y*stride+1];
- int d = (p0 - p3 + 4*(p2 - p1)) / 8;
-
- if (d<-2*strength) d1= 0;
- else if(d<- strength) d1=-2*strength - d;
- else if(d< strength) d1= d;
- else if(d< 2*strength) d1= 2*strength - d;
- else d1= 0;
-
- p1 += d1;
- p2 -= d1;
- if(p1&256) p1= ~(p1>>31);
- if(p2&256) p2= ~(p2>>31);
-
- src[y*stride-1] = p1;
- src[y*stride+0] = p2;
-
- ad1= FFABS(d1)>>1;
-
- d2= clip((p0-p3)/4, -ad1, ad1);
-
- src[y*stride-2] = p0 - d2;
- src[y*stride+1] = p3 + d2;
- }
-}
-
-static void h261_loop_filter_c(uint8_t *src, int stride){
- int x,y,xy,yz;
- int temp[64];
-
- for(x=0; x<8; x++){
- temp[x ] = 4*src[x ];
- temp[x + 7*8] = 4*src[x + 7*stride];
- }
- for(y=1; y<7; y++){
- for(x=0; x<8; x++){
- xy = y * stride + x;
- yz = y * 8 + x;
- temp[yz] = src[xy - stride] + 2*src[xy] + src[xy + stride];
- }
- }
-
- for(y=0; y<8; y++){
- src[ y*stride] = (temp[ y*8] + 2)>>2;
- src[7+y*stride] = (temp[7+y*8] + 2)>>2;
- for(x=1; x<7; x++){
- xy = y * stride + x;
- yz = y * 8 + x;
- src[xy] = (temp[yz-1] + 2*temp[yz] + temp[yz+1] + 8)>>4;
- }
- }
-}
-
-static inline void h264_loop_filter_luma_c(uint8_t *pix, int xstride, int ystride, int alpha, int beta, int8_t *tc0)
-{
- int i, d;
- for( i = 0; i < 4; i++ ) {
- if( tc0[i] < 0 ) {
- pix += 4*ystride;
- continue;
- }
- for( d = 0; d < 4; d++ ) {
- const int p0 = pix[-1*xstride];
- const int p1 = pix[-2*xstride];
- const int p2 = pix[-3*xstride];
- const int q0 = pix[0];
- 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 ) {
-
- int tc = tc0[i];
- int i_delta;
-
- if( FFABS( p2 - p0 ) < beta ) {
- pix[-2*xstride] = p1 + clip( (( p2 + ( ( p0 + q0 + 1 ) >> 1 ) ) >> 1) - p1, -tc0[i], tc0[i] );
- tc++;
- }
- if( FFABS( q2 - q0 ) < beta ) {
- pix[ xstride] = q1 + clip( (( q2 + ( ( p0 + q0 + 1 ) >> 1 ) ) >> 1) - q1, -tc0[i], tc0[i] );
- tc++;
- }
-
- i_delta = clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
- pix[-xstride] = clip_uint8( p0 + i_delta ); /* p0' */
- pix[0] = 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_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 = clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
-
- pix[-xstride] = clip_uint8( p0 + delta ); /* p0' */
- pix[0] = 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;
-
- s = 0;
- for(i=0;i<h;i++) {
- s += abs(pix1[0] - pix2[0]);
- s += abs(pix1[1] - pix2[1]);
- s += abs(pix1[2] - pix2[2]);
- s += abs(pix1[3] - pix2[3]);
- s += abs(pix1[4] - pix2[4]);
- s += abs(pix1[5] - pix2[5]);
- s += abs(pix1[6] - pix2[6]);
- s += abs(pix1[7] - pix2[7]);
- s += abs(pix1[8] - pix2[8]);
- s += abs(pix1[9] - pix2[9]);
- s += abs(pix1[10] - pix2[10]);
- s += abs(pix1[11] - pix2[11]);
- s += abs(pix1[12] - pix2[12]);
- s += abs(pix1[13] - pix2[13]);
- s += abs(pix1[14] - pix2[14]);
- s += abs(pix1[15] - pix2[15]);
- pix1 += line_size;
- pix2 += line_size;
- }
- return s;
-}
-
-static int pix_abs16_x2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
-{
- int s, i;
-
- s = 0;
- for(i=0;i<h;i++) {
- s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
- s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
- s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
- s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
- s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
- s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
- s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
- s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
- s += abs(pix1[8] - avg2(pix2[8], pix2[9]));
- s += abs(pix1[9] - avg2(pix2[9], pix2[10]));
- s += abs(pix1[10] - avg2(pix2[10], pix2[11]));
- s += abs(pix1[11] - avg2(pix2[11], pix2[12]));
- s += abs(pix1[12] - avg2(pix2[12], pix2[13]));
- s += abs(pix1[13] - avg2(pix2[13], pix2[14]));
- s += abs(pix1[14] - avg2(pix2[14], pix2[15]));
- s += abs(pix1[15] - avg2(pix2[15], pix2[16]));
- pix1 += line_size;
- pix2 += line_size;
- }
- return s;
-}
-
-static int pix_abs16_y2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
-{
- int s, i;
- uint8_t *pix3 = pix2 + line_size;
-
- s = 0;
- for(i=0;i<h;i++) {
- s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
- s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
- s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
- s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
- s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
- s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
- s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
- s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
- s += abs(pix1[8] - avg2(pix2[8], pix3[8]));
- s += abs(pix1[9] - avg2(pix2[9], pix3[9]));
- s += abs(pix1[10] - avg2(pix2[10], pix3[10]));
- s += abs(pix1[11] - avg2(pix2[11], pix3[11]));
- s += abs(pix1[12] - avg2(pix2[12], pix3[12]));
- s += abs(pix1[13] - avg2(pix2[13], pix3[13]));
- s += abs(pix1[14] - avg2(pix2[14], pix3[14]));
- s += abs(pix1[15] - avg2(pix2[15], pix3[15]));
- pix1 += line_size;
- pix2 += line_size;
- pix3 += line_size;
- }
- return s;
-}
-
-static int pix_abs16_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
-{
- int s, i;
- uint8_t *pix3 = pix2 + line_size;
-
- s = 0;
- for(i=0;i<h;i++) {
- s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
- s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
- s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
- s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
- s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
- s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
- s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
- s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
- s += abs(pix1[8] - avg4(pix2[8], pix2[9], pix3[8], pix3[9]));
- s += abs(pix1[9] - avg4(pix2[9], pix2[10], pix3[9], pix3[10]));
- s += abs(pix1[10] - avg4(pix2[10], pix2[11], pix3[10], pix3[11]));
- s += abs(pix1[11] - avg4(pix2[11], pix2[12], pix3[11], pix3[12]));
- s += abs(pix1[12] - avg4(pix2[12], pix2[13], pix3[12], pix3[13]));
- s += abs(pix1[13] - avg4(pix2[13], pix2[14], pix3[13], pix3[14]));
- s += abs(pix1[14] - avg4(pix2[14], pix2[15], pix3[14], pix3[15]));
- s += abs(pix1[15] - avg4(pix2[15], pix2[16], pix3[15], pix3[16]));
- pix1 += line_size;
- pix2 += line_size;
- pix3 += line_size;
- }
- return s;
-}
-
-static inline int pix_abs8_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
-{
- int s, i;
-
- s = 0;
- for(i=0;i<h;i++) {
- s += abs(pix1[0] - pix2[0]);
- s += abs(pix1[1] - pix2[1]);
- s += abs(pix1[2] - pix2[2]);
- s += abs(pix1[3] - pix2[3]);
- s += abs(pix1[4] - pix2[4]);
- s += abs(pix1[5] - pix2[5]);
- s += abs(pix1[6] - pix2[6]);
- s += abs(pix1[7] - pix2[7]);
- pix1 += line_size;
- pix2 += line_size;
- }
- return s;
-}
-
-static int pix_abs8_x2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
-{
- int s, i;
-
- s = 0;
- for(i=0;i<h;i++) {
- s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
- s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
- s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
- s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
- s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
- s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
- s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
- s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
- pix1 += line_size;
- pix2 += line_size;
- }
- return s;
-}
-
-static int pix_abs8_y2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
-{
- int s, i;
- uint8_t *pix3 = pix2 + line_size;
-
- s = 0;
- for(i=0;i<h;i++) {
- s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
- s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
- s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
- s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
- s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
- s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
- s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
- s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
- pix1 += line_size;
- pix2 += line_size;
- pix3 += line_size;
- }
- return s;
-}
-
-static int pix_abs8_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
-{
- int s, i;
- uint8_t *pix3 = pix2 + line_size;
-
- s = 0;
- for(i=0;i<h;i++) {
- s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
- s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
- s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
- s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
- s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
- s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
- s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
- s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
- pix1 += line_size;
- pix2 += line_size;
- pix3 += line_size;
- }
- return s;
-}
-
-static int nsse16_c(void *v, uint8_t *s1, uint8_t *s2, int stride, int h){
- MpegEncContext *c = v;
- int score1=0;
- int score2=0;
- int x,y;
-
- for(y=0; y<h; y++){
- for(x=0; x<16; x++){
- score1+= (s1[x ] - s2[x ])*(s1[x ] - s2[x ]);
- }
- if(y+1<h){
- for(x=0; x<15; x++){
- score2+= FFABS( s1[x ] - s1[x +stride]
- - s1[x+1] + s1[x+1+stride])
- -FFABS( s2[x ] - s2[x +stride]
- - s2[x+1] + s2[x+1+stride]);
- }
- }
- s1+= stride;
- s2+= stride;
- }
-
- if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight;
- else return score1 + FFABS(score2)*8;
-}
-
-static int nsse8_c(void *v, uint8_t *s1, uint8_t *s2, int stride, int h){
- MpegEncContext *c = v;
- int score1=0;
- int score2=0;
- int x,y;
-
- for(y=0; y<h; y++){
- for(x=0; x<8; x++){
- score1+= (s1[x ] - s2[x ])*(s1[x ] - s2[x ]);
- }
- if(y+1<h){
- for(x=0; x<7; x++){
- score2+= FFABS( s1[x ] - s1[x +stride]
- - s1[x+1] + s1[x+1+stride])
- -FFABS( s2[x ] - s2[x +stride]
- - s2[x+1] + s2[x+1+stride]);
- }
- }
- s1+= stride;
- s2+= stride;
- }
-
- if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight;
- else return score1 + FFABS(score2)*8;
-}
-
-static int try_8x8basis_c(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale){
- int i;
- unsigned int sum=0;
-
- for(i=0; i<8*8; i++){
- int b= rem[i] + ((basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT));
- int w= weight[i];
- b>>= RECON_SHIFT;
- assert(-512<b && b<512);
-
- sum += (w*b)*(w*b)>>4;
- }
- return sum>>2;
-}
-
-static void add_8x8basis_c(int16_t rem[64], int16_t basis[64], int scale){
- int i;
-
- for(i=0; i<8*8; i++){
- rem[i] += (basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT);
- }
-}
-
-/**
- * permutes an 8x8 block.
- * @param block the block which will be permuted according to the given permutation vector
- * @param permutation the permutation vector
- * @param last the last non zero coefficient in scantable order, used to speed the permutation up
- * @param scantable the used scantable, this is only used to speed the permutation up, the block is not
- * (inverse) permutated to scantable order!
- */
-void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last)
-{
- int i;
- DCTELEM temp[64];
-
- if(last<=0) return;
- //if(permutation[1]==1) return; //FIXME its ok but not clean and might fail for some perms
-
- for(i=0; i<=last; i++){
- const int j= scantable[i];
- temp[j]= block[j];
- block[j]=0;
- }
-
- for(i=0; i<=last; i++){
- const int j= scantable[i];
- const int perm_j= permutation[j];
- block[perm_j]= temp[j];
- }
-}
-
-static int zero_cmp(void *s, uint8_t *a, uint8_t *b, int stride, int h){
- return 0;
-}
-
-void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type){
- int i;
-
- memset(cmp, 0, sizeof(void*)*5);
-
- for(i=0; i<5; i++){
- switch(type&0xFF){
- case FF_CMP_SAD:
- cmp[i]= c->sad[i];
- break;
- case FF_CMP_SATD:
- cmp[i]= c->hadamard8_diff[i];
- break;
- case FF_CMP_SSE:
- cmp[i]= c->sse[i];
- break;
- case FF_CMP_DCT:
- cmp[i]= c->dct_sad[i];
- break;
- case FF_CMP_DCT264:
- cmp[i]= c->dct264_sad[i];
- break;
- case FF_CMP_DCTMAX:
- cmp[i]= c->dct_max[i];
- break;
- case FF_CMP_PSNR:
- cmp[i]= c->quant_psnr[i];
- break;
- case FF_CMP_BIT:
- cmp[i]= c->bit[i];
- break;
- case FF_CMP_RD:
- cmp[i]= c->rd[i];
- break;
- case FF_CMP_VSAD:
- cmp[i]= c->vsad[i];
- break;
- case FF_CMP_VSSE:
- cmp[i]= c->vsse[i];
- break;
- case FF_CMP_ZERO:
- cmp[i]= zero_cmp;
- break;
- case FF_CMP_NSSE:
- cmp[i]= c->nsse[i];
- break;
-#ifdef CONFIG_SNOW_ENCODER
- case FF_CMP_W53:
- cmp[i]= c->w53[i];
- break;
- case FF_CMP_W97:
- cmp[i]= c->w97[i];
- break;
-#endif
- default:
- av_log(NULL, AV_LOG_ERROR,"internal error in cmp function selection\n");
- }
- }
-}
-
-/**
- * memset(blocks, 0, sizeof(DCTELEM)*6*64)
- */
-static void clear_blocks_c(DCTELEM *blocks)
-{
- memset(blocks, 0, sizeof(DCTELEM)*6*64);
-}
-
-static void add_bytes_c(uint8_t *dst, uint8_t *src, int w){
- int i;
- for(i=0; i+7<w; i+=8){
- dst[i+0] += src[i+0];
- dst[i+1] += src[i+1];
- dst[i+2] += src[i+2];
- dst[i+3] += src[i+3];
- dst[i+4] += src[i+4];
- dst[i+5] += src[i+5];
- dst[i+6] += src[i+6];
- dst[i+7] += src[i+7];
- }
- for(; i<w; i++)
- dst[i+0] += src[i+0];
-}
-
-static void diff_bytes_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
- int i;
- for(i=0; i+7<w; i+=8){
- dst[i+0] = src1[i+0]-src2[i+0];
- dst[i+1] = src1[i+1]-src2[i+1];
- dst[i+2] = src1[i+2]-src2[i+2];
- dst[i+3] = src1[i+3]-src2[i+3];
- dst[i+4] = src1[i+4]-src2[i+4];
- dst[i+5] = src1[i+5]-src2[i+5];
- dst[i+6] = src1[i+6]-src2[i+6];
- dst[i+7] = src1[i+7]-src2[i+7];
- }
- for(; i<w; i++)
- dst[i+0] = src1[i+0]-src2[i+0];
-}
-
-static void sub_hfyu_median_prediction_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w, int *left, int *left_top){
- int i;
- uint8_t l, lt;
-
- l= *left;
- lt= *left_top;
-
- for(i=0; i<w; i++){
- const int pred= mid_pred(l, src1[i], (l + src1[i] - lt)&0xFF);
- lt= src1[i];
- l= src2[i];
- dst[i]= l - pred;
- }
-
- *left= l;
- *left_top= lt;
-}
-
-#define BUTTERFLY2(o1,o2,i1,i2) \
-o1= (i1)+(i2);\
-o2= (i1)-(i2);
-
-#define BUTTERFLY1(x,y) \
-{\
- int a,b;\
- a= x;\
- b= y;\
- x= a+b;\
- y= a-b;\
-}
-
-#define BUTTERFLYA(x,y) (FFABS((x)+(y)) + FFABS((x)-(y)))
-
-static int hadamard8_diff8x8_c(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h){
- int i;
- int temp[64];
- int sum=0;
-
- assert(h==8);
-
- for(i=0; i<8; i++){
- //FIXME try pointer walks
- BUTTERFLY2(temp[8*i+0], temp[8*i+1], src[stride*i+0]-dst[stride*i+0],src[stride*i+1]-dst[stride*i+1]);
- BUTTERFLY2(temp[8*i+2], temp[8*i+3], src[stride*i+2]-dst[stride*i+2],src[stride*i+3]-dst[stride*i+3]);
- BUTTERFLY2(temp[8*i+4], temp[8*i+5], src[stride*i+4]-dst[stride*i+4],src[stride*i+5]-dst[stride*i+5]);
- BUTTERFLY2(temp[8*i+6], temp[8*i+7], src[stride*i+6]-dst[stride*i+6],src[stride*i+7]-dst[stride*i+7]);
-
- BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
- BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
- BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
- BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
-
- BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
- BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
- BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
- BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
- }
-
- for(i=0; i<8; i++){
- BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
- BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
- BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
- BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
-
- BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
- BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
- BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
- BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
-
- sum +=
- BUTTERFLYA(temp[8*0+i], temp[8*4+i])
- +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
- +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
- +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
- }
-#if 0
-static int maxi=0;
-if(sum>maxi){
- maxi=sum;
- printf("MAX:%d\n", maxi);
-}
-#endif
- return sum;
-}
-
-static int hadamard8_intra8x8_c(/*MpegEncContext*/ void *s, uint8_t *src, uint8_t *dummy, int stride, int h){
- int i;
- int temp[64];
- int sum=0;
-
- assert(h==8);
-
- for(i=0; i<8; i++){
- //FIXME try pointer walks
- BUTTERFLY2(temp[8*i+0], temp[8*i+1], src[stride*i+0],src[stride*i+1]);
- BUTTERFLY2(temp[8*i+2], temp[8*i+3], src[stride*i+2],src[stride*i+3]);
- BUTTERFLY2(temp[8*i+4], temp[8*i+5], src[stride*i+4],src[stride*i+5]);
- BUTTERFLY2(temp[8*i+6], temp[8*i+7], src[stride*i+6],src[stride*i+7]);
-
- BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
- BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
- BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
- BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
-
- BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
- BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
- BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
- BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
- }
-
- for(i=0; i<8; i++){
- BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
- BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
- BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
- BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
-
- BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
- BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
- BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
- BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
-
- sum +=
- BUTTERFLYA(temp[8*0+i], temp[8*4+i])
- +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
- +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
- +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
- }
-
- sum -= FFABS(temp[8*0] + temp[8*4]); // -mean
-
- return sum;
-}
-
-static int dct_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
- MpegEncContext * const s= (MpegEncContext *)c;
- DECLARE_ALIGNED_8(uint64_t, aligned_temp[sizeof(DCTELEM)*64/8]);
- DCTELEM * const temp= (DCTELEM*)aligned_temp;
- int sum=0, i;
-
- assert(h==8);
-
- s->dsp.diff_pixels(temp, src1, src2, stride);
- s->dsp.fdct(temp);
-
- for(i=0; i<64; i++)
- sum+= FFABS(temp[i]);
-
- return sum;
-}
-
-#ifdef CONFIG_GPL
-#define DCT8_1D {\
- const int s07 = SRC(0) + SRC(7);\
- const int s16 = SRC(1) + SRC(6);\
- const int s25 = SRC(2) + SRC(5);\
- const int s34 = SRC(3) + SRC(4);\
- const int a0 = s07 + s34;\
- const int a1 = s16 + s25;\
- const int a2 = s07 - s34;\
- const int a3 = s16 - s25;\
- const int d07 = SRC(0) - SRC(7);\
- const int d16 = SRC(1) - SRC(6);\
- const int d25 = SRC(2) - SRC(5);\
- const int d34 = SRC(3) - SRC(4);\
- const int a4 = d16 + d25 + (d07 + (d07>>1));\
- const int a5 = d07 - d34 - (d25 + (d25>>1));\
- const int a6 = d07 + d34 - (d16 + (d16>>1));\
- const int a7 = d16 - d25 + (d34 + (d34>>1));\
- DST(0, a0 + a1 ) ;\
- DST(1, a4 + (a7>>2)) ;\
- DST(2, a2 + (a3>>1)) ;\
- DST(3, a5 + (a6>>2)) ;\
- DST(4, a0 - a1 ) ;\
- DST(5, a6 - (a5>>2)) ;\
- DST(6, (a2>>1) - a3 ) ;\
- DST(7, (a4>>2) - a7 ) ;\
-}
-
-static int dct264_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
- MpegEncContext * const s= (MpegEncContext *)c;
- int16_t dct[8][8];
- int i;
- int sum=0;
-
- s->dsp.diff_pixels(dct, src1, src2, stride);
-
-#define SRC(x) dct[i][x]
-#define DST(x,v) dct[i][x]= v
- for( i = 0; i < 8; i++ )
- DCT8_1D
-#undef SRC
-#undef DST
-
-#define SRC(x) dct[x][i]
-#define DST(x,v) sum += FFABS(v)
- for( i = 0; i < 8; i++ )
- DCT8_1D
-#undef SRC
-#undef DST
- return sum;
-}
-#endif
-
-static int dct_max8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
- MpegEncContext * const s= (MpegEncContext *)c;
- DECLARE_ALIGNED_8(uint64_t, aligned_temp[sizeof(DCTELEM)*64/8]);
- DCTELEM * const temp= (DCTELEM*)aligned_temp;
- int sum=0, i;
-
- assert(h==8);
-
- s->dsp.diff_pixels(temp, src1, src2, stride);
- s->dsp.fdct(temp);
-
- for(i=0; i<64; i++)
- sum= FFMAX(sum, FFABS(temp[i]));
-
- return sum;
-}
-
-static int quant_psnr8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
- MpegEncContext * const s= (MpegEncContext *)c;
- DECLARE_ALIGNED_8 (uint64_t, aligned_temp[sizeof(DCTELEM)*64*2/8]);
- DCTELEM * const temp= (DCTELEM*)aligned_temp;
- DCTELEM * const bak = ((DCTELEM*)aligned_temp)+64;
- int sum=0, i;
-
- assert(h==8);
- s->mb_intra=0;
-
- s->dsp.diff_pixels(temp, src1, src2, stride);
-
- memcpy(bak, temp, 64*sizeof(DCTELEM));
-
- s->block_last_index[0/*FIXME*/]= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
- s->dct_unquantize_inter(s, temp, 0, s->qscale);
- simple_idct(temp); //FIXME
-
- for(i=0; i<64; i++)
- sum+= (temp[i]-bak[i])*(temp[i]-bak[i]);
-
- return sum;
-}
-
-static int rd8x8_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]);
- DECLARE_ALIGNED_8 (uint64_t, aligned_bak[stride]);
- DCTELEM * const temp= (DCTELEM*)aligned_temp;
- uint8_t * const bak= (uint8_t*)aligned_bak;
- int i, last, run, bits, level, distoration, start_i;
- const int esc_length= s->ac_esc_length;
- uint8_t * length;
- uint8_t * last_length;
-
- assert(h==8);
-
- for(i=0; i<8; i++){
- ((uint32_t*)(bak + i*stride))[0]= ((uint32_t*)(src2 + i*stride))[0];
- ((uint32_t*)(bak + i*stride))[1]= ((uint32_t*)(src2 + i*stride))[1];
- }
-
- s->dsp.diff_pixels(temp, src1, src2, stride);
-
- s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
-
- bits=0;
-
- if (s->mb_intra) {
- start_i = 1;
- length = s->intra_ac_vlc_length;
- last_length= s->intra_ac_vlc_last_length;
- bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma
- } else {
- start_i = 0;
- length = s->inter_ac_vlc_length;
- last_length= s->inter_ac_vlc_last_length;
- }
-
- if(last>=start_i){
- run=0;
- for(i=start_i; i<last; i++){
- int j= scantable[i];
- level= temp[j];
-
- if(level){
- level+=64;
- if((level&(~127)) == 0){
- bits+= length[UNI_AC_ENC_INDEX(run, level)];
- }else
- bits+= esc_length;
- run=0;
- }else
- run++;
- }
- i= scantable[last];
-
- level= temp[i] + 64;
-
- assert(level - 64);
-
- if((level&(~127)) == 0){
- bits+= last_length[UNI_AC_ENC_INDEX(run, level)];
- }else
- bits+= esc_length;
-
- }
-
- if(last>=0){
- if(s->mb_intra)
- s->dct_unquantize_intra(s, temp, 0, s->qscale);
- else
- s->dct_unquantize_inter(s, temp, 0, s->qscale);
- }
-
- s->dsp.idct_add(bak, stride, temp);
-
- distoration= s->dsp.sse[1](NULL, bak, src1, stride, 8);
-
- return distoration + ((bits*s->qscale*s->qscale*109 + 64)>>7);
-}
-
-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;
- int i, last, run, bits, level, start_i;
- const int esc_length= s->ac_esc_length;
- uint8_t * length;
- uint8_t * last_length;
-
- assert(h==8);
-
- s->dsp.diff_pixels(temp, src1, src2, stride);
-
- s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
-
- bits=0;
-
- if (s->mb_intra) {
- start_i = 1;
- length = s->intra_ac_vlc_length;
- last_length= s->intra_ac_vlc_last_length;
- bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma
- } else {
- start_i = 0;
- length = s->inter_ac_vlc_length;
- last_length= s->inter_ac_vlc_last_length;
- }
-
- if(last>=start_i){
- run=0;
- for(i=start_i; i<last; i++){
- int j= scantable[i];
- level= temp[j];
-
- if(level){
- level+=64;
- if((level&(~127)) == 0){
- bits+= length[UNI_AC_ENC_INDEX(run, level)];
- }else
- bits+= esc_length;
- run=0;
- }else
- run++;
- }
- i= scantable[last];
-
- level= temp[i] + 64;
-
- assert(level - 64);
-
- if((level&(~127)) == 0){
- bits+= last_length[UNI_AC_ENC_INDEX(run, level)];
- }else
- bits+= esc_length;
- }
-
- return bits;
-}
-
-static int vsad_intra16_c(/*MpegEncContext*/ void *c, uint8_t *s, uint8_t *dummy, int stride, int h){
- int score=0;
- int x,y;
-
- for(y=1; y<h; y++){
- for(x=0; x<16; x+=4){
- score+= FFABS(s[x ] - s[x +stride]) + FFABS(s[x+1] - s[x+1+stride])
- +FFABS(s[x+2] - s[x+2+stride]) + FFABS(s[x+3] - s[x+3+stride]);
- }
- s+= stride;
- }
-
- return score;
-}
-
-static int vsad16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){
- int score=0;
- int x,y;
-
- for(y=1; y<h; y++){
- for(x=0; x<16; x++){
- score+= FFABS(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]);
- }
- s1+= stride;
- s2+= stride;
- }
-
- return score;
-}
-
-#define SQ(a) ((a)*(a))
-static int vsse_intra16_c(/*MpegEncContext*/ void *c, uint8_t *s, uint8_t *dummy, int stride, int h){
- int score=0;
- int x,y;
-
- for(y=1; y<h; y++){
- for(x=0; x<16; x+=4){
- score+= SQ(s[x ] - s[x +stride]) + SQ(s[x+1] - s[x+1+stride])
- +SQ(s[x+2] - s[x+2+stride]) + SQ(s[x+3] - s[x+3+stride]);
- }
- s+= stride;
- }
-
- return score;
-}
-
-static int vsse16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){
- int score=0;
- int x,y;
-
- for(y=1; y<h; y++){
- for(x=0; x<16; x++){
- score+= SQ(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]);
- }
- s1+= stride;
- s2+= stride;
- }
-
- return score;
-}
-
-WARPER8_16_SQ(hadamard8_diff8x8_c, hadamard8_diff16_c)
-WARPER8_16_SQ(hadamard8_intra8x8_c, hadamard8_intra16_c)
-WARPER8_16_SQ(dct_sad8x8_c, dct_sad16_c)
-#ifdef CONFIG_GPL
-WARPER8_16_SQ(dct264_sad8x8_c, dct264_sad16_c)
-#endif
-WARPER8_16_SQ(dct_max8x8_c, dct_max16_c)
-WARPER8_16_SQ(quant_psnr8x8_c, quant_psnr16_c)
-WARPER8_16_SQ(rd8x8_c, rd16_c)
-WARPER8_16_SQ(bit8x8_c, bit16_c)
-
-static void vector_fmul_c(float *dst, const float *src, int len){
- int i;
- for(i=0; i<len; i++)
- dst[i] *= src[i];
-}
-
-static void vector_fmul_reverse_c(float *dst, const float *src0, const float *src1, int len){
- int i;
- src1 += len-1;
- for(i=0; i<len; i++)
- 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){
- int i;
- for(i=0; i<len; i++)
- dst[i*step] = src0[i] * src1[i] + src2[i] + src3;
-}
-
-void ff_float_to_int16_c(int16_t *dst, const float *src, int len){
- int i;
- for(i=0; i<len; i++) {
- int_fast32_t tmp = ((int32_t*)src)[i];
- if(tmp & 0xf0000){
- tmp = (0x43c0ffff - tmp)>>31;
- // is this faster on some gcc/cpu combinations?
-// if(tmp > 0x43c0ffff) tmp = 0xFFFF;
-// else tmp = 0;
- }
- dst[i] = tmp - 0x8000;
- }
-}
-
-/* XXX: those functions should be suppressed ASAP when all IDCTs are
- converted */
-static void ff_jref_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
-{
- j_rev_dct (block);
- put_pixels_clamped_c(block, dest, line_size);
-}
-static void ff_jref_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
-{
- j_rev_dct (block);
- add_pixels_clamped_c(block, dest, line_size);
-}
-
-static void ff_jref_idct4_put(uint8_t *dest, int line_size, DCTELEM *block)
-{
- j_rev_dct4 (block);
- put_pixels_clamped4_c(block, dest, line_size);
-}
-static void ff_jref_idct4_add(uint8_t *dest, int line_size, DCTELEM *block)
-{
- j_rev_dct4 (block);
- add_pixels_clamped4_c(block, dest, line_size);
-}
-
-static void ff_jref_idct2_put(uint8_t *dest, int line_size, DCTELEM *block)
-{
- j_rev_dct2 (block);
- put_pixels_clamped2_c(block, dest, line_size);
-}
-static void ff_jref_idct2_add(uint8_t *dest, int line_size, DCTELEM *block)
-{
- j_rev_dct2 (block);
- add_pixels_clamped2_c(block, dest, line_size);
-}
-
-static void ff_jref_idct1_put(uint8_t *dest, int line_size, DCTELEM *block)
-{
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
-
- dest[0] = cm[(block[0] + 4)>>3];
-}
-static void ff_jref_idct1_add(uint8_t *dest, int line_size, DCTELEM *block)
-{
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
-
- dest[0] = cm[dest[0] + ((block[0] + 4)>>3)];
-}
-
-static void just_return() { return; }
-
-/* init static data */
-void dsputil_static_init(void)
-{
- int i;
-
- for(i=0;i<256;i++) ff_cropTbl[i + MAX_NEG_CROP] = i;
- for(i=0;i<MAX_NEG_CROP;i++) {
- ff_cropTbl[i] = 0;
- ff_cropTbl[i + MAX_NEG_CROP + 256] = 255;
- }
-
- for(i=0;i<512;i++) {
- ff_squareTbl[i] = (i - 256) * (i - 256);
- }
-
- for(i=0; i<64; i++) inv_zigzag_direct16[ff_zigzag_direct[i]]= i+1;
-}
-
-int ff_check_alignment(void){
- static int did_fail=0;
- DECLARE_ALIGNED_16(int, aligned);
-
- if((int)&aligned & 15){
- if(!did_fail){
-#if defined(HAVE_MMX) || defined(HAVE_ALTIVEC)
- av_log(NULL, AV_LOG_ERROR,
- "Compiler did not align stack variables. Libavcodec has been miscompiled\n"
- "and may be very slow or crash. This is not a bug in libavcodec,\n"
- "but in the compiler. Do not report crashes to FFmpeg developers.\n");
-#endif
- did_fail=1;
- }
- return -1;
- }
- return 0;
-}
-
-void dsputil_init(DSPContext* c, AVCodecContext *avctx)
-{
- int i;
-
- ff_check_alignment();
-
-#ifdef CONFIG_ENCODERS
- if(avctx->dct_algo==FF_DCT_FASTINT) {
- c->fdct = fdct_ifast;
- c->fdct248 = fdct_ifast248;
- }
- else if(avctx->dct_algo==FF_DCT_FAAN) {
- c->fdct = ff_faandct;
- c->fdct248 = ff_faandct248;
- }
- else {
- c->fdct = ff_jpeg_fdct_islow; //slow/accurate/default
- c->fdct248 = ff_fdct248_islow;
- }
-#endif //CONFIG_ENCODERS
-
- if(avctx->lowres==1){
- if(avctx->idct_algo==FF_IDCT_INT || avctx->idct_algo==FF_IDCT_AUTO){
- c->idct_put= ff_jref_idct4_put;
- c->idct_add= ff_jref_idct4_add;
- }else{
- c->idct_put= ff_h264_lowres_idct_put_c;
- c->idct_add= ff_h264_lowres_idct_add_c;
- }
- c->idct = j_rev_dct4;
- c->idct_permutation_type= FF_NO_IDCT_PERM;
- }else if(avctx->lowres==2){
- c->idct_put= ff_jref_idct2_put;
- c->idct_add= ff_jref_idct2_add;
- c->idct = j_rev_dct2;
- c->idct_permutation_type= FF_NO_IDCT_PERM;
- }else if(avctx->lowres==3){
- c->idct_put= ff_jref_idct1_put;
- c->idct_add= ff_jref_idct1_add;
- c->idct = j_rev_dct1;
- c->idct_permutation_type= FF_NO_IDCT_PERM;
- }else{
- if(avctx->idct_algo==FF_IDCT_INT){
- c->idct_put= ff_jref_idct_put;
- c->idct_add= ff_jref_idct_add;
- c->idct = j_rev_dct;
- c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
- }else if(avctx->idct_algo==FF_IDCT_VP3){
- c->idct_put= ff_vp3_idct_put_c;
- c->idct_add= ff_vp3_idct_add_c;
- c->idct = ff_vp3_idct_c;
- c->idct_permutation_type= FF_NO_IDCT_PERM;
- }else{ //accurate/default
- c->idct_put= simple_idct_put;
- c->idct_add= simple_idct_add;
- c->idct = simple_idct;
- c->idct_permutation_type= FF_NO_IDCT_PERM;
- }
- }
-
- 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->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->add_pixels_clamped = add_pixels_clamped_c;
- c->add_pixels8 = add_pixels8_c;
- c->add_pixels4 = add_pixels4_c;
- c->gmc1 = gmc1_c;
- c->gmc = ff_gmc_c;
- c->clear_blocks = clear_blocks_c;
- c->pix_sum = pix_sum_c;
- c->pix_norm1 = pix_norm1_c;
-
- /* TODO [0] 16 [1] 8 */
- c->pix_abs[0][0] = pix_abs16_c;
- c->pix_abs[0][1] = pix_abs16_x2_c;
- c->pix_abs[0][2] = pix_abs16_y2_c;
- c->pix_abs[0][3] = pix_abs16_xy2_c;
- c->pix_abs[1][0] = pix_abs8_c;
- c->pix_abs[1][1] = pix_abs8_x2_c;
- c->pix_abs[1][2] = pix_abs8_y2_c;
- c->pix_abs[1][3] = pix_abs8_xy2_c;
-
-#define dspfunc(PFX, IDX, NUM) \
- c->PFX ## _pixels_tab[IDX][0] = PFX ## _pixels ## NUM ## _c; \
- c->PFX ## _pixels_tab[IDX][1] = PFX ## _pixels ## NUM ## _x2_c; \
- c->PFX ## _pixels_tab[IDX][2] = PFX ## _pixels ## NUM ## _y2_c; \
- c->PFX ## _pixels_tab[IDX][3] = PFX ## _pixels ## NUM ## _xy2_c
-
- dspfunc(put, 0, 16);
- dspfunc(put_no_rnd, 0, 16);
- dspfunc(put, 1, 8);
- dspfunc(put_no_rnd, 1, 8);
- dspfunc(put, 2, 4);
- dspfunc(put, 3, 2);
-
- dspfunc(avg, 0, 16);
- dspfunc(avg_no_rnd, 0, 16);
- dspfunc(avg, 1, 8);
- dspfunc(avg_no_rnd, 1, 8);
- dspfunc(avg, 2, 4);
- dspfunc(avg, 3, 2);
-#undef dspfunc
-
- c->put_no_rnd_pixels_l2[0]= put_no_rnd_pixels16_l2_c;
- c->put_no_rnd_pixels_l2[1]= put_no_rnd_pixels8_l2_c;
-
- c->put_tpel_pixels_tab[ 0] = put_tpel_pixels_mc00_c;
- c->put_tpel_pixels_tab[ 1] = put_tpel_pixels_mc10_c;
- c->put_tpel_pixels_tab[ 2] = put_tpel_pixels_mc20_c;
- c->put_tpel_pixels_tab[ 4] = put_tpel_pixels_mc01_c;
- c->put_tpel_pixels_tab[ 5] = put_tpel_pixels_mc11_c;
- c->put_tpel_pixels_tab[ 6] = put_tpel_pixels_mc21_c;
- c->put_tpel_pixels_tab[ 8] = put_tpel_pixels_mc02_c;
- c->put_tpel_pixels_tab[ 9] = put_tpel_pixels_mc12_c;
- c->put_tpel_pixels_tab[10] = put_tpel_pixels_mc22_c;
-
- c->avg_tpel_pixels_tab[ 0] = avg_tpel_pixels_mc00_c;
- c->avg_tpel_pixels_tab[ 1] = avg_tpel_pixels_mc10_c;
- c->avg_tpel_pixels_tab[ 2] = avg_tpel_pixels_mc20_c;
- c->avg_tpel_pixels_tab[ 4] = avg_tpel_pixels_mc01_c;
- c->avg_tpel_pixels_tab[ 5] = avg_tpel_pixels_mc11_c;
- c->avg_tpel_pixels_tab[ 6] = avg_tpel_pixels_mc21_c;
- c->avg_tpel_pixels_tab[ 8] = avg_tpel_pixels_mc02_c;
- c->avg_tpel_pixels_tab[ 9] = avg_tpel_pixels_mc12_c;
- c->avg_tpel_pixels_tab[10] = avg_tpel_pixels_mc22_c;
-
-#define dspfunc(PFX, IDX, NUM) \
- c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_c; \
- c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_c; \
- c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_c; \
- c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_c; \
- c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_c; \
- c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_c; \
- c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_c; \
- c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_c; \
- c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_c; \
- c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_c; \
- c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_c; \
- c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_c; \
- c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_c; \
- c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_c; \
- c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_c; \
- c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_c
-
- dspfunc(put_qpel, 0, 16);
- dspfunc(put_no_rnd_qpel, 0, 16);
-
- dspfunc(avg_qpel, 0, 16);
- /* dspfunc(avg_no_rnd_qpel, 0, 16); */
-
- dspfunc(put_qpel, 1, 8);
- dspfunc(put_no_rnd_qpel, 1, 8);
-
- dspfunc(avg_qpel, 1, 8);
- /* dspfunc(avg_no_rnd_qpel, 1, 8); */
-
- dspfunc(put_h264_qpel, 0, 16);
- dspfunc(put_h264_qpel, 1, 8);
- dspfunc(put_h264_qpel, 2, 4);
- dspfunc(put_h264_qpel, 3, 2);
- dspfunc(avg_h264_qpel, 0, 16);
- dspfunc(avg_h264_qpel, 1, 8);
- dspfunc(avg_h264_qpel, 2, 4);
-
-#undef dspfunc
- c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_c;
- c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_c;
- c->put_h264_chroma_pixels_tab[2]= put_h264_chroma_mc2_c;
- c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_c;
- c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_c;
- c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_c;
- c->put_no_rnd_h264_chroma_pixels_tab[0]= put_no_rnd_h264_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;
-
-#ifdef CONFIG_CAVS_DECODER
- ff_cavsdsp_init(c,avctx);
-#endif
-#if defined(CONFIG_VC1_DECODER) || defined(CONFIG_WMV3_DECODER)
- ff_vc1dsp_init(c,avctx);
-#endif
-#if defined(CONFIG_H264_ENCODER)
- ff_h264dsp_init(c,avctx);
-#endif
-
- c->put_mspel_pixels_tab[0]= put_mspel8_mc00_c;
- c->put_mspel_pixels_tab[1]= put_mspel8_mc10_c;
- c->put_mspel_pixels_tab[2]= put_mspel8_mc20_c;
- c->put_mspel_pixels_tab[3]= put_mspel8_mc30_c;
- c->put_mspel_pixels_tab[4]= put_mspel8_mc02_c;
- c->put_mspel_pixels_tab[5]= put_mspel8_mc12_c;
- c->put_mspel_pixels_tab[6]= put_mspel8_mc22_c;
- c->put_mspel_pixels_tab[7]= put_mspel8_mc32_c;
-
-#define SET_CMP_FUNC(name) \
- c->name[0]= name ## 16_c;\
- c->name[1]= name ## 8x8_c;
-
- SET_CMP_FUNC(hadamard8_diff)
- c->hadamard8_diff[4]= hadamard8_intra16_c;
- SET_CMP_FUNC(dct_sad)
- SET_CMP_FUNC(dct_max)
-#ifdef CONFIG_GPL
- SET_CMP_FUNC(dct264_sad)
-#endif
- c->sad[0]= pix_abs16_c;
- c->sad[1]= pix_abs8_c;
- c->sse[0]= sse16_c;
- c->sse[1]= sse8_c;
- c->sse[2]= sse4_c;
- SET_CMP_FUNC(quant_psnr)
- SET_CMP_FUNC(rd)
- SET_CMP_FUNC(bit)
- c->vsad[0]= vsad16_c;
- c->vsad[4]= vsad_intra16_c;
- c->vsse[0]= vsse16_c;
- c->vsse[4]= vsse_intra16_c;
- c->nsse[0]= nsse16_c;
- c->nsse[1]= nsse8_c;
-#ifdef 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;
-#endif
-
- c->add_bytes= add_bytes_c;
- c->diff_bytes= diff_bytes_c;
- c->sub_hfyu_median_prediction= sub_hfyu_median_prediction_c;
- c->bswap_buf= bswap_buf;
-
- 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_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;
-
- c->h263_h_loop_filter= h263_h_loop_filter_c;
- c->h263_v_loop_filter= h263_v_loop_filter_c;
-
- c->h261_loop_filter= h261_loop_filter_c;
-
- c->try_8x8basis= try_8x8basis_c;
- c->add_8x8basis= add_8x8basis_c;
-
-#ifdef CONFIG_SNOW_ENCODER
- c->vertical_compose97i = ff_snow_vertical_compose97i;
- c->horizontal_compose97i = ff_snow_horizontal_compose97i;
- c->inner_add_yblock = ff_snow_inner_add_yblock;
-#endif
-
-#ifdef CONFIG_VORBIS_DECODER
- c->vorbis_inverse_coupling = vorbis_inverse_coupling;
-#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->float_to_int16 = ff_float_to_int16_c;
-
- c->shrink[0]= ff_img_copy_plane;
- c->shrink[1]= ff_shrink22;
- c->shrink[2]= ff_shrink44;
- c->shrink[3]= ff_shrink88;
-
- c->prefetch= just_return;
-
- memset(c->put_2tap_qpel_pixels_tab, 0, sizeof(c->put_2tap_qpel_pixels_tab));
- memset(c->avg_2tap_qpel_pixels_tab, 0, sizeof(c->avg_2tap_qpel_pixels_tab));
-
-#ifdef HAVE_MMX
- dsputil_init_mmx(c, avctx);
-#endif
-#ifdef ARCH_ARMV4L
- dsputil_init_armv4l(c, avctx);
-#endif
-#ifdef HAVE_MLIB
- dsputil_init_mlib(c, avctx);
-#endif
-#ifdef ARCH_SPARC
- dsputil_init_vis(c,avctx);
-#endif
-#ifdef ARCH_ALPHA
- dsputil_init_alpha(c, avctx);
-#endif
-#ifdef ARCH_POWERPC
- dsputil_init_ppc(c, avctx);
-#endif
-#ifdef HAVE_MMI
- dsputil_init_mmi(c, avctx);
-#endif
-#ifdef ARCH_SH4
- dsputil_init_sh4(c,avctx);
-#endif
-#ifdef ARCH_BFIN
- dsputil_init_bfin(c,avctx);
-#endif
-
- for(i=0; i<64; i++){
- if(!c->put_2tap_qpel_pixels_tab[0][i])
- c->put_2tap_qpel_pixels_tab[0][i]= c->put_h264_qpel_pixels_tab[0][i];
- if(!c->avg_2tap_qpel_pixels_tab[0][i])
- c->avg_2tap_qpel_pixels_tab[0][i]= c->avg_h264_qpel_pixels_tab[0][i];
- }
-
- switch(c->idct_permutation_type){
- case FF_NO_IDCT_PERM:
- for(i=0; i<64; i++)
- c->idct_permutation[i]= i;
- break;
- case FF_LIBMPEG2_IDCT_PERM:
- for(i=0; i<64; i++)
- c->idct_permutation[i]= (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2);
- break;
- case FF_SIMPLE_IDCT_PERM:
- for(i=0; i<64; i++)
- c->idct_permutation[i]= simple_mmx_permutation[i];
- break;
- case FF_TRANSPOSE_IDCT_PERM:
- for(i=0; i<64; i++)
- c->idct_permutation[i]= ((i&7)<<3) | (i>>3);
- break;
- case FF_PARTTRANS_IDCT_PERM:
- for(i=0; i<64; i++)
- c->idct_permutation[i]= (i&0x24) | ((i&3)<<3) | ((i>>3)&3);
- break;
- default:
- av_log(avctx, AV_LOG_ERROR, "Internal error, IDCT permutation not set\n");
- }
-}
-
diff --git a/src/libffmpeg/libavcodec/dsputil.h b/src/libffmpeg/libavcodec/dsputil.h
deleted file mode 100644
index 78109f7b9..000000000
--- a/src/libffmpeg/libavcodec/dsputil.h
+++ /dev/null
@@ -1,759 +0,0 @@
-/*
- * DSP utils
- * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
- * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/**
- * @file dsputil.h
- * 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
- */
-
-#ifndef DSPUTIL_H
-#define DSPUTIL_H
-
-#include "common.h"
-#include "avcodec.h"
-
-
-//#define DEBUG
-/* dct code */
-typedef short DCTELEM;
-typedef int DWTELEM;
-
-void fdct_ifast (DCTELEM *data);
-void fdct_ifast248 (DCTELEM *data);
-void ff_jpeg_fdct_islow (DCTELEM *data);
-void ff_fdct248_islow (DCTELEM *data);
-
-void j_rev_dct (DCTELEM *data);
-void j_rev_dct4 (DCTELEM *data);
-void j_rev_dct2 (DCTELEM *data);
-void j_rev_dct1 (DCTELEM *data);
-
-void ff_fdct_mmx(DCTELEM *block);
-void ff_fdct_mmx2(DCTELEM *block);
-void ff_fdct_sse2(DCTELEM *block);
-
-void ff_h264_idct8_add_c(uint8_t *dst, DCTELEM *block, int stride);
-void ff_h264_idct_add_c(uint8_t *dst, DCTELEM *block, int stride);
-void ff_h264_idct8_dc_add_c(uint8_t *dst, DCTELEM *block, int stride);
-void ff_h264_idct_dc_add_c(uint8_t *dst, DCTELEM *block, int stride);
-void ff_h264_lowres_idct_add_c(uint8_t *dst, int stride, DCTELEM *block);
-void ff_h264_lowres_idct_put_c(uint8_t *dst, int stride, DCTELEM *block);
-
-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_float_to_int16_c(int16_t *dst, const float *src, int len);
-
-/* encoding scans */
-extern const uint8_t ff_alternate_horizontal_scan[64];
-extern const uint8_t ff_alternate_vertical_scan[64];
-extern const uint8_t ff_zigzag_direct[64];
-extern const uint8_t ff_zigzag248_direct[64];
-
-/* pixel operations */
-#define MAX_NEG_CROP 1024
-
-/* temporary */
-extern uint32_t ff_squareTbl[512];
-extern uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP];
-
-/* VP3 DSP functions */
-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*/);
-
-/* 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);
-void ff_shrink44(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
-void ff_shrink88(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
-
-void ff_gmc_c(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);
-
-/* minimum alignment rules ;)
-if u notice errors in the align stuff, need more alignment for some asm code for some cpu
-or need to use a function with less aligned data then send a mail to the ffmpeg-dev list, ...
-
-!warning these alignments might not match reallity, (missing attribute((align)) stuff somewhere possible)
-i (michael) didnt check them, these are just the alignents which i think could be reached easily ...
-
-!future video codecs might need functions with less strict alignment
-*/
-
-/*
-void get_pixels_c(DCTELEM *block, const uint8_t *pixels, int line_size);
-void diff_pixels_c(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, int stride);
-void put_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size);
-void add_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size);
-void clear_blocks_c(DCTELEM *blocks);
-*/
-
-/* add and put pixel (decoding) */
-// blocksizes for op_pixels_func are 8x4,8x8 16x8 16x16
-//h for op_pixels_func is limited to {width/2, width} but never larger than 16 and never smaller then 4
-typedef void (*op_pixels_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, int line_size, int h);
-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);
-
-#define DEF_OLD_QPEL(name)\
-void ff_put_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
-void ff_put_no_rnd_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
-void ff_avg_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);
-
-DEF_OLD_QPEL(qpel16_mc11_old_c)
-DEF_OLD_QPEL(qpel16_mc31_old_c)
-DEF_OLD_QPEL(qpel16_mc12_old_c)
-DEF_OLD_QPEL(qpel16_mc32_old_c)
-DEF_OLD_QPEL(qpel16_mc13_old_c)
-DEF_OLD_QPEL(qpel16_mc33_old_c)
-DEF_OLD_QPEL(qpel8_mc11_old_c)
-DEF_OLD_QPEL(qpel8_mc31_old_c)
-DEF_OLD_QPEL(qpel8_mc12_old_c)
-DEF_OLD_QPEL(qpel8_mc32_old_c)
-DEF_OLD_QPEL(qpel8_mc13_old_c)
-DEF_OLD_QPEL(qpel8_mc33_old_c)
-
-#define CALL_2X_PIXELS(a, b, n)\
-static void a(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
- b(block , pixels , line_size, h);\
- b(block+n, pixels+n, line_size, h);\
-}
-
-/* motion estimation */
-// h is limited to {width/2, width, 2*width} but never larger than 16 and never smaller then 2
-// allthough currently h<4 is not used as functions with width <8 are not used and neither 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;
-
-/**
- * DSPContext.
- */
-typedef struct DSPContext {
- /* pixel ops : interface with DCT */
- void (*get_pixels)(DCTELEM *block/*align 16*/, const uint8_t *pixels/*align 8*/, int line_size);
- void (*diff_pixels)(DCTELEM *block/*align 16*/, const uint8_t *s1/*align 8*/, const uint8_t *s2/*align 8*/, int stride);
- void (*put_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
- void (*put_signed_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
- void (*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);
- /**
- * translational global motion compensation.
- */
- void (*gmc1)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x16, int y16, int rounder);
- /**
- * global motion compensation.
- */
- void (*gmc )(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int ox, int oy,
- int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height);
- void (*clear_blocks)(DCTELEM *blocks/*align 16*/);
- int (*pix_sum)(uint8_t * pix, int line_size);
- int (*pix_norm1)(uint8_t * pix, int line_size);
-// 16x16 8x8 4x4 2x2 16x8 8x4 4x2 8x16 4x8 2x4
-
- me_cmp_func sad[5]; /* identical to pix_absAxA except additional void * */
- me_cmp_func sse[5];
- me_cmp_func hadamard8_diff[5];
- me_cmp_func dct_sad[5];
- me_cmp_func quant_psnr[5];
- me_cmp_func bit[5];
- me_cmp_func rd[5];
- me_cmp_func vsad[5];
- me_cmp_func vsse[5];
- me_cmp_func nsse[5];
- me_cmp_func w53[5];
- me_cmp_func w97[5];
- me_cmp_func dct_max[5];
- me_cmp_func dct264_sad[5];
-
- me_cmp_func me_pre_cmp[5];
- me_cmp_func me_cmp[5];
- me_cmp_func me_sub_cmp[5];
- me_cmp_func mb_cmp[5];
- me_cmp_func ildct_cmp[5]; //only width 16 used
- me_cmp_func frame_skip_cmp[5]; //only width 8 used
-
- /**
- * Halfpel motion compensation with rounding (a+b+1)>>1.
- * this is an array[4][4] of motion compensation funcions for 4
- * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
- * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
- * @param block destination where the result is stored
- * @param pixels source
- * @param line_size number of bytes in a horizontal line of block
- * @param h height
- */
- op_pixels_func put_pixels_tab[4][4];
-
- /**
- * Halfpel motion compensation with rounding (a+b+1)>>1.
- * This is an array[4][4] of motion compensation functions for 4
- * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
- * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
- * @param block destination into which the result is averaged (a+b+1)>>1
- * @param pixels source
- * @param line_size number of bytes in a horizontal line of block
- * @param h height
- */
- op_pixels_func avg_pixels_tab[4][4];
-
- /**
- * Halfpel motion compensation with no rounding (a+b)>>1.
- * this is an array[2][4] of motion compensation funcions for 2
- * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
- * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
- * @param block destination where the result is stored
- * @param pixels source
- * @param line_size number of bytes in a horizontal line of block
- * @param h height
- */
- op_pixels_func put_no_rnd_pixels_tab[4][4];
-
- /**
- * Halfpel motion compensation with no rounding (a+b)>>1.
- * this is an array[2][4] of motion compensation funcions for 2
- * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
- * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
- * @param block destination into which the result is averaged (a+b)>>1
- * @param pixels source
- * @param line_size number of bytes in a horizontal line of block
- * @param h height
- */
- op_pixels_func avg_no_rnd_pixels_tab[4][4];
-
- void (*put_no_rnd_pixels_l2[2])(uint8_t *block/*align width (8 or 16)*/, const uint8_t *a/*align 1*/, const uint8_t *b/*align 1*/, int line_size, int h);
-
- /**
- * Thirdpel motion compensation with rounding (a+b+1)>>1.
- * this is an array[12] of motion compensation funcions for the 9 thirdpel positions<br>
- * *pixels_tab[ xthirdpel + 4*ythirdpel ]
- * @param block destination where the result is stored
- * @param pixels source
- * @param line_size number of bytes in a horizontal line of block
- * @param h height
- */
- tpel_mc_func put_tpel_pixels_tab[11]; //FIXME individual func ptr per width?
- tpel_mc_func avg_tpel_pixels_tab[11]; //FIXME individual func ptr per width?
-
- qpel_mc_func put_qpel_pixels_tab[2][16];
- qpel_mc_func avg_qpel_pixels_tab[2][16];
- qpel_mc_func put_no_rnd_qpel_pixels_tab[2][16];
- qpel_mc_func avg_no_rnd_qpel_pixels_tab[2][16];
- qpel_mc_func put_mspel_pixels_tab[8];
-
- /**
- * h264 Chram MC
- */
- h264_chroma_mc_func put_h264_chroma_pixels_tab[3];
- /* This is really one func used in VC-1 decoding */
- h264_chroma_mc_func put_no_rnd_h264_chroma_pixels_tab[3];
- h264_chroma_mc_func avg_h264_chroma_pixels_tab[3];
-
- qpel_mc_func put_h264_qpel_pixels_tab[4][16];
- qpel_mc_func avg_h264_qpel_pixels_tab[4][16];
-
- 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];
- void (*cavs_filter_lv)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
- void (*cavs_filter_lh)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
- void (*cavs_filter_cv)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
- void (*cavs_filter_ch)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
- void (*cavs_idct8_add)(uint8_t *dst, DCTELEM *block, int stride);
-
- me_cmp_func pix_abs[2][4];
-
- /* huffyuv specific */
- void (*add_bytes)(uint8_t *dst/*align 16*/, uint8_t *src/*align 16*/, int w);
- void (*diff_bytes)(uint8_t *dst/*align 16*/, uint8_t *src1/*align 16*/, uint8_t *src2/*align 1*/,int w);
- /**
- * subtract huffyuv's variant of median prediction
- * 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 (*bswap_buf)(uint32_t *dst, uint32_t *src, int w);
-
- void (*h264_v_loop_filter_luma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0);
- void (*h264_h_loop_filter_luma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0);
- void (*h264_v_loop_filter_chroma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0);
- void (*h264_h_loop_filter_chroma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0);
- void (*h264_v_loop_filter_chroma_intra)(uint8_t *pix, int stride, int alpha, int beta);
- void (*h264_h_loop_filter_chroma_intra)(uint8_t *pix, 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);
-
- void (*h263_v_loop_filter)(uint8_t *src, int stride, int qscale);
- void (*h263_h_loop_filter)(uint8_t *src, int stride, int qscale);
-
- void (*h261_loop_filter)(uint8_t *src, int stride);
-
- /* assume len is a multiple of 4, and arrays are 16-byte aligned */
- void (*vorbis_inverse_coupling)(float *mag, float *ang, int blocksize);
- /* 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);
-
- /* 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 */
- void (*float_to_int16)(int16_t *dst, const float *src, int len);
-
- /* (I)DCT */
- void (*fdct)(DCTELEM *block/* align 16*/);
- void (*fdct248)(DCTELEM *block/* align 16*/);
-
- /* IDCT really*/
- void (*idct)(DCTELEM *block/* align 16*/);
-
- /**
- * block -> idct -> clip to unsigned 8 bit -> dest.
- * (-1392, 0, 0, ...) -> idct -> (-174, -174, ...) -> put -> (0, 0, ...)
- * @param line_size size in bytes of a horizotal line of dest
- */
- void (*idct_put)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
-
- /**
- * block -> idct -> add dest -> clip to unsigned 8 bit -> dest.
- * @param line_size size in bytes of a horizotal line of dest
- */
- void (*idct_add)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
-
- /**
- * idct input permutation.
- * several optimized IDCTs need a permutated input (relative to the normal order of the reference
- * IDCT)
- * this permutation must be performed before the idct_put/add, note, normally this can be merged
- * with the zigzag/alternate scan<br>
- * an example to avoid confusion:
- * - (->decode coeffs -> zigzag reorder -> dequant -> reference idct ->...)
- * - (x -> referece dct -> reference idct -> x)
- * - (x -> referece dct -> simple_mmx_perm = idct_permutation -> simple_idct_mmx -> x)
- * - (->decode coeffs -> zigzag reorder -> simple_mmx_perm -> dequant -> simple_idct_mmx ->...)
- */
- uint8_t idct_permutation[64];
- int idct_permutation_type;
-#define FF_NO_IDCT_PERM 1
-#define FF_LIBMPEG2_IDCT_PERM 2
-#define FF_SIMPLE_IDCT_PERM 3
-#define FF_TRANSPOSE_IDCT_PERM 4
-#define FF_PARTTRANS_IDCT_PERM 5
-
- int (*try_8x8basis)(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale);
- void (*add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale);
-#define BASIS_SHIFT 16
-#define RECON_SHIFT 6
-
- /* h264 functions */
- void (*h264_idct_add)(uint8_t *dst, DCTELEM *block, int stride);
- void (*h264_idct8_add)(uint8_t *dst, DCTELEM *block, int stride);
- void (*h264_idct_dc_add)(uint8_t *dst, DCTELEM *block, int stride);
- void (*h264_idct8_dc_add)(uint8_t *dst, DCTELEM *block, int stride);
- void (*h264_dct)(DCTELEM block[4][4]);
-
- /* snow wavelet */
- void (*vertical_compose97i)(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWTELEM *b3, DWTELEM *b4, DWTELEM *b5, int width);
- void (*horizontal_compose97i)(DWTELEM *b, int width);
- void (*inner_add_yblock)(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);
-
- /* vc1 functions */
- void (*vc1_inv_trans_8x8)(DCTELEM *b);
- void (*vc1_inv_trans_8x4)(DCTELEM *b, int n);
- void (*vc1_inv_trans_4x8)(DCTELEM *b, int n);
- void (*vc1_inv_trans_4x4)(DCTELEM *b, int n);
- void (*vc1_v_overlap)(uint8_t* src, int stride);
- void (*vc1_h_overlap)(uint8_t* src, int stride);
- /* put 8x8 block with bicubic interpolation and quarterpel precision
- * last argument is actually round value instead of height
- */
- op_pixels_func put_vc1_mspel_pixels_tab[16];
-} DSPContext;
-
-void dsputil_static_init(void);
-void dsputil_init(DSPContext* p, AVCodecContext *avctx);
-
-int ff_check_alignment(void);
-
-/**
- * permute block according to permuatation.
- * @param last last non zero element in scantable order
- */
-void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last);
-
-void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type);
-
-#define BYTE_VEC32(c) ((c)*0x01010101UL)
-
-static inline uint32_t rnd_avg32(uint32_t a, uint32_t b)
-{
- return (a | b) - (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
-}
-
-static inline uint32_t no_rnd_avg32(uint32_t a, uint32_t b)
-{
- return (a & b) + (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
-}
-
-static inline int get_penalty_factor(int lambda, int lambda2, int type){
- switch(type&0xFF){
- default:
- case FF_CMP_SAD:
- return lambda>>FF_LAMBDA_SHIFT;
- case FF_CMP_DCT:
- return (3*lambda)>>(FF_LAMBDA_SHIFT+1);
- case FF_CMP_W53:
- return (4*lambda)>>(FF_LAMBDA_SHIFT);
- case FF_CMP_W97:
- return (2*lambda)>>(FF_LAMBDA_SHIFT);
- case FF_CMP_SATD:
- case FF_CMP_DCT264:
- return (2*lambda)>>FF_LAMBDA_SHIFT;
- case FF_CMP_RD:
- case FF_CMP_PSNR:
- case FF_CMP_SSE:
- case FF_CMP_NSSE:
- return lambda2>>FF_LAMBDA_SHIFT;
- case FF_CMP_BIT:
- return 1;
- }
-}
-
-/**
- * Empty mmx state.
- * this must be called between any dsp function and float/double code.
- * for example sin(); dsp->idct_put(); emms_c(); cos()
- */
-#define emms_c()
-
-/* should be defined by architectures supporting
- one or more MultiMedia extension */
-int mm_support(void);
-
-#ifdef __GNUC__
- #define DECLARE_ALIGNED_16(t,v) t v __attribute__ ((aligned (16)))
-#else
- #define DECLARE_ALIGNED_16(t,v) __declspec(align(16)) t v
-#endif
-
-#if defined(HAVE_MMX)
-
-#undef emms_c
-
-#define MM_MMX 0x0001 /* standard MMX */
-#define MM_3DNOW 0x0004 /* AMD 3DNOW */
-#define MM_MMXEXT 0x0002 /* SSE integer functions or AMD MMX ext */
-#define MM_SSE 0x0008 /* SSE functions */
-#define MM_SSE2 0x0010 /* PIV SSE2 functions */
-#define MM_3DNOWEXT 0x0020 /* AMD 3DNowExt */
-#define MM_SSE3 0x0040 /* Prescott SSE3 functions */
-#define MM_SSSE3 0x0080 /* Conroe SSSE3 functions */
-
-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");
-}
-
-
-#define emms_c() \
-{\
- if (mm_flags & MM_MMX)\
- emms();\
-}
-
-#ifdef __GNUC__
- #define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8)))
-#else
- #define DECLARE_ALIGNED_8(t,v) __declspec(align(8)) t v
-#endif
-
-#define STRIDE_ALIGN 8
-
-void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx);
-void dsputil_init_pix_mmx(DSPContext* c, AVCodecContext *avctx);
-
-#elif defined(ARCH_ARMV4L)
-
-/* This is to use 4 bytes read to the IDCT pointers for some 'zero'
- line optimizations */
-#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (4)))
-#define STRIDE_ALIGN 4
-
-#define MM_IWMMXT 0x0100 /* XScale IWMMXT */
-
-extern int mm_flags;
-
-void dsputil_init_armv4l(DSPContext* c, AVCodecContext *avctx);
-
-#elif defined(HAVE_MLIB)
-
-/* SPARC/VIS IDCT needs 8-byte aligned DCT blocks */
-#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8)))
-#define STRIDE_ALIGN 8
-
-void dsputil_init_mlib(DSPContext* c, AVCodecContext *avctx);
-
-#elif defined(ARCH_SPARC)
-
-/* SPARC/VIS IDCT needs 8-byte aligned DCT blocks */
-#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8)))
-#define STRIDE_ALIGN 8
-void dsputil_init_vis(DSPContext* c, AVCodecContext *avctx);
-
-#elif defined(ARCH_ALPHA)
-
-#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8)))
-#define STRIDE_ALIGN 8
-
-void dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx);
-
-#elif defined(ARCH_POWERPC)
-
-#define MM_ALTIVEC 0x0001 /* standard AltiVec */
-
-extern int mm_flags;
-
-#if defined(HAVE_ALTIVEC) && !defined(CONFIG_DARWIN)
-#define pixel altivec_pixel
-#include <altivec.h>
-#undef pixel
-#endif
-
-#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (16)))
-#define STRIDE_ALIGN 16
-
-void dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx);
-
-#elif defined(HAVE_MMI)
-
-#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (16)))
-#define STRIDE_ALIGN 16
-
-void dsputil_init_mmi(DSPContext* c, AVCodecContext *avctx);
-
-#elif defined(ARCH_SH4)
-
-#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8)))
-#define STRIDE_ALIGN 8
-
-void dsputil_init_sh4(DSPContext* c, AVCodecContext *avctx);
-
-#elif defined(ARCH_BFIN)
-
-#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8)))
-#define STRIDE_ALIGN 8
-
-void dsputil_init_bfin(DSPContext* c, AVCodecContext *avctx);
-
-#else
-
-#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8)))
-#define STRIDE_ALIGN 8
-
-#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 */
- void (*fft_calc)(struct FFTContext *s, FFTComplex *z);
- void (*imdct_calc)(struct MDCTContext *s, FFTSample *output,
- const FFTSample *input, FFTSample *tmp);
-} FFTContext;
-
-int ff_fft_init(FFTContext *s, int nbits, int inverse);
-void ff_fft_permute(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);
-
-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;
-
-int ff_mdct_init(MDCTContext *s, int nbits, int inverse);
-void ff_imdct_calc(MDCTContext *s, FFTSample *output,
- const FFTSample *input, FFTSample *tmp);
-void ff_imdct_calc_3dn2(MDCTContext *s, FFTSample *output,
- const FFTSample *input, FFTSample *tmp);
-void ff_imdct_calc_sse(MDCTContext *s, FFTSample *output,
- const FFTSample *input, FFTSample *tmp);
-void ff_mdct_calc(MDCTContext *s, FFTSample *out,
- const FFTSample *input, FFTSample *tmp);
-void ff_mdct_end(MDCTContext *s);
-
-#define WARPER8_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)\
- +name8(s, dst+8 , src+8 , stride, h);\
-}
-
-#define WARPER8_16_SQ(name8, name16)\
-static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\
- int score=0;\
- score +=name8(s, dst , src , stride, 8);\
- score +=name8(s, dst+8 , src+8 , stride, 8);\
- if(h==16){\
- dst += 8*stride;\
- src += 8*stride;\
- score +=name8(s, dst , src , stride, 8);\
- score +=name8(s, dst+8 , src+8 , stride, 8);\
- }\
- return score;\
-}
-
-
-static inline void copy_block2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
-{
- int i;
- for(i=0; i<h; i++)
- {
- ST16(dst , LD16(src ));
- dst+=dstStride;
- src+=srcStride;
- }
-}
-
-static inline void copy_block4(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
-{
- int i;
- for(i=0; i<h; i++)
- {
- ST32(dst , LD32(src ));
- dst+=dstStride;
- src+=srcStride;
- }
-}
-
-static inline void copy_block8(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
-{
- int i;
- for(i=0; i<h; i++)
- {
- ST32(dst , LD32(src ));
- ST32(dst+4 , LD32(src+4 ));
- dst+=dstStride;
- src+=srcStride;
- }
-}
-
-static inline void copy_block9(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
-{
- int i;
- for(i=0; i<h; i++)
- {
- ST32(dst , LD32(src ));
- ST32(dst+4 , LD32(src+4 ));
- dst[8]= src[8];
- dst+=dstStride;
- src+=srcStride;
- }
-}
-
-static inline void copy_block16(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
-{
- int i;
- for(i=0; i<h; i++)
- {
- ST32(dst , LD32(src ));
- ST32(dst+4 , LD32(src+4 ));
- ST32(dst+8 , LD32(src+8 ));
- ST32(dst+12, LD32(src+12));
- dst+=dstStride;
- src+=srcStride;
- }
-}
-
-static inline void copy_block17(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
-{
- int i;
- for(i=0; i<h; i++)
- {
- ST32(dst , LD32(src ));
- ST32(dst+4 , LD32(src+4 ));
- ST32(dst+8 , LD32(src+8 ));
- ST32(dst+12, LD32(src+12));
- dst[16]= src[16];
- dst+=dstStride;
- src+=srcStride;
- }
-}
-
-#endif
diff --git a/src/libffmpeg/libavcodec/dv.c b/src/libffmpeg/libavcodec/dv.c
deleted file mode 100644
index 505c88d49..000000000
--- a/src/libffmpeg/libavcodec/dv.c
+++ /dev/null
@@ -1,1266 +0,0 @@
-/*
- * DV decoder
- * Copyright (c) 2002 Fabrice Bellard.
- * Copyright (c) 2004 Roman Shaposhnik.
- *
- * DV encoder
- * Copyright (c) 2003 Roman Shaposhnik.
- *
- * 50 Mbps (DVCPRO50) support
- * Copyright (c) 2006 Daniel Maas <dmaas@maasdigital.com>
- *
- * Many thanks to Dan Dennedy <dan@dennedy.org> for providing wealth
- * of DV technical info.
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General 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 dv.c
- * DV codec.
- */
-#define ALT_BITSTREAM_READER
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-#include "simple_idct.h"
-#include "dvdata.h"
-
-//#undef NDEBUG
-//#include <assert.h>
-
-typedef struct DVVideoContext {
- const DVprofile* sys;
- AVFrame picture;
- AVCodecContext *avctx;
- uint8_t *buf;
-
- uint8_t dv_zigzag[2][64];
- uint8_t dv_idct_shift[2][2][22][64];
-
- void (*get_pixels)(DCTELEM *block, const uint8_t *pixels, int line_size);
- void (*fdct[2])(DCTELEM *block);
- void (*idct_put[2])(uint8_t *dest, int line_size, DCTELEM *block);
-} DVVideoContext;
-
-/* MultiThreading - dv_anchor applies to entire DV codec, not just the avcontext */
-/* one element is needed for each video segment in a DV frame */
-/* at most there are 2 DIF channels * 12 DIF sequences * 27 video segments (PAL 50Mbps) */
-#define DV_ANCHOR_SIZE (2*12*27)
-
-static void* dv_anchor[DV_ANCHOR_SIZE];
-
-#define TEX_VLC_BITS 9
-
-#ifdef DV_CODEC_TINY_TARGET
-#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;
-/* VLC encoding lookup table */
-static struct dv_vlc_pair {
- uint32_t vlc;
- uint8_t size;
-} (*dv_vlc_map)[DV_VLC_MAP_LEV_SIZE] = NULL;
-
-static void dv_build_unquantize_tables(DVVideoContext *s, uint8_t* perm)
-{
- int i, q, j;
-
- /* NOTE: max left shift is 6 */
- for(q = 0; q < 22; q++) {
- /* 88DCT */
- for(i = 1; i < 64; i++) {
- /* 88 table */
- j = perm[i];
- s->dv_idct_shift[0][0][q][j] =
- dv_quant_shifts[q][dv_88_areas[i]] + 1;
- s->dv_idct_shift[1][0][q][j] = s->dv_idct_shift[0][0][q][j] + 1;
- }
-
- /* 248DCT */
- for(i = 1; i < 64; i++) {
- /* 248 table */
- s->dv_idct_shift[0][1][q][i] =
- dv_quant_shifts[q][dv_248_areas[i]] + 1;
- s->dv_idct_shift[1][1][q][i] = s->dv_idct_shift[0][1][q][i] + 1;
- }
- }
-}
-
-static int dvvideo_init(AVCodecContext *avctx)
-{
- DVVideoContext *s = avctx->priv_data;
- DSPContext dsp;
- static int done=0;
- int i, j;
-
- if (!done) {
- VLC dv_vlc;
- uint16_t new_dv_vlc_bits[NB_DV_VLC*2];
- uint8_t new_dv_vlc_len[NB_DV_VLC*2];
- uint8_t new_dv_vlc_run[NB_DV_VLC*2];
- int16_t new_dv_vlc_level[NB_DV_VLC*2];
-
- done = 1;
-
- dv_vlc_map = av_mallocz_static(DV_VLC_MAP_LEV_SIZE*DV_VLC_MAP_RUN_SIZE*sizeof(struct dv_vlc_pair));
- if (!dv_vlc_map)
- return -ENOMEM;
-
- /* dv_anchor lets each thread know its Id */
- for (i=0; i<DV_ANCHOR_SIZE; i++)
- dv_anchor[i] = (void*)(size_t)i;
-
- /* it's faster to include sign bit in a generic VLC parsing scheme */
- for (i=0, j=0; i<NB_DV_VLC; i++, j++) {
- new_dv_vlc_bits[j] = dv_vlc_bits[i];
- new_dv_vlc_len[j] = dv_vlc_len[i];
- new_dv_vlc_run[j] = dv_vlc_run[i];
- new_dv_vlc_level[j] = dv_vlc_level[i];
-
- if (dv_vlc_level[i]) {
- new_dv_vlc_bits[j] <<= 1;
- new_dv_vlc_len[j]++;
-
- j++;
- new_dv_vlc_bits[j] = (dv_vlc_bits[i] << 1) | 1;
- new_dv_vlc_len[j] = dv_vlc_len[i] + 1;
- new_dv_vlc_run[j] = dv_vlc_run[i];
- new_dv_vlc_level[j] = -dv_vlc_level[i];
- }
- }
-
- /* NOTE: as a trick, we use the fact the no codes are unused
- to accelerate the parsing of partial codes */
- init_vlc(&dv_vlc, TEX_VLC_BITS, j,
- new_dv_vlc_len, 1, 1, new_dv_vlc_bits, 2, 2, 0);
-
- dv_rl_vlc = av_mallocz_static(dv_vlc.table_size * sizeof(RL_VLC_ELEM));
- if (!dv_rl_vlc)
- return -ENOMEM;
-
- for(i = 0; i < dv_vlc.table_size; i++){
- int code= dv_vlc.table[i][0];
- int len = dv_vlc.table[i][1];
- int level, run;
-
- if(len<0){ //more bits needed
- run= 0;
- level= code;
- } else {
- run= new_dv_vlc_run[code] + 1;
- level= new_dv_vlc_level[code];
- }
- dv_rl_vlc[i].len = len;
- dv_rl_vlc[i].level = level;
- dv_rl_vlc[i].run = run;
- }
- free_vlc(&dv_vlc);
-
- for (i = 0; i < NB_DV_VLC - 1; i++) {
- if (dv_vlc_run[i] >= DV_VLC_MAP_RUN_SIZE)
- continue;
-#ifdef DV_CODEC_TINY_TARGET
- 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++) {
-#ifdef DV_CODEC_TINY_TARGET
- 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
- }
- }
-
- /* Generic DSP setup */
- dsputil_init(&dsp, avctx);
- s->get_pixels = dsp.get_pixels;
-
- /* 88DCT setup */
- s->fdct[0] = dsp.fdct;
- s->idct_put[0] = dsp.idct_put;
- for (i=0; i<64; i++)
- s->dv_zigzag[0][i] = dsp.idct_permutation[ff_zigzag_direct[i]];
-
- /* 248DCT setup */
- s->fdct[1] = dsp.fdct248;
- s->idct_put[1] = simple_idct248_put; // FIXME: need to add it to DSP
- if(avctx->lowres){
- for (i=0; i<64; i++){
- int j= ff_zigzag248_direct[i];
- s->dv_zigzag[1][i] = dsp.idct_permutation[(j&7) + (j&8)*4 + (j&48)/2];
- }
- }else
- memcpy(s->dv_zigzag[1], ff_zigzag248_direct, 64);
-
- /* XXX: do it only for constant case */
- dv_build_unquantize_tables(s, dsp.idct_permutation);
-
- avctx->coded_frame = &s->picture;
- s->avctx= avctx;
-
- return 0;
-}
-
-// #define VLC_DEBUG
-// #define printf(...) av_log(NULL, AV_LOG_ERROR, __VA_ARGS__)
-
-typedef struct BlockInfo {
- const uint8_t *shift_table;
- const uint8_t *scan_table;
- const int *iweight_table;
- uint8_t pos; /* position in block */
- uint8_t dct_mode;
- uint8_t partial_bit_count;
- uint16_t partial_bit_buffer;
- int shift_offset;
-} BlockInfo;
-
-/* block size in bits */
-static const uint16_t block_sizes[6] = {
- 112, 112, 112, 112, 80, 80
-};
-/* bit budget for AC only in 5 MBs */
-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 get_bits_size(GetBitContext *s)
-{
- return s->size_in_bits;
-}
-
-static inline int put_bits_left(PutBitContext* s)
-{
- return (s->buf_end - s->buf) * 8 - put_bits_count(s);
-}
-
-/* decode ac coefs */
-static void dv_decode_ac(GetBitContext *gb, BlockInfo *mb, DCTELEM *block)
-{
- int last_index = get_bits_size(gb);
- const uint8_t *scan_table = mb->scan_table;
- const uint8_t *shift_table = mb->shift_table;
- const int *iweight_table = mb->iweight_table;
- int pos = mb->pos;
- int partial_bit_count = mb->partial_bit_count;
- int level, pos1, run, vlc_len, index;
-
- OPEN_READER(re, gb);
- UPDATE_CACHE(re, gb);
-
- /* if we must parse a partial vlc, we do it here */
- if (partial_bit_count > 0) {
- re_cache = ((unsigned)re_cache >> partial_bit_count) |
- (mb->partial_bit_buffer << (sizeof(re_cache)*8 - partial_bit_count));
- re_index -= partial_bit_count;
- mb->partial_bit_count = 0;
- }
-
- /* get the AC coefficients until last_index is reached */
- for(;;) {
-#ifdef VLC_DEBUG
- printf("%2d: bits=%04x index=%d\n", pos, SHOW_UBITS(re, gb, 16), re_index);
-#endif
- /* our own optimized GET_RL_VLC */
- index = NEG_USR32(re_cache, TEX_VLC_BITS);
- vlc_len = dv_rl_vlc[index].len;
- if (vlc_len < 0) {
- index = NEG_USR32((unsigned)re_cache << TEX_VLC_BITS, -vlc_len) + dv_rl_vlc[index].level;
- vlc_len = TEX_VLC_BITS - vlc_len;
- }
- level = dv_rl_vlc[index].level;
- run = dv_rl_vlc[index].run;
-
- /* gotta check if we're still within gb boundaries */
- if (re_index + vlc_len > last_index) {
- /* should be < 16 bits otherwise a codeword could have been parsed */
- mb->partial_bit_count = last_index - re_index;
- mb->partial_bit_buffer = NEG_USR32(re_cache, mb->partial_bit_count);
- re_index = last_index;
- break;
- }
- re_index += vlc_len;
-
-#ifdef VLC_DEBUG
- printf("run=%d level=%d\n", run, level);
-#endif
- pos += run;
- if (pos >= 64)
- break;
-
- pos1 = scan_table[pos];
- level <<= shift_table[pos1];
-
- /* unweigh, round, and shift down */
- level = (level*iweight_table[pos] + (1 << (dv_iweight_bits-1))) >> dv_iweight_bits;
-
- block[pos1] = level;
-
- UPDATE_CACHE(re, gb);
- }
- CLOSE_READER(re, gb);
- mb->pos = pos;
-}
-
-static inline void bit_copy(PutBitContext *pb, GetBitContext *gb)
-{
- int bits_left = get_bits_left(gb);
- while (bits_left >= MIN_CACHE_BITS) {
- put_bits(pb, MIN_CACHE_BITS, get_bits(gb, MIN_CACHE_BITS));
- bits_left -= MIN_CACHE_BITS;
- }
- if (bits_left > 0) {
- put_bits(pb, bits_left, get_bits(gb, bits_left));
- }
-}
-
-/* mb_x and mb_y are in units of 8 pixels */
-static inline void dv_decode_video_segment(DVVideoContext *s,
- uint8_t *buf_ptr1,
- const uint16_t *mb_pos_ptr)
-{
- int quant, dc, dct_mode, class1, j;
- int mb_index, mb_x, mb_y, v, last_index;
- DCTELEM *block, *block1;
- int c_offset;
- uint8_t *y_ptr;
- void (*idct_put)(uint8_t *dest, int line_size, DCTELEM *block);
- uint8_t *buf_ptr;
- PutBitContext pb, vs_pb;
- GetBitContext gb;
- BlockInfo mb_data[5 * 6], *mb, *mb1;
- DECLARE_ALIGNED_8(DCTELEM, sblock[5*6][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 */
- const int log2_blocksize= 3-s->avctx->lowres;
-
- assert((((int)mb_bit_buffer)&7)==0);
- assert((((int)vs_bit_buffer)&7)==0);
-
- memset(sblock, 0, sizeof(sblock));
-
- /* pass 1 : read DC and AC coefficients in blocks */
- buf_ptr = buf_ptr1;
- block1 = &sblock[0][0];
- mb1 = mb_data;
- init_put_bits(&vs_pb, vs_bit_buffer, 5 * 80);
- for(mb_index = 0; mb_index < 5; mb_index++, mb1 += 6, block1 += 6 * 64) {
- /* skip header */
- quant = buf_ptr[3] & 0x0f;
- buf_ptr += 4;
- init_put_bits(&pb, mb_bit_buffer, 80);
- mb = mb1;
- block = block1;
- for(j = 0;j < 6; j++) {
- last_index = block_sizes[j];
- init_get_bits(&gb, buf_ptr, last_index);
-
- /* get the dc */
- dc = get_sbits(&gb, 9);
- dct_mode = get_bits1(&gb);
- mb->dct_mode = dct_mode;
- mb->scan_table = s->dv_zigzag[dct_mode];
- mb->iweight_table = dct_mode ? dv_iweight_248 : dv_iweight_88;
- class1 = get_bits(&gb, 2);
- mb->shift_table = s->dv_idct_shift[class1 == 3][dct_mode]
- [quant + dv_quant_offset[class1]];
- dc = dc << 2;
- /* convert to unsigned because 128 is not added in the
- standard IDCT */
- dc += 1024;
- block[0] = dc;
- buf_ptr += last_index >> 3;
- mb->pos = 0;
- mb->partial_bit_count = 0;
-
-#ifdef VLC_DEBUG
- printf("MB block: %d, %d ", mb_index, j);
-#endif
- dv_decode_ac(&gb, mb, block);
-
- /* write the remaining bits in a new buffer only if the
- block is finished */
- if (mb->pos >= 64)
- bit_copy(&pb, &gb);
-
- block += 64;
- mb++;
- }
-
- /* pass 2 : we can do it just after */
-#ifdef VLC_DEBUG
- printf("***pass 2 size=%d MB#=%d\n", put_bits_count(&pb), mb_index);
-#endif
- block = block1;
- mb = mb1;
- init_get_bits(&gb, mb_bit_buffer, put_bits_count(&pb));
- flush_put_bits(&pb);
- for(j = 0;j < 6; j++, block += 64, mb++) {
- if (mb->pos < 64 && get_bits_left(&gb) > 0) {
- dv_decode_ac(&gb, mb, block);
- /* if still not finished, no need to parse other blocks */
- if (mb->pos < 64)
- break;
- }
- }
- /* all blocks are finished, so the extra bytes can be used at
- the video segment level */
- if (j >= 6)
- bit_copy(&vs_pb, &gb);
- }
-
- /* we need a pass other the whole video segment */
-#ifdef VLC_DEBUG
- printf("***pass 3 size=%d\n", put_bits_count(&vs_pb));
-#endif
- block = &sblock[0][0];
- mb = mb_data;
- init_get_bits(&gb, vs_bit_buffer, put_bits_count(&vs_pb));
- flush_put_bits(&vs_pb);
- for(mb_index = 0; mb_index < 5; mb_index++) {
- for(j = 0;j < 6; j++) {
- if (mb->pos < 64) {
-#ifdef VLC_DEBUG
- printf("start %d:%d\n", mb_index, j);
-#endif
- 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);
- block += 64;
- mb++;
- }
- }
-
- /* compute idct and place blocks */
- block = &sblock[0][0];
- mb = mb_data;
- for(mb_index = 0; mb_index < 5; mb_index++) {
- v = *mb_pos_ptr++;
- mb_x = v & 0xff;
- mb_y = v >> 8;
- if (s->sys->pix_fmt == PIX_FMT_YUV422P) {
- y_ptr = s->picture.data[0] + ((mb_y * s->picture.linesize[0] + (mb_x>>1))<<log2_blocksize);
- c_offset = ((mb_y * s->picture.linesize[1] + (mb_x >> 2))<<log2_blocksize);
- } else { /* 4:1:1 or 4:2:0 */
- y_ptr = s->picture.data[0] + ((mb_y * s->picture.linesize[0] + mb_x)<<log2_blocksize);
- if (s->sys->pix_fmt == PIX_FMT_YUV411P)
- c_offset = ((mb_y * s->picture.linesize[1] + (mb_x >> 2))<<log2_blocksize);
- else /* 4:2:0 */
- c_offset = (((mb_y >> 1) * s->picture.linesize[1] + (mb_x >> 1))<<log2_blocksize);
- }
- for(j = 0;j < 6; j++) {
- idct_put = s->idct_put[mb->dct_mode && log2_blocksize==3];
- if (s->sys->pix_fmt == PIX_FMT_YUV422P) { /* 4:2:2 */
- if (j == 0 || j == 2) {
- /* Y0 Y1 */
- idct_put(y_ptr + ((j >> 1)<<log2_blocksize),
- s->picture.linesize[0], block);
- } else if(j > 3) {
- /* Cr Cb */
- idct_put(s->picture.data[6 - j] + c_offset,
- s->picture.linesize[6 - j], block);
- }
- /* note: j=1 and j=3 are "dummy" blocks in 4:2:2 */
- } else { /* 4:1:1 or 4:2:0 */
- if (j < 4) {
- if (s->sys->pix_fmt == PIX_FMT_YUV411P && mb_x < (704 / 8)) {
- /* NOTE: at end of line, the macroblock is handled as 420 */
- idct_put(y_ptr + (j<<log2_blocksize), s->picture.linesize[0], block);
- } else {
- idct_put(y_ptr + (((j & 1) + (j >> 1) * s->picture.linesize[0])<<log2_blocksize),
- s->picture.linesize[0], block);
- }
- } else {
- if (s->sys->pix_fmt == PIX_FMT_YUV411P && mb_x >= (704 / 8)) {
- uint64_t aligned_pixels[64/8];
- uint8_t *pixels= (uint8_t*)aligned_pixels;
- uint8_t *c_ptr, *c_ptr1, *ptr, *ptr1;
- int x, y, linesize;
- /* NOTE: at end of line, the macroblock is handled as 420 */
- idct_put(pixels, 8, block);
- linesize = s->picture.linesize[6 - j];
- c_ptr = s->picture.data[6 - j] + c_offset;
- ptr = pixels;
- for(y = 0;y < (1<<log2_blocksize); y++) {
- ptr1= ptr + (1<<(log2_blocksize-1));
- c_ptr1 = c_ptr + (linesize<<log2_blocksize);
- for(x=0; x < (1<<(log2_blocksize-1)); x++){
- c_ptr[x]= ptr[x]; c_ptr1[x]= ptr1[x];
- }
- c_ptr += linesize;
- ptr += 8;
- }
- } else {
- /* don't ask me why they inverted Cb and Cr ! */
- idct_put(s->picture.data[6 - j] + c_offset,
- s->picture.linesize[6 - j], block);
- }
- }
- }
- block += 64;
- mb++;
- }
- }
-}
-
-#ifdef DV_CODEC_TINY_TARGET
-/* Converts run and level (where level != 0) pair into vlc, returning bit size */
-static av_always_inline int dv_rl2vlc(int run, int level, int sign, uint32_t* vlc)
-{
- int size;
- if (run < DV_VLC_MAP_RUN_SIZE && level < DV_VLC_MAP_LEV_SIZE) {
- *vlc = dv_vlc_map[run][level].vlc | sign;
- size = dv_vlc_map[run][level].size;
- }
- else {
- if (level < DV_VLC_MAP_LEV_SIZE) {
- *vlc = dv_vlc_map[0][level].vlc | sign;
- size = dv_vlc_map[0][level].size;
- } else {
- *vlc = 0xfe00 | (level << 1) | sign;
- size = 16;
- }
- if (run) {
- *vlc |= ((run < 16) ? dv_vlc_map[run-1][0].vlc :
- (0x1f80 | (run - 1))) << size;
- size += (run < 16) ? dv_vlc_map[run-1][0].size : 13;
- }
- }
-
- return size;
-}
-
-static av_always_inline int dv_rl2vlc_size(int run, int level)
-{
- int size;
-
- if (run < DV_VLC_MAP_RUN_SIZE && level < DV_VLC_MAP_LEV_SIZE) {
- size = dv_vlc_map[run][level].size;
- }
- else {
- size = (level < DV_VLC_MAP_LEV_SIZE) ? dv_vlc_map[0][level].size : 16;
- if (run) {
- size += (run < 16) ? dv_vlc_map[run-1][0].size : 13;
- }
- }
- return size;
-}
-#else
-static av_always_inline int dv_rl2vlc(int run, int l, int sign, uint32_t* vlc)
-{
- *vlc = dv_vlc_map[run][l].vlc | sign;
- return dv_vlc_map[run][l].size;
-}
-
-static av_always_inline int dv_rl2vlc_size(int run, int l)
-{
- return dv_vlc_map[run][l].size;
-}
-#endif
-
-typedef struct EncBlockInfo {
- int area_q[4];
- int bit_size[4];
- int prev[5];
- int cur_ac;
- int cno;
- int dct_mode;
- DCTELEM mb[64];
- uint8_t next[64];
- uint8_t sign[64];
- uint8_t partial_bit_count;
- uint32_t partial_bit_buffer; /* we can't use uint16_t here */
-} EncBlockInfo;
-
-static av_always_inline PutBitContext* dv_encode_ac(EncBlockInfo* bi, PutBitContext* pb_pool,
- PutBitContext* pb_end)
-{
- int prev;
- int bits_left;
- PutBitContext* pb = pb_pool;
- int size = bi->partial_bit_count;
- uint32_t vlc = bi->partial_bit_buffer;
-
- bi->partial_bit_count = bi->partial_bit_buffer = 0;
- for(;;){
- /* Find suitable storage space */
- for (; size > (bits_left = put_bits_left(pb)); pb++) {
- if (bits_left) {
- size -= bits_left;
- put_bits(pb, bits_left, vlc >> size);
- vlc = vlc & ((1<<size)-1);
- }
- if (pb + 1 >= pb_end) {
- bi->partial_bit_count = size;
- bi->partial_bit_buffer = vlc;
- return pb;
- }
- }
-
- /* Store VLC */
- put_bits(pb, size, vlc);
-
- if(bi->cur_ac>=64)
- break;
-
- /* Construct the next VLC */
- prev= bi->cur_ac;
- bi->cur_ac = bi->next[prev];
- if(bi->cur_ac < 64){
- size = dv_rl2vlc(bi->cur_ac - prev - 1, bi->mb[bi->cur_ac], bi->sign[bi->cur_ac], &vlc);
- } else {
- size = 4; vlc = 6; /* End Of Block stamp */
- }
- }
- return pb;
-}
-
-static av_always_inline void dv_set_class_number(DCTELEM* blk, EncBlockInfo* bi,
- const uint8_t* zigzag_scan, const int *weight, int bias)
-{
- int i, area;
- /* We offer two different methods for class number assignment: the
- method suggested in SMPTE 314M Table 22, and an improved
- method. The SMPTE method is very conservative; it assigns class
- 3 (i.e. severe quantization) to any block where the largest AC
- component is greater than 36. ffmpeg's DV encoder tracks AC bit
- consumption precisely, so there is no need to bias most blocks
- towards strongly lossy compression. Instead, we assign class 2
- to most blocks, and use class 3 only when strictly necessary
- (for blocks whose largest AC component exceeds 255). */
-
-#if 0 /* SMPTE spec method */
- static const int classes[] = {12, 24, 36, 0xffff};
-#else /* improved ffmpeg method */
- static const int classes[] = {-1, -1, 255, 0xffff};
-#endif
- int max=classes[0];
- int prev=0;
-
- bi->mb[0] = blk[0];
-
- for (area = 0; area < 4; area++) {
- bi->prev[area] = prev;
- bi->bit_size[area] = 1; // 4 areas 4 bits for EOB :)
- for (i=mb_area_start[area]; i<mb_area_start[area+1]; i++) {
- int level = blk[zigzag_scan[i]];
-
- if (level+15 > 30U) {
- bi->sign[i] = (level>>31)&1;
- /* weigh it and and shift down into range, adding for rounding */
- /* the extra division by a factor of 2^4 reverses the 8x expansion of the DCT
- AND the 2x doubling of the weights */
- level = (FFABS(level) * weight[i] + (1<<(dv_weight_bits+3))) >> (dv_weight_bits+4);
- bi->mb[i] = level;
- if(level>max) max= level;
- bi->bit_size[area] += dv_rl2vlc_size(i - prev - 1, level);
- bi->next[prev]= i;
- prev= i;
- }
- }
- }
- bi->next[prev]= i;
- for(bi->cno = 0; max > classes[bi->cno]; bi->cno++);
-
- bi->cno += bias;
-
- if (bi->cno >= 3) {
- bi->cno = 3;
- prev=0;
- i= bi->next[prev];
- for (area = 0; area < 4; area++) {
- bi->prev[area] = prev;
- bi->bit_size[area] = 1; // 4 areas 4 bits for EOB :)
- for (; i<mb_area_start[area+1]; i= bi->next[i]) {
- bi->mb[i] >>=1;
-
- if (bi->mb[i]) {
- bi->bit_size[area] += dv_rl2vlc_size(i - prev - 1, bi->mb[i]);
- bi->next[prev]= i;
- prev= i;
- }
- }
- }
- bi->next[prev]= i;
- }
-}
-
-//FIXME replace this by dsputil
-#define SC(x, y) ((s[x] - s[y]) ^ ((s[x] - s[y]) >> 7))
-static av_always_inline int dv_guess_dct_mode(DCTELEM *blk) {
- DCTELEM *s;
- int score88 = 0;
- int score248 = 0;
- int i;
-
- /* Compute 8-8 score (small values give a better chance for 8-8 DCT) */
- s = blk;
- for(i=0; i<7; i++) {
- score88 += SC(0, 8) + SC(1, 9) + SC(2, 10) + SC(3, 11) +
- SC(4, 12) + SC(5,13) + SC(6, 14) + SC(7, 15);
- s += 8;
- }
- /* Compute 2-4-8 score (small values give a better chance for 2-4-8 DCT) */
- s = blk;
- for(i=0; i<6; i++) {
- score248 += SC(0, 16) + SC(1,17) + SC(2, 18) + SC(3, 19) +
- SC(4, 20) + SC(5,21) + SC(6, 22) + SC(7, 23);
- s += 8;
- }
-
- return (score88 - score248 > -10);
-}
-
-static inline void dv_guess_qnos(EncBlockInfo* blks, int* qnos)
-{
- int size[5];
- int i, j, k, a, prev, a2;
- EncBlockInfo* b;
-
- size[0] = size[1] = size[2] = size[3] = size[4] = 1<<24;
- do {
- b = blks;
- for (i=0; i<5; i++) {
- if (!qnos[i])
- continue;
-
- qnos[i]--;
- size[i] = 0;
- for (j=0; j<6; j++, b++) {
- for (a=0; a<4; a++) {
- if (b->area_q[a] != dv_quant_shifts[qnos[i] + dv_quant_offset[b->cno]][a]) {
- b->bit_size[a] = 1; // 4 areas 4 bits for EOB :)
- b->area_q[a]++;
- prev= b->prev[a];
- assert(b->next[prev] >= mb_area_start[a+1] || b->mb[prev]);
- for (k= b->next[prev] ; k<mb_area_start[a+1]; k= b->next[k]) {
- b->mb[k] >>= 1;
- if (b->mb[k]) {
- b->bit_size[a] += dv_rl2vlc_size(k - prev - 1, b->mb[k]);
- prev= k;
- } else {
- if(b->next[k] >= mb_area_start[a+1] && b->next[k]<64){
- for(a2=a+1; b->next[k] >= mb_area_start[a2+1]; a2++)
- b->prev[a2] = prev;
- assert(a2<4);
- assert(b->mb[b->next[k]]);
- b->bit_size[a2] += dv_rl2vlc_size(b->next[k] - prev - 1, b->mb[b->next[k]])
- -dv_rl2vlc_size(b->next[k] - k - 1, b->mb[b->next[k]]);
- assert(b->prev[a2]==k && (a2+1 >= 4 || b->prev[a2+1]!=k));
- b->prev[a2] = prev;
- }
- b->next[prev] = b->next[k];
- }
- }
- b->prev[a+1]= prev;
- }
- size[i] += b->bit_size[a];
- }
- }
- if(vs_total_ac_bits >= size[0] + size[1] + size[2] + size[3] + size[4])
- return;
- }
- } while (qnos[0]|qnos[1]|qnos[2]|qnos[3]|qnos[4]);
-
-
- for(a=2; a==2 || vs_total_ac_bits < size[0]; a+=a){
- b = blks;
- size[0] = 5*6*4; //EOB
- for (j=0; j<6*5; j++, b++) {
- prev= b->prev[0];
- for (k= b->next[prev]; k<64; k= b->next[k]) {
- if(b->mb[k] < a && b->mb[k] > -a){
- b->next[prev] = b->next[k];
- }else{
- size[0] += dv_rl2vlc_size(k - prev - 1, b->mb[k]);
- prev= k;
- }
- }
- }
- }
-}
-
-static inline void dv_encode_video_segment(DVVideoContext *s,
- uint8_t *dif,
- const uint16_t *mb_pos_ptr)
-{
- int mb_index, i, j, v;
- int mb_x, mb_y, c_offset, linesize;
- uint8_t* y_ptr;
- uint8_t* data;
- uint8_t* ptr;
- int do_edge_wrap;
- DECLARE_ALIGNED_8(DCTELEM, block[64]);
- EncBlockInfo enc_blks[5*6];
- PutBitContext pbs[5*6];
- PutBitContext* pb;
- EncBlockInfo* enc_blk;
- int vs_bit_size = 0;
- int qnos[5];
-
- assert((((int)block) & 7) == 0);
-
- enc_blk = &enc_blks[0];
- pb = &pbs[0];
- for(mb_index = 0; mb_index < 5; mb_index++) {
- v = *mb_pos_ptr++;
- mb_x = v & 0xff;
- mb_y = v >> 8;
- if (s->sys->pix_fmt == PIX_FMT_YUV422P) {
- y_ptr = s->picture.data[0] + (mb_y * s->picture.linesize[0] * 8) + (mb_x * 4);
- } else { /* 4:1:1 */
- y_ptr = s->picture.data[0] + (mb_y * s->picture.linesize[0] * 8) + (mb_x * 8);
- }
- if (s->sys->pix_fmt == PIX_FMT_YUV420P) {
- c_offset = (((mb_y >> 1) * s->picture.linesize[1] * 8) + ((mb_x >> 1) * 8));
- } else { /* 4:2:2 or 4:1:1 */
- c_offset = ((mb_y * s->picture.linesize[1] * 8) + ((mb_x >> 2) * 8));
- }
- do_edge_wrap = 0;
- qnos[mb_index] = 15; /* No quantization */
- ptr = dif + mb_index*80 + 4;
- for(j = 0;j < 6; j++) {
- int dummy = 0;
- if (s->sys->pix_fmt == PIX_FMT_YUV422P) { /* 4:2:2 */
- if (j == 0 || j == 2) {
- /* Y0 Y1 */
- data = y_ptr + ((j>>1) * 8);
- linesize = s->picture.linesize[0];
- } else if (j > 3) {
- /* Cr Cb */
- data = s->picture.data[6 - j] + c_offset;
- linesize = s->picture.linesize[6 - j];
- } else {
- /* j=1 and j=3 are "dummy" blocks, used for AC data only */
- data = 0;
- linesize = 0;
- dummy = 1;
- }
- } else { /* 4:1:1 or 4:2:0 */
- if (j < 4) { /* Four Y blocks */
- /* NOTE: at end of line, the macroblock is handled as 420 */
- if (s->sys->pix_fmt == PIX_FMT_YUV411P && mb_x < (704 / 8)) {
- data = y_ptr + (j * 8);
- } else {
- data = y_ptr + ((j & 1) * 8) + ((j >> 1) * 8 * s->picture.linesize[0]);
- }
- linesize = s->picture.linesize[0];
- } else { /* Cr and Cb blocks */
- /* don't ask Fabrice why they inverted Cb and Cr ! */
- data = s->picture.data[6 - j] + c_offset;
- linesize = s->picture.linesize[6 - j];
- if (s->sys->pix_fmt == PIX_FMT_YUV411P && mb_x >= (704 / 8))
- do_edge_wrap = 1;
- }
- }
-
- /* Everything is set up -- now just copy data -> DCT block */
- if (do_edge_wrap) { /* Edge wrap copy: 4x16 -> 8x8 */
- uint8_t* d;
- DCTELEM *b = block;
- for (i=0;i<8;i++) {
- d = data + 8 * linesize;
- b[0] = data[0]; b[1] = data[1]; b[2] = data[2]; b[3] = data[3];
- b[4] = d[0]; b[5] = d[1]; b[6] = d[2]; b[7] = d[3];
- data += linesize;
- b += 8;
- }
- } else { /* Simple copy: 8x8 -> 8x8 */
- if (!dummy)
- s->get_pixels(block, data, linesize);
- }
-
- if(s->avctx->flags & CODEC_FLAG_INTERLACED_DCT)
- enc_blk->dct_mode = dv_guess_dct_mode(block);
- else
- enc_blk->dct_mode = 0;
- enc_blk->area_q[0] = enc_blk->area_q[1] = enc_blk->area_q[2] = enc_blk->area_q[3] = 0;
- enc_blk->partial_bit_count = 0;
- enc_blk->partial_bit_buffer = 0;
- enc_blk->cur_ac = 0;
-
- if (dummy) {
- /* 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(block, 0, sizeof(block));
- } else {
- s->fdct[enc_blk->dct_mode](block);
- }
-
- dv_set_class_number(block, enc_blk,
- enc_blk->dct_mode ? ff_zigzag248_direct : ff_zigzag_direct,
- enc_blk->dct_mode ? dv_weight_248 : dv_weight_88,
- j/4);
-
- init_put_bits(pb, ptr, block_sizes[j]/8);
- put_bits(pb, 9, (uint16_t)(((enc_blk->mb[0] >> 3) - 1024 + 2) >> 2));
- put_bits(pb, 1, enc_blk->dct_mode);
- put_bits(pb, 2, enc_blk->cno);
-
- vs_bit_size += enc_blk->bit_size[0] + enc_blk->bit_size[1] +
- enc_blk->bit_size[2] + enc_blk->bit_size[3];
- ++enc_blk;
- ++pb;
- ptr += block_sizes[j]/8;
- }
- }
-
- if (vs_total_ac_bits < vs_bit_size)
- dv_guess_qnos(&enc_blks[0], &qnos[0]);
-
- for (i=0; i<5; i++) {
- dif[i*80 + 3] = qnos[i];
- }
-
- /* First pass over individual cells only */
- for (j=0; j<5*6; j++)
- dv_encode_ac(&enc_blks[j], &pbs[j], &pbs[j+1]);
-
- /* Second pass over each MB space */
- for (j=0; j<5*6; j+=6) {
- pb= &pbs[j];
- for (i=0; i<6; i++) {
- if (enc_blks[i+j].partial_bit_count)
- pb=dv_encode_ac(&enc_blks[i+j], pb, &pbs[j+6]);
- }
- }
-
- /* Third and final pass over the whole vides segment space */
- pb= &pbs[0];
- for (j=0; j<5*6; j++) {
- if (enc_blks[j].partial_bit_count)
- pb=dv_encode_ac(&enc_blks[j], pb, &pbs[6*5]);
- if (enc_blks[j].partial_bit_count)
- av_log(NULL, AV_LOG_ERROR, "ac bitstream overflow\n");
- }
-
- for (j=0; j<5*6; j++)
- flush_put_bits(&pbs[j]);
-}
-
-static int dv_decode_mt(AVCodecContext *avctx, void* sl)
-{
- DVVideoContext *s = avctx->priv_data;
- int slice = (size_t)sl;
-
- /* which DIF channel is this? */
- int chan = slice / (s->sys->difseg_size * 27);
-
- /* slice within the DIF channel */
- int chan_slice = slice % (s->sys->difseg_size * 27);
-
- /* byte offset of this channel's data */
- int chan_offset = chan * s->sys->difseg_size * 150 * 80;
-
- dv_decode_video_segment(s, &s->buf[((chan_slice/27)*6+(chan_slice/3)+chan_slice*5+7)*80 + chan_offset],
- &s->sys->video_place[slice*5]);
- return 0;
-}
-
-#ifdef CONFIG_ENCODERS
-static int dv_encode_mt(AVCodecContext *avctx, void* sl)
-{
- DVVideoContext *s = avctx->priv_data;
- int slice = (size_t)sl;
-
- /* which DIF channel is this? */
- int chan = slice / (s->sys->difseg_size * 27);
-
- /* slice within the DIF channel */
- int chan_slice = slice % (s->sys->difseg_size * 27);
-
- /* byte offset of this channel's data */
- int chan_offset = chan * s->sys->difseg_size * 150 * 80;
-
- dv_encode_video_segment(s, &s->buf[((chan_slice/27)*6+(chan_slice/3)+chan_slice*5+7)*80 + chan_offset],
- &s->sys->video_place[slice*5]);
- return 0;
-}
-#endif
-
-#ifdef CONFIG_DECODERS
-/* NOTE: exactly one frame must be given (120000 bytes for NTSC,
- 144000 bytes for PAL - or twice those for 50Mbps) */
-static int dvvideo_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- DVVideoContext *s = avctx->priv_data;
-
- s->sys = dv_frame_profile(buf);
- if (!s->sys || buf_size < s->sys->frame_size)
- return -1; /* NOTE: we only accept several full frames */
-
- if(s->picture.data[0])
- avctx->release_buffer(avctx, &s->picture);
-
- s->picture.reference = 0;
- s->picture.key_frame = 1;
- s->picture.pict_type = FF_I_TYPE;
- avctx->pix_fmt = s->sys->pix_fmt;
- avcodec_set_dimensions(avctx, s->sys->width, s->sys->height);
- if(avctx->get_buffer(avctx, &s->picture) < 0) {
- av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
- return -1;
- }
- s->picture.interlaced_frame = 1;
- s->picture.top_field_first = 0;
-
- s->buf = buf;
- avctx->execute(avctx, dv_decode_mt, (void**)&dv_anchor[0], NULL,
- s->sys->n_difchan * s->sys->difseg_size * 27);
-
- emms_c();
-
- /* return image */
- *data_size = sizeof(AVFrame);
- *(AVFrame*)data= s->picture;
-
- return s->sys->frame_size;
-}
-#endif
-
-
-static inline int dv_write_pack(enum dv_pack_type pack_id, DVVideoContext *c, uint8_t* buf)
-{
- /*
- * Here's what SMPTE314M says about these two:
- * (page 6) APTn, AP1n, AP2n, AP3n: These data shall be identical
- * as track application IDs (APTn = 001, AP1n =
- * 001, AP2n = 001, AP3n = 001), if the source signal
- * comes from a digital VCR. If the signal source is
- * unknown, all bits for these data shall be set to 1.
- * (page 12) STYPE: STYPE defines a signal type of video signal
- * 00000b = 4:1:1 compression
- * 00100b = 4:2:2 compression
- * XXXXXX = Reserved
- * Now, I've got two problems with these statements:
- * 1. it looks like APT == 111b should be a safe bet, but it isn't.
- * It seems that for PAL as defined in IEC 61834 we have to set
- * APT to 000 and for SMPTE314M to 001.
- * 2. It is not at all clear what STYPE is used for 4:2:0 PAL
- * compression scheme (if any).
- */
- int apt = (c->sys->pix_fmt == PIX_FMT_YUV420P ? 0 : 1);
- int stype = (c->sys->pix_fmt == PIX_FMT_YUV422P ? 4 : 0);
-
- uint8_t aspect = 0;
- if((int)(av_q2d(c->avctx->sample_aspect_ratio) * c->avctx->width / c->avctx->height * 10) == 17) /* 16:9 */
- aspect = 0x02;
-
- buf[0] = (uint8_t)pack_id;
- switch (pack_id) {
- case dv_header525: /* I can't imagine why these two weren't defined as real */
- case dv_header625: /* packs in SMPTE314M -- they definitely look like ones */
- buf[1] = 0xf8 | /* reserved -- always 1 */
- (apt & 0x07); /* APT: Track application ID */
- buf[2] = (0 << 7) | /* TF1: audio data is 0 - valid; 1 - invalid */
- (0x0f << 3) | /* reserved -- always 1 */
- (apt & 0x07); /* AP1: Audio application ID */
- buf[3] = (0 << 7) | /* TF2: video data is 0 - valid; 1 - invalid */
- (0x0f << 3) | /* reserved -- always 1 */
- (apt & 0x07); /* AP2: Video application ID */
- buf[4] = (0 << 7) | /* TF3: subcode(SSYB) is 0 - valid; 1 - invalid */
- (0x0f << 3) | /* reserved -- always 1 */
- (apt & 0x07); /* AP3: Subcode application ID */
- break;
- case dv_video_source:
- buf[1] = 0xff; /* reserved -- always 1 */
- buf[2] = (1 << 7) | /* B/W: 0 - b/w, 1 - color */
- (1 << 6) | /* following CLF is valid - 0, invalid - 1 */
- (3 << 4) | /* CLF: color frames id (see ITU-R BT.470-4) */
- 0xf; /* reserved -- always 1 */
- buf[3] = (3 << 6) | /* reserved -- always 1 */
- (c->sys->dsf << 5) | /* system: 60fields/50fields */
- stype; /* signal type video compression */
- buf[4] = 0xff; /* VISC: 0xff -- no information */
- break;
- case dv_video_control:
- buf[1] = (0 << 6) | /* Copy generation management (CGMS) 0 -- free */
- 0x3f; /* reserved -- always 1 */
- buf[2] = 0xc8 | /* reserved -- always b11001xxx */
- aspect;
- buf[3] = (1 << 7) | /* Frame/field flag 1 -- frame, 0 -- field */
- (1 << 6) | /* First/second field flag 0 -- field 2, 1 -- field 1 */
- (1 << 5) | /* Frame change flag 0 -- same picture as before, 1 -- different */
- (1 << 4) | /* 1 - interlaced, 0 - noninterlaced */
- 0xc; /* reserved -- always b1100 */
- buf[4] = 0xff; /* reserved -- always 1 */
- break;
- default:
- buf[1] = buf[2] = buf[3] = buf[4] = 0xff;
- }
- return 5;
-}
-
-static void dv_format_frame(DVVideoContext* c, uint8_t* buf)
-{
- int chan, i, j, k;
-
- for (chan = 0; chan < c->sys->n_difchan; chan++) {
- for (i = 0; i < c->sys->difseg_size; i++) {
- memset(buf, 0xff, 80 * 6); /* First 6 DIF blocks are for control data */
-
- /* DV header: 1DIF */
- buf += dv_write_dif_id(dv_sect_header, chan, i, 0, buf);
- buf += dv_write_pack((c->sys->dsf ? dv_header625 : dv_header525), c, buf);
- buf += 72; /* unused bytes */
-
- /* DV subcode: 2DIFs */
- for (j = 0; j < 2; j++) {
- buf += dv_write_dif_id(dv_sect_subcode, chan, i, j, buf);
- for (k = 0; k < 6; k++)
- buf += dv_write_ssyb_id(k, (i < c->sys->difseg_size/2), buf) + 5;
- buf += 29; /* unused bytes */
- }
-
- /* DV VAUX: 3DIFS */
- for (j = 0; j < 3; j++) {
- buf += dv_write_dif_id(dv_sect_vaux, chan, i, j, buf);
- buf += dv_write_pack(dv_video_source, c, buf);
- buf += dv_write_pack(dv_video_control, c, buf);
- buf += 7*5;
- buf += dv_write_pack(dv_video_source, c, buf);
- buf += dv_write_pack(dv_video_control, c, buf);
- buf += 4*5 + 2; /* unused bytes */
- }
-
- /* DV Audio/Video: 135 Video DIFs + 9 Audio DIFs */
- for (j = 0; j < 135; j++) {
- if (j%15 == 0) {
- memset(buf, 0xff, 80);
- buf += dv_write_dif_id(dv_sect_audio, chan, i, j/15, buf);
- buf += 77; /* audio control & shuffled PCM audio */
- }
- buf += dv_write_dif_id(dv_sect_video, chan, i, j, buf);
- buf += 77; /* 1 video macro block: 1 bytes control
- 4 * 14 bytes Y 8x8 data
- 10 bytes Cr 8x8 data
- 10 bytes Cb 8x8 data */
- }
- }
- }
-}
-
-
-#ifdef CONFIG_ENCODERS
-static int dvvideo_encode_frame(AVCodecContext *c, uint8_t *buf, int buf_size,
- void *data)
-{
- DVVideoContext *s = c->priv_data;
-
- s->sys = dv_codec_profile(c);
- if (!s->sys)
- return -1;
- if(buf_size < s->sys->frame_size)
- return -1;
-
- c->pix_fmt = s->sys->pix_fmt;
- s->picture = *((AVFrame *)data);
- s->picture.key_frame = 1;
- s->picture.pict_type = FF_I_TYPE;
-
- s->buf = buf;
- c->execute(c, dv_encode_mt, (void**)&dv_anchor[0], NULL,
- s->sys->n_difchan * s->sys->difseg_size * 27);
-
- emms_c();
-
- dv_format_frame(s, buf);
-
- return s->sys->frame_size;
-}
-#endif
-
-static int dvvideo_close(AVCodecContext *c)
-{
- DVVideoContext *s = c->priv_data;
-
- if(s->picture.data[0])
- c->release_buffer(c, &s->picture);
-
- return 0;
-}
-
-
-#ifdef CONFIG_DVVIDEO_ENCODER
-AVCodec dvvideo_encoder = {
- "dvvideo",
- CODEC_TYPE_VIDEO,
- CODEC_ID_DVVIDEO,
- sizeof(DVVideoContext),
- dvvideo_init,
- dvvideo_encode_frame,
- .pix_fmts = (enum PixelFormat[]) {PIX_FMT_YUV411P, PIX_FMT_YUV422P, PIX_FMT_YUV420P, -1},
-};
-#endif // CONFIG_DVVIDEO_ENCODER
-
-#ifdef CONFIG_DVVIDEO_DECODER
-AVCodec dvvideo_decoder = {
- "dvvideo",
- CODEC_TYPE_VIDEO,
- CODEC_ID_DVVIDEO,
- sizeof(DVVideoContext),
- dvvideo_init,
- NULL,
- dvvideo_close,
- dvvideo_decode_frame,
- CODEC_CAP_DR1,
- NULL
-};
-#endif
diff --git a/src/libffmpeg/libavcodec/error_resilience.c b/src/libffmpeg/libavcodec/error_resilience.c
deleted file mode 100644
index 0923721ee..000000000
--- a/src/libffmpeg/libavcodec/error_resilience.c
+++ /dev/null
@@ -1,1030 +0,0 @@
-/*
- * Error resilience / concealment
- *
- * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/**
- * @file error_resilience.c
- * Error resilience / concealment.
- */
-
-#include <limits.h>
-
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-#include "common.h"
-
-static void decode_mb(MpegEncContext *s){
- 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;
-
- MPV_decode_mb(s, s->block);
-}
-
-/**
- * replaces the current MB with a flat dc only version.
- */
-static void put_dc(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int mb_x, int mb_y)
-{
- int dc, dcu, dcv, y, i;
- for(i=0; i<4; i++){
- dc= s->dc_val[0][mb_x*2 + (i&1) + (mb_y*2 + (i>>1))*s->b8_stride];
- if(dc<0) dc=0;
- else if(dc>2040) dc=2040;
- for(y=0; y<8; y++){
- int x;
- for(x=0; x<8; x++){
- dest_y[x + (i&1)*8 + (y + (i>>1)*8)*s->linesize]= dc/8;
- }
- }
- }
- dcu = s->dc_val[1][mb_x + mb_y*s->mb_stride];
- dcv = s->dc_val[2][mb_x + mb_y*s->mb_stride];
- if (dcu<0 ) dcu=0;
- else if(dcu>2040) dcu=2040;
- if (dcv<0 ) dcv=0;
- else if(dcv>2040) dcv=2040;
- for(y=0; y<8; y++){
- int x;
- for(x=0; x<8; x++){
- dest_cb[x + y*(s->uvlinesize)]= dcu/8;
- dest_cr[x + y*(s->uvlinesize)]= dcv/8;
- }
- }
-}
-
-static void filter181(int16_t *data, int width, int height, int stride){
- int x,y;
-
- /* horizontal filter */
- for(y=1; y<height-1; y++){
- int prev_dc= data[0 + y*stride];
-
- for(x=1; x<width-1; x++){
- int dc;
-
- dc= - prev_dc
- + data[x + y*stride]*8
- - data[x + 1 + y*stride];
- dc= (dc*10923 + 32768)>>16;
- prev_dc= data[x + y*stride];
- data[x + y*stride]= dc;
- }
- }
-
- /* vertical filter */
- for(x=1; x<width-1; x++){
- int prev_dc= data[x];
-
- for(y=1; y<height-1; y++){
- int dc;
-
- dc= - prev_dc
- + data[x + y *stride]*8
- - data[x + (y+1)*stride];
- dc= (dc*10923 + 32768)>>16;
- prev_dc= data[x + y*stride];
- data[x + y*stride]= dc;
- }
- }
-}
-
-/**
- * guess the dc of blocks which dont have a undamaged dc
- * @param w width in 8 pixel blocks
- * @param h height in 8 pixel blocks
- */
-static void guess_dc(MpegEncContext *s, int16_t *dc, int w, int h, int stride, int is_luma){
- int b_x, b_y;
-
- for(b_y=0; b_y<h; b_y++){
- for(b_x=0; b_x<w; b_x++){
- int color[4]={1024,1024,1024,1024};
- int distance[4]={9999,9999,9999,9999};
- int mb_index, error, j;
- int64_t guess, weight_sum;
-
- mb_index= (b_x>>is_luma) + (b_y>>is_luma)*s->mb_stride;
-
- error= s->error_status_table[mb_index];
-
- if(IS_INTER(s->current_picture.mb_type[mb_index])) continue; //inter
- if(!(error&DC_ERROR)) continue; //dc-ok
-
- /* right block */
- for(j=b_x+1; j<w; j++){
- int mb_index_j= (j>>is_luma) + (b_y>>is_luma)*s->mb_stride;
- int error_j= s->error_status_table[mb_index_j];
- int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
- if(intra_j==0 || !(error_j&DC_ERROR)){
- color[0]= dc[j + b_y*stride];
- distance[0]= j-b_x;
- break;
- }
- }
-
- /* left block */
- for(j=b_x-1; j>=0; j--){
- int mb_index_j= (j>>is_luma) + (b_y>>is_luma)*s->mb_stride;
- int error_j= s->error_status_table[mb_index_j];
- int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
- if(intra_j==0 || !(error_j&DC_ERROR)){
- color[1]= dc[j + b_y*stride];
- distance[1]= b_x-j;
- break;
- }
- }
-
- /* bottom block */
- for(j=b_y+1; j<h; j++){
- int mb_index_j= (b_x>>is_luma) + (j>>is_luma)*s->mb_stride;
- int error_j= s->error_status_table[mb_index_j];
- int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
- if(intra_j==0 || !(error_j&DC_ERROR)){
- color[2]= dc[b_x + j*stride];
- distance[2]= j-b_y;
- break;
- }
- }
-
- /* top block */
- for(j=b_y-1; j>=0; j--){
- int mb_index_j= (b_x>>is_luma) + (j>>is_luma)*s->mb_stride;
- int error_j= s->error_status_table[mb_index_j];
- int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
- if(intra_j==0 || !(error_j&DC_ERROR)){
- color[3]= dc[b_x + j*stride];
- distance[3]= b_y-j;
- break;
- }
- }
-
- weight_sum=0;
- guess=0;
- for(j=0; j<4; j++){
- int64_t weight= 256*256*256*16/distance[j];
- guess+= weight*(int64_t)color[j];
- weight_sum+= weight;
- }
- guess= (guess + weight_sum/2) / weight_sum;
-
- dc[b_x + b_y*stride]= guess;
- }
- }
-}
-
-/**
- * simple horizontal deblocking filter used for error resilience
- * @param w width in 8 pixel blocks
- * @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;
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
-
- for(b_y=0; b_y<h; b_y++){
- for(b_x=0; b_x<w-1; b_x++){
- int y;
- int left_status = s->error_status_table[( b_x >>is_luma) + (b_y>>is_luma)*s->mb_stride];
- int right_status= s->error_status_table[((b_x+1)>>is_luma) + (b_y>>is_luma)*s->mb_stride];
- int left_intra= IS_INTRA(s->current_picture.mb_type [( b_x >>is_luma) + (b_y>>is_luma)*s->mb_stride]);
- int right_intra= IS_INTRA(s->current_picture.mb_type [((b_x+1)>>is_luma) + (b_y>>is_luma)*s->mb_stride]);
- int left_damage = left_status&(DC_ERROR|AC_ERROR|MV_ERROR);
- int right_damage= right_status&(DC_ERROR|AC_ERROR|MV_ERROR);
- int offset= b_x*8 + b_y*stride*8;
- int16_t *left_mv= s->current_picture.motion_val[0][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))];
-
- if(!(left_damage||right_damage)) continue; // both undamaged
-
- if( (!left_intra) && (!right_intra)
- && FFABS(left_mv[0]-right_mv[0]) + FFABS(left_mv[1]+right_mv[1]) < 2) continue;
-
- for(y=0; y<8; y++){
- int a,b,c,d;
-
- a= dst[offset + 7 + y*stride] - dst[offset + 6 + y*stride];
- b= dst[offset + 8 + y*stride] - dst[offset + 7 + y*stride];
- c= dst[offset + 9 + y*stride] - dst[offset + 8 + y*stride];
-
- d= FFABS(b) - ((FFABS(a) + FFABS(c) + 1)>>1);
- d= FFMAX(d, 0);
- if(b<0) d= -d;
-
- if(d==0) continue;
-
- if(!(left_damage && right_damage))
- d= d*16/9;
-
- if(left_damage){
- dst[offset + 7 + y*stride] = cm[dst[offset + 7 + y*stride] + ((d*7)>>4)];
- dst[offset + 6 + y*stride] = cm[dst[offset + 6 + y*stride] + ((d*5)>>4)];
- dst[offset + 5 + y*stride] = cm[dst[offset + 5 + y*stride] + ((d*3)>>4)];
- dst[offset + 4 + y*stride] = cm[dst[offset + 4 + y*stride] + ((d*1)>>4)];
- }
- if(right_damage){
- dst[offset + 8 + y*stride] = cm[dst[offset + 8 + y*stride] - ((d*7)>>4)];
- dst[offset + 9 + y*stride] = cm[dst[offset + 9 + y*stride] - ((d*5)>>4)];
- dst[offset + 10+ y*stride] = cm[dst[offset +10 + y*stride] - ((d*3)>>4)];
- dst[offset + 11+ y*stride] = cm[dst[offset +11 + y*stride] - ((d*1)>>4)];
- }
- }
- }
- }
-}
-
-/**
- * simple vertical deblocking filter used for error resilience
- * @param w width in 8 pixel blocks
- * @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;
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
-
- for(b_y=0; b_y<h-1; b_y++){
- for(b_x=0; b_x<w; b_x++){
- int x;
- int top_status = s->error_status_table[(b_x>>is_luma) + ( b_y >>is_luma)*s->mb_stride];
- int bottom_status= s->error_status_table[(b_x>>is_luma) + ((b_y+1)>>is_luma)*s->mb_stride];
- int top_intra= IS_INTRA(s->current_picture.mb_type [(b_x>>is_luma) + ( b_y >>is_luma)*s->mb_stride]);
- int bottom_intra= IS_INTRA(s->current_picture.mb_type [(b_x>>is_luma) + ((b_y+1)>>is_luma)*s->mb_stride]);
- int top_damage = top_status&(DC_ERROR|AC_ERROR|MV_ERROR);
- int bottom_damage= bottom_status&(DC_ERROR|AC_ERROR|MV_ERROR);
- int offset= b_x*8 + b_y*stride*8;
- int16_t *top_mv= s->current_picture.motion_val[0][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))];
-
- if(!(top_damage||bottom_damage)) continue; // both undamaged
-
- if( (!top_intra) && (!bottom_intra)
- && FFABS(top_mv[0]-bottom_mv[0]) + FFABS(top_mv[1]+bottom_mv[1]) < 2) continue;
-
- for(x=0; x<8; x++){
- int a,b,c,d;
-
- a= dst[offset + x + 7*stride] - dst[offset + x + 6*stride];
- b= dst[offset + x + 8*stride] - dst[offset + x + 7*stride];
- c= dst[offset + x + 9*stride] - dst[offset + x + 8*stride];
-
- d= FFABS(b) - ((FFABS(a) + FFABS(c)+1)>>1);
- d= FFMAX(d, 0);
- if(b<0) d= -d;
-
- if(d==0) continue;
-
- if(!(top_damage && bottom_damage))
- d= d*16/9;
-
- if(top_damage){
- dst[offset + x + 7*stride] = cm[dst[offset + x + 7*stride] + ((d*7)>>4)];
- dst[offset + x + 6*stride] = cm[dst[offset + x + 6*stride] + ((d*5)>>4)];
- dst[offset + x + 5*stride] = cm[dst[offset + x + 5*stride] + ((d*3)>>4)];
- dst[offset + x + 4*stride] = cm[dst[offset + x + 4*stride] + ((d*1)>>4)];
- }
- if(bottom_damage){
- dst[offset + x + 8*stride] = cm[dst[offset + x + 8*stride] - ((d*7)>>4)];
- dst[offset + x + 9*stride] = cm[dst[offset + x + 9*stride] - ((d*5)>>4)];
- dst[offset + x + 10*stride] = cm[dst[offset + x + 10*stride] - ((d*3)>>4)];
- dst[offset + x + 11*stride] = cm[dst[offset + x + 11*stride] - ((d*1)>>4)];
- }
- }
- }
- }
-}
-
-static void guess_mv(MpegEncContext *s){
- uint8_t fixed[s->mb_stride * s->mb_height];
-#define MV_FROZEN 3
-#define MV_CHANGED 2
-#define MV_UNCHANGED 1
- const int mb_stride = s->mb_stride;
- const int mb_width = s->mb_width;
- const int mb_height= s->mb_height;
- int i, depth, num_avail;
- int mb_x, mb_y;
-
- num_avail=0;
- for(i=0; i<s->mb_num; i++){
- const int mb_xy= s->mb_index2xy[ i ];
- int f=0;
- int error= s->error_status_table[mb_xy];
-
- if(IS_INTRA(s->current_picture.mb_type[mb_xy])) f=MV_FROZEN; //intra //FIXME check
- if(!(error&MV_ERROR)) f=MV_FROZEN; //inter with undamaged MV
-
- fixed[mb_xy]= f;
- if(f==MV_FROZEN)
- num_avail++;
- }
-
- if((!(s->avctx->error_concealment&FF_EC_GUESS_MVS)) || num_avail <= mb_width/2){
- for(mb_y=0; mb_y<s->mb_height; mb_y++){
- for(mb_x=0; mb_x<s->mb_width; mb_x++){
- const int mb_xy= mb_x + mb_y*s->mb_stride;
-
- if(IS_INTRA(s->current_picture.mb_type[mb_xy])) continue;
- if(!(s->error_status_table[mb_xy]&MV_ERROR)) continue;
-
- s->mv_dir = MV_DIR_FORWARD;
- s->mb_intra=0;
- s->mv_type = MV_TYPE_16X16;
- s->mb_skipped=0;
-
- s->dsp.clear_blocks(s->block[0]);
-
- s->mb_x= mb_x;
- s->mb_y= mb_y;
- s->mv[0][0][0]= 0;
- s->mv[0][0][1]= 0;
- decode_mb(s);
- }
- }
- return;
- }
-
- for(depth=0;; depth++){
- int changed, pass, none_left;
-
- none_left=1;
- changed=1;
- for(pass=0; (changed || pass<2) && pass<10; pass++){
- int mb_x, mb_y;
-int score_sum=0;
-
- changed=0;
- for(mb_y=0; mb_y<s->mb_height; mb_y++){
- for(mb_x=0; mb_x<s->mb_width; mb_x++){
- const int mb_xy= mb_x + mb_y*s->mb_stride;
- int mv_predictor[8][2]={{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;
- int prev_x= s->current_picture.motion_val[0][mot_index][0];
- int prev_y= s->current_picture.motion_val[0][mot_index][1];
-
- if((mb_x^mb_y^pass)&1) continue;
-
- if(fixed[mb_xy]==MV_FROZEN) continue;
- assert(!IS_INTRA(s->current_picture.mb_type[mb_xy]));
- assert(s->last_picture_ptr && s->last_picture_ptr->data[0]);
-
- j=0;
- if(mb_x>0 && fixed[mb_xy-1 ]==MV_FROZEN) j=1;
- if(mb_x+1<mb_width && fixed[mb_xy+1 ]==MV_FROZEN) j=1;
- if(mb_y>0 && fixed[mb_xy-mb_stride]==MV_FROZEN) j=1;
- if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]==MV_FROZEN) j=1;
- if(j==0) continue;
-
- j=0;
- if(mb_x>0 && fixed[mb_xy-1 ]==MV_CHANGED) j=1;
- if(mb_x+1<mb_width && fixed[mb_xy+1 ]==MV_CHANGED) j=1;
- if(mb_y>0 && fixed[mb_xy-mb_stride]==MV_CHANGED) j=1;
- if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]==MV_CHANGED) j=1;
- if(j==0 && pass>1) continue;
-
- 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];
- pred_count++;
- }
- if(mb_x+1<mb_width && fixed[mb_xy+1]){
- mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index + 2][0];
- mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + 2][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];
- pred_count++;
- }
- if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]){
- mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index + mot_stride*2][0];
- mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + mot_stride*2][1];
- 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;
-
- for(j=0; j<pred_count; j++){
- sum_x+= mv_predictor[j][0];
- sum_y+= mv_predictor[j][1];
- }
-
- /* mean */
- mv_predictor[pred_count][0] = sum_x/j;
- mv_predictor[pred_count][1] = sum_y/j;
-
- /* median */
- if(pred_count>=3){
- min_y= min_x= 99999;
- max_y= max_x=-99999;
- }else{
- min_x=min_y=max_x=max_y=0;
- }
- for(j=0; j<pred_count; j++){
- max_x= FFMAX(max_x, mv_predictor[j][0]);
- max_y= FFMAX(max_y, mv_predictor[j][1]);
- min_x= FFMIN(min_x, mv_predictor[j][0]);
- min_y= FFMIN(min_y, mv_predictor[j][1]);
- }
- mv_predictor[pred_count+1][0] = sum_x - max_x - min_x;
- mv_predictor[pred_count+1][1] = sum_y - max_y - min_y;
-
- if(pred_count==4){
- mv_predictor[pred_count+1][0] /= 2;
- mv_predictor[pred_count+1][1] /= 2;
- }
- pred_count+=2;
- }
-
- /* zero MV */
- pred_count++;
-
- /* last MV */
- mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index][0];
- mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index][1];
- pred_count++;
-
- s->mv_dir = MV_DIR_FORWARD;
- s->mb_intra=0;
- s->mv_type = MV_TYPE_16X16;
- s->mb_skipped=0;
-
- s->dsp.clear_blocks(s->block[0]);
-
- s->mb_x= mb_x;
- s->mb_y= mb_y;
-
- for(j=0; j<pred_count; j++){
- int score=0;
- uint8_t *src= s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
-
- 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(mb_x>0 && fixed[mb_xy-1]){
- int k;
- for(k=0; k<16; k++)
- score += FFABS(src[k*s->linesize-1 ]-src[k*s->linesize ]);
- }
- if(mb_x+1<mb_width && fixed[mb_xy+1]){
- int k;
- for(k=0; k<16; k++)
- score += FFABS(src[k*s->linesize+15]-src[k*s->linesize+16]);
- }
- if(mb_y>0 && fixed[mb_xy-mb_stride]){
- int k;
- for(k=0; k<16; k++)
- score += FFABS(src[k-s->linesize ]-src[k ]);
- }
- if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]){
- int k;
- for(k=0; k<16; k++)
- score += FFABS(src[k+s->linesize*15]-src[k+s->linesize*16]);
- }
-
- if(score <= best_score){ // <= will favor the last MV
- best_score= score;
- best_pred= j;
- }
- }
-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];
-
- decode_mb(s);
-
-
- if(s->mv[0][0][0] != prev_x || s->mv[0][0][1] != prev_y){
- fixed[mb_xy]=MV_CHANGED;
- changed++;
- }else
- fixed[mb_xy]=MV_UNCHANGED;
- }
- }
-
-// printf(".%d/%d", changed, score_sum); fflush(stdout);
- }
-
- if(none_left)
- return;
-
- for(i=0; i<s->mb_num; i++){
- int mb_xy= s->mb_index2xy[i];
- if(fixed[mb_xy])
- fixed[mb_xy]=MV_FROZEN;
- }
-// printf(":"); fflush(stdout);
- }
-}
-
-static int is_intra_more_likely(MpegEncContext *s){
- int is_intra_likely, i, j, undamaged_count, skip_amount, mb_x, mb_y;
-
- if(s->last_picture_ptr==NULL) return 1; //no previous frame available -> use spatial prediction
-
- undamaged_count=0;
- for(i=0; i<s->mb_num; i++){
- const int mb_xy= s->mb_index2xy[i];
- const int error= s->error_status_table[mb_xy];
- if(!((error&DC_ERROR) && (error&MV_ERROR)))
- undamaged_count++;
- }
-
- if(undamaged_count < 5) return 0; //allmost all MBs damaged -> use temporal prediction
-
- skip_amount= FFMAX(undamaged_count/50, 1); //check only upto 50 MBs
- is_intra_likely=0;
-
- j=0;
- for(mb_y= 0; mb_y<s->mb_height-1; mb_y++){
- for(mb_x= 0; mb_x<s->mb_width; mb_x++){
- int error;
- const int mb_xy= mb_x + mb_y*s->mb_stride;
-
- error= s->error_status_table[mb_xy];
- if((error&DC_ERROR) && (error&MV_ERROR))
- continue; //skip damaged
-
- j++;
- if((j%skip_amount) != 0) continue; //skip a few to speed things up
-
- if(s->pict_type==I_TYPE){
- uint8_t *mb_ptr = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
- uint8_t *last_mb_ptr= s->last_picture.data [0] + mb_x*16 + mb_y*16*s->linesize;
-
- is_intra_likely += s->dsp.sad[0](NULL, last_mb_ptr, mb_ptr , s->linesize, 16);
- is_intra_likely -= s->dsp.sad[0](NULL, last_mb_ptr, last_mb_ptr+s->linesize*16, s->linesize, 16);
- }else{
- if(IS_INTRA(s->current_picture.mb_type[mb_xy]))
- is_intra_likely++;
- else
- is_intra_likely--;
- }
- }
- }
-//printf("is_intra_likely: %d type:%d\n", is_intra_likely, s->pict_type);
- return is_intra_likely > 0;
-}
-
-void ff_er_frame_start(MpegEncContext *s){
- if(!s->error_resilience) return;
-
- memset(s->error_status_table, MV_ERROR|AC_ERROR|DC_ERROR|VP_START|AC_END|DC_END|MV_END, s->mb_stride*s->mb_height*sizeof(uint8_t));
- s->error_count= 3*s->mb_num;
-}
-
-/**
- * adds a slice.
- * @param endx x component of the last macroblock, can be -1 for the last of the previous line
- * @param status the status at the end (MV_END, AC_ERROR, ...), it is assumed that no earlier end or
- * error of the same type occured
- */
-void ff_er_add_slice(MpegEncContext *s, int startx, int starty, int endx, int endy, int status){
- const int start_i= clip(startx + starty * s->mb_width , 0, s->mb_num-1);
- const int end_i = clip(endx + endy * s->mb_width , 0, s->mb_num);
- const int start_xy= s->mb_index2xy[start_i];
- const int end_xy = s->mb_index2xy[end_i];
- int mask= -1;
-
- if(!s->error_resilience) return;
-
- mask &= ~VP_START;
- if(status & (AC_ERROR|AC_END)){
- mask &= ~(AC_ERROR|AC_END);
- s->error_count -= end_i - start_i + 1;
- }
- if(status & (DC_ERROR|DC_END)){
- mask &= ~(DC_ERROR|DC_END);
- s->error_count -= end_i - start_i + 1;
- }
- if(status & (MV_ERROR|MV_END)){
- mask &= ~(MV_ERROR|MV_END);
- s->error_count -= end_i - start_i + 1;
- }
-
- if(status & (AC_ERROR|DC_ERROR|MV_ERROR)) s->error_count= INT_MAX;
-
- if(mask == ~0x7F){
- memset(&s->error_status_table[start_xy], 0, (end_xy - start_xy) * sizeof(uint8_t));
- }else{
- int i;
- for(i=start_xy; i<end_xy; i++){
- s->error_status_table[ i ] &= mask;
- }
- }
-
- if(end_i == s->mb_num)
- s->error_count= INT_MAX;
- else{
- s->error_status_table[end_xy] &= mask;
- s->error_status_table[end_xy] |= status;
- }
-
- s->error_status_table[start_xy] |= VP_START;
-
- if(start_xy > 0 && s->avctx->thread_count <= 1 && s->avctx->skip_top*s->mb_width < start_i){
- int prev_status= s->error_status_table[ s->mb_index2xy[start_i - 1] ];
-
- prev_status &= ~ VP_START;
- if(prev_status != (MV_END|DC_END|AC_END)) s->error_count= INT_MAX;
- }
-}
-
-void ff_er_frame_end(MpegEncContext *s){
- int i, mb_x, mb_y, error, error_type, dc_error, mv_error, ac_error;
- int distance;
- int threshold_part[4]= {100,100,100};
- int threshold= 50;
- int is_intra_likely;
- int size = s->b8_stride * 2 * s->mb_height;
- Picture *pic= s->current_picture_ptr;
-
- if(!s->error_resilience || s->error_count==0 ||
- 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->motion_val_base[i]= av_mallocz((size+4) * 2 * sizeof(uint16_t));
- pic->motion_val[i]= pic->motion_val_base[i]+4;
- }
- pic->motion_subsample_log2= 3;
- 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_y<s->mb_height; mb_y++){
- for(mb_x=0; mb_x<s->mb_width; mb_x++){
- int status= s->error_status_table[mb_x + mb_y*s->mb_stride];
-
- av_log(s->avctx, AV_LOG_DEBUG, "%2X ", status);
- }
- av_log(s->avctx, AV_LOG_DEBUG, "\n");
- }
- }
-
-#if 1
- /* handle overlapping slices */
- for(error_type=1; error_type<=3; error_type++){
- int end_ok=0;
-
- for(i=s->mb_num-1; i>=0; i--){
- const int mb_xy= s->mb_index2xy[i];
- int error= s->error_status_table[mb_xy];
-
- if(error&(1<<error_type))
- end_ok=1;
- if(error&(8<<error_type))
- end_ok=1;
-
- if(!end_ok)
- s->error_status_table[mb_xy]|= 1<<error_type;
-
- if(error&VP_START)
- end_ok=0;
- }
- }
-#endif
-#if 1
- /* handle slices with partitions of different length */
- if(s->partitioned_frame){
- int end_ok=0;
-
- for(i=s->mb_num-1; i>=0; i--){
- const int mb_xy= s->mb_index2xy[i];
- int error= s->error_status_table[mb_xy];
-
- if(error&AC_END)
- end_ok=0;
- if((error&MV_END) || (error&DC_END) || (error&AC_ERROR))
- end_ok=1;
-
- if(!end_ok)
- s->error_status_table[mb_xy]|= AC_ERROR;
-
- if(error&VP_START)
- end_ok=0;
- }
- }
-#endif
- /* handle missing slices */
- if(s->error_resilience>=4){
- int end_ok=1;
-
- for(i=s->mb_num-2; i>=s->mb_width+100; i--){ //FIXME +100 hack
- const int mb_xy= s->mb_index2xy[i];
- int error1= s->error_status_table[mb_xy ];
- int error2= s->error_status_table[s->mb_index2xy[i+1]];
-
- if(error1&VP_START)
- end_ok=1;
-
- if( error2==(VP_START|DC_ERROR|AC_ERROR|MV_ERROR|AC_END|DC_END|MV_END)
- && error1!=(VP_START|DC_ERROR|AC_ERROR|MV_ERROR|AC_END|DC_END|MV_END)
- && ((error1&AC_END) || (error1&DC_END) || (error1&MV_END))){ //end & uninited
- end_ok=0;
- }
-
- if(!end_ok)
- s->error_status_table[mb_xy]|= DC_ERROR|AC_ERROR|MV_ERROR;
- }
- }
-
-#if 1
- /* backward mark errors */
- distance=9999999;
- for(error_type=1; error_type<=3; error_type++){
- for(i=s->mb_num-1; i>=0; i--){
- const int mb_xy= s->mb_index2xy[i];
- int error= s->error_status_table[mb_xy];
-
- if(!s->mbskip_table[mb_xy]) //FIXME partition specific
- distance++;
- if(error&(1<<error_type))
- distance= 0;
-
- if(s->partitioned_frame){
- if(distance < threshold_part[error_type-1])
- s->error_status_table[mb_xy]|= 1<<error_type;
- }else{
- if(distance < threshold)
- s->error_status_table[mb_xy]|= 1<<error_type;
- }
-
- if(error&VP_START)
- distance= 9999999;
- }
- }
-#endif
-
- /* forward mark errors */
- error=0;
- for(i=0; i<s->mb_num; i++){
- const int mb_xy= s->mb_index2xy[i];
- int old_error= s->error_status_table[mb_xy];
-
- if(old_error&VP_START)
- error= old_error& (DC_ERROR|AC_ERROR|MV_ERROR);
- else{
- error|= old_error& (DC_ERROR|AC_ERROR|MV_ERROR);
- s->error_status_table[mb_xy]|= error;
- }
- }
-#if 1
- /* handle not partitioned case */
- if(!s->partitioned_frame){
- for(i=0; i<s->mb_num; i++){
- const int mb_xy= s->mb_index2xy[i];
- error= s->error_status_table[mb_xy];
- if(error&(AC_ERROR|DC_ERROR|MV_ERROR))
- error|= AC_ERROR|DC_ERROR|MV_ERROR;
- s->error_status_table[mb_xy]= error;
- }
- }
-#endif
-
- dc_error= ac_error= mv_error=0;
- for(i=0; i<s->mb_num; i++){
- const int mb_xy= s->mb_index2xy[i];
- error= s->error_status_table[mb_xy];
- if(error&DC_ERROR) dc_error ++;
- if(error&AC_ERROR) ac_error ++;
- if(error&MV_ERROR) mv_error ++;
- }
- av_log(s->avctx, AV_LOG_INFO, "concealing %d DC, %d AC, %d MV errors\n", dc_error, ac_error, mv_error);
-
- is_intra_likely= is_intra_more_likely(s);
-
- /* set unknown mb-type to most likely */
- for(i=0; i<s->mb_num; i++){
- const int mb_xy= s->mb_index2xy[i];
- error= s->error_status_table[mb_xy];
- if(!((error&DC_ERROR) && (error&MV_ERROR)))
- continue;
-
- if(is_intra_likely)
- s->current_picture.mb_type[mb_xy]= MB_TYPE_INTRA4x4;
- else
- s->current_picture.mb_type[mb_xy]= MB_TYPE_16x16 | MB_TYPE_L0;
- }
-
- /* handle inter blocks with damaged AC */
- for(mb_y=0; mb_y<s->mb_height; mb_y++){
- for(mb_x=0; mb_x<s->mb_width; mb_x++){
- const int mb_xy= mb_x + mb_y * s->mb_stride;
- const int mb_type= s->current_picture.mb_type[mb_xy];
- error= s->error_status_table[mb_xy];
-
- if(IS_INTRA(mb_type)) continue; //intra
- if(error&MV_ERROR) continue; //inter with damaged MV
- if(!(error&AC_ERROR)) continue; //undamaged inter
-
- s->mv_dir = MV_DIR_FORWARD;
- s->mb_intra=0;
- s->mb_skipped=0;
- if(IS_8X8(mb_type)){
- int mb_index= mb_x*2 + mb_y*2*s->b8_stride;
- int j;
- s->mv_type = MV_TYPE_8X8;
- for(j=0; j<4; j++){
- s->mv[0][j][0] = s->current_picture.motion_val[0][ mb_index + (j&1) + (j>>1)*s->b8_stride ][0];
- s->mv[0][j][1] = s->current_picture.motion_val[0][ mb_index + (j&1) + (j>>1)*s->b8_stride ][1];
- }
- }else{
- s->mv_type = MV_TYPE_16X16;
- s->mv[0][0][0] = s->current_picture.motion_val[0][ mb_x*2 + mb_y*2*s->b8_stride ][0];
- s->mv[0][0][1] = s->current_picture.motion_val[0][ mb_x*2 + mb_y*2*s->b8_stride ][1];
- }
-
- s->dsp.clear_blocks(s->block[0]);
-
- s->mb_x= mb_x;
- s->mb_y= mb_y;
- decode_mb(s);
- }
- }
-
- /* guess MVs */
- if(s->pict_type==B_TYPE){
- for(mb_y=0; mb_y<s->mb_height; mb_y++){
- for(mb_x=0; mb_x<s->mb_width; mb_x++){
- int xy= mb_x*2 + mb_y*2*s->b8_stride;
- const int mb_xy= mb_x + mb_y * s->mb_stride;
- const int mb_type= s->current_picture.mb_type[mb_xy];
- error= s->error_status_table[mb_xy];
-
- if(IS_INTRA(mb_type)) continue;
- if(!(error&MV_ERROR)) continue; //inter with undamaged MV
- if(!(error&AC_ERROR)) continue; //undamaged inter
-
- s->mv_dir = MV_DIR_FORWARD|MV_DIR_BACKWARD;
- s->mb_intra=0;
- s->mv_type = MV_TYPE_16X16;
- s->mb_skipped=0;
-
- if(s->pp_time){
- int time_pp= s->pp_time;
- int time_pb= s->pb_time;
-
- s->mv[0][0][0] = s->next_picture.motion_val[0][xy][0]*time_pb/time_pp;
- s->mv[0][0][1] = s->next_picture.motion_val[0][xy][1]*time_pb/time_pp;
- s->mv[1][0][0] = s->next_picture.motion_val[0][xy][0]*(time_pb - time_pp)/time_pp;
- s->mv[1][0][1] = s->next_picture.motion_val[0][xy][1]*(time_pb - time_pp)/time_pp;
- }else{
- 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->dsp.clear_blocks(s->block[0]);
- s->mb_x= mb_x;
- s->mb_y= mb_y;
- decode_mb(s);
- }
- }
- }else
- guess_mv(s);
-
-#ifdef HAVE_XVMC
- /* the filters below are not XvMC compatible, skip them */
- if(s->avctx->xvmc_acceleration) goto ec_clean;
-#endif
- /* fill DC for inter blocks */
- for(mb_y=0; mb_y<s->mb_height; mb_y++){
- for(mb_x=0; mb_x<s->mb_width; mb_x++){
- int dc, dcu, dcv, y, n;
- int16_t *dc_ptr;
- uint8_t *dest_y, *dest_cb, *dest_cr;
- const int mb_xy= mb_x + mb_y * s->mb_stride;
- const int mb_type= s->current_picture.mb_type[mb_xy];
-
- error= s->error_status_table[mb_xy];
-
- if(IS_INTRA(mb_type) && s->partitioned_frame) continue;
-// if(error&MV_ERROR) continue; //inter data damaged FIXME is this good?
-
- dest_y = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
- dest_cb= s->current_picture.data[1] + mb_x*8 + mb_y*8 *s->uvlinesize;
- dest_cr= s->current_picture.data[2] + mb_x*8 + mb_y*8 *s->uvlinesize;
-
- dc_ptr= &s->dc_val[0][mb_x*2 + mb_y*2*s->b8_stride];
- for(n=0; n<4; n++){
- dc=0;
- for(y=0; y<8; y++){
- int x;
- for(x=0; x<8; x++){
- dc+= dest_y[x + (n&1)*8 + (y + (n>>1)*8)*s->linesize];
- }
- }
- dc_ptr[(n&1) + (n>>1)*s->b8_stride]= (dc+4)>>3;
- }
-
- dcu=dcv=0;
- for(y=0; y<8; y++){
- int x;
- for(x=0; x<8; x++){
- dcu+=dest_cb[x + y*(s->uvlinesize)];
- dcv+=dest_cr[x + y*(s->uvlinesize)];
- }
- }
- s->dc_val[1][mb_x + mb_y*s->mb_stride]= (dcu+4)>>3;
- s->dc_val[2][mb_x + mb_y*s->mb_stride]= (dcv+4)>>3;
- }
- }
-#if 1
- /* guess DC for damaged blocks */
- guess_dc(s, s->dc_val[0], s->mb_width*2, s->mb_height*2, s->b8_stride, 1);
- guess_dc(s, s->dc_val[1], s->mb_width , s->mb_height , s->mb_stride, 0);
- guess_dc(s, s->dc_val[2], s->mb_width , s->mb_height , s->mb_stride, 0);
-#endif
- /* filter luma DC */
- filter181(s->dc_val[0], s->mb_width*2, s->mb_height*2, s->b8_stride);
-
-#if 1
- /* render DC only intra */
- for(mb_y=0; mb_y<s->mb_height; mb_y++){
- for(mb_x=0; mb_x<s->mb_width; mb_x++){
- uint8_t *dest_y, *dest_cb, *dest_cr;
- const int mb_xy= mb_x + mb_y * s->mb_stride;
- const int mb_type= s->current_picture.mb_type[mb_xy];
-
- error= s->error_status_table[mb_xy];
-
- if(IS_INTER(mb_type)) continue;
- if(!(error&AC_ERROR)) continue; //undamaged
-
- dest_y = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
- dest_cb= s->current_picture.data[1] + mb_x*8 + mb_y*8 *s->uvlinesize;
- dest_cr= s->current_picture.data[2] + mb_x*8 + mb_y*8 *s->uvlinesize;
-
- put_dc(s, dest_y, dest_cb, dest_cr, mb_x, mb_y);
- }
- }
-#endif
-
- if(s->avctx->error_concealment&FF_EC_DEBLOCK){
- /* filter horizontal block boundaries */
- h_block_filter(s, s->current_picture.data[0], s->mb_width*2, s->mb_height*2, s->linesize , 1);
- h_block_filter(s, s->current_picture.data[1], s->mb_width , s->mb_height , s->uvlinesize, 0);
- h_block_filter(s, s->current_picture.data[2], s->mb_width , s->mb_height , s->uvlinesize, 0);
-
- /* filter vertical block boundaries */
- v_block_filter(s, s->current_picture.data[0], s->mb_width*2, s->mb_height*2, s->linesize , 1);
- v_block_filter(s, s->current_picture.data[1], s->mb_width , s->mb_height , s->uvlinesize, 0);
- v_block_filter(s, s->current_picture.data[2], s->mb_width , s->mb_height , s->uvlinesize, 0);
- }
-
-#ifdef HAVE_XVMC
-ec_clean:
-#endif
- /* clean a few tables */
- for(i=0; i<s->mb_num; i++){
- const int mb_xy= s->mb_index2xy[i];
- int error= s->error_status_table[mb_xy];
-
- if(s->pict_type!=B_TYPE && (error&(DC_ERROR|MV_ERROR|AC_ERROR))){
- s->mbskip_table[mb_xy]=0;
- }
- s->mbintra_table[mb_xy]=1;
- }
-}
diff --git a/src/libffmpeg/libavcodec/eval.c b/src/libffmpeg/libavcodec/eval.c
deleted file mode 100644
index 6ec706991..000000000
--- a/src/libffmpeg/libavcodec/eval.c
+++ /dev/null
@@ -1,466 +0,0 @@
-/*
- * simple arithmetic expression evaluator
- *
- * Copyright (c) 2002-2006 Michael Niedermayer <michaelni@gmx.at>
- * Copyright (c) 2006 Oded Shimon <ods15@ods15.dyndns.org>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-/**
- * @file eval.c
- * simple arithmetic expression evaluator.
- *
- * see http://joe.hotchkiss.com/programming/eval/eval.html
- */
-
-#include "avcodec.h"
-#include "mpegvideo.h"
-#include "eval.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
-#ifndef NAN
- #define NAN 0.0/0.0
-#endif
-
-#ifndef M_PI
-#define M_PI 3.14159265358979323846
-#endif
-
-typedef struct Parser{
- int stack_index;
- char *s;
- double *const_value;
- const char **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
- char **func2_name; // NULL terminated
- void *opaque;
- char **error;
-#define VARS 10
- double var[VARS];
-} Parser;
-
-static int8_t si_prefixes['z' - 'E' + 1]={
- ['y'-'E']= -24,
- ['z'-'E']= -21,
- ['a'-'E']= -18,
- ['f'-'E']= -15,
- ['p'-'E']= -12,
- ['n'-'E']= - 9,
- ['u'-'E']= - 6,
- ['m'-'E']= - 3,
- ['c'-'E']= - 2,
- ['d'-'E']= - 1,
- ['h'-'E']= 2,
- ['k'-'E']= 3,
- ['K'-'E']= 3,
- ['M'-'E']= 6,
- ['G'-'E']= 9,
- ['T'-'E']= 12,
- ['P'-'E']= 15,
- ['E'-'E']= 18,
- ['Z'-'E']= 21,
- ['Y'-'E']= 24,
-};
-
-/** strtod() function extended with 'k', 'M', 'G', 'ki', 'Mi', 'Gi' and 'B'
- * postfixes. This allows using f.e. kB, MiB, G and B as a postfix. This
- * function assumes that the unit of numbers is bits not bytes.
- */
-static double av_strtod(const char *name, char **tail) {
- double d;
- char *next;
- d = strtod(name, &next);
- /* if parsing succeeded, check for and interpret postfixes */
- if (next!=name) {
-
- if(*next >= 'E' && *next <= 'z'){
- int e= si_prefixes[*next - 'E'];
- if(e){
- if(next[1] == 'i'){
- d*= pow( 2, e/0.3);
- next+=2;
- }else{
- d*= pow(10, e);
- next++;
- }
- }
- }
-
- if(*next=='B') {
- d*=8;
- next++;
- }
- }
- /* if requested, fill in tail with the position after the last parsed
- character */
- if (tail)
- *tail = next;
- return d;
-}
-
-static int strmatch(const char *s, const char *prefix){
- int i;
- for(i=0; prefix[i]; i++){
- if(prefix[i] != s[i]) return 0;
- }
- return 1;
-}
-
-struct ff_expr_s {
- enum {
- e_value, e_const, e_func0, e_func1, e_func2,
- e_squish, e_gauss, e_ld,
- e_mod, e_max, e_min, e_eq, e_gt, e_gte,
- e_pow, e_mul, e_div, e_add,
- e_last, e_st, e_while,
- } type;
- double value; // is sign in other types
- union {
- int const_index;
- double (*func0)(double);
- double (*func1)(void *, double);
- double (*func2)(void *, double, double);
- } a;
- AVEvalExpr * param[2];
-};
-
-static double eval_expr(Parser * p, AVEvalExpr * e) {
- switch (e->type) {
- case e_value: return e->value;
- case e_const: return e->value * p->const_value[e->a.const_index];
- case e_func0: return e->value * e->a.func0(eval_expr(p, e->param[0]));
- case e_func1: return e->value * e->a.func1(p->opaque, eval_expr(p, e->param[0]));
- case e_func2: return e->value * e->a.func2(p->opaque, eval_expr(p, e->param[0]), eval_expr(p, e->param[1]));
- case e_squish: return 1/(1+exp(4*eval_expr(p, e->param[0])));
- case e_gauss: { double d = eval_expr(p, e->param[0]); return exp(-d*d/2)/sqrt(2*M_PI); }
- case e_ld: return e->value * p->var[clip(eval_expr(p, e->param[0]), 0, VARS-1)];
- case e_while: {
- double d = NAN;
- while(eval_expr(p, e->param[0]))
- d=eval_expr(p, e->param[1]);
- return d;
- }
- default: {
- double d = eval_expr(p, e->param[0]);
- double d2 = eval_expr(p, e->param[1]);
- switch (e->type) {
- case e_mod: return e->value * (d - floor(d/d2)*d2);
- case e_max: return e->value * (d > d2 ? d : d2);
- case e_min: return e->value * (d < d2 ? d : d2);
- case e_eq: return e->value * (d == d2 ? 1.0 : 0.0);
- case e_gt: return e->value * (d > d2 ? 1.0 : 0.0);
- case e_gte: return e->value * (d >= d2 ? 1.0 : 0.0);
- case e_pow: return e->value * pow(d, d2);
- case e_mul: return e->value * (d * d2);
- case e_div: return e->value * (d / d2);
- case e_add: return e->value * (d + d2);
- case e_last:return e->value * d2;
- case e_st : return e->value * (p->var[clip(d, 0, VARS-1)]= d2);
- }
- }
- }
- return NAN;
-}
-
-static AVEvalExpr * parse_expr(Parser *p);
-
-void ff_eval_free(AVEvalExpr * e) {
- if (!e) return;
- ff_eval_free(e->param[0]);
- ff_eval_free(e->param[1]);
- av_freep(&e);
-}
-
-static AVEvalExpr * parse_primary(Parser *p) {
- AVEvalExpr * d = av_mallocz(sizeof(AVEvalExpr));
- char *next= p->s;
- int i;
-
- /* number */
- d->value = av_strtod(p->s, &next);
- if(next != p->s){
- d->type = e_value;
- p->s= next;
- return d;
- }
- d->value = 1;
-
- /* named constants */
- for(i=0; p->const_name && p->const_name[i]; i++){
- if(strmatch(p->s, p->const_name[i])){
- p->s+= strlen(p->const_name[i]);
- d->type = e_const;
- d->a.const_index = i;
- return d;
- }
- }
-
- p->s= strchr(p->s, '(');
- if(p->s==NULL){
- *p->error = "missing (";
- p->s= next;
- ff_eval_free(d);
- return NULL;
- }
- p->s++; // "("
- if (*next == '(') { // special case do-nothing
- av_freep(&d);
- d = parse_expr(p);
- if(p->s[0] != ')'){
- *p->error = "missing )";
- ff_eval_free(d);
- return NULL;
- }
- p->s++; // ")"
- return d;
- }
- d->param[0] = parse_expr(p);
- if(p->s[0]== ','){
- p->s++; // ","
- d->param[1] = parse_expr(p);
- }
- if(p->s[0] != ')'){
- *p->error = "missing )";
- ff_eval_free(d);
- return NULL;
- }
- p->s++; // ")"
-
- d->type = e_func0;
- if( strmatch(next, "sinh" ) ) d->a.func0 = sinh;
- else if( strmatch(next, "cosh" ) ) d->a.func0 = cosh;
- else if( strmatch(next, "tanh" ) ) d->a.func0 = tanh;
- else if( strmatch(next, "sin" ) ) d->a.func0 = sin;
- else if( strmatch(next, "cos" ) ) d->a.func0 = cos;
- else if( strmatch(next, "tan" ) ) d->a.func0 = tan;
- else if( strmatch(next, "atan" ) ) d->a.func0 = atan;
- else if( strmatch(next, "asin" ) ) d->a.func0 = asin;
- else if( strmatch(next, "acos" ) ) d->a.func0 = acos;
- else if( strmatch(next, "exp" ) ) d->a.func0 = exp;
- else if( strmatch(next, "log" ) ) d->a.func0 = log;
- else if( strmatch(next, "abs" ) ) d->a.func0 = fabs;
- else if( strmatch(next, "squish") ) d->type = e_squish;
- else if( strmatch(next, "gauss" ) ) d->type = e_gauss;
- else if( strmatch(next, "mod" ) ) d->type = e_mod;
- else if( strmatch(next, "max" ) ) d->type = e_max;
- else if( strmatch(next, "min" ) ) d->type = e_min;
- 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, "ld" ) ) d->type = e_ld;
- else if( strmatch(next, "st" ) ) d->type = e_st;
- else if( strmatch(next, "while" ) ) d->type = e_while;
- else {
- for(i=0; p->func1_name && p->func1_name[i]; i++){
- if(strmatch(next, p->func1_name[i])){
- d->a.func1 = p->func1[i];
- d->type = e_func1;
- return d;
- }
- }
-
- for(i=0; p->func2_name && p->func2_name[i]; i++){
- if(strmatch(next, p->func2_name[i])){
- d->a.func2 = p->func2[i];
- d->type = e_func2;
- return d;
- }
- }
-
- *p->error = "unknown function";
- ff_eval_free(d);
- return NULL;
- }
-
- return d;
-}
-
-static AVEvalExpr * new_eval_expr(int type, int value, AVEvalExpr *p0, AVEvalExpr *p1){
- AVEvalExpr * e = av_mallocz(sizeof(AVEvalExpr));
- e->type =type ;
- e->value =value ;
- e->param[0] =p0 ;
- e->param[1] =p1 ;
- return e;
-}
-
-static AVEvalExpr * 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){
- int sign, sign2;
- AVEvalExpr * 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->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);
- 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));
- }
- return e;
-}
-
-static AVEvalExpr * parse_subexpr(Parser *p) {
- AVEvalExpr * e = parse_term(p);
- while(*p->s == '+' || *p->s == '-') {
- e= new_eval_expr(e_add, 1, e, parse_term(p));
- };
-
- return e;
-}
-
-static AVEvalExpr * parse_expr(Parser *p) {
- AVEvalExpr * e;
-
- if(p->stack_index <= 0) //protect against stack overflows
- return NULL;
- p->stack_index--;
-
- e = parse_subexpr(p);
-
- while(*p->s == ';') {
- p->s++;
- e= new_eval_expr(e_last, 1, e, parse_subexpr(p));
- };
-
- p->stack_index++;
-
- return e;
-}
-
-static int verify_expr(AVEvalExpr * e) {
- if (!e) return 0;
- switch (e->type) {
- case e_value:
- case e_const: return 1;
- case e_func0:
- case e_func1:
- case e_squish:
- case e_ld:
- case e_gauss: return verify_expr(e->param[0]);
- default: return verify_expr(e->param[0]) && verify_expr(e->param[1]);
- }
-}
-
-AVEvalExpr * ff_parse(char *s, const char **const_name,
- double (**func1)(void *, double), const char **func1_name,
- double (**func2)(void *, double, double), char **func2_name,
- char **error){
- Parser p;
- AVEvalExpr * e;
- char w[strlen(s) + 1], * wp = w;
-
- while (*s)
- if (!isspace(*s++)) *wp++ = s[-1];
- *wp++ = 0;
-
- p.stack_index=100;
- p.s= w;
- p.const_name = const_name;
- p.func1 = func1;
- p.func1_name = func1_name;
- p.func2 = func2;
- p.func2_name = func2_name;
- p.error= error;
-
- e = parse_expr(&p);
- if (!verify_expr(e)) {
- ff_eval_free(e);
- return NULL;
- }
- return e;
-}
-
-double ff_parse_eval(AVEvalExpr * e, double *const_value, void *opaque) {
- Parser p;
-
- p.const_value= const_value;
- p.opaque = opaque;
- return eval_expr(&p, e);
-}
-
-double ff_eval2(char *s, double *const_value, const char **const_name,
- double (**func1)(void *, double), const char **func1_name,
- double (**func2)(void *, double, double), char **func2_name,
- void *opaque, char **error){
- AVEvalExpr * e = ff_parse(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);
- return d;
-}
-
-#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
-attribute_deprecated double ff_eval(char *s, double *const_value, const char **const_name,
- double (**func1)(void *, double), const char **func1_name,
- double (**func2)(void *, double, double), char **func2_name,
- void *opaque){
- char *error=NULL;
- double ret;
- ret = ff_eval2(s, const_value, const_name, func1, func1_name, func2, func2_name, opaque, &error);
- if (error)
- av_log(NULL, AV_LOG_ERROR, "Error evaluating \"%s\": %s\n", s, error);
- return ret;
-}
-#endif
-
-#ifdef TEST
-#undef printf
-static double const_values[]={
- M_PI,
- M_E,
- 0
-};
-static const char *const_names[]={
- "PI",
- "E",
- 0
-};
-main(){
- int i;
- printf("%f == 12.7\n", ff_eval("1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", const_values, const_names, NULL, NULL, NULL, NULL, NULL));
- printf("%f == 0.931322575\n", ff_eval("80G/80Gi", const_values, const_names, NULL, NULL, NULL, NULL, NULL));
-
- for(i=0; i<1050; i++){
- START_TIMER
- ff_eval("1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", const_values, const_names, NULL, NULL, NULL, NULL, NULL);
- STOP_TIMER("ff_eval")
- }
-}
-#endif
diff --git a/src/libffmpeg/libavcodec/fastmemcpy.h b/src/libffmpeg/libavcodec/fastmemcpy.h
deleted file mode 100644
index 3459bf1ce..000000000
--- a/src/libffmpeg/libavcodec/fastmemcpy.h
+++ /dev/null
@@ -1,4 +0,0 @@
-#if 0
-extern void *xine_fast_memcpy(void *to, const void *from, size_t len);
-#define memcpy(a,b,c) xine_fast_memcpy(a,b,c)
-#endif
diff --git a/src/libffmpeg/libavcodec/ffv1.c b/src/libffmpeg/libavcodec/ffv1.c
deleted file mode 100644
index 1ca18a4e8..000000000
--- a/src/libffmpeg/libavcodec/ffv1.c
+++ /dev/null
@@ -1,1040 +0,0 @@
-/*
- * FFV1 codec for libavcodec
- *
- * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-/**
- * @file ffv1.c
- * FF Video Codec 1 (an experimental lossless codec)
- */
-
-#include "common.h"
-#include "bitstream.h"
-#include "avcodec.h"
-#include "dsputil.h"
-#include "rangecoder.h"
-#include "golomb.h"
-
-#define MAX_PLANES 4
-#define CONTEXT_SIZE 32
-
-static const int8_t quant3[256]={
- 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 0,
-};
-static const int8_t quant5[256]={
- 0, 1, 1, 1, 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,-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,-1,-1,-1,
-};
-static const int8_t quant7[256]={
- 0, 1, 1, 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, 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
--3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,
--3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,
--3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,
--3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,
--3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,
--3,-3,-3,-3,-3,-3,-3,-3,-3,-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,-1,-1,
-};
-static const int8_t quant9[256]={
- 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 3, 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,-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,-3,-3,-3,-3,
--3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-2,-2,-2,-2,-1,-1,
-};
-static const int8_t quant11[256]={
- 0, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4,
- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
- 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-4,-4,
--4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,
--4,-4,-4,-4,-4,-3,-3,-3,-3,-3,-3,-3,-2,-2,-2,-1,
-};
-static const int8_t quant13[256]={
- 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
- 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
--6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,
--6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,
--6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,
--6,-6,-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,-5,
--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
--4,-4,-4,-4,-4,-4,-4,-4,-4,-3,-3,-3,-3,-2,-2,-1,
-};
-
-static const uint8_t log2_run[32]={
- 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3,
- 4, 4, 5, 5, 6, 6, 7, 7,
- 8, 9,10,11,12,13,14,15,
-};
-
-typedef struct VlcState{
- int16_t drift;
- uint16_t error_sum;
- int8_t bias;
- uint8_t count;
-} VlcState;
-
-typedef struct PlaneContext{
- int context_count;
- uint8_t (*state)[CONTEXT_SIZE];
- VlcState *vlc_state;
- uint8_t interlace_bit_state[2];
-} PlaneContext;
-
-typedef struct FFV1Context{
- AVCodecContext *avctx;
- RangeCoder c;
- GetBitContext gb;
- PutBitContext pb;
- int version;
- int width, height;
- int chroma_h_shift, chroma_v_shift;
- int flags;
- int picture_number;
- AVFrame picture;
- int plane_count;
- int ac; ///< 1-> CABAC 0-> golomb rice
- PlaneContext plane[MAX_PLANES];
- int16_t quant_table[5][256];
- int run_index;
- int colorspace;
-
- DSPContext dsp;
-}FFV1Context;
-
-static av_always_inline int fold(int diff, int bits){
- if(bits==8)
- diff= (int8_t)diff;
- else{
- diff+= 1<<(bits-1);
- diff&=(1<<bits)-1;
- diff-= 1<<(bits-1);
- }
-
- return diff;
-}
-
-static inline int predict(int_fast16_t *src, int_fast16_t *last){
- const int LT= last[-1];
- const int T= last[ 0];
- const int L = src[-1];
-
- return mid_pred(L, L + T - LT, T);
-}
-
-static inline int get_context(FFV1Context *f, int_fast16_t *src, int_fast16_t *last, int_fast16_t *last2){
- const int LT= last[-1];
- const int T= last[ 0];
- const int RT= last[ 1];
- const int L = src[-1];
-
- if(f->quant_table[3][127]){
- const int TT= last2[0];
- const int LL= src[-2];
- return f->quant_table[0][(L-LT) & 0xFF] + f->quant_table[1][(LT-T) & 0xFF] + f->quant_table[2][(T-RT) & 0xFF]
- +f->quant_table[3][(LL-L) & 0xFF] + f->quant_table[4][(TT-T) & 0xFF];
- }else
- return f->quant_table[0][(L-LT) & 0xFF] + f->quant_table[1][(LT-T) & 0xFF] + f->quant_table[2][(T-RT) & 0xFF];
-}
-
-static inline void put_symbol(RangeCoder *c, uint8_t *state, int v, int is_signed){
- int i;
-
- if(v){
- const int a= FFABS(v);
- const int e= av_log2(a);
- put_rac(c, state+0, 0);
-
- assert(e<=9);
-
- for(i=0; i<e; i++){
- put_rac(c, state+1+i, 1); //1..10
- }
- put_rac(c, state+1+i, 0);
-
- for(i=e-1; i>=0; i--){
- put_rac(c, state+22+i, (a>>i)&1); //22..31
- }
-
- if(is_signed)
- put_rac(c, state+11 + e, v < 0); //11..21
- }else{
- put_rac(c, state+0, 1);
- }
-}
-
-static inline int get_symbol(RangeCoder *c, uint8_t *state, int is_signed){
- if(get_rac(c, state+0))
- return 0;
- else{
- int i, e, a;
- e= 0;
- while(get_rac(c, state+1 + e)){ //1..10
- e++;
- }
- assert(e<=9);
-
- a= 1;
- for(i=e-1; i>=0; i--){
- a += a + get_rac(c, state+22 + i); //22..31
- }
-
- if(is_signed && get_rac(c, state+11 + e)) //11..21
- return -a;
- else
- return a;
- }
-}
-
-static inline void update_vlc_state(VlcState * const state, const int v){
- int drift= state->drift;
- int count= state->count;
- state->error_sum += FFABS(v);
- drift += v;
-
- if(count == 128){ //FIXME variable
- count >>= 1;
- drift >>= 1;
- state->error_sum >>= 1;
- }
- count++;
-
- if(drift <= -count){
- if(state->bias > -128) state->bias--;
-
- drift += count;
- if(drift <= -count)
- drift= -count + 1;
- }else if(drift > 0){
- if(state->bias < 127) state->bias++;
-
- drift -= count;
- if(drift > 0)
- drift= 0;
- }
-
- state->drift= drift;
- state->count= count;
-}
-
-static inline void put_vlc_symbol(PutBitContext *pb, VlcState * const state, int v, int bits){
- int i, k, code;
-//printf("final: %d ", v);
- v = fold(v - state->bias, bits);
-
- i= state->count;
- k=0;
- while(i < state->error_sum){ //FIXME optimize
- k++;
- i += i;
- }
-
- assert(k<=8);
-
-#if 0 // JPEG LS
- if(k==0 && 2*state->drift <= - state->count) code= v ^ (-1);
- else code= v;
-#else
- code= v ^ ((2*state->drift + state->count)>>31);
-#endif
-
-//printf("v:%d/%d bias:%d error:%d drift:%d count:%d k:%d\n", v, code, state->bias, state->error_sum, state->drift, state->count, k);
- set_sr_golomb(pb, code, k, 12, bits);
-
- update_vlc_state(state, v);
-}
-
-static inline int get_vlc_symbol(GetBitContext *gb, VlcState * const state, int bits){
- int k, i, v, ret;
-
- i= state->count;
- k=0;
- while(i < state->error_sum){ //FIXME optimize
- k++;
- i += i;
- }
-
- assert(k<=8);
-
- v= get_sr_golomb(gb, k, 12, bits);
-//printf("v:%d bias:%d error:%d drift:%d count:%d k:%d", v, state->bias, state->error_sum, state->drift, state->count, k);
-
-#if 0 // JPEG LS
- if(k==0 && 2*state->drift <= - state->count) v ^= (-1);
-#else
- v ^= ((2*state->drift + state->count)>>31);
-#endif
-
- ret= fold(v + state->bias, bits);
-
- update_vlc_state(state, v);
-//printf("final: %d\n", ret);
- return ret;
-}
-
-#ifdef CONFIG_ENCODERS
-static inline int encode_line(FFV1Context *s, int w, int_fast16_t *sample[2], int plane_index, int bits){
- PlaneContext * const p= &s->plane[plane_index];
- RangeCoder * const c= &s->c;
- int x;
- int run_index= s->run_index;
- int run_count=0;
- int run_mode=0;
-
- if(s->ac){
- if(c->bytestream_end - c->bytestream < w*20){
- av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
- return -1;
- }
- }else{
- if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < w*4){
- av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
- return -1;
- }
- }
-
- for(x=0; x<w; x++){
- int diff, context;
-
- context= get_context(s, sample[0]+x, sample[1]+x, sample[2]+x);
- diff= sample[0][x] - predict(sample[0]+x, sample[1]+x);
-
- if(context < 0){
- context = -context;
- diff= -diff;
- }
-
- diff= fold(diff, bits);
-
- if(s->ac){
- put_symbol(c, p->state[context], diff, 1);
- }else{
- if(context == 0) run_mode=1;
-
- if(run_mode){
-
- if(diff){
- while(run_count >= 1<<log2_run[run_index]){
- run_count -= 1<<log2_run[run_index];
- run_index++;
- put_bits(&s->pb, 1, 1);
- }
-
- put_bits(&s->pb, 1 + log2_run[run_index], run_count);
- if(run_index) run_index--;
- run_count=0;
- run_mode=0;
- if(diff>0) diff--;
- }else{
- run_count++;
- }
- }
-
-// printf("count:%d index:%d, mode:%d, x:%d y:%d pos:%d\n", run_count, run_index, run_mode, x, y, (int)put_bits_count(&s->pb));
-
- if(run_mode == 0)
- put_vlc_symbol(&s->pb, &p->vlc_state[context], diff, bits);
- }
- }
- if(run_mode){
- while(run_count >= 1<<log2_run[run_index]){
- run_count -= 1<<log2_run[run_index];
- run_index++;
- put_bits(&s->pb, 1, 1);
- }
-
- if(run_count)
- put_bits(&s->pb, 1, 1);
- }
- s->run_index= run_index;
-
- return 0;
-}
-
-static void encode_plane(FFV1Context *s, uint8_t *src, int w, int h, int stride, int plane_index){
- int x,y,i;
- const int ring_size= s->avctx->context_model ? 3 : 2;
- int_fast16_t sample_buffer[ring_size][w+6], *sample[ring_size];
- s->run_index=0;
-
- memset(sample_buffer, 0, sizeof(sample_buffer));
-
- for(y=0; y<h; y++){
- for(i=0; i<ring_size; i++)
- sample[i]= sample_buffer[(h+i-y)%ring_size]+3;
-
- sample[0][-1]= sample[1][0 ];
- sample[1][ w]= sample[1][w-1];
-//{START_TIMER
- for(x=0; x<w; x++){
- sample[0][x]= src[x + stride*y];
- }
- encode_line(s, w, sample, plane_index, 8);
-//STOP_TIMER("encode line")}
- }
-}
-
-static void encode_rgb_frame(FFV1Context *s, uint32_t *src, int w, int h, int stride){
- int x, y, p, i;
- const int ring_size= s->avctx->context_model ? 3 : 2;
- int_fast16_t sample_buffer[3][ring_size][w+6], *sample[3][ring_size];
- s->run_index=0;
-
- memset(sample_buffer, 0, sizeof(sample_buffer));
-
- for(y=0; y<h; y++){
- for(i=0; i<ring_size; i++)
- for(p=0; p<3; p++)
- sample[p][i]= sample_buffer[p][(h+i-y)%ring_size]+3;
-
- for(x=0; x<w; x++){
- int v= src[x + stride*y];
- int b= v&0xFF;
- int g= (v>>8)&0xFF;
- int r= (v>>16)&0xFF;
-
- b -= g;
- r -= g;
- g += (b + r)>>2;
- b += 0x100;
- r += 0x100;
-
-// assert(g>=0 && b>=0 && r>=0);
-// assert(g<256 && b<512 && r<512);
- sample[0][0][x]= g;
- sample[1][0][x]= b;
- sample[2][0][x]= r;
- }
- for(p=0; p<3; p++){
- sample[p][0][-1]= sample[p][1][0 ];
- sample[p][1][ w]= sample[p][1][w-1];
- encode_line(s, w, sample[p], FFMIN(p, 1), 9);
- }
- }
-}
-
-static void write_quant_table(RangeCoder *c, int16_t *quant_table){
- int last=0;
- int i;
- uint8_t state[CONTEXT_SIZE];
- memset(state, 128, sizeof(state));
-
- for(i=1; i<128 ; i++){
- if(quant_table[i] != quant_table[i-1]){
- put_symbol(c, state, i-last-1, 0);
- last= i;
- }
- }
- put_symbol(c, state, i-last-1, 0);
-}
-
-static void write_header(FFV1Context *f){
- uint8_t state[CONTEXT_SIZE];
- int i;
- RangeCoder * const c= &f->c;
-
- 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->colorspace, 0); //YUV cs type
- put_rac(c, state, 1); //chroma planes
- put_symbol(c, state, f->chroma_h_shift, 0);
- put_symbol(c, state, f->chroma_v_shift, 0);
- put_rac(c, state, 0); //no transparency plane
-
- for(i=0; i<5; i++)
- write_quant_table(c, f->quant_table[i]);
-}
-#endif /* CONFIG_ENCODERS */
-
-static int common_init(AVCodecContext *avctx){
- FFV1Context *s = avctx->priv_data;
- int width, height;
-
- s->avctx= avctx;
- s->flags= avctx->flags;
-
- dsputil_init(&s->dsp, avctx);
-
- width= s->width= avctx->width;
- height= s->height= avctx->height;
-
- assert(width && height);
-
- return 0;
-}
-
-#ifdef CONFIG_ENCODERS
-static int encode_init(AVCodecContext *avctx)
-{
- FFV1Context *s = avctx->priv_data;
- int i;
-
- common_init(avctx);
-
- s->version=0;
- s->ac= avctx->coder_type;
-
- s->plane_count=2;
- for(i=0; i<256; i++){
- s->quant_table[0][i]= quant11[i];
- s->quant_table[1][i]= 11*quant11[i];
- if(avctx->context_model==0){
- s->quant_table[2][i]= 11*11*quant11[i];
- s->quant_table[3][i]=
- s->quant_table[4][i]=0;
- }else{
- s->quant_table[2][i]= 11*11*quant5 [i];
- s->quant_table[3][i]= 5*11*11*quant5 [i];
- s->quant_table[4][i]= 5*5*11*11*quant5 [i];
- }
- }
-
- for(i=0; i<s->plane_count; i++){
- PlaneContext * const p= &s->plane[i];
-
- if(avctx->context_model==0){
- p->context_count= (11*11*11+1)/2;
- }else{
- p->context_count= (11*11*5*5*5+1)/2;
- }
-
- if(s->ac){
- if(!p->state) p->state= av_malloc(CONTEXT_SIZE*p->context_count*sizeof(uint8_t));
- }else{
- if(!p->vlc_state) p->vlc_state= av_malloc(p->context_count*sizeof(VlcState));
- }
- }
-
- avctx->coded_frame= &s->picture;
- switch(avctx->pix_fmt){
- case PIX_FMT_YUV444P:
- case PIX_FMT_YUV422P:
- case PIX_FMT_YUV420P:
- case PIX_FMT_YUV411P:
- case PIX_FMT_YUV410P:
- s->colorspace= 0;
- break;
- case PIX_FMT_RGBA32:
- s->colorspace= 1;
- break;
- default:
- av_log(avctx, AV_LOG_ERROR, "format not supported\n");
- return -1;
- }
- avcodec_get_chroma_sub_sample(avctx->pix_fmt, &s->chroma_h_shift, &s->chroma_v_shift);
-
- s->picture_number=0;
-
- return 0;
-}
-#endif /* CONFIG_ENCODERS */
-
-
-static void clear_state(FFV1Context *f){
- int i, j;
-
- for(i=0; i<f->plane_count; i++){
- PlaneContext *p= &f->plane[i];
-
- p->interlace_bit_state[0]= 128;
- p->interlace_bit_state[1]= 128;
-
- for(j=0; j<p->context_count; j++){
- if(f->ac){
- memset(p->state[j], 128, sizeof(uint8_t)*CONTEXT_SIZE);
- }else{
- p->vlc_state[j].drift= 0;
- p->vlc_state[j].error_sum= 4; //FFMAX((RANGE + 32)/64, 2);
- p->vlc_state[j].bias= 0;
- p->vlc_state[j].count= 1;
- }
- }
- }
-}
-
-#ifdef CONFIG_ENCODERS
-static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
- FFV1Context *f = avctx->priv_data;
- RangeCoder * const c= &f->c;
- AVFrame *pict = data;
- const int width= f->width;
- const int height= f->height;
- AVFrame * const p= &f->picture;
- int used_count= 0;
- 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;
- p->pict_type= FF_I_TYPE;
-
- if(avctx->gop_size==0 || f->picture_number % avctx->gop_size == 0){
- put_rac(c, &keystate, 1);
- p->key_frame= 1;
- write_header(f);
- clear_state(f);
- }else{
- put_rac(c, &keystate, 0);
- p->key_frame= 0;
- }
-
- if(!f->ac){
- used_count += ff_rac_terminate(c);
-//printf("pos=%d\n", used_count);
- init_put_bits(&f->pb, buf + used_count, buf_size - used_count);
- }
-
- if(f->colorspace==0){
- const int chroma_width = -((-width )>>f->chroma_h_shift);
- const int chroma_height= -((-height)>>f->chroma_v_shift);
-
- encode_plane(f, p->data[0], width, height, p->linesize[0], 0);
-
- encode_plane(f, p->data[1], chroma_width, chroma_height, p->linesize[1], 1);
- encode_plane(f, p->data[2], chroma_width, chroma_height, p->linesize[2], 1);
- }else{
- encode_rgb_frame(f, (uint32_t*)(p->data[0]), width, height, p->linesize[0]/4);
- }
- emms_c();
-
- f->picture_number++;
-
- if(f->ac){
- return ff_rac_terminate(c);
- }else{
- flush_put_bits(&f->pb); //nicer padding FIXME
- return used_count + (put_bits_count(&f->pb)+7)/8;
- }
-}
-#endif /* CONFIG_ENCODERS */
-
-static int common_end(AVCodecContext *avctx){
- FFV1Context *s = avctx->priv_data;
- int i;
-
- for(i=0; i<s->plane_count; i++){
- PlaneContext *p= &s->plane[i];
-
- av_freep(&p->state);
- }
-
- return 0;
-}
-
-static inline void decode_line(FFV1Context *s, int w, int_fast16_t *sample[2], int plane_index, int bits){
- PlaneContext * const p= &s->plane[plane_index];
- RangeCoder * const c= &s->c;
- int x;
- int run_count=0;
- int run_mode=0;
- int run_index= s->run_index;
-
- for(x=0; x<w; x++){
- int diff, context, sign;
-
- context= get_context(s, sample[1] + x, sample[0] + x, sample[1] + x);
- if(context < 0){
- context= -context;
- sign=1;
- }else
- sign=0;
-
-
- if(s->ac){
- diff= get_symbol(c, p->state[context], 1);
- }else{
- if(context == 0 && run_mode==0) run_mode=1;
-
- if(run_mode){
- if(run_count==0 && run_mode==1){
- if(get_bits1(&s->gb)){
- run_count = 1<<log2_run[run_index];
- if(x + run_count <= w) run_index++;
- }else{
- if(log2_run[run_index]) run_count = get_bits(&s->gb, log2_run[run_index]);
- else run_count=0;
- if(run_index) run_index--;
- run_mode=2;
- }
- }
- run_count--;
- if(run_count < 0){
- run_mode=0;
- run_count=0;
- diff= get_vlc_symbol(&s->gb, &p->vlc_state[context], bits);
- if(diff>=0) diff++;
- }else
- diff=0;
- }else
- diff= get_vlc_symbol(&s->gb, &p->vlc_state[context], bits);
-
-// printf("count:%d index:%d, mode:%d, x:%d y:%d pos:%d\n", run_count, run_index, run_mode, x, y, get_bits_count(&s->gb));
- }
-
- if(sign) diff= -diff;
-
- sample[1][x]= (predict(sample[1] + x, sample[0] + x) + diff) & ((1<<bits)-1);
- }
- s->run_index= run_index;
-}
-
-static void decode_plane(FFV1Context *s, uint8_t *src, int w, int h, int stride, int plane_index){
- int x, y;
- int_fast16_t sample_buffer[2][w+6];
- int_fast16_t *sample[2]= {sample_buffer[0]+3, sample_buffer[1]+3};
-
- s->run_index=0;
-
- memset(sample_buffer, 0, sizeof(sample_buffer));
-
- for(y=0; y<h; y++){
- int_fast16_t *temp= sample[0]; //FIXME try a normal buffer
-
- sample[0]= sample[1];
- sample[1]= temp;
-
- sample[1][-1]= sample[0][0 ];
- sample[0][ w]= sample[0][w-1];
-
-//{START_TIMER
- decode_line(s, w, sample, plane_index, 8);
- for(x=0; x<w; x++){
- src[x + stride*y]= sample[1][x];
- }
-//STOP_TIMER("decode-line")}
- }
-}
-
-static void decode_rgb_frame(FFV1Context *s, uint32_t *src, int w, int h, int stride){
- int x, y, p;
- int_fast16_t sample_buffer[3][2][w+6];
- int_fast16_t *sample[3][2]= {
- {sample_buffer[0][0]+3, sample_buffer[0][1]+3},
- {sample_buffer[1][0]+3, sample_buffer[1][1]+3},
- {sample_buffer[2][0]+3, sample_buffer[2][1]+3}};
-
- s->run_index=0;
-
- memset(sample_buffer, 0, sizeof(sample_buffer));
-
- for(y=0; y<h; y++){
- for(p=0; p<3; p++){
- int_fast16_t *temp= sample[p][0]; //FIXME try a normal buffer
-
- sample[p][0]= sample[p][1];
- sample[p][1]= temp;
-
- sample[p][1][-1]= sample[p][0][0 ];
- sample[p][0][ w]= sample[p][0][w-1];
- decode_line(s, w, sample[p], FFMIN(p, 1), 9);
- }
- for(x=0; x<w; x++){
- int g= sample[0][1][x];
- int b= sample[1][1][x];
- int r= sample[2][1][x];
-
-// assert(g>=0 && b>=0 && r>=0);
-// assert(g<256 && b<512 && r<512);
-
- b -= 0x100;
- r -= 0x100;
- g -= (b + r)>>2;
- b += g;
- r += g;
-
- src[x + stride*y]= b + (g<<8) + (r<<16);
- }
- }
-}
-
-static int read_quant_table(RangeCoder *c, int16_t *quant_table, int scale){
- int v;
- int i=0;
- uint8_t state[CONTEXT_SIZE];
-
- memset(state, 128, sizeof(state));
-
- for(v=0; i<128 ; v++){
- int len= get_symbol(c, state, 0) + 1;
-
- if(len + i > 128) return -1;
-
- while(len--){
- quant_table[i] = scale*v;
- i++;
-//printf("%2d ",v);
-//if(i%16==0) printf("\n");
- }
- }
-
- for(i=1; i<128; i++){
- quant_table[256-i]= -quant_table[i];
- }
- quant_table[128]= -quant_table[127];
-
- return 2*v - 1;
-}
-
-static int read_header(FFV1Context *f){
- uint8_t state[CONTEXT_SIZE];
- int i, context_count;
- RangeCoder * const c= &f->c;
-
- memset(state, 128, sizeof(state));
-
- f->version= get_symbol(c, state, 0);
- f->ac= f->avctx->coder_type= get_symbol(c, state, 0);
- f->colorspace= get_symbol(c, state, 0); //YUV cs type
- get_rac(c, state); //no chroma = false
- f->chroma_h_shift= get_symbol(c, state, 0);
- f->chroma_v_shift= get_symbol(c, state, 0);
- get_rac(c, state); //transparency plane
- f->plane_count= 2;
-
- if(f->colorspace==0){
- switch(16*f->chroma_h_shift + f->chroma_v_shift){
- case 0x00: f->avctx->pix_fmt= PIX_FMT_YUV444P; break;
- case 0x10: f->avctx->pix_fmt= PIX_FMT_YUV422P; break;
- case 0x11: f->avctx->pix_fmt= PIX_FMT_YUV420P; break;
- case 0x20: f->avctx->pix_fmt= PIX_FMT_YUV411P; break;
- case 0x22: f->avctx->pix_fmt= PIX_FMT_YUV410P; break;
- default:
- av_log(f->avctx, AV_LOG_ERROR, "format not supported\n");
- return -1;
- }
- }else if(f->colorspace==1){
- if(f->chroma_h_shift || f->chroma_v_shift){
- av_log(f->avctx, AV_LOG_ERROR, "chroma subsampling not supported in this colorspace\n");
- return -1;
- }
- f->avctx->pix_fmt= PIX_FMT_RGBA32;
- }else{
- av_log(f->avctx, AV_LOG_ERROR, "colorspace not supported\n");
- return -1;
- }
-
-//printf("%d %d %d\n", f->chroma_h_shift, f->chroma_v_shift,f->avctx->pix_fmt);
-
- context_count=1;
- for(i=0; i<5; i++){
- context_count*= read_quant_table(c, f->quant_table[i], context_count);
- if(context_count < 0 || context_count > 32768){
- av_log(f->avctx, AV_LOG_ERROR, "read_quant_table error\n");
- return -1;
- }
- }
- context_count= (context_count+1)/2;
-
- for(i=0; i<f->plane_count; i++){
- PlaneContext * const p= &f->plane[i];
-
- p->context_count= context_count;
-
- if(f->ac){
- if(!p->state) p->state= av_malloc(CONTEXT_SIZE*p->context_count*sizeof(uint8_t));
- }else{
- if(!p->vlc_state) p->vlc_state= av_malloc(p->context_count*sizeof(VlcState));
- }
- }
-
- return 0;
-}
-
-static int decode_init(AVCodecContext *avctx)
-{
-// FFV1Context *s = avctx->priv_data;
-
- common_init(avctx);
-
- return 0;
-}
-
-static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size){
- FFV1Context *f = avctx->priv_data;
- RangeCoder * const c= &f->c;
- const int width= f->width;
- const int height= f->height;
- AVFrame * const p= &f->picture;
- int bytes_read;
- uint8_t keystate= 128;
-
- AVFrame *picture = data;
-
- ff_init_range_decoder(c, buf, buf_size);
- ff_build_rac_states(c, 0.05*(1LL<<32), 256-8);
-
-
- p->pict_type= FF_I_TYPE; //FIXME I vs. P
- if(get_rac(c, &keystate)){
- p->key_frame= 1;
- if(read_header(f) < 0)
- return -1;
- clear_state(f);
- }else{
- p->key_frame= 0;
- }
- if(!f->plane[0].state && !f->plane[0].vlc_state)
- return -1;
-
- p->reference= 0;
- if(avctx->get_buffer(avctx, p) < 0){
- av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
- return -1;
- }
-
- if(avctx->debug&FF_DEBUG_PICT_INFO)
- av_log(avctx, AV_LOG_ERROR, "keyframe:%d coder:%d\n", p->key_frame, f->ac);
-
- if(!f->ac){
- bytes_read = c->bytestream - c->bytestream_start - 1;
- if(bytes_read ==0) av_log(avctx, AV_LOG_ERROR, "error at end of AC stream\n"); //FIXME
-//printf("pos=%d\n", bytes_read);
- init_get_bits(&f->gb, buf + bytes_read, buf_size - bytes_read);
- } else {
- bytes_read = 0; /* avoid warning */
- }
-
- if(f->colorspace==0){
- const int chroma_width = -((-width )>>f->chroma_h_shift);
- const int chroma_height= -((-height)>>f->chroma_v_shift);
- decode_plane(f, p->data[0], width, height, p->linesize[0], 0);
-
- decode_plane(f, p->data[1], chroma_width, chroma_height, p->linesize[1], 1);
- decode_plane(f, p->data[2], chroma_width, chroma_height, p->linesize[2], 1);
- }else{
- decode_rgb_frame(f, (uint32_t*)p->data[0], width, height, p->linesize[0]/4);
- }
-
- emms_c();
-
- f->picture_number++;
-
- *picture= *p;
-
- avctx->release_buffer(avctx, p); //FIXME
-
- *data_size = sizeof(AVFrame);
-
- if(f->ac){
- bytes_read= c->bytestream - c->bytestream_start - 1;
- if(bytes_read ==0) av_log(f->avctx, AV_LOG_ERROR, "error at end of frame\n");
- }else{
- bytes_read+= (get_bits_count(&f->gb)+7)/8;
- }
-
- return bytes_read;
-}
-
-AVCodec ffv1_decoder = {
- "ffv1",
- CODEC_TYPE_VIDEO,
- CODEC_ID_FFV1,
- sizeof(FFV1Context),
- decode_init,
- NULL,
- common_end,
- decode_frame,
- CODEC_CAP_DR1 /*| CODEC_CAP_DRAW_HORIZ_BAND*/,
- NULL
-};
-
-#ifdef CONFIG_ENCODERS
-AVCodec ffv1_encoder = {
- "ffv1",
- CODEC_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_RGBA32, -1},
-};
-#endif
diff --git a/src/libffmpeg/libavcodec/flicvideo.c b/src/libffmpeg/libavcodec/flicvideo.c
deleted file mode 100644
index 78506eee8..000000000
--- a/src/libffmpeg/libavcodec/flicvideo.c
+++ /dev/null
@@ -1,754 +0,0 @@
-/*
- * FLI/FLC Animation Video Decoder
- * Copyright (C) 2003, 2004 the ffmpeg project
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-/**
- * @file flic.c
- * 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
- * variations, visit:
- * http://www.compuphase.com/flic.htm
- *
- * This decoder outputs PAL8/RGB555/RGB565 and maybe one day RGB24
- * colorspace data, depending on the FLC. To use this decoder, be
- * sure that your demuxer sends the FLI file header to the decoder via
- * the extradata chunk in AVCodecContext. The chunk should be 128 bytes
- * large. The only exception is for FLI files from the game "Magic Carpet",
- * in which the header is only 12 bytes.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "common.h"
-#include "avcodec.h"
-#include "bswap.h"
-
-#define FLI_256_COLOR 4
-#define FLI_DELTA 7
-#define FLI_COLOR 11
-#define FLI_LC 12
-#define FLI_BLACK 13
-#define FLI_BRUN 15
-#define FLI_COPY 16
-#define FLI_MINI 18
-#define FLI_DTA_BRUN 25
-#define FLI_DTA_COPY 26
-#define FLI_DTA_LC 27
-
-#define FLI_TYPE_CODE (0xAF11)
-#define FLC_FLX_TYPE_CODE (0xAF12)
-#define FLC_DTA_TYPE_CODE (0xAF44) /* Marks an "Extended FLC" comes from Dave's Targa Animator (DTA) */
-#define FLC_MAGIC_CARPET_SYNTHETIC_TYPE_CODE (0xAF13)
-
-#define CHECK_PIXEL_PTR(n) \
- if (pixel_ptr + n > pixel_limit) { \
- av_log (s->avctx, AV_LOG_INFO, "Problem: pixel_ptr >= pixel_limit (%d >= %d)\n", \
- pixel_ptr + n, pixel_limit); \
- return -1; \
- } \
-
-typedef struct FlicDecodeContext {
- AVCodecContext *avctx;
- AVFrame frame;
-
- unsigned int palette[256];
- int new_palette;
- int fli_type; /* either 0xAF11 or 0xAF12, affects palette resolution */
-} FlicDecodeContext;
-
-static int flic_decode_init(AVCodecContext *avctx)
-{
- FlicDecodeContext *s = (FlicDecodeContext *)avctx->priv_data;
- unsigned char *fli_header = (unsigned char *)avctx->extradata;
- int depth;
-
- s->avctx = avctx;
- avctx->has_b_frames = 0;
-
- s->fli_type = AV_RL16(&fli_header[4]); /* Might be overridden if a Magic Carpet FLC */
- depth = AV_RL16(&fli_header[12]);
-
- if (depth == 0) {
- depth = 8; /* Some FLC generators set depth to zero, when they mean 8Bpp. Fix up here */
- }
-
- if (s->avctx->extradata_size == 12) {
- /* special case for magic carpet FLIs */
- s->fli_type = FLC_MAGIC_CARPET_SYNTHETIC_TYPE_CODE;
- } else if (s->avctx->extradata_size != 128) {
- av_log(avctx, AV_LOG_ERROR, "Expected extradata of 12 or 128 bytes\n");
- return -1;
- }
-
- if ((s->fli_type == FLC_FLX_TYPE_CODE) && (depth == 16)) {
- depth = 15; /* Original Autodesk FLX's say the depth is 16Bpp when it is really 15Bpp */
- }
-
- switch (depth) {
- case 8 : avctx->pix_fmt = PIX_FMT_PAL8; break;
- case 15 : avctx->pix_fmt = PIX_FMT_RGB555; break;
- case 16 : avctx->pix_fmt = PIX_FMT_RGB565; break;
- case 24 : avctx->pix_fmt = PIX_FMT_BGR24; /* Supposedly BGR, but havent any files to test with */
- av_log(avctx, AV_LOG_ERROR, "24Bpp FLC/FLX is unsupported due to no test files.\n");
- return -1;
- break;
- default :
- av_log(avctx, AV_LOG_ERROR, "Unkown FLC/FLX depth of %d Bpp is unsupported.\n",depth);
- return -1;
- }
-
- s->frame.data[0] = NULL;
- s->new_palette = 0;
-
- return 0;
-}
-
-static int flic_decode_frame_8BPP(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- FlicDecodeContext *s = (FlicDecodeContext *)avctx->priv_data;
-
- int stream_ptr = 0;
- int stream_ptr_after_color_chunk;
- int pixel_ptr;
- int palette_ptr;
- unsigned char palette_idx1;
- unsigned char palette_idx2;
-
- unsigned int frame_size;
- int num_chunks;
-
- unsigned int chunk_size;
- int chunk_type;
-
- int i, j;
-
- int color_packets;
- int color_changes;
- int color_shift;
- unsigned char r, g, b;
-
- int lines;
- int compressed_lines;
- int starting_line;
- signed short line_packets;
- int y_ptr;
- int byte_run;
- int pixel_skip;
- int pixel_countdown;
- unsigned char *pixels;
- int pixel_limit;
-
- s->frame.reference = 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;
- }
-
- pixels = s->frame.data[0];
- pixel_limit = s->avctx->height * s->frame.linesize[0];
-
- frame_size = AV_RL32(&buf[stream_ptr]);
- stream_ptr += 6; /* skip the magic number */
- num_chunks = AV_RL16(&buf[stream_ptr]);
- stream_ptr += 10; /* skip padding */
-
- frame_size -= 16;
-
- /* iterate through the chunks */
- while ((frame_size > 0) && (num_chunks > 0)) {
- chunk_size = AV_RL32(&buf[stream_ptr]);
- stream_ptr += 4;
- chunk_type = AV_RL16(&buf[stream_ptr]);
- stream_ptr += 2;
-
- switch (chunk_type) {
- case FLI_256_COLOR:
- case FLI_COLOR:
- stream_ptr_after_color_chunk = stream_ptr + chunk_size - 6;
-
- /* check special case: If this file is from the Magic Carpet
- * game and uses 6-bit colors even though it reports 256-color
- * chunks in a 0xAF12-type file (fli_type is set to 0xAF13 during
- * initialization) */
- if ((chunk_type == FLI_256_COLOR) && (s->fli_type != FLC_MAGIC_CARPET_SYNTHETIC_TYPE_CODE))
- color_shift = 0;
- else
- color_shift = 2;
- /* set up the palette */
- color_packets = AV_RL16(&buf[stream_ptr]);
- stream_ptr += 2;
- palette_ptr = 0;
- for (i = 0; i < color_packets; i++) {
- /* first byte is how many colors to skip */
- palette_ptr += buf[stream_ptr++];
-
- /* next byte indicates how many entries to change */
- color_changes = buf[stream_ptr++];
-
- /* if there are 0 color changes, there are actually 256 */
- if (color_changes == 0)
- color_changes = 256;
-
- for (j = 0; j < color_changes; j++) {
- unsigned int entry;
-
- /* wrap around, for good measure */
- if ((unsigned)palette_ptr >= 256)
- palette_ptr = 0;
-
- r = buf[stream_ptr++] << color_shift;
- g = buf[stream_ptr++] << color_shift;
- b = buf[stream_ptr++] << color_shift;
- entry = (r << 16) | (g << 8) | b;
- if (s->palette[palette_ptr] != entry)
- s->new_palette = 1;
- s->palette[palette_ptr++] = entry;
- }
- }
-
- /* color chunks sometimes have weird 16-bit alignment issues;
- * therefore, take the hardline approach and set the stream_ptr
- * to the value calculated w.r.t. the size specified by the color
- * chunk header */
- stream_ptr = stream_ptr_after_color_chunk;
-
- break;
-
- case FLI_DELTA:
- y_ptr = 0;
- compressed_lines = AV_RL16(&buf[stream_ptr]);
- stream_ptr += 2;
- while (compressed_lines > 0) {
- line_packets = AV_RL16(&buf[stream_ptr]);
- stream_ptr += 2;
- if ((line_packets & 0xC000) == 0xC000) {
- // line skip opcode
- line_packets = -line_packets;
- y_ptr += line_packets * s->frame.linesize[0];
- } else if ((line_packets & 0xC000) == 0x4000) {
- av_log(avctx, AV_LOG_ERROR, "Undefined opcode (%x) in DELTA_FLI\n", line_packets);
- } else if ((line_packets & 0xC000) == 0x8000) {
- // "last byte" opcode
- pixels[y_ptr + s->frame.linesize[0] - 1] = line_packets & 0xff;
- } else {
- compressed_lines--;
- pixel_ptr = y_ptr;
- pixel_countdown = s->avctx->width;
- for (i = 0; i < line_packets; i++) {
- /* account for the skip bytes */
- pixel_skip = buf[stream_ptr++];
- pixel_ptr += pixel_skip;
- pixel_countdown -= pixel_skip;
- byte_run = (signed char)(buf[stream_ptr++]);
- if (byte_run < 0) {
- byte_run = -byte_run;
- palette_idx1 = buf[stream_ptr++];
- palette_idx2 = buf[stream_ptr++];
- CHECK_PIXEL_PTR(byte_run);
- for (j = 0; j < byte_run; j++, pixel_countdown -= 2) {
- pixels[pixel_ptr++] = palette_idx1;
- pixels[pixel_ptr++] = palette_idx2;
- }
- } else {
- CHECK_PIXEL_PTR(byte_run * 2);
- for (j = 0; j < byte_run * 2; j++, pixel_countdown--) {
- palette_idx1 = buf[stream_ptr++];
- pixels[pixel_ptr++] = palette_idx1;
- }
- }
- }
-
- y_ptr += s->frame.linesize[0];
- }
- }
- break;
-
- case FLI_LC:
- /* line compressed */
- starting_line = AV_RL16(&buf[stream_ptr]);
- stream_ptr += 2;
- y_ptr = 0;
- y_ptr += starting_line * s->frame.linesize[0];
-
- compressed_lines = AV_RL16(&buf[stream_ptr]);
- stream_ptr += 2;
- while (compressed_lines > 0) {
- pixel_ptr = y_ptr;
- pixel_countdown = s->avctx->width;
- line_packets = buf[stream_ptr++];
- if (line_packets > 0) {
- for (i = 0; i < line_packets; i++) {
- /* account for the skip bytes */
- pixel_skip = buf[stream_ptr++];
- pixel_ptr += pixel_skip;
- pixel_countdown -= pixel_skip;
- byte_run = (signed char)(buf[stream_ptr++]);
- if (byte_run > 0) {
- CHECK_PIXEL_PTR(byte_run);
- for (j = 0; j < byte_run; j++, pixel_countdown--) {
- palette_idx1 = buf[stream_ptr++];
- pixels[pixel_ptr++] = palette_idx1;
- }
- } else if (byte_run < 0) {
- byte_run = -byte_run;
- palette_idx1 = buf[stream_ptr++];
- CHECK_PIXEL_PTR(byte_run);
- for (j = 0; j < byte_run; j++, pixel_countdown--) {
- pixels[pixel_ptr++] = palette_idx1;
- }
- }
- }
- }
-
- y_ptr += s->frame.linesize[0];
- compressed_lines--;
- }
- break;
-
- case FLI_BLACK:
- /* set the whole frame to color 0 (which is usually black) */
- memset(pixels, 0,
- s->frame.linesize[0] * s->avctx->height);
- break;
-
- case FLI_BRUN:
- /* Byte run compression: This chunk type only occurs in the first
- * FLI frame and it will update the entire frame. */
- y_ptr = 0;
- for (lines = 0; lines < s->avctx->height; lines++) {
- pixel_ptr = y_ptr;
- /* disregard the line packets; instead, iterate through all
- * pixels on a row */
- stream_ptr++;
- pixel_countdown = s->avctx->width;
- while (pixel_countdown > 0) {
- byte_run = (signed char)(buf[stream_ptr++]);
- if (byte_run > 0) {
- palette_idx1 = buf[stream_ptr++];
- CHECK_PIXEL_PTR(byte_run);
- for (j = 0; j < byte_run; j++) {
- pixels[pixel_ptr++] = palette_idx1;
- pixel_countdown--;
- if (pixel_countdown < 0)
- av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d)\n",
- pixel_countdown);
- }
- } else { /* copy bytes if byte_run < 0 */
- byte_run = -byte_run;
- CHECK_PIXEL_PTR(byte_run);
- for (j = 0; j < byte_run; j++) {
- palette_idx1 = buf[stream_ptr++];
- pixels[pixel_ptr++] = palette_idx1;
- pixel_countdown--;
- if (pixel_countdown < 0)
- av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d)\n",
- pixel_countdown);
- }
- }
- }
-
- y_ptr += s->frame.linesize[0];
- }
- break;
-
- case FLI_COPY:
- /* copy the chunk (uncompressed frame) */
- if (chunk_size - 6 > s->avctx->width * s->avctx->height) {
- av_log(avctx, AV_LOG_ERROR, "In chunk FLI_COPY : source data (%d bytes) " \
- "bigger than image, skipping chunk\n", chunk_size - 6);
- stream_ptr += chunk_size - 6;
- } else {
- for (y_ptr = 0; y_ptr < s->frame.linesize[0] * s->avctx->height;
- y_ptr += s->frame.linesize[0]) {
- memcpy(&pixels[y_ptr], &buf[stream_ptr],
- s->avctx->width);
- stream_ptr += s->avctx->width;
- }
- }
- break;
-
- case FLI_MINI:
- /* some sort of a thumbnail? disregard this chunk... */
- stream_ptr += chunk_size - 6;
- break;
-
- default:
- av_log(avctx, AV_LOG_ERROR, "Unrecognized chunk type: %d\n", chunk_type);
- break;
- }
-
- frame_size -= chunk_size;
- num_chunks--;
- }
-
- /* by the end of the chunk, the stream ptr should equal the frame
- * size (minus 1, possibly); if it doesn't, issue a warning */
- if ((stream_ptr != buf_size) && (stream_ptr != buf_size - 1))
- av_log(avctx, AV_LOG_ERROR, "Processed FLI chunk where chunk size = %d " \
- "and final chunk ptr = %d\n", buf_size, stream_ptr);
-
- /* make the palette available on the way out */
- memcpy(s->frame.data[1], s->palette, AVPALETTE_SIZE);
- if (s->new_palette) {
- s->frame.palette_has_changed = 1;
- s->new_palette = 0;
- }
-
- *data_size=sizeof(AVFrame);
- *(AVFrame*)data = s->frame;
-
- return buf_size;
-}
-
-static int flic_decode_frame_15_16BPP(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- /* Note, the only difference between the 15Bpp and 16Bpp */
- /* Format is the pixel format, the packets are processed the same. */
- FlicDecodeContext *s = (FlicDecodeContext *)avctx->priv_data;
-
- int stream_ptr = 0;
- int pixel_ptr;
- unsigned char palette_idx1;
-
- unsigned int frame_size;
- int num_chunks;
-
- unsigned int chunk_size;
- int chunk_type;
-
- int i, j;
-
- int lines;
- int compressed_lines;
- signed short line_packets;
- int y_ptr;
- int byte_run;
- int pixel_skip;
- int pixel_countdown;
- unsigned char *pixels;
- int pixel;
- int pixel_limit;
-
- s->frame.reference = 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;
- }
-
- pixels = s->frame.data[0];
- pixel_limit = s->avctx->height * s->frame.linesize[0];
-
- frame_size = AV_RL32(&buf[stream_ptr]);
- stream_ptr += 6; /* skip the magic number */
- num_chunks = AV_RL16(&buf[stream_ptr]);
- stream_ptr += 10; /* skip padding */
-
- frame_size -= 16;
-
- /* iterate through the chunks */
- while ((frame_size > 0) && (num_chunks > 0)) {
- chunk_size = AV_RL32(&buf[stream_ptr]);
- stream_ptr += 4;
- chunk_type = AV_RL16(&buf[stream_ptr]);
- stream_ptr += 2;
-
- switch (chunk_type) {
- case FLI_256_COLOR:
- case FLI_COLOR:
- /* For some reason, it seems that non-paletised flics do include one of these */
- /* chunks in their first frame. Why i do not know, it seems rather extraneous */
-/* av_log(avctx, AV_LOG_ERROR, "Unexpected Palette chunk %d in non-paletised FLC\n",chunk_type);*/
- stream_ptr = stream_ptr + chunk_size - 6;
- break;
-
- case FLI_DELTA:
- case FLI_DTA_LC:
- y_ptr = 0;
- compressed_lines = AV_RL16(&buf[stream_ptr]);
- stream_ptr += 2;
- while (compressed_lines > 0) {
- line_packets = AV_RL16(&buf[stream_ptr]);
- stream_ptr += 2;
- if (line_packets < 0) {
- line_packets = -line_packets;
- y_ptr += line_packets * s->frame.linesize[0];
- } else {
- compressed_lines--;
- pixel_ptr = y_ptr;
- pixel_countdown = s->avctx->width;
- for (i = 0; i < line_packets; i++) {
- /* account for the skip bytes */
- pixel_skip = buf[stream_ptr++];
- pixel_ptr += (pixel_skip*2); /* Pixel is 2 bytes wide */
- pixel_countdown -= pixel_skip;
- byte_run = (signed char)(buf[stream_ptr++]);
- if (byte_run < 0) {
- byte_run = -byte_run;
- pixel = AV_RL16(&buf[stream_ptr]);
- stream_ptr += 2;
- CHECK_PIXEL_PTR(byte_run);
- for (j = 0; j < byte_run; j++, pixel_countdown -= 2) {
- *((signed short*)(&pixels[pixel_ptr])) = pixel;
- pixel_ptr += 2;
- }
- } else {
- CHECK_PIXEL_PTR(byte_run);
- for (j = 0; j < byte_run; j++, pixel_countdown--) {
- *((signed short*)(&pixels[pixel_ptr])) = AV_RL16(&buf[stream_ptr]);
- stream_ptr += 2;
- pixel_ptr += 2;
- }
- }
- }
-
- y_ptr += s->frame.linesize[0];
- }
- }
- break;
-
- case FLI_LC:
- av_log(avctx, AV_LOG_ERROR, "Unexpected FLI_LC chunk in non-paletised FLC\n");
- stream_ptr = stream_ptr + chunk_size - 6;
- break;
-
- case FLI_BLACK:
- /* set the whole frame to 0x0000 which is black in both 15Bpp and 16Bpp modes. */
- memset(pixels, 0x0000,
- s->frame.linesize[0] * s->avctx->height);
- break;
-
- case FLI_BRUN:
- y_ptr = 0;
- for (lines = 0; lines < s->avctx->height; lines++) {
- pixel_ptr = y_ptr;
- /* disregard the line packets; instead, iterate through all
- * pixels on a row */
- stream_ptr++;
- pixel_countdown = (s->avctx->width * 2);
-
- while (pixel_countdown > 0) {
- byte_run = (signed char)(buf[stream_ptr++]);
- if (byte_run > 0) {
- palette_idx1 = buf[stream_ptr++];
- CHECK_PIXEL_PTR(byte_run);
- for (j = 0; j < byte_run; j++) {
- pixels[pixel_ptr++] = palette_idx1;
- pixel_countdown--;
- if (pixel_countdown < 0)
- av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d)\n",
- pixel_countdown);
- }
- } else { /* copy bytes if byte_run < 0 */
- byte_run = -byte_run;
- CHECK_PIXEL_PTR(byte_run);
- for (j = 0; j < byte_run; j++) {
- palette_idx1 = buf[stream_ptr++];
- pixels[pixel_ptr++] = palette_idx1;
- pixel_countdown--;
- if (pixel_countdown < 0)
- av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d)\n",
- pixel_countdown);
- }
- }
- }
-
- /* Now FLX is strange, in that it is "byte" as opposed to "pixel" run length compressed.
- * This doesnt give us any good oportunity to perform word endian conversion
- * during decompression. So if its requried (ie, this isnt a LE target, we do
- * a second pass over the line here, swapping the bytes.
- */
- pixel = 0xFF00;
- if (0xFF00 != AV_RL16(&pixel)) /* Check if its not an LE Target */
- {
- pixel_ptr = y_ptr;
- pixel_countdown = s->avctx->width;
- while (pixel_countdown > 0) {
- *((signed short*)(&pixels[pixel_ptr])) = AV_RL16(&buf[pixel_ptr]);
- pixel_ptr += 2;
- }
- }
- y_ptr += s->frame.linesize[0];
- }
- break;
-
- case FLI_DTA_BRUN:
- y_ptr = 0;
- for (lines = 0; lines < s->avctx->height; lines++) {
- pixel_ptr = y_ptr;
- /* disregard the line packets; instead, iterate through all
- * pixels on a row */
- stream_ptr++;
- pixel_countdown = s->avctx->width; /* Width is in pixels, not bytes */
-
- while (pixel_countdown > 0) {
- byte_run = (signed char)(buf[stream_ptr++]);
- if (byte_run > 0) {
- pixel = AV_RL16(&buf[stream_ptr]);
- stream_ptr += 2;
- CHECK_PIXEL_PTR(byte_run);
- for (j = 0; j < byte_run; j++) {
- *((signed short*)(&pixels[pixel_ptr])) = pixel;
- pixel_ptr += 2;
- pixel_countdown--;
- if (pixel_countdown < 0)
- av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d)\n",
- pixel_countdown);
- }
- } else { /* copy pixels if byte_run < 0 */
- byte_run = -byte_run;
- CHECK_PIXEL_PTR(byte_run);
- for (j = 0; j < byte_run; j++) {
- *((signed short*)(&pixels[pixel_ptr])) = AV_RL16(&buf[stream_ptr]);
- stream_ptr += 2;
- pixel_ptr += 2;
- pixel_countdown--;
- if (pixel_countdown < 0)
- av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d)\n",
- pixel_countdown);
- }
- }
- }
-
- y_ptr += s->frame.linesize[0];
- }
- break;
-
- case FLI_COPY:
- case FLI_DTA_COPY:
- /* copy the chunk (uncompressed frame) */
- if (chunk_size - 6 > (unsigned int)(s->avctx->width * s->avctx->height)*2) {
- av_log(avctx, AV_LOG_ERROR, "In chunk FLI_COPY : source data (%d bytes) " \
- "bigger than image, skipping chunk\n", chunk_size - 6);
- stream_ptr += chunk_size - 6;
- } else {
-
- for (y_ptr = 0; y_ptr < s->frame.linesize[0] * s->avctx->height;
- y_ptr += s->frame.linesize[0]) {
-
- pixel_countdown = s->avctx->width;
- pixel_ptr = 0;
- while (pixel_countdown > 0) {
- *((signed short*)(&pixels[y_ptr + pixel_ptr])) = AV_RL16(&buf[stream_ptr+pixel_ptr]);
- pixel_ptr += 2;
- pixel_countdown--;
- }
- stream_ptr += s->avctx->width*2;
- }
- }
- break;
-
- case FLI_MINI:
- /* some sort of a thumbnail? disregard this chunk... */
- stream_ptr += chunk_size - 6;
- break;
-
- default:
- av_log(avctx, AV_LOG_ERROR, "Unrecognized chunk type: %d\n", chunk_type);
- break;
- }
-
- frame_size -= chunk_size;
- num_chunks--;
- }
-
- /* by the end of the chunk, the stream ptr should equal the frame
- * size (minus 1, possibly); if it doesn't, issue a warning */
- if ((stream_ptr != buf_size) && (stream_ptr != buf_size - 1))
- av_log(avctx, AV_LOG_ERROR, "Processed FLI chunk where chunk size = %d " \
- "and final chunk ptr = %d\n", buf_size, stream_ptr);
-
-
- *data_size=sizeof(AVFrame);
- *(AVFrame*)data = s->frame;
-
- return buf_size;
-}
-
-static int flic_decode_frame_24BPP(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- av_log(avctx, AV_LOG_ERROR, "24Bpp FLC Unsupported due to lack of test files.\n");
- return -1;
-}
-
-static int flic_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- if (avctx->pix_fmt == PIX_FMT_PAL8) {
- return flic_decode_frame_8BPP(avctx, data, data_size,
- buf, buf_size);
- }
- else if ((avctx->pix_fmt == PIX_FMT_RGB555) ||
- (avctx->pix_fmt == PIX_FMT_RGB565)) {
- return flic_decode_frame_15_16BPP(avctx, data, data_size,
- buf, buf_size);
- }
- else if (avctx->pix_fmt == PIX_FMT_BGR24) {
- return flic_decode_frame_24BPP(avctx, data, data_size,
- buf, buf_size);
- }
-
- /* Shouldnt get here, ever as the pix_fmt is processed */
- /* in flic_decode_init and the above if should deal with */
- /* the finite set of possibilites allowable by here. */
- /* but in case we do, just error out. */
- av_log(avctx, AV_LOG_ERROR, "Unknown Format of FLC. My Science cant explain how this happened\n");
- return -1;
-}
-
-
-static int flic_decode_end(AVCodecContext *avctx)
-{
- FlicDecodeContext *s = avctx->priv_data;
-
- if (s->frame.data[0])
- avctx->release_buffer(avctx, &s->frame);
-
- return 0;
-}
-
-AVCodec flic_decoder = {
- "flic",
- CODEC_TYPE_VIDEO,
- CODEC_ID_FLIC,
- sizeof(FlicDecodeContext),
- flic_decode_init,
- NULL,
- flic_decode_end,
- flic_decode_frame,
- CODEC_CAP_DR1,
- NULL,
- NULL,
- NULL,
- NULL
-};
diff --git a/src/libffmpeg/libavcodec/g726.c b/src/libffmpeg/libavcodec/g726.c
deleted file mode 100644
index c509292b6..000000000
--- a/src/libffmpeg/libavcodec/g726.c
+++ /dev/null
@@ -1,429 +0,0 @@
-/*
- * G.726 ADPCM audio codec
- * Copyright (c) 2004 Roman Shaposhnik.
- *
- * This is a very straightforward rendition of the G.726
- * Section 4 "Computational Details".
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General 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 <limits.h>
-#include "avcodec.h"
-#include "common.h"
-#include "bitstream.h"
-
-/**
- * G.726 11bit float.
- * G.726 Standard uses rather odd 11bit floating point arithmentic for
- * numerous occasions. It's a mistery to me why they did it this way
- * instead of simply using 32bit integer arithmetic.
- */
-typedef struct Float11 {
- int sign; /**< 1bit sign */
- int exp; /**< 4bit exponent */
- int mant; /**< 6bit mantissa */
-} Float11;
-
-static inline Float11* i2f(int16_t i, Float11* f)
-{
- f->sign = (i < 0);
- if (f->sign)
- i = -i;
- f->exp = av_log2_16bit(i) + !!i;
- f->mant = i? (i<<6) >> f->exp : 1<<5;
- return f;
-}
-
-static inline int16_t mult(Float11* f1, Float11* f2)
-{
- int res, exp;
-
- exp = f1->exp + f2->exp;
- res = (((f1->mant * f2->mant) + 0x30) >> 4) << 7;
- res = exp > 26 ? res << (exp - 26) : res >> (26 - exp);
- return (f1->sign ^ f2->sign) ? -res : res;
-}
-
-static inline int sgn(int value)
-{
- return (value < 0) ? -1 : 1;
-}
-
-typedef struct G726Tables {
- int bits; /**< bits per sample */
- int* quant; /**< quantization table */
- int* iquant; /**< inverse quantization table */
- int* W; /**< special table #1 ;-) */
- int* F; /**< special table #2 */
-} G726Tables;
-
-typedef struct G726Context {
- G726Tables* tbls; /**< static tables needed for computation */
-
- Float11 sr[2]; /**< prev. reconstructed samples */
- Float11 dq[6]; /**< prev. difference */
- int a[2]; /**< second order predictor coeffs */
- int b[6]; /**< sixth order predictor coeffs */
- int pk[2]; /**< signs of prev. 2 sez + dq */
-
- int ap; /**< scale factor control */
- int yu; /**< fast scale factor */
- int yl; /**< slow scale factor */
- int dms; /**< short average magnitude of F[i] */
- int dml; /**< long average magnitude of F[i] */
- int td; /**< tone detect */
-
- int se; /**< estimated signal for the next iteration */
- int sez; /**< estimated second order prediction */
- int y; /**< quantizer scaling factor for the next iteration */
-} G726Context;
-
-static int quant_tbl16[] = /**< 16kbit/s 2bits per sample */
- { 260, INT_MAX };
-static int iquant_tbl16[] =
- { 116, 365, 365, 116 };
-static int W_tbl16[] =
- { -22, 439, 439, -22 };
-static int F_tbl16[] =
- { 0, 7, 7, 0 };
-
-static int quant_tbl24[] = /**< 24kbit/s 3bits per sample */
- { 7, 217, 330, INT_MAX };
-static int iquant_tbl24[] =
- { INT_MIN, 135, 273, 373, 373, 273, 135, INT_MIN };
-static int W_tbl24[] =
- { -4, 30, 137, 582, 582, 137, 30, -4 };
-static int F_tbl24[] =
- { 0, 1, 2, 7, 7, 2, 1, 0 };
-
-static int quant_tbl32[] = /**< 32kbit/s 4bits per sample */
- { -125, 79, 177, 245, 299, 348, 399, INT_MAX };
-static int iquant_tbl32[] =
- { INT_MIN, 4, 135, 213, 273, 323, 373, 425,
- 425, 373, 323, 273, 213, 135, 4, INT_MIN };
-static int W_tbl32[] =
- { -12, 18, 41, 64, 112, 198, 355, 1122,
- 1122, 355, 198, 112, 64, 41, 18, -12};
-static int F_tbl32[] =
- { 0, 0, 0, 1, 1, 1, 3, 7, 7, 3, 1, 1, 1, 0, 0, 0 };
-
-static int quant_tbl40[] = /**< 40kbit/s 5bits per sample */
- { -122, -16, 67, 138, 197, 249, 297, 338,
- 377, 412, 444, 474, 501, 527, 552, INT_MAX };
-static int iquant_tbl40[] =
- { INT_MIN, -66, 28, 104, 169, 224, 274, 318,
- 358, 395, 429, 459, 488, 514, 539, 566,
- 566, 539, 514, 488, 459, 429, 395, 358,
- 318, 274, 224, 169, 104, 28, -66, INT_MIN };
-static int W_tbl40[] =
- { 14, 14, 24, 39, 40, 41, 58, 100,
- 141, 179, 219, 280, 358, 440, 529, 696,
- 696, 529, 440, 358, 280, 219, 179, 141,
- 100, 58, 41, 40, 39, 24, 14, 14 };
-static int F_tbl40[] =
- { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 6,
- 6, 6, 5, 4, 3, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
-
-static G726Tables G726Tables_pool[] =
- {{ 2, quant_tbl16, iquant_tbl16, W_tbl16, F_tbl16 },
- { 3, quant_tbl24, iquant_tbl24, W_tbl24, F_tbl24 },
- { 4, quant_tbl32, iquant_tbl32, W_tbl32, F_tbl32 },
- { 5, quant_tbl40, iquant_tbl40, W_tbl40, F_tbl40 }};
-
-
-/**
- * Para 4.2.2 page 18: Adaptive quantizer.
- */
-static inline uint8_t quant(G726Context* c, int d)
-{
- int sign, exp, i, dln;
-
- sign = i = 0;
- if (d < 0) {
- sign = 1;
- d = -d;
- }
- exp = av_log2_16bit(d);
- dln = ((exp<<7) + (((d<<7)>>exp)&0x7f)) - (c->y>>2);
-
- while (c->tbls->quant[i] < INT_MAX && c->tbls->quant[i] < dln)
- ++i;
-
- if (sign)
- i = ~i;
- if (c->tbls->bits != 2 && i == 0) /* I'm not sure this is a good idea */
- i = 0xff;
-
- return i;
-}
-
-/**
- * Para 4.2.3 page 22: Inverse adaptive quantizer.
- */
-static inline int16_t inverse_quant(G726Context* c, int i)
-{
- int dql, dex, dqt;
-
- dql = c->tbls->iquant[i] + (c->y >> 2);
- dex = (dql>>7) & 0xf; /* 4bit exponent */
- dqt = (1<<7) + (dql & 0x7f); /* log2 -> linear */
- return (dql < 0) ? 0 : ((dqt<<7) >> (14-dex));
-}
-
-static inline int16_t g726_iterate(G726Context* c, int16_t I)
-{
- int dq, re_signal, pk0, fa1, i, tr, ylint, ylfrac, thr2, al, dq0;
- Float11 f;
-
- dq = inverse_quant(c, I);
- if (I >> (c->tbls->bits - 1)) /* get the sign */
- dq = -dq;
- re_signal = c->se + dq;
-
- /* Transition detect */
- ylint = (c->yl >> 15);
- ylfrac = (c->yl >> 10) & 0x1f;
- thr2 = (ylint > 9) ? 0x1f << 10 : (0x20 + ylfrac) << ylint;
- if (c->td == 1 && abs(dq) > ((thr2+(thr2>>1))>>1))
- tr = 1;
- else
- tr = 0;
-
- /* Update second order predictor coefficient A2 and A1 */
- pk0 = (c->sez + dq) ? sgn(c->sez + dq) : 0;
- dq0 = dq ? sgn(dq) : 0;
- if (tr) {
- c->a[0] = 0;
- c->a[1] = 0;
- for (i=0; i<6; i++)
- c->b[i] = 0;
- } else {
- /* This is a bit crazy, but it really is +255 not +256 */
- fa1 = clip((-c->a[0]*c->pk[0]*pk0)>>5, -256, 255);
-
- c->a[1] += 128*pk0*c->pk[1] + fa1 - (c->a[1]>>7);
- c->a[1] = clip(c->a[1], -12288, 12288);
- c->a[0] += 64*3*pk0*c->pk[0] - (c->a[0] >> 8);
- c->a[0] = clip(c->a[0], -(15360 - c->a[1]), 15360 - c->a[1]);
-
- for (i=0; i<6; i++)
- c->b[i] += 128*dq0*sgn(-c->dq[i].sign) - (c->b[i]>>8);
- }
-
- /* Update Dq and Sr and Pk */
- c->pk[1] = c->pk[0];
- c->pk[0] = pk0 ? pk0 : 1;
- c->sr[1] = c->sr[0];
- i2f(re_signal, &c->sr[0]);
- for (i=5; i>0; i--)
- c->dq[i] = c->dq[i-1];
- i2f(dq, &c->dq[0]);
- c->dq[0].sign = I >> (c->tbls->bits - 1); /* Isn't it crazy ?!?! */
-
- /* Update tone detect [I'm not sure 'tr == 0' is really needed] */
- c->td = (tr == 0 && c->a[1] < -11776);
-
- /* Update Ap */
- c->dms += ((c->tbls->F[I]<<9) - c->dms) >> 5;
- c->dml += ((c->tbls->F[I]<<11) - c->dml) >> 7;
- if (tr)
- c->ap = 256;
- else if (c->y > 1535 && !c->td && (abs((c->dms << 2) - c->dml) < (c->dml >> 3)))
- c->ap += (-c->ap) >> 4;
- else
- c->ap += (0x200 - c->ap) >> 4;
-
- /* Update Yu and Yl */
- c->yu = clip(c->y + (((c->tbls->W[I] << 5) - c->y) >> 5), 544, 5120);
- c->yl += c->yu + ((-c->yl)>>6);
-
- /* Next iteration for Y */
- al = (c->ap >= 256) ? 1<<6 : c->ap >> 2;
- c->y = (c->yl + (c->yu - (c->yl>>6))*al) >> 6;
-
- /* Next iteration for SE and SEZ */
- c->se = 0;
- for (i=0; i<6; i++)
- c->se += mult(i2f(c->b[i] >> 2, &f), &c->dq[i]);
- c->sez = c->se >> 1;
- for (i=0; i<2; i++)
- c->se += mult(i2f(c->a[i] >> 2, &f), &c->sr[i]);
- c->se >>= 1;
-
- return clip(re_signal << 2, -0xffff, 0xffff);
-}
-
-static int g726_reset(G726Context* c, int bit_rate)
-{
- int i;
-
- c->tbls = &G726Tables_pool[bit_rate/8000 - 2];
- for (i=0; i<2; i++) {
- i2f(0, &c->sr[i]);
- c->a[i] = 0;
- c->pk[i] = 1;
- }
- for (i=0; i<6; i++) {
- i2f(0, &c->dq[i]);
- c->b[i] = 0;
- }
- c->ap = 0;
- c->dms = 0;
- c->dml = 0;
- c->yu = 544;
- c->yl = 34816;
- c->td = 0;
-
- c->se = 0;
- c->sez = 0;
- c->y = 544;
-
- return 0;
-}
-
-static int16_t g726_decode(G726Context* c, int16_t i)
-{
- return g726_iterate(c, i);
-}
-
-#ifdef CONFIG_ENCODERS
-static int16_t g726_encode(G726Context* c, int16_t sig)
-{
- uint8_t i;
-
- i = quant(c, sig/4 - c->se) & ((1<<c->tbls->bits) - 1);
- g726_iterate(c, i);
- return i;
-}
-#endif
-
-/* Interfacing to the libavcodec */
-
-typedef struct AVG726Context {
- G726Context c;
- int bits_left;
- int bit_buffer;
- int code_size;
-} AVG726Context;
-
-static int g726_init(AVCodecContext * avctx)
-{
- AVG726Context* c = (AVG726Context*)avctx->priv_data;
-
- if (avctx->channels != 1 ||
- (avctx->bit_rate != 16000 && avctx->bit_rate != 24000 &&
- avctx->bit_rate != 32000 && avctx->bit_rate != 40000)) {
- av_log(avctx, AV_LOG_ERROR, "G726: unsupported audio format\n");
- return -1;
- }
- if (avctx->sample_rate != 8000 && avctx->strict_std_compliance>FF_COMPLIANCE_INOFFICIAL) {
- av_log(avctx, AV_LOG_ERROR, "G726: unsupported audio format\n");
- return -1;
- }
- g726_reset(&c->c, avctx->bit_rate);
- c->code_size = c->c.tbls->bits;
- c->bit_buffer = 0;
- c->bits_left = 0;
-
- avctx->coded_frame = avcodec_alloc_frame();
- if (!avctx->coded_frame)
- return -ENOMEM;
- avctx->coded_frame->key_frame = 1;
-
- return 0;
-}
-
-static int g726_close(AVCodecContext *avctx)
-{
- av_freep(&avctx->coded_frame);
- return 0;
-}
-
-#ifdef CONFIG_ENCODERS
-static int g726_encode_frame(AVCodecContext *avctx,
- uint8_t *dst, int buf_size, void *data)
-{
- AVG726Context *c = avctx->priv_data;
- short *samples = data;
- PutBitContext pb;
-
- init_put_bits(&pb, dst, 1024*1024);
-
- for (; buf_size; buf_size--)
- put_bits(&pb, c->code_size, g726_encode(&c->c, *samples++));
-
- flush_put_bits(&pb);
-
- return put_bits_count(&pb)>>3;
-}
-#endif
-
-static int g726_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- AVG726Context *c = avctx->priv_data;
- short *samples = data;
- uint8_t code;
- uint8_t mask;
- GetBitContext gb;
-
- if (!buf_size)
- goto out;
-
- mask = (1<<c->code_size) - 1;
- init_get_bits(&gb, buf, buf_size * 8);
- if (c->bits_left) {
- int s = c->code_size - c->bits_left;;
- code = (c->bit_buffer << s) | get_bits(&gb, s);
- *samples++ = g726_decode(&c->c, code & mask);
- }
-
- while (get_bits_count(&gb) + c->code_size <= buf_size*8)
- *samples++ = g726_decode(&c->c, get_bits(&gb, c->code_size) & mask);
-
- c->bits_left = buf_size*8 - get_bits_count(&gb);
- c->bit_buffer = get_bits(&gb, c->bits_left);
-
-out:
- *data_size = (uint8_t*)samples - (uint8_t*)data;
- return buf_size;
-}
-
-#ifdef CONFIG_ENCODERS
-AVCodec adpcm_g726_encoder = {
- "g726",
- CODEC_TYPE_AUDIO,
- CODEC_ID_ADPCM_G726,
- sizeof(AVG726Context),
- g726_init,
- g726_encode_frame,
- g726_close,
- NULL,
-};
-#endif //CONFIG_ENCODERS
-
-AVCodec adpcm_g726_decoder = {
- "g726",
- CODEC_TYPE_AUDIO,
- CODEC_ID_ADPCM_G726,
- sizeof(AVG726Context),
- g726_init,
- NULL,
- g726_close,
- g726_decode_frame,
-};
diff --git a/src/libffmpeg/libavcodec/h261.c b/src/libffmpeg/libavcodec/h261.c
deleted file mode 100644
index 8d4ca08cd..000000000
--- a/src/libffmpeg/libavcodec/h261.c
+++ /dev/null
@@ -1,1055 +0,0 @@
-/*
- * H261 decoder
- * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
- * Copyright (c) 2004 Maarten Daniels
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General 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 h261.c
- * h261codec.
- */
-
-#include "common.h"
-#include "dsputil.h"
-#include "avcodec.h"
-#include "mpegvideo.h"
-#include "h261data.h"
-
-
-#define H261_MBA_VLC_BITS 9
-#define H261_MTYPE_VLC_BITS 6
-#define H261_MV_VLC_BITS 7
-#define H261_CBP_VLC_BITS 9
-#define TCOEFF_VLC_BITS 9
-
-#define MBA_STUFFING 33
-#define MBA_STARTCODE 34
-#define IS_FIL(a) ((a)&MB_TYPE_H261_FIL)
-
-/**
- * H261Context
- */
-typedef struct H261Context{
- MpegEncContext s;
-
- int current_mba;
- int previous_mba;
- int mba_diff;
- int mtype;
- int current_mv_x;
- int current_mv_y;
- int gob_number;
- int gob_start_code_skipped; // 1 if gob start code is already read before gob header is read
-}H261Context;
-
-void ff_h261_loop_filter(MpegEncContext *s){
- H261Context * h= (H261Context*)s;
- const int linesize = s->linesize;
- const int uvlinesize= s->uvlinesize;
- uint8_t *dest_y = s->dest[0];
- uint8_t *dest_cb= s->dest[1];
- uint8_t *dest_cr= s->dest[2];
-
- if(!(IS_FIL (h->mtype)))
- return;
-
- s->dsp.h261_loop_filter(dest_y , linesize);
- s->dsp.h261_loop_filter(dest_y + 8, linesize);
- s->dsp.h261_loop_filter(dest_y + 8 * linesize , linesize);
- s->dsp.h261_loop_filter(dest_y + 8 * linesize + 8, linesize);
- s->dsp.h261_loop_filter(dest_cb, uvlinesize);
- s->dsp.h261_loop_filter(dest_cr, uvlinesize);
-}
-
-int ff_h261_get_picture_format(int width, int height){
- // QCIF
- if (width == 176 && height == 144)
- return 0;
- // CIF
- else if (width == 352 && height == 288)
- return 1;
- // ERROR
- else
- return -1;
-}
-
-static void h261_encode_block(H261Context * h, DCTELEM * block,
- int n);
-static int h261_decode_block(H261Context *h, DCTELEM *block,
- int n, int coded);
-
-void ff_h261_encode_picture_header(MpegEncContext * s, int picture_number){
- H261Context * h = (H261Context *) s;
- int format, temp_ref;
-
- align_put_bits(&s->pb);
-
- /* Update the pointer to last GOB */
- s->ptr_lastgob = pbBufPtr(&s->pb);
-
- put_bits(&s->pb, 20, 0x10); /* PSC */
-
- temp_ref= s->picture_number * (int64_t)30000 * s->avctx->time_base.num /
- (1001 * (int64_t)s->avctx->time_base.den); //FIXME maybe this should use a timestamp
- put_bits(&s->pb, 5, temp_ref & 0x1f); /* TemporalReference */
-
- 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_h261_get_picture_format(s->width, s->height);
-
- put_bits(&s->pb, 1, format); /* 0 == QCIF, 1 == CIF */
-
- put_bits(&s->pb, 1, 0); /* still image mode */
- put_bits(&s->pb, 1, 0); /* reserved */
-
- put_bits(&s->pb, 1, 0); /* no PEI */
- if(format == 0)
- h->gob_number = -1;
- else
- h->gob_number = 0;
- h->current_mba = 0;
-}
-
-/**
- * Encodes a group of blocks header.
- */
-static void h261_encode_gob_header(MpegEncContext * s, int mb_line){
- H261Context * h = (H261Context *)s;
- if(ff_h261_get_picture_format(s->width, s->height) == 0){
- h->gob_number+=2; // QCIF
- }
- else{
- h->gob_number++; // CIF
- }
- put_bits(&s->pb, 16, 1); /* GBSC */
- put_bits(&s->pb, 4, h->gob_number); /* GN */
- put_bits(&s->pb, 5, s->qscale); /* GQUANT */
- put_bits(&s->pb, 1, 0); /* no GEI */
- h->current_mba = 0;
- h->previous_mba = 0;
- h->current_mv_x=0;
- h->current_mv_y=0;
-}
-
-void ff_h261_reorder_mb_index(MpegEncContext* s){
- int index= s->mb_x + s->mb_y*s->mb_width;
-
- if(index % 33 == 0)
- h261_encode_gob_header(s,0);
-
- /* for CIF the GOB's are fragmented in the middle of a scanline
- that's why we need to adjust the x and y index of the macroblocks */
- if(ff_h261_get_picture_format(s->width,s->height) == 1){ // CIF
- s->mb_x = index % 11 ; index /= 11;
- s->mb_y = index % 3 ; index /= 3;
- s->mb_x+= 11*(index % 2); index /= 2;
- s->mb_y+= 3*index;
-
- ff_init_block_index(s);
- ff_update_block_index(s);
- }
-}
-
-static void h261_encode_motion(H261Context * h, int val){
- MpegEncContext * const s = &h->s;
- int sign, code;
- if(val==0){
- code = 0;
- put_bits(&s->pb,h261_mv_tab[code][1],h261_mv_tab[code][0]);
- }
- else{
- if(val > 15)
- val -=32;
- if(val < -16)
- val+=32;
- sign = val < 0;
- code = sign ? -val : val;
- put_bits(&s->pb,h261_mv_tab[code][1],h261_mv_tab[code][0]);
- put_bits(&s->pb,1,sign);
- }
-}
-
-static inline int get_cbp(MpegEncContext * s,
- DCTELEM block[6][64])
-{
- int i, cbp;
- cbp= 0;
- for (i = 0; i < 6; i++) {
- if (s->block_last_index[i] >= 0)
- cbp |= 1 << (5 - i);
- }
- return cbp;
-}
-void ff_h261_encode_mb(MpegEncContext * s,
- DCTELEM block[6][64],
- int motion_x, int motion_y)
-{
- H261Context * h = (H261Context *)s;
- int mvd, mv_diff_x, mv_diff_y, i, cbp;
- cbp = 63; // avoid warning
- mvd = 0;
-
- h->current_mba++;
- h->mtype = 0;
-
- if (!s->mb_intra){
- /* compute cbp */
- cbp= get_cbp(s, block);
-
- /* mvd indicates if this block is motion compensated */
- mvd = motion_x | motion_y;
-
- if((cbp | mvd | s->dquant ) == 0) {
- /* skip macroblock */
- s->skip_count++;
- h->current_mv_x=0;
- h->current_mv_y=0;
- return;
- }
- }
-
- /* MB is not skipped, encode MBA */
- put_bits(&s->pb, h261_mba_bits[(h->current_mba-h->previous_mba)-1], h261_mba_code[(h->current_mba-h->previous_mba)-1]);
-
- /* calculate MTYPE */
- if(!s->mb_intra){
- h->mtype++;
-
- if(mvd || s->loop_filter)
- h->mtype+=3;
- if(s->loop_filter)
- h->mtype+=3;
- if(cbp || s->dquant)
- h->mtype++;
- assert(h->mtype > 1);
- }
-
- if(s->dquant)
- h->mtype++;
-
- put_bits(&s->pb, h261_mtype_bits[h->mtype], h261_mtype_code[h->mtype]);
-
- h->mtype = h261_mtype_map[h->mtype];
-
- if(IS_QUANT(h->mtype)){
- ff_set_qscale(s,s->qscale+s->dquant);
- put_bits(&s->pb, 5, s->qscale);
- }
-
- if(IS_16X16(h->mtype)){
- mv_diff_x = (motion_x >> 1) - h->current_mv_x;
- mv_diff_y = (motion_y >> 1) - h->current_mv_y;
- h->current_mv_x = (motion_x >> 1);
- h->current_mv_y = (motion_y >> 1);
- h261_encode_motion(h,mv_diff_x);
- h261_encode_motion(h,mv_diff_y);
- }
-
- h->previous_mba = h->current_mba;
-
- if(HAS_CBP(h->mtype)){
- assert(cbp>0);
- put_bits(&s->pb,h261_cbp_tab[cbp-1][1],h261_cbp_tab[cbp-1][0]);
- }
- for(i=0; i<6; i++) {
- /* encode each block */
- h261_encode_block(h, block[i], i);
- }
-
- if ( ( h->current_mba == 11 ) || ( h->current_mba == 22 ) || ( h->current_mba == 33 ) || ( !IS_16X16 ( h->mtype ) )){
- h->current_mv_x=0;
- h->current_mv_y=0;
- }
-}
-
-void ff_h261_encode_init(MpegEncContext *s){
- static int done = 0;
-
- if (!done) {
- done = 1;
- init_rl(&h261_rl_tcoeff, 1);
- }
-
- 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 h261_encode_block(H261Context * h, DCTELEM * block, int n){
- MpegEncContext * const s = &h->s;
- int level, run, last, i, j, last_index, last_non_zero, sign, slevel, code;
- RLTable *rl;
-
- rl = &h261_rl_tcoeff;
- if (s->mb_intra) {
- /* 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)
- put_bits(&s->pb, 8, 0xff);
- else
- put_bits(&s->pb, 8, level);
- i = 1;
- } else if((block[0]==1 || block[0] == -1) && (s->block_last_index[n] > -1)){
- //special case
- put_bits(&s->pb,2,block[0]>0 ? 2 : 3 );
- i = 1;
- } else {
- i = 0;
- }
-
- /* 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, 0 /*no last in H.261, EOB is used*/, run, level);
- if(run==0 && level < 16)
- code+=1;
- put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
- if (code == rl->n) {
- put_bits(&s->pb, 6, run);
- assert(slevel != 0);
- assert(level <= 127);
- put_bits(&s->pb, 8, slevel & 0xff);
- } else {
- put_bits(&s->pb, 1, sign);
- }
- last_non_zero = i;
- }
- }
- if(last_index > -1){
- put_bits(&s->pb, rl->table_vlc[0][1], rl->table_vlc[0][0]);// END OF BLOCK
- }
-}
-
-/***********************************************/
-/* decoding */
-
-static VLC h261_mba_vlc;
-static VLC h261_mtype_vlc;
-static VLC h261_mv_vlc;
-static VLC h261_cbp_vlc;
-
-static void h261_decode_init_vlc(H261Context *h){
- static int done = 0;
-
- if(!done){
- done = 1;
- init_vlc(&h261_mba_vlc, H261_MBA_VLC_BITS, 35,
- h261_mba_bits, 1, 1,
- h261_mba_code, 1, 1, 1);
- init_vlc(&h261_mtype_vlc, H261_MTYPE_VLC_BITS, 10,
- h261_mtype_bits, 1, 1,
- h261_mtype_code, 1, 1, 1);
- init_vlc(&h261_mv_vlc, H261_MV_VLC_BITS, 17,
- &h261_mv_tab[0][1], 2, 1,
- &h261_mv_tab[0][0], 2, 1, 1);
- init_vlc(&h261_cbp_vlc, H261_CBP_VLC_BITS, 63,
- &h261_cbp_tab[0][1], 2, 1,
- &h261_cbp_tab[0][0], 2, 1, 1);
- init_rl(&h261_rl_tcoeff, 1);
- init_vlc_rl(&h261_rl_tcoeff, 1);
- }
-}
-
-static int h261_decode_init(AVCodecContext *avctx){
- H261Context *h= avctx->priv_data;
- MpegEncContext * const s = &h->s;
-
- // set defaults
- MPV_decode_defaults(s);
- s->avctx = avctx;
-
- s->width = s->avctx->coded_width;
- s->height = s->avctx->coded_height;
- s->codec_id = s->avctx->codec->id;
-
- s->out_format = FMT_H261;
- s->low_delay= 1;
- avctx->pix_fmt= PIX_FMT_YUV420P;
-
- s->codec_id= avctx->codec->id;
-
- h261_decode_init_vlc(h);
-
- h->gob_start_code_skipped = 0;
-
- return 0;
-}
-
-/**
- * decodes the group of blocks header or slice header.
- * @return <0 if an error occured
- */
-static int h261_decode_gob_header(H261Context *h){
- unsigned int val;
- MpegEncContext * const s = &h->s;
-
- if ( !h->gob_start_code_skipped ){
- /* Check for GOB Start Code */
- val = show_bits(&s->gb, 15);
- if(val)
- return -1;
-
- /* We have a GBSC */
- skip_bits(&s->gb, 16);
- }
-
- h->gob_start_code_skipped = 0;
-
- h->gob_number = get_bits(&s->gb, 4); /* GN */
- s->qscale = get_bits(&s->gb, 5); /* GQUANT */
-
- /* Check if gob_number is valid */
- if (s->mb_height==18){ //cif
- if ((h->gob_number<=0) || (h->gob_number>12))
- return -1;
- }
- else{ //qcif
- if ((h->gob_number!=1) && (h->gob_number!=3) && (h->gob_number!=5))
- return -1;
- }
-
- /* GEI */
- while (get_bits1(&s->gb) != 0) {
- skip_bits(&s->gb, 8);
- }
-
- if(s->qscale==0)
- return -1;
-
- // For the first transmitted macroblock in a GOB, MBA is the absolute address. For
- // subsequent macroblocks, MBA is the difference between the absolute addresses of
- // the macroblock and the last transmitted macroblock.
- h->current_mba = 0;
- h->mba_diff = 0;
-
- return 0;
-}
-
-/**
- * decodes the group of blocks / video packet header.
- * @return <0 if no resync found
- */
-static int ff_h261_resync(H261Context *h){
- MpegEncContext * const s = &h->s;
- int left, ret;
-
- if ( h->gob_start_code_skipped ){
- ret= h261_decode_gob_header(h);
- if(ret>=0)
- return 0;
- }
- else{
- if(show_bits(&s->gb, 15)==0){
- ret= h261_decode_gob_header(h);
- if(ret>=0)
- return 0;
- }
- //ok, its not where its 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>15+1+4+5; left-=8){
- if(show_bits(&s->gb, 15)==0){
- GetBitContext bak= s->gb;
-
- ret= h261_decode_gob_header(h);
- if(ret>=0)
- return 0;
-
- s->gb= bak;
- }
- skip_bits(&s->gb, 8);
- }
- }
-
- return -1;
-}
-
-/**
- * decodes skipped macroblocks
- * @return 0
- */
-static int h261_decode_mb_skipped(H261Context *h, int mba1, int mba2 )
-{
- MpegEncContext * const s = &h->s;
- int i;
-
- s->mb_intra = 0;
-
- for(i=mba1; i<mba2; i++){
- int j, xy;
-
- s->mb_x= ((h->gob_number-1) % 2) * 11 + i % 11;
- s->mb_y= ((h->gob_number-1) / 2) * 3 + i / 11;
- xy = s->mb_x + s->mb_y * s->mb_stride;
- ff_init_block_index(s);
- ff_update_block_index(s);
-
- for(j=0;j<6;j++)
- s->block_last_index[j] = -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 = 1;
- h->mtype &= ~MB_TYPE_H261_FIL;
-
- MPV_decode_mb(s, s->block);
- }
-
- return 0;
-}
-
-static int decode_mv_component(GetBitContext *gb, int v){
- int mv_diff = get_vlc2(gb, h261_mv_vlc.table, H261_MV_VLC_BITS, 2);
-
- /* check if mv_diff is valid */
- if ( mv_diff < 0 )
- return v;
-
- mv_diff = mvmap[mv_diff];
-
- if(mv_diff && !get_bits1(gb))
- mv_diff= -mv_diff;
-
- v += mv_diff;
- if (v <=-16) v+= 32;
- else if(v >= 16) v-= 32;
-
- return v;
-}
-
-static int h261_decode_mb(H261Context *h){
- MpegEncContext * const s = &h->s;
- int i, cbp, xy;
-
- cbp = 63;
- // Read mba
- do{
- h->mba_diff = get_vlc2(&s->gb, h261_mba_vlc.table, H261_MBA_VLC_BITS, 2);
-
- /* Check for slice end */
- /* NOTE: GOB can be empty (no MB data) or exist only of MBA_stuffing */
- if (h->mba_diff == MBA_STARTCODE){ // start code
- h->gob_start_code_skipped = 1;
- return SLICE_END;
- }
- }
- while( h->mba_diff == MBA_STUFFING ); // stuffing
-
- if ( h->mba_diff < 0 ){
- if ( get_bits_count(&s->gb) + 7 >= s->gb.size_in_bits )
- return SLICE_END;
-
- av_log(s->avctx, AV_LOG_ERROR, "illegal mba at %d %d\n", s->mb_x, s->mb_y);
- return SLICE_ERROR;
- }
-
- h->mba_diff += 1;
- h->current_mba += h->mba_diff;
-
- if ( h->current_mba > MBA_STUFFING )
- return SLICE_ERROR;
-
- s->mb_x= ((h->gob_number-1) % 2) * 11 + ((h->current_mba-1) % 11);
- s->mb_y= ((h->gob_number-1) / 2) * 3 + ((h->current_mba-1) / 11);
- xy = s->mb_x + s->mb_y * s->mb_stride;
- ff_init_block_index(s);
- ff_update_block_index(s);
-
- // Read mtype
- h->mtype = get_vlc2(&s->gb, h261_mtype_vlc.table, H261_MTYPE_VLC_BITS, 2);
- h->mtype = h261_mtype_map[h->mtype];
-
- // Read mquant
- if ( IS_QUANT ( h->mtype ) ){
- ff_set_qscale(s, get_bits(&s->gb, 5));
- }
-
- s->mb_intra = IS_INTRA4x4(h->mtype);
-
- // Read mv
- if ( IS_16X16 ( h->mtype ) ){
- // Motion vector data is included for all MC macroblocks. MVD is obtained from the macroblock vector by subtracting the
- // vector of the preceding macroblock. For this calculation the vector of the preceding macroblock is regarded as zero in the
- // following three situations:
- // 1) evaluating MVD for macroblocks 1, 12 and 23;
- // 2) evaluating MVD for macroblocks in which MBA does not represent a difference of 1;
- // 3) MTYPE of the previous macroblock was not MC.
- if ( ( h->current_mba == 1 ) || ( h->current_mba == 12 ) || ( h->current_mba == 23 ) ||
- ( h->mba_diff != 1))
- {
- h->current_mv_x = 0;
- h->current_mv_y = 0;
- }
-
- h->current_mv_x= decode_mv_component(&s->gb, h->current_mv_x);
- h->current_mv_y= decode_mv_component(&s->gb, h->current_mv_y);
- }else{
- h->current_mv_x = 0;
- h->current_mv_y = 0;
- }
-
- // Read cbp
- if ( HAS_CBP( h->mtype ) ){
- cbp = get_vlc2(&s->gb, h261_cbp_vlc.table, H261_CBP_VLC_BITS, 2) + 1;
- }
-
- if(s->mb_intra){
- s->current_picture.mb_type[xy]= MB_TYPE_INTRA;
- goto intra;
- }
-
- //set motion vectors
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_16X16;
- s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0;
- s->mv[0][0][0] = h->current_mv_x * 2;//gets divided by 2 in motion compensation
- s->mv[0][0][1] = h->current_mv_y * 2;
-
-intra:
- /* decode each block */
- if(s->mb_intra || HAS_CBP(h->mtype)){
- s->dsp.clear_blocks(s->block[0]);
- for (i = 0; i < 6; i++) {
- if (h261_decode_block(h, s->block[i], i, cbp&32) < 0){
- return SLICE_ERROR;
- }
- cbp+=cbp;
- }
- }else{
- for (i = 0; i < 6; i++)
- s->block_last_index[i]= -1;
- }
-
- MPV_decode_mb(s, s->block);
-
- return SLICE_OK;
-}
-
-/**
- * decodes a macroblock
- * @return <0 if an error occured
- */
-static int h261_decode_block(H261Context * h, DCTELEM * block,
- int n, int coded)
-{
- MpegEncContext * const s = &h->s;
- int code, level, i, j, run;
- RLTable *rl = &h261_rl_tcoeff;
- const uint8_t *scan_table;
-
- // For the variable length encoding there are two code tables, one being used for
- // the first transmitted LEVEL in INTER, INTER+MC and INTER+MC+FIL blocks, the second
- // for all other LEVELs except the first one in INTRA blocks which is fixed length
- // coded with 8 bits.
- // NOTE: the two code tables only differ in one VLC so we handle that manually.
- scan_table = s->intra_scantable.permutated;
- if (s->mb_intra){
- /* DC coef */
- level = get_bits(&s->gb, 8);
- // 0 (00000000b) and -128 (10000000b) are FORBIDDEN
- 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);
- return -1;
- }
- // The code 1000 0000 is not used, the reconstruction level of 1024 being coded as 1111 1111.
- if (level == 255)
- level = 128;
- block[0] = level;
- i = 1;
- }else if(coded){
- // Run Level Code
- // EOB Not possible for first level when cbp is available (that's why the table is different)
- // 0 1 1s
- // * * 0*
- int check = show_bits(&s->gb, 2);
- i = 0;
- if ( check & 0x2 ){
- skip_bits(&s->gb, 2);
- block[0] = ( check & 0x1 ) ? -1 : 1;
- i = 1;
- }
- }else{
- i = 0;
- }
- if(!coded){
- s->block_last_index[n] = i - 1;
- return 0;
- }
- for(;;){
- code = get_vlc2(&s->gb, rl->vlc.table, TCOEFF_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 */
- // The remaining combinations of (run, level) are encoded with a 20-bit word consisting of 6 bits escape, 6 bits run and 8 bits level.
- run = get_bits(&s->gb, 6);
- level = get_sbits(&s->gb, 8);
- }else if(code == 0){
- break;
- }else{
- run = rl->table_run[code];
- level = rl->table_level[code];
- if (get_bits1(&s->gb))
- level = -level;
- }
- i += run;
- if (i >= 64){
- av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d\n", s->mb_x, s->mb_y);
- return -1;
- }
- j = scan_table[i];
- block[j] = level;
- i++;
- }
- s->block_last_index[n] = i-1;
- return 0;
-}
-
-/**
- * decodes the H261 picture header.
- * @return <0 if no startcode found
- */
-static int h261_decode_picture_header(H261Context *h){
- MpegEncContext * const s = &h->s;
- int format, i;
- uint32_t startcode= 0;
-
- for(i= s->gb.size_in_bits - get_bits_count(&s->gb); i>24; i-=1){
- startcode = ((startcode << 1) | get_bits(&s->gb, 1)) & 0x000FFFFF;
-
- if(startcode == 0x10)
- break;
- }
-
- if (startcode != 0x10){
- av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
- return -1;
- }
-
- /* temporal reference */
- i= get_bits(&s->gb, 5); /* picture timestamp */
- if(i < (s->picture_number&31))
- i += 32;
- s->picture_number = (s->picture_number&~31) + i;
-
- s->avctx->time_base= (AVRational){1001, 30000};
- s->current_picture.pts= s->picture_number;
-
-
- /* PTYPE starts here */
- skip_bits1(&s->gb); /* split screen off */
- skip_bits1(&s->gb); /* camera off */
- skip_bits1(&s->gb); /* freeze picture release off */
-
- format = get_bits1(&s->gb);
-
- //only 2 formats possible
- if (format == 0){//QCIF
- s->width = 176;
- s->height = 144;
- s->mb_width = 11;
- s->mb_height = 9;
- }else{//CIF
- s->width = 352;
- s->height = 288;
- s->mb_width = 22;
- s->mb_height = 18;
- }
-
- s->mb_num = s->mb_width * s->mb_height;
-
- skip_bits1(&s->gb); /* still image mode off */
- skip_bits1(&s->gb); /* Reserved */
-
- /* PEI */
- while (get_bits1(&s->gb) != 0){
- skip_bits(&s->gb, 8);
- }
-
- // h261 has no I-FRAMES, but if we pass I_TYPE for the first frame, the codec crashes if it does
- // not contain all I-blocks (e.g. when a packet is lost)
- s->pict_type = P_TYPE;
-
- h->gob_number = 0;
- return 0;
-}
-
-static int h261_decode_gob(H261Context *h){
- MpegEncContext * const s = &h->s;
-
- ff_set_qscale(s, s->qscale);
-
- /* decode mb's */
- while(h->current_mba <= MBA_STUFFING)
- {
- int ret;
- /* DCT & quantize */
- ret= h261_decode_mb(h);
- if(ret<0){
- if(ret==SLICE_END){
- h261_decode_mb_skipped(h, h->current_mba, 33);
- return 0;
- }
- av_log(s->avctx, AV_LOG_ERROR, "Error at MB: %d\n", s->mb_x + s->mb_y*s->mb_stride);
- return -1;
- }
-
- h261_decode_mb_skipped(h, h->current_mba-h->mba_diff, h->current_mba-1);
- }
-
- return -1;
-}
-
-#ifdef CONFIG_H261_PARSER
-static int h261_find_frame_end(ParseContext *pc, AVCodecContext* avctx, const uint8_t *buf, int buf_size){
- int vop_found, i, j;
- uint32_t state;
-
- vop_found= pc->frame_start_found;
- state= pc->state;
-
- for(i=0; i<buf_size && !vop_found; i++){
- state= (state<<8) | buf[i];
- for(j=0; j<8; j++){
- if(((state>>j)&0xFFFFF) == 0x00010){
- vop_found=1;
- break;
- }
- }
- }
- if(vop_found){
- for(; i<buf_size; i++){
- state= (state<<8) | buf[i];
- for(j=0; j<8; j++){
- if(((state>>j)&0xFFFFF) == 0x00010){
- pc->frame_start_found=0;
- pc->state= state>>(2*8);
- return i-1;
- }
- }
- }
- }
-
- pc->frame_start_found= vop_found;
- pc->state= state;
- return END_NOT_FOUND;
-}
-
-static int h261_parse(AVCodecParserContext *s,
- AVCodecContext *avctx,
- uint8_t **poutbuf, int *poutbuf_size,
- const uint8_t *buf, int buf_size)
-{
- ParseContext *pc = s->priv_data;
- int next;
-
- next= h261_find_frame_end(pc,avctx, buf, buf_size);
- if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
- *poutbuf = NULL;
- *poutbuf_size = 0;
- return buf_size;
- }
- *poutbuf = (uint8_t *)buf;
- *poutbuf_size = buf_size;
- return next;
-}
-#endif
-
-/**
- * returns the number of bytes consumed for building the current frame
- */
-static int get_consumed_bytes(MpegEncContext *s, int buf_size){
- int pos= get_bits_count(&s->gb)>>3;
- if(pos==0) pos=1; //avoid infinite loops (i doubt thats needed but ...)
- if(pos+10>buf_size) pos=buf_size; // oops ;)
-
- return pos;
-}
-
-static int h261_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- H261Context *h= avctx->priv_data;
- MpegEncContext *s = &h->s;
- int ret;
- AVFrame *pict = data;
-
-#ifdef DEBUG
- av_log(avctx, AV_LOG_DEBUG, "*****frame %d size=%d\n", avctx->frame_number, buf_size);
- av_log(avctx, AV_LOG_DEBUG, "bytes=%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]);
-#endif
- s->flags= avctx->flags;
- s->flags2= avctx->flags2;
-
- h->gob_start_code_skipped=0;
-
-retry:
-
- init_get_bits(&s->gb, buf, buf_size*8);
-
- if(!s->context_initialized){
- if (MPV_common_init(s) < 0) //we need the idct permutaton for reading a custom matrix
- return -1;
- }
-
- //we need to set current_picture_ptr before reading the header, otherwise we cant store anyting im there
- if(s->current_picture_ptr==NULL || s->current_picture_ptr->data[0]){
- int i= ff_find_unused_picture(s, 0);
- s->current_picture_ptr= &s->picture[i];
- }
-
- ret = h261_decode_picture_header(h);
-
- /* skip if the header was thrashed */
- if (ret < 0){
- av_log(s->avctx, AV_LOG_ERROR, "header damaged\n");
- return -1;
- }
-
- if (s->width != avctx->coded_width || s->height != avctx->coded_height){
- ParseContext pc= s->parse_context; //FIXME move these demuxng hack to avformat
- s->parse_context.buffer=0;
- MPV_common_end(s);
- s->parse_context= pc;
- }
- if (!s->context_initialized) {
- avcodec_set_dimensions(avctx, s->width, s->height);
-
- goto retry;
- }
-
- // for hurry_up==5
- s->current_picture.pict_type= s->pict_type;
- s->current_picture.key_frame= s->pict_type == I_TYPE;
-
- /* skip everything if we are in a hurry>=5 */
- if(avctx->hurry_up>=5) return get_consumed_bytes(s, buf_size);
- if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==B_TYPE)
- ||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=I_TYPE)
- || avctx->skip_frame >= AVDISCARD_ALL)
- return get_consumed_bytes(s, buf_size);
-
- if(MPV_frame_start(s, avctx) < 0)
- return -1;
-
- ff_er_frame_start(s);
-
- /* decode each macroblock */
- s->mb_x=0;
- s->mb_y=0;
-
- while(h->gob_number < (s->mb_height==18 ? 12 : 5)){
- if(ff_h261_resync(h)<0)
- break;
- h261_decode_gob(h);
- }
- MPV_frame_end(s);
-
-assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type);
-assert(s->current_picture.pict_type == s->pict_type);
- *pict= *(AVFrame*)s->current_picture_ptr;
- ff_print_debug_info(s, pict);
-
- *data_size = sizeof(AVFrame);
-
- return get_consumed_bytes(s, buf_size);
-}
-
-static int h261_decode_end(AVCodecContext *avctx)
-{
- H261Context *h= avctx->priv_data;
- MpegEncContext *s = &h->s;
-
- MPV_common_end(s);
- return 0;
-}
-
-#ifdef CONFIG_ENCODERS
-AVCodec h261_encoder = {
- "h261",
- CODEC_TYPE_VIDEO,
- CODEC_ID_H261,
- sizeof(H261Context),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
- .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1},
-};
-#endif
-
-AVCodec h261_decoder = {
- "h261",
- CODEC_TYPE_VIDEO,
- CODEC_ID_H261,
- sizeof(H261Context),
- h261_decode_init,
- NULL,
- h261_decode_end,
- h261_decode_frame,
- CODEC_CAP_DR1,
-};
-
-#ifdef CONFIG_H261_PARSER
-AVCodecParser h261_parser = {
- { CODEC_ID_H261 },
- sizeof(ParseContext),
- NULL,
- h261_parse,
- ff_parse_close,
-};
-#endif
diff --git a/src/libffmpeg/libavcodec/h263.c b/src/libffmpeg/libavcodec/h263.c
deleted file mode 100644
index 27b66a0c8..000000000
--- a/src/libffmpeg/libavcodec/h263.c
+++ /dev/null
@@ -1,6312 +0,0 @@
-/*
- * H263/MPEG4 backend for ffmpeg encoder and decoder
- * Copyright (c) 2000,2001 Fabrice Bellard.
- * H263+ support.
- * Copyright (c) 2001 Juan J. Sierralta P.
- * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * ac prediction encoding, b-frame support, error resilience, optimizations,
- * qpel decoding, gmc decoding, interlaced decoding,
- * by Michael Niedermayer <michaelni@gmx.at>
- */
-
-/**
- * @file h263.c
- * h263/mpeg4 codec.
- */
-
-//#define DEBUG
-#include <limits.h>
-
-#include "common.h"
-#include "dsputil.h"
-#include "avcodec.h"
-#include "mpegvideo.h"
-#include "h263data.h"
-#include "mpeg4data.h"
-
-//#undef NDEBUG
-//#include <assert.h>
-
-#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
-
-#ifdef CONFIG_ENCODERS
-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);
-#endif
-
-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);
-#ifdef CONFIG_ENCODERS
-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);
-#endif //CONFIG_ENCODERS
-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);
-
-#ifdef 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_MV*2+1]= NULL;
-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
-
-#if 0 //3IV1 is quite rare and it slows things down a tiny bit
-#define IS_3IV1 s->codec_tag == ff_get_fourcc("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;
-}
-
-#ifdef 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 == 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= clip(1, div, 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 = pbBufPtr(&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_bits(&s->pb, 8, temp_ref & 0xff); /* 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 == 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 == 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_bits(&s->pb, 2, (temp_ref>>8)&3);
- }
-
- /* 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 == 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 == 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(j<block_last_index) rate+= s->intra_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;
- level-= 64;
-
- 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; i<s->mb_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] ]= 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; i<s->mb_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; i<s->mb_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== 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; i<s->mb_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; i<s->mb_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; i<s->mb_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)(sizeof(s->direct_scale_mv[0])/sizeof(int16_t)))
-#define tab_bias (tab_size/2)
-
-void ff_mpeg4_init_direct_mv(MpegEncContext *s){
- int i;
- for(i=0; i<tab_size; i++){
- s->direct_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= s->pp_time;
- uint16_t time_pb= s->pb_time;
- 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;
- //FIXME a lot of that is only needed for !low_delay
- const int wrap = s->b8_stride;
- const int xy = s->block_index[0];
-
- s->current_picture.mbskip_table[mb_xy]= s->mb_skipped;
-
- if(s->mv_type != MV_TYPE_8X8){
- int motion_x, motion_y;
- if (s->mb_intra) {
- motion_x = 0;
- motion_y = 0;
- } else if (s->mv_type == MV_TYPE_16X16) {
- motion_x = s->mv[0][0][0];
- motion_y = s->mv[0][0][1];
- } else /*if (s->mv_type == MV_TYPE_FIELD)*/ {
- int i;
- motion_x = s->mv[0][0][0] + s->mv[0][1][0];
- motion_y = s->mv[0][0][1] + s->mv[0][1][1];
- motion_x = (motion_x>>1) | (motion_x&1);
- for(i=0; i<2; i++){
- 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];
- }
-
- /* no update if 8X8 because it has been done during parsing */
- s->current_picture.motion_val[0][xy][0] = motion_x;
- s->current_picture.motion_val[0][xy][1] = motion_y;
- s->current_picture.motion_val[0][xy + 1][0] = motion_x;
- s->current_picture.motion_val[0][xy + 1][1] = motion_y;
- s->current_picture.motion_val[0][xy + wrap][0] = motion_x;
- s->current_picture.motion_val[0][xy + wrap][1] = motion_y;
- s->current_picture.motion_val[0][xy + 1 + wrap][0] = motion_x;
- s->current_picture.motion_val[0][xy + 1 + wrap][1] = motion_y;
- }
-
- if(s->encoding){ //FIXME encoding MUST be cleaned up
- if (s->mv_type == MV_TYPE_8X8)
- s->current_picture.mb_type[mb_xy]= MB_TYPE_L0 | MB_TYPE_8x8;
- else if(s->mb_intra)
- s->current_picture.mb_type[mb_xy]= MB_TYPE_INTRA;
- else
- s->current_picture.mb_type[mb_xy]= MB_TYPE_L0 | MB_TYPE_16x16;
- }
-}
-
-#ifdef 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)>>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;
- memset(s->block[i], 0, sizeof(DCTELEM)*64);
- }
- }
- }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;
- memset(s->block[i], 0, sizeof(DCTELEM)*64);
- }
- }
- }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);
- }
- }
- }
-}
-
-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!=B_TYPE ? &s->tex_pb : &s->pb;
- PutBitContext * const dc_pb = s->data_partitioning && s->pict_type!=I_TYPE ? &s->pb2 : &s->pb;
- const int interleaved_stats= (s->flags&CODEC_FLAG_PASS1) && !s->data_partitioning ? 1 : 0;
- const int dquant_code[5]= {1,0,9,2,3};
-
- // printf("**mb x=%d y=%d\n", s->mb_x, s->mb_y);
- if (!s->mb_intra) {
- int i, cbp;
-
- if(s->pict_type==B_TYPE){
- static const int mb_type_table[8]= {-1, 2, 3, 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==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; i<s->max_b_frames; i++){
- uint8_t *b_pic;
- int diff;
- Picture *pic= s->reordered_input_picture[i+1];
-
- if(pic==NULL || pic->pict_type!=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++;
- }
- } 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 == 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);
- }
-}
-
-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);
- const int dquant_code[5]= {1,0,9,2,3};
-
- //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 == 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;
- const int uvlinesize= s->uvlinesize;
- const int xy = s->mb_y * s->mb_stride + s->mb_x;
- uint8_t *dest_y = s->dest[0];
- uint8_t *dest_cb= s->dest[1];
- uint8_t *dest_cr= s->dest[2];
-
-// if(s->pict_type==B_TYPE && !s->readable) return;
-
- /*
- Diag Top
- Left Center
- */
- if(!IS_SKIP(s->current_picture.mb_type[xy])){
- qp_c= s->qscale;
- s->dsp.h263_v_loop_filter(dest_y+8*linesize , linesize, qp_c);
- s->dsp.h263_v_loop_filter(dest_y+8*linesize+8, linesize, qp_c);
- }else
- qp_c= 0;
-
- if(s->mb_y){
- int qp_dt, qp_t, qp_tc;
-
- if(IS_SKIP(s->current_picture.mb_type[xy-s->mb_stride]))
- qp_t=0;
- else
- qp_t= s->current_picture.qscale_table[xy-s->mb_stride];
-
- if(qp_c)
- qp_tc= qp_c;
- else
- qp_tc= qp_t;
-
- if(qp_tc){
- const int chroma_qp= s->chroma_qscale_table[qp_tc];
- s->dsp.h263_v_loop_filter(dest_y , linesize, qp_tc);
- s->dsp.h263_v_loop_filter(dest_y+8, linesize, qp_tc);
-
- s->dsp.h263_v_loop_filter(dest_cb , uvlinesize, chroma_qp);
- s->dsp.h263_v_loop_filter(dest_cr , uvlinesize, chroma_qp);
- }
-
- if(qp_t)
- s->dsp.h263_h_loop_filter(dest_y-8*linesize+8 , linesize, qp_t);
-
- if(s->mb_x){
- if(qp_t || IS_SKIP(s->current_picture.mb_type[xy-1-s->mb_stride]))
- qp_dt= qp_t;
- else
- qp_dt= s->current_picture.qscale_table[xy-1-s->mb_stride];
-
- if(qp_dt){
- const int chroma_qp= s->chroma_qscale_table[qp_dt];
- s->dsp.h263_h_loop_filter(dest_y -8*linesize , linesize, qp_dt);
- s->dsp.h263_h_loop_filter(dest_cb-8*uvlinesize, uvlinesize, chroma_qp);
- s->dsp.h263_h_loop_filter(dest_cr-8*uvlinesize, uvlinesize, chroma_qp);
- }
- }
- }
-
- if(qp_c){
- s->dsp.h263_h_loop_filter(dest_y +8, linesize, qp_c);
- if(s->mb_y + 1 == s->mb_height)
- s->dsp.h263_h_loop_filter(dest_y+8*linesize+8, linesize, qp_c);
- }
-
- if(s->mb_x){
- int qp_lc;
- if(qp_c || IS_SKIP(s->current_picture.mb_type[xy-1]))
- qp_lc= qp_c;
- else
- qp_lc= s->current_picture.qscale_table[xy-1];
-
- if(qp_lc){
- s->dsp.h263_h_loop_filter(dest_y, linesize, qp_lc);
- if(s->mb_y + 1 == s->mb_height){
- const int chroma_qp= s->chroma_qscale_table[qp_lc];
- s->dsp.h263_h_loop_filter(dest_y +8* linesize, linesize, qp_lc);
- s->dsp.h263_h_loop_filter(dest_cb , uvlinesize, chroma_qp);
- s->dsp.h263_h_loop_filter(dest_cr , uvlinesize, chroma_qp);
- }
- }
- }
-}
-
-#ifdef CONFIG_ENCODERS
-static int h263_pred_dc(MpegEncContext * s, int n, int16_t **dc_val_ptr)
-{
- int x, y, wrap, a, c, pred_dc, scale;
- 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];
- scale = s->y_dc_scale;
- } else {
- x = s->mb_x;
- y = s->mb_y;
- wrap = s->mb_stride;
- dc_val = s->dc_val[n - 4 + 1];
- scale = s->c_dc_scale;
- }
- /* 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;
- }
- pred_dc = 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 */
- //pred_dc = (pred_dc + (scale >> 1)) / scale;
- *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)
-{
- int x, y, wrap, a, c, pred_dc, scale, i;
- int16_t *dc_val, *ac_val, *ac_val1;
-
- /* find prediction */
- if (n < 4) {
- x = 2 * s->mb_x + (n & 1);
- y = 2 * s->mb_y + (n>> 1);
- wrap = s->b8_stride;
- dc_val = s->dc_val[0];
- ac_val = s->ac_val[0][0];
- scale = s->y_dc_scale;
- } else {
- x = s->mb_x;
- y = s->mb_y;
- wrap = s->mb_stride;
- dc_val = s->dc_val[n - 4 + 1];
- ac_val = s->ac_val[n - 4 + 1][0];
- scale = s->c_dc_scale;
- }
-
- ac_val += ((y) * wrap + (x)) * 16;
- ac_val1 = ac_val;
-
- /* 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;
- }
-
- if (s->ac_pred) {
- pred_dc = 1024;
- if (s->h263_aic_dir) {
- /* left prediction */
- if (a != 1024) {
- ac_val -= 16;
- for(i=1;i<8;i++) {
- block[s->dsp.idct_permutation[i<<3]] += ac_val[i];
- }
- pred_dc = a;
- }
- } else {
- /* top prediction */
- if (c != 1024) {
- ac_val -= 16 * wrap;
- for(i=1;i<8;i++) {
- block[s->dsp.idct_permutation[i ]] += ac_val[i + 8];
- }
- pred_dc = c;
- }
- }
- } else {
- /* 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 */
- block[0]=block[0]*scale + pred_dc;
-
- if (block[0] < 0)
- block[0] = 0;
- else
- block[0] |= 1;
-
- /* Update AC/DC tables */
- dc_val[(x) + (y) * wrap] = block[0];
-
- /* 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 ]];
-}
-
-int16_t *h263_pred_motion(MpegEncContext * s, int block, int dir,
- int *px, int *py)
-{
- int wrap;
- int16_t *A, *B, *C, (*mot_val)[2];
- static const int off[4]= {2, 1, 1, -1};
-
- wrap = s->b8_stride;
- mot_val = s->current_picture.motion_val[dir] + s->block_index[block];
-
- A = mot_val[ - 1];
- /* special case for first (slice) line */
- if (s->first_slice_line && block<3) {
- // we can't just change some MVs to simulate that as we need them for the B frames (and ME)
- // and if we ever support non rectangular objects than we need to do a few ifs here anyway :(
- if(block==0){ //most common case
- if(s->mb_x == s->resync_mb_x){ //rare
- *px= *py = 0;
- }else if(s->mb_x + 1 == s->resync_mb_x && s->h263_pred){ //rare
- C = mot_val[off[block] - wrap];
- if(s->mb_x==0){
- *px = C[0];
- *py = C[1];
- }else{
- *px = mid_pred(A[0], 0, C[0]);
- *py = mid_pred(A[1], 0, C[1]);
- }
- }else{
- *px = A[0];
- *py = A[1];
- }
- }else if(block==1){
- if(s->mb_x + 1 == s->resync_mb_x && s->h263_pred){ //rare
- C = mot_val[off[block] - wrap];
- *px = mid_pred(A[0], 0, C[0]);
- *py = mid_pred(A[1], 0, C[1]);
- }else{
- *px = A[0];
- *py = A[1];
- }
- }else{ /* block==2*/
- B = mot_val[ - wrap];
- C = mot_val[off[block] - wrap];
- if(s->mb_x == s->resync_mb_x) //rare
- A[0]=A[1]=0;
-
- *px = mid_pred(A[0], B[0], C[0]);
- *py = mid_pred(A[1], B[1], C[1]);
- }
- } else {
- B = mot_val[ - wrap];
- C = mot_val[off[block] - wrap];
- *px = mid_pred(A[0], B[0], C[0]);
- *py = mid_pred(A[1], B[1], C[1]);
- }
- return *mot_val;
-}
-
-#ifdef 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)>>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;
-
- if(mv_penalty==NULL)
- mv_penalty= av_mallocz( sizeof(uint8_t)*(MAX_FCODE+1)*(2*MAX_MV+1) );
-
- 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, range, code;
-
- bit_size = f_code - 1;
- range = 1 << bit_size;
-
- 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<<f_code); mv<(16<<f_code); mv++){
- fcode_tab[mv+MAX_MV]= f_code;
- }
- }
-
- for(mv=0; mv<MAX_MV*2+1; mv++){
- umv_fcode_tab[mv]= 1;
- }
-}
-#endif
-
-#ifdef CONFIG_ENCODERS
-
-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= 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;
-
- }
-}
-
-#endif //CONFIG_ENCODERS
-
-#ifdef CONFIG_ENCODERS
-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, 1);
- init_rl(&rl_intra, 1);
- init_rl(&rl_intra_aic, 1);
-
- 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_bits(&s->pb, 8, slevel & 0xff);
- else{
- put_bits(&s->pb, 8, 128);
- put_bits(&s->pb, 5, slevel & 0x1f);
- put_bits(&s->pb, 6, (slevel>>5)&0x3f);
- }
- }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_bits(&s->pb, 7, slevel & 0x7f);
- } else {
- /* 11-bit level */
- put_bits(&s->pb, 1, 1);
- put_bits(&s->pb, 1, last);
- put_bits(&s->pb, 6, run);
-
- put_bits(&s->pb, 11, slevel & 0x7ff);
- }
- }
- } else {
- put_bits(&s->pb, 1, sign);
- }
- last_non_zero = i;
- }
- }
-}
-#endif
-
-#ifdef CONFIG_ENCODERS
-
-/***************************************************/
-/**
- * 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<<length)-1);
-}
-
-/* must be called before writing the header */
-void ff_set_mpeg4_time(MpegEncContext * s, int picture_number){
- int time_div, time_mod;
-
- assert(s->current_picture_ptr->pts != AV_NOPTS_VALUE);
- s->time= s->current_picture_ptr->pts*s->avctx->time_base.num;
-
- time_div= s->time/s->avctx->time_base.den;
- time_mod= s->time%s->avctx->time_base.den;
-
- if(s->pict_type==B_TYPE){
- s->pb_time= s->pp_time - (s->last_non_b_time - s->time);
- assert(s->pb_time > 0 && s->pb_time < s->pp_time);
- ff_mpeg4_init_direct_mv(s);
- }else{
- s->last_time_base= s->time_base;
- s->time_base= time_div;
- s->pp_time= s->time - s->last_non_b_time;
- s->last_non_b_time= s->time;
- assert(picture_number==0 || s->pp_time > 0);
- }
-}
-
-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(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==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!=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 == P_TYPE
- || (s->pict_type == 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 != I_TYPE)
- put_bits(&s->pb, 3, s->f_code); /* fcode_for */
- if (s->pict_type == B_TYPE)
- put_bits(&s->pb, 3, s->b_code); /* fcode_back */
- // printf("****frame %d\n", picture_number);
-}
-
-#endif //CONFIG_ENCODERS
-
-/**
- * set qscale and update qscale dependant variables.
- */
-void ff_set_qscale(MpegEncContext * s, int qscale)
-{
- if (qscale < 1)
- qscale = 1;
- else if (qscale > 31)
- qscale = 31;
-
- s->qscale = qscale;
- s->chroma_qscale= s->chroma_qscale_table[qscale];
-
- s->y_dc_scale= s->y_dc_scale_table[ qscale ];
- s->c_dc_scale= s->c_dc_scale_table[ s->chroma_qscale ];
-}
-
-/**
- * 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_resilience>=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 ]];
-
-}
-
-#ifdef 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_bits(ac_pb, 12, slevel & 0xfff);
- 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;
- const RLTable *rl;
- 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;
- rl = &rl_intra;
- len_tab = uni_mpeg4_intra_rl_len;
- } else {
- if(last_index<0) return 0;
- i = 0;
- rl = &rl_inter;
- 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;
-
-void init_vlc_rl(RLTable *rl, int use_static)
-{
- int i, q;
-
- /* Return if static table is already initialized */
- if(use_static && rl->rl_vlc[0])
- return;
-
- init_vlc(&rl->vlc, 9, rl->n + 1,
- &rl->table_vlc[0][1], 4, 2,
- &rl->table_vlc[0][0], 4, 2, use_static);
-
-
- for(q=0; q<32; q++){
- int qmul= q*2;
- int qadd= (q-1)|1;
-
- if(q==0){
- qmul=1;
- qadd=0;
- }
- if(use_static)
- rl->rl_vlc[q]= av_mallocz_static(rl->vlc.table_size*sizeof(RL_VLC_ELEM));
- else
- rl->rl_vlc[q]= av_malloc(rl->vlc.table_size*sizeof(RL_VLC_ELEM));
- for(i=0; i<rl->vlc.table_size; i++){
- int code= rl->vlc.table[i][0];
- int len = rl->vlc.table[i][1];
- int level, run;
-
- if(len==0){ // illegal code
- run= 66;
- level= MAX_LEVEL;
- }else if(len<0){ //more bits needed
- run= 0;
- level= code;
- }else{
- if(code==rl->n){ //esc
- run= 66;
- level= 0;
- }else{
- run= rl->table_run [code] + 1;
- level= rl->table_level[code] * qmul + qadd;
- if(code >= rl->last) run+=192;
- }
- }
- rl->rl_vlc[q][i].len= len;
- rl->rl_vlc[q][i].level= level;
- rl->rl_vlc[q][i].run= run;
- }
- }
-}
-
-/* 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(&intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 9,
- intra_MCBPC_bits, 1, 1,
- intra_MCBPC_code, 1, 1, 1);
- init_vlc(&inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 28,
- inter_MCBPC_bits, 1, 1,
- inter_MCBPC_code, 1, 1, 1);
- init_vlc(&cbpy_vlc, CBPY_VLC_BITS, 16,
- &cbpy_tab[0][1], 2, 1,
- &cbpy_tab[0][0], 2, 1, 1);
- init_vlc(&mv_vlc, MV_VLC_BITS, 33,
- &mvtab[0][1], 2, 1,
- &mvtab[0][0], 2, 1, 1);
- init_rl(&rl_inter, 1);
- init_rl(&rl_intra, 1);
- init_rl(&rvlc_rl_inter, 1);
- init_rl(&rvlc_rl_intra, 1);
- init_rl(&rl_intra_aic, 1);
- init_vlc_rl(&rl_inter, 1);
- init_vlc_rl(&rl_intra, 1);
- init_vlc_rl(&rvlc_rl_inter, 1);
- init_vlc_rl(&rvlc_rl_intra, 1);
- init_vlc_rl(&rl_intra_aic, 1);
- init_vlc(&dc_lum, DC_VLC_BITS, 10 /* 13 */,
- &DCtab_lum[0][1], 2, 1,
- &DCtab_lum[0][0], 2, 1, 1);
- init_vlc(&dc_chrom, DC_VLC_BITS, 10 /* 13 */,
- &DCtab_chrom[0][1], 2, 1,
- &DCtab_chrom[0][0], 2, 1, 1);
- init_vlc(&sprite_trajectory, SPRITE_TRAJ_VLC_BITS, 15,
- &sprite_trajectory_tab[0][1], 4, 2,
- &sprite_trajectory_tab[0][0], 4, 2, 1);
- init_vlc(&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, 1);
- init_vlc(&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, 1);
- init_vlc(&cbpc_b_vlc, CBPC_B_VLC_BITS, 4,
- &cbpc_b_tab[0][1], 2, 1,
- &cbpc_b_tab[0][0], 2, 1, 1);
- }
-}
-
-/**
- * Get the GOB height based on picture height.
- */
-int ff_h263_get_gob_height(MpegEncContext *s){
- if (s->height <= 400)
- return 1;
- else if (s->height <= 800)
- return 2;
- 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 occured
- */
-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;i<n;i++)
- tab[i] = val;
-}
-
-#ifdef CONFIG_ENCODERS
-
-void ff_mpeg4_init_partitions(MpegEncContext *s)
-{
- uint8_t *start= pbBufPtr(&s->pb);
- uint8_t *end= s->pb.buf_end;
- int size= end - start;
- int pb_size = (((long)start + size/3)&(~3)) - (long)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==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 I_TYPE:
- return 16;
- case P_TYPE:
- case S_TYPE:
- return s->f_code+15;
- case B_TYPE:
- return FFMAX(FFMAX(s->f_code, s->b_code)+15, 17);
- default:
- return -1;
- }
-}
-
-#ifdef 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==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 == 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 allready 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 == 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 != 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 == 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;
-}
-
-/**
- * decodes the group of blocks / video packet header.
- * @return <0 if no resync found
- */
-int ff_h263_resync(MpegEncContext *s){
- int left, ret;
-
- if(s->codec_id==CODEC_ID_MPEG4){
- skip_bits1(&s->gb);
- align_get_bits(&s->gb);
- }
-
- if(show_bits(&s->gb, 16)==0){
- 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 0;
- }
- //ok, it's not where its 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;
-
- 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 0;
-
- 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]<<s->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 occured
- */
-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_y<s->mb_height; s->mb_y++){
- ff_init_block_index(s);
- for(; s->mb_x<s->mb_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==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==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==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 occured
- */
-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_x<s->mb_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==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==I_TYPE ? (DC_ERROR|MV_ERROR) : MV_ERROR;
- const int part_a_end = s->pict_type==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==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==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==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 occured
- */
-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 == P_TYPE || s->pict_type==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==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 == 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);
-}
-
-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;
-
- assert(!s->h263_pred);
-
- if (s->pict_type == 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;
-
- 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;
- }
- }
-
- /* 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->obmc){
- if(s->pict_type == P_TYPE && s->mb_x+1<s->mb_width && s->mb_num_left != 1)
- preview_obmc(s);
- }
- } else if(s->pict_type==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;
-
- /* decode each block */
- for (i = 0; i < 6; i++) {
- if (h263_decode_block(s, block[i], i, cbp&32) < 0)
- return -1;
- cbp+=cbp;
- }
- } 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;
-
- 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);
- }
-
- /* decode each block */
- for (i = 0; i < 6; i++) {
- if (h263_decode_block(s, block[i], i, cbp&32) < 0)
- return -1;
- cbp+=cbp;
- }
- }
-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 == P_TYPE || s->pict_type==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==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==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==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==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)>>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);
-#ifdef DEBUG
- av_log( s->avctx, AV_LOG_DEBUG,"H.263+ UMV Motion = %d\n", code);
-#endif
- 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){
-#ifdef CONFIG_RV10_DECODER
- if (s->rv10_version == 3 && s->pict_type == 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_resilience >= 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 its supposed to work ...
- rl = &rl_intra_aic;
- i = 0;
- s->gb= gb;
- memset(block, 0, sizeof(DCTELEM)*64);
- 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_resilience>=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 occured
- */
-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]<<n)&32;
- }else{
- level = mpeg4_decode_dc(s, n, &dc_pred_dir);
- if (level < 0)
- return -1;
- }
- block[0] = level;
- i = 0;
- }else{
- i = -1;
- ff_mpeg4_pred_dc(s, n, 0, &dc_pred_dir, 0);
- }
- if (!coded)
- goto not_coded;
-
- if(rvlc){
- rl = &rvlc_rl_intra;
- rl_vlc = rvlc_rl_intra.rl_vlc[0];
- }else{
- rl = &rl_intra;
- rl_vlc = rl_intra.rl_vlc[0];
- }
- if (s->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_resilience >= 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_resilience > 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_resilience > 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 = 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;
-
- if (get_bits1(&s->gb) != 0) {
- av_log(s->avctx, AV_LOG_ERROR, "H263 PB frame not supported\n");
- return -1; /* not PB frame */
- }
- 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("ufep=1, format: %d\n", format);
- s->custom_pcf= get_bits1(&s->gb);
- s->umvplus = get_bits(&s->gb, 1); /* 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= I_TYPE;break;
- case 1: s->pict_type= P_TYPE;break;
- case 3: s->pict_type= B_TYPE;break;
- case 7: s->pict_type= 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("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("\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= ff_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;
-
- /* 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){
- 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 1
- if (s->pict_type == I_TYPE && s->codec_tag == ff_get_fourcc("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<<s->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; i<s->num_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);
- d[i][0]= x;
- d[i][1]= y;
- }
-
- while((1<<alpha)<w) alpha++;
- while((1<<beta )<h) beta++; // there seems to be a typo in the mpeg4 std for the definition of w' and h'
- w2= 1<<alpha;
- h2= 1<<beta;
-
-// Note, the 4th point isn't used for GMC
- if(s->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<<s->sprite_shift[0]
- && s->sprite_delta[0][1] == 0
- && s->sprite_delta[1][0] == 0
- && s->sprite_delta[1][1] == a<<s->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!=1){
- 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 == ff_get_fourcc("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);
- 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)) av_log(s->avctx, AV_LOG_ERROR, "Complexity estimation not supported\n");
-
- 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.
- * allso inits 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';
- }
-
- /* 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) + I_TYPE; /* pict type: I = 0 , P = 1 */
- if(s->pict_type==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!=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!=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 == P_TYPE
- || (s->pict_type == 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 != 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) {
- 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 == 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 != 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 == 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\n",
- s->qscale, s->f_code, s->b_code,
- s->pict_type == I_TYPE ? "I" : (s->pict_type == P_TYPE ? "P" : (s->pict_type == 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);
- }
-
- if(!s->scalability){
- if (s->shape!=RECT_SHAPE && s->pict_type!=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 == ff_get_fourcc("WV1F") && show_bits(gb, 24) == 0x575630){
- skip_bits(gb, 24);
- if(get_bits(gb, 8) == 0xF0)
- return decode_vop_header(s, gb);
- }
-
- 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){
- return decode_vop_header(s, gb);
- }
-
- align_get_bits(gb);
- startcode = 0xff;
- }
-}
-
-/* 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 = 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 */
- }
- if (get_bits1(&s->gb) != 0) {
- s->obmc= 1;
- av_log(s->avctx, AV_LOG_ERROR, "Advanced Prediction Mode not supported\n");
-// return -1; /* advanced prediction mode: off */
- }
- if (get_bits1(&s->gb) != 0) {
- av_log(s->avctx, AV_LOG_ERROR, "PB frame mode no supported\n");
- return -1; /* PB frame mode */
- }
-
- /* skip unknown header garbage */
- skip_bits(&s->gb, 41);
-
- s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
- skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
-
- /* 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;
-
- 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 = I_TYPE + get_bits(&s->gb, 2);
- s->dropable= s->pict_type > P_TYPE;
- if (s->dropable)
- s->pict_type = 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/libffmpeg/libavcodec/h263dec.c b/src/libffmpeg/libavcodec/h263dec.c
deleted file mode 100644
index 9246b5217..000000000
--- a/src/libffmpeg/libavcodec/h263dec.c
+++ /dev/null
@@ -1,913 +0,0 @@
-/*
- * H.263 decoder
- * Copyright (c) 2001 Fabrice Bellard.
- * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/**
- * @file h263dec.c
- * H.263 decoder.
- */
-
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-
-//#define DEBUG
-//#define PRINT_FRAME_TIME
-
-int ff_h263_decode_init(AVCodecContext *avctx)
-{
- MpegEncContext *s = avctx->priv_data;
-
- s->avctx = avctx;
- s->out_format = FMT_H263;
-
- s->width = avctx->coded_width;
- s->height = avctx->coded_height;
- s->workaround_bugs= avctx->workaround_bugs;
-
- // set defaults
- MPV_decode_defaults(s);
- s->quant_precision=5;
- s->decode_mb= ff_h263_decode_mb;
- s->low_delay= 1;
- avctx->pix_fmt= PIX_FMT_YUV420P;
- s->unrestricted_mv= 1;
-
- /* select sub codec */
- switch(avctx->codec->id) {
- case CODEC_ID_H263:
- s->unrestricted_mv= 0;
- 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
- break;
- case CODEC_ID_MSMPEG4V1:
- s->h263_msmpeg4 = 1;
- s->h263_pred = 1;
- s->msmpeg4_version=1;
- break;
- case CODEC_ID_MSMPEG4V2:
- s->h263_msmpeg4 = 1;
- s->h263_pred = 1;
- s->msmpeg4_version=2;
- break;
- case CODEC_ID_MSMPEG4V3:
- s->h263_msmpeg4 = 1;
- s->h263_pred = 1;
- s->msmpeg4_version=3;
- break;
- case CODEC_ID_WMV1:
- s->h263_msmpeg4 = 1;
- s->h263_pred = 1;
- s->msmpeg4_version=4;
- break;
- case CODEC_ID_WMV2:
- s->h263_msmpeg4 = 1;
- s->h263_pred = 1;
- s->msmpeg4_version=5;
- break;
- case CODEC_ID_VC1:
- case CODEC_ID_WMV3:
- s->h263_msmpeg4 = 1;
- s->h263_pred = 1;
- s->msmpeg4_version=6;
- break;
- case CODEC_ID_H263I:
- break;
- case CODEC_ID_FLV1:
- s->h263_flv = 1;
- break;
- default:
- return -1;
- }
- s->codec_id= avctx->codec->id;
-
- /* for h263, we allocate the images after having read the header */
- if (avctx->codec->id != CODEC_ID_H263 && avctx->codec->id != CODEC_ID_MPEG4)
- if (MPV_common_init(s) < 0)
- return -1;
-
- if (s->h263_msmpeg4)
- ff_msmpeg4_decode_init(s);
- else
- h263_decode_init_vlc(s);
-
- return 0;
-}
-
-int ff_h263_decode_end(AVCodecContext *avctx)
-{
- MpegEncContext *s = avctx->priv_data;
-
- MPV_common_end(s);
- return 0;
-}
-
-/**
- * returns the number of bytes consumed for building the current frame
- */
-static int get_consumed_bytes(MpegEncContext *s, int buf_size){
- int pos= (get_bits_count(&s->gb)+7)>>3;
-
- if(s->divx_packed){
- //we would have to scan through the whole buf to handle the weird reordering ...
- return buf_size;
- }else if(s->flags&CODEC_FLAG_TRUNCATED){
- pos -= s->parse_context.last_index;
- if(pos<0) pos=0; // padding is not really read so this might be -1
- return pos;
- }else{
- if(pos==0) pos=1; //avoid infinite loops (i doubt thats needed but ...)
- if(pos+10>buf_size) pos=buf_size; // oops ;)
-
- return pos;
- }
-}
-
-static int decode_slice(MpegEncContext *s){
- const int part_mask= s->partitioned_frame ? (AC_END|AC_ERROR) : 0x7F;
- const int mb_size= 16>>s->avctx->lowres;
- s->last_resync_gb= s->gb;
- s->first_slice_line= 1;
-
- s->resync_mb_x= s->mb_x;
- s->resync_mb_y= s->mb_y;
-
- ff_set_qscale(s, s->qscale);
-
- if(s->partitioned_frame){
- const int qscale= s->qscale;
-
- if(s->codec_id==CODEC_ID_MPEG4){
- if(ff_mpeg4_decode_partitions(s) < 0)
- return -1;
- }
-
- /* restore variables which were modified */
- s->first_slice_line=1;
- s->mb_x= s->resync_mb_x;
- s->mb_y= s->resync_mb_y;
- ff_set_qscale(s, qscale);
- }
-
- for(; s->mb_y < s->mb_height; s->mb_y++) {
- /* per-row end of slice checks */
- if(s->msmpeg4_version){
- if(s->resync_mb_y + s->slice_height == s->mb_y){
- 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);
-
- return 0;
- }
- }
-
- if(s->msmpeg4_version==1){
- s->last_dc[0]=
- s->last_dc[1]=
- s->last_dc[2]= 128;
- }
-
- ff_init_block_index(s);
- for(; s->mb_x < s->mb_width; s->mb_x++) {
- int ret;
-
- ff_update_block_index(s);
-
- if(s->resync_mb_x == s->mb_x && s->resync_mb_y+1 == s->mb_y){
- s->first_slice_line=0;
- }
-
- /* DCT & quantize */
-
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_16X16;
-// s->mb_skipped = 0;
-//printf("%d %d %06X\n", ret, get_bits_count(&s->gb), show_bits(&s->gb, 24));
- ret= s->decode_mb(s, s->block);
-
- if (s->pict_type!=B_TYPE)
- ff_h263_update_motion_val(s);
-
- if(ret<0){
- const int xy= s->mb_x + s->mb_y*s->mb_stride;
- if(ret==SLICE_END){
- MPV_decode_mb(s, s->block);
- if(s->loop_filter)
- ff_h263_loop_filter(s);
-
-//printf("%d %d %d %06X\n", s->mb_x, s->mb_y, s->gb.size*8 - get_bits_count(&s->gb), show_bits(&s->gb, 24));
- 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);
-
- s->padding_bug_score--;
-
- if(++s->mb_x >= s->mb_width){
- s->mb_x=0;
- ff_draw_horiz_band(s, s->mb_y*mb_size, mb_size);
- s->mb_y++;
- }
- return 0;
- }else if(ret==SLICE_NOEND){
- av_log(s->avctx, AV_LOG_ERROR, "Slice mismatch at MB: %d\n", xy);
- 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 -1;
- }
- av_log(s->avctx, AV_LOG_ERROR, "Error at MB: %d\n", xy);
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);
-
- return -1;
- }
-
- MPV_decode_mb(s, s->block);
- if(s->loop_filter)
- ff_h263_loop_filter(s);
- }
-
- ff_draw_horiz_band(s, s->mb_y*mb_size, mb_size);
-
- s->mb_x= 0;
- }
-
- assert(s->mb_x==0 && s->mb_y==s->mb_height);
-
- /* 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
-// && !s->resync_marker
- && !s->data_partitioning){
-
- const int bits_count= get_bits_count(&s->gb);
- const int bits_left = s->gb.size_in_bits - bits_count;
-
- if(bits_left==0){
- s->padding_bug_score+=16;
- } else if(bits_left != 1){
- int v= show_bits(&s->gb, 8);
- v|= 0x7F >> (7-(bits_count&7));
-
- if(v==0x7F && bits_left<=8)
- s->padding_bug_score--;
- else if(v==0x7F && ((get_bits_count(&s->gb)+8)&8) && bits_left<=16)
- s->padding_bug_score+= 4;
- else
- s->padding_bug_score++;
- }
- }
-
- if(s->workaround_bugs&FF_BUG_AUTODETECT){
- if(s->padding_bug_score > -2 && !s->data_partitioning /*&& (s->divx_version || !s->resync_marker)*/)
- s->workaround_bugs |= FF_BUG_NO_PADDING;
- else
- s->workaround_bugs &= ~FF_BUG_NO_PADDING;
- }
-
- // 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 max_extra=7;
-
- /* no markers in M$ crap */
- if(s->msmpeg4_version && s->pict_type==I_TYPE)
- max_extra+= 17;
-
- /* buggy padding but the frame should still end approximately at the bitstream end */
- if((s->workaround_bugs&FF_BUG_NO_PADDING) && s->error_resilience>=3)
- max_extra+= 48;
- else if((s->workaround_bugs&FF_BUG_NO_PADDING))
- max_extra+= 256*256*256*64;
-
- if(left>max_extra){
- av_log(s->avctx, AV_LOG_ERROR, "discarding %d junk bits at end, next would be %X\n", left, show_bits(&s->gb, 24));
- }
- else if(left<0){
- av_log(s->avctx, AV_LOG_ERROR, "overreading %d bits\n", -left);
- }else
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, AC_END|DC_END|MV_END);
-
- return 0;
- }
-
- 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),
- 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);
-
- return -1;
-}
-
-/**
- * finds the end of the current frame in the bitstream.
- * @return the position of the first byte of the next frame, or -1
- */
-int ff_mpeg4_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size){
- int vop_found, i;
- uint32_t state;
-
- vop_found= pc->frame_start_found;
- state= pc->state;
-
- i=0;
- if(!vop_found){
- for(i=0; i<buf_size; i++){
- state= (state<<8) | buf[i];
- if(state == 0x1B6){
- i++;
- vop_found=1;
- break;
- }
- }
- }
-
- if(vop_found){
- /* EOF considered as end of frame */
- if (buf_size == 0)
- return 0;
- for(; i<buf_size; i++){
- state= (state<<8) | buf[i];
- if((state&0xFFFFFF00) == 0x100){
- pc->frame_start_found=0;
- pc->state=-1;
- return i-3;
- }
- }
- }
- pc->frame_start_found= vop_found;
- pc->state= state;
- return END_NOT_FOUND;
-}
-
-static int h263_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size){
- int vop_found, i;
- uint32_t state;
-
- vop_found= pc->frame_start_found;
- state= pc->state;
-
- i=0;
- if(!vop_found){
- for(i=0; i<buf_size; i++){
- state= (state<<8) | buf[i];
- if(state>>(32-22) == 0x20){
- i++;
- vop_found=1;
- break;
- }
- }
- }
-
- if(vop_found){
- for(; i<buf_size; i++){
- state= (state<<8) | buf[i];
- if(state>>(32-22) == 0x20){
- pc->frame_start_found=0;
- pc->state=-1;
- return i-3;
- }
- }
- }
- pc->frame_start_found= vop_found;
- pc->state= state;
-
- return END_NOT_FOUND;
-}
-
-#ifdef CONFIG_H263_PARSER
-static int h263_parse(AVCodecParserContext *s,
- AVCodecContext *avctx,
- uint8_t **poutbuf, int *poutbuf_size,
- const uint8_t *buf, int buf_size)
-{
- ParseContext *pc = s->priv_data;
- int next;
-
- next= h263_find_frame_end(pc, buf, buf_size);
-
- if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
- *poutbuf = NULL;
- *poutbuf_size = 0;
- return buf_size;
- }
-
- *poutbuf = (uint8_t *)buf;
- *poutbuf_size = buf_size;
- return next;
-}
-#endif
-
-int ff_h263_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- MpegEncContext *s = avctx->priv_data;
- int ret;
- AVFrame *pict = data;
-
-#ifdef PRINT_FRAME_TIME
-uint64_t time= rdtsc();
-#endif
-#ifdef DEBUG
- av_log(avctx, AV_LOG_DEBUG, "*****frame %d size=%d\n", avctx->frame_number, buf_size);
- av_log(avctx, AV_LOG_DEBUG, "bytes=%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]);
-#endif
- s->flags= avctx->flags;
- s->flags2= avctx->flags2;
-
- /* no supplementary picture */
- if (buf_size == 0) {
- /* special case for last picture */
- if (s->low_delay==0 && s->next_picture_ptr) {
- *pict= *(AVFrame*)s->next_picture_ptr;
- s->next_picture_ptr= NULL;
-
- *data_size = sizeof(AVFrame);
- }
-
- return 0;
- }
-
- if(s->flags&CODEC_FLAG_TRUNCATED){
- int next;
-
- if(s->codec_id==CODEC_ID_MPEG4){
- next= ff_mpeg4_find_frame_end(&s->parse_context, buf, buf_size);
- }else if(s->codec_id==CODEC_ID_H263){
- next= h263_find_frame_end(&s->parse_context, buf, buf_size);
- }else{
- av_log(s->avctx, AV_LOG_ERROR, "this codec does not support truncated bitstreams\n");
- return -1;
- }
-
- if( ff_combine_frame(&s->parse_context, next, &buf, &buf_size) < 0 )
- return buf_size;
- }
-
-
-retry:
-
- if(s->bitstream_buffer_size && (s->divx_packed || buf_size<20)){ //divx 5.01+/xvid frame reorder
- init_get_bits(&s->gb, s->bitstream_buffer, s->bitstream_buffer_size*8);
- }else
- init_get_bits(&s->gb, buf, buf_size*8);
- s->bitstream_buffer_size=0;
-
- if (!s->context_initialized) {
- if (MPV_common_init(s) < 0) //we need the idct permutaton for reading a custom matrix
- return -1;
- }
-
- //we need to set current_picture_ptr before reading the header, otherwise we cant store anyting im there
- if(s->current_picture_ptr==NULL || s->current_picture_ptr->data[0]){
- int i= ff_find_unused_picture(s, 0);
- s->current_picture_ptr= &s->picture[i];
- }
-
- /* let's go :-) */
- if (s->msmpeg4_version==5) {
- ret= ff_wmv2_decode_picture_header(s);
- } else if (s->msmpeg4_version) {
- ret = msmpeg4_decode_picture_header(s);
- } else if (s->h263_pred) {
- if(s->avctx->extradata_size && s->picture_number==0){
- GetBitContext gb;
-
- init_get_bits(&gb, s->avctx->extradata, s->avctx->extradata_size*8);
- ret = ff_mpeg4_decode_picture_header(s, &gb);
- }
- ret = ff_mpeg4_decode_picture_header(s, &s->gb);
-
- if(s->flags& CODEC_FLAG_LOW_DELAY)
- s->low_delay=1;
- } 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 {
- ret = h263_decode_picture_header(s);
- }
-
- if(ret==FRAME_SKIPPED) return get_consumed_bytes(s, buf_size);
-
- /* skip if the header was thrashed */
- if (ret < 0){
- av_log(s->avctx, AV_LOG_ERROR, "header damaged\n");
- return -1;
- }
-
- avctx->has_b_frames= !s->low_delay;
-
- if(s->xvid_build==0 && s->divx_version==0 && s->lavc_build==0){
- if(s->stream_codec_tag == ff_get_fourcc("XVID") ||
- s->codec_tag == ff_get_fourcc("XVID") || s->codec_tag == ff_get_fourcc("XVIX") ||
- s->codec_tag == ff_get_fourcc("RMP4"))
- s->xvid_build= -1;
-#if 0
- if(s->codec_tag == ff_get_fourcc("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;
-#endif
- }
-
- if(s->xvid_build==0 && s->divx_version==0 && s->lavc_build==0){
- if(s->codec_tag == ff_get_fourcc("DIVX") && s->vo_type==0 && s->vol_control_parameters==0)
- s->divx_version= 400; //divx 4
- }
-
- if(s->xvid_build && s->divx_version){
- s->divx_version=
- s->divx_build= 0;
- }
-
- if(s->workaround_bugs&FF_BUG_AUTODETECT){
- if(s->codec_tag == ff_get_fourcc("XVIX"))
- s->workaround_bugs|= FF_BUG_XVID_ILACE;
-
- if(s->codec_tag == ff_get_fourcc("UMP4")){
- s->workaround_bugs|= FF_BUG_UMP4;
- }
-
- if(s->divx_version>=500){
- s->workaround_bugs|= FF_BUG_QPEL_CHROMA;
- }
-
- if(s->divx_version>502){
- s->workaround_bugs|= FF_BUG_QPEL_CHROMA2;
- }
-
- if(s->xvid_build && s->xvid_build<=3)
- s->padding_bug_score= 256*256*256*64;
-
- if(s->xvid_build && s->xvid_build<=1)
- s->workaround_bugs|= FF_BUG_QPEL_CHROMA;
-
- if(s->xvid_build && s->xvid_build<=12)
- s->workaround_bugs|= FF_BUG_EDGE;
-
- if(s->xvid_build && s->xvid_build<=32)
- s->workaround_bugs|= FF_BUG_DC_CLIP;
-
-#define SET_QPEL_FUNC(postfix1, postfix2) \
- s->dsp.put_ ## postfix1 = ff_put_ ## postfix2;\
- 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)
- s->workaround_bugs|= FF_BUG_STD_QPEL;
-
- if(s->lavc_build && s->lavc_build<4655)
- s->workaround_bugs|= FF_BUG_DIRECT_BLOCKSIZE;
-
- if(s->lavc_build && s->lavc_build<4670){
- s->workaround_bugs|= FF_BUG_EDGE;
- }
-
- if(s->lavc_build && s->lavc_build<=4712)
- s->workaround_bugs|= FF_BUG_DC_CLIP;
-
- if(s->divx_version)
- 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){
- s->workaround_bugs|= FF_BUG_EDGE;
- }
-
- if(s->divx_version)
- s->workaround_bugs|= FF_BUG_HPEL_CHROMA;
-#if 0
- if(s->divx_version==500)
- s->padding_bug_score= 256*256*256*64;
-
- /* very ugly XVID padding bug detection FIXME/XXX solve this differently
- * lets hope this at least works
- */
- if( s->resync_marker==0 && s->data_partitioning==0 && s->divx_version==0
- && 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
- s->workaround_bugs|= FF_BUG_NO_PADDING;
-#endif
- }
-
- if(s->workaround_bugs& FF_BUG_STD_QPEL){
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 5], qpel16_mc11_old_c)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 7], qpel16_mc31_old_c)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 9], qpel16_mc12_old_c)
- SET_QPEL_FUNC(qpel_pixels_tab[0][11], qpel16_mc32_old_c)
- SET_QPEL_FUNC(qpel_pixels_tab[0][13], qpel16_mc13_old_c)
- SET_QPEL_FUNC(qpel_pixels_tab[0][15], qpel16_mc33_old_c)
-
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 5], qpel8_mc11_old_c)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 7], qpel8_mc31_old_c)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 9], qpel8_mc12_old_c)
- SET_QPEL_FUNC(qpel_pixels_tab[1][11], qpel8_mc32_old_c)
- SET_QPEL_FUNC(qpel_pixels_tab[1][13], qpel8_mc13_old_c)
- SET_QPEL_FUNC(qpel_pixels_tab[1][15], qpel8_mc33_old_c)
- }
-
- if(avctx->debug & FF_DEBUG_BUGS)
- av_log(s->avctx, AV_LOG_DEBUG, "bugs: %X lavc_build:%d xvid_build:%d divx_version:%d divx_build:%d %s\n",
- s->workaround_bugs, s->lavc_build, s->xvid_build, s->divx_version, s->divx_build,
- s->divx_packed ? "p" : "");
-
-#if 0 // dump bits per frame / qp / complexity
-{
- static FILE *f=NULL;
- if(!f) f=fopen("rate_qp_cplx.txt", "w");
- fprintf(f, "%d %d %f\n", buf_size, s->qscale, buf_size*(double)s->qscale);
-}
-#endif
-
-#if defined(HAVE_MMX) && defined(CONFIG_GPL)
- if(s->codec_id == CODEC_ID_MPEG4 && s->xvid_build && avctx->idct_algo == FF_IDCT_AUTO && (mm_flags & MM_MMX)){
- avctx->idct_algo= FF_IDCT_XVIDMMX;
- avctx->coded_width= 0; // force reinit
-// dsputil_init(&s->dsp, avctx);
- s->picture_number=0;
- }
-#endif
-
- /* After H263 & mpeg4 header decode we have the height, width,*/
- /* and other parameters. So then we could init the picture */
- /* FIXME: By the way H263 decoder is evolving it should have */
- /* an H263EncContext */
-
- if ( s->width != avctx->coded_width
- || s->height != avctx->coded_height) {
- /* H.263 could change picture size any time */
- ParseContext pc= s->parse_context; //FIXME move these demuxng hack to avformat
- s->parse_context.buffer=0;
- MPV_common_end(s);
- s->parse_context= pc;
- }
- if (!s->context_initialized) {
- avcodec_set_dimensions(avctx, s->width, s->height);
-
- goto retry;
- }
-
- if((s->codec_id==CODEC_ID_H263 || s->codec_id==CODEC_ID_H263P))
- s->gob_index = ff_h263_get_gob_height(s);
-
- // for hurry_up==5
- s->current_picture.pict_type= s->pict_type;
- s->current_picture.key_frame= s->pict_type == I_TYPE;
-
- /* skip B-frames if we don't have reference frames */
- if(s->last_picture_ptr==NULL && (s->pict_type==B_TYPE || s->dropable)) return get_consumed_bytes(s, buf_size);
- /* skip b frames if we are in a hurry */
- if(avctx->hurry_up && s->pict_type==B_TYPE) return get_consumed_bytes(s, buf_size);
- if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==B_TYPE)
- || (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=I_TYPE)
- || avctx->skip_frame >= AVDISCARD_ALL)
- return get_consumed_bytes(s, buf_size);
- /* skip everything if we are in a hurry>=5 */
- if(avctx->hurry_up>=5) return get_consumed_bytes(s, buf_size);
-
- if(s->next_p_frame_damaged){
- if(s->pict_type==B_TYPE)
- return get_consumed_bytes(s, buf_size);
- else
- s->next_p_frame_damaged=0;
- }
-
- if((s->avctx->flags2 & CODEC_FLAG2_FAST) && s->pict_type==B_TYPE){
- s->me.qpel_put= s->dsp.put_2tap_qpel_pixels_tab;
- s->me.qpel_avg= s->dsp.avg_2tap_qpel_pixels_tab;
- }else if((!s->no_rounding) || s->pict_type==B_TYPE){
- s->me.qpel_put= s->dsp.put_qpel_pixels_tab;
- s->me.qpel_avg= s->dsp.avg_qpel_pixels_tab;
- }else{
- s->me.qpel_put= s->dsp.put_no_rnd_qpel_pixels_tab;
- s->me.qpel_avg= s->dsp.avg_qpel_pixels_tab;
- }
-
- if(MPV_frame_start(s, avctx) < 0)
- return -1;
-
-#ifdef DEBUG
- av_log(avctx, AV_LOG_DEBUG, "qscale=%d\n", s->qscale);
-#endif
-
- ff_er_frame_start(s);
-
- //the second part of the wmv2 header contains the MB skip bits which are stored in current_picture->mb_type
- //which isnt available before MPV_frame_start()
- if (s->msmpeg4_version==5){
- if(ff_wmv2_decode_secondary_picture_header(s) < 0)
- return -1;
- }
-
- /* decode each macroblock */
- s->mb_x=0;
- s->mb_y=0;
-
- decode_slice(s);
- while(s->mb_y<s->mb_height){
- if(s->msmpeg4_version){
- if(s->slice_height==0 || s->mb_x!=0 || (s->mb_y%s->slice_height)!=0 || get_bits_count(&s->gb) > s->gb.size_in_bits)
- break;
- }else{
- if(ff_h263_resync(s)<0)
- break;
- }
-
- if(s->msmpeg4_version<4 && s->h263_pred)
- ff_mpeg4_clean_buffers(s);
-
- decode_slice(s);
- }
-
- if (s->h263_msmpeg4 && s->msmpeg4_version<4 && s->pict_type==I_TYPE)
- if(msmpeg4_decode_ext_header(s, buf_size) < 0){
- s->error_status_table[s->mb_num-1]= AC_ERROR|DC_ERROR|MV_ERROR;
- }
-
- /* divx 5.01+ bistream reorder stuff */
- if(s->codec_id==CODEC_ID_MPEG4 && s->bitstream_buffer_size==0 && s->divx_packed){
- int current_pos= get_bits_count(&s->gb)>>3;
- int startcode_found=0;
-
- if(buf_size - current_pos > 5){
- int i;
- for(i=current_pos; i<buf_size-3; i++){
- if(buf[i]==0 && buf[i+1]==0 && buf[i+2]==1 && buf[i+3]==0xB6){
- startcode_found=1;
- break;
- }
- }
- }
- if(s->gb.buffer == s->bitstream_buffer && buf_size>20){ //xvid style
- startcode_found=1;
- current_pos=0;
- }
-
- if(startcode_found){
- s->bitstream_buffer= av_fast_realloc(
- s->bitstream_buffer,
- &s->allocated_bitstream_buffer_size,
- buf_size - current_pos + FF_INPUT_BUFFER_PADDING_SIZE);
- memcpy(s->bitstream_buffer, buf + current_pos, buf_size - current_pos);
- s->bitstream_buffer_size= buf_size - current_pos;
- }
- }
-
- ff_er_frame_end(s);
-
- MPV_frame_end(s);
-
-assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type);
-assert(s->current_picture.pict_type == s->pict_type);
- if (s->pict_type == B_TYPE || s->low_delay) {
- *pict= *(AVFrame*)s->current_picture_ptr;
- } else if (s->last_picture_ptr != NULL) {
- *pict= *(AVFrame*)s->last_picture_ptr;
- }
-
- if(s->last_picture_ptr || s->low_delay){
- *data_size = sizeof(AVFrame);
- ff_print_debug_info(s, pict);
- }
-
- /* Return the Picture timestamp as the frame number */
- /* we substract 1 because it is added on utils.c */
- avctx->frame_number = s->picture_number - 1;
-
-#ifdef PRINT_FRAME_TIME
-av_log(avctx, AV_LOG_DEBUG, "%"PRId64"\n", rdtsc()-time);
-#endif
-
- 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,
-};
-
-AVCodec h263_decoder = {
- "h263",
- CODEC_TYPE_VIDEO,
- CODEC_ID_H263,
- sizeof(MpegEncContext),
- ff_h263_decode_init,
- NULL,
- ff_h263_decode_end,
- ff_h263_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY,
- .flush= ff_mpeg_flush,
-};
-
-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,
-};
-
-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,
-};
-
-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,
-};
-
-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,
-};
-
-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,
-};
-
-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
-};
-
-#ifdef CONFIG_H263_PARSER
-AVCodecParser h263_parser = {
- { CODEC_ID_H263 },
- sizeof(ParseContext),
- NULL,
- h263_parse,
- ff_parse_close,
-};
-#endif
diff --git a/src/libffmpeg/libavcodec/h264.c b/src/libffmpeg/libavcodec/h264.c
deleted file mode 100644
index d696676f0..000000000
--- a/src/libffmpeg/libavcodec/h264.c
+++ /dev/null
@@ -1,8653 +0,0 @@
-/*
- * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder
- * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-/**
- * @file h264.c
- * H.264 / AVC / MPEG4 part10 codec.
- * @author Michael Niedermayer <michaelni@gmx.at>
- */
-
-#include "common.h"
-#include "dsputil.h"
-#include "avcodec.h"
-#include "mpegvideo.h"
-#include "h264data.h"
-#include "golomb.h"
-
-#include "cabac.h"
-
-//#undef NDEBUG
-#include <assert.h>
-
-#define interlaced_dct interlaced_dct_is_a_bad_name
-#define mb_intra mb_intra_isnt_initalized_see_mb_type
-
-#define LUMA_DC_BLOCK_INDEX 25
-#define CHROMA_DC_BLOCK_INDEX 26
-
-#define CHROMA_DC_COEFF_TOKEN_VLC_BITS 8
-#define COEFF_TOKEN_VLC_BITS 8
-#define TOTAL_ZEROS_VLC_BITS 9
-#define CHROMA_DC_TOTAL_ZEROS_VLC_BITS 3
-#define RUN_VLC_BITS 3
-#define RUN7_VLC_BITS 6
-
-#define MAX_SPS_COUNT 32
-#define MAX_PPS_COUNT 256
-
-#define MAX_MMCO_COUNT 66
-
-/* Compiling in interlaced support reduces the speed
- * of progressive decoding by about 2%. */
-#define ALLOW_INTERLACE
-
-#ifdef ALLOW_INTERLACE
-#define MB_MBAFF h->mb_mbaff
-#define MB_FIELD h->mb_field_decoding_flag
-#define FRAME_MBAFF h->mb_aff_frame
-#else
-#define MB_MBAFF 0
-#define MB_FIELD 0
-#define FRAME_MBAFF 0
-#undef IS_INTERLACED
-#define IS_INTERLACED(mb_type) 0
-#endif
-
-/**
- * Sequence parameter set
- */
-typedef struct SPS{
-
- int profile_idc;
- int level_idc;
- int transform_bypass; ///< qpprime_y_zero_transform_bypass_flag
- int log2_max_frame_num; ///< log2_max_frame_num_minus4 + 4
- int poc_type; ///< pic_order_cnt_type
- int log2_max_poc_lsb; ///< log2_max_pic_order_cnt_lsb_minus4
- int delta_pic_order_always_zero_flag;
- int offset_for_non_ref_pic;
- int offset_for_top_to_bottom_field;
- int poc_cycle_length; ///< num_ref_frames_in_pic_order_cnt_cycle
- int ref_frame_count; ///< num_ref_frames
- int gaps_in_frame_num_allowed_flag;
- int mb_width; ///< frame_width_in_mbs_minus1 + 1
- int mb_height; ///< frame_height_in_mbs_minus1 + 1
- int frame_mbs_only_flag;
- int mb_aff; ///<mb_adaptive_frame_field_flag
- int direct_8x8_inference_flag;
- int crop; ///< frame_cropping_flag
- int crop_left; ///< frame_cropping_rect_left_offset
- int crop_right; ///< frame_cropping_rect_right_offset
- int crop_top; ///< frame_cropping_rect_top_offset
- int crop_bottom; ///< frame_cropping_rect_bottom_offset
- int vui_parameters_present_flag;
- AVRational sar;
- int timing_info_present_flag;
- uint32_t num_units_in_tick;
- uint32_t time_scale;
- int fixed_frame_rate_flag;
- short offset_for_ref_frame[256]; //FIXME dyn aloc?
- int bitstream_restriction_flag;
- int num_reorder_frames;
- int scaling_matrix_present;
- uint8_t scaling_matrix4[6][16];
- uint8_t scaling_matrix8[2][64];
-}SPS;
-
-/**
- * Picture parameter set
- */
-typedef struct PPS{
- unsigned int sps_id;
- int cabac; ///< entropy_coding_mode_flag
- int pic_order_present; ///< pic_order_present_flag
- int slice_group_count; ///< num_slice_groups_minus1 + 1
- int mb_slice_group_map_type;
- unsigned int ref_count[2]; ///< num_ref_idx_l0/1_active_minus1 + 1
- int weighted_pred; ///< weighted_pred_flag
- int weighted_bipred_idc;
- int init_qp; ///< pic_init_qp_minus26 + 26
- int init_qs; ///< pic_init_qs_minus26 + 26
- int chroma_qp_index_offset;
- int deblocking_filter_parameters_present; ///< deblocking_filter_parameters_present_flag
- int constrained_intra_pred; ///< constrained_intra_pred_flag
- int redundant_pic_cnt_present; ///< redundant_pic_cnt_present_flag
- int transform_8x8_mode; ///< transform_8x8_mode_flag
- uint8_t scaling_matrix4[6][16];
- uint8_t scaling_matrix8[2][64];
-}PPS;
-
-/**
- * Memory management control operation opcode.
- */
-typedef enum MMCOOpcode{
- MMCO_END=0,
- MMCO_SHORT2UNUSED,
- MMCO_LONG2UNUSED,
- MMCO_SHORT2LONG,
- MMCO_SET_MAX_LONG,
- MMCO_RESET,
- MMCO_LONG,
-} MMCOOpcode;
-
-/**
- * Memory management control operation.
- */
-typedef struct MMCO{
- MMCOOpcode opcode;
- int short_frame_num;
- int long_index;
-} MMCO;
-
-/**
- * H264Context
- */
-typedef struct H264Context{
- MpegEncContext s;
- int nal_ref_idc;
- int nal_unit_type;
- uint8_t *rbsp_buffer;
- unsigned int rbsp_buffer_size;
-
- /**
- * 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)
-
- int chroma_qp; //QPc
-
- int prev_mb_skipped;
- int next_mb_skipped;
-
- //prediction stuff
- int chroma_pred_mode;
- int intra16x16_pred_mode;
-
- int top_mb_xy;
- int left_mb_xy[2];
-
- int8_t intra4x4_pred_mode_cache[5*8];
- int8_t (*intra4x4_pred_mode)[8];
- void (*pred4x4 [9+3])(uint8_t *src, uint8_t *topright, int stride);//FIXME move to dsp?
- void (*pred8x8l [9+3])(uint8_t *src, int topleft, int topright, int stride);
- void (*pred8x8 [4+3])(uint8_t *src, int stride);
- void (*pred16x16[4+3])(uint8_t *src, int stride);
- 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];
-
- /**
- * Motion vector cache.
- */
- DECLARE_ALIGNED_8(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
-
- /**
- * is 1 if the specific list MV&references are set to 0,0,-2.
- */
- int mv_cache_clean[2];
-
- /**
- * number of neighbors (top and/or left) that used 8x8 dct
- */
- int neighbor_transform_size;
-
- /**
- * block_offset[ 0..23] for frame macroblocks
- * block_offset[24..47] for field macroblocks
- */
- int block_offset[2*(16+8)];
-
- uint32_t *mb2b_xy; //FIXME are these 4 a good idea?
- uint32_t *mb2b8_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;
-
- int emu_edge_width;
- int emu_edge_height;
-
- int halfpel_flag;
- int thirdpel_flag;
-
- int unknown_svq3_flag;
- int next_slice_index;
-
- SPS sps_buffer[MAX_SPS_COUNT];
- SPS sps; ///< current sps
-
- PPS pps_buffer[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 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;
- uint8_t *slice_table_base;
- uint8_t *slice_table; ///< slice_table_base + 2*mb_stride + 1
- int slice_type;
- int slice_type_fixed;
-
- //interlacing specific flags
- int mb_aff_frame;
- int mb_field_decoding_flag;
- int mb_mbaff; ///< mb_aff_frame && mb_field_decoding_flag
-
- unsigned int sub_mb_type[4];
-
- //POC stuff
- int poc_lsb;
- int poc_msb;
- int delta_poc_bottom;
- int delta_poc[2];
- int frame_num;
- int prev_poc_msb; ///< poc_msb of the last reference pic for POC type 0
- int prev_poc_lsb; ///< poc_lsb of the last reference pic for POC type 0
- int frame_num_offset; ///< for POC type 2
- int prev_frame_num_offset; ///< for POC type 2
- int prev_frame_num; ///< frame_num of the last pic for POC type 1/2
-
- /**
- * frame_num for frames or 2*frame_num for field pics.
- */
- int curr_pic_num;
-
- /**
- * max_frame_num or 2*max_frame_num for field pics.
- */
- 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[32];
- int map_col_to_list0[2][16];
- int map_col_to_list0_field[2][32];
-
- /**
- * num_ref_idx_l0/1_active_minus1 + 1
- */
- unsigned int ref_count[2]; ///< counts frames or fields, depending on current mb mode
- Picture *short_ref[32];
- Picture *long_ref[32];
- Picture default_ref_list[2][32];
- Picture ref_list[2][48]; ///< 0..15: frame refs, 16..47: mbaff field refs
- Picture *delayed_pic[18]; //FIXME size?
- Picture *delayed_output_pic;
-
- /**
- * memory management control operations buffer.
- */
- MMCO mmco[MAX_MMCO_COUNT];
- int mmco_index;
-
- 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_8(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 to 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;
-}H264Context;
-
-static VLC coeff_token_vlc[4];
-static VLC chroma_dc_coeff_token_vlc;
-
-static VLC total_zeros_vlc[15];
-static VLC chroma_dc_total_zeros_vlc[3];
-
-static VLC run_vlc[6];
-static VLC run7_vlc;
-
-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 av_always_inline uint32_t pack16to32(int a, int b){
-#ifdef WORDS_BIGENDIAN
- return (b&0xFFFF) + (a<<16);
-#else
- return (a&0xFFFF) + (b<<16);
-#endif
-}
-
-const uint8_t ff_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,
-};
-
-const uint8_t ff_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,
-};
-
-
-/**
- * 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
- */
-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(w<=4);
-
- w *= size;
- stride *= size;
-
- assert((((long)vp)&(FFMIN(w, STRIDE_ALIGN)-1)) == 0);
- assert((stride&(w-1))==0);
- if(w==2){
- const uint16_t v= size==4 ? val : val*0x0101;
- *(uint16_t*)(p + 0*stride)= v;
- if(h==1) return;
- *(uint16_t*)(p + 1*stride)= v;
- if(h==2) return;
- *(uint16_t*)(p + 2*stride)=
- *(uint16_t*)(p + 3*stride)= v;
- }else if(w==4){
- const uint32_t v= size==4 ? val : val*0x01010101;
- *(uint32_t*)(p + 0*stride)= v;
- if(h==1) return;
- *(uint32_t*)(p + 1*stride)= v;
- if(h==2) return;
- *(uint32_t*)(p + 2*stride)=
- *(uint32_t*)(p + 3*stride)= v;
- }else if(w==8){
- //gcc can't optimize 64bit math on x86_32
-#if defined(ARCH_X86_64) || (defined(MP_WORDSIZE) && MP_WORDSIZE >= 64)
- const uint64_t v= val*0x0100000001ULL;
- *(uint64_t*)(p + 0*stride)= v;
- if(h==1) return;
- *(uint64_t*)(p + 1*stride)= v;
- if(h==2) return;
- *(uint64_t*)(p + 2*stride)=
- *(uint64_t*)(p + 3*stride)= v;
- }else if(w==16){
- const uint64_t v= val*0x0100000001ULL;
- *(uint64_t*)(p + 0+0*stride)=
- *(uint64_t*)(p + 8+0*stride)=
- *(uint64_t*)(p + 0+1*stride)=
- *(uint64_t*)(p + 8+1*stride)= v;
- if(h==2) return;
- *(uint64_t*)(p + 0+2*stride)=
- *(uint64_t*)(p + 8+2*stride)=
- *(uint64_t*)(p + 0+3*stride)=
- *(uint64_t*)(p + 8+3*stride)= v;
-#else
- *(uint32_t*)(p + 0+0*stride)=
- *(uint32_t*)(p + 4+0*stride)= val;
- if(h==1) return;
- *(uint32_t*)(p + 0+1*stride)=
- *(uint32_t*)(p + 4+1*stride)= val;
- if(h==2) return;
- *(uint32_t*)(p + 0+2*stride)=
- *(uint32_t*)(p + 4+2*stride)=
- *(uint32_t*)(p + 0+3*stride)=
- *(uint32_t*)(p + 4+3*stride)= val;
- }else if(w==16){
- *(uint32_t*)(p + 0+0*stride)=
- *(uint32_t*)(p + 4+0*stride)=
- *(uint32_t*)(p + 8+0*stride)=
- *(uint32_t*)(p +12+0*stride)=
- *(uint32_t*)(p + 0+1*stride)=
- *(uint32_t*)(p + 4+1*stride)=
- *(uint32_t*)(p + 8+1*stride)=
- *(uint32_t*)(p +12+1*stride)= val;
- if(h==2) return;
- *(uint32_t*)(p + 0+2*stride)=
- *(uint32_t*)(p + 4+2*stride)=
- *(uint32_t*)(p + 8+2*stride)=
- *(uint32_t*)(p +12+2*stride)=
- *(uint32_t*)(p + 0+3*stride)=
- *(uint32_t*)(p + 4+3*stride)=
- *(uint32_t*)(p + 8+3*stride)=
- *(uint32_t*)(p +12+3*stride)= val;
-#endif
- }else
- assert(0);
- assert(h==4);
-}
-
-static void fill_caches(H264Context *h, int mb_type, int for_deblock){
- MpegEncContext * const s = &h->s;
- const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
- int topleft_xy, top_xy, topright_xy, left_xy[2];
- int topleft_type, top_type, topright_type, left_type[2];
- int left_block[8];
- int i;
-
- //FIXME deblocking could skip the intra and nnz parts.
- if(for_deblock && (h->slice_num == 1 || h->slice_table[mb_xy] == h->slice_table[mb_xy-s->mb_stride]) && !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
-
- top_xy = mb_xy - s->mb_stride;
- topleft_xy = top_xy - 1;
- topright_xy= top_xy + 1;
- left_xy[1] = left_xy[0] = mb_xy-1;
- left_block[0]= 0;
- left_block[1]= 1;
- left_block[2]= 2;
- left_block[3]= 3;
- left_block[4]= 7;
- left_block[5]= 10;
- left_block[6]= 8;
- left_block[7]= 11;
- 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_frame_flag = !IS_INTERLACED(s->current_picture.mb_type[topleft_pair_xy]);
- const int top_mb_frame_flag = !IS_INTERLACED(s->current_picture.mb_type[top_pair_xy]);
- const int topright_mb_frame_flag = !IS_INTERLACED(s->current_picture.mb_type[topright_pair_xy]);
- const int left_mb_frame_flag = !IS_INTERLACED(s->current_picture.mb_type[pair_xy-1]);
- const int curr_mb_frame_flag = !IS_INTERLACED(mb_type);
- const int bottom = (s->mb_y & 1);
- tprintf("fill_caches: curr_mb_frame_flag:%d, left_mb_frame_flag:%d, topleft_mb_frame_flag:%d, top_mb_frame_flag:%d, topright_mb_frame_flag:%d\n", curr_mb_frame_flag, left_mb_frame_flag, topleft_mb_frame_flag, top_mb_frame_flag, topright_mb_frame_flag);
- if (bottom
- ? !curr_mb_frame_flag // bottom macroblock
- : (!curr_mb_frame_flag && !top_mb_frame_flag) // top macroblock
- ) {
- top_xy -= s->mb_stride;
- }
- if (bottom
- ? !curr_mb_frame_flag // bottom macroblock
- : (!curr_mb_frame_flag && !topleft_mb_frame_flag) // top macroblock
- ) {
- topleft_xy -= s->mb_stride;
- }
- if (bottom
- ? !curr_mb_frame_flag // bottom macroblock
- : (!curr_mb_frame_flag && !topright_mb_frame_flag) // top macroblock
- ) {
- topright_xy -= s->mb_stride;
- }
- if (left_mb_frame_flag != curr_mb_frame_flag) {
- left_xy[1] = left_xy[0] = pair_xy - 1;
- if (curr_mb_frame_flag) {
- if (bottom) {
- left_block[0]= 2;
- left_block[1]= 2;
- left_block[2]= 3;
- left_block[3]= 3;
- left_block[4]= 8;
- left_block[5]= 11;
- left_block[6]= 8;
- left_block[7]= 11;
- } else {
- left_block[0]= 0;
- left_block[1]= 0;
- left_block[2]= 1;
- left_block[3]= 1;
- left_block[4]= 7;
- left_block[5]= 10;
- left_block[6]= 7;
- left_block[7]= 10;
- }
- } else {
- left_xy[1] += s->mb_stride;
- //left_block[0]= 0;
- left_block[1]= 2;
- left_block[2]= 0;
- left_block[3]= 2;
- //left_block[4]= 7;
- left_block[5]= 10;
- left_block[6]= 7;
- left_block[7]= 10;
- }
- }
- }
-
- 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 ] < 255 ? s->current_picture.mb_type[top_xy] : 0;
- left_type[0] = h->slice_table[left_xy[0] ] < 255 ? s->current_picture.mb_type[left_xy[0]] : 0;
- left_type[1] = h->slice_table[left_xy[1] ] < 255 ? s->current_picture.mb_type[left_xy[1]] : 0;
-
- if(FRAME_MBAFF && !IS_INTRA(mb_type)){
- int list;
- int v = *(uint16_t*)&h->non_zero_count[mb_xy][14];
- for(i=0; i<16; i++)
- h->non_zero_count_cache[scan8[i]] = (v>>i)&1;
- for(list=0; list<1+(h->slice_type==B_TYPE); list++){
- if(USES_LIST(mb_type,list)){
- uint32_t *src = (uint32_t*)s->current_picture.motion_val[list][h->mb2b_xy[mb_xy]];
- uint32_t *dst = (uint32_t*)h->mv_cache[list][scan8[0]];
- int8_t *ref = &s->current_picture.ref_index[list][h->mb2b8_xy[mb_xy]];
- for(i=0; i<4; i++, dst+=8, src+=h->b_stride){
- dst[0] = src[0];
- dst[1] = src[1];
- dst[2] = src[2];
- dst[3] = src[3];
- }
- *(uint32_t*)&h->ref_cache[list][scan8[ 0]] =
- *(uint32_t*)&h->ref_cache[list][scan8[ 2]] = pack16to32(ref[0],ref[1])*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])*0x0101;
- }else{
- fill_rectangle(&h-> mv_cache[list][scan8[ 0]], 4, 4, 8, 0, 4);
- fill_rectangle(&h->ref_cache[list][scan8[ 0]], 4, 4, 8, (uint8_t)LIST_NOT_USED, 1);
- }
- }
- }
- }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)){
- h->topleft_samples_available=
- h->top_samples_available=
- h->left_samples_available= 0xFFFF;
- h->topright_samples_available= 0xEEEA;
-
- if(!IS_INTRA(top_type) && (top_type==0 || h->pps.constrained_intra_pred)){
- h->topleft_samples_available= 0xB3FF;
- h->top_samples_available= 0x33FF;
- h->topright_samples_available= 0x26EA;
- }
- for(i=0; i<2; i++){
- if(!IS_INTRA(left_type[i]) && (left_type[i]==0 || h->pps.constrained_intra_pred)){
- h->topleft_samples_available&= 0xDF5F;
- h->left_samples_available&= 0x5F5F;
- }
- }
-
- if(!IS_INTRA(topleft_type) && (topleft_type==0 || h->pps.constrained_intra_pred))
- h->topleft_samples_available&= 0x7FFF;
-
- if(!IS_INTRA(topright_type) && (topright_type==0 || h->pps.constrained_intra_pred))
- 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 || (IS_INTER(top_type) && h->pps.constrained_intra_pred))
- 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] || (IS_INTER(left_type[i]) && h->pps.constrained_intra_pred))
- 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 (lets 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; list<1+(h->slice_type==B_TYPE); 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;
- }
-
- //FIXME unify cleanup or sth
- if(USES_LIST(left_type[0], list)){
- const int b_xy= h->mb2b_xy[left_xy[0]] + 3;
- const int b8_xy= h->mb2b8_xy[left_xy[0]] + 1;
- *(uint32_t*)h->mv_cache[list][scan8[0] - 1 + 0*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[0]];
- *(uint32_t*)h->mv_cache[list][scan8[0] - 1 + 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[1]];
- h->ref_cache[list][scan8[0] - 1 + 0*8]= s->current_picture.ref_index[list][b8_xy + h->b8_stride*(left_block[0]>>1)];
- h->ref_cache[list][scan8[0] - 1 + 1*8]= s->current_picture.ref_index[list][b8_xy + h->b8_stride*(left_block[1]>>1)];
- }else{
- *(uint32_t*)h->mv_cache [list][scan8[0] - 1 + 0*8]=
- *(uint32_t*)h->mv_cache [list][scan8[0] - 1 + 1*8]= 0;
- h->ref_cache[list][scan8[0] - 1 + 0*8]=
- h->ref_cache[list][scan8[0] - 1 + 1*8]= left_type[0] ? LIST_NOT_USED : PART_NOT_AVAILABLE;
- }
-
- if(USES_LIST(left_type[1], list)){
- const int b_xy= h->mb2b_xy[left_xy[1]] + 3;
- const int b8_xy= h->mb2b8_xy[left_xy[1]] + 1;
- *(uint32_t*)h->mv_cache[list][scan8[0] - 1 + 2*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[2]];
- *(uint32_t*)h->mv_cache[list][scan8[0] - 1 + 3*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[3]];
- h->ref_cache[list][scan8[0] - 1 + 2*8]= s->current_picture.ref_index[list][b8_xy + h->b8_stride*(left_block[2]>>1)];
- h->ref_cache[list][scan8[0] - 1 + 3*8]= s->current_picture.ref_index[list][b8_xy + h->b8_stride*(left_block[3]>>1)];
- }else{
- *(uint32_t*)h->mv_cache [list][scan8[0] - 1 + 2*8]=
- *(uint32_t*)h->mv_cache [list][scan8[0] - 1 + 3*8]= 0;
- h->ref_cache[list][scan8[0] - 1 + 2*8]=
- h->ref_cache[list][scan8[0] - 1 + 3*8]= left_type[0] ? LIST_NOT_USED : PART_NOT_AVAILABLE;
- assert((!left_type[0]) == (!left_type[1]));
- }
-
- 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 + 3*h->b_stride;
- const int b8_xy= h->mb2b8_xy[topleft_xy] + 1 + 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 == 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){
- MpegEncContext * const s = &h->s;
- const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
-
- 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];
-}
-
-/**
- * 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){
- 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};
- int i;
-
- if(!(h->top_samples_available&0x8000)){
- for(i=0; i<4; i++){
- int status= top[ h->intra4x4_pred_mode_cache[scan8[0] + i] ];
- if(status<0){
- av_log(h->s.avctx, AV_LOG_ERROR, "top block unavailable for requested intra4x4 mode %d at %d %d\n", status, s->mb_x, s->mb_y);
- return -1;
- } else if(status){
- h->intra4x4_pred_mode_cache[scan8[0] + i]= status;
- }
- }
- }
-
- if(!(h->left_samples_available&0x8000)){
- for(i=0; i<4; i++){
- int status= left[ h->intra4x4_pred_mode_cache[scan8[0] + 8*i] ];
- if(status<0){
- av_log(h->s.avctx, AV_LOG_ERROR, "left block unavailable for requested intra4x4 mode %d at %d %d\n", status, s->mb_x, s->mb_y);
- return -1;
- } else if(status){
- h->intra4x4_pred_mode_cache[scan8[0] + 8*i]= status;
- }
- }
- }
-
- return 0;
-} //FIXME cleanup like next
-
-/**
- * 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){
- 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};
-
- if(mode < 0 || mode > 6) {
- av_log(h->s.avctx, AV_LOG_ERROR, "out of range intra chroma pred mode at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
-
- if(!(h->top_samples_available&0x8000)){
- mode= top[ mode ];
- if(mode<0){
- av_log(h->s.avctx, AV_LOG_ERROR, "top block unavailable for requested intra mode at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- }
-
- if(!(h->left_samples_available&0x8000)){
- mode= left[ mode ];
- if(mode<0){
- av_log(h->s.avctx, AV_LOG_ERROR, "left block unavailable for requested intra mode at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- }
-
- 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("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){
- MpegEncContext * const s = &h->s;
- const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
-
- 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];
-
- if(FRAME_MBAFF){
- // store all luma nnzs, for deblocking
- int v = 0, i;
- for(i=0; i<16; i++)
- v += (!!h->non_zero_count_cache[scan8[i]]) << i;
- *(uint16_t*)&h->non_zero_count[mb_xy][14] = v;
- }
-}
-
-/**
- * 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("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 ];
-
- /* 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){
- MpegEncContext *s = &h->s;
- 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) && !IS_8X8(mb_type))\
- 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){
- // leftshift will turn LIST_NOT_USED into PART_NOT_AVAILABLE, but that's ok.
- SET_DIAG_MV(>>1, <<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("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("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("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("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("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("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("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("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 == 0 && *(uint32_t*)h->mv_cache[0][ scan8[0] - 8 ] == 0)
- || (left_ref == 0 && *(uint32_t*)h->mv_cache[0][ scan8[0] - 1 ] == 0)){
-
- *mx = *my = 0;
- return;
- }
-
- pred_motion(h, 0, 4, 0, 0, mx, my);
-
- return;
-}
-
-static inline void direct_dist_scale_factor(H264Context * const h){
- const int poc = h->s.current_picture_ptr->poc;
- const int poc1 = h->ref_list[1][0].poc;
- int i;
- for(i=0; i<h->ref_count[0]; i++){
- int poc0 = h->ref_list[0][i].poc;
- int td = clip(poc1 - poc0, -128, 127);
- if(td == 0 /* FIXME || pic0 is a long-term ref */){
- h->dist_scale_factor[i] = 256;
- }else{
- int tb = clip(poc - poc0, -128, 127);
- int tx = (16384 + (FFABS(td) >> 1)) / td;
- h->dist_scale_factor[i] = clip((tb*tx + 32) >> 6, -1024, 1023);
- }
- }
- if(FRAME_MBAFF){
- for(i=0; i<h->ref_count[0]; i++){
- h->dist_scale_factor_field[2*i] =
- h->dist_scale_factor_field[2*i+1] = h->dist_scale_factor[i];
- }
- }
-}
-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, i, j;
- if(cur->pict_type == I_TYPE)
- cur->ref_count[0] = 0;
- if(cur->pict_type != B_TYPE)
- cur->ref_count[1] = 0;
- for(list=0; list<2; list++){
- cur->ref_count[list] = h->ref_count[list];
- for(j=0; j<h->ref_count[list]; j++)
- cur->ref_poc[list][j] = h->ref_list[list][j].poc;
- }
- if(cur->pict_type != B_TYPE || h->direct_spatial_mv_pred)
- return;
- for(list=0; list<2; list++){
- for(i=0; i<ref1->ref_count[list]; i++){
- const int poc = ref1->ref_poc[list][i];
- h->map_col_to_list0[list][i] = 0; /* bogus; fills in for missing frames */
- for(j=0; j<h->ref_count[list]; j++)
- if(h->ref_list[list][j].poc == poc){
- h->map_col_to_list0[list][i] = j;
- break;
- }
- }
- }
- if(FRAME_MBAFF){
- for(list=0; list<2; list++){
- for(i=0; i<ref1->ref_count[list]; i++){
- j = h->map_col_to_list0[list][i];
- h->map_col_to_list0_field[list][2*i] = 2*j;
- h->map_col_to_list0_field[list][2*i+1] = 2*j+1;
- }
- }
- }
-}
-
-static inline void pred_direct_motion(H264Context * const h, int *mb_type){
- MpegEncContext * const s = &h->s;
- const int mb_xy = s->mb_x + s->mb_y*s->mb_stride;
- const int b8_xy = 2*s->mb_x + 2*s->mb_y*h->b8_stride;
- const int b4_xy = 4*s->mb_x + 4*s->mb_y*h->b_stride;
- const int mb_type_col = h->ref_list[1][0].mb_type[mb_xy];
- const int16_t (*l1mv0)[2] = (const int16_t (*)[2]) &h->ref_list[1][0].motion_val[0][b4_xy];
- const int16_t (*l1mv1)[2] = (const int16_t (*)[2]) &h->ref_list[1][0].motion_val[1][b4_xy];
- const int8_t *l1ref0 = &h->ref_list[1][0].ref_index[0][b8_xy];
- const int8_t *l1ref1 = &h->ref_list[1][0].ref_index[1][b8_xy];
- const int is_b8x8 = IS_8X8(*mb_type);
- unsigned int sub_mb_type;
- int i8, i4;
-
-#define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16|MB_TYPE_INTRA4x4|MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM)
- if(IS_8X8(mb_type_col) && !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 & 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;
- }
- if(!is_b8x8)
- *mb_type |= MB_TYPE_DIRECT2;
- if(MB_FIELD)
- *mb_type |= MB_TYPE_INTERLACED;
-
- tprintf("mb_type = %08x, sub_mb_type = %08x, is_b8x8 = %d, mb_type_col = %08x\n", *mb_type, sub_mb_type, is_b8x8, mb_type_col);
-
- 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 == -2)
- refc = h->ref_cache[list][scan8[0] - 8 - 1];
- ref[list] = refa;
- if(ref[list] < 0 || (refb < ref[list] && refb >= 0))
- ref[list] = refb;
- if(ref[list] < 0 || (refc < ref[list] && refc >= 0))
- ref[list] = 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){
- *mb_type &= ~MB_TYPE_P0L1;
- sub_mb_type &= ~MB_TYPE_P0L1;
- }else if(ref[0] < 0){
- *mb_type &= ~MB_TYPE_P0L0;
- sub_mb_type &= ~MB_TYPE_P0L0;
- }
-
- if(IS_16X16(*mb_type)){
- 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)
- && ( (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)
- fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mv[0][0],mv[0][1]), 4);
- else
- fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4);
- if(ref[1] > 0)
- fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, pack16to32(mv[1][0],mv[1][1]), 4);
- else
- fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, 0, 4);
- }else{
- fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mv[0][0],mv[0][1]), 4);
- fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, pack16to32(mv[1][0],mv[1][1]), 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) && ( l1ref0[x8 + y8*h->b8_stride] == 0
- || (l1ref0[x8 + y8*h->b8_stride] < 0 && l1ref1[x8 + y8*h->b8_stride] == 0
- && (h->x264_build>33 || !h->x264_build)))){
- const int16_t (*l1mv)[2]= l1ref0[x8 + y8*h->b8_stride] == 0 ? l1mv0 : l1mv1;
- if(IS_SUB_8X8(sub_mb_type)){
- const int16_t *mv_col = l1mv[x8*3 + y8*3*h->b_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))*h->b_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;
-
- if(FRAME_MBAFF){
- if(IS_INTERLACED(*mb_type)){
- map_col_to_list0[0] = h->map_col_to_list0_field[0];
- map_col_to_list0[1] = h->map_col_to_list0_field[1];
- dist_scale_factor = h->dist_scale_factor_field;
- }
- if(IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col)){
- /* FIXME assumes direct_8x8_inference == 1 */
- const int pair_xy = s->mb_x + (s->mb_y&~1)*s->mb_stride;
- int mb_types_col[2];
- int y_shift;
-
- *mb_type = MB_TYPE_8x8|MB_TYPE_L0L1
- | (is_b8x8 ? 0 : MB_TYPE_DIRECT2)
- | (*mb_type & MB_TYPE_INTERLACED);
- sub_mb_type = MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2|MB_TYPE_16x16;
-
- if(IS_INTERLACED(*mb_type)){
- /* frame to field scaling */
- mb_types_col[0] = h->ref_list[1][0].mb_type[pair_xy];
- mb_types_col[1] = h->ref_list[1][0].mb_type[pair_xy+s->mb_stride];
- if(s->mb_y&1){
- l1ref0 -= 2*h->b8_stride;
- l1ref1 -= 2*h->b8_stride;
- l1mv0 -= 4*h->b_stride;
- l1mv1 -= 4*h->b_stride;
- }
- y_shift = 0;
-
- if( (mb_types_col[0] & MB_TYPE_16x16_OR_INTRA)
- && (mb_types_col[1] & MB_TYPE_16x16_OR_INTRA)
- && !is_b8x8)
- *mb_type |= MB_TYPE_16x8;
- else
- *mb_type |= MB_TYPE_8x8;
- }else{
- /* field to frame scaling */
- /* col_mb_y = (mb_y&~1) + (topAbsDiffPOC < bottomAbsDiffPOC ? 0 : 1)
- * but in MBAFF, top and bottom POC are equal */
- int dy = (s->mb_y&1) ? 1 : 2;
- mb_types_col[0] =
- mb_types_col[1] = h->ref_list[1][0].mb_type[pair_xy+s->mb_stride];
- l1ref0 += dy*h->b8_stride;
- l1ref1 += dy*h->b8_stride;
- l1mv0 += 2*dy*h->b_stride;
- l1mv1 += 2*dy*h->b_stride;
- y_shift = 2;
-
- if((mb_types_col[0] & (MB_TYPE_16x16_OR_INTRA|MB_TYPE_16x8))
- && !is_b8x8)
- *mb_type |= MB_TYPE_16x16;
- else
- *mb_type |= MB_TYPE_8x8;
- }
-
- 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_types_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*2>>y_shift)*h->b8_stride];
- if(ref0 >= 0)
- ref0 = map_col_to_list0[0][ref0*2>>y_shift];
- else{
- ref0 = map_col_to_list0[1][l1ref1[x8 + (y8*2>>y_shift)*h->b8_stride]*2>>y_shift];
- 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*6>>y_shift)*h->b_stride];
- int my_col = (mv_col[1]<<y_shift)/2;
- int mx = (scale * mv_col[0] + 128) >> 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)){
- fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, 0, 1);
- if(IS_INTRA(mb_type_col)){
- fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, 0, 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);
- }else{
- const int ref0 = l1ref0[0] >= 0 ? map_col_to_list0[0][l1ref0[0]]
- : map_col_to_list0[1][l1ref1[0]];
- 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;
- fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, ref0, 1);
- fill_rectangle(&h-> mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mv_l0[0],mv_l0[1]), 4);
- fill_rectangle(&h-> mv_cache[1][scan8[0]], 4, 4, 8, pack16to32(mv_l0[0]-mv_col[0],mv_l0[1]-mv_col[1]), 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)){
- 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*h->b8_stride];
- if(ref0 >= 0)
- ref0 = map_col_to_list0[0][ref0];
- else{
- ref0 = map_col_to_list0[1][l1ref1[x8 + y8*h->b8_stride]];
- 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*h->b_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))*h->b_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; list<2; 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 == 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;
- }
- }
-}
-
-/**
- * Decodes a network abstraction layer unit.
- * @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
- */
-static uint8_t *decode_nal(H264Context *h, uint8_t *src, int *dst_length, int *consumed, int length){
- int i, si, di;
- uint8_t *dst;
-
-// src[0]&0x80; //forbidden bit
- h->nal_ref_idc= src[0]>>5;
- h->nal_unit_type= src[0]&0x1F;
-
- src++; length--;
-#if 0
- for(i=0; i<length; i++)
- printf("%2X ", src[i]);
-#endif
- for(i=0; i+1<length; i+=2){
- if(src[i]) continue;
- if(i>0 && src[i-1]==0) i--;
- if(i+2<length && src[i+1]==0 && src[i+2]<=3){
- if(src[i+2]!=3){
- /* startcode, so we must be past the end */
- length=i;
- }
- break;
- }
- }
-
- if(i>=length-1){ //no escaped 0
- *dst_length= length;
- *consumed= length+1; //+1 for the header
- return src;
- }
-
- h->rbsp_buffer= av_fast_realloc(h->rbsp_buffer, &h->rbsp_buffer_size, length);
- dst= h->rbsp_buffer;
-
- if (dst == NULL){
- return NULL;
- }
-
-//printf("decoding esc\n");
- si=di=0;
- while(si<length){
- //remove escapes (very rare 1:2^22)
- if(si+2<length && src[si]==0 && src[si+1]==0 && src[si+2]<=3){
- if(src[si+2]==3){ //escape
- dst[di++]= 0;
- dst[di++]= 0;
- si+=3;
- continue;
- }else //next start code
- break;
- }
-
- dst[di++]= src[si++];
- }
-
- *dst_length= di;
- *consumed= si + 1;//+1 for the header
-//FIXME store exact number of bits in the getbitcontext (its needed for decoding)
- return dst;
-}
-
-/**
- * identifies the exact end of the bitstream
- * @return the length of the trailing, or 0 if damaged
- */
-static int decode_rbsp_trailing(uint8_t *src){
- int v= *src;
- int r;
-
- tprintf("rbsp trailing %X\n", v);
-
- for(r=1; r<9; r++){
- if(v&1) return r;
- v>>=1;
- }
- return 0;
-}
-
-/**
- * idct tranforms the 16 dc values and dequantize them.
- * @param qp quantization parameter
- */
-static void h264_luma_dc_dequant_idct_c(DCTELEM *block, int qp, int qmul){
-#define stride 16
- int i;
- int temp[16]; //FIXME check if this is a good idea
- static const int x_offset[4]={0, 1*stride, 4* stride, 5*stride};
- static const int y_offset[4]={0, 2*stride, 8* stride, 10*stride};
-
-//memset(block, 64, 2*256);
-//return;
- for(i=0; i<4; i++){
- const int offset= y_offset[i];
- const int z0= block[offset+stride*0] + block[offset+stride*4];
- const int z1= block[offset+stride*0] - block[offset+stride*4];
- const int z2= block[offset+stride*1] - block[offset+stride*5];
- const int z3= block[offset+stride*1] + block[offset+stride*5];
-
- temp[4*i+0]= z0+z3;
- temp[4*i+1]= z1+z2;
- temp[4*i+2]= z1-z2;
- temp[4*i+3]= z0-z3;
- }
-
- for(i=0; i<4; i++){
- const int offset= x_offset[i];
- const int z0= temp[4*0+i] + temp[4*2+i];
- const int z1= temp[4*0+i] - temp[4*2+i];
- const int z2= temp[4*1+i] - temp[4*3+i];
- const int z3= temp[4*1+i] + temp[4*3+i];
-
- block[stride*0 +offset]= ((((z0 + z3)*qmul + 128 ) >> 8)); //FIXME think about merging this into decode_resdual
- block[stride*2 +offset]= ((((z1 + z2)*qmul + 128 ) >> 8));
- block[stride*8 +offset]= ((((z1 - z2)*qmul + 128 ) >> 8));
- block[stride*10+offset]= ((((z0 - z3)*qmul + 128 ) >> 8));
- }
-}
-
-#if 0
-/**
- * dct tranforms the 16 dc values.
- * @param qp quantization parameter ??? FIXME
- */
-static void h264_luma_dc_dct_c(DCTELEM *block/*, int qp*/){
-// const int qmul= dequant_coeff[qp][0];
- int i;
- int temp[16]; //FIXME check if this is a good idea
- static const int x_offset[4]={0, 1*stride, 4* stride, 5*stride};
- static const int y_offset[4]={0, 2*stride, 8* stride, 10*stride};
-
- for(i=0; i<4; i++){
- const int offset= y_offset[i];
- const int z0= block[offset+stride*0] + block[offset+stride*4];
- const int z1= block[offset+stride*0] - block[offset+stride*4];
- const int z2= block[offset+stride*1] - block[offset+stride*5];
- const int z3= block[offset+stride*1] + block[offset+stride*5];
-
- temp[4*i+0]= z0+z3;
- temp[4*i+1]= z1+z2;
- temp[4*i+2]= z1-z2;
- temp[4*i+3]= z0-z3;
- }
-
- for(i=0; i<4; i++){
- const int offset= x_offset[i];
- const int z0= temp[4*0+i] + temp[4*2+i];
- const int z1= temp[4*0+i] - temp[4*2+i];
- const int z2= temp[4*1+i] - temp[4*3+i];
- const int z3= temp[4*1+i] + temp[4*3+i];
-
- block[stride*0 +offset]= (z0 + z3)>>1;
- block[stride*2 +offset]= (z1 + z2)>>1;
- block[stride*8 +offset]= (z1 - z2)>>1;
- block[stride*10+offset]= (z0 - z3)>>1;
- }
-}
-#endif
-
-#undef xStride
-#undef stride
-
-static void chroma_dc_dequant_idct_c(DCTELEM *block, int qp, int qmul){
- const int stride= 16*2;
- const int xStride= 16;
- int a,b,c,d,e;
-
- a= block[stride*0 + xStride*0];
- b= block[stride*0 + xStride*1];
- c= block[stride*1 + xStride*0];
- d= block[stride*1 + xStride*1];
-
- e= a-b;
- a= a+b;
- b= c-d;
- c= c+d;
-
- block[stride*0 + xStride*0]= ((a+c)*qmul) >> 7;
- block[stride*0 + xStride*1]= ((e+b)*qmul) >> 7;
- block[stride*1 + xStride*0]= ((a-c)*qmul) >> 7;
- block[stride*1 + xStride*1]= ((e-b)*qmul) >> 7;
-}
-
-#if 0
-static void chroma_dc_dct_c(DCTELEM *block){
- const int stride= 16*2;
- const int xStride= 16;
- int a,b,c,d,e;
-
- a= block[stride*0 + xStride*0];
- b= block[stride*0 + xStride*1];
- c= block[stride*1 + xStride*0];
- d= block[stride*1 + xStride*1];
-
- e= a-b;
- a= a+b;
- b= c-d;
- c= c+d;
-
- block[stride*0 + xStride*0]= (a+c);
- block[stride*0 + xStride*1]= (e+b);
- block[stride*1 + xStride*0]= (a-c);
- block[stride*1 + xStride*1]= (e-b);
-}
-#endif
-
-/**
- * gets the chroma qp.
- */
-static inline int get_chroma_qp(int chroma_qp_index_offset, int qscale){
-
- return chroma_qp[clip(qscale + chroma_qp_index_offset, 0, 51)];
-}
-
-//FIXME need to check that this doesnt overflow signed 32 bit for low qp, i am not sure, it's very close
-//FIXME check that gcc inlines this (and optimizes intra & seperate_dc stuff away)
-static inline int quantize_c(DCTELEM *block, uint8_t *scantable, int qscale, int intra, int seperate_dc){
- int i;
- 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);
- int last_non_zero;
-
- if(seperate_dc){
- if(qscale<=18){
- //avoid overflows
- const int dc_bias= intra ? (1<<(QUANT_SHIFT-2))/3 : (1<<(QUANT_SHIFT-2))/6;
- const unsigned int dc_threshold1= (1<<(QUANT_SHIFT-2)) - dc_bias - 1;
- const unsigned int dc_threshold2= (dc_threshold1<<1);
-
- int level= block[0]*quant_coeff[qscale+18][0];
- if(((unsigned)(level+dc_threshold1))>dc_threshold2){
- if(level>0){
- level= (dc_bias + level)>>(QUANT_SHIFT-2);
- block[0]= level;
- }else{
- level= (dc_bias - level)>>(QUANT_SHIFT-2);
- block[0]= -level;
- }
-// last_non_zero = i;
- }else{
- block[0]=0;
- }
- }else{
- const int dc_bias= intra ? (1<<(QUANT_SHIFT+1))/3 : (1<<(QUANT_SHIFT+1))/6;
- const unsigned int dc_threshold1= (1<<(QUANT_SHIFT+1)) - dc_bias - 1;
- const unsigned int dc_threshold2= (dc_threshold1<<1);
-
- int level= block[0]*quant_table[0];
- if(((unsigned)(level+dc_threshold1))>dc_threshold2){
- if(level>0){
- level= (dc_bias + level)>>(QUANT_SHIFT+1);
- block[0]= level;
- }else{
- level= (dc_bias - level)>>(QUANT_SHIFT+1);
- block[0]= -level;
- }
-// last_non_zero = i;
- }else{
- block[0]=0;
- }
- }
- last_non_zero= 0;
- i=1;
- }else{
- last_non_zero= -1;
- i=0;
- }
-
- for(; i<16; i++){
- const int j= scantable[i];
- int level= block[j]*quant_table[j];
-
-// if( bias+level >= (1<<(QMAT_SHIFT - 3))
-// || bias-level >= (1<<(QMAT_SHIFT - 3))){
- if(((unsigned)(level+threshold1))>threshold2){
- if(level>0){
- level= (bias + level)>>QUANT_SHIFT;
- block[j]= level;
- }else{
- level= (bias - level)>>QUANT_SHIFT;
- block[j]= -level;
- }
- last_non_zero = i;
- }else{
- block[j]=0;
- }
- }
-
- return last_non_zero;
-}
-
-static void pred4x4_vertical_c(uint8_t *src, uint8_t *topright, int stride){
- const uint32_t a= ((uint32_t*)(src-stride))[0];
- ((uint32_t*)(src+0*stride))[0]= a;
- ((uint32_t*)(src+1*stride))[0]= a;
- ((uint32_t*)(src+2*stride))[0]= a;
- ((uint32_t*)(src+3*stride))[0]= a;
-}
-
-static void pred4x4_horizontal_c(uint8_t *src, uint8_t *topright, int stride){
- ((uint32_t*)(src+0*stride))[0]= src[-1+0*stride]*0x01010101;
- ((uint32_t*)(src+1*stride))[0]= src[-1+1*stride]*0x01010101;
- ((uint32_t*)(src+2*stride))[0]= src[-1+2*stride]*0x01010101;
- ((uint32_t*)(src+3*stride))[0]= src[-1+3*stride]*0x01010101;
-}
-
-static void pred4x4_dc_c(uint8_t *src, uint8_t *topright, int stride){
- const int dc= ( src[-stride] + src[1-stride] + src[2-stride] + src[3-stride]
- + src[-1+0*stride] + src[-1+1*stride] + src[-1+2*stride] + src[-1+3*stride] + 4) >>3;
-
- ((uint32_t*)(src+0*stride))[0]=
- ((uint32_t*)(src+1*stride))[0]=
- ((uint32_t*)(src+2*stride))[0]=
- ((uint32_t*)(src+3*stride))[0]= dc* 0x01010101;
-}
-
-static void pred4x4_left_dc_c(uint8_t *src, uint8_t *topright, int stride){
- const int dc= ( src[-1+0*stride] + src[-1+1*stride] + src[-1+2*stride] + src[-1+3*stride] + 2) >>2;
-
- ((uint32_t*)(src+0*stride))[0]=
- ((uint32_t*)(src+1*stride))[0]=
- ((uint32_t*)(src+2*stride))[0]=
- ((uint32_t*)(src+3*stride))[0]= dc* 0x01010101;
-}
-
-static void pred4x4_top_dc_c(uint8_t *src, uint8_t *topright, int stride){
- const int dc= ( src[-stride] + src[1-stride] + src[2-stride] + src[3-stride] + 2) >>2;
-
- ((uint32_t*)(src+0*stride))[0]=
- ((uint32_t*)(src+1*stride))[0]=
- ((uint32_t*)(src+2*stride))[0]=
- ((uint32_t*)(src+3*stride))[0]= dc* 0x01010101;
-}
-
-static void pred4x4_128_dc_c(uint8_t *src, uint8_t *topright, int stride){
- ((uint32_t*)(src+0*stride))[0]=
- ((uint32_t*)(src+1*stride))[0]=
- ((uint32_t*)(src+2*stride))[0]=
- ((uint32_t*)(src+3*stride))[0]= 128U*0x01010101U;
-}
-
-
-#define LOAD_TOP_RIGHT_EDGE\
- const int t4= topright[0];\
- const int t5= topright[1];\
- const int t6= topright[2];\
- const int t7= topright[3];\
-
-#define LOAD_LEFT_EDGE\
- const int l0= src[-1+0*stride];\
- const int l1= src[-1+1*stride];\
- const int l2= src[-1+2*stride];\
- const int l3= src[-1+3*stride];\
-
-#define LOAD_TOP_EDGE\
- const int t0= src[ 0-1*stride];\
- const int t1= src[ 1-1*stride];\
- const int t2= src[ 2-1*stride];\
- const int t3= src[ 3-1*stride];\
-
-static void pred4x4_down_right_c(uint8_t *src, uint8_t *topright, int stride){
- const int lt= src[-1-1*stride];
- LOAD_TOP_EDGE
- LOAD_LEFT_EDGE
-
- src[0+3*stride]=(l3 + 2*l2 + l1 + 2)>>2;
- src[0+2*stride]=
- src[1+3*stride]=(l2 + 2*l1 + l0 + 2)>>2;
- src[0+1*stride]=
- src[1+2*stride]=
- src[2+3*stride]=(l1 + 2*l0 + lt + 2)>>2;
- src[0+0*stride]=
- src[1+1*stride]=
- src[2+2*stride]=
- src[3+3*stride]=(l0 + 2*lt + t0 + 2)>>2;
- src[1+0*stride]=
- src[2+1*stride]=
- src[3+2*stride]=(lt + 2*t0 + t1 + 2)>>2;
- src[2+0*stride]=
- src[3+1*stride]=(t0 + 2*t1 + t2 + 2)>>2;
- src[3+0*stride]=(t1 + 2*t2 + t3 + 2)>>2;
-}
-
-static void pred4x4_down_left_c(uint8_t *src, uint8_t *topright, int stride){
- LOAD_TOP_EDGE
- LOAD_TOP_RIGHT_EDGE
-// LOAD_LEFT_EDGE
-
- src[0+0*stride]=(t0 + t2 + 2*t1 + 2)>>2;
- src[1+0*stride]=
- src[0+1*stride]=(t1 + t3 + 2*t2 + 2)>>2;
- src[2+0*stride]=
- src[1+1*stride]=
- src[0+2*stride]=(t2 + t4 + 2*t3 + 2)>>2;
- src[3+0*stride]=
- src[2+1*stride]=
- src[1+2*stride]=
- src[0+3*stride]=(t3 + t5 + 2*t4 + 2)>>2;
- src[3+1*stride]=
- src[2+2*stride]=
- src[1+3*stride]=(t4 + t6 + 2*t5 + 2)>>2;
- src[3+2*stride]=
- src[2+3*stride]=(t5 + t7 + 2*t6 + 2)>>2;
- src[3+3*stride]=(t6 + 3*t7 + 2)>>2;
-}
-
-static void pred4x4_vertical_right_c(uint8_t *src, uint8_t *topright, int stride){
- const int lt= src[-1-1*stride];
- LOAD_TOP_EDGE
- LOAD_LEFT_EDGE
- const __attribute__((unused)) int unu= l3;
-
- src[0+0*stride]=
- src[1+2*stride]=(lt + t0 + 1)>>1;
- src[1+0*stride]=
- src[2+2*stride]=(t0 + t1 + 1)>>1;
- src[2+0*stride]=
- src[3+2*stride]=(t1 + t2 + 1)>>1;
- src[3+0*stride]=(t2 + t3 + 1)>>1;
- src[0+1*stride]=
- src[1+3*stride]=(l0 + 2*lt + t0 + 2)>>2;
- src[1+1*stride]=
- src[2+3*stride]=(lt + 2*t0 + t1 + 2)>>2;
- src[2+1*stride]=
- src[3+3*stride]=(t0 + 2*t1 + t2 + 2)>>2;
- src[3+1*stride]=(t1 + 2*t2 + t3 + 2)>>2;
- src[0+2*stride]=(lt + 2*l0 + l1 + 2)>>2;
- src[0+3*stride]=(l0 + 2*l1 + l2 + 2)>>2;
-}
-
-static void pred4x4_vertical_left_c(uint8_t *src, uint8_t *topright, int stride){
- LOAD_TOP_EDGE
- LOAD_TOP_RIGHT_EDGE
- const __attribute__((unused)) int unu= t7;
-
- src[0+0*stride]=(t0 + t1 + 1)>>1;
- src[1+0*stride]=
- src[0+2*stride]=(t1 + t2 + 1)>>1;
- src[2+0*stride]=
- src[1+2*stride]=(t2 + t3 + 1)>>1;
- src[3+0*stride]=
- src[2+2*stride]=(t3 + t4+ 1)>>1;
- src[3+2*stride]=(t4 + t5+ 1)>>1;
- src[0+1*stride]=(t0 + 2*t1 + t2 + 2)>>2;
- src[1+1*stride]=
- src[0+3*stride]=(t1 + 2*t2 + t3 + 2)>>2;
- src[2+1*stride]=
- src[1+3*stride]=(t2 + 2*t3 + t4 + 2)>>2;
- src[3+1*stride]=
- src[2+3*stride]=(t3 + 2*t4 + t5 + 2)>>2;
- src[3+3*stride]=(t4 + 2*t5 + t6 + 2)>>2;
-}
-
-static void pred4x4_horizontal_up_c(uint8_t *src, uint8_t *topright, int stride){
- LOAD_LEFT_EDGE
-
- src[0+0*stride]=(l0 + l1 + 1)>>1;
- src[1+0*stride]=(l0 + 2*l1 + l2 + 2)>>2;
- src[2+0*stride]=
- src[0+1*stride]=(l1 + l2 + 1)>>1;
- src[3+0*stride]=
- src[1+1*stride]=(l1 + 2*l2 + l3 + 2)>>2;
- src[2+1*stride]=
- src[0+2*stride]=(l2 + l3 + 1)>>1;
- src[3+1*stride]=
- src[1+2*stride]=(l2 + 2*l3 + l3 + 2)>>2;
- src[3+2*stride]=
- src[1+3*stride]=
- src[0+3*stride]=
- src[2+2*stride]=
- src[2+3*stride]=
- src[3+3*stride]=l3;
-}
-
-static void pred4x4_horizontal_down_c(uint8_t *src, uint8_t *topright, int stride){
- const int lt= src[-1-1*stride];
- LOAD_TOP_EDGE
- LOAD_LEFT_EDGE
- const __attribute__((unused)) int unu= t3;
-
- src[0+0*stride]=
- src[2+1*stride]=(lt + l0 + 1)>>1;
- src[1+0*stride]=
- src[3+1*stride]=(l0 + 2*lt + t0 + 2)>>2;
- src[2+0*stride]=(lt + 2*t0 + t1 + 2)>>2;
- src[3+0*stride]=(t0 + 2*t1 + t2 + 2)>>2;
- src[0+1*stride]=
- src[2+2*stride]=(l0 + l1 + 1)>>1;
- src[1+1*stride]=
- src[3+2*stride]=(lt + 2*l0 + l1 + 2)>>2;
- src[0+2*stride]=
- src[2+3*stride]=(l1 + l2+ 1)>>1;
- src[1+2*stride]=
- src[3+3*stride]=(l0 + 2*l1 + l2 + 2)>>2;
- src[0+3*stride]=(l2 + l3 + 1)>>1;
- src[1+3*stride]=(l1 + 2*l2 + l3 + 2)>>2;
-}
-
-void ff_pred16x16_vertical_c(uint8_t *src, int stride){
- int i;
- const uint32_t a= ((uint32_t*)(src-stride))[0];
- const uint32_t b= ((uint32_t*)(src-stride))[1];
- const uint32_t c= ((uint32_t*)(src-stride))[2];
- const uint32_t d= ((uint32_t*)(src-stride))[3];
-
- for(i=0; i<16; i++){
- ((uint32_t*)(src+i*stride))[0]= a;
- ((uint32_t*)(src+i*stride))[1]= b;
- ((uint32_t*)(src+i*stride))[2]= c;
- ((uint32_t*)(src+i*stride))[3]= d;
- }
-}
-
-void ff_pred16x16_horizontal_c(uint8_t *src, int stride){
- int i;
-
- for(i=0; i<16; i++){
- ((uint32_t*)(src+i*stride))[0]=
- ((uint32_t*)(src+i*stride))[1]=
- ((uint32_t*)(src+i*stride))[2]=
- ((uint32_t*)(src+i*stride))[3]= src[-1+i*stride]*0x01010101;
- }
-}
-
-void ff_pred16x16_dc_c(uint8_t *src, int stride){
- int i, dc=0;
-
- for(i=0;i<16; i++){
- dc+= src[-1+i*stride];
- }
-
- for(i=0;i<16; i++){
- dc+= src[i-stride];
- }
-
- dc= 0x01010101*((dc + 16)>>5);
-
- for(i=0; i<16; i++){
- ((uint32_t*)(src+i*stride))[0]=
- ((uint32_t*)(src+i*stride))[1]=
- ((uint32_t*)(src+i*stride))[2]=
- ((uint32_t*)(src+i*stride))[3]= dc;
- }
-}
-
-static void pred16x16_left_dc_c(uint8_t *src, int stride){
- int i, dc=0;
-
- for(i=0;i<16; i++){
- dc+= src[-1+i*stride];
- }
-
- dc= 0x01010101*((dc + 8)>>4);
-
- for(i=0; i<16; i++){
- ((uint32_t*)(src+i*stride))[0]=
- ((uint32_t*)(src+i*stride))[1]=
- ((uint32_t*)(src+i*stride))[2]=
- ((uint32_t*)(src+i*stride))[3]= dc;
- }
-}
-
-static void pred16x16_top_dc_c(uint8_t *src, int stride){
- int i, dc=0;
-
- for(i=0;i<16; i++){
- dc+= src[i-stride];
- }
- dc= 0x01010101*((dc + 8)>>4);
-
- for(i=0; i<16; i++){
- ((uint32_t*)(src+i*stride))[0]=
- ((uint32_t*)(src+i*stride))[1]=
- ((uint32_t*)(src+i*stride))[2]=
- ((uint32_t*)(src+i*stride))[3]= dc;
- }
-}
-
-void ff_pred16x16_128_dc_c(uint8_t *src, int stride){
- int i;
-
- for(i=0; i<16; i++){
- ((uint32_t*)(src+i*stride))[0]=
- ((uint32_t*)(src+i*stride))[1]=
- ((uint32_t*)(src+i*stride))[2]=
- ((uint32_t*)(src+i*stride))[3]= 0x01010101U*128U;
- }
-}
-
-static inline void pred16x16_plane_compat_c(uint8_t *src, int stride, const int svq3){
- int i, j, k;
- int a;
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
- const uint8_t * const src0 = src+7-stride;
- const uint8_t *src1 = src+8*stride-1;
- const uint8_t *src2 = src1-2*stride; // == src+6*stride-1;
- int H = src0[1] - src0[-1];
- int V = src1[0] - src2[ 0];
- for(k=2; k<=8; ++k) {
- src1 += stride; src2 -= stride;
- H += k*(src0[k] - src0[-k]);
- V += k*(src1[0] - src2[ 0]);
- }
- if(svq3){
- H = ( 5*(H/4) ) / 16;
- V = ( 5*(V/4) ) / 16;
-
- /* required for 100% accuracy */
- i = H; H = V; V = i;
- }else{
- H = ( 5*H+32 ) >> 6;
- V = ( 5*V+32 ) >> 6;
- }
-
- a = 16*(src1[0] + src2[16] + 1) - 7*(V+H);
- for(j=16; j>0; --j) {
- int b = a;
- a += V;
- for(i=-16; i<0; i+=4) {
- src[16+i] = cm[ (b ) >> 5 ];
- src[17+i] = cm[ (b+ H) >> 5 ];
- src[18+i] = cm[ (b+2*H) >> 5 ];
- src[19+i] = cm[ (b+3*H) >> 5 ];
- b += 4*H;
- }
- src += stride;
- }
-}
-
-void ff_pred16x16_plane_c(uint8_t *src, int stride){
- pred16x16_plane_compat_c(src, stride, 0);
-}
-
-void ff_pred8x8_vertical_c(uint8_t *src, int stride){
- int i;
- const uint32_t a= ((uint32_t*)(src-stride))[0];
- const uint32_t b= ((uint32_t*)(src-stride))[1];
-
- for(i=0; i<8; i++){
- ((uint32_t*)(src+i*stride))[0]= a;
- ((uint32_t*)(src+i*stride))[1]= b;
- }
-}
-
-void ff_pred8x8_horizontal_c(uint8_t *src, int stride){
- int i;
-
- for(i=0; i<8; i++){
- ((uint32_t*)(src+i*stride))[0]=
- ((uint32_t*)(src+i*stride))[1]= src[-1+i*stride]*0x01010101;
- }
-}
-
-void ff_pred8x8_128_dc_c(uint8_t *src, int stride){
- int i;
-
- for(i=0; i<8; i++){
- ((uint32_t*)(src+i*stride))[0]=
- ((uint32_t*)(src+i*stride))[1]= 0x01010101U*128U;
- }
-}
-
-static void pred8x8_left_dc_c(uint8_t *src, int stride){
- int i;
- int dc0, dc2;
-
- dc0=dc2=0;
- for(i=0;i<4; i++){
- dc0+= src[-1+i*stride];
- dc2+= src[-1+(i+4)*stride];
- }
- dc0= 0x01010101*((dc0 + 2)>>2);
- dc2= 0x01010101*((dc2 + 2)>>2);
-
- for(i=0; i<4; i++){
- ((uint32_t*)(src+i*stride))[0]=
- ((uint32_t*)(src+i*stride))[1]= dc0;
- }
- for(i=4; i<8; i++){
- ((uint32_t*)(src+i*stride))[0]=
- ((uint32_t*)(src+i*stride))[1]= dc2;
- }
-}
-
-static void pred8x8_top_dc_c(uint8_t *src, int stride){
- int i;
- int dc0, dc1;
-
- dc0=dc1=0;
- for(i=0;i<4; i++){
- dc0+= src[i-stride];
- dc1+= src[4+i-stride];
- }
- dc0= 0x01010101*((dc0 + 2)>>2);
- dc1= 0x01010101*((dc1 + 2)>>2);
-
- for(i=0; i<4; i++){
- ((uint32_t*)(src+i*stride))[0]= dc0;
- ((uint32_t*)(src+i*stride))[1]= dc1;
- }
- for(i=4; i<8; i++){
- ((uint32_t*)(src+i*stride))[0]= dc0;
- ((uint32_t*)(src+i*stride))[1]= dc1;
- }
-}
-
-
-void ff_pred8x8_dc_c(uint8_t *src, int stride){
- int i;
- int dc0, dc1, dc2, dc3;
-
- dc0=dc1=dc2=0;
- for(i=0;i<4; i++){
- dc0+= src[-1+i*stride] + src[i-stride];
- dc1+= src[4+i-stride];
- dc2+= src[-1+(i+4)*stride];
- }
- dc3= 0x01010101*((dc1 + dc2 + 4)>>3);
- dc0= 0x01010101*((dc0 + 4)>>3);
- dc1= 0x01010101*((dc1 + 2)>>2);
- dc2= 0x01010101*((dc2 + 2)>>2);
-
- for(i=0; i<4; i++){
- ((uint32_t*)(src+i*stride))[0]= dc0;
- ((uint32_t*)(src+i*stride))[1]= dc1;
- }
- for(i=4; i<8; i++){
- ((uint32_t*)(src+i*stride))[0]= dc2;
- ((uint32_t*)(src+i*stride))[1]= dc3;
- }
-}
-
-void ff_pred8x8_plane_c(uint8_t *src, int stride){
- int j, k;
- int a;
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
- const uint8_t * const src0 = src+3-stride;
- const uint8_t *src1 = src+4*stride-1;
- const uint8_t *src2 = src1-2*stride; // == src+2*stride-1;
- int H = src0[1] - src0[-1];
- int V = src1[0] - src2[ 0];
- for(k=2; k<=4; ++k) {
- src1 += stride; src2 -= stride;
- H += k*(src0[k] - src0[-k]);
- V += k*(src1[0] - src2[ 0]);
- }
- H = ( 17*H+16 ) >> 5;
- V = ( 17*V+16 ) >> 5;
-
- a = 16*(src1[0] + src2[8]+1) - 3*(V+H);
- for(j=8; j>0; --j) {
- int b = a;
- a += V;
- src[0] = cm[ (b ) >> 5 ];
- src[1] = cm[ (b+ H) >> 5 ];
- src[2] = cm[ (b+2*H) >> 5 ];
- src[3] = cm[ (b+3*H) >> 5 ];
- src[4] = cm[ (b+4*H) >> 5 ];
- src[5] = cm[ (b+5*H) >> 5 ];
- src[6] = cm[ (b+6*H) >> 5 ];
- src[7] = cm[ (b+7*H) >> 5 ];
- src += stride;
- }
-}
-
-#define SRC(x,y) src[(x)+(y)*stride]
-#define PL(y) \
- const int l##y = (SRC(-1,y-1) + 2*SRC(-1,y) + SRC(-1,y+1) + 2) >> 2;
-#define PREDICT_8x8_LOAD_LEFT \
- const int l0 = ((has_topleft ? SRC(-1,-1) : SRC(-1,0)) \
- + 2*SRC(-1,0) + SRC(-1,1) + 2) >> 2; \
- PL(1) PL(2) PL(3) PL(4) PL(5) PL(6) \
- const int l7 attribute_unused = (SRC(-1,6) + 3*SRC(-1,7) + 2) >> 2
-
-#define PT(x) \
- const int t##x = (SRC(x-1,-1) + 2*SRC(x,-1) + SRC(x+1,-1) + 2) >> 2;
-#define PREDICT_8x8_LOAD_TOP \
- const int t0 = ((has_topleft ? SRC(-1,-1) : SRC(0,-1)) \
- + 2*SRC(0,-1) + SRC(1,-1) + 2) >> 2; \
- PT(1) PT(2) PT(3) PT(4) PT(5) PT(6) \
- const int t7 attribute_unused = ((has_topright ? SRC(8,-1) : SRC(7,-1)) \
- + 2*SRC(7,-1) + SRC(6,-1) + 2) >> 2
-
-#define PTR(x) \
- t##x = (SRC(x-1,-1) + 2*SRC(x,-1) + SRC(x+1,-1) + 2) >> 2;
-#define PREDICT_8x8_LOAD_TOPRIGHT \
- int t8, t9, t10, t11, t12, t13, t14, t15; \
- if(has_topright) { \
- PTR(8) PTR(9) PTR(10) PTR(11) PTR(12) PTR(13) PTR(14) \
- t15 = (SRC(14,-1) + 3*SRC(15,-1) + 2) >> 2; \
- } else t8=t9=t10=t11=t12=t13=t14=t15= SRC(7,-1);
-
-#define PREDICT_8x8_LOAD_TOPLEFT \
- const int lt = (SRC(-1,0) + 2*SRC(-1,-1) + SRC(0,-1) + 2) >> 2
-
-#define PREDICT_8x8_DC(v) \
- int y; \
- for( y = 0; y < 8; y++ ) { \
- ((uint32_t*)src)[0] = \
- ((uint32_t*)src)[1] = v; \
- src += stride; \
- }
-
-static void pred8x8l_128_dc_c(uint8_t *src, int has_topleft, int has_topright, int stride)
-{
- PREDICT_8x8_DC(0x80808080);
-}
-static void pred8x8l_left_dc_c(uint8_t *src, int has_topleft, int has_topright, int stride)
-{
- PREDICT_8x8_LOAD_LEFT;
- const uint32_t dc = ((l0+l1+l2+l3+l4+l5+l6+l7+4) >> 3) * 0x01010101;
- PREDICT_8x8_DC(dc);
-}
-static void pred8x8l_top_dc_c(uint8_t *src, int has_topleft, int has_topright, int stride)
-{
- PREDICT_8x8_LOAD_TOP;
- const uint32_t dc = ((t0+t1+t2+t3+t4+t5+t6+t7+4) >> 3) * 0x01010101;
- PREDICT_8x8_DC(dc);
-}
-static void pred8x8l_dc_c(uint8_t *src, int has_topleft, int has_topright, int stride)
-{
- PREDICT_8x8_LOAD_LEFT;
- PREDICT_8x8_LOAD_TOP;
- const uint32_t dc = ((l0+l1+l2+l3+l4+l5+l6+l7
- +t0+t1+t2+t3+t4+t5+t6+t7+8) >> 4) * 0x01010101;
- PREDICT_8x8_DC(dc);
-}
-static void pred8x8l_horizontal_c(uint8_t *src, int has_topleft, int has_topright, int stride)
-{
- PREDICT_8x8_LOAD_LEFT;
-#define ROW(y) ((uint32_t*)(src+y*stride))[0] =\
- ((uint32_t*)(src+y*stride))[1] = 0x01010101 * l##y
- ROW(0); ROW(1); ROW(2); ROW(3); ROW(4); ROW(5); ROW(6); ROW(7);
-#undef ROW
-}
-static void pred8x8l_vertical_c(uint8_t *src, int has_topleft, int has_topright, int stride)
-{
- int y;
- PREDICT_8x8_LOAD_TOP;
- src[0] = t0;
- src[1] = t1;
- src[2] = t2;
- src[3] = t3;
- src[4] = t4;
- src[5] = t5;
- src[6] = t6;
- src[7] = t7;
- for( y = 1; y < 8; y++ )
- *(uint64_t*)(src+y*stride) = *(uint64_t*)src;
-}
-static void pred8x8l_down_left_c(uint8_t *src, int has_topleft, int has_topright, int stride)
-{
- PREDICT_8x8_LOAD_TOP;
- PREDICT_8x8_LOAD_TOPRIGHT;
- SRC(0,0)= (t0 + 2*t1 + t2 + 2) >> 2;
- SRC(0,1)=SRC(1,0)= (t1 + 2*t2 + t3 + 2) >> 2;
- SRC(0,2)=SRC(1,1)=SRC(2,0)= (t2 + 2*t3 + t4 + 2) >> 2;
- SRC(0,3)=SRC(1,2)=SRC(2,1)=SRC(3,0)= (t3 + 2*t4 + t5 + 2) >> 2;
- SRC(0,4)=SRC(1,3)=SRC(2,2)=SRC(3,1)=SRC(4,0)= (t4 + 2*t5 + t6 + 2) >> 2;
- SRC(0,5)=SRC(1,4)=SRC(2,3)=SRC(3,2)=SRC(4,1)=SRC(5,0)= (t5 + 2*t6 + t7 + 2) >> 2;
- SRC(0,6)=SRC(1,5)=SRC(2,4)=SRC(3,3)=SRC(4,2)=SRC(5,1)=SRC(6,0)= (t6 + 2*t7 + t8 + 2) >> 2;
- SRC(0,7)=SRC(1,6)=SRC(2,5)=SRC(3,4)=SRC(4,3)=SRC(5,2)=SRC(6,1)=SRC(7,0)= (t7 + 2*t8 + t9 + 2) >> 2;
- SRC(1,7)=SRC(2,6)=SRC(3,5)=SRC(4,4)=SRC(5,3)=SRC(6,2)=SRC(7,1)= (t8 + 2*t9 + t10 + 2) >> 2;
- SRC(2,7)=SRC(3,6)=SRC(4,5)=SRC(5,4)=SRC(6,3)=SRC(7,2)= (t9 + 2*t10 + t11 + 2) >> 2;
- SRC(3,7)=SRC(4,6)=SRC(5,5)=SRC(6,4)=SRC(7,3)= (t10 + 2*t11 + t12 + 2) >> 2;
- SRC(4,7)=SRC(5,6)=SRC(6,5)=SRC(7,4)= (t11 + 2*t12 + t13 + 2) >> 2;
- SRC(5,7)=SRC(6,6)=SRC(7,5)= (t12 + 2*t13 + t14 + 2) >> 2;
- SRC(6,7)=SRC(7,6)= (t13 + 2*t14 + t15 + 2) >> 2;
- SRC(7,7)= (t14 + 3*t15 + 2) >> 2;
-}
-static void pred8x8l_down_right_c(uint8_t *src, int has_topleft, int has_topright, int stride)
-{
- PREDICT_8x8_LOAD_TOP;
- PREDICT_8x8_LOAD_LEFT;
- PREDICT_8x8_LOAD_TOPLEFT;
- SRC(0,7)= (l7 + 2*l6 + l5 + 2) >> 2;
- SRC(0,6)=SRC(1,7)= (l6 + 2*l5 + l4 + 2) >> 2;
- SRC(0,5)=SRC(1,6)=SRC(2,7)= (l5 + 2*l4 + l3 + 2) >> 2;
- SRC(0,4)=SRC(1,5)=SRC(2,6)=SRC(3,7)= (l4 + 2*l3 + l2 + 2) >> 2;
- SRC(0,3)=SRC(1,4)=SRC(2,5)=SRC(3,6)=SRC(4,7)= (l3 + 2*l2 + l1 + 2) >> 2;
- SRC(0,2)=SRC(1,3)=SRC(2,4)=SRC(3,5)=SRC(4,6)=SRC(5,7)= (l2 + 2*l1 + l0 + 2) >> 2;
- SRC(0,1)=SRC(1,2)=SRC(2,3)=SRC(3,4)=SRC(4,5)=SRC(5,6)=SRC(6,7)= (l1 + 2*l0 + lt + 2) >> 2;
- SRC(0,0)=SRC(1,1)=SRC(2,2)=SRC(3,3)=SRC(4,4)=SRC(5,5)=SRC(6,6)=SRC(7,7)= (l0 + 2*lt + t0 + 2) >> 2;
- SRC(1,0)=SRC(2,1)=SRC(3,2)=SRC(4,3)=SRC(5,4)=SRC(6,5)=SRC(7,6)= (lt + 2*t0 + t1 + 2) >> 2;
- SRC(2,0)=SRC(3,1)=SRC(4,2)=SRC(5,3)=SRC(6,4)=SRC(7,5)= (t0 + 2*t1 + t2 + 2) >> 2;
- SRC(3,0)=SRC(4,1)=SRC(5,2)=SRC(6,3)=SRC(7,4)= (t1 + 2*t2 + t3 + 2) >> 2;
- SRC(4,0)=SRC(5,1)=SRC(6,2)=SRC(7,3)= (t2 + 2*t3 + t4 + 2) >> 2;
- SRC(5,0)=SRC(6,1)=SRC(7,2)= (t3 + 2*t4 + t5 + 2) >> 2;
- SRC(6,0)=SRC(7,1)= (t4 + 2*t5 + t6 + 2) >> 2;
- SRC(7,0)= (t5 + 2*t6 + t7 + 2) >> 2;
-
-}
-static void pred8x8l_vertical_right_c(uint8_t *src, int has_topleft, int has_topright, int stride)
-{
- PREDICT_8x8_LOAD_TOP;
- PREDICT_8x8_LOAD_LEFT;
- PREDICT_8x8_LOAD_TOPLEFT;
- SRC(0,6)= (l5 + 2*l4 + l3 + 2) >> 2;
- SRC(0,7)= (l6 + 2*l5 + l4 + 2) >> 2;
- SRC(0,4)=SRC(1,6)= (l3 + 2*l2 + l1 + 2) >> 2;
- SRC(0,5)=SRC(1,7)= (l4 + 2*l3 + l2 + 2) >> 2;
- SRC(0,2)=SRC(1,4)=SRC(2,6)= (l1 + 2*l0 + lt + 2) >> 2;
- SRC(0,3)=SRC(1,5)=SRC(2,7)= (l2 + 2*l1 + l0 + 2) >> 2;
- SRC(0,1)=SRC(1,3)=SRC(2,5)=SRC(3,7)= (l0 + 2*lt + t0 + 2) >> 2;
- SRC(0,0)=SRC(1,2)=SRC(2,4)=SRC(3,6)= (lt + t0 + 1) >> 1;
- SRC(1,1)=SRC(2,3)=SRC(3,5)=SRC(4,7)= (lt + 2*t0 + t1 + 2) >> 2;
- SRC(1,0)=SRC(2,2)=SRC(3,4)=SRC(4,6)= (t0 + t1 + 1) >> 1;
- SRC(2,1)=SRC(3,3)=SRC(4,5)=SRC(5,7)= (t0 + 2*t1 + t2 + 2) >> 2;
- SRC(2,0)=SRC(3,2)=SRC(4,4)=SRC(5,6)= (t1 + t2 + 1) >> 1;
- SRC(3,1)=SRC(4,3)=SRC(5,5)=SRC(6,7)= (t1 + 2*t2 + t3 + 2) >> 2;
- SRC(3,0)=SRC(4,2)=SRC(5,4)=SRC(6,6)= (t2 + t3 + 1) >> 1;
- SRC(4,1)=SRC(5,3)=SRC(6,5)=SRC(7,7)= (t2 + 2*t3 + t4 + 2) >> 2;
- SRC(4,0)=SRC(5,2)=SRC(6,4)=SRC(7,6)= (t3 + t4 + 1) >> 1;
- SRC(5,1)=SRC(6,3)=SRC(7,5)= (t3 + 2*t4 + t5 + 2) >> 2;
- SRC(5,0)=SRC(6,2)=SRC(7,4)= (t4 + t5 + 1) >> 1;
- SRC(6,1)=SRC(7,3)= (t4 + 2*t5 + t6 + 2) >> 2;
- SRC(6,0)=SRC(7,2)= (t5 + t6 + 1) >> 1;
- SRC(7,1)= (t5 + 2*t6 + t7 + 2) >> 2;
- SRC(7,0)= (t6 + t7 + 1) >> 1;
-}
-static void pred8x8l_horizontal_down_c(uint8_t *src, int has_topleft, int has_topright, int stride)
-{
- PREDICT_8x8_LOAD_TOP;
- PREDICT_8x8_LOAD_LEFT;
- PREDICT_8x8_LOAD_TOPLEFT;
- SRC(0,7)= (l6 + l7 + 1) >> 1;
- SRC(1,7)= (l5 + 2*l6 + l7 + 2) >> 2;
- SRC(0,6)=SRC(2,7)= (l5 + l6 + 1) >> 1;
- SRC(1,6)=SRC(3,7)= (l4 + 2*l5 + l6 + 2) >> 2;
- SRC(0,5)=SRC(2,6)=SRC(4,7)= (l4 + l5 + 1) >> 1;
- SRC(1,5)=SRC(3,6)=SRC(5,7)= (l3 + 2*l4 + l5 + 2) >> 2;
- SRC(0,4)=SRC(2,5)=SRC(4,6)=SRC(6,7)= (l3 + l4 + 1) >> 1;
- SRC(1,4)=SRC(3,5)=SRC(5,6)=SRC(7,7)= (l2 + 2*l3 + l4 + 2) >> 2;
- SRC(0,3)=SRC(2,4)=SRC(4,5)=SRC(6,6)= (l2 + l3 + 1) >> 1;
- SRC(1,3)=SRC(3,4)=SRC(5,5)=SRC(7,6)= (l1 + 2*l2 + l3 + 2) >> 2;
- SRC(0,2)=SRC(2,3)=SRC(4,4)=SRC(6,5)= (l1 + l2 + 1) >> 1;
- SRC(1,2)=SRC(3,3)=SRC(5,4)=SRC(7,5)= (l0 + 2*l1 + l2 + 2) >> 2;
- SRC(0,1)=SRC(2,2)=SRC(4,3)=SRC(6,4)= (l0 + l1 + 1) >> 1;
- SRC(1,1)=SRC(3,2)=SRC(5,3)=SRC(7,4)= (lt + 2*l0 + l1 + 2) >> 2;
- SRC(0,0)=SRC(2,1)=SRC(4,2)=SRC(6,3)= (lt + l0 + 1) >> 1;
- SRC(1,0)=SRC(3,1)=SRC(5,2)=SRC(7,3)= (l0 + 2*lt + t0 + 2) >> 2;
- SRC(2,0)=SRC(4,1)=SRC(6,2)= (t1 + 2*t0 + lt + 2) >> 2;
- SRC(3,0)=SRC(5,1)=SRC(7,2)= (t2 + 2*t1 + t0 + 2) >> 2;
- SRC(4,0)=SRC(6,1)= (t3 + 2*t2 + t1 + 2) >> 2;
- SRC(5,0)=SRC(7,1)= (t4 + 2*t3 + t2 + 2) >> 2;
- SRC(6,0)= (t5 + 2*t4 + t3 + 2) >> 2;
- SRC(7,0)= (t6 + 2*t5 + t4 + 2) >> 2;
-}
-static void pred8x8l_vertical_left_c(uint8_t *src, int has_topleft, int has_topright, int stride)
-{
- PREDICT_8x8_LOAD_TOP;
- PREDICT_8x8_LOAD_TOPRIGHT;
- SRC(0,0)= (t0 + t1 + 1) >> 1;
- SRC(0,1)= (t0 + 2*t1 + t2 + 2) >> 2;
- SRC(0,2)=SRC(1,0)= (t1 + t2 + 1) >> 1;
- SRC(0,3)=SRC(1,1)= (t1 + 2*t2 + t3 + 2) >> 2;
- SRC(0,4)=SRC(1,2)=SRC(2,0)= (t2 + t3 + 1) >> 1;
- SRC(0,5)=SRC(1,3)=SRC(2,1)= (t2 + 2*t3 + t4 + 2) >> 2;
- SRC(0,6)=SRC(1,4)=SRC(2,2)=SRC(3,0)= (t3 + t4 + 1) >> 1;
- SRC(0,7)=SRC(1,5)=SRC(2,3)=SRC(3,1)= (t3 + 2*t4 + t5 + 2) >> 2;
- SRC(1,6)=SRC(2,4)=SRC(3,2)=SRC(4,0)= (t4 + t5 + 1) >> 1;
- SRC(1,7)=SRC(2,5)=SRC(3,3)=SRC(4,1)= (t4 + 2*t5 + t6 + 2) >> 2;
- SRC(2,6)=SRC(3,4)=SRC(4,2)=SRC(5,0)= (t5 + t6 + 1) >> 1;
- SRC(2,7)=SRC(3,5)=SRC(4,3)=SRC(5,1)= (t5 + 2*t6 + t7 + 2) >> 2;
- SRC(3,6)=SRC(4,4)=SRC(5,2)=SRC(6,0)= (t6 + t7 + 1) >> 1;
- SRC(3,7)=SRC(4,5)=SRC(5,3)=SRC(6,1)= (t6 + 2*t7 + t8 + 2) >> 2;
- SRC(4,6)=SRC(5,4)=SRC(6,2)=SRC(7,0)= (t7 + t8 + 1) >> 1;
- SRC(4,7)=SRC(5,5)=SRC(6,3)=SRC(7,1)= (t7 + 2*t8 + t9 + 2) >> 2;
- SRC(5,6)=SRC(6,4)=SRC(7,2)= (t8 + t9 + 1) >> 1;
- SRC(5,7)=SRC(6,5)=SRC(7,3)= (t8 + 2*t9 + t10 + 2) >> 2;
- SRC(6,6)=SRC(7,4)= (t9 + t10 + 1) >> 1;
- SRC(6,7)=SRC(7,5)= (t9 + 2*t10 + t11 + 2) >> 2;
- SRC(7,6)= (t10 + t11 + 1) >> 1;
- SRC(7,7)= (t10 + 2*t11 + t12 + 2) >> 2;
-}
-static void pred8x8l_horizontal_up_c(uint8_t *src, int has_topleft, int has_topright, int stride)
-{
- PREDICT_8x8_LOAD_LEFT;
- SRC(0,0)= (l0 + l1 + 1) >> 1;
- SRC(1,0)= (l0 + 2*l1 + l2 + 2) >> 2;
- SRC(0,1)=SRC(2,0)= (l1 + l2 + 1) >> 1;
- SRC(1,1)=SRC(3,0)= (l1 + 2*l2 + l3 + 2) >> 2;
- SRC(0,2)=SRC(2,1)=SRC(4,0)= (l2 + l3 + 1) >> 1;
- SRC(1,2)=SRC(3,1)=SRC(5,0)= (l2 + 2*l3 + l4 + 2) >> 2;
- SRC(0,3)=SRC(2,2)=SRC(4,1)=SRC(6,0)= (l3 + l4 + 1) >> 1;
- SRC(1,3)=SRC(3,2)=SRC(5,1)=SRC(7,0)= (l3 + 2*l4 + l5 + 2) >> 2;
- SRC(0,4)=SRC(2,3)=SRC(4,2)=SRC(6,1)= (l4 + l5 + 1) >> 1;
- SRC(1,4)=SRC(3,3)=SRC(5,2)=SRC(7,1)= (l4 + 2*l5 + l6 + 2) >> 2;
- SRC(0,5)=SRC(2,4)=SRC(4,3)=SRC(6,2)= (l5 + l6 + 1) >> 1;
- SRC(1,5)=SRC(3,4)=SRC(5,3)=SRC(7,2)= (l5 + 2*l6 + l7 + 2) >> 2;
- SRC(0,6)=SRC(2,5)=SRC(4,4)=SRC(6,3)= (l6 + l7 + 1) >> 1;
- SRC(1,6)=SRC(3,5)=SRC(5,4)=SRC(7,3)= (l6 + 3*l7 + 2) >> 2;
- SRC(0,7)=SRC(1,7)=SRC(2,6)=SRC(2,7)=SRC(3,6)=
- SRC(3,7)=SRC(4,5)=SRC(4,6)=SRC(4,7)=SRC(5,5)=
- SRC(5,6)=SRC(5,7)=SRC(6,4)=SRC(6,5)=SRC(6,6)=
- SRC(6,7)=SRC(7,4)=SRC(7,5)=SRC(7,6)=SRC(7,7)= l7;
-}
-#undef PREDICT_8x8_LOAD_LEFT
-#undef PREDICT_8x8_LOAD_TOP
-#undef PREDICT_8x8_LOAD_TOPLEFT
-#undef PREDICT_8x8_LOAD_TOPRIGHT
-#undef PREDICT_8x8_DC
-#undef PTR
-#undef PT
-#undef PL
-#undef SRC
-
-static inline void mc_dir_part(H264Context *h, Picture *pic, int n, int square, int chroma_height, int delta, int list,
- uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
- int src_x_offset, int src_y_offset,
- qpel_mc_func *qpix_op, h264_chroma_mc_func chroma_op){
- MpegEncContext * const s = &h->s;
- const int mx= h->mv_cache[list][ scan8[n] ][0] + src_x_offset*8;
- int my= h->mv_cache[list][ scan8[n] ][1] + src_y_offset*8;
- const int luma_xy= (mx&3) + ((my&3)<<2);
- uint8_t * src_y = pic->data[0] + (mx>>2) + (my>>2)*h->mb_linesize;
- uint8_t * src_cb, * src_cr;
- int extra_width= h->emu_edge_width;
- int extra_height= h->emu_edge_height;
- int emu=0;
- const int full_mx= mx>>2;
- const int full_my= my>>2;
- const int pic_width = 16*s->mb_width;
- const int pic_height = 16*s->mb_height >> MB_MBAFF;
-
- if(!pic->data[0]) //FIXME this is unacceptable, some senseable error concealment must be done for missing reference frames
- return;
-
- if(mx&7) extra_width -= 3;
- if(my&7) extra_height -= 3;
-
- if( full_mx < 0-extra_width
- || full_my < 0-extra_height
- || full_mx + 16/*FIXME*/ > pic_width + extra_width
- || full_my + 16/*FIXME*/ > pic_height + extra_height){
- ff_emulated_edge_mc(s->edge_emu_buffer, src_y - 2 - 2*h->mb_linesize, h->mb_linesize, 16+5, 16+5/*FIXME*/, full_mx-2, full_my-2, pic_width, pic_height);
- src_y= s->edge_emu_buffer + 2 + 2*h->mb_linesize;
- emu=1;
- }
-
- qpix_op[luma_xy](dest_y, src_y, h->mb_linesize); //FIXME try variable height perhaps?
- if(!square){
- qpix_op[luma_xy](dest_y + delta, src_y + delta, h->mb_linesize);
- }
-
- if(s->flags&CODEC_FLAG_GRAY) return;
-
- if(MB_MBAFF){
- // chroma offset when predicting from a field of opposite parity
- my += 2 * ((s->mb_y & 1) - (h->ref_cache[list][scan8[n]] & 1));
- emu |= (my>>3) < 0 || (my>>3) + 8 >= (pic_height>>1);
- }
- src_cb= pic->data[1] + (mx>>3) + (my>>3)*h->mb_uvlinesize;
- src_cr= pic->data[2] + (mx>>3) + (my>>3)*h->mb_uvlinesize;
-
- if(emu){
- ff_emulated_edge_mc(s->edge_emu_buffer, src_cb, h->mb_uvlinesize, 9, 9/*FIXME*/, (mx>>3), (my>>3), pic_width>>1, pic_height>>1);
- src_cb= s->edge_emu_buffer;
- }
- chroma_op(dest_cb, src_cb, h->mb_uvlinesize, chroma_height, mx&7, my&7);
-
- if(emu){
- ff_emulated_edge_mc(s->edge_emu_buffer, src_cr, h->mb_uvlinesize, 9, 9/*FIXME*/, (mx>>3), (my>>3), pic_width>>1, pic_height>>1);
- src_cr= s->edge_emu_buffer;
- }
- chroma_op(dest_cr, src_cr, h->mb_uvlinesize, chroma_height, mx&7, my&7);
-}
-
-static inline void mc_part_std(H264Context *h, int n, int square, int chroma_height, int delta,
- uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
- int x_offset, int y_offset,
- qpel_mc_func *qpix_put, h264_chroma_mc_func chroma_put,
- qpel_mc_func *qpix_avg, h264_chroma_mc_func chroma_avg,
- int list0, int list1){
- MpegEncContext * const s = &h->s;
- qpel_mc_func *qpix_op= qpix_put;
- h264_chroma_mc_func chroma_op= chroma_put;
-
- dest_y += 2*x_offset + 2*y_offset*h-> mb_linesize;
- dest_cb += x_offset + y_offset*h->mb_uvlinesize;
- dest_cr += x_offset + y_offset*h->mb_uvlinesize;
- x_offset += 8*s->mb_x;
- y_offset += 8*(s->mb_y >> MB_MBAFF);
-
- if(list0){
- Picture *ref= &h->ref_list[0][ h->ref_cache[0][ scan8[n] ] ];
- mc_dir_part(h, ref, n, square, chroma_height, delta, 0,
- dest_y, dest_cb, dest_cr, x_offset, y_offset,
- qpix_op, chroma_op);
-
- qpix_op= qpix_avg;
- chroma_op= chroma_avg;
- }
-
- if(list1){
- Picture *ref= &h->ref_list[1][ h->ref_cache[1][ scan8[n] ] ];
- mc_dir_part(h, ref, n, square, chroma_height, delta, 1,
- dest_y, dest_cb, dest_cr, x_offset, y_offset,
- qpix_op, chroma_op);
- }
-}
-
-static inline void mc_part_weighted(H264Context *h, int n, int square, int chroma_height, int delta,
- uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
- int x_offset, int y_offset,
- qpel_mc_func *qpix_put, h264_chroma_mc_func chroma_put,
- h264_weight_func luma_weight_op, h264_weight_func chroma_weight_op,
- h264_biweight_func luma_weight_avg, h264_biweight_func chroma_weight_avg,
- int list0, int list1){
- MpegEncContext * const s = &h->s;
-
- dest_y += 2*x_offset + 2*y_offset*h-> mb_linesize;
- dest_cb += x_offset + y_offset*h->mb_uvlinesize;
- dest_cr += x_offset + y_offset*h->mb_uvlinesize;
- x_offset += 8*s->mb_x;
- y_offset += 8*(s->mb_y >> MB_MBAFF);
-
- if(list0 && list1){
- /* don't optimize for luma-only case, since B-frames usually
- * use implicit weights => chroma too. */
- uint8_t *tmp_cb = s->obmc_scratchpad;
- uint8_t *tmp_cr = s->obmc_scratchpad + 8;
- uint8_t *tmp_y = s->obmc_scratchpad + 8*h->mb_uvlinesize;
- int refn0 = h->ref_cache[0][ scan8[n] ];
- int refn1 = h->ref_cache[1][ scan8[n] ];
-
- mc_dir_part(h, &h->ref_list[0][refn0], n, square, chroma_height, delta, 0,
- dest_y, dest_cb, dest_cr,
- x_offset, y_offset, qpix_put, chroma_put);
- mc_dir_part(h, &h->ref_list[1][refn1], n, square, chroma_height, delta, 1,
- tmp_y, tmp_cb, tmp_cr,
- x_offset, y_offset, qpix_put, chroma_put);
-
- if(h->use_weight == 2){
- int weight0 = h->implicit_weight[refn0][refn1];
- 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]);
- 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]);
- 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]);
- }
- }else{
- int list = list1 ? 1 : 0;
- int refn = h->ref_cache[list][ scan8[n] ];
- Picture *ref= &h->ref_list[list][refn];
- mc_dir_part(h, ref, n, square, chroma_height, delta, list,
- dest_y, dest_cb, dest_cr, x_offset, y_offset,
- 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]);
- 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]);
- 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]);
- }
- }
-}
-
-static inline void mc_part(H264Context *h, int n, int square, int chroma_height, int delta,
- uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
- int x_offset, int y_offset,
- qpel_mc_func *qpix_put, h264_chroma_mc_func chroma_put,
- qpel_mc_func *qpix_avg, h264_chroma_mc_func chroma_avg,
- h264_weight_func *weight_op, h264_biweight_func *weight_avg,
- int list0, int list1){
- if((h->use_weight==2 && list0 && list1
- && (h->implicit_weight[ h->ref_cache[0][scan8[n]] ][ h->ref_cache[1][scan8[n]] ] != 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,
- weight_op[0], weight_op[3], weight_avg[0], weight_avg[3], list0, list1);
- else
- mc_part_std(h, n, square, chroma_height, delta, dest_y, dest_cb, dest_cr,
- x_offset, y_offset, qpix_put, chroma_put, qpix_avg, chroma_avg, list0, list1);
-}
-
-static inline void prefetch_motion(H264Context *h, int list){
- /* fetch pixels for estimated mv 4 macroblocks ahead
- * optimized for 64byte cache lines */
- MpegEncContext * const s = &h->s;
- const int refn = h->ref_cache[list][scan8[0]];
- if(refn >= 0){
- const int mx= (h->mv_cache[list][scan8[0]][0]>>2) + 16*s->mb_x + 8;
- const int my= (h->mv_cache[list][scan8[0]][1]>>2) + 16*s->mb_y;
- uint8_t **src= h->ref_list[list][refn].data;
- int off= mx + (my + (s->mb_x&3)*4)*h->mb_linesize + 64;
- s->dsp.prefetch(src[0]+off, s->linesize, 4);
- off= (mx>>1) + ((my>>1) + (s->mb_x&7))*s->uvlinesize + 64;
- s->dsp.prefetch(src[1]+off, src[2]-src[1], 2);
- }
-}
-
-static void hl_motion(H264Context *h, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
- qpel_mc_func (*qpix_put)[16], h264_chroma_mc_func (*chroma_put),
- qpel_mc_func (*qpix_avg)[16], h264_chroma_mc_func (*chroma_avg),
- h264_weight_func *weight_op, h264_biweight_func *weight_avg){
- MpegEncContext * const s = &h->s;
- const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
- const int mb_type= s->current_picture.mb_type[mb_xy];
-
- assert(IS_INTER(mb_type));
-
- prefetch_motion(h, 0);
-
- 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],
- 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,
- qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0],
- &weight_op[1], &weight_avg[1],
- IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1));
- mc_part(h, 8, 0, 4, 8, dest_y, dest_cb, dest_cr, 0, 4,
- qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0],
- &weight_op[1], &weight_avg[1],
- IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1));
- }else if(IS_8X16(mb_type)){
- mc_part(h, 0, 0, 8, 8*h->mb_linesize, dest_y, dest_cb, dest_cr, 0, 0,
- qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],
- &weight_op[2], &weight_avg[2],
- IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1));
- mc_part(h, 4, 0, 8, 8*h->mb_linesize, dest_y, dest_cb, dest_cr, 4, 0,
- qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],
- &weight_op[2], &weight_avg[2],
- IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1));
- }else{
- int i;
-
- assert(IS_8X8(mb_type));
-
- for(i=0; i<4; i++){
- const int sub_mb_type= h->sub_mb_type[i];
- const int n= 4*i;
- int x_offset= (i&1)<<2;
- int y_offset= (i&2)<<1;
-
- if(IS_SUB_8X8(sub_mb_type)){
- mc_part(h, n, 1, 4, 0, dest_y, dest_cb, dest_cr, x_offset, y_offset,
- qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],
- &weight_op[3], &weight_avg[3],
- IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
- }else if(IS_SUB_8X4(sub_mb_type)){
- mc_part(h, n , 0, 2, 4, dest_y, dest_cb, dest_cr, x_offset, y_offset,
- qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1],
- &weight_op[4], &weight_avg[4],
- IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
- mc_part(h, n+2, 0, 2, 4, dest_y, dest_cb, dest_cr, x_offset, y_offset+2,
- qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1],
- &weight_op[4], &weight_avg[4],
- IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
- }else if(IS_SUB_4X8(sub_mb_type)){
- mc_part(h, n , 0, 4, 4*h->mb_linesize, dest_y, dest_cb, dest_cr, x_offset, y_offset,
- qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],
- &weight_op[5], &weight_avg[5],
- IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
- mc_part(h, n+1, 0, 4, 4*h->mb_linesize, dest_y, dest_cb, dest_cr, x_offset+2, y_offset,
- qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],
- &weight_op[5], &weight_avg[5],
- IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
- }else{
- int j;
- assert(IS_SUB_4X4(sub_mb_type));
- for(j=0; j<4; j++){
- int sub_x_offset= x_offset + 2*(j&1);
- int sub_y_offset= y_offset + (j&2);
- mc_part(h, n+j, 1, 2, 0, dest_y, dest_cb, dest_cr, sub_x_offset, sub_y_offset,
- qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],
- &weight_op[6], &weight_avg[6],
- IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
- }
- }
- }
- }
-
- prefetch_motion(h, 1);
-}
-
-static void decode_init_vlc(){
- static int done = 0;
-
- if (!done) {
- int i;
- done = 1;
-
- 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, 1);
-
- for(i=0; i<4; 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, 1);
- }
-
- for(i=0; i<3; i++){
- 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, 1);
- }
- for(i=0; i<15; i++){
- 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, 1);
- }
-
- for(i=0; i<6; i++){
- init_vlc(&run_vlc[i], RUN_VLC_BITS, 7,
- &run_len [i][0], 1, 1,
- &run_bits[i][0], 1, 1, 1);
- }
- init_vlc(&run7_vlc, RUN7_VLC_BITS, 16,
- &run_len [6][0], 1, 1,
- &run_bits[6][0], 1, 1, 1);
- }
-}
-
-/**
- * Sets the intra prediction function pointers.
- */
-static void init_pred_ptrs(H264Context *h){
-// MpegEncContext * const s = &h->s;
-
- h->pred4x4[VERT_PRED ]= pred4x4_vertical_c;
- h->pred4x4[HOR_PRED ]= pred4x4_horizontal_c;
- h->pred4x4[DC_PRED ]= pred4x4_dc_c;
- h->pred4x4[DIAG_DOWN_LEFT_PRED ]= pred4x4_down_left_c;
- h->pred4x4[DIAG_DOWN_RIGHT_PRED]= pred4x4_down_right_c;
- h->pred4x4[VERT_RIGHT_PRED ]= pred4x4_vertical_right_c;
- h->pred4x4[HOR_DOWN_PRED ]= pred4x4_horizontal_down_c;
- h->pred4x4[VERT_LEFT_PRED ]= pred4x4_vertical_left_c;
- h->pred4x4[HOR_UP_PRED ]= pred4x4_horizontal_up_c;
- h->pred4x4[LEFT_DC_PRED ]= pred4x4_left_dc_c;
- h->pred4x4[TOP_DC_PRED ]= pred4x4_top_dc_c;
- h->pred4x4[DC_128_PRED ]= pred4x4_128_dc_c;
-
- h->pred8x8l[VERT_PRED ]= pred8x8l_vertical_c;
- h->pred8x8l[HOR_PRED ]= pred8x8l_horizontal_c;
- h->pred8x8l[DC_PRED ]= pred8x8l_dc_c;
- h->pred8x8l[DIAG_DOWN_LEFT_PRED ]= pred8x8l_down_left_c;
- h->pred8x8l[DIAG_DOWN_RIGHT_PRED]= pred8x8l_down_right_c;
- h->pred8x8l[VERT_RIGHT_PRED ]= pred8x8l_vertical_right_c;
- h->pred8x8l[HOR_DOWN_PRED ]= pred8x8l_horizontal_down_c;
- h->pred8x8l[VERT_LEFT_PRED ]= pred8x8l_vertical_left_c;
- h->pred8x8l[HOR_UP_PRED ]= pred8x8l_horizontal_up_c;
- h->pred8x8l[LEFT_DC_PRED ]= pred8x8l_left_dc_c;
- h->pred8x8l[TOP_DC_PRED ]= pred8x8l_top_dc_c;
- h->pred8x8l[DC_128_PRED ]= pred8x8l_128_dc_c;
-
- h->pred8x8[DC_PRED8x8 ]= ff_pred8x8_dc_c;
- h->pred8x8[VERT_PRED8x8 ]= ff_pred8x8_vertical_c;
- h->pred8x8[HOR_PRED8x8 ]= ff_pred8x8_horizontal_c;
- h->pred8x8[PLANE_PRED8x8 ]= ff_pred8x8_plane_c;
- h->pred8x8[LEFT_DC_PRED8x8]= pred8x8_left_dc_c;
- h->pred8x8[TOP_DC_PRED8x8 ]= pred8x8_top_dc_c;
- h->pred8x8[DC_128_PRED8x8 ]= ff_pred8x8_128_dc_c;
-
- h->pred16x16[DC_PRED8x8 ]= ff_pred16x16_dc_c;
- h->pred16x16[VERT_PRED8x8 ]= ff_pred16x16_vertical_c;
- h->pred16x16[HOR_PRED8x8 ]= ff_pred16x16_horizontal_c;
- h->pred16x16[PLANE_PRED8x8 ]= ff_pred16x16_plane_c;
- h->pred16x16[LEFT_DC_PRED8x8]= pred16x16_left_dc_c;
- h->pred16x16[TOP_DC_PRED8x8 ]= pred16x16_top_dc_c;
- h->pred16x16[DC_128_PRED8x8 ]= ff_pred16x16_128_dc_c;
-}
-
-static void free_tables(H264Context *h){
- av_freep(&h->intra4x4_pred_mode);
- av_freep(&h->chroma_pred_mode_table);
- av_freep(&h->cbp_table);
- av_freep(&h->mvd_table[0]);
- av_freep(&h->mvd_table[1]);
- av_freep(&h->direct_table);
- av_freep(&h->non_zero_count);
- av_freep(&h->slice_table_base);
- av_freep(&h->top_borders[1]);
- av_freep(&h->top_borders[0]);
- h->slice_table= NULL;
-
- av_freep(&h->mb2b_xy);
- av_freep(&h->mb2b8_xy);
-
- av_freep(&h->s.obmc_scratchpad);
-}
-
-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
- h->dequant8_coeff[0] = h->dequant8_buffer[0];
- h->dequant8_coeff[1] = h->dequant8_buffer[1];
-
- for(i=0; i<2; i++ ){
- if(i && !memcmp(h->pps.scaling_matrix8[0], h->pps.scaling_matrix8[1], 64*sizeof(uint8_t))){
- h->dequant8_coeff[1] = h->dequant8_buffer[0];
- break;
- }
-
- for(q=0; q<52; q++){
- int shift = ff_div6[q];
- int idx = ff_rem6[q];
- for(x=0; x<64; x++)
- h->dequant8_coeff[i][q][transpose ? (x>>3)|((x&7)<<3) : x] =
- ((uint32_t)dequant8_coeff_init[idx][ dequant8_coeff_init_scan[((x>>1)&12) | (x&3)] ] *
- h->pps.scaling_matrix8[i][x]) << shift;
- }
- }
-}
-
-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
- for(i=0; i<6; i++ ){
- h->dequant4_coeff[i] = h->dequant4_buffer[i];
- for(j=0; j<i; j++){
- if(!memcmp(h->pps.scaling_matrix4[j], h->pps.scaling_matrix4[i], 16*sizeof(uint8_t))){
- h->dequant4_coeff[i] = h->dequant4_buffer[j];
- break;
- }
- }
- if(j<i)
- continue;
-
- for(q=0; q<52; q++){
- int shift = ff_div6[q] + 2;
- int idx = ff_rem6[q];
- for(x=0; x<16; x++)
- h->dequant4_coeff[i][q][transpose ? (x>>2)|((x<<2)&0xF) : x] =
- ((uint32_t)dequant4_coeff_init[idx][(x&1) + ((x>>2)&1)] *
- h->pps.scaling_matrix4[i][x]) << shift;
- }
- }
-}
-
-static void init_dequant_tables(H264Context *h){
- int i,x;
- init_dequant4_coeff_table(h);
- if(h->pps.transform_8x8_mode)
- init_dequant8_coeff_table(h);
- if(h->sps.transform_bypass){
- for(i=0; i<6; i++)
- for(x=0; x<16; x++)
- h->dequant4_coeff[i][0][x] = 1<<6;
- if(h->pps.transform_8x8_mode)
- for(i=0; i<2; i++)
- for(x=0; x<64; x++)
- h->dequant8_coeff[i][0][x] = 1<<6;
- }
-}
-
-
-/**
- * allocates tables.
- * needs width/height
- */
-static int alloc_tables(H264Context *h){
- MpegEncContext * const s = &h->s;
- const int big_mb_num= s->mb_stride * (s->mb_height+1);
- int x,y;
-
- CHECKED_ALLOCZ(h->intra4x4_pred_mode, big_mb_num * 8 * sizeof(uint8_t))
-
- 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(uint8_t))
- CHECKED_ALLOCZ(h->top_borders[0] , s->mb_width * (16+8+8) * sizeof(uint8_t))
- CHECKED_ALLOCZ(h->top_borders[1] , s->mb_width * (16+8+8) * sizeof(uint8_t))
- CHECKED_ALLOCZ(h->cbp_table, big_mb_num * sizeof(uint16_t))
-
- if( h->pps.cabac ) {
- 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));
- }
-
- memset(h->slice_table_base, -1, (big_mb_num+s->mb_stride) * sizeof(uint8_t));
- 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));
- for(y=0; y<s->mb_height; y++){
- for(x=0; x<s->mb_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;
- }
- }
-
- s->obmc_scratchpad = NULL;
-
- if(!h->dequant4_coeff[0])
- init_dequant_tables(h);
-
- return 0;
-fail:
- free_tables(h);
- return -1;
-}
-
-static void common_init(H264Context *h){
- MpegEncContext * const s = &h->s;
-
- s->width = s->avctx->width;
- s->height = s->avctx->height;
- s->codec_id= s->avctx->codec->id;
-
- init_pred_ptrs(h);
-
- h->dequant_coeff_pps= -1;
- s->unrestricted_mv=1;
- s->decode=1; //FIXME
-
- memset(h->pps.scaling_matrix4, 16, 6*16*sizeof(uint8_t));
- memset(h->pps.scaling_matrix8, 16, 2*64*sizeof(uint8_t));
-}
-
-static int decode_init(AVCodecContext *avctx){
- H264Context *h= avctx->priv_data;
- MpegEncContext * const s = &h->s;
-
- MPV_decode_defaults(s);
-
- s->avctx = avctx;
- common_init(h);
-
- s->out_format = FMT_H264;
- s->workaround_bugs= avctx->workaround_bugs;
-
- // set defaults
-// s->decode_mb= ff_h263_decode_mb;
- s->low_delay= 1;
- avctx->pix_fmt= PIX_FMT_YUV420P;
-
- 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;
- }
-
- return 0;
-}
-
-static int frame_start(H264Context *h){
- MpegEncContext * const s = &h->s;
- int i;
-
- if(MPV_frame_start(s, s->avctx) < 0)
- return -1;
- ff_er_frame_start(s);
-
- assert(s->linesize && s->uvlinesize);
-
- for(i=0; i<16; i++){
- h->block_offset[i]= 4*((scan8[i] - scan8[0])&7) + 4*s->linesize*((scan8[i] - scan8[0])>>3);
- h->block_offset[24+i]= 4*((scan8[i] - scan8[0])&7) + 8*s->linesize*((scan8[i] - scan8[0])>>3);
- }
- for(i=0; i<4; i++){
- h->block_offset[16+i]=
- h->block_offset[20+i]= 4*((scan8[i] - scan8[0])&7) + 4*s->uvlinesize*((scan8[i] - scan8[0])>>3);
- h->block_offset[24+16+i]=
- h->block_offset[24+20+i]= 4*((scan8[i] - scan8[0])&7) + 8*s->uvlinesize*((scan8[i] - scan8[0])>>3);
- }
-
- /* can't be in alloc_tables because linesize isn't known there.
- * FIXME: redo bipred weight to not require extra buffer? */
- if(!s->obmc_scratchpad)
- 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)
- memset(h->slice_table, -1, (s->mb_height*s->mb_stride-1) * sizeof(uint8_t));
-
-// s->decode= (s->flags&CODEC_FLAG_PSNR) || !s->encoding || s->current_picture.reference /*|| h->contains_intra*/ || 1;
- return 0;
-}
-
-static inline void backup_mb_border(H264Context *h, uint8_t *src_y, uint8_t *src_cb, uint8_t *src_cr, int linesize, int uvlinesize){
- MpegEncContext * const s = &h->s;
- int i;
-
- src_y -= linesize;
- src_cb -= uvlinesize;
- src_cr -= uvlinesize;
-
- // 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[0]= h->top_borders[0][s->mb_x][15];
- for(i=1; i<17; i++){
- h->left_border[i]= src_y[15+i* linesize];
- }
-
- *(uint64_t*)(h->top_borders[0][s->mb_x]+0)= *(uint64_t*)(src_y + 16*linesize);
- *(uint64_t*)(h->top_borders[0][s->mb_x]+8)= *(uint64_t*)(src_y +8+16*linesize);
-
- if(!(s->flags&CODEC_FLAG_GRAY)){
- h->left_border[17 ]= h->top_borders[0][s->mb_x][16+7];
- h->left_border[17+9]= h->top_borders[0][s->mb_x][24+7];
- for(i=1; i<9; i++){
- h->left_border[i+17 ]= src_cb[7+i*uvlinesize];
- h->left_border[i+17+9]= src_cr[7+i*uvlinesize];
- }
- *(uint64_t*)(h->top_borders[0][s->mb_x]+16)= *(uint64_t*)(src_cb+8*uvlinesize);
- *(uint64_t*)(h->top_borders[0][s->mb_x]+24)= *(uint64_t*)(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){
- MpegEncContext * const s = &h->s;
- int temp8, i;
- uint64_t temp64;
- int deblock_left = (s->mb_x > 0);
- int deblock_top = (s->mb_y > 0);
-
- src_y -= linesize + 1;
- src_cb -= uvlinesize + 1;
- src_cr -= uvlinesize + 1;
-
-#define XCHG(a,b,t,xchg)\
-t= a;\
-if(xchg)\
- a= b;\
-b= t;
-
- if(deblock_left){
- for(i = !deblock_top; i<17; i++){
- XCHG(h->left_border[i ], src_y [i* linesize], temp8, xchg);
- }
- }
-
- if(deblock_top){
- XCHG(*(uint64_t*)(h->top_borders[0][s->mb_x]+0), *(uint64_t*)(src_y +1), temp64, xchg);
- XCHG(*(uint64_t*)(h->top_borders[0][s->mb_x]+8), *(uint64_t*)(src_y +9), temp64, 1);
- if(s->mb_x+1 < s->mb_width){
- XCHG(*(uint64_t*)(h->top_borders[0][s->mb_x+1]), *(uint64_t*)(src_y +17), temp64, 1);
- }
- }
-
- if(!(s->flags&CODEC_FLAG_GRAY)){
- if(deblock_left){
- for(i = !deblock_top; i<9; i++){
- XCHG(h->left_border[i+17 ], src_cb[i*uvlinesize], temp8, xchg);
- XCHG(h->left_border[i+17+9], src_cr[i*uvlinesize], temp8, xchg);
- }
- }
- if(deblock_top){
- XCHG(*(uint64_t*)(h->top_borders[0][s->mb_x]+16), *(uint64_t*)(src_cb+1), temp64, 1);
- XCHG(*(uint64_t*)(h->top_borders[0][s->mb_x]+24), *(uint64_t*)(src_cr+1), temp64, 1);
- }
- }
-}
-
-static inline void backup_pair_border(H264Context *h, uint8_t *src_y, uint8_t *src_cb, uint8_t *src_cr, int linesize, int uvlinesize){
- MpegEncContext * const s = &h->s;
- int i;
-
- src_y -= 2 * linesize;
- src_cb -= 2 * uvlinesize;
- src_cr -= 2 * uvlinesize;
-
- // 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[0]= h->top_borders[0][s->mb_x][15];
- h->left_border[1]= h->top_borders[1][s->mb_x][15];
- for(i=2; i<34; i++){
- h->left_border[i]= src_y[15+i* linesize];
- }
-
- *(uint64_t*)(h->top_borders[0][s->mb_x]+0)= *(uint64_t*)(src_y + 32*linesize);
- *(uint64_t*)(h->top_borders[0][s->mb_x]+8)= *(uint64_t*)(src_y +8+32*linesize);
- *(uint64_t*)(h->top_borders[1][s->mb_x]+0)= *(uint64_t*)(src_y + 33*linesize);
- *(uint64_t*)(h->top_borders[1][s->mb_x]+8)= *(uint64_t*)(src_y +8+33*linesize);
-
- if(!(s->flags&CODEC_FLAG_GRAY)){
- h->left_border[34 ]= h->top_borders[0][s->mb_x][16+7];
- h->left_border[34+ 1]= h->top_borders[1][s->mb_x][16+7];
- h->left_border[34+18 ]= h->top_borders[0][s->mb_x][24+7];
- h->left_border[34+18+1]= h->top_borders[1][s->mb_x][24+7];
- for(i=2; i<18; i++){
- h->left_border[i+34 ]= src_cb[7+i*uvlinesize];
- h->left_border[i+34+18]= src_cr[7+i*uvlinesize];
- }
- *(uint64_t*)(h->top_borders[0][s->mb_x]+16)= *(uint64_t*)(src_cb+16*uvlinesize);
- *(uint64_t*)(h->top_borders[0][s->mb_x]+24)= *(uint64_t*)(src_cr+16*uvlinesize);
- *(uint64_t*)(h->top_borders[1][s->mb_x]+16)= *(uint64_t*)(src_cb+17*uvlinesize);
- *(uint64_t*)(h->top_borders[1][s->mb_x]+24)= *(uint64_t*)(src_cr+17*uvlinesize);
- }
-}
-
-static inline void xchg_pair_border(H264Context *h, uint8_t *src_y, uint8_t *src_cb, uint8_t *src_cr, int linesize, int uvlinesize, int xchg){
- MpegEncContext * const s = &h->s;
- int temp8, i;
- uint64_t temp64;
- int deblock_left = (s->mb_x > 0);
- int deblock_top = (s->mb_y > 1);
-
- tprintf("xchg_pair_border: src_y:%p src_cb:%p src_cr:%p ls:%d uvls:%d\n", src_y, src_cb, src_cr, linesize, uvlinesize);
-
- src_y -= 2 * linesize + 1;
- src_cb -= 2 * uvlinesize + 1;
- src_cr -= 2 * uvlinesize + 1;
-
-#define XCHG(a,b,t,xchg)\
-t= a;\
-if(xchg)\
- a= b;\
-b= t;
-
- if(deblock_left){
- for(i = (!deblock_top)<<1; i<34; i++){
- XCHG(h->left_border[i ], src_y [i* linesize], temp8, xchg);
- }
- }
-
- if(deblock_top){
- XCHG(*(uint64_t*)(h->top_borders[0][s->mb_x]+0), *(uint64_t*)(src_y +1), temp64, xchg);
- XCHG(*(uint64_t*)(h->top_borders[0][s->mb_x]+8), *(uint64_t*)(src_y +9), temp64, 1);
- XCHG(*(uint64_t*)(h->top_borders[1][s->mb_x]+0), *(uint64_t*)(src_y +1 +linesize), temp64, xchg);
- XCHG(*(uint64_t*)(h->top_borders[1][s->mb_x]+8), *(uint64_t*)(src_y +9 +linesize), temp64, 1);
- if(s->mb_x+1 < s->mb_width){
- XCHG(*(uint64_t*)(h->top_borders[0][s->mb_x+1]), *(uint64_t*)(src_y +17), temp64, 1);
- XCHG(*(uint64_t*)(h->top_borders[1][s->mb_x+1]), *(uint64_t*)(src_y +17 +linesize), temp64, 1);
- }
- }
-
- if(!(s->flags&CODEC_FLAG_GRAY)){
- if(deblock_left){
- for(i = (!deblock_top) << 1; i<18; i++){
- XCHG(h->left_border[i+34 ], src_cb[i*uvlinesize], temp8, xchg);
- XCHG(h->left_border[i+34+18], src_cr[i*uvlinesize], temp8, xchg);
- }
- }
- if(deblock_top){
- XCHG(*(uint64_t*)(h->top_borders[0][s->mb_x]+16), *(uint64_t*)(src_cb+1), temp64, 1);
- XCHG(*(uint64_t*)(h->top_borders[0][s->mb_x]+24), *(uint64_t*)(src_cr+1), temp64, 1);
- XCHG(*(uint64_t*)(h->top_borders[1][s->mb_x]+16), *(uint64_t*)(src_cb+1 +uvlinesize), temp64, 1);
- XCHG(*(uint64_t*)(h->top_borders[1][s->mb_x]+24), *(uint64_t*)(src_cr+1 +uvlinesize), temp64, 1);
- }
- }
-}
-
-static void hl_decode_mb(H264Context *h){
- MpegEncContext * const s = &h->s;
- const int mb_x= s->mb_x;
- const int mb_y= s->mb_y;
- const int mb_xy= mb_x + mb_y*s->mb_stride;
- const int mb_type= s->current_picture.mb_type[mb_xy];
- uint8_t *dest_y, *dest_cb, *dest_cr;
- int linesize, uvlinesize /*dct_offset*/;
- int i;
- int *block_offset = &h->block_offset[0];
- const unsigned int bottom = mb_y & 1;
- const int transform_bypass = (s->qscale == 0 && h->sps.transform_bypass);
- void (*idct_add)(uint8_t *dst, DCTELEM *block, int stride);
- void (*idct_dc_add)(uint8_t *dst, DCTELEM *block, int stride);
-
- if(!s->decode)
- return;
-
- dest_y = s->current_picture.data[0] + (mb_y * 16* s->linesize ) + mb_x * 16;
- dest_cb = s->current_picture.data[1] + (mb_y * 8 * s->uvlinesize) + mb_x * 8;
- dest_cr = s->current_picture.data[2] + (mb_y * 8 * s->uvlinesize) + mb_x * 8;
-
- 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);
-
- if (MB_FIELD) {
- linesize = h->mb_linesize = s->linesize * 2;
- uvlinesize = h->mb_uvlinesize = s->uvlinesize * 2;
- block_offset = &h->block_offset[24];
- if(mb_y&1){ //FIXME move out of this func?
- dest_y -= s->linesize*15;
- dest_cb-= s->uvlinesize*7;
- dest_cr-= s->uvlinesize*7;
- }
- if(FRAME_MBAFF) {
- int list;
- for(list=0; list<2; list++){
- if(!USES_LIST(mb_type, list))
- continue;
- if(IS_16X16(mb_type)){
- int8_t *ref = &h->ref_cache[list][scan8[0]];
- fill_rectangle(ref, 4, 4, 8, 16+*ref^(s->mb_y&1), 1);
- }else{
- for(i=0; i<16; i+=4){
- //FIXME can refs be smaller than 8x8 when !direct_8x8_inference ?
- int ref = h->ref_cache[list][scan8[i]];
- if(ref >= 0)
- fill_rectangle(&h->ref_cache[list][scan8[i]], 2, 2, 8, 16+ref^(s->mb_y&1), 1);
- }
- }
- }
- }
- } else {
- linesize = h->mb_linesize = s->linesize;
- uvlinesize = h->mb_uvlinesize = s->uvlinesize;
-// dct_offset = s->linesize * 16;
- }
-
- if(transform_bypass){
- idct_dc_add =
- idct_add = IS_8x8DCT(mb_type) ? s->dsp.add_pixels8 : s->dsp.add_pixels4;
- }else if(IS_8x8DCT(mb_type)){
- idct_dc_add = s->dsp.h264_idct8_dc_add;
- idct_add = s->dsp.h264_idct8_add;
- }else{
- idct_dc_add = s->dsp.h264_idct_dc_add;
- idct_add = s->dsp.h264_idct_add;
- }
-
- if(FRAME_MBAFF && h->deblocking_filter && IS_INTRA(mb_type)
- && (!bottom || !IS_INTRA(s->current_picture.mb_type[mb_xy-s->mb_stride]))){
- int mbt_y = mb_y&~1;
- uint8_t *top_y = s->current_picture.data[0] + (mbt_y * 16* s->linesize ) + mb_x * 16;
- uint8_t *top_cb = s->current_picture.data[1] + (mbt_y * 8 * s->uvlinesize) + mb_x * 8;
- uint8_t *top_cr = s->current_picture.data[2] + (mbt_y * 8 * s->uvlinesize) + mb_x * 8;
- xchg_pair_border(h, top_y, top_cb, top_cr, s->linesize, s->uvlinesize, 1);
- }
-
- if (IS_INTRA_PCM(mb_type)) {
- unsigned int x, y;
-
- // The pixels are stored in h->mb array in the same order as levels,
- // copy them in output in the correct order.
- for(i=0; i<16; i++) {
- for (y=0; y<4; y++) {
- for (x=0; x<4; x++) {
- *(dest_y + block_offset[i] + y*linesize + x) = h->mb[i*16+y*4+x];
- }
- }
- }
- for(i=16; i<16+4; i++) {
- for (y=0; y<4; y++) {
- for (x=0; x<4; x++) {
- *(dest_cb + block_offset[i] + y*uvlinesize + x) = h->mb[i*16+y*4+x];
- }
- }
- }
- for(i=20; i<20+4; i++) {
- for (y=0; y<4; y++) {
- for (x=0; x<4; x++) {
- *(dest_cr + block_offset[i] + y*uvlinesize + x) = h->mb[i*16+y*4+x];
- }
- }
- }
- } else {
- if(IS_INTRA(mb_type)){
- if(h->deblocking_filter && !FRAME_MBAFF)
- xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 1);
-
- if(!(s->flags&CODEC_FLAG_GRAY)){
- h->pred8x8[ h->chroma_pred_mode ](dest_cb, uvlinesize);
- h->pred8x8[ h->chroma_pred_mode ](dest_cr, uvlinesize);
- }
-
- if(IS_INTRA4x4(mb_type)){
- if(!s->encoding){
- if(IS_8x8DCT(mb_type)){
- for(i=0; i<16; i+=4){
- uint8_t * const ptr= dest_y + block_offset[i];
- const int dir= h->intra4x4_pred_mode_cache[ scan8[i] ];
- const int nnz = h->non_zero_count_cache[ scan8[i] ];
- h->pred8x8l[ dir ](ptr, (h->topleft_samples_available<<i)&0x8000,
- (h->topright_samples_available<<(i+1))&0x8000, linesize);
- if(nnz){
- if(nnz == 1 && h->mb[i*16])
- idct_dc_add(ptr, h->mb + i*16, linesize);
- else
- idct_add(ptr, h->mb + i*16, linesize);
- }
- }
- }else
- for(i=0; i<16; i++){
- uint8_t * const ptr= dest_y + block_offset[i];
- uint8_t *topright;
- const int dir= h->intra4x4_pred_mode_cache[ scan8[i] ];
- int nnz, tr;
-
- if(dir == DIAG_DOWN_LEFT_PRED || dir == VERT_LEFT_PRED){
- const int topright_avail= (h->topright_samples_available<<i)&0x8000;
- assert(mb_y || linesize <= block_offset[i]);
- if(!topright_avail){
- tr= ptr[3 - linesize]*0x01010101;
- topright= (uint8_t*) &tr;
- }else
- topright= ptr + 4 - linesize;
- }else
- topright= NULL;
-
- h->pred4x4[ dir ](ptr, topright, linesize);
- nnz = h->non_zero_count_cache[ scan8[i] ];
- if(nnz){
- if(s->codec_id == CODEC_ID_H264){
- if(nnz == 1 && h->mb[i*16])
- idct_dc_add(ptr, h->mb + i*16, linesize);
- else
- idct_add(ptr, h->mb + i*16, linesize);
- }else
- svq3_add_idct_c(ptr, h->mb + i*16, linesize, s->qscale, 0);
- }
- }
- }
- }else{
- h->pred16x16[ h->intra16x16_pred_mode ](dest_y , linesize);
- if(s->codec_id == CODEC_ID_H264){
- if(!transform_bypass)
- h264_luma_dc_dequant_idct_c(h->mb, s->qscale, h->dequant4_coeff[IS_INTRA(mb_type) ? 0:3][s->qscale][0]);
- }else
- svq3_luma_dc_dequant_idct_c(h->mb, s->qscale);
- }
- if(h->deblocking_filter && !FRAME_MBAFF)
- xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 0);
- }else if(s->codec_id == CODEC_ID_H264){
- 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);
- }
-
-
- if(!IS_INTRA4x4(mb_type)){
- if(s->codec_id == CODEC_ID_H264){
- if(IS_INTRA16x16(mb_type)){
- for(i=0; i<16; i++){
- if(h->non_zero_count_cache[ scan8[i] ])
- idct_add(dest_y + block_offset[i], h->mb + i*16, linesize);
- else if(h->mb[i*16])
- idct_dc_add(dest_y + block_offset[i], h->mb + i*16, linesize);
- }
- }else{
- const int di = IS_8x8DCT(mb_type) ? 4 : 1;
- for(i=0; i<16; i+=di){
- int nnz = h->non_zero_count_cache[ scan8[i] ];
- if(nnz){
- if(nnz==1 && h->mb[i*16])
- idct_dc_add(dest_y + block_offset[i], h->mb + i*16, linesize);
- else
- idct_add(dest_y + block_offset[i], h->mb + i*16, linesize);
- }
- }
- }
- }else{
- 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);
- }
- }
- }
- }
-
- if(!(s->flags&CODEC_FLAG_GRAY)){
- uint8_t *dest[2] = {dest_cb, dest_cr};
- if(transform_bypass){
- idct_add = idct_dc_add = s->dsp.add_pixels4;
- }else{
- idct_add = s->dsp.h264_idct_add;
- idct_dc_add = s->dsp.h264_idct_dc_add;
- chroma_dc_dequant_idct_c(h->mb + 16*16, h->chroma_qp, h->dequant4_coeff[IS_INTRA(mb_type) ? 1:4][h->chroma_qp][0]);
- chroma_dc_dequant_idct_c(h->mb + 16*16+4*16, h->chroma_qp, h->dequant4_coeff[IS_INTRA(mb_type) ? 2:5][h->chroma_qp][0]);
- }
- if(s->codec_id == CODEC_ID_H264){
- 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);
- else if(h->mb[i*16])
- idct_dc_add(dest[(i&4)>>2] + block_offset[i], h->mb + i*16, uvlinesize);
- }
- }else{
- 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);
- }
- }
- }
- }
- }
- if(h->deblocking_filter) {
- if (FRAME_MBAFF) {
- //FIXME try deblocking one mb at a time?
- // the reduction in load/storing mvs and such might outweigh the extra backup/xchg_border
- const int mb_y = s->mb_y - 1;
- uint8_t *pair_dest_y, *pair_dest_cb, *pair_dest_cr;
- const int mb_xy= mb_x + mb_y*s->mb_stride;
- const int mb_type_top = s->current_picture.mb_type[mb_xy];
- const int mb_type_bottom= s->current_picture.mb_type[mb_xy+s->mb_stride];
- if (!bottom) return;
- pair_dest_y = s->current_picture.data[0] + (mb_y * 16* s->linesize ) + mb_x * 16;
- pair_dest_cb = s->current_picture.data[1] + (mb_y * 8 * s->uvlinesize) + mb_x * 8;
- pair_dest_cr = s->current_picture.data[2] + (mb_y * 8 * s->uvlinesize) + mb_x * 8;
-
- if(IS_INTRA(mb_type_top | mb_type_bottom))
- xchg_pair_border(h, pair_dest_y, pair_dest_cb, pair_dest_cr, s->linesize, s->uvlinesize, 0);
-
- backup_pair_border(h, pair_dest_y, pair_dest_cb, pair_dest_cr, s->linesize, s->uvlinesize);
- // deblock a pair
- // top
- s->mb_y--;
- tprintf("call mbaff filter_mb mb_x:%d mb_y:%d pair_dest_y = %p, dest_y = %p\n", mb_x, mb_y, pair_dest_y, dest_y);
- fill_caches(h, mb_type_top, 1); //FIXME don't fill stuff which isn't used by filter_mb
- h->chroma_qp = get_chroma_qp(h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mb_xy]);
- filter_mb(h, mb_x, mb_y, pair_dest_y, pair_dest_cb, pair_dest_cr, linesize, uvlinesize);
- // bottom
- s->mb_y++;
- tprintf("call mbaff filter_mb\n");
- fill_caches(h, mb_type_bottom, 1); //FIXME don't fill stuff which isn't used by filter_mb
- h->chroma_qp = get_chroma_qp(h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mb_xy+s->mb_stride]);
- filter_mb(h, mb_x, mb_y+1, dest_y, dest_cb, dest_cr, linesize, uvlinesize);
- } else {
- tprintf("call filter_mb\n");
- backup_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize);
- fill_caches(h, mb_type, 1); //FIXME don't fill stuff which isn't used by filter_mb
- filter_mb_fast(h, mb_x, mb_y, dest_y, dest_cb, dest_cr, linesize, uvlinesize);
- }
- }
-}
-
-/**
- * fills the default_ref_list.
- */
-static int fill_default_ref_list(H264Context *h){
- MpegEncContext * const s = &h->s;
- int i;
- int smallest_poc_greater_than_current = -1;
- Picture sorted_short_ref[32];
-
- if(h->slice_type==B_TYPE){
- int out_i;
- int limit= INT_MIN;
-
- /* sort frame according to poc in B slice */
- for(out_i=0; out_i<h->short_ref_count; out_i++){
- int best_i=INT_MIN;
- int best_poc=INT_MAX;
-
- for(i=0; i<h->short_ref_count; i++){
- const int poc= h->short_ref[i]->poc;
- if(poc > limit && poc < best_poc){
- best_poc= poc;
- best_i= i;
- }
- }
-
- assert(best_i != INT_MIN);
-
- limit= best_poc;
- sorted_short_ref[out_i]= *h->short_ref[best_i];
- tprintf("sorted poc: %d->%d poc:%d fn:%d\n", best_i, out_i, sorted_short_ref[out_i].poc, sorted_short_ref[out_i].frame_num);
- if (-1 == smallest_poc_greater_than_current) {
- if (h->short_ref[best_i]->poc >= s->current_picture_ptr->poc) {
- smallest_poc_greater_than_current = out_i;
- }
- }
- }
- }
-
- if(s->picture_structure == PICT_FRAME){
- if(h->slice_type==B_TYPE){
- int list;
- tprintf("current poc: %d, smallest_poc_greater_than_current: %d\n", s->current_picture_ptr->poc, smallest_poc_greater_than_current);
-
- // find the largest poc
- for(list=0; list<2; list++){
- int index = 0;
- int j= -99;
- int step= list ? -1 : 1;
-
- for(i=0; i<h->short_ref_count && index < h->ref_count[list]; i++, j+=step) {
- while(j<0 || j>= h->short_ref_count){
- if(j != -99 && step == (list ? -1 : 1))
- return -1;
- step = -step;
- j= smallest_poc_greater_than_current + (step>>1);
- }
- if(sorted_short_ref[j].reference != 3) continue;
- h->default_ref_list[list][index ]= sorted_short_ref[j];
- h->default_ref_list[list][index++].pic_id= sorted_short_ref[j].frame_num;
- }
-
- for(i = 0; i < 16 && index < h->ref_count[ list ]; i++){
- if(h->long_ref[i] == NULL) continue;
- if(h->long_ref[i]->reference != 3) continue;
-
- h->default_ref_list[ list ][index ]= *h->long_ref[i];
- h->default_ref_list[ list ][index++].pic_id= i;;
- }
-
- if(list && (smallest_poc_greater_than_current<=0 || smallest_poc_greater_than_current>=h->short_ref_count) && (1 < index)){
- // swap the two first elements of L1 when
- // L0 and L1 are identical
- Picture temp= h->default_ref_list[1][0];
- h->default_ref_list[1][0] = h->default_ref_list[1][1];
- h->default_ref_list[1][1] = temp;
- }
-
- if(index < h->ref_count[ list ])
- memset(&h->default_ref_list[list][index], 0, sizeof(Picture)*(h->ref_count[ list ] - index));
- }
- }else{
- int index=0;
- for(i=0; i<h->short_ref_count; i++){
- if(h->short_ref[i]->reference != 3) continue; //FIXME refernce field shit
- h->default_ref_list[0][index ]= *h->short_ref[i];
- h->default_ref_list[0][index++].pic_id= h->short_ref[i]->frame_num;
- }
- for(i = 0; i < 16; i++){
- if(h->long_ref[i] == NULL) continue;
- if(h->long_ref[i]->reference != 3) continue;
- h->default_ref_list[0][index ]= *h->long_ref[i];
- h->default_ref_list[0][index++].pic_id= i;;
- }
- if(index < h->ref_count[0])
- memset(&h->default_ref_list[0][index], 0, sizeof(Picture)*(h->ref_count[0] - index));
- }
- }else{ //FIELD
- if(h->slice_type==B_TYPE){
- }else{
- //FIXME second field balh
- }
- }
-#ifdef TRACE
- for (i=0; i<h->ref_count[0]; i++) {
- tprintf("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==B_TYPE){
- for (i=0; i<h->ref_count[1]; i++) {
- tprintf("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[0][i].data[0]);
- }
- }
-#endif
- return 0;
-}
-
-static void print_short_term(H264Context *h);
-static void print_long_term(H264Context *h);
-
-static int decode_ref_pic_list_reordering(H264Context *h){
- MpegEncContext * const s = &h->s;
- int list, index;
-
- print_short_term(h);
- print_long_term(h);
- if(h->slice_type==I_TYPE || h->slice_type==SI_TYPE) return 0; //FIXME move before func
-
- for(list=0; list<2; 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(&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;
-
- 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;
-
- for(i= h->short_ref_count-1; i>=0; i--){
- ref = h->short_ref[i];
- assert(ref->reference == 3);
- assert(!ref->long_ref);
- if(ref->data[0] != NULL && ref->frame_num == pred && ref->long_ref == 0) // ignore non existing pictures by testing data[0] pointer
- break;
- }
- if(i>=0)
- ref->pic_id= ref->frame_num;
- }else{
- pic_id= get_ue_golomb(&s->gb); //long_term_pic_idx
- if(pic_id>31){
- av_log(h->s.avctx, AV_LOG_ERROR, "long_term_pic_idx overflow\n");
- return -1;
- }
- ref = h->long_ref[pic_id];
- if(ref){
- ref->pic_id= pic_id;
- assert(ref->reference == 3);
- 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+1<h->ref_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;
- }
- }else{
- av_log(h->s.avctx, AV_LOG_ERROR, "illegal reordering_of_pic_nums_idc\n");
- return -1;
- }
- }
- }
-
- if(h->slice_type!=B_TYPE) break;
- }
- for(list=0; list<2; list++){
- for(index= 0; index < h->ref_count[list]; index++){
- if(!h->ref_list[list][index].data[0])
- h->ref_list[list][index]= s->current_picture;
- }
- if(h->slice_type!=B_TYPE) break;
- }
-
- if(h->slice_type==B_TYPE && !h->direct_spatial_mv_pred)
- direct_dist_scale_factor(h);
- direct_ref_list_init(h);
- return 0;
-}
-
-static void fill_mbaff_ref_list(H264Context *h){
- int list, i, j;
- for(list=0; list<2; list++){
- for(i=0; i<h->ref_count[list]; i++){
- Picture *frame = &h->ref_list[list][i];
- Picture *field = &h->ref_list[list][16+2*i];
- field[0] = *frame;
- for(j=0; j<3; j++)
- field[0].linesize[j] <<= 1;
- field[1] = field[0];
- for(j=0; j<3; j++)
- field[1].data[j] += frame->linesize[j];
-
- 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; j<h->ref_count[1]; j++){
- for(i=0; i<h->ref_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;
- int luma_def, chroma_def;
-
- h->use_weight= 0;
- h->use_weight_chroma= 0;
- h->luma_log2_weight_denom= get_ue_golomb(&s->gb);
- h->chroma_log2_weight_denom= get_ue_golomb(&s->gb);
- luma_def = 1<<h->luma_log2_weight_denom;
- chroma_def = 1<<h->chroma_log2_weight_denom;
-
- for(list=0; list<2; list++){
- for(i=0; i<h->ref_count[list]; i++){
- int luma_weight_flag, chroma_weight_flag;
-
- 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->use_weight= 1;
- }else{
- h->luma_weight[list][i]= luma_def;
- h->luma_offset[list][i]= 0;
- }
-
- chroma_weight_flag= get_bits1(&s->gb);
- 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->use_weight_chroma= 1;
- }
- }else{
- int j;
- for(j=0; j<2; j++){
- h->chroma_weight[list][i][j]= chroma_def;
- h->chroma_offset[list][i][j]= 0;
- }
- }
- }
- if(h->slice_type != B_TYPE) break;
- }
- h->use_weight= h->use_weight || h->use_weight_chroma;
- return 0;
-}
-
-static void implicit_weight_table(H264Context *h){
- MpegEncContext * const s = &h->s;
- int ref0, ref1;
- int cur_poc = s->current_picture_ptr->poc;
-
- if( h->ref_count[0] == 1 && h->ref_count[1] == 1
- && 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;
- }
-
- 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++){
- int poc0 = h->ref_list[0][ref0].poc;
- for(ref1=0; ref1 < h->ref_count[1]; ref1++){
- int poc1 = h->ref_list[1][ref1].poc;
- int td = clip(poc1 - poc0, -128, 127);
- if(td){
- int tb = clip(cur_poc - poc0, -128, 127);
- int tx = (16384 + (FFABS(td) >> 1)) / td;
- int dist_scale_factor = 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;
- }
- }
-}
-
-static inline void unreference_pic(H264Context *h, Picture *pic){
- int i;
- pic->reference=0;
- if(pic == h->delayed_output_pic)
- pic->reference=1;
- else{
- for(i = 0; h->delayed_pic[i]; i++)
- if(pic == h->delayed_pic[i]){
- pic->reference=1;
- break;
- }
- }
-}
-
-/**
- * instantaneous decoder refresh.
- */
-static void idr(H264Context *h){
- int i;
-
- for(i=0; i<16; i++){
- if (h->long_ref[i] != NULL) {
- unreference_pic(h, h->long_ref[i]);
- h->long_ref[i]= NULL;
- }
- }
- h->long_ref_count=0;
-
- for(i=0; i<h->short_ref_count; i++){
- unreference_pic(h, h->short_ref[i]);
- h->short_ref[i]= NULL;
- }
- h->short_ref_count=0;
-}
-
-/* forget old pics after a seek */
-static void flush_dpb(AVCodecContext *avctx){
- H264Context *h= avctx->priv_data;
- int i;
- for(i=0; i<16; i++) {
- if(h->delayed_pic[i])
- h->delayed_pic[i]->reference= 0;
- h->delayed_pic[i]= NULL;
- }
- if(h->delayed_output_pic)
- h->delayed_output_pic->reference= 0;
- h->delayed_output_pic= NULL;
- idr(h);
- if(h->s.current_picture_ptr)
- h->s.current_picture_ptr->reference= 0;
-}
-
-/**
- *
- * @return the removed picture or NULL if an error occurs
- */
-static Picture * remove_short(H264Context *h, int frame_num){
- MpegEncContext * const s = &h->s;
- 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);
-
- for(i=0; i<h->short_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){
- h->short_ref[i]= NULL;
- memmove(&h->short_ref[i], &h->short_ref[i+1], (h->short_ref_count - i - 1)*sizeof(Picture*));
- h->short_ref_count--;
- return pic;
- }
- }
- return NULL;
-}
-
-/**
- *
- * @return the removed picture or NULL if an error occurs
- */
-static Picture * remove_long(H264Context *h, int i){
- Picture *pic;
-
- pic= h->long_ref[i];
- h->long_ref[i]= NULL;
- if(pic) 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; i<h->short_ref_count; i++){
- Picture *pic= h->short_ref[i];
- av_log(h->s.avctx, AV_LOG_DEBUG, "%d fn:%d poc:%d %p\n", i, pic->frame_num, pic->poc, pic->data[0]);
- }
- }
-}
-
-/**
- * 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, j;
- int current_is_long=0;
- Picture *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; i<mmco_count; i++){
- if(s->avctx->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_frame_num, h->mmco[i].long_index);
-
- switch(mmco[i].opcode){
- case MMCO_SHORT2UNUSED:
- pic= remove_short(h, mmco[i].short_frame_num);
- if(pic)
- unreference_pic(h, pic);
- else if(s->avctx->debug&FF_DEBUG_MMCO)
- av_log(h->s.avctx, AV_LOG_DEBUG, "mmco: remove_short() failure\n");
- break;
- case MMCO_SHORT2LONG:
- pic= remove_long(h, mmco[i].long_index);
- if(pic) unreference_pic(h, pic);
-
- h->long_ref[ mmco[i].long_index ]= remove_short(h, mmco[i].short_frame_num);
- if (h->long_ref[ mmco[i].long_index ]){
- h->long_ref[ mmco[i].long_index ]->long_ref=1;
- h->long_ref_count++;
- }
- break;
- case MMCO_LONG2UNUSED:
- pic= remove_long(h, mmco[i].long_index);
- if(pic)
- unreference_pic(h, pic);
- else if(s->avctx->debug&FF_DEBUG_MMCO)
- av_log(h->s.avctx, AV_LOG_DEBUG, "mmco: remove_long() failure\n");
- break;
- case MMCO_LONG:
- pic= remove_long(h, mmco[i].long_index);
- if(pic) unreference_pic(h, pic);
-
- h->long_ref[ mmco[i].long_index ]= s->current_picture_ptr;
- h->long_ref[ mmco[i].long_index ]->long_ref=1;
- h->long_ref_count++;
-
- current_is_long=1;
- break;
- case MMCO_SET_MAX_LONG:
- assert(mmco[i].long_index <= 16);
- // just remove the long term which index is greater than new max
- for(j = mmco[i].long_index; j<16; j++){
- pic = remove_long(h, j);
- if (pic) unreference_pic(h, pic);
- }
- break;
- case MMCO_RESET:
- while(h->short_ref_count){
- pic= remove_short(h, h->short_ref[0]->frame_num);
- if(pic) unreference_pic(h, pic);
- }
- for(j = 0; j < 16; j++) {
- pic= remove_long(h, j);
- if(pic) unreference_pic(h, pic);
- }
- break;
- default: assert(0);
- }
- }
-
- if(!current_is_long){
- pic= remove_short(h, s->current_picture_ptr->frame_num);
- if(pic){
- unreference_pic(h, 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[0]->long_ref=0;
- h->short_ref_count++;
- }
-
- print_short_term(h);
- print_long_term(h);
- return 0;
-}
-
-static int decode_ref_pic_marking(H264Context *h){
- MpegEncContext * const s = &h->s;
- int i;
-
- if(h->nal_unit_type == NAL_IDR_SLICE){ //FIXME fields
- s->broken_link= get_bits1(&s->gb) -1;
- h->mmco[0].long_index= get_bits1(&s->gb) - 1; // current_long_term_idx
- if(h->mmco[0].long_index == -1)
- h->mmco_index= 0;
- else{
- h->mmco[0].opcode= MMCO_LONG;
- h->mmco_index= 1;
- }
- }else{
- if(get_bits1(&s->gb)){ // adaptive_ref_pic_marking_mode_flag
- for(i= 0; i<MAX_MMCO_COUNT; i++) {
- MMCOOpcode opcode= get_ue_golomb(&s->gb);;
-
- h->mmco[i].opcode= opcode;
- if(opcode==MMCO_SHORT2UNUSED || opcode==MMCO_SHORT2LONG){
- h->mmco[i].short_frame_num= (h->frame_num - get_ue_golomb(&s->gb) - 1) & ((1<<h->sps.log2_max_frame_num)-1); //FIXME fields
-/* if(h->mmco[i].short_frame_num >= h->short_ref_count || h->short_ref[ h->mmco[i].short_frame_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_index= get_ue_golomb(&s->gb);
- if(/*h->mmco[i].long_index >= h->long_ref_count || h->long_ref[ h->mmco[i].long_index ] == NULL*/ long_index >= 16){
- 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_index= long_index;
- }
-
- 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->long_ref_count + h->short_ref_count == h->sps.ref_frame_count){ //FIXME fields
- h->mmco[0].opcode= MMCO_SHORT2UNUSED;
- h->mmco[0].short_frame_num= h->short_ref[ h->short_ref_count - 1 ]->frame_num;
- h->mmco_index= 1;
- }else
- h->mmco_index= 0;
- }
- }
-
- return 0;
-}
-
-static int init_poc(H264Context *h){
- MpegEncContext * const s = &h->s;
- const int max_frame_num= 1<<h->sps.log2_max_frame_num;
- int field_poc[2];
-
- if(h->nal_unit_type == NAL_IDR_SLICE){
- h->frame_num_offset= 0;
- }else{
- if(h->frame_num < h->prev_frame_num)
- h->frame_num_offset= h->prev_frame_num_offset + max_frame_num;
- else
- h->frame_num_offset= h->prev_frame_num_offset;
- }
-
- if(h->sps.poc_type==0){
- const int max_poc_lsb= 1<<h->sps.log2_max_poc_lsb;
-
- if(h->nal_unit_type == NAL_IDR_SLICE){
- h->prev_poc_msb=
- h->prev_poc_lsb= 0;
- }
-
- if (h->poc_lsb < h->prev_poc_lsb && h->prev_poc_lsb - h->poc_lsb >= max_poc_lsb/2)
- h->poc_msb = h->prev_poc_msb + max_poc_lsb;
- else if(h->poc_lsb > h->prev_poc_lsb && h->prev_poc_lsb - h->poc_lsb < -max_poc_lsb/2)
- h->poc_msb = h->prev_poc_msb - max_poc_lsb;
- else
- h->poc_msb = h->prev_poc_msb;
-//printf("poc: %d %d\n", h->poc_msb, h->poc_lsb);
- field_poc[0] =
- field_poc[1] = h->poc_msb + h->poc_lsb;
- if(s->picture_structure == PICT_FRAME)
- field_poc[1] += h->delta_poc_bottom;
- }else if(h->sps.poc_type==1){
- int abs_frame_num, expected_delta_per_poc_cycle, expectedpoc;
- int i;
-
- if(h->sps.poc_cycle_length != 0)
- abs_frame_num = h->frame_num_offset + h->frame_num;
- else
- abs_frame_num = 0;
-
- if(h->nal_ref_idc==0 && abs_frame_num > 0)
- abs_frame_num--;
-
- expected_delta_per_poc_cycle = 0;
- for(i=0; i < h->sps.poc_cycle_length; i++)
- expected_delta_per_poc_cycle += h->sps.offset_for_ref_frame[ i ]; //FIXME integrate during sps parse
-
- if(abs_frame_num > 0){
- int poc_cycle_cnt = (abs_frame_num - 1) / h->sps.poc_cycle_length;
- int frame_num_in_poc_cycle = (abs_frame_num - 1) % h->sps.poc_cycle_length;
-
- expectedpoc = poc_cycle_cnt * expected_delta_per_poc_cycle;
- for(i = 0; i <= frame_num_in_poc_cycle; i++)
- expectedpoc = expectedpoc + h->sps.offset_for_ref_frame[ i ];
- } else
- expectedpoc = 0;
-
- if(h->nal_ref_idc == 0)
- expectedpoc = expectedpoc + h->sps.offset_for_non_ref_pic;
-
- field_poc[0] = expectedpoc + h->delta_poc[0];
- field_poc[1] = field_poc[0] + h->sps.offset_for_top_to_bottom_field;
-
- if(s->picture_structure == PICT_FRAME)
- field_poc[1] += h->delta_poc[1];
- }else{
- int poc;
- if(h->nal_unit_type == NAL_IDR_SLICE){
- poc= 0;
- }else{
- if(h->nal_ref_idc) poc= 2*(h->frame_num_offset + h->frame_num);
- else poc= 2*(h->frame_num_offset + h->frame_num) - 1;
- }
- field_poc[0]= poc;
- field_poc[1]= poc;
- }
-
- if(s->picture_structure != PICT_BOTTOM_FIELD)
- s->current_picture_ptr->field_poc[0]= field_poc[0];
- if(s->picture_structure != PICT_TOP_FIELD)
- s->current_picture_ptr->field_poc[1]= field_poc[1];
- if(s->picture_structure == PICT_FRAME) // FIXME field pix?
- s->current_picture_ptr->poc= FFMIN(field_poc[0], field_poc[1]);
-
- return 0;
-}
-
-/**
- * decodes a slice header.
- * this will allso call MPV_common_init() and frame_start() as needed
- */
-static int decode_slice_header(H264Context *h){
- MpegEncContext * const s = &h->s;
- unsigned int first_mb_in_slice;
- unsigned int pps_id;
- int num_ref_idx_active_override_flag;
- static const uint8_t slice_type_map[5]= {P_TYPE, B_TYPE, I_TYPE, SP_TYPE, SI_TYPE};
- unsigned int slice_type, tmp;
- int default_ref_list_done = 0;
-
- s->current_picture.reference= h->nal_ref_idc != 0;
- s->dropable= h->nal_ref_idc == 0;
-
- first_mb_in_slice= get_ue_golomb(&s->gb);
-
- slice_type= get_ue_golomb(&s->gb);
- if(slice_type > 9){
- av_log(h->s.avctx, AV_LOG_ERROR, "slice type too large (%d) at %d %d\n", h->slice_type, s->mb_x, s->mb_y);
- return -1;
- }
- if(slice_type > 4){
- slice_type -= 5;
- h->slice_type_fixed=1;
- }else
- h->slice_type_fixed=0;
-
- slice_type= slice_type_map[ slice_type ];
- if (slice_type == I_TYPE
- || (h->slice_num != 0 && slice_type == h->slice_type) ) {
- default_ref_list_done = 1;
- }
- h->slice_type= slice_type;
-
- s->pict_type= h->slice_type; // to make a few old func happy, it's wrong though
-
- pps_id= get_ue_golomb(&s->gb);
- if(pps_id>=MAX_PPS_COUNT){
- av_log(h->s.avctx, AV_LOG_ERROR, "pps_id out of range\n");
- return -1;
- }
- h->pps= h->pps_buffer[pps_id];
- if(h->pps.slice_group_count == 0){
- av_log(h->s.avctx, AV_LOG_ERROR, "non existing PPS referenced\n");
- return -1;
- }
-
- h->sps= h->sps_buffer[ h->pps.sps_id ];
- if(h->sps.log2_max_frame_num == 0){
- av_log(h->s.avctx, AV_LOG_ERROR, "non existing SPS referenced\n");
- return -1;
- }
-
- if(h->dequant_coeff_pps != pps_id){
- h->dequant_coeff_pps = pps_id;
- init_dequant_tables(h);
- }
-
- s->mb_width= h->sps.mb_width;
- 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*(h->sps.crop_left + h->sps.crop_right );
- if(h->sps.frame_mbs_only_flag)
- s->height= 16*s->mb_height - 2*(h->sps.crop_top + h->sps.crop_bottom);
- else
- s->height= 16*s->mb_height - 4*(h->sps.crop_top + h->sps.crop_bottom); //FIXME recheck
-
- if (s->context_initialized
- && ( s->width != s->avctx->width || s->height != s->avctx->height)) {
- free_tables(h);
- MPV_common_end(s);
- }
- if (!s->context_initialized) {
- if (MPV_common_init(s) < 0)
- return -1;
-
- if(s->dsp.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{
- int i;
- for(i=0; i<16; i++){
-#define T(x) (x>>2) | ((x<<2) & 0xF)
- h->zigzag_scan[i] = T(zigzag_scan[i]);
- h-> field_scan[i] = T( field_scan[i]);
-#undef T
- }
- }
- if(s->dsp.h264_idct8_add == ff_h264_idct8_add_c){
- memcpy(h->zigzag_scan8x8, zigzag_scan8x8, 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));
- memcpy(h->field_scan8x8_cavlc, field_scan8x8_cavlc, 64*sizeof(uint8_t));
- }else{
- int i;
- for(i=0; i<64; i++){
-#define T(x) (x>>3) | ((x&7)<<3)
- h->zigzag_scan8x8[i] = T(zigzag_scan8x8[i]);
- h->zigzag_scan8x8_cavlc[i] = T(zigzag_scan8x8_cavlc[i]);
- h->field_scan8x8[i] = T(field_scan8x8[i]);
- h->field_scan8x8_cavlc[i] = T(field_scan8x8_cavlc[i]);
-#undef T
- }
- }
- if(h->sps.transform_bypass){ //FIXME same ugly
- h->zigzag_scan_q0 = zigzag_scan;
- h->zigzag_scan8x8_q0 = zigzag_scan8x8;
- h->zigzag_scan8x8_cavlc_q0 = zigzag_scan8x8_cavlc;
- h->field_scan_q0 = field_scan;
- h->field_scan8x8_q0 = field_scan8x8;
- h->field_scan8x8_cavlc_q0 = field_scan8x8_cavlc;
- }else{
- h->zigzag_scan_q0 = h->zigzag_scan;
- h->zigzag_scan8x8_q0 = h->zigzag_scan8x8;
- h->zigzag_scan8x8_cavlc_q0 = h->zigzag_scan8x8_cavlc;
- h->field_scan_q0 = h->field_scan;
- h->field_scan8x8_q0 = h->field_scan8x8;
- h->field_scan8x8_cavlc_q0 = h->field_scan8x8_cavlc;
- }
-
- alloc_tables(h);
-
- 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 * 2, 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);
- }
- }
-
- if(h->slice_num == 0){
- if(frame_start(h) < 0)
- return -1;
- }
-
- s->current_picture_ptr->frame_num= //FIXME frame_num cleanup
- h->frame_num= get_bits(&s->gb, h->sps.log2_max_frame_num);
-
- h->mb_mbaff = 0;
- h->mb_aff_frame = 0;
- if(h->sps.frame_mbs_only_flag){
- s->picture_structure= PICT_FRAME;
- }else{
- if(get_bits1(&s->gb)) { //field_pic_flag
- s->picture_structure= PICT_TOP_FIELD + get_bits1(&s->gb); //bottom_field_flag
- av_log(h->s.avctx, AV_LOG_ERROR, "PAFF interlacing is not implemented\n");
- } else {
- s->picture_structure= PICT_FRAME;
- h->mb_aff_frame = h->sps.mb_aff;
- }
- }
- assert(s->mb_num == s->mb_width * s->mb_height);
- if(first_mb_in_slice << h->mb_aff_frame >= s->mb_num ||
- first_mb_in_slice >= s->mb_num){
- av_log(h->s.avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\n");
- return -1;
- }
- s->resync_mb_x = s->mb_x = first_mb_in_slice % s->mb_width;
- s->resync_mb_y = s->mb_y = (first_mb_in_slice / s->mb_width) << h->mb_aff_frame;
- assert(s->mb_y < s->mb_height);
-
- if(s->picture_structure==PICT_FRAME){
- h->curr_pic_num= h->frame_num;
- h->max_pic_num= 1<< h->sps.log2_max_frame_num;
- }else{
- h->curr_pic_num= 2*h->frame_num;
- h->max_pic_num= 1<<(h->sps.log2_max_frame_num + 1);
- }
-
- if(h->nal_unit_type == NAL_IDR_SLICE){
- get_ue_golomb(&s->gb); /* idr_pic_id */
- }
-
- if(h->sps.poc_type==0){
- h->poc_lsb= get_bits(&s->gb, h->sps.log2_max_poc_lsb);
-
- if(h->pps.pic_order_present==1 && s->picture_structure==PICT_FRAME){
- h->delta_poc_bottom= get_se_golomb(&s->gb);
- }
- }
-
- if(h->sps.poc_type==1 && !h->sps.delta_pic_order_always_zero_flag){
- h->delta_poc[0]= get_se_golomb(&s->gb);
-
- if(h->pps.pic_order_present==1 && s->picture_structure==PICT_FRAME)
- h->delta_poc[1]= get_se_golomb(&s->gb);
- }
-
- init_poc(h);
-
- if(h->pps.redundant_pic_cnt_present){
- h->redundant_pic_count= get_ue_golomb(&s->gb);
- }
-
- //set defaults, might be overriden a few line later
- h->ref_count[0]= h->pps.ref_count[0];
- h->ref_count[1]= h->pps.ref_count[1];
-
- if(h->slice_type == P_TYPE || h->slice_type == SP_TYPE || h->slice_type == B_TYPE){
- if(h->slice_type == B_TYPE){
- h->direct_spatial_mv_pred= get_bits1(&s->gb);
- if(h->sps.mb_aff && h->direct_spatial_mv_pred)
- av_log(h->s.avctx, AV_LOG_ERROR, "MBAFF + spatial direct mode is not implemented\n");
- }
- num_ref_idx_active_override_flag= get_bits1(&s->gb);
-
- if(num_ref_idx_active_override_flag){
- h->ref_count[0]= get_ue_golomb(&s->gb) + 1;
- if(h->slice_type==B_TYPE)
- h->ref_count[1]= get_ue_golomb(&s->gb) + 1;
-
- if(h->ref_count[0] > 32 || h->ref_count[1] > 32){
- av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow\n");
- h->ref_count[0]= h->ref_count[1]= 1;
- return -1;
- }
- }
- }
-
- if(!default_ref_list_done){
- fill_default_ref_list(h);
- }
-
- if(decode_ref_pic_list_reordering(h) < 0)
- return -1;
-
- if( (h->pps.weighted_pred && (h->slice_type == P_TYPE || h->slice_type == SP_TYPE ))
- || (h->pps.weighted_bipred_idc==1 && h->slice_type==B_TYPE ) )
- pred_weight_table(h);
- else if(h->pps.weighted_bipred_idc==2 && h->slice_type==B_TYPE)
- implicit_weight_table(h);
- else
- h->use_weight = 0;
-
- if(s->current_picture.reference)
- decode_ref_pic_marking(h);
-
- if(FRAME_MBAFF)
- fill_mbaff_ref_list(h);
-
- if( h->slice_type != I_TYPE && h->slice_type != SI_TYPE && h->pps.cabac ){
- tmp = get_ue_golomb(&s->gb);
- if(tmp > 2){
- av_log(s->avctx, AV_LOG_ERROR, "cabac_init_idc overflow\n");
- return -1;
- }
- h->cabac_init_idc= tmp;
- }
-
- h->last_qscale_diff = 0;
- tmp = h->pps.init_qp + get_se_golomb(&s->gb);
- if(tmp>51){
- av_log(s->avctx, AV_LOG_ERROR, "QP %u out of range\n", tmp);
- return -1;
- }
- s->qscale= tmp;
- h->chroma_qp = get_chroma_qp(h->pps.chroma_qp_index_offset, s->qscale);
- //FIXME qscale / qp ... stuff
- if(h->slice_type == SP_TYPE){
- get_bits1(&s->gb); /* sp_for_switch_flag */
- }
- if(h->slice_type==SP_TYPE || h->slice_type == SI_TYPE){
- get_se_golomb(&s->gb); /* slice_qs_delta */
- }
-
- h->deblocking_filter = 1;
- h->slice_alpha_c0_offset = 0;
- h->slice_beta_offset = 0;
- if( h->pps.deblocking_filter_parameters_present ) {
- tmp= get_ue_golomb(&s->gb);
- if(tmp > 2){
- av_log(s->avctx, AV_LOG_ERROR, "deblocking_filter_idc %u out of range\n", tmp);
- return -1;
- }
- h->deblocking_filter= tmp;
- if(h->deblocking_filter < 2)
- 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;
- }
- }
- if( s->avctx->skip_loop_filter >= AVDISCARD_ALL
- ||(s->avctx->skip_loop_filter >= AVDISCARD_NONKEY && h->slice_type != I_TYPE)
- ||(s->avctx->skip_loop_filter >= AVDISCARD_BIDIR && h->slice_type == B_TYPE)
- ||(s->avctx->skip_loop_filter >= AVDISCARD_NONREF && h->nal_ref_idc == 0))
- h->deblocking_filter= 0;
-
-#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)
- slice_group_change_cycle= get_bits(&s->gb, ?);
-#endif
-
- h->slice_num++;
-
- h->emu_edge_width= (s->flags&CODEC_FLAG_EMU_EDGE) ? 0 : 16;
- h->emu_edge_height= FRAME_MBAFF ? 0 : h->emu_edge_width;
-
- if(s->avctx->debug&FF_DEBUG_PICT_INFO){
- av_log(h->s.avctx, AV_LOG_DEBUG, "slice:%d %s mb:%d %c pps:%u frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s\n",
- h->slice_num,
- (s->picture_structure==PICT_FRAME ? "F" : s->picture_structure==PICT_TOP_FIELD ? "T" : "B"),
- first_mb_in_slice,
- av_get_pict_type_char(h->slice_type),
- pps_id, h->frame_num,
- 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->use_weight,
- h->use_weight==1 && h->use_weight_chroma ? "c" : ""
- );
- }
-
- if((s->avctx->flags2 & CODEC_FLAG2_FAST) && !s->current_picture.reference){
- s->me.qpel_put= s->dsp.put_2tap_qpel_pixels_tab;
- s->me.qpel_avg= s->dsp.avg_2tap_qpel_pixels_tab;
- }else{
- s->me.qpel_put= s->dsp.put_h264_qpel_pixels_tab;
- s->me.qpel_avg= s->dsp.avg_h264_qpel_pixels_tab;
- }
-
- return 0;
-}
-
-/**
- *
- */
-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){
- int i;
- for(i=0; i<4; i++){
- if(!IS_SUB_8X8(h->sub_mb_type[i])
- || (!h->sps.direct_8x8_inference_flag && IS_DIRECT(h->sub_mb_type[i])))
- return 0;
- }
- return 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 occured
- */
-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("trailing:%d, total:%d\n", trailing_ones, total_coeff);
- assert(total_coeff<=16);
-
- for(i=0; i<trailing_ones; i++){
- level[i]= 1 - 2*get_bits1(gb);
- }
-
- if(i<total_coeff) {
- int level_code, mask;
- int suffix_length = total_coeff > 10 && trailing_ones < 3;
- int 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<<suffix_length) + get_bits(gb, suffix_length); //part
- else
- level_code= (prefix<<suffix_length); //part
- }else if(prefix==14){
- if(suffix_length)
- level_code= (prefix<<suffix_length) + get_bits(gb, suffix_length); //part
- else
- level_code= prefix + get_bits(gb, 4); //part
- }else if(prefix==15){
- level_code= (prefix<<suffix_length) + get_bits(gb, 12); //part
- if(suffix_length==0) level_code+=15; //FIXME doesn't make (much)sense
- }else{
- av_log(h->s.avctx, AV_LOG_ERROR, "prefix too large at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
-
- if(trailing_ones < 3) level_code += 2;
-
- suffix_length = 1;
- if(level_code > 5)
- suffix_length++;
- mask= -(level_code&1);
- level[i]= (((2+level_code)>>1) ^ mask) - mask;
- i++;
-
- //remaining coefficients have suffix_length > 0
- for(;i<total_coeff;i++) {
- static const int suffix_limit[7] = {0,5,11,23,47,95,INT_MAX };
- prefix = get_level_prefix(gb);
- if(prefix<15){
- level_code = (prefix<<suffix_length) + get_bits(gb, suffix_length);
- }else if(prefix==15){
- level_code = (prefix<<suffix_length) + get_bits(gb, 12);
- }else{
- av_log(h->s.avctx, AV_LOG_ERROR, "prefix too large at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- mask= -(level_code&1);
- level[i]= (((2+level_code)>>1) ^ mask) - mask;
- if(level_code > 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<total_coeff;i++) {
- if(zeros_left <= 0)
- run_before = 0;
- else if(zeros_left < 7){
- run_before= get_vlc2(gb, run_vlc[zeros_left-1].table, RUN_VLC_BITS, 1);
- }else{
- run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2);
- }
- zeros_left -= run_before;
- coeff_num -= 1 + run_before;
- j= scantable[ coeff_num ];
-
- block[j]= level[i];
- }
- }else{
- block[j] = (level[0] * qmul[j] + 32)>>6;
- for(i=1;i<total_coeff;i++) {
- if(zeros_left <= 0)
- run_before = 0;
- else if(zeros_left < 7){
- run_before= get_vlc2(gb, run_vlc[zeros_left-1].table, RUN_VLC_BITS, 1);
- }else{
- run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2);
- }
- zeros_left -= run_before;
- coeff_num -= 1 + run_before;
- j= scantable[ coeff_num ];
-
- block[j]= (level[i] * qmul[j] + 32)>>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){
- 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;
-}
-
-/**
- * decodes a P_SKIP or B_SKIP macroblock
- */
-static void decode_mb_skip(H264Context *h){
- MpegEncContext * const s = &h->s;
- const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
- int mb_type=0;
-
- memset(h->non_zero_count[mb_xy], 0, 16);
- 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 == B_TYPE )
- {
- // just for fill_caches. pred_direct_motion will set the real mb_type
- mb_type|= MB_TYPE_16x16|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;
- const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
- int partition_count;
- unsigned int mb_type, cbp;
- int dct8x8_allowed= h->pps.transform_8x8_mode;
-
- s->dsp.clear_blocks(h->mb); //FIXME avoid if already clear (move after skip handlong?
-
- tprintf("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 != I_TYPE && h->slice_type != SI_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);
- }else
- h->mb_field_decoding_flag= (s->picture_structure!=PICT_FRAME);
-
- h->prev_mb_skipped= 0;
-
- mb_type= get_ue_golomb(&s->gb);
- if(h->slice_type == 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 == P_TYPE /*|| h->slice_type == SP_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 == I_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, y;
-
- // we assume these blocks are very rare so we dont optimize it
- align_get_bits(&s->gb);
-
- // The pixels are stored in the same order as levels in h->mb array.
- for(y=0; y<16; y++){
- const int index= 4*(y&3) + 32*((y>>2)&1) + 128*(y>>3);
- for(x=0; x<16; x++){
- tprintf("LUMA ICPM LEVEL (%3d)\n", show_bits(&s->gb, 8));
- h->mb[index + (x&3) + 16*((x>>2)&1) + 64*(x>>3)]= get_bits(&s->gb, 8);
- }
- }
- for(y=0; y<8; y++){
- const int index= 256 + 4*(y&3) + 32*(y>>2);
- for(x=0; x<8; x++){
- tprintf("CHROMA U ICPM LEVEL (%3d)\n", show_bits(&s->gb, 8));
- h->mb[index + (x&3) + 16*(x>>2)]= get_bits(&s->gb, 8);
- }
- }
- for(y=0; y<8; y++){
- const int index= 256 + 64 + 4*(y&3) + 32*(y>>2);
- for(x=0; x<8; x++){
- tprintf("CHROMA V ICPM LEVEL (%3d)\n", show_bits(&s->gb, 8));
- h->mb[index + (x&3) + 16*(x>>2)]= get_bits(&s->gb, 8);
- }
- }
-
- // In deblocking, the quantizer is 0
- s->current_picture.qscale_table[mb_xy]= 0;
- h->chroma_qp = get_chroma_qp(h->pps.chroma_qp_index_offset, 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;
- }
-
- pred_mode= check_intra_pred_mode(h, get_ue_golomb(&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 == B_TYPE){
- for(i=0; i<4; i++){
- h->sub_mb_type[i]= get_ue_golomb(&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 == P_TYPE || h->slice_type == SP_TYPE); //FIXME SP correct ?
- for(i=0; i<4; i++){
- h->sub_mb_type[i]= get_ue_golomb(&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; list<2; list++){
- int ref_count= IS_REF0(mb_type) ? 1 : h->ref_count[list];
- if(ref_count == 0) continue;
- 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 = get_te0_golomb(&s->gb, ref_count); //FIXME init to 0 before and skip?
- 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; list<2; list++){
- const int ref_count= IS_REF0(mb_type) ? 1 : h->ref_count[list];
- if(ref_count == 0) continue;
-
- 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; j<sub_partition_count[i]; j++){
- int mx, my;
- const int index= 4*i + block_width*j;
- int16_t (* mv_cache)[2]= &h->mv_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("final mv:%d %d\n", mx, my);
-
- if(IS_SUB_8X8(sub_mb_type)){
- mv_cache[ 0 ][0]= mv_cache[ 1 ][0]=
- mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx;
- mv_cache[ 0 ][1]= mv_cache[ 1 ][1]=
- mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my;
- }else if(IS_SUB_8X4(sub_mb_type)){
- mv_cache[ 0 ][0]= mv_cache[ 1 ][0]= mx;
- mv_cache[ 0 ][1]= mv_cache[ 1 ][1]= my;
- }else if(IS_SUB_4X8(sub_mb_type)){
- mv_cache[ 0 ][0]= mv_cache[ 8 ][0]= mx;
- mv_cache[ 0 ][1]= mv_cache[ 8 ][1]= my;
- }else{
- assert(IS_SUB_4X4(sub_mb_type));
- 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; list<2; list++){
- if(h->ref_count[list]>0){
- if(IS_DIR(mb_type, 0, list)){
- unsigned int val= get_te0_golomb(&s->gb, h->ref_count[list]);
- 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);
- }else
- fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, (LIST_NOT_USED&0xFF), 1);
- }
- }
- for(list=0; list<2; 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("final mv:%d %d\n", mx, my);
-
- 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; list<2; list++){
- if(h->ref_count[list]>0){
- for(i=0; i<2; i++){
- if(IS_DIR(mb_type, i, list)){
- unsigned int val= get_te0_golomb(&s->gb, h->ref_count[list]);
- 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] + 16*i ], 4, 2, 8, val, 1);
- }else
- fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, (LIST_NOT_USED&0xFF), 1);
- }
- }
- }
- for(list=0; list<2; 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], &mx, &my);
- mx += get_se_golomb(&s->gb);
- my += get_se_golomb(&s->gb);
- tprintf("final mv:%d %d\n", mx, my);
-
- fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx,my), 4);
- }else
- fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 4);
- }
- }
- }else{
- assert(IS_8X16(mb_type));
- for(list=0; list<2; list++){
- if(h->ref_count[list]>0){
- for(i=0; i<2; i++){
- if(IS_DIR(mb_type, i, list)){ //FIXME optimize
- unsigned int val= get_te0_golomb(&s->gb, h->ref_count[list]);
- 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] + 2*i ], 2, 4, 8, val, 1);
- }else
- fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, (LIST_NOT_USED&0xFF), 1);
- }
- }
- }
- for(list=0; list<2; 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 ], &mx, &my);
- mx += get_se_golomb(&s->gb);
- my += get_se_golomb(&s->gb);
- tprintf("final mv:%d %d\n", mx, my);
-
- fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx,my), 4);
- }else
- fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 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(IS_INTRA4x4(mb_type))
- cbp= golomb_to_intra4x4_cbp[cbp];
- else
- cbp= golomb_to_inter_cbp[cbp];
- }
- h->cbp = cbp;
-
- if(dct8x8_allowed && (cbp&15) && !IS_INTRA(mb_type)){
- if(get_bits1(&s->gb))
- mb_type |= MB_TYPE_8x8DCT;
- }
- s->current_picture.mb_type[mb_xy]= mb_type;
-
- if(cbp || IS_INTRA16x16(mb_type)){
- int i8x8, i4x4, chroma_idx;
- int chroma_qp, 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= chroma_qp= get_chroma_qp(h->pps.chroma_qp_index_offset, 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<<i8x8)){
- if(IS_8x8DCT(mb_type)){
- DCTELEM *buf = &h->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++){
- 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, h->dequant4_coeff[chroma_idx+1+(IS_INTRA( mb_type ) ? 0:3)][chroma_qp], 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( H264Context *h ) {
- MpegEncContext * const s = &h->s;
-
- if( h->slice_type == I_TYPE ) {
- return decode_cabac_intra_mb_type(h, 3, 1);
- } else if( h->slice_type == 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 */
- return 3 * get_cabac_noinline( &h->cabac, &h->cabac_state[16] );
- } else {
- /* P_L0_D8x16, P_L0_D16x8 */
- return 2 - get_cabac_noinline( &h->cabac, &h->cabac_state[17] );
- }
- } else {
- return decode_cabac_intra_mb_type(h, 17, 0) + 5;
- }
- } else if( h->slice_type == B_TYPE ) {
- const int mba_xy = h->left_mb_xy[0];
- const int mbb_xy = h->top_mb_xy;
- int ctx = 0;
- int bits;
-
- 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_* */
- } else {
- /* TODO SI/SP frames? */
- return -1;
- }
-}
-
-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 = mb_x + mb_y*s->mb_stride;
- mba_xy = mb_xy - 1;
- mbb_xy = mb_xy - s->mb_stride;
- }
-
- 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 == 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 const uint8_t block_idx_x[16] = {
- 0, 1, 0, 1, 2, 3, 2, 3, 0, 1, 0, 1, 2, 3, 2, 3
-};
-static const uint8_t block_idx_y[16] = {
- 0, 0, 1, 1, 0, 0, 1, 1, 2, 2, 3, 3, 2, 2, 3, 3
-};
-static const uint8_t block_idx_xy[4][4] = {
- { 0, 2, 8, 10},
- { 1, 3, 9, 11},
- { 4, 6, 12, 14},
- { 5, 7, 13, 15}
-};
-
-static int decode_cabac_mb_cbp_luma( H264Context *h) {
- int cbp = 0;
- int cbp_b = -1;
- int i8x8;
-
- if( h->slice_table[h->top_mb_xy] == h->slice_num ) {
- cbp_b = h->top_cbp;
- tprintf("cbp_b = top_cbp = %x\n", cbp_b);
- }
-
- for( i8x8 = 0; i8x8 < 4; i8x8++ ) {
- int cbp_a = -1;
- int x, y;
- int ctx = 0;
-
- x = block_idx_x[4*i8x8];
- y = block_idx_y[4*i8x8];
-
- if( x > 0 )
- cbp_a = cbp;
- else if( h->slice_table[h->left_mb_xy[0]] == h->slice_num ) {
- cbp_a = h->left_cbp;
- tprintf("cbp_a = left_cbp = %x\n", cbp_a);
- }
-
- if( y > 0 )
- cbp_b = cbp;
-
- /* No need to test for skip as we put 0 for skip block */
- /* No need to test for IPCM as we put 1 for IPCM block */
- if( cbp_a >= 0 ) {
- int i8x8a = block_idx_xy[(x-1)&0x03][y]/4;
- if( ((cbp_a >> i8x8a)&0x01) == 0 )
- ctx++;
- }
-
- if( cbp_b >= 0 ) {
- int i8x8b = block_idx_xy[x][(y-1)&0x03]/4;
- if( ((cbp_b >> i8x8b)&0x01) == 0 )
- ctx += 2;
- }
-
- if( get_cabac( &h->cabac, &h->cabac_state[73 + ctx] ) ) {
- cbp |= 1 << i8x8;
- }
- }
- 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) {
- MpegEncContext * const s = &h->s;
- int mbn_xy;
- int ctx = 0;
- int val = 0;
-
- if( s->mb_x > 0 )
- mbn_xy = s->mb_x + s->mb_y*s->mb_stride - 1;
- else
- mbn_xy = s->mb_width - 1 + (s->mb_y-1)*s->mb_stride;
-
- if( h->last_qscale_diff != 0 )
- ctx++;
-
- while( get_cabac_noinline( &h->cabac, &h->cabac_state[60 + ctx] ) ) {
- if( ctx < 2 )
- ctx = 2;
- else
- ctx = 3;
- val++;
- if(val > 102) //prevent infinite loop
- return INT_MIN;
- }
-
- if( val&0x01 )
- return (val + 1)/2;
- else
- return -(val + 1)/2;
-}
-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 == 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++;
- if( ctx < 4 )
- ctx = 4;
- else
- ctx = 5;
- if(ref >= 32 /*h->ref_list[list]*/){
- av_log(h->s.avctx, AV_LOG_ERROR, "overflow in decode_cabac_mb_ref\n");
- return 0; //FIXME we should return -1 and check the return everywhere
- }
- }
- 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 ctx, mvd;
-
- if( amvd < 3 )
- ctx = 0;
- else if( amvd > 32 )
- ctx = 2;
- else
- ctx = 1;
-
- 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 int inline get_cabac_cbf_ctx( H264Context *h, int cat, int idx ) {
- int nza, nzb;
- int ctx = 0;
-
- if( cat == 0 ) {
- nza = h->left_cbp&0x100;
- nzb = h-> top_cbp&0x100;
- } else if( cat == 1 || cat == 2 ) {
- nza = h->non_zero_count_cache[scan8[idx] - 1];
- nzb = h->non_zero_count_cache[scan8[idx] - 8];
- } else if( cat == 3 ) {
- nza = (h->left_cbp>>(6+idx))&0x01;
- nzb = (h-> top_cbp>>(6+idx))&0x01;
- } else {
- assert(cat == 4);
- nza = h->non_zero_count_cache[scan8[16+idx] - 1];
- nzb = h->non_zero_count_cache[scan8[16+idx] - 8];
- }
-
- if( nza > 0 )
- ctx++;
-
- if( nzb > 0 )
- ctx += 2;
-
- return ctx + 4 * cat;
-}
-
-static const __attribute((used)) 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 int decode_cabac_residual( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff) {
- const int mb_xy = h->s.mb_x + h->s.mb_y*h->s.mb_stride;
- 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 }
- };
-
- int index[64];
-
- int last;
- int coeff_count = 0;
-
- int abslevel1 = 1;
- int abslevelgt1 = 0;
-
- uint8_t *significant_coeff_ctx_base;
- uint8_t *last_coeff_ctx_base;
- uint8_t *abs_level_m1_ctx_base;
-
-#ifndef 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 = 4 * iCbCr + chroma4x4idx
- * 5-> Luma8x8 n = 4 * luma8x8idx
- */
-
- /* read coded block flag */
- if( cat != 5 ) {
- if( get_cabac( CC, &h->cabac_state[85 + get_cabac_cbf_ctx( h, cat, n ) ] ) == 0 ) {
- if( cat == 1 || cat == 2 )
- h->non_zero_count_cache[scan8[n]] = 0;
- else if( cat == 4 )
- h->non_zero_count_cache[scan8[16+n]] = 0;
-#ifdef CABAC_ON_STACK
- h->cabac.range = cc.range ;
- h->cabac.low = cc.low ;
- h->cabac.bytestream= cc.bytestream;
-#endif
- return 0;
- }
- }
-
- 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( 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 defined(ARCH_X86) && !(defined(PIC) && defined(__GNUC__))
- 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( cat == 0 )
- h->cbp_table[mb_xy] |= 0x100;
- else if( cat == 1 || cat == 2 )
- h->non_zero_count_cache[scan8[n]] = coeff_count;
- else if( cat == 3 )
- h->cbp_table[mb_xy] |= 0x40 << n;
- else if( cat == 4 )
- h->non_zero_count_cache[scan8[16+n]] = coeff_count;
- else {
- assert( cat == 5 );
- fill_rectangle(&h->non_zero_count_cache[scan8[n]], 2, 2, 8, coeff_count, 1);
- }
-
- for( coeff_count--; coeff_count >= 0; coeff_count-- ) {
- uint8_t *ctx = (abslevelgt1 != 0 ? 0 : FFMIN( 4, abslevel1 )) + abs_level_m1_ctx_base;
- int j= scantable[index[coeff_count]];
-
- if( get_cabac( CC, ctx ) == 0 ) {
- if( !qmul ) {
- block[j] = get_cabac_bypass_sign( CC, -1);
- }else{
- block[j] = (get_cabac_bypass_sign( CC, -qmul[j]) + 32) >> 6;;
- }
-
- abslevel1++;
- } else {
- int coeff_abs = 2;
- ctx = 5 + FFMIN( 4, abslevelgt1 ) + abs_level_m1_ctx_base;
- 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( !qmul ) {
- if( get_cabac_bypass( CC ) ) block[j] = -coeff_abs;
- else block[j] = coeff_abs;
- }else{
- if( get_cabac_bypass( CC ) ) block[j] = (-coeff_abs * qmul[j] + 32) >> 6;
- else block[j] = ( coeff_abs * qmul[j] + 32) >> 6;
- }
-
- abslevelgt1++;
- }
- }
-#ifdef CABAC_ON_STACK
- h->cabac.range = cc.range ;
- h->cabac.low = cc.low ;
- h->cabac.bytestream= cc.bytestream;
-#endif
- return 0;
-}
-
-static void inline compute_mb_neighbors(H264Context *h)
-{
- MpegEncContext * const s = &h->s;
- const int mb_xy = s->mb_x + s->mb_y*s->mb_stride;
- 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_frame_flag = !IS_INTERLACED(s->current_picture.mb_type[top_pair_xy]);
- const int left_mb_frame_flag = !IS_INTERLACED(s->current_picture.mb_type[pair_xy-1]);
- const int curr_mb_frame_flag = !MB_FIELD;
- const int bottom = (s->mb_y & 1);
- if (bottom
- ? !curr_mb_frame_flag // bottom macroblock
- : (!curr_mb_frame_flag && !top_mb_frame_flag) // top macroblock
- ) {
- h->top_mb_xy -= s->mb_stride;
- }
- if (left_mb_frame_flag != curr_mb_frame_flag) {
- h->left_mb_xy[0] = pair_xy - 1;
- }
- }
- 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;
- const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
- int mb_type, partition_count, cbp = 0;
- int dct8x8_allowed= h->pps.transform_8x8_mode;
-
- s->dsp.clear_blocks(h->mb); //FIXME avoid if already clear (move after skip handlong?)
-
- tprintf("pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y);
- if( h->slice_type != I_TYPE && h->slice_type != SI_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)
- predict_field_decoding_flag(h);
- else
- 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);
- }else
- h->mb_field_decoding_flag= (s->picture_structure!=PICT_FRAME);
-
- h->prev_mb_skipped = 0;
-
- compute_mb_neighbors(h);
- if( ( mb_type = decode_cabac_mb_type( h ) ) < 0 ) {
- av_log( h->s.avctx, AV_LOG_ERROR, "decode_cabac_mb_type failed\n" );
- return -1;
- }
-
- if( h->slice_type == 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 == 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 == 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;
- unsigned int x, y;
-
- // We assume these blocks are very rare so we dont 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.
- for(y=0; y<16; y++){
- const int index= 4*(y&3) + 32*((y>>2)&1) + 128*(y>>3);
- for(x=0; x<16; x++){
- tprintf("LUMA ICPM LEVEL (%3d)\n", *ptr);
- h->mb[index + (x&3) + 16*((x>>2)&1) + 64*(x>>3)]= *ptr++;
- }
- }
- for(y=0; y<8; y++){
- const int index= 256 + 4*(y&3) + 32*(y>>2);
- for(x=0; x<8; x++){
- tprintf("CHROMA U ICPM LEVEL (%3d)\n", *ptr);
- h->mb[index + (x&3) + 16*(x>>2)]= *ptr++;
- }
- }
- for(y=0; y<8; y++){
- const int index= 256 + 64 + 4*(y&3) + 32*(y>>2);
- for(x=0; x<8; x++){
- tprintf("CHROMA V ICPM LEVEL (%3d)\n", *ptr);
- h->mb[index + (x&3) + 16*(x>>2)]= *ptr++;
- }
- }
-
- 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;
- h->chroma_qp = get_chroma_qp(h->pps.chroma_qp_index_offset, 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);
-
- 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;
- }
- 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 == 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);
- 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 < 2; list++ ) {
- if( h->ref_count[list] > 0 ) {
- 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 );
- 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; list<2; list++){
- for(i=0; i<4; i++){
- if(IS_DIRECT(h->sub_mb_type[i])){
- fill_rectangle(h->mvd_cache[list][scan8[4*i]], 2, 2, 8, 0, 4);
- continue;
- }
- h->ref_cache[list][ scan8[4*i] ]=h->ref_cache[list][ scan8[4*i]+1 ];
-
- 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; j<sub_partition_count[i]; j++){
- int mpx, mpy;
- int mx, my;
- const int index= 4*i + block_width*j;
- int16_t (* mv_cache)[2]= &h->mv_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("final mv:%d %d\n", mx, my);
-
- if(IS_SUB_8X8(sub_mb_type)){
- mv_cache[ 0 ][0]= mv_cache[ 1 ][0]=
- mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx;
- mv_cache[ 0 ][1]= mv_cache[ 1 ][1]=
- mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my;
-
- mvd_cache[ 0 ][0]= mvd_cache[ 1 ][0]=
- mvd_cache[ 8 ][0]= mvd_cache[ 9 ][0]= mx - mpx;
- mvd_cache[ 0 ][1]= mvd_cache[ 1 ][1]=
- mvd_cache[ 8 ][1]= mvd_cache[ 9 ][1]= my - mpy;
- }else if(IS_SUB_8X4(sub_mb_type)){
- mv_cache[ 0 ][0]= mv_cache[ 1 ][0]= mx;
- mv_cache[ 0 ][1]= mv_cache[ 1 ][1]= my;
-
- mvd_cache[ 0 ][0]= mvd_cache[ 1 ][0]= mx- mpx;
- mvd_cache[ 0 ][1]= mvd_cache[ 1 ][1]= my - mpy;
- }else if(IS_SUB_4X8(sub_mb_type)){
- mv_cache[ 0 ][0]= mv_cache[ 8 ][0]= mx;
- mv_cache[ 0 ][1]= mv_cache[ 8 ][1]= my;
-
- mvd_cache[ 0 ][0]= mvd_cache[ 8 ][0]= mx - mpx;
- mvd_cache[ 0 ][1]= mvd_cache[ 8 ][1]= my - mpy;
- }else{
- assert(IS_SUB_4X4(sub_mb_type));
- 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; list<2; list++){
- if(IS_DIR(mb_type, 0, list)){
- if(h->ref_count[list] > 0 ){
- const int ref = h->ref_count[list] > 1 ? decode_cabac_mb_ref( h, list, 0 ) : 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);
- }
- for(list=0; list<2; 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("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; list<2; list++){
- if(h->ref_count[list]>0){
- for(i=0; i<2; i++){
- if(IS_DIR(mb_type, i, list)){
- const int ref= h->ref_count[list] > 1 ? decode_cabac_mb_ref( h, list, 8*i ) : 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; list<2; 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("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; list<2; list++){
- if(h->ref_count[list]>0){
- for(i=0; i<2; i++){
- if(IS_DIR(mb_type, i, list)){ //FIXME optimize
- const int ref= h->ref_count[list] > 1 ? decode_cabac_mb_ref( h, list, 4*i ) : 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; list<2; 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("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 );
- 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;
- 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 = get_chroma_qp(h->pps.chroma_qp_index_offset, s->qscale);
-
- if( IS_INTRA16x16( mb_type ) ) {
- int i;
- //av_log( s->avctx, AV_LOG_ERROR, "INTRA16x16 DC\n" );
- if( decode_cabac_residual( h, h->mb, 0, 0, dc_scan, NULL, 16) < 0)
- return -1;
- if( cbp&15 ) {
- for( i = 0; i < 16; i++ ) {
- //av_log( s->avctx, AV_LOG_ERROR, "INTRA16x16 AC:%d\n", i );
- if( decode_cabac_residual(h, h->mb + 16*i, 1, i, 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 {
- int i8x8, i4x4;
- for( i8x8 = 0; i8x8 < 4; i8x8++ ) {
- if( cbp & (1<<i8x8) ) {
- if( IS_8x8DCT(mb_type) ) {
- if( decode_cabac_residual(h, h->mb + 64*i8x8, 5, 4*i8x8,
- scan8x8, h->dequant8_coeff[IS_INTRA( mb_type ) ? 0:1][s->qscale], 64) < 0 )
- return -1;
- } else
- 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
- if( decode_cabac_residual(h, h->mb + 16*index, 2, index, scan, h->dequant4_coeff[IS_INTRA( mb_type ) ? 0:3][s->qscale], 16) < 0 )
- return -1;
-//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 );
- if( decode_cabac_residual(h, h->mb + 256 + 16*4*c, 3, c, chroma_dc_scan, NULL, 4) < 0)
- return -1;
- }
- }
-
- if( cbp&0x20 ) {
- int c, i;
- for( c = 0; c < 2; 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 );
- if( decode_cabac_residual(h, h->mb + 16*index, 4, index - 16, scan + 1, h->dequant4_coeff[c+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp], 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;
- 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 ) {
- int i, d;
- 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( bS[0] < 4 ) {
- int8_t tc[4];
- for(i=0; i<4; i++)
- tc[i] = bS[i] ? (tc0_table+52)[index_a][bS[i] - 1] : -1;
- h->s.dsp.h264_h_loop_filter_luma(pix, stride, alpha, beta, tc);
- } else {
- /* 16px edge length, because bS=4 is triggered by being at
- * the edge of an intra MB, so all 4 bS are the same */
- for( d = 0; d < 16; d++ ) {
- 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("filter_mb_edgev i:%d d:%d\n# bS:4 -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\n", i, d, p2, p1, p0, q0, q1, q2, pix[-2], pix[-1], pix[0], pix[1]);
- }
- pix += stride;
- }
- }
-}
-static void filter_mb_edgecv( H264Context *h, uint8_t *pix, int stride, int16_t bS[4], int qp ) {
- int i;
- 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( bS[0] < 4 ) {
- int8_t tc[4];
- for(i=0; i<4; i++)
- tc[i] = bS[i] ? (tc0_table+52)[index_a][bS[i] - 1] + 1 : 0;
- 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] - 1];
- 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 + clip( ( p2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( p1 << 1 ) ) >> 1, -tc0, tc0 );
- tc++;
- }
- if( FFABS( q2 - q0 ) < beta ) {
- pix[1] = q1 + clip( ( q2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( q1 << 1 ) ) >> 1, -tc0, tc0 );
- tc++;
- }
-
- i_delta = clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
- pix[-1] = clip_uint8( p0 + i_delta ); /* p0' */
- pix[0] = clip_uint8( q0 - i_delta ); /* q0' */
- tprintf("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("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] + 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 = clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
-
- pix[-1] = clip_uint8( p0 + i_delta ); /* p0' */
- pix[0] = clip_uint8( q0 - i_delta ); /* q0' */
- tprintf("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("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 ) {
- int i, d;
- 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];
- const int pix_next = stride;
-
- if( bS[0] < 4 ) {
- int8_t tc[4];
- for(i=0; i<4; i++)
- tc[i] = bS[i] ? (tc0_table+52)[index_a][bS[i] - 1] : -1;
- h->s.dsp.h264_v_loop_filter_luma(pix, stride, alpha, beta, tc);
- } else {
- /* 16px edge length, see filter_mb_edgev */
- for( d = 0; d < 16; d++ ) {
- const int p0 = pix[-1*pix_next];
- const int p1 = pix[-2*pix_next];
- const int p2 = pix[-3*pix_next];
- const int q0 = pix[0];
- const int q1 = pix[1*pix_next];
- const int q2 = pix[2*pix_next];
-
- if( FFABS( p0 - q0 ) < alpha &&
- FFABS( p1 - p0 ) < beta &&
- FFABS( q1 - q0 ) < beta ) {
-
- const int p3 = pix[-4*pix_next];
- const int q3 = pix[ 3*pix_next];
-
- if(FFABS( p0 - q0 ) < (( alpha >> 2 ) + 2 )){
- if( FFABS( p2 - p0 ) < beta) {
- /* p0', p1', p2' */
- pix[-1*pix_next] = ( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3;
- pix[-2*pix_next] = ( p2 + p1 + p0 + q0 + 2 ) >> 2;
- pix[-3*pix_next] = ( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3;
- } else {
- /* p0' */
- pix[-1*pix_next] = ( 2*p1 + p0 + q1 + 2 ) >> 2;
- }
- if( FFABS( q2 - q0 ) < beta) {
- /* q0', q1', q2' */
- pix[0*pix_next] = ( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3;
- pix[1*pix_next] = ( p0 + q0 + q1 + q2 + 2 ) >> 2;
- pix[2*pix_next] = ( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3;
- } else {
- /* q0' */
- pix[0*pix_next] = ( 2*q1 + q0 + p1 + 2 ) >> 2;
- }
- }else{
- /* p0', q0' */
- pix[-1*pix_next] = ( 2*p1 + p0 + q1 + 2 ) >> 2;
- pix[ 0*pix_next] = ( 2*q1 + q0 + p1 + 2 ) >> 2;
- }
- tprintf("filter_mb_edgeh i:%d d:%d, qp:%d, indexA:%d, alpha:%d, beta:%d\n# bS:%d -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\n", i, d, qp, index_a, alpha, beta, bS[i], p2, p1, p0, q0, q1, q2, pix[-2*pix_next], pix[-pix_next], pix[0], pix[pix_next]);
- }
- pix++;
- }
- }
-}
-
-static void filter_mb_edgech( H264Context *h, uint8_t *pix, int stride, int16_t bS[4], int qp ) {
- int i;
- 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( bS[0] < 4 ) {
- int8_t tc[4];
- for(i=0; i<4; i++)
- tc[i] = bS[i] ? (tc0_table+52)[index_a][bS[i] - 1] + 1 : 0;
- 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_xy, mb_type;
- int qp, qp0, qp1, qpc, qpc0, qpc1, qp_thresh;
-
- if(mb_x==0 || mb_y==0 || !s->dsp.h264_loop_filter_strength) {
- filter_mb(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize);
- return;
- }
- assert(!FRAME_MBAFF);
-
- mb_xy = mb_x + mb_y*s->mb_stride;
- 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->pps.chroma_qp_index_offset, qp );
- qpc0 = get_chroma_qp( h->pps.chroma_qp_index_offset, qp0 );
- qpc1 = get_chroma_qp( h->pps.chroma_qp_index_offset, 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};
- 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, bS4, 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, bS4, 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, bS4, qpc1 );
- filter_mb_edgech( h, &img_cb[2*2*uvlinesize], uvlinesize, bS3, qpc );
- filter_mb_edgech( h, &img_cr[2*0*uvlinesize], uvlinesize, bS4, 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 == B_TYPE), edges, step, mask_edge0, mask_edge1 );
- }
- 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] = 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 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;
- int dir;
- /* FIXME: A given frame may occupy more than one position in
- * the reference list. So ref2frm should be populated with
- * frame numbers, not indices. */
- static const int ref2frm[34] = {-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};
-
- //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 - FFMAX(0, h->pps.chroma_qp_index_offset);
- 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)
- && (mb_y == 0 || ((qp + s->current_picture.qscale_table[h->top_mb_xy] + 1)>>1) <= qp_thresh)){
- return;
- }
- }
-
- if (FRAME_MBAFF
- // left mb is in picture
- && h->slice_table[mb_xy-1] != 255
- // 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 chroma_qp[2];
- int mb_qp, mbn0_qp, mbn1_qp;
- int i;
- first_vertical_edge_done = 1;
-
- 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 ||
- /* FIXME: with 8x8dct + cavlc, should check cbp instead of nnz */
- h->non_zero_count[mbn_xy][MB_FIELD ? i&3 : (i>>2)+(mb_y&1)*2] )
- bS[i] = 2;
- else
- bS[i] = 1;
- }
- }
-
- 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;
- chroma_qp[0] = ( get_chroma_qp( h->pps.chroma_qp_index_offset, mb_qp ) +
- get_chroma_qp( h->pps.chroma_qp_index_offset, mbn0_qp ) + 1 ) >> 1;
- qp[1] = ( mb_qp + mbn1_qp + 1 ) >> 1;
- chroma_qp[1] = ( get_chroma_qp( h->pps.chroma_qp_index_offset, mb_qp ) +
- get_chroma_qp( h->pps.chroma_qp_index_offset, mbn1_qp ) + 1 ) >> 1;
-
- /* Filter edge */
- tprintf("filter mb:%d/%d MBAFF, QPy:%d/%d, QPc:%d/%d ls:%d uvls:%d", mb_x, mb_y, qp[0], qp[1], chroma_qp[0], chroma_qp[1], linesize, uvlinesize);
- { int i; for (i = 0; i < 8; i++) tprintf(" bS[%d]:%d", i, bS[i]); tprintf("\n"); }
- filter_mb_mbaff_edgev ( h, &img_y [0], linesize, bS, qp );
- filter_mb_mbaff_edgecv( h, &img_cb[0], uvlinesize, bS, chroma_qp );
- filter_mb_mbaff_edgecv( h, &img_cr[0], uvlinesize, bS, chroma_qp );
- }
- /* dir : 0 -> vertical edge, 1 -> horizontal edge */
- for( dir = 0; dir < 2; dir++ )
- {
- 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 start = h->slice_table[mbm_xy] == 255 ? 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;
- first_vertical_edge_done = 0;
- }
-
- 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, chroma_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("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(" bS[%d]:%d", i, bS[i]); tprintf("\n"); }
- filter_mb_edgeh( h, &img_y[j*linesize], tmp_linesize, bS, qp );
- chroma_qp = ( h->chroma_qp +
- get_chroma_qp( h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1;
- filter_mb_edgech( h, &img_cb[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp );
- filter_mb_edgech( h, &img_cr[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp );
- }
-
- 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];
- 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 == B_TYPE); l++ ) {
- v |= ref2frm[h->ref_cache[l][b_idx]+2] != ref2frm[h->ref_cache[l][bn_idx]+2] ||
- 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[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] != 0 ||
- h->non_zero_count_cache[bn_idx] != 0 ) {
- bS[i] = 2;
- }
- else if(!mv_done)
- {
- bS[i] = 0;
- for( l = 0; l < 1 + (h->slice_type == B_TYPE); l++ ) {
- if( ref2frm[h->ref_cache[l][b_idx]+2] != ref2frm[h->ref_cache[l][bn_idx]+2] ||
- 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(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("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("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(" bS[%d]:%d", i, bS[i]); tprintf("\n"); }
- if( dir == 0 ) {
- filter_mb_edgev( h, &img_y[4*edge], linesize, bS, qp );
- if( (edge&1) == 0 ) {
- int chroma_qp = ( h->chroma_qp +
- get_chroma_qp( h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1;
- filter_mb_edgecv( h, &img_cb[2*edge], uvlinesize, bS, chroma_qp );
- filter_mb_edgecv( h, &img_cr[2*edge], uvlinesize, bS, chroma_qp );
- }
- } else {
- filter_mb_edgeh( h, &img_y[4*edge*linesize], linesize, bS, qp );
- if( (edge&1) == 0 ) {
- int chroma_qp = ( h->chroma_qp +
- get_chroma_qp( h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1;
- filter_mb_edgech( h, &img_cb[2*edge*uvlinesize], uvlinesize, bS, chroma_qp );
- filter_mb_edgech( h, &img_cr[2*edge*uvlinesize], uvlinesize, bS, chroma_qp );
- }
- }
- }
- }
-}
-
-static int decode_slice(H264Context *h){
- MpegEncContext * const s = &h->s;
- const int part_mask= s->partitioned_frame ? (AC_END|AC_ERROR) : 0x7F;
-
- s->mb_skip_run= -1;
-
- if( h->pps.cabac ) {
- int i;
-
- /* realign */
- align_get_bits( &s->gb );
-
- /* init cabac */
- 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 == I_TYPE )
- pre = clip( ((cabac_context_init_I[i][0] * s->qscale) >>4 ) + cabac_context_init_I[i][1], 1, 126 );
- else
- pre = 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 );
-
- if( pre <= 63 )
- h->cabac_state[i] = 2 * ( 63 - pre ) + 0;
- else
- h->cabac_state[i] = 2 * ( pre - 64 ) + 1;
- }
-
- for(;;){
-//START_TIMER
- int ret = decode_mb_cabac(h);
- int eos;
-//STOP_TIMER("decode_mb_cabac")
-
- if(ret>=0) hl_decode_mb(h);
-
- if( ret >= 0 && FRAME_MBAFF ) { //FIXME optimal? or let mb_decode decode 16x32 ?
- s->mb_y++;
-
- if(ret>=0) ret = decode_mb_cabac(h);
-
- if(ret>=0) hl_decode_mb(h);
- s->mb_y--;
- }
- eos = get_cabac_terminate( &h->cabac );
-
- 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 (%d)\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);
- return -1;
- }
-
- if( ++s->mb_x >= s->mb_width ) {
- s->mb_x = 0;
- ff_draw_horiz_band(s, 16*s->mb_y, 16);
- ++s->mb_y;
- if(FRAME_MBAFF) {
- ++s->mb_y;
- }
- }
-
- if( eos || s->mb_y >= s->mb_height ) {
- tprintf("slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits);
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
- return 0;
- }
- }
-
- } else {
- for(;;){
- int ret = decode_mb_cavlc(h);
-
- if(ret>=0) 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);
-
- if(ret>=0) hl_decode_mb(h);
- s->mb_y--;
- }
-
- if(ret<0){
- av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d\n", s->mb_x, s->mb_y);
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);
-
- return -1;
- }
-
- if(++s->mb_x >= s->mb_width){
- s->mb_x=0;
- ff_draw_horiz_band(s, 16*s->mb_y, 16);
- ++s->mb_y;
- if(FRAME_MBAFF) {
- ++s->mb_y;
- }
- if(s->mb_y >= s->mb_height){
- tprintf("slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits);
-
- if(get_bits_count(&s->gb) == s->gb.size_in_bits ) {
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
-
- return 0;
- }else{
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
-
- return -1;
- }
- }
- }
-
- if(get_bits_count(&s->gb) >= s->gb.size_in_bits && s->mb_skip_run<=0){
- tprintf("slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits);
- if(get_bits_count(&s->gb) == s->gb.size_in_bits ){
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
-
- return 0;
- }else{
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);
-
- return -1;
- }
- }
- }
- }
-
-#if 0
- for(;s->mb_y < s->mb_height; s->mb_y++){
- for(;s->mb_x < s->mb_width; s->mb_x++){
- int ret= decode_mb(h);
-
- hl_decode_mb(h);
-
- if(ret<0){
- av_log(s->avctx, AV_LOG_ERROR, "error while decoding MB %d %d\n", s->mb_x, s->mb_y);
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);
-
- return -1;
- }
-
- if(++s->mb_x >= s->mb_width){
- s->mb_x=0;
- if(++s->mb_y >= s->mb_height){
- if(get_bits_count(s->gb) == s->gb.size_in_bits){
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
-
- return 0;
- }else{
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
-
- return -1;
- }
- }
- }
-
- if(get_bits_count(s->?gb) >= s->gb?.size_in_bits){
- if(get_bits_count(s->gb) == s->gb.size_in_bits){
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
-
- return 0;
- }else{
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);
-
- return -1;
- }
- }
- }
- s->mb_x=0;
- ff_draw_horiz_band(s, 16*s->mb_y, 16);
- }
-#endif
- return -1; //not reached
-}
-
-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; i<sizeof(user_data)-1 && i<size; i++){
- user_data[i]= get_bits(&s->gb, 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(; i<size; i++)
- skip_bits(&s->gb, 8);
-
- return 0;
-}
-
-static int 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 5:
- if(decode_unregistered_user_data(h, size) < 0)
- return -1;
- break;
- default:
- skip_bits(&s->gb, 8*size);
- }
-
- //FIXME check bits here
- align_get_bits(&s->gb);
- }
-
- return 0;
-}
-
-static inline void decode_hrd_parameters(H264Context *h, SPS *sps){
- MpegEncContext * const s = &h->s;
- int cpb_count, i;
- cpb_count = get_ue_golomb(&s->gb) + 1;
- get_bits(&s->gb, 4); /* bit_rate_scale */
- get_bits(&s->gb, 4); /* cpb_size_scale */
- for(i=0; i<cpb_count; i++){
- get_ue_golomb(&s->gb); /* bit_rate_value_minus1 */
- get_ue_golomb(&s->gb); /* cpb_size_value_minus1 */
- get_bits1(&s->gb); /* cbr_flag */
- }
- get_bits(&s->gb, 5); /* initial_cpb_removal_delay_length_minus1 */
- get_bits(&s->gb, 5); /* cpb_removal_delay_length_minus1 */
- get_bits(&s->gb, 5); /* dpb_output_delay_length_minus1 */
- get_bits(&s->gb, 5); /* time_offset_length */
-}
-
-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;
- int nal_hrd_parameters_present_flag, vcl_hrd_parameters_present_flag;
-
- 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 < 14){
- 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 */
- get_ue_golomb(&s->gb); /* 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);
- }
-
- nal_hrd_parameters_present_flag = get_bits1(&s->gb);
- if(nal_hrd_parameters_present_flag)
- decode_hrd_parameters(h, sps);
- vcl_hrd_parameters_present_flag = get_bits1(&s->gb);
- if(vcl_hrd_parameters_present_flag)
- decode_hrd_parameters(h, sps);
- if(nal_hrd_parameters_present_flag || vcl_hrd_parameters_present_flag)
- get_bits1(&s->gb); /* low_delay_hrd_flag */
- get_bits1(&s->gb); /* pic_struct_present_flag */
-
- sps->bitstream_restriction_flag = get_bits1(&s->gb);
- if(sps->bitstream_restriction_flag){
- unsigned int num_reorder_frames;
- 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 */
- num_reorder_frames= get_ue_golomb(&s->gb);
- get_ue_golomb(&s->gb); /*max_dec_frame_buffering*/
-
- if(num_reorder_frames > 16 /*max_dec_frame_buffering || max_dec_frame_buffering > 16*/){
- av_log(h->s.avctx, AV_LOG_ERROR, "illegal num_reorder_frames %d\n", num_reorder_frames);
- return -1;
- }
-
- sps->num_reorder_frames= num_reorder_frames;
- }
-
- 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 : zigzag_scan8x8;
- 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;i<size;i++){
- if(next)
- next = (last + get_se_golomb(&s->gb)) & 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
- }
- } else if(fallback_sps) {
- memcpy(scaling_matrix4, sps->scaling_matrix4, 6*16*sizeof(uint8_t));
- memcpy(scaling_matrix8, sps->scaling_matrix8, 2*64*sizeof(uint8_t));
- }
-}
-
-static inline int decode_seq_parameter_set(H264Context *h){
- MpegEncContext * const s = &h->s;
- int profile_idc, level_idc;
- unsigned int sps_id, tmp, mb_width, mb_height;
- 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(&s->gb);
-
- if (sps_id >= MAX_SPS_COUNT){
- // ok it has gone out of hand, someone is sending us bad stuff.
- av_log(h->s.avctx, AV_LOG_ERROR, "illegal sps_id (%d)\n", sps_id);
- return -1;
- }
-
- sps= &h->sps_buffer[ sps_id ];
- sps->profile_idc= profile_idc;
- sps->level_idc= level_idc;
-
- if(sps->profile_idc >= 100){ //high profile
- if(get_ue_golomb(&s->gb) == 3) //chroma_format_idc
- get_bits1(&s->gb); //residual_color_transform_flag
- get_ue_golomb(&s->gb); //bit_depth_luma_minus8
- get_ue_golomb(&s->gb); //bit_depth_chroma_minus8
- sps->transform_bypass = get_bits1(&s->gb);
- decode_scaling_matrices(h, sps, NULL, 1, sps->scaling_matrix4, sps->scaling_matrix8);
- }else
- sps->scaling_matrix_present = 0;
-
- sps->log2_max_frame_num= get_ue_golomb(&s->gb) + 4;
- sps->poc_type= get_ue_golomb(&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);
- tmp= get_ue_golomb(&s->gb);
-
- if(tmp >= sizeof(sps->offset_for_ref_frame) / sizeof(sps->offset_for_ref_frame[0])){
- av_log(h->s.avctx, AV_LOG_ERROR, "poc_cycle_length overflow %u\n", tmp);
- return -1;
- }
- sps->poc_cycle_length= tmp;
-
- for(i=0; i<sps->poc_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);
- return -1;
- }
-
- tmp= get_ue_golomb(&s->gb);
- if(tmp > MAX_PICTURE_COUNT-2){
- av_log(h->s.avctx, AV_LOG_ERROR, "too many reference frames\n");
- }
- sps->ref_frame_count= tmp;
- sps->gaps_in_frame_num_allowed_flag= get_bits1(&s->gb);
- mb_width= get_ue_golomb(&s->gb) + 1;
- mb_height= get_ue_golomb(&s->gb) + 1;
- if(mb_width >= INT_MAX/16 || mb_height >= INT_MAX/16 ||
- avcodec_check_dimensions(NULL, 16*mb_width, 16*mb_height)){
- av_log(h->s.avctx, AV_LOG_ERROR, "mb_width/height overflow\n");
- return -1;
- }
- sps->mb_width = mb_width;
- sps->mb_height= mb_height;
-
- 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
- if(!sps->direct_8x8_inference_flag && sps->mb_aff)
- av_log(h->s.avctx, AV_LOG_ERROR, "MBAFF + !direct_8x8_inference is not implemented\n");
-
- 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");
- }
- }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 )
- decode_vui_parameters(h, sps);
-
- 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\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" : ""
- );
- }
- return 0;
-}
-
-static inline int decode_picture_parameter_set(H264Context *h, int bit_length){
- MpegEncContext * const s = &h->s;
- unsigned int tmp, 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 out of range\n");
- return -1;
- }
- pps = &h->pps_buffer[pps_id];
-
- tmp= get_ue_golomb(&s->gb);
- if(tmp>=MAX_SPS_COUNT){
- av_log(h->s.avctx, AV_LOG_ERROR, "sps_id out of range\n");
- return -1;
- }
- pps->sps_id= tmp;
-
- 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] > 32 || pps->ref_count[1] > 32){
- av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow (pps)\n");
- pps->ref_count[0]= pps->ref_count[1]= 1;
- return -1;
- }
-
- 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= 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
- memset(pps->scaling_matrix4, 16, 6*16*sizeof(uint8_t));
- memset(pps->scaling_matrix8, 16, 2*64*sizeof(uint8_t));
-
- if(get_bits_count(&s->gb) < bit_length){
- pps->transform_8x8_mode= get_bits1(&s->gb);
- decode_scaling_matrices(h, &h->sps_buffer[pps->sps_id], pps, 0, pps->scaling_matrix4, pps->scaling_matrix8);
- get_se_golomb(&s->gb); //second_chroma_qp_index_offset
- }
-
- 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 %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,
- pps->deblocking_filter_parameters_present ? "LPAR" : "",
- pps->constrained_intra_pred ? "CONSTR" : "",
- pps->redundant_pic_cnt_present ? "REDU" : "",
- pps->transform_8x8_mode ? "8x8DCT" : ""
- );
- }
-
- return 0;
-}
-
-/**
- * finds the end of the current frame in the bitstream.
- * @return the position of the first byte of the next frame, or -1
- */
-static int find_frame_end(H264Context *h, const uint8_t *buf, int buf_size){
- int i;
- uint32_t state;
- ParseContext *pc = &(h->s.parse_context);
-//printf("first %02X%02X%02X%02X\n", buf[0], buf[1],buf[2],buf[3]);
-// mb_addr= pc->mb_addr - 1;
- state= pc->state;
- for(i=0; i<=buf_size; i++){
- if((state&0xFFFFFF1F) == 0x101 || (state&0xFFFFFF1F) == 0x102 || (state&0xFFFFFF1F) == 0x105){
- tprintf("find_frame_end new startcode = %08x, frame_start_found = %d, pos = %d\n", state, pc->frame_start_found, i);
- if(pc->frame_start_found){
- // If there isn't one more byte in the buffer
- // the test on first_mb_in_slice cannot be done yet
- // do it at next call.
- if (i >= buf_size) break;
- if (buf[i] & 0x80) {
- // first_mb_in_slice is 0, probably the first nal of a new
- // slice
- tprintf("find_frame_end frame_end_found, state = %08x, pos = %d\n", state, i);
- pc->state=-1;
- pc->frame_start_found= 0;
- return i-4;
- }
- }
- pc->frame_start_found = 1;
- }
- if((state&0xFFFFFF1F) == 0x107 || (state&0xFFFFFF1F) == 0x108 || (state&0xFFFFFF1F) == 0x109){
- if(pc->frame_start_found){
- pc->state=-1;
- pc->frame_start_found= 0;
- return i-4;
- }
- }
- if (i<buf_size)
- state= (state<<8) | buf[i];
- }
-
- pc->state= state;
- return END_NOT_FOUND;
-}
-
-#ifdef CONFIG_H264_PARSER
-static int h264_parse(AVCodecParserContext *s,
- AVCodecContext *avctx,
- uint8_t **poutbuf, int *poutbuf_size,
- const uint8_t *buf, int buf_size)
-{
- H264Context *h = s->priv_data;
- ParseContext *pc = &h->s.parse_context;
- int next;
-
- next= find_frame_end(h, buf, buf_size);
-
- if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
- *poutbuf = NULL;
- *poutbuf_size = 0;
- return buf_size;
- }
-
- *poutbuf = (uint8_t *)buf;
- *poutbuf_size = buf_size;
- return next;
-}
-
-static int h264_split(AVCodecContext *avctx,
- const uint8_t *buf, int buf_size)
-{
- int i;
- uint32_t state = -1;
- int has_sps= 0;
-
- for(i=0; i<=buf_size; i++){
- if((state&0xFFFFFF1F) == 0x107)
- has_sps=1;
-/* if((state&0xFFFFFF1F) == 0x101 || (state&0xFFFFFF1F) == 0x102 || (state&0xFFFFFF1F) == 0x105){
- }*/
- if((state&0xFFFFFF00) == 0x100 && (state&0xFFFFFF1F) != 0x107 && (state&0xFFFFFF1F) != 0x108 && (state&0xFFFFFF1F) != 0x109){
- if(has_sps){
- while(i>4 && buf[i-5]==0) i--;
- return i-4;
- }
- }
- if (i<buf_size)
- state= (state<<8) | buf[i];
- }
- return 0;
-}
-#endif /* CONFIG_H264_PARSER */
-
-static int decode_nal_units(H264Context *h, uint8_t *buf, int buf_size){
- MpegEncContext * const s = &h->s;
- AVCodecContext * const avctx= s->avctx;
- int buf_index=0;
-#if 0
- int i;
- for(i=0; i<50; i++){
- av_log(NULL, AV_LOG_ERROR,"%02X ", buf[i]);
- }
-#endif
- h->slice_num = 0;
- s->current_picture_ptr= NULL;
- for(;;){
- int consumed;
- int dst_length;
- int bit_length;
- uint8_t *ptr;
- int i, nalsize = 0;
-
- if(h->is_avc) {
- if(buf_index >= buf_size) break;
- nalsize = 0;
- for(i = 0; i < h->nal_length_size; i++)
- nalsize = (nalsize << 8) | buf[buf_index++];
- if(nalsize <= 1 || nalsize > buf_size){
- if(nalsize == 1){
- buf_index++;
- continue;
- }else{
- av_log(h->s.avctx, AV_LOG_ERROR, "AVC: nal size %d\n", nalsize);
- break;
- }
- }
- } else {
- // start code prefix search
- for(; buf_index + 3 < buf_size; buf_index++){
- // this should allways succeed in the first iteration
- if(buf[buf_index] == 0 && buf[buf_index+1] == 0 && buf[buf_index+2] == 1)
- break;
- }
-
- if(buf_index+3 >= buf_size) break;
-
- buf_index+=3;
- }
-
- ptr= decode_nal(h, buf + buf_index, &dst_length, &consumed, h->is_avc ? nalsize : buf_size - buf_index);
- if (ptr==NULL || dst_length <= 0){
- return -1;
- }
- while(ptr[dst_length - 1] == 0 && dst_length > 1)
- dst_length--;
- bit_length= 8*dst_length - decode_rbsp_trailing(ptr + dst_length - 1);
-
- if(s->avctx->debug&FF_DEBUG_STARTCODE){
- av_log(h->s.avctx, AV_LOG_DEBUG, "NAL %d at %d/%d length %d\n", h->nal_unit_type, buf_index, buf_size, dst_length);
- }
-
- if (h->is_avc && (nalsize != consumed))
- av_log(h->s.avctx, AV_LOG_ERROR, "AVC: Consumed only %d bytes instead of %d\n", consumed, nalsize);
-
- buf_index += consumed;
-
- if( (s->hurry_up == 1 && h->nal_ref_idc == 0) //FIXME dont discard SEI id
- ||(avctx->skip_frame >= AVDISCARD_NONREF && h->nal_ref_idc == 0))
- continue;
-
- switch(h->nal_unit_type){
- case NAL_IDR_SLICE:
- idr(h); //FIXME ensure we don't loose some frames if there is reordering
- case NAL_SLICE:
- init_get_bits(&s->gb, ptr, bit_length);
- h->intra_gb_ptr=
- h->inter_gb_ptr= &s->gb;
- s->data_partitioning = 0;
-
- if(decode_slice_header(h) < 0){
- av_log(h->s.avctx, AV_LOG_ERROR, "decode_slice_header error\n");
- break;
- }
- s->current_picture_ptr->key_frame= (h->nal_unit_type == NAL_IDR_SLICE);
- if(h->redundant_pic_count==0 && s->hurry_up < 5
- && (avctx->skip_frame < AVDISCARD_NONREF || h->nal_ref_idc)
- && (avctx->skip_frame < AVDISCARD_BIDIR || h->slice_type!=B_TYPE)
- && (avctx->skip_frame < AVDISCARD_NONKEY || h->slice_type==I_TYPE)
- && avctx->skip_frame < AVDISCARD_ALL)
- decode_slice(h);
- break;
- case NAL_DPA:
- init_get_bits(&s->gb, ptr, bit_length);
- h->intra_gb_ptr=
- h->inter_gb_ptr= NULL;
- s->data_partitioning = 1;
-
- if(decode_slice_header(h) < 0){
- av_log(h->s.avctx, AV_LOG_ERROR, "decode_slice_header error\n");
- }
- break;
- case NAL_DPB:
- init_get_bits(&h->intra_gb, ptr, bit_length);
- h->intra_gb_ptr= &h->intra_gb;
- break;
- case NAL_DPC:
- init_get_bits(&h->inter_gb, ptr, bit_length);
- h->inter_gb_ptr= &h->inter_gb;
-
- if(h->redundant_pic_count==0 && h->intra_gb_ptr && s->data_partitioning
- && s->context_initialized
- && s->hurry_up < 5
- && (avctx->skip_frame < AVDISCARD_NONREF || h->nal_ref_idc)
- && (avctx->skip_frame < AVDISCARD_BIDIR || h->slice_type!=B_TYPE)
- && (avctx->skip_frame < AVDISCARD_NONKEY || h->slice_type==I_TYPE)
- && avctx->skip_frame < AVDISCARD_ALL)
- decode_slice(h);
- break;
- case NAL_SEI:
- init_get_bits(&s->gb, ptr, bit_length);
- decode_sei(h);
- break;
- case NAL_SPS:
- init_get_bits(&s->gb, ptr, bit_length);
- decode_seq_parameter_set(h);
-
- if(s->flags& CODEC_FLAG_LOW_DELAY)
- s->low_delay=1;
-
- if(avctx->has_b_frames < 2)
- avctx->has_b_frames= !s->low_delay;
- break;
- case NAL_PPS:
- init_get_bits(&s->gb, ptr, bit_length);
-
- decode_picture_parameter_set(h, bit_length);
-
- break;
- case NAL_AUD:
- case NAL_END_SEQUENCE:
- case NAL_END_STREAM:
- case NAL_FILLER_DATA:
- case NAL_SPS_EXT:
- case NAL_AUXILIARY_SLICE:
- break;
- default:
- av_log(avctx, AV_LOG_ERROR, "Unknown NAL code: %d\n", h->nal_unit_type);
- }
- }
-
- if(!s->current_picture_ptr) return buf_index; //no frame
-
- s->current_picture_ptr->qscale_type= FF_QSCALE_TYPE_H264;
- s->current_picture_ptr->pict_type= s->pict_type;
-
- h->prev_frame_num_offset= h->frame_num_offset;
- h->prev_frame_num= h->frame_num;
- if(s->current_picture_ptr->reference){
- h->prev_poc_msb= h->poc_msb;
- h->prev_poc_lsb= h->poc_lsb;
- }
- if(s->current_picture_ptr->reference)
- execute_ref_pic_marking(h, h->mmco, h->mmco_index);
-
- ff_er_frame_end(s);
-
- MPV_frame_end(s);
-
- return buf_index;
-}
-
-/**
- * returns the number of bytes consumed for building the current frame
- */
-static int get_consumed_bytes(MpegEncContext *s, int pos, int buf_size){
- if(s->flags&CODEC_FLAG_TRUNCATED){
- pos -= s->parse_context.last_index;
- if(pos<0) pos=0; // FIXME remove (unneeded?)
-
- return pos;
- }else{
- if(pos==0) pos=1; //avoid infinite loops (i doubt thats needed but ...)
- if(pos+10>buf_size) pos=buf_size; // oops ;)
-
- return pos;
- }
-}
-
-static int decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- H264Context *h = avctx->priv_data;
- MpegEncContext *s = &h->s;
- AVFrame *pict = data;
- int buf_index;
-
- s->flags= avctx->flags;
- s->flags2= avctx->flags2;
-
- /* no supplementary picture */
- if (buf_size == 0) {
- return 0;
- }
-
- if(s->flags&CODEC_FLAG_TRUNCATED){
- int next= find_frame_end(h, buf, buf_size);
-
- if( ff_combine_frame(&s->parse_context, next, &buf, &buf_size) < 0 )
- return buf_size;
-//printf("next:%d buf_size:%d last_index:%d\n", next, buf_size, s->parse_context.last_index);
- }
-
- 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->is_avc && s->avctx->extradata_size && s->picture_number==0){
- if(decode_nal_units(h, s->avctx->extradata, s->avctx->extradata_size) < 0)
- return -1;
- }
-
- buf_index=decode_nal_units(h, buf, buf_size);
- if(buf_index < 0)
- return -1;
-
- //FIXME do something with unavailable reference frames
-
-// if(ret==FRAME_SKIPPED) return get_consumed_bytes(s, buf_index, buf_size);
- if(!s->current_picture_ptr){
- av_log(h->s.avctx, AV_LOG_DEBUG, "error, NO frame\n");
- return -1;
- }
-
- {
- Picture *out = s->current_picture_ptr;
-#if 0 //decode order
- *data_size = sizeof(AVFrame);
-#else
- /* Sort B-frames into display order */
- Picture *cur = s->current_picture_ptr;
- Picture *prev = h->delayed_output_pic;
- int i, pics, cross_idr, out_of_order, out_idx;
-
- 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;
- }
-
- pics = 0;
- while(h->delayed_pic[pics]) pics++;
-
- assert(pics+1 < sizeof(h->delayed_pic) / sizeof(h->delayed_pic[0]));
-
- h->delayed_pic[pics++] = cur;
- if(cur->reference == 0)
- cur->reference = 1;
-
- cross_idr = 0;
- for(i=0; h->delayed_pic[i]; i++)
- if(h->delayed_pic[i]->key_frame || h->delayed_pic[i]->poc==0)
- cross_idr = 1;
-
- out = h->delayed_pic[0];
- out_idx = 0;
- for(i=1; h->delayed_pic[i] && !h->delayed_pic[i]->key_frame; i++)
- if(h->delayed_pic[i]->poc < out->poc){
- out = h->delayed_pic[i];
- out_idx = i;
- }
-
- out_of_order = !cross_idr && prev && out->poc < prev->poc;
- if(h->sps.bitstream_restriction_flag && s->avctx->has_b_frames >= h->sps.num_reorder_frames)
- { }
- else if(prev && pics <= s->avctx->has_b_frames)
- out = prev;
- else if((out_of_order && pics-1 == s->avctx->has_b_frames && pics < 15)
- || (s->low_delay &&
- ((!cross_idr && prev && out->poc > prev->poc + 2)
- || cur->pict_type == B_TYPE)))
- {
- s->low_delay = 0;
- s->avctx->has_b_frames++;
- out = prev;
- }
- else if(out_of_order)
- out = prev;
-
- if(out_of_order || pics > s->avctx->has_b_frames){
- for(i=out_idx; h->delayed_pic[i]; i++)
- h->delayed_pic[i] = h->delayed_pic[i+1];
- }
-
- if(prev == out)
- *data_size = 0;
- else
- *data_size = sizeof(AVFrame);
- if(prev && prev != out && prev->reference == 1)
- prev->reference = 0;
- h->delayed_output_pic = out;
-#endif
-
- if(out)
- *pict= *(AVFrame*)out;
- else
- av_log(avctx, AV_LOG_DEBUG, "no picture\n");
- }
-
- assert(pict->data[0] || !*data_size);
- ff_print_debug_info(s, pict);
-//printf("out %d\n", (int)pict->data[0]);
-#if 0 //?
-
- /* Return the Picture timestamp as the frame number */
- /* we substract 1 because it is added on utils.c */
- avctx->frame_number = s->picture_number - 1;
-#endif
- return get_consumed_bytes(s, buf_index, buf_size);
-}
-#if 0
-static inline void fill_mb_avail(H264Context *h){
- MpegEncContext * const s = &h->s;
- const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
-
- if(s->mb_y){
- h->mb_avail[0]= s->mb_x && h->slice_table[mb_xy - s->mb_stride - 1] == h->slice_num;
- h->mb_avail[1]= h->slice_table[mb_xy - s->mb_stride ] == h->slice_num;
- h->mb_avail[2]= s->mb_x+1 < s->mb_width && h->slice_table[mb_xy - s->mb_stride + 1] == h->slice_num;
- }else{
- h->mb_avail[0]=
- h->mb_avail[1]=
- h->mb_avail[2]= 0;
- }
- h->mb_avail[3]= s->mb_x && h->slice_table[mb_xy - 1] == h->slice_num;
- h->mb_avail[4]= 1; //FIXME move out
- h->mb_avail[5]= 0; //FIXME move out
-}
-#endif
-
-#if 0 //selftest
-#define COUNT 8000
-#define SIZE (COUNT*40)
-int main(){
- int i;
- uint8_t temp[SIZE];
- PutBitContext pb;
- GetBitContext gb;
-// int int_temp[10000];
- DSPContext dsp;
- AVCodecContext avctx;
-
- dsputil_init(&dsp, &avctx);
-
- init_put_bits(&pb, temp, SIZE);
- printf("testing unsigned exp golomb\n");
- for(i=0; i<COUNT; i++){
- START_TIMER
- set_ue_golomb(&pb, i);
- STOP_TIMER("set_ue_golomb");
- }
- flush_put_bits(&pb);
-
- init_get_bits(&gb, temp, 8*SIZE);
- for(i=0; i<COUNT; i++){
- int j, s;
-
- s= show_bits(&gb, 24);
-
- START_TIMER
- j= get_ue_golomb(&gb);
- if(j != i){
- printf("missmatch! at %d (%d should be %d) bits:%6X\n", i, j, i, s);
-// return -1;
- }
- STOP_TIMER("get_ue_golomb");
- }
-
-
- init_put_bits(&pb, temp, SIZE);
- printf("testing signed exp golomb\n");
- for(i=0; i<COUNT; i++){
- START_TIMER
- set_se_golomb(&pb, i - COUNT/2);
- STOP_TIMER("set_se_golomb");
- }
- flush_put_bits(&pb);
-
- init_get_bits(&gb, temp, 8*SIZE);
- for(i=0; i<COUNT; i++){
- int j, s;
-
- s= show_bits(&gb, 24);
-
- START_TIMER
- j= get_se_golomb(&gb);
- if(j != i - COUNT/2){
- printf("missmatch! at %d (%d should be %d) bits:%6X\n", i, j, i, s);
-// return -1;
- }
- STOP_TIMER("get_se_golomb");
- }
-
- printf("testing 4x4 (I)DCT\n");
-
- DCTELEM block[16];
- uint8_t src[16], ref[16];
- uint64_t error= 0, max_error=0;
-
- for(i=0; i<COUNT; i++){
- int j;
-// printf("%d %d %d\n", r1, r2, (r2-r1)*16);
- for(j=0; j<16; j++){
- ref[j]= random()%255;
- src[j]= random()%255;
- }
-
- h264_diff_dct_c(block, src, ref, 4);
-
- //normalize
- for(j=0; j<16; j++){
-// printf("%d ", block[j]);
- block[j]= block[j]*4;
- if(j&1) block[j]= (block[j]*4 + 2)/5;
- if(j&4) block[j]= (block[j]*4 + 2)/5;
- }
-// printf("\n");
-
- s->dsp.h264_idct_add(ref, block, 4);
-/* for(j=0; j<16; j++){
- printf("%d ", ref[j]);
- }
- printf("\n");*/
-
- for(j=0; j<16; j++){
- int diff= FFABS(src[j] - ref[j]);
-
- error+= diff*diff;
- max_error= FFMAX(max_error, diff);
- }
- }
- printf("error=%f max_error=%d\n", ((float)error)/COUNT/16, (int)max_error );
-#if 0
- printf("testing quantizer\n");
- for(qp=0; qp<52; qp++){
- for(i=0; i<16; i++)
- src1_block[i]= src2_block[i]= random()%255;
-
- }
-#endif
- printf("Testing NAL layer\n");
-
- uint8_t bitstream[COUNT];
- uint8_t nal[COUNT*2];
- H264Context h;
- memset(&h, 0, sizeof(H264Context));
-
- for(i=0; i<COUNT; i++){
- int zeros= i;
- int nal_length;
- int consumed;
- int out_length;
- uint8_t *out;
- int j;
-
- for(j=0; j<COUNT; j++){
- bitstream[j]= (random() % 255) + 1;
- }
-
- for(j=0; j<zeros; j++){
- int pos= random() % COUNT;
- while(bitstream[pos] == 0){
- pos++;
- pos %= COUNT;
- }
- bitstream[pos]=0;
- }
-
- START_TIMER
-
- nal_length= encode_nal(&h, nal, bitstream, COUNT, COUNT*2);
- if(nal_length<0){
- printf("encoding failed\n");
- return -1;
- }
-
- out= decode_nal(&h, nal, &out_length, &consumed, nal_length);
-
- STOP_TIMER("NAL")
-
- if(out_length != COUNT){
- printf("incorrect length %d %d\n", out_length, COUNT);
- return -1;
- }
-
- if(consumed != nal_length){
- printf("incorrect consumed length %d %d\n", nal_length, consumed);
- return -1;
- }
-
- if(memcmp(bitstream, out, COUNT)){
- printf("missmatch\n");
- return -1;
- }
- }
-
- printf("Testing RBSP\n");
-
-
- return 0;
-}
-#endif
-
-
-static int decode_end(AVCodecContext *avctx)
-{
- H264Context *h = avctx->priv_data;
- MpegEncContext *s = &h->s;
-
- av_freep(&h->rbsp_buffer);
- free_tables(h); //FIXME cleanup init stuff perhaps
- MPV_common_end(s);
-
-// memset(h, 0, sizeof(H264Context));
-
- return 0;
-}
-
-
-AVCodec h264_decoder = {
- "h264",
- CODEC_TYPE_VIDEO,
- CODEC_ID_H264,
- sizeof(H264Context),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- /*CODEC_CAP_DRAW_HORIZ_BAND |*/ CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY,
- .flush= flush_dpb,
-};
-
-#ifdef CONFIG_H264_PARSER
-AVCodecParser h264_parser = {
- { CODEC_ID_H264 },
- sizeof(H264Context),
- NULL,
- h264_parse,
- ff_parse_close,
- h264_split,
-};
-#endif
-
-#include "svq3.c"
diff --git a/src/libffmpeg/libavcodec/huffyuv.c b/src/libffmpeg/libavcodec/huffyuv.c
deleted file mode 100644
index 0aefd6d72..000000000
--- a/src/libffmpeg/libavcodec/huffyuv.c
+++ /dev/null
@@ -1,1290 +0,0 @@
-/*
- * huffyuv codec for libavcodec
- *
- * Copyright (c) 2002-2003 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * see http://www.pcisys.net/~melanson/codecs/huffyuv.txt for a description of
- * the algorithm used
- */
-
-/**
- * @file huffyuv.c
- * huffyuv codec for libavcodec.
- */
-
-#include "common.h"
-#include "bitstream.h"
-#include "avcodec.h"
-#include "dsputil.h"
-
-#define VLC_BITS 11
-
-#ifdef WORDS_BIGENDIAN
-#define B 3
-#define G 2
-#define R 1
-#else
-#define B 0
-#define G 1
-#define R 2
-#endif
-
-typedef enum Predictor{
- LEFT= 0,
- PLANE,
- MEDIAN,
-} Predictor;
-
-typedef struct HYuvContext{
- AVCodecContext *avctx;
- Predictor predictor;
- GetBitContext gb;
- PutBitContext pb;
- int interlaced;
- int decorrelate;
- int bitstream_bpp;
- int version;
- int yuy2; //use yuy2 instead of 422P
- int bgr32; //use bgr32 instead of bgr24
- int width, height;
- int flags;
- int context;
- int picture_number;
- int last_slice_end;
- uint8_t *temp[3];
- uint64_t stats[3][256];
- uint8_t len[3][256];
- uint32_t bits[3][256];
- VLC vlc[3];
- AVFrame picture;
- uint8_t *bitstream_buffer;
- unsigned int bitstream_buffer_size;
- DSPContext dsp;
-}HYuvContext;
-
-static const unsigned char classic_shift_luma[] = {
- 34,36,35,69,135,232,9,16,10,24,11,23,12,16,13,10,14,8,15,8,
- 16,8,17,20,16,10,207,206,205,236,11,8,10,21,9,23,8,8,199,70,
- 69,68, 0
-};
-
-static const unsigned char classic_shift_chroma[] = {
- 66,36,37,38,39,40,41,75,76,77,110,239,144,81,82,83,84,85,118,183,
- 56,57,88,89,56,89,154,57,58,57,26,141,57,56,58,57,58,57,184,119,
- 214,245,116,83,82,49,80,79,78,77,44,75,41,40,39,38,37,36,34, 0
-};
-
-static const unsigned char classic_add_luma[256] = {
- 3, 9, 5, 12, 10, 35, 32, 29, 27, 50, 48, 45, 44, 41, 39, 37,
- 73, 70, 68, 65, 64, 61, 58, 56, 53, 50, 49, 46, 44, 41, 38, 36,
- 68, 65, 63, 61, 58, 55, 53, 51, 48, 46, 45, 43, 41, 39, 38, 36,
- 35, 33, 32, 30, 29, 27, 26, 25, 48, 47, 46, 44, 43, 41, 40, 39,
- 37, 36, 35, 34, 32, 31, 30, 28, 27, 26, 24, 23, 22, 20, 19, 37,
- 35, 34, 33, 31, 30, 29, 27, 26, 24, 23, 21, 20, 18, 17, 15, 29,
- 27, 26, 24, 22, 21, 19, 17, 16, 14, 26, 25, 23, 21, 19, 18, 16,
- 15, 27, 25, 23, 21, 19, 17, 16, 14, 26, 25, 23, 21, 18, 17, 14,
- 12, 17, 19, 13, 4, 9, 2, 11, 1, 7, 8, 0, 16, 3, 14, 6,
- 12, 10, 5, 15, 18, 11, 10, 13, 15, 16, 19, 20, 22, 24, 27, 15,
- 18, 20, 22, 24, 26, 14, 17, 20, 22, 24, 27, 15, 18, 20, 23, 25,
- 28, 16, 19, 22, 25, 28, 32, 36, 21, 25, 29, 33, 38, 42, 45, 49,
- 28, 31, 34, 37, 40, 42, 44, 47, 49, 50, 52, 54, 56, 57, 59, 60,
- 62, 64, 66, 67, 69, 35, 37, 39, 40, 42, 43, 45, 47, 48, 51, 52,
- 54, 55, 57, 59, 60, 62, 63, 66, 67, 69, 71, 72, 38, 40, 42, 43,
- 46, 47, 49, 51, 26, 28, 30, 31, 33, 34, 18, 19, 11, 13, 7, 8,
-};
-
-static const unsigned char classic_add_chroma[256] = {
- 3, 1, 2, 2, 2, 2, 3, 3, 7, 5, 7, 5, 8, 6, 11, 9,
- 7, 13, 11, 10, 9, 8, 7, 5, 9, 7, 6, 4, 7, 5, 8, 7,
- 11, 8, 13, 11, 19, 15, 22, 23, 20, 33, 32, 28, 27, 29, 51, 77,
- 43, 45, 76, 81, 46, 82, 75, 55, 56,144, 58, 80, 60, 74,147, 63,
- 143, 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, 27, 30, 21, 22,
- 17, 14, 5, 6,100, 54, 47, 50, 51, 53,106,107,108,109,110,111,
- 112,113,114,115, 4,117,118, 92, 94,121,122, 3,124,103, 2, 1,
- 0,129,130,131,120,119,126,125,136,137,138,139,140,141,142,134,
- 135,132,133,104, 64,101, 62, 57,102, 95, 93, 59, 61, 28, 97, 96,
- 52, 49, 48, 29, 32, 25, 24, 46, 23, 98, 45, 44, 43, 20, 42, 41,
- 19, 18, 99, 40, 15, 39, 38, 16, 13, 12, 11, 37, 10, 9, 8, 36,
- 7,128,127,105,123,116, 35, 34, 33,145, 31, 79, 42,146, 78, 26,
- 83, 48, 49, 50, 44, 47, 26, 31, 30, 18, 17, 19, 21, 24, 25, 13,
- 14, 16, 17, 18, 20, 21, 12, 14, 15, 9, 10, 6, 9, 6, 5, 8,
- 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; i<w-1; i++){
- acc+= src[i];
- dst[i]= acc;
- i++;
- acc+= src[i];
- dst[i]= acc;
- }
-
- for(; i<w; i++){
- acc+= src[i];
- dst[i]= acc;
- }
-
- return acc;
-}
-
-static inline void add_median_prediction(uint8_t *dst, uint8_t *src1, uint8_t *diff, int w, int *left, int *left_top){
- int i;
- uint8_t l, lt;
-
- l= *left;
- lt= *left_top;
-
- for(i=0; i<w; i++){
- l= mid_pred(l, src1[i], (l + src1[i] - lt)&0xFF) + diff[i];
- lt= src1[i];
- dst[i]= l;
- }
-
- *left= l;
- *left_top= lt;
-}
-
-static inline void add_left_prediction_bgr32(uint8_t *dst, uint8_t *src, int w, int *red, int *green, int *blue){
- int i;
- int r,g,b;
- r= *red;
- g= *green;
- b= *blue;
-
- for(i=0; i<w; i++){
- b+= src[4*i+B];
- g+= src[4*i+G];
- r+= src[4*i+R];
-
- dst[4*i+B]= b;
- dst[4*i+G]= g;
- dst[4*i+R]= r;
- }
-
- *red= r;
- *green= g;
- *blue= b;
-}
-
-static inline int sub_left_prediction(HYuvContext *s, uint8_t *dst, uint8_t *src, int w, int left){
- int i;
- if(w<32){
- for(i=0; i<w; i++){
- const int temp= src[i];
- dst[i]= temp - left;
- left= temp;
- }
- return left;
- }else{
- for(i=0; i<16; i++){
- const int temp= src[i];
- dst[i]= temp - left;
- left= temp;
- }
- s->dsp.diff_bytes(dst+16, src+16, src+15, w-16);
- return src[w-1];
- }
-}
-
-static void read_len_table(uint8_t *dst, GetBitContext *gb){
- int i, val, repeat;
-
- for(i=0; i<256;){
- repeat= get_bits(gb, 3);
- val = get_bits(gb, 5);
- if(repeat==0)
- repeat= get_bits(gb, 8);
-//printf("%d %d\n", val, repeat);
- while (repeat--)
- dst[i++] = val;
- }
-}
-
-static int generate_bits_table(uint32_t *dst, uint8_t *len_table){
- int len, index;
- uint32_t bits=0;
-
- for(len=32; len>0; len--){
- for(index=0; index<256; index++){
- if(len_table[index]==len)
- dst[index]= bits++;
- }
- if(bits & 1){
- av_log(NULL, AV_LOG_ERROR, "Error generating huffman table\n");
- return -1;
- }
- bits >>= 1;
- }
- return 0;
-}
-
-#ifdef CONFIG_ENCODERS
-static void generate_len_table(uint8_t *dst, uint64_t *stats, int size){
- uint64_t counts[2*size];
- int up[2*size];
- int offset, i, next;
-
- for(offset=1; ; offset<<=1){
- for(i=0; i<size; i++){
- counts[i]= stats[i] + offset - 1;
- }
-
- for(next=size; next<size*2; next++){
- uint64_t min1, min2;
- int min1_i, min2_i;
-
- min1=min2= INT64_MAX;
- min1_i= min2_i=-1;
-
- for(i=0; i<next; i++){
- if(min2 > counts[i]){
- if(min1 > counts[i]){
- min2= min1;
- min2_i= min1_i;
- min1= counts[i];
- min1_i= i;
- }else{
- min2= counts[i];
- min2_i= i;
- }
- }
- }
-
- if(min2==INT64_MAX) break;
-
- counts[next]= min1 + min2;
- counts[min1_i]=
- counts[min2_i]= INT64_MAX;
- up[min1_i]=
- up[min2_i]= next;
- up[next]= -1;
- }
-
- for(i=0; i<size; i++){
- int len;
- int index=i;
-
- for(len=0; up[index] != -1; len++)
- index= up[index];
-
- if(len >= 32) break;
-
- dst[i]= len;
- }
- if(i==size) break;
- }
-}
-#endif /* CONFIG_ENCODERS */
-
-static int read_huffman_tables(HYuvContext *s, uint8_t *src, int length){
- GetBitContext gb;
- int i;
-
- init_get_bits(&gb, src, length*8);
-
- for(i=0; i<3; i++){
- read_len_table(s->len[i], &gb);
-
- if(generate_bits_table(s->bits[i], s->len[i])<0){
- return -1;
- }
-#if 0
-for(j=0; j<256; j++){
-printf("%6X, %2d, %3d\n", s->bits[i][j], s->len[i][j], j);
-}
-#endif
- free_vlc(&s->vlc[i]);
- init_vlc(&s->vlc[i], VLC_BITS, 256, s->len[i], 1, 1, s->bits[i], 4, 4, 0);
- }
-
- return (get_bits_count(&gb)+7)/8;
-}
-
-static int read_old_huffman_tables(HYuvContext *s){
-#if 1
- GetBitContext gb;
- int i;
-
- init_get_bits(&gb, classic_shift_luma, sizeof(classic_shift_luma)*8);
- read_len_table(s->len[0], &gb);
- init_get_bits(&gb, classic_shift_chroma, sizeof(classic_shift_chroma)*8);
- read_len_table(s->len[1], &gb);
-
- for(i=0; i<256; i++) s->bits[0][i] = classic_add_luma [i];
- for(i=0; i<256; i++) s->bits[1][i] = classic_add_chroma[i];
-
- if(s->bitstream_bpp >= 24){
- memcpy(s->bits[1], s->bits[0], 256*sizeof(uint32_t));
- memcpy(s->len[1] , s->len [0], 256*sizeof(uint8_t));
- }
- memcpy(s->bits[2], s->bits[1], 256*sizeof(uint32_t));
- memcpy(s->len[2] , s->len [1], 256*sizeof(uint8_t));
-
- for(i=0; i<3; i++){
- free_vlc(&s->vlc[i]);
- init_vlc(&s->vlc[i], VLC_BITS, 256, s->len[i], 1, 1, s->bits[i], 4, 4, 0);
- }
-
- return 0;
-#else
- av_log(s->avctx, AV_LOG_DEBUG, "v1 huffyuv is not supported \n");
- return -1;
-#endif
-}
-
-static void alloc_temp(HYuvContext *s){
- int i;
-
- if(s->bitstream_bpp<24){
- for(i=0; i<3; i++){
- s->temp[i]= av_malloc(s->width + 16);
- }
- }else{
- s->temp[0]= av_malloc(4*s->width + 16);
- }
-}
-
-static int common_init(AVCodecContext *avctx){
- HYuvContext *s = avctx->priv_data;
-
- s->avctx= avctx;
- s->flags= avctx->flags;
-
- dsputil_init(&s->dsp, avctx);
-
- s->width= avctx->width;
- s->height= avctx->height;
- assert(s->width>0 && s->height>0);
-
- return 0;
-}
-
-#ifdef CONFIG_DECODERS
-static int decode_init(AVCodecContext *avctx)
-{
- HYuvContext *s = avctx->priv_data;
-
- common_init(avctx);
- memset(s->vlc, 0, 3*sizeof(VLC));
-
- avctx->coded_frame= &s->picture;
- s->interlaced= s->height > 288;
-
-s->bgr32=1;
-//if(avctx->extradata)
-// printf("extradata:%X, extradata_size:%d\n", *(uint32_t*)avctx->extradata, avctx->extradata_size);
- if(avctx->extradata_size){
- if((avctx->bits_per_sample&7) && avctx->bits_per_sample != 12)
- s->version=1; // do such files exist at all?
- else
- s->version=2;
- }else
- s->version=0;
-
- if(s->version==2){
- int method, interlace;
-
- method= ((uint8_t*)avctx->extradata)[0];
- s->decorrelate= method&64 ? 1 : 0;
- s->predictor= method&63;
- s->bitstream_bpp= ((uint8_t*)avctx->extradata)[1];
- if(s->bitstream_bpp==0)
- s->bitstream_bpp= avctx->bits_per_sample&~7;
- interlace= (((uint8_t*)avctx->extradata)[2] & 0x30) >> 4;
- 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)
- return -1;
- }else{
- switch(avctx->bits_per_sample&7){
- case 1:
- s->predictor= LEFT;
- s->decorrelate= 0;
- break;
- case 2:
- s->predictor= LEFT;
- s->decorrelate= 1;
- break;
- case 3:
- s->predictor= PLANE;
- s->decorrelate= avctx->bits_per_sample >= 24;
- break;
- case 4:
- s->predictor= MEDIAN;
- s->decorrelate= 0;
- break;
- default:
- s->predictor= LEFT; //OLD
- s->decorrelate= 0;
- break;
- }
- s->bitstream_bpp= avctx->bits_per_sample & ~7;
- s->context= 0;
-
- if(read_old_huffman_tables(s) < 0)
- return -1;
- }
-
- switch(s->bitstream_bpp){
- case 12:
- avctx->pix_fmt = PIX_FMT_YUV420P;
- break;
- case 16:
- if(s->yuy2){
- avctx->pix_fmt = PIX_FMT_YUV422;
- }else{
- avctx->pix_fmt = PIX_FMT_YUV422P;
- }
- break;
- case 24:
- case 32:
- if(s->bgr32){
- avctx->pix_fmt = PIX_FMT_RGBA32;
- }else{
- avctx->pix_fmt = PIX_FMT_BGR24;
- }
- break;
- default:
- assert(0);
- }
-
- alloc_temp(s);
-
-// av_log(NULL, AV_LOG_DEBUG, "pred:%d bpp:%d hbpp:%d il:%d\n", s->predictor, s->bitstream_bpp, avctx->bits_per_sample, s->interlaced);
-
- return 0;
-}
-#endif
-
-#ifdef CONFIG_ENCODERS
-static int store_table(HYuvContext *s, uint8_t *len, uint8_t *buf){
- int i;
- int index= 0;
-
- for(i=0; i<256;){
- int val= len[i];
- int repeat=0;
-
- for(; i<256 && len[i]==val && repeat<255; i++)
- repeat++;
-
- assert(val < 32 && val >0 && repeat<256 && repeat>0);
- if(repeat>7){
- buf[index++]= val;
- buf[index++]= repeat;
- }else{
- buf[index++]= val | (repeat<<5);
- }
- }
-
- return index;
-}
-
-static int encode_init(AVCodecContext *avctx)
-{
- HYuvContext *s = avctx->priv_data;
- int i, j;
-
- common_init(avctx);
-
- avctx->extradata= av_mallocz(1024*30); // 256*3+4 == 772
- avctx->stats_out= av_mallocz(1024*30); // 21*256*3(%llu ) + 3(\n) + 1(0) = 16132
- s->version=2;
-
- avctx->coded_frame= &s->picture;
-
- switch(avctx->pix_fmt){
- case PIX_FMT_YUV420P:
- s->bitstream_bpp= 12;
- break;
- case PIX_FMT_YUV422P:
- s->bitstream_bpp= 16;
- break;
- default:
- av_log(avctx, AV_LOG_ERROR, "format not supported\n");
- return -1;
- }
- avctx->bits_per_sample= s->bitstream_bpp;
- s->decorrelate= s->bitstream_bpp >= 24;
- s->predictor= avctx->prediction_method;
- s->interlaced= avctx->flags&CODEC_FLAG_INTERLACED_ME ? 1 : 0;
- if(avctx->context_model==1){
- s->context= avctx->context_model;
- if(s->flags & (CODEC_FLAG_PASS1|CODEC_FLAG_PASS2)){
- av_log(avctx, AV_LOG_ERROR, "context=1 is not compatible with 2 pass huffyuv encoding\n");
- return -1;
- }
- }else s->context= 0;
-
- if(avctx->codec->id==CODEC_ID_HUFFYUV){
- if(avctx->pix_fmt==PIX_FMT_YUV420P){
- av_log(avctx, AV_LOG_ERROR, "Error: YV12 is not supported by huffyuv; use vcodec=ffvhuff or format=422p\n");
- return -1;
- }
- if(avctx->context_model){
- av_log(avctx, AV_LOG_ERROR, "Error: per-frame huffman tables are not supported by huffyuv; use vcodec=ffvhuff\n");
- return -1;
- }
- if(s->interlaced != ( s->height > 288 ))
- av_log(avctx, AV_LOG_INFO, "using huffyuv 2.2.0 or newer interlacing flag\n");
- }
-
- ((uint8_t*)avctx->extradata)[0]= s->predictor;
- ((uint8_t*)avctx->extradata)[1]= s->bitstream_bpp;
- ((uint8_t*)avctx->extradata)[2]= s->interlaced ? 0x10 : 0x20;
- if(s->context)
- ((uint8_t*)avctx->extradata)[2]|= 0x40;
- ((uint8_t*)avctx->extradata)[3]= 0;
- s->avctx->extradata_size= 4;
-
- if(avctx->stats_in){
- char *p= avctx->stats_in;
-
- for(i=0; i<3; i++)
- for(j=0; j<256; j++)
- s->stats[i][j]= 1;
-
- for(;;){
- for(i=0; i<3; i++){
- char *next;
-
- for(j=0; j<256; j++){
- s->stats[i][j]+= strtol(p, &next, 0);
- if(next==p) return -1;
- p=next;
- }
- }
- if(p[0]==0 || p[1]==0 || p[2]==0) break;
- }
- }else{
- for(i=0; i<3; i++)
- for(j=0; j<256; j++){
- int d= FFMIN(j, 256-j);
-
- s->stats[i][j]= 100000000/(d+1);
- }
- }
-
- for(i=0; i<3; i++){
- generate_len_table(s->len[i], s->stats[i], 256);
-
- if(generate_bits_table(s->bits[i], s->len[i])<0){
- return -1;
- }
-
- s->avctx->extradata_size+=
- store_table(s, s->len[i], &((uint8_t*)s->avctx->extradata)[s->avctx->extradata_size]);
- }
-
- if(s->context){
- for(i=0; i<3; i++){
- int pels = s->width*s->height / (i?40:10);
- for(j=0; j<256; j++){
- int d= FFMIN(j, 256-j);
- s->stats[i][j]= pels/(d+1);
- }
- }
- }else{
- for(i=0; i<3; i++)
- for(j=0; j<256; j++)
- s->stats[i][j]= 0;
- }
-
-// printf("pred:%d bpp:%d hbpp:%d il:%d\n", s->predictor, s->bitstream_bpp, avctx->bits_per_sample, s->interlaced);
-
- alloc_temp(s);
-
- s->picture_number=0;
-
- return 0;
-}
-#endif /* CONFIG_ENCODERS */
-
-static void decode_422_bitstream(HYuvContext *s, int count){
- int i;
-
- count/=2;
-
- for(i=0; i<count; i++){
- s->temp[0][2*i ]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
- s->temp[1][ i ]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3);
- s->temp[0][2*i+1]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
- s->temp[2][ i ]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3);
- }
-}
-
-static void decode_gray_bitstream(HYuvContext *s, int count){
- int i;
-
- count/=2;
-
- for(i=0; i<count; i++){
- s->temp[0][2*i ]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
- s->temp[0][2*i+1]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
- }
-}
-
-#ifdef CONFIG_ENCODERS
-static int encode_422_bitstream(HYuvContext *s, int count){
- int i;
-
- if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < 2*4*count){
- av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
- return -1;
- }
-
- count/=2;
- if(s->flags&CODEC_FLAG_PASS1){
- for(i=0; i<count; i++){
- s->stats[0][ s->temp[0][2*i ] ]++;
- s->stats[1][ s->temp[1][ i ] ]++;
- s->stats[0][ s->temp[0][2*i+1] ]++;
- s->stats[2][ s->temp[2][ i ] ]++;
- }
- }
- if(s->avctx->flags2&CODEC_FLAG2_NO_OUTPUT)
- return 0;
- if(s->context){
- for(i=0; i<count; i++){
- s->stats[0][ s->temp[0][2*i ] ]++;
- put_bits(&s->pb, s->len[0][ s->temp[0][2*i ] ], s->bits[0][ s->temp[0][2*i ] ]);
- s->stats[1][ s->temp[1][ i ] ]++;
- put_bits(&s->pb, s->len[1][ s->temp[1][ i ] ], s->bits[1][ s->temp[1][ i ] ]);
- s->stats[0][ s->temp[0][2*i+1] ]++;
- put_bits(&s->pb, s->len[0][ s->temp[0][2*i+1] ], s->bits[0][ s->temp[0][2*i+1] ]);
- s->stats[2][ s->temp[2][ i ] ]++;
- put_bits(&s->pb, s->len[2][ s->temp[2][ i ] ], s->bits[2][ s->temp[2][ i ] ]);
- }
- }else{
- for(i=0; i<count; i++){
- put_bits(&s->pb, s->len[0][ s->temp[0][2*i ] ], s->bits[0][ s->temp[0][2*i ] ]);
- put_bits(&s->pb, s->len[1][ s->temp[1][ i ] ], s->bits[1][ s->temp[1][ i ] ]);
- put_bits(&s->pb, s->len[0][ s->temp[0][2*i+1] ], s->bits[0][ s->temp[0][2*i+1] ]);
- put_bits(&s->pb, s->len[2][ s->temp[2][ i ] ], s->bits[2][ s->temp[2][ i ] ]);
- }
- }
- return 0;
-}
-
-static int encode_gray_bitstream(HYuvContext *s, int count){
- int i;
-
- if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < 4*count){
- av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
- return -1;
- }
-
- count/=2;
- if(s->flags&CODEC_FLAG_PASS1){
- for(i=0; i<count; i++){
- s->stats[0][ s->temp[0][2*i ] ]++;
- s->stats[0][ s->temp[0][2*i+1] ]++;
- }
- }
- if(s->avctx->flags2&CODEC_FLAG2_NO_OUTPUT)
- return 0;
-
- if(s->context){
- for(i=0; i<count; i++){
- s->stats[0][ s->temp[0][2*i ] ]++;
- put_bits(&s->pb, s->len[0][ s->temp[0][2*i ] ], s->bits[0][ s->temp[0][2*i ] ]);
- s->stats[0][ s->temp[0][2*i+1] ]++;
- put_bits(&s->pb, s->len[0][ s->temp[0][2*i+1] ], s->bits[0][ s->temp[0][2*i+1] ]);
- }
- }else{
- for(i=0; i<count; i++){
- put_bits(&s->pb, s->len[0][ s->temp[0][2*i ] ], s->bits[0][ s->temp[0][2*i ] ]);
- put_bits(&s->pb, s->len[0][ s->temp[0][2*i+1] ], s->bits[0][ s->temp[0][2*i+1] ]);
- }
- }
- return 0;
-}
-#endif /* CONFIG_ENCODERS */
-
-static void decode_bgr_bitstream(HYuvContext *s, int count){
- int i;
-
- if(s->decorrelate){
- if(s->bitstream_bpp==24){
- for(i=0; i<count; i++){
- s->temp[0][4*i+G]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3);
- s->temp[0][4*i+B]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3) + s->temp[0][4*i+G];
- s->temp[0][4*i+R]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3) + s->temp[0][4*i+G];
- }
- }else{
- for(i=0; i<count; i++){
- s->temp[0][4*i+G]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3);
- s->temp[0][4*i+B]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3) + s->temp[0][4*i+G];
- s->temp[0][4*i+R]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3) + s->temp[0][4*i+G];
- get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); //?!
- }
- }
- }else{
- if(s->bitstream_bpp==24){
- for(i=0; i<count; i++){
- s->temp[0][4*i+B]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
- s->temp[0][4*i+G]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3);
- s->temp[0][4*i+R]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3);
- }
- }else{
- for(i=0; i<count; i++){
- s->temp[0][4*i+B]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
- s->temp[0][4*i+G]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3);
- s->temp[0][4*i+R]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3);
- get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); //?!
- }
- }
- }
-}
-
-#ifdef CONFIG_DECODERS
-static void draw_slice(HYuvContext *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->bitstream_bpp==12){
- cy= y>>1;
- }else{
- cy= y;
- }
-
- offset[0] = s->picture.linesize[0]*y;
- offset[1] = s->picture.linesize[1]*cy;
- offset[2] = s->picture.linesize[2]*cy;
- offset[3] = 0;
- emms_c();
-
- s->avctx->draw_horiz_band(s->avctx, &s->picture, offset, y, 3, h);
-
- s->last_slice_end= y + h;
-}
-
-static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size){
- HYuvContext *s = avctx->priv_data;
- const int width= s->width;
- const int width2= s->width>>1;
- const int height= s->height;
- int fake_ystride, fake_ustride, fake_vstride;
- AVFrame * const p= &s->picture;
- int table_size= 0;
-
- AVFrame *picture = data;
-
- s->bitstream_buffer= av_fast_realloc(s->bitstream_buffer, &s->bitstream_buffer_size, buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
-
- s->dsp.bswap_buf((uint32_t*)s->bitstream_buffer, (uint32_t*)buf, buf_size/4);
-
- 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;
- }
-
- if(s->context){
- table_size = read_huffman_tables(s, s->bitstream_buffer, buf_size);
- if(table_size < 0)
- return -1;
- }
-
- if((unsigned)(buf_size-table_size) >= INT_MAX/8)
- return -1;
-
- init_get_bits(&s->gb, s->bitstream_buffer+table_size, (buf_size-table_size)*8);
-
- fake_ystride= s->interlaced ? p->linesize[0]*2 : p->linesize[0];
- fake_ustride= s->interlaced ? p->linesize[1]*2 : p->linesize[1];
- fake_vstride= s->interlaced ? p->linesize[2]*2 : p->linesize[2];
-
- s->last_slice_end= 0;
-
- if(s->bitstream_bpp<24){
- int y, cy;
- int lefty, leftu, leftv;
- int lefttopy, lefttopu, lefttopv;
-
- if(s->yuy2){
- p->data[0][3]= get_bits(&s->gb, 8);
- p->data[0][2]= get_bits(&s->gb, 8);
- p->data[0][1]= get_bits(&s->gb, 8);
- p->data[0][0]= get_bits(&s->gb, 8);
-
- av_log(avctx, AV_LOG_ERROR, "YUY2 output is not implemented yet\n");
- return -1;
- }else{
-
- leftv= p->data[2][0]= get_bits(&s->gb, 8);
- lefty= p->data[0][1]= get_bits(&s->gb, 8);
- leftu= p->data[1][0]= get_bits(&s->gb, 8);
- p->data[0][0]= get_bits(&s->gb, 8);
-
- switch(s->predictor){
- case LEFT:
- case PLANE:
- decode_422_bitstream(s, width-2);
- lefty= add_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);
- }
-
- for(cy=y=1; y<s->height; y++,cy++){
- uint8_t *ydst, *udst, *vdst;
-
- if(s->bitstream_bpp==12){
- decode_gray_bitstream(s, width);
-
- ydst= p->data[0] + p->linesize[0]*y;
-
- lefty= add_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);
- }
- y++;
- if(y>=s->height) break;
- }
-
- draw_slice(s, y);
-
- ydst= p->data[0] + p->linesize[0]*y;
- udst= p->data[1] + p->linesize[1]*cy;
- vdst= p->data[2] + p->linesize[2]*cy;
-
- decode_422_bitstream(s, width);
- lefty= add_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);
- }
- if(s->predictor == PLANE){
- if(cy>s->interlaced){
- s->dsp.add_bytes(ydst, ydst - fake_ystride, width);
- if(!(s->flags&CODEC_FLAG_GRAY)){
- s->dsp.add_bytes(udst, udst - fake_ustride, width2);
- s->dsp.add_bytes(vdst, vdst - fake_vstride, width2);
- }
- }
- }
- }
- draw_slice(s, height);
-
- break;
- 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);
- 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);
- }
-
- cy=y=1;
-
- /* 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);
- 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);
- }
- 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);
- 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);
- }
-
- /* next line except the first 4 pixels is median predicted */
- lefttopy= p->data[0][3];
- decode_422_bitstream(s, width-4);
- add_median_prediction(p->data[0] + fake_ystride+4, p->data[0]+4, s->temp[0], width-4, &lefty, &lefttopy);
- if(!(s->flags&CODEC_FLAG_GRAY)){
- lefttopu= p->data[1][1];
- lefttopv= p->data[2][1];
- add_median_prediction(p->data[1] + fake_ustride+2, p->data[1]+2, s->temp[1], width2-2, &leftu, &lefttopu);
- add_median_prediction(p->data[2] + fake_vstride+2, p->data[2]+2, s->temp[2], width2-2, &leftv, &lefttopv);
- }
- y++; cy++;
-
- for(; y<height; y++,cy++){
- uint8_t *ydst, *udst, *vdst;
-
- if(s->bitstream_bpp==12){
- while(2*cy > y){
- decode_gray_bitstream(s, width);
- ydst= p->data[0] + p->linesize[0]*y;
- add_median_prediction(ydst, ydst - fake_ystride, s->temp[0], width, &lefty, &lefttopy);
- y++;
- }
- if(y>=height) break;
- }
- draw_slice(s, y);
-
- decode_422_bitstream(s, width);
-
- ydst= p->data[0] + p->linesize[0]*y;
- udst= p->data[1] + p->linesize[1]*cy;
- vdst= p->data[2] + p->linesize[2]*cy;
-
- add_median_prediction(ydst, ydst - fake_ystride, s->temp[0], width, &lefty, &lefttopy);
- if(!(s->flags&CODEC_FLAG_GRAY)){
- add_median_prediction(udst, udst - fake_ustride, s->temp[1], width2, &leftu, &lefttopu);
- add_median_prediction(vdst, vdst - fake_vstride, s->temp[2], width2, &leftv, &lefttopv);
- }
- }
-
- draw_slice(s, height);
- break;
- }
- }
- }else{
- int y;
- int leftr, leftg, leftb;
- const int last_line= (height-1)*p->linesize[0];
-
- if(s->bitstream_bpp==32){
- skip_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);
- }else{
- 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);
- skip_bits(&s->gb, 8);
- }
-
- if(s->bgr32){
- switch(s->predictor){
- 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);
-
- for(y=s->height-2; y>=0; y--){ //yes its 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);
- if(s->predictor == PLANE){
- if((y&s->interlaced)==0 && y<s->height-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);
- }
- }
- }
- draw_slice(s, height); // just 1 large slice as this is not possible in reverse order
- break;
- default:
- av_log(avctx, AV_LOG_ERROR, "prediction type not supported!\n");
- }
- }else{
-
- av_log(avctx, AV_LOG_ERROR, "BGR24 output is not implemented yet\n");
- return -1;
- }
- }
- emms_c();
-
- *picture= *p;
- *data_size = sizeof(AVFrame);
-
- return (get_bits_count(&s->gb)+31)/32*4 + table_size;
-}
-#endif
-
-static int common_end(HYuvContext *s){
- int i;
-
- for(i=0; i<3; i++){
- av_freep(&s->temp[i]);
- }
- return 0;
-}
-
-#ifdef CONFIG_DECODERS
-static int decode_end(AVCodecContext *avctx)
-{
- HYuvContext *s = avctx->priv_data;
- int i;
-
- common_end(s);
- av_freep(&s->bitstream_buffer);
-
- for(i=0; i<3; i++){
- free_vlc(&s->vlc[i]);
- }
-
- return 0;
-}
-#endif
-
-#ifdef CONFIG_ENCODERS
-static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
- HYuvContext *s = avctx->priv_data;
- AVFrame *pict = data;
- const int width= s->width;
- const int width2= s->width>>1;
- const int height= s->height;
- const int fake_ystride= s->interlaced ? pict->linesize[0]*2 : pict->linesize[0];
- const int fake_ustride= s->interlaced ? pict->linesize[1]*2 : pict->linesize[1];
- const int fake_vstride= s->interlaced ? pict->linesize[2]*2 : pict->linesize[2];
- AVFrame * const p= &s->picture;
- int i, j, size=0;
-
- *p = *pict;
- p->pict_type= FF_I_TYPE;
- p->key_frame= 1;
-
- if(s->context){
- for(i=0; i<3; i++){
- generate_len_table(s->len[i], s->stats[i], 256);
- if(generate_bits_table(s->bits[i], s->len[i])<0)
- return -1;
- size+= store_table(s, s->len[i], &buf[size]);
- }
-
- for(i=0; i<3; i++)
- for(j=0; j<256; j++)
- s->stats[i][j] >>= 1;
- }
-
- init_put_bits(&s->pb, buf+size, buf_size-size);
-
- if(avctx->pix_fmt == PIX_FMT_YUV422P || avctx->pix_fmt == PIX_FMT_YUV420P){
- int lefty, leftu, leftv, y, cy;
-
- put_bits(&s->pb, 8, leftv= p->data[2][0]);
- put_bits(&s->pb, 8, lefty= p->data[0][1]);
- put_bits(&s->pb, 8, leftu= p->data[1][0]);
- put_bits(&s->pb, 8, p->data[0][0]);
-
- lefty= sub_left_prediction(s, s->temp[0], p->data[0]+2, width-2 , lefty);
- leftu= sub_left_prediction(s, s->temp[1], p->data[1]+1, width2-1, leftu);
- leftv= sub_left_prediction(s, s->temp[2], p->data[2]+1, width2-1, leftv);
-
- encode_422_bitstream(s, width-2);
-
- if(s->predictor==MEDIAN){
- int lefttopy, lefttopu, lefttopv;
- cy=y=1;
- if(s->interlaced){
- lefty= sub_left_prediction(s, s->temp[0], p->data[0]+p->linesize[0], width , lefty);
- leftu= sub_left_prediction(s, s->temp[1], p->data[1]+p->linesize[1], width2, leftu);
- leftv= sub_left_prediction(s, s->temp[2], p->data[2]+p->linesize[2], width2, leftv);
-
- encode_422_bitstream(s, width);
- y++; cy++;
- }
-
- lefty= sub_left_prediction(s, s->temp[0], p->data[0]+fake_ystride, 4, lefty);
- leftu= sub_left_prediction(s, s->temp[1], p->data[1]+fake_ustride, 2, leftu);
- leftv= sub_left_prediction(s, s->temp[2], p->data[2]+fake_vstride, 2, leftv);
-
- encode_422_bitstream(s, 4);
-
- lefttopy= p->data[0][3];
- lefttopu= p->data[1][1];
- lefttopv= p->data[2][1];
- s->dsp.sub_hfyu_median_prediction(s->temp[0], p->data[0]+4, p->data[0] + fake_ystride+4, width-4 , &lefty, &lefttopy);
- s->dsp.sub_hfyu_median_prediction(s->temp[1], p->data[1]+2, p->data[1] + fake_ustride+2, width2-2, &leftu, &lefttopu);
- s->dsp.sub_hfyu_median_prediction(s->temp[2], p->data[2]+2, p->data[2] + fake_vstride+2, width2-2, &leftv, &lefttopv);
- encode_422_bitstream(s, width-4);
- y++; cy++;
-
- for(; y<height; y++,cy++){
- uint8_t *ydst, *udst, *vdst;
-
- if(s->bitstream_bpp==12){
- while(2*cy > y){
- ydst= p->data[0] + p->linesize[0]*y;
- s->dsp.sub_hfyu_median_prediction(s->temp[0], ydst - fake_ystride, ydst, width , &lefty, &lefttopy);
- encode_gray_bitstream(s, width);
- y++;
- }
- if(y>=height) break;
- }
- ydst= p->data[0] + p->linesize[0]*y;
- udst= p->data[1] + p->linesize[1]*cy;
- vdst= p->data[2] + p->linesize[2]*cy;
-
- s->dsp.sub_hfyu_median_prediction(s->temp[0], ydst - fake_ystride, ydst, width , &lefty, &lefttopy);
- s->dsp.sub_hfyu_median_prediction(s->temp[1], udst - fake_ustride, udst, width2, &leftu, &lefttopu);
- s->dsp.sub_hfyu_median_prediction(s->temp[2], vdst - fake_vstride, vdst, width2, &leftv, &lefttopv);
-
- encode_422_bitstream(s, width);
- }
- }else{
- for(cy=y=1; y<height; y++,cy++){
- uint8_t *ydst, *udst, *vdst;
-
- /* encode a luma only line & y++ */
- if(s->bitstream_bpp==12){
- ydst= p->data[0] + p->linesize[0]*y;
-
- if(s->predictor == PLANE && s->interlaced < y){
- s->dsp.diff_bytes(s->temp[1], ydst, ydst - fake_ystride, width);
-
- lefty= sub_left_prediction(s, s->temp[0], s->temp[1], width , lefty);
- }else{
- lefty= sub_left_prediction(s, s->temp[0], ydst, width , lefty);
- }
- encode_gray_bitstream(s, width);
- y++;
- if(y>=height) break;
- }
-
- ydst= p->data[0] + p->linesize[0]*y;
- udst= p->data[1] + p->linesize[1]*cy;
- vdst= p->data[2] + p->linesize[2]*cy;
-
- if(s->predictor == PLANE && s->interlaced < cy){
- s->dsp.diff_bytes(s->temp[1], ydst, ydst - fake_ystride, width);
- s->dsp.diff_bytes(s->temp[2], udst, udst - fake_ustride, width2);
- s->dsp.diff_bytes(s->temp[2] + width2, vdst, vdst - fake_vstride, width2);
-
- lefty= sub_left_prediction(s, s->temp[0], s->temp[1], width , lefty);
- leftu= sub_left_prediction(s, s->temp[1], s->temp[2], width2, leftu);
- leftv= sub_left_prediction(s, s->temp[2], s->temp[2] + width2, width2, leftv);
- }else{
- lefty= sub_left_prediction(s, s->temp[0], ydst, width , lefty);
- leftu= sub_left_prediction(s, s->temp[1], udst, width2, leftu);
- leftv= sub_left_prediction(s, s->temp[2], vdst, width2, leftv);
- }
-
- encode_422_bitstream(s, width);
- }
- }
- }else{
- av_log(avctx, AV_LOG_ERROR, "Format not supported!\n");
- }
- emms_c();
-
- size+= (put_bits_count(&s->pb)+31)/8;
- size/= 4;
-
- if((s->flags&CODEC_FLAG_PASS1) && (s->picture_number&31)==0){
- int j;
- char *p= avctx->stats_out;
- char *end= p + 1024*30;
- for(i=0; i<3; i++){
- for(j=0; j<256; j++){
- snprintf(p, end-p, "%"PRIu64" ", s->stats[i][j]);
- p+= strlen(p);
- s->stats[i][j]= 0;
- }
- snprintf(p, end-p, "\n");
- p++;
- }
- }
- if(!(s->avctx->flags2 & CODEC_FLAG2_NO_OUTPUT)){
- flush_put_bits(&s->pb);
- s->dsp.bswap_buf((uint32_t*)buf, (uint32_t*)buf, size);
- avctx->stats_out[0] = '\0';
- }
-
- s->picture_number++;
-
- return size*4;
-}
-
-static int encode_end(AVCodecContext *avctx)
-{
- HYuvContext *s = avctx->priv_data;
-
- common_end(s);
-
- av_freep(&avctx->extradata);
- av_freep(&avctx->stats_out);
-
- return 0;
-}
-#endif /* CONFIG_ENCODERS */
-
-#ifdef CONFIG_DECODERS
-AVCodec huffyuv_decoder = {
- "huffyuv",
- CODEC_TYPE_VIDEO,
- CODEC_ID_HUFFYUV,
- sizeof(HYuvContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1 | CODEC_CAP_DRAW_HORIZ_BAND,
- NULL
-};
-
-AVCodec ffvhuff_decoder = {
- "ffvhuff",
- CODEC_TYPE_VIDEO,
- CODEC_ID_FFVHUFF,
- sizeof(HYuvContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1 | CODEC_CAP_DRAW_HORIZ_BAND,
- NULL
-};
-#endif
-
-#ifdef CONFIG_ENCODERS
-
-AVCodec huffyuv_encoder = {
- "huffyuv",
- CODEC_TYPE_VIDEO,
- CODEC_ID_HUFFYUV,
- sizeof(HYuvContext),
- encode_init,
- encode_frame,
- encode_end,
- .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV422P, -1},
-};
-
-AVCodec ffvhuff_encoder = {
- "ffvhuff",
- CODEC_TYPE_VIDEO,
- CODEC_ID_FFVHUFF,
- sizeof(HYuvContext),
- encode_init,
- encode_frame,
- encode_end,
- .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, -1},
-};
-
-#endif //CONFIG_ENCODERS
diff --git a/src/libffmpeg/libavcodec/i386/Makefile.am b/src/libffmpeg/libavcodec/i386/Makefile.am
deleted file mode 100644
index b9d33c3a7..000000000
--- a/src/libffmpeg/libavcodec/i386/Makefile.am
+++ /dev/null
@@ -1,54 +0,0 @@
-include $(top_srcdir)/misc/Makefile.common
-
-# -fomit-frame-pointer is always needed. it might cause debug to not
-# work, but at least it compiles.
-AM_CFLAGS = -fomit-frame-pointer -fno-strict-aliasing
-# CFLAGS is here to filter out -funroll-loops because it causes bad
-# behavior of libavcodec
-CFLAGS := `echo @CFLAGS@ | sed -e 's/-funroll-loops//g'`
-AM_CPPFLAGS = $(LIBFFMPEG_CPPFLAGS) -I$(top_srcdir)/src/libffmpeg/libavutil -I$(top_srcdir)/src/libffmpeg -I$(top_builddir)/src/libffmpeg
-
-# Avoid "can't find register" failures with -O1 and higher
-dsputil_mmx.o dsputil_mmx.lo: CFLAGS=$(shell echo @CFLAGS@ | sed -e 's/-funroll-loops//g; s/$$/ -Os/')
-
-# Avoid errors on (at least) amd64 with -O0
-fdct_mmx.o fdct_mmx.lo: CFLAGS=`echo @CFLAGS@ | sed -e 's/^/-Os /; s/-O0\?\s/-Os /g'`
-
-# Avoid errors with -O0
-mpegvideo_mmx.o mpegvideo_mmx.lo: CFLAGS=`echo @CFLAGS@ | sed -e 's/-O0\?\s/-Os /g'`
-
-ASFLAGS =
-
-noinst_LTLIBRARIES = libavcodec_mmx.la
-
-libavcodec_mmx_src = \
- cputest.c \
- dsputil_mmx.c \
- fdct_mmx.c \
- fft_3dn.c \
- fft_3dn2.c \
- fft_sse.c \
- idct_mmx.c \
- idct_mmx_xvid.c \
- motion_est_mmx.c \
- mpegvideo_mmx.c \
- simple_idct_mmx.c \
- vp3dsp_mmx.c \
- vp3dsp_sse2.c
-
-libavcodec_mmx_dummy = libavcodec_mmx_dummy.c
-
-EXTRA_DIST = \
- $(libavcodec_mmx_dummy) \
- $(libavcodec_mmx_src) \
- dsputil_h264_template_mmx.c \
- h264dsp_mmx.c \
- mpegvideo_mmx_template.c
-
-if HAVE_MMX
-mmx_modules = $(libavcodec_mmx_src)
-endif
-
-libavcodec_mmx_la_SOURCES = $(mmx_modules) $(libavcodec_mmx_dummy)
-
-noinst_HEADERS = dsputil_mmx_avg.h dsputil_mmx_rnd.h mathops.h mmx.h
diff --git a/src/libffmpeg/libavcodec/i386/dsputil_h264_template_mmx.c b/src/libffmpeg/libavcodec/i386/dsputil_h264_template_mmx.c
deleted file mode 100644
index e09a1007e..000000000
--- a/src/libffmpeg/libavcodec/i386/dsputil_h264_template_mmx.c
+++ /dev/null
@@ -1,326 +0,0 @@
-/*
- * Copyright (c) 2005 Zoltan Hidvegi <hzoli -a- hzoli -d- com>,
- * Loren Merritt
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/**
- * MMX optimized version of (put|avg)_h264_chroma_mc8.
- * H264_CHROMA_MC8_TMPL must be defined to the desired function name
- * H264_CHROMA_OP must be defined to empty for put and pavgb/pavgusb for avg
- * H264_CHROMA_MC8_MV0 must be defined to a (put|avg)_pixels8 function
- */
-static void H264_CHROMA_MC8_TMPL(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y)
-{
- DECLARE_ALIGNED_8(uint64_t, AA);
- DECLARE_ALIGNED_8(uint64_t, DD);
- int i;
-
- if(y==0 && x==0) {
- /* no filter needed */
- H264_CHROMA_MC8_MV0(dst, src, stride, h);
- return;
- }
-
- assert(x<8 && y<8 && x>=0 && y>=0);
-
- if(y==0 || x==0)
- {
- /* 1 dimensional filter only */
- const int dxy = x ? 1 : stride;
-
- asm volatile(
- "movd %0, %%mm5\n\t"
- "movq %1, %%mm4\n\t"
- "punpcklwd %%mm5, %%mm5\n\t"
- "punpckldq %%mm5, %%mm5\n\t" /* mm5 = B = x */
- "movq %%mm4, %%mm6\n\t"
- "pxor %%mm7, %%mm7\n\t"
- "psubw %%mm5, %%mm4\n\t" /* mm4 = A = 8-x */
- "psrlw $1, %%mm6\n\t" /* mm6 = 4 */
- :: "rm"(x+y), "m"(ff_pw_8));
-
- for(i=0; i<h; i++) {
- asm volatile(
- /* mm0 = src[0..7], mm1 = src[1..8] */
- "movq %0, %%mm0\n\t"
- "movq %1, %%mm2\n\t"
- :: "m"(src[0]), "m"(src[dxy]));
-
- asm volatile(
- /* [mm0,mm1] = A * src[0..7] */
- /* [mm2,mm3] = B * src[1..8] */
- "movq %%mm0, %%mm1\n\t"
- "movq %%mm2, %%mm3\n\t"
- "punpcklbw %%mm7, %%mm0\n\t"
- "punpckhbw %%mm7, %%mm1\n\t"
- "punpcklbw %%mm7, %%mm2\n\t"
- "punpckhbw %%mm7, %%mm3\n\t"
- "pmullw %%mm4, %%mm0\n\t"
- "pmullw %%mm4, %%mm1\n\t"
- "pmullw %%mm5, %%mm2\n\t"
- "pmullw %%mm5, %%mm3\n\t"
-
- /* dst[0..7] = (A * src[0..7] + B * src[1..8] + 4) >> 3 */
- "paddw %%mm6, %%mm0\n\t"
- "paddw %%mm6, %%mm1\n\t"
- "paddw %%mm2, %%mm0\n\t"
- "paddw %%mm3, %%mm1\n\t"
- "psrlw $3, %%mm0\n\t"
- "psrlw $3, %%mm1\n\t"
- "packuswb %%mm1, %%mm0\n\t"
- H264_CHROMA_OP(%0, %%mm0)
- "movq %%mm0, %0\n\t"
- : "=m" (dst[0]));
-
- src += stride;
- dst += stride;
- }
- return;
- }
-
- /* general case, bilinear */
- asm volatile("movd %2, %%mm4\n\t"
- "movd %3, %%mm6\n\t"
- "punpcklwd %%mm4, %%mm4\n\t"
- "punpcklwd %%mm6, %%mm6\n\t"
- "punpckldq %%mm4, %%mm4\n\t" /* mm4 = x words */
- "punpckldq %%mm6, %%mm6\n\t" /* mm6 = y words */
- "movq %%mm4, %%mm5\n\t"
- "pmullw %%mm6, %%mm4\n\t" /* mm4 = x * y */
- "psllw $3, %%mm5\n\t"
- "psllw $3, %%mm6\n\t"
- "movq %%mm5, %%mm7\n\t"
- "paddw %%mm6, %%mm7\n\t"
- "movq %%mm4, %1\n\t" /* DD = x * y */
- "psubw %%mm4, %%mm5\n\t" /* mm5 = B = 8x - xy */
- "psubw %%mm4, %%mm6\n\t" /* mm6 = C = 8y - xy */
- "paddw %4, %%mm4\n\t"
- "psubw %%mm7, %%mm4\n\t" /* mm4 = A = xy - (8x+8y) + 64 */
- "pxor %%mm7, %%mm7\n\t"
- "movq %%mm4, %0\n\t"
- : "=m" (AA), "=m" (DD) : "rm" (x), "rm" (y), "m" (ff_pw_64));
-
- asm volatile(
- /* mm0 = src[0..7], mm1 = src[1..8] */
- "movq %0, %%mm0\n\t"
- "movq %1, %%mm1\n\t"
- : : "m" (src[0]), "m" (src[1]));
-
- for(i=0; i<h; i++) {
- src += stride;
-
- asm volatile(
- /* mm2 = A * src[0..3] + B * src[1..4] */
- /* mm3 = A * src[4..7] + B * src[5..8] */
- "movq %%mm0, %%mm2\n\t"
- "movq %%mm1, %%mm3\n\t"
- "punpckhbw %%mm7, %%mm0\n\t"
- "punpcklbw %%mm7, %%mm1\n\t"
- "punpcklbw %%mm7, %%mm2\n\t"
- "punpckhbw %%mm7, %%mm3\n\t"
- "pmullw %0, %%mm0\n\t"
- "pmullw %0, %%mm2\n\t"
- "pmullw %%mm5, %%mm1\n\t"
- "pmullw %%mm5, %%mm3\n\t"
- "paddw %%mm1, %%mm2\n\t"
- "paddw %%mm0, %%mm3\n\t"
- : : "m" (AA));
-
- asm volatile(
- /* [mm2,mm3] += C * src[0..7] */
- "movq %0, %%mm0\n\t"
- "movq %%mm0, %%mm1\n\t"
- "punpcklbw %%mm7, %%mm0\n\t"
- "punpckhbw %%mm7, %%mm1\n\t"
- "pmullw %%mm6, %%mm0\n\t"
- "pmullw %%mm6, %%mm1\n\t"
- "paddw %%mm0, %%mm2\n\t"
- "paddw %%mm1, %%mm3\n\t"
- : : "m" (src[0]));
-
- asm volatile(
- /* [mm2,mm3] += D * src[1..8] */
- "movq %1, %%mm1\n\t"
- "movq %%mm1, %%mm0\n\t"
- "movq %%mm1, %%mm4\n\t"
- "punpcklbw %%mm7, %%mm0\n\t"
- "punpckhbw %%mm7, %%mm4\n\t"
- "pmullw %2, %%mm0\n\t"
- "pmullw %2, %%mm4\n\t"
- "paddw %%mm0, %%mm2\n\t"
- "paddw %%mm4, %%mm3\n\t"
- "movq %0, %%mm0\n\t"
- : : "m" (src[0]), "m" (src[1]), "m" (DD));
-
- asm volatile(
- /* dst[0..7] = ([mm2,mm3] + 32) >> 6 */
- "paddw %1, %%mm2\n\t"
- "paddw %1, %%mm3\n\t"
- "psrlw $6, %%mm2\n\t"
- "psrlw $6, %%mm3\n\t"
- "packuswb %%mm3, %%mm2\n\t"
- H264_CHROMA_OP(%0, %%mm2)
- "movq %%mm2, %0\n\t"
- : "=m" (dst[0]) : "m" (ff_pw_32));
- dst+= stride;
- }
-}
-
-static void H264_CHROMA_MC4_TMPL(uint8_t *dst/*align 4*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y)
-{
- DECLARE_ALIGNED_8(uint64_t, AA);
- DECLARE_ALIGNED_8(uint64_t, DD);
- int i;
-
- /* no special case for mv=(0,0) in 4x*, since it's much less common than in 8x*.
- * could still save a few cycles, but maybe not worth the complexity. */
-
- assert(x<8 && y<8 && x>=0 && y>=0);
-
- asm volatile("movd %2, %%mm4\n\t"
- "movd %3, %%mm6\n\t"
- "punpcklwd %%mm4, %%mm4\n\t"
- "punpcklwd %%mm6, %%mm6\n\t"
- "punpckldq %%mm4, %%mm4\n\t" /* mm4 = x words */
- "punpckldq %%mm6, %%mm6\n\t" /* mm6 = y words */
- "movq %%mm4, %%mm5\n\t"
- "pmullw %%mm6, %%mm4\n\t" /* mm4 = x * y */
- "psllw $3, %%mm5\n\t"
- "psllw $3, %%mm6\n\t"
- "movq %%mm5, %%mm7\n\t"
- "paddw %%mm6, %%mm7\n\t"
- "movq %%mm4, %1\n\t" /* DD = x * y */
- "psubw %%mm4, %%mm5\n\t" /* mm5 = B = 8x - xy */
- "psubw %%mm4, %%mm6\n\t" /* mm6 = C = 8y - xy */
- "paddw %4, %%mm4\n\t"
- "psubw %%mm7, %%mm4\n\t" /* mm4 = A = xy - (8x+8y) + 64 */
- "pxor %%mm7, %%mm7\n\t"
- "movq %%mm4, %0\n\t"
- : "=m" (AA), "=m" (DD) : "rm" (x), "rm" (y), "m" (ff_pw_64));
-
- asm volatile(
- /* mm0 = src[0..3], mm1 = src[1..4] */
- "movd %0, %%mm0\n\t"
- "movd %1, %%mm1\n\t"
- "punpcklbw %%mm7, %%mm0\n\t"
- "punpcklbw %%mm7, %%mm1\n\t"
- : : "m" (src[0]), "m" (src[1]));
-
- for(i=0; i<h; i++) {
- asm volatile(
- /* mm2 = A * src[0..3] + B * src[1..4] */
- "movq %%mm0, %%mm2\n\t"
- "pmullw %0, %%mm2\n\t"
- "pmullw %%mm5, %%mm1\n\t"
- "paddw %%mm1, %%mm2\n\t"
- : : "m" (AA));
-
- src += stride;
- asm volatile(
- /* mm0 = src[0..3], mm1 = src[1..4] */
- "movd %0, %%mm0\n\t"
- "movd %1, %%mm1\n\t"
- "punpcklbw %%mm7, %%mm0\n\t"
- "punpcklbw %%mm7, %%mm1\n\t"
- : : "m" (src[0]), "m" (src[1]));
-
- asm volatile(
- /* mm2 += C * src[0..3] + D * src[1..4] */
- "movq %%mm0, %%mm3\n\t"
- "movq %%mm1, %%mm4\n\t"
- "pmullw %%mm6, %%mm3\n\t"
- "pmullw %0, %%mm4\n\t"
- "paddw %%mm3, %%mm2\n\t"
- "paddw %%mm4, %%mm2\n\t"
- : : "m" (DD));
-
- asm volatile(
- /* dst[0..3] = pack((mm2 + 32) >> 6) */
- "paddw %1, %%mm2\n\t"
- "psrlw $6, %%mm2\n\t"
- "packuswb %%mm7, %%mm2\n\t"
- H264_CHROMA_OP4(%0, %%mm2, %%mm3)
- "movd %%mm2, %0\n\t"
- : "=m" (dst[0]) : "m" (ff_pw_32));
- dst += stride;
- }
-}
-
-#ifdef H264_CHROMA_MC2_TMPL
-static void H264_CHROMA_MC2_TMPL(uint8_t *dst/*align 2*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y)
-{
- int CD=((1<<16)-1)*x*y + 8*y;
- int AB=((8<<16)-8)*x + 64 - CD;
- int i;
-
- asm volatile(
- /* mm5 = {A,B,A,B} */
- /* mm6 = {C,D,C,D} */
- "movd %0, %%mm5\n\t"
- "movd %1, %%mm6\n\t"
- "punpckldq %%mm5, %%mm5\n\t"
- "punpckldq %%mm6, %%mm6\n\t"
- "pxor %%mm7, %%mm7\n\t"
- :: "r"(AB), "r"(CD));
-
- asm volatile(
- /* mm0 = src[0,1,1,2] */
- "movd %0, %%mm0\n\t"
- "punpcklbw %%mm7, %%mm0\n\t"
- "pshufw $0x94, %%mm0, %%mm0\n\t"
- :: "m"(src[0]));
-
- for(i=0; i<h; i++) {
- asm volatile(
- /* mm1 = A * src[0,1] + B * src[1,2] */
- "movq %%mm0, %%mm1\n\t"
- "pmaddwd %%mm5, %%mm1\n\t"
- ::);
-
- src += stride;
- asm volatile(
- /* mm0 = src[0,1,1,2] */
- "movd %0, %%mm0\n\t"
- "punpcklbw %%mm7, %%mm0\n\t"
- "pshufw $0x94, %%mm0, %%mm0\n\t"
- :: "m"(src[0]));
-
- asm volatile(
- /* mm1 += C * src[0,1] + D * src[1,2] */
- "movq %%mm0, %%mm2\n\t"
- "pmaddwd %%mm6, %%mm2\n\t"
- "paddw %%mm2, %%mm1\n\t"
- ::);
-
- asm volatile(
- /* dst[0,1] = pack((mm1 + 32) >> 6) */
- "paddw %1, %%mm1\n\t"
- "psrlw $6, %%mm1\n\t"
- "packssdw %%mm7, %%mm1\n\t"
- "packuswb %%mm7, %%mm1\n\t"
- /* writes garbage to the right of dst.
- * ok because partitions are processed from left to right. */
- H264_CHROMA_OP4(%0, %%mm1, %%mm3)
- "movd %%mm1, %0\n\t"
- : "=m" (dst[0]) : "m" (ff_pw_32));
- dst += stride;
- }
-}
-#endif
-
diff --git a/src/libffmpeg/libavcodec/i386/dsputil_mmx.c b/src/libffmpeg/libavcodec/i386/dsputil_mmx.c
deleted file mode 100644
index 673e749c4..000000000
--- a/src/libffmpeg/libavcodec/i386/dsputil_mmx.c
+++ /dev/null
@@ -1,3540 +0,0 @@
-/*
- * MMX optimized DSP utils
- * Copyright (c) 2000, 2001 Fabrice Bellard.
- * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
- */
-
-#include "../dsputil.h"
-#include "../simple_idct.h"
-#include "../mpegvideo.h"
-#include "x86_cpu.h"
-#include "mmx.h"
-
-//#undef NDEBUG
-//#include <assert.h>
-
-extern void ff_idct_xvid_mmx(short *block);
-extern void ff_idct_xvid_mmx2(short *block);
-
-int mm_flags; /* multimedia extension flags */
-
-/* pixel operations */
-static const uint64_t mm_bone attribute_used __attribute__ ((aligned(8))) = 0x0101010101010101ULL;
-static const uint64_t mm_wone attribute_used __attribute__ ((aligned(8))) = 0x0001000100010001ULL;
-static const uint64_t mm_wtwo attribute_used __attribute__ ((aligned(8))) = 0x0002000200020002ULL;
-
-static const uint64_t ff_pdw_80000000[2] attribute_used __attribute__ ((aligned(16))) =
-{0x8000000080000000ULL, 0x8000000080000000ULL};
-
-static const uint64_t ff_pw_20 attribute_used __attribute__ ((aligned(8))) = 0x0014001400140014ULL;
-static const uint64_t ff_pw_3 attribute_used __attribute__ ((aligned(8))) = 0x0003000300030003ULL;
-static const uint64_t ff_pw_4 attribute_used __attribute__ ((aligned(8))) = 0x0004000400040004ULL;
-static const uint64_t ff_pw_5 attribute_used __attribute__ ((aligned(8))) = 0x0005000500050005ULL;
-static const uint64_t ff_pw_8 attribute_used __attribute__ ((aligned(8))) = 0x0008000800080008ULL;
-static const uint64_t ff_pw_16 attribute_used __attribute__ ((aligned(8))) = 0x0010001000100010ULL;
-static const uint64_t ff_pw_32 attribute_used __attribute__ ((aligned(8))) = 0x0020002000200020ULL;
-static const uint64_t ff_pw_64 attribute_used __attribute__ ((aligned(8))) = 0x0040004000400040ULL;
-static const uint64_t ff_pw_15 attribute_used __attribute__ ((aligned(8))) = 0x000F000F000F000FULL;
-
-static const uint64_t ff_pb_1 attribute_used __attribute__ ((aligned(8))) = 0x0101010101010101ULL;
-static const uint64_t ff_pb_3 attribute_used __attribute__ ((aligned(8))) = 0x0303030303030303ULL;
-static const uint64_t ff_pb_7 attribute_used __attribute__ ((aligned(8))) = 0x0707070707070707ULL;
-static const uint64_t ff_pb_3F attribute_used __attribute__ ((aligned(8))) = 0x3F3F3F3F3F3F3F3FULL;
-static const uint64_t ff_pb_A1 attribute_used __attribute__ ((aligned(8))) = 0xA1A1A1A1A1A1A1A1ULL;
-static const uint64_t ff_pb_5F attribute_used __attribute__ ((aligned(8))) = 0x5F5F5F5F5F5F5F5FULL;
-static const uint64_t ff_pb_FC attribute_used __attribute__ ((aligned(8))) = 0xFCFCFCFCFCFCFCFCULL;
-
-#define JUMPALIGN() __asm __volatile (ASMALIGN(3)::)
-#define MOVQ_ZERO(regd) __asm __volatile ("pxor %%" #regd ", %%" #regd ::)
-
-#define MOVQ_WONE(regd) \
- __asm __volatile ( \
- "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
- "psrlw $15, %%" #regd ::)
-
-#define MOVQ_BFE(regd) \
- __asm __volatile ( \
- "pcmpeqd %%" #regd ", %%" #regd " \n\t"\
- "paddb %%" #regd ", %%" #regd " \n\t" ::)
-
-#ifndef PIC
-#define MOVQ_BONE(regd) __asm __volatile ("movq %0, %%" #regd " \n\t" ::"m"(mm_bone))
-#define MOVQ_WTWO(regd) __asm __volatile ("movq %0, %%" #regd " \n\t" ::"m"(mm_wtwo))
-#else
-// for shared library it's better to use this way for accessing constants
-// pcmpeqd -> -1
-#define MOVQ_BONE(regd) \
- __asm __volatile ( \
- "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
- "psrlw $15, %%" #regd " \n\t" \
- "packuswb %%" #regd ", %%" #regd " \n\t" ::)
-
-#define MOVQ_WTWO(regd) \
- __asm __volatile ( \
- "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
- "psrlw $15, %%" #regd " \n\t" \
- "psllw $1, %%" #regd " \n\t"::)
-
-#endif
-
-// using regr as temporary and for the output result
-// first argument is unmodifed and second is trashed
-// regfe is supposed to contain 0xfefefefefefefefe
-#define PAVGB_MMX_NO_RND(rega, regb, regr, regfe) \
- "movq " #rega ", " #regr " \n\t"\
- "pand " #regb ", " #regr " \n\t"\
- "pxor " #rega ", " #regb " \n\t"\
- "pand " #regfe "," #regb " \n\t"\
- "psrlq $1, " #regb " \n\t"\
- "paddb " #regb ", " #regr " \n\t"
-
-#define PAVGB_MMX(rega, regb, regr, regfe) \
- "movq " #rega ", " #regr " \n\t"\
- "por " #regb ", " #regr " \n\t"\
- "pxor " #rega ", " #regb " \n\t"\
- "pand " #regfe "," #regb " \n\t"\
- "psrlq $1, " #regb " \n\t"\
- "psubb " #regb ", " #regr " \n\t"
-
-// mm6 is supposed to contain 0xfefefefefefefefe
-#define PAVGBP_MMX_NO_RND(rega, regb, regr, regc, regd, regp) \
- "movq " #rega ", " #regr " \n\t"\
- "movq " #regc ", " #regp " \n\t"\
- "pand " #regb ", " #regr " \n\t"\
- "pand " #regd ", " #regp " \n\t"\
- "pxor " #rega ", " #regb " \n\t"\
- "pxor " #regc ", " #regd " \n\t"\
- "pand %%mm6, " #regb " \n\t"\
- "pand %%mm6, " #regd " \n\t"\
- "psrlq $1, " #regb " \n\t"\
- "psrlq $1, " #regd " \n\t"\
- "paddb " #regb ", " #regr " \n\t"\
- "paddb " #regd ", " #regp " \n\t"
-
-#define PAVGBP_MMX(rega, regb, regr, regc, regd, regp) \
- "movq " #rega ", " #regr " \n\t"\
- "movq " #regc ", " #regp " \n\t"\
- "por " #regb ", " #regr " \n\t"\
- "por " #regd ", " #regp " \n\t"\
- "pxor " #rega ", " #regb " \n\t"\
- "pxor " #regc ", " #regd " \n\t"\
- "pand %%mm6, " #regb " \n\t"\
- "pand %%mm6, " #regd " \n\t"\
- "psrlq $1, " #regd " \n\t"\
- "psrlq $1, " #regb " \n\t"\
- "psubb " #regb ", " #regr " \n\t"\
- "psubb " #regd ", " #regp " \n\t"
-
-/***********************************/
-/* MMX no rounding */
-#define DEF(x, y) x ## _no_rnd_ ## y ##_mmx
-#define SET_RND MOVQ_WONE
-#define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX_NO_RND(a, b, c, d, e, f)
-#define PAVGB(a, b, c, e) PAVGB_MMX_NO_RND(a, b, c, e)
-
-#include "dsputil_mmx_rnd.h"
-
-#undef DEF
-#undef SET_RND
-#undef PAVGBP
-#undef PAVGB
-/***********************************/
-/* MMX rounding */
-
-#define DEF(x, y) x ## _ ## y ##_mmx
-#define SET_RND MOVQ_WTWO
-#define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX(a, b, c, d, e, f)
-#define PAVGB(a, b, c, e) PAVGB_MMX(a, b, c, e)
-
-#include "dsputil_mmx_rnd.h"
-
-#undef DEF
-#undef SET_RND
-#undef PAVGBP
-#undef PAVGB
-
-/***********************************/
-/* 3Dnow specific */
-
-#define DEF(x) x ## _3dnow
-/* for Athlons PAVGUSB is prefered */
-#define PAVGB "pavgusb"
-
-#include "dsputil_mmx_avg.h"
-
-#undef DEF
-#undef PAVGB
-
-/***********************************/
-/* MMX2 specific */
-
-#define DEF(x) x ## _mmx2
-
-/* Introduced only in MMX2 set */
-#define PAVGB "pavgb"
-
-#include "dsputil_mmx_avg.h"
-
-#undef DEF
-#undef PAVGB
-
-#define SBUTTERFLY(a,b,t,n)\
- "movq " #a ", " #t " \n\t" /* abcd */\
- "punpckl" #n " " #b ", " #a " \n\t" /* aebf */\
- "punpckh" #n " " #b ", " #t " \n\t" /* cgdh */\
-
-/***********************************/
-/* standard MMX */
-
-#ifdef CONFIG_ENCODERS
-static void get_pixels_mmx(DCTELEM *block, const uint8_t *pixels, int line_size)
-{
- asm volatile(
- "mov $-128, %%"REG_a" \n\t"
- "pxor %%mm7, %%mm7 \n\t"
- ASMALIGN(4)
- "1: \n\t"
- "movq (%0), %%mm0 \n\t"
- "movq (%0, %2), %%mm2 \n\t"
- "movq %%mm0, %%mm1 \n\t"
- "movq %%mm2, %%mm3 \n\t"
- "punpcklbw %%mm7, %%mm0 \n\t"
- "punpckhbw %%mm7, %%mm1 \n\t"
- "punpcklbw %%mm7, %%mm2 \n\t"
- "punpckhbw %%mm7, %%mm3 \n\t"
- "movq %%mm0, (%1, %%"REG_a") \n\t"
- "movq %%mm1, 8(%1, %%"REG_a") \n\t"
- "movq %%mm2, 16(%1, %%"REG_a") \n\t"
- "movq %%mm3, 24(%1, %%"REG_a") \n\t"
- "add %3, %0 \n\t"
- "add $32, %%"REG_a" \n\t"
- "js 1b \n\t"
- : "+r" (pixels)
- : "r" (block+64), "r" ((long)line_size), "r" ((long)line_size*2)
- : "%"REG_a
- );
-}
-
-static inline void diff_pixels_mmx(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, int stride)
-{
- asm volatile(
- "pxor %%mm7, %%mm7 \n\t"
- "mov $-128, %%"REG_a" \n\t"
- ASMALIGN(4)
- "1: \n\t"
- "movq (%0), %%mm0 \n\t"
- "movq (%1), %%mm2 \n\t"
- "movq %%mm0, %%mm1 \n\t"
- "movq %%mm2, %%mm3 \n\t"
- "punpcklbw %%mm7, %%mm0 \n\t"
- "punpckhbw %%mm7, %%mm1 \n\t"
- "punpcklbw %%mm7, %%mm2 \n\t"
- "punpckhbw %%mm7, %%mm3 \n\t"
- "psubw %%mm2, %%mm0 \n\t"
- "psubw %%mm3, %%mm1 \n\t"
- "movq %%mm0, (%2, %%"REG_a") \n\t"
- "movq %%mm1, 8(%2, %%"REG_a") \n\t"
- "add %3, %0 \n\t"
- "add %3, %1 \n\t"
- "add $16, %%"REG_a" \n\t"
- "jnz 1b \n\t"
- : "+r" (s1), "+r" (s2)
- : "r" (block+64), "r" ((long)stride)
- : "%"REG_a
- );
-}
-#endif //CONFIG_ENCODERS
-
-void put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
-{
- const DCTELEM *p;
- uint8_t *pix;
-
- /* read the pixels */
- p = block;
- pix = pixels;
- /* unrolled loop */
- __asm __volatile(
- "movq %3, %%mm0 \n\t"
- "movq 8%3, %%mm1 \n\t"
- "movq 16%3, %%mm2 \n\t"
- "movq 24%3, %%mm3 \n\t"
- "movq 32%3, %%mm4 \n\t"
- "movq 40%3, %%mm5 \n\t"
- "movq 48%3, %%mm6 \n\t"
- "movq 56%3, %%mm7 \n\t"
- "packuswb %%mm1, %%mm0 \n\t"
- "packuswb %%mm3, %%mm2 \n\t"
- "packuswb %%mm5, %%mm4 \n\t"
- "packuswb %%mm7, %%mm6 \n\t"
- "movq %%mm0, (%0) \n\t"
- "movq %%mm2, (%0, %1) \n\t"
- "movq %%mm4, (%0, %1, 2) \n\t"
- "movq %%mm6, (%0, %2) \n\t"
- ::"r" (pix), "r" ((long)line_size), "r" ((long)line_size*3), "m"(*p)
- :"memory");
- pix += line_size*4;
- p += 32;
-
- // if here would be an exact copy of the code above
- // compiler would generate some very strange code
- // thus using "r"
- __asm __volatile(
- "movq (%3), %%mm0 \n\t"
- "movq 8(%3), %%mm1 \n\t"
- "movq 16(%3), %%mm2 \n\t"
- "movq 24(%3), %%mm3 \n\t"
- "movq 32(%3), %%mm4 \n\t"
- "movq 40(%3), %%mm5 \n\t"
- "movq 48(%3), %%mm6 \n\t"
- "movq 56(%3), %%mm7 \n\t"
- "packuswb %%mm1, %%mm0 \n\t"
- "packuswb %%mm3, %%mm2 \n\t"
- "packuswb %%mm5, %%mm4 \n\t"
- "packuswb %%mm7, %%mm6 \n\t"
- "movq %%mm0, (%0) \n\t"
- "movq %%mm2, (%0, %1) \n\t"
- "movq %%mm4, (%0, %1, 2) \n\t"
- "movq %%mm6, (%0, %2) \n\t"
- ::"r" (pix), "r" ((long)line_size), "r" ((long)line_size*3), "r"(p)
- :"memory");
-}
-
-static DECLARE_ALIGNED_8(const unsigned char, vector128[8]) =
- { 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 };
-
-void put_signed_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
-{
- int i;
-
- movq_m2r(*vector128, mm1);
- for (i = 0; i < 8; i++) {
- movq_m2r(*(block), mm0);
- packsswb_m2r(*(block + 4), mm0);
- block += 8;
- paddb_r2r(mm1, mm0);
- movq_r2m(mm0, *pixels);
- pixels += line_size;
- }
-}
-
-void add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
-{
- const DCTELEM *p;
- uint8_t *pix;
- int i;
-
- /* read the pixels */
- p = block;
- pix = pixels;
- MOVQ_ZERO(mm7);
- i = 4;
- do {
- __asm __volatile(
- "movq (%2), %%mm0 \n\t"
- "movq 8(%2), %%mm1 \n\t"
- "movq 16(%2), %%mm2 \n\t"
- "movq 24(%2), %%mm3 \n\t"
- "movq %0, %%mm4 \n\t"
- "movq %1, %%mm6 \n\t"
- "movq %%mm4, %%mm5 \n\t"
- "punpcklbw %%mm7, %%mm4 \n\t"
- "punpckhbw %%mm7, %%mm5 \n\t"
- "paddsw %%mm4, %%mm0 \n\t"
- "paddsw %%mm5, %%mm1 \n\t"
- "movq %%mm6, %%mm5 \n\t"
- "punpcklbw %%mm7, %%mm6 \n\t"
- "punpckhbw %%mm7, %%mm5 \n\t"
- "paddsw %%mm6, %%mm2 \n\t"
- "paddsw %%mm5, %%mm3 \n\t"
- "packuswb %%mm1, %%mm0 \n\t"
- "packuswb %%mm3, %%mm2 \n\t"
- "movq %%mm0, %0 \n\t"
- "movq %%mm2, %1 \n\t"
- :"+m"(*pix), "+m"(*(pix+line_size))
- :"r"(p)
- :"memory");
- pix += line_size*2;
- p += 16;
- } while (--i);
-}
-
-static void put_pixels4_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
-{
- __asm __volatile(
- "lea (%3, %3), %%"REG_a" \n\t"
- ASMALIGN(3)
- "1: \n\t"
- "movd (%1), %%mm0 \n\t"
- "movd (%1, %3), %%mm1 \n\t"
- "movd %%mm0, (%2) \n\t"
- "movd %%mm1, (%2, %3) \n\t"
- "add %%"REG_a", %1 \n\t"
- "add %%"REG_a", %2 \n\t"
- "movd (%1), %%mm0 \n\t"
- "movd (%1, %3), %%mm1 \n\t"
- "movd %%mm0, (%2) \n\t"
- "movd %%mm1, (%2, %3) \n\t"
- "add %%"REG_a", %1 \n\t"
- "add %%"REG_a", %2 \n\t"
- "subl $4, %0 \n\t"
- "jnz 1b \n\t"
- : "+g"(h), "+r" (pixels), "+r" (block)
- : "r"((long)line_size)
- : "%"REG_a, "memory"
- );
-}
-
-static void put_pixels8_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
-{
- __asm __volatile(
- "lea (%3, %3), %%"REG_a" \n\t"
- ASMALIGN(3)
- "1: \n\t"
- "movq (%1), %%mm0 \n\t"
- "movq (%1, %3), %%mm1 \n\t"
- "movq %%mm0, (%2) \n\t"
- "movq %%mm1, (%2, %3) \n\t"
- "add %%"REG_a", %1 \n\t"
- "add %%"REG_a", %2 \n\t"
- "movq (%1), %%mm0 \n\t"
- "movq (%1, %3), %%mm1 \n\t"
- "movq %%mm0, (%2) \n\t"
- "movq %%mm1, (%2, %3) \n\t"
- "add %%"REG_a", %1 \n\t"
- "add %%"REG_a", %2 \n\t"
- "subl $4, %0 \n\t"
- "jnz 1b \n\t"
- : "+g"(h), "+r" (pixels), "+r" (block)
- : "r"((long)line_size)
- : "%"REG_a, "memory"
- );
-}
-
-static void put_pixels16_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
-{
- __asm __volatile(
- "lea (%3, %3), %%"REG_a" \n\t"
- ASMALIGN(3)
- "1: \n\t"
- "movq (%1), %%mm0 \n\t"
- "movq 8(%1), %%mm4 \n\t"
- "movq (%1, %3), %%mm1 \n\t"
- "movq 8(%1, %3), %%mm5 \n\t"
- "movq %%mm0, (%2) \n\t"
- "movq %%mm4, 8(%2) \n\t"
- "movq %%mm1, (%2, %3) \n\t"
- "movq %%mm5, 8(%2, %3) \n\t"
- "add %%"REG_a", %1 \n\t"
- "add %%"REG_a", %2 \n\t"
- "movq (%1), %%mm0 \n\t"
- "movq 8(%1), %%mm4 \n\t"
- "movq (%1, %3), %%mm1 \n\t"
- "movq 8(%1, %3), %%mm5 \n\t"
- "movq %%mm0, (%2) \n\t"
- "movq %%mm4, 8(%2) \n\t"
- "movq %%mm1, (%2, %3) \n\t"
- "movq %%mm5, 8(%2, %3) \n\t"
- "add %%"REG_a", %1 \n\t"
- "add %%"REG_a", %2 \n\t"
- "subl $4, %0 \n\t"
- "jnz 1b \n\t"
- : "+g"(h), "+r" (pixels), "+r" (block)
- : "r"((long)line_size)
- : "%"REG_a, "memory"
- );
-}
-
-static void clear_blocks_mmx(DCTELEM *blocks)
-{
- __asm __volatile(
- "pxor %%mm7, %%mm7 \n\t"
- "mov $-128*6, %%"REG_a" \n\t"
- "1: \n\t"
- "movq %%mm7, (%0, %%"REG_a") \n\t"
- "movq %%mm7, 8(%0, %%"REG_a") \n\t"
- "movq %%mm7, 16(%0, %%"REG_a") \n\t"
- "movq %%mm7, 24(%0, %%"REG_a") \n\t"
- "add $32, %%"REG_a" \n\t"
- " js 1b \n\t"
- : : "r" (((uint8_t *)blocks)+128*6)
- : "%"REG_a
- );
-}
-
-#ifdef CONFIG_ENCODERS
-static int pix_sum16_mmx(uint8_t * pix, int line_size){
- const int h=16;
- int sum;
- long index= -line_size*h;
-
- __asm __volatile(
- "pxor %%mm7, %%mm7 \n\t"
- "pxor %%mm6, %%mm6 \n\t"
- "1: \n\t"
- "movq (%2, %1), %%mm0 \n\t"
- "movq (%2, %1), %%mm1 \n\t"
- "movq 8(%2, %1), %%mm2 \n\t"
- "movq 8(%2, %1), %%mm3 \n\t"
- "punpcklbw %%mm7, %%mm0 \n\t"
- "punpckhbw %%mm7, %%mm1 \n\t"
- "punpcklbw %%mm7, %%mm2 \n\t"
- "punpckhbw %%mm7, %%mm3 \n\t"
- "paddw %%mm0, %%mm1 \n\t"
- "paddw %%mm2, %%mm3 \n\t"
- "paddw %%mm1, %%mm3 \n\t"
- "paddw %%mm3, %%mm6 \n\t"
- "add %3, %1 \n\t"
- " js 1b \n\t"
- "movq %%mm6, %%mm5 \n\t"
- "psrlq $32, %%mm6 \n\t"
- "paddw %%mm5, %%mm6 \n\t"
- "movq %%mm6, %%mm5 \n\t"
- "psrlq $16, %%mm6 \n\t"
- "paddw %%mm5, %%mm6 \n\t"
- "movd %%mm6, %0 \n\t"
- "andl $0xFFFF, %0 \n\t"
- : "=&r" (sum), "+r" (index)
- : "r" (pix - index), "r" ((long)line_size)
- );
-
- return sum;
-}
-#endif //CONFIG_ENCODERS
-
-static void add_bytes_mmx(uint8_t *dst, uint8_t *src, int w){
- long i=0;
- asm volatile(
- "1: \n\t"
- "movq (%1, %0), %%mm0 \n\t"
- "movq (%2, %0), %%mm1 \n\t"
- "paddb %%mm0, %%mm1 \n\t"
- "movq %%mm1, (%2, %0) \n\t"
- "movq 8(%1, %0), %%mm0 \n\t"
- "movq 8(%2, %0), %%mm1 \n\t"
- "paddb %%mm0, %%mm1 \n\t"
- "movq %%mm1, 8(%2, %0) \n\t"
- "add $16, %0 \n\t"
- "cmp %3, %0 \n\t"
- " jb 1b \n\t"
- : "+r" (i)
- : "r"(src), "r"(dst), "r"((long)w-15)
- );
- for(; i<w; i++)
- dst[i+0] += src[i+0];
-}
-
-#define H263_LOOP_FILTER \
- "pxor %%mm7, %%mm7 \n\t"\
- "movq %0, %%mm0 \n\t"\
- "movq %0, %%mm1 \n\t"\
- "movq %3, %%mm2 \n\t"\
- "movq %3, %%mm3 \n\t"\
- "punpcklbw %%mm7, %%mm0 \n\t"\
- "punpckhbw %%mm7, %%mm1 \n\t"\
- "punpcklbw %%mm7, %%mm2 \n\t"\
- "punpckhbw %%mm7, %%mm3 \n\t"\
- "psubw %%mm2, %%mm0 \n\t"\
- "psubw %%mm3, %%mm1 \n\t"\
- "movq %1, %%mm2 \n\t"\
- "movq %1, %%mm3 \n\t"\
- "movq %2, %%mm4 \n\t"\
- "movq %2, %%mm5 \n\t"\
- "punpcklbw %%mm7, %%mm2 \n\t"\
- "punpckhbw %%mm7, %%mm3 \n\t"\
- "punpcklbw %%mm7, %%mm4 \n\t"\
- "punpckhbw %%mm7, %%mm5 \n\t"\
- "psubw %%mm2, %%mm4 \n\t"\
- "psubw %%mm3, %%mm5 \n\t"\
- "psllw $2, %%mm4 \n\t"\
- "psllw $2, %%mm5 \n\t"\
- "paddw %%mm0, %%mm4 \n\t"\
- "paddw %%mm1, %%mm5 \n\t"\
- "pxor %%mm6, %%mm6 \n\t"\
- "pcmpgtw %%mm4, %%mm6 \n\t"\
- "pcmpgtw %%mm5, %%mm7 \n\t"\
- "pxor %%mm6, %%mm4 \n\t"\
- "pxor %%mm7, %%mm5 \n\t"\
- "psubw %%mm6, %%mm4 \n\t"\
- "psubw %%mm7, %%mm5 \n\t"\
- "psrlw $3, %%mm4 \n\t"\
- "psrlw $3, %%mm5 \n\t"\
- "packuswb %%mm5, %%mm4 \n\t"\
- "packsswb %%mm7, %%mm6 \n\t"\
- "pxor %%mm7, %%mm7 \n\t"\
- "movd %4, %%mm2 \n\t"\
- "punpcklbw %%mm2, %%mm2 \n\t"\
- "punpcklbw %%mm2, %%mm2 \n\t"\
- "punpcklbw %%mm2, %%mm2 \n\t"\
- "psubusb %%mm4, %%mm2 \n\t"\
- "movq %%mm2, %%mm3 \n\t"\
- "psubusb %%mm4, %%mm3 \n\t"\
- "psubb %%mm3, %%mm2 \n\t"\
- "movq %1, %%mm3 \n\t"\
- "movq %2, %%mm4 \n\t"\
- "pxor %%mm6, %%mm3 \n\t"\
- "pxor %%mm6, %%mm4 \n\t"\
- "paddusb %%mm2, %%mm3 \n\t"\
- "psubusb %%mm2, %%mm4 \n\t"\
- "pxor %%mm6, %%mm3 \n\t"\
- "pxor %%mm6, %%mm4 \n\t"\
- "paddusb %%mm2, %%mm2 \n\t"\
- "packsswb %%mm1, %%mm0 \n\t"\
- "pcmpgtb %%mm0, %%mm7 \n\t"\
- "pxor %%mm7, %%mm0 \n\t"\
- "psubb %%mm7, %%mm0 \n\t"\
- "movq %%mm0, %%mm1 \n\t"\
- "psubusb %%mm2, %%mm0 \n\t"\
- "psubb %%mm0, %%mm1 \n\t"\
- "pand %5, %%mm1 \n\t"\
- "psrlw $2, %%mm1 \n\t"\
- "pxor %%mm7, %%mm1 \n\t"\
- "psubb %%mm7, %%mm1 \n\t"\
- "movq %0, %%mm5 \n\t"\
- "movq %3, %%mm6 \n\t"\
- "psubb %%mm1, %%mm5 \n\t"\
- "paddb %%mm1, %%mm6 \n\t"
-
-static void h263_v_loop_filter_mmx(uint8_t *src, int stride, int qscale){
- const int strength= ff_h263_loop_filter_strength[qscale];
-
- asm volatile(
-
- H263_LOOP_FILTER
-
- "movq %%mm3, %1 \n\t"
- "movq %%mm4, %2 \n\t"
- "movq %%mm5, %0 \n\t"
- "movq %%mm6, %3 \n\t"
- : "+m" (*(uint64_t*)(src - 2*stride)),
- "+m" (*(uint64_t*)(src - 1*stride)),
- "+m" (*(uint64_t*)(src + 0*stride)),
- "+m" (*(uint64_t*)(src + 1*stride))
- : "g" (2*strength), "m"(ff_pb_FC)
- );
-}
-
-static inline void transpose4x4(uint8_t *dst, uint8_t *src, int dst_stride, int src_stride){
- asm volatile( //FIXME could save 1 instruction if done as 8x4 ...
- "movd %4, %%mm0 \n\t"
- "movd %5, %%mm1 \n\t"
- "movd %6, %%mm2 \n\t"
- "movd %7, %%mm3 \n\t"
- "punpcklbw %%mm1, %%mm0 \n\t"
- "punpcklbw %%mm3, %%mm2 \n\t"
- "movq %%mm0, %%mm1 \n\t"
- "punpcklwd %%mm2, %%mm0 \n\t"
- "punpckhwd %%mm2, %%mm1 \n\t"
- "movd %%mm0, %0 \n\t"
- "punpckhdq %%mm0, %%mm0 \n\t"
- "movd %%mm0, %1 \n\t"
- "movd %%mm1, %2 \n\t"
- "punpckhdq %%mm1, %%mm1 \n\t"
- "movd %%mm1, %3 \n\t"
-
- : "=m" (*(uint32_t*)(dst + 0*dst_stride)),
- "=m" (*(uint32_t*)(dst + 1*dst_stride)),
- "=m" (*(uint32_t*)(dst + 2*dst_stride)),
- "=m" (*(uint32_t*)(dst + 3*dst_stride))
- : "m" (*(uint32_t*)(src + 0*src_stride)),
- "m" (*(uint32_t*)(src + 1*src_stride)),
- "m" (*(uint32_t*)(src + 2*src_stride)),
- "m" (*(uint32_t*)(src + 3*src_stride))
- );
-}
-
-static void h263_h_loop_filter_mmx(uint8_t *src, int stride, int qscale){
- const int strength= ff_h263_loop_filter_strength[qscale];
- uint64_t temp[4] __attribute__ ((aligned(8)));
- uint8_t *btemp= (uint8_t*)temp;
-
- src -= 2;
-
- transpose4x4(btemp , src , 8, stride);
- transpose4x4(btemp+4, src + 4*stride, 8, stride);
- asm volatile(
- H263_LOOP_FILTER // 5 3 4 6
-
- : "+m" (temp[0]),
- "+m" (temp[1]),
- "+m" (temp[2]),
- "+m" (temp[3])
- : "g" (2*strength), "m"(ff_pb_FC)
- );
-
- asm volatile(
- "movq %%mm5, %%mm1 \n\t"
- "movq %%mm4, %%mm0 \n\t"
- "punpcklbw %%mm3, %%mm5 \n\t"
- "punpcklbw %%mm6, %%mm4 \n\t"
- "punpckhbw %%mm3, %%mm1 \n\t"
- "punpckhbw %%mm6, %%mm0 \n\t"
- "movq %%mm5, %%mm3 \n\t"
- "movq %%mm1, %%mm6 \n\t"
- "punpcklwd %%mm4, %%mm5 \n\t"
- "punpcklwd %%mm0, %%mm1 \n\t"
- "punpckhwd %%mm4, %%mm3 \n\t"
- "punpckhwd %%mm0, %%mm6 \n\t"
- "movd %%mm5, (%0) \n\t"
- "punpckhdq %%mm5, %%mm5 \n\t"
- "movd %%mm5, (%0,%2) \n\t"
- "movd %%mm3, (%0,%2,2) \n\t"
- "punpckhdq %%mm3, %%mm3 \n\t"
- "movd %%mm3, (%0,%3) \n\t"
- "movd %%mm1, (%1) \n\t"
- "punpckhdq %%mm1, %%mm1 \n\t"
- "movd %%mm1, (%1,%2) \n\t"
- "movd %%mm6, (%1,%2,2) \n\t"
- "punpckhdq %%mm6, %%mm6 \n\t"
- "movd %%mm6, (%1,%3) \n\t"
- :: "r" (src),
- "r" (src + 4*stride),
- "r" ((long) stride ),
- "r" ((long)(3*stride))
- );
-}
-
-#ifdef CONFIG_ENCODERS
-static int pix_norm1_mmx(uint8_t *pix, int line_size) {
- int tmp;
- asm volatile (
- "movl $16,%%ecx\n"
- "pxor %%mm0,%%mm0\n"
- "pxor %%mm7,%%mm7\n"
- "1:\n"
- "movq (%0),%%mm2\n" /* mm2 = pix[0-7] */
- "movq 8(%0),%%mm3\n" /* mm3 = pix[8-15] */
-
- "movq %%mm2,%%mm1\n" /* mm1 = mm2 = pix[0-7] */
-
- "punpckhbw %%mm0,%%mm1\n" /* mm1 = [pix4-7] */
- "punpcklbw %%mm0,%%mm2\n" /* mm2 = [pix0-3] */
-
- "movq %%mm3,%%mm4\n" /* mm4 = mm3 = pix[8-15] */
- "punpckhbw %%mm0,%%mm3\n" /* mm3 = [pix12-15] */
- "punpcklbw %%mm0,%%mm4\n" /* mm4 = [pix8-11] */
-
- "pmaddwd %%mm1,%%mm1\n" /* mm1 = (pix0^2+pix1^2,pix2^2+pix3^2) */
- "pmaddwd %%mm2,%%mm2\n" /* mm2 = (pix4^2+pix5^2,pix6^2+pix7^2) */
-
- "pmaddwd %%mm3,%%mm3\n"
- "pmaddwd %%mm4,%%mm4\n"
-
- "paddd %%mm1,%%mm2\n" /* mm2 = (pix0^2+pix1^2+pix4^2+pix5^2,
- pix2^2+pix3^2+pix6^2+pix7^2) */
- "paddd %%mm3,%%mm4\n"
- "paddd %%mm2,%%mm7\n"
-
- "add %2, %0\n"
- "paddd %%mm4,%%mm7\n"
- "dec %%ecx\n"
- "jnz 1b\n"
-
- "movq %%mm7,%%mm1\n"
- "psrlq $32, %%mm7\n" /* shift hi dword to lo */
- "paddd %%mm7,%%mm1\n"
- "movd %%mm1,%1\n"
- : "+r" (pix), "=r"(tmp) : "r" ((long)line_size) : "%ecx" );
- return tmp;
-}
-
-static int sse8_mmx(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
- int tmp;
- asm volatile (
- "movl %4,%%ecx\n"
- "shr $1,%%ecx\n"
- "pxor %%mm0,%%mm0\n" /* mm0 = 0 */
- "pxor %%mm7,%%mm7\n" /* mm7 holds the sum */
- "1:\n"
- "movq (%0),%%mm1\n" /* mm1 = pix1[0][0-7] */
- "movq (%1),%%mm2\n" /* mm2 = pix2[0][0-7] */
- "movq (%0,%3),%%mm3\n" /* mm3 = pix1[1][0-7] */
- "movq (%1,%3),%%mm4\n" /* mm4 = pix2[1][0-7] */
-
- /* todo: mm1-mm2, mm3-mm4 */
- /* algo: substract mm1 from mm2 with saturation and vice versa */
- /* OR the results to get absolute difference */
- "movq %%mm1,%%mm5\n"
- "movq %%mm3,%%mm6\n"
- "psubusb %%mm2,%%mm1\n"
- "psubusb %%mm4,%%mm3\n"
- "psubusb %%mm5,%%mm2\n"
- "psubusb %%mm6,%%mm4\n"
-
- "por %%mm1,%%mm2\n"
- "por %%mm3,%%mm4\n"
-
- /* now convert to 16-bit vectors so we can square them */
- "movq %%mm2,%%mm1\n"
- "movq %%mm4,%%mm3\n"
-
- "punpckhbw %%mm0,%%mm2\n"
- "punpckhbw %%mm0,%%mm4\n"
- "punpcklbw %%mm0,%%mm1\n" /* mm1 now spread over (mm1,mm2) */
- "punpcklbw %%mm0,%%mm3\n" /* mm4 now spread over (mm3,mm4) */
-
- "pmaddwd %%mm2,%%mm2\n"
- "pmaddwd %%mm4,%%mm4\n"
- "pmaddwd %%mm1,%%mm1\n"
- "pmaddwd %%mm3,%%mm3\n"
-
- "lea (%0,%3,2), %0\n" /* pix1 += 2*line_size */
- "lea (%1,%3,2), %1\n" /* pix2 += 2*line_size */
-
- "paddd %%mm2,%%mm1\n"
- "paddd %%mm4,%%mm3\n"
- "paddd %%mm1,%%mm7\n"
- "paddd %%mm3,%%mm7\n"
-
- "decl %%ecx\n"
- "jnz 1b\n"
-
- "movq %%mm7,%%mm1\n"
- "psrlq $32, %%mm7\n" /* shift hi dword to lo */
- "paddd %%mm7,%%mm1\n"
- "movd %%mm1,%2\n"
- : "+r" (pix1), "+r" (pix2), "=r"(tmp)
- : "r" ((long)line_size) , "m" (h)
- : "%ecx");
- return tmp;
-}
-
-static int sse16_mmx(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
- int tmp;
- asm volatile (
- "movl %4,%%ecx\n"
- "pxor %%mm0,%%mm0\n" /* mm0 = 0 */
- "pxor %%mm7,%%mm7\n" /* mm7 holds the sum */
- "1:\n"
- "movq (%0),%%mm1\n" /* mm1 = pix1[0-7] */
- "movq (%1),%%mm2\n" /* mm2 = pix2[0-7] */
- "movq 8(%0),%%mm3\n" /* mm3 = pix1[8-15] */
- "movq 8(%1),%%mm4\n" /* mm4 = pix2[8-15] */
-
- /* todo: mm1-mm2, mm3-mm4 */
- /* algo: substract mm1 from mm2 with saturation and vice versa */
- /* OR the results to get absolute difference */
- "movq %%mm1,%%mm5\n"
- "movq %%mm3,%%mm6\n"
- "psubusb %%mm2,%%mm1\n"
- "psubusb %%mm4,%%mm3\n"
- "psubusb %%mm5,%%mm2\n"
- "psubusb %%mm6,%%mm4\n"
-
- "por %%mm1,%%mm2\n"
- "por %%mm3,%%mm4\n"
-
- /* now convert to 16-bit vectors so we can square them */
- "movq %%mm2,%%mm1\n"
- "movq %%mm4,%%mm3\n"
-
- "punpckhbw %%mm0,%%mm2\n"
- "punpckhbw %%mm0,%%mm4\n"
- "punpcklbw %%mm0,%%mm1\n" /* mm1 now spread over (mm1,mm2) */
- "punpcklbw %%mm0,%%mm3\n" /* mm4 now spread over (mm3,mm4) */
-
- "pmaddwd %%mm2,%%mm2\n"
- "pmaddwd %%mm4,%%mm4\n"
- "pmaddwd %%mm1,%%mm1\n"
- "pmaddwd %%mm3,%%mm3\n"
-
- "add %3,%0\n"
- "add %3,%1\n"
-
- "paddd %%mm2,%%mm1\n"
- "paddd %%mm4,%%mm3\n"
- "paddd %%mm1,%%mm7\n"
- "paddd %%mm3,%%mm7\n"
-
- "decl %%ecx\n"
- "jnz 1b\n"
-
- "movq %%mm7,%%mm1\n"
- "psrlq $32, %%mm7\n" /* shift hi dword to lo */
- "paddd %%mm7,%%mm1\n"
- "movd %%mm1,%2\n"
- : "+r" (pix1), "+r" (pix2), "=r"(tmp)
- : "r" ((long)line_size) , "m" (h)
- : "%ecx");
- return tmp;
-}
-
-static int sse16_sse2(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
- int tmp;
- asm volatile (
- "shr $1,%2\n"
- "pxor %%xmm0,%%xmm0\n" /* mm0 = 0 */
- "pxor %%xmm7,%%xmm7\n" /* mm7 holds the sum */
- "1:\n"
- "movdqu (%0),%%xmm1\n" /* mm1 = pix1[0][0-15] */
- "movdqu (%1),%%xmm2\n" /* mm2 = pix2[0][0-15] */
- "movdqu (%0,%4),%%xmm3\n" /* mm3 = pix1[1][0-15] */
- "movdqu (%1,%4),%%xmm4\n" /* mm4 = pix2[1][0-15] */
-
- /* todo: mm1-mm2, mm3-mm4 */
- /* algo: substract mm1 from mm2 with saturation and vice versa */
- /* OR the results to get absolute difference */
- "movdqa %%xmm1,%%xmm5\n"
- "movdqa %%xmm3,%%xmm6\n"
- "psubusb %%xmm2,%%xmm1\n"
- "psubusb %%xmm4,%%xmm3\n"
- "psubusb %%xmm5,%%xmm2\n"
- "psubusb %%xmm6,%%xmm4\n"
-
- "por %%xmm1,%%xmm2\n"
- "por %%xmm3,%%xmm4\n"
-
- /* now convert to 16-bit vectors so we can square them */
- "movdqa %%xmm2,%%xmm1\n"
- "movdqa %%xmm4,%%xmm3\n"
-
- "punpckhbw %%xmm0,%%xmm2\n"
- "punpckhbw %%xmm0,%%xmm4\n"
- "punpcklbw %%xmm0,%%xmm1\n" /* mm1 now spread over (mm1,mm2) */
- "punpcklbw %%xmm0,%%xmm3\n" /* mm4 now spread over (mm3,mm4) */
-
- "pmaddwd %%xmm2,%%xmm2\n"
- "pmaddwd %%xmm4,%%xmm4\n"
- "pmaddwd %%xmm1,%%xmm1\n"
- "pmaddwd %%xmm3,%%xmm3\n"
-
- "lea (%0,%4,2), %0\n" /* pix1 += 2*line_size */
- "lea (%1,%4,2), %1\n" /* pix2 += 2*line_size */
-
- "paddd %%xmm2,%%xmm1\n"
- "paddd %%xmm4,%%xmm3\n"
- "paddd %%xmm1,%%xmm7\n"
- "paddd %%xmm3,%%xmm7\n"
-
- "decl %2\n"
- "jnz 1b\n"
-
- "movdqa %%xmm7,%%xmm1\n"
- "psrldq $8, %%xmm7\n" /* shift hi qword to lo */
- "paddd %%xmm1,%%xmm7\n"
- "movdqa %%xmm7,%%xmm1\n"
- "psrldq $4, %%xmm7\n" /* shift hi dword to lo */
- "paddd %%xmm1,%%xmm7\n"
- "movd %%xmm7,%3\n"
- : "+r" (pix1), "+r" (pix2), "+r"(h), "=r"(tmp)
- : "r" ((long)line_size));
- return tmp;
-}
-
-static int hf_noise8_mmx(uint8_t * pix1, int line_size, int h) {
- int tmp;
- asm volatile (
- "movl %3,%%ecx\n"
- "pxor %%mm7,%%mm7\n"
- "pxor %%mm6,%%mm6\n"
-
- "movq (%0),%%mm0\n"
- "movq %%mm0, %%mm1\n"
- "psllq $8, %%mm0\n"
- "psrlq $8, %%mm1\n"
- "psrlq $8, %%mm0\n"
- "movq %%mm0, %%mm2\n"
- "movq %%mm1, %%mm3\n"
- "punpcklbw %%mm7,%%mm0\n"
- "punpcklbw %%mm7,%%mm1\n"
- "punpckhbw %%mm7,%%mm2\n"
- "punpckhbw %%mm7,%%mm3\n"
- "psubw %%mm1, %%mm0\n"
- "psubw %%mm3, %%mm2\n"
-
- "add %2,%0\n"
-
- "movq (%0),%%mm4\n"
- "movq %%mm4, %%mm1\n"
- "psllq $8, %%mm4\n"
- "psrlq $8, %%mm1\n"
- "psrlq $8, %%mm4\n"
- "movq %%mm4, %%mm5\n"
- "movq %%mm1, %%mm3\n"
- "punpcklbw %%mm7,%%mm4\n"
- "punpcklbw %%mm7,%%mm1\n"
- "punpckhbw %%mm7,%%mm5\n"
- "punpckhbw %%mm7,%%mm3\n"
- "psubw %%mm1, %%mm4\n"
- "psubw %%mm3, %%mm5\n"
- "psubw %%mm4, %%mm0\n"
- "psubw %%mm5, %%mm2\n"
- "pxor %%mm3, %%mm3\n"
- "pxor %%mm1, %%mm1\n"
- "pcmpgtw %%mm0, %%mm3\n\t"
- "pcmpgtw %%mm2, %%mm1\n\t"
- "pxor %%mm3, %%mm0\n"
- "pxor %%mm1, %%mm2\n"
- "psubw %%mm3, %%mm0\n"
- "psubw %%mm1, %%mm2\n"
- "paddw %%mm0, %%mm2\n"
- "paddw %%mm2, %%mm6\n"
-
- "add %2,%0\n"
- "1:\n"
-
- "movq (%0),%%mm0\n"
- "movq %%mm0, %%mm1\n"
- "psllq $8, %%mm0\n"
- "psrlq $8, %%mm1\n"
- "psrlq $8, %%mm0\n"
- "movq %%mm0, %%mm2\n"
- "movq %%mm1, %%mm3\n"
- "punpcklbw %%mm7,%%mm0\n"
- "punpcklbw %%mm7,%%mm1\n"
- "punpckhbw %%mm7,%%mm2\n"
- "punpckhbw %%mm7,%%mm3\n"
- "psubw %%mm1, %%mm0\n"
- "psubw %%mm3, %%mm2\n"
- "psubw %%mm0, %%mm4\n"
- "psubw %%mm2, %%mm5\n"
- "pxor %%mm3, %%mm3\n"
- "pxor %%mm1, %%mm1\n"
- "pcmpgtw %%mm4, %%mm3\n\t"
- "pcmpgtw %%mm5, %%mm1\n\t"
- "pxor %%mm3, %%mm4\n"
- "pxor %%mm1, %%mm5\n"
- "psubw %%mm3, %%mm4\n"
- "psubw %%mm1, %%mm5\n"
- "paddw %%mm4, %%mm5\n"
- "paddw %%mm5, %%mm6\n"
-
- "add %2,%0\n"
-
- "movq (%0),%%mm4\n"
- "movq %%mm4, %%mm1\n"
- "psllq $8, %%mm4\n"
- "psrlq $8, %%mm1\n"
- "psrlq $8, %%mm4\n"
- "movq %%mm4, %%mm5\n"
- "movq %%mm1, %%mm3\n"
- "punpcklbw %%mm7,%%mm4\n"
- "punpcklbw %%mm7,%%mm1\n"
- "punpckhbw %%mm7,%%mm5\n"
- "punpckhbw %%mm7,%%mm3\n"
- "psubw %%mm1, %%mm4\n"
- "psubw %%mm3, %%mm5\n"
- "psubw %%mm4, %%mm0\n"
- "psubw %%mm5, %%mm2\n"
- "pxor %%mm3, %%mm3\n"
- "pxor %%mm1, %%mm1\n"
- "pcmpgtw %%mm0, %%mm3\n\t"
- "pcmpgtw %%mm2, %%mm1\n\t"
- "pxor %%mm3, %%mm0\n"
- "pxor %%mm1, %%mm2\n"
- "psubw %%mm3, %%mm0\n"
- "psubw %%mm1, %%mm2\n"
- "paddw %%mm0, %%mm2\n"
- "paddw %%mm2, %%mm6\n"
-
- "add %2,%0\n"
- "subl $2, %%ecx\n"
- " jnz 1b\n"
-
- "movq %%mm6, %%mm0\n"
- "punpcklwd %%mm7,%%mm0\n"
- "punpckhwd %%mm7,%%mm6\n"
- "paddd %%mm0, %%mm6\n"
-
- "movq %%mm6,%%mm0\n"
- "psrlq $32, %%mm6\n"
- "paddd %%mm6,%%mm0\n"
- "movd %%mm0,%1\n"
- : "+r" (pix1), "=r"(tmp)
- : "r" ((long)line_size) , "g" (h-2)
- : "%ecx");
- return tmp;
-}
-
-static int hf_noise16_mmx(uint8_t * pix1, int line_size, int h) {
- int tmp;
- uint8_t * pix= pix1;
- asm volatile (
- "movl %3,%%ecx\n"
- "pxor %%mm7,%%mm7\n"
- "pxor %%mm6,%%mm6\n"
-
- "movq (%0),%%mm0\n"
- "movq 1(%0),%%mm1\n"
- "movq %%mm0, %%mm2\n"
- "movq %%mm1, %%mm3\n"
- "punpcklbw %%mm7,%%mm0\n"
- "punpcklbw %%mm7,%%mm1\n"
- "punpckhbw %%mm7,%%mm2\n"
- "punpckhbw %%mm7,%%mm3\n"
- "psubw %%mm1, %%mm0\n"
- "psubw %%mm3, %%mm2\n"
-
- "add %2,%0\n"
-
- "movq (%0),%%mm4\n"
- "movq 1(%0),%%mm1\n"
- "movq %%mm4, %%mm5\n"
- "movq %%mm1, %%mm3\n"
- "punpcklbw %%mm7,%%mm4\n"
- "punpcklbw %%mm7,%%mm1\n"
- "punpckhbw %%mm7,%%mm5\n"
- "punpckhbw %%mm7,%%mm3\n"
- "psubw %%mm1, %%mm4\n"
- "psubw %%mm3, %%mm5\n"
- "psubw %%mm4, %%mm0\n"
- "psubw %%mm5, %%mm2\n"
- "pxor %%mm3, %%mm3\n"
- "pxor %%mm1, %%mm1\n"
- "pcmpgtw %%mm0, %%mm3\n\t"
- "pcmpgtw %%mm2, %%mm1\n\t"
- "pxor %%mm3, %%mm0\n"
- "pxor %%mm1, %%mm2\n"
- "psubw %%mm3, %%mm0\n"
- "psubw %%mm1, %%mm2\n"
- "paddw %%mm0, %%mm2\n"
- "paddw %%mm2, %%mm6\n"
-
- "add %2,%0\n"
- "1:\n"
-
- "movq (%0),%%mm0\n"
- "movq 1(%0),%%mm1\n"
- "movq %%mm0, %%mm2\n"
- "movq %%mm1, %%mm3\n"
- "punpcklbw %%mm7,%%mm0\n"
- "punpcklbw %%mm7,%%mm1\n"
- "punpckhbw %%mm7,%%mm2\n"
- "punpckhbw %%mm7,%%mm3\n"
- "psubw %%mm1, %%mm0\n"
- "psubw %%mm3, %%mm2\n"
- "psubw %%mm0, %%mm4\n"
- "psubw %%mm2, %%mm5\n"
- "pxor %%mm3, %%mm3\n"
- "pxor %%mm1, %%mm1\n"
- "pcmpgtw %%mm4, %%mm3\n\t"
- "pcmpgtw %%mm5, %%mm1\n\t"
- "pxor %%mm3, %%mm4\n"
- "pxor %%mm1, %%mm5\n"
- "psubw %%mm3, %%mm4\n"
- "psubw %%mm1, %%mm5\n"
- "paddw %%mm4, %%mm5\n"
- "paddw %%mm5, %%mm6\n"
-
- "add %2,%0\n"
-
- "movq (%0),%%mm4\n"
- "movq 1(%0),%%mm1\n"
- "movq %%mm4, %%mm5\n"
- "movq %%mm1, %%mm3\n"
- "punpcklbw %%mm7,%%mm4\n"
- "punpcklbw %%mm7,%%mm1\n"
- "punpckhbw %%mm7,%%mm5\n"
- "punpckhbw %%mm7,%%mm3\n"
- "psubw %%mm1, %%mm4\n"
- "psubw %%mm3, %%mm5\n"
- "psubw %%mm4, %%mm0\n"
- "psubw %%mm5, %%mm2\n"
- "pxor %%mm3, %%mm3\n"
- "pxor %%mm1, %%mm1\n"
- "pcmpgtw %%mm0, %%mm3\n\t"
- "pcmpgtw %%mm2, %%mm1\n\t"
- "pxor %%mm3, %%mm0\n"
- "pxor %%mm1, %%mm2\n"
- "psubw %%mm3, %%mm0\n"
- "psubw %%mm1, %%mm2\n"
- "paddw %%mm0, %%mm2\n"
- "paddw %%mm2, %%mm6\n"
-
- "add %2,%0\n"
- "subl $2, %%ecx\n"
- " jnz 1b\n"
-
- "movq %%mm6, %%mm0\n"
- "punpcklwd %%mm7,%%mm0\n"
- "punpckhwd %%mm7,%%mm6\n"
- "paddd %%mm0, %%mm6\n"
-
- "movq %%mm6,%%mm0\n"
- "psrlq $32, %%mm6\n"
- "paddd %%mm6,%%mm0\n"
- "movd %%mm0,%1\n"
- : "+r" (pix1), "=r"(tmp)
- : "r" ((long)line_size) , "g" (h-2)
- : "%ecx");
- return tmp + hf_noise8_mmx(pix+8, line_size, h);
-}
-
-static int nsse16_mmx(void *p, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
- MpegEncContext *c = p;
- int score1, score2;
-
- if(c) score1 = c->dsp.sse[0](c, pix1, pix2, line_size, h);
- else score1 = sse16_mmx(c, pix1, pix2, line_size, h);
- score2= hf_noise16_mmx(pix1, line_size, h) - hf_noise16_mmx(pix2, line_size, h);
-
- if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight;
- else return score1 + FFABS(score2)*8;
-}
-
-static int nsse8_mmx(void *p, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
- MpegEncContext *c = p;
- int score1= sse8_mmx(c, pix1, pix2, line_size, h);
- int score2= hf_noise8_mmx(pix1, line_size, h) - hf_noise8_mmx(pix2, line_size, h);
-
- if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight;
- else return score1 + FFABS(score2)*8;
-}
-
-static int vsad_intra16_mmx(void *v, uint8_t * pix, uint8_t * dummy, int line_size, int h) {
- int tmp;
-
- assert( (((int)pix) & 7) == 0);
- assert((line_size &7) ==0);
-
-#define SUM(in0, in1, out0, out1) \
- "movq (%0), %%mm2\n"\
- "movq 8(%0), %%mm3\n"\
- "add %2,%0\n"\
- "movq %%mm2, " #out0 "\n"\
- "movq %%mm3, " #out1 "\n"\
- "psubusb " #in0 ", %%mm2\n"\
- "psubusb " #in1 ", %%mm3\n"\
- "psubusb " #out0 ", " #in0 "\n"\
- "psubusb " #out1 ", " #in1 "\n"\
- "por %%mm2, " #in0 "\n"\
- "por %%mm3, " #in1 "\n"\
- "movq " #in0 ", %%mm2\n"\
- "movq " #in1 ", %%mm3\n"\
- "punpcklbw %%mm7, " #in0 "\n"\
- "punpcklbw %%mm7, " #in1 "\n"\
- "punpckhbw %%mm7, %%mm2\n"\
- "punpckhbw %%mm7, %%mm3\n"\
- "paddw " #in1 ", " #in0 "\n"\
- "paddw %%mm3, %%mm2\n"\
- "paddw %%mm2, " #in0 "\n"\
- "paddw " #in0 ", %%mm6\n"
-
-
- asm volatile (
- "movl %3,%%ecx\n"
- "pxor %%mm6,%%mm6\n"
- "pxor %%mm7,%%mm7\n"
- "movq (%0),%%mm0\n"
- "movq 8(%0),%%mm1\n"
- "add %2,%0\n"
- "subl $2, %%ecx\n"
- SUM(%%mm0, %%mm1, %%mm4, %%mm5)
- "1:\n"
-
- SUM(%%mm4, %%mm5, %%mm0, %%mm1)
-
- SUM(%%mm0, %%mm1, %%mm4, %%mm5)
-
- "subl $2, %%ecx\n"
- "jnz 1b\n"
-
- "movq %%mm6,%%mm0\n"
- "psrlq $32, %%mm6\n"
- "paddw %%mm6,%%mm0\n"
- "movq %%mm0,%%mm6\n"
- "psrlq $16, %%mm0\n"
- "paddw %%mm6,%%mm0\n"
- "movd %%mm0,%1\n"
- : "+r" (pix), "=r"(tmp)
- : "r" ((long)line_size) , "m" (h)
- : "%ecx");
- return tmp & 0xFFFF;
-}
-#undef SUM
-
-static int vsad_intra16_mmx2(void *v, uint8_t * pix, uint8_t * dummy, int line_size, int h) {
- int tmp;
-
- assert( (((int)pix) & 7) == 0);
- assert((line_size &7) ==0);
-
-#define SUM(in0, in1, out0, out1) \
- "movq (%0), " #out0 "\n"\
- "movq 8(%0), " #out1 "\n"\
- "add %2,%0\n"\
- "psadbw " #out0 ", " #in0 "\n"\
- "psadbw " #out1 ", " #in1 "\n"\
- "paddw " #in1 ", " #in0 "\n"\
- "paddw " #in0 ", %%mm6\n"
-
- asm volatile (
- "movl %3,%%ecx\n"
- "pxor %%mm6,%%mm6\n"
- "pxor %%mm7,%%mm7\n"
- "movq (%0),%%mm0\n"
- "movq 8(%0),%%mm1\n"
- "add %2,%0\n"
- "subl $2, %%ecx\n"
- SUM(%%mm0, %%mm1, %%mm4, %%mm5)
- "1:\n"
-
- SUM(%%mm4, %%mm5, %%mm0, %%mm1)
-
- SUM(%%mm0, %%mm1, %%mm4, %%mm5)
-
- "subl $2, %%ecx\n"
- "jnz 1b\n"
-
- "movd %%mm6,%1\n"
- : "+r" (pix), "=r"(tmp)
- : "r" ((long)line_size) , "m" (h)
- : "%ecx");
- return tmp;
-}
-#undef SUM
-
-static int vsad16_mmx(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
- int tmp;
-
- assert( (((int)pix1) & 7) == 0);
- assert( (((int)pix2) & 7) == 0);
- assert((line_size &7) ==0);
-
-#define SUM(in0, in1, out0, out1) \
- "movq (%0),%%mm2\n"\
- "movq (%1)," #out0 "\n"\
- "movq 8(%0),%%mm3\n"\
- "movq 8(%1)," #out1 "\n"\
- "add %3,%0\n"\
- "add %3,%1\n"\
- "psubb " #out0 ", %%mm2\n"\
- "psubb " #out1 ", %%mm3\n"\
- "pxor %%mm7, %%mm2\n"\
- "pxor %%mm7, %%mm3\n"\
- "movq %%mm2, " #out0 "\n"\
- "movq %%mm3, " #out1 "\n"\
- "psubusb " #in0 ", %%mm2\n"\
- "psubusb " #in1 ", %%mm3\n"\
- "psubusb " #out0 ", " #in0 "\n"\
- "psubusb " #out1 ", " #in1 "\n"\
- "por %%mm2, " #in0 "\n"\
- "por %%mm3, " #in1 "\n"\
- "movq " #in0 ", %%mm2\n"\
- "movq " #in1 ", %%mm3\n"\
- "punpcklbw %%mm7, " #in0 "\n"\
- "punpcklbw %%mm7, " #in1 "\n"\
- "punpckhbw %%mm7, %%mm2\n"\
- "punpckhbw %%mm7, %%mm3\n"\
- "paddw " #in1 ", " #in0 "\n"\
- "paddw %%mm3, %%mm2\n"\
- "paddw %%mm2, " #in0 "\n"\
- "paddw " #in0 ", %%mm6\n"
-
-
- asm volatile (
- "movl %4,%%ecx\n"
- "pxor %%mm6,%%mm6\n"
- "pcmpeqw %%mm7,%%mm7\n"
- "psllw $15, %%mm7\n"
- "packsswb %%mm7, %%mm7\n"
- "movq (%0),%%mm0\n"
- "movq (%1),%%mm2\n"
- "movq 8(%0),%%mm1\n"
- "movq 8(%1),%%mm3\n"
- "add %3,%0\n"
- "add %3,%1\n"
- "subl $2, %%ecx\n"
- "psubb %%mm2, %%mm0\n"
- "psubb %%mm3, %%mm1\n"
- "pxor %%mm7, %%mm0\n"
- "pxor %%mm7, %%mm1\n"
- SUM(%%mm0, %%mm1, %%mm4, %%mm5)
- "1:\n"
-
- SUM(%%mm4, %%mm5, %%mm0, %%mm1)
-
- SUM(%%mm0, %%mm1, %%mm4, %%mm5)
-
- "subl $2, %%ecx\n"
- "jnz 1b\n"
-
- "movq %%mm6,%%mm0\n"
- "psrlq $32, %%mm6\n"
- "paddw %%mm6,%%mm0\n"
- "movq %%mm0,%%mm6\n"
- "psrlq $16, %%mm0\n"
- "paddw %%mm6,%%mm0\n"
- "movd %%mm0,%2\n"
- : "+r" (pix1), "+r" (pix2), "=r"(tmp)
- : "r" ((long)line_size) , "m" (h)
- : "%ecx");
- return tmp & 0x7FFF;
-}
-#undef SUM
-
-static int vsad16_mmx2(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
- int tmp;
-
- assert( (((int)pix1) & 7) == 0);
- assert( (((int)pix2) & 7) == 0);
- assert((line_size &7) ==0);
-
-#define SUM(in0, in1, out0, out1) \
- "movq (%0)," #out0 "\n"\
- "movq (%1),%%mm2\n"\
- "movq 8(%0)," #out1 "\n"\
- "movq 8(%1),%%mm3\n"\
- "add %3,%0\n"\
- "add %3,%1\n"\
- "psubb %%mm2, " #out0 "\n"\
- "psubb %%mm3, " #out1 "\n"\
- "pxor %%mm7, " #out0 "\n"\
- "pxor %%mm7, " #out1 "\n"\
- "psadbw " #out0 ", " #in0 "\n"\
- "psadbw " #out1 ", " #in1 "\n"\
- "paddw " #in1 ", " #in0 "\n"\
- "paddw " #in0 ", %%mm6\n"
-
- asm volatile (
- "movl %4,%%ecx\n"
- "pxor %%mm6,%%mm6\n"
- "pcmpeqw %%mm7,%%mm7\n"
- "psllw $15, %%mm7\n"
- "packsswb %%mm7, %%mm7\n"
- "movq (%0),%%mm0\n"
- "movq (%1),%%mm2\n"
- "movq 8(%0),%%mm1\n"
- "movq 8(%1),%%mm3\n"
- "add %3,%0\n"
- "add %3,%1\n"
- "subl $2, %%ecx\n"
- "psubb %%mm2, %%mm0\n"
- "psubb %%mm3, %%mm1\n"
- "pxor %%mm7, %%mm0\n"
- "pxor %%mm7, %%mm1\n"
- SUM(%%mm0, %%mm1, %%mm4, %%mm5)
- "1:\n"
-
- SUM(%%mm4, %%mm5, %%mm0, %%mm1)
-
- SUM(%%mm0, %%mm1, %%mm4, %%mm5)
-
- "subl $2, %%ecx\n"
- "jnz 1b\n"
-
- "movd %%mm6,%2\n"
- : "+r" (pix1), "+r" (pix2), "=r"(tmp)
- : "r" ((long)line_size) , "m" (h)
- : "%ecx");
- return tmp;
-}
-#undef SUM
-
-static void diff_bytes_mmx(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
- long i=0;
- asm volatile(
- "1: \n\t"
- "movq (%2, %0), %%mm0 \n\t"
- "movq (%1, %0), %%mm1 \n\t"
- "psubb %%mm0, %%mm1 \n\t"
- "movq %%mm1, (%3, %0) \n\t"
- "movq 8(%2, %0), %%mm0 \n\t"
- "movq 8(%1, %0), %%mm1 \n\t"
- "psubb %%mm0, %%mm1 \n\t"
- "movq %%mm1, 8(%3, %0) \n\t"
- "add $16, %0 \n\t"
- "cmp %4, %0 \n\t"
- " jb 1b \n\t"
- : "+r" (i)
- : "r"(src1), "r"(src2), "r"(dst), "r"((long)w-15)
- );
- for(; i<w; i++)
- 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){
- long i=0;
- uint8_t l, lt;
-
- asm volatile(
- "1: \n\t"
- "movq -1(%1, %0), %%mm0 \n\t" // LT
- "movq (%1, %0), %%mm1 \n\t" // T
- "movq -1(%2, %0), %%mm2 \n\t" // L
- "movq (%2, %0), %%mm3 \n\t" // X
- "movq %%mm2, %%mm4 \n\t" // L
- "psubb %%mm0, %%mm2 \n\t"
- "paddb %%mm1, %%mm2 \n\t" // L + T - LT
- "movq %%mm4, %%mm5 \n\t" // L
- "pmaxub %%mm1, %%mm4 \n\t" // max(T, L)
- "pminub %%mm5, %%mm1 \n\t" // min(T, L)
- "pminub %%mm2, %%mm4 \n\t"
- "pmaxub %%mm1, %%mm4 \n\t"
- "psubb %%mm4, %%mm3 \n\t" // dst - pred
- "movq %%mm3, (%3, %0) \n\t"
- "add $8, %0 \n\t"
- "cmp %4, %0 \n\t"
- " jb 1b \n\t"
- : "+r" (i)
- : "r"(src1), "r"(src2), "r"(dst), "r"((long)w)
- );
-
- l= *left;
- lt= *left_top;
-
- dst[0]= src2[0] - mid_pred(l, src1[0], (l + src1[0] - lt)&0xFF);
-
- *left_top= src1[w-1];
- *left = src2[w-1];
-}
-
-#define LBUTTERFLY2(a1,b1,a2,b2)\
- "paddw " #b1 ", " #a1 " \n\t"\
- "paddw " #b2 ", " #a2 " \n\t"\
- "paddw " #b1 ", " #b1 " \n\t"\
- "paddw " #b2 ", " #b2 " \n\t"\
- "psubw " #a1 ", " #b1 " \n\t"\
- "psubw " #a2 ", " #b2 " \n\t"
-
-#define HADAMARD48\
- LBUTTERFLY2(%%mm0, %%mm1, %%mm2, %%mm3)\
- LBUTTERFLY2(%%mm4, %%mm5, %%mm6, %%mm7)\
- LBUTTERFLY2(%%mm0, %%mm2, %%mm1, %%mm3)\
- LBUTTERFLY2(%%mm4, %%mm6, %%mm5, %%mm7)\
- LBUTTERFLY2(%%mm0, %%mm4, %%mm1, %%mm5)\
- LBUTTERFLY2(%%mm2, %%mm6, %%mm3, %%mm7)\
-
-#define MMABS(a,z)\
- "pxor " #z ", " #z " \n\t"\
- "pcmpgtw " #a ", " #z " \n\t"\
- "pxor " #z ", " #a " \n\t"\
- "psubw " #z ", " #a " \n\t"
-
-#define MMABS_SUM(a,z, sum)\
- "pxor " #z ", " #z " \n\t"\
- "pcmpgtw " #a ", " #z " \n\t"\
- "pxor " #z ", " #a " \n\t"\
- "psubw " #z ", " #a " \n\t"\
- "paddusw " #a ", " #sum " \n\t"
-
-#define MMABS_MMX2(a,z)\
- "pxor " #z ", " #z " \n\t"\
- "psubw " #a ", " #z " \n\t"\
- "pmaxsw " #z ", " #a " \n\t"
-
-#define MMABS_SUM_MMX2(a,z, sum)\
- "pxor " #z ", " #z " \n\t"\
- "psubw " #a ", " #z " \n\t"\
- "pmaxsw " #z ", " #a " \n\t"\
- "paddusw " #a ", " #sum " \n\t"
-
-#define TRANSPOSE4(a,b,c,d,t)\
- SBUTTERFLY(a,b,t,wd) /* a=aebf t=cgdh */\
- SBUTTERFLY(c,d,b,wd) /* c=imjn b=kolp */\
- SBUTTERFLY(a,c,d,dq) /* a=aeim d=bfjn */\
- SBUTTERFLY(t,b,c,dq) /* t=cgko c=dhlp */
-
-#define LOAD4(o, a, b, c, d)\
- "movq "#o"(%1), " #a " \n\t"\
- "movq "#o"+16(%1), " #b " \n\t"\
- "movq "#o"+32(%1), " #c " \n\t"\
- "movq "#o"+48(%1), " #d " \n\t"
-
-#define STORE4(o, a, b, c, d)\
- "movq "#a", "#o"(%1) \n\t"\
- "movq "#b", "#o"+16(%1) \n\t"\
- "movq "#c", "#o"+32(%1) \n\t"\
- "movq "#d", "#o"+48(%1) \n\t"\
-
-static int hadamard8_diff_mmx(void *s, uint8_t *src1, uint8_t *src2, int stride, int h){
- DECLARE_ALIGNED_8(uint64_t, temp[16]);
- int sum=0;
-
- assert(h==8);
-
- diff_pixels_mmx((DCTELEM*)temp, src1, src2, stride);
-
- asm volatile(
- LOAD4(0 , %%mm0, %%mm1, %%mm2, %%mm3)
- LOAD4(64, %%mm4, %%mm5, %%mm6, %%mm7)
-
- HADAMARD48
-
- "movq %%mm7, 112(%1) \n\t"
-
- TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm7)
- STORE4(0 , %%mm0, %%mm3, %%mm7, %%mm2)
-
- "movq 112(%1), %%mm7 \n\t"
- TRANSPOSE4(%%mm4, %%mm5, %%mm6, %%mm7, %%mm0)
- STORE4(64, %%mm4, %%mm7, %%mm0, %%mm6)
-
- LOAD4(8 , %%mm0, %%mm1, %%mm2, %%mm3)
- LOAD4(72, %%mm4, %%mm5, %%mm6, %%mm7)
-
- HADAMARD48
-
- "movq %%mm7, 120(%1) \n\t"
-
- TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm7)
- STORE4(8 , %%mm0, %%mm3, %%mm7, %%mm2)
-
- "movq 120(%1), %%mm7 \n\t"
- TRANSPOSE4(%%mm4, %%mm5, %%mm6, %%mm7, %%mm0)
- "movq %%mm7, %%mm5 \n\t"//FIXME remove
- "movq %%mm6, %%mm7 \n\t"
- "movq %%mm0, %%mm6 \n\t"
-// STORE4(72, %%mm4, %%mm7, %%mm0, %%mm6) //FIXME remove
-
- LOAD4(64, %%mm0, %%mm1, %%mm2, %%mm3)
-// LOAD4(72, %%mm4, %%mm5, %%mm6, %%mm7)
-
- HADAMARD48
- "movq %%mm7, 64(%1) \n\t"
- MMABS(%%mm0, %%mm7)
- MMABS_SUM(%%mm1, %%mm7, %%mm0)
- MMABS_SUM(%%mm2, %%mm7, %%mm0)
- MMABS_SUM(%%mm3, %%mm7, %%mm0)
- MMABS_SUM(%%mm4, %%mm7, %%mm0)
- MMABS_SUM(%%mm5, %%mm7, %%mm0)
- MMABS_SUM(%%mm6, %%mm7, %%mm0)
- "movq 64(%1), %%mm1 \n\t"
- MMABS_SUM(%%mm1, %%mm7, %%mm0)
- "movq %%mm0, 64(%1) \n\t"
-
- LOAD4(0 , %%mm0, %%mm1, %%mm2, %%mm3)
- LOAD4(8 , %%mm4, %%mm5, %%mm6, %%mm7)
-
- HADAMARD48
- "movq %%mm7, (%1) \n\t"
- MMABS(%%mm0, %%mm7)
- MMABS_SUM(%%mm1, %%mm7, %%mm0)
- MMABS_SUM(%%mm2, %%mm7, %%mm0)
- MMABS_SUM(%%mm3, %%mm7, %%mm0)
- MMABS_SUM(%%mm4, %%mm7, %%mm0)
- MMABS_SUM(%%mm5, %%mm7, %%mm0)
- MMABS_SUM(%%mm6, %%mm7, %%mm0)
- "movq (%1), %%mm1 \n\t"
- MMABS_SUM(%%mm1, %%mm7, %%mm0)
- "movq 64(%1), %%mm1 \n\t"
- MMABS_SUM(%%mm1, %%mm7, %%mm0)
-
- "movq %%mm0, %%mm1 \n\t"
- "psrlq $32, %%mm0 \n\t"
- "paddusw %%mm1, %%mm0 \n\t"
- "movq %%mm0, %%mm1 \n\t"
- "psrlq $16, %%mm0 \n\t"
- "paddusw %%mm1, %%mm0 \n\t"
- "movd %%mm0, %0 \n\t"
-
- : "=r" (sum)
- : "r"(temp)
- );
- return sum&0xFFFF;
-}
-
-static int hadamard8_diff_mmx2(void *s, uint8_t *src1, uint8_t *src2, int stride, int h){
- DECLARE_ALIGNED_8(uint64_t, temp[16]);
- int sum=0;
-
- assert(h==8);
-
- diff_pixels_mmx((DCTELEM*)temp, src1, src2, stride);
-
- asm volatile(
- LOAD4(0 , %%mm0, %%mm1, %%mm2, %%mm3)
- LOAD4(64, %%mm4, %%mm5, %%mm6, %%mm7)
-
- HADAMARD48
-
- "movq %%mm7, 112(%1) \n\t"
-
- TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm7)
- STORE4(0 , %%mm0, %%mm3, %%mm7, %%mm2)
-
- "movq 112(%1), %%mm7 \n\t"
- TRANSPOSE4(%%mm4, %%mm5, %%mm6, %%mm7, %%mm0)
- STORE4(64, %%mm4, %%mm7, %%mm0, %%mm6)
-
- LOAD4(8 , %%mm0, %%mm1, %%mm2, %%mm3)
- LOAD4(72, %%mm4, %%mm5, %%mm6, %%mm7)
-
- HADAMARD48
-
- "movq %%mm7, 120(%1) \n\t"
-
- TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm7)
- STORE4(8 , %%mm0, %%mm3, %%mm7, %%mm2)
-
- "movq 120(%1), %%mm7 \n\t"
- TRANSPOSE4(%%mm4, %%mm5, %%mm6, %%mm7, %%mm0)
- "movq %%mm7, %%mm5 \n\t"//FIXME remove
- "movq %%mm6, %%mm7 \n\t"
- "movq %%mm0, %%mm6 \n\t"
-// STORE4(72, %%mm4, %%mm7, %%mm0, %%mm6) //FIXME remove
-
- LOAD4(64, %%mm0, %%mm1, %%mm2, %%mm3)
-// LOAD4(72, %%mm4, %%mm5, %%mm6, %%mm7)
-
- HADAMARD48
- "movq %%mm7, 64(%1) \n\t"
- MMABS_MMX2(%%mm0, %%mm7)
- MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
- MMABS_SUM_MMX2(%%mm2, %%mm7, %%mm0)
- MMABS_SUM_MMX2(%%mm3, %%mm7, %%mm0)
- MMABS_SUM_MMX2(%%mm4, %%mm7, %%mm0)
- MMABS_SUM_MMX2(%%mm5, %%mm7, %%mm0)
- MMABS_SUM_MMX2(%%mm6, %%mm7, %%mm0)
- "movq 64(%1), %%mm1 \n\t"
- MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
- "movq %%mm0, 64(%1) \n\t"
-
- LOAD4(0 , %%mm0, %%mm1, %%mm2, %%mm3)
- LOAD4(8 , %%mm4, %%mm5, %%mm6, %%mm7)
-
- HADAMARD48
- "movq %%mm7, (%1) \n\t"
- MMABS_MMX2(%%mm0, %%mm7)
- MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
- MMABS_SUM_MMX2(%%mm2, %%mm7, %%mm0)
- MMABS_SUM_MMX2(%%mm3, %%mm7, %%mm0)
- MMABS_SUM_MMX2(%%mm4, %%mm7, %%mm0)
- MMABS_SUM_MMX2(%%mm5, %%mm7, %%mm0)
- MMABS_SUM_MMX2(%%mm6, %%mm7, %%mm0)
- "movq (%1), %%mm1 \n\t"
- MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
- "movq 64(%1), %%mm1 \n\t"
- MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
-
- "pshufw $0x0E, %%mm0, %%mm1 \n\t"
- "paddusw %%mm1, %%mm0 \n\t"
- "pshufw $0x01, %%mm0, %%mm1 \n\t"
- "paddusw %%mm1, %%mm0 \n\t"
- "movd %%mm0, %0 \n\t"
-
- : "=r" (sum)
- : "r"(temp)
- );
- return sum&0xFFFF;
-}
-
-
-WARPER8_16_SQ(hadamard8_diff_mmx, hadamard8_diff16_mmx)
-WARPER8_16_SQ(hadamard8_diff_mmx2, hadamard8_diff16_mmx2)
-#endif //CONFIG_ENCODERS
-
-#define put_no_rnd_pixels8_mmx(a,b,c,d) put_pixels8_mmx(a,b,c,d)
-#define put_no_rnd_pixels16_mmx(a,b,c,d) put_pixels16_mmx(a,b,c,d)
-
-#define QPEL_V_LOW(m3,m4,m5,m6, pw_20, pw_3, rnd, in0, in1, in2, in7, out, OP)\
- "paddw " #m4 ", " #m3 " \n\t" /* x1 */\
- "movq "MANGLE(ff_pw_20)", %%mm4 \n\t" /* 20 */\
- "pmullw " #m3 ", %%mm4 \n\t" /* 20x1 */\
- "movq "#in7", " #m3 " \n\t" /* d */\
- "movq "#in0", %%mm5 \n\t" /* D */\
- "paddw " #m3 ", %%mm5 \n\t" /* x4 */\
- "psubw %%mm5, %%mm4 \n\t" /* 20x1 - x4 */\
- "movq "#in1", %%mm5 \n\t" /* C */\
- "movq "#in2", %%mm6 \n\t" /* B */\
- "paddw " #m6 ", %%mm5 \n\t" /* x3 */\
- "paddw " #m5 ", %%mm6 \n\t" /* x2 */\
- "paddw %%mm6, %%mm6 \n\t" /* 2x2 */\
- "psubw %%mm6, %%mm5 \n\t" /* -2x2 + x3 */\
- "pmullw "MANGLE(ff_pw_3)", %%mm5 \n\t" /* -6x2 + 3x3 */\
- "paddw " #rnd ", %%mm4 \n\t" /* x2 */\
- "paddw %%mm4, %%mm5 \n\t" /* 20x1 - 6x2 + 3x3 - x4 */\
- "psraw $5, %%mm5 \n\t"\
- "packuswb %%mm5, %%mm5 \n\t"\
- OP(%%mm5, out, %%mm7, d)
-
-#define QPEL_BASE(OPNAME, ROUNDER, RND, OP_MMX2, OP_3DNOW)\
-static void OPNAME ## mpeg4_qpel16_h_lowpass_mmx2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
- uint64_t temp;\
-\
- asm volatile(\
- "pxor %%mm7, %%mm7 \n\t"\
- "1: \n\t"\
- "movq (%0), %%mm0 \n\t" /* ABCDEFGH */\
- "movq %%mm0, %%mm1 \n\t" /* ABCDEFGH */\
- "movq %%mm0, %%mm2 \n\t" /* ABCDEFGH */\
- "punpcklbw %%mm7, %%mm0 \n\t" /* 0A0B0C0D */\
- "punpckhbw %%mm7, %%mm1 \n\t" /* 0E0F0G0H */\
- "pshufw $0x90, %%mm0, %%mm5 \n\t" /* 0A0A0B0C */\
- "pshufw $0x41, %%mm0, %%mm6 \n\t" /* 0B0A0A0B */\
- "movq %%mm2, %%mm3 \n\t" /* ABCDEFGH */\
- "movq %%mm2, %%mm4 \n\t" /* ABCDEFGH */\
- "psllq $8, %%mm2 \n\t" /* 0ABCDEFG */\
- "psllq $16, %%mm3 \n\t" /* 00ABCDEF */\
- "psllq $24, %%mm4 \n\t" /* 000ABCDE */\
- "punpckhbw %%mm7, %%mm2 \n\t" /* 0D0E0F0G */\
- "punpckhbw %%mm7, %%mm3 \n\t" /* 0C0D0E0F */\
- "punpckhbw %%mm7, %%mm4 \n\t" /* 0B0C0D0E */\
- "paddw %%mm3, %%mm5 \n\t" /* b */\
- "paddw %%mm2, %%mm6 \n\t" /* c */\
- "paddw %%mm5, %%mm5 \n\t" /* 2b */\
- "psubw %%mm5, %%mm6 \n\t" /* c - 2b */\
- "pshufw $0x06, %%mm0, %%mm5 \n\t" /* 0C0B0A0A */\
- "pmullw "MANGLE(ff_pw_3)", %%mm6 \n\t" /* 3c - 6b */\
- "paddw %%mm4, %%mm0 \n\t" /* a */\
- "paddw %%mm1, %%mm5 \n\t" /* d */\
- "pmullw "MANGLE(ff_pw_20)", %%mm0 \n\t" /* 20a */\
- "psubw %%mm5, %%mm0 \n\t" /* 20a - d */\
- "paddw %6, %%mm6 \n\t"\
- "paddw %%mm6, %%mm0 \n\t" /* 20a - 6b + 3c - d */\
- "psraw $5, %%mm0 \n\t"\
- "movq %%mm0, %5 \n\t"\
- /* mm1=EFGH, mm2=DEFG, mm3=CDEF, mm4=BCDE, mm7=0 */\
- \
- "movq 5(%0), %%mm0 \n\t" /* FGHIJKLM */\
- "movq %%mm0, %%mm5 \n\t" /* FGHIJKLM */\
- "movq %%mm0, %%mm6 \n\t" /* FGHIJKLM */\
- "psrlq $8, %%mm0 \n\t" /* GHIJKLM0 */\
- "psrlq $16, %%mm5 \n\t" /* HIJKLM00 */\
- "punpcklbw %%mm7, %%mm0 \n\t" /* 0G0H0I0J */\
- "punpcklbw %%mm7, %%mm5 \n\t" /* 0H0I0J0K */\
- "paddw %%mm0, %%mm2 \n\t" /* b */\
- "paddw %%mm5, %%mm3 \n\t" /* c */\
- "paddw %%mm2, %%mm2 \n\t" /* 2b */\
- "psubw %%mm2, %%mm3 \n\t" /* c - 2b */\
- "movq %%mm6, %%mm2 \n\t" /* FGHIJKLM */\
- "psrlq $24, %%mm6 \n\t" /* IJKLM000 */\
- "punpcklbw %%mm7, %%mm2 \n\t" /* 0F0G0H0I */\
- "punpcklbw %%mm7, %%mm6 \n\t" /* 0I0J0K0L */\
- "pmullw "MANGLE(ff_pw_3)", %%mm3 \n\t" /* 3c - 6b */\
- "paddw %%mm2, %%mm1 \n\t" /* a */\
- "paddw %%mm6, %%mm4 \n\t" /* d */\
- "pmullw "MANGLE(ff_pw_20)", %%mm1 \n\t" /* 20a */\
- "psubw %%mm4, %%mm3 \n\t" /* - 6b +3c - d */\
- "paddw %6, %%mm1 \n\t"\
- "paddw %%mm1, %%mm3 \n\t" /* 20a - 6b +3c - d */\
- "psraw $5, %%mm3 \n\t"\
- "movq %5, %%mm1 \n\t"\
- "packuswb %%mm3, %%mm1 \n\t"\
- OP_MMX2(%%mm1, (%1),%%mm4, q)\
- /* mm0= GHIJ, mm2=FGHI, mm5=HIJK, mm6=IJKL, mm7=0 */\
- \
- "movq 9(%0), %%mm1 \n\t" /* JKLMNOPQ */\
- "movq %%mm1, %%mm4 \n\t" /* JKLMNOPQ */\
- "movq %%mm1, %%mm3 \n\t" /* JKLMNOPQ */\
- "psrlq $8, %%mm1 \n\t" /* KLMNOPQ0 */\
- "psrlq $16, %%mm4 \n\t" /* LMNOPQ00 */\
- "punpcklbw %%mm7, %%mm1 \n\t" /* 0K0L0M0N */\
- "punpcklbw %%mm7, %%mm4 \n\t" /* 0L0M0N0O */\
- "paddw %%mm1, %%mm5 \n\t" /* b */\
- "paddw %%mm4, %%mm0 \n\t" /* c */\
- "paddw %%mm5, %%mm5 \n\t" /* 2b */\
- "psubw %%mm5, %%mm0 \n\t" /* c - 2b */\
- "movq %%mm3, %%mm5 \n\t" /* JKLMNOPQ */\
- "psrlq $24, %%mm3 \n\t" /* MNOPQ000 */\
- "pmullw "MANGLE(ff_pw_3)", %%mm0 \n\t" /* 3c - 6b */\
- "punpcklbw %%mm7, %%mm3 \n\t" /* 0M0N0O0P */\
- "paddw %%mm3, %%mm2 \n\t" /* d */\
- "psubw %%mm2, %%mm0 \n\t" /* -6b + 3c - d */\
- "movq %%mm5, %%mm2 \n\t" /* JKLMNOPQ */\
- "punpcklbw %%mm7, %%mm2 \n\t" /* 0J0K0L0M */\
- "punpckhbw %%mm7, %%mm5 \n\t" /* 0N0O0P0Q */\
- "paddw %%mm2, %%mm6 \n\t" /* a */\
- "pmullw "MANGLE(ff_pw_20)", %%mm6 \n\t" /* 20a */\
- "paddw %6, %%mm0 \n\t"\
- "paddw %%mm6, %%mm0 \n\t" /* 20a - 6b + 3c - d */\
- "psraw $5, %%mm0 \n\t"\
- /* mm1=KLMN, mm2=JKLM, mm3=MNOP, mm4=LMNO, mm5=NOPQ mm7=0 */\
- \
- "paddw %%mm5, %%mm3 \n\t" /* a */\
- "pshufw $0xF9, %%mm5, %%mm6 \n\t" /* 0O0P0Q0Q */\
- "paddw %%mm4, %%mm6 \n\t" /* b */\
- "pshufw $0xBE, %%mm5, %%mm4 \n\t" /* 0P0Q0Q0P */\
- "pshufw $0x6F, %%mm5, %%mm5 \n\t" /* 0Q0Q0P0O */\
- "paddw %%mm1, %%mm4 \n\t" /* c */\
- "paddw %%mm2, %%mm5 \n\t" /* d */\
- "paddw %%mm6, %%mm6 \n\t" /* 2b */\
- "psubw %%mm6, %%mm4 \n\t" /* c - 2b */\
- "pmullw "MANGLE(ff_pw_20)", %%mm3 \n\t" /* 20a */\
- "pmullw "MANGLE(ff_pw_3)", %%mm4 \n\t" /* 3c - 6b */\
- "psubw %%mm5, %%mm3 \n\t" /* -6b + 3c - d */\
- "paddw %6, %%mm4 \n\t"\
- "paddw %%mm3, %%mm4 \n\t" /* 20a - 6b + 3c - d */\
- "psraw $5, %%mm4 \n\t"\
- "packuswb %%mm4, %%mm0 \n\t"\
- OP_MMX2(%%mm0, 8(%1), %%mm4, q)\
- \
- "add %3, %0 \n\t"\
- "add %4, %1 \n\t"\
- "decl %2 \n\t"\
- " jnz 1b \n\t"\
- : "+a"(src), "+c"(dst), "+m"(h)\
- : "d"((long)srcStride), "S"((long)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(temp), "m"(ROUNDER)\
- : "memory"\
- );\
-}\
-\
-static void OPNAME ## mpeg4_qpel16_h_lowpass_3dnow(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
- int i;\
- int16_t temp[16];\
- /* quick HACK, XXX FIXME MUST be optimized */\
- for(i=0; i<h; i++)\
- {\
- temp[ 0]= (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]);\
- temp[ 1]= (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]);\
- temp[ 2]= (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]);\
- temp[ 3]= (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]);\
- temp[ 4]= (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]);\
- temp[ 5]= (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]);\
- temp[ 6]= (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]);\
- temp[ 7]= (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]);\
- temp[ 8]= (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]);\
- temp[ 9]= (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]);\
- temp[10]= (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]);\
- temp[11]= (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]);\
- temp[12]= (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]);\
- temp[13]= (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]);\
- temp[14]= (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]);\
- temp[15]= (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]);\
- asm volatile(\
- "movq (%0), %%mm0 \n\t"\
- "movq 8(%0), %%mm1 \n\t"\
- "paddw %2, %%mm0 \n\t"\
- "paddw %2, %%mm1 \n\t"\
- "psraw $5, %%mm0 \n\t"\
- "psraw $5, %%mm1 \n\t"\
- "packuswb %%mm1, %%mm0 \n\t"\
- OP_3DNOW(%%mm0, (%1), %%mm1, q)\
- "movq 16(%0), %%mm0 \n\t"\
- "movq 24(%0), %%mm1 \n\t"\
- "paddw %2, %%mm0 \n\t"\
- "paddw %2, %%mm1 \n\t"\
- "psraw $5, %%mm0 \n\t"\
- "psraw $5, %%mm1 \n\t"\
- "packuswb %%mm1, %%mm0 \n\t"\
- OP_3DNOW(%%mm0, 8(%1), %%mm1, q)\
- :: "r"(temp), "r"(dst), "m"(ROUNDER)\
- : "memory"\
- );\
- dst+=dstStride;\
- src+=srcStride;\
- }\
-}\
-\
-static void OPNAME ## mpeg4_qpel8_h_lowpass_mmx2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
- uint64_t temp;\
-\
- asm volatile(\
- "pxor %%mm7, %%mm7 \n\t"\
- "1: \n\t"\
- "movq (%0), %%mm0 \n\t" /* ABCDEFGH */\
- "movq %%mm0, %%mm1 \n\t" /* ABCDEFGH */\
- "movq %%mm0, %%mm2 \n\t" /* ABCDEFGH */\
- "punpcklbw %%mm7, %%mm0 \n\t" /* 0A0B0C0D */\
- "punpckhbw %%mm7, %%mm1 \n\t" /* 0E0F0G0H */\
- "pshufw $0x90, %%mm0, %%mm5 \n\t" /* 0A0A0B0C */\
- "pshufw $0x41, %%mm0, %%mm6 \n\t" /* 0B0A0A0B */\
- "movq %%mm2, %%mm3 \n\t" /* ABCDEFGH */\
- "movq %%mm2, %%mm4 \n\t" /* ABCDEFGH */\
- "psllq $8, %%mm2 \n\t" /* 0ABCDEFG */\
- "psllq $16, %%mm3 \n\t" /* 00ABCDEF */\
- "psllq $24, %%mm4 \n\t" /* 000ABCDE */\
- "punpckhbw %%mm7, %%mm2 \n\t" /* 0D0E0F0G */\
- "punpckhbw %%mm7, %%mm3 \n\t" /* 0C0D0E0F */\
- "punpckhbw %%mm7, %%mm4 \n\t" /* 0B0C0D0E */\
- "paddw %%mm3, %%mm5 \n\t" /* b */\
- "paddw %%mm2, %%mm6 \n\t" /* c */\
- "paddw %%mm5, %%mm5 \n\t" /* 2b */\
- "psubw %%mm5, %%mm6 \n\t" /* c - 2b */\
- "pshufw $0x06, %%mm0, %%mm5 \n\t" /* 0C0B0A0A */\
- "pmullw "MANGLE(ff_pw_3)", %%mm6 \n\t" /* 3c - 6b */\
- "paddw %%mm4, %%mm0 \n\t" /* a */\
- "paddw %%mm1, %%mm5 \n\t" /* d */\
- "pmullw "MANGLE(ff_pw_20)", %%mm0 \n\t" /* 20a */\
- "psubw %%mm5, %%mm0 \n\t" /* 20a - d */\
- "paddw %6, %%mm6 \n\t"\
- "paddw %%mm6, %%mm0 \n\t" /* 20a - 6b + 3c - d */\
- "psraw $5, %%mm0 \n\t"\
- /* mm1=EFGH, mm2=DEFG, mm3=CDEF, mm4=BCDE, mm7=0 */\
- \
- "movd 5(%0), %%mm5 \n\t" /* FGHI */\
- "punpcklbw %%mm7, %%mm5 \n\t" /* 0F0G0H0I */\
- "pshufw $0xF9, %%mm5, %%mm6 \n\t" /* 0G0H0I0I */\
- "paddw %%mm5, %%mm1 \n\t" /* a */\
- "paddw %%mm6, %%mm2 \n\t" /* b */\
- "pshufw $0xBE, %%mm5, %%mm6 \n\t" /* 0H0I0I0H */\
- "pshufw $0x6F, %%mm5, %%mm5 \n\t" /* 0I0I0H0G */\
- "paddw %%mm6, %%mm3 \n\t" /* c */\
- "paddw %%mm5, %%mm4 \n\t" /* d */\
- "paddw %%mm2, %%mm2 \n\t" /* 2b */\
- "psubw %%mm2, %%mm3 \n\t" /* c - 2b */\
- "pmullw "MANGLE(ff_pw_20)", %%mm1 \n\t" /* 20a */\
- "pmullw "MANGLE(ff_pw_3)", %%mm3 \n\t" /* 3c - 6b */\
- "psubw %%mm4, %%mm3 \n\t" /* -6b + 3c - d */\
- "paddw %6, %%mm1 \n\t"\
- "paddw %%mm1, %%mm3 \n\t" /* 20a - 6b + 3c - d */\
- "psraw $5, %%mm3 \n\t"\
- "packuswb %%mm3, %%mm0 \n\t"\
- OP_MMX2(%%mm0, (%1), %%mm4, q)\
- \
- "add %3, %0 \n\t"\
- "add %4, %1 \n\t"\
- "decl %2 \n\t"\
- " jnz 1b \n\t"\
- : "+a"(src), "+c"(dst), "+m"(h)\
- : "S"((long)srcStride), "D"((long)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(temp), "m"(ROUNDER)\
- : "memory"\
- );\
-}\
-\
-static void OPNAME ## mpeg4_qpel8_h_lowpass_3dnow(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
- int i;\
- int16_t temp[8];\
- /* quick HACK, XXX FIXME MUST be optimized */\
- for(i=0; i<h; i++)\
- {\
- temp[ 0]= (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]);\
- temp[ 1]= (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]);\
- temp[ 2]= (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]);\
- temp[ 3]= (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]);\
- temp[ 4]= (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]);\
- temp[ 5]= (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 8]);\
- temp[ 6]= (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 8])*3 - (src[ 3]+src[ 7]);\
- temp[ 7]= (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 8])*6 + (src[ 5]+src[ 7])*3 - (src[ 4]+src[ 6]);\
- asm volatile(\
- "movq (%0), %%mm0 \n\t"\
- "movq 8(%0), %%mm1 \n\t"\
- "paddw %2, %%mm0 \n\t"\
- "paddw %2, %%mm1 \n\t"\
- "psraw $5, %%mm0 \n\t"\
- "psraw $5, %%mm1 \n\t"\
- "packuswb %%mm1, %%mm0 \n\t"\
- OP_3DNOW(%%mm0, (%1), %%mm1, q)\
- :: "r"(temp), "r"(dst), "m"(ROUNDER)\
- :"memory"\
- );\
- dst+=dstStride;\
- src+=srcStride;\
- }\
-}
-
-#define QPEL_OP(OPNAME, ROUNDER, RND, OP, MMX)\
-\
-static void OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
- uint64_t temp[17*4];\
- uint64_t *temp_ptr= temp;\
- int count= 17;\
-\
- /*FIXME unroll */\
- asm volatile(\
- "pxor %%mm7, %%mm7 \n\t"\
- "1: \n\t"\
- "movq (%0), %%mm0 \n\t"\
- "movq (%0), %%mm1 \n\t"\
- "movq 8(%0), %%mm2 \n\t"\
- "movq 8(%0), %%mm3 \n\t"\
- "punpcklbw %%mm7, %%mm0 \n\t"\
- "punpckhbw %%mm7, %%mm1 \n\t"\
- "punpcklbw %%mm7, %%mm2 \n\t"\
- "punpckhbw %%mm7, %%mm3 \n\t"\
- "movq %%mm0, (%1) \n\t"\
- "movq %%mm1, 17*8(%1) \n\t"\
- "movq %%mm2, 2*17*8(%1) \n\t"\
- "movq %%mm3, 3*17*8(%1) \n\t"\
- "add $8, %1 \n\t"\
- "add %3, %0 \n\t"\
- "decl %2 \n\t"\
- " jnz 1b \n\t"\
- : "+r" (src), "+r" (temp_ptr), "+r"(count)\
- : "r" ((long)srcStride)\
- : "memory"\
- );\
- \
- temp_ptr= temp;\
- count=4;\
- \
-/*FIXME reorder for speed */\
- asm volatile(\
- /*"pxor %%mm7, %%mm7 \n\t"*/\
- "1: \n\t"\
- "movq (%0), %%mm0 \n\t"\
- "movq 8(%0), %%mm1 \n\t"\
- "movq 16(%0), %%mm2 \n\t"\
- "movq 24(%0), %%mm3 \n\t"\
- QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 16(%0), 8(%0), (%0), 32(%0), (%1), OP)\
- QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 8(%0), (%0), (%0), 40(%0), (%1, %3), OP)\
- "add %4, %1 \n\t"\
- QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, (%0), (%0), 8(%0), 48(%0), (%1), OP)\
- \
- QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, (%0), 8(%0), 16(%0), 56(%0), (%1, %3), OP)\
- "add %4, %1 \n\t"\
- QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 8(%0), 16(%0), 24(%0), 64(%0), (%1), OP)\
- QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 16(%0), 24(%0), 32(%0), 72(%0), (%1, %3), OP)\
- "add %4, %1 \n\t"\
- QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 24(%0), 32(%0), 40(%0), 80(%0), (%1), OP)\
- QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 32(%0), 40(%0), 48(%0), 88(%0), (%1, %3), OP)\
- "add %4, %1 \n\t"\
- QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 40(%0), 48(%0), 56(%0), 96(%0), (%1), OP)\
- QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 48(%0), 56(%0), 64(%0),104(%0), (%1, %3), OP)\
- "add %4, %1 \n\t"\
- QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 56(%0), 64(%0), 72(%0),112(%0), (%1), OP)\
- QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 64(%0), 72(%0), 80(%0),120(%0), (%1, %3), OP)\
- "add %4, %1 \n\t"\
- QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 72(%0), 80(%0), 88(%0),128(%0), (%1), OP)\
- \
- QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 80(%0), 88(%0), 96(%0),128(%0), (%1, %3), OP)\
- "add %4, %1 \n\t" \
- QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 88(%0), 96(%0),104(%0),120(%0), (%1), OP)\
- QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 96(%0),104(%0),112(%0),112(%0), (%1, %3), OP)\
- \
- "add $136, %0 \n\t"\
- "add %6, %1 \n\t"\
- "decl %2 \n\t"\
- " jnz 1b \n\t"\
- \
- : "+r"(temp_ptr), "+r"(dst), "+g"(count)\
- : "r"((long)dstStride), "r"(2*(long)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(ROUNDER), "g"(4-14*(long)dstStride)\
- :"memory"\
- );\
-}\
-\
-static void OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
- uint64_t temp[9*2];\
- uint64_t *temp_ptr= temp;\
- int count= 9;\
-\
- /*FIXME unroll */\
- asm volatile(\
- "pxor %%mm7, %%mm7 \n\t"\
- "1: \n\t"\
- "movq (%0), %%mm0 \n\t"\
- "movq (%0), %%mm1 \n\t"\
- "punpcklbw %%mm7, %%mm0 \n\t"\
- "punpckhbw %%mm7, %%mm1 \n\t"\
- "movq %%mm0, (%1) \n\t"\
- "movq %%mm1, 9*8(%1) \n\t"\
- "add $8, %1 \n\t"\
- "add %3, %0 \n\t"\
- "decl %2 \n\t"\
- " jnz 1b \n\t"\
- : "+r" (src), "+r" (temp_ptr), "+r"(count)\
- : "r" ((long)srcStride)\
- : "memory"\
- );\
- \
- temp_ptr= temp;\
- count=2;\
- \
-/*FIXME reorder for speed */\
- asm volatile(\
- /*"pxor %%mm7, %%mm7 \n\t"*/\
- "1: \n\t"\
- "movq (%0), %%mm0 \n\t"\
- "movq 8(%0), %%mm1 \n\t"\
- "movq 16(%0), %%mm2 \n\t"\
- "movq 24(%0), %%mm3 \n\t"\
- QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 16(%0), 8(%0), (%0), 32(%0), (%1), OP)\
- QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 8(%0), (%0), (%0), 40(%0), (%1, %3), OP)\
- "add %4, %1 \n\t"\
- QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, (%0), (%0), 8(%0), 48(%0), (%1), OP)\
- \
- QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, (%0), 8(%0), 16(%0), 56(%0), (%1, %3), OP)\
- "add %4, %1 \n\t"\
- QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 8(%0), 16(%0), 24(%0), 64(%0), (%1), OP)\
- \
- QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 16(%0), 24(%0), 32(%0), 64(%0), (%1, %3), OP)\
- "add %4, %1 \n\t"\
- QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 24(%0), 32(%0), 40(%0), 56(%0), (%1), OP)\
- QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 32(%0), 40(%0), 48(%0), 48(%0), (%1, %3), OP)\
- \
- "add $72, %0 \n\t"\
- "add %6, %1 \n\t"\
- "decl %2 \n\t"\
- " jnz 1b \n\t"\
- \
- : "+r"(temp_ptr), "+r"(dst), "+g"(count)\
- : "r"((long)dstStride), "r"(2*(long)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(ROUNDER), "g"(4-6*(long)dstStride)\
- : "memory"\
- );\
-}\
-\
-static void OPNAME ## qpel8_mc00_ ## MMX (uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## pixels8_mmx(dst, src, stride, 8);\
-}\
-\
-static void OPNAME ## qpel8_mc10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t temp[8];\
- uint8_t * const half= (uint8_t*)temp;\
- put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, stride, 8);\
- OPNAME ## pixels8_l2_ ## MMX(dst, src, half, stride, stride, 8);\
-}\
-\
-static void OPNAME ## qpel8_mc20_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## mpeg4_qpel8_h_lowpass_ ## MMX(dst, src, stride, stride, 8);\
-}\
-\
-static void OPNAME ## qpel8_mc30_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t temp[8];\
- uint8_t * const half= (uint8_t*)temp;\
- put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, stride, 8);\
- OPNAME ## pixels8_l2_ ## MMX(dst, src+1, half, stride, stride, 8);\
-}\
-\
-static void OPNAME ## qpel8_mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t temp[8];\
- uint8_t * const half= (uint8_t*)temp;\
- put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, 8, stride);\
- OPNAME ## pixels8_l2_ ## MMX(dst, src, half, stride, stride, 8);\
-}\
-\
-static void OPNAME ## qpel8_mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, src, stride, stride);\
-}\
-\
-static void OPNAME ## qpel8_mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t temp[8];\
- uint8_t * const half= (uint8_t*)temp;\
- put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, 8, stride);\
- OPNAME ## pixels8_l2_ ## MMX(dst, src+stride, half, stride, stride, 8);\
-}\
-static void OPNAME ## qpel8_mc11_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[8 + 9];\
- uint8_t * const halfH= ((uint8_t*)half) + 64;\
- uint8_t * const halfHV= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
- put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8);\
-}\
-static void OPNAME ## qpel8_mc31_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[8 + 9];\
- uint8_t * const halfH= ((uint8_t*)half) + 64;\
- uint8_t * const halfHV= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
- put ## RND ## pixels8_l2_ ## MMX(halfH, src+1, halfH, 8, stride, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8);\
-}\
-static void OPNAME ## qpel8_mc13_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[8 + 9];\
- uint8_t * const halfH= ((uint8_t*)half) + 64;\
- uint8_t * const halfHV= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
- put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l2_ ## MMX(dst, halfH+8, halfHV, stride, 8, 8);\
-}\
-static void OPNAME ## qpel8_mc33_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[8 + 9];\
- uint8_t * const halfH= ((uint8_t*)half) + 64;\
- uint8_t * const halfHV= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
- put ## RND ## pixels8_l2_ ## MMX(halfH, src+1, halfH, 8, stride, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l2_ ## MMX(dst, halfH+8, halfHV, stride, 8, 8);\
-}\
-static void OPNAME ## qpel8_mc21_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[8 + 9];\
- uint8_t * const halfH= ((uint8_t*)half) + 64;\
- uint8_t * const halfHV= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8);\
-}\
-static void OPNAME ## qpel8_mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[8 + 9];\
- uint8_t * const halfH= ((uint8_t*)half) + 64;\
- uint8_t * const halfHV= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l2_ ## MMX(dst, halfH+8, halfHV, stride, 8, 8);\
-}\
-static void OPNAME ## qpel8_mc12_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[8 + 9];\
- uint8_t * const halfH= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
- put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9);\
- OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
-}\
-static void OPNAME ## qpel8_mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[8 + 9];\
- uint8_t * const halfH= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
- put ## RND ## pixels8_l2_ ## MMX(halfH, src+1, halfH, 8, stride, 9);\
- OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
-}\
-static void OPNAME ## qpel8_mc22_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[9];\
- uint8_t * const halfH= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
- OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
-}\
-static void OPNAME ## qpel16_mc00_ ## MMX (uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## pixels16_mmx(dst, src, stride, 16);\
-}\
-\
-static void OPNAME ## qpel16_mc10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t temp[32];\
- uint8_t * const half= (uint8_t*)temp;\
- put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, stride, 16);\
- OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, stride, 16);\
-}\
-\
-static void OPNAME ## qpel16_mc20_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## mpeg4_qpel16_h_lowpass_ ## MMX(dst, src, stride, stride, 16);\
-}\
-\
-static void OPNAME ## qpel16_mc30_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t temp[32];\
- uint8_t * const half= (uint8_t*)temp;\
- put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, stride, 16);\
- OPNAME ## pixels16_l2_ ## MMX(dst, src+1, half, stride, stride, 16);\
-}\
-\
-static void OPNAME ## qpel16_mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t temp[32];\
- uint8_t * const half= (uint8_t*)temp;\
- put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, stride);\
- OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, stride, 16);\
-}\
-\
-static void OPNAME ## qpel16_mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, src, stride, stride);\
-}\
-\
-static void OPNAME ## qpel16_mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t temp[32];\
- uint8_t * const half= (uint8_t*)temp;\
- put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, stride);\
- OPNAME ## pixels16_l2_ ## MMX(dst, src+stride, half, stride, stride, 16);\
-}\
-static void OPNAME ## qpel16_mc11_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[16*2 + 17*2];\
- uint8_t * const halfH= ((uint8_t*)half) + 256;\
- uint8_t * const halfHV= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
- put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, stride, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16);\
-}\
-static void OPNAME ## qpel16_mc31_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[16*2 + 17*2];\
- uint8_t * const halfH= ((uint8_t*)half) + 256;\
- uint8_t * const halfHV= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
- put ## RND ## pixels16_l2_ ## MMX(halfH, src+1, halfH, 16, stride, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16);\
-}\
-static void OPNAME ## qpel16_mc13_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[16*2 + 17*2];\
- uint8_t * const halfH= ((uint8_t*)half) + 256;\
- uint8_t * const halfHV= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
- put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, stride, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l2_ ## MMX(dst, halfH+16, halfHV, stride, 16, 16);\
-}\
-static void OPNAME ## qpel16_mc33_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[16*2 + 17*2];\
- uint8_t * const halfH= ((uint8_t*)half) + 256;\
- uint8_t * const halfHV= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
- put ## RND ## pixels16_l2_ ## MMX(halfH, src+1, halfH, 16, stride, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l2_ ## MMX(dst, halfH+16, halfHV, stride, 16, 16);\
-}\
-static void OPNAME ## qpel16_mc21_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[16*2 + 17*2];\
- uint8_t * const halfH= ((uint8_t*)half) + 256;\
- uint8_t * const halfHV= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16);\
-}\
-static void OPNAME ## qpel16_mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[16*2 + 17*2];\
- uint8_t * const halfH= ((uint8_t*)half) + 256;\
- uint8_t * const halfHV= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l2_ ## MMX(dst, halfH+16, halfHV, stride, 16, 16);\
-}\
-static void OPNAME ## qpel16_mc12_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[17*2];\
- uint8_t * const halfH= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
- put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, stride, 17);\
- OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
-}\
-static void OPNAME ## qpel16_mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[17*2];\
- uint8_t * const halfH= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
- put ## RND ## pixels16_l2_ ## MMX(halfH, src+1, halfH, 16, stride, 17);\
- OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
-}\
-static void OPNAME ## qpel16_mc22_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[17*2];\
- uint8_t * const halfH= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
- OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
-}
-
-#define PUT_OP(a,b,temp, size) "mov" #size " " #a ", " #b " \n\t"
-#define AVG_3DNOW_OP(a,b,temp, size) \
-"mov" #size " " #b ", " #temp " \n\t"\
-"pavgusb " #temp ", " #a " \n\t"\
-"mov" #size " " #a ", " #b " \n\t"
-#define AVG_MMX2_OP(a,b,temp, size) \
-"mov" #size " " #b ", " #temp " \n\t"\
-"pavgb " #temp ", " #a " \n\t"\
-"mov" #size " " #a ", " #b " \n\t"
-
-QPEL_BASE(put_ , ff_pw_16, _ , PUT_OP, PUT_OP)
-QPEL_BASE(avg_ , ff_pw_16, _ , AVG_MMX2_OP, AVG_3DNOW_OP)
-QPEL_BASE(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, PUT_OP)
-QPEL_OP(put_ , ff_pw_16, _ , PUT_OP, 3dnow)
-QPEL_OP(avg_ , ff_pw_16, _ , AVG_3DNOW_OP, 3dnow)
-QPEL_OP(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, 3dnow)
-QPEL_OP(put_ , ff_pw_16, _ , PUT_OP, mmx2)
-QPEL_OP(avg_ , ff_pw_16, _ , AVG_MMX2_OP, mmx2)
-QPEL_OP(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, mmx2)
-
-/***********************************/
-/* bilinear qpel: not compliant to any spec, only for -lavdopts fast */
-
-#define QPEL_2TAP_XY(OPNAME, SIZE, MMX, XY, HPEL)\
-static void OPNAME ## 2tap_qpel ## SIZE ## _mc ## XY ## _ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## pixels ## SIZE ## HPEL(dst, src, stride, SIZE);\
-}
-#define QPEL_2TAP_L3(OPNAME, SIZE, MMX, XY, S0, S1, S2)\
-static void OPNAME ## 2tap_qpel ## SIZE ## _mc ## XY ## _ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## 2tap_qpel ## SIZE ## _l3_ ## MMX(dst, src+S0, stride, SIZE, S1, S2);\
-}
-
-#define QPEL_2TAP(OPNAME, SIZE, MMX)\
-QPEL_2TAP_XY(OPNAME, SIZE, MMX, 20, _x2_ ## MMX)\
-QPEL_2TAP_XY(OPNAME, SIZE, MMX, 02, _y2_ ## MMX)\
-QPEL_2TAP_XY(OPNAME, SIZE, MMX, 22, _xy2_mmx)\
-static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc00_ ## MMX =\
- OPNAME ## qpel ## SIZE ## _mc00_ ## MMX;\
-static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc21_ ## MMX =\
- OPNAME ## 2tap_qpel ## SIZE ## _mc20_ ## MMX;\
-static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc12_ ## MMX =\
- OPNAME ## 2tap_qpel ## SIZE ## _mc02_ ## MMX;\
-static void OPNAME ## 2tap_qpel ## SIZE ## _mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## pixels ## SIZE ## _y2_ ## MMX(dst, src+1, stride, SIZE);\
-}\
-static void OPNAME ## 2tap_qpel ## SIZE ## _mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## pixels ## SIZE ## _x2_ ## MMX(dst, src+stride, stride, SIZE);\
-}\
-QPEL_2TAP_L3(OPNAME, SIZE, MMX, 10, 0, 1, 0)\
-QPEL_2TAP_L3(OPNAME, SIZE, MMX, 30, 1, -1, 0)\
-QPEL_2TAP_L3(OPNAME, SIZE, MMX, 01, 0, stride, 0)\
-QPEL_2TAP_L3(OPNAME, SIZE, MMX, 03, stride, -stride, 0)\
-QPEL_2TAP_L3(OPNAME, SIZE, MMX, 11, 0, stride, 1)\
-QPEL_2TAP_L3(OPNAME, SIZE, MMX, 31, 1, stride, -1)\
-QPEL_2TAP_L3(OPNAME, SIZE, MMX, 13, stride, -stride, 1)\
-QPEL_2TAP_L3(OPNAME, SIZE, MMX, 33, stride+1, -stride, -1)\
-
-QPEL_2TAP(put_, 16, mmx2)
-QPEL_2TAP(avg_, 16, mmx2)
-QPEL_2TAP(put_, 8, mmx2)
-QPEL_2TAP(avg_, 8, mmx2)
-QPEL_2TAP(put_, 16, 3dnow)
-QPEL_2TAP(avg_, 16, 3dnow)
-QPEL_2TAP(put_, 8, 3dnow)
-QPEL_2TAP(avg_, 8, 3dnow)
-
-
-#if 0
-static void just_return() { return; }
-#endif
-
-#define SET_QPEL_FUNC(postfix1, postfix2) \
- c->put_ ## postfix1 = put_ ## postfix2;\
- c->put_no_rnd_ ## postfix1 = put_no_rnd_ ## postfix2;\
- c->avg_ ## postfix1 = avg_ ## postfix2;
-
-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;
- const int ix = ox>>(16+shift);
- const int iy = oy>>(16+shift);
- const int oxs = ox>>4;
- const int oys = oy>>4;
- const int dxxs = dxx>>4;
- const int dxys = dxy>>4;
- const int dyxs = dyx>>4;
- const int dyys = dyy>>4;
- const uint16_t r4[4] = {r,r,r,r};
- const uint16_t dxy4[4] = {dxys,dxys,dxys,dxys};
- const uint16_t dyy4[4] = {dyys,dyys,dyys,dyys};
- const uint64_t shift2 = 2*shift;
- uint8_t edge_buf[(h+1)*stride];
- int x, y;
-
- const int dxw = (dxx-(1<<(16+shift)))*(w-1);
- const int dyh = (dyy-(1<<(16+shift)))*(h-1);
- const int dxh = dxy*(h-1);
- const int dyw = dyx*(w-1);
- if( // non-constant fullpel offset (3% of blocks)
- (ox^(ox+dxw) | ox^(ox+dxh) | ox^(ox+dxw+dxh) |
- oy^(oy+dyw) | oy^(oy+dyh) | oy^(oy+dyw+dyh)) >> (16+shift)
- // uses more than 16 bits of subpel mv (only at huge resolution)
- || (dxx|dxy|dyx|dyy)&15 )
- {
- //FIXME could still use mmx for some of the rows
- ff_gmc_c(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy, shift, r, width, height);
- return;
- }
-
- src += ix + iy*stride;
- if( (unsigned)ix >= width-w ||
- (unsigned)iy >= height-h )
- {
- ff_emulated_edge_mc(edge_buf, src, stride, w+1, h+1, ix, iy, width, height);
- src = edge_buf;
- }
-
- asm volatile(
- "movd %0, %%mm6 \n\t"
- "pxor %%mm7, %%mm7 \n\t"
- "punpcklwd %%mm6, %%mm6 \n\t"
- "punpcklwd %%mm6, %%mm6 \n\t"
- :: "r"(1<<shift)
- );
-
- for(x=0; x<w; x+=4){
- uint16_t dx4[4] = { oxs - dxys + dxxs*(x+0),
- oxs - dxys + dxxs*(x+1),
- oxs - dxys + dxxs*(x+2),
- oxs - dxys + dxxs*(x+3) };
- uint16_t dy4[4] = { oys - dyys + dyxs*(x+0),
- oys - dyys + dyxs*(x+1),
- oys - dyys + dyxs*(x+2),
- oys - dyys + dyxs*(x+3) };
-
- for(y=0; y<h; y++){
- asm volatile(
- "movq %0, %%mm4 \n\t"
- "movq %1, %%mm5 \n\t"
- "paddw %2, %%mm4 \n\t"
- "paddw %3, %%mm5 \n\t"
- "movq %%mm4, %0 \n\t"
- "movq %%mm5, %1 \n\t"
- "psrlw $12, %%mm4 \n\t"
- "psrlw $12, %%mm5 \n\t"
- : "+m"(*dx4), "+m"(*dy4)
- : "m"(*dxy4), "m"(*dyy4)
- );
-
- asm volatile(
- "movq %%mm6, %%mm2 \n\t"
- "movq %%mm6, %%mm1 \n\t"
- "psubw %%mm4, %%mm2 \n\t"
- "psubw %%mm5, %%mm1 \n\t"
- "movq %%mm2, %%mm0 \n\t"
- "movq %%mm4, %%mm3 \n\t"
- "pmullw %%mm1, %%mm0 \n\t" // (s-dx)*(s-dy)
- "pmullw %%mm5, %%mm3 \n\t" // dx*dy
- "pmullw %%mm5, %%mm2 \n\t" // (s-dx)*dy
- "pmullw %%mm4, %%mm1 \n\t" // dx*(s-dy)
-
- "movd %3, %%mm5 \n\t"
- "movd %2, %%mm4 \n\t"
- "punpcklbw %%mm7, %%mm5 \n\t"
- "punpcklbw %%mm7, %%mm4 \n\t"
- "pmullw %%mm5, %%mm3 \n\t" // src[1,1] * dx*dy
- "pmullw %%mm4, %%mm2 \n\t" // src[0,1] * (s-dx)*dy
-
- "movd %1, %%mm5 \n\t"
- "movd %0, %%mm4 \n\t"
- "punpcklbw %%mm7, %%mm5 \n\t"
- "punpcklbw %%mm7, %%mm4 \n\t"
- "pmullw %%mm5, %%mm1 \n\t" // src[1,0] * dx*(s-dy)
- "pmullw %%mm4, %%mm0 \n\t" // src[0,0] * (s-dx)*(s-dy)
- "paddw %4, %%mm1 \n\t"
- "paddw %%mm3, %%mm2 \n\t"
- "paddw %%mm1, %%mm0 \n\t"
- "paddw %%mm2, %%mm0 \n\t"
-
- "psrlw %5, %%mm0 \n\t"
- "packuswb %%mm0, %%mm0 \n\t"
-
- :
- : "m"(src[0]), "m"(src[1]),
- "m"(src[stride]), "m"(src[stride+1]),
- "m"(*r4), "m"(shift2)
- );
-
- asm volatile(
- "movd %%mm0, %0 \n\t"
-
- : "=m"(dst[x+y*stride])
- :
- );
- src += stride;
- }
- src += 4-h*stride;
- }
-}
-
-#ifdef CONFIG_ENCODERS
-static int try_8x8basis_mmx(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale){
- long i=0;
-
- assert(FFABS(scale) < 256);
- scale<<= 16 + 1 - BASIS_SHIFT + RECON_SHIFT;
-
- asm volatile(
- "pcmpeqw %%mm6, %%mm6 \n\t" // -1w
- "psrlw $15, %%mm6 \n\t" // 1w
- "pxor %%mm7, %%mm7 \n\t"
- "movd %4, %%mm5 \n\t"
- "punpcklwd %%mm5, %%mm5 \n\t"
- "punpcklwd %%mm5, %%mm5 \n\t"
- "1: \n\t"
- "movq (%1, %0), %%mm0 \n\t"
- "movq 8(%1, %0), %%mm1 \n\t"
- "pmulhw %%mm5, %%mm0 \n\t"
- "pmulhw %%mm5, %%mm1 \n\t"
- "paddw %%mm6, %%mm0 \n\t"
- "paddw %%mm6, %%mm1 \n\t"
- "psraw $1, %%mm0 \n\t"
- "psraw $1, %%mm1 \n\t"
- "paddw (%2, %0), %%mm0 \n\t"
- "paddw 8(%2, %0), %%mm1 \n\t"
- "psraw $6, %%mm0 \n\t"
- "psraw $6, %%mm1 \n\t"
- "pmullw (%3, %0), %%mm0 \n\t"
- "pmullw 8(%3, %0), %%mm1 \n\t"
- "pmaddwd %%mm0, %%mm0 \n\t"
- "pmaddwd %%mm1, %%mm1 \n\t"
- "paddd %%mm1, %%mm0 \n\t"
- "psrld $4, %%mm0 \n\t"
- "paddd %%mm0, %%mm7 \n\t"
- "add $16, %0 \n\t"
- "cmp $128, %0 \n\t" //FIXME optimize & bench
- " jb 1b \n\t"
- "movq %%mm7, %%mm6 \n\t"
- "psrlq $32, %%mm7 \n\t"
- "paddd %%mm6, %%mm7 \n\t"
- "psrld $2, %%mm7 \n\t"
- "movd %%mm7, %0 \n\t"
-
- : "+r" (i)
- : "r"(basis), "r"(rem), "r"(weight), "g"(scale)
- );
- return i;
-}
-
-static void add_8x8basis_mmx(int16_t rem[64], int16_t basis[64], int scale){
- long i=0;
-
- if(FFABS(scale) < 256){
- scale<<= 16 + 1 - BASIS_SHIFT + RECON_SHIFT;
- asm volatile(
- "pcmpeqw %%mm6, %%mm6 \n\t" // -1w
- "psrlw $15, %%mm6 \n\t" // 1w
- "movd %3, %%mm5 \n\t"
- "punpcklwd %%mm5, %%mm5 \n\t"
- "punpcklwd %%mm5, %%mm5 \n\t"
- "1: \n\t"
- "movq (%1, %0), %%mm0 \n\t"
- "movq 8(%1, %0), %%mm1 \n\t"
- "pmulhw %%mm5, %%mm0 \n\t"
- "pmulhw %%mm5, %%mm1 \n\t"
- "paddw %%mm6, %%mm0 \n\t"
- "paddw %%mm6, %%mm1 \n\t"
- "psraw $1, %%mm0 \n\t"
- "psraw $1, %%mm1 \n\t"
- "paddw (%2, %0), %%mm0 \n\t"
- "paddw 8(%2, %0), %%mm1 \n\t"
- "movq %%mm0, (%2, %0) \n\t"
- "movq %%mm1, 8(%2, %0) \n\t"
- "add $16, %0 \n\t"
- "cmp $128, %0 \n\t" //FIXME optimize & bench
- " jb 1b \n\t"
-
- : "+r" (i)
- : "r"(basis), "r"(rem), "g"(scale)
- );
- }else{
- for(i=0; i<8*8; i++){
- rem[i] += (basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT);
- }
- }
-}
-#endif /* CONFIG_ENCODERS */
-
-#define PREFETCH(name, op) \
-static void name(void *mem, int stride, int h){\
- const uint8_t *p= mem;\
- do{\
- asm volatile(#op" %0" :: "m"(*p));\
- p+= stride;\
- }while(--h);\
-}
-PREFETCH(prefetch_mmx2, prefetcht0)
-PREFETCH(prefetch_3dnow, prefetch)
-#undef PREFETCH
-
-#include "h264dsp_mmx.c"
-
-/* AVS specific */
-void ff_cavsdsp_init_mmx2(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);
-}
-void ff_avg_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
- avg_pixels8_mmx(dst, src, stride, 8);
-}
-void ff_put_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
- put_pixels16_mmx(dst, src, stride, 16);
-}
-void ff_avg_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
- avg_pixels16_mmx(dst, src, stride, 16);
-}
-
-/* external functions, from idct_mmx.c */
-void ff_mmx_idct(DCTELEM *block);
-void ff_mmxext_idct(DCTELEM *block);
-
-void ff_vp3_idct_sse2(int16_t *input_data);
-void ff_vp3_idct_mmx(int16_t *data);
-void ff_vp3_dsp_init_mmx(void);
-
-/* XXX: those functions should be suppressed ASAP when all IDCTs are
- converted */
-#ifdef CONFIG_GPL
-static void ff_libmpeg2mmx_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
-{
- ff_mmx_idct (block);
- put_pixels_clamped_mmx(block, dest, line_size);
-}
-static void ff_libmpeg2mmx_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
-{
- ff_mmx_idct (block);
- add_pixels_clamped_mmx(block, dest, line_size);
-}
-static void ff_libmpeg2mmx2_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
-{
- ff_mmxext_idct (block);
- put_pixels_clamped_mmx(block, dest, line_size);
-}
-static void ff_libmpeg2mmx2_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
-{
- ff_mmxext_idct (block);
- add_pixels_clamped_mmx(block, dest, line_size);
-}
-#endif
-static void ff_vp3_idct_put_sse2(uint8_t *dest, int line_size, DCTELEM *block)
-{
- ff_vp3_idct_sse2(block);
- put_signed_pixels_clamped_mmx(block, dest, line_size);
-}
-static void ff_vp3_idct_add_sse2(uint8_t *dest, int line_size, DCTELEM *block)
-{
- ff_vp3_idct_sse2(block);
- add_pixels_clamped_mmx(block, dest, line_size);
-}
-static void ff_vp3_idct_put_mmx(uint8_t *dest, int line_size, DCTELEM *block)
-{
- ff_vp3_idct_mmx(block);
- put_signed_pixels_clamped_mmx(block, dest, line_size);
-}
-static 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);
-}
-static void ff_idct_xvid_mmx_put(uint8_t *dest, int line_size, DCTELEM *block)
-{
- ff_idct_xvid_mmx (block);
- put_pixels_clamped_mmx(block, dest, line_size);
-}
-static void ff_idct_xvid_mmx_add(uint8_t *dest, int line_size, DCTELEM *block)
-{
- ff_idct_xvid_mmx (block);
- add_pixels_clamped_mmx(block, dest, line_size);
-}
-static void ff_idct_xvid_mmx2_put(uint8_t *dest, int line_size, DCTELEM *block)
-{
- ff_idct_xvid_mmx2 (block);
- put_pixels_clamped_mmx(block, dest, line_size);
-}
-static void ff_idct_xvid_mmx2_add(uint8_t *dest, int line_size, DCTELEM *block)
-{
- ff_idct_xvid_mmx2 (block);
- add_pixels_clamped_mmx(block, dest, line_size);
-}
-
-static void vorbis_inverse_coupling_3dnow(float *mag, float *ang, int blocksize)
-{
- int i;
- asm volatile("pxor %%mm7, %%mm7":);
- for(i=0; i<blocksize; i+=2) {
- asm volatile(
- "movq %0, %%mm0 \n\t"
- "movq %1, %%mm1 \n\t"
- "movq %%mm0, %%mm2 \n\t"
- "movq %%mm1, %%mm3 \n\t"
- "pfcmpge %%mm7, %%mm2 \n\t" // m <= 0.0
- "pfcmpge %%mm7, %%mm3 \n\t" // a <= 0.0
- "pslld $31, %%mm2 \n\t" // keep only the sign bit
- "pxor %%mm2, %%mm1 \n\t"
- "movq %%mm3, %%mm4 \n\t"
- "pand %%mm1, %%mm3 \n\t"
- "pandn %%mm1, %%mm4 \n\t"
- "pfadd %%mm0, %%mm3 \n\t" // a = m + ((a<0) & (a ^ sign(m)))
- "pfsub %%mm4, %%mm0 \n\t" // m = m + ((a>0) & (a ^ sign(m)))
- "movq %%mm3, %1 \n\t"
- "movq %%mm0, %0 \n\t"
- :"+m"(mag[i]), "+m"(ang[i])
- ::"memory"
- );
- }
- asm volatile("femms");
-}
-static void vorbis_inverse_coupling_sse(float *mag, float *ang, int blocksize)
-{
- int i;
-
- asm volatile(
- "movaps %0, %%xmm5 \n\t"
- ::"m"(ff_pdw_80000000[0])
- );
- for(i=0; i<blocksize; i+=4) {
- asm volatile(
- "movaps %0, %%xmm0 \n\t"
- "movaps %1, %%xmm1 \n\t"
- "xorps %%xmm2, %%xmm2 \n\t"
- "xorps %%xmm3, %%xmm3 \n\t"
- "cmpleps %%xmm0, %%xmm2 \n\t" // m <= 0.0
- "cmpleps %%xmm1, %%xmm3 \n\t" // a <= 0.0
- "andps %%xmm5, %%xmm2 \n\t" // keep only the sign bit
- "xorps %%xmm2, %%xmm1 \n\t"
- "movaps %%xmm3, %%xmm4 \n\t"
- "andps %%xmm1, %%xmm3 \n\t"
- "andnps %%xmm1, %%xmm4 \n\t"
- "addps %%xmm0, %%xmm3 \n\t" // a = m + ((a<0) & (a ^ sign(m)))
- "subps %%xmm4, %%xmm0 \n\t" // m = m + ((a>0) & (a ^ sign(m)))
- "movaps %%xmm3, %1 \n\t"
- "movaps %%xmm0, %0 \n\t"
- :"+m"(mag[i]), "+m"(ang[i])
- ::"memory"
- );
- }
-}
-
-static void vector_fmul_3dnow(float *dst, const float *src, int len){
- long i = (len-4)*4;
- asm volatile(
- "1: \n\t"
- "movq (%1,%0), %%mm0 \n\t"
- "movq 8(%1,%0), %%mm1 \n\t"
- "pfmul (%2,%0), %%mm0 \n\t"
- "pfmul 8(%2,%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"
- "femms \n\t"
- :"+r"(i)
- :"r"(dst), "r"(src)
- :"memory"
- );
-}
-static void vector_fmul_sse(float *dst, const float *src, int len){
- long i = (len-8)*4;
- asm volatile(
- "1: \n\t"
- "movaps (%1,%0), %%xmm0 \n\t"
- "movaps 16(%1,%0), %%xmm1 \n\t"
- "mulps (%2,%0), %%xmm0 \n\t"
- "mulps 16(%2,%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"(src)
- :"memory"
- );
-}
-
-static void vector_fmul_reverse_3dnow2(float *dst, const float *src0, const float *src1, int len){
- long i = len*4-16;
- asm volatile(
- "1: \n\t"
- "pswapd 8(%1), %%mm0 \n\t"
- "pswapd (%1), %%mm1 \n\t"
- "pfmul (%3,%0), %%mm0 \n\t"
- "pfmul 8(%3,%0), %%mm1 \n\t"
- "movq %%mm0, (%2,%0) \n\t"
- "movq %%mm1, 8(%2,%0) \n\t"
- "add $16, %1 \n\t"
- "sub $16, %0 \n\t"
- "jge 1b \n\t"
- :"+r"(i), "+r"(src1)
- :"r"(dst), "r"(src0)
- );
- asm volatile("femms");
-}
-static void vector_fmul_reverse_sse(float *dst, const float *src0, const float *src1, int len){
- long i = len*4-32;
- asm volatile(
- "1: \n\t"
- "movaps 16(%1), %%xmm0 \n\t"
- "movaps (%1), %%xmm1 \n\t"
- "shufps $0x1b, %%xmm0, %%xmm0 \n\t"
- "shufps $0x1b, %%xmm1, %%xmm1 \n\t"
- "mulps (%3,%0), %%xmm0 \n\t"
- "mulps 16(%3,%0), %%xmm1 \n\t"
- "movaps %%xmm0, (%2,%0) \n\t"
- "movaps %%xmm1, 16(%2,%0) \n\t"
- "add $32, %1 \n\t"
- "sub $32, %0 \n\t"
- "jge 1b \n\t"
- :"+r"(i), "+r"(src1)
- :"r"(dst), "r"(src0)
- );
-}
-
-static void vector_fmul_add_add_3dnow(float *dst, const float *src0, const float *src1,
- const float *src2, int src3, int len, int step){
- long 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("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){
- long 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);
-}
-
-static void float_to_int16_3dnow(int16_t *dst, const float *src, int len){
- // not bit-exact: pf2id uses different rounding than C and SSE
- int i;
- for(i=0; i<len; i+=4) {
- asm volatile(
- "pf2id %1, %%mm0 \n\t"
- "pf2id %2, %%mm1 \n\t"
- "packssdw %%mm1, %%mm0 \n\t"
- "movq %%mm0, %0 \n\t"
- :"=m"(dst[i])
- :"m"(src[i]), "m"(src[i+2])
- );
- }
- asm volatile("femms");
-}
-static void float_to_int16_sse(int16_t *dst, const float *src, int len){
- int i;
- for(i=0; i<len; i+=4) {
- asm volatile(
- "cvtps2pi %1, %%mm0 \n\t"
- "cvtps2pi %2, %%mm1 \n\t"
- "packssdw %%mm1, %%mm0 \n\t"
- "movq %%mm0, %0 \n\t"
- :"=m"(dst[i])
- :"m"(src[i]), "m"(src[i+2])
- );
- }
- asm volatile("emms");
-}
-
-#ifdef CONFIG_SNOW_ENCODER
-extern void ff_snow_horizontal_compose97i_sse2(DWTELEM *b, int width);
-extern void ff_snow_horizontal_compose97i_mmx(DWTELEM *b, int width);
-extern void ff_snow_vertical_compose97i_sse2(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWTELEM *b3, DWTELEM *b4, DWTELEM *b5, int width);
-extern void ff_snow_vertical_compose97i_mmx(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWTELEM *b3, DWTELEM *b4, DWTELEM *b5, int width);
-extern void ff_snow_inner_add_yblock_sse2(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);
-extern void ff_snow_inner_add_yblock_mmx(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);
-#endif
-
-void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
-{
- mm_flags = mm_support();
-
- if (avctx->dsp_mask) {
- if (avctx->dsp_mask & FF_MM_FORCE)
- mm_flags |= (avctx->dsp_mask & 0xffff);
- else
- mm_flags &= ~(avctx->dsp_mask & 0xffff);
- }
-
-#if 0
- av_log(avctx, AV_LOG_INFO, "libavcodec: CPU flags:");
- if (mm_flags & MM_MMX)
- av_log(avctx, AV_LOG_INFO, " mmx");
- if (mm_flags & MM_MMXEXT)
- av_log(avctx, AV_LOG_INFO, " mmxext");
- if (mm_flags & MM_3DNOW)
- av_log(avctx, AV_LOG_INFO, " 3dnow");
- if (mm_flags & MM_SSE)
- av_log(avctx, AV_LOG_INFO, " sse");
- if (mm_flags & MM_SSE2)
- av_log(avctx, AV_LOG_INFO, " sse2");
- av_log(avctx, AV_LOG_INFO, "\n");
-#endif
-
- if (mm_flags & MM_MMX) {
- const int idct_algo= avctx->idct_algo;
-
-#ifdef CONFIG_ENCODERS
- const int dct_algo = avctx->dct_algo;
- if(dct_algo==FF_DCT_AUTO || dct_algo==FF_DCT_MMX){
- if(mm_flags & MM_SSE2){
- c->fdct = ff_fdct_sse2;
- }else if(mm_flags & MM_MMXEXT){
- c->fdct = ff_fdct_mmx2;
- }else{
- c->fdct = ff_fdct_mmx;
- }
- }
-#endif //CONFIG_ENCODERS
- if(avctx->lowres==0){
- if(idct_algo==FF_IDCT_AUTO || idct_algo==FF_IDCT_SIMPLEMMX){
- c->idct_put= ff_simple_idct_put_mmx;
- c->idct_add= ff_simple_idct_add_mmx;
- c->idct = ff_simple_idct_mmx;
- c->idct_permutation_type= FF_SIMPLE_IDCT_PERM;
-#ifdef CONFIG_GPL
- }else if(idct_algo==FF_IDCT_LIBMPEG2MMX){
- if(mm_flags & MM_MMXEXT){
- c->idct_put= ff_libmpeg2mmx2_idct_put;
- c->idct_add= ff_libmpeg2mmx2_idct_add;
- c->idct = ff_mmxext_idct;
- }else{
- c->idct_put= ff_libmpeg2mmx_idct_put;
- c->idct_add= ff_libmpeg2mmx_idct_add;
- c->idct = ff_mmx_idct;
- }
- c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
-#endif
- }else if(idct_algo==FF_IDCT_VP3 &&
- avctx->codec->id!=CODEC_ID_THEORA &&
- !(avctx->flags & CODEC_FLAG_BITEXACT)){
- if(mm_flags & MM_SSE2){
- c->idct_put= ff_vp3_idct_put_sse2;
- c->idct_add= ff_vp3_idct_add_sse2;
- c->idct = ff_vp3_idct_sse2;
- c->idct_permutation_type= FF_TRANSPOSE_IDCT_PERM;
- }else{
- ff_vp3_dsp_init_mmx();
- c->idct_put= ff_vp3_idct_put_mmx;
- c->idct_add= ff_vp3_idct_add_mmx;
- c->idct = ff_vp3_idct_mmx;
- c->idct_permutation_type= FF_PARTTRANS_IDCT_PERM;
- }
- }else if(idct_algo==FF_IDCT_CAVS){
- c->idct_permutation_type= FF_TRANSPOSE_IDCT_PERM;
- }else if(idct_algo==FF_IDCT_XVIDMMX){
- if(mm_flags & MM_MMXEXT){
- c->idct_put= ff_idct_xvid_mmx2_put;
- c->idct_add= ff_idct_xvid_mmx2_add;
- c->idct = ff_idct_xvid_mmx2;
- }else{
- c->idct_put= ff_idct_xvid_mmx_put;
- c->idct_add= ff_idct_xvid_mmx_add;
- c->idct = ff_idct_xvid_mmx;
- }
- }
- }
-
-#ifdef CONFIG_ENCODERS
- c->get_pixels = get_pixels_mmx;
- c->diff_pixels = diff_pixels_mmx;
-#endif //CONFIG_ENCODERS
- c->put_pixels_clamped = put_pixels_clamped_mmx;
- c->put_signed_pixels_clamped = put_signed_pixels_clamped_mmx;
- c->add_pixels_clamped = add_pixels_clamped_mmx;
- c->clear_blocks = clear_blocks_mmx;
-#ifdef CONFIG_ENCODERS
- c->pix_sum = pix_sum16_mmx;
-#endif //CONFIG_ENCODERS
-
- c->put_pixels_tab[0][0] = put_pixels16_mmx;
- c->put_pixels_tab[0][1] = put_pixels16_x2_mmx;
- c->put_pixels_tab[0][2] = put_pixels16_y2_mmx;
- c->put_pixels_tab[0][3] = put_pixels16_xy2_mmx;
-
- c->put_no_rnd_pixels_tab[0][0] = put_pixels16_mmx;
- c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmx;
- c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmx;
- c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy2_mmx;
-
- c->avg_pixels_tab[0][0] = avg_pixels16_mmx;
- c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmx;
- c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmx;
- c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmx;
-
- c->avg_no_rnd_pixels_tab[0][0] = avg_no_rnd_pixels16_mmx;
- c->avg_no_rnd_pixels_tab[0][1] = avg_no_rnd_pixels16_x2_mmx;
- c->avg_no_rnd_pixels_tab[0][2] = avg_no_rnd_pixels16_y2_mmx;
- c->avg_no_rnd_pixels_tab[0][3] = avg_no_rnd_pixels16_xy2_mmx;
-
- c->put_pixels_tab[1][0] = put_pixels8_mmx;
- c->put_pixels_tab[1][1] = put_pixels8_x2_mmx;
- c->put_pixels_tab[1][2] = put_pixels8_y2_mmx;
- c->put_pixels_tab[1][3] = put_pixels8_xy2_mmx;
-
- c->put_no_rnd_pixels_tab[1][0] = put_pixels8_mmx;
- c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_mmx;
- c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_mmx;
- c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels8_xy2_mmx;
-
- c->avg_pixels_tab[1][0] = avg_pixels8_mmx;
- c->avg_pixels_tab[1][1] = avg_pixels8_x2_mmx;
- c->avg_pixels_tab[1][2] = avg_pixels8_y2_mmx;
- c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mmx;
-
- c->avg_no_rnd_pixels_tab[1][0] = avg_no_rnd_pixels8_mmx;
- c->avg_no_rnd_pixels_tab[1][1] = avg_no_rnd_pixels8_x2_mmx;
- c->avg_no_rnd_pixels_tab[1][2] = avg_no_rnd_pixels8_y2_mmx;
- c->avg_no_rnd_pixels_tab[1][3] = avg_no_rnd_pixels8_xy2_mmx;
-
- c->gmc= gmc_mmx;
-
- c->add_bytes= add_bytes_mmx;
-#ifdef CONFIG_ENCODERS
- c->diff_bytes= diff_bytes_mmx;
-
- c->hadamard8_diff[0]= hadamard8_diff16_mmx;
- c->hadamard8_diff[1]= hadamard8_diff_mmx;
-
- c->pix_norm1 = pix_norm1_mmx;
- c->sse[0] = (mm_flags & MM_SSE2) ? sse16_sse2 : sse16_mmx;
- c->sse[1] = sse8_mmx;
- c->vsad[4]= vsad_intra16_mmx;
-
- c->nsse[0] = nsse16_mmx;
- c->nsse[1] = nsse8_mmx;
- if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
- c->vsad[0] = vsad16_mmx;
- }
-
- if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
- c->try_8x8basis= try_8x8basis_mmx;
- }
- c->add_8x8basis= add_8x8basis_mmx;
-
-#endif //CONFIG_ENCODERS
-
- c->h263_v_loop_filter= h263_v_loop_filter_mmx;
- c->h263_h_loop_filter= h263_h_loop_filter_mmx;
- c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_mmx;
- c->put_h264_chroma_pixels_tab[1]= put_h264_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;
-
- if (mm_flags & MM_MMXEXT) {
- c->prefetch = prefetch_mmx2;
-
- c->put_pixels_tab[0][1] = put_pixels16_x2_mmx2;
- c->put_pixels_tab[0][2] = put_pixels16_y2_mmx2;
-
- c->avg_pixels_tab[0][0] = avg_pixels16_mmx2;
- c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmx2;
- c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmx2;
-
- c->put_pixels_tab[1][1] = put_pixels8_x2_mmx2;
- c->put_pixels_tab[1][2] = put_pixels8_y2_mmx2;
-
- c->avg_pixels_tab[1][0] = avg_pixels8_mmx2;
- c->avg_pixels_tab[1][1] = avg_pixels8_x2_mmx2;
- c->avg_pixels_tab[1][2] = avg_pixels8_y2_mmx2;
-
-#ifdef CONFIG_ENCODERS
- c->hadamard8_diff[0]= hadamard8_diff16_mmx2;
- c->hadamard8_diff[1]= hadamard8_diff_mmx2;
- c->vsad[4]= vsad_intra16_mmx2;
-#endif //CONFIG_ENCODERS
-
- c->h264_idct_dc_add= ff_h264_idct_dc_add_mmx2;
- c->h264_idct8_dc_add= ff_h264_idct8_dc_add_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;
- c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_mmx2;
- c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_mmx2;
- c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmx2;
- c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mmx2;
-#ifdef CONFIG_ENCODERS
- c->vsad[0] = vsad16_mmx2;
-#endif //CONFIG_ENCODERS
- }
-
-#if 1
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 0], qpel16_mc00_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 1], qpel16_mc10_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 2], qpel16_mc20_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 3], qpel16_mc30_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 4], qpel16_mc01_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 5], qpel16_mc11_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 6], qpel16_mc21_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 7], qpel16_mc31_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 8], qpel16_mc02_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 9], qpel16_mc12_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[0][10], qpel16_mc22_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[0][11], qpel16_mc32_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[0][12], qpel16_mc03_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[0][13], qpel16_mc13_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[0][14], qpel16_mc23_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[0][15], qpel16_mc33_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 0], qpel8_mc00_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 1], qpel8_mc10_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 2], qpel8_mc20_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 3], qpel8_mc30_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 4], qpel8_mc01_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 5], qpel8_mc11_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 6], qpel8_mc21_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 7], qpel8_mc31_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 8], qpel8_mc02_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 9], qpel8_mc12_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[1][10], qpel8_mc22_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[1][11], qpel8_mc32_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[1][12], qpel8_mc03_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[1][13], qpel8_mc13_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[1][14], qpel8_mc23_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[1][15], qpel8_mc33_mmx2)
-#endif
-
-//FIXME 3dnow too
-#define dspfunc(PFX, IDX, NUM) \
- c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_mmx2; \
- c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_mmx2; \
- c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_mmx2; \
- c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_mmx2; \
- c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_mmx2; \
- c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_mmx2; \
- c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_mmx2; \
- c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_mmx2; \
- c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_mmx2; \
- c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_mmx2; \
- c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_mmx2; \
- c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_mmx2; \
- c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_mmx2; \
- c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_mmx2; \
- c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_mmx2; \
- c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_mmx2
-
- dspfunc(put_h264_qpel, 0, 16);
- dspfunc(put_h264_qpel, 1, 8);
- dspfunc(put_h264_qpel, 2, 4);
- dspfunc(avg_h264_qpel, 0, 16);
- dspfunc(avg_h264_qpel, 1, 8);
- dspfunc(avg_h264_qpel, 2, 4);
-
- dspfunc(put_2tap_qpel, 0, 16);
- dspfunc(put_2tap_qpel, 1, 8);
- dspfunc(avg_2tap_qpel, 0, 16);
- dspfunc(avg_2tap_qpel, 1, 8);
-#undef dspfunc
-
- c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_mmx2;
- 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;
- 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;
-
-#ifdef CONFIG_CAVS_DECODER
- ff_cavsdsp_init_mmx2(c, avctx);
-#endif
-
-#ifdef CONFIG_ENCODERS
- c->sub_hfyu_median_prediction= sub_hfyu_median_prediction_mmx2;
-#endif //CONFIG_ENCODERS
- } else if (mm_flags & MM_3DNOW) {
- c->prefetch = prefetch_3dnow;
-
- c->put_pixels_tab[0][1] = put_pixels16_x2_3dnow;
- c->put_pixels_tab[0][2] = put_pixels16_y2_3dnow;
-
- c->avg_pixels_tab[0][0] = avg_pixels16_3dnow;
- c->avg_pixels_tab[0][1] = avg_pixels16_x2_3dnow;
- c->avg_pixels_tab[0][2] = avg_pixels16_y2_3dnow;
-
- c->put_pixels_tab[1][1] = put_pixels8_x2_3dnow;
- c->put_pixels_tab[1][2] = put_pixels8_y2_3dnow;
-
- c->avg_pixels_tab[1][0] = avg_pixels8_3dnow;
- c->avg_pixels_tab[1][1] = avg_pixels8_x2_3dnow;
- c->avg_pixels_tab[1][2] = avg_pixels8_y2_3dnow;
-
- if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
- c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_3dnow;
- c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_3dnow;
- c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_3dnow;
- c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_3dnow;
- c->avg_pixels_tab[0][3] = avg_pixels16_xy2_3dnow;
- c->avg_pixels_tab[1][3] = avg_pixels8_xy2_3dnow;
- }
-
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 0], qpel16_mc00_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 1], qpel16_mc10_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 2], qpel16_mc20_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 3], qpel16_mc30_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 4], qpel16_mc01_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 5], qpel16_mc11_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 6], qpel16_mc21_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 7], qpel16_mc31_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 8], qpel16_mc02_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 9], qpel16_mc12_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[0][10], qpel16_mc22_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[0][11], qpel16_mc32_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[0][12], qpel16_mc03_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[0][13], qpel16_mc13_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[0][14], qpel16_mc23_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[0][15], qpel16_mc33_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 0], qpel8_mc00_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 1], qpel8_mc10_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 2], qpel8_mc20_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 3], qpel8_mc30_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 4], qpel8_mc01_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 5], qpel8_mc11_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 6], qpel8_mc21_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 7], qpel8_mc31_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 8], qpel8_mc02_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 9], qpel8_mc12_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[1][10], qpel8_mc22_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[1][11], qpel8_mc32_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[1][12], qpel8_mc03_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[1][13], qpel8_mc13_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[1][14], qpel8_mc23_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[1][15], qpel8_mc33_3dnow)
-
-#define dspfunc(PFX, IDX, NUM) \
- c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_3dnow; \
- c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_3dnow; \
- c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_3dnow; \
- c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_3dnow; \
- c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_3dnow; \
- c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_3dnow; \
- c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_3dnow; \
- c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_3dnow; \
- c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_3dnow; \
- c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_3dnow; \
- c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_3dnow; \
- c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_3dnow; \
- c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_3dnow; \
- c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_3dnow; \
- c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_3dnow; \
- c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_3dnow
-
- dspfunc(put_h264_qpel, 0, 16);
- dspfunc(put_h264_qpel, 1, 8);
- dspfunc(put_h264_qpel, 2, 4);
- dspfunc(avg_h264_qpel, 0, 16);
- dspfunc(avg_h264_qpel, 1, 8);
- dspfunc(avg_h264_qpel, 2, 4);
-
- dspfunc(put_2tap_qpel, 0, 16);
- dspfunc(put_2tap_qpel, 1, 8);
- dspfunc(avg_2tap_qpel, 0, 16);
- dspfunc(avg_2tap_qpel, 1, 8);
-
- c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_3dnow;
- c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_3dnow;
- }
-
-#ifdef CONFIG_SNOW_ENCODER
- if(mm_flags & MM_SSE2){
- c->horizontal_compose97i = ff_snow_horizontal_compose97i_sse2;
- c->vertical_compose97i = ff_snow_vertical_compose97i_sse2;
- c->inner_add_yblock = ff_snow_inner_add_yblock_sse2;
- }
- else{
- c->horizontal_compose97i = ff_snow_horizontal_compose97i_mmx;
- c->vertical_compose97i = ff_snow_vertical_compose97i_mmx;
- c->inner_add_yblock = ff_snow_inner_add_yblock_mmx;
- }
-#endif
-
- if(mm_flags & MM_3DNOW){
- c->vorbis_inverse_coupling = vorbis_inverse_coupling_3dnow;
- c->vector_fmul = vector_fmul_3dnow;
- if(!(avctx->flags & CODEC_FLAG_BITEXACT))
- c->float_to_int16 = float_to_int16_3dnow;
- }
- if(mm_flags & MM_3DNOWEXT)
- c->vector_fmul_reverse = vector_fmul_reverse_3dnow2;
- if(mm_flags & MM_SSE){
- c->vorbis_inverse_coupling = vorbis_inverse_coupling_sse;
- c->vector_fmul = vector_fmul_sse;
- c->float_to_int16 = float_to_int16_sse;
- c->vector_fmul_reverse = vector_fmul_reverse_sse;
- c->vector_fmul_add_add = vector_fmul_add_add_sse;
- }
- if(mm_flags & MM_3DNOW)
- c->vector_fmul_add_add = vector_fmul_add_add_3dnow; // faster than sse
- }
-
-#ifdef CONFIG_ENCODERS
- dsputil_init_pix_mmx(c, avctx);
-#endif //CONFIG_ENCODERS
-#if 0
- // for speed testing
- get_pixels = just_return;
- put_pixels_clamped = just_return;
- add_pixels_clamped = just_return;
-
- pix_abs16x16 = just_return;
- pix_abs16x16_x2 = just_return;
- pix_abs16x16_y2 = just_return;
- pix_abs16x16_xy2 = just_return;
-
- put_pixels_tab[0] = just_return;
- put_pixels_tab[1] = just_return;
- put_pixels_tab[2] = just_return;
- put_pixels_tab[3] = just_return;
-
- put_no_rnd_pixels_tab[0] = just_return;
- put_no_rnd_pixels_tab[1] = just_return;
- put_no_rnd_pixels_tab[2] = just_return;
- put_no_rnd_pixels_tab[3] = just_return;
-
- avg_pixels_tab[0] = just_return;
- avg_pixels_tab[1] = just_return;
- avg_pixels_tab[2] = just_return;
- avg_pixels_tab[3] = just_return;
-
- avg_no_rnd_pixels_tab[0] = just_return;
- avg_no_rnd_pixels_tab[1] = just_return;
- avg_no_rnd_pixels_tab[2] = just_return;
- avg_no_rnd_pixels_tab[3] = just_return;
-
- //av_fdct = just_return;
- //ff_idct = just_return;
-#endif
-}
diff --git a/src/libffmpeg/libavcodec/i386/h264dsp_mmx.c b/src/libffmpeg/libavcodec/i386/h264dsp_mmx.c
deleted file mode 100644
index 40baf199b..000000000
--- a/src/libffmpeg/libavcodec/i386/h264dsp_mmx.c
+++ /dev/null
@@ -1,1513 +0,0 @@
-/*
- * Copyright (c) 2004-2005 Michael Niedermayer, Loren Merritt
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-
-/***********************************/
-/* IDCT */
-
-/* in/out: mma=mma+mmb, mmb=mmb-mma */
-#define SUMSUB_BA( a, b ) \
- "paddw "#b", "#a" \n\t"\
- "paddw "#b", "#b" \n\t"\
- "psubw "#a", "#b" \n\t"
-
-#define SUMSUB_BADC( a, b, c, d ) \
- "paddw "#b", "#a" \n\t"\
- "paddw "#d", "#c" \n\t"\
- "paddw "#b", "#b" \n\t"\
- "paddw "#d", "#d" \n\t"\
- "psubw "#a", "#b" \n\t"\
- "psubw "#c", "#d" \n\t"
-
-#define SUMSUBD2_AB( a, b, t ) \
- "movq "#b", "#t" \n\t"\
- "psraw $1 , "#b" \n\t"\
- "paddw "#a", "#b" \n\t"\
- "psraw $1 , "#a" \n\t"\
- "psubw "#t", "#a" \n\t"
-
-#define IDCT4_1D( s02, s13, d02, d13, t ) \
- SUMSUB_BA ( s02, d02 )\
- SUMSUBD2_AB( s13, d13, t )\
- SUMSUB_BADC( d13, s02, s13, d02 )
-
-#define TRANSPOSE4(a,b,c,d,t)\
- SBUTTERFLY(a,b,t,wd) /* a=aebf t=cgdh */\
- SBUTTERFLY(c,d,b,wd) /* c=imjn b=kolp */\
- SBUTTERFLY(a,c,d,dq) /* a=aeim d=bfjn */\
- SBUTTERFLY(t,b,c,dq) /* t=cgko c=dhlp */
-
-#define STORE_DIFF_4P( p, t, z ) \
- "psraw $6, "#p" \n\t"\
- "movd (%0), "#t" \n\t"\
- "punpcklbw "#z", "#t" \n\t"\
- "paddsw "#t", "#p" \n\t"\
- "packuswb "#z", "#p" \n\t"\
- "movd "#p", (%0) \n\t"
-
-static void ff_h264_idct_add_mmx(uint8_t *dst, int16_t *block, int stride)
-{
- /* Load dct coeffs */
- asm volatile(
- "movq (%0), %%mm0 \n\t"
- "movq 8(%0), %%mm1 \n\t"
- "movq 16(%0), %%mm2 \n\t"
- "movq 24(%0), %%mm3 \n\t"
- :: "r"(block) );
-
- asm volatile(
- /* mm1=s02+s13 mm2=s02-s13 mm4=d02+d13 mm0=d02-d13 */
- IDCT4_1D( %%mm2, %%mm1, %%mm0, %%mm3, %%mm4 )
-
- "movq %0, %%mm6 \n\t"
- /* in: 1,4,0,2 out: 1,2,3,0 */
- TRANSPOSE4( %%mm3, %%mm1, %%mm0, %%mm2, %%mm4 )
-
- "paddw %%mm6, %%mm3 \n\t"
-
- /* mm2=s02+s13 mm3=s02-s13 mm4=d02+d13 mm1=d02-d13 */
- IDCT4_1D( %%mm4, %%mm2, %%mm3, %%mm0, %%mm1 )
-
- "pxor %%mm7, %%mm7 \n\t"
- :: "m"(ff_pw_32));
-
- asm volatile(
- STORE_DIFF_4P( %%mm0, %%mm1, %%mm7)
- "add %1, %0 \n\t"
- STORE_DIFF_4P( %%mm2, %%mm1, %%mm7)
- "add %1, %0 \n\t"
- STORE_DIFF_4P( %%mm3, %%mm1, %%mm7)
- "add %1, %0 \n\t"
- STORE_DIFF_4P( %%mm4, %%mm1, %%mm7)
- : "+r"(dst)
- : "r" ((long)stride)
- );
-}
-
-static inline void h264_idct8_1d(int16_t *block)
-{
- asm volatile(
- "movq 112(%0), %%mm7 \n\t"
- "movq 80(%0), %%mm5 \n\t"
- "movq 48(%0), %%mm3 \n\t"
- "movq 16(%0), %%mm1 \n\t"
-
- "movq %%mm7, %%mm4 \n\t"
- "movq %%mm3, %%mm6 \n\t"
- "movq %%mm5, %%mm0 \n\t"
- "movq %%mm7, %%mm2 \n\t"
- "psraw $1, %%mm4 \n\t"
- "psraw $1, %%mm6 \n\t"
- "psubw %%mm7, %%mm0 \n\t"
- "psubw %%mm6, %%mm2 \n\t"
- "psubw %%mm4, %%mm0 \n\t"
- "psubw %%mm3, %%mm2 \n\t"
- "psubw %%mm3, %%mm0 \n\t"
- "paddw %%mm1, %%mm2 \n\t"
-
- "movq %%mm5, %%mm4 \n\t"
- "movq %%mm1, %%mm6 \n\t"
- "psraw $1, %%mm4 \n\t"
- "psraw $1, %%mm6 \n\t"
- "paddw %%mm5, %%mm4 \n\t"
- "paddw %%mm1, %%mm6 \n\t"
- "paddw %%mm7, %%mm4 \n\t"
- "paddw %%mm5, %%mm6 \n\t"
- "psubw %%mm1, %%mm4 \n\t"
- "paddw %%mm3, %%mm6 \n\t"
-
- "movq %%mm0, %%mm1 \n\t"
- "movq %%mm4, %%mm3 \n\t"
- "movq %%mm2, %%mm5 \n\t"
- "movq %%mm6, %%mm7 \n\t"
- "psraw $2, %%mm6 \n\t"
- "psraw $2, %%mm3 \n\t"
- "psraw $2, %%mm5 \n\t"
- "psraw $2, %%mm0 \n\t"
- "paddw %%mm6, %%mm1 \n\t"
- "paddw %%mm2, %%mm3 \n\t"
- "psubw %%mm4, %%mm5 \n\t"
- "psubw %%mm0, %%mm7 \n\t"
-
- "movq 32(%0), %%mm2 \n\t"
- "movq 96(%0), %%mm6 \n\t"
- "movq %%mm2, %%mm4 \n\t"
- "movq %%mm6, %%mm0 \n\t"
- "psraw $1, %%mm4 \n\t"
- "psraw $1, %%mm6 \n\t"
- "psubw %%mm0, %%mm4 \n\t"
- "paddw %%mm2, %%mm6 \n\t"
-
- "movq (%0), %%mm2 \n\t"
- "movq 64(%0), %%mm0 \n\t"
- SUMSUB_BA( %%mm0, %%mm2 )
- SUMSUB_BA( %%mm6, %%mm0 )
- SUMSUB_BA( %%mm4, %%mm2 )
- SUMSUB_BA( %%mm7, %%mm6 )
- SUMSUB_BA( %%mm5, %%mm4 )
- SUMSUB_BA( %%mm3, %%mm2 )
- SUMSUB_BA( %%mm1, %%mm0 )
- :: "r"(block)
- );
-}
-
-static void ff_h264_idct8_add_mmx(uint8_t *dst, int16_t *block, int stride)
-{
- int i;
- int16_t __attribute__ ((aligned(8))) b2[64];
-
- block[0] += 32;
-
- for(i=0; i<2; i++){
- DECLARE_ALIGNED_8(uint64_t, tmp);
-
- h264_idct8_1d(block+4*i);
-
- asm volatile(
- "movq %%mm7, %0 \n\t"
- TRANSPOSE4( %%mm0, %%mm2, %%mm4, %%mm6, %%mm7 )
- "movq %%mm0, 8(%1) \n\t"
- "movq %%mm6, 24(%1) \n\t"
- "movq %%mm7, 40(%1) \n\t"
- "movq %%mm4, 56(%1) \n\t"
- "movq %0, %%mm7 \n\t"
- TRANSPOSE4( %%mm7, %%mm5, %%mm3, %%mm1, %%mm0 )
- "movq %%mm7, (%1) \n\t"
- "movq %%mm1, 16(%1) \n\t"
- "movq %%mm0, 32(%1) \n\t"
- "movq %%mm3, 48(%1) \n\t"
- : "=m"(tmp)
- : "r"(b2+32*i)
- : "memory"
- );
- }
-
- for(i=0; i<2; i++){
- h264_idct8_1d(b2+4*i);
-
- asm volatile(
- "psraw $6, %%mm7 \n\t"
- "psraw $6, %%mm6 \n\t"
- "psraw $6, %%mm5 \n\t"
- "psraw $6, %%mm4 \n\t"
- "psraw $6, %%mm3 \n\t"
- "psraw $6, %%mm2 \n\t"
- "psraw $6, %%mm1 \n\t"
- "psraw $6, %%mm0 \n\t"
-
- "movq %%mm7, (%0) \n\t"
- "movq %%mm5, 16(%0) \n\t"
- "movq %%mm3, 32(%0) \n\t"
- "movq %%mm1, 48(%0) \n\t"
- "movq %%mm0, 64(%0) \n\t"
- "movq %%mm2, 80(%0) \n\t"
- "movq %%mm4, 96(%0) \n\t"
- "movq %%mm6, 112(%0) \n\t"
- :: "r"(b2+4*i)
- : "memory"
- );
- }
-
- add_pixels_clamped_mmx(b2, dst, stride);
-}
-
-static void ff_h264_idct_dc_add_mmx2(uint8_t *dst, int16_t *block, int stride)
-{
- int dc = (block[0] + 32) >> 6;
- asm volatile(
- "movd %0, %%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"
- ::"r"(dc)
- );
- asm volatile(
- "movd %0, %%mm2 \n\t"
- "movd %1, %%mm3 \n\t"
- "movd %2, %%mm4 \n\t"
- "movd %3, %%mm5 \n\t"
- "paddusb %%mm0, %%mm2 \n\t"
- "paddusb %%mm0, %%mm3 \n\t"
- "paddusb %%mm0, %%mm4 \n\t"
- "paddusb %%mm0, %%mm5 \n\t"
- "psubusb %%mm1, %%mm2 \n\t"
- "psubusb %%mm1, %%mm3 \n\t"
- "psubusb %%mm1, %%mm4 \n\t"
- "psubusb %%mm1, %%mm5 \n\t"
- "movd %%mm2, %0 \n\t"
- "movd %%mm3, %1 \n\t"
- "movd %%mm4, %2 \n\t"
- "movd %%mm5, %3 \n\t"
- :"+m"(*(uint32_t*)(dst+0*stride)),
- "+m"(*(uint32_t*)(dst+1*stride)),
- "+m"(*(uint32_t*)(dst+2*stride)),
- "+m"(*(uint32_t*)(dst+3*stride))
- );
-}
-
-static void ff_h264_idct8_dc_add_mmx2(uint8_t *dst, int16_t *block, int stride)
-{
- int dc = (block[0] + 32) >> 6;
- int y;
- asm volatile(
- "movd %0, %%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"
- ::"r"(dc)
- );
- for(y=2; y--; dst += 4*stride){
- asm volatile(
- "movq %0, %%mm2 \n\t"
- "movq %1, %%mm3 \n\t"
- "movq %2, %%mm4 \n\t"
- "movq %3, %%mm5 \n\t"
- "paddusb %%mm0, %%mm2 \n\t"
- "paddusb %%mm0, %%mm3 \n\t"
- "paddusb %%mm0, %%mm4 \n\t"
- "paddusb %%mm0, %%mm5 \n\t"
- "psubusb %%mm1, %%mm2 \n\t"
- "psubusb %%mm1, %%mm3 \n\t"
- "psubusb %%mm1, %%mm4 \n\t"
- "psubusb %%mm1, %%mm5 \n\t"
- "movq %%mm2, %0 \n\t"
- "movq %%mm3, %1 \n\t"
- "movq %%mm4, %2 \n\t"
- "movq %%mm5, %3 \n\t"
- :"+m"(*(uint64_t*)(dst+0*stride)),
- "+m"(*(uint64_t*)(dst+1*stride)),
- "+m"(*(uint64_t*)(dst+2*stride)),
- "+m"(*(uint64_t*)(dst+3*stride))
- );
- }
-}
-
-
-/***********************************/
-/* deblocking */
-
-// out: o = |x-y|>a
-// clobbers: t
-#define DIFF_GT_MMX(x,y,a,o,t)\
- "movq "#y", "#t" \n\t"\
- "movq "#x", "#o" \n\t"\
- "psubusb "#x", "#t" \n\t"\
- "psubusb "#y", "#o" \n\t"\
- "por "#t", "#o" \n\t"\
- "psubusb "#a", "#o" \n\t"
-
-// out: o = |x-y|>a
-// clobbers: t
-#define DIFF_GT2_MMX(x,y,a,o,t)\
- "movq "#y", "#t" \n\t"\
- "movq "#x", "#o" \n\t"\
- "psubusb "#x", "#t" \n\t"\
- "psubusb "#y", "#o" \n\t"\
- "psubusb "#a", "#t" \n\t"\
- "psubusb "#a", "#o" \n\t"\
- "pcmpeqb "#t", "#o" \n\t"\
-
-// in: mm0=p1 mm1=p0 mm2=q0 mm3=q1
-// out: mm5=beta-1, mm7=mask
-// clobbers: mm4,mm6
-#define H264_DEBLOCK_MASK(alpha1, beta1) \
- "pshufw $0, "#alpha1", %%mm4 \n\t"\
- "pshufw $0, "#beta1 ", %%mm5 \n\t"\
- "packuswb %%mm4, %%mm4 \n\t"\
- "packuswb %%mm5, %%mm5 \n\t"\
- DIFF_GT_MMX(%%mm1, %%mm2, %%mm4, %%mm7, %%mm6) /* |p0-q0| > alpha-1 */\
- DIFF_GT_MMX(%%mm0, %%mm1, %%mm5, %%mm4, %%mm6) /* |p1-p0| > beta-1 */\
- "por %%mm4, %%mm7 \n\t"\
- DIFF_GT_MMX(%%mm3, %%mm2, %%mm5, %%mm4, %%mm6) /* |q1-q0| > beta-1 */\
- "por %%mm4, %%mm7 \n\t"\
- "pxor %%mm6, %%mm6 \n\t"\
- "pcmpeqb %%mm6, %%mm7 \n\t"
-
-// in: mm0=p1 mm1=p0 mm2=q0 mm3=q1 mm7=(tc&mask)
-// out: mm1=p0' mm2=q0'
-// clobbers: mm0,3-6
-#define H264_DEBLOCK_P0_Q0(pb_01, pb_3f)\
- "movq %%mm1 , %%mm5 \n\t"\
- "pxor %%mm2 , %%mm5 \n\t" /* p0^q0*/\
- "pand "#pb_01" , %%mm5 \n\t" /* (p0^q0)&1*/\
- "pcmpeqb %%mm4 , %%mm4 \n\t"\
- "pxor %%mm4 , %%mm3 \n\t"\
- "pavgb %%mm0 , %%mm3 \n\t" /* (p1 - q1 + 256)>>1*/\
- "pavgb "MANGLE(ff_pb_3)" , %%mm3 \n\t" /*(((p1 - q1 + 256)>>1)+4)>>1 = 64+2+(p1-q1)>>2*/\
- "pxor %%mm1 , %%mm4 \n\t"\
- "pavgb %%mm2 , %%mm4 \n\t" /* (q0 - p0 + 256)>>1*/\
- "pavgb %%mm5 , %%mm3 \n\t"\
- "paddusb %%mm4 , %%mm3 \n\t" /* d+128+33*/\
- "movq "MANGLE(ff_pb_A1)" , %%mm6 \n\t"\
- "psubusb %%mm3 , %%mm6 \n\t"\
- "psubusb "MANGLE(ff_pb_A1)" , %%mm3 \n\t"\
- "pminub %%mm7 , %%mm6 \n\t"\
- "pminub %%mm7 , %%mm3 \n\t"\
- "psubusb %%mm6 , %%mm1 \n\t"\
- "psubusb %%mm3 , %%mm2 \n\t"\
- "paddusb %%mm3 , %%mm1 \n\t"\
- "paddusb %%mm6 , %%mm2 \n\t"
-
-// in: mm0=p1 mm1=p0 mm2=q0 mm3=q1 mm7=(tc&mask) %8=mm_bone
-// out: (q1addr) = clip( (q2+((p0+q0+1)>>1))>>1, q1-tc0, q1+tc0 )
-// clobbers: q2, tmp, tc0
-#define H264_DEBLOCK_Q1(p1, q2, q2addr, q1addr, tc0, tmp)\
- "movq %%mm1, "#tmp" \n\t"\
- "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 */\
- "psubusb "#tmp", "#q2" \n\t" /* (p2+((p0+q0+1)>>1))>>1 */\
- "movq "#p1", "#tmp" \n\t"\
- "psubusb "#tc0", "#tmp" \n\t"\
- "paddusb "#p1", "#tc0" \n\t"\
- "pmaxub "#tmp", "#q2" \n\t"\
- "pminub "#tc0", "#q2" \n\t"\
- "movq "#q2", "q1addr" \n\t"
-
-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]);
-
- 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)
-
- "movd %5, %%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"
- "pand %%mm4, %%mm7 \n\t"
- "movq %%mm7, %0 \n\t"
-
- /* filter p1 */
- "movq (%1), %%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
- "pand 8+%0, %%mm7 \n\t" // mask & tc0
- "movq %%mm7, %%mm4 \n\t"
- "psubb %%mm6, %%mm7 \n\t"
- "pand %%mm4, %%mm6 \n\t" // mask & |p2-p0|<beta & tc0
- H264_DEBLOCK_Q1(%%mm0, %%mm3, "(%1)", "(%1,%3)", %%mm6, %%mm4)
-
- /* filter q1 */
- "movq (%2,%3,2), %%mm4 \n\t" //q2
- DIFF_GT2_MMX(%%mm2, %%mm4, %%mm5, %%mm6, %%mm3) // |q2-q0|>beta-1
- "pand %0, %%mm6 \n\t"
- "movq 8+%0, %%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)
-
- /* filter p0, q0 */
- H264_DEBLOCK_P0_Q0(%8, unused)
- "movq %%mm1, (%1,%3,2) \n\t"
- "movq %%mm2, (%2) \n\t"
-
- : "=m"(*tmp0)
- : "r"(pix-3*stride), "r"(pix), "r"((long)stride),
- "m"(*tmp0/*unused*/), "m"(*(uint32_t*)tc0), "m"(alpha1), "m"(beta1),
- "m"(mm_bone)
- );
-}
-
-static void h264_v_loop_filter_luma_mmx2(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
-{
- if((tc0[0] & tc0[1]) >= 0)
- h264_loop_filter_luma_mmx2(pix, stride, alpha-1, beta-1, tc0);
- if((tc0[2] & tc0[3]) >= 0)
- h264_loop_filter_luma_mmx2(pix+8, stride, alpha-1, beta-1, tc0+2);
-}
-static void h264_h_loop_filter_luma_mmx2(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
-{
- //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]);
- int i;
- for(i=0; i<2; i++, pix+=8*stride, tc0+=2) {
- if((tc0[0] & tc0[1]) < 0)
- continue;
- transpose4x4(trans, pix-4, 8, stride);
- transpose4x4(trans +4*8, pix, 8, stride);
- transpose4x4(trans+4, pix-4+4*stride, 8, stride);
- transpose4x4(trans+4+4*8, pix +4*stride, 8, stride);
- h264_loop_filter_luma_mmx2(trans+4*8, 8, alpha-1, beta-1, tc0);
- transpose4x4(pix-2, trans +2*8, stride, 8);
- transpose4x4(pix-2+4*stride, trans+4+2*8, stride, 8);
- }
-}
-
-static inline void h264_loop_filter_chroma_mmx2(uint8_t *pix, int stride, int alpha1, int beta1, int8_t *tc0)
-{
- asm volatile(
- "movq (%0), %%mm0 \n\t" //p1
- "movq (%0,%2), %%mm1 \n\t" //p0
- "movq (%1), %%mm2 \n\t" //q0
- "movq (%1,%2), %%mm3 \n\t" //q1
- H264_DEBLOCK_MASK(%4, %5)
- "movd %3, %%mm6 \n\t"
- "punpcklbw %%mm6, %%mm6 \n\t"
- "pand %%mm6, %%mm7 \n\t" // mm7 = tc&mask
- H264_DEBLOCK_P0_Q0(%6, %7)
- "movq %%mm1, (%0,%2) \n\t"
- "movq %%mm2, (%1) \n\t"
-
- :: "r"(pix-2*stride), "r"(pix), "r"((long)stride),
- "r"(*(uint32_t*)tc0),
- "m"(alpha1), "m"(beta1), "m"(mm_bone), "m"(ff_pb_3F)
- );
-}
-
-static void h264_v_loop_filter_chroma_mmx2(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
-{
- h264_loop_filter_chroma_mmx2(pix, stride, alpha-1, beta-1, tc0);
-}
-
-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]);
- 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);
- transpose4x4(pix-2, trans, stride, 8);
- transpose4x4(pix-2+4*stride, trans+4, stride, 8);
-}
-
-// p0 = (p0 + q1 + 2*p1 + 2) >> 2
-#define H264_FILTER_CHROMA4(p0, p1, q1, one) \
- "movq "#p0", %%mm4 \n\t"\
- "pxor "#q1", %%mm4 \n\t"\
- "pand "#one", %%mm4 \n\t" /* mm4 = (p0^q1)&1 */\
- "pavgb "#q1", "#p0" \n\t"\
- "psubusb %%mm4, "#p0" \n\t"\
- "pavgb "#p1", "#p0" \n\t" /* dst = avg(p1, avg(p0,q1) - ((p0^q1)&1)) */\
-
-static inline void h264_loop_filter_chroma_intra_mmx2(uint8_t *pix, int stride, int alpha1, int beta1)
-{
- asm volatile(
- "movq (%0), %%mm0 \n\t"
- "movq (%0,%2), %%mm1 \n\t"
- "movq (%1), %%mm2 \n\t"
- "movq (%1,%2), %%mm3 \n\t"
- H264_DEBLOCK_MASK(%3, %4)
- "movq %%mm1, %%mm5 \n\t"
- "movq %%mm2, %%mm6 \n\t"
- H264_FILTER_CHROMA4(%%mm1, %%mm0, %%mm3, %5) //p0'
- H264_FILTER_CHROMA4(%%mm2, %%mm3, %%mm0, %5) //q0'
- "psubb %%mm5, %%mm1 \n\t"
- "psubb %%mm6, %%mm2 \n\t"
- "pand %%mm7, %%mm1 \n\t"
- "pand %%mm7, %%mm2 \n\t"
- "paddb %%mm5, %%mm1 \n\t"
- "paddb %%mm6, %%mm2 \n\t"
- "movq %%mm1, (%0,%2) \n\t"
- "movq %%mm2, (%1) \n\t"
- :: "r"(pix-2*stride), "r"(pix), "r"((long)stride),
- "m"(alpha1), "m"(beta1), "m"(mm_bone)
- );
-}
-
-static void h264_v_loop_filter_chroma_intra_mmx2(uint8_t *pix, int stride, int alpha, int beta)
-{
- h264_loop_filter_chroma_intra_mmx2(pix, stride, alpha-1, beta-1);
-}
-
-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]);
- 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);
- transpose4x4(pix-2, trans, stride, 8);
- transpose4x4(pix-2+4*stride, trans+4, stride, 8);
-}
-
-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 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)
- );
- // 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 int mask_mv = dir ? mask_mv1 : mask_mv0;
- DECLARE_ALIGNED_8(const uint64_t, mask_dir) = dir ? 0 : 0xffffffffffffffffULL;
- int b_idx, edge, l;
- for( b_idx=12, edge=0; edge<edges; edge+=step, b_idx+=8*step ) {
- asm volatile(
- "pand %0, %%mm0 \n\t"
- ::"m"(mask_dir)
- );
- if(!(mask_mv & edge)) {
- asm volatile("pxor %%mm0, %%mm0 \n\t":);
- for( l = bidir; l >= 0; l-- ) {
- 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])
- );
- }
- }
- 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]
- ::"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"
- :"=m"(*bS[dir][edge])
- ::"memory"
- );
- }
- edges = 4;
- step = 1;
- }
- asm volatile(
- "movq (%0), %%mm0 \n\t"
- "movq 8(%0), %%mm1 \n\t"
- "movq 16(%0), %%mm2 \n\t"
- "movq 24(%0), %%mm3 \n\t"
- TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4)
- "movq %%mm0, (%0) \n\t"
- "movq %%mm3, 8(%0) \n\t"
- "movq %%mm4, 16(%0) \n\t"
- "movq %%mm2, 24(%0) \n\t"
- ::"r"(bS[0])
- :"memory"
- );
-}
-
-/***********************************/
-/* motion compensation */
-
-#define QPEL_H264V(A,B,C,D,E,F,OP)\
- "movd (%0), "#F" \n\t"\
- "movq "#C", %%mm6 \n\t"\
- "paddw "#D", %%mm6 \n\t"\
- "psllw $2, %%mm6 \n\t"\
- "psubw "#B", %%mm6 \n\t"\
- "psubw "#E", %%mm6 \n\t"\
- "pmullw %4, %%mm6 \n\t"\
- "add %2, %0 \n\t"\
- "punpcklbw %%mm7, "#F" \n\t"\
- "paddw %5, "#A" \n\t"\
- "paddw "#F", "#A" \n\t"\
- "paddw "#A", %%mm6 \n\t"\
- "psraw $5, %%mm6 \n\t"\
- "packuswb %%mm6, %%mm6 \n\t"\
- OP(%%mm6, (%1), A, d)\
- "add %3, %1 \n\t"
-
-#define QPEL_H264HV(A,B,C,D,E,F,OF)\
- "movd (%0), "#F" \n\t"\
- "movq "#C", %%mm6 \n\t"\
- "paddw "#D", %%mm6 \n\t"\
- "psllw $2, %%mm6 \n\t"\
- "psubw "#B", %%mm6 \n\t"\
- "psubw "#E", %%mm6 \n\t"\
- "pmullw %3, %%mm6 \n\t"\
- "add %2, %0 \n\t"\
- "punpcklbw %%mm7, "#F" \n\t"\
- "paddw "#F", "#A" \n\t"\
- "paddw "#A", %%mm6 \n\t"\
- "movq %%mm6, "#OF"(%1) \n\t"
-
-#define QPEL_H264(OPNAME, OP, MMX)\
-static void OPNAME ## h264_qpel4_h_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
- int h=4;\
-\
- asm volatile(\
- "pxor %%mm7, %%mm7 \n\t"\
- "movq %5, %%mm4 \n\t"\
- "movq %6, %%mm5 \n\t"\
- "1: \n\t"\
- "movd -1(%0), %%mm1 \n\t"\
- "movd (%0), %%mm2 \n\t"\
- "movd 1(%0), %%mm3 \n\t"\
- "movd 2(%0), %%mm0 \n\t"\
- "punpcklbw %%mm7, %%mm1 \n\t"\
- "punpcklbw %%mm7, %%mm2 \n\t"\
- "punpcklbw %%mm7, %%mm3 \n\t"\
- "punpcklbw %%mm7, %%mm0 \n\t"\
- "paddw %%mm0, %%mm1 \n\t"\
- "paddw %%mm3, %%mm2 \n\t"\
- "movd -2(%0), %%mm0 \n\t"\
- "movd 3(%0), %%mm3 \n\t"\
- "punpcklbw %%mm7, %%mm0 \n\t"\
- "punpcklbw %%mm7, %%mm3 \n\t"\
- "paddw %%mm3, %%mm0 \n\t"\
- "psllw $2, %%mm2 \n\t"\
- "psubw %%mm1, %%mm2 \n\t"\
- "pmullw %%mm4, %%mm2 \n\t"\
- "paddw %%mm5, %%mm0 \n\t"\
- "paddw %%mm2, %%mm0 \n\t"\
- "psraw $5, %%mm0 \n\t"\
- "packuswb %%mm0, %%mm0 \n\t"\
- OP(%%mm0, (%1),%%mm6, d)\
- "add %3, %0 \n\t"\
- "add %4, %1 \n\t"\
- "decl %2 \n\t"\
- " jnz 1b \n\t"\
- : "+a"(src), "+c"(dst), "+m"(h)\
- : "d"((long)srcStride), "S"((long)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\
- : "memory"\
- );\
-}\
-static void OPNAME ## h264_qpel4_h_lowpass_l2_ ## MMX(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride){\
- int h=4;\
- asm volatile(\
- "pxor %%mm7, %%mm7 \n\t"\
- "movq %0, %%mm4 \n\t"\
- "movq %1, %%mm5 \n\t"\
- :: "m"(ff_pw_5), "m"(ff_pw_16)\
- );\
- do{\
- asm volatile(\
- "movd -1(%0), %%mm1 \n\t"\
- "movd (%0), %%mm2 \n\t"\
- "movd 1(%0), %%mm3 \n\t"\
- "movd 2(%0), %%mm0 \n\t"\
- "punpcklbw %%mm7, %%mm1 \n\t"\
- "punpcklbw %%mm7, %%mm2 \n\t"\
- "punpcklbw %%mm7, %%mm3 \n\t"\
- "punpcklbw %%mm7, %%mm0 \n\t"\
- "paddw %%mm0, %%mm1 \n\t"\
- "paddw %%mm3, %%mm2 \n\t"\
- "movd -2(%0), %%mm0 \n\t"\
- "movd 3(%0), %%mm3 \n\t"\
- "punpcklbw %%mm7, %%mm0 \n\t"\
- "punpcklbw %%mm7, %%mm3 \n\t"\
- "paddw %%mm3, %%mm0 \n\t"\
- "psllw $2, %%mm2 \n\t"\
- "psubw %%mm1, %%mm2 \n\t"\
- "pmullw %%mm4, %%mm2 \n\t"\
- "paddw %%mm5, %%mm0 \n\t"\
- "paddw %%mm2, %%mm0 \n\t"\
- "movd (%2), %%mm3 \n\t"\
- "psraw $5, %%mm0 \n\t"\
- "packuswb %%mm0, %%mm0 \n\t"\
- PAVGB" %%mm3, %%mm0 \n\t"\
- OP(%%mm0, (%1),%%mm6, d)\
- "add %4, %0 \n\t"\
- "add %4, %1 \n\t"\
- "add %3, %2 \n\t"\
- : "+a"(src), "+c"(dst), "+d"(src2)\
- : "D"((long)src2Stride), "S"((long)dstStride)\
- : "memory"\
- );\
- }while(--h);\
-}\
-static void OPNAME ## h264_qpel4_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
- src -= 2*srcStride;\
- asm volatile(\
- "pxor %%mm7, %%mm7 \n\t"\
- "movd (%0), %%mm0 \n\t"\
- "add %2, %0 \n\t"\
- "movd (%0), %%mm1 \n\t"\
- "add %2, %0 \n\t"\
- "movd (%0), %%mm2 \n\t"\
- "add %2, %0 \n\t"\
- "movd (%0), %%mm3 \n\t"\
- "add %2, %0 \n\t"\
- "movd (%0), %%mm4 \n\t"\
- "add %2, %0 \n\t"\
- "punpcklbw %%mm7, %%mm0 \n\t"\
- "punpcklbw %%mm7, %%mm1 \n\t"\
- "punpcklbw %%mm7, %%mm2 \n\t"\
- "punpcklbw %%mm7, %%mm3 \n\t"\
- "punpcklbw %%mm7, %%mm4 \n\t"\
- QPEL_H264V(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP)\
- QPEL_H264V(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP)\
- QPEL_H264V(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP)\
- QPEL_H264V(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP)\
- \
- : "+a"(src), "+c"(dst)\
- : "S"((long)srcStride), "D"((long)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\
- : "memory"\
- );\
-}\
-static void OPNAME ## h264_qpel4_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
- int h=4;\
- int w=3;\
- src -= 2*srcStride+2;\
- while(w--){\
- asm volatile(\
- "pxor %%mm7, %%mm7 \n\t"\
- "movd (%0), %%mm0 \n\t"\
- "add %2, %0 \n\t"\
- "movd (%0), %%mm1 \n\t"\
- "add %2, %0 \n\t"\
- "movd (%0), %%mm2 \n\t"\
- "add %2, %0 \n\t"\
- "movd (%0), %%mm3 \n\t"\
- "add %2, %0 \n\t"\
- "movd (%0), %%mm4 \n\t"\
- "add %2, %0 \n\t"\
- "punpcklbw %%mm7, %%mm0 \n\t"\
- "punpcklbw %%mm7, %%mm1 \n\t"\
- "punpcklbw %%mm7, %%mm2 \n\t"\
- "punpcklbw %%mm7, %%mm3 \n\t"\
- "punpcklbw %%mm7, %%mm4 \n\t"\
- QPEL_H264HV(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, 0*8*3)\
- QPEL_H264HV(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, 1*8*3)\
- QPEL_H264HV(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, 2*8*3)\
- QPEL_H264HV(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, 3*8*3)\
- \
- : "+a"(src)\
- : "c"(tmp), "S"((long)srcStride), "m"(ff_pw_5)\
- : "memory"\
- );\
- tmp += 4;\
- src += 4 - 9*srcStride;\
- }\
- tmp -= 3*4;\
- asm volatile(\
- "movq %4, %%mm6 \n\t"\
- "1: \n\t"\
- "movq (%0), %%mm0 \n\t"\
- "paddw 10(%0), %%mm0 \n\t"\
- "movq 2(%0), %%mm1 \n\t"\
- "paddw 8(%0), %%mm1 \n\t"\
- "movq 4(%0), %%mm2 \n\t"\
- "paddw 6(%0), %%mm2 \n\t"\
- "psubw %%mm1, %%mm0 \n\t"/*a-b (abccba)*/\
- "psraw $2, %%mm0 \n\t"/*(a-b)/4 */\
- "psubw %%mm1, %%mm0 \n\t"/*(a-b)/4-b */\
- "paddsw %%mm2, %%mm0 \n\t"\
- "psraw $2, %%mm0 \n\t"/*((a-b)/4-b+c)/4 */\
- "paddw %%mm6, %%mm2 \n\t"\
- "paddw %%mm2, %%mm0 \n\t"/*(a-5*b+20*c)/16 +32 */\
- "psraw $6, %%mm0 \n\t"\
- "packuswb %%mm0, %%mm0 \n\t"\
- OP(%%mm0, (%1),%%mm7, d)\
- "add $24, %0 \n\t"\
- "add %3, %1 \n\t"\
- "decl %2 \n\t"\
- " jnz 1b \n\t"\
- : "+a"(tmp), "+c"(dst), "+m"(h)\
- : "S"((long)dstStride), "m"(ff_pw_32)\
- : "memory"\
- );\
-}\
-\
-static void OPNAME ## h264_qpel8_h_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
- int h=8;\
- asm volatile(\
- "pxor %%mm7, %%mm7 \n\t"\
- "movq %5, %%mm6 \n\t"\
- "1: \n\t"\
- "movq (%0), %%mm0 \n\t"\
- "movq 1(%0), %%mm2 \n\t"\
- "movq %%mm0, %%mm1 \n\t"\
- "movq %%mm2, %%mm3 \n\t"\
- "punpcklbw %%mm7, %%mm0 \n\t"\
- "punpckhbw %%mm7, %%mm1 \n\t"\
- "punpcklbw %%mm7, %%mm2 \n\t"\
- "punpckhbw %%mm7, %%mm3 \n\t"\
- "paddw %%mm2, %%mm0 \n\t"\
- "paddw %%mm3, %%mm1 \n\t"\
- "psllw $2, %%mm0 \n\t"\
- "psllw $2, %%mm1 \n\t"\
- "movq -1(%0), %%mm2 \n\t"\
- "movq 2(%0), %%mm4 \n\t"\
- "movq %%mm2, %%mm3 \n\t"\
- "movq %%mm4, %%mm5 \n\t"\
- "punpcklbw %%mm7, %%mm2 \n\t"\
- "punpckhbw %%mm7, %%mm3 \n\t"\
- "punpcklbw %%mm7, %%mm4 \n\t"\
- "punpckhbw %%mm7, %%mm5 \n\t"\
- "paddw %%mm4, %%mm2 \n\t"\
- "paddw %%mm3, %%mm5 \n\t"\
- "psubw %%mm2, %%mm0 \n\t"\
- "psubw %%mm5, %%mm1 \n\t"\
- "pmullw %%mm6, %%mm0 \n\t"\
- "pmullw %%mm6, %%mm1 \n\t"\
- "movd -2(%0), %%mm2 \n\t"\
- "movd 7(%0), %%mm5 \n\t"\
- "punpcklbw %%mm7, %%mm2 \n\t"\
- "punpcklbw %%mm7, %%mm5 \n\t"\
- "paddw %%mm3, %%mm2 \n\t"\
- "paddw %%mm5, %%mm4 \n\t"\
- "movq %6, %%mm5 \n\t"\
- "paddw %%mm5, %%mm2 \n\t"\
- "paddw %%mm5, %%mm4 \n\t"\
- "paddw %%mm2, %%mm0 \n\t"\
- "paddw %%mm4, %%mm1 \n\t"\
- "psraw $5, %%mm0 \n\t"\
- "psraw $5, %%mm1 \n\t"\
- "packuswb %%mm1, %%mm0 \n\t"\
- OP(%%mm0, (%1),%%mm5, q)\
- "add %3, %0 \n\t"\
- "add %4, %1 \n\t"\
- "decl %2 \n\t"\
- " jnz 1b \n\t"\
- : "+a"(src), "+c"(dst), "+m"(h)\
- : "d"((long)srcStride), "S"((long)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\
- : "memory"\
- );\
-}\
-\
-static void OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride){\
- int h=8;\
- asm volatile(\
- "pxor %%mm7, %%mm7 \n\t"\
- "movq %0, %%mm6 \n\t"\
- :: "m"(ff_pw_5)\
- );\
- do{\
- asm volatile(\
- "movq (%0), %%mm0 \n\t"\
- "movq 1(%0), %%mm2 \n\t"\
- "movq %%mm0, %%mm1 \n\t"\
- "movq %%mm2, %%mm3 \n\t"\
- "punpcklbw %%mm7, %%mm0 \n\t"\
- "punpckhbw %%mm7, %%mm1 \n\t"\
- "punpcklbw %%mm7, %%mm2 \n\t"\
- "punpckhbw %%mm7, %%mm3 \n\t"\
- "paddw %%mm2, %%mm0 \n\t"\
- "paddw %%mm3, %%mm1 \n\t"\
- "psllw $2, %%mm0 \n\t"\
- "psllw $2, %%mm1 \n\t"\
- "movq -1(%0), %%mm2 \n\t"\
- "movq 2(%0), %%mm4 \n\t"\
- "movq %%mm2, %%mm3 \n\t"\
- "movq %%mm4, %%mm5 \n\t"\
- "punpcklbw %%mm7, %%mm2 \n\t"\
- "punpckhbw %%mm7, %%mm3 \n\t"\
- "punpcklbw %%mm7, %%mm4 \n\t"\
- "punpckhbw %%mm7, %%mm5 \n\t"\
- "paddw %%mm4, %%mm2 \n\t"\
- "paddw %%mm3, %%mm5 \n\t"\
- "psubw %%mm2, %%mm0 \n\t"\
- "psubw %%mm5, %%mm1 \n\t"\
- "pmullw %%mm6, %%mm0 \n\t"\
- "pmullw %%mm6, %%mm1 \n\t"\
- "movd -2(%0), %%mm2 \n\t"\
- "movd 7(%0), %%mm5 \n\t"\
- "punpcklbw %%mm7, %%mm2 \n\t"\
- "punpcklbw %%mm7, %%mm5 \n\t"\
- "paddw %%mm3, %%mm2 \n\t"\
- "paddw %%mm5, %%mm4 \n\t"\
- "movq %5, %%mm5 \n\t"\
- "paddw %%mm5, %%mm2 \n\t"\
- "paddw %%mm5, %%mm4 \n\t"\
- "paddw %%mm2, %%mm0 \n\t"\
- "paddw %%mm4, %%mm1 \n\t"\
- "psraw $5, %%mm0 \n\t"\
- "psraw $5, %%mm1 \n\t"\
- "movq (%2), %%mm4 \n\t"\
- "packuswb %%mm1, %%mm0 \n\t"\
- PAVGB" %%mm4, %%mm0 \n\t"\
- OP(%%mm0, (%1),%%mm5, q)\
- "add %4, %0 \n\t"\
- "add %4, %1 \n\t"\
- "add %3, %2 \n\t"\
- : "+a"(src), "+c"(dst), "+d"(src2)\
- : "D"((long)src2Stride), "S"((long)dstStride),\
- "m"(ff_pw_16)\
- : "memory"\
- );\
- }while(--h);\
-}\
-\
-static inline void OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
- int w= 2;\
- src -= 2*srcStride;\
- \
- while(w--){\
- asm volatile(\
- "pxor %%mm7, %%mm7 \n\t"\
- "movd (%0), %%mm0 \n\t"\
- "add %2, %0 \n\t"\
- "movd (%0), %%mm1 \n\t"\
- "add %2, %0 \n\t"\
- "movd (%0), %%mm2 \n\t"\
- "add %2, %0 \n\t"\
- "movd (%0), %%mm3 \n\t"\
- "add %2, %0 \n\t"\
- "movd (%0), %%mm4 \n\t"\
- "add %2, %0 \n\t"\
- "punpcklbw %%mm7, %%mm0 \n\t"\
- "punpcklbw %%mm7, %%mm1 \n\t"\
- "punpcklbw %%mm7, %%mm2 \n\t"\
- "punpcklbw %%mm7, %%mm3 \n\t"\
- "punpcklbw %%mm7, %%mm4 \n\t"\
- QPEL_H264V(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP)\
- QPEL_H264V(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP)\
- QPEL_H264V(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP)\
- QPEL_H264V(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP)\
- QPEL_H264V(%%mm4, %%mm5, %%mm0, %%mm1, %%mm2, %%mm3, OP)\
- QPEL_H264V(%%mm5, %%mm0, %%mm1, %%mm2, %%mm3, %%mm4, OP)\
- QPEL_H264V(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP)\
- QPEL_H264V(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP)\
- \
- : "+a"(src), "+c"(dst)\
- : "S"((long)srcStride), "D"((long)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\
- : "memory"\
- );\
- if(h==16){\
- asm volatile(\
- QPEL_H264V(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP)\
- QPEL_H264V(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP)\
- QPEL_H264V(%%mm4, %%mm5, %%mm0, %%mm1, %%mm2, %%mm3, OP)\
- QPEL_H264V(%%mm5, %%mm0, %%mm1, %%mm2, %%mm3, %%mm4, OP)\
- QPEL_H264V(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP)\
- QPEL_H264V(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP)\
- QPEL_H264V(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP)\
- QPEL_H264V(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP)\
- \
- : "+a"(src), "+c"(dst)\
- : "S"((long)srcStride), "D"((long)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\
- : "memory"\
- );\
- }\
- src += 4-(h+5)*srcStride;\
- dst += 4-h*dstStride;\
- }\
-}\
-static inline void OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride, int size){\
- int h = size;\
- int w = (size+8)>>2;\
- src -= 2*srcStride+2;\
- while(w--){\
- asm volatile(\
- "pxor %%mm7, %%mm7 \n\t"\
- "movd (%0), %%mm0 \n\t"\
- "add %2, %0 \n\t"\
- "movd (%0), %%mm1 \n\t"\
- "add %2, %0 \n\t"\
- "movd (%0), %%mm2 \n\t"\
- "add %2, %0 \n\t"\
- "movd (%0), %%mm3 \n\t"\
- "add %2, %0 \n\t"\
- "movd (%0), %%mm4 \n\t"\
- "add %2, %0 \n\t"\
- "punpcklbw %%mm7, %%mm0 \n\t"\
- "punpcklbw %%mm7, %%mm1 \n\t"\
- "punpcklbw %%mm7, %%mm2 \n\t"\
- "punpcklbw %%mm7, %%mm3 \n\t"\
- "punpcklbw %%mm7, %%mm4 \n\t"\
- QPEL_H264HV(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, 0*48)\
- QPEL_H264HV(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, 1*48)\
- QPEL_H264HV(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, 2*48)\
- QPEL_H264HV(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, 3*48)\
- QPEL_H264HV(%%mm4, %%mm5, %%mm0, %%mm1, %%mm2, %%mm3, 4*48)\
- QPEL_H264HV(%%mm5, %%mm0, %%mm1, %%mm2, %%mm3, %%mm4, 5*48)\
- QPEL_H264HV(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, 6*48)\
- QPEL_H264HV(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, 7*48)\
- : "+a"(src)\
- : "c"(tmp), "S"((long)srcStride), "m"(ff_pw_5)\
- : "memory"\
- );\
- if(size==16){\
- asm volatile(\
- QPEL_H264HV(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, 8*48)\
- QPEL_H264HV(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, 9*48)\
- QPEL_H264HV(%%mm4, %%mm5, %%mm0, %%mm1, %%mm2, %%mm3, 10*48)\
- QPEL_H264HV(%%mm5, %%mm0, %%mm1, %%mm2, %%mm3, %%mm4, 11*48)\
- QPEL_H264HV(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, 12*48)\
- QPEL_H264HV(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, 13*48)\
- QPEL_H264HV(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, 14*48)\
- QPEL_H264HV(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, 15*48)\
- : "+a"(src)\
- : "c"(tmp), "S"((long)srcStride), "m"(ff_pw_5)\
- : "memory"\
- );\
- }\
- tmp += 4;\
- src += 4 - (size+5)*srcStride;\
- }\
- tmp -= size+8;\
- w = size>>4;\
- do{\
- h = size;\
- asm volatile(\
- "movq %4, %%mm6 \n\t"\
- "1: \n\t"\
- "movq (%0), %%mm0 \n\t"\
- "movq 8(%0), %%mm3 \n\t"\
- "movq 2(%0), %%mm1 \n\t"\
- "movq 10(%0), %%mm4 \n\t"\
- "paddw %%mm4, %%mm0 \n\t"\
- "paddw %%mm3, %%mm1 \n\t"\
- "paddw 18(%0), %%mm3 \n\t"\
- "paddw 16(%0), %%mm4 \n\t"\
- "movq 4(%0), %%mm2 \n\t"\
- "movq 12(%0), %%mm5 \n\t"\
- "paddw 6(%0), %%mm2 \n\t"\
- "paddw 14(%0), %%mm5 \n\t"\
- "psubw %%mm1, %%mm0 \n\t"\
- "psubw %%mm4, %%mm3 \n\t"\
- "psraw $2, %%mm0 \n\t"\
- "psraw $2, %%mm3 \n\t"\
- "psubw %%mm1, %%mm0 \n\t"\
- "psubw %%mm4, %%mm3 \n\t"\
- "paddsw %%mm2, %%mm0 \n\t"\
- "paddsw %%mm5, %%mm3 \n\t"\
- "psraw $2, %%mm0 \n\t"\
- "psraw $2, %%mm3 \n\t"\
- "paddw %%mm6, %%mm2 \n\t"\
- "paddw %%mm6, %%mm5 \n\t"\
- "paddw %%mm2, %%mm0 \n\t"\
- "paddw %%mm5, %%mm3 \n\t"\
- "psraw $6, %%mm0 \n\t"\
- "psraw $6, %%mm3 \n\t"\
- "packuswb %%mm3, %%mm0 \n\t"\
- OP(%%mm0, (%1),%%mm7, q)\
- "add $48, %0 \n\t"\
- "add %3, %1 \n\t"\
- "decl %2 \n\t"\
- " jnz 1b \n\t"\
- : "+a"(tmp), "+c"(dst), "+m"(h)\
- : "S"((long)dstStride), "m"(ff_pw_32)\
- : "memory"\
- );\
- tmp += 8 - size*24;\
- dst += 8 - size*dstStride;\
- }while(w--);\
-}\
-\
-static void OPNAME ## h264_qpel8_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
- OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst , src , dstStride, srcStride, 8);\
-}\
-static void OPNAME ## h264_qpel16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
- OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst , src , dstStride, srcStride, 16);\
- OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride, 16);\
-}\
-\
-static void OPNAME ## h264_qpel16_h_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
- OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst , src , dstStride, srcStride);\
- OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride);\
- src += 8*srcStride;\
- dst += 8*dstStride;\
- OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst , src , dstStride, srcStride);\
- OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride);\
-}\
-\
-static void OPNAME ## h264_qpel16_h_lowpass_l2_ ## MMX(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride){\
- OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst , src , src2 , dstStride, src2Stride);\
- OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst+8, src+8, src2+8, dstStride, src2Stride);\
- src += 8*dstStride;\
- dst += 8*dstStride;\
- src2 += 8*src2Stride;\
- OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst , src , src2 , dstStride, src2Stride);\
- OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst+8, src+8, src2+8, dstStride, src2Stride);\
-}\
-\
-static void OPNAME ## h264_qpel8_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
- OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(dst , tmp , src , dstStride, tmpStride, srcStride, 8);\
-}\
-\
-static void OPNAME ## h264_qpel16_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
- OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(dst , tmp , src , dstStride, tmpStride, srcStride, 16);\
-}\
-\
-static void OPNAME ## pixels4_l2_shift5_ ## MMX(uint8_t *dst, int16_t *src16, uint8_t *src8, int dstStride, int src8Stride, int h)\
-{\
- asm volatile(\
- "movq %5, %%mm6 \n\t"\
- "movq (%1), %%mm0 \n\t"\
- "movq 24(%1), %%mm1 \n\t"\
- "paddw %%mm6, %%mm0 \n\t"\
- "paddw %%mm6, %%mm1 \n\t"\
- "psraw $5, %%mm0 \n\t"\
- "psraw $5, %%mm1 \n\t"\
- "packuswb %%mm0, %%mm0 \n\t"\
- "packuswb %%mm1, %%mm1 \n\t"\
- PAVGB" (%0), %%mm0 \n\t"\
- PAVGB" (%0,%3), %%mm1 \n\t"\
- OP(%%mm0, (%2), %%mm4, d)\
- OP(%%mm1, (%2,%4), %%mm5, d)\
- "lea (%0,%3,2), %0 \n\t"\
- "lea (%2,%4,2), %2 \n\t"\
- "movq 48(%1), %%mm0 \n\t"\
- "movq 72(%1), %%mm1 \n\t"\
- "paddw %%mm6, %%mm0 \n\t"\
- "paddw %%mm6, %%mm1 \n\t"\
- "psraw $5, %%mm0 \n\t"\
- "psraw $5, %%mm1 \n\t"\
- "packuswb %%mm0, %%mm0 \n\t"\
- "packuswb %%mm1, %%mm1 \n\t"\
- PAVGB" (%0), %%mm0 \n\t"\
- PAVGB" (%0,%3), %%mm1 \n\t"\
- OP(%%mm0, (%2), %%mm4, d)\
- OP(%%mm1, (%2,%4), %%mm5, d)\
- :"+a"(src8), "+c"(src16), "+d"(dst)\
- :"S"((long)src8Stride), "D"((long)dstStride), "m"(ff_pw_16)\
- :"memory");\
-}\
-static void OPNAME ## pixels8_l2_shift5_ ## MMX(uint8_t *dst, int16_t *src16, uint8_t *src8, int dstStride, int src8Stride, int h)\
-{\
- asm volatile(\
- "movq %0, %%mm6 \n\t"\
- ::"m"(ff_pw_16)\
- );\
- while(h--){\
- asm volatile(\
- "movq (%1), %%mm0 \n\t"\
- "movq 8(%1), %%mm1 \n\t"\
- "paddw %%mm6, %%mm0 \n\t"\
- "paddw %%mm6, %%mm1 \n\t"\
- "psraw $5, %%mm0 \n\t"\
- "psraw $5, %%mm1 \n\t"\
- "packuswb %%mm1, %%mm0 \n\t"\
- PAVGB" (%0), %%mm0 \n\t"\
- OP(%%mm0, (%2), %%mm5, q)\
- ::"a"(src8), "c"(src16), "d"(dst)\
- :"memory");\
- src8 += src8Stride;\
- src16 += 24;\
- dst += dstStride;\
- }\
-}\
-static void OPNAME ## pixels16_l2_shift5_ ## MMX(uint8_t *dst, int16_t *src16, uint8_t *src8, int dstStride, int src8Stride, int h)\
-{\
- OPNAME ## pixels8_l2_shift5_ ## MMX(dst , src16 , src8 , dstStride, src8Stride, h);\
- OPNAME ## pixels8_l2_shift5_ ## MMX(dst+8, src16+8, src8+8, dstStride, src8Stride, h);\
-}\
-
-
-#define H264_MC(OPNAME, SIZE, MMX) \
-static void OPNAME ## h264_qpel ## SIZE ## _mc00_ ## MMX (uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## pixels ## SIZE ## _mmx(dst, src, stride, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, src, stride, stride);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc20_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## h264_qpel ## SIZE ## _h_lowpass_ ## MMX(dst, src, stride, stride);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc30_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, src+1, stride, stride);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t temp[SIZE*SIZE/8];\
- uint8_t * const half= (uint8_t*)temp;\
- put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(half, src, SIZE, stride);\
- OPNAME ## pixels ## SIZE ## _l2_ ## MMX(dst, src, half, stride, stride, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## h264_qpel ## SIZE ## _v_lowpass_ ## MMX(dst, src, stride, stride);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t temp[SIZE*SIZE/8];\
- uint8_t * const half= (uint8_t*)temp;\
- put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(half, src, SIZE, stride);\
- OPNAME ## pixels ## SIZE ## _l2_ ## MMX(dst, src+stride, half, stride, stride, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc11_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t temp[SIZE*SIZE/8];\
- uint8_t * const halfV= (uint8_t*)temp;\
- put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(halfV, src, SIZE, stride);\
- OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, halfV, stride, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc31_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t temp[SIZE*SIZE/8];\
- uint8_t * const halfV= (uint8_t*)temp;\
- put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(halfV, src+1, SIZE, stride);\
- OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, halfV, stride, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc13_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t temp[SIZE*SIZE/8];\
- uint8_t * const halfV= (uint8_t*)temp;\
- put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(halfV, src, SIZE, stride);\
- OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src+stride, halfV, stride, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc33_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t temp[SIZE*SIZE/8];\
- uint8_t * const halfV= (uint8_t*)temp;\
- put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(halfV, src+1, SIZE, stride);\
- OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src+stride, halfV, stride, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc22_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t temp[SIZE*(SIZE<8?12:24)/4];\
- int16_t * const tmp= (int16_t*)temp;\
- OPNAME ## h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(dst, tmp, src, stride, SIZE, stride);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc21_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t temp[SIZE*(SIZE<8?12:24)/4 + SIZE*SIZE/8];\
- uint8_t * const halfHV= (uint8_t*)temp;\
- int16_t * const tmp= ((int16_t*)temp) + SIZE*SIZE/2;\
- put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, tmp, src, SIZE, SIZE, stride);\
- OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, halfHV, stride, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t temp[SIZE*(SIZE<8?12:24)/4 + SIZE*SIZE/8];\
- uint8_t * const halfHV= (uint8_t*)temp;\
- int16_t * const tmp= ((int16_t*)temp) + SIZE*SIZE/2;\
- put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, tmp, src, SIZE, SIZE, stride);\
- OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src+stride, halfHV, stride, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc12_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t temp[SIZE*(SIZE<8?12:24)/4 + SIZE*SIZE/8];\
- int16_t * const halfV= ((int16_t*)temp) + SIZE*SIZE/2;\
- uint8_t * const halfHV= ((uint8_t*)temp);\
- put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, halfV, src, SIZE, SIZE, stride);\
- OPNAME ## pixels ## SIZE ## _l2_shift5_ ## MMX(dst, halfV+2, halfHV, stride, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t temp[SIZE*(SIZE<8?12:24)/4 + SIZE*SIZE/8];\
- int16_t * const halfV= ((int16_t*)temp) + SIZE*SIZE/2;\
- uint8_t * const halfHV= ((uint8_t*)temp);\
- put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, halfV, src, SIZE, SIZE, stride);\
- OPNAME ## pixels ## SIZE ## _l2_shift5_ ## MMX(dst, halfV+3, halfHV, stride, SIZE, SIZE);\
-}\
-
-
-#define AVG_3DNOW_OP(a,b,temp, size) \
-"mov" #size " " #b ", " #temp " \n\t"\
-"pavgusb " #temp ", " #a " \n\t"\
-"mov" #size " " #a ", " #b " \n\t"
-#define AVG_MMX2_OP(a,b,temp, size) \
-"mov" #size " " #b ", " #temp " \n\t"\
-"pavgb " #temp ", " #a " \n\t"\
-"mov" #size " " #a ", " #b " \n\t"
-
-#define PAVGB "pavgusb"
-QPEL_H264(put_, PUT_OP, 3dnow)
-QPEL_H264(avg_, AVG_3DNOW_OP, 3dnow)
-#undef PAVGB
-#define PAVGB "pavgb"
-QPEL_H264(put_, PUT_OP, mmx2)
-QPEL_H264(avg_, AVG_MMX2_OP, mmx2)
-#undef PAVGB
-
-H264_MC(put_, 4, 3dnow)
-H264_MC(put_, 8, 3dnow)
-H264_MC(put_, 16,3dnow)
-H264_MC(avg_, 4, 3dnow)
-H264_MC(avg_, 8, 3dnow)
-H264_MC(avg_, 16,3dnow)
-H264_MC(put_, 4, mmx2)
-H264_MC(put_, 8, mmx2)
-H264_MC(put_, 16,mmx2)
-H264_MC(avg_, 4, mmx2)
-H264_MC(avg_, 8, mmx2)
-H264_MC(avg_, 16,mmx2)
-
-
-#define H264_CHROMA_OP(S,D)
-#define H264_CHROMA_OP4(S,D,T)
-#define H264_CHROMA_MC8_TMPL put_h264_chroma_mc8_mmx
-#define H264_CHROMA_MC4_TMPL put_h264_chroma_mc4_mmx
-#define H264_CHROMA_MC2_TMPL put_h264_chroma_mc2_mmx2
-#define H264_CHROMA_MC8_MV0 put_pixels8_mmx
-#include "dsputil_h264_template_mmx.c"
-#undef H264_CHROMA_OP
-#undef H264_CHROMA_OP4
-#undef H264_CHROMA_MC8_TMPL
-#undef H264_CHROMA_MC4_TMPL
-#undef H264_CHROMA_MC2_TMPL
-#undef H264_CHROMA_MC8_MV0
-
-#define H264_CHROMA_OP(S,D) "pavgb " #S ", " #D " \n\t"
-#define H264_CHROMA_OP4(S,D,T) "movd " #S ", " #T " \n\t"\
- "pavgb " #T ", " #D " \n\t"
-#define H264_CHROMA_MC8_TMPL avg_h264_chroma_mc8_mmx2
-#define H264_CHROMA_MC4_TMPL avg_h264_chroma_mc4_mmx2
-#define H264_CHROMA_MC2_TMPL avg_h264_chroma_mc2_mmx2
-#define H264_CHROMA_MC8_MV0 avg_pixels8_mmx2
-#include "dsputil_h264_template_mmx.c"
-#undef H264_CHROMA_OP
-#undef H264_CHROMA_OP4
-#undef H264_CHROMA_MC8_TMPL
-#undef H264_CHROMA_MC4_TMPL
-#undef H264_CHROMA_MC2_TMPL
-#undef H264_CHROMA_MC8_MV0
-
-#define H264_CHROMA_OP(S,D) "pavgusb " #S ", " #D " \n\t"
-#define H264_CHROMA_OP4(S,D,T) "movd " #S ", " #T " \n\t"\
- "pavgusb " #T ", " #D " \n\t"
-#define H264_CHROMA_MC8_TMPL avg_h264_chroma_mc8_3dnow
-#define H264_CHROMA_MC4_TMPL avg_h264_chroma_mc4_3dnow
-#define H264_CHROMA_MC8_MV0 avg_pixels8_3dnow
-#include "dsputil_h264_template_mmx.c"
-#undef H264_CHROMA_OP
-#undef H264_CHROMA_OP4
-#undef H264_CHROMA_MC8_TMPL
-#undef H264_CHROMA_MC4_TMPL
-#undef H264_CHROMA_MC8_MV0
-
-/***********************************/
-/* weighted prediction */
-
-static inline void ff_h264_weight_WxH_mmx2(uint8_t *dst, int stride, int log2_denom, int weight, int offset, int w, int h)
-{
- int x, y;
- offset <<= log2_denom;
- offset += (1 << log2_denom) >> 1;
- asm volatile(
- "movd %0, %%mm4 \n\t"
- "movd %1, %%mm5 \n\t"
- "movd %2, %%mm6 \n\t"
- "pshufw $0, %%mm4, %%mm4 \n\t"
- "pshufw $0, %%mm5, %%mm5 \n\t"
- "pxor %%mm7, %%mm7 \n\t"
- :: "g"(weight), "g"(offset), "g"(log2_denom)
- );
- for(y=0; y<h; y+=2){
- for(x=0; x<w; x+=4){
- asm volatile(
- "movd %0, %%mm0 \n\t"
- "movd %1, %%mm1 \n\t"
- "punpcklbw %%mm7, %%mm0 \n\t"
- "punpcklbw %%mm7, %%mm1 \n\t"
- "pmullw %%mm4, %%mm0 \n\t"
- "pmullw %%mm4, %%mm1 \n\t"
- "paddsw %%mm5, %%mm0 \n\t"
- "paddsw %%mm5, %%mm1 \n\t"
- "psraw %%mm6, %%mm0 \n\t"
- "psraw %%mm6, %%mm1 \n\t"
- "packuswb %%mm7, %%mm0 \n\t"
- "packuswb %%mm7, %%mm1 \n\t"
- "movd %%mm0, %0 \n\t"
- "movd %%mm1, %1 \n\t"
- : "+m"(*(uint32_t*)(dst+x)),
- "+m"(*(uint32_t*)(dst+x+stride))
- );
- }
- dst += 2*stride;
- }
-}
-
-static inline void ff_h264_biweight_WxH_mmx2(uint8_t *dst, uint8_t *src, int stride, int log2_denom, int weightd, int weights, int offset, int w, int h)
-{
- int x, y;
- offset = ((offset + 1) | 1) << log2_denom;
- asm volatile(
- "movd %0, %%mm3 \n\t"
- "movd %1, %%mm4 \n\t"
- "movd %2, %%mm5 \n\t"
- "movd %3, %%mm6 \n\t"
- "pshufw $0, %%mm3, %%mm3 \n\t"
- "pshufw $0, %%mm4, %%mm4 \n\t"
- "pshufw $0, %%mm5, %%mm5 \n\t"
- "pxor %%mm7, %%mm7 \n\t"
- :: "g"(weightd), "g"(weights), "g"(offset), "g"(log2_denom+1)
- );
- for(y=0; y<h; y++){
- for(x=0; x<w; x+=4){
- asm volatile(
- "movd %0, %%mm0 \n\t"
- "movd %1, %%mm1 \n\t"
- "punpcklbw %%mm7, %%mm0 \n\t"
- "punpcklbw %%mm7, %%mm1 \n\t"
- "pmullw %%mm3, %%mm0 \n\t"
- "pmullw %%mm4, %%mm1 \n\t"
- "paddsw %%mm1, %%mm0 \n\t"
- "paddsw %%mm5, %%mm0 \n\t"
- "psraw %%mm6, %%mm0 \n\t"
- "packuswb %%mm0, %%mm0 \n\t"
- "movd %%mm0, %0 \n\t"
- : "+m"(*(uint32_t*)(dst+x))
- : "m"(*(uint32_t*)(src+x))
- );
- }
- src += stride;
- dst += stride;
- }
-}
-
-#define H264_WEIGHT(W,H) \
-static void ff_h264_biweight_ ## W ## x ## H ## _mmx2(uint8_t *dst, uint8_t *src, int stride, int log2_denom, int weightd, int weights, int offset){ \
- ff_h264_biweight_WxH_mmx2(dst, src, stride, log2_denom, weightd, weights, offset, W, H); \
-} \
-static void ff_h264_weight_ ## W ## x ## H ## _mmx2(uint8_t *dst, int stride, int log2_denom, int weight, int offset){ \
- ff_h264_weight_WxH_mmx2(dst, stride, log2_denom, weight, offset, W, H); \
-}
-
-H264_WEIGHT(16,16)
-H264_WEIGHT(16, 8)
-H264_WEIGHT( 8,16)
-H264_WEIGHT( 8, 8)
-H264_WEIGHT( 8, 4)
-H264_WEIGHT( 4, 8)
-H264_WEIGHT( 4, 4)
-H264_WEIGHT( 4, 2)
-
diff --git a/src/libffmpeg/libavcodec/i386/idct_mmx_xvid.c b/src/libffmpeg/libavcodec/i386/idct_mmx_xvid.c
deleted file mode 100644
index 59b255943..000000000
--- a/src/libffmpeg/libavcodec/i386/idct_mmx_xvid.c
+++ /dev/null
@@ -1,535 +0,0 @@
-///****************************************************************************
-// *
-// * XVID MPEG-4 VIDEO CODEC
-// * - MMX and XMM forward discrete cosine transform -
-// *
-// * Copyright(C) 2001 Peter Ross <pross@xvid.org>
-// *
-// * This file is part of FFmpeg.
-// *
-// * FFmpeg is free software; you can redistribute it and/or
-// * modify it under the terms of the GNU Lesser General Public
-// * License as published by the Free Software Foundation; either
-// * version 2.1 of the License, or (at your option) any later version.
-// *
-// * FFmpeg is distributed in the hope that it will be useful,
-// * but WITHOUT ANY WARRANTY; without even the implied warranty of
-// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// * Lesser General Public License for more details.
-// *
-// * You should have received a copy of the GNU Lesser General Public License
-// * along with FFmpeg; if not, write to the Free Software Foundation,
-// * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-// *
-// * $Id: idct_mmx_xvid.c,v 1.4 2006/12/04 22:25:26 miguelfreitas Exp $
-// *
-// ***************************************************************************/
-
-// ****************************************************************************
-//
-// Originally provided by Intel at AP-922
-// http://developer.intel.com/vtune/cbts/strmsimd/922down.htm
-// (See more app notes at http://developer.intel.com/vtune/cbts/strmsimd/appnotes.htm)
-// but in a limited edition.
-// New macro implements a column part for precise iDCT
-// The routine precision now satisfies IEEE standard 1180-1990.
-//
-// Copyright(C) 2000-2001 Peter Gubanov <peter@elecard.net.ru>
-// Rounding trick Copyright(C) 2000 Michel Lespinasse <walken@zoy.org>
-//
-// http://www.elecard.com/peter/idct.html
-// http://www.linuxvideo.org/mpeg2dec/
-//
-// ***************************************************************************/
-//
-// These examples contain code fragments for first stage iDCT 8x8
-// (for rows) and first stage DCT 8x8 (for columns)
-//
-
-// conversion to gcc syntax by michael niedermayer
-
-
-#include <inttypes.h>
-#include "../avcodec.h"
-
-//=============================================================================
-// Macros and other preprocessor constants
-//=============================================================================
-
-#define BITS_INV_ACC 5 // 4 or 5 for IEEE
-#define SHIFT_INV_ROW (16 - BITS_INV_ACC) //11
-#define SHIFT_INV_COL (1 + BITS_INV_ACC) //6
-#define RND_INV_ROW (1024 * (6 - BITS_INV_ACC))
-#define RND_INV_COL (16 * (BITS_INV_ACC - 3))
-#define RND_INV_CORR (RND_INV_COL - 1)
-
-#define BITS_FRW_ACC 3 // 2 or 3 for accuracy
-#define SHIFT_FRW_COL BITS_FRW_ACC
-#define SHIFT_FRW_ROW (BITS_FRW_ACC + 17)
-#define RND_FRW_ROW (262144*(BITS_FRW_ACC - 1))
-
-
-//-----------------------------------------------------------------------------
-// Various memory constants (trigonometric values or rounding values)
-//-----------------------------------------------------------------------------
-
-
-static const int16_t tg_1_16[4*4] attribute_used __attribute__ ((aligned(8))) = {
- 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
-
-static const int32_t rounder_0[2*8] attribute_used __attribute__ ((aligned(8))) = {
- 65536,65536,
- 3597,3597,
- 2260,2260,
- 1203,1203,
- 0,0,
- 120,120,
- 512,512,
- 512,512};
-
-//-----------------------------------------------------------------------------
-//
-// The first stage iDCT 8x8 - inverse DCTs of rows
-//
-//-----------------------------------------------------------------------------
-// The 8-point inverse DCT direct algorithm
-//-----------------------------------------------------------------------------
-//
-// static const short w[32] = {
-// FIX(cos_4_16), FIX(cos_2_16), FIX(cos_4_16), FIX(cos_6_16),
-// FIX(cos_4_16), FIX(cos_6_16), -FIX(cos_4_16), -FIX(cos_2_16),
-// FIX(cos_4_16), -FIX(cos_6_16), -FIX(cos_4_16), FIX(cos_2_16),
-// FIX(cos_4_16), -FIX(cos_2_16), FIX(cos_4_16), -FIX(cos_6_16),
-// FIX(cos_1_16), FIX(cos_3_16), FIX(cos_5_16), FIX(cos_7_16),
-// FIX(cos_3_16), -FIX(cos_7_16), -FIX(cos_1_16), -FIX(cos_5_16),
-// FIX(cos_5_16), -FIX(cos_1_16), FIX(cos_7_16), FIX(cos_3_16),
-// FIX(cos_7_16), -FIX(cos_5_16), FIX(cos_3_16), -FIX(cos_1_16) };
-//
-// #define DCT_8_INV_ROW(x, y)
-// {
-// int a0, a1, a2, a3, b0, b1, b2, b3;
-//
-// a0 =x[0]*w[0]+x[2]*w[1]+x[4]*w[2]+x[6]*w[3];
-// a1 =x[0]*w[4]+x[2]*w[5]+x[4]*w[6]+x[6]*w[7];
-// a2 = x[0] * w[ 8] + x[2] * w[ 9] + x[4] * w[10] + x[6] * w[11];
-// a3 = x[0] * w[12] + x[2] * w[13] + x[4] * w[14] + x[6] * w[15];
-// b0 = x[1] * w[16] + x[3] * w[17] + x[5] * w[18] + x[7] * w[19];
-// b1 = x[1] * w[20] + x[3] * w[21] + x[5] * w[22] + x[7] * w[23];
-// b2 = x[1] * w[24] + x[3] * w[25] + x[5] * w[26] + x[7] * w[27];
-// b3 = x[1] * w[28] + x[3] * w[29] + x[5] * w[30] + x[7] * w[31];
-//
-// y[0] = SHIFT_ROUND ( a0 + b0 );
-// y[1] = SHIFT_ROUND ( a1 + b1 );
-// y[2] = SHIFT_ROUND ( a2 + b2 );
-// y[3] = SHIFT_ROUND ( a3 + b3 );
-// y[4] = SHIFT_ROUND ( a3 - b3 );
-// y[5] = SHIFT_ROUND ( a2 - b2 );
-// y[6] = SHIFT_ROUND ( a1 - b1 );
-// y[7] = SHIFT_ROUND ( a0 - b0 );
-// }
-//
-//-----------------------------------------------------------------------------
-//
-// In this implementation the outputs of the iDCT-1D are multiplied
-// for rows 0,4 - by cos_4_16,
-// for rows 1,7 - by cos_1_16,
-// for rows 2,6 - by cos_2_16,
-// for rows 3,5 - by cos_3_16
-// and are shifted to the left for better accuracy
-//
-// For the constants used,
-// FIX(float_const) = (short) (float_const * (1<<15) + 0.5)
-//
-//-----------------------------------------------------------------------------
-
-//-----------------------------------------------------------------------------
-// Tables for mmx processors
-//-----------------------------------------------------------------------------
-
-// Table for rows 0,4 - constants are multiplied by cos_4_16
-static const int16_t tab_i_04_mmx[32*4] attribute_used __attribute__ ((aligned(8))) = {
- 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
- -8867,21407,-21407,-8867, // w15 w13 w11 w09
- 22725,12873,19266,-22725, // w22 w20 w18 w16
- 19266,4520,-4520,-12873, // w23 w21 w19 w17
- 12873,4520,4520,19266, // w30 w28 w26 w24
- -22725,19266,-12873,-22725, // w31 w29 w27 w25
-// Table for rows 1,7 - constants are multiplied by cos_1_16
- 22725,22725,22725,-22725, // movq-> w06 w04 w02 w00
- 29692,12299,12299,-29692, // w07 w05 w03 w01
- 22725,-22725,22725,22725, // w14 w12 w10 w08
- -12299,29692,-29692,-12299, // w15 w13 w11 w09
- 31521,17855,26722,-31521, // w22 w20 w18 w16
- 26722,6270,-6270,-17855, // w23 w21 w19 w17
- 17855,6270,6270,26722, // w30 w28 w26 w24
- -31521,26722,-17855,-31521, // w31 w29 w27 w25
-// Table for rows 2,6 - constants are multiplied by cos_2_16
- 21407,21407,21407,-21407, // movq-> w06 w04 w02 w00
- 27969,11585,11585,-27969, // w07 w05 w03 w01
- 21407,-21407,21407,21407, // w14 w12 w10 w08
- -11585,27969,-27969,-11585, // w15 w13 w11 w09
- 29692,16819,25172,-29692, // w22 w20 w18 w16
- 25172,5906,-5906,-16819, // w23 w21 w19 w17
- 16819,5906,5906,25172, // w30 w28 w26 w24
- -29692,25172,-16819,-29692, // w31 w29 w27 w25
-// Table for rows 3,5 - constants are multiplied by cos_3_16
- 19266,19266,19266,-19266, // movq-> w06 w04 w02 w00
- 25172,10426,10426,-25172, // w07 w05 w03 w01
- 19266,-19266,19266,19266, // w14 w12 w10 w08
- -10426,25172,-25172,-10426, // w15 w13 w11 w09
- 26722,15137,22654,-26722, // w22 w20 w18 w16
- 22654,5315,-5315,-15137, // w23 w21 w19 w17
- 15137,5315,5315,22654, // w30 w28 w26 w24
- -26722,22654,-15137,-26722, // w31 w29 w27 w25
-};
-//-----------------------------------------------------------------------------
-// Tables for xmm processors
-//-----------------------------------------------------------------------------
-
-// %3 for rows 0,4 - constants are multiplied by cos_4_16
-static const int16_t tab_i_04_xmm[32*4] attribute_used __attribute__ ((aligned(8))) = {
- 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
- -16384,21407,16384,-8867, // w15 w14 w11 w10
- 22725,19266,19266,-4520, // w21 w20 w17 w16
- 12873,4520,-22725,-12873, // w23 w22 w19 w18
- 12873,-22725,4520,-12873, // w29 w28 w25 w24
- 4520,19266,19266,-22725, // w31 w30 w27 w26
-// %3 for rows 1,7 - constants are multiplied by cos_1_16
- 22725,29692,22725,12299, // movq-> w05 w04 w01 w00
- 22725,12299,-22725,-29692, // w07 w06 w03 w02
- 22725,-12299,22725,-29692, // w13 w12 w09 w08
- -22725,29692,22725,-12299, // w15 w14 w11 w10
- 31521,26722,26722,-6270, // w21 w20 w17 w16
- 17855,6270,-31521,-17855, // w23 w22 w19 w18
- 17855,-31521,6270,-17855, // w29 w28 w25 w24
- 6270,26722,26722,-31521, // w31 w30 w27 w26
-// %3 for rows 2,6 - constants are multiplied by cos_2_16
- 21407,27969,21407,11585, // movq-> w05 w04 w01 w00
- 21407,11585,-21407,-27969, // w07 w06 w03 w02
- 21407,-11585,21407,-27969, // w13 w12 w09 w08
- -21407,27969,21407,-11585, // w15 w14 w11 w10
- 29692,25172,25172,-5906, // w21 w20 w17 w16
- 16819,5906,-29692,-16819, // w23 w22 w19 w18
- 16819,-29692,5906,-16819, // w29 w28 w25 w24
- 5906,25172,25172,-29692, // w31 w30 w27 w26
-// %3 for rows 3,5 - constants are multiplied by cos_3_16
- 19266,25172,19266,10426, // movq-> w05 w04 w01 w00
- 19266,10426,-19266,-25172, // w07 w06 w03 w02
- 19266,-10426,19266,-25172, // w13 w12 w09 w08
- -19266,25172,19266,-10426, // w15 w14 w11 w10
- 26722,22654,22654,-5315, // w21 w20 w17 w16
- 15137,5315,-26722,-15137, // w23 w22 w19 w18
- 15137,-26722,5315,-15137, // w29 w28 w25 w24
- 5315,22654,22654,-26722, // w31 w30 w27 w26
-};
-//=============================================================================
-// Helper macros for the code
-//=============================================================================
-
-//-----------------------------------------------------------------------------
-// DCT_8_INV_ROW_MMX( INP, OUT, TABLE, ROUNDER
-//-----------------------------------------------------------------------------
-
-#define DCT_8_INV_ROW_MMX(A1,A2,A3,A4)\
- "movq " #A1 ",%%mm0 \n\t"/* 0 ; x3 x2 x1 x0*/\
- "movq 8+" #A1 ",%%mm1 \n\t"/* 1 ; x7 x6 x5 x4*/\
- "movq %%mm0,%%mm2 \n\t"/* 2 ; x3 x2 x1 x0*/\
- "movq " #A3 ",%%mm3 \n\t"/* 3 ; w06 w04 w02 w00*/\
- "punpcklwd %%mm1,%%mm0 \n\t"/* x5 x1 x4 x0*/\
- "movq %%mm0,%%mm5 \n\t"/* 5 ; x5 x1 x4 x0*/\
- "punpckldq %%mm0,%%mm0 \n\t"/* x4 x0 x4 x0*/\
- "movq 8+" #A3 ",%%mm4 \n\t"/* 4 ; w07 w05 w03 w01*/\
- "punpckhwd %%mm1,%%mm2 \n\t"/* 1 ; x7 x3 x6 x2*/\
- "pmaddwd %%mm0,%%mm3 \n\t"/* x4*w06+x0*w04 x4*w02+x0*w00*/\
- "movq %%mm2,%%mm6 \n\t"/* 6 ; x7 x3 x6 x2*/\
- "movq 32+" #A3 ",%%mm1 \n\t"/* 1 ; w22 w20 w18 w16*/\
- "punpckldq %%mm2,%%mm2 \n\t"/* x6 x2 x6 x2*/\
- "pmaddwd %%mm2,%%mm4 \n\t"/* x6*w07+x2*w05 x6*w03+x2*w01*/\
- "punpckhdq %%mm5,%%mm5 \n\t"/* x5 x1 x5 x1*/\
- "pmaddwd 16+" #A3 ",%%mm0 \n\t"/* x4*w14+x0*w12 x4*w10+x0*w08*/\
- "punpckhdq %%mm6,%%mm6 \n\t"/* x7 x3 x7 x3*/\
- "movq 40+" #A3 ",%%mm7 \n\t"/* 7 ; w23 w21 w19 w17*/\
- "pmaddwd %%mm5,%%mm1 \n\t"/* x5*w22+x1*w20 x5*w18+x1*w16*/\
- "paddd " #A4 ",%%mm3 \n\t"/* +%4*/\
- "pmaddwd %%mm6,%%mm7 \n\t"/* x7*w23+x3*w21 x7*w19+x3*w17*/\
- "pmaddwd 24+" #A3 ",%%mm2 \n\t"/* x6*w15+x2*w13 x6*w11+x2*w09*/\
- "paddd %%mm4,%%mm3 \n\t"/* 4 ; a1=sum(even1) a0=sum(even0)*/\
- "pmaddwd 48+" #A3 ",%%mm5 \n\t"/* x5*w30+x1*w28 x5*w26+x1*w24*/\
- "movq %%mm3,%%mm4 \n\t"/* 4 ; a1 a0*/\
- "pmaddwd 56+" #A3 ",%%mm6 \n\t"/* x7*w31+x3*w29 x7*w27+x3*w25*/\
- "paddd %%mm7,%%mm1 \n\t"/* 7 ; b1=sum(odd1) b0=sum(odd0)*/\
- "paddd " #A4 ",%%mm0 \n\t"/* +%4*/\
- "psubd %%mm1,%%mm3 \n\t"/* a1-b1 a0-b0*/\
- "psrad $11,%%mm3 \n\t"/* y6=a1-b1 y7=a0-b0*/\
- "paddd %%mm4,%%mm1 \n\t"/* 4 ; a1+b1 a0+b0*/\
- "paddd %%mm2,%%mm0 \n\t"/* 2 ; a3=sum(even3) a2=sum(even2)*/\
- "psrad $11,%%mm1 \n\t"/* y1=a1+b1 y0=a0+b0*/\
- "paddd %%mm6,%%mm5 \n\t"/* 6 ; b3=sum(odd3) b2=sum(odd2)*/\
- "movq %%mm0,%%mm4 \n\t"/* 4 ; a3 a2*/\
- "paddd %%mm5,%%mm0 \n\t"/* a3+b3 a2+b2*/\
- "psubd %%mm5,%%mm4 \n\t"/* 5 ; a3-b3 a2-b2*/\
- "psrad $11,%%mm0 \n\t"/* y3=a3+b3 y2=a2+b2*/\
- "psrad $11,%%mm4 \n\t"/* y4=a3-b3 y5=a2-b2*/\
- "packssdw %%mm0,%%mm1 \n\t"/* 0 ; y3 y2 y1 y0*/\
- "packssdw %%mm3,%%mm4 \n\t"/* 3 ; y6 y7 y4 y5*/\
- "movq %%mm4,%%mm7 \n\t"/* 7 ; y6 y7 y4 y5*/\
- "psrld $16,%%mm4 \n\t"/* 0 y6 0 y4*/\
- "pslld $16,%%mm7 \n\t"/* y7 0 y5 0*/\
- "movq %%mm1," #A2 " \n\t"/* 1 ; save y3 y2 y1 y0*/\
- "por %%mm4,%%mm7 \n\t"/* 4 ; y7 y6 y5 y4*/\
- "movq %%mm7,8 +" #A2 "\n\t"/* 7 ; save y7 y6 y5 y4*/\
-
-
-//-----------------------------------------------------------------------------
-// DCT_8_INV_ROW_XMM( INP, OUT, TABLE, ROUNDER
-//-----------------------------------------------------------------------------
-
-#define DCT_8_INV_ROW_XMM(A1,A2,A3,A4)\
- "movq " #A1 ",%%mm0 \n\t"/* 0 ; x3 x2 x1 x0*/\
- "movq 8+" #A1 ",%%mm1 \n\t"/* 1 ; x7 x6 x5 x4*/\
- "movq %%mm0,%%mm2 \n\t"/* 2 ; x3 x2 x1 x0*/\
- "movq " #A3 ",%%mm3 \n\t"/* 3 ; w05 w04 w01 w00*/\
- "pshufw $0x88,%%mm0,%%mm0 \n\t"/* x2 x0 x2 x0*/\
- "movq 8+" #A3 ",%%mm4 \n\t"/* 4 ; w07 w06 w03 w02*/\
- "movq %%mm1,%%mm5 \n\t"/* 5 ; x7 x6 x5 x4*/\
- "pmaddwd %%mm0,%%mm3 \n\t"/* x2*w05+x0*w04 x2*w01+x0*w00*/\
- "movq 32+" #A3 ",%%mm6 \n\t"/* 6 ; w21 w20 w17 w16*/\
- "pshufw $0x88,%%mm1,%%mm1 \n\t"/* x6 x4 x6 x4*/\
- "pmaddwd %%mm1,%%mm4 \n\t"/* x6*w07+x4*w06 x6*w03+x4*w02*/\
- "movq 40+" #A3 ",%%mm7 \n\t"/* 7 ; w23 w22 w19 w18*/\
- "pshufw $0xdd,%%mm2,%%mm2 \n\t"/* x3 x1 x3 x1*/\
- "pmaddwd %%mm2,%%mm6 \n\t"/* x3*w21+x1*w20 x3*w17+x1*w16*/\
- "pshufw $0xdd,%%mm5,%%mm5 \n\t"/* x7 x5 x7 x5*/\
- "pmaddwd %%mm5,%%mm7 \n\t"/* x7*w23+x5*w22 x7*w19+x5*w18*/\
- "paddd " #A4 ",%%mm3 \n\t"/* +%4*/\
- "pmaddwd 16+" #A3 ",%%mm0 \n\t"/* x2*w13+x0*w12 x2*w09+x0*w08*/\
- "paddd %%mm4,%%mm3 \n\t"/* 4 ; a1=sum(even1) a0=sum(even0)*/\
- "pmaddwd 24+" #A3 ",%%mm1 \n\t"/* x6*w15+x4*w14 x6*w11+x4*w10*/\
- "movq %%mm3,%%mm4 \n\t"/* 4 ; a1 a0*/\
- "pmaddwd 48+" #A3 ",%%mm2 \n\t"/* x3*w29+x1*w28 x3*w25+x1*w24*/\
- "paddd %%mm7,%%mm6 \n\t"/* 7 ; b1=sum(odd1) b0=sum(odd0)*/\
- "pmaddwd 56+" #A3 ",%%mm5 \n\t"/* x7*w31+x5*w30 x7*w27+x5*w26*/\
- "paddd %%mm6,%%mm3 \n\t"/* a1+b1 a0+b0*/\
- "paddd " #A4 ",%%mm0 \n\t"/* +%4*/\
- "psrad $11,%%mm3 \n\t"/* y1=a1+b1 y0=a0+b0*/\
- "paddd %%mm1,%%mm0 \n\t"/* 1 ; a3=sum(even3) a2=sum(even2)*/\
- "psubd %%mm6,%%mm4 \n\t"/* 6 ; a1-b1 a0-b0*/\
- "movq %%mm0,%%mm7 \n\t"/* 7 ; a3 a2*/\
- "paddd %%mm5,%%mm2 \n\t"/* 5 ; b3=sum(odd3) b2=sum(odd2)*/\
- "paddd %%mm2,%%mm0 \n\t"/* a3+b3 a2+b2*/\
- "psrad $11,%%mm4 \n\t"/* y6=a1-b1 y7=a0-b0*/\
- "psubd %%mm2,%%mm7 \n\t"/* 2 ; a3-b3 a2-b2*/\
- "psrad $11,%%mm0 \n\t"/* y3=a3+b3 y2=a2+b2*/\
- "psrad $11,%%mm7 \n\t"/* y4=a3-b3 y5=a2-b2*/\
- "packssdw %%mm0,%%mm3 \n\t"/* 0 ; y3 y2 y1 y0*/\
- "packssdw %%mm4,%%mm7 \n\t"/* 4 ; y6 y7 y4 y5*/\
- "movq %%mm3, " #A2 " \n\t"/* 3 ; save y3 y2 y1 y0*/\
- "pshufw $0xb1,%%mm7,%%mm7 \n\t"/* y7 y6 y5 y4*/\
- "movq %%mm7,8 +" #A2 "\n\t"/* 7 ; save y7 y6 y5 y4*/\
-
-
-//-----------------------------------------------------------------------------
-//
-// The first stage DCT 8x8 - forward DCTs of columns
-//
-// The %2puts are multiplied
-// for rows 0,4 - on cos_4_16,
-// for rows 1,7 - on cos_1_16,
-// for rows 2,6 - on cos_2_16,
-// for rows 3,5 - on cos_3_16
-// and are shifted to the left for rise of accuracy
-//
-//-----------------------------------------------------------------------------
-//
-// The 8-point scaled forward DCT algorithm (26a8m)
-//
-//-----------------------------------------------------------------------------
-//
-// #define DCT_8_FRW_COL(x, y)
-//{
-// short t0, t1, t2, t3, t4, t5, t6, t7;
-// short tp03, tm03, tp12, tm12, tp65, tm65;
-// short tp465, tm465, tp765, tm765;
-//
-// t0 = LEFT_SHIFT ( x[0] + x[7] );
-// t1 = LEFT_SHIFT ( x[1] + x[6] );
-// t2 = LEFT_SHIFT ( x[2] + x[5] );
-// t3 = LEFT_SHIFT ( x[3] + x[4] );
-// t4 = LEFT_SHIFT ( x[3] - x[4] );
-// t5 = LEFT_SHIFT ( x[2] - x[5] );
-// t6 = LEFT_SHIFT ( x[1] - x[6] );
-// t7 = LEFT_SHIFT ( x[0] - x[7] );
-//
-// tp03 = t0 + t3;
-// tm03 = t0 - t3;
-// tp12 = t1 + t2;
-// tm12 = t1 - t2;
-//
-// y[0] = tp03 + tp12;
-// y[4] = tp03 - tp12;
-//
-// y[2] = tm03 + tm12 * tg_2_16;
-// y[6] = tm03 * tg_2_16 - tm12;
-//
-// tp65 =(t6 +t5 )*cos_4_16;
-// tm65 =(t6 -t5 )*cos_4_16;
-//
-// tp765 = t7 + tp65;
-// tm765 = t7 - tp65;
-// tp465 = t4 + tm65;
-// tm465 = t4 - tm65;
-//
-// y[1] = tp765 + tp465 * tg_1_16;
-// y[7] = tp765 * tg_1_16 - tp465;
-// y[5] = tm765 * tg_3_16 + tm465;
-// y[3] = tm765 - tm465 * tg_3_16;
-//}
-//
-//-----------------------------------------------------------------------------
-
-//-----------------------------------------------------------------------------
-// DCT_8_INV_COL_4 INP,OUT
-//-----------------------------------------------------------------------------
-
-#define DCT_8_INV_COL(A1,A2)\
- "movq 2*8(%3),%%mm0\n\t"\
- "movq 16*3+" #A1 ",%%mm3\n\t"\
- "movq %%mm0,%%mm1 \n\t"/* tg_3_16*/\
- "movq 16*5+" #A1 ",%%mm5\n\t"\
- "pmulhw %%mm3,%%mm0 \n\t"/* x3*(tg_3_16-1)*/\
- "movq (%3),%%mm4\n\t"\
- "pmulhw %%mm5,%%mm1 \n\t"/* x5*(tg_3_16-1)*/\
- "movq 16*7+" #A1 ",%%mm7\n\t"\
- "movq %%mm4,%%mm2 \n\t"/* tg_1_16*/\
- "movq 16*1+" #A1 ",%%mm6\n\t"\
- "pmulhw %%mm7,%%mm4 \n\t"/* x7*tg_1_16*/\
- "paddsw %%mm3,%%mm0 \n\t"/* x3*tg_3_16*/\
- "pmulhw %%mm6,%%mm2 \n\t"/* x1*tg_1_16*/\
- "paddsw %%mm3,%%mm1 \n\t"/* x3+x5*(tg_3_16-1)*/\
- "psubsw %%mm5,%%mm0 \n\t"/* x3*tg_3_16-x5 = tm35*/\
- "movq 3*8(%3),%%mm3\n\t"\
- "paddsw %%mm5,%%mm1 \n\t"/* x3+x5*tg_3_16 = tp35*/\
- "paddsw %%mm6,%%mm4 \n\t"/* x1+tg_1_16*x7 = tp17*/\
- "psubsw %%mm7,%%mm2 \n\t"/* x1*tg_1_16-x7 = tm17*/\
- "movq %%mm4,%%mm5 \n\t"/* tp17*/\
- "movq %%mm2,%%mm6 \n\t"/* tm17*/\
- "paddsw %%mm1,%%mm5 \n\t"/* tp17+tp35 = b0*/\
- "psubsw %%mm0,%%mm6 \n\t"/* tm17-tm35 = b3*/\
- "psubsw %%mm1,%%mm4 \n\t"/* tp17-tp35 = t1*/\
- "paddsw %%mm0,%%mm2 \n\t"/* tm17+tm35 = t2*/\
- "movq 1*8(%3),%%mm7\n\t"\
- "movq %%mm4,%%mm1 \n\t"/* t1*/\
- "movq %%mm5,3*16 +" #A2 "\n\t"/* save b0*/\
- "paddsw %%mm2,%%mm1 \n\t"/* t1+t2*/\
- "movq %%mm6,5*16 +" #A2 "\n\t"/* save b3*/\
- "psubsw %%mm2,%%mm4 \n\t"/* t1-t2*/\
- "movq 2*16+" #A1 ",%%mm5\n\t"\
- "movq %%mm7,%%mm0 \n\t"/* tg_2_16*/\
- "movq 6*16+" #A1 ",%%mm6\n\t"\
- "pmulhw %%mm5,%%mm0 \n\t"/* x2*tg_2_16*/\
- "pmulhw %%mm6,%%mm7 \n\t"/* x6*tg_2_16*/\
- "pmulhw %%mm3,%%mm1 \n\t"/* ocos_4_16*(t1+t2) = b1/2*/\
- "movq 0*16+" #A1 ",%%mm2\n\t"\
- "pmulhw %%mm3,%%mm4 \n\t"/* ocos_4_16*(t1-t2) = b2/2*/\
- "psubsw %%mm6,%%mm0 \n\t"/* t2*tg_2_16-x6 = tm26*/\
- "movq %%mm2,%%mm3 \n\t"/* x0*/\
- "movq 4*16+" #A1 ",%%mm6\n\t"\
- "paddsw %%mm5,%%mm7 \n\t"/* x2+x6*tg_2_16 = tp26*/\
- "paddsw %%mm6,%%mm2 \n\t"/* x0+x4 = tp04*/\
- "psubsw %%mm6,%%mm3 \n\t"/* x0-x4 = tm04*/\
- "movq %%mm2,%%mm5 \n\t"/* tp04*/\
- "movq %%mm3,%%mm6 \n\t"/* tm04*/\
- "psubsw %%mm7,%%mm2 \n\t"/* tp04-tp26 = a3*/\
- "paddsw %%mm0,%%mm3 \n\t"/* tm04+tm26 = a1*/\
- "paddsw %%mm1,%%mm1 \n\t"/* b1*/\
- "paddsw %%mm4,%%mm4 \n\t"/* b2*/\
- "paddsw %%mm7,%%mm5 \n\t"/* tp04+tp26 = a0*/\
- "psubsw %%mm0,%%mm6 \n\t"/* tm04-tm26 = a2*/\
- "movq %%mm3,%%mm7 \n\t"/* a1*/\
- "movq %%mm6,%%mm0 \n\t"/* a2*/\
- "paddsw %%mm1,%%mm3 \n\t"/* a1+b1*/\
- "paddsw %%mm4,%%mm6 \n\t"/* a2+b2*/\
- "psraw $6,%%mm3 \n\t"/* dst1*/\
- "psubsw %%mm1,%%mm7 \n\t"/* a1-b1*/\
- "psraw $6,%%mm6 \n\t"/* dst2*/\
- "psubsw %%mm4,%%mm0 \n\t"/* a2-b2*/\
- "movq 3*16+" #A2 ",%%mm1 \n\t"/* load b0*/\
- "psraw $6,%%mm7 \n\t"/* dst6*/\
- "movq %%mm5,%%mm4 \n\t"/* a0*/\
- "psraw $6,%%mm0 \n\t"/* dst5*/\
- "movq %%mm3,1*16+" #A2 "\n\t"\
- "paddsw %%mm1,%%mm5 \n\t"/* a0+b0*/\
- "movq %%mm6,2*16+" #A2 "\n\t"\
- "psubsw %%mm1,%%mm4 \n\t"/* a0-b0*/\
- "movq 5*16+" #A2 ",%%mm3 \n\t"/* load b3*/\
- "psraw $6,%%mm5 \n\t"/* dst0*/\
- "movq %%mm2,%%mm6 \n\t"/* a3*/\
- "psraw $6,%%mm4 \n\t"/* dst7*/\
- "movq %%mm0,5*16+" #A2 "\n\t"\
- "paddsw %%mm3,%%mm2 \n\t"/* a3+b3*/\
- "movq %%mm7,6*16+" #A2 "\n\t"\
- "psubsw %%mm3,%%mm6 \n\t"/* a3-b3*/\
- "movq %%mm5,0*16+" #A2 "\n\t"\
- "psraw $6,%%mm2 \n\t"/* dst3*/\
- "movq %%mm4,7*16+" #A2 "\n\t"\
- "psraw $6,%%mm6 \n\t"/* dst4*/\
- "movq %%mm2,3*16+" #A2 "\n\t"\
- "movq %%mm6,4*16+" #A2 "\n\t"
-
-//=============================================================================
-// Code
-//=============================================================================
-
-//-----------------------------------------------------------------------------
-// void idct_mmx(uint16_t block[64]);
-//-----------------------------------------------------------------------------
-
-
-void ff_idct_xvid_mmx(short *block){
-asm volatile(
- //# Process each row
- DCT_8_INV_ROW_MMX(0*16(%0), 0*16(%0), 64*0(%2), 8*0(%1))
- DCT_8_INV_ROW_MMX(1*16(%0), 1*16(%0), 64*1(%2), 8*1(%1))
- DCT_8_INV_ROW_MMX(2*16(%0), 2*16(%0), 64*2(%2), 8*2(%1))
- DCT_8_INV_ROW_MMX(3*16(%0), 3*16(%0), 64*3(%2), 8*3(%1))
- DCT_8_INV_ROW_MMX(4*16(%0), 4*16(%0), 64*0(%2), 8*4(%1))
- DCT_8_INV_ROW_MMX(5*16(%0), 5*16(%0), 64*3(%2), 8*5(%1))
- DCT_8_INV_ROW_MMX(6*16(%0), 6*16(%0), 64*2(%2), 8*6(%1))
- DCT_8_INV_ROW_MMX(7*16(%0), 7*16(%0), 64*1(%2), 8*7(%1))
-
- //# Process the columns (4 at a time)
- DCT_8_INV_COL(0(%0), 0(%0))
- DCT_8_INV_COL(8(%0), 8(%0))
- :: "r"(block), "r"(rounder_0), "r"(tab_i_04_mmx), "r"(tg_1_16));
-}
-
-//-----------------------------------------------------------------------------
-// void idct_xmm(uint16_t block[64]);
-//-----------------------------------------------------------------------------
-
-
-void ff_idct_xvid_mmx2(short *block){
-asm volatile(
- //# Process each row
- DCT_8_INV_ROW_XMM(0*16(%0), 0*16(%0), 64*0(%2), 8*0(%1))
- DCT_8_INV_ROW_XMM(1*16(%0), 1*16(%0), 64*1(%2), 8*1(%1))
- DCT_8_INV_ROW_XMM(2*16(%0), 2*16(%0), 64*2(%2), 8*2(%1))
- DCT_8_INV_ROW_XMM(3*16(%0), 3*16(%0), 64*3(%2), 8*3(%1))
- DCT_8_INV_ROW_XMM(4*16(%0), 4*16(%0), 64*0(%2), 8*4(%1))
- DCT_8_INV_ROW_XMM(5*16(%0), 5*16(%0), 64*3(%2), 8*5(%1))
- DCT_8_INV_ROW_XMM(6*16(%0), 6*16(%0), 64*2(%2), 8*6(%1))
- DCT_8_INV_ROW_XMM(7*16(%0), 7*16(%0), 64*1(%2), 8*7(%1))
-
- //# Process the columns (4 at a time)
- DCT_8_INV_COL(0(%0), 0(%0))
- DCT_8_INV_COL(8(%0), 8(%0))
- :: "r"(block), "r"(rounder_0), "r"(tab_i_04_xmm), "r"(tg_1_16));
-}
-
diff --git a/src/libffmpeg/libavcodec/i386/libavcodec_mmx_dummy.c b/src/libffmpeg/libavcodec/i386/libavcodec_mmx_dummy.c
deleted file mode 100644
index 04a6fc298..000000000
--- a/src/libffmpeg/libavcodec/i386/libavcodec_mmx_dummy.c
+++ /dev/null
@@ -1,2 +0,0 @@
-
-char libavcodec_mmx_dummy;
diff --git a/src/libffmpeg/libavcodec/imgconvert.c b/src/libffmpeg/libavcodec/imgconvert.c
deleted file mode 100644
index b2305cd63..000000000
--- a/src/libffmpeg/libavcodec/imgconvert.c
+++ /dev/null
@@ -1,2855 +0,0 @@
-/*
- * Misc image convertion routines
- * Copyright (c) 2001, 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
- */
-
-/**
- * @file imgconvert.c
- * Misc image convertion routines.
- */
-
-/* TODO:
- * - write 'ffimg' program to test all the image related stuff
- * - move all api to slice based system
- * - integrate deinterlacing, postprocessing and scaling in the conversion process
- */
-
-#include "avcodec.h"
-#include "dsputil.h"
-
-#ifdef USE_FASTMEMCPY
-#include "libvo/fastmemcpy.h"
-#endif
-
-#ifdef HAVE_MMX
-#include "i386/mmx.h"
-#endif
-
-#define xglue(x, y) x ## y
-#define glue(x, y) xglue(x, y)
-
-#define FF_COLOR_RGB 0 /* RGB color space */
-#define FF_COLOR_GRAY 1 /* gray color space */
-#define FF_COLOR_YUV 2 /* YUV color space. 16 <= Y <= 235, 16 <= U, V <= 240 */
-#define FF_COLOR_YUV_JPEG 3 /* YUV color space. 0 <= Y <= 255, 0 <= U, V <= 255 */
-
-#define FF_PIXEL_PLANAR 0 /* each channel has one component in AVPicture */
-#define FF_PIXEL_PACKED 1 /* only one components containing all the channels */
-#define FF_PIXEL_PALETTE 2 /* one components containing indexes for a palette */
-
-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 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;
-
-/* this table gives more information about formats */
-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_YUV422] = {
- .name = "yuv422",
- .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,
- },
-
- /* 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,
- },
-
- /* 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_RGBA32] = {
- .name = "rgba32",
- .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_RGB565] = {
- .name = "rgb565",
- .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_RGB555] = {
- .name = "rgb555",
- .nb_channels = 3,
- .color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 5,
- .x_chroma_shift = 0, .y_chroma_shift = 0,
- },
-
- /* 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,
- .depth = 1,
- },
-
- /* 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",
- },
- [PIX_FMT_XVMC_MPEG2_IDCT] = {
- .name = "xvmcidct",
- },
- [PIX_FMT_UYVY411] = {
- .name = "uyvy411",
- .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_BGR32] = {
- .name = "bgr32",
- .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_BGR565] = {
- .name = "bgr565",
- .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_BGR555] = {
- .name = "bgr555",
- .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_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_BGR32_1] = {
- .name = "bgr32_1",
- .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_RGB32_1] = {
- .name = "rgb32_1",
- .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,
- },
-};
-
-void avcodec_get_chroma_sub_sample(int 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;
-}
-
-const char *avcodec_get_pix_fmt_name(int pix_fmt)
-{
- if (pix_fmt < 0 || pix_fmt >= PIX_FMT_NB)
- return "???";
- else
- return pix_fmt_info[pix_fmt].name;
-}
-
-enum PixelFormat avcodec_get_pix_fmt(const char* name)
-{
- int i;
-
- for (i=0; i < PIX_FMT_NB; i++)
- if (!strcmp(pix_fmt_info[i].name, name))
- break;
- return i;
-}
-
-/* Picture field are filled with 'ptr' addresses. Also return size */
-int avpicture_fill(AVPicture *picture, uint8_t *ptr,
- int pix_fmt, int width, int height)
-{
- int size, w2, h2, size2;
- const PixFmtInfo *pinfo;
-
- if(avcodec_check_dimensions(NULL, width, height))
- goto fail;
-
- pinfo = &pix_fmt_info[pix_fmt];
- size = width * height;
- 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_YUVJ420P:
- case PIX_FMT_YUVJ422P:
- case PIX_FMT_YUVJ444P:
- w2 = (width + (1 << pinfo->x_chroma_shift) - 1) >> pinfo->x_chroma_shift;
- h2 = (height + (1 << pinfo->y_chroma_shift) - 1) >> pinfo->y_chroma_shift;
- size2 = w2 * h2;
- picture->data[0] = ptr;
- picture->data[1] = picture->data[0] + size;
- picture->data[2] = picture->data[1] + size2;
- picture->linesize[0] = width;
- picture->linesize[1] = w2;
- picture->linesize[2] = w2;
- return size + 2 * size2;
- case PIX_FMT_NV12:
- case PIX_FMT_NV21:
- w2 = (width + (1 << pinfo->x_chroma_shift) - 1) >> pinfo->x_chroma_shift;
- h2 = (height + (1 << pinfo->y_chroma_shift) - 1) >> pinfo->y_chroma_shift;
- size2 = w2 * h2 * 2;
- picture->data[0] = ptr;
- picture->data[1] = picture->data[0] + size;
- picture->data[2] = NULL;
- picture->linesize[0] = width;
- picture->linesize[1] = w2;
- picture->linesize[2] = 0;
- return size + 2 * size2;
- case PIX_FMT_RGB24:
- case PIX_FMT_BGR24:
- picture->data[0] = ptr;
- picture->data[1] = NULL;
- picture->data[2] = NULL;
- picture->linesize[0] = width * 3;
- return size * 3;
- case PIX_FMT_RGBA32:
- case PIX_FMT_BGR32:
- case PIX_FMT_RGB32_1:
- case PIX_FMT_BGR32_1:
- picture->data[0] = ptr;
- picture->data[1] = NULL;
- picture->data[2] = NULL;
- picture->linesize[0] = width * 4;
- return size * 4;
- case PIX_FMT_GRAY16BE:
- case PIX_FMT_GRAY16LE:
- case PIX_FMT_BGR555:
- case PIX_FMT_BGR565:
- case PIX_FMT_RGB555:
- case PIX_FMT_RGB565:
- case PIX_FMT_YUV422:
- picture->data[0] = ptr;
- picture->data[1] = NULL;
- picture->data[2] = NULL;
- picture->linesize[0] = width * 2;
- return size * 2;
- case PIX_FMT_UYVY422:
- picture->data[0] = ptr;
- picture->data[1] = NULL;
- picture->data[2] = NULL;
- picture->linesize[0] = width * 2;
- return size * 2;
- case PIX_FMT_UYVY411:
- picture->data[0] = ptr;
- picture->data[1] = NULL;
- picture->data[2] = NULL;
- picture->linesize[0] = width + width/2;
- return size + size/2;
- case PIX_FMT_RGB8:
- case PIX_FMT_BGR8:
- case PIX_FMT_RGB4_BYTE:
- case PIX_FMT_BGR4_BYTE:
- case PIX_FMT_GRAY8:
- picture->data[0] = ptr;
- picture->data[1] = NULL;
- picture->data[2] = NULL;
- picture->linesize[0] = width;
- return size;
- case PIX_FMT_RGB4:
- case PIX_FMT_BGR4:
- picture->data[0] = ptr;
- picture->data[1] = NULL;
- picture->data[2] = NULL;
- picture->linesize[0] = width / 2;
- return size / 2;
- case PIX_FMT_MONOWHITE:
- case PIX_FMT_MONOBLACK:
- picture->data[0] = ptr;
- picture->data[1] = NULL;
- picture->data[2] = NULL;
- picture->linesize[0] = (width + 7) >> 3;
- return picture->linesize[0] * height;
- case PIX_FMT_PAL8:
- size2 = (size + 3) & ~3;
- picture->data[0] = ptr;
- picture->data[1] = ptr + size2; /* palette is stored here as 256 32 bit words */
- picture->data[2] = NULL;
- picture->linesize[0] = width;
- picture->linesize[1] = 4;
- return size2 + 256 * 4;
- default:
-fail:
- picture->data[0] = NULL;
- picture->data[1] = NULL;
- picture->data[2] = NULL;
- picture->data[3] = NULL;
- return -1;
- }
-}
-
-int avpicture_layout(const AVPicture* src, int pix_fmt, int width, int height,
- unsigned char *dest, int dest_size)
-{
- const PixFmtInfo* pf = &pix_fmt_info[pix_fmt];
- int i, j, w, h, data_planes;
- const unsigned char* s;
- int size = avpicture_get_size(pix_fmt, width, height);
-
- if (size > dest_size || size < 0)
- return -1;
-
- if (pf->pixel_type == FF_PIXEL_PACKED || pf->pixel_type == FF_PIXEL_PALETTE) {
- if (pix_fmt == PIX_FMT_YUV422 ||
- pix_fmt == PIX_FMT_UYVY422 ||
- pix_fmt == PIX_FMT_BGR565 ||
- pix_fmt == PIX_FMT_BGR555 ||
- pix_fmt == PIX_FMT_RGB565 ||
- pix_fmt == PIX_FMT_RGB555)
- w = width * 2;
- else if (pix_fmt == PIX_FMT_UYVY411)
- w = width + width/2;
- else if (pix_fmt == PIX_FMT_PAL8)
- w = width;
- else
- w = width * (pf->depth * pf->nb_channels / 8);
-
- data_planes = 1;
- h = height;
- } else {
- data_planes = pf->nb_channels;
- w = (width*pf->depth + 7)/8;
- h = height;
- }
-
- for (i=0; i<data_planes; i++) {
- if (i == 1) {
- w = width >> pf->x_chroma_shift;
- h = height >> pf->y_chroma_shift;
- }
- s = src->data[i];
- for(j=0; j<h; j++) {
- memcpy(dest, s, w);
- dest += w;
- s += src->linesize[i];
- }
- }
-
- if (pf->pixel_type == FF_PIXEL_PALETTE)
- memcpy((unsigned char *)(((size_t)dest + 3) & ~3), src->data[1], 256 * 4);
-
- return size;
-}
-
-int avpicture_get_size(int pix_fmt, int width, int height)
-{
- AVPicture dummy_pict;
- return avpicture_fill(&dummy_pict, NULL, pix_fmt, width, height);
-}
-
-/**
- * compute the loss when converting from a pixel format to another
- */
-int avcodec_get_pix_fmt_loss(int dst_pix_fmt, int src_pix_fmt,
- int has_alpha)
-{
- const PixFmtInfo *pf, *ps;
- int loss;
-
- ps = &pix_fmt_info[src_pix_fmt];
- pf = &pix_fmt_info[dst_pix_fmt];
-
- /* compute loss */
- loss = 0;
- pf = &pix_fmt_info[dst_pix_fmt];
- if (pf->depth < ps->depth ||
- (dst_pix_fmt == PIX_FMT_RGB555 && src_pix_fmt == PIX_FMT_RGB565))
- loss |= FF_LOSS_DEPTH;
- if (pf->x_chroma_shift > ps->x_chroma_shift ||
- pf->y_chroma_shift > ps->y_chroma_shift)
- loss |= FF_LOSS_RESOLUTION;
- switch(pf->color_type) {
- case FF_COLOR_RGB:
- if (ps->color_type != FF_COLOR_RGB &&
- ps->color_type != FF_COLOR_GRAY)
- loss |= FF_LOSS_COLORSPACE;
- break;
- case FF_COLOR_GRAY:
- if (ps->color_type != FF_COLOR_GRAY)
- loss |= FF_LOSS_COLORSPACE;
- break;
- case FF_COLOR_YUV:
- if (ps->color_type != FF_COLOR_YUV)
- loss |= FF_LOSS_COLORSPACE;
- break;
- case FF_COLOR_YUV_JPEG:
- if (ps->color_type != FF_COLOR_YUV_JPEG &&
- ps->color_type != FF_COLOR_YUV &&
- ps->color_type != FF_COLOR_GRAY)
- loss |= FF_LOSS_COLORSPACE;
- break;
- default:
- /* fail safe test */
- if (ps->color_type != pf->color_type)
- loss |= FF_LOSS_COLORSPACE;
- break;
- }
- if (pf->color_type == FF_COLOR_GRAY &&
- ps->color_type != FF_COLOR_GRAY)
- loss |= FF_LOSS_CHROMA;
- if (!pf->is_alpha && (ps->is_alpha && has_alpha))
- loss |= FF_LOSS_ALPHA;
- if (pf->pixel_type == FF_PIXEL_PALETTE &&
- (ps->pixel_type != FF_PIXEL_PALETTE && ps->color_type != FF_COLOR_GRAY))
- loss |= FF_LOSS_COLORQUANT;
- return loss;
-}
-
-static int avg_bits_per_pixel(int pix_fmt)
-{
- int bits;
- const PixFmtInfo *pf;
-
- pf = &pix_fmt_info[pix_fmt];
- switch(pf->pixel_type) {
- case FF_PIXEL_PACKED:
- switch(pix_fmt) {
- case PIX_FMT_YUV422:
- case PIX_FMT_UYVY422:
- case PIX_FMT_RGB565:
- case PIX_FMT_RGB555:
- case PIX_FMT_BGR565:
- case PIX_FMT_BGR555:
- bits = 16;
- break;
- case PIX_FMT_UYVY411:
- bits = 12;
- break;
- default:
- bits = pf->depth * pf->nb_channels;
- break;
- }
- break;
- case FF_PIXEL_PLANAR:
- if (pf->x_chroma_shift == 0 && pf->y_chroma_shift == 0) {
- bits = pf->depth * pf->nb_channels;
- } else {
- bits = pf->depth + ((2 * pf->depth) >>
- (pf->x_chroma_shift + pf->y_chroma_shift));
- }
- break;
- case FF_PIXEL_PALETTE:
- bits = 8;
- break;
- default:
- bits = -1;
- break;
- }
- return bits;
-}
-
-static int avcodec_find_best_pix_fmt1(int pix_fmt_mask,
- int src_pix_fmt,
- int has_alpha,
- int loss_mask)
-{
- int dist, i, loss, min_dist, dst_pix_fmt;
-
- /* find exact color match with smallest size */
- dst_pix_fmt = -1;
- min_dist = 0x7fffffff;
- for(i = 0;i < PIX_FMT_NB; i++) {
- if (pix_fmt_mask & (1 << i)) {
- loss = avcodec_get_pix_fmt_loss(i, src_pix_fmt, has_alpha) & loss_mask;
- if (loss == 0) {
- dist = avg_bits_per_pixel(i);
- if (dist < min_dist) {
- min_dist = dist;
- dst_pix_fmt = i;
- }
- }
- }
- }
- return dst_pix_fmt;
-}
-
-/**
- * find best pixel format to convert to. Return -1 if none found
- */
-int avcodec_find_best_pix_fmt(int pix_fmt_mask, int src_pix_fmt,
- int has_alpha, int *loss_ptr)
-{
- int dst_pix_fmt, loss_mask, i;
- static const int loss_mask_order[] = {
- ~0, /* no loss first */
- ~FF_LOSS_ALPHA,
- ~FF_LOSS_RESOLUTION,
- ~(FF_LOSS_COLORSPACE | FF_LOSS_RESOLUTION),
- ~FF_LOSS_COLORQUANT,
- ~FF_LOSS_DEPTH,
- 0,
- };
-
- /* try with successive loss */
- i = 0;
- for(;;) {
- loss_mask = loss_mask_order[i++];
- dst_pix_fmt = avcodec_find_best_pix_fmt1(pix_fmt_mask, src_pix_fmt,
- has_alpha, loss_mask);
- if (dst_pix_fmt >= 0)
- goto found;
- if (loss_mask == 0)
- break;
- }
- return -1;
- found:
- if (loss_ptr)
- *loss_ptr = avcodec_get_pix_fmt_loss(dst_pix_fmt, src_pix_fmt, has_alpha);
- return dst_pix_fmt;
-}
-
-void ff_img_copy_plane(uint8_t *dst, int dst_wrap,
- const uint8_t *src, int src_wrap,
- int width, int height)
-{
- if((!dst) || (!src))
- return;
- for(;height > 0; height--) {
- memcpy(dst, src, width);
- dst += dst_wrap;
- src += src_wrap;
- }
-}
-
-/**
- * Copy image 'src' to 'dst'.
- */
-void img_copy(AVPicture *dst, const AVPicture *src,
- int pix_fmt, int width, int height)
-{
- int bwidth, bits, i;
- const PixFmtInfo *pf = &pix_fmt_info[pix_fmt];
-
- pf = &pix_fmt_info[pix_fmt];
- switch(pf->pixel_type) {
- case FF_PIXEL_PACKED:
- switch(pix_fmt) {
- case PIX_FMT_YUV422:
- case PIX_FMT_UYVY422:
- case PIX_FMT_RGB565:
- case PIX_FMT_RGB555:
- case PIX_FMT_BGR565:
- case PIX_FMT_BGR555:
- bits = 16;
- break;
- case PIX_FMT_UYVY411:
- bits = 12;
- break;
- default:
- bits = pf->depth * pf->nb_channels;
- break;
- }
- bwidth = (width * bits + 7) >> 3;
- ff_img_copy_plane(dst->data[0], dst->linesize[0],
- src->data[0], src->linesize[0],
- bwidth, height);
- break;
- case FF_PIXEL_PLANAR:
- for(i = 0; i < pf->nb_channels; i++) {
- int w, h;
- w = width;
- h = height;
- if (i == 1 || i == 2) {
- w >>= pf->x_chroma_shift;
- h >>= pf->y_chroma_shift;
- }
- bwidth = (w * pf->depth + 7) >> 3;
- ff_img_copy_plane(dst->data[i], dst->linesize[i],
- src->data[i], src->linesize[i],
- bwidth, h);
- }
- break;
- case FF_PIXEL_PALETTE:
- ff_img_copy_plane(dst->data[0], dst->linesize[0],
- 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);
- break;
- }
-}
-
-/* XXX: totally non optimized */
-
-static void yuv422_to_yuv420p(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- const uint8_t *p, *p1;
- uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
- int w;
-
- p1 = src->data[0];
- lum1 = dst->data[0];
- cb1 = dst->data[1];
- cr1 = dst->data[2];
-
- for(;height >= 1; height -= 2) {
- p = p1;
- lum = lum1;
- cb = cb1;
- cr = cr1;
- for(w = width; w >= 2; w -= 2) {
- lum[0] = p[0];
- cb[0] = p[1];
- lum[1] = p[2];
- cr[0] = p[3];
- p += 4;
- lum += 2;
- cb++;
- cr++;
- }
- if (w) {
- lum[0] = p[0];
- cb[0] = p[1];
- cr[0] = p[3];
- cb++;
- cr++;
- }
- p1 += src->linesize[0];
- lum1 += dst->linesize[0];
- if (height>1) {
- p = p1;
- lum = lum1;
- for(w = width; w >= 2; w -= 2) {
- lum[0] = p[0];
- lum[1] = p[2];
- p += 4;
- lum += 2;
- }
- if (w) {
- lum[0] = p[0];
- }
- p1 += src->linesize[0];
- lum1 += dst->linesize[0];
- }
- cb1 += dst->linesize[1];
- cr1 += dst->linesize[2];
- }
-}
-
-static void uyvy422_to_yuv420p(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- const uint8_t *p, *p1;
- uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
- int w;
-
- p1 = src->data[0];
-
- lum1 = dst->data[0];
- cb1 = dst->data[1];
- cr1 = dst->data[2];
-
- for(;height >= 1; height -= 2) {
- p = p1;
- lum = lum1;
- cb = cb1;
- cr = cr1;
- for(w = width; w >= 2; w -= 2) {
- lum[0] = p[1];
- cb[0] = p[0];
- lum[1] = p[3];
- cr[0] = p[2];
- p += 4;
- lum += 2;
- cb++;
- cr++;
- }
- if (w) {
- lum[0] = p[1];
- cb[0] = p[0];
- cr[0] = p[2];
- cb++;
- cr++;
- }
- p1 += src->linesize[0];
- lum1 += dst->linesize[0];
- if (height>1) {
- p = p1;
- lum = lum1;
- for(w = width; w >= 2; w -= 2) {
- lum[0] = p[1];
- lum[1] = p[3];
- p += 4;
- lum += 2;
- }
- if (w) {
- lum[0] = p[1];
- }
- p1 += src->linesize[0];
- lum1 += dst->linesize[0];
- }
- cb1 += dst->linesize[1];
- cr1 += dst->linesize[2];
- }
-}
-
-
-static void uyvy422_to_yuv422p(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- const uint8_t *p, *p1;
- uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
- int w;
-
- p1 = src->data[0];
- lum1 = dst->data[0];
- cb1 = dst->data[1];
- cr1 = dst->data[2];
- for(;height > 0; height--) {
- p = p1;
- lum = lum1;
- cb = cb1;
- cr = cr1;
- for(w = width; w >= 2; w -= 2) {
- lum[0] = p[1];
- cb[0] = p[0];
- lum[1] = p[3];
- cr[0] = p[2];
- p += 4;
- lum += 2;
- cb++;
- cr++;
- }
- p1 += src->linesize[0];
- lum1 += dst->linesize[0];
- cb1 += dst->linesize[1];
- cr1 += dst->linesize[2];
- }
-}
-
-
-static void yuv422_to_yuv422p(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- const uint8_t *p, *p1;
- uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
- int w;
-
- p1 = src->data[0];
- lum1 = dst->data[0];
- cb1 = dst->data[1];
- cr1 = dst->data[2];
- for(;height > 0; height--) {
- p = p1;
- lum = lum1;
- cb = cb1;
- cr = cr1;
- for(w = width; w >= 2; w -= 2) {
- lum[0] = p[0];
- cb[0] = p[1];
- lum[1] = p[2];
- cr[0] = p[3];
- p += 4;
- lum += 2;
- cb++;
- cr++;
- }
- p1 += src->linesize[0];
- lum1 += dst->linesize[0];
- cb1 += dst->linesize[1];
- cr1 += dst->linesize[2];
- }
-}
-
-static void yuv422p_to_yuv422(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- uint8_t *p, *p1;
- const uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
- int w;
-
- p1 = dst->data[0];
- lum1 = src->data[0];
- cb1 = src->data[1];
- cr1 = src->data[2];
- for(;height > 0; height--) {
- p = p1;
- lum = lum1;
- cb = cb1;
- cr = cr1;
- for(w = width; w >= 2; w -= 2) {
- p[0] = lum[0];
- p[1] = cb[0];
- p[2] = lum[1];
- p[3] = cr[0];
- p += 4;
- lum += 2;
- cb++;
- cr++;
- }
- p1 += dst->linesize[0];
- lum1 += src->linesize[0];
- cb1 += src->linesize[1];
- cr1 += src->linesize[2];
- }
-}
-
-static void yuv422p_to_uyvy422(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- uint8_t *p, *p1;
- const uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
- int w;
-
- p1 = dst->data[0];
- lum1 = src->data[0];
- cb1 = src->data[1];
- cr1 = src->data[2];
- for(;height > 0; height--) {
- p = p1;
- lum = lum1;
- cb = cb1;
- cr = cr1;
- for(w = width; w >= 2; w -= 2) {
- p[1] = lum[0];
- p[0] = cb[0];
- p[3] = lum[1];
- p[2] = cr[0];
- p += 4;
- lum += 2;
- cb++;
- cr++;
- }
- p1 += dst->linesize[0];
- lum1 += src->linesize[0];
- cb1 += src->linesize[1];
- cr1 += src->linesize[2];
- }
-}
-
-static void uyvy411_to_yuv411p(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- const uint8_t *p, *p1;
- uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
- int w;
-
- p1 = src->data[0];
- lum1 = dst->data[0];
- cb1 = dst->data[1];
- cr1 = dst->data[2];
- for(;height > 0; height--) {
- p = p1;
- lum = lum1;
- cb = cb1;
- cr = cr1;
- for(w = width; w >= 4; w -= 4) {
- cb[0] = p[0];
- lum[0] = p[1];
- lum[1] = p[2];
- cr[0] = p[3];
- lum[2] = p[4];
- lum[3] = p[5];
- p += 6;
- lum += 4;
- cb++;
- cr++;
- }
- p1 += src->linesize[0];
- lum1 += dst->linesize[0];
- cb1 += dst->linesize[1];
- cr1 += dst->linesize[2];
- }
-}
-
-
-static void yuv420p_to_yuv422(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- int w, h;
- uint8_t *line1, *line2, *linesrc = dst->data[0];
- uint8_t *lum1, *lum2, *lumsrc = src->data[0];
- uint8_t *cb1, *cb2 = src->data[1];
- uint8_t *cr1, *cr2 = src->data[2];
-
- for(h = height / 2; h--;) {
- line1 = linesrc;
- line2 = linesrc + dst->linesize[0];
-
- lum1 = lumsrc;
- lum2 = lumsrc + src->linesize[0];
-
- cb1 = cb2;
- cr1 = cr2;
-
- for(w = width / 2; w--;) {
- *line1++ = *lum1++; *line2++ = *lum2++;
- *line1++ = *line2++ = *cb1++;
- *line1++ = *lum1++; *line2++ = *lum2++;
- *line1++ = *line2++ = *cr1++;
- }
-
- linesrc += dst->linesize[0] * 2;
- lumsrc += src->linesize[0] * 2;
- cb2 += src->linesize[1];
- cr2 += src->linesize[2];
- }
-}
-
-static void yuv420p_to_uyvy422(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- int w, h;
- uint8_t *line1, *line2, *linesrc = dst->data[0];
- uint8_t *lum1, *lum2, *lumsrc = src->data[0];
- uint8_t *cb1, *cb2 = src->data[1];
- uint8_t *cr1, *cr2 = src->data[2];
-
- for(h = height / 2; h--;) {
- line1 = linesrc;
- line2 = linesrc + dst->linesize[0];
-
- lum1 = lumsrc;
- lum2 = lumsrc + src->linesize[0];
-
- cb1 = cb2;
- cr1 = cr2;
-
- for(w = width / 2; w--;) {
- *line1++ = *line2++ = *cb1++;
- *line1++ = *lum1++; *line2++ = *lum2++;
- *line1++ = *line2++ = *cr1++;
- *line1++ = *lum1++; *line2++ = *lum2++;
- }
-
- linesrc += dst->linesize[0] * 2;
- lumsrc += src->linesize[0] * 2;
- cb2 += src->linesize[1];
- cr2 += src->linesize[2];
- }
-}
-
-#define SCALEBITS 10
-#define ONE_HALF (1 << (SCALEBITS - 1))
-#define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5))
-
-#define YUV_TO_RGB1_CCIR(cb1, cr1)\
-{\
- cb = (cb1) - 128;\
- cr = (cr1) - 128;\
- r_add = FIX(1.40200*255.0/224.0) * cr + ONE_HALF;\
- g_add = - FIX(0.34414*255.0/224.0) * cb - FIX(0.71414*255.0/224.0) * cr + \
- ONE_HALF;\
- b_add = FIX(1.77200*255.0/224.0) * cb + ONE_HALF;\
-}
-
-#define YUV_TO_RGB2_CCIR(r, g, b, y1)\
-{\
- y = ((y1) - 16) * FIX(255.0/219.0);\
- r = cm[(y + r_add) >> SCALEBITS];\
- g = cm[(y + g_add) >> SCALEBITS];\
- b = cm[(y + b_add) >> SCALEBITS];\
-}
-
-#define YUV_TO_RGB1(cb1, cr1)\
-{\
- cb = (cb1) - 128;\
- cr = (cr1) - 128;\
- r_add = FIX(1.40200) * cr + ONE_HALF;\
- g_add = - FIX(0.34414) * cb - FIX(0.71414) * cr + ONE_HALF;\
- b_add = FIX(1.77200) * cb + ONE_HALF;\
-}
-
-#define YUV_TO_RGB2(r, g, b, y1)\
-{\
- y = (y1) << SCALEBITS;\
- r = cm[(y + r_add) >> SCALEBITS];\
- g = cm[(y + g_add) >> SCALEBITS];\
- b = cm[(y + b_add) >> SCALEBITS];\
-}
-
-#define Y_CCIR_TO_JPEG(y)\
- cm[((y) * FIX(255.0/219.0) + (ONE_HALF - 16 * FIX(255.0/219.0))) >> SCALEBITS]
-
-#define Y_JPEG_TO_CCIR(y)\
- (((y) * FIX(219.0/255.0) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS)
-
-#define C_CCIR_TO_JPEG(y)\
- cm[(((y) - 128) * FIX(127.0/112.0) + (ONE_HALF + (128 << SCALEBITS))) >> SCALEBITS]
-
-/* NOTE: the clamp is really necessary! */
-static inline int C_JPEG_TO_CCIR(int y) {
- y = (((y - 128) * FIX(112.0/127.0) + (ONE_HALF + (128 << SCALEBITS))) >> SCALEBITS);
- if (y < 16)
- y = 16;
- return y;
-}
-
-
-#define RGB_TO_Y(r, g, b) \
-((FIX(0.29900) * (r) + FIX(0.58700) * (g) + \
- FIX(0.11400) * (b) + ONE_HALF) >> SCALEBITS)
-
-#define RGB_TO_U(r1, g1, b1, shift)\
-(((- FIX(0.16874) * r1 - FIX(0.33126) * g1 + \
- FIX(0.50000) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
-
-#define RGB_TO_V(r1, g1, b1, shift)\
-(((FIX(0.50000) * r1 - FIX(0.41869) * g1 - \
- FIX(0.08131) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
-
-#define RGB_TO_Y_CCIR(r, g, b) \
-((FIX(0.29900*219.0/255.0) * (r) + FIX(0.58700*219.0/255.0) * (g) + \
- FIX(0.11400*219.0/255.0) * (b) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS)
-
-#define RGB_TO_U_CCIR(r1, g1, b1, shift)\
-(((- FIX(0.16874*224.0/255.0) * r1 - FIX(0.33126*224.0/255.0) * g1 + \
- FIX(0.50000*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
-
-#define RGB_TO_V_CCIR(r1, g1, b1, shift)\
-(((FIX(0.50000*224.0/255.0) * r1 - FIX(0.41869*224.0/255.0) * g1 - \
- FIX(0.08131*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
-
-static uint8_t y_ccir_to_jpeg[256];
-static uint8_t y_jpeg_to_ccir[256];
-static uint8_t c_ccir_to_jpeg[256];
-static uint8_t c_jpeg_to_ccir[256];
-
-/* init various conversion tables */
-static void img_convert_init(void)
-{
- int i;
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
-
- for(i = 0;i < 256; i++) {
- y_ccir_to_jpeg[i] = Y_CCIR_TO_JPEG(i);
- y_jpeg_to_ccir[i] = Y_JPEG_TO_CCIR(i);
- c_ccir_to_jpeg[i] = C_CCIR_TO_JPEG(i);
- c_jpeg_to_ccir[i] = C_JPEG_TO_CCIR(i);
- }
-}
-
-/* apply to each pixel the given table */
-static void img_apply_table(uint8_t *dst, int dst_wrap,
- const uint8_t *src, int src_wrap,
- int width, int height, const uint8_t *table1)
-{
- int n;
- const uint8_t *s;
- uint8_t *d;
- const uint8_t *table;
-
- table = table1;
- for(;height > 0; height--) {
- s = src;
- d = dst;
- n = width;
- while (n >= 4) {
- d[0] = table[s[0]];
- d[1] = table[s[1]];
- d[2] = table[s[2]];
- d[3] = table[s[3]];
- d += 4;
- s += 4;
- n -= 4;
- }
- while (n > 0) {
- d[0] = table[s[0]];
- d++;
- s++;
- n--;
- }
- dst += dst_wrap;
- src += src_wrap;
- }
-}
-
-/* XXX: use generic filter ? */
-/* XXX: in most cases, the sampling position is incorrect */
-
-/* 4x1 -> 1x1 */
-static void shrink41(uint8_t *dst, int dst_wrap,
- const uint8_t *src, int src_wrap,
- int width, int height)
-{
- int w;
- const uint8_t *s;
- uint8_t *d;
-
- for(;height > 0; height--) {
- s = src;
- d = dst;
- for(w = width;w > 0; w--) {
- d[0] = (s[0] + s[1] + s[2] + s[3] + 2) >> 2;
- s += 4;
- d++;
- }
- src += src_wrap;
- dst += dst_wrap;
- }
-}
-
-/* 2x1 -> 1x1 */
-static void shrink21(uint8_t *dst, int dst_wrap,
- const uint8_t *src, int src_wrap,
- int width, int height)
-{
- int w;
- const uint8_t *s;
- uint8_t *d;
-
- for(;height > 0; height--) {
- s = src;
- d = dst;
- for(w = width;w > 0; w--) {
- d[0] = (s[0] + s[1]) >> 1;
- s += 2;
- d++;
- }
- src += src_wrap;
- dst += dst_wrap;
- }
-}
-
-/* 1x2 -> 1x1 */
-static void shrink12(uint8_t *dst, int dst_wrap,
- const uint8_t *src, int src_wrap,
- int width, int height)
-{
- int w;
- uint8_t *d;
- const uint8_t *s1, *s2;
-
- for(;height > 0; height--) {
- s1 = src;
- s2 = s1 + src_wrap;
- d = dst;
- for(w = width;w >= 4; w-=4) {
- d[0] = (s1[0] + s2[0]) >> 1;
- d[1] = (s1[1] + s2[1]) >> 1;
- d[2] = (s1[2] + s2[2]) >> 1;
- d[3] = (s1[3] + s2[3]) >> 1;
- s1 += 4;
- s2 += 4;
- d += 4;
- }
- for(;w > 0; w--) {
- d[0] = (s1[0] + s2[0]) >> 1;
- s1++;
- s2++;
- d++;
- }
- src += 2 * src_wrap;
- dst += dst_wrap;
- }
-}
-
-/* 2x2 -> 1x1 */
-void ff_shrink22(uint8_t *dst, int dst_wrap,
- const uint8_t *src, int src_wrap,
- int width, int height)
-{
- int w;
- const uint8_t *s1, *s2;
- uint8_t *d;
-
- for(;height > 0; height--) {
- s1 = src;
- s2 = s1 + src_wrap;
- d = dst;
- for(w = width;w >= 4; w-=4) {
- d[0] = (s1[0] + s1[1] + s2[0] + s2[1] + 2) >> 2;
- d[1] = (s1[2] + s1[3] + s2[2] + s2[3] + 2) >> 2;
- d[2] = (s1[4] + s1[5] + s2[4] + s2[5] + 2) >> 2;
- d[3] = (s1[6] + s1[7] + s2[6] + s2[7] + 2) >> 2;
- s1 += 8;
- s2 += 8;
- d += 4;
- }
- for(;w > 0; w--) {
- d[0] = (s1[0] + s1[1] + s2[0] + s2[1] + 2) >> 2;
- s1 += 2;
- s2 += 2;
- d++;
- }
- src += 2 * src_wrap;
- dst += dst_wrap;
- }
-}
-
-/* 4x4 -> 1x1 */
-void ff_shrink44(uint8_t *dst, int dst_wrap,
- const uint8_t *src, int src_wrap,
- int width, int height)
-{
- int w;
- const uint8_t *s1, *s2, *s3, *s4;
- uint8_t *d;
-
- for(;height > 0; height--) {
- s1 = src;
- s2 = s1 + src_wrap;
- s3 = s2 + src_wrap;
- s4 = s3 + src_wrap;
- d = dst;
- for(w = width;w > 0; w--) {
- d[0] = (s1[0] + s1[1] + s1[2] + s1[3] +
- s2[0] + s2[1] + s2[2] + s2[3] +
- s3[0] + s3[1] + s3[2] + s3[3] +
- s4[0] + s4[1] + s4[2] + s4[3] + 8) >> 4;
- s1 += 4;
- s2 += 4;
- s3 += 4;
- s4 += 4;
- d++;
- }
- src += 4 * src_wrap;
- dst += dst_wrap;
- }
-}
-
-/* 8x8 -> 1x1 */
-void ff_shrink88(uint8_t *dst, int dst_wrap,
- const uint8_t *src, int src_wrap,
- int width, int height)
-{
- int w, i;
-
- for(;height > 0; height--) {
- for(w = width;w > 0; w--) {
- int tmp=0;
- for(i=0; i<8; i++){
- tmp += src[0] + src[1] + src[2] + src[3] + src[4] + src[5] + src[6] + src[7];
- src += src_wrap;
- }
- *(dst++) = (tmp + 32)>>6;
- src += 8 - 8*src_wrap;
- }
- src += 8*src_wrap - 8*width;
- dst += dst_wrap - width;
- }
-}
-
-static void grow21_line(uint8_t *dst, const uint8_t *src,
- int width)
-{
- int w;
- const uint8_t *s1;
- uint8_t *d;
-
- s1 = src;
- d = dst;
- for(w = width;w >= 4; w-=4) {
- d[1] = d[0] = s1[0];
- d[3] = d[2] = s1[1];
- s1 += 2;
- d += 4;
- }
- for(;w >= 2; w -= 2) {
- d[1] = d[0] = s1[0];
- s1 ++;
- d += 2;
- }
- /* only needed if width is not a multiple of two */
- /* XXX: veryfy that */
- if (w) {
- d[0] = s1[0];
- }
-}
-
-static void grow41_line(uint8_t *dst, const uint8_t *src,
- int width)
-{
- int w, v;
- const uint8_t *s1;
- uint8_t *d;
-
- s1 = src;
- d = dst;
- for(w = width;w >= 4; w-=4) {
- v = s1[0];
- d[0] = v;
- d[1] = v;
- d[2] = v;
- d[3] = v;
- s1 ++;
- d += 4;
- }
-}
-
-/* 1x1 -> 2x1 */
-static void grow21(uint8_t *dst, int dst_wrap,
- const uint8_t *src, int src_wrap,
- int width, int height)
-{
- for(;height > 0; height--) {
- grow21_line(dst, src, width);
- src += src_wrap;
- dst += dst_wrap;
- }
-}
-
-/* 1x1 -> 2x2 */
-static void grow22(uint8_t *dst, int dst_wrap,
- const uint8_t *src, int src_wrap,
- int width, int height)
-{
- for(;height > 0; height--) {
- grow21_line(dst, src, width);
- if (height%2)
- src += src_wrap;
- dst += dst_wrap;
- }
-}
-
-/* 1x1 -> 4x1 */
-static void grow41(uint8_t *dst, int dst_wrap,
- const uint8_t *src, int src_wrap,
- int width, int height)
-{
- for(;height > 0; height--) {
- grow41_line(dst, src, width);
- src += src_wrap;
- dst += dst_wrap;
- }
-}
-
-/* 1x1 -> 4x4 */
-static void grow44(uint8_t *dst, int dst_wrap,
- const uint8_t *src, int src_wrap,
- int width, int height)
-{
- for(;height > 0; height--) {
- grow41_line(dst, src, width);
- if ((height & 3) == 1)
- src += src_wrap;
- dst += dst_wrap;
- }
-}
-
-/* 1x2 -> 2x1 */
-static void conv411(uint8_t *dst, int dst_wrap,
- const uint8_t *src, int src_wrap,
- int width, int height)
-{
- int w, c;
- const uint8_t *s1, *s2;
- uint8_t *d;
-
- width>>=1;
-
- for(;height > 0; height--) {
- s1 = src;
- s2 = src + src_wrap;
- d = dst;
- for(w = width;w > 0; w--) {
- c = (s1[0] + s2[0]) >> 1;
- d[0] = c;
- d[1] = c;
- s1++;
- s2++;
- d += 2;
- }
- src += src_wrap * 2;
- dst += dst_wrap;
- }
-}
-
-/* XXX: add jpeg quantize code */
-
-#define TRANSP_INDEX (6*6*6)
-
-/* this is maybe slow, but allows for extensions */
-static inline unsigned char gif_clut_index(uint8_t r, uint8_t g, uint8_t b)
-{
- return ((((r)/47)%6)*6*6+(((g)/47)%6)*6+(((b)/47)%6));
-}
-
-static void build_rgb_palette(uint8_t *palette, int has_alpha)
-{
- uint32_t *pal;
- static const uint8_t pal_value[6] = { 0x00, 0x33, 0x66, 0x99, 0xcc, 0xff };
- int i, r, g, b;
-
- pal = (uint32_t *)palette;
- i = 0;
- for(r = 0; r < 6; r++) {
- for(g = 0; g < 6; g++) {
- for(b = 0; b < 6; b++) {
- pal[i++] = (0xff << 24) | (pal_value[r] << 16) |
- (pal_value[g] << 8) | pal_value[b];
- }
- }
- }
- if (has_alpha)
- pal[i++] = 0;
- while (i < 256)
- pal[i++] = 0xff000000;
-}
-
-/* copy bit n to bits 0 ... n - 1 */
-static inline unsigned int bitcopy_n(unsigned int a, int n)
-{
- int mask;
- mask = (1 << n) - 1;
- return (a & (0xff & ~mask)) | ((-((a >> n) & 1)) & mask);
-}
-
-/* rgb555 handling */
-
-#define RGB_NAME rgb555
-
-#define RGB_IN(r, g, b, s)\
-{\
- unsigned int v = ((const uint16_t *)(s))[0];\
- r = bitcopy_n(v >> (10 - 3), 3);\
- g = bitcopy_n(v >> (5 - 3), 3);\
- b = bitcopy_n(v << 3, 3);\
-}
-
-
-#define RGB_OUT(d, r, g, b)\
-{\
- ((uint16_t *)(d))[0] = ((r >> 3) << 10) | ((g >> 3) << 5) | (b >> 3);\
-}
-
-#define BPP 2
-
-#include "imgconvert_template.h"
-
-/* rgb565 handling */
-
-#define RGB_NAME rgb565
-
-#define RGB_IN(r, g, b, s)\
-{\
- unsigned int v = ((const uint16_t *)(s))[0];\
- r = bitcopy_n(v >> (11 - 3), 3);\
- g = bitcopy_n(v >> (5 - 2), 2);\
- b = bitcopy_n(v << 3, 3);\
-}
-
-#define RGB_OUT(d, r, g, b)\
-{\
- ((uint16_t *)(d))[0] = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3);\
-}
-
-#define BPP 2
-
-#include "imgconvert_template.h"
-
-/* bgr24 handling */
-
-#define RGB_NAME bgr24
-
-#define RGB_IN(r, g, b, s)\
-{\
- b = (s)[0];\
- g = (s)[1];\
- r = (s)[2];\
-}
-
-#define RGB_OUT(d, r, g, b)\
-{\
- (d)[0] = b;\
- (d)[1] = g;\
- (d)[2] = r;\
-}
-
-#define BPP 3
-
-#include "imgconvert_template.h"
-
-#undef RGB_IN
-#undef RGB_OUT
-#undef BPP
-
-/* rgb24 handling */
-
-#define RGB_NAME rgb24
-#define FMT_RGB24
-
-#define RGB_IN(r, g, b, s)\
-{\
- r = (s)[0];\
- g = (s)[1];\
- b = (s)[2];\
-}
-
-#define RGB_OUT(d, r, g, b)\
-{\
- (d)[0] = r;\
- (d)[1] = g;\
- (d)[2] = b;\
-}
-
-#define BPP 3
-
-#include "imgconvert_template.h"
-
-/* rgba32 handling */
-
-#define RGB_NAME rgba32
-#define FMT_RGBA32
-
-#define RGB_IN(r, g, b, s)\
-{\
- unsigned int v = ((const uint32_t *)(s))[0];\
- r = (v >> 16) & 0xff;\
- g = (v >> 8) & 0xff;\
- b = v & 0xff;\
-}
-
-#define RGBA_IN(r, g, b, a, s)\
-{\
- unsigned int v = ((const uint32_t *)(s))[0];\
- a = (v >> 24) & 0xff;\
- r = (v >> 16) & 0xff;\
- g = (v >> 8) & 0xff;\
- b = v & 0xff;\
-}
-
-#define RGBA_OUT(d, r, g, b, a)\
-{\
- ((uint32_t *)(d))[0] = (a << 24) | (r << 16) | (g << 8) | b;\
-}
-
-#define BPP 4
-
-#include "imgconvert_template.h"
-
-static void mono_to_gray(AVPicture *dst, const AVPicture *src,
- int width, int height, int xor_mask)
-{
- const unsigned char *p;
- unsigned char *q;
- int v, dst_wrap, src_wrap;
- int y, w;
-
- p = src->data[0];
- src_wrap = src->linesize[0] - ((width + 7) >> 3);
-
- q = dst->data[0];
- dst_wrap = dst->linesize[0] - width;
- for(y=0;y<height;y++) {
- w = width;
- while (w >= 8) {
- v = *p++ ^ xor_mask;
- q[0] = -(v >> 7);
- q[1] = -((v >> 6) & 1);
- q[2] = -((v >> 5) & 1);
- q[3] = -((v >> 4) & 1);
- q[4] = -((v >> 3) & 1);
- q[5] = -((v >> 2) & 1);
- q[6] = -((v >> 1) & 1);
- q[7] = -((v >> 0) & 1);
- w -= 8;
- q += 8;
- }
- if (w > 0) {
- v = *p++ ^ xor_mask;
- do {
- q[0] = -((v >> 7) & 1);
- q++;
- v <<= 1;
- } while (--w);
- }
- p += src_wrap;
- q += dst_wrap;
- }
-}
-
-static void monowhite_to_gray(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- mono_to_gray(dst, src, width, height, 0xff);
-}
-
-static void monoblack_to_gray(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- mono_to_gray(dst, src, width, height, 0x00);
-}
-
-static void gray_to_mono(AVPicture *dst, const AVPicture *src,
- int width, int height, int xor_mask)
-{
- int n;
- const uint8_t *s;
- uint8_t *d;
- int j, b, v, n1, src_wrap, dst_wrap, y;
-
- s = src->data[0];
- src_wrap = src->linesize[0] - width;
-
- d = dst->data[0];
- dst_wrap = dst->linesize[0] - ((width + 7) >> 3);
-
- for(y=0;y<height;y++) {
- n = width;
- while (n >= 8) {
- v = 0;
- for(j=0;j<8;j++) {
- b = s[0];
- s++;
- v = (v << 1) | (b >> 7);
- }
- d[0] = v ^ xor_mask;
- d++;
- n -= 8;
- }
- if (n > 0) {
- n1 = n;
- v = 0;
- while (n > 0) {
- b = s[0];
- s++;
- v = (v << 1) | (b >> 7);
- n--;
- }
- d[0] = (v << (8 - (n1 & 7))) ^ xor_mask;
- d++;
- }
- s += src_wrap;
- d += dst_wrap;
- }
-}
-
-static void gray_to_monowhite(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- gray_to_mono(dst, src, width, height, 0xff);
-}
-
-static void gray_to_monoblack(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- gray_to_mono(dst, src, width, height, 0x00);
-}
-
-static void gray_to_gray16(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- int x, y, src_wrap, dst_wrap;
- uint8_t *s, *d;
- s = src->data[0];
- src_wrap = src->linesize[0] - width;
- d = dst->data[0];
- dst_wrap = dst->linesize[0] - width * 2;
- for(y=0; y<height; y++){
- for(x=0; x<width; x++){
- *d++ = *s;
- *d++ = *s++;
- }
- s += src_wrap;
- d += dst_wrap;
- }
-}
-
-static void gray16_to_gray(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- int x, y, src_wrap, dst_wrap;
- uint8_t *s, *d;
- s = src->data[0];
- src_wrap = src->linesize[0] - width * 2;
- d = dst->data[0];
- dst_wrap = dst->linesize[0] - width;
- for(y=0; y<height; y++){
- for(x=0; x<width; x++){
- *d++ = *s;
- s += 2;
- }
- s += src_wrap;
- d += dst_wrap;
- }
-}
-
-static void gray16be_to_gray(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- gray16_to_gray(dst, src, width, height);
-}
-
-static void gray16le_to_gray(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- gray16_to_gray(dst, src + 1, width, height);
-}
-
-static void gray16_to_gray16(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- int x, y, src_wrap, dst_wrap;
- uint16_t *s, *d;
- s = src->data[0];
- src_wrap = (src->linesize[0] - width * 2)/2;
- d = dst->data[0];
- dst_wrap = (dst->linesize[0] - width * 2)/2;
- for(y=0; y<height; y++){
- for(x=0; x<width; x++){
- *d++ = bswap_16(*s++);
- }
- s += src_wrap;
- d += dst_wrap;
- }
-}
-
-
-typedef struct ConvertEntry {
- void (*convert)(AVPicture *dst,
- const AVPicture *src, int width, int height);
-} ConvertEntry;
-
-/* Add each new convertion function in this table. In order to be able
- to convert from any format to any format, the following constraints
- must be satisfied:
-
- - all FF_COLOR_RGB formats must convert to and from PIX_FMT_RGB24
-
- - all FF_COLOR_GRAY formats must convert to and from PIX_FMT_GRAY8
-
- - all FF_COLOR_RGB formats with alpha must convert to and from PIX_FMT_RGBA32
-
- - PIX_FMT_YUV444P and PIX_FMT_YUVJ444P must convert to and from
- PIX_FMT_RGB24.
-
- - PIX_FMT_422 must convert to and from PIX_FMT_422P.
-
- The other conversion functions are just optimisations for common cases.
-*/
-static const ConvertEntry convert_table[PIX_FMT_NB][PIX_FMT_NB] = {
- [PIX_FMT_YUV420P] = {
- [PIX_FMT_YUV422] = {
- .convert = yuv420p_to_yuv422,
- },
- [PIX_FMT_RGB555] = {
- .convert = yuv420p_to_rgb555
- },
- [PIX_FMT_RGB565] = {
- .convert = yuv420p_to_rgb565
- },
- [PIX_FMT_BGR24] = {
- .convert = yuv420p_to_bgr24
- },
- [PIX_FMT_RGB24] = {
- .convert = yuv420p_to_rgb24
- },
- [PIX_FMT_RGBA32] = {
- .convert = yuv420p_to_rgba32
- },
- [PIX_FMT_UYVY422] = {
- .convert = yuv420p_to_uyvy422,
- },
- },
- [PIX_FMT_YUV422P] = {
- [PIX_FMT_YUV422] = {
- .convert = yuv422p_to_yuv422,
- },
- [PIX_FMT_UYVY422] = {
- .convert = yuv422p_to_uyvy422,
- },
- },
- [PIX_FMT_YUV444P] = {
- [PIX_FMT_RGB24] = {
- .convert = yuv444p_to_rgb24
- },
- },
- [PIX_FMT_YUVJ420P] = {
- [PIX_FMT_RGB555] = {
- .convert = yuvj420p_to_rgb555
- },
- [PIX_FMT_RGB565] = {
- .convert = yuvj420p_to_rgb565
- },
- [PIX_FMT_BGR24] = {
- .convert = yuvj420p_to_bgr24
- },
- [PIX_FMT_RGB24] = {
- .convert = yuvj420p_to_rgb24
- },
- [PIX_FMT_RGBA32] = {
- .convert = yuvj420p_to_rgba32
- },
- },
- [PIX_FMT_YUVJ444P] = {
- [PIX_FMT_RGB24] = {
- .convert = yuvj444p_to_rgb24
- },
- },
- [PIX_FMT_YUV422] = {
- [PIX_FMT_YUV420P] = {
- .convert = yuv422_to_yuv420p,
- },
- [PIX_FMT_YUV422P] = {
- .convert = yuv422_to_yuv422p,
- },
- },
- [PIX_FMT_UYVY422] = {
- [PIX_FMT_YUV420P] = {
- .convert = uyvy422_to_yuv420p,
- },
- [PIX_FMT_YUV422P] = {
- .convert = uyvy422_to_yuv422p,
- },
- },
- [PIX_FMT_RGB24] = {
- [PIX_FMT_YUV420P] = {
- .convert = rgb24_to_yuv420p
- },
- [PIX_FMT_RGB565] = {
- .convert = rgb24_to_rgb565
- },
- [PIX_FMT_RGB555] = {
- .convert = rgb24_to_rgb555
- },
- [PIX_FMT_RGBA32] = {
- .convert = rgb24_to_rgba32
- },
- [PIX_FMT_BGR24] = {
- .convert = rgb24_to_bgr24
- },
- [PIX_FMT_GRAY8] = {
- .convert = rgb24_to_gray
- },
- [PIX_FMT_PAL8] = {
- .convert = rgb24_to_pal8
- },
- [PIX_FMT_YUV444P] = {
- .convert = rgb24_to_yuv444p
- },
- [PIX_FMT_YUVJ420P] = {
- .convert = rgb24_to_yuvj420p
- },
- [PIX_FMT_YUVJ444P] = {
- .convert = rgb24_to_yuvj444p
- },
- },
- [PIX_FMT_RGBA32] = {
- [PIX_FMT_RGB24] = {
- .convert = rgba32_to_rgb24
- },
- [PIX_FMT_BGR24] = {
- .convert = rgba32_to_bgr24
- },
- [PIX_FMT_RGB565] = {
- .convert = rgba32_to_rgb565
- },
- [PIX_FMT_RGB555] = {
- .convert = rgba32_to_rgb555
- },
- [PIX_FMT_PAL8] = {
- .convert = rgba32_to_pal8
- },
- [PIX_FMT_YUV420P] = {
- .convert = rgba32_to_yuv420p
- },
- [PIX_FMT_GRAY8] = {
- .convert = rgba32_to_gray
- },
- },
- [PIX_FMT_BGR24] = {
- [PIX_FMT_RGBA32] = {
- .convert = bgr24_to_rgba32
- },
- [PIX_FMT_RGB24] = {
- .convert = bgr24_to_rgb24
- },
- [PIX_FMT_YUV420P] = {
- .convert = bgr24_to_yuv420p
- },
- [PIX_FMT_GRAY8] = {
- .convert = bgr24_to_gray
- },
- },
- [PIX_FMT_RGB555] = {
- [PIX_FMT_RGB24] = {
- .convert = rgb555_to_rgb24
- },
- [PIX_FMT_RGBA32] = {
- .convert = rgb555_to_rgba32
- },
- [PIX_FMT_YUV420P] = {
- .convert = rgb555_to_yuv420p
- },
- [PIX_FMT_GRAY8] = {
- .convert = rgb555_to_gray
- },
- },
- [PIX_FMT_RGB565] = {
- [PIX_FMT_RGBA32] = {
- .convert = rgb565_to_rgba32
- },
- [PIX_FMT_RGB24] = {
- .convert = rgb565_to_rgb24
- },
- [PIX_FMT_YUV420P] = {
- .convert = rgb565_to_yuv420p
- },
- [PIX_FMT_GRAY8] = {
- .convert = rgb565_to_gray
- },
- },
- [PIX_FMT_GRAY16BE] = {
- [PIX_FMT_GRAY8] = {
- .convert = gray16be_to_gray
- },
- [PIX_FMT_GRAY16LE] = {
- .convert = gray16_to_gray16
- },
- },
- [PIX_FMT_GRAY16LE] = {
- [PIX_FMT_GRAY8] = {
- .convert = gray16le_to_gray
- },
- [PIX_FMT_GRAY16BE] = {
- .convert = gray16_to_gray16
- },
- },
- [PIX_FMT_GRAY8] = {
- [PIX_FMT_RGB555] = {
- .convert = gray_to_rgb555
- },
- [PIX_FMT_RGB565] = {
- .convert = gray_to_rgb565
- },
- [PIX_FMT_RGB24] = {
- .convert = gray_to_rgb24
- },
- [PIX_FMT_BGR24] = {
- .convert = gray_to_bgr24
- },
- [PIX_FMT_RGBA32] = {
- .convert = gray_to_rgba32
- },
- [PIX_FMT_MONOWHITE] = {
- .convert = gray_to_monowhite
- },
- [PIX_FMT_MONOBLACK] = {
- .convert = gray_to_monoblack
- },
- [PIX_FMT_GRAY16LE] = {
- .convert = gray_to_gray16
- },
- [PIX_FMT_GRAY16BE] = {
- .convert = gray_to_gray16
- },
- },
- [PIX_FMT_MONOWHITE] = {
- [PIX_FMT_GRAY8] = {
- .convert = monowhite_to_gray
- },
- },
- [PIX_FMT_MONOBLACK] = {
- [PIX_FMT_GRAY8] = {
- .convert = monoblack_to_gray
- },
- },
- [PIX_FMT_PAL8] = {
- [PIX_FMT_RGB555] = {
- .convert = pal8_to_rgb555
- },
- [PIX_FMT_RGB565] = {
- .convert = pal8_to_rgb565
- },
- [PIX_FMT_BGR24] = {
- .convert = pal8_to_bgr24
- },
- [PIX_FMT_RGB24] = {
- .convert = pal8_to_rgb24
- },
- [PIX_FMT_RGBA32] = {
- .convert = pal8_to_rgba32
- },
- },
- [PIX_FMT_UYVY411] = {
- [PIX_FMT_YUV411P] = {
- .convert = uyvy411_to_yuv411p,
- },
- },
-
-};
-
-int avpicture_alloc(AVPicture *picture,
- int pix_fmt, int width, int height)
-{
- int size;
- void *ptr;
-
- size = avpicture_get_size(pix_fmt, width, height);
- if(size<0)
- goto fail;
- ptr = av_malloc(size);
- if (!ptr)
- goto fail;
- avpicture_fill(picture, ptr, pix_fmt, width, height);
- return 0;
- fail:
- memset(picture, 0, sizeof(AVPicture));
- return -1;
-}
-
-void avpicture_free(AVPicture *picture)
-{
- av_free(picture->data[0]);
-}
-
-/* return true if yuv planar */
-static inline int is_yuv_planar(const PixFmtInfo *ps)
-{
- return (ps->color_type == FF_COLOR_YUV ||
- ps->color_type == FF_COLOR_YUV_JPEG) &&
- ps->pixel_type == FF_PIXEL_PLANAR;
-}
-
-/**
- * Crop image top and left side
- */
-int img_crop(AVPicture *dst, const AVPicture *src,
- int pix_fmt, int top_band, int left_band)
-{
- int y_shift;
- int x_shift;
-
- 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;
-
- dst->data[0] = src->data[0] + (top_band * src->linesize[0]) + left_band;
- dst->data[1] = src->data[1] + ((top_band >> y_shift) * src->linesize[1]) + (left_band >> x_shift);
- dst->data[2] = src->data[2] + ((top_band >> y_shift) * src->linesize[2]) + (left_band >> x_shift);
-
- dst->linesize[0] = src->linesize[0];
- dst->linesize[1] = src->linesize[1];
- dst->linesize[2] = src->linesize[2];
- return 0;
-}
-
-/**
- * Pad image
- */
-int img_pad(AVPicture *dst, const AVPicture *src, int height, int width,
- int pix_fmt, int padtop, int padbottom, int padleft, int padright,
- int *color)
-{
- uint8_t *optr;
- int y_shift;
- int x_shift;
- int yheight;
- int i, y;
-
- if (pix_fmt < 0 || pix_fmt >= PIX_FMT_NB ||
- !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;
-
- if (padtop || padleft) {
- memset(dst->data[i], color[i],
- dst->linesize[i] * (padtop >> y_shift) + (padleft >> x_shift));
- }
-
- if (padleft || padright) {
- optr = dst->data[i] + dst->linesize[i] * (padtop >> y_shift) +
- (dst->linesize[i] - (padright >> x_shift));
- yheight = (height - 1 - (padtop + padbottom)) >> y_shift;
- for (y = 0; y < yheight; y++) {
- memset(optr, color[i], (padleft + padright) >> x_shift);
- optr += dst->linesize[i];
- }
- }
-
- if (src) { /* first line */
- uint8_t *iptr = src->data[i];
- optr = dst->data[i] + dst->linesize[i] * (padtop >> y_shift) +
- (padleft >> x_shift);
- memcpy(optr, iptr, src->linesize[i]);
- iptr += src->linesize[i];
- optr = dst->data[i] + dst->linesize[i] * (padtop >> y_shift) +
- (dst->linesize[i] - (padright >> x_shift));
- yheight = (height - 1 - (padtop + padbottom)) >> y_shift;
- for (y = 0; y < yheight; y++) {
- memset(optr, color[i], (padleft + padright) >> x_shift);
- memcpy(optr + ((padleft + padright) >> x_shift), iptr,
- src->linesize[i]);
- iptr += src->linesize[i];
- optr += dst->linesize[i];
- }
- }
-
- if (padbottom || padright) {
- optr = dst->data[i] + dst->linesize[i] *
- ((height - padbottom) >> y_shift) - (padright >> x_shift);
- memset(optr, color[i],dst->linesize[i] *
- (padbottom >> y_shift) + (padright >> x_shift));
- }
- }
- return 0;
-}
-
-#ifndef CONFIG_SWSCALER
-/* XXX: always use linesize. Return -1 if not supported */
-int img_convert(AVPicture *dst, int dst_pix_fmt,
- const AVPicture *src, int src_pix_fmt,
- int src_width, int src_height)
-{
- static int inited;
- int i, ret, dst_width, dst_height, int_pix_fmt;
- const PixFmtInfo *src_pix, *dst_pix;
- const ConvertEntry *ce;
- AVPicture tmp1, *tmp = &tmp1;
-
- if (src_pix_fmt < 0 || src_pix_fmt >= PIX_FMT_NB ||
- dst_pix_fmt < 0 || dst_pix_fmt >= PIX_FMT_NB)
- return -1;
- if (src_width <= 0 || src_height <= 0)
- return 0;
-
- if (!inited) {
- inited = 1;
- img_convert_init();
- }
-
- dst_width = src_width;
- dst_height = src_height;
-
- dst_pix = &pix_fmt_info[dst_pix_fmt];
- src_pix = &pix_fmt_info[src_pix_fmt];
- if (src_pix_fmt == dst_pix_fmt) {
- /* no conversion needed: just copy */
- img_copy(dst, src, dst_pix_fmt, dst_width, dst_height);
- return 0;
- }
-
- ce = &convert_table[src_pix_fmt][dst_pix_fmt];
- if (ce->convert) {
- /* specific conversion routine */
- ce->convert(dst, src, dst_width, dst_height);
- return 0;
- }
-
- /* gray to YUV */
- if (is_yuv_planar(dst_pix) &&
- src_pix_fmt == PIX_FMT_GRAY8) {
- int w, h, y;
- uint8_t *d;
-
- if (dst_pix->color_type == FF_COLOR_YUV_JPEG) {
- ff_img_copy_plane(dst->data[0], dst->linesize[0],
- src->data[0], src->linesize[0],
- dst_width, dst_height);
- } else {
- img_apply_table(dst->data[0], dst->linesize[0],
- src->data[0], src->linesize[0],
- dst_width, dst_height,
- y_jpeg_to_ccir);
- }
- /* fill U and V with 128 */
- w = dst_width;
- h = dst_height;
- w >>= dst_pix->x_chroma_shift;
- h >>= dst_pix->y_chroma_shift;
- for(i = 1; i <= 2; i++) {
- d = dst->data[i];
- for(y = 0; y< h; y++) {
- memset(d, 128, w);
- d += dst->linesize[i];
- }
- }
- return 0;
- }
-
- /* YUV to gray */
- if (is_yuv_planar(src_pix) &&
- dst_pix_fmt == PIX_FMT_GRAY8) {
- if (src_pix->color_type == FF_COLOR_YUV_JPEG) {
- ff_img_copy_plane(dst->data[0], dst->linesize[0],
- src->data[0], src->linesize[0],
- dst_width, dst_height);
- } else {
- img_apply_table(dst->data[0], dst->linesize[0],
- src->data[0], src->linesize[0],
- dst_width, dst_height,
- y_ccir_to_jpeg);
- }
- return 0;
- }
-
- /* YUV to YUV planar */
- if (is_yuv_planar(dst_pix) && is_yuv_planar(src_pix)) {
- int x_shift, y_shift, w, h, xy_shift;
- void (*resize_func)(uint8_t *dst, int dst_wrap,
- const uint8_t *src, int src_wrap,
- int width, int height);
-
- /* compute chroma size of the smallest dimensions */
- w = dst_width;
- h = dst_height;
- if (dst_pix->x_chroma_shift >= src_pix->x_chroma_shift)
- w >>= dst_pix->x_chroma_shift;
- else
- w >>= src_pix->x_chroma_shift;
- if (dst_pix->y_chroma_shift >= src_pix->y_chroma_shift)
- h >>= dst_pix->y_chroma_shift;
- else
- h >>= src_pix->y_chroma_shift;
-
- x_shift = (dst_pix->x_chroma_shift - src_pix->x_chroma_shift);
- y_shift = (dst_pix->y_chroma_shift - src_pix->y_chroma_shift);
- xy_shift = ((x_shift & 0xf) << 4) | (y_shift & 0xf);
- /* there must be filters for conversion at least from and to
- YUV444 format */
- switch(xy_shift) {
- case 0x00:
- resize_func = ff_img_copy_plane;
- break;
- case 0x10:
- resize_func = shrink21;
- break;
- case 0x20:
- resize_func = shrink41;
- break;
- case 0x01:
- resize_func = shrink12;
- break;
- case 0x11:
- resize_func = ff_shrink22;
- break;
- case 0x22:
- resize_func = ff_shrink44;
- break;
- case 0xf0:
- resize_func = grow21;
- break;
- case 0xe0:
- resize_func = grow41;
- break;
- case 0xff:
- resize_func = grow22;
- break;
- case 0xee:
- resize_func = grow44;
- break;
- case 0xf1:
- resize_func = conv411;
- break;
- default:
- /* currently not handled */
- goto no_chroma_filter;
- }
-
- ff_img_copy_plane(dst->data[0], dst->linesize[0],
- src->data[0], src->linesize[0],
- dst_width, dst_height);
-
- for(i = 1;i <= 2; i++)
- resize_func(dst->data[i], dst->linesize[i],
- src->data[i], src->linesize[i],
- dst_width>>dst_pix->x_chroma_shift, dst_height>>dst_pix->y_chroma_shift);
- /* if yuv color space conversion is needed, we do it here on
- the destination image */
- if (dst_pix->color_type != src_pix->color_type) {
- const uint8_t *y_table, *c_table;
- if (dst_pix->color_type == FF_COLOR_YUV) {
- y_table = y_jpeg_to_ccir;
- c_table = c_jpeg_to_ccir;
- } else {
- y_table = y_ccir_to_jpeg;
- c_table = c_ccir_to_jpeg;
- }
- img_apply_table(dst->data[0], dst->linesize[0],
- dst->data[0], dst->linesize[0],
- dst_width, dst_height,
- y_table);
-
- for(i = 1;i <= 2; i++)
- img_apply_table(dst->data[i], dst->linesize[i],
- dst->data[i], dst->linesize[i],
- dst_width>>dst_pix->x_chroma_shift,
- dst_height>>dst_pix->y_chroma_shift,
- c_table);
- }
- return 0;
- }
- no_chroma_filter:
-
- /* try to use an intermediate format */
- if (src_pix_fmt == PIX_FMT_YUV422 ||
- dst_pix_fmt == PIX_FMT_YUV422) {
- /* specific case: convert to YUV422P first */
- int_pix_fmt = PIX_FMT_YUV422P;
- } else if (src_pix_fmt == PIX_FMT_UYVY422 ||
- dst_pix_fmt == PIX_FMT_UYVY422) {
- /* specific case: convert to YUV422P first */
- int_pix_fmt = PIX_FMT_YUV422P;
- } else if (src_pix_fmt == PIX_FMT_UYVY411 ||
- dst_pix_fmt == PIX_FMT_UYVY411) {
- /* specific case: convert to YUV411P first */
- int_pix_fmt = PIX_FMT_YUV411P;
- } else if ((src_pix->color_type == FF_COLOR_GRAY &&
- src_pix_fmt != PIX_FMT_GRAY8) ||
- (dst_pix->color_type == FF_COLOR_GRAY &&
- dst_pix_fmt != PIX_FMT_GRAY8)) {
- /* gray8 is the normalized format */
- int_pix_fmt = PIX_FMT_GRAY8;
- } else if ((is_yuv_planar(src_pix) &&
- src_pix_fmt != PIX_FMT_YUV444P &&
- src_pix_fmt != PIX_FMT_YUVJ444P)) {
- /* yuv444 is the normalized format */
- if (src_pix->color_type == FF_COLOR_YUV_JPEG)
- int_pix_fmt = PIX_FMT_YUVJ444P;
- else
- int_pix_fmt = PIX_FMT_YUV444P;
- } else if ((is_yuv_planar(dst_pix) &&
- dst_pix_fmt != PIX_FMT_YUV444P &&
- dst_pix_fmt != PIX_FMT_YUVJ444P)) {
- /* yuv444 is the normalized format */
- if (dst_pix->color_type == FF_COLOR_YUV_JPEG)
- int_pix_fmt = PIX_FMT_YUVJ444P;
- else
- int_pix_fmt = PIX_FMT_YUV444P;
- } else {
- /* the two formats are rgb or gray8 or yuv[j]444p */
- if (src_pix->is_alpha && dst_pix->is_alpha)
- int_pix_fmt = PIX_FMT_RGBA32;
- else
- int_pix_fmt = PIX_FMT_RGB24;
- }
- if (avpicture_alloc(tmp, int_pix_fmt, dst_width, dst_height) < 0)
- return -1;
- ret = -1;
- if (img_convert(tmp, int_pix_fmt,
- src, src_pix_fmt, src_width, src_height) < 0)
- goto fail1;
- if (img_convert(dst, dst_pix_fmt,
- tmp, int_pix_fmt, dst_width, dst_height) < 0)
- goto fail1;
- ret = 0;
- fail1:
- avpicture_free(tmp);
- return ret;
-}
-#endif
-
-/* NOTE: we scan all the pixels to have an exact information */
-static int get_alpha_info_pal8(const AVPicture *src, int width, int height)
-{
- const unsigned char *p;
- int src_wrap, ret, x, y;
- unsigned int a;
- uint32_t *palette = (uint32_t *)src->data[1];
-
- p = src->data[0];
- src_wrap = src->linesize[0] - width;
- ret = 0;
- for(y=0;y<height;y++) {
- for(x=0;x<width;x++) {
- a = palette[p[0]] >> 24;
- if (a == 0x00) {
- ret |= FF_ALPHA_TRANSP;
- } else if (a != 0xff) {
- ret |= FF_ALPHA_SEMI_TRANSP;
- }
- p++;
- }
- p += src_wrap;
- }
- return ret;
-}
-
-/**
- * Tell if an image really has transparent alpha values.
- * @return ored mask of FF_ALPHA_xxx constants
- */
-int img_get_alpha_info(const AVPicture *src,
- int pix_fmt, int width, int height)
-{
- const PixFmtInfo *pf = &pix_fmt_info[pix_fmt];
- int ret;
-
- pf = &pix_fmt_info[pix_fmt];
- /* no alpha can be represented in format */
- if (!pf->is_alpha)
- return 0;
- switch(pix_fmt) {
- case PIX_FMT_RGBA32:
- ret = get_alpha_info_rgba32(src, width, height);
- break;
- case PIX_FMT_PAL8:
- ret = get_alpha_info_pal8(src, width, height);
- break;
- default:
- /* we do not know, so everything is indicated */
- ret = FF_ALPHA_TRANSP | FF_ALPHA_SEMI_TRANSP;
- break;
- }
- return ret;
-}
-
-#ifdef HAVE_MMX
-#define DEINT_INPLACE_LINE_LUM \
- movd_m2r(lum_m4[0],mm0);\
- movd_m2r(lum_m3[0],mm1);\
- movd_m2r(lum_m2[0],mm2);\
- movd_m2r(lum_m1[0],mm3);\
- movd_m2r(lum[0],mm4);\
- punpcklbw_r2r(mm7,mm0);\
- movd_r2m(mm2,lum_m4[0]);\
- punpcklbw_r2r(mm7,mm1);\
- punpcklbw_r2r(mm7,mm2);\
- punpcklbw_r2r(mm7,mm3);\
- punpcklbw_r2r(mm7,mm4);\
- paddw_r2r(mm3,mm1);\
- psllw_i2r(1,mm2);\
- paddw_r2r(mm4,mm0);\
- psllw_i2r(2,mm1);\
- paddw_r2r(mm6,mm2);\
- paddw_r2r(mm2,mm1);\
- psubusw_r2r(mm0,mm1);\
- psrlw_i2r(3,mm1);\
- packuswb_r2r(mm7,mm1);\
- movd_r2m(mm1,lum_m2[0]);
-
-#define DEINT_LINE_LUM \
- movd_m2r(lum_m4[0],mm0);\
- movd_m2r(lum_m3[0],mm1);\
- movd_m2r(lum_m2[0],mm2);\
- movd_m2r(lum_m1[0],mm3);\
- movd_m2r(lum[0],mm4);\
- punpcklbw_r2r(mm7,mm0);\
- punpcklbw_r2r(mm7,mm1);\
- punpcklbw_r2r(mm7,mm2);\
- punpcklbw_r2r(mm7,mm3);\
- punpcklbw_r2r(mm7,mm4);\
- paddw_r2r(mm3,mm1);\
- psllw_i2r(1,mm2);\
- paddw_r2r(mm4,mm0);\
- psllw_i2r(2,mm1);\
- paddw_r2r(mm6,mm2);\
- paddw_r2r(mm2,mm1);\
- psubusw_r2r(mm0,mm1);\
- psrlw_i2r(3,mm1);\
- packuswb_r2r(mm7,mm1);\
- movd_r2m(mm1,dst[0]);
-#endif
-
-/* filter parameters: [-1 4 2 4 -1] // 8 */
-static void deinterlace_line(uint8_t *dst,
- const uint8_t *lum_m4, const uint8_t *lum_m3,
- const uint8_t *lum_m2, const uint8_t *lum_m1,
- const uint8_t *lum,
- int size)
-{
-#ifndef HAVE_MMX
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
- int sum;
-
- for(;size > 0;size--) {
- sum = -lum_m4[0];
- sum += lum_m3[0] << 2;
- sum += lum_m2[0] << 1;
- sum += lum_m1[0] << 2;
- sum += -lum[0];
- dst[0] = cm[(sum + 4) >> 3];
- lum_m4++;
- lum_m3++;
- lum_m2++;
- lum_m1++;
- lum++;
- dst++;
- }
-#else
-
- {
- mmx_t rounder;
- rounder.uw[0]=4;
- rounder.uw[1]=4;
- rounder.uw[2]=4;
- rounder.uw[3]=4;
- pxor_r2r(mm7,mm7);
- movq_m2r(rounder,mm6);
- }
- for (;size > 3; size-=4) {
- DEINT_LINE_LUM
- lum_m4+=4;
- lum_m3+=4;
- lum_m2+=4;
- lum_m1+=4;
- lum+=4;
- dst+=4;
- }
-#endif
-}
-static void deinterlace_line_inplace(uint8_t *lum_m4, uint8_t *lum_m3, uint8_t *lum_m2, uint8_t *lum_m1, uint8_t *lum,
- int size)
-{
-#ifndef HAVE_MMX
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
- int sum;
-
- for(;size > 0;size--) {
- sum = -lum_m4[0];
- sum += lum_m3[0] << 2;
- sum += lum_m2[0] << 1;
- lum_m4[0]=lum_m2[0];
- sum += lum_m1[0] << 2;
- sum += -lum[0];
- lum_m2[0] = cm[(sum + 4) >> 3];
- lum_m4++;
- lum_m3++;
- lum_m2++;
- lum_m1++;
- lum++;
- }
-#else
-
- {
- mmx_t rounder;
- rounder.uw[0]=4;
- rounder.uw[1]=4;
- rounder.uw[2]=4;
- rounder.uw[3]=4;
- pxor_r2r(mm7,mm7);
- movq_m2r(rounder,mm6);
- }
- for (;size > 3; size-=4) {
- DEINT_INPLACE_LINE_LUM
- lum_m4+=4;
- lum_m3+=4;
- lum_m2+=4;
- lum_m1+=4;
- lum+=4;
- }
-#endif
-}
-
-/* deinterlacing : 2 temporal taps, 3 spatial taps linear filter. The
- top field is copied as is, but the bottom field is deinterlaced
- against the top field. */
-static void deinterlace_bottom_field(uint8_t *dst, int dst_wrap,
- const uint8_t *src1, int src_wrap,
- int width, int height)
-{
- const uint8_t *src_m2, *src_m1, *src_0, *src_p1, *src_p2;
- int y;
-
- src_m2 = src1;
- src_m1 = src1;
- src_0=&src_m1[src_wrap];
- src_p1=&src_0[src_wrap];
- src_p2=&src_p1[src_wrap];
- for(y=0;y<(height-2);y+=2) {
- memcpy(dst,src_m1,width);
- dst += dst_wrap;
- deinterlace_line(dst,src_m2,src_m1,src_0,src_p1,src_p2,width);
- src_m2 = src_0;
- src_m1 = src_p1;
- src_0 = src_p2;
- src_p1 += 2*src_wrap;
- src_p2 += 2*src_wrap;
- dst += dst_wrap;
- }
- memcpy(dst,src_m1,width);
- dst += dst_wrap;
- /* do last line */
- deinterlace_line(dst,src_m2,src_m1,src_0,src_0,src_0,width);
-}
-
-static void deinterlace_bottom_field_inplace(uint8_t *src1, int src_wrap,
- int width, int height)
-{
- uint8_t *src_m1, *src_0, *src_p1, *src_p2;
- int y;
- uint8_t *buf;
- buf = (uint8_t*)av_malloc(width);
-
- src_m1 = src1;
- memcpy(buf,src_m1,width);
- src_0=&src_m1[src_wrap];
- src_p1=&src_0[src_wrap];
- src_p2=&src_p1[src_wrap];
- for(y=0;y<(height-2);y+=2) {
- deinterlace_line_inplace(buf,src_m1,src_0,src_p1,src_p2,width);
- src_m1 = src_p1;
- src_0 = src_p2;
- src_p1 += 2*src_wrap;
- src_p2 += 2*src_wrap;
- }
- /* do last line */
- deinterlace_line_inplace(buf,src_m1,src_0,src_0,src_0,width);
- av_free(buf);
-}
-
-
-/* deinterlace - if not supported return -1 */
-int avpicture_deinterlace(AVPicture *dst, const AVPicture *src,
- int pix_fmt, int width, int height)
-{
- int i;
-
- if (pix_fmt != PIX_FMT_YUV420P &&
- pix_fmt != PIX_FMT_YUV422P &&
- pix_fmt != PIX_FMT_YUV444P &&
- pix_fmt != PIX_FMT_YUV411P)
- return -1;
- if ((width & 3) != 0 || (height & 3) != 0)
- return -1;
-
- for(i=0;i<3;i++) {
- if (i == 1) {
- switch(pix_fmt) {
- case PIX_FMT_YUV420P:
- width >>= 1;
- height >>= 1;
- break;
- case PIX_FMT_YUV422P:
- width >>= 1;
- break;
- case PIX_FMT_YUV411P:
- width >>= 2;
- break;
- default:
- break;
- }
- }
- if (src == dst) {
- deinterlace_bottom_field_inplace(dst->data[i], dst->linesize[i],
- width, height);
- } else {
- deinterlace_bottom_field(dst->data[i],dst->linesize[i],
- src->data[i], src->linesize[i],
- width, height);
- }
- }
-#ifdef HAVE_MMX
- emms();
-#endif
- return 0;
-}
-
-#undef FIX
diff --git a/src/libffmpeg/libavcodec/imgconvert_template.h b/src/libffmpeg/libavcodec/imgconvert_template.h
deleted file mode 100644
index 4cc898bab..000000000
--- a/src/libffmpeg/libavcodec/imgconvert_template.h
+++ /dev/null
@@ -1,875 +0,0 @@
-/*
- * Templates for image convertion routines
- * Copyright (c) 2001, 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
- */
-
-#ifndef RGB_OUT
-#define RGB_OUT(d, r, g, b) RGBA_OUT(d, r, g, b, 0xff)
-#endif
-
-static void glue(yuv420p_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- const uint8_t *y1_ptr, *y2_ptr, *cb_ptr, *cr_ptr;
- uint8_t *d, *d1, *d2;
- int w, y, cb, cr, r_add, g_add, b_add, width2;
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
- unsigned int r, g, b;
-
- d = dst->data[0];
- y1_ptr = src->data[0];
- cb_ptr = src->data[1];
- cr_ptr = src->data[2];
- width2 = (width + 1) >> 1;
- for(;height >= 2; height -= 2) {
- d1 = d;
- d2 = d + dst->linesize[0];
- y2_ptr = y1_ptr + src->linesize[0];
- for(w = width; w >= 2; w -= 2) {
- YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);
- /* output 4 pixels */
- YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
- RGB_OUT(d1, r, g, b);
-
- YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[1]);
- RGB_OUT(d1 + BPP, r, g, b);
-
- YUV_TO_RGB2_CCIR(r, g, b, y2_ptr[0]);
- RGB_OUT(d2, r, g, b);
-
- YUV_TO_RGB2_CCIR(r, g, b, y2_ptr[1]);
- RGB_OUT(d2 + BPP, r, g, b);
-
- d1 += 2 * BPP;
- d2 += 2 * BPP;
-
- y1_ptr += 2;
- y2_ptr += 2;
- cb_ptr++;
- cr_ptr++;
- }
- /* handle odd width */
- if (w) {
- YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);
- YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
- RGB_OUT(d1, r, g, b);
-
- YUV_TO_RGB2_CCIR(r, g, b, y2_ptr[0]);
- RGB_OUT(d2, r, g, b);
- d1 += BPP;
- d2 += BPP;
- y1_ptr++;
- y2_ptr++;
- cb_ptr++;
- cr_ptr++;
- }
- d += 2 * dst->linesize[0];
- y1_ptr += 2 * src->linesize[0] - width;
- cb_ptr += src->linesize[1] - width2;
- cr_ptr += src->linesize[2] - width2;
- }
- /* handle odd height */
- if (height) {
- d1 = d;
- for(w = width; w >= 2; w -= 2) {
- YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);
- /* output 2 pixels */
- YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
- RGB_OUT(d1, r, g, b);
-
- YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[1]);
- RGB_OUT(d1 + BPP, r, g, b);
-
- d1 += 2 * BPP;
-
- y1_ptr += 2;
- cb_ptr++;
- cr_ptr++;
- }
- /* handle width */
- if (w) {
- YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);
- /* output 2 pixels */
- YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
- RGB_OUT(d1, r, g, b);
- d1 += BPP;
-
- y1_ptr++;
- cb_ptr++;
- cr_ptr++;
- }
- }
-}
-
-static void glue(yuvj420p_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- const uint8_t *y1_ptr, *y2_ptr, *cb_ptr, *cr_ptr;
- uint8_t *d, *d1, *d2;
- int w, y, cb, cr, r_add, g_add, b_add, width2;
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
- unsigned int r, g, b;
-
- d = dst->data[0];
- y1_ptr = src->data[0];
- cb_ptr = src->data[1];
- cr_ptr = src->data[2];
- width2 = (width + 1) >> 1;
- for(;height >= 2; height -= 2) {
- d1 = d;
- d2 = d + dst->linesize[0];
- y2_ptr = y1_ptr + src->linesize[0];
- for(w = width; w >= 2; w -= 2) {
- YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
- /* output 4 pixels */
- YUV_TO_RGB2(r, g, b, y1_ptr[0]);
- RGB_OUT(d1, r, g, b);
-
- YUV_TO_RGB2(r, g, b, y1_ptr[1]);
- RGB_OUT(d1 + BPP, r, g, b);
-
- YUV_TO_RGB2(r, g, b, y2_ptr[0]);
- RGB_OUT(d2, r, g, b);
-
- YUV_TO_RGB2(r, g, b, y2_ptr[1]);
- RGB_OUT(d2 + BPP, r, g, b);
-
- d1 += 2 * BPP;
- d2 += 2 * BPP;
-
- y1_ptr += 2;
- y2_ptr += 2;
- cb_ptr++;
- cr_ptr++;
- }
- /* handle odd width */
- if (w) {
- YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
- YUV_TO_RGB2(r, g, b, y1_ptr[0]);
- RGB_OUT(d1, r, g, b);
-
- YUV_TO_RGB2(r, g, b, y2_ptr[0]);
- RGB_OUT(d2, r, g, b);
- d1 += BPP;
- d2 += BPP;
- y1_ptr++;
- y2_ptr++;
- cb_ptr++;
- cr_ptr++;
- }
- d += 2 * dst->linesize[0];
- y1_ptr += 2 * src->linesize[0] - width;
- cb_ptr += src->linesize[1] - width2;
- cr_ptr += src->linesize[2] - width2;
- }
- /* handle odd height */
- if (height) {
- d1 = d;
- for(w = width; w >= 2; w -= 2) {
- YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
- /* output 2 pixels */
- YUV_TO_RGB2(r, g, b, y1_ptr[0]);
- RGB_OUT(d1, r, g, b);
-
- YUV_TO_RGB2(r, g, b, y1_ptr[1]);
- RGB_OUT(d1 + BPP, r, g, b);
-
- d1 += 2 * BPP;
-
- y1_ptr += 2;
- cb_ptr++;
- cr_ptr++;
- }
- /* handle width */
- if (w) {
- YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
- /* output 2 pixels */
- YUV_TO_RGB2(r, g, b, y1_ptr[0]);
- RGB_OUT(d1, r, g, b);
- d1 += BPP;
-
- y1_ptr++;
- cb_ptr++;
- cr_ptr++;
- }
- }
-}
-
-static void glue(RGB_NAME, _to_yuv420p)(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- int wrap, wrap3, width2;
- int r, g, b, r1, g1, b1, w;
- uint8_t *lum, *cb, *cr;
- const uint8_t *p;
-
- lum = dst->data[0];
- cb = dst->data[1];
- cr = dst->data[2];
-
- width2 = (width + 1) >> 1;
- wrap = dst->linesize[0];
- wrap3 = src->linesize[0];
- p = src->data[0];
- for(;height>=2;height -= 2) {
- for(w = width; w >= 2; w -= 2) {
- RGB_IN(r, g, b, p);
- r1 = r;
- g1 = g;
- b1 = b;
- lum[0] = RGB_TO_Y_CCIR(r, g, b);
-
- RGB_IN(r, g, b, p + BPP);
- r1 += r;
- g1 += g;
- b1 += b;
- lum[1] = RGB_TO_Y_CCIR(r, g, b);
- p += wrap3;
- lum += wrap;
-
- RGB_IN(r, g, b, p);
- r1 += r;
- g1 += g;
- b1 += b;
- lum[0] = RGB_TO_Y_CCIR(r, g, b);
-
- RGB_IN(r, g, b, p + BPP);
- r1 += r;
- g1 += g;
- b1 += b;
- lum[1] = RGB_TO_Y_CCIR(r, g, b);
-
- cb[0] = RGB_TO_U_CCIR(r1, g1, b1, 2);
- cr[0] = RGB_TO_V_CCIR(r1, g1, b1, 2);
-
- cb++;
- cr++;
- p += -wrap3 + 2 * BPP;
- lum += -wrap + 2;
- }
- if (w) {
- RGB_IN(r, g, b, p);
- r1 = r;
- g1 = g;
- b1 = b;
- lum[0] = RGB_TO_Y_CCIR(r, g, b);
- p += wrap3;
- lum += wrap;
- RGB_IN(r, g, b, p);
- r1 += r;
- g1 += g;
- b1 += b;
- lum[0] = RGB_TO_Y_CCIR(r, g, b);
- cb[0] = RGB_TO_U_CCIR(r1, g1, b1, 1);
- cr[0] = RGB_TO_V_CCIR(r1, g1, b1, 1);
- cb++;
- cr++;
- p += -wrap3 + BPP;
- lum += -wrap + 1;
- }
- p += wrap3 + (wrap3 - width * BPP);
- lum += wrap + (wrap - width);
- cb += dst->linesize[1] - width2;
- cr += dst->linesize[2] - width2;
- }
- /* handle odd height */
- if (height) {
- for(w = width; w >= 2; w -= 2) {
- RGB_IN(r, g, b, p);
- r1 = r;
- g1 = g;
- b1 = b;
- lum[0] = RGB_TO_Y_CCIR(r, g, b);
-
- RGB_IN(r, g, b, p + BPP);
- r1 += r;
- g1 += g;
- b1 += b;
- lum[1] = RGB_TO_Y_CCIR(r, g, b);
- cb[0] = RGB_TO_U_CCIR(r1, g1, b1, 1);
- cr[0] = RGB_TO_V_CCIR(r1, g1, b1, 1);
- cb++;
- cr++;
- p += 2 * BPP;
- lum += 2;
- }
- if (w) {
- RGB_IN(r, g, b, p);
- lum[0] = RGB_TO_Y_CCIR(r, g, b);
- cb[0] = RGB_TO_U_CCIR(r, g, b, 0);
- cr[0] = RGB_TO_V_CCIR(r, g, b, 0);
- }
- }
-}
-
-static void glue(RGB_NAME, _to_gray)(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- const unsigned char *p;
- unsigned char *q;
- int r, g, b, dst_wrap, src_wrap;
- int x, y;
-
- p = src->data[0];
- src_wrap = src->linesize[0] - BPP * width;
-
- q = dst->data[0];
- dst_wrap = dst->linesize[0] - width;
-
- for(y=0;y<height;y++) {
- for(x=0;x<width;x++) {
- RGB_IN(r, g, b, p);
- q[0] = RGB_TO_Y(r, g, b);
- q++;
- p += BPP;
- }
- p += src_wrap;
- q += dst_wrap;
- }
-}
-
-static void glue(gray_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- const unsigned char *p;
- unsigned char *q;
- int r, dst_wrap, src_wrap;
- int x, y;
-
- p = src->data[0];
- src_wrap = src->linesize[0] - width;
-
- q = dst->data[0];
- dst_wrap = dst->linesize[0] - BPP * width;
-
- for(y=0;y<height;y++) {
- for(x=0;x<width;x++) {
- r = p[0];
- RGB_OUT(q, r, r, r);
- q += BPP;
- p ++;
- }
- p += src_wrap;
- q += dst_wrap;
- }
-}
-
-static void glue(pal8_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- const unsigned char *p;
- unsigned char *q;
- int r, g, b, dst_wrap, src_wrap;
- int x, y;
- uint32_t v;
- const uint32_t *palette;
-
- p = src->data[0];
- src_wrap = src->linesize[0] - width;
- palette = (uint32_t *)src->data[1];
-
- q = dst->data[0];
- dst_wrap = dst->linesize[0] - BPP * width;
-
- for(y=0;y<height;y++) {
- for(x=0;x<width;x++) {
- v = palette[p[0]];
- r = (v >> 16) & 0xff;
- g = (v >> 8) & 0xff;
- b = (v) & 0xff;
-#ifdef RGBA_OUT
- {
- int a;
- a = (v >> 24) & 0xff;
- RGBA_OUT(q, r, g, b, a);
- }
-#else
- RGB_OUT(q, r, g, b);
-#endif
- q += BPP;
- p ++;
- }
- p += src_wrap;
- q += dst_wrap;
- }
-}
-
-// RGB24 has optimised routines
-#if !defined(FMT_RGBA32) && !defined(FMT_RGB24)
-/* alpha support */
-
-static void glue(rgba32_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- const uint8_t *s;
- uint8_t *d;
- int src_wrap, dst_wrap, j, y;
- unsigned int v, r, g, b;
-#ifdef RGBA_OUT
- unsigned int a;
-#endif
-
- s = src->data[0];
- src_wrap = src->linesize[0] - width * 4;
-
- d = dst->data[0];
- dst_wrap = dst->linesize[0] - width * BPP;
-
- for(y=0;y<height;y++) {
- for(j = 0;j < width; j++) {
- v = ((const uint32_t *)(s))[0];
- r = (v >> 16) & 0xff;
- g = (v >> 8) & 0xff;
- b = v & 0xff;
-#ifdef RGBA_OUT
- a = (v >> 24) & 0xff;
- RGBA_OUT(d, r, g, b, a);
-#else
- RGB_OUT(d, r, g, b);
-#endif
- s += 4;
- d += BPP;
- }
- s += src_wrap;
- d += dst_wrap;
- }
-}
-
-static void glue(RGB_NAME, _to_rgba32)(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- const uint8_t *s;
- uint8_t *d;
- int src_wrap, dst_wrap, j, y;
- unsigned int r, g, b;
-#ifdef RGBA_IN
- unsigned int a;
-#endif
-
- s = src->data[0];
- src_wrap = src->linesize[0] - width * BPP;
-
- d = dst->data[0];
- dst_wrap = dst->linesize[0] - width * 4;
-
- for(y=0;y<height;y++) {
- for(j = 0;j < width; j++) {
-#ifdef RGBA_IN
- RGBA_IN(r, g, b, a, s);
- ((uint32_t *)(d))[0] = (a << 24) | (r << 16) | (g << 8) | b;
-#else
- RGB_IN(r, g, b, s);
- ((uint32_t *)(d))[0] = (0xff << 24) | (r << 16) | (g << 8) | b;
-#endif
- d += 4;
- s += BPP;
- }
- s += src_wrap;
- d += dst_wrap;
- }
-}
-
-#endif /* !defined(FMT_RGBA32) */
-
-#ifndef FMT_RGB24
-
-static void glue(rgb24_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- const uint8_t *s;
- uint8_t *d;
- int src_wrap, dst_wrap, j, y;
- unsigned int r, g, b;
-
- s = src->data[0];
- src_wrap = src->linesize[0] - width * 3;
-
- d = dst->data[0];
- dst_wrap = dst->linesize[0] - width * BPP;
-
- for(y=0;y<height;y++) {
- for(j = 0;j < width; j++) {
- r = s[0];
- g = s[1];
- b = s[2];
- RGB_OUT(d, r, g, b);
- s += 3;
- d += BPP;
- }
- s += src_wrap;
- d += dst_wrap;
- }
-}
-
-static void glue(RGB_NAME, _to_rgb24)(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- const uint8_t *s;
- uint8_t *d;
- int src_wrap, dst_wrap, j, y;
- unsigned int r, g , b;
-
- s = src->data[0];
- src_wrap = src->linesize[0] - width * BPP;
-
- d = dst->data[0];
- dst_wrap = dst->linesize[0] - width * 3;
-
- for(y=0;y<height;y++) {
- for(j = 0;j < width; j++) {
- RGB_IN(r, g, b, s)
- d[0] = r;
- d[1] = g;
- d[2] = b;
- d += 3;
- s += BPP;
- }
- s += src_wrap;
- d += dst_wrap;
- }
-}
-
-#endif /* !FMT_RGB24 */
-
-#ifdef FMT_RGB24
-
-static void yuv444p_to_rgb24(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- const uint8_t *y1_ptr, *cb_ptr, *cr_ptr;
- uint8_t *d, *d1;
- int w, y, cb, cr, r_add, g_add, b_add;
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
- unsigned int r, g, b;
-
- d = dst->data[0];
- y1_ptr = src->data[0];
- cb_ptr = src->data[1];
- cr_ptr = src->data[2];
- for(;height > 0; height --) {
- d1 = d;
- for(w = width; w > 0; w--) {
- YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);
-
- YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
- RGB_OUT(d1, r, g, b);
- d1 += BPP;
-
- y1_ptr++;
- cb_ptr++;
- cr_ptr++;
- }
- d += dst->linesize[0];
- y1_ptr += src->linesize[0] - width;
- cb_ptr += src->linesize[1] - width;
- cr_ptr += src->linesize[2] - width;
- }
-}
-
-static void yuvj444p_to_rgb24(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- const uint8_t *y1_ptr, *cb_ptr, *cr_ptr;
- uint8_t *d, *d1;
- int w, y, cb, cr, r_add, g_add, b_add;
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
- unsigned int r, g, b;
-
- d = dst->data[0];
- y1_ptr = src->data[0];
- cb_ptr = src->data[1];
- cr_ptr = src->data[2];
- for(;height > 0; height --) {
- d1 = d;
- for(w = width; w > 0; w--) {
- YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
-
- YUV_TO_RGB2(r, g, b, y1_ptr[0]);
- RGB_OUT(d1, r, g, b);
- d1 += BPP;
-
- y1_ptr++;
- cb_ptr++;
- cr_ptr++;
- }
- d += dst->linesize[0];
- y1_ptr += src->linesize[0] - width;
- cb_ptr += src->linesize[1] - width;
- cr_ptr += src->linesize[2] - width;
- }
-}
-
-static void rgb24_to_yuv444p(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- int src_wrap, x, y;
- int r, g, b;
- uint8_t *lum, *cb, *cr;
- const uint8_t *p;
-
- lum = dst->data[0];
- cb = dst->data[1];
- cr = dst->data[2];
-
- src_wrap = src->linesize[0] - width * BPP;
- p = src->data[0];
- for(y=0;y<height;y++) {
- for(x=0;x<width;x++) {
- RGB_IN(r, g, b, p);
- lum[0] = RGB_TO_Y_CCIR(r, g, b);
- cb[0] = RGB_TO_U_CCIR(r, g, b, 0);
- cr[0] = RGB_TO_V_CCIR(r, g, b, 0);
- p += BPP;
- cb++;
- cr++;
- lum++;
- }
- p += src_wrap;
- lum += dst->linesize[0] - width;
- cb += dst->linesize[1] - width;
- cr += dst->linesize[2] - width;
- }
-}
-
-static void rgb24_to_yuvj420p(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- int wrap, wrap3, width2;
- int r, g, b, r1, g1, b1, w;
- uint8_t *lum, *cb, *cr;
- const uint8_t *p;
-
- lum = dst->data[0];
- cb = dst->data[1];
- cr = dst->data[2];
-
- width2 = (width + 1) >> 1;
- wrap = dst->linesize[0];
- wrap3 = src->linesize[0];
- p = src->data[0];
- for(;height>=2;height -= 2) {
- for(w = width; w >= 2; w -= 2) {
- RGB_IN(r, g, b, p);
- r1 = r;
- g1 = g;
- b1 = b;
- lum[0] = RGB_TO_Y(r, g, b);
-
- RGB_IN(r, g, b, p + BPP);
- r1 += r;
- g1 += g;
- b1 += b;
- lum[1] = RGB_TO_Y(r, g, b);
- p += wrap3;
- lum += wrap;
-
- RGB_IN(r, g, b, p);
- r1 += r;
- g1 += g;
- b1 += b;
- lum[0] = RGB_TO_Y(r, g, b);
-
- RGB_IN(r, g, b, p + BPP);
- r1 += r;
- g1 += g;
- b1 += b;
- lum[1] = RGB_TO_Y(r, g, b);
-
- cb[0] = RGB_TO_U(r1, g1, b1, 2);
- cr[0] = RGB_TO_V(r1, g1, b1, 2);
-
- cb++;
- cr++;
- p += -wrap3 + 2 * BPP;
- lum += -wrap + 2;
- }
- if (w) {
- RGB_IN(r, g, b, p);
- r1 = r;
- g1 = g;
- b1 = b;
- lum[0] = RGB_TO_Y(r, g, b);
- p += wrap3;
- lum += wrap;
- RGB_IN(r, g, b, p);
- r1 += r;
- g1 += g;
- b1 += b;
- lum[0] = RGB_TO_Y(r, g, b);
- cb[0] = RGB_TO_U(r1, g1, b1, 1);
- cr[0] = RGB_TO_V(r1, g1, b1, 1);
- cb++;
- cr++;
- p += -wrap3 + BPP;
- lum += -wrap + 1;
- }
- p += wrap3 + (wrap3 - width * BPP);
- lum += wrap + (wrap - width);
- cb += dst->linesize[1] - width2;
- cr += dst->linesize[2] - width2;
- }
- /* handle odd height */
- if (height) {
- for(w = width; w >= 2; w -= 2) {
- RGB_IN(r, g, b, p);
- r1 = r;
- g1 = g;
- b1 = b;
- lum[0] = RGB_TO_Y(r, g, b);
-
- RGB_IN(r, g, b, p + BPP);
- r1 += r;
- g1 += g;
- b1 += b;
- lum[1] = RGB_TO_Y(r, g, b);
- cb[0] = RGB_TO_U(r1, g1, b1, 1);
- cr[0] = RGB_TO_V(r1, g1, b1, 1);
- cb++;
- cr++;
- p += 2 * BPP;
- lum += 2;
- }
- if (w) {
- RGB_IN(r, g, b, p);
- lum[0] = RGB_TO_Y(r, g, b);
- cb[0] = RGB_TO_U(r, g, b, 0);
- cr[0] = RGB_TO_V(r, g, b, 0);
- }
- }
-}
-
-static void rgb24_to_yuvj444p(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- int src_wrap, x, y;
- int r, g, b;
- uint8_t *lum, *cb, *cr;
- const uint8_t *p;
-
- lum = dst->data[0];
- cb = dst->data[1];
- cr = dst->data[2];
-
- src_wrap = src->linesize[0] - width * BPP;
- p = src->data[0];
- for(y=0;y<height;y++) {
- for(x=0;x<width;x++) {
- RGB_IN(r, g, b, p);
- lum[0] = RGB_TO_Y(r, g, b);
- cb[0] = RGB_TO_U(r, g, b, 0);
- cr[0] = RGB_TO_V(r, g, b, 0);
- p += BPP;
- cb++;
- cr++;
- lum++;
- }
- p += src_wrap;
- lum += dst->linesize[0] - width;
- cb += dst->linesize[1] - width;
- cr += dst->linesize[2] - width;
- }
-}
-
-#endif /* FMT_RGB24 */
-
-#if defined(FMT_RGB24) || defined(FMT_RGBA32)
-
-static void glue(RGB_NAME, _to_pal8)(AVPicture *dst, const AVPicture *src,
- int width, int height)
-{
- const unsigned char *p;
- unsigned char *q;
- int dst_wrap, src_wrap;
- int x, y, has_alpha;
- unsigned int r, g, b;
-
- p = src->data[0];
- src_wrap = src->linesize[0] - BPP * width;
-
- q = dst->data[0];
- dst_wrap = dst->linesize[0] - width;
- has_alpha = 0;
-
- for(y=0;y<height;y++) {
- for(x=0;x<width;x++) {
-#ifdef RGBA_IN
- {
- unsigned int a;
- RGBA_IN(r, g, b, a, p);
- /* crude approximation for alpha ! */
- if (a < 0x80) {
- has_alpha = 1;
- q[0] = TRANSP_INDEX;
- } else {
- q[0] = gif_clut_index(r, g, b);
- }
- }
-#else
- RGB_IN(r, g, b, p);
- q[0] = gif_clut_index(r, g, b);
-#endif
- q++;
- p += BPP;
- }
- p += src_wrap;
- q += dst_wrap;
- }
-
- build_rgb_palette(dst->data[1], has_alpha);
-}
-
-#endif /* defined(FMT_RGB24) || defined(FMT_RGBA32) */
-
-#ifdef RGBA_IN
-
-static int glue(get_alpha_info_, RGB_NAME)(const AVPicture *src,
- int width, int height)
-{
- const unsigned char *p;
- int src_wrap, ret, x, y;
- unsigned int r, g, b, a;
-
- p = src->data[0];
- src_wrap = src->linesize[0] - BPP * width;
- ret = 0;
- for(y=0;y<height;y++) {
- for(x=0;x<width;x++) {
- RGBA_IN(r, g, b, a, p);
- if (a == 0x00) {
- ret |= FF_ALPHA_TRANSP;
- } else if (a != 0xff) {
- ret |= FF_ALPHA_SEMI_TRANSP;
- }
- p += BPP;
- }
- p += src_wrap;
- }
- return ret;
-}
-
-#endif /* RGBA_IN */
-
-#undef RGB_IN
-#undef RGBA_IN
-#undef RGB_OUT
-#undef RGBA_OUT
-#undef BPP
-#undef RGB_NAME
-#undef FMT_RGB24
-#undef FMT_RGBA32
diff --git a/src/libffmpeg/libavcodec/imgresample.c b/src/libffmpeg/libavcodec/imgresample.c
deleted file mode 100644
index adcfd0481..000000000
--- a/src/libffmpeg/libavcodec/imgresample.c
+++ /dev/null
@@ -1,949 +0,0 @@
-/*
- * High quality image resampling with polyphase filters
- * Copyright (c) 2001 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 imgresample.c
- * High quality image resampling with polyphase filters .
- */
-
-#include "avcodec.h"
-#include "swscale.h"
-#include "dsputil.h"
-
-#ifdef USE_FASTMEMCPY
-#include "libvo/fastmemcpy.h"
-#endif
-
-#define NB_COMPONENTS 3
-
-#define PHASE_BITS 4
-#define NB_PHASES (1 << PHASE_BITS)
-#define NB_TAPS 4
-#define FCENTER 1 /* index of the center of the filter */
-//#define TEST 1 /* Test it */
-
-#define POS_FRAC_BITS 16
-#define POS_FRAC (1 << POS_FRAC_BITS)
-/* 6 bits precision is needed for MMX */
-#define FILTER_BITS 8
-
-#define LINE_BUF_HEIGHT (NB_TAPS * 4)
-
-struct SwsContext {
- struct ImgReSampleContext *resampling_ctx;
- enum PixelFormat src_pix_fmt, dst_pix_fmt;
-};
-
-struct ImgReSampleContext {
- int iwidth, iheight, owidth, oheight;
- int topBand, bottomBand, leftBand, rightBand;
- int padtop, padbottom, padleft, padright;
- int pad_owidth, pad_oheight;
- int h_incr, v_incr;
- DECLARE_ALIGNED_8(int16_t, h_filters[NB_PHASES][NB_TAPS]); /* horizontal filters */
- DECLARE_ALIGNED_8(int16_t, v_filters[NB_PHASES][NB_TAPS]); /* vertical filters */
- uint8_t *line_buf;
-};
-
-void av_build_filter(int16_t *filter, double factor, int tap_count, int phase_count, int scale, int type);
-
-static inline int get_phase(int pos)
-{
- return ((pos) >> (POS_FRAC_BITS - PHASE_BITS)) & ((1 << PHASE_BITS) - 1);
-}
-
-/* This function must be optimized */
-static void h_resample_fast(uint8_t *dst, int dst_width, const uint8_t *src,
- int src_width, int src_start, int src_incr,
- int16_t *filters)
-{
- int src_pos, phase, sum, i;
- const uint8_t *s;
- int16_t *filter;
-
- src_pos = src_start;
- for(i=0;i<dst_width;i++) {
-#ifdef TEST
- /* test */
- if ((src_pos >> POS_FRAC_BITS) < 0 ||
- (src_pos >> POS_FRAC_BITS) > (src_width - NB_TAPS))
- av_abort();
-#endif
- s = src + (src_pos >> POS_FRAC_BITS);
- phase = get_phase(src_pos);
- filter = filters + phase * NB_TAPS;
-#if NB_TAPS == 4
- sum = s[0] * filter[0] +
- s[1] * filter[1] +
- s[2] * filter[2] +
- s[3] * filter[3];
-#else
- {
- int j;
- sum = 0;
- for(j=0;j<NB_TAPS;j++)
- sum += s[j] * filter[j];
- }
-#endif
- sum = sum >> FILTER_BITS;
- if (sum < 0)
- sum = 0;
- else if (sum > 255)
- sum = 255;
- dst[0] = sum;
- src_pos += src_incr;
- dst++;
- }
-}
-
-/* This function must be optimized */
-static void v_resample(uint8_t *dst, int dst_width, const uint8_t *src,
- int wrap, int16_t *filter)
-{
- int sum, i;
- const uint8_t *s;
-
- s = src;
- for(i=0;i<dst_width;i++) {
-#if NB_TAPS == 4
- sum = s[0 * wrap] * filter[0] +
- s[1 * wrap] * filter[1] +
- s[2 * wrap] * filter[2] +
- s[3 * wrap] * filter[3];
-#else
- {
- int j;
- uint8_t *s1 = s;
-
- sum = 0;
- for(j=0;j<NB_TAPS;j++) {
- sum += s1[0] * filter[j];
- s1 += wrap;
- }
- }
-#endif
- sum = sum >> FILTER_BITS;
- if (sum < 0)
- sum = 0;
- else if (sum > 255)
- sum = 255;
- dst[0] = sum;
- dst++;
- s++;
- }
-}
-
-#ifdef HAVE_MMX
-
-#include "i386/mmx.h"
-
-#define FILTER4(reg) \
-{\
- s = src + (src_pos >> POS_FRAC_BITS);\
- phase = get_phase(src_pos);\
- filter = filters + phase * NB_TAPS;\
- movq_m2r(*s, reg);\
- punpcklbw_r2r(mm7, reg);\
- movq_m2r(*filter, mm6);\
- pmaddwd_r2r(reg, mm6);\
- movq_r2r(mm6, reg);\
- psrlq_i2r(32, reg);\
- paddd_r2r(mm6, reg);\
- psrad_i2r(FILTER_BITS, reg);\
- src_pos += src_incr;\
-}
-
-#define DUMP(reg) movq_r2m(reg, tmp); printf(#reg "=%016"PRIx64"\n", tmp.uq);
-
-/* XXX: do four pixels at a time */
-static void h_resample_fast4_mmx(uint8_t *dst, int dst_width,
- const uint8_t *src, int src_width,
- int src_start, int src_incr, int16_t *filters)
-{
- int src_pos, phase;
- const uint8_t *s;
- int16_t *filter;
- mmx_t tmp;
-
- src_pos = src_start;
- pxor_r2r(mm7, mm7);
-
- while (dst_width >= 4) {
-
- FILTER4(mm0);
- FILTER4(mm1);
- FILTER4(mm2);
- FILTER4(mm3);
-
- packuswb_r2r(mm7, mm0);
- packuswb_r2r(mm7, mm1);
- packuswb_r2r(mm7, mm3);
- packuswb_r2r(mm7, mm2);
- movq_r2m(mm0, tmp);
- dst[0] = tmp.ub[0];
- movq_r2m(mm1, tmp);
- dst[1] = tmp.ub[0];
- movq_r2m(mm2, tmp);
- dst[2] = tmp.ub[0];
- movq_r2m(mm3, tmp);
- dst[3] = tmp.ub[0];
- dst += 4;
- dst_width -= 4;
- }
- while (dst_width > 0) {
- FILTER4(mm0);
- packuswb_r2r(mm7, mm0);
- movq_r2m(mm0, tmp);
- dst[0] = tmp.ub[0];
- dst++;
- dst_width--;
- }
- emms();
-}
-
-static void v_resample4_mmx(uint8_t *dst, int dst_width, const uint8_t *src,
- int wrap, int16_t *filter)
-{
- int sum, i, v;
- const uint8_t *s;
- mmx_t tmp;
- mmx_t coefs[4];
-
- for(i=0;i<4;i++) {
- v = filter[i];
- coefs[i].uw[0] = v;
- coefs[i].uw[1] = v;
- coefs[i].uw[2] = v;
- coefs[i].uw[3] = v;
- }
-
- pxor_r2r(mm7, mm7);
- s = src;
- while (dst_width >= 4) {
- movq_m2r(s[0 * wrap], mm0);
- punpcklbw_r2r(mm7, mm0);
- movq_m2r(s[1 * wrap], mm1);
- punpcklbw_r2r(mm7, mm1);
- movq_m2r(s[2 * wrap], mm2);
- punpcklbw_r2r(mm7, mm2);
- movq_m2r(s[3 * wrap], mm3);
- punpcklbw_r2r(mm7, mm3);
-
- pmullw_m2r(coefs[0], mm0);
- pmullw_m2r(coefs[1], mm1);
- pmullw_m2r(coefs[2], mm2);
- pmullw_m2r(coefs[3], mm3);
-
- paddw_r2r(mm1, mm0);
- paddw_r2r(mm3, mm2);
- paddw_r2r(mm2, mm0);
- psraw_i2r(FILTER_BITS, mm0);
-
- packuswb_r2r(mm7, mm0);
- movq_r2m(mm0, tmp);
-
- *(uint32_t *)dst = tmp.ud[0];
- dst += 4;
- s += 4;
- dst_width -= 4;
- }
- while (dst_width > 0) {
- sum = s[0 * wrap] * filter[0] +
- s[1 * wrap] * filter[1] +
- s[2 * wrap] * filter[2] +
- s[3 * wrap] * filter[3];
- sum = sum >> FILTER_BITS;
- if (sum < 0)
- sum = 0;
- else if (sum > 255)
- sum = 255;
- dst[0] = sum;
- dst++;
- s++;
- dst_width--;
- }
- emms();
-}
-#endif
-
-#ifdef HAVE_ALTIVEC
-typedef union {
- vector unsigned char v;
- unsigned char c[16];
-} vec_uc_t;
-
-typedef union {
- vector signed short v;
- signed short s[8];
-} vec_ss_t;
-
-void v_resample16_altivec(uint8_t *dst, int dst_width, const uint8_t *src,
- int wrap, int16_t *filter)
-{
- int sum, i;
- const uint8_t *s;
- vector unsigned char *tv, tmp, dstv, zero;
- vec_ss_t srchv[4], srclv[4], fv[4];
- vector signed short zeros, sumhv, sumlv;
- s = src;
-
- for(i=0;i<4;i++)
- {
- /*
- The vec_madds later on does an implicit >>15 on the result.
- Since FILTER_BITS is 8, and we have 15 bits of magnitude in
- a signed short, we have just enough bits to pre-shift our
- filter constants <<7 to compensate for vec_madds.
- */
- fv[i].s[0] = filter[i] << (15-FILTER_BITS);
- fv[i].v = vec_splat(fv[i].v, 0);
- }
-
- zero = vec_splat_u8(0);
- zeros = vec_splat_s16(0);
-
-
- /*
- When we're resampling, we'd ideally like both our input buffers,
- and output buffers to be 16-byte aligned, so we can do both aligned
- reads and writes. Sadly we can't always have this at the moment, so
- we opt for aligned writes, as unaligned writes have a huge overhead.
- To do this, do enough scalar resamples to get dst 16-byte aligned.
- */
- i = (-(int)dst) & 0xf;
- while(i>0) {
- sum = s[0 * wrap] * filter[0] +
- s[1 * wrap] * filter[1] +
- s[2 * wrap] * filter[2] +
- s[3 * wrap] * filter[3];
- sum = sum >> FILTER_BITS;
- if (sum<0) sum = 0; else if (sum>255) sum=255;
- dst[0] = sum;
- dst++;
- s++;
- dst_width--;
- i--;
- }
-
- /* Do our altivec resampling on 16 pixels at once. */
- while(dst_width>=16) {
- /*
- Read 16 (potentially unaligned) bytes from each of
- 4 lines into 4 vectors, and split them into shorts.
- Interleave the multipy/accumulate for the resample
- filter with the loads to hide the 3 cycle latency
- the vec_madds have.
- */
- tv = (vector unsigned char *) &s[0 * wrap];
- tmp = vec_perm(tv[0], tv[1], vec_lvsl(0, &s[i * wrap]));
- srchv[0].v = (vector signed short) vec_mergeh(zero, tmp);
- srclv[0].v = (vector signed short) vec_mergel(zero, tmp);
- sumhv = vec_madds(srchv[0].v, fv[0].v, zeros);
- sumlv = vec_madds(srclv[0].v, fv[0].v, zeros);
-
- tv = (vector unsigned char *) &s[1 * wrap];
- tmp = vec_perm(tv[0], tv[1], vec_lvsl(0, &s[1 * wrap]));
- srchv[1].v = (vector signed short) vec_mergeh(zero, tmp);
- srclv[1].v = (vector signed short) vec_mergel(zero, tmp);
- sumhv = vec_madds(srchv[1].v, fv[1].v, sumhv);
- sumlv = vec_madds(srclv[1].v, fv[1].v, sumlv);
-
- tv = (vector unsigned char *) &s[2 * wrap];
- tmp = vec_perm(tv[0], tv[1], vec_lvsl(0, &s[2 * wrap]));
- srchv[2].v = (vector signed short) vec_mergeh(zero, tmp);
- srclv[2].v = (vector signed short) vec_mergel(zero, tmp);
- sumhv = vec_madds(srchv[2].v, fv[2].v, sumhv);
- sumlv = vec_madds(srclv[2].v, fv[2].v, sumlv);
-
- tv = (vector unsigned char *) &s[3 * wrap];
- tmp = vec_perm(tv[0], tv[1], vec_lvsl(0, &s[3 * wrap]));
- srchv[3].v = (vector signed short) vec_mergeh(zero, tmp);
- srclv[3].v = (vector signed short) vec_mergel(zero, tmp);
- sumhv = vec_madds(srchv[3].v, fv[3].v, sumhv);
- sumlv = vec_madds(srclv[3].v, fv[3].v, sumlv);
-
- /*
- Pack the results into our destination vector,
- and do an aligned write of that back to memory.
- */
- dstv = vec_packsu(sumhv, sumlv) ;
- vec_st(dstv, 0, (vector unsigned char *) dst);
-
- dst+=16;
- s+=16;
- dst_width-=16;
- }
-
- /*
- If there are any leftover pixels, resample them
- with the slow scalar method.
- */
- while(dst_width>0) {
- sum = s[0 * wrap] * filter[0] +
- s[1 * wrap] * filter[1] +
- s[2 * wrap] * filter[2] +
- s[3 * wrap] * filter[3];
- sum = sum >> FILTER_BITS;
- if (sum<0) sum = 0; else if (sum>255) sum=255;
- dst[0] = sum;
- dst++;
- s++;
- dst_width--;
- }
-}
-#endif
-
-/* slow version to handle limit cases. Does not need optimisation */
-static void h_resample_slow(uint8_t *dst, int dst_width,
- const uint8_t *src, int src_width,
- int src_start, int src_incr, int16_t *filters)
-{
- int src_pos, phase, sum, j, v, i;
- const uint8_t *s, *src_end;
- int16_t *filter;
-
- src_end = src + src_width;
- src_pos = src_start;
- for(i=0;i<dst_width;i++) {
- s = src + (src_pos >> POS_FRAC_BITS);
- phase = get_phase(src_pos);
- filter = filters + phase * NB_TAPS;
- sum = 0;
- for(j=0;j<NB_TAPS;j++) {
- if (s < src)
- v = src[0];
- else if (s >= src_end)
- v = src_end[-1];
- else
- v = s[0];
- sum += v * filter[j];
- s++;
- }
- sum = sum >> FILTER_BITS;
- if (sum < 0)
- sum = 0;
- else if (sum > 255)
- sum = 255;
- dst[0] = sum;
- src_pos += src_incr;
- dst++;
- }
-}
-
-static void h_resample(uint8_t *dst, int dst_width, const uint8_t *src,
- int src_width, int src_start, int src_incr,
- int16_t *filters)
-{
- int n, src_end;
-
- if (src_start < 0) {
- n = (0 - src_start + src_incr - 1) / src_incr;
- h_resample_slow(dst, n, src, src_width, src_start, src_incr, filters);
- dst += n;
- dst_width -= n;
- src_start += n * src_incr;
- }
- src_end = src_start + dst_width * src_incr;
- if (src_end > ((src_width - NB_TAPS) << POS_FRAC_BITS)) {
- n = (((src_width - NB_TAPS + 1) << POS_FRAC_BITS) - 1 - src_start) /
- src_incr;
- } else {
- n = dst_width;
- }
-#ifdef HAVE_MMX
- if ((mm_flags & MM_MMX) && NB_TAPS == 4)
- h_resample_fast4_mmx(dst, n,
- src, src_width, src_start, src_incr, filters);
- else
-#endif
- h_resample_fast(dst, n,
- src, src_width, src_start, src_incr, filters);
- if (n < dst_width) {
- dst += n;
- dst_width -= n;
- src_start += n * src_incr;
- h_resample_slow(dst, dst_width,
- src, src_width, src_start, src_incr, filters);
- }
-}
-
-static void component_resample(ImgReSampleContext *s,
- uint8_t *output, int owrap, int owidth, int oheight,
- uint8_t *input, int iwrap, int iwidth, int iheight)
-{
- int src_y, src_y1, last_src_y, ring_y, phase_y, y1, y;
- uint8_t *new_line, *src_line;
-
- last_src_y = - FCENTER - 1;
- /* position of the bottom of the filter in the source image */
- src_y = (last_src_y + NB_TAPS) * POS_FRAC;
- ring_y = NB_TAPS; /* position in ring buffer */
- for(y=0;y<oheight;y++) {
- /* apply horizontal filter on new lines from input if needed */
- src_y1 = src_y >> POS_FRAC_BITS;
- while (last_src_y < src_y1) {
- if (++ring_y >= LINE_BUF_HEIGHT + NB_TAPS)
- ring_y = NB_TAPS;
- last_src_y++;
- /* handle limit conditions : replicate line (slightly
- inefficient because we filter multiple times) */
- y1 = last_src_y;
- if (y1 < 0) {
- y1 = 0;
- } else if (y1 >= iheight) {
- y1 = iheight - 1;
- }
- src_line = input + y1 * iwrap;
- new_line = s->line_buf + ring_y * owidth;
- /* apply filter and handle limit cases correctly */
- h_resample(new_line, owidth,
- src_line, iwidth, - FCENTER * POS_FRAC, s->h_incr,
- &s->h_filters[0][0]);
- /* handle ring buffer wraping */
- if (ring_y >= LINE_BUF_HEIGHT) {
- memcpy(s->line_buf + (ring_y - LINE_BUF_HEIGHT) * owidth,
- new_line, owidth);
- }
- }
- /* apply vertical filter */
- phase_y = get_phase(src_y);
-#ifdef HAVE_MMX
- /* desactivated MMX because loss of precision */
- if ((mm_flags & MM_MMX) && NB_TAPS == 4 && 0)
- v_resample4_mmx(output, owidth,
- s->line_buf + (ring_y - NB_TAPS + 1) * owidth, owidth,
- &s->v_filters[phase_y][0]);
- else
-#endif
-#ifdef HAVE_ALTIVEC
- if ((mm_flags & MM_ALTIVEC) && NB_TAPS == 4 && FILTER_BITS <= 6)
- v_resample16_altivec(output, owidth,
- s->line_buf + (ring_y - NB_TAPS + 1) * owidth, owidth,
- &s->v_filters[phase_y][0]);
- else
-#endif
- v_resample(output, owidth,
- s->line_buf + (ring_y - NB_TAPS + 1) * owidth, owidth,
- &s->v_filters[phase_y][0]);
-
- src_y += s->v_incr;
-
- output += owrap;
- }
-}
-
-ImgReSampleContext *img_resample_init(int owidth, int oheight,
- int iwidth, int iheight)
-{
- return img_resample_full_init(owidth, oheight, iwidth, iheight,
- 0, 0, 0, 0, 0, 0, 0, 0);
-}
-
-ImgReSampleContext *img_resample_full_init(int owidth, int oheight,
- int iwidth, int iheight,
- int topBand, int bottomBand,
- int leftBand, int rightBand,
- int padtop, int padbottom,
- int padleft, int padright)
-{
- ImgReSampleContext *s;
-
- if (!owidth || !oheight || !iwidth || !iheight)
- return NULL;
-
- s = av_mallocz(sizeof(ImgReSampleContext));
- if (!s)
- return NULL;
- if((unsigned)owidth >= UINT_MAX / (LINE_BUF_HEIGHT + NB_TAPS))
- return NULL;
- s->line_buf = av_mallocz(owidth * (LINE_BUF_HEIGHT + NB_TAPS));
- if (!s->line_buf)
- goto fail;
-
- s->owidth = owidth;
- s->oheight = oheight;
- s->iwidth = iwidth;
- s->iheight = iheight;
-
- s->topBand = topBand;
- s->bottomBand = bottomBand;
- s->leftBand = leftBand;
- s->rightBand = rightBand;
-
- s->padtop = padtop;
- s->padbottom = padbottom;
- s->padleft = padleft;
- s->padright = padright;
-
- s->pad_owidth = owidth - (padleft + padright);
- s->pad_oheight = oheight - (padtop + padbottom);
-
- s->h_incr = ((iwidth - leftBand - rightBand) * POS_FRAC) / s->pad_owidth;
- s->v_incr = ((iheight - topBand - bottomBand) * POS_FRAC) / s->pad_oheight;
-
- av_build_filter(&s->h_filters[0][0], (float) s->pad_owidth /
- (float) (iwidth - leftBand - rightBand), NB_TAPS, NB_PHASES, 1<<FILTER_BITS, 0);
- av_build_filter(&s->v_filters[0][0], (float) s->pad_oheight /
- (float) (iheight - topBand - bottomBand), NB_TAPS, NB_PHASES, 1<<FILTER_BITS, 0);
-
- return s;
-fail:
- av_free(s);
- return NULL;
-}
-
-void img_resample(ImgReSampleContext *s,
- AVPicture *output, const AVPicture *input)
-{
- int i, shift;
- uint8_t* optr;
-
- for (i=0;i<3;i++) {
- shift = (i == 0) ? 0 : 1;
-
- optr = output->data[i] + (((output->linesize[i] *
- s->padtop) + s->padleft) >> shift);
-
- component_resample(s, optr, output->linesize[i],
- s->pad_owidth >> shift, s->pad_oheight >> shift,
- input->data[i] + (input->linesize[i] *
- (s->topBand >> shift)) + (s->leftBand >> shift),
- input->linesize[i], ((s->iwidth - s->leftBand -
- s->rightBand) >> shift),
- (s->iheight - s->topBand - s->bottomBand) >> shift);
- }
-}
-
-void img_resample_close(ImgReSampleContext *s)
-{
- av_free(s->line_buf);
- av_free(s);
-}
-
-struct SwsContext *sws_getContext(int srcW, int srcH, int srcFormat,
- int dstW, int dstH, int dstFormat,
- int flags, SwsFilter *srcFilter,
- SwsFilter *dstFilter, double *param)
-{
- struct SwsContext *ctx;
-
- ctx = av_malloc(sizeof(struct SwsContext));
- if (ctx == NULL) {
- av_log(NULL, AV_LOG_ERROR, "Cannot allocate a resampling context!\n");
-
- return NULL;
- }
-
- if ((srcH != dstH) || (srcW != dstW)) {
- if ((srcFormat != PIX_FMT_YUV420P) || (dstFormat != PIX_FMT_YUV420P)) {
- av_log(NULL, AV_LOG_INFO, "PIX_FMT_YUV420P will be used as an intermediate format for rescaling\n");
- }
- ctx->resampling_ctx = img_resample_init(dstW, dstH, srcW, srcH);
- } else {
- ctx->resampling_ctx = av_malloc(sizeof(ImgReSampleContext));
- ctx->resampling_ctx->iheight = srcH;
- ctx->resampling_ctx->iwidth = srcW;
- ctx->resampling_ctx->oheight = dstH;
- ctx->resampling_ctx->owidth = dstW;
- }
- ctx->src_pix_fmt = srcFormat;
- ctx->dst_pix_fmt = dstFormat;
-
- return ctx;
-}
-
-void sws_freeContext(struct SwsContext *ctx)
-{
- if (!ctx)
- return;
- if ((ctx->resampling_ctx->iwidth != ctx->resampling_ctx->owidth) ||
- (ctx->resampling_ctx->iheight != ctx->resampling_ctx->oheight)) {
- img_resample_close(ctx->resampling_ctx);
- } else {
- av_free(ctx->resampling_ctx);
- }
- av_free(ctx);
-}
-
-
-/**
- * Checks if context is valid or reallocs a new one instead.
- * If context is NULL, just calls sws_getContext() to get a new one.
- * Otherwise, checks if the parameters are the same already saved in context.
- * If that is the case, returns the current context.
- * Otherwise, frees context and gets a new one.
- *
- * Be warned that srcFilter, dstFilter are not checked, they are
- * asumed to remain valid.
- */
-struct SwsContext *sws_getCachedContext(struct SwsContext *ctx,
- int srcW, int srcH, int srcFormat,
- int dstW, int dstH, int dstFormat, int flags,
- SwsFilter *srcFilter, SwsFilter *dstFilter, double *param)
-{
- if (ctx != NULL) {
- if ((ctx->resampling_ctx->iwidth != srcW) ||
- (ctx->resampling_ctx->iheight != srcH) ||
- (ctx->src_pix_fmt != srcFormat) ||
- (ctx->resampling_ctx->owidth != dstW) ||
- (ctx->resampling_ctx->oheight != dstH) ||
- (ctx->dst_pix_fmt != dstFormat))
- {
- sws_freeContext(ctx);
- ctx = NULL;
- }
- }
- if (ctx == NULL) {
- return sws_getContext(srcW, srcH, srcFormat,
- dstW, dstH, dstFormat, flags,
- srcFilter, dstFilter, param);
- }
- return ctx;
-}
-
-int sws_scale(struct SwsContext *ctx, uint8_t* src[], int srcStride[],
- int srcSliceY, int srcSliceH, uint8_t* dst[], int dstStride[])
-{
- AVPicture src_pict, dst_pict;
- int i, res = 0;
- AVPicture picture_format_temp;
- AVPicture picture_resample_temp, *formatted_picture, *resampled_picture;
- uint8_t *buf1 = NULL, *buf2 = NULL;
- enum PixelFormat current_pix_fmt;
-
- for (i = 0; i < 4; i++) {
- src_pict.data[i] = src[i];
- src_pict.linesize[i] = srcStride[i];
- dst_pict.data[i] = dst[i];
- dst_pict.linesize[i] = dstStride[i];
- }
- if ((ctx->resampling_ctx->iwidth != ctx->resampling_ctx->owidth) ||
- (ctx->resampling_ctx->iheight != ctx->resampling_ctx->oheight)) {
- /* We have to rescale the picture, but only YUV420P rescaling is supported... */
-
- if (ctx->src_pix_fmt != PIX_FMT_YUV420P) {
- int size;
-
- /* create temporary picture for rescaling input*/
- size = avpicture_get_size(PIX_FMT_YUV420P, ctx->resampling_ctx->iwidth, ctx->resampling_ctx->iheight);
- buf1 = av_malloc(size);
- if (!buf1) {
- res = -1;
- goto the_end;
- }
- formatted_picture = &picture_format_temp;
- avpicture_fill((AVPicture*)formatted_picture, buf1,
- PIX_FMT_YUV420P, ctx->resampling_ctx->iwidth, ctx->resampling_ctx->iheight);
-
- if (img_convert((AVPicture*)formatted_picture, PIX_FMT_YUV420P,
- &src_pict, ctx->src_pix_fmt,
- ctx->resampling_ctx->iwidth, ctx->resampling_ctx->iheight) < 0) {
-
- av_log(NULL, AV_LOG_ERROR, "pixel format conversion not handled\n");
- res = -1;
- goto the_end;
- }
- } else {
- formatted_picture = &src_pict;
- }
-
- if (ctx->dst_pix_fmt != PIX_FMT_YUV420P) {
- int size;
-
- /* create temporary picture for rescaling output*/
- size = avpicture_get_size(PIX_FMT_YUV420P, ctx->resampling_ctx->owidth, ctx->resampling_ctx->oheight);
- buf2 = av_malloc(size);
- if (!buf2) {
- res = -1;
- goto the_end;
- }
- resampled_picture = &picture_resample_temp;
- avpicture_fill((AVPicture*)resampled_picture, buf2,
- PIX_FMT_YUV420P, ctx->resampling_ctx->owidth, ctx->resampling_ctx->oheight);
-
- } else {
- resampled_picture = &dst_pict;
- }
-
- /* ...and finally rescale!!! */
- img_resample(ctx->resampling_ctx, resampled_picture, formatted_picture);
- current_pix_fmt = PIX_FMT_YUV420P;
- } else {
- resampled_picture = &src_pict;
- current_pix_fmt = ctx->src_pix_fmt;
- }
-
- if (current_pix_fmt != ctx->dst_pix_fmt) {
- if (img_convert(&dst_pict, ctx->dst_pix_fmt,
- resampled_picture, current_pix_fmt,
- ctx->resampling_ctx->owidth, ctx->resampling_ctx->oheight) < 0) {
-
- av_log(NULL, AV_LOG_ERROR, "pixel format conversion not handled\n");
-
- res = -1;
- goto the_end;
- }
- } else if (resampled_picture != &dst_pict) {
- img_copy(&dst_pict, resampled_picture, current_pix_fmt,
- ctx->resampling_ctx->owidth, ctx->resampling_ctx->oheight);
- }
-
-the_end:
- av_free(buf1);
- av_free(buf2);
- return res;
-}
-
-
-#ifdef TEST
-#include <stdio.h>
-
-/* input */
-#define XSIZE 256
-#define YSIZE 256
-uint8_t img[XSIZE * YSIZE];
-
-/* output */
-#define XSIZE1 512
-#define YSIZE1 512
-uint8_t img1[XSIZE1 * YSIZE1];
-uint8_t img2[XSIZE1 * YSIZE1];
-
-void save_pgm(const char *filename, uint8_t *img, int xsize, int ysize)
-{
-#undef fprintf
- FILE *f;
- f=fopen(filename,"w");
- fprintf(f,"P5\n%d %d\n%d\n", xsize, ysize, 255);
- fwrite(img,1, xsize * ysize,f);
- fclose(f);
-#define fprintf please_use_av_log
-}
-
-static void dump_filter(int16_t *filter)
-{
- int i, ph;
-
- for(ph=0;ph<NB_PHASES;ph++) {
- av_log(NULL, AV_LOG_INFO, "%2d: ", ph);
- for(i=0;i<NB_TAPS;i++) {
- av_log(NULL, AV_LOG_INFO, " %5.2f", filter[ph * NB_TAPS + i] / 256.0);
- }
- av_log(NULL, AV_LOG_INFO, "\n");
- }
-}
-
-#ifdef HAVE_MMX
-int mm_flags;
-#endif
-
-int main(int argc, char **argv)
-{
- int x, y, v, i, xsize, ysize;
- ImgReSampleContext *s;
- float fact, factors[] = { 1/2.0, 3.0/4.0, 1.0, 4.0/3.0, 16.0/9.0, 2.0 };
- char buf[256];
-
- /* build test image */
- for(y=0;y<YSIZE;y++) {
- for(x=0;x<XSIZE;x++) {
- if (x < XSIZE/2 && y < YSIZE/2) {
- if (x < XSIZE/4 && y < YSIZE/4) {
- if ((x % 10) <= 6 &&
- (y % 10) <= 6)
- v = 0xff;
- else
- v = 0x00;
- } else if (x < XSIZE/4) {
- if (x & 1)
- v = 0xff;
- else
- v = 0;
- } else if (y < XSIZE/4) {
- if (y & 1)
- v = 0xff;
- else
- v = 0;
- } else {
- if (y < YSIZE*3/8) {
- if ((y+x) & 1)
- v = 0xff;
- else
- v = 0;
- } else {
- if (((x+3) % 4) <= 1 &&
- ((y+3) % 4) <= 1)
- v = 0xff;
- else
- v = 0x00;
- }
- }
- } else if (x < XSIZE/2) {
- v = ((x - (XSIZE/2)) * 255) / (XSIZE/2);
- } else if (y < XSIZE/2) {
- v = ((y - (XSIZE/2)) * 255) / (XSIZE/2);
- } else {
- v = ((x + y - XSIZE) * 255) / XSIZE;
- }
- img[(YSIZE - y) * XSIZE + (XSIZE - x)] = v;
- }
- }
- save_pgm("/tmp/in.pgm", img, XSIZE, YSIZE);
- for(i=0;i<sizeof(factors)/sizeof(float);i++) {
- fact = factors[i];
- xsize = (int)(XSIZE * fact);
- ysize = (int)((YSIZE - 100) * fact);
- s = img_resample_full_init(xsize, ysize, XSIZE, YSIZE, 50 ,50, 0, 0, 0, 0, 0, 0);
- av_log(NULL, AV_LOG_INFO, "Factor=%0.2f\n", fact);
- dump_filter(&s->h_filters[0][0]);
- component_resample(s, img1, xsize, xsize, ysize,
- img + 50 * XSIZE, XSIZE, XSIZE, YSIZE - 100);
- img_resample_close(s);
-
- snprintf(buf, sizeof(buf), "/tmp/out%d.pgm", i);
- save_pgm(buf, img1, xsize, ysize);
- }
-
- /* mmx test */
-#ifdef HAVE_MMX
- av_log(NULL, AV_LOG_INFO, "MMX test\n");
- fact = 0.72;
- xsize = (int)(XSIZE * fact);
- ysize = (int)(YSIZE * fact);
- mm_flags = MM_MMX;
- s = img_resample_init(xsize, ysize, XSIZE, YSIZE);
- component_resample(s, img1, xsize, xsize, ysize,
- img, XSIZE, XSIZE, YSIZE);
-
- mm_flags = 0;
- s = img_resample_init(xsize, ysize, XSIZE, YSIZE);
- component_resample(s, img2, xsize, xsize, ysize,
- img, XSIZE, XSIZE, YSIZE);
- if (memcmp(img1, img2, xsize * ysize) != 0) {
- av_log(NULL, AV_LOG_ERROR, "mmx error\n");
- exit(1);
- }
- av_log(NULL, AV_LOG_INFO, "MMX OK\n");
-#endif
- return 0;
-}
-
-#endif
diff --git a/src/libffmpeg/libavcodec/indeo2.c b/src/libffmpeg/libavcodec/indeo2.c
deleted file mode 100644
index f3917ff3a..000000000
--- a/src/libffmpeg/libavcodec/indeo2.c
+++ /dev/null
@@ -1,221 +0,0 @@
-/*
- * Intel Indeo 2 codec
- * Copyright (c) 2005 Konstantin Shishkov
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-/**
- * @file indeo2.c
- * Intel Indeo 2 decoder.
- */
-#define ALT_BITSTREAM_READER_LE
-#include "avcodec.h"
-#include "bitstream.h"
-#include "indeo2data.h"
-
-typedef struct Ir2Context{
- AVCodecContext *avctx;
- AVFrame picture;
- GetBitContext gb;
- int decode_delta;
-} Ir2Context;
-
-#define CODE_VLC_BITS 14
-static VLC ir2_vlc;
-
-/* Indeo 2 codes are in range 0x01..0x7F and 0x81..0x90 */
-static inline int ir2_get_code(GetBitContext *gb)
-{
- return get_vlc2(gb, ir2_vlc.table, CODE_VLC_BITS, 1) + 1;
-}
-
-static int ir2_decode_plane(Ir2Context *ctx, int width, int height, uint8_t *dst, int stride,
- const uint8_t *table)
-{
- int i;
- int j;
- int out = 0;
- int c;
- int t;
-
- if(width&1)
- return -1;
-
- /* first line contain absolute values, other lines contain deltas */
- while (out < width){
- c = ir2_get_code(&ctx->gb);
- if(c >= 0x80) { /* we have a run */
- c -= 0x7F;
- if(out + c*2 > width)
- return -1;
- for (i = 0; i < c * 2; i++)
- dst[out++] = 0x80;
- } else { /* copy two values from table */
- dst[out++] = table[c * 2];
- dst[out++] = table[(c * 2) + 1];
- }
- }
- dst += stride;
-
- for (j = 1; j < height; j++){
- out = 0;
- while (out < width){
- c = ir2_get_code(&ctx->gb);
- if(c >= 0x80) { /* we have a skip */
- c -= 0x7F;
- if(out + c*2 > width)
- return -1;
- for (i = 0; i < c * 2; i++) {
- dst[out] = dst[out - stride];
- out++;
- }
- } else { /* add two deltas from table */
- t = dst[out - stride] + (table[c * 2] - 128);
- t= clip_uint8(t);
- dst[out] = t;
- out++;
- t = dst[out - stride] + (table[(c * 2) + 1] - 128);
- t= clip_uint8(t);
- dst[out] = t;
- out++;
- }
- }
- dst += stride;
- }
- return 0;
-}
-
-static int ir2_decode_plane_inter(Ir2Context *ctx, int width, int height, uint8_t *dst, int stride,
- const uint8_t *table)
-{
- int j;
- int out = 0;
- int c;
- int t;
-
- if(width&1)
- return -1;
-
- for (j = 0; j < height; j++){
- out = 0;
- while (out < width){
- c = ir2_get_code(&ctx->gb);
- if(c >= 0x80) { /* we have a skip */
- c -= 0x7F;
- out += c * 2;
- } else { /* add two deltas from table */
- t = dst[out] + (((table[c * 2] - 128)*3) >> 2);
- t= clip_uint8(t);
- dst[out] = t;
- out++;
- t = dst[out] + (((table[(c * 2) + 1] - 128)*3) >> 2);
- t= clip_uint8(t);
- dst[out] = t;
- out++;
- }
- }
- dst += stride;
- }
- return 0;
-}
-
-static int ir2_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- Ir2Context * const s = avctx->priv_data;
- AVFrame *picture = data;
- AVFrame * const p= (AVFrame*)&s->picture;
- int start;
-
- if(p->data[0])
- avctx->release_buffer(avctx, p);
-
- p->reference = 1;
- p->buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
- if (avctx->reget_buffer(avctx, p)) {
- av_log(s->avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
- return -1;
- }
-
- s->decode_delta = buf[18];
-
- /* 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]];
-#endif
- start = 48; /* hardcoded for now */
-
- init_get_bits(&s->gb, buf + start, buf_size - start);
-
- if (s->decode_delta) { /* intraframe */
- ir2_decode_plane(s, avctx->width, avctx->height,
- s->picture.data[0], s->picture.linesize[0], ir2_luma_table);
- /* swapped U and V */
- ir2_decode_plane(s, avctx->width >> 2, avctx->height >> 2,
- s->picture.data[2], s->picture.linesize[2], ir2_luma_table);
- ir2_decode_plane(s, avctx->width >> 2, avctx->height >> 2,
- s->picture.data[1], s->picture.linesize[1], ir2_luma_table);
- } else { /* interframe */
- ir2_decode_plane_inter(s, avctx->width, avctx->height,
- s->picture.data[0], s->picture.linesize[0], ir2_luma_table);
- /* swapped U and V */
- ir2_decode_plane_inter(s, avctx->width >> 2, avctx->height >> 2,
- s->picture.data[2], s->picture.linesize[2], ir2_luma_table);
- ir2_decode_plane_inter(s, avctx->width >> 2, avctx->height >> 2,
- s->picture.data[1], s->picture.linesize[1], ir2_luma_table);
- }
-
- *picture= *(AVFrame*)&s->picture;
- *data_size = sizeof(AVPicture);
-
- return buf_size;
-}
-
-static int ir2_decode_init(AVCodecContext *avctx){
- Ir2Context * const ic = avctx->priv_data;
-
- ic->avctx = avctx;
-
- avctx->pix_fmt= PIX_FMT_YUV410P;
-
- if (!ir2_vlc.table)
- init_vlc(&ir2_vlc, CODE_VLC_BITS, IR2_CODES,
- &ir2_codes[0][1], 4, 2,
-#ifdef ALT_BITSTREAM_READER_LE
- &ir2_codes[0][0], 4, 2, INIT_VLC_USE_STATIC | INIT_VLC_LE);
-#else
- &ir2_codes[0][0], 4, 2, INIT_VLC_USE_STATIC);
-#endif
-
- return 0;
-}
-
-AVCodec indeo2_decoder = {
- "indeo2",
- CODEC_TYPE_VIDEO,
- CODEC_ID_INDEO2,
- sizeof(Ir2Context),
- ir2_decode_init,
- NULL,
- NULL,
- ir2_decode_frame,
- CODEC_CAP_DR1,
-};
diff --git a/src/libffmpeg/libavcodec/indeo3.c b/src/libffmpeg/libavcodec/indeo3.c
deleted file mode 100644
index 33dcff820..000000000
--- a/src/libffmpeg/libavcodec/indeo3.c
+++ /dev/null
@@ -1,1153 +0,0 @@
-/*
- * Intel Indeo 3 (IV31, IV32, etc.) video decoder for ffmpeg
- * written, produced, and directed by Alan Smithee
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General 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 <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "common.h"
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-
-#include "indeo3data.h"
-
-typedef struct
-{
- unsigned char *Ybuf;
- unsigned char *Ubuf;
- unsigned char *Vbuf;
- unsigned char *the_buf;
- unsigned int the_buf_size;
- unsigned short y_w, y_h;
- unsigned short uv_w, uv_h;
-} YUVBufs;
-
-typedef struct Indeo3DecodeContext {
- AVCodecContext *avctx;
- int width, height;
- AVFrame frame;
-
- YUVBufs iv_frame[2];
- YUVBufs *cur_frame;
- YUVBufs *ref_frame;
-
- unsigned char *ModPred;
- unsigned short *corrector_type;
-} Indeo3DecodeContext;
-
-static int corrector_type_0[24] = {
- 195, 159, 133, 115, 101, 93, 87, 77,
- 195, 159, 133, 115, 101, 93, 87, 77,
- 128, 79, 79, 79, 79, 79, 79, 79
-};
-
-static int corrector_type_2[8] = { 9, 7, 6, 8, 5, 4, 3, 2 };
-
-static void build_modpred(Indeo3DecodeContext *s)
-{
- int i, j;
-
- s->ModPred = (unsigned char *) av_malloc (8 * 128);
-
- for (i=0; i < 128; ++i) {
- s->ModPred[i+0*128] = (i > 126) ? 254 : 2*((i + 1) - ((i + 1) % 2));
- s->ModPred[i+1*128] = (i == 7) ? 20 : ((i == 119 || i == 120)
- ? 236 : 2*((i + 2) - ((i + 1) % 3)));
- s->ModPred[i+2*128] = (i > 125) ? 248 : 2*((i + 2) - ((i + 2) % 4));
- s->ModPred[i+3*128] = 2*((i + 1) - ((i - 3) % 5));
- s->ModPred[i+4*128] = (i == 8) ? 20 : 2*((i + 1) - ((i - 3) % 6));
- s->ModPred[i+5*128] = 2*((i + 4) - ((i + 3) % 7));
- s->ModPred[i+6*128] = (i > 123) ? 240 : 2*((i + 4) - ((i + 4) % 8));
- s->ModPred[i+7*128] = 2*((i + 5) - ((i + 4) % 9));
- }
-
- s->corrector_type = (unsigned short *) av_malloc (24 * 256 * sizeof(unsigned short));
-
- for (i=0; i < 24; ++i) {
- for (j=0; j < 256; ++j) {
- s->corrector_type[i*256+j] = (j < corrector_type_0[i])
- ? 1 : ((j < 248 || (i == 16 && j == 248))
- ? 0 : corrector_type_2[j - 248]);
- }
- }
-}
-
-static void iv_Decode_Chunk(Indeo3DecodeContext *s, unsigned char *cur,
- unsigned char *ref, int width, int height, unsigned char *buf1,
- long fflags2, unsigned char *hdr,
- unsigned char *buf2, int min_width_160);
-
-#ifndef min
-#define min(a,b) ((a) < (b) ? (a) : (b))
-#endif
-
-/* ---------------------------------------------------------------------- */
-static void iv_alloc_frames(Indeo3DecodeContext *s)
-{
- int luma_width, luma_height, luma_pixels, chroma_width, chroma_height,
- chroma_pixels, i;
- unsigned int bufsize;
-
- luma_width = (s->width + 3) & (~3);
- luma_height = (s->height + 3) & (~3);
-
- s->iv_frame[0].y_w = s->iv_frame[0].y_h =
- s->iv_frame[0].the_buf_size = 0;
- s->iv_frame[1].y_w = s->iv_frame[1].y_h =
- s->iv_frame[1].the_buf_size = 0;
- s->iv_frame[1].the_buf = NULL;
-
- chroma_width = ((luma_width >> 2) + 3) & (~3);
- chroma_height = ((luma_height>> 2) + 3) & (~3);
- luma_pixels = luma_width * luma_height;
- chroma_pixels = chroma_width * chroma_height;
-
- bufsize = luma_pixels * 2 + luma_width * 3 +
- (chroma_pixels + chroma_width) * 4;
-
- if((s->iv_frame[0].the_buf =
- (s->iv_frame[0].the_buf_size == 0 ? av_malloc(bufsize) :
- av_realloc(s->iv_frame[0].the_buf, bufsize))) == NULL)
- return;
- s->iv_frame[0].y_w = s->iv_frame[1].y_w = luma_width;
- s->iv_frame[0].y_h = s->iv_frame[1].y_h = luma_height;
- s->iv_frame[0].uv_w = s->iv_frame[1].uv_w = chroma_width;
- s->iv_frame[0].uv_h = s->iv_frame[1].uv_h = chroma_height;
- s->iv_frame[0].the_buf_size = bufsize;
-
- s->iv_frame[0].Ybuf = s->iv_frame[0].the_buf + luma_width;
- i = luma_pixels + luma_width * 2;
- s->iv_frame[1].Ybuf = s->iv_frame[0].the_buf + i;
- i += (luma_pixels + luma_width);
- s->iv_frame[0].Ubuf = s->iv_frame[0].the_buf + i;
- i += (chroma_pixels + chroma_width);
- s->iv_frame[1].Ubuf = s->iv_frame[0].the_buf + i;
- i += (chroma_pixels + chroma_width);
- s->iv_frame[0].Vbuf = s->iv_frame[0].the_buf + i;
- i += (chroma_pixels + chroma_width);
- s->iv_frame[1].Vbuf = s->iv_frame[0].the_buf + i;
-
- for(i = 1; i <= luma_width; i++)
- s->iv_frame[0].Ybuf[-i] = s->iv_frame[1].Ybuf[-i] =
- s->iv_frame[0].Ubuf[-i] = 0x80;
-
- for(i = 1; i <= chroma_width; i++) {
- s->iv_frame[1].Ubuf[-i] = 0x80;
- s->iv_frame[0].Vbuf[-i] = 0x80;
- s->iv_frame[1].Vbuf[-i] = 0x80;
- s->iv_frame[1].Vbuf[chroma_pixels+i-1] = 0x80;
- }
-}
-
-/* ---------------------------------------------------------------------- */
-static void iv_free_func(Indeo3DecodeContext *s)
-{
- int i;
-
- for(i = 0 ; i < 2 ; i++) {
- if(s->iv_frame[i].the_buf != NULL)
- av_free(s->iv_frame[i].the_buf);
- s->iv_frame[i].Ybuf = s->iv_frame[i].Ubuf =
- s->iv_frame[i].Vbuf = NULL;
- s->iv_frame[i].the_buf = NULL;
- s->iv_frame[i].the_buf_size = 0;
- s->iv_frame[i].y_w = s->iv_frame[i].y_h = 0;
- s->iv_frame[i].uv_w = s->iv_frame[i].uv_h = 0;
- }
-
- av_free(s->ModPred);
- av_free(s->corrector_type);
-}
-
-/* ---------------------------------------------------------------------- */
-static unsigned long iv_decode_frame(Indeo3DecodeContext *s,
- unsigned char *buf, int buf_size)
-{
- unsigned int hdr_width, hdr_height,
- chroma_width, chroma_height;
- unsigned long fflags1, fflags2, fflags3, offs1, offs2, offs3, offs;
- unsigned char *hdr_pos, *buf_pos;
-
- buf_pos = buf;
- buf_pos += 18;
-
- fflags1 = le2me_16(*(uint16_t *)buf_pos);
- buf_pos += 2;
- fflags3 = le2me_32(*(uint32_t *)buf_pos);
- buf_pos += 4;
- fflags2 = *buf_pos++;
- buf_pos += 3;
- hdr_height = le2me_16(*(uint16_t *)buf_pos);
- buf_pos += 2;
- hdr_width = le2me_16(*(uint16_t *)buf_pos);
-
- if(avcodec_check_dimensions(NULL, hdr_width, hdr_height))
- return -1;
-
- buf_pos += 2;
- chroma_height = ((hdr_height >> 2) + 3) & 0x7ffc;
- chroma_width = ((hdr_width >> 2) + 3) & 0x7ffc;
- offs1 = le2me_32(*(uint32_t *)buf_pos);
- buf_pos += 4;
- offs2 = le2me_32(*(uint32_t *)buf_pos);
- buf_pos += 4;
- offs3 = le2me_32(*(uint32_t *)buf_pos);
- buf_pos += 8;
- hdr_pos = buf_pos;
- if(fflags3 == 0x80) return 4;
-
- if(fflags1 & 0x200) {
- s->cur_frame = s->iv_frame + 1;
- s->ref_frame = s->iv_frame;
- } else {
- s->cur_frame = s->iv_frame;
- s->ref_frame = s->iv_frame + 1;
- }
-
- buf_pos = buf + 16 + offs1;
- offs = le2me_32(*(uint32_t *)buf_pos);
- buf_pos += 4;
-
- iv_Decode_Chunk(s, s->cur_frame->Ybuf, s->ref_frame->Ybuf, hdr_width,
- hdr_height, buf_pos + offs * 2, fflags2, hdr_pos, buf_pos,
- min(hdr_width, 160));
-
- if (!(s->avctx->flags & CODEC_FLAG_GRAY))
- {
-
- buf_pos = buf + 16 + offs2;
- offs = le2me_32(*(uint32_t *)buf_pos);
- buf_pos += 4;
-
- iv_Decode_Chunk(s, s->cur_frame->Vbuf, s->ref_frame->Vbuf, chroma_width,
- chroma_height, buf_pos + offs * 2, fflags2, hdr_pos, buf_pos,
- min(chroma_width, 40));
-
- buf_pos = buf + 16 + offs3;
- offs = le2me_32(*(uint32_t *)buf_pos);
- buf_pos += 4;
-
- iv_Decode_Chunk(s, s->cur_frame->Ubuf, s->ref_frame->Ubuf, chroma_width,
- chroma_height, buf_pos + offs * 2, fflags2, hdr_pos, buf_pos,
- min(chroma_width, 40));
-
- }
-
- return 8;
-}
-
-typedef struct {
- long xpos;
- long ypos;
- long width;
- long height;
- long split_flag;
- long split_direction;
- long usl7;
-} ustr_t;
-
-/* ---------------------------------------------------------------------- */
-
-#define LV1_CHECK(buf1,rle_v3,lv1,lp2) \
- if((lv1 & 0x80) != 0) { \
- if(rle_v3 != 0) \
- rle_v3 = 0; \
- else { \
- rle_v3 = 1; \
- buf1 -= 2; \
- } \
- } \
- lp2 = 4;
-
-
-#define RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3) \
- if(rle_v3 == 0) { \
- rle_v2 = *buf1; \
- rle_v1 = 1; \
- if(rle_v2 > 32) { \
- rle_v2 -= 32; \
- rle_v1 = 0; \
- } \
- rle_v3 = 1; \
- } \
- buf1--;
-
-
-#define LP2_CHECK(buf1,rle_v3,lp2) \
- if(lp2 == 0 && rle_v3 != 0) \
- rle_v3 = 0; \
- else { \
- buf1--; \
- rle_v3 = 1; \
- }
-
-
-#define RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2) \
- rle_v2--; \
- if(rle_v2 == 0) { \
- rle_v3 = 0; \
- buf1 += 2; \
- } \
- lp2 = 4;
-
-static void iv_Decode_Chunk(Indeo3DecodeContext *s,
- unsigned char *cur, unsigned char *ref, int width, int height,
- unsigned char *buf1, long fflags2, unsigned char *hdr,
- unsigned char *buf2, int min_width_160)
-{
- unsigned char bit_buf;
- unsigned long bit_pos, lv, lv1, lv2;
- long *width_tbl, width_tbl_arr[10];
- signed char *ref_vectors;
- unsigned char *cur_frm_pos, *ref_frm_pos, *cp, *cp2;
- uint32_t *cur_lp, *ref_lp;
- const uint32_t *correction_lp[2], *correctionloworder_lp[2], *correctionhighorder_lp[2];
- unsigned short *correction_type_sp[2];
- ustr_t strip_tbl[20], *strip;
- int i, j, k, lp1, lp2, flag1, cmd, blks_width, blks_height, region_160_width,
- rle_v1, rle_v2, rle_v3;
- unsigned short res;
-
- bit_buf = 0;
- ref_vectors = NULL;
-
- width_tbl = width_tbl_arr + 1;
- i = (width < 0 ? width + 3 : width)/4;
- for(j = -1; j < 8; j++)
- width_tbl[j] = i * j;
-
- strip = strip_tbl;
-
- for(region_160_width = 0; region_160_width < (width - min_width_160); region_160_width += min_width_160);
-
- strip->ypos = strip->xpos = 0;
- for(strip->width = min_width_160; width > strip->width; strip->width *= 2);
- strip->height = height;
- strip->split_direction = 0;
- strip->split_flag = 0;
- strip->usl7 = 0;
-
- bit_pos = 0;
-
- rle_v1 = rle_v2 = rle_v3 = 0;
-
- while(strip >= strip_tbl) {
- if(bit_pos <= 0) {
- bit_pos = 8;
- bit_buf = *buf1++;
- }
-
- bit_pos -= 2;
- cmd = (bit_buf >> bit_pos) & 0x03;
-
- if(cmd == 0) {
- strip++;
- memcpy(strip, strip-1, sizeof(ustr_t));
- strip->split_flag = 1;
- strip->split_direction = 0;
- strip->height = (strip->height > 8 ? ((strip->height+8)>>4)<<3 : 4);
- continue;
- } else if(cmd == 1) {
- strip++;
- memcpy(strip, strip-1, sizeof(ustr_t));
- strip->split_flag = 1;
- strip->split_direction = 1;
- strip->width = (strip->width > 8 ? ((strip->width+8)>>4)<<3 : 4);
- continue;
- } else if(cmd == 2) {
- if(strip->usl7 == 0) {
- strip->usl7 = 1;
- ref_vectors = NULL;
- continue;
- }
- } else if(cmd == 3) {
- if(strip->usl7 == 0) {
- strip->usl7 = 1;
- ref_vectors = (signed char*)buf2 + (*buf1 * 2);
- buf1++;
- continue;
- }
- }
-
- cur_frm_pos = cur + width * strip->ypos + strip->xpos;
-
- if((blks_width = strip->width) < 0)
- blks_width += 3;
- blks_width >>= 2;
- blks_height = strip->height;
-
- if(ref_vectors != NULL) {
- ref_frm_pos = ref + (ref_vectors[0] + strip->ypos) * width +
- ref_vectors[1] + strip->xpos;
- } else
- ref_frm_pos = cur_frm_pos - width_tbl[4];
-
- if(cmd == 2) {
- if(bit_pos <= 0) {
- bit_pos = 8;
- bit_buf = *buf1++;
- }
-
- bit_pos -= 2;
- cmd = (bit_buf >> bit_pos) & 0x03;
-
- if(cmd == 0 || ref_vectors != NULL) {
- for(lp1 = 0; lp1 < blks_width; lp1++) {
- for(i = 0, j = 0; i < blks_height; i++, j += width_tbl[1])
- ((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)ref_frm_pos)[j];
- cur_frm_pos += 4;
- ref_frm_pos += 4;
- }
- } else if(cmd != 1)
- return;
- } else {
- k = *buf1 >> 4;
- j = *buf1 & 0x0f;
- buf1++;
- lv = j + fflags2;
-
- if((lv - 8) <= 7 && (k == 0 || k == 3 || k == 10)) {
- cp2 = s->ModPred + ((lv - 8) << 7);
- cp = ref_frm_pos;
- for(i = 0; i < blks_width << 2; i++) {
- int v = *cp >> 1;
- *(cp++) = cp2[v];
- }
- }
-
- if(k == 1 || k == 4) {
- lv = (hdr[j] & 0xf) + fflags2;
- correction_type_sp[0] = s->corrector_type + (lv << 8);
- correction_lp[0] = correction + (lv << 8);
- lv = (hdr[j] >> 4) + fflags2;
- correction_lp[1] = correction + (lv << 8);
- correction_type_sp[1] = s->corrector_type + (lv << 8);
- } else {
- correctionloworder_lp[0] = correctionloworder_lp[1] = correctionloworder + (lv << 8);
- correctionhighorder_lp[0] = correctionhighorder_lp[1] = correctionhighorder + (lv << 8);
- correction_type_sp[0] = correction_type_sp[1] = s->corrector_type + (lv << 8);
- correction_lp[0] = correction_lp[1] = correction + (lv << 8);
- }
-
- switch(k) {
- case 1:
- case 0: /********** CASE 0 **********/
- for( ; blks_height > 0; blks_height -= 4) {
- for(lp1 = 0; lp1 < blks_width; lp1++) {
- for(lp2 = 0; lp2 < 4; ) {
- k = *buf1++;
- cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2];
- ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2];
-
- switch(correction_type_sp[0][k]) {
- case 0:
- *cur_lp = le2me_32(((le2me_32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
- lp2++;
- break;
- case 1:
- res = ((le2me_16(((unsigned short *)(ref_lp))[0]) >> 1) + correction_lp[lp2 & 0x01][*buf1]) << 1;
- ((unsigned short *)cur_lp)[0] = le2me_16(res);
- res = ((le2me_16(((unsigned short *)(ref_lp))[1]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1;
- ((unsigned short *)cur_lp)[1] = le2me_16(res);
- buf1++;
- lp2++;
- break;
- case 2:
- if(lp2 == 0) {
- for(i = 0, j = 0; i < 2; i++, j += width_tbl[1])
- cur_lp[j] = ref_lp[j];
- lp2 += 2;
- }
- break;
- case 3:
- if(lp2 < 2) {
- for(i = 0, j = 0; i < (3 - lp2); i++, j += width_tbl[1])
- cur_lp[j] = ref_lp[j];
- lp2 = 3;
- }
- break;
- case 8:
- if(lp2 == 0) {
- RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
-
- if(rle_v1 == 1 || ref_vectors != NULL) {
- for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
- cur_lp[j] = ref_lp[j];
- }
-
- RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
- break;
- } else {
- rle_v1 = 1;
- rle_v2 = *buf1 - 1;
- }
- case 5:
- LP2_CHECK(buf1,rle_v3,lp2)
- case 4:
- for(i = 0, j = 0; i < (4 - lp2); i++, j += width_tbl[1])
- cur_lp[j] = ref_lp[j];
- lp2 = 4;
- break;
-
- case 7:
- if(rle_v3 != 0)
- rle_v3 = 0;
- else {
- buf1--;
- rle_v3 = 1;
- }
- case 6:
- if(ref_vectors != NULL) {
- for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
- cur_lp[j] = ref_lp[j];
- }
- lp2 = 4;
- break;
-
- case 9:
- lv1 = *buf1++;
- lv = (lv1 & 0x7F) << 1;
- lv += (lv << 8);
- lv += (lv << 16);
- for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
- cur_lp[j] = lv;
-
- LV1_CHECK(buf1,rle_v3,lv1,lp2)
- break;
- default:
- return;
- }
- }
-
- cur_frm_pos += 4;
- ref_frm_pos += 4;
- }
-
- cur_frm_pos += ((width - blks_width) * 4);
- ref_frm_pos += ((width - blks_width) * 4);
- }
- break;
-
- case 4:
- case 3: /********** CASE 3 **********/
- if(ref_vectors != NULL)
- return;
- flag1 = 1;
-
- for( ; blks_height > 0; blks_height -= 8) {
- for(lp1 = 0; lp1 < blks_width; lp1++) {
- for(lp2 = 0; lp2 < 4; ) {
- k = *buf1++;
-
- cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2];
- ref_lp = ((uint32_t *)cur_frm_pos) + width_tbl[(lp2 * 2) - 1];
-
- switch(correction_type_sp[lp2 & 0x01][k]) {
- case 0:
- cur_lp[width_tbl[1]] = le2me_32(((le2me_32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
- if(lp2 > 0 || flag1 == 0 || strip->ypos != 0)
- cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
- else
- cur_lp[0] = le2me_32(((le2me_32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
- lp2++;
- break;
-
- case 1:
- res = ((le2me_16(((unsigned short *)ref_lp)[0]) >> 1) + correction_lp[lp2 & 0x01][*buf1]) << 1;
- ((unsigned short *)cur_lp)[width_tbl[2]] = le2me_16(res);
- res = ((le2me_16(((unsigned short *)ref_lp)[1]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1;
- ((unsigned short *)cur_lp)[width_tbl[2]+1] = le2me_16(res);
-
- if(lp2 > 0 || flag1 == 0 || strip->ypos != 0)
- cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
- else
- cur_lp[0] = cur_lp[width_tbl[1]];
- buf1++;
- lp2++;
- break;
-
- case 2:
- if(lp2 == 0) {
- for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
- cur_lp[j] = *ref_lp;
- lp2 += 2;
- }
- break;
-
- case 3:
- if(lp2 < 2) {
- for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1])
- cur_lp[j] = *ref_lp;
- lp2 = 3;
- }
- break;
-
- case 6:
- lp2 = 4;
- break;
-
- case 7:
- if(rle_v3 != 0)
- rle_v3 = 0;
- else {
- buf1--;
- rle_v3 = 1;
- }
- lp2 = 4;
- break;
-
- case 8:
- if(lp2 == 0) {
- RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
-
- if(rle_v1 == 1) {
- for(i = 0, j = 0; i < 8; i++, j += width_tbl[1])
- cur_lp[j] = ref_lp[j];
- }
-
- RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
- break;
- } else {
- rle_v2 = (*buf1) - 1;
- rle_v1 = 1;
- }
- case 5:
- LP2_CHECK(buf1,rle_v3,lp2)
- case 4:
- for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1])
- cur_lp[j] = *ref_lp;
- lp2 = 4;
- break;
-
- case 9:
- av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\n");
- lv1 = *buf1++;
- lv = (lv1 & 0x7F) << 1;
- lv += (lv << 8);
- lv += (lv << 16);
-
- for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
- cur_lp[j] = lv;
-
- LV1_CHECK(buf1,rle_v3,lv1,lp2)
- break;
-
- default:
- return;
- }
- }
-
- cur_frm_pos += 4;
- }
-
- cur_frm_pos += (((width * 2) - blks_width) * 4);
- flag1 = 0;
- }
- break;
-
- case 10: /********** CASE 10 **********/
- if(ref_vectors == NULL) {
- flag1 = 1;
-
- for( ; blks_height > 0; blks_height -= 8) {
- for(lp1 = 0; lp1 < blks_width; lp1 += 2) {
- for(lp2 = 0; lp2 < 4; ) {
- k = *buf1++;
- cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2];
- ref_lp = ((uint32_t *)cur_frm_pos) + width_tbl[(lp2 * 2) - 1];
- lv1 = ref_lp[0];
- lv2 = ref_lp[1];
- if(lp2 == 0 && flag1 != 0) {
-#ifdef WORDS_BIGENDIAN
- lv1 = lv1 & 0xFF00FF00;
- lv1 = (lv1 >> 8) | lv1;
- lv2 = lv2 & 0xFF00FF00;
- lv2 = (lv2 >> 8) | lv2;
-#else
- lv1 = lv1 & 0x00FF00FF;
- lv1 = (lv1 << 8) | lv1;
- lv2 = lv2 & 0x00FF00FF;
- lv2 = (lv2 << 8) | lv2;
-#endif
- }
-
- switch(correction_type_sp[lp2 & 0x01][k]) {
- case 0:
- cur_lp[width_tbl[1]] = le2me_32(((le2me_32(lv1) >> 1) + correctionloworder_lp[lp2 & 0x01][k]) << 1);
- cur_lp[width_tbl[1]+1] = le2me_32(((le2me_32(lv2) >> 1) + correctionhighorder_lp[lp2 & 0x01][k]) << 1);
- if(lp2 > 0 || strip->ypos != 0 || flag1 == 0) {
- cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
- cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
- } else {
- cur_lp[0] = cur_lp[width_tbl[1]];
- cur_lp[1] = cur_lp[width_tbl[1]+1];
- }
- lp2++;
- break;
-
- case 1:
- cur_lp[width_tbl[1]] = le2me_32(((le2me_32(lv1) >> 1) + correctionloworder_lp[lp2 & 0x01][*buf1]) << 1);
- cur_lp[width_tbl[1]+1] = le2me_32(((le2me_32(lv2) >> 1) + correctionloworder_lp[lp2 & 0x01][k]) << 1);
- if(lp2 > 0 || strip->ypos != 0 || flag1 == 0) {
- cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
- cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
- } else {
- cur_lp[0] = cur_lp[width_tbl[1]];
- cur_lp[1] = cur_lp[width_tbl[1]+1];
- }
- buf1++;
- lp2++;
- break;
-
- case 2:
- if(lp2 == 0) {
- if(flag1 != 0) {
- for(i = 0, j = width_tbl[1]; i < 3; i++, j += width_tbl[1]) {
- cur_lp[j] = lv1;
- cur_lp[j+1] = lv2;
- }
- cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
- cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
- } else {
- for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) {
- cur_lp[j] = lv1;
- cur_lp[j+1] = lv2;
- }
- }
- lp2 += 2;
- }
- break;
-
- case 3:
- if(lp2 < 2) {
- if(lp2 == 0 && flag1 != 0) {
- for(i = 0, j = width_tbl[1]; i < 5; i++, j += width_tbl[1]) {
- cur_lp[j] = lv1;
- cur_lp[j+1] = lv2;
- }
- cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
- cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
- } else {
- for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) {
- cur_lp[j] = lv1;
- cur_lp[j+1] = lv2;
- }
- }
- lp2 = 3;
- }
- break;
-
- case 8:
- if(lp2 == 0) {
- RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
- if(rle_v1 == 1) {
- if(flag1 != 0) {
- for(i = 0, j = width_tbl[1]; i < 7; i++, j += width_tbl[1]) {
- cur_lp[j] = lv1;
- cur_lp[j+1] = lv2;
- }
- cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
- cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
- } else {
- for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) {
- cur_lp[j] = lv1;
- cur_lp[j+1] = lv2;
- }
- }
- }
- RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
- break;
- } else {
- rle_v1 = 1;
- rle_v2 = (*buf1) - 1;
- }
- case 5:
- LP2_CHECK(buf1,rle_v3,lp2)
- case 4:
- if(lp2 == 0 && flag1 != 0) {
- for(i = 0, j = width_tbl[1]; i < 7; i++, j += width_tbl[1]) {
- cur_lp[j] = lv1;
- cur_lp[j+1] = lv2;
- }
- cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
- cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
- } else {
- for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) {
- cur_lp[j] = lv1;
- cur_lp[j+1] = lv2;
- }
- }
- lp2 = 4;
- break;
-
- case 6:
- lp2 = 4;
- break;
-
- case 7:
- if(lp2 == 0) {
- if(rle_v3 != 0)
- rle_v3 = 0;
- else {
- buf1--;
- rle_v3 = 1;
- }
- lp2 = 4;
- }
- break;
-
- case 9:
- av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\n");
- lv1 = *buf1;
- lv = (lv1 & 0x7F) << 1;
- lv += (lv << 8);
- lv += (lv << 16);
- for(i = 0, j = 0; i < 8; i++, j += width_tbl[1])
- cur_lp[j] = lv;
- LV1_CHECK(buf1,rle_v3,lv1,lp2)
- break;
-
- default:
- return;
- }
- }
-
- cur_frm_pos += 8;
- }
-
- cur_frm_pos += (((width * 2) - blks_width) * 4);
- flag1 = 0;
- }
- } else {
- for( ; blks_height > 0; blks_height -= 8) {
- for(lp1 = 0; lp1 < blks_width; lp1 += 2) {
- for(lp2 = 0; lp2 < 4; ) {
- k = *buf1++;
- cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2];
- ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2 * 2];
-
- switch(correction_type_sp[lp2 & 0x01][k]) {
- case 0:
- lv1 = correctionloworder_lp[lp2 & 0x01][k];
- lv2 = correctionhighorder_lp[lp2 & 0x01][k];
- cur_lp[0] = le2me_32(((le2me_32(ref_lp[0]) >> 1) + lv1) << 1);
- cur_lp[1] = le2me_32(((le2me_32(ref_lp[1]) >> 1) + lv2) << 1);
- cur_lp[width_tbl[1]] = le2me_32(((le2me_32(ref_lp[width_tbl[1]]) >> 1) + lv1) << 1);
- cur_lp[width_tbl[1]+1] = le2me_32(((le2me_32(ref_lp[width_tbl[1]+1]) >> 1) + lv2) << 1);
- lp2++;
- break;
-
- case 1:
- lv1 = correctionloworder_lp[lp2 & 0x01][*buf1++];
- lv2 = correctionloworder_lp[lp2 & 0x01][k];
- cur_lp[0] = le2me_32(((le2me_32(ref_lp[0]) >> 1) + lv1) << 1);
- cur_lp[1] = le2me_32(((le2me_32(ref_lp[1]) >> 1) + lv2) << 1);
- cur_lp[width_tbl[1]] = le2me_32(((le2me_32(ref_lp[width_tbl[1]]) >> 1) + lv1) << 1);
- cur_lp[width_tbl[1]+1] = le2me_32(((le2me_32(ref_lp[width_tbl[1]+1]) >> 1) + lv2) << 1);
- lp2++;
- break;
-
- case 2:
- if(lp2 == 0) {
- for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) {
- cur_lp[j] = ref_lp[j];
- cur_lp[j+1] = ref_lp[j+1];
- }
- lp2 += 2;
- }
- break;
-
- case 3:
- if(lp2 < 2) {
- for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) {
- cur_lp[j] = ref_lp[j];
- cur_lp[j+1] = ref_lp[j+1];
- }
- lp2 = 3;
- }
- break;
-
- case 8:
- if(lp2 == 0) {
- RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
- for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) {
- ((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)ref_frm_pos)[j];
- ((uint32_t *)cur_frm_pos)[j+1] = ((uint32_t *)ref_frm_pos)[j+1];
- }
- RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
- break;
- } else {
- rle_v1 = 1;
- rle_v2 = (*buf1) - 1;
- }
- case 5:
- case 7:
- LP2_CHECK(buf1,rle_v3,lp2)
- case 6:
- case 4:
- for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) {
- cur_lp[j] = ref_lp[j];
- cur_lp[j+1] = ref_lp[j+1];
- }
- lp2 = 4;
- break;
-
- case 9:
- av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\n");
- lv1 = *buf1;
- lv = (lv1 & 0x7F) << 1;
- lv += (lv << 8);
- lv += (lv << 16);
- for(i = 0, j = 0; i < 8; i++, j += width_tbl[1])
- ((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)cur_frm_pos)[j+1] = lv;
- LV1_CHECK(buf1,rle_v3,lv1,lp2)
- break;
-
- default:
- return;
- }
- }
-
- cur_frm_pos += 8;
- ref_frm_pos += 8;
- }
-
- cur_frm_pos += (((width * 2) - blks_width) * 4);
- ref_frm_pos += (((width * 2) - blks_width) * 4);
- }
- }
- break;
-
- case 11: /********** CASE 11 **********/
- if(ref_vectors == NULL)
- return;
-
- for( ; blks_height > 0; blks_height -= 8) {
- for(lp1 = 0; lp1 < blks_width; lp1++) {
- for(lp2 = 0; lp2 < 4; ) {
- k = *buf1++;
- cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2];
- ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2 * 2];
-
- switch(correction_type_sp[lp2 & 0x01][k]) {
- case 0:
- cur_lp[0] = le2me_32(((le2me_32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
- cur_lp[width_tbl[1]] = le2me_32(((le2me_32(ref_lp[width_tbl[1]]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
- lp2++;
- break;
-
- case 1:
- lv1 = (unsigned short)(correction_lp[lp2 & 0x01][*buf1++]);
- lv2 = (unsigned short)(correction_lp[lp2 & 0x01][k]);
- res = (unsigned short)(((le2me_16(((unsigned short *)ref_lp)[0]) >> 1) + lv1) << 1);
- ((unsigned short *)cur_lp)[0] = le2me_16(res);
- res = (unsigned short)(((le2me_16(((unsigned short *)ref_lp)[1]) >> 1) + lv2) << 1);
- ((unsigned short *)cur_lp)[1] = le2me_16(res);
- res = (unsigned short)(((le2me_16(((unsigned short *)ref_lp)[width_tbl[2]]) >> 1) + lv1) << 1);
- ((unsigned short *)cur_lp)[width_tbl[2]] = le2me_16(res);
- res = (unsigned short)(((le2me_16(((unsigned short *)ref_lp)[width_tbl[2]+1]) >> 1) + lv2) << 1);
- ((unsigned short *)cur_lp)[width_tbl[2]+1] = le2me_16(res);
- lp2++;
- break;
-
- case 2:
- if(lp2 == 0) {
- for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
- cur_lp[j] = ref_lp[j];
- lp2 += 2;
- }
- break;
-
- case 3:
- if(lp2 < 2) {
- for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1])
- cur_lp[j] = ref_lp[j];
- lp2 = 3;
- }
- break;
-
- case 8:
- if(lp2 == 0) {
- RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
-
- for(i = 0, j = 0; i < 8; i++, j += width_tbl[1])
- cur_lp[j] = ref_lp[j];
-
- RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
- break;
- } else {
- rle_v1 = 1;
- rle_v2 = (*buf1) - 1;
- }
- case 5:
- case 7:
- LP2_CHECK(buf1,rle_v3,lp2)
- case 4:
- case 6:
- for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1])
- cur_lp[j] = ref_lp[j];
- lp2 = 4;
- break;
-
- case 9:
- av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\n");
- lv1 = *buf1++;
- lv = (lv1 & 0x7F) << 1;
- lv += (lv << 8);
- lv += (lv << 16);
- for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
- cur_lp[j] = lv;
- LV1_CHECK(buf1,rle_v3,lv1,lp2)
- break;
-
- default:
- return;
- }
- }
-
- cur_frm_pos += 4;
- ref_frm_pos += 4;
- }
-
- cur_frm_pos += (((width * 2) - blks_width) * 4);
- ref_frm_pos += (((width * 2) - blks_width) * 4);
- }
- break;
-
- default:
- return;
- }
- }
-
- if(strip < strip_tbl)
- return;
-
- for( ; strip >= strip_tbl; strip--) {
- if(strip->split_flag != 0) {
- strip->split_flag = 0;
- strip->usl7 = (strip-1)->usl7;
-
- if(strip->split_direction) {
- strip->xpos += strip->width;
- strip->width = (strip-1)->width - strip->width;
- if(region_160_width <= strip->xpos && width < strip->width + strip->xpos)
- strip->width = width - strip->xpos;
- } else {
- strip->ypos += strip->height;
- strip->height = (strip-1)->height - strip->height;
- }
- break;
- }
- }
- }
-}
-
-static int indeo3_decode_init(AVCodecContext *avctx)
-{
- Indeo3DecodeContext *s = avctx->priv_data;
-
- s->avctx = avctx;
- s->width = avctx->width;
- s->height = avctx->height;
- avctx->pix_fmt = PIX_FMT_YUV410P;
- avctx->has_b_frames = 0;
-
- build_modpred(s);
- iv_alloc_frames(s);
-
- return 0;
-}
-
-static int indeo3_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- unsigned char *buf, int buf_size)
-{
- Indeo3DecodeContext *s=avctx->priv_data;
- unsigned char *src, *dest;
- int y;
-
- iv_decode_frame(s, buf, buf_size);
-
- if(s->frame.data[0])
- avctx->release_buffer(avctx, &s->frame);
-
- s->frame.reference = 0;
- if(avctx->get_buffer(avctx, &s->frame) < 0) {
- av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
- return -1;
- }
-
- src = s->cur_frame->Ybuf;
- dest = s->frame.data[0];
- for (y = 0; y < s->height; y++) {
- memcpy(dest, src, s->cur_frame->y_w);
- src += s->cur_frame->y_w;
- dest += s->frame.linesize[0];
- }
-
- if (!(s->avctx->flags & CODEC_FLAG_GRAY))
- {
- src = s->cur_frame->Ubuf;
- dest = s->frame.data[1];
- for (y = 0; y < s->height / 4; y++) {
- memcpy(dest, src, s->cur_frame->uv_w);
- src += s->cur_frame->uv_w;
- dest += s->frame.linesize[1];
- }
-
- src = s->cur_frame->Vbuf;
- dest = s->frame.data[2];
- for (y = 0; y < s->height / 4; y++) {
- memcpy(dest, src, s->cur_frame->uv_w);
- src += s->cur_frame->uv_w;
- dest += s->frame.linesize[2];
- }
- }
-
- *data_size=sizeof(AVFrame);
- *(AVFrame*)data= s->frame;
-
- return buf_size;
-}
-
-static int indeo3_decode_end(AVCodecContext *avctx)
-{
- Indeo3DecodeContext *s = avctx->priv_data;
-
- iv_free_func(s);
-
- return 0;
-}
-
-AVCodec indeo3_decoder = {
- "indeo3",
- CODEC_TYPE_VIDEO,
- CODEC_ID_INDEO3,
- sizeof(Indeo3DecodeContext),
- indeo3_decode_init,
- NULL,
- indeo3_decode_end,
- indeo3_decode_frame,
- 0,
- NULL
-};
diff --git a/src/libffmpeg/libavcodec/jpeg_ls.c b/src/libffmpeg/libavcodec/jpeg_ls.c
deleted file mode 100644
index 4629176ad..000000000
--- a/src/libffmpeg/libavcodec/jpeg_ls.c
+++ /dev/null
@@ -1,860 +0,0 @@
-/*
- * JPEG-LS encoder and decoder
- * Copyright (c) 2003 Michael Niedermayer
- * Copyright (c) 2006 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 "golomb.h"
-
-/**
- * @file jpeg_ls.c
- * JPEG-LS encoder and decoder.
- */
-
-typedef struct JpeglsContext{
- AVCodecContext *avctx;
- AVFrame picture;
-}JpeglsContext;
-
-typedef struct JLSState{
- int T1, T2, T3;
- int A[367], B[367], C[365], N[367];
- int limit, reset, bpp, qbpp, maxval, range;
- int near, twonear;
- int run_index[3];
-}JLSState;
-
-static const uint8_t log2_run[32]={
- 0, 0, 0, 0, 1, 1, 1, 1,
- 2, 2, 2, 2, 3, 3, 3, 3,
- 4, 4, 5, 5, 6, 6, 7, 7,
- 8, 9,10,11,12,13,14,15
-};
-
-/*
-* Uncomment this to significantly speed up decoding of broken JPEG-LS
-* (or test broken JPEG-LS decoder) and slow down ordinary decoding a bit.
-*
-* There is no Golomb code with length >= 32 bits possible, so check and
-* avoid situation of 32 zeros, FFmpeg Golomb decoder is painfully slow
-* on this errors.
-*/
-//#define JLS_BROKEN
-
-/********** Functions for both encoder and decoder **********/
-
-/**
- * Calculate initial JPEG-LS parameters
- */
-static void ls_init_state(JLSState *state){
- int i;
-
- state->twonear = state->near * 2 + 1;
- state->range = ((state->maxval + state->twonear - 1) / state->twonear) + 1;
-
- // QBPP = ceil(log2(RANGE))
- for(state->qbpp = 0; (1 << state->qbpp) < state->range; state->qbpp++);
-
- if(state->bpp < 8)
- state->limit = 16 + 2 * state->bpp - state->qbpp;
- else
- state->limit = (4 * state->bpp) - state->qbpp;
-
- for(i = 0; i < 367; i++) {
- state->A[i] = FFMAX((state->range + 32) >> 6, 2);
- state->N[i] = 1;
- }
-
-}
-
-/**
- * Calculate quantized gradient value, used for context determination
- */
-static inline int quantize(JLSState *s, int v){ //FIXME optimize
- if(v==0) return 0;
- if(v < 0){
- if(v <= -s->T3) return -4;
- if(v <= -s->T2) return -3;
- if(v <= -s->T1) return -2;
- if(v < -s->near) return -1;
- return 0;
- }else{
- if(v <= s->near) return 0;
- if(v < s->T1) return 1;
- if(v < s->T2) return 2;
- if(v < s->T3) return 3;
- return 4;
- }
-}
-
-/**
- * Custom value clipping function used in T1, T2, T3 calculation
- */
-static inline int iso_clip(int v, int vmin, int vmax){
- if(v > vmax || v < vmin) return vmin;
- else return v;
-}
-
-/**
- * Calculate JPEG-LS codec values
- */
-static void reset_ls_coding_parameters(JLSState *s, int reset_all){
- const int basic_t1= 3;
- const int basic_t2= 7;
- const int basic_t3= 21;
- int factor;
-
- if(s->maxval==0 || reset_all) s->maxval= (1 << s->bpp) - 1;
-
- if(s->maxval >=128){
- factor= (FFMIN(s->maxval, 4095) + 128)>>8;
-
- if(s->T1==0 || reset_all)
- s->T1= iso_clip(factor*(basic_t1-2) + 2 + 3*s->near, s->near+1, s->maxval);
- if(s->T2==0 || reset_all)
- s->T2= iso_clip(factor*(basic_t2-3) + 3 + 5*s->near, s->T1, s->maxval);
- if(s->T3==0 || reset_all)
- s->T3= iso_clip(factor*(basic_t3-4) + 4 + 7*s->near, s->T2, s->maxval);
- }else{
- factor= 256 / (s->maxval + 1);
-
- if(s->T1==0 || reset_all)
- s->T1= iso_clip(FFMAX(2, basic_t1/factor + 3*s->near), s->near+1, s->maxval);
- if(s->T2==0 || reset_all)
- s->T2= iso_clip(FFMAX(3, basic_t2/factor + 5*s->near), s->T1, s->maxval);
- if(s->T3==0 || reset_all)
- s->T3= iso_clip(FFMAX(4, basic_t3/factor + 6*s->near), s->T2, s->maxval);
- }
-
- if(s->reset==0 || reset_all) s->reset= 64;
-// av_log(NULL, AV_LOG_DEBUG, "[JPEG-LS RESET] T=%i,%i,%i\n", s->T1, s->T2, s->T3);
-}
-
-
-/********** Decoder-specific functions **********/
-
-/**
- * Decode LSE block with initialization parameters
- */
-static int decode_lse(MJpegDecodeContext *s)
-{
- int len, id;
-
- /* XXX: verify len field validity */
- len = get_bits(&s->gb, 16);
- id = get_bits(&s->gb, 8);
-
- switch(id){
- case 1:
- s->maxval= get_bits(&s->gb, 16);
- s->t1= get_bits(&s->gb, 16);
- s->t2= get_bits(&s->gb, 16);
- s->t3= get_bits(&s->gb, 16);
- s->reset= get_bits(&s->gb, 16);
-
-// reset_ls_coding_parameters(s, 0);
- //FIXME quant table?
- break;
- case 2:
- case 3:
- av_log(s->avctx, AV_LOG_ERROR, "palette not supported\n");
- return -1;
- case 4:
- av_log(s->avctx, AV_LOG_ERROR, "oversize image not supported\n");
- return -1;
- default:
- av_log(s->avctx, AV_LOG_ERROR, "invalid id %d\n", id);
- return -1;
- }
-// av_log(s->avctx, AV_LOG_DEBUG, "ID=%i, T=%i,%i,%i\n", id, s->t1, s->t2, s->t3);
-
- return 0;
-}
-
-static void inline downscale_state(JLSState *state, int Q){
- if(state->N[Q] == state->reset){
- state->A[Q] >>=1;
- state->B[Q] >>=1;
- state->N[Q] >>=1;
- }
- state->N[Q]++;
-}
-
-static inline int update_state_regular(JLSState *state, int Q, int err){
- state->A[Q] += FFABS(err);
- err *= state->twonear;
- state->B[Q] += err;
-
- downscale_state(state, Q);
-
- if(state->B[Q] <= -state->N[Q]) {
- state->B[Q]= FFMAX(state->B[Q] + state->N[Q], 1-state->N[Q]);
- if(state->C[Q] > -128)
- state->C[Q]--;
- }else if(state->B[Q] > 0){
- state->B[Q]= FFMIN(state->B[Q] - state->N[Q], 0);
- if(state->C[Q] < 127)
- state->C[Q]++;
- }
-
- return err;
-}
-
-/**
- * Get context-dependent Golomb code, decode it and update context
- */
-static inline int ls_get_code_regular(GetBitContext *gb, JLSState *state, int Q){
- int k, ret;
-
- for(k = 0; (state->N[Q] << k) < state->A[Q]; k++);
-
-#ifdef JLS_BROKEN
- if(!show_bits_long(gb, 32))return -1;
-#endif
- ret = get_ur_golomb_jpegls(gb, k, state->limit, state->qbpp);
-
- /* decode mapped error */
- if(ret & 1)
- ret = -((ret + 1) >> 1);
- else
- ret >>= 1;
-
- /* for NEAR=0, k=0 and 2*B[Q] <= - N[Q] mapping is reversed */
- if(!state->near && !k && (2 * state->B[Q] <= -state->N[Q]))
- ret = -(ret + 1);
-
- ret= update_state_regular(state, Q, ret);
-
- return ret;
-}
-
-/**
- * Get Golomb code, decode it and update state for run termination
- */
-static inline int ls_get_code_runterm(GetBitContext *gb, JLSState *state, int RItype, int limit_add){
- int k, ret, temp, map;
- int Q = 365 + RItype;
-
- temp= state->A[Q];
- if(RItype)
- temp += state->N[Q] >> 1;
-
- for(k = 0; (state->N[Q] << k) < temp; k++);
-
-#ifdef JLS_BROKEN
- if(!show_bits_long(gb, 32))return -1;
-#endif
- ret = get_ur_golomb_jpegls(gb, k, state->limit - limit_add - 1, state->qbpp);
-
- /* decode mapped error */
- map = 0;
- if(!k && (RItype || ret) && (2 * state->B[Q] < state->N[Q]))
- map = 1;
- ret += RItype + map;
-
- if(ret & 1){
- ret = map - ((ret + 1) >> 1);
- state->B[Q]++;
- } else {
- ret = ret >> 1;
- }
-
- /* update state */
- state->A[Q] += FFABS(ret) - RItype;
- ret *= state->twonear;
- downscale_state(state, Q);
-
- return ret;
-}
-
-#define R(a, i ) (bits == 8 ? ((uint8_t*)(a))[i] : ((uint16_t*)(a))[i] )
-#define W(a, i, v) (bits == 8 ? (((uint8_t*)(a))[i]=v) : (((uint16_t*)(a))[i]=v))
-/**
- * Decode one line of image
- */
-static inline void ls_decode_line(JLSState *state, MJpegDecodeContext *s, void *last, void *dst, int last2, int w, int stride, int comp, int bits){
- int i, x = 0;
- int Ra, Rb, Rc, Rd;
- int D0, D1, D2;
-
- while(x < w) {
- int err, pred;
-
- /* compute gradients */
- Ra = x ? R(dst, x - stride) : R(last, x);
- Rb = R(last, x);
- Rc = x ? R(last, x - stride) : last2;
- Rd = (x >= w - stride) ? R(last, x) : R(last, x + stride);
- D0 = Rd - Rb;
- D1 = Rb - Rc;
- D2 = Rc - Ra;
- /* run mode */
- if((FFABS(D0) <= state->near) && (FFABS(D1) <= state->near) && (FFABS(D2) <= state->near)) {
- int r;
- int RItype;
-
- /* decode full runs while available */
- while(get_bits1(&s->gb)) {
- int r;
- r = 1 << log2_run[state->run_index[comp]];
- if(x + r * stride > w) {
- r = (w - x) / stride;
- }
- for(i = 0; i < r; i++) {
- W(dst, x, Ra);
- x += stride;
- }
- /* if EOL reached, we stop decoding */
- if(r != (1 << log2_run[state->run_index[comp]]))
- return;
- if(state->run_index[comp] < 31)
- state->run_index[comp]++;
- if(x + stride > w)
- return;
- }
- /* decode aborted run */
- r = log2_run[state->run_index[comp]];
- if(r)
- r = get_bits_long(&s->gb, r);
- for(i = 0; i < r; i++) {
- W(dst, x, Ra);
- x += stride;
- }
-
- /* decode run termination value */
- Rb = R(last, x);
- RItype = (FFABS(Ra - Rb) <= state->near) ? 1 : 0;
- err = ls_get_code_runterm(&s->gb, state, RItype, log2_run[state->run_index[comp]]);
- if(state->run_index[comp])
- state->run_index[comp]--;
-
- if(state->near && RItype){
- pred = Ra + err;
- } else {
- if(Rb < Ra)
- pred = Rb - err;
- else
- pred = Rb + err;
- }
- } else { /* regular mode */
- int context, sign;
-
- context = quantize(state, D0) * 81 + quantize(state, D1) * 9 + quantize(state, D2);
- pred = mid_pred(Ra, Ra + Rb - Rc, Rb);
-
- if(context < 0){
- context = -context;
- sign = 1;
- }else{
- sign = 0;
- }
-
- if(sign){
- pred = clip(pred - state->C[context], 0, state->maxval);
- err = -ls_get_code_regular(&s->gb, state, context);
- } else {
- pred = clip(pred + state->C[context], 0, state->maxval);
- err = ls_get_code_regular(&s->gb, state, context);
- }
-
- /* we have to do something more for near-lossless coding */
- pred += err;
- }
- if(state->near){
- if(pred < -state->near)
- pred += state->range * state->twonear;
- else if(pred > state->maxval + state->near)
- pred -= state->range * state->twonear;
- pred = clip(pred, 0, state->maxval);
- }
-
- pred &= state->maxval;
- W(dst, x, pred);
- x += stride;
- }
-}
-
-static int ls_decode_picture(MJpegDecodeContext *s, int near, int point_transform, int ilv){
- int i, t = 0;
- uint8_t *zero, *last, *cur;
- JLSState *state;
- int off = 0, stride = 1, width, shift;
-
- zero = av_mallocz(s->picture.linesize[0]);
- last = zero;
- cur = s->picture.data[0];
-
- state = av_mallocz(sizeof(JLSState));
- /* initialize JPEG-LS state from JPEG parameters */
- state->near = near;
- state->bpp = (s->bits < 2) ? 2 : s->bits;
- state->maxval = s->maxval;
- state->T1 = s->t1;
- state->T2 = s->t2;
- state->T3 = s->t3;
- state->reset = s->reset;
- reset_ls_coding_parameters(state, 0);
- ls_init_state(state);
-
- if(s->bits <= 8)
- shift = point_transform + (8 - s->bits);
- else
- shift = point_transform + (16 - s->bits);
-
-// av_log(s->avctx, AV_LOG_DEBUG, "JPEG-LS params: %ix%i NEAR=%i MV=%i T(%i,%i,%i) RESET=%i, LIMIT=%i, qbpp=%i, RANGE=%i\n",s->width,s->height,state->near,state->maxval,state->T1,state->T2,state->T3,state->reset,state->limit,state->qbpp, state->range);
-// av_log(s->avctx, AV_LOG_DEBUG, "JPEG params: ILV=%i Pt=%i BPP=%i, scan = %i\n", ilv, point_transform, s->bits, s->cur_scan);
- if(ilv == 0) { /* separate planes */
- off = s->cur_scan - 1;
- stride = (s->nb_components > 1) ? 3 : 1;
- width = s->width * stride;
- cur += off;
- for(i = 0; i < s->height; i++) {
- if(s->bits <= 8){
- ls_decode_line(state, s, last, cur, t, width, stride, off, 8);
- t = last[0];
- }else{
- ls_decode_line(state, s, last, cur, t, width, stride, off, 16);
- t = *((uint16_t*)last);
- }
- last = cur;
- cur += s->picture.linesize[0];
-
- if (s->restart_interval && !--s->restart_count) {
- align_get_bits(&s->gb);
- skip_bits(&s->gb, 16); /* skip RSTn */
- }
- }
- } else if(ilv == 1) { /* line interleaving */
- int j;
- int Rc[3] = {0, 0, 0};
- memset(cur, 0, s->picture.linesize[0]);
- width = s->width * 3;
- for(i = 0; i < s->height; i++) {
- for(j = 0; j < 3; j++) {
- ls_decode_line(state, s, last + j, cur + j, Rc[j], width, 3, j, 8);
- Rc[j] = last[j];
-
- if (s->restart_interval && !--s->restart_count) {
- align_get_bits(&s->gb);
- skip_bits(&s->gb, 16); /* skip RSTn */
- }
- }
- last = cur;
- cur += s->picture.linesize[0];
- }
- } else if(ilv == 2) { /* sample interleaving */
- av_log(s->avctx, AV_LOG_ERROR, "Sample interleaved images are not supported.\n");
- av_free(state);
- av_free(zero);
- return -1;
- }
-
- if(shift){ /* we need to do point transform or normalize samples */
- int x, w;
-
- w = s->width * s->nb_components;
-
- if(s->bits <= 8){
- uint8_t *src = s->picture.data[0];
-
- for(i = 0; i < s->height; i++){
- for(x = off; x < w; x+= stride){
- src[x] <<= shift;
- }
- src += s->picture.linesize[0];
- }
- }else{
- uint16_t *src = s->picture.data[0];
-
- for(i = 0; i < s->height; i++){
- for(x = 0; x < w; x++){
- src[x] <<= shift;
- }
- src += s->picture.linesize[0]/2;
- }
- }
- }
- av_free(state);
- av_free(zero);
-
- return 0;
-}
-
-#if defined(CONFIG_ENCODERS) && defined(CONFIG_JPEGLS_ENCODER)
-/********** Encoder-specific functions **********/
-
-/**
- * Encode error from regular symbol
- */
-static inline void ls_encode_regular(JLSState *state, PutBitContext *pb, int Q, int err){
- int k;
- int val;
- int map;
-
- for(k = 0; (state->N[Q] << k) < state->A[Q]; k++);
-
- map = !state->near && !k && (2 * state->B[Q] <= -state->N[Q]);
-
- if(err < 0)
- err += state->range;
- if(err >= ((state->range + 1) >> 1)) {
- err -= state->range;
- val = 2 * FFABS(err) - 1 - map;
- } else
- val = 2 * err + map;
-
- set_ur_golomb_jpegls(pb, val, k, state->limit, state->qbpp);
-
- update_state_regular(state, Q, err);
-}
-
-/**
- * Encode error from run termination
- */
-static inline void ls_encode_runterm(JLSState *state, PutBitContext *pb, int RItype, int err, int limit_add){
- int k;
- int val, map;
- int Q = 365 + RItype;
- int temp;
-
- temp = state->A[Q];
- if(RItype)
- temp += state->N[Q] >> 1;
- for(k = 0; (state->N[Q] << k) < temp; k++);
- map = 0;
- if(!k && err && (2 * state->B[Q] < state->N[Q]))
- map = 1;
-
- if(err < 0)
- val = - (2 * err) - 1 - RItype + map;
- else
- val = 2 * err - RItype - map;
- set_ur_golomb_jpegls(pb, val, k, state->limit - limit_add - 1, state->qbpp);
-
- if(err < 0)
- state->B[Q]++;
- state->A[Q] += (val + 1 - RItype) >> 1;
-
- downscale_state(state, Q);
-}
-
-/**
- * Encode run value as specified by JPEG-LS standard
- */
-static inline void ls_encode_run(JLSState *state, PutBitContext *pb, int run, int comp, int trail){
- while(run >= (1 << log2_run[state->run_index[comp]])){
- put_bits(pb, 1, 1);
- run -= 1 << log2_run[state->run_index[comp]];
- if(state->run_index[comp] < 31)
- state->run_index[comp]++;
- }
- /* if hit EOL, encode another full run, else encode aborted run */
- if(!trail && run) {
- put_bits(pb, 1, 1);
- }else if(trail){
- put_bits(pb, 1, 0);
- if(log2_run[state->run_index[comp]])
- put_bits(pb, log2_run[state->run_index[comp]], run);
- }
-}
-
-/**
- * Encode one line of image
- */
-static inline void ls_encode_line(JLSState *state, PutBitContext *pb, void *last, void *cur, int last2, int w, int stride, int comp, int bits){
- int x = 0;
- int Ra, Rb, Rc, Rd;
- int D0, D1, D2;
-
- while(x < w) {
- int err, pred, sign;
-
- /* compute gradients */
- Ra = x ? R(cur, x - stride) : R(last, x);
- Rb = R(last, x);
- Rc = x ? R(last, x - stride) : last2;
- Rd = (x >= w - stride) ? R(last, x) : R(last, x + stride);
- D0 = Rd - Rb;
- D1 = Rb - Rc;
- D2 = Rc - Ra;
-
- /* run mode */
- if((FFABS(D0) <= state->near) && (FFABS(D1) <= state->near) && (FFABS(D2) <= state->near)) {
- int RUNval, RItype, run;
-
- run = 0;
- RUNval = Ra;
- while(x < w && (FFABS(R(cur, x) - RUNval) <= state->near)){
- run++;
- W(cur, x, Ra);
- x += stride;
- }
- ls_encode_run(state, pb, run, comp, x < w);
- if(x >= w)
- return;
- Rb = R(last, x);
- RItype = (FFABS(Ra - Rb) <= state->near);
- pred = RItype ? Ra : Rb;
- err = R(cur, x) - pred;
-
- if(!RItype && Ra > Rb)
- err = -err;
-
- if(state->near){
- if(err > 0)
- err = (state->near + err) / state->twonear;
- else
- err = -(state->near - err) / state->twonear;
-
- if(RItype || (Rb >= Ra))
- Ra = clip(pred + err * state->twonear, 0, state->maxval);
- else
- Ra = clip(pred - err * state->twonear, 0, state->maxval);
- W(cur, x, Ra);
- }
- if(err < 0)
- err += state->range;
- if(err >= ((state->range + 1) >> 1))
- err -= state->range;
-
- ls_encode_runterm(state, pb, RItype, err, log2_run[state->run_index[comp]]);
-
- if(state->run_index[comp] > 0)
- state->run_index[comp]--;
- } else { /* regular mode */
- int context;
-
- context = quantize(state, D0) * 81 + quantize(state, D1) * 9 + quantize(state, D2);
- pred = mid_pred(Ra, Ra + Rb - Rc, Rb);
-
- if(context < 0){
- context = -context;
- sign = 1;
- pred = clip(pred - state->C[context], 0, state->maxval);
- err = pred - R(cur, x);
- }else{
- sign = 0;
- pred = clip(pred + state->C[context], 0, state->maxval);
- err = R(cur, x) - pred;
- }
-
- if(state->near){
- if(err > 0)
- err = (state->near + err) / state->twonear;
- else
- err = -(state->near - err) / state->twonear;
- if(!sign)
- Ra = clip(pred + err * state->twonear, 0, state->maxval);
- else
- Ra = clip(pred - err * state->twonear, 0, state->maxval);
- W(cur, x, Ra);
- }
-
- ls_encode_regular(state, pb, context, err);
- }
- x += stride;
- }
-}
-
-static void ls_store_lse(JLSState *state, PutBitContext *pb){
- /* Test if we have default params and don't need to store LSE */
- JLSState state2;
- memset(&state2, 0, sizeof(JLSState));
- state2.bpp = state->bpp;
- state2.near = state->near;
- reset_ls_coding_parameters(&state2, 1);
- if(state->T1 == state2.T1 && state->T2 == state2.T2 && state->T3 == state2.T3 && state->reset == state2.reset)
- return;
- /* store LSE type 1 */
- put_marker(pb, LSE);
- put_bits(pb, 16, 13);
- put_bits(pb, 8, 1);
- put_bits(pb, 16, state->maxval);
- put_bits(pb, 16, state->T1);
- put_bits(pb, 16, state->T2);
- put_bits(pb, 16, state->T3);
- put_bits(pb, 16, state->reset);
-}
-
-static int encode_picture_ls(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
- JpeglsContext * const s = avctx->priv_data;
- AVFrame *pict = data;
- AVFrame * const p= (AVFrame*)&s->picture;
- const int near = avctx->prediction_method;
- PutBitContext pb, pb2;
- GetBitContext gb;
- uint8_t *buf2, *zero, *cur, *last;
- JLSState *state;
- int i, size;
- int comps;
-
- buf2 = av_malloc(buf_size);
-
- init_put_bits(&pb, buf, buf_size);
- init_put_bits(&pb2, buf2, buf_size);
-
- *p = *pict;
- p->pict_type= FF_I_TYPE;
- p->key_frame= 1;
-
- if(avctx->pix_fmt == PIX_FMT_GRAY8 || avctx->pix_fmt == PIX_FMT_GRAY16)
- comps = 1;
- else
- comps = 3;
-
- /* write our own JPEG header, can't use mjpeg_picture_header */
- put_marker(&pb, SOI);
- put_marker(&pb, SOF48);
- put_bits(&pb, 16, 8 + comps * 3); // header size depends on components
- put_bits(&pb, 8, (avctx->pix_fmt == PIX_FMT_GRAY16) ? 16 : 8); // bpp
- put_bits(&pb, 16, avctx->height);
- put_bits(&pb, 16, avctx->width);
- put_bits(&pb, 8, comps); // components
- for(i = 1; i <= comps; i++) {
- put_bits(&pb, 8, i); // component ID
- put_bits(&pb, 8, 0x11); // subsampling: none
- put_bits(&pb, 8, 0); // Tiq, used by JPEG-LS ext
- }
-
- put_marker(&pb, SOS);
- put_bits(&pb, 16, 6 + comps * 2);
- put_bits(&pb, 8, comps);
- for(i = 1; i <= comps; i++) {
- put_bits(&pb, 8, i); // component ID
- put_bits(&pb, 8, 0); // mapping index: none
- }
- put_bits(&pb, 8, near);
- put_bits(&pb, 8, (comps > 1) ? 1 : 0); // interleaving: 0 - plane, 1 - line
- put_bits(&pb, 8, 0); // point transform: none
-
- state = av_mallocz(sizeof(JLSState));
- /* initialize JPEG-LS state from JPEG parameters */
- state->near = near;
- state->bpp = (avctx->pix_fmt == PIX_FMT_GRAY16) ? 16 : 8;
- reset_ls_coding_parameters(state, 0);
- ls_init_state(state);
-
- ls_store_lse(state, &pb);
-
- zero = av_mallocz(p->linesize[0]);
- last = zero;
- cur = p->data[0];
- if(avctx->pix_fmt == PIX_FMT_GRAY8){
- int t = 0;
-
- for(i = 0; i < avctx->height; i++) {
- ls_encode_line(state, &pb2, last, cur, t, avctx->width, 1, 0, 8);
- t = last[0];
- last = cur;
- cur += p->linesize[0];
- }
- }else if(avctx->pix_fmt == PIX_FMT_GRAY16){
- int t = 0;
-
- for(i = 0; i < avctx->height; i++) {
- ls_encode_line(state, &pb2, last, cur, t, avctx->width, 1, 0, 16);
- t = *((uint16_t*)last);
- last = cur;
- cur += p->linesize[0];
- }
- }else if(avctx->pix_fmt == PIX_FMT_RGB24){
- int j, width;
- int Rc[3] = {0, 0, 0};
-
- width = avctx->width * 3;
- for(i = 0; i < avctx->height; i++) {
- for(j = 0; j < 3; j++) {
- ls_encode_line(state, &pb2, last + j, cur + j, Rc[j], width, 3, j, 8);
- Rc[j] = last[j];
- }
- last = cur;
- cur += s->picture.linesize[0];
- }
- }else if(avctx->pix_fmt == PIX_FMT_BGR24){
- int j, width;
- int Rc[3] = {0, 0, 0};
-
- width = avctx->width * 3;
- for(i = 0; i < avctx->height; i++) {
- for(j = 2; j >= 0; j--) {
- ls_encode_line(state, &pb2, last + j, cur + j, Rc[j], width, 3, j, 8);
- Rc[j] = last[j];
- }
- last = cur;
- cur += s->picture.linesize[0];
- }
- }
-
- av_free(zero);
- av_free(state);
-
- // the specification says that after doing 0xff escaping unused bits in the
- // last byte must be set to 0, so just append 7 "optional" zero-bits to
- // avoid special-casing.
- put_bits(&pb2, 7, 0);
- size = put_bits_count(&pb2);
- flush_put_bits(&pb2);
- /* do escape coding */
- init_get_bits(&gb, buf2, size);
- size -= 7;
- while(get_bits_count(&gb) < size){
- int v;
- v = get_bits(&gb, 8);
- put_bits(&pb, 8, v);
- if(v == 0xFF){
- v = get_bits(&gb, 7);
- put_bits(&pb, 8, v);
- }
- }
- align_put_bits(&pb);
- av_free(buf2);
-
- /* End of image */
- put_marker(&pb, EOI);
- flush_put_bits(&pb);
-
- emms_c();
-
- return put_bits_count(&pb) >> 3;
-}
-
-static int encode_init_ls(AVCodecContext *ctx) {
- JpeglsContext *c = (JpeglsContext*)ctx->priv_data;
-
- c->avctx = ctx;
- ctx->coded_frame = &c->picture;
-
- if(ctx->pix_fmt != PIX_FMT_GRAY8 && ctx->pix_fmt != PIX_FMT_GRAY16 && ctx->pix_fmt != PIX_FMT_RGB24 && ctx->pix_fmt != PIX_FMT_BGR24){
- av_log(ctx, AV_LOG_ERROR, "Only grayscale and RGB24/BGR24 images are supported\n");
- return -1;
- }
- return 0;
-}
-
-AVCodec jpegls_encoder = { //FIXME avoid MPV_* lossless jpeg shouldnt need them
- "jpegls",
- CODEC_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, -1},
-};
-#endif
diff --git a/src/libffmpeg/libavcodec/kmvc.c b/src/libffmpeg/libavcodec/kmvc.c
deleted file mode 100644
index 28dc01483..000000000
--- a/src/libffmpeg/libavcodec/kmvc.c
+++ /dev/null
@@ -1,417 +0,0 @@
-/*
- * KMVC decoder
- * Copyright (c) 2006 Konstantin Shishkov
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-/**
- * @file kmvc.c
- * Karl Morton's Video Codec decoder
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "common.h"
-#include "avcodec.h"
-
-#define KMVC_KEYFRAME 0x80
-#define KMVC_PALETTE 0x40
-#define KMVC_METHOD 0x0F
-
-/*
- * Decoder context
- */
-typedef struct KmvcContext {
- AVCodecContext *avctx;
- AVFrame pic;
-
- int setpal;
- int palsize;
- uint32_t pal[256];
- uint8_t *cur, *prev;
- uint8_t *frm0, *frm1;
-} KmvcContext;
-
-typedef struct BitBuf {
- int bits;
- int bitbuf;
-} BitBuf;
-
-#define BLK(data, x, y) data[(x) + (y) * 320]
-
-#define kmvc_init_getbits(bb, src) bb.bits = 7; bb.bitbuf = *src++;
-
-#define kmvc_getbit(bb, src, res) {\
- res = 0; \
- if (bb.bitbuf & (1 << bb.bits)) res = 1; \
- bb.bits--; \
- if(bb.bits == -1) { \
- bb.bitbuf = *src++; \
- bb.bits = 7; \
- } \
-}
-
-static void kmvc_decode_intra_8x8(KmvcContext * ctx, uint8_t * src, int w, int h)
-{
- BitBuf bb;
- int res, val;
- int i, j;
- int bx, by;
- int l0x, l1x, l0y, l1y;
- int mx, my;
-
- kmvc_init_getbits(bb, src);
-
- for (by = 0; by < h; by += 8)
- for (bx = 0; bx < w; bx += 8) {
- kmvc_getbit(bb, src, res);
- if (!res) { // fill whole 8x8 block
- val = *src++;
- for (i = 0; i < 64; i++)
- BLK(ctx->cur, bx + (i & 0x7), by + (i >> 3)) = val;
- } else { // handle four 4x4 subblocks
- for (i = 0; i < 4; i++) {
- l0x = bx + (i & 1) * 4;
- l0y = by + (i & 2) * 2;
- kmvc_getbit(bb, src, res);
- if (!res) {
- kmvc_getbit(bb, src, res);
- if (!res) { // fill whole 4x4 block
- val = *src++;
- for (j = 0; j < 16; j++)
- BLK(ctx->cur, l0x + (j & 3), l0y + (j >> 2)) = val;
- } else { // copy block from already decoded place
- val = *src++;
- mx = val & 0xF;
- my = val >> 4;
- for (j = 0; j < 16; j++)
- BLK(ctx->cur, l0x + (j & 3), l0y + (j >> 2)) =
- BLK(ctx->cur, l0x + (j & 3) - mx, l0y + (j >> 2) - my);
- }
- } else { // descend to 2x2 sub-sub-blocks
- for (j = 0; j < 4; j++) {
- l1x = l0x + (j & 1) * 2;
- l1y = l0y + (j & 2);
- kmvc_getbit(bb, src, res);
- if (!res) {
- kmvc_getbit(bb, src, res);
- if (!res) { // fill whole 2x2 block
- val = *src++;
- BLK(ctx->cur, l1x, l1y) = val;
- BLK(ctx->cur, l1x + 1, l1y) = val;
- BLK(ctx->cur, l1x, l1y + 1) = val;
- BLK(ctx->cur, l1x + 1, l1y + 1) = val;
- } else { // copy block from already decoded place
- val = *src++;
- mx = val & 0xF;
- my = val >> 4;
- BLK(ctx->cur, l1x, l1y) = BLK(ctx->cur, l1x - mx, l1y - my);
- BLK(ctx->cur, l1x + 1, l1y) =
- BLK(ctx->cur, l1x + 1 - mx, l1y - my);
- BLK(ctx->cur, l1x, l1y + 1) =
- BLK(ctx->cur, l1x - mx, l1y + 1 - my);
- BLK(ctx->cur, l1x + 1, l1y + 1) =
- BLK(ctx->cur, l1x + 1 - mx, l1y + 1 - my);
- }
- } else { // read values for block
- BLK(ctx->cur, l1x, l1y) = *src++;
- BLK(ctx->cur, l1x + 1, l1y) = *src++;
- BLK(ctx->cur, l1x, l1y + 1) = *src++;
- BLK(ctx->cur, l1x + 1, l1y + 1) = *src++;
- }
- }
- }
- }
- }
- }
-}
-
-static void kmvc_decode_inter_8x8(KmvcContext * ctx, uint8_t * src, int w, int h)
-{
- BitBuf bb;
- int res, val;
- int i, j;
- int bx, by;
- int l0x, l1x, l0y, l1y;
- int mx, my;
-
- kmvc_init_getbits(bb, src);
-
- for (by = 0; by < h; by += 8)
- for (bx = 0; bx < w; bx += 8) {
- kmvc_getbit(bb, src, res);
- if (!res) {
- kmvc_getbit(bb, src, res);
- if (!res) { // fill whole 8x8 block
- val = *src++;
- for (i = 0; i < 64; i++)
- BLK(ctx->cur, bx + (i & 0x7), by + (i >> 3)) = val;
- } else { // copy block from previous frame
- for (i = 0; i < 64; i++)
- BLK(ctx->cur, bx + (i & 0x7), by + (i >> 3)) =
- BLK(ctx->prev, bx + (i & 0x7), by + (i >> 3));
- }
- } else { // handle four 4x4 subblocks
- for (i = 0; i < 4; i++) {
- l0x = bx + (i & 1) * 4;
- l0y = by + (i & 2) * 2;
- kmvc_getbit(bb, src, res);
- if (!res) {
- kmvc_getbit(bb, src, res);
- if (!res) { // fill whole 4x4 block
- val = *src++;
- for (j = 0; j < 16; j++)
- BLK(ctx->cur, l0x + (j & 3), l0y + (j >> 2)) = val;
- } else { // copy block
- val = *src++;
- mx = (val & 0xF) - 8;
- my = (val >> 4) - 8;
- for (j = 0; j < 16; j++)
- BLK(ctx->cur, l0x + (j & 3), l0y + (j >> 2)) =
- BLK(ctx->prev, l0x + (j & 3) + mx, l0y + (j >> 2) + my);
- }
- } else { // descend to 2x2 sub-sub-blocks
- for (j = 0; j < 4; j++) {
- l1x = l0x + (j & 1) * 2;
- l1y = l0y + (j & 2);
- kmvc_getbit(bb, src, res);
- if (!res) {
- kmvc_getbit(bb, src, res);
- if (!res) { // fill whole 2x2 block
- val = *src++;
- BLK(ctx->cur, l1x, l1y) = val;
- BLK(ctx->cur, l1x + 1, l1y) = val;
- BLK(ctx->cur, l1x, l1y + 1) = val;
- BLK(ctx->cur, l1x + 1, l1y + 1) = val;
- } else { // copy block
- val = *src++;
- mx = (val & 0xF) - 8;
- my = (val >> 4) - 8;
- BLK(ctx->cur, l1x, l1y) = BLK(ctx->prev, l1x + mx, l1y + my);
- BLK(ctx->cur, l1x + 1, l1y) =
- BLK(ctx->prev, l1x + 1 + mx, l1y + my);
- BLK(ctx->cur, l1x, l1y + 1) =
- BLK(ctx->prev, l1x + mx, l1y + 1 + my);
- BLK(ctx->cur, l1x + 1, l1y + 1) =
- BLK(ctx->prev, l1x + 1 + mx, l1y + 1 + my);
- }
- } else { // read values for block
- BLK(ctx->cur, l1x, l1y) = *src++;
- BLK(ctx->cur, l1x + 1, l1y) = *src++;
- BLK(ctx->cur, l1x, l1y + 1) = *src++;
- BLK(ctx->cur, l1x + 1, l1y + 1) = *src++;
- }
- }
- }
- }
- }
- }
-}
-
-static int decode_frame(AVCodecContext * avctx, void *data, int *data_size, uint8_t * buf,
- int buf_size)
-{
- KmvcContext *const ctx = (KmvcContext *) avctx->priv_data;
- uint8_t *out, *src;
- int i;
- int header;
- int blocksize;
-
- if (ctx->pic.data[0])
- avctx->release_buffer(avctx, &ctx->pic);
-
- ctx->pic.reference = 1;
- ctx->pic.buffer_hints = FF_BUFFER_HINTS_VALID;
- if (avctx->get_buffer(avctx, &ctx->pic) < 0) {
- av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
- return -1;
- }
-
- header = *buf++;
-
- /* blocksize 127 is really palette change event */
- if (buf[0] == 127) {
- buf += 3;
- for (i = 0; i < 127; i++) {
- ctx->pal[i + (header & 0x81)] = (buf[0] << 16) | (buf[1] << 8) | buf[2];
- buf += 4;
- }
- buf -= 127 * 4 + 3;
- }
-
- if (header & KMVC_KEYFRAME) {
- ctx->pic.key_frame = 1;
- ctx->pic.pict_type = FF_I_TYPE;
- } else {
- ctx->pic.key_frame = 0;
- ctx->pic.pict_type = FF_P_TYPE;
- }
-
- /* if palette has been changed, copy it from palctrl */
- if (ctx->avctx->palctrl && ctx->avctx->palctrl->palette_changed) {
- memcpy(ctx->pal, ctx->avctx->palctrl->palette, AVPALETTE_SIZE);
- ctx->setpal = 1;
- ctx->avctx->palctrl->palette_changed = 0;
- }
-
- if (header & KMVC_PALETTE) {
- ctx->pic.palette_has_changed = 1;
- // palette starts from index 1 and has 127 entries
- for (i = 1; i <= ctx->palsize; i++) {
- ctx->pal[i] = (buf[0] << 16) | (buf[1] << 8) | buf[2];
- buf += 3;
- }
- }
-
- if (ctx->setpal) {
- ctx->setpal = 0;
- ctx->pic.palette_has_changed = 1;
- }
-
- /* make the palette available on the way out */
- memcpy(ctx->pic.data[1], ctx->pal, 1024);
-
- blocksize = *buf++;
-
- if (blocksize != 8 && blocksize != 127) {
- av_log(avctx, AV_LOG_ERROR, "Block size = %i\n", blocksize);
- return -1;
- }
- memset(ctx->cur, 0, 320 * 200);
- switch (header & KMVC_METHOD) {
- case 0:
- case 1: // used in palette changed event
- memcpy(ctx->cur, ctx->prev, 320 * 200);
- break;
- case 3:
- kmvc_decode_intra_8x8(ctx, buf, avctx->width, avctx->height);
- break;
- case 4:
- kmvc_decode_inter_8x8(ctx, buf, avctx->width, avctx->height);
- break;
- default:
- av_log(avctx, AV_LOG_ERROR, "Unknown compression method %i\n", header & KMVC_METHOD);
- return -1;
- }
-
- out = ctx->pic.data[0];
- src = ctx->cur;
- for (i = 0; i < avctx->height; i++) {
- memcpy(out, src, avctx->width);
- src += 320;
- out += ctx->pic.linesize[0];
- }
-
- /* flip buffers */
- if (ctx->cur == ctx->frm0) {
- ctx->cur = ctx->frm1;
- ctx->prev = ctx->frm0;
- } else {
- ctx->cur = ctx->frm0;
- ctx->prev = ctx->frm1;
- }
-
- *data_size = sizeof(AVFrame);
- *(AVFrame *) data = ctx->pic;
-
- /* always report that the buffer was completely consumed */
- return buf_size;
-}
-
-
-
-/*
- * Init kmvc decoder
- */
-static int decode_init(AVCodecContext * avctx)
-{
- KmvcContext *const c = (KmvcContext *) avctx->priv_data;
- int i;
-
- c->avctx = avctx;
- avctx->has_b_frames = 0;
-
- c->pic.data[0] = NULL;
-
- if (avctx->width > 320 || avctx->height > 200) {
- av_log(avctx, AV_LOG_ERROR, "KMVC supports frames <= 320x200\n");
- return -1;
- }
-
- c->frm0 = av_mallocz(320 * 200);
- c->frm1 = av_mallocz(320 * 200);
- c->cur = c->frm0;
- c->prev = c->frm1;
-
- for (i = 0; i < 256; i++) {
- c->pal[i] = i * 0x10101;
- }
-
- if (avctx->extradata_size < 12) {
- av_log(NULL, 0, "Extradata missing, decoding may not work properly...\n");
- c->palsize = 127;
- } else {
- c->palsize = AV_RL16(avctx->extradata + 10);
- }
-
- if (avctx->extradata_size == 1036) { // palette in extradata
- uint8_t *src = avctx->extradata + 12;
- for (i = 0; i < 256; i++) {
- c->pal[i] = AV_RL32(src);
- src += 4;
- }
- c->setpal = 1;
- if (c->avctx->palctrl) {
- c->avctx->palctrl->palette_changed = 0;
- }
- }
-
- avctx->pix_fmt = PIX_FMT_PAL8;
-
- return 0;
-}
-
-
-
-/*
- * Uninit kmvc decoder
- */
-static int decode_end(AVCodecContext * avctx)
-{
- KmvcContext *const c = (KmvcContext *) avctx->priv_data;
-
- av_freep(&c->frm0);
- av_freep(&c->frm1);
- if (c->pic.data[0])
- avctx->release_buffer(avctx, &c->pic);
-
- return 0;
-}
-
-AVCodec kmvc_decoder = {
- "kmvc",
- CODEC_TYPE_VIDEO,
- CODEC_ID_KMVC,
- sizeof(KmvcContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame
-};
diff --git a/src/libffmpeg/libavcodec/libpostproc/Makefile.am b/src/libffmpeg/libavcodec/libpostproc/Makefile.am
deleted file mode 100644
index 66bd17e53..000000000
--- a/src/libffmpeg/libavcodec/libpostproc/Makefile.am
+++ /dev/null
@@ -1,19 +0,0 @@
-include $(top_srcdir)/misc/Makefile.common
-
-# -fomit-frame-pointer is always needed. it might cause debug to not
-# work, but at least it compiles.
-AM_CFLAGS = -fomit-frame-pointer -fno-strict-aliasing
-AM_CPPFLAGS = $(LIBFFMPEG_CPPFLAGS) -I$(top_srcdir)/src/libffmpeg/libavcodec
-
-# Avoid errors with -O0
-postprocess.o postprocess.lo: CFLAGS=`echo @CFLAGS@ | sed -e 's/-O0\?\s/-Os /g'`
-
-ASFLAGS =
-
-noinst_LTLIBRARIES = libpostprocess.la
-
-EXTRA_DIST = postprocess_template.c postprocess_altivec_template.c
-
-libpostprocess_la_SOURCES = postprocess.c
-
-noinst_HEADERS = mangle.h postprocess.h postprocess_internal.h
diff --git a/src/libffmpeg/libavcodec/libpostproc/mangle.h b/src/libffmpeg/libavcodec/libpostproc/mangle.h
deleted file mode 100644
index 46480ab43..000000000
--- a/src/libffmpeg/libavcodec/libpostproc/mangle.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/* mangle.h - This file has some CPP macros to deal with different symbol
- * mangling across binary formats.
- * (c)2002 by Felix Buenemann <atmosfear at users.sourceforge.net>
- * File licensed under the GPL, see http://www.fsf.org/ for more info.
- */
-
-#ifndef __MANGLE_H
-#define __MANGLE_H
-
-/* Feel free to add more to the list, eg. a.out IMO */
-/* Use rip-relative addressing if compiling PIC code on x86-64. */
-#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__OS2__) || \
- (defined(__OpenBSD__) && !defined(__ELF__))
-#if defined(ARCH_X86_64) && defined(PIC)
-#define MANGLE(a) "_" #a"(%%rip)"
-#else
-#define MANGLE(a) "_" #a
-#endif
-#else
-#if defined(ARCH_X86_64) && defined(PIC)
-#define MANGLE(a) #a"(%%rip)"
-#elif defined(CONFIG_DARWIN)
-#define MANGLE(a) "_" #a
-#else
-#define MANGLE(a) #a
-#endif
-#endif
-
-#endif /* !__MANGLE_H */
-
diff --git a/src/libffmpeg/libavcodec/libpostproc/postprocess.c b/src/libffmpeg/libavcodec/libpostproc/postprocess.c
deleted file mode 100644
index 63d65fece..000000000
--- a/src/libffmpeg/libavcodec/libpostproc/postprocess.c
+++ /dev/null
@@ -1,1157 +0,0 @@
-/*
- Copyright (C) 2001-2003 Michael Niedermayer (michaelni@gmx.at)
-
- AltiVec optimizations (C) 2004 Romain Dolbeau <romain@dolbeau.org>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-
-/**
- * @file postprocess.c
- * postprocessing.
- */
-
-/*
- C MMX MMX2 3DNow AltiVec
-isVertDC Ec Ec Ec
-isVertMinMaxOk Ec Ec Ec
-doVertLowPass E e e Ec
-doVertDefFilter Ec Ec e e Ec
-isHorizDC Ec Ec Ec
-isHorizMinMaxOk a E Ec
-doHorizLowPass E e e Ec
-doHorizDefFilter Ec Ec e e Ec
-do_a_deblock Ec E Ec E
-deRing E e e* Ecp
-Vertical RKAlgo1 E a a
-Horizontal RKAlgo1 a a
-Vertical X1# a E E
-Horizontal X1# a E E
-LinIpolDeinterlace e E E*
-CubicIpolDeinterlace a e e*
-LinBlendDeinterlace e E E*
-MedianDeinterlace# E Ec Ec
-TempDeNoiser# E e e Ec
-
-* i dont have a 3dnow CPU -> its untested, but noone said it doesnt work so it seems to work
-# more or less selfinvented filters so the exactness isnt too meaningfull
-E = Exact implementation
-e = allmost exact implementation (slightly different rounding,...)
-a = alternative / approximate impl
-c = checked against the other implementations (-vo md5)
-p = partially optimized, still some work to do
-*/
-
-/*
-TODO:
-reduce the time wasted on the mem transfer
-unroll stuff if instructions depend too much on the prior one
-move YScale thing to the end instead of fixing QP
-write a faster and higher quality deblocking filter :)
-make the mainloop more flexible (variable number of blocks at once
- (the if/else stuff per block is slowing things down)
-compare the quality & speed of all filters
-split this huge file
-optimize c versions
-try to unroll inner for(x=0 ... loop to avoid these damn if(x ... checks
-...
-*/
-
-//Changelog: use the CVS log
-
-#include "config.h"
-#include <inttypes.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#ifdef HAVE_MALLOC_H
-#include <malloc.h>
-#endif
-//#undef HAVE_MMX2
-//#define HAVE_3DNOW
-//#undef HAVE_MMX
-//#undef ARCH_X86
-//#define DEBUG_BRIGHTNESS
-#ifdef USE_FASTMEMCPY
-#include "fastmemcpy.h"
-#endif
-#include "postprocess.h"
-#include "postprocess_internal.h"
-
-#include "mangle.h" //FIXME should be supressed
-
-#ifdef HAVE_ALTIVEC_H
-#include <altivec.h>
-#endif
-
-#ifndef HAVE_MEMALIGN
-#define memalign(a,b) malloc(b)
-#endif
-
-#define MIN(a,b) ((a) > (b) ? (b) : (a))
-#define MAX(a,b) ((a) < (b) ? (b) : (a))
-#define ABS(a) ((a) > 0 ? (a) : (-(a)))
-#define SIGN(a) ((a) > 0 ? 1 : -1)
-
-#define GET_MODE_BUFFER_SIZE 500
-#define OPTIONS_ARRAY_SIZE 10
-#define BLOCK_SIZE 8
-#define TEMP_STRIDE 8
-//#define NUM_BLOCKS_AT_ONCE 16 //not used yet
-
-#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
-# define attribute_used __attribute__((used))
-# define always_inline __attribute__((always_inline)) inline
-#else
-# define attribute_used
-# define always_inline inline
-#endif
-
-#if defined(ARCH_X86) || defined(ARCH_X86_64)
-static uint64_t __attribute__((aligned(8))) attribute_used w05= 0x0005000500050005LL;
-static uint64_t __attribute__((aligned(8))) attribute_used w04= 0x0004000400040004LL;
-static uint64_t __attribute__((aligned(8))) attribute_used w20= 0x0020002000200020LL;
-static uint64_t __attribute__((aligned(8))) attribute_used b00= 0x0000000000000000LL;
-static uint64_t __attribute__((aligned(8))) attribute_used b01= 0x0101010101010101LL;
-static uint64_t __attribute__((aligned(8))) attribute_used b02= 0x0202020202020202LL;
-static uint64_t __attribute__((aligned(8))) attribute_used b08= 0x0808080808080808LL;
-static uint64_t __attribute__((aligned(8))) attribute_used b80= 0x8080808080808080LL;
-#endif
-
-static uint8_t clip_table[3*256];
-static uint8_t * const clip_tab= clip_table + 256;
-
-static const int verbose= 0;
-
-static const int attribute_used deringThreshold= 20;
-
-
-static struct PPFilter filters[]=
-{
- {"hb", "hdeblock", 1, 1, 3, H_DEBLOCK},
- {"vb", "vdeblock", 1, 2, 4, V_DEBLOCK},
-/* {"hr", "rkhdeblock", 1, 1, 3, H_RK1_FILTER},
- {"vr", "rkvdeblock", 1, 2, 4, V_RK1_FILTER},*/
- {"h1", "x1hdeblock", 1, 1, 3, H_X1_FILTER},
- {"v1", "x1vdeblock", 1, 2, 4, V_X1_FILTER},
- {"ha", "ahdeblock", 1, 1, 3, H_A_DEBLOCK},
- {"va", "avdeblock", 1, 2, 4, V_A_DEBLOCK},
- {"dr", "dering", 1, 5, 6, DERING},
- {"al", "autolevels", 0, 1, 2, LEVEL_FIX},
- {"lb", "linblenddeint", 1, 1, 4, LINEAR_BLEND_DEINT_FILTER},
- {"li", "linipoldeint", 1, 1, 4, LINEAR_IPOL_DEINT_FILTER},
- {"ci", "cubicipoldeint", 1, 1, 4, CUBIC_IPOL_DEINT_FILTER},
- {"md", "mediandeint", 1, 1, 4, MEDIAN_DEINT_FILTER},
- {"fd", "ffmpegdeint", 1, 1, 4, FFMPEG_DEINT_FILTER},
- {"l5", "lowpass5", 1, 1, 4, LOWPASS5_DEINT_FILTER},
- {"tn", "tmpnoise", 1, 7, 8, TEMP_NOISE_FILTER},
- {"fq", "forcequant", 1, 0, 0, FORCE_QUANT},
- {NULL, NULL,0,0,0,0} //End Marker
-};
-
-static char *replaceTable[]=
-{
- "default", "hdeblock:a,vdeblock:a,dering:a",
- "de", "hdeblock:a,vdeblock:a,dering:a",
- "fast", "x1hdeblock:a,x1vdeblock:a,dering:a",
- "fa", "x1hdeblock:a,x1vdeblock:a,dering:a",
- "ac", "ha:a:128:7,va:a,dering:a",
- NULL //End Marker
-};
-
-
-#if defined(ARCH_X86) || defined(ARCH_X86_64)
-static inline void prefetchnta(void *p)
-{
- asm volatile( "prefetchnta (%0)\n\t"
- : : "r" (p)
- );
-}
-
-static inline void prefetcht0(void *p)
-{
- asm volatile( "prefetcht0 (%0)\n\t"
- : : "r" (p)
- );
-}
-
-static inline void prefetcht1(void *p)
-{
- asm volatile( "prefetcht1 (%0)\n\t"
- : : "r" (p)
- );
-}
-
-static inline void prefetcht2(void *p)
-{
- asm volatile( "prefetcht2 (%0)\n\t"
- : : "r" (p)
- );
-}
-#endif
-
-// The horizontal Functions exist only in C cuz the MMX code is faster with vertical filters and transposing
-
-/**
- * Check if the given 8x8 Block is mostly "flat"
- */
-static inline int isHorizDC_C(uint8_t src[], int stride, PPContext *c)
-{
- int numEq= 0;
- int y;
- const int dcOffset= ((c->nonBQP*c->ppMode.baseDcDiff)>>8) + 1;
- const int dcThreshold= dcOffset*2 + 1;
-
- for(y=0; y<BLOCK_SIZE; y++)
- {
- if(((unsigned)(src[0] - src[1] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[1] - src[2] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[2] - src[3] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[3] - src[4] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[4] - src[5] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[5] - src[6] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[6] - src[7] + dcOffset)) < dcThreshold) numEq++;
- src+= stride;
- }
- return numEq > c->ppMode.flatnessThreshold;
-}
-
-/**
- * Check if the middle 8x8 Block in the given 8x16 block is flat
- */
-static inline int isVertDC_C(uint8_t src[], int stride, PPContext *c){
- int numEq= 0;
- int y;
- const int dcOffset= ((c->nonBQP*c->ppMode.baseDcDiff)>>8) + 1;
- const int dcThreshold= dcOffset*2 + 1;
-
- src+= stride*4; // src points to begin of the 8x8 Block
- for(y=0; y<BLOCK_SIZE-1; y++)
- {
- if(((unsigned)(src[0] - src[0+stride] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[1] - src[1+stride] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[2] - src[2+stride] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[3] - src[3+stride] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[4] - src[4+stride] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[5] - src[5+stride] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[6] - src[6+stride] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[7] - src[7+stride] + dcOffset)) < dcThreshold) numEq++;
- src+= stride;
- }
- return numEq > c->ppMode.flatnessThreshold;
-}
-
-static inline int isHorizMinMaxOk_C(uint8_t src[], int stride, int QP)
-{
- int i;
-#if 1
- for(i=0; i<2; i++){
- if((unsigned)(src[0] - src[5] + 2*QP) > 4*QP) return 0;
- src += stride;
- if((unsigned)(src[2] - src[7] + 2*QP) > 4*QP) return 0;
- src += stride;
- if((unsigned)(src[4] - src[1] + 2*QP) > 4*QP) return 0;
- src += stride;
- if((unsigned)(src[6] - src[3] + 2*QP) > 4*QP) return 0;
- src += stride;
- }
-#else
- for(i=0; i<8; i++){
- if((unsigned)(src[0] - src[7] + 2*QP) > 4*QP) return 0;
- src += stride;
- }
-#endif
- return 1;
-}
-
-static inline int isVertMinMaxOk_C(uint8_t src[], int stride, int QP)
-{
-#if 1
-#if 1
- int x;
- src+= stride*4;
- for(x=0; x<BLOCK_SIZE; x+=4)
- {
- if((unsigned)(src[ x + 0*stride] - src[ x + 5*stride] + 2*QP) > 4*QP) return 0;
- if((unsigned)(src[1+x + 2*stride] - src[1+x + 7*stride] + 2*QP) > 4*QP) return 0;
- if((unsigned)(src[2+x + 4*stride] - src[2+x + 1*stride] + 2*QP) > 4*QP) return 0;
- if((unsigned)(src[3+x + 6*stride] - src[3+x + 3*stride] + 2*QP) > 4*QP) return 0;
- }
-#else
- int x;
- src+= stride*3;
- for(x=0; x<BLOCK_SIZE; x++)
- {
- if((unsigned)(src[x + stride] - src[x + (stride<<3)] + 2*QP) > 4*QP) return 0;
- }
-#endif
- return 1;
-#else
- int x;
- src+= stride*4;
- for(x=0; x<BLOCK_SIZE; x++)
- {
- int min=255;
- int max=0;
- int y;
- for(y=0; y<8; y++){
- int v= src[x + y*stride];
- if(v>max) max=v;
- if(v<min) min=v;
- }
- if(max-min > 2*QP) return 0;
- }
- return 1;
-#endif
-}
-
-static inline int horizClassify_C(uint8_t src[], int stride, PPContext *c){
- if( isHorizDC_C(src, stride, c) ){
- if( isHorizMinMaxOk_C(src, stride, c->QP) )
- return 1;
- else
- return 0;
- }else{
- return 2;
- }
-}
-
-static inline int vertClassify_C(uint8_t src[], int stride, PPContext *c){
- if( isVertDC_C(src, stride, c) ){
- if( isVertMinMaxOk_C(src, stride, c->QP) )
- return 1;
- else
- return 0;
- }else{
- return 2;
- }
-}
-
-static inline void doHorizDefFilter_C(uint8_t dst[], int stride, PPContext *c)
-{
- int y;
- for(y=0; y<BLOCK_SIZE; y++)
- {
- const int middleEnergy= 5*(dst[4] - dst[3]) + 2*(dst[2] - dst[5]);
-
- if(ABS(middleEnergy) < 8*c->QP)
- {
- const int q=(dst[3] - dst[4])/2;
- const int leftEnergy= 5*(dst[2] - dst[1]) + 2*(dst[0] - dst[3]);
- const int rightEnergy= 5*(dst[6] - dst[5]) + 2*(dst[4] - dst[7]);
-
- int d= ABS(middleEnergy) - MIN( ABS(leftEnergy), ABS(rightEnergy) );
- d= MAX(d, 0);
-
- d= (5*d + 32) >> 6;
- d*= SIGN(-middleEnergy);
-
- if(q>0)
- {
- d= d<0 ? 0 : d;
- d= d>q ? q : d;
- }
- else
- {
- d= d>0 ? 0 : d;
- d= d<q ? q : d;
- }
-
- dst[3]-= d;
- dst[4]+= d;
- }
- dst+= stride;
- }
-}
-
-/**
- * Do a horizontal low pass filter on the 10x8 block (dst points to middle 8x8 Block)
- * using the 9-Tap Filter (1,1,2,2,4,2,2,1,1)/16 (C version)
- */
-static inline void doHorizLowPass_C(uint8_t dst[], int stride, PPContext *c)
-{
- int y;
- for(y=0; y<BLOCK_SIZE; y++)
- {
- const int first= ABS(dst[-1] - dst[0]) < c->QP ? dst[-1] : dst[0];
- const int last= ABS(dst[8] - dst[7]) < c->QP ? dst[8] : dst[7];
-
- int sums[10];
- sums[0] = 4*first + dst[0] + dst[1] + dst[2] + 4;
- sums[1] = sums[0] - first + dst[3];
- sums[2] = sums[1] - first + dst[4];
- sums[3] = sums[2] - first + dst[5];
- sums[4] = sums[3] - first + dst[6];
- sums[5] = sums[4] - dst[0] + dst[7];
- sums[6] = sums[5] - dst[1] + last;
- sums[7] = sums[6] - dst[2] + last;
- sums[8] = sums[7] - dst[3] + last;
- sums[9] = sums[8] - dst[4] + last;
-
- dst[0]= (sums[0] + sums[2] + 2*dst[0])>>4;
- dst[1]= (sums[1] + sums[3] + 2*dst[1])>>4;
- dst[2]= (sums[2] + sums[4] + 2*dst[2])>>4;
- dst[3]= (sums[3] + sums[5] + 2*dst[3])>>4;
- dst[4]= (sums[4] + sums[6] + 2*dst[4])>>4;
- dst[5]= (sums[5] + sums[7] + 2*dst[5])>>4;
- dst[6]= (sums[6] + sums[8] + 2*dst[6])>>4;
- dst[7]= (sums[7] + sums[9] + 2*dst[7])>>4;
-
- dst+= stride;
- }
-}
-
-/**
- * Experimental Filter 1 (Horizontal)
- * will not damage linear gradients
- * Flat blocks should look like they where passed through the (1,1,2,2,4,2,2,1,1) 9-Tap filter
- * can only smooth blocks at the expected locations (it cant smooth them if they did move)
- * MMX2 version does correct clipping C version doesnt
- * not identical with the vertical one
- */
-static inline void horizX1Filter(uint8_t *src, int stride, int QP)
-{
- int y;
- static uint64_t *lut= NULL;
- if(lut==NULL)
- {
- int i;
- lut= (uint64_t*)memalign(8, 256*8);
- for(i=0; i<256; i++)
- {
- int v= i < 128 ? 2*i : 2*(i-256);
-/*
-//Simulate 112242211 9-Tap filter
- uint64_t a= (v/16) & 0xFF;
- uint64_t b= (v/8) & 0xFF;
- uint64_t c= (v/4) & 0xFF;
- uint64_t d= (3*v/8) & 0xFF;
-*/
-//Simulate piecewise linear interpolation
- uint64_t a= (v/16) & 0xFF;
- uint64_t b= (v*3/16) & 0xFF;
- uint64_t c= (v*5/16) & 0xFF;
- uint64_t d= (7*v/16) & 0xFF;
- uint64_t A= (0x100 - a)&0xFF;
- uint64_t B= (0x100 - b)&0xFF;
- uint64_t C= (0x100 - c)&0xFF;
- uint64_t D= (0x100 - c)&0xFF;
-
- lut[i] = (a<<56) | (b<<48) | (c<<40) | (d<<32) |
- (D<<24) | (C<<16) | (B<<8) | (A);
- //lut[i] = (v<<32) | (v<<24);
- }
- }
-
- for(y=0; y<BLOCK_SIZE; y++)
- {
- int a= src[1] - src[2];
- int b= src[3] - src[4];
- int c= src[5] - src[6];
-
- int d= MAX(ABS(b) - (ABS(a) + ABS(c))/2, 0);
-
- if(d < QP)
- {
- int v = d * SIGN(-b);
-
- src[1] +=v/8;
- src[2] +=v/4;
- src[3] +=3*v/8;
- src[4] -=3*v/8;
- src[5] -=v/4;
- src[6] -=v/8;
-
- }
- src+=stride;
- }
-}
-
-/**
- * accurate deblock filter
- */
-static always_inline void do_a_deblock_C(uint8_t *src, int step, int stride, PPContext *c){
- int y;
- const int QP= c->QP;
- const int dcOffset= ((c->nonBQP*c->ppMode.baseDcDiff)>>8) + 1;
- const int dcThreshold= dcOffset*2 + 1;
-//START_TIMER
- src+= step*4; // src points to begin of the 8x8 Block
- for(y=0; y<8; y++){
- int numEq= 0;
-
- if(((unsigned)(src[-1*step] - src[0*step] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[ 0*step] - src[1*step] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[ 1*step] - src[2*step] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[ 2*step] - src[3*step] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[ 3*step] - src[4*step] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[ 4*step] - src[5*step] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[ 5*step] - src[6*step] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[ 6*step] - src[7*step] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[ 7*step] - src[8*step] + dcOffset)) < dcThreshold) numEq++;
- if(numEq > c->ppMode.flatnessThreshold){
- int min, max, x;
-
- if(src[0] > src[step]){
- max= src[0];
- min= src[step];
- }else{
- max= src[step];
- min= src[0];
- }
- for(x=2; x<8; x+=2){
- if(src[x*step] > src[(x+1)*step]){
- if(src[x *step] > max) max= src[ x *step];
- if(src[(x+1)*step] < min) min= src[(x+1)*step];
- }else{
- if(src[(x+1)*step] > max) max= src[(x+1)*step];
- if(src[ x *step] < min) min= src[ x *step];
- }
- }
- if(max-min < 2*QP){
- const int first= ABS(src[-1*step] - src[0]) < QP ? src[-1*step] : src[0];
- const int last= ABS(src[8*step] - src[7*step]) < QP ? src[8*step] : src[7*step];
-
- int sums[10];
- sums[0] = 4*first + src[0*step] + src[1*step] + src[2*step] + 4;
- sums[1] = sums[0] - first + src[3*step];
- sums[2] = sums[1] - first + src[4*step];
- sums[3] = sums[2] - first + src[5*step];
- sums[4] = sums[3] - first + src[6*step];
- sums[5] = sums[4] - src[0*step] + src[7*step];
- sums[6] = sums[5] - src[1*step] + last;
- sums[7] = sums[6] - src[2*step] + last;
- sums[8] = sums[7] - src[3*step] + last;
- sums[9] = sums[8] - src[4*step] + last;
-
- src[0*step]= (sums[0] + sums[2] + 2*src[0*step])>>4;
- src[1*step]= (sums[1] + sums[3] + 2*src[1*step])>>4;
- src[2*step]= (sums[2] + sums[4] + 2*src[2*step])>>4;
- src[3*step]= (sums[3] + sums[5] + 2*src[3*step])>>4;
- src[4*step]= (sums[4] + sums[6] + 2*src[4*step])>>4;
- src[5*step]= (sums[5] + sums[7] + 2*src[5*step])>>4;
- src[6*step]= (sums[6] + sums[8] + 2*src[6*step])>>4;
- src[7*step]= (sums[7] + sums[9] + 2*src[7*step])>>4;
- }
- }else{
- const int middleEnergy= 5*(src[4*step] - src[3*step]) + 2*(src[2*step] - src[5*step]);
-
- if(ABS(middleEnergy) < 8*QP)
- {
- const int q=(src[3*step] - src[4*step])/2;
- const int leftEnergy= 5*(src[2*step] - src[1*step]) + 2*(src[0*step] - src[3*step]);
- const int rightEnergy= 5*(src[6*step] - src[5*step]) + 2*(src[4*step] - src[7*step]);
-
- int d= ABS(middleEnergy) - MIN( ABS(leftEnergy), ABS(rightEnergy) );
- d= MAX(d, 0);
-
- d= (5*d + 32) >> 6;
- d*= SIGN(-middleEnergy);
-
- if(q>0)
- {
- d= d<0 ? 0 : d;
- d= d>q ? q : d;
- }
- else
- {
- d= d>0 ? 0 : d;
- d= d<q ? q : d;
- }
-
- src[3*step]-= d;
- src[4*step]+= d;
- }
- }
-
- src += stride;
- }
-/*if(step==16){
- STOP_TIMER("step16")
-}else{
- STOP_TIMER("stepX")
-}*/
-}
-
-//Note: we have C, MMX, MMX2, 3DNOW version there is no 3DNOW+MMX2 one
-//Plain C versions
-#if !defined (HAVE_MMX) || defined (RUNTIME_CPUDETECT)
-#define COMPILE_C
-#endif
-
-#ifdef ARCH_POWERPC
-#ifdef HAVE_ALTIVEC
-#define COMPILE_ALTIVEC
-#endif //HAVE_ALTIVEC
-#endif //ARCH_POWERPC
-
-#if defined(ARCH_X86) || defined(ARCH_X86_64)
-
-#if (defined (HAVE_MMX) && !defined (HAVE_3DNOW) && !defined (HAVE_MMX2)) || defined (RUNTIME_CPUDETECT)
-#define COMPILE_MMX
-#endif
-
-#if defined (HAVE_MMX2) || defined (RUNTIME_CPUDETECT)
-#define COMPILE_MMX2
-#endif
-
-#if (defined (HAVE_3DNOW) && !defined (HAVE_MMX2)) || defined (RUNTIME_CPUDETECT)
-#define COMPILE_3DNOW
-#endif
-#endif //ARCH_X86
-
-#undef HAVE_MMX
-#undef HAVE_MMX2
-#undef HAVE_3DNOW
-#undef HAVE_ALTIVEC
-
-#ifdef COMPILE_C
-#undef HAVE_MMX
-#undef HAVE_MMX2
-#undef HAVE_3DNOW
-#define RENAME(a) a ## _C
-#include "postprocess_template.c"
-#endif
-
-#ifdef ARCH_POWERPC
-#ifdef COMPILE_ALTIVEC
-#undef RENAME
-#define HAVE_ALTIVEC
-#define RENAME(a) a ## _altivec
-#include "postprocess_altivec_template.c"
-#include "postprocess_template.c"
-#endif
-#endif //ARCH_POWERPC
-
-//MMX versions
-#ifdef COMPILE_MMX
-#undef RENAME
-#define HAVE_MMX
-#undef HAVE_MMX2
-#undef HAVE_3DNOW
-#define RENAME(a) a ## _MMX
-#include "postprocess_template.c"
-#endif
-
-//MMX2 versions
-#ifdef COMPILE_MMX2
-#undef RENAME
-#define HAVE_MMX
-#define HAVE_MMX2
-#undef HAVE_3DNOW
-#define RENAME(a) a ## _MMX2
-#include "postprocess_template.c"
-#endif
-
-//3DNOW versions
-#ifdef COMPILE_3DNOW
-#undef RENAME
-#define HAVE_MMX
-#undef HAVE_MMX2
-#define HAVE_3DNOW
-#define RENAME(a) a ## _3DNow
-#include "postprocess_template.c"
-#endif
-
-// minor note: the HAVE_xyz is messed up after that line so dont use it
-
-static inline void postProcess(uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height,
- QP_STORE_T QPs[], int QPStride, int isColor, pp_mode_t *vm, pp_context_t *vc)
-{
- PPContext *c= (PPContext *)vc;
- PPMode *ppMode= (PPMode *)vm;
- c->ppMode= *ppMode; //FIXME
-
- // useing ifs here as they are faster than function pointers allthough the
- // difference wouldnt be messureable here but its much better because
- // someone might exchange the cpu whithout restarting mplayer ;)
-#ifdef RUNTIME_CPUDETECT
-#if defined(ARCH_X86) || defined(ARCH_X86_64)
- // ordered per speed fasterst first
- if(c->cpuCaps & PP_CPU_CAPS_MMX2)
- postProcess_MMX2(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
- else if(c->cpuCaps & PP_CPU_CAPS_3DNOW)
- postProcess_3DNow(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
- else if(c->cpuCaps & PP_CPU_CAPS_MMX)
- postProcess_MMX(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
- else
- postProcess_C(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
-#else
-#ifdef ARCH_POWERPC
-#ifdef HAVE_ALTIVEC
- if(c->cpuCaps & PP_CPU_CAPS_ALTIVEC)
- postProcess_altivec(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
- else
-#endif
-#endif
- postProcess_C(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
-#endif
-#else //RUNTIME_CPUDETECT
-#ifdef HAVE_MMX2
- postProcess_MMX2(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
-#elif defined (HAVE_3DNOW)
- postProcess_3DNow(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
-#elif defined (HAVE_MMX)
- postProcess_MMX(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
-#elif defined (HAVE_ALTIVEC)
- postProcess_altivec(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
-#else
- postProcess_C(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
-#endif
-#endif //!RUNTIME_CPUDETECT
-}
-
-//static void postProcess(uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height,
-// QP_STORE_T QPs[], int QPStride, int isColor, struct PPMode *ppMode);
-
-/* -pp Command line Help
-*/
-char *pp_help=
-"Available postprocessing filters:\n"
-"Filters Options\n"
-"short long name short long option Description\n"
-"* * a autoq CPU power dependent enabler\n"
-" c chrom chrominance filtering enabled\n"
-" y nochrom chrominance filtering disabled\n"
-" n noluma luma filtering disabled\n"
-"hb hdeblock (2 threshold) horizontal deblocking filter\n"
-" 1. difference factor: default=32, higher -> more deblocking\n"
-" 2. flatness threshold: default=39, lower -> more deblocking\n"
-" the h & v deblocking filters share these\n"
-" so you can't set different thresholds for h / v\n"
-"vb vdeblock (2 threshold) vertical deblocking filter\n"
-"ha hadeblock (2 threshold) horizontal deblocking filter\n"
-"va vadeblock (2 threshold) vertical deblocking filter\n"
-"h1 x1hdeblock experimental h deblock filter 1\n"
-"v1 x1vdeblock experimental v deblock filter 1\n"
-"dr dering deringing filter\n"
-"al autolevels automatic brightness / contrast\n"
-" f fullyrange stretch luminance to (0..255)\n"
-"lb linblenddeint linear blend deinterlacer\n"
-"li linipoldeint linear interpolating deinterlace\n"
-"ci cubicipoldeint cubic interpolating deinterlacer\n"
-"md mediandeint median deinterlacer\n"
-"fd ffmpegdeint ffmpeg deinterlacer\n"
-"l5 lowpass5 FIR lowpass deinterlacer\n"
-"de default hb:a,vb:a,dr:a\n"
-"fa fast h1:a,v1:a,dr:a\n"
-"ac ha:a:128:7,va:a,dr:a\n"
-"tn tmpnoise (3 threshold) temporal noise reducer\n"
-" 1. <= 2. <= 3. larger -> stronger filtering\n"
-"fq forceQuant <quantizer> force quantizer\n"
-"Usage:\n"
-"<filterName>[:<option>[:<option>...]][[,|/][-]<filterName>[:<option>...]]...\n"
-"long form example:\n"
-"vdeblock:autoq/hdeblock:autoq/linblenddeint default,-vdeblock\n"
-"short form example:\n"
-"vb:a/hb:a/lb de,-vb\n"
-"more examples:\n"
-"tn:64:128:256\n"
-;
-
-pp_mode_t *pp_get_mode_by_name_and_quality(char *name, int quality)
-{
- char temp[GET_MODE_BUFFER_SIZE];
- char *p= temp;
- char *filterDelimiters= ",/";
- char *optionDelimiters= ":";
- struct PPMode *ppMode;
- char *filterToken;
-
- ppMode= memalign(8, sizeof(PPMode));
-
- ppMode->lumMode= 0;
- ppMode->chromMode= 0;
- ppMode->maxTmpNoise[0]= 700;
- ppMode->maxTmpNoise[1]= 1500;
- ppMode->maxTmpNoise[2]= 3000;
- ppMode->maxAllowedY= 234;
- ppMode->minAllowedY= 16;
- ppMode->baseDcDiff= 256/8;
- ppMode->flatnessThreshold= 56-16-1;
- ppMode->maxClippedThreshold= 0.01;
- ppMode->error=0;
-
- strncpy(temp, name, GET_MODE_BUFFER_SIZE);
-
- if(verbose>1) printf("pp: %s\n", name);
-
- for(;;){
- char *filterName;
- int q= 1000000; //PP_QUALITY_MAX;
- int chrom=-1;
- int luma=-1;
- char *option;
- char *options[OPTIONS_ARRAY_SIZE];
- int i;
- int filterNameOk=0;
- int numOfUnknownOptions=0;
- int enable=1; //does the user want us to enabled or disabled the filter
-
- filterToken= strtok(p, filterDelimiters);
- if(filterToken == NULL) break;
- p+= strlen(filterToken) + 1; // p points to next filterToken
- filterName= strtok(filterToken, optionDelimiters);
- if(verbose>1) printf("pp: %s::%s\n", filterToken, filterName);
-
- if(*filterName == '-')
- {
- enable=0;
- filterName++;
- }
-
- for(;;){ //for all options
- option= strtok(NULL, optionDelimiters);
- if(option == NULL) break;
-
- if(verbose>1) printf("pp: option: %s\n", option);
- if(!strcmp("autoq", option) || !strcmp("a", option)) q= quality;
- else if(!strcmp("nochrom", option) || !strcmp("y", option)) chrom=0;
- else if(!strcmp("chrom", option) || !strcmp("c", option)) chrom=1;
- else if(!strcmp("noluma", option) || !strcmp("n", option)) luma=0;
- else
- {
- options[numOfUnknownOptions] = option;
- numOfUnknownOptions++;
- }
- if(numOfUnknownOptions >= OPTIONS_ARRAY_SIZE-1) break;
- }
- options[numOfUnknownOptions] = NULL;
-
- /* replace stuff from the replace Table */
- for(i=0; replaceTable[2*i]!=NULL; i++)
- {
- if(!strcmp(replaceTable[2*i], filterName))
- {
- int newlen= strlen(replaceTable[2*i + 1]);
- int plen;
- int spaceLeft;
-
- if(p==NULL) p= temp, *p=0; //last filter
- else p--, *p=','; //not last filter
-
- plen= strlen(p);
- spaceLeft= p - temp + plen;
- if(spaceLeft + newlen >= GET_MODE_BUFFER_SIZE)
- {
- ppMode->error++;
- break;
- }
- memmove(p + newlen, p, plen+1);
- memcpy(p, replaceTable[2*i + 1], newlen);
- filterNameOk=1;
- }
- }
-
- for(i=0; filters[i].shortName!=NULL; i++)
- {
-// printf("Compareing %s, %s, %s\n", filters[i].shortName,filters[i].longName, filterName);
- if( !strcmp(filters[i].longName, filterName)
- || !strcmp(filters[i].shortName, filterName))
- {
- ppMode->lumMode &= ~filters[i].mask;
- ppMode->chromMode &= ~filters[i].mask;
-
- filterNameOk=1;
- if(!enable) break; // user wants to disable it
-
- if(q >= filters[i].minLumQuality && luma)
- ppMode->lumMode|= filters[i].mask;
- if(chrom==1 || (chrom==-1 && filters[i].chromDefault))
- if(q >= filters[i].minChromQuality)
- ppMode->chromMode|= filters[i].mask;
-
- if(filters[i].mask == LEVEL_FIX)
- {
- int o;
- ppMode->minAllowedY= 16;
- ppMode->maxAllowedY= 234;
- for(o=0; options[o]!=NULL; o++)
- {
- if( !strcmp(options[o],"fullyrange")
- ||!strcmp(options[o],"f"))
- {
- ppMode->minAllowedY= 0;
- ppMode->maxAllowedY= 255;
- numOfUnknownOptions--;
- }
- }
- }
- else if(filters[i].mask == TEMP_NOISE_FILTER)
- {
- int o;
- int numOfNoises=0;
-
- for(o=0; options[o]!=NULL; o++)
- {
- char *tail;
- ppMode->maxTmpNoise[numOfNoises]=
- strtol(options[o], &tail, 0);
- if(tail!=options[o])
- {
- numOfNoises++;
- numOfUnknownOptions--;
- if(numOfNoises >= 3) break;
- }
- }
- }
- else if(filters[i].mask == V_DEBLOCK || filters[i].mask == H_DEBLOCK
- || filters[i].mask == V_A_DEBLOCK || filters[i].mask == H_A_DEBLOCK)
- {
- int o;
-
- for(o=0; options[o]!=NULL && o<2; o++)
- {
- char *tail;
- int val= strtol(options[o], &tail, 0);
- if(tail==options[o]) break;
-
- numOfUnknownOptions--;
- if(o==0) ppMode->baseDcDiff= val;
- else ppMode->flatnessThreshold= val;
- }
- }
- else if(filters[i].mask == FORCE_QUANT)
- {
- int o;
- ppMode->forcedQuant= 15;
-
- for(o=0; options[o]!=NULL && o<1; o++)
- {
- char *tail;
- int val= strtol(options[o], &tail, 0);
- if(tail==options[o]) break;
-
- numOfUnknownOptions--;
- ppMode->forcedQuant= val;
- }
- }
- }
- }
- if(!filterNameOk) ppMode->error++;
- ppMode->error += numOfUnknownOptions;
- }
-
- if(verbose>1) printf("pp: lumMode=%X, chromMode=%X\n", ppMode->lumMode, ppMode->chromMode);
- if(ppMode->error)
- {
- fprintf(stderr, "%d errors in postprocess string \"%s\"\n", ppMode->error, name);
- free(ppMode);
- return NULL;
- }
- return ppMode;
-}
-
-void pp_free_mode(pp_mode_t *mode){
- if(mode) free(mode);
-}
-
-static void reallocAlign(void **p, int alignment, int size){
- if(*p) free(*p);
- *p= memalign(alignment, size);
- memset(*p, 0, size);
-}
-
-static void reallocBuffers(PPContext *c, int width, int height, int stride, int qpStride){
- int mbWidth = (width+15)>>4;
- int mbHeight= (height+15)>>4;
- int i;
-
- c->stride= stride;
- c->qpStride= qpStride;
-
- reallocAlign((void **)&c->tempDst, 8, stride*24);
- reallocAlign((void **)&c->tempSrc, 8, stride*24);
- reallocAlign((void **)&c->tempBlocks, 8, 2*16*8);
- reallocAlign((void **)&c->yHistogram, 8, 256*sizeof(uint64_t));
- for(i=0; i<256; i++)
- c->yHistogram[i]= width*height/64*15/256;
-
- for(i=0; i<3; i++)
- {
- //Note:the +17*1024 is just there so i dont have to worry about r/w over te end
- reallocAlign((void **)&c->tempBlured[i], 8, stride*mbHeight*16 + 17*1024);
- reallocAlign((void **)&c->tempBluredPast[i], 8, 256*((height+7)&(~7))/2 + 17*1024);//FIXME size
- }
-
- reallocAlign((void **)&c->deintTemp, 8, 2*width+32);
- reallocAlign((void **)&c->nonBQPTable, 8, qpStride*mbHeight*sizeof(QP_STORE_T));
- reallocAlign((void **)&c->stdQPTable, 8, qpStride*mbHeight*sizeof(QP_STORE_T));
- reallocAlign((void **)&c->forcedQPTable, 8, mbWidth*sizeof(QP_STORE_T));
-}
-
-static void global_init(void){
- int i;
- memset(clip_table, 0, 256);
- for(i=256; i<512; i++)
- clip_table[i]= i;
- memset(clip_table+512, 0, 256);
-}
-
-pp_context_t *pp_get_context(int width, int height, int cpuCaps){
- PPContext *c= memalign(32, sizeof(PPContext));
- int stride= (width+15)&(~15); //assumed / will realloc if needed
- int qpStride= (width+15)/16 + 2; //assumed / will realloc if needed
-
- global_init();
-
- memset(c, 0, sizeof(PPContext));
- c->cpuCaps= cpuCaps;
- if(cpuCaps&PP_FORMAT){
- c->hChromaSubSample= cpuCaps&0x3;
- c->vChromaSubSample= (cpuCaps>>4)&0x3;
- }else{
- c->hChromaSubSample= 1;
- c->vChromaSubSample= 1;
- }
-
- reallocBuffers(c, width, height, stride, qpStride);
-
- c->frameNum=-1;
-
- return c;
-}
-
-void pp_free_context(void *vc){
- PPContext *c = (PPContext*)vc;
- int i;
-
- for(i=0; i<3; i++) free(c->tempBlured[i]);
- for(i=0; i<3; i++) free(c->tempBluredPast[i]);
-
- free(c->tempBlocks);
- free(c->yHistogram);
- free(c->tempDst);
- free(c->tempSrc);
- free(c->deintTemp);
- free(c->stdQPTable);
- free(c->nonBQPTable);
- free(c->forcedQPTable);
-
- memset(c, 0, sizeof(PPContext));
-
- free(c);
-}
-
-void pp_postprocess(uint8_t * src[3], int srcStride[3],
- uint8_t * dst[3], int dstStride[3],
- int width, int height,
- QP_STORE_T *QP_store, int QPStride,
- pp_mode_t *vm, void *vc, int pict_type)
-{
- int mbWidth = (width+15)>>4;
- int mbHeight= (height+15)>>4;
- PPMode *mode = (PPMode*)vm;
- PPContext *c = (PPContext*)vc;
- int minStride= MAX(ABS(srcStride[0]), ABS(dstStride[0]));
- int absQPStride = ABS(QPStride);
-
- // c->stride and c->QPStride are always positive
- if(c->stride < minStride || c->qpStride < absQPStride)
- reallocBuffers(c, width, height,
- MAX(minStride, c->stride),
- MAX(c->qpStride, absQPStride));
-
- if(QP_store==NULL || (mode->lumMode & FORCE_QUANT))
- {
- int i;
- QP_store= c->forcedQPTable;
- absQPStride = QPStride = 0;
- if(mode->lumMode & FORCE_QUANT)
- for(i=0; i<mbWidth; i++) QP_store[i]= mode->forcedQuant;
- else
- for(i=0; i<mbWidth; i++) QP_store[i]= 1;
- }
-//printf("pict_type:%d\n", pict_type);
-
- if(pict_type & PP_PICT_TYPE_QP2){
- int i;
- const int count= mbHeight * absQPStride;
- for(i=0; i<(count>>2); i++){
- ((uint32_t*)c->stdQPTable)[i] = (((uint32_t*)QP_store)[i]>>1) & 0x7F7F7F7F;
- }
- for(i<<=2; i<count; i++){
- c->stdQPTable[i] = QP_store[i]>>1;
- }
- QP_store= c->stdQPTable;
- QPStride= absQPStride;
- }
-
-if(0){
-int x,y;
-for(y=0; y<mbHeight; y++){
- for(x=0; x<mbWidth; x++){
- printf("%2d ", QP_store[x + y*QPStride]);
- }
- printf("\n");
-}
- printf("\n");
-}
-
- if((pict_type&7)!=3)
- {
- if (QPStride >= 0) {
- int i;
- const int count= mbHeight * QPStride;
- for(i=0; i<(count>>2); i++){
- ((uint32_t*)c->nonBQPTable)[i] = ((uint32_t*)QP_store)[i] & 0x3F3F3F3F;
- }
- for(i<<=2; i<count; i++){
- c->nonBQPTable[i] = QP_store[i] & 0x3F;
- }
- } else {
- int i,j;
- for(i=0; i<mbHeight; i++) {
- for(j=0; j<absQPStride; j++) {
- c->nonBQPTable[i*absQPStride+j] = QP_store[i*QPStride+j] & 0x3F;
- }
- }
- }
- }
-
- if(verbose>2)
- {
- printf("using npp filters 0x%X/0x%X\n", mode->lumMode, mode->chromMode);
- }
-
- postProcess(src[0], srcStride[0], dst[0], dstStride[0],
- width, height, QP_store, QPStride, 0, mode, c);
-
- width = (width )>>c->hChromaSubSample;
- height = (height)>>c->vChromaSubSample;
-
- if(mode->chromMode)
- {
- postProcess(src[1], srcStride[1], dst[1], dstStride[1],
- width, height, QP_store, QPStride, 1, mode, c);
- postProcess(src[2], srcStride[2], dst[2], dstStride[2],
- width, height, QP_store, QPStride, 2, mode, c);
- }
- else if(srcStride[1] == dstStride[1] && srcStride[2] == dstStride[2])
- {
- linecpy(dst[1], src[1], height, srcStride[1]);
- linecpy(dst[2], src[2], height, srcStride[2]);
- }
- else
- {
- int y;
- for(y=0; y<height; y++)
- {
- memcpy(&(dst[1][y*dstStride[1]]), &(src[1][y*srcStride[1]]), width);
- memcpy(&(dst[2][y*dstStride[2]]), &(src[2][y*srcStride[2]]), width);
- }
- }
-}
-
diff --git a/src/libffmpeg/libavcodec/libpostproc/postprocess.h b/src/libffmpeg/libavcodec/libpostproc/postprocess.h
deleted file mode 100644
index 114c88a38..000000000
--- a/src/libffmpeg/libavcodec/libpostproc/postprocess.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- Copyright (C) 2001-2003 Michael Niedermayer (michaelni@gmx.at)
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-
-#ifndef NEWPOSTPROCESS_H
-#define NEWPOSTPROCESS_H
-
-/**
- * @file postprocess.h
- * @brief
- * external api for the pp stuff
- */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define LIBPOSTPROC_VERSION_INT ((51<<16)+(1<<8)+0)
-#define LIBPOSTPROC_VERSION 51.1.0
-#define LIBPOSTPROC_BUILD LIBPOSTPROC_VERSION_INT
-
-#define LIBPOSTPROC_IDENT "postproc" AV_STRINGIFY(LIBPOSTPROC_VERSION)
-
-#define PP_QUALITY_MAX 6
-
-#define QP_STORE_T int8_t
-
-typedef void pp_context_t;
-typedef void pp_mode_t;
-
-extern char *pp_help; ///< a simple help text
-
-void pp_postprocess(uint8_t * src[3], int srcStride[3],
- uint8_t * dst[3], int dstStride[3],
- int horizontalSize, int verticalSize,
- QP_STORE_T *QP_store, int QP_stride,
- pp_mode_t *mode, pp_context_t *ppContext, int pict_type);
-
-
-/**
- * returns a pp_mode_t or NULL if an error occured
- * name is the string after "-pp" on the command line
- * quality is a number from 0 to PP_QUALITY_MAX
- */
-pp_mode_t *pp_get_mode_by_name_and_quality(char *name, int quality);
-void pp_free_mode(pp_mode_t *mode);
-
-pp_context_t *pp_get_context(int width, int height, int flags);
-void pp_free_context(pp_context_t *ppContext);
-
-#define PP_CPU_CAPS_MMX 0x80000000
-#define PP_CPU_CAPS_MMX2 0x20000000
-#define PP_CPU_CAPS_3DNOW 0x40000000
-#define PP_CPU_CAPS_ALTIVEC 0x10000000
-
-#define PP_FORMAT 0x00000008
-#define PP_FORMAT_420 (0x00000011|PP_FORMAT)
-#define PP_FORMAT_422 (0x00000001|PP_FORMAT)
-#define PP_FORMAT_411 (0x00000002|PP_FORMAT)
-#define PP_FORMAT_444 (0x00000000|PP_FORMAT)
-
-#define PP_PICT_TYPE_QP2 0x00000010 ///< MPEG2 style QScale
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/libffmpeg/libavcodec/libpostproc/postprocess_altivec_template.c b/src/libffmpeg/libavcodec/libpostproc/postprocess_altivec_template.c
deleted file mode 100644
index 38adeb32d..000000000
--- a/src/libffmpeg/libavcodec/libpostproc/postprocess_altivec_template.c
+++ /dev/null
@@ -1,1196 +0,0 @@
-/*
- AltiVec optimizations (C) 2004 Romain Dolbeau <romain@dolbeau.org>
-
- based on code by Copyright (C) 2001-2003 Michael Niedermayer (michaelni@gmx.at)
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-
-
-#ifdef CONFIG_DARWIN
-#define AVV(x...) (x)
-#else
-#define AVV(x...) {x}
-#endif
-
-#define ALTIVEC_TRANSPOSE_8x8_SHORT(src_a,src_b,src_c,src_d,src_e,src_f,src_g,src_h) \
- do { \
- __typeof__(src_a) tempA1, tempB1, tempC1, tempD1; \
- __typeof__(src_a) tempE1, tempF1, tempG1, tempH1; \
- __typeof__(src_a) tempA2, tempB2, tempC2, tempD2; \
- __typeof__(src_a) tempE2, tempF2, tempG2, tempH2; \
- tempA1 = vec_mergeh (src_a, src_e); \
- tempB1 = vec_mergel (src_a, src_e); \
- tempC1 = vec_mergeh (src_b, src_f); \
- tempD1 = vec_mergel (src_b, src_f); \
- tempE1 = vec_mergeh (src_c, src_g); \
- tempF1 = vec_mergel (src_c, src_g); \
- tempG1 = vec_mergeh (src_d, src_h); \
- tempH1 = vec_mergel (src_d, src_h); \
- tempA2 = vec_mergeh (tempA1, tempE1); \
- tempB2 = vec_mergel (tempA1, tempE1); \
- tempC2 = vec_mergeh (tempB1, tempF1); \
- tempD2 = vec_mergel (tempB1, tempF1); \
- tempE2 = vec_mergeh (tempC1, tempG1); \
- tempF2 = vec_mergel (tempC1, tempG1); \
- tempG2 = vec_mergeh (tempD1, tempH1); \
- tempH2 = vec_mergel (tempD1, tempH1); \
- src_a = vec_mergeh (tempA2, tempE2); \
- src_b = vec_mergel (tempA2, tempE2); \
- src_c = vec_mergeh (tempB2, tempF2); \
- src_d = vec_mergel (tempB2, tempF2); \
- src_e = vec_mergeh (tempC2, tempG2); \
- src_f = vec_mergel (tempC2, tempG2); \
- src_g = vec_mergeh (tempD2, tempH2); \
- src_h = vec_mergel (tempD2, tempH2); \
- } while (0)
-
-
-static inline int vertClassify_altivec(uint8_t src[], int stride, PPContext *c) {
- /*
- this code makes no assumption on src or stride.
- One could remove the recomputation of the perm
- vector by assuming (stride % 16) == 0, unfortunately
- this is not always true.
- */
- register int y;
- short __attribute__ ((aligned(16))) data[8];
- int numEq;
- uint8_t *src2 = src;
- vector signed short v_dcOffset;
- vector signed short v2QP;
- vector unsigned short v4QP;
- vector unsigned short v_dcThreshold;
- const int properStride = (stride % 16);
- const int srcAlign = ((unsigned long)src2 % 16);
- const int two_vectors = ((srcAlign > 8) || properStride) ? 1 : 0;
- const vector signed int zero = vec_splat_s32(0);
- const vector signed short mask = vec_splat_s16(1);
- vector signed int v_numEq = vec_splat_s32(0);
-
- data[0] = ((c->nonBQP*c->ppMode.baseDcDiff)>>8) + 1;
- data[1] = data[0] * 2 + 1;
- data[2] = c->QP * 2;
- data[3] = c->QP * 4;
- vector signed short v_data = vec_ld(0, data);
- v_dcOffset = vec_splat(v_data, 0);
- v_dcThreshold = (vector unsigned short)vec_splat(v_data, 1);
- v2QP = vec_splat(v_data, 2);
- v4QP = (vector unsigned short)vec_splat(v_data, 3);
-
- src2 += stride * 4;
-
- vector signed short v_srcAss0, v_srcAss1, v_srcAss2, v_srcAss3, v_srcAss4, v_srcAss5, v_srcAss6, v_srcAss7;
-
-#define LOAD_LINE(i) \
- register int j##i = i * stride; \
- vector unsigned char perm##i = vec_lvsl(j##i, src2); \
- const vector unsigned char v_srcA1##i = vec_ld(j##i, src2); \
- vector unsigned char v_srcA2##i; \
- if (two_vectors) \
- v_srcA2##i = vec_ld(j##i + 16, src2); \
- const vector unsigned char v_srcA##i = \
- vec_perm(v_srcA1##i, v_srcA2##i, perm##i); \
- v_srcAss##i = \
- (vector signed short)vec_mergeh((vector signed char)zero, \
- (vector signed char)v_srcA##i)
-
-#define LOAD_LINE_ALIGNED(i) \
- register int j##i = i * stride; \
- const vector unsigned char v_srcA##i = vec_ld(j##i, src2); \
- v_srcAss##i = \
- (vector signed short)vec_mergeh((vector signed char)zero, \
- (vector signed char)v_srcA##i)
-
- // special casing the aligned case is worthwhile, as all call from
- // the (transposed) horizontable deblocks will be aligned, i naddition
- // to the naturraly aligned vertical deblocks.
- if (properStride && srcAlign) {
- LOAD_LINE_ALIGNED(0);
- LOAD_LINE_ALIGNED(1);
- LOAD_LINE_ALIGNED(2);
- LOAD_LINE_ALIGNED(3);
- LOAD_LINE_ALIGNED(4);
- LOAD_LINE_ALIGNED(5);
- LOAD_LINE_ALIGNED(6);
- LOAD_LINE_ALIGNED(7);
- } else {
- LOAD_LINE(0);
- LOAD_LINE(1);
- LOAD_LINE(2);
- LOAD_LINE(3);
- LOAD_LINE(4);
- LOAD_LINE(5);
- LOAD_LINE(6);
- LOAD_LINE(7);
- }
-#undef LOAD_LINE
-#undef LOAD_LINE_ALIGNED
-
-#define ITER(i, j) \
- const vector signed short v_diff##i = \
- vec_sub(v_srcAss##i, v_srcAss##j); \
- const vector signed short v_sum##i = \
- vec_add(v_diff##i, v_dcOffset); \
- const vector signed short v_comp##i = \
- (vector signed short)vec_cmplt((vector unsigned short)v_sum##i, \
- v_dcThreshold); \
- const vector signed short v_part##i = vec_and(mask, v_comp##i); \
- v_numEq = vec_sum4s(v_part##i, v_numEq);
-
- ITER(0, 1);
- ITER(1, 2);
- ITER(2, 3);
- ITER(3, 4);
- ITER(4, 5);
- ITER(5, 6);
- ITER(6, 7);
-#undef ITER
-
- v_numEq = vec_sums(v_numEq, zero);
-
- v_numEq = vec_splat(v_numEq, 3);
- vec_ste(v_numEq, 0, &numEq);
-
- if (numEq > c->ppMode.flatnessThreshold)
- {
- const vector unsigned char mmoP1 = (const vector unsigned char)
- AVV(0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f,
- 0x00, 0x01, 0x12, 0x13, 0x08, 0x09, 0x1A, 0x1B);
- const vector unsigned char mmoP2 = (const vector unsigned char)
- AVV(0x04, 0x05, 0x16, 0x17, 0x0C, 0x0D, 0x1E, 0x1F,
- 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f);
- const vector unsigned char mmoP = (const vector unsigned char)
- vec_lvsl(8, (unsigned char*)0);
-
- vector signed short mmoL1 = vec_perm(v_srcAss0, v_srcAss2, mmoP1);
- vector signed short mmoL2 = vec_perm(v_srcAss4, v_srcAss6, mmoP2);
- vector signed short mmoL = vec_perm(mmoL1, mmoL2, mmoP);
- vector signed short mmoR1 = vec_perm(v_srcAss5, v_srcAss7, mmoP1);
- vector signed short mmoR2 = vec_perm(v_srcAss1, v_srcAss3, mmoP2);
- vector signed short mmoR = vec_perm(mmoR1, mmoR2, mmoP);
- vector signed short mmoDiff = vec_sub(mmoL, mmoR);
- vector unsigned short mmoSum = (vector unsigned short)vec_add(mmoDiff, v2QP);
-
- if (vec_any_gt(mmoSum, v4QP))
- return 0;
- else
- return 1;
- }
- else return 2;
-}
-
-static inline void doVertLowPass_altivec(uint8_t *src, int stride, PPContext *c) {
- /*
- this code makes no assumption on src or stride.
- One could remove the recomputation of the perm
- vector by assuming (stride % 16) == 0, unfortunately
- this is not always true. Quite a lot of load/stores
- can be removed by assuming proper alignement of
- src & stride :-(
- */
- uint8_t *src2 = src;
- const vector signed int zero = vec_splat_s32(0);
- const int properStride = (stride % 16);
- const int srcAlign = ((unsigned long)src2 % 16);
- short __attribute__ ((aligned(16))) qp[8];
- qp[0] = c->QP;
- vector signed short vqp = vec_ld(0, qp);
- vqp = vec_splat(vqp, 0);
-
- src2 += stride*3;
-
- vector signed short vb0, vb1, vb2, vb3, vb4, vb5, vb6, vb7, vb8, vb9;
- vector unsigned char vbA0, vbA1, vbA2, vbA3, vbA4, vbA5, vbA6, vbA7, vbA8, vbA9;
- vector unsigned char vbB0, vbB1, vbB2, vbB3, vbB4, vbB5, vbB6, vbB7, vbB8, vbB9;
- vector unsigned char vbT0, vbT1, vbT2, vbT3, vbT4, vbT5, vbT6, vbT7, vbT8, vbT9;
-
-#define LOAD_LINE(i) \
- const vector unsigned char perml##i = \
- vec_lvsl(i * stride, src2); \
- vbA##i = vec_ld(i * stride, src2); \
- vbB##i = vec_ld(i * stride + 16, src2); \
- vbT##i = vec_perm(vbA##i, vbB##i, perml##i); \
- vb##i = \
- (vector signed short)vec_mergeh((vector unsigned char)zero, \
- (vector unsigned char)vbT##i)
-
-#define LOAD_LINE_ALIGNED(i) \
- register int j##i = i * stride; \
- vbT##i = vec_ld(j##i, src2); \
- vb##i = \
- (vector signed short)vec_mergeh((vector signed char)zero, \
- (vector signed char)vbT##i)
-
- // special casing the aligned case is worthwhile, as all call from
- // the (transposed) horizontable deblocks will be aligned, in addition
- // to the naturraly aligned vertical deblocks.
- if (properStride && srcAlign) {
- LOAD_LINE_ALIGNED(0);
- LOAD_LINE_ALIGNED(1);
- LOAD_LINE_ALIGNED(2);
- LOAD_LINE_ALIGNED(3);
- LOAD_LINE_ALIGNED(4);
- LOAD_LINE_ALIGNED(5);
- LOAD_LINE_ALIGNED(6);
- LOAD_LINE_ALIGNED(7);
- LOAD_LINE_ALIGNED(8);
- LOAD_LINE_ALIGNED(9);
- } else {
- LOAD_LINE(0);
- LOAD_LINE(1);
- LOAD_LINE(2);
- LOAD_LINE(3);
- LOAD_LINE(4);
- LOAD_LINE(5);
- LOAD_LINE(6);
- LOAD_LINE(7);
- LOAD_LINE(8);
- LOAD_LINE(9);
- }
-#undef LOAD_LINE
-#undef LOAD_LINE_ALIGNED
-
- const vector unsigned short v_1 = vec_splat_u16(1);
- const vector unsigned short v_2 = vec_splat_u16(2);
- const vector unsigned short v_4 = vec_splat_u16(4);
-
- const vector signed short v_diff01 = vec_sub(vb0, vb1);
- const vector unsigned short v_cmp01 =
- (const vector unsigned short) vec_cmplt(vec_abs(v_diff01), vqp);
- const vector signed short v_first = vec_sel(vb1, vb0, v_cmp01);
- const vector signed short v_diff89 = vec_sub(vb8, vb9);
- const vector unsigned short v_cmp89 =
- (const vector unsigned short) vec_cmplt(vec_abs(v_diff89), vqp);
- const vector signed short v_last = vec_sel(vb8, vb9, v_cmp89);
-
- const vector signed short temp01 = vec_mladd(v_first, (vector signed short)v_4, vb1);
- const vector signed short temp02 = vec_add(vb2, vb3);
- const vector signed short temp03 = vec_add(temp01, (vector signed short)v_4);
- const vector signed short v_sumsB0 = vec_add(temp02, temp03);
-
- const vector signed short temp11 = vec_sub(v_sumsB0, v_first);
- const vector signed short v_sumsB1 = vec_add(temp11, vb4);
-
- const vector signed short temp21 = vec_sub(v_sumsB1, v_first);
- const vector signed short v_sumsB2 = vec_add(temp21, vb5);
-
- const vector signed short temp31 = vec_sub(v_sumsB2, v_first);
- const vector signed short v_sumsB3 = vec_add(temp31, vb6);
-
- const vector signed short temp41 = vec_sub(v_sumsB3, v_first);
- const vector signed short v_sumsB4 = vec_add(temp41, vb7);
-
- const vector signed short temp51 = vec_sub(v_sumsB4, vb1);
- const vector signed short v_sumsB5 = vec_add(temp51, vb8);
-
- const vector signed short temp61 = vec_sub(v_sumsB5, vb2);
- const vector signed short v_sumsB6 = vec_add(temp61, v_last);
-
- const vector signed short temp71 = vec_sub(v_sumsB6, vb3);
- const vector signed short v_sumsB7 = vec_add(temp71, v_last);
-
- const vector signed short temp81 = vec_sub(v_sumsB7, vb4);
- const vector signed short v_sumsB8 = vec_add(temp81, v_last);
-
- const vector signed short temp91 = vec_sub(v_sumsB8, vb5);
- const vector signed short v_sumsB9 = vec_add(temp91, v_last);
-
-#define COMPUTE_VR(i, j, k) \
- const vector signed short temps1##i = \
- vec_add(v_sumsB##i, v_sumsB##k); \
- const vector signed short temps2##i = \
- vec_mladd(vb##j, (vector signed short)v_2, temps1##i); \
- const vector signed short vr##j = vec_sra(temps2##i, v_4)
-
- COMPUTE_VR(0, 1, 2);
- COMPUTE_VR(1, 2, 3);
- COMPUTE_VR(2, 3, 4);
- COMPUTE_VR(3, 4, 5);
- COMPUTE_VR(4, 5, 6);
- COMPUTE_VR(5, 6, 7);
- COMPUTE_VR(6, 7, 8);
- COMPUTE_VR(7, 8, 9);
-
- const vector signed char neg1 = vec_splat_s8(-1);
- const vector unsigned char permHH = (const vector unsigned char)AVV(0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F);
-
-#define PACK_AND_STORE(i) \
- const vector unsigned char perms##i = \
- vec_lvsr(i * stride, src2); \
- const vector unsigned char vf##i = \
- vec_packsu(vr##i, (vector signed short)zero); \
- const vector unsigned char vg##i = \
- vec_perm(vf##i, vbT##i, permHH); \
- const vector unsigned char mask##i = \
- vec_perm((vector unsigned char)zero, (vector unsigned char)neg1, perms##i); \
- const vector unsigned char vg2##i = \
- vec_perm(vg##i, vg##i, perms##i); \
- const vector unsigned char svA##i = \
- vec_sel(vbA##i, vg2##i, mask##i); \
- const vector unsigned char svB##i = \
- vec_sel(vg2##i, vbB##i, mask##i); \
- vec_st(svA##i, i * stride, src2); \
- vec_st(svB##i, i * stride + 16, src2)
-
-#define PACK_AND_STORE_ALIGNED(i) \
- const vector unsigned char vf##i = \
- vec_packsu(vr##i, (vector signed short)zero); \
- const vector unsigned char vg##i = \
- vec_perm(vf##i, vbT##i, permHH); \
- vec_st(vg##i, i * stride, src2)
-
- // special casing the aligned case is worthwhile, as all call from
- // the (transposed) horizontable deblocks will be aligned, in addition
- // to the naturraly aligned vertical deblocks.
- if (properStride && srcAlign) {
- PACK_AND_STORE_ALIGNED(1);
- PACK_AND_STORE_ALIGNED(2);
- PACK_AND_STORE_ALIGNED(3);
- PACK_AND_STORE_ALIGNED(4);
- PACK_AND_STORE_ALIGNED(5);
- PACK_AND_STORE_ALIGNED(6);
- PACK_AND_STORE_ALIGNED(7);
- PACK_AND_STORE_ALIGNED(8);
- } else {
- PACK_AND_STORE(1);
- PACK_AND_STORE(2);
- PACK_AND_STORE(3);
- PACK_AND_STORE(4);
- PACK_AND_STORE(5);
- PACK_AND_STORE(6);
- PACK_AND_STORE(7);
- PACK_AND_STORE(8);
- }
-#undef PACK_AND_STORE
-#undef PACK_AND_STORE_ALIGNED
-}
-
-
-
-static inline void doVertDefFilter_altivec(uint8_t src[], int stride, PPContext *c) {
- /*
- this code makes no assumption on src or stride.
- One could remove the recomputation of the perm
- vector by assuming (stride % 16) == 0, unfortunately
- this is not always true. Quite a lot of load/stores
- can be removed by assuming proper alignement of
- src & stride :-(
- */
- uint8_t *src2 = src;
- const vector signed int zero = vec_splat_s32(0);
- short __attribute__ ((aligned(16))) qp[8];
- qp[0] = 8*c->QP;
- vector signed short vqp = vec_ld(0, qp);
- vqp = vec_splat(vqp, 0);
-
-#define LOAD_LINE(i) \
- const vector unsigned char perm##i = \
- vec_lvsl(i * stride, src2); \
- const vector unsigned char vbA##i = \
- vec_ld(i * stride, src2); \
- const vector unsigned char vbB##i = \
- vec_ld(i * stride + 16, src2); \
- const vector unsigned char vbT##i = \
- vec_perm(vbA##i, vbB##i, perm##i); \
- const vector signed short vb##i = \
- (vector signed short)vec_mergeh((vector unsigned char)zero, \
- (vector unsigned char)vbT##i)
-
- src2 += stride*3;
-
- LOAD_LINE(1);
- LOAD_LINE(2);
- LOAD_LINE(3);
- LOAD_LINE(4);
- LOAD_LINE(5);
- LOAD_LINE(6);
- LOAD_LINE(7);
- LOAD_LINE(8);
-#undef LOAD_LINE
-
- const vector signed short v_1 = vec_splat_s16(1);
- const vector signed short v_2 = vec_splat_s16(2);
- const vector signed short v_5 = vec_splat_s16(5);
- const vector signed short v_32 = vec_sl(v_1,
- (vector unsigned short)v_5);
- /* middle energy */
- const vector signed short l3minusl6 = vec_sub(vb3, vb6);
- const vector signed short l5minusl4 = vec_sub(vb5, vb4);
- const vector signed short twotimes_l3minusl6 = vec_mladd(v_2, l3minusl6, (vector signed short)zero);
- const vector signed short mE = vec_mladd(v_5, l5minusl4, twotimes_l3minusl6);
- const vector signed short absmE = vec_abs(mE);
- /* left & right energy */
- const vector signed short l1minusl4 = vec_sub(vb1, vb4);
- const vector signed short l3minusl2 = vec_sub(vb3, vb2);
- const vector signed short l5minusl8 = vec_sub(vb5, vb8);
- const vector signed short l7minusl6 = vec_sub(vb7, vb6);
- const vector signed short twotimes_l1minusl4 = vec_mladd(v_2, l1minusl4, (vector signed short)zero);
- const vector signed short twotimes_l5minusl8 = vec_mladd(v_2, l5minusl8, (vector signed short)zero);
- const vector signed short lE = vec_mladd(v_5, l3minusl2, twotimes_l1minusl4);
- const vector signed short rE = vec_mladd(v_5, l7minusl6, twotimes_l5minusl8);
- /* d */
- const vector signed short ddiff = vec_sub(absmE,
- vec_min(vec_abs(lE),
- vec_abs(rE)));
- const vector signed short ddiffclamp = vec_max(ddiff, (vector signed short)zero);
- const vector signed short dtimes64 = vec_mladd(v_5, ddiffclamp, v_32);
- const vector signed short d = vec_sra(dtimes64, vec_splat_u16(6));
- const vector signed short minusd = vec_sub((vector signed short)zero, d);
- const vector signed short finald = vec_sel(minusd,
- d,
- vec_cmpgt(vec_sub((vector signed short)zero, mE),
- (vector signed short)zero));
- /* q */
- const vector signed short qtimes2 = vec_sub(vb4, vb5);
- /* for a shift right to behave like /2, we need to add one
- to all negative integer */
- const vector signed short rounddown = vec_sel((vector signed short)zero,
- v_1,
- vec_cmplt(qtimes2, (vector signed short)zero));
- const vector signed short q = vec_sra(vec_add(qtimes2, rounddown), vec_splat_u16(1));
- /* clamp */
- const vector signed short dclamp_P1 = vec_max((vector signed short)zero, finald);
- const vector signed short dclamp_P = vec_min(dclamp_P1, q);
- const vector signed short dclamp_N1 = vec_min((vector signed short)zero, finald);
- const vector signed short dclamp_N = vec_max(dclamp_N1, q);
-
- const vector signed short dclampedfinal = vec_sel(dclamp_N,
- dclamp_P,
- vec_cmpgt(q, (vector signed short)zero));
- const vector signed short dornotd = vec_sel((vector signed short)zero,
- dclampedfinal,
- vec_cmplt(absmE, vqp));
- /* add/substract to l4 and l5 */
- const vector signed short vb4minusd = vec_sub(vb4, dornotd);
- const vector signed short vb5plusd = vec_add(vb5, dornotd);
- /* finally, stores */
- const vector unsigned char st4 = vec_packsu(vb4minusd, (vector signed short)zero);
- const vector unsigned char st5 = vec_packsu(vb5plusd, (vector signed short)zero);
-
- const vector signed char neg1 = vec_splat_s8(-1);
- const vector unsigned char permHH = (const vector unsigned char)AVV(0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F);
-
-#define STORE(i) \
- const vector unsigned char perms##i = \
- vec_lvsr(i * stride, src2); \
- const vector unsigned char vg##i = \
- vec_perm(st##i, vbT##i, permHH); \
- const vector unsigned char mask##i = \
- vec_perm((vector unsigned char)zero, (vector unsigned char)neg1, perms##i); \
- const vector unsigned char vg2##i = \
- vec_perm(vg##i, vg##i, perms##i); \
- const vector unsigned char svA##i = \
- vec_sel(vbA##i, vg2##i, mask##i); \
- const vector unsigned char svB##i = \
- vec_sel(vg2##i, vbB##i, mask##i); \
- vec_st(svA##i, i * stride, src2); \
- vec_st(svB##i, i * stride + 16, src2)
-
- STORE(4);
- STORE(5);
-}
-
-static inline void dering_altivec(uint8_t src[], int stride, PPContext *c) {
- /*
- this code makes no assumption on src or stride.
- One could remove the recomputation of the perm
- vector by assuming (stride % 16) == 0, unfortunately
- this is not always true. Quite a lot of load/stores
- can be removed by assuming proper alignement of
- src & stride :-(
- */
- uint8_t *srcCopy = src;
- uint8_t __attribute__((aligned(16))) dt[16];
- const vector unsigned char vuint8_1 = vec_splat_u8(1);
- const vector signed int zero = vec_splat_s32(0);
- vector unsigned char v_dt;
- dt[0] = deringThreshold;
- v_dt = vec_splat(vec_ld(0, dt), 0);
-
-#define LOAD_LINE(i) \
- const vector unsigned char perm##i = \
- vec_lvsl(i * stride, srcCopy); \
- vector unsigned char sA##i = vec_ld(i * stride, srcCopy); \
- vector unsigned char sB##i = vec_ld(i * stride + 16, srcCopy); \
- vector unsigned char src##i = vec_perm(sA##i, sB##i, perm##i)
-
- LOAD_LINE(0);
- LOAD_LINE(1);
- LOAD_LINE(2);
- LOAD_LINE(3);
- LOAD_LINE(4);
- LOAD_LINE(5);
- LOAD_LINE(6);
- LOAD_LINE(7);
- LOAD_LINE(8);
- LOAD_LINE(9);
-#undef LOAD_LINE
-
- vector unsigned char v_avg;
- {
- const vector unsigned char trunc_perm = (vector unsigned char)
- AVV(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
- 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18);
- const vector unsigned char trunc_src12 = vec_perm(src1, src2, trunc_perm);
- const vector unsigned char trunc_src34 = vec_perm(src3, src4, trunc_perm);
- const vector unsigned char trunc_src56 = vec_perm(src5, src6, trunc_perm);
- const vector unsigned char trunc_src78 = vec_perm(src7, src8, trunc_perm);
-
-#define EXTRACT(op) do { \
- const vector unsigned char s##op##_1 = vec_##op(trunc_src12, trunc_src34); \
- const vector unsigned char s##op##_2 = vec_##op(trunc_src56, trunc_src78); \
- const vector unsigned char s##op##_6 = vec_##op(s##op##_1, s##op##_2); \
- const vector unsigned char s##op##_8h = vec_mergeh(s##op##_6, s##op##_6); \
- const vector unsigned char s##op##_8l = vec_mergel(s##op##_6, s##op##_6); \
- const vector unsigned char s##op##_9 = vec_##op(s##op##_8h, s##op##_8l); \
- const vector unsigned char s##op##_9h = vec_mergeh(s##op##_9, s##op##_9); \
- const vector unsigned char s##op##_9l = vec_mergel(s##op##_9, s##op##_9); \
- const vector unsigned char s##op##_10 = vec_##op(s##op##_9h, s##op##_9l); \
- const vector unsigned char s##op##_10h = vec_mergeh(s##op##_10, s##op##_10); \
- const vector unsigned char s##op##_10l = vec_mergel(s##op##_10, s##op##_10); \
- const vector unsigned char s##op##_11 = vec_##op(s##op##_10h, s##op##_10l); \
- const vector unsigned char s##op##_11h = vec_mergeh(s##op##_11, s##op##_11); \
- const vector unsigned char s##op##_11l = vec_mergel(s##op##_11, s##op##_11); \
- v_##op = vec_##op(s##op##_11h, s##op##_11l); } while (0)
-
- vector unsigned char v_min;
- vector unsigned char v_max;
- EXTRACT(min);
- EXTRACT(max);
-#undef EXTRACT
-
- if (vec_all_lt(vec_sub(v_max, v_min), v_dt))
- return;
-
- v_avg = vec_avg(v_min, v_max);
- }
-
- signed int __attribute__((aligned(16))) S[8];
- {
- const vector unsigned short mask1 = (vector unsigned short)
- AVV(0x0001, 0x0002, 0x0004, 0x0008,
- 0x0010, 0x0020, 0x0040, 0x0080);
- const vector unsigned short mask2 = (vector unsigned short)
- AVV(0x0100, 0x0200, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000);
-
- const vector unsigned int vuint32_16 = vec_sl(vec_splat_u32(1), vec_splat_u32(4));
- const vector unsigned int vuint32_1 = vec_splat_u32(1);
-
-#define COMPARE(i) \
- vector signed int sum##i; \
- do { \
- const vector unsigned char cmp##i = \
- (vector unsigned char)vec_cmpgt(src##i, v_avg); \
- const vector unsigned short cmpHi##i = \
- (vector unsigned short)vec_mergeh(cmp##i, cmp##i); \
- const vector unsigned short cmpLi##i = \
- (vector unsigned short)vec_mergel(cmp##i, cmp##i); \
- const vector signed short cmpHf##i = \
- (vector signed short)vec_and(cmpHi##i, mask1); \
- const vector signed short cmpLf##i = \
- (vector signed short)vec_and(cmpLi##i, mask2); \
- const vector signed int sump##i = vec_sum4s(cmpHf##i, zero); \
- const vector signed int sumq##i = vec_sum4s(cmpLf##i, sump##i); \
- sum##i = vec_sums(sumq##i, zero); } while (0)
-
- COMPARE(0);
- COMPARE(1);
- COMPARE(2);
- COMPARE(3);
- COMPARE(4);
- COMPARE(5);
- COMPARE(6);
- COMPARE(7);
- COMPARE(8);
- COMPARE(9);
-#undef COMPARE
-
- vector signed int sumA2;
- vector signed int sumB2;
- {
- const vector signed int sump02 = vec_mergel(sum0, sum2);
- const vector signed int sump13 = vec_mergel(sum1, sum3);
- const vector signed int sumA = vec_mergel(sump02, sump13);
-
- const vector signed int sump46 = vec_mergel(sum4, sum6);
- const vector signed int sump57 = vec_mergel(sum5, sum7);
- const vector signed int sumB = vec_mergel(sump46, sump57);
-
- const vector signed int sump8A = vec_mergel(sum8, zero);
- const vector signed int sump9B = vec_mergel(sum9, zero);
- const vector signed int sumC = vec_mergel(sump8A, sump9B);
-
- const vector signed int tA = vec_sl(vec_nor(zero, sumA), vuint32_16);
- const vector signed int tB = vec_sl(vec_nor(zero, sumB), vuint32_16);
- const vector signed int tC = vec_sl(vec_nor(zero, sumC), vuint32_16);
- const vector signed int t2A = vec_or(sumA, tA);
- const vector signed int t2B = vec_or(sumB, tB);
- const vector signed int t2C = vec_or(sumC, tC);
- const vector signed int t3A = vec_and(vec_sra(t2A, vuint32_1),
- vec_sl(t2A, vuint32_1));
- const vector signed int t3B = vec_and(vec_sra(t2B, vuint32_1),
- vec_sl(t2B, vuint32_1));
- const vector signed int t3C = vec_and(vec_sra(t2C, vuint32_1),
- vec_sl(t2C, vuint32_1));
- const vector signed int yA = vec_and(t2A, t3A);
- const vector signed int yB = vec_and(t2B, t3B);
- const vector signed int yC = vec_and(t2C, t3C);
-
- const vector unsigned char strangeperm1 = vec_lvsl(4, (unsigned char*)0);
- const vector unsigned char strangeperm2 = vec_lvsl(8, (unsigned char*)0);
- const vector signed int sumAd4 = vec_perm(yA, yB, strangeperm1);
- const vector signed int sumAd8 = vec_perm(yA, yB, strangeperm2);
- const vector signed int sumBd4 = vec_perm(yB, yC, strangeperm1);
- const vector signed int sumBd8 = vec_perm(yB, yC, strangeperm2);
- const vector signed int sumAp = vec_and(yA,
- vec_and(sumAd4,sumAd8));
- const vector signed int sumBp = vec_and(yB,
- vec_and(sumBd4,sumBd8));
- sumA2 = vec_or(sumAp,
- vec_sra(sumAp,
- vuint32_16));
- sumB2 = vec_or(sumBp,
- vec_sra(sumBp,
- vuint32_16));
- }
- vec_st(sumA2, 0, S);
- vec_st(sumB2, 16, S);
- }
-
- /* I'm not sure the following is actually faster
- than straight, unvectorized C code :-( */
-
- int __attribute__((aligned(16))) tQP2[4];
- tQP2[0]= c->QP/2 + 1;
- vector signed int vQP2 = vec_ld(0, tQP2);
- vQP2 = vec_splat(vQP2, 0);
- const vector unsigned char vuint8_2 = vec_splat_u8(2);
- const vector signed int vsint32_8 = vec_splat_s32(8);
- const vector unsigned int vuint32_4 = vec_splat_u32(4);
-
- const vector unsigned char permA1 = (vector unsigned char)
- AVV(0x00, 0x01, 0x02, 0x10, 0x11, 0x12, 0x1F, 0x1F,
- 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F);
- const vector unsigned char permA2 = (vector unsigned char)
- AVV(0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x10, 0x11,
- 0x12, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F);
- const vector unsigned char permA1inc = (vector unsigned char)
- AVV(0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
- const vector unsigned char permA2inc = (vector unsigned char)
- AVV(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
- 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
- const vector unsigned char magic = (vector unsigned char)
- AVV(0x01, 0x02, 0x01, 0x02, 0x04, 0x02, 0x01, 0x02,
- 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
- const vector unsigned char extractPerm = (vector unsigned char)
- AVV(0x10, 0x10, 0x10, 0x01, 0x10, 0x10, 0x10, 0x01,
- 0x10, 0x10, 0x10, 0x01, 0x10, 0x10, 0x10, 0x01);
- const vector unsigned char extractPermInc = (vector unsigned char)
- AVV(0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
- 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01);
- const vector unsigned char identity = vec_lvsl(0,(unsigned char *)0);
- const vector unsigned char tenRight = (vector unsigned char)
- AVV(0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
- const vector unsigned char eightLeft = (vector unsigned char)
- AVV(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08);
-
-
-#define F_INIT(i) \
- vector unsigned char tenRightM##i = tenRight; \
- vector unsigned char permA1M##i = permA1; \
- vector unsigned char permA2M##i = permA2; \
- vector unsigned char extractPermM##i = extractPerm
-
-#define F2(i, j, k, l) \
- if (S[i] & (1 << (l+1))) { \
- const vector unsigned char a_##j##_A##l = \
- vec_perm(src##i, src##j, permA1M##i); \
- const vector unsigned char a_##j##_B##l = \
- vec_perm(a_##j##_A##l, src##k, permA2M##i); \
- const vector signed int a_##j##_sump##l = \
- (vector signed int)vec_msum(a_##j##_B##l, magic, \
- (vector unsigned int)zero); \
- vector signed int F_##j##_##l = \
- vec_sr(vec_sums(a_##j##_sump##l, vsint32_8), vuint32_4); \
- F_##j##_##l = vec_splat(F_##j##_##l, 3); \
- const vector signed int p_##j##_##l = \
- (vector signed int)vec_perm(src##j, \
- (vector unsigned char)zero, \
- extractPermM##i); \
- const vector signed int sum_##j##_##l = vec_add( p_##j##_##l, vQP2);\
- const vector signed int diff_##j##_##l = vec_sub( p_##j##_##l, vQP2);\
- vector signed int newpm_##j##_##l; \
- if (vec_all_lt(sum_##j##_##l, F_##j##_##l)) \
- newpm_##j##_##l = sum_##j##_##l; \
- else if (vec_all_gt(diff_##j##_##l, F_##j##_##l)) \
- newpm_##j##_##l = diff_##j##_##l; \
- else newpm_##j##_##l = F_##j##_##l; \
- const vector unsigned char newpm2_##j##_##l = \
- vec_splat((vector unsigned char)newpm_##j##_##l, 15); \
- const vector unsigned char mask##j##l = vec_add(identity, \
- tenRightM##i); \
- src##j = vec_perm(src##j, newpm2_##j##_##l, mask##j##l); \
- } \
- permA1M##i = vec_add(permA1M##i, permA1inc); \
- permA2M##i = vec_add(permA2M##i, permA2inc); \
- tenRightM##i = vec_sro(tenRightM##i, eightLeft); \
- extractPermM##i = vec_add(extractPermM##i, extractPermInc)
-
-#define ITER(i, j, k) \
- F_INIT(i); \
- F2(i, j, k, 0); \
- F2(i, j, k, 1); \
- F2(i, j, k, 2); \
- F2(i, j, k, 3); \
- F2(i, j, k, 4); \
- F2(i, j, k, 5); \
- F2(i, j, k, 6); \
- F2(i, j, k, 7)
-
- ITER(0, 1, 2);
- ITER(1, 2, 3);
- ITER(2, 3, 4);
- ITER(3, 4, 5);
- ITER(4, 5, 6);
- ITER(5, 6, 7);
- ITER(6, 7, 8);
- ITER(7, 8, 9);
-
- const vector signed char neg1 = vec_splat_s8(-1);
-
-#define STORE_LINE(i) \
- const vector unsigned char permST##i = \
- vec_lvsr(i * stride, srcCopy); \
- const vector unsigned char maskST##i = \
- vec_perm((vector unsigned char)zero, \
- (vector unsigned char)neg1, permST##i); \
- src##i = vec_perm(src##i ,src##i, permST##i); \
- sA##i= vec_sel(sA##i, src##i, maskST##i); \
- sB##i= vec_sel(src##i, sB##i, maskST##i); \
- vec_st(sA##i, i * stride, srcCopy); \
- vec_st(sB##i, i * stride + 16, srcCopy)
-
- STORE_LINE(1);
- STORE_LINE(2);
- STORE_LINE(3);
- STORE_LINE(4);
- STORE_LINE(5);
- STORE_LINE(6);
- STORE_LINE(7);
- STORE_LINE(8);
-
-#undef STORE_LINE
-#undef ITER
-#undef F2
-}
-
-#define doHorizLowPass_altivec(a...) doHorizLowPass_C(a)
-#define doHorizDefFilter_altivec(a...) doHorizDefFilter_C(a)
-#define do_a_deblock_altivec(a...) do_a_deblock_C(a)
-
-static inline void RENAME(tempNoiseReducer)(uint8_t *src, int stride,
- uint8_t *tempBlured, uint32_t *tempBluredPast, int *maxNoise)
-{
- const vector signed int zero = vec_splat_s32(0);
- const vector signed short vsint16_1 = vec_splat_s16(1);
- vector signed int v_dp = zero;
- vector signed int v_sysdp = zero;
- int d, sysd, i;
-
- tempBluredPast[127]= maxNoise[0];
- tempBluredPast[128]= maxNoise[1];
- tempBluredPast[129]= maxNoise[2];
-
-#define LOAD_LINE(src, i) \
- register int j##src##i = i * stride; \
- vector unsigned char perm##src##i = vec_lvsl(j##src##i, src); \
- const vector unsigned char v_##src##A1##i = vec_ld(j##src##i, src); \
- const vector unsigned char v_##src##A2##i = vec_ld(j##src##i + 16, src); \
- const vector unsigned char v_##src##A##i = \
- vec_perm(v_##src##A1##i, v_##src##A2##i, perm##src##i); \
- vector signed short v_##src##Ass##i = \
- (vector signed short)vec_mergeh((vector signed char)zero, \
- (vector signed char)v_##src##A##i)
-
- LOAD_LINE(src, 0);
- LOAD_LINE(src, 1);
- LOAD_LINE(src, 2);
- LOAD_LINE(src, 3);
- LOAD_LINE(src, 4);
- LOAD_LINE(src, 5);
- LOAD_LINE(src, 6);
- LOAD_LINE(src, 7);
-
- LOAD_LINE(tempBlured, 0);
- LOAD_LINE(tempBlured, 1);
- LOAD_LINE(tempBlured, 2);
- LOAD_LINE(tempBlured, 3);
- LOAD_LINE(tempBlured, 4);
- LOAD_LINE(tempBlured, 5);
- LOAD_LINE(tempBlured, 6);
- LOAD_LINE(tempBlured, 7);
-#undef LOAD_LINE
-
-#define ACCUMULATE_DIFFS(i) \
- vector signed short v_d##i = vec_sub(v_tempBluredAss##i, \
- v_srcAss##i); \
- v_dp = vec_msums(v_d##i, v_d##i, v_dp); \
- v_sysdp = vec_msums(v_d##i, vsint16_1, v_sysdp)
-
- ACCUMULATE_DIFFS(0);
- ACCUMULATE_DIFFS(1);
- ACCUMULATE_DIFFS(2);
- ACCUMULATE_DIFFS(3);
- ACCUMULATE_DIFFS(4);
- ACCUMULATE_DIFFS(5);
- ACCUMULATE_DIFFS(6);
- ACCUMULATE_DIFFS(7);
-#undef ACCUMULATE_DIFFS
-
- v_dp = vec_sums(v_dp, zero);
- v_sysdp = vec_sums(v_sysdp, zero);
-
- v_dp = vec_splat(v_dp, 3);
- v_sysdp = vec_splat(v_sysdp, 3);
-
- vec_ste(v_dp, 0, &d);
- vec_ste(v_sysdp, 0, &sysd);
-
- i = d;
- d = (4*d
- +(*(tempBluredPast-256))
- +(*(tempBluredPast-1))+ (*(tempBluredPast+1))
- +(*(tempBluredPast+256))
- +4)>>3;
-
- *tempBluredPast=i;
-
- if (d > maxNoise[1]) {
- if (d < maxNoise[2]) {
-#define OP(i) v_tempBluredAss##i = vec_avg(v_tempBluredAss##i, v_srcAss##i);
-
- OP(0);
- OP(1);
- OP(2);
- OP(3);
- OP(4);
- OP(5);
- OP(6);
- OP(7);
-#undef OP
- } else {
-#define OP(i) v_tempBluredAss##i = v_srcAss##i;
-
- OP(0);
- OP(1);
- OP(2);
- OP(3);
- OP(4);
- OP(5);
- OP(6);
- OP(7);
-#undef OP
- }
- } else {
- if (d < maxNoise[0]) {
- const vector signed short vsint16_7 = vec_splat_s16(7);
- const vector signed short vsint16_4 = vec_splat_s16(4);
- const vector unsigned short vuint16_3 = vec_splat_u16(3);
-
-#define OP(i) \
- const vector signed short v_temp##i = \
- vec_mladd(v_tempBluredAss##i, \
- vsint16_7, v_srcAss##i); \
- const vector signed short v_temp2##i = \
- vec_add(v_temp##i, vsint16_4); \
- v_tempBluredAss##i = vec_sr(v_temp2##i, vuint16_3)
-
- OP(0);
- OP(1);
- OP(2);
- OP(3);
- OP(4);
- OP(5);
- OP(6);
- OP(7);
-#undef OP
- } else {
- const vector signed short vsint16_3 = vec_splat_s16(3);
- const vector signed short vsint16_2 = vec_splat_s16(2);
-
-#define OP(i) \
- const vector signed short v_temp##i = \
- vec_mladd(v_tempBluredAss##i, \
- vsint16_3, v_srcAss##i); \
- const vector signed short v_temp2##i = \
- vec_add(v_temp##i, vsint16_2); \
- v_tempBluredAss##i = vec_sr(v_temp2##i, (vector unsigned short)vsint16_2)
-
- OP(0);
- OP(1);
- OP(2);
- OP(3);
- OP(4);
- OP(5);
- OP(6);
- OP(7);
-#undef OP
- }
- }
-
- const vector signed char neg1 = vec_splat_s8(-1);
- const vector unsigned char permHH = (const vector unsigned char)AVV(0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F);
-
-#define PACK_AND_STORE(src, i) \
- const vector unsigned char perms##src##i = \
- vec_lvsr(i * stride, src); \
- const vector unsigned char vf##src##i = \
- vec_packsu(v_tempBluredAss##i, (vector signed short)zero); \
- const vector unsigned char vg##src##i = \
- vec_perm(vf##src##i, v_##src##A##i, permHH); \
- const vector unsigned char mask##src##i = \
- vec_perm((vector unsigned char)zero, (vector unsigned char)neg1, perms##src##i); \
- const vector unsigned char vg2##src##i = \
- vec_perm(vg##src##i, vg##src##i, perms##src##i); \
- const vector unsigned char svA##src##i = \
- vec_sel(v_##src##A1##i, vg2##src##i, mask##src##i); \
- const vector unsigned char svB##src##i = \
- vec_sel(vg2##src##i, v_##src##A2##i, mask##src##i); \
- vec_st(svA##src##i, i * stride, src); \
- vec_st(svB##src##i, i * stride + 16, src)
-
- PACK_AND_STORE(src, 0);
- PACK_AND_STORE(src, 1);
- PACK_AND_STORE(src, 2);
- PACK_AND_STORE(src, 3);
- PACK_AND_STORE(src, 4);
- PACK_AND_STORE(src, 5);
- PACK_AND_STORE(src, 6);
- PACK_AND_STORE(src, 7);
- PACK_AND_STORE(tempBlured, 0);
- PACK_AND_STORE(tempBlured, 1);
- PACK_AND_STORE(tempBlured, 2);
- PACK_AND_STORE(tempBlured, 3);
- PACK_AND_STORE(tempBlured, 4);
- PACK_AND_STORE(tempBlured, 5);
- PACK_AND_STORE(tempBlured, 6);
- PACK_AND_STORE(tempBlured, 7);
-#undef PACK_AND_STORE
-}
-
-static inline void transpose_16x8_char_toPackedAlign_altivec(unsigned char* dst, unsigned char* src, int stride) {
- const vector unsigned char zero = vec_splat_u8(0);
-
-#define LOAD_DOUBLE_LINE(i, j) \
- vector unsigned char perm1##i = vec_lvsl(i * stride, src); \
- vector unsigned char perm2##i = vec_lvsl(j * stride, src); \
- vector unsigned char srcA##i = vec_ld(i * stride, src); \
- vector unsigned char srcB##i = vec_ld(i * stride + 16, src); \
- vector unsigned char srcC##i = vec_ld(j * stride, src); \
- vector unsigned char srcD##i = vec_ld(j * stride+ 16, src); \
- vector unsigned char src##i = vec_perm(srcA##i, srcB##i, perm1##i); \
- vector unsigned char src##j = vec_perm(srcC##i, srcD##i, perm2##i)
-
- LOAD_DOUBLE_LINE(0, 1);
- LOAD_DOUBLE_LINE(2, 3);
- LOAD_DOUBLE_LINE(4, 5);
- LOAD_DOUBLE_LINE(6, 7);
-#undef LOAD_DOUBLE_LINE
-
- vector unsigned char tempA = vec_mergeh(src0, zero);
- vector unsigned char tempB = vec_mergel(src0, zero);
- vector unsigned char tempC = vec_mergeh(src1, zero);
- vector unsigned char tempD = vec_mergel(src1, zero);
- vector unsigned char tempE = vec_mergeh(src2, zero);
- vector unsigned char tempF = vec_mergel(src2, zero);
- vector unsigned char tempG = vec_mergeh(src3, zero);
- vector unsigned char tempH = vec_mergel(src3, zero);
- vector unsigned char tempI = vec_mergeh(src4, zero);
- vector unsigned char tempJ = vec_mergel(src4, zero);
- vector unsigned char tempK = vec_mergeh(src5, zero);
- vector unsigned char tempL = vec_mergel(src5, zero);
- vector unsigned char tempM = vec_mergeh(src6, zero);
- vector unsigned char tempN = vec_mergel(src6, zero);
- vector unsigned char tempO = vec_mergeh(src7, zero);
- vector unsigned char tempP = vec_mergel(src7, zero);
-
- vector unsigned char temp0 = vec_mergeh(tempA, tempI);
- vector unsigned char temp1 = vec_mergel(tempA, tempI);
- vector unsigned char temp2 = vec_mergeh(tempB, tempJ);
- vector unsigned char temp3 = vec_mergel(tempB, tempJ);
- vector unsigned char temp4 = vec_mergeh(tempC, tempK);
- vector unsigned char temp5 = vec_mergel(tempC, tempK);
- vector unsigned char temp6 = vec_mergeh(tempD, tempL);
- vector unsigned char temp7 = vec_mergel(tempD, tempL);
- vector unsigned char temp8 = vec_mergeh(tempE, tempM);
- vector unsigned char temp9 = vec_mergel(tempE, tempM);
- vector unsigned char temp10 = vec_mergeh(tempF, tempN);
- vector unsigned char temp11 = vec_mergel(tempF, tempN);
- vector unsigned char temp12 = vec_mergeh(tempG, tempO);
- vector unsigned char temp13 = vec_mergel(tempG, tempO);
- vector unsigned char temp14 = vec_mergeh(tempH, tempP);
- vector unsigned char temp15 = vec_mergel(tempH, tempP);
-
- tempA = vec_mergeh(temp0, temp8);
- tempB = vec_mergel(temp0, temp8);
- tempC = vec_mergeh(temp1, temp9);
- tempD = vec_mergel(temp1, temp9);
- tempE = vec_mergeh(temp2, temp10);
- tempF = vec_mergel(temp2, temp10);
- tempG = vec_mergeh(temp3, temp11);
- tempH = vec_mergel(temp3, temp11);
- tempI = vec_mergeh(temp4, temp12);
- tempJ = vec_mergel(temp4, temp12);
- tempK = vec_mergeh(temp5, temp13);
- tempL = vec_mergel(temp5, temp13);
- tempM = vec_mergeh(temp6, temp14);
- tempN = vec_mergel(temp6, temp14);
- tempO = vec_mergeh(temp7, temp15);
- tempP = vec_mergel(temp7, temp15);
-
- temp0 = vec_mergeh(tempA, tempI);
- temp1 = vec_mergel(tempA, tempI);
- temp2 = vec_mergeh(tempB, tempJ);
- temp3 = vec_mergel(tempB, tempJ);
- temp4 = vec_mergeh(tempC, tempK);
- temp5 = vec_mergel(tempC, tempK);
- temp6 = vec_mergeh(tempD, tempL);
- temp7 = vec_mergel(tempD, tempL);
- temp8 = vec_mergeh(tempE, tempM);
- temp9 = vec_mergel(tempE, tempM);
- temp10 = vec_mergeh(tempF, tempN);
- temp11 = vec_mergel(tempF, tempN);
- temp12 = vec_mergeh(tempG, tempO);
- temp13 = vec_mergel(tempG, tempO);
- temp14 = vec_mergeh(tempH, tempP);
- temp15 = vec_mergel(tempH, tempP);
-
- vec_st(temp0, 0, dst);
- vec_st(temp1, 16, dst);
- vec_st(temp2, 32, dst);
- vec_st(temp3, 48, dst);
- vec_st(temp4, 64, dst);
- vec_st(temp5, 80, dst);
- vec_st(temp6, 96, dst);
- vec_st(temp7, 112, dst);
- vec_st(temp8, 128, dst);
- vec_st(temp9, 144, dst);
- vec_st(temp10, 160, dst);
- vec_st(temp11, 176, dst);
- vec_st(temp12, 192, dst);
- vec_st(temp13, 208, dst);
- vec_st(temp14, 224, dst);
- vec_st(temp15, 240, dst);
-}
-
-static inline void transpose_8x16_char_fromPackedAlign_altivec(unsigned char* dst, unsigned char* src, int stride) {
- const vector unsigned char zero = vec_splat_u8(0);
- const vector unsigned char magic_perm = (const vector unsigned char)
- AVV(0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F);
-
-#define LOAD_DOUBLE_LINE(i, j) \
- vector unsigned char src##i = vec_ld(i * 16, src); \
- vector unsigned char src##j = vec_ld(j * 16, src)
-
- LOAD_DOUBLE_LINE(0, 1);
- LOAD_DOUBLE_LINE(2, 3);
- LOAD_DOUBLE_LINE(4, 5);
- LOAD_DOUBLE_LINE(6, 7);
- LOAD_DOUBLE_LINE(8, 9);
- LOAD_DOUBLE_LINE(10, 11);
- LOAD_DOUBLE_LINE(12, 13);
- LOAD_DOUBLE_LINE(14, 15);
-#undef LOAD_DOUBLE_LINE
-
- vector unsigned char tempA = vec_mergeh(src0, src8);
- vector unsigned char tempB;
- vector unsigned char tempC = vec_mergeh(src1, src9);
- vector unsigned char tempD;
- vector unsigned char tempE = vec_mergeh(src2, src10);
- vector unsigned char tempG = vec_mergeh(src3, src11);
- vector unsigned char tempI = vec_mergeh(src4, src12);
- vector unsigned char tempJ;
- vector unsigned char tempK = vec_mergeh(src5, src13);
- vector unsigned char tempL;
- vector unsigned char tempM = vec_mergeh(src6, src14);
- vector unsigned char tempO = vec_mergeh(src7, src15);
-
- vector unsigned char temp0 = vec_mergeh(tempA, tempI);
- vector unsigned char temp1 = vec_mergel(tempA, tempI);
- vector unsigned char temp2;
- vector unsigned char temp3;
- vector unsigned char temp4 = vec_mergeh(tempC, tempK);
- vector unsigned char temp5 = vec_mergel(tempC, tempK);
- vector unsigned char temp6;
- vector unsigned char temp7;
- vector unsigned char temp8 = vec_mergeh(tempE, tempM);
- vector unsigned char temp9 = vec_mergel(tempE, tempM);
- vector unsigned char temp12 = vec_mergeh(tempG, tempO);
- vector unsigned char temp13 = vec_mergel(tempG, tempO);
-
- tempA = vec_mergeh(temp0, temp8);
- tempB = vec_mergel(temp0, temp8);
- tempC = vec_mergeh(temp1, temp9);
- tempD = vec_mergel(temp1, temp9);
- tempI = vec_mergeh(temp4, temp12);
- tempJ = vec_mergel(temp4, temp12);
- tempK = vec_mergeh(temp5, temp13);
- tempL = vec_mergel(temp5, temp13);
-
- temp0 = vec_mergeh(tempA, tempI);
- temp1 = vec_mergel(tempA, tempI);
- temp2 = vec_mergeh(tempB, tempJ);
- temp3 = vec_mergel(tempB, tempJ);
- temp4 = vec_mergeh(tempC, tempK);
- temp5 = vec_mergel(tempC, tempK);
- temp6 = vec_mergeh(tempD, tempL);
- temp7 = vec_mergel(tempD, tempL);
-
-
- const vector signed char neg1 = vec_splat_s8(-1);
-#define STORE_DOUBLE_LINE(i, j) \
- vector unsigned char dstA##i = vec_ld(i * stride, dst); \
- vector unsigned char dstB##i = vec_ld(i * stride + 16, dst); \
- vector unsigned char dstA##j = vec_ld(j * stride, dst); \
- vector unsigned char dstB##j = vec_ld(j * stride+ 16, dst); \
- vector unsigned char align##i = vec_lvsr(i * stride, dst); \
- vector unsigned char align##j = vec_lvsr(j * stride, dst); \
- vector unsigned char mask##i = vec_perm(zero, (vector unsigned char)neg1, align##i); \
- vector unsigned char mask##j = vec_perm(zero, (vector unsigned char)neg1, align##j); \
- vector unsigned char dstR##i = vec_perm(temp##i, temp##i, align##i); \
- vector unsigned char dstR##j = vec_perm(temp##j, temp##j, align##j); \
- vector unsigned char dstAF##i = vec_sel(dstA##i, dstR##i, mask##i); \
- vector unsigned char dstBF##i = vec_sel(dstR##i, dstB##i, mask##i); \
- vector unsigned char dstAF##j = vec_sel(dstA##j, dstR##j, mask##j); \
- vector unsigned char dstBF##j = vec_sel(dstR##j, dstB##j, mask##j); \
- vec_st(dstAF##i, i * stride, dst); \
- vec_st(dstBF##i, i * stride + 16, dst); \
- vec_st(dstAF##j, j * stride, dst); \
- vec_st(dstBF##j, j * stride + 16, dst)
-
- STORE_DOUBLE_LINE(0,1);
- STORE_DOUBLE_LINE(2,3);
- STORE_DOUBLE_LINE(4,5);
- STORE_DOUBLE_LINE(6,7);
-}
diff --git a/src/libffmpeg/libavcodec/libpostproc/postprocess_internal.h b/src/libffmpeg/libavcodec/libpostproc/postprocess_internal.h
deleted file mode 100644
index 3d19c694b..000000000
--- a/src/libffmpeg/libavcodec/libpostproc/postprocess_internal.h
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- Copyright (C) 2001-2002 Michael Niedermayer (michaelni@gmx.at)
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-
-/**
- * @file postprocess_internal.h
- * internal api header.
- */
-
-#define V_DEBLOCK 0x01
-#define H_DEBLOCK 0x02
-#define DERING 0x04
-#define LEVEL_FIX 0x08 ///< Brightness & Contrast
-
-#define LUM_V_DEBLOCK V_DEBLOCK // 1
-#define LUM_H_DEBLOCK H_DEBLOCK // 2
-#define CHROM_V_DEBLOCK (V_DEBLOCK<<4) // 16
-#define CHROM_H_DEBLOCK (H_DEBLOCK<<4) // 32
-#define LUM_DERING DERING // 4
-#define CHROM_DERING (DERING<<4) // 64
-#define LUM_LEVEL_FIX LEVEL_FIX // 8
-#define CHROM_LEVEL_FIX (LEVEL_FIX<<4) // 128 (not implemented yet)
-
-// Experimental vertical filters
-#define V_X1_FILTER 0x0200 // 512
-#define V_A_DEBLOCK 0x0400
-
-// Experimental horizontal filters
-#define H_X1_FILTER 0x2000 // 8192
-#define H_A_DEBLOCK 0x4000
-
-/// select between full y range (255-0) or standart one (234-16)
-#define FULL_Y_RANGE 0x8000 // 32768
-
-//Deinterlacing Filters
-#define LINEAR_IPOL_DEINT_FILTER 0x10000 // 65536
-#define LINEAR_BLEND_DEINT_FILTER 0x20000 // 131072
-#define CUBIC_BLEND_DEINT_FILTER 0x8000 // (not implemented yet)
-#define CUBIC_IPOL_DEINT_FILTER 0x40000 // 262144
-#define MEDIAN_DEINT_FILTER 0x80000 // 524288
-#define FFMPEG_DEINT_FILTER 0x400000
-#define LOWPASS5_DEINT_FILTER 0x800000
-
-#define TEMP_NOISE_FILTER 0x100000
-#define FORCE_QUANT 0x200000
-
-#if ( defined(__PIC__) || defined(__pic__) ) && ! defined(PIC)
-# define PIC
-#endif
-
-//use if u want a faster postprocessing code
-//cant differentiate between chroma & luma filters (both on or both off)
-//obviosly the -pp option at the commandline has no effect except turning the here selected
-//filters on
-//#define COMPILE_TIME_MODE 0x77
-
-#if 1
-static inline int CLIP(int a){
- if(a&256) return ((a)>>31)^(-1);
- else return a;
-}
-//#define CLIP(a) (((a)&256) ? ((a)>>31)^(-1) : (a))
-#elif 0
-#define CLIP(a) clip_tab[a]
-#else
-#define CLIP(a) (a)
-#endif
-/**
- * Postprocessng filter.
- */
-struct PPFilter{
- char *shortName;
- char *longName;
- int chromDefault; ///< is chrominance filtering on by default if this filter is manually activated
- int minLumQuality; ///< minimum quality to turn luminance filtering on
- int minChromQuality; ///< minimum quality to turn chrominance filtering on
- int mask; ///< Bitmask to turn this filter on
-};
-
-/**
- * Postprocessng mode.
- */
-typedef struct PPMode{
- int lumMode; ///< acivates filters for luminance
- int chromMode; ///< acivates filters for chrominance
- int error; ///< non zero on error
-
- int minAllowedY; ///< for brigtness correction
- int maxAllowedY; ///< for brihtness correction
- float maxClippedThreshold; ///< amount of "black" u r willing to loose to get a brightness corrected picture
-
- int maxTmpNoise[3]; ///< for Temporal Noise Reducing filter (Maximal sum of abs differences)
-
- int baseDcDiff;
- int flatnessThreshold;
-
- int forcedQuant; ///< quantizer if FORCE_QUANT is used
-} PPMode;
-
-/**
- * postprocess context.
- */
-typedef struct PPContext{
- uint8_t *tempBlocks; ///<used for the horizontal code
-
- /**
- * luma histogram.
- * we need 64bit here otherwise we'll going to have a problem
- * after watching a black picture for 5 hours
- */
- uint64_t *yHistogram;
-
- uint64_t __attribute__((aligned(8))) packedYOffset;
- uint64_t __attribute__((aligned(8))) packedYScale;
-
- /** Temporal noise reducing buffers */
- uint8_t *tempBlured[3];
- int32_t *tempBluredPast[3];
-
- /** Temporary buffers for handling the last row(s) */
- uint8_t *tempDst;
- uint8_t *tempSrc;
-
- uint8_t *deintTemp;
-
- uint64_t __attribute__((aligned(8))) pQPb;
- uint64_t __attribute__((aligned(8))) pQPb2;
-
- uint64_t __attribute__((aligned(8))) mmxDcOffset[64];
- uint64_t __attribute__((aligned(8))) mmxDcThreshold[64];
-
- QP_STORE_T *stdQPTable; ///< used to fix MPEG2 style qscale
- QP_STORE_T *nonBQPTable;
- QP_STORE_T *forcedQPTable;
-
- int QP;
- int nonBQP;
-
- int frameNum;
-
- int cpuCaps;
-
- int qpStride; ///<size of qp buffers (needed to realloc them if needed)
- int stride; ///<size of some buffers (needed to realloc them if needed)
-
- int hChromaSubSample;
- int vChromaSubSample;
-
- PPMode ppMode;
-} PPContext;
-
-
-static inline void linecpy(void *dest, void *src, int lines, int stride)
-{
- if (stride > 0) {
- memcpy(dest, src, lines*stride);
- } else {
- memcpy(dest+(lines-1)*stride, src+(lines-1)*stride, -lines*stride);
- }
-}
diff --git a/src/libffmpeg/libavcodec/libpostproc/postprocess_template.c b/src/libffmpeg/libavcodec/libpostproc/postprocess_template.c
deleted file mode 100644
index 1171bd2aa..000000000
--- a/src/libffmpeg/libavcodec/libpostproc/postprocess_template.c
+++ /dev/null
@@ -1,3847 +0,0 @@
-/*
- Copyright (C) 2001-2002 Michael Niedermayer (michaelni@gmx.at)
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-
-/**
- * @file postprocess_template.c
- * mmx/mmx2/3dnow postprocess code.
- */
-
-
-#ifdef ARCH_X86_64
-# define REGa rax
-# define REGc rcx
-# define REGd rdx
-# define REG_a "rax"
-# define REG_c "rcx"
-# define REG_d "rdx"
-# define REG_SP "rsp"
-# define ALIGN_MASK "$0xFFFFFFFFFFFFFFF8"
-#else
-# define REGa eax
-# define REGc ecx
-# define REGd edx
-# define REG_a "eax"
-# define REG_c "ecx"
-# define REG_d "edx"
-# define REG_SP "esp"
-# define ALIGN_MASK "$0xFFFFFFF8"
-#endif
-
-
-#undef PAVGB
-#undef PMINUB
-#undef PMAXUB
-
-#ifdef HAVE_MMX2
-#define REAL_PAVGB(a,b) "pavgb " #a ", " #b " \n\t"
-#elif defined (HAVE_3DNOW)
-#define REAL_PAVGB(a,b) "pavgusb " #a ", " #b " \n\t"
-#endif
-#define PAVGB(a,b) REAL_PAVGB(a,b)
-
-#ifdef HAVE_MMX2
-#define PMINUB(a,b,t) "pminub " #a ", " #b " \n\t"
-#elif defined (HAVE_MMX)
-#define PMINUB(b,a,t) \
- "movq " #a ", " #t " \n\t"\
- "psubusb " #b ", " #t " \n\t"\
- "psubb " #t ", " #a " \n\t"
-#endif
-
-#ifdef HAVE_MMX2
-#define PMAXUB(a,b) "pmaxub " #a ", " #b " \n\t"
-#elif defined (HAVE_MMX)
-#define PMAXUB(a,b) \
- "psubusb " #a ", " #b " \n\t"\
- "paddb " #a ", " #b " \n\t"
-#endif
-
-//FIXME? |255-0| = 1 (shouldnt be a problem ...)
-#ifdef HAVE_MMX
-/**
- * Check if the middle 8x8 Block in the given 8x16 block is flat
- */
-static inline int RENAME(vertClassify)(uint8_t src[], int stride, PPContext *c){
- int numEq= 0, dcOk;
- src+= stride*4; // src points to begin of the 8x8 Block
-asm volatile(
- "movq %0, %%mm7 \n\t"
- "movq %1, %%mm6 \n\t"
- : : "m" (c->mmxDcOffset[c->nonBQP]), "m" (c->mmxDcThreshold[c->nonBQP])
- );
-
-asm volatile(
- "lea (%2, %3), %%"REG_a" \n\t"
-// 0 1 2 3 4 5 6 7 8 9
-// %1 eax eax+%2 eax+2%2 %1+4%2 ecx ecx+%2 ecx+2%2 %1+8%2 ecx+4%2
-
- "movq (%2), %%mm0 \n\t"
- "movq (%%"REG_a"), %%mm1 \n\t"
- "movq %%mm0, %%mm3 \n\t"
- "movq %%mm0, %%mm4 \n\t"
- PMAXUB(%%mm1, %%mm4)
- PMINUB(%%mm1, %%mm3, %%mm5)
- "psubb %%mm1, %%mm0 \n\t" // mm0 = differnece
- "paddb %%mm7, %%mm0 \n\t"
- "pcmpgtb %%mm6, %%mm0 \n\t"
-
- "movq (%%"REG_a",%3), %%mm2 \n\t"
- PMAXUB(%%mm2, %%mm4)
- PMINUB(%%mm2, %%mm3, %%mm5)
- "psubb %%mm2, %%mm1 \n\t"
- "paddb %%mm7, %%mm1 \n\t"
- "pcmpgtb %%mm6, %%mm1 \n\t"
- "paddb %%mm1, %%mm0 \n\t"
-
- "movq (%%"REG_a", %3, 2), %%mm1 \n\t"
- PMAXUB(%%mm1, %%mm4)
- PMINUB(%%mm1, %%mm3, %%mm5)
- "psubb %%mm1, %%mm2 \n\t"
- "paddb %%mm7, %%mm2 \n\t"
- "pcmpgtb %%mm6, %%mm2 \n\t"
- "paddb %%mm2, %%mm0 \n\t"
-
- "lea (%%"REG_a", %3, 4), %%"REG_a" \n\t"
-
- "movq (%2, %3, 4), %%mm2 \n\t"
- PMAXUB(%%mm2, %%mm4)
- PMINUB(%%mm2, %%mm3, %%mm5)
- "psubb %%mm2, %%mm1 \n\t"
- "paddb %%mm7, %%mm1 \n\t"
- "pcmpgtb %%mm6, %%mm1 \n\t"
- "paddb %%mm1, %%mm0 \n\t"
-
- "movq (%%"REG_a"), %%mm1 \n\t"
- PMAXUB(%%mm1, %%mm4)
- PMINUB(%%mm1, %%mm3, %%mm5)
- "psubb %%mm1, %%mm2 \n\t"
- "paddb %%mm7, %%mm2 \n\t"
- "pcmpgtb %%mm6, %%mm2 \n\t"
- "paddb %%mm2, %%mm0 \n\t"
-
- "movq (%%"REG_a", %3), %%mm2 \n\t"
- PMAXUB(%%mm2, %%mm4)
- PMINUB(%%mm2, %%mm3, %%mm5)
- "psubb %%mm2, %%mm1 \n\t"
- "paddb %%mm7, %%mm1 \n\t"
- "pcmpgtb %%mm6, %%mm1 \n\t"
- "paddb %%mm1, %%mm0 \n\t"
-
- "movq (%%"REG_a", %3, 2), %%mm1 \n\t"
- PMAXUB(%%mm1, %%mm4)
- PMINUB(%%mm1, %%mm3, %%mm5)
- "psubb %%mm1, %%mm2 \n\t"
- "paddb %%mm7, %%mm2 \n\t"
- "pcmpgtb %%mm6, %%mm2 \n\t"
- "paddb %%mm2, %%mm0 \n\t"
- "psubusb %%mm3, %%mm4 \n\t"
-
- " \n\t"
-#ifdef HAVE_MMX2
- "pxor %%mm7, %%mm7 \n\t"
- "psadbw %%mm7, %%mm0 \n\t"
-#else
- "movq %%mm0, %%mm1 \n\t"
- "psrlw $8, %%mm0 \n\t"
- "paddb %%mm1, %%mm0 \n\t"
- "movq %%mm0, %%mm1 \n\t"
- "psrlq $16, %%mm0 \n\t"
- "paddb %%mm1, %%mm0 \n\t"
- "movq %%mm0, %%mm1 \n\t"
- "psrlq $32, %%mm0 \n\t"
- "paddb %%mm1, %%mm0 \n\t"
-#endif
- "movq %4, %%mm7 \n\t" // QP,..., QP
- "paddusb %%mm7, %%mm7 \n\t" // 2QP ... 2QP
- "psubusb %%mm7, %%mm4 \n\t" // Diff <= 2QP -> 0
- "packssdw %%mm4, %%mm4 \n\t"
- "movd %%mm0, %0 \n\t"
- "movd %%mm4, %1 \n\t"
-
- : "=r" (numEq), "=r" (dcOk)
- : "r" (src), "r" ((long)stride), "m" (c->pQPb)
- : "%"REG_a
- );
-
- numEq= (-numEq) &0xFF;
- if(numEq > c->ppMode.flatnessThreshold){
- if(dcOk) return 0;
- else return 1;
- }else{
- return 2;
- }
-}
-#endif //HAVE_MMX
-
-/**
- * Do a vertical low pass filter on the 8x16 block (only write to the 8x8 block in the middle)
- * using the 9-Tap Filter (1,1,2,2,4,2,2,1,1)/16
- */
-#ifndef HAVE_ALTIVEC
-static inline void RENAME(doVertLowPass)(uint8_t *src, int stride, PPContext *c)
-{
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
- src+= stride*3;
- asm volatile( //"movv %0 %1 %2\n\t"
- "movq %2, %%mm0 \n\t" // QP,..., QP
- "pxor %%mm4, %%mm4 \n\t"
-
- "movq (%0), %%mm6 \n\t"
- "movq (%0, %1), %%mm5 \n\t"
- "movq %%mm5, %%mm1 \n\t"
- "movq %%mm6, %%mm2 \n\t"
- "psubusb %%mm6, %%mm5 \n\t"
- "psubusb %%mm1, %%mm2 \n\t"
- "por %%mm5, %%mm2 \n\t" // ABS Diff of lines
- "psubusb %%mm0, %%mm2 \n\t" // diff <= QP -> 0
- "pcmpeqb %%mm4, %%mm2 \n\t" // diff <= QP -> FF
-
- "pand %%mm2, %%mm6 \n\t"
- "pandn %%mm1, %%mm2 \n\t"
- "por %%mm2, %%mm6 \n\t"// First Line to Filter
-
- "movq (%0, %1, 8), %%mm5 \n\t"
- "lea (%0, %1, 4), %%"REG_a" \n\t"
- "lea (%0, %1, 8), %%"REG_c" \n\t"
- "sub %1, %%"REG_c" \n\t"
- "add %1, %0 \n\t" // %0 points to line 1 not 0
- "movq (%0, %1, 8), %%mm7 \n\t"
- "movq %%mm5, %%mm1 \n\t"
- "movq %%mm7, %%mm2 \n\t"
- "psubusb %%mm7, %%mm5 \n\t"
- "psubusb %%mm1, %%mm2 \n\t"
- "por %%mm5, %%mm2 \n\t" // ABS Diff of lines
- "psubusb %%mm0, %%mm2 \n\t" // diff <= QP -> 0
- "pcmpeqb %%mm4, %%mm2 \n\t" // diff <= QP -> FF
-
- "pand %%mm2, %%mm7 \n\t"
- "pandn %%mm1, %%mm2 \n\t"
- "por %%mm2, %%mm7 \n\t" // First Line to Filter
-
-
- // 1 2 3 4 5 6 7 8
- // %0 %0+%1 %0+2%1 eax %0+4%1 eax+2%1 ecx eax+4%1
- // 6 4 2 2 1 1
- // 6 4 4 2
- // 6 8 2
-
- "movq (%0, %1), %%mm0 \n\t" // 1
- "movq %%mm0, %%mm1 \n\t" // 1
- PAVGB(%%mm6, %%mm0) //1 1 /2
- PAVGB(%%mm6, %%mm0) //3 1 /4
-
- "movq (%0, %1, 4), %%mm2 \n\t" // 1
- "movq %%mm2, %%mm5 \n\t" // 1
- PAVGB((%%REGa), %%mm2) // 11 /2
- PAVGB((%0, %1, 2), %%mm2) // 211 /4
- "movq %%mm2, %%mm3 \n\t" // 211 /4
- "movq (%0), %%mm4 \n\t" // 1
- PAVGB(%%mm4, %%mm3) // 4 211 /8
- PAVGB(%%mm0, %%mm3) //642211 /16
- "movq %%mm3, (%0) \n\t" // X
- // mm1=2 mm2=3(211) mm4=1 mm5=5 mm6=0 mm7=9
- "movq %%mm1, %%mm0 \n\t" // 1
- PAVGB(%%mm6, %%mm0) //1 1 /2
- "movq %%mm4, %%mm3 \n\t" // 1
- PAVGB((%0,%1,2), %%mm3) // 1 1 /2
- PAVGB((%%REGa,%1,2), %%mm5) // 11 /2
- PAVGB((%%REGa), %%mm5) // 211 /4
- PAVGB(%%mm5, %%mm3) // 2 2211 /8
- PAVGB(%%mm0, %%mm3) //4242211 /16
- "movq %%mm3, (%0,%1) \n\t" // X
- // mm1=2 mm2=3(211) mm4=1 mm5=4(211) mm6=0 mm7=9
- PAVGB(%%mm4, %%mm6) //11 /2
- "movq (%%"REG_c"), %%mm0 \n\t" // 1
- PAVGB((%%REGa, %1, 2), %%mm0) // 11/2
- "movq %%mm0, %%mm3 \n\t" // 11/2
- PAVGB(%%mm1, %%mm0) // 2 11/4
- PAVGB(%%mm6, %%mm0) //222 11/8
- PAVGB(%%mm2, %%mm0) //22242211/16
- "movq (%0, %1, 2), %%mm2 \n\t" // 1
- "movq %%mm0, (%0, %1, 2) \n\t" // X
- // mm1=2 mm2=3 mm3=6(11) mm4=1 mm5=4(211) mm6=0(11) mm7=9
- "movq (%%"REG_a", %1, 4), %%mm0 \n\t" // 1
- PAVGB((%%REGc), %%mm0) // 11 /2
- PAVGB(%%mm0, %%mm6) //11 11 /4
- PAVGB(%%mm1, %%mm4) // 11 /2
- PAVGB(%%mm2, %%mm1) // 11 /2
- PAVGB(%%mm1, %%mm6) //1122 11 /8
- PAVGB(%%mm5, %%mm6) //112242211 /16
- "movq (%%"REG_a"), %%mm5 \n\t" // 1
- "movq %%mm6, (%%"REG_a") \n\t" // X
- // mm0=7(11) mm1=2(11) mm2=3 mm3=6(11) mm4=1(11) mm5=4 mm7=9
- "movq (%%"REG_a", %1, 4), %%mm6 \n\t" // 1
- PAVGB(%%mm7, %%mm6) // 11 /2
- PAVGB(%%mm4, %%mm6) // 11 11 /4
- PAVGB(%%mm3, %%mm6) // 11 2211 /8
- PAVGB(%%mm5, %%mm2) // 11 /2
- "movq (%0, %1, 4), %%mm4 \n\t" // 1
- PAVGB(%%mm4, %%mm2) // 112 /4
- PAVGB(%%mm2, %%mm6) // 112242211 /16
- "movq %%mm6, (%0, %1, 4) \n\t" // X
- // mm0=7(11) mm1=2(11) mm2=3(112) mm3=6(11) mm4=5 mm5=4 mm7=9
- PAVGB(%%mm7, %%mm1) // 11 2 /4
- PAVGB(%%mm4, %%mm5) // 11 /2
- PAVGB(%%mm5, %%mm0) // 11 11 /4
- "movq (%%"REG_a", %1, 2), %%mm6 \n\t" // 1
- PAVGB(%%mm6, %%mm1) // 11 4 2 /8
- PAVGB(%%mm0, %%mm1) // 11224222 /16
- "movq %%mm1, (%%"REG_a", %1, 2) \n\t" // X
- // mm2=3(112) mm3=6(11) mm4=5 mm5=4(11) mm6=6 mm7=9
- PAVGB((%%REGc), %%mm2) // 112 4 /8
- "movq (%%"REG_a", %1, 4), %%mm0 \n\t" // 1
- PAVGB(%%mm0, %%mm6) // 1 1 /2
- PAVGB(%%mm7, %%mm6) // 1 12 /4
- PAVGB(%%mm2, %%mm6) // 1122424 /4
- "movq %%mm6, (%%"REG_c") \n\t" // X
- // mm0=8 mm3=6(11) mm4=5 mm5=4(11) mm7=9
- PAVGB(%%mm7, %%mm5) // 11 2 /4
- PAVGB(%%mm7, %%mm5) // 11 6 /8
-
- PAVGB(%%mm3, %%mm0) // 112 /4
- PAVGB(%%mm0, %%mm5) // 112246 /16
- "movq %%mm5, (%%"REG_a", %1, 4) \n\t" // X
- "sub %1, %0 \n\t"
-
- :
- : "r" (src), "r" ((long)stride), "m" (c->pQPb)
- : "%"REG_a, "%"REG_c
- );
-#else //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
- const int l1= stride;
- const int l2= stride + l1;
- const int l3= stride + l2;
- const int l4= stride + l3;
- const int l5= stride + l4;
- const int l6= stride + l5;
- const int l7= stride + l6;
- const int l8= stride + l7;
- const int l9= stride + l8;
- int x;
- src+= stride*3;
- for(x=0; x<BLOCK_SIZE; x++)
- {
- const int first= ABS(src[0] - src[l1]) < c->QP ? src[0] : src[l1];
- const int last= ABS(src[l8] - src[l9]) < c->QP ? src[l9] : src[l8];
-
- int sums[10];
- sums[0] = 4*first + src[l1] + src[l2] + src[l3] + 4;
- sums[1] = sums[0] - first + src[l4];
- sums[2] = sums[1] - first + src[l5];
- sums[3] = sums[2] - first + src[l6];
- sums[4] = sums[3] - first + src[l7];
- sums[5] = sums[4] - src[l1] + src[l8];
- sums[6] = sums[5] - src[l2] + last;
- sums[7] = sums[6] - src[l3] + last;
- sums[8] = sums[7] - src[l4] + last;
- sums[9] = sums[8] - src[l5] + last;
-
- src[l1]= (sums[0] + sums[2] + 2*src[l1])>>4;
- src[l2]= (sums[1] + sums[3] + 2*src[l2])>>4;
- src[l3]= (sums[2] + sums[4] + 2*src[l3])>>4;
- src[l4]= (sums[3] + sums[5] + 2*src[l4])>>4;
- src[l5]= (sums[4] + sums[6] + 2*src[l5])>>4;
- src[l6]= (sums[5] + sums[7] + 2*src[l6])>>4;
- src[l7]= (sums[6] + sums[8] + 2*src[l7])>>4;
- src[l8]= (sums[7] + sums[9] + 2*src[l8])>>4;
-
- src++;
- }
-#endif //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
-}
-#endif //HAVE_ALTIVEC
-
-#if 0
-/**
- * Experimental implementation of the filter (Algorithm 1) described in a paper from Ramkishor & Karandikar
- * values are correctly clipped (MMX2)
- * values are wraparound (C)
- * conclusion: its fast, but introduces ugly horizontal patterns if there is a continious gradient
- 0 8 16 24
- x = 8
- x/2 = 4
- x/8 = 1
- 1 12 12 23
- */
-static inline void RENAME(vertRK1Filter)(uint8_t *src, int stride, int QP)
-{
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
- src+= stride*3;
-// FIXME rounding
- asm volatile(
- "pxor %%mm7, %%mm7 \n\t" // 0
- "movq "MANGLE(b80)", %%mm6 \n\t" // MIN_SIGNED_BYTE
- "leal (%0, %1), %%"REG_a" \n\t"
- "leal (%%"REG_a", %1, 4), %%"REG_c" \n\t"
-// 0 1 2 3 4 5 6 7 8 9
-// %0 eax eax+%1 eax+2%1 %0+4%1 ecx ecx+%1 ecx+2%1 %0+8%1 ecx+4%1
- "movq "MANGLE(pQPb)", %%mm0 \n\t" // QP,..., QP
- "movq %%mm0, %%mm1 \n\t" // QP,..., QP
- "paddusb "MANGLE(b02)", %%mm0 \n\t"
- "psrlw $2, %%mm0 \n\t"
- "pand "MANGLE(b3F)", %%mm0 \n\t" // QP/4,..., QP/4
- "paddusb %%mm1, %%mm0 \n\t" // QP*1.25 ...
- "movq (%0, %1, 4), %%mm2 \n\t" // line 4
- "movq (%%"REG_c"), %%mm3 \n\t" // line 5
- "movq %%mm2, %%mm4 \n\t" // line 4
- "pcmpeqb %%mm5, %%mm5 \n\t" // -1
- "pxor %%mm2, %%mm5 \n\t" // -line 4 - 1
- PAVGB(%%mm3, %%mm5)
- "paddb %%mm6, %%mm5 \n\t" // (l5-l4)/2
- "psubusb %%mm3, %%mm4 \n\t"
- "psubusb %%mm2, %%mm3 \n\t"
- "por %%mm3, %%mm4 \n\t" // |l4 - l5|
- "psubusb %%mm0, %%mm4 \n\t"
- "pcmpeqb %%mm7, %%mm4 \n\t"
- "pand %%mm4, %%mm5 \n\t" // d/2
-
-// "paddb %%mm6, %%mm2 \n\t" // line 4 + 0x80
- "paddb %%mm5, %%mm2 \n\t"
-// "psubb %%mm6, %%mm2 \n\t"
- "movq %%mm2, (%0,%1, 4) \n\t"
-
- "movq (%%"REG_c"), %%mm2 \n\t"
-// "paddb %%mm6, %%mm2 \n\t" // line 5 + 0x80
- "psubb %%mm5, %%mm2 \n\t"
-// "psubb %%mm6, %%mm2 \n\t"
- "movq %%mm2, (%%"REG_c") \n\t"
-
- "paddb %%mm6, %%mm5 \n\t"
- "psrlw $2, %%mm5 \n\t"
- "pand "MANGLE(b3F)", %%mm5 \n\t"
- "psubb "MANGLE(b20)", %%mm5 \n\t" // (l5-l4)/8
-
- "movq (%%"REG_a", %1, 2), %%mm2 \n\t"
- "paddb %%mm6, %%mm2 \n\t" // line 3 + 0x80
- "paddsb %%mm5, %%mm2 \n\t"
- "psubb %%mm6, %%mm2 \n\t"
- "movq %%mm2, (%%"REG_a", %1, 2) \n\t"
-
- "movq (%%"REG_c", %1), %%mm2 \n\t"
- "paddb %%mm6, %%mm2 \n\t" // line 6 + 0x80
- "psubsb %%mm5, %%mm2 \n\t"
- "psubb %%mm6, %%mm2 \n\t"
- "movq %%mm2, (%%"REG_c", %1) \n\t"
-
- :
- : "r" (src), "r" ((long)stride)
- : "%"REG_a, "%"REG_c
- );
-#else //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
- const int l1= stride;
- const int l2= stride + l1;
- const int l3= stride + l2;
- const int l4= stride + l3;
- const int l5= stride + l4;
- const int l6= stride + l5;
-// const int l7= stride + l6;
-// const int l8= stride + l7;
-// const int l9= stride + l8;
- int x;
- const int QP15= QP + (QP>>2);
- src+= stride*3;
- for(x=0; x<BLOCK_SIZE; x++)
- {
- const int v = (src[x+l5] - src[x+l4]);
- if(ABS(v) < QP15)
- {
- src[x+l3] +=v>>3;
- src[x+l4] +=v>>1;
- src[x+l5] -=v>>1;
- src[x+l6] -=v>>3;
-
- }
- }
-
-#endif //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
-}
-#endif //0
-
-/**
- * Experimental Filter 1
- * will not damage linear gradients
- * Flat blocks should look like they where passed through the (1,1,2,2,4,2,2,1,1) 9-Tap filter
- * can only smooth blocks at the expected locations (it cant smooth them if they did move)
- * MMX2 version does correct clipping C version doesnt
- */
-static inline void RENAME(vertX1Filter)(uint8_t *src, int stride, PPContext *co)
-{
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
- src+= stride*3;
-
- asm volatile(
- "pxor %%mm7, %%mm7 \n\t" // 0
- "lea (%0, %1), %%"REG_a" \n\t"
- "lea (%%"REG_a", %1, 4), %%"REG_c" \n\t"
-// 0 1 2 3 4 5 6 7 8 9
-// %0 eax eax+%1 eax+2%1 %0+4%1 ecx ecx+%1 ecx+2%1 %0+8%1 ecx+4%1
- "movq (%%"REG_a", %1, 2), %%mm0 \n\t" // line 3
- "movq (%0, %1, 4), %%mm1 \n\t" // line 4
- "movq %%mm1, %%mm2 \n\t" // line 4
- "psubusb %%mm0, %%mm1 \n\t"
- "psubusb %%mm2, %%mm0 \n\t"
- "por %%mm1, %%mm0 \n\t" // |l2 - l3|
- "movq (%%"REG_c"), %%mm3 \n\t" // line 5
- "movq (%%"REG_c", %1), %%mm4 \n\t" // line 6
- "movq %%mm3, %%mm5 \n\t" // line 5
- "psubusb %%mm4, %%mm3 \n\t"
- "psubusb %%mm5, %%mm4 \n\t"
- "por %%mm4, %%mm3 \n\t" // |l5 - l6|
- PAVGB(%%mm3, %%mm0) // (|l2 - l3| + |l5 - l6|)/2
- "movq %%mm2, %%mm1 \n\t" // line 4
- "psubusb %%mm5, %%mm2 \n\t"
- "movq %%mm2, %%mm4 \n\t"
- "pcmpeqb %%mm7, %%mm2 \n\t" // (l4 - l5) <= 0 ? -1 : 0
- "psubusb %%mm1, %%mm5 \n\t"
- "por %%mm5, %%mm4 \n\t" // |l4 - l5|
- "psubusb %%mm0, %%mm4 \n\t" //d = MAX(0, |l4-l5| - (|l2-l3| + |l5-l6|)/2)
- "movq %%mm4, %%mm3 \n\t" // d
- "movq %2, %%mm0 \n\t"
- "paddusb %%mm0, %%mm0 \n\t"
- "psubusb %%mm0, %%mm4 \n\t"
- "pcmpeqb %%mm7, %%mm4 \n\t" // d <= QP ? -1 : 0
- "psubusb "MANGLE(b01)", %%mm3 \n\t"
- "pand %%mm4, %%mm3 \n\t" // d <= QP ? d : 0
-
- PAVGB(%%mm7, %%mm3) // d/2
- "movq %%mm3, %%mm1 \n\t" // d/2
- PAVGB(%%mm7, %%mm3) // d/4
- PAVGB(%%mm1, %%mm3) // 3*d/8
-
- "movq (%0, %1, 4), %%mm0 \n\t" // line 4
- "pxor %%mm2, %%mm0 \n\t" //(l4 - l5) <= 0 ? -l4-1 : l4
- "psubusb %%mm3, %%mm0 \n\t"
- "pxor %%mm2, %%mm0 \n\t"
- "movq %%mm0, (%0, %1, 4) \n\t" // line 4
-
- "movq (%%"REG_c"), %%mm0 \n\t" // line 5
- "pxor %%mm2, %%mm0 \n\t" //(l4 - l5) <= 0 ? -l5-1 : l5
- "paddusb %%mm3, %%mm0 \n\t"
- "pxor %%mm2, %%mm0 \n\t"
- "movq %%mm0, (%%"REG_c") \n\t" // line 5
-
- PAVGB(%%mm7, %%mm1) // d/4
-
- "movq (%%"REG_a", %1, 2), %%mm0 \n\t" // line 3
- "pxor %%mm2, %%mm0 \n\t" //(l4 - l5) <= 0 ? -l4-1 : l4
- "psubusb %%mm1, %%mm0 \n\t"
- "pxor %%mm2, %%mm0 \n\t"
- "movq %%mm0, (%%"REG_a", %1, 2) \n\t" // line 3
-
- "movq (%%"REG_c", %1), %%mm0 \n\t" // line 6
- "pxor %%mm2, %%mm0 \n\t" //(l4 - l5) <= 0 ? -l5-1 : l5
- "paddusb %%mm1, %%mm0 \n\t"
- "pxor %%mm2, %%mm0 \n\t"
- "movq %%mm0, (%%"REG_c", %1) \n\t" // line 6
-
- PAVGB(%%mm7, %%mm1) // d/8
-
- "movq (%%"REG_a", %1), %%mm0 \n\t" // line 2
- "pxor %%mm2, %%mm0 \n\t" //(l4 - l5) <= 0 ? -l2-1 : l2
- "psubusb %%mm1, %%mm0 \n\t"
- "pxor %%mm2, %%mm0 \n\t"
- "movq %%mm0, (%%"REG_a", %1) \n\t" // line 2
-
- "movq (%%"REG_c", %1, 2), %%mm0 \n\t" // line 7
- "pxor %%mm2, %%mm0 \n\t" //(l4 - l5) <= 0 ? -l7-1 : l7
- "paddusb %%mm1, %%mm0 \n\t"
- "pxor %%mm2, %%mm0 \n\t"
- "movq %%mm0, (%%"REG_c", %1, 2) \n\t" // line 7
-
- :
- : "r" (src), "r" ((long)stride), "m" (co->pQPb)
- : "%"REG_a, "%"REG_c
- );
-#else //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
-
- const int l1= stride;
- const int l2= stride + l1;
- const int l3= stride + l2;
- const int l4= stride + l3;
- const int l5= stride + l4;
- const int l6= stride + l5;
- const int l7= stride + l6;
-// const int l8= stride + l7;
-// const int l9= stride + l8;
- int x;
-
- src+= stride*3;
- for(x=0; x<BLOCK_SIZE; x++)
- {
- int a= src[l3] - src[l4];
- int b= src[l4] - src[l5];
- int c= src[l5] - src[l6];
-
- int d= ABS(b) - ((ABS(a) + ABS(c))>>1);
- d= MAX(d, 0);
-
- if(d < co->QP*2)
- {
- int v = d * SIGN(-b);
-
- src[l2] +=v>>3;
- src[l3] +=v>>2;
- src[l4] +=(3*v)>>3;
- src[l5] -=(3*v)>>3;
- src[l6] -=v>>2;
- src[l7] -=v>>3;
-
- }
- src++;
- }
-#endif //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
-}
-
-#ifndef HAVE_ALTIVEC
-static inline void RENAME(doVertDefFilter)(uint8_t src[], int stride, PPContext *c)
-{
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
-/*
- uint8_t tmp[16];
- const int l1= stride;
- const int l2= stride + l1;
- const int l3= stride + l2;
- const int l4= (int)tmp - (int)src - stride*3;
- const int l5= (int)tmp - (int)src - stride*3 + 8;
- const int l6= stride*3 + l3;
- const int l7= stride + l6;
- const int l8= stride + l7;
-
- memcpy(tmp, src+stride*7, 8);
- memcpy(tmp+8, src+stride*8, 8);
-*/
- src+= stride*4;
- asm volatile(
-
-#if 0 //sligtly more accurate and slightly slower
- "pxor %%mm7, %%mm7 \n\t" // 0
- "lea (%0, %1), %%"REG_a" \n\t"
- "lea (%%"REG_a", %1, 4), %%"REG_c" \n\t"
-// 0 1 2 3 4 5 6 7
-// %0 %0+%1 %0+2%1 eax+2%1 %0+4%1 eax+4%1 ecx+%1 ecx+2%1
-// %0 eax eax+%1 eax+2%1 %0+4%1 ecx ecx+%1 ecx+2%1
-
-
- "movq (%0, %1, 2), %%mm0 \n\t" // l2
- "movq (%0), %%mm1 \n\t" // l0
- "movq %%mm0, %%mm2 \n\t" // l2
- PAVGB(%%mm7, %%mm0) // ~l2/2
- PAVGB(%%mm1, %%mm0) // ~(l2 + 2l0)/4
- PAVGB(%%mm2, %%mm0) // ~(5l2 + 2l0)/8
-
- "movq (%%"REG_a"), %%mm1 \n\t" // l1
- "movq (%%"REG_a", %1, 2), %%mm3 \n\t" // l3
- "movq %%mm1, %%mm4 \n\t" // l1
- PAVGB(%%mm7, %%mm1) // ~l1/2
- PAVGB(%%mm3, %%mm1) // ~(l1 + 2l3)/4
- PAVGB(%%mm4, %%mm1) // ~(5l1 + 2l3)/8
-
- "movq %%mm0, %%mm4 \n\t" // ~(5l2 + 2l0)/8
- "psubusb %%mm1, %%mm0 \n\t"
- "psubusb %%mm4, %%mm1 \n\t"
- "por %%mm0, %%mm1 \n\t" // ~|2l0 - 5l1 + 5l2 - 2l3|/8
-// mm1= |lenergy|, mm2= l2, mm3= l3, mm7=0
-
- "movq (%0, %1, 4), %%mm0 \n\t" // l4
- "movq %%mm0, %%mm4 \n\t" // l4
- PAVGB(%%mm7, %%mm0) // ~l4/2
- PAVGB(%%mm2, %%mm0) // ~(l4 + 2l2)/4
- PAVGB(%%mm4, %%mm0) // ~(5l4 + 2l2)/8
-
- "movq (%%"REG_c"), %%mm2 \n\t" // l5
- "movq %%mm3, %%mm5 \n\t" // l3
- PAVGB(%%mm7, %%mm3) // ~l3/2
- PAVGB(%%mm2, %%mm3) // ~(l3 + 2l5)/4
- PAVGB(%%mm5, %%mm3) // ~(5l3 + 2l5)/8
-
- "movq %%mm0, %%mm6 \n\t" // ~(5l4 + 2l2)/8
- "psubusb %%mm3, %%mm0 \n\t"
- "psubusb %%mm6, %%mm3 \n\t"
- "por %%mm0, %%mm3 \n\t" // ~|2l2 - 5l3 + 5l4 - 2l5|/8
- "pcmpeqb %%mm7, %%mm0 \n\t" // SIGN(2l2 - 5l3 + 5l4 - 2l5)
-// mm0= SIGN(menergy), mm1= |lenergy|, mm2= l5, mm3= |menergy|, mm4=l4, mm5= l3, mm7=0
-
- "movq (%%"REG_c", %1), %%mm6 \n\t" // l6
- "movq %%mm6, %%mm5 \n\t" // l6
- PAVGB(%%mm7, %%mm6) // ~l6/2
- PAVGB(%%mm4, %%mm6) // ~(l6 + 2l4)/4
- PAVGB(%%mm5, %%mm6) // ~(5l6 + 2l4)/8
-
- "movq (%%"REG_c", %1, 2), %%mm5 \n\t" // l7
- "movq %%mm2, %%mm4 \n\t" // l5
- PAVGB(%%mm7, %%mm2) // ~l5/2
- PAVGB(%%mm5, %%mm2) // ~(l5 + 2l7)/4
- PAVGB(%%mm4, %%mm2) // ~(5l5 + 2l7)/8
-
- "movq %%mm6, %%mm4 \n\t" // ~(5l6 + 2l4)/8
- "psubusb %%mm2, %%mm6 \n\t"
- "psubusb %%mm4, %%mm2 \n\t"
- "por %%mm6, %%mm2 \n\t" // ~|2l4 - 5l5 + 5l6 - 2l7|/8
-// mm0= SIGN(menergy), mm1= |lenergy|/8, mm2= |renergy|/8, mm3= |menergy|/8, mm7=0
-
-
- PMINUB(%%mm2, %%mm1, %%mm4) // MIN(|lenergy|,|renergy|)/8
- "movq %2, %%mm4 \n\t" // QP //FIXME QP+1 ?
- "paddusb "MANGLE(b01)", %%mm4 \n\t"
- "pcmpgtb %%mm3, %%mm4 \n\t" // |menergy|/8 < QP
- "psubusb %%mm1, %%mm3 \n\t" // d=|menergy|/8-MIN(|lenergy|,|renergy|)/8
- "pand %%mm4, %%mm3 \n\t"
-
- "movq %%mm3, %%mm1 \n\t"
-// "psubusb "MANGLE(b01)", %%mm3 \n\t"
- PAVGB(%%mm7, %%mm3)
- PAVGB(%%mm7, %%mm3)
- "paddusb %%mm1, %%mm3 \n\t"
-// "paddusb "MANGLE(b01)", %%mm3 \n\t"
-
- "movq (%%"REG_a", %1, 2), %%mm6 \n\t" //l3
- "movq (%0, %1, 4), %%mm5 \n\t" //l4
- "movq (%0, %1, 4), %%mm4 \n\t" //l4
- "psubusb %%mm6, %%mm5 \n\t"
- "psubusb %%mm4, %%mm6 \n\t"
- "por %%mm6, %%mm5 \n\t" // |l3-l4|
- "pcmpeqb %%mm7, %%mm6 \n\t" // SIGN(l3-l4)
- "pxor %%mm6, %%mm0 \n\t"
- "pand %%mm0, %%mm3 \n\t"
- PMINUB(%%mm5, %%mm3, %%mm0)
-
- "psubusb "MANGLE(b01)", %%mm3 \n\t"
- PAVGB(%%mm7, %%mm3)
-
- "movq (%%"REG_a", %1, 2), %%mm0 \n\t"
- "movq (%0, %1, 4), %%mm2 \n\t"
- "pxor %%mm6, %%mm0 \n\t"
- "pxor %%mm6, %%mm2 \n\t"
- "psubb %%mm3, %%mm0 \n\t"
- "paddb %%mm3, %%mm2 \n\t"
- "pxor %%mm6, %%mm0 \n\t"
- "pxor %%mm6, %%mm2 \n\t"
- "movq %%mm0, (%%"REG_a", %1, 2) \n\t"
- "movq %%mm2, (%0, %1, 4) \n\t"
-#endif //0
-
- "lea (%0, %1), %%"REG_a" \n\t"
- "pcmpeqb %%mm6, %%mm6 \n\t" // -1
-// 0 1 2 3 4 5 6 7
-// %0 %0+%1 %0+2%1 eax+2%1 %0+4%1 eax+4%1 ecx+%1 ecx+2%1
-// %0 eax eax+%1 eax+2%1 %0+4%1 ecx ecx+%1 ecx+2%1
-
-
- "movq (%%"REG_a", %1, 2), %%mm1 \n\t" // l3
- "movq (%0, %1, 4), %%mm0 \n\t" // l4
- "pxor %%mm6, %%mm1 \n\t" // -l3-1
- PAVGB(%%mm1, %%mm0) // -q+128 = (l4-l3+256)/2
-// mm1=-l3-1, mm0=128-q
-
- "movq (%%"REG_a", %1, 4), %%mm2 \n\t" // l5
- "movq (%%"REG_a", %1), %%mm3 \n\t" // l2
- "pxor %%mm6, %%mm2 \n\t" // -l5-1
- "movq %%mm2, %%mm5 \n\t" // -l5-1
- "movq "MANGLE(b80)", %%mm4 \n\t" // 128
- "lea (%%"REG_a", %1, 4), %%"REG_c" \n\t"
- PAVGB(%%mm3, %%mm2) // (l2-l5+256)/2
- PAVGB(%%mm0, %%mm4) // ~(l4-l3)/4 + 128
- PAVGB(%%mm2, %%mm4) // ~(l2-l5)/4 +(l4-l3)/8 + 128
- PAVGB(%%mm0, %%mm4) // ~(l2-l5)/8 +5(l4-l3)/16 + 128
-// mm1=-l3-1, mm0=128-q, mm3=l2, mm4=menergy/16 + 128, mm5= -l5-1
-
- "movq (%%"REG_a"), %%mm2 \n\t" // l1
- "pxor %%mm6, %%mm2 \n\t" // -l1-1
- PAVGB(%%mm3, %%mm2) // (l2-l1+256)/2
- PAVGB((%0), %%mm1) // (l0-l3+256)/2
- "movq "MANGLE(b80)", %%mm3 \n\t" // 128
- PAVGB(%%mm2, %%mm3) // ~(l2-l1)/4 + 128
- PAVGB(%%mm1, %%mm3) // ~(l0-l3)/4 +(l2-l1)/8 + 128
- PAVGB(%%mm2, %%mm3) // ~(l0-l3)/8 +5(l2-l1)/16 + 128
-// mm0=128-q, mm3=lenergy/16 + 128, mm4= menergy/16 + 128, mm5= -l5-1
-
- PAVGB((%%REGc, %1), %%mm5) // (l6-l5+256)/2
- "movq (%%"REG_c", %1, 2), %%mm1 \n\t" // l7
- "pxor %%mm6, %%mm1 \n\t" // -l7-1
- PAVGB((%0, %1, 4), %%mm1) // (l4-l7+256)/2
- "movq "MANGLE(b80)", %%mm2 \n\t" // 128
- PAVGB(%%mm5, %%mm2) // ~(l6-l5)/4 + 128
- PAVGB(%%mm1, %%mm2) // ~(l4-l7)/4 +(l6-l5)/8 + 128
- PAVGB(%%mm5, %%mm2) // ~(l4-l7)/8 +5(l6-l5)/16 + 128
-// mm0=128-q, mm2=renergy/16 + 128, mm3=lenergy/16 + 128, mm4= menergy/16 + 128
-
- "movq "MANGLE(b00)", %%mm1 \n\t" // 0
- "movq "MANGLE(b00)", %%mm5 \n\t" // 0
- "psubb %%mm2, %%mm1 \n\t" // 128 - renergy/16
- "psubb %%mm3, %%mm5 \n\t" // 128 - lenergy/16
- PMAXUB(%%mm1, %%mm2) // 128 + |renergy/16|
- PMAXUB(%%mm5, %%mm3) // 128 + |lenergy/16|
- PMINUB(%%mm2, %%mm3, %%mm1) // 128 + MIN(|lenergy|,|renergy|)/16
-
-// mm0=128-q, mm3=128 + MIN(|lenergy|,|renergy|)/16, mm4= menergy/16 + 128
-
- "movq "MANGLE(b00)", %%mm7 \n\t" // 0
- "movq %2, %%mm2 \n\t" // QP
- PAVGB(%%mm6, %%mm2) // 128 + QP/2
- "psubb %%mm6, %%mm2 \n\t"
-
- "movq %%mm4, %%mm1 \n\t"
- "pcmpgtb %%mm7, %%mm1 \n\t" // SIGN(menergy)
- "pxor %%mm1, %%mm4 \n\t"
- "psubb %%mm1, %%mm4 \n\t" // 128 + |menergy|/16
- "pcmpgtb %%mm4, %%mm2 \n\t" // |menergy|/16 < QP/2
- "psubusb %%mm3, %%mm4 \n\t" //d=|menergy|/16 - MIN(|lenergy|,|renergy|)/16
-// mm0=128-q, mm1= SIGN(menergy), mm2= |menergy|/16 < QP/2, mm4= d/16
-
- "movq %%mm4, %%mm3 \n\t" // d
- "psubusb "MANGLE(b01)", %%mm4 \n\t"
- PAVGB(%%mm7, %%mm4) // d/32
- PAVGB(%%mm7, %%mm4) // (d + 32)/64
- "paddb %%mm3, %%mm4 \n\t" // 5d/64
- "pand %%mm2, %%mm4 \n\t"
-
- "movq "MANGLE(b80)", %%mm5 \n\t" // 128
- "psubb %%mm0, %%mm5 \n\t" // q
- "paddsb %%mm6, %%mm5 \n\t" // fix bad rounding
- "pcmpgtb %%mm5, %%mm7 \n\t" // SIGN(q)
- "pxor %%mm7, %%mm5 \n\t"
-
- PMINUB(%%mm5, %%mm4, %%mm3) // MIN(|q|, 5d/64)
- "pxor %%mm1, %%mm7 \n\t" // SIGN(d*q)
-
- "pand %%mm7, %%mm4 \n\t"
- "movq (%%"REG_a", %1, 2), %%mm0 \n\t"
- "movq (%0, %1, 4), %%mm2 \n\t"
- "pxor %%mm1, %%mm0 \n\t"
- "pxor %%mm1, %%mm2 \n\t"
- "paddb %%mm4, %%mm0 \n\t"
- "psubb %%mm4, %%mm2 \n\t"
- "pxor %%mm1, %%mm0 \n\t"
- "pxor %%mm1, %%mm2 \n\t"
- "movq %%mm0, (%%"REG_a", %1, 2) \n\t"
- "movq %%mm2, (%0, %1, 4) \n\t"
-
- :
- : "r" (src), "r" ((long)stride), "m" (c->pQPb)
- : "%"REG_a, "%"REG_c
- );
-
-/*
- {
- int x;
- src-= stride;
- for(x=0; x<BLOCK_SIZE; x++)
- {
- const int middleEnergy= 5*(src[l5] - src[l4]) + 2*(src[l3] - src[l6]);
- if(ABS(middleEnergy)< 8*QP)
- {
- const int q=(src[l4] - src[l5])/2;
- const int leftEnergy= 5*(src[l3] - src[l2]) + 2*(src[l1] - src[l4]);
- const int rightEnergy= 5*(src[l7] - src[l6]) + 2*(src[l5] - src[l8]);
-
- int d= ABS(middleEnergy) - MIN( ABS(leftEnergy), ABS(rightEnergy) );
- d= MAX(d, 0);
-
- d= (5*d + 32) >> 6;
- d*= SIGN(-middleEnergy);
-
- if(q>0)
- {
- d= d<0 ? 0 : d;
- d= d>q ? q : d;
- }
- else
- {
- d= d>0 ? 0 : d;
- d= d<q ? q : d;
- }
-
- src[l4]-= d;
- src[l5]+= d;
- }
- src++;
- }
-src-=8;
- for(x=0; x<8; x++)
- {
- int y;
- for(y=4; y<6; y++)
- {
- int d= src[x+y*stride] - tmp[x+(y-4)*8];
- int ad= ABS(d);
- static int max=0;
- static int sum=0;
- static int num=0;
- static int bias=0;
-
- if(max<ad) max=ad;
- sum+= ad>3 ? 1 : 0;
- if(ad>3)
- {
- src[0] = src[7] = src[stride*7] = src[(stride+1)*7]=255;
- }
- if(y==4) bias+=d;
- num++;
- if(num%1000000 == 0)
- {
- printf(" %d %d %d %d\n", num, sum, max, bias);
- }
- }
- }
-}
-*/
-#elif defined (HAVE_MMX)
- src+= stride*4;
- asm volatile(
- "pxor %%mm7, %%mm7 \n\t"
- "lea -40(%%"REG_SP"), %%"REG_c" \n\t" // make space for 4 8-byte vars
- "and "ALIGN_MASK", %%"REG_c" \n\t" // align
-// 0 1 2 3 4 5 6 7
-// %0 %0+%1 %0+2%1 eax+2%1 %0+4%1 eax+4%1 edx+%1 edx+2%1
-// %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1
-
- "movq (%0), %%mm0 \n\t"
- "movq %%mm0, %%mm1 \n\t"
- "punpcklbw %%mm7, %%mm0 \n\t" // low part of line 0
- "punpckhbw %%mm7, %%mm1 \n\t" // high part of line 0
-
- "movq (%0, %1), %%mm2 \n\t"
- "lea (%0, %1, 2), %%"REG_a" \n\t"
- "movq %%mm2, %%mm3 \n\t"
- "punpcklbw %%mm7, %%mm2 \n\t" // low part of line 1
- "punpckhbw %%mm7, %%mm3 \n\t" // high part of line 1
-
- "movq (%%"REG_a"), %%mm4 \n\t"
- "movq %%mm4, %%mm5 \n\t"
- "punpcklbw %%mm7, %%mm4 \n\t" // low part of line 2
- "punpckhbw %%mm7, %%mm5 \n\t" // high part of line 2
-
- "paddw %%mm0, %%mm0 \n\t" // 2L0
- "paddw %%mm1, %%mm1 \n\t" // 2H0
- "psubw %%mm4, %%mm2 \n\t" // L1 - L2
- "psubw %%mm5, %%mm3 \n\t" // H1 - H2
- "psubw %%mm2, %%mm0 \n\t" // 2L0 - L1 + L2
- "psubw %%mm3, %%mm1 \n\t" // 2H0 - H1 + H2
-
- "psllw $2, %%mm2 \n\t" // 4L1 - 4L2
- "psllw $2, %%mm3 \n\t" // 4H1 - 4H2
- "psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2
- "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2
-
- "movq (%%"REG_a", %1), %%mm2 \n\t"
- "movq %%mm2, %%mm3 \n\t"
- "punpcklbw %%mm7, %%mm2 \n\t" // L3
- "punpckhbw %%mm7, %%mm3 \n\t" // H3
-
- "psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2 - L3
- "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2 - H3
- "psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2 - 2L3
- "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2 - 2H3
- "movq %%mm0, (%%"REG_c") \n\t" // 2L0 - 5L1 + 5L2 - 2L3
- "movq %%mm1, 8(%%"REG_c") \n\t" // 2H0 - 5H1 + 5H2 - 2H3
-
- "movq (%%"REG_a", %1, 2), %%mm0 \n\t"
- "movq %%mm0, %%mm1 \n\t"
- "punpcklbw %%mm7, %%mm0 \n\t" // L4
- "punpckhbw %%mm7, %%mm1 \n\t" // H4
-
- "psubw %%mm0, %%mm2 \n\t" // L3 - L4
- "psubw %%mm1, %%mm3 \n\t" // H3 - H4
- "movq %%mm2, 16(%%"REG_c") \n\t" // L3 - L4
- "movq %%mm3, 24(%%"REG_c") \n\t" // H3 - H4
- "paddw %%mm4, %%mm4 \n\t" // 2L2
- "paddw %%mm5, %%mm5 \n\t" // 2H2
- "psubw %%mm2, %%mm4 \n\t" // 2L2 - L3 + L4
- "psubw %%mm3, %%mm5 \n\t" // 2H2 - H3 + H4
-
- "lea (%%"REG_a", %1), %0 \n\t"
- "psllw $2, %%mm2 \n\t" // 4L3 - 4L4
- "psllw $2, %%mm3 \n\t" // 4H3 - 4H4
- "psubw %%mm2, %%mm4 \n\t" // 2L2 - 5L3 + 5L4
- "psubw %%mm3, %%mm5 \n\t" // 2H2 - 5H3 + 5H4
-//50 opcodes so far
- "movq (%0, %1, 2), %%mm2 \n\t"
- "movq %%mm2, %%mm3 \n\t"
- "punpcklbw %%mm7, %%mm2 \n\t" // L5
- "punpckhbw %%mm7, %%mm3 \n\t" // H5
- "psubw %%mm2, %%mm4 \n\t" // 2L2 - 5L3 + 5L4 - L5
- "psubw %%mm3, %%mm5 \n\t" // 2H2 - 5H3 + 5H4 - H5
- "psubw %%mm2, %%mm4 \n\t" // 2L2 - 5L3 + 5L4 - 2L5
- "psubw %%mm3, %%mm5 \n\t" // 2H2 - 5H3 + 5H4 - 2H5
-
- "movq (%%"REG_a", %1, 4), %%mm6 \n\t"
- "punpcklbw %%mm7, %%mm6 \n\t" // L6
- "psubw %%mm6, %%mm2 \n\t" // L5 - L6
- "movq (%%"REG_a", %1, 4), %%mm6 \n\t"
- "punpckhbw %%mm7, %%mm6 \n\t" // H6
- "psubw %%mm6, %%mm3 \n\t" // H5 - H6
-
- "paddw %%mm0, %%mm0 \n\t" // 2L4
- "paddw %%mm1, %%mm1 \n\t" // 2H4
- "psubw %%mm2, %%mm0 \n\t" // 2L4 - L5 + L6
- "psubw %%mm3, %%mm1 \n\t" // 2H4 - H5 + H6
-
- "psllw $2, %%mm2 \n\t" // 4L5 - 4L6
- "psllw $2, %%mm3 \n\t" // 4H5 - 4H6
- "psubw %%mm2, %%mm0 \n\t" // 2L4 - 5L5 + 5L6
- "psubw %%mm3, %%mm1 \n\t" // 2H4 - 5H5 + 5H6
-
- "movq (%0, %1, 4), %%mm2 \n\t"
- "movq %%mm2, %%mm3 \n\t"
- "punpcklbw %%mm7, %%mm2 \n\t" // L7
- "punpckhbw %%mm7, %%mm3 \n\t" // H7
-
- "paddw %%mm2, %%mm2 \n\t" // 2L7
- "paddw %%mm3, %%mm3 \n\t" // 2H7
- "psubw %%mm2, %%mm0 \n\t" // 2L4 - 5L5 + 5L6 - 2L7
- "psubw %%mm3, %%mm1 \n\t" // 2H4 - 5H5 + 5H6 - 2H7
-
- "movq (%%"REG_c"), %%mm2 \n\t" // 2L0 - 5L1 + 5L2 - 2L3
- "movq 8(%%"REG_c"), %%mm3 \n\t" // 2H0 - 5H1 + 5H2 - 2H3
-
-#ifdef HAVE_MMX2
- "movq %%mm7, %%mm6 \n\t" // 0
- "psubw %%mm0, %%mm6 \n\t"
- "pmaxsw %%mm6, %%mm0 \n\t" // |2L4 - 5L5 + 5L6 - 2L7|
- "movq %%mm7, %%mm6 \n\t" // 0
- "psubw %%mm1, %%mm6 \n\t"
- "pmaxsw %%mm6, %%mm1 \n\t" // |2H4 - 5H5 + 5H6 - 2H7|
- "movq %%mm7, %%mm6 \n\t" // 0
- "psubw %%mm2, %%mm6 \n\t"
- "pmaxsw %%mm6, %%mm2 \n\t" // |2L0 - 5L1 + 5L2 - 2L3|
- "movq %%mm7, %%mm6 \n\t" // 0
- "psubw %%mm3, %%mm6 \n\t"
- "pmaxsw %%mm6, %%mm3 \n\t" // |2H0 - 5H1 + 5H2 - 2H3|
-#else
- "movq %%mm7, %%mm6 \n\t" // 0
- "pcmpgtw %%mm0, %%mm6 \n\t"
- "pxor %%mm6, %%mm0 \n\t"
- "psubw %%mm6, %%mm0 \n\t" // |2L4 - 5L5 + 5L6 - 2L7|
- "movq %%mm7, %%mm6 \n\t" // 0
- "pcmpgtw %%mm1, %%mm6 \n\t"
- "pxor %%mm6, %%mm1 \n\t"
- "psubw %%mm6, %%mm1 \n\t" // |2H4 - 5H5 + 5H6 - 2H7|
- "movq %%mm7, %%mm6 \n\t" // 0
- "pcmpgtw %%mm2, %%mm6 \n\t"
- "pxor %%mm6, %%mm2 \n\t"
- "psubw %%mm6, %%mm2 \n\t" // |2L0 - 5L1 + 5L2 - 2L3|
- "movq %%mm7, %%mm6 \n\t" // 0
- "pcmpgtw %%mm3, %%mm6 \n\t"
- "pxor %%mm6, %%mm3 \n\t"
- "psubw %%mm6, %%mm3 \n\t" // |2H0 - 5H1 + 5H2 - 2H3|
-#endif
-
-#ifdef HAVE_MMX2
- "pminsw %%mm2, %%mm0 \n\t"
- "pminsw %%mm3, %%mm1 \n\t"
-#else
- "movq %%mm0, %%mm6 \n\t"
- "psubusw %%mm2, %%mm6 \n\t"
- "psubw %%mm6, %%mm0 \n\t"
- "movq %%mm1, %%mm6 \n\t"
- "psubusw %%mm3, %%mm6 \n\t"
- "psubw %%mm6, %%mm1 \n\t"
-#endif
-
- "movd %2, %%mm2 \n\t" // QP
- "punpcklbw %%mm7, %%mm2 \n\t"
-
- "movq %%mm7, %%mm6 \n\t" // 0
- "pcmpgtw %%mm4, %%mm6 \n\t" // sign(2L2 - 5L3 + 5L4 - 2L5)
- "pxor %%mm6, %%mm4 \n\t"
- "psubw %%mm6, %%mm4 \n\t" // |2L2 - 5L3 + 5L4 - 2L5|
- "pcmpgtw %%mm5, %%mm7 \n\t" // sign(2H2 - 5H3 + 5H4 - 2H5)
- "pxor %%mm7, %%mm5 \n\t"
- "psubw %%mm7, %%mm5 \n\t" // |2H2 - 5H3 + 5H4 - 2H5|
-// 100 opcodes
- "psllw $3, %%mm2 \n\t" // 8QP
- "movq %%mm2, %%mm3 \n\t" // 8QP
- "pcmpgtw %%mm4, %%mm2 \n\t"
- "pcmpgtw %%mm5, %%mm3 \n\t"
- "pand %%mm2, %%mm4 \n\t"
- "pand %%mm3, %%mm5 \n\t"
-
-
- "psubusw %%mm0, %%mm4 \n\t" // hd
- "psubusw %%mm1, %%mm5 \n\t" // ld
-
-
- "movq "MANGLE(w05)", %%mm2 \n\t" // 5
- "pmullw %%mm2, %%mm4 \n\t"
- "pmullw %%mm2, %%mm5 \n\t"
- "movq "MANGLE(w20)", %%mm2 \n\t" // 32
- "paddw %%mm2, %%mm4 \n\t"
- "paddw %%mm2, %%mm5 \n\t"
- "psrlw $6, %%mm4 \n\t"
- "psrlw $6, %%mm5 \n\t"
-
- "movq 16(%%"REG_c"), %%mm0 \n\t" // L3 - L4
- "movq 24(%%"REG_c"), %%mm1 \n\t" // H3 - H4
-
- "pxor %%mm2, %%mm2 \n\t"
- "pxor %%mm3, %%mm3 \n\t"
-
- "pcmpgtw %%mm0, %%mm2 \n\t" // sign (L3-L4)
- "pcmpgtw %%mm1, %%mm3 \n\t" // sign (H3-H4)
- "pxor %%mm2, %%mm0 \n\t"
- "pxor %%mm3, %%mm1 \n\t"
- "psubw %%mm2, %%mm0 \n\t" // |L3-L4|
- "psubw %%mm3, %%mm1 \n\t" // |H3-H4|
- "psrlw $1, %%mm0 \n\t" // |L3 - L4|/2
- "psrlw $1, %%mm1 \n\t" // |H3 - H4|/2
-
- "pxor %%mm6, %%mm2 \n\t"
- "pxor %%mm7, %%mm3 \n\t"
- "pand %%mm2, %%mm4 \n\t"
- "pand %%mm3, %%mm5 \n\t"
-
-#ifdef HAVE_MMX2
- "pminsw %%mm0, %%mm4 \n\t"
- "pminsw %%mm1, %%mm5 \n\t"
-#else
- "movq %%mm4, %%mm2 \n\t"
- "psubusw %%mm0, %%mm2 \n\t"
- "psubw %%mm2, %%mm4 \n\t"
- "movq %%mm5, %%mm2 \n\t"
- "psubusw %%mm1, %%mm2 \n\t"
- "psubw %%mm2, %%mm5 \n\t"
-#endif
- "pxor %%mm6, %%mm4 \n\t"
- "pxor %%mm7, %%mm5 \n\t"
- "psubw %%mm6, %%mm4 \n\t"
- "psubw %%mm7, %%mm5 \n\t"
- "packsswb %%mm5, %%mm4 \n\t"
- "movq (%0), %%mm0 \n\t"
- "paddb %%mm4, %%mm0 \n\t"
- "movq %%mm0, (%0) \n\t"
- "movq (%0, %1), %%mm0 \n\t"
- "psubb %%mm4, %%mm0 \n\t"
- "movq %%mm0, (%0, %1) \n\t"
-
- : "+r" (src)
- : "r" ((long)stride), "m" (c->pQPb)
- : "%"REG_a, "%"REG_c
- );
-#else //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
- const int l1= stride;
- const int l2= stride + l1;
- const int l3= stride + l2;
- const int l4= stride + l3;
- const int l5= stride + l4;
- const int l6= stride + l5;
- const int l7= stride + l6;
- const int l8= stride + l7;
-// const int l9= stride + l8;
- int x;
- src+= stride*3;
- for(x=0; x<BLOCK_SIZE; x++)
- {
- const int middleEnergy= 5*(src[l5] - src[l4]) + 2*(src[l3] - src[l6]);
- if(ABS(middleEnergy) < 8*c->QP)
- {
- const int q=(src[l4] - src[l5])/2;
- const int leftEnergy= 5*(src[l3] - src[l2]) + 2*(src[l1] - src[l4]);
- const int rightEnergy= 5*(src[l7] - src[l6]) + 2*(src[l5] - src[l8]);
-
- int d= ABS(middleEnergy) - MIN( ABS(leftEnergy), ABS(rightEnergy) );
- d= MAX(d, 0);
-
- d= (5*d + 32) >> 6;
- d*= SIGN(-middleEnergy);
-
- if(q>0)
- {
- d= d<0 ? 0 : d;
- d= d>q ? q : d;
- }
- else
- {
- d= d>0 ? 0 : d;
- d= d<q ? q : d;
- }
-
- src[l4]-= d;
- src[l5]+= d;
- }
- src++;
- }
-#endif //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
-}
-#endif //HAVE_ALTIVEC
-
-#ifndef HAVE_ALTIVEC
-static inline void RENAME(dering)(uint8_t src[], int stride, PPContext *c)
-{
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
- asm volatile(
- "pxor %%mm6, %%mm6 \n\t"
- "pcmpeqb %%mm7, %%mm7 \n\t"
- "movq %2, %%mm0 \n\t"
- "punpcklbw %%mm6, %%mm0 \n\t"
- "psrlw $1, %%mm0 \n\t"
- "psubw %%mm7, %%mm0 \n\t"
- "packuswb %%mm0, %%mm0 \n\t"
- "movq %%mm0, %3 \n\t"
-
- "lea (%0, %1), %%"REG_a" \n\t"
- "lea (%%"REG_a", %1, 4), %%"REG_d" \n\t"
-
-// 0 1 2 3 4 5 6 7 8 9
-// %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1
-
-#undef FIND_MIN_MAX
-#ifdef HAVE_MMX2
-#define REAL_FIND_MIN_MAX(addr)\
- "movq " #addr ", %%mm0 \n\t"\
- "pminub %%mm0, %%mm7 \n\t"\
- "pmaxub %%mm0, %%mm6 \n\t"
-#else
-#define REAL_FIND_MIN_MAX(addr)\
- "movq " #addr ", %%mm0 \n\t"\
- "movq %%mm7, %%mm1 \n\t"\
- "psubusb %%mm0, %%mm6 \n\t"\
- "paddb %%mm0, %%mm6 \n\t"\
- "psubusb %%mm0, %%mm1 \n\t"\
- "psubb %%mm1, %%mm7 \n\t"
-#endif
-#define FIND_MIN_MAX(addr) REAL_FIND_MIN_MAX(addr)
-
-FIND_MIN_MAX((%%REGa))
-FIND_MIN_MAX((%%REGa, %1))
-FIND_MIN_MAX((%%REGa, %1, 2))
-FIND_MIN_MAX((%0, %1, 4))
-FIND_MIN_MAX((%%REGd))
-FIND_MIN_MAX((%%REGd, %1))
-FIND_MIN_MAX((%%REGd, %1, 2))
-FIND_MIN_MAX((%0, %1, 8))
-
- "movq %%mm7, %%mm4 \n\t"
- "psrlq $8, %%mm7 \n\t"
-#ifdef HAVE_MMX2
- "pminub %%mm4, %%mm7 \n\t" // min of pixels
- "pshufw $0xF9, %%mm7, %%mm4 \n\t"
- "pminub %%mm4, %%mm7 \n\t" // min of pixels
- "pshufw $0xFE, %%mm7, %%mm4 \n\t"
- "pminub %%mm4, %%mm7 \n\t"
-#else
- "movq %%mm7, %%mm1 \n\t"
- "psubusb %%mm4, %%mm1 \n\t"
- "psubb %%mm1, %%mm7 \n\t"
- "movq %%mm7, %%mm4 \n\t"
- "psrlq $16, %%mm7 \n\t"
- "movq %%mm7, %%mm1 \n\t"
- "psubusb %%mm4, %%mm1 \n\t"
- "psubb %%mm1, %%mm7 \n\t"
- "movq %%mm7, %%mm4 \n\t"
- "psrlq $32, %%mm7 \n\t"
- "movq %%mm7, %%mm1 \n\t"
- "psubusb %%mm4, %%mm1 \n\t"
- "psubb %%mm1, %%mm7 \n\t"
-#endif
-
-
- "movq %%mm6, %%mm4 \n\t"
- "psrlq $8, %%mm6 \n\t"
-#ifdef HAVE_MMX2
- "pmaxub %%mm4, %%mm6 \n\t" // max of pixels
- "pshufw $0xF9, %%mm6, %%mm4 \n\t"
- "pmaxub %%mm4, %%mm6 \n\t"
- "pshufw $0xFE, %%mm6, %%mm4 \n\t"
- "pmaxub %%mm4, %%mm6 \n\t"
-#else
- "psubusb %%mm4, %%mm6 \n\t"
- "paddb %%mm4, %%mm6 \n\t"
- "movq %%mm6, %%mm4 \n\t"
- "psrlq $16, %%mm6 \n\t"
- "psubusb %%mm4, %%mm6 \n\t"
- "paddb %%mm4, %%mm6 \n\t"
- "movq %%mm6, %%mm4 \n\t"
- "psrlq $32, %%mm6 \n\t"
- "psubusb %%mm4, %%mm6 \n\t"
- "paddb %%mm4, %%mm6 \n\t"
-#endif
- "movq %%mm6, %%mm0 \n\t" // max
- "psubb %%mm7, %%mm6 \n\t" // max - min
- "movd %%mm6, %%ecx \n\t"
- "cmpb "MANGLE(deringThreshold)", %%cl \n\t"
- " jb 1f \n\t"
- "lea -24(%%"REG_SP"), %%"REG_c" \n\t"
- "and "ALIGN_MASK", %%"REG_c" \n\t"
- PAVGB(%%mm0, %%mm7) // a=(max + min)/2
- "punpcklbw %%mm7, %%mm7 \n\t"
- "punpcklbw %%mm7, %%mm7 \n\t"
- "punpcklbw %%mm7, %%mm7 \n\t"
- "movq %%mm7, (%%"REG_c") \n\t"
-
- "movq (%0), %%mm0 \n\t" // L10
- "movq %%mm0, %%mm1 \n\t" // L10
- "movq %%mm0, %%mm2 \n\t" // L10
- "psllq $8, %%mm1 \n\t"
- "psrlq $8, %%mm2 \n\t"
- "movd -4(%0), %%mm3 \n\t"
- "movd 8(%0), %%mm4 \n\t"
- "psrlq $24, %%mm3 \n\t"
- "psllq $56, %%mm4 \n\t"
- "por %%mm3, %%mm1 \n\t" // L00
- "por %%mm4, %%mm2 \n\t" // L20
- "movq %%mm1, %%mm3 \n\t" // L00
- PAVGB(%%mm2, %%mm1) // (L20 + L00)/2
- PAVGB(%%mm0, %%mm1) // (L20 + L00 + 2L10)/4
- "psubusb %%mm7, %%mm0 \n\t"
- "psubusb %%mm7, %%mm2 \n\t"
- "psubusb %%mm7, %%mm3 \n\t"
- "pcmpeqb "MANGLE(b00)", %%mm0 \n\t" // L10 > a ? 0 : -1
- "pcmpeqb "MANGLE(b00)", %%mm2 \n\t" // L20 > a ? 0 : -1
- "pcmpeqb "MANGLE(b00)", %%mm3 \n\t" // L00 > a ? 0 : -1
- "paddb %%mm2, %%mm0 \n\t"
- "paddb %%mm3, %%mm0 \n\t"
-
- "movq (%%"REG_a"), %%mm2 \n\t" // L11
- "movq %%mm2, %%mm3 \n\t" // L11
- "movq %%mm2, %%mm4 \n\t" // L11
- "psllq $8, %%mm3 \n\t"
- "psrlq $8, %%mm4 \n\t"
- "movd -4(%%"REG_a"), %%mm5 \n\t"
- "movd 8(%%"REG_a"), %%mm6 \n\t"
- "psrlq $24, %%mm5 \n\t"
- "psllq $56, %%mm6 \n\t"
- "por %%mm5, %%mm3 \n\t" // L01
- "por %%mm6, %%mm4 \n\t" // L21
- "movq %%mm3, %%mm5 \n\t" // L01
- PAVGB(%%mm4, %%mm3) // (L21 + L01)/2
- PAVGB(%%mm2, %%mm3) // (L21 + L01 + 2L11)/4
- "psubusb %%mm7, %%mm2 \n\t"
- "psubusb %%mm7, %%mm4 \n\t"
- "psubusb %%mm7, %%mm5 \n\t"
- "pcmpeqb "MANGLE(b00)", %%mm2 \n\t" // L11 > a ? 0 : -1
- "pcmpeqb "MANGLE(b00)", %%mm4 \n\t" // L21 > a ? 0 : -1
- "pcmpeqb "MANGLE(b00)", %%mm5 \n\t" // L01 > a ? 0 : -1
- "paddb %%mm4, %%mm2 \n\t"
- "paddb %%mm5, %%mm2 \n\t"
-// 0, 2, 3, 1
-#define REAL_DERING_CORE(dst,src,ppsx,psx,sx,pplx,plx,lx,t0,t1) \
- "movq " #src ", " #sx " \n\t" /* src[0] */\
- "movq " #sx ", " #lx " \n\t" /* src[0] */\
- "movq " #sx ", " #t0 " \n\t" /* src[0] */\
- "psllq $8, " #lx " \n\t"\
- "psrlq $8, " #t0 " \n\t"\
- "movd -4" #src ", " #t1 " \n\t"\
- "psrlq $24, " #t1 " \n\t"\
- "por " #t1 ", " #lx " \n\t" /* src[-1] */\
- "movd 8" #src ", " #t1 " \n\t"\
- "psllq $56, " #t1 " \n\t"\
- "por " #t1 ", " #t0 " \n\t" /* src[+1] */\
- "movq " #lx ", " #t1 " \n\t" /* src[-1] */\
- PAVGB(t0, lx) /* (src[-1] + src[+1])/2 */\
- PAVGB(sx, lx) /* (src[-1] + 2src[0] + src[+1])/4 */\
- PAVGB(lx, pplx) \
- "movq " #lx ", 8(%%"REG_c") \n\t"\
- "movq (%%"REG_c"), " #lx " \n\t"\
- "psubusb " #lx ", " #t1 " \n\t"\
- "psubusb " #lx ", " #t0 " \n\t"\
- "psubusb " #lx ", " #sx " \n\t"\
- "movq "MANGLE(b00)", " #lx " \n\t"\
- "pcmpeqb " #lx ", " #t1 " \n\t" /* src[-1] > a ? 0 : -1*/\
- "pcmpeqb " #lx ", " #t0 " \n\t" /* src[+1] > a ? 0 : -1*/\
- "pcmpeqb " #lx ", " #sx " \n\t" /* src[0] > a ? 0 : -1*/\
- "paddb " #t1 ", " #t0 " \n\t"\
- "paddb " #t0 ", " #sx " \n\t"\
-\
- PAVGB(plx, pplx) /* filtered */\
- "movq " #dst ", " #t0 " \n\t" /* dst */\
- "movq " #t0 ", " #t1 " \n\t" /* dst */\
- "psubusb %3, " #t0 " \n\t"\
- "paddusb %3, " #t1 " \n\t"\
- PMAXUB(t0, pplx)\
- PMINUB(t1, pplx, t0)\
- "paddb " #sx ", " #ppsx " \n\t"\
- "paddb " #psx ", " #ppsx " \n\t"\
- "#paddb "MANGLE(b02)", " #ppsx " \n\t"\
- "pand "MANGLE(b08)", " #ppsx " \n\t"\
- "pcmpeqb " #lx ", " #ppsx " \n\t"\
- "pand " #ppsx ", " #pplx " \n\t"\
- "pandn " #dst ", " #ppsx " \n\t"\
- "por " #pplx ", " #ppsx " \n\t"\
- "movq " #ppsx ", " #dst " \n\t"\
- "movq 8(%%"REG_c"), " #lx " \n\t"
-
-#define DERING_CORE(dst,src,ppsx,psx,sx,pplx,plx,lx,t0,t1) \
- REAL_DERING_CORE(dst,src,ppsx,psx,sx,pplx,plx,lx,t0,t1)
-/*
-0000000
-1111111
-
-1111110
-1111101
-1111100
-1111011
-1111010
-1111001
-
-1111000
-1110111
-
-*/
-//DERING_CORE(dst ,src ,ppsx ,psx ,sx ,pplx ,plx ,lx ,t0 ,t1)
-DERING_CORE((%%REGa) ,(%%REGa, %1) ,%%mm0,%%mm2,%%mm4,%%mm1,%%mm3,%%mm5,%%mm6,%%mm7)
-DERING_CORE((%%REGa, %1) ,(%%REGa, %1, 2),%%mm2,%%mm4,%%mm0,%%mm3,%%mm5,%%mm1,%%mm6,%%mm7)
-DERING_CORE((%%REGa, %1, 2),(%0, %1, 4) ,%%mm4,%%mm0,%%mm2,%%mm5,%%mm1,%%mm3,%%mm6,%%mm7)
-DERING_CORE((%0, %1, 4) ,(%%REGd) ,%%mm0,%%mm2,%%mm4,%%mm1,%%mm3,%%mm5,%%mm6,%%mm7)
-DERING_CORE((%%REGd) ,(%%REGd, %1) ,%%mm2,%%mm4,%%mm0,%%mm3,%%mm5,%%mm1,%%mm6,%%mm7)
-DERING_CORE((%%REGd, %1) ,(%%REGd, %1, 2),%%mm4,%%mm0,%%mm2,%%mm5,%%mm1,%%mm3,%%mm6,%%mm7)
-DERING_CORE((%%REGd, %1, 2),(%0, %1, 8) ,%%mm0,%%mm2,%%mm4,%%mm1,%%mm3,%%mm5,%%mm6,%%mm7)
-DERING_CORE((%0, %1, 8) ,(%%REGd, %1, 4),%%mm2,%%mm4,%%mm0,%%mm3,%%mm5,%%mm1,%%mm6,%%mm7)
-
- "1: \n\t"
- : : "r" (src), "r" ((long)stride), "m" (c->pQPb), "m"(c->pQPb2)
- : "%"REG_a, "%"REG_d, "%"REG_c
- );
-#else //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
- int y;
- int min=255;
- int max=0;
- int avg;
- uint8_t *p;
- int s[10];
- const int QP2= c->QP/2 + 1;
-
- for(y=1; y<9; y++)
- {
- int x;
- p= src + stride*y;
- for(x=1; x<9; x++)
- {
- p++;
- if(*p > max) max= *p;
- if(*p < min) min= *p;
- }
- }
- avg= (min + max + 1)>>1;
-
- if(max - min <deringThreshold) return;
-
- for(y=0; y<10; y++)
- {
- int t = 0;
-
- if(src[stride*y + 0] > avg) t+= 1;
- if(src[stride*y + 1] > avg) t+= 2;
- if(src[stride*y + 2] > avg) t+= 4;
- if(src[stride*y + 3] > avg) t+= 8;
- if(src[stride*y + 4] > avg) t+= 16;
- if(src[stride*y + 5] > avg) t+= 32;
- if(src[stride*y + 6] > avg) t+= 64;
- if(src[stride*y + 7] > avg) t+= 128;
- if(src[stride*y + 8] > avg) t+= 256;
- if(src[stride*y + 9] > avg) t+= 512;
-
- t |= (~t)<<16;
- t &= (t<<1) & (t>>1);
- s[y] = t;
- }
-
- for(y=1; y<9; y++)
- {
- int t = s[y-1] & s[y] & s[y+1];
- t|= t>>16;
- s[y-1]= t;
- }
-
- for(y=1; y<9; y++)
- {
- int x;
- int t = s[y-1];
-
- p= src + stride*y;
- for(x=1; x<9; x++)
- {
- p++;
- if(t & (1<<x))
- {
- int f= (*(p-stride-1)) + 2*(*(p-stride)) + (*(p-stride+1))
- +2*(*(p -1)) + 4*(*p ) + 2*(*(p +1))
- +(*(p+stride-1)) + 2*(*(p+stride)) + (*(p+stride+1));
- f= (f + 8)>>4;
-
-#ifdef DEBUG_DERING_THRESHOLD
- asm volatile("emms\n\t":);
- {
- static long long numPixels=0;
- if(x!=1 && x!=8 && y!=1 && y!=8) numPixels++;
-// if((max-min)<20 || (max-min)*QP<200)
-// if((max-min)*QP < 500)
-// if(max-min<QP/2)
- if(max-min < 20)
- {
- static int numSkiped=0;
- static int errorSum=0;
- static int worstQP=0;
- static int worstRange=0;
- static int worstDiff=0;
- int diff= (f - *p);
- int absDiff= ABS(diff);
- int error= diff*diff;
-
- if(x==1 || x==8 || y==1 || y==8) continue;
-
- numSkiped++;
- if(absDiff > worstDiff)
- {
- worstDiff= absDiff;
- worstQP= QP;
- worstRange= max-min;
- }
- errorSum+= error;
-
- if(1024LL*1024LL*1024LL % numSkiped == 0)
- {
- printf( "sum:%1.3f, skip:%d, wQP:%d, "
- "wRange:%d, wDiff:%d, relSkip:%1.3f\n",
- (float)errorSum/numSkiped, numSkiped, worstQP, worstRange,
- worstDiff, (float)numSkiped/numPixels);
- }
- }
- }
-#endif
- if (*p + QP2 < f) *p= *p + QP2;
- else if(*p - QP2 > f) *p= *p - QP2;
- else *p=f;
- }
- }
- }
-#ifdef DEBUG_DERING_THRESHOLD
- if(max-min < 20)
- {
- for(y=1; y<9; y++)
- {
- int x;
- int t = 0;
- p= src + stride*y;
- for(x=1; x<9; x++)
- {
- p++;
- *p = MIN(*p + 20, 255);
- }
- }
-// src[0] = src[7]=src[stride*7]=src[stride*7 + 7]=255;
- }
-#endif
-#endif //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
-}
-#endif //HAVE_ALTIVEC
-
-/**
- * Deinterlaces the given block by linearly interpolating every second line.
- * will be called for every 8x8 block and can read & write from line 4-15
- * lines 0-3 have been passed through the deblock / dering filters allready, but can be read too
- * lines 4-12 will be read into the deblocking filter and should be deinterlaced
- */
-static inline void RENAME(deInterlaceInterpolateLinear)(uint8_t src[], int stride)
-{
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
- src+= 4*stride;
- asm volatile(
- "lea (%0, %1), %%"REG_a" \n\t"
- "lea (%%"REG_a", %1, 4), %%"REG_c" \n\t"
-// 0 1 2 3 4 5 6 7 8 9
-// %0 eax eax+%1 eax+2%1 %0+4%1 ecx ecx+%1 ecx+2%1 %0+8%1 ecx+4%1
-
- "movq (%0), %%mm0 \n\t"
- "movq (%%"REG_a", %1), %%mm1 \n\t"
- PAVGB(%%mm1, %%mm0)
- "movq %%mm0, (%%"REG_a") \n\t"
- "movq (%0, %1, 4), %%mm0 \n\t"
- PAVGB(%%mm0, %%mm1)
- "movq %%mm1, (%%"REG_a", %1, 2) \n\t"
- "movq (%%"REG_c", %1), %%mm1 \n\t"
- PAVGB(%%mm1, %%mm0)
- "movq %%mm0, (%%"REG_c") \n\t"
- "movq (%0, %1, 8), %%mm0 \n\t"
- PAVGB(%%mm0, %%mm1)
- "movq %%mm1, (%%"REG_c", %1, 2) \n\t"
-
- : : "r" (src), "r" ((long)stride)
- : "%"REG_a, "%"REG_c
- );
-#else
- int a, b, x;
- src+= 4*stride;
-
- for(x=0; x<2; x++){
- a= *(uint32_t*)&src[stride*0];
- b= *(uint32_t*)&src[stride*2];
- *(uint32_t*)&src[stride*1]= (a|b) - (((a^b)&0xFEFEFEFEUL)>>1);
- a= *(uint32_t*)&src[stride*4];
- *(uint32_t*)&src[stride*3]= (a|b) - (((a^b)&0xFEFEFEFEUL)>>1);
- b= *(uint32_t*)&src[stride*6];
- *(uint32_t*)&src[stride*5]= (a|b) - (((a^b)&0xFEFEFEFEUL)>>1);
- a= *(uint32_t*)&src[stride*8];
- *(uint32_t*)&src[stride*7]= (a|b) - (((a^b)&0xFEFEFEFEUL)>>1);
- src += 4;
- }
-#endif
-}
-
-/**
- * Deinterlaces the given block by cubic interpolating every second line.
- * will be called for every 8x8 block and can read & write from line 4-15
- * lines 0-3 have been passed through the deblock / dering filters allready, but can be read too
- * lines 4-12 will be read into the deblocking filter and should be deinterlaced
- * this filter will read lines 3-15 and write 7-13
- */
-static inline void RENAME(deInterlaceInterpolateCubic)(uint8_t src[], int stride)
-{
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
- src+= stride*3;
- asm volatile(
- "lea (%0, %1), %%"REG_a" \n\t"
- "lea (%%"REG_a", %1, 4), %%"REG_d" \n\t"
- "lea (%%"REG_d", %1, 4), %%"REG_c" \n\t"
- "add %1, %%"REG_c" \n\t"
- "pxor %%mm7, %%mm7 \n\t"
-// 0 1 2 3 4 5 6 7 8 9 10
-// %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1 ecx
-
-#define REAL_DEINT_CUBIC(a,b,c,d,e)\
- "movq " #a ", %%mm0 \n\t"\
- "movq " #b ", %%mm1 \n\t"\
- "movq " #d ", %%mm2 \n\t"\
- "movq " #e ", %%mm3 \n\t"\
- PAVGB(%%mm2, %%mm1) /* (b+d) /2 */\
- PAVGB(%%mm3, %%mm0) /* a(a+e) /2 */\
- "movq %%mm0, %%mm2 \n\t"\
- "punpcklbw %%mm7, %%mm0 \n\t"\
- "punpckhbw %%mm7, %%mm2 \n\t"\
- "movq %%mm1, %%mm3 \n\t"\
- "punpcklbw %%mm7, %%mm1 \n\t"\
- "punpckhbw %%mm7, %%mm3 \n\t"\
- "psubw %%mm1, %%mm0 \n\t" /* L(a+e - (b+d))/2 */\
- "psubw %%mm3, %%mm2 \n\t" /* H(a+e - (b+d))/2 */\
- "psraw $3, %%mm0 \n\t" /* L(a+e - (b+d))/16 */\
- "psraw $3, %%mm2 \n\t" /* H(a+e - (b+d))/16 */\
- "psubw %%mm0, %%mm1 \n\t" /* L(9b + 9d - a - e)/16 */\
- "psubw %%mm2, %%mm3 \n\t" /* H(9b + 9d - a - e)/16 */\
- "packuswb %%mm3, %%mm1 \n\t"\
- "movq %%mm1, " #c " \n\t"
-#define DEINT_CUBIC(a,b,c,d,e) REAL_DEINT_CUBIC(a,b,c,d,e)
-
-DEINT_CUBIC((%0) , (%%REGa, %1), (%%REGa, %1, 2), (%0, %1, 4) , (%%REGd, %1))
-DEINT_CUBIC((%%REGa, %1), (%0, %1, 4) , (%%REGd) , (%%REGd, %1), (%0, %1, 8))
-DEINT_CUBIC((%0, %1, 4) , (%%REGd, %1), (%%REGd, %1, 2), (%0, %1, 8) , (%%REGc))
-DEINT_CUBIC((%%REGd, %1), (%0, %1, 8) , (%%REGd, %1, 4), (%%REGc) , (%%REGc, %1, 2))
-
- : : "r" (src), "r" ((long)stride)
- : "%"REG_a, "%"REG_d, "%"REG_c
- );
-#else //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
- int x;
- src+= stride*3;
- for(x=0; x<8; x++)
- {
- src[stride*3] = CLIP((-src[0] + 9*src[stride*2] + 9*src[stride*4] - src[stride*6])>>4);
- src[stride*5] = CLIP((-src[stride*2] + 9*src[stride*4] + 9*src[stride*6] - src[stride*8])>>4);
- src[stride*7] = CLIP((-src[stride*4] + 9*src[stride*6] + 9*src[stride*8] - src[stride*10])>>4);
- src[stride*9] = CLIP((-src[stride*6] + 9*src[stride*8] + 9*src[stride*10] - src[stride*12])>>4);
- src++;
- }
-#endif //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
-}
-
-/**
- * Deinterlaces the given block by filtering every second line with a (-1 4 2 4 -1) filter.
- * will be called for every 8x8 block and can read & write from line 4-15
- * lines 0-3 have been passed through the deblock / dering filters allready, but can be read too
- * lines 4-12 will be read into the deblocking filter and should be deinterlaced
- * this filter will read lines 4-13 and write 5-11
- */
-static inline void RENAME(deInterlaceFF)(uint8_t src[], int stride, uint8_t *tmp)
-{
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
- src+= stride*4;
- asm volatile(
- "lea (%0, %1), %%"REG_a" \n\t"
- "lea (%%"REG_a", %1, 4), %%"REG_d" \n\t"
- "pxor %%mm7, %%mm7 \n\t"
- "movq (%2), %%mm0 \n\t"
-// 0 1 2 3 4 5 6 7 8 9 10
-// %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1 ecx
-
-#define REAL_DEINT_FF(a,b,c,d)\
- "movq " #a ", %%mm1 \n\t"\
- "movq " #b ", %%mm2 \n\t"\
- "movq " #c ", %%mm3 \n\t"\
- "movq " #d ", %%mm4 \n\t"\
- PAVGB(%%mm3, %%mm1) \
- PAVGB(%%mm4, %%mm0) \
- "movq %%mm0, %%mm3 \n\t"\
- "punpcklbw %%mm7, %%mm0 \n\t"\
- "punpckhbw %%mm7, %%mm3 \n\t"\
- "movq %%mm1, %%mm4 \n\t"\
- "punpcklbw %%mm7, %%mm1 \n\t"\
- "punpckhbw %%mm7, %%mm4 \n\t"\
- "psllw $2, %%mm1 \n\t"\
- "psllw $2, %%mm4 \n\t"\
- "psubw %%mm0, %%mm1 \n\t"\
- "psubw %%mm3, %%mm4 \n\t"\
- "movq %%mm2, %%mm5 \n\t"\
- "movq %%mm2, %%mm0 \n\t"\
- "punpcklbw %%mm7, %%mm2 \n\t"\
- "punpckhbw %%mm7, %%mm5 \n\t"\
- "paddw %%mm2, %%mm1 \n\t"\
- "paddw %%mm5, %%mm4 \n\t"\
- "psraw $2, %%mm1 \n\t"\
- "psraw $2, %%mm4 \n\t"\
- "packuswb %%mm4, %%mm1 \n\t"\
- "movq %%mm1, " #b " \n\t"\
-
-#define DEINT_FF(a,b,c,d) REAL_DEINT_FF(a,b,c,d)
-
-DEINT_FF((%0) , (%%REGa) , (%%REGa, %1), (%%REGa, %1, 2))
-DEINT_FF((%%REGa, %1), (%%REGa, %1, 2), (%0, %1, 4) , (%%REGd) )
-DEINT_FF((%0, %1, 4) , (%%REGd) , (%%REGd, %1), (%%REGd, %1, 2))
-DEINT_FF((%%REGd, %1), (%%REGd, %1, 2), (%0, %1, 8) , (%%REGd, %1, 4))
-
- "movq %%mm0, (%2) \n\t"
- : : "r" (src), "r" ((long)stride), "r"(tmp)
- : "%"REG_a, "%"REG_d
- );
-#else //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
- int x;
- src+= stride*4;
- for(x=0; x<8; x++)
- {
- int t1= tmp[x];
- int t2= src[stride*1];
-
- src[stride*1]= CLIP((-t1 + 4*src[stride*0] + 2*t2 + 4*src[stride*2] - src[stride*3] + 4)>>3);
- t1= src[stride*4];
- src[stride*3]= CLIP((-t2 + 4*src[stride*2] + 2*t1 + 4*src[stride*4] - src[stride*5] + 4)>>3);
- t2= src[stride*6];
- src[stride*5]= CLIP((-t1 + 4*src[stride*4] + 2*t2 + 4*src[stride*6] - src[stride*7] + 4)>>3);
- t1= src[stride*8];
- src[stride*7]= CLIP((-t2 + 4*src[stride*6] + 2*t1 + 4*src[stride*8] - src[stride*9] + 4)>>3);
- tmp[x]= t1;
-
- src++;
- }
-#endif //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
-}
-
-/**
- * Deinterlaces the given block by filtering every line with a (-1 2 6 2 -1) filter.
- * will be called for every 8x8 block and can read & write from line 4-15
- * lines 0-3 have been passed through the deblock / dering filters allready, but can be read too
- * lines 4-12 will be read into the deblocking filter and should be deinterlaced
- * this filter will read lines 4-13 and write 4-11
- */
-static inline void RENAME(deInterlaceL5)(uint8_t src[], int stride, uint8_t *tmp, uint8_t *tmp2)
-{
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
- src+= stride*4;
- asm volatile(
- "lea (%0, %1), %%"REG_a" \n\t"
- "lea (%%"REG_a", %1, 4), %%"REG_d" \n\t"
- "pxor %%mm7, %%mm7 \n\t"
- "movq (%2), %%mm0 \n\t"
- "movq (%3), %%mm1 \n\t"
-// 0 1 2 3 4 5 6 7 8 9 10
-// %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1 ecx
-
-#define REAL_DEINT_L5(t1,t2,a,b,c)\
- "movq " #a ", %%mm2 \n\t"\
- "movq " #b ", %%mm3 \n\t"\
- "movq " #c ", %%mm4 \n\t"\
- PAVGB(t2, %%mm3) \
- PAVGB(t1, %%mm4) \
- "movq %%mm2, %%mm5 \n\t"\
- "movq %%mm2, " #t1 " \n\t"\
- "punpcklbw %%mm7, %%mm2 \n\t"\
- "punpckhbw %%mm7, %%mm5 \n\t"\
- "movq %%mm2, %%mm6 \n\t"\
- "paddw %%mm2, %%mm2 \n\t"\
- "paddw %%mm6, %%mm2 \n\t"\
- "movq %%mm5, %%mm6 \n\t"\
- "paddw %%mm5, %%mm5 \n\t"\
- "paddw %%mm6, %%mm5 \n\t"\
- "movq %%mm3, %%mm6 \n\t"\
- "punpcklbw %%mm7, %%mm3 \n\t"\
- "punpckhbw %%mm7, %%mm6 \n\t"\
- "paddw %%mm3, %%mm3 \n\t"\
- "paddw %%mm6, %%mm6 \n\t"\
- "paddw %%mm3, %%mm2 \n\t"\
- "paddw %%mm6, %%mm5 \n\t"\
- "movq %%mm4, %%mm6 \n\t"\
- "punpcklbw %%mm7, %%mm4 \n\t"\
- "punpckhbw %%mm7, %%mm6 \n\t"\
- "psubw %%mm4, %%mm2 \n\t"\
- "psubw %%mm6, %%mm5 \n\t"\
- "psraw $2, %%mm2 \n\t"\
- "psraw $2, %%mm5 \n\t"\
- "packuswb %%mm5, %%mm2 \n\t"\
- "movq %%mm2, " #a " \n\t"\
-
-#define DEINT_L5(t1,t2,a,b,c) REAL_DEINT_L5(t1,t2,a,b,c)
-
-DEINT_L5(%%mm0, %%mm1, (%0) , (%%REGa) , (%%REGa, %1) )
-DEINT_L5(%%mm1, %%mm0, (%%REGa) , (%%REGa, %1) , (%%REGa, %1, 2))
-DEINT_L5(%%mm0, %%mm1, (%%REGa, %1) , (%%REGa, %1, 2), (%0, %1, 4) )
-DEINT_L5(%%mm1, %%mm0, (%%REGa, %1, 2), (%0, %1, 4) , (%%REGd) )
-DEINT_L5(%%mm0, %%mm1, (%0, %1, 4) , (%%REGd) , (%%REGd, %1) )
-DEINT_L5(%%mm1, %%mm0, (%%REGd) , (%%REGd, %1) , (%%REGd, %1, 2))
-DEINT_L5(%%mm0, %%mm1, (%%REGd, %1) , (%%REGd, %1, 2), (%0, %1, 8) )
-DEINT_L5(%%mm1, %%mm0, (%%REGd, %1, 2), (%0, %1, 8) , (%%REGd, %1, 4))
-
- "movq %%mm0, (%2) \n\t"
- "movq %%mm1, (%3) \n\t"
- : : "r" (src), "r" ((long)stride), "r"(tmp), "r"(tmp2)
- : "%"REG_a, "%"REG_d
- );
-#else //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
- int x;
- src+= stride*4;
- for(x=0; x<8; x++)
- {
- int t1= tmp[x];
- int t2= tmp2[x];
- int t3= src[0];
-
- src[stride*0]= CLIP((-(t1 + src[stride*2]) + 2*(t2 + src[stride*1]) + 6*t3 + 4)>>3);
- t1= src[stride*1];
- src[stride*1]= CLIP((-(t2 + src[stride*3]) + 2*(t3 + src[stride*2]) + 6*t1 + 4)>>3);
- t2= src[stride*2];
- src[stride*2]= CLIP((-(t3 + src[stride*4]) + 2*(t1 + src[stride*3]) + 6*t2 + 4)>>3);
- t3= src[stride*3];
- src[stride*3]= CLIP((-(t1 + src[stride*5]) + 2*(t2 + src[stride*4]) + 6*t3 + 4)>>3);
- t1= src[stride*4];
- src[stride*4]= CLIP((-(t2 + src[stride*6]) + 2*(t3 + src[stride*5]) + 6*t1 + 4)>>3);
- t2= src[stride*5];
- src[stride*5]= CLIP((-(t3 + src[stride*7]) + 2*(t1 + src[stride*6]) + 6*t2 + 4)>>3);
- t3= src[stride*6];
- src[stride*6]= CLIP((-(t1 + src[stride*8]) + 2*(t2 + src[stride*7]) + 6*t3 + 4)>>3);
- t1= src[stride*7];
- src[stride*7]= CLIP((-(t2 + src[stride*9]) + 2*(t3 + src[stride*8]) + 6*t1 + 4)>>3);
-
- tmp[x]= t3;
- tmp2[x]= t1;
-
- src++;
- }
-#endif //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
-}
-
-/**
- * Deinterlaces the given block by filtering all lines with a (1 2 1) filter.
- * will be called for every 8x8 block and can read & write from line 4-15
- * lines 0-3 have been passed through the deblock / dering filters allready, but can be read too
- * lines 4-12 will be read into the deblocking filter and should be deinterlaced
- * this filter will read lines 4-13 and write 4-11
- */
-static inline void RENAME(deInterlaceBlendLinear)(uint8_t src[], int stride, uint8_t *tmp)
-{
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
- src+= 4*stride;
- asm volatile(
- "lea (%0, %1), %%"REG_a" \n\t"
- "lea (%%"REG_a", %1, 4), %%"REG_d" \n\t"
-// 0 1 2 3 4 5 6 7 8 9
-// %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1
-
- "movq (%2), %%mm0 \n\t" // L0
- "movq (%%"REG_a"), %%mm1 \n\t" // L2
- PAVGB(%%mm1, %%mm0) // L0+L2
- "movq (%0), %%mm2 \n\t" // L1
- PAVGB(%%mm2, %%mm0)
- "movq %%mm0, (%0) \n\t"
- "movq (%%"REG_a", %1), %%mm0 \n\t" // L3
- PAVGB(%%mm0, %%mm2) // L1+L3
- PAVGB(%%mm1, %%mm2) // 2L2 + L1 + L3
- "movq %%mm2, (%%"REG_a") \n\t"
- "movq (%%"REG_a", %1, 2), %%mm2 \n\t" // L4
- PAVGB(%%mm2, %%mm1) // L2+L4
- PAVGB(%%mm0, %%mm1) // 2L3 + L2 + L4
- "movq %%mm1, (%%"REG_a", %1) \n\t"
- "movq (%0, %1, 4), %%mm1 \n\t" // L5
- PAVGB(%%mm1, %%mm0) // L3+L5
- PAVGB(%%mm2, %%mm0) // 2L4 + L3 + L5
- "movq %%mm0, (%%"REG_a", %1, 2) \n\t"
- "movq (%%"REG_d"), %%mm0 \n\t" // L6
- PAVGB(%%mm0, %%mm2) // L4+L6
- PAVGB(%%mm1, %%mm2) // 2L5 + L4 + L6
- "movq %%mm2, (%0, %1, 4) \n\t"
- "movq (%%"REG_d", %1), %%mm2 \n\t" // L7
- PAVGB(%%mm2, %%mm1) // L5+L7
- PAVGB(%%mm0, %%mm1) // 2L6 + L5 + L7
- "movq %%mm1, (%%"REG_d") \n\t"
- "movq (%%"REG_d", %1, 2), %%mm1 \n\t" // L8
- PAVGB(%%mm1, %%mm0) // L6+L8
- PAVGB(%%mm2, %%mm0) // 2L7 + L6 + L8
- "movq %%mm0, (%%"REG_d", %1) \n\t"
- "movq (%0, %1, 8), %%mm0 \n\t" // L9
- PAVGB(%%mm0, %%mm2) // L7+L9
- PAVGB(%%mm1, %%mm2) // 2L8 + L7 + L9
- "movq %%mm2, (%%"REG_d", %1, 2) \n\t"
- "movq %%mm1, (%2) \n\t"
-
- : : "r" (src), "r" ((long)stride), "r" (tmp)
- : "%"REG_a, "%"REG_d
- );
-#else //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
- int a, b, c, x;
- src+= 4*stride;
-
- for(x=0; x<2; x++){
- a= *(uint32_t*)&tmp[stride*0];
- b= *(uint32_t*)&src[stride*0];
- c= *(uint32_t*)&src[stride*1];
- a= (a&c) + (((a^c)&0xFEFEFEFEUL)>>1);
- *(uint32_t*)&src[stride*0]= (a|b) - (((a^b)&0xFEFEFEFEUL)>>1);
-
- a= *(uint32_t*)&src[stride*2];
- b= (a&b) + (((a^b)&0xFEFEFEFEUL)>>1);
- *(uint32_t*)&src[stride*1]= (c|b) - (((c^b)&0xFEFEFEFEUL)>>1);
-
- b= *(uint32_t*)&src[stride*3];
- c= (b&c) + (((b^c)&0xFEFEFEFEUL)>>1);
- *(uint32_t*)&src[stride*2]= (c|a) - (((c^a)&0xFEFEFEFEUL)>>1);
-
- c= *(uint32_t*)&src[stride*4];
- a= (a&c) + (((a^c)&0xFEFEFEFEUL)>>1);
- *(uint32_t*)&src[stride*3]= (a|b) - (((a^b)&0xFEFEFEFEUL)>>1);
-
- a= *(uint32_t*)&src[stride*5];
- b= (a&b) + (((a^b)&0xFEFEFEFEUL)>>1);
- *(uint32_t*)&src[stride*4]= (c|b) - (((c^b)&0xFEFEFEFEUL)>>1);
-
- b= *(uint32_t*)&src[stride*6];
- c= (b&c) + (((b^c)&0xFEFEFEFEUL)>>1);
- *(uint32_t*)&src[stride*5]= (c|a) - (((c^a)&0xFEFEFEFEUL)>>1);
-
- c= *(uint32_t*)&src[stride*7];
- a= (a&c) + (((a^c)&0xFEFEFEFEUL)>>1);
- *(uint32_t*)&src[stride*6]= (a|b) - (((a^b)&0xFEFEFEFEUL)>>1);
-
- a= *(uint32_t*)&src[stride*8];
- b= (a&b) + (((a^b)&0xFEFEFEFEUL)>>1);
- *(uint32_t*)&src[stride*7]= (c|b) - (((c^b)&0xFEFEFEFEUL)>>1);
-
- *(uint32_t*)&tmp[stride*0]= c;
- src += 4;
- tmp += 4;
- }
-#endif //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
-}
-
-/**
- * Deinterlaces the given block by applying a median filter to every second line.
- * will be called for every 8x8 block and can read & write from line 4-15,
- * lines 0-3 have been passed through the deblock / dering filters allready, but can be read too
- * lines 4-12 will be read into the deblocking filter and should be deinterlaced
- */
-static inline void RENAME(deInterlaceMedian)(uint8_t src[], int stride)
-{
-#ifdef HAVE_MMX
- src+= 4*stride;
-#ifdef HAVE_MMX2
- asm volatile(
- "lea (%0, %1), %%"REG_a" \n\t"
- "lea (%%"REG_a", %1, 4), %%"REG_d" \n\t"
-// 0 1 2 3 4 5 6 7 8 9
-// %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1
-
- "movq (%0), %%mm0 \n\t" //
- "movq (%%"REG_a", %1), %%mm2 \n\t" //
- "movq (%%"REG_a"), %%mm1 \n\t" //
- "movq %%mm0, %%mm3 \n\t"
- "pmaxub %%mm1, %%mm0 \n\t" //
- "pminub %%mm3, %%mm1 \n\t" //
- "pmaxub %%mm2, %%mm1 \n\t" //
- "pminub %%mm1, %%mm0 \n\t"
- "movq %%mm0, (%%"REG_a") \n\t"
-
- "movq (%0, %1, 4), %%mm0 \n\t" //
- "movq (%%"REG_a", %1, 2), %%mm1 \n\t" //
- "movq %%mm2, %%mm3 \n\t"
- "pmaxub %%mm1, %%mm2 \n\t" //
- "pminub %%mm3, %%mm1 \n\t" //
- "pmaxub %%mm0, %%mm1 \n\t" //
- "pminub %%mm1, %%mm2 \n\t"
- "movq %%mm2, (%%"REG_a", %1, 2) \n\t"
-
- "movq (%%"REG_d"), %%mm2 \n\t" //
- "movq (%%"REG_d", %1), %%mm1 \n\t" //
- "movq %%mm2, %%mm3 \n\t"
- "pmaxub %%mm0, %%mm2 \n\t" //
- "pminub %%mm3, %%mm0 \n\t" //
- "pmaxub %%mm1, %%mm0 \n\t" //
- "pminub %%mm0, %%mm2 \n\t"
- "movq %%mm2, (%%"REG_d") \n\t"
-
- "movq (%%"REG_d", %1, 2), %%mm2 \n\t" //
- "movq (%0, %1, 8), %%mm0 \n\t" //
- "movq %%mm2, %%mm3 \n\t"
- "pmaxub %%mm0, %%mm2 \n\t" //
- "pminub %%mm3, %%mm0 \n\t" //
- "pmaxub %%mm1, %%mm0 \n\t" //
- "pminub %%mm0, %%mm2 \n\t"
- "movq %%mm2, (%%"REG_d", %1, 2) \n\t"
-
-
- : : "r" (src), "r" ((long)stride)
- : "%"REG_a, "%"REG_d
- );
-
-#else // MMX without MMX2
- asm volatile(
- "lea (%0, %1), %%"REG_a" \n\t"
- "lea (%%"REG_a", %1, 4), %%"REG_d" \n\t"
-// 0 1 2 3 4 5 6 7 8 9
-// %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1
- "pxor %%mm7, %%mm7 \n\t"
-
-#define REAL_MEDIAN(a,b,c)\
- "movq " #a ", %%mm0 \n\t"\
- "movq " #b ", %%mm2 \n\t"\
- "movq " #c ", %%mm1 \n\t"\
- "movq %%mm0, %%mm3 \n\t"\
- "movq %%mm1, %%mm4 \n\t"\
- "movq %%mm2, %%mm5 \n\t"\
- "psubusb %%mm1, %%mm3 \n\t"\
- "psubusb %%mm2, %%mm4 \n\t"\
- "psubusb %%mm0, %%mm5 \n\t"\
- "pcmpeqb %%mm7, %%mm3 \n\t"\
- "pcmpeqb %%mm7, %%mm4 \n\t"\
- "pcmpeqb %%mm7, %%mm5 \n\t"\
- "movq %%mm3, %%mm6 \n\t"\
- "pxor %%mm4, %%mm3 \n\t"\
- "pxor %%mm5, %%mm4 \n\t"\
- "pxor %%mm6, %%mm5 \n\t"\
- "por %%mm3, %%mm1 \n\t"\
- "por %%mm4, %%mm2 \n\t"\
- "por %%mm5, %%mm0 \n\t"\
- "pand %%mm2, %%mm0 \n\t"\
- "pand %%mm1, %%mm0 \n\t"\
- "movq %%mm0, " #b " \n\t"
-#define MEDIAN(a,b,c) REAL_MEDIAN(a,b,c)
-
-MEDIAN((%0) , (%%REGa) , (%%REGa, %1))
-MEDIAN((%%REGa, %1), (%%REGa, %1, 2), (%0, %1, 4))
-MEDIAN((%0, %1, 4) , (%%REGd) , (%%REGd, %1))
-MEDIAN((%%REGd, %1), (%%REGd, %1, 2), (%0, %1, 8))
-
- : : "r" (src), "r" ((long)stride)
- : "%"REG_a, "%"REG_d
- );
-#endif //HAVE_MMX2
-#else //HAVE_MMX
- int x, y;
- src+= 4*stride;
- // FIXME - there should be a way to do a few columns in parallel like w/mmx
- for(x=0; x<8; x++)
- {
- uint8_t *colsrc = src;
- for (y=0; y<4; y++)
- {
- int a, b, c, d, e, f;
- a = colsrc[0 ];
- b = colsrc[stride ];
- c = colsrc[stride*2];
- d = (a-b)>>31;
- e = (b-c)>>31;
- f = (c-a)>>31;
- colsrc[stride ] = (a|(d^f)) & (b|(d^e)) & (c|(e^f));
- colsrc += stride*2;
- }
- src++;
- }
-#endif //HAVE_MMX
-}
-
-#ifdef HAVE_MMX
-/**
- * transposes and shift the given 8x8 Block into dst1 and dst2
- */
-static inline void RENAME(transpose1)(uint8_t *dst1, uint8_t *dst2, uint8_t *src, int srcStride)
-{
- asm(
- "lea (%0, %1), %%"REG_a" \n\t"
-// 0 1 2 3 4 5 6 7 8 9
-// %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1
- "movq (%0), %%mm0 \n\t" // 12345678
- "movq (%%"REG_a"), %%mm1 \n\t" // abcdefgh
- "movq %%mm0, %%mm2 \n\t" // 12345678
- "punpcklbw %%mm1, %%mm0 \n\t" // 1a2b3c4d
- "punpckhbw %%mm1, %%mm2 \n\t" // 5e6f7g8h
-
- "movq (%%"REG_a", %1), %%mm1 \n\t"
- "movq (%%"REG_a", %1, 2), %%mm3 \n\t"
- "movq %%mm1, %%mm4 \n\t"
- "punpcklbw %%mm3, %%mm1 \n\t"
- "punpckhbw %%mm3, %%mm4 \n\t"
-
- "movq %%mm0, %%mm3 \n\t"
- "punpcklwd %%mm1, %%mm0 \n\t"
- "punpckhwd %%mm1, %%mm3 \n\t"
- "movq %%mm2, %%mm1 \n\t"
- "punpcklwd %%mm4, %%mm2 \n\t"
- "punpckhwd %%mm4, %%mm1 \n\t"
-
- "movd %%mm0, 128(%2) \n\t"
- "psrlq $32, %%mm0 \n\t"
- "movd %%mm0, 144(%2) \n\t"
- "movd %%mm3, 160(%2) \n\t"
- "psrlq $32, %%mm3 \n\t"
- "movd %%mm3, 176(%2) \n\t"
- "movd %%mm3, 48(%3) \n\t"
- "movd %%mm2, 192(%2) \n\t"
- "movd %%mm2, 64(%3) \n\t"
- "psrlq $32, %%mm2 \n\t"
- "movd %%mm2, 80(%3) \n\t"
- "movd %%mm1, 96(%3) \n\t"
- "psrlq $32, %%mm1 \n\t"
- "movd %%mm1, 112(%3) \n\t"
-
- "lea (%%"REG_a", %1, 4), %%"REG_a" \n\t"
-
- "movq (%0, %1, 4), %%mm0 \n\t" // 12345678
- "movq (%%"REG_a"), %%mm1 \n\t" // abcdefgh
- "movq %%mm0, %%mm2 \n\t" // 12345678
- "punpcklbw %%mm1, %%mm0 \n\t" // 1a2b3c4d
- "punpckhbw %%mm1, %%mm2 \n\t" // 5e6f7g8h
-
- "movq (%%"REG_a", %1), %%mm1 \n\t"
- "movq (%%"REG_a", %1, 2), %%mm3 \n\t"
- "movq %%mm1, %%mm4 \n\t"
- "punpcklbw %%mm3, %%mm1 \n\t"
- "punpckhbw %%mm3, %%mm4 \n\t"
-
- "movq %%mm0, %%mm3 \n\t"
- "punpcklwd %%mm1, %%mm0 \n\t"
- "punpckhwd %%mm1, %%mm3 \n\t"
- "movq %%mm2, %%mm1 \n\t"
- "punpcklwd %%mm4, %%mm2 \n\t"
- "punpckhwd %%mm4, %%mm1 \n\t"
-
- "movd %%mm0, 132(%2) \n\t"
- "psrlq $32, %%mm0 \n\t"
- "movd %%mm0, 148(%2) \n\t"
- "movd %%mm3, 164(%2) \n\t"
- "psrlq $32, %%mm3 \n\t"
- "movd %%mm3, 180(%2) \n\t"
- "movd %%mm3, 52(%3) \n\t"
- "movd %%mm2, 196(%2) \n\t"
- "movd %%mm2, 68(%3) \n\t"
- "psrlq $32, %%mm2 \n\t"
- "movd %%mm2, 84(%3) \n\t"
- "movd %%mm1, 100(%3) \n\t"
- "psrlq $32, %%mm1 \n\t"
- "movd %%mm1, 116(%3) \n\t"
-
-
- :: "r" (src), "r" ((long)srcStride), "r" (dst1), "r" (dst2)
- : "%"REG_a
- );
-}
-
-/**
- * transposes the given 8x8 block
- */
-static inline void RENAME(transpose2)(uint8_t *dst, int dstStride, uint8_t *src)
-{
- asm(
- "lea (%0, %1), %%"REG_a" \n\t"
- "lea (%%"REG_a",%1,4), %%"REG_d" \n\t"
-// 0 1 2 3 4 5 6 7 8 9
-// %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1
- "movq (%2), %%mm0 \n\t" // 12345678
- "movq 16(%2), %%mm1 \n\t" // abcdefgh
- "movq %%mm0, %%mm2 \n\t" // 12345678
- "punpcklbw %%mm1, %%mm0 \n\t" // 1a2b3c4d
- "punpckhbw %%mm1, %%mm2 \n\t" // 5e6f7g8h
-
- "movq 32(%2), %%mm1 \n\t"
- "movq 48(%2), %%mm3 \n\t"
- "movq %%mm1, %%mm4 \n\t"
- "punpcklbw %%mm3, %%mm1 \n\t"
- "punpckhbw %%mm3, %%mm4 \n\t"
-
- "movq %%mm0, %%mm3 \n\t"
- "punpcklwd %%mm1, %%mm0 \n\t"
- "punpckhwd %%mm1, %%mm3 \n\t"
- "movq %%mm2, %%mm1 \n\t"
- "punpcklwd %%mm4, %%mm2 \n\t"
- "punpckhwd %%mm4, %%mm1 \n\t"
-
- "movd %%mm0, (%0) \n\t"
- "psrlq $32, %%mm0 \n\t"
- "movd %%mm0, (%%"REG_a") \n\t"
- "movd %%mm3, (%%"REG_a", %1) \n\t"
- "psrlq $32, %%mm3 \n\t"
- "movd %%mm3, (%%"REG_a", %1, 2) \n\t"
- "movd %%mm2, (%0, %1, 4) \n\t"
- "psrlq $32, %%mm2 \n\t"
- "movd %%mm2, (%%"REG_d") \n\t"
- "movd %%mm1, (%%"REG_d", %1) \n\t"
- "psrlq $32, %%mm1 \n\t"
- "movd %%mm1, (%%"REG_d", %1, 2) \n\t"
-
-
- "movq 64(%2), %%mm0 \n\t" // 12345678
- "movq 80(%2), %%mm1 \n\t" // abcdefgh
- "movq %%mm0, %%mm2 \n\t" // 12345678
- "punpcklbw %%mm1, %%mm0 \n\t" // 1a2b3c4d
- "punpckhbw %%mm1, %%mm2 \n\t" // 5e6f7g8h
-
- "movq 96(%2), %%mm1 \n\t"
- "movq 112(%2), %%mm3 \n\t"
- "movq %%mm1, %%mm4 \n\t"
- "punpcklbw %%mm3, %%mm1 \n\t"
- "punpckhbw %%mm3, %%mm4 \n\t"
-
- "movq %%mm0, %%mm3 \n\t"
- "punpcklwd %%mm1, %%mm0 \n\t"
- "punpckhwd %%mm1, %%mm3 \n\t"
- "movq %%mm2, %%mm1 \n\t"
- "punpcklwd %%mm4, %%mm2 \n\t"
- "punpckhwd %%mm4, %%mm1 \n\t"
-
- "movd %%mm0, 4(%0) \n\t"
- "psrlq $32, %%mm0 \n\t"
- "movd %%mm0, 4(%%"REG_a") \n\t"
- "movd %%mm3, 4(%%"REG_a", %1) \n\t"
- "psrlq $32, %%mm3 \n\t"
- "movd %%mm3, 4(%%"REG_a", %1, 2) \n\t"
- "movd %%mm2, 4(%0, %1, 4) \n\t"
- "psrlq $32, %%mm2 \n\t"
- "movd %%mm2, 4(%%"REG_d") \n\t"
- "movd %%mm1, 4(%%"REG_d", %1) \n\t"
- "psrlq $32, %%mm1 \n\t"
- "movd %%mm1, 4(%%"REG_d", %1, 2) \n\t"
-
- :: "r" (dst), "r" ((long)dstStride), "r" (src)
- : "%"REG_a, "%"REG_d
- );
-}
-#endif //HAVE_MMX
-//static long test=0;
-
-#ifndef HAVE_ALTIVEC
-static inline void RENAME(tempNoiseReducer)(uint8_t *src, int stride,
- uint8_t *tempBlured, uint32_t *tempBluredPast, int *maxNoise)
-{
- // to save a register (FIXME do this outside of the loops)
- tempBluredPast[127]= maxNoise[0];
- tempBluredPast[128]= maxNoise[1];
- tempBluredPast[129]= maxNoise[2];
-
-#define FAST_L2_DIFF
-//#define L1_DIFF //u should change the thresholds too if u try that one
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
- asm volatile(
- "lea (%2, %2, 2), %%"REG_a" \n\t" // 3*stride
- "lea (%2, %2, 4), %%"REG_d" \n\t" // 5*stride
- "lea (%%"REG_d", %2, 2), %%"REG_c" \n\t" // 7*stride
-// 0 1 2 3 4 5 6 7 8 9
-// %x %x+%2 %x+2%2 %x+eax %x+4%2 %x+edx %x+2eax %x+ecx %x+8%2
-//FIXME reorder?
-#ifdef L1_DIFF //needs mmx2
- "movq (%0), %%mm0 \n\t" // L0
- "psadbw (%1), %%mm0 \n\t" // |L0-R0|
- "movq (%0, %2), %%mm1 \n\t" // L1
- "psadbw (%1, %2), %%mm1 \n\t" // |L1-R1|
- "movq (%0, %2, 2), %%mm2 \n\t" // L2
- "psadbw (%1, %2, 2), %%mm2 \n\t" // |L2-R2|
- "movq (%0, %%"REG_a"), %%mm3 \n\t" // L3
- "psadbw (%1, %%"REG_a"), %%mm3 \n\t" // |L3-R3|
-
- "movq (%0, %2, 4), %%mm4 \n\t" // L4
- "paddw %%mm1, %%mm0 \n\t"
- "psadbw (%1, %2, 4), %%mm4 \n\t" // |L4-R4|
- "movq (%0, %%"REG_d"), %%mm5 \n\t" // L5
- "paddw %%mm2, %%mm0 \n\t"
- "psadbw (%1, %%"REG_d"), %%mm5 \n\t" // |L5-R5|
- "movq (%0, %%"REG_a", 2), %%mm6 \n\t" // L6
- "paddw %%mm3, %%mm0 \n\t"
- "psadbw (%1, %%"REG_a", 2), %%mm6 \n\t" // |L6-R6|
- "movq (%0, %%"REG_c"), %%mm7 \n\t" // L7
- "paddw %%mm4, %%mm0 \n\t"
- "psadbw (%1, %%"REG_c"), %%mm7 \n\t" // |L7-R7|
- "paddw %%mm5, %%mm6 \n\t"
- "paddw %%mm7, %%mm6 \n\t"
- "paddw %%mm6, %%mm0 \n\t"
-#else //L1_DIFF
-#if defined (FAST_L2_DIFF)
- "pcmpeqb %%mm7, %%mm7 \n\t"
- "movq "MANGLE(b80)", %%mm6 \n\t"
- "pxor %%mm0, %%mm0 \n\t"
-#define REAL_L2_DIFF_CORE(a, b)\
- "movq " #a ", %%mm5 \n\t"\
- "movq " #b ", %%mm2 \n\t"\
- "pxor %%mm7, %%mm2 \n\t"\
- PAVGB(%%mm2, %%mm5)\
- "paddb %%mm6, %%mm5 \n\t"\
- "movq %%mm5, %%mm2 \n\t"\
- "psllw $8, %%mm5 \n\t"\
- "pmaddwd %%mm5, %%mm5 \n\t"\
- "pmaddwd %%mm2, %%mm2 \n\t"\
- "paddd %%mm2, %%mm5 \n\t"\
- "psrld $14, %%mm5 \n\t"\
- "paddd %%mm5, %%mm0 \n\t"
-
-#else //defined (FAST_L2_DIFF)
- "pxor %%mm7, %%mm7 \n\t"
- "pxor %%mm0, %%mm0 \n\t"
-#define REAL_L2_DIFF_CORE(a, b)\
- "movq " #a ", %%mm5 \n\t"\
- "movq " #b ", %%mm2 \n\t"\
- "movq %%mm5, %%mm1 \n\t"\
- "movq %%mm2, %%mm3 \n\t"\
- "punpcklbw %%mm7, %%mm5 \n\t"\
- "punpckhbw %%mm7, %%mm1 \n\t"\
- "punpcklbw %%mm7, %%mm2 \n\t"\
- "punpckhbw %%mm7, %%mm3 \n\t"\
- "psubw %%mm2, %%mm5 \n\t"\
- "psubw %%mm3, %%mm1 \n\t"\
- "pmaddwd %%mm5, %%mm5 \n\t"\
- "pmaddwd %%mm1, %%mm1 \n\t"\
- "paddd %%mm1, %%mm5 \n\t"\
- "paddd %%mm5, %%mm0 \n\t"
-
-#endif //defined (FAST_L2_DIFF)
-
-#define L2_DIFF_CORE(a, b) REAL_L2_DIFF_CORE(a, b)
-
-L2_DIFF_CORE((%0) , (%1))
-L2_DIFF_CORE((%0, %2) , (%1, %2))
-L2_DIFF_CORE((%0, %2, 2) , (%1, %2, 2))
-L2_DIFF_CORE((%0, %%REGa) , (%1, %%REGa))
-L2_DIFF_CORE((%0, %2, 4) , (%1, %2, 4))
-L2_DIFF_CORE((%0, %%REGd) , (%1, %%REGd))
-L2_DIFF_CORE((%0, %%REGa,2), (%1, %%REGa,2))
-L2_DIFF_CORE((%0, %%REGc) , (%1, %%REGc))
-
-#endif //L1_DIFF
-
- "movq %%mm0, %%mm4 \n\t"
- "psrlq $32, %%mm0 \n\t"
- "paddd %%mm0, %%mm4 \n\t"
- "movd %%mm4, %%ecx \n\t"
- "shll $2, %%ecx \n\t"
- "mov %3, %%"REG_d" \n\t"
- "addl -4(%%"REG_d"), %%ecx \n\t"
- "addl 4(%%"REG_d"), %%ecx \n\t"
- "addl -1024(%%"REG_d"), %%ecx \n\t"
- "addl $4, %%ecx \n\t"
- "addl 1024(%%"REG_d"), %%ecx \n\t"
- "shrl $3, %%ecx \n\t"
- "movl %%ecx, (%%"REG_d") \n\t"
-
-// "mov %3, %%"REG_c" \n\t"
-// "mov %%"REG_c", test \n\t"
-// "jmp 4f \n\t"
- "cmpl 512(%%"REG_d"), %%ecx \n\t"
- " jb 2f \n\t"
- "cmpl 516(%%"REG_d"), %%ecx \n\t"
- " jb 1f \n\t"
-
- "lea (%%"REG_a", %2, 2), %%"REG_d" \n\t" // 5*stride
- "lea (%%"REG_d", %2, 2), %%"REG_c" \n\t" // 7*stride
- "movq (%0), %%mm0 \n\t" // L0
- "movq (%0, %2), %%mm1 \n\t" // L1
- "movq (%0, %2, 2), %%mm2 \n\t" // L2
- "movq (%0, %%"REG_a"), %%mm3 \n\t" // L3
- "movq (%0, %2, 4), %%mm4 \n\t" // L4
- "movq (%0, %%"REG_d"), %%mm5 \n\t" // L5
- "movq (%0, %%"REG_a", 2), %%mm6 \n\t" // L6
- "movq (%0, %%"REG_c"), %%mm7 \n\t" // L7
- "movq %%mm0, (%1) \n\t" // L0
- "movq %%mm1, (%1, %2) \n\t" // L1
- "movq %%mm2, (%1, %2, 2) \n\t" // L2
- "movq %%mm3, (%1, %%"REG_a") \n\t" // L3
- "movq %%mm4, (%1, %2, 4) \n\t" // L4
- "movq %%mm5, (%1, %%"REG_d") \n\t" // L5
- "movq %%mm6, (%1, %%"REG_a", 2) \n\t" // L6
- "movq %%mm7, (%1, %%"REG_c") \n\t" // L7
- "jmp 4f \n\t"
-
- "1: \n\t"
- "lea (%%"REG_a", %2, 2), %%"REG_d" \n\t" // 5*stride
- "lea (%%"REG_d", %2, 2), %%"REG_c" \n\t" // 7*stride
- "movq (%0), %%mm0 \n\t" // L0
- PAVGB((%1), %%mm0) // L0
- "movq (%0, %2), %%mm1 \n\t" // L1
- PAVGB((%1, %2), %%mm1) // L1
- "movq (%0, %2, 2), %%mm2 \n\t" // L2
- PAVGB((%1, %2, 2), %%mm2) // L2
- "movq (%0, %%"REG_a"), %%mm3 \n\t" // L3
- PAVGB((%1, %%REGa), %%mm3) // L3
- "movq (%0, %2, 4), %%mm4 \n\t" // L4
- PAVGB((%1, %2, 4), %%mm4) // L4
- "movq (%0, %%"REG_d"), %%mm5 \n\t" // L5
- PAVGB((%1, %%REGd), %%mm5) // L5
- "movq (%0, %%"REG_a", 2), %%mm6 \n\t" // L6
- PAVGB((%1, %%REGa, 2), %%mm6) // L6
- "movq (%0, %%"REG_c"), %%mm7 \n\t" // L7
- PAVGB((%1, %%REGc), %%mm7) // L7
- "movq %%mm0, (%1) \n\t" // R0
- "movq %%mm1, (%1, %2) \n\t" // R1
- "movq %%mm2, (%1, %2, 2) \n\t" // R2
- "movq %%mm3, (%1, %%"REG_a") \n\t" // R3
- "movq %%mm4, (%1, %2, 4) \n\t" // R4
- "movq %%mm5, (%1, %%"REG_d") \n\t" // R5
- "movq %%mm6, (%1, %%"REG_a", 2) \n\t" // R6
- "movq %%mm7, (%1, %%"REG_c") \n\t" // R7
- "movq %%mm0, (%0) \n\t" // L0
- "movq %%mm1, (%0, %2) \n\t" // L1
- "movq %%mm2, (%0, %2, 2) \n\t" // L2
- "movq %%mm3, (%0, %%"REG_a") \n\t" // L3
- "movq %%mm4, (%0, %2, 4) \n\t" // L4
- "movq %%mm5, (%0, %%"REG_d") \n\t" // L5
- "movq %%mm6, (%0, %%"REG_a", 2) \n\t" // L6
- "movq %%mm7, (%0, %%"REG_c") \n\t" // L7
- "jmp 4f \n\t"
-
- "2: \n\t"
- "cmpl 508(%%"REG_d"), %%ecx \n\t"
- " jb 3f \n\t"
-
- "lea (%%"REG_a", %2, 2), %%"REG_d" \n\t" // 5*stride
- "lea (%%"REG_d", %2, 2), %%"REG_c" \n\t" // 7*stride
- "movq (%0), %%mm0 \n\t" // L0
- "movq (%0, %2), %%mm1 \n\t" // L1
- "movq (%0, %2, 2), %%mm2 \n\t" // L2
- "movq (%0, %%"REG_a"), %%mm3 \n\t" // L3
- "movq (%1), %%mm4 \n\t" // R0
- "movq (%1, %2), %%mm5 \n\t" // R1
- "movq (%1, %2, 2), %%mm6 \n\t" // R2
- "movq (%1, %%"REG_a"), %%mm7 \n\t" // R3
- PAVGB(%%mm4, %%mm0)
- PAVGB(%%mm5, %%mm1)
- PAVGB(%%mm6, %%mm2)
- PAVGB(%%mm7, %%mm3)
- PAVGB(%%mm4, %%mm0)
- PAVGB(%%mm5, %%mm1)
- PAVGB(%%mm6, %%mm2)
- PAVGB(%%mm7, %%mm3)
- "movq %%mm0, (%1) \n\t" // R0
- "movq %%mm1, (%1, %2) \n\t" // R1
- "movq %%mm2, (%1, %2, 2) \n\t" // R2
- "movq %%mm3, (%1, %%"REG_a") \n\t" // R3
- "movq %%mm0, (%0) \n\t" // L0
- "movq %%mm1, (%0, %2) \n\t" // L1
- "movq %%mm2, (%0, %2, 2) \n\t" // L2
- "movq %%mm3, (%0, %%"REG_a") \n\t" // L3
-
- "movq (%0, %2, 4), %%mm0 \n\t" // L4
- "movq (%0, %%"REG_d"), %%mm1 \n\t" // L5
- "movq (%0, %%"REG_a", 2), %%mm2 \n\t" // L6
- "movq (%0, %%"REG_c"), %%mm3 \n\t" // L7
- "movq (%1, %2, 4), %%mm4 \n\t" // R4
- "movq (%1, %%"REG_d"), %%mm5 \n\t" // R5
- "movq (%1, %%"REG_a", 2), %%mm6 \n\t" // R6
- "movq (%1, %%"REG_c"), %%mm7 \n\t" // R7
- PAVGB(%%mm4, %%mm0)
- PAVGB(%%mm5, %%mm1)
- PAVGB(%%mm6, %%mm2)
- PAVGB(%%mm7, %%mm3)
- PAVGB(%%mm4, %%mm0)
- PAVGB(%%mm5, %%mm1)
- PAVGB(%%mm6, %%mm2)
- PAVGB(%%mm7, %%mm3)
- "movq %%mm0, (%1, %2, 4) \n\t" // R4
- "movq %%mm1, (%1, %%"REG_d") \n\t" // R5
- "movq %%mm2, (%1, %%"REG_a", 2) \n\t" // R6
- "movq %%mm3, (%1, %%"REG_c") \n\t" // R7
- "movq %%mm0, (%0, %2, 4) \n\t" // L4
- "movq %%mm1, (%0, %%"REG_d") \n\t" // L5
- "movq %%mm2, (%0, %%"REG_a", 2) \n\t" // L6
- "movq %%mm3, (%0, %%"REG_c") \n\t" // L7
- "jmp 4f \n\t"
-
- "3: \n\t"
- "lea (%%"REG_a", %2, 2), %%"REG_d" \n\t" // 5*stride
- "lea (%%"REG_d", %2, 2), %%"REG_c" \n\t" // 7*stride
- "movq (%0), %%mm0 \n\t" // L0
- "movq (%0, %2), %%mm1 \n\t" // L1
- "movq (%0, %2, 2), %%mm2 \n\t" // L2
- "movq (%0, %%"REG_a"), %%mm3 \n\t" // L3
- "movq (%1), %%mm4 \n\t" // R0
- "movq (%1, %2), %%mm5 \n\t" // R1
- "movq (%1, %2, 2), %%mm6 \n\t" // R2
- "movq (%1, %%"REG_a"), %%mm7 \n\t" // R3
- PAVGB(%%mm4, %%mm0)
- PAVGB(%%mm5, %%mm1)
- PAVGB(%%mm6, %%mm2)
- PAVGB(%%mm7, %%mm3)
- PAVGB(%%mm4, %%mm0)
- PAVGB(%%mm5, %%mm1)
- PAVGB(%%mm6, %%mm2)
- PAVGB(%%mm7, %%mm3)
- PAVGB(%%mm4, %%mm0)
- PAVGB(%%mm5, %%mm1)
- PAVGB(%%mm6, %%mm2)
- PAVGB(%%mm7, %%mm3)
- "movq %%mm0, (%1) \n\t" // R0
- "movq %%mm1, (%1, %2) \n\t" // R1
- "movq %%mm2, (%1, %2, 2) \n\t" // R2
- "movq %%mm3, (%1, %%"REG_a") \n\t" // R3
- "movq %%mm0, (%0) \n\t" // L0
- "movq %%mm1, (%0, %2) \n\t" // L1
- "movq %%mm2, (%0, %2, 2) \n\t" // L2
- "movq %%mm3, (%0, %%"REG_a") \n\t" // L3
-
- "movq (%0, %2, 4), %%mm0 \n\t" // L4
- "movq (%0, %%"REG_d"), %%mm1 \n\t" // L5
- "movq (%0, %%"REG_a", 2), %%mm2 \n\t" // L6
- "movq (%0, %%"REG_c"), %%mm3 \n\t" // L7
- "movq (%1, %2, 4), %%mm4 \n\t" // R4
- "movq (%1, %%"REG_d"), %%mm5 \n\t" // R5
- "movq (%1, %%"REG_a", 2), %%mm6 \n\t" // R6
- "movq (%1, %%"REG_c"), %%mm7 \n\t" // R7
- PAVGB(%%mm4, %%mm0)
- PAVGB(%%mm5, %%mm1)
- PAVGB(%%mm6, %%mm2)
- PAVGB(%%mm7, %%mm3)
- PAVGB(%%mm4, %%mm0)
- PAVGB(%%mm5, %%mm1)
- PAVGB(%%mm6, %%mm2)
- PAVGB(%%mm7, %%mm3)
- PAVGB(%%mm4, %%mm0)
- PAVGB(%%mm5, %%mm1)
- PAVGB(%%mm6, %%mm2)
- PAVGB(%%mm7, %%mm3)
- "movq %%mm0, (%1, %2, 4) \n\t" // R4
- "movq %%mm1, (%1, %%"REG_d") \n\t" // R5
- "movq %%mm2, (%1, %%"REG_a", 2) \n\t" // R6
- "movq %%mm3, (%1, %%"REG_c") \n\t" // R7
- "movq %%mm0, (%0, %2, 4) \n\t" // L4
- "movq %%mm1, (%0, %%"REG_d") \n\t" // L5
- "movq %%mm2, (%0, %%"REG_a", 2) \n\t" // L6
- "movq %%mm3, (%0, %%"REG_c") \n\t" // L7
-
- "4: \n\t"
-
- :: "r" (src), "r" (tempBlured), "r"((long)stride), "m" (tempBluredPast)
- : "%"REG_a, "%"REG_d, "%"REG_c, "memory"
- );
-//printf("%d\n", test);
-#else //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
-{
- int y;
- int d=0;
-// int sysd=0;
- int i;
-
- for(y=0; y<8; y++)
- {
- int x;
- for(x=0; x<8; x++)
- {
- int ref= tempBlured[ x + y*stride ];
- int cur= src[ x + y*stride ];
- int d1=ref - cur;
-// if(x==0 || x==7) d1+= d1>>1;
-// if(y==0 || y==7) d1+= d1>>1;
-// d+= ABS(d1);
- d+= d1*d1;
-// sysd+= d1;
- }
- }
- i=d;
- d= (
- 4*d
- +(*(tempBluredPast-256))
- +(*(tempBluredPast-1))+ (*(tempBluredPast+1))
- +(*(tempBluredPast+256))
- +4)>>3;
- *tempBluredPast=i;
-// ((*tempBluredPast)*3 + d + 2)>>2;
-
-//printf("%d %d %d\n", maxNoise[0], maxNoise[1], maxNoise[2]);
-/*
-Switch between
- 1 0 0 0 0 0 0 (0)
-64 32 16 8 4 2 1 (1)
-64 48 36 27 20 15 11 (33) (approx)
-64 56 49 43 37 33 29 (200) (approx)
-*/
- if(d > maxNoise[1])
- {
- if(d < maxNoise[2])
- {
- for(y=0; y<8; y++)
- {
- int x;
- for(x=0; x<8; x++)
- {
- int ref= tempBlured[ x + y*stride ];
- int cur= src[ x + y*stride ];
- tempBlured[ x + y*stride ]=
- src[ x + y*stride ]=
- (ref + cur + 1)>>1;
- }
- }
- }
- else
- {
- for(y=0; y<8; y++)
- {
- int x;
- for(x=0; x<8; x++)
- {
- tempBlured[ x + y*stride ]= src[ x + y*stride ];
- }
- }
- }
- }
- else
- {
- if(d < maxNoise[0])
- {
- for(y=0; y<8; y++)
- {
- int x;
- for(x=0; x<8; x++)
- {
- int ref= tempBlured[ x + y*stride ];
- int cur= src[ x + y*stride ];
- tempBlured[ x + y*stride ]=
- src[ x + y*stride ]=
- (ref*7 + cur + 4)>>3;
- }
- }
- }
- else
- {
- for(y=0; y<8; y++)
- {
- int x;
- for(x=0; x<8; x++)
- {
- int ref= tempBlured[ x + y*stride ];
- int cur= src[ x + y*stride ];
- tempBlured[ x + y*stride ]=
- src[ x + y*stride ]=
- (ref*3 + cur + 2)>>2;
- }
- }
- }
- }
-}
-#endif //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
-}
-#endif //HAVE_ALTIVEC
-
-#ifdef HAVE_MMX
-/**
- * accurate deblock filter
- */
-static always_inline void RENAME(do_a_deblock)(uint8_t *src, int step, int stride, PPContext *c){
- int64_t dc_mask, eq_mask, both_masks;
- int64_t sums[10*8*2];
- src+= step*3; // src points to begin of the 8x8 Block
-//START_TIMER
-asm volatile(
- "movq %0, %%mm7 \n\t"
- "movq %1, %%mm6 \n\t"
- : : "m" (c->mmxDcOffset[c->nonBQP]), "m" (c->mmxDcThreshold[c->nonBQP])
- );
-
-asm volatile(
- "lea (%2, %3), %%"REG_a" \n\t"
-// 0 1 2 3 4 5 6 7 8 9
-// %1 eax eax+%2 eax+2%2 %1+4%2 ecx ecx+%2 ecx+2%2 %1+8%2 ecx+4%2
-
- "movq (%2), %%mm0 \n\t"
- "movq (%%"REG_a"), %%mm1 \n\t"
- "movq %%mm1, %%mm3 \n\t"
- "movq %%mm1, %%mm4 \n\t"
- "psubb %%mm1, %%mm0 \n\t" // mm0 = differnece
- "paddb %%mm7, %%mm0 \n\t"
- "pcmpgtb %%mm6, %%mm0 \n\t"
-
- "movq (%%"REG_a",%3), %%mm2 \n\t"
- PMAXUB(%%mm2, %%mm4)
- PMINUB(%%mm2, %%mm3, %%mm5)
- "psubb %%mm2, %%mm1 \n\t"
- "paddb %%mm7, %%mm1 \n\t"
- "pcmpgtb %%mm6, %%mm1 \n\t"
- "paddb %%mm1, %%mm0 \n\t"
-
- "movq (%%"REG_a", %3, 2), %%mm1 \n\t"
- PMAXUB(%%mm1, %%mm4)
- PMINUB(%%mm1, %%mm3, %%mm5)
- "psubb %%mm1, %%mm2 \n\t"
- "paddb %%mm7, %%mm2 \n\t"
- "pcmpgtb %%mm6, %%mm2 \n\t"
- "paddb %%mm2, %%mm0 \n\t"
-
- "lea (%%"REG_a", %3, 4), %%"REG_a" \n\t"
-
- "movq (%2, %3, 4), %%mm2 \n\t"
- PMAXUB(%%mm2, %%mm4)
- PMINUB(%%mm2, %%mm3, %%mm5)
- "psubb %%mm2, %%mm1 \n\t"
- "paddb %%mm7, %%mm1 \n\t"
- "pcmpgtb %%mm6, %%mm1 \n\t"
- "paddb %%mm1, %%mm0 \n\t"
-
- "movq (%%"REG_a"), %%mm1 \n\t"
- PMAXUB(%%mm1, %%mm4)
- PMINUB(%%mm1, %%mm3, %%mm5)
- "psubb %%mm1, %%mm2 \n\t"
- "paddb %%mm7, %%mm2 \n\t"
- "pcmpgtb %%mm6, %%mm2 \n\t"
- "paddb %%mm2, %%mm0 \n\t"
-
- "movq (%%"REG_a", %3), %%mm2 \n\t"
- PMAXUB(%%mm2, %%mm4)
- PMINUB(%%mm2, %%mm3, %%mm5)
- "psubb %%mm2, %%mm1 \n\t"
- "paddb %%mm7, %%mm1 \n\t"
- "pcmpgtb %%mm6, %%mm1 \n\t"
- "paddb %%mm1, %%mm0 \n\t"
-
- "movq (%%"REG_a", %3, 2), %%mm1 \n\t"
- PMAXUB(%%mm1, %%mm4)
- PMINUB(%%mm1, %%mm3, %%mm5)
- "psubb %%mm1, %%mm2 \n\t"
- "paddb %%mm7, %%mm2 \n\t"
- "pcmpgtb %%mm6, %%mm2 \n\t"
- "paddb %%mm2, %%mm0 \n\t"
-
- "movq (%2, %3, 8), %%mm2 \n\t"
- PMAXUB(%%mm2, %%mm4)
- PMINUB(%%mm2, %%mm3, %%mm5)
- "psubb %%mm2, %%mm1 \n\t"
- "paddb %%mm7, %%mm1 \n\t"
- "pcmpgtb %%mm6, %%mm1 \n\t"
- "paddb %%mm1, %%mm0 \n\t"
-
- "movq (%%"REG_a", %3, 4), %%mm1 \n\t"
- "psubb %%mm1, %%mm2 \n\t"
- "paddb %%mm7, %%mm2 \n\t"
- "pcmpgtb %%mm6, %%mm2 \n\t"
- "paddb %%mm2, %%mm0 \n\t"
- "psubusb %%mm3, %%mm4 \n\t"
-
- "pxor %%mm6, %%mm6 \n\t"
- "movq %4, %%mm7 \n\t" // QP,..., QP
- "paddusb %%mm7, %%mm7 \n\t" // 2QP ... 2QP
- "psubusb %%mm4, %%mm7 \n\t" // Diff >=2QP -> 0
- "pcmpeqb %%mm6, %%mm7 \n\t" // Diff < 2QP -> 0
- "pcmpeqb %%mm6, %%mm7 \n\t" // Diff < 2QP -> 0
- "movq %%mm7, %1 \n\t"
-
- "movq %5, %%mm7 \n\t"
- "punpcklbw %%mm7, %%mm7 \n\t"
- "punpcklbw %%mm7, %%mm7 \n\t"
- "punpcklbw %%mm7, %%mm7 \n\t"
- "psubb %%mm0, %%mm6 \n\t"
- "pcmpgtb %%mm7, %%mm6 \n\t"
- "movq %%mm6, %0 \n\t"
-
- : "=m" (eq_mask), "=m" (dc_mask)
- : "r" (src), "r" ((long)step), "m" (c->pQPb), "m"(c->ppMode.flatnessThreshold)
- : "%"REG_a
- );
-
- both_masks = dc_mask & eq_mask;
-
- if(both_masks){
- long offset= -8*step;
- int64_t *temp_sums= sums;
-
- asm volatile(
- "movq %2, %%mm0 \n\t" // QP,..., QP
- "pxor %%mm4, %%mm4 \n\t"
-
- "movq (%0), %%mm6 \n\t"
- "movq (%0, %1), %%mm5 \n\t"
- "movq %%mm5, %%mm1 \n\t"
- "movq %%mm6, %%mm2 \n\t"
- "psubusb %%mm6, %%mm5 \n\t"
- "psubusb %%mm1, %%mm2 \n\t"
- "por %%mm5, %%mm2 \n\t" // ABS Diff of lines
- "psubusb %%mm2, %%mm0 \n\t" // diff >= QP -> 0
- "pcmpeqb %%mm4, %%mm0 \n\t" // diff >= QP -> FF
-
- "pxor %%mm6, %%mm1 \n\t"
- "pand %%mm0, %%mm1 \n\t"
- "pxor %%mm1, %%mm6 \n\t"
- // 0:QP 6:First
-
- "movq (%0, %1, 8), %%mm5 \n\t"
- "add %1, %0 \n\t" // %0 points to line 1 not 0
- "movq (%0, %1, 8), %%mm7 \n\t"
- "movq %%mm5, %%mm1 \n\t"
- "movq %%mm7, %%mm2 \n\t"
- "psubusb %%mm7, %%mm5 \n\t"
- "psubusb %%mm1, %%mm2 \n\t"
- "por %%mm5, %%mm2 \n\t" // ABS Diff of lines
- "movq %2, %%mm0 \n\t" // QP,..., QP
- "psubusb %%mm2, %%mm0 \n\t" // diff >= QP -> 0
- "pcmpeqb %%mm4, %%mm0 \n\t" // diff >= QP -> FF
-
- "pxor %%mm7, %%mm1 \n\t"
- "pand %%mm0, %%mm1 \n\t"
- "pxor %%mm1, %%mm7 \n\t"
-
- "movq %%mm6, %%mm5 \n\t"
- "punpckhbw %%mm4, %%mm6 \n\t"
- "punpcklbw %%mm4, %%mm5 \n\t"
- // 4:0 5/6:First 7:Last
-
- "movq %%mm5, %%mm0 \n\t"
- "movq %%mm6, %%mm1 \n\t"
- "psllw $2, %%mm0 \n\t"
- "psllw $2, %%mm1 \n\t"
- "paddw "MANGLE(w04)", %%mm0 \n\t"
- "paddw "MANGLE(w04)", %%mm1 \n\t"
-
-#define NEXT\
- "movq (%0), %%mm2 \n\t"\
- "movq (%0), %%mm3 \n\t"\
- "add %1, %0 \n\t"\
- "punpcklbw %%mm4, %%mm2 \n\t"\
- "punpckhbw %%mm4, %%mm3 \n\t"\
- "paddw %%mm2, %%mm0 \n\t"\
- "paddw %%mm3, %%mm1 \n\t"
-
-#define PREV\
- "movq (%0), %%mm2 \n\t"\
- "movq (%0), %%mm3 \n\t"\
- "add %1, %0 \n\t"\
- "punpcklbw %%mm4, %%mm2 \n\t"\
- "punpckhbw %%mm4, %%mm3 \n\t"\
- "psubw %%mm2, %%mm0 \n\t"\
- "psubw %%mm3, %%mm1 \n\t"
-
-
- NEXT //0
- NEXT //1
- NEXT //2
- "movq %%mm0, (%3) \n\t"
- "movq %%mm1, 8(%3) \n\t"
-
- NEXT //3
- "psubw %%mm5, %%mm0 \n\t"
- "psubw %%mm6, %%mm1 \n\t"
- "movq %%mm0, 16(%3) \n\t"
- "movq %%mm1, 24(%3) \n\t"
-
- NEXT //4
- "psubw %%mm5, %%mm0 \n\t"
- "psubw %%mm6, %%mm1 \n\t"
- "movq %%mm0, 32(%3) \n\t"
- "movq %%mm1, 40(%3) \n\t"
-
- NEXT //5
- "psubw %%mm5, %%mm0 \n\t"
- "psubw %%mm6, %%mm1 \n\t"
- "movq %%mm0, 48(%3) \n\t"
- "movq %%mm1, 56(%3) \n\t"
-
- NEXT //6
- "psubw %%mm5, %%mm0 \n\t"
- "psubw %%mm6, %%mm1 \n\t"
- "movq %%mm0, 64(%3) \n\t"
- "movq %%mm1, 72(%3) \n\t"
-
- "movq %%mm7, %%mm6 \n\t"
- "punpckhbw %%mm4, %%mm7 \n\t"
- "punpcklbw %%mm4, %%mm6 \n\t"
-
- NEXT //7
- "mov %4, %0 \n\t"
- "add %1, %0 \n\t"
- PREV //0
- "movq %%mm0, 80(%3) \n\t"
- "movq %%mm1, 88(%3) \n\t"
-
- PREV //1
- "paddw %%mm6, %%mm0 \n\t"
- "paddw %%mm7, %%mm1 \n\t"
- "movq %%mm0, 96(%3) \n\t"
- "movq %%mm1, 104(%3) \n\t"
-
- PREV //2
- "paddw %%mm6, %%mm0 \n\t"
- "paddw %%mm7, %%mm1 \n\t"
- "movq %%mm0, 112(%3) \n\t"
- "movq %%mm1, 120(%3) \n\t"
-
- PREV //3
- "paddw %%mm6, %%mm0 \n\t"
- "paddw %%mm7, %%mm1 \n\t"
- "movq %%mm0, 128(%3) \n\t"
- "movq %%mm1, 136(%3) \n\t"
-
- PREV //4
- "paddw %%mm6, %%mm0 \n\t"
- "paddw %%mm7, %%mm1 \n\t"
- "movq %%mm0, 144(%3) \n\t"
- "movq %%mm1, 152(%3) \n\t"
-
- "mov %4, %0 \n\t" //FIXME
-
- : "+&r"(src)
- : "r" ((long)step), "m" (c->pQPb), "r"(sums), "g"(src)
- );
-
- src+= step; // src points to begin of the 8x8 Block
-
- asm volatile(
- "movq %4, %%mm6 \n\t"
- "pcmpeqb %%mm5, %%mm5 \n\t"
- "pxor %%mm6, %%mm5 \n\t"
- "pxor %%mm7, %%mm7 \n\t"
-
- "1: \n\t"
- "movq (%1), %%mm0 \n\t"
- "movq 8(%1), %%mm1 \n\t"
- "paddw 32(%1), %%mm0 \n\t"
- "paddw 40(%1), %%mm1 \n\t"
- "movq (%0, %3), %%mm2 \n\t"
- "movq %%mm2, %%mm3 \n\t"
- "movq %%mm2, %%mm4 \n\t"
- "punpcklbw %%mm7, %%mm2 \n\t"
- "punpckhbw %%mm7, %%mm3 \n\t"
- "paddw %%mm2, %%mm0 \n\t"
- "paddw %%mm3, %%mm1 \n\t"
- "paddw %%mm2, %%mm0 \n\t"
- "paddw %%mm3, %%mm1 \n\t"
- "psrlw $4, %%mm0 \n\t"
- "psrlw $4, %%mm1 \n\t"
- "packuswb %%mm1, %%mm0 \n\t"
- "pand %%mm6, %%mm0 \n\t"
- "pand %%mm5, %%mm4 \n\t"
- "por %%mm4, %%mm0 \n\t"
- "movq %%mm0, (%0, %3) \n\t"
- "add $16, %1 \n\t"
- "add %2, %0 \n\t"
- " js 1b \n\t"
-
- : "+r"(offset), "+r"(temp_sums)
- : "r" ((long)step), "r"(src - offset), "m"(both_masks)
- );
- }else
- src+= step; // src points to begin of the 8x8 Block
-
- if(eq_mask != -1LL){
- uint8_t *temp_src= src;
- asm volatile(
- "pxor %%mm7, %%mm7 \n\t"
- "lea -40(%%"REG_SP"), %%"REG_c" \n\t" // make space for 4 8-byte vars
- "and "ALIGN_MASK", %%"REG_c" \n\t" // align
-// 0 1 2 3 4 5 6 7 8 9
-// %0 eax eax+%1 eax+2%1 %0+4%1 ecx ecx+%1 ecx+2%1 %1+8%1 ecx+4%1
-
- "movq (%0), %%mm0 \n\t"
- "movq %%mm0, %%mm1 \n\t"
- "punpcklbw %%mm7, %%mm0 \n\t" // low part of line 0
- "punpckhbw %%mm7, %%mm1 \n\t" // high part of line 0
-
- "movq (%0, %1), %%mm2 \n\t"
- "lea (%0, %1, 2), %%"REG_a" \n\t"
- "movq %%mm2, %%mm3 \n\t"
- "punpcklbw %%mm7, %%mm2 \n\t" // low part of line 1
- "punpckhbw %%mm7, %%mm3 \n\t" // high part of line 1
-
- "movq (%%"REG_a"), %%mm4 \n\t"
- "movq %%mm4, %%mm5 \n\t"
- "punpcklbw %%mm7, %%mm4 \n\t" // low part of line 2
- "punpckhbw %%mm7, %%mm5 \n\t" // high part of line 2
-
- "paddw %%mm0, %%mm0 \n\t" // 2L0
- "paddw %%mm1, %%mm1 \n\t" // 2H0
- "psubw %%mm4, %%mm2 \n\t" // L1 - L2
- "psubw %%mm5, %%mm3 \n\t" // H1 - H2
- "psubw %%mm2, %%mm0 \n\t" // 2L0 - L1 + L2
- "psubw %%mm3, %%mm1 \n\t" // 2H0 - H1 + H2
-
- "psllw $2, %%mm2 \n\t" // 4L1 - 4L2
- "psllw $2, %%mm3 \n\t" // 4H1 - 4H2
- "psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2
- "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2
-
- "movq (%%"REG_a", %1), %%mm2 \n\t"
- "movq %%mm2, %%mm3 \n\t"
- "punpcklbw %%mm7, %%mm2 \n\t" // L3
- "punpckhbw %%mm7, %%mm3 \n\t" // H3
-
- "psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2 - L3
- "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2 - H3
- "psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2 - 2L3
- "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2 - 2H3
- "movq %%mm0, (%%"REG_c") \n\t" // 2L0 - 5L1 + 5L2 - 2L3
- "movq %%mm1, 8(%%"REG_c") \n\t" // 2H0 - 5H1 + 5H2 - 2H3
-
- "movq (%%"REG_a", %1, 2), %%mm0 \n\t"
- "movq %%mm0, %%mm1 \n\t"
- "punpcklbw %%mm7, %%mm0 \n\t" // L4
- "punpckhbw %%mm7, %%mm1 \n\t" // H4
-
- "psubw %%mm0, %%mm2 \n\t" // L3 - L4
- "psubw %%mm1, %%mm3 \n\t" // H3 - H4
- "movq %%mm2, 16(%%"REG_c") \n\t" // L3 - L4
- "movq %%mm3, 24(%%"REG_c") \n\t" // H3 - H4
- "paddw %%mm4, %%mm4 \n\t" // 2L2
- "paddw %%mm5, %%mm5 \n\t" // 2H2
- "psubw %%mm2, %%mm4 \n\t" // 2L2 - L3 + L4
- "psubw %%mm3, %%mm5 \n\t" // 2H2 - H3 + H4
-
- "lea (%%"REG_a", %1), %0 \n\t"
- "psllw $2, %%mm2 \n\t" // 4L3 - 4L4
- "psllw $2, %%mm3 \n\t" // 4H3 - 4H4
- "psubw %%mm2, %%mm4 \n\t" // 2L2 - 5L3 + 5L4
- "psubw %%mm3, %%mm5 \n\t" // 2H2 - 5H3 + 5H4
-//50 opcodes so far
- "movq (%0, %1, 2), %%mm2 \n\t"
- "movq %%mm2, %%mm3 \n\t"
- "punpcklbw %%mm7, %%mm2 \n\t" // L5
- "punpckhbw %%mm7, %%mm3 \n\t" // H5
- "psubw %%mm2, %%mm4 \n\t" // 2L2 - 5L3 + 5L4 - L5
- "psubw %%mm3, %%mm5 \n\t" // 2H2 - 5H3 + 5H4 - H5
- "psubw %%mm2, %%mm4 \n\t" // 2L2 - 5L3 + 5L4 - 2L5
- "psubw %%mm3, %%mm5 \n\t" // 2H2 - 5H3 + 5H4 - 2H5
-
- "movq (%%"REG_a", %1, 4), %%mm6 \n\t"
- "punpcklbw %%mm7, %%mm6 \n\t" // L6
- "psubw %%mm6, %%mm2 \n\t" // L5 - L6
- "movq (%%"REG_a", %1, 4), %%mm6 \n\t"
- "punpckhbw %%mm7, %%mm6 \n\t" // H6
- "psubw %%mm6, %%mm3 \n\t" // H5 - H6
-
- "paddw %%mm0, %%mm0 \n\t" // 2L4
- "paddw %%mm1, %%mm1 \n\t" // 2H4
- "psubw %%mm2, %%mm0 \n\t" // 2L4 - L5 + L6
- "psubw %%mm3, %%mm1 \n\t" // 2H4 - H5 + H6
-
- "psllw $2, %%mm2 \n\t" // 4L5 - 4L6
- "psllw $2, %%mm3 \n\t" // 4H5 - 4H6
- "psubw %%mm2, %%mm0 \n\t" // 2L4 - 5L5 + 5L6
- "psubw %%mm3, %%mm1 \n\t" // 2H4 - 5H5 + 5H6
-
- "movq (%0, %1, 4), %%mm2 \n\t"
- "movq %%mm2, %%mm3 \n\t"
- "punpcklbw %%mm7, %%mm2 \n\t" // L7
- "punpckhbw %%mm7, %%mm3 \n\t" // H7
-
- "paddw %%mm2, %%mm2 \n\t" // 2L7
- "paddw %%mm3, %%mm3 \n\t" // 2H7
- "psubw %%mm2, %%mm0 \n\t" // 2L4 - 5L5 + 5L6 - 2L7
- "psubw %%mm3, %%mm1 \n\t" // 2H4 - 5H5 + 5H6 - 2H7
-
- "movq (%%"REG_c"), %%mm2 \n\t" // 2L0 - 5L1 + 5L2 - 2L3
- "movq 8(%%"REG_c"), %%mm3 \n\t" // 2H0 - 5H1 + 5H2 - 2H3
-
-#ifdef HAVE_MMX2
- "movq %%mm7, %%mm6 \n\t" // 0
- "psubw %%mm0, %%mm6 \n\t"
- "pmaxsw %%mm6, %%mm0 \n\t" // |2L4 - 5L5 + 5L6 - 2L7|
- "movq %%mm7, %%mm6 \n\t" // 0
- "psubw %%mm1, %%mm6 \n\t"
- "pmaxsw %%mm6, %%mm1 \n\t" // |2H4 - 5H5 + 5H6 - 2H7|
- "movq %%mm7, %%mm6 \n\t" // 0
- "psubw %%mm2, %%mm6 \n\t"
- "pmaxsw %%mm6, %%mm2 \n\t" // |2L0 - 5L1 + 5L2 - 2L3|
- "movq %%mm7, %%mm6 \n\t" // 0
- "psubw %%mm3, %%mm6 \n\t"
- "pmaxsw %%mm6, %%mm3 \n\t" // |2H0 - 5H1 + 5H2 - 2H3|
-#else
- "movq %%mm7, %%mm6 \n\t" // 0
- "pcmpgtw %%mm0, %%mm6 \n\t"
- "pxor %%mm6, %%mm0 \n\t"
- "psubw %%mm6, %%mm0 \n\t" // |2L4 - 5L5 + 5L6 - 2L7|
- "movq %%mm7, %%mm6 \n\t" // 0
- "pcmpgtw %%mm1, %%mm6 \n\t"
- "pxor %%mm6, %%mm1 \n\t"
- "psubw %%mm6, %%mm1 \n\t" // |2H4 - 5H5 + 5H6 - 2H7|
- "movq %%mm7, %%mm6 \n\t" // 0
- "pcmpgtw %%mm2, %%mm6 \n\t"
- "pxor %%mm6, %%mm2 \n\t"
- "psubw %%mm6, %%mm2 \n\t" // |2L0 - 5L1 + 5L2 - 2L3|
- "movq %%mm7, %%mm6 \n\t" // 0
- "pcmpgtw %%mm3, %%mm6 \n\t"
- "pxor %%mm6, %%mm3 \n\t"
- "psubw %%mm6, %%mm3 \n\t" // |2H0 - 5H1 + 5H2 - 2H3|
-#endif
-
-#ifdef HAVE_MMX2
- "pminsw %%mm2, %%mm0 \n\t"
- "pminsw %%mm3, %%mm1 \n\t"
-#else
- "movq %%mm0, %%mm6 \n\t"
- "psubusw %%mm2, %%mm6 \n\t"
- "psubw %%mm6, %%mm0 \n\t"
- "movq %%mm1, %%mm6 \n\t"
- "psubusw %%mm3, %%mm6 \n\t"
- "psubw %%mm6, %%mm1 \n\t"
-#endif
-
- "movd %2, %%mm2 \n\t" // QP
- "punpcklbw %%mm7, %%mm2 \n\t"
-
- "movq %%mm7, %%mm6 \n\t" // 0
- "pcmpgtw %%mm4, %%mm6 \n\t" // sign(2L2 - 5L3 + 5L4 - 2L5)
- "pxor %%mm6, %%mm4 \n\t"
- "psubw %%mm6, %%mm4 \n\t" // |2L2 - 5L3 + 5L4 - 2L5|
- "pcmpgtw %%mm5, %%mm7 \n\t" // sign(2H2 - 5H3 + 5H4 - 2H5)
- "pxor %%mm7, %%mm5 \n\t"
- "psubw %%mm7, %%mm5 \n\t" // |2H2 - 5H3 + 5H4 - 2H5|
-// 100 opcodes
- "psllw $3, %%mm2 \n\t" // 8QP
- "movq %%mm2, %%mm3 \n\t" // 8QP
- "pcmpgtw %%mm4, %%mm2 \n\t"
- "pcmpgtw %%mm5, %%mm3 \n\t"
- "pand %%mm2, %%mm4 \n\t"
- "pand %%mm3, %%mm5 \n\t"
-
-
- "psubusw %%mm0, %%mm4 \n\t" // hd
- "psubusw %%mm1, %%mm5 \n\t" // ld
-
-
- "movq "MANGLE(w05)", %%mm2 \n\t" // 5
- "pmullw %%mm2, %%mm4 \n\t"
- "pmullw %%mm2, %%mm5 \n\t"
- "movq "MANGLE(w20)", %%mm2 \n\t" // 32
- "paddw %%mm2, %%mm4 \n\t"
- "paddw %%mm2, %%mm5 \n\t"
- "psrlw $6, %%mm4 \n\t"
- "psrlw $6, %%mm5 \n\t"
-
- "movq 16(%%"REG_c"), %%mm0 \n\t" // L3 - L4
- "movq 24(%%"REG_c"), %%mm1 \n\t" // H3 - H4
-
- "pxor %%mm2, %%mm2 \n\t"
- "pxor %%mm3, %%mm3 \n\t"
-
- "pcmpgtw %%mm0, %%mm2 \n\t" // sign (L3-L4)
- "pcmpgtw %%mm1, %%mm3 \n\t" // sign (H3-H4)
- "pxor %%mm2, %%mm0 \n\t"
- "pxor %%mm3, %%mm1 \n\t"
- "psubw %%mm2, %%mm0 \n\t" // |L3-L4|
- "psubw %%mm3, %%mm1 \n\t" // |H3-H4|
- "psrlw $1, %%mm0 \n\t" // |L3 - L4|/2
- "psrlw $1, %%mm1 \n\t" // |H3 - H4|/2
-
- "pxor %%mm6, %%mm2 \n\t"
- "pxor %%mm7, %%mm3 \n\t"
- "pand %%mm2, %%mm4 \n\t"
- "pand %%mm3, %%mm5 \n\t"
-
-#ifdef HAVE_MMX2
- "pminsw %%mm0, %%mm4 \n\t"
- "pminsw %%mm1, %%mm5 \n\t"
-#else
- "movq %%mm4, %%mm2 \n\t"
- "psubusw %%mm0, %%mm2 \n\t"
- "psubw %%mm2, %%mm4 \n\t"
- "movq %%mm5, %%mm2 \n\t"
- "psubusw %%mm1, %%mm2 \n\t"
- "psubw %%mm2, %%mm5 \n\t"
-#endif
- "pxor %%mm6, %%mm4 \n\t"
- "pxor %%mm7, %%mm5 \n\t"
- "psubw %%mm6, %%mm4 \n\t"
- "psubw %%mm7, %%mm5 \n\t"
- "packsswb %%mm5, %%mm4 \n\t"
- "movq %3, %%mm1 \n\t"
- "pandn %%mm4, %%mm1 \n\t"
- "movq (%0), %%mm0 \n\t"
- "paddb %%mm1, %%mm0 \n\t"
- "movq %%mm0, (%0) \n\t"
- "movq (%0, %1), %%mm0 \n\t"
- "psubb %%mm1, %%mm0 \n\t"
- "movq %%mm0, (%0, %1) \n\t"
-
- : "+r" (temp_src)
- : "r" ((long)step), "m" (c->pQPb), "m"(eq_mask)
- : "%"REG_a, "%"REG_c
- );
- }
-/*if(step==16){
- STOP_TIMER("step16")
-}else{
- STOP_TIMER("stepX")
-}*/
-}
-#endif //HAVE_MMX
-
-static void RENAME(postProcess)(uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height,
- QP_STORE_T QPs[], int QPStride, int isColor, PPContext *c);
-
-/**
- * Copies a block from src to dst and fixes the blacklevel
- * levelFix == 0 -> dont touch the brighness & contrast
- */
-#undef SCALED_CPY
-
-static inline void RENAME(blockCopy)(uint8_t dst[], int dstStride, uint8_t src[], int srcStride,
- int levelFix, int64_t *packedOffsetAndScale)
-{
-#ifndef HAVE_MMX
- int i;
-#endif
- if(levelFix)
- {
-#ifdef HAVE_MMX
- asm volatile(
- "movq (%%"REG_a"), %%mm2 \n\t" // packedYOffset
- "movq 8(%%"REG_a"), %%mm3 \n\t" // packedYScale
- "lea (%2,%4), %%"REG_a" \n\t"
- "lea (%3,%5), %%"REG_d" \n\t"
- "pxor %%mm4, %%mm4 \n\t"
-#ifdef HAVE_MMX2
-#define REAL_SCALED_CPY(src1, src2, dst1, dst2) \
- "movq " #src1 ", %%mm0 \n\t"\
- "movq " #src1 ", %%mm5 \n\t"\
- "movq " #src2 ", %%mm1 \n\t"\
- "movq " #src2 ", %%mm6 \n\t"\
- "punpcklbw %%mm0, %%mm0 \n\t"\
- "punpckhbw %%mm5, %%mm5 \n\t"\
- "punpcklbw %%mm1, %%mm1 \n\t"\
- "punpckhbw %%mm6, %%mm6 \n\t"\
- "pmulhuw %%mm3, %%mm0 \n\t"\
- "pmulhuw %%mm3, %%mm5 \n\t"\
- "pmulhuw %%mm3, %%mm1 \n\t"\
- "pmulhuw %%mm3, %%mm6 \n\t"\
- "psubw %%mm2, %%mm0 \n\t"\
- "psubw %%mm2, %%mm5 \n\t"\
- "psubw %%mm2, %%mm1 \n\t"\
- "psubw %%mm2, %%mm6 \n\t"\
- "packuswb %%mm5, %%mm0 \n\t"\
- "packuswb %%mm6, %%mm1 \n\t"\
- "movq %%mm0, " #dst1 " \n\t"\
- "movq %%mm1, " #dst2 " \n\t"\
-
-#else //HAVE_MMX2
-#define REAL_SCALED_CPY(src1, src2, dst1, dst2) \
- "movq " #src1 ", %%mm0 \n\t"\
- "movq " #src1 ", %%mm5 \n\t"\
- "punpcklbw %%mm4, %%mm0 \n\t"\
- "punpckhbw %%mm4, %%mm5 \n\t"\
- "psubw %%mm2, %%mm0 \n\t"\
- "psubw %%mm2, %%mm5 \n\t"\
- "movq " #src2 ", %%mm1 \n\t"\
- "psllw $6, %%mm0 \n\t"\
- "psllw $6, %%mm5 \n\t"\
- "pmulhw %%mm3, %%mm0 \n\t"\
- "movq " #src2 ", %%mm6 \n\t"\
- "pmulhw %%mm3, %%mm5 \n\t"\
- "punpcklbw %%mm4, %%mm1 \n\t"\
- "punpckhbw %%mm4, %%mm6 \n\t"\
- "psubw %%mm2, %%mm1 \n\t"\
- "psubw %%mm2, %%mm6 \n\t"\
- "psllw $6, %%mm1 \n\t"\
- "psllw $6, %%mm6 \n\t"\
- "pmulhw %%mm3, %%mm1 \n\t"\
- "pmulhw %%mm3, %%mm6 \n\t"\
- "packuswb %%mm5, %%mm0 \n\t"\
- "packuswb %%mm6, %%mm1 \n\t"\
- "movq %%mm0, " #dst1 " \n\t"\
- "movq %%mm1, " #dst2 " \n\t"\
-
-#endif //HAVE_MMX2
-#define SCALED_CPY(src1, src2, dst1, dst2)\
- REAL_SCALED_CPY(src1, src2, dst1, dst2)
-
-SCALED_CPY((%2) , (%2, %4) , (%3) , (%3, %5))
-SCALED_CPY((%2, %4, 2), (%%REGa, %4, 2), (%3, %5, 2), (%%REGd, %5, 2))
-SCALED_CPY((%2, %4, 4), (%%REGa, %4, 4), (%3, %5, 4), (%%REGd, %5, 4))
- "lea (%%"REG_a",%4,4), %%"REG_a" \n\t"
- "lea (%%"REG_d",%5,4), %%"REG_d" \n\t"
-SCALED_CPY((%%REGa, %4), (%%REGa, %4, 2), (%%REGd, %5), (%%REGd, %5, 2))
-
-
- : "=&a" (packedOffsetAndScale)
- : "0" (packedOffsetAndScale),
- "r"(src),
- "r"(dst),
- "r" ((long)srcStride),
- "r" ((long)dstStride)
- : "%"REG_d
- );
-#else //HAVE_MMX
- for(i=0; i<8; i++)
- memcpy( &(dst[dstStride*i]),
- &(src[srcStride*i]), BLOCK_SIZE);
-#endif //HAVE_MMX
- }
- else
- {
-#ifdef HAVE_MMX
- asm volatile(
- "lea (%0,%2), %%"REG_a" \n\t"
- "lea (%1,%3), %%"REG_d" \n\t"
-
-#define REAL_SIMPLE_CPY(src1, src2, dst1, dst2) \
- "movq " #src1 ", %%mm0 \n\t"\
- "movq " #src2 ", %%mm1 \n\t"\
- "movq %%mm0, " #dst1 " \n\t"\
- "movq %%mm1, " #dst2 " \n\t"\
-
-#define SIMPLE_CPY(src1, src2, dst1, dst2)\
- REAL_SIMPLE_CPY(src1, src2, dst1, dst2)
-
-SIMPLE_CPY((%0) , (%0, %2) , (%1) , (%1, %3))
-SIMPLE_CPY((%0, %2, 2), (%%REGa, %2, 2), (%1, %3, 2), (%%REGd, %3, 2))
-SIMPLE_CPY((%0, %2, 4), (%%REGa, %2, 4), (%1, %3, 4), (%%REGd, %3, 4))
- "lea (%%"REG_a",%2,4), %%"REG_a" \n\t"
- "lea (%%"REG_d",%3,4), %%"REG_d" \n\t"
-SIMPLE_CPY((%%REGa, %2), (%%REGa, %2, 2), (%%REGd, %3), (%%REGd, %3, 2))
-
- : : "r" (src),
- "r" (dst),
- "r" ((long)srcStride),
- "r" ((long)dstStride)
- : "%"REG_a, "%"REG_d
- );
-#else //HAVE_MMX
- for(i=0; i<8; i++)
- memcpy( &(dst[dstStride*i]),
- &(src[srcStride*i]), BLOCK_SIZE);
-#endif //HAVE_MMX
- }
-}
-
-/**
- * Duplicates the given 8 src pixels ? times upward
- */
-static inline void RENAME(duplicate)(uint8_t src[], int stride)
-{
-#ifdef HAVE_MMX
- asm volatile(
- "movq (%0), %%mm0 \n\t"
- "add %1, %0 \n\t"
- "movq %%mm0, (%0) \n\t"
- "movq %%mm0, (%0, %1) \n\t"
- "movq %%mm0, (%0, %1, 2) \n\t"
- : "+r" (src)
- : "r" ((long)-stride)
- );
-#else
- int i;
- uint8_t *p=src;
- for(i=0; i<3; i++)
- {
- p-= stride;
- memcpy(p, src, 8);
- }
-#endif
-}
-
-/**
- * Filters array of bytes (Y or U or V values)
- */
-static void RENAME(postProcess)(uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height,
- QP_STORE_T QPs[], int QPStride, int isColor, PPContext *c2)
-{
- PPContext __attribute__((aligned(8))) c= *c2; //copy to stack for faster access
- int x,y;
-#ifdef COMPILE_TIME_MODE
- const int mode= COMPILE_TIME_MODE;
-#else
- const int mode= isColor ? c.ppMode.chromMode : c.ppMode.lumMode;
-#endif
- int black=0, white=255; // blackest black and whitest white in the picture
- int QPCorrecture= 256*256;
-
- int copyAhead;
-#ifdef HAVE_MMX
- int i;
-#endif
-
- const int qpHShift= isColor ? 4-c.hChromaSubSample : 4;
- const int qpVShift= isColor ? 4-c.vChromaSubSample : 4;
-
- //FIXME remove
- uint64_t * const yHistogram= c.yHistogram;
- uint8_t * const tempSrc= srcStride > 0 ? c.tempSrc : c.tempSrc - 23*srcStride;
- uint8_t * const tempDst= dstStride > 0 ? c.tempDst : c.tempDst - 23*dstStride;
- //const int mbWidth= isColor ? (width+7)>>3 : (width+15)>>4;
-
-#ifdef HAVE_MMX
- for(i=0; i<57; i++){
- int offset= ((i*c.ppMode.baseDcDiff)>>8) + 1;
- int threshold= offset*2 + 1;
- c.mmxDcOffset[i]= 0x7F - offset;
- c.mmxDcThreshold[i]= 0x7F - threshold;
- c.mmxDcOffset[i]*= 0x0101010101010101LL;
- c.mmxDcThreshold[i]*= 0x0101010101010101LL;
- }
-#endif
-
- if(mode & CUBIC_IPOL_DEINT_FILTER) copyAhead=16;
- else if( (mode & LINEAR_BLEND_DEINT_FILTER)
- || (mode & FFMPEG_DEINT_FILTER)
- || (mode & LOWPASS5_DEINT_FILTER)) copyAhead=14;
- else if( (mode & V_DEBLOCK)
- || (mode & LINEAR_IPOL_DEINT_FILTER)
- || (mode & MEDIAN_DEINT_FILTER)
- || (mode & V_A_DEBLOCK)) copyAhead=13;
- else if(mode & V_X1_FILTER) copyAhead=11;
-// else if(mode & V_RK1_FILTER) copyAhead=10;
- else if(mode & DERING) copyAhead=9;
- else copyAhead=8;
-
- copyAhead-= 8;
-
- if(!isColor)
- {
- uint64_t sum= 0;
- int i;
- uint64_t maxClipped;
- uint64_t clipped;
- double scale;
-
- c.frameNum++;
- // first frame is fscked so we ignore it
- if(c.frameNum == 1) yHistogram[0]= width*height/64*15/256;
-
- for(i=0; i<256; i++)
- {
- sum+= yHistogram[i];
-// printf("%d ", yHistogram[i]);
- }
-// printf("\n\n");
-
- /* we allways get a completly black picture first */
- maxClipped= (uint64_t)(sum * c.ppMode.maxClippedThreshold);
-
- clipped= sum;
- for(black=255; black>0; black--)
- {
- if(clipped < maxClipped) break;
- clipped-= yHistogram[black];
- }
-
- clipped= sum;
- for(white=0; white<256; white++)
- {
- if(clipped < maxClipped) break;
- clipped-= yHistogram[white];
- }
-
- scale= (double)(c.ppMode.maxAllowedY - c.ppMode.minAllowedY) / (double)(white-black);
-
-#ifdef HAVE_MMX2
- c.packedYScale= (uint16_t)(scale*256.0 + 0.5);
- c.packedYOffset= (((black*c.packedYScale)>>8) - c.ppMode.minAllowedY) & 0xFFFF;
-#else
- c.packedYScale= (uint16_t)(scale*1024.0 + 0.5);
- c.packedYOffset= (black - c.ppMode.minAllowedY) & 0xFFFF;
-#endif
-
- c.packedYOffset|= c.packedYOffset<<32;
- c.packedYOffset|= c.packedYOffset<<16;
-
- c.packedYScale|= c.packedYScale<<32;
- c.packedYScale|= c.packedYScale<<16;
-
- if(mode & LEVEL_FIX) QPCorrecture= (int)(scale*256*256 + 0.5);
- else QPCorrecture= 256*256;
- }
- else
- {
- c.packedYScale= 0x0100010001000100LL;
- c.packedYOffset= 0;
- QPCorrecture= 256*256;
- }
-
- /* copy & deinterlace first row of blocks */
- y=-BLOCK_SIZE;
- {
- uint8_t *srcBlock= &(src[y*srcStride]);
- uint8_t *dstBlock= tempDst + dstStride;
-
- // From this point on it is guranteed that we can read and write 16 lines downward
- // finish 1 block before the next otherwise we might have a problem
- // with the L1 Cache of the P4 ... or only a few blocks at a time or soemthing
- for(x=0; x<width; x+=BLOCK_SIZE)
- {
-
-#ifdef HAVE_MMX2
-/*
- prefetchnta(srcBlock + (((x>>2)&6) + 5)*srcStride + 32);
- prefetchnta(srcBlock + (((x>>2)&6) + 6)*srcStride + 32);
- prefetcht0(dstBlock + (((x>>2)&6) + 5)*dstStride + 32);
- prefetcht0(dstBlock + (((x>>2)&6) + 6)*dstStride + 32);
-*/
-
- asm(
- "mov %4, %%"REG_a" \n\t"
- "shr $2, %%"REG_a" \n\t"
- "and $6, %%"REG_a" \n\t"
- "add %5, %%"REG_a" \n\t"
- "mov %%"REG_a", %%"REG_d" \n\t"
- "imul %1, %%"REG_a" \n\t"
- "imul %3, %%"REG_d" \n\t"
- "prefetchnta 32(%%"REG_a", %0) \n\t"
- "prefetcht0 32(%%"REG_d", %2) \n\t"
- "add %1, %%"REG_a" \n\t"
- "add %3, %%"REG_d" \n\t"
- "prefetchnta 32(%%"REG_a", %0) \n\t"
- "prefetcht0 32(%%"REG_d", %2) \n\t"
- :: "r" (srcBlock), "r" ((long)srcStride), "r" (dstBlock), "r" ((long)dstStride),
- "g" ((long)x), "g" ((long)copyAhead)
- : "%"REG_a, "%"REG_d
- );
-
-#elif defined(HAVE_3DNOW)
-//FIXME check if this is faster on an 3dnow chip or if its faster without the prefetch or ...
-/* prefetch(srcBlock + (((x>>3)&3) + 5)*srcStride + 32);
- prefetch(srcBlock + (((x>>3)&3) + 9)*srcStride + 32);
- prefetchw(dstBlock + (((x>>3)&3) + 5)*dstStride + 32);
- prefetchw(dstBlock + (((x>>3)&3) + 9)*dstStride + 32);
-*/
-#endif
-
- RENAME(blockCopy)(dstBlock + dstStride*8, dstStride,
- srcBlock + srcStride*8, srcStride, mode & LEVEL_FIX, &c.packedYOffset);
-
- RENAME(duplicate)(dstBlock + dstStride*8, dstStride);
-
- if(mode & LINEAR_IPOL_DEINT_FILTER)
- RENAME(deInterlaceInterpolateLinear)(dstBlock, dstStride);
- else if(mode & LINEAR_BLEND_DEINT_FILTER)
- RENAME(deInterlaceBlendLinear)(dstBlock, dstStride, c.deintTemp + x);
- else if(mode & MEDIAN_DEINT_FILTER)
- RENAME(deInterlaceMedian)(dstBlock, dstStride);
- else if(mode & CUBIC_IPOL_DEINT_FILTER)
- RENAME(deInterlaceInterpolateCubic)(dstBlock, dstStride);
- else if(mode & FFMPEG_DEINT_FILTER)
- RENAME(deInterlaceFF)(dstBlock, dstStride, c.deintTemp + x);
- else if(mode & LOWPASS5_DEINT_FILTER)
- RENAME(deInterlaceL5)(dstBlock, dstStride, c.deintTemp + x, c.deintTemp + width + x);
-/* else if(mode & CUBIC_BLEND_DEINT_FILTER)
- RENAME(deInterlaceBlendCubic)(dstBlock, dstStride);
-*/
- dstBlock+=8;
- srcBlock+=8;
- }
- if(width==ABS(dstStride))
- linecpy(dst, tempDst + 9*dstStride, copyAhead, dstStride);
- else
- {
- int i;
- for(i=0; i<copyAhead; i++)
- {
- memcpy(dst + i*dstStride, tempDst + (9+i)*dstStride, width);
- }
- }
- }
-
-//printf("\n");
- for(y=0; y<height; y+=BLOCK_SIZE)
- {
- //1% speedup if these are here instead of the inner loop
- uint8_t *srcBlock= &(src[y*srcStride]);
- uint8_t *dstBlock= &(dst[y*dstStride]);
-#ifdef HAVE_MMX
- uint8_t *tempBlock1= c.tempBlocks;
- uint8_t *tempBlock2= c.tempBlocks + 8;
-#endif
- int8_t *QPptr= &QPs[(y>>qpVShift)*QPStride];
- int8_t *nonBQPptr= &c.nonBQPTable[(y>>qpVShift)*ABS(QPStride)];
- int QP=0;
- /* can we mess with a 8x16 block from srcBlock/dstBlock downwards and 1 line upwards
- if not than use a temporary buffer */
- if(y+15 >= height)
- {
- int i;
- /* copy from line (copyAhead) to (copyAhead+7) of src, these will be copied with
- blockcopy to dst later */
- linecpy(tempSrc + srcStride*copyAhead, srcBlock + srcStride*copyAhead,
- MAX(height-y-copyAhead, 0), srcStride);
-
- /* duplicate last line of src to fill the void upto line (copyAhead+7) */
- for(i=MAX(height-y, 8); i<copyAhead+8; i++)
- memcpy(tempSrc + srcStride*i, src + srcStride*(height-1), ABS(srcStride));
-
- /* copy up to (copyAhead+1) lines of dst (line -1 to (copyAhead-1))*/
- linecpy(tempDst, dstBlock - dstStride, MIN(height-y+1, copyAhead+1), dstStride);
-
- /* duplicate last line of dst to fill the void upto line (copyAhead) */
- for(i=height-y+1; i<=copyAhead; i++)
- memcpy(tempDst + dstStride*i, dst + dstStride*(height-1), ABS(dstStride));
-
- dstBlock= tempDst + dstStride;
- srcBlock= tempSrc;
- }
-//printf("\n");
-
- // From this point on it is guranteed that we can read and write 16 lines downward
- // finish 1 block before the next otherwise we might have a problem
- // with the L1 Cache of the P4 ... or only a few blocks at a time or soemthing
- for(x=0; x<width; x+=BLOCK_SIZE)
- {
- const int stride= dstStride;
-#ifdef HAVE_MMX
- uint8_t *tmpXchg;
-#endif
- if(isColor)
- {
- QP= QPptr[x>>qpHShift];
- c.nonBQP= nonBQPptr[x>>qpHShift];
- }
- else
- {
- QP= QPptr[x>>4];
- QP= (QP* QPCorrecture + 256*128)>>16;
- c.nonBQP= nonBQPptr[x>>4];
- c.nonBQP= (c.nonBQP* QPCorrecture + 256*128)>>16;
- yHistogram[ srcBlock[srcStride*12 + 4] ]++;
- }
- c.QP= QP;
-#ifdef HAVE_MMX
- asm volatile(
- "movd %1, %%mm7 \n\t"
- "packuswb %%mm7, %%mm7 \n\t" // 0, 0, 0, QP, 0, 0, 0, QP
- "packuswb %%mm7, %%mm7 \n\t" // 0,QP, 0, QP, 0,QP, 0, QP
- "packuswb %%mm7, %%mm7 \n\t" // QP,..., QP
- "movq %%mm7, %0 \n\t"
- : "=m" (c.pQPb)
- : "r" (QP)
- );
-#endif
-
-
-#ifdef HAVE_MMX2
-/*
- prefetchnta(srcBlock + (((x>>2)&6) + 5)*srcStride + 32);
- prefetchnta(srcBlock + (((x>>2)&6) + 6)*srcStride + 32);
- prefetcht0(dstBlock + (((x>>2)&6) + 5)*dstStride + 32);
- prefetcht0(dstBlock + (((x>>2)&6) + 6)*dstStride + 32);
-*/
-
- asm(
- "mov %4, %%"REG_a" \n\t"
- "shr $2, %%"REG_a" \n\t"
- "and $6, %%"REG_a" \n\t"
- "add %5, %%"REG_a" \n\t"
- "mov %%"REG_a", %%"REG_d" \n\t"
- "imul %1, %%"REG_a" \n\t"
- "imul %3, %%"REG_d" \n\t"
- "prefetchnta 32(%%"REG_a", %0) \n\t"
- "prefetcht0 32(%%"REG_d", %2) \n\t"
- "add %1, %%"REG_a" \n\t"
- "add %3, %%"REG_d" \n\t"
- "prefetchnta 32(%%"REG_a", %0) \n\t"
- "prefetcht0 32(%%"REG_d", %2) \n\t"
- :: "r" (srcBlock), "r" ((long)srcStride), "r" (dstBlock), "r" ((long)dstStride),
- "g" ((long)x), "g" ((long)copyAhead)
- : "%"REG_a, "%"REG_d
- );
-
-#elif defined(HAVE_3DNOW)
-//FIXME check if this is faster on an 3dnow chip or if its faster without the prefetch or ...
-/* prefetch(srcBlock + (((x>>3)&3) + 5)*srcStride + 32);
- prefetch(srcBlock + (((x>>3)&3) + 9)*srcStride + 32);
- prefetchw(dstBlock + (((x>>3)&3) + 5)*dstStride + 32);
- prefetchw(dstBlock + (((x>>3)&3) + 9)*dstStride + 32);
-*/
-#endif
-
- RENAME(blockCopy)(dstBlock + dstStride*copyAhead, dstStride,
- srcBlock + srcStride*copyAhead, srcStride, mode & LEVEL_FIX, &c.packedYOffset);
-
- if(mode & LINEAR_IPOL_DEINT_FILTER)
- RENAME(deInterlaceInterpolateLinear)(dstBlock, dstStride);
- else if(mode & LINEAR_BLEND_DEINT_FILTER)
- RENAME(deInterlaceBlendLinear)(dstBlock, dstStride, c.deintTemp + x);
- else if(mode & MEDIAN_DEINT_FILTER)
- RENAME(deInterlaceMedian)(dstBlock, dstStride);
- else if(mode & CUBIC_IPOL_DEINT_FILTER)
- RENAME(deInterlaceInterpolateCubic)(dstBlock, dstStride);
- else if(mode & FFMPEG_DEINT_FILTER)
- RENAME(deInterlaceFF)(dstBlock, dstStride, c.deintTemp + x);
- else if(mode & LOWPASS5_DEINT_FILTER)
- RENAME(deInterlaceL5)(dstBlock, dstStride, c.deintTemp + x, c.deintTemp + width + x);
-/* else if(mode & CUBIC_BLEND_DEINT_FILTER)
- RENAME(deInterlaceBlendCubic)(dstBlock, dstStride);
-*/
-
- /* only deblock if we have 2 blocks */
- if(y + 8 < height)
- {
- if(mode & V_X1_FILTER)
- RENAME(vertX1Filter)(dstBlock, stride, &c);
- else if(mode & V_DEBLOCK)
- {
- const int t= RENAME(vertClassify)(dstBlock, stride, &c);
-
- if(t==1)
- RENAME(doVertLowPass)(dstBlock, stride, &c);
- else if(t==2)
- RENAME(doVertDefFilter)(dstBlock, stride, &c);
- }else if(mode & V_A_DEBLOCK){
- RENAME(do_a_deblock)(dstBlock, stride, 1, &c);
- }
- }
-
-#ifdef HAVE_MMX
- RENAME(transpose1)(tempBlock1, tempBlock2, dstBlock, dstStride);
-#endif
- /* check if we have a previous block to deblock it with dstBlock */
- if(x - 8 >= 0)
- {
-#ifdef HAVE_MMX
- if(mode & H_X1_FILTER)
- RENAME(vertX1Filter)(tempBlock1, 16, &c);
- else if(mode & H_DEBLOCK)
- {
-//START_TIMER
- const int t= RENAME(vertClassify)(tempBlock1, 16, &c);
-//STOP_TIMER("dc & minmax")
- if(t==1)
- RENAME(doVertLowPass)(tempBlock1, 16, &c);
- else if(t==2)
- RENAME(doVertDefFilter)(tempBlock1, 16, &c);
- }else if(mode & H_A_DEBLOCK){
- RENAME(do_a_deblock)(tempBlock1, 16, 1, &c);
- }
-
- RENAME(transpose2)(dstBlock-4, dstStride, tempBlock1 + 4*16);
-
-#else
- if(mode & H_X1_FILTER)
- horizX1Filter(dstBlock-4, stride, QP);
- else if(mode & H_DEBLOCK)
- {
-#ifdef HAVE_ALTIVEC
- unsigned char __attribute__ ((aligned(16))) tempBlock[272];
- transpose_16x8_char_toPackedAlign_altivec(tempBlock, dstBlock - (4 + 1), stride);
-
- const int t=vertClassify_altivec(tempBlock-48, 16, &c);
- if(t==1) {
- doVertLowPass_altivec(tempBlock-48, 16, &c);
- transpose_8x16_char_fromPackedAlign_altivec(dstBlock - (4 + 1), tempBlock, stride);
- }
- else if(t==2) {
- doVertDefFilter_altivec(tempBlock-48, 16, &c);
- transpose_8x16_char_fromPackedAlign_altivec(dstBlock - (4 + 1), tempBlock, stride);
- }
-#else
- const int t= RENAME(horizClassify)(dstBlock-4, stride, &c);
-
- if(t==1)
- RENAME(doHorizLowPass)(dstBlock-4, stride, &c);
- else if(t==2)
- RENAME(doHorizDefFilter)(dstBlock-4, stride, &c);
-#endif
- }else if(mode & H_A_DEBLOCK){
- RENAME(do_a_deblock)(dstBlock-8, 1, stride, &c);
- }
-#endif //HAVE_MMX
- if(mode & DERING)
- {
- //FIXME filter first line
- if(y>0) RENAME(dering)(dstBlock - stride - 8, stride, &c);
- }
-
- if(mode & TEMP_NOISE_FILTER)
- {
- RENAME(tempNoiseReducer)(dstBlock-8, stride,
- c.tempBlured[isColor] + y*dstStride + x,
- c.tempBluredPast[isColor] + (y>>3)*256 + (x>>3),
- c.ppMode.maxTmpNoise);
- }
- }
-
- dstBlock+=8;
- srcBlock+=8;
-
-#ifdef HAVE_MMX
- tmpXchg= tempBlock1;
- tempBlock1= tempBlock2;
- tempBlock2 = tmpXchg;
-#endif
- }
-
- if(mode & DERING)
- {
- if(y > 0) RENAME(dering)(dstBlock - dstStride - 8, dstStride, &c);
- }
-
- if((mode & TEMP_NOISE_FILTER))
- {
- RENAME(tempNoiseReducer)(dstBlock-8, dstStride,
- c.tempBlured[isColor] + y*dstStride + x,
- c.tempBluredPast[isColor] + (y>>3)*256 + (x>>3),
- c.ppMode.maxTmpNoise);
- }
-
- /* did we use a tmp buffer for the last lines*/
- if(y+15 >= height)
- {
- uint8_t *dstBlock= &(dst[y*dstStride]);
- if(width==ABS(dstStride))
- linecpy(dstBlock, tempDst + dstStride, height-y, dstStride);
- else
- {
- int i;
- for(i=0; i<height-y; i++)
- {
- memcpy(dstBlock + i*dstStride, tempDst + (i+1)*dstStride, width);
- }
- }
- }
-/*
- for(x=0; x<width; x+=32)
- {
- volatile int i;
- i+= + dstBlock[x + 7*dstStride] + dstBlock[x + 8*dstStride]
- + dstBlock[x + 9*dstStride] + dstBlock[x +10*dstStride]
- + dstBlock[x +11*dstStride] + dstBlock[x +12*dstStride];
-// + dstBlock[x +13*dstStride]
-// + dstBlock[x +14*dstStride] + dstBlock[x +15*dstStride];
- }*/
- }
-#ifdef HAVE_3DNOW
- asm volatile("femms");
-#elif defined (HAVE_MMX)
- asm volatile("emms");
-#endif
-
-#ifdef DEBUG_BRIGHTNESS
- if(!isColor)
- {
- int max=1;
- int i;
- for(i=0; i<256; i++)
- if(yHistogram[i] > max) max=yHistogram[i];
-
- for(i=1; i<256; i++)
- {
- int x;
- int start=yHistogram[i-1]/(max/256+1);
- int end=yHistogram[i]/(max/256+1);
- int inc= end > start ? 1 : -1;
- for(x=start; x!=end+inc; x+=inc)
- dst[ i*dstStride + x]+=128;
- }
-
- for(i=0; i<100; i+=2)
- {
- dst[ (white)*dstStride + i]+=128;
- dst[ (black)*dstStride + i]+=128;
- }
-
- }
-#endif
-
- *c2= c; //copy local context back
-
-}
diff --git a/src/libffmpeg/libavcodec/loco.c b/src/libffmpeg/libavcodec/loco.c
deleted file mode 100644
index b1f99f425..000000000
--- a/src/libffmpeg/libavcodec/loco.c
+++ /dev/null
@@ -1,287 +0,0 @@
-/*
- * LOCO codec
- * Copyright (c) 2005 Konstantin Shishkov
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-/**
- * @file loco.c
- * LOCO codec.
- */
-
-#include "avcodec.h"
-#include "common.h"
-#include "bitstream.h"
-#include "golomb.h"
-
-enum LOCO_MODE {LOCO_UNKN=0, LOCO_CYUY2=-1, LOCO_CRGB=-2, LOCO_CRGBA=-3, LOCO_CYV12=-4,
- LOCO_YUY2=1, LOCO_UYVY=2, LOCO_RGB=3, LOCO_RGBA=4, LOCO_YV12=5};
-
-typedef struct LOCOContext{
- AVCodecContext *avctx;
- AVFrame pic;
- int lossy;
- int mode;
-} LOCOContext;
-
-typedef struct RICEContext{
- GetBitContext gb;
- int save, run, run2; /* internal rice decoder state */
- int sum, count; /* sum and count for getting rice parameter */
- int lossy;
-}RICEContext;
-
-static int loco_get_rice_param(RICEContext *r)
-{
- int cnt = 0;
- int val = r->count;
-
- while(r->sum > val && cnt < 9) {
- val <<= 1;
- cnt++;
- }
-
- return cnt;
-}
-
-static inline void loco_update_rice_param(RICEContext *r, int val)
-{
- r->sum += val;
- r->count++;
-
- if(r->count == 16) {
- r->sum >>= 1;
- r->count >>= 1;
- }
-}
-
-static inline int loco_get_rice(RICEContext *r)
-{
- int v;
- if (r->run > 0) { /* we have zero run */
- r->run--;
- loco_update_rice_param(r, 0);
- return 0;
- }
- v = get_ur_golomb_jpegls(&r->gb, loco_get_rice_param(r), INT_MAX, 0);
- loco_update_rice_param(r, (v+1)>>1);
- if (!v) {
- if (r->save >= 0) {
- r->run = get_ur_golomb_jpegls(&r->gb, 2, INT_MAX, 0);
- if(r->run > 1)
- r->save += r->run + 1;
- else
- r->save -= 3;
- }
- else
- r->run2++;
- } else {
- v = ((v>>1) + r->lossy) ^ -(v&1);
- if (r->run2 > 0) {
- if (r->run2 > 2)
- r->save += r->run2;
- else
- r->save -= 3;
- r->run2 = 0;
- }
- }
-
- return v;
-}
-
-/* LOCO main predictor - LOCO-I/JPEG-LS predictor */
-static inline int loco_predict(uint8_t* data, int stride, int step)
-{
- int a, b, c;
-
- a = data[-stride];
- b = data[-step];
- c = data[-stride - step];
-
- return mid_pred(a, a + b - c, b);
-}
-
-static int loco_decode_plane(LOCOContext *l, uint8_t *data, int width, int height,
- int stride, uint8_t *buf, int buf_size, int step)
-{
- RICEContext rc;
- int val;
- int i, j;
-
- init_get_bits(&rc.gb, buf, buf_size*8);
- rc.save = 0;
- rc.run = 0;
- rc.run2 = 0;
- rc.lossy = l->lossy;
-
- rc.sum = 8;
- rc.count = 1;
-
- /* restore top left pixel */
- val = loco_get_rice(&rc);
- data[0] = 128 + val;
- /* restore top line */
- for (i = 1; i < width; i++) {
- val = loco_get_rice(&rc);
- data[i * step] = data[i * step - step] + val;
- }
- data += stride;
- for (j = 1; j < height; j++) {
- /* restore left column */
- val = loco_get_rice(&rc);
- data[0] = data[-stride] + val;
- /* restore all other pixels */
- for (i = 1; i < width; i++) {
- val = loco_get_rice(&rc);
- data[i * step] = loco_predict(&data[i * step], stride, step) + val;
- }
- data += stride;
- }
-
- return ((get_bits_count(&rc.gb) + 7) >> 3);
-}
-
-static int decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- LOCOContext * const l = avctx->priv_data;
- AVFrame * const p= (AVFrame*)&l->pic;
- int decoded;
-
- 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->key_frame = 1;
-
- switch(l->mode) {
- case LOCO_CYUY2: case LOCO_YUY2: case LOCO_UYVY:
- decoded = loco_decode_plane(l, p->data[0], avctx->width, avctx->height,
- p->linesize[0], buf, buf_size, 1);
- buf += decoded; buf_size -= decoded;
- decoded = loco_decode_plane(l, p->data[1], avctx->width / 2, avctx->height,
- p->linesize[1], buf, buf_size, 1);
- buf += decoded; buf_size -= decoded;
- decoded = loco_decode_plane(l, p->data[2], avctx->width / 2, avctx->height,
- p->linesize[2], buf, buf_size, 1);
- break;
- case LOCO_CYV12: case LOCO_YV12:
- decoded = loco_decode_plane(l, p->data[0], avctx->width, avctx->height,
- p->linesize[0], buf, buf_size, 1);
- buf += decoded; buf_size -= decoded;
- decoded = loco_decode_plane(l, p->data[2], avctx->width / 2, avctx->height / 2,
- p->linesize[2], buf, buf_size, 1);
- buf += decoded; buf_size -= decoded;
- decoded = loco_decode_plane(l, p->data[1], avctx->width / 2, avctx->height / 2,
- p->linesize[1], buf, buf_size, 1);
- break;
- case LOCO_CRGB: case LOCO_RGB:
- decoded = loco_decode_plane(l, p->data[0] + p->linesize[0]*(avctx->height-1), avctx->width, avctx->height,
- -p->linesize[0], buf, buf_size, 3);
- buf += decoded; buf_size -= decoded;
- decoded = loco_decode_plane(l, p->data[0] + p->linesize[0]*(avctx->height-1) + 1, avctx->width, avctx->height,
- -p->linesize[0], buf, buf_size, 3);
- buf += decoded; buf_size -= decoded;
- decoded = loco_decode_plane(l, p->data[0] + p->linesize[0]*(avctx->height-1) + 2, avctx->width, avctx->height,
- -p->linesize[0], buf, buf_size, 3);
- break;
- case LOCO_RGBA:
- decoded = loco_decode_plane(l, p->data[0], avctx->width, avctx->height,
- p->linesize[0], buf, buf_size, 4);
- buf += decoded; buf_size -= decoded;
- decoded = loco_decode_plane(l, p->data[0] + 1, avctx->width, avctx->height,
- p->linesize[0], buf, buf_size, 4);
- buf += decoded; buf_size -= decoded;
- decoded = loco_decode_plane(l, p->data[0] + 2, avctx->width, avctx->height,
- p->linesize[0], buf, buf_size, 4);
- buf += decoded; buf_size -= decoded;
- decoded = loco_decode_plane(l, p->data[0] + 3, avctx->width, avctx->height,
- p->linesize[0], buf, buf_size, 4);
- break;
- }
-
- *data_size = sizeof(AVFrame);
- *(AVFrame*)data = l->pic;
-
- return buf_size;
-}
-
-static int decode_init(AVCodecContext *avctx){
- LOCOContext * const l = avctx->priv_data;
- int version;
-
- l->avctx = avctx;
- if (avctx->extradata_size < 12) {
- av_log(avctx, AV_LOG_ERROR, "Extradata size must be >= 12 instead of %i\n",
- avctx->extradata_size);
- return -1;
- }
- version = AV_RL32(avctx->extradata);
- switch(version) {
- case 1:
- l->lossy = 0;
- break;
- case 2:
- l->lossy = AV_RL32(avctx->extradata + 8);
- break;
- default:
- l->lossy = AV_RL32(avctx->extradata + 8);
- av_log(avctx, AV_LOG_INFO, "This is LOCO codec version %i, please upload file for study\n", version);
- }
-
- l->mode = AV_RL32(avctx->extradata + 4);
- switch(l->mode) {
- case LOCO_CYUY2: case LOCO_YUY2: case LOCO_UYVY:
- avctx->pix_fmt = PIX_FMT_YUV422P;
- break;
- case LOCO_CRGB: case LOCO_RGB:
- avctx->pix_fmt = PIX_FMT_BGR24;
- break;
- case LOCO_CYV12: case LOCO_YV12:
- avctx->pix_fmt = PIX_FMT_YUV420P;
- break;
- case LOCO_CRGBA: case LOCO_RGBA:
- avctx->pix_fmt = PIX_FMT_RGBA32;
- break;
- default:
- av_log(avctx, AV_LOG_INFO, "Unknown colorspace, index = %i\n", l->mode);
- return -1;
- }
- if(avctx->debug & FF_DEBUG_PICT_INFO)
- av_log(avctx, AV_LOG_INFO, "lossy:%i, version:%i, mode: %i\n", l->lossy, version, l->mode);
-
- return 0;
-}
-
-AVCodec loco_decoder = {
- "loco",
- CODEC_TYPE_VIDEO,
- CODEC_ID_LOCO,
- sizeof(LOCOContext),
- decode_init,
- NULL,
- NULL,
- decode_frame,
- CODEC_CAP_DR1,
-};
diff --git a/src/libffmpeg/libavcodec/lzo.c b/src/libffmpeg/libavcodec/lzo.c
deleted file mode 100644
index 0ee7eca04..000000000
--- a/src/libffmpeg/libavcodec/lzo.c
+++ /dev/null
@@ -1,268 +0,0 @@
-/*
- * LZO 1x decompression
- * Copyright (c) 2006 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 "common.h"
-//! avoid e.g. MPlayers fast_memcpy, it slows things down here
-#undef memcpy
-#include <string.h>
-#include "lzo.h"
-
-//! define if we may write up to 12 bytes beyond the output buffer
-#define OUTBUF_PADDED 1
-//! define if we may read up to 8 bytes beyond the input buffer
-#define INBUF_PADDED 1
-typedef struct LZOContext {
- uint8_t *in, *in_end;
- uint8_t *out_start, *out, *out_end;
- int error;
-} LZOContext;
-
-/**
- * \brief read one byte from input buffer, avoiding overrun
- * \return byte read
- */
-static inline int get_byte(LZOContext *c) {
- if (c->in < c->in_end)
- return *c->in++;
- c->error |= LZO_INPUT_DEPLETED;
- return 1;
-}
-
-#ifdef INBUF_PADDED
-#define GETB(c) (*(c).in++)
-#else
-#define GETB(c) get_byte(&(c))
-#endif
-
-/**
- * \brief decode a length value in the coding used by lzo
- * \param x previous byte value
- * \param mask bits used from x
- * \return decoded length value
- */
-static inline int get_len(LZOContext *c, int x, int mask) {
- int cnt = x & mask;
- if (!cnt) {
- while (!(x = get_byte(c))) cnt += 255;
- cnt += mask + x;
- }
- return cnt;
-}
-
-/**
- * \brief copy bytes from input to output buffer with checking
- * \param cnt number of bytes to copy, must be > 0
- */
-static inline void copy(LZOContext *c, int cnt) {
- register uint8_t *src = c->in;
- register uint8_t *dst = c->out;
- if (src + cnt > c->in_end || src + cnt < src) {
- cnt = c->in_end - src;
- c->error |= LZO_INPUT_DEPLETED;
- }
- if (dst + cnt > c->out_end || dst + cnt < dst) {
- cnt = c->out_end - dst;
- c->error |= LZO_OUTPUT_FULL;
- }
-#if defined(INBUF_PADDED) && defined(OUTBUF_PADDED)
- dst[0] = src[0];
- dst[1] = src[1];
- dst[2] = src[2];
- dst[3] = src[3];
- src += 4;
- dst += 4;
- cnt -= 4;
- if (cnt > 0)
-#endif
- memcpy(dst, src, cnt);
- c->in = src + cnt;
- c->out = dst + cnt;
-}
-
-/**
- * \brief copy previously decoded bytes to current position
- * \param back how many bytes back we start
- * \param cnt number of bytes to copy, must be > 0
- *
- * cnt > back is valid, this will copy the bytes we just copied,
- * thus creating a repeating pattern with a period length of back.
- */
-static inline void copy_backptr(LZOContext *c, int back, int cnt) {
- register uint8_t *src = &c->out[-back];
- register uint8_t *dst = c->out;
- if (src < c->out_start || src > dst) {
- c->error |= LZO_INVALID_BACKPTR;
- return;
- }
- if (dst + cnt > c->out_end || dst + cnt < dst) {
- cnt = c->out_end - dst;
- c->error |= LZO_OUTPUT_FULL;
- }
- if (back == 1) {
- memset(dst, *src, cnt);
- dst += cnt;
- } else {
-#ifdef OUTBUF_PADDED
- dst[0] = src[0];
- dst[1] = src[1];
- dst[2] = src[2];
- dst[3] = src[3];
- src += 4;
- dst += 4;
- cnt -= 4;
- if (cnt > 0) {
- dst[0] = src[0];
- dst[1] = src[1];
- dst[2] = src[2];
- dst[3] = src[3];
- dst[4] = src[4];
- dst[5] = src[5];
- dst[6] = src[6];
- dst[7] = src[7];
- src += 8;
- dst += 8;
- cnt -= 8;
- }
-#endif
- if (cnt > 0) {
- int blocklen = back;
- while (cnt > blocklen) {
- memcpy(dst, src, blocklen);
- dst += blocklen;
- cnt -= blocklen;
- blocklen <<= 1;
- }
- memcpy(dst, src, cnt);
- }
- dst += cnt;
- }
- c->out = dst;
-}
-
-/**
- * \brief decode LZO 1x compressed data
- * \param out output buffer
- * \param outlen size of output buffer, number of bytes left are returned here
- * \param in input buffer
- * \param inlen size of input buffer, number of bytes left are returned here
- * \return 0 on success, otherwise error flags, see lzo.h
- *
- * make sure all buffers are appropriately padded, in must provide
- * LZO_INPUT_PADDING, out must provide LZO_OUTPUT_PADDING additional bytes
- */
-int lzo1x_decode(void *out, int *outlen, void *in, int *inlen) {
- enum {COPY, BACKPTR} state = COPY;
- int x;
- LZOContext c;
- c.in = in;
- c.in_end = (uint8_t *)in + *inlen;
- c.out = c.out_start = out;
- c.out_end = (uint8_t *)out + * outlen;
- c.error = 0;
- x = GETB(c);
- if (x > 17) {
- copy(&c, x - 17);
- x = GETB(c);
- if (x < 16) c.error |= LZO_ERROR;
- }
- while (!c.error) {
- int cnt, back;
- if (x >> 4) {
- if (x >> 6) {
- cnt = (x >> 5) - 1;
- back = (GETB(c) << 3) + ((x >> 2) & 7) + 1;
- } else if (x >> 5) {
- cnt = get_len(&c, x, 31);
- x = GETB(c);
- back = (GETB(c) << 6) + (x >> 2) + 1;
- } else {
- cnt = get_len(&c, x, 7);
- back = (1 << 14) + ((x & 8) << 11);
- x = GETB(c);
- back += (GETB(c) << 6) + (x >> 2);
- if (back == (1 << 14)) {
- if (cnt != 1)
- c.error |= LZO_ERROR;
- break;
- }
- }
- } else
- switch (state) {
- case COPY:
- cnt = get_len(&c, x, 15);
- copy(&c, cnt + 3);
- x = GETB(c);
- if (x >> 4)
- continue;
- cnt = 1;
- back = (1 << 11) + (GETB(c) << 2) + (x >> 2) + 1;
- break;
- case BACKPTR:
- cnt = 0;
- back = (GETB(c) << 2) + (x >> 2) + 1;
- break;
- }
- copy_backptr(&c, back, cnt + 2);
- cnt = x & 3;
- state = cnt ? BACKPTR : COPY;
- if (cnt)
- copy(&c, cnt);
- x = GETB(c);
- if (c.in > c.in_end)
- c.error |= LZO_INPUT_DEPLETED;
- }
- *inlen = c.in_end - c.in;
- if (c.in > c.in_end)
- *inlen = 0;
- *outlen = c.out_end - c.out;
- return c.error;
-}
-
-#ifdef TEST
-#include <stdio.h>
-#include <lzo/lzo1x.h>
-#include "log.h"
-#define MAXSZ (10*1024*1024)
-int main(int argc, char *argv[]) {
- FILE *in = fopen(argv[1], "rb");
- uint8_t *orig = av_malloc(MAXSZ + 16);
- uint8_t *comp = av_malloc(2*MAXSZ + 16);
- uint8_t *decomp = av_malloc(MAXSZ + 16);
- size_t s = fread(orig, 1, MAXSZ, in);
- lzo_uint clen = 0;
- long tmp[LZO1X_MEM_COMPRESS];
- int inlen, outlen;
- int i;
- av_log_level = AV_LOG_DEBUG;
- lzo1x_999_compress(orig, s, comp, &clen, tmp);
- for (i = 0; i < 300; i++) {
-START_TIMER
- inlen = clen; outlen = MAXSZ;
- if (lzo1x_decode(decomp, &outlen, comp, &inlen))
- av_log(NULL, AV_LOG_ERROR, "decompression error\n");
-STOP_TIMER("lzod")
- }
- if (memcmp(orig, decomp, s))
- av_log(NULL, AV_LOG_ERROR, "decompression incorrect\n");
- else
- av_log(NULL, AV_LOG_ERROR, "decompression ok\n");
- return 0;
-}
-#endif
diff --git a/src/libffmpeg/libavcodec/mjpeg.c b/src/libffmpeg/libavcodec/mjpeg.c
deleted file mode 100644
index 3d4dd9cc4..000000000
--- a/src/libffmpeg/libavcodec/mjpeg.c
+++ /dev/null
@@ -1,2632 +0,0 @@
-/*
- * MJPEG encoder and decoder
- * Copyright (c) 2000, 2001 Fabrice Bellard.
- * Copyright (c) 2003 Alex Beregszaszi
- * Copyright (c) 2003-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
- *
- * Support for external huffman table, various fixes (AVID workaround),
- * aspecting, new decode_frame mechanism and apple mjpeg-b support
- * by Alex Beregszaszi <alex@naxine.org>
- */
-
-/**
- * @file mjpeg.c
- * MJPEG encoder and decoder.
- */
-
-//#define DEBUG
-#include <assert.h>
-
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-#include "bytestream.h"
-
-/* if xine's MPEG encoder is enabled, enable the encoding features in
- * this particular module */
-#if defined(XINE_MPEG_ENCODER) && !defined(CONFIG_ENCODERS)
-#define CONFIG_ENCODERS
-#endif
-
-
-/* use two quantizer tables (one for luminance and one for chrominance) */
-/* not yet working */
-#undef TWOMATRIXES
-
-typedef struct MJpegContext {
- uint8_t huff_size_dc_luminance[12]; //FIXME use array [3] instead of lumi / chrom, for easier addressing
- uint16_t huff_code_dc_luminance[12];
- uint8_t huff_size_dc_chrominance[12];
- uint16_t huff_code_dc_chrominance[12];
-
- uint8_t huff_size_ac_luminance[256];
- uint16_t huff_code_ac_luminance[256];
- uint8_t huff_size_ac_chrominance[256];
- uint16_t huff_code_ac_chrominance[256];
-} MJpegContext;
-
-/* JPEG marker codes */
-typedef enum {
- /* start of frame */
- SOF0 = 0xc0, /* baseline */
- SOF1 = 0xc1, /* extended sequential, huffman */
- SOF2 = 0xc2, /* progressive, huffman */
- SOF3 = 0xc3, /* lossless, huffman */
-
- SOF5 = 0xc5, /* differential sequential, huffman */
- SOF6 = 0xc6, /* differential progressive, huffman */
- SOF7 = 0xc7, /* differential lossless, huffman */
- JPG = 0xc8, /* reserved for JPEG extension */
- SOF9 = 0xc9, /* extended sequential, arithmetic */
- SOF10 = 0xca, /* progressive, arithmetic */
- SOF11 = 0xcb, /* lossless, arithmetic */
-
- SOF13 = 0xcd, /* differential sequential, arithmetic */
- SOF14 = 0xce, /* differential progressive, arithmetic */
- SOF15 = 0xcf, /* differential lossless, arithmetic */
-
- DHT = 0xc4, /* define huffman tables */
-
- DAC = 0xcc, /* define arithmetic-coding conditioning */
-
- /* restart with modulo 8 count "m" */
- RST0 = 0xd0,
- RST1 = 0xd1,
- RST2 = 0xd2,
- RST3 = 0xd3,
- RST4 = 0xd4,
- RST5 = 0xd5,
- RST6 = 0xd6,
- RST7 = 0xd7,
-
- SOI = 0xd8, /* start of image */
- EOI = 0xd9, /* end of image */
- SOS = 0xda, /* start of scan */
- DQT = 0xdb, /* define quantization tables */
- DNL = 0xdc, /* define number of lines */
- DRI = 0xdd, /* define restart interval */
- DHP = 0xde, /* define hierarchical progression */
- EXP = 0xdf, /* expand reference components */
-
- APP0 = 0xe0,
- APP1 = 0xe1,
- APP2 = 0xe2,
- APP3 = 0xe3,
- APP4 = 0xe4,
- APP5 = 0xe5,
- APP6 = 0xe6,
- APP7 = 0xe7,
- APP8 = 0xe8,
- APP9 = 0xe9,
- APP10 = 0xea,
- APP11 = 0xeb,
- APP12 = 0xec,
- APP13 = 0xed,
- APP14 = 0xee,
- APP15 = 0xef,
-
- JPG0 = 0xf0,
- JPG1 = 0xf1,
- JPG2 = 0xf2,
- JPG3 = 0xf3,
- JPG4 = 0xf4,
- JPG5 = 0xf5,
- JPG6 = 0xf6,
- SOF48 = 0xf7, ///< JPEG-LS
- LSE = 0xf8, ///< JPEG-LS extension parameters
- JPG9 = 0xf9,
- JPG10 = 0xfa,
- JPG11 = 0xfb,
- JPG12 = 0xfc,
- JPG13 = 0xfd,
-
- COM = 0xfe, /* comment */
-
- TEM = 0x01, /* temporary private use for arithmetic coding */
-
- /* 0x02 -> 0xbf reserved */
-} JPEG_MARKER;
-
-#if 0
-/* These are the sample quantization tables given in JPEG spec section K.1.
- * The spec says that the values given produce "good" quality, and
- * when divided by 2, "very good" quality.
- */
-static const unsigned char std_luminance_quant_tbl[64] = {
- 16, 11, 10, 16, 24, 40, 51, 61,
- 12, 12, 14, 19, 26, 58, 60, 55,
- 14, 13, 16, 24, 40, 57, 69, 56,
- 14, 17, 22, 29, 51, 87, 80, 62,
- 18, 22, 37, 56, 68, 109, 103, 77,
- 24, 35, 55, 64, 81, 104, 113, 92,
- 49, 64, 78, 87, 103, 121, 120, 101,
- 72, 92, 95, 98, 112, 100, 103, 99
-};
-static const unsigned char std_chrominance_quant_tbl[64] = {
- 17, 18, 24, 47, 99, 99, 99, 99,
- 18, 21, 26, 66, 99, 99, 99, 99,
- 24, 26, 56, 99, 99, 99, 99, 99,
- 47, 66, 99, 99, 99, 99, 99, 99,
- 99, 99, 99, 99, 99, 99, 99, 99,
- 99, 99, 99, 99, 99, 99, 99, 99,
- 99, 99, 99, 99, 99, 99, 99, 99,
- 99, 99, 99, 99, 99, 99, 99, 99
-};
-#endif
-
-/* Set up the standard Huffman tables (cf. JPEG standard section K.3) */
-/* IMPORTANT: these are only valid for 8-bit data precision! */
-static const uint8_t bits_dc_luminance[17] =
-{ /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
-static const uint8_t val_dc_luminance[] =
-{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
-
-static const uint8_t bits_dc_chrominance[17] =
-{ /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
-static const uint8_t val_dc_chrominance[] =
-{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
-
-static const uint8_t bits_ac_luminance[17] =
-{ /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
-static const uint8_t val_ac_luminance[] =
-{ 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
- 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
- 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
- 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
- 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
- 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
- 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
- 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
- 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
- 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
- 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
- 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
- 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
- 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
- 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
- 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
- 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
- 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
- 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
- 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
- 0xf9, 0xfa
-};
-
-static const uint8_t bits_ac_chrominance[17] =
-{ /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
-
-static const uint8_t val_ac_chrominance[] =
-{ 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
- 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
- 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
- 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
- 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
- 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
- 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
- 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
- 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
- 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
- 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
- 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
- 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
- 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
- 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
- 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
- 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
- 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
- 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
- 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
- 0xf9, 0xfa
-};
-
-/* isn't this function nicer than the one in the libjpeg ? */
-static void build_huffman_codes(uint8_t *huff_size, uint16_t *huff_code,
- const uint8_t *bits_table, const uint8_t *val_table)
-{
- int i, j, k,nb, code, sym;
-
- code = 0;
- k = 0;
- for(i=1;i<=16;i++) {
- nb = bits_table[i];
- for(j=0;j<nb;j++) {
- sym = val_table[k++];
- huff_size[sym] = i;
- huff_code[sym] = code;
- code++;
- }
- code <<= 1;
- }
-}
-
-#ifdef CONFIG_ENCODERS
-int mjpeg_init(MpegEncContext *s)
-{
- MJpegContext *m;
-
- m = av_malloc(sizeof(MJpegContext));
- if (!m)
- return -1;
-
- s->min_qcoeff=-1023;
- s->max_qcoeff= 1023;
-
- /* build all the huffman tables */
- build_huffman_codes(m->huff_size_dc_luminance,
- m->huff_code_dc_luminance,
- bits_dc_luminance,
- val_dc_luminance);
- build_huffman_codes(m->huff_size_dc_chrominance,
- m->huff_code_dc_chrominance,
- bits_dc_chrominance,
- val_dc_chrominance);
- build_huffman_codes(m->huff_size_ac_luminance,
- m->huff_code_ac_luminance,
- bits_ac_luminance,
- val_ac_luminance);
- build_huffman_codes(m->huff_size_ac_chrominance,
- m->huff_code_ac_chrominance,
- bits_ac_chrominance,
- val_ac_chrominance);
-
- s->mjpeg_ctx = m;
- return 0;
-}
-
-void mjpeg_close(MpegEncContext *s)
-{
- av_free(s->mjpeg_ctx);
-}
-#endif //CONFIG_ENCODERS
-
-#define PREDICT(ret, topleft, top, left, predictor)\
- switch(predictor){\
- case 1: ret= left; break;\
- case 2: ret= top; break;\
- case 3: ret= topleft; break;\
- case 4: ret= left + top - topleft; break;\
- case 5: ret= left + ((top - topleft)>>1); break;\
- case 6: ret= top + ((left - topleft)>>1); break;\
- default:\
- case 7: ret= (left + top)>>1; break;\
- }
-
-#ifdef CONFIG_ENCODERS
-static inline void put_marker(PutBitContext *p, int code)
-{
- put_bits(p, 8, 0xff);
- put_bits(p, 8, code);
-}
-
-/* table_class: 0 = DC coef, 1 = AC coefs */
-static int put_huffman_table(MpegEncContext *s, int table_class, int table_id,
- const uint8_t *bits_table, const uint8_t *value_table)
-{
- PutBitContext *p = &s->pb;
- int n, i;
-
- put_bits(p, 4, table_class);
- put_bits(p, 4, table_id);
-
- n = 0;
- for(i=1;i<=16;i++) {
- n += bits_table[i];
- put_bits(p, 8, bits_table[i]);
- }
-
- for(i=0;i<n;i++)
- put_bits(p, 8, value_table[i]);
-
- return n + 17;
-}
-
-static void jpeg_table_header(MpegEncContext *s)
-{
- PutBitContext *p = &s->pb;
- int i, j, size;
- uint8_t *ptr;
-
- /* quant matrixes */
- put_marker(p, DQT);
-#ifdef TWOMATRIXES
- put_bits(p, 16, 2 + 2 * (1 + 64));
-#else
- put_bits(p, 16, 2 + 1 * (1 + 64));
-#endif
- put_bits(p, 4, 0); /* 8 bit precision */
- put_bits(p, 4, 0); /* table 0 */
- for(i=0;i<64;i++) {
- j = s->intra_scantable.permutated[i];
- put_bits(p, 8, s->intra_matrix[j]);
- }
-#ifdef TWOMATRIXES
- put_bits(p, 4, 0); /* 8 bit precision */
- put_bits(p, 4, 1); /* table 1 */
- for(i=0;i<64;i++) {
- j = s->intra_scantable.permutated[i];
- put_bits(p, 8, s->chroma_intra_matrix[j]);
- }
-#endif
-
- /* huffman table */
- put_marker(p, DHT);
- flush_put_bits(p);
- ptr = pbBufPtr(p);
- put_bits(p, 16, 0); /* patched later */
- size = 2;
- size += put_huffman_table(s, 0, 0, bits_dc_luminance, val_dc_luminance);
- size += put_huffman_table(s, 0, 1, bits_dc_chrominance, val_dc_chrominance);
-
- size += put_huffman_table(s, 1, 0, bits_ac_luminance, val_ac_luminance);
- size += put_huffman_table(s, 1, 1, bits_ac_chrominance, val_ac_chrominance);
- ptr[0] = size >> 8;
- ptr[1] = size;
-}
-
-static void jpeg_put_comments(MpegEncContext *s)
-{
- PutBitContext *p = &s->pb;
- int size;
- uint8_t *ptr;
-
- if (s->aspect_ratio_info /* && !lossless */)
- {
- /* JFIF header */
- put_marker(p, APP0);
- put_bits(p, 16, 16);
- ff_put_string(p, "JFIF", 1); /* this puts the trailing zero-byte too */
- put_bits(p, 16, 0x0201); /* v 1.02 */
- put_bits(p, 8, 0); /* units type: 0 - aspect ratio */
- put_bits(p, 16, s->avctx->sample_aspect_ratio.num);
- put_bits(p, 16, s->avctx->sample_aspect_ratio.den);
- put_bits(p, 8, 0); /* thumbnail width */
- put_bits(p, 8, 0); /* thumbnail height */
- }
-
- /* comment */
- if(!(s->flags & CODEC_FLAG_BITEXACT)){
- put_marker(p, COM);
- flush_put_bits(p);
- ptr = pbBufPtr(p);
- put_bits(p, 16, 0); /* patched later */
- ff_put_string(p, LIBAVCODEC_IDENT, 1);
- size = strlen(LIBAVCODEC_IDENT)+3;
- ptr[0] = size >> 8;
- ptr[1] = size;
- }
-
- if( s->avctx->pix_fmt == PIX_FMT_YUV420P
- ||s->avctx->pix_fmt == PIX_FMT_YUV422P
- ||s->avctx->pix_fmt == PIX_FMT_YUV444P){
- put_marker(p, COM);
- flush_put_bits(p);
- ptr = pbBufPtr(p);
- put_bits(p, 16, 0); /* patched later */
- ff_put_string(p, "CS=ITU601", 1);
- size = strlen("CS=ITU601")+3;
- ptr[0] = size >> 8;
- ptr[1] = size;
- }
-}
-
-void mjpeg_picture_header(MpegEncContext *s)
-{
- const int lossless= s->avctx->codec_id != CODEC_ID_MJPEG;
- const int ls = s->avctx->codec_id == CODEC_ID_JPEGLS;
-
- assert(!(ls && s->mjpeg_write_tables));
-
- put_marker(&s->pb, SOI);
-
- if (!s->mjpeg_data_only_frames)
- {
- jpeg_put_comments(s);
-
- if (s->mjpeg_write_tables) jpeg_table_header(s);
-
- switch(s->avctx->codec_id){
- case CODEC_ID_MJPEG: put_marker(&s->pb, SOF0 ); break;
- case CODEC_ID_LJPEG: put_marker(&s->pb, SOF3 ); break;
- case CODEC_ID_JPEGLS: put_marker(&s->pb, SOF48); break;
- default: assert(0);
- }
-
- put_bits(&s->pb, 16, 17);
- if(lossless && s->avctx->pix_fmt == PIX_FMT_RGBA32)
- put_bits(&s->pb, 8, 9); /* 9 bits/component RCT */
- else
- put_bits(&s->pb, 8, 8); /* 8 bits/component */
- put_bits(&s->pb, 16, s->height);
- put_bits(&s->pb, 16, s->width);
- put_bits(&s->pb, 8, 3); /* 3 components */
-
- /* Y component */
- put_bits(&s->pb, 8, 1); /* component number */
- put_bits(&s->pb, 4, s->mjpeg_hsample[0]); /* H factor */
- put_bits(&s->pb, 4, s->mjpeg_vsample[0]); /* V factor */
- put_bits(&s->pb, 8, 0); /* select matrix */
-
- /* Cb component */
- put_bits(&s->pb, 8, 2); /* component number */
- put_bits(&s->pb, 4, s->mjpeg_hsample[1]); /* H factor */
- put_bits(&s->pb, 4, s->mjpeg_vsample[1]); /* V factor */
-#ifdef TWOMATRIXES
- put_bits(&s->pb, 8, lossless ? 0 : 1); /* select matrix */
-#else
- put_bits(&s->pb, 8, 0); /* select matrix */
-#endif
-
- /* Cr component */
- put_bits(&s->pb, 8, 3); /* component number */
- put_bits(&s->pb, 4, s->mjpeg_hsample[2]); /* H factor */
- put_bits(&s->pb, 4, s->mjpeg_vsample[2]); /* V factor */
-#ifdef TWOMATRIXES
- put_bits(&s->pb, 8, lossless ? 0 : 1); /* select matrix */
-#else
- put_bits(&s->pb, 8, 0); /* select matrix */
-#endif
- }
-
- /* scan header */
- put_marker(&s->pb, SOS);
- put_bits(&s->pb, 16, 12); /* length */
- put_bits(&s->pb, 8, 3); /* 3 components */
-
- /* Y component */
- put_bits(&s->pb, 8, 1); /* index */
- put_bits(&s->pb, 4, 0); /* DC huffman table index */
- put_bits(&s->pb, 4, 0); /* AC huffman table index */
-
- /* Cb component */
- put_bits(&s->pb, 8, 2); /* index */
- put_bits(&s->pb, 4, 1); /* DC huffman table index */
- put_bits(&s->pb, 4, lossless ? 0 : 1); /* AC huffman table index */
-
- /* Cr component */
- put_bits(&s->pb, 8, 3); /* index */
- put_bits(&s->pb, 4, 1); /* DC huffman table index */
- put_bits(&s->pb, 4, lossless ? 0 : 1); /* AC huffman table index */
-
- put_bits(&s->pb, 8, (lossless && !ls) ? s->avctx->prediction_method+1 : 0); /* Ss (not used) */
-
- switch(s->avctx->codec_id){
- case CODEC_ID_MJPEG: put_bits(&s->pb, 8, 63); break; /* Se (not used) */
- case CODEC_ID_LJPEG: put_bits(&s->pb, 8, 0); break; /* not used */
- case CODEC_ID_JPEGLS: put_bits(&s->pb, 8, 1); break; /* ILV = line interleaved */
- default: assert(0);
- }
-
- put_bits(&s->pb, 8, 0); /* Ah/Al (not used) */
-
- //FIXME DC/AC entropy table selectors stuff in jpegls
-}
-
-static void escape_FF(MpegEncContext *s, int start)
-{
- int size= put_bits_count(&s->pb) - start*8;
- int i, ff_count;
- uint8_t *buf= s->pb.buf + start;
- int align= (-(size_t)(buf))&3;
-
- assert((size&7) == 0);
- size >>= 3;
-
- ff_count=0;
- for(i=0; i<size && i<align; i++){
- if(buf[i]==0xFF) ff_count++;
- }
- for(; i<size-15; i+=16){
- int acc, v;
-
- v= *(uint32_t*)(&buf[i]);
- acc= (((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010;
- v= *(uint32_t*)(&buf[i+4]);
- acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010;
- v= *(uint32_t*)(&buf[i+8]);
- acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010;
- v= *(uint32_t*)(&buf[i+12]);
- acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010;
-
- acc>>=4;
- acc+= (acc>>16);
- acc+= (acc>>8);
- ff_count+= acc&0xFF;
- }
- for(; i<size; i++){
- if(buf[i]==0xFF) ff_count++;
- }
-
- if(ff_count==0) return;
-
- /* skip put bits */
- for(i=0; i<ff_count-3; i+=4)
- put_bits(&s->pb, 32, 0);
- put_bits(&s->pb, (ff_count-i)*8, 0);
- flush_put_bits(&s->pb);
-
- for(i=size-1; ff_count; i--){
- int v= buf[i];
-
- if(v==0xFF){
-//printf("%d %d\n", i, ff_count);
- buf[i+ff_count]= 0;
- ff_count--;
- }
-
- buf[i+ff_count]= v;
- }
-}
-
-void ff_mjpeg_stuffing(PutBitContext * pbc)
-{
- int length;
- length= (-put_bits_count(pbc))&7;
- if(length) put_bits(pbc, length, (1<<length)-1);
-}
-
-void mjpeg_picture_trailer(MpegEncContext *s)
-{
- ff_mjpeg_stuffing(&s->pb);
- flush_put_bits(&s->pb);
-
- assert((s->header_bits&7)==0);
-
- escape_FF(s, s->header_bits>>3);
-
- put_marker(&s->pb, EOI);
-}
-
-static inline void mjpeg_encode_dc(MpegEncContext *s, int val,
- uint8_t *huff_size, uint16_t *huff_code)
-{
- int mant, nbits;
-
- if (val == 0) {
- put_bits(&s->pb, huff_size[0], huff_code[0]);
- } else {
- mant = val;
- if (val < 0) {
- val = -val;
- mant--;
- }
-
- nbits= av_log2_16bit(val) + 1;
-
- put_bits(&s->pb, huff_size[nbits], huff_code[nbits]);
-
- put_bits(&s->pb, nbits, mant & ((1 << nbits) - 1));
- }
-}
-
-static void encode_block(MpegEncContext *s, DCTELEM *block, int n)
-{
- int mant, nbits, code, i, j;
- int component, dc, run, last_index, val;
- MJpegContext *m = s->mjpeg_ctx;
- uint8_t *huff_size_ac;
- uint16_t *huff_code_ac;
-
- /* DC coef */
- component = (n <= 3 ? 0 : (n&1) + 1);
- dc = block[0]; /* overflow is impossible */
- val = dc - s->last_dc[component];
- if (n < 4) {
- mjpeg_encode_dc(s, val, m->huff_size_dc_luminance, m->huff_code_dc_luminance);
- huff_size_ac = m->huff_size_ac_luminance;
- huff_code_ac = m->huff_code_ac_luminance;
- } else {
- mjpeg_encode_dc(s, val, m->huff_size_dc_chrominance, m->huff_code_dc_chrominance);
- huff_size_ac = m->huff_size_ac_chrominance;
- huff_code_ac = m->huff_code_ac_chrominance;
- }
- s->last_dc[component] = dc;
-
- /* AC coefs */
-
- run = 0;
- last_index = s->block_last_index[n];
- for(i=1;i<=last_index;i++) {
- j = s->intra_scantable.permutated[i];
- val = block[j];
- if (val == 0) {
- run++;
- } else {
- while (run >= 16) {
- put_bits(&s->pb, huff_size_ac[0xf0], huff_code_ac[0xf0]);
- run -= 16;
- }
- mant = val;
- if (val < 0) {
- val = -val;
- mant--;
- }
-
- nbits= av_log2(val) + 1;
- code = (run << 4) | nbits;
-
- put_bits(&s->pb, huff_size_ac[code], huff_code_ac[code]);
-
- put_bits(&s->pb, nbits, mant & ((1 << nbits) - 1));
- run = 0;
- }
- }
-
- /* output EOB only if not already 64 values */
- if (last_index < 63 || run != 0)
- put_bits(&s->pb, huff_size_ac[0], huff_code_ac[0]);
-}
-
-void mjpeg_encode_mb(MpegEncContext *s,
- DCTELEM block[6][64])
-{
- int i;
- for(i=0;i<5;i++) {
- encode_block(s, block[i], i);
- }
- if (s->chroma_format == CHROMA_420) {
- encode_block(s, block[5], 5);
- } else {
- encode_block(s, block[6], 6);
- encode_block(s, block[5], 5);
- encode_block(s, block[7], 7);
- }
-}
-
-static int encode_picture_lossless(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
- MpegEncContext * const s = avctx->priv_data;
- MJpegContext * const m = s->mjpeg_ctx;
- AVFrame *pict = data;
- const int width= s->width;
- const int height= s->height;
- AVFrame * const p= (AVFrame*)&s->current_picture;
- const int predictor= avctx->prediction_method+1;
-
- init_put_bits(&s->pb, buf, buf_size);
-
- *p = *pict;
- p->pict_type= FF_I_TYPE;
- p->key_frame= 1;
-
- mjpeg_picture_header(s);
-
- s->header_bits= put_bits_count(&s->pb);
-
- if(avctx->pix_fmt == PIX_FMT_RGBA32){
- int x, y, i;
- const int linesize= p->linesize[0];
- uint16_t (*buffer)[4]= (void *) s->rd_scratchpad;
- int left[3], top[3], topleft[3];
-
- for(i=0; i<3; i++){
- buffer[0][i]= 1 << (9 - 1);
- }
-
- for(y = 0; y < height; y++) {
- const int modified_predictor= y ? predictor : 1;
- uint8_t *ptr = p->data[0] + (linesize * y);
-
- if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < width*3*4){
- av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
- return -1;
- }
-
- for(i=0; i<3; i++){
- top[i]= left[i]= topleft[i]= buffer[0][i];
- }
- for(x = 0; x < width; x++) {
- buffer[x][1] = ptr[4*x+0] - ptr[4*x+1] + 0x100;
- buffer[x][2] = ptr[4*x+2] - ptr[4*x+1] + 0x100;
- buffer[x][0] = (ptr[4*x+0] + 2*ptr[4*x+1] + ptr[4*x+2])>>2;
-
- for(i=0;i<3;i++) {
- int pred, diff;
-
- PREDICT(pred, topleft[i], top[i], left[i], modified_predictor);
-
- topleft[i]= top[i];
- top[i]= buffer[x+1][i];
-
- left[i]= buffer[x][i];
-
- diff= ((left[i] - pred + 0x100)&0x1FF) - 0x100;
-
- if(i==0)
- mjpeg_encode_dc(s, diff, m->huff_size_dc_luminance, m->huff_code_dc_luminance); //FIXME ugly
- else
- mjpeg_encode_dc(s, diff, m->huff_size_dc_chrominance, m->huff_code_dc_chrominance);
- }
- }
- }
- }else{
- int mb_x, mb_y, i;
- const int mb_width = (width + s->mjpeg_hsample[0] - 1) / s->mjpeg_hsample[0];
- const int mb_height = (height + s->mjpeg_vsample[0] - 1) / s->mjpeg_vsample[0];
-
- for(mb_y = 0; mb_y < mb_height; mb_y++) {
- if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < mb_width * 4 * 3 * s->mjpeg_hsample[0] * s->mjpeg_vsample[0]){
- av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
- return -1;
- }
- for(mb_x = 0; mb_x < mb_width; mb_x++) {
- if(mb_x==0 || mb_y==0){
- for(i=0;i<3;i++) {
- uint8_t *ptr;
- int x, y, h, v, linesize;
- h = s->mjpeg_hsample[i];
- v = s->mjpeg_vsample[i];
- linesize= p->linesize[i];
-
- for(y=0; y<v; y++){
- for(x=0; x<h; x++){
- int pred;
-
- ptr = p->data[i] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
- if(y==0 && mb_y==0){
- if(x==0 && mb_x==0){
- pred= 128;
- }else{
- pred= ptr[-1];
- }
- }else{
- if(x==0 && mb_x==0){
- pred= ptr[-linesize];
- }else{
- PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);
- }
- }
-
- if(i==0)
- mjpeg_encode_dc(s, (int8_t)(*ptr - pred), m->huff_size_dc_luminance, m->huff_code_dc_luminance); //FIXME ugly
- else
- mjpeg_encode_dc(s, (int8_t)(*ptr - pred), m->huff_size_dc_chrominance, m->huff_code_dc_chrominance);
- }
- }
- }
- }else{
- for(i=0;i<3;i++) {
- uint8_t *ptr;
- int x, y, h, v, linesize;
- h = s->mjpeg_hsample[i];
- v = s->mjpeg_vsample[i];
- linesize= p->linesize[i];
-
- for(y=0; y<v; y++){
- for(x=0; x<h; x++){
- int pred;
-
- ptr = p->data[i] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
-//printf("%d %d %d %d %8X\n", mb_x, mb_y, x, y, ptr);
- PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);
-
- if(i==0)
- mjpeg_encode_dc(s, (int8_t)(*ptr - pred), m->huff_size_dc_luminance, m->huff_code_dc_luminance); //FIXME ugly
- else
- mjpeg_encode_dc(s, (int8_t)(*ptr - pred), m->huff_size_dc_chrominance, m->huff_code_dc_chrominance);
- }
- }
- }
- }
- }
- }
- }
-
- emms_c();
-
- mjpeg_picture_trailer(s);
- s->picture_number++;
-
- flush_put_bits(&s->pb);
- return pbBufPtr(&s->pb) - s->pb.buf;
-// return (put_bits_count(&f->pb)+7)/8;
-}
-
-#endif //CONFIG_ENCODERS
-
-/******************************************/
-/* decoding */
-
-#define MAX_COMPONENTS 4
-
-typedef struct MJpegDecodeContext {
- AVCodecContext *avctx;
- GetBitContext gb;
- int mpeg_enc_ctx_allocated; /* true if decoding context allocated */
-
- int start_code; /* current start code */
- int buffer_size;
- uint8_t *buffer;
-
- int16_t quant_matrixes[4][64];
- VLC vlcs[2][4];
- int qscale[4]; ///< quantizer scale calculated from quant_matrixes
-
- int org_height; /* size given at codec init */
- int first_picture; /* true if decoding first picture */
- int interlaced; /* true if interlaced */
- int bottom_field; /* true if bottom field */
- int lossless;
- int ls;
- int progressive;
- int rgb;
- int rct; /* standard rct */
- int pegasus_rct; /* pegasus reversible colorspace transform */
- int bits; /* bits per component */
-
- int maxval;
- int near; ///< near lossless bound (si 0 for lossless)
- int t1,t2,t3;
- int reset; ///< context halfing intervall ?rename
-
- int width, height;
- int mb_width, mb_height;
- int nb_components;
- int component_id[MAX_COMPONENTS];
- int h_count[MAX_COMPONENTS]; /* horizontal and vertical count for each component */
- int v_count[MAX_COMPONENTS];
- int comp_index[MAX_COMPONENTS];
- int dc_index[MAX_COMPONENTS];
- int ac_index[MAX_COMPONENTS];
- int nb_blocks[MAX_COMPONENTS];
- int h_scount[MAX_COMPONENTS];
- int v_scount[MAX_COMPONENTS];
- int h_max, v_max; /* maximum h and v counts */
- int quant_index[4]; /* quant table index for each component */
- int last_dc[MAX_COMPONENTS]; /* last DEQUANTIZED dc (XXX: am I right to do that ?) */
- AVFrame picture; /* picture structure */
- int linesize[MAX_COMPONENTS]; ///< linesize << interlaced
- int8_t *qscale_table;
- DECLARE_ALIGNED_8(DCTELEM, block[64]);
- ScanTable scantable;
- void (*idct_put)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
- void (*idct_add)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
-
- int restart_interval;
- int restart_count;
-
- int buggy_avid;
- int cs_itu601;
- int interlace_polarity;
-
- int mjpb_skiptosod;
-
- int cur_scan; /* current scan, used by JPEG-LS */
-} MJpegDecodeContext;
-
-#include "jpeg_ls.c" //FIXME make jpeg-ls more independant
-
-static int mjpeg_decode_dht(MJpegDecodeContext *s);
-
-static int build_vlc(VLC *vlc, const uint8_t *bits_table, const uint8_t *val_table,
- int nb_codes, int use_static, int is_ac)
-{
- uint8_t huff_size[256+16];
- uint16_t huff_code[256+16];
-
- assert(nb_codes <= 256);
-
- memset(huff_size, 0, sizeof(huff_size));
- build_huffman_codes(huff_size, huff_code, bits_table, val_table);
-
- if(is_ac){
- memmove(huff_size+16, huff_size, sizeof(uint8_t)*nb_codes);
- memmove(huff_code+16, huff_code, sizeof(uint16_t)*nb_codes);
- memset(huff_size, 0, sizeof(uint8_t)*16);
- memset(huff_code, 0, sizeof(uint16_t)*16);
- nb_codes += 16;
- }
-
- return init_vlc(vlc, 9, nb_codes, huff_size, 1, 1, huff_code, 2, 2, use_static);
-}
-
-static int mjpeg_decode_init(AVCodecContext *avctx)
-{
- MJpegDecodeContext *s = avctx->priv_data;
- MpegEncContext s2;
- memset(s, 0, sizeof(MJpegDecodeContext));
-
- s->avctx = avctx;
-
- /* ugly way to get the idct & scantable FIXME */
- memset(&s2, 0, sizeof(MpegEncContext));
- s2.avctx= avctx;
-// s2->out_format = FMT_MJPEG;
- dsputil_init(&s2.dsp, avctx);
- DCT_common_init(&s2);
-
- s->scantable= s2.intra_scantable;
- s->idct_put= s2.dsp.idct_put;
- s->idct_add= s2.dsp.idct_add;
-
- s->mpeg_enc_ctx_allocated = 0;
- s->buffer_size = 0;
- s->buffer = NULL;
- s->start_code = -1;
- s->first_picture = 1;
- s->org_height = avctx->coded_height;
-
- build_vlc(&s->vlcs[0][0], bits_dc_luminance, val_dc_luminance, 12, 0, 0);
- build_vlc(&s->vlcs[0][1], bits_dc_chrominance, val_dc_chrominance, 12, 0, 0);
- build_vlc(&s->vlcs[1][0], bits_ac_luminance, val_ac_luminance, 251, 0, 1);
- build_vlc(&s->vlcs[1][1], bits_ac_chrominance, val_ac_chrominance, 251, 0, 1);
-
- if (avctx->flags & CODEC_FLAG_EXTERN_HUFF)
- {
- av_log(avctx, AV_LOG_INFO, "mjpeg: using external huffman table\n");
- init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size*8);
- mjpeg_decode_dht(s);
- /* should check for error - but dunno */
- }
-
- return 0;
-}
-
-
-/**
- * finds the end of the current frame in the bitstream.
- * @return the position of the first byte of the next frame, or -1
- */
-static int find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size){
- int vop_found, i;
- uint16_t state;
-
- vop_found= pc->frame_start_found;
- state= pc->state;
-
- i=0;
- if(!vop_found){
- for(i=0; i<buf_size; i++){
- state= (state<<8) | buf[i];
- if(state == 0xFFD8){
- i++;
- vop_found=1;
- break;
- }
- }
- }
-
- if(vop_found){
- /* EOF considered as end of frame */
- if (buf_size == 0)
- return 0;
- for(; i<buf_size; i++){
- state= (state<<8) | buf[i];
- if(state == 0xFFD8){
- pc->frame_start_found=0;
- pc->state=0;
- return i-1;
- }
- }
- }
- pc->frame_start_found= vop_found;
- pc->state= state;
- return END_NOT_FOUND;
-}
-
-static int jpeg_parse(AVCodecParserContext *s,
- AVCodecContext *avctx,
- uint8_t **poutbuf, int *poutbuf_size,
- const uint8_t *buf, int buf_size)
-{
- ParseContext *pc = s->priv_data;
- int next;
-
- next= find_frame_end(pc, buf, buf_size);
-
- if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
- *poutbuf = NULL;
- *poutbuf_size = 0;
- return buf_size;
- }
-
- *poutbuf = (uint8_t *)buf;
- *poutbuf_size = buf_size;
- return next;
-}
-
-/* quantize tables */
-static int mjpeg_decode_dqt(MJpegDecodeContext *s)
-{
- int len, index, i, j;
-
- len = get_bits(&s->gb, 16) - 2;
-
- while (len >= 65) {
- /* only 8 bit precision handled */
- if (get_bits(&s->gb, 4) != 0)
- {
- dprintf("dqt: 16bit precision\n");
- return -1;
- }
- index = get_bits(&s->gb, 4);
- if (index >= 4)
- return -1;
- dprintf("index=%d\n", index);
- /* read quant table */
- for(i=0;i<64;i++) {
- j = s->scantable.permutated[i];
- s->quant_matrixes[index][j] = get_bits(&s->gb, 8);
- }
-
- //XXX FIXME finetune, and perhaps add dc too
- s->qscale[index]= FFMAX(
- s->quant_matrixes[index][s->scantable.permutated[1]],
- s->quant_matrixes[index][s->scantable.permutated[8]]) >> 1;
- dprintf("qscale[%d]: %d\n", index, s->qscale[index]);
- len -= 65;
- }
-
- return 0;
-}
-
-/* decode huffman tables and build VLC decoders */
-static int mjpeg_decode_dht(MJpegDecodeContext *s)
-{
- int len, index, i, class, n, v, code_max;
- uint8_t bits_table[17];
- uint8_t val_table[256];
-
- len = get_bits(&s->gb, 16) - 2;
-
- while (len > 0) {
- if (len < 17)
- return -1;
- class = get_bits(&s->gb, 4);
- if (class >= 2)
- return -1;
- index = get_bits(&s->gb, 4);
- if (index >= 4)
- return -1;
- n = 0;
- for(i=1;i<=16;i++) {
- bits_table[i] = get_bits(&s->gb, 8);
- n += bits_table[i];
- }
- len -= 17;
- if (len < n || n > 256)
- return -1;
-
- code_max = 0;
- for(i=0;i<n;i++) {
- v = get_bits(&s->gb, 8);
- if (v > code_max)
- code_max = v;
- val_table[i] = v;
- }
- len -= n;
-
- /* build VLC and flush previous vlc if present */
- free_vlc(&s->vlcs[class][index]);
- dprintf("class=%d index=%d nb_codes=%d\n",
- class, index, code_max + 1);
- if(build_vlc(&s->vlcs[class][index], bits_table, val_table, code_max + 1, 0, class > 0) < 0){
- return -1;
- }
- }
- return 0;
-}
-
-static int mjpeg_decode_sof(MJpegDecodeContext *s)
-{
- int len, nb_components, i, width, height, pix_fmt_id;
-
- /* XXX: verify len field validity */
- len = get_bits(&s->gb, 16);
- s->bits= get_bits(&s->gb, 8);
-
- if(s->pegasus_rct) s->bits=9;
- if(s->bits==9 && !s->pegasus_rct) s->rct=1; //FIXME ugly
-
- if (s->bits != 8 && !s->lossless){
- av_log(s->avctx, AV_LOG_ERROR, "only 8 bits/component accepted\n");
- return -1;
- }
-
- height = get_bits(&s->gb, 16);
- width = get_bits(&s->gb, 16);
-
- dprintf("sof0: picture: %dx%d\n", width, height);
- if(avcodec_check_dimensions(s->avctx, width, height))
- return -1;
-
- nb_components = get_bits(&s->gb, 8);
- if (nb_components <= 0 ||
- nb_components > MAX_COMPONENTS)
- return -1;
- if (s->ls && !(s->bits <= 8 || nb_components == 1)){
- av_log(s->avctx, AV_LOG_ERROR, "only <= 8 bits/component or 16-bit gray accepted for JPEG-LS\n");
- return -1;
- }
- s->nb_components = nb_components;
- s->h_max = 1;
- s->v_max = 1;
- for(i=0;i<nb_components;i++) {
- /* component id */
- s->component_id[i] = get_bits(&s->gb, 8) - 1;
- s->h_count[i] = get_bits(&s->gb, 4);
- s->v_count[i] = get_bits(&s->gb, 4);
- /* compute hmax and vmax (only used in interleaved case) */
- if (s->h_count[i] > s->h_max)
- s->h_max = s->h_count[i];
- if (s->v_count[i] > s->v_max)
- s->v_max = s->v_count[i];
- s->quant_index[i] = get_bits(&s->gb, 8);
- if (s->quant_index[i] >= 4)
- return -1;
- dprintf("component %d %d:%d id: %d quant:%d\n", i, s->h_count[i],
- s->v_count[i], s->component_id[i], s->quant_index[i]);
- }
-
- if(s->ls && (s->h_max > 1 || s->v_max > 1)) {
- av_log(s->avctx, AV_LOG_ERROR, "Subsampling in JPEG-LS is not supported.\n");
- return -1;
- }
-
- if(s->v_max==1 && s->h_max==1 && s->lossless==1) s->rgb=1;
-
- /* if different size, realloc/alloc picture */
- /* XXX: also check h_count and v_count */
- if (width != s->width || height != s->height) {
- av_freep(&s->qscale_table);
-
- s->width = width;
- s->height = height;
-
- /* test interlaced mode */
- if (s->first_picture &&
- s->org_height != 0 &&
- s->height < ((s->org_height * 3) / 4)) {
- s->interlaced = 1;
-// s->bottom_field = (s->interlace_polarity) ? 1 : 0;
- s->bottom_field = 0;
- height *= 2;
- }
-
- avcodec_set_dimensions(s->avctx, width, height);
-
- s->qscale_table= av_mallocz((s->width+15)/16);
-
- s->first_picture = 0;
- }
-
- if(s->interlaced && s->bottom_field)
- return 0;
-
- /* XXX: not complete test ! */
- pix_fmt_id = (s->h_count[0] << 20) | (s->v_count[0] << 16) |
- (s->h_count[1] << 12) | (s->v_count[1] << 8) |
- (s->h_count[2] << 4) | s->v_count[2];
- dprintf("pix fmt id %x\n", pix_fmt_id);
- switch(pix_fmt_id){
- case 0x222222:
- case 0x111111:
- if(s->rgb){
- s->avctx->pix_fmt = PIX_FMT_RGBA32;
- }else if(s->nb_components==3)
- s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV444P : PIX_FMT_YUVJ444P;
- else
- s->avctx->pix_fmt = PIX_FMT_GRAY8;
- break;
- case 0x211111:
- case 0x221212:
- s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV422P : PIX_FMT_YUVJ422P;
- break;
- default:
- case 0x221111:
- s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV420P : PIX_FMT_YUVJ420P;
- break;
- }
- if(s->ls){
- if(s->nb_components > 1)
- s->avctx->pix_fmt = PIX_FMT_RGB24;
- else if(s->bits <= 8)
- s->avctx->pix_fmt = PIX_FMT_GRAY8;
- else
- s->avctx->pix_fmt = PIX_FMT_GRAY16;
- }
-
- if(s->picture.data[0])
- s->avctx->release_buffer(s->avctx, &s->picture);
-
- s->picture.reference= 0;
- if(s->avctx->get_buffer(s->avctx, &s->picture) < 0){
- av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
- return -1;
- }
- s->picture.pict_type= I_TYPE;
- s->picture.key_frame= 1;
-
- for(i=0; i<3; i++){
- s->linesize[i]= s->picture.linesize[i] << s->interlaced;
- }
-
-// printf("%d %d %d %d %d %d\n", s->width, s->height, s->linesize[0], s->linesize[1], s->interlaced, s->avctx->height);
-
- if (len != (8+(3*nb_components)))
- {
- dprintf("decode_sof0: error, len(%d) mismatch\n", len);
- }
-
- /* totally blank picture as progressive JPEG will only add details to it */
- if(s->progressive){
- memset(s->picture.data[0], 0, s->picture.linesize[0] * s->height);
- memset(s->picture.data[1], 0, s->picture.linesize[1] * s->height >> (s->v_max - s->v_count[1]));
- memset(s->picture.data[2], 0, s->picture.linesize[2] * s->height >> (s->v_max - s->v_count[2]));
- }
- return 0;
-}
-
-static inline int mjpeg_decode_dc(MJpegDecodeContext *s, int dc_index)
-{
- int code;
- code = get_vlc2(&s->gb, s->vlcs[0][dc_index].table, 9, 2);
- if (code < 0)
- {
- dprintf("mjpeg_decode_dc: bad vlc: %d:%d (%p)\n", 0, dc_index,
- &s->vlcs[0][dc_index]);
- return 0xffff;
- }
-
- if(code)
- return get_xbits(&s->gb, code);
- else
- return 0;
-}
-
-/* decode block and dequantize */
-static int decode_block(MJpegDecodeContext *s, DCTELEM *block,
- int component, int dc_index, int ac_index, int16_t *quant_matrix)
-{
- int code, i, j, level, val;
-
- /* DC coef */
- val = mjpeg_decode_dc(s, dc_index);
- if (val == 0xffff) {
- dprintf("error dc\n");
- return -1;
- }
- val = val * quant_matrix[0] + s->last_dc[component];
- s->last_dc[component] = val;
- block[0] = val;
- /* AC coefs */
- i = 0;
- {OPEN_READER(re, &s->gb)
- for(;;) {
- UPDATE_CACHE(re, &s->gb);
- GET_VLC(code, re, &s->gb, s->vlcs[1][ac_index].table, 9, 2)
-
- /* EOB */
- if (code == 0x10)
- break;
- i += ((unsigned)code) >> 4;
- if(code != 0x100){
- code &= 0xf;
- if(code > MIN_CACHE_BITS - 16){
- UPDATE_CACHE(re, &s->gb)
- }
- {
- int cache=GET_CACHE(re,&s->gb);
- int sign=(~cache)>>31;
- level = (NEG_USR32(sign ^ cache,code) ^ sign) - sign;
- }
-
- LAST_SKIP_BITS(re, &s->gb, code)
-
- if (i >= 63) {
- if(i == 63){
- j = s->scantable.permutated[63];
- block[j] = level * quant_matrix[j];
- break;
- }
- dprintf("error count: %d\n", i);
- return -1;
- }
- j = s->scantable.permutated[i];
- block[j] = level * quant_matrix[j];
- }
- }
- CLOSE_READER(re, &s->gb)}
-
- return 0;
-}
-
-/* decode block and dequantize - progressive JPEG version */
-static int decode_block_progressive(MJpegDecodeContext *s, DCTELEM *block,
- int component, int dc_index, int ac_index, int16_t *quant_matrix,
- int ss, int se, int Ah, int Al, int *EOBRUN)
-{
- int code, i, j, level, val, run;
-
- /* DC coef */
- if(!ss){
- val = mjpeg_decode_dc(s, dc_index);
- if (val == 0xffff) {
- dprintf("error dc\n");
- return -1;
- }
- val = (val * quant_matrix[0] << Al) + s->last_dc[component];
- }else
- val = 0;
- s->last_dc[component] = val;
- block[0] = val;
- if(!se) return 0;
- /* AC coefs */
- if(*EOBRUN){
- (*EOBRUN)--;
- return 0;
- }
- {OPEN_READER(re, &s->gb)
- for(i=ss;;i++) {
- UPDATE_CACHE(re, &s->gb);
- GET_VLC(code, re, &s->gb, s->vlcs[1][ac_index].table, 9, 2)
- /* Progressive JPEG use AC coeffs from zero and this decoder sets offset 16 by default */
- code -= 16;
- if(code & 0xF) {
- i += ((unsigned) code) >> 4;
- code &= 0xf;
- if(code > MIN_CACHE_BITS - 16){
- UPDATE_CACHE(re, &s->gb)
- }
- {
- int cache=GET_CACHE(re,&s->gb);
- int sign=(~cache)>>31;
- level = (NEG_USR32(sign ^ cache,code) ^ sign) - sign;
- }
-
- LAST_SKIP_BITS(re, &s->gb, code)
-
- if (i >= se) {
- if(i == se){
- j = s->scantable.permutated[se];
- block[j] = level * quant_matrix[j] << Al;
- break;
- }
- dprintf("error count: %d\n", i);
- return -1;
- }
- j = s->scantable.permutated[i];
- block[j] = level * quant_matrix[j] << Al;
- }else{
- run = ((unsigned) code) >> 4;
- if(run == 0xF){// ZRL - skip 15 coefficients
- i += 15;
- }else{
- val = run;
- run = (1 << run);
- UPDATE_CACHE(re, &s->gb);
- run += (GET_CACHE(re, &s->gb) >> (32 - val)) & (run - 1);
- if(val)
- LAST_SKIP_BITS(re, &s->gb, val);
- *EOBRUN = run - 1;
- break;
- }
- }
- }
- CLOSE_READER(re, &s->gb)}
-
- return 0;
-}
-
-static int ljpeg_decode_rgb_scan(MJpegDecodeContext *s, int predictor, int point_transform){
- int i, mb_x, mb_y;
- uint16_t buffer[32768][4];
- int left[3], top[3], topleft[3];
- const int linesize= s->linesize[0];
- const int mask= (1<<s->bits)-1;
-
- if((unsigned)s->mb_width > 32768) //dynamic alloc
- return -1;
-
- for(i=0; i<3; i++){
- buffer[0][i]= 1 << (s->bits + point_transform - 1);
- }
- for(mb_y = 0; mb_y < s->mb_height; mb_y++) {
- const int modified_predictor= mb_y ? predictor : 1;
- uint8_t *ptr = s->picture.data[0] + (linesize * mb_y);
-
- if (s->interlaced && s->bottom_field)
- ptr += linesize >> 1;
-
- for(i=0; i<3; i++){
- top[i]= left[i]= topleft[i]= buffer[0][i];
- }
- for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
- if (s->restart_interval && !s->restart_count)
- s->restart_count = s->restart_interval;
-
- for(i=0;i<3;i++) {
- int pred;
-
- topleft[i]= top[i];
- top[i]= buffer[mb_x][i];
-
- PREDICT(pred, topleft[i], top[i], left[i], modified_predictor);
-
- left[i]=
- buffer[mb_x][i]= mask & (pred + (mjpeg_decode_dc(s, s->dc_index[i]) << point_transform));
- }
-
- if (s->restart_interval && !--s->restart_count) {
- align_get_bits(&s->gb);
- skip_bits(&s->gb, 16); /* skip RSTn */
- }
- }
-
- if(s->rct){
- for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
- ptr[4*mb_x+1] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2] - 0x200)>>2);
- ptr[4*mb_x+0] = buffer[mb_x][1] + ptr[4*mb_x+1];
- ptr[4*mb_x+2] = buffer[mb_x][2] + ptr[4*mb_x+1];
- }
- }else if(s->pegasus_rct){
- for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
- ptr[4*mb_x+1] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2])>>2);
- ptr[4*mb_x+0] = buffer[mb_x][1] + ptr[4*mb_x+1];
- ptr[4*mb_x+2] = buffer[mb_x][2] + ptr[4*mb_x+1];
- }
- }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+1] = buffer[mb_x][1];
- ptr[4*mb_x+2] = buffer[mb_x][2];
- }
- }
- }
- return 0;
-}
-
-static int ljpeg_decode_yuv_scan(MJpegDecodeContext *s, int predictor, int point_transform){
- int i, mb_x, mb_y;
- const int nb_components=3;
-
- for(mb_y = 0; mb_y < s->mb_height; mb_y++) {
- for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
- if (s->restart_interval && !s->restart_count)
- s->restart_count = s->restart_interval;
-
- if(mb_x==0 || mb_y==0 || s->interlaced){
- for(i=0;i<nb_components;i++) {
- uint8_t *ptr;
- int n, h, v, x, y, c, j, linesize;
- n = s->nb_blocks[i];
- c = s->comp_index[i];
- h = s->h_scount[i];
- v = s->v_scount[i];
- x = 0;
- y = 0;
- linesize= s->linesize[c];
-
- for(j=0; j<n; j++) {
- int pred;
-
- ptr = s->picture.data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
- if(y==0 && mb_y==0){
- if(x==0 && mb_x==0){
- pred= 128 << point_transform;
- }else{
- pred= ptr[-1];
- }
- }else{
- if(x==0 && mb_x==0){
- pred= ptr[-linesize];
- }else{
- PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);
- }
- }
-
- if (s->interlaced && s->bottom_field)
- ptr += linesize >> 1;
- *ptr= pred + (mjpeg_decode_dc(s, s->dc_index[i]) << point_transform);
-
- if (++x == h) {
- x = 0;
- y++;
- }
- }
- }
- }else{
- for(i=0;i<nb_components;i++) {
- uint8_t *ptr;
- int n, h, v, x, y, c, j, linesize;
- n = s->nb_blocks[i];
- c = s->comp_index[i];
- h = s->h_scount[i];
- v = s->v_scount[i];
- x = 0;
- y = 0;
- linesize= s->linesize[c];
-
- for(j=0; j<n; j++) {
- int pred;
-
- ptr = s->picture.data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
- PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);
- *ptr= pred + (mjpeg_decode_dc(s, s->dc_index[i]) << point_transform);
- if (++x == h) {
- x = 0;
- y++;
- }
- }
- }
- }
- if (s->restart_interval && !--s->restart_count) {
- align_get_bits(&s->gb);
- skip_bits(&s->gb, 16); /* skip RSTn */
- }
- }
- }
- return 0;
-}
-
-static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int ss, int se, int Ah, int Al){
- int i, mb_x, mb_y;
- int EOBRUN = 0;
-
- if(Ah) return 0; /* TODO decode refinement planes too */
- for(mb_y = 0; mb_y < s->mb_height; mb_y++) {
- for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
- if (s->restart_interval && !s->restart_count)
- s->restart_count = s->restart_interval;
-
- for(i=0;i<nb_components;i++) {
- uint8_t *ptr;
- int n, h, v, x, y, c, j;
- n = s->nb_blocks[i];
- c = s->comp_index[i];
- h = s->h_scount[i];
- v = s->v_scount[i];
- x = 0;
- y = 0;
- for(j=0;j<n;j++) {
- memset(s->block, 0, sizeof(s->block));
- if (!s->progressive && decode_block(s, s->block, i,
- s->dc_index[i], s->ac_index[i],
- s->quant_matrixes[ s->quant_index[c] ]) < 0) {
- dprintf("error y=%d x=%d\n", mb_y, mb_x);
- return -1;
- }
- if (s->progressive && decode_block_progressive(s, s->block, i,
- s->dc_index[i], s->ac_index[i],
- s->quant_matrixes[ s->quant_index[c] ], ss, se, Ah, Al, &EOBRUN) < 0) {
- dprintf("error y=%d x=%d\n", mb_y, mb_x);
- return -1;
- }
-// dprintf("mb: %d %d processed\n", mb_y, mb_x);
- ptr = s->picture.data[c] +
- (((s->linesize[c] * (v * mb_y + y) * 8) +
- (h * mb_x + x) * 8) >> s->avctx->lowres);
- if (s->interlaced && s->bottom_field)
- ptr += s->linesize[c] >> 1;
-//av_log(NULL, AV_LOG_DEBUG, "%d %d %d %d %d %d %d %d \n", mb_x, mb_y, x, y, c, s->bottom_field, (v * mb_y + y) * 8, (h * mb_x + x) * 8);
- if(!s->progressive)
- s->idct_put(ptr, s->linesize[c], s->block);
- else
- s->idct_add(ptr, s->linesize[c], s->block);
- if (++x == h) {
- x = 0;
- y++;
- }
- }
- }
- /* (< 1350) buggy workaround for Spectralfan.mov, should be fixed */
- if (s->restart_interval && (s->restart_interval < 1350) &&
- !--s->restart_count) {
- align_get_bits(&s->gb);
- skip_bits(&s->gb, 16); /* skip RSTn */
- for (i=0; i<nb_components; i++) /* reset dc */
- s->last_dc[i] = 1024;
- }
- }
- }
- return 0;
-}
-
-static int mjpeg_decode_sos(MJpegDecodeContext *s)
-{
- int len, nb_components, i, h, v, predictor, point_transform;
- int vmax, hmax, index, id;
- const int block_size= s->lossless ? 1 : 8;
- int ilv, prev_shift;
-
- /* XXX: verify len field validity */
- len = get_bits(&s->gb, 16);
- nb_components = get_bits(&s->gb, 8);
- if (len != 6+2*nb_components)
- {
- dprintf("decode_sos: invalid len (%d)\n", len);
- return -1;
- }
- vmax = 0;
- hmax = 0;
- for(i=0;i<nb_components;i++) {
- id = get_bits(&s->gb, 8) - 1;
- dprintf("component: %d\n", id);
- /* find component index */
- for(index=0;index<s->nb_components;index++)
- if (id == s->component_id[index])
- break;
- if (index == s->nb_components)
- {
- dprintf("decode_sos: index(%d) out of components\n", index);
- return -1;
- }
-
- s->comp_index[i] = index;
-
- s->nb_blocks[i] = s->h_count[index] * s->v_count[index];
- s->h_scount[i] = s->h_count[index];
- s->v_scount[i] = s->v_count[index];
-
- s->dc_index[i] = get_bits(&s->gb, 4);
- s->ac_index[i] = get_bits(&s->gb, 4);
-
- if (s->dc_index[i] < 0 || s->ac_index[i] < 0 ||
- s->dc_index[i] >= 4 || s->ac_index[i] >= 4)
- goto out_of_range;
-#if 0 //buggy
- switch(s->start_code)
- {
- case SOF0:
- if (dc_index[i] > 1 || ac_index[i] > 1)
- goto out_of_range;
- break;
- case SOF1:
- case SOF2:
- if (dc_index[i] > 3 || ac_index[i] > 3)
- goto out_of_range;
- break;
- case SOF3:
- if (dc_index[i] > 3 || ac_index[i] != 0)
- goto out_of_range;
- break;
- }
-#endif
- }
-
- predictor= get_bits(&s->gb, 8); /* JPEG Ss / lossless JPEG predictor /JPEG-LS NEAR */
- ilv= get_bits(&s->gb, 8); /* JPEG Se / JPEG-LS ILV */
- prev_shift = get_bits(&s->gb, 4); /* Ah */
- point_transform= get_bits(&s->gb, 4); /* Al */
-
- for(i=0;i<nb_components;i++)
- s->last_dc[i] = 1024;
-
- if (nb_components > 1) {
- /* interleaved stream */
- s->mb_width = (s->width + s->h_max * block_size - 1) / (s->h_max * block_size);
- s->mb_height = (s->height + s->v_max * block_size - 1) / (s->v_max * block_size);
- } else if(!s->ls) { /* skip this for JPEG-LS */
- h = s->h_max / s->h_scount[0];
- v = s->v_max / s->v_scount[0];
- s->mb_width = (s->width + h * block_size - 1) / (h * block_size);
- s->mb_height = (s->height + v * block_size - 1) / (v * block_size);
- s->nb_blocks[0] = 1;
- s->h_scount[0] = 1;
- s->v_scount[0] = 1;
- }
-
- 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" : "",
- predictor, point_transform, ilv, s->bits,
- s->pegasus_rct ? "PRCT" : (s->rct ? "RCT" : ""));
-
-
- /* mjpeg-b can have padding bytes between sos and image data, skip them */
- for (i = s->mjpb_skiptosod; i > 0; i--)
- skip_bits(&s->gb, 8);
-
- if(s->lossless){
- if(s->ls){
-// for(){
-// reset_ls_coding_parameters(s, 0);
-
- ls_decode_picture(s, predictor, point_transform, ilv);
- }else{
- if(s->rgb){
- if(ljpeg_decode_rgb_scan(s, predictor, point_transform) < 0)
- return -1;
- }else{
- if(ljpeg_decode_yuv_scan(s, predictor, point_transform) < 0)
- return -1;
- }
- }
- }else{
- if(mjpeg_decode_scan(s, nb_components, predictor, ilv, prev_shift, point_transform) < 0)
- return -1;
- }
- emms_c();
- return 0;
- out_of_range:
- dprintf("decode_sos: ac/dc index out of range\n");
- return -1;
-}
-
-static int mjpeg_decode_dri(MJpegDecodeContext *s)
-{
- if (get_bits(&s->gb, 16) != 4)
- return -1;
- s->restart_interval = get_bits(&s->gb, 16);
- s->restart_count = 0;
- dprintf("restart interval: %d\n", s->restart_interval);
-
- return 0;
-}
-
-static int mjpeg_decode_app(MJpegDecodeContext *s)
-{
- int len, id;
-
- len = get_bits(&s->gb, 16);
- if (len < 5)
- return -1;
- if(8*len + get_bits_count(&s->gb) > s->gb.size_in_bits)
- return -1;
-
- id = (get_bits(&s->gb, 16) << 16) | get_bits(&s->gb, 16);
- id = be2me_32(id);
- len -= 6;
-
- if(s->avctx->debug & FF_DEBUG_STARTCODE){
- av_log(s->avctx, AV_LOG_DEBUG, "APPx %8X\n", id);
- }
-
- /* buggy AVID, it puts EOI only at every 10th frame */
- /* also this fourcc is used by non-avid files too, it holds some
- informations, but it's always present in AVID creates files */
- if (id == ff_get_fourcc("AVI1"))
- {
- /* structure:
- 4bytes AVI1
- 1bytes polarity
- 1bytes always zero
- 4bytes field_size
- 4bytes field_size_less_padding
- */
- s->buggy_avid = 1;
-// if (s->first_picture)
-// printf("mjpeg: workarounding buggy AVID\n");
- s->interlace_polarity = get_bits(&s->gb, 8);
-#if 0
- skip_bits(&s->gb, 8);
- skip_bits(&s->gb, 32);
- skip_bits(&s->gb, 32);
- len -= 10;
-#endif
-// if (s->interlace_polarity)
-// printf("mjpeg: interlace polarity: %d\n", s->interlace_polarity);
- goto out;
- }
-
-// len -= 2;
-
- if (id == ff_get_fourcc("JFIF"))
- {
- int t_w, t_h, v1, v2;
- skip_bits(&s->gb, 8); /* the trailing zero-byte */
- v1= get_bits(&s->gb, 8);
- v2= get_bits(&s->gb, 8);
- skip_bits(&s->gb, 8);
-
- s->avctx->sample_aspect_ratio.num= get_bits(&s->gb, 16);
- s->avctx->sample_aspect_ratio.den= get_bits(&s->gb, 16);
-
- if (s->avctx->debug & FF_DEBUG_PICT_INFO)
- av_log(s->avctx, AV_LOG_INFO, "mjpeg: JFIF header found (version: %x.%x) SAR=%d/%d\n",
- v1, v2,
- s->avctx->sample_aspect_ratio.num,
- s->avctx->sample_aspect_ratio.den
- );
-
- t_w = get_bits(&s->gb, 8);
- t_h = get_bits(&s->gb, 8);
- if (t_w && t_h)
- {
- /* skip thumbnail */
- if (len-10-(t_w*t_h*3) > 0)
- len -= t_w*t_h*3;
- }
- len -= 10;
- goto out;
- }
-
- if (id == ff_get_fourcc("Adob") && (get_bits(&s->gb, 8) == 'e'))
- {
- if (s->avctx->debug & FF_DEBUG_PICT_INFO)
- av_log(s->avctx, AV_LOG_INFO, "mjpeg: Adobe header found\n");
- skip_bits(&s->gb, 16); /* version */
- skip_bits(&s->gb, 16); /* flags0 */
- skip_bits(&s->gb, 16); /* flags1 */
- skip_bits(&s->gb, 8); /* transform */
- len -= 7;
- goto out;
- }
-
- if (id == ff_get_fourcc("LJIF")){
- if (s->avctx->debug & FF_DEBUG_PICT_INFO)
- av_log(s->avctx, AV_LOG_INFO, "Pegasus lossless jpeg header found\n");
- skip_bits(&s->gb, 16); /* version ? */
- skip_bits(&s->gb, 16); /* unknwon always 0? */
- skip_bits(&s->gb, 16); /* unknwon always 0? */
- skip_bits(&s->gb, 16); /* unknwon always 0? */
- switch( get_bits(&s->gb, 8)){
- case 1:
- s->rgb= 1;
- s->pegasus_rct=0;
- break;
- case 2:
- s->rgb= 1;
- s->pegasus_rct=1;
- break;
- default:
- av_log(s->avctx, AV_LOG_ERROR, "unknown colorspace\n");
- }
- len -= 9;
- goto out;
- }
-
- /* Apple MJPEG-A */
- if ((s->start_code == APP1) && (len > (0x28 - 8)))
- {
- id = (get_bits(&s->gb, 16) << 16) | get_bits(&s->gb, 16);
- id = be2me_32(id);
- len -= 4;
- if (id == ff_get_fourcc("mjpg")) /* Apple MJPEG-A */
- {
-#if 0
- skip_bits(&s->gb, 32); /* field size */
- skip_bits(&s->gb, 32); /* pad field size */
- skip_bits(&s->gb, 32); /* next off */
- skip_bits(&s->gb, 32); /* quant off */
- skip_bits(&s->gb, 32); /* huff off */
- skip_bits(&s->gb, 32); /* image off */
- skip_bits(&s->gb, 32); /* scan off */
- skip_bits(&s->gb, 32); /* data off */
-#endif
- if (s->avctx->debug & FF_DEBUG_PICT_INFO)
- av_log(s->avctx, AV_LOG_INFO, "mjpeg: Apple MJPEG-A header found\n");
- }
- }
-
-out:
- /* slow but needed for extreme adobe jpegs */
- if (len < 0)
- av_log(s->avctx, AV_LOG_ERROR, "mjpeg: error, decode_app parser read over the end\n");
- while(--len > 0)
- skip_bits(&s->gb, 8);
-
- return 0;
-}
-
-static int mjpeg_decode_com(MJpegDecodeContext *s)
-{
- int len = get_bits(&s->gb, 16);
- if (len >= 2 && 8*len - 16 + get_bits_count(&s->gb) <= s->gb.size_in_bits) {
- char *cbuf = av_malloc(len - 1);
- if (cbuf) {
- int i;
- for (i = 0; i < len - 2; i++)
- cbuf[i] = get_bits(&s->gb, 8);
- if (i > 0 && cbuf[i-1] == '\n')
- cbuf[i-1] = 0;
- else
- cbuf[i] = 0;
-
- if(s->avctx->debug & FF_DEBUG_PICT_INFO)
- av_log(s->avctx, AV_LOG_INFO, "mjpeg comment: '%s'\n", cbuf);
-
- /* buggy avid, it puts EOI only at every 10th frame */
- if (!strcmp(cbuf, "AVID"))
- {
- s->buggy_avid = 1;
- // if (s->first_picture)
- // printf("mjpeg: workarounding buggy AVID\n");
- }
- else if(!strcmp(cbuf, "CS=ITU601")){
- s->cs_itu601= 1;
- }
-
- av_free(cbuf);
- }
- }
-
- return 0;
-}
-
-#if 0
-static int valid_marker_list[] =
-{
- /* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f */
-/* 0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* 1 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* 2 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* 3 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* 4 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* 5 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* 6 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* 7 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* 8 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* 9 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* a */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* b */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* c */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-/* d */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-/* e */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-/* f */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
-}
-#endif
-
-/* return the 8 bit start code value and update the search
- state. Return -1 if no start code found */
-static int find_marker(uint8_t **pbuf_ptr, uint8_t *buf_end)
-{
- uint8_t *buf_ptr;
- unsigned int v, v2;
- int val;
-#ifdef DEBUG
- int skipped=0;
-#endif
-
- buf_ptr = *pbuf_ptr;
- while (buf_ptr < buf_end) {
- v = *buf_ptr++;
- v2 = *buf_ptr;
- if ((v == 0xff) && (v2 >= 0xc0) && (v2 <= 0xfe) && buf_ptr < buf_end) {
- val = *buf_ptr++;
- goto found;
- }
-#ifdef DEBUG
- skipped++;
-#endif
- }
- val = -1;
-found:
-#ifdef DEBUG
- dprintf("find_marker skipped %d bytes\n", skipped);
-#endif
- *pbuf_ptr = buf_ptr;
- return val;
-}
-
-static int mjpeg_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- MJpegDecodeContext *s = avctx->priv_data;
- uint8_t *buf_end, *buf_ptr;
- int start_code;
- AVFrame *picture = data;
-
- buf_ptr = buf;
- buf_end = buf + buf_size;
- while (buf_ptr < buf_end) {
- /* find start next marker */
- start_code = find_marker(&buf_ptr, buf_end);
- {
- /* EOF */
- if (start_code < 0) {
- goto the_end;
- } else {
- dprintf("marker=%x avail_size_in_buf=%d\n", start_code, buf_end - buf_ptr);
-
- if ((buf_end - buf_ptr) > s->buffer_size)
- {
- av_free(s->buffer);
- s->buffer_size = buf_end-buf_ptr;
- s->buffer = av_malloc(s->buffer_size + FF_INPUT_BUFFER_PADDING_SIZE);
- dprintf("buffer too small, expanding to %d bytes\n",
- s->buffer_size);
- }
-
- /* unescape buffer of SOS, use special treatment for JPEG-LS */
- if (start_code == SOS && !s->ls)
- {
- uint8_t *src = buf_ptr;
- uint8_t *dst = s->buffer;
-
- while (src<buf_end)
- {
- uint8_t x = *(src++);
-
- *(dst++) = x;
- if (x == 0xff)
- {
- while(src<buf_end && x == 0xff)
- x = *(src++);
-
- if (x >= 0xd0 && x <= 0xd7)
- *(dst++) = x;
- else if (x)
- break;
- }
- }
- init_get_bits(&s->gb, s->buffer, (dst - s->buffer)*8);
-
- dprintf("escaping removed %d bytes\n",
- (buf_end - buf_ptr) - (dst - s->buffer));
- }
- else if(start_code == SOS && s->ls){
- uint8_t *src = buf_ptr;
- uint8_t *dst = s->buffer;
- int bit_count = 0;
- int t = 0, b = 0;
- PutBitContext pb;
-
- s->cur_scan++;
-
- /* find marker */
- while (src + t < buf_end){
- uint8_t x = src[t++];
- if (x == 0xff){
- while((src + t < buf_end) && x == 0xff)
- x = src[t++];
- if (x & 0x80) {
- t -= 2;
- break;
- }
- }
- }
- bit_count = t * 8;
-
- init_put_bits(&pb, dst, t);
-
- /* unescape bitstream */
- while(b < t){
- uint8_t x = src[b++];
- put_bits(&pb, 8, x);
- if(x == 0xFF){
- x = src[b++];
- put_bits(&pb, 7, x);
- bit_count--;
- }
- }
- flush_put_bits(&pb);
-
- init_get_bits(&s->gb, dst, bit_count);
- }
- else
- init_get_bits(&s->gb, buf_ptr, (buf_end - buf_ptr)*8);
-
- s->start_code = start_code;
- if(s->avctx->debug & FF_DEBUG_STARTCODE){
- av_log(s->avctx, AV_LOG_DEBUG, "startcode: %X\n", start_code);
- }
-
- /* process markers */
- if (start_code >= 0xd0 && start_code <= 0xd7) {
- dprintf("restart marker: %d\n", start_code&0x0f);
- /* APP fields */
- } else if (start_code >= APP0 && start_code <= APP15) {
- mjpeg_decode_app(s);
- /* Comment */
- } else if (start_code == COM){
- mjpeg_decode_com(s);
- }
-
- switch(start_code) {
- case SOI:
- s->restart_interval = 0;
-
- s->restart_count = 0;
- /* nothing to do on SOI */
- break;
- case DQT:
- mjpeg_decode_dqt(s);
- break;
- case DHT:
- if(mjpeg_decode_dht(s) < 0){
- av_log(s->avctx, AV_LOG_ERROR, "huffman table decode error\n");
- return -1;
- }
- break;
- case SOF0:
- s->lossless=0;
- s->progressive=0;
- if (mjpeg_decode_sof(s) < 0)
- return -1;
- break;
- case SOF2:
- s->lossless=0;
- s->progressive=1;
- if (mjpeg_decode_sof(s) < 0)
- return -1;
- break;
- case SOF3:
- s->lossless=1;
- s->progressive=0;
- if (mjpeg_decode_sof(s) < 0)
- return -1;
- break;
- case SOF48:
- s->lossless=1;
- s->ls=1;
- s->progressive=0;
- if (mjpeg_decode_sof(s) < 0)
- return -1;
- break;
- case LSE:
- if (decode_lse(s) < 0)
- return -1;
- break;
- case EOI:
- s->cur_scan = 0;
- if ((s->buggy_avid && !s->interlaced) || s->restart_interval)
- break;
-eoi_parser:
- {
- if (s->interlaced) {
- s->bottom_field ^= 1;
- /* if not bottom field, do not output image yet */
- if (s->bottom_field)
- goto not_the_end;
- }
- *picture = s->picture;
- *data_size = sizeof(AVFrame);
-
- if(!s->lossless){
- picture->quality= FFMAX(FFMAX(s->qscale[0], s->qscale[1]), s->qscale[2]);
- picture->qstride= 0;
- picture->qscale_table= s->qscale_table;
- memset(picture->qscale_table, picture->quality, (s->width+15)/16);
- if(avctx->debug & FF_DEBUG_QP)
- av_log(s->avctx, AV_LOG_DEBUG, "QP: %d\n", picture->quality);
- picture->quality*= FF_QP2LAMBDA;
- }
-
- goto the_end;
- }
- break;
- case SOS:
- mjpeg_decode_sos(s);
- /* buggy avid puts EOI every 10-20th frame */
- /* if restart period is over process EOI */
- if ((s->buggy_avid && !s->interlaced) || s->restart_interval)
- goto eoi_parser;
- break;
- case DRI:
- mjpeg_decode_dri(s);
- break;
- case SOF1:
- case SOF5:
- case SOF6:
- case SOF7:
- case SOF9:
- case SOF10:
- case SOF11:
- case SOF13:
- case SOF14:
- case SOF15:
- case JPG:
- av_log(s->avctx, AV_LOG_ERROR, "mjpeg: unsupported coding type (%x)\n", start_code);
- break;
-// default:
-// printf("mjpeg: unsupported marker (%x)\n", start_code);
-// break;
- }
-
-not_the_end:
- /* eof process start code */
- buf_ptr += (get_bits_count(&s->gb)+7)/8;
- dprintf("marker parser used %d bytes (%d bits)\n",
- (get_bits_count(&s->gb)+7)/8, get_bits_count(&s->gb));
- }
- }
- }
-the_end:
- dprintf("mjpeg decode frame unused %d bytes\n", buf_end - buf_ptr);
-// return buf_end - buf_ptr;
- return buf_ptr - buf;
-}
-
-static int mjpegb_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- MJpegDecodeContext *s = avctx->priv_data;
- uint8_t *buf_end, *buf_ptr;
- AVFrame *picture = data;
- GetBitContext hgb; /* for the header */
- uint32_t dqt_offs, dht_offs, sof_offs, sos_offs, second_field_offs;
- uint32_t field_size, sod_offs;
-
- buf_ptr = buf;
- buf_end = buf + buf_size;
-
-read_header:
- /* reset on every SOI */
- s->restart_interval = 0;
- s->restart_count = 0;
- s->mjpb_skiptosod = 0;
-
- init_get_bits(&hgb, buf_ptr, /*buf_size*/(buf_end - buf_ptr)*8);
-
- skip_bits(&hgb, 32); /* reserved zeros */
-
- if (get_bits_long(&hgb, 32) != be2me_32(ff_get_fourcc("mjpg")))
- {
- dprintf("not mjpeg-b (bad fourcc)\n");
- return 0;
- }
-
- field_size = get_bits_long(&hgb, 32); /* field size */
- dprintf("field size: 0x%x\n", field_size);
- skip_bits(&hgb, 32); /* padded field size */
- second_field_offs = get_bits_long(&hgb, 32);
- dprintf("second field offs: 0x%x\n", second_field_offs);
- if (second_field_offs)
- s->interlaced = 1;
-
- dqt_offs = get_bits_long(&hgb, 32);
- dprintf("dqt offs: 0x%x\n", dqt_offs);
- if (dqt_offs)
- {
- init_get_bits(&s->gb, buf+dqt_offs, (buf_end - (buf+dqt_offs))*8);
- s->start_code = DQT;
- mjpeg_decode_dqt(s);
- }
-
- dht_offs = get_bits_long(&hgb, 32);
- dprintf("dht offs: 0x%x\n", dht_offs);
- if (dht_offs)
- {
- init_get_bits(&s->gb, buf+dht_offs, (buf_end - (buf+dht_offs))*8);
- s->start_code = DHT;
- mjpeg_decode_dht(s);
- }
-
- sof_offs = get_bits_long(&hgb, 32);
- dprintf("sof offs: 0x%x\n", sof_offs);
- if (sof_offs)
- {
- init_get_bits(&s->gb, buf+sof_offs, (buf_end - (buf+sof_offs))*8);
- s->start_code = SOF0;
- if (mjpeg_decode_sof(s) < 0)
- return -1;
- }
-
- sos_offs = get_bits_long(&hgb, 32);
- dprintf("sos offs: 0x%x\n", sos_offs);
- sod_offs = get_bits_long(&hgb, 32);
- dprintf("sod offs: 0x%x\n", sod_offs);
- if (sos_offs)
- {
-// init_get_bits(&s->gb, buf+sos_offs, (buf_end - (buf+sos_offs))*8);
- init_get_bits(&s->gb, buf+sos_offs, field_size*8);
- s->mjpb_skiptosod = (sod_offs - sos_offs - show_bits(&s->gb, 16));
- s->start_code = SOS;
- mjpeg_decode_sos(s);
- }
-
- if (s->interlaced) {
- s->bottom_field ^= 1;
- /* if not bottom field, do not output image yet */
- if (s->bottom_field && second_field_offs)
- {
- buf_ptr = buf + second_field_offs;
- second_field_offs = 0;
- goto read_header;
- }
- }
-
- //XXX FIXME factorize, this looks very similar to the EOI code
-
- *picture= s->picture;
- *data_size = sizeof(AVFrame);
-
- if(!s->lossless){
- picture->quality= FFMAX(FFMAX(s->qscale[0], s->qscale[1]), s->qscale[2]);
- picture->qstride= 0;
- picture->qscale_table= s->qscale_table;
- memset(picture->qscale_table, picture->quality, (s->width+15)/16);
- if(avctx->debug & FF_DEBUG_QP)
- av_log(avctx, AV_LOG_DEBUG, "QP: %d\n", picture->quality);
- picture->quality*= FF_QP2LAMBDA;
- }
-
- return buf_ptr - buf;
-}
-
-#include "sp5x.h"
-
-static int sp5x_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
-#if 0
- MJpegDecodeContext *s = avctx->priv_data;
-#endif
- const int qscale = 5;
- uint8_t *buf_ptr, *buf_end, *recoded;
- int i = 0, j = 0;
-
- if (!avctx->width || !avctx->height)
- return -1;
-
- buf_ptr = buf;
- buf_end = buf + buf_size;
-
-#if 1
- recoded = av_mallocz(buf_size + 1024);
- if (!recoded)
- return -1;
-
- /* SOI */
- recoded[j++] = 0xFF;
- recoded[j++] = 0xD8;
-
- memcpy(recoded+j, &sp5x_data_dqt[0], sizeof(sp5x_data_dqt));
- memcpy(recoded+j+5, &sp5x_quant_table[qscale * 2], 64);
- memcpy(recoded+j+70, &sp5x_quant_table[(qscale * 2) + 1], 64);
- j += sizeof(sp5x_data_dqt);
-
- memcpy(recoded+j, &sp5x_data_dht[0], sizeof(sp5x_data_dht));
- j += sizeof(sp5x_data_dht);
-
- memcpy(recoded+j, &sp5x_data_sof[0], sizeof(sp5x_data_sof));
- recoded[j+5] = (avctx->coded_height >> 8) & 0xFF;
- recoded[j+6] = avctx->coded_height & 0xFF;
- recoded[j+7] = (avctx->coded_width >> 8) & 0xFF;
- recoded[j+8] = avctx->coded_width & 0xFF;
- j += sizeof(sp5x_data_sof);
-
- memcpy(recoded+j, &sp5x_data_sos[0], sizeof(sp5x_data_sos));
- j += sizeof(sp5x_data_sos);
-
- for (i = 14; i < buf_size && j < buf_size+1024-2; i++)
- {
- recoded[j++] = buf[i];
- if (buf[i] == 0xff)
- recoded[j++] = 0;
- }
-
- /* EOI */
- recoded[j++] = 0xFF;
- recoded[j++] = 0xD9;
-
- i = mjpeg_decode_frame(avctx, data, data_size, recoded, j);
-
- av_free(recoded);
-
-#else
- /* SOF */
- s->bits = 8;
- s->width = avctx->coded_width;
- s->height = avctx->coded_height;
- s->nb_components = 3;
- s->component_id[0] = 0;
- s->h_count[0] = 2;
- s->v_count[0] = 2;
- s->quant_index[0] = 0;
- s->component_id[1] = 1;
- s->h_count[1] = 1;
- s->v_count[1] = 1;
- s->quant_index[1] = 1;
- s->component_id[2] = 2;
- s->h_count[2] = 1;
- s->v_count[2] = 1;
- s->quant_index[2] = 1;
- s->h_max = 2;
- s->v_max = 2;
-
- s->qscale_table = av_mallocz((s->width+15)/16);
- avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV420P : PIX_FMT_YUVJ420;
- s->interlaced = 0;
-
- s->picture.reference = 0;
- if (avctx->get_buffer(avctx, &s->picture) < 0)
- {
- av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
- return -1;
- }
-
- s->picture.pict_type = I_TYPE;
- s->picture.key_frame = 1;
-
- for (i = 0; i < 3; i++)
- s->linesize[i] = s->picture.linesize[i] << s->interlaced;
-
- /* DQT */
- for (i = 0; i < 64; i++)
- {
- j = s->scantable.permutated[i];
- s->quant_matrixes[0][j] = sp5x_quant_table[(qscale * 2) + i];
- }
- s->qscale[0] = FFMAX(
- s->quant_matrixes[0][s->scantable.permutated[1]],
- s->quant_matrixes[0][s->scantable.permutated[8]]) >> 1;
-
- for (i = 0; i < 64; i++)
- {
- j = s->scantable.permutated[i];
- s->quant_matrixes[1][j] = sp5x_quant_table[(qscale * 2) + 1 + i];
- }
- s->qscale[1] = FFMAX(
- s->quant_matrixes[1][s->scantable.permutated[1]],
- s->quant_matrixes[1][s->scantable.permutated[8]]) >> 1;
-
- /* DHT */
-
- /* SOS */
- s->comp_index[0] = 0;
- s->nb_blocks[0] = s->h_count[0] * s->v_count[0];
- s->h_scount[0] = s->h_count[0];
- s->v_scount[0] = s->v_count[0];
- s->dc_index[0] = 0;
- s->ac_index[0] = 0;
-
- s->comp_index[1] = 1;
- s->nb_blocks[1] = s->h_count[1] * s->v_count[1];
- s->h_scount[1] = s->h_count[1];
- s->v_scount[1] = s->v_count[1];
- s->dc_index[1] = 1;
- s->ac_index[1] = 1;
-
- s->comp_index[2] = 2;
- s->nb_blocks[2] = s->h_count[2] * s->v_count[2];
- s->h_scount[2] = s->h_count[2];
- s->v_scount[2] = s->v_count[2];
- s->dc_index[2] = 1;
- s->ac_index[2] = 1;
-
- for (i = 0; i < 3; i++)
- s->last_dc[i] = 1024;
-
- s->mb_width = (s->width * s->h_max * 8 -1) / (s->h_max * 8);
- s->mb_height = (s->height * s->v_max * 8 -1) / (s->v_max * 8);
-
- init_get_bits(&s->gb, buf+14, (buf_size-14)*8);
-
- return mjpeg_decode_scan(s);
-#endif
-
- return i;
-}
-
-static int mjpeg_decode_end(AVCodecContext *avctx)
-{
- MJpegDecodeContext *s = avctx->priv_data;
- int i, j;
-
- av_free(s->buffer);
- av_free(s->qscale_table);
-
- for(i=0;i<2;i++) {
- for(j=0;j<4;j++)
- free_vlc(&s->vlcs[i][j]);
- }
- return 0;
-}
-
-static int mjpega_dump_header(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
- uint8_t **poutbuf, int *poutbuf_size,
- const uint8_t *buf, int buf_size, int keyframe)
-{
- uint8_t *poutbufp;
- int i;
-
- if (avctx->codec_id != CODEC_ID_MJPEG) {
- av_log(avctx, AV_LOG_ERROR, "mjpega bitstream filter only applies to mjpeg codec\n");
- return 0;
- }
-
- *poutbuf_size = 0;
- *poutbuf = av_malloc(buf_size + 44 + FF_INPUT_BUFFER_PADDING_SIZE);
- poutbufp = *poutbuf;
- bytestream_put_byte(&poutbufp, 0xff);
- bytestream_put_byte(&poutbufp, SOI);
- bytestream_put_byte(&poutbufp, 0xff);
- bytestream_put_byte(&poutbufp, APP1);
- bytestream_put_be16(&poutbufp, 42); /* size */
- bytestream_put_be32(&poutbufp, 0);
- bytestream_put_buffer(&poutbufp, "mjpg", 4);
- bytestream_put_be32(&poutbufp, buf_size + 44); /* field size */
- bytestream_put_be32(&poutbufp, buf_size + 44); /* pad field size */
- bytestream_put_be32(&poutbufp, 0); /* next ptr */
-
- for (i = 0; i < buf_size - 1; i++) {
- if (buf[i] == 0xff) {
- switch (buf[i + 1]) {
- case DQT: /* quant off */
- case DHT: /* huff off */
- case SOF0: /* image off */
- bytestream_put_be32(&poutbufp, i + 46);
- break;
- case SOS:
- bytestream_put_be32(&poutbufp, i + 46); /* scan off */
- bytestream_put_be32(&poutbufp, i + 46 + AV_RB16(buf + i + 2)); /* data off */
- bytestream_put_buffer(&poutbufp, buf + 2, buf_size - 2); /* skip already written SOI */
- *poutbuf_size = poutbufp - *poutbuf;
- return 1;
- case APP1:
- if (i + 8 < buf_size && AV_RL32(buf + i + 8) == ff_get_fourcc("mjpg")) {
- av_log(avctx, AV_LOG_ERROR, "bitstream already formatted\n");
- memcpy(*poutbuf, buf, buf_size);
- *poutbuf_size = buf_size;
- return 1;
- }
- }
- }
- }
- av_freep(poutbuf);
- av_log(avctx, AV_LOG_ERROR, "could not find SOS marker in bitstream\n");
- return 0;
-}
-
-AVCodec mjpeg_decoder = {
- "mjpeg",
- CODEC_TYPE_VIDEO,
- CODEC_ID_MJPEG,
- sizeof(MJpegDecodeContext),
- mjpeg_decode_init,
- NULL,
- mjpeg_decode_end,
- mjpeg_decode_frame,
- CODEC_CAP_DR1,
- NULL
-};
-
-AVCodec mjpegb_decoder = {
- "mjpegb",
- CODEC_TYPE_VIDEO,
- CODEC_ID_MJPEGB,
- sizeof(MJpegDecodeContext),
- mjpeg_decode_init,
- NULL,
- mjpeg_decode_end,
- mjpegb_decode_frame,
- CODEC_CAP_DR1,
- NULL
-};
-
-AVCodec sp5x_decoder = {
- "sp5x",
- CODEC_TYPE_VIDEO,
- CODEC_ID_SP5X,
- sizeof(MJpegDecodeContext),
- mjpeg_decode_init,
- NULL,
- mjpeg_decode_end,
- sp5x_decode_frame,
- CODEC_CAP_DR1,
- NULL
-};
-
-#ifdef CONFIG_ENCODERS
-AVCodec ljpeg_encoder = { //FIXME avoid MPV_* lossless jpeg shouldnt need them
- "ljpeg",
- CODEC_TYPE_VIDEO,
- CODEC_ID_LJPEG,
- sizeof(MpegEncContext),
- MPV_encode_init,
- encode_picture_lossless,
- MPV_encode_end,
-};
-#endif
-
-AVCodecParser mjpeg_parser = {
- { CODEC_ID_MJPEG },
- sizeof(ParseContext),
- NULL,
- jpeg_parse,
- ff_parse_close,
-};
-
-AVBitStreamFilter mjpega_dump_header_bsf = {
- "mjpegadump",
- 0,
- mjpega_dump_header,
-};
diff --git a/src/libffmpeg/libavcodec/mlib/Makefile.am b/src/libffmpeg/libavcodec/mlib/Makefile.am
deleted file mode 100644
index ed8b3c8d0..000000000
--- a/src/libffmpeg/libavcodec/mlib/Makefile.am
+++ /dev/null
@@ -1,18 +0,0 @@
-include $(top_srcdir)/misc/Makefile.common
-
-AM_CPPFLAGS = $(LIBFFMPEG_CPPFLAGS) -I$(top_srcdir)/src/libffmpeg/libavutil
-AM_CFLAGS = -fno-strict-aliasing
-ASFLAGS =
-
-noinst_LTLIBRARIES = libavcodec_mlib.la
-
-libavcodec_mlib_src = dsputil_mlib.c
-libavcodec_mlib_dummy = libavcodec_mlib_dummy.c
-
-EXTRA_DIST = $(libavcodec_mlib_src) $(libavcodec_mlib_dummy)
-
-if HAVE_MLIB
-mlib_modules = $(libavcodec_mlib_src)
-endif
-
-libavcodec_mlib_la_SOURCES = $(mlib_modules) $(libavcodec_mlib_dummy)
diff --git a/src/libffmpeg/libavcodec/mlib/dsputil_mlib.c b/src/libffmpeg/libavcodec/mlib/dsputil_mlib.c
deleted file mode 100644
index 59c56b1dd..000000000
--- a/src/libffmpeg/libavcodec/mlib/dsputil_mlib.c
+++ /dev/null
@@ -1,466 +0,0 @@
-/*
- * Sun mediaLib optimized DSP utils
- * Copyright (c) 2001 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 "../dsputil.h"
-#include "../mpegvideo.h"
-
-#include "../../../xine-utils/xineutils.h"
-
-#include <mlib_types.h>
-#include <mlib_status.h>
-#include <mlib_sys.h>
-#include <mlib_algebra.h>
-#include <mlib_video.h>
-
-/* misc */
-
-static void get_pixels_mlib(DCTELEM *restrict block, const uint8_t *pixels, int line_size)
-{
- int i;
-
- for (i=0;i<8;i++) {
- mlib_VectorConvert_S16_U8_Mod((mlib_s16 *)block, (mlib_u8 *)pixels, 8);
-
- pixels += line_size;
- block += 8;
- }
-}
-
-static void diff_pixels_mlib(DCTELEM *restrict block, const uint8_t *s1, const uint8_t *s2, int line_size)
-{
- int i;
-
- for (i=0;i<8;i++) {
- mlib_VectorSub_S16_U8_Mod((mlib_s16 *)block, (mlib_u8 *)s1, (mlib_u8 *)s2, 8);
-
- s1 += line_size;
- s2 += line_size;
- block += 8;
- }
-}
-
-static void add_pixels_clamped_mlib(const DCTELEM *block, uint8_t *pixels, int line_size)
-{
- mlib_VideoAddBlock_U8_S16(pixels, (mlib_s16 *)block, line_size);
-}
-
-/* put block, width 16 pixel, height 8/16 */
-
-static void put_pixels16_mlib (uint8_t * dest, const uint8_t * ref,
- int stride, int height)
-{
- switch (height) {
- case 8:
- mlib_VideoCopyRef_U8_U8_16x8(dest, (uint8_t *)ref, stride);
- break;
-
- case 16:
- mlib_VideoCopyRef_U8_U8_16x16(dest, (uint8_t *)ref, stride);
- break;
-
- default:
- assert(0);
- }
-}
-
-static void put_pixels16_x2_mlib (uint8_t * dest, const uint8_t * ref,
- int stride, int height)
-{
- switch (height) {
- case 8:
- mlib_VideoInterpX_U8_U8_16x8(dest, (uint8_t *)ref, stride, stride);
- break;
-
- case 16:
- mlib_VideoInterpX_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
- break;
-
- default:
- assert(0);
- }
-}
-
-static void put_pixels16_y2_mlib (uint8_t * dest, const uint8_t * ref,
- int stride, int height)
-{
- switch (height) {
- case 8:
- mlib_VideoInterpY_U8_U8_16x8(dest, (uint8_t *)ref, stride, stride);
- break;
-
- case 16:
- mlib_VideoInterpY_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
- break;
-
- default:
- assert(0);
- }
-}
-
-static void put_pixels16_xy2_mlib(uint8_t * dest, const uint8_t * ref,
- int stride, int height)
-{
- switch (height) {
- case 8:
- mlib_VideoInterpXY_U8_U8_16x8(dest, (uint8_t *)ref, stride, stride);
- break;
-
- case 16:
- mlib_VideoInterpXY_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
- break;
-
- default:
- assert(0);
- }
-}
-
-/* put block, width 8 pixel, height 4/8/16 */
-
-static void put_pixels8_mlib (uint8_t * dest, const uint8_t * ref,
- int stride, int height)
-{
- switch (height) {
- case 4:
- mlib_VideoCopyRef_U8_U8_8x4(dest, (uint8_t *)ref, stride);
- break;
-
- case 8:
- mlib_VideoCopyRef_U8_U8_8x8(dest, (uint8_t *)ref, stride);
- break;
-
- case 16:
- mlib_VideoCopyRef_U8_U8_8x16(dest, (uint8_t *)ref, stride);
- break;
-
- default:
- assert(0);
- }
-}
-
-static void put_pixels8_x2_mlib (uint8_t * dest, const uint8_t * ref,
- int stride, int height)
-{
- switch (height) {
- case 4:
- mlib_VideoInterpX_U8_U8_8x4(dest, (uint8_t *)ref, stride, stride);
- break;
-
- case 8:
- mlib_VideoInterpX_U8_U8_8x8(dest, (uint8_t *)ref, stride, stride);
- break;
-
- case 16:
- mlib_VideoInterpX_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
- break;
-
- default:
- assert(0);
- }
-}
-
-static void put_pixels8_y2_mlib (uint8_t * dest, const uint8_t * ref,
- int stride, int height)
-{
- switch (height) {
- case 4:
- mlib_VideoInterpY_U8_U8_8x4(dest, (uint8_t *)ref, stride, stride);
- break;
-
- case 8:
- mlib_VideoInterpY_U8_U8_8x8(dest, (uint8_t *)ref, stride, stride);
- break;
-
- case 16:
- mlib_VideoInterpY_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
- break;
-
- default:
- assert(0);
- }
-}
-
-static void put_pixels8_xy2_mlib(uint8_t * dest, const uint8_t * ref,
- int stride, int height)
-{
- switch (height) {
- case 4:
- mlib_VideoInterpXY_U8_U8_8x4(dest, (uint8_t *)ref, stride, stride);
- break;
-
- case 8:
- mlib_VideoInterpXY_U8_U8_8x8(dest, (uint8_t *)ref, stride, stride);
- break;
-
- case 16:
- mlib_VideoInterpXY_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
- break;
-
- default:
- assert(0);
- }
-}
-
-/* average block, width 16 pixel, height 8/16 */
-
-static void avg_pixels16_mlib (uint8_t * dest, const uint8_t * ref,
- int stride, int height)
-{
- switch (height) {
- case 8:
- mlib_VideoCopyRefAve_U8_U8_16x8(dest, (uint8_t *)ref, stride);
- break;
-
- case 16:
- mlib_VideoCopyRefAve_U8_U8_16x16(dest, (uint8_t *)ref, stride);
- break;
-
- default:
- assert(0);
- }
-}
-
-static void avg_pixels16_x2_mlib (uint8_t * dest, const uint8_t * ref,
- int stride, int height)
-{
- switch (height) {
- case 8:
- mlib_VideoInterpAveX_U8_U8_16x8(dest, (uint8_t *)ref, stride, stride);
- break;
-
- case 16:
- mlib_VideoInterpAveX_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
- break;
-
- default:
- assert(0);
- }
-}
-
-static void avg_pixels16_y2_mlib (uint8_t * dest, const uint8_t * ref,
- int stride, int height)
-{
- switch (height) {
- case 8:
- mlib_VideoInterpAveY_U8_U8_16x8(dest, (uint8_t *)ref, stride, stride);
- break;
-
- case 16:
- mlib_VideoInterpAveY_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
- break;
-
- default:
- assert(0);
- }
-}
-
-static void avg_pixels16_xy2_mlib(uint8_t * dest, const uint8_t * ref,
- int stride, int height)
-{
- switch (height) {
- case 8:
- mlib_VideoInterpAveXY_U8_U8_16x8(dest, (uint8_t *)ref, stride, stride);
- break;
-
- case 16:
- mlib_VideoInterpAveXY_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
- break;
-
- default:
- assert(0);
- }
-}
-
-/* average block, width 8 pixel, height 4/8/16 */
-
-static void avg_pixels8_mlib (uint8_t * dest, const uint8_t * ref,
- int stride, int height)
-{
- switch (height) {
- case 4:
- mlib_VideoCopyRefAve_U8_U8_8x4(dest, (uint8_t *)ref, stride);
- break;
-
- case 8:
- mlib_VideoCopyRefAve_U8_U8_8x8(dest, (uint8_t *)ref, stride);
- break;
-
- case 16:
- mlib_VideoCopyRefAve_U8_U8_8x16(dest, (uint8_t *)ref, stride);
- break;
-
- default:
- assert(0);
- }
-}
-
-static void avg_pixels8_x2_mlib (uint8_t * dest, const uint8_t * ref,
- int stride, int height)
-{
- switch (height) {
- case 4:
- mlib_VideoInterpAveX_U8_U8_8x4(dest, (uint8_t *)ref, stride, stride);
- break;
-
- case 8:
- mlib_VideoInterpAveX_U8_U8_8x8(dest, (uint8_t *)ref, stride, stride);
- break;
-
- case 16:
- mlib_VideoInterpAveX_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
- break;
-
- default:
- assert(0);
- }
-}
-
-static void avg_pixels8_y2_mlib (uint8_t * dest, const uint8_t * ref,
- int stride, int height)
-{
- switch (height) {
- case 4:
- mlib_VideoInterpAveY_U8_U8_8x4(dest, (uint8_t *)ref, stride, stride);
- break;
-
- case 8:
- mlib_VideoInterpAveY_U8_U8_8x8(dest, (uint8_t *)ref, stride, stride);
- break;
-
- case 16:
- mlib_VideoInterpAveY_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
- break;
-
- default:
- assert(0);
- }
-}
-
-static void avg_pixels8_xy2_mlib(uint8_t * dest, const uint8_t * ref,
- int stride, int height)
-{
- switch (height) {
- case 4:
- mlib_VideoInterpAveXY_U8_U8_8x4(dest, (uint8_t *)ref, stride, stride);
- break;
-
- case 8:
- mlib_VideoInterpAveXY_U8_U8_8x8(dest, (uint8_t *)ref, stride, stride);
- break;
-
- case 16:
- mlib_VideoInterpAveXY_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
- break;
-
- default:
- assert(0);
- }
-}
-
-/* swap byte order of a buffer */
-
-static void bswap_buf_mlib(uint32_t *dst, uint32_t *src, int w)
-{
- mlib_VectorReverseByteOrder_U32_U32(dst, src, w);
-}
-
-/* transformations */
-
-static void ff_idct_put_mlib(uint8_t *dest, int line_size, DCTELEM *data)
-{
- int i;
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
-
- mlib_VideoIDCT8x8_S16_S16 (data, data);
-
- for(i=0;i<8;i++) {
- dest[0] = cm[data[0]];
- dest[1] = cm[data[1]];
- dest[2] = cm[data[2]];
- dest[3] = cm[data[3]];
- dest[4] = cm[data[4]];
- dest[5] = cm[data[5]];
- dest[6] = cm[data[6]];
- dest[7] = cm[data[7]];
-
- dest += line_size;
- data += 8;
- }
-}
-
-static void ff_idct_add_mlib(uint8_t *dest, int line_size, DCTELEM *data)
-{
- mlib_VideoIDCT8x8_S16_S16 (data, data);
- mlib_VideoAddBlock_U8_S16(dest, (mlib_s16 *)data, line_size);
-}
-
-static void ff_idct_mlib(DCTELEM *data)
-{
- mlib_VideoIDCT8x8_S16_S16 (data, data);
-}
-
-static void ff_fdct_mlib(DCTELEM *data)
-{
- mlib_VideoDCT8x8_S16_S16 (data, data);
-}
-
-void dsputil_init_mlib(DSPContext* c, AVCodecContext *avctx)
-{
- c->get_pixels = get_pixels_mlib;
- c->diff_pixels = diff_pixels_mlib;
- c->add_pixels_clamped = add_pixels_clamped_mlib;
-
- c->put_pixels_tab[0][0] = put_pixels16_mlib;
- c->put_pixels_tab[0][1] = put_pixels16_x2_mlib;
- c->put_pixels_tab[0][2] = put_pixels16_y2_mlib;
- c->put_pixels_tab[0][3] = put_pixels16_xy2_mlib;
- c->put_pixels_tab[1][0] = put_pixels8_mlib;
- c->put_pixels_tab[1][1] = put_pixels8_x2_mlib;
- c->put_pixels_tab[1][2] = put_pixels8_y2_mlib;
- c->put_pixels_tab[1][3] = put_pixels8_xy2_mlib;
-
- c->avg_pixels_tab[0][0] = avg_pixels16_mlib;
- c->avg_pixels_tab[0][1] = avg_pixels16_x2_mlib;
- c->avg_pixels_tab[0][2] = avg_pixels16_y2_mlib;
- c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mlib;
- c->avg_pixels_tab[1][0] = avg_pixels8_mlib;
- c->avg_pixels_tab[1][1] = avg_pixels8_x2_mlib;
- c->avg_pixels_tab[1][2] = avg_pixels8_y2_mlib;
- c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mlib;
-
- c->put_no_rnd_pixels_tab[0][0] = put_pixels16_mlib;
- c->put_no_rnd_pixels_tab[1][0] = put_pixels8_mlib;
-
- c->bswap_buf = bswap_buf_mlib;
-}
-
-void MPV_common_init_mlib(MpegEncContext *s)
-{
- if(s->avctx->dct_algo==FF_DCT_AUTO || s->avctx->dct_algo==FF_DCT_MLIB){
- s->dsp.fdct = ff_fdct_mlib;
- }
-
- if(s->avctx->idct_algo==FF_IDCT_AUTO || s->avctx->idct_algo==FF_IDCT_MLIB){
- s->dsp.idct_put= ff_idct_put_mlib;
- s->dsp.idct_add= ff_idct_add_mlib;
- s->dsp.idct = ff_idct_mlib;
- s->dsp.idct_permutation_type= FF_NO_IDCT_PERM;
- }
-}
diff --git a/src/libffmpeg/libavcodec/mlib/libavcodec_mlib_dummy.c b/src/libffmpeg/libavcodec/mlib/libavcodec_mlib_dummy.c
deleted file mode 100644
index a09ee4e28..000000000
--- a/src/libffmpeg/libavcodec/mlib/libavcodec_mlib_dummy.c
+++ /dev/null
@@ -1,2 +0,0 @@
-
-char libavcodec_mlib_dummy;
diff --git a/src/libffmpeg/libavcodec/motion_est.c b/src/libffmpeg/libavcodec/motion_est.c
deleted file mode 100644
index a11787bac..000000000
--- a/src/libffmpeg/libavcodec/motion_est.c
+++ /dev/null
@@ -1,2149 +0,0 @@
-/*
- * Motion estimation
- * Copyright (c) 2000,2001 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
- *
- * new Motion Estimation (X1/EPZS) by Michael Niedermayer <michaelni@gmx.at>
- */
-
-/* motion estimation only needed for encoders */
-#ifdef CONFIG_ENCODERS
-
-/**
- * @file motion_est.c
- * Motion estimation.
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <limits.h>
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-
-#undef NDEBUG
-#include <assert.h>
-
-#define SQ(a) ((a)*(a))
-
-#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]
-
-static inline int sad_hpel_motion_search(MpegEncContext * s,
- int *mx_ptr, int *my_ptr, int dmin,
- int src_index, int ref_index,
- int size, int h);
-
-static inline int update_map_generation(MotionEstContext *c)
-{
- c->map_generation+= 1<<(ME_MAP_MV_BITS*2);
- if(c->map_generation==0){
- c->map_generation= 1<<(ME_MAP_MV_BITS*2);
- memset(c->map, 0, sizeof(uint32_t)*ME_MAP_SIZE);
- }
- return c->map_generation;
-}
-
-/* shape adaptive search stuff */
-typedef struct Minima{
- int height;
- int x, y;
- int checked;
-}Minima;
-
-static int minima_cmp(const void *a, const void *b){
- const Minima *da = (const Minima *) a;
- const Minima *db = (const Minima *) b;
-
- return da->height - db->height;
-}
-
-#define FLAG_QPEL 1 //must be 1
-#define FLAG_CHROMA 2
-#define FLAG_DIRECT 4
-
-static inline void init_ref(MotionEstContext *c, uint8_t *src[3], uint8_t *ref[3], uint8_t *ref2[3], int x, int y, int ref_index){
- const int offset[3]= {
- y*c-> stride + x,
- ((y*c->uvstride + x)>>1),
- ((y*c->uvstride + x)>>1),
- };
- int i;
- for(i=0; i<3; i++){
- c->src[0][i]= src [i] + offset[i];
- c->ref[0][i]= ref [i] + offset[i];
- }
- if(ref_index){
- for(i=0; i<3; i++){
- c->ref[ref_index][i]= ref2[i] + offset[i];
- }
- }
-}
-
-static int get_flags(MotionEstContext *c, int direct, int chroma){
- return ((c->avctx->flags&CODEC_FLAG_QPEL) ? FLAG_QPEL : 0)
- + (direct ? FLAG_DIRECT : 0)
- + (chroma ? FLAG_CHROMA : 0);
-}
-
-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){
- 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;
- const int time_pb= s->pb_time;
- const int mask= 2*qpel+1;
- if(s->mv_type==MV_TYPE_8X8){
- int i;
- for(i=0; i<4; i++){
- int fx = c->direct_basis_mv[i][0] + hx;
- int fy = c->direct_basis_mv[i][1] + hy;
- int bx = hx ? fx - c->co_located_mv[i][0] : c->co_located_mv[i][0]*(time_pb - time_pp)/time_pp + ((i &1)<<(qpel+4));
- int by = hy ? fy - c->co_located_mv[i][1] : c->co_located_mv[i][1]*(time_pb - time_pp)/time_pp + ((i>>1)<<(qpel+4));
- int fxy= (fx&mask) + ((fy&mask)<<(qpel+1));
- int bxy= (bx&mask) + ((by&mask)<<(qpel+1));
-
- uint8_t *dst= c->temp + 8*(i&1) + 8*stride*(i>>1);
- if(qpel){
- c->qpel_put[1][fxy](dst, ref[0] + (fx>>2) + (fy>>2)*stride, stride);
- c->qpel_avg[1][bxy](dst, ref[8] + (bx>>2) + (by>>2)*stride, stride);
- }else{
- c->hpel_put[1][fxy](dst, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 8);
- c->hpel_avg[1][bxy](dst, ref[8] + (bx>>1) + (by>>1)*stride, stride, 8);
- }
- }
- }else{
- int fx = c->direct_basis_mv[0][0] + hx;
- int fy = c->direct_basis_mv[0][1] + hy;
- int bx = hx ? fx - c->co_located_mv[0][0] : (c->co_located_mv[0][0]*(time_pb - time_pp)/time_pp);
- int by = hy ? fy - c->co_located_mv[0][1] : (c->co_located_mv[0][1]*(time_pb - time_pp)/time_pp);
- int fxy= (fx&mask) + ((fy&mask)<<(qpel+1));
- int bxy= (bx&mask) + ((by&mask)<<(qpel+1));
-
- if(qpel){
- c->qpel_put[1][fxy](c->temp , ref[0] + (fx>>2) + (fy>>2)*stride , stride);
- c->qpel_put[1][fxy](c->temp + 8 , ref[0] + (fx>>2) + (fy>>2)*stride + 8 , stride);
- c->qpel_put[1][fxy](c->temp + 8*stride, ref[0] + (fx>>2) + (fy>>2)*stride + 8*stride, stride);
- c->qpel_put[1][fxy](c->temp + 8 + 8*stride, ref[0] + (fx>>2) + (fy>>2)*stride + 8 + 8*stride, stride);
- c->qpel_avg[1][bxy](c->temp , ref[8] + (bx>>2) + (by>>2)*stride , stride);
- c->qpel_avg[1][bxy](c->temp + 8 , ref[8] + (bx>>2) + (by>>2)*stride + 8 , stride);
- c->qpel_avg[1][bxy](c->temp + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride + 8*stride, stride);
- c->qpel_avg[1][bxy](c->temp + 8 + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride + 8 + 8*stride, stride);
- }else{
- assert((fx>>1) + 16*s->mb_x >= -16);
- assert((fy>>1) + 16*s->mb_y >= -16);
- assert((fx>>1) + 16*s->mb_x <= s->width);
- assert((fy>>1) + 16*s->mb_y <= s->height);
- assert((bx>>1) + 16*s->mb_x >= -16);
- assert((by>>1) + 16*s->mb_y >= -16);
- assert((bx>>1) + 16*s->mb_x <= s->width);
- assert((by>>1) + 16*s->mb_y <= s->height);
-
- c->hpel_put[0][fxy](c->temp, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 16);
- c->hpel_avg[0][bxy](c->temp, ref[8] + (bx>>1) + (by>>1)*stride, stride, 16);
- }
- }
- d = cmp_func(s, c->temp, src[0], stride, 16);
- }else
- d= 256*256*256*32;
- }else{
- int uvdxy; /* no, it might not be used uninitialized */
- if(dxy){
- if(qpel){
- c->qpel_put[size][dxy](c->temp, ref[0] + x + y*stride, stride); //FIXME prototype (add h)
- if(chroma){
- int cx= hx/2;
- int cy= hy/2;
- cx= (cx>>1)|(cx&1);
- cy= (cy>>1)|(cy&1);
- uvdxy= (cx&1) + 2*(cy&1);
- //FIXME x/y wrong, but mpeg4 qpel is sick anyway, we should drop as much of it as possible in favor for h264
- }
- }else{
- c->hpel_put[size][dxy](c->temp, ref[0] + x + y*stride, stride, h);
- if(chroma)
- uvdxy= dxy | (x&1) | (2*(y&1));
- }
- d = cmp_func(s, c->temp, src[0], stride, h);
- }else{
- d = cmp_func(s, src[0], ref[0] + x + y*stride, stride, h);
- if(chroma)
- uvdxy= (x&1) + 2*(y&1);
- }
- if(chroma){
- uint8_t * const uvtemp= c->temp + 16*stride;
- c->hpel_put[size+1][uvdxy](uvtemp , ref[1] + (x>>1) + (y>>1)*uvstride, uvstride, h>>1);
- c->hpel_put[size+1][uvdxy](uvtemp+8, ref[2] + (x>>1) + (y>>1)*uvstride, uvstride, h>>1);
- 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)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);
- score_map[index]= d;
- }
-
- d += (c->mv_penalty[hx - c->pred_x] + c->mv_penalty[hy - c->pred_y])*c->penalty_factor;
-#endif
- return d;
-}
-
-#include "motion_est_template.c"
-
-static int zero_cmp(void *s, uint8_t *a, uint8_t *b, int stride, int h){
- return 0;
-}
-
-static void zero_hpel(uint8_t *a, const uint8_t *b, int stride, int h){
-}
-
-void ff_init_me(MpegEncContext *s){
- MotionEstContext * const c= &s->me;
- int cache_size= FFMIN(ME_MAP_SIZE>>ME_MAP_SHIFT, 1<<ME_MAP_SHIFT);
- int dia_size= FFMAX(FFABS(s->avctx->dia_size)&255, FFABS(s->avctx->pre_dia_size)&255);
- c->avctx= s->avctx;
-
- if(cache_size < 2*dia_size && !c->stride){
- av_log(s->avctx, AV_LOG_INFO, "ME_MAP size may be a little small for the selected diamond size\n");
- }
-
- ff_set_cmp(&s->dsp, s->dsp.me_pre_cmp, c->avctx->me_pre_cmp);
- ff_set_cmp(&s->dsp, s->dsp.me_cmp, c->avctx->me_cmp);
- ff_set_cmp(&s->dsp, s->dsp.me_sub_cmp, c->avctx->me_sub_cmp);
- ff_set_cmp(&s->dsp, s->dsp.mb_cmp, c->avctx->mb_cmp);
-
- c->flags = get_flags(c, 0, c->avctx->me_cmp &FF_CMP_CHROMA);
- c->sub_flags= get_flags(c, 0, c->avctx->me_sub_cmp&FF_CMP_CHROMA);
- c->mb_flags = get_flags(c, 0, c->avctx->mb_cmp &FF_CMP_CHROMA);
-
-/*FIXME s->no_rounding b_type*/
- if(s->flags&CODEC_FLAG_QPEL){
- c->sub_motion_search= qpel_motion_search;
- c->qpel_avg= s->dsp.avg_qpel_pixels_tab;
- if(s->no_rounding) c->qpel_put= s->dsp.put_no_rnd_qpel_pixels_tab;
- else c->qpel_put= s->dsp.put_qpel_pixels_tab;
- }else{
- if(c->avctx->me_sub_cmp&FF_CMP_CHROMA)
- c->sub_motion_search= hpel_motion_search;
- else if( c->avctx->me_sub_cmp == FF_CMP_SAD
- && c->avctx-> me_cmp == FF_CMP_SAD
- && c->avctx-> mb_cmp == FF_CMP_SAD)
- c->sub_motion_search= sad_hpel_motion_search; // 2050 vs. 2450 cycles
- else
- c->sub_motion_search= hpel_motion_search;
- }
- c->hpel_avg= s->dsp.avg_pixels_tab;
- if(s->no_rounding) c->hpel_put= s->dsp.put_no_rnd_pixels_tab;
- else c->hpel_put= s->dsp.put_pixels_tab;
-
- if(s->linesize){
- c->stride = s->linesize;
- c->uvstride= s->uvlinesize;
- }else{
- c->stride = 16*s->mb_width + 32;
- c->uvstride= 8*s->mb_width + 16;
- }
-
- // 8x8 fullpel search would need a 4x4 chroma compare, which we dont have yet, and even if we had the motion estimation code doesnt expect it
- if(s->codec_id != CODEC_ID_SNOW){
- if((c->avctx->me_cmp&FF_CMP_CHROMA)/* && !s->dsp.me_cmp[2]*/){
- s->dsp.me_cmp[2]= zero_cmp;
- }
- if((c->avctx->me_sub_cmp&FF_CMP_CHROMA) && !s->dsp.me_sub_cmp[2]){
- s->dsp.me_sub_cmp[2]= zero_cmp;
- }
- c->hpel_put[2][0]= c->hpel_put[2][1]=
- c->hpel_put[2][2]= c->hpel_put[2][3]= zero_hpel;
- }
-
- if(s->codec_id == CODEC_ID_H261){
- c->sub_motion_search= no_sub_motion_search;
- }
-
- c->temp= c->scratchpad;
-}
-
-#if 0
-static int pix_dev(uint8_t * pix, int line_size, int mean)
-{
- int s, i, j;
-
- s = 0;
- for (i = 0; i < 16; i++) {
- for (j = 0; j < 16; j += 8) {
- s += FFABS(pix[0]-mean);
- s += FFABS(pix[1]-mean);
- s += FFABS(pix[2]-mean);
- s += FFABS(pix[3]-mean);
- s += FFABS(pix[4]-mean);
- s += FFABS(pix[5]-mean);
- s += FFABS(pix[6]-mean);
- s += FFABS(pix[7]-mean);
- pix += 8;
- }
- pix += line_size - 16;
- }
- return s;
-}
-#endif
-
-static inline void no_motion_search(MpegEncContext * s,
- int *mx_ptr, int *my_ptr)
-{
- *mx_ptr = 16 * s->mb_x;
- *my_ptr = 16 * s->mb_y;
-}
-
-#if 0 /* the use of these functions is inside #if 0 */
-static int full_motion_search(MpegEncContext * s,
- int *mx_ptr, int *my_ptr, int range,
- int xmin, int ymin, int xmax, int ymax, uint8_t *ref_picture)
-{
- int x1, y1, x2, y2, xx, yy, x, y;
- int mx, my, dmin, d;
- uint8_t *pix;
-
- xx = 16 * s->mb_x;
- yy = 16 * s->mb_y;
- x1 = xx - range + 1; /* we loose one pixel to avoid boundary pb with half pixel pred */
- if (x1 < xmin)
- x1 = xmin;
- x2 = xx + range - 1;
- if (x2 > xmax)
- x2 = xmax;
- y1 = yy - range + 1;
- if (y1 < ymin)
- y1 = ymin;
- y2 = yy + range - 1;
- if (y2 > ymax)
- y2 = ymax;
- pix = s->new_picture.data[0] + (yy * s->linesize) + xx;
- dmin = 0x7fffffff;
- mx = 0;
- my = 0;
- for (y = y1; y <= y2; y++) {
- for (x = x1; x <= x2; x++) {
- d = s->dsp.pix_abs[0][0](NULL, pix, ref_picture + (y * s->linesize) + x,
- s->linesize, 16);
- if (d < dmin ||
- (d == dmin &&
- (abs(x - xx) + abs(y - yy)) <
- (abs(mx - xx) + abs(my - yy)))) {
- dmin = d;
- mx = x;
- my = y;
- }
- }
- }
-
- *mx_ptr = mx;
- *my_ptr = my;
-
-#if 0
- if (*mx_ptr < -(2 * range) || *mx_ptr >= (2 * range) ||
- *my_ptr < -(2 * range) || *my_ptr >= (2 * range)) {
- av_log(NULL, AV_LOG_ERROR, "error %d %d\n", *mx_ptr, *my_ptr);
- }
-#endif
- return dmin;
-}
-
-
-static int log_motion_search(MpegEncContext * s,
- int *mx_ptr, int *my_ptr, int range,
- int xmin, int ymin, int xmax, int ymax, uint8_t *ref_picture)
-{
- int x1, y1, x2, y2, xx, yy, x, y;
- int mx, my, dmin, d;
- uint8_t *pix;
-
- xx = s->mb_x << 4;
- yy = s->mb_y << 4;
-
- /* Left limit */
- x1 = xx - range;
- if (x1 < xmin)
- x1 = xmin;
-
- /* Right limit */
- x2 = xx + range;
- if (x2 > xmax)
- x2 = xmax;
-
- /* Upper limit */
- y1 = yy - range;
- if (y1 < ymin)
- y1 = ymin;
-
- /* Lower limit */
- y2 = yy + range;
- if (y2 > ymax)
- y2 = ymax;
-
- pix = s->new_picture.data[0] + (yy * s->linesize) + xx;
- dmin = 0x7fffffff;
- mx = 0;
- my = 0;
-
- do {
- for (y = y1; y <= y2; y += range) {
- for (x = x1; x <= x2; x += range) {
- d = s->dsp.pix_abs[0][0](NULL, pix, ref_picture + (y * s->linesize) + x, s->linesize, 16);
- if (d < dmin || (d == dmin && (abs(x - xx) + abs(y - yy)) < (abs(mx - xx) + abs(my - yy)))) {
- dmin = d;
- mx = x;
- my = y;
- }
- }
- }
-
- range = range >> 1;
-
- x1 = mx - range;
- if (x1 < xmin)
- x1 = xmin;
-
- x2 = mx + range;
- if (x2 > xmax)
- x2 = xmax;
-
- y1 = my - range;
- if (y1 < ymin)
- y1 = ymin;
-
- y2 = my + range;
- if (y2 > ymax)
- y2 = ymax;
-
- } while (range >= 1);
-
-#ifdef DEBUG
- av_log(s->avctx, AV_LOG_DEBUG, "log - MX: %d\tMY: %d\n", mx, my);
-#endif
- *mx_ptr = mx;
- *my_ptr = my;
- return dmin;
-}
-
-static int phods_motion_search(MpegEncContext * s,
- int *mx_ptr, int *my_ptr, int range,
- int xmin, int ymin, int xmax, int ymax, uint8_t *ref_picture)
-{
- int x1, y1, x2, y2, xx, yy, x, y, lastx, d;
- int mx, my, dminx, dminy;
- uint8_t *pix;
-
- xx = s->mb_x << 4;
- yy = s->mb_y << 4;
-
- /* Left limit */
- x1 = xx - range;
- if (x1 < xmin)
- x1 = xmin;
-
- /* Right limit */
- x2 = xx + range;
- if (x2 > xmax)
- x2 = xmax;
-
- /* Upper limit */
- y1 = yy - range;
- if (y1 < ymin)
- y1 = ymin;
-
- /* Lower limit */
- y2 = yy + range;
- if (y2 > ymax)
- y2 = ymax;
-
- pix = s->new_picture.data[0] + (yy * s->linesize) + xx;
- mx = 0;
- my = 0;
-
- x = xx;
- y = yy;
- do {
- dminx = 0x7fffffff;
- dminy = 0x7fffffff;
-
- lastx = x;
- for (x = x1; x <= x2; x += range) {
- d = s->dsp.pix_abs[0][0](NULL, pix, ref_picture + (y * s->linesize) + x, s->linesize, 16);
- if (d < dminx || (d == dminx && (abs(x - xx) + abs(y - yy)) < (abs(mx - xx) + abs(my - yy)))) {
- dminx = d;
- mx = x;
- }
- }
-
- x = lastx;
- for (y = y1; y <= y2; y += range) {
- d = s->dsp.pix_abs[0][0](NULL, pix, ref_picture + (y * s->linesize) + x, s->linesize, 16);
- if (d < dminy || (d == dminy && (abs(x - xx) + abs(y - yy)) < (abs(mx - xx) + abs(my - yy)))) {
- dminy = d;
- my = y;
- }
- }
-
- range = range >> 1;
-
- x = mx;
- y = my;
- x1 = mx - range;
- if (x1 < xmin)
- x1 = xmin;
-
- x2 = mx + range;
- if (x2 > xmax)
- x2 = xmax;
-
- y1 = my - range;
- if (y1 < ymin)
- y1 = ymin;
-
- y2 = my + range;
- if (y2 > ymax)
- y2 = ymax;
-
- } while (range >= 1);
-
-#ifdef DEBUG
- av_log(s->avctx, AV_LOG_DEBUG, "phods - MX: %d\tMY: %d\n", mx, my);
-#endif
-
- /* half pixel search */
- *mx_ptr = mx;
- *my_ptr = my;
- return dminy;
-}
-#endif /* 0 */
-
-#define Z_THRESHOLD 256
-
-#define CHECK_SAD_HALF_MV(suffix, x, y) \
-{\
- d= s->dsp.pix_abs[size][(x?1:0)+(y?2:0)](NULL, pix, ptr+((x)>>1), stride, h);\
- d += (mv_penalty[pen_x + x] + mv_penalty[pen_y + y])*penalty_factor;\
- COPY3_IF_LT(dminh, d, dx, x, dy, y)\
-}
-
-static inline int sad_hpel_motion_search(MpegEncContext * s,
- int *mx_ptr, int *my_ptr, int dmin,
- int src_index, int ref_index,
- int size, int h)
-{
- MotionEstContext * const c= &s->me;
- const int penalty_factor= c->sub_penalty_factor;
- int mx, my, dminh;
- uint8_t *pix, *ptr;
- int stride= c->stride;
- const int flags= c->sub_flags;
- LOAD_COMMON
-
- assert(flags == 0);
-
- if(c->skip){
-// printf("S");
- *mx_ptr = 0;
- *my_ptr = 0;
- return dmin;
- }
-// printf("N");
-
- pix = c->src[src_index][0];
-
- mx = *mx_ptr;
- my = *my_ptr;
- ptr = c->ref[ref_index][0] + (my * stride) + mx;
-
- dminh = dmin;
-
- if (mx > xmin && mx < xmax &&
- my > ymin && my < ymax) {
- int dx=0, dy=0;
- int d, pen_x, pen_y;
- const int index= (my<<ME_MAP_SHIFT) + mx;
- const int t= score_map[(index-(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)];
- const int l= score_map[(index- 1 )&(ME_MAP_SIZE-1)];
- const int r= score_map[(index+ 1 )&(ME_MAP_SIZE-1)];
- const int b= score_map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)];
- mx<<=1;
- my<<=1;
-
-
- pen_x= pred_x + mx;
- pen_y= pred_y + my;
-
- ptr-= stride;
- if(t<=b){
- CHECK_SAD_HALF_MV(y2 , 0, -1)
- if(l<=r){
- CHECK_SAD_HALF_MV(xy2, -1, -1)
- if(t+r<=b+l){
- CHECK_SAD_HALF_MV(xy2, +1, -1)
- ptr+= stride;
- }else{
- ptr+= stride;
- CHECK_SAD_HALF_MV(xy2, -1, +1)
- }
- CHECK_SAD_HALF_MV(x2 , -1, 0)
- }else{
- CHECK_SAD_HALF_MV(xy2, +1, -1)
- if(t+l<=b+r){
- CHECK_SAD_HALF_MV(xy2, -1, -1)
- ptr+= stride;
- }else{
- ptr+= stride;
- CHECK_SAD_HALF_MV(xy2, +1, +1)
- }
- CHECK_SAD_HALF_MV(x2 , +1, 0)
- }
- }else{
- if(l<=r){
- if(t+l<=b+r){
- CHECK_SAD_HALF_MV(xy2, -1, -1)
- ptr+= stride;
- }else{
- ptr+= stride;
- CHECK_SAD_HALF_MV(xy2, +1, +1)
- }
- CHECK_SAD_HALF_MV(x2 , -1, 0)
- CHECK_SAD_HALF_MV(xy2, -1, +1)
- }else{
- if(t+r<=b+l){
- CHECK_SAD_HALF_MV(xy2, +1, -1)
- ptr+= stride;
- }else{
- ptr+= stride;
- CHECK_SAD_HALF_MV(xy2, -1, +1)
- }
- CHECK_SAD_HALF_MV(x2 , +1, 0)
- CHECK_SAD_HALF_MV(xy2, +1, +1)
- }
- CHECK_SAD_HALF_MV(y2 , 0, +1)
- }
- mx+=dx;
- my+=dy;
-
- }else{
- mx<<=1;
- my<<=1;
- }
-
- *mx_ptr = mx;
- *my_ptr = my;
- return dminh;
-}
-
-static inline void set_p_mv_tables(MpegEncContext * s, int mx, int my, int mv4)
-{
- const int xy= s->mb_x + s->mb_y*s->mb_stride;
-
- s->p_mv_table[xy][0] = mx;
- s->p_mv_table[xy][1] = my;
-
- /* has already been set to the 4 MV if 4MV is done */
- if(mv4){
- int mot_xy= s->block_index[0];
-
- s->current_picture.motion_val[0][mot_xy ][0]= mx;
- s->current_picture.motion_val[0][mot_xy ][1]= my;
- s->current_picture.motion_val[0][mot_xy+1][0]= mx;
- s->current_picture.motion_val[0][mot_xy+1][1]= my;
-
- mot_xy += s->b8_stride;
- s->current_picture.motion_val[0][mot_xy ][0]= mx;
- s->current_picture.motion_val[0][mot_xy ][1]= my;
- s->current_picture.motion_val[0][mot_xy+1][0]= mx;
- s->current_picture.motion_val[0][mot_xy+1][1]= my;
- }
-}
-
-/**
- * get fullpel ME search limits.
- */
-static inline void get_limits(MpegEncContext *s, int x, int y)
-{
- MotionEstContext * const c= &s->me;
- int range= c->avctx->me_range >> (1 + !!(c->flags&FLAG_QPEL));
-/*
- if(c->avctx->me_range) c->range= c->avctx->me_range >> 1;
- else c->range= 16;
-*/
- if (s->unrestricted_mv) {
- c->xmin = - x - 16;
- c->ymin = - y - 16;
- c->xmax = - x + s->mb_width *16;
- c->ymax = - y + s->mb_height*16;
- } else if (s->out_format == FMT_H261){
- // Search range of H261 is different from other codec standards
- c->xmin = (x > 15) ? - 15 : 0;
- c->ymin = (y > 15) ? - 15 : 0;
- c->xmax = (x < s->mb_width * 16 - 16) ? 15 : 0;
- c->ymax = (y < s->mb_height * 16 - 16) ? 15 : 0;
- } else {
- c->xmin = - x;
- c->ymin = - y;
- c->xmax = - x + s->mb_width *16 - 16;
- c->ymax = - y + s->mb_height*16 - 16;
- }
- if(range){
- c->xmin = FFMAX(c->xmin,-range);
- c->xmax = FFMIN(c->xmax, range);
- c->ymin = FFMAX(c->ymin,-range);
- c->ymax = FFMIN(c->ymax, range);
- }
-}
-
-static inline void init_mv4_ref(MotionEstContext *c){
- const int stride= c->stride;
-
- c->ref[1][0] = c->ref[0][0] + 8;
- c->ref[2][0] = c->ref[0][0] + 8*stride;
- c->ref[3][0] = c->ref[2][0] + 8;
- c->src[1][0] = c->src[0][0] + 8;
- c->src[2][0] = c->src[0][0] + 8*stride;
- c->src[3][0] = c->src[2][0] + 8;
-}
-
-static inline int h263_mv4_search(MpegEncContext *s, int mx, int my, int shift)
-{
- MotionEstContext * const c= &s->me;
- const int size= 1;
- const int h=8;
- int block;
- int P[10][2];
- int dmin_sum=0, mx4_sum=0, my4_sum=0;
- int same=1;
- const int stride= c->stride;
- uint8_t *mv_penalty= c->current_mv_penalty;
-
- init_mv4_ref(c);
-
- for(block=0; block<4; block++){
- int mx4, my4;
- int pred_x4, pred_y4;
- int dmin4;
- static const int off[4]= {2, 1, 1, -1};
- const int mot_stride = s->b8_stride;
- const int mot_xy = s->block_index[block];
-
- P_LEFT[0] = s->current_picture.motion_val[0][mot_xy - 1][0];
- P_LEFT[1] = s->current_picture.motion_val[0][mot_xy - 1][1];
-
- if(P_LEFT[0] > (c->xmax<<shift)) P_LEFT[0] = (c->xmax<<shift);
-
- /* special case for first line */
- if (s->first_slice_line && block<2) {
- c->pred_x= pred_x4= P_LEFT[0];
- c->pred_y= pred_y4= P_LEFT[1];
- } else {
- P_TOP[0] = s->current_picture.motion_val[0][mot_xy - mot_stride ][0];
- P_TOP[1] = s->current_picture.motion_val[0][mot_xy - mot_stride ][1];
- P_TOPRIGHT[0] = s->current_picture.motion_val[0][mot_xy - mot_stride + off[block]][0];
- P_TOPRIGHT[1] = s->current_picture.motion_val[0][mot_xy - mot_stride + off[block]][1];
- if(P_TOP[1] > (c->ymax<<shift)) P_TOP[1] = (c->ymax<<shift);
- if(P_TOPRIGHT[0] < (c->xmin<<shift)) P_TOPRIGHT[0]= (c->xmin<<shift);
- if(P_TOPRIGHT[0] > (c->xmax<<shift)) P_TOPRIGHT[0]= (c->xmax<<shift);
- if(P_TOPRIGHT[1] > (c->ymax<<shift)) P_TOPRIGHT[1]= (c->ymax<<shift);
-
- P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
- P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);
-
- c->pred_x= pred_x4 = P_MEDIAN[0];
- c->pred_y= pred_y4 = P_MEDIAN[1];
- }
- P_MV1[0]= mx;
- P_MV1[1]= my;
-
- dmin4 = epzs_motion_search4(s, &mx4, &my4, P, block, block, s->p_mv_table, (1<<16)>>shift);
-
- dmin4= c->sub_motion_search(s, &mx4, &my4, dmin4, block, block, size, h);
-
- if(s->dsp.me_sub_cmp[0] != s->dsp.mb_cmp[0]){
- int dxy;
- const int offset= ((block&1) + (block>>1)*stride)*8;
- uint8_t *dest_y = c->scratchpad + offset;
- if(s->quarter_sample){
- uint8_t *ref= c->ref[block][0] + (mx4>>2) + (my4>>2)*stride;
- dxy = ((my4 & 3) << 2) | (mx4 & 3);
-
- if(s->no_rounding)
- s->dsp.put_no_rnd_qpel_pixels_tab[1][dxy](dest_y , ref , stride);
- else
- s->dsp.put_qpel_pixels_tab [1][dxy](dest_y , ref , stride);
- }else{
- uint8_t *ref= c->ref[block][0] + (mx4>>1) + (my4>>1)*stride;
- dxy = ((my4 & 1) << 1) | (mx4 & 1);
-
- if(s->no_rounding)
- s->dsp.put_no_rnd_pixels_tab[1][dxy](dest_y , ref , stride, h);
- else
- s->dsp.put_pixels_tab [1][dxy](dest_y , ref , stride, h);
- }
- dmin_sum+= (mv_penalty[mx4-pred_x4] + mv_penalty[my4-pred_y4])*c->mb_penalty_factor;
- }else
- dmin_sum+= dmin4;
-
- if(s->quarter_sample){
- mx4_sum+= mx4/2;
- my4_sum+= my4/2;
- }else{
- mx4_sum+= mx4;
- my4_sum+= my4;
- }
-
- s->current_picture.motion_val[0][ s->block_index[block] ][0]= mx4;
- s->current_picture.motion_val[0][ s->block_index[block] ][1]= my4;
-
- if(mx4 != mx || my4 != my) same=0;
- }
-
- if(same)
- return INT_MAX;
-
- if(s->dsp.me_sub_cmp[0] != s->dsp.mb_cmp[0]){
- dmin_sum += s->dsp.mb_cmp[0](s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*16*stride, c->scratchpad, stride, 16);
- }
-
- if(c->avctx->mb_cmp&FF_CMP_CHROMA){
- int dxy;
- int mx, my;
- int offset;
-
- mx= ff_h263_round_chroma(mx4_sum);
- my= ff_h263_round_chroma(my4_sum);
- dxy = ((my & 1) << 1) | (mx & 1);
-
- offset= (s->mb_x*8 + (mx>>1)) + (s->mb_y*8 + (my>>1))*s->uvlinesize;
-
- if(s->no_rounding){
- s->dsp.put_no_rnd_pixels_tab[1][dxy](c->scratchpad , s->last_picture.data[1] + offset, s->uvlinesize, 8);
- s->dsp.put_no_rnd_pixels_tab[1][dxy](c->scratchpad+8 , s->last_picture.data[2] + offset, s->uvlinesize, 8);
- }else{
- s->dsp.put_pixels_tab [1][dxy](c->scratchpad , s->last_picture.data[1] + offset, s->uvlinesize, 8);
- s->dsp.put_pixels_tab [1][dxy](c->scratchpad+8 , s->last_picture.data[2] + offset, s->uvlinesize, 8);
- }
-
- dmin_sum += s->dsp.mb_cmp[1](s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*8*s->uvlinesize, c->scratchpad , s->uvlinesize, 8);
- dmin_sum += s->dsp.mb_cmp[1](s, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*8*s->uvlinesize, c->scratchpad+8, s->uvlinesize, 8);
- }
-
- c->pred_x= mx;
- c->pred_y= my;
-
- switch(c->avctx->mb_cmp&0xFF){
- /*case FF_CMP_SSE:
- return dmin_sum+ 32*s->qscale*s->qscale;*/
- case FF_CMP_RD:
- return dmin_sum;
- default:
- return dmin_sum+ 11*c->mb_penalty_factor;
- }
-}
-
-static inline void init_interlaced_ref(MpegEncContext *s, int ref_index){
- MotionEstContext * const c= &s->me;
-
- c->ref[1+ref_index][0] = c->ref[0+ref_index][0] + s->linesize;
- c->src[1][0] = c->src[0][0] + s->linesize;
- if(c->flags & FLAG_CHROMA){
- c->ref[1+ref_index][1] = c->ref[0+ref_index][1] + s->uvlinesize;
- c->ref[1+ref_index][2] = c->ref[0+ref_index][2] + s->uvlinesize;
- c->src[1][1] = c->src[0][1] + s->uvlinesize;
- c->src[1][2] = c->src[0][2] + s->uvlinesize;
- }
-}
-
-static int interlaced_search(MpegEncContext *s, int ref_index,
- int16_t (*mv_tables[2][2])[2], uint8_t *field_select_tables[2], int mx, int my, int user_field_select)
-{
- MotionEstContext * const c= &s->me;
- const int size=0;
- const int h=8;
- int block;
- int P[10][2];
- uint8_t * const mv_penalty= c->current_mv_penalty;
- int same=1;
- const int stride= 2*s->linesize;
- int dmin_sum= 0;
- const int mot_stride= s->mb_stride;
- const int xy= s->mb_x + s->mb_y*mot_stride;
-
- c->ymin>>=1;
- c->ymax>>=1;
- c->stride<<=1;
- c->uvstride<<=1;
- init_interlaced_ref(s, ref_index);
-
- for(block=0; block<2; block++){
- int field_select;
- int best_dmin= INT_MAX;
- int best_field= -1;
-
- for(field_select=0; field_select<2; field_select++){
- int dmin, mx_i, my_i;
- int16_t (*mv_table)[2]= mv_tables[block][field_select];
-
- if(user_field_select){
- assert(field_select==0 || field_select==1);
- assert(field_select_tables[block][xy]==0 || field_select_tables[block][xy]==1);
- if(field_select_tables[block][xy] != field_select)
- continue;
- }
-
- P_LEFT[0] = mv_table[xy - 1][0];
- P_LEFT[1] = mv_table[xy - 1][1];
- if(P_LEFT[0] > (c->xmax<<1)) P_LEFT[0] = (c->xmax<<1);
-
- c->pred_x= P_LEFT[0];
- c->pred_y= P_LEFT[1];
-
- if(!s->first_slice_line){
- P_TOP[0] = mv_table[xy - mot_stride][0];
- P_TOP[1] = mv_table[xy - mot_stride][1];
- P_TOPRIGHT[0] = mv_table[xy - mot_stride + 1][0];
- P_TOPRIGHT[1] = mv_table[xy - mot_stride + 1][1];
- if(P_TOP[1] > (c->ymax<<1)) P_TOP[1] = (c->ymax<<1);
- if(P_TOPRIGHT[0] < (c->xmin<<1)) P_TOPRIGHT[0]= (c->xmin<<1);
- if(P_TOPRIGHT[0] > (c->xmax<<1)) P_TOPRIGHT[0]= (c->xmax<<1);
- if(P_TOPRIGHT[1] > (c->ymax<<1)) P_TOPRIGHT[1]= (c->ymax<<1);
-
- P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
- P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);
- }
- P_MV1[0]= mx; //FIXME not correct if block != field_select
- P_MV1[1]= my / 2;
-
- dmin = epzs_motion_search2(s, &mx_i, &my_i, P, block, field_select+ref_index, mv_table, (1<<16)>>1);
-
- dmin= c->sub_motion_search(s, &mx_i, &my_i, dmin, block, field_select+ref_index, size, h);
-
- mv_table[xy][0]= mx_i;
- mv_table[xy][1]= my_i;
-
- if(s->dsp.me_sub_cmp[0] != s->dsp.mb_cmp[0]){
- int dxy;
-
- //FIXME chroma ME
- uint8_t *ref= c->ref[field_select+ref_index][0] + (mx_i>>1) + (my_i>>1)*stride;
- dxy = ((my_i & 1) << 1) | (mx_i & 1);
-
- if(s->no_rounding){
- s->dsp.put_no_rnd_pixels_tab[size][dxy](c->scratchpad, ref , stride, h);
- }else{
- s->dsp.put_pixels_tab [size][dxy](c->scratchpad, ref , stride, h);
- }
- dmin= s->dsp.mb_cmp[size](s, c->src[block][0], c->scratchpad, stride, h);
- dmin+= (mv_penalty[mx_i-c->pred_x] + mv_penalty[my_i-c->pred_y] + 1)*c->mb_penalty_factor;
- }else
- dmin+= c->mb_penalty_factor; //field_select bits
-
- dmin += field_select != block; //slightly prefer same field
-
- if(dmin < best_dmin){
- best_dmin= dmin;
- best_field= field_select;
- }
- }
- {
- int16_t (*mv_table)[2]= mv_tables[block][best_field];
-
- if(mv_table[xy][0] != mx) same=0; //FIXME check if these checks work and are any good at all
- if(mv_table[xy][1]&1) same=0;
- if(mv_table[xy][1]*2 != my) same=0;
- if(best_field != block) same=0;
- }
-
- field_select_tables[block][xy]= best_field;
- dmin_sum += best_dmin;
- }
-
- c->ymin<<=1;
- c->ymax<<=1;
- c->stride>>=1;
- c->uvstride>>=1;
-
- if(same)
- return INT_MAX;
-
- switch(c->avctx->mb_cmp&0xFF){
- /*case FF_CMP_SSE:
- return dmin_sum+ 32*s->qscale*s->qscale;*/
- case FF_CMP_RD:
- return dmin_sum;
- default:
- return dmin_sum+ 11*c->mb_penalty_factor;
- }
-}
-
-static void clip_input_mv(MpegEncContext * s, int16_t *mv, int interlaced){
- int ymax= s->me.ymax>>interlaced;
- int ymin= s->me.ymin>>interlaced;
-
- if(mv[0] < s->me.xmin) mv[0] = s->me.xmin;
- if(mv[0] > s->me.xmax) mv[0] = s->me.xmax;
- if(mv[1] < ymin) mv[1] = ymin;
- if(mv[1] > ymax) mv[1] = ymax;
-}
-
-static inline int check_input_motion(MpegEncContext * s, int mb_x, int mb_y, int p_type){
- MotionEstContext * const c= &s->me;
- Picture *p= s->current_picture_ptr;
- int mb_xy= mb_x + mb_y*s->mb_stride;
- int xy= 2*mb_x + 2*mb_y*s->b8_stride;
- int mb_type= s->current_picture.mb_type[mb_xy];
- int flags= c->flags;
- int shift= (flags&FLAG_QPEL) + 1;
- int mask= (1<<shift)-1;
- int x, y, i;
- int d=0;
- me_cmp_func cmpf= s->dsp.sse[0];
- me_cmp_func chroma_cmpf= s->dsp.sse[1];
-
- if(p_type && USES_LIST(mb_type, 1)){
- av_log(c->avctx, AV_LOG_ERROR, "backward motion vector in P frame\n");
- return INT_MAX/2;
- }
- assert(IS_INTRA(mb_type) || USES_LIST(mb_type,0) || USES_LIST(mb_type,1));
-
- for(i=0; i<4; i++){
- int xy= s->block_index[i];
- clip_input_mv(s, p->motion_val[0][xy], !!IS_INTERLACED(mb_type));
- clip_input_mv(s, p->motion_val[1][xy], !!IS_INTERLACED(mb_type));
- }
-
- if(IS_INTERLACED(mb_type)){
- int xy2= xy + s->b8_stride;
- s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTRA;
- c->stride<<=1;
- c->uvstride<<=1;
-
- if(!(s->flags & CODEC_FLAG_INTERLACED_ME)){
- av_log(c->avctx, AV_LOG_ERROR, "Interlaced macroblock selected but interlaced motion estimation disabled\n");
- return INT_MAX/2;
- }
-
- if(USES_LIST(mb_type, 0)){
- int field_select0= p->ref_index[0][xy ];
- int field_select1= p->ref_index[0][xy2];
- assert(field_select0==0 ||field_select0==1);
- assert(field_select1==0 ||field_select1==1);
- init_interlaced_ref(s, 0);
-
- if(p_type){
- s->p_field_select_table[0][mb_xy]= field_select0;
- s->p_field_select_table[1][mb_xy]= field_select1;
- *(uint32_t*)s->p_field_mv_table[0][field_select0][mb_xy]= *(uint32_t*)p->motion_val[0][xy ];
- *(uint32_t*)s->p_field_mv_table[1][field_select1][mb_xy]= *(uint32_t*)p->motion_val[0][xy2];
- s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTER_I;
- }else{
- s->b_field_select_table[0][0][mb_xy]= field_select0;
- s->b_field_select_table[0][1][mb_xy]= field_select1;
- *(uint32_t*)s->b_field_mv_table[0][0][field_select0][mb_xy]= *(uint32_t*)p->motion_val[0][xy ];
- *(uint32_t*)s->b_field_mv_table[0][1][field_select1][mb_xy]= *(uint32_t*)p->motion_val[0][xy2];
- s->mb_type[mb_xy]= CANDIDATE_MB_TYPE_FORWARD_I;
- }
-
- x= p->motion_val[0][xy ][0];
- y= p->motion_val[0][xy ][1];
- d = cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 8, field_select0, 0, cmpf, chroma_cmpf, flags);
- x= p->motion_val[0][xy2][0];
- y= p->motion_val[0][xy2][1];
- 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];
- assert(field_select0==0 ||field_select0==1);
- assert(field_select1==0 ||field_select1==1);
- init_interlaced_ref(s, 2);
-
- s->b_field_select_table[1][0][mb_xy]= field_select0;
- s->b_field_select_table[1][1][mb_xy]= field_select1;
- *(uint32_t*)s->b_field_mv_table[1][0][field_select0][mb_xy]= *(uint32_t*)p->motion_val[1][xy ];
- *(uint32_t*)s->b_field_mv_table[1][1][field_select1][mb_xy]= *(uint32_t*)p->motion_val[1][xy2];
- if(USES_LIST(mb_type, 0)){
- s->mb_type[mb_xy]= CANDIDATE_MB_TYPE_BIDIR_I;
- }else{
- s->mb_type[mb_xy]= CANDIDATE_MB_TYPE_BACKWARD_I;
- }
-
- x= p->motion_val[1][xy ][0];
- y= p->motion_val[1][xy ][1];
- d = cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 8, field_select0+2, 0, cmpf, chroma_cmpf, flags);
- x= p->motion_val[1][xy2][0];
- y= p->motion_val[1][xy2][1];
- d+= cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 8, field_select1+2, 1, cmpf, chroma_cmpf, flags);
- //FIXME bidir scores
- }
- c->stride>>=1;
- c->uvstride>>=1;
- }else if(IS_8X8(mb_type)){
- if(!(s->flags & CODEC_FLAG_4MV)){
- av_log(c->avctx, AV_LOG_ERROR, "4MV macroblock selected but 4MV encoding disabled\n");
- return INT_MAX/2;
- }
- cmpf= s->dsp.sse[1];
- chroma_cmpf= s->dsp.sse[1];
- init_mv4_ref(c);
- for(i=0; i<4; i++){
- xy= s->block_index[i];
- x= p->motion_val[0][xy][0];
- y= p->motion_val[0][xy][1];
- d+= cmp(s, x>>shift, y>>shift, x&mask, y&mask, 1, 8, i, i, cmpf, chroma_cmpf, flags);
- }
- s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTER4V;
- }else{
- if(USES_LIST(mb_type, 0)){
- if(p_type){
- *(uint32_t*)s->p_mv_table[mb_xy]= *(uint32_t*)p->motion_val[0][xy];
- s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTER;
- }else if(USES_LIST(mb_type, 1)){
- *(uint32_t*)s->b_bidir_forw_mv_table[mb_xy]= *(uint32_t*)p->motion_val[0][xy];
- *(uint32_t*)s->b_bidir_back_mv_table[mb_xy]= *(uint32_t*)p->motion_val[1][xy];
- s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_BIDIR;
- }else{
- *(uint32_t*)s->b_forw_mv_table[mb_xy]= *(uint32_t*)p->motion_val[0][xy];
- s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_FORWARD;
- }
- x= p->motion_val[0][xy][0];
- y= p->motion_val[0][xy][1];
- d = cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 16, 0, 0, cmpf, chroma_cmpf, flags);
- }else if(USES_LIST(mb_type, 1)){
- *(uint32_t*)s->b_back_mv_table[mb_xy]= *(uint32_t*)p->motion_val[1][xy];
- s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_BACKWARD;
-
- x= p->motion_val[1][xy][0];
- y= p->motion_val[1][xy][1];
- d = cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 16, 2, 0, cmpf, chroma_cmpf, flags);
- }else
- s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTRA;
- }
- return d;
-}
-
-void ff_estimate_p_frame_motion(MpegEncContext * s,
- int mb_x, int mb_y)
-{
- MotionEstContext * const c= &s->me;
- uint8_t *pix, *ppix;
- int sum, mx, my, dmin;
- int varc; ///< the variance of the block (sum of squared (p[y][x]-average))
- int vard; ///< sum of squared differences with the estimated motion vector
- int P[10][2];
- const int shift= 1+s->quarter_sample;
- int mb_type=0;
- Picture * const pic= &s->current_picture;
-
- init_ref(c, s->new_picture.data, s->last_picture.data, NULL, 16*mb_x, 16*mb_y, 0);
-
- assert(s->quarter_sample==0 || s->quarter_sample==1);
- assert(s->linesize == c->stride);
- assert(s->uvlinesize == c->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->f_code] + MAX_MV;
-
- get_limits(s, 16*mb_x, 16*mb_y);
- c->skip=0;
-
- /* intra / predictive decision */
- pix = c->src[0][0];
- sum = s->dsp.pix_sum(pix, s->linesize);
- varc = s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)(sum*sum))>>8) + 500;
-
- pic->mb_mean[s->mb_stride * mb_y + mb_x] = (sum+128)>>8;
- pic->mb_var [s->mb_stride * mb_y + mb_x] = (varc+128)>>8;
- c->mb_var_sum_temp += (varc+128)>>8;
-
- if(c->avctx->me_threshold){
- vard= check_input_motion(s, mb_x, mb_y, 1);
-
- if((vard+128)>>8 < c->avctx->me_threshold){
- int p_score= FFMIN(vard, varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*100);
- int i_score= varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*20;
- pic->mc_mb_var[s->mb_stride * mb_y + mb_x] = (vard+128)>>8;
- c->mc_mb_var_sum_temp += (vard+128)>>8;
- c->scene_change_score+= ff_sqrt(p_score) - ff_sqrt(i_score);
- return;
- }
- if((vard+128)>>8 < c->avctx->mb_threshold)
- mb_type= s->mb_type[mb_x + mb_y*s->mb_stride];
- }
-
- switch(s->me_method) {
- case ME_ZERO:
- default:
- no_motion_search(s, &mx, &my);
- mx-= mb_x*16;
- my-= mb_y*16;
- dmin = 0;
- break;
-#if 0
- case ME_FULL:
- dmin = full_motion_search(s, &mx, &my, range, ref_picture);
- mx-= mb_x*16;
- my-= mb_y*16;
- break;
- case ME_LOG:
- dmin = log_motion_search(s, &mx, &my, range / 2, ref_picture);
- mx-= mb_x*16;
- my-= mb_y*16;
- break;
- case ME_PHODS:
- dmin = phods_motion_search(s, &mx, &my, range / 2, ref_picture);
- mx-= mb_x*16;
- my-= mb_y*16;
- break;
-#endif
- case ME_X1:
- case ME_EPZS:
- {
- const int mot_stride = s->b8_stride;
- const int mot_xy = s->block_index[0];
-
- P_LEFT[0] = s->current_picture.motion_val[0][mot_xy - 1][0];
- P_LEFT[1] = s->current_picture.motion_val[0][mot_xy - 1][1];
-
- if(P_LEFT[0] > (c->xmax<<shift)) P_LEFT[0] = (c->xmax<<shift);
-
- if(!s->first_slice_line) {
- P_TOP[0] = s->current_picture.motion_val[0][mot_xy - mot_stride ][0];
- P_TOP[1] = s->current_picture.motion_val[0][mot_xy - mot_stride ][1];
- P_TOPRIGHT[0] = s->current_picture.motion_val[0][mot_xy - mot_stride + 2][0];
- P_TOPRIGHT[1] = s->current_picture.motion_val[0][mot_xy - mot_stride + 2][1];
- if(P_TOP[1] > (c->ymax<<shift)) P_TOP[1] = (c->ymax<<shift);
- if(P_TOPRIGHT[0] < (c->xmin<<shift)) P_TOPRIGHT[0]= (c->xmin<<shift);
- if(P_TOPRIGHT[1] > (c->ymax<<shift)) P_TOPRIGHT[1]= (c->ymax<<shift);
-
- P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
- P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);
-
- if(s->out_format == FMT_H263){
- c->pred_x = P_MEDIAN[0];
- c->pred_y = P_MEDIAN[1];
- }else { /* mpeg1 at least */
- c->pred_x= P_LEFT[0];
- c->pred_y= P_LEFT[1];
- }
- }else{
- c->pred_x= P_LEFT[0];
- c->pred_y= P_LEFT[1];
- }
-
- }
- dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, 0, s->p_mv_table, (1<<16)>>shift, 0, 16);
-
- break;
- }
-
- /* At this point (mx,my) are full-pell and the relative displacement */
- ppix = c->ref[0][0] + (my * s->linesize) + mx;
-
- vard = s->dsp.sse[0](NULL, pix, ppix, s->linesize, 16);
-
- pic->mc_mb_var[s->mb_stride * mb_y + mb_x] = (vard+128)>>8;
-// pic->mb_cmp_score[s->mb_stride * mb_y + mb_x] = dmin;
- c->mc_mb_var_sum_temp += (vard+128)>>8;
-
-#if 0
- printf("varc=%4d avg_var=%4d (sum=%4d) vard=%4d mx=%2d my=%2d\n",
- varc, s->avg_mb_var, sum, vard, mx - xx, my - yy);
-#endif
- if(mb_type){
- int p_score= FFMIN(vard, varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*100);
- int i_score= varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*20;
- c->scene_change_score+= ff_sqrt(p_score) - ff_sqrt(i_score);
-
- if(mb_type == CANDIDATE_MB_TYPE_INTER){
- c->sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);
- set_p_mv_tables(s, mx, my, 1);
- }else{
- mx <<=shift;
- my <<=shift;
- }
- if(mb_type == CANDIDATE_MB_TYPE_INTER4V){
- h263_mv4_search(s, mx, my, shift);
-
- set_p_mv_tables(s, mx, my, 0);
- }
- if(mb_type == CANDIDATE_MB_TYPE_INTER_I){
- interlaced_search(s, 0, s->p_field_mv_table, s->p_field_select_table, mx, my, 1);
- }
- }else if(c->avctx->mb_decision > FF_MB_DECISION_SIMPLE){
- int p_score= FFMIN(vard, varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*100);
- int i_score= varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*20;
- c->scene_change_score+= ff_sqrt(p_score) - ff_sqrt(i_score);
-
- if (vard*2 + 200*256 > varc)
- mb_type|= CANDIDATE_MB_TYPE_INTRA;
- if (varc*2 + 200*256 > vard || s->qscale > 24){
-// if (varc*2 + 200*256 + 50*(s->lambda2>>FF_LAMBDA_SHIFT) > vard){
- mb_type|= CANDIDATE_MB_TYPE_INTER;
- c->sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);
- if(s->flags&CODEC_FLAG_MV0)
- if(mx || my)
- mb_type |= CANDIDATE_MB_TYPE_SKIPPED; //FIXME check difference
- }else{
- mx <<=shift;
- my <<=shift;
- }
- if((s->flags&CODEC_FLAG_4MV)
- && !c->skip && varc>50<<8 && vard>10<<8){
- if(h263_mv4_search(s, mx, my, shift) < INT_MAX)
- mb_type|=CANDIDATE_MB_TYPE_INTER4V;
-
- set_p_mv_tables(s, mx, my, 0);
- }else
- set_p_mv_tables(s, mx, my, 1);
- if((s->flags&CODEC_FLAG_INTERLACED_ME)
- && !c->skip){ //FIXME varc/d checks
- if(interlaced_search(s, 0, s->p_field_mv_table, s->p_field_select_table, mx, my, 0) < INT_MAX)
- mb_type |= CANDIDATE_MB_TYPE_INTER_I;
- }
- }else{
- int intra_score, i;
- mb_type= CANDIDATE_MB_TYPE_INTER;
-
- dmin= c->sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);
- if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip)
- dmin= ff_get_mb_score(s, mx, my, 0, 0, 0, 16, 1);
-
- if((s->flags&CODEC_FLAG_4MV)
- && !c->skip && varc>50<<8 && vard>10<<8){
- int dmin4= h263_mv4_search(s, mx, my, shift);
- if(dmin4 < dmin){
- mb_type= CANDIDATE_MB_TYPE_INTER4V;
- dmin=dmin4;
- }
- }
- if((s->flags&CODEC_FLAG_INTERLACED_ME)
- && !c->skip){ //FIXME varc/d checks
- int dmin_i= interlaced_search(s, 0, s->p_field_mv_table, s->p_field_select_table, mx, my, 0);
- if(dmin_i < dmin){
- mb_type = CANDIDATE_MB_TYPE_INTER_I;
- dmin= dmin_i;
- }
- }
-
-// pic->mb_cmp_score[s->mb_stride * mb_y + mb_x] = dmin;
- set_p_mv_tables(s, mx, my, mb_type!=CANDIDATE_MB_TYPE_INTER4V);
-
- /* get intra luma score */
- if((c->avctx->mb_cmp&0xFF)==FF_CMP_SSE){
- intra_score= varc - 500;
- }else{
- int mean= (sum+128)>>8;
- mean*= 0x01010101;
-
- for(i=0; i<16; i++){
- *(uint32_t*)(&c->scratchpad[i*s->linesize+ 0]) = mean;
- *(uint32_t*)(&c->scratchpad[i*s->linesize+ 4]) = mean;
- *(uint32_t*)(&c->scratchpad[i*s->linesize+ 8]) = mean;
- *(uint32_t*)(&c->scratchpad[i*s->linesize+12]) = mean;
- }
-
- intra_score= s->dsp.mb_cmp[0](s, c->scratchpad, pix, s->linesize, 16);
- }
-#if 0 //FIXME
- /* get chroma score */
- if(c->avctx->mb_cmp&FF_CMP_CHROMA){
- for(i=1; i<3; i++){
- uint8_t *dest_c;
- int mean;
-
- if(s->out_format == FMT_H263){
- mean= (s->dc_val[i][mb_x + mb_y*s->b8_stride] + 4)>>3; //FIXME not exact but simple ;)
- }else{
- mean= (s->last_dc[i] + 4)>>3;
- }
- dest_c = s->new_picture.data[i] + (mb_y * 8 * (s->uvlinesize)) + mb_x * 8;
-
- mean*= 0x01010101;
- for(i=0; i<8; i++){
- *(uint32_t*)(&c->scratchpad[i*s->uvlinesize+ 0]) = mean;
- *(uint32_t*)(&c->scratchpad[i*s->uvlinesize+ 4]) = mean;
- }
-
- intra_score+= s->dsp.mb_cmp[1](s, c->scratchpad, dest_c, s->uvlinesize);
- }
- }
-#endif
- intra_score += c->mb_penalty_factor*16;
-
- if(intra_score < dmin){
- mb_type= CANDIDATE_MB_TYPE_INTRA;
- s->current_picture.mb_type[mb_y*s->mb_stride + mb_x]= CANDIDATE_MB_TYPE_INTRA; //FIXME cleanup
- }else
- s->current_picture.mb_type[mb_y*s->mb_stride + mb_x]= 0;
-
- {
- int p_score= FFMIN(vard, varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*100);
- int i_score= varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*20;
- c->scene_change_score+= ff_sqrt(p_score) - ff_sqrt(i_score);
- }
- }
-
- s->mb_type[mb_y*s->mb_stride + mb_x]= mb_type;
-}
-
-int ff_pre_estimate_p_frame_motion(MpegEncContext * s,
- int mb_x, int mb_y)
-{
- MotionEstContext * const c= &s->me;
- int mx, my, dmin;
- int P[10][2];
- const int shift= 1+s->quarter_sample;
- const int xy= mb_x + mb_y*s->mb_stride;
- init_ref(c, s->new_picture.data, s->last_picture.data, NULL, 16*mb_x, 16*mb_y, 0);
-
- assert(s->quarter_sample==0 || s->quarter_sample==1);
-
- c->pre_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_pre_cmp);
- c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_MV;
-
- get_limits(s, 16*mb_x, 16*mb_y);
- c->skip=0;
-
- P_LEFT[0] = s->p_mv_table[xy + 1][0];
- P_LEFT[1] = s->p_mv_table[xy + 1][1];
-
- if(P_LEFT[0] < (c->xmin<<shift)) P_LEFT[0] = (c->xmin<<shift);
-
- /* special case for first line */
- if (s->first_slice_line) {
- c->pred_x= P_LEFT[0];
- c->pred_y= P_LEFT[1];
- P_TOP[0]= P_TOPRIGHT[0]= P_MEDIAN[0]=
- P_TOP[1]= P_TOPRIGHT[1]= P_MEDIAN[1]= 0; //FIXME
- } else {
- P_TOP[0] = s->p_mv_table[xy + s->mb_stride ][0];
- P_TOP[1] = s->p_mv_table[xy + s->mb_stride ][1];
- P_TOPRIGHT[0] = s->p_mv_table[xy + s->mb_stride - 1][0];
- P_TOPRIGHT[1] = s->p_mv_table[xy + s->mb_stride - 1][1];
- if(P_TOP[1] < (c->ymin<<shift)) P_TOP[1] = (c->ymin<<shift);
- if(P_TOPRIGHT[0] > (c->xmax<<shift)) P_TOPRIGHT[0]= (c->xmax<<shift);
- if(P_TOPRIGHT[1] < (c->ymin<<shift)) P_TOPRIGHT[1]= (c->ymin<<shift);
-
- P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
- P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);
-
- c->pred_x = P_MEDIAN[0];
- c->pred_y = P_MEDIAN[1];
- }
-
- dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, 0, s->p_mv_table, (1<<16)>>shift, 0, 16);
-
- s->p_mv_table[xy][0] = mx<<shift;
- s->p_mv_table[xy][1] = my<<shift;
-
- return dmin;
-}
-
-static int ff_estimate_motion_b(MpegEncContext * s,
- int mb_x, int mb_y, int16_t (*mv_table)[2], int ref_index, int f_code)
-{
- MotionEstContext * const c= &s->me;
- int mx, my, dmin;
- int P[10][2];
- const int shift= 1+s->quarter_sample;
- const int mot_stride = s->mb_stride;
- const int mot_xy = mb_y*mot_stride + mb_x;
- uint8_t * const mv_penalty= c->mv_penalty[f_code] + MAX_MV;
- int mv_scale;
-
- 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= mv_penalty;
-
- get_limits(s, 16*mb_x, 16*mb_y);
-
- switch(s->me_method) {
- case ME_ZERO:
- default:
- no_motion_search(s, &mx, &my);
- dmin = 0;
- mx-= mb_x*16;
- my-= mb_y*16;
- break;
-#if 0
- case ME_FULL:
- dmin = full_motion_search(s, &mx, &my, range, ref_picture);
- mx-= mb_x*16;
- my-= mb_y*16;
- break;
- case ME_LOG:
- dmin = log_motion_search(s, &mx, &my, range / 2, ref_picture);
- mx-= mb_x*16;
- my-= mb_y*16;
- break;
- case ME_PHODS:
- dmin = phods_motion_search(s, &mx, &my, range / 2, ref_picture);
- mx-= mb_x*16;
- my-= mb_y*16;
- break;
-#endif
- case ME_X1:
- case ME_EPZS:
- {
- P_LEFT[0] = mv_table[mot_xy - 1][0];
- P_LEFT[1] = mv_table[mot_xy - 1][1];
-
- if(P_LEFT[0] > (c->xmax<<shift)) P_LEFT[0] = (c->xmax<<shift);
-
- /* special case for first line */
- if (!s->first_slice_line) {
- P_TOP[0] = mv_table[mot_xy - mot_stride ][0];
- P_TOP[1] = mv_table[mot_xy - mot_stride ][1];
- P_TOPRIGHT[0] = mv_table[mot_xy - mot_stride + 1 ][0];
- P_TOPRIGHT[1] = mv_table[mot_xy - mot_stride + 1 ][1];
- if(P_TOP[1] > (c->ymax<<shift)) P_TOP[1]= (c->ymax<<shift);
- if(P_TOPRIGHT[0] < (c->xmin<<shift)) P_TOPRIGHT[0]= (c->xmin<<shift);
- if(P_TOPRIGHT[1] > (c->ymax<<shift)) P_TOPRIGHT[1]= (c->ymax<<shift);
-
- P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
- P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);
- }
- c->pred_x= P_LEFT[0];
- c->pred_y= P_LEFT[1];
- }
-
- if(mv_table == s->b_forw_mv_table){
- mv_scale= (s->pb_time<<16) / (s->pp_time<<shift);
- }else{
- mv_scale= ((s->pb_time - s->pp_time)<<16) / (s->pp_time<<shift);
- }
-
- dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, ref_index, s->p_mv_table, mv_scale, 0, 16);
-
- break;
- }
-
- dmin= c->sub_motion_search(s, &mx, &my, dmin, 0, ref_index, 0, 16);
-
- if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip)
- dmin= ff_get_mb_score(s, mx, my, 0, ref_index, 0, 16, 1);
-
-//printf("%d %d %d %d//", s->mb_x, s->mb_y, mx, my);
-// s->mb_type[mb_y*s->mb_width + mb_x]= mb_type;
- mv_table[mot_xy][0]= mx;
- mv_table[mot_xy][1]= my;
-
- return dmin;
-}
-
-static inline int check_bidir_mv(MpegEncContext * s,
- int motion_fx, int motion_fy,
- int motion_bx, int motion_by,
- int pred_fx, int pred_fy,
- int pred_bx, int pred_by,
- int size, int h)
-{
- //FIXME optimize?
- //FIXME better f_code prediction (max mv & distance)
- //FIXME pointers
- MotionEstContext * const c= &s->me;
- uint8_t * const mv_penalty_f= c->mv_penalty[s->f_code] + MAX_MV; // f_code of the prev frame
- uint8_t * const mv_penalty_b= c->mv_penalty[s->b_code] + MAX_MV; // f_code of the prev frame
- int stride= c->stride;
- uint8_t *dest_y = c->scratchpad;
- uint8_t *ptr;
- int dxy;
- int src_x, src_y;
- int fbmin;
- uint8_t **src_data= c->src[0];
- uint8_t **ref_data= c->ref[0];
- uint8_t **ref2_data= c->ref[2];
-
- if(s->quarter_sample){
- dxy = ((motion_fy & 3) << 2) | (motion_fx & 3);
- src_x = motion_fx >> 2;
- src_y = motion_fy >> 2;
-
- ptr = ref_data[0] + (src_y * stride) + src_x;
- s->dsp.put_qpel_pixels_tab[0][dxy](dest_y , ptr , stride);
-
- dxy = ((motion_by & 3) << 2) | (motion_bx & 3);
- src_x = motion_bx >> 2;
- src_y = motion_by >> 2;
-
- ptr = ref2_data[0] + (src_y * stride) + src_x;
- s->dsp.avg_qpel_pixels_tab[size][dxy](dest_y , ptr , stride);
- }else{
- dxy = ((motion_fy & 1) << 1) | (motion_fx & 1);
- src_x = motion_fx >> 1;
- src_y = motion_fy >> 1;
-
- ptr = ref_data[0] + (src_y * stride) + src_x;
- s->dsp.put_pixels_tab[size][dxy](dest_y , ptr , stride, h);
-
- dxy = ((motion_by & 1) << 1) | (motion_bx & 1);
- src_x = motion_bx >> 1;
- src_y = motion_by >> 1;
-
- ptr = ref2_data[0] + (src_y * stride) + src_x;
- s->dsp.avg_pixels_tab[size][dxy](dest_y , ptr , stride, h);
- }
-
- fbmin = (mv_penalty_f[motion_fx-pred_fx] + mv_penalty_f[motion_fy-pred_fy])*c->mb_penalty_factor
- +(mv_penalty_b[motion_bx-pred_bx] + mv_penalty_b[motion_by-pred_by])*c->mb_penalty_factor
- + s->dsp.mb_cmp[size](s, src_data[0], dest_y, stride, h); //FIXME new_pic
-
- if(c->avctx->mb_cmp&FF_CMP_CHROMA){
- }
- //FIXME CHROMA !!!
-
- return fbmin;
-}
-
-/* refine the bidir vectors in hq mode and return the score in both lq & hq mode*/
-static inline int bidir_refine(MpegEncContext * s, int mb_x, int mb_y)
-{
- MotionEstContext * const c= &s->me;
- const int mot_stride = s->mb_stride;
- const int xy = mb_y *mot_stride + mb_x;
- int fbmin;
- int pred_fx= s->b_bidir_forw_mv_table[xy-1][0];
- int pred_fy= s->b_bidir_forw_mv_table[xy-1][1];
- int pred_bx= s->b_bidir_back_mv_table[xy-1][0];
- int pred_by= s->b_bidir_back_mv_table[xy-1][1];
- int motion_fx= s->b_bidir_forw_mv_table[xy][0]= s->b_forw_mv_table[xy][0];
- int motion_fy= s->b_bidir_forw_mv_table[xy][1]= s->b_forw_mv_table[xy][1];
- int motion_bx= s->b_bidir_back_mv_table[xy][0]= s->b_back_mv_table[xy][0];
- int motion_by= s->b_bidir_back_mv_table[xy][1]= s->b_back_mv_table[xy][1];
- const int flags= c->sub_flags;
- const int qpel= flags&FLAG_QPEL;
- const int shift= 1+qpel;
- const int xmin= c->xmin<<shift;
- const int ymin= c->ymin<<shift;
- const int xmax= c->xmax<<shift;
- const int ymax= c->ymax<<shift;
- uint8_t map[8][8][8][8];
-
- memset(map,0,sizeof(map));
-#define BIDIR_MAP(fx,fy,bx,by) \
- map[(motion_fx+fx)&7][(motion_fy+fy)&7][(motion_bx+bx)&7][(motion_by+by)&7]
- BIDIR_MAP(0,0,0,0) = 1;
-
- fbmin= check_bidir_mv(s, motion_fx, motion_fy,
- motion_bx, motion_by,
- pred_fx, pred_fy,
- pred_bx, pred_by,
- 0, 16);
-
- if(s->avctx->bidir_refine){
- int score, end;
-#define CHECK_BIDIR(fx,fy,bx,by)\
- if( !BIDIR_MAP(fx,fy,bx,by)\
- &&(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;\
- 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){\
- fbmin= score;\
- motion_fx+=fx;\
- motion_fy+=fy;\
- motion_bx+=bx;\
- motion_by+=by;\
- end=0;\
- }\
- }
-#define CHECK_BIDIR2(a,b,c,d)\
-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{
- 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)
- }
- }
- }
- }while(!end);
- }
-
- s->b_bidir_forw_mv_table[xy][0]= motion_fx;
- s->b_bidir_forw_mv_table[xy][1]= motion_fy;
- s->b_bidir_back_mv_table[xy][0]= motion_bx;
- s->b_bidir_back_mv_table[xy][1]= motion_by;
-
- return fbmin;
-}
-
-static inline int direct_search(MpegEncContext * s, int mb_x, int mb_y)
-{
- MotionEstContext * const c= &s->me;
- int P[10][2];
- const int mot_stride = s->mb_stride;
- const int mot_xy = mb_y*mot_stride + mb_x;
- const int shift= 1+s->quarter_sample;
- int dmin, i;
- const int time_pp= s->pp_time;
- const int time_pb= s->pb_time;
- int mx, my, xmin, xmax, ymin, ymax;
- int16_t (*mv_table)[2]= s->b_direct_mv_table;
-
- c->current_mv_penalty= c->mv_penalty[1] + MAX_MV;
- ymin= xmin=(-32)>>shift;
- ymax= xmax= 31>>shift;
-
- if(IS_8X8(s->next_picture.mb_type[mot_xy])){
- s->mv_type= MV_TYPE_8X8;
- }else{
- s->mv_type= MV_TYPE_16X16;
- }
-
- for(i=0; i<4; i++){
- int index= s->block_index[i];
- int min, max;
-
- c->co_located_mv[i][0]= s->next_picture.motion_val[0][index][0];
- c->co_located_mv[i][1]= s->next_picture.motion_val[0][index][1];
- c->direct_basis_mv[i][0]= c->co_located_mv[i][0]*time_pb/time_pp + ((i& 1)<<(shift+3));
- c->direct_basis_mv[i][1]= c->co_located_mv[i][1]*time_pb/time_pp + ((i>>1)<<(shift+3));
-// c->direct_basis_mv[1][i][0]= c->co_located_mv[i][0]*(time_pb - time_pp)/time_pp + ((i &1)<<(shift+3);
-// c->direct_basis_mv[1][i][1]= c->co_located_mv[i][1]*(time_pb - time_pp)/time_pp + ((i>>1)<<(shift+3);
-
- max= FFMAX(c->direct_basis_mv[i][0], c->direct_basis_mv[i][0] - c->co_located_mv[i][0])>>shift;
- min= FFMIN(c->direct_basis_mv[i][0], c->direct_basis_mv[i][0] - c->co_located_mv[i][0])>>shift;
- max+= 16*mb_x + 1; // +-1 is for the simpler rounding
- min+= 16*mb_x - 1;
- xmax= FFMIN(xmax, s->width - max);
- xmin= FFMAX(xmin, - 16 - min);
-
- max= FFMAX(c->direct_basis_mv[i][1], c->direct_basis_mv[i][1] - c->co_located_mv[i][1])>>shift;
- min= FFMIN(c->direct_basis_mv[i][1], c->direct_basis_mv[i][1] - c->co_located_mv[i][1])>>shift;
- max+= 16*mb_y + 1; // +-1 is for the simpler rounding
- min+= 16*mb_y - 1;
- ymax= FFMIN(ymax, s->height - max);
- ymin= FFMAX(ymin, - 16 - min);
-
- if(s->mv_type == MV_TYPE_16X16) break;
- }
-
- assert(xmax <= 15 && ymax <= 15 && xmin >= -16 && ymin >= -16);
-
- if(xmax < 0 || xmin >0 || ymax < 0 || ymin > 0){
- s->b_direct_mv_table[mot_xy][0]= 0;
- s->b_direct_mv_table[mot_xy][1]= 0;
-
- return 256*256*256*64;
- }
-
- c->xmin= xmin;
- c->ymin= ymin;
- c->xmax= xmax;
- c->ymax= ymax;
- c->flags |= FLAG_DIRECT;
- c->sub_flags |= FLAG_DIRECT;
- c->pred_x=0;
- c->pred_y=0;
-
- P_LEFT[0] = clip(mv_table[mot_xy - 1][0], xmin<<shift, xmax<<shift);
- P_LEFT[1] = clip(mv_table[mot_xy - 1][1], ymin<<shift, ymax<<shift);
-
- /* special case for first line */
- if (!s->first_slice_line) { //FIXME maybe allow this over thread boundary as its clipped
- P_TOP[0] = clip(mv_table[mot_xy - mot_stride ][0], xmin<<shift, xmax<<shift);
- P_TOP[1] = clip(mv_table[mot_xy - mot_stride ][1], ymin<<shift, ymax<<shift);
- P_TOPRIGHT[0] = clip(mv_table[mot_xy - mot_stride + 1 ][0], xmin<<shift, xmax<<shift);
- P_TOPRIGHT[1] = clip(mv_table[mot_xy - mot_stride + 1 ][1], ymin<<shift, ymax<<shift);
-
- P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
- P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);
- }
-
- dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, 0, mv_table, 1<<(16-shift), 0, 16);
- if(c->sub_flags&FLAG_QPEL)
- dmin = qpel_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);
- else
- dmin = hpel_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);
-
- if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip)
- dmin= ff_get_mb_score(s, mx, my, 0, 0, 0, 16, 1);
-
- get_limits(s, 16*mb_x, 16*mb_y); //restore c->?min/max, maybe not needed
-
- mv_table[mot_xy][0]= mx;
- mv_table[mot_xy][1]= my;
- c->flags &= ~FLAG_DIRECT;
- c->sub_flags &= ~FLAG_DIRECT;
-
- return dmin;
-}
-
-void ff_estimate_b_frame_motion(MpegEncContext * s,
- int mb_x, int mb_y)
-{
- MotionEstContext * const c= &s->me;
- const int penalty_factor= c->mb_penalty_factor;
- int fmin, bmin, dmin, fbmin, bimin, fimin;
- int type=0;
- const int xy = mb_y*s->mb_stride + mb_x;
- init_ref(c, s->new_picture.data, s->last_picture.data, s->next_picture.data, 16*mb_x, 16*mb_y, 2);
-
- get_limits(s, 16*mb_x, 16*mb_y);
-
- c->skip=0;
-
- if(s->codec_id == CODEC_ID_MPEG4 && s->next_picture.mbskip_table[xy]){
- int score= direct_search(s, mb_x, mb_y); //FIXME just check 0,0
-
- score= ((unsigned)(score*score + 128*256))>>16;
- c->mc_mb_var_sum_temp += score;
- s->current_picture.mc_mb_var[mb_y*s->mb_stride + mb_x] = score; //FIXME use SSE
- s->mb_type[mb_y*s->mb_stride + mb_x]= CANDIDATE_MB_TYPE_DIRECT0;
-
- return;
- }
-
- if(c->avctx->me_threshold){
- int vard= check_input_motion(s, mb_x, mb_y, 0);
-
- if((vard+128)>>8 < c->avctx->me_threshold){
-// pix = c->src[0][0];
-// sum = s->dsp.pix_sum(pix, s->linesize);
-// varc = s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)(sum*sum))>>8) + 500;
-
-// pic->mb_var [s->mb_stride * mb_y + mb_x] = (varc+128)>>8;
- s->current_picture.mc_mb_var[s->mb_stride * mb_y + mb_x] = (vard+128)>>8;
-/* pic->mb_mean [s->mb_stride * mb_y + mb_x] = (sum+128)>>8;
- c->mb_var_sum_temp += (varc+128)>>8;*/
- c->mc_mb_var_sum_temp += (vard+128)>>8;
-/* if (vard <= 64<<8 || vard < varc) {
- c->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc);
- }else{
- c->scene_change_score+= s->qscale * s->avctx->scenechange_factor;
- }*/
- return;
- }
- if((vard+128)>>8 < c->avctx->mb_threshold){
- type= s->mb_type[mb_y*s->mb_stride + mb_x];
- if(type == CANDIDATE_MB_TYPE_DIRECT){
- direct_search(s, mb_x, mb_y);
- }
- if(type == CANDIDATE_MB_TYPE_FORWARD || type == CANDIDATE_MB_TYPE_BIDIR){
- c->skip=0;
- ff_estimate_motion_b(s, mb_x, mb_y, s->b_forw_mv_table, 0, s->f_code);
- }
- if(type == CANDIDATE_MB_TYPE_BACKWARD || type == CANDIDATE_MB_TYPE_BIDIR){
- c->skip=0;
- ff_estimate_motion_b(s, mb_x, mb_y, s->b_back_mv_table, 2, s->b_code);
- }
- if(type == CANDIDATE_MB_TYPE_FORWARD_I || type == CANDIDATE_MB_TYPE_BIDIR_I){
- c->skip=0;
- c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_MV;
- interlaced_search(s, 0,
- s->b_field_mv_table[0], s->b_field_select_table[0],
- s->b_forw_mv_table[xy][0], s->b_forw_mv_table[xy][1], 1);
- }
- if(type == CANDIDATE_MB_TYPE_BACKWARD_I || type == CANDIDATE_MB_TYPE_BIDIR_I){
- c->skip=0;
- c->current_mv_penalty= c->mv_penalty[s->b_code] + MAX_MV;
- interlaced_search(s, 2,
- s->b_field_mv_table[1], s->b_field_select_table[1],
- s->b_back_mv_table[xy][0], s->b_back_mv_table[xy][1], 1);
- }
- return;
- }
- }
-
- if (s->codec_id == CODEC_ID_MPEG4)
- dmin= direct_search(s, mb_x, mb_y);
- else
- dmin= INT_MAX;
-//FIXME penalty stuff for non mpeg4
- c->skip=0;
- fmin= ff_estimate_motion_b(s, mb_x, mb_y, s->b_forw_mv_table, 0, s->f_code) + 3*penalty_factor;
-
- c->skip=0;
- bmin= ff_estimate_motion_b(s, mb_x, mb_y, s->b_back_mv_table, 2, s->b_code) + 2*penalty_factor;
-//printf(" %d %d ", s->b_forw_mv_table[xy][0], s->b_forw_mv_table[xy][1]);
-
- c->skip=0;
- fbmin= bidir_refine(s, mb_x, mb_y) + penalty_factor;
-//printf("%d %d %d %d\n", dmin, fmin, bmin, fbmin);
-
- if(s->flags & CODEC_FLAG_INTERLACED_ME){
-//FIXME mb type penalty
- c->skip=0;
- c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_MV;
- fimin= interlaced_search(s, 0,
- s->b_field_mv_table[0], s->b_field_select_table[0],
- s->b_forw_mv_table[xy][0], s->b_forw_mv_table[xy][1], 0);
- c->current_mv_penalty= c->mv_penalty[s->b_code] + MAX_MV;
- bimin= interlaced_search(s, 2,
- s->b_field_mv_table[1], s->b_field_select_table[1],
- s->b_back_mv_table[xy][0], s->b_back_mv_table[xy][1], 0);
- }else
- fimin= bimin= INT_MAX;
-
- {
- int score= fmin;
- type = CANDIDATE_MB_TYPE_FORWARD;
-
- if (dmin <= score){
- score = dmin;
- type = CANDIDATE_MB_TYPE_DIRECT;
- }
- if(bmin<score){
- score=bmin;
- type= CANDIDATE_MB_TYPE_BACKWARD;
- }
- if(fbmin<score){
- score=fbmin;
- type= CANDIDATE_MB_TYPE_BIDIR;
- }
- if(fimin<score){
- score=fimin;
- type= CANDIDATE_MB_TYPE_FORWARD_I;
- }
- if(bimin<score){
- score=bimin;
- type= CANDIDATE_MB_TYPE_BACKWARD_I;
- }
-
- score= ((unsigned)(score*score + 128*256))>>16;
- c->mc_mb_var_sum_temp += score;
- s->current_picture.mc_mb_var[mb_y*s->mb_stride + mb_x] = score; //FIXME use SSE
- }
-
- if(c->avctx->mb_decision > FF_MB_DECISION_SIMPLE){
- type= CANDIDATE_MB_TYPE_FORWARD | CANDIDATE_MB_TYPE_BACKWARD | CANDIDATE_MB_TYPE_BIDIR | CANDIDATE_MB_TYPE_DIRECT;
- if(fimin < INT_MAX)
- type |= CANDIDATE_MB_TYPE_FORWARD_I;
- if(bimin < INT_MAX)
- type |= CANDIDATE_MB_TYPE_BACKWARD_I;
- if(fimin < INT_MAX && bimin < INT_MAX){
- type |= CANDIDATE_MB_TYPE_BIDIR_I;
- }
- //FIXME something smarter
- if(dmin>256*256*16) type&= ~CANDIDATE_MB_TYPE_DIRECT; //dont try direct mode if its invalid for this MB
- if(s->codec_id == CODEC_ID_MPEG4 && type&CANDIDATE_MB_TYPE_DIRECT && s->flags&CODEC_FLAG_MV0 && *(uint32_t*)s->b_direct_mv_table[xy])
- type |= CANDIDATE_MB_TYPE_DIRECT0;
-#if 0
- if(s->out_format == FMT_MPEG1)
- type |= CANDIDATE_MB_TYPE_INTRA;
-#endif
- }
-
- s->mb_type[mb_y*s->mb_stride + mb_x]= type;
-}
-
-/* find best f_code for ME which do unlimited searches */
-int ff_get_best_fcode(MpegEncContext * s, int16_t (*mv_table)[2], int type)
-{
- if(s->me_method>=ME_EPZS){
- int score[8];
- int i, y, range= s->avctx->me_range ? s->avctx->me_range : (INT_MAX/2);
- uint8_t * fcode_tab= s->fcode_tab;
- int best_fcode=-1;
- int best_score=-10000000;
-
- if(s->msmpeg4_version)
- range= FFMIN(range, 16);
- else if(s->codec_id == CODEC_ID_MPEG2VIDEO && s->avctx->strict_std_compliance >= FF_COMPLIANCE_NORMAL)
- range= FFMIN(range, 256);
-
- for(i=0; i<8; i++) score[i]= s->mb_num*(8-i);
-
- for(y=0; y<s->mb_height; y++){
- int x;
- int xy= y*s->mb_stride;
- for(x=0; x<s->mb_width; x++){
- if(s->mb_type[xy] & type){
- int mx= mv_table[xy][0];
- int my= mv_table[xy][1];
- int fcode= FFMAX(fcode_tab[mx + MAX_MV],
- fcode_tab[my + MAX_MV]);
- int j;
-
- if(mx >= range || mx < -range ||
- my >= range || my < -range)
- continue;
-
- for(j=0; j<fcode && j<8; j++){
- if(s->pict_type==B_TYPE || s->current_picture.mc_mb_var[xy] < s->current_picture.mb_var[xy])
- score[j]-= 170;
- }
- }
- xy++;
- }
- }
-
- for(i=1; i<8; i++){
- if(score[i] > best_score){
- best_score= score[i];
- best_fcode= i;
- }
-// printf("%d %d\n", i, score[i]);
- }
-
-// printf("fcode: %d type: %d\n", i, s->pict_type);
- return best_fcode;
-/* for(i=0; i<=MAX_FCODE; i++){
- printf("%d ", mv_num[i]);
- }
- printf("\n");*/
- }else{
- return 1;
- }
-}
-
-void ff_fix_long_p_mvs(MpegEncContext * s)
-{
- MotionEstContext * const c= &s->me;
- const int f_code= s->f_code;
- int y, range;
- assert(s->pict_type==P_TYPE);
-
- range = (((s->out_format == FMT_MPEG1 || s->msmpeg4_version) ? 8 : 16) << f_code);
-
- assert(range <= 16 || !s->msmpeg4_version);
- assert(range <=256 || !(s->codec_id == CODEC_ID_MPEG2VIDEO && s->avctx->strict_std_compliance >= FF_COMPLIANCE_NORMAL));
-
- if(c->avctx->me_range && range > c->avctx->me_range) range= c->avctx->me_range;
-
-//printf("%d no:%d %d//\n", clip, noclip, f_code);
- if(s->flags&CODEC_FLAG_4MV){
- const int wrap= s->b8_stride;
-
- /* clip / convert to intra 8x8 type MVs */
- for(y=0; y<s->mb_height; y++){
- int xy= y*2*wrap;
- int i= y*s->mb_stride;
- int x;
-
- for(x=0; x<s->mb_width; x++){
- if(s->mb_type[i]&CANDIDATE_MB_TYPE_INTER4V){
- int block;
- for(block=0; block<4; block++){
- int off= (block& 1) + (block>>1)*wrap;
- int mx= s->current_picture.motion_val[0][ xy + off ][0];
- int my= s->current_picture.motion_val[0][ xy + off ][1];
-
- if( mx >=range || mx <-range
- || my >=range || my <-range){
- s->mb_type[i] &= ~CANDIDATE_MB_TYPE_INTER4V;
- s->mb_type[i] |= CANDIDATE_MB_TYPE_INTRA;
- s->current_picture.mb_type[i]= CANDIDATE_MB_TYPE_INTRA;
- }
- }
- }
- xy+=2;
- i++;
- }
- }
- }
-}
-
-/**
- *
- * @param truncate 1 for truncation, 0 for using intra
- */
-void ff_fix_long_mvs(MpegEncContext * s, uint8_t *field_select_table, int field_select,
- int16_t (*mv_table)[2], int f_code, int type, int truncate)
-{
- MotionEstContext * const c= &s->me;
- int y, h_range, v_range;
-
- // RAL: 8 in MPEG-1, 16 in MPEG-4
- int range = (((s->out_format == FMT_MPEG1 || s->msmpeg4_version) ? 8 : 16) << f_code);
-
- if(c->avctx->me_range && range > c->avctx->me_range) range= c->avctx->me_range;
-
- h_range= range;
- v_range= field_select_table ? range>>1 : range;
-
- /* clip / convert to intra 16x16 type MVs */
- for(y=0; y<s->mb_height; y++){
- int x;
- int xy= y*s->mb_stride;
- for(x=0; x<s->mb_width; x++){
- if (s->mb_type[xy] & type){ // RAL: "type" test added...
- if(field_select_table==NULL || field_select_table[xy] == field_select){
- if( mv_table[xy][0] >=h_range || mv_table[xy][0] <-h_range
- || mv_table[xy][1] >=v_range || mv_table[xy][1] <-v_range){
-
- if(truncate){
- if (mv_table[xy][0] > h_range-1) mv_table[xy][0]= h_range-1;
- else if(mv_table[xy][0] < -h_range ) mv_table[xy][0]= -h_range;
- if (mv_table[xy][1] > v_range-1) mv_table[xy][1]= v_range-1;
- else if(mv_table[xy][1] < -v_range ) mv_table[xy][1]= -v_range;
- }else{
- s->mb_type[xy] &= ~type;
- s->mb_type[xy] |= CANDIDATE_MB_TYPE_INTRA;
- mv_table[xy][0]=
- mv_table[xy][1]= 0;
- }
- }
- }
- }
- xy++;
- }
- }
-}
-
-#endif /* CONFIG_ENCODERS */
diff --git a/src/libffmpeg/libavcodec/motion_est_template.c b/src/libffmpeg/libavcodec/motion_est_template.c
deleted file mode 100644
index 897c08e3d..000000000
--- a/src/libffmpeg/libavcodec/motion_est_template.c
+++ /dev/null
@@ -1,1238 +0,0 @@
-/*
- * Motion estimation
- * 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 motion_est_template.c
- * Motion estimation template.
- */
-
-//lets hope gcc will remove the unused vars ...(gcc 3.2.2 seems to do it ...)
-#define LOAD_COMMON\
- uint32_t attribute_unused * const score_map= c->score_map;\
- const int attribute_unused xmin= c->xmin;\
- const int attribute_unused ymin= c->ymin;\
- const int attribute_unused xmax= c->xmax;\
- const int attribute_unused ymax= c->ymax;\
- uint8_t *mv_penalty= c->current_mv_penalty;\
- const int pred_x= c->pred_x;\
- const int pred_y= c->pred_y;\
-
-#define CHECK_HALF_MV(dx, dy, x, y)\
-{\
- const int hx= 2*(x)+(dx);\
- const int hy= 2*(y)+(dy);\
- d= cmp(s, x, y, dx, dy, size, h, ref_index, src_index, cmp_sub, chroma_cmp_sub, flags);\
- d += (mv_penalty[hx - pred_x] + mv_penalty[hy - pred_y])*penalty_factor;\
- COPY3_IF_LT(dmin, d, bx, hx, by, hy)\
-}
-
-#if 0
-static int hpel_motion_search)(MpegEncContext * s,
- int *mx_ptr, int *my_ptr, int dmin,
- uint8_t *ref_data[3],
- int size)
-{
- const int xx = 16 * s->mb_x + 8*(n&1);
- const int yy = 16 * s->mb_y + 8*(n>>1);
- const int mx = *mx_ptr;
- const int my = *my_ptr;
- const int penalty_factor= c->sub_penalty_factor;
-
- LOAD_COMMON
-
- // INIT;
- //FIXME factorize
- me_cmp_func cmp, chroma_cmp, cmp_sub, chroma_cmp_sub;
-
- if(s->no_rounding /*FIXME b_type*/){
- hpel_put= &s->dsp.put_no_rnd_pixels_tab[size];
- chroma_hpel_put= &s->dsp.put_no_rnd_pixels_tab[size+1];
- }else{
- hpel_put=& s->dsp.put_pixels_tab[size];
- chroma_hpel_put= &s->dsp.put_pixels_tab[size+1];
- }
- cmpf= s->dsp.me_cmp[size];
- chroma_cmpf= s->dsp.me_cmp[size+1];
- cmp_sub= s->dsp.me_sub_cmp[size];
- chroma_cmp_sub= s->dsp.me_sub_cmp[size+1];
-
- if(c->skip){ //FIXME somehow move up (benchmark)
- *mx_ptr = 0;
- *my_ptr = 0;
- return dmin;
- }
-
- if(c->avctx->me_cmp != c->avctx->me_sub_cmp){
- CMP_HPEL(dmin, 0, 0, mx, my, size);
- if(mx || my)
- dmin += (mv_penalty[2*mx - pred_x] + mv_penalty[2*my - pred_y])*penalty_factor;
- }
-
- if (mx > xmin && mx < xmax &&
- my > ymin && my < ymax) {
- int bx=2*mx, by=2*my;
- int d= dmin;
-
- CHECK_HALF_MV(1, 1, mx-1, my-1)
- CHECK_HALF_MV(0, 1, mx , my-1)
- CHECK_HALF_MV(1, 1, mx , my-1)
- CHECK_HALF_MV(1, 0, mx-1, my )
- CHECK_HALF_MV(1, 0, mx , my )
- CHECK_HALF_MV(1, 1, mx-1, my )
- CHECK_HALF_MV(0, 1, mx , my )
- CHECK_HALF_MV(1, 1, mx , my )
-
- assert(bx >= xmin*2 || bx <= xmax*2 || by >= ymin*2 || by <= ymax*2);
-
- *mx_ptr = bx;
- *my_ptr = by;
- }else{
- *mx_ptr =2*mx;
- *my_ptr =2*my;
- }
-
- return dmin;
-}
-
-#else
-static int hpel_motion_search(MpegEncContext * s,
- int *mx_ptr, int *my_ptr, int dmin,
- int src_index, int ref_index,
- int size, int h)
-{
- MotionEstContext * const c= &s->me;
- const int mx = *mx_ptr;
- const int my = *my_ptr;
- const int penalty_factor= c->sub_penalty_factor;
- me_cmp_func cmp_sub, chroma_cmp_sub;
- int bx=2*mx, by=2*my;
-
- LOAD_COMMON
- int flags= c->sub_flags;
-
- //FIXME factorize
-
- cmp_sub= s->dsp.me_sub_cmp[size];
- chroma_cmp_sub= s->dsp.me_sub_cmp[size+1];
-
- if(c->skip){ //FIXME move out of hpel?
- *mx_ptr = 0;
- *my_ptr = 0;
- return dmin;
- }
-
- if(c->avctx->me_cmp != c->avctx->me_sub_cmp){
- dmin= cmp(s, mx, my, 0, 0, size, h, ref_index, src_index, cmp_sub, chroma_cmp_sub, flags);
- if(mx || my || size>0)
- dmin += (mv_penalty[2*mx - pred_x] + mv_penalty[2*my - pred_y])*penalty_factor;
- }
-
- if (mx > xmin && mx < xmax &&
- my > ymin && my < ymax) {
- int d= dmin;
- const int index= (my<<ME_MAP_SHIFT) + mx;
- const int t= score_map[(index-(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)]
- + (mv_penalty[bx - pred_x] + mv_penalty[by-2 - pred_y])*c->penalty_factor;
- const int l= score_map[(index- 1 )&(ME_MAP_SIZE-1)]
- + (mv_penalty[bx-2 - pred_x] + mv_penalty[by - pred_y])*c->penalty_factor;
- const int r= score_map[(index+ 1 )&(ME_MAP_SIZE-1)]
- + (mv_penalty[bx+2 - pred_x] + mv_penalty[by - pred_y])*c->penalty_factor;
- const int b= score_map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)]
- + (mv_penalty[bx - pred_x] + mv_penalty[by+2 - pred_y])*c->penalty_factor;
-
-#if 1
- int key;
- int map_generation= c->map_generation;
-#ifndef NDEBUG
- uint32_t *map= c->map;
-#endif
- key= ((my-1)<<ME_MAP_MV_BITS) + (mx) + map_generation;
- assert(map[(index-(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)] == key);
- key= ((my+1)<<ME_MAP_MV_BITS) + (mx) + map_generation;
- assert(map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)] == key);
- key= ((my)<<ME_MAP_MV_BITS) + (mx+1) + map_generation;
- assert(map[(index+1)&(ME_MAP_SIZE-1)] == key);
- key= ((my)<<ME_MAP_MV_BITS) + (mx-1) + map_generation;
- assert(map[(index-1)&(ME_MAP_SIZE-1)] == key);
-#endif
- if(t<=b){
- CHECK_HALF_MV(0, 1, mx ,my-1)
- if(l<=r){
- CHECK_HALF_MV(1, 1, mx-1, my-1)
- if(t+r<=b+l){
- CHECK_HALF_MV(1, 1, mx , my-1)
- }else{
- CHECK_HALF_MV(1, 1, mx-1, my )
- }
- CHECK_HALF_MV(1, 0, mx-1, my )
- }else{
- CHECK_HALF_MV(1, 1, mx , my-1)
- if(t+l<=b+r){
- CHECK_HALF_MV(1, 1, mx-1, my-1)
- }else{
- CHECK_HALF_MV(1, 1, mx , my )
- }
- CHECK_HALF_MV(1, 0, mx , my )
- }
- }else{
- if(l<=r){
- if(t+l<=b+r){
- CHECK_HALF_MV(1, 1, mx-1, my-1)
- }else{
- CHECK_HALF_MV(1, 1, mx , my )
- }
- CHECK_HALF_MV(1, 0, mx-1, my)
- CHECK_HALF_MV(1, 1, mx-1, my)
- }else{
- if(t+r<=b+l){
- CHECK_HALF_MV(1, 1, mx , my-1)
- }else{
- CHECK_HALF_MV(1, 1, mx-1, my)
- }
- CHECK_HALF_MV(1, 0, mx , my)
- CHECK_HALF_MV(1, 1, mx , my)
- }
- CHECK_HALF_MV(0, 1, mx , my)
- }
- assert(bx >= xmin*2 && bx <= xmax*2 && by >= ymin*2 && by <= ymax*2);
- }
-
- *mx_ptr = bx;
- *my_ptr = by;
-
- return dmin;
-}
-#endif
-
-static int no_sub_motion_search(MpegEncContext * s,
- int *mx_ptr, int *my_ptr, int dmin,
- int src_index, int ref_index,
- int size, int h)
-{
- (*mx_ptr)<<=1;
- (*my_ptr)<<=1;
- return dmin;
-}
-
-inline int ff_get_mb_score(MpegEncContext * s, int mx, int my, int src_index,
- int ref_index, int size, int h, int add_rate)
-{
-// const int check_luma= s->dsp.me_sub_cmp != s->dsp.mb_cmp;
- MotionEstContext * const c= &s->me;
- const int penalty_factor= c->mb_penalty_factor;
- const int flags= c->mb_flags;
- const int qpel= flags & FLAG_QPEL;
- const int mask= 1+2*qpel;
- me_cmp_func cmp_sub, chroma_cmp_sub;
- int d;
-
- LOAD_COMMON
-
- //FIXME factorize
-
- cmp_sub= s->dsp.mb_cmp[size];
- chroma_cmp_sub= s->dsp.mb_cmp[size+1];
-
-// assert(!c->skip);
-// assert(c->avctx->me_sub_cmp != c->avctx->mb_cmp);
-
- d= cmp(s, mx>>(qpel+1), my>>(qpel+1), mx&mask, my&mask, size, h, ref_index, src_index, cmp_sub, chroma_cmp_sub, flags);
- //FIXME check cbp before adding penalty for (0,0) vector
- if(add_rate && (mx || my || size>0))
- d += (mv_penalty[mx - pred_x] + mv_penalty[my - pred_y])*penalty_factor;
-
- return d;
-}
-
-#define CHECK_QUARTER_MV(dx, dy, x, y)\
-{\
- const int hx= 4*(x)+(dx);\
- const int hy= 4*(y)+(dy);\
- d= cmp(s, x, y, dx, dy, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
- d += (mv_penalty[hx - pred_x] + mv_penalty[hy - pred_y])*penalty_factor;\
- COPY3_IF_LT(dmin, d, bx, hx, by, hy)\
-}
-
-static int qpel_motion_search(MpegEncContext * s,
- int *mx_ptr, int *my_ptr, int dmin,
- int src_index, int ref_index,
- int size, int h)
-{
- MotionEstContext * const c= &s->me;
- const int mx = *mx_ptr;
- const int my = *my_ptr;
- const int penalty_factor= c->sub_penalty_factor;
- const int map_generation= c->map_generation;
- const int subpel_quality= c->avctx->me_subpel_quality;
- uint32_t *map= c->map;
- me_cmp_func cmpf, chroma_cmpf;
- me_cmp_func cmp_sub, chroma_cmp_sub;
-
- LOAD_COMMON
- int flags= c->sub_flags;
-
- cmpf= s->dsp.me_cmp[size];
- chroma_cmpf= s->dsp.me_cmp[size+1]; //factorize FIXME
- //FIXME factorize
-
- cmp_sub= s->dsp.me_sub_cmp[size];
- chroma_cmp_sub= s->dsp.me_sub_cmp[size+1];
-
- if(c->skip){ //FIXME somehow move up (benchmark)
- *mx_ptr = 0;
- *my_ptr = 0;
- return dmin;
- }
-
- if(c->avctx->me_cmp != c->avctx->me_sub_cmp){
- dmin= cmp(s, mx, my, 0, 0, size, h, ref_index, src_index, cmp_sub, chroma_cmp_sub, flags);
- if(mx || my || size>0)
- dmin += (mv_penalty[4*mx - pred_x] + mv_penalty[4*my - pred_y])*penalty_factor;
- }
-
- if (mx > xmin && mx < xmax &&
- my > ymin && my < ymax) {
- int bx=4*mx, by=4*my;
- int d= dmin;
- int i, nx, ny;
- const int index= (my<<ME_MAP_SHIFT) + mx;
- const int t= score_map[(index-(1<<ME_MAP_SHIFT) )&(ME_MAP_SIZE-1)];
- const int l= score_map[(index- 1 )&(ME_MAP_SIZE-1)];
- const int r= score_map[(index+ 1 )&(ME_MAP_SIZE-1)];
- const int b= score_map[(index+(1<<ME_MAP_SHIFT) )&(ME_MAP_SIZE-1)];
- const int c= score_map[(index )&(ME_MAP_SIZE-1)];
- int best[8];
- int best_pos[8][2];
-
- memset(best, 64, sizeof(int)*8);
-#if 1
- if(s->me.dia_size>=2){
- const int tl= score_map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
- const int bl= score_map[(index+(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
- const int tr= score_map[(index-(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];
- const int br= score_map[(index+(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];
-
- for(ny= -3; ny <= 3; ny++){
- for(nx= -3; nx <= 3; nx++){
- //FIXME this could overflow (unlikely though)
- const int64_t t2= nx*nx*(tr + tl - 2*t) + 4*nx*(tr-tl) + 32*t;
- const int64_t c2= nx*nx*( r + l - 2*c) + 4*nx*( r- l) + 32*c;
- const int64_t b2= nx*nx*(br + bl - 2*b) + 4*nx*(br-bl) + 32*b;
- int score= (ny*ny*(b2 + t2 - 2*c2) + 4*ny*(b2 - t2) + 32*c2 + 512)>>10;
- int i;
-
- if((nx&3)==0 && (ny&3)==0) continue;
-
- score += (mv_penalty[4*mx + nx - pred_x] + mv_penalty[4*my + ny - pred_y])*penalty_factor;
-
-// if(nx&1) score-=1024*c->penalty_factor;
-// if(ny&1) score-=1024*c->penalty_factor;
-
- for(i=0; i<8; i++){
- if(score < best[i]){
- memmove(&best[i+1], &best[i], sizeof(int)*(7-i));
- memmove(&best_pos[i+1][0], &best_pos[i][0], sizeof(int)*2*(7-i));
- best[i]= score;
- best_pos[i][0]= nx + 4*mx;
- best_pos[i][1]= ny + 4*my;
- break;
- }
- }
- }
- }
- }else{
- int tl;
- //FIXME this could overflow (unlikely though)
- const int cx = 4*(r - l);
- const int cx2= r + l - 2*c;
- const int cy = 4*(b - t);
- const int cy2= b + t - 2*c;
- int cxy;
-
- if(map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)] == (my<<ME_MAP_MV_BITS) + mx + map_generation && 0){ //FIXME
- tl= score_map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
- }else{
- tl= cmp(s, mx-1, my-1, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);//FIXME wrong if chroma me is different
- }
-
- cxy= 2*tl + (cx + cy)/4 - (cx2 + cy2) - 2*c;
-
- assert(16*cx2 + 4*cx + 32*c == 32*r);
- assert(16*cx2 - 4*cx + 32*c == 32*l);
- assert(16*cy2 + 4*cy + 32*c == 32*b);
- assert(16*cy2 - 4*cy + 32*c == 32*t);
- assert(16*cxy + 16*cy2 + 16*cx2 - 4*cy - 4*cx + 32*c == 32*tl);
-
- for(ny= -3; ny <= 3; ny++){
- for(nx= -3; nx <= 3; nx++){
- //FIXME this could overflow (unlikely though)
- int score= ny*nx*cxy + nx*nx*cx2 + ny*ny*cy2 + nx*cx + ny*cy + 32*c; //FIXME factor
- int i;
-
- if((nx&3)==0 && (ny&3)==0) continue;
-
- score += 32*(mv_penalty[4*mx + nx - pred_x] + mv_penalty[4*my + ny - pred_y])*penalty_factor;
-// if(nx&1) score-=32*c->penalty_factor;
- // if(ny&1) score-=32*c->penalty_factor;
-
- for(i=0; i<8; i++){
- if(score < best[i]){
- memmove(&best[i+1], &best[i], sizeof(int)*(7-i));
- memmove(&best_pos[i+1][0], &best_pos[i][0], sizeof(int)*2*(7-i));
- best[i]= score;
- best_pos[i][0]= nx + 4*mx;
- best_pos[i][1]= ny + 4*my;
- break;
- }
- }
- }
- }
- }
- for(i=0; i<subpel_quality; i++){
- nx= best_pos[i][0];
- ny= best_pos[i][1];
- CHECK_QUARTER_MV(nx&3, ny&3, nx>>2, ny>>2)
- }
-
-#if 0
- const int tl= score_map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
- const int bl= score_map[(index+(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
- const int tr= score_map[(index-(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];
- const int br= score_map[(index+(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];
-// if(l < r && l < t && l < b && l < tl && l < bl && l < tr && l < br && bl < tl){
- if(tl<br){
-
-// nx= FFMAX(4*mx - bx, bx - 4*mx);
-// ny= FFMAX(4*my - by, by - 4*my);
-
- static int stats[7][7], count;
- count++;
- stats[4*mx - bx + 3][4*my - by + 3]++;
- if(256*256*256*64 % count ==0){
- for(i=0; i<49; i++){
- if((i%7)==0) printf("\n");
- printf("%6d ", stats[0][i]);
- }
- printf("\n");
- }
- }
-#endif
-#else
-
- CHECK_QUARTER_MV(2, 2, mx-1, my-1)
- CHECK_QUARTER_MV(0, 2, mx , my-1)
- CHECK_QUARTER_MV(2, 2, mx , my-1)
- CHECK_QUARTER_MV(2, 0, mx , my )
- CHECK_QUARTER_MV(2, 2, mx , my )
- CHECK_QUARTER_MV(0, 2, mx , my )
- CHECK_QUARTER_MV(2, 2, mx-1, my )
- CHECK_QUARTER_MV(2, 0, mx-1, my )
-
- nx= bx;
- ny= by;
-
- for(i=0; i<8; i++){
- int ox[8]= {0, 1, 1, 1, 0,-1,-1,-1};
- int oy[8]= {1, 1, 0,-1,-1,-1, 0, 1};
- CHECK_QUARTER_MV((nx + ox[i])&3, (ny + oy[i])&3, (nx + ox[i])>>2, (ny + oy[i])>>2)
- }
-#endif
-#if 0
- //outer ring
- CHECK_QUARTER_MV(1, 3, mx-1, my-1)
- CHECK_QUARTER_MV(1, 2, mx-1, my-1)
- CHECK_QUARTER_MV(1, 1, mx-1, my-1)
- CHECK_QUARTER_MV(2, 1, mx-1, my-1)
- CHECK_QUARTER_MV(3, 1, mx-1, my-1)
- CHECK_QUARTER_MV(0, 1, mx , my-1)
- CHECK_QUARTER_MV(1, 1, mx , my-1)
- CHECK_QUARTER_MV(2, 1, mx , my-1)
- CHECK_QUARTER_MV(3, 1, mx , my-1)
- CHECK_QUARTER_MV(3, 2, mx , my-1)
- CHECK_QUARTER_MV(3, 3, mx , my-1)
- CHECK_QUARTER_MV(3, 0, mx , my )
- CHECK_QUARTER_MV(3, 1, mx , my )
- CHECK_QUARTER_MV(3, 2, mx , my )
- CHECK_QUARTER_MV(3, 3, mx , my )
- CHECK_QUARTER_MV(2, 3, mx , my )
- CHECK_QUARTER_MV(1, 3, mx , my )
- CHECK_QUARTER_MV(0, 3, mx , my )
- CHECK_QUARTER_MV(3, 3, mx-1, my )
- CHECK_QUARTER_MV(2, 3, mx-1, my )
- CHECK_QUARTER_MV(1, 3, mx-1, my )
- CHECK_QUARTER_MV(1, 2, mx-1, my )
- CHECK_QUARTER_MV(1, 1, mx-1, my )
- CHECK_QUARTER_MV(1, 0, mx-1, my )
-#endif
- assert(bx >= xmin*4 && bx <= xmax*4 && by >= ymin*4 && by <= ymax*4);
-
- *mx_ptr = bx;
- *my_ptr = by;
- }else{
- *mx_ptr =4*mx;
- *my_ptr =4*my;
- }
-
- return dmin;
-}
-
-
-#define CHECK_MV(x,y)\
-{\
- const int key= ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
- const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\
- assert((x) >= xmin);\
- assert((x) <= xmax);\
- assert((y) >= ymin);\
- assert((y) <= ymax);\
-/*printf("check_mv %d %d\n", x, y);*/\
- if(map[index]!=key){\
- d= cmp(s, x, y, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
- map[index]= key;\
- score_map[index]= d;\
- d += (mv_penalty[((x)<<shift)-pred_x] + mv_penalty[((y)<<shift)-pred_y])*penalty_factor;\
-/*printf("score:%d\n", d);*/\
- COPY3_IF_LT(dmin, d, best[0], x, best[1], y)\
- }\
-}
-
-#define CHECK_CLIPPED_MV(ax,ay)\
-{\
- const int Lx= ax;\
- const int Ly= ay;\
- const int Lx2= FFMAX(xmin, FFMIN(Lx, xmax));\
- const int Ly2= FFMAX(ymin, FFMIN(Ly, ymax));\
- CHECK_MV(Lx2, Ly2)\
-}
-
-#define CHECK_MV_DIR(x,y,new_dir)\
-{\
- const int key= ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
- const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\
-/*printf("check_mv_dir %d %d %d\n", x, y, new_dir);*/\
- if(map[index]!=key){\
- d= cmp(s, x, y, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
- map[index]= key;\
- score_map[index]= d;\
- d += (mv_penalty[((x)<<shift)-pred_x] + mv_penalty[((y)<<shift)-pred_y])*penalty_factor;\
-/*printf("score:%d\n", d);*/\
- if(d<dmin){\
- best[0]=x;\
- best[1]=y;\
- dmin=d;\
- next_dir= new_dir;\
- }\
- }\
-}
-
-#define check(x,y,S,v)\
-if( (x)<(xmin<<(S)) ) printf("%d %d %d %d %d xmin" #v, xmin, (x), (y), s->mb_x, s->mb_y);\
-if( (x)>(xmax<<(S)) ) printf("%d %d %d %d %d xmax" #v, xmax, (x), (y), s->mb_x, s->mb_y);\
-if( (y)<(ymin<<(S)) ) printf("%d %d %d %d %d ymin" #v, ymin, (x), (y), s->mb_x, s->mb_y);\
-if( (y)>(ymax<<(S)) ) printf("%d %d %d %d %d ymax" #v, ymax, (x), (y), s->mb_x, s->mb_y);\
-
-#define LOAD_COMMON2\
- uint32_t *map= c->map;\
- const int qpel= flags&FLAG_QPEL;\
- const int shift= 1+qpel;\
-
-static av_always_inline int small_diamond_search(MpegEncContext * s, int *best, int dmin,
- int src_index, int ref_index, int const penalty_factor,
- int size, int h, int flags)
-{
- MotionEstContext * const c= &s->me;
- me_cmp_func cmpf, chroma_cmpf;
- int next_dir=-1;
- LOAD_COMMON
- LOAD_COMMON2
- int map_generation= c->map_generation;
-
- cmpf= s->dsp.me_cmp[size];
- chroma_cmpf= s->dsp.me_cmp[size+1];
-
- { /* ensure that the best point is in the MAP as h/qpel refinement needs it */
- const int key= (best[1]<<ME_MAP_MV_BITS) + best[0] + map_generation;
- const int index= ((best[1]<<ME_MAP_SHIFT) + best[0])&(ME_MAP_SIZE-1);
- if(map[index]!=key){ //this will be executed only very rarey
- score_map[index]= cmp(s, best[0], best[1], 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);
- map[index]= key;
- }
- }
-
- for(;;){
- int d;
- const int dir= next_dir;
- const int x= best[0];
- const int y= best[1];
- next_dir=-1;
-
-//printf("%d", dir);
- if(dir!=2 && x>xmin) CHECK_MV_DIR(x-1, y , 0)
- if(dir!=3 && y>ymin) CHECK_MV_DIR(x , y-1, 1)
- if(dir!=0 && x<xmax) CHECK_MV_DIR(x+1, y , 2)
- if(dir!=1 && y<ymax) CHECK_MV_DIR(x , y+1, 3)
-
- if(next_dir==-1){
- return dmin;
- }
- }
-}
-
-static int funny_diamond_search(MpegEncContext * s, int *best, int dmin,
- int src_index, int ref_index, int const penalty_factor,
- int size, int h, int flags)
-{
- MotionEstContext * const c= &s->me;
- me_cmp_func cmpf, chroma_cmpf;
- int dia_size;
- LOAD_COMMON
- LOAD_COMMON2
- int map_generation= c->map_generation;
-
- cmpf= s->dsp.me_cmp[size];
- chroma_cmpf= s->dsp.me_cmp[size+1];
-
- for(dia_size=1; dia_size<=4; dia_size++){
- int dir;
- const int x= best[0];
- const int y= best[1];
-
- if(dia_size&(dia_size-1)) continue;
-
- if( x + dia_size > xmax
- || x - dia_size < xmin
- || y + dia_size > ymax
- || y - dia_size < ymin)
- continue;
-
- for(dir= 0; dir<dia_size; dir+=2){
- int d;
-
- CHECK_MV(x + dir , y + dia_size - dir);
- CHECK_MV(x + dia_size - dir, y - dir );
- CHECK_MV(x - dir , y - dia_size + dir);
- CHECK_MV(x - dia_size + dir, y + dir );
- }
-
- if(x!=best[0] || y!=best[1])
- dia_size=0;
-#if 0
-{
-int dx, dy, i;
-static int stats[8*8];
-dx= FFABS(x-best[0]);
-dy= FFABS(y-best[1]);
-if(dy>dx){
- dx^=dy; dy^=dx; dx^=dy;
-}
-stats[dy*8 + dx] ++;
-if(256*256*256*64 % (stats[0]+1)==0){
- for(i=0; i<64; i++){
- if((i&7)==0) printf("\n");
- printf("%8d ", stats[i]);
- }
- printf("\n");
-}
-}
-#endif
- }
- return dmin;
-}
-
-static int hex_search(MpegEncContext * s, int *best, int dmin,
- int src_index, int ref_index, int const penalty_factor,
- int size, int h, int flags, int dia_size)
-{
- MotionEstContext * const c= &s->me;
- me_cmp_func cmpf, chroma_cmpf;
- LOAD_COMMON
- LOAD_COMMON2
- int map_generation= c->map_generation;
- int x,y,d;
- const int dec= dia_size & (dia_size-1);
-
- cmpf= s->dsp.me_cmp[size];
- chroma_cmpf= s->dsp.me_cmp[size+1];
-
- for(;dia_size; dia_size= dec ? dia_size-1 : dia_size>>1){
- do{
- x= best[0];
- y= best[1];
-
- CHECK_CLIPPED_MV(x -dia_size , y);
- CHECK_CLIPPED_MV(x+ dia_size , y);
- CHECK_CLIPPED_MV(x+( dia_size>>1), y+dia_size);
- CHECK_CLIPPED_MV(x+( dia_size>>1), y-dia_size);
- if(dia_size>1){
- CHECK_CLIPPED_MV(x+(-dia_size>>1), y+dia_size);
- CHECK_CLIPPED_MV(x+(-dia_size>>1), y-dia_size);
- }
- }while(best[0] != x || best[1] != y);
- }
-
- return dmin;
-}
-
-static int l2s_dia_search(MpegEncContext * s, int *best, int dmin,
- int src_index, int ref_index, int const penalty_factor,
- int size, int h, int flags)
-{
- MotionEstContext * const c= &s->me;
- me_cmp_func cmpf, chroma_cmpf;
- LOAD_COMMON
- LOAD_COMMON2
- int map_generation= c->map_generation;
- int x,y,i,d;
- int dia_size= c->dia_size&0xFF;
- const int dec= dia_size & (dia_size-1);
- static const int hex[8][2]={{-2, 0}, {-1,-1}, { 0,-2}, { 1,-1},
- { 2, 0}, { 1, 1}, { 0, 2}, {-1, 1}};
-
- cmpf= s->dsp.me_cmp[size];
- chroma_cmpf= s->dsp.me_cmp[size+1];
-
- for(; dia_size; dia_size= dec ? dia_size-1 : dia_size>>1){
- do{
- x= best[0];
- y= best[1];
- for(i=0; i<8; i++){
- CHECK_CLIPPED_MV(x+hex[i][0]*dia_size, y+hex[i][1]*dia_size);
- }
- }while(best[0] != x || best[1] != y);
- }
-
- x= best[0];
- y= best[1];
- CHECK_CLIPPED_MV(x+1, y);
- CHECK_CLIPPED_MV(x, y+1);
- CHECK_CLIPPED_MV(x-1, y);
- CHECK_CLIPPED_MV(x, y-1);
-
- return dmin;
-}
-
-static int umh_search(MpegEncContext * s, int *best, int dmin,
- int src_index, int ref_index, int const penalty_factor,
- int size, int h, int flags)
-{
- MotionEstContext * const c= &s->me;
- me_cmp_func cmpf, chroma_cmpf;
- LOAD_COMMON
- LOAD_COMMON2
- int map_generation= c->map_generation;
- int x,y,x2,y2, i, j, d;
- const int dia_size= c->dia_size&0xFE;
- static const int hex[16][2]={{-4,-2}, {-4,-1}, {-4, 0}, {-4, 1}, {-4, 2},
- { 4,-2}, { 4,-1}, { 4, 0}, { 4, 1}, { 4, 2},
- {-2, 3}, { 0, 4}, { 2, 3},
- {-2,-3}, { 0,-4}, { 2,-3},};
-
- cmpf= s->dsp.me_cmp[size];
- chroma_cmpf= s->dsp.me_cmp[size+1];
-
- x= best[0];
- y= best[1];
- for(x2=FFMAX(x-dia_size+1, xmin); x2<=FFMIN(x+dia_size-1,xmax); x2+=2){
- CHECK_MV(x2, y);
- }
- for(y2=FFMAX(y-dia_size/2+1, ymin); y2<=FFMIN(y+dia_size/2-1,ymax); y2+=2){
- CHECK_MV(x, y2);
- }
-
- x= best[0];
- y= best[1];
- for(y2=FFMAX(y-2, ymin); y2<=FFMIN(y+2,ymax); y2++){
- for(x2=FFMAX(x-2, xmin); x2<=FFMIN(x+2,xmax); x2++){
- CHECK_MV(x2, y2);
- }
- }
-
-//FIXME prevent the CLIP stuff
-
- for(j=1; j<=dia_size/4; j++){
- for(i=0; i<16; i++){
- CHECK_CLIPPED_MV(x+hex[i][0]*j, y+hex[i][1]*j);
- }
- }
-
- return hex_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags, 2);
-}
-
-#define SAB_CHECK_MV(ax,ay)\
-{\
- const int key= ((ay)<<ME_MAP_MV_BITS) + (ax) + map_generation;\
- const int index= (((ay)<<ME_MAP_SHIFT) + (ax))&(ME_MAP_SIZE-1);\
-/*printf("sab check %d %d\n", ax, ay);*/\
- if(map[index]!=key){\
- d= cmp(s, ax, ay, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
- map[index]= key;\
- score_map[index]= d;\
- d += (mv_penalty[((ax)<<shift)-pred_x] + mv_penalty[((ay)<<shift)-pred_y])*penalty_factor;\
-/*printf("score: %d\n", d);*/\
- if(d < minima[minima_count-1].height){\
- int j=0;\
- \
- while(d >= minima[j].height) j++;\
-\
- memmove(&minima [j+1], &minima [j], (minima_count - j - 1)*sizeof(Minima));\
-\
- minima[j].checked= 0;\
- minima[j].height= d;\
- minima[j].x= ax;\
- minima[j].y= ay;\
- \
- i=-1;\
- continue;\
- }\
- }\
-}
-
-#define MAX_SAB_SIZE ME_MAP_SIZE
-static int sab_diamond_search(MpegEncContext * s, int *best, int dmin,
- int src_index, int ref_index, int const penalty_factor,
- int size, int h, int flags)
-{
- MotionEstContext * const c= &s->me;
- me_cmp_func cmpf, chroma_cmpf;
- Minima minima[MAX_SAB_SIZE];
- const int minima_count= FFABS(c->dia_size);
- int i, j;
- LOAD_COMMON
- LOAD_COMMON2
- int map_generation= c->map_generation;
-
- cmpf= s->dsp.me_cmp[size];
- chroma_cmpf= s->dsp.me_cmp[size+1];
-
- /*Note j<MAX_SAB_SIZE is needed if MAX_SAB_SIZE < ME_MAP_SIZE as j can
- become larger due to MVs overflowing their ME_MAP_MV_BITS bits space in map
- */
- for(j=i=0; i<ME_MAP_SIZE && j<MAX_SAB_SIZE; i++){
- uint32_t key= map[i];
-
- key += (1<<(ME_MAP_MV_BITS-1)) + (1<<(2*ME_MAP_MV_BITS-1));
-
- if((key&((-1)<<(2*ME_MAP_MV_BITS))) != map_generation) continue;
-
- minima[j].height= score_map[i];
- minima[j].x= key & ((1<<ME_MAP_MV_BITS)-1); key>>=ME_MAP_MV_BITS;
- minima[j].y= key & ((1<<ME_MAP_MV_BITS)-1);
- minima[j].x-= (1<<(ME_MAP_MV_BITS-1));
- minima[j].y-= (1<<(ME_MAP_MV_BITS-1));
-
- // all entries in map should be in range except if the mv overflows their ME_MAP_MV_BITS bits space
- if( minima[j].x > xmax || minima[j].x < xmin
- || minima[j].y > ymax || minima[j].y < ymin)
- continue;
-
- minima[j].checked=0;
- if(minima[j].x || minima[j].y)
- minima[j].height+= (mv_penalty[((minima[j].x)<<shift)-pred_x] + mv_penalty[((minima[j].y)<<shift)-pred_y])*penalty_factor;
-
- j++;
- }
-
- qsort(minima, j, sizeof(Minima), minima_cmp);
-
- for(; j<minima_count; j++){
- minima[j].height=256*256*256*64;
- minima[j].checked=0;
- minima[j].x= minima[j].y=0;
- }
-
- for(i=0; i<minima_count; i++){
- const int x= minima[i].x;
- const int y= minima[i].y;
- int d;
-
- if(minima[i].checked) continue;
-
- if( x >= xmax || x <= xmin
- || y >= ymax || y <= ymin)
- continue;
-
- SAB_CHECK_MV(x-1, y)
- SAB_CHECK_MV(x+1, y)
- SAB_CHECK_MV(x , y-1)
- SAB_CHECK_MV(x , y+1)
-
- minima[i].checked= 1;
- }
-
- best[0]= minima[0].x;
- best[1]= minima[0].y;
- dmin= minima[0].height;
-
- if( best[0] < xmax && best[0] > xmin
- && best[1] < ymax && best[1] > ymin){
- int d;
- //ensure that the refernece samples for hpel refinement are in the map
- CHECK_MV(best[0]-1, best[1])
- CHECK_MV(best[0]+1, best[1])
- CHECK_MV(best[0], best[1]-1)
- CHECK_MV(best[0], best[1]+1)
- }
- return dmin;
-}
-
-static int var_diamond_search(MpegEncContext * s, int *best, int dmin,
- int src_index, int ref_index, int const penalty_factor,
- int size, int h, int flags)
-{
- MotionEstContext * const c= &s->me;
- me_cmp_func cmpf, chroma_cmpf;
- int dia_size;
- LOAD_COMMON
- LOAD_COMMON2
- int map_generation= c->map_generation;
-
- cmpf= s->dsp.me_cmp[size];
- chroma_cmpf= s->dsp.me_cmp[size+1];
-
- for(dia_size=1; dia_size<=c->dia_size; dia_size++){
- int dir, start, end;
- const int x= best[0];
- const int y= best[1];
-
- start= FFMAX(0, y + dia_size - ymax);
- end = FFMIN(dia_size, xmax - x + 1);
- for(dir= start; dir<end; dir++){
- int d;
-
-//check(x + dir,y + dia_size - dir,0, a0)
- CHECK_MV(x + dir , y + dia_size - dir);
- }
-
- start= FFMAX(0, x + dia_size - xmax);
- end = FFMIN(dia_size, y - ymin + 1);
- for(dir= start; dir<end; dir++){
- int d;
-
-//check(x + dia_size - dir, y - dir,0, a1)
- CHECK_MV(x + dia_size - dir, y - dir );
- }
-
- start= FFMAX(0, -y + dia_size + ymin );
- end = FFMIN(dia_size, x - xmin + 1);
- for(dir= start; dir<end; dir++){
- int d;
-
-//check(x - dir,y - dia_size + dir,0, a2)
- CHECK_MV(x - dir , y - dia_size + dir);
- }
-
- start= FFMAX(0, -x + dia_size + xmin );
- end = FFMIN(dia_size, ymax - y + 1);
- for(dir= start; dir<end; dir++){
- int d;
-
-//check(x - dia_size + dir, y + dir,0, a3)
- CHECK_MV(x - dia_size + dir, y + dir );
- }
-
- if(x!=best[0] || y!=best[1])
- dia_size=0;
-#if 0
-{
-int dx, dy, i;
-static int stats[8*8];
-dx= FFABS(x-best[0]);
-dy= FFABS(y-best[1]);
-stats[dy*8 + dx] ++;
-if(256*256*256*64 % (stats[0]+1)==0){
- for(i=0; i<64; i++){
- if((i&7)==0) printf("\n");
- printf("%6d ", stats[i]);
- }
- printf("\n");
-}
-}
-#endif
- }
- return dmin;
-}
-
-static av_always_inline int diamond_search(MpegEncContext * s, int *best, int dmin,
- int src_index, int ref_index, int const penalty_factor,
- int size, int h, int flags){
- MotionEstContext * const c= &s->me;
- if(c->dia_size==-1)
- return funny_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
- else if(c->dia_size<-1)
- return sab_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
- else if(c->dia_size<2)
- return small_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
- else if(c->dia_size>768)
- return umh_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
- else if(c->dia_size>512)
- return hex_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags, c->dia_size&0xFF);
- else if(c->dia_size>256)
- return l2s_dia_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
- else
- return var_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
-}
-
-static av_always_inline int epzs_motion_search_internal(MpegEncContext * s, int *mx_ptr, int *my_ptr,
- int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2],
- int ref_mv_scale, int flags, int size, int h)
-{
- MotionEstContext * const c= &s->me;
- int best[2]={0, 0};
- int d, dmin;
- int map_generation;
- int penalty_factor;
- const int ref_mv_stride= s->mb_stride; //pass as arg FIXME
- const int ref_mv_xy= s->mb_x + s->mb_y*ref_mv_stride; //add to last_mv beforepassing FIXME
- me_cmp_func cmpf, chroma_cmpf;
-
- LOAD_COMMON
- LOAD_COMMON2
-
- if(c->pre_pass){
- penalty_factor= c->pre_penalty_factor;
- cmpf= s->dsp.me_pre_cmp[size];
- chroma_cmpf= s->dsp.me_pre_cmp[size+1];
- }else{
- penalty_factor= c->penalty_factor;
- cmpf= s->dsp.me_cmp[size];
- chroma_cmpf= s->dsp.me_cmp[size+1];
- }
-
- map_generation= update_map_generation(c);
-
- assert(cmpf);
- dmin= cmp(s, 0, 0, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);
- map[0]= map_generation;
- score_map[0]= dmin;
-
- //FIXME precalc first term below?
- if((s->pict_type == B_TYPE && !(c->flags & FLAG_DIRECT)) || s->flags&CODEC_FLAG_MV0)
- dmin += (mv_penalty[pred_x] + mv_penalty[pred_y])*penalty_factor;
-
- /* first line */
- if (s->first_slice_line) {
- CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
- CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
- (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
- }else{
- if(dmin<((h*h*s->avctx->mv0_threshold)>>8)
- && ( P_LEFT[0] |P_LEFT[1]
- |P_TOP[0] |P_TOP[1]
- |P_TOPRIGHT[0]|P_TOPRIGHT[1])==0){
- *mx_ptr= 0;
- *my_ptr= 0;
- c->skip=1;
- return dmin;
- }
- CHECK_MV( P_MEDIAN[0] >>shift , P_MEDIAN[1] >>shift)
- CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift) , (P_MEDIAN[1]>>shift)-1)
- CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift) , (P_MEDIAN[1]>>shift)+1)
- CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift)-1, (P_MEDIAN[1]>>shift) )
- CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift)+1, (P_MEDIAN[1]>>shift) )
- CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
- (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
- CHECK_MV(P_LEFT[0] >>shift, P_LEFT[1] >>shift)
- CHECK_MV(P_TOP[0] >>shift, P_TOP[1] >>shift)
- CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift)
- }
- if(dmin>h*h*4){
- if(c->pre_pass){
- CHECK_CLIPPED_MV((last_mv[ref_mv_xy-1][0]*ref_mv_scale + (1<<15))>>16,
- (last_mv[ref_mv_xy-1][1]*ref_mv_scale + (1<<15))>>16)
- if(!s->first_slice_line)
- CHECK_CLIPPED_MV((last_mv[ref_mv_xy-ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
- (last_mv[ref_mv_xy-ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
- }else{
- CHECK_CLIPPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16,
- (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16)
- if(s->mb_y+1<s->end_mb_y) //FIXME replace at least with last_slice_line
- CHECK_CLIPPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
- (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
- }
- }
-
- if(c->avctx->last_predictor_count){
- const int count= c->avctx->last_predictor_count;
- const int xstart= FFMAX(0, s->mb_x - count);
- const int ystart= FFMAX(0, s->mb_y - count);
- const int xend= FFMIN(s->mb_width , s->mb_x + count + 1);
- const int yend= FFMIN(s->mb_height, s->mb_y + count + 1);
- int mb_y;
-
- for(mb_y=ystart; mb_y<yend; mb_y++){
- int mb_x;
- for(mb_x=xstart; mb_x<xend; mb_x++){
- const int xy= mb_x + 1 + (mb_y + 1)*ref_mv_stride;
- int mx= (last_mv[xy][0]*ref_mv_scale + (1<<15))>>16;
- int my= (last_mv[xy][1]*ref_mv_scale + (1<<15))>>16;
-
- if(mx>xmax || mx<xmin || my>ymax || my<ymin) continue;
- CHECK_MV(mx,my)
- }
- }
- }
-
-//check(best[0],best[1],0, b0)
- dmin= diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
-
-//check(best[0],best[1],0, b1)
- *mx_ptr= best[0];
- *my_ptr= best[1];
-
-// printf("%d %d %d \n", best[0], best[1], dmin);
- return dmin;
-}
-
-//this function is dedicated to the braindamaged gcc
-inline int ff_epzs_motion_search(MpegEncContext * s, int *mx_ptr, int *my_ptr,
- int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2],
- int ref_mv_scale, int size, int h)
-{
- MotionEstContext * const c= &s->me;
-//FIXME convert other functions in the same way if faster
- if(c->flags==0 && h==16 && size==0){
- return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, 0, 0, 16);
-// case FLAG_QPEL:
-// return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, FLAG_QPEL);
- }else{
- return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, c->flags, size, h);
- }
-}
-
-static int epzs_motion_search4(MpegEncContext * s,
- int *mx_ptr, int *my_ptr, int P[10][2],
- int src_index, int ref_index, int16_t (*last_mv)[2],
- int ref_mv_scale)
-{
- MotionEstContext * const c= &s->me;
- int best[2]={0, 0};
- int d, dmin;
- int map_generation;
- const int penalty_factor= c->penalty_factor;
- const int size=1;
- const int h=8;
- const int ref_mv_stride= s->mb_stride;
- const int ref_mv_xy= s->mb_x + s->mb_y *ref_mv_stride;
- me_cmp_func cmpf, chroma_cmpf;
- LOAD_COMMON
- int flags= c->flags;
- LOAD_COMMON2
-
- cmpf= s->dsp.me_cmp[size];
- chroma_cmpf= s->dsp.me_cmp[size+1];
-
- map_generation= update_map_generation(c);
-
- dmin = 1000000;
-//printf("%d %d %d %d //",xmin, ymin, xmax, ymax);
- /* first line */
- if (s->first_slice_line) {
- CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
- CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
- (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
- CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
- }else{
- CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
- //FIXME try some early stop
- CHECK_MV(P_MEDIAN[0]>>shift, P_MEDIAN[1]>>shift)
- CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
- CHECK_MV(P_TOP[0]>>shift, P_TOP[1]>>shift)
- CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift)
- CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
- (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
- }
- if(dmin>64*4){
- CHECK_CLIPPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16,
- (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16)
- if(s->mb_y+1<s->end_mb_y) //FIXME replace at least with last_slice_line
- CHECK_CLIPPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
- (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
- }
-
- dmin= diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
-
- *mx_ptr= best[0];
- *my_ptr= best[1];
-
-// printf("%d %d %d \n", best[0], best[1], dmin);
- return dmin;
-}
-
-//try to merge with above FIXME (needs PSNR test)
-static int epzs_motion_search2(MpegEncContext * s,
- int *mx_ptr, int *my_ptr, int P[10][2],
- int src_index, int ref_index, int16_t (*last_mv)[2],
- int ref_mv_scale)
-{
- MotionEstContext * const c= &s->me;
- int best[2]={0, 0};
- int d, dmin;
- int map_generation;
- const int penalty_factor= c->penalty_factor;
- const int size=0; //FIXME pass as arg
- const int h=8;
- const int ref_mv_stride= s->mb_stride;
- const int ref_mv_xy= s->mb_x + s->mb_y *ref_mv_stride;
- me_cmp_func cmpf, chroma_cmpf;
- LOAD_COMMON
- int flags= c->flags;
- LOAD_COMMON2
-
- cmpf= s->dsp.me_cmp[size];
- chroma_cmpf= s->dsp.me_cmp[size+1];
-
- map_generation= update_map_generation(c);
-
- dmin = 1000000;
-//printf("%d %d %d %d //",xmin, ymin, xmax, ymax);
- /* first line */
- if (s->first_slice_line) {
- CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
- CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
- (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
- CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
- }else{
- CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
- //FIXME try some early stop
- CHECK_MV(P_MEDIAN[0]>>shift, P_MEDIAN[1]>>shift)
- CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
- CHECK_MV(P_TOP[0]>>shift, P_TOP[1]>>shift)
- CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift)
- CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
- (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
- }
- if(dmin>64*4){
- CHECK_CLIPPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16,
- (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16)
- if(s->mb_y+1<s->end_mb_y) //FIXME replace at least with last_slice_line
- CHECK_CLIPPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
- (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
- }
-
- dmin= diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
-
- *mx_ptr= best[0];
- *my_ptr= best[1];
-
-// printf("%d %d %d \n", best[0], best[1], dmin);
- return dmin;
-}
diff --git a/src/libffmpeg/libavcodec/mpeg12.c b/src/libffmpeg/libavcodec/mpeg12.c
deleted file mode 100644
index 63fb00feb..000000000
--- a/src/libffmpeg/libavcodec/mpeg12.c
+++ /dev/null
@@ -1,3504 +0,0 @@
-/*
- * MPEG1 codec / MPEG2 decoder
- * Copyright (c) 2000,2001 Fabrice Bellard.
- * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/**
- * @file mpeg12.c
- * MPEG1/2 codec
- */
-
-//#define DEBUG
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-
-#include "mpeg12data.h"
-
-//#undef NDEBUG
-//#include <assert.h>
-
-
-/* if xine's MPEG encoder is enabled, enable the encoding features in
- * this particular module */
-#if defined(XINE_MPEG_ENCODER) && !defined(CONFIG_ENCODERS)
-#define CONFIG_ENCODERS
-#endif
-
-
-/* Start codes. */
-#define SEQ_END_CODE 0x000001b7
-#define SEQ_START_CODE 0x000001b3
-#define GOP_START_CODE 0x000001b8
-#define PICTURE_START_CODE 0x00000100
-#define SLICE_MIN_START_CODE 0x00000101
-#define SLICE_MAX_START_CODE 0x000001af
-#define EXT_START_CODE 0x000001b5
-#define USER_START_CODE 0x000001b2
-
-#define DC_VLC_BITS 9
-#define MV_VLC_BITS 9
-#define MBINCR_VLC_BITS 9
-#define MB_PAT_VLC_BITS 9
-#define MB_PTYPE_VLC_BITS 6
-#define MB_BTYPE_VLC_BITS 6
-#define TEX_VLC_BITS 9
-
-#ifdef CONFIG_ENCODERS
-static void mpeg1_encode_block(MpegEncContext *s,
- DCTELEM *block,
- int component);
-static void mpeg1_encode_motion(MpegEncContext *s, int val, int f_or_b_code); // RAL: f_code parameter added
-#endif //CONFIG_ENCODERS
-static inline int mpeg1_decode_block_inter(MpegEncContext *s,
- DCTELEM *block,
- int n);
-static inline int mpeg1_decode_block_intra(MpegEncContext *s,
- DCTELEM *block,
- int n);
-static inline int mpeg1_fast_decode_block_inter(MpegEncContext *s, DCTELEM *block, int n);
-static inline int mpeg2_decode_block_non_intra(MpegEncContext *s,
- DCTELEM *block,
- int n);
-static inline int mpeg2_decode_block_intra(MpegEncContext *s,
- DCTELEM *block,
- int n);
-static inline int mpeg2_fast_decode_block_non_intra(MpegEncContext *s, DCTELEM *block, int n);
-static inline int mpeg2_fast_decode_block_intra(MpegEncContext *s, DCTELEM *block, int n);
-static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred);
-static void exchange_uv(MpegEncContext *s);
-
-#ifdef HAVE_XVMC
-extern int XVMC_field_start(MpegEncContext *s, AVCodecContext *avctx);
-extern int XVMC_field_end(MpegEncContext *s);
-extern void XVMC_pack_pblocks(MpegEncContext *s,int cbp);
-extern void XVMC_init_block(MpegEncContext *s);//set s->block
-#endif
-
-static const enum PixelFormat pixfmt_yuv_420[]= {PIX_FMT_YUV420P,-1};
-static const enum PixelFormat pixfmt_yuv_422[]= {PIX_FMT_YUV422P,-1};
-static const enum PixelFormat pixfmt_yuv_444[]= {PIX_FMT_YUV444P,-1};
-static const enum PixelFormat pixfmt_xvmc_mpg2_420[] = {
- PIX_FMT_XVMC_MPEG2_IDCT,
- PIX_FMT_XVMC_MPEG2_MC,
- -1};
-#ifdef CONFIG_ENCODERS
-static uint8_t (*mv_penalty)[MAX_MV*2+1]= NULL;
-static uint8_t fcode_tab[MAX_MV*2+1];
-
-static uint8_t uni_mpeg1_ac_vlc_len [64*64*2];
-static uint8_t uni_mpeg2_ac_vlc_len [64*64*2];
-
-/* simple include everything table for dc, first byte is bits number next 3 are code*/
-static uint32_t mpeg1_lum_dc_uni[512];
-static uint32_t mpeg1_chr_dc_uni[512];
-
-static uint8_t mpeg1_index_run[2][64];
-static int8_t mpeg1_max_level[2][64];
-#endif //CONFIG_ENCODERS
-
-static void init_2d_vlc_rl(RLTable *rl, int use_static)
-{
- int i;
-
- init_vlc(&rl->vlc, TEX_VLC_BITS, rl->n + 2,
- &rl->table_vlc[0][1], 4, 2,
- &rl->table_vlc[0][0], 4, 2, use_static);
-
- if(use_static)
- rl->rl_vlc[0]= av_mallocz_static(rl->vlc.table_size*sizeof(RL_VLC_ELEM));
- else
- rl->rl_vlc[0]= av_malloc(rl->vlc.table_size*sizeof(RL_VLC_ELEM));
-
- for(i=0; i<rl->vlc.table_size; i++){
- int code= rl->vlc.table[i][0];
- int len = rl->vlc.table[i][1];
- int level, run;
-
- if(len==0){ // illegal code
- run= 65;
- level= MAX_LEVEL;
- }else if(len<0){ //more bits needed
- run= 0;
- level= code;
- }else{
- if(code==rl->n){ //esc
- run= 65;
- level= 0;
- }else if(code==rl->n+1){ //eob
- run= 0;
- level= 127;
- }else{
- run= rl->table_run [code] + 1;
- level= rl->table_level[code];
- }
- }
- rl->rl_vlc[0][i].len= len;
- rl->rl_vlc[0][i].level= level;
- rl->rl_vlc[0][i].run= run;
- }
-}
-
-#ifdef CONFIG_ENCODERS
-static void init_uni_ac_vlc(RLTable *rl, uint8_t *uni_ac_vlc_len){
- int i;
-
- for(i=0; i<128; i++){
- int level= i-64;
- int run;
- for(run=0; run<64; run++){
- int len, bits, code;
-
- int alevel= FFABS(level);
- int sign= (level>>31)&1;
-
- if (alevel > rl->max_level[0][run])
- code= 111; /*rl->n*/
- else
- code= rl->index_run[0][run] + alevel - 1;
-
- if (code < 111 /* rl->n */) {
- /* store the vlc & sign at once */
- len= rl->table_vlc[code][1]+1;
- bits= (rl->table_vlc[code][0]<<1) + sign;
- } else {
- len= rl->table_vlc[111/*rl->n*/][1]+6;
- bits= rl->table_vlc[111/*rl->n*/][0]<<6;
-
- bits|= run;
- if (alevel < 128) {
- bits<<=8; len+=8;
- bits|= level & 0xff;
- } else {
- bits<<=16; len+=16;
- bits|= level & 0xff;
- if (level < 0) {
- bits|= 0x8001 + level + 255;
- } else {
- bits|= level & 0xffff;
- }
- }
- }
-
- uni_ac_vlc_len [UNI_AC_ENC_INDEX(run, i)]= len;
- }
- }
-}
-
-
-static int find_frame_rate_index(MpegEncContext *s){
- int i;
- int64_t dmin= INT64_MAX;
- int64_t d;
-
- for(i=1;i<14;i++) {
- int64_t n0= 1001LL/ff_frame_rate_tab[i].den*ff_frame_rate_tab[i].num*s->avctx->time_base.num;
- int64_t n1= 1001LL*s->avctx->time_base.den;
- if(s->avctx->strict_std_compliance > FF_COMPLIANCE_INOFFICIAL && i>=9) break;
-
- d = FFABS(n0 - n1);
- if(d < dmin){
- dmin=d;
- s->frame_rate_index= i;
- }
- }
- if(dmin)
- return -1;
- else
- return 0;
-}
-
-static int encode_init(AVCodecContext *avctx)
-{
- MpegEncContext *s = avctx->priv_data;
-
- if(MPV_encode_init(avctx) < 0)
- return -1;
-
- if(find_frame_rate_index(s) < 0){
- if(s->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){
- av_log(avctx, AV_LOG_ERROR, "MPEG1/2 does not support %d/%d fps\n", avctx->time_base.den, avctx->time_base.num);
- return -1;
- }else{
- av_log(avctx, AV_LOG_INFO, "MPEG1/2 does not support %d/%d fps, there may be AV sync issues\n", avctx->time_base.den, avctx->time_base.num);
- }
- }
-
- if(avctx->profile == FF_PROFILE_UNKNOWN)
- avctx->profile = s->chroma_format == CHROMA_420 ? 4 : 0;
-
- if(avctx->level == FF_LEVEL_UNKNOWN)
- avctx->level = s->chroma_format == CHROMA_420 ? 8 : 5;
-
- if((avctx->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE) && s->frame_rate_index != 4){
- av_log(avctx, AV_LOG_ERROR, "Drop frame time code only allowed with 1001/30000 fps\n");
- return -1;
- }
-
- return 0;
-}
-
-static void put_header(MpegEncContext *s, int header)
-{
- align_put_bits(&s->pb);
- put_bits(&s->pb, 16, header>>16);
- put_bits(&s->pb, 16, header&0xFFFF);
-}
-
-/* put sequence header if needed */
-static void mpeg1_encode_sequence_header(MpegEncContext *s)
-{
- unsigned int vbv_buffer_size;
- unsigned int fps, v;
- int i;
- uint64_t time_code;
- float best_aspect_error= 1E10;
- float aspect_ratio= av_q2d(s->avctx->sample_aspect_ratio);
- int constraint_parameter_flag;
-
- if(aspect_ratio==0.0) aspect_ratio= 1.0; //pixel aspect 1:1 (VGA)
-
- if (s->current_picture.key_frame) {
- AVRational framerate= ff_frame_rate_tab[s->frame_rate_index];
-
- /* mpeg1 header repeated every gop */
- put_header(s, SEQ_START_CODE);
-
- put_bits(&s->pb, 12, s->width);
- put_bits(&s->pb, 12, s->height);
-
- for(i=1; i<15; i++){
- float error= aspect_ratio;
- if(s->codec_id == CODEC_ID_MPEG1VIDEO || i <=1)
- error-= 1.0/mpeg1_aspect[i];
- else
- error-= av_q2d(mpeg2_aspect[i])*s->height/s->width;
-
- error= FFABS(error);
-
- if(error < best_aspect_error){
- best_aspect_error= error;
- s->aspect_ratio_info= i;
- }
- }
-
- put_bits(&s->pb, 4, s->aspect_ratio_info);
- put_bits(&s->pb, 4, s->frame_rate_index);
-
- if(s->avctx->rc_max_rate){
- v = (s->avctx->rc_max_rate + 399) / 400;
- if (v > 0x3ffff && s->codec_id == CODEC_ID_MPEG1VIDEO)
- v = 0x3ffff;
- }else{
- v= 0x3FFFF;
- }
-
- if(s->avctx->rc_buffer_size)
- vbv_buffer_size = s->avctx->rc_buffer_size;
- else
- /* VBV calculation: Scaled so that a VCD has the proper VBV size of 40 kilobytes */
- vbv_buffer_size = (( 20 * s->bit_rate) / (1151929 / 2)) * 8 * 1024;
- vbv_buffer_size= (vbv_buffer_size + 16383) / 16384;
-
- put_bits(&s->pb, 18, v & 0x3FFFF);
- put_bits(&s->pb, 1, 1); /* marker */
- put_bits(&s->pb, 10, vbv_buffer_size & 0x3FF);
-
- constraint_parameter_flag=
- s->width <= 768 && s->height <= 576 &&
- s->mb_width * s->mb_height <= 396 &&
- s->mb_width * s->mb_height * framerate.num <= framerate.den*396*25 &&
- framerate.num <= framerate.den*30 &&
- s->avctx->me_range && s->avctx->me_range < 128 &&
- vbv_buffer_size <= 20 &&
- v <= 1856000/400 &&
- s->codec_id == CODEC_ID_MPEG1VIDEO;
-
- put_bits(&s->pb, 1, constraint_parameter_flag);
-
- ff_write_quant_matrix(&s->pb, s->avctx->intra_matrix);
- ff_write_quant_matrix(&s->pb, s->avctx->inter_matrix);
-
- if(s->codec_id == CODEC_ID_MPEG2VIDEO){
- put_header(s, EXT_START_CODE);
- put_bits(&s->pb, 4, 1); //seq ext
-
- put_bits(&s->pb, 1, s->chroma_format == CHROMA_422); //escx
-
- put_bits(&s->pb, 3, s->avctx->profile); //profile
- put_bits(&s->pb, 4, s->avctx->level); //level
-
- put_bits(&s->pb, 1, s->progressive_sequence);
- put_bits(&s->pb, 2, s->chroma_format);
- put_bits(&s->pb, 2, 0); //horizontal size ext
- put_bits(&s->pb, 2, 0); //vertical size ext
- put_bits(&s->pb, 12, v>>18); //bitrate ext
- put_bits(&s->pb, 1, 1); //marker
- put_bits(&s->pb, 8, vbv_buffer_size >>10); //vbv buffer ext
- put_bits(&s->pb, 1, s->low_delay);
- put_bits(&s->pb, 2, 0); // frame_rate_ext_n
- put_bits(&s->pb, 5, 0); // frame_rate_ext_d
- }
-
- put_header(s, GOP_START_CODE);
- put_bits(&s->pb, 1, !!(s->avctx->flags & CODEC_FLAG2_DROP_FRAME_TIMECODE)); /* drop frame flag */
- /* time code : we must convert from the real frame rate to a
- fake mpeg frame rate in case of low frame rate */
- fps = (framerate.num + framerate.den/2)/ framerate.den;
- time_code = s->current_picture_ptr->coded_picture_number + s->avctx->timecode_frame_start;
-
- s->gop_picture_number = s->current_picture_ptr->coded_picture_number;
- if (s->avctx->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE) {
- /* only works for NTSC 29.97 */
- int d = time_code / 17982;
- int m = time_code % 17982;
- //if (m < 2) m += 2; /* not needed since -2,-1 / 1798 in C returns 0 */
- time_code += 18 * d + 2 * ((m - 2) / 1798);
- }
- put_bits(&s->pb, 5, (uint32_t)((time_code / (fps * 3600)) % 24));
- put_bits(&s->pb, 6, (uint32_t)((time_code / (fps * 60)) % 60));
- put_bits(&s->pb, 1, 1);
- put_bits(&s->pb, 6, (uint32_t)((time_code / fps) % 60));
- put_bits(&s->pb, 6, (uint32_t)((time_code % fps)));
- put_bits(&s->pb, 1, !!(s->flags & CODEC_FLAG_CLOSED_GOP));
- put_bits(&s->pb, 1, 0); /* broken link */
- }
-}
-
-static inline void encode_mb_skip_run(MpegEncContext *s, int run){
- while (run >= 33) {
- put_bits(&s->pb, 11, 0x008);
- run -= 33;
- }
- put_bits(&s->pb, mbAddrIncrTable[run][1],
- mbAddrIncrTable[run][0]);
-}
-#endif //CONFIG_ENCODERS
-
-static void common_init(MpegEncContext *s)
-{
-
- s->y_dc_scale_table=
- s->c_dc_scale_table= mpeg2_dc_scale_table[s->intra_dc_precision];
-
-}
-
-void ff_mpeg1_clean_buffers(MpegEncContext *s){
- s->last_dc[0] = 1 << (7 + s->intra_dc_precision);
- s->last_dc[1] = s->last_dc[0];
- s->last_dc[2] = s->last_dc[0];
- memset(s->last_mv, 0, sizeof(s->last_mv));
-}
-
-#ifdef CONFIG_ENCODERS
-
-void ff_mpeg1_encode_slice_header(MpegEncContext *s){
- put_header(s, SLICE_MIN_START_CODE + s->mb_y);
- put_bits(&s->pb, 5, s->qscale); /* quantizer scale */
- put_bits(&s->pb, 1, 0); /* slice extra information */
-}
-
-void mpeg1_encode_picture_header(MpegEncContext *s, int picture_number)
-{
- mpeg1_encode_sequence_header(s);
-
- /* mpeg1 picture header */
- put_header(s, PICTURE_START_CODE);
- /* temporal reference */
-
- // RAL: s->picture_number instead of s->fake_picture_number
- put_bits(&s->pb, 10, (s->picture_number -
- s->gop_picture_number) & 0x3ff);
- put_bits(&s->pb, 3, s->pict_type);
-
- s->vbv_delay_ptr= s->pb.buf + put_bits_count(&s->pb)/8;
- put_bits(&s->pb, 16, 0xFFFF); /* vbv_delay */
-
- // RAL: Forward f_code also needed for B frames
- if (s->pict_type == P_TYPE || s->pict_type == B_TYPE) {
- put_bits(&s->pb, 1, 0); /* half pel coordinates */
- if(s->codec_id == CODEC_ID_MPEG1VIDEO)
- put_bits(&s->pb, 3, s->f_code); /* forward_f_code */
- else
- put_bits(&s->pb, 3, 7); /* forward_f_code */
- }
-
- // RAL: Backward f_code necessary for B frames
- if (s->pict_type == B_TYPE) {
- put_bits(&s->pb, 1, 0); /* half pel coordinates */
- if(s->codec_id == CODEC_ID_MPEG1VIDEO)
- put_bits(&s->pb, 3, s->b_code); /* backward_f_code */
- else
- put_bits(&s->pb, 3, 7); /* backward_f_code */
- }
-
- put_bits(&s->pb, 1, 0); /* extra bit picture */
-
- s->frame_pred_frame_dct = 1;
- if(s->codec_id == CODEC_ID_MPEG2VIDEO){
- put_header(s, EXT_START_CODE);
- put_bits(&s->pb, 4, 8); //pic ext
- if (s->pict_type == P_TYPE || s->pict_type == B_TYPE) {
- put_bits(&s->pb, 4, s->f_code);
- put_bits(&s->pb, 4, s->f_code);
- }else{
- put_bits(&s->pb, 8, 255);
- }
- if (s->pict_type == B_TYPE) {
- put_bits(&s->pb, 4, s->b_code);
- put_bits(&s->pb, 4, s->b_code);
- }else{
- put_bits(&s->pb, 8, 255);
- }
- put_bits(&s->pb, 2, s->intra_dc_precision);
-
- assert(s->picture_structure == PICT_FRAME);
- put_bits(&s->pb, 2, s->picture_structure);
- if (s->progressive_sequence) {
- put_bits(&s->pb, 1, 0); /* no repeat */
- } else {
- put_bits(&s->pb, 1, s->current_picture_ptr->top_field_first);
- }
- /* XXX: optimize the generation of this flag with entropy
- measures */
- s->frame_pred_frame_dct = s->progressive_sequence;
-
- put_bits(&s->pb, 1, s->frame_pred_frame_dct);
- put_bits(&s->pb, 1, s->concealment_motion_vectors);
- put_bits(&s->pb, 1, s->q_scale_type);
- put_bits(&s->pb, 1, s->intra_vlc_format);
- put_bits(&s->pb, 1, s->alternate_scan);
- put_bits(&s->pb, 1, s->repeat_first_field);
- s->progressive_frame = s->progressive_sequence;
- put_bits(&s->pb, 1, s->chroma_format == CHROMA_420 ? s->progressive_frame : 0); /* chroma_420_type */
- put_bits(&s->pb, 1, s->progressive_frame);
- put_bits(&s->pb, 1, 0); //composite_display_flag
- }
- if(s->flags & CODEC_FLAG_SVCD_SCAN_OFFSET){
- int i;
-
- put_header(s, USER_START_CODE);
- for(i=0; i<sizeof(svcd_scan_offset_placeholder); i++){
- put_bits(&s->pb, 8, svcd_scan_offset_placeholder[i]);
- }
- }
-
- s->mb_y=0;
- ff_mpeg1_encode_slice_header(s);
-}
-
-static inline void put_mb_modes(MpegEncContext *s, int n, int bits,
- int has_mv, int field_motion)
-{
- put_bits(&s->pb, n, bits);
- if (!s->frame_pred_frame_dct) {
- if (has_mv)
- put_bits(&s->pb, 2, 2 - field_motion); /* motion_type: frame/field */
- put_bits(&s->pb, 1, s->interlaced_dct);
- }
-}
-
-static av_always_inline void mpeg1_encode_mb_internal(MpegEncContext *s,
- DCTELEM block[6][64],
- int motion_x, int motion_y,
- int mb_block_count)
-{
- int i, cbp;
- const int mb_x = s->mb_x;
- const int mb_y = s->mb_y;
- const int first_mb= mb_x == s->resync_mb_x && mb_y == s->resync_mb_y;
-
- /* compute cbp */
- cbp = 0;
- for(i=0;i<mb_block_count;i++) {
- if (s->block_last_index[i] >= 0)
- cbp |= 1 << (mb_block_count - 1 - i);
- }
-
- if (cbp == 0 && !first_mb && s->mv_type == MV_TYPE_16X16 &&
- (mb_x != s->mb_width - 1 || (mb_y != s->mb_height - 1 && s->codec_id == CODEC_ID_MPEG1VIDEO)) &&
- ((s->pict_type == P_TYPE && (motion_x | motion_y) == 0) ||
- (s->pict_type == B_TYPE && s->mv_dir == s->last_mv_dir && (((s->mv_dir & MV_DIR_FORWARD) ? ((s->mv[0][0][0] - s->last_mv[0][0][0])|(s->mv[0][0][1] - s->last_mv[0][0][1])) : 0) |
- ((s->mv_dir & MV_DIR_BACKWARD) ? ((s->mv[1][0][0] - s->last_mv[1][0][0])|(s->mv[1][0][1] - s->last_mv[1][0][1])) : 0)) == 0))) {
- s->mb_skip_run++;
- s->qscale -= s->dquant;
- s->skip_count++;
- s->misc_bits++;
- s->last_bits++;
- if(s->pict_type == P_TYPE){
- s->last_mv[0][1][0]= s->last_mv[0][0][0]=
- s->last_mv[0][1][1]= s->last_mv[0][0][1]= 0;
- }
- } else {
- if(first_mb){
- assert(s->mb_skip_run == 0);
- encode_mb_skip_run(s, s->mb_x);
- }else{
- encode_mb_skip_run(s, s->mb_skip_run);
- }
-
- if (s->pict_type == I_TYPE) {
- if(s->dquant && cbp){
- put_mb_modes(s, 2, 1, 0, 0); /* macroblock_type : macroblock_quant = 1 */
- put_bits(&s->pb, 5, s->qscale);
- }else{
- put_mb_modes(s, 1, 1, 0, 0); /* macroblock_type : macroblock_quant = 0 */
- s->qscale -= s->dquant;
- }
- s->misc_bits+= get_bits_diff(s);
- s->i_count++;
- } else if (s->mb_intra) {
- if(s->dquant && cbp){
- put_mb_modes(s, 6, 0x01, 0, 0);
- put_bits(&s->pb, 5, s->qscale);
- }else{
- put_mb_modes(s, 5, 0x03, 0, 0);
- s->qscale -= s->dquant;
- }
- s->misc_bits+= get_bits_diff(s);
- s->i_count++;
- memset(s->last_mv, 0, sizeof(s->last_mv));
- } else if (s->pict_type == P_TYPE) {
- if(s->mv_type == MV_TYPE_16X16){
- if (cbp != 0) {
- if ((motion_x|motion_y) == 0) {
- if(s->dquant){
- put_mb_modes(s, 5, 1, 0, 0); /* macroblock_pattern & quant */
- put_bits(&s->pb, 5, s->qscale);
- }else{
- put_mb_modes(s, 2, 1, 0, 0); /* macroblock_pattern only */
- }
- s->misc_bits+= get_bits_diff(s);
- } else {
- if(s->dquant){
- put_mb_modes(s, 5, 2, 1, 0); /* motion + cbp */
- put_bits(&s->pb, 5, s->qscale);
- }else{
- put_mb_modes(s, 1, 1, 1, 0); /* motion + cbp */
- }
- s->misc_bits+= get_bits_diff(s);
- mpeg1_encode_motion(s, motion_x - s->last_mv[0][0][0], s->f_code); // RAL: f_code parameter added
- mpeg1_encode_motion(s, motion_y - s->last_mv[0][0][1], s->f_code); // RAL: f_code parameter added
- s->mv_bits+= get_bits_diff(s);
- }
- } else {
- put_bits(&s->pb, 3, 1); /* motion only */
- if (!s->frame_pred_frame_dct)
- put_bits(&s->pb, 2, 2); /* motion_type: frame */
- s->misc_bits+= get_bits_diff(s);
- mpeg1_encode_motion(s, motion_x - s->last_mv[0][0][0], s->f_code); // RAL: f_code parameter added
- mpeg1_encode_motion(s, motion_y - s->last_mv[0][0][1], s->f_code); // RAL: f_code parameter added
- s->qscale -= s->dquant;
- s->mv_bits+= get_bits_diff(s);
- }
- s->last_mv[0][1][0]= s->last_mv[0][0][0]= motion_x;
- s->last_mv[0][1][1]= s->last_mv[0][0][1]= motion_y;
- }else{
- assert(!s->frame_pred_frame_dct && s->mv_type == MV_TYPE_FIELD);
-
- if (cbp) {
- if(s->dquant){
- put_mb_modes(s, 5, 2, 1, 1); /* motion + cbp */
- put_bits(&s->pb, 5, s->qscale);
- }else{
- put_mb_modes(s, 1, 1, 1, 1); /* motion + cbp */
- }
- } else {
- put_bits(&s->pb, 3, 1); /* motion only */
- put_bits(&s->pb, 2, 1); /* motion_type: field */
- s->qscale -= s->dquant;
- }
- s->misc_bits+= get_bits_diff(s);
- for(i=0; i<2; i++){
- put_bits(&s->pb, 1, s->field_select[0][i]);
- mpeg1_encode_motion(s, s->mv[0][i][0] - s->last_mv[0][i][0] , s->f_code);
- mpeg1_encode_motion(s, s->mv[0][i][1] - (s->last_mv[0][i][1]>>1), s->f_code);
- s->last_mv[0][i][0]= s->mv[0][i][0];
- s->last_mv[0][i][1]= 2*s->mv[0][i][1];
- }
- s->mv_bits+= get_bits_diff(s);
- }
- if(cbp) {
- if (s->chroma_y_shift) {
- put_bits(&s->pb, mbPatTable[cbp][1], mbPatTable[cbp][0]);
- } else {
- put_bits(&s->pb, mbPatTable[cbp>>2][1], mbPatTable[cbp>>2][0]);
- put_bits(&s->pb, 2, cbp & 3);
- }
- }
- s->f_count++;
- } else{
- static const int mb_type_len[4]={0,3,4,2}; //bak,for,bi
-
- if(s->mv_type == MV_TYPE_16X16){
- if (cbp){ // With coded bloc pattern
- if (s->dquant) {
- if(s->mv_dir == MV_DIR_FORWARD)
- put_mb_modes(s, 6, 3, 1, 0);
- else
- put_mb_modes(s, mb_type_len[s->mv_dir]+3, 2, 1, 0);
- put_bits(&s->pb, 5, s->qscale);
- } else {
- put_mb_modes(s, mb_type_len[s->mv_dir], 3, 1, 0);
- }
- }else{ // No coded bloc pattern
- put_bits(&s->pb, mb_type_len[s->mv_dir], 2);
- if (!s->frame_pred_frame_dct)
- put_bits(&s->pb, 2, 2); /* motion_type: frame */
- s->qscale -= s->dquant;
- }
- s->misc_bits += get_bits_diff(s);
- if (s->mv_dir&MV_DIR_FORWARD){
- mpeg1_encode_motion(s, s->mv[0][0][0] - s->last_mv[0][0][0], s->f_code);
- mpeg1_encode_motion(s, 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){
- mpeg1_encode_motion(s, s->mv[1][0][0] - s->last_mv[1][0][0], s->b_code);
- mpeg1_encode_motion(s, 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{
- assert(s->mv_type == MV_TYPE_FIELD);
- assert(!s->frame_pred_frame_dct);
- if (cbp){ // With coded bloc pattern
- if (s->dquant) {
- if(s->mv_dir == MV_DIR_FORWARD)
- put_mb_modes(s, 6, 3, 1, 1);
- else
- put_mb_modes(s, mb_type_len[s->mv_dir]+3, 2, 1, 1);
- put_bits(&s->pb, 5, s->qscale);
- } else {
- put_mb_modes(s, mb_type_len[s->mv_dir], 3, 1, 1);
- }
- }else{ // No coded bloc pattern
- put_bits(&s->pb, mb_type_len[s->mv_dir], 2);
- put_bits(&s->pb, 2, 1); /* motion_type: field */
- s->qscale -= s->dquant;
- }
- s->misc_bits += get_bits_diff(s);
- if (s->mv_dir&MV_DIR_FORWARD){
- for(i=0; i<2; i++){
- put_bits(&s->pb, 1, s->field_select[0][i]);
- mpeg1_encode_motion(s, s->mv[0][i][0] - s->last_mv[0][i][0] , s->f_code);
- mpeg1_encode_motion(s, s->mv[0][i][1] - (s->last_mv[0][i][1]>>1), s->f_code);
- s->last_mv[0][i][0]= s->mv[0][i][0];
- s->last_mv[0][i][1]= 2*s->mv[0][i][1];
- }
- s->f_count++;
- }
- if (s->mv_dir&MV_DIR_BACKWARD){
- for(i=0; i<2; i++){
- put_bits(&s->pb, 1, s->field_select[1][i]);
- mpeg1_encode_motion(s, s->mv[1][i][0] - s->last_mv[1][i][0] , s->b_code);
- mpeg1_encode_motion(s, s->mv[1][i][1] - (s->last_mv[1][i][1]>>1), s->b_code);
- s->last_mv[1][i][0]= s->mv[1][i][0];
- s->last_mv[1][i][1]= 2*s->mv[1][i][1];
- }
- s->b_count++;
- }
- }
- s->mv_bits += get_bits_diff(s);
- if(cbp) {
- if (s->chroma_y_shift) {
- put_bits(&s->pb, mbPatTable[cbp][1], mbPatTable[cbp][0]);
- } else {
- put_bits(&s->pb, mbPatTable[cbp>>2][1], mbPatTable[cbp>>2][0]);
- put_bits(&s->pb, 2, cbp & 3);
- }
- }
- }
- for(i=0;i<mb_block_count;i++) {
- if (cbp & (1 << (mb_block_count - 1 - i))) {
- mpeg1_encode_block(s, block[i], i);
- }
- }
- s->mb_skip_run = 0;
- if(s->mb_intra)
- s->i_tex_bits+= get_bits_diff(s);
- else
- s->p_tex_bits+= get_bits_diff(s);
- }
-}
-
-void mpeg1_encode_mb(MpegEncContext *s, DCTELEM block[6][64], int motion_x, int motion_y)
-{
- if (s->chroma_format == CHROMA_420) mpeg1_encode_mb_internal(s, block, motion_x, motion_y, 6);
- else mpeg1_encode_mb_internal(s, block, motion_x, motion_y, 8);
-}
-
-// RAL: Parameter added: f_or_b_code
-static void mpeg1_encode_motion(MpegEncContext *s, int val, int f_or_b_code)
-{
- int code, bit_size, l, bits, range, sign;
-
- if (val == 0) {
- /* zero vector */
- code = 0;
- put_bits(&s->pb,
- mbMotionVectorTable[0][1],
- mbMotionVectorTable[0][0]);
- } else {
- bit_size = f_or_b_code - 1;
- range = 1 << bit_size;
- /* modulo encoding */
- l= INT_BIT - 5 - bit_size;
- val= (val<<l)>>l;
-
- if (val >= 0) {
- val--;
- code = (val >> bit_size) + 1;
- bits = val & (range - 1);
- sign = 0;
- } else {
- val = -val;
- val--;
- code = (val >> bit_size) + 1;
- bits = val & (range - 1);
- sign = 1;
- }
-
- assert(code > 0 && code <= 16);
-
- put_bits(&s->pb,
- mbMotionVectorTable[code][1],
- mbMotionVectorTable[code][0]);
-
- put_bits(&s->pb, 1, sign);
- if (bit_size > 0) {
- put_bits(&s->pb, bit_size, bits);
- }
- }
-}
-
-void ff_mpeg1_encode_init(MpegEncContext *s)
-{
- static int done=0;
-
- common_init(s);
-
- if(!done){
- int f_code;
- int mv;
- int i;
-
- done=1;
- init_rl(&rl_mpeg1, 1);
- if(s->intra_vlc_format)
- init_rl(&rl_mpeg2, 1);
-
- for(i=0; i<64; i++)
- {
- mpeg1_max_level[0][i]= rl_mpeg1.max_level[0][i];
- mpeg1_index_run[0][i]= rl_mpeg1.index_run[0][i];
- }
-
- init_uni_ac_vlc(&rl_mpeg1, uni_mpeg1_ac_vlc_len);
- if(s->intra_vlc_format)
- init_uni_ac_vlc(&rl_mpeg2, uni_mpeg2_ac_vlc_len);
-
- /* build unified dc encoding tables */
- for(i=-255; i<256; i++)
- {
- int adiff, index;
- int bits, code;
- int diff=i;
-
- adiff = FFABS(diff);
- if(diff<0) diff--;
- index = av_log2(2*adiff);
-
- bits= vlc_dc_lum_bits[index] + index;
- code= (vlc_dc_lum_code[index]<<index) + (diff & ((1 << index) - 1));
- mpeg1_lum_dc_uni[i+255]= bits + (code<<8);
-
- bits= vlc_dc_chroma_bits[index] + index;
- code= (vlc_dc_chroma_code[index]<<index) + (diff & ((1 << index) - 1));
- mpeg1_chr_dc_uni[i+255]= bits + (code<<8);
- }
-
- mv_penalty= av_mallocz( sizeof(uint8_t)*(MAX_FCODE+1)*(2*MAX_MV+1) );
-
- for(f_code=1; f_code<=MAX_FCODE; f_code++){
- for(mv=-MAX_MV; mv<=MAX_MV; mv++){
- int len;
-
- if(mv==0) len= mbMotionVectorTable[0][1];
- else{
- int val, bit_size, range, code;
-
- bit_size = f_code - 1;
- range = 1 << bit_size;
-
- val=mv;
- if (val < 0)
- val = -val;
- val--;
- code = (val >> bit_size) + 1;
- if(code<17){
- len= mbMotionVectorTable[code][1] + 1 + bit_size;
- }else{
- len= mbMotionVectorTable[16][1] + 2 + bit_size;
- }
- }
-
- mv_penalty[f_code][mv+MAX_MV]= len;
- }
- }
-
-
- for(f_code=MAX_FCODE; f_code>0; f_code--){
- for(mv=-(8<<f_code); mv<(8<<f_code); mv++){
- fcode_tab[mv+MAX_MV]= f_code;
- }
- }
- }
- s->me.mv_penalty= mv_penalty;
- s->fcode_tab= fcode_tab;
- if(s->codec_id == CODEC_ID_MPEG1VIDEO){
- s->min_qcoeff=-255;
- s->max_qcoeff= 255;
- }else{
- s->min_qcoeff=-2047;
- s->max_qcoeff= 2047;
- }
- if (s->intra_vlc_format) {
- s->intra_ac_vlc_length=
- s->intra_ac_vlc_last_length= uni_mpeg2_ac_vlc_len;
- } else {
- s->intra_ac_vlc_length=
- s->intra_ac_vlc_last_length= uni_mpeg1_ac_vlc_len;
- }
- s->inter_ac_vlc_length=
- s->inter_ac_vlc_last_length= uni_mpeg1_ac_vlc_len;
-}
-
-static inline void encode_dc(MpegEncContext *s, int diff, int component)
-{
- if(((unsigned) (diff+255)) >= 511){
- int index;
-
- if(diff<0){
- index= av_log2_16bit(-2*diff);
- diff--;
- }else{
- index= av_log2_16bit(2*diff);
- }
- if (component == 0) {
- put_bits(
- &s->pb,
- vlc_dc_lum_bits[index] + index,
- (vlc_dc_lum_code[index]<<index) + (diff & ((1 << index) - 1)));
- }else{
- put_bits(
- &s->pb,
- vlc_dc_chroma_bits[index] + index,
- (vlc_dc_chroma_code[index]<<index) + (diff & ((1 << index) - 1)));
- }
- }else{
- if (component == 0) {
- put_bits(
- &s->pb,
- mpeg1_lum_dc_uni[diff+255]&0xFF,
- mpeg1_lum_dc_uni[diff+255]>>8);
- } else {
- put_bits(
- &s->pb,
- mpeg1_chr_dc_uni[diff+255]&0xFF,
- mpeg1_chr_dc_uni[diff+255]>>8);
- }
- }
-}
-
-static void mpeg1_encode_block(MpegEncContext *s,
- DCTELEM *block,
- int n)
-{
- int alevel, level, last_non_zero, dc, diff, i, j, run, last_index, sign;
- int code, component;
- const uint16_t (*table_vlc)[2] = rl_mpeg1.table_vlc;
-
- last_index = s->block_last_index[n];
-
- /* DC coef */
- if (s->mb_intra) {
- component = (n <= 3 ? 0 : (n&1) + 1);
- dc = block[0]; /* overflow is impossible */
- diff = dc - s->last_dc[component];
- encode_dc(s, diff, component);
- s->last_dc[component] = dc;
- i = 1;
- if (s->intra_vlc_format)
- table_vlc = rl_mpeg2.table_vlc;
- } else {
- /* encode the first coefficient : needs to be done here because
- it is handled slightly differently */
- level = block[0];
- if (abs(level) == 1) {
- code = ((uint32_t)level >> 31); /* the sign bit */
- put_bits(&s->pb, 2, code | 0x02);
- i = 1;
- } else {
- i = 0;
- last_non_zero = -1;
- goto next_coef;
- }
- }
-
- /* now quantify & encode AC coefs */
- last_non_zero = i - 1;
-
- for(;i<=last_index;i++) {
- j = s->intra_scantable.permutated[i];
- level = block[j];
- next_coef:
-#if 0
- if (level != 0)
- dprintf("level[%d]=%d\n", i, level);
-#endif
- /* encode using VLC */
- if (level != 0) {
- run = i - last_non_zero - 1;
-
- alevel= level;
- MASK_ABS(sign, alevel)
- sign&=1;
-
- if (alevel <= mpeg1_max_level[0][run]){
- code= mpeg1_index_run[0][run] + alevel - 1;
- /* store the vlc & sign at once */
- put_bits(&s->pb, table_vlc[code][1]+1, (table_vlc[code][0]<<1) + sign);
- } else {
- /* escape seems to be pretty rare <5% so i dont optimize it */
- put_bits(&s->pb, table_vlc[111][1], table_vlc[111][0]);
- /* escape: only clip in this case */
- put_bits(&s->pb, 6, run);
- if(s->codec_id == CODEC_ID_MPEG1VIDEO){
- if (alevel < 128) {
- put_bits(&s->pb, 8, level & 0xff);
- } else {
- if (level < 0) {
- put_bits(&s->pb, 16, 0x8001 + level + 255);
- } else {
- put_bits(&s->pb, 16, level & 0xffff);
- }
- }
- }else{
- put_bits(&s->pb, 12, level & 0xfff);
- }
- }
- last_non_zero = i;
- }
- }
- /* end of block */
- put_bits(&s->pb, table_vlc[112][1], table_vlc[112][0]);
-}
-#endif //CONFIG_ENCODERS
-
-/******************************************/
-/* decoding */
-
-static VLC dc_lum_vlc;
-static VLC dc_chroma_vlc;
-static VLC mv_vlc;
-static VLC mbincr_vlc;
-static VLC mb_ptype_vlc;
-static VLC mb_btype_vlc;
-static VLC mb_pat_vlc;
-
-static void init_vlcs(void)
-{
- static int done = 0;
-
- if (!done) {
- done = 1;
-
- init_vlc(&dc_lum_vlc, DC_VLC_BITS, 12,
- vlc_dc_lum_bits, 1, 1,
- vlc_dc_lum_code, 2, 2, 1);
- init_vlc(&dc_chroma_vlc, DC_VLC_BITS, 12,
- vlc_dc_chroma_bits, 1, 1,
- vlc_dc_chroma_code, 2, 2, 1);
- init_vlc(&mv_vlc, MV_VLC_BITS, 17,
- &mbMotionVectorTable[0][1], 2, 1,
- &mbMotionVectorTable[0][0], 2, 1, 1);
- init_vlc(&mbincr_vlc, MBINCR_VLC_BITS, 36,
- &mbAddrIncrTable[0][1], 2, 1,
- &mbAddrIncrTable[0][0], 2, 1, 1);
- init_vlc(&mb_pat_vlc, MB_PAT_VLC_BITS, 64,
- &mbPatTable[0][1], 2, 1,
- &mbPatTable[0][0], 2, 1, 1);
-
- init_vlc(&mb_ptype_vlc, MB_PTYPE_VLC_BITS, 7,
- &table_mb_ptype[0][1], 2, 1,
- &table_mb_ptype[0][0], 2, 1, 1);
- init_vlc(&mb_btype_vlc, MB_BTYPE_VLC_BITS, 11,
- &table_mb_btype[0][1], 2, 1,
- &table_mb_btype[0][0], 2, 1, 1);
- init_rl(&rl_mpeg1, 1);
- init_rl(&rl_mpeg2, 1);
-
- init_2d_vlc_rl(&rl_mpeg1, 1);
- init_2d_vlc_rl(&rl_mpeg2, 1);
- }
-}
-
-static inline int get_dmv(MpegEncContext *s)
-{
- if(get_bits1(&s->gb))
- return 1 - (get_bits1(&s->gb) << 1);
- else
- return 0;
-}
-
-static inline int get_qscale(MpegEncContext *s)
-{
- int qscale = get_bits(&s->gb, 5);
- if (s->q_scale_type) {
- return non_linear_qscale[qscale];
- } else {
- return qscale << 1;
- }
-}
-
-/* motion type (for mpeg2) */
-#define MT_FIELD 1
-#define MT_FRAME 2
-#define MT_16X8 2
-#define MT_DMV 3
-
-static int mpeg_decode_mb(MpegEncContext *s,
- DCTELEM block[12][64])
-{
- int i, j, k, cbp, val, mb_type, motion_type;
- const int mb_block_count = 4 + (1<< s->chroma_format);
-
- dprintf("decode_mb: x=%d y=%d\n", s->mb_x, s->mb_y);
-
- assert(s->mb_skipped==0);
-
- if (s->mb_skip_run-- != 0) {
- if(s->pict_type == I_TYPE){
- av_log(s->avctx, AV_LOG_ERROR, "skipped MB in I frame at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
-
- /* skip mb */
- s->mb_intra = 0;
- for(i=0;i<12;i++)
- s->block_last_index[i] = -1;
- if(s->picture_structure == PICT_FRAME)
- s->mv_type = MV_TYPE_16X16;
- else
- s->mv_type = MV_TYPE_FIELD;
- if (s->pict_type == P_TYPE) {
- /* if P type, zero motion vector is implied */
- s->mv_dir = MV_DIR_FORWARD;
- s->mv[0][0][0] = s->mv[0][0][1] = 0;
- s->last_mv[0][0][0] = s->last_mv[0][0][1] = 0;
- s->last_mv[0][1][0] = s->last_mv[0][1][1] = 0;
- s->field_select[0][0]= s->picture_structure - 1;
- s->mb_skipped = 1;
- s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ]= MB_TYPE_SKIP | MB_TYPE_L0 | MB_TYPE_16x16;
- } else {
- int mb_type;
-
- if(s->mb_x)
- mb_type= s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride - 1];
- else
- mb_type= s->current_picture.mb_type[ s->mb_width + (s->mb_y-1)*s->mb_stride - 1]; // FIXME not sure if this is allowed in mpeg at all,
- if(IS_INTRA(mb_type))
- return -1;
-
- /* if B type, reuse previous vectors and directions */
- s->mv[0][0][0] = s->last_mv[0][0][0];
- s->mv[0][0][1] = s->last_mv[0][0][1];
- s->mv[1][0][0] = s->last_mv[1][0][0];
- s->mv[1][0][1] = s->last_mv[1][0][1];
-
- s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ]=
- mb_type | MB_TYPE_SKIP;
-// assert(s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride - 1]&(MB_TYPE_16x16|MB_TYPE_16x8));
-
- if((s->mv[0][0][0]|s->mv[0][0][1]|s->mv[1][0][0]|s->mv[1][0][1])==0)
- s->mb_skipped = 1;
- }
-
- return 0;
- }
-
- switch(s->pict_type) {
- default:
- case I_TYPE:
- if (get_bits1(&s->gb) == 0) {
- if (get_bits1(&s->gb) == 0){
- av_log(s->avctx, AV_LOG_ERROR, "invalid mb type in I Frame at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- mb_type = MB_TYPE_QUANT | MB_TYPE_INTRA;
- } else {
- mb_type = MB_TYPE_INTRA;
- }
- break;
- case P_TYPE:
- mb_type = get_vlc2(&s->gb, mb_ptype_vlc.table, MB_PTYPE_VLC_BITS, 1);
- if (mb_type < 0){
- av_log(s->avctx, AV_LOG_ERROR, "invalid mb type in P Frame at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- mb_type = ptype2mb_type[ mb_type ];
- break;
- case B_TYPE:
- mb_type = get_vlc2(&s->gb, mb_btype_vlc.table, MB_BTYPE_VLC_BITS, 1);
- if (mb_type < 0){
- av_log(s->avctx, AV_LOG_ERROR, "invalid mb type in B Frame at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- mb_type = btype2mb_type[ mb_type ];
- break;
- }
- dprintf("mb_type=%x\n", mb_type);
-// motion_type = 0; /* avoid warning */
- if (IS_INTRA(mb_type)) {
- s->dsp.clear_blocks(s->block[0]);
-
- if(!s->chroma_y_shift){
- s->dsp.clear_blocks(s->block[6]);
- }
-
- /* compute dct type */
- if (s->picture_structure == PICT_FRAME && //FIXME add a interlaced_dct coded var?
- !s->frame_pred_frame_dct) {
- s->interlaced_dct = get_bits1(&s->gb);
- }
-
- if (IS_QUANT(mb_type))
- s->qscale = get_qscale(s);
-
- if (s->concealment_motion_vectors) {
- /* just parse them */
- if (s->picture_structure != PICT_FRAME)
- skip_bits1(&s->gb); /* field select */
-
- s->mv[0][0][0]= s->last_mv[0][0][0]= s->last_mv[0][1][0] =
- mpeg_decode_motion(s, s->mpeg_f_code[0][0], s->last_mv[0][0][0]);
- s->mv[0][0][1]= s->last_mv[0][0][1]= s->last_mv[0][1][1] =
- mpeg_decode_motion(s, s->mpeg_f_code[0][1], s->last_mv[0][0][1]);
-
- skip_bits1(&s->gb); /* marker */
- }else
- memset(s->last_mv, 0, sizeof(s->last_mv)); /* reset mv prediction */
- s->mb_intra = 1;
-#ifdef HAVE_XVMC
- //one 1 we memcpy blocks in xvmcvideo
- if(s->avctx->xvmc_acceleration > 1){
- XVMC_pack_pblocks(s,-1);//inter are always full blocks
- if(s->swap_uv){
- exchange_uv(s);
- }
- }
-#endif
-
- if (s->codec_id == CODEC_ID_MPEG2VIDEO) {
- if(s->flags2 & CODEC_FLAG2_FAST){
- for(i=0;i<6;i++) {
- mpeg2_fast_decode_block_intra(s, s->pblocks[i], i);
- }
- }else{
- for(i=0;i<mb_block_count;i++) {
- if (mpeg2_decode_block_intra(s, s->pblocks[i], i) < 0)
- return -1;
- }
- }
- } else {
- for(i=0;i<6;i++) {
- if (mpeg1_decode_block_intra(s, s->pblocks[i], i) < 0)
- return -1;
- }
- }
- } else {
- if (mb_type & MB_TYPE_ZERO_MV){
- assert(mb_type & MB_TYPE_CBP);
-
- /* compute dct type */
- if (s->picture_structure == PICT_FRAME && //FIXME add a interlaced_dct coded var?
- !s->frame_pred_frame_dct) {
- s->interlaced_dct = get_bits1(&s->gb);
- }
-
- if (IS_QUANT(mb_type))
- s->qscale = get_qscale(s);
-
- s->mv_dir = MV_DIR_FORWARD;
- if(s->picture_structure == PICT_FRAME)
- s->mv_type = MV_TYPE_16X16;
- else{
- s->mv_type = MV_TYPE_FIELD;
- mb_type |= MB_TYPE_INTERLACED;
- s->field_select[0][0]= s->picture_structure - 1;
- }
- s->last_mv[0][0][0] = 0;
- s->last_mv[0][0][1] = 0;
- s->last_mv[0][1][0] = 0;
- s->last_mv[0][1][1] = 0;
- s->mv[0][0][0] = 0;
- s->mv[0][0][1] = 0;
- }else{
- assert(mb_type & MB_TYPE_L0L1);
-//FIXME decide if MBs in field pictures are MB_TYPE_INTERLACED
- /* get additionnal motion vector type */
- if (s->frame_pred_frame_dct)
- motion_type = MT_FRAME;
- else{
- motion_type = get_bits(&s->gb, 2);
- }
-
- /* compute dct type */
- if (s->picture_structure == PICT_FRAME && //FIXME add a interlaced_dct coded var?
- !s->frame_pred_frame_dct && HAS_CBP(mb_type)) {
- s->interlaced_dct = get_bits1(&s->gb);
- }
-
- if (IS_QUANT(mb_type))
- s->qscale = get_qscale(s);
-
- /* motion vectors */
- s->mv_dir = 0;
- for(i=0;i<2;i++) {
- if (USES_LIST(mb_type, i)) {
- s->mv_dir |= (MV_DIR_FORWARD >> i);
- dprintf("motion_type=%d\n", motion_type);
- switch(motion_type) {
- case MT_FRAME: /* or MT_16X8 */
- if (s->picture_structure == PICT_FRAME) {
- /* MT_FRAME */
- mb_type |= MB_TYPE_16x16;
- s->mv_type = MV_TYPE_16X16;
- s->mv[i][0][0]= s->last_mv[i][0][0]= s->last_mv[i][1][0] =
- mpeg_decode_motion(s, s->mpeg_f_code[i][0], s->last_mv[i][0][0]);
- s->mv[i][0][1]= s->last_mv[i][0][1]= s->last_mv[i][1][1] =
- mpeg_decode_motion(s, s->mpeg_f_code[i][1], s->last_mv[i][0][1]);
- /* full_pel: only for mpeg1 */
- if (s->full_pel[i]){
- s->mv[i][0][0] <<= 1;
- s->mv[i][0][1] <<= 1;
- }
- } else {
- /* MT_16X8 */
- mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED;
- s->mv_type = MV_TYPE_16X8;
- for(j=0;j<2;j++) {
- s->field_select[i][j] = get_bits1(&s->gb);
- for(k=0;k<2;k++) {
- val = mpeg_decode_motion(s, s->mpeg_f_code[i][k],
- s->last_mv[i][j][k]);
- s->last_mv[i][j][k] = val;
- s->mv[i][j][k] = val;
- }
- }
- }
- break;
- case MT_FIELD:
- s->mv_type = MV_TYPE_FIELD;
- if (s->picture_structure == PICT_FRAME) {
- mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED;
- for(j=0;j<2;j++) {
- s->field_select[i][j] = get_bits1(&s->gb);
- val = mpeg_decode_motion(s, s->mpeg_f_code[i][0],
- s->last_mv[i][j][0]);
- s->last_mv[i][j][0] = val;
- s->mv[i][j][0] = val;
- dprintf("fmx=%d\n", val);
- val = mpeg_decode_motion(s, s->mpeg_f_code[i][1],
- s->last_mv[i][j][1] >> 1);
- s->last_mv[i][j][1] = val << 1;
- s->mv[i][j][1] = val;
- dprintf("fmy=%d\n", val);
- }
- } else {
- mb_type |= MB_TYPE_16x16 | MB_TYPE_INTERLACED;
- s->field_select[i][0] = get_bits1(&s->gb);
- for(k=0;k<2;k++) {
- val = mpeg_decode_motion(s, s->mpeg_f_code[i][k],
- s->last_mv[i][0][k]);
- s->last_mv[i][0][k] = val;
- s->last_mv[i][1][k] = val;
- s->mv[i][0][k] = val;
- }
- }
- break;
- case MT_DMV:
- {
- int dmx, dmy, mx, my, m;
-
- 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);
- dmy = get_dmv(s);
- s->mv_type = MV_TYPE_DMV;
-
-
- s->last_mv[i][0][1] = my<<1;
- s->last_mv[i][1][1] = my<<1;
-
- s->mv[i][0][0] = mx;
- s->mv[i][0][1] = my;
- s->mv[i][1][0] = mx;//not used
- s->mv[i][1][1] = my;//not used
-
- if (s->picture_structure == PICT_FRAME) {
- mb_type |= MB_TYPE_16x16 | MB_TYPE_INTERLACED;
-
- //m = 1 + 2 * s->top_field_first;
- m = s->top_field_first ? 1 : 3;
-
- /* top -> top pred */
- s->mv[i][2][0] = ((mx * m + (mx > 0)) >> 1) + dmx;
- s->mv[i][2][1] = ((my * m + (my > 0)) >> 1) + dmy - 1;
- m = 4 - m;
- s->mv[i][3][0] = ((mx * m + (mx > 0)) >> 1) + dmx;
- s->mv[i][3][1] = ((my * m + (my > 0)) >> 1) + dmy + 1;
- } else {
- mb_type |= MB_TYPE_16x16;
-
- s->mv[i][2][0] = ((mx + (mx > 0)) >> 1) + dmx;
- s->mv[i][2][1] = ((my + (my > 0)) >> 1) + dmy;
- if(s->picture_structure == PICT_TOP_FIELD)
- s->mv[i][2][1]--;
- else
- s->mv[i][2][1]++;
- }
- }
- break;
- default:
- av_log(s->avctx, AV_LOG_ERROR, "00 motion_type at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- }
- }
- }
-
- s->mb_intra = 0;
- if (HAS_CBP(mb_type)) {
- s->dsp.clear_blocks(s->block[0]);
-
- if(!s->chroma_y_shift){
- s->dsp.clear_blocks(s->block[6]);
- }
-
- cbp = get_vlc2(&s->gb, mb_pat_vlc.table, MB_PAT_VLC_BITS, 1);
- if (cbp < 0 || ((cbp == 0) && (s->chroma_format < 2)) ){
- av_log(s->avctx, AV_LOG_ERROR, "invalid cbp at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- if(mb_block_count > 6){
- cbp<<= mb_block_count-6;
- cbp |= get_bits(&s->gb, mb_block_count-6);
- }
-
-#ifdef HAVE_XVMC
- //on 1 we memcpy blocks in xvmcvideo
- if(s->avctx->xvmc_acceleration > 1){
- XVMC_pack_pblocks(s,cbp);
- if(s->swap_uv){
- exchange_uv(s);
- }
- }
-#endif
-
- if (s->codec_id == CODEC_ID_MPEG2VIDEO) {
- if(s->flags2 & CODEC_FLAG2_FAST){
- for(i=0;i<6;i++) {
- if(cbp & 32) {
- mpeg2_fast_decode_block_non_intra(s, s->pblocks[i], i);
- } else {
- s->block_last_index[i] = -1;
- }
- cbp+=cbp;
- }
- }else{
- cbp<<= 12-mb_block_count;
-
- for(i=0;i<mb_block_count;i++) {
- if ( cbp & (1<<11) ) {
- if (mpeg2_decode_block_non_intra(s, s->pblocks[i], i) < 0)
- return -1;
- } else {
- s->block_last_index[i] = -1;
- }
- cbp+=cbp;
- }
- }
- } else {
- if(s->flags2 & CODEC_FLAG2_FAST){
- for(i=0;i<6;i++) {
- if (cbp & 32) {
- mpeg1_fast_decode_block_inter(s, s->pblocks[i], i);
- } else {
- s->block_last_index[i] = -1;
- }
- cbp+=cbp;
- }
- }else{
- for(i=0;i<6;i++) {
- if (cbp & 32) {
- if (mpeg1_decode_block_inter(s, s->pblocks[i], i) < 0)
- return -1;
- } else {
- s->block_last_index[i] = -1;
- }
- cbp+=cbp;
- }
- }
- }
- }else{
- for(i=0;i<12;i++)
- s->block_last_index[i] = -1;
- }
- }
-
- s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ]= mb_type;
-
- return 0;
-}
-
-/* as h263, but only 17 codes */
-static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred)
-{
- int code, sign, val, l, shift;
-
- 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 = fcode - 1;
- val = code;
- if (shift) {
- val = (val - 1) << shift;
- val |= get_bits(&s->gb, shift);
- val++;
- }
- if (sign)
- val = -val;
- val += pred;
-
- /* modulo decoding */
- l= INT_BIT - 5 - shift;
- val = (val<<l)>>l;
- return val;
-}
-
-static inline int decode_dc(GetBitContext *gb, int component)
-{
- int code, diff;
-
- if (component == 0) {
- code = get_vlc2(gb, dc_lum_vlc.table, DC_VLC_BITS, 2);
- } else {
- code = get_vlc2(gb, dc_chroma_vlc.table, DC_VLC_BITS, 2);
- }
- if (code < 0){
- av_log(NULL, AV_LOG_ERROR, "invalid dc code at\n");
- return 0xffff;
- }
- if (code == 0) {
- diff = 0;
- } else {
- diff = get_xbits(gb, code);
- }
- return diff;
-}
-
-static inline int mpeg1_decode_block_intra(MpegEncContext *s,
- DCTELEM *block,
- int n)
-{
- int level, dc, diff, i, j, run;
- int component;
- RLTable *rl = &rl_mpeg1;
- uint8_t * const scantable= s->intra_scantable.permutated;
- const uint16_t *quant_matrix= s->intra_matrix;
- const int qscale= s->qscale;
-
- /* DC coef */
- component = (n <= 3 ? 0 : n - 4 + 1);
- diff = decode_dc(&s->gb, component);
- if (diff >= 0xffff)
- return -1;
- dc = s->last_dc[component];
- dc += diff;
- s->last_dc[component] = dc;
- block[0] = dc<<3;
- dprintf("dc=%d diff=%d\n", dc, diff);
- i = 0;
- {
- OPEN_READER(re, &s->gb);
- /* now quantify & encode AC coefs */
- for(;;) {
- UPDATE_CACHE(re, &s->gb);
- GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
-
- if(level == 127){
- break;
- } else if(level != 0) {
- i += run;
- j = scantable[i];
- level= (level*qscale*quant_matrix[j])>>4;
- level= (level-1)|1;
- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
- LAST_SKIP_BITS(re, &s->gb, 1);
- } else {
- /* escape */
- run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
- UPDATE_CACHE(re, &s->gb);
- level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8);
- if (level == -128) {
- level = SHOW_UBITS(re, &s->gb, 8) - 256; LAST_SKIP_BITS(re, &s->gb, 8);
- } else if (level == 0) {
- level = SHOW_UBITS(re, &s->gb, 8) ; LAST_SKIP_BITS(re, &s->gb, 8);
- }
- i += run;
- j = scantable[i];
- if(level<0){
- level= -level;
- level= (level*qscale*quant_matrix[j])>>4;
- level= (level-1)|1;
- level= -level;
- }else{
- level= (level*qscale*quant_matrix[j])>>4;
- level= (level-1)|1;
- }
- }
- if (i > 63){
- av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
-
- block[j] = level;
- }
- CLOSE_READER(re, &s->gb);
- }
- s->block_last_index[n] = i;
- return 0;
-}
-
-static inline int mpeg1_decode_block_inter(MpegEncContext *s,
- DCTELEM *block,
- int n)
-{
- int level, i, j, run;
- RLTable *rl = &rl_mpeg1;
- uint8_t * const scantable= s->intra_scantable.permutated;
- const uint16_t *quant_matrix= s->inter_matrix;
- const int qscale= s->qscale;
-
- {
- OPEN_READER(re, &s->gb);
- i = -1;
- /* special case for the first coef. no need to add a second vlc table */
- UPDATE_CACHE(re, &s->gb);
- if (((int32_t)GET_CACHE(re, &s->gb)) < 0) {
- level= (3*qscale*quant_matrix[0])>>5;
- level= (level-1)|1;
- if(GET_CACHE(re, &s->gb)&0x40000000)
- level= -level;
- block[0] = level;
- i++;
- SKIP_BITS(re, &s->gb, 2);
- if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
- goto end;
- }
-
- /* now quantify & encode AC coefs */
- for(;;) {
- GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
-
- if(level != 0) {
- i += run;
- j = scantable[i];
- level= ((level*2+1)*qscale*quant_matrix[j])>>5;
- level= (level-1)|1;
- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
- SKIP_BITS(re, &s->gb, 1);
- } else {
- /* escape */
- run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
- UPDATE_CACHE(re, &s->gb);
- level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8);
- if (level == -128) {
- level = SHOW_UBITS(re, &s->gb, 8) - 256; SKIP_BITS(re, &s->gb, 8);
- } else if (level == 0) {
- level = SHOW_UBITS(re, &s->gb, 8) ; SKIP_BITS(re, &s->gb, 8);
- }
- i += run;
- j = scantable[i];
- if(level<0){
- level= -level;
- level= ((level*2+1)*qscale*quant_matrix[j])>>5;
- level= (level-1)|1;
- level= -level;
- }else{
- level= ((level*2+1)*qscale*quant_matrix[j])>>5;
- level= (level-1)|1;
- }
- }
- if (i > 63){
- av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
-
- block[j] = level;
- if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
- break;
- UPDATE_CACHE(re, &s->gb);
- }
-end:
- LAST_SKIP_BITS(re, &s->gb, 2);
- CLOSE_READER(re, &s->gb);
- }
- s->block_last_index[n] = i;
- return 0;
-}
-
-static inline int mpeg1_fast_decode_block_inter(MpegEncContext *s, DCTELEM *block, int n)
-{
- int level, i, j, run;
- RLTable *rl = &rl_mpeg1;
- uint8_t * const scantable= s->intra_scantable.permutated;
- const int qscale= s->qscale;
-
- {
- OPEN_READER(re, &s->gb);
- i = -1;
- /* special case for the first coef. no need to add a second vlc table */
- UPDATE_CACHE(re, &s->gb);
- if (((int32_t)GET_CACHE(re, &s->gb)) < 0) {
- level= (3*qscale)>>1;
- level= (level-1)|1;
- if(GET_CACHE(re, &s->gb)&0x40000000)
- level= -level;
- block[0] = level;
- i++;
- SKIP_BITS(re, &s->gb, 2);
- if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
- goto end;
- }
-
- /* now quantify & encode AC coefs */
- for(;;) {
- GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
-
- if(level != 0) {
- i += run;
- j = scantable[i];
- level= ((level*2+1)*qscale)>>1;
- level= (level-1)|1;
- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
- SKIP_BITS(re, &s->gb, 1);
- } else {
- /* escape */
- run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
- UPDATE_CACHE(re, &s->gb);
- level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8);
- if (level == -128) {
- level = SHOW_UBITS(re, &s->gb, 8) - 256; SKIP_BITS(re, &s->gb, 8);
- } else if (level == 0) {
- level = SHOW_UBITS(re, &s->gb, 8) ; SKIP_BITS(re, &s->gb, 8);
- }
- i += run;
- j = scantable[i];
- if(level<0){
- level= -level;
- level= ((level*2+1)*qscale)>>1;
- level= (level-1)|1;
- level= -level;
- }else{
- level= ((level*2+1)*qscale)>>1;
- level= (level-1)|1;
- }
- }
-
- block[j] = level;
- if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
- break;
- UPDATE_CACHE(re, &s->gb);
- }
-end:
- LAST_SKIP_BITS(re, &s->gb, 2);
- CLOSE_READER(re, &s->gb);
- }
- s->block_last_index[n] = i;
- return 0;
-}
-
-
-static inline int mpeg2_decode_block_non_intra(MpegEncContext *s,
- DCTELEM *block,
- int n)
-{
- int level, i, j, run;
- RLTable *rl = &rl_mpeg1;
- uint8_t * const scantable= s->intra_scantable.permutated;
- const uint16_t *quant_matrix;
- const int qscale= s->qscale;
- int mismatch;
-
- mismatch = 1;
-
- {
- OPEN_READER(re, &s->gb);
- i = -1;
- if (n < 4)
- quant_matrix = s->inter_matrix;
- else
- quant_matrix = s->chroma_inter_matrix;
-
- /* special case for the first coef. no need to add a second vlc table */
- UPDATE_CACHE(re, &s->gb);
- if (((int32_t)GET_CACHE(re, &s->gb)) < 0) {
- level= (3*qscale*quant_matrix[0])>>5;
- if(GET_CACHE(re, &s->gb)&0x40000000)
- level= -level;
- block[0] = level;
- mismatch ^= level;
- i++;
- SKIP_BITS(re, &s->gb, 2);
- if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
- goto end;
- }
-
- /* now quantify & encode AC coefs */
- for(;;) {
- GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
-
- if(level != 0) {
- i += run;
- j = scantable[i];
- level= ((level*2+1)*qscale*quant_matrix[j])>>5;
- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
- SKIP_BITS(re, &s->gb, 1);
- } else {
- /* escape */
- run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
- UPDATE_CACHE(re, &s->gb);
- level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12);
-
- i += run;
- j = scantable[i];
- if(level<0){
- level= ((-level*2+1)*qscale*quant_matrix[j])>>5;
- level= -level;
- }else{
- level= ((level*2+1)*qscale*quant_matrix[j])>>5;
- }
- }
- if (i > 63){
- av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
-
- mismatch ^= level;
- block[j] = level;
- if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
- break;
- UPDATE_CACHE(re, &s->gb);
- }
-end:
- LAST_SKIP_BITS(re, &s->gb, 2);
- CLOSE_READER(re, &s->gb);
- }
- block[63] ^= (mismatch & 1);
-
- s->block_last_index[n] = i;
- return 0;
-}
-
-static inline int mpeg2_fast_decode_block_non_intra(MpegEncContext *s,
- DCTELEM *block,
- int n)
-{
- int level, i, j, run;
- RLTable *rl = &rl_mpeg1;
- uint8_t * const scantable= s->intra_scantable.permutated;
- const int qscale= s->qscale;
- OPEN_READER(re, &s->gb);
- i = -1;
-
- /* special case for the first coef. no need to add a second vlc table */
- UPDATE_CACHE(re, &s->gb);
- if (((int32_t)GET_CACHE(re, &s->gb)) < 0) {
- level= (3*qscale)>>1;
- if(GET_CACHE(re, &s->gb)&0x40000000)
- level= -level;
- block[0] = level;
- i++;
- SKIP_BITS(re, &s->gb, 2);
- if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
- goto end;
- }
-
- /* now quantify & encode AC coefs */
- for(;;) {
- GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
-
- if(level != 0) {
- i += run;
- j = scantable[i];
- level= ((level*2+1)*qscale)>>1;
- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
- SKIP_BITS(re, &s->gb, 1);
- } else {
- /* escape */
- run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
- UPDATE_CACHE(re, &s->gb);
- level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12);
-
- i += run;
- j = scantable[i];
- if(level<0){
- level= ((-level*2+1)*qscale)>>1;
- level= -level;
- }else{
- level= ((level*2+1)*qscale)>>1;
- }
- }
-
- block[j] = level;
- if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
- break;
- UPDATE_CACHE(re, &s->gb);
- }
-end:
- LAST_SKIP_BITS(re, &s->gb, 2);
- CLOSE_READER(re, &s->gb);
- s->block_last_index[n] = i;
- return 0;
-}
-
-
-static inline int mpeg2_decode_block_intra(MpegEncContext *s,
- DCTELEM *block,
- int n)
-{
- int level, dc, diff, i, j, run;
- int component;
- RLTable *rl;
- uint8_t * const scantable= s->intra_scantable.permutated;
- const uint16_t *quant_matrix;
- const int qscale= s->qscale;
- int mismatch;
-
- /* DC coef */
- if (n < 4){
- quant_matrix = s->intra_matrix;
- component = 0;
- }else{
- quant_matrix = s->chroma_intra_matrix;
- component = (n&1) + 1;
- }
- diff = decode_dc(&s->gb, component);
- if (diff >= 0xffff)
- return -1;
- dc = s->last_dc[component];
- dc += diff;
- s->last_dc[component] = dc;
- block[0] = dc << (3 - s->intra_dc_precision);
- dprintf("dc=%d\n", block[0]);
- mismatch = block[0] ^ 1;
- i = 0;
- if (s->intra_vlc_format)
- rl = &rl_mpeg2;
- else
- rl = &rl_mpeg1;
-
- {
- OPEN_READER(re, &s->gb);
- /* now quantify & encode AC coefs */
- for(;;) {
- UPDATE_CACHE(re, &s->gb);
- GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
-
- if(level == 127){
- break;
- } else if(level != 0) {
- i += run;
- j = scantable[i];
- level= (level*qscale*quant_matrix[j])>>4;
- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
- LAST_SKIP_BITS(re, &s->gb, 1);
- } else {
- /* escape */
- run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
- UPDATE_CACHE(re, &s->gb);
- level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12);
- i += run;
- j = scantable[i];
- if(level<0){
- level= (-level*qscale*quant_matrix[j])>>4;
- level= -level;
- }else{
- level= (level*qscale*quant_matrix[j])>>4;
- }
- }
- if (i > 63){
- av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
-
- mismatch^= level;
- block[j] = level;
- }
- CLOSE_READER(re, &s->gb);
- }
- block[63]^= mismatch&1;
-
- s->block_last_index[n] = i;
- return 0;
-}
-
-static inline int mpeg2_fast_decode_block_intra(MpegEncContext *s,
- DCTELEM *block,
- int n)
-{
- int level, dc, diff, j, run;
- int component;
- RLTable *rl;
- uint8_t * scantable= s->intra_scantable.permutated;
- const uint16_t *quant_matrix;
- const int qscale= s->qscale;
-
- /* DC coef */
- if (n < 4){
- quant_matrix = s->intra_matrix;
- component = 0;
- }else{
- quant_matrix = s->chroma_intra_matrix;
- component = (n&1) + 1;
- }
- diff = decode_dc(&s->gb, component);
- if (diff >= 0xffff)
- return -1;
- dc = s->last_dc[component];
- dc += diff;
- s->last_dc[component] = dc;
- block[0] = dc << (3 - s->intra_dc_precision);
- if (s->intra_vlc_format)
- rl = &rl_mpeg2;
- else
- rl = &rl_mpeg1;
-
- {
- OPEN_READER(re, &s->gb);
- /* now quantify & encode AC coefs */
- for(;;) {
- UPDATE_CACHE(re, &s->gb);
- GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
-
- if(level == 127){
- break;
- } else if(level != 0) {
- scantable += run;
- j = *scantable;
- level= (level*qscale*quant_matrix[j])>>4;
- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
- LAST_SKIP_BITS(re, &s->gb, 1);
- } else {
- /* escape */
- run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
- UPDATE_CACHE(re, &s->gb);
- level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12);
- scantable += run;
- j = *scantable;
- if(level<0){
- level= (-level*qscale*quant_matrix[j])>>4;
- level= -level;
- }else{
- level= (level*qscale*quant_matrix[j])>>4;
- }
- }
-
- block[j] = level;
- }
- CLOSE_READER(re, &s->gb);
- }
-
- s->block_last_index[n] = scantable - s->intra_scantable.permutated;
- return 0;
-}
-
-typedef struct Mpeg1Context {
- MpegEncContext mpeg_enc_ctx;
- int mpeg_enc_ctx_allocated; /* true if decoding context allocated */
- int repeat_field; /* true if we must repeat the field */
- AVPanScan pan_scan; /** some temporary storage for the panscan */
- int slice_count;
- int swap_uv;//indicate VCR2
- int save_aspect_info;
- AVRational frame_rate_ext; ///< MPEG-2 specific framerate modificator
-
-} Mpeg1Context;
-
-static int mpeg_decode_init(AVCodecContext *avctx)
-{
- Mpeg1Context *s = avctx->priv_data;
- MpegEncContext *s2 = &s->mpeg_enc_ctx;
- int i;
-
- //we need some parmutation to store
- //matrixes, until MPV_common_init()
- //set the real permutatuon
- for(i=0;i<64;i++)
- s2->dsp.idct_permutation[i]=i;
-
- MPV_decode_defaults(s2);
-
- s->mpeg_enc_ctx.avctx= avctx;
- s->mpeg_enc_ctx.flags= avctx->flags;
- s->mpeg_enc_ctx.flags2= avctx->flags2;
- common_init(&s->mpeg_enc_ctx);
- init_vlcs();
-
- s->mpeg_enc_ctx_allocated = 0;
- s->mpeg_enc_ctx.picture_number = 0;
- s->repeat_field = 0;
- s->mpeg_enc_ctx.codec_id= avctx->codec->id;
- return 0;
-}
-
-static void quant_matrix_rebuild(uint16_t *matrix, const uint8_t *old_perm,
- const uint8_t *new_perm){
- uint16_t temp_matrix[64];
- int i;
-
- memcpy(temp_matrix,matrix,64*sizeof(uint16_t));
-
- for(i=0;i<64;i++){
- matrix[new_perm[i]] = temp_matrix[old_perm[i]];
- }
-}
-
-//Call this function when we know all parameters
-//it may be called in different places for mpeg1 and mpeg2
-static int mpeg_decode_postinit(AVCodecContext *avctx){
- Mpeg1Context *s1 = avctx->priv_data;
- MpegEncContext *s = &s1->mpeg_enc_ctx;
- uint8_t old_permutation[64];
-
- if (
- (s1->mpeg_enc_ctx_allocated == 0)||
- avctx->coded_width != s->width ||
- avctx->coded_height != s->height||
- s1->save_aspect_info != s->aspect_ratio_info||
- 0)
- {
-
- if (s1->mpeg_enc_ctx_allocated) {
- ParseContext pc= s->parse_context;
- s->parse_context.buffer=0;
- MPV_common_end(s);
- s->parse_context= pc;
- }
-
- if( (s->width == 0 )||(s->height == 0))
- return -2;
-
- avcodec_set_dimensions(avctx, s->width, s->height);
- avctx->bit_rate = s->bit_rate;
- s1->save_aspect_info = s->aspect_ratio_info;
-
- //low_delay may be forced, in this case we will have B frames
- //that behave like P frames
- avctx->has_b_frames = !(s->low_delay);
-
- if(avctx->sub_id==1){//s->codec_id==avctx->codec_id==CODEC_ID
- //mpeg1 fps
- avctx->time_base.den= ff_frame_rate_tab[s->frame_rate_index].num;
- avctx->time_base.num= ff_frame_rate_tab[s->frame_rate_index].den;
- //mpeg1 aspect
- avctx->sample_aspect_ratio= av_d2q(
- 1.0/mpeg1_aspect[s->aspect_ratio_info], 255);
-
- }else{//mpeg2
- //mpeg2 fps
- av_reduce(
- &s->avctx->time_base.den,
- &s->avctx->time_base.num,
- ff_frame_rate_tab[s->frame_rate_index].num * s1->frame_rate_ext.num,
- ff_frame_rate_tab[s->frame_rate_index].den * s1->frame_rate_ext.den,
- 1<<30);
- //mpeg2 aspect
- if(s->aspect_ratio_info > 1){
- if( (s1->pan_scan.width == 0 )||(s1->pan_scan.height == 0) ){
- s->avctx->sample_aspect_ratio=
- av_div_q(
- mpeg2_aspect[s->aspect_ratio_info],
- (AVRational){s->width, s->height}
- );
- }else{
- s->avctx->sample_aspect_ratio=
- av_div_q(
- mpeg2_aspect[s->aspect_ratio_info],
- (AVRational){s1->pan_scan.width, s1->pan_scan.height}
- );
- }
- }else{
- s->avctx->sample_aspect_ratio=
- mpeg2_aspect[s->aspect_ratio_info];
- }
- }//mpeg2
-
- if(avctx->xvmc_acceleration){
- avctx->pix_fmt = avctx->get_format(avctx,pixfmt_xvmc_mpg2_420);
- }else{
- if(s->chroma_format < 2){
- avctx->pix_fmt = avctx->get_format(avctx,pixfmt_yuv_420);
- }else
- if(s->chroma_format == 2){
- avctx->pix_fmt = avctx->get_format(avctx,pixfmt_yuv_422);
- }else
- if(s->chroma_format > 2){
- avctx->pix_fmt = avctx->get_format(avctx,pixfmt_yuv_444);
- }
- }
- //until then pix_fmt may be changed right after codec init
- if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT )
- if( avctx->idct_algo == FF_IDCT_AUTO )
- avctx->idct_algo = FF_IDCT_SIMPLE;
-
- //quantization matrixes may need reordering
- //if dct permutation is changed
- memcpy(old_permutation,s->dsp.idct_permutation,64*sizeof(uint8_t));
-
- if (MPV_common_init(s) < 0)
- return -2;
-
- quant_matrix_rebuild(s->intra_matrix, old_permutation,s->dsp.idct_permutation);
- quant_matrix_rebuild(s->inter_matrix, old_permutation,s->dsp.idct_permutation);
- quant_matrix_rebuild(s->chroma_intra_matrix,old_permutation,s->dsp.idct_permutation);
- quant_matrix_rebuild(s->chroma_inter_matrix,old_permutation,s->dsp.idct_permutation);
-
- s1->mpeg_enc_ctx_allocated = 1;
- }
- return 0;
-}
-
-static int mpeg1_decode_picture(AVCodecContext *avctx,
- const uint8_t *buf, int buf_size)
-{
- Mpeg1Context *s1 = avctx->priv_data;
- 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 */
- s->pict_type = get_bits(&s->gb, 3);
- if(s->pict_type == 0 || s->pict_type > 3)
- return -1;
-
- vbv_delay= get_bits(&s->gb, 16);
- if (s->pict_type == P_TYPE || s->pict_type == B_TYPE) {
- s->full_pel[0] = get_bits1(&s->gb);
- f_code = get_bits(&s->gb, 3);
- if (f_code == 0 && avctx->error_resilience >= FF_ER_COMPLIANT)
- return -1;
- s->mpeg_f_code[0][0] = f_code;
- s->mpeg_f_code[0][1] = f_code;
- }
- if (s->pict_type == B_TYPE) {
- s->full_pel[1] = get_bits1(&s->gb);
- f_code = get_bits(&s->gb, 3);
- if (f_code == 0 && avctx->error_resilience >= FF_ER_COMPLIANT)
- return -1;
- s->mpeg_f_code[1][0] = f_code;
- s->mpeg_f_code[1][1] = f_code;
- }
- s->current_picture.pict_type= s->pict_type;
- s->current_picture.key_frame= s->pict_type == I_TYPE;
-
- if(avctx->debug & FF_DEBUG_PICT_INFO)
- av_log(avctx, AV_LOG_DEBUG, "vbv_delay %d, ref %d type:%d\n", vbv_delay, ref, s->pict_type);
-
- s->y_dc_scale = 8;
- s->c_dc_scale = 8;
- s->first_slice = 1;
- return 0;
-}
-
-static void mpeg_decode_sequence_extension(Mpeg1Context *s1)
-{
- MpegEncContext *s= &s1->mpeg_enc_ctx;
- int horiz_size_ext, vert_size_ext;
- int bit_rate_ext;
-
- skip_bits(&s->gb, 1); /* profil and level esc*/
- s->avctx->profile= get_bits(&s->gb, 3);
- s->avctx->level= get_bits(&s->gb, 4);
- s->progressive_sequence = get_bits1(&s->gb); /* progressive_sequence */
- s->chroma_format = get_bits(&s->gb, 2); /* chroma_format 1=420, 2=422, 3=444 */
- horiz_size_ext = get_bits(&s->gb, 2);
- vert_size_ext = get_bits(&s->gb, 2);
- s->width |= (horiz_size_ext << 12);
- s->height |= (vert_size_ext << 12);
- bit_rate_ext = get_bits(&s->gb, 12); /* XXX: handle it */
- s->bit_rate += (bit_rate_ext << 18) * 400;
- skip_bits1(&s->gb); /* marker */
- s->avctx->rc_buffer_size += get_bits(&s->gb, 8)*1024*16<<10;
-
- s->low_delay = get_bits1(&s->gb);
- if(s->flags & CODEC_FLAG_LOW_DELAY) s->low_delay=1;
-
- s1->frame_rate_ext.num = get_bits(&s->gb, 2)+1;
- s1->frame_rate_ext.den = get_bits(&s->gb, 5)+1;
-
- dprintf("sequence extension\n");
- s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG2VIDEO;
- s->avctx->sub_id = 2; /* indicates mpeg2 found */
-
- if(s->avctx->debug & FF_DEBUG_PICT_INFO)
- av_log(s->avctx, AV_LOG_DEBUG, "profile: %d, level: %d vbv buffer: %d, bitrate:%d\n",
- s->avctx->profile, s->avctx->level, s->avctx->rc_buffer_size, s->bit_rate);
-
-}
-
-static void mpeg_decode_sequence_display_extension(Mpeg1Context *s1)
-{
- MpegEncContext *s= &s1->mpeg_enc_ctx;
- int color_description, w, h;
-
- skip_bits(&s->gb, 3); /* video format */
- color_description= get_bits1(&s->gb);
- if(color_description){
- skip_bits(&s->gb, 8); /* color primaries */
- skip_bits(&s->gb, 8); /* transfer_characteristics */
- skip_bits(&s->gb, 8); /* matrix_coefficients */
- }
- w= get_bits(&s->gb, 14);
- skip_bits(&s->gb, 1); //marker
- h= get_bits(&s->gb, 14);
- skip_bits(&s->gb, 1); //marker
-
- s1->pan_scan.width= 16*w;
- s1->pan_scan.height=16*h;
-
- if(s->avctx->debug & FF_DEBUG_PICT_INFO)
- av_log(s->avctx, AV_LOG_DEBUG, "sde w:%d, h:%d\n", w, h);
-}
-
-static void mpeg_decode_picture_display_extension(Mpeg1Context *s1)
-{
- MpegEncContext *s= &s1->mpeg_enc_ctx;
- int i,nofco;
-
- nofco = 1;
- if(s->progressive_sequence){
- if(s->repeat_first_field){
- nofco++;
- if(s->top_field_first)
- nofco++;
- }
- }else{
- if(s->picture_structure == PICT_FRAME){
- nofco++;
- if(s->repeat_first_field)
- nofco++;
- }
- }
- for(i=0; i<nofco; i++){
- s1->pan_scan.position[i][0]= get_sbits(&s->gb, 16);
- skip_bits(&s->gb, 1); //marker
- s1->pan_scan.position[i][1]= get_sbits(&s->gb, 16);
- skip_bits(&s->gb, 1); //marker
- }
-
- if(s->avctx->debug & FF_DEBUG_PICT_INFO)
- av_log(s->avctx, AV_LOG_DEBUG, "pde (%d,%d) (%d,%d) (%d,%d)\n",
- s1->pan_scan.position[0][0], s1->pan_scan.position[0][1],
- s1->pan_scan.position[1][0], s1->pan_scan.position[1][1],
- s1->pan_scan.position[2][0], s1->pan_scan.position[2][1]
- );
-}
-
-static void mpeg_decode_quant_matrix_extension(MpegEncContext *s)
-{
- int i, v, j;
-
- dprintf("matrix extension\n");
-
- if (get_bits1(&s->gb)) {
- for(i=0;i<64;i++) {
- v = get_bits(&s->gb, 8);
- j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
- s->intra_matrix[j] = v;
- s->chroma_intra_matrix[j] = v;
- }
- }
- if (get_bits1(&s->gb)) {
- for(i=0;i<64;i++) {
- v = get_bits(&s->gb, 8);
- j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
- s->inter_matrix[j] = v;
- s->chroma_inter_matrix[j] = v;
- }
- }
- if (get_bits1(&s->gb)) {
- for(i=0;i<64;i++) {
- v = get_bits(&s->gb, 8);
- j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
- s->chroma_intra_matrix[j] = v;
- }
- }
- if (get_bits1(&s->gb)) {
- for(i=0;i<64;i++) {
- v = get_bits(&s->gb, 8);
- j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
- s->chroma_inter_matrix[j] = v;
- }
- }
-}
-
-static void mpeg_decode_picture_coding_extension(MpegEncContext *s)
-{
- s->full_pel[0] = s->full_pel[1] = 0;
- s->mpeg_f_code[0][0] = get_bits(&s->gb, 4);
- s->mpeg_f_code[0][1] = get_bits(&s->gb, 4);
- s->mpeg_f_code[1][0] = get_bits(&s->gb, 4);
- s->mpeg_f_code[1][1] = get_bits(&s->gb, 4);
- s->intra_dc_precision = get_bits(&s->gb, 2);
- s->picture_structure = get_bits(&s->gb, 2);
- s->top_field_first = get_bits1(&s->gb);
- s->frame_pred_frame_dct = get_bits1(&s->gb);
- s->concealment_motion_vectors = get_bits1(&s->gb);
- s->q_scale_type = get_bits1(&s->gb);
- s->intra_vlc_format = get_bits1(&s->gb);
- s->alternate_scan = get_bits1(&s->gb);
- s->repeat_first_field = get_bits1(&s->gb);
- s->chroma_420_type = get_bits1(&s->gb);
- s->progressive_frame = get_bits1(&s->gb);
-
- if(s->picture_structure == PICT_FRAME){
- s->first_field=0;
- s->v_edge_pos= 16*s->mb_height;
- }else{
- s->first_field ^= 1;
- s->v_edge_pos= 8*s->mb_height;
- memset(s->mbskip_table, 0, s->mb_stride*s->mb_height);
- }
-
- if(s->alternate_scan){
- ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_alternate_vertical_scan);
- ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_alternate_vertical_scan);
- }else{
- ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_zigzag_direct);
- ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_zigzag_direct);
- }
-
- /* composite display not parsed */
- dprintf("intra_dc_precision=%d\n", s->intra_dc_precision);
- dprintf("picture_structure=%d\n", s->picture_structure);
- dprintf("top field first=%d\n", s->top_field_first);
- dprintf("repeat first field=%d\n", s->repeat_first_field);
- dprintf("conceal=%d\n", s->concealment_motion_vectors);
- dprintf("intra_vlc_format=%d\n", s->intra_vlc_format);
- dprintf("alternate_scan=%d\n", s->alternate_scan);
- dprintf("frame_pred_frame_dct=%d\n", s->frame_pred_frame_dct);
- dprintf("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(s);
- break;
- }
-}
-
-static void exchange_uv(MpegEncContext *s){
- short * tmp = s->pblocks[4];
- s->pblocks[4] = s->pblocks[5];
- s->pblocks[5] = tmp;
-}
-
-static int mpeg_field_start(MpegEncContext *s){
- AVCodecContext *avctx= s->avctx;
- Mpeg1Context *s1 = (Mpeg1Context*)s;
-
- /* start frame decoding */
- if(s->first_field || s->picture_structure==PICT_FRAME){
- if(MPV_frame_start(s, avctx) < 0)
- return -1;
-
- ff_er_frame_start(s);
-
- /* first check if we must repeat the frame */
- s->current_picture_ptr->repeat_pict = 0;
- if (s->repeat_first_field) {
- if (s->progressive_sequence) {
- if (s->top_field_first)
- s->current_picture_ptr->repeat_pict = 4;
- else
- s->current_picture_ptr->repeat_pict = 2;
- } else if (s->progressive_frame) {
- s->current_picture_ptr->repeat_pict = 1;
- }
- }
-
- *s->current_picture_ptr->pan_scan= s1->pan_scan;
- }else{ //second field
- int i;
-
- if(!s->current_picture_ptr){
- av_log(s->avctx, AV_LOG_ERROR, "first field missing\n");
- return -1;
- }
-
- for(i=0; i<4; i++){
- s->current_picture.data[i] = s->current_picture_ptr->data[i];
- if(s->picture_structure == PICT_BOTTOM_FIELD){
- s->current_picture.data[i] += s->current_picture_ptr->linesize[i];
- }
- }
- }
-#ifdef HAVE_XVMC
-// MPV_frame_start will call this function too,
-// but we need to call it on every field
- if(s->avctx->xvmc_acceleration)
- XVMC_field_start(s,avctx);
-#endif
-
- return 0;
-}
-
-#define DECODE_SLICE_ERROR -1
-#define DECODE_SLICE_OK 0
-
-/**
- * decodes a slice. MpegEncContext.mb_y must be set to the MB row from the startcode
- * @return DECODE_SLICE_ERROR if the slice is damaged<br>
- * DECODE_SLICE_OK if this slice is ok<br>
- */
-static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y,
- const uint8_t **buf, int buf_size)
-{
- MpegEncContext *s = &s1->mpeg_enc_ctx;
- AVCodecContext *avctx= s->avctx;
- int ret;
- const int field_pic= s->picture_structure != PICT_FRAME;
- const int lowres= s->avctx->lowres;
-
- s->resync_mb_x=
- s->resync_mb_y= -1;
-
- if (mb_y<<field_pic >= s->mb_height){
- av_log(s->avctx, AV_LOG_ERROR, "slice below image (%d >= %d)\n", mb_y, s->mb_height);
- return -1;
- }
-
- init_get_bits(&s->gb, *buf, buf_size*8);
-
- ff_mpeg1_clean_buffers(s);
- s->interlaced_dct = 0;
-
- s->qscale = get_qscale(s);
-
- if(s->qscale == 0){
- av_log(s->avctx, AV_LOG_ERROR, "qscale == 0\n");
- return -1;
- }
-
- /* extra slice info */
- while (get_bits1(&s->gb) != 0) {
- skip_bits(&s->gb, 8);
- }
-
- s->mb_x=0;
-
- 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;
- }
- }
-
- s->resync_mb_x= s->mb_x;
- s->resync_mb_y= s->mb_y= mb_y;
- s->mb_skip_run= 0;
- ff_init_block_index(s);
-
- if (s->mb_y==0 && s->mb_x==0 && (s->first_field || s->picture_structure==PICT_FRAME)) {
- if(s->avctx->debug&FF_DEBUG_PICT_INFO){
- av_log(s->avctx, AV_LOG_DEBUG, "qp:%d fc:%2d%2d%2d%2d %s %s %s %s %s dc:%d pstruct:%d fdct:%d cmv:%d qtype:%d ivlc:%d rff:%d %s\n",
- s->qscale, s->mpeg_f_code[0][0],s->mpeg_f_code[0][1],s->mpeg_f_code[1][0],s->mpeg_f_code[1][1],
- s->pict_type == I_TYPE ? "I" : (s->pict_type == P_TYPE ? "P" : (s->pict_type == B_TYPE ? "B" : "S")),
- s->progressive_sequence ? "ps" :"", s->progressive_frame ? "pf" : "", s->alternate_scan ? "alt" :"", s->top_field_first ? "top" :"",
- s->intra_dc_precision, s->picture_structure, s->frame_pred_frame_dct, s->concealment_motion_vectors,
- s->q_scale_type, s->intra_vlc_format, s->repeat_first_field, s->chroma_420_type ? "420" :"");
- }
- }
-
- for(;;) {
-#ifdef HAVE_XVMC
- //one 1 we memcpy blocks in xvmcvideo
- if(s->avctx->xvmc_acceleration > 1)
- XVMC_init_block(s);//set s->block
-#endif
-
- ret = mpeg_decode_mb(s, s->block);
- s->chroma_qscale= s->qscale;
-
- dprintf("ret=%d\n", ret);
- if (ret < 0)
- return -1;
-
- if(s->current_picture.motion_val[0] && !s->encoding){ //note motion_val is normally NULL unless we want to extract the MVs
- const int wrap = field_pic ? 2*s->b8_stride : s->b8_stride;
- int xy = s->mb_x*2 + s->mb_y*2*wrap;
- 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++){
- if (s->mb_intra || (dir==1 && s->pict_type != B_TYPE)) {
- motion_x = motion_y = 0;
- }else if (s->mv_type == MV_TYPE_16X16 || (s->mv_type == MV_TYPE_FIELD && field_pic)){
- motion_x = s->mv[dir][0][0];
- motion_y = s->mv[dir][0][1];
- } else /*if ((s->mv_type == MV_TYPE_FIELD) || (s->mv_type == MV_TYPE_16X8))*/ {
- motion_x = s->mv[dir][i][0];
- motion_y = s->mv[dir][i][1];
- }
-
- s->current_picture.motion_val[dir][xy ][0] = motion_x;
- s->current_picture.motion_val[dir][xy ][1] = motion_y;
- s->current_picture.motion_val[dir][xy + 1][0] = motion_x;
- s->current_picture.motion_val[dir][xy + 1][1] = motion_y;
- s->current_picture.ref_index [dir][xy ]=
- s->current_picture.ref_index [dir][xy + 1]= s->field_select[dir][i];
- assert(s->field_select[dir][i]==0 || s->field_select[dir][i]==1);
- }
- xy += wrap;
- }
- }
-
- s->dest[0] += 16 >> lowres;
- s->dest[1] += 16 >> (s->chroma_x_shift + lowres);
- s->dest[2] += 16 >> (s->chroma_x_shift + lowres);
-
- MPV_decode_mb(s, s->block);
-
- 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);
-
- s->mb_x = 0;
- s->mb_y++;
-
- if(s->mb_y<<field_pic >= s->mb_height){
- int left= s->gb.size_in_bits - get_bits_count(&s->gb);
- int is_d10= s->chroma_format==2 && s->pict_type==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*/;
-
- if(left < 0 || (left && show_bits(&s->gb, FFMIN(left, 23)) && !is_d10)
- || (avctx->error_resilience >= FF_ER_AGGRESSIVE && left>8)){
- av_log(avctx, AV_LOG_ERROR, "end mismatch left=%d %0X\n", left, show_bits(&s->gb, FFMIN(left, 23)));
- return -1;
- }else
- goto eos;
- }
-
- ff_init_block_index(s);
- }
-
- /* skip mb handling */
- if (s->mb_skip_run == -1) {
- /* read again increment */
- s->mb_skip_run = 0;
- for(;;) {
- int code = get_vlc2(&s->gb, mbincr_vlc.table, MBINCR_VLC_BITS, 2);
- if (code < 0){
- av_log(s->avctx, AV_LOG_ERROR, "mb incr damaged\n");
- return -1;
- }
- if (code >= 33) {
- if (code == 33) {
- s->mb_skip_run += 33;
- }else if(code == 35){
- if(s->mb_skip_run != 0 || show_bits(&s->gb, 15) != 0){
- av_log(s->avctx, AV_LOG_ERROR, "slice mismatch\n");
- return -1;
- }
- goto eos; /* end of slice */
- }
- /* otherwise, stuffing, nothing to do */
- } else {
- s->mb_skip_run += code;
- break;
- }
- }
- }
- }
-eos: // end of slice
- *buf += get_bits_count(&s->gb)/8 - 1;
-//printf("y %d %d %d %d\n", s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y);
- return 0;
-}
-
-static int slice_decode_thread(AVCodecContext *c, void *arg){
- MpegEncContext *s= arg;
- const uint8_t *buf= s->gb.buffer;
- int mb_y= s->start_mb_y;
-
- s->error_count= 3*(s->end_mb_y - s->start_mb_y)*s->mb_width;
-
- for(;;){
- uint32_t start_code;
- int ret;
-
- ret= mpeg_decode_slice((Mpeg1Context*)s, mb_y, &buf, s->gb.buffer_end - buf);
- emms_c();
-//av_log(c, AV_LOG_DEBUG, "ret:%d resync:%d/%d mb:%d/%d ts:%d/%d ec:%d\n",
-//ret, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, s->start_mb_y, s->end_mb_y, s->error_count);
- if(ret < 0){
- if(s->resync_mb_x>=0 && s->resync_mb_y>=0)
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, AC_ERROR|DC_ERROR|MV_ERROR);
- }else{
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, AC_END|DC_END|MV_END);
- }
-
- if(s->mb_y == s->end_mb_y)
- return 0;
-
- start_code= -1;
- buf = ff_find_start_code(buf, s->gb.buffer_end, &start_code);
- mb_y= start_code - SLICE_MIN_START_CODE;
- if(mb_y < 0 || mb_y >= s->end_mb_y)
- return -1;
- }
-
- return 0; //not reached
-}
-
-/**
- * handles slice ends.
- * @return 1 if it seems to be the last slice of
- */
-static int slice_end(AVCodecContext *avctx, AVFrame *pict)
-{
- Mpeg1Context *s1 = avctx->priv_data;
- MpegEncContext *s = &s1->mpeg_enc_ctx;
-
- if (!s1->mpeg_enc_ctx_allocated || !s->current_picture_ptr)
- return 0;
-
-#ifdef HAVE_XVMC
- if(s->avctx->xvmc_acceleration)
- XVMC_field_end(s);
-#endif
- /* end of slice reached */
- if (/*s->mb_y<<field_pic == s->mb_height &&*/ !s->first_field) {
- /* end of image */
-
- s->current_picture_ptr->qscale_type= FF_QSCALE_TYPE_MPEG2;
-
- ff_er_frame_end(s);
-
- MPV_frame_end(s);
-
- if (s->pict_type == B_TYPE || s->low_delay) {
- *pict= *(AVFrame*)s->current_picture_ptr;
- ff_print_debug_info(s, pict);
- } else {
- s->picture_number++;
- /* latency of 1 frame for I and P frames */
- /* XXX: use another variable than picture_number */
- if (s->last_picture_ptr != NULL) {
- *pict= *(AVFrame*)s->last_picture_ptr;
- ff_print_debug_info(s, pict);
- }
- }
-
- return 1;
- } else {
- return 0;
- }
-}
-
-static int mpeg1_decode_sequence(AVCodecContext *avctx,
- const uint8_t *buf, int buf_size)
-{
- Mpeg1Context *s1 = avctx->priv_data;
- MpegEncContext *s = &s1->mpeg_enc_ctx;
- int width,height;
- int i, v, j;
-
- init_get_bits(&s->gb, buf, buf_size*8);
-
- width = get_bits(&s->gb, 12);
- height = get_bits(&s->gb, 12);
- if (width <= 0 || height <= 0 ||
- (width % 2) != 0 || (height % 2) != 0)
- return -1;
- s->aspect_ratio_info= get_bits(&s->gb, 4);
- if (s->aspect_ratio_info == 0)
- return -1;
- s->frame_rate_index = get_bits(&s->gb, 4);
- if (s->frame_rate_index == 0 || s->frame_rate_index > 13)
- return -1;
- s->bit_rate = get_bits(&s->gb, 18) * 400;
- if (get_bits1(&s->gb) == 0) /* marker */
- return -1;
- s->width = width;
- s->height = height;
-
- s->avctx->rc_buffer_size= get_bits(&s->gb, 10) * 1024*16;
- skip_bits(&s->gb, 1);
-
- /* get matrix */
- if (get_bits1(&s->gb)) {
- for(i=0;i<64;i++) {
- v = get_bits(&s->gb, 8);
- if(v==0){
- av_log(s->avctx, AV_LOG_ERROR, "intra matrix damaged\n");
- return -1;
- }
- j = s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
- s->intra_matrix[j] = v;
- s->chroma_intra_matrix[j] = v;
- }
-#ifdef DEBUG
- dprintf("intra matrix present\n");
- for(i=0;i<64;i++)
- dprintf(" %d", s->intra_matrix[s->dsp.idct_permutation[i]]);
- dprintf("\n");
-#endif
- } else {
- for(i=0;i<64;i++) {
- j = s->dsp.idct_permutation[i];
- v = ff_mpeg1_default_intra_matrix[i];
- s->intra_matrix[j] = v;
- s->chroma_intra_matrix[j] = v;
- }
- }
- if (get_bits1(&s->gb)) {
- for(i=0;i<64;i++) {
- v = get_bits(&s->gb, 8);
- if(v==0){
- av_log(s->avctx, AV_LOG_ERROR, "inter matrix damaged\n");
- return -1;
- }
- j = s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
- s->inter_matrix[j] = v;
- s->chroma_inter_matrix[j] = v;
- }
-#ifdef DEBUG
- dprintf("non intra matrix present\n");
- for(i=0;i<64;i++)
- dprintf(" %d", s->inter_matrix[s->dsp.idct_permutation[i]]);
- dprintf("\n");
-#endif
- } else {
- for(i=0;i<64;i++) {
- int j= s->dsp.idct_permutation[i];
- v = ff_mpeg1_default_non_intra_matrix[i];
- s->inter_matrix[j] = v;
- s->chroma_inter_matrix[j] = v;
- }
- }
-
- if(show_bits(&s->gb, 23) != 0){
- av_log(s->avctx, AV_LOG_ERROR, "sequence header damaged\n");
- return -1;
- }
-
- /* we set mpeg2 parameters so that it emulates mpeg1 */
- s->progressive_sequence = 1;
- s->progressive_frame = 1;
- s->picture_structure = PICT_FRAME;
- s->frame_pred_frame_dct = 1;
- s->chroma_format = 1;
- s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG1VIDEO;
- avctx->sub_id = 1; /* indicates mpeg1 */
- s->out_format = FMT_MPEG1;
- s->swap_uv = 0;//AFAIK VCR2 don't have SEQ_HEADER
- if(s->flags & CODEC_FLAG_LOW_DELAY) s->low_delay=1;
-
- if(s->avctx->debug & FF_DEBUG_PICT_INFO)
- av_log(s->avctx, AV_LOG_DEBUG, "vbv buffer: %d, bitrate:%d\n",
- s->avctx->rc_buffer_size, s->bit_rate);
-
- return 0;
-}
-
-static int vcr2_init_sequence(AVCodecContext *avctx)
-{
- Mpeg1Context *s1 = avctx->priv_data;
- MpegEncContext *s = &s1->mpeg_enc_ctx;
- int i, v;
-
- /* start new mpeg1 context decoding */
- s->out_format = FMT_MPEG1;
- if (s1->mpeg_enc_ctx_allocated) {
- MPV_common_end(s);
- }
- s->width = avctx->coded_width;
- s->height = avctx->coded_height;
- avctx->has_b_frames= 0; //true?
- s->low_delay= 1;
-
- if(avctx->xvmc_acceleration){
- avctx->pix_fmt = avctx->get_format(avctx,pixfmt_xvmc_mpg2_420);
- }else{
- avctx->pix_fmt = avctx->get_format(avctx,pixfmt_yuv_420);
- }
-
- if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT )
- if( avctx->idct_algo == FF_IDCT_AUTO )
- avctx->idct_algo = FF_IDCT_SIMPLE;
-
- if (MPV_common_init(s) < 0)
- return -1;
- exchange_uv(s);//common init reset pblocks, so we swap them here
- s->swap_uv = 1;// in case of xvmc we need to swap uv for each MB
- s1->mpeg_enc_ctx_allocated = 1;
-
- for(i=0;i<64;i++) {
- int j= s->dsp.idct_permutation[i];
- v = ff_mpeg1_default_intra_matrix[i];
- s->intra_matrix[j] = v;
- s->chroma_intra_matrix[j] = v;
-
- v = ff_mpeg1_default_non_intra_matrix[i];
- s->inter_matrix[j] = v;
- s->chroma_inter_matrix[j] = v;
- }
-
- s->progressive_sequence = 1;
- s->progressive_frame = 1;
- s->picture_structure = PICT_FRAME;
- s->frame_pred_frame_dct = 1;
- s->chroma_format = 1;
- s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG2VIDEO;
- avctx->sub_id = 2; /* indicates mpeg2 */
- return 0;
-}
-
-
-static void mpeg_decode_user_data(AVCodecContext *avctx,
- const uint8_t *buf, int buf_size)
-{
- const uint8_t *p;
- int len, flags;
- p = buf;
- len = buf_size;
-
- /* we parse the DTG active format information */
- if (len >= 5 &&
- p[0] == 'D' && p[1] == 'T' && p[2] == 'G' && p[3] == '1') {
- 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)
- return;
- avctx->dtg_active_format = p[0] & 0x0f;
- }
- }
-}
-
-static void mpeg_decode_gop(AVCodecContext *avctx,
- const uint8_t *buf, int buf_size){
- Mpeg1Context *s1 = avctx->priv_data;
- MpegEncContext *s = &s1->mpeg_enc_ctx;
-
- int drop_frame_flag;
- int time_code_hours, time_code_minutes;
- int time_code_seconds, time_code_pictures;
- int broken_link;
-
- init_get_bits(&s->gb, buf, buf_size*8);
-
- drop_frame_flag = get_bits1(&s->gb);
-
- time_code_hours=get_bits(&s->gb,5);
- time_code_minutes = get_bits(&s->gb,6);
- skip_bits1(&s->gb);//marker bit
- time_code_seconds = get_bits(&s->gb,6);
- time_code_pictures = get_bits(&s->gb,6);
-
- /*broken_link indicate that after editing the
- reference frames of the first B-Frames after GOP I-Frame
- are missing (open gop)*/
- broken_link = get_bits1(&s->gb);
-
- if(s->avctx->debug & FF_DEBUG_PICT_INFO)
- av_log(s->avctx, AV_LOG_DEBUG, "GOP (%2d:%02d:%02d.[%02d]) broken_link=%d\n",
- time_code_hours, time_code_minutes, time_code_seconds,
- time_code_pictures, broken_link);
-}
-/**
- * finds the end of the current frame in the bitstream.
- * @return the position of the first byte of the next frame, or -1
- */
-static int mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size)
-{
- int i;
- uint32_t state= pc->state;
-
- i=0;
- if(!pc->frame_start_found){
- for(i=0; i<buf_size; i++){
- i= ff_find_start_code(buf+i, buf+buf_size, &state) - buf - 1;
- if(state >= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE){
- i++;
- pc->frame_start_found=1;
- break;
- }
- }
- }
-
- if(pc->frame_start_found){
- /* EOF considered as end of frame */
- if (buf_size == 0)
- return 0;
- for(; i<buf_size; i++){
- i= ff_find_start_code(buf+i, buf+buf_size, &state) - buf - 1;
- if((state&0xFFFFFF00) == 0x100){
- if(state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE){
- pc->frame_start_found=0;
- pc->state=-1;
- return i-3;
- }
- }
- }
- }
- pc->state= state;
- return END_NOT_FOUND;
-}
-
-/* handle buffering and image synchronisation */
-static int mpeg_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- Mpeg1Context *s = avctx->priv_data;
- const uint8_t *buf_end;
- const uint8_t *buf_ptr;
- uint32_t start_code;
- int ret, input_size;
- AVFrame *picture = data;
- MpegEncContext *s2 = &s->mpeg_enc_ctx;
- dprintf("fill_buffer\n");
-
- if (buf_size == 0) {
- /* special case for last picture */
- if (s2->low_delay==0 && s2->next_picture_ptr) {
- *picture= *(AVFrame*)s2->next_picture_ptr;
- s2->next_picture_ptr= NULL;
-
- *data_size = sizeof(AVFrame);
- }
- return 0;
- }
-
- if(s2->flags&CODEC_FLAG_TRUNCATED){
- int next= mpeg1_find_frame_end(&s2->parse_context, buf, buf_size);
-
- if( ff_combine_frame(&s2->parse_context, next, &buf, &buf_size) < 0 )
- return buf_size;
- }
-
- buf_ptr = buf;
- buf_end = buf + buf_size;
-
-#if 0
- if (s->repeat_field % 2 == 1) {
- s->repeat_field++;
- //fprintf(stderr,"\nRepeating last frame: %d -> %d! pict: %d %d", avctx->frame_number-1, avctx->frame_number,
- // s2->picture_number, s->repeat_field);
- if (avctx->flags & CODEC_FLAG_REPEAT_FIELD) {
- *data_size = sizeof(AVPicture);
- goto the_end;
- }
- }
-#endif
-
- if(s->mpeg_enc_ctx_allocated==0 && avctx->codec_tag == ff_get_fourcc("VCR2"))
- vcr2_init_sequence(avctx);
-
- s->slice_count= 0;
-
- for(;;) {
- /* find start next code */
- start_code = -1;
- buf_ptr = ff_find_start_code(buf_ptr,buf_end, &start_code);
- if (start_code > 0x1ff){
- if(s2->pict_type != B_TYPE || avctx->skip_frame <= AVDISCARD_DEFAULT){
- if(avctx->thread_count > 1){
- int i;
-
- avctx->execute(avctx, slice_decode_thread, (void**)&(s2->thread_context[0]), NULL, s->slice_count);
- for(i=0; i<s->slice_count; i++)
- s2->error_count += s2->thread_context[i]->error_count;
- }
- if (slice_end(avctx, picture)) {
- if(s2->last_picture_ptr || s2->low_delay) //FIXME merge with the stuff in mpeg_decode_slice
- *data_size = sizeof(AVPicture);
- }
- }
- return FFMAX(0, buf_ptr - buf - s2->parse_context.last_index);
- }
-
- input_size = buf_end - buf_ptr;
-
- if(avctx->debug & FF_DEBUG_STARTCODE){
- av_log(avctx, AV_LOG_DEBUG, "%3X at %zd left %d\n", start_code, buf_ptr-buf, input_size);
- }
-
- /* prepare data for next start code */
- switch(start_code) {
- case SEQ_START_CODE:
- mpeg1_decode_sequence(avctx, buf_ptr,
- input_size);
- break;
-
- case PICTURE_START_CODE:
- /* we have a complete image : we try to decompress it */
- mpeg1_decode_picture(avctx,
- buf_ptr, input_size);
- break;
- case EXT_START_CODE:
- mpeg_decode_extension(avctx,
- buf_ptr, input_size);
- break;
- case USER_START_CODE:
- mpeg_decode_user_data(avctx,
- buf_ptr, input_size);
- break;
- case GOP_START_CODE:
- s2->first_field=0;
- mpeg_decode_gop(avctx,
- buf_ptr, input_size);
- break;
- default:
- if (start_code >= SLICE_MIN_START_CODE &&
- start_code <= SLICE_MAX_START_CODE) {
- int mb_y= start_code - SLICE_MIN_START_CODE;
-
- if(s2->last_picture_ptr==NULL){
- /* skip b frames if we dont have reference frames */
- if(s2->pict_type==B_TYPE) break;
- /* skip P frames if we dont have reference frame no valid header */
-// if(s2->pict_type==P_TYPE && s2->first_field && !s2->first_slice) break;
- }
- /* skip b frames if we are in a hurry */
- if(avctx->hurry_up && s2->pict_type==B_TYPE) break;
- if( (avctx->skip_frame >= AVDISCARD_NONREF && s2->pict_type==B_TYPE)
- ||(avctx->skip_frame >= AVDISCARD_NONKEY && s2->pict_type!=I_TYPE)
- || avctx->skip_frame >= AVDISCARD_ALL)
- break;
- /* skip everything if we are in a hurry>=5 */
- if(avctx->hurry_up>=5) break;
-
- if (!s->mpeg_enc_ctx_allocated) break;
-
- if(s2->codec_id == CODEC_ID_MPEG2VIDEO){
- if(mb_y < avctx->skip_top || mb_y >= s2->mb_height - avctx->skip_bottom)
- break;
- }
-
- if(s2->first_slice){
- s2->first_slice=0;
- if(mpeg_field_start(s2) < 0)
- return -1;
- }
- if(!s2->current_picture_ptr){
- av_log(avctx, AV_LOG_ERROR, "current_picture not initalized\n");
- return -1;
- }
-
- if(avctx->thread_count > 1){
- int threshold= (s2->mb_height*s->slice_count + avctx->thread_count/2) / avctx->thread_count;
- if(threshold <= mb_y){
- MpegEncContext *thread_context= s2->thread_context[s->slice_count];
-
- thread_context->start_mb_y= mb_y;
- thread_context->end_mb_y = s2->mb_height;
- if(s->slice_count){
- s2->thread_context[s->slice_count-1]->end_mb_y= mb_y;
- ff_update_duplicate_context(thread_context, s2);
- }
- init_get_bits(&thread_context->gb, buf_ptr, input_size*8);
- s->slice_count++;
- }
- buf_ptr += 2; //FIXME add minimum num of bytes per slice
- }else{
- ret = mpeg_decode_slice(s, mb_y, &buf_ptr, input_size);
- emms_c();
-
- if(ret < 0){
- if(s2->resync_mb_x>=0 && s2->resync_mb_y>=0)
- ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x, s2->mb_y, AC_ERROR|DC_ERROR|MV_ERROR);
- }else{
- ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x-1, s2->mb_y, AC_END|DC_END|MV_END);
- }
- }
- }
- break;
- }
- }
-}
-
-static int mpeg_decode_end(AVCodecContext *avctx)
-{
- Mpeg1Context *s = avctx->priv_data;
-
- if (s->mpeg_enc_ctx_allocated)
- MPV_common_end(&s->mpeg_enc_ctx);
- return 0;
-}
-
-AVCodec mpeg1video_decoder = {
- "mpeg1video",
- CODEC_TYPE_VIDEO,
- CODEC_ID_MPEG1VIDEO,
- sizeof(Mpeg1Context),
- mpeg_decode_init,
- NULL,
- mpeg_decode_end,
- mpeg_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY,
- .flush= ff_mpeg_flush,
-};
-
-AVCodec mpeg2video_decoder = {
- "mpeg2video",
- CODEC_TYPE_VIDEO,
- CODEC_ID_MPEG2VIDEO,
- sizeof(Mpeg1Context),
- mpeg_decode_init,
- NULL,
- mpeg_decode_end,
- mpeg_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY,
- .flush= ff_mpeg_flush,
-};
-
-//legacy decoder
-AVCodec mpegvideo_decoder = {
- "mpegvideo",
- CODEC_TYPE_VIDEO,
- CODEC_ID_MPEG2VIDEO,
- sizeof(Mpeg1Context),
- mpeg_decode_init,
- NULL,
- mpeg_decode_end,
- mpeg_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY,
- .flush= ff_mpeg_flush,
-};
-
-#ifdef CONFIG_ENCODERS
-
-AVCodec mpeg1video_encoder = {
- "mpeg1video",
- CODEC_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, -1},
- .capabilities= CODEC_CAP_DELAY,
-};
-
-AVCodec mpeg2video_encoder = {
- "mpeg2video",
- CODEC_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, -1},
- .capabilities= CODEC_CAP_DELAY,
-};
-#endif
-
-#ifdef HAVE_XVMC
-static int mpeg_mc_decode_init(AVCodecContext *avctx){
- Mpeg1Context *s;
-
- if( avctx->thread_count > 1)
- return -1;
- if( !(avctx->slice_flags & SLICE_FLAG_CODED_ORDER) )
- return -1;
- if( !(avctx->slice_flags & SLICE_FLAG_ALLOW_FIELD) ){
- dprintf("mpeg12.c: XvMC decoder will work better if SLICE_FLAG_ALLOW_FIELD is set\n");
- }
- mpeg_decode_init(avctx);
- s = avctx->priv_data;
-
- avctx->pix_fmt = PIX_FMT_XVMC_MPEG2_IDCT;
- avctx->xvmc_acceleration = 2;//2 - the blocks are packed!
-
- return 0;
-}
-
-AVCodec mpeg_xvmc_decoder = {
- "mpegvideo_xvmc",
- CODEC_TYPE_VIDEO,
- CODEC_ID_MPEG2VIDEO_XVMC,
- sizeof(Mpeg1Context),
- mpeg_mc_decode_init,
- NULL,
- mpeg_decode_end,
- mpeg_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED| CODEC_CAP_HWACCEL | CODEC_CAP_DELAY,
- .flush= ff_mpeg_flush,
-};
-
-#endif
-
-#ifdef CONFIG_MPEGVIDEO_PARSER
-static void mpegvideo_extract_headers(AVCodecParserContext *s,
- AVCodecContext *avctx,
- const uint8_t *buf, int buf_size)
-{
- ParseContext1 *pc = s->priv_data;
- const uint8_t *buf_end;
- 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;
-//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);
- bytes_left = buf_end - buf;
- switch(start_code) {
- case PICTURE_START_CODE:
- if (bytes_left >= 2) {
- s->pict_type = (buf[1] >> 3) & 7;
- }
- break;
- case SEQ_START_CODE:
- 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);
- 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;
- avctx->bit_rate = ((buf[4]<<10) | (buf[5]<<2) | (buf[6]>>6))*400;
- avctx->codec_id = CODEC_ID_MPEG1VIDEO;
- avctx->sub_id = 1;
- }
- break;
- case EXT_START_CODE:
- if (bytes_left >= 1) {
- ext_type = (buf[0] >> 4);
- switch(ext_type) {
- case 0x1: /* sequence extension */
- if (bytes_left >= 6) {
- horiz_size_ext = ((buf[1] & 1) << 1) | (buf[2] >> 7);
- vert_size_ext = (buf[2] >> 5) & 3;
- bit_rate_ext = ((buf[2] & 0x1F)<<7) | (buf[3]>>1);
- frame_rate_ext_n = (buf[5] >> 5) & 3;
- frame_rate_ext_d = (buf[5] & 0x1f);
- pc->progressive_sequence = buf[1] & (1 << 3);
- avctx->has_b_frames= !(buf[5] >> 7);
-
- 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);
- avctx->time_base.den = pc->frame_rate.den * (frame_rate_ext_n + 1);
- avctx->time_base.num = pc->frame_rate.num * (frame_rate_ext_d + 1);
- avctx->codec_id = CODEC_ID_MPEG2VIDEO;
- avctx->sub_id = 2; /* forces MPEG2 */
- }
- break;
- case 0x8: /* picture coding extension */
- if (bytes_left >= 5) {
- picture_structure = buf[2]&3;
- top_field_first = buf[3] & (1 << 7);
- repeat_first_field = buf[3] & (1 << 1);
- progressive_frame = buf[4] & (1 << 7);
-
- /* check if we must repeat the frame */
- if (repeat_first_field) {
- if (pc->progressive_sequence) {
- if (top_field_first)
- s->repeat_pict = 4;
- else
- s->repeat_pict = 2;
- } else if (progressive_frame) {
- s->repeat_pict = 1;
- }
- }
-
- /* the packet only represents half a frame
- XXX,FIXME maybe find a different solution */
- if(picture_structure != 3)
- s->repeat_pict = -1;
- }
- break;
- }
- }
- break;
- case -1:
- goto the_end;
- default:
- /* we stop parsing when we encounter a slice. It ensures
- that this function takes a negligible amount of time */
- if (start_code >= SLICE_MIN_START_CODE &&
- start_code <= SLICE_MAX_START_CODE)
- goto the_end;
- break;
- }
- }
- the_end: ;
-}
-
-static int mpegvideo_parse(AVCodecParserContext *s,
- AVCodecContext *avctx,
- uint8_t **poutbuf, int *poutbuf_size,
- const uint8_t *buf, int buf_size)
-{
- ParseContext1 *pc1 = s->priv_data;
- ParseContext *pc= &pc1->pc;
- int next;
-
- if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){
- next= buf_size;
- }else{
- next= mpeg1_find_frame_end(pc, buf, buf_size);
-
- if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
- *poutbuf = NULL;
- *poutbuf_size = 0;
- return buf_size;
- }
-
- }
- /* we have a full frame : we just parse the first few MPEG headers
- to have the full timing information. The time take by this
- function should be negligible for uncorrupted streams */
- mpegvideo_extract_headers(s, avctx, buf, buf_size);
-#if 0
- printf("pict_type=%d frame_rate=%0.3f repeat_pict=%d\n",
- s->pict_type, (double)avctx->time_base.den / avctx->time_base.num, s->repeat_pict);
-#endif
-
- *poutbuf = (uint8_t *)buf;
- *poutbuf_size = buf_size;
- return next;
-}
-
-static int mpegvideo_split(AVCodecContext *avctx,
- const uint8_t *buf, int buf_size)
-{
- int i;
- uint32_t state= -1;
-
- for(i=0; i<buf_size; i++){
- state= (state<<8) | buf[i];
- if(state != 0x1B3 && state != 0x1B5 && state < 0x200 && state >= 0x100)
- return i-3;
- }
- return 0;
-}
-
-AVCodecParser mpegvideo_parser = {
- { CODEC_ID_MPEG1VIDEO, CODEC_ID_MPEG2VIDEO },
- sizeof(ParseContext1),
- NULL,
- mpegvideo_parse,
- ff_parse1_close,
- mpegvideo_split,
-};
-#endif /* !CONFIG_MPEGVIDEO_PARSER */
-
-/* this is ugly i know, but the alternative is too make
- hundreds of vars global and prefix them with ff_mpeg1_
- which is far uglier. */
-#include "mdec.c"
diff --git a/src/libffmpeg/libavcodec/mpeg12data.h b/src/libffmpeg/libavcodec/mpeg12data.h
deleted file mode 100644
index 6c96a495b..000000000
--- a/src/libffmpeg/libavcodec/mpeg12data.h
+++ /dev/null
@@ -1,469 +0,0 @@
-/*
- * MPEG1 codec / MPEG2 decoder
- * copyright (c) 2000,2001 Fabrice Bellard
- * copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/**
- * @file mpeg12data.h
- * MPEG1/2 tables.
- */
-
-const uint16_t ff_mpeg1_default_intra_matrix[64] = {
- 8, 16, 19, 22, 26, 27, 29, 34,
- 16, 16, 22, 24, 27, 29, 34, 37,
- 19, 22, 26, 27, 29, 34, 34, 38,
- 22, 22, 26, 27, 29, 34, 37, 40,
- 22, 26, 27, 29, 32, 35, 40, 48,
- 26, 27, 29, 32, 35, 40, 48, 58,
- 26, 27, 29, 34, 38, 46, 56, 69,
- 27, 29, 35, 38, 46, 56, 69, 83
-};
-
-const uint16_t ff_mpeg1_default_non_intra_matrix[64] = {
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
-};
-
-static const uint16_t vlc_dc_lum_code[12] = {
- 0x4, 0x0, 0x1, 0x5, 0x6, 0xe, 0x1e, 0x3e, 0x7e, 0xfe, 0x1fe, 0x1ff,
-};
-static const unsigned char vlc_dc_lum_bits[12] = {
- 3, 2, 2, 3, 3, 4, 5, 6, 7, 8, 9, 9,
-};
-
-static const uint16_t vlc_dc_chroma_code[12] = {
- 0x0, 0x1, 0x2, 0x6, 0xe, 0x1e, 0x3e, 0x7e, 0xfe, 0x1fe, 0x3fe, 0x3ff,
-};
-static const unsigned char vlc_dc_chroma_bits[12] = {
- 2, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10,
-};
-
-static const uint16_t mpeg1_vlc[113][2] = {
- { 0x3, 2 }, { 0x4, 4 }, { 0x5, 5 }, { 0x6, 7 },
- { 0x26, 8 }, { 0x21, 8 }, { 0xa, 10 }, { 0x1d, 12 },
- { 0x18, 12 }, { 0x13, 12 }, { 0x10, 12 }, { 0x1a, 13 },
- { 0x19, 13 }, { 0x18, 13 }, { 0x17, 13 }, { 0x1f, 14 },
- { 0x1e, 14 }, { 0x1d, 14 }, { 0x1c, 14 }, { 0x1b, 14 },
- { 0x1a, 14 }, { 0x19, 14 }, { 0x18, 14 }, { 0x17, 14 },
- { 0x16, 14 }, { 0x15, 14 }, { 0x14, 14 }, { 0x13, 14 },
- { 0x12, 14 }, { 0x11, 14 }, { 0x10, 14 }, { 0x18, 15 },
- { 0x17, 15 }, { 0x16, 15 }, { 0x15, 15 }, { 0x14, 15 },
- { 0x13, 15 }, { 0x12, 15 }, { 0x11, 15 }, { 0x10, 15 },
- { 0x3, 3 }, { 0x6, 6 }, { 0x25, 8 }, { 0xc, 10 },
- { 0x1b, 12 }, { 0x16, 13 }, { 0x15, 13 }, { 0x1f, 15 },
- { 0x1e, 15 }, { 0x1d, 15 }, { 0x1c, 15 }, { 0x1b, 15 },
- { 0x1a, 15 }, { 0x19, 15 }, { 0x13, 16 }, { 0x12, 16 },
- { 0x11, 16 }, { 0x10, 16 }, { 0x5, 4 }, { 0x4, 7 },
- { 0xb, 10 }, { 0x14, 12 }, { 0x14, 13 }, { 0x7, 5 },
- { 0x24, 8 }, { 0x1c, 12 }, { 0x13, 13 }, { 0x6, 5 },
- { 0xf, 10 }, { 0x12, 12 }, { 0x7, 6 }, { 0x9, 10 },
- { 0x12, 13 }, { 0x5, 6 }, { 0x1e, 12 }, { 0x14, 16 },
- { 0x4, 6 }, { 0x15, 12 }, { 0x7, 7 }, { 0x11, 12 },
- { 0x5, 7 }, { 0x11, 13 }, { 0x27, 8 }, { 0x10, 13 },
- { 0x23, 8 }, { 0x1a, 16 }, { 0x22, 8 }, { 0x19, 16 },
- { 0x20, 8 }, { 0x18, 16 }, { 0xe, 10 }, { 0x17, 16 },
- { 0xd, 10 }, { 0x16, 16 }, { 0x8, 10 }, { 0x15, 16 },
- { 0x1f, 12 }, { 0x1a, 12 }, { 0x19, 12 }, { 0x17, 12 },
- { 0x16, 12 }, { 0x1f, 13 }, { 0x1e, 13 }, { 0x1d, 13 },
- { 0x1c, 13 }, { 0x1b, 13 }, { 0x1f, 16 }, { 0x1e, 16 },
- { 0x1d, 16 }, { 0x1c, 16 }, { 0x1b, 16 },
- { 0x1, 6 }, /* escape */
- { 0x2, 2 }, /* EOB */
-};
-
-static const uint16_t mpeg2_vlc[113][2] = {
- {0x02, 2}, {0x06, 3}, {0x07, 4}, {0x1c, 5},
- {0x1d, 5}, {0x05, 6}, {0x04, 6}, {0x7b, 7},
- {0x7c, 7}, {0x23, 8}, {0x22, 8}, {0xfa, 8},
- {0xfb, 8}, {0xfe, 8}, {0xff, 8}, {0x1f,14},
- {0x1e,14}, {0x1d,14}, {0x1c,14}, {0x1b,14},
- {0x1a,14}, {0x19,14}, {0x18,14}, {0x17,14},
- {0x16,14}, {0x15,14}, {0x14,14}, {0x13,14},
- {0x12,14}, {0x11,14}, {0x10,14}, {0x18,15},
- {0x17,15}, {0x16,15}, {0x15,15}, {0x14,15},
- {0x13,15}, {0x12,15}, {0x11,15}, {0x10,15},
- {0x02, 3}, {0x06, 5}, {0x79, 7}, {0x27, 8},
- {0x20, 8}, {0x16,13}, {0x15,13}, {0x1f,15},
- {0x1e,15}, {0x1d,15}, {0x1c,15}, {0x1b,15},
- {0x1a,15}, {0x19,15}, {0x13,16}, {0x12,16},
- {0x11,16}, {0x10,16}, {0x05, 5}, {0x07, 7},
- {0xfc, 8}, {0x0c,10}, {0x14,13}, {0x07, 5},
- {0x26, 8}, {0x1c,12}, {0x13,13}, {0x06, 6},
- {0xfd, 8}, {0x12,12}, {0x07, 6}, {0x04, 9},
- {0x12,13}, {0x06, 7}, {0x1e,12}, {0x14,16},
- {0x04, 7}, {0x15,12}, {0x05, 7}, {0x11,12},
- {0x78, 7}, {0x11,13}, {0x7a, 7}, {0x10,13},
- {0x21, 8}, {0x1a,16}, {0x25, 8}, {0x19,16},
- {0x24, 8}, {0x18,16}, {0x05, 9}, {0x17,16},
- {0x07, 9}, {0x16,16}, {0x0d,10}, {0x15,16},
- {0x1f,12}, {0x1a,12}, {0x19,12}, {0x17,12},
- {0x16,12}, {0x1f,13}, {0x1e,13}, {0x1d,13},
- {0x1c,13}, {0x1b,13}, {0x1f,16}, {0x1e,16},
- {0x1d,16}, {0x1c,16}, {0x1b,16},
- {0x01,6}, /* escape */
- {0x06,4}, /* EOB */
-};
-
-static const int8_t mpeg1_level[111] = {
- 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,
- 1, 2, 3, 4, 5, 6, 7, 8,
- 9, 10, 11, 12, 13, 14, 15, 16,
- 17, 18, 1, 2, 3, 4, 5, 1,
- 2, 3, 4, 1, 2, 3, 1, 2,
- 3, 1, 2, 3, 1, 2, 1, 2,
- 1, 2, 1, 2, 1, 2, 1, 2,
- 1, 2, 1, 2, 1, 2, 1, 2,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1,
-};
-
-static const int8_t mpeg1_run[111] = {
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 2, 2, 2, 2, 2, 3,
- 3, 3, 3, 4, 4, 4, 5, 5,
- 5, 6, 6, 6, 7, 7, 8, 8,
- 9, 9, 10, 10, 11, 11, 12, 12,
- 13, 13, 14, 14, 15, 15, 16, 16,
- 17, 18, 19, 20, 21, 22, 23, 24,
- 25, 26, 27, 28, 29, 30, 31,
-};
-
-static RLTable rl_mpeg1 = {
- 111,
- 111,
- mpeg1_vlc,
- mpeg1_run,
- mpeg1_level,
-};
-
-static RLTable rl_mpeg2 = {
- 111,
- 111,
- mpeg2_vlc,
- mpeg1_run,
- mpeg1_level,
-};
-
-static const uint8_t mbAddrIncrTable[36][2] = {
- {0x1, 1},
- {0x3, 3},
- {0x2, 3},
- {0x3, 4},
- {0x2, 4},
- {0x3, 5},
- {0x2, 5},
- {0x7, 7},
- {0x6, 7},
- {0xb, 8},
- {0xa, 8},
- {0x9, 8},
- {0x8, 8},
- {0x7, 8},
- {0x6, 8},
- {0x17, 10},
- {0x16, 10},
- {0x15, 10},
- {0x14, 10},
- {0x13, 10},
- {0x12, 10},
- {0x23, 11},
- {0x22, 11},
- {0x21, 11},
- {0x20, 11},
- {0x1f, 11},
- {0x1e, 11},
- {0x1d, 11},
- {0x1c, 11},
- {0x1b, 11},
- {0x1a, 11},
- {0x19, 11},
- {0x18, 11},
- {0x8, 11}, /* escape */
- {0xf, 11}, /* stuffing */
- {0x0, 8}, /* end (and 15 more 0 bits should follow) */
-};
-
-static const uint8_t mbPatTable[64][2] = {
- {0x1, 9},
- {0xb, 5},
- {0x9, 5},
- {0xd, 6},
- {0xd, 4},
- {0x17, 7},
- {0x13, 7},
- {0x1f, 8},
- {0xc, 4},
- {0x16, 7},
- {0x12, 7},
- {0x1e, 8},
- {0x13, 5},
- {0x1b, 8},
- {0x17, 8},
- {0x13, 8},
- {0xb, 4},
- {0x15, 7},
- {0x11, 7},
- {0x1d, 8},
- {0x11, 5},
- {0x19, 8},
- {0x15, 8},
- {0x11, 8},
- {0xf, 6},
- {0xf, 8},
- {0xd, 8},
- {0x3, 9},
- {0xf, 5},
- {0xb, 8},
- {0x7, 8},
- {0x7, 9},
- {0xa, 4},
- {0x14, 7},
- {0x10, 7},
- {0x1c, 8},
- {0xe, 6},
- {0xe, 8},
- {0xc, 8},
- {0x2, 9},
- {0x10, 5},
- {0x18, 8},
- {0x14, 8},
- {0x10, 8},
- {0xe, 5},
- {0xa, 8},
- {0x6, 8},
- {0x6, 9},
- {0x12, 5},
- {0x1a, 8},
- {0x16, 8},
- {0x12, 8},
- {0xd, 5},
- {0x9, 8},
- {0x5, 8},
- {0x5, 9},
- {0xc, 5},
- {0x8, 8},
- {0x4, 8},
- {0x4, 9},
- {0x7, 3},
- {0xa, 5},
- {0x8, 5},
- {0xc, 6}
-};
-
-#define MB_TYPE_ZERO_MV 0x20000000
-#define IS_ZERO_MV(a) ((a)&MB_TYPE_ZERO_MV)
-
-static const uint8_t table_mb_ptype[7][2] = {
- { 3, 5 }, // 0x01 MB_INTRA
- { 1, 2 }, // 0x02 MB_PAT
- { 1, 3 }, // 0x08 MB_FOR
- { 1, 1 }, // 0x0A MB_FOR|MB_PAT
- { 1, 6 }, // 0x11 MB_QUANT|MB_INTRA
- { 1, 5 }, // 0x12 MB_QUANT|MB_PAT
- { 2, 5 }, // 0x1A MB_QUANT|MB_FOR|MB_PAT
-};
-
-static const uint32_t ptype2mb_type[7] = {
- MB_TYPE_INTRA,
- MB_TYPE_L0 | MB_TYPE_CBP | MB_TYPE_ZERO_MV | MB_TYPE_16x16,
- MB_TYPE_L0,
- MB_TYPE_L0 | MB_TYPE_CBP,
- MB_TYPE_QUANT | MB_TYPE_INTRA,
- MB_TYPE_QUANT | MB_TYPE_L0 | MB_TYPE_CBP | MB_TYPE_ZERO_MV | MB_TYPE_16x16,
- MB_TYPE_QUANT | MB_TYPE_L0 | MB_TYPE_CBP,
-};
-
-static const uint8_t table_mb_btype[11][2] = {
- { 3, 5 }, // 0x01 MB_INTRA
- { 2, 3 }, // 0x04 MB_BACK
- { 3, 3 }, // 0x06 MB_BACK|MB_PAT
- { 2, 4 }, // 0x08 MB_FOR
- { 3, 4 }, // 0x0A MB_FOR|MB_PAT
- { 2, 2 }, // 0x0C MB_FOR|MB_BACK
- { 3, 2 }, // 0x0E MB_FOR|MB_BACK|MB_PAT
- { 1, 6 }, // 0x11 MB_QUANT|MB_INTRA
- { 2, 6 }, // 0x16 MB_QUANT|MB_BACK|MB_PAT
- { 3, 6 }, // 0x1A MB_QUANT|MB_FOR|MB_PAT
- { 2, 5 }, // 0x1E MB_QUANT|MB_FOR|MB_BACK|MB_PAT
-};
-
-static const uint32_t btype2mb_type[11] = {
- MB_TYPE_INTRA,
- MB_TYPE_L1,
- MB_TYPE_L1 | MB_TYPE_CBP,
- MB_TYPE_L0,
- MB_TYPE_L0 | MB_TYPE_CBP,
- MB_TYPE_L0L1,
- MB_TYPE_L0L1 | MB_TYPE_CBP,
- MB_TYPE_QUANT | MB_TYPE_INTRA,
- MB_TYPE_QUANT | MB_TYPE_L1 | MB_TYPE_CBP,
- MB_TYPE_QUANT | MB_TYPE_L0 | MB_TYPE_CBP,
- MB_TYPE_QUANT | MB_TYPE_L0L1 | MB_TYPE_CBP,
-};
-
-static const uint8_t mbMotionVectorTable[17][2] = {
-{ 0x1, 1 },
-{ 0x1, 2 },
-{ 0x1, 3 },
-{ 0x1, 4 },
-{ 0x3, 6 },
-{ 0x5, 7 },
-{ 0x4, 7 },
-{ 0x3, 7 },
-{ 0xb, 9 },
-{ 0xa, 9 },
-{ 0x9, 9 },
-{ 0x11, 10 },
-{ 0x10, 10 },
-{ 0xf, 10 },
-{ 0xe, 10 },
-{ 0xd, 10 },
-{ 0xc, 10 },
-};
-
-const AVRational ff_frame_rate_tab[] = {
- { 0, 0},
- {24000, 1001},
- { 24, 1},
- { 25, 1},
- {30000, 1001},
- { 30, 1},
- { 50, 1},
- {60000, 1001},
- { 60, 1},
- // Xing's 15fps: (9)
- { 15, 1},
- // libmpeg3's "Unofficial economy rates": (10-13)
- { 5, 1},
- { 10, 1},
- { 12, 1},
- { 15, 1},
- { 0, 0},
-};
-
-static const uint8_t non_linear_qscale[32] = {
- 0, 1, 2, 3, 4, 5, 6, 7,
- 8,10,12,14,16,18,20,22,
- 24,28,32,36,40,44,48,52,
- 56,64,72,80,88,96,104,112,
-};
-
-const uint8_t ff_mpeg1_dc_scale_table[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
- 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,
- 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,
- 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,
- 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,
-};
-
-static const uint8_t *mpeg2_dc_scale_table[4]={
- ff_mpeg1_dc_scale_table,
- mpeg2_dc_scale_table1,
- mpeg2_dc_scale_table2,
- mpeg2_dc_scale_table3,
-};
-
-static const float mpeg1_aspect[16]={
- 0.0000,
- 1.0000,
- 0.6735,
- 0.7031,
-
- 0.7615,
- 0.8055,
- 0.8437,
- 0.8935,
-
- 0.9157,
- 0.9815,
- 1.0255,
- 1.0695,
-
- 1.0950,
- 1.1575,
- 1.2015,
-};
-
-static const AVRational mpeg2_aspect[16]={
- {0,1},
- {1,1},
- {4,3},
- {16,9},
- {221,100},
- {0,1},
- {0,1},
- {0,1},
- {0,1},
- {0,1},
- {0,1},
- {0,1},
- {0,1},
- {0,1},
- {0,1},
- {0,1},
-};
-
-static const uint8_t svcd_scan_offset_placeholder[14]={
- 0x10, 0x0E,
- 0x00, 0x80, 0x81,
- 0x00, 0x80, 0x81,
- 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff,
-};
diff --git a/src/libffmpeg/libavcodec/mpegaudiodec.c b/src/libffmpeg/libavcodec/mpegaudiodec.c
deleted file mode 100644
index 367400581..000000000
--- a/src/libffmpeg/libavcodec/mpegaudiodec.c
+++ /dev/null
@@ -1,2879 +0,0 @@
-/*
- * MPEG Audio decoder
- * Copyright (c) 2001, 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 mpegaudiodec.c
- * MPEG Audio decoder.
- */
-
-//#define DEBUG
-#include "avcodec.h"
-#include "bitstream.h"
-#include "dsputil.h"
-
-/*
- * TODO:
- * - in low precision mode, use more 16 bit multiplies in synth filter
- * - test lsf / mpeg25 extensively.
- */
-
-/* define USE_HIGHPRECISION to have a bit exact (but slower) mpeg
- audio decoder */
-#ifdef CONFIG_MPEGAUDIO_HP
-# define USE_HIGHPRECISION
-#endif
-
-#include "mpegaudio.h"
-
-#include "mathops.h"
-
-#define FRAC_ONE (1 << FRAC_BITS)
-
-#define FIX(a) ((int)((a) * FRAC_ONE))
-/* WARNING: only correct for posititive numbers */
-#define FIXR(a) ((int)((a) * FRAC_ONE + 0.5))
-#define FRAC_RND(a) (((a) + (FRAC_ONE/2)) >> FRAC_BITS)
-
-#define FIXHR(a) ((int)((a) * (1LL<<32) + 0.5))
-
-/****************/
-
-#define HEADER_SIZE 4
-#define BACKSTEP_SIZE 512
-#define EXTRABYTES 24
-
-struct GranuleDef;
-
-typedef struct MPADecodeContext {
- DECLARE_ALIGNED_8(uint8_t, last_buf[2*BACKSTEP_SIZE + EXTRABYTES]);
- int last_buf_size;
- int frame_size;
- /* next header (used in free format parsing) */
- uint32_t free_format_next_header;
- int error_protection;
- int layer;
- int sample_rate;
- int sample_rate_index; /* between 0 and 8 */
- int bit_rate;
- GetBitContext gb;
- GetBitContext in_gb;
- int nb_channels;
- int mode;
- int mode_ext;
- int lsf;
- MPA_INT synth_buf[MPA_MAX_CHANNELS][512 * 2] __attribute__((aligned(16)));
- int synth_buf_offset[MPA_MAX_CHANNELS];
- int32_t sb_samples[MPA_MAX_CHANNELS][36][SBLIMIT] __attribute__((aligned(16)));
- int32_t mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18]; /* previous samples, for layer 3 MDCT */
-#ifdef DEBUG
- int frame_count;
-#endif
- void (*compute_antialias)(struct MPADecodeContext *s, struct GranuleDef *g);
- int adu_mode; ///< 0 for standard mp3, 1 for adu formatted mp3
- int dither_state;
- int error_resilience;
-} MPADecodeContext;
-
-/**
- * Context for MP3On4 decoder
- */
-typedef struct MP3On4DecodeContext {
- int frames; ///< number of mp3 frames per block (number of mp3 decoder instances)
- int chan_cfg; ///< channel config number
- MPADecodeContext *mp3decctx[5]; ///< MPADecodeContext for every decoder instance
-} MP3On4DecodeContext;
-
-/* 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 MODE_EXT_MS_STEREO 2
-#define MODE_EXT_I_STEREO 1
-
-/* layer 3 huffman tables */
-typedef struct HuffTable {
- int xsize;
- const uint8_t *bits;
- const uint16_t *codes;
-} HuffTable;
-
-#include "mpegaudiodectab.h"
-
-static void compute_antialias_integer(MPADecodeContext *s, GranuleDef *g);
-static void compute_antialias_float(MPADecodeContext *s, GranuleDef *g);
-
-/* vlc structure for decoding layer 3 huffman tables */
-static VLC huff_vlc[16];
-static VLC huff_quad_vlc[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;
-static uint32_t *table_4_3_value;
-static uint32_t exp_table[512];
-static uint32_t expval_table[512][16];
-/* intensity stereo coef table */
-static int32_t is_table[2][16];
-static int32_t is_table_lsf[2][2][16];
-static int32_t csa_table[8][4];
-static float csa_table_float[8][4];
-static int32_t mdct_win[8][36];
-
-/* lower 2 bits: modulo 3, higher bits: shift */
-static uint16_t scale_factor_modshift[64];
-/* [i][j]: 2^(-j/3) * FRAC_ONE * 2^(i+2) / (2^(i+2) - 1) */
-static int32_t scale_factor_mult[15][3];
-/* mult table for layer 2 group quantization */
-
-#define SCALE_GEN(v) \
-{ FIXR(1.0 * (v)), FIXR(0.7937005259 * (v)), FIXR(0.6299605249 * (v)) }
-
-static const int32_t scale_factor_mult2[3][3] = {
- SCALE_GEN(4.0 / 3.0), /* 3 steps */
- SCALE_GEN(4.0 / 5.0), /* 5 steps */
- SCALE_GEN(4.0 / 9.0), /* 9 steps */
-};
-
-static MPA_INT window[512] __attribute__((aligned(16)));
-
-/* layer 1 unscaling */
-/* n = number of bits of the mantissa minus 1 */
-static inline int l1_unscale(int n, int mant, int scale_factor)
-{
- int shift, mod;
- int64_t val;
-
- shift = scale_factor_modshift[scale_factor];
- mod = shift & 3;
- shift >>= 2;
- val = MUL64(mant + (-1 << n) + 1, scale_factor_mult[n-1][mod]);
- shift += n;
- /* NOTE: at this point, 1 <= shift >= 21 + 15 */
- return (int)((val + (1LL << (shift - 1))) >> shift);
-}
-
-static inline int l2_unscale_group(int steps, int mant, int scale_factor)
-{
- int shift, mod, val;
-
- shift = scale_factor_modshift[scale_factor];
- mod = shift & 3;
- shift >>= 2;
-
- val = (mant - (steps >> 1)) * scale_factor_mult2[steps >> 2][mod];
- /* NOTE: at this point, 0 <= shift <= 21 */
- if (shift > 0)
- val = (val + (1 << (shift - 1))) >> shift;
- return val;
-}
-
-/* compute value^(4/3) * 2^(exponent/4). It normalized to FRAC_BITS */
-static inline int l3_unscale(int value, int exponent)
-{
- unsigned int m;
- int e;
-
- e = table_4_3_exp [4*value + (exponent&3)];
- m = table_4_3_value[4*value + (exponent&3)];
- e -= (exponent >> 2);
- assert(e>=1);
- if (e > 31)
- return 0;
- m = (m + (1 << (e-1))) >> e;
-
- return m;
-}
-
-/* all integer n^(4/3) computation code */
-#define DEV_ORDER 13
-
-#define POW_FRAC_BITS 24
-#define POW_FRAC_ONE (1 << POW_FRAC_BITS)
-#define POW_FIX(a) ((int)((a) * POW_FRAC_ONE))
-#define POW_MULL(a,b) (((int64_t)(a) * (int64_t)(b)) >> POW_FRAC_BITS)
-
-static int dev_4_3_coefs[DEV_ORDER];
-
-#if 0 /* unused */
-static int pow_mult3[3] = {
- POW_FIX(1.0),
- POW_FIX(1.25992104989487316476),
- POW_FIX(1.58740105196819947474),
-};
-#endif
-
-static void int_pow_init(void)
-{
- int i, a;
-
- a = POW_FIX(1.0);
- for(i=0;i<DEV_ORDER;i++) {
- a = POW_MULL(a, POW_FIX(4.0 / 3.0) - i * POW_FIX(1.0)) / (i + 1);
- dev_4_3_coefs[i] = a;
- }
-}
-
-#if 0 /* unused, remove? */
-/* return the mantissa and the binary exponent */
-static int int_pow(int i, int *exp_ptr)
-{
- int e, er, eq, j;
- int a, a1;
-
- /* renormalize */
- a = i;
- e = POW_FRAC_BITS;
- while (a < (1 << (POW_FRAC_BITS - 1))) {
- a = a << 1;
- e--;
- }
- a -= (1 << POW_FRAC_BITS);
- a1 = 0;
- for(j = DEV_ORDER - 1; j >= 0; j--)
- a1 = POW_MULL(a, dev_4_3_coefs[j] + a1);
- a = (1 << POW_FRAC_BITS) + a1;
- /* exponent compute (exact) */
- e = e * 4;
- er = e % 3;
- eq = e / 3;
- a = POW_MULL(a, pow_mult3[er]);
- while (a >= 2 * POW_FRAC_ONE) {
- a = a >> 1;
- eq++;
- }
- /* convert to float */
- while (a < POW_FRAC_ONE) {
- a = a << 1;
- eq--;
- }
- /* now POW_FRAC_ONE <= a < 2 * POW_FRAC_ONE */
-#if POW_FRAC_BITS > FRAC_BITS
- a = (a + (1 << (POW_FRAC_BITS - FRAC_BITS - 1))) >> (POW_FRAC_BITS - FRAC_BITS);
- /* correct overflow */
- if (a >= 2 * (1 << FRAC_BITS)) {
- a = a >> 1;
- eq++;
- }
-#endif
- *exp_ptr = eq;
- return a;
-}
-#endif
-
-static int decode_init(AVCodecContext * avctx)
-{
- MPADecodeContext *s = avctx->priv_data;
- static int init=0;
- int i, j, k;
-
-#if defined(USE_HIGHPRECISION) && defined(CONFIG_AUDIO_NONSHORT)
- avctx->sample_fmt= SAMPLE_FMT_S32;
-#else
- avctx->sample_fmt= SAMPLE_FMT_S16;
-#endif
- s->error_resilience= avctx->error_resilience;
-
- if(avctx->antialias_algo != FF_AA_FLOAT)
- s->compute_antialias= compute_antialias_integer;
- else
- s->compute_antialias= compute_antialias_float;
-
- if (!init && !avctx->parse_only) {
- /* scale factors table for layer 1/2 */
- for(i=0;i<64;i++) {
- int shift, mod;
- /* 1.0 (i = 3) is normalized to 2 ^ FRAC_BITS */
- shift = (i / 3);
- mod = i % 3;
- scale_factor_modshift[i] = mod | (shift << 2);
- }
-
- /* scale factor multiply for layer 1 */
- for(i=0;i<15;i++) {
- int n, norm;
- n = i + 2;
- norm = ((INT64_C(1) << n) * FRAC_ONE) / ((1 << n) - 1);
- scale_factor_mult[i][0] = MULL(FIXR(1.0 * 2.0), norm);
- scale_factor_mult[i][1] = MULL(FIXR(0.7937005259 * 2.0), norm);
- scale_factor_mult[i][2] = MULL(FIXR(0.6299605249 * 2.0), norm);
- dprintf("%d: norm=%x s=%x %x %x\n",
- i, norm,
- scale_factor_mult[i][0],
- scale_factor_mult[i][1],
- scale_factor_mult[i][2]);
- }
-
- ff_mpa_synth_init(window);
-
- /* huffman decode tables */
- for(i=1;i<16;i++) {
- const HuffTable *h = &mpa_huff_tables[i];
- int xsize, x, y;
- unsigned int n;
- uint8_t tmp_bits [512];
- uint16_t tmp_codes[512];
-
- memset(tmp_bits , 0, sizeof(tmp_bits ));
- memset(tmp_codes, 0, sizeof(tmp_codes));
-
- xsize = h->xsize;
- n = xsize * xsize;
-
- j = 0;
- for(x=0;x<xsize;x++) {
- for(y=0;y<xsize;y++){
- tmp_bits [(x << 5) | y | ((x&&y)<<4)]= h->bits [j ];
- tmp_codes[(x << 5) | y | ((x&&y)<<4)]= h->codes[j++];
- }
- }
-
- /* XXX: fail test */
- init_vlc(&huff_vlc[i], 7, 512,
- tmp_bits, 1, 1, tmp_codes, 2, 2, 1);
- }
- for(i=0;i<2;i++) {
- init_vlc(&huff_quad_vlc[i], i == 0 ? 7 : 4, 16,
- mpa_quad_bits[i], 1, 1, mpa_quad_codes[i], 1, 1, 1);
- }
-
- for(i=0;i<9;i++) {
- k = 0;
- for(j=0;j<22;j++) {
- band_index_long[i][j] = k;
- k += band_size_long[i][j];
- }
- band_index_long[i][22] = k;
- }
-
- /* compute n ^ (4/3) and store it in mantissa/exp format */
- table_4_3_exp= av_mallocz_static(TABLE_4_3_SIZE * sizeof(table_4_3_exp[0]));
- if(!table_4_3_exp)
- return -1;
- table_4_3_value= av_mallocz_static(TABLE_4_3_SIZE * sizeof(table_4_3_value[0]));
- if(!table_4_3_value)
- return -1;
-
- int_pow_init();
- for(i=1;i<TABLE_4_3_SIZE;i++) {
- double f, fm;
- int e, m;
- f = pow((double)(i/4), 4.0 / 3.0) * 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;
-// av_log(NULL, AV_LOG_DEBUG, "%d %d %f\n", i, m, pow((double)i, 4.0 / 3.0));
- table_4_3_exp[i] = -e;
- }
- for(i=0; i<512*16; i++){
- int exponent= (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);
- }
-
- for(i=0;i<7;i++) {
- float f;
- int v;
- if (i != 6) {
- f = tan((double)i * M_PI / 12.0);
- v = FIXR(f / (1.0 + f));
- } else {
- v = FIXR(1.0);
- }
- is_table[0][i] = v;
- is_table[1][6 - i] = v;
- }
- /* invalid values */
- for(i=7;i<16;i++)
- is_table[0][i] = is_table[1][i] = 0.0;
-
- for(i=0;i<16;i++) {
- double f;
- int e, k;
-
- for(j=0;j<2;j++) {
- e = -(j + 1) * ((i + 1) >> 1);
- f = pow(2.0, e / 4.0);
- k = i & 1;
- is_table_lsf[j][k ^ 1][i] = FIXR(f);
- is_table_lsf[j][k][i] = FIXR(1.0);
- dprintf("is_table_lsf %d %d: %x %x\n",
- i, j, is_table_lsf[j][0][i], is_table_lsf[j][1][i]);
- }
- }
-
- for(i=0;i<8;i++) {
- float ci, cs, ca;
- ci = ci_table[i];
- cs = 1.0 / sqrt(1.0 + ci * ci);
- ca = cs * ci;
- csa_table[i][0] = FIXHR(cs/4);
- csa_table[i][1] = FIXHR(ca/4);
- csa_table[i][2] = FIXHR(ca/4) + FIXHR(cs/4);
- csa_table[i][3] = FIXHR(ca/4) - FIXHR(cs/4);
- csa_table_float[i][0] = cs;
- csa_table_float[i][1] = ca;
- csa_table_float[i][2] = ca + cs;
- csa_table_float[i][3] = ca - cs;
-// printf("%d %d %d %d\n", FIX(cs), FIX(cs-1), FIX(ca), FIX(cs)-FIX(ca));
-// av_log(NULL, AV_LOG_DEBUG,"%f %f %f %f\n", cs, ca, ca+cs, ca-cs);
- }
-
- /* compute mdct windows */
- for(i=0;i<36;i++) {
- for(j=0; j<4; j++){
- double d;
-
- if(j==2 && i%3 != 1)
- continue;
-
- d= sin(M_PI * (i + 0.5) / 36.0);
- if(j==1){
- if (i>=30) d= 0;
- else if(i>=24) d= sin(M_PI * (i - 18 + 0.5) / 12.0);
- else if(i>=18) d= 1;
- }else if(j==3){
- if (i< 6) d= 0;
- else if(i< 12) d= sin(M_PI * (i - 6 + 0.5) / 12.0);
- else if(i< 18) d= 1;
- }
- //merge last stage of imdct into the window coefficients
- d*= 0.5 / cos(M_PI*(2*i + 19)/72);
-
- if(j==2)
- mdct_win[j][i/3] = FIXHR((d / (1<<5)));
- else
- mdct_win[j][i ] = FIXHR((d / (1<<5)));
-// av_log(NULL, AV_LOG_DEBUG, "%2d %d %f\n", i,j,d / (1<<5));
- }
- }
-
- /* NOTE: we do frequency inversion adter the MDCT by changing
- the sign of the right window coefs */
- for(j=0;j<4;j++) {
- for(i=0;i<36;i+=2) {
- mdct_win[j + 4][i] = mdct_win[j][i];
- mdct_win[j + 4][i + 1] = -mdct_win[j][i + 1];
- }
- }
-
-#if defined(DEBUG)
- for(j=0;j<8;j++) {
- av_log(avctx, AV_LOG_DEBUG, "win%d=\n", j);
- for(i=0;i<36;i++)
- av_log(avctx, AV_LOG_DEBUG, "%f, ", (double)mdct_win[j][i] / FRAC_ONE);
- av_log(avctx, AV_LOG_DEBUG, "\n");
- }
-#endif
- init = 1;
- }
-
-#ifdef DEBUG
- s->frame_count = 0;
-#endif
- if (avctx->codec_id == CODEC_ID_MP3ADU)
- s->adu_mode = 1;
- return 0;
-}
-
-/* tab[i][j] = 1.0 / (2.0 * cos(pi*(2*k+1) / 2^(6 - j))) */
-
-/* cos(i*pi/64) */
-
-#define COS0_0 FIXHR(0.50060299823519630134/2)
-#define COS0_1 FIXHR(0.50547095989754365998/2)
-#define COS0_2 FIXHR(0.51544730992262454697/2)
-#define COS0_3 FIXHR(0.53104259108978417447/2)
-#define COS0_4 FIXHR(0.55310389603444452782/2)
-#define COS0_5 FIXHR(0.58293496820613387367/2)
-#define COS0_6 FIXHR(0.62250412303566481615/2)
-#define COS0_7 FIXHR(0.67480834145500574602/2)
-#define COS0_8 FIXHR(0.74453627100229844977/2)
-#define COS0_9 FIXHR(0.83934964541552703873/2)
-#define COS0_10 FIXHR(0.97256823786196069369/2)
-#define COS0_11 FIXHR(1.16943993343288495515/4)
-#define COS0_12 FIXHR(1.48416461631416627724/4)
-#define COS0_13 FIXHR(2.05778100995341155085/8)
-#define COS0_14 FIXHR(3.40760841846871878570/8)
-#define COS0_15 FIXHR(10.19000812354805681150/32)
-
-#define COS1_0 FIXHR(0.50241928618815570551/2)
-#define COS1_1 FIXHR(0.52249861493968888062/2)
-#define COS1_2 FIXHR(0.56694403481635770368/2)
-#define COS1_3 FIXHR(0.64682178335999012954/2)
-#define COS1_4 FIXHR(0.78815462345125022473/2)
-#define COS1_5 FIXHR(1.06067768599034747134/4)
-#define COS1_6 FIXHR(1.72244709823833392782/4)
-#define COS1_7 FIXHR(5.10114861868916385802/16)
-
-#define COS2_0 FIXHR(0.50979557910415916894/2)
-#define COS2_1 FIXHR(0.60134488693504528054/2)
-#define COS2_2 FIXHR(0.89997622313641570463/2)
-#define COS2_3 FIXHR(2.56291544774150617881/8)
-
-#define COS3_0 FIXHR(0.54119610014619698439/2)
-#define COS3_1 FIXHR(1.30656296487637652785/4)
-
-#define COS4_0 FIXHR(0.70710678118654752439/2)
-
-/* butterfly operator */
-#define BF(a, b, c, s)\
-{\
- tmp0 = tab[a] + tab[b];\
- tmp1 = tab[a] - tab[b];\
- tab[a] = tmp0;\
- tab[b] = MULH(tmp1<<(s), c);\
-}
-
-#define BF1(a, b, c, d)\
-{\
- BF(a, b, COS4_0, 1);\
- BF(c, d,-COS4_0, 1);\
- tab[c] += tab[d];\
-}
-
-#define BF2(a, b, c, d)\
-{\
- BF(a, b, COS4_0, 1);\
- BF(c, d,-COS4_0, 1);\
- tab[c] += tab[d];\
- tab[a] += tab[c];\
- tab[c] += tab[b];\
- tab[b] += tab[d];\
-}
-
-#define ADD(a, b) tab[a] += tab[b]
-
-/* DCT32 without 1/sqrt(2) coef zero scaling. */
-static void dct32(int32_t *out, int32_t *tab)
-{
- int tmp0, tmp1;
-
- /* pass 1 */
- BF( 0, 31, COS0_0 , 1);
- BF(15, 16, COS0_15, 5);
- /* pass 2 */
- BF( 0, 15, COS1_0 , 1);
- BF(16, 31,-COS1_0 , 1);
- /* pass 1 */
- BF( 7, 24, COS0_7 , 1);
- BF( 8, 23, COS0_8 , 1);
- /* pass 2 */
- BF( 7, 8, COS1_7 , 4);
- BF(23, 24,-COS1_7 , 4);
- /* pass 3 */
- BF( 0, 7, COS2_0 , 1);
- BF( 8, 15,-COS2_0 , 1);
- BF(16, 23, COS2_0 , 1);
- BF(24, 31,-COS2_0 , 1);
- /* pass 1 */
- BF( 3, 28, COS0_3 , 1);
- BF(12, 19, COS0_12, 2);
- /* pass 2 */
- BF( 3, 12, COS1_3 , 1);
- BF(19, 28,-COS1_3 , 1);
- /* pass 1 */
- BF( 4, 27, COS0_4 , 1);
- BF(11, 20, COS0_11, 2);
- /* pass 2 */
- BF( 4, 11, COS1_4 , 1);
- BF(20, 27,-COS1_4 , 1);
- /* pass 3 */
- BF( 3, 4, COS2_3 , 3);
- BF(11, 12,-COS2_3 , 3);
- BF(19, 20, COS2_3 , 3);
- BF(27, 28,-COS2_3 , 3);
- /* pass 4 */
- BF( 0, 3, COS3_0 , 1);
- BF( 4, 7,-COS3_0 , 1);
- BF( 8, 11, COS3_0 , 1);
- BF(12, 15,-COS3_0 , 1);
- BF(16, 19, COS3_0 , 1);
- BF(20, 23,-COS3_0 , 1);
- BF(24, 27, COS3_0 , 1);
- BF(28, 31,-COS3_0 , 1);
-
-
-
- /* pass 1 */
- BF( 1, 30, COS0_1 , 1);
- BF(14, 17, COS0_14, 3);
- /* pass 2 */
- BF( 1, 14, COS1_1 , 1);
- BF(17, 30,-COS1_1 , 1);
- /* pass 1 */
- BF( 6, 25, COS0_6 , 1);
- BF( 9, 22, COS0_9 , 1);
- /* pass 2 */
- BF( 6, 9, COS1_6 , 2);
- BF(22, 25,-COS1_6 , 2);
- /* pass 3 */
- BF( 1, 6, COS2_1 , 1);
- BF( 9, 14,-COS2_1 , 1);
- BF(17, 22, COS2_1 , 1);
- BF(25, 30,-COS2_1 , 1);
-
- /* pass 1 */
- BF( 2, 29, COS0_2 , 1);
- BF(13, 18, COS0_13, 3);
- /* pass 2 */
- BF( 2, 13, COS1_2 , 1);
- BF(18, 29,-COS1_2 , 1);
- /* pass 1 */
- BF( 5, 26, COS0_5 , 1);
- BF(10, 21, COS0_10, 1);
- /* pass 2 */
- BF( 5, 10, COS1_5 , 2);
- BF(21, 26,-COS1_5 , 2);
- /* pass 3 */
- BF( 2, 5, COS2_2 , 1);
- BF(10, 13,-COS2_2 , 1);
- BF(18, 21, COS2_2 , 1);
- BF(26, 29,-COS2_2 , 1);
- /* pass 4 */
- BF( 1, 2, COS3_1 , 2);
- BF( 5, 6,-COS3_1 , 2);
- BF( 9, 10, COS3_1 , 2);
- BF(13, 14,-COS3_1 , 2);
- BF(17, 18, COS3_1 , 2);
- BF(21, 22,-COS3_1 , 2);
- BF(25, 26, COS3_1 , 2);
- BF(29, 30,-COS3_1 , 2);
-
- /* pass 5 */
- BF1( 0, 1, 2, 3);
- BF2( 4, 5, 6, 7);
- BF1( 8, 9, 10, 11);
- BF2(12, 13, 14, 15);
- BF1(16, 17, 18, 19);
- BF2(20, 21, 22, 23);
- BF1(24, 25, 26, 27);
- BF2(28, 29, 30, 31);
-
- /* pass 6 */
-
- ADD( 8, 12);
- ADD(12, 10);
- ADD(10, 14);
- ADD(14, 9);
- ADD( 9, 13);
- ADD(13, 11);
- ADD(11, 15);
-
- out[ 0] = tab[0];
- out[16] = tab[1];
- out[ 8] = tab[2];
- out[24] = tab[3];
- out[ 4] = tab[4];
- out[20] = tab[5];
- out[12] = tab[6];
- out[28] = tab[7];
- out[ 2] = tab[8];
- out[18] = tab[9];
- out[10] = tab[10];
- out[26] = tab[11];
- out[ 6] = tab[12];
- out[22] = tab[13];
- out[14] = tab[14];
- out[30] = tab[15];
-
- ADD(24, 28);
- ADD(28, 26);
- ADD(26, 30);
- ADD(30, 25);
- ADD(25, 29);
- ADD(29, 27);
- ADD(27, 31);
-
- out[ 1] = tab[16] + tab[24];
- out[17] = tab[17] + tab[25];
- out[ 9] = tab[18] + tab[26];
- out[25] = tab[19] + tab[27];
- out[ 5] = tab[20] + tab[28];
- out[21] = tab[21] + tab[29];
- out[13] = tab[22] + tab[30];
- out[29] = tab[23] + tab[31];
- out[ 3] = tab[24] + tab[20];
- out[19] = tab[25] + tab[21];
- out[11] = tab[26] + tab[22];
- out[27] = tab[27] + tab[23];
- out[ 7] = tab[28] + tab[18];
- out[23] = tab[29] + tab[19];
- out[15] = tab[30] + tab[17];
- out[31] = tab[31];
-}
-
-#if FRAC_BITS <= 15
-
-static inline int round_sample(int *sum)
-{
- int sum1;
- sum1 = (*sum) >> OUT_SHIFT;
- *sum &= (1<<OUT_SHIFT)-1;
- if (sum1 < OUT_MIN)
- sum1 = OUT_MIN;
- else if (sum1 > OUT_MAX)
- sum1 = OUT_MAX;
- return sum1;
-}
-
-/* signed 16x16 -> 32 multiply add accumulate */
-#define MACS(rt, ra, rb) MAC16(rt, ra, rb)
-
-/* signed 16x16 -> 32 multiply */
-#define MULS(ra, rb) MUL16(ra, rb)
-
-#else
-
-static inline int round_sample(int64_t *sum)
-{
- int sum1;
- sum1 = (int)((*sum) >> OUT_SHIFT);
- *sum &= (1<<OUT_SHIFT)-1;
- if (sum1 < OUT_MIN)
- sum1 = OUT_MIN;
- else if (sum1 > OUT_MAX)
- sum1 = OUT_MAX;
- return sum1;
-}
-
-# define MULS(ra, rb) MUL64(ra, rb)
-#endif
-
-#define SUM8(sum, op, w, p) \
-{ \
- sum op MULS((w)[0 * 64], p[0 * 64]);\
- sum op MULS((w)[1 * 64], p[1 * 64]);\
- sum op MULS((w)[2 * 64], p[2 * 64]);\
- sum op MULS((w)[3 * 64], p[3 * 64]);\
- sum op MULS((w)[4 * 64], p[4 * 64]);\
- sum op MULS((w)[5 * 64], p[5 * 64]);\
- sum op MULS((w)[6 * 64], p[6 * 64]);\
- sum op MULS((w)[7 * 64], p[7 * 64]);\
-}
-
-#define SUM8P2(sum1, op1, sum2, op2, w1, w2, p) \
-{ \
- int tmp;\
- tmp = p[0 * 64];\
- sum1 op1 MULS((w1)[0 * 64], tmp);\
- sum2 op2 MULS((w2)[0 * 64], tmp);\
- tmp = p[1 * 64];\
- sum1 op1 MULS((w1)[1 * 64], tmp);\
- sum2 op2 MULS((w2)[1 * 64], tmp);\
- tmp = p[2 * 64];\
- sum1 op1 MULS((w1)[2 * 64], tmp);\
- sum2 op2 MULS((w2)[2 * 64], tmp);\
- tmp = p[3 * 64];\
- sum1 op1 MULS((w1)[3 * 64], tmp);\
- sum2 op2 MULS((w2)[3 * 64], tmp);\
- tmp = p[4 * 64];\
- sum1 op1 MULS((w1)[4 * 64], tmp);\
- sum2 op2 MULS((w2)[4 * 64], tmp);\
- tmp = p[5 * 64];\
- sum1 op1 MULS((w1)[5 * 64], tmp);\
- sum2 op2 MULS((w2)[5 * 64], tmp);\
- tmp = p[6 * 64];\
- sum1 op1 MULS((w1)[6 * 64], tmp);\
- sum2 op2 MULS((w2)[6 * 64], tmp);\
- tmp = p[7 * 64];\
- sum1 op1 MULS((w1)[7 * 64], tmp);\
- sum2 op2 MULS((w2)[7 * 64], tmp);\
-}
-
-void ff_mpa_synth_init(MPA_INT *window)
-{
- int i;
-
- /* max = 18760, max sum over all 16 coefs : 44736 */
- for(i=0;i<257;i++) {
- int v;
- v = mpa_enwindow[i];
-#if WFRAC_BITS < 16
- v = (v + (1 << (16 - WFRAC_BITS - 1))) >> (16 - WFRAC_BITS);
-#endif
- window[i] = v;
- if ((i & 63) != 0)
- v = -v;
- if (i != 0)
- window[512 - i] = v;
- }
-}
-
-/* 32 sub band synthesis filter. Input: 32 sub band samples, Output:
- 32 samples. */
-/* XXX: optimize by avoiding ring buffer usage */
-void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,
- MPA_INT *window, int *dither_state,
- OUT_INT *samples, int incr,
- int32_t sb_samples[SBLIMIT])
-{
- int32_t tmp[32];
- register MPA_INT *synth_buf;
- register const MPA_INT *w, *w2, *p;
- int j, offset, v;
- OUT_INT *samples2;
-#if FRAC_BITS <= 15
- int sum, sum2;
-#else
- int64_t sum, sum2;
-#endif
-
- dct32(tmp, sb_samples);
-
- offset = *synth_buf_offset;
- synth_buf = synth_buf_ptr + offset;
-
- for(j=0;j<32;j++) {
- v = tmp[j];
-#if FRAC_BITS <= 15
- /* NOTE: can cause a loss in precision if very high amplitude
- sound */
- if (v > 32767)
- v = 32767;
- else if (v < -32768)
- v = -32768;
-#endif
- synth_buf[j] = v;
- }
- /* copy to avoid wrap */
- memcpy(synth_buf + 512, synth_buf, 32 * sizeof(MPA_INT));
-
- samples2 = samples + 31 * incr;
- w = window;
- w2 = window + 31;
-
- sum = *dither_state;
- p = synth_buf + 16;
- SUM8(sum, +=, w, p);
- p = synth_buf + 48;
- SUM8(sum, -=, w + 32, p);
- *samples = round_sample(&sum);
- samples += incr;
- w++;
-
- /* we calculate two samples at the same time to avoid one memory
- access per two sample */
- for(j=1;j<16;j++) {
- sum2 = 0;
- p = synth_buf + 16 + j;
- SUM8P2(sum, +=, sum2, -=, w, w2, p);
- p = synth_buf + 48 - j;
- SUM8P2(sum, -=, sum2, -=, w + 32, w2 + 32, p);
-
- *samples = round_sample(&sum);
- samples += incr;
- sum += sum2;
- *samples2 = round_sample(&sum);
- samples2 -= incr;
- w++;
- w2--;
- }
-
- p = synth_buf + 32;
- SUM8(sum, -=, w + 32, p);
- *samples = round_sample(&sum);
- *dither_state= sum;
-
- offset = (offset - 32) & 511;
- *synth_buf_offset = offset;
-}
-
-#define C3 FIXHR(0.86602540378443864676/2)
-
-/* 0.5 / cos(pi*(2*i+1)/36) */
-static const int icos36[9] = {
- FIXR(0.50190991877167369479),
- FIXR(0.51763809020504152469), //0
- FIXR(0.55168895948124587824),
- FIXR(0.61038729438072803416),
- FIXR(0.70710678118654752439), //1
- FIXR(0.87172339781054900991),
- FIXR(1.18310079157624925896),
- FIXR(1.93185165257813657349), //2
- FIXR(5.73685662283492756461),
-};
-
-/* 0.5 / cos(pi*(2*i+1)/36) */
-static const int icos36h[9] = {
- FIXHR(0.50190991877167369479/2),
- FIXHR(0.51763809020504152469/2), //0
- FIXHR(0.55168895948124587824/2),
- FIXHR(0.61038729438072803416/2),
- FIXHR(0.70710678118654752439/2), //1
- FIXHR(0.87172339781054900991/2),
- FIXHR(1.18310079157624925896/4),
- FIXHR(1.93185165257813657349/4), //2
-// FIXHR(5.73685662283492756461),
-};
-
-/* 12 points IMDCT. We compute it "by hand" by factorizing obvious
- cases. */
-static void imdct12(int *out, int *in)
-{
- int in0, in1, in2, in3, in4, in5, t1, t2;
-
- in0= in[0*3];
- in1= in[1*3] + in[0*3];
- in2= in[2*3] + in[1*3];
- in3= in[3*3] + in[2*3];
- in4= in[4*3] + in[3*3];
- in5= in[5*3] + in[4*3];
- in5 += in3;
- in3 += in1;
-
- in2= MULH(2*in2, C3);
- in3= MULH(4*in3, C3);
-
- t1 = in0 - in4;
- t2 = MULH(2*(in1 - in5), icos36h[4]);
-
- out[ 7]=
- out[10]= t1 + t2;
- out[ 1]=
- out[ 4]= t1 - t2;
-
- in0 += in4>>1;
- in4 = in0 + in2;
- in5 += 2*in1;
- in1 = MULH(in5 + in3, icos36h[1]);
- out[ 8]=
- out[ 9]= in4 + in1;
- out[ 2]=
- out[ 3]= in4 - in1;
-
- in0 -= in2;
- in5 = MULH(2*(in5 - in3), icos36h[7]);
- out[ 0]=
- out[ 5]= in0 - in5;
- out[ 6]=
- out[11]= in0 + in5;
-}
-
-/* cos(pi*i/18) */
-#define C1 FIXHR(0.98480775301220805936/2)
-#define C2 FIXHR(0.93969262078590838405/2)
-#define C3 FIXHR(0.86602540378443864676/2)
-#define C4 FIXHR(0.76604444311897803520/2)
-#define C5 FIXHR(0.64278760968653932632/2)
-#define C6 FIXHR(0.5/2)
-#define C7 FIXHR(0.34202014332566873304/2)
-#define C8 FIXHR(0.17364817766693034885/2)
-
-
-/* using Lee like decomposition followed by hand coded 9 points DCT */
-static void imdct36(int *out, int *buf, int *in, int *win)
-{
- int i, j, t0, t1, t2, t3, s0, s1, s2, s3;
- int tmp[18], *tmp1, *in1;
-
- for(i=17;i>=1;i--)
- in[i] += in[i-1];
- for(i=17;i>=3;i-=2)
- in[i] += in[i-2];
-
- for(j=0;j<2;j++) {
- tmp1 = tmp + j;
- in1 = in + j;
-#if 0
-//more accurate but slower
- int64_t t0, t1, t2, t3;
- t2 = in1[2*4] + in1[2*8] - in1[2*2];
-
- t3 = (in1[2*0] + (int64_t)(in1[2*6]>>1))<<32;
- t1 = in1[2*0] - in1[2*6];
- tmp1[ 6] = t1 - (t2>>1);
- tmp1[16] = t1 + t2;
-
- t0 = MUL64(2*(in1[2*2] + in1[2*4]), C2);
- t1 = MUL64( in1[2*4] - in1[2*8] , -2*C8);
- t2 = MUL64(2*(in1[2*2] + in1[2*8]), -C4);
-
- tmp1[10] = (t3 - t0 - t2) >> 32;
- tmp1[ 2] = (t3 + t0 + t1) >> 32;
- tmp1[14] = (t3 + t2 - t1) >> 32;
-
- tmp1[ 4] = MULH(2*(in1[2*5] + in1[2*7] - in1[2*1]), -C3);
- t2 = MUL64(2*(in1[2*1] + in1[2*5]), C1);
- t3 = MUL64( in1[2*5] - in1[2*7] , -2*C7);
- t0 = MUL64(2*in1[2*3], C3);
-
- t1 = MUL64(2*(in1[2*1] + in1[2*7]), -C5);
-
- tmp1[ 0] = (t2 + t3 + t0) >> 32;
- tmp1[12] = (t2 + t1 - t0) >> 32;
- tmp1[ 8] = (t3 - t1 - t0) >> 32;
-#else
- t2 = in1[2*4] + in1[2*8] - in1[2*2];
-
- t3 = in1[2*0] + (in1[2*6]>>1);
- t1 = in1[2*0] - in1[2*6];
- tmp1[ 6] = t1 - (t2>>1);
- tmp1[16] = t1 + t2;
-
- t0 = MULH(2*(in1[2*2] + in1[2*4]), C2);
- t1 = MULH( in1[2*4] - in1[2*8] , -2*C8);
- t2 = MULH(2*(in1[2*2] + in1[2*8]), -C4);
-
- tmp1[10] = t3 - t0 - t2;
- tmp1[ 2] = t3 + t0 + t1;
- tmp1[14] = t3 + t2 - t1;
-
- tmp1[ 4] = MULH(2*(in1[2*5] + in1[2*7] - in1[2*1]), -C3);
- t2 = MULH(2*(in1[2*1] + in1[2*5]), C1);
- t3 = MULH( in1[2*5] - in1[2*7] , -2*C7);
- t0 = MULH(2*in1[2*3], C3);
-
- t1 = MULH(2*(in1[2*1] + in1[2*7]), -C5);
-
- tmp1[ 0] = t2 + t3 + t0;
- tmp1[12] = t2 + t1 - t0;
- tmp1[ 8] = t3 - t1 - t0;
-#endif
- }
-
- i = 0;
- for(j=0;j<4;j++) {
- t0 = tmp[i];
- t1 = tmp[i + 2];
- s0 = t1 + t0;
- s2 = t1 - t0;
-
- t2 = tmp[i + 1];
- t3 = tmp[i + 3];
- s1 = MULH(2*(t3 + t2), icos36h[j]);
- s3 = MULL(t3 - t2, icos36[8 - j]);
-
- t0 = s0 + s1;
- t1 = s0 - s1;
- out[(9 + j)*SBLIMIT] = MULH(t1, win[9 + j]) + buf[9 + j];
- out[(8 - j)*SBLIMIT] = MULH(t1, win[8 - j]) + buf[8 - j];
- buf[9 + j] = MULH(t0, win[18 + 9 + j]);
- buf[8 - j] = MULH(t0, win[18 + 8 - j]);
-
- t0 = s2 + s3;
- t1 = s2 - s3;
- out[(9 + 8 - j)*SBLIMIT] = MULH(t1, win[9 + 8 - j]) + buf[9 + 8 - j];
- out[( j)*SBLIMIT] = MULH(t1, win[ j]) + buf[ j];
- buf[9 + 8 - j] = MULH(t0, win[18 + 9 + 8 - j]);
- buf[ + j] = MULH(t0, win[18 + j]);
- i += 4;
- }
-
- s0 = tmp[16];
- s1 = MULH(2*tmp[17], icos36h[4]);
- t0 = s0 + s1;
- t1 = s0 - s1;
- out[(9 + 4)*SBLIMIT] = MULH(t1, win[9 + 4]) + buf[9 + 4];
- out[(8 - 4)*SBLIMIT] = MULH(t1, win[8 - 4]) + buf[8 - 4];
- buf[9 + 4] = MULH(t0, win[18 + 9 + 4]);
- buf[8 - 4] = MULH(t0, win[18 + 8 - 4]);
-}
-
-/* header decoding. MUST check the header before because no
- consistency check is done there. Return 1 if free format found and
- that the frame size must be computed externally */
-static int decode_header(MPADecodeContext *s, uint32_t header)
-{
- int sample_rate, frame_size, mpeg25, padding;
- int sample_rate_index, bitrate_index;
- if (header & (1<<20)) {
- s->lsf = (header & (1<<19)) ? 0 : 1;
- mpeg25 = 0;
- } else {
- s->lsf = 1;
- mpeg25 = 1;
- }
-
- s->layer = 4 - ((header >> 17) & 3);
- /* extract frequency */
- sample_rate_index = (header >> 10) & 3;
- sample_rate = mpa_freq_tab[sample_rate_index] >> (s->lsf + mpeg25);
- sample_rate_index += 3 * (s->lsf + mpeg25);
- s->sample_rate_index = sample_rate_index;
- s->error_protection = ((header >> 16) & 1) ^ 1;
- s->sample_rate = sample_rate;
-
- bitrate_index = (header >> 12) & 0xf;
- padding = (header >> 9) & 1;
- //extension = (header >> 8) & 1;
- s->mode = (header >> 6) & 3;
- s->mode_ext = (header >> 4) & 3;
- //copyright = (header >> 3) & 1;
- //original = (header >> 2) & 1;
- //emphasis = header & 3;
-
- if (s->mode == MPA_MONO)
- s->nb_channels = 1;
- else
- s->nb_channels = 2;
-
- if (bitrate_index != 0) {
- frame_size = mpa_bitrate_tab[s->lsf][s->layer - 1][bitrate_index];
- s->bit_rate = frame_size * 1000;
- switch(s->layer) {
- case 1:
- frame_size = (frame_size * 12000) / sample_rate;
- frame_size = (frame_size + padding) * 4;
- break;
- case 2:
- frame_size = (frame_size * 144000) / sample_rate;
- frame_size += padding;
- break;
- default:
- case 3:
- frame_size = (frame_size * 144000) / (sample_rate << s->lsf);
- frame_size += padding;
- break;
- }
- s->frame_size = frame_size;
- } else {
- /* if no frame size computed, signal it */
- return 1;
- }
-
-#if defined(DEBUG)
- dprintf("layer%d, %d Hz, %d kbits/s, ",
- s->layer, s->sample_rate, s->bit_rate);
- if (s->nb_channels == 2) {
- if (s->layer == 3) {
- if (s->mode_ext & MODE_EXT_MS_STEREO)
- dprintf("ms-");
- if (s->mode_ext & MODE_EXT_I_STEREO)
- dprintf("i-");
- }
- dprintf("stereo");
- } else {
- dprintf("mono");
- }
- dprintf("\n");
-#endif
- return 0;
-}
-
-/* useful helper to get mpeg audio stream infos. Return -1 if error in
- header, otherwise the coded frame size in bytes */
-int mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate)
-{
- MPADecodeContext s1, *s = &s1;
-
- if (ff_mpa_check_header(head) != 0)
- return -1;
-
- if (decode_header(s, head) != 0) {
- return -1;
- }
-
- switch(s->layer) {
- case 1:
- avctx->frame_size = 384;
- break;
- case 2:
- avctx->frame_size = 1152;
- break;
- default:
- case 3:
- if (s->lsf)
- avctx->frame_size = 576;
- else
- avctx->frame_size = 1152;
- break;
- }
-
- *sample_rate = s->sample_rate;
- avctx->channels = s->nb_channels;
- avctx->bit_rate = s->bit_rate;
- avctx->sub_id = s->layer;
- return s->frame_size;
-}
-
-/* return the number of decoded frames */
-static int mp_decode_layer1(MPADecodeContext *s)
-{
- int bound, i, v, n, ch, j, mant;
- uint8_t allocation[MPA_MAX_CHANNELS][SBLIMIT];
- uint8_t scale_factors[MPA_MAX_CHANNELS][SBLIMIT];
-
- if (s->mode == MPA_JSTEREO)
- bound = (s->mode_ext + 1) * 4;
- else
- bound = SBLIMIT;
-
- /* allocation bits */
- for(i=0;i<bound;i++) {
- for(ch=0;ch<s->nb_channels;ch++) {
- allocation[ch][i] = get_bits(&s->gb, 4);
- }
- }
- for(i=bound;i<SBLIMIT;i++) {
- allocation[0][i] = get_bits(&s->gb, 4);
- }
-
- /* scale factors */
- for(i=0;i<bound;i++) {
- for(ch=0;ch<s->nb_channels;ch++) {
- if (allocation[ch][i])
- scale_factors[ch][i] = get_bits(&s->gb, 6);
- }
- }
- for(i=bound;i<SBLIMIT;i++) {
- if (allocation[0][i]) {
- scale_factors[0][i] = get_bits(&s->gb, 6);
- scale_factors[1][i] = get_bits(&s->gb, 6);
- }
- }
-
- /* compute samples */
- for(j=0;j<12;j++) {
- for(i=0;i<bound;i++) {
- for(ch=0;ch<s->nb_channels;ch++) {
- n = allocation[ch][i];
- if (n) {
- mant = get_bits(&s->gb, n + 1);
- v = l1_unscale(n, mant, scale_factors[ch][i]);
- } else {
- v = 0;
- }
- s->sb_samples[ch][j][i] = v;
- }
- }
- for(i=bound;i<SBLIMIT;i++) {
- n = allocation[0][i];
- if (n) {
- mant = get_bits(&s->gb, n + 1);
- v = l1_unscale(n, mant, scale_factors[0][i]);
- s->sb_samples[0][j][i] = v;
- v = l1_unscale(n, mant, scale_factors[1][i]);
- s->sb_samples[1][j][i] = v;
- } else {
- s->sb_samples[0][j][i] = 0;
- s->sb_samples[1][j][i] = 0;
- }
- }
- }
- return 12;
-}
-
-/* bitrate is in kb/s */
-int l2_select_table(int bitrate, int nb_channels, int freq, int lsf)
-{
- int ch_bitrate, table;
-
- ch_bitrate = bitrate / nb_channels;
- if (!lsf) {
- if ((freq == 48000 && ch_bitrate >= 56) ||
- (ch_bitrate >= 56 && ch_bitrate <= 80))
- table = 0;
- else if (freq != 48000 && ch_bitrate >= 96)
- table = 1;
- else if (freq != 32000 && ch_bitrate <= 48)
- table = 2;
- else
- table = 3;
- } else {
- table = 4;
- }
- return table;
-}
-
-static int mp_decode_layer2(MPADecodeContext *s)
-{
- int sblimit; /* number of used subbands */
- const unsigned char *alloc_table;
- int table, bit_alloc_bits, i, j, ch, bound, v;
- unsigned char bit_alloc[MPA_MAX_CHANNELS][SBLIMIT];
- unsigned char scale_code[MPA_MAX_CHANNELS][SBLIMIT];
- unsigned char scale_factors[MPA_MAX_CHANNELS][SBLIMIT][3], *sf;
- int scale, qindex, bits, steps, k, l, m, b;
-
- /* select decoding table */
- table = l2_select_table(s->bit_rate / 1000, s->nb_channels,
- s->sample_rate, s->lsf);
- sblimit = sblimit_table[table];
- alloc_table = alloc_tables[table];
-
- if (s->mode == MPA_JSTEREO)
- bound = (s->mode_ext + 1) * 4;
- else
- bound = sblimit;
-
- dprintf("bound=%d sblimit=%d\n", bound, sblimit);
-
- /* sanity check */
- if( bound > sblimit ) bound = sblimit;
-
- /* parse bit allocation */
- j = 0;
- for(i=0;i<bound;i++) {
- bit_alloc_bits = alloc_table[j];
- for(ch=0;ch<s->nb_channels;ch++) {
- bit_alloc[ch][i] = get_bits(&s->gb, bit_alloc_bits);
- }
- j += 1 << bit_alloc_bits;
- }
- for(i=bound;i<sblimit;i++) {
- bit_alloc_bits = alloc_table[j];
- v = get_bits(&s->gb, bit_alloc_bits);
- bit_alloc[0][i] = v;
- bit_alloc[1][i] = v;
- j += 1 << bit_alloc_bits;
- }
-
-#ifdef DEBUG
- {
- for(ch=0;ch<s->nb_channels;ch++) {
- for(i=0;i<sblimit;i++)
- dprintf(" %d", bit_alloc[ch][i]);
- dprintf("\n");
- }
- }
-#endif
-
- /* scale codes */
- for(i=0;i<sblimit;i++) {
- for(ch=0;ch<s->nb_channels;ch++) {
- if (bit_alloc[ch][i])
- scale_code[ch][i] = get_bits(&s->gb, 2);
- }
- }
-
- /* scale factors */
- for(i=0;i<sblimit;i++) {
- for(ch=0;ch<s->nb_channels;ch++) {
- if (bit_alloc[ch][i]) {
- sf = scale_factors[ch][i];
- switch(scale_code[ch][i]) {
- default:
- case 0:
- sf[0] = get_bits(&s->gb, 6);
- sf[1] = get_bits(&s->gb, 6);
- sf[2] = get_bits(&s->gb, 6);
- break;
- case 2:
- sf[0] = get_bits(&s->gb, 6);
- sf[1] = sf[0];
- sf[2] = sf[0];
- break;
- case 1:
- sf[0] = get_bits(&s->gb, 6);
- sf[2] = get_bits(&s->gb, 6);
- sf[1] = sf[0];
- break;
- case 3:
- sf[0] = get_bits(&s->gb, 6);
- sf[2] = get_bits(&s->gb, 6);
- sf[1] = sf[2];
- break;
- }
- }
- }
- }
-
-#ifdef DEBUG
- for(ch=0;ch<s->nb_channels;ch++) {
- for(i=0;i<sblimit;i++) {
- if (bit_alloc[ch][i]) {
- sf = scale_factors[ch][i];
- dprintf(" %d %d %d", sf[0], sf[1], sf[2]);
- } else {
- dprintf(" -");
- }
- }
- dprintf("\n");
- }
-#endif
-
- /* samples */
- for(k=0;k<3;k++) {
- for(l=0;l<12;l+=3) {
- j = 0;
- for(i=0;i<bound;i++) {
- bit_alloc_bits = alloc_table[j];
- for(ch=0;ch<s->nb_channels;ch++) {
- b = bit_alloc[ch][i];
- if (b) {
- scale = scale_factors[ch][i][k];
- qindex = alloc_table[j+b];
- bits = quant_bits[qindex];
- if (bits < 0) {
- /* 3 values at the same time */
- v = get_bits(&s->gb, -bits);
- steps = quant_steps[qindex];
- s->sb_samples[ch][k * 12 + l + 0][i] =
- l2_unscale_group(steps, v % steps, scale);
- v = v / steps;
- s->sb_samples[ch][k * 12 + l + 1][i] =
- l2_unscale_group(steps, v % steps, scale);
- v = v / steps;
- s->sb_samples[ch][k * 12 + l + 2][i] =
- l2_unscale_group(steps, v, scale);
- } else {
- for(m=0;m<3;m++) {
- v = get_bits(&s->gb, bits);
- v = l1_unscale(bits - 1, v, scale);
- s->sb_samples[ch][k * 12 + l + m][i] = v;
- }
- }
- } else {
- s->sb_samples[ch][k * 12 + l + 0][i] = 0;
- s->sb_samples[ch][k * 12 + l + 1][i] = 0;
- s->sb_samples[ch][k * 12 + l + 2][i] = 0;
- }
- }
- /* next subband in alloc table */
- j += 1 << bit_alloc_bits;
- }
- /* XXX: find a way to avoid this duplication of code */
- for(i=bound;i<sblimit;i++) {
- bit_alloc_bits = alloc_table[j];
- b = bit_alloc[0][i];
- if (b) {
- int mant, scale0, scale1;
- scale0 = scale_factors[0][i][k];
- scale1 = scale_factors[1][i][k];
- qindex = alloc_table[j+b];
- bits = quant_bits[qindex];
- if (bits < 0) {
- /* 3 values at the same time */
- v = get_bits(&s->gb, -bits);
- steps = quant_steps[qindex];
- mant = v % steps;
- v = v / steps;
- s->sb_samples[0][k * 12 + l + 0][i] =
- l2_unscale_group(steps, mant, scale0);
- s->sb_samples[1][k * 12 + l + 0][i] =
- l2_unscale_group(steps, mant, scale1);
- mant = v % steps;
- v = v / steps;
- s->sb_samples[0][k * 12 + l + 1][i] =
- l2_unscale_group(steps, mant, scale0);
- s->sb_samples[1][k * 12 + l + 1][i] =
- l2_unscale_group(steps, mant, scale1);
- s->sb_samples[0][k * 12 + l + 2][i] =
- l2_unscale_group(steps, v, scale0);
- s->sb_samples[1][k * 12 + l + 2][i] =
- l2_unscale_group(steps, v, scale1);
- } else {
- for(m=0;m<3;m++) {
- mant = get_bits(&s->gb, bits);
- s->sb_samples[0][k * 12 + l + m][i] =
- l1_unscale(bits - 1, mant, scale0);
- s->sb_samples[1][k * 12 + l + m][i] =
- l1_unscale(bits - 1, mant, scale1);
- }
- }
- } else {
- s->sb_samples[0][k * 12 + l + 0][i] = 0;
- s->sb_samples[0][k * 12 + l + 1][i] = 0;
- s->sb_samples[0][k * 12 + l + 2][i] = 0;
- s->sb_samples[1][k * 12 + l + 0][i] = 0;
- s->sb_samples[1][k * 12 + l + 1][i] = 0;
- s->sb_samples[1][k * 12 + l + 2][i] = 0;
- }
- /* next subband in alloc table */
- j += 1 << bit_alloc_bits;
- }
- /* fill remaining samples to zero */
- for(i=sblimit;i<SBLIMIT;i++) {
- for(ch=0;ch<s->nb_channels;ch++) {
- s->sb_samples[ch][k * 12 + l + 0][i] = 0;
- s->sb_samples[ch][k * 12 + l + 1][i] = 0;
- s->sb_samples[ch][k * 12 + l + 2][i] = 0;
- }
- }
- }
- }
- return 3 * 12;
-}
-
-static 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;
- slen[0] = sf;
-}
-
-static void exponents_from_scale_factors(MPADecodeContext *s,
- GranuleDef *g,
- int16_t *exponents)
-{
- const uint8_t *bstab, *pretab;
- int len, i, j, k, l, v0, shift, gain, gains[3];
- int16_t *exp_ptr;
-
- exp_ptr = exponents;
- gain = g->global_gain - 210;
- shift = g->scalefac_scale + 1;
-
- bstab = band_size_long[s->sample_rate_index];
- pretab = mpa_pretab[g->preflag];
- for(i=0;i<g->long_end;i++) {
- v0 = gain - ((g->scale_factors[i] + pretab[i]) << shift) + 400;
- len = bstab[i];
- for(j=len;j>0;j--)
- *exp_ptr++ = v0;
- }
-
- if (g->short_start < 13) {
- bstab = band_size_short[s->sample_rate_index];
- gains[0] = gain - (g->subblock_gain[0] << 3);
- gains[1] = gain - (g->subblock_gain[1] << 3);
- gains[2] = gain - (g->subblock_gain[2] << 3);
- k = g->long_end;
- for(i=g->short_start;i<13;i++) {
- len = bstab[i];
- for(l=0;l<3;l++) {
- v0 = gains[l] - (g->scale_factors[k++] << shift) + 400;
- for(j=len;j>0;j--)
- *exp_ptr++ = v0;
- }
- }
- }
-}
-
-/* handle n = 0 too */
-static inline int get_bitsz(GetBitContext *s, int n)
-{
- if (n == 0)
- return 0;
- else
- return get_bits(s, n);
-}
-
-static int huffman_decode(MPADecodeContext *s, GranuleDef *g,
- int16_t *exponents, int end_pos2)
-{
- int s_index;
- int i;
- int last_pos, bits_left;
- VLC *vlc;
- int end_pos= FFMIN(end_pos2, s->gb.size_in_bits);
-
- /* low frequencies (called big values) */
- s_index = 0;
- for(i=0;i<3;i++) {
- int j, k, l, linbits;
- j = g->region_size[i];
- if (j == 0)
- continue;
- /* select vlc table */
- k = g->table_select[i];
- l = mpa_huff_data[k][0];
- linbits = mpa_huff_data[k][1];
- vlc = &huff_vlc[l];
-
- if(!l){
- memset(&g->sb_hybrid[s_index], 0, sizeof(*g->sb_hybrid)*2*j);
- s_index += 2*j;
- continue;
- }
-
- /* read huffcode and compute each couple */
- for(;j>0;j--) {
- int exponent, x, y, v;
- int pos= get_bits_count(&s->gb);
-
- if (pos >= end_pos){
-// av_log(NULL, AV_LOG_ERROR, "pos: %d %d %d %d\n", pos, end_pos, end_pos2, s_index);
- if(s->in_gb.buffer && pos >= s->gb.size_in_bits){
- s->gb= s->in_gb;
- s->in_gb.buffer=NULL;
- assert((get_bits_count(&s->gb) & 7) == 0);
- skip_bits_long(&s->gb, pos - end_pos);
- end_pos2=
- end_pos= end_pos2 + get_bits_count(&s->gb) - pos;
- pos= get_bits_count(&s->gb);
- }
-// av_log(NULL, AV_LOG_ERROR, "new pos: %d %d\n", pos, end_pos);
- if(pos >= end_pos)
- break;
- }
- y = get_vlc2(&s->gb, vlc->table, 7, 3);
-
- if(!y){
- g->sb_hybrid[s_index ] =
- g->sb_hybrid[s_index+1] = 0;
- s_index += 2;
- continue;
- }
-
- exponent= exponents[s_index];
-
- dprintf("region=%d n=%d x=%d y=%d exp=%d\n",
- i, g->region_size[i] - j, x, y, exponent);
- if(y&16){
- x = y >> 5;
- y = y & 0x0f;
- if (x < 15){
- v = expval_table[ exponent ][ x ];
-// v = expval_table[ (exponent&3) ][ x ] >> FFMIN(0 - (exponent>>2), 31);
- }else{
- x += get_bitsz(&s->gb, linbits);
- v = l3_unscale(x, exponent);
- }
- if (get_bits1(&s->gb))
- v = -v;
- g->sb_hybrid[s_index] = v;
- if (y < 15){
- v = expval_table[ exponent ][ y ];
- }else{
- y += get_bitsz(&s->gb, linbits);
- v = l3_unscale(y, exponent);
- }
- if (get_bits1(&s->gb))
- v = -v;
- g->sb_hybrid[s_index+1] = v;
- }else{
- x = y >> 5;
- y = y & 0x0f;
- x += y;
- if (x < 15){
- v = expval_table[ exponent ][ x ];
- }else{
- x += get_bitsz(&s->gb, linbits);
- v = l3_unscale(x, exponent);
- }
- if (get_bits1(&s->gb))
- v = -v;
- g->sb_hybrid[s_index+!!y] = v;
- g->sb_hybrid[s_index+ !y] = 0;
- }
- s_index+=2;
- }
- }
-
- /* high frequencies */
- vlc = &huff_quad_vlc[g->count1table_select];
- last_pos=0;
- while (s_index <= 572) {
- int pos, code;
- pos = get_bits_count(&s->gb);
- if (pos >= end_pos) {
- if (pos > end_pos2 && last_pos){
- /* some encoders generate an incorrect size for this
- part. We must go back into the data */
- s_index -= 4;
- skip_bits_long(&s->gb, last_pos - pos);
- av_log(NULL, AV_LOG_INFO, "overread, skip %d enddists: %d %d\n", last_pos - pos, end_pos-pos, end_pos2-pos);
- if(s->error_resilience >= FF_ER_COMPLIANT)
- s_index=0;
- break;
- }
-// av_log(NULL, AV_LOG_ERROR, "pos2: %d %d %d %d\n", pos, end_pos, end_pos2, s_index);
- if(s->in_gb.buffer && pos >= s->gb.size_in_bits){
- s->gb= s->in_gb;
- s->in_gb.buffer=NULL;
- assert((get_bits_count(&s->gb) & 7) == 0);
- skip_bits_long(&s->gb, pos - end_pos);
- end_pos2=
- end_pos= end_pos2 + get_bits_count(&s->gb) - pos;
- pos= get_bits_count(&s->gb);
- }
-// av_log(NULL, AV_LOG_ERROR, "new pos2: %d %d %d\n", pos, end_pos, s_index);
- if(pos >= end_pos)
- break;
- }
- last_pos= pos;
-
- code = get_vlc2(&s->gb, vlc->table, vlc->bits, 1);
- dprintf("t=%d code=%d\n", g->count1table_select, code);
- g->sb_hybrid[s_index+0]=
- g->sb_hybrid[s_index+1]=
- g->sb_hybrid[s_index+2]=
- g->sb_hybrid[s_index+3]= 0;
- while(code){
- const static int idxtab[16]={3,3,2,2,1,1,1,1,0,0,0,0,0,0,0,0};
- int v;
- int pos= s_index+idxtab[code];
- code ^= 8>>idxtab[code];
- v = exp_table[ exponents[pos] ];
-// v = exp_table[ (exponents[pos]&3) ] >> FFMIN(0 - (exponents[pos]>>2), 31);
- if(get_bits1(&s->gb))
- v = -v;
- g->sb_hybrid[pos] = v;
- }
- s_index+=4;
- }
- /* skip extension bits */
- bits_left = end_pos - get_bits_count(&s->gb);
-//av_log(NULL, AV_LOG_ERROR, "left:%d buf:%p\n", bits_left, s->in_gb.buffer);
- if (bits_left < 0 || bits_left > 500) {
- av_log(NULL, AV_LOG_ERROR, "bits_left=%d\n", bits_left);
- s_index=0;
- }else if(bits_left > 0 && s->error_resilience >= FF_ER_AGGRESSIVE){
- av_log(NULL, AV_LOG_ERROR, "bits_left=%d\n", bits_left);
- s_index=0;
- }
- memset(&g->sb_hybrid[s_index], 0, sizeof(*g->sb_hybrid)*(576 - s_index));
- skip_bits_long(&s->gb, bits_left);
-
- return 0;
-}
-
-/* Reorder short blocks from bitstream order to interleaved order. It
- would be faster to do it in parsing, but the code would be far more
- complicated */
-static void reorder_block(MPADecodeContext *s, GranuleDef *g)
-{
- int i, j, len;
- int32_t *ptr, *dst, *ptr1;
- int32_t tmp[576];
-
- if (g->block_type != 2)
- return;
-
- if (g->switch_point) {
- if (s->sample_rate_index != 8) {
- ptr = g->sb_hybrid + 36;
- } else {
- ptr = g->sb_hybrid + 48;
- }
- } else {
- ptr = g->sb_hybrid;
- }
-
- for(i=g->short_start;i<13;i++) {
- len = band_size_short[s->sample_rate_index][i];
- ptr1 = ptr;
- dst = tmp;
- for(j=len;j>0;j--) {
- *dst++ = ptr[0*len];
- *dst++ = ptr[1*len];
- *dst++ = ptr[2*len];
- ptr++;
- }
- ptr+=2*len;
- memcpy(ptr1, tmp, len * 3 * sizeof(*ptr1));
- }
-}
-
-#define ISQRT2 FIXR(0.70710678118654752440)
-
-static void compute_stereo(MPADecodeContext *s,
- GranuleDef *g0, GranuleDef *g1)
-{
- int i, j, k, l;
- int32_t v1, v2;
- int sf_max, tmp0, tmp1, sf, len, non_zero_found;
- int32_t (*is_tab)[16];
- int32_t *tab0, *tab1;
- int non_zero_found_short[3];
-
- /* intensity stereo */
- if (s->mode_ext & MODE_EXT_I_STEREO) {
- if (!s->lsf) {
- is_tab = is_table;
- sf_max = 7;
- } else {
- is_tab = is_table_lsf[g1->scalefac_compress & 1];
- sf_max = 16;
- }
-
- tab0 = g0->sb_hybrid + 576;
- tab1 = g1->sb_hybrid + 576;
-
- non_zero_found_short[0] = 0;
- non_zero_found_short[1] = 0;
- non_zero_found_short[2] = 0;
- k = (13 - g1->short_start) * 3 + g1->long_end - 3;
- for(i = 12;i >= g1->short_start;i--) {
- /* for last band, use previous scale factor */
- if (i != 11)
- k -= 3;
- len = band_size_short[s->sample_rate_index][i];
- for(l=2;l>=0;l--) {
- tab0 -= len;
- tab1 -= len;
- if (!non_zero_found_short[l]) {
- /* test if non zero band. if so, stop doing i-stereo */
- for(j=0;j<len;j++) {
- if (tab1[j] != 0) {
- non_zero_found_short[l] = 1;
- goto found1;
- }
- }
- sf = g1->scale_factors[k + l];
- if (sf >= sf_max)
- goto found1;
-
- v1 = is_tab[0][sf];
- v2 = is_tab[1][sf];
- for(j=0;j<len;j++) {
- tmp0 = tab0[j];
- tab0[j] = MULL(tmp0, v1);
- tab1[j] = MULL(tmp0, v2);
- }
- } else {
- found1:
- if (s->mode_ext & MODE_EXT_MS_STEREO) {
- /* lower part of the spectrum : do ms stereo
- if enabled */
- for(j=0;j<len;j++) {
- tmp0 = tab0[j];
- tmp1 = tab1[j];
- tab0[j] = MULL(tmp0 + tmp1, ISQRT2);
- tab1[j] = MULL(tmp0 - tmp1, ISQRT2);
- }
- }
- }
- }
- }
-
- non_zero_found = non_zero_found_short[0] |
- non_zero_found_short[1] |
- non_zero_found_short[2];
-
- for(i = g1->long_end - 1;i >= 0;i--) {
- len = band_size_long[s->sample_rate_index][i];
- tab0 -= len;
- tab1 -= len;
- /* test if non zero band. if so, stop doing i-stereo */
- if (!non_zero_found) {
- for(j=0;j<len;j++) {
- if (tab1[j] != 0) {
- non_zero_found = 1;
- goto found2;
- }
- }
- /* for last band, use previous scale factor */
- k = (i == 21) ? 20 : i;
- sf = g1->scale_factors[k];
- if (sf >= sf_max)
- goto found2;
- v1 = is_tab[0][sf];
- v2 = is_tab[1][sf];
- for(j=0;j<len;j++) {
- tmp0 = tab0[j];
- tab0[j] = MULL(tmp0, v1);
- tab1[j] = MULL(tmp0, v2);
- }
- } else {
- found2:
- if (s->mode_ext & MODE_EXT_MS_STEREO) {
- /* lower part of the spectrum : do ms stereo
- if enabled */
- for(j=0;j<len;j++) {
- tmp0 = tab0[j];
- tmp1 = tab1[j];
- tab0[j] = MULL(tmp0 + tmp1, ISQRT2);
- tab1[j] = MULL(tmp0 - tmp1, ISQRT2);
- }
- }
- }
- }
- } else if (s->mode_ext & MODE_EXT_MS_STEREO) {
- /* ms stereo ONLY */
- /* NOTE: the 1/sqrt(2) normalization factor is included in the
- global gain */
- tab0 = g0->sb_hybrid;
- tab1 = g1->sb_hybrid;
- for(i=0;i<576;i++) {
- tmp0 = tab0[i];
- tmp1 = tab1[i];
- tab0[i] = tmp0 + tmp1;
- tab1[i] = tmp0 - tmp1;
- }
- }
-}
-
-static void compute_antialias_integer(MPADecodeContext *s,
- GranuleDef *g)
-{
- int32_t *ptr, *csa;
- int n, i;
-
- /* we antialias only "long" bands */
- if (g->block_type == 2) {
- if (!g->switch_point)
- return;
- /* XXX: check this for 8000Hz case */
- n = 1;
- } else {
- n = SBLIMIT - 1;
- }
-
- ptr = g->sb_hybrid + 18;
- for(i = n;i > 0;i--) {
- int tmp0, tmp1, tmp2;
- csa = &csa_table[0][0];
-#define INT_AA(j) \
- tmp0 = ptr[-1-j];\
- tmp1 = ptr[ j];\
- tmp2= MULH(tmp0 + tmp1, csa[0+4*j]);\
- ptr[-1-j] = 4*(tmp2 - MULH(tmp1, csa[2+4*j]));\
- ptr[ j] = 4*(tmp2 + MULH(tmp0, csa[3+4*j]));
-
- INT_AA(0)
- INT_AA(1)
- INT_AA(2)
- INT_AA(3)
- INT_AA(4)
- INT_AA(5)
- INT_AA(6)
- INT_AA(7)
-
- ptr += 18;
- }
-}
-
-static void compute_antialias_float(MPADecodeContext *s,
- GranuleDef *g)
-{
- int32_t *ptr;
- int n, i;
-
- /* we antialias only "long" bands */
- if (g->block_type == 2) {
- if (!g->switch_point)
- return;
- /* XXX: check this for 8000Hz case */
- n = 1;
- } else {
- n = SBLIMIT - 1;
- }
-
- ptr = g->sb_hybrid + 18;
- for(i = n;i > 0;i--) {
- float tmp0, tmp1;
- float *csa = &csa_table_float[0][0];
-#define FLOAT_AA(j)\
- tmp0= ptr[-1-j];\
- tmp1= ptr[ j];\
- ptr[-1-j] = lrintf(tmp0 * csa[0+4*j] - tmp1 * csa[1+4*j]);\
- ptr[ j] = lrintf(tmp0 * csa[1+4*j] + tmp1 * csa[0+4*j]);
-
- FLOAT_AA(0)
- FLOAT_AA(1)
- FLOAT_AA(2)
- FLOAT_AA(3)
- FLOAT_AA(4)
- FLOAT_AA(5)
- FLOAT_AA(6)
- FLOAT_AA(7)
-
- ptr += 18;
- }
-}
-
-static void compute_imdct(MPADecodeContext *s,
- GranuleDef *g,
- int32_t *sb_samples,
- int32_t *mdct_buf)
-{
- int32_t *ptr, *win, *win1, *buf, *out_ptr, *ptr1;
- int32_t out2[12];
- int i, j, mdct_long_end, v, sblimit;
-
- /* find last non zero block */
- ptr = g->sb_hybrid + 576;
- ptr1 = g->sb_hybrid + 2 * 18;
- while (ptr >= ptr1) {
- ptr -= 6;
- v = ptr[0] | ptr[1] | ptr[2] | ptr[3] | ptr[4] | ptr[5];
- if (v != 0)
- break;
- }
- sblimit = ((ptr - g->sb_hybrid) / 18) + 1;
-
- if (g->block_type == 2) {
- /* XXX: check for 8000 Hz */
- if (g->switch_point)
- mdct_long_end = 2;
- else
- mdct_long_end = 0;
- } else {
- mdct_long_end = sblimit;
- }
-
- buf = mdct_buf;
- ptr = g->sb_hybrid;
- for(j=0;j<mdct_long_end;j++) {
- /* apply window & overlap with previous buffer */
- out_ptr = sb_samples + j;
- /* select window */
- if (g->switch_point && j < 2)
- win1 = mdct_win[0];
- else
- win1 = mdct_win[g->block_type];
- /* select frequency inversion */
- win = win1 + ((4 * 36) & -(j & 1));
- imdct36(out_ptr, buf, ptr, win);
- out_ptr += 18*SBLIMIT;
- ptr += 18;
- buf += 18;
- }
- for(j=mdct_long_end;j<sblimit;j++) {
- /* select frequency inversion */
- win = mdct_win[2] + ((4 * 36) & -(j & 1));
- out_ptr = sb_samples + j;
-
- for(i=0; i<6; i++){
- *out_ptr = buf[i];
- out_ptr += SBLIMIT;
- }
- imdct12(out2, ptr + 0);
- for(i=0;i<6;i++) {
- *out_ptr = MULH(out2[i], win[i]) + buf[i + 6*1];
- buf[i + 6*2] = MULH(out2[i + 6], win[i + 6]);
- out_ptr += SBLIMIT;
- }
- imdct12(out2, ptr + 1);
- for(i=0;i<6;i++) {
- *out_ptr = MULH(out2[i], win[i]) + buf[i + 6*2];
- buf[i + 6*0] = MULH(out2[i + 6], win[i + 6]);
- out_ptr += SBLIMIT;
- }
- imdct12(out2, ptr + 2);
- for(i=0;i<6;i++) {
- buf[i + 6*0] = MULH(out2[i], win[i]) + buf[i + 6*0];
- buf[i + 6*1] = MULH(out2[i + 6], win[i + 6]);
- buf[i + 6*2] = 0;
- }
- ptr += 18;
- buf += 18;
- }
- /* zero bands */
- for(j=sblimit;j<SBLIMIT;j++) {
- /* overlap */
- out_ptr = sb_samples + j;
- for(i=0;i<18;i++) {
- *out_ptr = buf[i];
- buf[i] = 0;
- out_ptr += SBLIMIT;
- }
- buf += 18;
- }
-}
-
-#if defined(DEBUG)
-void sample_dump(int fnum, int32_t *tab, int n)
-{
- static FILE *files[16], *f;
- char buf[512];
- int i;
- int32_t v;
-
- f = files[fnum];
- if (!f) {
- snprintf(buf, sizeof(buf), "/tmp/out%d.%s.pcm",
- fnum,
-#ifdef USE_HIGHPRECISION
- "hp"
-#else
- "lp"
-#endif
- );
- f = fopen(buf, "w");
- if (!f)
- return;
- files[fnum] = f;
- }
-
- if (fnum == 0) {
- static int pos = 0;
- av_log(NULL, AV_LOG_DEBUG, "pos=%d\n", pos);
- for(i=0;i<n;i++) {
- av_log(NULL, AV_LOG_DEBUG, " %0.4f", (double)tab[i] / FRAC_ONE);
- if ((i % 18) == 17)
- av_log(NULL, AV_LOG_DEBUG, "\n");
- }
- pos += n;
- }
- for(i=0;i<n;i++) {
- /* normalize to 23 frac bits */
- v = tab[i] << (23 - FRAC_BITS);
- fwrite(&v, 1, sizeof(int32_t), f);
- }
-}
-#endif
-
-
-/* main layer3 decoding function */
-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;
- int16_t exponents[576];
-
- /* read side info */
- if (s->lsf) {
- main_data_begin = get_bits(&s->gb, 8);
- private_bits = get_bits(&s->gb, s->nb_channels);
- nb_granules = 1;
- } else {
- main_data_begin = get_bits(&s->gb, 9);
- if (s->nb_channels == 2)
- private_bits = get_bits(&s->gb, 3);
- else
- private_bits = get_bits(&s->gb, 5);
- nb_granules = 2;
- for(ch=0;ch<s->nb_channels;ch++) {
- granules[ch][0].scfsi = 0; /* all scale factors are transmitted */
- granules[ch][1].scfsi = get_bits(&s->gb, 4);
- }
- }
-
- for(gr=0;gr<nb_granules;gr++) {
- for(ch=0;ch<s->nb_channels;ch++) {
- dprintf("gr=%d ch=%d: side_info\n", gr, ch);
- g = &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){
- av_log(NULL, AV_LOG_ERROR, "big_values too big\n");
- return -1;
- }
-
- g->global_gain = get_bits(&s->gb, 8);
- /* if MS stereo only is selected, we precompute the
- 1/sqrt(2) renormalization factor */
- if ((s->mode_ext & (MODE_EXT_MS_STEREO | MODE_EXT_I_STEREO)) ==
- MODE_EXT_MS_STEREO)
- g->global_gain -= 2;
- if (s->lsf)
- g->scalefac_compress = get_bits(&s->gb, 9);
- else
- g->scalefac_compress = get_bits(&s->gb, 4);
- blocksplit_flag = get_bits(&s->gb, 1);
- if (blocksplit_flag) {
- g->block_type = get_bits(&s->gb, 2);
- if (g->block_type == 0){
- av_log(NULL, AV_LOG_ERROR, "invalid block type\n");
- return -1;
- }
- g->switch_point = get_bits(&s->gb, 1);
- for(i=0;i<2;i++)
- g->table_select[i] = get_bits(&s->gb, 5);
- for(i=0;i<3;i++)
- g->subblock_gain[i] = get_bits(&s->gb, 3);
- /* compute huffman coded region sizes */
- if (g->block_type == 2)
- g->region_size[0] = (36 / 2);
- else {
- if (s->sample_rate_index <= 2)
- g->region_size[0] = (36 / 2);
- else if (s->sample_rate_index != 8)
- g->region_size[0] = (54 / 2);
- else
- g->region_size[0] = (108 / 2);
- }
- g->region_size[1] = (576 / 2);
- } else {
- int region_address1, region_address2, l;
- g->block_type = 0;
- g->switch_point = 0;
- for(i=0;i<3;i++)
- g->table_select[i] = get_bits(&s->gb, 5);
- /* compute huffman coded region sizes */
- region_address1 = get_bits(&s->gb, 4);
- region_address2 = get_bits(&s->gb, 3);
- dprintf("region1=%d region2=%d\n",
- region_address1, region_address2);
- g->region_size[0] =
- band_index_long[s->sample_rate_index][region_address1 + 1] >> 1;
- l = region_address1 + region_address2 + 2;
- /* should not overflow */
- if (l > 22)
- l = 22;
- g->region_size[1] =
- band_index_long[s->sample_rate_index][l] >> 1;
- }
- /* convert region offsets to region sizes and truncate
- size to big_values */
- g->region_size[2] = (576 / 2);
- j = 0;
- for(i=0;i<3;i++) {
- k = FFMIN(g->region_size[i], g->big_values);
- g->region_size[i] = k - j;
- j = k;
- }
-
- /* compute band indexes */
- if (g->block_type == 2) {
- if (g->switch_point) {
- /* if switched mode, we handle the 36 first samples as
- long blocks. For 8000Hz, we handle the 48 first
- exponents as long blocks (XXX: check this!) */
- if (s->sample_rate_index <= 2)
- g->long_end = 8;
- else if (s->sample_rate_index != 8)
- g->long_end = 6;
- else
- g->long_end = 4; /* 8000 Hz */
-
- g->short_start = 2 + (s->sample_rate_index != 8);
- } else {
- g->long_end = 0;
- g->short_start = 0;
- }
- } else {
- g->short_start = 13;
- g->long_end = 22;
- }
-
- g->preflag = 0;
- if (!s->lsf)
- g->preflag = get_bits(&s->gb, 1);
- g->scalefac_scale = get_bits(&s->gb, 1);
- g->count1table_select = get_bits(&s->gb, 1);
- dprintf("block_type=%d switch_point=%d\n",
- g->block_type, g->switch_point);
- }
- }
-
- if (!s->adu_mode) {
- const uint8_t *ptr = s->gb.buffer + (get_bits_count(&s->gb)>>3);
- assert((get_bits_count(&s->gb) & 7) == 0);
- /* now we get bits from the main_data_begin offset */
- dprintf("seekback: %d\n", main_data_begin);
-//av_log(NULL, AV_LOG_ERROR, "backstep:%d, lastbuf:%d\n", main_data_begin, s->last_buf_size);
-
- memcpy(s->last_buf + s->last_buf_size, ptr, EXTRABYTES);
- s->in_gb= s->gb;
- init_get_bits(&s->gb, s->last_buf, s->last_buf_size*8);
- skip_bits_long(&s->gb, 8*(s->last_buf_size - main_data_begin));
- }
-
- for(gr=0;gr<nb_granules;gr++) {
- for(ch=0;ch<s->nb_channels;ch++) {
- g = &granules[ch][gr];
- if(get_bits_count(&s->gb)<0){
- av_log(NULL, AV_LOG_ERROR, "mdb:%d, lastbuf:%d skiping 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));
- if(get_bits_count(&s->gb) >= s->gb.size_in_bits && s->in_gb.buffer){
- skip_bits_long(&s->in_gb, get_bits_count(&s->gb) - s->gb.size_in_bits);
- s->gb= s->in_gb;
- s->in_gb.buffer=NULL;
- }
- continue;
- }
-
- bits_pos = get_bits_count(&s->gb);
-
- if (!s->lsf) {
- uint8_t *sc;
- int slen, slen1, slen2;
-
- /* MPEG1 scale factors */
- slen1 = slen_table[0][g->scalefac_compress];
- slen2 = slen_table[1][g->scalefac_compress];
- dprintf("slen1=%d slen2=%d\n", slen1, slen2);
- if (g->block_type == 2) {
- n = g->switch_point ? 17 : 18;
- j = 0;
- if(slen1){
- for(i=0;i<n;i++)
- g->scale_factors[j++] = get_bits(&s->gb, slen1);
- }else{
- for(i=0;i<n;i++)
- g->scale_factors[j++] = 0;
- }
- if(slen2){
- for(i=0;i<18;i++)
- g->scale_factors[j++] = get_bits(&s->gb, slen2);
- for(i=0;i<3;i++)
- g->scale_factors[j++] = 0;
- }else{
- for(i=0;i<21;i++)
- g->scale_factors[j++] = 0;
- }
- } else {
- sc = granules[ch][0].scale_factors;
- j = 0;
- for(k=0;k<4;k++) {
- n = (k == 0 ? 6 : 5);
- if ((g->scfsi & (0x8 >> k)) == 0) {
- slen = (k < 2) ? slen1 : slen2;
- if(slen){
- for(i=0;i<n;i++)
- g->scale_factors[j++] = get_bits(&s->gb, slen);
- }else{
- for(i=0;i<n;i++)
- g->scale_factors[j++] = 0;
- }
- } else {
- /* simply copy from last granule */
- for(i=0;i<n;i++) {
- g->scale_factors[j] = sc[j];
- j++;
- }
- }
- }
- g->scale_factors[j++] = 0;
- }
-#if defined(DEBUG)
- {
- dprintf("scfsi=%x gr=%d ch=%d scale_factors:\n",
- g->scfsi, gr, ch);
- for(i=0;i<j;i++)
- dprintf(" %d", g->scale_factors[i]);
- dprintf("\n");
- }
-#endif
- } else {
- int tindex, tindex2, slen[4], sl, sf;
-
- /* LSF scale factors */
- if (g->block_type == 2) {
- tindex = g->switch_point ? 2 : 1;
- } else {
- tindex = 0;
- }
- sf = g->scalefac_compress;
- if ((s->mode_ext & MODE_EXT_I_STEREO) && ch == 1) {
- /* intensity stereo case */
- sf >>= 1;
- if (sf < 180) {
- lsf_sf_expand(slen, sf, 6, 6, 0);
- tindex2 = 3;
- } else if (sf < 244) {
- lsf_sf_expand(slen, sf - 180, 4, 4, 0);
- tindex2 = 4;
- } else {
- lsf_sf_expand(slen, sf - 244, 3, 0, 0);
- tindex2 = 5;
- }
- } else {
- /* normal case */
- if (sf < 400) {
- lsf_sf_expand(slen, sf, 5, 4, 4);
- tindex2 = 0;
- } else if (sf < 500) {
- lsf_sf_expand(slen, sf - 400, 5, 4, 0);
- tindex2 = 1;
- } else {
- lsf_sf_expand(slen, sf - 500, 3, 0, 0);
- tindex2 = 2;
- g->preflag = 1;
- }
- }
-
- j = 0;
- for(k=0;k<4;k++) {
- n = lsf_nsf_table[tindex2][tindex][k];
- sl = slen[k];
- if(sl){
- for(i=0;i<n;i++)
- g->scale_factors[j++] = get_bits(&s->gb, sl);
- }else{
- for(i=0;i<n;i++)
- g->scale_factors[j++] = 0;
- }
- }
- /* XXX: should compute exact size */
- for(;j<40;j++)
- g->scale_factors[j] = 0;
-#if defined(DEBUG)
- {
- dprintf("gr=%d ch=%d scale_factors:\n",
- gr, ch);
- for(i=0;i<40;i++)
- dprintf(" %d", g->scale_factors[i]);
- dprintf("\n");
- }
-#endif
- }
-
- exponents_from_scale_factors(s, g, exponents);
-
- /* read Huffman coded residue */
- huffman_decode(s, g, exponents, bits_pos + g->part2_3_length);
-#if defined(DEBUG)
- sample_dump(0, g->sb_hybrid, 576);
-#endif
- } /* ch */
-
- if (s->nb_channels == 2)
- compute_stereo(s, &granules[0][gr], &granules[1][gr]);
-
- for(ch=0;ch<s->nb_channels;ch++) {
- g = &granules[ch][gr];
-
- reorder_block(s, g);
-#if defined(DEBUG)
- sample_dump(0, g->sb_hybrid, 576);
-#endif
- s->compute_antialias(s, g);
-#if defined(DEBUG)
- sample_dump(1, g->sb_hybrid, 576);
-#endif
- compute_imdct(s, g, &s->sb_samples[ch][18 * gr][0], s->mdct_buf[ch]);
-#if defined(DEBUG)
- sample_dump(2, &s->sb_samples[ch][18 * gr][0], 576);
-#endif
- }
- } /* gr */
- if(get_bits_count(&s->gb)<0)
- skip_bits_long(&s->gb, -get_bits_count(&s->gb));
- return nb_granules * 18;
-}
-
-static int mp_decode_frame(MPADecodeContext *s,
- OUT_INT *samples, const uint8_t *buf, int buf_size)
-{
- int i, nb_frames, ch;
- OUT_INT *samples_ptr;
-
- init_get_bits(&s->gb, buf + HEADER_SIZE, (buf_size - HEADER_SIZE)*8);
-
- /* skip error protection field */
- if (s->error_protection)
- get_bits(&s->gb, 16);
-
- dprintf("frame %d:\n", s->frame_count);
- switch(s->layer) {
- case 1:
- nb_frames = mp_decode_layer1(s);
- break;
- case 2:
- nb_frames = mp_decode_layer2(s);
- break;
- case 3:
- default:
- nb_frames = mp_decode_layer3(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;
- 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;
- }else
- av_log(NULL, AV_LOG_ERROR, "invalid old backstep %d\n", i);
- s->gb= s->in_gb;
- s->in_gb.buffer= NULL;
- }
-
- 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;
-
- if(i<0 || i > BACKSTEP_SIZE || nb_frames<0){
- av_log(NULL, AV_LOG_ERROR, "invalid new backstep %d\n", i);
- i= FFMIN(BACKSTEP_SIZE, buf_size - HEADER_SIZE);
- }
- assert(i <= buf_size - HEADER_SIZE && i>= 0);
- memcpy(s->last_buf + s->last_buf_size, s->gb.buffer + buf_size - HEADER_SIZE - i, i);
- s->last_buf_size += i;
-
- break;
- }
-#if defined(DEBUG)
- for(i=0;i<nb_frames;i++) {
- for(ch=0;ch<s->nb_channels;ch++) {
- int j;
- dprintf("%d-%d:", i, ch);
- for(j=0;j<SBLIMIT;j++)
- dprintf(" %0.6f", (double)s->sb_samples[ch][i][j] / FRAC_ONE);
- dprintf("\n");
- }
- }
-#endif
- /* apply the synthesis filter */
- for(ch=0;ch<s->nb_channels;ch++) {
- samples_ptr = samples + ch;
- for(i=0;i<nb_frames;i++) {
- ff_mpa_synth_filter(s->synth_buf[ch], &(s->synth_buf_offset[ch]),
- window, &s->dither_state,
- samples_ptr, s->nb_channels,
- s->sb_samples[ch][i]);
- samples_ptr += 32 * s->nb_channels;
- }
- }
-#ifdef DEBUG
- s->frame_count++;
-#endif
- return nb_frames * 32 * sizeof(OUT_INT) * s->nb_channels;
-}
-
-static int decode_frame(AVCodecContext * avctx,
- void *data, int *data_size,
- uint8_t * buf, int buf_size)
-{
- MPADecodeContext *s = avctx->priv_data;
- uint32_t header;
- int out_size;
- OUT_INT *out_samples = data;
-
-retry:
- if(buf_size < HEADER_SIZE)
- return -1;
-
- header = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
- if(ff_mpa_check_header(header) < 0){
- buf++;
-// buf_size--;
- av_log(avctx, AV_LOG_ERROR, "Header missing skipping one byte.\n");
- goto retry;
- }
-
- if (decode_header(s, header) == 1) {
- /* free format: prepare to compute frame size */
- s->frame_size = -1;
- return -1;
- }
- /* update codec info */
- avctx->channels = s->nb_channels;
- avctx->bit_rate = s->bit_rate;
- avctx->sub_id = s->layer;
- switch(s->layer) {
- case 1:
- avctx->frame_size = 384;
- break;
- case 2:
- avctx->frame_size = 1152;
- break;
- case 3:
- if (s->lsf)
- avctx->frame_size = 576;
- else
- avctx->frame_size = 1152;
- break;
- }
-
- if(s->frame_size<=0 || s->frame_size > buf_size){
- av_log(avctx, AV_LOG_ERROR, "incomplete frame\n");
- return -1;
- }else if(s->frame_size < buf_size){
- av_log(avctx, AV_LOG_ERROR, "incorrect frame size\n");
- }
-
- out_size = mp_decode_frame(s, out_samples, buf, buf_size);
- if(out_size>=0){
- *data_size = out_size;
- avctx->sample_rate = s->sample_rate;
- //FIXME maybe move the other codec info stuff from above here too
- }else
- av_log(avctx, AV_LOG_DEBUG, "Error while decoding MPEG audio frame.\n"); //FIXME return -1 / but also return the number of bytes consumed
- s->frame_size = 0;
- return buf_size;
-}
-
-static void flush(AVCodecContext *avctx){
- MPADecodeContext *s = avctx->priv_data;
- s->last_buf_size= 0;
-}
-
-#ifdef CONFIG_MP3ADU_DECODER
-static int decode_frame_adu(AVCodecContext * avctx,
- void *data, int *data_size,
- uint8_t * buf, int buf_size)
-{
- MPADecodeContext *s = avctx->priv_data;
- uint32_t header;
- int len, out_size;
- OUT_INT *out_samples = data;
-
- len = buf_size;
-
- // Discard too short frames
- if (buf_size < HEADER_SIZE) {
- *data_size = 0;
- return buf_size;
- }
-
-
- if (len > MPA_MAX_CODED_FRAME_SIZE)
- len = MPA_MAX_CODED_FRAME_SIZE;
-
- // Get header and restore sync word
- header = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3] | 0xffe00000;
-
- if (ff_mpa_check_header(header) < 0) { // Bad header, discard frame
- *data_size = 0;
- return buf_size;
- }
-
- decode_header(s, header);
- /* update codec info */
- avctx->sample_rate = s->sample_rate;
- avctx->channels = s->nb_channels;
- avctx->bit_rate = s->bit_rate;
- avctx->sub_id = s->layer;
-
- avctx->frame_size=s->frame_size = len;
-
- if (avctx->parse_only) {
- out_size = buf_size;
- } else {
- out_size = mp_decode_frame(s, out_samples, buf, buf_size);
- }
-
- *data_size = out_size;
- return buf_size;
-}
-#endif /* CONFIG_MP3ADU_DECODER */
-
-#ifdef CONFIG_MP3ON4_DECODER
-/* Next 3 arrays are indexed by channel config number (passed via codecdata) */
-static int mp3Frames[16] = {0,1,1,2,3,3,4,5,2}; /* number of mp3 decoder instances */
-static int mp3Channels[16] = {0,1,2,3,4,5,6,8,4}; /* total output channels */
-/* offsets into output buffer, assume output order is FL FR BL BR C LFE */
-static int chan_offset[9][5] = {
- {0},
- {0}, // C
- {0}, // FLR
- {2,0}, // C FLR
- {2,0,3}, // C FLR BS
- {4,0,2}, // C FLR BLRS
- {4,0,2,5}, // C FLR BLRS LFE
- {4,0,2,6,5}, // C FLR BLRS BLR LFE
- {0,2} // FLR BLRS
-};
-
-
-static int decode_init_mp3on4(AVCodecContext * avctx)
-{
- MP3On4DecodeContext *s = avctx->priv_data;
- int i;
-
- if ((avctx->extradata_size < 2) || (avctx->extradata == NULL)) {
- av_log(avctx, AV_LOG_ERROR, "Codec extradata missing or too short.\n");
- return -1;
- }
-
- s->chan_cfg = (((unsigned char *)avctx->extradata)[1] >> 3) & 0x0f;
- s->frames = mp3Frames[s->chan_cfg];
- if(!s->frames) {
- av_log(avctx, AV_LOG_ERROR, "Invalid channel config number.\n");
- return -1;
- }
- avctx->channels = mp3Channels[s->chan_cfg];
-
- /* Init the first mp3 decoder in standard way, so that all tables get builded
- * We replace avctx->priv_data with the context of the first decoder so that
- * decode_init() does not have to be changed.
- * Other decoders will be inited here copying data from the first context
- */
- // Allocate zeroed memory for the first decoder context
- s->mp3decctx[0] = av_mallocz(sizeof(MPADecodeContext));
- // Put decoder context in place to make init_decode() happy
- avctx->priv_data = s->mp3decctx[0];
- decode_init(avctx);
- // Restore mp3on4 context pointer
- avctx->priv_data = s;
- s->mp3decctx[0]->adu_mode = 1; // Set adu mode
-
- /* Create a separate codec/context for each frame (first is already ok).
- * Each frame is 1 or 2 channels - up to 5 frames allowed
- */
- for (i = 1; i < s->frames; i++) {
- s->mp3decctx[i] = av_mallocz(sizeof(MPADecodeContext));
- s->mp3decctx[i]->compute_antialias = s->mp3decctx[0]->compute_antialias;
- s->mp3decctx[i]->adu_mode = 1;
- }
-
- return 0;
-}
-
-
-static int decode_close_mp3on4(AVCodecContext * avctx)
-{
- MP3On4DecodeContext *s = avctx->priv_data;
- int i;
-
- for (i = 0; i < s->frames; i++)
- if (s->mp3decctx[i])
- av_free(s->mp3decctx[i]);
-
- return 0;
-}
-
-
-static int decode_frame_mp3on4(AVCodecContext * avctx,
- void *data, int *data_size,
- uint8_t * buf, int buf_size)
-{
- MP3On4DecodeContext *s = avctx->priv_data;
- MPADecodeContext *m;
- int len, out_size = 0;
- uint32_t header;
- OUT_INT *out_samples = data;
- OUT_INT decoded_buf[MPA_FRAME_SIZE * MPA_MAX_CHANNELS];
- OUT_INT *outptr, *bp;
- int fsize;
- unsigned char *start2 = buf, *start;
- int fr, i, j, n;
- int off = avctx->channels;
- int *coff = chan_offset[s->chan_cfg];
-
- len = buf_size;
-
- // Discard too short frames
- if (buf_size < HEADER_SIZE) {
- *data_size = 0;
- return buf_size;
- }
-
- // If only one decoder interleave is not needed
- outptr = s->frames == 1 ? out_samples : decoded_buf;
-
- for (fr = 0; fr < s->frames; fr++) {
- start = start2;
- fsize = (start[0] << 4) | (start[1] >> 4);
- start2 += fsize;
- if (fsize > len)
- fsize = len;
- len -= fsize;
- if (fsize > MPA_MAX_CODED_FRAME_SIZE)
- fsize = MPA_MAX_CODED_FRAME_SIZE;
- m = s->mp3decctx[fr];
- assert (m != NULL);
-
- // Get header
- header = (start[0] << 24) | (start[1] << 16) | (start[2] << 8) | start[3] | 0xfff00000;
-
- if (ff_mpa_check_header(header) < 0) { // Bad header, discard block
- *data_size = 0;
- return buf_size;
- }
-
- decode_header(m, header);
- mp_decode_frame(m, decoded_buf, start, fsize);
-
- n = MPA_FRAME_SIZE * m->nb_channels;
- out_size += n * sizeof(OUT_INT);
- if(s->frames > 1) {
- /* interleave output data */
- bp = out_samples + coff[fr];
- if(m->nb_channels == 1) {
- for(j = 0; j < n; j++) {
- *bp = decoded_buf[j];
- bp += off;
- }
- } else {
- for(j = 0; j < n; j++) {
- bp[0] = decoded_buf[j++];
- bp[1] = decoded_buf[j];
- bp += off;
- }
- }
- }
- }
-
- /* update codec info */
- avctx->sample_rate = s->mp3decctx[0]->sample_rate;
- avctx->frame_size= buf_size;
- avctx->bit_rate = 0;
- for (i = 0; i < s->frames; i++)
- avctx->bit_rate += s->mp3decctx[i]->bit_rate;
-
- *data_size = out_size;
- return buf_size;
-}
-#endif /* CONFIG_MP3ON4_DECODER */
-
-#ifdef CONFIG_MP2_DECODER
-AVCodec mp2_decoder =
-{
- "mp2",
- CODEC_TYPE_AUDIO,
- CODEC_ID_MP2,
- sizeof(MPADecodeContext),
- decode_init,
- NULL,
- NULL,
- decode_frame,
- CODEC_CAP_PARSE_ONLY,
-};
-#endif
-#ifdef CONFIG_MP3_DECODER
-AVCodec mp3_decoder =
-{
- "mp3",
- CODEC_TYPE_AUDIO,
- CODEC_ID_MP3,
- sizeof(MPADecodeContext),
- decode_init,
- NULL,
- NULL,
- decode_frame,
- CODEC_CAP_PARSE_ONLY,
- .flush= flush,
-};
-#endif
-#ifdef CONFIG_MP3ADU_DECODER
-AVCodec mp3adu_decoder =
-{
- "mp3adu",
- CODEC_TYPE_AUDIO,
- CODEC_ID_MP3ADU,
- sizeof(MPADecodeContext),
- decode_init,
- NULL,
- NULL,
- decode_frame_adu,
- CODEC_CAP_PARSE_ONLY,
- .flush= flush,
-};
-#endif
-#ifdef CONFIG_MP3ON4_DECODER
-AVCodec mp3on4_decoder =
-{
- "mp3on4",
- CODEC_TYPE_AUDIO,
- CODEC_ID_MP3ON4,
- sizeof(MP3On4DecodeContext),
- decode_init_mp3on4,
- NULL,
- decode_close_mp3on4,
- decode_frame_mp3on4,
- .flush= flush,
-};
-#endif
diff --git a/src/libffmpeg/libavcodec/mpegvideo.c b/src/libffmpeg/libavcodec/mpegvideo.c
deleted file mode 100644
index 87c913efa..000000000
--- a/src/libffmpeg/libavcodec/mpegvideo.c
+++ /dev/null
@@ -1,7013 +0,0 @@
-/*
- * The simplest mpeg encoder (well, it was the simplest!)
- * Copyright (c) 2000,2001 Fabrice Bellard.
- * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * 4MV & hq & b-frame encoding stuff by Michael Niedermayer <michaelni@gmx.at>
- */
-
-/**
- * @file mpegvideo.c
- * The simplest mpeg encoder (well, it was the simplest!).
- */
-
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-#include "faandct.h"
-#include <limits.h>
-
-#ifdef USE_FASTMEMCPY
-#include "libvo/fastmemcpy.h"
-#endif
-
-//#undef NDEBUG
-//#include <assert.h>
-
-
-/* if xine's MPEG encoder is enabled, enable the encoding features in
- * this particular module */
-#if defined(XINE_MPEG_ENCODER) && !defined(CONFIG_ENCODERS)
-#define CONFIG_ENCODERS
-#endif
-
-
-#ifdef CONFIG_ENCODERS
-static int encode_picture(MpegEncContext *s, int picture_number);
-#endif //CONFIG_ENCODERS
-static void dct_unquantize_mpeg1_intra_c(MpegEncContext *s,
- DCTELEM *block, int n, int qscale);
-static void dct_unquantize_mpeg1_inter_c(MpegEncContext *s,
- DCTELEM *block, int n, int qscale);
-static void dct_unquantize_mpeg2_intra_c(MpegEncContext *s,
- DCTELEM *block, int n, int qscale);
-static void dct_unquantize_mpeg2_intra_bitexact(MpegEncContext *s,
- DCTELEM *block, int n, int qscale);
-static void dct_unquantize_mpeg2_inter_c(MpegEncContext *s,
- DCTELEM *block, int n, int qscale);
-static void dct_unquantize_h263_intra_c(MpegEncContext *s,
- DCTELEM *block, int n, int qscale);
-static void dct_unquantize_h263_inter_c(MpegEncContext *s,
- DCTELEM *block, int n, int qscale);
-static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w);
-#ifdef CONFIG_ENCODERS
-static int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
-static int dct_quantize_trellis_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
-static int dct_quantize_refine(MpegEncContext *s, DCTELEM *block, int16_t *weight, DCTELEM *orig, int n, int qscale);
-static int sse_mb(MpegEncContext *s);
-static void denoise_dct_c(MpegEncContext *s, DCTELEM *block);
-#endif //CONFIG_ENCODERS
-
-#ifdef HAVE_XVMC
-extern int XVMC_field_start(MpegEncContext*s, AVCodecContext *avctx);
-extern void XVMC_field_end(MpegEncContext *s);
-extern void XVMC_decode_mb(MpegEncContext *s);
-#endif
-
-void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w)= draw_edges_c;
-
-
-/* enable all paranoid tests for rounding, overflows, etc... */
-//#define PARANOID
-
-//#define DEBUG
-
-
-/* for jpeg fast DCT */
-#define CONST_BITS 14
-
-static const uint16_t aanscales[64] = {
- /* precomputed values scaled up by 14 bits */
- 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
- 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
- 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
- 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
- 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
- 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
- 8867 , 12299, 11585, 10426, 8867, 6967, 4799, 2446,
- 4520 , 6270, 5906, 5315, 4520, 3552, 2446, 1247
-};
-
-static const uint8_t h263_chroma_roundtab[16] = {
-// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
- 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2,
-};
-
-static const uint8_t ff_default_chroma_qscale_table[32]={
-// 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
- 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
-};
-
-#ifdef CONFIG_ENCODERS
-static uint8_t (*default_mv_penalty)[MAX_MV*2+1]=NULL;
-static uint8_t default_fcode_tab[MAX_MV*2+1];
-
-enum PixelFormat ff_yuv420p_list[2]= {PIX_FMT_YUV420P, -1};
-
-static void convert_matrix(DSPContext *dsp, int (*qmat)[64], uint16_t (*qmat16)[2][64],
- const uint16_t *quant_matrix, int bias, int qmin, int qmax, int intra)
-{
- int qscale;
- int shift=0;
-
- for(qscale=qmin; qscale<=qmax; qscale++){
- int i;
- if (dsp->fdct == ff_jpeg_fdct_islow
-#ifdef FAAN_POSTSCALE
- || dsp->fdct == ff_faandct
-#endif
- ) {
- for(i=0;i<64;i++) {
- const int j= dsp->idct_permutation[i];
- /* 16 <= qscale * quant_matrix[i] <= 7905 */
- /* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */
- /* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */
- /* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */
-
- qmat[qscale][i] = (int)((UINT64_C(1) << QMAT_SHIFT) /
- (qscale * quant_matrix[j]));
- }
- } else if (dsp->fdct == fdct_ifast
-#ifndef FAAN_POSTSCALE
- || dsp->fdct == ff_faandct
-#endif
- ) {
- for(i=0;i<64;i++) {
- const int j= dsp->idct_permutation[i];
- /* 16 <= qscale * quant_matrix[i] <= 7905 */
- /* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */
- /* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */
- /* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */
-
- qmat[qscale][i] = (int)((UINT64_C(1) << (QMAT_SHIFT + 14)) /
- (aanscales[i] * qscale * quant_matrix[j]));
- }
- } else {
- for(i=0;i<64;i++) {
- const int j= dsp->idct_permutation[i];
- /* We can safely suppose that 16 <= quant_matrix[i] <= 255
- So 16 <= qscale * quant_matrix[i] <= 7905
- so (1<<19) / 16 >= (1<<19) / (qscale * quant_matrix[i]) >= (1<<19) / 7905
- so 32768 >= (1<<19) / (qscale * quant_matrix[i]) >= 67
- */
- qmat[qscale][i] = (int)((UINT64_C(1) << QMAT_SHIFT) / (qscale * quant_matrix[j]));
-// qmat [qscale][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[i]);
- qmat16[qscale][0][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[j]);
-
- if(qmat16[qscale][0][i]==0 || qmat16[qscale][0][i]==128*256) qmat16[qscale][0][i]=128*256-1;
- qmat16[qscale][1][i]= ROUNDED_DIV(bias<<(16-QUANT_BIAS_SHIFT), qmat16[qscale][0][i]);
- }
- }
-
- for(i=intra; i<64; i++){
- int64_t max= 8191;
- if (dsp->fdct == fdct_ifast
-#ifndef FAAN_POSTSCALE
- || dsp->fdct == ff_faandct
-#endif
- ) {
- max= (8191LL*aanscales[i]) >> 14;
- }
- while(((max * qmat[qscale][i]) >> shift) > INT_MAX){
- shift++;
- }
- }
- }
- if(shift){
- av_log(NULL, AV_LOG_INFO, "Warning, QMAT_SHIFT is larger then %d, overflows possible\n", QMAT_SHIFT - shift);
- }
-}
-
-static inline void update_qscale(MpegEncContext *s){
- s->qscale= (s->lambda*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7);
- s->qscale= clip(s->qscale, s->avctx->qmin, s->avctx->qmax);
-
- s->lambda2= (s->lambda*s->lambda + FF_LAMBDA_SCALE/2) >> FF_LAMBDA_SHIFT;
-}
-#endif //CONFIG_ENCODERS
-
-void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable){
- int i;
- int end;
-
- st->scantable= src_scantable;
-
- for(i=0; i<64; i++){
- int j;
- j = src_scantable[i];
- st->permutated[i] = permutation[j];
-#ifdef ARCH_POWERPC
- st->inverse[j] = i;
-#endif
- }
-
- end=-1;
- for(i=0; i<64; i++){
- int j;
- j = st->permutated[i];
- if(j>end) end=j;
- st->raster_end[i]= end;
- }
-}
-
-#ifdef CONFIG_ENCODERS
-void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix){
- int i;
-
- if(matrix){
- put_bits(pb, 1, 1);
- for(i=0;i<64;i++) {
- put_bits(pb, 8, matrix[ ff_zigzag_direct[i] ]);
- }
- }else
- put_bits(pb, 1, 0);
-}
-#endif //CONFIG_ENCODERS
-
-const uint8_t *ff_find_start_code(const uint8_t * restrict p, const uint8_t *end, uint32_t * restrict state){
- int i;
-
- assert(p<=end);
- if(p>=end)
- return end;
-
- for(i=0; i<3; i++){
- uint32_t tmp= *state << 8;
- *state= tmp + *(p++);
- if(tmp == 0x100 || p==end)
- return p;
- }
-
- while(p<end){
- if (p[-1] > 1 ) p+= 3;
- else if(p[-2] ) p+= 2;
- else if(p[-3]|(p[-1]-1)) p++;
- else{
- p++;
- break;
- }
- }
-
- p= FFMIN(p, end)-4;
- *state= be2me_32(unaligned32(p));
-
- return p+4;
-}
-
-/* init common dct for both encoder and decoder */
-int DCT_common_init(MpegEncContext *s)
-{
- s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_c;
- s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_c;
- s->dct_unquantize_mpeg1_intra = dct_unquantize_mpeg1_intra_c;
- s->dct_unquantize_mpeg1_inter = dct_unquantize_mpeg1_inter_c;
- s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_c;
- if(s->flags & CODEC_FLAG_BITEXACT)
- s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_bitexact;
- s->dct_unquantize_mpeg2_inter = dct_unquantize_mpeg2_inter_c;
-
-#ifdef CONFIG_ENCODERS
- s->dct_quantize= dct_quantize_c;
- s->denoise_dct= denoise_dct_c;
-#endif //CONFIG_ENCODERS
-
-#ifdef HAVE_MMX
- MPV_common_init_mmx(s);
-#endif
-#ifdef ARCH_ALPHA
- MPV_common_init_axp(s);
-#endif
-#ifdef HAVE_MLIB
- MPV_common_init_mlib(s);
-#endif
-#ifdef HAVE_MMI
- MPV_common_init_mmi(s);
-#endif
-#ifdef ARCH_ARMV4L
- MPV_common_init_armv4l(s);
-#endif
-#ifdef ARCH_POWERPC
- MPV_common_init_ppc(s);
-#endif
-
-#ifdef CONFIG_ENCODERS
- s->fast_dct_quantize= s->dct_quantize;
-
- if(s->flags&CODEC_FLAG_TRELLIS_QUANT){
- s->dct_quantize= dct_quantize_trellis_c; //move before MPV_common_init_*
- }
-
-#endif //CONFIG_ENCODERS
-
- /* load & permutate scantables
- note: only wmv uses different ones
- */
- if(s->alternate_scan){
- ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_alternate_vertical_scan);
- ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_alternate_vertical_scan);
- }else{
- ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_zigzag_direct);
- ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_zigzag_direct);
- }
- 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);
-
- return 0;
-}
-
-static void copy_picture(Picture *dst, Picture *src){
- *dst = *src;
- dst->type= FF_BUFFER_TYPE_COPY;
-}
-
-#ifdef CONFIG_ENCODERS
-static void copy_picture_attributes(MpegEncContext *s, AVFrame *dst, AVFrame *src){
- int i;
-
- dst->pict_type = src->pict_type;
- dst->quality = src->quality;
- dst->coded_picture_number = src->coded_picture_number;
- dst->display_picture_number = src->display_picture_number;
-// dst->reference = src->reference;
- dst->pts = src->pts;
- dst->interlaced_frame = src->interlaced_frame;
- dst->top_field_first = src->top_field_first;
-
- if(s->avctx->me_threshold){
- if(!src->motion_val[0])
- av_log(s->avctx, AV_LOG_ERROR, "AVFrame.motion_val not set!\n");
- if(!src->mb_type)
- av_log(s->avctx, AV_LOG_ERROR, "AVFrame.mb_type not set!\n");
- if(!src->ref_index[0])
- av_log(s->avctx, AV_LOG_ERROR, "AVFrame.ref_index not set!\n");
- if(src->motion_subsample_log2 != dst->motion_subsample_log2)
- av_log(s->avctx, AV_LOG_ERROR, "AVFrame.motion_subsample_log2 doesn't match! (%d!=%d)\n",
- src->motion_subsample_log2, dst->motion_subsample_log2);
-
- memcpy(dst->mb_type, src->mb_type, s->mb_stride * s->mb_height * sizeof(dst->mb_type[0]));
-
- for(i=0; i<2; i++){
- int stride= ((16*s->mb_width )>>src->motion_subsample_log2) + 1;
- int height= ((16*s->mb_height)>>src->motion_subsample_log2);
-
- if(src->motion_val[i] && src->motion_val[i] != dst->motion_val[i]){
- 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));
- }
- }
- }
-}
-#endif
-
-/**
- * allocates a Picture
- * The pixels are allocated/set by calling get_buffer() if shared=0
- */
-static int alloc_picture(MpegEncContext *s, Picture *pic, int shared){
- const int big_mb_num= s->mb_stride*(s->mb_height+1) + 1; //the +1 is needed so memset(,,stride*height) doesnt sig11
- const int mb_array_size= s->mb_stride*s->mb_height;
- const int b8_array_size= s->b8_stride*s->mb_height*2;
- const int b4_array_size= s->b4_stride*s->mb_height*4;
- int i;
-
- if(shared){
- assert(pic->data[0]);
- assert(pic->type == 0 || pic->type == FF_BUFFER_TYPE_SHARED);
- pic->type= FF_BUFFER_TYPE_SHARED;
- }else{
- int r;
-
- assert(!pic->data[0]);
-
- r= s->avctx->get_buffer(s->avctx, (AVFrame*)pic);
-
- if(r<0 || !pic->age || !pic->type || !pic->data[0]){
- av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (%d %d %d %p)\n", r, pic->age, pic->type, pic->data[0]);
- return -1;
- }
-
- if(s->linesize && (s->linesize != pic->linesize[0] || s->uvlinesize != pic->linesize[1])){
- av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (stride changed)\n");
- return -1;
- }
-
- if(pic->linesize[1] != pic->linesize[2]){
- av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (uv stride mismatch)\n");
- return -1;
- }
-
- s->linesize = pic->linesize[0];
- s->uvlinesize= pic->linesize[1];
- }
-
- 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))
- }
-
- 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 * sizeof(uint32_t))
- pic->mb_type= pic->mb_type_base + 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))
- pic->motion_val[i]= pic->motion_val_base[i]+4;
- CHECKED_ALLOCZ(pic->ref_index[i], b8_array_size * sizeof(uint8_t))
- }
- 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))
- pic->motion_val[i]= pic->motion_val_base[i]+4;
- CHECKED_ALLOCZ(pic->ref_index[i], b8_array_size * sizeof(uint8_t))
- }
- 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)
- }
- pic->qstride= s->mb_stride;
- CHECKED_ALLOCZ(pic->pan_scan , 1 * sizeof(AVPanScan))
- }
-
- //it might be nicer if the application would keep track of these but it would require a API change
- memmove(s->prev_pict_types+1, s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE-1);
- s->prev_pict_types[0]= s->pict_type;
- if(pic->age < PREV_PICT_TYPES_BUFFER_SIZE && s->prev_pict_types[pic->age] == B_TYPE)
- pic->age= INT_MAX; // skipped MBs in b frames are quite rare in mpeg1/2 and its a bit tricky to skip them anyway
-
- return 0;
-fail: //for the CHECKED_ALLOCZ macro
- return -1;
-}
-
-/**
- * deallocates a picture
- */
-static void free_picture(MpegEncContext *s, Picture *pic){
- int i;
-
- if(pic->data[0] && pic->type!=FF_BUFFER_TYPE_SHARED){
- s->avctx->release_buffer(s->avctx, (AVFrame*)pic);
- }
-
- av_freep(&pic->mb_var);
- av_freep(&pic->mc_mb_var);
- av_freep(&pic->mb_mean);
- av_freep(&pic->mbskip_table);
- av_freep(&pic->qscale_table);
- av_freep(&pic->mb_type_base);
- av_freep(&pic->dct_coeff);
- av_freep(&pic->pan_scan);
- pic->mb_type= NULL;
- for(i=0; i<2; i++){
- av_freep(&pic->motion_val_base[i]);
- av_freep(&pic->ref_index[i]);
- }
-
- if(pic->type == FF_BUFFER_TYPE_SHARED){
- for(i=0; i<4; i++){
- pic->base[i]=
- pic->data[i]= NULL;
- }
- pic->type= 0;
- }
-}
-
-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
- 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 isnt known before get_buffer()
- CHECKED_ALLOCZ(s->me.scratchpad, (s->width+64)*4*16*2*sizeof(uint8_t))
- 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))
- if(s->avctx->noise_reduction){
- CHECKED_ALLOCZ(s->dct_error_sum, 2 * 64 * sizeof(int))
- }
- }
- CHECKED_ALLOCZ(s->blocks, 64*12*2 * sizeof(DCTELEM))
- s->block= s->blocks[0];
-
- for(i=0;i<12;i++){
- s->pblocks[i] = (short *)(&s->block[i]);
- }
- return 0;
-fail:
- return -1; //free() through MPV_common_end()
-}
-
-static void free_duplicate_context(MpegEncContext *s){
- if(s==NULL) return;
-
- av_freep(&s->allocated_edge_emu_buffer); s->edge_emu_buffer= NULL;
- av_freep(&s->me.scratchpad);
- s->rd_scratchpad=
- s->b_scratchpad=
- s->obmc_scratchpad= NULL;
-
- av_freep(&s->dct_error_sum);
- av_freep(&s->me.map);
- av_freep(&s->me.score_map);
- av_freep(&s->blocks);
- s->block= NULL;
-}
-
-static void backup_duplicate_context(MpegEncContext *bak, MpegEncContext *src){
-#define COPY(a) bak->a= src->a
- COPY(allocated_edge_emu_buffer);
- COPY(edge_emu_buffer);
- COPY(me.scratchpad);
- COPY(rd_scratchpad);
- COPY(b_scratchpad);
- COPY(obmc_scratchpad);
- COPY(me.map);
- COPY(me.score_map);
- COPY(blocks);
- COPY(block);
- COPY(start_mb_y);
- COPY(end_mb_y);
- COPY(me.map_generation);
- COPY(pb);
- COPY(dct_error_sum);
- COPY(dct_count[0]);
- COPY(dct_count[1]);
-#undef COPY
-}
-
-void ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src){
- MpegEncContext bak;
- int i;
- //FIXME copy only needed parts
-//START_TIMER
- backup_duplicate_context(&bak, dst);
- memcpy(dst, src, sizeof(MpegEncContext));
- backup_duplicate_context(dst, &bak);
- for(i=0;i<12;i++){
- dst->pblocks[i] = (short *)(&dst->block[i]);
- }
-//STOP_TIMER("update_duplicate_context") //about 10k cycles / 0.01 sec for 1000frames on 1ghz with 2 threads
-}
-
-#ifdef CONFIG_ENCODERS
-static void update_duplicate_context_after_me(MpegEncContext *dst, MpegEncContext *src){
-#define COPY(a) dst->a= src->a
- COPY(pict_type);
- COPY(current_picture);
- COPY(f_code);
- COPY(b_code);
- COPY(qscale);
- COPY(lambda);
- COPY(lambda2);
- COPY(picture_in_gop_number);
- COPY(gop_picture_number);
- COPY(frame_pred_frame_dct); //FIXME don't set in encode_header
- COPY(progressive_frame); //FIXME don't set in encode_header
- COPY(partitioned_frame); //FIXME don't set in encode_header
-#undef COPY
-}
-#endif
-
-/**
- * sets the given MpegEncContext to common defaults (same for encoding and decoding).
- * the changed fields will not depend upon the prior state of the MpegEncContext.
- */
-static void MPV_common_defaults(MpegEncContext *s){
- s->y_dc_scale_table=
- s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
- s->chroma_qscale_table= ff_default_chroma_qscale_table;
- s->progressive_frame= 1;
- s->progressive_sequence= 1;
- s->picture_structure= PICT_FRAME;
-
- s->coded_picture_number = 0;
- s->picture_number = 0;
- s->input_picture_number = 0;
-
- s->picture_in_gop_number = 0;
-
- s->f_code = 1;
- s->b_code = 1;
-}
-
-/**
- * sets the given MpegEncContext to defaults for decoding.
- * the changed fields will not depend upon the prior state of the MpegEncContext.
- */
-void MPV_decode_defaults(MpegEncContext *s){
- MPV_common_defaults(s);
-}
-
-/**
- * sets the given MpegEncContext to defaults for encoding.
- * the changed fields will not depend upon the prior state of the MpegEncContext.
- */
-
-#ifdef CONFIG_ENCODERS
-static void MPV_encode_defaults(MpegEncContext *s){
- static int done=0;
-
- MPV_common_defaults(s);
-
- if(!done){
- int i;
- done=1;
-
- default_mv_penalty= av_mallocz( sizeof(uint8_t)*(MAX_FCODE+1)*(2*MAX_MV+1) );
- memset(default_fcode_tab , 0, sizeof(uint8_t)*(2*MAX_MV+1));
-
- for(i=-16; i<16; i++){
- default_fcode_tab[i + MAX_MV]= 1;
- }
- }
- s->me.mv_penalty= default_mv_penalty;
- s->fcode_tab= default_fcode_tab;
-}
-#endif //CONFIG_ENCODERS
-
-/**
- * init common structure for both encoder and decoder.
- * this assumes that some variables like width/height are already set
- */
-int MPV_common_init(MpegEncContext *s)
-{
- int y_size, c_size, yc_size, i, mb_array_size, mv_table_size, x, y;
-
- s->mb_height = (s->height + 15) / 16;
-
- if(s->avctx->thread_count > MAX_THREADS || (s->avctx->thread_count > s->mb_height && s->mb_height)){
- av_log(s->avctx, AV_LOG_ERROR, "too many threads\n");
- return -1;
- }
-
- if((s->width || s->height) && avcodec_check_dimensions(s->avctx, s->width, s->height))
- return -1;
-
- dsputil_init(&s->dsp, s->avctx);
- DCT_common_init(s);
-
- s->flags= s->avctx->flags;
- s->flags2= s->avctx->flags2;
-
- s->mb_width = (s->width + 15) / 16;
- s->mb_stride = s->mb_width + 1;
- s->b8_stride = s->mb_width*2 + 1;
- s->b4_stride = s->mb_width*4 + 1;
- mb_array_size= s->mb_height * s->mb_stride;
- mv_table_size= (s->mb_height+2) * s->mb_stride + 1;
-
- /* set chroma shifts */
- avcodec_get_chroma_sub_sample(s->avctx->pix_fmt,&(s->chroma_x_shift),
- &(s->chroma_y_shift) );
-
- /* set default edge pos, will be overriden in decode_header if needed */
- s->h_edge_pos= s->mb_width*16;
- s->v_edge_pos= s->mb_height*16;
-
- s->mb_num = s->mb_width * s->mb_height;
-
- s->block_wrap[0]=
- s->block_wrap[1]=
- s->block_wrap[2]=
- s->block_wrap[3]= s->b8_stride;
- s->block_wrap[4]=
- s->block_wrap[5]= s->mb_stride;
-
- y_size = s->b8_stride * (2 * s->mb_height + 1);
- c_size = s->mb_stride * (s->mb_height + 1);
- yc_size = y_size + 2 * c_size;
-
- /* convert fourcc to upper case */
- s->codec_tag= toupper( s->avctx->codec_tag &0xFF)
- + (toupper((s->avctx->codec_tag>>8 )&0xFF)<<8 )
- + (toupper((s->avctx->codec_tag>>16)&0xFF)<<16)
- + (toupper((s->avctx->codec_tag>>24)&0xFF)<<24);
-
- s->stream_codec_tag= toupper( s->avctx->stream_codec_tag &0xFF)
- + (toupper((s->avctx->stream_codec_tag>>8 )&0xFF)<<8 )
- + (toupper((s->avctx->stream_codec_tag>>16)&0xFF)<<16)
- + (toupper((s->avctx->stream_codec_tag>>24)&0xFF)<<24);
-
- 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
- for(y=0; y<s->mb_height; y++){
- for(x=0; x<s->mb_width; x++){
- s->mb_index2xy[ x + y*s->mb_width ] = x + y*s->mb_stride;
- }
- }
- s->mb_index2xy[ s->mb_height*s->mb_width ] = (s->mb_height-1)*s->mb_stride + s->mb_width; //FIXME really needed?
-
- if (s->encoding) {
- /* Allocate MV tables */
- 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))
- s->p_mv_table = s->p_mv_table_base + s->mb_stride + 1;
- s->b_forw_mv_table = s->b_forw_mv_table_base + s->mb_stride + 1;
- s->b_back_mv_table = s->b_back_mv_table_base + s->mb_stride + 1;
- s->b_bidir_forw_mv_table= s->b_bidir_forw_mv_table_base + s->mb_stride + 1;
- s->b_bidir_back_mv_table= s->b_bidir_back_mv_table_base + s->mb_stride + 1;
- s->b_direct_mv_table = s->b_direct_mv_table_base + s->mb_stride + 1;
-
- if(s->msmpeg4_version){
- CHECKED_ALLOCZ(s->ac_stats, 2*2*(MAX_LEVEL+1)*(MAX_RUN+1)*2*sizeof(int));
- }
- CHECKED_ALLOCZ(s->avctx->stats_out, 256);
-
- /* Allocate MB type table */
- CHECKED_ALLOCZ(s->mb_type , mb_array_size * sizeof(uint16_t)) //needed for encoding
-
- CHECKED_ALLOCZ(s->lambda_table, mb_array_size * sizeof(int))
-
- 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*))
-
- if(s->avctx->noise_reduction){
- CHECKED_ALLOCZ(s->dct_offset, 2 * 64 * sizeof(uint16_t))
- }
- }
- CHECKED_ALLOCZ(s->picture, MAX_PICTURE_COUNT * sizeof(Picture))
-
- CHECKED_ALLOCZ(s->error_status_table, mb_array_size*sizeof(uint8_t))
-
- if(s->codec_id==CODEC_ID_MPEG4 || (s->flags & CODEC_FLAG_INTERLACED_ME)){
- /* interlaced direct mode decoding tables */
- for(i=0; i<2; i++){
- int j, k;
- for(j=0; j<2; j++){
- 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;
- }
- 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;
- }
- CHECKED_ALLOCZ(s->p_field_select_table[i] , mb_array_size * 2 * sizeof(uint8_t))
- }
- }
- if (s->out_format == FMT_H263) {
- /* ac values */
- CHECKED_ALLOCZ(s->ac_val_base, yc_size * sizeof(int16_t) * 16);
- 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);
- 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))
- }
-
- 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));
- s->dc_val[0] = s->dc_val_base + s->b8_stride + 1;
- s->dc_val[1] = s->dc_val_base + y_size + s->mb_stride + 1;
- s->dc_val[2] = s->dc_val[1] + c_size;
- for(i=0;i<yc_size;i++)
- s->dc_val_base[i] = 1024;
- }
-
- /* which mb is a intra block */
- CHECKED_ALLOCZ(s->mbintra_table, mb_array_size);
- memset(s->mbintra_table, 1, mb_array_size);
-
- /* init macroblock skip table */
- CHECKED_ALLOCZ(s->mbskip_table, mb_array_size+2);
- //Note the +1 is for a quicker mpeg4 slice_end detection
- CHECKED_ALLOCZ(s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE);
-
- s->parse_context.state= -1;
- if((s->avctx->debug&(FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)) || (s->avctx->debug_mv)){
- s->visualization_buffer[0] = av_malloc((s->mb_width*16 + 2*EDGE_WIDTH) * s->mb_height*16 + 2*EDGE_WIDTH);
- s->visualization_buffer[1] = av_malloc((s->mb_width*8 + EDGE_WIDTH) * s->mb_height*8 + EDGE_WIDTH);
- s->visualization_buffer[2] = av_malloc((s->mb_width*8 + EDGE_WIDTH) * s->mb_height*8 + EDGE_WIDTH);
- }
-
- s->context_initialized = 1;
-
- s->thread_context[0]= s;
- for(i=1; i<s->avctx->thread_count; i++){
- s->thread_context[i]= av_malloc(sizeof(MpegEncContext));
- memcpy(s->thread_context[i], s, sizeof(MpegEncContext));
- }
-
- for(i=0; i<s->avctx->thread_count; i++){
- if(init_duplicate_context(s->thread_context[i], s) < 0)
- goto fail;
- s->thread_context[i]->start_mb_y= (s->mb_height*(i ) + s->avctx->thread_count/2) / s->avctx->thread_count;
- s->thread_context[i]->end_mb_y = (s->mb_height*(i+1) + s->avctx->thread_count/2) / s->avctx->thread_count;
- }
-
- return 0;
- fail:
- MPV_common_end(s);
- return -1;
-}
-
-/* init common structure for both encoder and decoder */
-void MPV_common_end(MpegEncContext *s)
-{
- int i, j, k;
-
- for(i=0; i<s->avctx->thread_count; i++){
- free_duplicate_context(s->thread_context[i]);
- }
- for(i=1; i<s->avctx->thread_count; i++){
- av_freep(&s->thread_context[i]);
- }
-
- av_freep(&s->parse_context.buffer);
- s->parse_context.buffer_size=0;
-
- av_freep(&s->mb_type);
- av_freep(&s->p_mv_table_base);
- av_freep(&s->b_forw_mv_table_base);
- av_freep(&s->b_back_mv_table_base);
- av_freep(&s->b_bidir_forw_mv_table_base);
- av_freep(&s->b_bidir_back_mv_table_base);
- av_freep(&s->b_direct_mv_table_base);
- s->p_mv_table= NULL;
- s->b_forw_mv_table= NULL;
- s->b_back_mv_table= NULL;
- s->b_bidir_forw_mv_table= NULL;
- s->b_bidir_back_mv_table= NULL;
- s->b_direct_mv_table= NULL;
- for(i=0; i<2; i++){
- for(j=0; j<2; j++){
- for(k=0; k<2; k++){
- av_freep(&s->b_field_mv_table_base[i][j][k]);
- s->b_field_mv_table[i][j][k]=NULL;
- }
- av_freep(&s->b_field_select_table[i][j]);
- av_freep(&s->p_field_mv_table_base[i][j]);
- s->p_field_mv_table[i][j]=NULL;
- }
- av_freep(&s->p_field_select_table[i]);
- }
-
- av_freep(&s->dc_val_base);
- av_freep(&s->ac_val_base);
- av_freep(&s->coded_block_base);
- av_freep(&s->mbintra_table);
- av_freep(&s->cbp_table);
- av_freep(&s->pred_dir_table);
-
- av_freep(&s->mbskip_table);
- av_freep(&s->prev_pict_types);
- av_freep(&s->bitstream_buffer);
- s->allocated_bitstream_buffer_size=0;
-
- av_freep(&s->avctx->stats_out);
- av_freep(&s->ac_stats);
- av_freep(&s->error_status_table);
- av_freep(&s->mb_index2xy);
- av_freep(&s->lambda_table);
- av_freep(&s->q_intra_matrix);
- av_freep(&s->q_inter_matrix);
- av_freep(&s->q_intra_matrix16);
- av_freep(&s->q_inter_matrix16);
- av_freep(&s->input_picture);
- av_freep(&s->reordered_input_picture);
- av_freep(&s->dct_offset);
-
- if(s->picture){
- for(i=0; i<MAX_PICTURE_COUNT; i++){
- free_picture(s, &s->picture[i]);
- }
- }
- av_freep(&s->picture);
- s->context_initialized = 0;
- s->last_picture_ptr=
- s->next_picture_ptr=
- s->current_picture_ptr= NULL;
- s->linesize= s->uvlinesize= 0;
-
- for(i=0; i<3; i++)
- av_freep(&s->visualization_buffer[i]);
-
- avcodec_default_free_buffers(s->avctx);
-}
-
-#ifdef CONFIG_ENCODERS
-
-/* init video encoder */
-int MPV_encode_init(AVCodecContext *avctx)
-{
- MpegEncContext *s = avctx->priv_data;
- int i;
- int chroma_h_shift, chroma_v_shift;
-
- MPV_encode_defaults(s);
-
- switch (avctx->codec_id) {
- case CODEC_ID_MPEG2VIDEO:
- if(avctx->pix_fmt != PIX_FMT_YUV420P && avctx->pix_fmt != PIX_FMT_YUV422P){
- av_log(avctx, AV_LOG_ERROR, "only YUV420 and YUV422 are supported\n");
- return -1;
- }
- break;
- case CODEC_ID_LJPEG:
- case CODEC_ID_MJPEG:
- if(avctx->pix_fmt != PIX_FMT_YUVJ420P && avctx->pix_fmt != PIX_FMT_YUVJ422P &&
- ((avctx->pix_fmt != PIX_FMT_YUV420P && avctx->pix_fmt != PIX_FMT_YUV422P) || avctx->strict_std_compliance>FF_COMPLIANCE_INOFFICIAL)){
- av_log(avctx, AV_LOG_ERROR, "colorspace not supported in jpeg\n");
- return -1;
- }
- break;
- default:
- if(avctx->pix_fmt != PIX_FMT_YUV420P){
- av_log(avctx, AV_LOG_ERROR, "only YUV420 is supported\n");
- return -1;
- }
- }
-
- switch (avctx->pix_fmt) {
- case PIX_FMT_YUVJ422P:
- case PIX_FMT_YUV422P:
- s->chroma_format = CHROMA_422;
- break;
- case PIX_FMT_YUVJ420P:
- case PIX_FMT_YUV420P:
- default:
- s->chroma_format = CHROMA_420;
- break;
- }
-
- s->bit_rate = avctx->bit_rate;
- s->width = avctx->width;
- s->height = avctx->height;
- if(avctx->gop_size > 600 && avctx->strict_std_compliance>FF_COMPLIANCE_EXPERIMENTAL){
- av_log(avctx, AV_LOG_ERROR, "Warning keyframe interval too large! reducing it ...\n");
- avctx->gop_size=600;
- }
- s->gop_size = avctx->gop_size;
- s->avctx = avctx;
- s->flags= avctx->flags;
- s->flags2= avctx->flags2;
- s->max_b_frames= avctx->max_b_frames;
- s->codec_id= avctx->codec->id;
- s->luma_elim_threshold = avctx->luma_elim_threshold;
- s->chroma_elim_threshold= avctx->chroma_elim_threshold;
- s->strict_std_compliance= avctx->strict_std_compliance;
- s->data_partitioning= avctx->flags & CODEC_FLAG_PART;
- s->quarter_sample= (avctx->flags & CODEC_FLAG_QPEL)!=0;
- s->mpeg_quant= avctx->mpeg_quant;
- s->rtp_mode= !!avctx->rtp_payload_size;
- s->intra_dc_precision= avctx->intra_dc_precision;
- s->user_specified_pts = AV_NOPTS_VALUE;
-
- if (s->gop_size <= 1) {
- s->intra_only = 1;
- s->gop_size = 12;
- } else {
- s->intra_only = 0;
- }
-
- s->me_method = avctx->me_method;
-
- /* Fixed QSCALE */
- s->fixed_qscale = !!(avctx->flags & CODEC_FLAG_QSCALE);
-
- s->adaptive_quant= ( s->avctx->lumi_masking
- || s->avctx->dark_masking
- || s->avctx->temporal_cplx_masking
- || s->avctx->spatial_cplx_masking
- || s->avctx->p_masking
- || s->avctx->border_masking
- || (s->flags&CODEC_FLAG_QP_RD))
- && !s->fixed_qscale;
-
- s->obmc= !!(s->flags & CODEC_FLAG_OBMC);
- s->loop_filter= !!(s->flags & CODEC_FLAG_LOOP_FILTER);
- s->alternate_scan= !!(s->flags & CODEC_FLAG_ALT_SCAN);
- s->intra_vlc_format= !!(s->flags2 & CODEC_FLAG2_INTRA_VLC);
-
- if(avctx->rc_max_rate && !avctx->rc_buffer_size){
- av_log(avctx, AV_LOG_ERROR, "a vbv buffer size is needed, for encoding with a maximum bitrate\n");
- return -1;
- }
-
- if(avctx->rc_min_rate && avctx->rc_max_rate != avctx->rc_min_rate){
- av_log(avctx, AV_LOG_INFO, "Warning min_rate > 0 but min_rate != max_rate isn't recommended!\n");
- }
-
- if(avctx->rc_min_rate && avctx->rc_min_rate > avctx->bit_rate){
- av_log(avctx, AV_LOG_INFO, "bitrate below min bitrate\n");
- return -1;
- }
-
- if(avctx->rc_max_rate && avctx->rc_max_rate < avctx->bit_rate){
- av_log(avctx, AV_LOG_INFO, "bitrate above max bitrate\n");
- return -1;
- }
-
- if( s->avctx->rc_max_rate && s->avctx->rc_min_rate == s->avctx->rc_max_rate
- && (s->codec_id == CODEC_ID_MPEG1VIDEO || s->codec_id == CODEC_ID_MPEG2VIDEO)
- && 90000LL * (avctx->rc_buffer_size-1) > s->avctx->rc_max_rate*0xFFFFLL){
-
- av_log(avctx, AV_LOG_INFO, "Warning vbv_delay will be set to 0xFFFF (=VBR) as the specified vbv buffer is too large for the given bitrate!\n");
- }
-
- if((s->flags & CODEC_FLAG_4MV) && s->codec_id != CODEC_ID_MPEG4
- && s->codec_id != CODEC_ID_H263 && s->codec_id != CODEC_ID_H263P && s->codec_id != CODEC_ID_FLV1){
- av_log(avctx, AV_LOG_ERROR, "4MV not supported by codec\n");
- return -1;
- }
-
- if(s->obmc && s->avctx->mb_decision != FF_MB_DECISION_SIMPLE){
- av_log(avctx, AV_LOG_ERROR, "OBMC is only supported with simple mb decision\n");
- return -1;
- }
-
- if(s->obmc && s->codec_id != CODEC_ID_H263 && s->codec_id != CODEC_ID_H263P){
- av_log(avctx, AV_LOG_ERROR, "OBMC is only supported with H263(+)\n");
- return -1;
- }
-
- if(s->quarter_sample && s->codec_id != CODEC_ID_MPEG4){
- av_log(avctx, AV_LOG_ERROR, "qpel not supported by codec\n");
- return -1;
- }
-
- if(s->data_partitioning && s->codec_id != CODEC_ID_MPEG4){
- av_log(avctx, AV_LOG_ERROR, "data partitioning not supported by codec\n");
- return -1;
- }
-
- if(s->max_b_frames && s->codec_id != CODEC_ID_MPEG4 && s->codec_id != CODEC_ID_MPEG1VIDEO && s->codec_id != CODEC_ID_MPEG2VIDEO){
- av_log(avctx, AV_LOG_ERROR, "b frames not supported by codec\n");
- 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");
- return -1;
- }
-
- if(s->mpeg_quant && s->codec_id != CODEC_ID_MPEG4){ //FIXME mpeg2 uses that too
- av_log(avctx, AV_LOG_ERROR, "mpeg2 style quantization not supported by codec\n");
- return -1;
- }
-
- if((s->flags & CODEC_FLAG_CBP_RD) && !(s->flags & CODEC_FLAG_TRELLIS_QUANT)){
- av_log(avctx, AV_LOG_ERROR, "CBP RD needs trellis quant\n");
- return -1;
- }
-
- if((s->flags & CODEC_FLAG_QP_RD) && s->avctx->mb_decision != FF_MB_DECISION_RD){
- av_log(avctx, AV_LOG_ERROR, "QP RD needs mbd=2\n");
- return -1;
- }
-
- if(s->avctx->scenechange_threshold < 1000000000 && (s->flags & CODEC_FLAG_CLOSED_GOP)){
- av_log(avctx, AV_LOG_ERROR, "closed gop with scene change detection arent supported yet, set threshold to 1000000000\n");
- return -1;
- }
-
- if((s->flags2 & CODEC_FLAG2_INTRA_VLC) && s->codec_id != CODEC_ID_MPEG2VIDEO){
- av_log(avctx, AV_LOG_ERROR, "intra vlc table not supported by codec\n");
- return -1;
- }
-
- if(s->flags & CODEC_FLAG_LOW_DELAY){
- if (s->codec_id != CODEC_ID_MPEG2VIDEO && s->codec_id != CODEC_ID_MPEG1VIDEO){
- av_log(avctx, AV_LOG_ERROR, "low delay forcing is only available for mpeg1/2\n");
- return -1;
- }
- if (s->max_b_frames != 0){
- av_log(avctx, AV_LOG_ERROR, "b frames cannot be used with low delay\n");
- return -1;
- }
- }
-
- if(s->avctx->thread_count > 1 && s->codec_id != CODEC_ID_MPEG4
- && s->codec_id != CODEC_ID_MPEG1VIDEO && s->codec_id != CODEC_ID_MPEG2VIDEO
- && (s->codec_id != CODEC_ID_H263P || !(s->flags & CODEC_FLAG_H263P_SLICE_STRUCT))){
- av_log(avctx, AV_LOG_ERROR, "multi threaded encoding not supported by codec\n");
- return -1;
- }
-
- if(s->avctx->thread_count > 1)
- s->rtp_mode= 1;
-
- if(!avctx->time_base.den || !avctx->time_base.num){
- av_log(avctx, AV_LOG_ERROR, "framerate not set\n");
- return -1;
- }
-
- i= (INT_MAX/2+128)>>8;
- if(avctx->me_threshold >= i){
- av_log(avctx, AV_LOG_ERROR, "me_threshold too large, max is %d\n", i - 1);
- return -1;
- }
- if(avctx->mb_threshold >= i){
- av_log(avctx, AV_LOG_ERROR, "mb_threshold too large, max is %d\n", i - 1);
- return -1;
- }
-
- if(avctx->b_frame_strategy && (avctx->flags&CODEC_FLAG_PASS2)){
- av_log(avctx, AV_LOG_INFO, "notice: b_frame_strategy only affects the first pass\n");
- avctx->b_frame_strategy = 0;
- }
-
- i= ff_gcd(avctx->time_base.den, avctx->time_base.num);
- if(i > 1){
- av_log(avctx, AV_LOG_INFO, "removing common factors from framerate\n");
- avctx->time_base.den /= i;
- avctx->time_base.num /= i;
-// 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){
- s->intra_quant_bias= 3<<(QUANT_BIAS_SHIFT-3); //(a + x*3/8)/x
- s->inter_quant_bias= 0;
- }else{
- s->intra_quant_bias=0;
- s->inter_quant_bias=-(1<<(QUANT_BIAS_SHIFT-2)); //(a - x/4)/x
- }
-
- if(avctx->intra_quant_bias != FF_DEFAULT_QUANT_BIAS)
- s->intra_quant_bias= avctx->intra_quant_bias;
- if(avctx->inter_quant_bias != FF_DEFAULT_QUANT_BIAS)
- s->inter_quant_bias= avctx->inter_quant_bias;
-
- avcodec_get_chroma_sub_sample(avctx->pix_fmt, &chroma_h_shift, &chroma_v_shift);
-
- if(avctx->codec_id == CODEC_ID_MPEG4 && s->avctx->time_base.den > (1<<16)-1){
- av_log(avctx, AV_LOG_ERROR, "timebase not supported by mpeg 4 standard\n");
- return -1;
- }
- s->time_increment_bits = av_log2(s->avctx->time_base.den - 1) + 1;
-
- switch(avctx->codec->id) {
- case CODEC_ID_MPEG1VIDEO:
- s->out_format = FMT_MPEG1;
- s->low_delay= !!(s->flags & CODEC_FLAG_LOW_DELAY);
- avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1);
- break;
- case CODEC_ID_MPEG2VIDEO:
- s->out_format = FMT_MPEG1;
- s->low_delay= !!(s->flags & CODEC_FLAG_LOW_DELAY);
- avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1);
- s->rtp_mode= 1;
- break;
- case CODEC_ID_LJPEG:
- case CODEC_ID_JPEGLS:
- case CODEC_ID_MJPEG:
- s->out_format = FMT_MJPEG;
- s->intra_only = 1; /* force intra only for jpeg */
- s->mjpeg_write_tables = avctx->codec->id != CODEC_ID_JPEGLS;
- s->mjpeg_data_only_frames = 0; /* write all the needed headers */
- 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 (mjpeg_init(s) < 0)
- return -1;
- avctx->delay=0;
- s->low_delay=1;
- break;
-#ifdef CONFIG_H261_ENCODER
- case CODEC_ID_H261:
- if (ff_h261_get_picture_format(s->width, s->height) < 0) {
- av_log(avctx, AV_LOG_ERROR, "The specified picture size of %dx%d is not valid for the H.261 codec.\nValid sizes are 176x144, 352x288\n", s->width, s->height);
- return -1;
- }
- s->out_format = FMT_H261;
- avctx->delay=0;
- s->low_delay=1;
- break;
-#endif
- case CODEC_ID_H263:
- if (h263_get_picture_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;
- }
- s->out_format = FMT_H263;
- s->obmc= (avctx->flags & CODEC_FLAG_OBMC) ? 1:0;
- avctx->delay=0;
- s->low_delay=1;
- break;
- case CODEC_ID_H263P:
- s->out_format = FMT_H263;
- s->h263_plus = 1;
- /* Fx */
- s->umvplus = (avctx->flags & CODEC_FLAG_H263P_UMV) ? 1:0;
- s->h263_aic= (avctx->flags & CODEC_FLAG_H263P_AIC) ? 1:0;
- s->modified_quant= s->h263_aic;
- s->alt_inter_vlc= (avctx->flags & CODEC_FLAG_H263P_AIV) ? 1:0;
- s->obmc= (avctx->flags & CODEC_FLAG_OBMC) ? 1:0;
- s->loop_filter= (avctx->flags & CODEC_FLAG_LOOP_FILTER) ? 1:0;
- s->unrestricted_mv= s->obmc || s->loop_filter || s->umvplus;
- s->h263_slice_structured= (s->flags & CODEC_FLAG_H263P_SLICE_STRUCT) ? 1:0;
-
- /* /Fx */
- /* These are just to be sure */
- avctx->delay=0;
- s->low_delay=1;
- break;
- case CODEC_ID_FLV1:
- s->out_format = FMT_H263;
- s->h263_flv = 2; /* format = 1; 11-bit codes */
- s->unrestricted_mv = 1;
- s->rtp_mode=0; /* don't allow GOB */
- avctx->delay=0;
- s->low_delay=1;
- break;
- case CODEC_ID_RV10:
- s->out_format = FMT_H263;
- avctx->delay=0;
- s->low_delay=1;
- break;
- case CODEC_ID_RV20:
- s->out_format = FMT_H263;
- avctx->delay=0;
- s->low_delay=1;
- s->modified_quant=1;
- s->h263_aic=1;
- s->h263_plus=1;
- s->loop_filter=1;
- s->unrestricted_mv= s->obmc || s->loop_filter || s->umvplus;
- break;
- case CODEC_ID_MPEG4:
- s->out_format = FMT_H263;
- s->h263_pred = 1;
- s->unrestricted_mv = 1;
- s->low_delay= s->max_b_frames ? 0 : 1;
- avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1);
- break;
- case CODEC_ID_MSMPEG4V1:
- s->out_format = FMT_H263;
- s->h263_msmpeg4 = 1;
- s->h263_pred = 1;
- s->unrestricted_mv = 1;
- s->msmpeg4_version= 1;
- avctx->delay=0;
- s->low_delay=1;
- break;
- case CODEC_ID_MSMPEG4V2:
- s->out_format = FMT_H263;
- s->h263_msmpeg4 = 1;
- s->h263_pred = 1;
- s->unrestricted_mv = 1;
- s->msmpeg4_version= 2;
- avctx->delay=0;
- s->low_delay=1;
- break;
- case CODEC_ID_MSMPEG4V3:
- s->out_format = FMT_H263;
- s->h263_msmpeg4 = 1;
- s->h263_pred = 1;
- s->unrestricted_mv = 1;
- s->msmpeg4_version= 3;
- s->flipflop_rounding=1;
- avctx->delay=0;
- s->low_delay=1;
- break;
- case CODEC_ID_WMV1:
- s->out_format = FMT_H263;
- s->h263_msmpeg4 = 1;
- s->h263_pred = 1;
- s->unrestricted_mv = 1;
- s->msmpeg4_version= 4;
- s->flipflop_rounding=1;
- avctx->delay=0;
- s->low_delay=1;
- break;
- case CODEC_ID_WMV2:
- s->out_format = FMT_H263;
- s->h263_msmpeg4 = 1;
- s->h263_pred = 1;
- s->unrestricted_mv = 1;
- s->msmpeg4_version= 5;
- s->flipflop_rounding=1;
- avctx->delay=0;
- s->low_delay=1;
- break;
- default:
- return -1;
- }
-
- avctx->has_b_frames= !s->low_delay;
-
- s->encoding = 1;
-
- /* init */
- if (MPV_common_init(s) < 0)
- return -1;
-
- if(s->modified_quant)
- s->chroma_qscale_table= ff_h263_chroma_qscale_table;
- s->progressive_frame=
- s->progressive_sequence= !(avctx->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME|CODEC_FLAG_ALT_SCAN));
- s->quant_precision=5;
-
- ff_set_cmp(&s->dsp, s->dsp.ildct_cmp, s->avctx->ildct_cmp);
- ff_set_cmp(&s->dsp, s->dsp.frame_skip_cmp, s->avctx->frame_skip_cmp);
-
-/* xine: do not need this for decode or MPEG-1 encoding modes */
-#if 0
-#ifdef CONFIG_H261_ENCODER
- if (s->out_format == FMT_H261)
- ff_h261_encode_init(s);
-#endif
- if (s->out_format == FMT_H263)
- h263_encode_init(s);
- if(s->msmpeg4_version)
- ff_msmpeg4_encode_init(s);
-#endif /* #if 0 */
-/* xine: we DO want this for MPEG-1 encoding */
- if (s->out_format == FMT_MPEG1)
- ff_mpeg1_encode_init(s);
-
- /* init q matrix */
- for(i=0;i<64;i++) {
- int j= s->dsp.idct_permutation[i];
- if(s->codec_id==CODEC_ID_MPEG4 && s->mpeg_quant){
- s->intra_matrix[j] = ff_mpeg4_default_intra_matrix[i];
- s->inter_matrix[j] = ff_mpeg4_default_non_intra_matrix[i];
- }else if(s->out_format == FMT_H263 || s->out_format == FMT_H261){
- s->intra_matrix[j] =
- s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i];
- }else
- { /* mpeg1/2 */
- s->intra_matrix[j] = ff_mpeg1_default_intra_matrix[i];
- s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i];
- }
- if(s->avctx->intra_matrix)
- s->intra_matrix[j] = s->avctx->intra_matrix[i];
- if(s->avctx->inter_matrix)
- s->inter_matrix[j] = s->avctx->inter_matrix[i];
- }
-
- /* precompute matrix */
- /* for mjpeg, we do include qscale in the matrix */
- if (s->out_format != FMT_MJPEG) {
- convert_matrix(&s->dsp, s->q_intra_matrix, s->q_intra_matrix16,
- s->intra_matrix, s->intra_quant_bias, avctx->qmin, 31, 1);
- convert_matrix(&s->dsp, s->q_inter_matrix, s->q_inter_matrix16,
- s->inter_matrix, s->inter_quant_bias, avctx->qmin, 31, 0);
- }
-
- if(ff_rate_control_init(s) < 0)
- return -1;
-
- return 0;
-}
-
-int MPV_encode_end(AVCodecContext *avctx)
-{
- MpegEncContext *s = avctx->priv_data;
-
- ff_rate_control_uninit(s);
-
-/* xine: do not need this for decode or MPEG-1 encoding modes */
-#if 0
- MPV_common_end(s);
- if (s->out_format == FMT_MJPEG)
- mjpeg_close(s);
-#endif /* #if 0 */
-
- av_freep(&avctx->extradata);
-
- return 0;
-}
-
-#endif //CONFIG_ENCODERS
-
-void init_rl(RLTable *rl, int use_static)
-{
- int8_t max_level[MAX_RUN+1], max_run[MAX_LEVEL+1];
- uint8_t index_run[MAX_RUN+1];
- int last, run, level, start, end, i;
-
- /* If table is static, we can quit if rl->max_level[0] is not NULL */
- if(use_static && rl->max_level[0])
- return;
-
- /* compute max_level[], max_run[] and index_run[] */
- for(last=0;last<2;last++) {
- if (last == 0) {
- start = 0;
- end = rl->last;
- } else {
- start = rl->last;
- end = rl->n;
- }
-
- memset(max_level, 0, MAX_RUN + 1);
- memset(max_run, 0, MAX_LEVEL + 1);
- memset(index_run, rl->n, MAX_RUN + 1);
- for(i=start;i<end;i++) {
- run = rl->table_run[i];
- level = rl->table_level[i];
- if (index_run[run] == rl->n)
- index_run[run] = i;
- if (level > max_level[run])
- max_level[run] = level;
- if (run > max_run[level])
- max_run[level] = run;
- }
- if(use_static)
- rl->max_level[last] = av_mallocz_static(MAX_RUN + 1);
- else
- rl->max_level[last] = av_malloc(MAX_RUN + 1);
- memcpy(rl->max_level[last], max_level, MAX_RUN + 1);
- if(use_static)
- rl->max_run[last] = av_mallocz_static(MAX_LEVEL + 1);
- else
- rl->max_run[last] = av_malloc(MAX_LEVEL + 1);
- memcpy(rl->max_run[last], max_run, MAX_LEVEL + 1);
- if(use_static)
- rl->index_run[last] = av_mallocz_static(MAX_RUN + 1);
- else
- rl->index_run[last] = av_malloc(MAX_RUN + 1);
- memcpy(rl->index_run[last], index_run, MAX_RUN + 1);
- }
-}
-
-/* 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)
-{
- uint8_t *ptr, *last_line;
- int i;
-
- last_line = buf + (height - 1) * wrap;
- for(i=0;i<w;i++) {
- /* top and bottom */
- memcpy(buf - (i + 1) * wrap, buf, width);
- memcpy(last_line + (i + 1) * wrap, last_line, width);
- }
- /* left and right */
- ptr = buf;
- for(i=0;i<height;i++) {
- memset(ptr - w, ptr[0], w);
- memset(ptr + width, ptr[width-1], w);
- ptr += wrap;
- }
- /* corners */
- for(i=0;i<w;i++) {
- memset(buf - (i + 1) * wrap - w, buf[0], w); /* top left */
- memset(buf - (i + 1) * wrap + width, buf[width-1], w); /* top right */
- memset(last_line + (i + 1) * wrap - w, last_line[0], w); /* top left */
- memset(last_line + (i + 1) * wrap + width, last_line[width-1], w); /* top right */
- }
-}
-
-int ff_find_unused_picture(MpegEncContext *s, int shared){
- int i;
-
- if(shared){
- for(i=0; i<MAX_PICTURE_COUNT; i++){
- if(s->picture[i].data[0]==NULL && s->picture[i].type==0) return i;
- }
- }else{
- for(i=0; i<MAX_PICTURE_COUNT; i++){
- if(s->picture[i].data[0]==NULL && s->picture[i].type!=0) return i; //FIXME
- }
- for(i=0; i<MAX_PICTURE_COUNT; i++){
- if(s->picture[i].data[0]==NULL) return i;
- }
- }
-
- assert(0);
- return -1;
-}
-
-static void update_noise_reduction(MpegEncContext *s){
- int intra, i;
-
- for(intra=0; intra<2; intra++){
- if(s->dct_count[intra] > (1<<16)){
- for(i=0; i<64; i++){
- s->dct_error_sum[intra][i] >>=1;
- }
- s->dct_count[intra] >>= 1;
- }
-
- for(i=0; i<64; i++){
- s->dct_offset[intra][i]= (s->avctx->noise_reduction * s->dct_count[intra] + s->dct_error_sum[intra][i]/2) / (s->dct_error_sum[intra][i]+1);
- }
- }
-}
-
-/**
- * generic function for encode/decode called after coding/decoding the header and before a frame is coded/decoded
- */
-int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx)
-{
- int i;
- AVFrame *pic;
- s->mb_skipped = 0;
-
- assert(s->last_picture_ptr==NULL || s->out_format != FMT_H264 || s->codec_id == CODEC_ID_SVQ3);
-
- /* mark&release old frames */
- if (s->pict_type != B_TYPE && s->last_picture_ptr && s->last_picture_ptr != s->next_picture_ptr && s->last_picture_ptr->data[0]) {
- if(s->out_format != FMT_H264 || s->codec_id == CODEC_ID_SVQ3){
- avctx->release_buffer(avctx, (AVFrame*)s->last_picture_ptr);
-
- /* release forgotten pictures */
- /* if(mpeg124/h263) */
- if(!s->encoding){
- for(i=0; i<MAX_PICTURE_COUNT; i++){
- if(s->picture[i].data[0] && &s->picture[i] != s->next_picture_ptr && s->picture[i].reference){
- av_log(avctx, AV_LOG_ERROR, "releasing zombie picture\n");
- avctx->release_buffer(avctx, (AVFrame*)&s->picture[i]);
- }
- }
- }
- }
- }
-alloc:
- if(!s->encoding){
- /* release non reference frames */
- for(i=0; i<MAX_PICTURE_COUNT; i++){
- if(s->picture[i].data[0] && !s->picture[i].reference /*&& s->picture[i].type!=FF_BUFFER_TYPE_SHARED*/){
- s->avctx->release_buffer(s->avctx, (AVFrame*)&s->picture[i]);
- }
- }
-
- if(s->current_picture_ptr && s->current_picture_ptr->data[0]==NULL)
- pic= (AVFrame*)s->current_picture_ptr; //we allready have a unused image (maybe it was set before reading the header)
- else{
- i= ff_find_unused_picture(s, 0);
- pic= (AVFrame*)&s->picture[i];
- }
-
- pic->reference= (s->pict_type != B_TYPE || s->codec_id == CODEC_ID_H264)
- && !s->dropable ? 3 : 0;
-
- pic->coded_picture_number= s->coded_picture_number++;
-
- if( alloc_picture(s, (Picture*)pic, 0) < 0)
- return -1;
-
- s->current_picture_ptr= (Picture*)pic;
- s->current_picture_ptr->top_field_first= s->top_field_first; //FIXME use only the vars from current_pic
- s->current_picture_ptr->interlaced_frame= !s->progressive_frame && !s->progressive_sequence;
- }
-
- s->current_picture_ptr->pict_type= s->pict_type;
-// if(s->flags && CODEC_FLAG_QSCALE)
- // s->current_picture_ptr->quality= s->new_picture_ptr->quality;
- s->current_picture_ptr->key_frame= s->pict_type == I_TYPE;
-
- copy_picture(&s->current_picture, s->current_picture_ptr);
-
- if (s->pict_type != B_TYPE) {
- s->last_picture_ptr= s->next_picture_ptr;
- if(!s->dropable)
- s->next_picture_ptr= s->current_picture_ptr;
- }
-/* av_log(s->avctx, AV_LOG_DEBUG, "L%p N%p C%p L%p N%p C%p type:%d drop:%d\n", s->last_picture_ptr, s->next_picture_ptr,s->current_picture_ptr,
- s->last_picture_ptr ? s->last_picture_ptr->data[0] : NULL,
- s->next_picture_ptr ? s->next_picture_ptr->data[0] : NULL,
- s->current_picture_ptr ? s->current_picture_ptr->data[0] : NULL,
- s->pict_type, s->dropable);*/
-
- if(s->last_picture_ptr) copy_picture(&s->last_picture, s->last_picture_ptr);
- if(s->next_picture_ptr) copy_picture(&s->next_picture, s->next_picture_ptr);
-
- if(s->pict_type != I_TYPE && (s->last_picture_ptr==NULL || s->last_picture_ptr->data[0]==NULL) && !s->dropable){
- av_log(avctx, AV_LOG_ERROR, "warning: first frame is no keyframe\n");
- assert(s->pict_type != B_TYPE); //these should have been dropped if we don't have a reference
- goto alloc;
- }
-
- assert(s->pict_type == I_TYPE || (s->last_picture_ptr && s->last_picture_ptr->data[0]));
-
- if(s->picture_structure!=PICT_FRAME){
- int i;
- for(i=0; i<4; i++){
- if(s->picture_structure == PICT_BOTTOM_FIELD){
- s->current_picture.data[i] += s->current_picture.linesize[i];
- }
- s->current_picture.linesize[i] *= 2;
- s->last_picture.linesize[i] *=2;
- s->next_picture.linesize[i] *=2;
- }
- }
-
- s->hurry_up= s->avctx->hurry_up;
- s->error_resilience= avctx->error_resilience;
-
- /* set dequantizer, we can't do it during init as it might change for mpeg4
- and we can't do it in the header decode as init isnt called for mpeg4 there yet */
- if(s->mpeg_quant || s->codec_id == CODEC_ID_MPEG2VIDEO){
- s->dct_unquantize_intra = s->dct_unquantize_mpeg2_intra;
- s->dct_unquantize_inter = s->dct_unquantize_mpeg2_inter;
- }else if(s->out_format == FMT_H263 || s->out_format == FMT_H261){
- s->dct_unquantize_intra = s->dct_unquantize_h263_intra;
- s->dct_unquantize_inter = s->dct_unquantize_h263_inter;
- }else{
- s->dct_unquantize_intra = s->dct_unquantize_mpeg1_intra;
- s->dct_unquantize_inter = s->dct_unquantize_mpeg1_inter;
- }
-
- if(s->dct_error_sum){
- assert(s->avctx->noise_reduction && s->encoding);
-
- update_noise_reduction(s);
- }
-
-#ifdef HAVE_XVMC
- if(s->avctx->xvmc_acceleration)
- return XVMC_field_start(s, avctx);
-#endif
- return 0;
-}
-
-/* generic function for encode/decode called after a frame has been coded/decoded */
-void MPV_frame_end(MpegEncContext *s)
-{
- int i;
- /* draw edge for correct motion prediction if outside */
-#ifdef HAVE_XVMC
-//just to make sure that all data is rendered.
- if(s->avctx->xvmc_acceleration){
- XVMC_field_end(s);
- }else
-#endif
- if(s->unrestricted_mv && s->current_picture.reference && !s->intra_only && !(s->flags&CODEC_FLAG_EMU_EDGE)) {
- draw_edges(s->current_picture.data[0], s->linesize , s->h_edge_pos , s->v_edge_pos , EDGE_WIDTH );
- draw_edges(s->current_picture.data[1], s->uvlinesize, s->h_edge_pos>>1, s->v_edge_pos>>1, EDGE_WIDTH/2);
- draw_edges(s->current_picture.data[2], s->uvlinesize, s->h_edge_pos>>1, s->v_edge_pos>>1, EDGE_WIDTH/2);
- }
- emms_c();
-
- s->last_pict_type = s->pict_type;
- s->last_lambda_for[s->pict_type]= s->current_picture_ptr->quality;
- if(s->pict_type!=B_TYPE){
- s->last_non_b_pict_type= s->pict_type;
- }
-#if 0
- /* copy back current_picture variables */
- for(i=0; i<MAX_PICTURE_COUNT; i++){
- if(s->picture[i].data[0] == s->current_picture.data[0]){
- s->picture[i]= s->current_picture;
- break;
- }
- }
- assert(i<MAX_PICTURE_COUNT);
-#endif
-
- if(s->encoding){
- /* release non-reference frames */
- for(i=0; i<MAX_PICTURE_COUNT; i++){
- if(s->picture[i].data[0] && !s->picture[i].reference /*&& s->picture[i].type!=FF_BUFFER_TYPE_SHARED*/){
- s->avctx->release_buffer(s->avctx, (AVFrame*)&s->picture[i]);
- }
- }
- }
- // clear copies, to avoid confusion
-#if 0
- memset(&s->last_picture, 0, sizeof(Picture));
- memset(&s->next_picture, 0, sizeof(Picture));
- memset(&s->current_picture, 0, sizeof(Picture));
-#endif
- s->avctx->coded_frame= (AVFrame*)s->current_picture_ptr;
-}
-
-/**
- * draws an line from (ex, ey) -> (sx, sy).
- * @param w width of the image
- * @param h height of the image
- * @param stride stride/linesize of the image
- * @param color color of the arrow
- */
-static void draw_line(uint8_t *buf, int sx, int sy, int ex, int ey, int w, int h, int stride, int color){
- int x, y, fr, f;
-
- sx= clip(sx, 0, w-1);
- sy= clip(sy, 0, h-1);
- ex= clip(ex, 0, w-1);
- ey= clip(ey, 0, h-1);
-
- buf[sy*stride + sx]+= color;
-
- if(FFABS(ex - sx) > FFABS(ey - sy)){
- if(sx > ex){
- FFSWAP(int, sx, ex);
- FFSWAP(int, sy, ey);
- }
- buf+= sx + sy*stride;
- ex-= sx;
- f= ((ey-sy)<<16)/ex;
- for(x= 0; x <= ex; x++){
- y = (x*f)>>16;
- fr= (x*f)&0xFFFF;
- buf[ y *stride + x]+= (color*(0x10000-fr))>>16;
- buf[(y+1)*stride + x]+= (color* fr )>>16;
- }
- }else{
- if(sy > ey){
- FFSWAP(int, sx, ex);
- FFSWAP(int, sy, ey);
- }
- buf+= sx + sy*stride;
- ey-= sy;
- if(ey) f= ((ex-sx)<<16)/ey;
- else f= 0;
- for(y= 0; y <= ey; y++){
- x = (y*f)>>16;
- fr= (y*f)&0xFFFF;
- buf[y*stride + x ]+= (color*(0x10000-fr))>>16;;
- buf[y*stride + x+1]+= (color* fr )>>16;;
- }
- }
-}
-
-/**
- * draws an arrow from (ex, ey) -> (sx, sy).
- * @param w width of the image
- * @param h height of the image
- * @param stride stride/linesize of the image
- * @param color color of the arrow
- */
-static void draw_arrow(uint8_t *buf, int sx, int sy, int ex, int ey, int w, int h, int stride, int color){
- int dx,dy;
-
- sx= clip(sx, -100, w+100);
- sy= clip(sy, -100, h+100);
- ex= clip(ex, -100, w+100);
- ey= clip(ey, -100, h+100);
-
- dx= ex - sx;
- dy= ey - sy;
-
- if(dx*dx + dy*dy > 3*3){
- int rx= dx + dy;
- int ry= -dx + dy;
- int length= ff_sqrt((rx*rx + ry*ry)<<8);
-
- //FIXME subpixel accuracy
- rx= ROUNDED_DIV(rx*3<<4, length);
- ry= ROUNDED_DIV(ry*3<<4, length);
-
- draw_line(buf, sx, sy, sx + rx, sy + ry, w, h, stride, color);
- draw_line(buf, sx, sy, sx - ry, sy + rx, w, h, stride, color);
- }
- draw_line(buf, sx, sy, ex, ey, w, h, stride, color);
-}
-
-/**
- * prints debuging info for the given picture.
- */
-void ff_print_debug_info(MpegEncContext *s, AVFrame *pict){
-
- if(!pict || !pict->mb_type) return;
-
- if(s->avctx->debug&(FF_DEBUG_SKIP | FF_DEBUG_QP | FF_DEBUG_MB_TYPE)){
- int x,y;
-
- av_log(s->avctx,AV_LOG_DEBUG,"New frame, type: ");
- switch (pict->pict_type) {
- case FF_I_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"I\n"); break;
- case FF_P_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"P\n"); break;
- case FF_B_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"B\n"); break;
- case FF_S_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"S\n"); break;
- case FF_SI_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"SI\n"); break;
- case FF_SP_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"SP\n"); break;
- }
- for(y=0; y<s->mb_height; y++){
- for(x=0; x<s->mb_width; x++){
- if(s->avctx->debug&FF_DEBUG_SKIP){
- int count= s->mbskip_table[x + y*s->mb_stride];
- if(count>9) count=9;
- av_log(s->avctx, AV_LOG_DEBUG, "%1d", count);
- }
- if(s->avctx->debug&FF_DEBUG_QP){
- av_log(s->avctx, AV_LOG_DEBUG, "%2d", pict->qscale_table[x + y*s->mb_stride]);
- }
- if(s->avctx->debug&FF_DEBUG_MB_TYPE){
- int mb_type= pict->mb_type[x + y*s->mb_stride];
- //Type & MV direction
- if(IS_PCM(mb_type))
- av_log(s->avctx, AV_LOG_DEBUG, "P");
- else if(IS_INTRA(mb_type) && IS_ACPRED(mb_type))
- av_log(s->avctx, AV_LOG_DEBUG, "A");
- else if(IS_INTRA4x4(mb_type))
- av_log(s->avctx, AV_LOG_DEBUG, "i");
- else if(IS_INTRA16x16(mb_type))
- av_log(s->avctx, AV_LOG_DEBUG, "I");
- else if(IS_DIRECT(mb_type) && IS_SKIP(mb_type))
- av_log(s->avctx, AV_LOG_DEBUG, "d");
- else if(IS_DIRECT(mb_type))
- av_log(s->avctx, AV_LOG_DEBUG, "D");
- else if(IS_GMC(mb_type) && IS_SKIP(mb_type))
- av_log(s->avctx, AV_LOG_DEBUG, "g");
- else if(IS_GMC(mb_type))
- av_log(s->avctx, AV_LOG_DEBUG, "G");
- else if(IS_SKIP(mb_type))
- av_log(s->avctx, AV_LOG_DEBUG, "S");
- else if(!USES_LIST(mb_type, 1))
- av_log(s->avctx, AV_LOG_DEBUG, ">");
- else if(!USES_LIST(mb_type, 0))
- av_log(s->avctx, AV_LOG_DEBUG, "<");
- else{
- assert(USES_LIST(mb_type, 0) && USES_LIST(mb_type, 1));
- av_log(s->avctx, AV_LOG_DEBUG, "X");
- }
-
- //segmentation
- if(IS_8X8(mb_type))
- av_log(s->avctx, AV_LOG_DEBUG, "+");
- else if(IS_16X8(mb_type))
- av_log(s->avctx, AV_LOG_DEBUG, "-");
- else if(IS_8X16(mb_type))
- av_log(s->avctx, AV_LOG_DEBUG, "|");
- else if(IS_INTRA(mb_type) || IS_16X16(mb_type))
- av_log(s->avctx, AV_LOG_DEBUG, " ");
- else
- av_log(s->avctx, AV_LOG_DEBUG, "?");
-
-
- if(IS_INTERLACED(mb_type) && s->codec_id == CODEC_ID_H264)
- av_log(s->avctx, AV_LOG_DEBUG, "=");
- else
- av_log(s->avctx, AV_LOG_DEBUG, " ");
- }
-// av_log(s->avctx, AV_LOG_DEBUG, " ");
- }
- av_log(s->avctx, AV_LOG_DEBUG, "\n");
- }
- }
-
- if((s->avctx->debug&(FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)) || (s->avctx->debug_mv)){
- const int shift= 1 + s->quarter_sample;
- int mb_y;
- uint8_t *ptr;
- int i;
- int h_chroma_shift, v_chroma_shift;
- const int width = s->avctx->width;
- const int height= s->avctx->height;
- const int mv_sample_log2= 4 - pict->motion_subsample_log2;
- const int mv_stride= (s->mb_width << mv_sample_log2) + (s->codec_id == CODEC_ID_H264 ? 0 : 1);
- s->low_delay=0; //needed to see the vectors without trashing the buffers
-
- avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &h_chroma_shift, &v_chroma_shift);
- for(i=0; i<3; i++){
- memcpy(s->visualization_buffer[i], pict->data[i], (i==0) ? pict->linesize[i]*height:pict->linesize[i]*height >> v_chroma_shift);
- pict->data[i]= s->visualization_buffer[i];
- }
- pict->type= FF_BUFFER_TYPE_COPY;
- ptr= pict->data[0];
-
- for(mb_y=0; mb_y<s->mb_height; mb_y++){
- int mb_x;
- for(mb_x=0; mb_x<s->mb_width; mb_x++){
- const int mb_index= mb_x + mb_y*s->mb_stride;
- if((s->avctx->debug_mv) && pict->motion_val){
- int type;
- for(type=0; type<3; type++){
- int direction = 0;
- switch (type) {
- case 0: if ((!(s->avctx->debug_mv&FF_DEBUG_VIS_MV_P_FOR)) || (pict->pict_type!=FF_P_TYPE))
- continue;
- direction = 0;
- break;
- case 1: if ((!(s->avctx->debug_mv&FF_DEBUG_VIS_MV_B_FOR)) || (pict->pict_type!=FF_B_TYPE))
- continue;
- direction = 0;
- break;
- case 2: if ((!(s->avctx->debug_mv&FF_DEBUG_VIS_MV_B_BACK)) || (pict->pict_type!=FF_B_TYPE))
- continue;
- direction = 1;
- break;
- }
- if(!USES_LIST(pict->mb_type[mb_index], direction))
- continue;
-
- if(IS_8X8(pict->mb_type[mb_index])){
- int i;
- for(i=0; i<4; i++){
- int sx= mb_x*16 + 4 + 8*(i&1);
- int sy= mb_y*16 + 4 + 8*(i>>1);
- int xy= (mb_x*2 + (i&1) + (mb_y*2 + (i>>1))*mv_stride) << (mv_sample_log2-1);
- int mx= (pict->motion_val[direction][xy][0]>>shift) + sx;
- int my= (pict->motion_val[direction][xy][1]>>shift) + sy;
- draw_arrow(ptr, sx, sy, mx, my, width, height, s->linesize, 100);
- }
- }else if(IS_16X8(pict->mb_type[mb_index])){
- int i;
- for(i=0; i<2; i++){
- int sx=mb_x*16 + 8;
- int sy=mb_y*16 + 4 + 8*i;
- int xy= (mb_x*2 + (mb_y*2 + i)*mv_stride) << (mv_sample_log2-1);
- int mx=(pict->motion_val[direction][xy][0]>>shift);
- int my=(pict->motion_val[direction][xy][1]>>shift);
-
- if(IS_INTERLACED(pict->mb_type[mb_index]))
- my*=2;
-
- draw_arrow(ptr, sx, sy, mx+sx, my+sy, width, height, s->linesize, 100);
- }
- }else if(IS_8X16(pict->mb_type[mb_index])){
- int i;
- for(i=0; i<2; i++){
- int sx=mb_x*16 + 4 + 8*i;
- int sy=mb_y*16 + 8;
- int xy= (mb_x*2 + i + mb_y*2*mv_stride) << (mv_sample_log2-1);
- int mx=(pict->motion_val[direction][xy][0]>>shift);
- int my=(pict->motion_val[direction][xy][1]>>shift);
-
- if(IS_INTERLACED(pict->mb_type[mb_index]))
- my*=2;
-
- draw_arrow(ptr, sx, sy, mx+sx, my+sy, width, height, s->linesize, 100);
- }
- }else{
- int sx= mb_x*16 + 8;
- int sy= mb_y*16 + 8;
- int xy= (mb_x + mb_y*mv_stride) << mv_sample_log2;
- int mx= (pict->motion_val[direction][xy][0]>>shift) + sx;
- int my= (pict->motion_val[direction][xy][1]>>shift) + sy;
- draw_arrow(ptr, sx, sy, mx, my, width, height, s->linesize, 100);
- }
- }
- }
- if((s->avctx->debug&FF_DEBUG_VIS_QP) && pict->motion_val){
- uint64_t c= (pict->qscale_table[mb_index]*128/31) * 0x0101010101010101ULL;
- int y;
- for(y=0; y<8; y++){
- *(uint64_t*)(pict->data[1] + 8*mb_x + (8*mb_y + y)*pict->linesize[1])= c;
- *(uint64_t*)(pict->data[2] + 8*mb_x + (8*mb_y + y)*pict->linesize[2])= c;
- }
- }
- if((s->avctx->debug&FF_DEBUG_VIS_MB_TYPE) && pict->motion_val){
- int mb_type= pict->mb_type[mb_index];
- uint64_t u,v;
- int y;
-#define COLOR(theta, r)\
-u= (int)(128 + r*cos(theta*3.141592/180));\
-v= (int)(128 + r*sin(theta*3.141592/180));
-
-
- u=v=128;
- if(IS_PCM(mb_type)){
- COLOR(120,48)
- }else if((IS_INTRA(mb_type) && IS_ACPRED(mb_type)) || IS_INTRA16x16(mb_type)){
- COLOR(30,48)
- }else if(IS_INTRA4x4(mb_type)){
- COLOR(90,48)
- }else if(IS_DIRECT(mb_type) && IS_SKIP(mb_type)){
-// COLOR(120,48)
- }else if(IS_DIRECT(mb_type)){
- COLOR(150,48)
- }else if(IS_GMC(mb_type) && IS_SKIP(mb_type)){
- COLOR(170,48)
- }else if(IS_GMC(mb_type)){
- COLOR(190,48)
- }else if(IS_SKIP(mb_type)){
-// COLOR(180,48)
- }else if(!USES_LIST(mb_type, 1)){
- COLOR(240,48)
- }else if(!USES_LIST(mb_type, 0)){
- COLOR(0,48)
- }else{
- assert(USES_LIST(mb_type, 0) && USES_LIST(mb_type, 1));
- COLOR(300,48)
- }
-
- u*= 0x0101010101010101ULL;
- v*= 0x0101010101010101ULL;
- for(y=0; y<8; y++){
- *(uint64_t*)(pict->data[1] + 8*mb_x + (8*mb_y + y)*pict->linesize[1])= u;
- *(uint64_t*)(pict->data[2] + 8*mb_x + (8*mb_y + y)*pict->linesize[2])= v;
- }
-
- //segmentation
- if(IS_8X8(mb_type) || IS_16X8(mb_type)){
- *(uint64_t*)(pict->data[0] + 16*mb_x + 0 + (16*mb_y + 8)*pict->linesize[0])^= 0x8080808080808080ULL;
- *(uint64_t*)(pict->data[0] + 16*mb_x + 8 + (16*mb_y + 8)*pict->linesize[0])^= 0x8080808080808080ULL;
- }
- if(IS_8X8(mb_type) || IS_8X16(mb_type)){
- for(y=0; y<16; y++)
- pict->data[0][16*mb_x + 8 + (16*mb_y + y)*pict->linesize[0]]^= 0x80;
- }
- if(IS_8X8(mb_type) && mv_sample_log2 >= 2){
- int dm= 1 << (mv_sample_log2-2);
- for(i=0; i<4; i++){
- int sx= mb_x*16 + 8*(i&1);
- int sy= mb_y*16 + 8*(i>>1);
- int xy= (mb_x*2 + (i&1) + (mb_y*2 + (i>>1))*mv_stride) << (mv_sample_log2-1);
- //FIXME bidir
- int32_t *mv = (int32_t*)&pict->motion_val[0][xy];
- if(mv[0] != mv[dm] || mv[dm*mv_stride] != mv[dm*(mv_stride+1)])
- for(y=0; y<8; y++)
- pict->data[0][sx + 4 + (sy + y)*pict->linesize[0]]^= 0x80;
- if(mv[0] != mv[dm*mv_stride] || mv[dm] != mv[dm*(mv_stride+1)])
- *(uint64_t*)(pict->data[0] + sx + (sy + 4)*pict->linesize[0])^= 0x8080808080808080ULL;
- }
- }
-
- if(IS_INTERLACED(mb_type) && s->codec_id == CODEC_ID_H264){
- // hmm
- }
- }
- s->mbskip_table[mb_index]=0;
- }
- }
- }
-}
-
-#ifdef CONFIG_ENCODERS
-
-static int get_sae(uint8_t *src, int ref, int stride){
- int x,y;
- int acc=0;
-
- for(y=0; y<16; y++){
- for(x=0; x<16; x++){
- acc+= FFABS(src[x+y*stride] - ref);
- }
- }
-
- return acc;
-}
-
-static int get_intra_count(MpegEncContext *s, uint8_t *src, uint8_t *ref, int stride){
- int x, y, w, h;
- int acc=0;
-
- w= s->width &~15;
- h= s->height&~15;
-
- for(y=0; y<h; y+=16){
- for(x=0; x<w; x+=16){
- int offset= x + y*stride;
- int sad = s->dsp.sad[0](NULL, src + offset, ref + offset, stride, 16);
- int mean= (s->dsp.pix_sum(src + offset, stride) + 128)>>8;
- int sae = get_sae(src + offset, mean, stride);
-
- acc+= sae + 500 < sad;
- }
- }
- return acc;
-}
-
-
-static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg){
- AVFrame *pic=NULL;
- int64_t pts;
- int i;
- const int encoding_delay= s->max_b_frames;
- int direct=1;
-
- if(pic_arg){
- pts= pic_arg->pts;
- pic_arg->display_picture_number= s->input_picture_number++;
-
- if(pts != AV_NOPTS_VALUE){
- if(s->user_specified_pts != AV_NOPTS_VALUE){
- int64_t time= pts;
- int64_t last= s->user_specified_pts;
-
- if(time <= last){
- av_log(s->avctx, AV_LOG_ERROR, "Error, Invalid timestamp=%"PRId64", last=%"PRId64"\n", pts, s->user_specified_pts);
- return -1;
- }
- }
- s->user_specified_pts= pts;
- }else{
- if(s->user_specified_pts != AV_NOPTS_VALUE){
- s->user_specified_pts=
- pts= s->user_specified_pts + 1;
- av_log(s->avctx, AV_LOG_INFO, "Warning: AVFrame.pts=? trying to guess (%"PRId64")\n", pts);
- }else{
- pts= pic_arg->display_picture_number;
- }
- }
- }
-
- if(pic_arg){
- if(encoding_delay && !(s->flags&CODEC_FLAG_INPUT_PRESERVED)) direct=0;
- if(pic_arg->linesize[0] != s->linesize) direct=0;
- if(pic_arg->linesize[1] != s->uvlinesize) direct=0;
- if(pic_arg->linesize[2] != s->uvlinesize) direct=0;
-
-// av_log(AV_LOG_DEBUG, "%d %d %d %d\n",pic_arg->linesize[0], pic_arg->linesize[1], s->linesize, s->uvlinesize);
-
- if(direct){
- i= ff_find_unused_picture(s, 1);
-
- pic= (AVFrame*)&s->picture[i];
- pic->reference= 3;
-
- for(i=0; i<4; i++){
- pic->data[i]= pic_arg->data[i];
- pic->linesize[i]= pic_arg->linesize[i];
- }
- alloc_picture(s, (Picture*)pic, 1);
- }else{
- i= ff_find_unused_picture(s, 0);
-
- pic= (AVFrame*)&s->picture[i];
- pic->reference= 3;
-
- alloc_picture(s, (Picture*)pic, 0);
-
- if( pic->data[0] + INPLACE_OFFSET == pic_arg->data[0]
- && pic->data[1] + INPLACE_OFFSET == pic_arg->data[1]
- && pic->data[2] + INPLACE_OFFSET == pic_arg->data[2]){
- // empty
- }else{
- int h_chroma_shift, v_chroma_shift;
- avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &h_chroma_shift, &v_chroma_shift);
-
- for(i=0; i<3; i++){
- int src_stride= pic_arg->linesize[i];
- int dst_stride= i ? s->uvlinesize : s->linesize;
- int h_shift= i ? h_chroma_shift : 0;
- int v_shift= i ? v_chroma_shift : 0;
- int w= s->width >>h_shift;
- int h= s->height>>v_shift;
- uint8_t *src= pic_arg->data[i];
- uint8_t *dst= pic->data[i];
-
- if(!s->avctx->rc_buffer_size)
- dst +=INPLACE_OFFSET;
-
- if(src_stride==dst_stride)
- memcpy(dst, src, src_stride*h);
- else{
- while(h--){
- memcpy(dst, src, w);
- dst += dst_stride;
- src += src_stride;
- }
- }
- }
- }
- }
- copy_picture_attributes(s, pic, pic_arg);
- pic->pts= pts; //we set this here to avoid modifiying pic_arg
- }
-
- /* shift buffer entries */
- for(i=1; i<MAX_PICTURE_COUNT /*s->encoding_delay+1*/; i++)
- s->input_picture[i-1]= s->input_picture[i];
-
- s->input_picture[encoding_delay]= (Picture*)pic;
-
- return 0;
-}
-
-static int skip_check(MpegEncContext *s, Picture *p, Picture *ref){
- int x, y, plane;
- int score=0;
- int64_t score64=0;
-
- for(plane=0; plane<3; plane++){
- const int stride= p->linesize[plane];
- const int bw= plane ? 1 : 2;
- for(y=0; y<s->mb_height*bw; y++){
- for(x=0; x<s->mb_width*bw; x++){
- int off= p->type == FF_BUFFER_TYPE_SHARED ? 0: 16;
- int v= s->dsp.frame_skip_cmp[1](s, p->data[plane] + 8*(x + y*stride)+off, ref->data[plane] + 8*(x + y*stride), stride, 8);
-
- switch(s->avctx->frame_skip_exp){
- case 0: score= FFMAX(score, v); break;
- case 1: score+= FFABS(v);break;
- case 2: score+= v*v;break;
- case 3: score64+= FFABS(v*v*(int64_t)v);break;
- case 4: score64+= v*v*(int64_t)(v*v);break;
- }
- }
- }
- }
-
- if(score) score64= score;
-
- if(score64 < s->avctx->frame_skip_threshold)
- return 1;
- if(score64 < ((s->avctx->frame_skip_factor * (int64_t)s->lambda)>>8))
- return 1;
- return 0;
-}
-
-static int estimate_best_b_count(MpegEncContext *s){
- AVCodec *codec= avcodec_find_encoder(s->avctx->codec_id);
- AVCodecContext *c= avcodec_alloc_context();
- AVFrame input[FF_MAX_B_FRAMES+2];
- const int scale= s->avctx->brd_scale;
- int i, j, out_size, p_lambda, b_lambda, lambda2;
- int outbuf_size= s->width * s->height; //FIXME
- uint8_t *outbuf= av_malloc(outbuf_size);
- int64_t best_rd= INT64_MAX;
- int best_b_count= -1;
-
- assert(scale>=0 && scale <=3);
-
-// emms_c();
- p_lambda= s->last_lambda_for[P_TYPE]; //s->next_picture_ptr->quality;
- b_lambda= s->last_lambda_for[B_TYPE]; //p_lambda *FFABS(s->avctx->b_quant_factor) + s->avctx->b_quant_offset;
- if(!b_lambda) b_lambda= p_lambda; //FIXME we should do this somewhere else
- lambda2= (b_lambda*b_lambda + (1<<FF_LAMBDA_SHIFT)/2 ) >> FF_LAMBDA_SHIFT;
-
- c->width = s->width >> scale;
- c->height= s->height>> scale;
- c->flags= CODEC_FLAG_QSCALE | CODEC_FLAG_PSNR | CODEC_FLAG_INPUT_PRESERVED /*| CODEC_FLAG_EMU_EDGE*/;
- c->flags|= s->avctx->flags & CODEC_FLAG_QPEL;
- c->mb_decision= s->avctx->mb_decision;
- c->me_cmp= s->avctx->me_cmp;
- c->mb_cmp= s->avctx->mb_cmp;
- c->me_sub_cmp= s->avctx->me_sub_cmp;
- c->pix_fmt = PIX_FMT_YUV420P;
- c->time_base= s->avctx->time_base;
- c->max_b_frames= s->max_b_frames;
-
- if (avcodec_open(c, codec) < 0)
- return -1;
-
- for(i=0; i<s->max_b_frames+2; i++){
- int ysize= c->width*c->height;
- int csize= (c->width/2)*(c->height/2);
- Picture pre_input, *pre_input_ptr= i ? s->input_picture[i-1] : s->next_picture_ptr;
-
- avcodec_get_frame_defaults(&input[i]);
- input[i].data[0]= av_malloc(ysize + 2*csize);
- input[i].data[1]= input[i].data[0] + ysize;
- input[i].data[2]= input[i].data[1] + csize;
- input[i].linesize[0]= c->width;
- input[i].linesize[1]=
- input[i].linesize[2]= c->width/2;
-
- if(pre_input_ptr && (!i || s->input_picture[i-1])) {
- pre_input= *pre_input_ptr;
-
- if(pre_input.type != FF_BUFFER_TYPE_SHARED && i) {
- pre_input.data[0]+=INPLACE_OFFSET;
- pre_input.data[1]+=INPLACE_OFFSET;
- pre_input.data[2]+=INPLACE_OFFSET;
- }
-
- s->dsp.shrink[scale](input[i].data[0], input[i].linesize[0], pre_input.data[0], pre_input.linesize[0], c->width, c->height);
- s->dsp.shrink[scale](input[i].data[1], input[i].linesize[1], pre_input.data[1], pre_input.linesize[1], c->width>>1, c->height>>1);
- s->dsp.shrink[scale](input[i].data[2], input[i].linesize[2], pre_input.data[2], pre_input.linesize[2], c->width>>1, c->height>>1);
- }
- }
-
- for(j=0; j<s->max_b_frames+1; j++){
- int64_t rd=0;
-
- if(!s->input_picture[j])
- break;
-
- c->error[0]= c->error[1]= c->error[2]= 0;
-
- input[0].pict_type= I_TYPE;
- input[0].quality= 1 * FF_QP2LAMBDA;
- out_size = avcodec_encode_video(c, outbuf, outbuf_size, &input[0]);
-// rd += (out_size * lambda2) >> FF_LAMBDA_SHIFT;
-
- for(i=0; i<s->max_b_frames+1; i++){
- int is_p= i % (j+1) == j || i==s->max_b_frames;
-
- input[i+1].pict_type= is_p ? P_TYPE : B_TYPE;
- input[i+1].quality= is_p ? p_lambda : b_lambda;
- out_size = avcodec_encode_video(c, outbuf, outbuf_size, &input[i+1]);
- rd += (out_size * lambda2) >> (FF_LAMBDA_SHIFT - 3);
- }
-
- /* get the delayed frames */
- while(out_size){
- out_size = avcodec_encode_video(c, outbuf, outbuf_size, NULL);
- rd += (out_size * lambda2) >> (FF_LAMBDA_SHIFT - 3);
- }
-
- rd += c->error[0] + c->error[1] + c->error[2];
-
- if(rd < best_rd){
- best_rd= rd;
- best_b_count= j;
- }
- }
-
- av_freep(&outbuf);
- avcodec_close(c);
- av_freep(&c);
-
- for(i=0; i<s->max_b_frames+2; i++){
- av_freep(&input[i].data[0]);
- }
-
- return best_b_count;
-}
-
-static void select_input_picture(MpegEncContext *s){
- int i;
-
- for(i=1; i<MAX_PICTURE_COUNT; i++)
- s->reordered_input_picture[i-1]= s->reordered_input_picture[i];
- s->reordered_input_picture[MAX_PICTURE_COUNT-1]= NULL;
-
- /* set next picture type & ordering */
- if(s->reordered_input_picture[0]==NULL && s->input_picture[0]){
- if(/*s->picture_in_gop_number >= s->gop_size ||*/ s->next_picture_ptr==NULL || s->intra_only){
- s->reordered_input_picture[0]= s->input_picture[0];
- s->reordered_input_picture[0]->pict_type= I_TYPE;
- s->reordered_input_picture[0]->coded_picture_number= s->coded_picture_number++;
- }else{
- int b_frames;
-
- if(s->avctx->frame_skip_threshold || s->avctx->frame_skip_factor){
- if(s->picture_in_gop_number < s->gop_size && skip_check(s, s->input_picture[0], s->next_picture_ptr)){
- //FIXME check that te gop check above is +-1 correct
-//av_log(NULL, AV_LOG_DEBUG, "skip %p %"PRId64"\n", s->input_picture[0]->data[0], s->input_picture[0]->pts);
-
- if(s->input_picture[0]->type == FF_BUFFER_TYPE_SHARED){
- for(i=0; i<4; i++)
- s->input_picture[0]->data[i]= NULL;
- s->input_picture[0]->type= 0;
- }else{
- assert( s->input_picture[0]->type==FF_BUFFER_TYPE_USER
- || s->input_picture[0]->type==FF_BUFFER_TYPE_INTERNAL);
-
- s->avctx->release_buffer(s->avctx, (AVFrame*)s->input_picture[0]);
- }
-
- emms_c();
- ff_vbv_update(s, 0);
-
- goto no_output_pic;
- }
- }
-
- if(s->flags&CODEC_FLAG_PASS2){
- for(i=0; i<s->max_b_frames+1; i++){
- int pict_num= s->input_picture[0]->display_picture_number + i;
-
- if(pict_num >= s->rc_context.num_entries)
- break;
- if(!s->input_picture[i]){
- s->rc_context.entry[pict_num-1].new_pict_type = P_TYPE;
- break;
- }
-
- s->input_picture[i]->pict_type=
- s->rc_context.entry[pict_num].new_pict_type;
- }
- }
-
- if(s->avctx->b_frame_strategy==0){
- b_frames= s->max_b_frames;
- while(b_frames && !s->input_picture[b_frames]) b_frames--;
- }else if(s->avctx->b_frame_strategy==1){
- for(i=1; i<s->max_b_frames+1; i++){
- if(s->input_picture[i] && s->input_picture[i]->b_frame_score==0){
- s->input_picture[i]->b_frame_score=
- get_intra_count(s, s->input_picture[i ]->data[0],
- s->input_picture[i-1]->data[0], s->linesize) + 1;
- }
- }
- for(i=0; i<s->max_b_frames+1; i++){
- if(s->input_picture[i]==NULL || s->input_picture[i]->b_frame_score - 1 > s->mb_num/s->avctx->b_sensitivity) break;
- }
-
- b_frames= FFMAX(0, i-1);
-
- /* reset scores */
- for(i=0; i<b_frames+1; i++){
- s->input_picture[i]->b_frame_score=0;
- }
- }else if(s->avctx->b_frame_strategy==2){
- b_frames= estimate_best_b_count(s);
- }else{
- av_log(s->avctx, AV_LOG_ERROR, "illegal b frame strategy\n");
- b_frames=0;
- }
-
- emms_c();
-//static int b_count=0;
-//b_count+= b_frames;
-//av_log(s->avctx, AV_LOG_DEBUG, "b_frames: %d\n", b_count);
-
- for(i= b_frames - 1; i>=0; i--){
- int type= s->input_picture[i]->pict_type;
- if(type && type != B_TYPE)
- b_frames= i;
- }
- if(s->input_picture[b_frames]->pict_type == B_TYPE && b_frames == s->max_b_frames){
- av_log(s->avctx, AV_LOG_ERROR, "warning, too many b frames in a row\n");
- }
-
- if(s->picture_in_gop_number + b_frames >= s->gop_size){
- if((s->flags2 & CODEC_FLAG2_STRICT_GOP) && s->gop_size > s->picture_in_gop_number){
- b_frames= s->gop_size - s->picture_in_gop_number - 1;
- }else{
- if(s->flags & CODEC_FLAG_CLOSED_GOP)
- b_frames=0;
- s->input_picture[b_frames]->pict_type= I_TYPE;
- }
- }
-
- if( (s->flags & CODEC_FLAG_CLOSED_GOP)
- && b_frames
- && s->input_picture[b_frames]->pict_type== I_TYPE)
- b_frames--;
-
- s->reordered_input_picture[0]= s->input_picture[b_frames];
- if(s->reordered_input_picture[0]->pict_type != I_TYPE)
- s->reordered_input_picture[0]->pict_type= P_TYPE;
- s->reordered_input_picture[0]->coded_picture_number= s->coded_picture_number++;
- for(i=0; i<b_frames; i++){
- s->reordered_input_picture[i+1]= s->input_picture[i];
- s->reordered_input_picture[i+1]->pict_type= B_TYPE;
- s->reordered_input_picture[i+1]->coded_picture_number= s->coded_picture_number++;
- }
- }
- }
-no_output_pic:
- if(s->reordered_input_picture[0]){
- s->reordered_input_picture[0]->reference= s->reordered_input_picture[0]->pict_type!=B_TYPE ? 3 : 0;
-
- copy_picture(&s->new_picture, s->reordered_input_picture[0]);
-
- if(s->reordered_input_picture[0]->type == FF_BUFFER_TYPE_SHARED || s->avctx->rc_buffer_size){
- // input is a shared pix, so we can't modifiy it -> alloc a new one & ensure that the shared one is reuseable
-
- int i= ff_find_unused_picture(s, 0);
- Picture *pic= &s->picture[i];
-
- pic->reference = s->reordered_input_picture[0]->reference;
- alloc_picture(s, pic, 0);
-
- /* mark us unused / free shared pic */
- if(s->reordered_input_picture[0]->type == FF_BUFFER_TYPE_INTERNAL)
- s->avctx->release_buffer(s->avctx, (AVFrame*)s->reordered_input_picture[0]);
- for(i=0; i<4; i++)
- s->reordered_input_picture[0]->data[i]= NULL;
- s->reordered_input_picture[0]->type= 0;
-
- copy_picture_attributes(s, (AVFrame*)pic, (AVFrame*)s->reordered_input_picture[0]);
-
- s->current_picture_ptr= pic;
- }else{
- // input is not a shared pix -> reuse buffer for current_pix
-
- assert( s->reordered_input_picture[0]->type==FF_BUFFER_TYPE_USER
- || s->reordered_input_picture[0]->type==FF_BUFFER_TYPE_INTERNAL);
-
- s->current_picture_ptr= s->reordered_input_picture[0];
- for(i=0; i<4; i++){
- s->new_picture.data[i]+= INPLACE_OFFSET;
- }
- }
- copy_picture(&s->current_picture, s->current_picture_ptr);
-
- s->picture_number= s->new_picture.display_picture_number;
-//printf("dpn:%d\n", s->picture_number);
- }else{
- memset(&s->new_picture, 0, sizeof(Picture));
- }
-}
-
-int MPV_encode_picture(AVCodecContext *avctx,
- unsigned char *buf, int buf_size, void *data)
-{
- MpegEncContext *s = avctx->priv_data;
- AVFrame *pic_arg = data;
- int i, stuffing_count;
-
- for(i=0; i<avctx->thread_count; i++){
- int start_y= s->thread_context[i]->start_mb_y;
- int end_y= s->thread_context[i]-> end_mb_y;
- int h= s->mb_height;
- uint8_t *start= buf + (size_t)(((int64_t) buf_size)*start_y/h);
- uint8_t *end = buf + (size_t)(((int64_t) buf_size)* end_y/h);
-
- init_put_bits(&s->thread_context[i]->pb, start, end - start);
- }
-
- s->picture_in_gop_number++;
-
- if(load_input_picture(s, pic_arg) < 0)
- return -1;
-
- select_input_picture(s);
-
- /* output? */
- if(s->new_picture.data[0]){
- s->pict_type= s->new_picture.pict_type;
-//emms_c();
-//printf("qs:%f %f %d\n", s->new_picture.quality, s->current_picture.quality, s->qscale);
- MPV_frame_start(s, avctx);
-vbv_retry:
- if (encode_picture(s, s->picture_number) < 0)
- return -1;
-
- avctx->real_pict_num = s->picture_number;
- avctx->header_bits = s->header_bits;
- avctx->mv_bits = s->mv_bits;
- avctx->misc_bits = s->misc_bits;
- avctx->i_tex_bits = s->i_tex_bits;
- avctx->p_tex_bits = s->p_tex_bits;
- avctx->i_count = s->i_count;
- avctx->p_count = s->mb_num - s->i_count - s->skip_count; //FIXME f/b_count in avctx
- avctx->skip_count = s->skip_count;
-
- MPV_frame_end(s);
-
-/* xine: do not need this for decode or MPEG-1 encoding modes */
-#if 0
- if (s->out_format == FMT_MJPEG)
- mjpeg_picture_trailer(s);
-#endif /* #if 0 */
-
- if(avctx->rc_buffer_size){
- RateControlContext *rcc= &s->rc_context;
- int max_size= rcc->buffer_index/3;
-
- if(put_bits_count(&s->pb) > max_size && s->lambda < s->avctx->lmax){
- s->next_lambda= FFMAX(s->lambda+1, s->lambda*(s->qscale+1) / s->qscale);
- if(s->adaptive_quant){
- int i;
- for(i=0; i<s->mb_height*s->mb_stride; i++)
- s->lambda_table[i]= FFMAX(s->lambda_table[i]+1, s->lambda_table[i]*(s->qscale+1) / s->qscale);
- }
- s->mb_skipped = 0; //done in MPV_frame_start()
- if(s->pict_type==P_TYPE){ //done in encode_picture() so we must undo it
- if(s->flipflop_rounding || s->codec_id == CODEC_ID_H263P || s->codec_id == CODEC_ID_MPEG4)
- s->no_rounding ^= 1;
- }
- if(s->pict_type!=B_TYPE){
- s->time_base= s->last_time_base;
- s->last_non_b_time= s->time - s->pp_time;
- }
-// av_log(NULL, AV_LOG_ERROR, "R:%d ", s->next_lambda);
- for(i=0; i<avctx->thread_count; i++){
- PutBitContext *pb= &s->thread_context[i]->pb;
- init_put_bits(pb, pb->buf, pb->buf_end - pb->buf);
- }
- goto vbv_retry;
- }
-
- assert(s->avctx->rc_max_rate);
- }
-
- if(s->flags&CODEC_FLAG_PASS1)
- ff_write_pass1_stats(s);
-
- for(i=0; i<4; i++){
- s->current_picture_ptr->error[i]= s->current_picture.error[i];
- avctx->error[i] += s->current_picture_ptr->error[i];
- }
-
- if(s->flags&CODEC_FLAG_PASS1)
- assert(avctx->header_bits + avctx->mv_bits + avctx->misc_bits + avctx->i_tex_bits + avctx->p_tex_bits == put_bits_count(&s->pb));
- flush_put_bits(&s->pb);
- s->frame_bits = put_bits_count(&s->pb);
-
- stuffing_count= ff_vbv_update(s, s->frame_bits);
- if(stuffing_count){
- if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < stuffing_count + 50){
- av_log(s->avctx, AV_LOG_ERROR, "stuffing too large\n");
- return -1;
- }
-
- switch(s->codec_id){
- case CODEC_ID_MPEG1VIDEO:
- case CODEC_ID_MPEG2VIDEO:
- while(stuffing_count--){
- put_bits(&s->pb, 8, 0);
- }
- break;
- case CODEC_ID_MPEG4:
- put_bits(&s->pb, 16, 0);
- put_bits(&s->pb, 16, 0x1C3);
- stuffing_count -= 4;
- while(stuffing_count--){
- put_bits(&s->pb, 8, 0xFF);
- }
- break;
- default:
- av_log(s->avctx, AV_LOG_ERROR, "vbv buffer overflow\n");
- }
- flush_put_bits(&s->pb);
- s->frame_bits = put_bits_count(&s->pb);
- }
-
- /* update mpeg1/2 vbv_delay for CBR */
- if(s->avctx->rc_max_rate && s->avctx->rc_min_rate == s->avctx->rc_max_rate && s->out_format == FMT_MPEG1
- && 90000LL * (avctx->rc_buffer_size-1) <= s->avctx->rc_max_rate*0xFFFFLL){
- int vbv_delay;
-
- assert(s->repeat_first_field==0);
-
- vbv_delay= lrintf(90000 * s->rc_context.buffer_index / s->avctx->rc_max_rate);
- assert(vbv_delay < 0xFFFF);
-
- s->vbv_delay_ptr[0] &= 0xF8;
- s->vbv_delay_ptr[0] |= vbv_delay>>13;
- s->vbv_delay_ptr[1] = vbv_delay>>5;
- s->vbv_delay_ptr[2] &= 0x07;
- s->vbv_delay_ptr[2] |= vbv_delay<<3;
- }
- s->total_bits += s->frame_bits;
- avctx->frame_bits = s->frame_bits;
- }else{
- assert((pbBufPtr(&s->pb) == s->pb.buf));
- s->frame_bits=0;
- }
- assert((s->frame_bits&7)==0);
-
- return s->frame_bits/8;
-}
-
-#endif //CONFIG_ENCODERS
-
-static inline void gmc1_motion(MpegEncContext *s,
- uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
- uint8_t **ref_picture)
-{
- uint8_t *ptr;
- int offset, src_x, src_y, linesize, uvlinesize;
- int motion_x, motion_y;
- int emu=0;
-
- motion_x= s->sprite_offset[0][0];
- motion_y= s->sprite_offset[0][1];
- src_x = s->mb_x * 16 + (motion_x >> (s->sprite_warping_accuracy+1));
- src_y = s->mb_y * 16 + (motion_y >> (s->sprite_warping_accuracy+1));
- motion_x<<=(3-s->sprite_warping_accuracy);
- motion_y<<=(3-s->sprite_warping_accuracy);
- src_x = clip(src_x, -16, s->width);
- if (src_x == s->width)
- motion_x =0;
- src_y = clip(src_y, -16, s->height);
- if (src_y == s->height)
- motion_y =0;
-
- linesize = s->linesize;
- uvlinesize = s->uvlinesize;
-
- ptr = ref_picture[0] + (src_y * linesize) + src_x;
-
- if(s->flags&CODEC_FLAG_EMU_EDGE){
- if( (unsigned)src_x >= s->h_edge_pos - 17
- || (unsigned)src_y >= s->v_edge_pos - 17){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr, linesize, 17, 17, src_x, src_y, s->h_edge_pos, s->v_edge_pos);
- ptr= s->edge_emu_buffer;
- }
- }
-
- if((motion_x|motion_y)&7){
- s->dsp.gmc1(dest_y , ptr , linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding);
- s->dsp.gmc1(dest_y+8, ptr+8, linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding);
- }else{
- int dxy;
-
- dxy= ((motion_x>>3)&1) | ((motion_y>>2)&2);
- if (s->no_rounding){
- s->dsp.put_no_rnd_pixels_tab[0][dxy](dest_y, ptr, linesize, 16);
- }else{
- s->dsp.put_pixels_tab [0][dxy](dest_y, ptr, linesize, 16);
- }
- }
-
- if(s->flags&CODEC_FLAG_GRAY) return;
-
- motion_x= s->sprite_offset[1][0];
- motion_y= s->sprite_offset[1][1];
- src_x = s->mb_x * 8 + (motion_x >> (s->sprite_warping_accuracy+1));
- src_y = s->mb_y * 8 + (motion_y >> (s->sprite_warping_accuracy+1));
- motion_x<<=(3-s->sprite_warping_accuracy);
- motion_y<<=(3-s->sprite_warping_accuracy);
- src_x = clip(src_x, -8, s->width>>1);
- if (src_x == s->width>>1)
- motion_x =0;
- src_y = clip(src_y, -8, s->height>>1);
- if (src_y == s->height>>1)
- motion_y =0;
-
- offset = (src_y * uvlinesize) + src_x;
- ptr = ref_picture[1] + offset;
- if(s->flags&CODEC_FLAG_EMU_EDGE){
- if( (unsigned)src_x >= (s->h_edge_pos>>1) - 9
- || (unsigned)src_y >= (s->v_edge_pos>>1) - 9){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
- ptr= s->edge_emu_buffer;
- emu=1;
- }
- }
- s->dsp.gmc1(dest_cb, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding);
-
- ptr = ref_picture[2] + offset;
- if(emu){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
- ptr= s->edge_emu_buffer;
- }
- s->dsp.gmc1(dest_cr, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding);
-
- return;
-}
-
-static inline void gmc_motion(MpegEncContext *s,
- uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
- uint8_t **ref_picture)
-{
- uint8_t *ptr;
- int linesize, uvlinesize;
- const int a= s->sprite_warping_accuracy;
- int ox, oy;
-
- linesize = s->linesize;
- uvlinesize = s->uvlinesize;
-
- ptr = ref_picture[0];
-
- ox= s->sprite_offset[0][0] + s->sprite_delta[0][0]*s->mb_x*16 + s->sprite_delta[0][1]*s->mb_y*16;
- oy= s->sprite_offset[0][1] + s->sprite_delta[1][0]*s->mb_x*16 + s->sprite_delta[1][1]*s->mb_y*16;
-
- s->dsp.gmc(dest_y, ptr, linesize, 16,
- ox,
- oy,
- s->sprite_delta[0][0], s->sprite_delta[0][1],
- s->sprite_delta[1][0], s->sprite_delta[1][1],
- a+1, (1<<(2*a+1)) - s->no_rounding,
- s->h_edge_pos, s->v_edge_pos);
- s->dsp.gmc(dest_y+8, ptr, linesize, 16,
- ox + s->sprite_delta[0][0]*8,
- oy + s->sprite_delta[1][0]*8,
- s->sprite_delta[0][0], s->sprite_delta[0][1],
- s->sprite_delta[1][0], s->sprite_delta[1][1],
- a+1, (1<<(2*a+1)) - s->no_rounding,
- s->h_edge_pos, s->v_edge_pos);
-
- if(s->flags&CODEC_FLAG_GRAY) return;
-
- ox= s->sprite_offset[1][0] + s->sprite_delta[0][0]*s->mb_x*8 + s->sprite_delta[0][1]*s->mb_y*8;
- oy= s->sprite_offset[1][1] + s->sprite_delta[1][0]*s->mb_x*8 + s->sprite_delta[1][1]*s->mb_y*8;
-
- ptr = ref_picture[1];
- s->dsp.gmc(dest_cb, ptr, uvlinesize, 8,
- ox,
- oy,
- s->sprite_delta[0][0], s->sprite_delta[0][1],
- s->sprite_delta[1][0], s->sprite_delta[1][1],
- a+1, (1<<(2*a+1)) - s->no_rounding,
- s->h_edge_pos>>1, s->v_edge_pos>>1);
-
- ptr = ref_picture[2];
- s->dsp.gmc(dest_cr, ptr, uvlinesize, 8,
- ox,
- oy,
- s->sprite_delta[0][0], s->sprite_delta[0][1],
- s->sprite_delta[1][0], s->sprite_delta[1][1],
- a+1, (1<<(2*a+1)) - s->no_rounding,
- s->h_edge_pos>>1, s->v_edge_pos>>1);
-}
-
-/**
- * Copies a rectangular area of samples to a temporary buffer and replicates the boarder samples.
- * @param buf destination buffer
- * @param src source buffer
- * @param linesize number of bytes between 2 vertically adjacent samples in both the source and destination buffers
- * @param block_w width of block
- * @param block_h height of block
- * @param src_x x coordinate of the top left sample of the block in the source buffer
- * @param src_y y coordinate of the top left sample of the block in the source buffer
- * @param w width of the source buffer
- * @param h height of the source buffer
- */
-void ff_emulated_edge_mc(uint8_t *buf, uint8_t *src, int linesize, int block_w, int block_h,
- int src_x, int src_y, int w, int h){
- int x, y;
- int start_y, start_x, end_y, end_x;
-
- if(src_y>= h){
- src+= (h-1-src_y)*linesize;
- src_y=h-1;
- }else if(src_y<=-block_h){
- src+= (1-block_h-src_y)*linesize;
- src_y=1-block_h;
- }
- if(src_x>= w){
- src+= (w-1-src_x);
- src_x=w-1;
- }else if(src_x<=-block_w){
- src+= (1-block_w-src_x);
- src_x=1-block_w;
- }
-
- start_y= FFMAX(0, -src_y);
- start_x= FFMAX(0, -src_x);
- end_y= FFMIN(block_h, h-src_y);
- end_x= FFMIN(block_w, w-src_x);
-
- // copy existing part
- for(y=start_y; y<end_y; y++){
- for(x=start_x; x<end_x; x++){
- buf[x + y*linesize]= src[x + y*linesize];
- }
- }
-
- //top
- for(y=0; y<start_y; y++){
- for(x=start_x; x<end_x; x++){
- buf[x + y*linesize]= buf[x + start_y*linesize];
- }
- }
-
- //bottom
- for(y=end_y; y<block_h; y++){
- for(x=start_x; x<end_x; x++){
- buf[x + y*linesize]= buf[x + (end_y-1)*linesize];
- }
- }
-
- for(y=0; y<block_h; y++){
- //left
- for(x=0; x<start_x; x++){
- buf[x + y*linesize]= buf[start_x + y*linesize];
- }
-
- //right
- for(x=end_x; x<block_w; x++){
- buf[x + y*linesize]= buf[end_x - 1 + y*linesize];
- }
- }
-}
-
-static inline int hpel_motion(MpegEncContext *s,
- uint8_t *dest, uint8_t *src,
- int field_based, int field_select,
- int src_x, int src_y,
- int width, int height, int stride,
- int h_edge_pos, int v_edge_pos,
- int w, int h, op_pixels_func *pix_op,
- int motion_x, int motion_y)
-{
- int dxy;
- int emu=0;
-
- dxy = ((motion_y & 1) << 1) | (motion_x & 1);
- src_x += motion_x >> 1;
- src_y += motion_y >> 1;
-
- /* WARNING: do no forget half pels */
- src_x = clip(src_x, -16, width); //FIXME unneeded for emu?
- if (src_x == width)
- dxy &= ~1;
- src_y = clip(src_y, -16, height);
- if (src_y == height)
- dxy &= ~2;
- src += src_y * stride + src_x;
-
- if(s->unrestricted_mv && (s->flags&CODEC_FLAG_EMU_EDGE)){
- if( (unsigned)src_x > h_edge_pos - (motion_x&1) - w
- || (unsigned)src_y > v_edge_pos - (motion_y&1) - h){
- ff_emulated_edge_mc(s->edge_emu_buffer, src, s->linesize, w+1, (h+1)<<field_based,
- src_x, src_y<<field_based, h_edge_pos, s->v_edge_pos);
- src= s->edge_emu_buffer;
- emu=1;
- }
- }
- if(field_select)
- src += s->linesize;
- pix_op[dxy](dest, src, stride, h);
- return emu;
-}
-
-static inline int hpel_motion_lowres(MpegEncContext *s,
- uint8_t *dest, uint8_t *src,
- int field_based, int field_select,
- int src_x, int src_y,
- int width, int height, int stride,
- int h_edge_pos, int v_edge_pos,
- int w, int h, h264_chroma_mc_func *pix_op,
- int motion_x, int motion_y)
-{
- const int lowres= s->avctx->lowres;
- const int s_mask= (2<<lowres)-1;
- int emu=0;
- int sx, sy;
-
- if(s->quarter_sample){
- motion_x/=2;
- motion_y/=2;
- }
-
- sx= motion_x & s_mask;
- sy= motion_y & s_mask;
- src_x += motion_x >> (lowres+1);
- src_y += motion_y >> (lowres+1);
-
- src += src_y * stride + src_x;
-
- if( (unsigned)src_x > h_edge_pos - (!!sx) - w
- || (unsigned)src_y >(v_edge_pos >> field_based) - (!!sy) - h){
- ff_emulated_edge_mc(s->edge_emu_buffer, src, s->linesize, w+1, (h+1)<<field_based,
- src_x, src_y<<field_based, h_edge_pos, v_edge_pos);
- src= s->edge_emu_buffer;
- emu=1;
- }
-
- sx <<= 2 - lowres;
- sy <<= 2 - lowres;
- if(field_select)
- src += s->linesize;
- pix_op[lowres](dest, src, stride, h, sx, sy);
- return emu;
-}
-
-/* apply one mpeg motion vector to the three components */
-static av_always_inline 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)
-{
- uint8_t *ptr_y, *ptr_cb, *ptr_cr;
- int dxy, uvdxy, mx, my, src_x, src_y, uvsrc_x, uvsrc_y, v_edge_pos, uvlinesize, linesize;
-
-#if 0
-if(s->quarter_sample)
-{
- motion_x>>=1;
- motion_y>>=1;
-}
-#endif
-
- v_edge_pos = s->v_edge_pos >> field_based;
- linesize = s->current_picture.linesize[0] << field_based;
- uvlinesize = s->current_picture.linesize[1] << field_based;
-
- 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);
-
- if (s->out_format == FMT_H263) {
- if((s->workaround_bugs & FF_BUG_HPEL_CHROMA) && field_based){
- mx = (motion_x>>1)|(motion_x&1);
- 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);
- }else{
- uvdxy = dxy | (motion_y & 2) | ((motion_x & 2) >> 1);
- uvsrc_x = src_x>>1;
- uvsrc_y = src_y>>1;
- }
- }else if(s->out_format == FMT_H261){//even chroma mv's are full pel in H261
- mx = motion_x / 4;
- my = motion_y / 4;
- uvdxy = 0;
- uvsrc_x = s->mb_x*8 + mx;
- uvsrc_y = s->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);
- } else {
- if(s->chroma_x_shift){
- //Chroma422
- mx = motion_x / 2;
- uvdxy = ((motion_y & 1) << 1) | (mx & 1);
- uvsrc_x = s->mb_x* 8 + (mx >> 1);
- uvsrc_y = src_y;
- } else {
- //Chroma444
- uvdxy = dxy;
- uvsrc_x = src_x;
- uvsrc_y = src_y;
- }
- }
- }
-
- ptr_y = ref_picture[0] + src_y * linesize + src_x;
- ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x;
- ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x;
-
- if( (unsigned)src_x > s->h_edge_pos - (motion_x&1) - 16
- || (unsigned)src_y > v_edge_pos - (motion_y&1) - h){
- if(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");
- return ;
- }
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based,
- src_x, src_y<<field_based, s->h_edge_pos, s->v_edge_pos);
- ptr_y = s->edge_emu_buffer;
- if(!(s->flags&CODEC_FLAG_GRAY)){
- uint8_t *uvbuf= s->edge_emu_buffer+18*s->linesize;
- ff_emulated_edge_mc(uvbuf , ptr_cb, s->uvlinesize, 9, 9+field_based,
- uvsrc_x, uvsrc_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1);
- ff_emulated_edge_mc(uvbuf+16, ptr_cr, s->uvlinesize, 9, 9+field_based,
- uvsrc_x, uvsrc_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1);
- ptr_cb= uvbuf;
- ptr_cr= uvbuf+16;
- }
- }
-
- if(bottom_field){ //FIXME use this for field pix too instead of the obnoxious hack which changes picture.data
- dest_y += s->linesize;
- dest_cb+= s->uvlinesize;
- dest_cr+= s->uvlinesize;
- }
-
- if(field_select){
- ptr_y += s->linesize;
- ptr_cb+= s->uvlinesize;
- ptr_cr+= s->uvlinesize;
- }
-
- pix_op[0][dxy](dest_y, ptr_y, linesize, h);
-
- if(!(s->flags&CODEC_FLAG_GRAY)){
- pix_op[s->chroma_x_shift][uvdxy](dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift);
- pix_op[s->chroma_x_shift][uvdxy](dest_cr, ptr_cr, uvlinesize, h >> s->chroma_y_shift);
- }
-#if defined(CONFIG_H261_ENCODER) || defined(CONFIG_H261_DECODER)
- if(s->out_format == FMT_H261){
- ff_h261_loop_filter(s);
- }
-#endif
-}
-
-/* apply one mpeg motion vector to the three components */
-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)
-{
- 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 block_s= 8>>lowres;
- const int s_mask= (2<<lowres)-1;
- const int h_edge_pos = s->h_edge_pos >> lowres;
- const int v_edge_pos = s->v_edge_pos >> lowres;
- linesize = s->current_picture.linesize[0] << field_based;
- uvlinesize = s->current_picture.linesize[1] << field_based;
-
- if(s->quarter_sample){ //FIXME obviously not perfect but qpel wont work in lowres anyway
- motion_x/=2;
- motion_y/=2;
- }
-
- if(field_based){
- motion_y += (bottom_field - field_select)*((1<<lowres)-1);
- }
-
- 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));
-
- if (s->out_format == FMT_H263) {
- uvsx = ((motion_x>>1) & s_mask) | (sx&1);
- uvsy = ((motion_y>>1) & s_mask) | (sy&1);
- uvsrc_x = src_x>>1;
- uvsrc_y = src_y>>1;
- }else if(s->out_format == FMT_H261){//even chroma mv's are full pel in H261
- mx = motion_x / 4;
- my = motion_y / 4;
- 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);
- } 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));
- }
-
- ptr_y = ref_picture[0] + src_y * linesize + src_x;
- ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x;
- ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x;
-
- if( (unsigned)src_x > h_edge_pos - (!!sx) - 2*block_s
- || (unsigned)src_y >(v_edge_pos >> field_based) - (!!sy) - h){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based,
- src_x, src_y<<field_based, h_edge_pos, v_edge_pos);
- ptr_y = s->edge_emu_buffer;
- if(!(s->flags&CODEC_FLAG_GRAY)){
- uint8_t *uvbuf= s->edge_emu_buffer+18*s->linesize;
- ff_emulated_edge_mc(uvbuf , ptr_cb, s->uvlinesize, 9, 9+field_based,
- uvsrc_x, uvsrc_y<<field_based, h_edge_pos>>1, v_edge_pos>>1);
- ff_emulated_edge_mc(uvbuf+16, ptr_cr, s->uvlinesize, 9, 9+field_based,
- uvsrc_x, uvsrc_y<<field_based, h_edge_pos>>1, v_edge_pos>>1);
- ptr_cb= uvbuf;
- ptr_cr= uvbuf+16;
- }
- }
-
- if(bottom_field){ //FIXME use this for field pix too instead of the obnoxious hack which changes picture.data
- dest_y += s->linesize;
- dest_cb+= s->uvlinesize;
- dest_cr+= s->uvlinesize;
- }
-
- if(field_select){
- ptr_y += s->linesize;
- ptr_cb+= s->uvlinesize;
- ptr_cr+= s->uvlinesize;
- }
-
- sx <<= 2 - lowres;
- sy <<= 2 - lowres;
- pix_op[lowres-1](dest_y, ptr_y, linesize, h, sx, sy);
-
- if(!(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);
- }
- //FIXME h261 lowres loop filter
-}
-
-//FIXME move to dsputil, avg variant, 16x16 version
-static inline void put_obmc(uint8_t *dst, uint8_t *src[5], int stride){
- int x;
- uint8_t * const top = src[1];
- uint8_t * const left = src[2];
- uint8_t * const mid = src[0];
- uint8_t * const right = src[3];
- uint8_t * const bottom= src[4];
-#define OBMC_FILTER(x, t, l, m, r, b)\
- dst[x]= (t*top[x] + l*left[x] + m*mid[x] + r*right[x] + b*bottom[x] + 4)>>3
-#define OBMC_FILTER4(x, t, l, m, r, b)\
- OBMC_FILTER(x , t, l, m, r, b);\
- OBMC_FILTER(x+1 , t, l, m, r, b);\
- OBMC_FILTER(x +stride, t, l, m, r, b);\
- OBMC_FILTER(x+1+stride, t, l, m, r, b);
-
- x=0;
- OBMC_FILTER (x , 2, 2, 4, 0, 0);
- OBMC_FILTER (x+1, 2, 1, 5, 0, 0);
- OBMC_FILTER4(x+2, 2, 1, 5, 0, 0);
- OBMC_FILTER4(x+4, 2, 0, 5, 1, 0);
- OBMC_FILTER (x+6, 2, 0, 5, 1, 0);
- OBMC_FILTER (x+7, 2, 0, 4, 2, 0);
- x+= stride;
- OBMC_FILTER (x , 1, 2, 5, 0, 0);
- OBMC_FILTER (x+1, 1, 2, 5, 0, 0);
- OBMC_FILTER (x+6, 1, 0, 5, 2, 0);
- OBMC_FILTER (x+7, 1, 0, 5, 2, 0);
- x+= stride;
- OBMC_FILTER4(x , 1, 2, 5, 0, 0);
- OBMC_FILTER4(x+2, 1, 1, 6, 0, 0);
- OBMC_FILTER4(x+4, 1, 0, 6, 1, 0);
- OBMC_FILTER4(x+6, 1, 0, 5, 2, 0);
- x+= 2*stride;
- OBMC_FILTER4(x , 0, 2, 5, 0, 1);
- OBMC_FILTER4(x+2, 0, 1, 6, 0, 1);
- OBMC_FILTER4(x+4, 0, 0, 6, 1, 1);
- OBMC_FILTER4(x+6, 0, 0, 5, 2, 1);
- x+= 2*stride;
- OBMC_FILTER (x , 0, 2, 5, 0, 1);
- OBMC_FILTER (x+1, 0, 2, 5, 0, 1);
- OBMC_FILTER4(x+2, 0, 1, 5, 0, 2);
- OBMC_FILTER4(x+4, 0, 0, 5, 1, 2);
- OBMC_FILTER (x+6, 0, 0, 5, 2, 1);
- OBMC_FILTER (x+7, 0, 0, 5, 2, 1);
- x+= stride;
- OBMC_FILTER (x , 0, 2, 4, 0, 2);
- OBMC_FILTER (x+1, 0, 1, 5, 0, 2);
- OBMC_FILTER (x+6, 0, 0, 5, 1, 2);
- OBMC_FILTER (x+7, 0, 0, 4, 2, 2);
-}
-
-/* obmc for 1 8x8 luma block */
-static inline void obmc_motion(MpegEncContext *s,
- uint8_t *dest, uint8_t *src,
- int src_x, int src_y,
- op_pixels_func *pix_op,
- int16_t mv[5][2]/* mid top left right bottom*/)
-#define MID 0
-{
- int i;
- uint8_t *ptr[5];
-
- assert(s->quarter_sample==0);
-
- for(i=0; i<5; i++){
- if(i && mv[i][0]==mv[MID][0] && mv[i][1]==mv[MID][1]){
- ptr[i]= ptr[MID];
- }else{
- ptr[i]= s->obmc_scratchpad + 8*(i&1) + s->linesize*8*(i>>1);
- hpel_motion(s, ptr[i], src, 0, 0,
- src_x, src_y,
- s->width, s->height, s->linesize,
- s->h_edge_pos, s->v_edge_pos,
- 8, 8, pix_op,
- mv[i][0], mv[i][1]);
- }
- }
-
- put_obmc(dest, ptr, s->linesize);
-}
-
-static inline void qpel_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],
- qpel_mc_func (*qpix_op)[16],
- int motion_x, int motion_y, int h)
-{
- uint8_t *ptr_y, *ptr_cb, *ptr_cr;
- int dxy, uvdxy, mx, my, src_x, src_y, uvsrc_x, uvsrc_y, v_edge_pos, linesize, uvlinesize;
-
- dxy = ((motion_y & 3) << 2) | (motion_x & 3);
- src_x = s->mb_x * 16 + (motion_x >> 2);
- src_y = s->mb_y * (16 >> field_based) + (motion_y >> 2);
-
- v_edge_pos = s->v_edge_pos >> field_based;
- linesize = s->linesize << field_based;
- uvlinesize = s->uvlinesize << field_based;
-
- if(field_based){
- mx= motion_x/2;
- my= motion_y>>1;
- }else if(s->workaround_bugs&FF_BUG_QPEL_CHROMA2){
- static const int rtab[8]= {0,0,1,1,0,0,0,1};
- mx= (motion_x>>1) + rtab[motion_x&7];
- my= (motion_y>>1) + rtab[motion_y&7];
- }else if(s->workaround_bugs&FF_BUG_QPEL_CHROMA){
- mx= (motion_x>>1)|(motion_x&1);
- my= (motion_y>>1)|(motion_y&1);
- }else{
- mx= motion_x/2;
- my= motion_y/2;
- }
- mx= (mx>>1)|(mx&1);
- my= (my>>1)|(my&1);
-
- uvdxy= (mx&1) | ((my&1)<<1);
- mx>>=1;
- my>>=1;
-
- uvsrc_x = s->mb_x * 8 + mx;
- uvsrc_y = s->mb_y * (8 >> field_based) + my;
-
- ptr_y = ref_picture[0] + src_y * linesize + src_x;
- ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x;
- ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x;
-
- if( (unsigned)src_x > s->h_edge_pos - (motion_x&3) - 16
- || (unsigned)src_y > v_edge_pos - (motion_y&3) - h ){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based,
- src_x, src_y<<field_based, s->h_edge_pos, s->v_edge_pos);
- ptr_y= s->edge_emu_buffer;
- if(!(s->flags&CODEC_FLAG_GRAY)){
- uint8_t *uvbuf= s->edge_emu_buffer + 18*s->linesize;
- ff_emulated_edge_mc(uvbuf, ptr_cb, s->uvlinesize, 9, 9 + field_based,
- uvsrc_x, uvsrc_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1);
- ff_emulated_edge_mc(uvbuf + 16, ptr_cr, s->uvlinesize, 9, 9 + field_based,
- uvsrc_x, uvsrc_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1);
- ptr_cb= uvbuf;
- ptr_cr= uvbuf + 16;
- }
- }
-
- if(!field_based)
- qpix_op[0][dxy](dest_y, ptr_y, linesize);
- else{
- if(bottom_field){
- dest_y += s->linesize;
- dest_cb+= s->uvlinesize;
- dest_cr+= s->uvlinesize;
- }
-
- if(field_select){
- ptr_y += s->linesize;
- ptr_cb += s->uvlinesize;
- ptr_cr += s->uvlinesize;
- }
- //damn interlaced mode
- //FIXME boundary mirroring is not exactly correct here
- qpix_op[1][dxy](dest_y , ptr_y , linesize);
- qpix_op[1][dxy](dest_y+8, ptr_y+8, linesize);
- }
- if(!(s->flags&CODEC_FLAG_GRAY)){
- pix_op[1][uvdxy](dest_cr, ptr_cr, uvlinesize, h >> 1);
- pix_op[1][uvdxy](dest_cb, ptr_cb, uvlinesize, h >> 1);
- }
-}
-
-inline int ff_h263_round_chroma(int x){
- if (x >= 0)
- return (h263_chroma_roundtab[x & 0xf] + ((x >> 3) & ~1));
- else {
- x = -x;
- return -(h263_chroma_roundtab[x & 0xf] + ((x >> 3) & ~1));
- }
-}
-
-/**
- * h263 chorma 4mv motion compensation.
- */
-static inline void chroma_4mv_motion(MpegEncContext *s,
- uint8_t *dest_cb, uint8_t *dest_cr,
- uint8_t **ref_picture,
- op_pixels_func *pix_op,
- int mx, int my){
- int dxy, emu=0, src_x, src_y, offset;
- uint8_t *ptr;
-
- /* In case of 8X8, we construct a single chroma motion vector
- with a special rounding */
- mx= ff_h263_round_chroma(mx);
- my= ff_h263_round_chroma(my);
-
- dxy = ((my & 1) << 1) | (mx & 1);
- mx >>= 1;
- my >>= 1;
-
- src_x = s->mb_x * 8 + mx;
- src_y = s->mb_y * 8 + my;
- src_x = clip(src_x, -8, s->width/2);
- if (src_x == s->width/2)
- dxy &= ~1;
- src_y = clip(src_y, -8, s->height/2);
- if (src_y == s->height/2)
- dxy &= ~2;
-
- offset = (src_y * (s->uvlinesize)) + src_x;
- ptr = ref_picture[1] + offset;
- if(s->flags&CODEC_FLAG_EMU_EDGE){
- if( (unsigned)src_x > (s->h_edge_pos>>1) - (dxy &1) - 8
- || (unsigned)src_y > (s->v_edge_pos>>1) - (dxy>>1) - 8){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
- ptr= s->edge_emu_buffer;
- emu=1;
- }
- }
- pix_op[dxy](dest_cb, ptr, s->uvlinesize, 8);
-
- ptr = ref_picture[2] + offset;
- if(emu){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
- ptr= s->edge_emu_buffer;
- }
- pix_op[dxy](dest_cr, ptr, s->uvlinesize, 8);
-}
-
-static inline void chroma_4mv_motion_lowres(MpegEncContext *s,
- uint8_t *dest_cb, uint8_t *dest_cr,
- uint8_t **ref_picture,
- h264_chroma_mc_func *pix_op,
- int mx, int my){
- const int lowres= s->avctx->lowres;
- const int block_s= 8>>lowres;
- const int s_mask= (2<<lowres)-1;
- const int h_edge_pos = s->h_edge_pos >> (lowres+1);
- const int v_edge_pos = s->v_edge_pos >> (lowres+1);
- int emu=0, src_x, src_y, offset, sx, sy;
- uint8_t *ptr;
-
- if(s->quarter_sample){
- mx/=2;
- my/=2;
- }
-
- /* In case of 8X8, we construct a single chroma motion vector
- with a special rounding */
- mx= ff_h263_round_chroma(mx);
- my= ff_h263_round_chroma(my);
-
- sx= mx & s_mask;
- sy= my & s_mask;
- src_x = s->mb_x*block_s + (mx >> (lowres+1));
- src_y = s->mb_y*block_s + (my >> (lowres+1));
-
- offset = src_y * s->uvlinesize + src_x;
- ptr = ref_picture[1] + offset;
- if(s->flags&CODEC_FLAG_EMU_EDGE){
- if( (unsigned)src_x > h_edge_pos - (!!sx) - block_s
- || (unsigned)src_y > v_edge_pos - (!!sy) - block_s){
- 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;
- emu=1;
- }
- }
- sx <<= 2 - lowres;
- sy <<= 2 - lowres;
- pix_op[lowres](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);
-}
-
-static inline void prefetch_motion(MpegEncContext *s, uint8_t **pix, int dir){
- /* fetch pixels for estimated mv 4 macroblocks ahead
- * optimized for 64byte cache lines */
- const int shift = s->quarter_sample ? 2 : 1;
- const int mx= (s->mv[dir][0][0]>>shift) + 16*s->mb_x + 8;
- const int my= (s->mv[dir][0][1]>>shift) + 16*s->mb_y;
- int off= mx + (my + (s->mb_x&3)*4)*s->linesize + 64;
- s->dsp.prefetch(pix[0]+off, s->linesize, 4);
- off= (mx>>1) + ((my>>1) + (s->mb_x&7))*s->uvlinesize + 64;
- s->dsp.prefetch(pix[1]+off, pix[2]-pix[1], 2);
-}
-
-/**
- * motion compensation of a single macroblock
- * @param s context
- * @param dest_y luma destination pointer
- * @param dest_cb chroma cb/u destination pointer
- * @param dest_cr chroma cr/v destination pointer
- * @param dir direction (0->forward, 1->backward)
- * @param ref_picture array[3] of pointers to the 3 planes of the reference picture
- * @param pic_op halfpel motion compensation function (average or put normally)
- * @param pic_op qpel motion compensation function (average or put normally)
- * the motion vectors are taken from s->mv and the MV type from s->mv_type
- */
-static inline void MPV_motion(MpegEncContext *s,
- uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
- int dir, uint8_t **ref_picture,
- op_pixels_func (*pix_op)[4], qpel_mc_func (*qpix_op)[16])
-{
- int dxy, mx, my, src_x, src_y, motion_x, motion_y;
- int mb_x, mb_y, i;
- uint8_t *ptr, *dest;
-
- mb_x = s->mb_x;
- mb_y = s->mb_y;
-
- prefetch_motion(s, ref_picture, dir);
-
- if(s->obmc && s->pict_type != B_TYPE){
- int16_t mv_cache[4][4][2];
- const int xy= s->mb_x + s->mb_y*s->mb_stride;
- const int mot_stride= s->b8_stride;
- const int mot_xy= mb_x*2 + mb_y*2*mot_stride;
-
- assert(!s->mb_skipped);
-
- memcpy(mv_cache[1][1], s->current_picture.motion_val[0][mot_xy ], sizeof(int16_t)*4);
- memcpy(mv_cache[2][1], s->current_picture.motion_val[0][mot_xy+mot_stride], sizeof(int16_t)*4);
- memcpy(mv_cache[3][1], s->current_picture.motion_val[0][mot_xy+mot_stride], sizeof(int16_t)*4);
-
- if(mb_y==0 || IS_INTRA(s->current_picture.mb_type[xy-s->mb_stride])){
- memcpy(mv_cache[0][1], mv_cache[1][1], sizeof(int16_t)*4);
- }else{
- memcpy(mv_cache[0][1], s->current_picture.motion_val[0][mot_xy-mot_stride], sizeof(int16_t)*4);
- }
-
- if(mb_x==0 || IS_INTRA(s->current_picture.mb_type[xy-1])){
- *(int32_t*)mv_cache[1][0]= *(int32_t*)mv_cache[1][1];
- *(int32_t*)mv_cache[2][0]= *(int32_t*)mv_cache[2][1];
- }else{
- *(int32_t*)mv_cache[1][0]= *(int32_t*)s->current_picture.motion_val[0][mot_xy-1];
- *(int32_t*)mv_cache[2][0]= *(int32_t*)s->current_picture.motion_val[0][mot_xy-1+mot_stride];
- }
-
- if(mb_x+1>=s->mb_width || IS_INTRA(s->current_picture.mb_type[xy+1])){
- *(int32_t*)mv_cache[1][3]= *(int32_t*)mv_cache[1][2];
- *(int32_t*)mv_cache[2][3]= *(int32_t*)mv_cache[2][2];
- }else{
- *(int32_t*)mv_cache[1][3]= *(int32_t*)s->current_picture.motion_val[0][mot_xy+2];
- *(int32_t*)mv_cache[2][3]= *(int32_t*)s->current_picture.motion_val[0][mot_xy+2+mot_stride];
- }
-
- mx = 0;
- my = 0;
- for(i=0;i<4;i++) {
- const int x= (i&1)+1;
- const int y= (i>>1)+1;
- int16_t mv[5][2]= {
- {mv_cache[y][x ][0], mv_cache[y][x ][1]},
- {mv_cache[y-1][x][0], mv_cache[y-1][x][1]},
- {mv_cache[y][x-1][0], mv_cache[y][x-1][1]},
- {mv_cache[y][x+1][0], mv_cache[y][x+1][1]},
- {mv_cache[y+1][x][0], mv_cache[y+1][x][1]}};
- //FIXME cleanup
- obmc_motion(s, dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize,
- ref_picture[0],
- mb_x * 16 + (i & 1) * 8, mb_y * 16 + (i >>1) * 8,
- pix_op[1],
- mv);
-
- mx += mv[0][0];
- my += mv[0][1];
- }
- if(!(s->flags&CODEC_FLAG_GRAY))
- chroma_4mv_motion(s, dest_cb, dest_cr, ref_picture, pix_op[1], mx, my);
-
- return;
- }
-
- switch(s->mv_type) {
- case MV_TYPE_16X16:
- if(s->mcsel){
- if(s->real_sprite_warping_points==1){
- gmc1_motion(s, dest_y, dest_cb, dest_cr,
- ref_picture);
- }else{
- gmc_motion(s, dest_y, dest_cb, dest_cr,
- ref_picture);
- }
- }else if(s->quarter_sample){
- qpel_motion(s, dest_y, dest_cb, dest_cr,
- 0, 0, 0,
- ref_picture, pix_op, qpix_op,
- s->mv[dir][0][0], s->mv[dir][0][1], 16);
- }else if(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);
- }else
- {
- 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);
- }
- break;
- case MV_TYPE_8X8:
- mx = 0;
- my = 0;
- if(s->quarter_sample){
- for(i=0;i<4;i++) {
- motion_x = s->mv[dir][i][0];
- motion_y = s->mv[dir][i][1];
-
- dxy = ((motion_y & 3) << 2) | (motion_x & 3);
- src_x = mb_x * 16 + (motion_x >> 2) + (i & 1) * 8;
- src_y = mb_y * 16 + (motion_y >> 2) + (i >>1) * 8;
-
- /* WARNING: do no forget half pels */
- src_x = clip(src_x, -16, s->width);
- if (src_x == s->width)
- dxy &= ~3;
- src_y = clip(src_y, -16, s->height);
- if (src_y == s->height)
- dxy &= ~12;
-
- ptr = ref_picture[0] + (src_y * s->linesize) + (src_x);
- if(s->flags&CODEC_FLAG_EMU_EDGE){
- if( (unsigned)src_x > s->h_edge_pos - (motion_x&3) - 8
- || (unsigned)src_y > s->v_edge_pos - (motion_y&3) - 8 ){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->linesize, 9, 9, src_x, src_y, s->h_edge_pos, s->v_edge_pos);
- ptr= s->edge_emu_buffer;
- }
- }
- dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize;
- qpix_op[1][dxy](dest, ptr, s->linesize);
-
- mx += s->mv[dir][i][0]/2;
- my += s->mv[dir][i][1]/2;
- }
- }else{
- for(i=0;i<4;i++) {
- hpel_motion(s, dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize,
- ref_picture[0], 0, 0,
- mb_x * 16 + (i & 1) * 8, mb_y * 16 + (i >>1) * 8,
- s->width, s->height, s->linesize,
- s->h_edge_pos, s->v_edge_pos,
- 8, 8, pix_op[1],
- s->mv[dir][i][0], s->mv[dir][i][1]);
-
- mx += s->mv[dir][i][0];
- my += s->mv[dir][i][1];
- }
- }
-
- if(!(s->flags&CODEC_FLAG_GRAY))
- chroma_4mv_motion(s, dest_cb, dest_cr, ref_picture, pix_op[1], mx, my);
- break;
- case MV_TYPE_FIELD:
- if (s->picture_structure == PICT_FRAME) {
- if(s->quarter_sample){
- for(i=0; i<2; i++){
- qpel_motion(s, dest_y, dest_cb, dest_cr,
- 1, i, s->field_select[dir][i],
- ref_picture, pix_op, qpix_op,
- s->mv[dir][i][0], s->mv[dir][i][1], 8);
- }
- }else{
- /* top field */
- 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);
- /* 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);
- }
- } else {
- if(s->picture_structure != s->field_select[dir][0] + 1 && s->pict_type != B_TYPE && !s->first_field){
- ref_picture= s->current_picture_ptr->data;
- }
-
- 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);
- }
- break;
- case MV_TYPE_16X8:
- for(i=0; i<2; i++){
- uint8_t ** ref2picture;
-
- if(s->picture_structure == s->field_select[dir][i] + 1 || s->pict_type == B_TYPE || s->first_field){
- ref2picture= ref_picture;
- }else{
- ref2picture= s->current_picture_ptr->data;
- }
-
- 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);
-
- dest_y += 16*s->linesize;
- dest_cb+= (16>>s->chroma_y_shift)*s->uvlinesize;
- dest_cr+= (16>>s->chroma_y_shift)*s->uvlinesize;
- }
- break;
- case MV_TYPE_DMV:
- if(s->picture_structure == PICT_FRAME){
- for(i=0; i<2; i++){
- int j;
- for(j=0; j<2; j++){
- 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);
- }
- pix_op = s->dsp.avg_pixels_tab;
- }
- }else{
- for(i=0; i<2; i++){
- 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);
-
- // after put we make avg of the same block
- pix_op=s->dsp.avg_pixels_tab;
-
- //opposite parity is always in the same frame if this is second field
- if(!s->first_field){
- ref_picture = s->current_picture_ptr->data;
- }
- }
- }
- break;
- default: assert(0);
- }
-}
-
-/**
- * motion compensation of a single macroblock
- * @param s context
- * @param dest_y luma destination pointer
- * @param dest_cb chroma cb/u destination pointer
- * @param dest_cr chroma cr/v destination pointer
- * @param dir direction (0->forward, 1->backward)
- * @param ref_picture array[3] of pointers to the 3 planes of the reference picture
- * @param pic_op halfpel motion compensation function (average or put normally)
- * the motion vectors are taken from s->mv and the MV type from s->mv_type
- */
-static inline void MPV_motion_lowres(MpegEncContext *s,
- uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
- int dir, uint8_t **ref_picture,
- h264_chroma_mc_func *pix_op)
-{
- int mx, my;
- int mb_x, mb_y, i;
- const int lowres= s->avctx->lowres;
- const int block_s= 8>>lowres;
-
- mb_x = s->mb_x;
- mb_y = s->mb_y;
-
- switch(s->mv_type) {
- case MV_TYPE_16X16:
- 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);
- break;
- case MV_TYPE_8X8:
- mx = 0;
- my = 0;
- for(i=0;i<4;i++) {
- hpel_motion_lowres(s, dest_y + ((i & 1) + (i >> 1) * s->linesize)*block_s,
- ref_picture[0], 0, 0,
- (2*mb_x + (i & 1))*block_s, (2*mb_y + (i >>1))*block_s,
- s->width, s->height, s->linesize,
- s->h_edge_pos >> lowres, s->v_edge_pos >> lowres,
- block_s, block_s, pix_op,
- s->mv[dir][i][0], s->mv[dir][i][1]);
-
- mx += s->mv[dir][i][0];
- my += s->mv[dir][i][1];
- }
-
- if(!(s->flags&CODEC_FLAG_GRAY))
- chroma_4mv_motion_lowres(s, dest_cb, dest_cr, ref_picture, pix_op, mx, my);
- break;
- case MV_TYPE_FIELD:
- if (s->picture_structure == PICT_FRAME) {
- /* top field */
- 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);
- /* 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);
- } else {
- if(s->picture_structure != s->field_select[dir][0] + 1 && s->pict_type != B_TYPE && !s->first_field){
- ref_picture= s->current_picture_ptr->data;
- }
-
- 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);
- }
- break;
- case MV_TYPE_16X8:
- for(i=0; i<2; i++){
- uint8_t ** ref2picture;
-
- if(s->picture_structure == s->field_select[dir][i] + 1 || s->pict_type == B_TYPE || s->first_field){
- ref2picture= ref_picture;
- }else{
- ref2picture= s->current_picture_ptr->data;
- }
-
- 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);
-
- dest_y += 2*block_s*s->linesize;
- dest_cb+= (2*block_s>>s->chroma_y_shift)*s->uvlinesize;
- dest_cr+= (2*block_s>>s->chroma_y_shift)*s->uvlinesize;
- }
- break;
- case MV_TYPE_DMV:
- if(s->picture_structure == PICT_FRAME){
- for(i=0; i<2; i++){
- int j;
- for(j=0; j<2; j++){
- 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);
- }
- pix_op = s->dsp.avg_h264_chroma_pixels_tab;
- }
- }else{
- for(i=0; i<2; i++){
- 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);
-
- // after put we make avg of the same block
- pix_op = s->dsp.avg_h264_chroma_pixels_tab;
-
- //opposite parity is always in the same frame if this is second field
- if(!s->first_field){
- ref_picture = s->current_picture_ptr->data;
- }
- }
- }
- break;
- default: assert(0);
- }
-}
-
-/* put block[] to dest[] */
-static inline void put_dct(MpegEncContext *s,
- DCTELEM *block, int i, uint8_t *dest, int line_size, int qscale)
-{
- s->dct_unquantize_intra(s, block, i, qscale);
- s->dsp.idct_put (dest, line_size, block);
-}
-
-/* add block[] to dest[] */
-static inline void add_dct(MpegEncContext *s,
- DCTELEM *block, int i, uint8_t *dest, int line_size)
-{
- if (s->block_last_index[i] >= 0) {
- s->dsp.idct_add (dest, line_size, block);
- }
-}
-
-static inline void add_dequant_dct(MpegEncContext *s,
- DCTELEM *block, int i, uint8_t *dest, int line_size, int qscale)
-{
- if (s->block_last_index[i] >= 0) {
- s->dct_unquantize_inter(s, block, i, qscale);
-
- s->dsp.idct_add (dest, line_size, block);
- }
-}
-
-/**
- * cleans dc, ac, coded_block for the current non intra MB
- */
-void ff_clean_intra_table_entries(MpegEncContext *s)
-{
- int wrap = s->b8_stride;
- int xy = s->block_index[0];
-
- s->dc_val[0][xy ] =
- s->dc_val[0][xy + 1 ] =
- s->dc_val[0][xy + wrap] =
- s->dc_val[0][xy + 1 + wrap] = 1024;
- /* ac pred */
- memset(s->ac_val[0][xy ], 0, 32 * sizeof(int16_t));
- memset(s->ac_val[0][xy + wrap], 0, 32 * sizeof(int16_t));
- if (s->msmpeg4_version>=3) {
- s->coded_block[xy ] =
- s->coded_block[xy + 1 ] =
- s->coded_block[xy + wrap] =
- s->coded_block[xy + 1 + wrap] = 0;
- }
- /* chroma */
- wrap = s->mb_stride;
- xy = s->mb_x + s->mb_y * wrap;
- s->dc_val[1][xy] =
- s->dc_val[2][xy] = 1024;
- /* ac pred */
- memset(s->ac_val[1][xy], 0, 16 * sizeof(int16_t));
- memset(s->ac_val[2][xy], 0, 16 * sizeof(int16_t));
-
- s->mbintra_table[xy]= 0;
-}
-
-/* generic function called after a macroblock has been parsed by the
- decoder or after it has been encoded by the encoder.
-
- Important variables used:
- s->mb_intra : true if intra macroblock
- s->mv_dir : motion vector direction
- s->mv_type : motion vector type
- s->mv : motion vector
- s->interlaced_dct : true if interlaced dct used (mpeg2)
- */
-static av_always_inline void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64], int lowres_flag)
-{
- int mb_x, mb_y;
- const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
-#ifdef HAVE_XVMC
- if(s->avctx->xvmc_acceleration){
- XVMC_decode_mb(s);//xvmc uses pblocks
- return;
- }
-#endif
-
- mb_x = s->mb_x;
- mb_y = s->mb_y;
-
- if(s->avctx->debug&FF_DEBUG_DCT_COEFF) {
- /* save DCT coefficients */
- int i,j;
- DCTELEM *dct = &s->current_picture.dct_coeff[mb_xy*64*6];
- for(i=0; i<6; i++)
- for(j=0; j<64; j++)
- *dct++ = block[i][s->dsp.idct_permutation[j]];
- }
-
- s->current_picture.qscale_table[mb_xy]= s->qscale;
-
- /* update DC predictors for P macroblocks */
- if (!s->mb_intra) {
- if (s->h263_pred || s->h263_aic) {
- if(s->mbintra_table[mb_xy])
- ff_clean_intra_table_entries(s);
- } else {
- s->last_dc[0] =
- s->last_dc[1] =
- s->last_dc[2] = 128 << s->intra_dc_precision;
- }
- }
- else if (s->h263_pred || s->h263_aic)
- s->mbintra_table[mb_xy]=1;
-
- if ((s->flags&CODEC_FLAG_PSNR) || !(s->encoding && (s->intra_only || s->pict_type==B_TYPE) && s->avctx->mb_decision != FF_MB_DECISION_RD)) { //FIXME precalc
- uint8_t *dest_y, *dest_cb, *dest_cr;
- int dct_linesize, dct_offset;
- op_pixels_func (*op_pix)[4];
- qpel_mc_func (*op_qpix)[16];
- const int linesize= s->current_picture.linesize[0]; //not s->linesize as this would be wrong for field pics
- const int uvlinesize= s->current_picture.linesize[1];
- const int readable= s->pict_type != B_TYPE || s->encoding || s->avctx->draw_horiz_band || lowres_flag;
- const int block_size= lowres_flag ? 8>>s->avctx->lowres : 8;
-
- /* avoid copy if macroblock skipped in last frame too */
- /* skip only during decoding as we might trash the buffers during encoding a bit */
- if(!s->encoding){
- uint8_t *mbskip_ptr = &s->mbskip_table[mb_xy];
- const int age= s->current_picture.age;
-
- assert(age);
-
- if (s->mb_skipped) {
- s->mb_skipped= 0;
- assert(s->pict_type!=I_TYPE);
-
- (*mbskip_ptr) ++; /* indicate that this time we skipped it */
- if(*mbskip_ptr >99) *mbskip_ptr= 99;
-
- /* if previous was skipped too, then nothing to do ! */
- if (*mbskip_ptr >= age && s->current_picture.reference){
- return;
- }
- } else if(!s->current_picture.reference){
- (*mbskip_ptr) ++; /* increase counter so the age can be compared cleanly */
- if(*mbskip_ptr >99) *mbskip_ptr= 99;
- } else{
- *mbskip_ptr = 0; /* not skipped */
- }
- }
-
- dct_linesize = linesize << s->interlaced_dct;
- dct_offset =(s->interlaced_dct)? linesize : linesize*block_size;
-
- if(readable){
- dest_y= s->dest[0];
- dest_cb= s->dest[1];
- dest_cr= s->dest[2];
- }else{
- dest_y = s->b_scratchpad;
- dest_cb= s->b_scratchpad+16*linesize;
- dest_cr= s->b_scratchpad+32*linesize;
- }
-
- if (!s->mb_intra) {
- /* motion handling */
- /* decoding or more than one mb_type (MC was already done otherwise) */
- if(!s->encoding){
- if(lowres_flag){
- h264_chroma_mc_func *op_pix = s->dsp.put_h264_chroma_pixels_tab;
-
- if (s->mv_dir & MV_DIR_FORWARD) {
- MPV_motion_lowres(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.data, op_pix);
- op_pix = s->dsp.avg_h264_chroma_pixels_tab;
- }
- if (s->mv_dir & MV_DIR_BACKWARD) {
- MPV_motion_lowres(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.data, op_pix);
- }
- }else{
- op_qpix= s->me.qpel_put;
- if ((!s->no_rounding) || s->pict_type==B_TYPE){
- op_pix = s->dsp.put_pixels_tab;
- }else{
- op_pix = s->dsp.put_no_rnd_pixels_tab;
- }
- if (s->mv_dir & MV_DIR_FORWARD) {
- MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.data, op_pix, op_qpix);
- op_pix = s->dsp.avg_pixels_tab;
- op_qpix= s->me.qpel_avg;
- }
- if (s->mv_dir & MV_DIR_BACKWARD) {
- MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.data, op_pix, op_qpix);
- }
- }
- }
-
- /* skip dequant / idct if we are really late ;) */
- if(s->hurry_up>1) goto skip_idct;
- if(s->avctx->skip_idct){
- if( (s->avctx->skip_idct >= AVDISCARD_NONREF && s->pict_type == B_TYPE)
- ||(s->avctx->skip_idct >= AVDISCARD_NONKEY && s->pict_type != I_TYPE)
- || s->avctx->skip_idct >= AVDISCARD_ALL)
- goto skip_idct;
- }
-
- /* add dct residue */
- if(s->encoding || !( s->h263_msmpeg4 || s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO
- || (s->codec_id==CODEC_ID_MPEG4 && !s->mpeg_quant))){
- add_dequant_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale);
- add_dequant_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale);
- add_dequant_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale);
- add_dequant_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale);
-
- if(!(s->flags&CODEC_FLAG_GRAY)){
- if (s->chroma_y_shift){
- add_dequant_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale);
- add_dequant_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale);
- }else{
- dct_linesize >>= 1;
- dct_offset >>=1;
- add_dequant_dct(s, block[4], 4, dest_cb, dct_linesize, s->chroma_qscale);
- add_dequant_dct(s, block[5], 5, dest_cr, dct_linesize, s->chroma_qscale);
- add_dequant_dct(s, block[6], 6, dest_cb + dct_offset, dct_linesize, s->chroma_qscale);
- add_dequant_dct(s, block[7], 7, dest_cr + dct_offset, dct_linesize, s->chroma_qscale);
- }
- }
- } else if(s->codec_id != CODEC_ID_WMV2){
- add_dct(s, block[0], 0, dest_y , dct_linesize);
- add_dct(s, block[1], 1, dest_y + block_size, dct_linesize);
- add_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize);
- add_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize);
-
- if(!(s->flags&CODEC_FLAG_GRAY)){
- if(s->chroma_y_shift){//Chroma420
- add_dct(s, block[4], 4, dest_cb, uvlinesize);
- add_dct(s, block[5], 5, dest_cr, uvlinesize);
- }else{
- //chroma422
- dct_linesize = uvlinesize << s->interlaced_dct;
- dct_offset =(s->interlaced_dct)? uvlinesize : uvlinesize*8;
-
- add_dct(s, block[4], 4, dest_cb, dct_linesize);
- add_dct(s, block[5], 5, dest_cr, dct_linesize);
- add_dct(s, block[6], 6, dest_cb+dct_offset, dct_linesize);
- add_dct(s, block[7], 7, dest_cr+dct_offset, dct_linesize);
- if(!s->chroma_x_shift){//Chroma444
- add_dct(s, block[8], 8, dest_cb+8, dct_linesize);
- add_dct(s, block[9], 9, dest_cr+8, dct_linesize);
- add_dct(s, block[10], 10, dest_cb+8+dct_offset, dct_linesize);
- add_dct(s, block[11], 11, dest_cr+8+dct_offset, dct_linesize);
- }
- }
- }//fi gray
- }
- else{
- ff_wmv2_add_mb(s, block, dest_y, dest_cb, dest_cr);
- }
- } else {
- /* dct only in intra block */
- if(s->encoding || !(s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO)){
- put_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale);
- put_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale);
- put_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale);
- put_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale);
-
- if(!(s->flags&CODEC_FLAG_GRAY)){
- if(s->chroma_y_shift){
- put_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale);
- put_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale);
- }else{
- dct_offset >>=1;
- dct_linesize >>=1;
- put_dct(s, block[4], 4, dest_cb, dct_linesize, s->chroma_qscale);
- put_dct(s, block[5], 5, dest_cr, dct_linesize, s->chroma_qscale);
- put_dct(s, block[6], 6, dest_cb + dct_offset, dct_linesize, s->chroma_qscale);
- put_dct(s, block[7], 7, dest_cr + dct_offset, dct_linesize, s->chroma_qscale);
- }
- }
- }else{
- s->dsp.idct_put(dest_y , dct_linesize, block[0]);
- s->dsp.idct_put(dest_y + block_size, dct_linesize, block[1]);
- s->dsp.idct_put(dest_y + dct_offset , dct_linesize, block[2]);
- s->dsp.idct_put(dest_y + dct_offset + block_size, dct_linesize, block[3]);
-
- if(!(s->flags&CODEC_FLAG_GRAY)){
- if(s->chroma_y_shift){
- s->dsp.idct_put(dest_cb, uvlinesize, block[4]);
- s->dsp.idct_put(dest_cr, uvlinesize, block[5]);
- }else{
-
- dct_linesize = uvlinesize << s->interlaced_dct;
- dct_offset =(s->interlaced_dct)? uvlinesize : uvlinesize*8;
-
- s->dsp.idct_put(dest_cb, dct_linesize, block[4]);
- s->dsp.idct_put(dest_cr, dct_linesize, block[5]);
- s->dsp.idct_put(dest_cb + dct_offset, dct_linesize, block[6]);
- s->dsp.idct_put(dest_cr + dct_offset, dct_linesize, block[7]);
- if(!s->chroma_x_shift){//Chroma444
- s->dsp.idct_put(dest_cb + 8, dct_linesize, block[8]);
- s->dsp.idct_put(dest_cr + 8, dct_linesize, block[9]);
- s->dsp.idct_put(dest_cb + 8 + dct_offset, dct_linesize, block[10]);
- s->dsp.idct_put(dest_cr + 8 + dct_offset, dct_linesize, block[11]);
- }
- }
- }//gray
- }
- }
-skip_idct:
- if(!readable){
- s->dsp.put_pixels_tab[0][0](s->dest[0], dest_y , linesize,16);
- s->dsp.put_pixels_tab[s->chroma_x_shift][0](s->dest[1], dest_cb, uvlinesize,16 >> s->chroma_y_shift);
- s->dsp.put_pixels_tab[s->chroma_x_shift][0](s->dest[2], dest_cr, uvlinesize,16 >> s->chroma_y_shift);
- }
- }
-}
-
-void MPV_decode_mb(MpegEncContext *s, DCTELEM block[12][64]){
- if(s->avctx->lowres) MPV_decode_mb_internal(s, block, 1);
- else MPV_decode_mb_internal(s, block, 0);
-}
-
-#ifdef CONFIG_ENCODERS
-
-static inline void dct_single_coeff_elimination(MpegEncContext *s, int n, int threshold)
-{
- static const char tab[64]=
- {3,2,2,1,1,1,1,1,
- 1,1,1,1,1,1,1,1,
- 1,1,1,1,1,1,1,1,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0};
- int score=0;
- int run=0;
- int i;
- DCTELEM *block= s->block[n];
- const int last_index= s->block_last_index[n];
- int skip_dc;
-
- if(threshold<0){
- skip_dc=0;
- threshold= -threshold;
- }else
- skip_dc=1;
-
- /* are all which we could set to zero are allready zero? */
- if(last_index<=skip_dc - 1) return;
-
- for(i=0; i<=last_index; i++){
- const int j = s->intra_scantable.permutated[i];
- const int level = FFABS(block[j]);
- if(level==1){
- if(skip_dc && i==0) continue;
- score+= tab[run];
- run=0;
- }else if(level>1){
- return;
- }else{
- run++;
- }
- }
- if(score >= threshold) return;
- for(i=skip_dc; i<=last_index; i++){
- const int j = s->intra_scantable.permutated[i];
- block[j]=0;
- }
- if(block[0]) s->block_last_index[n]= 0;
- else s->block_last_index[n]= -1;
-}
-
-static inline void clip_coeffs(MpegEncContext *s, DCTELEM *block, int last_index)
-{
- int i;
- const int maxlevel= s->max_qcoeff;
- const int minlevel= s->min_qcoeff;
- int overflow=0;
-
- if(s->mb_intra){
- i=1; //skip clipping of intra dc
- }else
- i=0;
-
- for(;i<=last_index; i++){
- const int j= s->intra_scantable.permutated[i];
- int level = block[j];
-
- if (level>maxlevel){
- level=maxlevel;
- overflow++;
- }else if(level<minlevel){
- level=minlevel;
- overflow++;
- }
-
- block[j]= level;
- }
-
- if(overflow && s->avctx->mb_decision == FF_MB_DECISION_SIMPLE)
- av_log(s->avctx, AV_LOG_INFO, "warning, clipping %d dct coefficients to %d..%d\n", overflow, minlevel, maxlevel);
-}
-
-#endif //CONFIG_ENCODERS
-
-/**
- *
- * @param h is the normal height, this will be reduced automatically if needed for the last row
- */
-void ff_draw_horiz_band(MpegEncContext *s, int y, int h){
- if (s->avctx->draw_horiz_band) {
- AVFrame *src;
- int offset[4];
-
- if(s->picture_structure != PICT_FRAME){
- h <<= 1;
- y <<= 1;
- if(s->first_field && !(s->avctx->slice_flags&SLICE_FLAG_ALLOW_FIELD)) return;
- }
-
- h= FFMIN(h, s->avctx->height - y);
-
- if(s->pict_type==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)
- src= (AVFrame*)s->last_picture_ptr;
- else
- return;
-
- if(s->pict_type==B_TYPE && s->picture_structure == PICT_FRAME && s->out_format != FMT_H264){
- offset[0]=
- offset[1]=
- offset[2]=
- offset[3]= 0;
- }else{
- offset[0]= y * s->linesize;;
- offset[1]=
- offset[2]= (y >> s->chroma_y_shift) * s->uvlinesize;
- offset[3]= 0;
- }
-
- emms_c();
-
- s->avctx->draw_horiz_band(s->avctx, src, offset,
- y, s->picture_structure, h);
- }
-}
-
-void ff_init_block_index(MpegEncContext *s){ //FIXME maybe rename
- const int linesize= s->current_picture.linesize[0]; //not s->linesize as this would be wrong for field pics
- const int uvlinesize= s->current_picture.linesize[1];
- const int mb_size= 4 - s->avctx->lowres;
-
- s->block_index[0]= s->b8_stride*(s->mb_y*2 ) - 2 + s->mb_x*2;
- s->block_index[1]= s->b8_stride*(s->mb_y*2 ) - 1 + s->mb_x*2;
- s->block_index[2]= s->b8_stride*(s->mb_y*2 + 1) - 2 + s->mb_x*2;
- s->block_index[3]= s->b8_stride*(s->mb_y*2 + 1) - 1 + s->mb_x*2;
- s->block_index[4]= s->mb_stride*(s->mb_y + 1) + s->b8_stride*s->mb_height*2 + s->mb_x - 1;
- s->block_index[5]= s->mb_stride*(s->mb_y + s->mb_height + 2) + s->b8_stride*s->mb_height*2 + s->mb_x - 1;
- //block_index is not used by mpeg2, so it is not affected by chroma_format
-
- s->dest[0] = s->current_picture.data[0] + ((s->mb_x - 1) << mb_size);
- s->dest[1] = s->current_picture.data[1] + ((s->mb_x - 1) << (mb_size - s->chroma_x_shift));
- s->dest[2] = s->current_picture.data[2] + ((s->mb_x - 1) << (mb_size - s->chroma_x_shift));
-
- if(!(s->pict_type==B_TYPE && s->avctx->draw_horiz_band && 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);
- }
-}
-
-#ifdef CONFIG_ENCODERS
-
-static void get_vissual_weight(int16_t *weight, uint8_t *ptr, int stride){
- int x, y;
-//FIXME optimize
- for(y=0; y<8; y++){
- for(x=0; x<8; x++){
- int x2, y2;
- int sum=0;
- int sqr=0;
- int count=0;
-
- for(y2= FFMAX(y-1, 0); y2 < FFMIN(8, y+2); y2++){
- for(x2= FFMAX(x-1, 0); x2 < FFMIN(8, x+2); x2++){
- int v= ptr[x2 + y2*stride];
- sum += v;
- sqr += v*v;
- count++;
- }
- }
- weight[x + 8*y]= (36*ff_sqrt(count*sqr - sum*sum)) / count;
- }
- }
-}
-
-static av_always_inline void encode_mb_internal(MpegEncContext *s, int motion_x, int motion_y, int mb_block_height, int mb_block_count)
-{
- int16_t weight[8][64];
- DCTELEM orig[8][64];
- const int mb_x= s->mb_x;
- const int mb_y= s->mb_y;
- int i;
- int skip_dct[8];
- int dct_offset = s->linesize*8; //default for progressive frames
- uint8_t *ptr_y, *ptr_cb, *ptr_cr;
- int wrap_y, wrap_c;
-
- for(i=0; i<mb_block_count; i++) skip_dct[i]=s->skipdct;
-
- if(s->adaptive_quant){
- const int last_qp= s->qscale;
- const int mb_xy= mb_x + mb_y*s->mb_stride;
-
- s->lambda= s->lambda_table[mb_xy];
- update_qscale(s);
-
- if(!(s->flags&CODEC_FLAG_QP_RD)){
- s->qscale= s->current_picture_ptr->qscale_table[mb_xy];
- s->dquant= s->qscale - last_qp;
-
- if(s->out_format==FMT_H263){
- s->dquant= clip(s->dquant, -2, 2);
-
- if(s->codec_id==CODEC_ID_MPEG4){
- if(!s->mb_intra){
- if(s->pict_type == B_TYPE){
- if(s->dquant&1 || s->mv_dir&MV_DIRECT)
- s->dquant= 0;
- }
- if(s->mv_type==MV_TYPE_8X8)
- s->dquant=0;
- }
- }
- }
- }
- ff_set_qscale(s, last_qp + s->dquant);
- }else if(s->flags&CODEC_FLAG_QP_RD)
- ff_set_qscale(s, s->qscale + s->dquant);
-
- wrap_y = s->linesize;
- wrap_c = s->uvlinesize;
- ptr_y = s->new_picture.data[0] + (mb_y * 16 * wrap_y) + mb_x * 16;
- ptr_cb = s->new_picture.data[1] + (mb_y * mb_block_height * wrap_c) + mb_x * 8;
- ptr_cr = s->new_picture.data[2] + (mb_y * mb_block_height * wrap_c) + mb_x * 8;
-
- if(mb_x*16+16 > s->width || mb_y*16+16 > s->height){
- uint8_t *ebuf= s->edge_emu_buffer + 32;
- ff_emulated_edge_mc(ebuf , ptr_y , wrap_y,16,16,mb_x*16,mb_y*16, s->width , s->height);
- ptr_y= ebuf;
- ff_emulated_edge_mc(ebuf+18*wrap_y , ptr_cb, wrap_c, 8, mb_block_height, mb_x*8, mb_y*8, s->width>>1, s->height>>1);
- ptr_cb= ebuf+18*wrap_y;
- ff_emulated_edge_mc(ebuf+18*wrap_y+8, ptr_cr, wrap_c, 8, mb_block_height, mb_x*8, mb_y*8, s->width>>1, s->height>>1);
- ptr_cr= ebuf+18*wrap_y+8;
- }
-
- if (s->mb_intra) {
- if(s->flags&CODEC_FLAG_INTERLACED_DCT){
- int progressive_score, interlaced_score;
-
- s->interlaced_dct=0;
- progressive_score= s->dsp.ildct_cmp[4](s, ptr_y , NULL, wrap_y, 8)
- +s->dsp.ildct_cmp[4](s, ptr_y + wrap_y*8, NULL, wrap_y, 8) - 400;
-
- if(progressive_score > 0){
- interlaced_score = s->dsp.ildct_cmp[4](s, ptr_y , NULL, wrap_y*2, 8)
- +s->dsp.ildct_cmp[4](s, ptr_y + wrap_y , NULL, wrap_y*2, 8);
- if(progressive_score > interlaced_score){
- s->interlaced_dct=1;
-
- dct_offset= wrap_y;
- wrap_y<<=1;
- if (s->chroma_format == CHROMA_422)
- wrap_c<<=1;
- }
- }
- }
-
- s->dsp.get_pixels(s->block[0], ptr_y , wrap_y);
- s->dsp.get_pixels(s->block[1], ptr_y + 8, wrap_y);
- s->dsp.get_pixels(s->block[2], ptr_y + dct_offset , wrap_y);
- s->dsp.get_pixels(s->block[3], ptr_y + dct_offset + 8, wrap_y);
-
- if(s->flags&CODEC_FLAG_GRAY){
- skip_dct[4]= 1;
- skip_dct[5]= 1;
- }else{
- s->dsp.get_pixels(s->block[4], ptr_cb, wrap_c);
- s->dsp.get_pixels(s->block[5], ptr_cr, wrap_c);
- if(!s->chroma_y_shift){ /* 422 */
- s->dsp.get_pixels(s->block[6], ptr_cb + (dct_offset>>1), wrap_c);
- s->dsp.get_pixels(s->block[7], ptr_cr + (dct_offset>>1), wrap_c);
- }
- }
- }else{
- op_pixels_func (*op_pix)[4];
- qpel_mc_func (*op_qpix)[16];
- uint8_t *dest_y, *dest_cb, *dest_cr;
-
- dest_y = s->dest[0];
- dest_cb = s->dest[1];
- dest_cr = s->dest[2];
-
- if ((!s->no_rounding) || s->pict_type==B_TYPE){
- op_pix = s->dsp.put_pixels_tab;
- op_qpix= s->dsp.put_qpel_pixels_tab;
- }else{
- op_pix = s->dsp.put_no_rnd_pixels_tab;
- op_qpix= s->dsp.put_no_rnd_qpel_pixels_tab;
- }
-
- if (s->mv_dir & MV_DIR_FORWARD) {
- MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.data, op_pix, op_qpix);
- op_pix = s->dsp.avg_pixels_tab;
- op_qpix= s->dsp.avg_qpel_pixels_tab;
- }
- if (s->mv_dir & MV_DIR_BACKWARD) {
- MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.data, op_pix, op_qpix);
- }
-
- if(s->flags&CODEC_FLAG_INTERLACED_DCT){
- int progressive_score, interlaced_score;
-
- s->interlaced_dct=0;
- progressive_score= s->dsp.ildct_cmp[0](s, dest_y , ptr_y , wrap_y, 8)
- +s->dsp.ildct_cmp[0](s, dest_y + wrap_y*8, ptr_y + wrap_y*8, wrap_y, 8) - 400;
-
- if(s->avctx->ildct_cmp == FF_CMP_VSSE) progressive_score -= 400;
-
- if(progressive_score>0){
- interlaced_score = s->dsp.ildct_cmp[0](s, dest_y , ptr_y , wrap_y*2, 8)
- +s->dsp.ildct_cmp[0](s, dest_y + wrap_y , ptr_y + wrap_y , wrap_y*2, 8);
-
- if(progressive_score > interlaced_score){
- s->interlaced_dct=1;
-
- dct_offset= wrap_y;
- wrap_y<<=1;
- if (s->chroma_format == CHROMA_422)
- wrap_c<<=1;
- }
- }
- }
-
- s->dsp.diff_pixels(s->block[0], ptr_y , dest_y , wrap_y);
- s->dsp.diff_pixels(s->block[1], ptr_y + 8, dest_y + 8, wrap_y);
- s->dsp.diff_pixels(s->block[2], ptr_y + dct_offset , dest_y + dct_offset , wrap_y);
- s->dsp.diff_pixels(s->block[3], ptr_y + dct_offset + 8, dest_y + dct_offset + 8, wrap_y);
-
- if(s->flags&CODEC_FLAG_GRAY){
- skip_dct[4]= 1;
- skip_dct[5]= 1;
- }else{
- s->dsp.diff_pixels(s->block[4], ptr_cb, dest_cb, wrap_c);
- s->dsp.diff_pixels(s->block[5], ptr_cr, dest_cr, wrap_c);
- if(!s->chroma_y_shift){ /* 422 */
- s->dsp.diff_pixels(s->block[6], ptr_cb + (dct_offset>>1), dest_cb + (dct_offset>>1), wrap_c);
- s->dsp.diff_pixels(s->block[7], ptr_cr + (dct_offset>>1), dest_cr + (dct_offset>>1), wrap_c);
- }
- }
- /* pre quantization */
- if(s->current_picture.mc_mb_var[s->mb_stride*mb_y+ mb_x]<2*s->qscale*s->qscale){
- //FIXME optimize
- if(s->dsp.sad[1](NULL, ptr_y , dest_y , wrap_y, 8) < 20*s->qscale) skip_dct[0]= 1;
- if(s->dsp.sad[1](NULL, ptr_y + 8, dest_y + 8, wrap_y, 8) < 20*s->qscale) skip_dct[1]= 1;
- if(s->dsp.sad[1](NULL, ptr_y +dct_offset , dest_y +dct_offset , wrap_y, 8) < 20*s->qscale) skip_dct[2]= 1;
- if(s->dsp.sad[1](NULL, ptr_y +dct_offset+ 8, dest_y +dct_offset+ 8, wrap_y, 8) < 20*s->qscale) skip_dct[3]= 1;
- if(s->dsp.sad[1](NULL, ptr_cb , dest_cb , wrap_c, 8) < 20*s->qscale) skip_dct[4]= 1;
- if(s->dsp.sad[1](NULL, ptr_cr , dest_cr , wrap_c, 8) < 20*s->qscale) skip_dct[5]= 1;
- if(!s->chroma_y_shift){ /* 422 */
- if(s->dsp.sad[1](NULL, ptr_cb +(dct_offset>>1), dest_cb +(dct_offset>>1), wrap_c, 8) < 20*s->qscale) skip_dct[6]= 1;
- if(s->dsp.sad[1](NULL, ptr_cr +(dct_offset>>1), dest_cr +(dct_offset>>1), wrap_c, 8) < 20*s->qscale) skip_dct[7]= 1;
- }
- }
- }
-
- if(s->avctx->quantizer_noise_shaping){
- if(!skip_dct[0]) get_vissual_weight(weight[0], ptr_y , wrap_y);
- if(!skip_dct[1]) get_vissual_weight(weight[1], ptr_y + 8, wrap_y);
- if(!skip_dct[2]) get_vissual_weight(weight[2], ptr_y + dct_offset , wrap_y);
- if(!skip_dct[3]) get_vissual_weight(weight[3], ptr_y + dct_offset + 8, wrap_y);
- if(!skip_dct[4]) get_vissual_weight(weight[4], ptr_cb , wrap_c);
- if(!skip_dct[5]) get_vissual_weight(weight[5], ptr_cr , wrap_c);
- if(!s->chroma_y_shift){ /* 422 */
- if(!skip_dct[6]) get_vissual_weight(weight[6], ptr_cb + (dct_offset>>1), wrap_c);
- if(!skip_dct[7]) get_vissual_weight(weight[7], ptr_cr + (dct_offset>>1), wrap_c);
- }
- memcpy(orig[0], s->block[0], sizeof(DCTELEM)*64*mb_block_count);
- }
-
- /* DCT & quantize */
- assert(s->out_format!=FMT_MJPEG || s->qscale==8);
- {
- for(i=0;i<mb_block_count;i++) {
- if(!skip_dct[i]){
- int overflow;
- s->block_last_index[i] = s->dct_quantize(s, s->block[i], i, s->qscale, &overflow);
- // FIXME we could decide to change to quantizer instead of clipping
- // JS: I don't think that would be a good idea it could lower quality instead
- // of improve it. Just INTRADC clipping deserves changes in quantizer
- if (overflow) clip_coeffs(s, s->block[i], s->block_last_index[i]);
- }else
- s->block_last_index[i]= -1;
- }
- if(s->avctx->quantizer_noise_shaping){
- for(i=0;i<mb_block_count;i++) {
- if(!skip_dct[i]){
- s->block_last_index[i] = dct_quantize_refine(s, s->block[i], weight[i], orig[i], i, s->qscale);
- }
- }
- }
-
- if(s->luma_elim_threshold && !s->mb_intra)
- for(i=0; i<4; i++)
- dct_single_coeff_elimination(s, i, s->luma_elim_threshold);
- if(s->chroma_elim_threshold && !s->mb_intra)
- for(i=4; i<mb_block_count; i++)
- dct_single_coeff_elimination(s, i, s->chroma_elim_threshold);
-
- if(s->flags & CODEC_FLAG_CBP_RD){
- for(i=0;i<mb_block_count;i++) {
- if(s->block_last_index[i] == -1)
- s->coded_score[i]= INT_MAX/256;
- }
- }
- }
-
- if((s->flags&CODEC_FLAG_GRAY) && s->mb_intra){
- s->block_last_index[4]=
- s->block_last_index[5]= 0;
- s->block[4][0]=
- s->block[5][0]= (1024 + s->c_dc_scale/2)/ s->c_dc_scale;
- }
-
- //non c quantize code returns incorrect block_last_index FIXME
- if(s->alternate_scan && s->dct_quantize != dct_quantize_c){
- for(i=0; i<mb_block_count; i++){
- int j;
- if(s->block_last_index[i]>0){
- for(j=63; j>0; j--){
- if(s->block[i][ s->intra_scantable.permutated[j] ]) break;
- }
- s->block_last_index[i]= j;
- }
- }
- }
-
- /* huffman encode */
- switch(s->codec_id){ //FIXME funct ptr could be slightly faster
- case CODEC_ID_MPEG1VIDEO:
- case CODEC_ID_MPEG2VIDEO:
- mpeg1_encode_mb(s, s->block, motion_x, motion_y); break;
-/* xine: do not need this for decode or MPEG-1 encoding modes */
-#if 0
- case CODEC_ID_MPEG4:
- mpeg4_encode_mb(s, s->block, motion_x, motion_y); break;
- case CODEC_ID_MSMPEG4V2:
- case CODEC_ID_MSMPEG4V3:
- case CODEC_ID_WMV1:
- msmpeg4_encode_mb(s, s->block, motion_x, motion_y); break;
- case CODEC_ID_WMV2:
- ff_wmv2_encode_mb(s, s->block, motion_x, motion_y); break;
-#ifdef CONFIG_H261_ENCODER
- case CODEC_ID_H261:
- ff_h261_encode_mb(s, s->block, motion_x, motion_y); break;
-#endif
- case CODEC_ID_H263:
- case CODEC_ID_H263P:
- case CODEC_ID_FLV1:
- case CODEC_ID_RV10:
- case CODEC_ID_RV20:
- h263_encode_mb(s, s->block, motion_x, motion_y); break;
- case CODEC_ID_MJPEG:
- mjpeg_encode_mb(s, s->block); break;
-#endif /* #if 0 */
- default:
- assert(0);
- }
-}
-
-static av_always_inline void encode_mb(MpegEncContext *s, int motion_x, int motion_y)
-{
- if (s->chroma_format == CHROMA_420) encode_mb_internal(s, motion_x, motion_y, 8, 6);
- else encode_mb_internal(s, motion_x, motion_y, 16, 8);
-}
-
-#endif //CONFIG_ENCODERS
-
-void ff_mpeg_flush(AVCodecContext *avctx){
- int i;
- MpegEncContext *s = avctx->priv_data;
-
- if(s==NULL || s->picture==NULL)
- return;
-
- for(i=0; i<MAX_PICTURE_COUNT; i++){
- if(s->picture[i].data[0] && ( s->picture[i].type == FF_BUFFER_TYPE_INTERNAL
- || s->picture[i].type == FF_BUFFER_TYPE_USER))
- avctx->release_buffer(avctx, (AVFrame*)&s->picture[i]);
- }
- s->current_picture_ptr = s->last_picture_ptr = s->next_picture_ptr = NULL;
-
- s->mb_x= s->mb_y= 0;
-
- s->parse_context.state= -1;
- s->parse_context.frame_start_found= 0;
- s->parse_context.overread= 0;
- s->parse_context.overread_index= 0;
- s->parse_context.index= 0;
- s->parse_context.last_index= 0;
- s->bitstream_buffer_size=0;
- s->pp_time=0;
-}
-
-#ifdef CONFIG_ENCODERS
-void ff_copy_bits(PutBitContext *pb, uint8_t *src, int length)
-{
- const uint16_t *srcw= (uint16_t*)src;
- int words= length>>4;
- int bits= length&15;
- int i;
-
- if(length==0) return;
-
- if(words < 16){
- for(i=0; i<words; i++) put_bits(pb, 16, be2me_16(srcw[i]));
- }else if(put_bits_count(pb)&7){
- for(i=0; i<words; i++) put_bits(pb, 16, be2me_16(srcw[i]));
- }else{
- for(i=0; put_bits_count(pb)&31; i++)
- put_bits(pb, 8, src[i]);
- flush_put_bits(pb);
- memcpy(pbBufPtr(pb), src+i, 2*words-i);
- skip_put_bytes(pb, 2*words-i);
- }
-
- put_bits(pb, bits, be2me_16(srcw[words])>>(16-bits));
-}
-
-static inline void copy_context_before_encode(MpegEncContext *d, MpegEncContext *s, int type){
- int i;
-
- memcpy(d->last_mv, s->last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster then a loop?
-
- /* mpeg1 */
- d->mb_skip_run= s->mb_skip_run;
- for(i=0; i<3; i++)
- d->last_dc[i]= s->last_dc[i];
-
- /* statistics */
- d->mv_bits= s->mv_bits;
- d->i_tex_bits= s->i_tex_bits;
- d->p_tex_bits= s->p_tex_bits;
- d->i_count= s->i_count;
- d->f_count= s->f_count;
- d->b_count= s->b_count;
- d->skip_count= s->skip_count;
- d->misc_bits= s->misc_bits;
- d->last_bits= 0;
-
- d->mb_skipped= 0;
- d->qscale= s->qscale;
- d->dquant= s->dquant;
-}
-
-static inline void copy_context_after_encode(MpegEncContext *d, MpegEncContext *s, int type){
- int i;
-
- memcpy(d->mv, s->mv, 2*4*2*sizeof(int));
- memcpy(d->last_mv, s->last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster then a loop?
-
- /* mpeg1 */
- d->mb_skip_run= s->mb_skip_run;
- for(i=0; i<3; i++)
- d->last_dc[i]= s->last_dc[i];
-
- /* statistics */
- d->mv_bits= s->mv_bits;
- d->i_tex_bits= s->i_tex_bits;
- d->p_tex_bits= s->p_tex_bits;
- d->i_count= s->i_count;
- d->f_count= s->f_count;
- d->b_count= s->b_count;
- d->skip_count= s->skip_count;
- d->misc_bits= s->misc_bits;
-
- d->mb_intra= s->mb_intra;
- d->mb_skipped= s->mb_skipped;
- d->mv_type= s->mv_type;
- d->mv_dir= s->mv_dir;
- d->pb= s->pb;
- if(s->data_partitioning){
- d->pb2= s->pb2;
- d->tex_pb= s->tex_pb;
- }
- d->block= s->block;
- for(i=0; i<8; i++)
- d->block_last_index[i]= s->block_last_index[i];
- d->interlaced_dct= s->interlaced_dct;
- d->qscale= s->qscale;
-}
-
-static inline void encode_mb_hq(MpegEncContext *s, MpegEncContext *backup, MpegEncContext *best, int type,
- PutBitContext pb[2], PutBitContext pb2[2], PutBitContext tex_pb[2],
- int *dmin, int *next_block, int motion_x, int motion_y)
-{
- int score;
- uint8_t *dest_backup[3];
-
- copy_context_before_encode(s, backup, type);
-
- s->block= s->blocks[*next_block];
- s->pb= pb[*next_block];
- if(s->data_partitioning){
- s->pb2 = pb2 [*next_block];
- s->tex_pb= tex_pb[*next_block];
- }
-
- if(*next_block){
- memcpy(dest_backup, s->dest, sizeof(s->dest));
- s->dest[0] = s->rd_scratchpad;
- s->dest[1] = s->rd_scratchpad + 16*s->linesize;
- s->dest[2] = s->rd_scratchpad + 16*s->linesize + 8;
- assert(s->linesize >= 32); //FIXME
- }
-
- encode_mb(s, motion_x, motion_y);
-
- score= put_bits_count(&s->pb);
- if(s->data_partitioning){
- score+= put_bits_count(&s->pb2);
- score+= put_bits_count(&s->tex_pb);
- }
-
- if(s->avctx->mb_decision == FF_MB_DECISION_RD){
- MPV_decode_mb(s, s->block);
-
- score *= s->lambda2;
- score += sse_mb(s) << FF_LAMBDA_SHIFT;
- }
-
- if(*next_block){
- memcpy(s->dest, dest_backup, sizeof(s->dest));
- }
-
- if(score<*dmin){
- *dmin= score;
- *next_block^=1;
-
- copy_context_after_encode(best, s, type);
- }
-}
-
-static int sse(MpegEncContext *s, uint8_t *src1, uint8_t *src2, int w, int h, int stride){
- uint32_t *sq = ff_squareTbl + 256;
- int acc=0;
- int x,y;
-
- if(w==16 && h==16)
- return s->dsp.sse[0](NULL, src1, src2, stride, 16);
- else if(w==8 && h==8)
- return s->dsp.sse[1](NULL, src1, src2, stride, 8);
-
- for(y=0; y<h; y++){
- for(x=0; x<w; x++){
- acc+= sq[src1[x + y*stride] - src2[x + y*stride]];
- }
- }
-
- assert(acc>=0);
-
- return acc;
-}
-
-static int sse_mb(MpegEncContext *s){
- int w= 16;
- int h= 16;
-
- if(s->mb_x*16 + 16 > s->width ) w= s->width - s->mb_x*16;
- if(s->mb_y*16 + 16 > s->height) h= s->height- s->mb_y*16;
-
- if(w==16 && h==16)
- if(s->avctx->mb_cmp == FF_CMP_NSSE){
- return s->dsp.nsse[0](s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], s->linesize, 16)
- +s->dsp.nsse[1](s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], s->uvlinesize, 8)
- +s->dsp.nsse[1](s, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], s->uvlinesize, 8);
- }else{
- return s->dsp.sse[0](NULL, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], s->linesize, 16)
- +s->dsp.sse[1](NULL, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], s->uvlinesize, 8)
- +s->dsp.sse[1](NULL, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], s->uvlinesize, 8);
- }
- else
- return sse(s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], w, h, s->linesize)
- +sse(s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], w>>1, h>>1, s->uvlinesize)
- +sse(s, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], w>>1, h>>1, s->uvlinesize);
-}
-
-/* xine: do not need this for decode or MPEG-1 encoding modes */
-#if 0
-static int pre_estimate_motion_thread(AVCodecContext *c, void *arg){
- MpegEncContext *s= arg;
-
-
- s->me.pre_pass=1;
- s->me.dia_size= s->avctx->pre_dia_size;
- s->first_slice_line=1;
- for(s->mb_y= s->end_mb_y-1; s->mb_y >= s->start_mb_y; s->mb_y--) {
- for(s->mb_x=s->mb_width-1; s->mb_x >=0 ;s->mb_x--) {
- ff_pre_estimate_p_frame_motion(s, s->mb_x, s->mb_y);
- }
- s->first_slice_line=0;
- }
-
- s->me.pre_pass=0;
-
- return 0;
-}
-
-static int estimate_motion_thread(AVCodecContext *c, void *arg){
- MpegEncContext *s= arg;
-
- ff_check_alignment();
-
- s->me.dia_size= s->avctx->dia_size;
- s->first_slice_line=1;
- for(s->mb_y= s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) {
- s->mb_x=0; //for block init below
- ff_init_block_index(s);
- for(s->mb_x=0; s->mb_x < s->mb_width; s->mb_x++) {
- s->block_index[0]+=2;
- s->block_index[1]+=2;
- s->block_index[2]+=2;
- s->block_index[3]+=2;
-
- /* compute motion vector & mb_type and store in context */
- if(s->pict_type==B_TYPE)
- ff_estimate_b_frame_motion(s, s->mb_x, s->mb_y);
- else
- ff_estimate_p_frame_motion(s, s->mb_x, s->mb_y);
- }
- s->first_slice_line=0;
- }
- return 0;
-}
-#endif /* #if 0 */
-
-static int mb_var_thread(AVCodecContext *c, void *arg){
- MpegEncContext *s= arg;
- int mb_x, mb_y;
-
- ff_check_alignment();
-
- for(mb_y=s->start_mb_y; mb_y < s->end_mb_y; mb_y++) {
- for(mb_x=0; mb_x < s->mb_width; mb_x++) {
- int xx = mb_x * 16;
- int yy = mb_y * 16;
- uint8_t *pix = s->new_picture.data[0] + (yy * s->linesize) + xx;
- int varc;
- int sum = s->dsp.pix_sum(pix, s->linesize);
-
- varc = (s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)(sum*sum))>>8) + 500 + 128)>>8;
-
- s->current_picture.mb_var [s->mb_stride * mb_y + mb_x] = varc;
- s->current_picture.mb_mean[s->mb_stride * mb_y + mb_x] = (sum+128)>>8;
- s->me.mb_var_sum_temp += varc;
- }
- }
- return 0;
-}
-
-static void write_slice_end(MpegEncContext *s){
-/* xine: do not need this for decode or MPEG-1 encoding modes */
-#if 0
- if(s->codec_id==CODEC_ID_MPEG4){
- if(s->partitioned_frame){
- ff_mpeg4_merge_partitions(s);
- }
-
- ff_mpeg4_stuffing(&s->pb);
- }else if(s->out_format == FMT_MJPEG){
- ff_mjpeg_stuffing(&s->pb);
- }
-#endif /* #if 0 */
-
- align_put_bits(&s->pb);
- flush_put_bits(&s->pb);
-
- if((s->flags&CODEC_FLAG_PASS1) && !s->partitioned_frame)
- s->misc_bits+= get_bits_diff(s);
-}
-
-static int encode_thread(AVCodecContext *c, void *arg){
- MpegEncContext *s= arg;
- int mb_x, mb_y, pdif = 0;
- int i, j;
- MpegEncContext best_s, backup_s;
- uint8_t bit_buf[2][MAX_MB_BYTES];
- uint8_t bit_buf2[2][MAX_MB_BYTES];
- uint8_t bit_buf_tex[2][MAX_MB_BYTES];
- PutBitContext pb[2], pb2[2], tex_pb[2];
-//printf("%d->%d\n", s->resync_mb_y, s->end_mb_y);
-
- ff_check_alignment();
-
- for(i=0; i<2; i++){
- init_put_bits(&pb [i], bit_buf [i], MAX_MB_BYTES);
- init_put_bits(&pb2 [i], bit_buf2 [i], MAX_MB_BYTES);
- init_put_bits(&tex_pb[i], bit_buf_tex[i], MAX_MB_BYTES);
- }
-
- s->last_bits= put_bits_count(&s->pb);
- s->mv_bits=0;
- s->misc_bits=0;
- s->i_tex_bits=0;
- s->p_tex_bits=0;
- s->i_count=0;
- s->f_count=0;
- s->b_count=0;
- s->skip_count=0;
-
- for(i=0; i<3; i++){
- /* init last dc values */
- /* note: quant matrix value (8) is implied here */
- s->last_dc[i] = 128 << s->intra_dc_precision;
-
- s->current_picture.error[i] = 0;
- }
- s->mb_skip_run = 0;
- memset(s->last_mv, 0, sizeof(s->last_mv));
-
- s->last_mv_dir = 0;
-
- switch(s->codec_id){
- case CODEC_ID_H263:
- case CODEC_ID_H263P:
- case CODEC_ID_FLV1:
- s->gob_index = ff_h263_get_gob_height(s);
- break;
-/* xine: do not need this for decode or MPEG-1 encoding modes */
-#if 0
- case CODEC_ID_MPEG4:
- if(s->partitioned_frame)
- ff_mpeg4_init_partitions(s);
- break;
-#endif /* #if 0 */
- }
-
- s->resync_mb_x=0;
- s->resync_mb_y=0;
- s->first_slice_line = 1;
- s->ptr_lastgob = s->pb.buf;
- for(mb_y= s->start_mb_y; mb_y < s->end_mb_y; mb_y++) {
-// printf("row %d at %X\n", s->mb_y, (int)s);
- s->mb_x=0;
- s->mb_y= mb_y;
-
- ff_set_qscale(s, s->qscale);
- ff_init_block_index(s);
-
- for(mb_x=0; mb_x < s->mb_width; mb_x++) {
- int xy= mb_y*s->mb_stride + mb_x; // removed const, H261 needs to adjust this
- int mb_type= s->mb_type[xy];
-// int d;
- int dmin= INT_MAX;
- int dir;
-
- if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < MAX_MB_BYTES){
- av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
- return -1;
- }
- if(s->data_partitioning){
- if( s->pb2 .buf_end - s->pb2 .buf - (put_bits_count(&s-> pb2)>>3) < MAX_MB_BYTES
- || s->tex_pb.buf_end - s->tex_pb.buf - (put_bits_count(&s->tex_pb )>>3) < MAX_MB_BYTES){
- av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
- return -1;
- }
- }
-
- s->mb_x = mb_x;
- s->mb_y = mb_y; // moved into loop, can get changed by H.261
- ff_update_block_index(s);
-
-#ifdef CONFIG_H261_ENCODER
- if(s->codec_id == CODEC_ID_H261){
- ff_h261_reorder_mb_index(s);
- xy= s->mb_y*s->mb_stride + s->mb_x;
- mb_type= s->mb_type[xy];
- }
-#endif
-
- /* write gob / video packet header */
- if(s->rtp_mode){
- int current_packet_size, is_gob_start;
-
- current_packet_size= ((put_bits_count(&s->pb)+7)>>3) - (s->ptr_lastgob - s->pb.buf);
-
- is_gob_start= s->avctx->rtp_payload_size && current_packet_size >= s->avctx->rtp_payload_size && mb_y + mb_x>0;
-
- if(s->start_mb_y == mb_y && mb_y > 0 && mb_x==0) is_gob_start=1;
-
- switch(s->codec_id){
- case CODEC_ID_H263:
- case CODEC_ID_H263P:
- if(!s->h263_slice_structured)
- if(s->mb_x || s->mb_y%s->gob_index) is_gob_start=0;
- break;
- case CODEC_ID_MPEG2VIDEO:
- if(s->mb_x==0 && s->mb_y!=0) is_gob_start=1;
- case CODEC_ID_MPEG1VIDEO:
- if(s->mb_skip_run) is_gob_start=0;
- break;
- }
-
- if(is_gob_start){
- if(s->start_mb_y != mb_y || mb_x!=0){
- write_slice_end(s);
-
-/* xine: do not need this for decode or MPEG-1 encoding modes */
-#if 0
- if(s->codec_id==CODEC_ID_MPEG4 && s->partitioned_frame){
- ff_mpeg4_init_partitions(s);
- }
-#endif /* #if 0 */
- }
-
- assert((put_bits_count(&s->pb)&7) == 0);
- current_packet_size= pbBufPtr(&s->pb) - s->ptr_lastgob;
-
- if(s->avctx->error_rate && s->resync_mb_x + s->resync_mb_y > 0){
- int r= put_bits_count(&s->pb)/8 + s->picture_number + 16 + s->mb_x + s->mb_y;
- int d= 100 / s->avctx->error_rate;
- if(r % d == 0){
- current_packet_size=0;
-#ifndef ALT_BITSTREAM_WRITER
- s->pb.buf_ptr= s->ptr_lastgob;
-#endif
- assert(pbBufPtr(&s->pb) == s->ptr_lastgob);
- }
- }
-
- if (s->avctx->rtp_callback){
- int number_mb = (mb_y - s->resync_mb_y)*s->mb_width + mb_x - s->resync_mb_x;
- s->avctx->rtp_callback(s->avctx, s->ptr_lastgob, current_packet_size, number_mb);
- }
-
- switch(s->codec_id){
-/* xine: do not need this for decode or MPEG-1 encoding modes */
-#if 0
- case CODEC_ID_MPEG4:
- ff_mpeg4_encode_video_packet_header(s);
- ff_mpeg4_clean_buffers(s);
- break;
-#endif /* #if 0 */
- case CODEC_ID_MPEG1VIDEO:
- case CODEC_ID_MPEG2VIDEO:
- ff_mpeg1_encode_slice_header(s);
- ff_mpeg1_clean_buffers(s);
- break;
-/* xine: do not need this for decode or MPEG-1 encoding modes */
-#if 0
- case CODEC_ID_H263:
- case CODEC_ID_H263P:
- h263_encode_gob_header(s, mb_y);
- break;
-#endif /* #if 0 */
- }
-
- if(s->flags&CODEC_FLAG_PASS1){
- int bits= put_bits_count(&s->pb);
- s->misc_bits+= bits - s->last_bits;
- s->last_bits= bits;
- }
-
- s->ptr_lastgob += current_packet_size;
- s->first_slice_line=1;
- s->resync_mb_x=mb_x;
- s->resync_mb_y=mb_y;
- }
- }
-
- if( (s->resync_mb_x == s->mb_x)
- && s->resync_mb_y+1 == s->mb_y){
- s->first_slice_line=0;
- }
-
- s->mb_skipped=0;
- s->dquant=0; //only for QP_RD
-
- if(mb_type & (mb_type-1) || (s->flags & CODEC_FLAG_QP_RD)){ // more than 1 MB type possible or CODEC_FLAG_QP_RD
- int next_block=0;
- int pb_bits_count, pb2_bits_count, tex_pb_bits_count;
-
- copy_context_before_encode(&backup_s, s, -1);
- backup_s.pb= s->pb;
- best_s.data_partitioning= s->data_partitioning;
- best_s.partitioned_frame= s->partitioned_frame;
- if(s->data_partitioning){
- backup_s.pb2= s->pb2;
- backup_s.tex_pb= s->tex_pb;
- }
-
- if(mb_type&CANDIDATE_MB_TYPE_INTER){
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_16X16;
- s->mb_intra= 0;
- s->mv[0][0][0] = s->p_mv_table[xy][0];
- s->mv[0][0][1] = s->p_mv_table[xy][1];
- encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER, pb, pb2, tex_pb,
- &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]);
- }
- if(mb_type&CANDIDATE_MB_TYPE_INTER_I){
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_FIELD;
- s->mb_intra= 0;
- for(i=0; i<2; i++){
- j= s->field_select[0][i] = s->p_field_select_table[i][xy];
- s->mv[0][i][0] = s->p_field_mv_table[i][j][xy][0];
- s->mv[0][i][1] = s->p_field_mv_table[i][j][xy][1];
- }
- encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER_I, pb, pb2, tex_pb,
- &dmin, &next_block, 0, 0);
- }
- if(mb_type&CANDIDATE_MB_TYPE_SKIPPED){
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_16X16;
- s->mb_intra= 0;
- s->mv[0][0][0] = 0;
- s->mv[0][0][1] = 0;
- encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_SKIPPED, pb, pb2, tex_pb,
- &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]);
- }
- if(mb_type&CANDIDATE_MB_TYPE_INTER4V){
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_8X8;
- s->mb_intra= 0;
- for(i=0; i<4; i++){
- s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0];
- s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1];
- }
- encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER4V, pb, pb2, tex_pb,
- &dmin, &next_block, 0, 0);
- }
- if(mb_type&CANDIDATE_MB_TYPE_FORWARD){
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_16X16;
- s->mb_intra= 0;
- s->mv[0][0][0] = s->b_forw_mv_table[xy][0];
- s->mv[0][0][1] = s->b_forw_mv_table[xy][1];
- encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_FORWARD, pb, pb2, tex_pb,
- &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]);
- }
- if(mb_type&CANDIDATE_MB_TYPE_BACKWARD){
- s->mv_dir = MV_DIR_BACKWARD;
- s->mv_type = MV_TYPE_16X16;
- s->mb_intra= 0;
- s->mv[1][0][0] = s->b_back_mv_table[xy][0];
- s->mv[1][0][1] = s->b_back_mv_table[xy][1];
- encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BACKWARD, pb, pb2, tex_pb,
- &dmin, &next_block, s->mv[1][0][0], s->mv[1][0][1]);
- }
- if(mb_type&CANDIDATE_MB_TYPE_BIDIR){
- s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD;
- s->mv_type = MV_TYPE_16X16;
- s->mb_intra= 0;
- s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0];
- s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1];
- s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0];
- s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1];
- encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BIDIR, pb, pb2, tex_pb,
- &dmin, &next_block, 0, 0);
- }
- if(mb_type&CANDIDATE_MB_TYPE_FORWARD_I){
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_FIELD;
- s->mb_intra= 0;
- for(i=0; i<2; i++){
- j= s->field_select[0][i] = s->b_field_select_table[0][i][xy];
- s->mv[0][i][0] = s->b_field_mv_table[0][i][j][xy][0];
- s->mv[0][i][1] = s->b_field_mv_table[0][i][j][xy][1];
- }
- encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_FORWARD_I, pb, pb2, tex_pb,
- &dmin, &next_block, 0, 0);
- }
- if(mb_type&CANDIDATE_MB_TYPE_BACKWARD_I){
- s->mv_dir = MV_DIR_BACKWARD;
- s->mv_type = MV_TYPE_FIELD;
- s->mb_intra= 0;
- for(i=0; i<2; i++){
- j= s->field_select[1][i] = s->b_field_select_table[1][i][xy];
- s->mv[1][i][0] = s->b_field_mv_table[1][i][j][xy][0];
- s->mv[1][i][1] = s->b_field_mv_table[1][i][j][xy][1];
- }
- encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BACKWARD_I, pb, pb2, tex_pb,
- &dmin, &next_block, 0, 0);
- }
- if(mb_type&CANDIDATE_MB_TYPE_BIDIR_I){
- s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD;
- s->mv_type = MV_TYPE_FIELD;
- s->mb_intra= 0;
- for(dir=0; dir<2; dir++){
- for(i=0; i<2; i++){
- j= s->field_select[dir][i] = s->b_field_select_table[dir][i][xy];
- s->mv[dir][i][0] = s->b_field_mv_table[dir][i][j][xy][0];
- s->mv[dir][i][1] = s->b_field_mv_table[dir][i][j][xy][1];
- }
- }
- encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BIDIR_I, pb, pb2, tex_pb,
- &dmin, &next_block, 0, 0);
- }
- if(mb_type&CANDIDATE_MB_TYPE_INTRA){
- s->mv_dir = 0;
- s->mv_type = MV_TYPE_16X16;
- s->mb_intra= 1;
- s->mv[0][0][0] = 0;
- s->mv[0][0][1] = 0;
- encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTRA, pb, pb2, tex_pb,
- &dmin, &next_block, 0, 0);
- if(s->h263_pred || s->h263_aic){
- if(best_s.mb_intra)
- s->mbintra_table[mb_x + mb_y*s->mb_stride]=1;
- else
- ff_clean_intra_table_entries(s); //old mode?
- }
- }
-
- if((s->flags & CODEC_FLAG_QP_RD) && dmin < INT_MAX){
- if(best_s.mv_type==MV_TYPE_16X16){ //FIXME move 4mv after QPRD
- const int last_qp= backup_s.qscale;
- int qpi, qp, dc[6];
- DCTELEM ac[6][16];
- const int mvdir= (best_s.mv_dir&MV_DIR_BACKWARD) ? 1 : 0;
- static const int dquant_tab[4]={-1,1,-2,2};
-
- assert(backup_s.dquant == 0);
-
- //FIXME intra
- s->mv_dir= best_s.mv_dir;
- s->mv_type = MV_TYPE_16X16;
- s->mb_intra= best_s.mb_intra;
- s->mv[0][0][0] = best_s.mv[0][0][0];
- s->mv[0][0][1] = best_s.mv[0][0][1];
- s->mv[1][0][0] = best_s.mv[1][0][0];
- s->mv[1][0][1] = best_s.mv[1][0][1];
-
- qpi = s->pict_type == B_TYPE ? 2 : 0;
- for(; qpi<4; qpi++){
- int dquant= dquant_tab[qpi];
- qp= last_qp + dquant;
- if(qp < s->avctx->qmin || qp > s->avctx->qmax)
- continue;
- backup_s.dquant= dquant;
- if(s->mb_intra && s->dc_val[0]){
- for(i=0; i<6; i++){
- dc[i]= s->dc_val[0][ s->block_index[i] ];
- memcpy(ac[i], s->ac_val[0][s->block_index[i]], sizeof(DCTELEM)*16);
- }
- }
-
- encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER /* wrong but unused */, pb, pb2, tex_pb,
- &dmin, &next_block, s->mv[mvdir][0][0], s->mv[mvdir][0][1]);
- if(best_s.qscale != qp){
- if(s->mb_intra && s->dc_val[0]){
- for(i=0; i<6; i++){
- s->dc_val[0][ s->block_index[i] ]= dc[i];
- memcpy(s->ac_val[0][s->block_index[i]], ac[i], sizeof(DCTELEM)*16);
- }
- }
- }
- }
- }
- }
- if(mb_type&CANDIDATE_MB_TYPE_DIRECT){
- int mx= s->b_direct_mv_table[xy][0];
- int my= s->b_direct_mv_table[xy][1];
-
- backup_s.dquant = 0;
- s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
- s->mb_intra= 0;
- ff_mpeg4_set_direct_mv(s, mx, my);
- encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_DIRECT, pb, pb2, tex_pb,
- &dmin, &next_block, mx, my);
- }
- if(mb_type&CANDIDATE_MB_TYPE_DIRECT0){
- backup_s.dquant = 0;
- s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
- s->mb_intra= 0;
-/* xine: do not need this for decode or MPEG-1 encoding modes */
-#if 0
- ff_mpeg4_set_direct_mv(s, 0, 0);
-#endif /* #if 0 */
- encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_DIRECT, pb, pb2, tex_pb,
- &dmin, &next_block, 0, 0);
- }
- if(!best_s.mb_intra && s->flags2&CODEC_FLAG2_SKIP_RD){
- int coded=0;
- for(i=0; i<6; i++)
- coded |= s->block_last_index[i];
- if(coded){
- int mx,my;
- memcpy(s->mv, best_s.mv, sizeof(s->mv));
- if(best_s.mv_dir & MV_DIRECT){
- mx=my=0; //FIXME find the one we actually used
- ff_mpeg4_set_direct_mv(s, mx, my);
- }else if(best_s.mv_dir&MV_DIR_BACKWARD){
- mx= s->mv[1][0][0];
- my= s->mv[1][0][1];
- }else{
- mx= s->mv[0][0][0];
- my= s->mv[0][0][1];
- }
-
- s->mv_dir= best_s.mv_dir;
- s->mv_type = best_s.mv_type;
- s->mb_intra= 0;
-/* s->mv[0][0][0] = best_s.mv[0][0][0];
- s->mv[0][0][1] = best_s.mv[0][0][1];
- s->mv[1][0][0] = best_s.mv[1][0][0];
- s->mv[1][0][1] = best_s.mv[1][0][1];*/
- backup_s.dquant= 0;
- s->skipdct=1;
- encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER /* wrong but unused */, pb, pb2, tex_pb,
- &dmin, &next_block, mx, my);
- s->skipdct=0;
- }
- }
-
- s->current_picture.qscale_table[xy]= best_s.qscale;
-
- copy_context_after_encode(s, &best_s, -1);
-
- pb_bits_count= put_bits_count(&s->pb);
- flush_put_bits(&s->pb);
- ff_copy_bits(&backup_s.pb, bit_buf[next_block^1], pb_bits_count);
- s->pb= backup_s.pb;
-
- if(s->data_partitioning){
- pb2_bits_count= put_bits_count(&s->pb2);
- flush_put_bits(&s->pb2);
- ff_copy_bits(&backup_s.pb2, bit_buf2[next_block^1], pb2_bits_count);
- s->pb2= backup_s.pb2;
-
- tex_pb_bits_count= put_bits_count(&s->tex_pb);
- flush_put_bits(&s->tex_pb);
- ff_copy_bits(&backup_s.tex_pb, bit_buf_tex[next_block^1], tex_pb_bits_count);
- s->tex_pb= backup_s.tex_pb;
- }
- s->last_bits= put_bits_count(&s->pb);
-
- if (s->out_format == FMT_H263 && s->pict_type!=B_TYPE)
- ff_h263_update_motion_val(s);
-
- if(next_block==0){ //FIXME 16 vs linesize16
- s->dsp.put_pixels_tab[0][0](s->dest[0], s->rd_scratchpad , s->linesize ,16);
- s->dsp.put_pixels_tab[1][0](s->dest[1], s->rd_scratchpad + 16*s->linesize , s->uvlinesize, 8);
- s->dsp.put_pixels_tab[1][0](s->dest[2], s->rd_scratchpad + 16*s->linesize + 8, s->uvlinesize, 8);
- }
-
- if(s->avctx->mb_decision == FF_MB_DECISION_BITS)
- MPV_decode_mb(s, s->block);
- } else {
- int motion_x = 0, motion_y = 0;
- s->mv_type=MV_TYPE_16X16;
- // only one MB-Type possible
-
- switch(mb_type){
- case CANDIDATE_MB_TYPE_INTRA:
- s->mv_dir = 0;
- s->mb_intra= 1;
- motion_x= s->mv[0][0][0] = 0;
- motion_y= s->mv[0][0][1] = 0;
- break;
- case CANDIDATE_MB_TYPE_INTER:
- s->mv_dir = MV_DIR_FORWARD;
- s->mb_intra= 0;
- motion_x= s->mv[0][0][0] = s->p_mv_table[xy][0];
- motion_y= s->mv[0][0][1] = s->p_mv_table[xy][1];
- break;
- case CANDIDATE_MB_TYPE_INTER_I:
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_FIELD;
- s->mb_intra= 0;
- for(i=0; i<2; i++){
- j= s->field_select[0][i] = s->p_field_select_table[i][xy];
- s->mv[0][i][0] = s->p_field_mv_table[i][j][xy][0];
- s->mv[0][i][1] = s->p_field_mv_table[i][j][xy][1];
- }
- break;
- case CANDIDATE_MB_TYPE_INTER4V:
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_8X8;
- s->mb_intra= 0;
- for(i=0; i<4; i++){
- s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0];
- s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1];
- }
- break;
- case CANDIDATE_MB_TYPE_DIRECT:
- s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
- s->mb_intra= 0;
- motion_x=s->b_direct_mv_table[xy][0];
- motion_y=s->b_direct_mv_table[xy][1];
-/* xine: do not need this for decode or MPEG-1 encoding modes */
-#if 0
- ff_mpeg4_set_direct_mv(s, motion_x, motion_y);
-#endif /* #if 0 */
- break;
- case CANDIDATE_MB_TYPE_DIRECT0:
- s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
- s->mb_intra= 0;
- ff_mpeg4_set_direct_mv(s, 0, 0);
- break;
- case CANDIDATE_MB_TYPE_BIDIR:
- s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD;
- s->mb_intra= 0;
- s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0];
- s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1];
- s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0];
- s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1];
- break;
- case CANDIDATE_MB_TYPE_BACKWARD:
- s->mv_dir = MV_DIR_BACKWARD;
- s->mb_intra= 0;
- motion_x= s->mv[1][0][0] = s->b_back_mv_table[xy][0];
- motion_y= s->mv[1][0][1] = s->b_back_mv_table[xy][1];
- break;
- case CANDIDATE_MB_TYPE_FORWARD:
- s->mv_dir = MV_DIR_FORWARD;
- s->mb_intra= 0;
- motion_x= s->mv[0][0][0] = s->b_forw_mv_table[xy][0];
- motion_y= s->mv[0][0][1] = s->b_forw_mv_table[xy][1];
-// printf(" %d %d ", motion_x, motion_y);
- break;
- case CANDIDATE_MB_TYPE_FORWARD_I:
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_FIELD;
- s->mb_intra= 0;
- for(i=0; i<2; i++){
- j= s->field_select[0][i] = s->b_field_select_table[0][i][xy];
- s->mv[0][i][0] = s->b_field_mv_table[0][i][j][xy][0];
- s->mv[0][i][1] = s->b_field_mv_table[0][i][j][xy][1];
- }
- break;
- case CANDIDATE_MB_TYPE_BACKWARD_I:
- s->mv_dir = MV_DIR_BACKWARD;
- s->mv_type = MV_TYPE_FIELD;
- s->mb_intra= 0;
- for(i=0; i<2; i++){
- j= s->field_select[1][i] = s->b_field_select_table[1][i][xy];
- s->mv[1][i][0] = s->b_field_mv_table[1][i][j][xy][0];
- s->mv[1][i][1] = s->b_field_mv_table[1][i][j][xy][1];
- }
- break;
- case CANDIDATE_MB_TYPE_BIDIR_I:
- s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD;
- s->mv_type = MV_TYPE_FIELD;
- s->mb_intra= 0;
- for(dir=0; dir<2; dir++){
- for(i=0; i<2; i++){
- j= s->field_select[dir][i] = s->b_field_select_table[dir][i][xy];
- s->mv[dir][i][0] = s->b_field_mv_table[dir][i][j][xy][0];
- s->mv[dir][i][1] = s->b_field_mv_table[dir][i][j][xy][1];
- }
- }
- break;
- default:
- av_log(s->avctx, AV_LOG_ERROR, "illegal MB type\n");
- }
-
- encode_mb(s, motion_x, motion_y);
-
- // RAL: Update last macroblock type
- s->last_mv_dir = s->mv_dir;
-
- if (s->out_format == FMT_H263 && s->pict_type!=B_TYPE)
- ff_h263_update_motion_val(s);
-
- MPV_decode_mb(s, s->block);
- }
-
- /* clean the MV table in IPS frames for direct mode in B frames */
- if(s->mb_intra /* && I,P,S_TYPE */){
- s->p_mv_table[xy][0]=0;
- s->p_mv_table[xy][1]=0;
- }
-
- if(s->flags&CODEC_FLAG_PSNR){
- int w= 16;
- int h= 16;
-
- if(s->mb_x*16 + 16 > s->width ) w= s->width - s->mb_x*16;
- if(s->mb_y*16 + 16 > s->height) h= s->height- s->mb_y*16;
-
- s->current_picture.error[0] += sse(
- s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16,
- s->dest[0], w, h, s->linesize);
- s->current_picture.error[1] += sse(
- s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,
- s->dest[1], w>>1, h>>1, s->uvlinesize);
- s->current_picture.error[2] += sse(
- s, s->new_picture .data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,
- s->dest[2], w>>1, h>>1, s->uvlinesize);
- }
- if(s->loop_filter){
- if(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));
- }
- }
-
- //not beautiful here but we must write it before flushing so it has to be here
-/* xine: do not need this for decode or MPEG-1 encoding modes */
-#if 0
- if (s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type == I_TYPE)
- msmpeg4_encode_ext_header(s);
-#endif /* #if 0 */
-
- write_slice_end(s);
-
- /* Send the last GOB if RTP */
- if (s->avctx->rtp_callback) {
- int number_mb = (mb_y - s->resync_mb_y)*s->mb_width - s->resync_mb_x;
- pdif = pbBufPtr(&s->pb) - s->ptr_lastgob;
- /* Call the RTP callback to send the last GOB */
- emms_c();
- s->avctx->rtp_callback(s->avctx, s->ptr_lastgob, pdif, number_mb);
- }
-
- return 0;
-}
-
-#define MERGE(field) dst->field += src->field; src->field=0
-static void merge_context_after_me(MpegEncContext *dst, MpegEncContext *src){
- MERGE(me.scene_change_score);
- MERGE(me.mc_mb_var_sum_temp);
- MERGE(me.mb_var_sum_temp);
-}
-
-static void merge_context_after_encode(MpegEncContext *dst, MpegEncContext *src){
- int i;
-
- MERGE(dct_count[0]); //note, the other dct vars are not part of the context
- MERGE(dct_count[1]);
- MERGE(mv_bits);
- MERGE(i_tex_bits);
- MERGE(p_tex_bits);
- MERGE(i_count);
- MERGE(f_count);
- MERGE(b_count);
- MERGE(skip_count);
- MERGE(misc_bits);
- MERGE(error_count);
- MERGE(padding_bug_score);
- MERGE(current_picture.error[0]);
- MERGE(current_picture.error[1]);
- MERGE(current_picture.error[2]);
-
- if(dst->avctx->noise_reduction){
- for(i=0; i<64; i++){
- MERGE(dct_error_sum[0][i]);
- MERGE(dct_error_sum[1][i]);
- }
- }
-
- assert(put_bits_count(&src->pb) % 8 ==0);
- assert(put_bits_count(&dst->pb) % 8 ==0);
- ff_copy_bits(&dst->pb, src->pb.buf, put_bits_count(&src->pb));
- flush_put_bits(&dst->pb);
-}
-
-static int estimate_qp(MpegEncContext *s, int dry_run){
- if (s->next_lambda){
- s->current_picture_ptr->quality=
- s->current_picture.quality = s->next_lambda;
- if(!dry_run) s->next_lambda= 0;
- } else if (!s->fixed_qscale) {
- s->current_picture_ptr->quality=
- s->current_picture.quality = ff_rate_estimate_qscale(s, dry_run);
- if (s->current_picture.quality < 0)
- return -1;
- }
-
- if(s->adaptive_quant){
-/* xine: do not need this for decode or MPEG-1 encoding modes */
-#if 0
- switch(s->codec_id){
- case CODEC_ID_MPEG4:
- ff_clean_mpeg4_qscales(s);
- break;
- case CODEC_ID_H263:
- case CODEC_ID_H263P:
- case CODEC_ID_FLV1:
- ff_clean_h263_qscales(s);
- break;
- }
-#endif /* #if 0 */
-
- s->lambda= s->lambda_table[0];
- //FIXME broken
- }else
- s->lambda= s->current_picture.quality;
-//printf("%d %d\n", s->avctx->global_quality, s->current_picture.quality);
- update_qscale(s);
- return 0;
-}
-
-static int encode_picture(MpegEncContext *s, int picture_number)
-{
- int i;
- int bits;
-
- s->picture_number = picture_number;
-
- /* Reset the average MB variance */
- s->me.mb_var_sum_temp =
- s->me.mc_mb_var_sum_temp = 0;
-
-/* xine: do not need this for decode or MPEG-1 encoding modes */
-#if 0
- /* we need to initialize some time vars before we can encode b-frames */
- // RAL: Condition added for MPEG1VIDEO
- if (s->codec_id == CODEC_ID_MPEG1VIDEO || s->codec_id == CODEC_ID_MPEG2VIDEO || (s->h263_pred && !s->h263_msmpeg4))
- ff_set_mpeg4_time(s, s->picture_number); //FIXME rename and use has_b_frames or similar
-#endif /* #if 0 */
-
- s->me.scene_change_score=0;
-
-// s->lambda= s->current_picture_ptr->quality; //FIXME qscale / ... stuff for ME ratedistoration
-
- if(s->pict_type==I_TYPE){
- if(s->msmpeg4_version >= 3) s->no_rounding=1;
- else s->no_rounding=0;
- }else if(s->pict_type!=B_TYPE){
- if(s->flipflop_rounding || s->codec_id == CODEC_ID_H263P || s->codec_id == CODEC_ID_MPEG4)
- s->no_rounding ^= 1;
- }
-
- if(s->flags & CODEC_FLAG_PASS2){
- if (estimate_qp(s,1) < 0)
- return -1;
- ff_get_2pass_fcode(s);
- }else if(!(s->flags & CODEC_FLAG_QSCALE)){
- if(s->pict_type==B_TYPE)
- s->lambda= s->last_lambda_for[s->pict_type];
- else
- s->lambda= s->last_lambda_for[s->last_non_b_pict_type];
- update_qscale(s);
- }
-
- s->mb_intra=0; //for the rate distortion & bit compare functions
- for(i=1; i<s->avctx->thread_count; i++){
- ff_update_duplicate_context(s->thread_context[i], s);
- }
-
-/* xine: do not need this for decode or MPEG-1 encoding modes */
-#if 0
- ff_init_me(s);
-
- /* Estimate motion for every MB */
- if(s->pict_type != I_TYPE){
- s->lambda = (s->lambda * s->avctx->me_penalty_compensation + 128)>>8;
- s->lambda2= (s->lambda2* (int64_t)s->avctx->me_penalty_compensation + 128)>>8;
- if(s->pict_type != B_TYPE && s->avctx->me_threshold==0){
- if((s->avctx->pre_me && s->last_non_b_pict_type==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);
- }
- }
-
- s->avctx->execute(s->avctx, estimate_motion_thread, (void**)&(s->thread_context[0]), NULL, s->avctx->thread_count);
- }else /* if(s->pict_type == I_TYPE) */{
-#endif /* #if 0 */
- {
- /* I-Frame */
- for(i=0; i<s->mb_stride*s->mb_height; i++)
- s->mb_type[i]= CANDIDATE_MB_TYPE_INTRA;
-
- 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);
- }
- }
- for(i=1; i<s->avctx->thread_count; i++){
- merge_context_after_me(s, s->thread_context[i]);
- }
- s->current_picture.mc_mb_var_sum= s->current_picture_ptr->mc_mb_var_sum= s->me.mc_mb_var_sum_temp;
- s->current_picture. mb_var_sum= s->current_picture_ptr-> mb_var_sum= s->me. mb_var_sum_temp;
- emms_c();
-
- if(s->me.scene_change_score > s->avctx->scenechange_threshold && s->pict_type == P_TYPE){
- s->pict_type= I_TYPE;
- for(i=0; i<s->mb_stride*s->mb_height; i++)
- s->mb_type[i]= CANDIDATE_MB_TYPE_INTRA;
-//printf("Scene change detected, encoding as I Frame %d %d\n", s->current_picture.mb_var_sum, s->current_picture.mc_mb_var_sum);
- }
-
-/* xine: do not need this for decode or MPEG-1 encoding modes */
-#if 0
- if(!s->umvplus){
- if(s->pict_type==P_TYPE || s->pict_type==S_TYPE) {
- s->f_code= ff_get_best_fcode(s, s->p_mv_table, CANDIDATE_MB_TYPE_INTER);
-
- if(s->flags & CODEC_FLAG_INTERLACED_ME){
- int a,b;
- a= ff_get_best_fcode(s, s->p_field_mv_table[0][0], CANDIDATE_MB_TYPE_INTER_I); //FIXME field_select
- b= ff_get_best_fcode(s, s->p_field_mv_table[1][1], CANDIDATE_MB_TYPE_INTER_I);
- s->f_code= FFMAX(s->f_code, FFMAX(a,b));
- }
-
- ff_fix_long_p_mvs(s);
- ff_fix_long_mvs(s, NULL, 0, s->p_mv_table, s->f_code, CANDIDATE_MB_TYPE_INTER, 0);
- if(s->flags & CODEC_FLAG_INTERLACED_ME){
- int j;
- for(i=0; i<2; i++){
- for(j=0; j<2; j++)
- ff_fix_long_mvs(s, s->p_field_select_table[i], j,
- s->p_field_mv_table[i][j], s->f_code, CANDIDATE_MB_TYPE_INTER_I, 0);
- }
- }
- }
-
- if(s->pict_type==B_TYPE){
- int a, b;
-
- a = ff_get_best_fcode(s, s->b_forw_mv_table, CANDIDATE_MB_TYPE_FORWARD);
- b = ff_get_best_fcode(s, s->b_bidir_forw_mv_table, CANDIDATE_MB_TYPE_BIDIR);
- s->f_code = FFMAX(a, b);
-
- a = ff_get_best_fcode(s, s->b_back_mv_table, CANDIDATE_MB_TYPE_BACKWARD);
- b = ff_get_best_fcode(s, s->b_bidir_back_mv_table, CANDIDATE_MB_TYPE_BIDIR);
- s->b_code = FFMAX(a, b);
-
- ff_fix_long_mvs(s, NULL, 0, s->b_forw_mv_table, s->f_code, CANDIDATE_MB_TYPE_FORWARD, 1);
- ff_fix_long_mvs(s, NULL, 0, s->b_back_mv_table, s->b_code, CANDIDATE_MB_TYPE_BACKWARD, 1);
- ff_fix_long_mvs(s, NULL, 0, s->b_bidir_forw_mv_table, s->f_code, CANDIDATE_MB_TYPE_BIDIR, 1);
- ff_fix_long_mvs(s, NULL, 0, s->b_bidir_back_mv_table, s->b_code, CANDIDATE_MB_TYPE_BIDIR, 1);
- if(s->flags & CODEC_FLAG_INTERLACED_ME){
- int dir, j;
- for(dir=0; dir<2; dir++){
- for(i=0; i<2; i++){
- for(j=0; j<2; j++){
- int type= dir ? (CANDIDATE_MB_TYPE_BACKWARD_I|CANDIDATE_MB_TYPE_BIDIR_I)
- : (CANDIDATE_MB_TYPE_FORWARD_I |CANDIDATE_MB_TYPE_BIDIR_I);
- ff_fix_long_mvs(s, s->b_field_select_table[dir][i], j,
- s->b_field_mv_table[dir][i][j], dir ? s->b_code : s->f_code, type, 1);
- }
- }
- }
- }
- }
- }
-#endif /* #if 0 */
-
- if (estimate_qp(s, 0) < 0)
- return -1;
-
- if(s->qscale < 3 && s->max_qcoeff<=128 && s->pict_type==I_TYPE && !(s->flags & CODEC_FLAG_QSCALE))
- s->qscale= 3; //reduce clipping problems
-
- 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] = clip_uint8((ff_mpeg1_default_intra_matrix[i] * s->qscale) >> 3);
- }
- 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;
- }
-
- //FIXME var duplication
- s->current_picture_ptr->key_frame=
- s->current_picture.key_frame= s->pict_type == I_TYPE; //FIXME pic_ptr
- s->current_picture_ptr->pict_type=
- s->current_picture.pict_type= s->pict_type;
-
- if(s->current_picture.key_frame)
- s->picture_in_gop_number=0;
-
- s->last_bits= put_bits_count(&s->pb);
- switch(s->out_format) {
-/* xine: do not need this for decode or MPEG-1 encoding modes */
-#if 0
- case FMT_MJPEG:
- mjpeg_picture_header(s);
- break;
-#ifdef CONFIG_H261_ENCODER
- case FMT_H261:
- ff_h261_encode_picture_header(s, picture_number);
- break;
-#endif
- case FMT_H263:
- if (s->codec_id == CODEC_ID_WMV2)
- ff_wmv2_encode_picture_header(s, picture_number);
- else if (s->h263_msmpeg4)
- msmpeg4_encode_picture_header(s, picture_number);
- else if (s->h263_pred)
- mpeg4_encode_picture_header(s, picture_number);
-#ifdef CONFIG_RV10_ENCODER
- else if (s->codec_id == CODEC_ID_RV10)
- rv10_encode_picture_header(s, picture_number);
-#endif
-#ifdef CONFIG_RV20_ENCODER
- else if (s->codec_id == CODEC_ID_RV20)
- rv20_encode_picture_header(s, picture_number);
-#endif
- else if (s->codec_id == CODEC_ID_FLV1)
- ff_flv_encode_picture_header(s, picture_number);
- else
- h263_encode_picture_header(s, picture_number);
- break;
-#endif /* #if 0 */
- case FMT_MPEG1:
- mpeg1_encode_picture_header(s, picture_number);
- break;
-/* xine: do not need this for decode or MPEG-1 encoding modes */
-#if 0
- case FMT_H264:
- break;
-#endif /* #if 0 */
- default:
- assert(0);
- }
- bits= put_bits_count(&s->pb);
- s->header_bits= bits - s->last_bits;
-
- for(i=1; i<s->avctx->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);
- for(i=1; i<s->avctx->thread_count; i++){
- merge_context_after_encode(s, s->thread_context[i]);
- }
- emms_c();
- return 0;
-}
-
-static void denoise_dct_c(MpegEncContext *s, DCTELEM *block){
- const int intra= s->mb_intra;
- int i;
-
- s->dct_count[intra]++;
-
- for(i=0; i<64; i++){
- int level= block[i];
-
- if(level){
- if(level>0){
- s->dct_error_sum[intra][i] += level;
- level -= s->dct_offset[intra][i];
- if(level<0) level=0;
- }else{
- s->dct_error_sum[intra][i] -= level;
- level += s->dct_offset[intra][i];
- if(level>0) level=0;
- }
- block[i]= level;
- }
- }
-}
-
-static int dct_quantize_trellis_c(MpegEncContext *s,
- DCTELEM *block, int n,
- int qscale, int *overflow){
- const int *qmat;
- const uint8_t *scantable= s->intra_scantable.scantable;
- const uint8_t *perm_scantable= s->intra_scantable.permutated;
- int max=0;
- unsigned int threshold1, threshold2;
- int bias=0;
- int run_tab[65];
- int level_tab[65];
- int score_tab[65];
- int survivor[65];
- int survivor_count;
- int last_run=0;
- int last_level=0;
- int last_score= 0;
- int last_i;
- int coeff[2][64];
- int coeff_count[64];
- int qmul, qadd, start_i, last_non_zero, i, dc;
- const int esc_length= s->ac_esc_length;
- uint8_t * length;
- uint8_t * last_length;
- const int lambda= s->lambda2 >> (FF_LAMBDA_SHIFT - 6);
-
- s->dsp.fdct (block);
-
- if(s->dct_error_sum)
- s->denoise_dct(s, block);
- qmul= qscale*16;
- qadd= ((qscale-1)|1)*8;
-
- if (s->mb_intra) {
- int q;
- if (!s->h263_aic) {
- if (n < 4)
- q = s->y_dc_scale;
- else
- q = s->c_dc_scale;
- q = q << 3;
- } else{
- /* For AIC we skip quant/dequant of INTRADC */
- q = 1 << 3;
- qadd=0;
- }
-
- /* note: block[0] is assumed to be positive */
- block[0] = (block[0] + (q >> 1)) / q;
- start_i = 1;
- last_non_zero = 0;
- qmat = s->q_intra_matrix[qscale];
- if(s->mpeg_quant || s->out_format == FMT_MPEG1)
- bias= 1<<(QMAT_SHIFT-1);
- length = s->intra_ac_vlc_length;
- last_length= s->intra_ac_vlc_last_length;
- } else {
- start_i = 0;
- last_non_zero = -1;
- qmat = s->q_inter_matrix[qscale];
- length = s->inter_ac_vlc_length;
- last_length= s->inter_ac_vlc_last_length;
- }
- last_i= start_i;
-
- threshold1= (1<<QMAT_SHIFT) - bias - 1;
- threshold2= (threshold1<<1);
-
- for(i=63; i>=start_i; i--) {
- const int j = scantable[i];
- int level = block[j] * qmat[j];
-
- if(((unsigned)(level+threshold1))>threshold2){
- last_non_zero = i;
- break;
- }
- }
-
- for(i=start_i; i<=last_non_zero; i++) {
- const int j = scantable[i];
- int level = block[j] * qmat[j];
-
-// if( bias+level >= (1<<(QMAT_SHIFT - 3))
-// || bias-level >= (1<<(QMAT_SHIFT - 3))){
- if(((unsigned)(level+threshold1))>threshold2){
- if(level>0){
- level= (bias + level)>>QMAT_SHIFT;
- coeff[0][i]= level;
- coeff[1][i]= level-1;
-// coeff[2][k]= level-2;
- }else{
- level= (bias - level)>>QMAT_SHIFT;
- coeff[0][i]= -level;
- coeff[1][i]= -level+1;
-// coeff[2][k]= -level+2;
- }
- coeff_count[i]= FFMIN(level, 2);
- assert(coeff_count[i]);
- max |=level;
- }else{
- coeff[0][i]= (level>>31)|1;
- coeff_count[i]= 1;
- }
- }
-
- *overflow= s->max_qcoeff < max; //overflow might have happened
-
- if(last_non_zero < start_i){
- memset(block + start_i, 0, (64-start_i)*sizeof(DCTELEM));
- return last_non_zero;
- }
-
- score_tab[start_i]= 0;
- survivor[0]= start_i;
- survivor_count= 1;
-
- for(i=start_i; i<=last_non_zero; i++){
- int level_index, j;
- const int dct_coeff= FFABS(block[ scantable[i] ]);
- const int zero_distoration= dct_coeff*dct_coeff;
- int best_score=256*256*256*120;
- for(level_index=0; level_index < coeff_count[i]; level_index++){
- int distoration;
- int level= coeff[level_index][i];
- const int alevel= FFABS(level);
- int unquant_coeff;
-
- assert(level);
-
- if(s->out_format == FMT_H263){
- unquant_coeff= alevel*qmul + qadd;
- }else{ //MPEG1
- j= s->dsp.idct_permutation[ scantable[i] ]; //FIXME optimize
- if(s->mb_intra){
- unquant_coeff = (int)( alevel * qscale * s->intra_matrix[j]) >> 3;
- unquant_coeff = (unquant_coeff - 1) | 1;
- }else{
- unquant_coeff = ((( alevel << 1) + 1) * qscale * ((int) s->inter_matrix[j])) >> 4;
- unquant_coeff = (unquant_coeff - 1) | 1;
- }
- unquant_coeff<<= 3;
- }
-
- distoration= (unquant_coeff - dct_coeff) * (unquant_coeff - dct_coeff) - zero_distoration;
- level+=64;
- if((level&(~127)) == 0){
- for(j=survivor_count-1; j>=0; j--){
- int run= i - survivor[j];
- int score= distoration + length[UNI_AC_ENC_INDEX(run, level)]*lambda;
- score += score_tab[i-run];
-
- if(score < best_score){
- best_score= score;
- run_tab[i+1]= run;
- level_tab[i+1]= level-64;
- }
- }
-
- if(s->out_format == FMT_H263){
- for(j=survivor_count-1; j>=0; j--){
- int run= i - survivor[j];
- int score= distoration + last_length[UNI_AC_ENC_INDEX(run, level)]*lambda;
- score += score_tab[i-run];
- if(score < last_score){
- last_score= score;
- last_run= run;
- last_level= level-64;
- last_i= i+1;
- }
- }
- }
- }else{
- distoration += esc_length*lambda;
- for(j=survivor_count-1; j>=0; j--){
- int run= i - survivor[j];
- int score= distoration + score_tab[i-run];
-
- if(score < best_score){
- best_score= score;
- run_tab[i+1]= run;
- level_tab[i+1]= level-64;
- }
- }
-
- if(s->out_format == FMT_H263){
- for(j=survivor_count-1; j>=0; j--){
- int run= i - survivor[j];
- int score= distoration + score_tab[i-run];
- if(score < last_score){
- last_score= score;
- last_run= run;
- last_level= level-64;
- last_i= i+1;
- }
- }
- }
- }
- }
-
- score_tab[i+1]= best_score;
-
- //Note: there is a vlc code in mpeg4 which is 1 bit shorter then another one with a shorter run and the same level
- if(last_non_zero <= 27){
- for(; survivor_count; survivor_count--){
- if(score_tab[ survivor[survivor_count-1] ] <= best_score)
- break;
- }
- }else{
- for(; survivor_count; survivor_count--){
- if(score_tab[ survivor[survivor_count-1] ] <= best_score + lambda)
- break;
- }
- }
-
- survivor[ survivor_count++ ]= i+1;
- }
-
- if(s->out_format != FMT_H263){
- last_score= 256*256*256*120;
- for(i= survivor[0]; i<=last_non_zero + 1; i++){
- int score= score_tab[i];
- if(i) score += lambda*2; //FIXME exacter?
-
- if(score < last_score){
- last_score= score;
- last_i= i;
- last_level= level_tab[i];
- last_run= run_tab[i];
- }
- }
- }
-
- s->coded_score[n] = last_score;
-
- dc= FFABS(block[0]);
- last_non_zero= last_i - 1;
- memset(block + start_i, 0, (64-start_i)*sizeof(DCTELEM));
-
- if(last_non_zero < start_i)
- return last_non_zero;
-
- if(last_non_zero == 0 && start_i == 0){
- int best_level= 0;
- int best_score= dc * dc;
-
- for(i=0; i<coeff_count[0]; i++){
- int level= coeff[i][0];
- int alevel= FFABS(level);
- int unquant_coeff, score, distortion;
-
- if(s->out_format == FMT_H263){
- unquant_coeff= (alevel*qmul + qadd)>>3;
- }else{ //MPEG1
- unquant_coeff = ((( alevel << 1) + 1) * qscale * ((int) s->inter_matrix[0])) >> 4;
- unquant_coeff = (unquant_coeff - 1) | 1;
- }
- unquant_coeff = (unquant_coeff + 4) >> 3;
- unquant_coeff<<= 3 + 3;
-
- distortion= (unquant_coeff - dc) * (unquant_coeff - dc);
- level+=64;
- if((level&(~127)) == 0) score= distortion + last_length[UNI_AC_ENC_INDEX(0, level)]*lambda;
- else score= distortion + esc_length*lambda;
-
- if(score < best_score){
- best_score= score;
- best_level= level - 64;
- }
- }
- block[0]= best_level;
- s->coded_score[n] = best_score - dc*dc;
- if(best_level == 0) return -1;
- else return last_non_zero;
- }
-
- i= last_i;
- assert(last_level);
-
- block[ perm_scantable[last_non_zero] ]= last_level;
- i -= last_run + 1;
-
- for(; i>start_i; i -= run_tab[i] + 1){
- block[ perm_scantable[i-1] ]= level_tab[i];
- }
-
- return last_non_zero;
-}
-
-//#define REFINE_STATS 1
-static int16_t basis[64][64];
-
-static void build_basis(uint8_t *perm){
- int i, j, x, y;
- emms_c();
- for(i=0; i<8; i++){
- for(j=0; j<8; j++){
- for(y=0; y<8; y++){
- for(x=0; x<8; x++){
- double s= 0.25*(1<<BASIS_SHIFT);
- int index= 8*i + j;
- int perm_index= perm[index];
- if(i==0) s*= sqrt(0.5);
- if(j==0) s*= sqrt(0.5);
- basis[perm_index][8*x + y]= lrintf(s * cos((M_PI/8.0)*i*(x+0.5)) * cos((M_PI/8.0)*j*(y+0.5)));
- }
- }
- }
- }
-}
-
-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]);
- const int *qmat;
- const uint8_t *scantable= s->intra_scantable.scantable;
- const uint8_t *perm_scantable= s->intra_scantable.permutated;
-// unsigned int threshold1, threshold2;
-// int bias=0;
- int run_tab[65];
- int prev_run=0;
- int prev_level=0;
- int qmul, qadd, start_i, last_non_zero, i, dc;
- uint8_t * length;
- uint8_t * last_length;
- int lambda;
- int rle_index, run, q = 1, sum; //q is only used when s->mb_intra is true
-#ifdef REFINE_STATS
-static int count=0;
-static int after_last=0;
-static int to_zero=0;
-static int from_zero=0;
-static int raise=0;
-static int lower=0;
-static int messed_sign=0;
-#endif
-
- if(basis[0][0] == 0)
- build_basis(s->dsp.idct_permutation);
-
- qmul= qscale*2;
- qadd= (qscale-1)|1;
- if (s->mb_intra) {
- if (!s->h263_aic) {
- if (n < 4)
- q = s->y_dc_scale;
- else
- q = s->c_dc_scale;
- } else{
- /* For AIC we skip quant/dequant of INTRADC */
- q = 1;
- qadd=0;
- }
- q <<= RECON_SHIFT-3;
- /* note: block[0] is assumed to be positive */
- dc= block[0]*q;
-// block[0] = (block[0] + (q >> 1)) / q;
- start_i = 1;
- qmat = s->q_intra_matrix[qscale];
-// if(s->mpeg_quant || s->out_format == FMT_MPEG1)
-// bias= 1<<(QMAT_SHIFT-1);
- length = s->intra_ac_vlc_length;
- last_length= s->intra_ac_vlc_last_length;
- } else {
- dc= 0;
- start_i = 0;
- qmat = s->q_inter_matrix[qscale];
- length = s->inter_ac_vlc_length;
- last_length= s->inter_ac_vlc_last_length;
- }
- last_non_zero = s->block_last_index[n];
-
-#ifdef REFINE_STATS
-{START_TIMER
-#endif
- dc += (1<<(RECON_SHIFT-1));
- for(i=0; i<64; i++){
- rem[i]= dc - (orig[i]<<RECON_SHIFT); //FIXME use orig dirrectly instead of copying to rem[]
- }
-#ifdef REFINE_STATS
-STOP_TIMER("memset rem[]")}
-#endif
- sum=0;
- for(i=0; i<64; i++){
- int one= 36;
- int qns=4;
- int w;
-
- w= FFABS(weight[i]) + qns*one;
- w= 15 + (48*qns*one + w/2)/w; // 16 .. 63
-
- weight[i] = w;
-// w=weight[i] = (63*qns + (w/2)) / w;
-
- assert(w>0);
- assert(w<(1<<6));
- sum += w*w;
- }
- lambda= sum*(uint64_t)s->lambda2 >> (FF_LAMBDA_SHIFT - 6 + 6 + 6 + 6);
-#ifdef REFINE_STATS
-{START_TIMER
-#endif
- run=0;
- rle_index=0;
- for(i=start_i; i<=last_non_zero; i++){
- int j= perm_scantable[i];
- const int level= block[j];
- int coeff;
-
- if(level){
- if(level<0) coeff= qmul*level - qadd;
- else coeff= qmul*level + qadd;
- run_tab[rle_index++]=run;
- run=0;
-
- s->dsp.add_8x8basis(rem, basis[j], coeff);
- }else{
- run++;
- }
- }
-#ifdef REFINE_STATS
-if(last_non_zero>0){
-STOP_TIMER("init rem[]")
-}
-}
-
-{START_TIMER
-#endif
- for(;;){
- int best_score=s->dsp.try_8x8basis(rem, weight, basis[0], 0);
- int best_coeff=0;
- int best_change=0;
- int run2, best_unquant_change=0, analyze_gradient;
-#ifdef REFINE_STATS
-{START_TIMER
-#endif
- analyze_gradient = last_non_zero > 2 || s->avctx->quantizer_noise_shaping >= 3;
-
- if(analyze_gradient){
-#ifdef REFINE_STATS
-{START_TIMER
-#endif
- for(i=0; i<64; i++){
- int w= weight[i];
-
- d1[i] = (rem[i]*w*w + (1<<(RECON_SHIFT+12-1)))>>(RECON_SHIFT+12);
- }
-#ifdef REFINE_STATS
-STOP_TIMER("rem*w*w")}
-{START_TIMER
-#endif
- s->dsp.fdct(d1);
-#ifdef REFINE_STATS
-STOP_TIMER("dct")}
-#endif
- }
-
- if(start_i){
- const int level= block[0];
- int change, old_coeff;
-
- assert(s->mb_intra);
-
- old_coeff= q*level;
-
- for(change=-1; change<=1; change+=2){
- int new_level= level + change;
- int score, new_coeff;
-
- new_coeff= q*new_level;
- if(new_coeff >= 2048 || new_coeff < 0)
- continue;
-
- score= s->dsp.try_8x8basis(rem, weight, basis[0], new_coeff - old_coeff);
- if(score<best_score){
- best_score= score;
- best_coeff= 0;
- best_change= change;
- best_unquant_change= new_coeff - old_coeff;
- }
- }
- }
-
- run=0;
- rle_index=0;
- run2= run_tab[rle_index++];
- prev_level=0;
- prev_run=0;
-
- for(i=start_i; i<64; i++){
- int j= perm_scantable[i];
- const int level= block[j];
- int change, old_coeff;
-
- if(s->avctx->quantizer_noise_shaping < 3 && i > last_non_zero + 1)
- break;
-
- if(level){
- if(level<0) old_coeff= qmul*level - qadd;
- else old_coeff= qmul*level + qadd;
- run2= run_tab[rle_index++]; //FIXME ! maybe after last
- }else{
- old_coeff=0;
- run2--;
- assert(run2>=0 || i >= last_non_zero );
- }
-
- for(change=-1; change<=1; change+=2){
- int new_level= level + change;
- int score, new_coeff, unquant_change;
-
- score=0;
- if(s->avctx->quantizer_noise_shaping < 2 && FFABS(new_level) > FFABS(level))
- continue;
-
- if(new_level){
- if(new_level<0) new_coeff= qmul*new_level - qadd;
- else new_coeff= qmul*new_level + qadd;
- if(new_coeff >= 2048 || new_coeff <= -2048)
- continue;
- //FIXME check for overflow
-
- if(level){
- if(level < 63 && level > -63){
- if(i < last_non_zero)
- score += length[UNI_AC_ENC_INDEX(run, new_level+64)]
- - length[UNI_AC_ENC_INDEX(run, level+64)];
- else
- score += last_length[UNI_AC_ENC_INDEX(run, new_level+64)]
- - last_length[UNI_AC_ENC_INDEX(run, level+64)];
- }
- }else{
- assert(FFABS(new_level)==1);
-
- if(analyze_gradient){
- int g= d1[ scantable[i] ];
- if(g && (g^new_level) >= 0)
- continue;
- }
-
- if(i < last_non_zero){
- int next_i= i + run2 + 1;
- int next_level= block[ perm_scantable[next_i] ] + 64;
-
- if(next_level&(~127))
- next_level= 0;
-
- if(next_i < last_non_zero)
- score += length[UNI_AC_ENC_INDEX(run, 65)]
- + length[UNI_AC_ENC_INDEX(run2, next_level)]
- - length[UNI_AC_ENC_INDEX(run + run2 + 1, next_level)];
- else
- score += length[UNI_AC_ENC_INDEX(run, 65)]
- + last_length[UNI_AC_ENC_INDEX(run2, next_level)]
- - last_length[UNI_AC_ENC_INDEX(run + run2 + 1, next_level)];
- }else{
- score += last_length[UNI_AC_ENC_INDEX(run, 65)];
- if(prev_level){
- score += length[UNI_AC_ENC_INDEX(prev_run, prev_level)]
- - last_length[UNI_AC_ENC_INDEX(prev_run, prev_level)];
- }
- }
- }
- }else{
- new_coeff=0;
- assert(FFABS(level)==1);
-
- if(i < last_non_zero){
- int next_i= i + run2 + 1;
- int next_level= block[ perm_scantable[next_i] ] + 64;
-
- if(next_level&(~127))
- next_level= 0;
-
- if(next_i < last_non_zero)
- score += length[UNI_AC_ENC_INDEX(run + run2 + 1, next_level)]
- - length[UNI_AC_ENC_INDEX(run2, next_level)]
- - length[UNI_AC_ENC_INDEX(run, 65)];
- else
- score += last_length[UNI_AC_ENC_INDEX(run + run2 + 1, next_level)]
- - last_length[UNI_AC_ENC_INDEX(run2, next_level)]
- - length[UNI_AC_ENC_INDEX(run, 65)];
- }else{
- score += -last_length[UNI_AC_ENC_INDEX(run, 65)];
- if(prev_level){
- score += last_length[UNI_AC_ENC_INDEX(prev_run, prev_level)]
- - length[UNI_AC_ENC_INDEX(prev_run, prev_level)];
- }
- }
- }
-
- score *= lambda;
-
- unquant_change= new_coeff - old_coeff;
- assert((score < 100*lambda && score > -100*lambda) || lambda==0);
-
- score+= s->dsp.try_8x8basis(rem, weight, basis[j], unquant_change);
- if(score<best_score){
- best_score= score;
- best_coeff= i;
- best_change= change;
- best_unquant_change= unquant_change;
- }
- }
- if(level){
- prev_level= level + 64;
- if(prev_level&(~127))
- prev_level= 0;
- prev_run= run;
- run=0;
- }else{
- run++;
- }
- }
-#ifdef REFINE_STATS
-STOP_TIMER("iterative step")}
-#endif
-
- if(best_change){
- int j= perm_scantable[ best_coeff ];
-
- block[j] += best_change;
-
- if(best_coeff > last_non_zero){
- last_non_zero= best_coeff;
- assert(block[j]);
-#ifdef REFINE_STATS
-after_last++;
-#endif
- }else{
-#ifdef REFINE_STATS
-if(block[j]){
- if(block[j] - best_change){
- if(FFABS(block[j]) > FFABS(block[j] - best_change)){
- raise++;
- }else{
- lower++;
- }
- }else{
- from_zero++;
- }
-}else{
- to_zero++;
-}
-#endif
- for(; last_non_zero>=start_i; last_non_zero--){
- if(block[perm_scantable[last_non_zero]])
- break;
- }
- }
-#ifdef REFINE_STATS
-count++;
-if(256*256*256*64 % count == 0){
- printf("after_last:%d to_zero:%d from_zero:%d raise:%d lower:%d sign:%d xyp:%d/%d/%d\n", after_last, to_zero, from_zero, raise, lower, messed_sign, s->mb_x, s->mb_y, s->picture_number);
-}
-#endif
- run=0;
- rle_index=0;
- for(i=start_i; i<=last_non_zero; i++){
- int j= perm_scantable[i];
- const int level= block[j];
-
- if(level){
- run_tab[rle_index++]=run;
- run=0;
- }else{
- run++;
- }
- }
-
- s->dsp.add_8x8basis(rem, basis[j], best_unquant_change);
- }else{
- break;
- }
- }
-#ifdef REFINE_STATS
-if(last_non_zero>0){
-STOP_TIMER("iterative search")
-}
-}
-#endif
-
- return last_non_zero;
-}
-
-static int dct_quantize_c(MpegEncContext *s,
- DCTELEM *block, int n,
- int qscale, int *overflow)
-{
- int i, j, level, last_non_zero, q, start_i;
- const int *qmat;
- const uint8_t *scantable= s->intra_scantable.scantable;
- int bias;
- int max=0;
- unsigned int threshold1, threshold2;
-
- s->dsp.fdct (block);
-
- if(s->dct_error_sum)
- s->denoise_dct(s, block);
-
- if (s->mb_intra) {
- if (!s->h263_aic) {
- if (n < 4)
- q = s->y_dc_scale;
- else
- q = s->c_dc_scale;
- q = q << 3;
- } else
- /* For AIC we skip quant/dequant of INTRADC */
- q = 1 << 3;
-
- /* note: block[0] is assumed to be positive */
- block[0] = (block[0] + (q >> 1)) / q;
- start_i = 1;
- last_non_zero = 0;
- qmat = s->q_intra_matrix[qscale];
- bias= s->intra_quant_bias<<(QMAT_SHIFT - QUANT_BIAS_SHIFT);
- } else {
- start_i = 0;
- last_non_zero = -1;
- qmat = s->q_inter_matrix[qscale];
- bias= s->inter_quant_bias<<(QMAT_SHIFT - QUANT_BIAS_SHIFT);
- }
- threshold1= (1<<QMAT_SHIFT) - bias - 1;
- threshold2= (threshold1<<1);
- for(i=63;i>=start_i;i--) {
- j = scantable[i];
- level = block[j] * qmat[j];
-
- if(((unsigned)(level+threshold1))>threshold2){
- last_non_zero = i;
- break;
- }else{
- block[j]=0;
- }
- }
- for(i=start_i; i<=last_non_zero; i++) {
- j = scantable[i];
- level = block[j] * qmat[j];
-
-// if( bias+level >= (1<<QMAT_SHIFT)
-// || bias-level >= (1<<QMAT_SHIFT)){
- if(((unsigned)(level+threshold1))>threshold2){
- if(level>0){
- level= (bias + level)>>QMAT_SHIFT;
- block[j]= level;
- }else{
- level= (bias - level)>>QMAT_SHIFT;
- block[j]= -level;
- }
- max |=level;
- }else{
- block[j]=0;
- }
- }
- *overflow= s->max_qcoeff < max; //overflow might have happened
-
- /* we need this permutation so that we correct the IDCT, we only permute the !=0 elements */
- if (s->dsp.idct_permutation_type != FF_NO_IDCT_PERM)
- ff_block_permute(block, s->dsp.idct_permutation, scantable, last_non_zero);
-
- return last_non_zero;
-}
-
-#endif //CONFIG_ENCODERS
-
-static void dct_unquantize_mpeg1_intra_c(MpegEncContext *s,
- DCTELEM *block, int n, int qscale)
-{
- int i, level, nCoeffs;
- const uint16_t *quant_matrix;
-
- nCoeffs= s->block_last_index[n];
-
- if (n < 4)
- block[0] = block[0] * s->y_dc_scale;
- else
- block[0] = block[0] * s->c_dc_scale;
- /* XXX: only mpeg1 */
- quant_matrix = s->intra_matrix;
- for(i=1;i<=nCoeffs;i++) {
- int j= s->intra_scantable.permutated[i];
- level = block[j];
- if (level) {
- if (level < 0) {
- level = -level;
- level = (int)(level * qscale * quant_matrix[j]) >> 3;
- level = (level - 1) | 1;
- level = -level;
- } else {
- level = (int)(level * qscale * quant_matrix[j]) >> 3;
- level = (level - 1) | 1;
- }
- block[j] = level;
- }
- }
-}
-
-static void dct_unquantize_mpeg1_inter_c(MpegEncContext *s,
- DCTELEM *block, int n, int qscale)
-{
- int i, level, nCoeffs;
- const uint16_t *quant_matrix;
-
- nCoeffs= s->block_last_index[n];
-
- quant_matrix = s->inter_matrix;
- for(i=0; i<=nCoeffs; i++) {
- int j= s->intra_scantable.permutated[i];
- level = block[j];
- if (level) {
- if (level < 0) {
- level = -level;
- level = (((level << 1) + 1) * qscale *
- ((int) (quant_matrix[j]))) >> 4;
- level = (level - 1) | 1;
- level = -level;
- } else {
- level = (((level << 1) + 1) * qscale *
- ((int) (quant_matrix[j]))) >> 4;
- level = (level - 1) | 1;
- }
- block[j] = level;
- }
- }
-}
-
-static void dct_unquantize_mpeg2_intra_c(MpegEncContext *s,
- DCTELEM *block, int n, int qscale)
-{
- int i, level, nCoeffs;
- const uint16_t *quant_matrix;
-
- if(s->alternate_scan) nCoeffs= 63;
- else nCoeffs= s->block_last_index[n];
-
- if (n < 4)
- block[0] = block[0] * s->y_dc_scale;
- else
- block[0] = block[0] * s->c_dc_scale;
- quant_matrix = s->intra_matrix;
- for(i=1;i<=nCoeffs;i++) {
- int j= s->intra_scantable.permutated[i];
- level = block[j];
- if (level) {
- if (level < 0) {
- level = -level;
- level = (int)(level * qscale * quant_matrix[j]) >> 3;
- level = -level;
- } else {
- level = (int)(level * qscale * quant_matrix[j]) >> 3;
- }
- block[j] = level;
- }
- }
-}
-
-static void dct_unquantize_mpeg2_intra_bitexact(MpegEncContext *s,
- DCTELEM *block, int n, int qscale)
-{
- int i, level, nCoeffs;
- const uint16_t *quant_matrix;
- int sum=-1;
-
- if(s->alternate_scan) nCoeffs= 63;
- else nCoeffs= s->block_last_index[n];
-
- if (n < 4)
- block[0] = block[0] * s->y_dc_scale;
- else
- block[0] = block[0] * s->c_dc_scale;
- quant_matrix = s->intra_matrix;
- for(i=1;i<=nCoeffs;i++) {
- int j= s->intra_scantable.permutated[i];
- level = block[j];
- if (level) {
- if (level < 0) {
- level = -level;
- level = (int)(level * qscale * quant_matrix[j]) >> 3;
- level = -level;
- } else {
- level = (int)(level * qscale * quant_matrix[j]) >> 3;
- }
- block[j] = level;
- sum+=level;
- }
- }
- block[63]^=sum&1;
-}
-
-static void dct_unquantize_mpeg2_inter_c(MpegEncContext *s,
- DCTELEM *block, int n, int qscale)
-{
- int i, level, nCoeffs;
- const uint16_t *quant_matrix;
- int sum=-1;
-
- if(s->alternate_scan) nCoeffs= 63;
- else nCoeffs= s->block_last_index[n];
-
- quant_matrix = s->inter_matrix;
- for(i=0; i<=nCoeffs; i++) {
- int j= s->intra_scantable.permutated[i];
- level = block[j];
- if (level) {
- if (level < 0) {
- level = -level;
- level = (((level << 1) + 1) * qscale *
- ((int) (quant_matrix[j]))) >> 4;
- level = -level;
- } else {
- level = (((level << 1) + 1) * qscale *
- ((int) (quant_matrix[j]))) >> 4;
- }
- block[j] = level;
- sum+=level;
- }
- }
- block[63]^=sum&1;
-}
-
-static void dct_unquantize_h263_intra_c(MpegEncContext *s,
- DCTELEM *block, int n, int qscale)
-{
- int i, level, qmul, qadd;
- int nCoeffs;
-
- assert(s->block_last_index[n]>=0);
-
- qmul = qscale << 1;
-
- if (!s->h263_aic) {
- if (n < 4)
- block[0] = block[0] * s->y_dc_scale;
- else
- block[0] = block[0] * s->c_dc_scale;
- qadd = (qscale - 1) | 1;
- }else{
- qadd = 0;
- }
- if(s->ac_pred)
- nCoeffs=63;
- else
- nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];
-
- for(i=1; i<=nCoeffs; i++) {
- level = block[i];
- if (level) {
- if (level < 0) {
- level = level * qmul - qadd;
- } else {
- level = level * qmul + qadd;
- }
- block[i] = level;
- }
- }
-}
-
-static void dct_unquantize_h263_inter_c(MpegEncContext *s,
- DCTELEM *block, int n, int qscale)
-{
- int i, level, qmul, qadd;
- int nCoeffs;
-
- assert(s->block_last_index[n]>=0);
-
- qadd = (qscale - 1) | 1;
- qmul = qscale << 1;
-
- nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];
-
- for(i=0; i<=nCoeffs; i++) {
- level = block[i];
- if (level) {
- if (level < 0) {
- level = level * qmul - qadd;
- } else {
- level = level * qmul + qadd;
- }
- block[i] = level;
- }
- }
-}
-
-#ifdef CONFIG_ENCODERS
-AVCodec h263_encoder = {
- "h263",
- CODEC_TYPE_VIDEO,
- CODEC_ID_H263,
- sizeof(MpegEncContext),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
- .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1},
-};
-
-AVCodec h263p_encoder = {
- "h263p",
- CODEC_TYPE_VIDEO,
- CODEC_ID_H263P,
- sizeof(MpegEncContext),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
- .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1},
-};
-
-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, -1},
-};
-
-AVCodec rv10_encoder = {
- "rv10",
- CODEC_TYPE_VIDEO,
- CODEC_ID_RV10,
- sizeof(MpegEncContext),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
- .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1},
-};
-
-AVCodec rv20_encoder = {
- "rv20",
- CODEC_TYPE_VIDEO,
- CODEC_ID_RV20,
- sizeof(MpegEncContext),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
- .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1},
-};
-
-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, -1},
- .capabilities= CODEC_CAP_DELAY,
-};
-
-AVCodec msmpeg4v1_encoder = {
- "msmpeg4v1",
- CODEC_TYPE_VIDEO,
- CODEC_ID_MSMPEG4V1,
- sizeof(MpegEncContext),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
- .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1},
-};
-
-AVCodec msmpeg4v2_encoder = {
- "msmpeg4v2",
- CODEC_TYPE_VIDEO,
- CODEC_ID_MSMPEG4V2,
- sizeof(MpegEncContext),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
- .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1},
-};
-
-AVCodec msmpeg4v3_encoder = {
- "msmpeg4",
- CODEC_TYPE_VIDEO,
- CODEC_ID_MSMPEG4V3,
- sizeof(MpegEncContext),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
- .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1},
-};
-
-AVCodec wmv1_encoder = {
- "wmv1",
- CODEC_TYPE_VIDEO,
- CODEC_ID_WMV1,
- sizeof(MpegEncContext),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
- .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1},
-};
-
-AVCodec mjpeg_encoder = {
- "mjpeg",
- CODEC_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, -1},
-};
-
-#endif //CONFIG_ENCODERS
diff --git a/src/libffmpeg/libavcodec/mpegvideo.h b/src/libffmpeg/libavcodec/mpegvideo.h
deleted file mode 100644
index ed02759ae..000000000
--- a/src/libffmpeg/libavcodec/mpegvideo.h
+++ /dev/null
@@ -1,931 +0,0 @@
-/*
- * Generic DCT based hybrid video encoder
- * 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
- */
-
-/**
- * @file mpegvideo.h
- * mpegvideo header.
- */
-
-#ifndef AVCODEC_MPEGVIDEO_H
-#define AVCODEC_MPEGVIDEO_H
-
-#include "dsputil.h"
-#include "bitstream.h"
-#include "ratecontrol.h"
-#include "parser.h"
-
-#define FRAME_SKIPPED 100 ///< return value for header parsers if frame is not coded
-
-enum OutputFormat {
- FMT_MPEG1,
- FMT_H261,
- FMT_H263,
- FMT_MJPEG,
- FMT_H264,
-};
-
-#define EDGE_WIDTH 16
-
-#define MPEG_BUF_SIZE (16 * 1024)
-
-#define QMAT_SHIFT_MMX 16
-#define QMAT_SHIFT 22
-
-#define MAX_FCODE 7
-#define MAX_MV 2048
-
-#define MAX_THREADS 8
-
-#define MAX_PICTURE_COUNT 32
-
-#define ME_MAP_SIZE 64
-#define ME_MAP_SHIFT 3
-#define ME_MAP_MV_BITS 11
-
-/* run length table */
-#define MAX_RUN 64
-#define MAX_LEVEL 64
-
-#define I_TYPE FF_I_TYPE ///< Intra
-#define P_TYPE FF_P_TYPE ///< Predicted
-#define B_TYPE FF_B_TYPE ///< Bi-dir predicted
-#define S_TYPE FF_S_TYPE ///< S(GMC)-VOP MPEG4
-#define SI_TYPE FF_SI_TYPE ///< Switching Intra
-#define SP_TYPE FF_SP_TYPE ///< Switching Predicted
-
-#define MAX_MB_BYTES (30*16*16*3/8 + 120)
-
-#define INPLACE_OFFSET 16
-
-/**
- * Scantable.
- */
-typedef struct ScanTable{
- const uint8_t *scantable;
- uint8_t permutated[64];
- uint8_t raster_end[64];
-#ifdef ARCH_POWERPC
- /** Used by dct_quantise_alitvec to find last-non-zero */
- DECLARE_ALIGNED_8(uint8_t, inverse[64]);
-#endif
-} ScanTable;
-
-/**
- * Picture.
- */
-typedef struct Picture{
- FF_COMMON_FRAME
-
- /**
- * halfpel luma planes.
- */
- uint8_t *interpolated[3];
- int16_t (*motion_val_base[2])[2];
- uint32_t *mb_type_base;
-#define MB_TYPE_INTRA MB_TYPE_INTRA4x4 //default mb_type if theres just one type
-#define IS_INTRA4x4(a) ((a)&MB_TYPE_INTRA4x4)
-#define IS_INTRA16x16(a) ((a)&MB_TYPE_INTRA16x16)
-#define IS_PCM(a) ((a)&MB_TYPE_INTRA_PCM)
-#define IS_INTRA(a) ((a)&7)
-#define IS_INTER(a) ((a)&(MB_TYPE_16x16|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_8x8))
-#define IS_SKIP(a) ((a)&MB_TYPE_SKIP)
-#define IS_INTRA_PCM(a) ((a)&MB_TYPE_INTRA_PCM)
-#define IS_INTERLACED(a) ((a)&MB_TYPE_INTERLACED)
-#define IS_DIRECT(a) ((a)&MB_TYPE_DIRECT2)
-#define IS_GMC(a) ((a)&MB_TYPE_GMC)
-#define IS_16X16(a) ((a)&MB_TYPE_16x16)
-#define IS_16X8(a) ((a)&MB_TYPE_16x8)
-#define IS_8X16(a) ((a)&MB_TYPE_8x16)
-#define IS_8X8(a) ((a)&MB_TYPE_8x8)
-#define IS_SUB_8X8(a) ((a)&MB_TYPE_16x16) //note reused
-#define IS_SUB_8X4(a) ((a)&MB_TYPE_16x8) //note reused
-#define IS_SUB_4X8(a) ((a)&MB_TYPE_8x16) //note reused
-#define IS_SUB_4X4(a) ((a)&MB_TYPE_8x8) //note reused
-#define IS_ACPRED(a) ((a)&MB_TYPE_ACPRED)
-#define IS_QUANT(a) ((a)&MB_TYPE_QUANT)
-#define IS_DIR(a, part, list) ((a) & (MB_TYPE_P0L0<<((part)+2*(list))))
-#define USES_LIST(a, list) ((a) & ((MB_TYPE_P0L0|MB_TYPE_P1L0)<<(2*(list)))) ///< does this mb use listX, note doesnt work if subMBs
-#define HAS_CBP(a) ((a)&MB_TYPE_CBP)
-
- int field_poc[2]; ///< h264 top/bottom POC
- int poc; ///< h264 frame POC
- int frame_num; ///< h264 frame_num
- int pic_id; ///< h264 pic_num or long_term_pic_idx
- int long_ref; ///< 1->long term reference 0->short term reference
- int ref_poc[2][16]; ///< h264 POCs of the frames used as reference
- int ref_count[2]; ///< number of entries in ref_poc
-
- int mb_var_sum; ///< sum of MB variance for current frame
- int mc_mb_var_sum; ///< motion compensated MB variance for current frame
- uint16_t *mb_var; ///< Table for MB variances
- uint16_t *mc_mb_var; ///< Table for motion compensated MB variances
- uint8_t *mb_mean; ///< Table for MB luminance
- int32_t *mb_cmp_score; ///< Table for MB cmp scores, for mb decision FIXME remove
- int b_frame_score; /* */
-} Picture;
-
-struct MpegEncContext;
-
-/**
- * Motion estimation context.
- */
-typedef struct MotionEstContext{
- AVCodecContext *avctx;
- int skip; ///< set if ME is skipped for the current MB
- int co_located_mv[4][2]; ///< mv from last p frame for direct mode ME
- int direct_basis_mv[4][2];
- uint8_t *scratchpad; ///< data area for the me algo, so that the ME doesnt need to malloc/free
- uint8_t *best_mb;
- uint8_t *temp_mb[2];
- uint8_t *temp;
- int best_bits;
- uint32_t *map; ///< map to avoid duplicate evaluations
- uint32_t *score_map; ///< map to store the scores
- int map_generation;
- int pre_penalty_factor;
- int penalty_factor;
- int sub_penalty_factor;
- int mb_penalty_factor;
- int flags;
- int sub_flags;
- int mb_flags;
- int pre_pass; ///< = 1 for the pre pass
- int dia_size;
- int xmin;
- int xmax;
- int ymin;
- int ymax;
- int pred_x;
- int pred_y;
- uint8_t *src[4][4];
- uint8_t *ref[4][4];
- int stride;
- int uvstride;
- /* temp variables for picture complexity calculation */
- int mc_mb_var_sum_temp;
- int mb_var_sum_temp;
- int scene_change_score;
-/* cmp, chroma_cmp;*/
- op_pixels_func (*hpel_put)[4];
- op_pixels_func (*hpel_avg)[4];
- qpel_mc_func (*qpel_put)[16];
- qpel_mc_func (*qpel_avg)[16];
- uint8_t (*mv_penalty)[MAX_MV*2+1]; ///< amount of bits needed to encode a MV
- uint8_t *current_mv_penalty;
- int (*sub_motion_search)(struct MpegEncContext * s,
- int *mx_ptr, int *my_ptr, int dmin,
- int src_index, int ref_index,
- int size, int h);
-}MotionEstContext;
-
-/**
- * MpegEncContext.
- */
-typedef struct MpegEncContext {
- struct AVCodecContext *avctx;
- /* the following parameters must be initialized before encoding */
- int width, height;///< picture size. must be a multiple of 16
- int gop_size;
- int intra_only; ///< if true, only intra pictures are generated
- int bit_rate; ///< wanted bit rate
- enum OutputFormat out_format; ///< output format
- int h263_pred; ///< use mpeg4/h263 ac/dc predictions
-
-/* the following codec id fields are deprecated in favor of codec_id */
- int h263_plus; ///< h263 plus headers
- int h263_msmpeg4; ///< generate MSMPEG4 compatible stream (deprecated, use msmpeg4_version instead)
- int h263_flv; ///< use flv h263 header
-
- enum CodecID codec_id; /* see CODEC_ID_xxx */
- int fixed_qscale; ///< fixed qscale if non zero
- int encoding; ///< true if we are encoding (vs decoding)
- int flags; ///< AVCodecContext.flags (HQ, MV4, ...)
- int flags2; ///< AVCodecContext.flags2
- int max_b_frames; ///< max number of b-frames for encoding
- int luma_elim_threshold;
- int chroma_elim_threshold;
- int strict_std_compliance; ///< strictly follow the std (MPEG4, ...)
- int workaround_bugs; ///< workaround bugs in encoders which cannot be detected automatically
- int codec_tag; ///< internal codec_tag upper case converted from avctx codec_tag
- int stream_codec_tag; ///< internal stream_codec_tag upper case converted from avctx stream_codec_tag
- /* the following fields are managed internally by the encoder */
-
- /** bit output */
- PutBitContext pb;
-
- /* sequence parameters */
- int context_initialized;
- int input_picture_number; ///< used to set pic->display_picture_number, shouldnt be used for/by anything else
- int coded_picture_number; ///< used to set pic->coded_picture_number, shouldnt be used for/by anything else
- int picture_number; //FIXME remove, unclear definition
- int picture_in_gop_number; ///< 0-> first pic in gop, ...
- int b_frames_since_non_b; ///< used for encoding, relative to not yet reordered input
- int64_t user_specified_pts;///< last non zero pts from AVFrame which was passed into avcodec_encode_video()
- int mb_width, mb_height; ///< number of MBs horizontally & vertically
- int mb_stride; ///< mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11
- int b8_stride; ///< 2*mb_width+1 used for some 8x8 block arrays to allow simple addressing
- int b4_stride; ///< 4*mb_width+1 used for some 4x4 block arrays to allow simple addressing
- int h_edge_pos, v_edge_pos;///< horizontal / vertical position of the right/bottom edge (pixel replication)
- int mb_num; ///< number of MBs of a picture
- int linesize; ///< line size, in bytes, may be different from width
- int uvlinesize; ///< line size, for chroma in bytes, may be different from width
- Picture *picture; ///< main picture buffer
- Picture **input_picture; ///< next pictures on display order for encoding
- Picture **reordered_input_picture; ///< pointer to the next pictures in codedorder for encoding
-
- int start_mb_y; ///< start mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y)
- int end_mb_y; ///< end mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y)
- struct MpegEncContext *thread_context[MAX_THREADS];
-
- /**
- * copy of the previous picture structure.
- * note, linesize & data, might not match the previous picture (for field pictures)
- */
- Picture last_picture;
-
- /**
- * copy of the next picture structure.
- * note, linesize & data, might not match the next picture (for field pictures)
- */
- Picture next_picture;
-
- /**
- * copy of the source picture structure for encoding.
- * note, linesize & data, might not match the source picture (for field pictures)
- */
- Picture new_picture;
-
- /**
- * copy of the current picture structure.
- * note, linesize & data, might not match the current picture (for field pictures)
- */
- Picture current_picture; ///< buffer to store the decompressed current picture
-
- Picture *last_picture_ptr; ///< pointer to the previous picture.
- Picture *next_picture_ptr; ///< pointer to the next picture (for bidir pred)
- Picture *current_picture_ptr; ///< pointer to the current picture
- uint8_t *visualization_buffer[3]; //< temporary buffer vor MV visualization
- int last_dc[3]; ///< last DC values for MPEG1
- int16_t *dc_val_base;
- int16_t *dc_val[3]; ///< used for mpeg4 DC prediction, all 3 arrays must be continuous
- int16_t dc_cache[4*5];
- int y_dc_scale, c_dc_scale;
- const uint8_t *y_dc_scale_table; ///< qscale -> y_dc_scale table
- const uint8_t *c_dc_scale_table; ///< qscale -> c_dc_scale table
- const uint8_t *chroma_qscale_table; ///< qscale -> chroma_qscale (h263)
- uint8_t *coded_block_base;
- uint8_t *coded_block; ///< used for coded block pattern prediction (msmpeg4v3, wmv1)
- int16_t (*ac_val_base)[16];
- int16_t (*ac_val[3])[16]; ///< used for for mpeg4 AC prediction, all 3 arrays must be continuous
- int ac_pred;
- uint8_t *prev_pict_types; ///< previous picture types in bitstream order, used for mb skip
-#define PREV_PICT_TYPES_BUFFER_SIZE 256
- int mb_skipped; ///< MUST BE SET only during DECODING
- uint8_t *mbskip_table; /**< used to avoid copy if macroblock skipped (for black regions for example)
- and used for b-frame encoding & decoding (contains skip table of next P Frame) */
- uint8_t *mbintra_table; ///< used to avoid setting {ac, dc, cbp}-pred stuff to zero on inter MB decoding
- uint8_t *cbp_table; ///< used to store cbp, ac_pred for partitioned decoding
- uint8_t *pred_dir_table; ///< used to store pred_dir for partitioned decoding
- uint8_t *allocated_edge_emu_buffer;
- uint8_t *edge_emu_buffer; ///< points into the middle of allocated_edge_emu_buffer
- uint8_t *rd_scratchpad; ///< scratchpad for rate distortion mb decision
- uint8_t *obmc_scratchpad;
- uint8_t *b_scratchpad; ///< scratchpad used for writing into write only buffers
-
- int qscale; ///< QP
- int chroma_qscale; ///< chroma QP
- unsigned int lambda; ///< lagrange multipler used in rate distortion
- unsigned int lambda2; ///< (lambda*lambda) >> FF_LAMBDA_SHIFT
- int *lambda_table;
- int adaptive_quant; ///< use adaptive quantization
- int dquant; ///< qscale difference to prev qscale
- int pict_type; ///< I_TYPE, P_TYPE, B_TYPE, ...
- int last_pict_type; //FIXME removes
- int last_non_b_pict_type; ///< used for mpeg4 gmc b-frames & ratecontrol
- int dropable;
- int frame_rate_index;
- int last_lambda_for[5]; ///< last lambda for a specific pict type
- int skipdct; ///< skip dct and code zero residual
-
- /* motion compensation */
- int unrestricted_mv; ///< mv can point outside of the coded picture
- int h263_long_vectors; ///< use horrible h263v1 long vector mode
- int decode; ///< if 0 then decoding will be skipped (for encoding b frames for example)
-
- DSPContext dsp; ///< pointers for accelerated dsp functions
- int f_code; ///< forward MV resolution
- int b_code; ///< backward MV resolution for B Frames (mpeg4)
- int16_t (*p_mv_table_base)[2];
- int16_t (*b_forw_mv_table_base)[2];
- int16_t (*b_back_mv_table_base)[2];
- int16_t (*b_bidir_forw_mv_table_base)[2];
- int16_t (*b_bidir_back_mv_table_base)[2];
- int16_t (*b_direct_mv_table_base)[2];
- int16_t (*p_field_mv_table_base[2][2])[2];
- int16_t (*b_field_mv_table_base[2][2][2])[2];
- int16_t (*p_mv_table)[2]; ///< MV table (1MV per MB) p-frame encoding
- int16_t (*b_forw_mv_table)[2]; ///< MV table (1MV per MB) forward mode b-frame encoding
- int16_t (*b_back_mv_table)[2]; ///< MV table (1MV per MB) backward mode b-frame encoding
- int16_t (*b_bidir_forw_mv_table)[2]; ///< MV table (1MV per MB) bidir mode b-frame encoding
- int16_t (*b_bidir_back_mv_table)[2]; ///< MV table (1MV per MB) bidir mode b-frame encoding
- int16_t (*b_direct_mv_table)[2]; ///< MV table (1MV per MB) direct mode b-frame encoding
- int16_t (*p_field_mv_table[2][2])[2]; ///< MV table (2MV per MB) interlaced p-frame encoding
- int16_t (*b_field_mv_table[2][2][2])[2];///< MV table (4MV per MB) interlaced b-frame encoding
- uint8_t (*p_field_select_table[2]);
- uint8_t (*b_field_select_table[2][2]);
- int me_method; ///< ME algorithm
- int mv_dir;
-#define MV_DIR_BACKWARD 1
-#define MV_DIR_FORWARD 2
-#define MV_DIRECT 4 ///< bidirectional mode where the difference equals the MV of the last P/S/I-Frame (mpeg4)
- int mv_type;
-#define MV_TYPE_16X16 0 ///< 1 vector for the whole mb
-#define MV_TYPE_8X8 1 ///< 4 vectors (h263, mpeg4 4MV)
-#define MV_TYPE_16X8 2 ///< 2 vectors, one per 16x8 block
-#define MV_TYPE_FIELD 3 ///< 2 vectors, one per field
-#define MV_TYPE_DMV 4 ///< 2 vectors, special mpeg2 Dual Prime Vectors
- /**motion vectors for a macroblock
- first coordinate : 0 = forward 1 = backward
- second " : depend on type
- third " : 0 = x, 1 = y
- */
- int mv[2][4][2];
- int field_select[2][2];
- int last_mv[2][2][2]; ///< last MV, used for MV prediction in MPEG1 & B-frame MPEG4
- uint8_t *fcode_tab; ///< smallest fcode needed for each MV
- int16_t direct_scale_mv[2][64]; ///< precomputed to avoid divisions in ff_mpeg4_set_direct_mv
-
- MotionEstContext me;
-
- int no_rounding; /**< apply no rounding to motion compensation (MPEG4, msmpeg4, ...)
- for b-frames rounding mode is allways 0 */
-
- int hurry_up; /**< when set to 1 during decoding, b frames will be skipped
- when set to 2 idct/dequant will be skipped too */
-
- /* macroblock layer */
- int mb_x, mb_y;
- int mb_skip_run;
- int mb_intra;
- uint16_t *mb_type; ///< Table for candidate MB types for encoding
-#define CANDIDATE_MB_TYPE_INTRA 0x01
-#define CANDIDATE_MB_TYPE_INTER 0x02
-#define CANDIDATE_MB_TYPE_INTER4V 0x04
-#define CANDIDATE_MB_TYPE_SKIPPED 0x08
-//#define MB_TYPE_GMC 0x10
-
-#define CANDIDATE_MB_TYPE_DIRECT 0x10
-#define CANDIDATE_MB_TYPE_FORWARD 0x20
-#define CANDIDATE_MB_TYPE_BACKWARD 0x40
-#define CANDIDATE_MB_TYPE_BIDIR 0x80
-
-#define CANDIDATE_MB_TYPE_INTER_I 0x100
-#define CANDIDATE_MB_TYPE_FORWARD_I 0x200
-#define CANDIDATE_MB_TYPE_BACKWARD_I 0x400
-#define CANDIDATE_MB_TYPE_BIDIR_I 0x800
-
-#define CANDIDATE_MB_TYPE_DIRECT0 0x1000
-
- int block_index[6]; ///< index to current MB in block based arrays with edges
- int block_wrap[6];
- uint8_t *dest[3];
-
- int *mb_index2xy; ///< mb_index -> mb_x + mb_y*mb_stride
-
- /** matrix transmitted in the bitstream */
- uint16_t intra_matrix[64];
- uint16_t chroma_intra_matrix[64];
- uint16_t inter_matrix[64];
- uint16_t chroma_inter_matrix[64];
-#define QUANT_BIAS_SHIFT 8
- int intra_quant_bias; ///< bias for the quantizer
- int inter_quant_bias; ///< bias for the quantizer
- int min_qcoeff; ///< minimum encodable coefficient
- int max_qcoeff; ///< maximum encodable coefficient
- int ac_esc_length; ///< num of bits needed to encode the longest esc
- uint8_t *intra_ac_vlc_length;
- uint8_t *intra_ac_vlc_last_length;
- uint8_t *inter_ac_vlc_length;
- uint8_t *inter_ac_vlc_last_length;
- uint8_t *luma_dc_vlc_length;
- uint8_t *chroma_dc_vlc_length;
-#define UNI_AC_ENC_INDEX(run,level) ((run)*128 + (level))
-
- int coded_score[8];
-
- /** precomputed matrix (combine qscale and DCT renorm) */
- int (*q_intra_matrix)[64];
- int (*q_inter_matrix)[64];
- /** identical to the above but for MMX & these are not permutated, second 64 entries are bias*/
- uint16_t (*q_intra_matrix16)[2][64];
- uint16_t (*q_inter_matrix16)[2][64];
- int block_last_index[12]; ///< last non zero coefficient in block
- /* scantables */
- DECLARE_ALIGNED_8(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
-
- /* noise reduction */
- int (*dct_error_sum)[64];
- int dct_count[2];
- uint16_t (*dct_offset)[64];
-
- void *opaque; ///< private data for the user
-
- /* bit rate control */
- int64_t wanted_bits;
- int64_t total_bits;
- int frame_bits; ///< bits used for the current frame
- int next_lambda; ///< next lambda used for retrying to encode a frame
- RateControlContext rc_context; ///< contains stuff only accessed in ratecontrol.c
-
- /* statistics, used for 2-pass encoding */
- int mv_bits;
- int header_bits;
- int i_tex_bits;
- int p_tex_bits;
- int i_count;
- int f_count;
- int b_count;
- int skip_count;
- int misc_bits; ///< cbp, mb_type
- int last_bits; ///< temp var used for calculating the above vars
-
- /* error concealment / resync */
- int error_count;
- uint8_t *error_status_table; ///< table of the error status of each MB
-#define VP_START 1 ///< current MB is the first after a resync marker
-#define AC_ERROR 2
-#define DC_ERROR 4
-#define MV_ERROR 8
-#define AC_END 16
-#define DC_END 32
-#define MV_END 64
-//FIXME some prefix?
-
- int resync_mb_x; ///< x position of last resync marker
- int resync_mb_y; ///< y position of last resync marker
- GetBitContext last_resync_gb; ///< used to search for the next resync marker
- int mb_num_left; ///< number of MBs left in this video packet (for partitioned Slices only)
- int next_p_frame_damaged; ///< set if the next p frame is damaged, to avoid showing trashed b frames
- int error_resilience;
-
- ParseContext parse_context;
-
- /* H.263 specific */
- int gob_index;
- int obmc; ///< overlapped block motion compensation
-
- /* H.263+ specific */
- int umvplus; ///< == H263+ && unrestricted_mv
- int h263_aic; ///< Advanded INTRA Coding (AIC)
- int h263_aic_dir; ///< AIC direction: 0 = left, 1 = top
- int h263_slice_structured;
- int alt_inter_vlc; ///< alternative inter vlc
- int modified_quant;
- int loop_filter;
- int custom_pcf;
-
- /* mpeg4 specific */
- int time_increment_bits; ///< number of bits to represent the fractional part of time
- int last_time_base;
- int time_base; ///< time in seconds of last I,P,S Frame
- int64_t time; ///< time of current frame
- int64_t last_non_b_time;
- uint16_t pp_time; ///< time distance between the last 2 p,s,i frames
- uint16_t pb_time; ///< time distance between the last b and p,s,i frame
- uint16_t pp_field_time;
- uint16_t pb_field_time; ///< like above, just for interlaced
- int shape;
- int vol_sprite_usage;
- int sprite_width;
- int sprite_height;
- int sprite_left;
- int sprite_top;
- int sprite_brightness_change;
- int num_sprite_warping_points;
- int real_sprite_warping_points;
- int sprite_offset[2][2]; ///< sprite offset[isChroma][isMVY]
- int sprite_delta[2][2]; ///< sprite_delta [isY][isMVY]
- int sprite_shift[2]; ///< sprite shift [isChroma]
- int mcsel;
- int quant_precision;
- int quarter_sample; ///< 1->qpel, 0->half pel ME/MC
- int scalability;
- int hierachy_type;
- int enhancement_type;
- int new_pred;
- int reduced_res_vop;
- int aspect_ratio_info; //FIXME remove
- int sprite_warping_accuracy;
- int low_latency_sprite;
- int data_partitioning; ///< data partitioning flag from header
- int partitioned_frame; ///< is current frame partitioned
- int rvlc; ///< reversible vlc
- int resync_marker; ///< could this stream contain resync markers
- int low_delay; ///< no reordering needed / has no b-frames
- int vo_type;
- int vol_control_parameters; ///< does the stream contain the low_delay flag, used to workaround buggy encoders
- int intra_dc_threshold; ///< QP above whch the ac VLC should be used for intra dc
- int use_intra_dc_vlc;
- PutBitContext tex_pb; ///< used for data partitioned VOPs
- PutBitContext pb2; ///< used for data partitioned VOPs
- int mpeg_quant;
- int t_frame; ///< time distance of first I -> B, used for interlaced b frames
- int padding_bug_score; ///< used to detect the VERY common padding bug in MPEG4
-
- /* divx specific, used to workaround (many) bugs in divx5 */
- int divx_version;
- int divx_build;
- int divx_packed;
- uint8_t *bitstream_buffer; //Divx 5.01 puts several frames in a single one, this is used to reorder them
- int bitstream_buffer_size;
- unsigned int allocated_bitstream_buffer_size;
-
- int xvid_build;
-
- /* lavc specific stuff, used to workaround bugs in libavcodec */
- int lavc_build;
-
- /* RV10 specific */
- int rv10_version; ///< RV10 version: 0 or 3
- int rv10_first_dc_coded[3];
-
- /* MJPEG specific */
- struct MJpegContext *mjpeg_ctx;
- int mjpeg_vsample[3]; ///< vertical sampling factors, default = {2, 1, 1}
- int mjpeg_hsample[3]; ///< horizontal sampling factors, default = {2, 1, 1}
- int mjpeg_write_tables; ///< do we want to have quantisation- and huffmantables in the jpeg file ?
- int mjpeg_data_only_frames; ///< frames only with SOI, SOS and EOI markers
-
- /* MSMPEG4 specific */
- int mv_table_index;
- int rl_table_index;
- int rl_chroma_table_index;
- int dc_table_index;
- int use_skip_mb_code;
- int slice_height; ///< in macroblocks
- int first_slice_line; ///< used in mpeg4 too to handle resync markers
- int flipflop_rounding;
- int msmpeg4_version; ///< 0=not msmpeg4, 1=mp41, 2=mp42, 3=mp43/divx3 4=wmv1/7 5=wmv2/8
- int per_mb_rl_table;
- int esc3_level_length;
- int esc3_run_length;
- /** [mb_intra][isChroma][level][run][last] */
- int (*ac_stats)[2][MAX_LEVEL+1][MAX_RUN+1][2];
- int inter_intra_pred;
- int mspel;
-
- /* decompression specific */
- GetBitContext gb;
-
- /* Mpeg1 specific */
- int gop_picture_number; ///< index of the first picture of a GOP based on fake_pic_num & mpeg1 specific
- int last_mv_dir; ///< last mv_dir, used for b frame encoding
- int broken_link; ///< no_output_of_prior_pics_flag
- uint8_t *vbv_delay_ptr; ///< pointer to vbv_delay in the bitstream
-
- /* MPEG2 specific - I wish I had not to support this mess. */
- int progressive_sequence;
- int mpeg_f_code[2][2];
- int picture_structure;
-/* picture type */
-#define PICT_TOP_FIELD 1
-#define PICT_BOTTOM_FIELD 2
-#define PICT_FRAME 3
-
- int intra_dc_precision;
- int frame_pred_frame_dct;
- int top_field_first;
- int concealment_motion_vectors;
- int q_scale_type;
- int intra_vlc_format;
- int alternate_scan;
- int repeat_first_field;
- int chroma_420_type;
- int chroma_format;
-#define CHROMA_420 1
-#define CHROMA_422 2
-#define CHROMA_444 3
- int chroma_x_shift;//depend on pix_format, that depend on chroma_format
- int chroma_y_shift;
-
- int progressive_frame;
- int full_pel[2];
- int interlaced_dct;
- int first_slice;
- int first_field; ///< is 1 for the first field of a field picture 0 otherwise
-
- /* RTP specific */
- int rtp_mode;
-
- uint8_t *ptr_lastgob;
- int swap_uv;//vcr2 codec is mpeg2 varint with UV swaped
- short * pblocks[12];
-
- DCTELEM (*block)[64]; ///< points to one of the following blocks
- DCTELEM (*blocks)[8][64]; // for HQ mode we need to keep the best block
- int (*decode_mb)(struct MpegEncContext *s, DCTELEM block[6][64]); // used by some codecs to avoid a switch()
-#define SLICE_OK 0
-#define SLICE_ERROR -1
-#define SLICE_END -2 ///<end marker found
-#define SLICE_NOEND -3 ///<no end marker or error found but mb count exceeded
-
- void (*dct_unquantize_mpeg1_intra)(struct MpegEncContext *s,
- DCTELEM *block/*align 16*/, int n, int qscale);
- void (*dct_unquantize_mpeg1_inter)(struct MpegEncContext *s,
- DCTELEM *block/*align 16*/, int n, int qscale);
- void (*dct_unquantize_mpeg2_intra)(struct MpegEncContext *s,
- DCTELEM *block/*align 16*/, int n, int qscale);
- void (*dct_unquantize_mpeg2_inter)(struct MpegEncContext *s,
- DCTELEM *block/*align 16*/, int n, int qscale);
- void (*dct_unquantize_h263_intra)(struct MpegEncContext *s,
- DCTELEM *block/*align 16*/, int n, int qscale);
- void (*dct_unquantize_h263_inter)(struct MpegEncContext *s,
- DCTELEM *block/*align 16*/, int n, int qscale);
- void (*dct_unquantize_h261_intra)(struct MpegEncContext *s,
- DCTELEM *block/*align 16*/, int n, int qscale);
- void (*dct_unquantize_h261_inter)(struct MpegEncContext *s,
- DCTELEM *block/*align 16*/, int n, int qscale);
- void (*dct_unquantize_intra)(struct MpegEncContext *s, // unquantizer to use (mpeg4 can use both)
- DCTELEM *block/*align 16*/, int n, int qscale);
- void (*dct_unquantize_inter)(struct MpegEncContext *s, // unquantizer to use (mpeg4 can use both)
- DCTELEM *block/*align 16*/, int n, int qscale);
- int (*dct_quantize)(struct MpegEncContext *s, DCTELEM *block/*align 16*/, int n, int qscale, int *overflow);
- int (*fast_dct_quantize)(struct MpegEncContext *s, DCTELEM *block/*align 16*/, int n, int qscale, int *overflow);
- void (*denoise_dct)(struct MpegEncContext *s, DCTELEM *block);
-} MpegEncContext;
-
-
-int DCT_common_init(MpegEncContext *s);
-void MPV_decode_defaults(MpegEncContext *s);
-int MPV_common_init(MpegEncContext *s);
-void MPV_common_end(MpegEncContext *s);
-void MPV_decode_mb(MpegEncContext *s, DCTELEM block[12][64]);
-int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx);
-void MPV_frame_end(MpegEncContext *s);
-int MPV_encode_init(AVCodecContext *avctx);
-int MPV_encode_end(AVCodecContext *avctx);
-int MPV_encode_picture(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data);
-#ifdef HAVE_MMX
-void MPV_common_init_mmx(MpegEncContext *s);
-#endif
-#ifdef ARCH_ALPHA
-void MPV_common_init_axp(MpegEncContext *s);
-#endif
-#ifdef HAVE_MLIB
-void MPV_common_init_mlib(MpegEncContext *s);
-#endif
-#ifdef HAVE_MMI
-void MPV_common_init_mmi(MpegEncContext *s);
-#endif
-#ifdef ARCH_ARMV4L
-void MPV_common_init_armv4l(MpegEncContext *s);
-#endif
-#ifdef ARCH_POWERPC
-void MPV_common_init_ppc(MpegEncContext *s);
-#endif
-extern void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w);
-void ff_copy_bits(PutBitContext *pb, uint8_t *src, int length);
-void ff_clean_intra_table_entries(MpegEncContext *s);
-void ff_init_scantable(uint8_t *, ScanTable *st, const uint8_t *src_scantable);
-void ff_draw_horiz_band(MpegEncContext *s, int y, int h);
-void ff_emulated_edge_mc(uint8_t *buf, uint8_t *src, int linesize, int block_w, int block_h,
- int src_x, int src_y, int w, int h);
-void ff_mpeg_flush(AVCodecContext *avctx);
-void ff_print_debug_info(MpegEncContext *s, AVFrame *pict);
-void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix);
-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_er_frame_start(MpegEncContext *s);
-void ff_er_frame_end(MpegEncContext *s);
-void ff_er_add_slice(MpegEncContext *s, int startx, int starty, int endx, int endy, int status);
-
-
-extern enum PixelFormat ff_yuv420p_list[2];
-
-void ff_init_block_index(MpegEncContext *s);
-
-static inline void ff_update_block_index(MpegEncContext *s){
- const int block_size= 8>>s->avctx->lowres;
-
- s->block_index[0]+=2;
- s->block_index[1]+=2;
- s->block_index[2]+=2;
- s->block_index[3]+=2;
- s->block_index[4]++;
- s->block_index[5]++;
- s->dest[0]+= 2*block_size;
- s->dest[1]+= block_size;
- s->dest[2]+= block_size;
-}
-
-static inline int get_bits_diff(MpegEncContext *s){
- const int bits= put_bits_count(&s->pb);
- const int last= s->last_bits;
-
- s->last_bits = bits;
-
- return bits - last;
-}
-
-/* motion_est.c */
-void ff_estimate_p_frame_motion(MpegEncContext * s,
- int mb_x, int mb_y);
-void ff_estimate_b_frame_motion(MpegEncContext * s,
- int mb_x, int mb_y);
-int ff_get_best_fcode(MpegEncContext * s, int16_t (*mv_table)[2], int type);
-void ff_fix_long_p_mvs(MpegEncContext * s);
-void ff_fix_long_mvs(MpegEncContext * s, uint8_t *field_select_table, int field_select,
- int16_t (*mv_table)[2], int f_code, int type, int truncate);
-void ff_init_me(MpegEncContext *s);
-int ff_pre_estimate_p_frame_motion(MpegEncContext * s, int mb_x, int mb_y);
-inline int ff_epzs_motion_search(MpegEncContext * s, int *mx_ptr, int *my_ptr,
- int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2],
- int ref_mv_scale, int size, int h);
-inline int ff_get_mb_score(MpegEncContext * s, int mx, int my, int src_index,
- int ref_index, int size, int h, int add_rate);
-
-/* mpeg12.c */
-extern const uint16_t ff_mpeg1_default_intra_matrix[64];
-extern const uint16_t ff_mpeg1_default_non_intra_matrix[64];
-extern const uint8_t ff_mpeg1_dc_scale_table[128];
-
-void mpeg1_encode_picture_header(MpegEncContext *s, int picture_number);
-void mpeg1_encode_mb(MpegEncContext *s,
- DCTELEM block[6][64],
- int motion_x, int motion_y);
-void ff_mpeg1_encode_init(MpegEncContext *s);
-void ff_mpeg1_encode_slice_header(MpegEncContext *s);
-void ff_mpeg1_clean_buffers(MpegEncContext *s);
-
-
-/** RLTable. */
-typedef struct RLTable {
- int n; ///< number of entries of table_vlc minus 1
- int last; ///< number of values for last = 0
- const uint16_t (*table_vlc)[2];
- const int8_t *table_run;
- const int8_t *table_level;
- uint8_t *index_run[2]; ///< encoding only
- int8_t *max_level[2]; ///< encoding & decoding
- int8_t *max_run[2]; ///< encoding & decoding
- VLC vlc; ///< decoding only deprected FIXME remove
- RL_VLC_ELEM *rl_vlc[32]; ///< decoding only
-} RLTable;
-
-void init_rl(RLTable *rl, int use_static);
-void init_vlc_rl(RLTable *rl, int use_static);
-
-static inline int get_rl_index(const RLTable *rl, int last, int run, int level)
-{
- int index;
- index = rl->index_run[last][run];
- if (index >= rl->n)
- return rl->n;
- if (level > rl->max_level[last][run])
- return rl->n;
- return index + level - 1;
-}
-
-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];
-
-/* h261.c */
-void ff_h261_loop_filter(MpegEncContext *s);
-void ff_h261_reorder_mb_index(MpegEncContext* s);
-void ff_h261_encode_mb(MpegEncContext *s,
- DCTELEM block[6][64],
- int motion_x, int motion_y);
-void ff_h261_encode_picture_header(MpegEncContext * s, int picture_number);
-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,
- uint8_t *buf, int buf_size);
-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, int picture_number);
-void mpeg4_encode_picture_header(MpegEncContext *s, int picture_number);
-#ifdef CONFIG_ENCODERS
-void h263_encode_init(MpegEncContext *s);
-#else
-static void h263_encode_init(MpegEncContext *s) {assert(0);}
-#endif
-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);
-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);
-int ff_h263_round_chroma(int x);
-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);
-void rv20_encode_picture_header(MpegEncContext *s, int picture_number);
-
-
-/* msmpeg4.c */
-void msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number);
-void msmpeg4_encode_ext_header(MpegEncContext * s);
-void msmpeg4_encode_mb(MpegEncContext * s,
- DCTELEM block[6][64],
- 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);
-void ff_msmpeg4_encode_init(MpegEncContext *s);
-int ff_wmv2_decode_picture_header(MpegEncContext * s);
-int ff_wmv2_decode_secondary_picture_header(MpegEncContext * s);
-void ff_wmv2_add_mb(MpegEncContext *s, DCTELEM block[6][64], uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr);
-void ff_mspel_motion(MpegEncContext *s,
- uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
- uint8_t **ref_picture, op_pixels_func (*pix_op)[4],
- int motion_x, int motion_y, int h);
-int ff_wmv2_encode_picture_header(MpegEncContext * s, int picture_number);
-void ff_wmv2_encode_mb(MpegEncContext * s,
- DCTELEM block[6][64],
- int motion_x, int motion_y);
-
-/* mjpeg.c */
-int mjpeg_init(MpegEncContext *s);
-void mjpeg_close(MpegEncContext *s);
-void mjpeg_encode_mb(MpegEncContext *s,
- DCTELEM block[6][64]);
-void mjpeg_picture_header(MpegEncContext *s);
-void mjpeg_picture_trailer(MpegEncContext *s);
-void ff_mjpeg_stuffing(PutBitContext * pbc);
-
-#endif /* AVCODEC_MPEGVIDEO_H */
-
diff --git a/src/libffmpeg/libavcodec/msmpeg4.c b/src/libffmpeg/libavcodec/msmpeg4.c
deleted file mode 100644
index a8124172b..000000000
--- a/src/libffmpeg/libavcodec/msmpeg4.c
+++ /dev/null
@@ -1,1938 +0,0 @@
-/*
- * MSMPEG4 backend for ffmpeg encoder and decoder
- * Copyright (c) 2001 Fabrice Bellard.
- * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * msmpeg4v1 & v2 stuff by Michael Niedermayer <michaelni@gmx.at>
- */
-
-/**
- * @file msmpeg4.c
- * MSMPEG4 backend for ffmpeg encoder and decoder.
- */
-
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-
-/*
- * You can also call this codec : MPEG4 with a twist !
- *
- * TODO:
- * - (encoding) select best mv table (two choices)
- * - (encoding) select best vlc/dc table
- */
-//#define DEBUG
-
-#define DC_VLC_BITS 9
-#define CBPY_VLC_BITS 6
-#define INTER_INTRA_VLC_BITS 3
-#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
-#define V2_MV_VLC_BITS 9
-#define TEX_VLC_BITS 9
-#define MB_NON_INTRA_VLC_BITS 9
-#define MB_INTRA_VLC_BITS 9
-
-#define II_BITRATE 128*1024
-#define MBAC_BITRATE 50*1024
-
-#define DEFAULT_INTER_INDEX 3
-
-static uint32_t v2_dc_lum_table[512][2];
-static uint32_t v2_dc_chroma_table[512][2];
-
-static inline void msmpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n);
-static inline int msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block,
- int n, int coded, const uint8_t *scantable);
-static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr);
-static int msmpeg4_decode_motion(MpegEncContext * s,
- int *mx_ptr, int *my_ptr);
-static void init_h263_dc_for_msmpeg4(void);
-static inline void msmpeg4_memsetw(short *tab, int val, int n);
-#ifdef 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]);
-static int wmv2_decode_mb(MpegEncContext *s, DCTELEM block[6][64]);
-
-/* vc1 externs */
-extern uint8_t wmv3_dc_scale_table[32];
-
-#ifdef DEBUG
-int intra_count = 0;
-int frame_count = 0;
-#endif
-
-#include "msmpeg4data.h"
-
-#ifdef CONFIG_ENCODERS //strangely gcc includes this even if its not references
-static uint8_t rl_length[NB_RL_TABLES][MAX_LEVEL+1][MAX_RUN+1][2];
-#endif //CONFIG_ENCODERS
-
-static void common_init(MpegEncContext * s)
-{
- static int inited=0;
-
- switch(s->msmpeg4_version){
- case 1:
- case 2:
- s->y_dc_scale_table=
- s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
- break;
- case 3:
- if(s->workaround_bugs){
- s->y_dc_scale_table= old_ff_y_dc_scale_table;
- s->c_dc_scale_table= old_ff_c_dc_scale_table;
- } else{
- s->y_dc_scale_table= ff_mpeg4_y_dc_scale_table;
- s->c_dc_scale_table= ff_mpeg4_c_dc_scale_table;
- }
- break;
- case 4:
- case 5:
- s->y_dc_scale_table= wmv1_y_dc_scale_table;
- s->c_dc_scale_table= wmv1_c_dc_scale_table;
- break;
-#if defined(CONFIG_WMV3_DECODER)||defined(CONFIG_VC1_DECODER)
- case 6:
- s->y_dc_scale_table= wmv3_dc_scale_table;
- s->c_dc_scale_table= wmv3_dc_scale_table;
- break;
-#endif
-
- }
-
-
- if(s->msmpeg4_version>=4){
- ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , wmv1_scantable[1]);
- ff_init_scantable(s->dsp.idct_permutation, &s->intra_h_scantable, wmv1_scantable[2]);
- ff_init_scantable(s->dsp.idct_permutation, &s->intra_v_scantable, wmv1_scantable[3]);
- ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , wmv1_scantable[0]);
- }
- //Note the default tables are set in common_init in mpegvideo.c
-
- if(!inited){
- inited=1;
-
- init_h263_dc_for_msmpeg4();
- }
-}
-
-#ifdef CONFIG_ENCODERS
-
-/* build the table which associate a (x,y) motion vector to a vlc */
-static void init_mv_table(MVTable *tab)
-{
- int i, x, y;
-
- tab->table_mv_index = av_malloc(sizeof(uint16_t) * 4096);
- /* mark all entries as not used */
- for(i=0;i<4096;i++)
- tab->table_mv_index[i] = tab->n;
-
- for(i=0;i<tab->n;i++) {
- x = tab->table_mvx[i];
- y = tab->table_mvy[i];
- tab->table_mv_index[(x << 6) | y] = i;
- }
-}
-
-static void code012(PutBitContext *pb, int n)
-{
- if (n == 0) {
- put_bits(pb, 1, 0);
- } else {
- put_bits(pb, 1, 1);
- put_bits(pb, 1, (n >= 2));
- }
-}
-
-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;i<NB_RL_TABLES;i++)
- init_rl(&rl_table[i], 1);
-
- for(i=0; i<NB_RL_TABLES; i++){
- int level;
- for(level=0; level<=MAX_LEVEL; level++){
- int run;
- for(run=0; run<=MAX_RUN; run++){
- int last;
- for(last=0; last<2; last++){
- rl_length[i][level][run][last]= get_size_of_code(s, &rl_table[ i], last, run, level, 0);
- }
- }
- }
- }
- }
-}
-
-static int get_size_of_code(MpegEncContext * s, RLTable *rl, int last, int run, int level, int intra){
- int size=0;
- int code;
- int run_diff= intra ? 0 : 1;
-
- code = get_rl_index(rl, last, run, level);
- size+= rl->table_vlc[code][1];
- 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:
- size++;
- if (level > MAX_LEVEL)
- goto esc3;
- run1 = run - rl->max_run[last][level] - run_diff;
- if (run1 < 0)
- goto esc3;
- code = get_rl_index(rl, last, run1, level);
- if (code == rl->n) {
- esc3:
- /* third escape */
- size+=1+1+6+8;
- } else {
- /* second escape */
- size+= 1+1+ rl->table_vlc[code][1];
- }
- } else {
- /* first escape */
- size+= 1+1+ rl->table_vlc[code][1];
- }
- } else {
- size++;
- }
- return size;
-}
-
-static void find_best_tables(MpegEncContext * s)
-{
- int i;
- int best =-1, best_size =9999999;
- int chroma_best=-1, best_chroma_size=9999999;
-
- for(i=0; i<3; i++){
- int level;
- int chroma_size=0;
- int size=0;
-
- if(i>0){// ;)
- size++;
- chroma_size++;
- }
- for(level=0; level<=MAX_LEVEL; level++){
- int run;
- for(run=0; run<=MAX_RUN; run++){
- int last;
- const int last_size= size + chroma_size;
- for(last=0; last<2; last++){
- int inter_count = s->ac_stats[0][0][level][run][last] + s->ac_stats[0][1][level][run][last];
- int intra_luma_count = s->ac_stats[1][0][level][run][last];
- int intra_chroma_count= s->ac_stats[1][1][level][run][last];
-
- if(s->pict_type==I_TYPE){
- size += intra_luma_count *rl_length[i ][level][run][last];
- chroma_size+= intra_chroma_count*rl_length[i+3][level][run][last];
- }else{
- size+= intra_luma_count *rl_length[i ][level][run][last]
- +intra_chroma_count*rl_length[i+3][level][run][last]
- +inter_count *rl_length[i+3][level][run][last];
- }
- }
- if(last_size == size+chroma_size) break;
- }
- }
- if(size<best_size){
- best_size= size;
- best= i;
- }
- if(chroma_size<best_chroma_size){
- best_chroma_size= chroma_size;
- chroma_best= i;
- }
- }
-
-// printf("type:%d, best:%d, qp:%d, var:%d, mcvar:%d, size:%d //\n",
-// s->pict_type, best, s->qscale, s->mb_var_sum, s->mc_mb_var_sum, best_size);
-
- if(s->pict_type==P_TYPE) chroma_best= best;
-
- memset(s->ac_stats, 0, sizeof(int)*(MAX_LEVEL+1)*(MAX_RUN+1)*2*2*2);
-
- s->rl_table_index = best;
- s->rl_chroma_table_index= chroma_best;
-
- if(s->pict_type != s->last_non_b_pict_type){
- s->rl_table_index= 2;
- if(s->pict_type==I_TYPE)
- s->rl_chroma_table_index= 1;
- else
- s->rl_chroma_table_index= 2;
- }
-
-}
-
-/* write MSMPEG4 compatible frame header */
-void msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number)
-{
- find_best_tables(s);
-
- align_put_bits(&s->pb);
- put_bits(&s->pb, 2, s->pict_type - 1);
-
- put_bits(&s->pb, 5, s->qscale);
- if(s->msmpeg4_version<=2){
- s->rl_table_index = 2;
- s->rl_chroma_table_index = 2;
- }
-
- s->dc_table_index = 1;
- s->mv_table_index = 1; /* only if P frame */
- s->use_skip_mb_code = 1; /* only if P frame */
- s->per_mb_rl_table = 0;
- if(s->msmpeg4_version==4)
- s->inter_intra_pred= (s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE && s->pict_type==P_TYPE);
-//printf("%d %d %d %d %d\n", s->pict_type, s->bit_rate, s->inter_intra_pred, s->width, s->height);
-
- if (s->pict_type == I_TYPE) {
- s->slice_height= s->mb_height/1;
- put_bits(&s->pb, 5, 0x16 + s->mb_height/s->slice_height);
-
- if(s->msmpeg4_version==4){
- msmpeg4_encode_ext_header(s);
- if(s->bit_rate>MBAC_BITRATE)
- put_bits(&s->pb, 1, s->per_mb_rl_table);
- }
-
- if(s->msmpeg4_version>2){
- if(!s->per_mb_rl_table){
- code012(&s->pb, s->rl_chroma_table_index);
- code012(&s->pb, s->rl_table_index);
- }
-
- put_bits(&s->pb, 1, s->dc_table_index);
- }
- } else {
- put_bits(&s->pb, 1, s->use_skip_mb_code);
-
- if(s->msmpeg4_version==4 && s->bit_rate>MBAC_BITRATE)
- put_bits(&s->pb, 1, s->per_mb_rl_table);
-
- if(s->msmpeg4_version>2){
- if(!s->per_mb_rl_table)
- code012(&s->pb, s->rl_table_index);
-
- put_bits(&s->pb, 1, s->dc_table_index);
-
- put_bits(&s->pb, 1, s->mv_table_index);
- }
- }
-
- s->esc3_level_length= 0;
- s->esc3_run_length= 0;
-
-#ifdef DEBUG
- intra_count = 0;
- av_log(s->avctx, AV_LOG_DEBUG, "*****frame %d:\n", frame_count++);
-#endif
-}
-
-void msmpeg4_encode_ext_header(MpegEncContext * s)
-{
- put_bits(&s->pb, 5, s->avctx->time_base.den / s->avctx->time_base.num); //yes 29.97 -> 29
-
- put_bits(&s->pb, 11, FFMIN(s->bit_rate/1024, 2047));
-
- if(s->msmpeg4_version>=3)
- put_bits(&s->pb, 1, s->flipflop_rounding);
- else
- assert(s->flipflop_rounding==0);
-}
-
-#endif //CONFIG_ENCODERS
-
-/* predict coded block */
-static inline int coded_block_pred(MpegEncContext * s, int n, uint8_t **coded_block_ptr)
-{
- int xy, wrap, pred, a, b, c;
-
- xy = s->block_index[n];
- wrap = s->b8_stride;
-
- /* B C
- * A X
- */
- a = s->coded_block[xy - 1 ];
- b = s->coded_block[xy - 1 - wrap];
- c = s->coded_block[xy - wrap];
-
- if (b == c) {
- pred = a;
- } else {
- pred = c;
- }
-
- /* store value */
- *coded_block_ptr = &s->coded_block[xy];
-
- return pred;
-}
-
-#ifdef CONFIG_ENCODERS
-
-static void msmpeg4_encode_motion(MpegEncContext * s,
- int mx, int my)
-{
- int code;
- MVTable *mv;
-
- /* modulo encoding */
- /* WARNING : you cannot reach all the MVs even with the modulo
- encoding. This is a somewhat strange compromise they took !!! */
- if (mx <= -64)
- mx += 64;
- else if (mx >= 64)
- mx -= 64;
- if (my <= -64)
- my += 64;
- else if (my >= 64)
- my -= 64;
-
- mx += 32;
- my += 32;
-#if 0
- if ((unsigned)mx >= 64 ||
- (unsigned)my >= 64)
- av_log(s->avctx, AV_LOG_ERROR, "error mx=%d my=%d\n", mx, my);
-#endif
- mv = &mv_tables[s->mv_table_index];
-
- code = mv->table_mv_index[(mx << 6) | my];
- put_bits(&s->pb,
- mv->table_mv_bits[code],
- mv->table_mv_code[code]);
- if (code == mv->n) {
- /* escape : code litterally */
- put_bits(&s->pb, 6, mx);
- put_bits(&s->pb, 6, my);
- }
-}
-
-static inline void handle_slices(MpegEncContext *s){
- if (s->mb_x == 0) {
- if (s->slice_height && (s->mb_y % s->slice_height) == 0) {
- if(s->msmpeg4_version < 4){
- ff_mpeg4_clean_buffers(s);
- }
- s->first_slice_line = 1;
- } else {
- s->first_slice_line = 0;
- }
- }
-}
-
-void msmpeg4_encode_mb(MpegEncContext * s,
- DCTELEM block[6][64],
- int motion_x, int motion_y)
-{
- int cbp, coded_cbp, i;
- int pred_x, pred_y;
- uint8_t *coded_block;
-
- handle_slices(s);
-
- if (!s->mb_intra) {
- /* compute cbp */
- cbp = 0;
- for (i = 0; i < 6; i++) {
- if (s->block_last_index[i] >= 0)
- cbp |= 1 << (5 - i);
- }
- if (s->use_skip_mb_code && (cbp | motion_x | motion_y) == 0) {
- /* skip macroblock */
- put_bits(&s->pb, 1, 1);
- s->last_bits++;
- s->misc_bits++;
- s->skip_count++;
-
- return;
- }
- if (s->use_skip_mb_code)
- put_bits(&s->pb, 1, 0); /* mb coded */
-
- if(s->msmpeg4_version<=2){
- put_bits(&s->pb,
- v2_mb_type[cbp&3][1],
- v2_mb_type[cbp&3][0]);
- if((cbp&3) != 3) coded_cbp= cbp ^ 0x3C;
- else coded_cbp= cbp;
-
- put_bits(&s->pb,
- cbpy_tab[coded_cbp>>2][1],
- cbpy_tab[coded_cbp>>2][0]);
-
- s->misc_bits += get_bits_diff(s);
-
- h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
- msmpeg4v2_encode_motion(s, motion_x - pred_x);
- msmpeg4v2_encode_motion(s, motion_y - pred_y);
- }else{
- put_bits(&s->pb,
- table_mb_non_intra[cbp + 64][1],
- table_mb_non_intra[cbp + 64][0]);
-
- s->misc_bits += get_bits_diff(s);
-
- /* motion vector */
- h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
- msmpeg4_encode_motion(s, motion_x - pred_x,
- motion_y - pred_y);
- }
-
- s->mv_bits += get_bits_diff(s);
-
- for (i = 0; i < 6; i++) {
- msmpeg4_encode_block(s, block[i], i);
- }
- s->p_tex_bits += get_bits_diff(s);
- } else {
- /* compute cbp */
- cbp = 0;
- coded_cbp = 0;
- for (i = 0; i < 6; i++) {
- int val, pred;
- val = (s->block_last_index[i] >= 1);
- cbp |= val << (5 - i);
- if (i < 4) {
- /* predict value for close blocks only for luma */
- pred = coded_block_pred(s, i, &coded_block);
- *coded_block = val;
- val = val ^ pred;
- }
- coded_cbp |= val << (5 - i);
- }
-#if 0
- if (coded_cbp)
- printf("cbp=%x %x\n", cbp, coded_cbp);
-#endif
-
- if(s->msmpeg4_version<=2){
- if (s->pict_type == I_TYPE) {
- put_bits(&s->pb,
- v2_intra_cbpc[cbp&3][1], v2_intra_cbpc[cbp&3][0]);
- } else {
- if (s->use_skip_mb_code)
- put_bits(&s->pb, 1, 0); /* mb coded */
- put_bits(&s->pb,
- v2_mb_type[(cbp&3) + 4][1],
- v2_mb_type[(cbp&3) + 4][0]);
- }
- put_bits(&s->pb, 1, 0); /* no AC prediction yet */
- put_bits(&s->pb,
- cbpy_tab[cbp>>2][1],
- cbpy_tab[cbp>>2][0]);
- }else{
- if (s->pict_type == I_TYPE) {
- put_bits(&s->pb,
- ff_msmp4_mb_i_table[coded_cbp][1], ff_msmp4_mb_i_table[coded_cbp][0]);
- } else {
- if (s->use_skip_mb_code)
- put_bits(&s->pb, 1, 0); /* mb coded */
- put_bits(&s->pb,
- table_mb_non_intra[cbp][1],
- table_mb_non_intra[cbp][0]);
- }
- put_bits(&s->pb, 1, 0); /* no AC prediction yet */
- if(s->inter_intra_pred){
- s->h263_aic_dir=0;
- put_bits(&s->pb, table_inter_intra[s->h263_aic_dir][1], table_inter_intra[s->h263_aic_dir][0]);
- }
- }
- s->misc_bits += get_bits_diff(s);
-
- for (i = 0; i < 6; i++) {
- msmpeg4_encode_block(s, block[i], i);
- }
- s->i_tex_bits += get_bits_diff(s);
- s->i_count++;
- }
-}
-
-#endif //CONFIG_ENCODERS
-
-static inline int msmpeg4v1_pred_dc(MpegEncContext * s, int n,
- int32_t **dc_val_ptr)
-{
- int i;
-
- if (n < 4) {
- i= 0;
- } else {
- i= n-3;
- }
-
- *dc_val_ptr= &s->last_dc[i];
- return s->last_dc[i];
-}
-
-static int get_dc(uint8_t *src, int stride, int scale)
-{
- int y;
- int sum=0;
- for(y=0; y<8; y++){
- int x;
- for(x=0; x<8; x++){
- sum+=src[x + y*stride];
- }
- }
- return FASTDIV((sum + (scale>>1)), scale);
-}
-
-/* dir = 0: left, dir = 1: top prediction */
-static inline int msmpeg4_pred_dc(MpegEncContext * s, int n,
- int16_t **dc_val_ptr, int *dir_ptr)
-{
- int a, b, c, wrap, pred, scale;
- int16_t *dc_val;
-
- /* find prediction */
- if (n < 4) {
- scale = s->y_dc_scale;
- } else {
- scale = s->c_dc_scale;
- }
-
- wrap = s->block_wrap[n];
- dc_val= s->dc_val[0] + s->block_index[n];
-
- /* B C
- * A X
- */
- a = dc_val[ - 1];
- b = dc_val[ - 1 - wrap];
- c = dc_val[ - wrap];
-
- if(s->first_slice_line && (n&2)==0 && s->msmpeg4_version<4){
- b=c=1024;
- }
-
- /* XXX: the following solution consumes divisions, but it does not
- necessitate to modify mpegvideo.c. The problem comes from the
- fact they decided to store the quantized DC (which would lead
- to problems if Q could vary !) */
-#if (defined(ARCH_X86)) && !defined PIC
- asm volatile(
- "movl %3, %%eax \n\t"
- "shrl $1, %%eax \n\t"
- "addl %%eax, %2 \n\t"
- "addl %%eax, %1 \n\t"
- "addl %0, %%eax \n\t"
- "mull %4 \n\t"
- "movl %%edx, %0 \n\t"
- "movl %1, %%eax \n\t"
- "mull %4 \n\t"
- "movl %%edx, %1 \n\t"
- "movl %2, %%eax \n\t"
- "mull %4 \n\t"
- "movl %%edx, %2 \n\t"
- : "+b" (a), "+c" (b), "+D" (c)
- : "g" (scale), "S" (ff_inverse[scale])
- : "%eax", "%edx"
- );
-#else
- /* #elif defined (ARCH_ALPHA) */
- /* Divisions are extremely costly on Alpha; optimize the most
- common case. But they are costly everywhere...
- */
- if (scale == 8) {
- a = (a + (8 >> 1)) / 8;
- b = (b + (8 >> 1)) / 8;
- c = (c + (8 >> 1)) / 8;
- } else {
- a = FASTDIV((a + (scale >> 1)), scale);
- b = FASTDIV((b + (scale >> 1)), scale);
- c = FASTDIV((c + (scale >> 1)), scale);
- }
-#endif
- /* XXX: WARNING: they did not choose the same test as MPEG4. This
- is very important ! */
- if(s->msmpeg4_version>3){
- if(s->inter_intra_pred){
- uint8_t *dest;
- int wrap;
-
- if(n==1){
- pred=a;
- *dir_ptr = 0;
- }else if(n==2){
- pred=c;
- *dir_ptr = 1;
- }else if(n==3){
- if (abs(a - b) < abs(b - c)) {
- pred = c;
- *dir_ptr = 1;
- } else {
- pred = a;
- *dir_ptr = 0;
- }
- }else{
- if(n<4){
- wrap= s->linesize;
- dest= s->current_picture.data[0] + (((n>>1) + 2*s->mb_y) * 8* wrap ) + ((n&1) + 2*s->mb_x) * 8;
- }else{
- wrap= s->uvlinesize;
- dest= s->current_picture.data[n-3] + (s->mb_y * 8 * wrap) + s->mb_x * 8;
- }
- if(s->mb_x==0) a= (1024 + (scale>>1))/scale;
- else a= get_dc(dest-8, wrap, scale*8);
- if(s->mb_y==0) c= (1024 + (scale>>1))/scale;
- else c= get_dc(dest-8*wrap, wrap, scale*8);
-
- if (s->h263_aic_dir==0) {
- pred= a;
- *dir_ptr = 0;
- }else if (s->h263_aic_dir==1) {
- if(n==0){
- pred= c;
- *dir_ptr = 1;
- }else{
- pred= a;
- *dir_ptr = 0;
- }
- }else if (s->h263_aic_dir==2) {
- if(n==0){
- pred= a;
- *dir_ptr = 0;
- }else{
- pred= c;
- *dir_ptr = 1;
- }
- } else {
- pred= c;
- *dir_ptr = 1;
- }
- }
- }else{
- if (abs(a - b) < abs(b - c)) {
- pred = c;
- *dir_ptr = 1;
- } else {
- pred = a;
- *dir_ptr = 0;
- }
- }
- }else{
- if (abs(a - b) <= abs(b - c)) {
- pred = c;
- *dir_ptr = 1;
- } else {
- pred = a;
- *dir_ptr = 0;
- }
- }
-
- /* update predictor */
- *dc_val_ptr = &dc_val[0];
- return pred;
-}
-
-#define DC_MAX 119
-
-static void msmpeg4_encode_dc(MpegEncContext * s, int level, int n, int *dir_ptr)
-{
- int sign, code;
- int pred;
-
- if(s->msmpeg4_version==1){
- int32_t *dc_val;
- pred = msmpeg4v1_pred_dc(s, n, &dc_val);
-
- /* update predictor */
- *dc_val= level;
- }else{
- int16_t *dc_val;
- pred = msmpeg4_pred_dc(s, n, &dc_val, dir_ptr);
-
- /* update predictor */
- if (n < 4) {
- *dc_val = level * s->y_dc_scale;
- } else {
- *dc_val = level * s->c_dc_scale;
- }
- }
-
- /* do the prediction */
- level -= pred;
-
- if(s->msmpeg4_version<=2){
- if (n < 4) {
- put_bits(&s->pb,
- v2_dc_lum_table[level+256][1],
- v2_dc_lum_table[level+256][0]);
- }else{
- put_bits(&s->pb,
- v2_dc_chroma_table[level+256][1],
- v2_dc_chroma_table[level+256][0]);
- }
- }else{
- sign = 0;
- if (level < 0) {
- level = -level;
- sign = 1;
- }
- code = level;
- if (code > DC_MAX)
- code = DC_MAX;
-
- if (s->dc_table_index == 0) {
- if (n < 4) {
- put_bits(&s->pb, ff_table0_dc_lum[code][1], ff_table0_dc_lum[code][0]);
- } else {
- put_bits(&s->pb, ff_table0_dc_chroma[code][1], ff_table0_dc_chroma[code][0]);
- }
- } else {
- if (n < 4) {
- put_bits(&s->pb, ff_table1_dc_lum[code][1], ff_table1_dc_lum[code][0]);
- } else {
- put_bits(&s->pb, ff_table1_dc_chroma[code][1], ff_table1_dc_chroma[code][0]);
- }
- }
-
- if (code == DC_MAX)
- put_bits(&s->pb, 8, level);
-
- if (level != 0) {
- put_bits(&s->pb, 1, sign);
- }
- }
-}
-
-/* Encoding of a block. Very similar to MPEG4 except for a different
- escape coding (same as H263) and more vlc tables.
- */
-static inline void msmpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n)
-{
- int level, run, last, i, j, last_index;
- int last_non_zero, sign, slevel;
- int code, run_diff, dc_pred_dir;
- const RLTable *rl;
- const uint8_t *scantable;
-
- if (s->mb_intra) {
- msmpeg4_encode_dc(s, block[0], n, &dc_pred_dir);
- i = 1;
- if (n < 4) {
- rl = &rl_table[s->rl_table_index];
- } else {
- rl = &rl_table[3 + s->rl_chroma_table_index];
- }
- run_diff = 0;
- scantable= s->intra_scantable.permutated;
- } else {
- i = 0;
- rl = &rl_table[3 + s->rl_table_index];
- if(s->msmpeg4_version<=2)
- run_diff = 0;
- else
- run_diff = 1;
- scantable= s->inter_scantable.permutated;
- }
-
- /* recalculate block_last_index for M$ wmv1 */
- if(s->msmpeg4_version>=4 && s->block_last_index[n]>0){
- for(last_index=63; last_index>=0; last_index--){
- if(block[scantable[last_index]]) break;
- }
- s->block_last_index[n]= last_index;
- }else
- last_index = s->block_last_index[n];
- /* AC coefs */
- last_non_zero = i - 1;
- for (; i <= last_index; i++) {
- j = scantable[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;
- }
-
- if(level<=MAX_LEVEL && run<=MAX_RUN){
- s->ac_stats[s->mb_intra][n>3][level][run][last]++;
- }
-#if 0
-else
- s->ac_stats[s->mb_intra][n>3][40][63][0]++; //esc3 like
-#endif
- 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) {
- 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(&s->pb, 1, 0);
- if (level > MAX_LEVEL)
- goto esc3;
- run1 = run - rl->max_run[last][level] - run_diff;
- if (run1 < 0)
- goto esc3;
- code = get_rl_index(rl, last, run1, level);
- if (code == rl->n) {
- esc3:
- /* third escape */
- put_bits(&s->pb, 1, 0);
- put_bits(&s->pb, 1, last);
- if(s->msmpeg4_version>=4){
- if(s->esc3_level_length==0){
- s->esc3_level_length=8;
- s->esc3_run_length= 6;
- if(s->qscale<8)
- put_bits(&s->pb, 6, 3);
- else
- put_bits(&s->pb, 8, 3);
- }
- put_bits(&s->pb, s->esc3_run_length, run);
- put_bits(&s->pb, 1, sign);
- put_bits(&s->pb, s->esc3_level_length, level);
- }else{
- put_bits(&s->pb, 6, run);
- put_bits(&s->pb, 8, slevel & 0xff);
- }
- } else {
- /* second escape */
- put_bits(&s->pb, 1, 1);
- put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
- put_bits(&s->pb, 1, sign);
- }
- } else {
- /* first escape */
- put_bits(&s->pb, 1, 1);
- put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
- put_bits(&s->pb, 1, sign);
- }
- } else {
- put_bits(&s->pb, 1, sign);
- }
- last_non_zero = i;
- }
- }
-}
-
-/****************************************/
-/* decoding stuff */
-
-static VLC mb_non_intra_vlc[4];
-VLC ff_msmp4_mb_i_vlc;
-VLC ff_msmp4_dc_luma_vlc[2];
-VLC ff_msmp4_dc_chroma_vlc[2];
-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;
-static VLC inter_intra_vlc;
-
-/* this table is practically identical to the one from h263 except that its inverted */
-static 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= DCtab_lum[size][0];
- uni_len = DCtab_lum[size][1];
- uni_code ^= (1<<uni_len)-1; //M$ doesnt like compatibility
-
- if (size > 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<<uni_len)-1; //M$ doesnt like compatibility
-
- if (size > 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;
-
- }
-}
-
-/* init all vlc decoding tables */
-int ff_msmpeg4_decode_init(MpegEncContext *s)
-{
- static int done = 0;
- int i;
- MVTable *mv;
-
- common_init(s);
-
- if (!done) {
- done = 1;
-
- for(i=0;i<NB_RL_TABLES;i++) {
- init_rl(&rl_table[i], 1);
- init_vlc_rl(&rl_table[i], 1);
- }
- for(i=0;i<2;i++) {
- mv = &mv_tables[i];
- init_vlc(&mv->vlc, MV_VLC_BITS, mv->n + 1,
- mv->table_mv_bits, 1, 1,
- mv->table_mv_code, 2, 2, 1);
- }
-
- init_vlc(&ff_msmp4_dc_luma_vlc[0], DC_VLC_BITS, 120,
- &ff_table0_dc_lum[0][1], 8, 4,
- &ff_table0_dc_lum[0][0], 8, 4, 1);
- init_vlc(&ff_msmp4_dc_chroma_vlc[0], DC_VLC_BITS, 120,
- &ff_table0_dc_chroma[0][1], 8, 4,
- &ff_table0_dc_chroma[0][0], 8, 4, 1);
- init_vlc(&ff_msmp4_dc_luma_vlc[1], DC_VLC_BITS, 120,
- &ff_table1_dc_lum[0][1], 8, 4,
- &ff_table1_dc_lum[0][0], 8, 4, 1);
- init_vlc(&ff_msmp4_dc_chroma_vlc[1], DC_VLC_BITS, 120,
- &ff_table1_dc_chroma[0][1], 8, 4,
- &ff_table1_dc_chroma[0][0], 8, 4, 1);
-
- init_vlc(&v2_dc_lum_vlc, DC_VLC_BITS, 512,
- &v2_dc_lum_table[0][1], 8, 4,
- &v2_dc_lum_table[0][0], 8, 4, 1);
- init_vlc(&v2_dc_chroma_vlc, DC_VLC_BITS, 512,
- &v2_dc_chroma_table[0][1], 8, 4,
- &v2_dc_chroma_table[0][0], 8, 4, 1);
-
- init_vlc(&cbpy_vlc, CBPY_VLC_BITS, 16,
- &cbpy_tab[0][1], 2, 1,
- &cbpy_tab[0][0], 2, 1, 1);
- init_vlc(&v2_intra_cbpc_vlc, V2_INTRA_CBPC_VLC_BITS, 4,
- &v2_intra_cbpc[0][1], 2, 1,
- &v2_intra_cbpc[0][0], 2, 1, 1);
- init_vlc(&v2_mb_type_vlc, V2_MB_TYPE_VLC_BITS, 8,
- &v2_mb_type[0][1], 2, 1,
- &v2_mb_type[0][0], 2, 1, 1);
- init_vlc(&v2_mv_vlc, V2_MV_VLC_BITS, 33,
- &mvtab[0][1], 2, 1,
- &mvtab[0][0], 2, 1, 1);
-
- for(i=0; i<4; i++){
- init_vlc(&mb_non_intra_vlc[i], MB_NON_INTRA_VLC_BITS, 128,
- &wmv2_inter_table[i][0][1], 8, 4,
- &wmv2_inter_table[i][0][0], 8, 4, 1); //FIXME name?
- }
-
- 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, 1);
-
- init_vlc(&v1_intra_cbpc_vlc, V1_INTRA_CBPC_VLC_BITS, 8,
- intra_MCBPC_bits, 1, 1,
- intra_MCBPC_code, 1, 1, 1);
- init_vlc(&v1_inter_cbpc_vlc, V1_INTER_CBPC_VLC_BITS, 25,
- inter_MCBPC_bits, 1, 1,
- inter_MCBPC_code, 1, 1, 1);
-
- init_vlc(&inter_intra_vlc, INTER_INTRA_VLC_BITS, 4,
- &table_inter_intra[0][1], 2, 1,
- &table_inter_intra[0][0], 2, 1, 1);
- }
-
- switch(s->msmpeg4_version){
- case 1:
- case 2:
- s->decode_mb= msmpeg4v12_decode_mb;
- break;
- case 3:
- case 4:
- s->decode_mb= msmpeg4v34_decode_mb;
- break;
- case 5:
- s->decode_mb= wmv2_decode_mb;
- case 6:
- //FIXME + TODO VC1 decode mb
- break;
- }
-
- s->slice_height= s->mb_height; //to avoid 1/0 if the first frame isnt a keyframe
-
- return 0;
-}
-
-int msmpeg4_decode_picture_header(MpegEncContext * s)
-{
- int code;
-
-#if 0
-{
-int i;
-for(i=0; i<s->gb.size_in_bits; i++)
- av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb));
-// get_bits1(&s->gb);
-av_log(s->avctx, AV_LOG_DEBUG, "END\n");
-return -1;
-}
-#endif
-
- if(s->msmpeg4_version==1){
- int start_code, num;
- start_code = (get_bits(&s->gb, 16)<<16) | get_bits(&s->gb, 16);
- if(start_code!=0x00000100){
- av_log(s->avctx, AV_LOG_ERROR, "invalid startcode\n");
- return -1;
- }
-
- num= get_bits(&s->gb, 5); // frame number */
- }
-
- s->pict_type = get_bits(&s->gb, 2) + 1;
- if (s->pict_type != I_TYPE &&
- s->pict_type != P_TYPE){
- av_log(s->avctx, AV_LOG_ERROR, "invalid picture type\n");
- return -1;
- }
-#if 0
-{
- static int had_i=0;
- if(s->pict_type == I_TYPE) had_i=1;
- if(!had_i) return -1;
-}
-#endif
- s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
- if(s->qscale==0){
- av_log(s->avctx, AV_LOG_ERROR, "invalid qscale\n");
- return -1;
- }
-
- if (s->pict_type == I_TYPE) {
- code = get_bits(&s->gb, 5);
- if(s->msmpeg4_version==1){
- if(code==0 || code>s->mb_height){
- av_log(s->avctx, AV_LOG_ERROR, "invalid slice height %d\n", code);
- return -1;
- }
-
- s->slice_height = code;
- }else{
- /* 0x17: one slice, 0x18: two slices, ... */
- if (code < 0x17){
- av_log(s->avctx, AV_LOG_ERROR, "error, slice code was %X\n", code);
- return -1;
- }
-
- s->slice_height = s->mb_height / (code - 0x16);
- }
-
- switch(s->msmpeg4_version){
- case 1:
- case 2:
- s->rl_chroma_table_index = 2;
- s->rl_table_index = 2;
-
- s->dc_table_index = 0; //not used
- break;
- case 3:
- s->rl_chroma_table_index = decode012(&s->gb);
- s->rl_table_index = decode012(&s->gb);
-
- s->dc_table_index = get_bits1(&s->gb);
- break;
- case 4:
- msmpeg4_decode_ext_header(s, (2+5+5+17+7)/8);
-
- if(s->bit_rate > MBAC_BITRATE) s->per_mb_rl_table= get_bits1(&s->gb);
- else s->per_mb_rl_table= 0;
-
- if(!s->per_mb_rl_table){
- s->rl_chroma_table_index = decode012(&s->gb);
- s->rl_table_index = decode012(&s->gb);
- }
-
- s->dc_table_index = get_bits1(&s->gb);
- s->inter_intra_pred= 0;
- break;
- }
- s->no_rounding = 1;
- if(s->avctx->debug&FF_DEBUG_PICT_INFO)
- av_log(s->avctx, AV_LOG_DEBUG, "qscale:%d rlc:%d rl:%d dc:%d mbrl:%d slice:%d \n",
- s->qscale,
- s->rl_chroma_table_index,
- s->rl_table_index,
- s->dc_table_index,
- s->per_mb_rl_table,
- s->slice_height);
- } else {
- switch(s->msmpeg4_version){
- case 1:
- case 2:
- if(s->msmpeg4_version==1)
- s->use_skip_mb_code = 1;
- else
- s->use_skip_mb_code = get_bits1(&s->gb);
- s->rl_table_index = 2;
- s->rl_chroma_table_index = s->rl_table_index;
- s->dc_table_index = 0; //not used
- s->mv_table_index = 0;
- break;
- case 3:
- s->use_skip_mb_code = get_bits1(&s->gb);
- s->rl_table_index = decode012(&s->gb);
- s->rl_chroma_table_index = s->rl_table_index;
-
- s->dc_table_index = get_bits1(&s->gb);
-
- s->mv_table_index = get_bits1(&s->gb);
- break;
- case 4:
- s->use_skip_mb_code = get_bits1(&s->gb);
-
- if(s->bit_rate > MBAC_BITRATE) s->per_mb_rl_table= get_bits1(&s->gb);
- else s->per_mb_rl_table= 0;
-
- if(!s->per_mb_rl_table){
- s->rl_table_index = decode012(&s->gb);
- s->rl_chroma_table_index = s->rl_table_index;
- }
-
- s->dc_table_index = get_bits1(&s->gb);
-
- s->mv_table_index = get_bits1(&s->gb);
- s->inter_intra_pred= (s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE);
- break;
- }
-
- if(s->avctx->debug&FF_DEBUG_PICT_INFO)
- av_log(s->avctx, AV_LOG_DEBUG, "skip:%d rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d \n",
- s->use_skip_mb_code,
- s->rl_table_index,
- s->rl_chroma_table_index,
- s->dc_table_index,
- s->mv_table_index,
- s->per_mb_rl_table,
- s->qscale);
-
- if(s->flipflop_rounding){
- s->no_rounding ^= 1;
- }else{
- s->no_rounding = 0;
- }
- }
-//printf("%d %d %d %d %d\n", s->pict_type, s->bit_rate, s->inter_intra_pred, s->width, s->height);
-
- s->esc3_level_length= 0;
- s->esc3_run_length= 0;
-
-#ifdef DEBUG
- av_log(s->avctx, AV_LOG_DEBUG, "*****frame %d:\n", frame_count++);
-#endif
- return 0;
-}
-
-int msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size)
-{
- int left= buf_size*8 - get_bits_count(&s->gb);
- int length= s->msmpeg4_version>=3 ? 17 : 16;
- /* the alt_bitstream reader could read over the end so we need to check it */
- if(left>=length && left<length+8)
- {
- int fps;
-
- fps= get_bits(&s->gb, 5);
- s->bit_rate= get_bits(&s->gb, 11)*1024;
- if(s->msmpeg4_version>=3)
- s->flipflop_rounding= get_bits1(&s->gb);
- else
- s->flipflop_rounding= 0;
-
-// printf("fps:%2d bps:%2d roundingType:%1d\n", fps, s->bit_rate/1024, s->flipflop_rounding);
- }
- else if(left<length+8)
- {
- s->flipflop_rounding= 0;
- if(s->msmpeg4_version != 2)
- av_log(s->avctx, AV_LOG_ERROR, "ext header missing, %d left\n", left);
- }
- else
- {
- av_log(s->avctx, AV_LOG_ERROR, "I frame too long, ignoring ext header\n");
- }
-
- return 0;
-}
-
-static inline void msmpeg4_memsetw(short *tab, int val, int n)
-{
- int i;
- for(i=0;i<n;i++)
- tab[i] = val;
-}
-
-#ifdef CONFIG_ENCODERS
-static void msmpeg4v2_encode_motion(MpegEncContext * s, int val)
-{
- int range, 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 = 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);
- }
- }
-}
-#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;
-
- 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 == 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==P_TYPE) cbp^=0x3C;
- }
- }
-
- s->dsp.clear_blocks(s->block[0]);
- for (i = 0; i < 6; i++) {
- if (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 == 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, 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 = 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 (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, 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 (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
-static inline int msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block,
- int n, int coded, const uint8_t *scan_table)
-{
- int level, i, last, run, run_diff;
- int dc_pred_dir;
- RLTable *rl;
- RL_VLC_ELEM *rl_vlc;
- int qmul, qadd;
-
- if (s->mb_intra) {
- qmul=1;
- qadd=0;
-
- /* DC coef */
- level = msmpeg4_decode_dc(s, n, &dc_pred_dir);
-
- if (level < 0){
- av_log(s->avctx, AV_LOG_ERROR, "dc overflow- block: %d qscale: %d//\n", n, s->qscale);
- if(s->inter_intra_pred) level=0;
- else return -1;
- }
- if (n < 4) {
- rl = &rl_table[s->rl_table_index];
- if(level > 256*s->y_dc_scale){
- av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ L qscale: %d//\n", s->qscale);
- if(!s->inter_intra_pred) return -1;
- }
- } else {
- rl = &rl_table[3 + s->rl_chroma_table_index];
- if(level > 256*s->c_dc_scale){
- av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ C qscale: %d//\n", s->qscale);
- if(!s->inter_intra_pred) return -1;
- }
- }
- block[0] = level;
-
- run_diff = 0;
- i = 0;
- if (!coded) {
- goto not_coded;
- }
- if (s->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;
- }
- rl_vlc= rl->rl_vlc[0];
- } else {
- qmul = s->qscale << 1;
- qadd = (s->qscale - 1) | 1;
- i = -1;
- rl = &rl_table[3 + s->rl_table_index];
-
- if(s->msmpeg4_version==2)
- run_diff = 0;
- else
- run_diff = 1;
-
- if (!coded) {
- s->block_last_index[n] = i;
- return 0;
- }
- if(!scan_table)
- scan_table = s->inter_scantable.permutated;
- rl_vlc= rl->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) {
- int cache;
- cache= GET_CACHE(re, &s->gb);
- /* escape */
- if (s->msmpeg4_version==1 || (cache&0x80000000)==0) {
- if (s->msmpeg4_version==1 || (cache&0x40000000)==0) {
- /* third escape */
- if(s->msmpeg4_version!=1) LAST_SKIP_BITS(re, &s->gb, 2);
- UPDATE_CACHE(re, &s->gb);
- if(s->msmpeg4_version<=3){
- last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1);
- run= SHOW_UBITS(re, &s->gb, 6); SKIP_CACHE(re, &s->gb, 6);
- level= SHOW_SBITS(re, &s->gb, 8); LAST_SKIP_CACHE(re, &s->gb, 8);
- SKIP_COUNTER(re, &s->gb, 1+6+8);
- }else{
- int sign;
- last= SHOW_UBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1);
- if(!s->esc3_level_length){
- int ll;
- //printf("ESC-3 %X at %d %d\n", show_bits(&s->gb, 24), s->mb_x, s->mb_y);
- 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;
- }
- }else{
- ll=2;
- while(ll<8 && SHOW_UBITS(re, &s->gb, 1)==0){
- ll++;
- SKIP_BITS(re, &s->gb, 1);
- }
- if(ll<8) SKIP_BITS(re, &s->gb, 1);
- }
-
- s->esc3_level_length= ll;
- s->esc3_run_length= SHOW_UBITS(re, &s->gb, 2) + 3; SKIP_BITS(re, &s->gb, 2);
-//printf("level length:%d, run length: %d\n", ll, s->esc3_run_length);
- UPDATE_CACHE(re, &s->gb);
- }
- run= SHOW_UBITS(re, &s->gb, s->esc3_run_length);
- SKIP_BITS(re, &s->gb, s->esc3_run_length);
-
- sign= SHOW_UBITS(re, &s->gb, 1);
- SKIP_BITS(re, &s->gb, 1);
-
- level= SHOW_UBITS(re, &s->gb, s->esc3_level_length);
- SKIP_BITS(re, &s->gb, s->esc3_level_length);
- if(sign) level= -level;
- }
-//printf("level: %d, run: %d at %d %d\n", level, run, s->mb_x, s->mb_y);
-#if 0 // waste of time / this will detect very few errors
- {
- const int abs_level= FFABS(level);
- const int run1= run - rl->max_run[last][abs_level] - run_diff;
- if(abs_level<=MAX_LEVEL && run<=MAX_RUN){
- if(abs_level <= rl->max_level[last][run]){
- av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, vlc encoding possible\n");
- return DECODING_AC_LOST;
- }
- 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 DECODING_AC_LOST;
- }
- 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 DECODING_AC_LOST;
- }
- }
- }
-#endif
- //level = level * qmul + (level>0) * qadd - (level<=0) * qadd ;
- if (level>0) level= level * qmul + qadd;
- else level= level * qmul - qadd;
-#if 0 // waste of time too :(
- if(level>2048 || level<-2048){
- av_log(s->avctx, AV_LOG_ERROR, "|level| overflow in 3. esc\n");
- return DECODING_AC_LOST;
- }
-#endif
- i+= run + 1;
- if(last) i+=192;
-#ifdef ERROR_DETAILS
- if(run==66)
- av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC3 level=%d\n", level);
- else if((i>62 && i<192) || i>192+63)
- av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC3 i=%d run=%d level=%d\n", i, run, level);
-#endif
- } else {
- /* second escape */
-#if MIN_CACHE_BITS < 23
- 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] + run_diff; //FIXME opt indexing
- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
- LAST_SKIP_BITS(re, &s->gb, 1);
-#ifdef ERROR_DETAILS
- if(run==66)
- av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC2 level=%d\n", level);
- else if((i>62 && i<192) || i>192+63)
- av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC2 i=%d run=%d level=%d\n", i, run, level);
-#endif
- }
- } else {
- /* first escape */
-#if MIN_CACHE_BITS < 22
- 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);
-#ifdef ERROR_DETAILS
- if(run==66)
- av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC1 level=%d\n", level);
- else if((i>62 && i<192) || i>192+63)
- av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC1 i=%d run=%d level=%d\n", i, run, level);
-#endif
- }
- } else {
- i+= run;
- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
- LAST_SKIP_BITS(re, &s->gb, 1);
-#ifdef ERROR_DETAILS
- if(run==66)
- av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code level=%d\n", level);
- else if((i>62 && i<192) || i>192+63)
- av_log(s->avctx, AV_LOG_ERROR, "run overflow i=%d run=%d level=%d\n", i, run, level);
-#endif
- }
- if (i > 62){
- i-= 192;
- if(i&(~63)){
- const int left= s->gb.size_in_bits - get_bits_count(&s->gb);
- if(((i+192 == 64 && level/qmul==-1) || s->error_resilience<=1) && left>=0){
- av_log(s->avctx, AV_LOG_ERROR, "ignoring overflow at %d %d\n", s->mb_x, s->mb_y);
- break;
- }else{
- 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 (s->mb_intra) {
- mpeg4_pred_ac(s, block, n, dc_pred_dir);
- if (s->ac_pred) {
- i = 63; /* XXX: not optimal */
- }
- }
- if(s->msmpeg4_version>=4 && i>0) i=63; //FIXME/XXX optimize
- s->block_last_index[n] = i;
-
- 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;
-}
-
-static int msmpeg4_decode_motion(MpegEncContext * s,
- int *mx_ptr, int *my_ptr)
-{
- MVTable *mv;
- int code, mx, my;
-
- mv = &mv_tables[s->mv_table_index];
-
- code = get_vlc2(&s->gb, mv->vlc.table, MV_VLC_BITS, 2);
- if (code < 0){
- av_log(s->avctx, AV_LOG_ERROR, "illegal MV code at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- if (code == mv->n) {
-//printf("MV ESC %X at %d %d\n", show_bits(&s->gb, 24), s->mb_x, s->mb_y);
- mx = get_bits(&s->gb, 6);
- my = get_bits(&s->gb, 6);
- } else {
- mx = mv->table_mvx[code];
- my = mv->table_mvy[code];
- }
-
- mx += *mx_ptr - 32;
- my += *my_ptr - 32;
- /* WARNING : they do not do exactly modulo encoding */
- if (mx <= -64)
- mx += 64;
- else if (mx >= 64)
- mx -= 64;
-
- if (my <= -64)
- my += 64;
- else if (my >= 64)
- my -= 64;
- *mx_ptr = mx;
- *my_ptr = my;
- return 0;
-}
-
-/* cleanest way to support it
- * there is too much shared between versions so that we cant have 1 file per version & 1 common
- * as allmost everything would be in the common file
- */
-#include "wmv2.c"
diff --git a/src/libffmpeg/libavcodec/nuv.c b/src/libffmpeg/libavcodec/nuv.c
deleted file mode 100644
index 19e343056..000000000
--- a/src/libffmpeg/libavcodec/nuv.c
+++ /dev/null
@@ -1,216 +0,0 @@
-/*
- * NuppelVideo decoder
- * Copyright (c) 2006 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 <stdio.h>
-#include <stdlib.h>
-
-#include "common.h"
-#include "avcodec.h"
-
-#include "bswap.h"
-#include "dsputil.h"
-#include "lzo.h"
-#include "rtjpeg.h"
-
-typedef struct {
- AVFrame pic;
- int width, height;
- unsigned int decomp_size;
- unsigned char* decomp_buf;
- uint32_t lq[64], cq[64];
- RTJpegContext rtj;
- DSPContext dsp;
-} NuvContext;
-
-/**
- * \brief copy frame data from buffer to AVFrame, handling stride.
- * \param f destination AVFrame
- * \param src source buffer, does not use any line-stride
- * \param width width of the video frame
- * \param height height of the video frame
- */
-static void copy_frame(AVFrame *f, uint8_t *src,
- int width, int height) {
- AVPicture pic;
- avpicture_fill(&pic, src, PIX_FMT_YUV420P, width, height);
- img_copy((AVPicture *)f, &pic, PIX_FMT_YUV420P, width, height);
-}
-
-/**
- * \brief extract quantization tables from codec data into our context
- */
-static int get_quant(AVCodecContext *avctx, NuvContext *c,
- uint8_t *buf, int size) {
- int i;
- if (size < 2 * 64 * 4) {
- av_log(avctx, AV_LOG_ERROR, "insufficient rtjpeg quant data\n");
- return -1;
- }
- for (i = 0; i < 64; i++, buf += 4)
- c->lq[i] = AV_RL32(buf);
- for (i = 0; i < 64; i++, buf += 4)
- c->cq[i] = AV_RL32(buf);
- return 0;
-}
-
-static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
- uint8_t *buf, int buf_size) {
- NuvContext *c = (NuvContext *)avctx->priv_data;
- AVFrame *picture = data;
- int orig_size = buf_size;
- enum {NUV_UNCOMPRESSED = '0', NUV_RTJPEG = '1',
- NUV_RTJPEG_IN_LZO = '2', NUV_LZO = '3',
- NUV_BLACK = 'N', NUV_COPY_LAST = 'L'} comptype;
-
- if (buf_size < 12) {
- av_log(avctx, AV_LOG_ERROR, "coded frame too small\n");
- return -1;
- }
-
- if (c->pic.data[0])
- avctx->release_buffer(avctx, &c->pic);
- c->pic.reference = 1;
- c->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_READABLE |
- FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
- if (avctx->get_buffer(avctx, &c->pic) < 0) {
- av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
- return -1;
- }
-
- // codec data (rtjpeg quant tables)
- if (buf[0] == 'D' && buf[1] == 'R') {
- int ret;
- // skip rest of the frameheader.
- buf = &buf[12];
- buf_size -= 12;
- ret = get_quant(avctx, c, buf, buf_size);
- if (ret < 0)
- return ret;
- rtjpeg_decode_init(&c->rtj, &c->dsp, c->width, c->height, c->lq, c->cq);
- return orig_size;
- }
-
- if (buf[0] != 'V' || buf_size < 12) {
- av_log(avctx, AV_LOG_ERROR, "not a nuv video frame\n");
- return -1;
- }
- comptype = buf[1];
- // skip rest of the frameheader.
- buf = &buf[12];
- buf_size -= 12;
-
- c->pic.pict_type = FF_I_TYPE;
- c->pic.key_frame = 1;
- // decompress/copy/whatever data
- switch (comptype) {
- case NUV_UNCOMPRESSED: {
- int height = c->height;
- if (buf_size < c->width * height * 3 / 2) {
- av_log(avctx, AV_LOG_ERROR, "uncompressed frame too short\n");
- height = buf_size / c->width / 3 * 2;
- }
- copy_frame(&c->pic, buf, c->width, height);
- break;
- }
- case NUV_RTJPEG: {
- rtjpeg_decode_frame_yuv420(&c->rtj, &c->pic, buf, buf_size);
- break;
- }
- case NUV_RTJPEG_IN_LZO: {
- int outlen = c->decomp_size, inlen = buf_size;
- if (lzo1x_decode(c->decomp_buf, &outlen, buf, &inlen))
- av_log(avctx, AV_LOG_ERROR, "error during lzo decompression\n");
- rtjpeg_decode_frame_yuv420(&c->rtj, &c->pic, c->decomp_buf, c->decomp_size);
- break;
- }
- case NUV_LZO: {
- int outlen = c->decomp_size, inlen = buf_size;
- if (lzo1x_decode(c->decomp_buf, &outlen, buf, &inlen))
- av_log(avctx, AV_LOG_ERROR, "error during lzo decompression\n");
- copy_frame(&c->pic, c->decomp_buf, c->width, c->height);
- break;
- }
- case NUV_BLACK: {
- memset(c->pic.data[0], 0, c->width * c->height);
- memset(c->pic.data[1], 128, c->width * c->height / 4);
- memset(c->pic.data[2], 128, c->width * c->height / 4);
- break;
- }
- case NUV_COPY_LAST: {
- c->pic.pict_type = FF_P_TYPE;
- c->pic.key_frame = 0;
- /* nothing more to do here */
- break;
- }
- default:
- av_log(avctx, AV_LOG_ERROR, "unknown compression\n");
- return -1;
- }
-
- *picture = c->pic;
- *data_size = sizeof(AVFrame);
- return orig_size;
-}
-
-static int decode_init(AVCodecContext *avctx) {
- NuvContext *c = (NuvContext *)avctx->priv_data;
- avctx->width = (avctx->width + 1) & ~1;
- avctx->height = (avctx->height + 1) & ~1;
- if (avcodec_check_dimensions(avctx, avctx->height, avctx->width) < 0) {
- return 1;
- }
- avctx->has_b_frames = 0;
- avctx->pix_fmt = PIX_FMT_YUV420P;
- c->pic.data[0] = NULL;
- c->width = avctx->width;
- c->height = avctx->height;
- c->decomp_size = c->height * c->width * 3 / 2;
- c->decomp_buf = av_malloc(c->decomp_size + LZO_OUTPUT_PADDING);
- if (!c->decomp_buf) {
- av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
- return 1;
- }
- dsputil_init(&c->dsp, avctx);
- if (avctx->extradata_size)
- get_quant(avctx, c, avctx->extradata, avctx->extradata_size);
- rtjpeg_decode_init(&c->rtj, &c->dsp, c->width, c->height, c->lq, c->cq);
- return 0;
-}
-
-static int decode_end(AVCodecContext *avctx) {
- NuvContext *c = (NuvContext *)avctx->priv_data;
- av_freep(&c->decomp_buf);
- if (c->pic.data[0])
- avctx->release_buffer(avctx, &c->pic);
- return 0;
-}
-
-AVCodec nuv_decoder = {
- "nuv",
- CODEC_TYPE_VIDEO,
- CODEC_ID_NUV,
- sizeof(NuvContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
-};
-
diff --git a/src/libffmpeg/libavcodec/opt.c b/src/libffmpeg/libavcodec/opt.c
deleted file mode 100644
index 70babd587..000000000
--- a/src/libffmpeg/libavcodec/opt.c
+++ /dev/null
@@ -1,381 +0,0 @@
-/*
- * AVOptions
- * Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-/**
- * @file opt.c
- * AVOptions
- * @author Michael Niedermayer <michaelni@gmx.at>
- */
-
-#include "avcodec.h"
-#include "opt.h"
-#include "eval.h"
-
-//FIXME order them and do a bin search
-static const AVOption *find_opt(void *v, const char *name, const char *unit){
- AVClass *c= *(AVClass**)v; //FIXME silly way of storing AVClass
- const AVOption *o= c->option;
-
- for(;o && o->name; o++){
- if(!strcmp(o->name, name) && (!unit || !strcmp(o->unit, unit)) )
- return o;
- }
- return NULL;
-}
-
-const AVOption *av_next_option(void *obj, const AVOption *last){
- if(last && last[1].name) return ++last;
- else if(last) return NULL;
- else return (*(AVClass**)obj)->option;
-}
-
-static const AVOption *av_set_number(void *obj, const char *name, double num, int den, int64_t intnum){
- const AVOption *o= find_opt(obj, name, NULL);
- void *dst;
- if(!o || o->offset<=0)
- return NULL;
-
- if(o->max*den < num*intnum || o->min*den > num*intnum) {
- av_log(NULL, AV_LOG_ERROR, "Value %lf for parameter '%s' out of range.\n", num, name);
- return NULL;
- }
-
- dst= ((uint8_t*)obj) + o->offset;
-
- switch(o->type){
- case FF_OPT_TYPE_FLAGS:
- case FF_OPT_TYPE_INT: *(int *)dst= lrintf(num/den)*intnum; break;
- case FF_OPT_TYPE_INT64: *(int64_t *)dst= lrintf(num/den)*intnum; break;
- case FF_OPT_TYPE_FLOAT: *(float *)dst= num*intnum/den; break;
- case FF_OPT_TYPE_DOUBLE:*(double *)dst= num*intnum/den; break;
- case FF_OPT_TYPE_RATIONAL:
- if((int)num == num) *(AVRational*)dst= (AVRational){num*intnum, den};
- else *(AVRational*)dst= av_d2q(num*intnum/den, 1<<24);
- default:
- return NULL;
- }
- return o;
-}
-
-static const AVOption *set_all_opt(void *v, const char *unit, double d){
- AVClass *c= *(AVClass**)v; //FIXME silly way of storing AVClass
- const AVOption *o= c->option;
- const AVOption *ret=NULL;
-
- for(;o && o->name; o++){
- if(o->type != FF_OPT_TYPE_CONST && o->unit && !strcmp(o->unit, unit)){
- double tmp= d;
- if(o->type == FF_OPT_TYPE_FLAGS)
- tmp= av_get_int(v, o->name, NULL) | (int64_t)d;
-
- av_set_number(v, o->name, tmp, 1, 1);
- ret= o;
- }
- }
- return ret;
-}
-
-static double const_values[]={
- M_PI,
- M_E,
- FF_QP2LAMBDA,
- 0
-};
-
-static const char *const_names[]={
- "PI",
- "E",
- "QP2LAMBDA",
- 0
-};
-
-const AVOption *av_set_string(void *obj, const char *name, const char *val){
- const AVOption *o= find_opt(obj, name, NULL);
- if(o && o->offset==0 && o->type == FF_OPT_TYPE_CONST && o->unit){
- return set_all_opt(obj, o->unit, o->default_val);
- }
- if(!o || !val || o->offset<=0)
- return NULL;
- if(o->type != FF_OPT_TYPE_STRING){
- for(;;){
- int i;
- char buf[256];
- int cmd=0;
- double d;
- char *error = NULL;
-
- if(*val == '+' || *val == '-')
- cmd= *(val++);
-
- for(i=0; i<sizeof(buf)-1 && val[i] && val[i]!='+' && val[i]!='-'; i++)
- buf[i]= val[i];
- buf[i]=0;
- val+= i;
-
- d = ff_eval2(buf, const_values, const_names, NULL, NULL, NULL, NULL, NULL, &error);
- if(isnan(d)) {
- const AVOption *o_named= find_opt(obj, buf, o->unit);
- if(o_named && o_named->type == FF_OPT_TYPE_CONST)
- d= o_named->default_val;
- else if(!strcmp(buf, "default")) d= o->default_val;
- else if(!strcmp(buf, "max" )) d= o->max;
- else if(!strcmp(buf, "min" )) d= o->min;
- else {
- if (!error)
- av_log(NULL, AV_LOG_ERROR, "Unable to parse option value \"%s\": %s\n", val, error);
- return NULL;
- }
- }
- if(o->type == FF_OPT_TYPE_FLAGS){
- if (cmd=='+') d= av_get_int(obj, name, NULL) | (int64_t)d;
- else if(cmd=='-') d= av_get_int(obj, name, NULL) &~(int64_t)d;
- }else if(cmd=='-')
- d= -d;
-
- av_set_number(obj, name, d, 1, 1);
- if(!*val)
- return o;
- }
- return NULL;
- }
-
- memcpy(((uint8_t*)obj) + o->offset, val, sizeof(val));
- return o;
-}
-
-const AVOption *av_set_double(void *obj, const char *name, double n){
- return av_set_number(obj, name, n, 1, 1);
-}
-
-const AVOption *av_set_q(void *obj, const char *name, AVRational n){
- return av_set_number(obj, name, n.num, n.den, 1);
-}
-
-const AVOption *av_set_int(void *obj, const char *name, int64_t n){
- return av_set_number(obj, name, 1, 1, n);
-}
-
-/**
- *
- * @param buf a buffer which is used for returning non string values as strings, can be NULL
- * @param buf_len allocated length in bytes of buf
- */
-const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len){
- const AVOption *o= find_opt(obj, name, NULL);
- void *dst;
- if(!o || o->offset<=0)
- return NULL;
- if(o->type != FF_OPT_TYPE_STRING && (!buf || !buf_len))
- return NULL;
-
- dst= ((uint8_t*)obj) + o->offset;
- if(o_out) *o_out= o;
-
- if(o->type == FF_OPT_TYPE_STRING)
- return dst;
-
- switch(o->type){
- case FF_OPT_TYPE_FLAGS: snprintf(buf, buf_len, "0x%08X",*(int *)dst);break;
- case FF_OPT_TYPE_INT: snprintf(buf, buf_len, "%d" , *(int *)dst);break;
- case FF_OPT_TYPE_INT64: snprintf(buf, buf_len, "%"PRId64, *(int64_t*)dst);break;
- case FF_OPT_TYPE_FLOAT: snprintf(buf, buf_len, "%f" , *(float *)dst);break;
- case FF_OPT_TYPE_DOUBLE: snprintf(buf, buf_len, "%f" , *(double *)dst);break;
- case FF_OPT_TYPE_RATIONAL: snprintf(buf, buf_len, "%d/%d", ((AVRational*)dst)->num, ((AVRational*)dst)->den);break;
- default: return NULL;
- }
- return buf;
-}
-
-static int av_get_number(void *obj, const char *name, const AVOption **o_out, double *num, int *den, int64_t *intnum){
- const AVOption *o= find_opt(obj, name, NULL);
- void *dst;
- if(!o || o->offset<=0)
- goto error;
-
- dst= ((uint8_t*)obj) + o->offset;
-
- if(o_out) *o_out= o;
-
- switch(o->type){
- case FF_OPT_TYPE_FLAGS:
- case FF_OPT_TYPE_INT: *intnum= *(int *)dst;return 0;
- case FF_OPT_TYPE_INT64: *intnum= *(int64_t*)dst;return 0;
- case FF_OPT_TYPE_FLOAT: *num= *(float *)dst;return 0;
- case FF_OPT_TYPE_DOUBLE: *num= *(double *)dst;return 0;
- case FF_OPT_TYPE_RATIONAL: *intnum= ((AVRational*)dst)->num;
- *den = ((AVRational*)dst)->den;
- return 0;
- }
-error:
- *den=*intnum=0;
- return -1;
-}
-
-double av_get_double(void *obj, const char *name, const AVOption **o_out){
- int64_t intnum=1;
- double num=1;
- int den=1;
-
- av_get_number(obj, name, o_out, &num, &den, &intnum);
- return num*intnum/den;
-}
-
-AVRational av_get_q(void *obj, const char *name, const AVOption **o_out){
- int64_t intnum=1;
- double num=1;
- int den=1;
-
- av_get_number(obj, name, o_out, &num, &den, &intnum);
- if(num == 1.0 && (int)intnum == intnum)
- return (AVRational){intnum, den};
- else
- return av_d2q(num*intnum/den, 1<<24);
-}
-
-int64_t av_get_int(void *obj, const char *name, const AVOption **o_out){
- int64_t intnum=1;
- double num=1;
- int den=1;
-
- av_get_number(obj, name, o_out, &num, &den, &intnum);
- return num*intnum/den;
-}
-
-static void opt_list(void *obj, void *av_log_obj, const char *unit)
-{
- const AVOption *opt=NULL;
-
- while((opt= av_next_option(obj, opt))){
- if(!(opt->flags & (AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM)))
- continue;
-
- /* Don't print CONST's on level one.
- * Don't print anything but CONST's on level two.
- * Only print items from the requested unit.
- */
- if (!unit && opt->type==FF_OPT_TYPE_CONST)
- continue;
- else if (unit && opt->type!=FF_OPT_TYPE_CONST)
- continue;
- else if (unit && opt->type==FF_OPT_TYPE_CONST && strcmp(unit, opt->unit))
- continue;
- else if (unit && opt->type == FF_OPT_TYPE_CONST)
- av_log(av_log_obj, AV_LOG_INFO, " %-15s ", opt->name);
- else
- av_log(av_log_obj, AV_LOG_INFO, "-%-17s ", opt->name);
-
- switch( opt->type )
- {
- case FF_OPT_TYPE_FLAGS:
- av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "<flags>" );
- break;
- case FF_OPT_TYPE_INT:
- av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "<int>" );
- break;
- case FF_OPT_TYPE_INT64:
- av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "<int64>" );
- break;
- case FF_OPT_TYPE_DOUBLE:
- av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "<double>" );
- break;
- case FF_OPT_TYPE_FLOAT:
- av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "<float>" );
- break;
- case FF_OPT_TYPE_STRING:
- av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "<string>" );
- break;
- case FF_OPT_TYPE_RATIONAL:
- av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "<rational>" );
- break;
- case FF_OPT_TYPE_CONST:
- default:
- av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "" );
- break;
- }
- av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_ENCODING_PARAM) ? 'E' : '.');
- av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_DECODING_PARAM) ? 'D' : '.');
- av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_VIDEO_PARAM ) ? 'V' : '.');
- av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_AUDIO_PARAM ) ? 'A' : '.');
- av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_SUBTITLE_PARAM) ? 'S' : '.');
-
- if(opt->help)
- av_log(av_log_obj, AV_LOG_INFO, " %s", opt->help);
- av_log(av_log_obj, AV_LOG_INFO, "\n");
- if (opt->unit && opt->type != FF_OPT_TYPE_CONST) {
- opt_list(obj, av_log_obj, opt->unit);
- }
- }
-}
-
-int av_opt_show(void *obj, void *av_log_obj){
- if(!obj)
- return -1;
-
- av_log(av_log_obj, AV_LOG_INFO, "%s AVOptions:\n", (*(AVClass**)obj)->class_name);
-
- opt_list(obj, av_log_obj, NULL);
-
- return 0;
-}
-
-/** Set the values of the AVCodecContext or AVFormatContext structure.
- * They are set to the defaults specified in the according AVOption options
- * array default_val field.
- *
- * @param s AVCodecContext or AVFormatContext for which the defaults will be set
- */
-void av_opt_set_defaults(void *s)
-{
- const AVOption *opt = NULL;
- while ((opt = av_next_option(s, opt)) != NULL) {
- switch(opt->type) {
- case FF_OPT_TYPE_CONST:
- /* Nothing to be done here */
- break;
- case FF_OPT_TYPE_FLAGS:
- case FF_OPT_TYPE_INT: {
- int val;
- val = opt->default_val;
- av_set_int(s, opt->name, val);
- }
- break;
- case FF_OPT_TYPE_FLOAT: {
- double val;
- val = opt->default_val;
- av_set_double(s, opt->name, val);
- }
- break;
- case FF_OPT_TYPE_RATIONAL: {
- AVRational val;
- val = av_d2q(opt->default_val, INT_MAX);
- av_set_q(s, opt->name, val);
- }
- break;
- case FF_OPT_TYPE_STRING:
- /* Cannot set default for string as default_val is of type * double */
- break;
- default:
- av_log(s, AV_LOG_DEBUG, "AVOption type %d of option %s not implemented yet\n", opt->type, opt->name);
- }
- }
-}
-
diff --git a/src/libffmpeg/libavcodec/opt.h b/src/libffmpeg/libavcodec/opt.h
deleted file mode 100644
index ff65456d8..000000000
--- a/src/libffmpeg/libavcodec/opt.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * AVOptions
- * copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef AVOPT_H
-#define AVOPT_H
-
-/**
- * @file opt.h
- * AVOptions
- */
-
-enum AVOptionType{
- FF_OPT_TYPE_FLAGS,
- FF_OPT_TYPE_INT,
- FF_OPT_TYPE_INT64,
- FF_OPT_TYPE_DOUBLE,
- FF_OPT_TYPE_FLOAT,
- FF_OPT_TYPE_STRING,
- FF_OPT_TYPE_RATIONAL,
- FF_OPT_TYPE_CONST=128,
-};
-
-/**
- * AVOption.
- */
-typedef struct AVOption {
- const char *name;
-
- /**
- * short English text help.
- * @fixme what about other languages
- */
- const char *help;
- int offset; ///< offset to context structure where the parsed value should be stored
- enum AVOptionType type;
-
- double default_val;
- double min;
- double max;
-
- 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
- const char *unit;
-} AVOption;
-
-
-const AVOption *av_set_string(void *obj, const char *name, const char *val);
-const AVOption *av_set_double(void *obj, const char *name, double n);
-const AVOption *av_set_q(void *obj, const char *name, AVRational n);
-const AVOption *av_set_int(void *obj, const char *name, int64_t n);
-double av_get_double(void *obj, const char *name, const AVOption **o_out);
-AVRational av_get_q(void *obj, const char *name, const AVOption **o_out);
-int64_t av_get_int(void *obj, const char *name, const AVOption **o_out);
-const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len);
-const AVOption *av_next_option(void *obj, const AVOption *last);
-int av_opt_show(void *obj, void *av_log_obj);
-void av_opt_set_defaults(void *s);
-
-#endif
diff --git a/src/libffmpeg/libavcodec/parser.c b/src/libffmpeg/libavcodec/parser.c
deleted file mode 100644
index 62a95c1a4..000000000
--- a/src/libffmpeg/libavcodec/parser.c
+++ /dev/null
@@ -1,902 +0,0 @@
-/*
- * Audio and Video frame extraction
- * Copyright (c) 2003 Fabrice Bellard.
- * 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 "avcodec.h"
-#include "mpegvideo.h"
-#include "mpegaudio.h"
-#include "parser.h"
-
-AVCodecParser *av_first_parser = NULL;
-
-void av_register_codec_parser(AVCodecParser *parser)
-{
- parser->next = av_first_parser;
- av_first_parser = parser;
-}
-
-AVCodecParserContext *av_parser_init(int codec_id)
-{
- AVCodecParserContext *s;
- AVCodecParser *parser;
- int ret;
-
- if(codec_id == CODEC_ID_NONE)
- return NULL;
-
- for(parser = av_first_parser; parser != NULL; parser = parser->next) {
- if (parser->codec_ids[0] == codec_id ||
- parser->codec_ids[1] == codec_id ||
- parser->codec_ids[2] == codec_id ||
- parser->codec_ids[3] == codec_id ||
- parser->codec_ids[4] == codec_id)
- goto found;
- }
- return NULL;
- found:
- s = av_mallocz(sizeof(AVCodecParserContext));
- if (!s)
- return NULL;
- s->parser = parser;
- s->priv_data = av_mallocz(parser->priv_data_size);
- if (!s->priv_data) {
- av_free(s);
- return NULL;
- }
- if (parser->parser_init) {
- ret = parser->parser_init(s);
- if (ret != 0) {
- av_free(s->priv_data);
- av_free(s);
- return NULL;
- }
- }
- s->fetch_timestamp=1;
- return s;
-}
-
-/**
- *
- * @param buf input
- * @param buf_size input length, to signal EOF, this should be 0 (so that the last frame can be output)
- * @param pts input presentation timestamp
- * @param dts input decoding timestamp
- * @param poutbuf will contain a pointer to the first byte of the output frame
- * @param poutbuf_size will contain the length of the output frame
- * @return the number of bytes of the input bitstream used
- *
- * Example:
- * @code
- * while(in_len){
- * len = av_parser_parse(myparser, AVCodecContext, &data, &size,
- * in_data, in_len,
- * pts, dts);
- * in_data += len;
- * in_len -= len;
- *
- * if(size)
- * decode_frame(data, size);
- * }
- * @endcode
- */
-int av_parser_parse(AVCodecParserContext *s,
- AVCodecContext *avctx,
- uint8_t **poutbuf, int *poutbuf_size,
- const uint8_t *buf, int buf_size,
- int64_t pts, int64_t dts)
-{
- int index, i, k;
- uint8_t dummy_buf[FF_INPUT_BUFFER_PADDING_SIZE];
-
- if (buf_size == 0) {
- /* padding is always necessary even if EOF, so we add it here */
- memset(dummy_buf, 0, sizeof(dummy_buf));
- buf = dummy_buf;
- } else {
- /* add a new packet descriptor */
- k = (s->cur_frame_start_index + 1) & (AV_PARSER_PTS_NB - 1);
- s->cur_frame_start_index = k;
- s->cur_frame_offset[k] = s->cur_offset;
- s->cur_frame_pts[k] = pts;
- s->cur_frame_dts[k] = dts;
-
- /* fill first PTS/DTS */
- if (s->fetch_timestamp){
- s->fetch_timestamp=0;
- s->last_pts = pts;
- s->last_dts = dts;
- s->cur_frame_pts[k] =
- s->cur_frame_dts[k] = AV_NOPTS_VALUE;
- }
- }
-
- /* WARNING: the returned index can be negative */
- index = s->parser->parser_parse(s, avctx, poutbuf, poutbuf_size, buf, buf_size);
-//av_log(NULL, AV_LOG_DEBUG, "parser: in:%"PRId64", %"PRId64", out:%"PRId64", %"PRId64", in:%d out:%d id:%d\n", pts, dts, s->last_pts, s->last_dts, buf_size, *poutbuf_size, avctx->codec_id);
- /* update the file pointer */
- if (*poutbuf_size) {
- /* fill the data for the current frame */
- s->frame_offset = s->last_frame_offset;
- s->pts = s->last_pts;
- s->dts = s->last_dts;
-
- /* offset of the next frame */
- s->last_frame_offset = s->cur_offset + index;
- /* find the packet in which the new frame starts. It
- is tricky because of MPEG video start codes
- which can begin in one packet and finish in
- another packet. In the worst case, an MPEG
- video start code could be in 4 different
- packets. */
- k = s->cur_frame_start_index;
- for(i = 0; i < AV_PARSER_PTS_NB; i++) {
- if (s->last_frame_offset >= s->cur_frame_offset[k])
- break;
- k = (k - 1) & (AV_PARSER_PTS_NB - 1);
- }
-
- s->last_pts = s->cur_frame_pts[k];
- s->last_dts = s->cur_frame_dts[k];
-
- /* some parsers tell us the packet size even before seeing the first byte of the next packet,
- so the next pts/dts is in the next chunk */
- if(index == buf_size){
- s->fetch_timestamp=1;
- }
- }
- if (index < 0)
- index = 0;
- s->cur_offset += index;
- return index;
-}
-
-/**
- *
- * @return 0 if the output buffer is a subset of the input, 1 if it is allocated and must be freed
- * @deprecated use AVBitstreamFilter
- */
-int av_parser_change(AVCodecParserContext *s,
- AVCodecContext *avctx,
- uint8_t **poutbuf, int *poutbuf_size,
- const uint8_t *buf, int buf_size, int keyframe){
-
- if(s && s->parser->split){
- if((avctx->flags & CODEC_FLAG_GLOBAL_HEADER) || (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER)){
- int i= s->parser->split(avctx, buf, buf_size);
- buf += i;
- buf_size -= i;
- }
- }
-
- /* cast to avoid warning about discarding qualifiers */
- *poutbuf= (uint8_t *) buf;
- *poutbuf_size= buf_size;
- if(avctx->extradata){
- if( (keyframe && (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER))
- /*||(s->pict_type != I_TYPE && (s->flags & PARSER_FLAG_DUMP_EXTRADATA_AT_NOKEY))*/
- /*||(? && (s->flags & PARSER_FLAG_DUMP_EXTRADATA_AT_BEGIN)*/){
- int size= buf_size + avctx->extradata_size;
- *poutbuf_size= size;
- *poutbuf= av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
-
- memcpy(*poutbuf, avctx->extradata, avctx->extradata_size);
- memcpy((*poutbuf) + avctx->extradata_size, buf, buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
- return 1;
- }
- }
-
- return 0;
-}
-
-void av_parser_close(AVCodecParserContext *s)
-{
- if (s->parser->parser_close)
- s->parser->parser_close(s);
- av_free(s->priv_data);
- av_free(s);
-}
-
-/*****************************************************/
-
-/**
- * combines the (truncated) bitstream to a complete frame
- * @returns -1 if no complete frame could be created
- */
-int ff_combine_frame(ParseContext *pc, int next, uint8_t **buf, int *buf_size)
-{
-#if 0
- if(pc->overread){
- printf("overread %d, state:%X next:%d index:%d o_index:%d\n", pc->overread, pc->state, next, pc->index, pc->overread_index);
- printf("%X %X %X %X\n", (*buf)[0], (*buf)[1],(*buf)[2],(*buf)[3]);
- }
-#endif
-
- /* copy overreaded bytes from last frame into buffer */
- for(; pc->overread>0; pc->overread--){
- pc->buffer[pc->index++]= pc->buffer[pc->overread_index++];
- }
-
- /* flush remaining if EOF */
- if(!*buf_size && next == END_NOT_FOUND){
- next= 0;
- }
-
- pc->last_index= pc->index;
-
- /* copy into buffer end return */
- if(next == END_NOT_FOUND){
- pc->buffer= av_fast_realloc(pc->buffer, &pc->buffer_size, (*buf_size) + pc->index + FF_INPUT_BUFFER_PADDING_SIZE);
-
- memcpy(&pc->buffer[pc->index], *buf, *buf_size);
- pc->index += *buf_size;
- return -1;
- }
-
- *buf_size=
- pc->overread_index= pc->index + next;
-
- /* append to buffer */
- if(pc->index){
- pc->buffer= av_fast_realloc(pc->buffer, &pc->buffer_size, next + pc->index + FF_INPUT_BUFFER_PADDING_SIZE);
-
- memcpy(&pc->buffer[pc->index], *buf, next + FF_INPUT_BUFFER_PADDING_SIZE );
- pc->index = 0;
- *buf= pc->buffer;
- }
-
- /* store overread bytes */
- for(;next < 0; next++){
- pc->state = (pc->state<<8) | pc->buffer[pc->last_index + next];
- pc->overread++;
- }
-
-#if 0
- if(pc->overread){
- printf("overread %d, state:%X next:%d index:%d o_index:%d\n", pc->overread, pc->state, next, pc->index, pc->overread_index);
- printf("%X %X %X %X\n", (*buf)[0], (*buf)[1],(*buf)[2],(*buf)[3]);
- }
-#endif
-
- return 0;
-}
-
-void ff_parse_close(AVCodecParserContext *s)
-{
- ParseContext *pc = s->priv_data;
-
- av_free(pc->buffer);
-}
-
-void ff_parse1_close(AVCodecParserContext *s)
-{
- ParseContext1 *pc1 = s->priv_data;
-
- av_free(pc1->pc.buffer);
- av_free(pc1->enc);
-}
-
-/*************************/
-
-#ifdef CONFIG_MPEG4VIDEO_PARSER
-/* used by parser */
-/* XXX: make it use less memory */
-static int av_mpeg4_decode_header(AVCodecParserContext *s1,
- AVCodecContext *avctx,
- const uint8_t *buf, int buf_size)
-{
- ParseContext1 *pc = s1->priv_data;
- MpegEncContext *s = pc->enc;
- GetBitContext gb1, *gb = &gb1;
- int ret;
-
- s->avctx = avctx;
- s->current_picture_ptr = &s->current_picture;
-
- if (avctx->extradata_size && pc->first_picture){
- init_get_bits(gb, avctx->extradata, avctx->extradata_size*8);
- ret = ff_mpeg4_decode_picture_header(s, gb);
- }
-
- init_get_bits(gb, buf, 8 * buf_size);
- ret = ff_mpeg4_decode_picture_header(s, gb);
- if (s->width) {
- avcodec_set_dimensions(avctx, s->width, s->height);
- }
- s1->pict_type= s->pict_type;
- pc->first_picture = 0;
- return ret;
-}
-
-static int mpeg4video_parse_init(AVCodecParserContext *s)
-{
- ParseContext1 *pc = s->priv_data;
-
- pc->enc = av_mallocz(sizeof(MpegEncContext));
- if (!pc->enc)
- return -1;
- pc->first_picture = 1;
- return 0;
-}
-
-static int mpeg4video_parse(AVCodecParserContext *s,
- AVCodecContext *avctx,
- uint8_t **poutbuf, int *poutbuf_size,
- const uint8_t *buf, int buf_size)
-{
- ParseContext *pc = s->priv_data;
- int next;
-
- if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){
- next= buf_size;
- }else{
- next= ff_mpeg4_find_frame_end(pc, buf, buf_size);
-
- if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
- *poutbuf = NULL;
- *poutbuf_size = 0;
- return buf_size;
- }
- }
- av_mpeg4_decode_header(s, avctx, buf, buf_size);
-
- *poutbuf = (uint8_t *)buf;
- *poutbuf_size = buf_size;
- return next;
-}
-#endif
-
-int ff_mpeg4video_split(AVCodecContext *avctx,
- const uint8_t *buf, int buf_size)
-{
- int i;
- uint32_t state= -1;
-
- for(i=0; i<buf_size; i++){
- state= (state<<8) | buf[i];
- if(state == 0x1B3 || state == 0x1B6)
- return i-3;
- }
- return 0;
-}
-
-/*************************/
-
-#ifdef CONFIG_MPEGAUDIO_PARSER
-typedef struct MpegAudioParseContext {
- uint8_t inbuf[MPA_MAX_CODED_FRAME_SIZE]; /* input buffer */
- uint8_t *inbuf_ptr;
- int frame_size;
- int free_format_frame_size;
- int free_format_next_header;
- uint32_t header;
- int header_count;
-} MpegAudioParseContext;
-
-#define MPA_HEADER_SIZE 4
-
-/* header + layer + bitrate + freq + lsf/mpeg25 */
-#undef SAME_HEADER_MASK /* mpegaudio.h defines different version */
-#define SAME_HEADER_MASK \
- (0xffe00000 | (3 << 17) | (3 << 10) | (3 << 19))
-
-static int mpegaudio_parse_init(AVCodecParserContext *s1)
-{
- MpegAudioParseContext *s = s1->priv_data;
- s->inbuf_ptr = s->inbuf;
- return 0;
-}
-
-static int mpegaudio_parse(AVCodecParserContext *s1,
- AVCodecContext *avctx,
- uint8_t **poutbuf, int *poutbuf_size,
- const uint8_t *buf, int buf_size)
-{
- MpegAudioParseContext *s = s1->priv_data;
- int len, ret, sr;
- uint32_t header;
- const uint8_t *buf_ptr;
-
- *poutbuf = NULL;
- *poutbuf_size = 0;
- buf_ptr = buf;
- while (buf_size > 0) {
- len = s->inbuf_ptr - s->inbuf;
- if (s->frame_size == 0) {
- /* special case for next header for first frame in free
- format case (XXX: find a simpler method) */
- if (s->free_format_next_header != 0) {
- s->inbuf[0] = s->free_format_next_header >> 24;
- s->inbuf[1] = s->free_format_next_header >> 16;
- s->inbuf[2] = s->free_format_next_header >> 8;
- s->inbuf[3] = s->free_format_next_header;
- s->inbuf_ptr = s->inbuf + 4;
- s->free_format_next_header = 0;
- goto got_header;
- }
- /* no header seen : find one. We need at least MPA_HEADER_SIZE
- bytes to parse it */
- len = FFMIN(MPA_HEADER_SIZE - len, buf_size);
- if (len > 0) {
- memcpy(s->inbuf_ptr, buf_ptr, len);
- buf_ptr += len;
- buf_size -= len;
- s->inbuf_ptr += len;
- }
- if ((s->inbuf_ptr - s->inbuf) >= MPA_HEADER_SIZE) {
- got_header:
- header = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) |
- (s->inbuf[2] << 8) | s->inbuf[3];
-
- ret = mpa_decode_header(avctx, header, &sr);
- if (ret < 0) {
- s->header_count= -2;
- /* no sync found : move by one byte (inefficient, but simple!) */
- memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1);
- s->inbuf_ptr--;
- dprintf("skip %x\n", header);
- /* reset free format frame size to give a chance
- to get a new bitrate */
- s->free_format_frame_size = 0;
- } else {
- if((header&SAME_HEADER_MASK) != (s->header&SAME_HEADER_MASK) && s->header)
- s->header_count= -3;
- s->header= header;
- s->header_count++;
- s->frame_size = ret;
-
-#if 0
- /* free format: prepare to compute frame size */
- if (decode_header(s, header) == 1) {
- s->frame_size = -1;
- }
-#endif
- }
- if(s->header_count > 1)
- avctx->sample_rate= sr;
- }
- } else
-#if 0
- if (s->frame_size == -1) {
- /* free format : find next sync to compute frame size */
- len = MPA_MAX_CODED_FRAME_SIZE - len;
- if (len > buf_size)
- len = buf_size;
- if (len == 0) {
- /* frame too long: resync */
- s->frame_size = 0;
- memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1);
- s->inbuf_ptr--;
- } else {
- uint8_t *p, *pend;
- uint32_t header1;
- int padding;
-
- memcpy(s->inbuf_ptr, buf_ptr, len);
- /* check for header */
- p = s->inbuf_ptr - 3;
- pend = s->inbuf_ptr + len - 4;
- while (p <= pend) {
- header = (p[0] << 24) | (p[1] << 16) |
- (p[2] << 8) | p[3];
- header1 = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) |
- (s->inbuf[2] << 8) | s->inbuf[3];
- /* check with high probability that we have a
- valid header */
- if ((header & SAME_HEADER_MASK) ==
- (header1 & SAME_HEADER_MASK)) {
- /* header found: update pointers */
- len = (p + 4) - s->inbuf_ptr;
- buf_ptr += len;
- buf_size -= len;
- s->inbuf_ptr = p;
- /* compute frame size */
- s->free_format_next_header = header;
- s->free_format_frame_size = s->inbuf_ptr - s->inbuf;
- padding = (header1 >> 9) & 1;
- if (s->layer == 1)
- s->free_format_frame_size -= padding * 4;
- else
- s->free_format_frame_size -= padding;
- dprintf("free frame size=%d padding=%d\n",
- s->free_format_frame_size, padding);
- decode_header(s, header1);
- goto next_data;
- }
- p++;
- }
- /* not found: simply increase pointers */
- buf_ptr += len;
- s->inbuf_ptr += len;
- buf_size -= len;
- }
- } else
-#endif
- if (len < s->frame_size) {
- if (s->frame_size > MPA_MAX_CODED_FRAME_SIZE)
- s->frame_size = MPA_MAX_CODED_FRAME_SIZE;
- len = FFMIN(s->frame_size - len, buf_size);
- memcpy(s->inbuf_ptr, buf_ptr, len);
- buf_ptr += len;
- s->inbuf_ptr += len;
- buf_size -= len;
- }
-
- if(s->frame_size > 0 && buf_ptr - buf == s->inbuf_ptr - s->inbuf
- && buf_size + buf_ptr - buf >= s->frame_size){
- if(s->header_count > 0){
- *poutbuf = buf;
- *poutbuf_size = s->frame_size;
- }
- buf_ptr = buf + s->frame_size;
- s->inbuf_ptr = s->inbuf;
- s->frame_size = 0;
- break;
- }
-
- // next_data:
- if (s->frame_size > 0 &&
- (s->inbuf_ptr - s->inbuf) >= s->frame_size) {
- if(s->header_count > 0){
- *poutbuf = s->inbuf;
- *poutbuf_size = s->inbuf_ptr - s->inbuf;
- }
- s->inbuf_ptr = s->inbuf;
- s->frame_size = 0;
- break;
- }
- }
- return buf_ptr - buf;
-}
-#endif /* CONFIG_MPEGAUDIO_PARSER */
-
-#if defined(CONFIG_AC3_PARSER) || defined(CONFIG_AAC_PARSER)
-/* also used for ADTS AAC */
-typedef struct AC3ParseContext {
- uint8_t *inbuf_ptr;
- int frame_size;
- int header_size;
- int (*sync)(const uint8_t *buf, int *channels, int *sample_rate,
- int *bit_rate, int *samples);
- uint8_t inbuf[8192]; /* input buffer */
-} AC3ParseContext;
-
-#define AC3_HEADER_SIZE 7
-#define AAC_HEADER_SIZE 7
-
-#ifdef CONFIG_AC3_PARSER
-static const int ac3_sample_rates[4] = {
- 48000, 44100, 32000, 0
-};
-
-static const int ac3_frame_sizes[64][3] = {
- { 64, 69, 96 },
- { 64, 70, 96 },
- { 80, 87, 120 },
- { 80, 88, 120 },
- { 96, 104, 144 },
- { 96, 105, 144 },
- { 112, 121, 168 },
- { 112, 122, 168 },
- { 128, 139, 192 },
- { 128, 140, 192 },
- { 160, 174, 240 },
- { 160, 175, 240 },
- { 192, 208, 288 },
- { 192, 209, 288 },
- { 224, 243, 336 },
- { 224, 244, 336 },
- { 256, 278, 384 },
- { 256, 279, 384 },
- { 320, 348, 480 },
- { 320, 349, 480 },
- { 384, 417, 576 },
- { 384, 418, 576 },
- { 448, 487, 672 },
- { 448, 488, 672 },
- { 512, 557, 768 },
- { 512, 558, 768 },
- { 640, 696, 960 },
- { 640, 697, 960 },
- { 768, 835, 1152 },
- { 768, 836, 1152 },
- { 896, 975, 1344 },
- { 896, 976, 1344 },
- { 1024, 1114, 1536 },
- { 1024, 1115, 1536 },
- { 1152, 1253, 1728 },
- { 1152, 1254, 1728 },
- { 1280, 1393, 1920 },
- { 1280, 1394, 1920 },
-};
-
-static const int ac3_bitrates[64] = {
- 32, 32, 40, 40, 48, 48, 56, 56, 64, 64, 80, 80, 96, 96, 112, 112,
- 128, 128, 160, 160, 192, 192, 224, 224, 256, 256, 320, 320, 384,
- 384, 448, 448, 512, 512, 576, 576, 640, 640,
-};
-
-static const uint8_t ac3_channels[8] = {
- 2, 1, 2, 3, 3, 4, 4, 5
-};
-
-static const uint8_t eac3_blocks[4] = {
- 1, 2, 3, 6
-};
-
-#endif /* CONFIG_AC3_PARSER */
-
-#ifdef CONFIG_AAC_PARSER
-static const int aac_sample_rates[16] = {
- 96000, 88200, 64000, 48000, 44100, 32000,
- 24000, 22050, 16000, 12000, 11025, 8000, 7350
-};
-
-static const int aac_channels[8] = {
- 0, 1, 2, 3, 4, 5, 6, 8
-};
-#endif
-
-#ifdef CONFIG_AC3_PARSER
-static int ac3_sync(const uint8_t *buf, int *channels, int *sample_rate,
- int *bit_rate, int *samples)
-{
- unsigned int fscod, frmsizecod, acmod, bsid, lfeon;
- unsigned int strmtyp, substreamid, frmsiz, fscod2, numblkscod;
- GetBitContext bits;
-
- init_get_bits(&bits, buf, AC3_HEADER_SIZE * 8);
-
- if(get_bits(&bits, 16) != 0x0b77)
- return 0;
-
- bsid = show_bits_long(&bits, 29) & 0x1f;
- if(bsid <= 8) { /* Normal AC-3 */
- skip_bits(&bits, 16); /* crc */
- fscod = get_bits(&bits, 2);
- frmsizecod = get_bits(&bits, 6);
-
- if(fscod == 3)
- return 0;
-
- skip_bits(&bits, 5); /* bsid */
- skip_bits(&bits, 3); /* bsmod */
- acmod = get_bits(&bits, 3);
- if(acmod & 1 && acmod != 1)
- skip_bits(&bits, 2); /* cmixlev */
- if(acmod & 4)
- skip_bits(&bits, 2); /* surmixlev */
- if(acmod & 2)
- skip_bits(&bits, 2); /* dsurmod */
- lfeon = get_bits1(&bits);
-
- *sample_rate = ac3_sample_rates[fscod];
- *bit_rate = ac3_bitrates[frmsizecod] * 1000;
- *channels = ac3_channels[acmod] + lfeon;
- *samples = 6 * 256;
-
- return ac3_frame_sizes[frmsizecod][fscod] * 2;
- } else if (bsid >= 10 && bsid <= 16) { /* Enhanced AC-3 */
- strmtyp = get_bits(&bits, 2);
- substreamid = get_bits(&bits, 3);
-
- if (strmtyp != 0 || substreamid != 0)
- return 0; /* Currently don't support additional streams */
-
- frmsiz = get_bits(&bits, 11) + 1;
- fscod = get_bits(&bits, 2);
- if (fscod == 3) {
- fscod2 = get_bits(&bits, 2);
- numblkscod = 3;
-
- if(fscod2 == 3)
- return 0;
-
- *sample_rate = ac3_sample_rates[fscod2] / 2;
- } else {
- numblkscod = get_bits(&bits, 2);
-
- *sample_rate = ac3_sample_rates[fscod];
- }
-
- acmod = get_bits(&bits, 3);
- lfeon = get_bits1(&bits);
-
- *samples = eac3_blocks[numblkscod] * 256;
- *bit_rate = frmsiz * (*sample_rate) * 16 / (*samples);
- *channels = ac3_channels[acmod] + lfeon;
-
- return frmsiz * 2;
- }
-
- /* Unsupported bitstream version */
- return 0;
-}
-#endif /* CONFIG_AC3_PARSER */
-
-#ifdef CONFIG_AAC_PARSER
-static int aac_sync(const uint8_t *buf, int *channels, int *sample_rate,
- int *bit_rate, int *samples)
-{
- GetBitContext bits;
- int size, rdb, ch, sr;
-
- init_get_bits(&bits, buf, AAC_HEADER_SIZE * 8);
-
- if(get_bits(&bits, 12) != 0xfff)
- return 0;
-
- skip_bits1(&bits); /* id */
- skip_bits(&bits, 2); /* layer */
- skip_bits1(&bits); /* protection_absent */
- skip_bits(&bits, 2); /* profile_objecttype */
- sr = get_bits(&bits, 4); /* sample_frequency_index */
- if(!aac_sample_rates[sr])
- return 0;
- skip_bits1(&bits); /* private_bit */
- ch = get_bits(&bits, 3); /* channel_configuration */
- if(!aac_channels[ch])
- return 0;
- skip_bits1(&bits); /* original/copy */
- skip_bits1(&bits); /* home */
-
- /* adts_variable_header */
- skip_bits1(&bits); /* copyright_identification_bit */
- skip_bits1(&bits); /* copyright_identification_start */
- size = get_bits(&bits, 13); /* aac_frame_length */
- skip_bits(&bits, 11); /* adts_buffer_fullness */
- rdb = get_bits(&bits, 2); /* number_of_raw_data_blocks_in_frame */
-
- *channels = aac_channels[ch];
- *sample_rate = aac_sample_rates[sr];
- *samples = (rdb + 1) * 1024;
- *bit_rate = size * 8 * *sample_rate / *samples;
-
- return size;
-}
-#endif /* CONFIG_AAC_PARSER */
-
-#ifdef CONFIG_AC3_PARSER
-static int ac3_parse_init(AVCodecParserContext *s1)
-{
- AC3ParseContext *s = s1->priv_data;
- s->inbuf_ptr = s->inbuf;
- s->header_size = AC3_HEADER_SIZE;
- s->sync = ac3_sync;
- return 0;
-}
-#endif
-
-#ifdef CONFIG_AAC_PARSER
-static int aac_parse_init(AVCodecParserContext *s1)
-{
- AC3ParseContext *s = s1->priv_data;
- s->inbuf_ptr = s->inbuf;
- s->header_size = AAC_HEADER_SIZE;
- s->sync = aac_sync;
- return 0;
-}
-#endif
-
-/* also used for ADTS AAC */
-static int ac3_parse(AVCodecParserContext *s1,
- AVCodecContext *avctx,
- uint8_t **poutbuf, int *poutbuf_size,
- const uint8_t *buf, int buf_size)
-{
- AC3ParseContext *s = s1->priv_data;
- const uint8_t *buf_ptr;
- int len, sample_rate, bit_rate, channels, samples;
-
- *poutbuf = NULL;
- *poutbuf_size = 0;
-
- buf_ptr = buf;
- while (buf_size > 0) {
- len = s->inbuf_ptr - s->inbuf;
- if (s->frame_size == 0) {
- /* no header seen : find one. We need at least s->header_size
- bytes to parse it */
- len = FFMIN(s->header_size - len, buf_size);
-
- memcpy(s->inbuf_ptr, buf_ptr, len);
- buf_ptr += len;
- s->inbuf_ptr += len;
- buf_size -= len;
- if ((s->inbuf_ptr - s->inbuf) == s->header_size) {
- len = s->sync(s->inbuf, &channels, &sample_rate, &bit_rate,
- &samples);
- if (len == 0) {
- /* no sync found : move by one byte (inefficient, but simple!) */
- memmove(s->inbuf, s->inbuf + 1, s->header_size - 1);
- s->inbuf_ptr--;
- } else {
- s->frame_size = len;
- /* update codec info */
- avctx->sample_rate = sample_rate;
- /* set channels,except if the user explicitly requests 1 or 2 channels, XXX/FIXME this is a bit ugly */
- if(avctx->codec_id == CODEC_ID_AC3){
- if(avctx->channels!=1 && avctx->channels!=2){
- avctx->channels = channels;
- }
- } else {
- avctx->channels = channels;
- }
- avctx->bit_rate = bit_rate;
- avctx->frame_size = samples;
- }
- }
- } else {
- len = FFMIN(s->frame_size - len, buf_size);
-
- memcpy(s->inbuf_ptr, buf_ptr, len);
- buf_ptr += len;
- s->inbuf_ptr += len;
- buf_size -= len;
-
- if(s->inbuf_ptr - s->inbuf == s->frame_size){
- *poutbuf = s->inbuf;
- *poutbuf_size = s->frame_size;
- s->inbuf_ptr = s->inbuf;
- s->frame_size = 0;
- break;
- }
- }
- }
- return buf_ptr - buf;
-}
-#endif /* CONFIG_AC3_PARSER || CONFIG_AAC_PARSER */
-
-#ifdef CONFIG_MPEG4VIDEO_PARSER
-AVCodecParser mpeg4video_parser = {
- { CODEC_ID_MPEG4 },
- sizeof(ParseContext1),
- mpeg4video_parse_init,
- mpeg4video_parse,
- ff_parse1_close,
- ff_mpeg4video_split,
-};
-#endif
-#ifdef CONFIG_MPEGAUDIO_PARSER
-AVCodecParser mpegaudio_parser = {
- { CODEC_ID_MP2, CODEC_ID_MP3 },
- sizeof(MpegAudioParseContext),
- mpegaudio_parse_init,
- mpegaudio_parse,
- NULL,
-};
-#endif
-#ifdef CONFIG_AC3_PARSER
-AVCodecParser ac3_parser = {
- { CODEC_ID_AC3 },
- sizeof(AC3ParseContext),
- ac3_parse_init,
- ac3_parse,
- NULL,
-};
-#endif
-#ifdef CONFIG_AAC_PARSER
-AVCodecParser aac_parser = {
- { CODEC_ID_AAC },
- sizeof(AC3ParseContext),
- aac_parse_init,
- ac3_parse,
- NULL,
-};
-#endif
diff --git a/src/libffmpeg/libavcodec/pcm.c b/src/libffmpeg/libavcodec/pcm.c
deleted file mode 100644
index 4011ed3b5..000000000
--- a/src/libffmpeg/libavcodec/pcm.c
+++ /dev/null
@@ -1,548 +0,0 @@
-/*
- * PCM codecs
- * Copyright (c) 2001 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 pcm.c
- * PCM codecs
- */
-
-#include "avcodec.h"
-#include "bitstream.h" // for ff_reverse
-
-/* 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 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 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 = NULL;
-static int linear_to_alaw_ref = 0;
-
-static uint8_t *linear_to_ulaw = NULL;
-static int linear_to_ulaw_ref = 0;
-
-static 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<v;j++) {
- linear_to_xlaw[8192 + j] = (i ^ mask);
- if (j > 0)
- linear_to_xlaw[8192 - j] = (i ^ (mask ^ 0x80));
- }
- }
- linear_to_xlaw[0] = linear_to_xlaw[1];
-}
-
-static int pcm_encode_init(AVCodecContext *avctx)
-{
- avctx->frame_size = 1;
- switch(avctx->codec->id) {
- case CODEC_ID_PCM_ALAW:
- if (linear_to_alaw_ref == 0) {
- linear_to_alaw = av_malloc(16384);
- if (!linear_to_alaw)
- return -1;
- build_xlaw_table(linear_to_alaw, alaw2linear, 0xd5);
- }
- linear_to_alaw_ref++;
- break;
- case CODEC_ID_PCM_MULAW:
- if (linear_to_ulaw_ref == 0) {
- linear_to_ulaw = av_malloc(16384);
- if (!linear_to_ulaw)
- return -1;
- build_xlaw_table(linear_to_ulaw, ulaw2linear, 0xff);
- }
- linear_to_ulaw_ref++;
- break;
- default:
- break;
- }
-
- switch(avctx->codec->id) {
- case CODEC_ID_PCM_S32LE:
- case CODEC_ID_PCM_S32BE:
- case CODEC_ID_PCM_U32LE:
- case CODEC_ID_PCM_U32BE:
- avctx->block_align = 4 * avctx->channels;
- 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:
- avctx->block_align = 3 * avctx->channels;
- break;
- case CODEC_ID_PCM_S16LE:
- case CODEC_ID_PCM_S16BE:
- case CODEC_ID_PCM_U16LE:
- case CODEC_ID_PCM_U16BE:
- avctx->block_align = 2 * avctx->channels;
- break;
- case CODEC_ID_PCM_S8:
- case CODEC_ID_PCM_U8:
- case CODEC_ID_PCM_MULAW:
- case CODEC_ID_PCM_ALAW:
- avctx->block_align = avctx->channels;
- break;
- default:
- break;
- }
-
- avctx->coded_frame= avcodec_alloc_frame();
- avctx->coded_frame->key_frame= 1;
-
- return 0;
-}
-
-static int pcm_encode_close(AVCodecContext *avctx)
-{
- av_freep(&avctx->coded_frame);
-
- switch(avctx->codec->id) {
- case CODEC_ID_PCM_ALAW:
- if (--linear_to_alaw_ref == 0)
- av_free(linear_to_alaw);
- break;
- case CODEC_ID_PCM_MULAW:
- if (--linear_to_ulaw_ref == 0)
- av_free(linear_to_ulaw);
- break;
- default:
- /* nothing to free */
- break;
- }
- return 0;
-}
-
-/**
- * \brief convert samples from 16 bit
- * \param bps byte per sample for the destination format, must be >= 2
- * \param le 0 for big-, 1 for little-endian
- * \param us 0 for signed, 1 for unsigned output
- * \param samples input samples
- * \param dst output samples
- * \param n number of samples in samples buffer.
- */
-static inline void encode_from16(int bps, int le, int us,
- short **samples, uint8_t **dst, int n) {
- if (bps > 2)
- memset(*dst, 0, n * bps);
- if (le) *dst += bps - 2;
- for(;n>0;n--) {
- register int v = *(*samples)++;
- if (us) v += 0x8000;
- (*dst)[le] = v >> 8;
- (*dst)[1 - le] = v;
- *dst += bps;
- }
- if (le) *dst -= bps - 2;
-}
-
-static int pcm_encode_frame(AVCodecContext *avctx,
- unsigned char *frame, int buf_size, void *data)
-{
- int n, sample_size, v;
- short *samples;
- unsigned char *dst;
-
- switch(avctx->codec->id) {
- case CODEC_ID_PCM_S32LE:
- case CODEC_ID_PCM_S32BE:
- case CODEC_ID_PCM_U32LE:
- case CODEC_ID_PCM_U32BE:
- sample_size = 4;
- 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:
- sample_size = 3;
- break;
- case CODEC_ID_PCM_S16LE:
- case CODEC_ID_PCM_S16BE:
- case CODEC_ID_PCM_U16LE:
- case CODEC_ID_PCM_U16BE:
- sample_size = 2;
- break;
- default:
- sample_size = 1;
- break;
- }
- n = buf_size / sample_size;
- samples = data;
- dst = frame;
-
- switch(avctx->codec->id) {
- case CODEC_ID_PCM_S32LE:
- encode_from16(4, 1, 0, &samples, &dst, n);
- break;
- case CODEC_ID_PCM_S32BE:
- encode_from16(4, 0, 0, &samples, &dst, n);
- break;
- case CODEC_ID_PCM_U32LE:
- encode_from16(4, 1, 1, &samples, &dst, n);
- break;
- case CODEC_ID_PCM_U32BE:
- encode_from16(4, 0, 1, &samples, &dst, n);
- break;
- case CODEC_ID_PCM_S24LE:
- encode_from16(3, 1, 0, &samples, &dst, n);
- break;
- case CODEC_ID_PCM_S24BE:
- encode_from16(3, 0, 0, &samples, &dst, n);
- break;
- case CODEC_ID_PCM_U24LE:
- encode_from16(3, 1, 1, &samples, &dst, n);
- break;
- case CODEC_ID_PCM_U24BE:
- encode_from16(3, 0, 1, &samples, &dst, n);
- break;
- case CODEC_ID_PCM_S24DAUD:
- for(;n>0;n--) {
- uint32_t tmp = ff_reverse[*samples >> 8] +
- (ff_reverse[*samples & 0xff] << 8);
- tmp <<= 4; // sync flags would go here
- dst[2] = tmp & 0xff;
- tmp >>= 8;
- dst[1] = tmp & 0xff;
- dst[0] = tmp >> 8;
- samples++;
- dst += 3;
- }
- break;
- case CODEC_ID_PCM_S16LE:
- for(;n>0;n--) {
- v = *samples++;
- dst[0] = v & 0xff;
- dst[1] = v >> 8;
- dst += 2;
- }
- break;
- case CODEC_ID_PCM_S16BE:
- for(;n>0;n--) {
- v = *samples++;
- dst[0] = v >> 8;
- dst[1] = v;
- dst += 2;
- }
- break;
- case CODEC_ID_PCM_U16LE:
- for(;n>0;n--) {
- v = *samples++;
- v += 0x8000;
- dst[0] = v & 0xff;
- dst[1] = v >> 8;
- dst += 2;
- }
- break;
- case CODEC_ID_PCM_U16BE:
- for(;n>0;n--) {
- v = *samples++;
- v += 0x8000;
- dst[0] = v >> 8;
- dst[1] = v;
- dst += 2;
- }
- break;
- case CODEC_ID_PCM_S8:
- for(;n>0;n--) {
- v = *samples++;
- dst[0] = v >> 8;
- dst++;
- }
- break;
- case CODEC_ID_PCM_U8:
- for(;n>0;n--) {
- v = *samples++;
- dst[0] = (v >> 8) + 128;
- dst++;
- }
- break;
- case CODEC_ID_PCM_ALAW:
- for(;n>0;n--) {
- v = *samples++;
- dst[0] = linear_to_alaw[(v + 32768) >> 2];
- dst++;
- }
- break;
- case CODEC_ID_PCM_MULAW:
- for(;n>0;n--) {
- v = *samples++;
- dst[0] = linear_to_ulaw[(v + 32768) >> 2];
- dst++;
- }
- break;
- default:
- return -1;
- }
- //avctx->frame_size = (dst - frame) / (sample_size * avctx->channels);
-
- return dst - frame;
-}
-
-typedef struct PCMDecode {
- short table[256];
-} PCMDecode;
-
-static int pcm_decode_init(AVCodecContext * avctx)
-{
- PCMDecode *s = avctx->priv_data;
- int i;
-
- switch(avctx->codec->id) {
- case CODEC_ID_PCM_ALAW:
- for(i=0;i<256;i++)
- s->table[i] = alaw2linear(i);
- break;
- case CODEC_ID_PCM_MULAW:
- for(i=0;i<256;i++)
- s->table[i] = ulaw2linear(i);
- break;
- default:
- break;
- }
- return 0;
-}
-
-/**
- * \brief convert samples to 16 bit
- * \param bps byte per sample for the source format, must be >= 2
- * \param le 0 for big-, 1 for little-endian
- * \param us 0 for signed, 1 for unsigned input
- * \param src input samples
- * \param samples output samples
- * \param src_len number of bytes in src
- */
-static inline void decode_to16(int bps, int le, int us,
- uint8_t **src, short **samples, int src_len)
-{
- register int n = src_len / bps;
- if (le) *src += bps - 2;
- for(;n>0;n--) {
- *(*samples)++ = ((*src)[le] << 8 | (*src)[1 - le]) - (us?0x8000:0);
- *src += bps;
- }
- if (le) *src -= bps - 2;
-}
-
-static int pcm_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- PCMDecode *s = avctx->priv_data;
- int n;
- short *samples;
- uint8_t *src;
-
- samples = data;
- src = buf;
-
- buf_size= FFMIN(buf_size, *data_size/2);
- *data_size=0;
-
- switch(avctx->codec->id) {
- case CODEC_ID_PCM_S32LE:
- decode_to16(4, 1, 0, &src, &samples, buf_size);
- break;
- case CODEC_ID_PCM_S32BE:
- decode_to16(4, 0, 0, &src, &samples, buf_size);
- break;
- case CODEC_ID_PCM_U32LE:
- decode_to16(4, 1, 1, &src, &samples, buf_size);
- break;
- case CODEC_ID_PCM_U32BE:
- decode_to16(4, 0, 1, &src, &samples, buf_size);
- break;
- case CODEC_ID_PCM_S24LE:
- decode_to16(3, 1, 0, &src, &samples, buf_size);
- break;
- case CODEC_ID_PCM_S24BE:
- decode_to16(3, 0, 0, &src, &samples, buf_size);
- break;
- case CODEC_ID_PCM_U24LE:
- decode_to16(3, 1, 1, &src, &samples, buf_size);
- break;
- case CODEC_ID_PCM_U24BE:
- decode_to16(3, 0, 1, &src, &samples, buf_size);
- break;
- case CODEC_ID_PCM_S24DAUD:
- n = buf_size / 3;
- for(;n>0;n--) {
- uint32_t v = src[0] << 16 | src[1] << 8 | src[2];
- v >>= 4; // sync flags are here
- *samples++ = ff_reverse[(v >> 8) & 0xff] +
- (ff_reverse[v & 0xff] << 8);
- src += 3;
- }
- break;
- case CODEC_ID_PCM_S16LE:
- n = buf_size >> 1;
- for(;n>0;n--) {
- *samples++ = src[0] | (src[1] << 8);
- src += 2;
- }
- break;
- case CODEC_ID_PCM_S16BE:
- n = buf_size >> 1;
- for(;n>0;n--) {
- *samples++ = (src[0] << 8) | src[1];
- src += 2;
- }
- break;
- case CODEC_ID_PCM_U16LE:
- n = buf_size >> 1;
- for(;n>0;n--) {
- *samples++ = (src[0] | (src[1] << 8)) - 0x8000;
- src += 2;
- }
- break;
- case CODEC_ID_PCM_U16BE:
- n = buf_size >> 1;
- for(;n>0;n--) {
- *samples++ = ((src[0] << 8) | src[1]) - 0x8000;
- src += 2;
- }
- break;
- case CODEC_ID_PCM_S8:
- n = buf_size;
- for(;n>0;n--) {
- *samples++ = src[0] << 8;
- src++;
- }
- break;
- case CODEC_ID_PCM_U8:
- n = buf_size;
- for(;n>0;n--) {
- *samples++ = ((int)src[0] - 128) << 8;
- src++;
- }
- break;
- case CODEC_ID_PCM_ALAW:
- case CODEC_ID_PCM_MULAW:
- n = buf_size;
- for(;n>0;n--) {
- *samples++ = s->table[src[0]];
- src++;
- }
- break;
- default:
- return -1;
- }
- *data_size = (uint8_t *)samples - (uint8_t *)data;
- return src - buf;
-}
-
-#define PCM_CODEC(id, name) \
-AVCodec name ## _encoder = { \
- #name, \
- CODEC_TYPE_AUDIO, \
- id, \
- 0, \
- pcm_encode_init, \
- pcm_encode_frame, \
- pcm_encode_close, \
- NULL, \
-}; \
-AVCodec name ## _decoder = { \
- #name, \
- CODEC_TYPE_AUDIO, \
- id, \
- sizeof(PCMDecode), \
- pcm_decode_init, \
- NULL, \
- NULL, \
- pcm_decode_frame, \
-}
-
-PCM_CODEC(CODEC_ID_PCM_S32LE, pcm_s32le);
-PCM_CODEC(CODEC_ID_PCM_S32BE, pcm_s32be);
-PCM_CODEC(CODEC_ID_PCM_U32LE, pcm_u32le);
-PCM_CODEC(CODEC_ID_PCM_U32BE, pcm_u32be);
-PCM_CODEC(CODEC_ID_PCM_S24LE, pcm_s24le);
-PCM_CODEC(CODEC_ID_PCM_S24BE, pcm_s24be);
-PCM_CODEC(CODEC_ID_PCM_U24LE, pcm_u24le);
-PCM_CODEC(CODEC_ID_PCM_U24BE, pcm_u24be);
-PCM_CODEC(CODEC_ID_PCM_S24DAUD, pcm_s24daud);
-PCM_CODEC(CODEC_ID_PCM_S16LE, pcm_s16le);
-PCM_CODEC(CODEC_ID_PCM_S16BE, pcm_s16be);
-PCM_CODEC(CODEC_ID_PCM_U16LE, pcm_u16le);
-PCM_CODEC(CODEC_ID_PCM_U16BE, pcm_u16be);
-PCM_CODEC(CODEC_ID_PCM_S8, pcm_s8);
-PCM_CODEC(CODEC_ID_PCM_U8, pcm_u8);
-PCM_CODEC(CODEC_ID_PCM_ALAW, pcm_alaw);
-PCM_CODEC(CODEC_ID_PCM_MULAW, pcm_mulaw);
-
-#undef PCM_CODEC
diff --git a/src/libffmpeg/libavcodec/ppc/Makefile.am b/src/libffmpeg/libavcodec/ppc/Makefile.am
deleted file mode 100644
index d52cc481e..000000000
--- a/src/libffmpeg/libavcodec/ppc/Makefile.am
+++ /dev/null
@@ -1,36 +0,0 @@
-include $(top_srcdir)/misc/Makefile.common
-
-AM_CPPFLAGS = $(LIBFFMPEG_CPPFLAGS)
-AM_CFLAGS = -fno-strict-aliasing
-# CFLAGS is here to filter out -funroll-loops because it causes bad
-# behavior of libavcodec
-CFLAGS = `echo @CFLAGS@ | sed -e 's/-funroll-loops//g'`
-
-ASFLAGS =
-
-noinst_LTLIBRARIES = libavcodec_ppc.la
-
-libavcodec_ppc_src = dsputil_altivec.c \
- dsputil_ppc.c \
- h264_altivec.c \
- h264_template_altivec.c \
- fdct_altivec.c \
- fft_altivec.c \
- float_altivec.c \
- idct_altivec.c \
- gmc_altivec.c \
- mpegvideo_altivec.c \
- mpegvideo_ppc.c \
- snow_altivec.c \
- vc1dsp_altivec.c
-libavcodec_ppc_dummy = libavcodec_ppc_dummy.c
-
-EXTRA_DIST = $(libavcodec_ppc_src) $(libavcodec_ppc_dummy)
-
-#if PPC_ARCH
-#ppc_modules = $(libavcodec_ppc_src)
-#endif
-
-libavcodec_ppc_la_SOURCES = $(ppc_modules) $(libavcodec_ppc_dummy)
-
-noinst_HEADERS = dsputil_altivec.h dsputil_ppc.h gcc_fixes.h mathops.h types_altivec.h
diff --git a/src/libffmpeg/libavcodec/ppc/dsputil_h264_altivec.c b/src/libffmpeg/libavcodec/ppc/dsputil_h264_altivec.c
deleted file mode 100644
index 14391e60c..000000000
--- a/src/libffmpeg/libavcodec/ppc/dsputil_h264_altivec.c
+++ /dev/null
@@ -1,319 +0,0 @@
-/*
- * Copyright (c) 2004 Romain Dolbeau <romain@dolbeau.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include "../dsputil.h"
-
-#include "gcc_fixes.h"
-
-#include "dsputil_altivec.h"
-
-#define PUT_OP_U8_ALTIVEC(d, s, dst) d = s
-#define AVG_OP_U8_ALTIVEC(d, s, dst) d = vec_avg(dst, s)
-
-#define OP_U8_ALTIVEC PUT_OP_U8_ALTIVEC
-#define PREFIX_h264_chroma_mc8_altivec put_h264_chroma_mc8_altivec
-#define PREFIX_h264_chroma_mc8_num altivec_put_h264_chroma_mc8_num
-#define PREFIX_h264_qpel16_h_lowpass_altivec put_h264_qpel16_h_lowpass_altivec
-#define PREFIX_h264_qpel16_h_lowpass_num altivec_put_h264_qpel16_h_lowpass_num
-#define PREFIX_h264_qpel16_v_lowpass_altivec put_h264_qpel16_v_lowpass_altivec
-#define PREFIX_h264_qpel16_v_lowpass_num altivec_put_h264_qpel16_v_lowpass_num
-#define PREFIX_h264_qpel16_hv_lowpass_altivec put_h264_qpel16_hv_lowpass_altivec
-#define PREFIX_h264_qpel16_hv_lowpass_num altivec_put_h264_qpel16_hv_lowpass_num
-#include "dsputil_h264_template_altivec.c"
-#undef OP_U8_ALTIVEC
-#undef PREFIX_h264_chroma_mc8_altivec
-#undef PREFIX_h264_chroma_mc8_num
-#undef PREFIX_h264_qpel16_h_lowpass_altivec
-#undef PREFIX_h264_qpel16_h_lowpass_num
-#undef PREFIX_h264_qpel16_v_lowpass_altivec
-#undef PREFIX_h264_qpel16_v_lowpass_num
-#undef PREFIX_h264_qpel16_hv_lowpass_altivec
-#undef PREFIX_h264_qpel16_hv_lowpass_num
-
-#define OP_U8_ALTIVEC AVG_OP_U8_ALTIVEC
-#define PREFIX_h264_chroma_mc8_altivec avg_h264_chroma_mc8_altivec
-#define PREFIX_h264_chroma_mc8_num altivec_avg_h264_chroma_mc8_num
-#define PREFIX_h264_qpel16_h_lowpass_altivec avg_h264_qpel16_h_lowpass_altivec
-#define PREFIX_h264_qpel16_h_lowpass_num altivec_avg_h264_qpel16_h_lowpass_num
-#define PREFIX_h264_qpel16_v_lowpass_altivec avg_h264_qpel16_v_lowpass_altivec
-#define PREFIX_h264_qpel16_v_lowpass_num altivec_avg_h264_qpel16_v_lowpass_num
-#define PREFIX_h264_qpel16_hv_lowpass_altivec avg_h264_qpel16_hv_lowpass_altivec
-#define PREFIX_h264_qpel16_hv_lowpass_num altivec_avg_h264_qpel16_hv_lowpass_num
-#include "dsputil_h264_template_altivec.c"
-#undef OP_U8_ALTIVEC
-#undef PREFIX_h264_chroma_mc8_altivec
-#undef PREFIX_h264_chroma_mc8_num
-#undef PREFIX_h264_qpel16_h_lowpass_altivec
-#undef PREFIX_h264_qpel16_h_lowpass_num
-#undef PREFIX_h264_qpel16_v_lowpass_altivec
-#undef PREFIX_h264_qpel16_v_lowpass_num
-#undef PREFIX_h264_qpel16_hv_lowpass_altivec
-#undef PREFIX_h264_qpel16_hv_lowpass_num
-
-#define H264_MC(OPNAME, SIZE, CODETYPE) \
-static void OPNAME ## h264_qpel ## SIZE ## _mc00_ ## CODETYPE (uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## pixels ## SIZE ## _ ## CODETYPE(dst, src, stride, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc10_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){ \
- DECLARE_ALIGNED_16(uint64_t, temp[SIZE*SIZE/8]);\
- uint8_t * const half= (uint8_t*)temp;\
- put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(half, src, SIZE, stride);\
- OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, src, half, stride, stride, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc20_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(dst, src, stride, stride);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc30_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\
- DECLARE_ALIGNED_16(uint64_t, temp[SIZE*SIZE/8]);\
- uint8_t * const half= (uint8_t*)temp;\
- 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(uint64_t, temp[SIZE*SIZE/8]);\
- uint8_t * const half= (uint8_t*)temp;\
- put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(half, src, SIZE, stride);\
- OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, src, half, stride, stride, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc02_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(dst, src, stride, stride);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc03_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\
- DECLARE_ALIGNED_16(uint64_t, temp[SIZE*SIZE/8]);\
- uint8_t * const half= (uint8_t*)temp;\
- 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(uint64_t, temp[SIZE*SIZE/4]);\
- uint8_t * const halfH= (uint8_t*)temp;\
- uint8_t * const halfV= ((uint8_t*)temp) + 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(uint64_t, temp[SIZE*SIZE/4]);\
- uint8_t * const halfH= (uint8_t*)temp;\
- uint8_t * const halfV= ((uint8_t*)temp) + 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(uint64_t, temp[SIZE*SIZE/4]);\
- uint8_t * const halfH= (uint8_t*)temp;\
- uint8_t * const halfV= ((uint8_t*)temp) + 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(uint64_t, temp[SIZE*SIZE/4]);\
- uint8_t * const halfH= (uint8_t*)temp;\
- uint8_t * const halfV= ((uint8_t*)temp) + 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(uint64_t, temp[SIZE*(SIZE+8)/4]);\
- int16_t * const tmp= (int16_t*)temp;\
- 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(uint64_t, temp[SIZE*(SIZE+8)/4 + SIZE*SIZE/4]);\
- uint8_t * const halfH= (uint8_t*)temp;\
- uint8_t * const halfHV= ((uint8_t*)temp) + SIZE*SIZE;\
- int16_t * const tmp= ((int16_t*)temp) + SIZE*SIZE;\
- 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(uint64_t, temp[SIZE*(SIZE+8)/4 + SIZE*SIZE/4]);\
- uint8_t * const halfH= (uint8_t*)temp;\
- uint8_t * const halfHV= ((uint8_t*)temp) + SIZE*SIZE;\
- int16_t * const tmp= ((int16_t*)temp) + SIZE*SIZE;\
- 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(uint64_t, temp[SIZE*(SIZE+8)/4 + SIZE*SIZE/4]);\
- uint8_t * const halfV= (uint8_t*)temp;\
- uint8_t * const halfHV= ((uint8_t*)temp) + SIZE*SIZE;\
- int16_t * const tmp= ((int16_t*)temp) + SIZE*SIZE;\
- 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(uint64_t, temp[SIZE*(SIZE+8)/4 + SIZE*SIZE/4]);\
- uint8_t * const halfV= (uint8_t*)temp;\
- uint8_t * const halfHV= ((uint8_t*)temp) + SIZE*SIZE;\
- int16_t * const tmp= ((int16_t*)temp) + SIZE*SIZE;\
- 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);\
-}\
-
-static inline void put_pixels16_l2_altivec( uint8_t * dst, const uint8_t * src1,
- const uint8_t * src2, int dst_stride,
- int src_stride1, int h)
-{
- int i;
- vector unsigned char a, b, d, tmp1, tmp2, mask, mask_, edges, align;
-
- mask_ = vec_lvsl(0, src2);
-
- for (i = 0; i < h; i++) {
-
- tmp1 = vec_ld(i * src_stride1, src1);
- mask = vec_lvsl(i * src_stride1, src1);
- tmp2 = vec_ld(i * src_stride1 + 15, src1);
-
- a = vec_perm(tmp1, tmp2, mask);
-
- tmp1 = vec_ld(i * 16, src2);
- tmp2 = vec_ld(i * 16 + 15, src2);
-
- b = vec_perm(tmp1, tmp2, mask_);
-
- tmp1 = vec_ld(0, dst);
- mask = vec_lvsl(0, dst);
- tmp2 = vec_ld(15, dst);
-
- d = vec_avg(a, b);
-
- edges = vec_perm(tmp2, tmp1, mask);
-
- align = vec_lvsr(0, dst);
-
- tmp1 = vec_perm(edges, d, align);
- tmp2 = vec_perm(d, edges, align);
-
- vec_st(tmp2, 15, dst);
- vec_st(tmp1, 0 , dst);
-
- dst += dst_stride;
- }
-}
-
-static inline void avg_pixels16_l2_altivec( uint8_t * dst, const uint8_t * src1,
- const uint8_t * src2, int dst_stride,
- int src_stride1, int h)
-{
- int i;
- vector unsigned char a, b, d, tmp1, tmp2, mask, mask_, edges, align;
-
- mask_ = vec_lvsl(0, src2);
-
- for (i = 0; i < h; i++) {
-
- tmp1 = vec_ld(i * src_stride1, src1);
- mask = vec_lvsl(i * src_stride1, src1);
- tmp2 = vec_ld(i * src_stride1 + 15, src1);
-
- a = vec_perm(tmp1, tmp2, mask);
-
- tmp1 = vec_ld(i * 16, src2);
- tmp2 = vec_ld(i * 16 + 15, src2);
-
- b = vec_perm(tmp1, tmp2, mask_);
-
- tmp1 = vec_ld(0, dst);
- mask = vec_lvsl(0, dst);
- tmp2 = vec_ld(15, dst);
-
- d = vec_avg(vec_perm(tmp1, tmp2, mask), vec_avg(a, b));
-
- edges = vec_perm(tmp2, tmp1, mask);
-
- align = vec_lvsr(0, dst);
-
- tmp1 = vec_perm(edges, d, align);
- tmp2 = vec_perm(d, edges, align);
-
- vec_st(tmp2, 15, dst);
- vec_st(tmp1, 0 , dst);
-
- dst += dst_stride;
- }
-}
-
-/* Implemented but could be faster
-#define put_pixels16_l2_altivec(d,s1,s2,ds,s1s,h) put_pixels16_l2(d,s1,s2,ds,s1s,16,h)
-#define avg_pixels16_l2_altivec(d,s1,s2,ds,s1s,h) avg_pixels16_l2(d,s1,s2,ds,s1s,16,h)
- */
-
- H264_MC(put_, 16, altivec)
- H264_MC(avg_, 16, altivec)
-
-void dsputil_h264_init_ppc(DSPContext* c, AVCodecContext *avctx) {
-
-#ifdef HAVE_ALTIVEC
- if (has_altivec()) {
- c->put_h264_chroma_pixels_tab[0] = put_h264_chroma_mc8_altivec;
- c->avg_h264_chroma_pixels_tab[0] = avg_h264_chroma_mc8_altivec;
-
-#define dspfunc(PFX, IDX, NUM) \
- c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_altivec; \
- c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_altivec; \
- c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_altivec; \
- c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_altivec; \
- c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_altivec; \
- c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_altivec; \
- c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_altivec; \
- c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_altivec; \
- c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_altivec; \
- c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_altivec; \
- c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_altivec; \
- c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_altivec; \
- c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_altivec; \
- c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_altivec; \
- c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_altivec; \
- c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_altivec
-
- dspfunc(put_h264_qpel, 0, 16);
- dspfunc(avg_h264_qpel, 0, 16);
-#undef dspfunc
-
- } else
-#endif /* HAVE_ALTIVEC */
- {
- // Non-AltiVec PPC optimisations
-
- // ... pending ...
- }
-}
diff --git a/src/libffmpeg/libavcodec/ppc/dsputil_h264_template_altivec.c b/src/libffmpeg/libavcodec/ppc/dsputil_h264_template_altivec.c
deleted file mode 100644
index 37f4de58f..000000000
--- a/src/libffmpeg/libavcodec/ppc/dsputil_h264_template_altivec.c
+++ /dev/null
@@ -1,717 +0,0 @@
-/*
- * Copyright (c) 2004 Romain Dolbeau <romain@dolbeau.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/* this code assume that stride % 16 == 0 */
-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);
- signed int ABCD[4] __attribute__((aligned(16))) =
- {((8 - x) * (8 - y)),
- ((x) * (8 - y)),
- ((8 - x) * (y)),
- ((x) * (y))};
- register int i;
- vector unsigned char fperm;
- const vector signed int vABCD = vec_ld(0, ABCD);
- const vector signed short vA = vec_splat((vector signed short)vABCD, 1);
- const vector signed short vB = vec_splat((vector signed short)vABCD, 3);
- const vector signed short vC = vec_splat((vector signed short)vABCD, 5);
- const vector signed short vD = vec_splat((vector signed short)vABCD, 7);
- const vector signed int vzero = vec_splat_s32(0);
- const vector signed short v32ss = vec_sl(vec_splat_s16(1),vec_splat_u16(5));
- const vector unsigned short v6us = vec_splat_u16(6);
- register int loadSecond = (((unsigned long)src) % 16) <= 7 ? 0 : 1;
- register int reallyBadAlign = (((unsigned long)src) % 16) == 15 ? 1 : 0;
-
- vector unsigned char vsrcAuc, vsrcBuc, vsrcperm0, vsrcperm1;
- vector unsigned char vsrc0uc, vsrc1uc;
- vector signed short vsrc0ssH, vsrc1ssH;
- vector unsigned char vsrcCuc, vsrc2uc, vsrc3uc;
- vector signed short vsrc2ssH, vsrc3ssH, psum;
- vector unsigned char vdst, ppsum, vfdst, fsum;
-
- POWERPC_PERF_START_COUNT(PREFIX_h264_chroma_mc8_num, 1);
-
- if (((unsigned long)dst) % 16 == 0) {
- fperm = (vector unsigned char)AVV(0x10, 0x11, 0x12, 0x13,
- 0x14, 0x15, 0x16, 0x17,
- 0x08, 0x09, 0x0A, 0x0B,
- 0x0C, 0x0D, 0x0E, 0x0F);
- } else {
- fperm = (vector unsigned char)AVV(0x00, 0x01, 0x02, 0x03,
- 0x04, 0x05, 0x06, 0x07,
- 0x18, 0x19, 0x1A, 0x1B,
- 0x1C, 0x1D, 0x1E, 0x1F);
- }
-
- vsrcAuc = vec_ld(0, src);
-
- if (loadSecond)
- vsrcBuc = vec_ld(16, src);
- vsrcperm0 = vec_lvsl(0, src);
- vsrcperm1 = vec_lvsl(1, src);
-
- vsrc0uc = vec_perm(vsrcAuc, vsrcBuc, vsrcperm0);
- if (reallyBadAlign)
- vsrc1uc = vsrcBuc;
- else
- vsrc1uc = vec_perm(vsrcAuc, vsrcBuc, vsrcperm1);
-
- vsrc0ssH = (vector signed short)vec_mergeh((vector unsigned char)vzero,
- (vector unsigned char)vsrc0uc);
- vsrc1ssH = (vector signed short)vec_mergeh((vector unsigned char)vzero,
- (vector unsigned char)vsrc1uc);
-
- if (!loadSecond) {// -> !reallyBadAlign
- for (i = 0 ; i < h ; i++) {
-
-
- vsrcCuc = vec_ld(stride + 0, src);
-
- vsrc2uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm0);
- vsrc3uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm1);
-
- vsrc2ssH = (vector signed short)vec_mergeh((vector unsigned char)vzero,
- (vector unsigned char)vsrc2uc);
- vsrc3ssH = (vector signed short)vec_mergeh((vector unsigned char)vzero,
- (vector unsigned char)vsrc3uc);
-
- psum = vec_mladd(vA, vsrc0ssH, vec_splat_s16(0));
- psum = vec_mladd(vB, vsrc1ssH, psum);
- psum = vec_mladd(vC, vsrc2ssH, psum);
- psum = vec_mladd(vD, vsrc3ssH, psum);
- psum = vec_add(v32ss, psum);
- psum = vec_sra(psum, v6us);
-
- vdst = vec_ld(0, dst);
- ppsum = (vector unsigned char)vec_packsu(psum, psum);
- vfdst = vec_perm(vdst, ppsum, fperm);
-
- OP_U8_ALTIVEC(fsum, vfdst, vdst);
-
- vec_st(fsum, 0, dst);
-
- vsrc0ssH = vsrc2ssH;
- vsrc1ssH = vsrc3ssH;
-
- dst += stride;
- src += stride;
- }
- } else {
- vector unsigned char vsrcDuc;
- for (i = 0 ; i < h ; i++) {
- vsrcCuc = vec_ld(stride + 0, src);
- vsrcDuc = vec_ld(stride + 16, src);
-
- vsrc2uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm0);
- if (reallyBadAlign)
- vsrc3uc = vsrcDuc;
- else
- vsrc3uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm1);
-
- vsrc2ssH = (vector signed short)vec_mergeh((vector unsigned char)vzero,
- (vector unsigned char)vsrc2uc);
- vsrc3ssH = (vector signed short)vec_mergeh((vector unsigned char)vzero,
- (vector unsigned char)vsrc3uc);
-
- psum = vec_mladd(vA, vsrc0ssH, vec_splat_s16(0));
- psum = vec_mladd(vB, vsrc1ssH, psum);
- psum = vec_mladd(vC, vsrc2ssH, psum);
- psum = vec_mladd(vD, vsrc3ssH, psum);
- psum = vec_add(v32ss, psum);
- psum = vec_sr(psum, v6us);
-
- vdst = vec_ld(0, dst);
- ppsum = (vector unsigned char)vec_pack(psum, psum);
- vfdst = vec_perm(vdst, ppsum, fperm);
-
- OP_U8_ALTIVEC(fsum, vfdst, vdst);
-
- vec_st(fsum, 0, dst);
-
- vsrc0ssH = vsrc2ssH;
- vsrc1ssH = vsrc3ssH;
-
- dst += stride;
- src += stride;
- }
- }
- POWERPC_PERF_STOP_COUNT(PREFIX_h264_chroma_mc8_num, 1);
-}
-
-/* this code assume stride % 16 == 0 */
-static void PREFIX_h264_qpel16_h_lowpass_altivec(uint8_t * dst, uint8_t * src, int dstStride, int srcStride) {
- POWERPC_PERF_DECLARE(PREFIX_h264_qpel16_h_lowpass_num, 1);
- register int i;
-
- const vector signed int vzero = vec_splat_s32(0);
- const vector unsigned char permM2 = vec_lvsl(-2, src);
- const vector unsigned char permM1 = vec_lvsl(-1, src);
- const vector unsigned char permP0 = vec_lvsl(+0, src);
- const vector unsigned char permP1 = vec_lvsl(+1, src);
- const vector unsigned char permP2 = vec_lvsl(+2, src);
- const vector unsigned char permP3 = vec_lvsl(+3, src);
- const vector signed short v5ss = vec_splat_s16(5);
- const vector unsigned short v5us = vec_splat_u16(5);
- const vector signed short v20ss = vec_sl(vec_splat_s16(5),vec_splat_u16(2));
- const vector signed short v16ss = vec_sl(vec_splat_s16(1),vec_splat_u16(4));
- const vector unsigned char dstperm = vec_lvsr(0, dst);
- const vector unsigned char neg1 =
- (const vector unsigned char) vec_splat_s8(-1);
-
- const vector unsigned char dstmask =
- vec_perm((const vector unsigned char)vzero,
- neg1, dstperm);
-
- vector unsigned char srcM2, srcM1, srcP0, srcP1, srcP2, srcP3;
-
- register int align = ((((unsigned long)src) - 2) % 16);
-
- vector signed short srcP0A, srcP0B, srcP1A, srcP1B,
- srcP2A, srcP2B, srcP3A, srcP3B,
- srcM1A, srcM1B, srcM2A, srcM2B,
- sum1A, sum1B, sum2A, sum2B, sum3A, sum3B,
- pp1A, pp1B, pp2A, pp2B, pp3A, pp3B,
- psumA, psumB, sumA, sumB;
-
- vector unsigned char sum, dst1, dst2, vdst, fsum,
- rsum, fdst1, fdst2;
-
- POWERPC_PERF_START_COUNT(PREFIX_h264_qpel16_h_lowpass_num, 1);
-
- for (i = 0 ; i < 16 ; i ++) {
- vector unsigned char srcR1 = vec_ld(-2, src);
- vector unsigned char srcR2 = vec_ld(14, src);
-
- switch (align) {
- default: {
- srcM2 = vec_perm(srcR1, srcR2, permM2);
- srcM1 = vec_perm(srcR1, srcR2, permM1);
- srcP0 = vec_perm(srcR1, srcR2, permP0);
- srcP1 = vec_perm(srcR1, srcR2, permP1);
- srcP2 = vec_perm(srcR1, srcR2, permP2);
- srcP3 = vec_perm(srcR1, srcR2, permP3);
- } break;
- case 11: {
- srcM2 = vec_perm(srcR1, srcR2, permM2);
- srcM1 = vec_perm(srcR1, srcR2, permM1);
- srcP0 = vec_perm(srcR1, srcR2, permP0);
- srcP1 = vec_perm(srcR1, srcR2, permP1);
- srcP2 = vec_perm(srcR1, srcR2, permP2);
- srcP3 = srcR2;
- } break;
- case 12: {
- vector unsigned char srcR3 = vec_ld(30, src);
- srcM2 = vec_perm(srcR1, srcR2, permM2);
- srcM1 = vec_perm(srcR1, srcR2, permM1);
- srcP0 = vec_perm(srcR1, srcR2, permP0);
- srcP1 = vec_perm(srcR1, srcR2, permP1);
- srcP2 = srcR2;
- srcP3 = vec_perm(srcR2, srcR3, permP3);
- } break;
- case 13: {
- vector unsigned char srcR3 = vec_ld(30, src);
- srcM2 = vec_perm(srcR1, srcR2, permM2);
- srcM1 = vec_perm(srcR1, srcR2, permM1);
- srcP0 = vec_perm(srcR1, srcR2, permP0);
- srcP1 = srcR2;
- srcP2 = vec_perm(srcR2, srcR3, permP2);
- srcP3 = vec_perm(srcR2, srcR3, permP3);
- } break;
- case 14: {
- vector unsigned char srcR3 = vec_ld(30, src);
- srcM2 = vec_perm(srcR1, srcR2, permM2);
- srcM1 = vec_perm(srcR1, srcR2, permM1);
- srcP0 = srcR2;
- srcP1 = vec_perm(srcR2, srcR3, permP1);
- srcP2 = vec_perm(srcR2, srcR3, permP2);
- srcP3 = vec_perm(srcR2, srcR3, permP3);
- } break;
- case 15: {
- vector unsigned char srcR3 = vec_ld(30, src);
- srcM2 = vec_perm(srcR1, srcR2, permM2);
- srcM1 = srcR2;
- srcP0 = vec_perm(srcR2, srcR3, permP0);
- srcP1 = vec_perm(srcR2, srcR3, permP1);
- srcP2 = vec_perm(srcR2, srcR3, permP2);
- srcP3 = vec_perm(srcR2, srcR3, permP3);
- } break;
- }
-
- srcP0A = (vector signed short)
- vec_mergeh((vector unsigned char)vzero, srcP0);
- srcP0B = (vector signed short)
- vec_mergel((vector unsigned char)vzero, srcP0);
- srcP1A = (vector signed short)
- vec_mergeh((vector unsigned char)vzero, srcP1);
- srcP1B = (vector signed short)
- vec_mergel((vector unsigned char)vzero, srcP1);
-
- srcP2A = (vector signed short)
- vec_mergeh((vector unsigned char)vzero, srcP2);
- srcP2B = (vector signed short)
- vec_mergel((vector unsigned char)vzero, srcP2);
- srcP3A = (vector signed short)
- vec_mergeh((vector unsigned char)vzero, srcP3);
- srcP3B = (vector signed short)
- vec_mergel((vector unsigned char)vzero, srcP3);
-
- srcM1A = (vector signed short)
- vec_mergeh((vector unsigned char)vzero, srcM1);
- srcM1B = (vector signed short)
- vec_mergel((vector unsigned char)vzero, srcM1);
- srcM2A = (vector signed short)
- vec_mergeh((vector unsigned char)vzero, srcM2);
- srcM2B = (vector signed short)
- vec_mergel((vector unsigned char)vzero, srcM2);
-
- sum1A = vec_adds(srcP0A, srcP1A);
- sum1B = vec_adds(srcP0B, srcP1B);
- sum2A = vec_adds(srcM1A, srcP2A);
- sum2B = vec_adds(srcM1B, srcP2B);
- sum3A = vec_adds(srcM2A, srcP3A);
- sum3B = vec_adds(srcM2B, srcP3B);
-
- pp1A = vec_mladd(sum1A, v20ss, v16ss);
- pp1B = vec_mladd(sum1B, v20ss, v16ss);
-
- pp2A = vec_mladd(sum2A, v5ss, (vector signed short)vzero);
- pp2B = vec_mladd(sum2B, v5ss, (vector signed short)vzero);
-
- pp3A = vec_add(sum3A, pp1A);
- pp3B = vec_add(sum3B, pp1B);
-
- psumA = vec_sub(pp3A, pp2A);
- psumB = vec_sub(pp3B, pp2B);
-
- sumA = vec_sra(psumA, v5us);
- sumB = vec_sra(psumB, v5us);
-
- sum = vec_packsu(sumA, sumB);
-
- dst1 = vec_ld(0, dst);
- dst2 = vec_ld(16, dst);
- vdst = vec_perm(dst1, dst2, vec_lvsl(0, dst));
-
- OP_U8_ALTIVEC(fsum, sum, vdst);
-
- rsum = vec_perm(fsum, fsum, dstperm);
- fdst1 = vec_sel(dst1, rsum, dstmask);
- fdst2 = vec_sel(rsum, dst2, dstmask);
-
- vec_st(fdst1, 0, dst);
- vec_st(fdst2, 16, dst);
-
- src += srcStride;
- dst += dstStride;
- }
-POWERPC_PERF_STOP_COUNT(PREFIX_h264_qpel16_h_lowpass_num, 1);
-}
-
-/* this code assume stride % 16 == 0 */
-static void PREFIX_h264_qpel16_v_lowpass_altivec(uint8_t * dst, uint8_t * src, int dstStride, int srcStride) {
- POWERPC_PERF_DECLARE(PREFIX_h264_qpel16_v_lowpass_num, 1);
-
- register int i;
-
- const vector signed int vzero = vec_splat_s32(0);
- const vector unsigned char perm = vec_lvsl(0, src);
- const vector signed short v20ss = vec_sl(vec_splat_s16(5),vec_splat_u16(2));
- const vector unsigned short v5us = vec_splat_u16(5);
- const vector signed short v5ss = vec_splat_s16(5);
- const vector signed short v16ss = vec_sl(vec_splat_s16(1),vec_splat_u16(4));
- const vector unsigned char dstperm = vec_lvsr(0, dst);
- const vector unsigned char neg1 = (const vector unsigned char)vec_splat_s8(-1);
- const vector unsigned char dstmask = vec_perm((const vector unsigned char)vzero, neg1, dstperm);
-
- uint8_t *srcbis = src - (srcStride * 2);
-
- const vector unsigned char srcM2a = vec_ld(0, srcbis);
- const vector unsigned char srcM2b = vec_ld(16, srcbis);
- const vector unsigned char srcM2 = vec_perm(srcM2a, srcM2b, perm);
-// srcbis += srcStride;
- const vector unsigned char srcM1a = vec_ld(0, srcbis += srcStride);
- const vector unsigned char srcM1b = vec_ld(16, srcbis);
- const vector unsigned char srcM1 = vec_perm(srcM1a, srcM1b, perm);
-// srcbis += srcStride;
- const vector unsigned char srcP0a = vec_ld(0, srcbis += srcStride);
- const vector unsigned char srcP0b = vec_ld(16, srcbis);
- const vector unsigned char srcP0 = vec_perm(srcP0a, srcP0b, perm);
-// srcbis += srcStride;
- const vector unsigned char srcP1a = vec_ld(0, srcbis += srcStride);
- const vector unsigned char srcP1b = vec_ld(16, srcbis);
- const vector unsigned char srcP1 = vec_perm(srcP1a, srcP1b, perm);
-// srcbis += srcStride;
- const vector unsigned char srcP2a = vec_ld(0, srcbis += srcStride);
- const vector unsigned char srcP2b = vec_ld(16, srcbis);
- const vector unsigned char srcP2 = vec_perm(srcP2a, srcP2b, perm);
-// srcbis += srcStride;
-
- vector signed short srcM2ssA = (vector signed short)
- vec_mergeh((vector unsigned char)vzero, srcM2);
- vector signed short srcM2ssB = (vector signed short)
- vec_mergel((vector unsigned char)vzero, srcM2);
- vector signed short srcM1ssA = (vector signed short)
- vec_mergeh((vector unsigned char)vzero, srcM1);
- vector signed short srcM1ssB = (vector signed short)
- vec_mergel((vector unsigned char)vzero, srcM1);
- vector signed short srcP0ssA = (vector signed short)
- vec_mergeh((vector unsigned char)vzero, srcP0);
- vector signed short srcP0ssB = (vector signed short)
- vec_mergel((vector unsigned char)vzero, srcP0);
- vector signed short srcP1ssA = (vector signed short)
- vec_mergeh((vector unsigned char)vzero, srcP1);
- vector signed short srcP1ssB = (vector signed short)
- vec_mergel((vector unsigned char)vzero, srcP1);
- vector signed short srcP2ssA = (vector signed short)
- vec_mergeh((vector unsigned char)vzero, srcP2);
- vector signed short srcP2ssB = (vector signed short)
- vec_mergel((vector unsigned char)vzero, srcP2);
-
- vector signed short pp1A, pp1B, pp2A, pp2B, pp3A, pp3B,
- psumA, psumB, sumA, sumB,
- srcP3ssA, srcP3ssB,
- sum1A, sum1B, sum2A, sum2B, sum3A, sum3B;
-
- vector unsigned char sum, dst1, dst2, vdst, fsum, rsum, fdst1, fdst2,
- srcP3a, srcP3b, srcP3;
-
- POWERPC_PERF_START_COUNT(PREFIX_h264_qpel16_v_lowpass_num, 1);
-
- for (i = 0 ; i < 16 ; i++) {
- srcP3a = vec_ld(0, srcbis += srcStride);
- srcP3b = vec_ld(16, srcbis);
- srcP3 = vec_perm(srcP3a, srcP3b, perm);
- srcP3ssA = (vector signed short)
- vec_mergeh((vector unsigned char)vzero, srcP3);
- srcP3ssB = (vector signed short)
- vec_mergel((vector unsigned char)vzero, srcP3);
-// srcbis += srcStride;
-
- sum1A = vec_adds(srcP0ssA, srcP1ssA);
- sum1B = vec_adds(srcP0ssB, srcP1ssB);
- sum2A = vec_adds(srcM1ssA, srcP2ssA);
- sum2B = vec_adds(srcM1ssB, srcP2ssB);
- sum3A = vec_adds(srcM2ssA, srcP3ssA);
- sum3B = vec_adds(srcM2ssB, srcP3ssB);
-
- srcM2ssA = srcM1ssA;
- srcM2ssB = srcM1ssB;
- srcM1ssA = srcP0ssA;
- srcM1ssB = srcP0ssB;
- srcP0ssA = srcP1ssA;
- srcP0ssB = srcP1ssB;
- srcP1ssA = srcP2ssA;
- srcP1ssB = srcP2ssB;
- srcP2ssA = srcP3ssA;
- srcP2ssB = srcP3ssB;
-
- pp1A = vec_mladd(sum1A, v20ss, v16ss);
- pp1B = vec_mladd(sum1B, v20ss, v16ss);
-
- pp2A = vec_mladd(sum2A, v5ss, (vector signed short)vzero);
- pp2B = vec_mladd(sum2B, v5ss, (vector signed short)vzero);
-
- pp3A = vec_add(sum3A, pp1A);
- pp3B = vec_add(sum3B, pp1B);
-
- psumA = vec_sub(pp3A, pp2A);
- psumB = vec_sub(pp3B, pp2B);
-
- sumA = vec_sra(psumA, v5us);
- sumB = vec_sra(psumB, v5us);
-
- sum = vec_packsu(sumA, sumB);
-
- dst1 = vec_ld(0, dst);
- dst2 = vec_ld(16, dst);
- vdst = vec_perm(dst1, dst2, vec_lvsl(0, dst));
-
- OP_U8_ALTIVEC(fsum, sum, vdst);
-
- rsum = vec_perm(fsum, fsum, dstperm);
- fdst1 = vec_sel(dst1, rsum, dstmask);
- fdst2 = vec_sel(rsum, dst2, dstmask);
-
- vec_st(fdst1, 0, dst);
- vec_st(fdst2, 16, dst);
-
- dst += dstStride;
- }
- POWERPC_PERF_STOP_COUNT(PREFIX_h264_qpel16_v_lowpass_num, 1);
-}
-
-/* this code assume stride % 16 == 0 *and* tmp is properly aligned */
-static void PREFIX_h264_qpel16_hv_lowpass_altivec(uint8_t * dst, int16_t * tmp, uint8_t * src, int dstStride, int tmpStride, int srcStride) {
- POWERPC_PERF_DECLARE(PREFIX_h264_qpel16_hv_lowpass_num, 1);
- register int i;
- const vector signed int vzero = vec_splat_s32(0);
- const vector unsigned char permM2 = vec_lvsl(-2, src);
- const vector unsigned char permM1 = vec_lvsl(-1, src);
- const vector unsigned char permP0 = vec_lvsl(+0, src);
- const vector unsigned char permP1 = vec_lvsl(+1, src);
- const vector unsigned char permP2 = vec_lvsl(+2, src);
- const vector unsigned char permP3 = vec_lvsl(+3, src);
- const vector signed short v20ss = vec_sl(vec_splat_s16(5),vec_splat_u16(2));
- const vector unsigned int v10ui = vec_splat_u32(10);
- const vector signed short v5ss = vec_splat_s16(5);
- const vector signed short v1ss = vec_splat_s16(1);
- const vector signed int v512si = vec_sl(vec_splat_s32(1),vec_splat_u32(9));
- const vector unsigned int v16ui = vec_sl(vec_splat_u32(1),vec_splat_u32(4));
-
- register int align = ((((unsigned long)src) - 2) % 16);
-
- const vector unsigned char neg1 = (const vector unsigned char)
- vec_splat_s8(-1);
-
- vector signed short srcP0A, srcP0B, srcP1A, srcP1B,
- srcP2A, srcP2B, srcP3A, srcP3B,
- srcM1A, srcM1B, srcM2A, srcM2B,
- sum1A, sum1B, sum2A, sum2B, sum3A, sum3B,
- pp1A, pp1B, pp2A, pp2B, psumA, psumB;
-
- const vector unsigned char dstperm = vec_lvsr(0, dst);
-
- const vector unsigned char dstmask = vec_perm((const vector unsigned char)vzero, neg1, dstperm);
-
- const vector unsigned char mperm = (const vector unsigned char)
- AVV(0x00, 0x08, 0x01, 0x09, 0x02, 0x0A, 0x03, 0x0B,
- 0x04, 0x0C, 0x05, 0x0D, 0x06, 0x0E, 0x07, 0x0F);
- int16_t *tmpbis = tmp;
-
- vector signed short tmpM1ssA, tmpM1ssB, tmpM2ssA, tmpM2ssB,
- tmpP0ssA, tmpP0ssB, tmpP1ssA, tmpP1ssB,
- tmpP2ssA, tmpP2ssB;
-
- vector signed int pp1Ae, pp1Ao, pp1Be, pp1Bo, pp2Ae, pp2Ao, pp2Be, pp2Bo,
- pp3Ae, pp3Ao, pp3Be, pp3Bo, pp1cAe, pp1cAo, pp1cBe, pp1cBo,
- pp32Ae, pp32Ao, pp32Be, pp32Bo, sumAe, sumAo, sumBe, sumBo,
- ssumAe, ssumAo, ssumBe, ssumBo;
- vector unsigned char fsum, sumv, sum, dst1, dst2, vdst,
- rsum, fdst1, fdst2;
- vector signed short ssume, ssumo;
-
- POWERPC_PERF_START_COUNT(PREFIX_h264_qpel16_hv_lowpass_num, 1);
- src -= (2 * srcStride);
- for (i = 0 ; i < 21 ; i ++) {
- vector unsigned char srcM2, srcM1, srcP0, srcP1, srcP2, srcP3;
- vector unsigned char srcR1 = vec_ld(-2, src);
- vector unsigned char srcR2 = vec_ld(14, src);
-
- switch (align) {
- default: {
- srcM2 = vec_perm(srcR1, srcR2, permM2);
- srcM1 = vec_perm(srcR1, srcR2, permM1);
- srcP0 = vec_perm(srcR1, srcR2, permP0);
- srcP1 = vec_perm(srcR1, srcR2, permP1);
- srcP2 = vec_perm(srcR1, srcR2, permP2);
- srcP3 = vec_perm(srcR1, srcR2, permP3);
- } break;
- case 11: {
- srcM2 = vec_perm(srcR1, srcR2, permM2);
- srcM1 = vec_perm(srcR1, srcR2, permM1);
- srcP0 = vec_perm(srcR1, srcR2, permP0);
- srcP1 = vec_perm(srcR1, srcR2, permP1);
- srcP2 = vec_perm(srcR1, srcR2, permP2);
- srcP3 = srcR2;
- } break;
- case 12: {
- vector unsigned char srcR3 = vec_ld(30, src);
- srcM2 = vec_perm(srcR1, srcR2, permM2);
- srcM1 = vec_perm(srcR1, srcR2, permM1);
- srcP0 = vec_perm(srcR1, srcR2, permP0);
- srcP1 = vec_perm(srcR1, srcR2, permP1);
- srcP2 = srcR2;
- srcP3 = vec_perm(srcR2, srcR3, permP3);
- } break;
- case 13: {
- vector unsigned char srcR3 = vec_ld(30, src);
- srcM2 = vec_perm(srcR1, srcR2, permM2);
- srcM1 = vec_perm(srcR1, srcR2, permM1);
- srcP0 = vec_perm(srcR1, srcR2, permP0);
- srcP1 = srcR2;
- srcP2 = vec_perm(srcR2, srcR3, permP2);
- srcP3 = vec_perm(srcR2, srcR3, permP3);
- } break;
- case 14: {
- vector unsigned char srcR3 = vec_ld(30, src);
- srcM2 = vec_perm(srcR1, srcR2, permM2);
- srcM1 = vec_perm(srcR1, srcR2, permM1);
- srcP0 = srcR2;
- srcP1 = vec_perm(srcR2, srcR3, permP1);
- srcP2 = vec_perm(srcR2, srcR3, permP2);
- srcP3 = vec_perm(srcR2, srcR3, permP3);
- } break;
- case 15: {
- vector unsigned char srcR3 = vec_ld(30, src);
- srcM2 = vec_perm(srcR1, srcR2, permM2);
- srcM1 = srcR2;
- srcP0 = vec_perm(srcR2, srcR3, permP0);
- srcP1 = vec_perm(srcR2, srcR3, permP1);
- srcP2 = vec_perm(srcR2, srcR3, permP2);
- srcP3 = vec_perm(srcR2, srcR3, permP3);
- } break;
- }
-
- srcP0A = (vector signed short)
- vec_mergeh((vector unsigned char)vzero, srcP0);
- srcP0B = (vector signed short)
- vec_mergel((vector unsigned char)vzero, srcP0);
- srcP1A = (vector signed short)
- vec_mergeh((vector unsigned char)vzero, srcP1);
- srcP1B = (vector signed short)
- vec_mergel((vector unsigned char)vzero, srcP1);
-
- srcP2A = (vector signed short)
- vec_mergeh((vector unsigned char)vzero, srcP2);
- srcP2B = (vector signed short)
- vec_mergel((vector unsigned char)vzero, srcP2);
- srcP3A = (vector signed short)
- vec_mergeh((vector unsigned char)vzero, srcP3);
- srcP3B = (vector signed short)
- vec_mergel((vector unsigned char)vzero, srcP3);
-
- srcM1A = (vector signed short)
- vec_mergeh((vector unsigned char)vzero, srcM1);
- srcM1B = (vector signed short)
- vec_mergel((vector unsigned char)vzero, srcM1);
- srcM2A = (vector signed short)
- vec_mergeh((vector unsigned char)vzero, srcM2);
- srcM2B = (vector signed short)
- vec_mergel((vector unsigned char)vzero, srcM2);
-
- sum1A = vec_adds(srcP0A, srcP1A);
- sum1B = vec_adds(srcP0B, srcP1B);
- sum2A = vec_adds(srcM1A, srcP2A);
- sum2B = vec_adds(srcM1B, srcP2B);
- sum3A = vec_adds(srcM2A, srcP3A);
- sum3B = vec_adds(srcM2B, srcP3B);
-
- pp1A = vec_mladd(sum1A, v20ss, sum3A);
- pp1B = vec_mladd(sum1B, v20ss, sum3B);
-
- pp2A = vec_mladd(sum2A, v5ss, (vector signed short)vzero);
- pp2B = vec_mladd(sum2B, v5ss, (vector signed short)vzero);
-
- psumA = vec_sub(pp1A, pp2A);
- psumB = vec_sub(pp1B, pp2B);
-
- vec_st(psumA, 0, tmp);
- vec_st(psumB, 16, tmp);
-
- src += srcStride;
- tmp += tmpStride; /* int16_t*, and stride is 16, so it's OK here */
- }
-
- tmpM2ssA = vec_ld(0, tmpbis);
- tmpM2ssB = vec_ld(16, tmpbis);
- tmpbis += tmpStride;
- tmpM1ssA = vec_ld(0, tmpbis);
- tmpM1ssB = vec_ld(16, tmpbis);
- tmpbis += tmpStride;
- tmpP0ssA = vec_ld(0, tmpbis);
- tmpP0ssB = vec_ld(16, tmpbis);
- tmpbis += tmpStride;
- tmpP1ssA = vec_ld(0, tmpbis);
- tmpP1ssB = vec_ld(16, tmpbis);
- tmpbis += tmpStride;
- tmpP2ssA = vec_ld(0, tmpbis);
- tmpP2ssB = vec_ld(16, tmpbis);
- tmpbis += tmpStride;
-
- for (i = 0 ; i < 16 ; i++) {
- const vector signed short tmpP3ssA = vec_ld(0, tmpbis);
- const vector signed short tmpP3ssB = vec_ld(16, tmpbis);
-
- const vector signed short sum1A = vec_adds(tmpP0ssA, tmpP1ssA);
- const vector signed short sum1B = vec_adds(tmpP0ssB, tmpP1ssB);
- const vector signed short sum2A = vec_adds(tmpM1ssA, tmpP2ssA);
- const vector signed short sum2B = vec_adds(tmpM1ssB, tmpP2ssB);
- const vector signed short sum3A = vec_adds(tmpM2ssA, tmpP3ssA);
- const vector signed short sum3B = vec_adds(tmpM2ssB, tmpP3ssB);
-
- tmpbis += tmpStride;
-
- tmpM2ssA = tmpM1ssA;
- tmpM2ssB = tmpM1ssB;
- tmpM1ssA = tmpP0ssA;
- tmpM1ssB = tmpP0ssB;
- tmpP0ssA = tmpP1ssA;
- tmpP0ssB = tmpP1ssB;
- tmpP1ssA = tmpP2ssA;
- tmpP1ssB = tmpP2ssB;
- tmpP2ssA = tmpP3ssA;
- tmpP2ssB = tmpP3ssB;
-
- pp1Ae = vec_mule(sum1A, v20ss);
- pp1Ao = vec_mulo(sum1A, v20ss);
- pp1Be = vec_mule(sum1B, v20ss);
- pp1Bo = vec_mulo(sum1B, v20ss);
-
- pp2Ae = vec_mule(sum2A, v5ss);
- pp2Ao = vec_mulo(sum2A, v5ss);
- pp2Be = vec_mule(sum2B, v5ss);
- pp2Bo = vec_mulo(sum2B, v5ss);
-
- pp3Ae = vec_sra((vector signed int)sum3A, v16ui);
- pp3Ao = vec_mulo(sum3A, v1ss);
- pp3Be = vec_sra((vector signed int)sum3B, v16ui);
- pp3Bo = vec_mulo(sum3B, v1ss);
-
- pp1cAe = vec_add(pp1Ae, v512si);
- pp1cAo = vec_add(pp1Ao, v512si);
- pp1cBe = vec_add(pp1Be, v512si);
- pp1cBo = vec_add(pp1Bo, v512si);
-
- pp32Ae = vec_sub(pp3Ae, pp2Ae);
- pp32Ao = vec_sub(pp3Ao, pp2Ao);
- pp32Be = vec_sub(pp3Be, pp2Be);
- pp32Bo = vec_sub(pp3Bo, pp2Bo);
-
- sumAe = vec_add(pp1cAe, pp32Ae);
- sumAo = vec_add(pp1cAo, pp32Ao);
- sumBe = vec_add(pp1cBe, pp32Be);
- sumBo = vec_add(pp1cBo, pp32Bo);
-
- ssumAe = vec_sra(sumAe, v10ui);
- ssumAo = vec_sra(sumAo, v10ui);
- ssumBe = vec_sra(sumBe, v10ui);
- ssumBo = vec_sra(sumBo, v10ui);
-
- ssume = vec_packs(ssumAe, ssumBe);
- ssumo = vec_packs(ssumAo, ssumBo);
-
- sumv = vec_packsu(ssume, ssumo);
- sum = vec_perm(sumv, sumv, mperm);
-
- dst1 = vec_ld(0, dst);
- dst2 = vec_ld(16, dst);
- vdst = vec_perm(dst1, dst2, vec_lvsl(0, dst));
-
- OP_U8_ALTIVEC(fsum, sum, vdst);
-
- rsum = vec_perm(fsum, fsum, dstperm);
- fdst1 = vec_sel(dst1, rsum, dstmask);
- fdst2 = vec_sel(rsum, dst2, dstmask);
-
- vec_st(fdst1, 0, dst);
- vec_st(fdst2, 16, dst);
-
- dst += dstStride;
- }
- POWERPC_PERF_STOP_COUNT(PREFIX_h264_qpel16_hv_lowpass_num, 1);
-}
diff --git a/src/libffmpeg/libavcodec/ppc/dsputil_ppc.c b/src/libffmpeg/libavcodec/ppc/dsputil_ppc.c
deleted file mode 100644
index 9169eaef0..000000000
--- a/src/libffmpeg/libavcodec/ppc/dsputil_ppc.c
+++ /dev/null
@@ -1,325 +0,0 @@
-/*
- * Copyright (c) 2002 Brian Foley
- * Copyright (c) 2002 Dieter Shirley
- * Copyright (c) 2003-2004 Romain Dolbeau <romain@dolbeau.org>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include "../dsputil.h"
-
-#include "dsputil_ppc.h"
-
-#ifdef HAVE_ALTIVEC
-#include "dsputil_altivec.h"
-
-extern void fdct_altivec(int16_t *block);
-extern void gmc1_altivec(uint8_t *dst, uint8_t *src, int stride, int h,
- int x16, int y16, int rounder);
-extern void idct_put_altivec(uint8_t *dest, int line_size, int16_t *block);
-extern void idct_add_altivec(uint8_t *dest, int line_size, int16_t *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 snow_init_altivec(DSPContext* c, AVCodecContext *avctx);
-void float_init_altivec(DSPContext* c, AVCodecContext *avctx);
-
-#endif
-
-int mm_flags = 0;
-
-int mm_support(void)
-{
- int result = 0;
-#ifdef HAVE_ALTIVEC
- if (has_altivec()) {
- result |= MM_ALTIVEC;
- }
-#endif /* result */
- return result;
-}
-
-#ifdef POWERPC_PERFORMANCE_REPORT
-unsigned long long perfdata[POWERPC_NUM_PMC_ENABLED][powerpc_perf_total][powerpc_data_total];
-/* list below must match enum in dsputil_ppc.h */
-static unsigned char* perfname[] = {
- "ff_fft_calc_altivec",
- "gmc1_altivec",
- "dct_unquantize_h263_altivec",
- "fdct_altivec",
- "idct_add_altivec",
- "idct_put_altivec",
- "put_pixels16_altivec",
- "avg_pixels16_altivec",
- "avg_pixels8_altivec",
- "put_pixels8_xy2_altivec",
- "put_no_rnd_pixels8_xy2_altivec",
- "put_pixels16_xy2_altivec",
- "put_no_rnd_pixels16_xy2_altivec",
- "hadamard8_diff8x8_altivec",
- "hadamard8_diff16_altivec",
- "avg_pixels8_xy2_altivec",
- "clear_blocks_dcbz32_ppc",
- "clear_blocks_dcbz128_ppc",
- "put_h264_chroma_mc8_altivec",
- "avg_h264_chroma_mc8_altivec",
- "put_h264_qpel16_h_lowpass_altivec",
- "avg_h264_qpel16_h_lowpass_altivec",
- "put_h264_qpel16_v_lowpass_altivec",
- "avg_h264_qpel16_v_lowpass_altivec",
- "put_h264_qpel16_hv_lowpass_altivec",
- "avg_h264_qpel16_hv_lowpass_altivec",
- ""
-};
-#include <stdio.h>
-#endif
-
-#ifdef POWERPC_PERFORMANCE_REPORT
-void powerpc_display_perf_report(void)
-{
- int i, j;
- av_log(NULL, AV_LOG_INFO, "PowerPC performance report\n Values are from the PMC registers, and represent whatever the registers are set to record.\n");
- for(i = 0 ; i < powerpc_perf_total ; i++)
- {
- for (j = 0; j < POWERPC_NUM_PMC_ENABLED ; j++)
- {
- if (perfdata[j][i][powerpc_data_num] != (unsigned long long)0)
- av_log(NULL, AV_LOG_INFO,
- " Function \"%s\" (pmc%d):\n\tmin: %"PRIu64"\n\tmax: %"PRIu64"\n\tavg: %1.2lf (%"PRIu64")\n",
- perfname[i],
- j+1,
- perfdata[j][i][powerpc_data_min],
- perfdata[j][i][powerpc_data_max],
- (double)perfdata[j][i][powerpc_data_sum] /
- (double)perfdata[j][i][powerpc_data_num],
- perfdata[j][i][powerpc_data_num]);
- }
- }
-}
-#endif /* POWERPC_PERFORMANCE_REPORT */
-
-/* ***** WARNING ***** WARNING ***** WARNING ***** */
-/*
- clear_blocks_dcbz32_ppc will not work properly
- on PowerPC processors with a cache line size
- not equal to 32 bytes.
- Fortunately all processor used by Apple up to
- at least the 7450 (aka second generation G4)
- use 32 bytes cache line.
- This is due to the use of the 'dcbz' instruction.
- It simply clear to zero a single cache line,
- so you need to know the cache line size to use it !
- It's absurd, but it's fast...
-
- update 24/06/2003 : Apple released yesterday the G5,
- with a PPC970. cache line size : 128 bytes. Oups.
- The semantic of dcbz was changed, it always clear
- 32 bytes. so the function below will work, but will
- be slow. So I fixed check_dcbz_effect to use dcbzl,
- which is defined to clear a cache line (as dcbz before).
- So we still can distinguish, and use dcbz (32 bytes)
- or dcbzl (one cache line) as required.
-
- see <http://developer.apple.com/technotes/tn/tn2087.html>
- and <http://developer.apple.com/technotes/tn/tn2086.html>
-*/
-void clear_blocks_dcbz32_ppc(DCTELEM *blocks)
-{
-POWERPC_PERF_DECLARE(powerpc_clear_blocks_dcbz32, 1);
- register int misal = ((unsigned long)blocks & 0x00000010);
- register int i = 0;
-POWERPC_PERF_START_COUNT(powerpc_clear_blocks_dcbz32, 1);
-#if 1
- if (misal) {
- ((unsigned long*)blocks)[0] = 0L;
- ((unsigned long*)blocks)[1] = 0L;
- ((unsigned long*)blocks)[2] = 0L;
- ((unsigned long*)blocks)[3] = 0L;
- i += 16;
- }
- for ( ; i < sizeof(DCTELEM)*6*64-31 ; i += 32) {
-#ifndef __MWERKS__
- asm volatile("dcbz %0,%1" : : "b" (blocks), "r" (i) : "memory");
-#else
- __dcbz( blocks, i );
-#endif
- }
- if (misal) {
- ((unsigned long*)blocks)[188] = 0L;
- ((unsigned long*)blocks)[189] = 0L;
- ((unsigned long*)blocks)[190] = 0L;
- ((unsigned long*)blocks)[191] = 0L;
- i += 16;
- }
-#else
- memset(blocks, 0, sizeof(DCTELEM)*6*64);
-#endif
-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 */
-#ifdef HAVE_DCBZL
-void clear_blocks_dcbz128_ppc(DCTELEM *blocks)
-{
-POWERPC_PERF_DECLARE(powerpc_clear_blocks_dcbz128, 1);
- register int misal = ((unsigned long)blocks & 0x0000007f);
- register int i = 0;
-POWERPC_PERF_START_COUNT(powerpc_clear_blocks_dcbz128, 1);
-#if 1
- if (misal) {
- // we could probably also optimize this case,
- // but there's not much point as the machines
- // aren't available yet (2003-06-26)
- memset(blocks, 0, sizeof(DCTELEM)*6*64);
- }
- else
- for ( ; i < sizeof(DCTELEM)*6*64 ; i += 128) {
- asm volatile("dcbzl %0,%1" : : "b" (blocks), "r" (i) : "memory");
- }
-#else
- memset(blocks, 0, sizeof(DCTELEM)*6*64);
-#endif
-POWERPC_PERF_STOP_COUNT(powerpc_clear_blocks_dcbz128, 1);
-}
-#else
-void clear_blocks_dcbz128_ppc(DCTELEM *blocks)
-{
- memset(blocks, 0, sizeof(DCTELEM)*6*64);
-}
-#endif
-
-#ifdef HAVE_DCBZL
-/* check dcbz report how many bytes are set to 0 by dcbz */
-/* update 24/06/2003 : replace dcbz by dcbzl to get
- the intended effect (Apple "fixed" dcbz)
- unfortunately this cannot be used unless the assembler
- knows about dcbzl ... */
-long check_dcbzl_effect(void)
-{
- register char *fakedata = (char*)av_malloc(1024);
- register char *fakedata_middle;
- register long zero = 0;
- register long i = 0;
- long count = 0;
-
- if (!fakedata)
- {
- return 0L;
- }
-
- fakedata_middle = (fakedata + 512);
-
- memset(fakedata, 0xFF, 1024);
-
- /* below the constraint "b" seems to mean "Address base register"
- in gcc-3.3 / RS/6000 speaks. seems to avoid using r0, so.... */
- asm volatile("dcbzl %0, %1" : : "b" (fakedata_middle), "r" (zero));
-
- for (i = 0; i < 1024 ; i ++)
- {
- if (fakedata[i] == (char)0)
- count++;
- }
-
- av_free(fakedata);
-
- return count;
-}
-#else
-long check_dcbzl_effect(void)
-{
- return 0;
-}
-#endif
-
-static void prefetch_ppc(void *mem, int stride, int h)
-{
- register const uint8_t *p = mem;
- do {
- asm volatile ("dcbt 0,%0" : : "r" (p));
- p+= stride;
- } while(--h);
-}
-
-void dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx)
-{
- // Common optimizations whether Altivec is available or not
- c->prefetch = prefetch_ppc;
- switch (check_dcbzl_effect()) {
- case 32:
- c->clear_blocks = clear_blocks_dcbz32_ppc;
- break;
- case 128:
- c->clear_blocks = clear_blocks_dcbz128_ppc;
- break;
- default:
- break;
- }
-
-#ifdef HAVE_ALTIVEC
- if(ENABLE_H264_DECODER) dsputil_h264_init_ppc(c, avctx);
-
- if (has_altivec()) {
- mm_flags |= MM_ALTIVEC;
-
- dsputil_init_altivec(c, avctx);
- if(ENABLE_SNOW_DECODER) snow_init_altivec(c, avctx);
- if(ENABLE_VC1_DECODER || ENABLE_WMV3_DECODER)
- vc1dsp_init_altivec(c, avctx);
- float_init_altivec(c, avctx);
- c->gmc1 = gmc1_altivec;
-
-#ifdef CONFIG_ENCODERS
- if (avctx->dct_algo == FF_DCT_AUTO ||
- avctx->dct_algo == FF_DCT_ALTIVEC)
- {
- c->fdct = fdct_altivec;
- }
-#endif //CONFIG_ENCODERS
-
- if (avctx->lowres==0)
- {
- if ((avctx->idct_algo == FF_IDCT_AUTO) ||
- (avctx->idct_algo == FF_IDCT_ALTIVEC))
- {
- c->idct_put = idct_put_altivec;
- c->idct_add = idct_add_altivec;
- c->idct_permutation_type = FF_TRANSPOSE_IDCT_PERM;
- }
- }
-
-#ifdef POWERPC_PERFORMANCE_REPORT
- {
- int i, j;
- for (i = 0 ; i < powerpc_perf_total ; i++)
- {
- for (j = 0; j < POWERPC_NUM_PMC_ENABLED ; j++)
- {
- perfdata[j][i][powerpc_data_min] = 0xFFFFFFFFFFFFFFFFULL;
- perfdata[j][i][powerpc_data_max] = 0x0000000000000000ULL;
- perfdata[j][i][powerpc_data_sum] = 0x0000000000000000ULL;
- perfdata[j][i][powerpc_data_num] = 0x0000000000000000ULL;
- }
- }
- }
-#endif /* POWERPC_PERFORMANCE_REPORT */
- }
-#endif /* HAVE_ALTIVEC */
-}
diff --git a/src/libffmpeg/libavcodec/ppc/dsputil_ppc.h b/src/libffmpeg/libavcodec/ppc/dsputil_ppc.h
deleted file mode 100644
index ab2b05780..000000000
--- a/src/libffmpeg/libavcodec/ppc/dsputil_ppc.h
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright (c) 2003-2004 Romain Dolbeau <romain@dolbeau.org>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef _DSPUTIL_PPC_
-#define _DSPUTIL_PPC_
-
-#ifdef POWERPC_PERFORMANCE_REPORT
-void powerpc_display_perf_report(void);
-/* the 604* have 2, the G3* have 4, the G4s have 6,
- and the G5 are completely different (they MUST use
- POWERPC_MODE_64BITS, and let's hope all future 64 bis PPC
- will use the same PMCs... */
-#define POWERPC_NUM_PMC_ENABLED 6
-/* if you add to the enum below, also add to the perfname array
- in dsputil_ppc.c */
-enum powerpc_perf_index {
- altivec_fft_num = 0,
- altivec_gmc1_num,
- altivec_dct_unquantize_h263_num,
- altivec_fdct,
- altivec_idct_add_num,
- altivec_idct_put_num,
- altivec_put_pixels16_num,
- altivec_avg_pixels16_num,
- altivec_avg_pixels8_num,
- altivec_put_pixels8_xy2_num,
- altivec_put_no_rnd_pixels8_xy2_num,
- altivec_put_pixels16_xy2_num,
- altivec_put_no_rnd_pixels16_xy2_num,
- altivec_hadamard8_diff8x8_num,
- altivec_hadamard8_diff16_num,
- altivec_avg_pixels8_xy2_num,
- powerpc_clear_blocks_dcbz32,
- powerpc_clear_blocks_dcbz128,
- altivec_put_h264_chroma_mc8_num,
- altivec_avg_h264_chroma_mc8_num,
- altivec_put_h264_qpel16_h_lowpass_num,
- altivec_avg_h264_qpel16_h_lowpass_num,
- altivec_put_h264_qpel16_v_lowpass_num,
- altivec_avg_h264_qpel16_v_lowpass_num,
- altivec_put_h264_qpel16_hv_lowpass_num,
- altivec_avg_h264_qpel16_hv_lowpass_num,
- powerpc_perf_total
-};
-enum powerpc_data_index {
- powerpc_data_min = 0,
- powerpc_data_max,
- powerpc_data_sum,
- powerpc_data_num,
- powerpc_data_total
-};
-extern unsigned long long perfdata[POWERPC_NUM_PMC_ENABLED][powerpc_perf_total][powerpc_data_total];
-
-#ifndef POWERPC_MODE_64BITS
-#define POWERP_PMC_DATATYPE unsigned long
-#define POWERPC_GET_PMC1(a) asm volatile("mfspr %0, 937" : "=r" (a))
-#define POWERPC_GET_PMC2(a) asm volatile("mfspr %0, 938" : "=r" (a))
-#if (POWERPC_NUM_PMC_ENABLED > 2)
-#define POWERPC_GET_PMC3(a) asm volatile("mfspr %0, 941" : "=r" (a))
-#define POWERPC_GET_PMC4(a) asm volatile("mfspr %0, 942" : "=r" (a))
-#else
-#define POWERPC_GET_PMC3(a) do {} while (0)
-#define POWERPC_GET_PMC4(a) do {} while (0)
-#endif
-#if (POWERPC_NUM_PMC_ENABLED > 4)
-#define POWERPC_GET_PMC5(a) asm volatile("mfspr %0, 929" : "=r" (a))
-#define POWERPC_GET_PMC6(a) asm volatile("mfspr %0, 930" : "=r" (a))
-#else
-#define POWERPC_GET_PMC5(a) do {} while (0)
-#define POWERPC_GET_PMC6(a) do {} while (0)
-#endif
-#else /* POWERPC_MODE_64BITS */
-#define POWERP_PMC_DATATYPE unsigned long long
-#define POWERPC_GET_PMC1(a) asm volatile("mfspr %0, 771" : "=r" (a))
-#define POWERPC_GET_PMC2(a) asm volatile("mfspr %0, 772" : "=r" (a))
-#if (POWERPC_NUM_PMC_ENABLED > 2)
-#define POWERPC_GET_PMC3(a) asm volatile("mfspr %0, 773" : "=r" (a))
-#define POWERPC_GET_PMC4(a) asm volatile("mfspr %0, 774" : "=r" (a))
-#else
-#define POWERPC_GET_PMC3(a) do {} while (0)
-#define POWERPC_GET_PMC4(a) do {} while (0)
-#endif
-#if (POWERPC_NUM_PMC_ENABLED > 4)
-#define POWERPC_GET_PMC5(a) asm volatile("mfspr %0, 775" : "=r" (a))
-#define POWERPC_GET_PMC6(a) asm volatile("mfspr %0, 776" : "=r" (a))
-#else
-#define POWERPC_GET_PMC5(a) do {} while (0)
-#define POWERPC_GET_PMC6(a) do {} while (0)
-#endif
-#endif /* POWERPC_MODE_64BITS */
-#define POWERPC_PERF_DECLARE(a, cond) \
- POWERP_PMC_DATATYPE \
- pmc_start[POWERPC_NUM_PMC_ENABLED], \
- pmc_stop[POWERPC_NUM_PMC_ENABLED], \
- pmc_loop_index;
-#define POWERPC_PERF_START_COUNT(a, cond) do { \
- POWERPC_GET_PMC6(pmc_start[5]); \
- POWERPC_GET_PMC5(pmc_start[4]); \
- POWERPC_GET_PMC4(pmc_start[3]); \
- POWERPC_GET_PMC3(pmc_start[2]); \
- POWERPC_GET_PMC2(pmc_start[1]); \
- POWERPC_GET_PMC1(pmc_start[0]); \
- } while (0)
-#define POWERPC_PERF_STOP_COUNT(a, cond) do { \
- POWERPC_GET_PMC1(pmc_stop[0]); \
- POWERPC_GET_PMC2(pmc_stop[1]); \
- POWERPC_GET_PMC3(pmc_stop[2]); \
- POWERPC_GET_PMC4(pmc_stop[3]); \
- POWERPC_GET_PMC5(pmc_stop[4]); \
- POWERPC_GET_PMC6(pmc_stop[5]); \
- if (cond) \
- { \
- for(pmc_loop_index = 0; \
- pmc_loop_index < POWERPC_NUM_PMC_ENABLED; \
- pmc_loop_index++) \
- { \
- if (pmc_stop[pmc_loop_index] >= pmc_start[pmc_loop_index]) \
- { \
- POWERP_PMC_DATATYPE diff = \
- pmc_stop[pmc_loop_index] - pmc_start[pmc_loop_index]; \
- if (diff < perfdata[pmc_loop_index][a][powerpc_data_min]) \
- perfdata[pmc_loop_index][a][powerpc_data_min] = diff; \
- if (diff > perfdata[pmc_loop_index][a][powerpc_data_max]) \
- perfdata[pmc_loop_index][a][powerpc_data_max] = diff; \
- perfdata[pmc_loop_index][a][powerpc_data_sum] += diff; \
- perfdata[pmc_loop_index][a][powerpc_data_num] ++; \
- } \
- } \
- } \
-} while (0)
-#else /* POWERPC_PERFORMANCE_REPORT */
-// those are needed to avoid empty statements.
-#define POWERPC_PERF_DECLARE(a, cond) int altivec_placeholder __attribute__ ((unused))
-#define POWERPC_PERF_START_COUNT(a, cond) do {} while (0)
-#define POWERPC_PERF_STOP_COUNT(a, cond) do {} while (0)
-#endif /* POWERPC_PERFORMANCE_REPORT */
-
-#endif /* _DSPUTIL_PPC_ */
diff --git a/src/libffmpeg/libavcodec/ppc/idct_altivec.c b/src/libffmpeg/libavcodec/ppc/idct_altivec.c
deleted file mode 100644
index cee46fc25..000000000
--- a/src/libffmpeg/libavcodec/ppc/idct_altivec.c
+++ /dev/null
@@ -1,237 +0,0 @@
-/*
- * Copyright (c) 2001 Michel Lespinasse
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-/*
- * NOTE: This code is based on GPL code from the libmpeg2 project. The
- * author, Michel Lespinasses, has given explicit permission to release
- * under LGPL as part of ffmpeg.
- *
- */
-
-/*
- * FFMpeg integration by Dieter Shirley
- *
- * This file is a direct copy of the altivec idct module from the libmpeg2
- * project. I've deleted all of the libmpeg2 specific code, renamed the functions and
- * re-ordered the function parameters. The only change to the IDCT function
- * itself was to factor out the partial transposition, and to perform a full
- * transpose at the end of the function.
- */
-
-
-#include <stdlib.h> /* malloc(), free() */
-#include <string.h>
-#include "../dsputil.h"
-
-#include "gcc_fixes.h"
-
-#include "dsputil_altivec.h"
-
-#define vector_s16_t vector signed short
-#define const_vector_s16_t const_vector signed short
-#define vector_u16_t vector unsigned short
-#define vector_s8_t vector signed char
-#define vector_u8_t vector unsigned char
-#define vector_s32_t vector signed int
-#define vector_u32_t vector unsigned int
-
-#define IDCT_HALF \
- /* 1st stage */ \
- t1 = vec_mradds (a1, vx7, vx1 ); \
- t8 = vec_mradds (a1, vx1, vec_subs (zero, vx7)); \
- t7 = vec_mradds (a2, vx5, vx3); \
- t3 = vec_mradds (ma2, vx3, vx5); \
- \
- /* 2nd stage */ \
- t5 = vec_adds (vx0, vx4); \
- t0 = vec_subs (vx0, vx4); \
- t2 = vec_mradds (a0, vx6, vx2); \
- t4 = vec_mradds (a0, vx2, vec_subs (zero, vx6)); \
- t6 = vec_adds (t8, t3); \
- t3 = vec_subs (t8, t3); \
- t8 = vec_subs (t1, t7); \
- t1 = vec_adds (t1, t7); \
- \
- /* 3rd stage */ \
- t7 = vec_adds (t5, t2); \
- t2 = vec_subs (t5, t2); \
- t5 = vec_adds (t0, t4); \
- t0 = vec_subs (t0, t4); \
- t4 = vec_subs (t8, t3); \
- t3 = vec_adds (t8, t3); \
- \
- /* 4th stage */ \
- vy0 = vec_adds (t7, t1); \
- vy7 = vec_subs (t7, t1); \
- vy1 = vec_mradds (c4, t3, t5); \
- vy6 = vec_mradds (mc4, t3, t5); \
- vy2 = vec_mradds (c4, t4, t0); \
- vy5 = vec_mradds (mc4, t4, t0); \
- vy3 = vec_adds (t2, t6); \
- vy4 = vec_subs (t2, t6);
-
-
-#define IDCT \
- vector_s16_t vx0, vx1, vx2, vx3, vx4, vx5, vx6, vx7; \
- vector_s16_t vy0, vy1, vy2, vy3, vy4, vy5, vy6, vy7; \
- vector_s16_t a0, a1, a2, ma2, c4, mc4, zero, bias; \
- vector_s16_t t0, t1, t2, t3, t4, t5, t6, t7, t8; \
- vector_u16_t shift; \
- \
- c4 = vec_splat (constants[0], 0); \
- a0 = vec_splat (constants[0], 1); \
- a1 = vec_splat (constants[0], 2); \
- a2 = vec_splat (constants[0], 3); \
- mc4 = vec_splat (constants[0], 4); \
- ma2 = vec_splat (constants[0], 5); \
- bias = (vector_s16_t)vec_splat ((vector_s32_t)constants[0], 3); \
- \
- zero = vec_splat_s16 (0); \
- shift = vec_splat_u16 (4); \
- \
- vx0 = vec_mradds (vec_sl (block[0], shift), constants[1], zero); \
- vx1 = vec_mradds (vec_sl (block[1], shift), constants[2], zero); \
- vx2 = vec_mradds (vec_sl (block[2], shift), constants[3], zero); \
- vx3 = vec_mradds (vec_sl (block[3], shift), constants[4], zero); \
- vx4 = vec_mradds (vec_sl (block[4], shift), constants[1], zero); \
- vx5 = vec_mradds (vec_sl (block[5], shift), constants[4], zero); \
- vx6 = vec_mradds (vec_sl (block[6], shift), constants[3], zero); \
- vx7 = vec_mradds (vec_sl (block[7], shift), constants[2], zero); \
- \
- IDCT_HALF \
- \
- vx0 = vec_mergeh (vy0, vy4); \
- vx1 = vec_mergel (vy0, vy4); \
- vx2 = vec_mergeh (vy1, vy5); \
- vx3 = vec_mergel (vy1, vy5); \
- vx4 = vec_mergeh (vy2, vy6); \
- vx5 = vec_mergel (vy2, vy6); \
- vx6 = vec_mergeh (vy3, vy7); \
- vx7 = vec_mergel (vy3, vy7); \
- \
- vy0 = vec_mergeh (vx0, vx4); \
- vy1 = vec_mergel (vx0, vx4); \
- vy2 = vec_mergeh (vx1, vx5); \
- vy3 = vec_mergel (vx1, vx5); \
- vy4 = vec_mergeh (vx2, vx6); \
- vy5 = vec_mergel (vx2, vx6); \
- vy6 = vec_mergeh (vx3, vx7); \
- vy7 = vec_mergel (vx3, vx7); \
- \
- vx0 = vec_adds (vec_mergeh (vy0, vy4), bias); \
- vx1 = vec_mergel (vy0, vy4); \
- vx2 = vec_mergeh (vy1, vy5); \
- vx3 = vec_mergel (vy1, vy5); \
- vx4 = vec_mergeh (vy2, vy6); \
- vx5 = vec_mergel (vy2, vy6); \
- vx6 = vec_mergeh (vy3, vy7); \
- vx7 = vec_mergel (vy3, vy7); \
- \
- IDCT_HALF \
- \
- shift = vec_splat_u16 (6); \
- vx0 = vec_sra (vy0, shift); \
- vx1 = vec_sra (vy1, shift); \
- vx2 = vec_sra (vy2, shift); \
- vx3 = vec_sra (vy3, shift); \
- vx4 = vec_sra (vy4, shift); \
- vx5 = vec_sra (vy5, shift); \
- vx6 = vec_sra (vy6, shift); \
- vx7 = vec_sra (vy7, shift);
-
-
-static const_vector_s16_t constants[5] = {
- (vector_s16_t) AVV(23170, 13573, 6518, 21895, -23170, -21895, 32, 31),
- (vector_s16_t) AVV(16384, 22725, 21407, 19266, 16384, 19266, 21407, 22725),
- (vector_s16_t) AVV(22725, 31521, 29692, 26722, 22725, 26722, 29692, 31521),
- (vector_s16_t) AVV(21407, 29692, 27969, 25172, 21407, 25172, 27969, 29692),
- (vector_s16_t) AVV(19266, 26722, 25172, 22654, 19266, 22654, 25172, 26722)
-};
-
-void idct_put_altivec(uint8_t* dest, int stride, vector_s16_t* block)
-{
-POWERPC_PERF_DECLARE(altivec_idct_put_num, 1);
- vector_u8_t tmp;
-
-#ifdef POWERPC_PERFORMANCE_REPORT
-POWERPC_PERF_START_COUNT(altivec_idct_put_num, 1);
-#endif
- IDCT
-
-#define COPY(dest,src) \
- tmp = vec_packsu (src, src); \
- vec_ste ((vector_u32_t)tmp, 0, (unsigned int *)dest); \
- vec_ste ((vector_u32_t)tmp, 4, (unsigned int *)dest);
-
- COPY (dest, vx0) dest += stride;
- COPY (dest, vx1) dest += stride;
- COPY (dest, vx2) dest += stride;
- COPY (dest, vx3) dest += stride;
- COPY (dest, vx4) dest += stride;
- COPY (dest, vx5) dest += stride;
- COPY (dest, vx6) dest += stride;
- COPY (dest, vx7)
-
-POWERPC_PERF_STOP_COUNT(altivec_idct_put_num, 1);
-}
-
-void idct_add_altivec(uint8_t* dest, int stride, vector_s16_t* block)
-{
-POWERPC_PERF_DECLARE(altivec_idct_add_num, 1);
- vector_u8_t tmp;
- vector_s16_t tmp2, tmp3;
- vector_u8_t perm0;
- vector_u8_t perm1;
- vector_u8_t p0, p1, p;
-
-#ifdef POWERPC_PERFORMANCE_REPORT
-POWERPC_PERF_START_COUNT(altivec_idct_add_num, 1);
-#endif
-
- IDCT
-
- p0 = vec_lvsl (0, dest);
- p1 = vec_lvsl (stride, dest);
- p = vec_splat_u8 (-1);
- perm0 = vec_mergeh (p, p0);
- perm1 = vec_mergeh (p, p1);
-
-#define ADD(dest,src,perm) \
- /* *(uint64_t *)&tmp = *(uint64_t *)dest; */ \
- tmp = vec_ld (0, dest); \
- tmp2 = (vector_s16_t)vec_perm (tmp, (vector_u8_t)zero, perm); \
- tmp3 = vec_adds (tmp2, src); \
- tmp = vec_packsu (tmp3, tmp3); \
- vec_ste ((vector_u32_t)tmp, 0, (unsigned int *)dest); \
- vec_ste ((vector_u32_t)tmp, 4, (unsigned int *)dest);
-
- ADD (dest, vx0, perm0) dest += stride;
- ADD (dest, vx1, perm1) dest += stride;
- ADD (dest, vx2, perm0) dest += stride;
- ADD (dest, vx3, perm1) dest += stride;
- ADD (dest, vx4, perm0) dest += stride;
- ADD (dest, vx5, perm1) dest += stride;
- ADD (dest, vx6, perm0) dest += stride;
- ADD (dest, vx7, perm1)
-
-POWERPC_PERF_STOP_COUNT(altivec_idct_add_num, 1);
-}
-
diff --git a/src/libffmpeg/libavcodec/ppc/libavcodec_ppc_dummy.c b/src/libffmpeg/libavcodec/ppc/libavcodec_ppc_dummy.c
deleted file mode 100644
index 506a55beb..000000000
--- a/src/libffmpeg/libavcodec/ppc/libavcodec_ppc_dummy.c
+++ /dev/null
@@ -1,2 +0,0 @@
-
-char libavcodec_ppc_dummy;
diff --git a/src/libffmpeg/libavcodec/qpeg.c b/src/libffmpeg/libavcodec/qpeg.c
deleted file mode 100644
index 3c597e8df..000000000
--- a/src/libffmpeg/libavcodec/qpeg.c
+++ /dev/null
@@ -1,324 +0,0 @@
-/*
- * QPEG codec
- * Copyright (c) 2004 Konstantin Shishkov
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-/**
- * @file qpeg.c
- * QPEG codec.
- */
-
-#include "avcodec.h"
-#include "mpegvideo.h"
-
-typedef struct QpegContext{
- AVCodecContext *avctx;
- AVFrame pic;
- uint8_t *refdata;
-} QpegContext;
-
-static void qpeg_decode_intra(uint8_t *src, uint8_t *dst, int size,
- int stride, int width, int height)
-{
- int i;
- int code;
- int c0, c1;
- int run, copy;
- int filled = 0;
- int rows_to_go;
-
- rows_to_go = height;
- height--;
- dst = dst + height * stride;
-
- while((size > 0) && (rows_to_go > 0)) {
- code = *src++;
- size--;
- run = copy = 0;
- if(code == 0xFC) /* end-of-picture code */
- break;
- if(code >= 0xF8) { /* very long run */
- c0 = *src++;
- c1 = *src++;
- size -= 2;
- run = ((code & 0x7) << 16) + (c0 << 8) + c1 + 2;
- } else if (code >= 0xF0) { /* long run */
- c0 = *src++;
- size--;
- run = ((code & 0xF) << 8) + c0 + 2;
- } else if (code >= 0xE0) { /* short run */
- run = (code & 0x1F) + 2;
- } else if (code >= 0xC0) { /* very long copy */
- c0 = *src++;
- c1 = *src++;
- size -= 2;
- copy = ((code & 0x3F) << 16) + (c0 << 8) + c1 + 1;
- } else if (code >= 0x80) { /* long copy */
- c0 = *src++;
- size--;
- copy = ((code & 0x7F) << 8) + c0 + 1;
- } else { /* short copy */
- copy = code + 1;
- }
-
- /* perform actual run or copy */
- if(run) {
- int p;
-
- p = *src++;
- size--;
- for(i = 0; i < run; i++) {
- dst[filled++] = p;
- if (filled >= width) {
- filled = 0;
- dst -= stride;
- rows_to_go--;
- if(rows_to_go <= 0)
- break;
- }
- }
- } else {
- size -= copy;
- for(i = 0; i < copy; i++) {
- dst[filled++] = *src++;
- if (filled >= width) {
- filled = 0;
- dst -= stride;
- rows_to_go--;
- if(rows_to_go <= 0)
- break;
- }
- }
- }
- }
-}
-
-static int qpeg_table_h[16] =
- { 0x00, 0x20, 0x20, 0x20, 0x18, 0x10, 0x10, 0x20, 0x10, 0x08, 0x18, 0x08, 0x08, 0x18, 0x10, 0x04};
-static int qpeg_table_w[16] =
- { 0x00, 0x20, 0x18, 0x08, 0x18, 0x10, 0x20, 0x10, 0x08, 0x10, 0x20, 0x20, 0x08, 0x10, 0x18, 0x04};
-
-/* Decodes delta frames */
-static void qpeg_decode_inter(uint8_t *src, uint8_t *dst, int size,
- int stride, int width, int height,
- int delta, uint8_t *ctable, uint8_t *refdata)
-{
- int i, j;
- int code;
- int filled = 0;
- int orig_height;
- uint8_t *blkdata;
-
- /* copy prev frame */
- for(i = 0; i < height; i++)
- memcpy(refdata + (i * width), dst + (i * stride), width);
-
- orig_height = height;
- blkdata = src - 0x86;
- height--;
- dst = dst + height * stride;
-
- while((size > 0) && (height >= 0)) {
- code = *src++;
- size--;
-
- if(delta) {
- /* motion compensation */
- while((code & 0xF0) == 0xF0) {
- if(delta == 1) {
- int me_idx;
- int me_w, me_h, me_x, me_y;
- uint8_t *me_plane;
- int corr, val;
-
- /* get block size by index */
- me_idx = code & 0xF;
- me_w = qpeg_table_w[me_idx];
- me_h = qpeg_table_h[me_idx];
-
- /* extract motion vector */
- corr = *src++;
- size--;
-
- val = corr >> 4;
- if(val > 7)
- val -= 16;
- me_x = val;
-
- val = corr & 0xF;
- if(val > 7)
- val -= 16;
- me_y = val;
-
- /* check motion vector */
- if ((me_x + filled < 0) || (me_x + me_w + filled > width) ||
- (height - me_y - me_h < 0) || (height - me_y > orig_height) ||
- (filled + me_w > width) || (height - me_h < 0))
- av_log(NULL, AV_LOG_ERROR, "Bogus motion vector (%i,%i), block size %ix%i at %i,%i\n",
- me_x, me_y, me_w, me_h, filled, height);
- else {
- /* do motion compensation */
- me_plane = refdata + (filled + me_x) + (height - me_y) * width;
- for(j = 0; j < me_h; j++) {
- for(i = 0; i < me_w; i++)
- dst[filled + i - (j * stride)] = me_plane[i - (j * width)];
- }
- }
- }
- code = *src++;
- size--;
- }
- }
-
- if(code == 0xE0) /* end-of-picture code */
- break;
- if(code > 0xE0) { /* run code: 0xE1..0xFF */
- int p;
-
- code &= 0x1F;
- p = *src++;
- size--;
- for(i = 0; i <= code; i++) {
- dst[filled++] = p;
- if(filled >= width) {
- filled = 0;
- dst -= stride;
- height--;
- }
- }
- } else if(code >= 0xC0) { /* copy code: 0xC0..0xDF */
- code &= 0x1F;
-
- for(i = 0; i <= code; i++) {
- dst[filled++] = *src++;
- if(filled >= width) {
- filled = 0;
- dst -= stride;
- height--;
- }
- }
- size -= code + 1;
- } else if(code >= 0x80) { /* skip code: 0x80..0xBF */
- int skip;
-
- code &= 0x3F;
- /* codes 0x80 and 0x81 are actually escape codes,
- skip value minus constant is in the next byte */
- if(!code)
- skip = (*src++) + 64;
- else if(code == 1)
- skip = (*src++) + 320;
- else
- skip = code;
- filled += skip;
- while( filled >= width) {
- filled -= width;
- dst -= stride;
- height--;
- if(height < 0)
- break;
- }
- } else {
- /* zero code treated as one-pixel skip */
- if(code)
- dst[filled++] = ctable[code & 0x7F];
- else
- filled++;
- if(filled >= width) {
- filled = 0;
- dst -= stride;
- height--;
- }
- }
- }
-}
-
-static int decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- QpegContext * const a = avctx->priv_data;
- AVFrame * const p= (AVFrame*)&a->pic;
- uint8_t* outdata;
- int delta;
-
- 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;
- }
- outdata = a->pic.data[0];
- if(buf[0x85] == 0x10) {
- qpeg_decode_intra(buf+0x86, outdata, buf_size - 0x86, a->pic.linesize[0], avctx->width, avctx->height);
- } else {
- delta = buf[0x85];
- qpeg_decode_inter(buf+0x86, outdata, buf_size - 0x86, a->pic.linesize[0], avctx->width, avctx->height, delta, buf + 4, a->refdata);
- }
-
- /* make the palette available on the way out */
- memcpy(a->pic.data[1], a->avctx->palctrl->palette, AVPALETTE_SIZE);
- if (a->avctx->palctrl->palette_changed) {
- a->pic.palette_has_changed = 1;
- a->avctx->palctrl->palette_changed = 0;
- }
-
- *data_size = sizeof(AVFrame);
- *(AVFrame*)data = a->pic;
-
- return buf_size;
-}
-
-static int decode_init(AVCodecContext *avctx){
- QpegContext * const a = avctx->priv_data;
-
- a->avctx = avctx;
- avctx->pix_fmt= PIX_FMT_PAL8;
- avctx->has_b_frames = 0;
- a->pic.data[0] = NULL;
- a->refdata = av_malloc(avctx->width * avctx->height);
-
- return 0;
-}
-
-static int decode_end(AVCodecContext *avctx){
- QpegContext * const a = avctx->priv_data;
- AVFrame * const p= (AVFrame*)&a->pic;
-
- if(p->data[0])
- avctx->release_buffer(avctx, p);
-
- av_free(a->refdata);
- return 0;
-}
-
-AVCodec qpeg_decoder = {
- "qpeg",
- CODEC_TYPE_VIDEO,
- CODEC_ID_QPEG,
- sizeof(QpegContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
-};
diff --git a/src/libffmpeg/libavcodec/qtrle.c b/src/libffmpeg/libavcodec/qtrle.c
deleted file mode 100644
index 0ccca28c6..000000000
--- a/src/libffmpeg/libavcodec/qtrle.c
+++ /dev/null
@@ -1,630 +0,0 @@
-/*
- * Quicktime Animation (RLE) Video Decoder
- * Copyright (C) 2004 the ffmpeg project
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-/**
- * @file qtrle.c
- * 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/
- *
- * The QT RLE decoder has seven modes of operation:
- * 1, 2, 4, 8, 16, 24, and 32 bits per pixel. For modes 1, 2, 4, and 8
- * the decoder outputs PAL8 colorspace data. 16-bit data yields RGB555
- * data. 24-bit data is RGB24 and 32-bit data is RGBA32.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "common.h"
-#include "avcodec.h"
-#include "dsputil.h"
-
-typedef struct QtrleContext {
-
- AVCodecContext *avctx;
- DSPContext dsp;
- AVFrame frame;
-
- unsigned char *buf;
- int size;
-
-} QtrleContext;
-
-#define CHECK_STREAM_PTR(n) \
- if ((stream_ptr + n) > s->size) { \
- av_log (s->avctx, AV_LOG_INFO, "Problem: stream_ptr out of bounds (%d >= %d)\n", \
- stream_ptr + n, s->size); \
- return; \
- }
-
-#define CHECK_PIXEL_PTR(n) \
- if ((pixel_ptr + n > pixel_limit) || (pixel_ptr + n < 0)) { \
- av_log (s->avctx, AV_LOG_INFO, "Problem: pixel_ptr = %d, pixel_limit = %d\n", \
- pixel_ptr + n, pixel_limit); \
- return; \
- } \
-
-static void qtrle_decode_1bpp(QtrleContext *s)
-{
-}
-
-static void qtrle_decode_2bpp(QtrleContext *s)
-{
-}
-
-static void qtrle_decode_4bpp(QtrleContext *s)
-{
- int stream_ptr;
- int header;
- int start_line;
- int lines_to_change;
- int rle_code;
- int row_ptr, pixel_ptr;
- int row_inc = s->frame.linesize[0];
- unsigned char pi1, pi2, pi3, pi4, pi5, pi6, pi7, pi8; /* 8 palette indices */
- unsigned char *rgb = s->frame.data[0];
- int pixel_limit = s->frame.linesize[0] * s->avctx->height;
-
- /* check if this frame is even supposed to change */
- if (s->size < 8)
- return;
-
- /* start after the chunk size */
- stream_ptr = 4;
-
- /* fetch the header */
- CHECK_STREAM_PTR(2);
- header = AV_RB16(&s->buf[stream_ptr]);
- stream_ptr += 2;
-
- /* if a header is present, fetch additional decoding parameters */
- if (header & 0x0008) {
- CHECK_STREAM_PTR(8);
- start_line = AV_RB16(&s->buf[stream_ptr]);
- stream_ptr += 4;
- lines_to_change = AV_RB16(&s->buf[stream_ptr]);
- stream_ptr += 4;
- } else {
- start_line = 0;
- lines_to_change = s->avctx->height;
- }
-
- row_ptr = row_inc * start_line;
- while (lines_to_change--) {
- CHECK_STREAM_PTR(2);
- pixel_ptr = row_ptr + (8 * (s->buf[stream_ptr++] - 1));
-
- while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) {
- if (rle_code == 0) {
- /* there's another skip code in the stream */
- CHECK_STREAM_PTR(1);
- pixel_ptr += (8 * (s->buf[stream_ptr++] - 1));
- CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */
- } else if (rle_code < 0) {
- /* decode the run length code */
- rle_code = -rle_code;
- /* get the next 4 bytes from the stream, treat them as palette
- * indices, and output them rle_code times */
- CHECK_STREAM_PTR(4);
- pi1 = ((s->buf[stream_ptr]) >> 4) & 0x0f;
- pi2 = (s->buf[stream_ptr++]) & 0x0f;
- pi3 = ((s->buf[stream_ptr]) >> 4) & 0x0f;
- pi4 = (s->buf[stream_ptr++]) & 0x0f;
- pi5 = ((s->buf[stream_ptr]) >> 4) & 0x0f;
- pi6 = (s->buf[stream_ptr++]) & 0x0f;
- pi7 = ((s->buf[stream_ptr]) >> 4) & 0x0f;
- pi8 = (s->buf[stream_ptr++]) & 0x0f;
-
- CHECK_PIXEL_PTR(rle_code * 8);
-
- while (rle_code--) {
- rgb[pixel_ptr++] = pi1;
- rgb[pixel_ptr++] = pi2;
- rgb[pixel_ptr++] = pi3;
- rgb[pixel_ptr++] = pi4;
- rgb[pixel_ptr++] = pi5;
- rgb[pixel_ptr++] = pi6;
- rgb[pixel_ptr++] = pi7;
- rgb[pixel_ptr++] = pi8;
- }
- } else {
- /* copy the same pixel directly to output 4 times */
- rle_code *= 4;
- CHECK_STREAM_PTR(rle_code);
- CHECK_PIXEL_PTR(rle_code*2);
-
- while (rle_code--) {
- rgb[pixel_ptr++] = ((s->buf[stream_ptr]) >> 4) & 0x0f;
- rgb[pixel_ptr++] = (s->buf[stream_ptr++]) & 0x0f;
- }
- }
- }
- row_ptr += row_inc;
- }
-}
-
-static void qtrle_decode_8bpp(QtrleContext *s)
-{
- int stream_ptr;
- int header;
- int start_line;
- int lines_to_change;
- int rle_code;
- int row_ptr, pixel_ptr;
- int row_inc = s->frame.linesize[0];
- unsigned char pi1, pi2, pi3, pi4; /* 4 palette indices */
- unsigned char *rgb = s->frame.data[0];
- int pixel_limit = s->frame.linesize[0] * s->avctx->height;
-
- /* check if this frame is even supposed to change */
- if (s->size < 8)
- return;
-
- /* start after the chunk size */
- stream_ptr = 4;
-
- /* fetch the header */
- CHECK_STREAM_PTR(2);
- header = AV_RB16(&s->buf[stream_ptr]);
- stream_ptr += 2;
-
- /* if a header is present, fetch additional decoding parameters */
- if (header & 0x0008) {
- CHECK_STREAM_PTR(8);
- start_line = AV_RB16(&s->buf[stream_ptr]);
- stream_ptr += 4;
- lines_to_change = AV_RB16(&s->buf[stream_ptr]);
- stream_ptr += 4;
- } else {
- start_line = 0;
- lines_to_change = s->avctx->height;
- }
-
- row_ptr = row_inc * start_line;
- while (lines_to_change--) {
- CHECK_STREAM_PTR(2);
- pixel_ptr = row_ptr + (4 * (s->buf[stream_ptr++] - 1));
-
- while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) {
- if (rle_code == 0) {
- /* there's another skip code in the stream */
- CHECK_STREAM_PTR(1);
- pixel_ptr += (4 * (s->buf[stream_ptr++] - 1));
- CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */
- } else if (rle_code < 0) {
- /* decode the run length code */
- rle_code = -rle_code;
- /* get the next 4 bytes from the stream, treat them as palette
- * indices, and output them rle_code times */
- CHECK_STREAM_PTR(4);
- pi1 = s->buf[stream_ptr++];
- pi2 = s->buf[stream_ptr++];
- pi3 = s->buf[stream_ptr++];
- pi4 = s->buf[stream_ptr++];
-
- CHECK_PIXEL_PTR(rle_code * 4);
-
- while (rle_code--) {
- rgb[pixel_ptr++] = pi1;
- rgb[pixel_ptr++] = pi2;
- rgb[pixel_ptr++] = pi3;
- rgb[pixel_ptr++] = pi4;
- }
- } else {
- /* copy the same pixel directly to output 4 times */
- rle_code *= 4;
- CHECK_STREAM_PTR(rle_code);
- CHECK_PIXEL_PTR(rle_code);
-
- while (rle_code--) {
- rgb[pixel_ptr++] = s->buf[stream_ptr++];
- }
- }
- }
- row_ptr += row_inc;
- }
-}
-
-static void qtrle_decode_16bpp(QtrleContext *s)
-{
- int stream_ptr;
- int header;
- int start_line;
- int lines_to_change;
- int rle_code;
- int row_ptr, pixel_ptr;
- int row_inc = s->frame.linesize[0];
- unsigned short rgb16;
- unsigned char *rgb = s->frame.data[0];
- int pixel_limit = s->frame.linesize[0] * s->avctx->height;
-
- /* check if this frame is even supposed to change */
- if (s->size < 8)
- return;
-
- /* start after the chunk size */
- stream_ptr = 4;
-
- /* fetch the header */
- CHECK_STREAM_PTR(2);
- header = AV_RB16(&s->buf[stream_ptr]);
- stream_ptr += 2;
-
- /* if a header is present, fetch additional decoding parameters */
- if (header & 0x0008) {
- CHECK_STREAM_PTR(8);
- start_line = AV_RB16(&s->buf[stream_ptr]);
- stream_ptr += 4;
- lines_to_change = AV_RB16(&s->buf[stream_ptr]);
- stream_ptr += 4;
- } else {
- start_line = 0;
- lines_to_change = s->avctx->height;
- }
-
- row_ptr = row_inc * start_line;
- while (lines_to_change--) {
- CHECK_STREAM_PTR(2);
- pixel_ptr = row_ptr + (s->buf[stream_ptr++] - 1) * 2;
-
- while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) {
- if (rle_code == 0) {
- /* there's another skip code in the stream */
- CHECK_STREAM_PTR(1);
- pixel_ptr += (s->buf[stream_ptr++] - 1) * 2;
- CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */
- } else if (rle_code < 0) {
- /* decode the run length code */
- rle_code = -rle_code;
- CHECK_STREAM_PTR(2);
- rgb16 = AV_RB16(&s->buf[stream_ptr]);
- stream_ptr += 2;
-
- CHECK_PIXEL_PTR(rle_code * 2);
-
- while (rle_code--) {
- *(unsigned short *)(&rgb[pixel_ptr]) = rgb16;
- pixel_ptr += 2;
- }
- } else {
- CHECK_STREAM_PTR(rle_code * 2);
- CHECK_PIXEL_PTR(rle_code * 2);
-
- /* copy pixels directly to output */
- while (rle_code--) {
- rgb16 = AV_RB16(&s->buf[stream_ptr]);
- stream_ptr += 2;
- *(unsigned short *)(&rgb[pixel_ptr]) = rgb16;
- pixel_ptr += 2;
- }
- }
- }
- row_ptr += row_inc;
- }
-}
-
-static void qtrle_decode_24bpp(QtrleContext *s)
-{
- int stream_ptr;
- int header;
- int start_line;
- int lines_to_change;
- int rle_code;
- int row_ptr, pixel_ptr;
- int row_inc = s->frame.linesize[0];
- unsigned char r, g, b;
- unsigned char *rgb = s->frame.data[0];
- int pixel_limit = s->frame.linesize[0] * s->avctx->height;
-
- /* check if this frame is even supposed to change */
- if (s->size < 8)
- return;
-
- /* start after the chunk size */
- stream_ptr = 4;
-
- /* fetch the header */
- CHECK_STREAM_PTR(2);
- header = AV_RB16(&s->buf[stream_ptr]);
- stream_ptr += 2;
-
- /* if a header is present, fetch additional decoding parameters */
- if (header & 0x0008) {
- CHECK_STREAM_PTR(8);
- start_line = AV_RB16(&s->buf[stream_ptr]);
- stream_ptr += 4;
- lines_to_change = AV_RB16(&s->buf[stream_ptr]);
- stream_ptr += 4;
- } else {
- start_line = 0;
- lines_to_change = s->avctx->height;
- }
-
- row_ptr = row_inc * start_line;
- while (lines_to_change--) {
- CHECK_STREAM_PTR(2);
- pixel_ptr = row_ptr + (s->buf[stream_ptr++] - 1) * 3;
-
- while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) {
- if (rle_code == 0) {
- /* there's another skip code in the stream */
- CHECK_STREAM_PTR(1);
- pixel_ptr += (s->buf[stream_ptr++] - 1) * 3;
- CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */
- } else if (rle_code < 0) {
- /* decode the run length code */
- rle_code = -rle_code;
- CHECK_STREAM_PTR(3);
- r = s->buf[stream_ptr++];
- g = s->buf[stream_ptr++];
- b = s->buf[stream_ptr++];
-
- CHECK_PIXEL_PTR(rle_code * 3);
-
- while (rle_code--) {
- rgb[pixel_ptr++] = r;
- rgb[pixel_ptr++] = g;
- rgb[pixel_ptr++] = b;
- }
- } else {
- CHECK_STREAM_PTR(rle_code * 3);
- CHECK_PIXEL_PTR(rle_code * 3);
-
- /* copy pixels directly to output */
- while (rle_code--) {
- rgb[pixel_ptr++] = s->buf[stream_ptr++];
- rgb[pixel_ptr++] = s->buf[stream_ptr++];
- rgb[pixel_ptr++] = s->buf[stream_ptr++];
- }
- }
- }
- row_ptr += row_inc;
- }
-}
-
-static void qtrle_decode_32bpp(QtrleContext *s)
-{
- int stream_ptr;
- int header;
- int start_line;
- int lines_to_change;
- int rle_code;
- int row_ptr, pixel_ptr;
- int row_inc = s->frame.linesize[0];
- unsigned char a, r, g, b;
- unsigned int argb;
- unsigned char *rgb = s->frame.data[0];
- int pixel_limit = s->frame.linesize[0] * s->avctx->height;
-
- /* check if this frame is even supposed to change */
- if (s->size < 8)
- return;
-
- /* start after the chunk size */
- stream_ptr = 4;
-
- /* fetch the header */
- CHECK_STREAM_PTR(2);
- header = AV_RB16(&s->buf[stream_ptr]);
- stream_ptr += 2;
-
- /* if a header is present, fetch additional decoding parameters */
- if (header & 0x0008) {
- CHECK_STREAM_PTR(8);
- start_line = AV_RB16(&s->buf[stream_ptr]);
- stream_ptr += 4;
- lines_to_change = AV_RB16(&s->buf[stream_ptr]);
- stream_ptr += 4;
- } else {
- start_line = 0;
- lines_to_change = s->avctx->height;
- }
-
- row_ptr = row_inc * start_line;
- while (lines_to_change--) {
- CHECK_STREAM_PTR(2);
- pixel_ptr = row_ptr + (s->buf[stream_ptr++] - 1) * 4;
-
- while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) {
- if (rle_code == 0) {
- /* there's another skip code in the stream */
- CHECK_STREAM_PTR(1);
- pixel_ptr += (s->buf[stream_ptr++] - 1) * 4;
- CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */
- } else if (rle_code < 0) {
- /* decode the run length code */
- rle_code = -rle_code;
- CHECK_STREAM_PTR(4);
- a = s->buf[stream_ptr++];
- r = s->buf[stream_ptr++];
- g = s->buf[stream_ptr++];
- b = s->buf[stream_ptr++];
- argb = (a << 24) | (r << 16) | (g << 8) | (b << 0);
-
- CHECK_PIXEL_PTR(rle_code * 4);
-
- while (rle_code--) {
- *(unsigned int *)(&rgb[pixel_ptr]) = argb;
- pixel_ptr += 4;
- }
- } else {
- CHECK_STREAM_PTR(rle_code * 4);
- CHECK_PIXEL_PTR(rle_code * 4);
-
- /* copy pixels directly to output */
- while (rle_code--) {
- a = s->buf[stream_ptr++];
- r = s->buf[stream_ptr++];
- g = s->buf[stream_ptr++];
- b = s->buf[stream_ptr++];
- argb = (a << 24) | (r << 16) | (g << 8) | (b << 0);
- *(unsigned int *)(&rgb[pixel_ptr]) = argb;
- pixel_ptr += 4;
- }
- }
- }
- row_ptr += row_inc;
- }
-}
-
-static int qtrle_decode_init(AVCodecContext *avctx)
-{
- QtrleContext *s = (QtrleContext *)avctx->priv_data;
-
- s->avctx = avctx;
- switch (avctx->bits_per_sample) {
- case 1:
- case 2:
- case 4:
- case 8:
- case 33:
- case 34:
- case 36:
- case 40:
- avctx->pix_fmt = PIX_FMT_PAL8;
- break;
-
- case 16:
- avctx->pix_fmt = PIX_FMT_RGB555;
- break;
-
- case 24:
- avctx->pix_fmt = PIX_FMT_RGB24;
- break;
-
- case 32:
- avctx->pix_fmt = PIX_FMT_RGBA32;
- break;
-
- default:
- av_log (avctx, AV_LOG_ERROR, "Unsupported colorspace: %d bits/sample?\n",
- avctx->bits_per_sample);
- break;
- }
- avctx->has_b_frames = 0;
- dsputil_init(&s->dsp, avctx);
-
- s->frame.data[0] = NULL;
-
- return 0;
-}
-
-static int qtrle_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- QtrleContext *s = (QtrleContext *)avctx->priv_data;
-
- s->buf = buf;
- s->size = buf_size;
-
- s->frame.reference = 1;
- s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE |
- FF_BUFFER_HINTS_REUSABLE | FF_BUFFER_HINTS_READABLE;
- if (avctx->reget_buffer(avctx, &s->frame)) {
- av_log (s->avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
- return -1;
- }
-
- switch (avctx->bits_per_sample) {
- case 1:
- case 33:
- qtrle_decode_1bpp(s);
- break;
-
- case 2:
- case 34:
- qtrle_decode_2bpp(s);
- break;
-
- case 4:
- case 36:
- qtrle_decode_4bpp(s);
- /* make the palette available on the way out */
- memcpy(s->frame.data[1], s->avctx->palctrl->palette, AVPALETTE_SIZE);
- if (s->avctx->palctrl->palette_changed) {
- s->frame.palette_has_changed = 1;
- s->avctx->palctrl->palette_changed = 0;
- }
- break;
-
- case 8:
- case 40:
- qtrle_decode_8bpp(s);
- /* make the palette available on the way out */
- memcpy(s->frame.data[1], s->avctx->palctrl->palette, AVPALETTE_SIZE);
- if (s->avctx->palctrl->palette_changed) {
- s->frame.palette_has_changed = 1;
- s->avctx->palctrl->palette_changed = 0;
- }
- break;
-
- case 16:
- qtrle_decode_16bpp(s);
- break;
-
- case 24:
- qtrle_decode_24bpp(s);
- break;
-
- case 32:
- qtrle_decode_32bpp(s);
- break;
-
- default:
- av_log (s->avctx, AV_LOG_ERROR, "Unsupported colorspace: %d bits/sample?\n",
- avctx->bits_per_sample);
- break;
- }
-
- *data_size = sizeof(AVFrame);
- *(AVFrame*)data = s->frame;
-
- /* always report that the buffer was completely consumed */
- return buf_size;
-}
-
-static int qtrle_decode_end(AVCodecContext *avctx)
-{
- QtrleContext *s = (QtrleContext *)avctx->priv_data;
-
- if (s->frame.data[0])
- avctx->release_buffer(avctx, &s->frame);
-
- return 0;
-}
-
-AVCodec qtrle_decoder = {
- "qtrle",
- CODEC_TYPE_VIDEO,
- CODEC_ID_QTRLE,
- sizeof(QtrleContext),
- qtrle_decode_init,
- NULL,
- qtrle_decode_end,
- qtrle_decode_frame,
- CODEC_CAP_DR1,
-};
-
diff --git a/src/libffmpeg/libavcodec/ratecontrol.c b/src/libffmpeg/libavcodec/ratecontrol.c
deleted file mode 100644
index d96c837e6..000000000
--- a/src/libffmpeg/libavcodec/ratecontrol.c
+++ /dev/null
@@ -1,944 +0,0 @@
-/*
- * Rate control for video encoders
- *
- * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/**
- * @file ratecontrol.c
- * Rate control for video encoders.
- */
-
-#include "avcodec.h"
-#include "dsputil.h"
-#include "ratecontrol.h"
-#include "mpegvideo.h"
-#include "eval.h"
-
-#undef NDEBUG // allways check asserts, the speed effect is far too small to disable them
-#include <assert.h>
-
-#ifndef M_E
-#define M_E 2.718281828
-#endif
-
-static int init_pass2(MpegEncContext *s);
-static double get_qscale(MpegEncContext *s, RateControlEntry *rce, double rate_factor, int frame_num);
-
-void ff_write_pass1_stats(MpegEncContext *s){
- snprintf(s->avctx->stats_out, 256, "in:%d out:%d type:%d q:%d itex:%d ptex:%d mv:%d misc:%d fcode:%d bcode:%d mc-var:%d var:%d icount:%d skipcount:%d hbits:%d;\n",
- s->current_picture_ptr->display_picture_number, s->current_picture_ptr->coded_picture_number, s->pict_type,
- s->current_picture.quality, s->i_tex_bits, s->p_tex_bits, s->mv_bits, s->misc_bits,
- s->f_code, s->b_code, s->current_picture.mc_mb_var_sum, s->current_picture.mb_var_sum, s->i_count, s->skip_count, s->header_bits);
-}
-
-static inline double qp2bits(RateControlEntry *rce, double qp){
- if(qp<=0.0){
- av_log(NULL, AV_LOG_ERROR, "qp<=0.0\n");
- }
- return rce->qscale * (double)(rce->i_tex_bits + rce->p_tex_bits+1)/ qp;
-}
-
-static inline double bits2qp(RateControlEntry *rce, double bits){
- if(bits<0.9){
- av_log(NULL, AV_LOG_ERROR, "bits<0.9\n");
- }
- return rce->qscale * (double)(rce->i_tex_bits + rce->p_tex_bits+1)/ bits;
-}
-
-int ff_rate_control_init(MpegEncContext *s)
-{
- RateControlContext *rcc= &s->rc_context;
- int i;
- char *error = NULL;
- static const char *const_names[]={
- "PI",
- "E",
- "iTex",
- "pTex",
- "tex",
- "mv",
- "fCode",
- "iCount",
- "mcVar",
- "var",
- "isI",
- "isP",
- "isB",
- "avgQP",
- "qComp",
-/* "lastIQP",
- "lastPQP",
- "lastBQP",
- "nextNonBQP",*/
- "avgIITex",
- "avgPITex",
- "avgPPTex",
- "avgBPTex",
- "avgTex",
- NULL
- };
- static double (*func1[])(void *, double)={
- (void *)bits2qp,
- (void *)qp2bits,
- NULL
- };
- static const char *func1_names[]={
- "bits2qp",
- "qp2bits",
- NULL
- };
- emms_c();
-
- rcc->rc_eq_eval = ff_parse(s->avctx->rc_eq, 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;
- }
-
- for(i=0; i<5; i++){
- rcc->pred[i].coeff= FF_QP2LAMBDA * 7.0;
- rcc->pred[i].count= 1.0;
-
- rcc->pred[i].decay= 0.4;
- rcc->i_cplx_sum [i]=
- rcc->p_cplx_sum [i]=
- rcc->mv_bits_sum[i]=
- rcc->qscale_sum [i]=
- rcc->frame_count[i]= 1; // 1 is better cuz of 1/0 and such
- rcc->last_qscale_for[i]=FF_QP2LAMBDA * 5;
- }
- rcc->buffer_index= s->avctx->rc_initial_buffer_occupancy;
-
- if(s->flags&CODEC_FLAG_PASS2){
- int i;
- char *p;
-
- /* find number of pics */
- p= s->avctx->stats_in;
- for(i=-1; p; i++){
- p= strchr(p+1, ';');
- }
- i+= s->max_b_frames;
- if(i<=0 || i>=INT_MAX / sizeof(RateControlEntry))
- return -1;
- rcc->entry = (RateControlEntry*)av_mallocz(i*sizeof(RateControlEntry));
- rcc->num_entries= i;
-
- /* init all to skipped p frames (with b frames we might have a not encoded frame at the end FIXME) */
- for(i=0; i<rcc->num_entries; i++){
- RateControlEntry *rce= &rcc->entry[i];
- rce->pict_type= rce->new_pict_type=P_TYPE;
- rce->qscale= rce->new_qscale=FF_QP2LAMBDA * 2;
- rce->misc_bits= s->mb_num + 10;
- rce->mb_var_sum= s->mb_num*100;
- }
-
- /* read stats */
- p= s->avctx->stats_in;
- for(i=0; i<rcc->num_entries - s->max_b_frames; i++){
- RateControlEntry *rce;
- int picture_number;
- int e;
- char *next;
-
- next= strchr(p, ';');
- if(next){
- (*next)=0; //sscanf in unbelieavle slow on looong strings //FIXME copy / dont write
- next++;
- }
- e= sscanf(p, " in:%d ", &picture_number);
-
- assert(picture_number >= 0);
- assert(picture_number < rcc->num_entries);
- rce= &rcc->entry[picture_number];
-
- e+=sscanf(p, " in:%*d out:%*d type:%d q:%f itex:%d ptex:%d mv:%d misc:%d fcode:%d bcode:%d mc-var:%d var:%d icount:%d skipcount:%d hbits:%d",
- &rce->pict_type, &rce->qscale, &rce->i_tex_bits, &rce->p_tex_bits, &rce->mv_bits, &rce->misc_bits,
- &rce->f_code, &rce->b_code, &rce->mc_mb_var_sum, &rce->mb_var_sum, &rce->i_count, &rce->skip_count, &rce->header_bits);
- if(e!=14){
- av_log(s->avctx, AV_LOG_ERROR, "statistics are damaged at line %d, parser out=%d\n", i, e);
- return -1;
- }
-
- p= next;
- }
-
- if(init_pass2(s) < 0) return -1;
-
- //FIXME maybe move to end
- if((s->flags&CODEC_FLAG_PASS2) && s->avctx->rc_strategy == FF_RC_STRATEGY_XVID) {
-#ifdef CONFIG_XVID
- return ff_xvid_rate_control_init(s);
-#else
- av_log(s->avctx, AV_LOG_ERROR, "XviD ratecontrol requires libavcodec compiled with XviD support\n");
- return -1;
-#endif
- }
- }
-
- if(!(s->flags&CODEC_FLAG_PASS2)){
-
- rcc->short_term_qsum=0.001;
- rcc->short_term_qcount=0.001;
-
- rcc->pass1_rc_eq_output_sum= 0.001;
- rcc->pass1_wanted_bits=0.001;
-
- /* init stuff with the user specified complexity */
- if(s->avctx->rc_initial_cplx){
- for(i=0; i<60*30; i++){
- double bits= s->avctx->rc_initial_cplx * (i/10000.0 + 1.0)*s->mb_num;
- RateControlEntry rce;
- double q;
-
- if (i%((s->gop_size+3)/4)==0) rce.pict_type= I_TYPE;
- else if(i%(s->max_b_frames+1)) rce.pict_type= B_TYPE;
- else rce.pict_type= P_TYPE;
-
- rce.new_pict_type= rce.pict_type;
- rce.mc_mb_var_sum= bits*s->mb_num/100000;
- rce.mb_var_sum = s->mb_num;
- rce.qscale = FF_QP2LAMBDA * 2;
- rce.f_code = 2;
- rce.b_code = 1;
- rce.misc_bits= 1;
-
- if(s->pict_type== I_TYPE){
- rce.i_count = s->mb_num;
- rce.i_tex_bits= bits;
- rce.p_tex_bits= 0;
- rce.mv_bits= 0;
- }else{
- rce.i_count = 0; //FIXME we do know this approx
- rce.i_tex_bits= 0;
- rce.p_tex_bits= bits*0.9;
- rce.mv_bits= bits*0.1;
- }
- rcc->i_cplx_sum [rce.pict_type] += rce.i_tex_bits*rce.qscale;
- rcc->p_cplx_sum [rce.pict_type] += rce.p_tex_bits*rce.qscale;
- rcc->mv_bits_sum[rce.pict_type] += rce.mv_bits;
- rcc->frame_count[rce.pict_type] ++;
-
- bits= rce.i_tex_bits + rce.p_tex_bits;
-
- q= get_qscale(s, &rce, rcc->pass1_wanted_bits/rcc->pass1_rc_eq_output_sum, i);
- rcc->pass1_wanted_bits+= s->bit_rate/(1/av_q2d(s->avctx->time_base)); //FIXME missbehaves a little for variable fps
- }
- }
-
- }
-
- return 0;
-}
-
-void ff_rate_control_uninit(MpegEncContext *s)
-{
- RateControlContext *rcc= &s->rc_context;
- emms_c();
-
- ff_eval_free(rcc->rc_eq_eval);
- av_freep(&rcc->entry);
-
-#ifdef CONFIG_XVID
- if((s->flags&CODEC_FLAG_PASS2) && s->avctx->rc_strategy == FF_RC_STRATEGY_XVID)
- ff_xvid_rate_control_uninit(s);
-#endif
-}
-
-int ff_vbv_update(MpegEncContext *s, int frame_size){
- RateControlContext *rcc= &s->rc_context;
- const double fps= 1/av_q2d(s->avctx->time_base);
- const int buffer_size= s->avctx->rc_buffer_size;
- const double min_rate= s->avctx->rc_min_rate/fps;
- const double max_rate= s->avctx->rc_max_rate/fps;
-
-//printf("%d %f %d %f %f\n", buffer_size, rcc->buffer_index, frame_size, min_rate, max_rate);
- if(buffer_size){
- int left;
-
- rcc->buffer_index-= frame_size;
- if(rcc->buffer_index < 0){
- av_log(s->avctx, AV_LOG_ERROR, "rc buffer underflow\n");
- rcc->buffer_index= 0;
- }
-
- left= buffer_size - rcc->buffer_index - 1;
- rcc->buffer_index += clip(left, min_rate, max_rate);
-
- if(rcc->buffer_index > buffer_size){
- int stuffing= ceil((rcc->buffer_index - buffer_size)/8);
-
- if(stuffing < 4 && s->codec_id == CODEC_ID_MPEG4)
- stuffing=4;
- rcc->buffer_index -= 8*stuffing;
-
- if(s->avctx->debug & FF_DEBUG_RC)
- av_log(s->avctx, AV_LOG_DEBUG, "stuffing %d bytes\n", stuffing);
-
- return stuffing;
- }
- }
- return 0;
-}
-
-/**
- * modifies the bitrate curve from pass1 for one frame
- */
-static double get_qscale(MpegEncContext *s, RateControlEntry *rce, double rate_factor, int frame_num){
- RateControlContext *rcc= &s->rc_context;
- AVCodecContext *a= s->avctx;
- double q, bits;
- const int pict_type= rce->new_pict_type;
- const double mb_num= s->mb_num;
- int i;
-
- double const_values[]={
- M_PI,
- M_E,
- rce->i_tex_bits*rce->qscale,
- rce->p_tex_bits*rce->qscale,
- (rce->i_tex_bits + rce->p_tex_bits)*(double)rce->qscale,
- rce->mv_bits/mb_num,
- rce->pict_type == B_TYPE ? (rce->f_code + rce->b_code)*0.5 : rce->f_code,
- rce->i_count/mb_num,
- rce->mc_mb_var_sum/mb_num,
- rce->mb_var_sum/mb_num,
- rce->pict_type == I_TYPE,
- rce->pict_type == P_TYPE,
- rce->pict_type == B_TYPE,
- rcc->qscale_sum[pict_type] / (double)rcc->frame_count[pict_type],
- a->qcompress,
-/* rcc->last_qscale_for[I_TYPE],
- rcc->last_qscale_for[P_TYPE],
- rcc->last_qscale_for[B_TYPE],
- rcc->next_non_b_qscale,*/
- rcc->i_cplx_sum[I_TYPE] / (double)rcc->frame_count[I_TYPE],
- rcc->i_cplx_sum[P_TYPE] / (double)rcc->frame_count[P_TYPE],
- rcc->p_cplx_sum[P_TYPE] / (double)rcc->frame_count[P_TYPE],
- rcc->p_cplx_sum[B_TYPE] / (double)rcc->frame_count[B_TYPE],
- (rcc->i_cplx_sum[pict_type] + rcc->p_cplx_sum[pict_type]) / (double)rcc->frame_count[pict_type],
- 0
- };
-
- bits= ff_parse_eval(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;
- }
-
- rcc->pass1_rc_eq_output_sum+= bits;
- bits*=rate_factor;
- if(bits<0.0) bits=0.0;
- bits+= 1.0; //avoid 1/0 issues
-
- /* user override */
- for(i=0; i<s->avctx->rc_override_count; i++){
- RcOverride *rco= s->avctx->rc_override;
- if(rco[i].start_frame > frame_num) continue;
- if(rco[i].end_frame < frame_num) continue;
-
- if(rco[i].qscale)
- bits= qp2bits(rce, rco[i].qscale); //FIXME move at end to really force it?
- else
- bits*= rco[i].quality_factor;
- }
-
- q= bits2qp(rce, bits);
-
- /* I/B difference */
- if (pict_type==I_TYPE && s->avctx->i_quant_factor<0.0)
- q= -q*s->avctx->i_quant_factor + s->avctx->i_quant_offset;
- else if(pict_type==B_TYPE && s->avctx->b_quant_factor<0.0)
- q= -q*s->avctx->b_quant_factor + s->avctx->b_quant_offset;
-
- return q;
-}
-
-static double get_diff_limited_q(MpegEncContext *s, RateControlEntry *rce, double q){
- RateControlContext *rcc= &s->rc_context;
- AVCodecContext *a= s->avctx;
- const int pict_type= rce->new_pict_type;
- const double last_p_q = rcc->last_qscale_for[P_TYPE];
- const double last_non_b_q= rcc->last_qscale_for[rcc->last_non_b_pict_type];
-
- if (pict_type==I_TYPE && (a->i_quant_factor>0.0 || rcc->last_non_b_pict_type==P_TYPE))
- q= last_p_q *FFABS(a->i_quant_factor) + a->i_quant_offset;
- else if(pict_type==B_TYPE && a->b_quant_factor>0.0)
- q= last_non_b_q* a->b_quant_factor + a->b_quant_offset;
-
- /* last qscale / qdiff stuff */
- if(rcc->last_non_b_pict_type==pict_type || pict_type!=I_TYPE){
- double last_q= rcc->last_qscale_for[pict_type];
- const int maxdiff= FF_QP2LAMBDA * a->max_qdiff;
-
- if (q > last_q + maxdiff) q= last_q + maxdiff;
- else if(q < last_q - maxdiff) q= last_q - maxdiff;
- }
-
- rcc->last_qscale_for[pict_type]= q; //Note we cant do that after blurring
-
- if(pict_type!=B_TYPE)
- rcc->last_non_b_pict_type= pict_type;
-
- return q;
-}
-
-/**
- * gets the qmin & qmax for pict_type
- */
-static void get_qminmax(int *qmin_ret, int *qmax_ret, MpegEncContext *s, int pict_type){
- int qmin= s->avctx->lmin;
- int qmax= s->avctx->lmax;
-
- assert(qmin <= qmax);
-
- if(pict_type==B_TYPE){
- qmin= (int)(qmin*FFABS(s->avctx->b_quant_factor)+s->avctx->b_quant_offset + 0.5);
- qmax= (int)(qmax*FFABS(s->avctx->b_quant_factor)+s->avctx->b_quant_offset + 0.5);
- }else if(pict_type==I_TYPE){
- qmin= (int)(qmin*FFABS(s->avctx->i_quant_factor)+s->avctx->i_quant_offset + 0.5);
- qmax= (int)(qmax*FFABS(s->avctx->i_quant_factor)+s->avctx->i_quant_offset + 0.5);
- }
-
- qmin= clip(qmin, 1, FF_LAMBDA_MAX);
- qmax= clip(qmax, 1, FF_LAMBDA_MAX);
-
- if(qmax<qmin) qmax= qmin;
-
- *qmin_ret= qmin;
- *qmax_ret= qmax;
-}
-
-static double modify_qscale(MpegEncContext *s, RateControlEntry *rce, double q, int frame_num){
- RateControlContext *rcc= &s->rc_context;
- int qmin, qmax;
- double bits;
- const int pict_type= rce->new_pict_type;
- const double buffer_size= s->avctx->rc_buffer_size;
- const double fps= 1/av_q2d(s->avctx->time_base);
- const double min_rate= s->avctx->rc_min_rate / fps;
- const double max_rate= s->avctx->rc_max_rate / fps;
-
- get_qminmax(&qmin, &qmax, s, pict_type);
-
- /* modulation */
- if(s->avctx->rc_qmod_freq && frame_num%s->avctx->rc_qmod_freq==0 && pict_type==P_TYPE)
- q*= s->avctx->rc_qmod_amp;
-
- bits= qp2bits(rce, q);
-//printf("q:%f\n", q);
- /* buffer overflow/underflow protection */
- if(buffer_size){
- double expected_size= rcc->buffer_index;
- double q_limit;
-
- if(min_rate){
- double d= 2*(buffer_size - expected_size)/buffer_size;
- if(d>1.0) d=1.0;
- else if(d<0.0001) d=0.0001;
- q*= pow(d, 1.0/s->avctx->rc_buffer_aggressivity);
-
- q_limit= bits2qp(rce, FFMAX((min_rate - buffer_size + rcc->buffer_index)*3, 1));
- if(q > q_limit){
- if(s->avctx->debug&FF_DEBUG_RC){
- av_log(s->avctx, AV_LOG_DEBUG, "limiting QP %f -> %f\n", q, q_limit);
- }
- q= q_limit;
- }
- }
-
- if(max_rate){
- double d= 2*expected_size/buffer_size;
- if(d>1.0) d=1.0;
- else if(d<0.0001) d=0.0001;
- q/= pow(d, 1.0/s->avctx->rc_buffer_aggressivity);
-
- q_limit= bits2qp(rce, FFMAX(rcc->buffer_index/3, 1));
- if(q < q_limit){
- if(s->avctx->debug&FF_DEBUG_RC){
- av_log(s->avctx, AV_LOG_DEBUG, "limiting QP %f -> %f\n", q, q_limit);
- }
- q= q_limit;
- }
- }
- }
-//printf("q:%f max:%f min:%f size:%f index:%d bits:%f agr:%f\n", q,max_rate, min_rate, buffer_size, rcc->buffer_index, bits, s->avctx->rc_buffer_aggressivity);
- if(s->avctx->rc_qsquish==0.0 || qmin==qmax){
- if (q<qmin) q=qmin;
- else if(q>qmax) q=qmax;
- }else{
- double min2= log(qmin);
- double max2= log(qmax);
-
- q= log(q);
- q= (q - min2)/(max2-min2) - 0.5;
- q*= -4.0;
- q= 1.0/(1.0 + exp(q));
- q= q*(max2-min2) + min2;
-
- q= exp(q);
- }
-
- return q;
-}
-
-//----------------------------------
-// 1 Pass Code
-
-static double predict_size(Predictor *p, double q, double var)
-{
- return p->coeff*var / (q*p->count);
-}
-
-/*
-static double predict_qp(Predictor *p, double size, double var)
-{
-//printf("coeff:%f, count:%f, var:%f, size:%f//\n", p->coeff, p->count, var, size);
- return p->coeff*var / (size*p->count);
-}
-*/
-
-static void update_predictor(Predictor *p, double q, double var, double size)
-{
- double new_coeff= size*q / (var + 1);
- if(var<10) return;
-
- p->count*= p->decay;
- p->coeff*= p->decay;
- p->count++;
- p->coeff+= new_coeff;
-}
-
-static void adaptive_quantization(MpegEncContext *s, double q){
- int i;
- const float lumi_masking= s->avctx->lumi_masking / (128.0*128.0);
- const float dark_masking= s->avctx->dark_masking / (128.0*128.0);
- const float temp_cplx_masking= s->avctx->temporal_cplx_masking;
- const float spatial_cplx_masking = s->avctx->spatial_cplx_masking;
- const float p_masking = s->avctx->p_masking;
- const float border_masking = s->avctx->border_masking;
- float bits_sum= 0.0;
- float cplx_sum= 0.0;
- float cplx_tab[s->mb_num];
- float bits_tab[s->mb_num];
- const int qmin= s->avctx->mb_lmin;
- const int qmax= s->avctx->mb_lmax;
- Picture * const pic= &s->current_picture;
- const int mb_width = s->mb_width;
- const int mb_height = s->mb_height;
-
- for(i=0; i<s->mb_num; i++){
- const int mb_xy= s->mb_index2xy[i];
- float temp_cplx= sqrt(pic->mc_mb_var[mb_xy]); //FIXME merge in pow()
- float spat_cplx= sqrt(pic->mb_var[mb_xy]);
- const int lumi= pic->mb_mean[mb_xy];
- float bits, cplx, factor;
- int mb_x = mb_xy % s->mb_stride;
- int mb_y = mb_xy / s->mb_stride;
- int mb_distance;
- float mb_factor = 0.0;
-#if 0
- if(spat_cplx < q/3) spat_cplx= q/3; //FIXME finetune
- if(temp_cplx < q/3) temp_cplx= q/3; //FIXME finetune
-#endif
- if(spat_cplx < 4) spat_cplx= 4; //FIXME finetune
- if(temp_cplx < 4) temp_cplx= 4; //FIXME finetune
-
- if((s->mb_type[mb_xy]&CANDIDATE_MB_TYPE_INTRA)){//FIXME hq mode
- cplx= spat_cplx;
- factor= 1.0 + p_masking;
- }else{
- cplx= temp_cplx;
- factor= pow(temp_cplx, - temp_cplx_masking);
- }
- factor*=pow(spat_cplx, - spatial_cplx_masking);
-
- if(lumi>127)
- factor*= (1.0 - (lumi-128)*(lumi-128)*lumi_masking);
- else
- factor*= (1.0 - (lumi-128)*(lumi-128)*dark_masking);
-
- if(mb_x < mb_width/5){
- mb_distance = mb_width/5 - mb_x;
- mb_factor = (float)mb_distance / (float)(mb_width/5);
- }else if(mb_x > 4*mb_width/5){
- mb_distance = mb_x - 4*mb_width/5;
- mb_factor = (float)mb_distance / (float)(mb_width/5);
- }
- if(mb_y < mb_height/5){
- mb_distance = mb_height/5 - mb_y;
- mb_factor = FFMAX(mb_factor, (float)mb_distance / (float)(mb_height/5));
- }else if(mb_y > 4*mb_height/5){
- mb_distance = mb_y - 4*mb_height/5;
- mb_factor = FFMAX(mb_factor, (float)mb_distance / (float)(mb_height/5));
- }
-
- factor*= 1.0 - border_masking*mb_factor;
-
- if(factor<0.00001) factor= 0.00001;
-
- bits= cplx*factor;
- cplx_sum+= cplx;
- bits_sum+= bits;
- cplx_tab[i]= cplx;
- bits_tab[i]= bits;
- }
-
- /* handle qmin/qmax cliping */
- if(s->flags&CODEC_FLAG_NORMALIZE_AQP){
- float factor= bits_sum/cplx_sum;
- for(i=0; i<s->mb_num; i++){
- float newq= q*cplx_tab[i]/bits_tab[i];
- newq*= factor;
-
- if (newq > qmax){
- bits_sum -= bits_tab[i];
- cplx_sum -= cplx_tab[i]*q/qmax;
- }
- else if(newq < qmin){
- bits_sum -= bits_tab[i];
- cplx_sum -= cplx_tab[i]*q/qmin;
- }
- }
- if(bits_sum < 0.001) bits_sum= 0.001;
- if(cplx_sum < 0.001) cplx_sum= 0.001;
- }
-
- for(i=0; i<s->mb_num; i++){
- const int mb_xy= s->mb_index2xy[i];
- float newq= q*cplx_tab[i]/bits_tab[i];
- int intq;
-
- if(s->flags&CODEC_FLAG_NORMALIZE_AQP){
- newq*= bits_sum/cplx_sum;
- }
-
- intq= (int)(newq + 0.5);
-
- if (intq > qmax) intq= qmax;
- else if(intq < qmin) intq= qmin;
-//if(i%s->mb_width==0) printf("\n");
-//printf("%2d%3d ", intq, ff_sqrt(s->mc_mb_var[i]));
- s->lambda_table[mb_xy]= intq;
- }
-}
-
-void ff_get_2pass_fcode(MpegEncContext *s){
- RateControlContext *rcc= &s->rc_context;
- int picture_number= s->picture_number;
- RateControlEntry *rce;
-
- rce= &rcc->entry[picture_number];
- s->f_code= rce->f_code;
- s->b_code= rce->b_code;
-}
-
-//FIXME rd or at least approx for dquant
-
-float ff_rate_estimate_qscale(MpegEncContext *s, int dry_run)
-{
- float q;
- int qmin, qmax;
- float br_compensation;
- double diff;
- double short_term_q;
- double fps;
- int picture_number= s->picture_number;
- int64_t wanted_bits;
- RateControlContext *rcc= &s->rc_context;
- AVCodecContext *a= s->avctx;
- RateControlEntry local_rce, *rce;
- double bits;
- double rate_factor;
- int var;
- const int pict_type= s->pict_type;
- Picture * const pic= &s->current_picture;
- emms_c();
-
-#ifdef CONFIG_XVID
- if((s->flags&CODEC_FLAG_PASS2) && s->avctx->rc_strategy == FF_RC_STRATEGY_XVID)
- return ff_xvid_rate_estimate_qscale(s, dry_run);
-#endif
-
- get_qminmax(&qmin, &qmax, s, pict_type);
-
- fps= 1/av_q2d(s->avctx->time_base);
-//printf("input_pic_num:%d pic_num:%d frame_rate:%d\n", s->input_picture_number, s->picture_number, s->frame_rate);
- /* update predictors */
- if(picture_number>2 && !dry_run){
- const int last_var= s->last_pict_type == I_TYPE ? rcc->last_mb_var_sum : rcc->last_mc_mb_var_sum;
- update_predictor(&rcc->pred[s->last_pict_type], rcc->last_qscale, sqrt(last_var), s->frame_bits);
- }
-
- if(s->flags&CODEC_FLAG_PASS2){
- assert(picture_number>=0);
- assert(picture_number<rcc->num_entries);
- rce= &rcc->entry[picture_number];
- wanted_bits= rce->expected_bits;
- }else{
- rce= &local_rce;
- wanted_bits= (uint64_t)(s->bit_rate*(double)picture_number/fps);
- }
-
- diff= s->total_bits - wanted_bits;
- br_compensation= (a->bit_rate_tolerance - diff)/a->bit_rate_tolerance;
- if(br_compensation<=0.0) br_compensation=0.001;
-
- var= pict_type == I_TYPE ? pic->mb_var_sum : pic->mc_mb_var_sum;
-
- short_term_q = 0; /* avoid warning */
- if(s->flags&CODEC_FLAG_PASS2){
- if(pict_type!=I_TYPE)
- assert(pict_type == rce->new_pict_type);
-
- q= rce->new_qscale / br_compensation;
-//printf("%f %f %f last:%d var:%d type:%d//\n", q, rce->new_qscale, br_compensation, s->frame_bits, var, pict_type);
- }else{
- rce->pict_type=
- rce->new_pict_type= pict_type;
- rce->mc_mb_var_sum= pic->mc_mb_var_sum;
- rce->mb_var_sum = pic-> mb_var_sum;
- rce->qscale = FF_QP2LAMBDA * 2;
- rce->f_code = s->f_code;
- rce->b_code = s->b_code;
- rce->misc_bits= 1;
-
- bits= predict_size(&rcc->pred[pict_type], rce->qscale, sqrt(var));
- if(pict_type== I_TYPE){
- rce->i_count = s->mb_num;
- rce->i_tex_bits= bits;
- rce->p_tex_bits= 0;
- rce->mv_bits= 0;
- }else{
- rce->i_count = 0; //FIXME we do know this approx
- rce->i_tex_bits= 0;
- rce->p_tex_bits= bits*0.9;
-
- rce->mv_bits= bits*0.1;
- }
- rcc->i_cplx_sum [pict_type] += rce->i_tex_bits*rce->qscale;
- rcc->p_cplx_sum [pict_type] += rce->p_tex_bits*rce->qscale;
- rcc->mv_bits_sum[pict_type] += rce->mv_bits;
- rcc->frame_count[pict_type] ++;
-
- bits= rce->i_tex_bits + rce->p_tex_bits;
- rate_factor= rcc->pass1_wanted_bits/rcc->pass1_rc_eq_output_sum * br_compensation;
-
- q= get_qscale(s, rce, rate_factor, picture_number);
- if (q < 0)
- return -1;
-
- assert(q>0.0);
-//printf("%f ", q);
- q= get_diff_limited_q(s, rce, q);
-//printf("%f ", q);
- assert(q>0.0);
-
- if(pict_type==P_TYPE || s->intra_only){ //FIXME type dependant blur like in 2-pass
- rcc->short_term_qsum*=a->qblur;
- rcc->short_term_qcount*=a->qblur;
-
- rcc->short_term_qsum+= q;
- rcc->short_term_qcount++;
-//printf("%f ", q);
- q= short_term_q= rcc->short_term_qsum/rcc->short_term_qcount;
-//printf("%f ", q);
- }
- assert(q>0.0);
-
- q= modify_qscale(s, rce, q, picture_number);
-
- rcc->pass1_wanted_bits+= s->bit_rate/fps;
-
- assert(q>0.0);
- }
-
- if(s->avctx->debug&FF_DEBUG_RC){
- av_log(s->avctx, AV_LOG_DEBUG, "%c qp:%d<%2.1f<%d %d want:%d total:%d comp:%f st_q:%2.2f size:%d var:%d/%d br:%d fps:%d\n",
- av_get_pict_type_char(pict_type), qmin, q, qmax, picture_number, (int)wanted_bits/1000, (int)s->total_bits/1000,
- br_compensation, short_term_q, s->frame_bits, pic->mb_var_sum, pic->mc_mb_var_sum, s->bit_rate/1000, (int)fps
- );
- }
-
- if (q<qmin) q=qmin;
- else if(q>qmax) q=qmax;
-
- if(s->adaptive_quant)
- adaptive_quantization(s, q);
- else
- q= (int)(q + 0.5);
-
- if(!dry_run){
- rcc->last_qscale= q;
- rcc->last_mc_mb_var_sum= pic->mc_mb_var_sum;
- rcc->last_mb_var_sum= pic->mb_var_sum;
- }
-#if 0
-{
- static int mvsum=0, texsum=0;
- mvsum += s->mv_bits;
- texsum += s->i_tex_bits + s->p_tex_bits;
- printf("%d %d//\n\n", mvsum, texsum);
-}
-#endif
- return q;
-}
-
-//----------------------------------------------
-// 2-Pass code
-
-static int init_pass2(MpegEncContext *s)
-{
- RateControlContext *rcc= &s->rc_context;
- AVCodecContext *a= s->avctx;
- int i, toobig;
- double fps= 1/av_q2d(s->avctx->time_base);
- double complexity[5]={0,0,0,0,0}; // aproximate bits at quant=1
- uint64_t const_bits[5]={0,0,0,0,0}; // quantizer idependant bits
- uint64_t all_const_bits;
- uint64_t all_available_bits= (uint64_t)(s->bit_rate*(double)rcc->num_entries/fps);
- double rate_factor=0;
- double step;
- //int last_i_frame=-10000000;
- const int filter_size= (int)(a->qblur*4) | 1;
- double expected_bits;
- double *qscale, *blured_qscale, qscale_sum;
-
- /* find complexity & const_bits & decide the pict_types */
- for(i=0; i<rcc->num_entries; i++){
- RateControlEntry *rce= &rcc->entry[i];
-
- rce->new_pict_type= rce->pict_type;
- rcc->i_cplx_sum [rce->pict_type] += rce->i_tex_bits*rce->qscale;
- rcc->p_cplx_sum [rce->pict_type] += rce->p_tex_bits*rce->qscale;
- rcc->mv_bits_sum[rce->pict_type] += rce->mv_bits;
- rcc->frame_count[rce->pict_type] ++;
-
- complexity[rce->new_pict_type]+= (rce->i_tex_bits+ rce->p_tex_bits)*(double)rce->qscale;
- const_bits[rce->new_pict_type]+= rce->mv_bits + rce->misc_bits;
- }
- all_const_bits= const_bits[I_TYPE] + const_bits[P_TYPE] + const_bits[B_TYPE];
-
- if(all_available_bits < all_const_bits){
- av_log(s->avctx, AV_LOG_ERROR, "requested bitrate is too low\n");
- return -1;
- }
-
- qscale= av_malloc(sizeof(double)*rcc->num_entries);
- blured_qscale= av_malloc(sizeof(double)*rcc->num_entries);
- toobig = 0;
-
- for(step=256*256; step>0.0000001; step*=0.5){
- expected_bits=0;
- rate_factor+= step;
-
- rcc->buffer_index= s->avctx->rc_buffer_size/2;
-
- /* find qscale */
- for(i=0; i<rcc->num_entries; i++){
- qscale[i]= get_qscale(s, &rcc->entry[i], rate_factor, i);
- }
- assert(filter_size%2==1);
-
- /* fixed I/B QP relative to P mode */
- for(i=rcc->num_entries-1; i>=0; i--){
- RateControlEntry *rce= &rcc->entry[i];
-
- qscale[i]= get_diff_limited_q(s, rce, qscale[i]);
- }
-
- /* smooth curve */
- for(i=0; i<rcc->num_entries; i++){
- RateControlEntry *rce= &rcc->entry[i];
- const int pict_type= rce->new_pict_type;
- int j;
- double q=0.0, sum=0.0;
-
- for(j=0; j<filter_size; j++){
- int index= i+j-filter_size/2;
- double d= index-i;
- double coeff= a->qblur==0 ? 1.0 : exp(-d*d/(a->qblur * a->qblur));
-
- if(index < 0 || index >= rcc->num_entries) continue;
- if(pict_type != rcc->entry[index].new_pict_type) continue;
- q+= qscale[index] * coeff;
- sum+= coeff;
- }
- blured_qscale[i]= q/sum;
- }
-
- /* find expected bits */
- for(i=0; i<rcc->num_entries; i++){
- RateControlEntry *rce= &rcc->entry[i];
- double bits;
- rce->new_qscale= modify_qscale(s, rce, blured_qscale[i], i);
- bits= qp2bits(rce, rce->new_qscale) + rce->mv_bits + rce->misc_bits;
-//printf("%d %f\n", rce->new_bits, blured_qscale[i]);
- bits += 8*ff_vbv_update(s, bits);
-
- rce->expected_bits= expected_bits;
- expected_bits += bits;
- }
-
- /*
- av_log(s->avctx, AV_LOG_INFO,
- "expected_bits: %f all_available_bits: %d rate_factor: %f\n",
- expected_bits, (int)all_available_bits, rate_factor);
- */
- if(expected_bits > all_available_bits) {
- rate_factor-= step;
- ++toobig;
- }
- }
- av_free(qscale);
- av_free(blured_qscale);
-
- /* check bitrate calculations and print info */
- qscale_sum = 0.0;
- for(i=0; i<rcc->num_entries; i++){
- /* av_log(s->avctx, AV_LOG_DEBUG, "[lavc rc] entry[%d].new_qscale = %.3f qp = %.3f\n",
- i, rcc->entry[i].new_qscale, rcc->entry[i].new_qscale / FF_QP2LAMBDA); */
- qscale_sum += clip(rcc->entry[i].new_qscale / FF_QP2LAMBDA, s->avctx->qmin, s->avctx->qmax);
- }
- assert(toobig <= 40);
- av_log(s->avctx, AV_LOG_DEBUG,
- "[lavc rc] requested bitrate: %d bps expected bitrate: %d bps\n",
- s->bit_rate,
- (int)(expected_bits / ((double)all_available_bits/s->bit_rate)));
- av_log(s->avctx, AV_LOG_DEBUG,
- "[lavc rc] estimated target average qp: %.3f\n",
- (float)qscale_sum / rcc->num_entries);
- if (toobig == 0) {
- av_log(s->avctx, AV_LOG_INFO,
- "[lavc rc] Using all of requested bitrate is not "
- "necessary for this video with these parameters.\n");
- } else if (toobig == 40) {
- av_log(s->avctx, AV_LOG_ERROR,
- "[lavc rc] Error: bitrate too low for this video "
- "with these parameters.\n");
- return -1;
- } else if (fabs(expected_bits/all_available_bits - 1.0) > 0.01) {
- av_log(s->avctx, AV_LOG_ERROR,
- "[lavc rc] Error: 2pass curve failed to converge\n");
- return -1;
- }
-
- return 0;
-}
diff --git a/src/libffmpeg/libavcodec/raw.c b/src/libffmpeg/libavcodec/raw.c
deleted file mode 100644
index f4fddf73c..000000000
--- a/src/libffmpeg/libavcodec/raw.c
+++ /dev/null
@@ -1,210 +0,0 @@
-/*
- * Raw Video Codec
- * Copyright (c) 2001 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 raw.c
- * Raw Video Codec
- */
-
-#include "avcodec.h"
-
-typedef struct RawVideoContext {
- unsigned char * buffer; /* block of memory for holding one frame */
- int length; /* number of bytes in buffer */
- AVFrame pic; ///< AVCodecContext.coded_frame
-} RawVideoContext;
-
-typedef struct PixelFormatTag {
- int pix_fmt;
- unsigned int fourcc;
-} PixelFormatTag;
-
-static const PixelFormatTag pixelFormatTags[] = {
- { PIX_FMT_YUV420P, MKTAG('I', '4', '2', '0') }, /* Planar formats */
- { PIX_FMT_YUV420P, MKTAG('I', 'Y', 'U', 'V') },
- { PIX_FMT_YUV420P, MKTAG('Y', 'V', '1', '2') },
- { PIX_FMT_YUV410P, MKTAG('Y', 'U', 'V', '9') },
- { PIX_FMT_YUV411P, MKTAG('Y', '4', '1', 'B') },
- { PIX_FMT_YUV422P, MKTAG('Y', '4', '2', 'B') },
- { PIX_FMT_GRAY8, MKTAG('Y', '8', '0', '0') },
- { PIX_FMT_GRAY8, MKTAG(' ', ' ', 'Y', '8') },
-
-
- { PIX_FMT_YUV422, MKTAG('Y', 'U', 'Y', '2') }, /* Packed formats */
- { PIX_FMT_YUV422, MKTAG('Y', '4', '2', '2') },
- { PIX_FMT_UYVY422, MKTAG('U', 'Y', 'V', 'Y') },
- { 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) },
-
- /* quicktime */
- { PIX_FMT_UYVY422, MKTAG('2', 'v', 'u', 'y') },
-
- { -1, 0 },
-};
-
-static int findPixelFormat(unsigned int fourcc)
-{
- const PixelFormatTag * tags = pixelFormatTags;
- while (tags->pix_fmt >= 0) {
- if (tags->fourcc == fourcc)
- return tags->pix_fmt;
- tags++;
- }
- return PIX_FMT_YUV420P;
-}
-
-unsigned int avcodec_pix_fmt_to_codec_tag(enum PixelFormat fmt)
-{
- const PixelFormatTag * tags = pixelFormatTags;
- while (tags->pix_fmt >= 0) {
- if (tags->pix_fmt == fmt)
- return tags->fourcc;
- tags++;
- }
- return 0;
-}
-
-/* RAW Decoder Implementation */
-
-static int raw_init_decoder(AVCodecContext *avctx)
-{
- RawVideoContext *context = avctx->priv_data;
-
- if (avctx->codec_tag)
- avctx->pix_fmt = findPixelFormat(avctx->codec_tag);
- else if (avctx->bits_per_sample){
- switch(avctx->bits_per_sample){
- case 8: avctx->pix_fmt= PIX_FMT_PAL8 ; break;
- case 15: avctx->pix_fmt= PIX_FMT_RGB555; break;
- case 16: avctx->pix_fmt= PIX_FMT_RGB555; break;
- case 24: avctx->pix_fmt= PIX_FMT_BGR24 ; break;
- case 32: avctx->pix_fmt= PIX_FMT_RGBA32; break;
- }
- }
-
- context->length = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
- context->buffer = av_malloc(context->length);
- context->pic.pict_type = FF_I_TYPE;
- context->pic.key_frame = 1;
-
- avctx->coded_frame= &context->pic;
-
- if (!context->buffer)
- return -1;
-
- return 0;
-}
-
-static void flip(AVCodecContext *avctx, AVPicture * picture){
- if(!avctx->codec_tag && avctx->bits_per_sample && picture->linesize[2]==0){
- picture->data[0] += picture->linesize[0] * (avctx->height-1);
- picture->linesize[0] *= -1;
- }
-}
-
-static int raw_decode(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- RawVideoContext *context = avctx->priv_data;
-
- AVFrame * frame = (AVFrame *) data;
- AVPicture * picture = (AVPicture *) data;
-
- frame->interlaced_frame = avctx->coded_frame->interlaced_frame;
- frame->top_field_first = avctx->coded_frame->top_field_first;
-
- if(buf_size < context->length - (avctx->pix_fmt==PIX_FMT_PAL8 ? 256*4 : 0))
- return -1;
-
- avpicture_fill(picture, buf, avctx->pix_fmt, avctx->width, avctx->height);
- if(avctx->pix_fmt==PIX_FMT_PAL8 && buf_size < context->length){
- frame->data[1]= context->buffer;
- }
- if (avctx->palctrl && avctx->palctrl->palette_changed) {
- memcpy(frame->data[1], avctx->palctrl->palette, AVPALETTE_SIZE);
- avctx->palctrl->palette_changed = 0;
- }
-
- flip(avctx, picture);
-
- if (avctx->codec_tag == MKTAG('Y', 'V', '1', '2'))
- {
- // swap fields
- unsigned char *tmp = picture->data[1];
- picture->data[1] = picture->data[2];
- picture->data[2] = tmp;
- }
-
- *data_size = sizeof(AVPicture);
- return buf_size;
-}
-
-static int raw_close_decoder(AVCodecContext *avctx)
-{
- RawVideoContext *context = avctx->priv_data;
-
- av_freep(&context->buffer);
- return 0;
-}
-
-/* RAW Encoder Implementation */
-#ifdef CONFIG_RAWVIDEO_ENCODER
-static 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;
- if(!avctx->codec_tag)
- avctx->codec_tag = avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt);
- return 0;
-}
-
-static int raw_encode(AVCodecContext *avctx,
- unsigned char *frame, int buf_size, void *data)
-{
- return avpicture_layout((AVPicture *)data, avctx->pix_fmt, avctx->width,
- avctx->height, frame, buf_size);
-}
-
-AVCodec rawvideo_encoder = {
- "rawvideo",
- CODEC_TYPE_VIDEO,
- CODEC_ID_RAWVIDEO,
- sizeof(AVFrame),
- raw_init_encoder,
- raw_encode,
-};
-#endif // CONFIG_RAWVIDEO_ENCODER
-
-AVCodec rawvideo_decoder = {
- "rawvideo",
- CODEC_TYPE_VIDEO,
- CODEC_ID_RAWVIDEO,
- sizeof(RawVideoContext),
- raw_init_decoder,
- NULL,
- raw_close_decoder,
- raw_decode,
-};
diff --git a/src/libffmpeg/libavcodec/resample2.c b/src/libffmpeg/libavcodec/resample2.c
deleted file mode 100644
index 3ae0ba855..000000000
--- a/src/libffmpeg/libavcodec/resample2.c
+++ /dev/null
@@ -1,274 +0,0 @@
-/*
- * audio resampling
- * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-/**
- * @file resample2.c
- * audio resampling
- * @author Michael Niedermayer <michaelni@gmx.at>
- */
-
-#include "avcodec.h"
-#include "common.h"
-#include "dsputil.h"
-
-#if 1
-#define FILTER_SHIFT 15
-
-#define FELEM int16_t
-#define FELEM2 int32_t
-#define FELEM_MAX INT16_MAX
-#define FELEM_MIN INT16_MIN
-#else
-#define FILTER_SHIFT 22
-
-#define FELEM int32_t
-#define FELEM2 int64_t
-#define FELEM_MAX INT32_MAX
-#define FELEM_MIN INT32_MIN
-#endif
-
-
-typedef struct AVResampleContext{
- FELEM *filter_bank;
- int filter_length;
- int ideal_dst_incr;
- int dst_incr;
- int index;
- int frac;
- int src_incr;
- int compensation_distance;
- int phase_shift;
- int phase_mask;
- int linear;
-}AVResampleContext;
-
-/**
- * 0th order modified bessel function of the first kind.
- */
-static double bessel(double x){
- double v=1;
- double t=1;
- int i;
-
- for(i=1; i<50; i++){
- t *= i;
- v += pow(x*x/4, i)/(t*t);
- }
- return v;
-}
-
-/**
- * builds a polyphase filterbank.
- * @param factor resampling factor
- * @param scale wanted sum of coefficients for each filter
- * @param type 0->cubic, 1->blackman nuttall windowed sinc, 2->kaiser windowed sinc beta=16
- */
-void av_build_filter(FELEM *filter, double factor, int tap_count, int phase_count, int scale, int type){
- int ph, i, v;
- double x, y, w, tab[tap_count];
- const int center= (tap_count-1)/2;
-
- /* if upsampling, only need to interpolate, no filter */
- if (factor > 1.0)
- factor = 1.0;
-
- for(ph=0;ph<phase_count;ph++) {
- double norm = 0;
- double e= 0;
- for(i=0;i<tap_count;i++) {
- x = M_PI * ((double)(i - center) - (double)ph / phase_count) * factor;
- if (x == 0) y = 1.0;
- else y = sin(x) / x;
- switch(type){
- case 0:{
- const float d= -0.5; //first order derivative = -0.5
- x = fabs(((double)(i - center) - (double)ph / phase_count) * factor);
- if(x<1.0) y= 1 - 3*x*x + 2*x*x*x + d*( -x*x + x*x*x);
- else y= d*(-4 + 8*x - 5*x*x + x*x*x);
- break;}
- case 1:
- w = 2.0*x / (factor*tap_count) + M_PI;
- y *= 0.3635819 - 0.4891775 * cos(w) + 0.1365995 * cos(2*w) - 0.0106411 * cos(3*w);
- break;
- case 2:
- w = 2.0*x / (factor*tap_count*M_PI);
- y *= bessel(16*sqrt(FFMAX(1-w*w, 0)));
- break;
- }
-
- tab[i] = y;
- norm += y;
- }
-
- /* normalize so that an uniform color remains the same */
- for(i=0;i<tap_count;i++) {
- v = clip(lrintf(tab[i] * scale / norm + e), FELEM_MIN, FELEM_MAX);
- filter[ph * tap_count + i] = v;
- e += tab[i] * scale / norm - v;
- }
- }
-}
-
-/**
- * initalizes a audio resampler.
- * note, if either rate is not a integer then simply scale both rates up so they are
- */
-AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_size, int phase_shift, int linear, double cutoff){
- AVResampleContext *c= av_mallocz(sizeof(AVResampleContext));
- double factor= FFMIN(out_rate * cutoff / in_rate, 1.0);
- int phase_count= 1<<phase_shift;
-
- c->phase_shift= phase_shift;
- c->phase_mask= phase_count-1;
- c->linear= linear;
-
- 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_SHIFT, 1);
- memcpy(&c->filter_bank[c->filter_length*phase_count+1], c->filter_bank, (c->filter_length-1)*sizeof(FELEM));
- c->filter_bank[c->filter_length*phase_count]= c->filter_bank[c->filter_length - 1];
-
- c->src_incr= out_rate;
- c->ideal_dst_incr= c->dst_incr= in_rate * phase_count;
- c->index= -phase_count*((c->filter_length-1)/2);
-
- return c;
-}
-
-void av_resample_close(AVResampleContext *c){
- av_freep(&c->filter_bank);
- av_freep(&c);
-}
-
-/**
- * Compensates samplerate/timestamp drift. The compensation is done by changing
- * the resampler parameters, so no audible clicks or similar distortions ocur
- * @param compensation_distance distance in output samples over which the compensation should be performed
- * @param sample_delta number of output samples which should be output less
- *
- * example: av_resample_compensate(c, 10, 500)
- * here instead of 510 samples only 500 samples would be output
- *
- * note, due to rounding the actual compensation might be slightly different,
- * especially if the compensation_distance is large and the in_rate used during init is small
- */
-void av_resample_compensate(AVResampleContext *c, int sample_delta, int compensation_distance){
-// sample_delta += (c->ideal_dst_incr - c->dst_incr)*(int64_t)c->compensation_distance / c->ideal_dst_incr;
- c->compensation_distance= compensation_distance;
- c->dst_incr = c->ideal_dst_incr - c->ideal_dst_incr * (int64_t)sample_delta / compensation_distance;
-}
-
-/**
- * resamples.
- * @param src an array of unconsumed samples
- * @param consumed the number of samples of src which have been consumed are returned here
- * @param src_size the number of unconsumed samples available
- * @param dst_size the amount of space in samples available in dst
- * @param update_ctx if this is 0 then the context wont be modified, that way several channels can be resampled with the same context
- * @return the number of samples written in dst or -1 if an error occured
- */
-int av_resample(AVResampleContext *c, short *dst, short *src, int *consumed, int src_size, int dst_size, int update_ctx){
- int dst_index, i;
- int index= c->index;
- int frac= c->frac;
- int dst_incr_frac= c->dst_incr % c->src_incr;
- int dst_incr= c->dst_incr / c->src_incr;
- int compensation_distance= c->compensation_distance;
-
- if(compensation_distance == 0 && c->filter_length == 1 && c->phase_shift==0){
- int64_t index2= ((int64_t)index)<<32;
- int64_t incr= (1LL<<32) * c->dst_incr / c->src_incr;
- dst_size= FFMIN(dst_size, (src_size-1-index) * (int64_t)c->src_incr / c->dst_incr);
-
- for(dst_index=0; dst_index < dst_size; dst_index++){
- dst[dst_index] = src[index2>>32];
- index2 += incr;
- }
- frac += dst_index * dst_incr_frac;
- index += dst_index * dst_incr;
- index += frac / c->src_incr;
- frac %= c->src_incr;
- }else{
- for(dst_index=0; dst_index < dst_size; dst_index++){
- FELEM *filter= c->filter_bank + c->filter_length*(index & c->phase_mask);
- int sample_index= index >> c->phase_shift;
- FELEM2 val=0;
-
- if(sample_index < 0){
- for(i=0; i<c->filter_length; i++)
- val += src[FFABS(sample_index + i) % src_size] * filter[i];
- }else if(sample_index + c->filter_length > src_size){
- break;
- }else if(c->linear){
- int64_t v=0;
- int sub_phase= (frac<<8) / c->src_incr;
- for(i=0; i<c->filter_length; i++){
- int64_t coeff= filter[i]*(256 - sub_phase) + filter[i + c->filter_length]*sub_phase;
- v += src[sample_index + i] * coeff;
- }
- val= v>>8;
- }else{
- for(i=0; i<c->filter_length; i++){
- val += src[sample_index + i] * (FELEM2)filter[i];
- }
- }
-
- val = (val + (1<<(FILTER_SHIFT-1)))>>FILTER_SHIFT;
- dst[dst_index] = (unsigned)(val + 32768) > 65535 ? (val>>31) ^ 32767 : val;
-
- frac += dst_incr_frac;
- index += dst_incr;
- if(frac >= c->src_incr){
- frac -= c->src_incr;
- index++;
- }
-
- if(dst_index + 1 == compensation_distance){
- compensation_distance= 0;
- dst_incr_frac= c->ideal_dst_incr % c->src_incr;
- dst_incr= c->ideal_dst_incr / c->src_incr;
- }
- }
- }
- *consumed= FFMAX(index, 0) >> c->phase_shift;
- if(index>=0) index &= c->phase_mask;
-
- if(compensation_distance){
- compensation_distance -= dst_index;
- assert(compensation_distance > 0);
- }
- if(update_ctx){
- c->frac= frac;
- c->index= index;
- c->dst_incr= dst_incr_frac + c->src_incr*dst_incr;
- c->compensation_distance= compensation_distance;
- }
-#if 0
- if(update_ctx && !c->compensation_distance){
-#undef rand
- av_resample_compensate(c, rand() % (8000*2) - 8000, 8000*2);
-av_log(NULL, AV_LOG_DEBUG, "%d %d %d\n", c->dst_incr, c->ideal_dst_incr, c->compensation_distance);
- }
-#endif
-
- return dst_index;
-}
diff --git a/src/libffmpeg/libavcodec/roqvideo.c b/src/libffmpeg/libavcodec/roqvideo.c
deleted file mode 100644
index 4595b047c..000000000
--- a/src/libffmpeg/libavcodec/roqvideo.c
+++ /dev/null
@@ -1,474 +0,0 @@
-/*
- * Copyright (C) 2003 the ffmpeg project
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-/**
- * @file roqvideo.c
- * Id RoQ Video Decoder by Dr. Tim Ferguson
- * For more information about the Id RoQ format, visit:
- * http://www.csse.monash.edu.au/~timf/
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "common.h"
-#include "avcodec.h"
-#include "dsputil.h"
-
-typedef struct {
- unsigned char y0, y1, y2, y3, u, v;
-} roq_cell;
-
-typedef struct {
- int idx[4];
-} roq_qcell;
-
-static int uiclip[1024], *uiclp; /* clipping table */
-#define avg2(a,b) uiclp[(((int)(a)+(int)(b)+1)>>1)]
-#define avg4(a,b,c,d) uiclp[(((int)(a)+(int)(b)+(int)(c)+(int)(d)+2)>>2)]
-
-typedef struct RoqContext {
-
- AVCodecContext *avctx;
- DSPContext dsp;
- AVFrame last_frame;
- AVFrame current_frame;
- int first_frame;
- int y_stride;
- int c_stride;
-
- roq_cell cells[256];
- roq_qcell qcells[256];
-
- unsigned char *buf;
- int size;
-
-} RoqContext;
-
-#define RoQ_INFO 0x1001
-#define RoQ_QUAD_CODEBOOK 0x1002
-#define RoQ_QUAD_VQ 0x1011
-#define RoQ_SOUND_MONO 0x1020
-#define RoQ_SOUND_STEREO 0x1021
-
-#define RoQ_ID_MOT 0x00
-#define RoQ_ID_FCC 0x01
-#define RoQ_ID_SLD 0x02
-#define RoQ_ID_CCC 0x03
-
-#define get_byte(in_buffer) *(in_buffer++)
-#define get_word(in_buffer) ((unsigned short)(in_buffer += 2, \
- (in_buffer[-1] << 8 | in_buffer[-2])))
-#define get_long(in_buffer) ((unsigned long)(in_buffer += 4, \
- (in_buffer[-1] << 24 | in_buffer[-2] << 16 | in_buffer[-3] << 8 | in_buffer[-4])))
-
-
-static void apply_vector_2x2(RoqContext *ri, int x, int y, roq_cell *cell)
-{
- unsigned char *yptr;
-
- yptr = ri->current_frame.data[0] + (y * ri->y_stride) + x;
- *yptr++ = cell->y0;
- *yptr++ = cell->y1;
- yptr += (ri->y_stride - 2);
- *yptr++ = cell->y2;
- *yptr++ = cell->y3;
- ri->current_frame.data[1][(y/2) * (ri->c_stride) + x/2] = cell->u;
- ri->current_frame.data[2][(y/2) * (ri->c_stride) + x/2] = cell->v;
-}
-
-static void apply_vector_4x4(RoqContext *ri, int x, int y, roq_cell *cell)
-{
- unsigned long row_inc, c_row_inc;
- register unsigned char y0, y1, u, v;
- unsigned char *yptr, *uptr, *vptr;
-
- yptr = ri->current_frame.data[0] + (y * ri->y_stride) + x;
- uptr = ri->current_frame.data[1] + (y/2) * (ri->c_stride) + x/2;
- vptr = ri->current_frame.data[2] + (y/2) * (ri->c_stride) + x/2;
-
- row_inc = ri->y_stride - 4;
- c_row_inc = (ri->c_stride) - 2;
- *yptr++ = y0 = cell->y0; *uptr++ = u = cell->u; *vptr++ = v = cell->v;
- *yptr++ = y0;
- *yptr++ = y1 = cell->y1; *uptr++ = u; *vptr++ = v;
- *yptr++ = y1;
-
- yptr += row_inc;
-
- *yptr++ = y0;
- *yptr++ = y0;
- *yptr++ = y1;
- *yptr++ = y1;
-
- yptr += row_inc; uptr += c_row_inc; vptr += c_row_inc;
-
- *yptr++ = y0 = cell->y2; *uptr++ = u; *vptr++ = v;
- *yptr++ = y0;
- *yptr++ = y1 = cell->y3; *uptr++ = u; *vptr++ = v;
- *yptr++ = y1;
-
- yptr += row_inc;
-
- *yptr++ = y0;
- *yptr++ = y0;
- *yptr++ = y1;
- *yptr++ = y1;
-}
-
-static void apply_motion_4x4(RoqContext *ri, int x, int y, unsigned char mv,
- signed char mean_x, signed char mean_y)
-{
- int i, hw, mx, my;
- unsigned char *pa, *pb;
-
- mx = x + 8 - (mv >> 4) - mean_x;
- my = y + 8 - (mv & 0xf) - mean_y;
-
- /* check MV against frame boundaries */
- if ((mx < 0) || (mx > ri->avctx->width - 4) ||
- (my < 0) || (my > ri->avctx->height - 4)) {
- av_log(ri->avctx, AV_LOG_ERROR, "motion vector out of bounds: MV = (%d, %d), boundaries = (0, 0, %d, %d)\n",
- mx, my, ri->avctx->width, ri->avctx->height);
- return;
- }
-
- pa = ri->current_frame.data[0] + (y * ri->y_stride) + x;
- pb = ri->last_frame.data[0] + (my * ri->y_stride) + mx;
- for(i = 0; i < 4; i++) {
- pa[0] = pb[0];
- pa[1] = pb[1];
- pa[2] = pb[2];
- pa[3] = pb[3];
- pa += ri->y_stride;
- pb += ri->y_stride;
- }
-
- hw = ri->y_stride/2;
- pa = ri->current_frame.data[1] + (y * ri->y_stride)/4 + x/2;
- pb = ri->last_frame.data[1] + (my/2) * (ri->y_stride/2) + (mx + 1)/2;
-
- for(i = 0; i < 2; i++) {
- switch(((my & 0x01) << 1) | (mx & 0x01)) {
-
- case 0:
- pa[0] = pb[0];
- pa[1] = pb[1];
- pa[hw] = pb[hw];
- pa[hw+1] = pb[hw+1];
- break;
-
- case 1:
- pa[0] = avg2(pb[0], pb[1]);
- pa[1] = avg2(pb[1], pb[2]);
- pa[hw] = avg2(pb[hw], pb[hw+1]);
- pa[hw+1] = avg2(pb[hw+1], pb[hw+2]);
- break;
-
- case 2:
- pa[0] = avg2(pb[0], pb[hw]);
- pa[1] = avg2(pb[1], pb[hw+1]);
- pa[hw] = avg2(pb[hw], pb[hw*2]);
- pa[hw+1] = avg2(pb[hw+1], pb[(hw*2)+1]);
- break;
-
- case 3:
- pa[0] = avg4(pb[0], pb[1], pb[hw], pb[hw+1]);
- pa[1] = avg4(pb[1], pb[2], pb[hw+1], pb[hw+2]);
- pa[hw] = avg4(pb[hw], pb[hw+1], pb[hw*2], pb[(hw*2)+1]);
- pa[hw+1] = avg4(pb[hw+1], pb[hw+2], pb[(hw*2)+1], pb[(hw*2)+1]);
- break;
- }
-
- pa = ri->current_frame.data[2] + (y * ri->y_stride)/4 + x/2;
- pb = ri->last_frame.data[2] + (my/2) * (ri->y_stride/2) + (mx + 1)/2;
- }
-}
-
-static void apply_motion_8x8(RoqContext *ri, int x, int y,
- unsigned char mv, signed char mean_x, signed char mean_y)
-{
- int mx, my, i, j, hw;
- unsigned char *pa, *pb;
-
- mx = x + 8 - (mv >> 4) - mean_x;
- my = y + 8 - (mv & 0xf) - mean_y;
-
- /* check MV against frame boundaries */
- if ((mx < 0) || (mx > ri->avctx->width - 8) ||
- (my < 0) || (my > ri->avctx->height - 8)) {
- av_log(ri->avctx, AV_LOG_ERROR, "motion vector out of bounds: MV = (%d, %d), boundaries = (0, 0, %d, %d)\n",
- mx, my, ri->avctx->width, ri->avctx->height);
- return;
- }
-
- pa = ri->current_frame.data[0] + (y * ri->y_stride) + x;
- pb = ri->last_frame.data[0] + (my * ri->y_stride) + mx;
- for(i = 0; i < 8; i++) {
- pa[0] = pb[0];
- pa[1] = pb[1];
- pa[2] = pb[2];
- pa[3] = pb[3];
- pa[4] = pb[4];
- pa[5] = pb[5];
- pa[6] = pb[6];
- pa[7] = pb[7];
- pa += ri->y_stride;
- pb += ri->y_stride;
- }
-
- hw = ri->c_stride;
- pa = ri->current_frame.data[1] + (y * ri->y_stride)/4 + x/2;
- pb = ri->last_frame.data[1] + (my/2) * (ri->y_stride/2) + (mx + 1)/2;
- for(j = 0; j < 2; j++) {
- for(i = 0; i < 4; i++) {
- switch(((my & 0x01) << 1) | (mx & 0x01)) {
-
- case 0:
- pa[0] = pb[0];
- pa[1] = pb[1];
- pa[2] = pb[2];
- pa[3] = pb[3];
- break;
-
- case 1:
- pa[0] = avg2(pb[0], pb[1]);
- pa[1] = avg2(pb[1], pb[2]);
- pa[2] = avg2(pb[2], pb[3]);
- pa[3] = avg2(pb[3], pb[4]);
- break;
-
- case 2:
- pa[0] = avg2(pb[0], pb[hw]);
- pa[1] = avg2(pb[1], pb[hw+1]);
- pa[2] = avg2(pb[2], pb[hw+2]);
- pa[3] = avg2(pb[3], pb[hw+3]);
- break;
-
- case 3:
- pa[0] = avg4(pb[0], pb[1], pb[hw], pb[hw+1]);
- pa[1] = avg4(pb[1], pb[2], pb[hw+1], pb[hw+2]);
- pa[2] = avg4(pb[2], pb[3], pb[hw+2], pb[hw+3]);
- pa[3] = avg4(pb[3], pb[4], pb[hw+3], pb[hw+4]);
- break;
- }
- pa += ri->c_stride;
- pb += ri->c_stride;
- }
-
- pa = ri->current_frame.data[2] + (y * ri->y_stride)/4 + x/2;
- pb = ri->last_frame.data[2] + (my/2) * (ri->y_stride/2) + (mx + 1)/2;
- }
-}
-
-static void roqvideo_decode_frame(RoqContext *ri)
-{
- unsigned int chunk_id = 0, chunk_arg = 0;
- unsigned long chunk_size = 0;
- int i, j, k, nv1, nv2, vqflg = 0, vqflg_pos = -1;
- int vqid, bpos, xpos, ypos, xp, yp, x, y;
- int frame_stats[2][4] = {{0},{0}};
- roq_qcell *qcell;
- unsigned char *buf = ri->buf;
- unsigned char *buf_end = ri->buf + ri->size;
-
- while (buf < buf_end) {
- chunk_id = get_word(buf);
- chunk_size = get_long(buf);
- chunk_arg = get_word(buf);
-
- if(chunk_id == RoQ_QUAD_VQ)
- break;
- if(chunk_id == RoQ_QUAD_CODEBOOK) {
- if((nv1 = chunk_arg >> 8) == 0)
- nv1 = 256;
- if((nv2 = chunk_arg & 0xff) == 0 && nv1 * 6 < chunk_size)
- nv2 = 256;
- for(i = 0; i < nv1; i++) {
- ri->cells[i].y0 = get_byte(buf);
- ri->cells[i].y1 = get_byte(buf);
- ri->cells[i].y2 = get_byte(buf);
- ri->cells[i].y3 = get_byte(buf);
- ri->cells[i].u = get_byte(buf);
- ri->cells[i].v = get_byte(buf);
- }
- for(i = 0; i < nv2; i++)
- for(j = 0; j < 4; j++)
- ri->qcells[i].idx[j] = get_byte(buf);
- }
- }
-
- bpos = xpos = ypos = 0;
- while(bpos < chunk_size) {
- for (yp = ypos; yp < ypos + 16; yp += 8)
- for (xp = xpos; xp < xpos + 16; xp += 8) {
- if (vqflg_pos < 0) {
- vqflg = buf[bpos++]; vqflg |= (buf[bpos++] << 8);
- vqflg_pos = 7;
- }
- vqid = (vqflg >> (vqflg_pos * 2)) & 0x3;
- frame_stats[0][vqid]++;
- vqflg_pos--;
-
- switch(vqid) {
- case RoQ_ID_MOT:
- apply_motion_8x8(ri, xp, yp, 0, 8, 8);
- break;
- case RoQ_ID_FCC:
- apply_motion_8x8(ri, xp, yp, buf[bpos++], chunk_arg >> 8,
- chunk_arg & 0xff);
- break;
- case RoQ_ID_SLD:
- qcell = ri->qcells + buf[bpos++];
- apply_vector_4x4(ri, xp, yp, ri->cells + qcell->idx[0]);
- apply_vector_4x4(ri, xp+4, yp, ri->cells + qcell->idx[1]);
- apply_vector_4x4(ri, xp, yp+4, ri->cells + qcell->idx[2]);
- apply_vector_4x4(ri, xp+4, yp+4, ri->cells + qcell->idx[3]);
- break;
- case RoQ_ID_CCC:
- for (k = 0; k < 4; k++) {
- x = xp; y = yp;
- if(k & 0x01) x += 4;
- if(k & 0x02) y += 4;
-
- if (vqflg_pos < 0) {
- vqflg = buf[bpos++];
- vqflg |= (buf[bpos++] << 8);
- vqflg_pos = 7;
- }
- vqid = (vqflg >> (vqflg_pos * 2)) & 0x3;
- frame_stats[1][vqid]++;
- vqflg_pos--;
- switch(vqid) {
- case RoQ_ID_MOT:
- apply_motion_4x4(ri, x, y, 0, 8, 8);
- break;
- case RoQ_ID_FCC:
- apply_motion_4x4(ri, x, y, buf[bpos++],
- chunk_arg >> 8, chunk_arg & 0xff);
- break;
- case RoQ_ID_SLD:
- qcell = ri->qcells + buf[bpos++];
- apply_vector_2x2(ri, x, y, ri->cells + qcell->idx[0]);
- apply_vector_2x2(ri, x+2, y, ri->cells + qcell->idx[1]);
- apply_vector_2x2(ri, x, y+2, ri->cells + qcell->idx[2]);
- apply_vector_2x2(ri, x+2, y+2, ri->cells + qcell->idx[3]);
- break;
- case RoQ_ID_CCC:
- apply_vector_2x2(ri, x, y, ri->cells + buf[bpos]);
- apply_vector_2x2(ri, x+2, y, ri->cells + buf[bpos+1]);
- apply_vector_2x2(ri, x, y+2, ri->cells + buf[bpos+2]);
- apply_vector_2x2(ri, x+2, y+2, ri->cells + buf[bpos+3]);
- bpos += 4;
- break;
- }
- }
- break;
- default:
- av_log(ri->avctx, AV_LOG_ERROR, "Unknown vq code: %d\n", vqid);
- }
- }
-
- xpos += 16;
- if (xpos >= ri->avctx->width) {
- xpos -= ri->avctx->width;
- ypos += 16;
- }
- if(ypos >= ri->avctx->height)
- break;
- }
-}
-
-
-static int roq_decode_init(AVCodecContext *avctx)
-{
- RoqContext *s = avctx->priv_data;
- int i;
-
- s->avctx = avctx;
- s->first_frame = 1;
- avctx->pix_fmt = PIX_FMT_YUV420P;
- avctx->has_b_frames = 0;
- dsputil_init(&s->dsp, avctx);
-
- uiclp = uiclip+512;
- for(i = -512; i < 512; i++)
- uiclp[i] = (i < 0 ? 0 : (i > 255 ? 255 : i));
-
- return 0;
-}
-
-static int roq_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- RoqContext *s = avctx->priv_data;
-
- if (avctx->get_buffer(avctx, &s->current_frame)) {
- av_log(avctx, AV_LOG_ERROR, " RoQ: get_buffer() failed\n");
- return -1;
- }
- s->y_stride = s->current_frame.linesize[0];
- s->c_stride = s->current_frame.linesize[1];
-
- s->buf = buf;
- s->size = buf_size;
- roqvideo_decode_frame(s);
-
- /* release the last frame if it is allocated */
- if (s->first_frame)
- s->first_frame = 0;
- else
- avctx->release_buffer(avctx, &s->last_frame);
-
- /* shuffle frames */
- s->last_frame = s->current_frame;
-
- *data_size = sizeof(AVFrame);
- *(AVFrame*)data = s->current_frame;
-
- return buf_size;
-}
-
-static int roq_decode_end(AVCodecContext *avctx)
-{
- RoqContext *s = avctx->priv_data;
-
- /* release the last frame */
- if (s->last_frame.data[0])
- avctx->release_buffer(avctx, &s->last_frame);
-
- return 0;
-}
-
-AVCodec roq_decoder = {
- "roqvideo",
- CODEC_TYPE_VIDEO,
- CODEC_ID_ROQ,
- sizeof(RoqContext),
- roq_decode_init,
- NULL,
- roq_decode_end,
- roq_decode_frame,
- CODEC_CAP_DR1,
-};
diff --git a/src/libffmpeg/libavcodec/rv10.c b/src/libffmpeg/libavcodec/rv10.c
deleted file mode 100644
index af438a34b..000000000
--- a/src/libffmpeg/libavcodec/rv10.c
+++ /dev/null
@@ -1,803 +0,0 @@
-/*
- * RV10 codec
- * Copyright (c) 2000,2001 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
- */
-
-/**
- * @file rv10.c
- * RV10 codec.
- */
-
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-
-//#define DEBUG
-
-#define DC_VLC_BITS 14 //FIXME find a better solution
-
-static const uint16_t rv_lum_code[256] =
-{
- 0x3e7f, 0x0f00, 0x0f01, 0x0f02, 0x0f03, 0x0f04, 0x0f05, 0x0f06,
- 0x0f07, 0x0f08, 0x0f09, 0x0f0a, 0x0f0b, 0x0f0c, 0x0f0d, 0x0f0e,
- 0x0f0f, 0x0f10, 0x0f11, 0x0f12, 0x0f13, 0x0f14, 0x0f15, 0x0f16,
- 0x0f17, 0x0f18, 0x0f19, 0x0f1a, 0x0f1b, 0x0f1c, 0x0f1d, 0x0f1e,
- 0x0f1f, 0x0f20, 0x0f21, 0x0f22, 0x0f23, 0x0f24, 0x0f25, 0x0f26,
- 0x0f27, 0x0f28, 0x0f29, 0x0f2a, 0x0f2b, 0x0f2c, 0x0f2d, 0x0f2e,
- 0x0f2f, 0x0f30, 0x0f31, 0x0f32, 0x0f33, 0x0f34, 0x0f35, 0x0f36,
- 0x0f37, 0x0f38, 0x0f39, 0x0f3a, 0x0f3b, 0x0f3c, 0x0f3d, 0x0f3e,
- 0x0f3f, 0x0380, 0x0381, 0x0382, 0x0383, 0x0384, 0x0385, 0x0386,
- 0x0387, 0x0388, 0x0389, 0x038a, 0x038b, 0x038c, 0x038d, 0x038e,
- 0x038f, 0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396,
- 0x0397, 0x0398, 0x0399, 0x039a, 0x039b, 0x039c, 0x039d, 0x039e,
- 0x039f, 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6,
- 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce,
- 0x00cf, 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056,
- 0x0057, 0x0020, 0x0021, 0x0022, 0x0023, 0x000c, 0x000d, 0x0004,
- 0x0000, 0x0005, 0x000e, 0x000f, 0x0024, 0x0025, 0x0026, 0x0027,
- 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f,
- 0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7,
- 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df,
- 0x03a0, 0x03a1, 0x03a2, 0x03a3, 0x03a4, 0x03a5, 0x03a6, 0x03a7,
- 0x03a8, 0x03a9, 0x03aa, 0x03ab, 0x03ac, 0x03ad, 0x03ae, 0x03af,
- 0x03b0, 0x03b1, 0x03b2, 0x03b3, 0x03b4, 0x03b5, 0x03b6, 0x03b7,
- 0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf,
- 0x0f40, 0x0f41, 0x0f42, 0x0f43, 0x0f44, 0x0f45, 0x0f46, 0x0f47,
- 0x0f48, 0x0f49, 0x0f4a, 0x0f4b, 0x0f4c, 0x0f4d, 0x0f4e, 0x0f4f,
- 0x0f50, 0x0f51, 0x0f52, 0x0f53, 0x0f54, 0x0f55, 0x0f56, 0x0f57,
- 0x0f58, 0x0f59, 0x0f5a, 0x0f5b, 0x0f5c, 0x0f5d, 0x0f5e, 0x0f5f,
- 0x0f60, 0x0f61, 0x0f62, 0x0f63, 0x0f64, 0x0f65, 0x0f66, 0x0f67,
- 0x0f68, 0x0f69, 0x0f6a, 0x0f6b, 0x0f6c, 0x0f6d, 0x0f6e, 0x0f6f,
- 0x0f70, 0x0f71, 0x0f72, 0x0f73, 0x0f74, 0x0f75, 0x0f76, 0x0f77,
- 0x0f78, 0x0f79, 0x0f7a, 0x0f7b, 0x0f7c, 0x0f7d, 0x0f7e, 0x0f7f,
-};
-
-static const uint8_t rv_lum_bits[256] =
-{
- 14, 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, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 7, 7, 7, 7, 7, 7, 7,
- 7, 6, 6, 6, 6, 5, 5, 4,
- 2, 4, 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,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 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,
-};
-
-static const uint16_t rv_chrom_code[256] =
-{
- 0xfe7f, 0x3f00, 0x3f01, 0x3f02, 0x3f03, 0x3f04, 0x3f05, 0x3f06,
- 0x3f07, 0x3f08, 0x3f09, 0x3f0a, 0x3f0b, 0x3f0c, 0x3f0d, 0x3f0e,
- 0x3f0f, 0x3f10, 0x3f11, 0x3f12, 0x3f13, 0x3f14, 0x3f15, 0x3f16,
- 0x3f17, 0x3f18, 0x3f19, 0x3f1a, 0x3f1b, 0x3f1c, 0x3f1d, 0x3f1e,
- 0x3f1f, 0x3f20, 0x3f21, 0x3f22, 0x3f23, 0x3f24, 0x3f25, 0x3f26,
- 0x3f27, 0x3f28, 0x3f29, 0x3f2a, 0x3f2b, 0x3f2c, 0x3f2d, 0x3f2e,
- 0x3f2f, 0x3f30, 0x3f31, 0x3f32, 0x3f33, 0x3f34, 0x3f35, 0x3f36,
- 0x3f37, 0x3f38, 0x3f39, 0x3f3a, 0x3f3b, 0x3f3c, 0x3f3d, 0x3f3e,
- 0x3f3f, 0x0f80, 0x0f81, 0x0f82, 0x0f83, 0x0f84, 0x0f85, 0x0f86,
- 0x0f87, 0x0f88, 0x0f89, 0x0f8a, 0x0f8b, 0x0f8c, 0x0f8d, 0x0f8e,
- 0x0f8f, 0x0f90, 0x0f91, 0x0f92, 0x0f93, 0x0f94, 0x0f95, 0x0f96,
- 0x0f97, 0x0f98, 0x0f99, 0x0f9a, 0x0f9b, 0x0f9c, 0x0f9d, 0x0f9e,
- 0x0f9f, 0x03c0, 0x03c1, 0x03c2, 0x03c3, 0x03c4, 0x03c5, 0x03c6,
- 0x03c7, 0x03c8, 0x03c9, 0x03ca, 0x03cb, 0x03cc, 0x03cd, 0x03ce,
- 0x03cf, 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6,
- 0x00e7, 0x0030, 0x0031, 0x0032, 0x0033, 0x0008, 0x0009, 0x0002,
- 0x0000, 0x0003, 0x000a, 0x000b, 0x0034, 0x0035, 0x0036, 0x0037,
- 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef,
- 0x03d0, 0x03d1, 0x03d2, 0x03d3, 0x03d4, 0x03d5, 0x03d6, 0x03d7,
- 0x03d8, 0x03d9, 0x03da, 0x03db, 0x03dc, 0x03dd, 0x03de, 0x03df,
- 0x0fa0, 0x0fa1, 0x0fa2, 0x0fa3, 0x0fa4, 0x0fa5, 0x0fa6, 0x0fa7,
- 0x0fa8, 0x0fa9, 0x0faa, 0x0fab, 0x0fac, 0x0fad, 0x0fae, 0x0faf,
- 0x0fb0, 0x0fb1, 0x0fb2, 0x0fb3, 0x0fb4, 0x0fb5, 0x0fb6, 0x0fb7,
- 0x0fb8, 0x0fb9, 0x0fba, 0x0fbb, 0x0fbc, 0x0fbd, 0x0fbe, 0x0fbf,
- 0x3f40, 0x3f41, 0x3f42, 0x3f43, 0x3f44, 0x3f45, 0x3f46, 0x3f47,
- 0x3f48, 0x3f49, 0x3f4a, 0x3f4b, 0x3f4c, 0x3f4d, 0x3f4e, 0x3f4f,
- 0x3f50, 0x3f51, 0x3f52, 0x3f53, 0x3f54, 0x3f55, 0x3f56, 0x3f57,
- 0x3f58, 0x3f59, 0x3f5a, 0x3f5b, 0x3f5c, 0x3f5d, 0x3f5e, 0x3f5f,
- 0x3f60, 0x3f61, 0x3f62, 0x3f63, 0x3f64, 0x3f65, 0x3f66, 0x3f67,
- 0x3f68, 0x3f69, 0x3f6a, 0x3f6b, 0x3f6c, 0x3f6d, 0x3f6e, 0x3f6f,
- 0x3f70, 0x3f71, 0x3f72, 0x3f73, 0x3f74, 0x3f75, 0x3f76, 0x3f77,
- 0x3f78, 0x3f79, 0x3f7a, 0x3f7b, 0x3f7c, 0x3f7d, 0x3f7e, 0x3f7f,
-};
-
-static const uint8_t rv_chrom_bits[256] =
-{
- 16, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 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, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 8, 8, 8, 8, 8, 8, 8,
- 8, 6, 6, 6, 6, 4, 4, 3,
- 2, 3, 4, 4, 6, 6, 6, 6,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 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,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
-};
-
-static VLC rv_dc_lum, rv_dc_chrom;
-
-int rv_decode_dc(MpegEncContext *s, int n)
-{
- int code;
-
- if (n < 4) {
- code = get_vlc2(&s->gb, rv_dc_lum.table, DC_VLC_BITS, 2);
- if (code < 0) {
- /* XXX: I don't understand why they use LONGER codes than
- necessary. The following code would be completely useless
- if they had thought about it !!! */
- code = get_bits(&s->gb, 7);
- if (code == 0x7c) {
- code = (int8_t)(get_bits(&s->gb, 7) + 1);
- } else if (code == 0x7d) {
- code = -128 + get_bits(&s->gb, 7);
- } else if (code == 0x7e) {
- if (get_bits(&s->gb, 1) == 0)
- code = (int8_t)(get_bits(&s->gb, 8) + 1);
- else
- code = (int8_t)(get_bits(&s->gb, 8));
- } else if (code == 0x7f) {
- get_bits(&s->gb, 11);
- code = 1;
- }
- } else {
- code -= 128;
- }
- } else {
- code = get_vlc2(&s->gb, rv_dc_chrom.table, DC_VLC_BITS, 2);
- /* same remark */
- if (code < 0) {
- code = get_bits(&s->gb, 9);
- if (code == 0x1fc) {
- code = (int8_t)(get_bits(&s->gb, 7) + 1);
- } else if (code == 0x1fd) {
- code = -128 + get_bits(&s->gb, 7);
- } else if (code == 0x1fe) {
- get_bits(&s->gb, 9);
- code = 1;
- } else {
- av_log(s->avctx, AV_LOG_ERROR, "chroma dc error\n");
- return 0xffff;
- }
- } else {
- code -= 128;
- }
- }
- return -code;
-}
-
-#ifdef CONFIG_ENCODERS
-
-/* write RV 1.0 compatible frame header */
-void rv10_encode_picture_header(MpegEncContext *s, int picture_number)
-{
- int full_frame= 0;
-
- align_put_bits(&s->pb);
-
- put_bits(&s->pb, 1, 1); /* marker */
-
- put_bits(&s->pb, 1, (s->pict_type == P_TYPE));
-
- put_bits(&s->pb, 1, 0); /* not PB frame */
-
- put_bits(&s->pb, 5, s->qscale);
-
- if (s->pict_type == I_TYPE) {
- /* specific MPEG like DC coding not used */
- }
- /* if multiple packets per frame are sent, the position at which
- to display the macro blocks is coded here */
- if(!full_frame){
- put_bits(&s->pb, 6, 0); /* mb_x */
- put_bits(&s->pb, 6, 0); /* mb_y */
- put_bits(&s->pb, 12, s->mb_width * s->mb_height);
- }
-
- put_bits(&s->pb, 3, 0); /* ignored */
-}
-
-void rv20_encode_picture_header(MpegEncContext *s, int picture_number){
- put_bits(&s->pb, 2, s->pict_type); //I 0 vs. 1 ?
- put_bits(&s->pb, 1, 0); /* unknown bit */
- put_bits(&s->pb, 5, s->qscale);
-
- put_bits(&s->pb, 8, picture_number&0xFF); //FIXME wrong, but correct is not known
- s->mb_x= s->mb_y= 0;
- ff_h263_encode_mba(s);
-
- put_bits(&s->pb, 1, s->no_rounding);
-
- assert(s->f_code == 1);
- assert(s->unrestricted_mv == 1);
-// assert(s->h263_aic== (s->pict_type == I_TYPE));
- assert(s->alt_inter_vlc == 0);
- assert(s->umvplus == 0);
- assert(s->modified_quant==1);
- assert(s->loop_filter==1);
-
- s->h263_aic= s->pict_type == I_TYPE;
- 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 0 /* unused, remove? */
-static int get_num(GetBitContext *gb)
-{
- int n, n1;
-
- n = get_bits(gb, 16);
- if (n >= 0x4000) {
- return n - 0x4000;
- } else {
- n1 = get_bits(gb, 16);
- return (n << 16) | n1;
- }
-}
-#endif
-
-#endif //CONFIG_ENCODERS
-
-/* read RV 1.0 compatible frame header */
-static int rv10_decode_picture_header(MpegEncContext *s)
-{
- int mb_count, pb_frame, marker, unk, mb_xy;
-
-//printf("ff:%d\n", full_frame);
- marker = get_bits(&s->gb, 1);
-
- if (get_bits(&s->gb, 1))
- s->pict_type = P_TYPE;
- else
- s->pict_type = I_TYPE;
-//printf("h:%X ver:%d\n",h,s->rv10_version);
- if(!marker) av_log(s->avctx, AV_LOG_ERROR, "marker missing\n");
- pb_frame = get_bits(&s->gb, 1);
-
-#ifdef DEBUG
- av_log(s->avctx, AV_LOG_DEBUG, "pict_type=%d pb_frame=%d\n", s->pict_type, pb_frame);
-#endif
-
- if (pb_frame){
- av_log(s->avctx, AV_LOG_ERROR, "pb frame not supported\n");
- return -1;
- }
-
- s->qscale = get_bits(&s->gb, 5);
- if(s->qscale==0){
- av_log(s->avctx, AV_LOG_ERROR, "error, qscale:0\n");
- return -1;
- }
-
- if (s->pict_type == I_TYPE) {
- if (s->rv10_version == 3) {
- /* specific MPEG like DC coding not used */
- s->last_dc[0] = get_bits(&s->gb, 8);
- s->last_dc[1] = get_bits(&s->gb, 8);
- s->last_dc[2] = get_bits(&s->gb, 8);
-#ifdef DEBUG
- av_log(s->avctx, AV_LOG_DEBUG, "DC:%d %d %d\n",
- s->last_dc[0],
- s->last_dc[1],
- s->last_dc[2]);
-#endif
- }
- }
- /* if multiple packets per frame are sent, the position at which
- to display the macro blocks is coded here */
-
- mb_xy= s->mb_x + s->mb_y*s->mb_width;
- if(show_bits(&s->gb, 12)==0 || (mb_xy && mb_xy < s->mb_num)){
- s->mb_x = get_bits(&s->gb, 6); /* mb_x */
- s->mb_y = get_bits(&s->gb, 6); /* mb_y */
- mb_count = get_bits(&s->gb, 12);
- } else {
- s->mb_x = 0;
- s->mb_y = 0;
- mb_count = s->mb_width * s->mb_height;
- }
- unk= get_bits(&s->gb, 3); /* ignored */
-//printf("%d\n", unk);
- s->f_code = 1;
- s->unrestricted_mv = 1;
-
- return mb_count;
-}
-
-static int rv20_decode_picture_header(MpegEncContext *s)
-{
- int seq, mb_pos, i;
-
-#if 0
- GetBitContext gb= s->gb;
- for(i=0; i<64; i++){
- av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&gb));
- if(i%4==3) av_log(s->avctx, AV_LOG_DEBUG, " ");
- }
- av_log(s->avctx, AV_LOG_DEBUG, "\n");
-#endif
-#if 0
- av_log(s->avctx, AV_LOG_DEBUG, "%3dx%03d/%02Xx%02X ", s->width, s->height, s->width/4, s->height/4);
- for(i=0; i<s->avctx->extradata_size; i++){
- av_log(s->avctx, AV_LOG_DEBUG, "%02X ", ((uint8_t*)s->avctx->extradata)[i]);
- if(i%4==3) av_log(s->avctx, AV_LOG_DEBUG, " ");
- }
- av_log(s->avctx, AV_LOG_DEBUG, "\n");
-#endif
-
- if(s->avctx->sub_id == 0x30202002 || s->avctx->sub_id == 0x30203002){
- if (get_bits(&s->gb, 3)){
- av_log(s->avctx, AV_LOG_ERROR, "unknown triplet set\n");
- return -1;
- }
- }
-
- i= get_bits(&s->gb, 2);
- switch(i){
- case 0: s->pict_type= I_TYPE; break;
- case 1: s->pict_type= I_TYPE; break; //hmm ...
- case 2: s->pict_type= P_TYPE; break;
- case 3: s->pict_type= B_TYPE; break;
- default:
- av_log(s->avctx, AV_LOG_ERROR, "unknown frame type\n");
- return -1;
- }
-
- if(s->last_picture_ptr==NULL && s->pict_type==B_TYPE){
- av_log(s->avctx, AV_LOG_ERROR, "early B pix\n");
- return -1;
- }
-
- if (get_bits(&s->gb, 1)){
- av_log(s->avctx, AV_LOG_ERROR, "unknown bit set\n");
- return -1;
- }
-
- s->qscale = get_bits(&s->gb, 5);
- if(s->qscale==0){
- av_log(s->avctx, AV_LOG_ERROR, "error, qscale:0\n");
- return -1;
- }
- if(s->avctx->sub_id == 0x30203002){
- if (get_bits(&s->gb, 1)){
- av_log(s->avctx, AV_LOG_ERROR, "unknown bit2 set\n");
- return -1;
- }
- }
-
- if(s->avctx->has_b_frames){
- int f, new_w, new_h;
- int v= s->avctx->extradata_size >= 4 ? 7&((uint8_t*)s->avctx->extradata)[1] : 0;
-
- if (get_bits(&s->gb, 1)){
- av_log(s->avctx, AV_LOG_ERROR, "unknown bit3 set\n");
-// return -1;
- }
- seq= get_bits(&s->gb, 13)<<2;
-
- f= get_bits(&s->gb, av_log2(v)+1);
-
- if(f){
- 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;
- }
- 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);
- MPV_common_end(s);
- s->width = s->avctx->width = new_w;
- s->height = s->avctx->height= new_h;
- if (MPV_common_init(s) < 0)
- return -1;
- }
-
- if(s->avctx->debug & FF_DEBUG_PICT_INFO){
- av_log(s->avctx, AV_LOG_DEBUG, "F %d/%d\n", f, v);
- }
- }else{
- seq= get_bits(&s->gb, 8)*128;
- }
-
-// if(s->avctx->sub_id <= 0x20201002){ //0x20201002 definitely needs this
- mb_pos= ff_h263_decode_mba(s);
-/* }else{
- mb_pos= get_bits(&s->gb, av_log2(s->mb_num-1)+1);
- s->mb_x= mb_pos % s->mb_width;
- s->mb_y= mb_pos / s->mb_width;
- }*/
-//av_log(s->avctx, AV_LOG_DEBUG, "%d\n", seq);
- seq |= s->time &~0x7FFF;
- if(seq - s->time > 0x4000) seq -= 0x8000;
- if(seq - s->time < -0x4000) seq += 0x8000;
- if(seq != s->time){
- if(s->pict_type!=B_TYPE){
- s->time= seq;
- s->pp_time= s->time - s->last_non_b_time;
- s->last_non_b_time= s->time;
- }else{
- s->time= seq;
- 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){
- av_log(s->avctx, AV_LOG_DEBUG, "messed up order, possible from seeking? skipping current b frame\n");
- return FRAME_SKIPPED;
- }
- ff_mpeg4_init_direct_mv(s);
- }
- }
-// printf("%d %d %d %d %d\n", seq, (int)s->time, (int)s->last_non_b_time, s->pp_time, s->pb_time);
-/*for(i=0; i<32; i++){
- av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb));
-}
-av_log(s->avctx, AV_LOG_DEBUG, "\n");*/
- s->no_rounding= get_bits1(&s->gb);
-
- s->f_code = 1;
- s->unrestricted_mv = 1;
- s->h263_aic= s->pict_type == I_TYPE;
-// s->alt_inter_vlc=1;
-// s->obmc=1;
-// s->umvplus=1;
- s->modified_quant=1;
- s->loop_filter=1;
-
- if(s->avctx->debug & FF_DEBUG_PICT_INFO){
- av_log(s->avctx, AV_LOG_INFO, "num:%5d x:%2d y:%2d type:%d qscale:%2d rnd:%d\n",
- seq, s->mb_x, s->mb_y, s->pict_type, s->qscale, s->no_rounding);
- }
-
- assert(s->pict_type != B_TYPE || !s->low_delay);
-
- return s->mb_width*s->mb_height - mb_pos;
-}
-
-static int rv10_decode_init(AVCodecContext *avctx)
-{
- MpegEncContext *s = avctx->priv_data;
- static int done=0;
-
- MPV_decode_defaults(s);
-
- s->avctx= avctx;
- s->out_format = FMT_H263;
- s->codec_id= avctx->codec_id;
-
- s->width = avctx->width;
- s->height = avctx->height;
-
- s->h263_long_vectors= ((uint8_t*)avctx->extradata)[3] & 1;
- avctx->sub_id= AV_RB32((uint8_t*)avctx->extradata + 4);
-
- switch(avctx->sub_id){
- case 0x10000000:
- s->rv10_version= 0;
- s->low_delay=1;
- break;
- case 0x10002000:
- s->rv10_version= 3;
- s->low_delay=1;
- s->obmc=1;
- break;
- case 0x10003000:
- s->rv10_version= 3;
- s->low_delay=1;
- break;
- case 0x10003001:
- s->rv10_version= 3;
- s->low_delay=1;
- break;
- case 0x20001000: /* real rv20 decoder fail on this id */
- /*case 0x20100001:
- case 0x20101001:
- case 0x20103001:*/
- case 0x20100000 ... 0x2019ffff:
- s->low_delay=1;
- break;
- /*case 0x20200002:
- case 0x20201002:
- case 0x20203002:*/
- case 0x20200002 ... 0x202fffff:
- case 0x30202002:
- case 0x30203002:
- s->low_delay=0;
- s->avctx->has_b_frames=1;
- break;
- default:
- av_log(s->avctx, AV_LOG_ERROR, "unknown header %X\n", avctx->sub_id);
- }
-
- if(avctx->debug & FF_DEBUG_PICT_INFO){
- av_log(avctx, AV_LOG_DEBUG, "ver:%X ver0:%X\n", avctx->sub_id, avctx->extradata_size >= 4 ? ((uint32_t*)avctx->extradata)[0] : -1);
- }
-
- avctx->pix_fmt = PIX_FMT_YUV420P;
-
- if (MPV_common_init(s) < 0)
- return -1;
-
- h263_decode_init_vlc(s);
-
- /* init rv vlc */
- if (!done) {
- init_vlc(&rv_dc_lum, DC_VLC_BITS, 256,
- rv_lum_bits, 1, 1,
- rv_lum_code, 2, 2, 1);
- init_vlc(&rv_dc_chrom, DC_VLC_BITS, 256,
- rv_chrom_bits, 1, 1,
- rv_chrom_code, 2, 2, 1);
- done = 1;
- }
-
- return 0;
-}
-
-static int rv10_decode_end(AVCodecContext *avctx)
-{
- MpegEncContext *s = avctx->priv_data;
-
- MPV_common_end(s);
- return 0;
-}
-
-static int rv10_decode_packet(AVCodecContext *avctx,
- uint8_t *buf, int buf_size)
-{
- MpegEncContext *s = avctx->priv_data;
- int mb_count, mb_pos, left, start_mb_x;
-
- init_get_bits(&s->gb, buf, buf_size*8);
- if(s->codec_id ==CODEC_ID_RV10)
- mb_count = rv10_decode_picture_header(s);
- else
- mb_count = rv20_decode_picture_header(s);
- if (mb_count < 0) {
- av_log(s->avctx, AV_LOG_ERROR, "HEADER ERROR\n");
- return -1;
- }
-
- if (s->mb_x >= s->mb_width ||
- s->mb_y >= s->mb_height) {
- av_log(s->avctx, AV_LOG_ERROR, "POS ERROR %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- mb_pos = s->mb_y * s->mb_width + s->mb_x;
- left = s->mb_width * s->mb_height - mb_pos;
- if (mb_count > left) {
- av_log(s->avctx, AV_LOG_ERROR, "COUNT ERROR\n");
- return -1;
- }
-//if(s->pict_type == P_TYPE) return 0;
-
- if ((s->mb_x == 0 && s->mb_y == 0) || s->current_picture_ptr==NULL) {
- if(s->current_picture_ptr){ //FIXME write parser so we always have complete frames?
- ff_er_frame_end(s);
- MPV_frame_end(s);
- s->mb_x= s->mb_y = s->resync_mb_x = s->resync_mb_y= 0;
- }
- if(MPV_frame_start(s, avctx) < 0)
- return -1;
- ff_er_frame_start(s);
- }
-
-#ifdef DEBUG
- av_log(avctx, AV_LOG_DEBUG, "qscale=%d\n", s->qscale);
-#endif
-
- /* default quantization values */
- if(s->codec_id== CODEC_ID_RV10){
- if(s->mb_y==0) s->first_slice_line=1;
- }else{
- s->first_slice_line=1;
- s->resync_mb_x= s->mb_x;
- }
- start_mb_x= s->mb_x;
- s->resync_mb_y= s->mb_y;
- 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->modified_quant)
- s->chroma_qscale_table= ff_h263_chroma_qscale_table;
-
- ff_set_qscale(s, s->qscale);
-
- s->rv10_first_dc_coded[0] = 0;
- s->rv10_first_dc_coded[1] = 0;
- s->rv10_first_dc_coded[2] = 0;
-//printf("%d %X %X\n", s->pict_type, s->current_picture.motion_val[0], s->current_picture.motion_val[1]);
- s->block_wrap[0]=
- s->block_wrap[1]=
- s->block_wrap[2]=
- s->block_wrap[3]= s->b8_stride;
- s->block_wrap[4]=
- s->block_wrap[5]= s->mb_stride;
- ff_init_block_index(s);
- /* decode each macroblock */
-
- for(s->mb_num_left= mb_count; s->mb_num_left>0; s->mb_num_left--) {
- int ret;
- ff_update_block_index(s);
-#ifdef DEBUG
- av_log(avctx, AV_LOG_DEBUG, "**mb x=%d y=%d\n", s->mb_x, s->mb_y);
-#endif
-
- s->mv_dir = MV_DIR_FORWARD;
- 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)) {
- av_log(s->avctx, AV_LOG_ERROR, "ERROR at MB %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- if(s->pict_type != B_TYPE)
- ff_h263_update_motion_val(s);
- MPV_decode_mb(s, s->block);
- if(s->loop_filter)
- ff_h263_loop_filter(s);
-
- if (++s->mb_x == s->mb_width) {
- s->mb_x = 0;
- s->mb_y++;
- ff_init_block_index(s);
- }
- if(s->mb_x == s->resync_mb_x)
- s->first_slice_line=0;
- if(ret == SLICE_END) break;
- }
-
- 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;
-}
-
-static int rv10_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- MpegEncContext *s = avctx->priv_data;
- int i;
- AVFrame *pict = data;
-
-#ifdef DEBUG
- av_log(avctx, AV_LOG_DEBUG, "*****frame %d size=%d\n", avctx->frame_number, buf_size);
-#endif
-
- /* no supplementary picture */
- if (buf_size == 0) {
- return 0;
- }
-
- if(avctx->slice_count){
- for(i=0; i<avctx->slice_count; i++){
- int offset= avctx->slice_offset[i];
- int size;
-
- if(i+1 == avctx->slice_count)
- size= buf_size - offset;
- else
- size= avctx->slice_offset[i+1] - offset;
-
- rv10_decode_packet(avctx, buf+offset, size);
- }
- }else{
- rv10_decode_packet(avctx, buf, buf_size);
- }
-
- if(s->current_picture_ptr != NULL && s->mb_y>=s->mb_height){
- ff_er_frame_end(s);
- MPV_frame_end(s);
-
- if (s->pict_type == B_TYPE || s->low_delay) {
- *pict= *(AVFrame*)s->current_picture_ptr;
- } else if (s->last_picture_ptr != NULL) {
- *pict= *(AVFrame*)s->last_picture_ptr;
- }
-
- if(s->last_picture_ptr || s->low_delay){
- *data_size = sizeof(AVFrame);
- ff_print_debug_info(s, pict);
- }
- s->current_picture_ptr= NULL; //so we can detect if frame_end wasnt called (find some nicer solution...)
- }
-
- return buf_size;
-}
-
-AVCodec rv10_decoder = {
- "rv10",
- CODEC_TYPE_VIDEO,
- CODEC_ID_RV10,
- sizeof(MpegEncContext),
- rv10_decode_init,
- NULL,
- rv10_decode_end,
- rv10_decode_frame,
- CODEC_CAP_DR1
-};
-
-AVCodec rv20_decoder = {
- "rv20",
- CODEC_TYPE_VIDEO,
- CODEC_ID_RV20,
- sizeof(MpegEncContext),
- rv10_decode_init,
- NULL,
- rv10_decode_end,
- rv10_decode_frame,
- CODEC_CAP_DR1 | CODEC_CAP_DELAY,
- .flush= ff_mpeg_flush,
-};
-
diff --git a/src/libffmpeg/libavcodec/shorten.c b/src/libffmpeg/libavcodec/shorten.c
deleted file mode 100644
index 358ecf23f..000000000
--- a/src/libffmpeg/libavcodec/shorten.c
+++ /dev/null
@@ -1,533 +0,0 @@
-/*
- * Shorten decoder
- * Copyright (c) 2005 Jeff Muizelaar
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General 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 shorten.c
- * Shorten decoder
- * @author Jeff Muizelaar
- *
- */
-
-#define DEBUG
-#include <limits.h>
-#include "avcodec.h"
-#include "bitstream.h"
-#include "golomb.h"
-
-#define MAX_CHANNELS 8
-#define MAX_BLOCKSIZE 65535
-
-#define OUT_BUFFER_SIZE 16384
-
-#define ULONGSIZE 2
-
-#define WAVE_FORMAT_PCM 0x0001
-
-#define DEFAULT_BLOCK_SIZE 256
-
-#define TYPESIZE 4
-#define CHANSIZE 0
-#define LPCQSIZE 2
-#define ENERGYSIZE 3
-#define BITSHIFTSIZE 2
-
-#define TYPE_S16HL 3
-#define TYPE_S16LH 5
-
-#define NWRAP 3
-#define NSKIPSIZE 1
-
-#define LPCQUANT 5
-#define V2LPCQOFFSET (1 << LPCQUANT)
-
-#define FNSIZE 2
-#define FN_DIFF0 0
-#define FN_DIFF1 1
-#define FN_DIFF2 2
-#define FN_DIFF3 3
-#define FN_QUIT 4
-#define FN_BLOCKSIZE 5
-#define FN_BITSHIFT 6
-#define FN_QLPC 7
-#define FN_ZERO 8
-#define FN_VERBATIM 9
-
-#define VERBATIM_CKSIZE_SIZE 5
-#define VERBATIM_BYTE_SIZE 8
-#define CANONICAL_HEADER_SIZE 44
-
-typedef struct ShortenContext {
- AVCodecContext *avctx;
- GetBitContext gb;
-
- int min_framesize, max_framesize;
- int channels;
-
- int32_t *decoded[MAX_CHANNELS];
- int32_t *offset[MAX_CHANNELS];
- uint8_t *bitstream;
- int bitstream_size;
- int bitstream_index;
- unsigned int allocated_bitstream_size;
- int header_size;
- uint8_t header[OUT_BUFFER_SIZE];
- int version;
- int cur_chan;
- int bitshift;
- int nmean;
- int internal_ftype;
- int nwrap;
- int blocksize;
- int bitindex;
- int32_t lpcqoffset;
-} ShortenContext;
-
-static int shorten_decode_init(AVCodecContext * avctx)
-{
- ShortenContext *s = avctx->priv_data;
- s->avctx = avctx;
-
- return 0;
-}
-
-static int allocate_buffers(ShortenContext *s)
-{
- int i, chan;
- for (chan=0; chan<s->channels; chan++) {
- if(FFMAX(1, s->nmean) >= UINT_MAX/sizeof(int32_t)){
- av_log(s->avctx, AV_LOG_ERROR, "nmean too large\n");
- return -1;
- }
- if(s->blocksize + s->nwrap >= UINT_MAX/sizeof(int32_t) || s->blocksize + s->nwrap <= (unsigned)s->nwrap){
- av_log(s->avctx, AV_LOG_ERROR, "s->blocksize + s->nwrap too large\n");
- return -1;
- }
-
- s->offset[chan] = av_realloc(s->offset[chan], sizeof(int32_t)*FFMAX(1, s->nmean));
-
- s->decoded[chan] = av_realloc(s->decoded[chan], sizeof(int32_t)*(s->blocksize + s->nwrap));
- for (i=0; i<s->nwrap; i++)
- s->decoded[chan][i] = 0;
- s->decoded[chan] += s->nwrap;
- }
- return 0;
-}
-
-
-static inline unsigned int get_uint(ShortenContext *s, int k)
-{
- if (s->version != 0)
- k = get_ur_golomb_shorten(&s->gb, ULONGSIZE);
- return get_ur_golomb_shorten(&s->gb, k);
-}
-
-
-static void fix_bitshift(ShortenContext *s, int32_t *buffer)
-{
- int i;
-
- if (s->bitshift != 0)
- for (i = 0; i < s->blocksize; i++)
- buffer[s->nwrap + i] <<= s->bitshift;
-}
-
-
-static void init_offset(ShortenContext *s)
-{
- int32_t mean = 0;
- int chan, i;
- int nblock = FFMAX(1, s->nmean);
- /* initialise offset */
- switch (s->internal_ftype)
- {
- case TYPE_S16HL:
- case TYPE_S16LH:
- mean = 0;
- break;
- default:
- av_log(s->avctx, AV_LOG_ERROR, "unknown audio type");
- abort();
- }
-
- for (chan = 0; chan < s->channels; chan++)
- for (i = 0; i < nblock; i++)
- s->offset[chan][i] = mean;
-}
-
-static int inline get_le32(GetBitContext *gb)
-{
- return bswap_32(get_bits_long(gb, 32));
-}
-
-static short inline get_le16(GetBitContext *gb)
-{
- return bswap_16(get_bits_long(gb, 16));
-}
-
-static int decode_wave_header(AVCodecContext *avctx, uint8_t *header, int header_size)
-{
- GetBitContext hb;
- int len;
- int chunk_size;
- short wave_format;
-
- init_get_bits(&hb, header, header_size*8);
- if (get_le32(&hb) != MKTAG('R','I','F','F')) {
- av_log(avctx, AV_LOG_ERROR, "missing RIFF tag\n");
- return -1;
- }
-
- chunk_size = get_le32(&hb);
-
- if (get_le32(&hb) != MKTAG('W','A','V','E')) {
- av_log(avctx, AV_LOG_ERROR, "missing WAVE tag\n");
- return -1;
- }
-
- while (get_le32(&hb) != MKTAG('f','m','t',' ')) {
- len = get_le32(&hb);
- skip_bits(&hb, 8*len);
- }
- len = get_le32(&hb);
-
- if (len < 16) {
- av_log(avctx, AV_LOG_ERROR, "fmt chunk was too short\n");
- return -1;
- }
-
- wave_format = get_le16(&hb);
-
- switch (wave_format) {
- case WAVE_FORMAT_PCM:
- break;
- default:
- av_log(avctx, AV_LOG_ERROR, "unsupported wave format\n");
- return -1;
- }
-
- avctx->channels = get_le16(&hb);
- avctx->sample_rate = get_le32(&hb);
- avctx->bit_rate = get_le32(&hb) * 8;
- avctx->block_align = get_le16(&hb);
- avctx->bits_per_sample = get_le16(&hb);
-
- if (avctx->bits_per_sample != 16) {
- av_log(avctx, AV_LOG_ERROR, "unsupported number of bits per sample\n");
- return -1;
- }
-
- len -= 16;
- if (len > 0)
- av_log(avctx, AV_LOG_INFO, "%d header bytes unparsed\n", len);
-
- return 0;
-}
-
-static int16_t * interleave_buffer(int16_t *samples, int nchan, int blocksize, int32_t **buffer) {
- int i, chan;
- for (i=0; i<blocksize; i++)
- for (chan=0; chan < nchan; chan++)
- *samples++ = FFMIN(buffer[chan][i], 32768);
- return samples;
-}
-
-static void decode_subframe_lpc(ShortenContext *s, int channel, int residual_size, int pred_order)
-{
- int sum, i, j;
- int coeffs[pred_order];
-
- for (i=0; i<pred_order; i++)
- coeffs[i] = get_sr_golomb_shorten(&s->gb, LPCQUANT);
-
- for (i=0; i < s->blocksize; i++) {
- sum = s->lpcqoffset;
- for (j=0; j<pred_order; j++)
- sum += coeffs[j] * s->decoded[channel][i-j-1];
- s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + (sum >> LPCQUANT);
- }
-}
-
-
-static int shorten_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- ShortenContext *s = avctx->priv_data;
- int i, input_buf_size = 0;
- int16_t *samples = data;
- if(s->max_framesize == 0){
- s->max_framesize= 1024; // should hopefully be enough for the first header
- s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->max_framesize);
- }
-
- if(1 && s->max_framesize){//FIXME truncated
- buf_size= FFMIN(buf_size, s->max_framesize - s->bitstream_size);
- input_buf_size= buf_size;
-
- if(s->bitstream_index + s->bitstream_size + buf_size > s->allocated_bitstream_size){
- // printf("memmove\n");
- memmove(s->bitstream, &s->bitstream[s->bitstream_index], s->bitstream_size);
- s->bitstream_index=0;
- }
- memcpy(&s->bitstream[s->bitstream_index + s->bitstream_size], buf, buf_size);
- buf= &s->bitstream[s->bitstream_index];
- buf_size += s->bitstream_size;
- s->bitstream_size= buf_size;
-
- if(buf_size < s->max_framesize){
- //dprintf("wanna more data ... %d\n", buf_size);
- return input_buf_size;
- }
- }
- init_get_bits(&s->gb, buf, buf_size*8);
- get_bits(&s->gb, s->bitindex);
- if (!s->blocksize)
- {
- int maxnlpc = 0;
- /* shorten signature */
- if (get_bits_long(&s->gb, 32) != bswap_32(ff_get_fourcc("ajkg"))) {
- av_log(s->avctx, AV_LOG_ERROR, "missing shorten magic 'ajkg'\n");
- return -1;
- }
-
- s->lpcqoffset = 0;
- s->blocksize = DEFAULT_BLOCK_SIZE;
- s->channels = 1;
- s->nmean = -1;
- s->version = get_bits(&s->gb, 8);
- s->internal_ftype = get_uint(s, TYPESIZE);
-
- s->channels = get_uint(s, CHANSIZE);
- if (s->channels > MAX_CHANNELS) {
- av_log(s->avctx, AV_LOG_ERROR, "too many channels: %d\n", s->channels);
- return -1;
- }
-
- /* get blocksize if version > 0 */
- if (s->version > 0) {
- int skip_bytes;
- s->blocksize = get_uint(s, av_log2(DEFAULT_BLOCK_SIZE));
- maxnlpc = get_uint(s, LPCQSIZE);
- s->nmean = get_uint(s, 0);
-
- skip_bytes = get_uint(s, NSKIPSIZE);
- for (i=0; i<skip_bytes; i++) {
- skip_bits(&s->gb, 8);
- }
- }
- s->nwrap = FFMAX(NWRAP, maxnlpc);
-
- if (allocate_buffers(s))
- return -1;
-
- init_offset(s);
-
- if (s->version > 1)
- s->lpcqoffset = V2LPCQOFFSET;
-
- if (get_ur_golomb_shorten(&s->gb, FNSIZE) != FN_VERBATIM) {
- av_log(s->avctx, AV_LOG_ERROR, "missing verbatim section at begining of stream\n");
- return -1;
- }
-
- s->header_size = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE);
- if (s->header_size >= OUT_BUFFER_SIZE || s->header_size < CANONICAL_HEADER_SIZE) {
- av_log(s->avctx, AV_LOG_ERROR, "header is wrong size: %d\n", s->header_size);
- return -1;
- }
-
- for (i=0; i<s->header_size; i++)
- s->header[i] = (char)get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE);
-
- if (decode_wave_header(avctx, s->header, s->header_size) < 0)
- return -1;
-
- s->cur_chan = 0;
- s->bitshift = 0;
- }
- else
- {
- int cmd;
- int len;
- cmd = get_ur_golomb_shorten(&s->gb, FNSIZE);
- switch (cmd) {
- case FN_ZERO:
- case FN_DIFF0:
- case FN_DIFF1:
- case FN_DIFF2:
- case FN_DIFF3:
- case FN_QLPC:
- {
- int residual_size = 0;
- int channel = s->cur_chan;
- int32_t coffset;
- if (cmd != FN_ZERO) {
- residual_size = get_ur_golomb_shorten(&s->gb, ENERGYSIZE);
- /* this is a hack as version 0 differed in defintion of get_sr_golomb_shorten */
- if (s->version == 0)
- residual_size--;
- }
-
- if (s->nmean == 0)
- coffset = s->offset[channel][0];
- else {
- int32_t sum = (s->version < 2) ? 0 : s->nmean / 2;
- for (i=0; i<s->nmean; i++)
- sum += s->offset[channel][i];
- coffset = sum / s->nmean;
- if (s->version >= 2)
- coffset >>= FFMIN(1, s->bitshift);
- }
- switch (cmd) {
- case FN_ZERO:
- for (i=0; i<s->blocksize; i++)
- s->decoded[channel][i] = 0;
- break;
- case FN_DIFF0:
- for (i=0; i<s->blocksize; i++)
- s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + coffset;
- break;
- case FN_DIFF1:
- for (i=0; i<s->blocksize; i++)
- s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + s->decoded[channel][i - 1];
- break;
- case FN_DIFF2:
- for (i=0; i<s->blocksize; i++)
- s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + 2*s->decoded[channel][i-1]
- - s->decoded[channel][i-2];
- break;
- case FN_DIFF3:
- for (i=0; i<s->blocksize; i++)
- s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + 3*s->decoded[channel][i-1]
- - 3*s->decoded[channel][i-2]
- + s->decoded[channel][i-3];
- break;
- case FN_QLPC:
- {
- int pred_order = get_ur_golomb_shorten(&s->gb, LPCQSIZE);
- for (i=0; i<pred_order; i++)
- s->decoded[channel][i - pred_order] -= coffset;
- decode_subframe_lpc(s, channel, residual_size, pred_order);
- if (coffset != 0)
- for (i=0; i < s->blocksize; i++)
- s->decoded[channel][i] += coffset;
- }
- }
- if (s->nmean > 0) {
- int32_t sum = (s->version < 2) ? 0 : s->blocksize / 2;
- for (i=0; i<s->blocksize; i++)
- sum += s->decoded[channel][i];
-
- for (i=1; i<s->nmean; i++)
- s->offset[channel][i-1] = s->offset[channel][i];
-
- if (s->version < 2)
- s->offset[channel][s->nmean - 1] = sum / s->blocksize;
- else
- s->offset[channel][s->nmean - 1] = (sum / s->blocksize) << s->bitshift;
- }
- for (i=-s->nwrap; i<0; i++)
- s->decoded[channel][i] = s->decoded[channel][i + s->blocksize];
-
- fix_bitshift(s, s->decoded[channel]);
-
- s->cur_chan++;
- if (s->cur_chan == s->channels) {
- samples = interleave_buffer(samples, s->channels, s->blocksize, s->decoded);
- s->cur_chan = 0;
- goto frame_done;
- }
- break;
- }
- break;
- case FN_VERBATIM:
- len = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE);
- while (len--) {
- get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE);
- }
- break;
- case FN_BITSHIFT:
- s->bitshift = get_ur_golomb_shorten(&s->gb, BITSHIFTSIZE);
- break;
- case FN_BLOCKSIZE:
- s->blocksize = get_uint(s, av_log2(s->blocksize));
- break;
- case FN_QUIT:
- return buf_size;
- break;
- default:
- av_log(avctx, AV_LOG_ERROR, "unknown shorten function %d\n", cmd);
- return -1;
- break;
- }
- }
-frame_done:
- *data_size = (int8_t *)samples - (int8_t *)data;
-
- // s->last_blocksize = s->blocksize;
- s->bitindex = get_bits_count(&s->gb) - 8*((get_bits_count(&s->gb))/8);
- i= (get_bits_count(&s->gb))/8;
- if (i > buf_size) {
- av_log(s->avctx, AV_LOG_ERROR, "overread: %d\n", i - buf_size);
- s->bitstream_size=0;
- s->bitstream_index=0;
- return -1;
- }
- if (s->bitstream_size) {
- s->bitstream_index += i;
- s->bitstream_size -= i;
- return input_buf_size;
- } else
- return i;
-}
-
-static int shorten_decode_close(AVCodecContext *avctx)
-{
- ShortenContext *s = avctx->priv_data;
- int i;
-
- for (i = 0; i < s->channels; i++) {
- s->decoded[i] -= s->nwrap;
- av_freep(&s->decoded[i]);
- av_freep(&s->offset[i]);
- }
- av_freep(&s->bitstream);
- return 0;
-}
-
-static void shorten_flush(AVCodecContext *avctx){
- ShortenContext *s = avctx->priv_data;
-
- s->bitstream_size=
- s->bitstream_index= 0;
-}
-
-AVCodec shorten_decoder = {
- "shorten",
- CODEC_TYPE_AUDIO,
- CODEC_ID_SHORTEN,
- sizeof(ShortenContext),
- shorten_decode_init,
- NULL,
- shorten_decode_close,
- shorten_decode_frame,
- .flush= shorten_flush,
-};
diff --git a/src/libffmpeg/libavcodec/simple_idct.c b/src/libffmpeg/libavcodec/simple_idct.c
deleted file mode 100644
index 2c026f08f..000000000
--- a/src/libffmpeg/libavcodec/simple_idct.c
+++ /dev/null
@@ -1,587 +0,0 @@
-/*
- * Simple IDCT
- *
- * Copyright (c) 2001 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/**
- * @file simple_idct.c
- * simpleidct in C.
- */
-
-/*
- based upon some outcommented c code from mpeg2dec (idct_mmx.c
- written by Aaron Holtzman <aholtzma@ess.engr.uvic.ca>)
- */
-#include "avcodec.h"
-#include "dsputil.h"
-#include "simple_idct.h"
-
-#if 0
-#define W1 2841 /* 2048*sqrt (2)*cos (1*pi/16) */
-#define W2 2676 /* 2048*sqrt (2)*cos (2*pi/16) */
-#define W3 2408 /* 2048*sqrt (2)*cos (3*pi/16) */
-#define W4 2048 /* 2048*sqrt (2)*cos (4*pi/16) */
-#define W5 1609 /* 2048*sqrt (2)*cos (5*pi/16) */
-#define W6 1108 /* 2048*sqrt (2)*cos (6*pi/16) */
-#define W7 565 /* 2048*sqrt (2)*cos (7*pi/16) */
-#define ROW_SHIFT 8
-#define COL_SHIFT 17
-#else
-#define W1 22725 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-#define W2 21407 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-#define W3 19266 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-#define W4 16383 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-#define W5 12873 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-#define W6 8867 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-#define W7 4520 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-#define ROW_SHIFT 11
-#define COL_SHIFT 20 // 6
-#endif
-
-#if defined(ARCH_POWERPC_405)
-
-/* signed 16x16 -> 32 multiply add accumulate */
-#define MAC16(rt, ra, rb) \
- asm ("maclhw %0, %2, %3" : "=r" (rt) : "0" (rt), "r" (ra), "r" (rb));
-
-/* signed 16x16 -> 32 multiply */
-#define MUL16(rt, ra, rb) \
- asm ("mullhw %0, %1, %2" : "=r" (rt) : "r" (ra), "r" (rb));
-
-#else
-
-/* signed 16x16 -> 32 multiply add accumulate */
-#define MAC16(rt, ra, rb) rt += (ra) * (rb)
-
-/* signed 16x16 -> 32 multiply */
-#define MUL16(rt, ra, rb) rt = (ra) * (rb)
-
-#endif
-
-static inline void idctRowCondDC (DCTELEM * row)
-{
- int a0, a1, a2, a3, b0, b1, b2, b3;
-#ifdef FAST_64BIT
- uint64_t temp;
-#else
- uint32_t temp;
-#endif
-
-#ifdef FAST_64BIT
-#ifdef WORDS_BIGENDIAN
-#define ROW0_MASK 0xffff000000000000LL
-#else
-#define ROW0_MASK 0xffffLL
-#endif
- if(sizeof(DCTELEM)==2){
- if ( ((((uint64_t *)row)[0] & ~ROW0_MASK) |
- ((uint64_t *)row)[1]) == 0) {
- temp = (row[0] << 3) & 0xffff;
- temp += temp << 16;
- temp += temp << 32;
- ((uint64_t *)row)[0] = temp;
- ((uint64_t *)row)[1] = temp;
- return;
- }
- }else{
- if (!(row[1]|row[2]|row[3]|row[4]|row[5]|row[6]|row[7])) {
- row[0]=row[1]=row[2]=row[3]=row[4]=row[5]=row[6]=row[7]= row[0] << 3;
- return;
- }
- }
-#else
- if(sizeof(DCTELEM)==2){
- if (!(((uint32_t*)row)[1] |
- ((uint32_t*)row)[2] |
- ((uint32_t*)row)[3] |
- row[1])) {
- temp = (row[0] << 3) & 0xffff;
- temp += temp << 16;
- ((uint32_t*)row)[0]=((uint32_t*)row)[1] =
- ((uint32_t*)row)[2]=((uint32_t*)row)[3] = temp;
- return;
- }
- }else{
- if (!(row[1]|row[2]|row[3]|row[4]|row[5]|row[6]|row[7])) {
- row[0]=row[1]=row[2]=row[3]=row[4]=row[5]=row[6]=row[7]= row[0] << 3;
- return;
- }
- }
-#endif
-
- a0 = (W4 * row[0]) + (1 << (ROW_SHIFT - 1));
- a1 = a0;
- a2 = a0;
- a3 = a0;
-
- /* no need to optimize : gcc does it */
- a0 += W2 * row[2];
- a1 += W6 * row[2];
- a2 -= W6 * row[2];
- a3 -= W2 * row[2];
-
- MUL16(b0, W1, row[1]);
- MAC16(b0, W3, row[3]);
- MUL16(b1, W3, row[1]);
- MAC16(b1, -W7, row[3]);
- MUL16(b2, W5, row[1]);
- MAC16(b2, -W1, row[3]);
- MUL16(b3, W7, row[1]);
- MAC16(b3, -W5, row[3]);
-
-#ifdef FAST_64BIT
- temp = ((uint64_t*)row)[1];
-#else
- temp = ((uint32_t*)row)[2] | ((uint32_t*)row)[3];
-#endif
- if (temp != 0) {
- a0 += W4*row[4] + W6*row[6];
- a1 += - W4*row[4] - W2*row[6];
- a2 += - W4*row[4] + W2*row[6];
- a3 += W4*row[4] - W6*row[6];
-
- MAC16(b0, W5, row[5]);
- MAC16(b0, W7, row[7]);
-
- MAC16(b1, -W1, row[5]);
- MAC16(b1, -W5, row[7]);
-
- MAC16(b2, W7, row[5]);
- MAC16(b2, W3, row[7]);
-
- MAC16(b3, W3, row[5]);
- MAC16(b3, -W1, row[7]);
- }
-
- row[0] = (a0 + b0) >> ROW_SHIFT;
- row[7] = (a0 - b0) >> ROW_SHIFT;
- row[1] = (a1 + b1) >> ROW_SHIFT;
- row[6] = (a1 - b1) >> ROW_SHIFT;
- row[2] = (a2 + b2) >> ROW_SHIFT;
- row[5] = (a2 - b2) >> ROW_SHIFT;
- row[3] = (a3 + b3) >> ROW_SHIFT;
- row[4] = (a3 - b3) >> ROW_SHIFT;
-}
-
-static inline void idctSparseColPut (uint8_t *dest, int line_size,
- DCTELEM * col)
-{
- int a0, a1, a2, a3, b0, b1, b2, b3;
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
-
- /* XXX: I did that only to give same values as previous code */
- a0 = W4 * (col[8*0] + ((1<<(COL_SHIFT-1))/W4));
- a1 = a0;
- a2 = a0;
- a3 = a0;
-
- a0 += + W2*col[8*2];
- a1 += + W6*col[8*2];
- a2 += - W6*col[8*2];
- a3 += - W2*col[8*2];
-
- MUL16(b0, W1, col[8*1]);
- MUL16(b1, W3, col[8*1]);
- MUL16(b2, W5, col[8*1]);
- MUL16(b3, W7, col[8*1]);
-
- MAC16(b0, + W3, col[8*3]);
- MAC16(b1, - W7, col[8*3]);
- MAC16(b2, - W1, col[8*3]);
- MAC16(b3, - W5, col[8*3]);
-
- if(col[8*4]){
- a0 += + W4*col[8*4];
- a1 += - W4*col[8*4];
- a2 += - W4*col[8*4];
- a3 += + W4*col[8*4];
- }
-
- if (col[8*5]) {
- MAC16(b0, + W5, col[8*5]);
- MAC16(b1, - W1, col[8*5]);
- MAC16(b2, + W7, col[8*5]);
- MAC16(b3, + W3, col[8*5]);
- }
-
- if(col[8*6]){
- a0 += + W6*col[8*6];
- a1 += - W2*col[8*6];
- a2 += + W2*col[8*6];
- a3 += - W6*col[8*6];
- }
-
- if (col[8*7]) {
- MAC16(b0, + W7, col[8*7]);
- MAC16(b1, - W5, col[8*7]);
- MAC16(b2, + W3, col[8*7]);
- MAC16(b3, - W1, col[8*7]);
- }
-
- dest[0] = cm[(a0 + b0) >> COL_SHIFT];
- dest += line_size;
- dest[0] = cm[(a1 + b1) >> COL_SHIFT];
- dest += line_size;
- dest[0] = cm[(a2 + b2) >> COL_SHIFT];
- dest += line_size;
- dest[0] = cm[(a3 + b3) >> COL_SHIFT];
- dest += line_size;
- dest[0] = cm[(a3 - b3) >> COL_SHIFT];
- dest += line_size;
- dest[0] = cm[(a2 - b2) >> COL_SHIFT];
- dest += line_size;
- dest[0] = cm[(a1 - b1) >> COL_SHIFT];
- dest += line_size;
- dest[0] = cm[(a0 - b0) >> COL_SHIFT];
-}
-
-static inline void idctSparseColAdd (uint8_t *dest, int line_size,
- DCTELEM * col)
-{
- int a0, a1, a2, a3, b0, b1, b2, b3;
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
-
- /* XXX: I did that only to give same values as previous code */
- a0 = W4 * (col[8*0] + ((1<<(COL_SHIFT-1))/W4));
- a1 = a0;
- a2 = a0;
- a3 = a0;
-
- a0 += + W2*col[8*2];
- a1 += + W6*col[8*2];
- a2 += - W6*col[8*2];
- a3 += - W2*col[8*2];
-
- MUL16(b0, W1, col[8*1]);
- MUL16(b1, W3, col[8*1]);
- MUL16(b2, W5, col[8*1]);
- MUL16(b3, W7, col[8*1]);
-
- MAC16(b0, + W3, col[8*3]);
- MAC16(b1, - W7, col[8*3]);
- MAC16(b2, - W1, col[8*3]);
- MAC16(b3, - W5, col[8*3]);
-
- if(col[8*4]){
- a0 += + W4*col[8*4];
- a1 += - W4*col[8*4];
- a2 += - W4*col[8*4];
- a3 += + W4*col[8*4];
- }
-
- if (col[8*5]) {
- MAC16(b0, + W5, col[8*5]);
- MAC16(b1, - W1, col[8*5]);
- MAC16(b2, + W7, col[8*5]);
- MAC16(b3, + W3, col[8*5]);
- }
-
- if(col[8*6]){
- a0 += + W6*col[8*6];
- a1 += - W2*col[8*6];
- a2 += + W2*col[8*6];
- a3 += - W6*col[8*6];
- }
-
- if (col[8*7]) {
- MAC16(b0, + W7, col[8*7]);
- MAC16(b1, - W5, col[8*7]);
- MAC16(b2, + W3, col[8*7]);
- MAC16(b3, - W1, col[8*7]);
- }
-
- dest[0] = cm[dest[0] + ((a0 + b0) >> COL_SHIFT)];
- dest += line_size;
- dest[0] = cm[dest[0] + ((a1 + b1) >> COL_SHIFT)];
- dest += line_size;
- dest[0] = cm[dest[0] + ((a2 + b2) >> COL_SHIFT)];
- dest += line_size;
- dest[0] = cm[dest[0] + ((a3 + b3) >> COL_SHIFT)];
- dest += line_size;
- dest[0] = cm[dest[0] + ((a3 - b3) >> COL_SHIFT)];
- dest += line_size;
- dest[0] = cm[dest[0] + ((a2 - b2) >> COL_SHIFT)];
- dest += line_size;
- dest[0] = cm[dest[0] + ((a1 - b1) >> COL_SHIFT)];
- dest += line_size;
- dest[0] = cm[dest[0] + ((a0 - b0) >> COL_SHIFT)];
-}
-
-static inline void idctSparseCol (DCTELEM * col)
-{
- int a0, a1, a2, a3, b0, b1, b2, b3;
-
- /* XXX: I did that only to give same values as previous code */
- a0 = W4 * (col[8*0] + ((1<<(COL_SHIFT-1))/W4));
- a1 = a0;
- a2 = a0;
- a3 = a0;
-
- a0 += + W2*col[8*2];
- a1 += + W6*col[8*2];
- a2 += - W6*col[8*2];
- a3 += - W2*col[8*2];
-
- MUL16(b0, W1, col[8*1]);
- MUL16(b1, W3, col[8*1]);
- MUL16(b2, W5, col[8*1]);
- MUL16(b3, W7, col[8*1]);
-
- MAC16(b0, + W3, col[8*3]);
- MAC16(b1, - W7, col[8*3]);
- MAC16(b2, - W1, col[8*3]);
- MAC16(b3, - W5, col[8*3]);
-
- if(col[8*4]){
- a0 += + W4*col[8*4];
- a1 += - W4*col[8*4];
- a2 += - W4*col[8*4];
- a3 += + W4*col[8*4];
- }
-
- if (col[8*5]) {
- MAC16(b0, + W5, col[8*5]);
- MAC16(b1, - W1, col[8*5]);
- MAC16(b2, + W7, col[8*5]);
- MAC16(b3, + W3, col[8*5]);
- }
-
- if(col[8*6]){
- a0 += + W6*col[8*6];
- a1 += - W2*col[8*6];
- a2 += + W2*col[8*6];
- a3 += - W6*col[8*6];
- }
-
- if (col[8*7]) {
- MAC16(b0, + W7, col[8*7]);
- MAC16(b1, - W5, col[8*7]);
- MAC16(b2, + W3, col[8*7]);
- MAC16(b3, - W1, col[8*7]);
- }
-
- col[0 ] = ((a0 + b0) >> COL_SHIFT);
- col[8 ] = ((a1 + b1) >> COL_SHIFT);
- col[16] = ((a2 + b2) >> COL_SHIFT);
- col[24] = ((a3 + b3) >> COL_SHIFT);
- col[32] = ((a3 - b3) >> COL_SHIFT);
- col[40] = ((a2 - b2) >> COL_SHIFT);
- col[48] = ((a1 - b1) >> COL_SHIFT);
- col[56] = ((a0 - b0) >> COL_SHIFT);
-}
-
-void simple_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
-{
- int i;
- for(i=0; i<8; i++)
- idctRowCondDC(block + i*8);
-
- for(i=0; i<8; i++)
- idctSparseColPut(dest + i, line_size, block + i);
-}
-
-void simple_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
-{
- int i;
- for(i=0; i<8; i++)
- idctRowCondDC(block + i*8);
-
- for(i=0; i<8; i++)
- idctSparseColAdd(dest + i, line_size, block + i);
-}
-
-void simple_idct(DCTELEM *block)
-{
- int i;
- for(i=0; i<8; i++)
- idctRowCondDC(block + i*8);
-
- for(i=0; i<8; i++)
- idctSparseCol(block + i);
-}
-
-/* 2x4x8 idct */
-
-#define CN_SHIFT 12
-#define C_FIX(x) ((int)((x) * (1 << CN_SHIFT) + 0.5))
-#define C1 C_FIX(0.6532814824)
-#define C2 C_FIX(0.2705980501)
-
-/* row idct is multiple by 16 * sqrt(2.0), col idct4 is normalized,
- and the butterfly must be multiplied by 0.5 * sqrt(2.0) */
-#define C_SHIFT (4+1+12)
-
-static inline void idct4col(uint8_t *dest, int line_size, const DCTELEM *col)
-{
- int c0, c1, c2, c3, a0, a1, a2, a3;
- const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
-
- a0 = col[8*0];
- a1 = col[8*2];
- a2 = col[8*4];
- a3 = col[8*6];
- c0 = ((a0 + a2) << (CN_SHIFT - 1)) + (1 << (C_SHIFT - 1));
- c2 = ((a0 - a2) << (CN_SHIFT - 1)) + (1 << (C_SHIFT - 1));
- c1 = a1 * C1 + a3 * C2;
- c3 = a1 * C2 - a3 * C1;
- dest[0] = cm[(c0 + c1) >> C_SHIFT];
- dest += line_size;
- dest[0] = cm[(c2 + c3) >> C_SHIFT];
- dest += line_size;
- dest[0] = cm[(c2 - c3) >> C_SHIFT];
- dest += line_size;
- dest[0] = cm[(c0 - c1) >> C_SHIFT];
-}
-
-#define BF(k) \
-{\
- int a0, a1;\
- a0 = ptr[k];\
- a1 = ptr[8 + k];\
- ptr[k] = a0 + a1;\
- ptr[8 + k] = a0 - a1;\
-}
-
-/* only used by DV codec. The input must be interlaced. 128 is added
- to the pixels before clamping to avoid systematic error
- (1024*sqrt(2)) offset would be needed otherwise. */
-/* XXX: I think a 1.0/sqrt(2) normalization should be needed to
- compensate the extra butterfly stage - I don't have the full DV
- specification */
-void simple_idct248_put(uint8_t *dest, int line_size, DCTELEM *block)
-{
- int i;
- DCTELEM *ptr;
-
- /* butterfly */
- ptr = block;
- for(i=0;i<4;i++) {
- BF(0);
- BF(1);
- BF(2);
- BF(3);
- BF(4);
- BF(5);
- BF(6);
- BF(7);
- ptr += 2 * 8;
- }
-
- /* IDCT8 on each line */
- for(i=0; i<8; i++) {
- idctRowCondDC(block + i*8);
- }
-
- /* IDCT4 and store */
- for(i=0;i<8;i++) {
- idct4col(dest + i, 2 * line_size, block + i);
- idct4col(dest + line_size + i, 2 * line_size, block + 8 + i);
- }
-}
-
-/* 8x4 & 4x8 WMV2 IDCT */
-#undef CN_SHIFT
-#undef C_SHIFT
-#undef C_FIX
-#undef C1
-#undef C2
-#define CN_SHIFT 12
-#define C_FIX(x) ((int)((x) * 1.414213562 * (1 << CN_SHIFT) + 0.5))
-#define C1 C_FIX(0.6532814824)
-#define C2 C_FIX(0.2705980501)
-#define C3 C_FIX(0.5)
-#define C_SHIFT (4+1+12)
-static inline void idct4col_add(uint8_t *dest, int line_size, const DCTELEM *col)
-{
- int c0, c1, c2, c3, a0, a1, a2, a3;
- const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
-
- a0 = col[8*0];
- a1 = col[8*1];
- a2 = col[8*2];
- a3 = col[8*3];
- c0 = (a0 + a2)*C3 + (1 << (C_SHIFT - 1));
- c2 = (a0 - a2)*C3 + (1 << (C_SHIFT - 1));
- c1 = a1 * C1 + a3 * C2;
- c3 = a1 * C2 - a3 * C1;
- dest[0] = cm[dest[0] + ((c0 + c1) >> C_SHIFT)];
- dest += line_size;
- dest[0] = cm[dest[0] + ((c2 + c3) >> C_SHIFT)];
- dest += line_size;
- dest[0] = cm[dest[0] + ((c2 - c3) >> C_SHIFT)];
- dest += line_size;
- dest[0] = cm[dest[0] + ((c0 - c1) >> C_SHIFT)];
-}
-
-#define RN_SHIFT 15
-#define R_FIX(x) ((int)((x) * 1.414213562 * (1 << RN_SHIFT) + 0.5))
-#define R1 R_FIX(0.6532814824)
-#define R2 R_FIX(0.2705980501)
-#define R3 R_FIX(0.5)
-#define R_SHIFT 11
-static inline void idct4row(DCTELEM *row)
-{
- int c0, c1, c2, c3, a0, a1, a2, a3;
- //const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
-
- a0 = row[0];
- a1 = row[1];
- a2 = row[2];
- a3 = row[3];
- c0 = (a0 + a2)*R3 + (1 << (R_SHIFT - 1));
- c2 = (a0 - a2)*R3 + (1 << (R_SHIFT - 1));
- c1 = a1 * R1 + a3 * R2;
- c3 = a1 * R2 - a3 * R1;
- row[0]= (c0 + c1) >> R_SHIFT;
- row[1]= (c2 + c3) >> R_SHIFT;
- row[2]= (c2 - c3) >> R_SHIFT;
- row[3]= (c0 - c1) >> R_SHIFT;
-}
-
-void simple_idct84_add(uint8_t *dest, int line_size, DCTELEM *block)
-{
- int i;
-
- /* IDCT8 on each line */
- for(i=0; i<4; i++) {
- idctRowCondDC(block + i*8);
- }
-
- /* IDCT4 and store */
- for(i=0;i<8;i++) {
- idct4col_add(dest + i, line_size, block + i);
- }
-}
-
-void simple_idct48_add(uint8_t *dest, int line_size, DCTELEM *block)
-{
- int i;
-
- /* IDCT4 on each line */
- for(i=0; i<8; i++) {
- idct4row(block + i*8);
- }
-
- /* IDCT8 and store */
- for(i=0; i<4; i++){
- idctSparseColAdd(dest + i, line_size, block + i);
- }
-}
-
diff --git a/src/libffmpeg/libavcodec/smacker.c b/src/libffmpeg/libavcodec/smacker.c
deleted file mode 100644
index 0bdbc7977..000000000
--- a/src/libffmpeg/libavcodec/smacker.c
+++ /dev/null
@@ -1,723 +0,0 @@
-/*
- * Smacker decoder
- * Copyright (c) 2006 Konstantin Shishkov
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-/**
- * @file smacker.c
- * Smacker decoder
- */
-
-/*
- * Based on http://wiki.multimedia.cx/index.php?title=Smacker
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "common.h"
-#include "avcodec.h"
-
-#define ALT_BITSTREAM_READER_LE
-#include "bitstream.h"
-
-#define SMKTREE_BITS 9
-#define SMK_NODE 0x80000000
-
-/*
- * Decoder context
- */
-typedef struct SmackVContext {
- AVCodecContext *avctx;
- AVFrame pic;
-
- int *mmap_tbl, *mclr_tbl, *full_tbl, *type_tbl;
- int mmap_last[3], mclr_last[3], full_last[3], type_last[3];
-} SmackVContext;
-
-/**
- * Context used for code reconstructing
- */
-typedef struct HuffContext {
- int length;
- int maxlength;
- int current;
- uint32_t *bits;
- int *lengths;
- int *values;
-} HuffContext;
-
-/* common parameters used for decode_bigtree */
-typedef struct DBCtx {
- VLC *v1, *v2;
- int *recode1, *recode2;
- int escapes[3];
- int *last;
- int lcur;
-} DBCtx;
-
-/* possible runs of blocks */
-static const int block_runs[64] = {
- 1, 2, 3, 4, 5, 6, 7, 8,
- 9, 10, 11, 12, 13, 14, 15, 16,
- 17, 18, 19, 20, 21, 22, 23, 24,
- 25, 26, 27, 28, 29, 30, 31, 32,
- 33, 34, 35, 36, 37, 38, 39, 40,
- 41, 42, 43, 44, 45, 46, 47, 48,
- 49, 50, 51, 52, 53, 54, 55, 56,
- 57, 58, 59, 128, 256, 512, 1024, 2048 };
-
-enum SmkBlockTypes {
- SMK_BLK_MONO = 0,
- SMK_BLK_FULL = 1,
- SMK_BLK_SKIP = 2,
- SMK_BLK_FILL = 3 };
-
-/**
- * Decode local frame tree
- */
-static int smacker_decode_tree(GetBitContext *gb, HuffContext *hc, uint32_t prefix, int length)
-{
- if(!get_bits1(gb)){ //Leaf
- if(hc->current >= 256){
- av_log(NULL, AV_LOG_ERROR, "Tree size exceeded!\n");
- return -1;
- }
- if(length){
- hc->bits[hc->current] = prefix;
- hc->lengths[hc->current] = length;
- } else {
- hc->bits[hc->current] = 0;
- hc->lengths[hc->current] = 0;
- }
- hc->values[hc->current] = get_bits(gb, 8);
- hc->current++;
- if(hc->maxlength < length)
- hc->maxlength = length;
- return 0;
- } else { //Node
- int r;
- length++;
- r = smacker_decode_tree(gb, hc, prefix, length);
- if(r)
- return r;
- return smacker_decode_tree(gb, hc, prefix | (1 << (length - 1)), length);
- }
-}
-
-/**
- * Decode header tree
- */
-static int smacker_decode_bigtree(GetBitContext *gb, HuffContext *hc, DBCtx *ctx)
-{
- if(!get_bits1(gb)){ //Leaf
- int val, i1, i2, b1, b2;
- if(hc->current >= hc->length){
- av_log(NULL, AV_LOG_ERROR, "Tree size exceeded!\n");
- return -1;
- }
- b1 = get_bits_count(gb);
- i1 = get_vlc2(gb, ctx->v1->table, SMKTREE_BITS, 3);
- b1 = get_bits_count(gb) - b1;
- b2 = get_bits_count(gb);
- i2 = get_vlc2(gb, ctx->v2->table, SMKTREE_BITS, 3);
- b2 = get_bits_count(gb) - b2;
- val = ctx->recode1[i1] | (ctx->recode2[i2] << 8);
- if(val == ctx->escapes[0]) {
- ctx->last[0] = hc->current;
- val = 0;
- } else if(val == ctx->escapes[1]) {
- ctx->last[1] = hc->current;
- val = 0;
- } else if(val == ctx->escapes[2]) {
- ctx->last[2] = hc->current;
- val = 0;
- }
-
- hc->values[hc->current++] = val;
- return 1;
- } else { //Node
- int r = 0, t;
-
- t = hc->current++;
- r = smacker_decode_bigtree(gb, hc, ctx);
- if(r < 0)
- return r;
- hc->values[t] = SMK_NODE | r;
- r++;
- r += smacker_decode_bigtree(gb, hc, ctx);
- return r;
- }
-}
-
-/**
- * Store large tree as FFmpeg's vlc codes
- */
-static int smacker_decode_header_tree(SmackVContext *smk, GetBitContext *gb, int **recodes, int *last, int size)
-{
- int res;
- HuffContext huff;
- HuffContext tmp1, tmp2;
- VLC vlc[2];
- int escapes[3];
- DBCtx ctx;
-
- if(size >= UINT_MAX>>4){ // (((size + 3) >> 2) + 3) << 2 must not overflow
- av_log(smk->avctx, AV_LOG_ERROR, "size too large\n");
- return -1;
- }
-
- tmp1.length = 256;
- tmp1.maxlength = 0;
- tmp1.current = 0;
- tmp1.bits = av_mallocz(256 * 4);
- tmp1.lengths = av_mallocz(256 * sizeof(int));
- tmp1.values = av_mallocz(256 * sizeof(int));
-
- tmp2.length = 256;
- tmp2.maxlength = 0;
- tmp2.current = 0;
- tmp2.bits = av_mallocz(256 * 4);
- tmp2.lengths = av_mallocz(256 * sizeof(int));
- tmp2.values = av_mallocz(256 * sizeof(int));
-
- memset(&vlc[0], 0, sizeof(VLC));
- memset(&vlc[1], 0, sizeof(VLC));
-
- if(get_bits1(gb)) {
- smacker_decode_tree(gb, &tmp1, 0, 0);
- get_bits1(gb);
- res = init_vlc(&vlc[0], SMKTREE_BITS, tmp1.length,
- tmp1.lengths, sizeof(int), sizeof(int),
- tmp1.bits, sizeof(uint32_t), sizeof(uint32_t), INIT_VLC_LE);
- if(res < 0) {
- av_log(smk->avctx, AV_LOG_ERROR, "Cannot build VLC table\n");
- return -1;
- }
- } else {
- av_log(smk->avctx, AV_LOG_ERROR, "Skipping low bytes tree\n");
- }
- if(get_bits1(gb)){
- smacker_decode_tree(gb, &tmp2, 0, 0);
- get_bits1(gb);
- res = init_vlc(&vlc[1], SMKTREE_BITS, tmp2.length,
- tmp2.lengths, sizeof(int), sizeof(int),
- tmp2.bits, sizeof(uint32_t), sizeof(uint32_t), INIT_VLC_LE);
- if(res < 0) {
- av_log(smk->avctx, AV_LOG_ERROR, "Cannot build VLC table\n");
- return -1;
- }
- } else {
- av_log(smk->avctx, AV_LOG_ERROR, "Skipping high bytes tree\n");
- }
-
- escapes[0] = get_bits(gb, 8);
- escapes[0] |= get_bits(gb, 8) << 8;
- escapes[1] = get_bits(gb, 8);
- escapes[1] |= get_bits(gb, 8) << 8;
- escapes[2] = get_bits(gb, 8);
- escapes[2] |= get_bits(gb, 8) << 8;
-
- last[0] = last[1] = last[2] = -1;
-
- ctx.escapes[0] = escapes[0];
- ctx.escapes[1] = escapes[1];
- ctx.escapes[2] = escapes[2];
- ctx.v1 = &vlc[0];
- ctx.v2 = &vlc[1];
- ctx.recode1 = tmp1.values;
- ctx.recode2 = tmp2.values;
- ctx.last = last;
-
- huff.length = ((size + 3) >> 2) + 3;
- huff.maxlength = 0;
- huff.current = 0;
- huff.values = av_mallocz(huff.length * sizeof(int));
-
- smacker_decode_bigtree(gb, &huff, &ctx);
- get_bits1(gb);
- if(ctx.last[0] == -1) ctx.last[0] = huff.current++;
- if(ctx.last[1] == -1) ctx.last[1] = huff.current++;
- if(ctx.last[2] == -1) ctx.last[2] = huff.current++;
-
- *recodes = huff.values;
-
- if(vlc[0].table)
- free_vlc(&vlc[0]);
- if(vlc[1].table)
- free_vlc(&vlc[1]);
- av_free(tmp1.bits);
- av_free(tmp1.lengths);
- av_free(tmp1.values);
- av_free(tmp2.bits);
- av_free(tmp2.lengths);
- av_free(tmp2.values);
-
- return 0;
-}
-
-static int decode_header_trees(SmackVContext *smk) {
- GetBitContext gb;
- int mmap_size, mclr_size, full_size, type_size;
-
- mmap_size = AV_RL32(smk->avctx->extradata);
- mclr_size = AV_RL32(smk->avctx->extradata + 4);
- full_size = AV_RL32(smk->avctx->extradata + 8);
- type_size = AV_RL32(smk->avctx->extradata + 12);
-
- init_get_bits(&gb, smk->avctx->extradata + 16, (smk->avctx->extradata_size - 16) * 8);
-
- if(!get_bits1(&gb)) {
- av_log(smk->avctx, AV_LOG_INFO, "Skipping MMAP tree\n");
- smk->mmap_tbl = av_malloc(sizeof(int) * 2);
- smk->mmap_tbl[0] = 0;
- smk->mmap_last[0] = smk->mmap_last[1] = smk->mmap_last[2] = 1;
- } else {
- smacker_decode_header_tree(smk, &gb, &smk->mmap_tbl, smk->mmap_last, mmap_size);
- }
- if(!get_bits(&gb, 1)) {
- av_log(smk->avctx, AV_LOG_INFO, "Skipping MCLR tree\n");
- smk->mclr_tbl = av_malloc(sizeof(int) * 2);
- smk->mclr_tbl[0] = 0;
- smk->mclr_last[0] = smk->mclr_last[1] = smk->mclr_last[2] = 1;
- } else {
- smacker_decode_header_tree(smk, &gb, &smk->mclr_tbl, smk->mclr_last, mclr_size);
- }
- if(!get_bits(&gb, 1)) {
- av_log(smk->avctx, AV_LOG_INFO, "Skipping FULL tree\n");
- smk->full_tbl = av_malloc(sizeof(int) * 2);
- smk->full_tbl[0] = 0;
- smk->full_last[0] = smk->full_last[1] = smk->full_last[2] = 1;
- } else {
- smacker_decode_header_tree(smk, &gb, &smk->full_tbl, smk->full_last, full_size);
- }
- if(!get_bits(&gb, 1)) {
- av_log(smk->avctx, AV_LOG_INFO, "Skipping TYPE tree\n");
- smk->type_tbl = av_malloc(sizeof(int) * 2);
- smk->type_tbl[0] = 0;
- smk->type_last[0] = smk->type_last[1] = smk->type_last[2] = 1;
- } else {
- smacker_decode_header_tree(smk, &gb, &smk->type_tbl, smk->type_last, type_size);
- }
-
- return 0;
-}
-
-static av_always_inline void last_reset(int *recode, int *last) {
- recode[last[0]] = recode[last[1]] = recode[last[2]] = 0;
-}
-
-/* get code and update history */
-static av_always_inline int smk_get_code(GetBitContext *gb, int *recode, int *last) {
- register int *table = recode;
- int v, b;
-
- b = get_bits_count(gb);
- while(*table & SMK_NODE) {
- if(get_bits1(gb))
- table += (*table) & (~SMK_NODE);
- table++;
- }
- v = *table;
- b = get_bits_count(gb) - b;
-
- if(v != recode[last[0]]) {
- recode[last[2]] = recode[last[1]];
- recode[last[1]] = recode[last[0]];
- recode[last[0]] = v;
- }
- return v;
-}
-
-static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size)
-{
- SmackVContext * const smk = (SmackVContext *)avctx->priv_data;
- uint8_t *out;
- uint32_t *pal;
- GetBitContext gb;
- int blocks, blk, bw, bh;
- int i;
- int stride;
-
- if(buf_size == 769)
- return 0;
- if(smk->pic.data[0])
- avctx->release_buffer(avctx, &smk->pic);
-
- smk->pic.reference = 1;
- smk->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
- if(avctx->reget_buffer(avctx, &smk->pic) < 0){
- av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
- return -1;
- }
-
- /* make the palette available on the way out */
- out = buf + 1;
- pal = (uint32_t*)smk->pic.data[1];
- smk->pic.palette_has_changed = buf[0] & 1;
- smk->pic.key_frame = !!(buf[0] & 2);
- if(smk->pic.key_frame)
- smk->pic.pict_type = FF_I_TYPE;
- else
- smk->pic.pict_type = FF_P_TYPE;
-
- for(i = 0; i < 256; i++) {
- int r, g, b;
- r = *out++;
- g = *out++;
- b = *out++;
- *pal++ = (r << 16) | (g << 8) | b;
- }
-
- last_reset(smk->mmap_tbl, smk->mmap_last);
- last_reset(smk->mclr_tbl, smk->mclr_last);
- last_reset(smk->full_tbl, smk->full_last);
- last_reset(smk->type_tbl, smk->type_last);
- init_get_bits(&gb, buf + 769, (buf_size - 769) * 8);
-
- blk = 0;
- bw = avctx->width >> 2;
- bh = avctx->height >> 2;
- blocks = bw * bh;
- out = smk->pic.data[0];
- stride = smk->pic.linesize[0];
- while(blk < blocks) {
- int type, run, mode;
- uint16_t pix;
-
- type = smk_get_code(&gb, smk->type_tbl, smk->type_last);
- run = block_runs[(type >> 2) & 0x3F];
- switch(type & 3){
- case SMK_BLK_MONO:
- while(run-- && blk < blocks){
- int clr, map;
- int hi, lo;
- clr = smk_get_code(&gb, smk->mclr_tbl, smk->mclr_last);
- map = smk_get_code(&gb, smk->mmap_tbl, smk->mmap_last);
- out = smk->pic.data[0] + (blk / bw) * (stride * 4) + (blk % bw) * 4;
- hi = clr >> 8;
- lo = clr & 0xFF;
- for(i = 0; i < 4; i++) {
- if(map & 1) out[0] = hi; else out[0] = lo;
- if(map & 2) out[1] = hi; else out[1] = lo;
- if(map & 4) out[2] = hi; else out[2] = lo;
- if(map & 8) out[3] = hi; else out[3] = lo;
- map >>= 4;
- out += stride;
- }
- blk++;
- }
- break;
- case SMK_BLK_FULL:
- mode = 0;
- if(avctx->codec_tag == MKTAG('S', 'M', 'K', '4')) { // In case of Smacker v4 we have three modes
- if(get_bits1(&gb)) mode = 1;
- else if(get_bits1(&gb)) mode = 2;
- }
- while(run-- && blk < blocks){
- out = smk->pic.data[0] + (blk / bw) * (stride * 4) + (blk % bw) * 4;
- switch(mode){
- case 0:
- for(i = 0; i < 4; i++) {
- pix = smk_get_code(&gb, smk->full_tbl, smk->full_last);
- out[2] = pix & 0xFF;
- out[3] = pix >> 8;
- pix = smk_get_code(&gb, smk->full_tbl, smk->full_last);
- out[0] = pix & 0xFF;
- out[1] = pix >> 8;
- out += stride;
- }
- break;
- case 1:
- pix = smk_get_code(&gb, smk->full_tbl, smk->full_last);
- out[0] = out[1] = pix & 0xFF;
- out[2] = out[3] = pix >> 8;
- out += stride;
- out[0] = out[1] = pix & 0xFF;
- out[2] = out[3] = pix >> 8;
- out += stride;
- pix = smk_get_code(&gb, smk->full_tbl, smk->full_last);
- out[0] = out[1] = pix & 0xFF;
- out[2] = out[3] = pix >> 8;
- out += stride;
- out[0] = out[1] = pix & 0xFF;
- out[2] = out[3] = pix >> 8;
- out += stride;
- break;
- case 2:
- for(i = 0; i < 2; i++) {
- uint16_t pix1, pix2;
- pix1 = smk_get_code(&gb, smk->full_tbl, smk->full_last);
- pix2 = smk_get_code(&gb, smk->full_tbl, smk->full_last);
- out[0] = pix1 & 0xFF; out[1] = pix1 >> 8;
- out[2] = pix2 & 0xFF; out[3] = pix2 >> 8;
- out += stride;
- out[0] = pix1 & 0xFF; out[1] = pix1 >> 8;
- out[2] = pix2 & 0xFF; out[3] = pix2 >> 8;
- out += stride;
- }
- break;
- }
- blk++;
- }
- break;
- case SMK_BLK_SKIP:
- while(run-- && blk < blocks)
- blk++;
- break;
- case SMK_BLK_FILL:
- mode = type >> 8;
- while(run-- && blk < blocks){
- uint32_t col;
- out = smk->pic.data[0] + (blk / bw) * (stride * 4) + (blk % bw) * 4;
- col = mode * 0x01010101;
- for(i = 0; i < 4; i++) {
- *((uint32_t*)out) = col;
- out += stride;
- }
- blk++;
- }
- break;
- }
-
- }
-
- *data_size = sizeof(AVFrame);
- *(AVFrame*)data = smk->pic;
-
- /* always report that the buffer was completely consumed */
- return buf_size;
-}
-
-
-
-/*
- *
- * Init smacker decoder
- *
- */
-static int decode_init(AVCodecContext *avctx)
-{
- SmackVContext * const c = (SmackVContext *)avctx->priv_data;
-
- c->avctx = avctx;
- avctx->has_b_frames = 0;
-
- c->pic.data[0] = NULL;
-
- if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) {
- return 1;
- }
-
- avctx->pix_fmt = PIX_FMT_PAL8;
-
-
- /* decode huffman trees from extradata */
- if(avctx->extradata_size < 16){
- av_log(avctx, AV_LOG_ERROR, "Extradata missing!\n");
- return -1;
- }
-
- decode_header_trees(c);
-
-
- return 0;
-}
-
-
-
-/*
- *
- * Uninit smacker decoder
- *
- */
-static int decode_end(AVCodecContext *avctx)
-{
- SmackVContext * const smk = (SmackVContext *)avctx->priv_data;
-
- av_freep(&smk->mmap_tbl);
- av_freep(&smk->mclr_tbl);
- av_freep(&smk->full_tbl);
- av_freep(&smk->type_tbl);
-
- if (smk->pic.data[0])
- avctx->release_buffer(avctx, &smk->pic);
-
- return 0;
-}
-
-
-static int smka_decode_init(AVCodecContext *avctx)
-{
- return 0;
-}
-
-/**
- * Decode Smacker audio data
- */
-static int smka_decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size)
-{
- GetBitContext gb;
- HuffContext h[4];
- VLC vlc[4];
- int16_t *samples = data;
- int val;
- int i, res;
- int unp_size;
- int bits, stereo;
- int pred[2] = {0, 0};
-
- unp_size = AV_RL32(buf);
-
- init_get_bits(&gb, buf + 4, (buf_size - 4) * 8);
-
- if(!get_bits1(&gb)){
- av_log(avctx, AV_LOG_INFO, "Sound: no data\n");
- *data_size = 0;
- return 1;
- }
- stereo = get_bits1(&gb);
- bits = get_bits1(&gb);
-
- memset(vlc, 0, sizeof(VLC) * 4);
- memset(h, 0, sizeof(HuffContext) * 4);
- // Initialize
- for(i = 0; i < (1 << (bits + stereo)); i++) {
- h[i].length = 256;
- h[i].maxlength = 0;
- h[i].current = 0;
- h[i].bits = av_mallocz(256 * 4);
- h[i].lengths = av_mallocz(256 * sizeof(int));
- h[i].values = av_mallocz(256 * sizeof(int));
- get_bits1(&gb);
- smacker_decode_tree(&gb, &h[i], 0, 0);
- get_bits1(&gb);
- if(h[i].current > 1) {
- res = init_vlc(&vlc[i], SMKTREE_BITS, h[i].length,
- h[i].lengths, sizeof(int), sizeof(int),
- h[i].bits, sizeof(uint32_t), sizeof(uint32_t), INIT_VLC_LE);
- if(res < 0) {
- av_log(avctx, AV_LOG_ERROR, "Cannot build VLC table\n");
- return -1;
- }
- }
- }
- if(bits) { //decode 16-bit data
- pred[0] = get_bits(&gb, 8);
- pred[0] |= get_bits(&gb, 8);
- *samples++ = pred[0];
- if(stereo) {
- pred[1] = get_bits(&gb, 8);
- pred[1] |= get_bits(&gb, 8);
- *samples++ = pred[1];
- }
- for(i = 0; i < unp_size / 2; i++) {
- if(i & stereo) {
- if(vlc[2].table)
- res = get_vlc2(&gb, vlc[2].table, SMKTREE_BITS, 3);
- else
- res = 0;
- val = h[2].values[res];
- if(vlc[3].table)
- res = get_vlc2(&gb, vlc[3].table, SMKTREE_BITS, 3);
- else
- res = 0;
- val |= h[3].values[res] << 8;
- pred[1] += (int16_t)val;
- *samples++ = pred[1];
- } else {
- if(vlc[0].table)
- res = get_vlc2(&gb, vlc[0].table, SMKTREE_BITS, 3);
- else
- res = 0;
- val = h[0].values[res];
- if(vlc[1].table)
- res = get_vlc2(&gb, vlc[1].table, SMKTREE_BITS, 3);
- else
- res = 0;
- val |= h[1].values[res] << 8;
- pred[0] += val;
- *samples++ = pred[0];
- }
- }
- } else { //8-bit data
- pred[0] = get_bits(&gb, 8);
- *samples++ = (pred[0] - 0x80) << 8;
- if(stereo) {
- pred[1] = get_bits(&gb, 8);
- *samples++ = (pred[1] - 0x80) << 8;
- }
- for(i = 0; i < unp_size; i++) {
- if(i & stereo){
- if(vlc[1].table)
- res = get_vlc2(&gb, vlc[1].table, SMKTREE_BITS, 3);
- else
- res = 0;
- pred[1] += (int8_t)h[1].values[res];
- *samples++ = (pred[1] - 0x80) << 8;
- } else {
- if(vlc[0].table)
- res = get_vlc2(&gb, vlc[0].table, SMKTREE_BITS, 3);
- else
- res = 0;
- pred[0] += (int8_t)h[0].values[res];
- *samples++ = (pred[0] - 0x80) << 8;
- }
- }
- unp_size *= 2;
- }
-
- for(i = 0; i < 4; i++) {
- if(vlc[i].table)
- free_vlc(&vlc[i]);
- if(h[i].bits)
- av_free(h[i].bits);
- if(h[i].lengths)
- av_free(h[i].lengths);
- if(h[i].values)
- av_free(h[i].values);
- }
-
- *data_size = unp_size;
- return buf_size;
-}
-
-AVCodec smacker_decoder = {
- "smackvid",
- CODEC_TYPE_VIDEO,
- CODEC_ID_SMACKVIDEO,
- sizeof(SmackVContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame
-};
-
-AVCodec smackaud_decoder = {
- "smackaud",
- CODEC_TYPE_AUDIO,
- CODEC_ID_SMACKAUDIO,
- 0,
- smka_decode_init,
- NULL,
- NULL,
- smka_decode_frame
-};
-
diff --git a/src/libffmpeg/libavcodec/snow.c b/src/libffmpeg/libavcodec/snow.c
deleted file mode 100644
index 03e634bf1..000000000
--- a/src/libffmpeg/libavcodec/snow.c
+++ /dev/null
@@ -1,4720 +0,0 @@
-/*
- * Copyright (C) 2004 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include "avcodec.h"
-#include "common.h"
-#include "dsputil.h"
-#include "snow.h"
-
-#include "rangecoder.h"
-
-#include "mpegvideo.h"
-
-#undef NDEBUG
-#include <assert.h>
-
-static const int8_t quant3[256]={
- 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 0,
-};
-static const int8_t quant3b[256]={
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
--1,-1,-1,-1,-1,-1,-1,-1,-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 int8_t quant3bA[256]={
- 0, 0, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1,
- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1,
- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1,
- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1,
- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1,
- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1,
- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1,
- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1,
- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1,
- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1,
- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1,
- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1,
- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1,
- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1,
- 1,-1, 1,-1, 1,-1, 1,-1, 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 int8_t quant5[256]={
- 0, 1, 1, 1, 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,-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,-1,-1,-1,
-};
-static const int8_t quant7[256]={
- 0, 1, 1, 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, 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
--3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,
--3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,
--3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,
--3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,
--3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,
--3,-3,-3,-3,-3,-3,-3,-3,-3,-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,-1,-1,
-};
-static const int8_t quant9[256]={
- 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 3, 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,-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,-3,-3,-3,-3,
--3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-2,-2,-2,-2,-1,-1,
-};
-static const int8_t quant11[256]={
- 0, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4,
- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
- 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-4,-4,
--4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,
--4,-4,-4,-4,-4,-3,-3,-3,-3,-3,-3,-3,-2,-2,-2,-1,
-};
-static const int8_t quant13[256]={
- 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
- 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
--6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,
--6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,
--6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,
--6,-6,-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,-5,
--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
--4,-4,-4,-4,-4,-4,-4,-4,-4,-3,-3,-3,-3,-2,-2,-1,
-};
-
-#if 0 //64*cubic
-static const uint8_t obmc32[1024]={
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
- 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0,
- 0, 0, 1, 1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 7, 8, 8, 8, 8, 7, 7, 6, 6, 5, 4, 4, 3, 2, 2, 1, 1, 0, 0,
- 0, 0, 1, 2, 2, 3, 4, 6, 7, 8, 9,10,11,12,12,12,12,12,12,11,10, 9, 8, 7, 6, 4, 3, 2, 2, 1, 0, 0,
- 0, 1, 1, 2, 3, 5, 6, 8,10,11,13,14,15,16,17,18,18,17,16,15,14,13,11,10, 8, 6, 5, 3, 2, 1, 1, 0,
- 0, 1, 1, 3, 4, 6, 8,10,13,15,17,19,20,22,22,23,23,22,22,20,19,17,15,13,10, 8, 6, 4, 3, 1, 1, 0,
- 0, 1, 2, 4, 6, 8,10,13,16,19,21,23,25,27,28,29,29,28,27,25,23,21,19,16,13,10, 8, 6, 4, 2, 1, 0,
- 0, 1, 2, 4, 7,10,13,16,19,22,25,28,31,33,34,35,35,34,33,31,28,25,22,19,16,13,10, 7, 4, 2, 1, 0,
- 0, 1, 3, 5, 8,11,15,19,22,26,30,33,36,38,40,41,41,40,38,36,33,30,26,22,19,15,11, 8, 5, 3, 1, 0,
- 0, 1, 3, 6, 9,12,17,21,25,30,34,38,41,44,45,46,46,45,44,41,38,34,30,25,21,17,12, 9, 6, 3, 1, 0,
- 0, 1, 3, 6,10,14,19,23,28,33,38,42,45,48,51,52,52,51,48,45,42,38,33,28,23,19,14,10, 6, 3, 1, 0,
- 0, 1, 4, 7,11,15,20,25,31,36,41,45,49,52,55,56,56,55,52,49,45,41,36,31,25,20,15,11, 7, 4, 1, 0,
- 0, 2, 4, 7,12,16,22,27,33,38,44,48,52,56,58,60,60,58,56,52,48,44,38,33,27,22,16,12, 7, 4, 2, 0,
- 0, 1, 4, 8,12,17,22,28,34,40,45,51,55,58,61,62,62,61,58,55,51,45,40,34,28,22,17,12, 8, 4, 1, 0,
- 0, 2, 4, 8,12,18,23,29,35,41,46,52,56,60,62,64,64,62,60,56,52,46,41,35,29,23,18,12, 8, 4, 2, 0,
- 0, 2, 4, 8,12,18,23,29,35,41,46,52,56,60,62,64,64,62,60,56,52,46,41,35,29,23,18,12, 8, 4, 2, 0,
- 0, 1, 4, 8,12,17,22,28,34,40,45,51,55,58,61,62,62,61,58,55,51,45,40,34,28,22,17,12, 8, 4, 1, 0,
- 0, 2, 4, 7,12,16,22,27,33,38,44,48,52,56,58,60,60,58,56,52,48,44,38,33,27,22,16,12, 7, 4, 2, 0,
- 0, 1, 4, 7,11,15,20,25,31,36,41,45,49,52,55,56,56,55,52,49,45,41,36,31,25,20,15,11, 7, 4, 1, 0,
- 0, 1, 3, 6,10,14,19,23,28,33,38,42,45,48,51,52,52,51,48,45,42,38,33,28,23,19,14,10, 6, 3, 1, 0,
- 0, 1, 3, 6, 9,12,17,21,25,30,34,38,41,44,45,46,46,45,44,41,38,34,30,25,21,17,12, 9, 6, 3, 1, 0,
- 0, 1, 3, 5, 8,11,15,19,22,26,30,33,36,38,40,41,41,40,38,36,33,30,26,22,19,15,11, 8, 5, 3, 1, 0,
- 0, 1, 2, 4, 7,10,13,16,19,22,25,28,31,33,34,35,35,34,33,31,28,25,22,19,16,13,10, 7, 4, 2, 1, 0,
- 0, 1, 2, 4, 6, 8,10,13,16,19,21,23,25,27,28,29,29,28,27,25,23,21,19,16,13,10, 8, 6, 4, 2, 1, 0,
- 0, 1, 1, 3, 4, 6, 8,10,13,15,17,19,20,22,22,23,23,22,22,20,19,17,15,13,10, 8, 6, 4, 3, 1, 1, 0,
- 0, 1, 1, 2, 3, 5, 6, 8,10,11,13,14,15,16,17,18,18,17,16,15,14,13,11,10, 8, 6, 5, 3, 2, 1, 1, 0,
- 0, 0, 1, 2, 2, 3, 4, 6, 7, 8, 9,10,11,12,12,12,12,12,12,11,10, 9, 8, 7, 6, 4, 3, 2, 2, 1, 0, 0,
- 0, 0, 1, 1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 7, 8, 8, 8, 8, 7, 7, 6, 6, 5, 4, 4, 3, 2, 2, 1, 1, 0, 0,
- 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0,
- 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-//error:0.000022
-};
-static const uint8_t obmc16[256]={
- 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
- 0, 1, 1, 2, 4, 5, 5, 6, 6, 5, 5, 4, 2, 1, 1, 0,
- 0, 1, 4, 6, 9,11,13,15,15,13,11, 9, 6, 4, 1, 0,
- 0, 2, 6,11,15,20,24,26,26,24,20,15,11, 6, 2, 0,
- 0, 4, 9,15,23,29,34,38,38,34,29,23,15, 9, 4, 0,
- 0, 5,11,20,29,38,45,49,49,45,38,29,20,11, 5, 0,
- 1, 5,13,24,34,45,53,57,57,53,45,34,24,13, 5, 1,
- 1, 6,15,26,38,49,57,62,62,57,49,38,26,15, 6, 1,
- 1, 6,15,26,38,49,57,62,62,57,49,38,26,15, 6, 1,
- 1, 5,13,24,34,45,53,57,57,53,45,34,24,13, 5, 1,
- 0, 5,11,20,29,38,45,49,49,45,38,29,20,11, 5, 0,
- 0, 4, 9,15,23,29,34,38,38,34,29,23,15, 9, 4, 0,
- 0, 2, 6,11,15,20,24,26,26,24,20,15,11, 6, 2, 0,
- 0, 1, 4, 6, 9,11,13,15,15,13,11, 9, 6, 4, 1, 0,
- 0, 1, 1, 2, 4, 5, 5, 6, 6, 5, 5, 4, 2, 1, 1, 0,
- 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
-//error:0.000033
-};
-#elif 1 // 64*linear
-static const uint8_t obmc32[1024]={
- 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0,
- 0, 4, 4, 4, 8, 8, 8, 12, 12, 16, 16, 16, 20, 20, 20, 24, 24, 20, 20, 20, 16, 16, 16, 12, 12, 8, 8, 8, 4, 4, 4, 0,
- 0, 4, 8, 8, 12, 12, 16, 20, 20, 24, 28, 28, 32, 32, 36, 40, 40, 36, 32, 32, 28, 28, 24, 20, 20, 16, 12, 12, 8, 8, 4, 0,
- 0, 4, 8, 12, 16, 20, 24, 28, 28, 32, 36, 40, 44, 48, 52, 56, 56, 52, 48, 44, 40, 36, 32, 28, 28, 24, 20, 16, 12, 8, 4, 0,
- 4, 8, 12, 16, 20, 24, 28, 32, 40, 44, 48, 52, 56, 60, 64, 68, 68, 64, 60, 56, 52, 48, 44, 40, 32, 28, 24, 20, 16, 12, 8, 4,
- 4, 8, 12, 20, 24, 32, 36, 40, 48, 52, 56, 64, 68, 76, 80, 84, 84, 80, 76, 68, 64, 56, 52, 48, 40, 36, 32, 24, 20, 12, 8, 4,
- 4, 8, 16, 24, 28, 36, 44, 48, 56, 60, 68, 76, 80, 88, 96,100,100, 96, 88, 80, 76, 68, 60, 56, 48, 44, 36, 28, 24, 16, 8, 4,
- 4, 12, 20, 28, 32, 40, 48, 56, 64, 72, 80, 88, 92,100,108,116,116,108,100, 92, 88, 80, 72, 64, 56, 48, 40, 32, 28, 20, 12, 4,
- 4, 12, 20, 28, 40, 48, 56, 64, 72, 80, 88, 96,108,116,124,132,132,124,116,108, 96, 88, 80, 72, 64, 56, 48, 40, 28, 20, 12, 4,
- 4, 16, 24, 32, 44, 52, 60, 72, 80, 92,100,108,120,128,136,148,148,136,128,120,108,100, 92, 80, 72, 60, 52, 44, 32, 24, 16, 4,
- 4, 16, 28, 36, 48, 56, 68, 80, 88,100,112,120,132,140,152,164,164,152,140,132,120,112,100, 88, 80, 68, 56, 48, 36, 28, 16, 4,
- 4, 16, 28, 40, 52, 64, 76, 88, 96,108,120,132,144,156,168,180,180,168,156,144,132,120,108, 96, 88, 76, 64, 52, 40, 28, 16, 4,
- 8, 20, 32, 44, 56, 68, 80, 92,108,120,132,144,156,168,180,192,192,180,168,156,144,132,120,108, 92, 80, 68, 56, 44, 32, 20, 8,
- 8, 20, 32, 48, 60, 76, 88,100,116,128,140,156,168,184,196,208,208,196,184,168,156,140,128,116,100, 88, 76, 60, 48, 32, 20, 8,
- 8, 20, 36, 52, 64, 80, 96,108,124,136,152,168,180,196,212,224,224,212,196,180,168,152,136,124,108, 96, 80, 64, 52, 36, 20, 8,
- 8, 24, 40, 56, 68, 84,100,116,132,148,164,180,192,208,224,240,240,224,208,192,180,164,148,132,116,100, 84, 68, 56, 40, 24, 8,
- 8, 24, 40, 56, 68, 84,100,116,132,148,164,180,192,208,224,240,240,224,208,192,180,164,148,132,116,100, 84, 68, 56, 40, 24, 8,
- 8, 20, 36, 52, 64, 80, 96,108,124,136,152,168,180,196,212,224,224,212,196,180,168,152,136,124,108, 96, 80, 64, 52, 36, 20, 8,
- 8, 20, 32, 48, 60, 76, 88,100,116,128,140,156,168,184,196,208,208,196,184,168,156,140,128,116,100, 88, 76, 60, 48, 32, 20, 8,
- 8, 20, 32, 44, 56, 68, 80, 92,108,120,132,144,156,168,180,192,192,180,168,156,144,132,120,108, 92, 80, 68, 56, 44, 32, 20, 8,
- 4, 16, 28, 40, 52, 64, 76, 88, 96,108,120,132,144,156,168,180,180,168,156,144,132,120,108, 96, 88, 76, 64, 52, 40, 28, 16, 4,
- 4, 16, 28, 36, 48, 56, 68, 80, 88,100,112,120,132,140,152,164,164,152,140,132,120,112,100, 88, 80, 68, 56, 48, 36, 28, 16, 4,
- 4, 16, 24, 32, 44, 52, 60, 72, 80, 92,100,108,120,128,136,148,148,136,128,120,108,100, 92, 80, 72, 60, 52, 44, 32, 24, 16, 4,
- 4, 12, 20, 28, 40, 48, 56, 64, 72, 80, 88, 96,108,116,124,132,132,124,116,108, 96, 88, 80, 72, 64, 56, 48, 40, 28, 20, 12, 4,
- 4, 12, 20, 28, 32, 40, 48, 56, 64, 72, 80, 88, 92,100,108,116,116,108,100, 92, 88, 80, 72, 64, 56, 48, 40, 32, 28, 20, 12, 4,
- 4, 8, 16, 24, 28, 36, 44, 48, 56, 60, 68, 76, 80, 88, 96,100,100, 96, 88, 80, 76, 68, 60, 56, 48, 44, 36, 28, 24, 16, 8, 4,
- 4, 8, 12, 20, 24, 32, 36, 40, 48, 52, 56, 64, 68, 76, 80, 84, 84, 80, 76, 68, 64, 56, 52, 48, 40, 36, 32, 24, 20, 12, 8, 4,
- 4, 8, 12, 16, 20, 24, 28, 32, 40, 44, 48, 52, 56, 60, 64, 68, 68, 64, 60, 56, 52, 48, 44, 40, 32, 28, 24, 20, 16, 12, 8, 4,
- 0, 4, 8, 12, 16, 20, 24, 28, 28, 32, 36, 40, 44, 48, 52, 56, 56, 52, 48, 44, 40, 36, 32, 28, 28, 24, 20, 16, 12, 8, 4, 0,
- 0, 4, 8, 8, 12, 12, 16, 20, 20, 24, 28, 28, 32, 32, 36, 40, 40, 36, 32, 32, 28, 28, 24, 20, 20, 16, 12, 12, 8, 8, 4, 0,
- 0, 4, 4, 4, 8, 8, 8, 12, 12, 16, 16, 16, 20, 20, 20, 24, 24, 20, 20, 20, 16, 16, 16, 12, 12, 8, 8, 8, 4, 4, 4, 0,
- 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0,
- //error:0.000020
-};
-static const uint8_t obmc16[256]={
- 0, 4, 4, 8, 8, 12, 12, 16, 16, 12, 12, 8, 8, 4, 4, 0,
- 4, 8, 16, 20, 28, 32, 40, 44, 44, 40, 32, 28, 20, 16, 8, 4,
- 4, 16, 24, 36, 44, 56, 64, 76, 76, 64, 56, 44, 36, 24, 16, 4,
- 8, 20, 36, 48, 64, 76, 92,104,104, 92, 76, 64, 48, 36, 20, 8,
- 8, 28, 44, 64, 80,100,116,136,136,116,100, 80, 64, 44, 28, 8,
- 12, 32, 56, 76,100,120,144,164,164,144,120,100, 76, 56, 32, 12,
- 12, 40, 64, 92,116,144,168,196,196,168,144,116, 92, 64, 40, 12,
- 16, 44, 76,104,136,164,196,224,224,196,164,136,104, 76, 44, 16,
- 16, 44, 76,104,136,164,196,224,224,196,164,136,104, 76, 44, 16,
- 12, 40, 64, 92,116,144,168,196,196,168,144,116, 92, 64, 40, 12,
- 12, 32, 56, 76,100,120,144,164,164,144,120,100, 76, 56, 32, 12,
- 8, 28, 44, 64, 80,100,116,136,136,116,100, 80, 64, 44, 28, 8,
- 8, 20, 36, 48, 64, 76, 92,104,104, 92, 76, 64, 48, 36, 20, 8,
- 4, 16, 24, 36, 44, 56, 64, 76, 76, 64, 56, 44, 36, 24, 16, 4,
- 4, 8, 16, 20, 28, 32, 40, 44, 44, 40, 32, 28, 20, 16, 8, 4,
- 0, 4, 4, 8, 8, 12, 12, 16, 16, 12, 12, 8, 8, 4, 4, 0,
-//error:0.000015
-};
-#else //64*cos
-static const uint8_t obmc32[1024]={
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0,
- 0, 0, 1, 1, 1, 2, 2, 3, 4, 5, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 5, 5, 4, 3, 2, 2, 1, 1, 1, 0, 0,
- 0, 0, 1, 1, 2, 3, 4, 5, 6, 7, 9,10,11,11,12,12,12,12,11,11,10, 9, 7, 6, 5, 4, 3, 2, 1, 1, 0, 0,
- 0, 0, 1, 2, 3, 5, 6, 8, 9,11,12,14,15,16,17,17,17,17,16,15,14,12,11, 9, 8, 6, 5, 3, 2, 1, 0, 0,
- 0, 1, 1, 2, 4, 6, 8,10,12,15,17,19,20,21,22,23,23,22,21,20,19,17,15,12,10, 8, 6, 4, 2, 1, 1, 0,
- 0, 1, 2, 3, 5, 8,10,13,16,19,21,24,26,27,28,29,29,28,27,26,24,21,19,16,13,10, 8, 5, 3, 2, 1, 0,
- 0, 1, 2, 4, 6, 9,12,16,19,23,26,29,31,33,34,35,35,34,33,31,29,26,23,19,16,12, 9, 6, 4, 2, 1, 0,
- 0, 1, 3, 5, 7,11,15,19,23,26,30,34,37,39,40,41,41,40,39,37,34,30,26,23,19,15,11, 7, 5, 3, 1, 0,
- 0, 1, 3, 5, 9,12,17,21,26,30,35,38,42,44,46,47,47,46,44,42,38,35,30,26,21,17,12, 9, 5, 3, 1, 0,
- 0, 1, 3, 6, 9,14,19,24,29,34,38,43,46,49,51,52,52,51,49,46,43,38,34,29,24,19,14, 9, 6, 3, 1, 0,
- 0, 1, 3, 6,11,15,20,26,31,37,42,46,50,53,56,57,57,56,53,50,46,42,37,31,26,20,15,11, 6, 3, 1, 0,
- 0, 1, 3, 7,11,16,21,27,33,39,44,49,53,57,59,60,60,59,57,53,49,44,39,33,27,21,16,11, 7, 3, 1, 0,
- 0, 1, 4, 7,12,17,22,28,34,40,46,51,56,59,61,63,63,61,59,56,51,46,40,34,28,22,17,12, 7, 4, 1, 0,
- 0, 1, 4, 7,12,17,23,29,35,41,47,52,57,60,63,64,64,63,60,57,52,47,41,35,29,23,17,12, 7, 4, 1, 0,
- 0, 1, 4, 7,12,17,23,29,35,41,47,52,57,60,63,64,64,63,60,57,52,47,41,35,29,23,17,12, 7, 4, 1, 0,
- 0, 1, 4, 7,12,17,22,28,34,40,46,51,56,59,61,63,63,61,59,56,51,46,40,34,28,22,17,12, 7, 4, 1, 0,
- 0, 1, 3, 7,11,16,21,27,33,39,44,49,53,57,59,60,60,59,57,53,49,44,39,33,27,21,16,11, 7, 3, 1, 0,
- 0, 1, 3, 6,11,15,20,26,31,37,42,46,50,53,56,57,57,56,53,50,46,42,37,31,26,20,15,11, 6, 3, 1, 0,
- 0, 1, 3, 6, 9,14,19,24,29,34,38,43,46,49,51,52,52,51,49,46,43,38,34,29,24,19,14, 9, 6, 3, 1, 0,
- 0, 1, 3, 5, 9,12,17,21,26,30,35,38,42,44,46,47,47,46,44,42,38,35,30,26,21,17,12, 9, 5, 3, 1, 0,
- 0, 1, 3, 5, 7,11,15,19,23,26,30,34,37,39,40,41,41,40,39,37,34,30,26,23,19,15,11, 7, 5, 3, 1, 0,
- 0, 1, 2, 4, 6, 9,12,16,19,23,26,29,31,33,34,35,35,34,33,31,29,26,23,19,16,12, 9, 6, 4, 2, 1, 0,
- 0, 1, 2, 3, 5, 8,10,13,16,19,21,24,26,27,28,29,29,28,27,26,24,21,19,16,13,10, 8, 5, 3, 2, 1, 0,
- 0, 1, 1, 2, 4, 6, 8,10,12,15,17,19,20,21,22,23,23,22,21,20,19,17,15,12,10, 8, 6, 4, 2, 1, 1, 0,
- 0, 0, 1, 2, 3, 5, 6, 8, 9,11,12,14,15,16,17,17,17,17,16,15,14,12,11, 9, 8, 6, 5, 3, 2, 1, 0, 0,
- 0, 0, 1, 1, 2, 3, 4, 5, 6, 7, 9,10,11,11,12,12,12,12,11,11,10, 9, 7, 6, 5, 4, 3, 2, 1, 1, 0, 0,
- 0, 0, 1, 1, 1, 2, 2, 3, 4, 5, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 5, 5, 4, 3, 2, 2, 1, 1, 1, 0, 0,
- 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-//error:0.000022
-};
-static const uint8_t obmc16[256]={
- 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
- 0, 0, 1, 2, 3, 4, 5, 5, 5, 5, 4, 3, 2, 1, 0, 0,
- 0, 1, 3, 6, 8,11,13,14,14,13,11, 8, 6, 3, 1, 0,
- 0, 2, 6,10,15,20,24,26,26,24,20,15,10, 6, 2, 0,
- 0, 3, 8,16,23,30,35,38,38,35,30,23,16, 8, 3, 0,
- 1, 4,11,20,30,39,46,49,49,46,39,30,20,11, 4, 1,
- 1, 5,13,24,35,46,54,58,58,54,46,35,24,13, 5, 1,
- 0, 5,14,26,38,49,58,63,63,58,49,38,26,14, 5, 0,
- 0, 5,14,26,38,49,58,63,63,58,49,38,26,14, 5, 0,
- 1, 5,13,24,35,46,54,58,58,54,46,35,24,13, 5, 1,
- 1, 4,11,20,30,39,46,49,49,46,39,30,20,11, 4, 1,
- 0, 3, 8,16,23,30,35,38,38,35,30,23,16, 8, 3, 0,
- 0, 2, 6,10,15,20,24,26,26,24,20,15,10, 6, 2, 0,
- 0, 1, 3, 6, 8,11,13,14,14,13,11, 8, 6, 3, 1, 0,
- 0, 0, 1, 2, 3, 4, 5, 5, 5, 5, 4, 3, 2, 1, 0, 0,
- 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
-//error:0.000022
-};
-#endif
-
-//linear *64
-static const uint8_t obmc8[64]={
- 4, 12, 20, 28, 28, 20, 12, 4,
- 12, 36, 60, 84, 84, 60, 36, 12,
- 20, 60,100,140,140,100, 60, 20,
- 28, 84,140,196,196,140, 84, 28,
- 28, 84,140,196,196,140, 84, 28,
- 20, 60,100,140,140,100, 60, 20,
- 12, 36, 60, 84, 84, 60, 36, 12,
- 4, 12, 20, 28, 28, 20, 12, 4,
-//error:0.000000
-};
-
-//linear *64
-static const uint8_t obmc4[16]={
- 16, 48, 48, 16,
- 48,144,144, 48,
- 48,144,144, 48,
- 16, 48, 48, 16,
-//error:0.000000
-};
-
-static const uint8_t *obmc_tab[4]={
- obmc32, obmc16, obmc8, obmc4
-};
-
-static int scale_mv_ref[MAX_REF_FRAMES][MAX_REF_FRAMES];
-
-typedef struct BlockNode{
- int16_t mx;
- int16_t my;
- uint8_t ref;
- uint8_t color[3];
- uint8_t type;
-//#define TYPE_SPLIT 1
-#define BLOCK_INTRA 1
-#define BLOCK_OPT 2
-//#define TYPE_NOCOLOR 4
- uint8_t level; //FIXME merge into type?
-}BlockNode;
-
-static const BlockNode null_block= { //FIXME add border maybe
- .color= {128,128,128},
- .mx= 0,
- .my= 0,
- .ref= 0,
- .type= 0,
- .level= 0,
-};
-
-#define LOG2_MB_SIZE 4
-#define MB_SIZE (1<<LOG2_MB_SIZE)
-
-typedef struct x_and_coeff{
- int16_t x;
- uint16_t coeff;
-} x_and_coeff;
-
-typedef struct SubBand{
- int level;
- int stride;
- int width;
- int height;
- int qlog; ///< log(qscale)/log[2^(1/6)]
- DWTELEM *buf;
- int buf_x_offset;
- int buf_y_offset;
- int stride_line; ///< Stride measured in lines, not pixels.
- x_and_coeff * x_coeff;
- struct SubBand *parent;
- uint8_t state[/*7*2*/ 7 + 512][32];
-}SubBand;
-
-typedef struct Plane{
- int width;
- int height;
- SubBand band[MAX_DECOMPOSITIONS][4];
-}Plane;
-
-typedef struct SnowContext{
-// MpegEncContext m; // needed for motion estimation, should not be used for anything else, the idea is to make the motion estimation eventually independant of MpegEncContext, so this will be removed then (FIXME/XXX)
-
- AVCodecContext *avctx;
- RangeCoder c;
- DSPContext dsp;
- AVFrame new_picture;
- AVFrame input_picture; ///< new_picture with the internal linesizes
- AVFrame current_picture;
- AVFrame last_picture[MAX_REF_FRAMES];
- AVFrame mconly_picture;
-// uint8_t q_context[16];
- uint8_t header_state[32];
- uint8_t block_state[128 + 32*128];
- int keyframe;
- int always_reset;
- int version;
- int spatial_decomposition_type;
- int last_spatial_decomposition_type;
- int temporal_decomposition_type;
- int spatial_decomposition_count;
- int temporal_decomposition_count;
- int max_ref_frames;
- int ref_frames;
- int16_t (*ref_mvs[MAX_REF_FRAMES])[2];
- uint32_t *ref_scores[MAX_REF_FRAMES];
- DWTELEM *spatial_dwt_buffer;
- int colorspace_type;
- int chroma_h_shift;
- int chroma_v_shift;
- int spatial_scalability;
- int qlog;
- int last_qlog;
- int lambda;
- int lambda2;
- int pass1_rc;
- int mv_scale;
- int last_mv_scale;
- int qbias;
- int last_qbias;
-#define QBIAS_SHIFT 3
- int b_width;
- int b_height;
- int block_max_depth;
- int last_block_max_depth;
- Plane plane[MAX_PLANES];
- BlockNode *block;
-#define ME_CACHE_SIZE 1024
- int me_cache[ME_CACHE_SIZE];
- int me_cache_generation;
- slice_buffer sb;
-
- MpegEncContext m; // needed for motion estimation, should not be used for anything else, the idea is to make the motion estimation eventually independant of MpegEncContext, so this will be removed then (FIXME/XXX)
-}SnowContext;
-
-typedef struct {
- DWTELEM *b0;
- DWTELEM *b1;
- DWTELEM *b2;
- DWTELEM *b3;
- int y;
-} dwt_compose_t;
-
-#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)))
-
-#ifdef CONFIG_ENCODERS
-static void iterative_me(SnowContext *s);
-#endif
-
-static void slice_buffer_init(slice_buffer * buf, int line_count, int max_allocated_lines, int line_width, DWTELEM * 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 = (DWTELEM * *) av_mallocz (sizeof(DWTELEM *) * line_count);
- buf->data_stack = (DWTELEM * *) av_malloc (sizeof(DWTELEM *) * max_allocated_lines);
-
- for (i = 0; i < max_allocated_lines; i++)
- {
- buf->data_stack[i] = (DWTELEM *) av_malloc (sizeof(DWTELEM) * line_width);
- }
-
- buf->data_stack_top = max_allocated_lines - 1;
-}
-
-static DWTELEM * slice_buffer_load_line(slice_buffer * buf, int line)
-{
- int offset;
- DWTELEM * buffer;
-
-// av_log(NULL, AV_LOG_DEBUG, "Cache hit: %d\n", line);
-
- assert(buf->data_stack_top >= 0);
-// assert(!buf->line[line]);
- if (buf->line[line])
- return buf->line[line];
-
- offset = buf->line_width * line;
- buffer = buf->data_stack[buf->data_stack_top];
- buf->data_stack_top--;
- buf->line[line] = buffer;
-
-// av_log(NULL, AV_LOG_DEBUG, "slice_buffer_load_line: line: %d remaining: %d\n", line, buf->data_stack_top + 1);
-
- return buffer;
-}
-
-static void slice_buffer_release(slice_buffer * buf, int line)
-{
- int offset;
- DWTELEM * buffer;
-
- assert(line >= 0 && line < buf->line_count);
- assert(buf->line[line]);
-
- offset = buf->line_width * line;
- buffer = buf->line[line];
- buf->data_stack_top++;
- buf->data_stack[buf->data_stack_top] = buffer;
- buf->line[line] = NULL;
-
-// av_log(NULL, AV_LOG_DEBUG, "slice_buffer_release: line: %d remaining: %d\n", line, buf->data_stack_top + 1);
-}
-
-static void slice_buffer_flush(slice_buffer * buf)
-{
- int i;
- for (i = 0; i < buf->line_count; i++)
- {
- if (buf->line[i])
- {
-// av_log(NULL, AV_LOG_DEBUG, "slice_buffer_flush: line: %d \n", 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--)
- {
- assert(buf->data_stack[i]);
- av_freep(&buf->data_stack[i]);
- }
- assert(buf->data_stack);
- av_freep(&buf->data_stack);
- assert(buf->line);
- av_freep(&buf->line);
-}
-
-#ifdef __sgi
-// Avoid a name clash on SGI IRIX
-#undef qexp
-#endif
-#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;
-
- if(v){
- const int a= FFABS(v);
- const int e= av_log2(a);
-#if 1
- const int el= FFMIN(e, 10);
- put_rac(c, state+0, 0);
-
- for(i=0; i<el; i++){
- put_rac(c, state+1+i, 1); //1..10
- }
- for(; i<e; i++){
- put_rac(c, state+1+9, 1); //1..10
- }
- put_rac(c, state+1+FFMIN(i,9), 0);
-
- for(i=e-1; i>=el; i--){
- put_rac(c, state+22+9, (a>>i)&1); //22..31
- }
- for(; i>=0; i--){
- put_rac(c, state+22+i, (a>>i)&1); //22..31
- }
-
- if(is_signed)
- put_rac(c, state+11 + el, v < 0); //11..21
-#else
-
- put_rac(c, state+0, 0);
- if(e<=9){
- for(i=0; i<e; i++){
- put_rac(c, state+1+i, 1); //1..10
- }
- put_rac(c, state+1+i, 0);
-
- for(i=e-1; i>=0; i--){
- put_rac(c, state+22+i, (a>>i)&1); //22..31
- }
-
- if(is_signed)
- put_rac(c, state+11 + e, v < 0); //11..21
- }else{
- for(i=0; i<e; i++){
- put_rac(c, state+1+FFMIN(i,9), 1); //1..10
- }
- put_rac(c, state+1+FFMIN(i,9), 0);
-
- for(i=e-1; i>=0; i--){
- put_rac(c, state+22+FFMIN(i,9), (a>>i)&1); //22..31
- }
-
- if(is_signed)
- put_rac(c, state+11 + FFMIN(e,10), v < 0); //11..21
- }
-#endif
- }else{
- put_rac(c, state+0, 1);
- }
-}
-
-static inline int get_symbol(RangeCoder *c, uint8_t *state, int is_signed){
- if(get_rac(c, state+0))
- return 0;
- else{
- int i, e, a;
- e= 0;
- while(get_rac(c, state+1 + FFMIN(e,9))){ //1..10
- e++;
- }
-
- a= 1;
- for(i=e-1; i>=0; i--){
- a += a + get_rac(c, state+22 + FFMIN(i,9)); //22..31
- }
-
- if(is_signed && get_rac(c, state+11 + FFMIN(e,10))) //11..21
- return -a;
- else
- return a;
- }
-}
-
-static inline void put_symbol2(RangeCoder *c, uint8_t *state, int v, int log2){
- int i;
- int r= log2>=0 ? 1<<log2 : 1;
-
- assert(v>=0);
- assert(log2>=-4);
-
- while(v >= r){
- put_rac(c, state+4+log2, 1);
- v -= r;
- log2++;
- if(log2>0) r+=r;
- }
- put_rac(c, state+4+log2, 0);
-
- for(i=log2-1; i>=0; i--){
- put_rac(c, state+31-i, (v>>i)&1);
- }
-}
-
-static inline int get_symbol2(RangeCoder *c, uint8_t *state, int log2){
- int i;
- int r= log2>=0 ? 1<<log2 : 1;
- int v=0;
-
- assert(log2>=-4);
-
- while(get_rac(c, state+4+log2)){
- v+= r;
- log2++;
- if(log2>0) r+=r;
- }
-
- for(i=log2-1; i>=0; i--){
- v+= get_rac(c, state+31-i)<<i;
- }
-
- 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<w; i++){
- dst[i*dst_step] = LIFT(src[i*src_step], ((mul*(ref[i*ref_step] + ref[(i+1)*ref_step])+add)>>shift), inverse);
- }
-
- if(mirror_right){
- dst[w*dst_step] = LIFT(src[w*src_step], ((mul*2*ref[w*ref_step]+add)>>shift), inverse);
- }
-}
-
-#ifndef lift5
-static av_always_inline void lift5(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;
-
- if(mirror_left){
- int r= 3*2*ref[0];
- r += r>>4;
- r += r>>8;
- dst[0] = LIFT(src[0], ((r+add)>>shift), inverse);
- dst += dst_step;
- src += src_step;
- }
-
- for(i=0; i<w; i++){
- int r= 3*(ref[i*ref_step] + ref[(i+1)*ref_step]);
- r += r>>4;
- r += r>>8;
- dst[i*dst_step] = LIFT(src[i*src_step], ((r+add)>>shift), inverse);
- }
-
- if(mirror_right){
- int r= 3*2*ref[w*ref_step];
- r += r>>4;
- r += r>>8;
- dst[w*dst_step] = LIFT(src[w*src_step], ((r+add)>>shift), inverse);
- }
-}
-#endif
-
-#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*4*(src) + 4*(ref) + 8 + (5<<27))/(5*16) - (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<w; i++){
- dst[i*dst_step] = LIFTS(src[i*src_step], mul*(ref[i*ref_step] + ref[(i+1)*ref_step])+add, inverse);
- }
-
- if(mirror_right){
- dst[w*dst_step] = LIFTS(src[w*src_step], mul*2*ref[w*ref_step]+add, inverse);
- }
-}
-#endif
-
-
-static void inplace_lift(DWTELEM *dst, int width, int *coeffs, int n, int shift, int start, int inverse){
- int x, i;
-
- for(x=start; x<width; x+=2){
- int64_t sum=0;
-
- for(i=0; i<n; i++){
- int x2= x + 2*i - n + 1;
- if (x2< 0) x2= -x2;
- else if(x2>=width) x2= 2*width-x2-2;
- sum += coeffs[i]*(int64_t)dst[x2];
- }
- if(inverse) dst[x] -= (sum + (1<<shift)/2)>>shift;
- else dst[x] += (sum + (1<<shift)/2)>>shift;
- }
-}
-
-static void inplace_liftV(DWTELEM *dst, int width, int height, int stride, int *coeffs, int n, int shift, int start, int inverse){
- int x, y, i;
- for(y=start; y<height; y+=2){
- for(x=0; x<width; x++){
- int64_t sum=0;
-
- for(i=0; i<n; i++){
- int y2= y + 2*i - n + 1;
- if (y2< 0) y2= -y2;
- else if(y2>=height) y2= 2*height-y2-2;
- sum += coeffs[i]*(int64_t)dst[x + y2*stride];
- }
- if(inverse) dst[x + y*stride] -= (sum + (1<<shift)/2)>>shift;
- else dst[x + y*stride] += (sum + (1<<shift)/2)>>shift;
- }
- }
-}
-
-#define SCALEX 1
-#define LX0 0
-#define LX1 1
-
-#if 0 // more accurate 9/7
-#define N1 2
-#define SHIFT1 14
-#define COEFFS1 (int[]){-25987,-25987}
-#define N2 2
-#define SHIFT2 19
-#define COEFFS2 (int[]){-27777,-27777}
-#define N3 2
-#define SHIFT3 15
-#define COEFFS3 (int[]){28931,28931}
-#define N4 2
-#define SHIFT4 15
-#define COEFFS4 (int[]){14533,14533}
-#elif 1 // 13/7 CRF
-#define N1 4
-#define SHIFT1 4
-#define COEFFS1 (int[]){1,-9,-9,1}
-#define N2 4
-#define SHIFT2 4
-#define COEFFS2 (int[]){-1,5,5,-1}
-#define N3 0
-#define SHIFT3 1
-#define COEFFS3 NULL
-#define N4 0
-#define SHIFT4 1
-#define COEFFS4 NULL
-#elif 1 // 3/5
-#define LX0 1
-#define LX1 0
-#define SCALEX 0.5
-#define N1 2
-#define SHIFT1 1
-#define COEFFS1 (int[]){1,1}
-#define N2 2
-#define SHIFT2 2
-#define COEFFS2 (int[]){-1,-1}
-#define N3 0
-#define SHIFT3 0
-#define COEFFS3 NULL
-#define N4 0
-#define SHIFT4 0
-#define COEFFS4 NULL
-#elif 1 // 11/5
-#define N1 0
-#define SHIFT1 1
-#define COEFFS1 NULL
-#define N2 2
-#define SHIFT2 2
-#define COEFFS2 (int[]){-1,-1}
-#define N3 2
-#define SHIFT3 0
-#define COEFFS3 (int[]){-1,-1}
-#define N4 4
-#define SHIFT4 7
-#define COEFFS4 (int[]){-5,29,29,-5}
-#define SCALEX 4
-#elif 1 // 9/7 CDF
-#define N1 2
-#define SHIFT1 7
-#define COEFFS1 (int[]){-203,-203}
-#define N2 2
-#define SHIFT2 12
-#define COEFFS2 (int[]){-217,-217}
-#define N3 2
-#define SHIFT3 7
-#define COEFFS3 (int[]){113,113}
-#define N4 2
-#define SHIFT4 9
-#define COEFFS4 (int[]){227,227}
-#define SCALEX 1
-#elif 1 // 7/5 CDF
-#define N1 0
-#define SHIFT1 1
-#define COEFFS1 NULL
-#define N2 2
-#define SHIFT2 2
-#define COEFFS2 (int[]){-1,-1}
-#define N3 2
-#define SHIFT3 0
-#define COEFFS3 (int[]){-1,-1}
-#define N4 2
-#define SHIFT4 4
-#define COEFFS4 (int[]){3,3}
-#elif 1 // 9/7 MN
-#define N1 4
-#define SHIFT1 4
-#define COEFFS1 (int[]){1,-9,-9,1}
-#define N2 2
-#define SHIFT2 2
-#define COEFFS2 (int[]){1,1}
-#define N3 0
-#define SHIFT3 1
-#define COEFFS3 NULL
-#define N4 0
-#define SHIFT4 1
-#define COEFFS4 NULL
-#else // 13/7 CRF
-#define N1 4
-#define SHIFT1 4
-#define COEFFS1 (int[]){1,-9,-9,1}
-#define N2 4
-#define SHIFT2 4
-#define COEFFS2 (int[]){-1,5,5,-1}
-#define N3 0
-#define SHIFT3 1
-#define COEFFS3 NULL
-#define N4 0
-#define SHIFT4 1
-#define COEFFS4 NULL
-#endif
-static void horizontal_decomposeX(DWTELEM *b, int width){
- DWTELEM temp[width];
- const int width2= width>>1;
- const int w2= (width+1)>>1;
- int x;
-
- inplace_lift(b, width, COEFFS1, N1, SHIFT1, LX1, 0);
- inplace_lift(b, width, COEFFS2, N2, SHIFT2, LX0, 0);
- inplace_lift(b, width, COEFFS3, N3, SHIFT3, LX1, 0);
- inplace_lift(b, width, COEFFS4, N4, SHIFT4, LX0, 0);
-
- for(x=0; x<width2; x++){
- temp[x ]= b[2*x ];
- temp[x+w2]= b[2*x + 1];
- }
- if(width&1)
- temp[x ]= b[2*x ];
- memcpy(b, temp, width*sizeof(int));
-}
-
-static void horizontal_composeX(DWTELEM *b, int width){
- DWTELEM temp[width];
- const int width2= width>>1;
- int x;
- const int w2= (width+1)>>1;
-
- memcpy(temp, b, width*sizeof(int));
- for(x=0; x<width2; x++){
- b[2*x ]= temp[x ];
- b[2*x + 1]= temp[x+w2];
- }
- if(width&1)
- b[2*x ]= temp[x ];
-
- inplace_lift(b, width, COEFFS4, N4, SHIFT4, LX0, 1);
- inplace_lift(b, width, COEFFS3, N3, SHIFT3, LX1, 1);
- inplace_lift(b, width, COEFFS2, N2, SHIFT2, LX0, 1);
- inplace_lift(b, width, COEFFS1, N1, SHIFT1, LX1, 1);
-}
-
-static void spatial_decomposeX(DWTELEM *buffer, int width, int height, int stride){
- int x, y;
-
- for(y=0; y<height; y++){
- for(x=0; x<width; x++){
- buffer[y*stride + x] *= SCALEX;
- }
- }
-
- for(y=0; y<height; y++){
- horizontal_decomposeX(buffer + y*stride, width);
- }
-
- inplace_liftV(buffer, width, height, stride, COEFFS1, N1, SHIFT1, LX1, 0);
- inplace_liftV(buffer, width, height, stride, COEFFS2, N2, SHIFT2, LX0, 0);
- inplace_liftV(buffer, width, height, stride, COEFFS3, N3, SHIFT3, LX1, 0);
- inplace_liftV(buffer, width, height, stride, COEFFS4, N4, SHIFT4, LX0, 0);
-}
-
-static void spatial_composeX(DWTELEM *buffer, int width, int height, int stride){
- int x, y;
-
- inplace_liftV(buffer, width, height, stride, COEFFS4, N4, SHIFT4, LX0, 1);
- inplace_liftV(buffer, width, height, stride, COEFFS3, N3, SHIFT3, LX1, 1);
- inplace_liftV(buffer, width, height, stride, COEFFS2, N2, SHIFT2, LX0, 1);
- inplace_liftV(buffer, width, height, stride, COEFFS1, N1, SHIFT1, LX1, 1);
-
- for(y=0; y<height; y++){
- horizontal_composeX(buffer + y*stride, width);
- }
-
- for(y=0; y<height; y++){
- for(x=0; x<width; x++){
- buffer[y*stride + x] /= SCALEX;
- }
- }
-}
-
-static void horizontal_decompose53i(DWTELEM *b, int width){
- DWTELEM temp[width];
- const int width2= width>>1;
- int x;
- const int w2= (width+1)>>1;
-
- for(x=0; x<width2; x++){
- temp[x ]= b[2*x ];
- temp[x+w2]= b[2*x + 1];
- }
- if(width&1)
- temp[x ]= b[2*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<width2; x+=2){
- A3= temp[x+width2];
- A4= temp[x+1 ];
- A3 -= (A2 + A4)>>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
-}
-
-static void vertical_decompose53iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
- int i;
-
- for(i=0; i<width; i++){
- b1[i] -= (b0[i] + b2[i])>>1;
- }
-}
-
-static void vertical_decompose53iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
- int i;
-
- for(i=0; i<width; i++){
- b1[i] += (b0[i] + b2[i] + 2)>>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<height; y+=2){
- DWTELEM *b2= buffer + mirror(y+1, height-1)*stride;
- DWTELEM *b3= buffer + mirror(y+2, height-1)*stride;
-
-{START_TIMER
- if(y+1<(unsigned)height) horizontal_decompose53i(b2, width);
- if(y+2<(unsigned)height) horizontal_decompose53i(b3, width);
-STOP_TIMER("horizontal_decompose53i")}
-
-{START_TIMER
- if(y+1<(unsigned)height) vertical_decompose53iH0(b1, b2, b3, width);
- if(y+0<(unsigned)height) vertical_decompose53iL0(b0, b1, b2, width);
-STOP_TIMER("vertical_decompose53i*")}
-
- b0=b2;
- b1=b3;
- }
-}
-
-static void horizontal_decompose97i(DWTELEM *b, int width){
- DWTELEM temp[width];
- const int w2= (width+1)>>1;
-
- lift (temp+w2, b +1, b , 1, 2, 2, width, -W_AM, W_AO, W_AS, 1, 0);
- liftS(temp , b , temp+w2, 1, 2, 1, width, -W_BM, W_BO, W_BS, 0, 0);
- lift5(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<width; i++){
- b1[i] -= (W_AM*(b0[i] + b2[i])+W_AO)>>W_AS;
- }
-}
-
-static void vertical_decompose97iH1(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
- int i;
-
- for(i=0; i<width; i++){
-#ifdef lift5
- b1[i] += (W_CM*(b0[i] + b2[i])+W_CO)>>W_CS;
-#else
- int r= 3*(b0[i] + b2[i]);
- r+= r>>4;
- r+= r>>8;
- b1[i] += (r+W_CO)>>W_CS;
-#endif
- }
-}
-
-static void vertical_decompose97iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
- int i;
-
- for(i=0; i<width; i++){
-#ifdef liftS
- b1[i] -= (W_BM*(b0[i] + b2[i])+W_BO)>>W_BS;
-#else
- b1[i] = (16*4*b1[i] - 4*(b0[i] + b2[i]) + 8*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<width; i++){
- b1[i] += (W_DM*(b0[i] + b2[i])+W_DO)>>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<height; y+=2){
- DWTELEM *b4= buffer + mirror(y+3, height-1)*stride;
- DWTELEM *b5= buffer + mirror(y+4, height-1)*stride;
-
-{START_TIMER
- if(y+3<(unsigned)height) horizontal_decompose97i(b4, width);
- if(y+4<(unsigned)height) horizontal_decompose97i(b5, width);
-if(width>400){
-STOP_TIMER("horizontal_decompose97i")
-}}
-
-{START_TIMER
- if(y+3<(unsigned)height) vertical_decompose97iH0(b3, b4, b5, width);
- if(y+2<(unsigned)height) vertical_decompose97iL0(b2, b3, b4, width);
- if(y+1<(unsigned)height) vertical_decompose97iH1(b1, b2, b3, width);
- if(y+0<(unsigned)height) vertical_decompose97iL1(b0, b1, b2, width);
-
-if(width>400){
-STOP_TIMER("vertical_decompose97i")
-}}
-
- b0=b2;
- b1=b3;
- b2=b4;
- b3=b5;
- }
-}
-
-void ff_spatial_dwt(DWTELEM *buffer, int width, int height, int stride, int type, int decomposition_count){
- int level;
-
- for(level=0; level<decomposition_count; level++){
- switch(type){
- case DWT_97: spatial_decompose97i(buffer, width>>level, height>>level, stride<<level); break;
- case DWT_53: spatial_decompose53i(buffer, width>>level, height>>level, stride<<level); break;
- case DWT_X: spatial_decomposeX (buffer, width>>level, height>>level, stride<<level); break;
- }
- }
-}
-
-static void horizontal_compose53i(DWTELEM *b, int width){
- DWTELEM temp[width];
- const int width2= width>>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<width2; x+=2){
- A3= temp[x+width2];
- A4= temp[x+1 ];
- A3 -= (A2 + A4)>>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(temp , b , b+w2, 1, 1, 1, width, 1, 2, 2, 0, 1);
- lift(temp+w2, b+w2, temp, 1, 1, 1, width, -1, 0, 1, 1, 1);
-#endif
- for(x=0; x<width2; x++){
- b[2*x ]= temp[x ];
- b[2*x + 1]= temp[x+w2];
- }
- if(width&1)
- b[2*x ]= temp[x ];
-}
-
-static void vertical_compose53iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
- int i;
-
- for(i=0; i<width; i++){
- b1[i] += (b0[i] + b2[i])>>1;
- }
-}
-
-static void vertical_compose53iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
- int i;
-
- for(i=0; i<width; i++){
- b1[i] -= (b0[i] + b2[i] + 2)>>2;
- }
-}
-
-static void spatial_compose53i_buffered_init(dwt_compose_t *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(dwt_compose_t *cs, DWTELEM *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(dwt_compose_t *cs, slice_buffer * sb, int width, int height, int stride_line){
- int y= cs->y;
-
- DWTELEM *b0= cs->b0;
- DWTELEM *b1= cs->b1;
- DWTELEM *b2= slice_buffer_get_line(sb, mirror(y+1, height-1) * stride_line);
- DWTELEM *b3= slice_buffer_get_line(sb, mirror(y+2, height-1) * stride_line);
-
-{START_TIMER
- if(y+1<(unsigned)height) vertical_compose53iL0(b1, b2, b3, width);
- if(y+0<(unsigned)height) vertical_compose53iH0(b0, b1, b2, width);
-STOP_TIMER("vertical_compose53i*")}
-
-{START_TIMER
- if(y-1<(unsigned)height) horizontal_compose53i(b0, width);
- if(y+0<(unsigned)height) horizontal_compose53i(b1, width);
-STOP_TIMER("horizontal_compose53i")}
-
- cs->b0 = b2;
- cs->b1 = b3;
- cs->y += 2;
-}
-
-static void spatial_compose53i_dy(dwt_compose_t *cs, DWTELEM *buffer, int width, int height, int stride){
- int y= cs->y;
- DWTELEM *b0= cs->b0;
- DWTELEM *b1= cs->b1;
- DWTELEM *b2= buffer + mirror(y+1, height-1)*stride;
- DWTELEM *b3= buffer + mirror(y+2, height-1)*stride;
-
-{START_TIMER
- if(y+1<(unsigned)height) vertical_compose53iL0(b1, b2, b3, width);
- if(y+0<(unsigned)height) vertical_compose53iH0(b0, b1, b2, width);
-STOP_TIMER("vertical_compose53i*")}
-
-{START_TIMER
- if(y-1<(unsigned)height) horizontal_compose53i(b0, width);
- if(y+0<(unsigned)height) horizontal_compose53i(b1, width);
-STOP_TIMER("horizontal_compose53i")}
-
- cs->b0 = b2;
- cs->b1 = b3;
- cs->y += 2;
-}
-
-static void spatial_compose53i(DWTELEM *buffer, int width, int height, int stride){
- dwt_compose_t 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(DWTELEM *b, int width){
- DWTELEM temp[width];
- const int w2= (width+1)>>1;
-
- lift (temp , b , b +w2, 1, 1, 1, width, W_DM, W_DO, W_DS, 0, 1);
- lift5(temp+w2, b +w2, temp , 1, 1, 1, width, W_CM, W_CO, W_CS, 1, 1);
- liftS(b , temp , temp+w2, 2, 1, 1, width, -W_BM, W_BO, W_BS, 0, 1);
- lift (b+1 , temp+w2, b , 2, 1, 2, width, -W_AM, W_AO, W_AS, 1, 1);
-}
-
-static void vertical_compose97iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
- int i;
-
- for(i=0; i<width; i++){
- b1[i] += (W_AM*(b0[i] + b2[i])+W_AO)>>W_AS;
- }
-}
-
-static void vertical_compose97iH1(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
- int i;
-
- for(i=0; i<width; i++){
-#ifdef lift5
- b1[i] -= (W_CM*(b0[i] + b2[i])+W_CO)>>W_CS;
-#else
- int r= 3*(b0[i] + b2[i]);
- r+= r>>4;
- r+= r>>8;
- b1[i] -= (r+W_CO)>>W_CS;
-#endif
- }
-}
-
-static void vertical_compose97iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
- int i;
-
- for(i=0; i<width; i++){
-#ifdef liftS
- b1[i] += (W_BM*(b0[i] + b2[i])+W_BO)>>W_BS;
-#else
- b1[i] += (W_BM*(b0[i] + b2[i])+4*b1[i]+W_BO)>>W_BS;
-#endif
- }
-}
-
-static void vertical_compose97iL1(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
- int i;
-
- for(i=0; i<width; i++){
- b1[i] -= (W_DM*(b0[i] + b2[i])+W_DO)>>W_DS;
- }
-}
-
-void ff_snow_vertical_compose97i(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWTELEM *b3, DWTELEM *b4, DWTELEM *b5, int width){
- int i;
-
- for(i=0; i<width; i++){
-#ifndef lift5
- int r;
-#endif
- b4[i] -= (W_DM*(b3[i] + b5[i])+W_DO)>>W_DS;
-#ifdef lift5
- b3[i] -= (W_CM*(b2[i] + b4[i])+W_CO)>>W_CS;
-#else
- r= 3*(b2[i] + b4[i]);
- r+= r>>4;
- r+= r>>8;
- b3[i] -= (r+W_CO)>>W_CS;
-#endif
-#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(dwt_compose_t *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(dwt_compose_t *cs, DWTELEM *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, dwt_compose_t *cs, slice_buffer * sb, int width, int height, int stride_line){
- int y = cs->y;
-
- DWTELEM *b0= cs->b0;
- DWTELEM *b1= cs->b1;
- DWTELEM *b2= cs->b2;
- DWTELEM *b3= cs->b3;
- DWTELEM *b4= slice_buffer_get_line(sb, mirror(y + 3, height - 1) * stride_line);
- DWTELEM *b5= slice_buffer_get_line(sb, mirror(y + 4, height - 1) * stride_line);
-
-{START_TIMER
- if(y>0 && y+4<height){
- dsp->vertical_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(width>400){
-STOP_TIMER("vertical_compose97i")}}
-
-{START_TIMER
- if(y-1<(unsigned)height) dsp->horizontal_compose97i(b0, width);
- if(y+0<(unsigned)height) dsp->horizontal_compose97i(b1, width);
-if(width>400 && y+0<(unsigned)height){
-STOP_TIMER("horizontal_compose97i")}}
-
- cs->b0=b2;
- cs->b1=b3;
- cs->b2=b4;
- cs->b3=b5;
- cs->y += 2;
-}
-
-static void spatial_compose97i_dy(dwt_compose_t *cs, DWTELEM *buffer, int width, int height, int stride){
- int y = cs->y;
- DWTELEM *b0= cs->b0;
- DWTELEM *b1= cs->b1;
- DWTELEM *b2= cs->b2;
- DWTELEM *b3= cs->b3;
- DWTELEM *b4= buffer + mirror(y+3, height-1)*stride;
- DWTELEM *b5= buffer + mirror(y+4, height-1)*stride;
-
-{START_TIMER
- 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(width>400){
-STOP_TIMER("vertical_compose97i")}}
-
-{START_TIMER
- if(y-1<(unsigned)height) ff_snow_horizontal_compose97i(b0, width);
- if(y+0<(unsigned)height) ff_snow_horizontal_compose97i(b1, width);
-if(width>400 && b0 <= b2){
-STOP_TIMER("horizontal_compose97i")}}
-
- cs->b0=b2;
- cs->b1=b3;
- cs->b2=b4;
- cs->b3=b5;
- cs->y += 2;
-}
-
-static void spatial_compose97i(DWTELEM *buffer, int width, int height, int stride){
- dwt_compose_t 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(dwt_compose_t *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); break;
- case DWT_53: spatial_compose53i_buffered_init(cs+level, sb, height>>level, stride_line<<level); break;
- /* not slicified yet */
- case DWT_X: /*spatial_composeX(buffer, width>>level, height>>level, stride<<level); break;*/
- av_log(NULL, AV_LOG_ERROR, "spatial_composeX neither buffered nor slicified yet.\n"); break;
- }
- }
-}
-
-static void ff_spatial_idwt_init(dwt_compose_t *cs, DWTELEM *buffer, int width, int height, int stride, int type, int decomposition_count){
- int level;
- for(level=decomposition_count-1; level>=0; level--){
- switch(type){
- case DWT_97: spatial_compose97i_init(cs+level, buffer, height>>level, stride<<level); break;
- case DWT_53: spatial_compose53i_init(cs+level, buffer, height>>level, stride<<level); break;
- /* not slicified yet */
- case DWT_X: spatial_composeX(buffer, width>>level, height>>level, stride<<level); break;
- }
- }
-}
-
-static void ff_spatial_idwt_slice(dwt_compose_t *cs, DWTELEM *buffer, int width, int height, int stride, int type, int decomposition_count, int y){
- const int support = type==1 ? 3 : 5;
- int level;
- if(type==2) return;
-
- for(level=decomposition_count-1; level>=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);
- break;
- case DWT_53: spatial_compose53i_dy(cs+level, buffer, width>>level, height>>level, stride<<level);
- break;
- case DWT_X: break;
- }
- }
- }
-}
-
-static void ff_spatial_idwt_buffered_slice(DSPContext *dsp, dwt_compose_t *cs, slice_buffer * slice_buf, int width, int height, int stride_line, int type, int decomposition_count, int y){
- const int support = type==1 ? 3 : 5;
- int level;
- if(type==2) return;
-
- for(level=decomposition_count-1; level>=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);
- break;
- case DWT_53: spatial_compose53i_dy_buffered(cs+level, slice_buf, width>>level, height>>level, stride_line<<level);
- break;
- case DWT_X: break;
- }
- }
- }
-}
-
-static void ff_spatial_idwt(DWTELEM *buffer, int width, int height, int stride, int type, int decomposition_count){
- if(type==2){
- int level;
- for(level=decomposition_count-1; level>=0; level--)
- spatial_composeX (buffer, width>>level, height>>level, stride<<level);
- }else{
- dwt_compose_t cs[MAX_DECOMPOSITIONS];
- int y;
- ff_spatial_idwt_init(cs, buffer, width, height, stride, type, decomposition_count);
- for(y=0; y<height; y+=4)
- ff_spatial_idwt_slice(cs, buffer, width, height, stride, type, decomposition_count, y);
- }
-}
-
-static int encode_subband_c0run(SnowContext *s, SubBand *b, DWTELEM *src, DWTELEM *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<h; y++){
- for(x=0; x<w; x++){
- int v, p=0;
- int /*ll=0, */l=0, lt=0, t=0, rt=0;
- v= src[x + y*stride];
-
- if(y){
- t= src[x + (y-1)*stride];
- if(x){
- lt= src[x - 1 + (y-1)*stride];
- }
- if(x + 1 < w){
- rt= src[x + 1 + (y-1)*stride];
- }
- }
- if(x){
- l= src[x - 1 + y*stride];
- /*if(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(px<b->parent->width && py<b->parent->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; y<h; y++){
- if(s->c.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<w; x++){
- int v, p=0;
- int /*ll=0, */l=0, lt=0, t=0, rt=0;
- v= src[x + y*stride];
-
- if(y){
- t= src[x + (y-1)*stride];
- if(x){
- lt= src[x - 1 + (y-1)*stride];
- }
- if(x + 1 < w){
- rt= src[x + 1 + (y-1)*stride];
- }
- }
- if(x){
- l= src[x - 1 + y*stride];
- /*if(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(px<b->parent->width && py<b->parent->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, DWTELEM *src, DWTELEM *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;
-
- 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; y<h; y++){
- int v=0;
- int lt=0, t=0, rt=0;
-
- if(y && prev_xc->x == 0){
- rt= prev_xc->coeff;
- }
- for(x=0; x<w; x++){
- int p=0;
- const int l= v;
-
- lt= t; t= rt;
-
- if(y){
- if(prev_xc->x <= 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++;
- 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]){
- const int w= b->width;
- int y;
- const int qlog= clip(s->qlog + b->qlog, 0, QROOT*16);
- int qmul= qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT);
- int qadd= (s->qbias*qmul)>>QBIAS_SHIFT;
- int new_index = 0;
-
- START_TIMER
-
- if(b->buf == s->spatial_dwt_buffer || s->qlog == LOSSLESS_QLOG){
- qadd= 0;
- qmul= 1<<QEXPSHIFT;
- }
-
- /* If we are on the second or later slice, restore our index. */
- if (start_y != 0)
- new_index = save_state[0];
-
-
- for(y=start_y; y<h; y++){
- int x = 0;
- int v;
- DWTELEM * line = slice_buffer_get_line(sb, y * b->stride_line + b->buf_y_offset) + b->buf_x_offset;
- memset(line, 0, b->width*sizeof(DWTELEM));
- v = b->x_coeff[new_index].coeff;
- x = b->x_coeff[new_index++].x;
- while(x < w)
- {
- register int t= ( (v>>1)*qmul + qadd)>>QEXPSHIFT;
- register int u= -(v&1);
- line[x] = (t^u) - u;
-
- v = b->x_coeff[new_index].coeff;
- x = b->x_coeff[new_index++].x;
- }
- }
- if(w > 200 && start_y != 0/*level+1 == s->spatial_decomposition_count*/){
- STOP_TIMER("decode_subband")
- }
-
- /* Save our variables for the next slice. */
- save_state[0] = new_index;
-
- return;
-}
-
-static void reset_contexts(SnowContext *s){ //FIXME better initial contexts
- int plane_index, level, orientation;
-
- for(plane_index=0; plane_index<3; plane_index++){
- for(level=0; level<s->spatial_decomposition_count; level++){
- for(orientation=level ? 1:0; orientation<4; orientation++){
- memset(s->plane[plane_index].band[level][orientation].state, MID_STATE, sizeof(s->plane[plane_index].band[level][orientation].state));
- }
- }
- }
- memset(s->header_state, MID_STATE, sizeof(s->header_state));
- memset(s->block_state, MID_STATE, sizeof(s->block_state));
-}
-
-static int alloc_blocks(SnowContext *s){
- int w= -((-s->avctx->width )>>LOG2_MB_SIZE);
- int h= -((-s->avctx->height)>>LOG2_MB_SIZE);
-
- s->b_width = w;
- s->b_height= h;
-
- s->block= av_mallocz(w * h * sizeof(BlockNode) << (s->block_max_depth*2));
- return 0;
-}
-
-static inline void copy_rac_state(RangeCoder *d, RangeCoder *s){
- uint8_t *bytestream= d->bytestream;
- uint8_t *bytestream_start= d->bytestream_start;
- *d= *s;
- d->bytestream= bytestream;
- 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;
- const int index= (x + y*w) << rem_depth;
- const int block_w= 1<<rem_depth;
- BlockNode block;
- int i,j;
-
- block.color[0]= l;
- block.color[1]= cb;
- block.color[2]= cr;
- block.mx= mx;
- block.my= my;
- block.ref= ref;
- block.type= type;
- block.level= level;
-
- for(j=0; j<block_w; j++){
- for(i=0; i<block_w; i++){
- s->block[index + i + j*w]= block;
- }
- }
-}
-
-static inline void init_ref(MotionEstContext *c, uint8_t *src[3], uint8_t *ref[3], uint8_t *ref2[3], int x, int y, int ref_index){
- const int offset[3]= {
- y*c-> stride + x,
- ((y*c->uvstride + x)>>1),
- ((y*c->uvstride + x)>>1),
- };
- int i;
- for(i=0; i<3; i++){
- c->src[0][i]= src [i];
- c->ref[0][i]= ref [i] + offset[i];
- }
- assert(!ref_index);
-}
-
-static inline void pred_mv(SnowContext *s, int *mx, int *my, int ref,
- const BlockNode *left, const BlockNode *top, const BlockNode *tr){
- if(s->ref_frames == 1){
- *mx = mid_pred(left->mx, top->mx, tr->mx);
- *my = mid_pred(left->my, top->my, tr->my);
- }else{
- const int *scale = scale_mv_ref[ref];
- *mx = mid_pred((left->mx * scale[left->ref] + 128) >>8,
- (top ->mx * scale[top ->ref] + 128) >>8,
- (tr ->mx * scale[tr ->ref] + 128) >>8);
- *my = mid_pred((left->my * scale[left->ref] + 128) >>8,
- (top ->my * scale[top ->ref] + 128) >>8,
- (tr ->my * scale[tr ->ref] + 128) >>8);
- }
-}
-
-//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
-
-#ifdef CONFIG_ENCODERS
-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;
- 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)<<rem_depth;
- int try= (y+1)<<rem_depth;
- const BlockNode *left = x ? &s->block[index-1] : &null_block;
- const BlockNode *top = y ? &s->block[index-w] : &null_block;
- const BlockNode *right = trx<w ? &s->block[index+1] : &null_block;
- const BlockNode *bottom= try<h ? &s->block[index+w] : &null_block;
- const BlockNode *tl = y && x ? &s->block[index-w-1] : left;
- const BlockNode *tr = y && trx<w && ((x&1)==0 || level==0) ? &s->block[index-w+(1<<rem_depth)] : tl; //FIXME use lt
- int pl = left->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+2;
- c->ymin = - y*block_w - 16+2;
- c->xmax = - (x+1)*block_w + (w<<(LOG2_MB_SIZE - s->block_max_depth)) + 16-2;
- c->ymax = - (y+1)*block_w + (h<<(LOG2_MB_SIZE - s->block_max_depth)) + 16-2;
-
- if(P_LEFT[0] > (c->xmax<<shift)) P_LEFT[0] = (c->xmax<<shift);
- if(P_LEFT[1] > (c->ymax<<shift)) P_LEFT[1] = (c->ymax<<shift);
- if(P_TOP[0] > (c->xmax<<shift)) P_TOP[0] = (c->xmax<<shift);
- if(P_TOP[1] > (c->ymax<<shift)) P_TOP[1] = (c->ymax<<shift);
- if(P_TOPRIGHT[0] < (c->xmin<<shift)) P_TOPRIGHT[0]= (c->xmin<<shift);
- if(P_TOPRIGHT[0] > (c->xmax<<shift)) P_TOPRIGHT[0]= (c->xmax<<shift); //due to pmx no clip
- if(P_TOPRIGHT[1] > (c->ymax<<shift)) P_TOPRIGHT[1]= (c->ymax<<shift);
-
- P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
- P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);
-
- if (!y) {
- c->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; ref<s->ref_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 cant be compared currently and mb_penalty vs. lambda2
-
- // subpel search
- 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*(p_len*8
- + (pc.outstanding_count - s->c.outstanding_count)*8
- + (-av_log2(pc.range) + av_log2(s->c.range))
- ))>>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(&current_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(&current_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*(i_len*8
- + (ic.outstanding_count - s->c.outstanding_count)*8
- + (-av_log2(ic.range) + av_log2(s->c.range))
- ))>>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;
- }
-}
-#endif
-
-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]));
- }else{
- return !((a->mx - b->mx) | (a->my - b->my) | (a->ref - b->ref) | ((a->type ^ b->type)&BLOCK_INTRA));
- }
-}
-
-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)<<rem_depth;
- BlockNode *b= &s->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 && trx<w && ((x&1)==0 || level==0) ? &s->block[index-w+(1<<rem_depth)] : tl; //FIXME use lt
- int pl = left->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;
- const int index= (x + y*w) << rem_depth;
- int trx= (x+1)<<rem_depth;
- 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 && trx<w && ((x&1)==0 || level==0) ? &s->block[index-w+(1<<rem_depth)] : tl; //FIXME use lt
- int s_context= 2*left->level + 2*top->level + tl->level + tr->level;
-
- if(s->keyframe){
- set_blocks(s, level, x, y, null_block.color[0], null_block.color[1], null_block.color[2], null_block.mx, null_block.my, null_block.ref, BLOCK_INTRA);
- return;
- }
-
- if(level==s->block_max_depth || get_rac(&s->c, &s->block_state[4 + s_context])){
- int type, mx, my;
- int l = left->color[0];
- int cb= left->color[1];
- int cr= left->color[2];
- int ref = 0;
- int ref_context= av_log2(2*left->ref) + av_log2(2*top->ref);
- int mx_context= av_log2(2*FFABS(left->mx - top->mx)) + 0*av_log2(2*FFABS(tr->mx - top->mx));
- int my_context= av_log2(2*FFABS(left->my - top->my)) + 0*av_log2(2*FFABS(tr->my - top->my));
-
- type= get_rac(&s->c, &s->block_state[1 + left->type + top->type]) ? BLOCK_INTRA : 0;
-
- if(type){
- pred_mv(s, &mx, &my, 0, left, top, tr);
- l += get_symbol(&s->c, &s->block_state[32], 1);
- cb+= get_symbol(&s->c, &s->block_state[64], 1);
- cr+= get_symbol(&s->c, &s->block_state[96], 1);
- }else{
- if(s->ref_frames > 1)
- ref= get_symbol(&s->c, &s->block_state[128 + 1024 + 32*ref_context], 0);
- pred_mv(s, &mx, &my, ref, left, top, tr);
- mx+= get_symbol(&s->c, &s->block_state[128 + 32*(mx_context + 16*!!ref)], 1);
- my+= get_symbol(&s->c, &s->block_state[128 + 32*(my_context + 16*!!ref)], 1);
- }
- set_blocks(s, level, x, y, l, cb, cr, mx, my, ref, type);
- }else{
- decode_q_branch(s, level+1, 2*x+0, 2*y+0);
- decode_q_branch(s, level+1, 2*x+1, 2*y+0);
- decode_q_branch(s, level+1, 2*x+0, 2*y+1);
- decode_q_branch(s, level+1, 2*x+1, 2*y+1);
- }
-}
-
-#ifdef CONFIG_ENCODERS
-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; y<h; y++){
- if(s->c.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; x<w; x++){
- if(s->avctx->me_method == ME_ITER || !search)
- encode_q_branch2(s, 0, x, y);
- else
- encode_q_branch (s, 0, x, y);
- }
- }
-}
-#endif
-
-static void decode_blocks(SnowContext *s){
- int x, y;
- int w= s->b_width;
- int h= s->b_height;
-
- for(y=0; y<h; y++){
- for(x=0; x<w; x++){
- decode_q_branch(s, 0, x, y);
- }
- }
-}
-
-static void mc_block(uint8_t *dst, uint8_t *src, uint8_t *tmp, int stride, int b_w, int b_h, int dx, int dy){
- int x, y;
-START_TIMER
- for(y=0; y < b_h+5; y++){
- for(x=0; x < b_w; x++){
- int a0= src[x ];
- int a1= src[x + 1];
- int a2= src[x + 2];
- int a3= src[x + 3];
- int a4= src[x + 4];
- int a5= src[x + 5];
-// int am= 9*(a1+a2) - (a0+a3);
- int am= 20*(a2+a3) - 5*(a1+a4) + (a0+a5);
-// int am= 18*(a2+a3) - 2*(a1+a4);
-// int aL= (-7*a0 + 105*a1 + 35*a2 - 5*a3)>>3;
-// int aR= (-7*a3 + 105*a2 + 35*a1 - 5*a0)>>3;
-
-// if(b_w==16) am= 8*(a1+a2);
-
- if(dx<8) am = (32*a2*( 8-dx) + am* dx + 128)>>8;
- else am = ( am*(16-dx) + 32*a3*(dx-8) + 128)>>8;
-
- /* FIXME Try increasing tmp buffer to 16 bits and not clipping here. Should give marginally better results. - Robert*/
- if(am&(~255)) am= ~(am>>31);
-
- tmp[x] = am;
-
-/* if (dx< 4) tmp[x + y*stride]= (16*a1*( 4-dx) + aL* dx + 32)>>6;
- else if(dx< 8) tmp[x + y*stride]= ( aL*( 8-dx) + am*(dx- 4) + 32)>>6;
- else if(dx<12) tmp[x + y*stride]= ( am*(12-dx) + aR*(dx- 8) + 32)>>6;
- else tmp[x + y*stride]= ( aR*(16-dx) + 16*a2*(dx-12) + 32)>>6;*/
- }
- tmp += stride;
- src += stride;
- }
- tmp -= (b_h+5)*stride;
-
- for(y=0; y < b_h; y++){
- for(x=0; x < b_w; x++){
- int a0= tmp[x + 0*stride];
- int a1= tmp[x + 1*stride];
- int a2= tmp[x + 2*stride];
- int a3= tmp[x + 3*stride];
- int a4= tmp[x + 4*stride];
- int a5= tmp[x + 5*stride];
- int am= 20*(a2+a3) - 5*(a1+a4) + (a0+a5);
-// int am= 18*(a2+a3) - 2*(a1+a4);
-/* int aL= (-7*a0 + 105*a1 + 35*a2 - 5*a3)>>3;
- int aR= (-7*a3 + 105*a2 + 35*a1 - 5*a0)>>3;*/
-
-// if(b_w==16) am= 8*(a1+a2);
-
- if(dy<8) am = (32*a2*( 8-dy) + am* dy + 128)>>8;
- else am = ( am*(16-dy) + 32*a3*(dy-8) + 128)>>8;
-
- if(am&(~255)) am= ~(am>>31);
-
- dst[x] = am;
-/* if (dy< 4) tmp[x + y*stride]= (16*a1*( 4-dy) + aL* dy + 32)>>6;
- else if(dy< 8) tmp[x + y*stride]= ( aL*( 8-dy) + am*(dy- 4) + 32)>>6;
- else if(dy<12) tmp[x + y*stride]= ( am*(12-dy) + aR*(dy- 8) + 32)>>6;
- else tmp[x + y*stride]= ( aR*(16-dy) + 16*a2*(dy-12) + 32)>>6;*/
- }
- dst += stride;
- tmp += stride;
- }
-STOP_TIMER("mc_block")
-}
-
-#define mca(dx,dy,b_w)\
-static void mc_block_hpel ## dx ## dy ## b_w(uint8_t *dst, uint8_t *src, int stride, int h){\
- uint8_t tmp[stride*(b_w+5)];\
- assert(h==b_w);\
- mc_block(dst, src-2-2*stride, tmp, stride, b_w, b_w, dx, dy);\
-}
-
-mca( 0, 0,16)
-mca( 8, 0,16)
-mca( 0, 8,16)
-mca( 8, 8,16)
-mca( 0, 0,8)
-mca( 8, 0,8)
-mca( 0, 8,8)
-mca( 8, 8,8)
-
-static void pred_block(SnowContext *s, uint8_t *dst, uint8_t *tmp, int stride, int sx, int sy, int b_w, int b_h, BlockNode *block, int plane_index, int w, int h){
- if(block->type & BLOCK_INTRA){
- int x, y;
- const int color = block->color[plane_index];
- const int color4= color*0x01010101;
- if(b_w==32){
- for(y=0; y < b_h; y++){
- *(uint32_t*)&dst[0 + y*stride]= color4;
- *(uint32_t*)&dst[4 + y*stride]= color4;
- *(uint32_t*)&dst[8 + y*stride]= color4;
- *(uint32_t*)&dst[12+ y*stride]= color4;
- *(uint32_t*)&dst[16+ y*stride]= color4;
- *(uint32_t*)&dst[20+ y*stride]= color4;
- *(uint32_t*)&dst[24+ y*stride]= color4;
- *(uint32_t*)&dst[28+ y*stride]= color4;
- }
- }else if(b_w==16){
- for(y=0; y < b_h; y++){
- *(uint32_t*)&dst[0 + y*stride]= color4;
- *(uint32_t*)&dst[4 + y*stride]= color4;
- *(uint32_t*)&dst[8 + y*stride]= color4;
- *(uint32_t*)&dst[12+ y*stride]= color4;
- }
- }else if(b_w==8){
- for(y=0; y < b_h; y++){
- *(uint32_t*)&dst[0 + y*stride]= color4;
- *(uint32_t*)&dst[4 + y*stride]= color4;
- }
- }else if(b_w==4){
- for(y=0; y < b_h; y++){
- *(uint32_t*)&dst[0 + y*stride]= color4;
- }
- }else{
- for(y=0; y < b_h; y++){
- for(x=0; x < b_w; x++){
- dst[x + y*stride]= color;
- }
- }
- }
- }else{
- uint8_t *src= s->last_picture[block->ref].data[plane_index];
- const int scale= plane_index ? s->mv_scale : 2*s->mv_scale;
- int mx= block->mx*scale;
- int my= block->my*scale;
- const int dx= mx&15;
- const int dy= my&15;
- const int tab_index= 3 - (b_w>>2) + (b_w>>4);
- sx += (mx>>4) - 2;
- sy += (my>>4) - 2;
- src += sx + sy*stride;
- if( (unsigned)sx >= w - b_w - 4
- || (unsigned)sy >= h - b_h - 4){
- ff_emulated_edge_mc(tmp + MB_SIZE, src, stride, b_w+5, b_h+5, sx, sy, w, h);
- src= tmp + MB_SIZE;
- }
-// assert(b_w == b_h || 2*b_w == b_h || b_w == 2*b_h);
-// assert(!(b_w&(b_w-1)));
- assert(b_w>1 && b_h>1);
- assert(tab_index>=0 && tab_index<4 || b_w==32);
- if((dx&3) || (dy&3) || !(b_w == b_h || 2*b_w == b_h || b_w == 2*b_h) || (b_w&(b_w-1)))
- mc_block(dst, src, tmp, stride, b_w, b_h, dx, dy);
- else if(b_w==32){
- int y;
- for(y=0; y<b_h; y+=16){
- s->dsp.put_h264_qpel_pixels_tab[0][dy+(dx>>2)](dst + y*stride, src + 2 + (y+2)*stride,stride);
- s->dsp.put_h264_qpel_pixels_tab[0][dy+(dx>>2)](dst + 16 + y*stride, src + 18 + (y+2)*stride,stride);
- }
- }else if(b_w==b_h)
- s->dsp.put_h264_qpel_pixels_tab[tab_index ][dy+(dx>>2)](dst,src + 2 + 2*stride,stride);
- else if(b_w==2*b_h){
- s->dsp.put_h264_qpel_pixels_tab[tab_index+1][dy+(dx>>2)](dst ,src + 2 + 2*stride,stride);
- s->dsp.put_h264_qpel_pixels_tab[tab_index+1][dy+(dx>>2)](dst+b_h,src + 2 + b_h + 2*stride,stride);
- }else{
- assert(2*b_w==b_h);
- s->dsp.put_h264_qpel_pixels_tab[tab_index ][dy+(dx>>2)](dst ,src + 2 + 2*stride ,stride);
- s->dsp.put_h264_qpel_pixels_tab[tab_index ][dy+(dx>>2)](dst+b_w*stride,src + 2 + 2*stride+b_w*stride,stride);
- }
- }
-}
-
-void ff_snow_inner_add_yblock(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 y, x;
- DWTELEM * dst;
- for(y=0; y<b_h; y++){
- //FIXME ugly missue of obmc_stride
- uint8_t *obmc1= obmc + y*obmc_stride;
- uint8_t *obmc2= obmc1+ (obmc_stride>>1);
- uint8_t *obmc3= obmc1+ obmc_stride*(obmc_stride>>1);
- uint8_t *obmc4= obmc3+ (obmc_stride>>1);
- dst = slice_buffer_get_line(sb, src_y + y);
- for(x=0; x<b_w; x++){
- int v= obmc1[x] * block[3][x + y*src_stride]
- +obmc2[x] * block[2][x + y*src_stride]
- +obmc3[x] * block[1][x + y*src_stride]
- +obmc4[x] * block[0][x + y*src_stride];
-
- v <<= 8 - LOG2_OBMC_MAX;
- if(FRAC_BITS != 8){
- v += 1<<(7 - FRAC_BITS);
- v >>= 8 - FRAC_BITS;
- }
- if(add){
- v += dst[x + src_x];
- v = (v + (1<<(FRAC_BITS-1))) >> FRAC_BITS;
- if(v&(~255)) v= ~(v>>31);
- dst8[x + y*src_stride] = v;
- }else{
- dst[x + src_x] -= v;
- }
- }
- }
-}
-
-//FIXME name clenup (b_w, block_w, b_width stuff)
-static av_always_inline void add_yblock(SnowContext *s, int sliced, slice_buffer *sb, DWTELEM *dst, uint8_t *dst8, const uint8_t *obmc, int src_x, int src_y, int b_w, int b_h, int w, int h, int dst_stride, int src_stride, int obmc_stride, int b_x, int b_y, int add, int offset_dst, int plane_index){
- const int b_width = s->b_width << s->block_max_depth;
- const int b_height= s->b_height << s->block_max_depth;
- const int b_stride= b_width;
- BlockNode *lt= &s->block[b_x + b_y*b_stride];
- BlockNode *rt= lt+1;
- BlockNode *lb= lt+b_stride;
- BlockNode *rb= lb+1;
- uint8_t *block[4];
- int tmp_step= src_stride >= 7*MB_SIZE ? MB_SIZE : MB_SIZE*src_stride;
- uint8_t tmp[src_stride*7*MB_SIZE]; //FIXME align
- uint8_t *ptmp;
- int x,y;
-
- if(b_x<0){
- lt= rt;
- lb= rb;
- }else if(b_x + 1 >= b_width){
- rt= lt;
- rb= lb;
- }
- if(b_y<0){
- lt= lb;
- rt= rb;
- }else if(b_y + 1 >= b_height){
- lb= lt;
- rb= rt;
- }
-
- if(src_x<0){ //FIXME merge with prev & always round internal width upto *16
- obmc -= src_x;
- b_w += src_x;
- if(!sliced && !offset_dst)
- dst -= src_x;
- src_x=0;
- }else if(src_x + b_w > w){
- b_w = w - src_x;
- }
- if(src_y<0){
- obmc -= src_y*obmc_stride;
- b_h += src_y;
- if(!sliced && !offset_dst)
- dst -= src_y*dst_stride;
- src_y=0;
- }else if(src_y + b_h> h){
- b_h = h - src_y;
- }
-
- if(b_w<=0 || b_h<=0) return;
-
-assert(src_stride > 2*MB_SIZE + 5);
- if(!sliced && offset_dst)
- dst += src_x + src_y*dst_stride;
- dst8+= src_x + src_y*src_stride;
-// src += src_x + src_y*src_stride;
-
- ptmp= tmp + 3*tmp_step;
- block[0]= ptmp;
- ptmp+=tmp_step;
- pred_block(s, block[0], tmp, src_stride, src_x, src_y, b_w, b_h, lt, plane_index, w, h);
-
- if(same_block(lt, rt)){
- block[1]= block[0];
- }else{
- block[1]= ptmp;
- ptmp+=tmp_step;
- pred_block(s, block[1], tmp, src_stride, src_x, src_y, b_w, b_h, rt, plane_index, w, h);
- }
-
- if(same_block(lt, lb)){
- block[2]= block[0];
- }else if(same_block(rt, lb)){
- block[2]= block[1];
- }else{
- block[2]= ptmp;
- ptmp+=tmp_step;
- pred_block(s, block[2], tmp, src_stride, src_x, src_y, b_w, b_h, lb, plane_index, w, h);
- }
-
- if(same_block(lt, rb) ){
- block[3]= block[0];
- }else if(same_block(rt, rb)){
- block[3]= block[1];
- }else if(same_block(lb, rb)){
- block[3]= block[2];
- }else{
- block[3]= ptmp;
- pred_block(s, block[3], tmp, src_stride, src_x, src_y, b_w, b_h, rb, plane_index, w, h);
- }
-#if 0
- for(y=0; y<b_h; y++){
- for(x=0; x<b_w; x++){
- int v= obmc [x + y*obmc_stride] * block[3][x + y*src_stride] * (256/OBMC_MAX);
- if(add) dst[x + y*dst_stride] += v;
- else dst[x + y*dst_stride] -= v;
- }
- }
- for(y=0; y<b_h; y++){
- uint8_t *obmc2= obmc + (obmc_stride>>1);
- for(x=0; x<b_w; x++){
- int v= obmc2[x + y*obmc_stride] * block[2][x + y*src_stride] * (256/OBMC_MAX);
- if(add) dst[x + y*dst_stride] += v;
- else dst[x + y*dst_stride] -= v;
- }
- }
- for(y=0; y<b_h; y++){
- uint8_t *obmc3= obmc + obmc_stride*(obmc_stride>>1);
- for(x=0; x<b_w; x++){
- int v= obmc3[x + y*obmc_stride] * block[1][x + y*src_stride] * (256/OBMC_MAX);
- if(add) dst[x + y*dst_stride] += v;
- else dst[x + y*dst_stride] -= v;
- }
- }
- for(y=0; y<b_h; y++){
- uint8_t *obmc3= obmc + obmc_stride*(obmc_stride>>1);
- uint8_t *obmc4= obmc3+ (obmc_stride>>1);
- for(x=0; x<b_w; x++){
- int v= obmc4[x + y*obmc_stride] * block[0][x + y*src_stride] * (256/OBMC_MAX);
- if(add) dst[x + y*dst_stride] += v;
- else dst[x + y*dst_stride] -= v;
- }
- }
-#else
- if(sliced){
- START_TIMER
-
- s->dsp.inner_add_yblock(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8);
- STOP_TIMER("inner_add_yblock")
- }else
- for(y=0; y<b_h; y++){
- //FIXME ugly missue of obmc_stride
- uint8_t *obmc1= obmc + y*obmc_stride;
- uint8_t *obmc2= obmc1+ (obmc_stride>>1);
- uint8_t *obmc3= obmc1+ obmc_stride*(obmc_stride>>1);
- uint8_t *obmc4= obmc3+ (obmc_stride>>1);
- for(x=0; x<b_w; x++){
- int v= obmc1[x] * block[3][x + y*src_stride]
- +obmc2[x] * block[2][x + y*src_stride]
- +obmc3[x] * block[1][x + y*src_stride]
- +obmc4[x] * block[0][x + y*src_stride];
-
- v <<= 8 - LOG2_OBMC_MAX;
- if(FRAC_BITS != 8){
- v += 1<<(7 - FRAC_BITS);
- v >>= 8 - FRAC_BITS;
- }
- if(add){
- v += dst[x + y*dst_stride];
- v = (v + (1<<(FRAC_BITS-1))) >> FRAC_BITS;
- if(v&(~255)) v= ~(v>>31);
- dst8[x + y*src_stride] = v;
- }else{
- dst[x + y*dst_stride] -= v;
- }
- }
- }
-#endif
-}
-
-static av_always_inline void predict_slice_buffered(SnowContext *s, slice_buffer * sb, DWTELEM * old_buffer, int plane_index, int add, int mb_y){
- Plane *p= &s->plane[plane_index];
- const int mb_w= s->b_width << s->block_max_depth;
- const int mb_h= s->b_height << s->block_max_depth;
- int x, y, mb_x;
- int block_size = MB_SIZE >> s->block_max_depth;
- int block_w = plane_index ? block_size/2 : block_size;
- const uint8_t *obmc = plane_index ? obmc_tab[s->block_max_depth+1] : obmc_tab[s->block_max_depth];
- int obmc_stride= plane_index ? block_size : 2*block_size;
- int ref_stride= s->current_picture.linesize[plane_index];
- uint8_t *dst8= s->current_picture.data[plane_index];
- int w= p->width;
- int h= p->height;
- START_TIMER
-
- if(s->keyframe || (s->avctx->debug&512)){
- if(mb_y==mb_h)
- return;
-
- if(add){
- for(y=block_w*mb_y; y<FFMIN(h,block_w*(mb_y+1)); y++)
- {
-// DWTELEM * line = slice_buffer_get_line(sb, y);
- DWTELEM * line = sb->line[y];
- for(x=0; x<w; x++)
- {
-// int v= buf[x + y*w] + (128<<FRAC_BITS) + (1<<(FRAC_BITS-1));
- int v= line[x] + (128<<FRAC_BITS) + (1<<(FRAC_BITS-1));
- v >>= FRAC_BITS;
- if(v&(~255)) v= ~(v>>31);
- dst8[x + y*ref_stride]= v;
- }
- }
- }else{
- for(y=block_w*mb_y; y<FFMIN(h,block_w*(mb_y+1)); y++)
- {
-// DWTELEM * line = slice_buffer_get_line(sb, y);
- DWTELEM * line = sb->line[y];
- for(x=0; x<w; x++)
- {
- line[x] -= 128 << FRAC_BITS;
-// buf[x + y*w]-= 128<<FRAC_BITS;
- }
- }
- }
-
- return;
- }
-
- for(mb_x=0; mb_x<=mb_w; mb_x++){
- START_TIMER
-
- add_yblock(s, 1, sb, old_buffer, dst8, obmc,
- block_w*mb_x - block_w/2,
- block_w*mb_y - block_w/2,
- block_w, block_w,
- w, h,
- w, ref_stride, obmc_stride,
- mb_x - 1, mb_y - 1,
- add, 0, plane_index);
-
- STOP_TIMER("add_yblock")
- }
-
- STOP_TIMER("predict_slice")
-}
-
-static av_always_inline void predict_slice(SnowContext *s, DWTELEM *buf, int plane_index, int add, int mb_y){
- Plane *p= &s->plane[plane_index];
- const int mb_w= s->b_width << s->block_max_depth;
- const int mb_h= s->b_height << s->block_max_depth;
- int x, y, mb_x;
- int block_size = MB_SIZE >> s->block_max_depth;
- int block_w = plane_index ? block_size/2 : block_size;
- const uint8_t *obmc = plane_index ? obmc_tab[s->block_max_depth+1] : obmc_tab[s->block_max_depth];
- const int obmc_stride= plane_index ? block_size : 2*block_size;
- int ref_stride= s->current_picture.linesize[plane_index];
- uint8_t *dst8= s->current_picture.data[plane_index];
- int w= p->width;
- int h= p->height;
- START_TIMER
-
- if(s->keyframe || (s->avctx->debug&512)){
- if(mb_y==mb_h)
- return;
-
- if(add){
- for(y=block_w*mb_y; y<FFMIN(h,block_w*(mb_y+1)); y++){
- for(x=0; x<w; x++){
- int v= buf[x + y*w] + (128<<FRAC_BITS) + (1<<(FRAC_BITS-1));
- v >>= FRAC_BITS;
- if(v&(~255)) v= ~(v>>31);
- dst8[x + y*ref_stride]= v;
- }
- }
- }else{
- for(y=block_w*mb_y; y<FFMIN(h,block_w*(mb_y+1)); y++){
- for(x=0; x<w; x++){
- buf[x + y*w]-= 128<<FRAC_BITS;
- }
- }
- }
-
- return;
- }
-
- for(mb_x=0; mb_x<=mb_w; mb_x++){
- START_TIMER
-
- add_yblock(s, 0, NULL, buf, dst8, obmc,
- block_w*mb_x - block_w/2,
- block_w*mb_y - block_w/2,
- block_w, block_w,
- w, h,
- w, ref_stride, obmc_stride,
- mb_x - 1, mb_y - 1,
- add, 1, plane_index);
-
- STOP_TIMER("add_yblock")
- }
-
- STOP_TIMER("predict_slice")
-}
-
-static av_always_inline void predict_plane(SnowContext *s, DWTELEM *buf, int plane_index, int add){
- const int mb_h= s->b_height << s->block_max_depth;
- int mb_y;
- for(mb_y=0; mb_y<=mb_h; mb_y++)
- predict_slice(s, buf, plane_index, add, mb_y);
-}
-
-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];
- const int block_size = MB_SIZE >> s->block_max_depth;
- const int block_w = plane_index ? block_size/2 : block_size;
- const uint8_t *obmc = plane_index ? obmc_tab[s->block_max_depth+1] : obmc_tab[s->block_max_depth];
- const int obmc_stride= plane_index ? block_size : 2*block_size;
- const int ref_stride= s->current_picture.linesize[plane_index];
- uint8_t *src= s-> input_picture.data[plane_index];
- DWTELEM *dst= (DWTELEM*)s->m.obmc_scratchpad + plane_index*block_size*block_size*4;
- const int b_stride = s->b_width << s->block_max_depth;
- const int w= p->width;
- const int h= p->height;
- int index= mb_x + mb_y*b_stride;
- BlockNode *b= &s->block[index];
- BlockNode backup= *b;
- int ab=0;
- int aa=0;
-
- b->type|= BLOCK_INTRA;
- b->color[plane_index]= 0;
- memset(dst, 0, obmc_stride*obmc_stride*sizeof(DWTELEM));
-
- for(i=0; i<4; i++){
- int mb_x2= mb_x + (i &1) - 1;
- int mb_y2= mb_y + (i>>1) - 1;
- int x= block_w*mb_x2 + block_w/2;
- int y= block_w*mb_y2 + block_w/2;
-
- add_yblock(s, 0, NULL, dst + ((i&1)+(i>>1)*obmc_stride)*block_w, NULL, obmc,
- x, y, block_w, block_w, w, h, obmc_stride, ref_stride, obmc_stride, mb_x2, mb_y2, 0, 0, plane_index);
-
- for(y2= FFMAX(y, 0); y2<FFMIN(h, y+block_w); y2++){
- for(x2= FFMAX(x, 0); x2<FFMIN(w, x+block_w); x2++){
- int index= x2-(block_w*mb_x - block_w/2) + (y2-(block_w*mb_y - block_w/2))*obmc_stride;
- int obmc_v= obmc[index];
- int d;
- if(y<0) obmc_v += obmc[index + block_w*obmc_stride];
- if(x<0) obmc_v += obmc[index + block_w];
- if(y+block_w>h) obmc_v += obmc[index - block_w*obmc_stride];
- if(x+block_w>w) obmc_v += obmc[index - block_w];
- //FIXME precalc this or simplify it somehow else
-
- d = -dst[index] + (1<<(FRAC_BITS-1));
- dst[index] = d;
- ab += (src[x2 + y2*ref_stride] - (d>>FRAC_BITS)) * obmc_v;
- aa += obmc_v * obmc_v; //FIXME precalclate this
- }
- }
- }
- *b= backup;
-
- return clip(((ab<<LOG2_OBMC_MAX) + aa/2)/aa, 0, 255); //FIXME we shouldnt need cliping
-}
-
-static inline int get_block_bits(SnowContext *s, int x, int y, int w){
- const int b_stride = s->b_width << s->block_max_depth;
- const int b_height = s->b_height<< s->block_max_depth;
- int index= x + y*b_stride;
- const BlockNode *b = &s->block[index];
- const BlockNode *left = x ? &s->block[index-1] : &null_block;
- const BlockNode *top = y ? &s->block[index-b_stride] : &null_block;
- const BlockNode *tl = y && x ? &s->block[index-b_stride-1] : left;
- const BlockNode *tr = y && x+w<b_stride ? &s->block[index-b_stride+w] : tl;
- int dmx, dmy;
-// int mx_context= av_log2(2*FFABS(left->mx - top->mx));
-// int my_context= av_log2(2*FFABS(left->my - top->my));
-
- if(x<0 || x>=b_stride || y>=b_height)
- return 0;
-/*
-1 0 0
-01X 1-2 1
-001XX 3-6 2-3
-0001XXX 7-14 4-7
-00001XXXX 15-30 8-15
-*/
-//FIXME try accurate rate
-//FIXME intra and inter predictors if surrounding blocks arent the same type
- if(b->type & BLOCK_INTRA){
- return 3+2*( av_log2(2*FFABS(left->color[0] - b->color[0]))
- + av_log2(2*FFABS(left->color[1] - b->color[1]))
- + av_log2(2*FFABS(left->color[2] - b->color[2])));
- }else{
- pred_mv(s, &dmx, &dmy, b->ref, left, top, tr);
- dmx-= b->mx;
- dmy-= b->my;
- return 2*(1 + av_log2(2*FFABS(dmx)) //FIXME kill the 2* can be merged in lambda
- + av_log2(2*FFABS(dmy))
- + av_log2(2*b->ref));
- }
-}
-
-static int get_block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index, const uint8_t *obmc_edged){
- Plane *p= &s->plane[plane_index];
- const int block_size = MB_SIZE >> s->block_max_depth;
- const int block_w = plane_index ? block_size/2 : block_size;
- const int obmc_stride= plane_index ? block_size : 2*block_size;
- const int ref_stride= s->current_picture.linesize[plane_index];
- uint8_t *dst= s->current_picture.data[plane_index];
- uint8_t *src= s-> input_picture.data[plane_index];
- DWTELEM *pred= (DWTELEM*)s->m.obmc_scratchpad + plane_index*block_size*block_size*4;
- uint8_t cur[ref_stride*2*MB_SIZE]; //FIXME alignment
- uint8_t tmp[ref_stride*(2*MB_SIZE+5)];
- const int b_stride = s->b_width << s->block_max_depth;
- const int b_height = s->b_height<< s->block_max_depth;
- const int w= p->width;
- const int h= p->height;
- int distortion;
- int rate= 0;
- const int penalty_factor= get_penalty_factor(s->lambda, s->lambda2, s->avctx->me_cmp);
- int sx= block_w*mb_x - block_w/2;
- int sy= block_w*mb_y - block_w/2;
- int x0= FFMAX(0,-sx);
- int y0= FFMAX(0,-sy);
- int x1= FFMIN(block_w*2, w-sx);
- int y1= FFMIN(block_w*2, h-sy);
- int i,x,y;
-
- pred_block(s, cur, tmp, ref_stride, sx, sy, block_w*2, block_w*2, &s->block[mb_x + mb_y*b_stride], plane_index, w, h);
-
- for(y=y0; y<y1; y++){
- const uint8_t *obmc1= obmc_edged + y*obmc_stride;
- const DWTELEM *pred1 = pred + y*obmc_stride;
- uint8_t *cur1 = cur + y*ref_stride;
- uint8_t *dst1 = dst + sx + (sy+y)*ref_stride;
- for(x=x0; x<x1; x++){
- int v = (cur1[x] * obmc1[x]) << (FRAC_BITS - LOG2_OBMC_MAX);
- v = (v + pred1[x]) >> FRAC_BITS;
- if(v&(~255)) v= ~(v>>31);
- dst1[x] = v;
- }
- }
-
- /* copy the regions where obmc[] = (uint8_t)256 */
- if(LOG2_OBMC_MAX == 8
- && (mb_x == 0 || mb_x == b_stride-1)
- && (mb_y == 0 || mb_y == b_height-1)){
- if(mb_x == 0)
- x1 = block_w;
- else
- x0 = block_w;
- if(mb_y == 0)
- y1 = block_w;
- else
- y0 = block_w;
- for(y=y0; y<y1; y++)
- memcpy(dst + sx+x0 + (sy+y)*ref_stride, cur + x0 + y*ref_stride, x1-x0);
- }
-
- if(block_w==16){
- /* FIXME rearrange dsputil to fit 32x32 cmp functions */
- /* FIXME check alignment of the cmp wavelet vs the encoding wavelet */
- /* FIXME cmps overlap but don't cover the wavelet's whole support,
- * so improving the score of one block is not strictly guaranteed to
- * improve the score of the whole frame, so iterative motion est
- * doesn't 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);
- 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);
- else{
- distortion = 0;
- for(i=0; i<4; i++){
- int off = sx+16*(i&1) + (sy+16*(i>>1))*ref_stride;
- distortion += s->dsp.me_cmp[0](&s->m, src + off, dst + off, ref_stride, 16);
- }
- }
- }else{
- assert(block_w==8);
- distortion = s->dsp.me_cmp[0](&s->m, src + sx + sy*ref_stride, dst + sx + sy*ref_stride, ref_stride, block_w*2);
- }
-
- if(plane_index==0){
- for(i=0; i<4; i++){
-/* ..RRr
- * .RXx.
- * rxx..
- */
- rate += get_block_bits(s, mb_x + (i&1) - (i>>1), mb_y + (i>>1), 1);
- }
- if(mb_x == b_stride-2)
- rate += get_block_bits(s, mb_x + 1, mb_y + 1, 1);
- }
- return distortion + rate*penalty_factor;
-}
-
-static int get_4block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index){
- int i, y2;
- Plane *p= &s->plane[plane_index];
- const int block_size = MB_SIZE >> s->block_max_depth;
- const int block_w = plane_index ? block_size/2 : block_size;
- const uint8_t *obmc = plane_index ? obmc_tab[s->block_max_depth+1] : obmc_tab[s->block_max_depth];
- const int obmc_stride= plane_index ? block_size : 2*block_size;
- const int ref_stride= s->current_picture.linesize[plane_index];
- uint8_t *dst= s->current_picture.data[plane_index];
- uint8_t *src= s-> input_picture.data[plane_index];
- static const DWTELEM zero_dst[4096]; //FIXME
- const int b_stride = s->b_width << s->block_max_depth;
- const int w= p->width;
- const int h= p->height;
- int distortion= 0;
- int rate= 0;
- const int penalty_factor= get_penalty_factor(s->lambda, s->lambda2, s->avctx->me_cmp);
-
- for(i=0; i<9; i++){
- int mb_x2= mb_x + (i%3) - 1;
- int mb_y2= mb_y + (i/3) - 1;
- int x= block_w*mb_x2 + block_w/2;
- int y= block_w*mb_y2 + block_w/2;
-
- add_yblock(s, 0, NULL, zero_dst, dst, obmc,
- x, y, block_w, block_w, w, h, /*dst_stride*/0, ref_stride, obmc_stride, mb_x2, mb_y2, 1, 1, plane_index);
-
- //FIXME find a cleaner/simpler way to skip the outside stuff
- for(y2= y; y2<0; y2++)
- memcpy(dst + x + y2*ref_stride, src + x + y2*ref_stride, block_w);
- for(y2= h; y2<y+block_w; y2++)
- memcpy(dst + x + y2*ref_stride, src + x + y2*ref_stride, block_w);
- if(x<0){
- for(y2= y; y2<y+block_w; y2++)
- memcpy(dst + x + y2*ref_stride, src + x + y2*ref_stride, -x);
- }
- if(x+block_w > w){
- for(y2= y; y2<y+block_w; y2++)
- memcpy(dst + w + y2*ref_stride, src + w + y2*ref_stride, x+block_w - w);
- }
-
- assert(block_w== 8 || block_w==16);
- distortion += s->dsp.me_cmp[block_w==8](&s->m, src + x + y*ref_stride, dst + x + y*ref_stride, ref_stride, block_w);
- }
-
- if(plane_index==0){
- BlockNode *b= &s->block[mb_x+mb_y*b_stride];
- int merged= same_block(b,b+1) && same_block(b,b+b_stride) && same_block(b,b+b_stride+1);
-
-/* ..RRRr
- * .RXXx.
- * .RXXx.
- * rxxx.
- */
- if(merged)
- rate = get_block_bits(s, mb_x, mb_y, 2);
- for(i=merged?4:0; i<9; i++){
- static const int dxy[9][2] = {{0,0},{1,0},{0,1},{1,1},{2,0},{2,1},{-1,2},{0,2},{1,2}};
- rate += get_block_bits(s, mb_x + dxy[i][0], mb_y + dxy[i][1], 1);
- }
- }
- return distortion + rate*penalty_factor;
-}
-
-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];
- BlockNode backup= *block;
- int rd, index, value;
-
- assert(mb_x>=0 && mb_y>=0);
- assert(mb_x<b_stride);
-
- if(intra){
- block->color[0] = p[0];
- block->color[1] = p[1];
- block->color[2] = p[2];
- block->type |= BLOCK_INTRA;
- }else{
- index= (p[0] + 31*p[1]) & (ME_CACHE_SIZE-1);
- value= s->me_cache_generation + (p[0]>>10) + (p[1]<<6) + (block->ref<<12);
- if(s->me_cache[index] == value)
- return 0;
- s->me_cache[index]= value;
-
- block->mx= p[0];
- block->my= p[1];
- block->type &= ~BLOCK_INTRA;
- }
-
- rd= get_block_rd(s, mb_x, mb_y, 0, obmc_edged);
-
-//FIXME chroma
- if(rd < *best_rd){
- *best_rd= rd;
- return 1;
- }else{
- *block= backup;
- return 0;
- }
-}
-
-/* special case for int[2] args we discard afterward, fixes compilation prob with gcc 2.95 */
-static av_always_inline int check_block_inter(SnowContext *s, int mb_x, int mb_y, int p0, int p1, const uint8_t *obmc_edged, int *best_rd){
- int p[2] = {p0, p1};
- return check_block(s, mb_x, mb_y, p, 0, obmc_edged, best_rd);
-}
-
-static av_always_inline int check_4block_inter(SnowContext *s, int mb_x, int mb_y, int p0, int p1, int ref, int *best_rd){
- const int b_stride= s->b_width << s->block_max_depth;
- BlockNode *block= &s->block[mb_x + mb_y * b_stride];
- BlockNode backup[4]= {block[0], block[1], block[b_stride], block[b_stride+1]};
- int rd, index, value;
-
- assert(mb_x>=0 && mb_y>=0);
- assert(mb_x<b_stride);
- assert(((mb_x|mb_y)&1) == 0);
-
- index= (p0 + 31*p1) & (ME_CACHE_SIZE-1);
- value= s->me_cache_generation + (p0>>10) + (p1<<6) + (block->ref<<12);
- if(s->me_cache[index] == value)
- return 0;
- s->me_cache[index]= value;
-
- block->mx= p0;
- block->my= p1;
- block->ref= ref;
- block->type &= ~BLOCK_INTRA;
- block[1]= block[b_stride]= block[b_stride+1]= *block;
-
- rd= get_4block_rd(s, mb_x, mb_y, 0);
-
-//FIXME chroma
- if(rd < *best_rd){
- *best_rd= rd;
- return 1;
- }else{
- block[0]= backup[0];
- block[1]= backup[1];
- block[b_stride]= backup[2];
- block[b_stride+1]= backup[3];
- return 0;
- }
-}
-
-#ifdef CONFIG_ENCODERS
-static void iterative_me(SnowContext *s){
- int pass, mb_x, mb_y;
- const int b_width = s->b_width << s->block_max_depth;
- const int b_height= s->b_height << s->block_max_depth;
- const int b_stride= b_width;
- int color[3];
-
- {
- RangeCoder r = s->c;
- uint8_t state[sizeof(s->block_state)];
- memcpy(state, s->block_state, sizeof(s->block_state));
- for(mb_y= 0; mb_y<s->b_height; mb_y++)
- for(mb_x= 0; mb_x<s->b_width; mb_x++)
- encode_q_branch(s, 0, mb_x, mb_y);
- s->c = r;
- memcpy(s->block_state, state, sizeof(s->block_state));
- }
-
- for(pass=0; pass<25; pass++){
- int change= 0;
-
- for(mb_y= 0; mb_y<b_height; mb_y++){
- for(mb_x= 0; mb_x<b_width; mb_x++){
- int dia_change, i, j, ref;
- int best_rd= INT_MAX, ref_rd;
- BlockNode backup, ref_b;
- const int index= mb_x + mb_y * b_stride;
- BlockNode *block= &s->block[index];
- BlockNode *tb = mb_y ? &s->block[index-b_stride ] : NULL;
- BlockNode *lb = mb_x ? &s->block[index -1] : NULL;
- BlockNode *rb = mb_x+1<b_width ? &s->block[index +1] : NULL;
- BlockNode *bb = mb_y+1<b_height ? &s->block[index+b_stride ] : NULL;
- BlockNode *tlb= mb_x && mb_y ? &s->block[index-b_stride-1] : NULL;
- BlockNode *trb= mb_x+1<b_width && mb_y ? &s->block[index-b_stride+1] : NULL;
- BlockNode *blb= mb_x && mb_y+1<b_height ? &s->block[index+b_stride-1] : NULL;
- BlockNode *brb= mb_x+1<b_width && mb_y+1<b_height ? &s->block[index+b_stride+1] : NULL;
- const int b_w= (MB_SIZE >> s->block_max_depth);
- uint8_t obmc_edged[b_w*2][b_w*2];
-
- if(pass && (block->type & BLOCK_OPT))
- continue;
- block->type |= BLOCK_OPT;
-
- backup= *block;
-
- if(!s->me_cache_generation)
- memset(s->me_cache, 0, sizeof(s->me_cache));
- s->me_cache_generation += 1<<22;
-
- //FIXME precalc
- {
- int x, y;
- memcpy(obmc_edged, obmc_tab[s->block_max_depth], b_w*b_w*4);
- if(mb_x==0)
- for(y=0; y<b_w*2; y++)
- memset(obmc_edged[y], obmc_edged[y][0] + obmc_edged[y][b_w-1], b_w);
- if(mb_x==b_stride-1)
- for(y=0; y<b_w*2; y++)
- memset(obmc_edged[y]+b_w, obmc_edged[y][b_w] + obmc_edged[y][b_w*2-1], b_w);
- if(mb_y==0){
- for(x=0; x<b_w*2; x++)
- obmc_edged[0][x] += obmc_edged[b_w-1][x];
- for(y=1; y<b_w; y++)
- memcpy(obmc_edged[y], obmc_edged[0], b_w*2);
- }
- if(mb_y==b_height-1){
- for(x=0; x<b_w*2; x++)
- obmc_edged[b_w*2-1][x] += obmc_edged[b_w][x];
- for(y=b_w; y<b_w*2-1; y++)
- memcpy(obmc_edged[y], obmc_edged[b_w*2-1], b_w*2);
- }
- }
-
- //skip stuff outside the picture
- if(mb_x==0 || mb_y==0 || mb_x==b_width-1 || mb_y==b_height-1)
- {
- uint8_t *src= s-> input_picture.data[0];
- uint8_t *dst= s->current_picture.data[0];
- const int stride= s->current_picture.linesize[0];
- const int block_w= MB_SIZE >> s->block_max_depth;
- const int sx= block_w*mb_x - block_w/2;
- const int sy= block_w*mb_y - block_w/2;
- const int w= s->plane[0].width;
- const int h= s->plane[0].height;
- int y;
-
- for(y=sy; y<0; y++)
- memcpy(dst + sx + y*stride, src + sx + y*stride, block_w*2);
- for(y=h; y<sy+block_w*2; y++)
- memcpy(dst + sx + y*stride, src + sx + y*stride, block_w*2);
- if(sx<0){
- for(y=sy; y<sy+block_w*2; y++)
- memcpy(dst + sx + y*stride, src + sx + y*stride, -sx);
- }
- if(sx+block_w*2 > w){
- for(y=sy; y<sy+block_w*2; y++)
- memcpy(dst + w + y*stride, src + w + y*stride, sx+block_w*2 - w);
- }
- }
-
- // intra(black) = neighbors' contribution to the current block
- for(i=0; i<3; i++)
- color[i]= get_dc(s, mb_x, mb_y, i);
-
- // get previous score (cant be cached due to OBMC)
- if(pass > 0 && (block->type&BLOCK_INTRA)){
- int color0[3]= {block->color[0], block->color[1], block->color[2]};
- check_block(s, mb_x, mb_y, color0, 1, *obmc_edged, &best_rd);
- }else
- check_block_inter(s, mb_x, mb_y, block->mx, block->my, *obmc_edged, &best_rd);
-
- ref_b= *block;
- ref_rd= best_rd;
- for(ref=0; ref < s->ref_frames; ref++){
- int16_t (*mvr)[2]= &s->ref_mvs[ref][index];
- if(s->ref_scores[ref][index] > s->ref_scores[ref_b.ref][index]*3/2) //FIXME tune threshold
- continue;
- block->ref= ref;
- best_rd= INT_MAX;
-
- check_block_inter(s, mb_x, mb_y, mvr[0][0], mvr[0][1], *obmc_edged, &best_rd);
- check_block_inter(s, mb_x, mb_y, 0, 0, *obmc_edged, &best_rd);
- if(tb)
- check_block_inter(s, mb_x, mb_y, mvr[-b_stride][0], mvr[-b_stride][1], *obmc_edged, &best_rd);
- if(lb)
- check_block_inter(s, mb_x, mb_y, mvr[-1][0], mvr[-1][1], *obmc_edged, &best_rd);
- if(rb)
- check_block_inter(s, mb_x, mb_y, mvr[1][0], mvr[1][1], *obmc_edged, &best_rd);
- if(bb)
- check_block_inter(s, mb_x, mb_y, mvr[b_stride][0], mvr[b_stride][1], *obmc_edged, &best_rd);
-
- /* fullpel ME */
- //FIXME avoid subpel interpol / round to nearest integer
- do{
- dia_change=0;
- for(i=0; i<FFMAX(s->avctx->dia_size, 1); i++){
- for(j=0; j<i; j++){
- dia_change |= check_block_inter(s, mb_x, mb_y, block->mx+4*(i-j), block->my+(4*j), *obmc_edged, &best_rd);
- dia_change |= check_block_inter(s, mb_x, mb_y, block->mx-4*(i-j), block->my-(4*j), *obmc_edged, &best_rd);
- dia_change |= check_block_inter(s, mb_x, mb_y, block->mx+4*(i-j), block->my-(4*j), *obmc_edged, &best_rd);
- dia_change |= check_block_inter(s, mb_x, mb_y, block->mx-4*(i-j), block->my+(4*j), *obmc_edged, &best_rd);
- }
- }
- }while(dia_change);
- /* subpel ME */
- do{
- static const int square[8][2]= {{+1, 0},{-1, 0},{ 0,+1},{ 0,-1},{+1,+1},{-1,-1},{+1,-1},{-1,+1},};
- dia_change=0;
- for(i=0; i<8; i++)
- dia_change |= check_block_inter(s, mb_x, mb_y, block->mx+square[i][0], block->my+square[i][1], *obmc_edged, &best_rd);
- }while(dia_change);
- //FIXME or try the standard 2 pass qpel or similar
-
- mvr[0][0]= block->mx;
- mvr[0][1]= block->my;
- if(ref_rd > best_rd){
- ref_rd= best_rd;
- ref_b= *block;
- }
- }
- best_rd= ref_rd;
- *block= ref_b;
-#if 1
- check_block(s, mb_x, mb_y, color, 1, *obmc_edged, &best_rd);
- //FIXME RD style color selection
-#endif
- if(!same_block(block, &backup)){
- if(tb ) tb ->type &= ~BLOCK_OPT;
- if(lb ) lb ->type &= ~BLOCK_OPT;
- if(rb ) rb ->type &= ~BLOCK_OPT;
- if(bb ) bb ->type &= ~BLOCK_OPT;
- if(tlb) tlb->type &= ~BLOCK_OPT;
- if(trb) trb->type &= ~BLOCK_OPT;
- if(blb) blb->type &= ~BLOCK_OPT;
- if(brb) brb->type &= ~BLOCK_OPT;
- change ++;
- }
- }
- }
- av_log(NULL, AV_LOG_ERROR, "pass:%d changed:%d\n", pass, change);
- if(!change)
- break;
- }
-
- if(s->block_max_depth == 1){
- int change= 0;
- for(mb_y= 0; mb_y<b_height; mb_y+=2){
- for(mb_x= 0; mb_x<b_width; mb_x+=2){
- int i;
- int best_rd, init_rd;
- const int index= mb_x + mb_y * b_stride;
- BlockNode *b[4];
-
- b[0]= &s->block[index];
- b[1]= b[0]+1;
- b[2]= b[0]+b_stride;
- b[3]= b[2]+1;
- if(same_block(b[0], b[1]) &&
- same_block(b[0], b[2]) &&
- same_block(b[0], b[3]))
- continue;
-
- if(!s->me_cache_generation)
- memset(s->me_cache, 0, sizeof(s->me_cache));
- s->me_cache_generation += 1<<22;
-
- init_rd= best_rd= get_4block_rd(s, mb_x, mb_y, 0);
-
- //FIXME more multiref search?
- check_4block_inter(s, mb_x, mb_y,
- (b[0]->mx + b[1]->mx + b[2]->mx + b[3]->mx + 2) >> 2,
- (b[0]->my + b[1]->my + b[2]->my + b[3]->my + 2) >> 2, 0, &best_rd);
-
- for(i=0; i<4; i++)
- if(!(b[i]->type&BLOCK_INTRA))
- check_4block_inter(s, mb_x, mb_y, b[i]->mx, b[i]->my, b[i]->ref, &best_rd);
-
- if(init_rd != best_rd)
- change++;
- }
- }
- av_log(NULL, AV_LOG_ERROR, "pass:4mv changed:%d\n", change*4);
- }
-}
-#endif
-
-static void quantize(SnowContext *s, SubBand *b, DWTELEM *src, int stride, int bias){
- const int level= b->level;
- const int w= b->width;
- const int h= b->height;
- const int qlog= clip(s->qlog + b->qlog, 0, QROOT*16);
- const int qmul= qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT);
- int x,y, thres1, thres2;
-// START_TIMER
-
- if(s->qlog == LOSSLESS_QLOG) return;
-
- bias= bias ? 0 : (3*qmul)>>3;
- thres1= ((qmul - bias)>>QEXPSHIFT) - 1;
- thres2= 2*thres1;
-
- if(!bias){
- for(y=0; y<h; y++){
- for(x=0; x<w; x++){
- int i= src[x + y*stride];
-
- if((unsigned)(i+thres1) > thres2){
- if(i>=0){
- i<<= QEXPSHIFT;
- i/= qmul; //FIXME optimize
- src[x + y*stride]= i;
- }else{
- i= -i;
- i<<= QEXPSHIFT;
- i/= qmul; //FIXME optimize
- src[x + y*stride]= -i;
- }
- }else
- src[x + y*stride]= 0;
- }
- }
- }else{
- for(y=0; y<h; y++){
- for(x=0; x<w; x++){
- int i= src[x + y*stride];
-
- if((unsigned)(i+thres1) > thres2){
- if(i>=0){
- i<<= QEXPSHIFT;
- i= (i + bias) / qmul; //FIXME optimize
- src[x + y*stride]= i;
- }else{
- i= -i;
- i<<= QEXPSHIFT;
- i= (i + bias) / qmul; //FIXME optimize
- src[x + y*stride]= -i;
- }
- }else
- src[x + y*stride]= 0;
- }
- }
- }
- if(level+1 == s->spatial_decomposition_count){
-// STOP_TIMER("quantize")
- }
-}
-
-static void dequantize_slice_buffered(SnowContext *s, slice_buffer * sb, SubBand *b, DWTELEM *src, int stride, int start_y, int end_y){
- const int w= b->width;
- const int qlog= 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;
- START_TIMER
-
- if(s->qlog == LOSSLESS_QLOG) return;
-
- for(y=start_y; y<end_y; y++){
-// DWTELEM * line = slice_buffer_get_line_from_address(sb, src + (y * stride));
- DWTELEM * line = slice_buffer_get_line(sb, (y * b->stride_line) + b->buf_y_offset) + b->buf_x_offset;
- for(x=0; x<w; x++){
- int i= line[x];
- if(i<0){
- line[x]= -((-i*qmul + qadd)>>(QEXPSHIFT)); //FIXME try different bias
- }else if(i>0){
- line[x]= (( i*qmul + qadd)>>(QEXPSHIFT));
- }
- }
- }
- if(w > 200 /*level+1 == s->spatial_decomposition_count*/){
- STOP_TIMER("dquant")
- }
-}
-
-static void dequantize(SnowContext *s, SubBand *b, DWTELEM *src, int stride){
- const int w= b->width;
- const int h= b->height;
- const int qlog= 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;
- START_TIMER
-
- if(s->qlog == LOSSLESS_QLOG) return;
-
- for(y=0; y<h; y++){
- for(x=0; x<w; x++){
- int i= src[x + y*stride];
- if(i<0){
- src[x + y*stride]= -((-i*qmul + qadd)>>(QEXPSHIFT)); //FIXME try different bias
- }else if(i>0){
- src[x + y*stride]= (( i*qmul + qadd)>>(QEXPSHIFT));
- }
- }
- }
- if(w > 200 /*level+1 == s->spatial_decomposition_count*/){
- STOP_TIMER("dquant")
- }
-}
-
-static void decorrelate(SnowContext *s, SubBand *b, DWTELEM *src, int stride, int inverse, int use_median){
- const int w= b->width;
- const int h= b->height;
- int x,y;
-
- for(y=h-1; y>=0; y--){
- for(x=w-1; x>=0; x--){
- int i= x + y*stride;
-
- if(x){
- if(use_median){
- if(y && x+1<w) src[i] -= mid_pred(src[i - 1], src[i - stride], src[i - stride + 1]);
- else src[i] -= src[i - 1];
- }else{
- if(y) src[i] -= mid_pred(src[i - 1], src[i - stride], src[i - 1] + src[i - stride] - src[i - 1 - stride]);
- else src[i] -= src[i - 1];
- }
- }else{
- if(y) src[i] -= src[i - stride];
- }
- }
- }
-}
-
-static void correlate_slice_buffered(SnowContext *s, slice_buffer * sb, SubBand *b, DWTELEM *src, int stride, int inverse, int use_median, int start_y, int end_y){
- const int w= b->width;
- int x,y;
-
-// START_TIMER
-
- DWTELEM * line=0; // silence silly "could be used without having been initialized" warning
- DWTELEM * 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; y<end_y; y++){
- prev = line;
-// line = slice_buffer_get_line_from_address(sb, src + (y * stride));
- line = slice_buffer_get_line(sb, (y * b->stride_line) + b->buf_y_offset) + b->buf_x_offset;
- for(x=0; x<w; x++){
- if(x){
- if(use_median){
- if(y && x+1<w) line[x] += mid_pred(line[x - 1], prev[x], prev[x + 1]);
- else line[x] += line[x - 1];
- }else{
- if(y) line[x] += mid_pred(line[x - 1], prev[x], line[x - 1] + prev[x] - prev[x - 1]);
- else line[x] += line[x - 1];
- }
- }else{
- if(y) line[x] += prev[x];
- }
- }
- }
-
-// STOP_TIMER("correlate")
-}
-
-static void correlate(SnowContext *s, SubBand *b, DWTELEM *src, int stride, int inverse, int use_median){
- const int w= b->width;
- const int h= b->height;
- int x,y;
-
- for(y=0; y<h; y++){
- for(x=0; x<w; x++){
- int i= x + y*stride;
-
- if(x){
- if(use_median){
- if(y && x+1<w) src[i] += mid_pred(src[i - 1], src[i - stride], src[i - stride + 1]);
- else src[i] += src[i - 1];
- }else{
- if(y) src[i] += mid_pred(src[i - 1], src[i - stride], src[i - 1] + src[i - stride] - src[i - 1 - stride]);
- else src[i] += src[i - 1];
- }
- }else{
- if(y) src[i] += src[i - stride];
- }
- }
- }
-}
-
-static void encode_header(SnowContext *s){
- int plane_index, level, orientation;
- uint8_t kstate[32];
-
- memset(kstate, MID_STATE, sizeof(kstate));
-
- put_rac(&s->c, kstate, s->keyframe);
- if(s->keyframe || s->always_reset){
- reset_contexts(s);
- s->last_spatial_decomposition_type=
- s->last_qlog=
- s->last_qbias=
- s->last_mv_scale=
- s->last_block_max_depth= 0;
- }
- if(s->keyframe){
- put_symbol(&s->c, s->header_state, s->version, 0);
- put_rac(&s->c, s->header_state, s->always_reset);
- put_symbol(&s->c, s->header_state, s->temporal_decomposition_type, 0);
- put_symbol(&s->c, s->header_state, s->temporal_decomposition_count, 0);
- put_symbol(&s->c, s->header_state, s->spatial_decomposition_count, 0);
- put_symbol(&s->c, s->header_state, s->colorspace_type, 0);
- put_symbol(&s->c, s->header_state, s->chroma_h_shift, 0);
- put_symbol(&s->c, s->header_state, s->chroma_v_shift, 0);
- put_rac(&s->c, s->header_state, s->spatial_scalability);
-// put_rac(&s->c, s->header_state, s->rate_scalability);
- put_symbol(&s->c, s->header_state, s->max_ref_frames-1, 0);
-
- for(plane_index=0; plane_index<2; plane_index++){
- for(level=0; level<s->spatial_decomposition_count; level++){
- for(orientation=level ? 1:0; orientation<4; orientation++){
- if(orientation==2) continue;
- put_symbol(&s->c, s->header_state, s->plane[plane_index].band[level][orientation].qlog, 1);
- }
- }
- }
- }
- put_symbol(&s->c, s->header_state, s->spatial_decomposition_type - s->last_spatial_decomposition_type, 1);
- put_symbol(&s->c, s->header_state, s->qlog - s->last_qlog , 1);
- put_symbol(&s->c, s->header_state, s->mv_scale - s->last_mv_scale, 1);
- put_symbol(&s->c, s->header_state, s->qbias - s->last_qbias , 1);
- put_symbol(&s->c, s->header_state, s->block_max_depth - s->last_block_max_depth, 1);
-
- s->last_spatial_decomposition_type= s->spatial_decomposition_type;
- s->last_qlog = s->qlog;
- s->last_qbias = s->qbias;
- s->last_mv_scale = s->mv_scale;
- s->last_block_max_depth = s->block_max_depth;
-}
-
-static int decode_header(SnowContext *s){
- int plane_index, level, orientation;
- 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){
- s->version= get_symbol(&s->c, s->header_state, 0);
- if(s->version>0){
- av_log(s->avctx, AV_LOG_ERROR, "version %d not supported", s->version);
- return -1;
- }
- 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);
- s->spatial_decomposition_count= get_symbol(&s->c, s->header_state, 0);
- 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);
- s->max_ref_frames= get_symbol(&s->c, s->header_state, 0)+1;
-
- for(plane_index=0; plane_index<3; plane_index++){
- for(level=0; level<s->spatial_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;
- }
- }
- }
- }
-
- s->spatial_decomposition_type+= get_symbol(&s->c, s->header_state, 1);
- if(s->spatial_decomposition_type > 2){
- av_log(s->avctx, AV_LOG_ERROR, "spatial_decomposition_type %d not supported", s->spatial_decomposition_type);
- 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; i<QROOT; i++){
- qexp[i]= lrintf(v);
- v *= pow(2, 1.0 / QROOT);
- }
-}
-
-static int common_init(AVCodecContext *avctx){
- SnowContext *s = avctx->priv_data;
- int width, height;
- int level, orientation, plane_index, dec;
- int i, j;
-
- s->avctx= avctx;
-
- 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= s->spatial_decomposition_count= 5;
- s->spatial_decomposition_type= avctx->prediction_method; //FIXME add decorrelator type r transform_type
-
- s->chroma_h_shift= 1; //FIXME XXX
- s->chroma_v_shift= 1;
-
-// dec += FFMAX(s->chroma_h_shift, s->chroma_v_shift);
-
- width= s->avctx->width;
- height= s->avctx->height;
-
- s->spatial_dwt_buffer= av_mallocz(width*height*sizeof(DWTELEM));
-
- s->mv_scale= (s->avctx->flags & CODEC_FLAG_QPEL) ? 2 : 4;
- s->block_max_depth= (s->avctx->flags & CODEC_FLAG_4MV) ? 1 : 0;
-
- 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;
-//av_log(NULL, AV_LOG_DEBUG, "%d %d\n", w, 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;
- }
-
- if(level)
- b->parent= &s->plane[plane_index].band[level-1][orientation];
- b->x_coeff=av_mallocz(((b->width+1) * b->height+1)*sizeof(x_and_coeff));
- }
- w= (w+1)>>1;
- h= (h+1)>>1;
- }
- }
-
- for(i=0; i<MAX_REF_FRAMES; i++)
- for(j=0; j<MAX_REF_FRAMES; j++)
- scale_mv_ref[i][j] = 256*(i+1)/(j+1);
-
- reset_contexts(s);
-/*
- width= s->width= avctx->width;
- height= s->height= avctx->height;
-
- assert(width && height);
-*/
- s->avctx->get_buffer(s->avctx, &s->mconly_picture);
-
- return 0;
-}
-
-static int qscale2qlog(int qscale){
- return rint(QROOT*log(qscale / (float)FF_QP2LAMBDA)/log(2))
- + 61*QROOT/8; //<64 >60
-}
-
-static int ratecontrol_1pass(SnowContext *s, AVFrame *pict)
-{
- /* estimate the frame's complexity as a sum of weighted dwt coefs.
- * FIXME we know exact mv bits at this point,
- * but ratecontrol isn't set up to include them. */
- uint32_t coef_sum= 0;
- int level, orientation, delta_qlog;
-
- for(level=0; level<s->spatial_decomposition_count; level++){
- for(orientation=level ? 1 : 0; orientation<4; orientation++){
- SubBand *b= &s->plane[0].band[level][orientation];
- DWTELEM *buf= b->buf;
- const int w= b->width;
- const int h= b->height;
- const int stride= b->stride;
- const int qlog= clip(2*QROOT + b->qlog, 0, QROOT*16);
- const int qmul= qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT);
- const int qdiv= (1<<16)/qmul;
- int x, y;
- if(orientation==0)
- decorrelate(s, b, buf, stride, 1, 0);
- for(y=0; y<h; y++)
- for(x=0; x<w; x++)
- coef_sum+= abs(buf[x+y*stride]) * qdiv >> 16;
- if(orientation==0)
- correlate(s, b, buf, stride, 1, 0);
- }
- }
-
- /* ugly, ratecontrol just takes a sqrt again */
- coef_sum = (uint64_t)coef_sum * coef_sum >> 16;
- assert(coef_sum < INT_MAX);
-
- if(pict->pict_type == I_TYPE){
- s->m.current_picture.mb_var_sum= coef_sum;
- s->m.current_picture.mc_mb_var_sum= 0;
- }else{
- s->m.current_picture.mc_mb_var_sum= coef_sum;
- s->m.current_picture.mb_var_sum= 0;
- }
-
- pict->quality= ff_rate_estimate_qscale(&s->m, 1);
- if (pict->quality < 0)
- return INT_MIN;
- s->lambda= pict->quality * 3/2;
- delta_qlog= qscale2qlog(pict->quality) - s->qlog;
- s->qlog+= delta_qlog;
- return delta_qlog;
-}
-
-static void calculate_vissual_weight(SnowContext *s, Plane *p){
- int width = p->width;
- int height= p->height;
- int level, orientation, x, y;
-
- for(level=0; level<s->spatial_decomposition_count; level++){
- for(orientation=level ? 1 : 0; orientation<4; orientation++){
- SubBand *b= &p->band[level][orientation];
- DWTELEM *buf= b->buf;
- int64_t error=0;
-
- memset(s->spatial_dwt_buffer, 0, sizeof(int)*width*height);
- buf[b->width/2 + b->height/2*b->stride]= 256*256;
- ff_spatial_idwt(s->spatial_dwt_buffer, width, height, width, s->spatial_decomposition_type, s->spatial_decomposition_count);
- for(y=0; y<height; y++){
- for(x=0; x<width; x++){
- int64_t d= s->spatial_dwt_buffer[x + y*width];
- error += d*d;
- }
- }
-
- b->qlog= (int)(log(352256.0/sqrt(error)) / log(pow(2.0, 1.0/QROOT))+0.5);
-// av_log(NULL, AV_LOG_DEBUG, "%d %d %d\n", level, orientation, b->qlog/*, sqrt(error)*/);
- }
- }
-}
-
-#ifdef CONFIG_ENCODERS
-static 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;
- }
-
- 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.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));
-
- for(plane_index=0; plane_index<3; plane_index++){
- calculate_vissual_weight(s, &s->plane[plane_index]);
- }
-
-
- 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_RGBA32:
- s->colorspace= 1;
- break;*/
- default:
- av_log(avctx, AV_LOG_ERROR, "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; i<s->max_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;
-}
-#endif
-
-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]){
- draw_edges(s->current_picture.data[0], s->current_picture.linesize[0], w , h , EDGE_WIDTH );
- draw_edges(s->current_picture.data[1], s->current_picture.linesize[1], w>>1, h>>1, EDGE_WIDTH/2);
- draw_edges(s->current_picture.data[2], s->current_picture.linesize[2], w>>1, h>>1, EDGE_WIDTH/2);
- }
-
- tmp= s->last_picture[s->max_ref_frames-1];
- memmove(s->last_picture+1, s->last_picture, (s->max_ref_frames-1)*sizeof(AVFrame));
- s->last_picture[0]= s->current_picture;
- s->current_picture= tmp;
-
- if(s->keyframe){
- s->ref_frames= 0;
- }else{
- int i;
- for(i=0; i<s->max_ref_frames && s->last_picture[i].data[0]; i++)
- if(i && s->last_picture[i-1].key_frame)
- break;
- s->ref_frames= i;
- }
-
- 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;
-}
-
-#ifdef CONFIG_ENCODERS
-static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
- SnowContext *s = avctx->priv_data;
- RangeCoder * const c= &s->c;
- AVFrame *pict = data;
- const int width= s->avctx->width;
- const int height= s->avctx->height;
- int level, orientation, plane_index, i, y;
- uint8_t rc_header_bak[sizeof(s->header_state)];
- uint8_t rc_block_bak[sizeof(s->block_state)];
-
- ff_init_range_encoder(c, buf, buf_size);
- ff_build_rac_states(c, 0.05*(1LL<<32), 256-8);
-
- for(i=0; i<3; i++){
- int shift= !!i;
- for(y=0; y<(height>>shift); y++)
- memcpy(&s->input_picture.data[i][y * s->input_picture.linesize[i]],
- &pict->data[i][y * pict->linesize[i]],
- width>>shift);
- }
- s->new_picture = *pict;
-
- s->m.picture_number= avctx->frame_number;
- if(avctx->flags&CODEC_FLAG_PASS2){
- s->m.pict_type =
- pict->pict_type= s->m.rc_context.entry[avctx->frame_number].new_pict_type;
- s->keyframe= pict->pict_type==FF_I_TYPE;
- if(!(avctx->flags&CODEC_FLAG_QSCALE)) {
- pict->quality= ff_rate_estimate_qscale(&s->m, 0);
- if (pict->quality < 0)
- return -1;
- }
- }else{
- s->keyframe= avctx->gop_size==0 || avctx->frame_number % avctx->gop_size == 0;
- s->m.pict_type=
- pict->pict_type= s->keyframe ? FF_I_TYPE : FF_P_TYPE;
- }
-
- if(s->pass1_rc && avctx->frame_number == 0)
- pict->quality= 2*FF_QP2LAMBDA;
- if(pict->quality){
- s->qlog= qscale2qlog(pict->quality);
- s->lambda = pict->quality * 3/2;
- }
- if(s->qlog < 0 || (!pict->quality && (avctx->flags & CODEC_FLAG_QSCALE))){
- s->qlog= LOSSLESS_QLOG;
- s->lambda = 0;
- }//else keep previous frame's qlog until after motion est
-
- frame_start(s);
-
- s->m.current_picture_ptr= &s->m.current_picture;
- if(pict->pict_type == P_TYPE){
- int block_width = (width +15)>>4;
- int block_height= (height+15)>>4;
- int stride= s->current_picture.linesize[0];
-
- assert(s->current_picture.data[0]);
- assert(s->last_picture[0].data[0]);
-
- s->m.avctx= s->avctx;
- s->m.current_picture.data[0]= s->current_picture.data[0];
- s->m. last_picture.data[0]= s->last_picture[0].data[0];
- s->m. new_picture.data[0]= s-> input_picture.data[0];
- s->m. last_picture_ptr= &s->m. last_picture;
- s->m.linesize=
- s->m. last_picture.linesize[0]=
- s->m. new_picture.linesize[0]=
- s->m.current_picture.linesize[0]= stride;
- s->m.uvlinesize= s->current_picture.linesize[1];
- s->m.width = width;
- s->m.height= height;
- s->m.mb_width = block_width;
- s->m.mb_height= block_height;
- s->m.mb_stride= s->m.mb_width+1;
- s->m.b8_stride= 2*s->m.mb_width+1;
- s->m.f_code=1;
- s->m.pict_type= pict->pict_type;
- s->m.me_method= s->avctx->me_method;
- s->m.me.scene_change_score=0;
- s->m.flags= s->avctx->flags;
- s->m.quarter_sample= (s->avctx->flags & CODEC_FLAG_QPEL)!=0;
- s->m.out_format= FMT_H263;
- s->m.unrestricted_mv= 1;
-
- s->m.lambda = s->lambda;
- s->m.qscale= (s->m.lambda*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7);
- s->lambda2= s->m.lambda2= (s->m.lambda*s->m.lambda + FF_LAMBDA_SCALE/2) >> FF_LAMBDA_SHIFT;
-
- s->m.dsp= s->dsp; //move
- ff_init_me(&s->m);
- s->dsp= s->m.dsp;
- }
-
- if(s->pass1_rc){
- memcpy(rc_header_bak, s->header_state, sizeof(s->header_state));
- memcpy(rc_block_bak, s->block_state, sizeof(s->block_state));
- }
-
-redo_frame:
-
- s->m.pict_type = pict->pict_type;
- s->qbias= pict->pict_type == P_TYPE ? 2 : 0;
-
- encode_header(s);
- s->m.misc_bits = 8*(s->c.bytestream - s->c.bytestream_start);
- encode_blocks(s, 1);
- s->m.mv_bits = 8*(s->c.bytestream - s->c.bytestream_start) - s->m.misc_bits;
-
- 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 bits= put_bits_count(&s->c.pb);
-
- if(!(avctx->flags2 & CODEC_FLAG2_MEMC_ONLY)){
- //FIXME optimize
- if(pict->data[plane_index]) //FIXME gray hack
- for(y=0; y<h; y++){
- for(x=0; x<w; x++){
- s->spatial_dwt_buffer[y*w + x]= pict->data[plane_index][y*pict->linesize[plane_index] + x]<<FRAC_BITS;
- }
- }
- predict_plane(s, s->spatial_dwt_buffer, plane_index, 0);
-
- if( plane_index==0
- && pict->pict_type == P_TYPE
- && !(avctx->flags&CODEC_FLAG_PASS2)
- && s->m.me.scene_change_score > s->avctx->scenechange_threshold){
- ff_init_range_encoder(c, buf, buf_size);
- ff_build_rac_states(c, 0.05*(1LL<<32), 256-8);
- pict->pict_type= FF_I_TYPE;
- s->keyframe=1;
- s->current_picture.key_frame=1;
- goto redo_frame;
- }
-
- if(s->qlog == LOSSLESS_QLOG){
- for(y=0; y<h; y++){
- for(x=0; x<w; x++){
- s->spatial_dwt_buffer[y*w + x]= (s->spatial_dwt_buffer[y*w + x] + (1<<(FRAC_BITS-1))-1)>>FRAC_BITS;
- }
- }
- }
-
- ff_spatial_dwt(s->spatial_dwt_buffer, w, h, w, s->spatial_decomposition_type, s->spatial_decomposition_count);
-
- if(s->pass1_rc && plane_index==0){
- int delta_qlog = ratecontrol_1pass(s, pict);
- if (delta_qlog <= INT_MIN)
- return -1;
- if(delta_qlog){
- //reordering qlog in the bitstream would eliminate this reset
- ff_init_range_encoder(c, buf, buf_size);
- memcpy(s->header_state, rc_header_bak, sizeof(s->header_state));
- memcpy(s->block_state, rc_block_bak, sizeof(s->block_state));
- encode_header(s);
- encode_blocks(s, 0);
- }
- }
-
- for(level=0; level<s->spatial_decomposition_count; level++){
- for(orientation=level ? 1 : 0; orientation<4; orientation++){
- SubBand *b= &p->band[level][orientation];
-
- quantize(s, b, b->buf, b->stride, s->qbias);
- if(orientation==0)
- decorrelate(s, b, b->buf, b->stride, pict->pict_type == P_TYPE, 0);
- encode_subband(s, b, b->buf, b->parent ? b->parent->buf : NULL, b->stride, orientation);
- assert(b->parent==NULL || b->parent->stride == b->stride*2);
- if(orientation==0)
- correlate(s, b, b->buf, b->stride, 1, 0);
- }
- }
-// av_log(NULL, AV_LOG_DEBUG, "plane:%d bits:%d\n", plane_index, put_bits_count(&s->c.pb) - bits);
-
- for(level=0; level<s->spatial_decomposition_count; level++){
- for(orientation=level ? 1 : 0; orientation<4; orientation++){
- SubBand *b= &p->band[level][orientation];
-
- dequantize(s, b, b->buf, b->stride);
- }
- }
-
- ff_spatial_idwt(s->spatial_dwt_buffer, w, h, w, s->spatial_decomposition_type, s->spatial_decomposition_count);
- if(s->qlog == LOSSLESS_QLOG){
- for(y=0; y<h; y++){
- for(x=0; x<w; x++){
- s->spatial_dwt_buffer[y*w + x]<<=FRAC_BITS;
- }
- }
- }
-{START_TIMER
- predict_plane(s, s->spatial_dwt_buffer, plane_index, 1);
-STOP_TIMER("pred-conv")}
- }else{
- //ME/MC only
- if(pict->pict_type == I_TYPE){
- for(y=0; y<h; y++){
- for(x=0; x<w; x++){
- s->current_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x]=
- pict->data[plane_index][y*pict->linesize[plane_index] + x];
- }
- }
- }else{
- memset(s->spatial_dwt_buffer, 0, sizeof(DWTELEM)*w*h);
- predict_plane(s, s->spatial_dwt_buffer, plane_index, 1);
- }
- }
- if(s->avctx->flags&CODEC_FLAG_PSNR){
- int64_t error= 0;
-
- if(pict->data[plane_index]) //FIXME gray hack
- for(y=0; y<h; y++){
- for(x=0; x<w; x++){
- int d= s->current_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x] - pict->data[plane_index][y*pict->linesize[plane_index] + x];
- error += d*d;
- }
- }
- s->avctx->error[plane_index] += error;
- s->current_picture.error[plane_index] = error;
- }
- }
-
- if(s->last_picture[s->max_ref_frames-1].data[0])
- avctx->release_buffer(avctx, &s->last_picture[s->max_ref_frames-1]);
-
- s->current_picture.coded_picture_number = avctx->frame_number;
- s->current_picture.pict_type = pict->pict_type;
- s->current_picture.quality = pict->quality;
- s->m.frame_bits = 8*(s->c.bytestream - s->c.bytestream_start);
- s->m.p_tex_bits = s->m.frame_bits - s->m.misc_bits - s->m.mv_bits;
- s->m.current_picture.display_picture_number =
- s->m.current_picture.coded_picture_number = avctx->frame_number;
- s->m.current_picture.quality = pict->quality;
- s->m.total_bits += 8*(s->c.bytestream - s->c.bytestream_start);
- if(s->pass1_rc)
- if (ff_rate_estimate_qscale(&s->m, 0) < 0)
- return -1;
- if(avctx->flags&CODEC_FLAG_PASS1)
- ff_write_pass1_stats(&s->m);
- s->m.last_pict_type = s->m.pict_type;
- avctx->frame_bits = s->m.frame_bits;
- avctx->mv_bits = s->m.mv_bits;
- avctx->misc_bits = s->m.misc_bits;
- avctx->p_tex_bits = s->m.p_tex_bits;
-
- emms_c();
-
- return ff_rac_terminate(c);
-}
-#endif
-
-static void common_end(SnowContext *s){
- int plane_index, level, orientation, i;
-
- av_freep(&s->spatial_dwt_buffer);
-
- 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);
-
- for(i=0; i<MAX_REF_FRAMES; i++){
- av_freep(&s->ref_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);
- }
- }
- }
-}
-
-#ifdef CONFIG_ENCODERS
-static int encode_end(AVCodecContext *avctx)
-{
- SnowContext *s = avctx->priv_data;
-
- common_end(s);
- av_free(avctx->stats_out);
-
- return 0;
-}
-#endif
-
-static int decode_init(AVCodecContext *avctx)
-{
- SnowContext *s = avctx->priv_data;
- int block_size;
-
- avctx->pix_fmt= PIX_FMT_YUV420P;
-
- common_init(avctx);
-
- block_size = MB_SIZE >> s->block_max_depth;
- slice_buffer_init(&s->sb, s->plane[0].height, (block_size) + (s->spatial_decomposition_count * (s->spatial_decomposition_count + 3)) + 1, s->plane[0].width, s->spatial_dwt_buffer);
-
- return 0;
-}
-
-static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_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
- decode_header(s);
- if(!s->block) alloc_blocks(s);
-
- frame_start(s);
- //keyframe flag dupliaction 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_dwt_buffer, plane_index, 1);
-
- for(y=0; y<h; y++){
- for(x=0; x<w; x++){
- int v= s->current_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;
- }
- }
-}
-
-{ START_TIMER
- for(level=0; level<s->spatial_decomposition_count; level++){
- for(orientation=level ? 1 : 0; orientation<4; orientation++){
- SubBand *b= &p->band[level][orientation];
- unpack_coeffs(s, b, b->parent, orientation);
- }
- }
- STOP_TIMER("unpack coeffs");
-}
-
-{START_TIMER
- 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;
- dwt_compose_t 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);
- }
-
- {
- START_TIMER
- for(level=0; level<s->spatial_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->buf, correlate_band->stride, 1, 0, correlate_start_y, correlate_end_y);
- dequantize_slice_buffered(s, &s->sb, correlate_band, correlate_band->buf, correlate_band->stride, start_y, end_y);
- }
- else
- decode_subband_slice_buffered(s, b, &s->sb, start_y, end_y, decode_state[level][orientation]);
- }
- }
- }
- STOP_TIMER("decode_subband_slice");
- }
-
-{ START_TIMER
- for(; yd<slice_h; yd+=4){
- ff_spatial_idwt_buffered_slice(&s->dsp, cs, &s->sb, w, h, 1, s->spatial_decomposition_type, s->spatial_decomposition_count, yd);
- }
- STOP_TIMER("idwt slice");}
-
-
- if(s->qlog == LOSSLESS_QLOG){
- for(; yq<slice_h && yq<h; yq++){
- DWTELEM * line = slice_buffer_get_line(&s->sb, yq);
- for(x=0; x<w; x++){
- line[x] <<= FRAC_BITS;
- }
- }
- }
-
- predict_slice_buffered(s, &s->sb, s->spatial_dwt_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);
-
-STOP_TIMER("idwt + predict_slices")}
- }
-
- emms_c();
-
- if(s->last_picture[s->max_ref_frames-1].data[0])
- avctx->release_buffer(avctx, &s->last_picture[s->max_ref_frames-1]);
-
-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 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,
- 0 /*CODEC_CAP_DR1*/ /*| CODEC_CAP_DRAW_HORIZ_BAND*/,
- NULL
-};
-
-#ifdef CONFIG_ENCODERS
-AVCodec snow_encoder = {
- "snow",
- CODEC_TYPE_VIDEO,
- CODEC_ID_SNOW,
- sizeof(SnowContext),
- encode_init,
- encode_frame,
- encode_end,
-};
-#endif
-
-
-#if 0
-#undef malloc
-#undef free
-#undef printf
-
-int main(){
- int width=256;
- int height=256;
- int buffer[2][width*height];
- SnowContext s;
- int i;
- s.spatial_decomposition_count=6;
- s.spatial_decomposition_type=1;
-
- printf("testing 5/3 DWT\n");
- for(i=0; i<width*height; i++)
- buffer[0][i]= buffer[1][i]= random()%54321 - 12345;
-
- ff_spatial_dwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
- ff_spatial_idwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
-
- for(i=0; i<width*height; i++)
- if(buffer[0][i]!= buffer[1][i]) printf("fsck: %d %d %d\n",i, buffer[0][i], buffer[1][i]);
-
- printf("testing 9/7 DWT\n");
- s.spatial_decomposition_type=0;
- for(i=0; i<width*height; i++)
- buffer[0][i]= buffer[1][i]= random()%54321 - 12345;
-
- ff_spatial_dwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
- ff_spatial_idwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
-
- for(i=0; i<width*height; i++)
- if(FFABS(buffer[0][i] - buffer[1][i])>20) printf("fsck: %d %d %d\n",i, buffer[0][i], buffer[1][i]);
-
-#if 0
- printf("testing AC coder\n");
- memset(s.header_state, 0, sizeof(s.header_state));
- ff_init_range_encoder(&s.c, buffer[0], 256*256);
- ff_init_cabac_states(&s.c, ff_h264_lps_range, ff_h264_mps_state, ff_h264_lps_state, 64);
-
- for(i=-256; i<256; i++){
-START_TIMER
- put_symbol(&s.c, s.header_state, i*i*i/3*FFABS(i), 1);
-STOP_TIMER("put_symbol")
- }
- ff_rac_terminate(&s.c);
-
- memset(s.header_state, 0, sizeof(s.header_state));
- ff_init_range_decoder(&s.c, buffer[0], 256*256);
- ff_init_cabac_states(&s.c, ff_h264_lps_range, ff_h264_mps_state, ff_h264_lps_state, 64);
-
- for(i=-256; i<256; i++){
- int j;
-START_TIMER
- j= get_symbol(&s.c, s.header_state, 1);
-STOP_TIMER("get_symbol")
- if(j!=i*i*i/3*FFABS(i)) printf("fsck: %d != %d\n", i, j);
- }
-#endif
-{
-int level, orientation, x, y;
-int64_t errors[8][4];
-int64_t g=0;
-
- memset(errors, 0, sizeof(errors));
- s.spatial_decomposition_count=3;
- s.spatial_decomposition_type=0;
- for(level=0; level<s.spatial_decomposition_count; level++){
- for(orientation=level ? 1 : 0; orientation<4; orientation++){
- int w= width >> (s.spatial_decomposition_count-level);
- int h= height >> (s.spatial_decomposition_count-level);
- int stride= width << (s.spatial_decomposition_count-level);
- DWTELEM *buf= buffer[0];
- int64_t error=0;
-
- if(orientation&1) buf+=w;
- if(orientation>1) buf+=stride>>1;
-
- memset(buffer[0], 0, sizeof(int)*width*height);
- buf[w/2 + h/2*stride]= 256*256;
- ff_spatial_idwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
- for(y=0; y<height; y++){
- for(x=0; x<width; x++){
- int64_t d= buffer[0][x + y*width];
- error += d*d;
- if(FFABS(width/2-x)<9 && FFABS(height/2-y)<9 && level==2) printf("%8"PRId64" ", d);
- }
- if(FFABS(height/2-y)<9 && level==2) printf("\n");
- }
- error= (int)(sqrt(error)+0.5);
- errors[level][orientation]= error;
- if(g) g=ff_gcd(g, error);
- else g= error;
- }
- }
- printf("static int const visual_weight[][4]={\n");
- for(level=0; level<s.spatial_decomposition_count; level++){
- printf(" {");
- for(orientation=0; orientation<4; orientation++){
- printf("%8"PRId64",", errors[level][orientation]/g);
- }
- printf("},\n");
- }
- printf("};\n");
- {
- int level=2;
- int orientation=3;
- int w= width >> (s.spatial_decomposition_count-level);
- int h= height >> (s.spatial_decomposition_count-level);
- int stride= width << (s.spatial_decomposition_count-level);
- DWTELEM *buf= buffer[0];
- int64_t error=0;
-
- buf+=w;
- buf+=stride>>1;
-
- memset(buffer[0], 0, sizeof(int)*width*height);
-#if 1
- for(y=0; y<height; y++){
- for(x=0; x<width; x++){
- int tab[4]={0,2,3,1};
- buffer[0][x+width*y]= 256*256*tab[(x&1) + 2*(y&1)];
- }
- }
- ff_spatial_dwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
-#else
- for(y=0; y<h; y++){
- for(x=0; x<w; x++){
- buf[x + y*stride ]=169;
- buf[x + y*stride-w]=64;
- }
- }
- ff_spatial_idwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
-#endif
- for(y=0; y<height; y++){
- for(x=0; x<width; x++){
- int64_t d= buffer[0][x + y*width];
- error += d*d;
- if(FFABS(width/2-x)<9 && FFABS(height/2-y)<9) printf("%8"PRId64" ", d);
- }
- if(FFABS(height/2-y)<9) printf("\n");
- }
- }
-
-}
- return 0;
-}
-#endif
-
diff --git a/src/libffmpeg/libavcodec/snow.h b/src/libffmpeg/libavcodec/snow.h
deleted file mode 100644
index 6794d2c5a..000000000
--- a/src/libffmpeg/libavcodec/snow.h
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * Copyright (C) 2004 Michael Niedermayer <michaelni@gmx.at>
- * Copyright (C) 2006 Robert Edele <yartrebo@earthlink.net>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General 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 _SNOW_H
-#define _SNOW_H
-
-#include "dsputil.h"
-
-#define MID_STATE 128
-
-#define MAX_DECOMPOSITIONS 8
-#define MAX_PLANES 4
-#define QSHIFT 5
-#define QROOT (1<<QSHIFT)
-#define LOSSLESS_QLOG -128
-#define FRAC_BITS 8
-#define MAX_REF_FRAMES 8
-
-#define LOG2_OBMC_MAX 8
-#define OBMC_MAX (1<<(LOG2_OBMC_MAX))
-
-#define DWT_97 0
-#define DWT_53 1
-#define DWT_X 2
-
-/** Used to minimize the amount of memory used in order to optimize cache performance. **/
-struct slice_buffer_s {
- DWTELEM * * line; ///< For use by idwt and predict_slices.
- DWTELEM * * data_stack; ///< Used for internal purposes.
- int data_stack_top;
- int line_count;
- int line_width;
- int data_count;
- DWTELEM * base_buffer; ///< Buffer that this structure is caching.
-};
-
-#define liftS lift
-#define lift5 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
-
-extern void ff_snow_vertical_compose97i(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWTELEM *b3, DWTELEM *b4, DWTELEM *b5, int width);
-extern void ff_snow_horizontal_compose97i(DWTELEM *b, int width);
-extern void ff_snow_inner_add_yblock(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);
-
-#ifdef CONFIG_SNOW_ENCODER
-int w53_32_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h);
-int w97_32_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h);
-#else
-static int w53_32_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {assert (0);}
-static int w97_32_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {assert (0);}
-#endif
-
-/* C bits used by mmx/sse2/altivec */
-
-static av_always_inline void snow_interleave_line_header(int * i, int width, DWTELEM * low, DWTELEM * high){
- (*i) = (width) - 2;
-
- if (width & 1){
- low[(*i)+1] = low[((*i)+1)>>1];
- (*i)--;
- }
-}
-
-static av_always_inline void snow_interleave_line_footer(int * i, DWTELEM * low, DWTELEM * high){
- for (; (*i)>=0; (*i)-=2){
- low[(*i)+1] = high[(*i)>>1];
- low[*i] = low[(*i)>>1];
- }
-}
-
-static av_always_inline void snow_horizontal_compose_lift_lead_out(int i, DWTELEM * dst, DWTELEM * src, DWTELEM * ref, int width, int w, int lift_high, int mul, int add, int shift){
- for(; i<w; i++){
- dst[i] = src[i] - ((mul * (ref[i] + ref[i + 1]) + add) >> shift);
- }
-
- if((width^lift_high)&1){
- dst[w] = src[w] - ((mul * 2 * ref[w] + add) >> shift);
- }
-}
-
-static av_always_inline void snow_horizontal_compose_liftS_lead_out(int i, DWTELEM * dst, DWTELEM * src, DWTELEM * ref, int width, int w){
- for(; i<w; i++){
- dst[i] = src[i] - (((-(ref[i] + ref[(i+1)])+W_BO) - 4 * src[i]) >> W_BS);
- }
-
- if(width&1){
- dst[w] = src[w] - (((-2 * ref[w] + W_BO) - 4 * src[w]) >> W_BS);
- }
-}
-
-#endif
diff --git a/src/libffmpeg/libavcodec/sparc/Makefile.am b/src/libffmpeg/libavcodec/sparc/Makefile.am
deleted file mode 100644
index c3973f2ea..000000000
--- a/src/libffmpeg/libavcodec/sparc/Makefile.am
+++ /dev/null
@@ -1,18 +0,0 @@
-include $(top_srcdir)/misc/Makefile.common
-
-AM_CPPFLAGS = $(LIBFFMPEG_CPPFLAGS) -I$(top_srcdir)/src/libffmpeg/libavutil -I$(top_srcdir)/src/libffmpeg
-AM_CFLAGS = -fno-strict-aliasing
-ASFLAGS =
-
-noinst_LTLIBRARIES = libavcodec_sparc.la
-
-libavcodec_sparc_src = dsputil_vis.c
-libavcodec_sparc_dummy = libavcodec_sparc_dummy.c
-
-EXTRA_DIST = $(libavcodec_sparc_src) $(libavcodec_sparc_dummy) vis.h
-
-if ENABLE_VIS
-sparc_modules = $(libavcodec_sparc_src)
-endif
-
-libavcodec_sparc_la_SOURCES = $(sparc_modules) $(libavcodec_sparc_dummy)
diff --git a/src/libffmpeg/libavcodec/sparc/libavcodec_sparc_dummy.c b/src/libffmpeg/libavcodec/sparc/libavcodec_sparc_dummy.c
deleted file mode 100644
index 5efeac422..000000000
--- a/src/libffmpeg/libavcodec/sparc/libavcodec_sparc_dummy.c
+++ /dev/null
@@ -1,2 +0,0 @@
-
-char libavcodec_sparc_dummy;
diff --git a/src/libffmpeg/libavcodec/svq1.c b/src/libffmpeg/libavcodec/svq1.c
deleted file mode 100644
index 5e8616269..000000000
--- a/src/libffmpeg/libavcodec/svq1.c
+++ /dev/null
@@ -1,1431 +0,0 @@
-/*
- *
- * Copyright (C) 2002 the xine project
- * Copyright (C) 2002 the ffmpeg project
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * (SVQ1 Decoder)
- * Ported to mplayer by Arpi <arpi@thot.banki.hu>
- * Ported to libavcodec by Nick Kurshev <nickols_k@mail.ru>
- *
- * SVQ1 Encoder (c) 2004 Mike Melanson <melanson@pcisys.net>
- */
-
-/**
- * @file svq1.c
- * Sorenson Vector Quantizer #1 (SVQ1) video codec.
- * For more information of the SVQ1 algorithm, visit:
- * http://www.pcisys.net/~melanson/codecs/
- */
-
-
-//#define DEBUG_SVQ1
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <limits.h>
-
-#include "common.h"
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-#include "bswap.h"
-
-#undef NDEBUG
-#include <assert.h>
-
-extern const uint8_t mvtab[33][2];
-
-static VLC svq1_block_type;
-static VLC svq1_motion_component;
-static VLC svq1_intra_multistage[6];
-static VLC svq1_inter_multistage[6];
-static VLC svq1_intra_mean;
-static VLC svq1_inter_mean;
-
-#define SVQ1_BLOCK_SKIP 0
-#define SVQ1_BLOCK_INTER 1
-#define SVQ1_BLOCK_INTER_4V 2
-#define SVQ1_BLOCK_INTRA 3
-
-typedef struct SVQ1Context {
- MpegEncContext m; // needed for motion estimation, should not be used for anything else, the idea is to make the motion estimation eventually independant of MpegEncContext, so this will be removed then (FIXME/XXX)
- AVCodecContext *avctx;
- DSPContext dsp;
- AVFrame picture;
- AVFrame current_picture;
- AVFrame last_picture;
- PutBitContext pb;
- GetBitContext gb;
-
- PutBitContext reorder_pb[6]; //why ooh why this sick breadth first order, everything is slower and more complex
-
- int frame_width;
- int frame_height;
-
- /* Y plane block dimensions */
- int y_block_width;
- int y_block_height;
-
- /* U & V plane (C planes) block dimensions */
- int c_block_width;
- int c_block_height;
-
- uint16_t *mb_type;
- uint32_t *dummy;
- int16_t (*motion_val8[3])[2];
- int16_t (*motion_val16[3])[2];
-
- int64_t rd_total;
-} SVQ1Context;
-
-/* motion vector (prediction) */
-typedef struct svq1_pmv_s {
- int x;
- int y;
-} svq1_pmv_t;
-
-#include "svq1_cb.h"
-#include "svq1_vlc.h"
-
-static const uint16_t checksum_table[256] = {
- 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
- 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
- 0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
- 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
- 0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
- 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
- 0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
- 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
- 0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
- 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
- 0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
- 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
- 0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
- 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
- 0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
- 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
- 0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
- 0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
- 0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
- 0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
- 0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
- 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
- 0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
- 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
- 0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
- 0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
- 0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
- 0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
- 0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
- 0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
- 0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
- 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0
-};
-
-static const uint8_t string_table[256] = {
- 0x00, 0xD5, 0x7F, 0xAA, 0xFE, 0x2B, 0x81, 0x54,
- 0x29, 0xFC, 0x56, 0x83, 0xD7, 0x02, 0xA8, 0x7D,
- 0x52, 0x87, 0x2D, 0xF8, 0xAC, 0x79, 0xD3, 0x06,
- 0x7B, 0xAE, 0x04, 0xD1, 0x85, 0x50, 0xFA, 0x2F,
- 0xA4, 0x71, 0xDB, 0x0E, 0x5A, 0x8F, 0x25, 0xF0,
- 0x8D, 0x58, 0xF2, 0x27, 0x73, 0xA6, 0x0C, 0xD9,
- 0xF6, 0x23, 0x89, 0x5C, 0x08, 0xDD, 0x77, 0xA2,
- 0xDF, 0x0A, 0xA0, 0x75, 0x21, 0xF4, 0x5E, 0x8B,
- 0x9D, 0x48, 0xE2, 0x37, 0x63, 0xB6, 0x1C, 0xC9,
- 0xB4, 0x61, 0xCB, 0x1E, 0x4A, 0x9F, 0x35, 0xE0,
- 0xCF, 0x1A, 0xB0, 0x65, 0x31, 0xE4, 0x4E, 0x9B,
- 0xE6, 0x33, 0x99, 0x4C, 0x18, 0xCD, 0x67, 0xB2,
- 0x39, 0xEC, 0x46, 0x93, 0xC7, 0x12, 0xB8, 0x6D,
- 0x10, 0xC5, 0x6F, 0xBA, 0xEE, 0x3B, 0x91, 0x44,
- 0x6B, 0xBE, 0x14, 0xC1, 0x95, 0x40, 0xEA, 0x3F,
- 0x42, 0x97, 0x3D, 0xE8, 0xBC, 0x69, 0xC3, 0x16,
- 0xEF, 0x3A, 0x90, 0x45, 0x11, 0xC4, 0x6E, 0xBB,
- 0xC6, 0x13, 0xB9, 0x6C, 0x38, 0xED, 0x47, 0x92,
- 0xBD, 0x68, 0xC2, 0x17, 0x43, 0x96, 0x3C, 0xE9,
- 0x94, 0x41, 0xEB, 0x3E, 0x6A, 0xBF, 0x15, 0xC0,
- 0x4B, 0x9E, 0x34, 0xE1, 0xB5, 0x60, 0xCA, 0x1F,
- 0x62, 0xB7, 0x1D, 0xC8, 0x9C, 0x49, 0xE3, 0x36,
- 0x19, 0xCC, 0x66, 0xB3, 0xE7, 0x32, 0x98, 0x4D,
- 0x30, 0xE5, 0x4F, 0x9A, 0xCE, 0x1B, 0xB1, 0x64,
- 0x72, 0xA7, 0x0D, 0xD8, 0x8C, 0x59, 0xF3, 0x26,
- 0x5B, 0x8E, 0x24, 0xF1, 0xA5, 0x70, 0xDA, 0x0F,
- 0x20, 0xF5, 0x5F, 0x8A, 0xDE, 0x0B, 0xA1, 0x74,
- 0x09, 0xDC, 0x76, 0xA3, 0xF7, 0x22, 0x88, 0x5D,
- 0xD6, 0x03, 0xA9, 0x7C, 0x28, 0xFD, 0x57, 0x82,
- 0xFF, 0x2A, 0x80, 0x55, 0x01, 0xD4, 0x7E, 0xAB,
- 0x84, 0x51, 0xFB, 0x2E, 0x7A, 0xAF, 0x05, 0xD0,
- 0xAD, 0x78, 0xD2, 0x07, 0x53, 0x86, 0x2C, 0xF9
-};
-
-#define SVQ1_PROCESS_VECTOR()\
- for (; level > 0; i++) {\
- /* process next depth */\
- if (i == m) {\
- m = n;\
- if (--level == 0)\
- break;\
- }\
- /* divide block if next bit set */\
- if (get_bits (bitbuf, 1) == 0)\
- break;\
- /* add child nodes */\
- list[n++] = list[i];\
- list[n++] = list[i] + (((level & 1) ? pitch : 1) << ((level / 2) + 1));\
- }
-
-#define SVQ1_ADD_CODEBOOK()\
- /* add codebook entries to vector */\
- for (j=0; j < stages; j++) {\
- n3 = codebook[entries[j]] ^ 0x80808080;\
- n1 += ((n3 & 0xFF00FF00) >> 8);\
- n2 += (n3 & 0x00FF00FF);\
- }\
-\
- /* clip to [0..255] */\
- if (n1 & 0xFF00FF00) {\
- n3 = ((( n1 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;\
- n1 += 0x7F007F00;\
- n1 |= (((~n1 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;\
- n1 &= (n3 & 0x00FF00FF);\
- }\
-\
- if (n2 & 0xFF00FF00) {\
- n3 = ((( n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;\
- n2 += 0x7F007F00;\
- n2 |= (((~n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;\
- n2 &= (n3 & 0x00FF00FF);\
- }
-
-#define SVQ1_DO_CODEBOOK_INTRA()\
- for (y=0; y < height; y++) {\
- for (x=0; x < (width / 4); x++, codebook++) {\
- n1 = n4;\
- n2 = n4;\
- SVQ1_ADD_CODEBOOK()\
- /* store result */\
- dst[x] = (n1 << 8) | n2;\
- }\
- dst += (pitch / 4);\
- }
-
-#define SVQ1_DO_CODEBOOK_NONINTRA()\
- for (y=0; y < height; y++) {\
- for (x=0; x < (width / 4); x++, codebook++) {\
- n3 = dst[x];\
- /* add mean value to vector */\
- n1 = ((n3 & 0xFF00FF00) >> 8) + n4;\
- n2 = (n3 & 0x00FF00FF) + n4;\
- SVQ1_ADD_CODEBOOK()\
- /* store result */\
- dst[x] = (n1 << 8) | n2;\
- }\
- dst += (pitch / 4);\
- }
-
-#define SVQ1_CALC_CODEBOOK_ENTRIES(cbook)\
- codebook = (const uint32_t *) cbook[level];\
- bit_cache = get_bits (bitbuf, 4*stages);\
- /* calculate codebook entries for this vector */\
- for (j=0; j < stages; j++) {\
- entries[j] = (((bit_cache >> (4*(stages - j - 1))) & 0xF) + 16*j) << (level + 1);\
- }\
- mean -= (stages * 128);\
- n4 = ((mean + (mean >> 31)) << 16) | (mean & 0xFFFF);
-
-static int svq1_decode_block_intra (GetBitContext *bitbuf, uint8_t *pixels, int pitch ) {
- uint32_t bit_cache;
- uint8_t *list[63];
- uint32_t *dst;
- const uint32_t *codebook;
- int entries[6];
- int i, j, m, n;
- int mean, stages;
- unsigned x, y, width, height, level;
- uint32_t n1, n2, n3, n4;
-
- /* initialize list for breadth first processing of vectors */
- list[0] = pixels;
-
- /* recursively process vector */
- for (i=0, m=1, n=1, level=5; i < n; i++) {
- SVQ1_PROCESS_VECTOR();
-
- /* destination address and vector size */
- dst = (uint32_t *) list[i];
- width = 1 << ((4 + level) /2);
- height = 1 << ((3 + level) /2);
-
- /* get number of stages (-1 skips vector, 0 for mean only) */
- stages = get_vlc2(bitbuf, svq1_intra_multistage[level].table, 3, 3) - 1;
-
- if (stages == -1) {
- for (y=0; y < height; y++) {
- memset (&dst[y*(pitch / 4)], 0, width);
- }
- continue; /* skip vector */
- }
-
- if ((stages > 0) && (level >= 4)) {
-#ifdef DEBUG_SVQ1
- av_log(s->avctx, AV_LOG_INFO, "Error (svq1_decode_block_intra): invalid vector: stages=%i level=%i\n",stages,level);
-#endif
- return -1; /* invalid vector */
- }
-
- mean = get_vlc2(bitbuf, svq1_intra_mean.table, 8, 3);
-
- if (stages == 0) {
- for (y=0; y < height; y++) {
- memset (&dst[y*(pitch / 4)], mean, width);
- }
- } else {
- SVQ1_CALC_CODEBOOK_ENTRIES(svq1_intra_codebooks);
- SVQ1_DO_CODEBOOK_INTRA()
- }
- }
-
- return 0;
-}
-
-static int svq1_decode_block_non_intra (GetBitContext *bitbuf, uint8_t *pixels, int pitch ) {
- uint32_t bit_cache;
- uint8_t *list[63];
- uint32_t *dst;
- const uint32_t *codebook;
- int entries[6];
- int i, j, m, n;
- int mean, stages;
- int x, y, width, height, level;
- uint32_t n1, n2, n3, n4;
-
- /* initialize list for breadth first processing of vectors */
- list[0] = pixels;
-
- /* recursively process vector */
- for (i=0, m=1, n=1, level=5; i < n; i++) {
- SVQ1_PROCESS_VECTOR();
-
- /* destination address and vector size */
- dst = (uint32_t *) list[i];
- width = 1 << ((4 + level) /2);
- height = 1 << ((3 + level) /2);
-
- /* get number of stages (-1 skips vector, 0 for mean only) */
- stages = get_vlc2(bitbuf, svq1_inter_multistage[level].table, 3, 2) - 1;
-
- if (stages == -1) continue; /* skip vector */
-
- if ((stages > 0) && (level >= 4)) {
-#ifdef DEBUG_SVQ1
- av_log(s->avctx, AV_LOG_INFO, "Error (svq1_decode_block_non_intra): invalid vector: stages=%i level=%i\n",stages,level);
-#endif
- return -1; /* invalid vector */
- }
-
- mean = get_vlc2(bitbuf, svq1_inter_mean.table, 9, 3) - 256;
-
- SVQ1_CALC_CODEBOOK_ENTRIES(svq1_inter_codebooks);
- SVQ1_DO_CODEBOOK_NONINTRA()
- }
- return 0;
-}
-
-static int svq1_decode_motion_vector (GetBitContext *bitbuf, svq1_pmv_t *mv, svq1_pmv_t **pmv) {
- int diff;
- int i;
-
- for (i=0; i < 2; i++) {
-
- /* get motion code */
- diff = get_vlc2(bitbuf, svq1_motion_component.table, 7, 2);
- if(diff<0)
- return -1;
- else if(diff){
- if(get_bits1(bitbuf)) diff= -diff;
- }
-
- /* add median of motion vector predictors and clip result */
- if (i == 1)
- mv->y = ((diff + mid_pred(pmv[0]->y, pmv[1]->y, pmv[2]->y)) << 26) >> 26;
- else
- mv->x = ((diff + mid_pred(pmv[0]->x, pmv[1]->x, pmv[2]->x)) << 26) >> 26;
- }
-
- return 0;
-}
-
-static void svq1_skip_block (uint8_t *current, uint8_t *previous, int pitch, int x, int y) {
- uint8_t *src;
- uint8_t *dst;
- int i;
-
- src = &previous[x + y*pitch];
- dst = current;
-
- for (i=0; i < 16; i++) {
- memcpy (dst, src, 16);
- src += pitch;
- dst += pitch;
- }
-}
-
-static int svq1_motion_inter_block (MpegEncContext *s, GetBitContext *bitbuf,
- uint8_t *current, uint8_t *previous, int pitch,
- svq1_pmv_t *motion, int x, int y) {
- uint8_t *src;
- uint8_t *dst;
- svq1_pmv_t mv;
- svq1_pmv_t *pmv[3];
- int result;
-
- /* predict and decode motion vector */
- pmv[0] = &motion[0];
- if (y == 0) {
- pmv[1] =
- pmv[2] = pmv[0];
- }
- else {
- pmv[1] = &motion[(x / 8) + 2];
- pmv[2] = &motion[(x / 8) + 4];
- }
-
- result = svq1_decode_motion_vector (bitbuf, &mv, pmv);
-
- if (result != 0)
- return result;
-
- motion[0].x =
- motion[(x / 8) + 2].x =
- motion[(x / 8) + 3].x = mv.x;
- motion[0].y =
- motion[(x / 8) + 2].y =
- motion[(x / 8) + 3].y = mv.y;
-
- if(y + (mv.y >> 1)<0)
- mv.y= 0;
- if(x + (mv.x >> 1)<0)
- mv.x= 0;
-
-#if 0
- int w= (s->width+15)&~15;
- int h= (s->height+15)&~15;
- if(x + (mv.x >> 1)<0 || y + (mv.y >> 1)<0 || x + (mv.x >> 1) + 16 > w || y + (mv.y >> 1) + 16> h)
- av_log(s->avctx, AV_LOG_INFO, "%d %d %d %d\n", x, y, x + (mv.x >> 1), y + (mv.y >> 1));
-#endif
-
- src = &previous[(x + (mv.x >> 1)) + (y + (mv.y >> 1))*pitch];
- dst = current;
-
- s->dsp.put_pixels_tab[0][((mv.y & 1) << 1) | (mv.x & 1)](dst,src,pitch,16);
-
- return 0;
-}
-
-static int svq1_motion_inter_4v_block (MpegEncContext *s, GetBitContext *bitbuf,
- uint8_t *current, uint8_t *previous, int pitch,
- svq1_pmv_t *motion,int x, int y) {
- uint8_t *src;
- uint8_t *dst;
- svq1_pmv_t mv;
- svq1_pmv_t *pmv[4];
- int i, result;
-
- /* predict and decode motion vector (0) */
- pmv[0] = &motion[0];
- if (y == 0) {
- pmv[1] =
- pmv[2] = pmv[0];
- }
- else {
- pmv[1] = &motion[(x / 8) + 2];
- pmv[2] = &motion[(x / 8) + 4];
- }
-
- result = svq1_decode_motion_vector (bitbuf, &mv, pmv);
-
- if (result != 0)
- return result;
-
- /* predict and decode motion vector (1) */
- pmv[0] = &mv;
- if (y == 0) {
- pmv[1] =
- pmv[2] = pmv[0];
- }
- else {
- pmv[1] = &motion[(x / 8) + 3];
- }
- result = svq1_decode_motion_vector (bitbuf, &motion[0], pmv);
-
- if (result != 0)
- return result;
-
- /* predict and decode motion vector (2) */
- pmv[1] = &motion[0];
- pmv[2] = &motion[(x / 8) + 1];
-
- result = svq1_decode_motion_vector (bitbuf, &motion[(x / 8) + 2], pmv);
-
- if (result != 0)
- return result;
-
- /* predict and decode motion vector (3) */
- pmv[2] = &motion[(x / 8) + 2];
- pmv[3] = &motion[(x / 8) + 3];
-
- result = svq1_decode_motion_vector (bitbuf, pmv[3], pmv);
-
- if (result != 0)
- return result;
-
- /* form predictions */
- for (i=0; i < 4; i++) {
- int mvx= pmv[i]->x + (i&1)*16;
- int mvy= pmv[i]->y + (i>>1)*16;
-
- ///XXX /FIXME cliping or padding?
- if(y + (mvy >> 1)<0)
- mvy= 0;
- if(x + (mvx >> 1)<0)
- mvx= 0;
-
-#if 0
- int w= (s->width+15)&~15;
- int h= (s->height+15)&~15;
- if(x + (mvx >> 1)<0 || y + (mvy >> 1)<0 || x + (mvx >> 1) + 8 > w || y + (mvy >> 1) + 8> h)
- av_log(s->avctx, AV_LOG_INFO, "%d %d %d %d\n", x, y, x + (mvx >> 1), y + (mvy >> 1));
-#endif
- src = &previous[(x + (mvx >> 1)) + (y + (mvy >> 1))*pitch];
- dst = current;
-
- s->dsp.put_pixels_tab[1][((mvy & 1) << 1) | (mvx & 1)](dst,src,pitch,8);
-
- /* select next block */
- if (i & 1) {
- current += 8*(pitch - 1);
- } else {
- current += 8;
- }
- }
-
- return 0;
-}
-
-static int svq1_decode_delta_block (MpegEncContext *s, GetBitContext *bitbuf,
- uint8_t *current, uint8_t *previous, int pitch,
- svq1_pmv_t *motion, int x, int y) {
- uint32_t block_type;
- int result = 0;
-
- /* get block type */
- block_type = get_vlc2(bitbuf, svq1_block_type.table, 2, 2);
-
- /* reset motion vectors */
- if (block_type == SVQ1_BLOCK_SKIP || block_type == SVQ1_BLOCK_INTRA) {
- motion[0].x =
- motion[0].y =
- motion[(x / 8) + 2].x =
- motion[(x / 8) + 2].y =
- motion[(x / 8) + 3].x =
- motion[(x / 8) + 3].y = 0;
- }
-
- switch (block_type) {
- case SVQ1_BLOCK_SKIP:
- svq1_skip_block (current, previous, pitch, x, y);
- break;
-
- case SVQ1_BLOCK_INTER:
- result = svq1_motion_inter_block (s, bitbuf, current, previous, pitch, motion, x, y);
-
- if (result != 0)
- {
-#ifdef DEBUG_SVQ1
- av_log(s->avctx, AV_LOG_INFO, "Error in svq1_motion_inter_block %i\n",result);
-#endif
- break;
- }
- result = svq1_decode_block_non_intra (bitbuf, current, pitch);
- break;
-
- case SVQ1_BLOCK_INTER_4V:
- result = svq1_motion_inter_4v_block (s, bitbuf, current, previous, pitch, motion, x, y);
-
- if (result != 0)
- {
-#ifdef DEBUG_SVQ1
- av_log(s->avctx, AV_LOG_INFO, "Error in svq1_motion_inter_4v_block %i\n",result);
-#endif
- break;
- }
- result = svq1_decode_block_non_intra (bitbuf, current, pitch);
- break;
-
- case SVQ1_BLOCK_INTRA:
- result = svq1_decode_block_intra (bitbuf, current, pitch);
- break;
- }
-
- return result;
-}
-
-/* standard video sizes */
-static struct { int width; int height; } svq1_frame_size_table[8] = {
- { 160, 120 }, { 128, 96 }, { 176, 144 }, { 352, 288 },
- { 704, 576 }, { 240, 180 }, { 320, 240 }, { -1, -1 }
-};
-
-static uint16_t svq1_packet_checksum (uint8_t *data, int length, int value) {
- int i;
-
- for (i=0; i < length; i++) {
- value = checksum_table[data[i] ^ (value >> 8)] ^ ((value & 0xFF) << 8);
- }
-
- return value;
-}
-
-#if 0 /* unused, remove? */
-static uint16_t svq1_component_checksum (uint16_t *pixels, int pitch,
- int width, int height, int value) {
- int x, y;
-
- for (y=0; y < height; y++) {
- for (x=0; x < width; x++) {
- value = checksum_table[pixels[x] ^ (value >> 8)] ^ ((value & 0xFF) << 8);
- }
-
- pixels += pitch;
- }
-
- return value;
-}
-#endif
-
-#ifdef CONFIG_DECODERS
-static void svq1_parse_string (GetBitContext *bitbuf, uint8_t *out) {
- uint8_t seed;
- int i;
-
- out[0] = get_bits (bitbuf, 8);
-
- seed = string_table[out[0]];
-
- for (i=1; i <= out[0]; i++) {
- out[i] = get_bits (bitbuf, 8) ^ seed;
- seed = string_table[out[i] ^ seed];
- }
-}
-
-static int svq1_decode_frame_header (GetBitContext *bitbuf,MpegEncContext *s) {
- int frame_size_code;
- int temporal_reference;
-
- temporal_reference = get_bits (bitbuf, 8);
-
- /* frame type */
- s->pict_type= get_bits (bitbuf, 2)+1;
- if(s->pict_type==4)
- return -1;
-
- if (s->pict_type == I_TYPE) {
-
- /* unknown fields */
- if (s->f_code == 0x50 || s->f_code == 0x60) {
- int csum = get_bits (bitbuf, 16);
-
- csum = svq1_packet_checksum ((uint8_t *)bitbuf->buffer, bitbuf->size_in_bits>>3, csum);
-
-// av_log(s->avctx, AV_LOG_INFO, "%s checksum (%02x) for packet data\n",
-// (csum == 0) ? "correct" : "incorrect", csum);
- }
-
- if ((s->f_code ^ 0x10) >= 0x50) {
- uint8_t msg[256];
-
- svq1_parse_string (bitbuf, msg);
-
- av_log(s->avctx, AV_LOG_INFO, "embedded message: \"%s\"\n", (char *) msg);
- }
-
- skip_bits (bitbuf, 2);
- skip_bits (bitbuf, 2);
- skip_bits1 (bitbuf);
-
- /* load frame size */
- frame_size_code = get_bits (bitbuf, 3);
-
- if (frame_size_code == 7) {
- /* load width, height (12 bits each) */
- s->width = get_bits (bitbuf, 12);
- s->height = get_bits (bitbuf, 12);
-
- if (!s->width || !s->height)
- return -1;
- } else {
- /* get width, height from table */
- s->width = svq1_frame_size_table[frame_size_code].width;
- s->height = svq1_frame_size_table[frame_size_code].height;
- }
- }
-
- /* unknown fields */
- if (get_bits (bitbuf, 1) == 1) {
- skip_bits1 (bitbuf); /* use packet checksum if (1) */
- skip_bits1 (bitbuf); /* component checksums after image data if (1) */
-
- if (get_bits (bitbuf, 2) != 0)
- return -1;
- }
-
- if (get_bits (bitbuf, 1) == 1) {
- skip_bits1 (bitbuf);
- skip_bits (bitbuf, 4);
- skip_bits1 (bitbuf);
- skip_bits (bitbuf, 2);
-
- while (get_bits (bitbuf, 1) == 1) {
- skip_bits (bitbuf, 8);
- }
- }
-
- return 0;
-}
-
-static int svq1_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- MpegEncContext *s=avctx->priv_data;
- uint8_t *current, *previous;
- int result, i, x, y, width, height;
- AVFrame *pict = data;
-
- /* initialize bit buffer */
- init_get_bits(&s->gb,buf,buf_size*8);
-
- /* decode frame header */
- s->f_code = get_bits (&s->gb, 22);
-
- if ((s->f_code & ~0x70) || !(s->f_code & 0x60))
- return -1;
-
- /* swap some header bytes (why?) */
- if (s->f_code != 0x20) {
- uint32_t *src = (uint32_t *) (buf + 4);
-
- for (i=0; i < 4; i++) {
- src[i] = ((src[i] << 16) | (src[i] >> 16)) ^ src[7 - i];
- }
- }
-
- result = svq1_decode_frame_header (&s->gb, s);
-
- if (result != 0)
- {
-#ifdef DEBUG_SVQ1
- av_log(s->avctx, AV_LOG_INFO, "Error in svq1_decode_frame_header %i\n",result);
-#endif
- return result;
- }
-
- //FIXME this avoids some confusion for "B frames" without 2 references
- //this should be removed after libavcodec can handle more flexible picture types & ordering
- if(s->pict_type==B_TYPE && s->last_picture_ptr==NULL) return buf_size;
-
- if(avctx->hurry_up && s->pict_type==B_TYPE) return buf_size;
- if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==B_TYPE)
- ||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=I_TYPE)
- || avctx->skip_frame >= AVDISCARD_ALL)
- return buf_size;
-
- if(MPV_frame_start(s, avctx) < 0)
- return -1;
-
- /* decode y, u and v components */
- for (i=0; i < 3; i++) {
- int linesize;
- if (i == 0) {
- width = (s->width+15)&~15;
- height = (s->height+15)&~15;
- linesize= s->linesize;
- } else {
- if(s->flags&CODEC_FLAG_GRAY) break;
- width = (s->width/4+15)&~15;
- height = (s->height/4+15)&~15;
- linesize= s->uvlinesize;
- }
-
- current = s->current_picture.data[i];
-
- if(s->pict_type==B_TYPE){
- previous = s->next_picture.data[i];
- }else{
- previous = s->last_picture.data[i];
- }
-
- if (s->pict_type == I_TYPE) {
- /* keyframe */
- for (y=0; y < height; y+=16) {
- for (x=0; x < width; x+=16) {
- result = svq1_decode_block_intra (&s->gb, &current[x], linesize);
- if (result != 0)
- {
-//#ifdef DEBUG_SVQ1
- av_log(s->avctx, AV_LOG_INFO, "Error in svq1_decode_block %i (keyframe)\n",result);
-//#endif
- return result;
- }
- }
- current += 16*linesize;
- }
- } else {
- svq1_pmv_t pmv[width/8+3];
- /* delta frame */
- memset (pmv, 0, ((width / 8) + 3) * sizeof(svq1_pmv_t));
-
- for (y=0; y < height; y+=16) {
- for (x=0; x < width; x+=16) {
- result = svq1_decode_delta_block (s, &s->gb, &current[x], previous,
- linesize, pmv, x, y);
- if (result != 0)
- {
-#ifdef DEBUG_SVQ1
- av_log(s->avctx, AV_LOG_INFO, "Error in svq1_decode_delta_block %i\n",result);
-#endif
- return result;
- }
- }
-
- pmv[0].x =
- pmv[0].y = 0;
-
- current += 16*linesize;
- }
- }
- }
-
- *pict = *(AVFrame*)&s->current_picture;
-
-
- MPV_frame_end(s);
-
- *data_size=sizeof(AVFrame);
- return buf_size;
-}
-
-static int svq1_decode_init(AVCodecContext *avctx)
-{
- MpegEncContext *s = avctx->priv_data;
- int i;
-
- MPV_decode_defaults(s);
-
- s->avctx = avctx;
- s->width = (avctx->width+3)&~3;
- s->height = (avctx->height+3)&~3;
- s->codec_id= avctx->codec->id;
- avctx->pix_fmt = PIX_FMT_YUV410P;
- avctx->has_b_frames= 1; // not true, but DP frames and these behave like unidirectional b frames
- s->flags= avctx->flags;
- if (MPV_common_init(s) < 0) return -1;
-
- init_vlc(&svq1_block_type, 2, 4,
- &svq1_block_type_vlc[0][1], 2, 1,
- &svq1_block_type_vlc[0][0], 2, 1, 1);
-
- init_vlc(&svq1_motion_component, 7, 33,
- &mvtab[0][1], 2, 1,
- &mvtab[0][0], 2, 1, 1);
-
- for (i = 0; i < 6; i++) {
- init_vlc(&svq1_intra_multistage[i], 3, 8,
- &svq1_intra_multistage_vlc[i][0][1], 2, 1,
- &svq1_intra_multistage_vlc[i][0][0], 2, 1, 1);
- init_vlc(&svq1_inter_multistage[i], 3, 8,
- &svq1_inter_multistage_vlc[i][0][1], 2, 1,
- &svq1_inter_multistage_vlc[i][0][0], 2, 1, 1);
- }
-
- init_vlc(&svq1_intra_mean, 8, 256,
- &svq1_intra_mean_vlc[0][1], 4, 2,
- &svq1_intra_mean_vlc[0][0], 4, 2, 1);
-
- init_vlc(&svq1_inter_mean, 9, 512,
- &svq1_inter_mean_vlc[0][1], 4, 2,
- &svq1_inter_mean_vlc[0][0], 4, 2, 1);
-
- return 0;
-}
-
-static int svq1_decode_end(AVCodecContext *avctx)
-{
- MpegEncContext *s = avctx->priv_data;
-
- MPV_common_end(s);
- return 0;
-}
-#endif /* CONFIG_DECODERS */
-
-#ifdef CONFIG_ENCODERS
-static void svq1_write_header(SVQ1Context *s, int frame_type)
-{
- int i;
-
- /* frame code */
- put_bits(&s->pb, 22, 0x20);
-
- /* temporal reference (sure hope this is a "don't care") */
- put_bits(&s->pb, 8, 0x00);
-
- /* frame type */
- put_bits(&s->pb, 2, frame_type - 1);
-
- if (frame_type == I_TYPE) {
-
- /* no checksum since frame code is 0x20 */
-
- /* no embedded string either */
-
- /* 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 ((svq1_frame_size_table[i].width == s->frame_width) &&
- (svq1_frame_size_table[i].height == s->frame_height))
- {
- put_bits(&s->pb, 3, i);
- break;
- }
- }
-
- 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);
- }
- }
-
- /* no checksum or extra data (next 2 bits get 0) */
- put_bits(&s->pb, 2, 0);
-}
-
-
-#define QUALITY_THRESHOLD 100
-#define THRESHOLD_MULTIPLIER 0.6
-
-#if defined(HAVE_ALTIVEC)
-#undef vector
-#endif
-
-static int encode_block(SVQ1Context *s, uint8_t *src, uint8_t *ref, uint8_t *decoded, int stride, int level, int threshold, int lambda, int intra){
- int count, y, x, i, j, split, best_mean, best_score, best_count;
- int best_vector[6];
- int block_sum[7]= {0, 0, 0, 0, 0, 0};
- int w= 2<<((level+2)>>1);
- int h= 2<<((level+1)>>1);
- int size=w*h;
- int16_t block[7][256];
- const int8_t *codebook_sum, *codebook;
- const uint16_t (*mean_vlc)[2];
- const uint8_t (*multistage_vlc)[2];
-
- best_score=0;
- //FIXME optimize, this doenst need to be done multiple times
- if(intra){
- codebook_sum= svq1_intra_codebook_sum[level];
- codebook= svq1_intra_codebooks[level];
- mean_vlc= svq1_intra_mean_vlc;
- multistage_vlc= svq1_intra_multistage_vlc[level];
- for(y=0; y<h; y++){
- for(x=0; x<w; x++){
- int v= src[x + y*stride];
- block[0][x + w*y]= v;
- best_score += v*v;
- block_sum[0] += v;
- }
- }
- }else{
- codebook_sum= svq1_inter_codebook_sum[level];
- codebook= svq1_inter_codebooks[level];
- mean_vlc= svq1_inter_mean_vlc + 256;
- multistage_vlc= svq1_inter_multistage_vlc[level];
- for(y=0; y<h; y++){
- for(x=0; x<w; x++){
- int v= src[x + y*stride] - ref[x + y*stride];
- block[0][x + w*y]= v;
- best_score += v*v;
- block_sum[0] += v;
- }
- }
- }
-
- best_count=0;
- best_score -= ((block_sum[0]*block_sum[0])>>(level+3));
- best_mean= (block_sum[0] + (size>>1)) >> (level+3);
-
- if(level<4){
- for(count=1; count<7; count++){
- int best_vector_score= INT_MAX;
- int best_vector_sum=-999, best_vector_mean=-999;
- const int stage= count-1;
- const int8_t *vector;
-
- for(i=0; i<16; i++){
- int sum= codebook_sum[stage*16 + i];
- int sqr=0;
- int diff, mean, score;
-
- vector = codebook + stage*size*16 + i*size;
-
- for(j=0; j<size; j++){
- int v= vector[j];
- sqr += (v - block[stage][j])*(v - block[stage][j]);
- }
- diff= block_sum[stage] - sum;
- mean= (diff + (size>>1)) >> (level+3);
- assert(mean >-300 && mean<300);
- if(intra) mean= clip(mean, 0, 255);
- else mean= clip(mean, -256, 255);
- score= sqr - ((diff*(int64_t)diff)>>(level+3)); //FIXME 64bit slooow
- if(score < best_vector_score){
- best_vector_score= score;
- best_vector[stage]= i;
- best_vector_sum= sum;
- best_vector_mean= mean;
- }
- }
- assert(best_vector_mean != -999);
- vector= codebook + stage*size*16 + best_vector[stage]*size;
- for(j=0; j<size; j++){
- block[stage+1][j] = block[stage][j] - vector[j];
- }
- block_sum[stage+1]= block_sum[stage] - best_vector_sum;
- best_vector_score +=
- lambda*(+ 1 + 4*count
- + multistage_vlc[1+count][1]
- + mean_vlc[best_vector_mean][1]);
-
- if(best_vector_score < best_score){
- best_score= best_vector_score;
- best_count= count;
- best_mean= best_vector_mean;
- }
- }
- }
-
- split=0;
- if(best_score > threshold && level){
- int score=0;
- int offset= (level&1) ? stride*h/2 : w/2;
- PutBitContext backup[6];
-
- for(i=level-1; i>=0; i--){
- backup[i]= s->reorder_pb[i];
- }
- score += encode_block(s, src , ref , decoded , stride, level-1, threshold>>1, lambda, intra);
- score += encode_block(s, src + offset, ref + offset, decoded + offset, stride, level-1, threshold>>1, lambda, intra);
- score += lambda;
-
- if(score < best_score){
- best_score= score;
- split=1;
- }else{
- for(i=level-1; i>=0; i--){
- s->reorder_pb[i]= backup[i];
- }
- }
- }
- if (level > 0)
- put_bits(&s->reorder_pb[level], 1, split);
-
- if(!split){
- assert((best_mean >= 0 && best_mean<256) || !intra);
- assert(best_mean >= -256 && best_mean<256);
- assert(best_count >=0 && best_count<7);
- assert(level<4 || best_count==0);
-
- /* output the encoding */
- put_bits(&s->reorder_pb[level],
- multistage_vlc[1 + best_count][1],
- multistage_vlc[1 + best_count][0]);
- put_bits(&s->reorder_pb[level], mean_vlc[best_mean][1],
- mean_vlc[best_mean][0]);
-
- for (i = 0; i < best_count; i++){
- assert(best_vector[i]>=0 && best_vector[i]<16);
- put_bits(&s->reorder_pb[level], 4, best_vector[i]);
- }
-
- for(y=0; y<h; y++){
- for(x=0; x<w; x++){
- decoded[x + y*stride]= src[x + y*stride] - block[best_count][x + w*y] + best_mean;
- }
- }
- }
-
- return best_score;
-}
-
-
-static int svq1_encode_plane(SVQ1Context *s, int plane, unsigned char *src_plane, unsigned char *ref_plane, unsigned char *decoded_plane,
- int width, int height, int src_stride, int stride)
-{
- int x, y;
- int i;
- int block_width, block_height;
- int level;
- int threshold[6];
- const int lambda= (s->picture.quality*s->picture.quality) >> (2*FF_LAMBDA_SHIFT);
-
- /* figure out the acceptable level thresholds in advance */
- threshold[5] = QUALITY_THRESHOLD;
- for (level = 4; level >= 0; level--)
- threshold[level] = threshold[level + 1] * THRESHOLD_MULTIPLIER;
-
- block_width = (width + 15) / 16;
- block_height = (height + 15) / 16;
-
- if(s->picture.pict_type == P_TYPE){
- s->m.avctx= s->avctx;
- s->m.current_picture_ptr= &s->m.current_picture;
- s->m.last_picture_ptr = &s->m.last_picture;
- s->m.last_picture.data[0]= ref_plane;
- s->m.linesize=
- s->m.last_picture.linesize[0]=
- s->m.new_picture.linesize[0]=
- s->m.current_picture.linesize[0]= stride;
- s->m.width= width;
- s->m.height= height;
- s->m.mb_width= block_width;
- s->m.mb_height= block_height;
- s->m.mb_stride= s->m.mb_width+1;
- s->m.b8_stride= 2*s->m.mb_width+1;
- s->m.f_code=1;
- s->m.pict_type= s->picture.pict_type;
- s->m.me_method= s->avctx->me_method;
- s->m.me.scene_change_score=0;
- s->m.flags= s->avctx->flags;
-// s->m.out_format = FMT_H263;
-// s->m.unrestricted_mv= 1;
-
- s->m.lambda= s->picture.quality;
- s->m.qscale= (s->m.lambda*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7);
- s->m.lambda2= (s->m.lambda*s->m.lambda + FF_LAMBDA_SCALE/2) >> FF_LAMBDA_SHIFT;
-
- if(!s->motion_val8[plane]){
- s->motion_val8 [plane]= av_mallocz((s->m.b8_stride*block_height*2 + 2)*2*sizeof(int16_t));
- s->motion_val16[plane]= av_mallocz((s->m.mb_stride*(block_height + 2) + 1)*2*sizeof(int16_t));
- }
-
- s->m.mb_type= s->mb_type;
-
- //dummies, to avoid segfaults
- s->m.current_picture.mb_mean= (uint8_t *)s->dummy;
- s->m.current_picture.mb_var= (uint16_t*)s->dummy;
- s->m.current_picture.mc_mb_var= (uint16_t*)s->dummy;
- s->m.current_picture.mb_type= s->dummy;
-
- s->m.current_picture.motion_val[0]= s->motion_val8[plane] + 2;
- s->m.p_mv_table= s->motion_val16[plane] + s->m.mb_stride + 1;
- s->m.dsp= s->dsp; //move
- ff_init_me(&s->m);
-
- 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;
-
- for(i=0; i<16 && i + 16*y<height; i++){
- memcpy(&src[i*stride], &src_plane[(i+16*y)*src_stride], width);
- for(x=width; x<16*block_width; x++)
- src[i*stride+x]= src[i*stride+x-1];
- }
- for(; i<16 && i + 16*y<16*block_height; i++)
- memcpy(&src[i*stride], &src[(i-1)*stride], 16*block_width);
-
- for (x = 0; x < block_width; x++) {
- s->m.mb_x= x;
- ff_init_block_index(&s->m);
- ff_update_block_index(&s->m);
-
- ff_estimate_p_frame_motion(&s->m, x, y);
- }
- s->m.first_slice_line=0;
- }
-
- ff_fix_long_p_mvs(&s->m);
- ff_fix_long_mvs(&s->m, NULL, 0, s->m.p_mv_table, s->m.f_code, CANDIDATE_MB_TYPE_INTER, 0);
- }
-
- 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*y<height; i++){
- memcpy(&src[i*stride], &src_plane[(i+16*y)*src_stride], width);
- for(x=width; x<16*block_width; x++)
- src[i*stride+x]= src[i*stride+x-1];
- }
- for(; i<16 && i + 16*y<16*block_height; i++)
- memcpy(&src[i*stride], &src[(i-1)*stride], 16*block_width);
-
- s->m.mb_y= y;
- for (x = 0; x < block_width; x++) {
- uint8_t reorder_buffer[3][6][7*32];
- int count[3][6];
- int offset = y * 16 * stride + x * 16;
- uint8_t *decoded= decoded_plane + offset;
- uint8_t *ref= ref_plane + offset;
- int score[4]={0,0,0,0}, best;
- uint8_t temp[16*stride];
-
- if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < 3000){ //FIXME check size
- av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
- return -1;
- }
-
- s->m.mb_x= x;
- ff_init_block_index(&s->m);
- ff_update_block_index(&s->m);
-
- if(s->picture.pict_type == I_TYPE || (s->m.mb_type[x + y*s->m.mb_stride]&CANDIDATE_MB_TYPE_INTRA)){
- for(i=0; i<6; i++){
- init_put_bits(&s->reorder_pb[i], reorder_buffer[0][i], 7*32);
- }
- if(s->picture.pict_type == P_TYPE){
- const uint8_t *vlc= svq1_block_type_vlc[SVQ1_BLOCK_INTRA];
- put_bits(&s->reorder_pb[5], vlc[1], vlc[0]);
- score[0]= vlc[1]*lambda;
- }
- score[0]+= encode_block(s, src+16*x, NULL, temp, stride, 5, 64, lambda, 1);
- for(i=0; i<6; i++){
- count[0][i]= put_bits_count(&s->reorder_pb[i]);
- flush_put_bits(&s->reorder_pb[i]);
- }
- }else
- score[0]= INT_MAX;
-
- best=0;
-
- if(s->picture.pict_type == P_TYPE){
- const uint8_t *vlc= svq1_block_type_vlc[SVQ1_BLOCK_INTER];
- int mx, my, pred_x, pred_y, dxy;
- int16_t *motion_ptr;
-
- motion_ptr= h263_pred_motion(&s->m, 0, 0, &pred_x, &pred_y);
- if(s->m.mb_type[x + y*s->m.mb_stride]&CANDIDATE_MB_TYPE_INTER){
- for(i=0; i<6; i++)
- init_put_bits(&s->reorder_pb[i], reorder_buffer[1][i], 7*32);
-
- put_bits(&s->reorder_pb[5], vlc[1], vlc[0]);
-
- s->m.pb= s->reorder_pb[5];
- mx= motion_ptr[0];
- my= motion_ptr[1];
- assert(mx>=-32 && mx<=31);
- assert(my>=-32 && my<=31);
- assert(pred_x>=-32 && pred_x<=31);
- assert(pred_y>=-32 && pred_y<=31);
- ff_h263_encode_motion(&s->m, mx - pred_x, 1);
- ff_h263_encode_motion(&s->m, my - pred_y, 1);
- s->reorder_pb[5]= s->m.pb;
- score[1] += lambda*put_bits_count(&s->reorder_pb[5]);
-
- dxy= (mx&1) + 2*(my&1);
-
- s->dsp.put_pixels_tab[0][dxy](temp+16, ref + (mx>>1) + stride*(my>>1), stride, 16);
-
- score[1]+= encode_block(s, src+16*x, temp+16, decoded, stride, 5, 64, lambda, 0);
- best= score[1] <= score[0];
-
- vlc= svq1_block_type_vlc[SVQ1_BLOCK_SKIP];
- score[2]= s->dsp.sse[0](NULL, src+16*x, ref, stride, 16);
- score[2]+= vlc[1]*lambda;
- if(score[2] < score[best] && mx==0 && my==0){
- best=2;
- s->dsp.put_pixels_tab[0][0](decoded, ref, stride, 16);
- for(i=0; i<6; i++){
- count[2][i]=0;
- }
- put_bits(&s->pb, vlc[1], vlc[0]);
- }
- }
-
- if(best==1){
- for(i=0; i<6; i++){
- count[1][i]= put_bits_count(&s->reorder_pb[i]);
- flush_put_bits(&s->reorder_pb[i]);
- }
- }else{
- motion_ptr[0 ] = motion_ptr[1 ]=
- motion_ptr[2 ] = motion_ptr[3 ]=
- motion_ptr[0+2*s->m.b8_stride] = motion_ptr[1+2*s->m.b8_stride]=
- motion_ptr[2+2*s->m.b8_stride] = motion_ptr[3+2*s->m.b8_stride]=0;
- }
- }
-
- s->rd_total += score[best];
-
- for(i=5; i>=0; i--){
- ff_copy_bits(&s->pb, reorder_buffer[best][i], count[best][i]);
- }
- if(best==0){
- s->dsp.put_pixels_tab[0][0](decoded, temp, stride, 16);
- }
- }
- s->m.first_slice_line=0;
- }
- return 0;
-}
-
-static int svq1_encode_init(AVCodecContext *avctx)
-{
- SVQ1Context * const s = avctx->priv_data;
-
- dsputil_init(&s->dsp, avctx);
- avctx->coded_frame= (AVFrame*)&s->picture;
-
- s->frame_width = avctx->width;
- s->frame_height = avctx->height;
-
- s->y_block_width = (s->frame_width + 15) / 16;
- s->y_block_height = (s->frame_height + 15) / 16;
-
- s->c_block_width = (s->frame_width / 4 + 15) / 16;
- s->c_block_height = (s->frame_height / 4 + 15) / 16;
-
- s->avctx= avctx;
- s->m.avctx= avctx;
- 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->mb_type = av_mallocz((s->y_block_width+1)*s->y_block_height*sizeof(int16_t));
- s->dummy = av_mallocz((s->y_block_width+1)*s->y_block_height*sizeof(int32_t));
- h263_encode_init(&s->m); //mv_penalty
-
- return 0;
-}
-
-static int svq1_encode_frame(AVCodecContext *avctx, unsigned char *buf,
- int buf_size, void *data)
-{
- SVQ1Context * const s = avctx->priv_data;
- AVFrame *pict = data;
- AVFrame * const p= (AVFrame*)&s->picture;
- AVFrame temp;
- int i;
-
- if(avctx->pix_fmt != PIX_FMT_YUV410P){
- av_log(avctx, AV_LOG_ERROR, "unsupported pixel format\n");
- return -1;
- }
-
- if(!s->current_picture.data[0]){
- avctx->get_buffer(avctx, &s->current_picture);
- avctx->get_buffer(avctx, &s->last_picture);
- }
-
- temp= s->current_picture;
- s->current_picture= s->last_picture;
- s->last_picture= temp;
-
- init_put_bits(&s->pb, buf, buf_size);
-
- *p = *pict;
- p->pict_type = avctx->gop_size && avctx->frame_number % avctx->gop_size ? P_TYPE : I_TYPE;
- p->key_frame = p->pict_type == I_TYPE;
-
- svq1_write_header(s, p->pict_type);
- for(i=0; i<3; i++){
- if(svq1_encode_plane(s, i,
- s->picture.data[i], s->last_picture.data[i], s->current_picture.data[i],
- s->frame_width / (i?4:1), s->frame_height / (i?4:1),
- s->picture.linesize[i], s->current_picture.linesize[i]) < 0)
- return -1;
- }
-
-// align_put_bits(&s->pb);
- while(put_bits_count(&s->pb) & 31)
- put_bits(&s->pb, 1, 0);
-
- flush_put_bits(&s->pb);
-
- return (put_bits_count(&s->pb) / 8);
-}
-
-static int svq1_encode_end(AVCodecContext *avctx)
-{
- SVQ1Context * const s = avctx->priv_data;
- int i;
-
- av_log(avctx, AV_LOG_DEBUG, "RD: %f\n", s->rd_total/(double)(avctx->width*avctx->height*avctx->frame_number));
-
- av_freep(&s->m.me.scratchpad);
- av_freep(&s->m.me.map);
- av_freep(&s->m.me.score_map);
- av_freep(&s->mb_type);
- av_freep(&s->dummy);
-
- for(i=0; i<3; i++){
- av_freep(&s->motion_val8[i]);
- av_freep(&s->motion_val16[i]);
- }
-
- return 0;
-}
-
-#endif //CONFIG_ENCODERS
-
-#ifdef CONFIG_DECODERS
-AVCodec svq1_decoder = {
- "svq1",
- CODEC_TYPE_VIDEO,
- CODEC_ID_SVQ1,
- sizeof(MpegEncContext),
- svq1_decode_init,
- NULL,
- svq1_decode_end,
- svq1_decode_frame,
- CODEC_CAP_DR1,
- .flush= ff_mpeg_flush,
- .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV410P, -1},
-};
-#endif
-
-#ifdef CONFIG_ENCODERS
-
-AVCodec svq1_encoder = {
- "svq1",
- CODEC_TYPE_VIDEO,
- CODEC_ID_SVQ1,
- sizeof(SVQ1Context),
- svq1_encode_init,
- svq1_encode_frame,
- svq1_encode_end,
- .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV410P, -1},
-};
-
-#endif //CONFIG_ENCODERS
diff --git a/src/libffmpeg/libavcodec/svq3.c b/src/libffmpeg/libavcodec/svq3.c
deleted file mode 100644
index e02981e61..000000000
--- a/src/libffmpeg/libavcodec/svq3.c
+++ /dev/null
@@ -1,1015 +0,0 @@
-/*
- * Copyright (c) 2003 The FFmpeg Project.
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- *
- * How to use this decoder:
- * SVQ3 data is transported within Apple Quicktime files. Quicktime files
- * have stsd atoms to describe media trak properties. A stsd atom for a
- * video trak contains 1 or more ImageDescription atoms. These atoms begin
- * with the 4-byte length of the atom followed by the codec fourcc. Some
- * decoders need information in this atom to operate correctly. Such
- * is the case with SVQ3. In order to get the best use out of this decoder,
- * the calling app must make the SVQ3 ImageDescription atom available
- * via the AVCodecContext's extradata[_size] field:
- *
- * AVCodecContext.extradata = pointer to ImageDescription, first characters
- * are expected to be 'S', 'V', 'Q', and '3', NOT the 4-byte atom length
- * AVCodecContext.extradata_size = size of ImageDescription atom memory
- * buffer (which will be the same as the ImageDescription atom size field
- * from the QT file, minus 4 bytes since the length is missing)
- *
- * You will know you have these parameters passed correctly when the decoder
- * correctly decodes this file:
- * ftp://ftp.mplayerhq.hu/MPlayer/samples/V-codecs/SVQ3/Vertical400kbit.sorenson3.mov
- *
- */
-
-/**
- * @file svq3.c
- * svq3 decoder.
- */
-
-#define FULLPEL_MODE 1
-#define HALFPEL_MODE 2
-#define THIRDPEL_MODE 3
-#define PREDICT_MODE 4
-
-/* dual scan (from some older h264 draft)
- o-->o-->o o
- | /|
- o o o / o
- | / | |/ |
- o o o o
- /
- o-->o-->o-->o
-*/
-static const uint8_t svq3_scan[16]={
- 0+0*4, 1+0*4, 2+0*4, 2+1*4,
- 2+2*4, 3+0*4, 3+1*4, 3+2*4,
- 0+1*4, 0+2*4, 1+1*4, 1+2*4,
- 0+3*4, 1+3*4, 2+3*4, 3+3*4,
-};
-
-static const uint8_t svq3_pred_0[25][2] = {
- { 0, 0 },
- { 1, 0 }, { 0, 1 },
- { 0, 2 }, { 1, 1 }, { 2, 0 },
- { 3, 0 }, { 2, 1 }, { 1, 2 }, { 0, 3 },
- { 0, 4 }, { 1, 3 }, { 2, 2 }, { 3, 1 }, { 4, 0 },
- { 4, 1 }, { 3, 2 }, { 2, 3 }, { 1, 4 },
- { 2, 4 }, { 3, 3 }, { 4, 2 },
- { 4, 3 }, { 3, 4 },
- { 4, 4 }
-};
-
-static const int8_t svq3_pred_1[6][6][5] = {
- { { 2,-1,-1,-1,-1 }, { 2, 1,-1,-1,-1 }, { 1, 2,-1,-1,-1 },
- { 2, 1,-1,-1,-1 }, { 1, 2,-1,-1,-1 }, { 1, 2,-1,-1,-1 } },
- { { 0, 2,-1,-1,-1 }, { 0, 2, 1, 4, 3 }, { 0, 1, 2, 4, 3 },
- { 0, 2, 1, 4, 3 }, { 2, 0, 1, 3, 4 }, { 0, 4, 2, 1, 3 } },
- { { 2, 0,-1,-1,-1 }, { 2, 1, 0, 4, 3 }, { 1, 2, 4, 0, 3 },
- { 2, 1, 0, 4, 3 }, { 2, 1, 4, 3, 0 }, { 1, 2, 4, 0, 3 } },
- { { 2, 0,-1,-1,-1 }, { 2, 0, 1, 4, 3 }, { 1, 2, 0, 4, 3 },
- { 2, 1, 0, 4, 3 }, { 2, 1, 3, 4, 0 }, { 2, 4, 1, 0, 3 } },
- { { 0, 2,-1,-1,-1 }, { 0, 2, 1, 3, 4 }, { 1, 2, 3, 0, 4 },
- { 2, 0, 1, 3, 4 }, { 2, 1, 3, 0, 4 }, { 2, 0, 4, 3, 1 } },
- { { 0, 2,-1,-1,-1 }, { 0, 2, 4, 1, 3 }, { 1, 4, 2, 0, 3 },
- { 4, 2, 0, 1, 3 }, { 2, 0, 1, 4, 3 }, { 4, 2, 1, 0, 3 } },
-};
-
-static const struct { uint8_t run; uint8_t level; } svq3_dct_tables[2][16] = {
- { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 2, 1 }, { 0, 2 }, { 3, 1 }, { 4, 1 }, { 5, 1 },
- { 0, 3 }, { 1, 2 }, { 2, 2 }, { 6, 1 }, { 7, 1 }, { 8, 1 }, { 9, 1 }, { 0, 4 } },
- { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 0, 2 }, { 2, 1 }, { 0, 3 }, { 0, 4 }, { 0, 5 },
- { 3, 1 }, { 4, 1 }, { 1, 2 }, { 1, 3 }, { 0, 6 }, { 0, 7 }, { 0, 8 }, { 0, 9 } }
-};
-
-static const uint32_t svq3_dequant_coeff[32] = {
- 3881, 4351, 4890, 5481, 6154, 6914, 7761, 8718,
- 9781, 10987, 12339, 13828, 15523, 17435, 19561, 21873,
- 24552, 27656, 30847, 34870, 38807, 43747, 49103, 54683,
- 61694, 68745, 77615, 89113,100253,109366,126635,141533
-};
-
-
-static void svq3_luma_dc_dequant_idct_c(DCTELEM *block, int qp){
- const int qmul= svq3_dequant_coeff[qp];
-#define stride 16
- int i;
- int temp[16];
- static const int x_offset[4]={0, 1*stride, 4* stride, 5*stride};
- static const int y_offset[4]={0, 2*stride, 8* stride, 10*stride};
-
- for(i=0; i<4; i++){
- const int offset= y_offset[i];
- const int z0= 13*(block[offset+stride*0] + block[offset+stride*4]);
- const int z1= 13*(block[offset+stride*0] - block[offset+stride*4]);
- const int z2= 7* block[offset+stride*1] - 17*block[offset+stride*5];
- const int z3= 17* block[offset+stride*1] + 7*block[offset+stride*5];
-
- temp[4*i+0]= z0+z3;
- temp[4*i+1]= z1+z2;
- temp[4*i+2]= z1-z2;
- temp[4*i+3]= z0-z3;
- }
-
- for(i=0; i<4; i++){
- const int offset= x_offset[i];
- const int z0= 13*(temp[4*0+i] + temp[4*2+i]);
- const int z1= 13*(temp[4*0+i] - temp[4*2+i]);
- const int z2= 7* temp[4*1+i] - 17*temp[4*3+i];
- const int z3= 17* temp[4*1+i] + 7*temp[4*3+i];
-
- block[stride*0 +offset]= ((z0 + z3)*qmul + 0x80000)>>20;
- block[stride*2 +offset]= ((z1 + z2)*qmul + 0x80000)>>20;
- block[stride*8 +offset]= ((z1 - z2)*qmul + 0x80000)>>20;
- block[stride*10+offset]= ((z0 - z3)*qmul + 0x80000)>>20;
- }
-}
-#undef stride
-
-static void svq3_add_idct_c (uint8_t *dst, DCTELEM *block, int stride, int qp, int dc){
- const int qmul= svq3_dequant_coeff[qp];
- int i;
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
-
- if (dc) {
- dc = 13*13*((dc == 1) ? 1538*block[0] : ((qmul*(block[0] >> 3)) / 2));
- block[0] = 0;
- }
-
- for (i=0; i < 4; i++) {
- const int z0= 13*(block[0 + 4*i] + block[2 + 4*i]);
- const int z1= 13*(block[0 + 4*i] - block[2 + 4*i]);
- const int z2= 7* block[1 + 4*i] - 17*block[3 + 4*i];
- const int z3= 17* block[1 + 4*i] + 7*block[3 + 4*i];
-
- block[0 + 4*i]= z0 + z3;
- block[1 + 4*i]= z1 + z2;
- block[2 + 4*i]= z1 - z2;
- block[3 + 4*i]= z0 - z3;
- }
-
- for (i=0; i < 4; i++) {
- const int z0= 13*(block[i + 4*0] + block[i + 4*2]);
- const int z1= 13*(block[i + 4*0] - block[i + 4*2]);
- const int z2= 7* block[i + 4*1] - 17*block[i + 4*3];
- const int z3= 17* block[i + 4*1] + 7*block[i + 4*3];
- const int rr= (dc + 0x80000);
-
- dst[i + stride*0]= cm[ dst[i + stride*0] + (((z0 + z3)*qmul + rr) >> 20) ];
- dst[i + stride*1]= cm[ dst[i + stride*1] + (((z1 + z2)*qmul + rr) >> 20) ];
- dst[i + stride*2]= cm[ dst[i + stride*2] + (((z1 - z2)*qmul + rr) >> 20) ];
- dst[i + stride*3]= cm[ dst[i + stride*3] + (((z0 - z3)*qmul + rr) >> 20) ];
- }
-}
-
-static void pred4x4_down_left_svq3_c(uint8_t *src, uint8_t *topright, int stride){
- LOAD_TOP_EDGE
- LOAD_LEFT_EDGE
- const __attribute__((unused)) int unu0= t0;
- const __attribute__((unused)) int unu1= l0;
-
- src[0+0*stride]=(l1 + t1)>>1;
- src[1+0*stride]=
- src[0+1*stride]=(l2 + t2)>>1;
- src[2+0*stride]=
- src[1+1*stride]=
- src[0+2*stride]=
- src[3+0*stride]=
- src[2+1*stride]=
- src[1+2*stride]=
- src[0+3*stride]=
- src[3+1*stride]=
- src[2+2*stride]=
- src[1+3*stride]=
- src[3+2*stride]=
- src[2+3*stride]=
- src[3+3*stride]=(l3 + t3)>>1;
-}
-
-static void pred16x16_plane_svq3_c(uint8_t *src, int stride){
- pred16x16_plane_compat_c(src, stride, 1);
-}
-
-static inline int svq3_decode_block (GetBitContext *gb, DCTELEM *block,
- int index, const int type) {
-
- static const uint8_t *const scan_patterns[4] =
- { luma_dc_zigzag_scan, zigzag_scan, svq3_scan, chroma_dc_scan };
-
- int run, level, sign, vlc, limit;
- const int intra = (3 * type) >> 2;
- const uint8_t *const scan = scan_patterns[type];
-
- for (limit=(16 >> intra); index < 16; index=limit, limit+=8) {
- for (; (vlc = svq3_get_ue_golomb (gb)) != 0; index++) {
-
- if (vlc == INVALID_VLC)
- return -1;
-
- sign = (vlc & 0x1) - 1;
- vlc = (vlc + 1) >> 1;
-
- if (type == 3) {
- if (vlc < 3) {
- run = 0;
- level = vlc;
- } else if (vlc < 4) {
- run = 1;
- level = 1;
- } else {
- run = (vlc & 0x3);
- level = ((vlc + 9) >> 2) - run;
- }
- } else {
- if (vlc < 16) {
- run = svq3_dct_tables[intra][vlc].run;
- level = svq3_dct_tables[intra][vlc].level;
- } else if (intra) {
- run = (vlc & 0x7);
- level = (vlc >> 3) + ((run == 0) ? 8 : ((run < 2) ? 2 : ((run < 5) ? 0 : -1)));
- } else {
- run = (vlc & 0xF);
- level = (vlc >> 4) + ((run == 0) ? 4 : ((run < 3) ? 2 : ((run < 10) ? 1 : 0)));
- }
- }
-
- if ((index += run) >= limit)
- return -1;
-
- block[scan[index]] = (level ^ sign) - sign;
- }
-
- if (type != 2) {
- break;
- }
- }
-
- return 0;
-}
-
-static inline void svq3_mc_dir_part (MpegEncContext *s,
- int x, int y, int width, int height,
- int mx, int my, int dxy,
- int thirdpel, int dir, int avg) {
-
- const Picture *pic = (dir == 0) ? &s->last_picture : &s->next_picture;
- uint8_t *src, *dest;
- int i, emu = 0;
- int blocksize= 2 - (width>>3); //16->0, 8->1, 4->2
-
- mx += x;
- my += y;
-
- if (mx < 0 || mx >= (s->h_edge_pos - width - 1) ||
- my < 0 || my >= (s->v_edge_pos - height - 1)) {
-
- if ((s->flags & CODEC_FLAG_EMU_EDGE)) {
- emu = 1;
- }
-
- mx = clip (mx, -16, (s->h_edge_pos - width + 15));
- my = clip (my, -16, (s->v_edge_pos - height + 15));
- }
-
- /* form component predictions */
- dest = s->current_picture.data[0] + x + y*s->linesize;
- src = pic->data[0] + mx + my*s->linesize;
-
- if (emu) {
- ff_emulated_edge_mc (s->edge_emu_buffer, src, s->linesize, (width + 1), (height + 1),
- mx, my, s->h_edge_pos, s->v_edge_pos);
- src = s->edge_emu_buffer;
- }
- if(thirdpel)
- (avg ? s->dsp.avg_tpel_pixels_tab : s->dsp.put_tpel_pixels_tab)[dxy](dest, src, s->linesize, width, height);
- else
- (avg ? s->dsp.avg_pixels_tab : s->dsp.put_pixels_tab)[blocksize][dxy](dest, src, s->linesize, height);
-
- if (!(s->flags & CODEC_FLAG_GRAY)) {
- mx = (mx + (mx < (int) x)) >> 1;
- my = (my + (my < (int) y)) >> 1;
- width = (width >> 1);
- height = (height >> 1);
- blocksize++;
-
- for (i=1; i < 3; i++) {
- dest = s->current_picture.data[i] + (x >> 1) + (y >> 1)*s->uvlinesize;
- src = pic->data[i] + mx + my*s->uvlinesize;
-
- if (emu) {
- ff_emulated_edge_mc (s->edge_emu_buffer, src, s->uvlinesize, (width + 1), (height + 1),
- mx, my, (s->h_edge_pos >> 1), (s->v_edge_pos >> 1));
- src = s->edge_emu_buffer;
- }
- if(thirdpel)
- (avg ? s->dsp.avg_tpel_pixels_tab : s->dsp.put_tpel_pixels_tab)[dxy](dest, src, s->uvlinesize, width, height);
- else
- (avg ? s->dsp.avg_pixels_tab : s->dsp.put_pixels_tab)[blocksize][dxy](dest, src, s->uvlinesize, height);
- }
- }
-}
-
-static inline int svq3_mc_dir (H264Context *h, int size, int mode, int dir, int avg) {
-
- int i, j, k, mx, my, dx, dy, x, y;
- MpegEncContext *const s = (MpegEncContext *) h;
- const int part_width = ((size & 5) == 4) ? 4 : 16 >> (size & 1);
- const int part_height = 16 >> ((unsigned) (size + 1) / 3);
- const int extra_width = (mode == PREDICT_MODE) ? -16*6 : 0;
- const int h_edge_pos = 6*(s->h_edge_pos - part_width ) - extra_width;
- const int v_edge_pos = 6*(s->v_edge_pos - part_height) - extra_width;
-
- for (i=0; i < 16; i+=part_height) {
- for (j=0; j < 16; j+=part_width) {
- const int b_xy = (4*s->mb_x+(j>>2)) + (4*s->mb_y+(i>>2))*h->b_stride;
- int dxy;
- x = 16*s->mb_x + j;
- y = 16*s->mb_y + i;
- k = ((j>>2)&1) + ((i>>1)&2) + ((j>>1)&4) + (i&8);
-
- if (mode != PREDICT_MODE) {
- pred_motion (h, k, (part_width >> 2), dir, 1, &mx, &my);
- } else {
- mx = s->next_picture.motion_val[0][b_xy][0]<<1;
- my = s->next_picture.motion_val[0][b_xy][1]<<1;
-
- if (dir == 0) {
- mx = ((mx * h->frame_num_offset) / h->prev_frame_num_offset + 1)>>1;
- my = ((my * h->frame_num_offset) / h->prev_frame_num_offset + 1)>>1;
- } else {
- mx = ((mx * (h->frame_num_offset - h->prev_frame_num_offset)) / h->prev_frame_num_offset + 1)>>1;
- my = ((my * (h->frame_num_offset - h->prev_frame_num_offset)) / h->prev_frame_num_offset + 1)>>1;
- }
- }
-
- /* clip motion vector prediction to frame border */
- mx = clip (mx, extra_width - 6*x, h_edge_pos - 6*x);
- my = clip (my, extra_width - 6*y, v_edge_pos - 6*y);
-
- /* get (optional) motion vector differential */
- if (mode == PREDICT_MODE) {
- dx = dy = 0;
- } else {
- dy = svq3_get_se_golomb (&s->gb);
- dx = svq3_get_se_golomb (&s->gb);
-
- if (dx == INVALID_VLC || dy == INVALID_VLC) {
- av_log(h->s.avctx, AV_LOG_ERROR, "invalid MV vlc\n");
- return -1;
- }
- }
-
- /* compute motion vector */
- if (mode == THIRDPEL_MODE) {
- int fx, fy;
- mx = ((mx + 1)>>1) + dx;
- my = ((my + 1)>>1) + dy;
- fx= ((unsigned)(mx + 0x3000))/3 - 0x1000;
- fy= ((unsigned)(my + 0x3000))/3 - 0x1000;
- dxy= (mx - 3*fx) + 4*(my - 3*fy);
-
- svq3_mc_dir_part (s, x, y, part_width, part_height, fx, fy, dxy, 1, dir, avg);
- mx += mx;
- my += my;
- } else if (mode == HALFPEL_MODE || mode == PREDICT_MODE) {
- mx = ((unsigned)(mx + 1 + 0x3000))/3 + dx - 0x1000;
- my = ((unsigned)(my + 1 + 0x3000))/3 + dy - 0x1000;
- dxy= (mx&1) + 2*(my&1);
-
- svq3_mc_dir_part (s, x, y, part_width, part_height, mx>>1, my>>1, dxy, 0, dir, avg);
- mx *= 3;
- my *= 3;
- } else {
- mx = ((unsigned)(mx + 3 + 0x6000))/6 + dx - 0x1000;
- my = ((unsigned)(my + 3 + 0x6000))/6 + dy - 0x1000;
-
- svq3_mc_dir_part (s, x, y, part_width, part_height, mx, my, 0, 0, dir, avg);
- mx *= 6;
- my *= 6;
- }
-
- /* update mv_cache */
- if (mode != PREDICT_MODE) {
- int32_t mv = pack16to32(mx,my);
-
- if (part_height == 8 && i < 8) {
- *(int32_t *) h->mv_cache[dir][scan8[k] + 1*8] = mv;
-
- if (part_width == 8 && j < 8) {
- *(int32_t *) h->mv_cache[dir][scan8[k] + 1 + 1*8] = mv;
- }
- }
- if (part_width == 8 && j < 8) {
- *(int32_t *) h->mv_cache[dir][scan8[k] + 1] = mv;
- }
- if (part_width == 4 || part_height == 4) {
- *(int32_t *) h->mv_cache[dir][scan8[k]] = mv;
- }
- }
-
- /* write back motion vectors */
- fill_rectangle(s->current_picture.motion_val[dir][b_xy], part_width>>2, part_height>>2, h->b_stride, pack16to32(mx,my), 4);
- }
- }
-
- return 0;
-}
-
-static int svq3_decode_mb (H264Context *h, unsigned int mb_type) {
- int i, j, k, m, dir, mode;
- int cbp = 0;
- uint32_t vlc;
- int8_t *top, *left;
- MpegEncContext *const s = (MpegEncContext *) h;
- const int mb_xy = s->mb_x + s->mb_y*s->mb_stride;
- const int b_xy = 4*s->mb_x + 4*s->mb_y*h->b_stride;
-
- h->top_samples_available = (s->mb_y == 0) ? 0x33FF : 0xFFFF;
- h->left_samples_available = (s->mb_x == 0) ? 0x5F5F : 0xFFFF;
- h->topright_samples_available = 0xFFFF;
-
- if (mb_type == 0) { /* SKIP */
- if (s->pict_type == P_TYPE || s->next_picture.mb_type[mb_xy] == -1) {
- svq3_mc_dir_part (s, 16*s->mb_x, 16*s->mb_y, 16, 16, 0, 0, 0, 0, 0, 0);
-
- if (s->pict_type == B_TYPE) {
- svq3_mc_dir_part (s, 16*s->mb_x, 16*s->mb_y, 16, 16, 0, 0, 0, 0, 1, 1);
- }
-
- mb_type = MB_TYPE_SKIP;
- } else {
- mb_type= FFMIN(s->next_picture.mb_type[mb_xy], 6);
- if(svq3_mc_dir (h, mb_type, PREDICT_MODE, 0, 0) < 0)
- return -1;
- if(svq3_mc_dir (h, mb_type, PREDICT_MODE, 1, 1) < 0)
- return -1;
-
- mb_type = MB_TYPE_16x16;
- }
- } else if (mb_type < 8) { /* INTER */
- if (h->thirdpel_flag && h->halfpel_flag == !get_bits (&s->gb, 1)) {
- mode = THIRDPEL_MODE;
- } else if (h->halfpel_flag && h->thirdpel_flag == !get_bits (&s->gb, 1)) {
- mode = HALFPEL_MODE;
- } else {
- mode = FULLPEL_MODE;
- }
-
- /* fill caches */
- /* note ref_cache should contain here:
- ????????
- ???11111
- N??11111
- N??11111
- N??11111
- N
- */
-
- for (m=0; m < 2; m++) {
- if (s->mb_x > 0 && h->intra4x4_pred_mode[mb_xy - 1][0] != -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];
- }
- } else {
- for (i=0; i < 4; i++) {
- *(uint32_t *) h->mv_cache[m][scan8[0] - 1 + i*8] = 0;
- }
- }
- 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);
-
- 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;
- }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;
- }else
- h->ref_cache[m][scan8[0] - 1 - 1*8] = PART_NOT_AVAILABLE;
- }else
- memset (&h->ref_cache[m][scan8[0] - 1*8 - 1], PART_NOT_AVAILABLE, 8);
-
- if (s->pict_type != B_TYPE)
- break;
- }
-
- /* decode motion vector(s) and form prediction(s) */
- if (s->pict_type == P_TYPE) {
- if(svq3_mc_dir (h, (mb_type - 1), mode, 0, 0) < 0)
- return -1;
- } else { /* B_TYPE */
- if (mb_type != 2) {
- if(svq3_mc_dir (h, 0, mode, 0, 0) < 0)
- return -1;
- } else {
- for (i=0; i < 4; i++) {
- memset (s->current_picture.motion_val[0][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t));
- }
- }
- if (mb_type != 1) {
- if(svq3_mc_dir (h, 0, mode, 1, (mb_type == 3)) < 0)
- return -1;
- } else {
- for (i=0; i < 4; i++) {
- memset (s->current_picture.motion_val[1][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t));
- }
- }
- }
-
- mb_type = MB_TYPE_16x16;
- } else if (mb_type == 8 || mb_type == 33) { /* INTRA4x4 */
- memset (h->intra4x4_pred_mode_cache, -1, 8*5*sizeof(int8_t));
-
- 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];
- }
- 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];
-
- if (h->intra4x4_pred_mode_cache[4+8*0] == -1) {
- h->top_samples_available = 0x33FF;
- }
- }
-
- /* decode prediction codes for luma blocks */
- for (i=0; i < 16; i+=2) {
- vlc = svq3_get_ue_golomb (&s->gb);
-
- if (vlc >= 25){
- av_log(h->s.avctx, AV_LOG_ERROR, "luma prediction:%d\n", vlc);
- return -1;
- }
-
- left = &h->intra4x4_pred_mode_cache[scan8[i] - 1];
- top = &h->intra4x4_pred_mode_cache[scan8[i] - 8];
-
- left[1] = svq3_pred_1[top[0] + 1][left[0] + 1][svq3_pred_0[vlc][0]];
- left[2] = svq3_pred_1[top[1] + 1][left[1] + 1][svq3_pred_0[vlc][1]];
-
- if (left[1] == -1 || left[2] == -1){
- av_log(h->s.avctx, AV_LOG_ERROR, "weird prediction\n");
- return -1;
- }
- }
- } else { /* mb_type == 33, DC_128_PRED block type */
- for (i=0; i < 4; i++) {
- memset (&h->intra4x4_pred_mode_cache[scan8[0] + 8*i], DC_PRED, 4);
- }
- }
-
- write_back_intra_pred_mode (h);
-
- if (mb_type == 8) {
- 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;
- } else {
- for (i=0; i < 4; i++) {
- memset (&h->intra4x4_pred_mode_cache[scan8[0] + 8*i], DC_128_PRED, 4);
- }
-
- h->top_samples_available = 0x33FF;
- h->left_samples_available = 0x5F5F;
- }
-
- mb_type = MB_TYPE_INTRA4x4;
- } else { /* INTRA16x16 */
- 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){
- av_log(h->s.avctx, AV_LOG_ERROR, "check_intra_pred_mode = -1\n");
- return -1;
- }
-
- cbp = i_mb_type_info[mb_type - 8].cbp;
- mb_type = MB_TYPE_INTRA16x16;
- }
-
- if (!IS_INTER(mb_type) && s->pict_type != I_TYPE) {
- for (i=0; i < 4; i++) {
- memset (s->current_picture.motion_val[0][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t));
- }
- if (s->pict_type == B_TYPE) {
- for (i=0; i < 4; i++) {
- memset (s->current_picture.motion_val[1][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t));
- }
- }
- }
- if (!IS_INTRA4x4(mb_type)) {
- memset (h->intra4x4_pred_mode[mb_xy], DC_PRED, 8);
- }
- if (!IS_SKIP(mb_type) || s->pict_type == B_TYPE) {
- memset (h->non_zero_count_cache + 8, 0, 4*9*sizeof(uint8_t));
- s->dsp.clear_blocks(h->mb);
- }
-
- if (!IS_INTRA16x16(mb_type) && (!IS_SKIP(mb_type) || s->pict_type == B_TYPE)) {
- if ((vlc = svq3_get_ue_golomb (&s->gb)) >= 48){
- av_log(h->s.avctx, AV_LOG_ERROR, "cbp_vlc=%d\n", vlc);
- return -1;
- }
-
- cbp = IS_INTRA(mb_type) ? golomb_to_intra4x4_cbp[vlc] : golomb_to_inter_cbp[vlc];
- }
- if (IS_INTRA16x16(mb_type) || (s->pict_type != I_TYPE && s->adaptive_quant && cbp)) {
- s->qscale += svq3_get_se_golomb (&s->gb);
-
- if (s->qscale > 31){
- av_log(h->s.avctx, AV_LOG_ERROR, "qscale:%d\n", s->qscale);
- return -1;
- }
- }
- if (IS_INTRA16x16(mb_type)) {
- if (svq3_decode_block (&s->gb, h->mb, 0, 0)){
- av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding intra luma dc\n");
- return -1;
- }
- }
-
- if (cbp) {
- const int index = IS_INTRA16x16(mb_type) ? 1 : 0;
- const int type = ((s->qscale < 24 && IS_INTRA4x4(mb_type)) ? 2 : 1);
-
- for (i=0; i < 4; i++) {
- if ((cbp & (1 << i))) {
- for (j=0; j < 4; j++) {
- k = index ? ((j&1) + 2*(i&1) + 2*(j&2) + 4*(i&2)) : (4*i + j);
- h->non_zero_count_cache[ scan8[k] ] = 1;
-
- if (svq3_decode_block (&s->gb, &h->mb[16*k], index, type)){
- av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding block\n");
- return -1;
- }
- }
- }
- }
-
- if ((cbp & 0x30)) {
- for (i=0; i < 2; ++i) {
- if (svq3_decode_block (&s->gb, &h->mb[16*(16 + 4*i)], 0, 3)){
- av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding chroma dc block\n");
- return -1;
- }
- }
-
- if ((cbp & 0x20)) {
- for (i=0; i < 8; i++) {
- h->non_zero_count_cache[ scan8[16+i] ] = 1;
-
- if (svq3_decode_block (&s->gb, &h->mb[16*(16 + i)], 1, 1)){
- av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding chroma ac block\n");
- return -1;
- }
- }
- }
- }
- }
-
- 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);
- }
-
- return 0;
-}
-
-static int svq3_decode_slice_header (H264Context *h) {
- MpegEncContext *const s = (MpegEncContext *) h;
- const int mb_xy = s->mb_x + s->mb_y*s->mb_stride;
- int i, header;
-
- header = get_bits (&s->gb, 8);
-
- if (((header & 0x9F) != 1 && (header & 0x9F) != 2) || (header & 0x60) == 0) {
- /* TODO: what? */
- av_log(h->s.avctx, AV_LOG_ERROR, "unsupported slice header (%02X)\n", header);
- return -1;
- } else {
- int length = (header >> 5) & 3;
-
- h->next_slice_index = get_bits_count(&s->gb) + 8*show_bits (&s->gb, 8*length) + 8*length;
-
- if (h->next_slice_index > s->gb.size_in_bits){
- av_log(h->s.avctx, AV_LOG_ERROR, "slice after bitstream end\n");
- return -1;
- }
-
- s->gb.size_in_bits = h->next_slice_index - 8*(length - 1);
- skip_bits(&s->gb, 8);
-
- if (length > 0) {
- memcpy ((uint8_t *) &s->gb.buffer[get_bits_count(&s->gb) >> 3],
- &s->gb.buffer[s->gb.size_in_bits >> 3], (length - 1));
- }
- }
-
- if ((i = svq3_get_ue_golomb (&s->gb)) == INVALID_VLC || i >= 3){
- av_log(h->s.avctx, AV_LOG_ERROR, "illegal slice type %d \n", i);
- return -1;
- }
-
- h->slice_type = golomb_to_pict_type[i];
-
- if ((header & 0x9F) == 2) {
- i = (s->mb_num < 64) ? 6 : (1 + av_log2 (s->mb_num - 1));
- s->mb_skip_run = get_bits (&s->gb, i) - (s->mb_x + (s->mb_y * s->mb_width));
- } else {
- get_bits1 (&s->gb);
- s->mb_skip_run = 0;
- }
-
- h->slice_num = get_bits (&s->gb, 8);
- s->qscale = get_bits (&s->gb, 5);
- s->adaptive_quant = get_bits1 (&s->gb);
-
- /* unknown fields */
- get_bits1 (&s->gb);
-
- if (h->unknown_svq3_flag) {
- get_bits1 (&s->gb);
- }
-
- get_bits1 (&s->gb);
- get_bits (&s->gb, 2);
-
- while (get_bits1 (&s->gb)) {
- get_bits (&s->gb, 8);
- }
-
- /* 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);
- }
- 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));
-
- if (s->mb_x > 0) {
- h->intra4x4_pred_mode[mb_xy - s->mb_stride - 1][3] = -1;
- }
- }
-
- return 0;
-}
-
-static int svq3_decode_frame (AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size) {
- MpegEncContext *const s = avctx->priv_data;
- H264Context *const h = avctx->priv_data;
- int m, mb_type;
- unsigned char *extradata;
- unsigned int size;
-
- s->flags = avctx->flags;
- s->flags2 = avctx->flags2;
- s->unrestricted_mv = 1;
-
- if (!s->context_initialized) {
- s->width = avctx->width;
- s->height = avctx->height;
- h->pred4x4[DIAG_DOWN_LEFT_PRED] = pred4x4_down_left_svq3_c;
- h->pred16x16[PLANE_PRED8x8] = pred16x16_plane_svq3_c;
- h->halfpel_flag = 1;
- h->thirdpel_flag = 1;
- h->unknown_svq3_flag = 0;
- h->chroma_qp = 4;
-
- if (MPV_common_init (s) < 0)
- return -1;
-
- h->b_stride = 4*s->mb_width;
-
- alloc_tables (h);
-
- /* prowl for the "SEQH" marker in the extradata */
- extradata = (unsigned char *)avctx->extradata;
- for (m = 0; m < avctx->extradata_size; m++) {
- if (!memcmp (extradata, "SEQH", 4))
- break;
- extradata++;
- }
-
- /* if a match was found, parse the extra data */
- if (extradata && !memcmp (extradata, "SEQH", 4)) {
-
- GetBitContext gb;
-
- size = AV_RB32(&extradata[4]);
- init_get_bits (&gb, extradata + 8, size*8);
-
- /* 'frame size code' and optional 'width, height' */
- if (get_bits (&gb, 3) == 7) {
- get_bits (&gb, 12);
- get_bits (&gb, 12);
- }
-
- h->halfpel_flag = get_bits1 (&gb);
- h->thirdpel_flag = get_bits1 (&gb);
-
- /* unknown fields */
- get_bits1 (&gb);
- get_bits1 (&gb);
- get_bits1 (&gb);
- get_bits1 (&gb);
-
- s->low_delay = get_bits1 (&gb);
-
- /* unknown field */
- get_bits1 (&gb);
-
- while (get_bits1 (&gb)) {
- get_bits (&gb, 8);
- }
-
- h->unknown_svq3_flag = get_bits1 (&gb);
- avctx->has_b_frames = !s->low_delay;
- }
- }
-
- /* special case for last picture */
- if (buf_size == 0) {
- if (s->next_picture_ptr && !s->low_delay) {
- *(AVFrame *) data = *(AVFrame *) &s->next_picture;
- *data_size = sizeof(AVFrame);
- }
- return 0;
- }
-
- init_get_bits (&s->gb, buf, 8*buf_size);
-
- s->mb_x = s->mb_y = 0;
-
- if (svq3_decode_slice_header (h))
- return -1;
-
- s->pict_type = h->slice_type;
- s->picture_number = h->slice_num;
-
- if(avctx->debug&FF_DEBUG_PICT_INFO){
- av_log(h->s.avctx, AV_LOG_DEBUG, "%c hpel:%d, tpel:%d aqp:%d qp:%d\n",
- av_get_pict_type_char(s->pict_type), h->halfpel_flag, h->thirdpel_flag,
- s->adaptive_quant, s->qscale
- );
- }
-
- /* for hurry_up==5 */
- s->current_picture.pict_type = s->pict_type;
- s->current_picture.key_frame = (s->pict_type == I_TYPE);
-
- /* skip b frames if we dont have reference frames */
- if (s->last_picture_ptr == NULL && s->pict_type == B_TYPE) return 0;
- /* skip b frames if we are in a hurry */
- if (avctx->hurry_up && s->pict_type == B_TYPE) return 0;
- /* skip everything if we are in a hurry >= 5 */
- if (avctx->hurry_up >= 5) return 0;
- if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==B_TYPE)
- ||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=I_TYPE)
- || avctx->skip_frame >= AVDISCARD_ALL)
- return 0;
-
- if (s->next_p_frame_damaged) {
- if (s->pict_type == B_TYPE)
- return 0;
- else
- s->next_p_frame_damaged = 0;
- }
-
- if (frame_start (h) < 0)
- return -1;
-
- if (s->pict_type == B_TYPE) {
- h->frame_num_offset = (h->slice_num - h->prev_frame_num);
-
- if (h->frame_num_offset < 0) {
- h->frame_num_offset += 256;
- }
- if (h->frame_num_offset == 0 || h->frame_num_offset >= h->prev_frame_num_offset) {
- av_log(h->s.avctx, AV_LOG_ERROR, "error in B-frame picture id\n");
- return -1;
- }
- } else {
- h->prev_frame_num = h->frame_num;
- h->frame_num = h->slice_num;
- h->prev_frame_num_offset = (h->frame_num - h->prev_frame_num);
-
- if (h->prev_frame_num_offset < 0) {
- h->prev_frame_num_offset += 256;
- }
- }
-
- for(m=0; m<2; m++){
- int i;
- for(i=0; i<4; i++){
- int j;
- for(j=-1; j<4; j++)
- h->ref_cache[m][scan8[0] + 8*i + j]= 1;
- h->ref_cache[m][scan8[0] + 8*i + j]= PART_NOT_AVAILABLE;
- }
- }
-
- for (s->mb_y=0; s->mb_y < s->mb_height; s->mb_y++) {
- for (s->mb_x=0; s->mb_x < s->mb_width; s->mb_x++) {
-
- if ( (get_bits_count(&s->gb) + 7) >= s->gb.size_in_bits &&
- ((get_bits_count(&s->gb) & 7) == 0 || show_bits (&s->gb, (-get_bits_count(&s->gb) & 7)) == 0)) {
-
- skip_bits(&s->gb, h->next_slice_index - get_bits_count(&s->gb));
- s->gb.size_in_bits = 8*buf_size;
-
- if (svq3_decode_slice_header (h))
- return -1;
-
- /* TODO: support s->mb_skip_run */
- }
-
- mb_type = svq3_get_ue_golomb (&s->gb);
-
- if (s->pict_type == I_TYPE) {
- mb_type += 8;
- } else if (s->pict_type == B_TYPE && mb_type >= 4) {
- mb_type += 4;
- }
- if (mb_type > 33 || svq3_decode_mb (h, mb_type)) {
- av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
-
- if (mb_type != 0) {
- hl_decode_mb (h);
- }
-
- if (s->pict_type != B_TYPE && !s->low_delay) {
- s->current_picture.mb_type[s->mb_x + s->mb_y*s->mb_stride] =
- (s->pict_type == P_TYPE && mb_type < 8) ? (mb_type - 1) : -1;
- }
- }
-
- ff_draw_horiz_band(s, 16*s->mb_y, 16);
- }
-
- MPV_frame_end(s);
-
- if (s->pict_type == B_TYPE || s->low_delay) {
- *(AVFrame *) data = *(AVFrame *) &s->current_picture;
- } else {
- *(AVFrame *) data = *(AVFrame *) &s->last_picture;
- }
-
- avctx->frame_number = s->picture_number - 1;
-
- /* dont output the last pic after seeking */
- if (s->last_picture_ptr || s->low_delay) {
- *data_size = sizeof(AVFrame);
- }
-
- return buf_size;
-}
-
-
-AVCodec svq3_decoder = {
- "svq3",
- CODEC_TYPE_VIDEO,
- CODEC_ID_SVQ3,
- sizeof(H264Context),
- decode_init,
- NULL,
- decode_end,
- svq3_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_DELAY,
-};
diff --git a/src/libffmpeg/libavcodec/swscale.h b/src/libffmpeg/libavcodec/swscale.h
deleted file mode 100644
index 06088b8e4..000000000
--- a/src/libffmpeg/libavcodec/swscale.h
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef SWSCALE_H
-#define SWSCALE_H
-
-/**
- * @file swscale.h
- * @brief
- * external api for the swscale stuff
- */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define AV_STRINGIFY(s) AV_TOSTRING(s)
-#define AV_TOSTRING(s) #s
-
-#define LIBSWSCALE_VERSION_INT ((0<<16)+(5<<8)+0)
-#define LIBSWSCALE_VERSION 0.5.0
-#define LIBSWSCALE_BUILD LIBSWSCALE_VERSION_INT
-
-#define LIBSWSCALE_IDENT "SwS" AV_STRINGIFY(LIBSWSCALE_VERSION)
-
-/* values for the flags, the stuff on the command line is different */
-#define SWS_FAST_BILINEAR 1
-#define SWS_BILINEAR 2
-#define SWS_BICUBIC 4
-#define SWS_X 8
-#define SWS_POINT 0x10
-#define SWS_AREA 0x20
-#define SWS_BICUBLIN 0x40
-#define SWS_GAUSS 0x80
-#define SWS_SINC 0x100
-#define SWS_LANCZOS 0x200
-#define SWS_SPLINE 0x400
-
-#define SWS_SRC_V_CHR_DROP_MASK 0x30000
-#define SWS_SRC_V_CHR_DROP_SHIFT 16
-
-#define SWS_PARAM_DEFAULT 123456
-
-#define SWS_PRINT_INFO 0x1000
-
-//the following 3 flags are not completly implemented
-//internal chrominace subsamling info
-#define SWS_FULL_CHR_H_INT 0x2000
-//input subsampling info
-#define SWS_FULL_CHR_H_INP 0x4000
-#define SWS_DIRECT_BGR 0x8000
-#define SWS_ACCURATE_RND 0x40000
-
-#define SWS_CPU_CAPS_MMX 0x80000000
-#define SWS_CPU_CAPS_MMX2 0x20000000
-#define SWS_CPU_CAPS_3DNOW 0x40000000
-#define SWS_CPU_CAPS_ALTIVEC 0x10000000
-
-#define SWS_MAX_REDUCE_CUTOFF 0.002
-
-#define SWS_CS_ITU709 1
-#define SWS_CS_FCC 4
-#define SWS_CS_ITU601 5
-#define SWS_CS_ITU624 5
-#define SWS_CS_SMPTE170M 5
-#define SWS_CS_SMPTE240M 7
-#define SWS_CS_DEFAULT 5
-
-
-
-// when used for filters they must have an odd number of elements
-// coeffs cannot be shared between vectors
-typedef struct {
- double *coeff;
- int length;
-} SwsVector;
-
-// vectors can be shared
-typedef struct {
- SwsVector *lumH;
- SwsVector *lumV;
- SwsVector *chrH;
- SwsVector *chrV;
-} SwsFilter;
-
-struct SwsContext;
-
-void sws_freeContext(struct SwsContext *swsContext);
-
-struct SwsContext *sws_getContext(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags,
- SwsFilter *srcFilter, SwsFilter *dstFilter, double *param);
-int sws_scale(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY,
- int srcSliceH, uint8_t* dst[], int dstStride[]);
-int sws_scale_ordered(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY,
- int srcSliceH, uint8_t* dst[], int dstStride[]);
-
-
-int sws_setColorspaceDetails(struct SwsContext *c, const int inv_table[4], int srcRange, const int table[4], int dstRange, int brightness, int contrast, int saturation);
-int sws_getColorspaceDetails(struct SwsContext *c, int **inv_table, int *srcRange, int **table, int *dstRange, int *brightness, int *contrast, int *saturation);
-SwsVector *sws_getGaussianVec(double variance, double quality);
-SwsVector *sws_getConstVec(double c, int length);
-SwsVector *sws_getIdentityVec(void);
-void sws_scaleVec(SwsVector *a, double scalar);
-void sws_normalizeVec(SwsVector *a, double height);
-void sws_convVec(SwsVector *a, SwsVector *b);
-void sws_addVec(SwsVector *a, SwsVector *b);
-void sws_subVec(SwsVector *a, SwsVector *b);
-void sws_shiftVec(SwsVector *a, int shift);
-SwsVector *sws_cloneVec(SwsVector *a);
-
-void sws_printVec(SwsVector *a);
-void sws_freeVec(SwsVector *a);
-
-SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur,
- float lumaSarpen, float chromaSharpen,
- float chromaHShift, float chromaVShift,
- int verbose);
-void sws_freeFilter(SwsFilter *filter);
-
-struct SwsContext *sws_getCachedContext(struct SwsContext *context,
- int srcW, int srcH, int srcFormat,
- int dstW, int dstH, int dstFormat, int flags,
- SwsFilter *srcFilter, SwsFilter *dstFilter, double *param);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/libffmpeg/libavcodec/truemotion1.c b/src/libffmpeg/libavcodec/truemotion1.c
deleted file mode 100644
index 4b7aa976d..000000000
--- a/src/libffmpeg/libavcodec/truemotion1.c
+++ /dev/null
@@ -1,923 +0,0 @@
-/*
- * Duck TrueMotion 1.0 Decoder
- * Copyright (C) 2003 Alex Beregszaszi & Mike Melanson
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General 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 truemotion1.c
- * Duck TrueMotion v1 Video Decoder by
- * Alex Beregszaszi (alex@fsn.hu) and
- * Mike Melanson (melanson@pcisys.net)
- *
- * The TrueMotion v1 decoder presently only decodes 16-bit TM1 data and
- * outputs RGB555 (or RGB565) data. 24-bit TM1 data is not supported yet.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "common.h"
-#include "avcodec.h"
-#include "dsputil.h"
-
-#include "truemotion1data.h"
-
-typedef struct TrueMotion1Context {
- AVCodecContext *avctx;
- AVFrame frame;
- AVFrame prev_frame;
-
- uint8_t *buf;
- int size;
-
- uint8_t *mb_change_bits;
- int mb_change_bits_row_size;
- uint8_t *index_stream;
- int index_stream_size;
-
- int flags;
- int x, y, w, h;
-
- uint32_t y_predictor_table[1024];
- uint32_t c_predictor_table[1024];
- uint32_t fat_y_predictor_table[1024];
- uint32_t fat_c_predictor_table[1024];
-
- int compression;
- int block_type;
- int block_width;
- int block_height;
-
- int16_t ydt[8];
- int16_t cdt[8];
- int16_t fat_ydt[8];
- int16_t fat_cdt[8];
-
- int last_deltaset, last_vectable;
-
- unsigned int *vert_pred;
-
-} TrueMotion1Context;
-
-#define FLAG_SPRITE 32
-#define FLAG_KEYFRAME 16
-#define FLAG_INTERFRAME 8
-#define FLAG_INTERPOLATED 4
-
-struct frame_header {
- uint8_t header_size;
- uint8_t compression;
- uint8_t deltaset;
- uint8_t vectable;
- uint16_t ysize;
- uint16_t xsize;
- uint16_t checksum;
- uint8_t version;
- uint8_t header_type;
- uint8_t flags;
- uint8_t control;
- uint16_t xoffset;
- uint16_t yoffset;
- uint16_t width;
- uint16_t height;
-};
-
-#define ALGO_NOP 0
-#define ALGO_RGB16V 1
-#define ALGO_RGB16H 2
-#define ALGO_RGB24H 3
-
-/* these are the various block sizes that can occupy a 4x4 block */
-#define BLOCK_2x2 0
-#define BLOCK_2x4 1
-#define BLOCK_4x2 2
-#define BLOCK_4x4 3
-
-typedef struct comp_types {
- int algorithm;
- int block_width; // vres
- int block_height; // hres
- int block_type;
-} comp_types;
-
-/* { valid for metatype }, algorithm, num of deltas, vert res, horiz res */
-static comp_types compression_types[17] = {
- { ALGO_NOP, 0, 0, 0 },
-
- { ALGO_RGB16V, 4, 4, BLOCK_4x4 },
- { ALGO_RGB16H, 4, 4, BLOCK_4x4 },
- { ALGO_RGB16V, 4, 2, BLOCK_4x2 },
- { ALGO_RGB16H, 4, 2, BLOCK_4x2 },
-
- { ALGO_RGB16V, 2, 4, BLOCK_2x4 },
- { ALGO_RGB16H, 2, 4, BLOCK_2x4 },
- { ALGO_RGB16V, 2, 2, BLOCK_2x2 },
- { ALGO_RGB16H, 2, 2, BLOCK_2x2 },
-
- { ALGO_NOP, 4, 4, BLOCK_4x4 },
- { ALGO_RGB24H, 4, 4, BLOCK_4x4 },
- { ALGO_NOP, 4, 2, BLOCK_4x2 },
- { ALGO_RGB24H, 4, 2, BLOCK_4x2 },
-
- { ALGO_NOP, 2, 4, BLOCK_2x4 },
- { ALGO_RGB24H, 2, 4, BLOCK_2x4 },
- { ALGO_NOP, 2, 2, BLOCK_2x2 },
- { ALGO_RGB24H, 2, 2, BLOCK_2x2 }
-};
-
-static void select_delta_tables(TrueMotion1Context *s, int delta_table_index)
-{
- int i;
-
- if (delta_table_index > 3)
- return;
-
- memcpy(s->ydt, ydts[delta_table_index], 8 * sizeof(int16_t));
- memcpy(s->cdt, cdts[delta_table_index], 8 * sizeof(int16_t));
- memcpy(s->fat_ydt, fat_ydts[delta_table_index], 8 * sizeof(int16_t));
- memcpy(s->fat_cdt, fat_cdts[delta_table_index], 8 * sizeof(int16_t));
-
- /* Y skinny deltas need to be halved for some reason; maybe the
- * skinny Y deltas should be modified */
- for (i = 0; i < 8; i++)
- {
- /* drop the lsb before dividing by 2-- net effect: round down
- * when dividing a negative number (e.g., -3/2 = -2, not -1) */
- s->ydt[i] &= 0xFFFE;
- s->ydt[i] /= 2;
- }
-}
-
-#ifdef WORDS_BIGENDIAN
-static int make_ydt15_entry(int p2, int p1, int16_t *ydt)
-#else
-static int make_ydt15_entry(int p1, int p2, int16_t *ydt)
-#endif
-{
- int lo, hi;
-
- lo = ydt[p1];
- lo += (lo << 5) + (lo << 10);
- hi = ydt[p2];
- hi += (hi << 5) + (hi << 10);
- return ((lo + (hi << 16)) << 1);
-}
-
-#ifdef WORDS_BIGENDIAN
-static int make_cdt15_entry(int p2, int p1, int16_t *cdt)
-#else
-static int make_cdt15_entry(int p1, int p2, int16_t *cdt)
-#endif
-{
- int r, b, lo;
-
- b = cdt[p2];
- r = cdt[p1] << 10;
- lo = b + r;
- return ((lo + (lo << 16)) << 1);
-}
-
-#ifdef WORDS_BIGENDIAN
-static int make_ydt16_entry(int p2, int p1, int16_t *ydt)
-#else
-static int make_ydt16_entry(int p1, int p2, int16_t *ydt)
-#endif
-{
- int lo, hi;
-
- lo = ydt[p1];
- lo += (lo << 6) + (lo << 11);
- hi = ydt[p2];
- hi += (hi << 6) + (hi << 11);
- return ((lo + (hi << 16)) << 1);
-}
-
-#ifdef WORDS_BIGENDIAN
-static int make_cdt16_entry(int p2, int p1, int16_t *cdt)
-#else
-static int make_cdt16_entry(int p1, int p2, int16_t *cdt)
-#endif
-{
- int r, b, lo;
-
- b = cdt[p2];
- r = cdt[p1] << 11;
- lo = b + r;
- return ((lo + (lo << 16)) << 1);
-}
-
-#ifdef WORDS_BIGENDIAN
-static int make_ydt24_entry(int p2, int p1, int16_t *ydt)
-#else
-static int make_ydt24_entry(int p1, int p2, int16_t *ydt)
-#endif
-{
- int lo, hi;
-
- lo = ydt[p1];
- hi = ydt[p2];
- return ((lo + (hi << 8) + (hi << 16)) << 1);
-}
-
-#ifdef WORDS_BIGENDIAN
-static int make_cdt24_entry(int p2, int p1, int16_t *cdt)
-#else
-static int make_cdt24_entry(int p1, int p2, int16_t *cdt)
-#endif
-{
- int r, b;
-
- b = cdt[p2];
- r = cdt[p1]<<16;
- return ((b+r) << 1);
-}
-
-static void gen_vector_table15(TrueMotion1Context *s, const uint8_t *sel_vector_table)
-{
- int len, i, j;
- unsigned char delta_pair;
-
- for (i = 0; i < 1024; i += 4)
- {
- len = *sel_vector_table++ / 2;
- for (j = 0; j < len; j++)
- {
- delta_pair = *sel_vector_table++;
- s->y_predictor_table[i+j] = 0xfffffffe &
- make_ydt15_entry(delta_pair >> 4, delta_pair & 0xf, s->ydt);
- s->c_predictor_table[i+j] = 0xfffffffe &
- make_cdt15_entry(delta_pair >> 4, delta_pair & 0xf, s->cdt);
- }
- s->y_predictor_table[i+(j-1)] |= 1;
- s->c_predictor_table[i+(j-1)] |= 1;
- }
-}
-
-static void gen_vector_table16(TrueMotion1Context *s, const uint8_t *sel_vector_table)
-{
- int len, i, j;
- unsigned char delta_pair;
-
- for (i = 0; i < 1024; i += 4)
- {
- len = *sel_vector_table++ / 2;
- for (j = 0; j < len; j++)
- {
- delta_pair = *sel_vector_table++;
- s->y_predictor_table[i+j] = 0xfffffffe &
- make_ydt16_entry(delta_pair >> 4, delta_pair & 0xf, s->ydt);
- s->c_predictor_table[i+j] = 0xfffffffe &
- make_cdt16_entry(delta_pair >> 4, delta_pair & 0xf, s->cdt);
- }
- s->y_predictor_table[i+(j-1)] |= 1;
- s->c_predictor_table[i+(j-1)] |= 1;
- }
-}
-
-static void gen_vector_table24(TrueMotion1Context *s, const uint8_t *sel_vector_table)
-{
- int len, i, j;
- unsigned char delta_pair;
-
- for (i = 0; i < 1024; i += 4)
- {
- len = *sel_vector_table++ / 2;
- for (j = 0; j < len; j++)
- {
- delta_pair = *sel_vector_table++;
- s->y_predictor_table[i+j] = 0xfffffffe &
- make_ydt24_entry(delta_pair >> 4, delta_pair & 0xf, s->ydt);
- s->c_predictor_table[i+j] = 0xfffffffe &
- make_cdt24_entry(delta_pair >> 4, delta_pair & 0xf, s->cdt);
- s->fat_y_predictor_table[i+j] = 0xfffffffe &
- make_ydt24_entry(delta_pair >> 4, delta_pair & 0xf, s->fat_ydt);
- s->fat_c_predictor_table[i+j] = 0xfffffffe &
- make_cdt24_entry(delta_pair >> 4, delta_pair & 0xf, s->fat_cdt);
- }
- s->y_predictor_table[i+(j-1)] |= 1;
- s->c_predictor_table[i+(j-1)] |= 1;
- s->fat_y_predictor_table[i+(j-1)] |= 1;
- s->fat_c_predictor_table[i+(j-1)] |= 1;
- }
-}
-
-/* Returns the number of bytes consumed from the bytestream. Returns -1 if
- * there was an error while decoding the header */
-static int truemotion1_decode_header(TrueMotion1Context *s)
-{
- int i;
- struct frame_header header;
- uint8_t header_buffer[128]; /* logical maximum size of the header */
- const uint8_t *sel_vector_table;
-
- /* There is 1 change bit per 4 pixels, so each change byte represents
- * 32 pixels; divide width by 4 to obtain the number of change bits and
- * then round up to the nearest byte. */
- s->mb_change_bits_row_size = ((s->avctx->width >> 2) + 7) >> 3;
-
- header.header_size = ((s->buf[0] >> 5) | (s->buf[0] << 3)) & 0x7f;
- if (s->buf[0] < 0x10)
- {
- av_log(s->avctx, AV_LOG_ERROR, "invalid header size (%d)\n", s->buf[0]);
- return -1;
- }
-
- /* unscramble the header bytes with a XOR operation */
- memset(header_buffer, 0, 128);
- for (i = 1; i < header.header_size; i++)
- header_buffer[i - 1] = s->buf[i] ^ s->buf[i + 1];
-
- header.compression = header_buffer[0];
- header.deltaset = header_buffer[1];
- header.vectable = header_buffer[2];
- header.ysize = AV_RL16(&header_buffer[3]);
- header.xsize = AV_RL16(&header_buffer[5]);
- header.checksum = AV_RL16(&header_buffer[7]);
- header.version = header_buffer[9];
- header.header_type = header_buffer[10];
- header.flags = header_buffer[11];
- header.control = header_buffer[12];
-
- /* Version 2 */
- if (header.version >= 2)
- {
- if (header.header_type > 3)
- {
- av_log(s->avctx, AV_LOG_ERROR, "invalid header type (%d)\n", header.header_type);
- return -1;
- } else if ((header.header_type == 2) || (header.header_type == 3)) {
- s->flags = header.flags;
- if (!(s->flags & FLAG_INTERFRAME))
- s->flags |= FLAG_KEYFRAME;
- } else
- s->flags = FLAG_KEYFRAME;
- } else /* Version 1 */
- s->flags = FLAG_KEYFRAME;
-
- if (s->flags & FLAG_SPRITE) {
- av_log(s->avctx, AV_LOG_INFO, "SPRITE frame found, please report the sample to the developers\n");
- s->w = header.width;
- s->h = header.height;
- s->x = header.xoffset;
- s->y = header.yoffset;
- } else {
- s->w = header.xsize;
- s->h = header.ysize;
- if (header.header_type < 2) {
- if ((s->w < 213) && (s->h >= 176))
- {
- s->flags |= FLAG_INTERPOLATED;
- av_log(s->avctx, AV_LOG_INFO, "INTERPOLATION selected, please report the sample to the developers\n");
- }
- }
- }
-
- if (header.compression > 17) {
- av_log(s->avctx, AV_LOG_ERROR, "invalid compression type (%d)\n", header.compression);
- return -1;
- }
-
- if ((header.deltaset != s->last_deltaset) ||
- (header.vectable != s->last_vectable))
- select_delta_tables(s, header.deltaset);
-
- if ((header.compression & 1) && header.header_type)
- sel_vector_table = pc_tbl2;
- else {
- if (header.vectable < 4)
- sel_vector_table = tables[header.vectable - 1];
- else {
- av_log(s->avctx, AV_LOG_ERROR, "invalid vector table id (%d)\n", header.vectable);
- return -1;
- }
- }
-
- // FIXME: where to place this ?!?!
- if (compression_types[header.compression].algorithm == ALGO_RGB24H)
- s->avctx->pix_fmt = PIX_FMT_RGBA32;
- else
- s->avctx->pix_fmt = PIX_FMT_RGB555; // RGB565 is supported aswell
-
- if ((header.deltaset != s->last_deltaset) || (header.vectable != s->last_vectable))
- {
- if (compression_types[header.compression].algorithm == ALGO_RGB24H)
- gen_vector_table24(s, sel_vector_table);
- else
- if (s->avctx->pix_fmt == PIX_FMT_RGB555)
- gen_vector_table15(s, sel_vector_table);
- else
- gen_vector_table16(s, sel_vector_table);
- }
-
- /* set up pointers to the other key data chunks */
- s->mb_change_bits = s->buf + header.header_size;
- if (s->flags & FLAG_KEYFRAME) {
- /* no change bits specified for a keyframe; only index bytes */
- s->index_stream = s->mb_change_bits;
- } else {
- /* one change bit per 4x4 block */
- s->index_stream = s->mb_change_bits +
- (s->mb_change_bits_row_size * (s->avctx->height >> 2));
- }
- s->index_stream_size = s->size - (s->index_stream - s->buf);
-
- s->last_deltaset = header.deltaset;
- s->last_vectable = header.vectable;
- s->compression = header.compression;
- s->block_width = compression_types[header.compression].block_width;
- s->block_height = compression_types[header.compression].block_height;
- s->block_type = compression_types[header.compression].block_type;
-
- if (s->avctx->debug & FF_DEBUG_PICT_INFO)
- av_log(s->avctx, AV_LOG_INFO, "tables: %d / %d c:%d %dx%d t:%d %s%s%s%s\n",
- s->last_deltaset, s->last_vectable, s->compression, s->block_width,
- s->block_height, s->block_type,
- s->flags & FLAG_KEYFRAME ? " KEY" : "",
- s->flags & FLAG_INTERFRAME ? " INTER" : "",
- s->flags & FLAG_SPRITE ? " SPRITE" : "",
- s->flags & FLAG_INTERPOLATED ? " INTERPOL" : "");
-
- return header.header_size;
-}
-
-static int truemotion1_decode_init(AVCodecContext *avctx)
-{
- TrueMotion1Context *s = (TrueMotion1Context *)avctx->priv_data;
-
- s->avctx = avctx;
-
- // FIXME: it may change ?
-// if (avctx->bits_per_sample == 24)
-// avctx->pix_fmt = PIX_FMT_RGB24;
-// else
-// avctx->pix_fmt = PIX_FMT_RGB555;
-
- avctx->has_b_frames = 0;
- s->frame.data[0] = s->prev_frame.data[0] = NULL;
-
- /* there is a vertical predictor for each pixel in a line; each vertical
- * predictor is 0 to start with */
- s->vert_pred =
- (unsigned int *)av_malloc(s->avctx->width * sizeof(unsigned int));
-
- return 0;
-}
-
-/*
-Block decoding order:
-
-dxi: Y-Y
-dxic: Y-C-Y
-dxic2: Y-C-Y-C
-
-hres,vres,i,i%vres (0 < i < 4)
-2x2 0: 0 dxic2
-2x2 1: 1 dxi
-2x2 2: 0 dxic2
-2x2 3: 1 dxi
-2x4 0: 0 dxic2
-2x4 1: 1 dxi
-2x4 2: 2 dxi
-2x4 3: 3 dxi
-4x2 0: 0 dxic
-4x2 1: 1 dxi
-4x2 2: 0 dxic
-4x2 3: 1 dxi
-4x4 0: 0 dxic
-4x4 1: 1 dxi
-4x4 2: 2 dxi
-4x4 3: 3 dxi
-*/
-
-#define GET_NEXT_INDEX() \
-{\
- if (index_stream_index >= s->index_stream_size) { \
- av_log(s->avctx, AV_LOG_INFO, " help! truemotion1 decoder went out of bounds\n"); \
- return; \
- } \
- index = s->index_stream[index_stream_index++] * 4; \
-}
-
-#define APPLY_C_PREDICTOR() \
- predictor_pair = s->c_predictor_table[index]; \
- horiz_pred += (predictor_pair >> 1); \
- if (predictor_pair & 1) { \
- GET_NEXT_INDEX() \
- if (!index) { \
- GET_NEXT_INDEX() \
- predictor_pair = s->c_predictor_table[index]; \
- horiz_pred += ((predictor_pair >> 1) * 5); \
- if (predictor_pair & 1) \
- GET_NEXT_INDEX() \
- else \
- index++; \
- } \
- } else \
- index++;
-
-#define APPLY_C_PREDICTOR_24() \
- predictor_pair = s->c_predictor_table[index]; \
- horiz_pred += (predictor_pair >> 1); \
- if (predictor_pair & 1) { \
- GET_NEXT_INDEX() \
- if (!index) { \
- GET_NEXT_INDEX() \
- predictor_pair = s->fat_c_predictor_table[index]; \
- horiz_pred += (predictor_pair >> 1); \
- if (predictor_pair & 1) \
- GET_NEXT_INDEX() \
- else \
- index++; \
- } \
- } else \
- index++;
-
-
-#define APPLY_Y_PREDICTOR() \
- predictor_pair = s->y_predictor_table[index]; \
- horiz_pred += (predictor_pair >> 1); \
- if (predictor_pair & 1) { \
- GET_NEXT_INDEX() \
- if (!index) { \
- GET_NEXT_INDEX() \
- predictor_pair = s->y_predictor_table[index]; \
- horiz_pred += ((predictor_pair >> 1) * 5); \
- if (predictor_pair & 1) \
- GET_NEXT_INDEX() \
- else \
- index++; \
- } \
- } else \
- index++;
-
-#define APPLY_Y_PREDICTOR_24() \
- predictor_pair = s->y_predictor_table[index]; \
- horiz_pred += (predictor_pair >> 1); \
- if (predictor_pair & 1) { \
- GET_NEXT_INDEX() \
- if (!index) { \
- GET_NEXT_INDEX() \
- predictor_pair = s->fat_y_predictor_table[index]; \
- horiz_pred += (predictor_pair >> 1); \
- if (predictor_pair & 1) \
- GET_NEXT_INDEX() \
- else \
- index++; \
- } \
- } else \
- index++;
-
-#define OUTPUT_PIXEL_PAIR() \
- *current_pixel_pair = *vert_pred + horiz_pred; \
- *vert_pred++ = *current_pixel_pair++; \
- prev_pixel_pair++;
-
-static void truemotion1_decode_16bit(TrueMotion1Context *s)
-{
- int y;
- int pixels_left; /* remaining pixels on this line */
- unsigned int predictor_pair;
- unsigned int horiz_pred;
- unsigned int *vert_pred;
- unsigned int *current_pixel_pair;
- unsigned int *prev_pixel_pair;
- unsigned char *current_line = s->frame.data[0];
- unsigned char *prev_line = s->prev_frame.data[0];
- int keyframe = s->flags & FLAG_KEYFRAME;
-
- /* these variables are for managing the stream of macroblock change bits */
- unsigned char *mb_change_bits = s->mb_change_bits;
- unsigned char mb_change_byte;
- unsigned char mb_change_byte_mask;
- int mb_change_index;
-
- /* these variables are for managing the main index stream */
- int index_stream_index = 0; /* yes, the index into the index stream */
- int index;
-
- /* clean out the line buffer */
- memset(s->vert_pred, 0, s->avctx->width * sizeof(unsigned int));
-
- GET_NEXT_INDEX();
-
- for (y = 0; y < s->avctx->height; y++) {
-
- /* re-init variables for the next line iteration */
- horiz_pred = 0;
- current_pixel_pair = (unsigned int *)current_line;
- prev_pixel_pair = (unsigned int *)prev_line;
- vert_pred = s->vert_pred;
- mb_change_index = 0;
- mb_change_byte = mb_change_bits[mb_change_index++];
- mb_change_byte_mask = 0x01;
- pixels_left = s->avctx->width;
-
- while (pixels_left > 0) {
-
- if (keyframe || ((mb_change_byte & mb_change_byte_mask) == 0)) {
-
- switch (y & 3) {
- case 0:
- /* if macroblock width is 2, apply C-Y-C-Y; else
- * apply C-Y-Y */
- if (s->block_width == 2) {
- APPLY_C_PREDICTOR();
- APPLY_Y_PREDICTOR();
- OUTPUT_PIXEL_PAIR();
- APPLY_C_PREDICTOR();
- APPLY_Y_PREDICTOR();
- OUTPUT_PIXEL_PAIR();
- } else {
- APPLY_C_PREDICTOR();
- APPLY_Y_PREDICTOR();
- OUTPUT_PIXEL_PAIR();
- APPLY_Y_PREDICTOR();
- OUTPUT_PIXEL_PAIR();
- }
- break;
-
- case 1:
- case 3:
- /* always apply 2 Y predictors on these iterations */
- APPLY_Y_PREDICTOR();
- OUTPUT_PIXEL_PAIR();
- APPLY_Y_PREDICTOR();
- OUTPUT_PIXEL_PAIR();
- break;
-
- case 2:
- /* this iteration might be C-Y-C-Y, Y-Y, or C-Y-Y
- * depending on the macroblock type */
- if (s->block_type == BLOCK_2x2) {
- APPLY_C_PREDICTOR();
- APPLY_Y_PREDICTOR();
- OUTPUT_PIXEL_PAIR();
- APPLY_C_PREDICTOR();
- APPLY_Y_PREDICTOR();
- OUTPUT_PIXEL_PAIR();
- } else if (s->block_type == BLOCK_4x2) {
- APPLY_C_PREDICTOR();
- APPLY_Y_PREDICTOR();
- OUTPUT_PIXEL_PAIR();
- APPLY_Y_PREDICTOR();
- OUTPUT_PIXEL_PAIR();
- } else {
- APPLY_Y_PREDICTOR();
- OUTPUT_PIXEL_PAIR();
- APPLY_Y_PREDICTOR();
- OUTPUT_PIXEL_PAIR();
- }
- break;
- }
-
- } else {
-
- /* skip (copy) four pixels, but reassign the horizontal
- * predictor */
- *current_pixel_pair = *prev_pixel_pair++;
- *vert_pred++ = *current_pixel_pair++;
- *current_pixel_pair = *prev_pixel_pair++;
- horiz_pred = *current_pixel_pair - *vert_pred;
- *vert_pred++ = *current_pixel_pair++;
-
- }
-
- if (!keyframe) {
- mb_change_byte_mask <<= 1;
-
- /* next byte */
- if (!mb_change_byte_mask) {
- mb_change_byte = mb_change_bits[mb_change_index++];
- mb_change_byte_mask = 0x01;
- }
- }
-
- pixels_left -= 4;
- }
-
- /* next change row */
- if (((y + 1) & 3) == 0)
- mb_change_bits += s->mb_change_bits_row_size;
-
- current_line += s->frame.linesize[0];
- prev_line += s->prev_frame.linesize[0];
- }
-}
-
-static void truemotion1_decode_24bit(TrueMotion1Context *s)
-{
- int y;
- int pixels_left; /* remaining pixels on this line */
- unsigned int predictor_pair;
- unsigned int horiz_pred;
- unsigned int *vert_pred;
- unsigned int *current_pixel_pair;
- unsigned int *prev_pixel_pair;
- unsigned char *current_line = s->frame.data[0];
- unsigned char *prev_line = s->prev_frame.data[0];
- int keyframe = s->flags & FLAG_KEYFRAME;
-
- /* these variables are for managing the stream of macroblock change bits */
- unsigned char *mb_change_bits = s->mb_change_bits;
- unsigned char mb_change_byte;
- unsigned char mb_change_byte_mask;
- int mb_change_index;
-
- /* these variables are for managing the main index stream */
- int index_stream_index = 0; /* yes, the index into the index stream */
- int index;
-
- /* clean out the line buffer */
- memset(s->vert_pred, 0, s->avctx->width * sizeof(unsigned int));
-
- GET_NEXT_INDEX();
-
- for (y = 0; y < s->avctx->height; y++) {
-
- /* re-init variables for the next line iteration */
- horiz_pred = 0;
- current_pixel_pair = (unsigned int *)current_line;
- prev_pixel_pair = (unsigned int *)prev_line;
- vert_pred = s->vert_pred;
- mb_change_index = 0;
- mb_change_byte = mb_change_bits[mb_change_index++];
- mb_change_byte_mask = 0x01;
- pixels_left = s->avctx->width;
-
- while (pixels_left > 0) {
-
- if (keyframe || ((mb_change_byte & mb_change_byte_mask) == 0)) {
-
- switch (y & 3) {
- case 0:
- /* if macroblock width is 2, apply C-Y-C-Y; else
- * apply C-Y-Y */
- if (s->block_width == 2) {
- APPLY_C_PREDICTOR_24();
- APPLY_Y_PREDICTOR_24();
- OUTPUT_PIXEL_PAIR();
- APPLY_C_PREDICTOR_24();
- APPLY_Y_PREDICTOR_24();
- OUTPUT_PIXEL_PAIR();
- } else {
- APPLY_C_PREDICTOR_24();
- APPLY_Y_PREDICTOR_24();
- OUTPUT_PIXEL_PAIR();
- APPLY_Y_PREDICTOR_24();
- OUTPUT_PIXEL_PAIR();
- }
- break;
-
- case 1:
- case 3:
- /* always apply 2 Y predictors on these iterations */
- APPLY_Y_PREDICTOR_24();
- OUTPUT_PIXEL_PAIR();
- APPLY_Y_PREDICTOR_24();
- OUTPUT_PIXEL_PAIR();
- break;
-
- case 2:
- /* this iteration might be C-Y-C-Y, Y-Y, or C-Y-Y
- * depending on the macroblock type */
- if (s->block_type == BLOCK_2x2) {
- APPLY_C_PREDICTOR_24();
- APPLY_Y_PREDICTOR_24();
- OUTPUT_PIXEL_PAIR();
- APPLY_C_PREDICTOR_24();
- APPLY_Y_PREDICTOR_24();
- OUTPUT_PIXEL_PAIR();
- } else if (s->block_type == BLOCK_4x2) {
- APPLY_C_PREDICTOR_24();
- APPLY_Y_PREDICTOR_24();
- OUTPUT_PIXEL_PAIR();
- APPLY_Y_PREDICTOR_24();
- OUTPUT_PIXEL_PAIR();
- } else {
- APPLY_Y_PREDICTOR_24();
- OUTPUT_PIXEL_PAIR();
- APPLY_Y_PREDICTOR_24();
- OUTPUT_PIXEL_PAIR();
- }
- break;
- }
-
- } else {
-
- /* skip (copy) four pixels, but reassign the horizontal
- * predictor */
- *current_pixel_pair = *prev_pixel_pair++;
- *vert_pred++ = *current_pixel_pair++;
- *current_pixel_pair = *prev_pixel_pair++;
- horiz_pred = *current_pixel_pair - *vert_pred;
- *vert_pred++ = *current_pixel_pair++;
-
- }
-
- if (!keyframe) {
- mb_change_byte_mask <<= 1;
-
- /* next byte */
- if (!mb_change_byte_mask) {
- mb_change_byte = mb_change_bits[mb_change_index++];
- mb_change_byte_mask = 0x01;
- }
- }
-
- pixels_left -= 4;
- }
-
- /* next change row */
- if (((y + 1) & 3) == 0)
- mb_change_bits += s->mb_change_bits_row_size;
-
- current_line += s->frame.linesize[0];
- prev_line += s->prev_frame.linesize[0];
- }
-}
-
-
-static int truemotion1_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- TrueMotion1Context *s = (TrueMotion1Context *)avctx->priv_data;
-
- s->buf = buf;
- s->size = buf_size;
-
- if (truemotion1_decode_header(s) == -1)
- return -1;
-
- s->frame.reference = 1;
- if (avctx->get_buffer(avctx, &s->frame) < 0) {
- av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
- return -1;
- }
-
- /* check for a do-nothing frame and copy the previous frame */
- if (compression_types[s->compression].algorithm == ALGO_NOP)
- {
- memcpy(s->frame.data[0], s->prev_frame.data[0],
- s->frame.linesize[0] * s->avctx->height);
- } else if (compression_types[s->compression].algorithm == ALGO_RGB24H) {
- truemotion1_decode_24bit(s);
- } else {
- truemotion1_decode_16bit(s);
- }
-
- if (s->prev_frame.data[0])
- avctx->release_buffer(avctx, &s->prev_frame);
-
- /* shuffle frames */
- s->prev_frame = s->frame;
-
- *data_size = sizeof(AVFrame);
- *(AVFrame*)data = s->frame;
-
- /* report that the buffer was completely consumed */
- return buf_size;
-}
-
-static int truemotion1_decode_end(AVCodecContext *avctx)
-{
- TrueMotion1Context *s = (TrueMotion1Context *)avctx->priv_data;
-
- /* release the last frame */
- if (s->prev_frame.data[0])
- avctx->release_buffer(avctx, &s->prev_frame);
-
- av_free(s->vert_pred);
-
- return 0;
-}
-
-AVCodec truemotion1_decoder = {
- "truemotion1",
- CODEC_TYPE_VIDEO,
- CODEC_ID_TRUEMOTION1,
- sizeof(TrueMotion1Context),
- truemotion1_decode_init,
- NULL,
- truemotion1_decode_end,
- truemotion1_decode_frame,
- CODEC_CAP_DR1,
-};
diff --git a/src/libffmpeg/libavcodec/truemotion2.c b/src/libffmpeg/libavcodec/truemotion2.c
deleted file mode 100644
index e9bc6b7cb..000000000
--- a/src/libffmpeg/libavcodec/truemotion2.c
+++ /dev/null
@@ -1,893 +0,0 @@
-/*
- * Duck/ON2 TrueMotion 2 Decoder
- * Copyright (c) 2005 Konstantin Shishkov
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-/**
- * @file truemotion2.c
- * Duck TrueMotion2 decoder.
- */
-
-#include "avcodec.h"
-#include "common.h"
-#include "bitstream.h"
-#include "dsputil.h"
-
-#define TM2_ESCAPE 0x80000000
-#define TM2_DELTAS 64
-/* Huffman-coded streams of different types of blocks */
-enum TM2_STREAMS{ TM2_C_HI = 0, TM2_C_LO, TM2_L_HI, TM2_L_LO,
- TM2_UPD, TM2_MOT, TM2_TYPE, TM2_NUM_STREAMS};
-/* Block types */
-enum TM2_BLOCKS{ TM2_HI_RES = 0, TM2_MED_RES, TM2_LOW_RES, TM2_NULL_RES,
- TM2_UPDATE, TM2_STILL, TM2_MOTION};
-
-typedef struct TM2Context{
- AVCodecContext *avctx;
- AVFrame pic;
-
- GetBitContext gb;
- DSPContext dsp;
-
- /* TM2 streams */
- int *tokens[TM2_NUM_STREAMS];
- int tok_lens[TM2_NUM_STREAMS];
- int tok_ptrs[TM2_NUM_STREAMS];
- int deltas[TM2_NUM_STREAMS][TM2_DELTAS];
- /* for blocks decoding */
- int D[4];
- int CD[4];
- int *last;
- int *clast;
-
- /* data for current and previous frame */
- int *Y1, *U1, *V1, *Y2, *U2, *V2;
- int cur;
-} TM2Context;
-
-/**
-* Huffman codes for each of streams
-*/
-typedef struct TM2Codes{
- VLC vlc; ///< table for FFmpeg bitstream reader
- int bits;
- int *recode; ///< table for converting from code indexes to values
- int length;
-} TM2Codes;
-
-/**
-* structure for gathering Huffman codes information
-*/
-typedef struct TM2Huff{
- int val_bits; ///< length of literal
- int max_bits; ///< maximum length of code
- int min_bits; ///< minimum length of code
- int nodes; ///< total number of nodes in tree
- int num; ///< current number filled
- int max_num; ///< total number of codes
- int *nums; ///< literals
- uint32_t *bits; ///< codes
- int *lens; ///< codelengths
-} TM2Huff;
-
-static int tm2_read_tree(TM2Context *ctx, uint32_t prefix, int length, TM2Huff *huff)
-{
- if(length > huff->max_bits) {
- av_log(ctx->avctx, AV_LOG_ERROR, "Tree exceeded its given depth (%i)\n", huff->max_bits);
- return -1;
- }
-
- if(!get_bits1(&ctx->gb)) { /* literal */
- if (length == 0) {
- length = 1;
- }
- if(huff->num >= huff->max_num) {
- av_log(ctx->avctx, AV_LOG_DEBUG, "Too many literals\n");
- return -1;
- }
- huff->nums[huff->num] = get_bits_long(&ctx->gb, huff->val_bits);
- huff->bits[huff->num] = prefix;
- huff->lens[huff->num] = length;
- huff->num++;
- return 0;
- } else { /* non-terminal node */
- if(tm2_read_tree(ctx, prefix << 1, length + 1, huff) == -1)
- return -1;
- if(tm2_read_tree(ctx, (prefix << 1) | 1, length + 1, huff) == -1)
- return -1;
- }
- return 0;
-}
-
-static int tm2_build_huff_table(TM2Context *ctx, TM2Codes *code)
-{
- TM2Huff huff;
- int res = 0;
-
- huff.val_bits = get_bits(&ctx->gb, 5);
- huff.max_bits = get_bits(&ctx->gb, 5);
- huff.min_bits = get_bits(&ctx->gb, 5);
- huff.nodes = get_bits_long(&ctx->gb, 17);
- huff.num = 0;
-
- /* check for correct codes parameters */
- if((huff.val_bits < 1) || (huff.val_bits > 32) ||
- (huff.max_bits < 0) || (huff.max_bits > 32)) {
- av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect tree parameters - literal length: %i, max code length: %i\n",
- huff.val_bits, huff.max_bits);
- return -1;
- }
- if((huff.nodes < 0) || (huff.nodes > 0x10000)) {
- av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect number of Huffman tree nodes: %i\n", huff.nodes);
- return -1;
- }
- /* one-node tree */
- if(huff.max_bits == 0)
- huff.max_bits = 1;
-
- /* allocate space for codes - it is exactly ceil(nodes / 2) entries */
- huff.max_num = (huff.nodes + 1) >> 1;
- huff.nums = av_mallocz(huff.max_num * sizeof(int));
- huff.bits = av_mallocz(huff.max_num * sizeof(uint32_t));
- huff.lens = av_mallocz(huff.max_num * sizeof(int));
-
- if(tm2_read_tree(ctx, 0, 0, &huff) == -1)
- res = -1;
-
- if(huff.num != huff.max_num) {
- av_log(ctx->avctx, AV_LOG_ERROR, "Got less codes than expected: %i of %i\n",
- huff.num, huff.max_num);
- res = -1;
- }
-
- /* convert codes to vlc_table */
- if(res != -1) {
- int i;
-
- res = init_vlc(&code->vlc, huff.max_bits, huff.max_num,
- huff.lens, sizeof(int), sizeof(int),
- huff.bits, sizeof(uint32_t), sizeof(uint32_t), 0);
- if(res < 0) {
- av_log(ctx->avctx, AV_LOG_ERROR, "Cannot build VLC table\n");
- res = -1;
- } else
- res = 0;
- if(res != -1) {
- code->bits = huff.max_bits;
- code->length = huff.max_num;
- code->recode = av_malloc(code->length * sizeof(int));
- for(i = 0; i < code->length; i++)
- code->recode[i] = huff.nums[i];
- }
- }
- /* free allocated memory */
- av_free(huff.nums);
- av_free(huff.bits);
- av_free(huff.lens);
-
- return res;
-}
-
-static void tm2_free_codes(TM2Codes *code)
-{
- if(code->recode)
- av_free(code->recode);
- if(code->vlc.table)
- free_vlc(&code->vlc);
-}
-
-static inline int tm2_get_token(GetBitContext *gb, TM2Codes *code)
-{
- int val;
- val = get_vlc2(gb, code->vlc.table, code->bits, 1);
- return code->recode[val];
-}
-
-static inline int tm2_read_header(TM2Context *ctx, uint8_t *buf)
-{
- uint32_t magic;
- uint8_t *obuf;
- int length;
-
- obuf = buf;
-
- magic = AV_RL32(buf);
- buf += 4;
-
- if(magic == 0x00000100) { /* old header */
-/* av_log (ctx->avctx, AV_LOG_ERROR, "TM2 old header: not implemented (yet)\n"); */
- return 40;
- } else if(magic == 0x00000101) { /* new header */
- int w, h, size, flags, xr, yr;
-
- length = AV_RL32(buf);
- buf += 4;
-
- init_get_bits(&ctx->gb, buf, 32 * 8);
- size = get_bits_long(&ctx->gb, 31);
- h = get_bits(&ctx->gb, 15);
- w = get_bits(&ctx->gb, 15);
- flags = get_bits_long(&ctx->gb, 31);
- yr = get_bits(&ctx->gb, 9);
- xr = get_bits(&ctx->gb, 9);
-
- return 40;
- } else {
- av_log (ctx->avctx, AV_LOG_ERROR, "Not a TM2 header: 0x%08X\n", magic);
- return -1;
- }
-
- return (buf - obuf);
-}
-
-static int tm2_read_deltas(TM2Context *ctx, int stream_id) {
- int d, mb;
- int i, v;
-
- d = get_bits(&ctx->gb, 9);
- mb = get_bits(&ctx->gb, 5);
-
- if((d < 1) || (d > TM2_DELTAS) || (mb < 1) || (mb > 32)) {
- av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect delta table: %i deltas x %i bits\n", d, mb);
- return -1;
- }
-
- for(i = 0; i < d; i++) {
- v = get_bits_long(&ctx->gb, mb);
- if(v & (1 << (mb - 1)))
- ctx->deltas[stream_id][i] = v - (1 << mb);
- else
- ctx->deltas[stream_id][i] = v;
- }
- for(; i < TM2_DELTAS; i++)
- ctx->deltas[stream_id][i] = 0;
-
- return 0;
-}
-
-static int tm2_read_stream(TM2Context *ctx, uint8_t *buf, int stream_id) {
- int i;
- int cur = 0;
- int skip = 0;
- int len, toks;
- TM2Codes codes;
-
- /* get stream length in dwords */
- len = AV_RB32(buf); buf += 4; cur += 4;
- skip = len * 4 + 4;
-
- if(len == 0)
- return 4;
-
- toks = AV_RB32(buf); buf += 4; cur += 4;
- if(toks & 1) {
- len = AV_RB32(buf); buf += 4; cur += 4;
- if(len == TM2_ESCAPE) {
- len = AV_RB32(buf); buf += 4; cur += 4;
- }
- if(len > 0) {
- init_get_bits(&ctx->gb, buf, (skip - cur) * 8);
- if(tm2_read_deltas(ctx, stream_id) == -1)
- return -1;
- buf += ((get_bits_count(&ctx->gb) + 31) >> 5) << 2;
- cur += ((get_bits_count(&ctx->gb) + 31) >> 5) << 2;
- }
- }
- /* skip unused fields */
- if(AV_RB32(buf) == TM2_ESCAPE) {
- buf += 4; cur += 4; /* some unknown length - could be escaped too */
- }
- buf += 4; cur += 4;
- buf += 4; cur += 4; /* unused by decoder */
-
- init_get_bits(&ctx->gb, buf, (skip - cur) * 8);
- if(tm2_build_huff_table(ctx, &codes) == -1)
- return -1;
- buf += ((get_bits_count(&ctx->gb) + 31) >> 5) << 2;
- cur += ((get_bits_count(&ctx->gb) + 31) >> 5) << 2;
-
- toks >>= 1;
- /* check if we have sane number of tokens */
- if((toks < 0) || (toks > 0xFFFFFF)){
- av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect number of tokens: %i\n", toks);
- tm2_free_codes(&codes);
- return -1;
- }
- ctx->tokens[stream_id] = av_realloc(ctx->tokens[stream_id], toks * sizeof(int));
- ctx->tok_lens[stream_id] = toks;
- len = AV_RB32(buf); buf += 4; cur += 4;
- if(len > 0) {
- init_get_bits(&ctx->gb, buf, (skip - cur) * 8);
- for(i = 0; i < toks; i++)
- ctx->tokens[stream_id][i] = tm2_get_token(&ctx->gb, &codes);
- } else {
- for(i = 0; i < toks; i++)
- ctx->tokens[stream_id][i] = codes.recode[0];
- }
- tm2_free_codes(&codes);
-
- return skip;
-}
-
-static inline int GET_TOK(TM2Context *ctx,int type) {
- if(ctx->tok_ptrs[type] >= ctx->tok_lens[type]) {
- av_log(ctx->avctx, AV_LOG_ERROR, "Read token from stream %i out of bounds (%i>=%i)\n", type, ctx->tok_ptrs[type], ctx->tok_lens[type]);
- return 0;
- }
- if(type <= TM2_MOT)
- return ctx->deltas[type][ctx->tokens[type][ctx->tok_ptrs[type]++]];
- return ctx->tokens[type][ctx->tok_ptrs[type]++];
-}
-
-/* blocks decoding routines */
-
-/* common Y, U, V pointers initialisation */
-#define TM2_INIT_POINTERS() \
- int *last, *clast; \
- int *Y, *U, *V;\
- int Ystride, Ustride, Vstride;\
-\
- Ystride = ctx->avctx->width;\
- Vstride = (ctx->avctx->width + 1) >> 1;\
- Ustride = (ctx->avctx->width + 1) >> 1;\
- Y = (ctx->cur?ctx->Y2:ctx->Y1) + by * 4 * Ystride + bx * 4;\
- V = (ctx->cur?ctx->V2:ctx->V1) + by * 2 * Vstride + bx * 2;\
- U = (ctx->cur?ctx->U2:ctx->U1) + by * 2 * Ustride + bx * 2;\
- last = ctx->last + bx * 4;\
- clast = ctx->clast + bx * 4;
-
-#define TM2_INIT_POINTERS_2() \
- int *Yo, *Uo, *Vo;\
- int oYstride, oUstride, oVstride;\
-\
- TM2_INIT_POINTERS();\
- oYstride = Ystride;\
- oVstride = Vstride;\
- oUstride = Ustride;\
- Yo = (ctx->cur?ctx->Y1:ctx->Y2) + by * 4 * oYstride + bx * 4;\
- Vo = (ctx->cur?ctx->V1:ctx->V2) + by * 2 * oVstride + bx * 2;\
- Uo = (ctx->cur?ctx->U1:ctx->U2) + by * 2 * oUstride + bx * 2;
-
-/* recalculate last and delta values for next blocks */
-#define TM2_RECALC_BLOCK(CHR, stride, last, CD) {\
- CD[0] = (CHR[1] - 128) - last[1];\
- CD[1] = (int)CHR[stride + 1] - (int)CHR[1];\
- last[0] = (int)CHR[stride + 0] - 128;\
- last[1] = (int)CHR[stride + 1] - 128;}
-
-/* common operations - add deltas to 4x4 block of luma or 2x2 blocks of chroma */
-static inline void tm2_apply_deltas(TM2Context *ctx, int* Y, int stride, int *deltas, int *last)
-{
- int ct, d;
- int i, j;
-
- for(j = 0; j < 4; j++){
- ct = ctx->D[j];
- for(i = 0; i < 4; i++){
- d = deltas[i + j * 4];
- ct += d;
- last[i] += ct;
- Y[i] = clip_uint8(last[i]);
- }
- Y += stride;
- ctx->D[j] = ct;
- }
-}
-
-static inline void tm2_high_chroma(int *data, int stride, int *last, int *CD, int *deltas)
-{
- int i, j;
- for(j = 0; j < 2; j++){
- for(i = 0; i < 2; i++){
- CD[j] += deltas[i + j * 2];
- last[i] += CD[j];
- data[i] = last[i] + 128;
- }
- data += stride;
- }
-}
-
-static inline void tm2_low_chroma(int *data, int stride, int *clast, int *CD, int *deltas, int bx)
-{
- int t;
- int l;
- int prev;
-
- if(bx > 0)
- prev = clast[-3];
- else
- prev = 0;
- t = (CD[0] + CD[1]) >> 1;
- l = (prev - CD[0] - CD[1] + clast[1]) >> 1;
- CD[1] = CD[0] + CD[1] - t;
- CD[0] = t;
- clast[0] = l;
-
- tm2_high_chroma(data, stride, clast, CD, deltas);
-}
-
-static inline void tm2_hi_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
-{
- int i;
- int deltas[16];
- TM2_INIT_POINTERS();
-
- /* hi-res chroma */
- for(i = 0; i < 4; i++) {
- deltas[i] = GET_TOK(ctx, TM2_C_HI);
- deltas[i + 4] = GET_TOK(ctx, TM2_C_HI);
- }
- tm2_high_chroma(U, Ustride, clast, ctx->CD, deltas);
- tm2_high_chroma(V, Vstride, clast + 2, ctx->CD + 2, deltas + 4);
-
- /* hi-res luma */
- for(i = 0; i < 16; i++)
- deltas[i] = GET_TOK(ctx, TM2_L_HI);
-
- tm2_apply_deltas(ctx, Y, Ystride, deltas, last);
-}
-
-static inline void tm2_med_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
-{
- int i;
- int deltas[16];
- TM2_INIT_POINTERS();
-
- /* low-res chroma */
- deltas[0] = GET_TOK(ctx, TM2_C_LO);
- deltas[1] = deltas[2] = deltas[3] = 0;
- tm2_low_chroma(U, Ustride, clast, ctx->CD, deltas, bx);
-
- deltas[0] = GET_TOK(ctx, TM2_C_LO);
- deltas[1] = deltas[2] = deltas[3] = 0;
- tm2_low_chroma(V, Vstride, clast + 2, ctx->CD + 2, deltas, bx);
-
- /* hi-res luma */
- for(i = 0; i < 16; i++)
- deltas[i] = GET_TOK(ctx, TM2_L_HI);
-
- tm2_apply_deltas(ctx, Y, Ystride, deltas, last);
-}
-
-static inline void tm2_low_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
-{
- int i;
- int t1, t2;
- int deltas[16];
- TM2_INIT_POINTERS();
-
- /* low-res chroma */
- deltas[0] = GET_TOK(ctx, TM2_C_LO);
- deltas[1] = deltas[2] = deltas[3] = 0;
- tm2_low_chroma(U, Ustride, clast, ctx->CD, deltas, bx);
-
- deltas[0] = GET_TOK(ctx, TM2_C_LO);
- deltas[1] = deltas[2] = deltas[3] = 0;
- tm2_low_chroma(V, Vstride, clast + 2, ctx->CD + 2, deltas, bx);
-
- /* low-res luma */
- for(i = 0; i < 16; i++)
- deltas[i] = 0;
-
- deltas[ 0] = GET_TOK(ctx, TM2_L_LO);
- deltas[ 2] = GET_TOK(ctx, TM2_L_LO);
- deltas[ 8] = GET_TOK(ctx, TM2_L_LO);
- deltas[10] = GET_TOK(ctx, TM2_L_LO);
-
- if(bx > 0)
- last[0] = (last[-1] - ctx->D[0] - ctx->D[1] - ctx->D[2] - ctx->D[3] + last[1]) >> 1;
- else
- last[0] = (last[1] - ctx->D[0] - ctx->D[1] - ctx->D[2] - ctx->D[3])>> 1;
- last[2] = (last[1] + last[3]) >> 1;
-
- t1 = ctx->D[0] + ctx->D[1];
- ctx->D[0] = t1 >> 1;
- ctx->D[1] = t1 - (t1 >> 1);
- t2 = ctx->D[2] + ctx->D[3];
- ctx->D[2] = t2 >> 1;
- ctx->D[3] = t2 - (t2 >> 1);
-
- tm2_apply_deltas(ctx, Y, Ystride, deltas, last);
-}
-
-static inline void tm2_null_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
-{
- int i;
- int ct;
- int left, right, diff;
- int deltas[16];
- TM2_INIT_POINTERS();
-
- /* null chroma */
- deltas[0] = deltas[1] = deltas[2] = deltas[3] = 0;
- tm2_low_chroma(U, Ustride, clast, ctx->CD, deltas, bx);
-
- deltas[0] = deltas[1] = deltas[2] = deltas[3] = 0;
- tm2_low_chroma(V, Vstride, clast + 2, ctx->CD + 2, deltas, bx);
-
- /* null luma */
- for(i = 0; i < 16; i++)
- deltas[i] = 0;
-
- ct = ctx->D[0] + ctx->D[1] + ctx->D[2] + ctx->D[3];
-
- if(bx > 0)
- left = last[-1] - ct;
- else
- left = 0;
-
- right = last[3];
- diff = right - left;
- last[0] = left + (diff >> 2);
- last[1] = left + (diff >> 1);
- last[2] = right - (diff >> 2);
- last[3] = right;
- {
- int tp = left;
-
- ctx->D[0] = (tp + (ct >> 2)) - left;
- left += ctx->D[0];
- ctx->D[1] = (tp + (ct >> 1)) - left;
- left += ctx->D[1];
- ctx->D[2] = ((tp + ct) - (ct >> 2)) - left;
- left += ctx->D[2];
- ctx->D[3] = (tp + ct) - left;
- }
- tm2_apply_deltas(ctx, Y, Ystride, deltas, last);
-}
-
-static inline void tm2_still_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
-{
- int i, j;
- TM2_INIT_POINTERS_2();
-
- /* update chroma */
- for(j = 0; j < 2; j++){
- for(i = 0; i < 2; i++){
- U[i] = Uo[i];
- V[i] = Vo[i];
- }
- U += Ustride; V += Vstride;
- Uo += oUstride; Vo += oVstride;
- }
- U -= Ustride * 2;
- V -= Vstride * 2;
- TM2_RECALC_BLOCK(U, Ustride, clast, ctx->CD);
- TM2_RECALC_BLOCK(V, Vstride, (clast + 2), (ctx->CD + 2));
-
- /* update deltas */
- ctx->D[0] = Yo[3] - last[3];
- ctx->D[1] = Yo[3 + oYstride] - Yo[3];
- ctx->D[2] = Yo[3 + oYstride * 2] - Yo[3 + oYstride];
- ctx->D[3] = Yo[3 + oYstride * 3] - Yo[3 + oYstride * 2];
-
- for(j = 0; j < 4; j++){
- for(i = 0; i < 4; i++){
- Y[i] = Yo[i];
- last[i] = Yo[i];
- }
- Y += Ystride;
- Yo += oYstride;
- }
-}
-
-static inline void tm2_update_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
-{
- int i, j;
- int d;
- TM2_INIT_POINTERS_2();
-
- /* update chroma */
- for(j = 0; j < 2; j++){
- for(i = 0; i < 2; i++){
- U[i] = Uo[i] + GET_TOK(ctx, TM2_UPD);
- V[i] = Vo[i] + GET_TOK(ctx, TM2_UPD);
- }
- U += Ustride; V += Vstride;
- Uo += oUstride; Vo += oVstride;
- }
- U -= Ustride * 2;
- V -= Vstride * 2;
- TM2_RECALC_BLOCK(U, Ustride, clast, ctx->CD);
- TM2_RECALC_BLOCK(V, Vstride, (clast + 2), (ctx->CD + 2));
-
- /* update deltas */
- ctx->D[0] = Yo[3] - last[3];
- ctx->D[1] = Yo[3 + oYstride] - Yo[3];
- ctx->D[2] = Yo[3 + oYstride * 2] - Yo[3 + oYstride];
- ctx->D[3] = Yo[3 + oYstride * 3] - Yo[3 + oYstride * 2];
-
- for(j = 0; j < 4; j++){
- d = last[3];
- for(i = 0; i < 4; i++){
- Y[i] = Yo[i] + GET_TOK(ctx, TM2_UPD);
- last[i] = Y[i];
- }
- ctx->D[j] = last[3] - d;
- Y += Ystride;
- Yo += oYstride;
- }
-}
-
-static inline void tm2_motion_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
-{
- int i, j;
- int mx, my;
- TM2_INIT_POINTERS_2();
-
- mx = GET_TOK(ctx, TM2_MOT);
- my = GET_TOK(ctx, TM2_MOT);
-
- Yo += my * oYstride + mx;
- Uo += (my >> 1) * oUstride + (mx >> 1);
- Vo += (my >> 1) * oVstride + (mx >> 1);
-
- /* copy chroma */
- for(j = 0; j < 2; j++){
- for(i = 0; i < 2; i++){
- U[i] = Uo[i];
- V[i] = Vo[i];
- }
- U += Ustride; V += Vstride;
- Uo += oUstride; Vo += oVstride;
- }
- U -= Ustride * 2;
- V -= Vstride * 2;
- TM2_RECALC_BLOCK(U, Ustride, clast, ctx->CD);
- TM2_RECALC_BLOCK(V, Vstride, (clast + 2), (ctx->CD + 2));
-
- /* copy luma */
- for(j = 0; j < 4; j++){
- for(i = 0; i < 4; i++){
- Y[i] = Yo[i];
- }
- Y += Ystride;
- Yo += oYstride;
- }
- /* calculate deltas */
- Y -= Ystride * 4;
- ctx->D[0] = Y[3] - last[3];
- ctx->D[1] = Y[3 + Ystride] - Y[3];
- ctx->D[2] = Y[3 + Ystride * 2] - Y[3 + Ystride];
- ctx->D[3] = Y[3 + Ystride * 3] - Y[3 + Ystride * 2];
- for(i = 0; i < 4; i++)
- last[i] = Y[i + Ystride * 3];
-}
-
-static int tm2_decode_blocks(TM2Context *ctx, AVFrame *p)
-{
- int i, j;
- int bw, bh;
- int type;
- int keyframe = 1;
- uint8_t *Y, *U, *V;
- int *src;
-
- bw = ctx->avctx->width >> 2;
- bh = ctx->avctx->height >> 2;
-
- for(i = 0; i < TM2_NUM_STREAMS; i++)
- ctx->tok_ptrs[i] = 0;
-
- if (ctx->tok_lens[TM2_TYPE]<bw*bh){
- av_log(ctx->avctx,AV_LOG_ERROR,"Got %i tokens for %i blocks\n",ctx->tok_lens[TM2_TYPE],bw*bh);
- return -1;
- }
-
- memset(ctx->last, 0, 4 * bw * sizeof(int));
- memset(ctx->clast, 0, 4 * bw * sizeof(int));
-
- for(j = 0; j < bh; j++) {
- memset(ctx->D, 0, 4 * sizeof(int));
- memset(ctx->CD, 0, 4 * sizeof(int));
- for(i = 0; i < bw; i++) {
- type = GET_TOK(ctx, TM2_TYPE);
- switch(type) {
- case TM2_HI_RES:
- tm2_hi_res_block(ctx, p, i, j);
- break;
- case TM2_MED_RES:
- tm2_med_res_block(ctx, p, i, j);
- break;
- case TM2_LOW_RES:
- tm2_low_res_block(ctx, p, i, j);
- break;
- case TM2_NULL_RES:
- tm2_null_res_block(ctx, p, i, j);
- break;
- case TM2_UPDATE:
- tm2_update_block(ctx, p, i, j);
- keyframe = 0;
- break;
- case TM2_STILL:
- tm2_still_block(ctx, p, i, j);
- keyframe = 0;
- break;
- case TM2_MOTION:
- tm2_motion_block(ctx, p, i, j);
- keyframe = 0;
- break;
- default:
- av_log(ctx->avctx, AV_LOG_ERROR, "Skipping unknown block type %i\n", type);
- }
- }
- }
-
- /* copy data from our buffer to AVFrame */
- Y = p->data[0];
- src = (ctx->cur?ctx->Y2:ctx->Y1);
- for(j = 0; j < ctx->avctx->height; j++){
- for(i = 0; i < ctx->avctx->width; i++){
- Y[i] = clip_uint8(*src++);
- }
- Y += p->linesize[0];
- }
- U = p->data[2];
- src = (ctx->cur?ctx->U2:ctx->U1);
- for(j = 0; j < (ctx->avctx->height + 1) >> 1; j++){
- for(i = 0; i < (ctx->avctx->width + 1) >> 1; i++){
- U[i] = clip_uint8(*src++);
- }
- U += p->linesize[2];
- }
- V = p->data[1];
- src = (ctx->cur?ctx->V2:ctx->V1);
- for(j = 0; j < (ctx->avctx->height + 1) >> 1; j++){
- for(i = 0; i < (ctx->avctx->width + 1) >> 1; i++){
- V[i] = clip_uint8(*src++);
- }
- V += p->linesize[1];
- }
-
- return keyframe;
-}
-
-static int decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- TM2Context * const l = avctx->priv_data;
- AVFrame * const p= (AVFrame*)&l->pic;
- int skip, t;
-
- p->reference = 1;
- p->buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
- if(avctx->reget_buffer(avctx, p) < 0){
- av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
- return -1;
- }
-
- l->dsp.bswap_buf((uint32_t*)buf, (uint32_t*)buf, buf_size >> 2);
- skip = tm2_read_header(l, buf);
-
- if(skip == -1)
- return -1;
-
- t = tm2_read_stream(l, buf + skip, TM2_C_HI);
- if(t == -1)
- return -1;
- skip += t;
- t = tm2_read_stream(l, buf + skip, TM2_C_LO);
- if(t == -1)
- return -1;
- skip += t;
- t = tm2_read_stream(l, buf + skip, TM2_L_HI);
- if(t == -1)
- return -1;
- skip += t;
- t = tm2_read_stream(l, buf + skip, TM2_L_LO);
- if(t == -1)
- return -1;
- skip += t;
- t = tm2_read_stream(l, buf + skip, TM2_UPD);
- if(t == -1)
- return -1;
- skip += t;
- t = tm2_read_stream(l, buf + skip, TM2_MOT);
- if(t == -1)
- return -1;
- skip += t;
- t = tm2_read_stream(l, buf + skip, TM2_TYPE);
- if(t == -1)
- return -1;
- p->key_frame = tm2_decode_blocks(l, p);
- if(p->key_frame)
- p->pict_type = FF_I_TYPE;
- else
- p->pict_type = FF_P_TYPE;
-
- l->cur = !l->cur;
- *data_size = sizeof(AVFrame);
- *(AVFrame*)data = l->pic;
-
- return buf_size;
-}
-
-static 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;
- }
-
- l->avctx = avctx;
- l->pic.data[0]=NULL;
- avctx->has_b_frames = 0;
- avctx->pix_fmt = PIX_FMT_YUV420P;
-
- dsputil_init(&l->dsp, avctx);
-
- l->last = av_malloc(4 * sizeof(int) * (avctx->width >> 2));
- l->clast = av_malloc(4 * sizeof(int) * (avctx->width >> 2));
-
- for(i = 0; i < TM2_NUM_STREAMS; i++) {
- l->tokens[i] = NULL;
- l->tok_lens[i] = 0;
- }
-
- l->Y1 = av_malloc(sizeof(int) * avctx->width * avctx->height);
- l->U1 = av_malloc(sizeof(int) * ((avctx->width + 1) >> 1) * ((avctx->height + 1) >> 1));
- l->V1 = av_malloc(sizeof(int) * ((avctx->width + 1) >> 1) * ((avctx->height + 1) >> 1));
- l->Y2 = av_malloc(sizeof(int) * avctx->width * avctx->height);
- l->U2 = av_malloc(sizeof(int) * ((avctx->width + 1) >> 1) * ((avctx->height + 1) >> 1));
- l->V2 = av_malloc(sizeof(int) * ((avctx->width + 1) >> 1) * ((avctx->height + 1) >> 1));
- l->cur = 0;
-
- return 0;
-}
-
-static int decode_end(AVCodecContext *avctx){
- TM2Context * const l = avctx->priv_data;
- int i;
-
- if(l->last)
- av_free(l->last);
- if(l->clast)
- av_free(l->clast);
- for(i = 0; i < TM2_NUM_STREAMS; i++)
- if(l->tokens[i])
- av_free(l->tokens[i]);
- if(l->Y1){
- av_free(l->Y1);
- av_free(l->U1);
- av_free(l->V1);
- av_free(l->Y2);
- av_free(l->U2);
- av_free(l->V2);
- }
- return 0;
-}
-
-AVCodec truemotion2_decoder = {
- "truemotion2",
- CODEC_TYPE_VIDEO,
- CODEC_ID_TRUEMOTION2,
- sizeof(TM2Context),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
-};
diff --git a/src/libffmpeg/libavcodec/truespeech.c b/src/libffmpeg/libavcodec/truespeech.c
deleted file mode 100644
index d37aa9454..000000000
--- a/src/libffmpeg/libavcodec/truespeech.c
+++ /dev/null
@@ -1,381 +0,0 @@
-/*
- * DSP Group TrueSpeech compatible decoder
- * Copyright (c) 2005 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 "truespeech_data.h"
-/**
- * @file truespeech.c
- * TrueSpeech decoder.
- */
-
-/**
- * TrueSpeech decoder context
- */
-typedef struct {
- /* input data */
- int16_t vector[8]; //< input vector: 5/5/4/4/4/3/3/3
- int offset1[2]; //< 8-bit value, used in one copying offset
- int offset2[4]; //< 7-bit value, encodes offsets for copying and for two-point filter
- int pulseoff[4]; //< 4-bit offset of pulse values block
- int pulsepos[4]; //< 27-bit variable, encodes 7 pulse positions
- int pulseval[4]; //< 7x2-bit pulse values
- int flag; //< 1-bit flag, shows how to choose filters
- /* temporary data */
- int filtbuf[146]; // some big vector used for storing filters
- int prevfilt[8]; // filter from previous frame
- int16_t tmp1[8]; // coefficients for adding to out
- int16_t tmp2[8]; // coefficients for adding to out
- int16_t tmp3[8]; // coefficients for adding to out
- int16_t cvector[8]; // correlated input vector
- int filtval; // gain value for one function
- int16_t newvec[60]; // tmp vector
- int16_t filters[32]; // filters for every subframe
-} TSContext;
-
-static int truespeech_decode_init(AVCodecContext * avctx)
-{
-// TSContext *c = avctx->priv_data;
-
- return 0;
-}
-
-static void truespeech_read_frame(TSContext *dec, uint8_t *input)
-{
- uint32_t t;
-
- /* first dword */
- t = AV_RL32(input);
- input += 4;
-
- dec->flag = t & 1;
-
- dec->vector[0] = ts_codebook[0][(t >> 1) & 0x1F];
- dec->vector[1] = ts_codebook[1][(t >> 6) & 0x1F];
- dec->vector[2] = ts_codebook[2][(t >> 11) & 0xF];
- dec->vector[3] = ts_codebook[3][(t >> 15) & 0xF];
- dec->vector[4] = ts_codebook[4][(t >> 19) & 0xF];
- dec->vector[5] = ts_codebook[5][(t >> 23) & 0x7];
- dec->vector[6] = ts_codebook[6][(t >> 26) & 0x7];
- dec->vector[7] = ts_codebook[7][(t >> 29) & 0x7];
-
- /* second dword */
- t = AV_RL32(input);
- input += 4;
-
- dec->offset2[0] = (t >> 0) & 0x7F;
- dec->offset2[1] = (t >> 7) & 0x7F;
- dec->offset2[2] = (t >> 14) & 0x7F;
- dec->offset2[3] = (t >> 21) & 0x7F;
-
- dec->offset1[0] = ((t >> 28) & 0xF) << 4;
-
- /* third dword */
- t = AV_RL32(input);
- input += 4;
-
- dec->pulseval[0] = (t >> 0) & 0x3FFF;
- dec->pulseval[1] = (t >> 14) & 0x3FFF;
-
- dec->offset1[1] = (t >> 28) & 0x0F;
-
- /* fourth dword */
- t = AV_RL32(input);
- input += 4;
-
- dec->pulseval[2] = (t >> 0) & 0x3FFF;
- dec->pulseval[3] = (t >> 14) & 0x3FFF;
-
- dec->offset1[1] |= ((t >> 28) & 0x0F) << 4;
-
- /* fifth dword */
- t = AV_RL32(input);
- input += 4;
-
- dec->pulsepos[0] = (t >> 4) & 0x7FFFFFF;
-
- dec->pulseoff[0] = (t >> 0) & 0xF;
-
- dec->offset1[0] |= (t >> 31) & 1;
-
- /* sixth dword */
- t = AV_RL32(input);
- input += 4;
-
- dec->pulsepos[1] = (t >> 4) & 0x7FFFFFF;
-
- dec->pulseoff[1] = (t >> 0) & 0xF;
-
- dec->offset1[0] |= ((t >> 31) & 1) << 1;
-
- /* seventh dword */
- t = AV_RL32(input);
- input += 4;
-
- dec->pulsepos[2] = (t >> 4) & 0x7FFFFFF;
-
- dec->pulseoff[2] = (t >> 0) & 0xF;
-
- dec->offset1[0] |= ((t >> 31) & 1) << 2;
-
- /* eighth dword */
- t = AV_RL32(input);
- input += 4;
-
- dec->pulsepos[3] = (t >> 4) & 0x7FFFFFF;
-
- dec->pulseoff[3] = (t >> 0) & 0xF;
-
- dec->offset1[0] |= ((t >> 31) & 1) << 3;
-
-}
-
-static void truespeech_correlate_filter(TSContext *dec)
-{
- int16_t tmp[8];
- int i, j;
-
- for(i = 0; i < 8; i++){
- if(i > 0){
- memcpy(tmp, dec->cvector, i * 2);
- for(j = 0; j < i; j++)
- dec->cvector[j] = ((tmp[i - j - 1] * dec->vector[i]) +
- (dec->cvector[j] << 15) + 0x4000) >> 15;
- }
- dec->cvector[i] = (8 - dec->vector[i]) >> 3;
- }
- for(i = 0; i < 8; i++)
- dec->cvector[i] = (dec->cvector[i] * ts_230[i]) >> 15;
-
- dec->filtval = dec->vector[0];
-}
-
-static void truespeech_filters_merge(TSContext *dec)
-{
- int i;
-
- if(!dec->flag){
- for(i = 0; i < 8; i++){
- dec->filters[i + 0] = dec->prevfilt[i];
- dec->filters[i + 8] = dec->prevfilt[i];
- }
- }else{
- for(i = 0; i < 8; i++){
- dec->filters[i + 0]=(dec->cvector[i] * 21846 + dec->prevfilt[i] * 10923 + 16384) >> 15;
- dec->filters[i + 8]=(dec->cvector[i] * 10923 + dec->prevfilt[i] * 21846 + 16384) >> 15;
- }
- }
- for(i = 0; i < 8; i++){
- dec->filters[i + 16] = dec->cvector[i];
- dec->filters[i + 24] = dec->cvector[i];
- }
-}
-
-static void truespeech_apply_twopoint_filter(TSContext *dec, int quart)
-{
- int16_t tmp[146 + 60], *ptr0, *ptr1;
- const int16_t *filter;
- int i, t, off;
-
- t = dec->offset2[quart];
- if(t == 127){
- memset(dec->newvec, 0, 60 * 2);
- return;
- }
- for(i = 0; i < 146; i++)
- tmp[i] = dec->filtbuf[i];
- off = (t / 25) + dec->offset1[quart >> 1] + 18;
- ptr0 = tmp + 145 - off;
- ptr1 = tmp + 146;
- filter = (const int16_t*)ts_240 + (t % 25) * 2;
- for(i = 0; i < 60; i++){
- t = (ptr0[0] * filter[0] + ptr0[1] * filter[1] + 0x2000) >> 14;
- ptr0++;
- dec->newvec[i] = t;
- ptr1[i] = t;
- }
-}
-
-static void truespeech_place_pulses(TSContext *dec, int16_t *out, int quart)
-{
- int16_t tmp[7];
- int i, j, t;
- const int16_t *ptr1;
- int16_t *ptr2;
- int coef;
-
- memset(out, 0, 60 * 2);
- for(i = 0; i < 7; i++) {
- t = dec->pulseval[quart] & 3;
- dec->pulseval[quart] >>= 2;
- tmp[6 - i] = ts_562[dec->pulseoff[quart] * 4 + t];
- }
-
- coef = dec->pulsepos[quart] >> 15;
- ptr1 = (const int16_t*)ts_140 + 30;
- ptr2 = tmp;
- for(i = 0, j = 3; (i < 30) && (j > 0); i++){
- t = *ptr1++;
- if(coef >= t)
- coef -= t;
- else{
- out[i] = *ptr2++;
- ptr1 += 30;
- j--;
- }
- }
- coef = dec->pulsepos[quart] & 0x7FFF;
- ptr1 = (const int16_t*)ts_140;
- for(i = 30, j = 4; (i < 60) && (j > 0); i++){
- t = *ptr1++;
- if(coef >= t)
- coef -= t;
- else{
- out[i] = *ptr2++;
- ptr1 += 30;
- j--;
- }
- }
-
-}
-
-static void truespeech_update_filters(TSContext *dec, int16_t *out, int quart)
-{
- int i;
-
- for(i = 0; i < 86; i++)
- dec->filtbuf[i] = dec->filtbuf[i + 60];
- for(i = 0; i < 60; i++){
- dec->filtbuf[i + 86] = out[i] + dec->newvec[i] - (dec->newvec[i] >> 3);
- out[i] += dec->newvec[i];
- }
-}
-
-static void truespeech_synth(TSContext *dec, int16_t *out, int quart)
-{
- int i,k;
- int t[8];
- int16_t *ptr0, *ptr1;
-
- ptr0 = dec->tmp1;
- ptr1 = dec->filters + quart * 8;
- for(i = 0; i < 60; i++){
- int sum = 0;
- for(k = 0; k < 8; k++)
- sum += ptr0[k] * ptr1[k];
- sum = (sum + (out[i] << 12) + 0x800) >> 12;
- out[i] = clip(sum, -0x7FFE, 0x7FFE);
- for(k = 7; k > 0; k--)
- ptr0[k] = ptr0[k - 1];
- ptr0[0] = out[i];
- }
-
- for(i = 0; i < 8; i++)
- t[i] = (ts_5E2[i] * ptr1[i]) >> 15;
-
- ptr0 = dec->tmp2;
- for(i = 0; i < 60; i++){
- int sum = 0;
- for(k = 0; k < 8; k++)
- sum += ptr0[k] * t[k];
- for(k = 7; k > 0; k--)
- ptr0[k] = ptr0[k - 1];
- ptr0[0] = out[i];
- out[i] = ((out[i] << 12) - sum) >> 12;
- }
-
- for(i = 0; i < 8; i++)
- t[i] = (ts_5F2[i] * ptr1[i]) >> 15;
-
- ptr0 = dec->tmp3;
- for(i = 0; i < 60; i++){
- int sum = out[i] << 12;
- for(k = 0; k < 8; k++)
- sum += ptr0[k] * t[k];
- for(k = 7; k > 0; k--)
- ptr0[k] = ptr0[k - 1];
- ptr0[0] = clip((sum + 0x800) >> 12, -0x7FFE, 0x7FFE);
-
- sum = ((ptr0[1] * (dec->filtval - (dec->filtval >> 2))) >> 4) + sum;
- sum = sum - (sum >> 3);
- out[i] = clip((sum + 0x800) >> 12, -0x7FFE, 0x7FFE);
- }
-}
-
-static void truespeech_save_prevvec(TSContext *c)
-{
- int i;
-
- for(i = 0; i < 8; i++)
- c->prevfilt[i] = c->cvector[i];
-}
-
-static int truespeech_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- TSContext *c = avctx->priv_data;
-
- int i;
- short *samples = data;
- int consumed = 0;
- int16_t out_buf[240];
-
- if (!buf_size)
- return 0;
-
- while (consumed < buf_size) {
- truespeech_read_frame(c, buf + consumed);
- consumed += 32;
-
- truespeech_correlate_filter(c);
- truespeech_filters_merge(c);
-
- memset(out_buf, 0, 240 * 2);
- for(i = 0; i < 4; i++) {
- truespeech_apply_twopoint_filter(c, i);
- truespeech_place_pulses(c, out_buf + i * 60, i);
- truespeech_update_filters(c, out_buf + i * 60, i);
- truespeech_synth(c, out_buf + i * 60, i);
- }
-
- truespeech_save_prevvec(c);
-
- /* finally output decoded frame */
- for(i = 0; i < 240; i++)
- *samples++ = out_buf[i];
-
- }
-
- *data_size = consumed * 15;
-
- return buf_size;
-}
-
-AVCodec truespeech_decoder = {
- "truespeech",
- CODEC_TYPE_AUDIO,
- CODEC_ID_TRUESPEECH,
- sizeof(TSContext),
- truespeech_decode_init,
- NULL,
- NULL,
- truespeech_decode_frame,
-};
diff --git a/src/libffmpeg/libavcodec/tscc.c b/src/libffmpeg/libavcodec/tscc.c
deleted file mode 100644
index e379abbbf..000000000
--- a/src/libffmpeg/libavcodec/tscc.c
+++ /dev/null
@@ -1,348 +0,0 @@
-/*
- * TechSmith Camtasia decoder
- * Copyright (c) 2004 Konstantin Shishkov
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-/**
- * @file tscc.c
- * TechSmith Camtasia decoder
- *
- * Fourcc: TSCC
- *
- * Codec is very simple:
- * it codes picture (picture difference, really)
- * with algorithm almost identical to Windows RLE8,
- * only without padding and with greater pixel sizes,
- * then this coded picture is packed with ZLib
- *
- * Supports: BGR8,BGR555,BGR24 - only BGR8 and BGR555 tested
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "common.h"
-#include "avcodec.h"
-
-#ifdef CONFIG_ZLIB
-#include <zlib.h>
-#endif
-
-
-/*
- * Decoder context
- */
-typedef struct TsccContext {
-
- AVCodecContext *avctx;
- AVFrame pic;
-
- // Bits per pixel
- int bpp;
- // Decompressed data size
- unsigned int decomp_size;
- // Decompression buffer
- unsigned char* decomp_buf;
- int height;
-#ifdef CONFIG_ZLIB
- z_stream zstream;
-#endif
-} CamtasiaContext;
-
-/*
- *
- * Decode RLE - almost identical to Windows BMP RLE8
- * and enhanced to bigger color depths
- *
- */
-
-static int decode_rle(CamtasiaContext *c, unsigned int srcsize)
-{
- unsigned char *src = c->decomp_buf;
- unsigned char *output, *output_end;
- int p1, p2, line=c->height, pos=0, i;
- uint16_t pix16;
- uint32_t pix32;
-
- output = c->pic.data[0] + (c->height - 1) * c->pic.linesize[0];
- output_end = c->pic.data[0] + (c->height) * c->pic.linesize[0];
- while(src < c->decomp_buf + srcsize) {
- p1 = *src++;
- if(p1 == 0) { //Escape code
- p2 = *src++;
- if(p2 == 0) { //End-of-line
- output = c->pic.data[0] + (--line) * c->pic.linesize[0];
- if (line < 0)
- return -1;
- pos = 0;
- continue;
- } else if(p2 == 1) { //End-of-picture
- return 0;
- } else if(p2 == 2) { //Skip
- p1 = *src++;
- p2 = *src++;
- line -= p2;
- if (line < 0)
- return -1;
- pos += p1;
- output = c->pic.data[0] + line * c->pic.linesize[0] + pos * (c->bpp / 8);
- continue;
- }
- // Copy data
- if (output + p2 * (c->bpp / 8) > output_end) {
- src += p2 * (c->bpp / 8);
- continue;
- }
- if ((c->bpp == 8) || (c->bpp == 24)) {
- for(i = 0; i < p2 * (c->bpp / 8); i++) {
- *output++ = *src++;
- }
- // RLE8 copy is actually padded - and runs are not!
- if(c->bpp == 8 && (p2 & 1)) {
- src++;
- }
- } else if (c->bpp == 16) {
- for(i = 0; i < p2; i++) {
- pix16 = AV_RL16(src);
- src += 2;
- *(uint16_t*)output = pix16;
- output += 2;
- }
- } else if (c->bpp == 32) {
- for(i = 0; i < p2; i++) {
- pix32 = AV_RL32(src);
- src += 4;
- *(uint32_t*)output = pix32;
- output += 4;
- }
- }
- pos += p2;
- } else { //Run of pixels
- int pix[4]; //original pixel
- switch(c->bpp){
- case 8: pix[0] = *src++;
- break;
- case 16: pix16 = AV_RL16(src);
- src += 2;
- *(uint16_t*)pix = pix16;
- break;
- case 24: pix[0] = *src++;
- pix[1] = *src++;
- pix[2] = *src++;
- break;
- case 32: pix32 = AV_RL32(src);
- src += 4;
- *(uint32_t*)pix = pix32;
- break;
- }
- if (output + p1 * (c->bpp / 8) > output_end)
- continue;
- for(i = 0; i < p1; i++) {
- switch(c->bpp){
- case 8: *output++ = pix[0];
- break;
- case 16: *(uint16_t*)output = pix16;
- output += 2;
- break;
- case 24: *output++ = pix[0];
- *output++ = pix[1];
- *output++ = pix[2];
- break;
- case 32: *(uint32_t*)output = pix32;
- output += 4;
- break;
- }
- }
- pos += p1;
- }
- }
-
- av_log(c->avctx, AV_LOG_ERROR, "Camtasia warning: no End-of-picture code\n");
- return 1;
-}
-
-/*
- *
- * Decode a frame
- *
- */
-static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size)
-{
- CamtasiaContext * const c = (CamtasiaContext *)avctx->priv_data;
- unsigned char *encoded = (unsigned char *)buf;
- unsigned char *outptr;
-#ifdef CONFIG_ZLIB
- int zret; // Zlib return code
-#endif
- int len = buf_size;
-
- if(c->pic.data[0])
- avctx->release_buffer(avctx, &c->pic);
-
- c->pic.reference = 1;
- c->pic.buffer_hints = FF_BUFFER_HINTS_VALID;
- if(avctx->get_buffer(avctx, &c->pic) < 0){
- av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
- return -1;
- }
-
- outptr = c->pic.data[0]; // Output image pointer
-
-#ifdef CONFIG_ZLIB
- zret = inflateReset(&(c->zstream));
- if (zret != Z_OK) {
- av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret);
- return -1;
- }
- c->zstream.next_in = encoded;
- c->zstream.avail_in = len;
- c->zstream.next_out = c->decomp_buf;
- c->zstream.avail_out = c->decomp_size;
- zret = inflate(&(c->zstream), Z_FINISH);
- // Z_DATA_ERROR means empty picture
- if ((zret != Z_OK) && (zret != Z_STREAM_END) && (zret != Z_DATA_ERROR)) {
- av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", zret);
- return -1;
- }
-
-
- if(zret != Z_DATA_ERROR)
- decode_rle(c, c->zstream.avail_out);
-
- /* make the palette available on the way out */
- if (c->avctx->pix_fmt == PIX_FMT_PAL8) {
- memcpy(c->pic.data[1], c->avctx->palctrl->palette, AVPALETTE_SIZE);
- if (c->avctx->palctrl->palette_changed) {
- c->pic.palette_has_changed = 1;
- c->avctx->palctrl->palette_changed = 0;
- }
- }
-
-#else
- av_log(avctx, AV_LOG_ERROR, "BUG! Zlib support not compiled in frame decoder.\n");
- return -1;
-#endif
-
- *data_size = sizeof(AVFrame);
- *(AVFrame*)data = c->pic;
-
- /* always report that the buffer was completely consumed */
- return buf_size;
-}
-
-
-
-/*
- *
- * Init tscc decoder
- *
- */
-static int decode_init(AVCodecContext *avctx)
-{
- CamtasiaContext * const c = (CamtasiaContext *)avctx->priv_data;
- int zret; // Zlib return code
-
- c->avctx = avctx;
- avctx->has_b_frames = 0;
-
- c->pic.data[0] = NULL;
- c->height = avctx->height;
-
- if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) {
- return 1;
- }
-
-#ifdef CONFIG_ZLIB
- // Needed if zlib unused or init aborted before inflateInit
- memset(&(c->zstream), 0, sizeof(z_stream));
-#else
- av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled.\n");
- return 1;
-#endif
- switch(avctx->bits_per_sample){
- case 8: avctx->pix_fmt = PIX_FMT_PAL8; break;
- case 16: avctx->pix_fmt = PIX_FMT_RGB555; break;
- case 24:
- avctx->pix_fmt = PIX_FMT_BGR24;
- break;
- case 32: avctx->pix_fmt = PIX_FMT_RGBA32; break;
- default: av_log(avctx, AV_LOG_ERROR, "Camtasia error: unknown depth %i bpp\n", avctx->bits_per_sample);
- return -1;
- }
- c->bpp = avctx->bits_per_sample;
- c->decomp_size = (avctx->width * c->bpp + (avctx->width + 254) / 255 + 2) * avctx->height + 2;//RLE in the 'best' case
-
- /* Allocate decompression buffer */
- if (c->decomp_size) {
- if ((c->decomp_buf = av_malloc(c->decomp_size)) == NULL) {
- av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
- return 1;
- }
- }
-
-#ifdef CONFIG_ZLIB
- c->zstream.zalloc = Z_NULL;
- c->zstream.zfree = Z_NULL;
- c->zstream.opaque = Z_NULL;
- zret = inflateInit(&(c->zstream));
- if (zret != Z_OK) {
- av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
- return 1;
- }
-#endif
-
- return 0;
-}
-
-
-
-/*
- *
- * Uninit tscc decoder
- *
- */
-static int decode_end(AVCodecContext *avctx)
-{
- CamtasiaContext * const c = (CamtasiaContext *)avctx->priv_data;
-
- av_freep(&c->decomp_buf);
-
- if (c->pic.data[0])
- avctx->release_buffer(avctx, &c->pic);
-#ifdef CONFIG_ZLIB
- inflateEnd(&(c->zstream));
-#endif
-
- return 0;
-}
-
-AVCodec tscc_decoder = {
- "camtasia",
- CODEC_TYPE_VIDEO,
- CODEC_ID_TSCC,
- sizeof(CamtasiaContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
-};
-
diff --git a/src/libffmpeg/libavcodec/ulti.c b/src/libffmpeg/libavcodec/ulti.c
deleted file mode 100644
index b4028f439..000000000
--- a/src/libffmpeg/libavcodec/ulti.c
+++ /dev/null
@@ -1,428 +0,0 @@
-/*
- * IBM Ultimotion Video Decoder
- * Copyright (C) 2004 Konstantin Shishkov
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-/**
- * @file ulti.c
- * IBM Ultimotion Video Decoder.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "common.h"
-#include "avcodec.h"
-
-#include "ulti_cb.h"
-
-typedef struct UltimotionDecodeContext {
- AVCodecContext *avctx;
- int width, height, blocks;
- AVFrame frame;
- const uint8_t *ulti_codebook;
-} UltimotionDecodeContext;
-
-static int ulti_decode_init(AVCodecContext *avctx)
-{
- UltimotionDecodeContext *s = avctx->priv_data;
-
- s->avctx = avctx;
- s->width = avctx->width;
- s->height = avctx->height;
- s->blocks = (s->width / 8) * (s->height / 8);
- avctx->pix_fmt = PIX_FMT_YUV410P;
- avctx->has_b_frames = 0;
- avctx->coded_frame = (AVFrame*) &s->frame;
- s->ulti_codebook = ulti_codebook;
-
- return 0;
-}
-
-static int block_coords[8] = // 4x4 block coords in 8x8 superblock
- { 0, 0, 0, 4, 4, 4, 4, 0};
-
-static int angle_by_index[4] = { 0, 2, 6, 12};
-
-/* Lookup tables for luma and chroma - used by ulti_convert_yuv() */
-static uint8_t ulti_lumas[64] =
- { 0x10, 0x13, 0x17, 0x1A, 0x1E, 0x21, 0x25, 0x28,
- 0x2C, 0x2F, 0x33, 0x36, 0x3A, 0x3D, 0x41, 0x44,
- 0x48, 0x4B, 0x4F, 0x52, 0x56, 0x59, 0x5C, 0x60,
- 0x63, 0x67, 0x6A, 0x6E, 0x71, 0x75, 0x78, 0x7C,
- 0x7F, 0x83, 0x86, 0x8A, 0x8D, 0x91, 0x94, 0x98,
- 0x9B, 0x9F, 0xA2, 0xA5, 0xA9, 0xAC, 0xB0, 0xB3,
- 0xB7, 0xBA, 0xBE, 0xC1, 0xC5, 0xC8, 0xCC, 0xCF,
- 0xD3, 0xD6, 0xDA, 0xDD, 0xE1, 0xE4, 0xE8, 0xEB};
-
-static uint8_t ulti_chromas[16] =
- { 0x60, 0x67, 0x6D, 0x73, 0x7A, 0x80, 0x86, 0x8D,
- 0x93, 0x99, 0xA0, 0xA6, 0xAC, 0xB3, 0xB9, 0xC0};
-
-/* convert Ultimotion YUV block (sixteen 6-bit Y samples and
- two 4-bit chroma samples) into standard YUV and put it into frame */
-static void ulti_convert_yuv(AVFrame *frame, int x, int y,
- uint8_t *luma,int chroma)
-{
- uint8_t *y_plane, *cr_plane, *cb_plane;
- int i;
-
- y_plane = frame->data[0] + x + y * frame->linesize[0];
- cr_plane = frame->data[1] + (x / 4) + (y / 4) * frame->linesize[1];
- cb_plane = frame->data[2] + (x / 4) + (y / 4) * frame->linesize[2];
-
- cr_plane[0] = ulti_chromas[chroma >> 4];
-
- cb_plane[0] = ulti_chromas[chroma & 0xF];
-
-
- for(i = 0; i < 16; i++){
- y_plane[i & 3] = ulti_lumas[luma[i]];
- if((i & 3) == 3) { //next row
- y_plane += frame->linesize[0];
- }
- }
-}
-
-/* generate block like in MS Video1 */
-static void ulti_pattern(AVFrame *frame, int x, int y,
- int f0, int f1, int Y0, int Y1, int chroma)
-{
- uint8_t Luma[16];
- int mask, i;
- for(mask = 0x80, i = 0; mask; mask >>= 1, i++) {
- if(f0 & mask)
- Luma[i] = Y1;
- else
- Luma[i] = Y0;
- }
-
- for(mask = 0x80, i = 8; mask; mask >>= 1, i++) {
- if(f1 & mask)
- Luma[i] = Y1;
- else
- Luma[i] = Y0;
- }
-
- ulti_convert_yuv(frame, x, y, Luma, chroma);
-}
-
-/* fill block with some gradient */
-static void ulti_grad(AVFrame *frame, int x, int y, uint8_t *Y, int chroma, int angle)
-{
- uint8_t Luma[16];
- if(angle & 8) { //reverse order
- int t;
- angle &= 0x7;
- t = Y[0];
- Y[0] = Y[3];
- Y[3] = t;
- t = Y[1];
- Y[1] = Y[2];
- Y[2] = t;
- }
- switch(angle){
- case 0:
- Luma[0] = Y[0]; Luma[1] = Y[1]; Luma[2] = Y[2]; Luma[3] = Y[3];
- Luma[4] = Y[0]; Luma[5] = Y[1]; Luma[6] = Y[2]; Luma[7] = Y[3];
- Luma[8] = Y[0]; Luma[9] = Y[1]; Luma[10] = Y[2]; Luma[11] = Y[3];
- Luma[12] = Y[0]; Luma[13] = Y[1]; Luma[14] = Y[2]; Luma[15] = Y[3];
- break;
- case 1:
- Luma[0] = Y[1]; Luma[1] = Y[2]; Luma[2] = Y[3]; Luma[3] = Y[3];
- Luma[4] = Y[0]; Luma[5] = Y[1]; Luma[6] = Y[2]; Luma[7] = Y[3];
- Luma[8] = Y[0]; Luma[9] = Y[1]; Luma[10] = Y[2]; Luma[11] = Y[3];
- Luma[12] = Y[0]; Luma[13] = Y[0]; Luma[14] = Y[1]; Luma[15] = Y[2];
- break;
- case 2:
- Luma[0] = Y[1]; Luma[1] = Y[2]; Luma[2] = Y[3]; Luma[3] = Y[3];
- Luma[4] = Y[1]; Luma[5] = Y[2]; Luma[6] = Y[2]; Luma[7] = Y[3];
- Luma[8] = Y[0]; Luma[9] = Y[1]; Luma[10] = Y[1]; Luma[11] = Y[2];
- Luma[12] = Y[0]; Luma[13] = Y[0]; Luma[14] = Y[1]; Luma[15] = Y[2];
- break;
- case 3:
- Luma[0] = Y[2]; Luma[1] = Y[3]; Luma[2] = Y[3]; Luma[3] = Y[3];
- Luma[4] = Y[1]; Luma[5] = Y[2]; Luma[6] = Y[2]; Luma[7] = Y[3];
- Luma[8] = Y[0]; Luma[9] = Y[1]; Luma[10] = Y[1]; Luma[11] = Y[2];
- Luma[12] = Y[0]; Luma[13] = Y[0]; Luma[14] = Y[0]; Luma[15] = Y[1];
- break;
- case 4:
- Luma[0] = Y[3]; Luma[1] = Y[3]; Luma[2] = Y[3]; Luma[3] = Y[3];
- Luma[4] = Y[2]; Luma[5] = Y[2]; Luma[6] = Y[2]; Luma[7] = Y[2];
- Luma[8] = Y[1]; Luma[9] = Y[1]; Luma[10] = Y[1]; Luma[11] = Y[1];
- Luma[12] = Y[0]; Luma[13] = Y[0]; Luma[14] = Y[0]; Luma[15] = Y[0];
- break;
- case 5:
- Luma[0] = Y[3]; Luma[1] = Y[3]; Luma[2] = Y[3]; Luma[3] = Y[2];
- Luma[4] = Y[3]; Luma[5] = Y[2]; Luma[6] = Y[2]; Luma[7] = Y[1];
- Luma[8] = Y[2]; Luma[9] = Y[1]; Luma[10] = Y[1]; Luma[11] = Y[0];
- Luma[12] = Y[1]; Luma[13] = Y[0]; Luma[14] = Y[0]; Luma[15] = Y[0];
- break;
- case 6:
- Luma[0] = Y[3]; Luma[1] = Y[3]; Luma[2] = Y[2]; Luma[3] = Y[2];
- Luma[4] = Y[3]; Luma[5] = Y[2]; Luma[6] = Y[1]; Luma[7] = Y[1];
- Luma[8] = Y[2]; Luma[9] = Y[2]; Luma[10] = Y[1]; Luma[11] = Y[0];
- Luma[12] = Y[1]; Luma[13] = Y[1]; Luma[14] = Y[0]; Luma[15] = Y[0];
- break;
- case 7:
- Luma[0] = Y[3]; Luma[1] = Y[3]; Luma[2] = Y[2]; Luma[3] = Y[1];
- Luma[4] = Y[3]; Luma[5] = Y[2]; Luma[6] = Y[1]; Luma[7] = Y[0];
- Luma[8] = Y[3]; Luma[9] = Y[2]; Luma[10] = Y[1]; Luma[11] = Y[0];
- Luma[12] = Y[2]; Luma[13] = Y[1]; Luma[14] = Y[0]; Luma[15] = Y[0];
- break;
- default:
- Luma[0] = Y[0]; Luma[1] = Y[0]; Luma[2] = Y[1]; Luma[3] = Y[1];
- Luma[4] = Y[0]; Luma[5] = Y[0]; Luma[6] = Y[1]; Luma[7] = Y[1];
- Luma[8] = Y[2]; Luma[9] = Y[2]; Luma[10] = Y[3]; Luma[11] = Y[3];
- Luma[12] = Y[2]; Luma[13] = Y[2]; Luma[14] = Y[3]; Luma[15] = Y[3];
- break;
- }
-
- ulti_convert_yuv(frame, x, y, Luma, chroma);
-}
-
-static int ulti_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- UltimotionDecodeContext *s=avctx->priv_data;
- int modifier = 0;
- int uniq = 0;
- int mode = 0;
- int blocks = 0;
- int done = 0;
- int x = 0, y = 0;
- int i;
- int skip;
- int tmp;
-
- if(s->frame.data[0])
- avctx->release_buffer(avctx, &s->frame);
-
- s->frame.reference = 1;
- s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
- if(avctx->get_buffer(avctx, &s->frame) < 0) {
- av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
- return -1;
- }
-
- while(!done) {
- int idx;
- if(blocks >= s->blocks || y >= s->height)
- break;//all blocks decoded
-
- idx = *buf++;
- if((idx & 0xF8) == 0x70) {
- switch(idx) {
- case 0x70: //change modifier
- modifier = *buf++;
- if(modifier>1)
- av_log(avctx, AV_LOG_INFO, "warning: modifier must be 0 or 1, got %i\n", modifier);
- break;
- case 0x71: // set uniq flag
- uniq = 1;
- break;
- case 0x72: //toggle mode
- mode = !mode;
- break;
- case 0x73: //end-of-frame
- done = 1;
- break;
- case 0x74: //skip some blocks
- skip = *buf++;
- if ((blocks + skip) >= s->blocks)
- break;
- blocks += skip;
- x += skip * 8;
- while(x >= s->width) {
- x -= s->width;
- y += 8;
- }
- break;
- default:
- av_log(avctx, AV_LOG_INFO, "warning: unknown escape 0x%02X\n", idx);
- }
- } else { //handle one block
- int code;
- int cf;
- int angle = 0;
- uint8_t Y[4]; // luma samples of block
- int tx = 0, ty = 0; //coords of subblock
- int chroma = 0;
- if (mode || uniq) {
- uniq = 0;
- cf = 1;
- chroma = 0;
- } else {
- cf = 0;
- if (idx)
- chroma = *buf++;
- }
- for (i = 0; i < 4; i++) { // for every subblock
- code = (idx >> (6 - i*2)) & 3; //extract 2 bits
- if(!code) //skip subblock
- continue;
- if(cf)
- chroma = *buf++;
- tx = x + block_coords[i * 2];
- ty = y + block_coords[(i * 2) + 1];
- switch(code) {
- case 1:
- tmp = *buf++;
-
- angle = angle_by_index[(tmp >> 6) & 0x3];
-
- Y[0] = tmp & 0x3F;
- Y[1] = Y[0];
-
- if (angle) {
- Y[2] = Y[0]+1;
- if (Y[2] > 0x3F)
- Y[2] = 0x3F;
- Y[3] = Y[2];
- } else {
- Y[2] = Y[0];
- Y[3] = Y[0];
- }
- break;
-
- case 2:
- if (modifier) { // unpack four luma samples
- tmp = (*buf++) << 16;
- tmp += (*buf++) << 8;
- tmp += *buf++;
-
- Y[0] = (tmp >> 18) & 0x3F;
- Y[1] = (tmp >> 12) & 0x3F;
- Y[2] = (tmp >> 6) & 0x3F;
- Y[3] = tmp & 0x3F;
- angle = 16;
- } else { // retrieve luma samples from codebook
- tmp = (*buf++) << 8;
- tmp += (*buf++);
-
- angle = (tmp >> 12) & 0xF;
- tmp &= 0xFFF;
- tmp <<= 2;
- Y[0] = s->ulti_codebook[tmp];
- Y[1] = s->ulti_codebook[tmp + 1];
- Y[2] = s->ulti_codebook[tmp + 2];
- Y[3] = s->ulti_codebook[tmp + 3];
- }
- break;
-
- case 3:
- if (modifier) { // all 16 luma samples
- uint8_t Luma[16];
-
- tmp = (*buf++) << 16;
- tmp += (*buf++) << 8;
- tmp += *buf++;
- Luma[0] = (tmp >> 18) & 0x3F;
- Luma[1] = (tmp >> 12) & 0x3F;
- Luma[2] = (tmp >> 6) & 0x3F;
- Luma[3] = tmp & 0x3F;
-
- tmp = (*buf++) << 16;
- tmp += (*buf++) << 8;
- tmp += *buf++;
- Luma[4] = (tmp >> 18) & 0x3F;
- Luma[5] = (tmp >> 12) & 0x3F;
- Luma[6] = (tmp >> 6) & 0x3F;
- Luma[7] = tmp & 0x3F;
-
- tmp = (*buf++) << 16;
- tmp += (*buf++) << 8;
- tmp += *buf++;
- Luma[8] = (tmp >> 18) & 0x3F;
- Luma[9] = (tmp >> 12) & 0x3F;
- Luma[10] = (tmp >> 6) & 0x3F;
- Luma[11] = tmp & 0x3F;
-
- tmp = (*buf++) << 16;
- tmp += (*buf++) << 8;
- tmp += *buf++;
- Luma[12] = (tmp >> 18) & 0x3F;
- Luma[13] = (tmp >> 12) & 0x3F;
- Luma[14] = (tmp >> 6) & 0x3F;
- Luma[15] = tmp & 0x3F;
-
- ulti_convert_yuv(&s->frame, tx, ty, Luma, chroma);
- } else {
- tmp = *buf++;
- if(tmp & 0x80) {
- angle = (tmp >> 4) & 0x7;
- tmp = (tmp << 8) + *buf++;
- Y[0] = (tmp >> 6) & 0x3F;
- Y[1] = tmp & 0x3F;
- Y[2] = (*buf++) & 0x3F;
- Y[3] = (*buf++) & 0x3F;
- ulti_grad(&s->frame, tx, ty, Y, chroma, angle); //draw block
- } else { // some patterns
- int f0, f1;
- f0 = *buf++;
- f1 = tmp;
- Y[0] = (*buf++) & 0x3F;
- Y[1] = (*buf++) & 0x3F;
- ulti_pattern(&s->frame, tx, ty, f1, f0, Y[0], Y[1], chroma);
- }
- }
- break;
- }
- if(code != 3)
- ulti_grad(&s->frame, tx, ty, Y, chroma, angle); // draw block
- }
- blocks++;
- x += 8;
- if(x >= s->width) {
- x = 0;
- y += 8;
- }
- }
- }
-
- *data_size=sizeof(AVFrame);
- *(AVFrame*)data= s->frame;
-
- return buf_size;
-}
-
-static int ulti_decode_end(AVCodecContext *avctx)
-{
-/* UltimotionDecodeContext *s = avctx->priv_data;*/
-
- return 0;
-}
-
-AVCodec ulti_decoder = {
- "ultimotion",
- CODEC_TYPE_VIDEO,
- CODEC_ID_ULTI,
- sizeof(UltimotionDecodeContext),
- ulti_decode_init,
- NULL,
- ulti_decode_end,
- ulti_decode_frame,
- CODEC_CAP_DR1,
- NULL
-};
-
diff --git a/src/libffmpeg/libavcodec/utils.c b/src/libffmpeg/libavcodec/utils.c
deleted file mode 100644
index f6f061360..000000000
--- a/src/libffmpeg/libavcodec/utils.c
+++ /dev/null
@@ -1,1354 +0,0 @@
-/*
- * utils for libavcodec
- * Copyright (c) 2001 Fabrice Bellard.
- * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/**
- * @file utils.c
- * utils.
- */
-
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-#include "integer.h"
-#include "opt.h"
-#include "crc.h"
-#include <stdarg.h>
-#include <limits.h>
-#include <float.h>
-#ifdef __MINGW32__
-#include <fcntl.h>
-#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;
-
-/**
- * realloc which does nothing if the block is large enough
- */
-void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size)
-{
- if(min_size < *size)
- return ptr;
-
- *size= FFMAX(17*min_size/16 + 32, min_size);
-
- return av_realloc(ptr, *size);
-}
-
-static unsigned int last_static = 0;
-static unsigned int allocated_static = 0;
-static void** array_static = NULL;
-
-/**
- * allocation of static arrays - do not use for normal allocation.
- */
-void *av_mallocz_static(unsigned int size)
-{
- void *ptr = av_mallocz(size);
-
- if(ptr){
- array_static =av_fast_realloc(array_static, &allocated_static, sizeof(void*)*(last_static+1));
- if(!array_static)
- return NULL;
- array_static[last_static++] = ptr;
- }
-
- return ptr;
-}
-
-/**
- * same as above, but does realloc
- */
-
-void *av_realloc_static(void *ptr, unsigned int size)
-{
- int i;
- if(!ptr)
- return av_mallocz_static(size);
- /* Look for the old ptr */
- for(i = 0; i < last_static; i++) {
- if(array_static[i] == ptr) {
- array_static[i] = av_realloc(array_static[i], size);
- return array_static[i];
- }
- }
- return NULL;
-
-}
-
-/**
- * free all static arrays and reset pointers to 0.
- */
-void av_free_static(void)
-{
- while(last_static){
- av_freep(&array_static[--last_static]);
- }
- av_freep(&array_static);
-}
-
-/**
- * Call av_free_static automatically before it's too late
- */
-
-static void do_free(void) __attribute__ ((destructor));
-
-static void do_free(void)
-{
- av_free_static();
-}
-
-
-/* encoder management */
-AVCodec *first_avcodec = NULL;
-
-void register_avcodec(AVCodec *format)
-{
- AVCodec **p;
- p = &first_avcodec;
- while (*p != NULL) p = &(*p)->next;
- *p = format;
- format->next = NULL;
-}
-
-void avcodec_set_dimensions(AVCodecContext *s, int width, int height){
- s->coded_width = width;
- s->coded_height= height;
- s->width = -((-width )>>s->lowres);
- s->height= -((-height)>>s->lowres);
-}
-
-typedef struct InternalBuffer{
- int last_pic_num;
- uint8_t *base[4];
- uint8_t *data[4];
- int linesize[4];
-}InternalBuffer;
-
-#define INTERNAL_BUFFER_SIZE 32
-
-#define ALIGN(x, a) (((x)+(a)-1)&~((a)-1))
-
-void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){
- int w_align= 1;
- int h_align= 1;
-
- switch(s->pix_fmt){
- case PIX_FMT_YUV420P:
- case PIX_FMT_YUV422:
- case PIX_FMT_UYVY422:
- case PIX_FMT_YUV422P:
- 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_YUVJ444P:
- w_align= 16; //FIXME check for non mpeg style codecs and use less alignment
- h_align= 16;
- break;
- case PIX_FMT_YUV411P:
- case PIX_FMT_UYVY411:
- w_align=32;
- h_align=8;
- break;
- case PIX_FMT_YUV410P:
- if(s->codec_id == CODEC_ID_SVQ1){
- w_align=64;
- h_align=64;
- }
- case PIX_FMT_RGB555:
- if(s->codec_id == CODEC_ID_RPZA){
- w_align=4;
- h_align=4;
- }
- case PIX_FMT_PAL8:
- if(s->codec_id == CODEC_ID_SMC){
- w_align=4;
- h_align=4;
- }
- break;
- case PIX_FMT_BGR24:
- if((s->codec_id == CODEC_ID_MSZH) || (s->codec_id == CODEC_ID_ZLIB)){
- w_align=4;
- h_align=4;
- }
- break;
- default:
- w_align= 1;
- h_align= 1;
- break;
- }
-
- *width = ALIGN(*width , w_align);
- *height= ALIGN(*height, h_align);
-}
-
-int avcodec_check_dimensions(void *av_log_ctx, unsigned int w, unsigned int h){
- if((int)w>0 && (int)h>0 && (w+128)*(uint64_t)(h+128) < INT_MAX/4)
- return 0;
-
- av_log(av_log_ctx, AV_LOG_ERROR, "picture size invalid (%ux%u)\n", w, h);
- return -1;
-}
-
-int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){
- int i;
- int w= s->width;
- int h= s->height;
- InternalBuffer *buf;
- int *picture_number;
-
- assert(pic->data[0]==NULL);
- assert(INTERNAL_BUFFER_SIZE > s->internal_buffer_count);
-
- if(avcodec_check_dimensions(s,w,h))
- return -1;
-
- if(s->internal_buffer==NULL){
- s->internal_buffer= av_mallocz(INTERNAL_BUFFER_SIZE*sizeof(InternalBuffer));
- }
-#if 0
- s->internal_buffer= av_fast_realloc(
- s->internal_buffer,
- &s->internal_buffer_size,
- sizeof(InternalBuffer)*FFMAX(99, s->internal_buffer_count+1)/*FIXME*/
- );
-#endif
-
- buf= &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];
- picture_number= &(((InternalBuffer*)s->internal_buffer)[INTERNAL_BUFFER_SIZE-1]).last_pic_num; //FIXME ugly hack
- (*picture_number)++;
-
- if(buf->base[0]){
- pic->age= *picture_number - buf->last_pic_num;
- buf->last_pic_num= *picture_number;
- }else{
- int h_chroma_shift, v_chroma_shift;
- int pixel_size, size[3];
- AVPicture picture;
-
- avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);
-
- avcodec_align_dimensions(s, &w, &h);
-
- if(!(s->flags&CODEC_FLAG_EMU_EDGE)){
- w+= EDGE_WIDTH*2;
- h+= EDGE_WIDTH*2;
- }
- avpicture_fill(&picture, NULL, s->pix_fmt, w, h);
- pixel_size= picture.linesize[0]*8 / w;
-//av_log(NULL, AV_LOG_ERROR, "%d %d %d %d\n", (int)picture.data[1], w, h, s->pix_fmt);
- assert(pixel_size>=1);
- //FIXME next ensures that linesize= 2^x uvlinesize, thats needed because some MC code assumes it
- if(pixel_size == 3*8)
- w= ALIGN(w, STRIDE_ALIGN<<h_chroma_shift);
- else
- w= ALIGN(pixel_size*w, STRIDE_ALIGN<<(h_chroma_shift+3)) / pixel_size;
- size[1] = avpicture_fill(&picture, NULL, s->pix_fmt, w, h);
- size[0] = picture.linesize[0] * h;
- size[1] -= size[0];
- if(picture.data[2])
- size[1]= size[2]= size[1]/2;
- else
- size[2]= 0;
-
- buf->last_pic_num= -256*256*256*64;
- memset(buf->base, 0, sizeof(buf->base));
- memset(buf->data, 0, sizeof(buf->data));
-
- for(i=0; i<3 && size[i]; i++){
- const int h_shift= i==0 ? 0 : h_chroma_shift;
- const int v_shift= i==0 ? 0 : v_chroma_shift;
-
- buf->linesize[i]= picture.linesize[i];
-
- buf->base[i]= av_malloc(size[i]+16); //FIXME 16
- if(buf->base[i]==NULL) return -1;
- memset(buf->base[i], 128, size[i]);
-
- // no edge if EDEG EMU or not planar YUV, we check for PAL8 redundantly to protect against a exploitable bug regression ...
- if((s->flags&CODEC_FLAG_EMU_EDGE) || (s->pix_fmt == PIX_FMT_PAL8) || !size[2])
- buf->data[i] = buf->base[i];
- else
- buf->data[i] = buf->base[i] + ALIGN((buf->linesize[i]*EDGE_WIDTH>>v_shift) + (EDGE_WIDTH>>h_shift), STRIDE_ALIGN);
- }
- pic->age= 256*256*256*64;
- }
- pic->type= FF_BUFFER_TYPE_INTERNAL;
-
- for(i=0; i<4; i++){
- pic->base[i]= buf->base[i];
- pic->data[i]= buf->data[i];
- pic->linesize[i]= buf->linesize[i];
- }
- s->internal_buffer_count++;
-
- return 0;
-}
-
-void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){
- int i;
- InternalBuffer *buf, *last, temp;
-
- assert(pic->type==FF_BUFFER_TYPE_INTERNAL);
- assert(s->internal_buffer_count);
-
- buf = NULL; /* avoids warning */
- for(i=0; i<s->internal_buffer_count; i++){ //just 3-5 checks so is not worth to optimize
- buf= &((InternalBuffer*)s->internal_buffer)[i];
- if(buf->data[0] == pic->data[0])
- break;
- }
- assert(i < s->internal_buffer_count);
- s->internal_buffer_count--;
- last = &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];
-
- temp= *buf;
- *buf= *last;
- *last= temp;
-
- for(i=0; i<3; i++){
- pic->data[i]=NULL;
-// pic->base[i]=NULL;
- }
-//printf("R%X\n", pic->opaque);
-}
-
-int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic){
- AVFrame temp_pic;
- int i;
-
- /* If no picture return a new buffer */
- if(pic->data[0] == NULL) {
- /* We will copy from buffer, so must be readable */
- pic->buffer_hints |= FF_BUFFER_HINTS_READABLE;
- return s->get_buffer(s, pic);
- }
-
- /* If internal buffer type return the same buffer */
- if(pic->type == FF_BUFFER_TYPE_INTERNAL)
- return 0;
-
- /*
- * Not internal type and reget_buffer not overridden, emulate cr buffer
- */
- temp_pic = *pic;
- for(i = 0; i < 4; i++)
- pic->data[i] = pic->base[i] = NULL;
- pic->opaque = NULL;
- /* Allocate new frame */
- if (s->get_buffer(s, pic))
- return -1;
- /* Copy image data from old buffer to new buffer */
- img_copy((AVPicture*)pic, (AVPicture*)&temp_pic, s->pix_fmt, s->width,
- s->height);
- s->release_buffer(s, &temp_pic); // Release old frame
- return 0;
-}
-
-int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count){
- int i;
-
- for(i=0; i<count; i++){
- int r= func(c, arg[i]);
- if(ret) ret[i]= r;
- }
- return 0;
-}
-
-enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat * fmt){
- return fmt[0];
-}
-
-static const char* context_to_name(void* ptr) {
- AVCodecContext *avc= ptr;
-
- if(avc && avc->codec && avc->codec->name)
- return avc->codec->name;
- else
- return "NULL";
-}
-
-#define OFFSET(x) offsetof(AVCodecContext,x)
-#define DEFAULT 0 //should be NAN but it doesnt work as its not a constant in glibc as required by ANSI/ISO C
-//these names are too long to be readable
-#define V AV_OPT_FLAG_VIDEO_PARAM
-#define A AV_OPT_FLAG_AUDIO_PARAM
-#define S AV_OPT_FLAG_SUBTITLE_PARAM
-#define E AV_OPT_FLAG_ENCODING_PARAM
-#define D AV_OPT_FLAG_DECODING_PARAM
-
-#define AV_CODEC_DEFAULT_BITRATE 200*1000
-
-static const AVOption options[]={
-{"b", "set video bitrate (in bits/s)", OFFSET(bit_rate), FF_OPT_TYPE_INT, AV_CODEC_DEFAULT_BITRATE, INT_MIN, INT_MAX, V|A|E},
-{"bt", "set video bitrate tolerance (in bits/s)", OFFSET(bit_rate_tolerance), FF_OPT_TYPE_INT, AV_CODEC_DEFAULT_BITRATE*20, 1, INT_MAX, V|E},
-{"flags", NULL, OFFSET(flags), FF_OPT_TYPE_FLAGS, DEFAULT, INT_MIN, INT_MAX, V|A|E|D, "flags"},
-{"mv4", "use four motion vector by macroblock (mpeg4)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_4MV, INT_MIN, INT_MAX, V|E, "flags"},
-{"obmc", "use overlapped block motion compensation (h263+)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_OBMC, INT_MIN, INT_MAX, V|E, "flags"},
-{"qpel", "use 1/4 pel motion compensation", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_QPEL, INT_MIN, INT_MAX, V|E, "flags"},
-{"loop", "use loop filter", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_LOOP_FILTER, INT_MIN, INT_MAX, V|E, "flags"},
-{"qscale", "use fixed qscale", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_QSCALE, INT_MIN, INT_MAX, 0, "flags"},
-{"gmc", "use gmc", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_GMC, INT_MIN, INT_MAX, V|E, "flags"},
-{"mv0", "always try a mb with mv=<0,0>", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_MV0, INT_MIN, INT_MAX, V|E, "flags"},
-{"part", "use data partitioning", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_PART, INT_MIN, INT_MAX, V|E, "flags"},
-{"input_preserved", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG_INPUT_PRESERVED, INT_MIN, INT_MAX, 0, "flags"},
-{"pass1", "use internal 2pass ratecontrol in first pass mode", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_PASS1, INT_MIN, INT_MAX, 0, "flags"},
-{"pass2", "use internal 2pass ratecontrol in second pass mode", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_PASS2, INT_MIN, INT_MAX, 0, "flags"},
-{"extern_huff", "use external huffman table (for mjpeg)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_EXTERN_HUFF, INT_MIN, INT_MAX, 0, "flags"},
-{"gray", "only decode/encode grayscale", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_GRAY, INT_MIN, INT_MAX, V|E|D, "flags"},
-{"emu_edge", "don't draw edges", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_EMU_EDGE, INT_MIN, INT_MAX, 0, "flags"},
-{"psnr", "error[?] variables will be set during encoding", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_PSNR, INT_MIN, INT_MAX, V|E, "flags"},
-{"truncated", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG_TRUNCATED, INT_MIN, INT_MAX, 0, "flags"},
-{"naq", "normalize adaptive quantization", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_NORMALIZE_AQP, INT_MIN, INT_MAX, V|E, "flags"},
-{"ildct", "use interlaced dct", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_INTERLACED_DCT, INT_MIN, INT_MAX, V|E, "flags"},
-{"low_delay", "force low delay", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_LOW_DELAY, INT_MIN, INT_MAX, V|D|E, "flags"},
-{"alt", "enable alternate scantable (mpeg2/mpeg4)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_ALT_SCAN, INT_MIN, INT_MAX, V|E, "flags"},
-{"trell", "use trellis quantization", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_TRELLIS_QUANT, INT_MIN, INT_MAX, V|E, "flags"},
-{"global_header", "place global headers in extradata instead of every keyframe", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_GLOBAL_HEADER, INT_MIN, INT_MAX, 0, "flags"},
-{"bitexact", "use only bitexact stuff (except (i)dct)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_BITEXACT, INT_MIN, INT_MAX, A|V|S|D|E, "flags"},
-{"aic", "h263 advanced intra coding / mpeg4 ac prediction", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_AC_PRED, INT_MIN, INT_MAX, V|E, "flags"},
-{"umv", "use unlimited motion vectors", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_H263P_UMV, INT_MIN, INT_MAX, V|E, "flags"},
-{"cbp", "use rate distortion optimization for cbp", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_CBP_RD, INT_MIN, INT_MAX, V|E, "flags"},
-{"qprd", "use rate distortion optimization for qp selection", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_QP_RD, INT_MIN, INT_MAX, V|E, "flags"},
-{"aiv", "h263 alternative inter vlc", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_H263P_AIV, INT_MIN, INT_MAX, V|E, "flags"},
-{"slice", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG_H263P_SLICE_STRUCT, INT_MIN, INT_MAX, V|E, "flags"},
-{"ilme", "interlaced motion estimation", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_INTERLACED_ME, INT_MIN, INT_MAX, V|E, "flags"},
-{"scan_offset", "will reserve space for svcd scan offset user data", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_SVCD_SCAN_OFFSET, INT_MIN, INT_MAX, V|E, "flags"},
-{"cgop", "closed gop", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_CLOSED_GOP, INT_MIN, INT_MAX, V|E, "flags"},
-{"fast", "allow non spec compliant speedup tricks", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_FAST, INT_MIN, INT_MAX, V|E, "flags2"},
-{"sgop", "strictly enforce gop size", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_STRICT_GOP, INT_MIN, INT_MAX, V|E, "flags2"},
-{"noout", "skip bitstream encoding", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_NO_OUTPUT, INT_MIN, INT_MAX, V|E, "flags2"},
-{"local_header", "place global headers at every keyframe instead of in extradata", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_LOCAL_HEADER, INT_MIN, INT_MAX, V|E, "flags2"},
-{"sub_id", NULL, OFFSET(sub_id), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"me_method", "set motion estimation method", OFFSET(me_method), FF_OPT_TYPE_INT, ME_EPZS, INT_MIN, INT_MAX, V|E, "me_method"},
-{"extradata_size", NULL, OFFSET(extradata_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"time_base", NULL, OFFSET(time_base), FF_OPT_TYPE_RATIONAL, DEFAULT, INT_MIN, INT_MAX},
-{"g", "set the group of picture size", OFFSET(gop_size), FF_OPT_TYPE_INT, 12, INT_MIN, INT_MAX, V|E},
-{"rate_emu", "frame rate emulation", OFFSET(rate_emu), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"ar", "set audio sampling rate (in Hz)", OFFSET(sample_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"ac", "set number of audio channels", OFFSET(channels), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"cutoff", "set cutoff bandwidth", OFFSET(cutoff), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, A|E},
-{"frame_size", NULL, OFFSET(frame_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, A|E},
-{"frame_number", NULL, OFFSET(frame_number), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"real_pict_num", NULL, OFFSET(real_pict_num), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"delay", NULL, OFFSET(delay), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"qcomp", "video quantizer scale compression (VBR)", OFFSET(qcompress), FF_OPT_TYPE_FLOAT, 0.5, FLT_MIN, FLT_MAX, V|E},
-{"qblur", "video quantizer scale blur (VBR)", OFFSET(qblur), FF_OPT_TYPE_FLOAT, 0.5, FLT_MIN, FLT_MAX, V|E},
-{"qmin", "min video quantizer scale (VBR)", OFFSET(qmin), FF_OPT_TYPE_INT, 2, 1, 51, V|E},
-{"qmax", "max video quantizer scale (VBR)", OFFSET(qmax), FF_OPT_TYPE_INT, 31, 1, 51, V|E},
-{"qdiff", "max difference between the quantizer scale (VBR)", OFFSET(max_qdiff), FF_OPT_TYPE_INT, 3, INT_MIN, INT_MAX, V|E},
-{"bf", "use 'frames' B frames", OFFSET(max_b_frames), FF_OPT_TYPE_INT, DEFAULT, 0, FF_MAX_B_FRAMES, V|E},
-{"b_qfactor", "qp factor between p and b frames", OFFSET(b_quant_factor), FF_OPT_TYPE_FLOAT, 1.25, FLT_MIN, 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},
-{"hurry_up", NULL, OFFSET(hurry_up), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D},
-{"rtp_mode", NULL, OFFSET(rtp_mode), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"rtp_payload_size", NULL, OFFSET(rtp_payload_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"mv_bits", NULL, OFFSET(mv_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"header_bits", NULL, OFFSET(header_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"i_tex_bits", NULL, OFFSET(i_tex_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"p_tex_bits", NULL, OFFSET(p_tex_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"i_count", NULL, OFFSET(i_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"p_count", NULL, OFFSET(p_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"skip_count", NULL, OFFSET(skip_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"misc_bits", NULL, OFFSET(misc_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"frame_bits", NULL, OFFSET(frame_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"codec_tag", NULL, OFFSET(codec_tag), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"bug", "workaround not auto detected encoder bugs", OFFSET(workaround_bugs), FF_OPT_TYPE_FLAGS, FF_BUG_AUTODETECT, INT_MIN, INT_MAX, V|D, "bug"},
-{"autodetect", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_AUTODETECT, INT_MIN, INT_MAX, V|D, "bug"},
-{"old_msmpeg4", "some old lavc generated msmpeg4v3 files (no autodetection)", 0, FF_OPT_TYPE_CONST, FF_BUG_OLD_MSMPEG4, INT_MIN, INT_MAX, V|D, "bug"},
-{"xvid_ilace", "Xvid interlacing bug (autodetected if fourcc==XVIX)", 0, FF_OPT_TYPE_CONST, FF_BUG_XVID_ILACE, INT_MIN, INT_MAX, V|D, "bug"},
-{"ump4", "(autodetected if fourcc==UMP4)", 0, FF_OPT_TYPE_CONST, FF_BUG_UMP4, INT_MIN, INT_MAX, V|D, "bug"},
-{"no_padding", "padding bug (autodetected)", 0, FF_OPT_TYPE_CONST, FF_BUG_NO_PADDING, INT_MIN, INT_MAX, V|D, "bug"},
-{"amv", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_AMV, INT_MIN, INT_MAX, V|D, "bug"},
-{"ac_vlc", "illegal vlc bug (autodetected per fourcc)", 0, FF_OPT_TYPE_CONST, FF_BUG_AC_VLC, INT_MIN, INT_MAX, V|D, "bug"},
-{"qpel_chroma", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_QPEL_CHROMA, INT_MIN, INT_MAX, V|D, "bug"},
-{"std_qpel", "old standard qpel (autodetected per fourcc/version)", 0, FF_OPT_TYPE_CONST, FF_BUG_STD_QPEL, INT_MIN, INT_MAX, V|D, "bug"},
-{"qpel_chroma2", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_QPEL_CHROMA2, INT_MIN, INT_MAX, V|D, "bug"},
-{"direct_blocksize", "direct-qpel-blocksize bug (autodetected per fourcc/version)", 0, FF_OPT_TYPE_CONST, FF_BUG_DIRECT_BLOCKSIZE, INT_MIN, INT_MAX, V|D, "bug"},
-{"edge", "edge padding bug (autodetected per fourcc/version)", 0, FF_OPT_TYPE_CONST, FF_BUG_EDGE, INT_MIN, INT_MAX, V|D, "bug"},
-{"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"},
-{"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, "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|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|E, "strict"},
-{"normal", NULL, 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_NORMAL, INT_MIN, INT_MAX, V|E, "strict"},
-{"inofficial", "allow inofficial extensions", 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_INOFFICIAL, INT_MIN, INT_MAX, V|E, "strict"},
-{"experimental", "allow non standarized experimental things", 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_EXPERIMENTAL, INT_MIN, INT_MAX, V|E, "strict"},
-{"b_qoffset", "qp offset between p and b frames", OFFSET(b_quant_offset), FF_OPT_TYPE_FLOAT, 1.25, FLT_MIN, FLT_MAX, V|E},
-{"er", "set error resilience strategy", OFFSET(error_resilience), FF_OPT_TYPE_INT, FF_ER_CAREFUL, INT_MIN, INT_MAX, A|V|D, "er"},
-{"careful", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_CAREFUL, INT_MIN, INT_MAX, V|D, "er"},
-{"compliant", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_COMPLIANT, INT_MIN, INT_MAX, V|D, "er"},
-{"aggressive", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_AGGRESSIVE, INT_MIN, INT_MAX, V|D, "er"},
-{"very_aggressive", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_VERY_AGGRESSIVE, INT_MIN, INT_MAX, V|D, "er"},
-{"has_b_frames", NULL, OFFSET(has_b_frames), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"block_align", NULL, OFFSET(block_align), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"parse_only", NULL, OFFSET(parse_only), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"mpeg_quant", "use MPEG quantizers instead of H.263", OFFSET(mpeg_quant), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"stats_out", NULL, OFFSET(stats_out), FF_OPT_TYPE_STRING, DEFAULT, CHAR_MIN, CHAR_MAX},
-{"stats_in", NULL, OFFSET(stats_in), FF_OPT_TYPE_STRING, DEFAULT, CHAR_MIN, CHAR_MAX},
-{"qsquish", "how to keep quantizer between qmin and qmax (0 = clip, 1 = use differentiable function)", OFFSET(rc_qsquish), FF_OPT_TYPE_FLOAT, DEFAULT, 0, 99, V|E},
-{"rc_qmod_amp", "experimental quantizer modulation", OFFSET(rc_qmod_amp), FF_OPT_TYPE_FLOAT, DEFAULT, -FLT_MAX, FLT_MAX, V|E},
-{"rc_qmod_freq", "experimental quantizer modulation", OFFSET(rc_qmod_freq), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"rc_override_count", NULL, OFFSET(rc_override_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"rc_eq", "set rate control equation", OFFSET(rc_eq), FF_OPT_TYPE_STRING, DEFAULT, CHAR_MIN, CHAR_MAX, V|E},
-{"maxrate", "set max video bitrate tolerance (in bits/s)", OFFSET(rc_max_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"minrate", "set min video bitrate tolerance (in bits/s)", OFFSET(rc_min_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"bufsize", "set ratecontrol buffer size (in bits)", OFFSET(rc_buffer_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"rc_buf_aggressivity", "currently useless", OFFSET(rc_buffer_aggressivity), FF_OPT_TYPE_FLOAT, 1.0, FLT_MIN, FLT_MAX, V|E},
-{"i_qfactor", "qp factor between p and i frames", OFFSET(i_quant_factor), FF_OPT_TYPE_FLOAT, -0.8, -FLT_MAX, FLT_MAX, V|E},
-{"i_qoffset", "qp offset between p and i frames", OFFSET(i_quant_offset), FF_OPT_TYPE_FLOAT, 0.0, -FLT_MAX, FLT_MAX, V|E},
-{"rc_init_cplx", "initial complexity for 1-pass encoding", OFFSET(rc_initial_cplx), FF_OPT_TYPE_FLOAT, DEFAULT, -FLT_MAX, FLT_MAX, V|E},
-{"dct", "DCT algorithm", OFFSET(dct_algo), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, V|E, "dct"},
-{"auto", "autoselect a good one (default)", 0, FF_OPT_TYPE_CONST, FF_DCT_AUTO, INT_MIN, INT_MAX, V|E, "dct"},
-{"fastint", "fast integer", 0, FF_OPT_TYPE_CONST, FF_DCT_FASTINT, INT_MIN, INT_MAX, V|E, "dct"},
-{"int", "accurate integer", 0, FF_OPT_TYPE_CONST, FF_DCT_INT, INT_MIN, INT_MAX, V|E, "dct"},
-{"mmx", NULL, 0, FF_OPT_TYPE_CONST, FF_DCT_MMX, INT_MIN, INT_MAX, V|E, "dct"},
-{"mlib", NULL, 0, FF_OPT_TYPE_CONST, FF_DCT_MLIB, INT_MIN, INT_MAX, V|E, "dct"},
-{"altivec", NULL, 0, FF_OPT_TYPE_CONST, FF_DCT_ALTIVEC, INT_MIN, INT_MAX, V|E, "dct"},
-{"faan", "floating point AAN DCT", 0, FF_OPT_TYPE_CONST, FF_DCT_FAAN, INT_MIN, INT_MAX, V|E, "dct"},
-{"lumi_mask", "compresses bright areas stronger than medium ones", OFFSET(lumi_masking), FF_OPT_TYPE_FLOAT, 0, -FLT_MAX, FLT_MAX, V|E},
-{"tcplx_mask", "temporal complexity masking", OFFSET(temporal_cplx_masking), FF_OPT_TYPE_FLOAT, 0, -FLT_MAX, FLT_MAX, V|E},
-{"scplx_mask", "spatial complexity masking", OFFSET(spatial_cplx_masking), FF_OPT_TYPE_FLOAT, 0, -FLT_MAX, FLT_MAX, V|E},
-{"p_mask", "inter masking", OFFSET(p_masking), FF_OPT_TYPE_FLOAT, 0, -FLT_MAX, FLT_MAX, V|E},
-{"dark_mask", "compresses dark areas stronger than medium ones", OFFSET(dark_masking), FF_OPT_TYPE_FLOAT, 0, -FLT_MAX, FLT_MAX, V|E},
-{"unused", NULL, OFFSET(unused), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"idct", "select IDCT implementation", OFFSET(idct_algo), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, V|E|D, "idct"},
-{"auto", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_AUTO, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"int", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_INT, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"simple", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLE, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"simplemmx", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLEMMX, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"libmpeg2mmx", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_LIBMPEG2MMX, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"ps2", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_PS2, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"mlib", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_MLIB, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"arm", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_ARM, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"altivec", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_ALTIVEC, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"sh4", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SH4, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"simplearm", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLEARM, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"simplearmv5te", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLEARMV5TE, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"h264", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_H264, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"vp3", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_VP3, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"ipp", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_IPP, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"xvidmmx", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_XVIDMMX, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"slice_count", NULL, OFFSET(slice_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"ec", "set error concealment strategy", OFFSET(error_concealment), FF_OPT_TYPE_FLAGS, 3, INT_MIN, INT_MAX, V|D, "ec"},
-{"guess_mvs", "iterative motion vector (MV) search (slow)", 0, FF_OPT_TYPE_CONST, FF_EC_GUESS_MVS, INT_MIN, INT_MAX, V|D, "ec"},
-{"deblock", "use strong deblock filter for damaged MBs", 0, FF_OPT_TYPE_CONST, FF_EC_DEBLOCK, INT_MIN, INT_MAX, V|D, "ec"},
-{"bits_per_sample", NULL, OFFSET(bits_per_sample), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"pred", "prediction method", OFFSET(prediction_method), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "pred"},
-{"left", NULL, 0, FF_OPT_TYPE_CONST, FF_PRED_LEFT, INT_MIN, INT_MAX, V|E, "pred"},
-{"plane", NULL, 0, FF_OPT_TYPE_CONST, FF_PRED_PLANE, INT_MIN, INT_MAX, V|E, "pred"},
-{"median", NULL, 0, FF_OPT_TYPE_CONST, FF_PRED_MEDIAN, INT_MIN, INT_MAX, V|E, "pred"},
-{"aspect", "sample aspect ratio", OFFSET(sample_aspect_ratio), FF_OPT_TYPE_RATIONAL, DEFAULT, 0, 10, V|E},
-{"debug", "print specific debug info", OFFSET(debug), FF_OPT_TYPE_FLAGS, DEFAULT, 0, INT_MAX, V|A|S|E|D, "debug"},
-{"pict", "picture info", 0, FF_OPT_TYPE_CONST, FF_DEBUG_PICT_INFO, INT_MIN, INT_MAX, V|D, "debug"},
-{"rc", "rate control", 0, FF_OPT_TYPE_CONST, FF_DEBUG_RC, INT_MIN, INT_MAX, V|E, "debug"},
-{"bitstream", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_BITSTREAM, INT_MIN, INT_MAX, V|D, "debug"},
-{"mb_type", "macroblock (MB) type", 0, FF_OPT_TYPE_CONST, FF_DEBUG_MB_TYPE, INT_MIN, INT_MAX, V|D, "debug"},
-{"qp", "per-block quantization parameter (QP)", 0, FF_OPT_TYPE_CONST, FF_DEBUG_QP, INT_MIN, INT_MAX, V|D, "debug"},
-{"mv", "motion vector", 0, FF_OPT_TYPE_CONST, FF_DEBUG_MV, INT_MIN, INT_MAX, V|D, "debug"},
-{"dct_coeff", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_DCT_COEFF, INT_MIN, INT_MAX, V|D, "debug"},
-{"skip", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_SKIP, INT_MIN, INT_MAX, V|D, "debug"},
-{"startcode", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_STARTCODE, INT_MIN, INT_MAX, V|D, "debug"},
-{"pts", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_PTS, INT_MIN, INT_MAX, V|D, "debug"},
-{"er", "error resilience", 0, FF_OPT_TYPE_CONST, FF_DEBUG_ER, INT_MIN, INT_MAX, V|D, "debug"},
-{"mmco", "memory management control operations (H.264)", 0, FF_OPT_TYPE_CONST, FF_DEBUG_MMCO, INT_MIN, INT_MAX, V|D, "debug"},
-{"bugs", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_BUGS, INT_MIN, INT_MAX, V|D, "debug"},
-{"vis_qp", "visualize quantization parameter (QP), lower QP are tinted greener", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_QP, INT_MIN, INT_MAX, V|D, "debug"},
-{"vis_mb_type", "visualize block types", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MB_TYPE, INT_MIN, INT_MAX, V|D, "debug"},
-{"vismv", "visualize motion vectors (MVs)", OFFSET(debug_mv), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, V|D, "debug_mv"},
-{"pf", "forward predicted MVs of P-frames", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MV_P_FOR, INT_MIN, INT_MAX, V|D, "debug_mv"},
-{"bf", "forward predicted MVs of B-frames", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MV_B_FOR, INT_MIN, INT_MAX, V|D, "debug_mv"},
-{"bb", "backward predicted MVs of B-frames", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MV_B_BACK, INT_MIN, INT_MAX, V|D, "debug_mv"},
-{"mb_qmin", "obsolete, use qmin", OFFSET(mb_qmin), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"mb_qmax", "obsolete, use qmax", OFFSET(mb_qmax), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"cmp", "full pel me compare function", OFFSET(me_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"subcmp", "sub pel me compare function", OFFSET(me_sub_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"mbcmp", "macroblock compare function", OFFSET(mb_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"ildctcmp", "interlaced dct compare function", OFFSET(ildct_cmp), FF_OPT_TYPE_INT, FF_CMP_VSAD, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"dia_size", "diamond type & size for motion estimation", OFFSET(dia_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"last_pred", "amount of motion predictors from the previous frame", OFFSET(last_predictor_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"preme", "pre motion estimation", OFFSET(pre_me), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"precmp", "pre motion estimation compare function", OFFSET(me_pre_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"sad", "sum of absolute differences, fast (default)", 0, FF_OPT_TYPE_CONST, FF_CMP_SAD, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"sse", "sum of squared errors", 0, FF_OPT_TYPE_CONST, FF_CMP_SSE, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"satd", "sum of absolute Hadamard transformed differences", 0, FF_OPT_TYPE_CONST, FF_CMP_SATD, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"dct", "sum of absolute DCT transformed differences", 0, FF_OPT_TYPE_CONST, FF_CMP_DCT, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"psnr", "sum of squared quantization errors (avoid, low quality)", 0, FF_OPT_TYPE_CONST, FF_CMP_PSNR, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"bit", "number of bits needed for the block", 0, FF_OPT_TYPE_CONST, FF_CMP_BIT, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"rd", "rate distortion optimal, slow", 0, FF_OPT_TYPE_CONST, FF_CMP_RD, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"zero", "0", 0, FF_OPT_TYPE_CONST, FF_CMP_ZERO, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"vsad", "sum of absolute vertical differences", 0, FF_OPT_TYPE_CONST, FF_CMP_VSAD, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"vsse","sum of squared vertical differences", 0, FF_OPT_TYPE_CONST, FF_CMP_VSSE, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"nsse", "noise preserving sum of squared differences", 0, FF_OPT_TYPE_CONST, FF_CMP_NSSE, INT_MIN, INT_MAX, V|E, "cmp_func"},
-#ifdef CONFIG_SNOW_ENCODER
-{"w53", "5/3 wavelet, only used in snow", 0, FF_OPT_TYPE_CONST, FF_CMP_W53, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"w97", "9/7 wavelet, only used in snow", 0, FF_OPT_TYPE_CONST, FF_CMP_W97, INT_MIN, INT_MAX, V|E, "cmp_func"},
-#endif
-{"dctmax", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_DCTMAX, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"chroma", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_CHROMA, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"pre_dia_size", "diamond type & size for motion estimation pre-pass", OFFSET(pre_dia_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"subq", "sub pel motion estimation quality", OFFSET(me_subpel_quality), FF_OPT_TYPE_INT, 8, INT_MIN, INT_MAX, V|E},
-{"dtg_active_format", NULL, OFFSET(dtg_active_format), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"me_range", "limit motion vectors range (1023 for DivX player)", OFFSET(me_range), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"ibias", "intra quant bias", OFFSET(intra_quant_bias), FF_OPT_TYPE_INT, FF_DEFAULT_QUANT_BIAS, INT_MIN, INT_MAX, V|E},
-{"pbias", "inter quant bias", OFFSET(inter_quant_bias), FF_OPT_TYPE_INT, FF_DEFAULT_QUANT_BIAS, INT_MIN, INT_MAX, V|E},
-{"color_table_id", NULL, OFFSET(color_table_id), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"internal_buffer_count", NULL, OFFSET(internal_buffer_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"global_quality", NULL, OFFSET(global_quality), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"coder", NULL, OFFSET(coder_type), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "coder"},
-{"vlc", "variable length coder / huffman coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_VLC, INT_MIN, INT_MAX, V|E, "coder"},
-{"ac", "arithmetic coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_AC, INT_MIN, INT_MAX, V|E, "coder"},
-{"context", "context model", OFFSET(context_model), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"slice_flags", NULL, OFFSET(slice_flags), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"xvmc_acceleration", NULL, OFFSET(xvmc_acceleration), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"mbd", "macroblock decision algorithm (high quality mode)", OFFSET(mb_decision), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "mbd"},
-{"simple", "use mbcmp (default)", 0, FF_OPT_TYPE_CONST, FF_MB_DECISION_SIMPLE, INT_MIN, INT_MAX, V|E, "mbd"},
-{"bits", "use fewest bits", 0, FF_OPT_TYPE_CONST, FF_MB_DECISION_BITS, INT_MIN, INT_MAX, V|E, "mbd"},
-{"rd", "use best rate distortion", 0, FF_OPT_TYPE_CONST, FF_MB_DECISION_RD, INT_MIN, INT_MAX, V|E, "mbd"},
-{"stream_codec_tag", NULL, OFFSET(stream_codec_tag), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"sc_threshold", "scene change threshold", OFFSET(scenechange_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"lmin", "min lagrange factor (VBR)", OFFSET(lmin), FF_OPT_TYPE_INT, 2*FF_QP2LAMBDA, 0, INT_MAX, V|E},
-{"lmax", "max lagrange factor (VBR)", OFFSET(lmax), FF_OPT_TYPE_INT, 31*FF_QP2LAMBDA, 0, INT_MAX, V|E},
-{"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, INT_MIN, INT_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"},
-{"fastint", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_FASTINT, INT_MIN, INT_MAX, V|D, "aa"},
-{"int", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_INT, INT_MIN, INT_MAX, V|D, "aa"},
-{"float", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_FLOAT, INT_MIN, INT_MAX, V|D, "aa"},
-{"qns", "quantizer noise shaping", OFFSET(quantizer_noise_shaping), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"threads", NULL, OFFSET(thread_count), FF_OPT_TYPE_INT, 1, INT_MIN, INT_MAX, V|E|D},
-{"me_threshold", "motion estimaton threshold", OFFSET(me_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"mb_threshold", "macroblock threshold", OFFSET(mb_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"dc", "intra_dc_precision", OFFSET(intra_dc_precision), FF_OPT_TYPE_INT, 0, INT_MIN, INT_MAX, V|E},
-{"nssew", "nsse weight", OFFSET(nsse_weight), FF_OPT_TYPE_INT, 8, INT_MIN, INT_MAX, V|E},
-{"skip_top", "number of macroblock rows at the top which are skipped", OFFSET(skip_top), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D},
-{"skip_bottom", "number of macroblock rows at the bottom which are skipped", OFFSET(skip_bottom), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D},
-{"profile", NULL, OFFSET(profile), FF_OPT_TYPE_INT, FF_PROFILE_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "profile"},
-{"unknown", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "profile"},
-{"level", NULL, OFFSET(level), FF_OPT_TYPE_INT, FF_LEVEL_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "level"},
-{"unknown", NULL, 0, FF_OPT_TYPE_CONST, FF_LEVEL_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "level"},
-{"lowres", "decode at 1= 1/2, 2=1/4, 3=1/8 resolutions", OFFSET(lowres), FF_OPT_TYPE_INT, 0, 0, INT_MAX, V|D},
-{"skip_threshold", "frame skip threshold", OFFSET(frame_skip_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"skip_factor", "frame skip factor", OFFSET(frame_skip_factor), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"skip_exp", "frame skip exponent", OFFSET(frame_skip_exp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"skipcmp", "frame skip compare function", OFFSET(frame_skip_cmp), FF_OPT_TYPE_INT, FF_CMP_DCTMAX, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"border_mask", "increases the quantizer for macroblocks close to borders", OFFSET(border_masking), FF_OPT_TYPE_FLOAT, DEFAULT, -FLT_MAX, FLT_MAX, V|E},
-{"mblmin", "min macroblock lagrange factor (VBR)", OFFSET(mb_lmin), FF_OPT_TYPE_INT, FF_QP2LAMBDA * 2, 1, FF_LAMBDA_MAX, V|E},
-{"mblmax", "max macroblock lagrange factor (VBR)", OFFSET(mb_lmax), FF_OPT_TYPE_INT, FF_QP2LAMBDA * 31, 1, FF_LAMBDA_MAX, V|E},
-{"mepc", "motion estimation bitrate penalty compensation (1.0 = 256)", OFFSET(me_penalty_compensation), FF_OPT_TYPE_INT, 256, INT_MIN, INT_MAX, V|E},
-{"bidir_refine", "refine the two motion vectors used in bidirectional macroblocks", OFFSET(bidir_refine), FF_OPT_TYPE_INT, DEFAULT, 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},
-{"keyint_min", "minimum interval between IDR-frames (x264)", OFFSET(keyint_min), FF_OPT_TYPE_INT, 25, INT_MIN, INT_MAX, V|E},
-{"refs", "reference frames to consider for motion compensation (Snow)", OFFSET(refs), FF_OPT_TYPE_INT, 1, INT_MIN, INT_MAX, V|E},
-{"chromaoffset", "chroma qp offset from luma", OFFSET(chromaoffset), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"bframebias", "influences how often B-frames are used", OFFSET(bframebias), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"trellis", "rate-distortion optimal quantization", OFFSET(trellis), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|A|E},
-{"directpred", "direct mv prediction mode - 0 (none), 1 (spatial), 2 (temporal)", OFFSET(directpred), FF_OPT_TYPE_INT, 2, INT_MIN, INT_MAX, V|E},
-{"bpyramid", "allows B-frames to be used as references for predicting", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_BPYRAMID, INT_MIN, INT_MAX, V|E, "flags2"},
-{"wpred", "weighted biprediction for b-frames (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_WPRED, INT_MIN, INT_MAX, V|E, "flags2"},
-{"mixed_refs", "one reference per partition, as opposed to one reference per macroblock", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_MIXED_REFS, INT_MIN, INT_MAX, V|E, "flags2"},
-{"8x8dct", "high profile 8x8 transform (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_8X8DCT, INT_MIN, INT_MAX, V|E, "flags2"},
-{"fastpskip", "fast pskip (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_FASTPSKIP, INT_MIN, INT_MAX, V|E, "flags2"},
-{"aud", "access unit delimiters (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_AUD, INT_MIN, INT_MAX, V|E, "flags2"},
-{"brdo", "b-frame rate-distortion optimization", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_BRDO, INT_MIN, INT_MAX, V|E, "flags2"},
-{"skiprd", "RD optimal MB level residual skiping", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_SKIP_RD, INT_MIN, INT_MAX, V|E, "flags2"},
-{"complexityblur", "reduce fluctuations in qp (before curve compression)", OFFSET(complexityblur), FF_OPT_TYPE_FLOAT, 20.0, FLT_MIN, FLT_MAX, V|E},
-{"deblockalpha", "in-loop deblocking filter alphac0 parameter", OFFSET(deblockalpha), FF_OPT_TYPE_INT, DEFAULT, -6, 6, V|E},
-{"deblockbeta", "in-loop deblocking filter beta parameter", OFFSET(deblockbeta), FF_OPT_TYPE_INT, DEFAULT, -6, 6, V|E},
-{"partitions", "macroblock subpartition sizes to consider", OFFSET(partitions), FF_OPT_TYPE_FLAGS, DEFAULT, INT_MIN, INT_MAX, V|E, "partitions"},
-{"parti4x4", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_I4X4, INT_MIN, INT_MAX, V|E, "partitions"},
-{"parti8x8", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_I8X8, INT_MIN, INT_MAX, V|E, "partitions"},
-{"partp4x4", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_P4X4, INT_MIN, INT_MAX, V|E, "partitions"},
-{"partp8x8", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_P8X8, INT_MIN, INT_MAX, V|E, "partitions"},
-{"partb8x8", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_B8X8, INT_MIN, INT_MAX, V|E, "partitions"},
-{"sc_factor", "multiplied by qscale for each frame and added to scene_change_score", OFFSET(scenechange_factor), FF_OPT_TYPE_INT, 6, 0, INT_MAX, V|E},
-{"mv0_threshold", NULL, OFFSET(mv0_threshold), FF_OPT_TYPE_INT, 256, 0, INT_MAX, V|E},
-{"ivlc", "intra vlc table", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_INTRA_VLC, INT_MIN, INT_MAX, V|E, "flags2"},
-{"b_sensitivity", "adjusts sensitivity of b_frame_strategy 1", OFFSET(b_sensitivity), FF_OPT_TYPE_INT, 40, 1, INT_MAX, V|E},
-{"compression_level", NULL, OFFSET(compression_level), FF_OPT_TYPE_INT, FF_COMPRESSION_DEFAULT, INT_MIN, INT_MAX, V|A|E},
-{"use_lpc", "sets whether to use LPC mode (FLAC)", OFFSET(use_lpc), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
-{"lpc_coeff_precision", "LPC coefficient precision (FLAC)", OFFSET(lpc_coeff_precision), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, A|E},
-{"min_prediction_order", NULL, OFFSET(min_prediction_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
-{"max_prediction_order", NULL, OFFSET(max_prediction_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
-{"prediction_order_method", "search method for selecting prediction order", OFFSET(prediction_order_method), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
-{"min_partition_order", NULL, OFFSET(min_partition_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
-{"max_partition_order", NULL, OFFSET(max_partition_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
-{"timecode_frame_start", "GOP timecode frame start number, in non drop frame format", OFFSET(timecode_frame_start), FF_OPT_TYPE_INT, 0, 0, INT_MAX, V|E},
-{"drop_frame_timecode", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_DROP_FRAME_TIMECODE, INT_MIN, INT_MAX, V|E, "flags2"},
-{NULL},
-};
-
-#undef A
-#undef V
-#undef S
-#undef E
-#undef D
-#undef DEFAULT
-
-static AVClass av_codec_context_class = { "AVCodecContext", context_to_name, options };
-
-void avcodec_get_context_defaults(AVCodecContext *s){
- memset(s, 0, sizeof(AVCodecContext));
-
- s->av_class= &av_codec_context_class;
-
- av_opt_set_defaults(s);
-
- s->rc_eq= "tex^qComp";
- s->time_base= (AVRational){0,1};
- s->get_buffer= avcodec_default_get_buffer;
- s->release_buffer= avcodec_default_release_buffer;
- s->get_format= avcodec_default_get_format;
- s->execute= avcodec_default_execute;
- s->sample_aspect_ratio= (AVRational){0,1};
- s->pix_fmt= PIX_FMT_NONE;
- s->sample_fmt= SAMPLE_FMT_S16; // FIXME: set to NONE
-
- s->palctrl = NULL;
- s->reget_buffer= avcodec_default_reget_buffer;
-}
-
-/**
- * allocates a AVCodecContext and set it to defaults.
- * this can be deallocated by simply calling free()
- */
-AVCodecContext *avcodec_alloc_context(void){
- AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));
-
- if(avctx==NULL) return NULL;
-
- avcodec_get_context_defaults(avctx);
-
- return avctx;
-}
-
-void avcodec_get_frame_defaults(AVFrame *pic){
- memset(pic, 0, sizeof(AVFrame));
-
- pic->pts= AV_NOPTS_VALUE;
- pic->key_frame= 1;
-}
-
-/**
- * allocates a AVPFrame and set it to defaults.
- * this can be deallocated by simply calling free()
- */
-AVFrame *avcodec_alloc_frame(void){
- AVFrame *pic= av_malloc(sizeof(AVFrame));
-
- if(pic==NULL) return NULL;
-
- avcodec_get_frame_defaults(pic);
-
- return pic;
-}
-
-int avcodec_open(AVCodecContext *avctx, AVCodec *codec)
-{
- int ret= -1;
-
- entangled_thread_counter++;
- if(entangled_thread_counter != 1){
- av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
- goto end;
- }
-
- if(avctx->codec)
- goto end;
-
- if (codec->priv_data_size > 0) {
- avctx->priv_data = av_mallocz(codec->priv_data_size);
- if (!avctx->priv_data)
- goto end;
- } else {
- avctx->priv_data = NULL;
- }
-
- if(avctx->coded_width && avctx->coded_height)
- avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
- else if(avctx->width && 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);
- goto end;
- }
-
- avctx->codec = codec;
- avctx->codec_id = codec->id;
- avctx->frame_number = 0;
- ret = avctx->codec->init(avctx);
- if (ret < 0) {
- av_freep(&avctx->priv_data);
- avctx->codec= NULL;
- goto end;
- }
- ret=0;
-end:
- entangled_thread_counter--;
- return ret;
-}
-
-int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
- const short *samples)
-{
- if(buf_size < FF_MIN_BUFFER_SIZE && 0){
- av_log(avctx, AV_LOG_ERROR, "buffer smaller then minimum size\n");
- return -1;
- }
- if((avctx->codec->capabilities & CODEC_CAP_DELAY) || samples){
- int ret = avctx->codec->encode(avctx, buf, buf_size, (void *)samples);
- avctx->frame_number++;
- return ret;
- }else
- return 0;
-}
-
-int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
- const AVFrame *pict)
-{
- if(buf_size < FF_MIN_BUFFER_SIZE){
- av_log(avctx, AV_LOG_ERROR, "buffer smaller then minimum size\n");
- return -1;
- }
- if(avcodec_check_dimensions(avctx,avctx->width,avctx->height))
- return -1;
- if((avctx->codec->capabilities & CODEC_CAP_DELAY) || pict){
- int ret = avctx->codec->encode(avctx, buf, buf_size, (void *)pict);
- avctx->frame_number++;
- emms_c(); //needed to avoid an emms_c() call before every return;
-
- return ret;
- }else
- return 0;
-}
-
-int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
- const AVSubtitle *sub)
-{
- int ret;
- ret = avctx->codec->encode(avctx, buf, buf_size, (void *)sub);
- avctx->frame_number++;
- return ret;
-}
-
-/**
- * decode a frame.
- * @param buf bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE larger then the actual read bytes
- * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end
- * @param buf_size the size of the buffer in bytes
- * @param got_picture_ptr zero if no frame could be decompressed, Otherwise, it is non zero
- * @return -1 if error, otherwise return the number of
- * bytes used.
- */
-int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
- int *got_picture_ptr,
- uint8_t *buf, int buf_size)
-{
- int ret;
-
- *got_picture_ptr= 0;
- if((avctx->coded_width||avctx->coded_height) && avcodec_check_dimensions(avctx,avctx->coded_width,avctx->coded_height))
- return -1;
- if((avctx->codec->capabilities & CODEC_CAP_DELAY) || buf_size){
- ret = avctx->codec->decode(avctx, picture, got_picture_ptr,
- buf, buf_size);
-
- emms_c(); //needed to avoid an emms_c() call before every return;
-
- if (*got_picture_ptr)
- avctx->frame_number++;
- }else
- ret= 0;
-
- return ret;
-}
-
-/* decode an audio frame. return -1 if error, otherwise return the
- *number of bytes used. If no frame could be decompressed,
- *frame_size_ptr is zero. Otherwise, it is the decompressed frame
- *size in BYTES. */
-int avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples,
- int *frame_size_ptr,
- uint8_t *buf, int buf_size)
-{
- int ret;
-
- //FIXME remove the check below _after_ ensuring that all audio check that the available space is enough
- if(*frame_size_ptr < AVCODEC_MAX_AUDIO_FRAME_SIZE){
- av_log(avctx, AV_LOG_ERROR, "buffer smaller then AVCODEC_MAX_AUDIO_FRAME_SIZE\n");
- return -1;
- }
- if(*frame_size_ptr < FF_MIN_BUFFER_SIZE ||
- *frame_size_ptr < avctx->channels * avctx->frame_size * sizeof(int16_t) ||
- *frame_size_ptr < buf_size){
- av_log(avctx, AV_LOG_ERROR, "buffer too small\n");
- return -1;
- }
- if((avctx->codec->capabilities & CODEC_CAP_DELAY) || buf_size){
- ret = avctx->codec->decode(avctx, samples, frame_size_ptr,
- buf, buf_size);
- avctx->frame_number++;
- }else{
- ret= 0;
- *frame_size_ptr=0;
- }
- return ret;
-}
-
-#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
-int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples,
- int *frame_size_ptr,
- uint8_t *buf, int buf_size){
- *frame_size_ptr= AVCODEC_MAX_AUDIO_FRAME_SIZE;
- return avcodec_decode_audio2(avctx, samples, frame_size_ptr, buf, buf_size);
-}
-#endif
-
-
-/* decode a subtitle message. return -1 if error, otherwise return the
- *number of bytes used. If no subtitle could be decompressed,
- *got_sub_ptr is zero. Otherwise, the subtitle is stored in *sub. */
-int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub,
- int *got_sub_ptr,
- const uint8_t *buf, int buf_size)
-{
- int ret;
-
- *got_sub_ptr = 0;
- ret = avctx->codec->decode(avctx, sub, got_sub_ptr,
- (uint8_t *)buf, buf_size);
- if (*got_sub_ptr)
- avctx->frame_number++;
- return ret;
-}
-
-int avcodec_close(AVCodecContext *avctx)
-{
- entangled_thread_counter++;
- if(entangled_thread_counter != 1){
- av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
- entangled_thread_counter--;
- return -1;
- }
-
- if (avctx->codec->close)
- avctx->codec->close(avctx);
- avcodec_default_free_buffers(avctx);
- av_freep(&avctx->priv_data);
- avctx->codec = NULL;
- entangled_thread_counter--;
- return 0;
-}
-
-AVCodec *avcodec_find_encoder(enum CodecID id)
-{
- AVCodec *p;
- p = first_avcodec;
- while (p) {
- if (p->encode != NULL && p->id == id)
- return p;
- p = p->next;
- }
- return NULL;
-}
-
-AVCodec *avcodec_find_encoder_by_name(const char *name)
-{
- AVCodec *p;
- p = first_avcodec;
- while (p) {
- if (p->encode != NULL && strcmp(name,p->name) == 0)
- return p;
- p = p->next;
- }
- return NULL;
-}
-
-AVCodec *avcodec_find_decoder(enum CodecID id)
-{
- AVCodec *p;
- p = first_avcodec;
- while (p) {
- if (p->decode != NULL && p->id == id)
- return p;
- p = p->next;
- }
- return NULL;
-}
-
-AVCodec *avcodec_find_decoder_by_name(const char *name)
-{
- AVCodec *p;
- p = first_avcodec;
- while (p) {
- if (p->decode != NULL && strcmp(name,p->name) == 0)
- return p;
- p = p->next;
- }
- return NULL;
-}
-
-void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
-{
- const char *codec_name;
- AVCodec *p;
- char buf1[32];
- char channels_str[100];
- int bitrate;
-
- if (encode)
- p = avcodec_find_encoder(enc->codec_id);
- else
- p = avcodec_find_decoder(enc->codec_id);
-
- if (p) {
- codec_name = p->name;
- if (!encode && enc->codec_id == CODEC_ID_MP3) {
- if (enc->sub_id == 2)
- codec_name = "mp2";
- else if (enc->sub_id == 1)
- codec_name = "mp1";
- }
- } else if (enc->codec_id == CODEC_ID_MPEG2TS) {
- /* fake mpeg2 transport stream codec (currently not
- registered) */
- codec_name = "mpeg2ts";
- } else if (enc->codec_name[0] != '\0') {
- codec_name = enc->codec_name;
- } else {
- /* output avi tags */
- if( isprint(enc->codec_tag&0xFF) && isprint((enc->codec_tag>>8)&0xFF)
- && isprint((enc->codec_tag>>16)&0xFF) && isprint((enc->codec_tag>>24)&0xFF)){
- snprintf(buf1, sizeof(buf1), "%c%c%c%c / 0x%04X",
- enc->codec_tag & 0xff,
- (enc->codec_tag >> 8) & 0xff,
- (enc->codec_tag >> 16) & 0xff,
- (enc->codec_tag >> 24) & 0xff,
- enc->codec_tag);
- } else {
- snprintf(buf1, sizeof(buf1), "0x%04x", enc->codec_tag);
- }
- codec_name = buf1;
- }
-
- switch(enc->codec_type) {
- case CODEC_TYPE_VIDEO:
- snprintf(buf, buf_size,
- "Video: %s%s",
- codec_name, enc->mb_decision ? " (hq)" : "");
- if (enc->pix_fmt != PIX_FMT_NONE) {
- snprintf(buf + strlen(buf), buf_size - strlen(buf),
- ", %s",
- avcodec_get_pix_fmt_name(enc->pix_fmt));
- }
- if (enc->width) {
- snprintf(buf + strlen(buf), buf_size - strlen(buf),
- ", %dx%d",
- enc->width, enc->height);
- if(av_log_get_level() >= AV_LOG_DEBUG){
- int g= ff_gcd(enc->time_base.num, enc->time_base.den);
- snprintf(buf + strlen(buf), buf_size - strlen(buf),
- ", %d/%d",
- enc->time_base.num/g, enc->time_base.den/g);
- }
- }
- if (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:
- snprintf(buf, buf_size,
- "Audio: %s",
- codec_name);
- switch (enc->channels) {
- case 1:
- strcpy(channels_str, "mono");
- break;
- case 2:
- strcpy(channels_str, "stereo");
- break;
- case 6:
- strcpy(channels_str, "5:1");
- break;
- default:
- snprintf(channels_str, sizeof(channels_str), "%d channels", enc->channels);
- break;
- }
- if (enc->sample_rate) {
- snprintf(buf + strlen(buf), buf_size - strlen(buf),
- ", %d Hz, %s",
- enc->sample_rate,
- channels_str);
- }
-
- /* for PCM codecs, compute bitrate directly */
- switch(enc->codec_id) {
- case CODEC_ID_PCM_S32LE:
- case CODEC_ID_PCM_S32BE:
- case CODEC_ID_PCM_U32LE:
- case CODEC_ID_PCM_U32BE:
- 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_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:
- bitrate = enc->sample_rate * enc->channels * 8;
- break;
- default:
- bitrate = enc->bit_rate;
- break;
- }
- break;
- case CODEC_TYPE_DATA:
- snprintf(buf, buf_size, "Data: %s", codec_name);
- bitrate = enc->bit_rate;
- break;
- case CODEC_TYPE_SUBTITLE:
- snprintf(buf, buf_size, "Subtitle: %s", codec_name);
- bitrate = enc->bit_rate;
- break;
- default:
- snprintf(buf, buf_size, "Invalid Codec type %d", enc->codec_type);
- return;
- }
- if (encode) {
- if (enc->flags & CODEC_FLAG_PASS1)
- snprintf(buf + strlen(buf), buf_size - strlen(buf),
- ", pass 1");
- if (enc->flags & CODEC_FLAG_PASS2)
- snprintf(buf + strlen(buf), buf_size - strlen(buf),
- ", pass 2");
- }
- if (bitrate != 0) {
- snprintf(buf + strlen(buf), buf_size - strlen(buf),
- ", %d kb/s", bitrate / 1000);
- }
-}
-
-unsigned avcodec_version( void )
-{
- return LIBAVCODEC_VERSION_INT;
-}
-
-unsigned avcodec_build( void )
-{
- return LIBAVCODEC_BUILD;
-}
-
-static void init_crcs(void){
- av_crc04C11DB7= av_mallocz_static(sizeof(AVCRC) * 257);
- av_crc8005 = av_mallocz_static(sizeof(AVCRC) * 257);
- av_crc07 = av_mallocz_static(sizeof(AVCRC) * 257);
- av_crc_init(av_crc04C11DB7, 0, 32, 0x04c11db7, sizeof(AVCRC)*257);
- av_crc_init(av_crc8005 , 0, 16, 0x8005 , sizeof(AVCRC)*257);
- av_crc_init(av_crc07 , 0, 8, 0x07 , sizeof(AVCRC)*257);
-}
-
-/* must be called before any other functions */
-void avcodec_init(void)
-{
- static int inited = 0;
-
- if (inited != 0)
- return;
- inited = 1;
-
- dsputil_static_init();
- init_crcs();
-}
-
-/**
- * Flush buffers, should be called when seeking or when swicthing to a different stream.
- */
-void avcodec_flush_buffers(AVCodecContext *avctx)
-{
- if(avctx->codec->flush)
- avctx->codec->flush(avctx);
-}
-
-void avcodec_default_free_buffers(AVCodecContext *s){
- int i, j;
-
- if(s->internal_buffer==NULL) return;
-
- for(i=0; i<INTERNAL_BUFFER_SIZE; i++){
- InternalBuffer *buf= &((InternalBuffer*)s->internal_buffer)[i];
- for(j=0; j<4; j++){
- av_freep(&buf->base[j]);
- buf->data[j]= NULL;
- }
- }
- av_freep(&s->internal_buffer);
-
- s->internal_buffer_count=0;
-}
-
-char av_get_pict_type_char(int pict_type){
- switch(pict_type){
- case I_TYPE: return 'I';
- case P_TYPE: return 'P';
- case B_TYPE: return 'B';
- case S_TYPE: return 'S';
- case SI_TYPE:return 'i';
- case SP_TYPE:return 'p';
- default: return '?';
- }
-}
-
-int av_get_bits_per_sample(enum CodecID codec_id){
- switch(codec_id){
- case CODEC_ID_ADPCM_SBPRO_2:
- return 2;
- case CODEC_ID_ADPCM_SBPRO_3:
- return 3;
- case CODEC_ID_ADPCM_SBPRO_4:
- case CODEC_ID_ADPCM_CT:
- return 4;
- case CODEC_ID_PCM_ALAW:
- case CODEC_ID_PCM_MULAW:
- case CODEC_ID_PCM_S8:
- case CODEC_ID_PCM_U8:
- return 8;
- case CODEC_ID_PCM_S16BE:
- case CODEC_ID_PCM_S16LE:
- case CODEC_ID_PCM_U16BE:
- case CODEC_ID_PCM_U16LE:
- return 16;
- case CODEC_ID_PCM_S24DAUD:
- case CODEC_ID_PCM_S24BE:
- case CODEC_ID_PCM_S24LE:
- case CODEC_ID_PCM_U24BE:
- case CODEC_ID_PCM_U24LE:
- return 24;
- case CODEC_ID_PCM_S32BE:
- case CODEC_ID_PCM_S32LE:
- case CODEC_ID_PCM_U32BE:
- case CODEC_ID_PCM_U32LE:
- return 32;
- default:
- return 0;
- }
-}
-
-#if !defined(HAVE_THREADS)
-int avcodec_thread_init(AVCodecContext *s, int thread_count){
- return -1;
-}
-#endif
-
-unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
-{
- unsigned int n = 0;
-
- while(v >= 0xff) {
- *s++ = 0xff;
- v -= 0xff;
- n++;
- }
- *s = v;
- n++;
- return n;
-}
-
-/* Wrapper to work around the lack of mkstemp() on mingw/cygin.
- * Also, tries to create file in /tmp first, if possible.
- * *prefix can be a character constant; *filename will be allocated internally.
- * Returns file descriptor of opened file (or -1 on error)
- * and opened file name in **filename. */
-int av_tempfile(char *prefix, char **filename) {
- int fd=-1;
-#ifdef __MINGW32__
- *filename = tempnam(".", prefix);
-#else
- size_t len = strlen(prefix) + 12; /* room for "/tmp/" and "XXXXXX\0" */
- *filename = av_malloc(len);
-#endif
- /* -----common section-----*/
- if (*filename == NULL) {
- av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot allocate file name\n");
- return -1;
- }
-#ifdef __MINGW32__
- fd = open(*filename, _O_RDWR | _O_BINARY | _O_CREAT, 0444);
-#else
- snprintf(*filename, len, "/tmp/%sXXXXXX", prefix);
- fd = mkstemp(*filename);
- if (fd < 0) {
- snprintf(*filename, len, "./%sXXXXXX", prefix);
- fd = mkstemp(*filename);
- }
-#endif
- /* -----common section-----*/
- if (fd < 0) {
- av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot open temporary file %s\n", *filename);
- return -1;
- }
- return fd; /* success */
-}
diff --git a/src/libffmpeg/libavcodec/vc1.c b/src/libffmpeg/libavcodec/vc1.c
deleted file mode 100644
index 40b79b326..000000000
--- a/src/libffmpeg/libavcodec/vc1.c
+++ /dev/null
@@ -1,4390 +0,0 @@
-/*
- * VC-1 and WMV3 decoder
- * Copyright (c) 2006 Konstantin Shishkov
- * Partly based on vc9.c (c) 2005 Anonymous, Alex Beregszaszi, 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 vc1.c
- * VC-1 and WMV3 decoder
- *
- */
-#include "common.h"
-#include "dsputil.h"
-#include "avcodec.h"
-#include "mpegvideo.h"
-#include "vc1data.h"
-#include "vc1acdata.h"
-
-#undef NDEBUG
-#include <assert.h>
-
-extern const uint32_t ff_table0_dc_lum[120][2], ff_table1_dc_lum[120][2];
-extern const uint32_t ff_table0_dc_chroma[120][2], ff_table1_dc_chroma[120][2];
-extern VLC ff_msmp4_dc_luma_vlc[2], ff_msmp4_dc_chroma_vlc[2];
-#define MB_INTRA_VLC_BITS 9
-extern VLC ff_msmp4_mb_i_vlc;
-extern const uint16_t ff_msmp4_mb_i_table[64][2];
-#define DC_VLC_BITS 9
-#define AC_VLC_BITS 9
-static const uint16_t table_mb_intra[64][2];
-
-
-/** Available Profiles */
-//@{
-enum Profile {
- PROFILE_SIMPLE,
- PROFILE_MAIN,
- PROFILE_COMPLEX, ///< TODO: WMV9 specific
- PROFILE_ADVANCED
-};
-//@}
-
-/** Sequence quantizer mode */
-//@{
-enum QuantMode {
- QUANT_FRAME_IMPLICIT, ///< Implicitly specified at frame level
- QUANT_FRAME_EXPLICIT, ///< Explicitly specified at frame level
- QUANT_NON_UNIFORM, ///< Non-uniform quant used for all frames
- QUANT_UNIFORM ///< Uniform quant used for all frames
-};
-//@}
-
-/** Where quant can be changed */
-//@{
-enum DQProfile {
- DQPROFILE_FOUR_EDGES,
- DQPROFILE_DOUBLE_EDGES,
- DQPROFILE_SINGLE_EDGE,
- DQPROFILE_ALL_MBS
-};
-//@}
-
-/** @name Where quant can be changed
- */
-//@{
-enum DQSingleEdge {
- DQSINGLE_BEDGE_LEFT,
- DQSINGLE_BEDGE_TOP,
- DQSINGLE_BEDGE_RIGHT,
- DQSINGLE_BEDGE_BOTTOM
-};
-//@}
-
-/** Which pair of edges is quantized with ALTPQUANT */
-//@{
-enum DQDoubleEdge {
- DQDOUBLE_BEDGE_TOPLEFT,
- DQDOUBLE_BEDGE_TOPRIGHT,
- DQDOUBLE_BEDGE_BOTTOMRIGHT,
- DQDOUBLE_BEDGE_BOTTOMLEFT
-};
-//@}
-
-/** MV modes for P frames */
-//@{
-enum MVModes {
- MV_PMODE_1MV_HPEL_BILIN,
- MV_PMODE_1MV,
- MV_PMODE_1MV_HPEL,
- MV_PMODE_MIXED_MV,
- MV_PMODE_INTENSITY_COMP
-};
-//@}
-
-/** @name MV types for B frames */
-//@{
-enum BMVTypes {
- BMV_TYPE_BACKWARD,
- BMV_TYPE_FORWARD,
- BMV_TYPE_INTERPOLATED
-};
-//@}
-
-/** @name Block types for P/B frames */
-//@{
-enum TransformTypes {
- TT_8X8,
- TT_8X4_BOTTOM,
- TT_8X4_TOP,
- TT_8X4, //Both halves
- TT_4X8_RIGHT,
- TT_4X8_LEFT,
- TT_4X8, //Both halves
- TT_4X4
-};
-//@}
-
-/** Table for conversion between TTBLK and TTMB */
-static const int ttblk_to_tt[3][8] = {
- { TT_8X4, TT_4X8, TT_8X8, TT_4X4, TT_8X4_TOP, TT_8X4_BOTTOM, TT_4X8_RIGHT, TT_4X8_LEFT },
- { TT_8X8, TT_4X8_RIGHT, TT_4X8_LEFT, TT_4X4, TT_8X4, TT_4X8, TT_8X4_BOTTOM, TT_8X4_TOP },
- { TT_8X8, TT_4X8, TT_4X4, TT_8X4_BOTTOM, TT_4X8_RIGHT, TT_4X8_LEFT, TT_8X4, TT_8X4_TOP }
-};
-
-static const int ttfrm_to_tt[4] = { TT_8X8, TT_8X4, TT_4X8, TT_4X4 };
-
-/** MV P mode - the 5th element is only used for mode 1 */
-static const uint8_t mv_pmode_table[2][5] = {
- { MV_PMODE_1MV_HPEL_BILIN, MV_PMODE_1MV, MV_PMODE_1MV_HPEL, MV_PMODE_INTENSITY_COMP, MV_PMODE_MIXED_MV },
- { MV_PMODE_1MV, MV_PMODE_MIXED_MV, MV_PMODE_1MV_HPEL, MV_PMODE_INTENSITY_COMP, MV_PMODE_1MV_HPEL_BILIN }
-};
-static const uint8_t mv_pmode_table2[2][4] = {
- { MV_PMODE_1MV_HPEL_BILIN, MV_PMODE_1MV, MV_PMODE_1MV_HPEL, MV_PMODE_MIXED_MV },
- { MV_PMODE_1MV, MV_PMODE_MIXED_MV, MV_PMODE_1MV_HPEL, MV_PMODE_1MV_HPEL_BILIN }
-};
-
-/** One more frame type */
-#define BI_TYPE 7
-
-static const int fps_nr[5] = { 24, 25, 30, 50, 60 },
- fps_dr[2] = { 1000, 1001 };
-static const uint8_t pquant_table[3][32] = {
- { /* Implicit quantizer */
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 6, 7, 8, 9, 10, 11, 12,
- 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 29, 31
- },
- { /* Explicit quantizer, pquantizer uniform */
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
- },
- { /* Explicit quantizer, pquantizer non-uniform */
- 0, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
- 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29, 31
- }
-};
-
-/** @name VC-1 VLC tables and defines
- * @todo TODO move this into the context
- */
-//@{
-#define VC1_BFRACTION_VLC_BITS 7
-static VLC vc1_bfraction_vlc;
-#define VC1_IMODE_VLC_BITS 4
-static VLC vc1_imode_vlc;
-#define VC1_NORM2_VLC_BITS 3
-static VLC vc1_norm2_vlc;
-#define VC1_NORM6_VLC_BITS 9
-static VLC vc1_norm6_vlc;
-/* Could be optimized, one table only needs 8 bits */
-#define VC1_TTMB_VLC_BITS 9 //12
-static VLC vc1_ttmb_vlc[3];
-#define VC1_MV_DIFF_VLC_BITS 9 //15
-static VLC vc1_mv_diff_vlc[4];
-#define VC1_CBPCY_P_VLC_BITS 9 //14
-static VLC vc1_cbpcy_p_vlc[4];
-#define VC1_4MV_BLOCK_PATTERN_VLC_BITS 6
-static VLC vc1_4mv_block_pattern_vlc[4];
-#define VC1_TTBLK_VLC_BITS 5
-static VLC vc1_ttblk_vlc[3];
-#define VC1_SUBBLKPAT_VLC_BITS 6
-static VLC vc1_subblkpat_vlc[3];
-
-static VLC vc1_ac_coeff_table[8];
-//@}
-
-enum CodingSet {
- CS_HIGH_MOT_INTRA = 0,
- CS_HIGH_MOT_INTER,
- CS_LOW_MOT_INTRA,
- CS_LOW_MOT_INTER,
- CS_MID_RATE_INTRA,
- CS_MID_RATE_INTER,
- CS_HIGH_RATE_INTRA,
- CS_HIGH_RATE_INTER
-};
-
-/** @name Overlap conditions for Advanced Profile */
-//@{
-enum COTypes {
- CONDOVER_NONE = 0,
- CONDOVER_ALL,
- CONDOVER_SELECT
-};
-//@}
-
-
-/** The VC1 Context
- * @fixme Change size wherever another size is more efficient
- * Many members are only used for Advanced Profile
- */
-typedef struct VC1Context{
- MpegEncContext s;
-
- int bits;
-
- /** Simple/Main Profile sequence header */
- //@{
- int res_sm; ///< reserved, 2b
- int res_x8; ///< reserved
- int multires; ///< frame-level RESPIC syntax element present
- int res_fasttx; ///< reserved, always 1
- int res_transtab; ///< reserved, always 0
- int rangered; ///< RANGEREDFRM (range reduction) syntax element present
- ///< at frame level
- int res_rtm_flag; ///< reserved, set to 1
- int reserved; ///< reserved
- //@}
-
- /** Advanced Profile */
- //@{
- int level; ///< 3bits, for Advanced/Simple Profile, provided by TS layer
- int chromaformat; ///< 2bits, 2=4:2:0, only defined
- int postprocflag; ///< Per-frame processing suggestion flag present
- int broadcast; ///< TFF/RFF present
- int interlace; ///< Progressive/interlaced (RPTFTM syntax element)
- int tfcntrflag; ///< TFCNTR present
- int panscanflag; ///< NUMPANSCANWIN, TOPLEFT{X,Y}, BOTRIGHT{X,Y} present
- int extended_dmv; ///< Additional extended dmv range at P/B frame-level
- int color_prim; ///< 8bits, chroma coordinates of the color primaries
- int transfer_char; ///< 8bits, Opto-electronic transfer characteristics
- int matrix_coef; ///< 8bits, Color primaries->YCbCr transform matrix
- int hrd_param_flag; ///< Presence of Hypothetical Reference
- ///< Decoder parameters
- int psf; ///< Progressive Segmented Frame
- //@}
-
- /** Sequence header data for all Profiles
- * TODO: choose between ints, uint8_ts and monobit flags
- */
- //@{
- int profile; ///< 2bits, Profile
- int frmrtq_postproc; ///< 3bits,
- int bitrtq_postproc; ///< 5bits, quantized framerate-based postprocessing strength
- int fastuvmc; ///< Rounding of qpel vector to hpel ? (not in Simple)
- int extended_mv; ///< Ext MV in P/B (not in Simple)
- int dquant; ///< How qscale varies with MBs, 2bits (not in Simple)
- int vstransform; ///< variable-size [48]x[48] transform type + info
- int overlap; ///< overlapped transforms in use
- int quantizer_mode; ///< 2bits, quantizer mode used for sequence, see QUANT_*
- int finterpflag; ///< INTERPFRM present
- //@}
-
- /** Frame decoding info for all profiles */
- //@{
- uint8_t mv_mode; ///< MV coding monde
- uint8_t mv_mode2; ///< Secondary MV coding mode (B frames)
- int k_x; ///< Number of bits for MVs (depends on MV range)
- int k_y; ///< Number of bits for MVs (depends on MV range)
- int range_x, range_y; ///< MV range
- uint8_t pq, altpq; ///< Current/alternate frame quantizer scale
- /** pquant parameters */
- //@{
- uint8_t dquantfrm;
- uint8_t dqprofile;
- uint8_t dqsbedge;
- uint8_t dqbilevel;
- //@}
- /** AC coding set indexes
- * @see 8.1.1.10, p(1)10
- */
- //@{
- int c_ac_table_index; ///< Chroma index from ACFRM element
- int y_ac_table_index; ///< Luma index from AC2FRM element
- //@}
- int ttfrm; ///< Transform type info present at frame level
- uint8_t ttmbf; ///< Transform type flag
- uint8_t ttblk4x4; ///< Value of ttblk which indicates a 4x4 transform
- int codingset; ///< index of current table set from 11.8 to use for luma block decoding
- int codingset2; ///< index of current table set from 11.8 to use for chroma block decoding
- int pqindex; ///< raw pqindex used in coding set selection
- int a_avail, c_avail;
- uint8_t *mb_type_base, *mb_type[3];
-
-
- /** Luma compensation parameters */
- //@{
- uint8_t lumscale;
- uint8_t lumshift;
- //@}
- int16_t bfraction; ///< Relative position % anchors=> how to scale MVs
- uint8_t halfpq; ///< Uniform quant over image and qp+.5
- uint8_t respic; ///< Frame-level flag for resized images
- int buffer_fullness; ///< HRD info
- /** Ranges:
- * -# 0 -> [-64n 63.f] x [-32, 31.f]
- * -# 1 -> [-128, 127.f] x [-64, 63.f]
- * -# 2 -> [-512, 511.f] x [-128, 127.f]
- * -# 3 -> [-1024, 1023.f] x [-256, 255.f]
- */
- uint8_t mvrange;
- uint8_t pquantizer; ///< Uniform (over sequence) quantizer in use
- VLC *cbpcy_vlc; ///< CBPCY VLC table
- int tt_index; ///< Index for Transform Type tables
- uint8_t* mv_type_mb_plane; ///< bitplane for mv_type == (4MV)
- uint8_t* direct_mb_plane; ///< bitplane for "direct" MBs
- int mv_type_is_raw; ///< mv type mb plane is not coded
- int dmb_is_raw; ///< direct mb plane is raw
- int skip_is_raw; ///< skip mb plane is not coded
- uint8_t luty[256], lutuv[256]; // lookup tables used for intensity compensation
- int use_ic; ///< use intensity compensation in B-frames
- int rnd; ///< rounding control
-
- /** Frame decoding info for S/M profiles only */
- //@{
- uint8_t rangeredfrm; ///< out_sample = CLIP((in_sample-128)*2+128)
- uint8_t interpfrm;
- //@}
-
- /** Frame decoding info for Advanced profile */
- //@{
- uint8_t fcm; ///< 0->Progressive, 2->Frame-Interlace, 3->Field-Interlace
- uint8_t numpanscanwin;
- uint8_t tfcntr;
- uint8_t rptfrm, tff, rff;
- uint16_t topleftx;
- uint16_t toplefty;
- uint16_t bottomrightx;
- uint16_t bottomrighty;
- uint8_t uvsamp;
- uint8_t postproc;
- int hrd_num_leaky_buckets;
- uint8_t bit_rate_exponent;
- uint8_t buffer_size_exponent;
- uint8_t* acpred_plane; ///< AC prediction flags bitplane
- int acpred_is_raw;
- uint8_t* over_flags_plane; ///< Overflags bitplane
- int overflg_is_raw;
- uint8_t condover;
- uint16_t *hrd_rate, *hrd_buffer;
- uint8_t *hrd_fullness;
- uint8_t range_mapy_flag;
- uint8_t range_mapuv_flag;
- uint8_t range_mapy;
- uint8_t range_mapuv;
- //@}
-
- int p_frame_skipped;
- int bi_type;
-} VC1Context;
-
-/**
- * Get unary code of limited length
- * @fixme FIXME Slow and ugly
- * @param gb GetBitContext
- * @param[in] stop The bitstop value (unary code of 1's or 0's)
- * @param[in] len Maximum length
- * @return Unary length/index
- */
-static int get_prefix(GetBitContext *gb, int stop, int len)
-{
-#if 1
- int i;
-
- for(i = 0; i < len && get_bits1(gb) != stop; i++);
- return i;
-/* int i = 0, tmp = !stop;
-
- while (i != len && tmp != stop)
- {
- tmp = get_bits(gb, 1);
- i++;
- }
- if (i == len && tmp != stop) return len+1;
- return i;*/
-#else
- unsigned int buf;
- int log;
-
- OPEN_READER(re, gb);
- UPDATE_CACHE(re, gb);
- buf=GET_CACHE(re, gb); //Still not sure
- if (stop) buf = ~buf;
-
- log= av_log2(-buf); //FIXME: -?
- if (log < limit){
- LAST_SKIP_BITS(re, gb, log+1);
- CLOSE_READER(re, gb);
- return log;
- }
-
- LAST_SKIP_BITS(re, gb, limit);
- CLOSE_READER(re, gb);
- return limit;
-#endif
-}
-
-static inline int decode210(GetBitContext *gb){
- int n;
- n = get_bits1(gb);
- if (n == 1)
- return 0;
- else
- return 2 - get_bits1(gb);
-}
-
-/**
- * Init VC-1 specific tables and VC1Context members
- * @param v The VC1Context to initialize
- * @return Status
- */
-static int vc1_init_common(VC1Context *v)
-{
- static int done = 0;
- int i = 0;
-
- v->hrd_rate = v->hrd_buffer = NULL;
-
- /* VLC tables */
- if(!done)
- {
- done = 1;
- init_vlc(&vc1_bfraction_vlc, VC1_BFRACTION_VLC_BITS, 23,
- vc1_bfraction_bits, 1, 1,
- vc1_bfraction_codes, 1, 1, 1);
- init_vlc(&vc1_norm2_vlc, VC1_NORM2_VLC_BITS, 4,
- vc1_norm2_bits, 1, 1,
- vc1_norm2_codes, 1, 1, 1);
- init_vlc(&vc1_norm6_vlc, VC1_NORM6_VLC_BITS, 64,
- vc1_norm6_bits, 1, 1,
- vc1_norm6_codes, 2, 2, 1);
- init_vlc(&vc1_imode_vlc, VC1_IMODE_VLC_BITS, 7,
- vc1_imode_bits, 1, 1,
- vc1_imode_codes, 1, 1, 1);
- for (i=0; i<3; i++)
- {
- init_vlc(&vc1_ttmb_vlc[i], VC1_TTMB_VLC_BITS, 16,
- vc1_ttmb_bits[i], 1, 1,
- vc1_ttmb_codes[i], 2, 2, 1);
- init_vlc(&vc1_ttblk_vlc[i], VC1_TTBLK_VLC_BITS, 8,
- vc1_ttblk_bits[i], 1, 1,
- vc1_ttblk_codes[i], 1, 1, 1);
- init_vlc(&vc1_subblkpat_vlc[i], VC1_SUBBLKPAT_VLC_BITS, 15,
- vc1_subblkpat_bits[i], 1, 1,
- vc1_subblkpat_codes[i], 1, 1, 1);
- }
- for(i=0; i<4; i++)
- {
- init_vlc(&vc1_4mv_block_pattern_vlc[i], VC1_4MV_BLOCK_PATTERN_VLC_BITS, 16,
- vc1_4mv_block_pattern_bits[i], 1, 1,
- vc1_4mv_block_pattern_codes[i], 1, 1, 1);
- init_vlc(&vc1_cbpcy_p_vlc[i], VC1_CBPCY_P_VLC_BITS, 64,
- vc1_cbpcy_p_bits[i], 1, 1,
- vc1_cbpcy_p_codes[i], 2, 2, 1);
- init_vlc(&vc1_mv_diff_vlc[i], VC1_MV_DIFF_VLC_BITS, 73,
- vc1_mv_diff_bits[i], 1, 1,
- vc1_mv_diff_codes[i], 2, 2, 1);
- }
- for(i=0; i<8; i++)
- init_vlc(&vc1_ac_coeff_table[i], AC_VLC_BITS, vc1_ac_sizes[i],
- &vc1_ac_tables[i][0][1], 8, 4,
- &vc1_ac_tables[i][0][0], 8, 4, 1);
- 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, 1);
- }
-
- /* Other defaults */
- v->pq = -1;
- v->mvrange = 0; /* 7.1.1.18, p80 */
-
- return 0;
-}
-
-/***********************************************************************/
-/**
- * @defgroup bitplane VC9 Bitplane decoding
- * @see 8.7, p56
- * @{
- */
-
-/** @addtogroup bitplane
- * Imode types
- * @{
- */
-enum Imode {
- IMODE_RAW,
- IMODE_NORM2,
- IMODE_DIFF2,
- IMODE_NORM6,
- IMODE_DIFF6,
- IMODE_ROWSKIP,
- IMODE_COLSKIP
-};
-/** @} */ //imode defines
-
-/** Decode rows by checking if they are skipped
- * @param plane Buffer to store decoded bits
- * @param[in] width Width of this buffer
- * @param[in] height Height of this buffer
- * @param[in] stride of this buffer
- */
-static void decode_rowskip(uint8_t* plane, int width, int height, int stride, GetBitContext *gb){
- int x, y;
-
- for (y=0; y<height; y++){
- if (!get_bits(gb, 1)) //rowskip
- memset(plane, 0, width);
- else
- for (x=0; x<width; x++)
- plane[x] = get_bits(gb, 1);
- plane += stride;
- }
-}
-
-/** Decode columns by checking if they are skipped
- * @param plane Buffer to store decoded bits
- * @param[in] width Width of this buffer
- * @param[in] height Height of this buffer
- * @param[in] stride of this buffer
- * @fixme FIXME: Optimize
- */
-static void decode_colskip(uint8_t* plane, int width, int height, int stride, GetBitContext *gb){
- int x, y;
-
- for (x=0; x<width; x++){
- if (!get_bits(gb, 1)) //colskip
- for (y=0; y<height; y++)
- plane[y*stride] = 0;
- else
- for (y=0; y<height; y++)
- plane[y*stride] = get_bits(gb, 1);
- plane ++;
- }
-}
-
-/** Decode a bitplane's bits
- * @param bp Bitplane where to store the decode bits
- * @param v VC-1 context for bit reading and logging
- * @return Status
- * @fixme FIXME: Optimize
- */
-static int bitplane_decoding(uint8_t* data, int *raw_flag, VC1Context *v)
-{
- GetBitContext *gb = &v->s.gb;
-
- int imode, x, y, code, offset;
- uint8_t invert, *planep = data;
- int width, height, stride;
-
- width = v->s.mb_width;
- height = v->s.mb_height;
- stride = v->s.mb_stride;
- invert = get_bits(gb, 1);
- imode = get_vlc2(gb, vc1_imode_vlc.table, VC1_IMODE_VLC_BITS, 1);
-
- *raw_flag = 0;
- switch (imode)
- {
- case IMODE_RAW:
- //Data is actually read in the MB layer (same for all tests == "raw")
- *raw_flag = 1; //invert ignored
- return invert;
- case IMODE_DIFF2:
- case IMODE_NORM2:
- if ((height * width) & 1)
- {
- *planep++ = get_bits(gb, 1);
- offset = 1;
- }
- else offset = 0;
- // decode bitplane as one long line
- for (y = offset; y < height * width; y += 2) {
- code = get_vlc2(gb, vc1_norm2_vlc.table, VC1_NORM2_VLC_BITS, 1);
- *planep++ = code & 1;
- offset++;
- if(offset == width) {
- offset = 0;
- planep += stride - width;
- }
- *planep++ = code >> 1;
- offset++;
- if(offset == width) {
- offset = 0;
- planep += stride - width;
- }
- }
- break;
- case IMODE_DIFF6:
- case IMODE_NORM6:
- if(!(height % 3) && (width % 3)) { // use 2x3 decoding
- for(y = 0; y < height; y+= 3) {
- for(x = width & 1; x < width; x += 2) {
- code = get_vlc2(gb, vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2);
- if(code < 0){
- av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");
- return -1;
- }
- planep[x + 0] = (code >> 0) & 1;
- planep[x + 1] = (code >> 1) & 1;
- planep[x + 0 + stride] = (code >> 2) & 1;
- planep[x + 1 + stride] = (code >> 3) & 1;
- planep[x + 0 + stride * 2] = (code >> 4) & 1;
- planep[x + 1 + stride * 2] = (code >> 5) & 1;
- }
- planep += stride * 3;
- }
- if(width & 1) decode_colskip(data, 1, height, stride, &v->s.gb);
- } else { // 3x2
- planep += (height & 1) * stride;
- for(y = height & 1; y < height; y += 2) {
- for(x = width % 3; x < width; x += 3) {
- code = get_vlc2(gb, vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2);
- if(code < 0){
- av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");
- return -1;
- }
- planep[x + 0] = (code >> 0) & 1;
- planep[x + 1] = (code >> 1) & 1;
- planep[x + 2] = (code >> 2) & 1;
- planep[x + 0 + stride] = (code >> 3) & 1;
- planep[x + 1 + stride] = (code >> 4) & 1;
- planep[x + 2 + stride] = (code >> 5) & 1;
- }
- planep += stride * 2;
- }
- x = width % 3;
- if(x) decode_colskip(data , x, height , stride, &v->s.gb);
- if(height & 1) decode_rowskip(data+x, width - x, 1, stride, &v->s.gb);
- }
- break;
- case IMODE_ROWSKIP:
- decode_rowskip(data, width, height, stride, &v->s.gb);
- break;
- case IMODE_COLSKIP:
- decode_colskip(data, width, height, stride, &v->s.gb);
- break;
- default: break;
- }
-
- /* Applying diff operator */
- if (imode == IMODE_DIFF2 || imode == IMODE_DIFF6)
- {
- planep = data;
- planep[0] ^= invert;
- for (x=1; x<width; x++)
- planep[x] ^= planep[x-1];
- for (y=1; y<height; y++)
- {
- planep += stride;
- planep[0] ^= planep[-stride];
- for (x=1; x<width; x++)
- {
- if (planep[x-1] != planep[x-stride]) planep[x] ^= invert;
- else planep[x] ^= planep[x-1];
- }
- }
- }
- else if (invert)
- {
- planep = data;
- for (x=0; x<stride*height; x++) planep[x] = !planep[x]; //FIXME stride
- }
- return (imode<<1) + invert;
-}
-
-/** @} */ //Bitplane group
-
-/***********************************************************************/
-/** VOP Dquant decoding
- * @param v VC-1 Context
- */
-static int vop_dquant_decoding(VC1Context *v)
-{
- GetBitContext *gb = &v->s.gb;
- int pqdiff;
-
- //variable size
- if (v->dquant == 2)
- {
- pqdiff = get_bits(gb, 3);
- if (pqdiff == 7) v->altpq = get_bits(gb, 5);
- else v->altpq = v->pq + pqdiff + 1;
- }
- else
- {
- v->dquantfrm = get_bits(gb, 1);
- if ( v->dquantfrm )
- {
- v->dqprofile = get_bits(gb, 2);
- switch (v->dqprofile)
- {
- case DQPROFILE_SINGLE_EDGE:
- case DQPROFILE_DOUBLE_EDGES:
- v->dqsbedge = get_bits(gb, 2);
- break;
- case DQPROFILE_ALL_MBS:
- v->dqbilevel = get_bits(gb, 1);
- default: break; //Forbidden ?
- }
- if (v->dqbilevel || v->dqprofile != DQPROFILE_ALL_MBS)
- {
- pqdiff = get_bits(gb, 3);
- if (pqdiff == 7) v->altpq = get_bits(gb, 5);
- else v->altpq = v->pq + pqdiff + 1;
- }
- }
- }
- return 0;
-}
-
-/** Put block onto picture
- */
-static void vc1_put_block(VC1Context *v, DCTELEM block[6][64])
-{
- uint8_t *Y;
- int ys, us, vs;
- DSPContext *dsp = &v->s.dsp;
-
- if(v->rangeredfrm) {
- int i, j, k;
- for(k = 0; k < 6; k++)
- for(j = 0; j < 8; j++)
- for(i = 0; i < 8; i++)
- block[k][i + j*8] = ((block[k][i + j*8] - 128) << 1) + 128;
-
- }
- ys = v->s.current_picture.linesize[0];
- us = v->s.current_picture.linesize[1];
- vs = v->s.current_picture.linesize[2];
- Y = v->s.dest[0];
-
- dsp->put_pixels_clamped(block[0], Y, ys);
- dsp->put_pixels_clamped(block[1], Y + 8, ys);
- Y += ys * 8;
- dsp->put_pixels_clamped(block[2], Y, ys);
- dsp->put_pixels_clamped(block[3], Y + 8, ys);
-
- if(!(v->s.flags & CODEC_FLAG_GRAY)) {
- dsp->put_pixels_clamped(block[4], v->s.dest[1], us);
- dsp->put_pixels_clamped(block[5], v->s.dest[2], vs);
- }
-}
-
-/** Do motion compensation over 1 macroblock
- * Mostly adapted hpel_motion and qpel_motion from mpegvideo.c
- */
-static void vc1_mc_1mv(VC1Context *v, int dir)
-{
- MpegEncContext *s = &v->s;
- DSPContext *dsp = &v->s.dsp;
- uint8_t *srcY, *srcU, *srcV;
- int dxy, uvdxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y;
-
- if(!v->s.last_picture.data[0])return;
-
- mx = s->mv[dir][0][0];
- my = s->mv[dir][0][1];
-
- // store motion vectors for further use in B frames
- if(s->pict_type == P_TYPE) {
- s->current_picture.motion_val[1][s->block_index[0]][0] = mx;
- s->current_picture.motion_val[1][s->block_index[0]][1] = my;
- }
- uvmx = (mx + ((mx & 3) == 3)) >> 1;
- uvmy = (my + ((my & 3) == 3)) >> 1;
- if(v->fastuvmc) {
- uvmx = uvmx + ((uvmx<0)?(uvmx&1):-(uvmx&1));
- uvmy = uvmy + ((uvmy<0)?(uvmy&1):-(uvmy&1));
- }
- if(!dir) {
- srcY = s->last_picture.data[0];
- srcU = s->last_picture.data[1];
- srcV = s->last_picture.data[2];
- } else {
- srcY = s->next_picture.data[0];
- srcU = s->next_picture.data[1];
- srcV = s->next_picture.data[2];
- }
-
- src_x = s->mb_x * 16 + (mx >> 2);
- src_y = s->mb_y * 16 + (my >> 2);
- uvsrc_x = s->mb_x * 8 + (uvmx >> 2);
- uvsrc_y = s->mb_y * 8 + (uvmy >> 2);
-
- src_x = clip( src_x, -16, s->mb_width * 16);
- src_y = clip( src_y, -16, s->mb_height * 16);
- uvsrc_x = clip(uvsrc_x, -8, s->mb_width * 8);
- uvsrc_y = clip(uvsrc_y, -8, s->mb_height * 8);
-
- srcY += src_y * s->linesize + src_x;
- srcU += uvsrc_y * s->uvlinesize + uvsrc_x;
- srcV += uvsrc_y * s->uvlinesize + uvsrc_x;
-
- /* for grayscale we should not try to read from unknown area */
- if(s->flags & CODEC_FLAG_GRAY) {
- srcU = s->edge_emu_buffer + 18 * s->linesize;
- srcV = s->edge_emu_buffer + 18 * s->linesize;
- }
-
- if(v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP)
- || (unsigned)(src_x - s->mspel) > s->h_edge_pos - (mx&3) - 16 - s->mspel*3
- || (unsigned)(src_y - s->mspel) > s->v_edge_pos - (my&3) - 16 - s->mspel*3){
- uint8_t *uvbuf= s->edge_emu_buffer + 19 * s->linesize;
-
- srcY -= s->mspel * (1 + s->linesize);
- ff_emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize, 17+s->mspel*2, 17+s->mspel*2,
- src_x - s->mspel, src_y - s->mspel, s->h_edge_pos, s->v_edge_pos);
- srcY = s->edge_emu_buffer;
- ff_emulated_edge_mc(uvbuf , srcU, s->uvlinesize, 8+1, 8+1,
- uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
- ff_emulated_edge_mc(uvbuf + 16, srcV, s->uvlinesize, 8+1, 8+1,
- uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
- srcU = uvbuf;
- srcV = uvbuf + 16;
- /* if we deal with range reduction we need to scale source blocks */
- if(v->rangeredfrm) {
- int i, j;
- uint8_t *src, *src2;
-
- src = srcY;
- for(j = 0; j < 17 + s->mspel*2; j++) {
- for(i = 0; i < 17 + s->mspel*2; i++) src[i] = ((src[i] - 128) >> 1) + 128;
- src += s->linesize;
- }
- src = srcU; src2 = srcV;
- for(j = 0; j < 9; j++) {
- for(i = 0; i < 9; i++) {
- src[i] = ((src[i] - 128) >> 1) + 128;
- src2[i] = ((src2[i] - 128) >> 1) + 128;
- }
- src += s->uvlinesize;
- src2 += s->uvlinesize;
- }
- }
- /* if we deal with intensity compensation we need to scale source blocks */
- if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {
- int i, j;
- uint8_t *src, *src2;
-
- src = srcY;
- for(j = 0; j < 17 + s->mspel*2; j++) {
- for(i = 0; i < 17 + s->mspel*2; i++) src[i] = v->luty[src[i]];
- src += s->linesize;
- }
- src = srcU; src2 = srcV;
- for(j = 0; j < 9; j++) {
- for(i = 0; i < 9; i++) {
- src[i] = v->lutuv[src[i]];
- src2[i] = v->lutuv[src2[i]];
- }
- src += s->uvlinesize;
- src2 += s->uvlinesize;
- }
- }
- srcY += s->mspel * (1 + s->linesize);
- }
-
- if(s->mspel) {
- dxy = ((my & 3) << 2) | (mx & 3);
- dsp->put_vc1_mspel_pixels_tab[dxy](s->dest[0] , srcY , s->linesize, v->rnd);
- dsp->put_vc1_mspel_pixels_tab[dxy](s->dest[0] + 8, srcY + 8, s->linesize, v->rnd);
- srcY += s->linesize * 8;
- dsp->put_vc1_mspel_pixels_tab[dxy](s->dest[0] + 8 * s->linesize , srcY , s->linesize, v->rnd);
- dsp->put_vc1_mspel_pixels_tab[dxy](s->dest[0] + 8 * s->linesize + 8, srcY + 8, s->linesize, v->rnd);
- } else { // hpel mc - always used for luma
- dxy = (my & 2) | ((mx & 2) >> 1);
-
- if(!v->rnd)
- dsp->put_pixels_tab[0][dxy](s->dest[0], srcY, s->linesize, 16);
- else
- dsp->put_no_rnd_pixels_tab[0][dxy](s->dest[0], srcY, s->linesize, 16);
- }
-
- if(s->flags & CODEC_FLAG_GRAY) return;
- /* Chroma MC always uses qpel bilinear */
- uvdxy = ((uvmy & 3) << 2) | (uvmx & 3);
- uvmx = (uvmx&3)<<1;
- uvmy = (uvmy&3)<<1;
- if(!v->rnd){
- dsp->put_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);
- dsp->put_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);
- }else{
- dsp->put_no_rnd_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);
- dsp->put_no_rnd_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);
- }
-}
-
-/** Do motion compensation for 4-MV macroblock - luminance block
- */
-static void vc1_mc_4mv_luma(VC1Context *v, int n)
-{
- MpegEncContext *s = &v->s;
- DSPContext *dsp = &v->s.dsp;
- uint8_t *srcY;
- int dxy, mx, my, src_x, src_y;
- int off;
-
- if(!v->s.last_picture.data[0])return;
- mx = s->mv[0][n][0];
- my = s->mv[0][n][1];
- srcY = s->last_picture.data[0];
-
- off = s->linesize * 4 * (n&2) + (n&1) * 8;
-
- src_x = s->mb_x * 16 + (n&1) * 8 + (mx >> 2);
- src_y = s->mb_y * 16 + (n&2) * 4 + (my >> 2);
-
- src_x = clip( src_x, -16, s->mb_width * 16);
- src_y = clip( src_y, -16, s->mb_height * 16);
-
- srcY += src_y * s->linesize + src_x;
-
- if(v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP)
- || (unsigned)(src_x - s->mspel) > s->h_edge_pos - (mx&3) - 8 - s->mspel*2
- || (unsigned)(src_y - s->mspel) > s->v_edge_pos - (my&3) - 8 - s->mspel*2){
- srcY -= s->mspel * (1 + s->linesize);
- ff_emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize, 9+s->mspel*2, 9+s->mspel*2,
- src_x - s->mspel, src_y - s->mspel, s->h_edge_pos, s->v_edge_pos);
- srcY = s->edge_emu_buffer;
- /* if we deal with range reduction we need to scale source blocks */
- if(v->rangeredfrm) {
- int i, j;
- uint8_t *src;
-
- src = srcY;
- for(j = 0; j < 9 + s->mspel*2; j++) {
- for(i = 0; i < 9 + s->mspel*2; i++) src[i] = ((src[i] - 128) >> 1) + 128;
- src += s->linesize;
- }
- }
- /* if we deal with intensity compensation we need to scale source blocks */
- if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {
- int i, j;
- uint8_t *src;
-
- src = srcY;
- for(j = 0; j < 9 + s->mspel*2; j++) {
- for(i = 0; i < 9 + s->mspel*2; i++) src[i] = v->luty[src[i]];
- src += s->linesize;
- }
- }
- srcY += s->mspel * (1 + s->linesize);
- }
-
- if(s->mspel) {
- dxy = ((my & 3) << 2) | (mx & 3);
- dsp->put_vc1_mspel_pixels_tab[dxy](s->dest[0] + off, srcY, s->linesize, v->rnd);
- } else { // hpel mc - always used for luma
- dxy = (my & 2) | ((mx & 2) >> 1);
- if(!v->rnd)
- dsp->put_pixels_tab[1][dxy](s->dest[0] + off, srcY, s->linesize, 8);
- else
- dsp->put_no_rnd_pixels_tab[1][dxy](s->dest[0] + off, srcY, s->linesize, 8);
- }
-}
-
-static inline int median4(int a, int b, int c, int d)
-{
- if(a < b) {
- if(c < d) return (FFMIN(b, d) + FFMAX(a, c)) / 2;
- else return (FFMIN(b, c) + FFMAX(a, d)) / 2;
- } else {
- if(c < d) return (FFMIN(a, d) + FFMAX(b, c)) / 2;
- else return (FFMIN(a, c) + FFMAX(b, d)) / 2;
- }
-}
-
-
-/** Do motion compensation for 4-MV macroblock - both chroma blocks
- */
-static void vc1_mc_4mv_chroma(VC1Context *v)
-{
- MpegEncContext *s = &v->s;
- DSPContext *dsp = &v->s.dsp;
- uint8_t *srcU, *srcV;
- int uvdxy, uvmx, uvmy, uvsrc_x, uvsrc_y;
- int i, idx, tx = 0, ty = 0;
- int mvx[4], mvy[4], intra[4];
- static const int count[16] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};
-
- if(!v->s.last_picture.data[0])return;
- if(s->flags & CODEC_FLAG_GRAY) return;
-
- for(i = 0; i < 4; i++) {
- mvx[i] = s->mv[0][i][0];
- mvy[i] = s->mv[0][i][1];
- intra[i] = v->mb_type[0][s->block_index[i]];
- }
-
- /* calculate chroma MV vector from four luma MVs */
- idx = (intra[3] << 3) | (intra[2] << 2) | (intra[1] << 1) | intra[0];
- if(!idx) { // all blocks are inter
- tx = median4(mvx[0], mvx[1], mvx[2], mvx[3]);
- ty = median4(mvy[0], mvy[1], mvy[2], mvy[3]);
- } else if(count[idx] == 1) { // 3 inter blocks
- switch(idx) {
- case 0x1:
- tx = mid_pred(mvx[1], mvx[2], mvx[3]);
- ty = mid_pred(mvy[1], mvy[2], mvy[3]);
- break;
- case 0x2:
- tx = mid_pred(mvx[0], mvx[2], mvx[3]);
- ty = mid_pred(mvy[0], mvy[2], mvy[3]);
- break;
- case 0x4:
- tx = mid_pred(mvx[0], mvx[1], mvx[3]);
- ty = mid_pred(mvy[0], mvy[1], mvy[3]);
- break;
- case 0x8:
- tx = mid_pred(mvx[0], mvx[1], mvx[2]);
- ty = mid_pred(mvy[0], mvy[1], mvy[2]);
- break;
- }
- } else if(count[idx] == 2) {
- int t1 = 0, t2 = 0;
- for(i=0; i<3;i++) if(!intra[i]) {t1 = i; break;}
- for(i= t1+1; i<4; i++)if(!intra[i]) {t2 = i; break;}
- tx = (mvx[t1] + mvx[t2]) / 2;
- ty = (mvy[t1] + mvy[t2]) / 2;
- } else
- return; //no need to do MC for inter blocks
-
- s->current_picture.motion_val[1][s->block_index[0]][0] = tx;
- s->current_picture.motion_val[1][s->block_index[0]][1] = ty;
- uvmx = (tx + ((tx&3) == 3)) >> 1;
- uvmy = (ty + ((ty&3) == 3)) >> 1;
- if(v->fastuvmc) {
- uvmx = uvmx + ((uvmx<0)?(uvmx&1):-(uvmx&1));
- uvmy = uvmy + ((uvmy<0)?(uvmy&1):-(uvmy&1));
- }
-
- uvsrc_x = s->mb_x * 8 + (uvmx >> 2);
- uvsrc_y = s->mb_y * 8 + (uvmy >> 2);
-
- uvsrc_x = clip(uvsrc_x, -8, s->mb_width * 8);
- uvsrc_y = clip(uvsrc_y, -8, s->mb_height * 8);
- srcU = s->last_picture.data[1] + uvsrc_y * s->uvlinesize + uvsrc_x;
- srcV = s->last_picture.data[2] + uvsrc_y * s->uvlinesize + uvsrc_x;
- if(v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP)
- || (unsigned)uvsrc_x > (s->h_edge_pos >> 1) - 9
- || (unsigned)uvsrc_y > (s->v_edge_pos >> 1) - 9){
- ff_emulated_edge_mc(s->edge_emu_buffer , srcU, s->uvlinesize, 8+1, 8+1,
- uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
- ff_emulated_edge_mc(s->edge_emu_buffer + 16, srcV, s->uvlinesize, 8+1, 8+1,
- uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
- srcU = s->edge_emu_buffer;
- srcV = s->edge_emu_buffer + 16;
-
- /* if we deal with range reduction we need to scale source blocks */
- if(v->rangeredfrm) {
- int i, j;
- uint8_t *src, *src2;
-
- src = srcU; src2 = srcV;
- for(j = 0; j < 9; j++) {
- for(i = 0; i < 9; i++) {
- src[i] = ((src[i] - 128) >> 1) + 128;
- src2[i] = ((src2[i] - 128) >> 1) + 128;
- }
- src += s->uvlinesize;
- src2 += s->uvlinesize;
- }
- }
- /* if we deal with intensity compensation we need to scale source blocks */
- if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {
- int i, j;
- uint8_t *src, *src2;
-
- src = srcU; src2 = srcV;
- for(j = 0; j < 9; j++) {
- for(i = 0; i < 9; i++) {
- src[i] = v->lutuv[src[i]];
- src2[i] = v->lutuv[src2[i]];
- }
- src += s->uvlinesize;
- src2 += s->uvlinesize;
- }
- }
- }
-
- /* Chroma MC always uses qpel bilinear */
- uvdxy = ((uvmy & 3) << 2) | (uvmx & 3);
- uvmx = (uvmx&3)<<1;
- uvmy = (uvmy&3)<<1;
- if(!v->rnd){
- dsp->put_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);
- dsp->put_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);
- }else{
- dsp->put_no_rnd_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);
- dsp->put_no_rnd_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);
- }
-}
-
-static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb);
-
-/**
- * Decode Simple/Main Profiles sequence header
- * @see Figure 7-8, p16-17
- * @param avctx Codec context
- * @param gb GetBit context initialized from Codec context extra_data
- * @return Status
- */
-static int decode_sequence_header(AVCodecContext *avctx, GetBitContext *gb)
-{
- VC1Context *v = avctx->priv_data;
-
- av_log(avctx, AV_LOG_DEBUG, "Header: %0X\n", show_bits(gb, 32));
- v->profile = get_bits(gb, 2);
- if (v->profile == 2)
- {
- av_log(avctx, AV_LOG_ERROR, "Profile value 2 is forbidden (and WMV3 Complex Profile is unsupported)\n");
- return -1;
- }
-
- if (v->profile == PROFILE_ADVANCED)
- {
- return decode_sequence_header_adv(v, gb);
- }
- else
- {
- v->res_sm = get_bits(gb, 2); //reserved
- if (v->res_sm)
- {
- av_log(avctx, AV_LOG_ERROR,
- "Reserved RES_SM=%i is forbidden\n", v->res_sm);
- return -1;
- }
- }
-
- // (fps-2)/4 (->30)
- v->frmrtq_postproc = get_bits(gb, 3); //common
- // (bitrate-32kbps)/64kbps
- v->bitrtq_postproc = get_bits(gb, 5); //common
- v->s.loop_filter = get_bits(gb, 1); //common
- if(v->s.loop_filter == 1 && v->profile == PROFILE_SIMPLE)
- {
- av_log(avctx, AV_LOG_ERROR,
- "LOOPFILTER shell not be enabled in simple profile\n");
- }
-
- v->res_x8 = get_bits(gb, 1); //reserved
- if (v->res_x8)
- {
- av_log(avctx, AV_LOG_ERROR,
- "1 for reserved RES_X8 is forbidden\n");
- //return -1;
- }
- v->multires = get_bits(gb, 1);
- v->res_fasttx = get_bits(gb, 1);
- if (!v->res_fasttx)
- {
- av_log(avctx, AV_LOG_ERROR,
- "0 for reserved RES_FASTTX is forbidden\n");
- //return -1;
- }
-
- v->fastuvmc = get_bits(gb, 1); //common
- if (!v->profile && !v->fastuvmc)
- {
- av_log(avctx, AV_LOG_ERROR,
- "FASTUVMC unavailable in Simple Profile\n");
- return -1;
- }
- v->extended_mv = get_bits(gb, 1); //common
- if (!v->profile && v->extended_mv)
- {
- av_log(avctx, AV_LOG_ERROR,
- "Extended MVs unavailable in Simple Profile\n");
- return -1;
- }
- v->dquant = get_bits(gb, 2); //common
- v->vstransform = get_bits(gb, 1); //common
-
- v->res_transtab = get_bits(gb, 1);
- if (v->res_transtab)
- {
- av_log(avctx, AV_LOG_ERROR,
- "1 for reserved RES_TRANSTAB is forbidden\n");
- return -1;
- }
-
- v->overlap = get_bits(gb, 1); //common
-
- v->s.resync_marker = get_bits(gb, 1);
- v->rangered = get_bits(gb, 1);
- if (v->rangered && v->profile == PROFILE_SIMPLE)
- {
- av_log(avctx, AV_LOG_INFO,
- "RANGERED should be set to 0 in simple profile\n");
- }
-
- v->s.max_b_frames = avctx->max_b_frames = get_bits(gb, 3); //common
- v->quantizer_mode = get_bits(gb, 2); //common
-
- v->finterpflag = get_bits(gb, 1); //common
- v->res_rtm_flag = get_bits(gb, 1); //reserved
- if (!v->res_rtm_flag)
- {
-// av_log(avctx, AV_LOG_ERROR,
-// "0 for reserved RES_RTM_FLAG is forbidden\n");
- av_log(avctx, AV_LOG_ERROR,
- "Old WMV3 version detected, only I-frames will be decoded\n");
- //return -1;
- }
- av_log(avctx, AV_LOG_DEBUG,
- "Profile %i:\nfrmrtq_postproc=%i, bitrtq_postproc=%i\n"
- "LoopFilter=%i, MultiRes=%i, FastUVMC=%i, Extended MV=%i\n"
- "Rangered=%i, VSTransform=%i, Overlap=%i, SyncMarker=%i\n"
- "DQuant=%i, Quantizer mode=%i, Max B frames=%i\n",
- v->profile, v->frmrtq_postproc, v->bitrtq_postproc,
- v->s.loop_filter, v->multires, v->fastuvmc, v->extended_mv,
- v->rangered, v->vstransform, v->overlap, v->s.resync_marker,
- v->dquant, v->quantizer_mode, avctx->max_b_frames
- );
- return 0;
-}
-
-static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb)
-{
- v->res_rtm_flag = 1;
- v->level = get_bits(gb, 3);
- if(v->level >= 5)
- {
- av_log(v->s.avctx, AV_LOG_ERROR, "Reserved LEVEL %i\n",v->level);
- }
- v->chromaformat = get_bits(gb, 2);
- if (v->chromaformat != 1)
- {
- av_log(v->s.avctx, AV_LOG_ERROR,
- "Only 4:2:0 chroma format supported\n");
- return -1;
- }
-
- // (fps-2)/4 (->30)
- v->frmrtq_postproc = get_bits(gb, 3); //common
- // (bitrate-32kbps)/64kbps
- v->bitrtq_postproc = get_bits(gb, 5); //common
- v->postprocflag = get_bits(gb, 1); //common
-
- v->s.avctx->coded_width = (get_bits(gb, 12) + 1) << 1;
- v->s.avctx->coded_height = (get_bits(gb, 12) + 1) << 1;
- v->broadcast = get_bits1(gb);
- v->interlace = get_bits1(gb);
- if(v->interlace){
- av_log(v->s.avctx, AV_LOG_ERROR, "Interlaced mode not supported (yet)\n");
- return -1;
- }
- v->tfcntrflag = get_bits1(gb);
- v->finterpflag = get_bits1(gb);
- get_bits1(gb); // reserved
-
- av_log(v->s.avctx, AV_LOG_DEBUG,
- "Advanced Profile level %i:\nfrmrtq_postproc=%i, bitrtq_postproc=%i\n"
- "LoopFilter=%i, ChromaFormat=%i, Pulldown=%i, Interlace: %i\n"
- "TFCTRflag=%i, FINTERPflag=%i\n",
- v->level, v->frmrtq_postproc, v->bitrtq_postproc,
- v->s.loop_filter, v->chromaformat, v->broadcast, v->interlace,
- v->tfcntrflag, v->finterpflag
- );
-
- v->psf = get_bits1(gb);
- if(v->psf) { //PsF, 6.1.13
- av_log(v->s.avctx, AV_LOG_ERROR, "Progressive Segmented Frame mode: not supported (yet)\n");
- return -1;
- }
- if(get_bits1(gb)) { //Display Info - decoding is not affected by it
- int w, h, ar = 0;
- av_log(v->s.avctx, AV_LOG_INFO, "Display extended info:\n");
- w = get_bits(gb, 14) + 1;
- h = get_bits(gb, 14) + 1;
- av_log(v->s.avctx, AV_LOG_INFO, "Display dimensions: %ix%i\n", w, h);
- if(get_bits1(gb))
- ar = get_bits(gb, 4);
- if(ar && ar < 14){
- v->s.avctx->sample_aspect_ratio = vc1_pixel_aspect[ar];
- }else if(ar == 15){
- w = get_bits(gb, 8);
- h = get_bits(gb, 8);
- v->s.avctx->sample_aspect_ratio = (AVRational){w, h};
- }
-
- if(get_bits1(gb)){ //framerate stuff
- if(get_bits1(gb)) {
- get_bits(gb, 16);
- } else {
- get_bits(gb, 8);
- get_bits(gb, 4);
- }
- }
-
- if(get_bits1(gb)){
- v->color_prim = get_bits(gb, 8);
- v->transfer_char = get_bits(gb, 8);
- v->matrix_coef = get_bits(gb, 8);
- }
- }
-
- v->hrd_param_flag = get_bits1(gb);
- if(v->hrd_param_flag) {
- int i;
- v->hrd_num_leaky_buckets = get_bits(gb, 5);
- get_bits(gb, 4); //bitrate exponent
- get_bits(gb, 4); //buffer size exponent
- for(i = 0; i < v->hrd_num_leaky_buckets; i++) {
- get_bits(gb, 16); //hrd_rate[n]
- get_bits(gb, 16); //hrd_buffer[n]
- }
- }
- return 0;
-}
-
-static int decode_entry_point(AVCodecContext *avctx, GetBitContext *gb)
-{
- VC1Context *v = avctx->priv_data;
- int i, blink, refdist;
-
- av_log(avctx, AV_LOG_DEBUG, "Entry point: %08X\n", show_bits_long(gb, 32));
- blink = get_bits1(gb); // broken link
- avctx->max_b_frames = 1 - get_bits1(gb); // 'closed entry' also signalize possible B-frames
- v->panscanflag = get_bits1(gb);
- refdist = get_bits1(gb); // refdist flag
- v->s.loop_filter = get_bits1(gb);
- v->fastuvmc = get_bits1(gb);
- v->extended_mv = get_bits1(gb);
- v->dquant = get_bits(gb, 2);
- v->vstransform = get_bits1(gb);
- v->overlap = get_bits1(gb);
- v->quantizer_mode = get_bits(gb, 2);
-
- if(v->hrd_param_flag){
- for(i = 0; i < v->hrd_num_leaky_buckets; i++) {
- get_bits(gb, 8); //hrd_full[n]
- }
- }
-
- if(get_bits1(gb)){
- avctx->coded_width = (get_bits(gb, 12)+1)<<1;
- avctx->coded_height = (get_bits(gb, 12)+1)<<1;
- }
- if(v->extended_mv)
- v->extended_dmv = get_bits1(gb);
- if(get_bits1(gb)) {
- av_log(avctx, AV_LOG_ERROR, "Luma scaling is not supported, expect wrong picture\n");
- skip_bits(gb, 3); // Y range, ignored for now
- }
- if(get_bits1(gb)) {
- av_log(avctx, AV_LOG_ERROR, "Chroma scaling is not supported, expect wrong picture\n");
- skip_bits(gb, 3); // UV range, ignored for now
- }
-
- av_log(avctx, AV_LOG_DEBUG, "Entry point info:\n"
- "BrokenLink=%i, ClosedEntry=%i, PanscanFlag=%i\n"
- "RefDist=%i, Postproc=%i, FastUVMC=%i, ExtMV=%i\n"
- "DQuant=%i, VSTransform=%i, Overlap=%i, Qmode=%i\n",
- blink, 1 - avctx->max_b_frames, v->panscanflag, refdist, v->s.loop_filter,
- v->fastuvmc, v->extended_mv, v->dquant, v->vstransform, v->overlap, v->quantizer_mode);
-
- return 0;
-}
-
-static int vc1_parse_frame_header(VC1Context *v, GetBitContext* gb)
-{
- int pqindex, lowquant, status;
-
- if(v->finterpflag) v->interpfrm = get_bits(gb, 1);
- skip_bits(gb, 2); //framecnt unused
- v->rangeredfrm = 0;
- if (v->rangered) v->rangeredfrm = get_bits(gb, 1);
- v->s.pict_type = get_bits(gb, 1);
- if (v->s.avctx->max_b_frames) {
- if (!v->s.pict_type) {
- if (get_bits(gb, 1)) v->s.pict_type = I_TYPE;
- else v->s.pict_type = B_TYPE;
- } else v->s.pict_type = P_TYPE;
- } else v->s.pict_type = v->s.pict_type ? P_TYPE : I_TYPE;
-
- v->bi_type = 0;
- if(v->s.pict_type == B_TYPE) {
- v->bfraction = get_vlc2(gb, vc1_bfraction_vlc.table, VC1_BFRACTION_VLC_BITS, 1);
- v->bfraction = vc1_bfraction_lut[v->bfraction];
- if(v->bfraction == 0) {
- v->s.pict_type = BI_TYPE;
- }
- }
- if(v->s.pict_type == I_TYPE || v->s.pict_type == BI_TYPE)
- get_bits(gb, 7); // skip buffer fullness
-
- /* calculate RND */
- if(v->s.pict_type == I_TYPE || v->s.pict_type == BI_TYPE)
- v->rnd = 1;
- if(v->s.pict_type == P_TYPE)
- v->rnd ^= 1;
-
- /* Quantizer stuff */
- pqindex = get_bits(gb, 5);
- if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
- v->pq = pquant_table[0][pqindex];
- else
- v->pq = pquant_table[1][pqindex];
-
- v->pquantizer = 1;
- if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
- v->pquantizer = pqindex < 9;
- if (v->quantizer_mode == QUANT_NON_UNIFORM)
- v->pquantizer = 0;
- v->pqindex = pqindex;
- if (pqindex < 9) v->halfpq = get_bits(gb, 1);
- else v->halfpq = 0;
- if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)
- v->pquantizer = get_bits(gb, 1);
- v->dquantfrm = 0;
- if (v->extended_mv == 1) v->mvrange = get_prefix(gb, 0, 3);
- v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
- v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
- v->range_x = 1 << (v->k_x - 1);
- v->range_y = 1 << (v->k_y - 1);
- if (v->profile == PROFILE_ADVANCED)
- {
- if (v->postprocflag) v->postproc = get_bits(gb, 1);
- }
- else
- if (v->multires && v->s.pict_type != B_TYPE) v->respic = get_bits(gb, 2);
-
-//av_log(v->s.avctx, AV_LOG_INFO, "%c Frame: QP=[%i]%i (+%i/2) %i\n",
-// (v->s.pict_type == P_TYPE) ? 'P' : ((v->s.pict_type == I_TYPE) ? 'I' : 'B'), pqindex, v->pq, v->halfpq, v->rangeredfrm);
-
- if(v->s.pict_type == I_TYPE || v->s.pict_type == P_TYPE) v->use_ic = 0;
-
- switch(v->s.pict_type) {
- case P_TYPE:
- if (v->pq < 5) v->tt_index = 0;
- else if(v->pq < 13) v->tt_index = 1;
- else v->tt_index = 2;
-
- lowquant = (v->pq > 12) ? 0 : 1;
- v->mv_mode = mv_pmode_table[lowquant][get_prefix(gb, 1, 4)];
- if (v->mv_mode == MV_PMODE_INTENSITY_COMP)
- {
- int scale, shift, i;
- v->mv_mode2 = mv_pmode_table2[lowquant][get_prefix(gb, 1, 3)];
- v->lumscale = get_bits(gb, 6);
- v->lumshift = get_bits(gb, 6);
- v->use_ic = 1;
- /* fill lookup tables for intensity compensation */
- if(!v->lumscale) {
- scale = -64;
- shift = (255 - v->lumshift * 2) << 6;
- if(v->lumshift > 31)
- shift += 128 << 6;
- } else {
- scale = v->lumscale + 32;
- if(v->lumshift > 31)
- shift = (v->lumshift - 64) << 6;
- else
- shift = v->lumshift << 6;
- }
- for(i = 0; i < 256; i++) {
- v->luty[i] = clip_uint8((scale * i + shift + 32) >> 6);
- v->lutuv[i] = clip_uint8((scale * (i - 128) + 128*64 + 32) >> 6);
- }
- }
- if(v->mv_mode == MV_PMODE_1MV_HPEL || v->mv_mode == MV_PMODE_1MV_HPEL_BILIN)
- v->s.quarter_sample = 0;
- else if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {
- if(v->mv_mode2 == MV_PMODE_1MV_HPEL || v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN)
- v->s.quarter_sample = 0;
- else
- v->s.quarter_sample = 1;
- } else
- v->s.quarter_sample = 1;
- v->s.mspel = !(v->mv_mode == MV_PMODE_1MV_HPEL_BILIN || (v->mv_mode == MV_PMODE_INTENSITY_COMP && v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN));
-
- if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
- v->mv_mode2 == MV_PMODE_MIXED_MV)
- || v->mv_mode == MV_PMODE_MIXED_MV)
- {
- status = bitplane_decoding(v->mv_type_mb_plane, &v->mv_type_is_raw, v);
- if (status < 0) return -1;
- av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "
- "Imode: %i, Invert: %i\n", status>>1, status&1);
- } else {
- v->mv_type_is_raw = 0;
- memset(v->mv_type_mb_plane, 0, v->s.mb_stride * v->s.mb_height);
- }
- status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
- if (status < 0) return -1;
- av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
- "Imode: %i, Invert: %i\n", status>>1, status&1);
-
- /* Hopefully this is correct for P frames */
- v->s.mv_table_index = get_bits(gb, 2); //but using vc1_ tables
- v->cbpcy_vlc = &vc1_cbpcy_p_vlc[get_bits(gb, 2)];
-
- if (v->dquant)
- {
- av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
- vop_dquant_decoding(v);
- }
-
- v->ttfrm = 0; //FIXME Is that so ?
- if (v->vstransform)
- {
- v->ttmbf = get_bits(gb, 1);
- if (v->ttmbf)
- {
- v->ttfrm = ttfrm_to_tt[get_bits(gb, 2)];
- }
- } else {
- v->ttmbf = 1;
- v->ttfrm = TT_8X8;
- }
- break;
- case B_TYPE:
- if (v->pq < 5) v->tt_index = 0;
- else if(v->pq < 13) v->tt_index = 1;
- else v->tt_index = 2;
-
- lowquant = (v->pq > 12) ? 0 : 1;
- v->mv_mode = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN;
- v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV);
- v->s.mspel = v->s.quarter_sample;
-
- status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v);
- if (status < 0) return -1;
- av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "
- "Imode: %i, Invert: %i\n", status>>1, status&1);
- status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
- if (status < 0) return -1;
- av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
- "Imode: %i, Invert: %i\n", status>>1, status&1);
-
- v->s.mv_table_index = get_bits(gb, 2);
- v->cbpcy_vlc = &vc1_cbpcy_p_vlc[get_bits(gb, 2)];
-
- if (v->dquant)
- {
- av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
- vop_dquant_decoding(v);
- }
-
- v->ttfrm = 0;
- if (v->vstransform)
- {
- v->ttmbf = get_bits(gb, 1);
- if (v->ttmbf)
- {
- v->ttfrm = ttfrm_to_tt[get_bits(gb, 2)];
- }
- } else {
- v->ttmbf = 1;
- v->ttfrm = TT_8X8;
- }
- break;
- }
-
- /* AC Syntax */
- v->c_ac_table_index = decode012(gb);
- if (v->s.pict_type == I_TYPE || v->s.pict_type == BI_TYPE)
- {
- v->y_ac_table_index = decode012(gb);
- }
- /* DC Syntax */
- v->s.dc_table_index = get_bits(gb, 1);
-
- if(v->s.pict_type == BI_TYPE) {
- v->s.pict_type = B_TYPE;
- v->bi_type = 1;
- }
- return 0;
-}
-
-static int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
-{
- int fcm;
- int pqindex, lowquant;
- int status;
-
- v->p_frame_skipped = 0;
-
- if(v->interlace)
- fcm = decode012(gb);
- switch(get_prefix(gb, 0, 4)) {
- case 0:
- v->s.pict_type = P_TYPE;
- break;
- case 1:
- v->s.pict_type = B_TYPE;
- break;
- case 2:
- v->s.pict_type = I_TYPE;
- break;
- case 3:
- v->s.pict_type = BI_TYPE;
- break;
- case 4:
- v->s.pict_type = P_TYPE; // skipped pic
- v->p_frame_skipped = 1;
- return 0;
- }
- if(v->tfcntrflag)
- get_bits(gb, 8);
- if(v->broadcast) {
- if(!v->interlace || v->panscanflag) {
- get_bits(gb, 2);
- } else {
- get_bits1(gb);
- get_bits1(gb);
- }
- }
- if(v->panscanflag) {
- //...
- }
- v->rnd = get_bits1(gb);
- if(v->interlace)
- v->uvsamp = get_bits1(gb);
- if(v->finterpflag) v->interpfrm = get_bits(gb, 1);
- if(v->s.pict_type == B_TYPE) {
- v->bfraction = get_vlc2(gb, vc1_bfraction_vlc.table, VC1_BFRACTION_VLC_BITS, 1);
- v->bfraction = vc1_bfraction_lut[v->bfraction];
- if(v->bfraction == 0) {
- v->s.pict_type = BI_TYPE; /* XXX: should not happen here */
- }
- }
- pqindex = get_bits(gb, 5);
- v->pqindex = pqindex;
- if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
- v->pq = pquant_table[0][pqindex];
- else
- v->pq = pquant_table[1][pqindex];
-
- v->pquantizer = 1;
- if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
- v->pquantizer = pqindex < 9;
- if (v->quantizer_mode == QUANT_NON_UNIFORM)
- v->pquantizer = 0;
- v->pqindex = pqindex;
- if (pqindex < 9) v->halfpq = get_bits(gb, 1);
- else v->halfpq = 0;
- if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)
- v->pquantizer = get_bits(gb, 1);
-
- switch(v->s.pict_type) {
- case I_TYPE:
- case BI_TYPE:
- status = bitplane_decoding(v->acpred_plane, &v->acpred_is_raw, v);
- if (status < 0) return -1;
- av_log(v->s.avctx, AV_LOG_DEBUG, "ACPRED plane encoding: "
- "Imode: %i, Invert: %i\n", status>>1, status&1);
- v->condover = CONDOVER_NONE;
- if(v->overlap && v->pq <= 8) {
- v->condover = decode012(gb);
- if(v->condover == CONDOVER_SELECT) {
- status = bitplane_decoding(v->over_flags_plane, &v->overflg_is_raw, v);
- if (status < 0) return -1;
- av_log(v->s.avctx, AV_LOG_DEBUG, "CONDOVER plane encoding: "
- "Imode: %i, Invert: %i\n", status>>1, status&1);
- }
- }
- break;
- case P_TYPE:
- if(v->postprocflag)
- v->postproc = get_bits1(gb);
- if (v->extended_mv) v->mvrange = get_prefix(gb, 0, 3);
- else v->mvrange = 0;
- v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
- v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
- v->range_x = 1 << (v->k_x - 1);
- v->range_y = 1 << (v->k_y - 1);
-
- if (v->pq < 5) v->tt_index = 0;
- else if(v->pq < 13) v->tt_index = 1;
- else v->tt_index = 2;
-
- lowquant = (v->pq > 12) ? 0 : 1;
- v->mv_mode = mv_pmode_table[lowquant][get_prefix(gb, 1, 4)];
- if (v->mv_mode == MV_PMODE_INTENSITY_COMP)
- {
- int scale, shift, i;
- v->mv_mode2 = mv_pmode_table2[lowquant][get_prefix(gb, 1, 3)];
- v->lumscale = get_bits(gb, 6);
- v->lumshift = get_bits(gb, 6);
- /* fill lookup tables for intensity compensation */
- if(!v->lumscale) {
- scale = -64;
- shift = (255 - v->lumshift * 2) << 6;
- if(v->lumshift > 31)
- shift += 128 << 6;
- } else {
- scale = v->lumscale + 32;
- if(v->lumshift > 31)
- shift = (v->lumshift - 64) << 6;
- else
- shift = v->lumshift << 6;
- }
- for(i = 0; i < 256; i++) {
- v->luty[i] = clip_uint8((scale * i + shift + 32) >> 6);
- v->lutuv[i] = clip_uint8((scale * (i - 128) + 128*64 + 32) >> 6);
- }
- }
- if(v->mv_mode == MV_PMODE_1MV_HPEL || v->mv_mode == MV_PMODE_1MV_HPEL_BILIN)
- v->s.quarter_sample = 0;
- else if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {
- if(v->mv_mode2 == MV_PMODE_1MV_HPEL || v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN)
- v->s.quarter_sample = 0;
- else
- v->s.quarter_sample = 1;
- } else
- v->s.quarter_sample = 1;
- v->s.mspel = !(v->mv_mode == MV_PMODE_1MV_HPEL_BILIN || (v->mv_mode == MV_PMODE_INTENSITY_COMP && v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN));
-
- if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
- v->mv_mode2 == MV_PMODE_MIXED_MV)
- || v->mv_mode == MV_PMODE_MIXED_MV)
- {
- status = bitplane_decoding(v->mv_type_mb_plane, &v->mv_type_is_raw, v);
- if (status < 0) return -1;
- av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "
- "Imode: %i, Invert: %i\n", status>>1, status&1);
- } else {
- v->mv_type_is_raw = 0;
- memset(v->mv_type_mb_plane, 0, v->s.mb_stride * v->s.mb_height);
- }
- status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
- if (status < 0) return -1;
- av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
- "Imode: %i, Invert: %i\n", status>>1, status&1);
-
- /* Hopefully this is correct for P frames */
- v->s.mv_table_index = get_bits(gb, 2); //but using vc1_ tables
- v->cbpcy_vlc = &vc1_cbpcy_p_vlc[get_bits(gb, 2)];
- if (v->dquant)
- {
- av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
- vop_dquant_decoding(v);
- }
-
- v->ttfrm = 0; //FIXME Is that so ?
- if (v->vstransform)
- {
- v->ttmbf = get_bits(gb, 1);
- if (v->ttmbf)
- {
- v->ttfrm = ttfrm_to_tt[get_bits(gb, 2)];
- }
- } else {
- v->ttmbf = 1;
- v->ttfrm = TT_8X8;
- }
- break;
- case B_TYPE:
- if(v->postprocflag)
- v->postproc = get_bits1(gb);
- if (v->extended_mv) v->mvrange = get_prefix(gb, 0, 3);
- else v->mvrange = 0;
- v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
- v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
- v->range_x = 1 << (v->k_x - 1);
- v->range_y = 1 << (v->k_y - 1);
-
- if (v->pq < 5) v->tt_index = 0;
- else if(v->pq < 13) v->tt_index = 1;
- else v->tt_index = 2;
-
- lowquant = (v->pq > 12) ? 0 : 1;
- v->mv_mode = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN;
- v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV);
- v->s.mspel = v->s.quarter_sample;
-
- status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v);
- if (status < 0) return -1;
- av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "
- "Imode: %i, Invert: %i\n", status>>1, status&1);
- status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
- if (status < 0) return -1;
- av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
- "Imode: %i, Invert: %i\n", status>>1, status&1);
-
- v->s.mv_table_index = get_bits(gb, 2);
- v->cbpcy_vlc = &vc1_cbpcy_p_vlc[get_bits(gb, 2)];
-
- if (v->dquant)
- {
- av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
- vop_dquant_decoding(v);
- }
-
- v->ttfrm = 0;
- if (v->vstransform)
- {
- v->ttmbf = get_bits(gb, 1);
- if (v->ttmbf)
- {
- v->ttfrm = ttfrm_to_tt[get_bits(gb, 2)];
- }
- } else {
- v->ttmbf = 1;
- v->ttfrm = TT_8X8;
- }
- break;
- }
-
- /* AC Syntax */
- v->c_ac_table_index = decode012(gb);
- if (v->s.pict_type == I_TYPE || v->s.pict_type == BI_TYPE)
- {
- v->y_ac_table_index = decode012(gb);
- }
- /* DC Syntax */
- v->s.dc_table_index = get_bits(gb, 1);
- if (v->s.pict_type == I_TYPE && v->dquant) {
- av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
- vop_dquant_decoding(v);
- }
-
- v->bi_type = 0;
- if(v->s.pict_type == BI_TYPE) {
- v->s.pict_type = B_TYPE;
- v->bi_type = 1;
- }
- return 0;
-}
-
-/***********************************************************************/
-/**
- * @defgroup block VC-1 Block-level functions
- * @see 7.1.4, p91 and 8.1.1.7, p(1)04
- * @{
- */
-
-/**
- * @def GET_MQUANT
- * @brief Get macroblock-level quantizer scale
- */
-#define GET_MQUANT() \
- if (v->dquantfrm) \
- { \
- int edges = 0; \
- if (v->dqprofile == DQPROFILE_ALL_MBS) \
- { \
- if (v->dqbilevel) \
- { \
- mquant = (get_bits(gb, 1)) ? v->altpq : v->pq; \
- } \
- else \
- { \
- mqdiff = get_bits(gb, 3); \
- if (mqdiff != 7) mquant = v->pq + mqdiff; \
- else mquant = get_bits(gb, 5); \
- } \
- } \
- if(v->dqprofile == DQPROFILE_SINGLE_EDGE) \
- edges = 1 << v->dqsbedge; \
- else if(v->dqprofile == DQPROFILE_DOUBLE_EDGES) \
- edges = (3 << v->dqsbedge) % 15; \
- else if(v->dqprofile == DQPROFILE_FOUR_EDGES) \
- edges = 15; \
- if((edges&1) && !s->mb_x) \
- mquant = v->altpq; \
- if((edges&2) && s->first_slice_line) \
- mquant = v->altpq; \
- if((edges&4) && s->mb_x == (s->mb_width - 1)) \
- mquant = v->altpq; \
- if((edges&8) && s->mb_y == (s->mb_height - 1)) \
- mquant = v->altpq; \
- }
-
-/**
- * @def GET_MVDATA(_dmv_x, _dmv_y)
- * @brief Get MV differentials
- * @see MVDATA decoding from 8.3.5.2, p(1)20
- * @param _dmv_x Horizontal differential for decoded MV
- * @param _dmv_y Vertical differential for decoded MV
- */
-#define GET_MVDATA(_dmv_x, _dmv_y) \
- index = 1 + get_vlc2(gb, vc1_mv_diff_vlc[s->mv_table_index].table,\
- VC1_MV_DIFF_VLC_BITS, 2); \
- if (index > 36) \
- { \
- mb_has_coeffs = 1; \
- index -= 37; \
- } \
- else mb_has_coeffs = 0; \
- s->mb_intra = 0; \
- if (!index) { _dmv_x = _dmv_y = 0; } \
- else if (index == 35) \
- { \
- _dmv_x = get_bits(gb, v->k_x - 1 + s->quarter_sample); \
- _dmv_y = get_bits(gb, v->k_y - 1 + s->quarter_sample); \
- } \
- else if (index == 36) \
- { \
- _dmv_x = 0; \
- _dmv_y = 0; \
- s->mb_intra = 1; \
- } \
- else \
- { \
- index1 = index%6; \
- if (!s->quarter_sample && index1 == 5) val = 1; \
- else val = 0; \
- if(size_table[index1] - val > 0) \
- val = get_bits(gb, size_table[index1] - val); \
- else val = 0; \
- sign = 0 - (val&1); \
- _dmv_x = (sign ^ ((val>>1) + offset_table[index1])) - sign; \
- \
- index1 = index/6; \
- if (!s->quarter_sample && index1 == 5) val = 1; \
- else val = 0; \
- if(size_table[index1] - val > 0) \
- val = get_bits(gb, size_table[index1] - val); \
- else val = 0; \
- sign = 0 - (val&1); \
- _dmv_y = (sign ^ ((val>>1) + offset_table[index1])) - sign; \
- }
-
-/** Predict and set motion vector
- */
-static inline void vc1_pred_mv(MpegEncContext *s, int n, int dmv_x, int dmv_y, int mv1, int r_x, int r_y, uint8_t* is_intra)
-{
- int xy, wrap, off = 0;
- int16_t *A, *B, *C;
- int px, py;
- int sum;
-
- /* scale MV difference to be quad-pel */
- dmv_x <<= 1 - s->quarter_sample;
- dmv_y <<= 1 - s->quarter_sample;
-
- wrap = s->b8_stride;
- xy = s->block_index[n];
-
- if(s->mb_intra){
- s->mv[0][n][0] = s->current_picture.motion_val[0][xy][0] = 0;
- s->mv[0][n][1] = s->current_picture.motion_val[0][xy][1] = 0;
- if(mv1) { /* duplicate motion data for 1-MV block */
- s->current_picture.motion_val[0][xy + 1][0] = 0;
- s->current_picture.motion_val[0][xy + 1][1] = 0;
- s->current_picture.motion_val[0][xy + wrap][0] = 0;
- s->current_picture.motion_val[0][xy + wrap][1] = 0;
- s->current_picture.motion_val[0][xy + wrap + 1][0] = 0;
- s->current_picture.motion_val[0][xy + wrap + 1][1] = 0;
- }
- return;
- }
-
- C = s->current_picture.motion_val[0][xy - 1];
- A = s->current_picture.motion_val[0][xy - wrap];
- if(mv1)
- off = (s->mb_x == (s->mb_width - 1)) ? -1 : 2;
- else {
- //in 4-MV mode different blocks have different B predictor position
- switch(n){
- case 0:
- off = (s->mb_x > 0) ? -1 : 1;
- break;
- case 1:
- off = (s->mb_x == (s->mb_width - 1)) ? -1 : 1;
- break;
- case 2:
- off = 1;
- break;
- case 3:
- off = -1;
- }
- }
- B = s->current_picture.motion_val[0][xy - wrap + off];
-
- if(!s->first_slice_line || (n==2 || n==3)) { // predictor A is not out of bounds
- if(s->mb_width == 1) {
- px = A[0];
- py = A[1];
- } else {
- px = mid_pred(A[0], B[0], C[0]);
- py = mid_pred(A[1], B[1], C[1]);
- }
- } else if(s->mb_x || (n==1 || n==3)) { // predictor C is not out of bounds
- px = C[0];
- py = C[1];
- } else {
- px = py = 0;
- }
- /* Pullback MV as specified in 8.3.5.3.4 */
- {
- int qx, qy, X, Y;
- qx = (s->mb_x << 6) + ((n==1 || n==3) ? 32 : 0);
- qy = (s->mb_y << 6) + ((n==2 || n==3) ? 32 : 0);
- X = (s->mb_width << 6) - 4;
- Y = (s->mb_height << 6) - 4;
- if(mv1) {
- if(qx + px < -60) px = -60 - qx;
- if(qy + py < -60) py = -60 - qy;
- } else {
- if(qx + px < -28) px = -28 - qx;
- if(qy + py < -28) py = -28 - qy;
- }
- if(qx + px > X) px = X - qx;
- if(qy + py > Y) py = Y - qy;
- }
- /* Calculate hybrid prediction as specified in 8.3.5.3.5 */
- if((!s->first_slice_line || (n==2 || n==3)) && (s->mb_x || (n==1 || n==3))) {
- if(is_intra[xy - wrap])
- sum = FFABS(px) + FFABS(py);
- else
- sum = FFABS(px - A[0]) + FFABS(py - A[1]);
- if(sum > 32) {
- if(get_bits1(&s->gb)) {
- px = A[0];
- py = A[1];
- } else {
- px = C[0];
- py = C[1];
- }
- } else {
- if(is_intra[xy - 1])
- sum = FFABS(px) + FFABS(py);
- else
- sum = FFABS(px - C[0]) + FFABS(py - C[1]);
- if(sum > 32) {
- if(get_bits1(&s->gb)) {
- px = A[0];
- py = A[1];
- } else {
- px = C[0];
- py = C[1];
- }
- }
- }
- }
- /* store MV using signed modulus of MV range defined in 4.11 */
- s->mv[0][n][0] = s->current_picture.motion_val[0][xy][0] = ((px + dmv_x + r_x) & ((r_x << 1) - 1)) - r_x;
- s->mv[0][n][1] = s->current_picture.motion_val[0][xy][1] = ((py + dmv_y + r_y) & ((r_y << 1) - 1)) - r_y;
- if(mv1) { /* duplicate motion data for 1-MV block */
- s->current_picture.motion_val[0][xy + 1][0] = s->current_picture.motion_val[0][xy][0];
- s->current_picture.motion_val[0][xy + 1][1] = s->current_picture.motion_val[0][xy][1];
- s->current_picture.motion_val[0][xy + wrap][0] = s->current_picture.motion_val[0][xy][0];
- s->current_picture.motion_val[0][xy + wrap][1] = s->current_picture.motion_val[0][xy][1];
- s->current_picture.motion_val[0][xy + wrap + 1][0] = s->current_picture.motion_val[0][xy][0];
- s->current_picture.motion_val[0][xy + wrap + 1][1] = s->current_picture.motion_val[0][xy][1];
- }
-}
-
-/** Motion compensation for direct or interpolated blocks in B-frames
- */
-static void vc1_interp_mc(VC1Context *v)
-{
- MpegEncContext *s = &v->s;
- DSPContext *dsp = &v->s.dsp;
- uint8_t *srcY, *srcU, *srcV;
- int dxy, uvdxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y;
-
- if(!v->s.next_picture.data[0])return;
-
- mx = s->mv[1][0][0];
- my = s->mv[1][0][1];
- uvmx = (mx + ((mx & 3) == 3)) >> 1;
- uvmy = (my + ((my & 3) == 3)) >> 1;
- if(v->fastuvmc) {
- uvmx = uvmx + ((uvmx<0)?-(uvmx&1):(uvmx&1));
- uvmy = uvmy + ((uvmy<0)?-(uvmy&1):(uvmy&1));
- }
- srcY = s->next_picture.data[0];
- srcU = s->next_picture.data[1];
- srcV = s->next_picture.data[2];
-
- src_x = s->mb_x * 16 + (mx >> 2);
- src_y = s->mb_y * 16 + (my >> 2);
- uvsrc_x = s->mb_x * 8 + (uvmx >> 2);
- uvsrc_y = s->mb_y * 8 + (uvmy >> 2);
-
- src_x = clip( src_x, -16, s->mb_width * 16);
- src_y = clip( src_y, -16, s->mb_height * 16);
- uvsrc_x = clip(uvsrc_x, -8, s->mb_width * 8);
- uvsrc_y = clip(uvsrc_y, -8, s->mb_height * 8);
-
- srcY += src_y * s->linesize + src_x;
- srcU += uvsrc_y * s->uvlinesize + uvsrc_x;
- srcV += uvsrc_y * s->uvlinesize + uvsrc_x;
-
- /* for grayscale we should not try to read from unknown area */
- if(s->flags & CODEC_FLAG_GRAY) {
- srcU = s->edge_emu_buffer + 18 * s->linesize;
- srcV = s->edge_emu_buffer + 18 * s->linesize;
- }
-
- if(v->rangeredfrm
- || (unsigned)src_x > s->h_edge_pos - (mx&3) - 16
- || (unsigned)src_y > s->v_edge_pos - (my&3) - 16){
- uint8_t *uvbuf= s->edge_emu_buffer + 19 * s->linesize;
-
- srcY -= s->mspel * (1 + s->linesize);
- ff_emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize, 17+s->mspel*2, 17+s->mspel*2,
- src_x - s->mspel, src_y - s->mspel, s->h_edge_pos, s->v_edge_pos);
- srcY = s->edge_emu_buffer;
- ff_emulated_edge_mc(uvbuf , srcU, s->uvlinesize, 8+1, 8+1,
- uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
- ff_emulated_edge_mc(uvbuf + 16, srcV, s->uvlinesize, 8+1, 8+1,
- uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
- srcU = uvbuf;
- srcV = uvbuf + 16;
- /* if we deal with range reduction we need to scale source blocks */
- if(v->rangeredfrm) {
- int i, j;
- uint8_t *src, *src2;
-
- src = srcY;
- for(j = 0; j < 17 + s->mspel*2; j++) {
- for(i = 0; i < 17 + s->mspel*2; i++) src[i] = ((src[i] - 128) >> 1) + 128;
- src += s->linesize;
- }
- src = srcU; src2 = srcV;
- for(j = 0; j < 9; j++) {
- for(i = 0; i < 9; i++) {
- src[i] = ((src[i] - 128) >> 1) + 128;
- src2[i] = ((src2[i] - 128) >> 1) + 128;
- }
- src += s->uvlinesize;
- src2 += s->uvlinesize;
- }
- }
- srcY += s->mspel * (1 + s->linesize);
- }
-
- mx >>= 1;
- my >>= 1;
- dxy = ((my & 1) << 1) | (mx & 1);
-
- dsp->avg_pixels_tab[0][dxy](s->dest[0], srcY, s->linesize, 16);
-
- if(s->flags & CODEC_FLAG_GRAY) return;
- /* Chroma MC always uses qpel blilinear */
- uvdxy = ((uvmy & 3) << 2) | (uvmx & 3);
- uvmx = (uvmx&3)<<1;
- uvmy = (uvmy&3)<<1;
- dsp->avg_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);
- dsp->avg_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);
-}
-
-static av_always_inline int scale_mv(int value, int bfrac, int inv, int qs)
-{
- int n = bfrac;
-
-#if B_FRACTION_DEN==256
- if(inv)
- n -= 256;
- if(!qs)
- return 2 * ((value * n + 255) >> 9);
- return (value * n + 128) >> 8;
-#else
- if(inv)
- n -= B_FRACTION_DEN;
- if(!qs)
- return 2 * ((value * n + B_FRACTION_DEN - 1) / (2 * B_FRACTION_DEN));
- return (value * n + B_FRACTION_DEN/2) / B_FRACTION_DEN;
-#endif
-}
-
-/** Reconstruct motion vector for B-frame and do motion compensation
- */
-static inline void vc1_b_mc(VC1Context *v, int dmv_x[2], int dmv_y[2], int direct, int mode)
-{
- if(v->use_ic) {
- v->mv_mode2 = v->mv_mode;
- v->mv_mode = MV_PMODE_INTENSITY_COMP;
- }
- if(direct) {
- vc1_mc_1mv(v, 0);
- vc1_interp_mc(v);
- if(v->use_ic) v->mv_mode = v->mv_mode2;
- return;
- }
- if(mode == BMV_TYPE_INTERPOLATED) {
- vc1_mc_1mv(v, 0);
- vc1_interp_mc(v);
- if(v->use_ic) v->mv_mode = v->mv_mode2;
- return;
- }
-
- if(v->use_ic && (mode == BMV_TYPE_BACKWARD)) v->mv_mode = v->mv_mode2;
- vc1_mc_1mv(v, (mode == BMV_TYPE_BACKWARD));
- if(v->use_ic) v->mv_mode = v->mv_mode2;
-}
-
-static inline void vc1_pred_b_mv(VC1Context *v, int dmv_x[2], int dmv_y[2], int direct, int mvtype)
-{
- MpegEncContext *s = &v->s;
- int xy, wrap, off = 0;
- int16_t *A, *B, *C;
- int px, py;
- int sum;
- int r_x, r_y;
- const uint8_t *is_intra = v->mb_type[0];
-
- r_x = v->range_x;
- r_y = v->range_y;
- /* scale MV difference to be quad-pel */
- dmv_x[0] <<= 1 - s->quarter_sample;
- dmv_y[0] <<= 1 - s->quarter_sample;
- dmv_x[1] <<= 1 - s->quarter_sample;
- dmv_y[1] <<= 1 - s->quarter_sample;
-
- wrap = s->b8_stride;
- xy = s->block_index[0];
-
- if(s->mb_intra) {
- s->current_picture.motion_val[0][xy][0] =
- s->current_picture.motion_val[0][xy][1] =
- s->current_picture.motion_val[1][xy][0] =
- s->current_picture.motion_val[1][xy][1] = 0;
- return;
- }
- s->mv[0][0][0] = scale_mv(s->next_picture.motion_val[1][xy][0], v->bfraction, 0, s->quarter_sample);
- s->mv[0][0][1] = scale_mv(s->next_picture.motion_val[1][xy][1], v->bfraction, 0, s->quarter_sample);
- s->mv[1][0][0] = scale_mv(s->next_picture.motion_val[1][xy][0], v->bfraction, 1, s->quarter_sample);
- s->mv[1][0][1] = scale_mv(s->next_picture.motion_val[1][xy][1], v->bfraction, 1, s->quarter_sample);
- if(direct) {
- s->current_picture.motion_val[0][xy][0] = s->mv[0][0][0];
- s->current_picture.motion_val[0][xy][1] = s->mv[0][0][1];
- s->current_picture.motion_val[1][xy][0] = s->mv[1][0][0];
- s->current_picture.motion_val[1][xy][1] = s->mv[1][0][1];
- return;
- }
-
- if((mvtype == BMV_TYPE_FORWARD) || (mvtype == BMV_TYPE_INTERPOLATED)) {
- C = s->current_picture.motion_val[0][xy - 2];
- A = s->current_picture.motion_val[0][xy - wrap*2];
- off = (s->mb_x == (s->mb_width - 1)) ? -2 : 2;
- B = s->current_picture.motion_val[0][xy - wrap*2 + off];
-
- if(!s->first_slice_line) { // predictor A is not out of bounds
- if(s->mb_width == 1) {
- px = A[0];
- py = A[1];
- } else {
- px = mid_pred(A[0], B[0], C[0]);
- py = mid_pred(A[1], B[1], C[1]);
- }
- } else if(s->mb_x) { // predictor C is not out of bounds
- px = C[0];
- py = C[1];
- } else {
- px = py = 0;
- }
- /* Pullback MV as specified in 8.3.5.3.4 */
- {
- int qx, qy, X, Y;
- if(v->profile < PROFILE_ADVANCED) {
- qx = (s->mb_x << 5);
- qy = (s->mb_y << 5);
- X = (s->mb_width << 5) - 4;
- Y = (s->mb_height << 5) - 4;
- if(qx + px < -28) px = -28 - qx;
- if(qy + py < -28) py = -28 - qy;
- if(qx + px > X) px = X - qx;
- if(qy + py > Y) py = Y - qy;
- } else {
- qx = (s->mb_x << 6);
- qy = (s->mb_y << 6);
- X = (s->mb_width << 6) - 4;
- Y = (s->mb_height << 6) - 4;
- if(qx + px < -60) px = -60 - qx;
- if(qy + py < -60) py = -60 - qy;
- if(qx + px > X) px = X - qx;
- if(qy + py > Y) py = Y - qy;
- }
- }
- /* Calculate hybrid prediction as specified in 8.3.5.3.5 */
- if(0 && !s->first_slice_line && s->mb_x) {
- if(is_intra[xy - wrap])
- sum = FFABS(px) + FFABS(py);
- else
- sum = FFABS(px - A[0]) + FFABS(py - A[1]);
- if(sum > 32) {
- if(get_bits1(&s->gb)) {
- px = A[0];
- py = A[1];
- } else {
- px = C[0];
- py = C[1];
- }
- } else {
- if(is_intra[xy - 2])
- sum = FFABS(px) + FFABS(py);
- else
- sum = FFABS(px - C[0]) + FFABS(py - C[1]);
- if(sum > 32) {
- if(get_bits1(&s->gb)) {
- px = A[0];
- py = A[1];
- } else {
- px = C[0];
- py = C[1];
- }
- }
- }
- }
- /* store MV using signed modulus of MV range defined in 4.11 */
- s->mv[0][0][0] = ((px + dmv_x[0] + r_x) & ((r_x << 1) - 1)) - r_x;
- s->mv[0][0][1] = ((py + dmv_y[0] + r_y) & ((r_y << 1) - 1)) - r_y;
- }
- if((mvtype == BMV_TYPE_BACKWARD) || (mvtype == BMV_TYPE_INTERPOLATED)) {
- C = s->current_picture.motion_val[1][xy - 2];
- A = s->current_picture.motion_val[1][xy - wrap*2];
- off = (s->mb_x == (s->mb_width - 1)) ? -2 : 2;
- B = s->current_picture.motion_val[1][xy - wrap*2 + off];
-
- if(!s->first_slice_line) { // predictor A is not out of bounds
- if(s->mb_width == 1) {
- px = A[0];
- py = A[1];
- } else {
- px = mid_pred(A[0], B[0], C[0]);
- py = mid_pred(A[1], B[1], C[1]);
- }
- } else if(s->mb_x) { // predictor C is not out of bounds
- px = C[0];
- py = C[1];
- } else {
- px = py = 0;
- }
- /* Pullback MV as specified in 8.3.5.3.4 */
- {
- int qx, qy, X, Y;
- if(v->profile < PROFILE_ADVANCED) {
- qx = (s->mb_x << 5);
- qy = (s->mb_y << 5);
- X = (s->mb_width << 5) - 4;
- Y = (s->mb_height << 5) - 4;
- if(qx + px < -28) px = -28 - qx;
- if(qy + py < -28) py = -28 - qy;
- if(qx + px > X) px = X - qx;
- if(qy + py > Y) py = Y - qy;
- } else {
- qx = (s->mb_x << 6);
- qy = (s->mb_y << 6);
- X = (s->mb_width << 6) - 4;
- Y = (s->mb_height << 6) - 4;
- if(qx + px < -60) px = -60 - qx;
- if(qy + py < -60) py = -60 - qy;
- if(qx + px > X) px = X - qx;
- if(qy + py > Y) py = Y - qy;
- }
- }
- /* Calculate hybrid prediction as specified in 8.3.5.3.5 */
- if(0 && !s->first_slice_line && s->mb_x) {
- if(is_intra[xy - wrap])
- sum = FFABS(px) + FFABS(py);
- else
- sum = FFABS(px - A[0]) + FFABS(py - A[1]);
- if(sum > 32) {
- if(get_bits1(&s->gb)) {
- px = A[0];
- py = A[1];
- } else {
- px = C[0];
- py = C[1];
- }
- } else {
- if(is_intra[xy - 2])
- sum = FFABS(px) + FFABS(py);
- else
- sum = FFABS(px - C[0]) + FFABS(py - C[1]);
- if(sum > 32) {
- if(get_bits1(&s->gb)) {
- px = A[0];
- py = A[1];
- } else {
- px = C[0];
- py = C[1];
- }
- }
- }
- }
- /* store MV using signed modulus of MV range defined in 4.11 */
-
- s->mv[1][0][0] = ((px + dmv_x[1] + r_x) & ((r_x << 1) - 1)) - r_x;
- s->mv[1][0][1] = ((py + dmv_y[1] + r_y) & ((r_y << 1) - 1)) - r_y;
- }
- s->current_picture.motion_val[0][xy][0] = s->mv[0][0][0];
- s->current_picture.motion_val[0][xy][1] = s->mv[0][0][1];
- s->current_picture.motion_val[1][xy][0] = s->mv[1][0][0];
- s->current_picture.motion_val[1][xy][1] = s->mv[1][0][1];
-}
-
-/** Get predicted DC value for I-frames only
- * prediction dir: left=0, top=1
- * @param s MpegEncContext
- * @param[in] n block index in the current MB
- * @param dc_val_ptr Pointer to DC predictor
- * @param dir_ptr Prediction direction for use in AC prediction
- */
-static inline int vc1_i_pred_dc(MpegEncContext *s, int overlap, int pq, int n,
- int16_t **dc_val_ptr, int *dir_ptr)
-{
- int a, b, c, wrap, pred, scale;
- int16_t *dc_val;
- static const uint16_t dcpred[32] = {
- -1, 1024, 512, 341, 256, 205, 171, 146, 128,
- 114, 102, 93, 85, 79, 73, 68, 64,
- 60, 57, 54, 51, 49, 47, 45, 43,
- 41, 39, 38, 37, 35, 34, 33
- };
-
- /* find prediction - wmv3_dc_scale always used here in fact */
- if (n < 4) scale = s->y_dc_scale;
- else scale = s->c_dc_scale;
-
- wrap = s->block_wrap[n];
- dc_val= s->dc_val[0] + s->block_index[n];
-
- /* B A
- * C X
- */
- c = dc_val[ - 1];
- b = dc_val[ - 1 - wrap];
- a = dc_val[ - wrap];
-
- if (pq < 9 || !overlap)
- {
- /* Set outer values */
- if (s->first_slice_line && (n!=2 && n!=3)) b=a=dcpred[scale];
- if (s->mb_x == 0 && (n!=1 && n!=3)) b=c=dcpred[scale];
- }
- else
- {
- /* Set outer values */
- if (s->first_slice_line && (n!=2 && n!=3)) b=a=0;
- if (s->mb_x == 0 && (n!=1 && n!=3)) b=c=0;
- }
-
- if (abs(a - b) <= abs(b - c)) {
- pred = c;
- *dir_ptr = 1;//left
- } else {
- pred = a;
- *dir_ptr = 0;//top
- }
-
- /* update predictor */
- *dc_val_ptr = &dc_val[0];
- return pred;
-}
-
-
-/** Get predicted DC value
- * prediction dir: left=0, top=1
- * @param s MpegEncContext
- * @param[in] n block index in the current MB
- * @param dc_val_ptr Pointer to DC predictor
- * @param dir_ptr Prediction direction for use in AC prediction
- */
-static inline int vc1_pred_dc(MpegEncContext *s, int overlap, int pq, int n,
- int a_avail, int c_avail,
- int16_t **dc_val_ptr, int *dir_ptr)
-{
- int a, b, c, wrap, pred, scale;
- int16_t *dc_val;
- int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
- int q1, q2 = 0;
-
- /* find prediction - wmv3_dc_scale always used here in fact */
- if (n < 4) scale = s->y_dc_scale;
- else scale = s->c_dc_scale;
-
- wrap = s->block_wrap[n];
- dc_val= s->dc_val[0] + s->block_index[n];
-
- /* B A
- * C X
- */
- c = dc_val[ - 1];
- b = dc_val[ - 1 - wrap];
- a = dc_val[ - wrap];
- /* scale predictors if needed */
- q1 = s->current_picture.qscale_table[mb_pos];
- if(c_avail && (n!= 1 && n!=3)) {
- q2 = s->current_picture.qscale_table[mb_pos - 1];
- if(q2 && q2 != q1)
- c = (c * s->y_dc_scale_table[q2] * vc1_dqscale[s->y_dc_scale_table[q1] - 1] + 0x20000) >> 18;
- }
- if(a_avail && (n!= 2 && n!=3)) {
- q2 = s->current_picture.qscale_table[mb_pos - s->mb_stride];
- if(q2 && q2 != q1)
- a = (a * s->y_dc_scale_table[q2] * vc1_dqscale[s->y_dc_scale_table[q1] - 1] + 0x20000) >> 18;
- }
- if(a_avail && c_avail && (n!=3)) {
- int off = mb_pos;
- if(n != 1) off--;
- if(n != 2) off -= s->mb_stride;
- q2 = s->current_picture.qscale_table[off];
- if(q2 && q2 != q1)
- b = (b * s->y_dc_scale_table[q2] * vc1_dqscale[s->y_dc_scale_table[q1] - 1] + 0x20000) >> 18;
- }
-
- if(a_avail && c_avail) {
- if(abs(a - b) <= abs(b - c)) {
- pred = c;
- *dir_ptr = 1;//left
- } else {
- pred = a;
- *dir_ptr = 0;//top
- }
- } else if(a_avail) {
- pred = a;
- *dir_ptr = 0;//top
- } else if(c_avail) {
- pred = c;
- *dir_ptr = 1;//left
- } else {
- pred = 0;
- *dir_ptr = 1;//left
- }
-
- /* update predictor */
- *dc_val_ptr = &dc_val[0];
- return pred;
-}
-
-
-/**
- * @defgroup std_mb VC1 Macroblock-level functions in Simple/Main Profiles
- * @see 7.1.4, p91 and 8.1.1.7, p(1)04
- * @{
- */
-
-static inline int vc1_coded_block_pred(MpegEncContext * s, int n, uint8_t **coded_block_ptr)
-{
- int xy, wrap, pred, a, b, c;
-
- xy = s->block_index[n];
- wrap = s->b8_stride;
-
- /* B C
- * A X
- */
- a = s->coded_block[xy - 1 ];
- b = s->coded_block[xy - 1 - wrap];
- c = s->coded_block[xy - wrap];
-
- if (b == c) {
- pred = a;
- } else {
- pred = c;
- }
-
- /* store value */
- *coded_block_ptr = &s->coded_block[xy];
-
- return pred;
-}
-
-/**
- * Decode one AC coefficient
- * @param v The VC1 context
- * @param last Last coefficient
- * @param skip How much zero coefficients to skip
- * @param value Decoded AC coefficient value
- * @see 8.1.3.4
- */
-static void vc1_decode_ac_coeff(VC1Context *v, int *last, int *skip, int *value, int codingset)
-{
- GetBitContext *gb = &v->s.gb;
- int index, escape, run = 0, level = 0, lst = 0;
-
- index = get_vlc2(gb, vc1_ac_coeff_table[codingset].table, AC_VLC_BITS, 3);
- if (index != vc1_ac_sizes[codingset] - 1) {
- run = vc1_index_decode_table[codingset][index][0];
- level = vc1_index_decode_table[codingset][index][1];
- lst = index >= vc1_last_decode_table[codingset];
- if(get_bits(gb, 1))
- level = -level;
- } else {
- escape = decode210(gb);
- if (escape != 2) {
- index = get_vlc2(gb, vc1_ac_coeff_table[codingset].table, AC_VLC_BITS, 3);
- run = vc1_index_decode_table[codingset][index][0];
- level = vc1_index_decode_table[codingset][index][1];
- lst = index >= vc1_last_decode_table[codingset];
- if(escape == 0) {
- if(lst)
- level += vc1_last_delta_level_table[codingset][run];
- else
- level += vc1_delta_level_table[codingset][run];
- } else {
- if(lst)
- run += vc1_last_delta_run_table[codingset][level] + 1;
- else
- run += vc1_delta_run_table[codingset][level] + 1;
- }
- if(get_bits(gb, 1))
- level = -level;
- } else {
- int sign;
- lst = get_bits(gb, 1);
- if(v->s.esc3_level_length == 0) {
- if(v->pq < 8 || v->dquantfrm) { // table 59
- v->s.esc3_level_length = get_bits(gb, 3);
- if(!v->s.esc3_level_length)
- v->s.esc3_level_length = get_bits(gb, 2) + 8;
- } else { //table 60
- v->s.esc3_level_length = get_prefix(gb, 1, 6) + 2;
- }
- v->s.esc3_run_length = 3 + get_bits(gb, 2);
- }
- run = get_bits(gb, v->s.esc3_run_length);
- sign = get_bits(gb, 1);
- level = get_bits(gb, v->s.esc3_level_length);
- if(sign)
- level = -level;
- }
- }
-
- *last = lst;
- *skip = run;
- *value = level;
-}
-
-/** Decode intra block in intra frames - should be faster than decode_intra_block
- * @param v VC1Context
- * @param block block to decode
- * @param coded are AC coeffs present or not
- * @param codingset set of VLC to decode data
- */
-static int vc1_decode_i_block(VC1Context *v, DCTELEM block[64], int n, int coded, int codingset)
-{
- GetBitContext *gb = &v->s.gb;
- MpegEncContext *s = &v->s;
- int dc_pred_dir = 0; /* Direction of the DC prediction used */
- int run_diff, i;
- int16_t *dc_val;
- int16_t *ac_val, *ac_val2;
- int dcdiff;
-
- /* Get DC differential */
- if (n < 4) {
- dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
- } else {
- dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
- }
- if (dcdiff < 0){
- av_log(s->avctx, AV_LOG_ERROR, "Illegal DC VLC\n");
- return -1;
- }
- if (dcdiff)
- {
- if (dcdiff == 119 /* ESC index value */)
- {
- /* TODO: Optimize */
- if (v->pq == 1) dcdiff = get_bits(gb, 10);
- else if (v->pq == 2) dcdiff = get_bits(gb, 9);
- else dcdiff = get_bits(gb, 8);
- }
- else
- {
- if (v->pq == 1)
- dcdiff = (dcdiff<<2) + get_bits(gb, 2) - 3;
- else if (v->pq == 2)
- dcdiff = (dcdiff<<1) + get_bits(gb, 1) - 1;
- }
- if (get_bits(gb, 1))
- dcdiff = -dcdiff;
- }
-
- /* Prediction */
- dcdiff += vc1_i_pred_dc(&v->s, v->overlap, v->pq, n, &dc_val, &dc_pred_dir);
- *dc_val = dcdiff;
-
- /* Store the quantized DC coeff, used for prediction */
- if (n < 4) {
- block[0] = dcdiff * s->y_dc_scale;
- } else {
- block[0] = dcdiff * s->c_dc_scale;
- }
- /* Skip ? */
- run_diff = 0;
- i = 0;
- if (!coded) {
- goto not_coded;
- }
-
- //AC Decoding
- i = 1;
-
- {
- int last = 0, skip, value;
- const int8_t *zz_table;
- int scale;
- int k;
-
- scale = v->pq * 2 + v->halfpq;
-
- if(v->s.ac_pred) {
- if(!dc_pred_dir)
- zz_table = vc1_horizontal_zz;
- else
- zz_table = vc1_vertical_zz;
- } else
- zz_table = vc1_normal_zz;
-
- ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
- ac_val2 = ac_val;
- if(dc_pred_dir) //left
- ac_val -= 16;
- else //top
- ac_val -= 16 * s->block_wrap[n];
-
- while (!last) {
- vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);
- i += skip;
- if(i > 63)
- break;
- block[zz_table[i++]] = value;
- }
-
- /* apply AC prediction if needed */
- if(s->ac_pred) {
- if(dc_pred_dir) { //left
- for(k = 1; k < 8; k++)
- block[k << 3] += ac_val[k];
- } else { //top
- for(k = 1; k < 8; k++)
- block[k] += ac_val[k + 8];
- }
- }
- /* save AC coeffs for further prediction */
- for(k = 1; k < 8; k++) {
- ac_val2[k] = block[k << 3];
- ac_val2[k + 8] = block[k];
- }
-
- /* scale AC coeffs */
- for(k = 1; k < 64; k++)
- if(block[k]) {
- block[k] *= scale;
- if(!v->pquantizer)
- block[k] += (block[k] < 0) ? -v->pq : v->pq;
- }
-
- if(s->ac_pred) i = 63;
- }
-
-not_coded:
- if(!coded) {
- int k, scale;
- ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
- ac_val2 = ac_val;
-
- scale = v->pq * 2 + v->halfpq;
- memset(ac_val2, 0, 16 * 2);
- if(dc_pred_dir) {//left
- ac_val -= 16;
- if(s->ac_pred)
- memcpy(ac_val2, ac_val, 8 * 2);
- } else {//top
- ac_val -= 16 * s->block_wrap[n];
- if(s->ac_pred)
- memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
- }
-
- /* apply AC prediction if needed */
- if(s->ac_pred) {
- if(dc_pred_dir) { //left
- for(k = 1; k < 8; k++) {
- block[k << 3] = ac_val[k] * scale;
- if(!v->pquantizer && block[k << 3])
- block[k << 3] += (block[k << 3] < 0) ? -v->pq : v->pq;
- }
- } else { //top
- for(k = 1; k < 8; k++) {
- block[k] = ac_val[k + 8] * scale;
- if(!v->pquantizer && block[k])
- block[k] += (block[k] < 0) ? -v->pq : v->pq;
- }
- }
- i = 63;
- }
- }
- s->block_last_index[n] = i;
-
- return 0;
-}
-
-/** Decode intra block in intra frames - should be faster than decode_intra_block
- * @param v VC1Context
- * @param block block to decode
- * @param coded are AC coeffs present or not
- * @param codingset set of VLC to decode data
- */
-static int vc1_decode_i_block_adv(VC1Context *v, DCTELEM block[64], int n, int coded, int codingset, int mquant)
-{
- GetBitContext *gb = &v->s.gb;
- MpegEncContext *s = &v->s;
- int dc_pred_dir = 0; /* Direction of the DC prediction used */
- int run_diff, i;
- int16_t *dc_val;
- int16_t *ac_val, *ac_val2;
- int dcdiff;
- int a_avail = v->a_avail, c_avail = v->c_avail;
- int use_pred = s->ac_pred;
- int scale;
- int q1, q2 = 0;
- int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
-
- /* Get DC differential */
- if (n < 4) {
- dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
- } else {
- dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
- }
- if (dcdiff < 0){
- av_log(s->avctx, AV_LOG_ERROR, "Illegal DC VLC\n");
- return -1;
- }
- if (dcdiff)
- {
- if (dcdiff == 119 /* ESC index value */)
- {
- /* TODO: Optimize */
- if (mquant == 1) dcdiff = get_bits(gb, 10);
- else if (mquant == 2) dcdiff = get_bits(gb, 9);
- else dcdiff = get_bits(gb, 8);
- }
- else
- {
- if (mquant == 1)
- dcdiff = (dcdiff<<2) + get_bits(gb, 2) - 3;
- else if (mquant == 2)
- dcdiff = (dcdiff<<1) + get_bits(gb, 1) - 1;
- }
- if (get_bits(gb, 1))
- dcdiff = -dcdiff;
- }
-
- /* Prediction */
- dcdiff += vc1_pred_dc(&v->s, v->overlap, mquant, n, v->a_avail, v->c_avail, &dc_val, &dc_pred_dir);
- *dc_val = dcdiff;
-
- /* Store the quantized DC coeff, used for prediction */
- if (n < 4) {
- block[0] = dcdiff * s->y_dc_scale;
- } else {
- block[0] = dcdiff * s->c_dc_scale;
- }
- /* Skip ? */
- run_diff = 0;
- i = 0;
-
- //AC Decoding
- i = 1;
-
- /* check if AC is needed at all and adjust direction if needed */
- if(!a_avail) dc_pred_dir = 1;
- if(!c_avail) dc_pred_dir = 0;
- if(!a_avail && !c_avail) use_pred = 0;
- ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
- ac_val2 = ac_val;
-
- scale = mquant * 2 + v->halfpq;
-
- if(dc_pred_dir) //left
- ac_val -= 16;
- else //top
- ac_val -= 16 * s->block_wrap[n];
-
- q1 = s->current_picture.qscale_table[mb_pos];
- if(dc_pred_dir && c_avail) q2 = s->current_picture.qscale_table[mb_pos - 1];
- if(!dc_pred_dir && a_avail) q2 = s->current_picture.qscale_table[mb_pos - s->mb_stride];
- if(n && n<4) q2 = q1;
-
- if(coded) {
- int last = 0, skip, value;
- const int8_t *zz_table;
- int k;
-
- if(v->s.ac_pred) {
- if(!dc_pred_dir)
- zz_table = vc1_horizontal_zz;
- else
- zz_table = vc1_vertical_zz;
- } else
- zz_table = vc1_normal_zz;
-
- while (!last) {
- vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);
- i += skip;
- if(i > 63)
- break;
- block[zz_table[i++]] = value;
- }
-
- /* apply AC prediction if needed */
- if(use_pred) {
- /* scale predictors if needed*/
- if(q2 && q1!=q2) {
- q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
- q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
-
- if(dc_pred_dir) { //left
- for(k = 1; k < 8; k++)
- block[k << 3] += (ac_val[k] * q2 * vc1_dqscale[q1 - 1] + 0x20000) >> 18;
- } else { //top
- for(k = 1; k < 8; k++)
- block[k] += (ac_val[k + 8] * q2 * vc1_dqscale[q1 - 1] + 0x20000) >> 18;
- }
- } else {
- if(dc_pred_dir) { //left
- for(k = 1; k < 8; k++)
- block[k << 3] += ac_val[k];
- } else { //top
- for(k = 1; k < 8; k++)
- block[k] += ac_val[k + 8];
- }
- }
- }
- /* save AC coeffs for further prediction */
- for(k = 1; k < 8; k++) {
- ac_val2[k] = block[k << 3];
- ac_val2[k + 8] = block[k];
- }
-
- /* scale AC coeffs */
- for(k = 1; k < 64; k++)
- if(block[k]) {
- block[k] *= scale;
- if(!v->pquantizer)
- block[k] += (block[k] < 0) ? -mquant : mquant;
- }
-
- if(use_pred) i = 63;
- } else { // no AC coeffs
- int k;
-
- memset(ac_val2, 0, 16 * 2);
- if(dc_pred_dir) {//left
- if(use_pred) {
- memcpy(ac_val2, ac_val, 8 * 2);
- if(q2 && q1!=q2) {
- q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
- q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
- for(k = 1; k < 8; k++)
- ac_val2[k] = (ac_val2[k] * q2 * vc1_dqscale[q1 - 1] + 0x20000) >> 18;
- }
- }
- } else {//top
- if(use_pred) {
- memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
- if(q2 && q1!=q2) {
- q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
- q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
- for(k = 1; k < 8; k++)
- ac_val2[k + 8] = (ac_val2[k + 8] * q2 * vc1_dqscale[q1 - 1] + 0x20000) >> 18;
- }
- }
- }
-
- /* apply AC prediction if needed */
- if(use_pred) {
- if(dc_pred_dir) { //left
- for(k = 1; k < 8; k++) {
- block[k << 3] = ac_val2[k] * scale;
- if(!v->pquantizer && block[k << 3])
- block[k << 3] += (block[k << 3] < 0) ? -mquant : mquant;
- }
- } else { //top
- for(k = 1; k < 8; k++) {
- block[k] = ac_val2[k + 8] * scale;
- if(!v->pquantizer && block[k])
- block[k] += (block[k] < 0) ? -mquant : mquant;
- }
- }
- i = 63;
- }
- }
- s->block_last_index[n] = i;
-
- return 0;
-}
-
-/** Decode intra block in inter frames - more generic version than vc1_decode_i_block
- * @param v VC1Context
- * @param block block to decode
- * @param coded are AC coeffs present or not
- * @param mquant block quantizer
- * @param codingset set of VLC to decode data
- */
-static int vc1_decode_intra_block(VC1Context *v, DCTELEM block[64], int n, int coded, int mquant, int codingset)
-{
- GetBitContext *gb = &v->s.gb;
- MpegEncContext *s = &v->s;
- int dc_pred_dir = 0; /* Direction of the DC prediction used */
- int run_diff, i;
- int16_t *dc_val;
- int16_t *ac_val, *ac_val2;
- int dcdiff;
- int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
- int a_avail = v->a_avail, c_avail = v->c_avail;
- int use_pred = s->ac_pred;
- int scale;
- int q1, q2 = 0;
-
- /* XXX: Guard against dumb values of mquant */
- mquant = (mquant < 1) ? 0 : ( (mquant>31) ? 31 : mquant );
-
- /* Set DC scale - y and c use the same */
- s->y_dc_scale = s->y_dc_scale_table[mquant];
- s->c_dc_scale = s->c_dc_scale_table[mquant];
-
- /* Get DC differential */
- if (n < 4) {
- dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
- } else {
- dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
- }
- if (dcdiff < 0){
- av_log(s->avctx, AV_LOG_ERROR, "Illegal DC VLC\n");
- return -1;
- }
- if (dcdiff)
- {
- if (dcdiff == 119 /* ESC index value */)
- {
- /* TODO: Optimize */
- if (mquant == 1) dcdiff = get_bits(gb, 10);
- else if (mquant == 2) dcdiff = get_bits(gb, 9);
- else dcdiff = get_bits(gb, 8);
- }
- else
- {
- if (mquant == 1)
- dcdiff = (dcdiff<<2) + get_bits(gb, 2) - 3;
- else if (mquant == 2)
- dcdiff = (dcdiff<<1) + get_bits(gb, 1) - 1;
- }
- if (get_bits(gb, 1))
- dcdiff = -dcdiff;
- }
-
- /* Prediction */
- dcdiff += vc1_pred_dc(&v->s, v->overlap, mquant, n, a_avail, c_avail, &dc_val, &dc_pred_dir);
- *dc_val = dcdiff;
-
- /* Store the quantized DC coeff, used for prediction */
-
- if (n < 4) {
- block[0] = dcdiff * s->y_dc_scale;
- } else {
- block[0] = dcdiff * s->c_dc_scale;
- }
- /* Skip ? */
- run_diff = 0;
- i = 0;
-
- //AC Decoding
- i = 1;
-
- /* check if AC is needed at all and adjust direction if needed */
- if(!a_avail) dc_pred_dir = 1;
- if(!c_avail) dc_pred_dir = 0;
- if(!a_avail && !c_avail) use_pred = 0;
- ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
- ac_val2 = ac_val;
-
- scale = mquant * 2 + v->halfpq;
-
- if(dc_pred_dir) //left
- ac_val -= 16;
- else //top
- ac_val -= 16 * s->block_wrap[n];
-
- q1 = s->current_picture.qscale_table[mb_pos];
- if(dc_pred_dir && c_avail && mb_pos) q2 = s->current_picture.qscale_table[mb_pos - 1];
- if(!dc_pred_dir && a_avail && mb_pos >= s->mb_stride) q2 = s->current_picture.qscale_table[mb_pos - s->mb_stride];
- if(n && n<4) q2 = q1;
-
- if(coded) {
- int last = 0, skip, value;
- const int8_t *zz_table;
- int k;
-
- zz_table = vc1_simple_progressive_8x8_zz;
-
- while (!last) {
- vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);
- i += skip;
- if(i > 63)
- break;
- block[zz_table[i++]] = value;
- }
-
- /* apply AC prediction if needed */
- if(use_pred) {
- /* scale predictors if needed*/
- if(q2 && q1!=q2) {
- q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
- q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
-
- if(dc_pred_dir) { //left
- for(k = 1; k < 8; k++)
- block[k << 3] += (ac_val[k] * q2 * vc1_dqscale[q1 - 1] + 0x20000) >> 18;
- } else { //top
- for(k = 1; k < 8; k++)
- block[k] += (ac_val[k + 8] * q2 * vc1_dqscale[q1 - 1] + 0x20000) >> 18;
- }
- } else {
- if(dc_pred_dir) { //left
- for(k = 1; k < 8; k++)
- block[k << 3] += ac_val[k];
- } else { //top
- for(k = 1; k < 8; k++)
- block[k] += ac_val[k + 8];
- }
- }
- }
- /* save AC coeffs for further prediction */
- for(k = 1; k < 8; k++) {
- ac_val2[k] = block[k << 3];
- ac_val2[k + 8] = block[k];
- }
-
- /* scale AC coeffs */
- for(k = 1; k < 64; k++)
- if(block[k]) {
- block[k] *= scale;
- if(!v->pquantizer)
- block[k] += (block[k] < 0) ? -mquant : mquant;
- }
-
- if(use_pred) i = 63;
- } else { // no AC coeffs
- int k;
-
- memset(ac_val2, 0, 16 * 2);
- if(dc_pred_dir) {//left
- if(use_pred) {
- memcpy(ac_val2, ac_val, 8 * 2);
- if(q2 && q1!=q2) {
- q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
- q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
- for(k = 1; k < 8; k++)
- ac_val2[k] = (ac_val2[k] * q2 * vc1_dqscale[q1 - 1] + 0x20000) >> 18;
- }
- }
- } else {//top
- if(use_pred) {
- memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
- if(q2 && q1!=q2) {
- q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
- q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
- for(k = 1; k < 8; k++)
- ac_val2[k + 8] = (ac_val2[k + 8] * q2 * vc1_dqscale[q1 - 1] + 0x20000) >> 18;
- }
- }
- }
-
- /* apply AC prediction if needed */
- if(use_pred) {
- if(dc_pred_dir) { //left
- for(k = 1; k < 8; k++) {
- block[k << 3] = ac_val2[k] * scale;
- if(!v->pquantizer && block[k << 3])
- block[k << 3] += (block[k << 3] < 0) ? -mquant : mquant;
- }
- } else { //top
- for(k = 1; k < 8; k++) {
- block[k] = ac_val2[k + 8] * scale;
- if(!v->pquantizer && block[k])
- block[k] += (block[k] < 0) ? -mquant : mquant;
- }
- }
- i = 63;
- }
- }
- s->block_last_index[n] = i;
-
- return 0;
-}
-
-/** Decode P block
- */
-static int vc1_decode_p_block(VC1Context *v, DCTELEM block[64], int n, int mquant, int ttmb, int first_block)
-{
- MpegEncContext *s = &v->s;
- GetBitContext *gb = &s->gb;
- int i, j;
- int subblkpat = 0;
- int scale, off, idx, last, skip, value;
- int ttblk = ttmb & 7;
-
- if(ttmb == -1) {
- ttblk = ttblk_to_tt[v->tt_index][get_vlc2(gb, vc1_ttblk_vlc[v->tt_index].table, VC1_TTBLK_VLC_BITS, 1)];
- }
- if(ttblk == TT_4X4) {
- subblkpat = ~(get_vlc2(gb, vc1_subblkpat_vlc[v->tt_index].table, VC1_SUBBLKPAT_VLC_BITS, 1) + 1);
- }
- if((ttblk != TT_8X8 && ttblk != TT_4X4) && (v->ttmbf || (ttmb != -1 && (ttmb & 8) && !first_block))) {
- subblkpat = decode012(gb);
- if(subblkpat) subblkpat ^= 3; //swap decoded pattern bits
- if(ttblk == TT_8X4_TOP || ttblk == TT_8X4_BOTTOM) ttblk = TT_8X4;
- if(ttblk == TT_4X8_RIGHT || ttblk == TT_4X8_LEFT) ttblk = TT_4X8;
- }
- scale = 2 * mquant + v->halfpq;
-
- // convert transforms like 8X4_TOP to generic TT and SUBBLKPAT
- if(ttblk == TT_8X4_TOP || ttblk == TT_8X4_BOTTOM) {
- subblkpat = 2 - (ttblk == TT_8X4_TOP);
- ttblk = TT_8X4;
- }
- if(ttblk == TT_4X8_RIGHT || ttblk == TT_4X8_LEFT) {
- subblkpat = 2 - (ttblk == TT_4X8_LEFT);
- ttblk = TT_4X8;
- }
- switch(ttblk) {
- case TT_8X8:
- i = 0;
- last = 0;
- while (!last) {
- vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
- i += skip;
- if(i > 63)
- break;
- idx = vc1_simple_progressive_8x8_zz[i++];
- block[idx] = value * scale;
- if(!v->pquantizer)
- block[idx] += (block[idx] < 0) ? -mquant : mquant;
- }
- s->dsp.vc1_inv_trans_8x8(block);
- break;
- case TT_4X4:
- for(j = 0; j < 4; j++) {
- last = subblkpat & (1 << (3 - j));
- i = 0;
- off = (j & 1) * 4 + (j & 2) * 16;
- while (!last) {
- vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
- i += skip;
- if(i > 15)
- break;
- idx = vc1_simple_progressive_4x4_zz[i++];
- block[idx + off] = value * scale;
- if(!v->pquantizer)
- block[idx + off] += (block[idx + off] < 0) ? -mquant : mquant;
- }
- if(!(subblkpat & (1 << (3 - j))))
- s->dsp.vc1_inv_trans_4x4(block, j);
- }
- break;
- case TT_8X4:
- for(j = 0; j < 2; j++) {
- last = subblkpat & (1 << (1 - j));
- i = 0;
- off = j * 32;
- while (!last) {
- vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
- i += skip;
- if(i > 31)
- break;
- if(v->profile < PROFILE_ADVANCED)
- idx = vc1_simple_progressive_8x4_zz[i++];
- else
- idx = vc1_adv_progressive_8x4_zz[i++];
- block[idx + off] = value * scale;
- if(!v->pquantizer)
- block[idx + off] += (block[idx + off] < 0) ? -mquant : mquant;
- }
- if(!(subblkpat & (1 << (1 - j))))
- s->dsp.vc1_inv_trans_8x4(block, j);
- }
- break;
- case TT_4X8:
- for(j = 0; j < 2; j++) {
- last = subblkpat & (1 << (1 - j));
- i = 0;
- off = j * 4;
- while (!last) {
- vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
- i += skip;
- if(i > 31)
- break;
- if(v->profile < PROFILE_ADVANCED)
- idx = vc1_simple_progressive_4x8_zz[i++];
- else
- idx = vc1_adv_progressive_4x8_zz[i++];
- block[idx + off] = value * scale;
- if(!v->pquantizer)
- block[idx + off] += (block[idx + off] < 0) ? -mquant : mquant;
- }
- if(!(subblkpat & (1 << (1 - j))))
- s->dsp.vc1_inv_trans_4x8(block, j);
- }
- break;
- }
- return 0;
-}
-
-
-/** Decode one P-frame MB (in Simple/Main profile)
- */
-static int vc1_decode_p_mb(VC1Context *v)
-{
- MpegEncContext *s = &v->s;
- GetBitContext *gb = &s->gb;
- int i, j;
- int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
- int cbp; /* cbp decoding stuff */
- int mqdiff, mquant; /* MB quantization */
- int ttmb = v->ttfrm; /* MB Transform type */
- int status;
-
- static const int size_table[6] = { 0, 2, 3, 4, 5, 8 },
- offset_table[6] = { 0, 1, 3, 7, 15, 31 };
- int mb_has_coeffs = 1; /* last_flag */
- int dmv_x, dmv_y; /* Differential MV components */
- int index, index1; /* LUT indices */
- int val, sign; /* temp values */
- int first_block = 1;
- int dst_idx, off;
- int skipped, fourmv;
-
- mquant = v->pq; /* Loosy initialization */
-
- if (v->mv_type_is_raw)
- fourmv = get_bits1(gb);
- else
- fourmv = v->mv_type_mb_plane[mb_pos];
- if (v->skip_is_raw)
- skipped = get_bits1(gb);
- else
- skipped = v->s.mbskip_table[mb_pos];
-
- s->dsp.clear_blocks(s->block[0]);
-
- if (!fourmv) /* 1MV mode */
- {
- if (!skipped)
- {
- GET_MVDATA(dmv_x, dmv_y);
-
- if (s->mb_intra) {
- s->current_picture.motion_val[1][s->block_index[0]][0] = 0;
- s->current_picture.motion_val[1][s->block_index[0]][1] = 0;
- }
- s->current_picture.mb_type[mb_pos] = s->mb_intra ? MB_TYPE_INTRA : MB_TYPE_16x16;
- vc1_pred_mv(s, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0]);
-
- /* FIXME Set DC val for inter block ? */
- if (s->mb_intra && !mb_has_coeffs)
- {
- GET_MQUANT();
- s->ac_pred = get_bits(gb, 1);
- cbp = 0;
- }
- else if (mb_has_coeffs)
- {
- if (s->mb_intra) s->ac_pred = get_bits(gb, 1);
- cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
- GET_MQUANT();
- }
- else
- {
- mquant = v->pq;
- cbp = 0;
- }
- s->current_picture.qscale_table[mb_pos] = mquant;
-
- if (!v->ttmbf && !s->mb_intra && mb_has_coeffs)
- ttmb = get_vlc2(gb, vc1_ttmb_vlc[v->tt_index].table,
- VC1_TTMB_VLC_BITS, 2);
- if(!s->mb_intra) vc1_mc_1mv(v, 0);
- dst_idx = 0;
- for (i=0; i<6; i++)
- {
- s->dc_val[0][s->block_index[i]] = 0;
- dst_idx += i >> 2;
- val = ((cbp >> (5 - i)) & 1);
- off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
- v->mb_type[0][s->block_index[i]] = s->mb_intra;
- if(s->mb_intra) {
- /* check if prediction blocks A and C are available */
- v->a_avail = v->c_avail = 0;
- if(i == 2 || i == 3 || !s->first_slice_line)
- v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
- if(i == 1 || i == 3 || s->mb_x)
- v->c_avail = v->mb_type[0][s->block_index[i] - 1];
-
- vc1_decode_intra_block(v, s->block[i], i, val, mquant, (i&4)?v->codingset2:v->codingset);
- if((i>3) && (s->flags & CODEC_FLAG_GRAY)) continue;
- s->dsp.vc1_inv_trans_8x8(s->block[i]);
- if(v->rangeredfrm) for(j = 0; j < 64; j++) s->block[i][j] <<= 1;
- for(j = 0; j < 64; j++) s->block[i][j] += 128;
- s->dsp.put_pixels_clamped(s->block[i], s->dest[dst_idx] + off, s->linesize >> ((i & 4) >> 2));
- if(v->pq >= 9 && v->overlap) {
- if(v->c_avail)
- s->dsp.vc1_h_overlap(s->dest[dst_idx] + off, s->linesize >> ((i & 4) >> 2));
- if(v->a_avail)
- s->dsp.vc1_v_overlap(s->dest[dst_idx] + off, s->linesize >> ((i & 4) >> 2));
- }
- } else if(val) {
- vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block);
- if(!v->ttmbf && ttmb < 8) ttmb = -1;
- first_block = 0;
- if((i<4) || !(s->flags & CODEC_FLAG_GRAY))
- s->dsp.add_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize);
- }
- }
- }
- else //Skipped
- {
- s->mb_intra = 0;
- for(i = 0; i < 6; i++) {
- v->mb_type[0][s->block_index[i]] = 0;
- s->dc_val[0][s->block_index[i]] = 0;
- }
- s->current_picture.mb_type[mb_pos] = MB_TYPE_SKIP;
- s->current_picture.qscale_table[mb_pos] = 0;
- vc1_pred_mv(s, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type[0]);
- vc1_mc_1mv(v, 0);
- return 0;
- }
- } //1MV mode
- else //4MV mode
- {
- if (!skipped /* unskipped MB */)
- {
- int intra_count = 0, coded_inter = 0;
- int is_intra[6], is_coded[6];
- /* Get CBPCY */
- cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
- for (i=0; i<6; i++)
- {
- val = ((cbp >> (5 - i)) & 1);
- s->dc_val[0][s->block_index[i]] = 0;
- s->mb_intra = 0;
- if(i < 4) {
- dmv_x = dmv_y = 0;
- s->mb_intra = 0;
- mb_has_coeffs = 0;
- if(val) {
- GET_MVDATA(dmv_x, dmv_y);
- }
- vc1_pred_mv(s, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0]);
- if(!s->mb_intra) vc1_mc_4mv_luma(v, i);
- intra_count += s->mb_intra;
- is_intra[i] = s->mb_intra;
- is_coded[i] = mb_has_coeffs;
- }
- if(i&4){
- is_intra[i] = (intra_count >= 3);
- is_coded[i] = val;
- }
- if(i == 4) vc1_mc_4mv_chroma(v);
- v->mb_type[0][s->block_index[i]] = is_intra[i];
- if(!coded_inter) coded_inter = !is_intra[i] & is_coded[i];
- }
- // if there are no coded blocks then don't do anything more
- if(!intra_count && !coded_inter) return 0;
- dst_idx = 0;
- GET_MQUANT();
- s->current_picture.qscale_table[mb_pos] = mquant;
- /* test if block is intra and has pred */
- {
- int intrapred = 0;
- for(i=0; i<6; i++)
- if(is_intra[i]) {
- if(((!s->first_slice_line || (i==2 || i==3)) && v->mb_type[0][s->block_index[i] - s->block_wrap[i]])
- || ((s->mb_x || (i==1 || i==3)) && v->mb_type[0][s->block_index[i] - 1])) {
- intrapred = 1;
- break;
- }
- }
- if(intrapred)s->ac_pred = get_bits(gb, 1);
- else s->ac_pred = 0;
- }
- if (!v->ttmbf && coded_inter)
- ttmb = get_vlc2(gb, vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
- for (i=0; i<6; i++)
- {
- dst_idx += i >> 2;
- off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
- s->mb_intra = is_intra[i];
- if (is_intra[i]) {
- /* check if prediction blocks A and C are available */
- v->a_avail = v->c_avail = 0;
- if(i == 2 || i == 3 || !s->first_slice_line)
- v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
- if(i == 1 || i == 3 || s->mb_x)
- v->c_avail = v->mb_type[0][s->block_index[i] - 1];
-
- vc1_decode_intra_block(v, s->block[i], i, is_coded[i], mquant, (i&4)?v->codingset2:v->codingset);
- if((i>3) && (s->flags & CODEC_FLAG_GRAY)) continue;
- s->dsp.vc1_inv_trans_8x8(s->block[i]);
- if(v->rangeredfrm) for(j = 0; j < 64; j++) s->block[i][j] <<= 1;
- for(j = 0; j < 64; j++) s->block[i][j] += 128;
- s->dsp.put_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize);
- if(v->pq >= 9 && v->overlap) {
- if(v->c_avail)
- s->dsp.vc1_h_overlap(s->dest[dst_idx] + off, s->linesize >> ((i & 4) >> 2));
- if(v->a_avail)
- s->dsp.vc1_v_overlap(s->dest[dst_idx] + off, s->linesize >> ((i & 4) >> 2));
- }
- } else if(is_coded[i]) {
- status = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block);
- if(!v->ttmbf && ttmb < 8) ttmb = -1;
- first_block = 0;
- if((i<4) || !(s->flags & CODEC_FLAG_GRAY))
- s->dsp.add_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize);
- }
- }
- return status;
- }
- else //Skipped MB
- {
- s->mb_intra = 0;
- s->current_picture.qscale_table[mb_pos] = 0;
- for (i=0; i<6; i++) {
- v->mb_type[0][s->block_index[i]] = 0;
- s->dc_val[0][s->block_index[i]] = 0;
- }
- for (i=0; i<4; i++)
- {
- vc1_pred_mv(s, i, 0, 0, 0, v->range_x, v->range_y, v->mb_type[0]);
- vc1_mc_4mv_luma(v, i);
- }
- vc1_mc_4mv_chroma(v);
- s->current_picture.qscale_table[mb_pos] = 0;
- return 0;
- }
- }
-
- /* Should never happen */
- return -1;
-}
-
-/** Decode one B-frame MB (in Main profile)
- */
-static void vc1_decode_b_mb(VC1Context *v)
-{
- MpegEncContext *s = &v->s;
- GetBitContext *gb = &s->gb;
- int i, j;
- int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
- int cbp = 0; /* cbp decoding stuff */
- int mqdiff, mquant; /* MB quantization */
- int ttmb = v->ttfrm; /* MB Transform type */
-
- static const int size_table[6] = { 0, 2, 3, 4, 5, 8 },
- offset_table[6] = { 0, 1, 3, 7, 15, 31 };
- int mb_has_coeffs = 0; /* last_flag */
- int index, index1; /* LUT indices */
- int val, sign; /* temp values */
- int first_block = 1;
- int dst_idx, off;
- int skipped, direct;
- int dmv_x[2], dmv_y[2];
- int bmvtype = BMV_TYPE_BACKWARD;
-
- mquant = v->pq; /* Loosy initialization */
- s->mb_intra = 0;
-
- if (v->dmb_is_raw)
- direct = get_bits1(gb);
- else
- direct = v->direct_mb_plane[mb_pos];
- if (v->skip_is_raw)
- skipped = get_bits1(gb);
- else
- skipped = v->s.mbskip_table[mb_pos];
-
- s->dsp.clear_blocks(s->block[0]);
- dmv_x[0] = dmv_x[1] = dmv_y[0] = dmv_y[1] = 0;
- for(i = 0; i < 6; i++) {
- v->mb_type[0][s->block_index[i]] = 0;
- s->dc_val[0][s->block_index[i]] = 0;
- }
- s->current_picture.qscale_table[mb_pos] = 0;
-
- if (!direct) {
- if (!skipped) {
- GET_MVDATA(dmv_x[0], dmv_y[0]);
- dmv_x[1] = dmv_x[0];
- dmv_y[1] = dmv_y[0];
- }
- if(skipped || !s->mb_intra) {
- bmvtype = decode012(gb);
- switch(bmvtype) {
- case 0:
- bmvtype = (v->bfraction >= (B_FRACTION_DEN/2)) ? BMV_TYPE_BACKWARD : BMV_TYPE_FORWARD;
- break;
- case 1:
- bmvtype = (v->bfraction >= (B_FRACTION_DEN/2)) ? BMV_TYPE_FORWARD : BMV_TYPE_BACKWARD;
- break;
- case 2:
- bmvtype = BMV_TYPE_INTERPOLATED;
- dmv_x[0] = dmv_y[0] = 0;
- }
- }
- }
- for(i = 0; i < 6; i++)
- v->mb_type[0][s->block_index[i]] = s->mb_intra;
-
- if (skipped) {
- if(direct) bmvtype = BMV_TYPE_INTERPOLATED;
- vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
- vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
- return;
- }
- if (direct) {
- cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
- GET_MQUANT();
- s->mb_intra = 0;
- mb_has_coeffs = 0;
- s->current_picture.qscale_table[mb_pos] = mquant;
- if(!v->ttmbf)
- ttmb = get_vlc2(gb, vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
- dmv_x[0] = dmv_y[0] = dmv_x[1] = dmv_y[1] = 0;
- vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
- vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
- } else {
- if(!mb_has_coeffs && !s->mb_intra) {
- /* no coded blocks - effectively skipped */
- vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
- vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
- return;
- }
- if(s->mb_intra && !mb_has_coeffs) {
- GET_MQUANT();
- s->current_picture.qscale_table[mb_pos] = mquant;
- s->ac_pred = get_bits1(gb);
- cbp = 0;
- vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
- } else {
- if(bmvtype == BMV_TYPE_INTERPOLATED) {
- GET_MVDATA(dmv_x[0], dmv_y[0]);
- if(!mb_has_coeffs) {
- /* interpolated skipped block */
- vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
- vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
- return;
- }
- }
- vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
- if(!s->mb_intra) {
- vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
- }
- if(s->mb_intra)
- s->ac_pred = get_bits1(gb);
- cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
- GET_MQUANT();
- s->current_picture.qscale_table[mb_pos] = mquant;
- if(!v->ttmbf && !s->mb_intra && mb_has_coeffs)
- ttmb = get_vlc2(gb, vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
- }
- }
- dst_idx = 0;
- for (i=0; i<6; i++)
- {
- s->dc_val[0][s->block_index[i]] = 0;
- dst_idx += i >> 2;
- val = ((cbp >> (5 - i)) & 1);
- off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
- v->mb_type[0][s->block_index[i]] = s->mb_intra;
- if(s->mb_intra) {
- /* check if prediction blocks A and C are available */
- v->a_avail = v->c_avail = 0;
- if(i == 2 || i == 3 || !s->first_slice_line)
- v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
- if(i == 1 || i == 3 || s->mb_x)
- v->c_avail = v->mb_type[0][s->block_index[i] - 1];
-
- vc1_decode_intra_block(v, s->block[i], i, val, mquant, (i&4)?v->codingset2:v->codingset);
- if((i>3) && (s->flags & CODEC_FLAG_GRAY)) continue;
- s->dsp.vc1_inv_trans_8x8(s->block[i]);
- if(v->rangeredfrm) for(j = 0; j < 64; j++) s->block[i][j] <<= 1;
- for(j = 0; j < 64; j++) s->block[i][j] += 128;
- s->dsp.put_pixels_clamped(s->block[i], s->dest[dst_idx] + off, s->linesize >> ((i & 4) >> 2));
- } else if(val) {
- vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block);
- if(!v->ttmbf && ttmb < 8) ttmb = -1;
- first_block = 0;
- if((i<4) || !(s->flags & CODEC_FLAG_GRAY))
- s->dsp.add_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize);
- }
- }
-}
-
-/** Decode blocks of I-frame
- */
-static void vc1_decode_i_blocks(VC1Context *v)
-{
- int k, j;
- MpegEncContext *s = &v->s;
- int cbp, val;
- uint8_t *coded_val;
- int mb_pos;
-
- /* select codingmode used for VLC tables selection */
- switch(v->y_ac_table_index){
- case 0:
- v->codingset = (v->pqindex <= 8) ? CS_HIGH_RATE_INTRA : CS_LOW_MOT_INTRA;
- break;
- case 1:
- v->codingset = CS_HIGH_MOT_INTRA;
- break;
- case 2:
- v->codingset = CS_MID_RATE_INTRA;
- break;
- }
-
- switch(v->c_ac_table_index){
- case 0:
- v->codingset2 = (v->pqindex <= 8) ? CS_HIGH_RATE_INTER : CS_LOW_MOT_INTER;
- break;
- case 1:
- v->codingset2 = CS_HIGH_MOT_INTER;
- break;
- case 2:
- v->codingset2 = CS_MID_RATE_INTER;
- break;
- }
-
- /* Set DC scale - y and c use the same */
- s->y_dc_scale = s->y_dc_scale_table[v->pq];
- s->c_dc_scale = s->c_dc_scale_table[v->pq];
-
- //do frame decode
- s->mb_x = s->mb_y = 0;
- s->mb_intra = 1;
- s->first_slice_line = 1;
- ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END));
- for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
- for(s->mb_x = 0; s->mb_x < s->mb_width; s->mb_x++) {
- ff_init_block_index(s);
- ff_update_block_index(s);
- s->dsp.clear_blocks(s->block[0]);
- mb_pos = s->mb_x + s->mb_y * s->mb_width;
- s->current_picture.mb_type[mb_pos] = MB_TYPE_INTRA;
- s->current_picture.qscale_table[mb_pos] = v->pq;
- s->current_picture.motion_val[1][s->block_index[0]][0] = 0;
- s->current_picture.motion_val[1][s->block_index[0]][1] = 0;
-
- // do actual MB decoding and displaying
- cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2);
- v->s.ac_pred = get_bits(&v->s.gb, 1);
-
- for(k = 0; k < 6; k++) {
- val = ((cbp >> (5 - k)) & 1);
-
- if (k < 4) {
- int pred = vc1_coded_block_pred(&v->s, k, &coded_val);
- val = val ^ pred;
- *coded_val = val;
- }
- cbp |= val << (5 - k);
-
- vc1_decode_i_block(v, s->block[k], k, val, (k<4)? v->codingset : v->codingset2);
-
- s->dsp.vc1_inv_trans_8x8(s->block[k]);
- if(v->pq >= 9 && v->overlap) {
- for(j = 0; j < 64; j++) s->block[k][j] += 128;
- }
- }
-
- vc1_put_block(v, s->block);
- if(v->pq >= 9 && v->overlap) {
- if(s->mb_x) {
- s->dsp.vc1_h_overlap(s->dest[0], s->linesize);
- s->dsp.vc1_h_overlap(s->dest[0] + 8 * s->linesize, s->linesize);
- if(!(s->flags & CODEC_FLAG_GRAY)) {
- s->dsp.vc1_h_overlap(s->dest[1], s->uvlinesize);
- s->dsp.vc1_h_overlap(s->dest[2], s->uvlinesize);
- }
- }
- s->dsp.vc1_h_overlap(s->dest[0] + 8, s->linesize);
- s->dsp.vc1_h_overlap(s->dest[0] + 8 * s->linesize + 8, s->linesize);
- if(!s->first_slice_line) {
- s->dsp.vc1_v_overlap(s->dest[0], s->linesize);
- s->dsp.vc1_v_overlap(s->dest[0] + 8, s->linesize);
- if(!(s->flags & CODEC_FLAG_GRAY)) {
- s->dsp.vc1_v_overlap(s->dest[1], s->uvlinesize);
- s->dsp.vc1_v_overlap(s->dest[2], s->uvlinesize);
- }
- }
- s->dsp.vc1_v_overlap(s->dest[0] + 8 * s->linesize, s->linesize);
- s->dsp.vc1_v_overlap(s->dest[0] + 8 * s->linesize + 8, s->linesize);
- }
-
- if(get_bits_count(&s->gb) > v->bits) {
- av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n", get_bits_count(&s->gb), v->bits);
- return;
- }
- }
- ff_draw_horiz_band(s, s->mb_y * 16, 16);
- s->first_slice_line = 0;
- }
-}
-
-/** Decode blocks of I-frame for advanced profile
- */
-static void vc1_decode_i_blocks_adv(VC1Context *v)
-{
- int k, j;
- MpegEncContext *s = &v->s;
- int cbp, val;
- uint8_t *coded_val;
- int mb_pos;
- int mquant = v->pq;
- int mqdiff;
- int overlap;
- GetBitContext *gb = &s->gb;
-
- /* select codingmode used for VLC tables selection */
- switch(v->y_ac_table_index){
- case 0:
- v->codingset = (v->pqindex <= 8) ? CS_HIGH_RATE_INTRA : CS_LOW_MOT_INTRA;
- break;
- case 1:
- v->codingset = CS_HIGH_MOT_INTRA;
- break;
- case 2:
- v->codingset = CS_MID_RATE_INTRA;
- break;
- }
-
- switch(v->c_ac_table_index){
- case 0:
- v->codingset2 = (v->pqindex <= 8) ? CS_HIGH_RATE_INTER : CS_LOW_MOT_INTER;
- break;
- case 1:
- v->codingset2 = CS_HIGH_MOT_INTER;
- break;
- case 2:
- v->codingset2 = CS_MID_RATE_INTER;
- break;
- }
-
- //do frame decode
- s->mb_x = s->mb_y = 0;
- s->mb_intra = 1;
- s->first_slice_line = 1;
- ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END));
- for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
- for(s->mb_x = 0; s->mb_x < s->mb_width; s->mb_x++) {
- ff_init_block_index(s);
- ff_update_block_index(s);
- s->dsp.clear_blocks(s->block[0]);
- mb_pos = s->mb_x + s->mb_y * s->mb_stride;
- s->current_picture.mb_type[mb_pos] = MB_TYPE_INTRA;
- s->current_picture.motion_val[1][s->block_index[0]][0] = 0;
- s->current_picture.motion_val[1][s->block_index[0]][1] = 0;
-
- // do actual MB decoding and displaying
- cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2);
- if(v->acpred_is_raw)
- v->s.ac_pred = get_bits(&v->s.gb, 1);
- else
- v->s.ac_pred = v->acpred_plane[mb_pos];
-
- if(v->condover == CONDOVER_SELECT) {
- if(v->overflg_is_raw)
- overlap = get_bits(&v->s.gb, 1);
- else
- overlap = v->over_flags_plane[mb_pos];
- } else
- overlap = (v->condover == CONDOVER_ALL);
-
- GET_MQUANT();
-
- s->current_picture.qscale_table[mb_pos] = mquant;
- /* Set DC scale - y and c use the same */
- s->y_dc_scale = s->y_dc_scale_table[mquant];
- s->c_dc_scale = s->c_dc_scale_table[mquant];
-
- for(k = 0; k < 6; k++) {
- val = ((cbp >> (5 - k)) & 1);
-
- if (k < 4) {
- int pred = vc1_coded_block_pred(&v->s, k, &coded_val);
- val = val ^ pred;
- *coded_val = val;
- }
- cbp |= val << (5 - k);
-
- v->a_avail = !s->first_slice_line || (k==2 || k==3);
- v->c_avail = !!s->mb_x || (k==1 || k==3);
-
- vc1_decode_i_block_adv(v, s->block[k], k, val, (k<4)? v->codingset : v->codingset2, mquant);
-
- s->dsp.vc1_inv_trans_8x8(s->block[k]);
- for(j = 0; j < 64; j++) s->block[k][j] += 128;
- }
-
- vc1_put_block(v, s->block);
- if(overlap) {
- if(s->mb_x) {
- s->dsp.vc1_h_overlap(s->dest[0], s->linesize);
- s->dsp.vc1_h_overlap(s->dest[0] + 8 * s->linesize, s->linesize);
- if(!(s->flags & CODEC_FLAG_GRAY)) {
- s->dsp.vc1_h_overlap(s->dest[1], s->uvlinesize);
- s->dsp.vc1_h_overlap(s->dest[2], s->uvlinesize);
- }
- }
- s->dsp.vc1_h_overlap(s->dest[0] + 8, s->linesize);
- s->dsp.vc1_h_overlap(s->dest[0] + 8 * s->linesize + 8, s->linesize);
- if(!s->first_slice_line) {
- s->dsp.vc1_v_overlap(s->dest[0], s->linesize);
- s->dsp.vc1_v_overlap(s->dest[0] + 8, s->linesize);
- if(!(s->flags & CODEC_FLAG_GRAY)) {
- s->dsp.vc1_v_overlap(s->dest[1], s->uvlinesize);
- s->dsp.vc1_v_overlap(s->dest[2], s->uvlinesize);
- }
- }
- s->dsp.vc1_v_overlap(s->dest[0] + 8 * s->linesize, s->linesize);
- s->dsp.vc1_v_overlap(s->dest[0] + 8 * s->linesize + 8, s->linesize);
- }
-
- if(get_bits_count(&s->gb) > v->bits) {
- av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n", get_bits_count(&s->gb), v->bits);
- return;
- }
- }
- ff_draw_horiz_band(s, s->mb_y * 16, 16);
- s->first_slice_line = 0;
- }
-}
-
-static void vc1_decode_p_blocks(VC1Context *v)
-{
- MpegEncContext *s = &v->s;
-
- /* select codingmode used for VLC tables selection */
- switch(v->c_ac_table_index){
- case 0:
- v->codingset = (v->pqindex <= 8) ? CS_HIGH_RATE_INTRA : CS_LOW_MOT_INTRA;
- break;
- case 1:
- v->codingset = CS_HIGH_MOT_INTRA;
- break;
- case 2:
- v->codingset = CS_MID_RATE_INTRA;
- break;
- }
-
- switch(v->c_ac_table_index){
- case 0:
- v->codingset2 = (v->pqindex <= 8) ? CS_HIGH_RATE_INTER : CS_LOW_MOT_INTER;
- break;
- case 1:
- v->codingset2 = CS_HIGH_MOT_INTER;
- break;
- case 2:
- v->codingset2 = CS_MID_RATE_INTER;
- break;
- }
-
- ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END));
- s->first_slice_line = 1;
- for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
- for(s->mb_x = 0; s->mb_x < s->mb_width; s->mb_x++) {
- ff_init_block_index(s);
- ff_update_block_index(s);
- s->dsp.clear_blocks(s->block[0]);
-
- vc1_decode_p_mb(v);
- if(get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) {
- av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i at %ix%i\n", get_bits_count(&s->gb), v->bits,s->mb_x,s->mb_y);
- return;
- }
- }
- ff_draw_horiz_band(s, s->mb_y * 16, 16);
- s->first_slice_line = 0;
- }
-}
-
-static void vc1_decode_b_blocks(VC1Context *v)
-{
- MpegEncContext *s = &v->s;
-
- /* select codingmode used for VLC tables selection */
- switch(v->c_ac_table_index){
- case 0:
- v->codingset = (v->pqindex <= 8) ? CS_HIGH_RATE_INTRA : CS_LOW_MOT_INTRA;
- break;
- case 1:
- v->codingset = CS_HIGH_MOT_INTRA;
- break;
- case 2:
- v->codingset = CS_MID_RATE_INTRA;
- break;
- }
-
- switch(v->c_ac_table_index){
- case 0:
- v->codingset2 = (v->pqindex <= 8) ? CS_HIGH_RATE_INTER : CS_LOW_MOT_INTER;
- break;
- case 1:
- v->codingset2 = CS_HIGH_MOT_INTER;
- break;
- case 2:
- v->codingset2 = CS_MID_RATE_INTER;
- break;
- }
-
- ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END));
- s->first_slice_line = 1;
- for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
- for(s->mb_x = 0; s->mb_x < s->mb_width; s->mb_x++) {
- ff_init_block_index(s);
- ff_update_block_index(s);
- s->dsp.clear_blocks(s->block[0]);
-
- vc1_decode_b_mb(v);
- if(get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) {
- av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i at %ix%i\n", get_bits_count(&s->gb), v->bits,s->mb_x,s->mb_y);
- return;
- }
- }
- ff_draw_horiz_band(s, s->mb_y * 16, 16);
- s->first_slice_line = 0;
- }
-}
-
-static void vc1_decode_skip_blocks(VC1Context *v)
-{
- MpegEncContext *s = &v->s;
-
- ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END));
- s->first_slice_line = 1;
- for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
- s->mb_x = 0;
- ff_init_block_index(s);
- ff_update_block_index(s);
- memcpy(s->dest[0], s->last_picture.data[0] + s->mb_y * 16 * s->linesize, s->linesize * 16);
- memcpy(s->dest[1], s->last_picture.data[1] + s->mb_y * 8 * s->uvlinesize, s->uvlinesize * 8);
- memcpy(s->dest[2], s->last_picture.data[2] + s->mb_y * 8 * s->uvlinesize, s->uvlinesize * 8);
- ff_draw_horiz_band(s, s->mb_y * 16, 16);
- s->first_slice_line = 0;
- }
- s->pict_type = P_TYPE;
-}
-
-static void vc1_decode_blocks(VC1Context *v)
-{
-
- v->s.esc3_level_length = 0;
-
- switch(v->s.pict_type) {
- case I_TYPE:
- if(v->profile == PROFILE_ADVANCED)
- vc1_decode_i_blocks_adv(v);
- else
- vc1_decode_i_blocks(v);
- break;
- case P_TYPE:
- if(v->p_frame_skipped)
- vc1_decode_skip_blocks(v);
- else
- vc1_decode_p_blocks(v);
- break;
- case B_TYPE:
- if(v->bi_type)
- vc1_decode_i_blocks(v);
- else
- vc1_decode_b_blocks(v);
- break;
- }
-}
-
-
-/** Initialize a VC1/WMV3 decoder
- * @todo TODO: Handle VC-1 IDUs (Transport level?)
- * @todo TODO: Decypher remaining bits in extra_data
- */
-static int vc1_decode_init(AVCodecContext *avctx)
-{
- VC1Context *v = avctx->priv_data;
- MpegEncContext *s = &v->s;
- GetBitContext gb;
-
- if (!avctx->extradata_size || !avctx->extradata) return -1;
- if (!(avctx->flags & CODEC_FLAG_GRAY))
- avctx->pix_fmt = PIX_FMT_YUV420P;
- else
- avctx->pix_fmt = PIX_FMT_GRAY8;
- v->s.avctx = avctx;
- avctx->flags |= CODEC_FLAG_EMU_EDGE;
- v->s.flags |= CODEC_FLAG_EMU_EDGE;
-
- if(ff_h263_decode_init(avctx) < 0)
- return -1;
- if (vc1_init_common(v) < 0) return -1;
-
- avctx->coded_width = avctx->width;
- avctx->coded_height = avctx->height;
- if (avctx->codec_id == CODEC_ID_WMV3)
- {
- int count = 0;
-
- // looks like WMV3 has a sequence header stored in the extradata
- // advanced sequence header may be before the first frame
- // the last byte of the extradata is a version number, 1 for the
- // samples we can decode
-
- init_get_bits(&gb, avctx->extradata, avctx->extradata_size*8);
-
- if (decode_sequence_header(avctx, &gb) < 0)
- return -1;
-
- count = avctx->extradata_size*8 - get_bits_count(&gb);
- if (count>0)
- {
- av_log(avctx, AV_LOG_INFO, "Extra data: %i bits left, value: %X\n",
- count, get_bits(&gb, count));
- }
- else if (count < 0)
- {
- av_log(avctx, AV_LOG_INFO, "Read %i bits in overflow\n", -count);
- }
- } else { // VC1/WVC1
- int edata_size = avctx->extradata_size;
- uint8_t *edata = avctx->extradata;
-
- if(avctx->extradata_size < 16) {
- av_log(avctx, AV_LOG_ERROR, "Extradata size too small: %i\n", edata_size);
- return -1;
- }
- while(edata_size > 8) {
- // test if we've found header
- if(AV_RB32(edata) == 0x0000010F) {
- edata += 4;
- edata_size -= 4;
- break;
- }
- edata_size--;
- edata++;
- }
-
- init_get_bits(&gb, edata, edata_size*8);
-
- if (decode_sequence_header(avctx, &gb) < 0)
- return -1;
-
- while(edata_size > 8) {
- // test if we've found entry point
- if(AV_RB32(edata) == 0x0000010E) {
- edata += 4;
- edata_size -= 4;
- break;
- }
- edata_size--;
- edata++;
- }
-
- init_get_bits(&gb, edata, edata_size*8);
-
- if (decode_entry_point(avctx, &gb) < 0)
- return -1;
- }
- avctx->has_b_frames= !!(avctx->max_b_frames);
- s->low_delay = !avctx->has_b_frames;
-
- s->mb_width = (avctx->coded_width+15)>>4;
- s->mb_height = (avctx->coded_height+15)>>4;
-
- /* Allocate mb bitplanes */
- v->mv_type_mb_plane = av_malloc(s->mb_stride * s->mb_height);
- v->direct_mb_plane = av_malloc(s->mb_stride * s->mb_height);
- v->acpred_plane = av_malloc(s->mb_stride * s->mb_height);
- v->over_flags_plane = av_malloc(s->mb_stride * s->mb_height);
-
- /* allocate block type info in that way so it could be used with s->block_index[] */
- v->mb_type_base = av_malloc(s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2);
- v->mb_type[0] = v->mb_type_base + s->b8_stride + 1;
- v->mb_type[1] = v->mb_type_base + s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride + 1;
- v->mb_type[2] = v->mb_type[1] + s->mb_stride * (s->mb_height + 1);
-
- /* Init coded blocks info */
- if (v->profile == PROFILE_ADVANCED)
- {
-// if (alloc_bitplane(&v->over_flags_plane, s->mb_width, s->mb_height) < 0)
-// return -1;
-// if (alloc_bitplane(&v->ac_pred_plane, s->mb_width, s->mb_height) < 0)
-// return -1;
- }
-
- return 0;
-}
-
-
-/** Decode a VC1/WMV3 frame
- * @todo TODO: Handle VC-1 IDUs (Transport level?)
- */
-static int vc1_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- VC1Context *v = avctx->priv_data;
- MpegEncContext *s = &v->s;
- AVFrame *pict = data;
- uint8_t *buf2 = NULL;
-
- /* no supplementary picture */
- if (buf_size == 0) {
- /* special case for last picture */
- if (s->low_delay==0 && s->next_picture_ptr) {
- *pict= *(AVFrame*)s->next_picture_ptr;
- s->next_picture_ptr= NULL;
-
- *data_size = sizeof(AVFrame);
- }
-
- return 0;
- }
-
- //we need to set current_picture_ptr before reading the header, otherwise we cant store anyting im there
- if(s->current_picture_ptr==NULL || s->current_picture_ptr->data[0]){
- int i= ff_find_unused_picture(s, 0);
- s->current_picture_ptr= &s->picture[i];
- }
-
- //for advanced profile we need to unescape buffer
- if (avctx->codec_id == CODEC_ID_VC1) {
- int i, buf_size2;
- buf2 = av_malloc(buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
- buf_size2 = 0;
- for(i = 0; i < buf_size; i++) {
- if(buf[i] == 3 && i >= 2 && !buf[i-1] && !buf[i-2] && i < buf_size-1 && buf[i+1] < 4) {
- buf2[buf_size2++] = buf[i+1];
- i++;
- } else
- buf2[buf_size2++] = buf[i];
- }
- init_get_bits(&s->gb, buf2, buf_size2*8);
- } else
- init_get_bits(&s->gb, buf, buf_size*8);
- // do parse frame header
- if(v->profile < PROFILE_ADVANCED) {
- if(vc1_parse_frame_header(v, &s->gb) == -1) {
- av_free(buf2);
- return -1;
- }
- } else {
- if(vc1_parse_frame_header_adv(v, &s->gb) == -1) {
- av_free(buf2);
- return -1;
- }
- }
-
- if(s->pict_type != I_TYPE && !v->res_rtm_flag){
- av_free(buf2);
- return -1;
- }
-
- // for hurry_up==5
- s->current_picture.pict_type= s->pict_type;
- s->current_picture.key_frame= s->pict_type == I_TYPE;
-
- /* skip B-frames if we don't have reference frames */
- if(s->last_picture_ptr==NULL && (s->pict_type==B_TYPE || s->dropable)){
- av_free(buf2);
- return -1;//buf_size;
- }
- /* skip b frames if we are in a hurry */
- if(avctx->hurry_up && s->pict_type==B_TYPE) return -1;//buf_size;
- if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==B_TYPE)
- || (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=I_TYPE)
- || avctx->skip_frame >= AVDISCARD_ALL) {
- av_free(buf2);
- return buf_size;
- }
- /* skip everything if we are in a hurry>=5 */
- if(avctx->hurry_up>=5) {
- av_free(buf2);
- return -1;//buf_size;
- }
-
- if(s->next_p_frame_damaged){
- if(s->pict_type==B_TYPE)
- return buf_size;
- else
- s->next_p_frame_damaged=0;
- }
-
- if(MPV_frame_start(s, avctx) < 0) {
- av_free(buf2);
- return -1;
- }
-
- ff_er_frame_start(s);
-
- v->bits = buf_size * 8;
- vc1_decode_blocks(v);
-//av_log(s->avctx, AV_LOG_INFO, "Consumed %i/%i bits\n", get_bits_count(&s->gb), buf_size*8);
-// if(get_bits_count(&s->gb) > buf_size * 8)
-// return -1;
- ff_er_frame_end(s);
-
- MPV_frame_end(s);
-
-assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type);
-assert(s->current_picture.pict_type == s->pict_type);
- if (s->pict_type == B_TYPE || s->low_delay) {
- *pict= *(AVFrame*)s->current_picture_ptr;
- } else if (s->last_picture_ptr != NULL) {
- *pict= *(AVFrame*)s->last_picture_ptr;
- }
-
- if(s->last_picture_ptr || s->low_delay){
- *data_size = sizeof(AVFrame);
- ff_print_debug_info(s, pict);
- }
-
- /* Return the Picture timestamp as the frame number */
- /* we substract 1 because it is added on utils.c */
- avctx->frame_number = s->picture_number - 1;
-
- av_free(buf2);
- return buf_size;
-}
-
-
-/** Close a VC1/WMV3 decoder
- * @warning Initial try at using MpegEncContext stuff
- */
-static int vc1_decode_end(AVCodecContext *avctx)
-{
- VC1Context *v = avctx->priv_data;
-
- av_freep(&v->hrd_rate);
- av_freep(&v->hrd_buffer);
- MPV_common_end(&v->s);
- av_freep(&v->mv_type_mb_plane);
- av_freep(&v->direct_mb_plane);
- av_freep(&v->acpred_plane);
- av_freep(&v->over_flags_plane);
- av_freep(&v->mb_type_base);
- return 0;
-}
-
-
-AVCodec vc1_decoder = {
- "vc1",
- CODEC_TYPE_VIDEO,
- CODEC_ID_VC1,
- sizeof(VC1Context),
- vc1_decode_init,
- NULL,
- vc1_decode_end,
- vc1_decode_frame,
- CODEC_CAP_DELAY,
- NULL
-};
-
-AVCodec wmv3_decoder = {
- "wmv3",
- CODEC_TYPE_VIDEO,
- CODEC_ID_WMV3,
- sizeof(VC1Context),
- vc1_decode_init,
- NULL,
- vc1_decode_end,
- vc1_decode_frame,
- CODEC_CAP_DELAY,
- NULL
-};
diff --git a/src/libffmpeg/libavcodec/vc1data.h b/src/libffmpeg/libavcodec/vc1data.h
deleted file mode 100644
index 70e88b525..000000000
--- a/src/libffmpeg/libavcodec/vc1data.h
+++ /dev/null
@@ -1,652 +0,0 @@
-/*
- * VC-1 and WMV3 decoder
- * copyright (c) 2006 Konstantin Shishkov
- * (c) 2005 anonymous, Alex Beregszaszi, 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 vc1data.h
- * VC-1 tables.
- */
-
-#ifndef VC1DATA_H
-#define VC1DATA_H
-
-#if 0 //original bfraction from vc9data.h, not conforming to standard
-/* Denominator used for vc1_bfraction_lut */
-#define B_FRACTION_DEN 840
-
-/* bfraction is fractional, we scale to the GCD 3*5*7*8 = 840 */
-const int16_t vc1_bfraction_lut[23] = {
- 420 /*1/2*/, 280 /*1/3*/, 560 /*2/3*/, 210 /*1/4*/,
- 630 /*3/4*/, 168 /*1/5*/, 336 /*2/5*/,
- 504 /*3/5*/, 672 /*4/5*/, 140 /*1/6*/, 700 /*5/6*/,
- 120 /*1/7*/, 240 /*2/7*/, 360 /*3/7*/, 480 /*4/7*/,
- 600 /*5/7*/, 720 /*6/7*/, 105 /*1/8*/, 315 /*3/8*/,
- 525 /*5/8*/, 735 /*7/8*/,
- -1 /*inv.*/, 0 /*BI fm*/
-};
-#else
-/* Denominator used for vc1_bfraction_lut */
-#define B_FRACTION_DEN 256
-
-/* pre-computed scales for all bfractions and base=256 */
-static const int16_t vc1_bfraction_lut[23] = {
- 128 /*1/2*/, 85 /*1/3*/, 170 /*2/3*/, 64 /*1/4*/,
- 192 /*3/4*/, 51 /*1/5*/, 102 /*2/5*/,
- 153 /*3/5*/, 204 /*4/5*/, 43 /*1/6*/, 215 /*5/6*/,
- 37 /*1/7*/, 74 /*2/7*/, 111 /*3/7*/, 148 /*4/7*/,
- 185 /*5/7*/, 222 /*6/7*/, 32 /*1/8*/, 96 /*3/8*/,
- 160 /*5/8*/, 224 /*7/8*/,
- -1 /*inv.*/, 0 /*BI fm*/
-};
-#endif
-
-static const uint8_t vc1_bfraction_bits[23] = {
- 3, 3, 3, 3,
- 3, 3, 3,
- 7, 7, 7, 7,
- 7, 7, 7, 7,
- 7, 7, 7, 7,
- 7, 7,
- 7, 7
-};
-static const uint8_t vc1_bfraction_codes[23] = {
- 0, 1, 2, 3,
- 4, 5, 6,
- 112, 113, 114, 115,
- 116, 117, 118, 119,
- 120, 121, 122, 123,
- 124, 125,
- 126, 127
-};
-
-//Same as H.264
-static const AVRational vc1_pixel_aspect[16]={
- {0, 1},
- {1, 1},
- {12, 11},
- {10, 11},
- {16, 11},
- {40, 33},
- {24, 11},
- {20, 11},
- {32, 11},
- {80, 33},
- {18, 11},
- {15, 11},
- {64, 33},
- {160, 99},
- {0, 1},
- {0, 1}
-};
-
-/* BitPlane IMODE - such a small table... */
-static const uint8_t vc1_imode_codes[7] = {
- 0, 2, 1, 3, 1, 2, 3
-};
-static const uint8_t vc1_imode_bits[7] = {
- 4, 2, 3, 2, 4, 3, 3
-};
-
-/* Normal-2 imode */
-static const uint8_t vc1_norm2_codes[4] = {
- 0, 4, 5, 3
-};
-static const uint8_t vc1_norm2_bits[4] = {
- 1, 3, 3, 2
-};
-
-static const uint16_t vc1_norm6_codes[64] = {
-0x001, 0x002, 0x003, 0x000, 0x004, 0x001, 0x002, 0x047, 0x005, 0x003, 0x004, 0x04B, 0x005, 0x04D, 0x04E, 0x30E,
-0x006, 0x006, 0x007, 0x053, 0x008, 0x055, 0x056, 0x30D, 0x009, 0x059, 0x05A, 0x30C, 0x05C, 0x30B, 0x30A, 0x037,
-0x007, 0x00A, 0x00B, 0x043, 0x00C, 0x045, 0x046, 0x309, 0x00D, 0x049, 0x04A, 0x308, 0x04C, 0x307, 0x306, 0x036,
-0x00E, 0x051, 0x052, 0x305, 0x054, 0x304, 0x303, 0x035, 0x058, 0x302, 0x301, 0x034, 0x300, 0x033, 0x032, 0x007,
-};
-
-static const uint8_t vc1_norm6_bits[64] = {
- 1, 4, 4, 8, 4, 8, 8, 10, 4, 8, 8, 10, 8, 10, 10, 13,
- 4, 8, 8, 10, 8, 10, 10, 13, 8, 10, 10, 13, 10, 13, 13, 9,
- 4, 8, 8, 10, 8, 10, 10, 13, 8, 10, 10, 13, 10, 13, 13, 9,
- 8, 10, 10, 13, 10, 13, 13, 9, 10, 13, 13, 9, 13, 9, 9, 6,
-};
-/* Normal-6 imode */
-static const uint8_t vc1_norm6_spec[64][5] = {
-{ 0, 1, 1 },
-{ 1, 2, 4 },
-{ 2, 3, 4 },
-{ 3, 0, 8 },
-{ 4, 4, 4 },
-{ 5, 1, 8 },
-{ 6, 2, 8 },
-{ 7, 2, 5, 7, 5 },
-{ 8, 5, 4 },
-{ 9, 3, 8 },
-{10, 4, 8 },
-{11, 2, 5, 11, 5 },
-{12, 5, 8 },
-{13, 2, 5, 13, 5 },
-{14, 2, 5, 14, 5 },
-{15, 3, 5, 14, 8 },
-{16, 6, 4 },
-{17, 6, 8 },
-{18, 7, 8 },
-{19, 2, 5, 19, 5 },
-{20, 8, 8 },
-{21, 2, 5, 21, 5 },
-{22, 2, 5, 22, 5 },
-{23, 3, 5, 13, 8 },
-{24, 9, 8 },
-{25, 2, 5, 25, 5 },
-{26, 2, 5, 26, 5 },
-{27, 3, 5, 12, 8 },
-{28, 2, 5, 28, 5 },
-{29, 3, 5, 11, 8 },
-{30, 3, 5, 10, 8 },
-{31, 3, 5, 7, 4 },
-{32, 7, 4 },
-{33, 10, 8 },
-{34, 11, 8 },
-{35, 2, 5, 3, 5 },
-{36, 12, 8 },
-{37, 2, 5, 5, 5 },
-{38, 2, 5, 6, 5 },
-{39, 3, 5, 9, 8 },
-{40, 13, 8 },
-{41, 2, 5, 9, 5 },
-{42, 2, 5, 10, 5 },
-{43, 3, 5, 8, 8 },
-{44, 2, 5, 12, 5 },
-{45, 3, 5, 7, 8 },
-{46, 3, 5, 6, 8 },
-{47, 3, 5, 6, 4 },
-{48, 14, 8 },
-{49, 2, 5, 17, 5 },
-{50, 2, 5, 18, 5 },
-{51, 3, 5, 5, 8 },
-{52, 2, 5, 20, 5 },
-{53, 3, 5, 4, 8 },
-{54, 3, 5, 3, 8 },
-{55, 3, 5, 5, 4 },
-{56, 2, 5, 24, 5 },
-{57, 3, 5, 2, 8 },
-{58, 3, 5, 1, 8 },
-{59, 3, 5, 4, 4 },
-{60, 3, 5, 0, 8 },
-{61, 3, 5, 3, 4 },
-{62, 3, 5, 2, 4 },
-{63, 3, 5, 1, 1 },
-};
-
-/* 4MV Block pattern VLC tables */
-static const uint8_t vc1_4mv_block_pattern_codes[4][16] = {
- { 14, 58, 59, 25, 12, 26, 15, 15, 13, 24, 27, 0, 28, 1, 2, 2},
- { 8, 18, 19, 4, 20, 5, 30, 11, 21, 31, 6, 12, 7, 13, 14, 0},
- { 15, 6, 7, 2, 8, 3, 28, 9, 10, 29, 4, 11, 5, 12, 13, 0},
- { 0, 11, 12, 4, 13, 5, 30, 16, 14, 31, 6, 17, 7, 18, 19, 19}
-};
-static const uint8_t vc1_4mv_block_pattern_bits[4][16] = {
- { 5, 6, 6, 5, 5, 5, 5, 4, 5, 5, 5, 3, 5, 3, 3, 2},
- { 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 4, 4, 4, 4, 4, 2},
- { 4, 4, 4, 4, 4, 4, 5, 4, 4, 5, 4, 4, 4, 4, 4, 3},
- { 2, 4, 4, 4, 4, 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 4}
-};
-
-const uint8_t wmv3_dc_scale_table[32]={
- 0, 2, 4, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,21
-};
-
-/* P-Picture CBPCY VLC tables */
-#if 1 // Looks like original tables are not conforming to standard at all. Are they used for old WMV?
-static const uint16_t vc1_cbpcy_p_codes[4][64] = {
- {
- 0, 6, 15, 13, 13, 11, 3, 13, 5, 8, 49, 10, 12, 114, 102, 119,
- 1, 54, 96, 8, 10, 111, 5, 15, 12, 10, 2, 12, 13, 115, 53, 63,
- 1, 7, 1, 7, 14, 12, 4, 14, 1, 9, 97, 11, 7, 58, 52, 62,
- 4, 103, 1, 9, 11, 56, 101, 118, 4, 110, 100, 30, 2, 5, 4, 3
- },
- {
- 0, 9, 1, 18, 5, 14, 237, 26, 3, 121, 3, 22, 13, 16, 6, 30,
- 2, 10, 1, 20, 12, 241, 5, 28, 16, 12, 3, 24, 28, 124, 239, 247,
- 1, 240, 1, 19, 18, 15, 4, 27, 1, 122, 2, 23, 1, 17, 7, 31,
- 1, 11, 2, 21, 19, 246, 238, 29, 17, 13, 236, 25, 58, 63, 8, 125
- },
- {
- 0, 201, 25, 231, 5, 221, 1, 3, 2, 414, 2, 241, 16, 225, 195, 492,
- 2, 412, 1, 240, 7, 224, 98, 245, 1, 220, 96, 5, 9, 230, 101, 247,
- 1, 102, 1, 415, 24, 3, 2, 244, 3, 54, 3, 484, 17, 114, 200, 493,
- 3, 413, 1, 4, 13, 113, 99, 485, 4, 111, 194, 243, 5, 29, 26, 31
- },
- {
- 0, 28, 12, 44, 3, 36, 20, 52, 2, 32, 16, 48, 8, 40, 24, 28,
- 1, 30, 14, 46, 6, 38, 22, 54, 3, 34, 18, 50, 10, 42, 26, 30,
- 1, 29, 13, 45, 5, 37, 21, 53, 2, 33, 17, 49, 9, 41, 25, 29,
- 1, 31, 15, 47, 7, 39, 23, 55, 4, 35, 19, 51, 11, 43, 27, 31
- }
-};
-
-static const uint8_t vc1_cbpcy_p_bits[4][64] = {
- {
- 13, 13, 7, 13, 7, 13, 13, 12, 6, 13, 7, 12, 6, 8, 8, 8,
- 5, 7, 8, 12, 6, 8, 13, 12, 7, 13, 13, 12, 6, 8, 7, 7,
- 6, 13, 8, 12, 7, 13, 13, 12, 7, 13, 8, 12, 5, 7, 7, 7,
- 6, 8, 13, 12, 6, 7, 8, 8, 5, 8, 8, 6, 3, 3, 3, 2
- },
- {
- 14, 13, 8, 13, 3, 13, 8, 13, 3, 7, 8, 13, 4, 13, 13, 13,
- 3, 13, 13, 13, 4, 8, 13, 13, 5, 13, 13, 13, 5, 7, 8, 8,
- 3, 8, 14, 13, 5, 13, 13, 13, 4, 7, 13, 13, 6, 13, 13, 13,
- 5, 13, 8, 13, 5, 8, 8, 13, 5, 13, 8, 13, 6, 6, 13, 7
- },
- {
- 13, 8, 6, 8, 4, 8, 13, 12, 4, 9, 8, 8, 5, 8, 8, 9,
- 5, 9, 10, 8, 4, 8, 7, 8, 6, 8, 7, 13, 4, 8, 7, 8,
- 5, 7, 8, 9, 6, 13, 13, 8, 4, 6, 8, 9, 5, 7, 8, 9,
- 5, 9, 9, 13, 5, 7, 7, 9, 4, 7, 8, 8, 3, 5, 5, 5
- },
- {
- 9, 9, 9, 9, 2, 9, 9, 9, 2, 9, 9, 9, 9, 9, 9, 8,
- 3, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8,
- 2, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8,
- 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8
- }
-};
-#else
-static const uint16_t vc1_cbpcy_p_codes[4][64] = {
- {
- 0, 1, 1, 4, 5, 1, 12, 4, 13, 14, 10, 11, 12, 7, 13, 2,
- 15, 1, 96, 1, 49, 97, 2, 100, 3, 4, 5, 101, 102, 52, 53, 4,
- 6, 7, 54, 103, 8, 9, 10, 110, 11, 12, 111, 56, 114, 58, 115, 5,
- 13, 7, 8, 9, 10, 11, 12, 30, 13, 14, 15, 118, 119, 62, 63, 3
- },
- {
- 0, 1, 2, 1, 3, 1, 16, 17, 5, 18, 12, 19, 13, 1, 28, 58,
- 1, 1, 1, 2, 3, 2, 3, 236, 237, 4, 5, 238, 6, 7, 239, 8,
- 9, 240, 10, 11, 121, 122, 12, 13, 14, 15, 241, 246, 16, 17, 124, 63,
- 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 247, 125
- },
- {
- 0, 1, 2, 3, 2, 3, 1, 4, 5, 24, 7, 13, 16, 17, 9, 5,
- 25, 1, 1, 1, 2, 3, 96, 194, 1, 2, 98, 99, 195, 200, 101, 26,
- 201, 102, 412, 413, 414, 54, 220, 111, 221, 3, 224, 113, 225, 114, 230, 29,
- 231, 415, 240, 4, 241, 484, 5, 243, 3, 244, 245, 485, 492, 493, 247, 31
- },
- {
- 0, 1, 1, 1, 2, 2, 3, 4, 3, 5, 6, 7, 8, 9, 10, 11,
- 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
- 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
- 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 28, 29, 30, 31
- }
-};
-static const uint8_t vc1_cbpcy_p_bits[4][64] = {
- {
- 13, 6, 5, 6, 6, 7, 7, 5, 7, 7, 6, 6, 6, 5, 6, 3,
- 7, 8, 8, 13, 7, 8, 13, 8, 13, 13, 13, 8, 8, 7, 7, 3,
- 13, 13, 7, 8, 13, 13, 13, 8, 13, 13, 8, 7, 8, 7, 8, 3,
- 13, 12, 12, 12, 12, 12, 12, 6, 12, 12, 12, 8, 8, 7, 7, 2
- },
- {
- 14, 3, 3, 5, 3, 4, 5, 5, 3, 5, 4, 5, 4, 6, 5, 6,
- 8, 14, 13, 8, 8, 13, 13, 8, 8, 13, 13, 8, 13, 13, 8, 13,
- 13, 8, 13, 13, 7, 7, 13, 13, 13, 13, 8, 8, 13, 13, 7, 6,
- 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 8, 7
- },
- {
- 13, 5, 5, 5, 4, 4, 6, 4, 4, 6, 4, 5, 5, 5, 4, 3,
- 6, 8, 10, 9, 8, 8, 7, 8, 13, 13, 7, 7, 8, 8, 7, 5,
- 8, 7, 9, 9, 9, 6, 8, 7, 8, 13, 8, 7, 8, 7, 8, 5,
- 8, 9, 8, 13, 8, 9, 13, 8, 12, 8, 8, 9, 9, 9, 8, 5
- },
- {
- 9, 2, 3, 9, 2, 9, 9, 9, 2, 9, 9, 9, 9, 9, 9, 9,
- 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
- 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
- 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8
- }
-};
-#endif
-
-/* MacroBlock Transform Type: 7.1.3.11, p89
- * 8x8:B
- * 8x4:B:btm 8x4:B:top 8x4:B:both,
- * 4x8:B:right 4x8:B:left 4x8:B:both
- * 4x4:B 8x8:MB
- * 8x4:MB:btm 8x4:MB:top 8x4,MB,both
- * 4x8,MB,right 4x8,MB,left
- * 4x4,MB */
-static const uint16_t vc1_ttmb_codes[3][16] = {
- {
- 0x0003,
- 0x002E, 0x005F, 0x0000,
- 0x0016, 0x0015, 0x0001,
- 0x0004, 0x0014,
- 0x02F1, 0x0179, 0x017B,
- 0x0BC0, 0x0BC1, 0x05E1,
- 0x017A
- },
- {
- 0x0006,
- 0x0006, 0x0003, 0x0007,
- 0x000F, 0x000E, 0x0000,
- 0x0002, 0x0002,
- 0x0014, 0x0011, 0x000B,
- 0x0009, 0x0021, 0x0015,
- 0x0020
- },
- {
- 0x0006,
- 0x0000, 0x000E, 0x0005,
- 0x0002, 0x0003, 0x0003,
- 0x000F, 0x0002,
- 0x0081, 0x0021, 0x0009,
- 0x0101, 0x0041, 0x0011,
- 0x0100
- }
-};
-
-static const uint8_t vc1_ttmb_bits[3][16] = {
- {
- 2,
- 6, 7, 2,
- 5, 5, 2,
- 3, 5,
- 10, 9, 9,
- 12, 12, 11,
- 9
- },
- {
- 3,
- 4, 4, 4,
- 4, 4, 3,
- 3, 2,
- 7, 7, 6,
- 6, 8, 7,
- 8
- },
- {
- 3,
- 3, 4, 5,
- 3, 3, 4,
- 4, 2,
- 10, 8, 6,
- 11, 9, 7,
- 11
- }
-};
-
-/* TTBLK (Transform Type per Block) tables */
-static const uint8_t vc1_ttblk_codes[3][8] = {
- { 0, 1, 3, 5, 16, 17, 18, 19},
- { 3, 0, 1, 2, 3, 5, 8, 9},
- { 1, 0, 1, 4, 6, 7, 10, 11}
-};
-static const uint8_t vc1_ttblk_bits[3][8] = {
- { 2, 2, 2, 3, 5, 5, 5, 5},
- { 2, 3, 3, 3, 3, 3, 4, 4},
- { 2, 3, 3, 3, 3, 3, 4, 4}
-};
-
-/* SUBBLKPAT tables, p93-94, reordered */
-static const uint8_t vc1_subblkpat_codes[3][15] = {
- { 14, 12, 7, 11, 9, 26, 2, 10, 27, 8, 0, 6, 1, 15, 1},
- { 14, 0, 8, 15, 10, 4, 23, 13, 5, 9, 25, 3, 24, 22, 1},
- { 5, 6, 2, 2, 8, 0, 28, 3, 1, 3, 29, 1, 19, 18, 15}
-};
-static const uint8_t vc1_subblkpat_bits[3][15] = {
- { 5, 5, 5, 5, 5, 6, 4, 5, 6, 5, 4, 5, 4, 5, 1},
- { 4, 3, 4, 4, 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 2},
- { 3, 3, 4, 3, 4, 5, 5, 3, 5, 4, 5, 4, 5, 5, 4}
-};
-
-/* MV differential tables, p265 */
-static const uint16_t vc1_mv_diff_codes[4][73] = {
- {
- 0, 2, 3, 8, 576, 3, 2, 6,
- 5, 577, 578, 7, 8, 9, 40, 19,
- 37, 82, 21, 22, 23, 579, 580, 166,
- 96, 167, 49, 194, 195, 581, 582, 583,
- 292, 293, 294, 13, 2, 7, 24, 50,
- 102, 295, 13, 7, 8, 18, 50, 103,
- 38, 20, 21, 22, 39, 204, 103, 23,
- 24, 25, 104, 410, 105, 106, 107, 108,
- 109, 220, 411, 442, 222, 443, 446, 447,
- 7 /* 73 elements */
- },
- {
- 0, 4, 5, 3, 4, 3, 4, 5,
- 20, 6, 21, 44, 45, 46, 3008, 95,
- 112, 113, 57, 3009, 3010, 116, 117, 3011,
- 118, 3012, 3013, 3014, 3015, 3016, 3017, 3018,
- 3019, 3020, 3021, 3022, 1, 4, 15, 160,
- 161, 41, 6, 11, 42, 162, 43, 119,
- 56, 57, 58, 163, 236, 237, 3023, 119,
- 120, 242, 122, 486, 1512, 487, 246, 494,
- 1513, 495, 1514, 1515, 1516, 1517, 1518, 1519,
- 31 /* 73 elements */
- },
- {
- 0, 512, 513, 514, 515, 2, 3, 258,
- 259, 260, 261, 262, 263, 264, 265, 266,
- 267, 268, 269, 270, 271, 272, 273, 274,
- 275, 276, 277, 278, 279, 280, 281, 282,
- 283, 284, 285, 286, 1, 5, 287, 288,
- 289, 290, 6, 7, 291, 292, 293, 294,
- 295, 296, 297, 298, 299, 300, 301, 302,
- 303, 304, 305, 306, 307, 308, 309, 310,
- 311, 312, 313, 314, 315, 316, 317, 318,
- 319 /* 73 elements */
- },
- {
- 0, 1, 1, 2, 3, 4, 1, 5,
- 4, 3, 5, 8, 6, 9, 10, 11,
- 12, 7, 104, 14, 105, 4, 10, 15,
- 11, 6, 14, 8, 106, 107, 108, 15,
- 109, 9, 55, 10, 1, 2, 1, 2,
- 3, 12, 6, 2, 6, 7, 28, 7,
- 15, 8, 5, 18, 29, 152, 77, 24,
- 25, 26, 39, 108, 13, 109, 55, 56,
- 57, 116, 11, 153, 234, 235, 118, 119,
- 15 /* 73 elements */
- }
-};
-static const uint8_t vc1_mv_diff_bits[4][73] = {
- {
- 6, 7, 7, 8, 14, 6, 5, 6, 7, 14, 14, 6, 6, 6, 8, 9,
- 10, 9, 7, 7, 7, 14, 14, 10, 9, 10, 8, 10, 10, 14, 14, 14,
- 13, 13, 13, 6, 3, 5, 6, 8, 9, 13, 5, 4, 4, 5, 7, 9,
- 6, 5, 5, 5, 6, 9, 8, 5, 5, 5, 7, 10, 7, 7, 7, 7,
- 7, 8, 10, 9, 8, 9, 9, 9, 3 /* 73 elements */
- },
- {
- 5, 7, 7, 6, 6, 5, 5, 6, 7, 5, 7, 8, 8, 8, 14, 9,
- 9, 9, 8, 14, 14, 9, 9, 14, 9, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 2, 3, 6, 8, 8, 6, 3, 4, 6, 8, 6, 9,
- 6, 6, 6, 8, 8, 8, 14, 7, 7, 8, 7, 9, 13, 9, 8, 9,
- 13, 9, 13, 13, 13, 13, 13, 13, 5 /* 73 elements */
-
- },
- {
- 3, 12, 12, 12, 12, 3, 4, 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, 5, 11, 11, 11, 11, 4, 4, 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 /* 73 elements */
- },
- {
- 15, 11, 15, 15, 15, 15, 12, 15, 12, 11, 12, 12, 15, 12, 12, 12,
- 12, 15, 15, 12, 15, 10, 11, 12, 11, 10, 11, 10, 15, 15, 15, 11,
- 15, 10, 14, 10, 4, 4, 5, 7, 8, 9, 5, 3, 4, 5, 6, 8,
- 5, 4, 3, 5, 6, 8, 7, 5, 5, 5, 6, 7, 9, 7, 6, 6,
- 6, 7, 10, 8, 8, 8, 7, 7, 4 /* 73 elements */
- }
-};
-
-/* DC differentials low+hi-mo, p217 are the same as in msmpeg4data .h */
-
-/* Scantables/ZZ scan are at 11.9 (p262) and 8.1.1.12 (p10) */
-static const int8_t vc1_normal_zz[64] = {
- 0, 8, 1, 2, 9, 16, 24, 17,
- 10, 3, 4, 11, 18, 25, 32, 40,
- 33, 48, 26, 19, 12, 5, 6, 13,
- 20, 27, 34, 41, 56, 49, 57, 42,
- 35, 28, 21, 14, 7, 15, 22, 29,
- 36, 43, 50, 58, 51, 59, 44, 37,
- 30, 23, 31, 38, 45, 52, 60, 53,
- 61, 46, 39, 47, 54, 62, 55, 63
-};
-
-static const int8_t vc1_horizontal_zz [64] = /* Table 227 */
-{
- 0, 1, 8, 2, 3, 9, 16, 24,
- 17, 10, 4, 5, 11, 18, 25, 32,
- 40, 48, 33, 26, 19, 12, 6, 7,
- 13, 20, 27, 34, 41, 56, 49, 57,
- 42, 35, 28, 21, 14, 15, 22, 29,
- 36, 43, 50, 58, 51, 44, 37, 30,
- 23, 31, 38, 45, 52, 59, 60, 53,
- 46, 39, 47, 54, 61, 62, 55, 63
-};
-
-static const int8_t vc1_vertical_zz [64] = /* Table 228 */
-{
- 0, 8, 16, 1, 24, 32, 40, 9,
- 2, 3, 10, 17, 25, 48, 56, 41,
- 33, 26, 18, 11, 4, 5, 12, 19,
- 27, 34, 49, 57, 50, 42, 35, 28,
- 20, 13, 6, 7, 14, 21, 29, 36,
- 43, 51, 58, 59, 52, 44, 37, 30,
- 22, 15, 23, 31, 38, 45, 60, 53,
- 46, 39, 47, 54, 61, 62, 55, 63
-};
-
-static const int8_t vc1_simple_progressive_8x8_zz [64] =
-/* Table 229 */
-{
- 0, 8, 1, 2, 9, 16, 24, 17,
- 10, 3, 4, 11, 18, 25, 32, 40,
- 48, 56, 41, 33, 26, 19, 12, 5,
- 6, 13, 20, 27, 34, 49, 57, 58,
- 50, 42, 35, 28, 21, 14, 7, 15,
- 22, 29, 36, 43, 51, 59, 60, 52,
- 44, 37, 30, 23, 31, 38, 45, 53,
- 61, 62, 54, 46, 39, 47, 55, 63
-};
-
-static const int8_t vc1_simple_progressive_8x4_zz [32] = /* Table 230 */
-{
- 0, 1, 2, 8, 3, 9, 10, 16,
- 4, 11, 17, 24, 18, 12, 5, 19,
- 25, 13, 20, 26, 27, 6, 21, 28,
- 14, 22, 29, 7, 30, 15, 23, 31
-};
-
-static const int8_t vc1_simple_progressive_4x8_zz [32] = /* Table 231 */
-{
- 0, 8, 1, 16,
- 9, 24, 17, 2,
- 32, 10, 25, 40,
- 18, 48, 33, 26,
- 56, 41, 34, 3,
- 49, 57, 11, 42,
- 19, 50, 27, 58,
- 35, 43, 51, 59
-};
-
-/* Table 232 */
-static const int8_t vc1_simple_progressive_4x4_zz [16] =
-{
- 0, 8, 16, 1,
- 9, 24, 17, 2,
- 10, 18, 25, 3,
- 11, 26, 19, 27
-};
-
-static const int8_t vc1_adv_progressive_8x4_zz [32] = /* Table 233 */
-{
- 0, 8, 1, 16, 2, 9, 10, 3,
- 24, 17, 4, 11, 18, 12, 5, 19,
- 25, 13, 20, 26, 27, 6, 21, 28,
- 14, 22, 29, 7, 30, 15, 23, 31
-};
-
-static const int8_t vc1_adv_progressive_4x8_zz [32] = /* Table 234 */
-{
- 0, 1, 8, 2,
- 9, 16, 17, 24,
- 10, 32, 25, 18,
- 40, 3, 33, 26,
- 48, 11, 56, 41,
- 34, 49, 57, 42,
- 19, 50, 27, 58,
- 35, 43, 51, 59
-};
-
-static const int8_t vc1_adv_interlaced_8x8_zz [64] = /* Table 235 */
-{
- 0, 8, 1, 16, 24, 9, 2, 32,
- 40, 48, 56, 17, 10, 3, 25, 18,
- 11, 4, 33, 41, 49, 57, 26, 34,
- 42, 50, 58, 19, 12, 5, 27, 20,
- 13, 6, 35, 28, 21, 14, 7, 15,
- 22, 29, 36, 43, 51, 59, 60, 52,
- 44, 37, 30, 23, 31, 38, 45, 53,
- 61, 62, 54, 46, 39, 47, 55, 63
-};
-
-static const int8_t vc1_adv_interlaced_8x4_zz [32] = /* Table 236 */
-{
- 0, 8, 16, 24, 1, 9, 2, 17,
- 25, 10, 3, 18, 26, 4, 11, 19,
- 12, 5, 13, 20, 27, 6, 21, 28,
- 14, 22, 29, 7, 30, 15, 23, 31
-};
-
-static const int8_t vc1_adv_interlaced_4x8_zz [32] = /* Table 237 */
-{
- 0, 1, 2, 8,
- 16, 9, 24, 17,
- 10, 3, 32, 40,
- 48, 56, 25, 18,
- 33, 26, 41, 34,
- 49, 57, 11, 42,
- 19, 50, 27, 58,
- 35, 43, 51, 59
-};
-
-static const int8_t vc1_adv_interlaced_4x4_zz [16] = /* Table 238 */
-{
- 0, 8, 16, 24,
- 1, 9, 17, 2,
- 25, 10, 18, 3,
- 26, 11, 19, 27
-};
-
-
-/* DQScale as specified in 8.1.3.9 - almost identical to 0x40000/i */
-static const int32_t vc1_dqscale[63] = {
-0x40000, 0x20000, 0x15555, 0x10000, 0xCCCD, 0xAAAB, 0x9249, 0x8000,
- 0x71C7, 0x6666, 0x5D17, 0x5555, 0x4EC5, 0x4925, 0x4444, 0x4000,
- 0x3C3C, 0x38E4, 0x35E5, 0x3333, 0x30C3, 0x2E8C, 0x2C86, 0x2AAB,
- 0x28F6, 0x2762, 0x25ED, 0x2492, 0x234F, 0x2222, 0x2108, 0x2000,
- 0x1F08, 0x1E1E, 0x1D42, 0x1C72, 0x1BAD, 0x1AF3, 0x1A42, 0x199A,
- 0x18FA, 0x1862, 0x17D0, 0x1746, 0x16C1, 0x1643, 0x15CA, 0x1555,
- 0x14E6, 0x147B, 0x1414, 0x13B1, 0x1352, 0x12F7, 0x129E, 0x1249,
- 0x11F7, 0x11A8, 0x115B, 0x1111, 0x10C9, 0x1084, 0x1000
-};
-#endif /* VC1DATA_H */
diff --git a/src/libffmpeg/libavcodec/vc1dsp.c b/src/libffmpeg/libavcodec/vc1dsp.c
deleted file mode 100644
index f19f266d1..000000000
--- a/src/libffmpeg/libavcodec/vc1dsp.c
+++ /dev/null
@@ -1,463 +0,0 @@
-/*
- * VC-1 and WMV3 decoder - DSP functions
- * Copyright (c) 2006 Konstantin Shishkov
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-/**
-* @file vc1dsp.c
- * VC-1 and WMV3 decoder
- *
- */
-
-#include "dsputil.h"
-
-
-/** Apply overlap transform to horizontal edge
-*/
-static void vc1_v_overlap_c(uint8_t* src, int stride)
-{
- int i;
- int a, b, c, d;
- int d1, d2;
- int rnd = 1;
- for(i = 0; i < 8; i++) {
- a = src[-2*stride];
- b = src[-stride];
- c = src[0];
- d = src[stride];
- d1 = (a - d + 3 + rnd) >> 3;
- d2 = (a - d + b - c + 4 - rnd) >> 3;
-
- src[-2*stride] = a - d1;
- src[-stride] = b - d2;
- src[0] = c + d2;
- src[stride] = d + d1;
- src++;
- rnd = !rnd;
- }
-}
-
-/** Apply overlap transform to vertical edge
-*/
-static void vc1_h_overlap_c(uint8_t* src, int stride)
-{
- int i;
- int a, b, c, d;
- int d1, d2;
- int rnd = 1;
- for(i = 0; i < 8; i++) {
- a = src[-2];
- b = src[-1];
- c = src[0];
- d = src[1];
- d1 = (a - d + 3 + rnd) >> 3;
- d2 = (a - d + b - c + 4 - rnd) >> 3;
-
- src[-2] = a - d1;
- src[-1] = b - d2;
- src[0] = c + d2;
- src[1] = d + d1;
- src += stride;
- rnd = !rnd;
- }
-}
-
-
-/** Do inverse transform on 8x8 block
-*/
-static void vc1_inv_trans_8x8_c(DCTELEM block[64])
-{
- int i;
- register int t1,t2,t3,t4,t5,t6,t7,t8;
- DCTELEM *src, *dst;
-
- src = block;
- dst = block;
- for(i = 0; i < 8; i++){
- t1 = 12 * (src[0] + src[4]);
- t2 = 12 * (src[0] - src[4]);
- t3 = 16 * src[2] + 6 * src[6];
- t4 = 6 * src[2] - 16 * src[6];
-
- t5 = t1 + t3;
- t6 = t2 + t4;
- t7 = t2 - t4;
- t8 = t1 - t3;
-
- t1 = 16 * src[1] + 15 * src[3] + 9 * src[5] + 4 * src[7];
- t2 = 15 * src[1] - 4 * src[3] - 16 * src[5] - 9 * src[7];
- t3 = 9 * src[1] - 16 * src[3] + 4 * src[5] + 15 * src[7];
- t4 = 4 * src[1] - 9 * src[3] + 15 * src[5] - 16 * src[7];
-
- dst[0] = (t5 + t1 + 4) >> 3;
- dst[1] = (t6 + t2 + 4) >> 3;
- dst[2] = (t7 + t3 + 4) >> 3;
- dst[3] = (t8 + t4 + 4) >> 3;
- dst[4] = (t8 - t4 + 4) >> 3;
- dst[5] = (t7 - t3 + 4) >> 3;
- dst[6] = (t6 - t2 + 4) >> 3;
- dst[7] = (t5 - t1 + 4) >> 3;
-
- src += 8;
- dst += 8;
- }
-
- src = block;
- dst = block;
- for(i = 0; i < 8; i++){
- t1 = 12 * (src[ 0] + src[32]);
- t2 = 12 * (src[ 0] - src[32]);
- t3 = 16 * src[16] + 6 * src[48];
- t4 = 6 * src[16] - 16 * src[48];
-
- t5 = t1 + t3;
- t6 = t2 + t4;
- t7 = t2 - t4;
- t8 = t1 - t3;
-
- t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56];
- t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56];
- t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56];
- t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56];
-
- dst[ 0] = (t5 + t1 + 64) >> 7;
- dst[ 8] = (t6 + t2 + 64) >> 7;
- dst[16] = (t7 + t3 + 64) >> 7;
- dst[24] = (t8 + t4 + 64) >> 7;
- dst[32] = (t8 - t4 + 64 + 1) >> 7;
- dst[40] = (t7 - t3 + 64 + 1) >> 7;
- dst[48] = (t6 - t2 + 64 + 1) >> 7;
- dst[56] = (t5 - t1 + 64 + 1) >> 7;
-
- src++;
- dst++;
- }
-}
-
-/** Do inverse transform on 8x4 part of block
-*/
-static void vc1_inv_trans_8x4_c(DCTELEM block[64], int n)
-{
- int i;
- register int t1,t2,t3,t4,t5,t6,t7,t8;
- DCTELEM *src, *dst;
- int off;
-
- off = n * 32;
- src = block + off;
- dst = block + off;
- for(i = 0; i < 4; i++){
- t1 = 12 * (src[0] + src[4]);
- t2 = 12 * (src[0] - src[4]);
- t3 = 16 * src[2] + 6 * src[6];
- t4 = 6 * src[2] - 16 * src[6];
-
- t5 = t1 + t3;
- t6 = t2 + t4;
- t7 = t2 - t4;
- t8 = t1 - t3;
-
- t1 = 16 * src[1] + 15 * src[3] + 9 * src[5] + 4 * src[7];
- t2 = 15 * src[1] - 4 * src[3] - 16 * src[5] - 9 * src[7];
- t3 = 9 * src[1] - 16 * src[3] + 4 * src[5] + 15 * src[7];
- t4 = 4 * src[1] - 9 * src[3] + 15 * src[5] - 16 * src[7];
-
- dst[0] = (t5 + t1 + 4) >> 3;
- dst[1] = (t6 + t2 + 4) >> 3;
- dst[2] = (t7 + t3 + 4) >> 3;
- dst[3] = (t8 + t4 + 4) >> 3;
- dst[4] = (t8 - t4 + 4) >> 3;
- dst[5] = (t7 - t3 + 4) >> 3;
- dst[6] = (t6 - t2 + 4) >> 3;
- dst[7] = (t5 - t1 + 4) >> 3;
-
- src += 8;
- dst += 8;
- }
-
- src = block + off;
- dst = block + off;
- for(i = 0; i < 8; i++){
- t1 = 17 * (src[ 0] + src[16]);
- t2 = 17 * (src[ 0] - src[16]);
- t3 = 22 * src[ 8];
- t4 = 22 * src[24];
- t5 = 10 * src[ 8];
- t6 = 10 * src[24];
-
- dst[ 0] = (t1 + t3 + t6 + 64) >> 7;
- dst[ 8] = (t2 - t4 + t5 + 64) >> 7;
- dst[16] = (t2 + t4 - t5 + 64) >> 7;
- dst[24] = (t1 - t3 - t6 + 64) >> 7;
-
- src ++;
- dst ++;
- }
-}
-
-/** Do inverse transform on 4x8 parts of block
-*/
-static void vc1_inv_trans_4x8_c(DCTELEM block[64], int n)
-{
- int i;
- register int t1,t2,t3,t4,t5,t6,t7,t8;
- DCTELEM *src, *dst;
- int off;
-
- off = n * 4;
- src = block + off;
- dst = block + off;
- for(i = 0; i < 8; i++){
- t1 = 17 * (src[0] + src[2]);
- t2 = 17 * (src[0] - src[2]);
- t3 = 22 * src[1];
- t4 = 22 * src[3];
- t5 = 10 * src[1];
- t6 = 10 * src[3];
-
- dst[0] = (t1 + t3 + t6 + 4) >> 3;
- dst[1] = (t2 - t4 + t5 + 4) >> 3;
- dst[2] = (t2 + t4 - t5 + 4) >> 3;
- dst[3] = (t1 - t3 - t6 + 4) >> 3;
-
- src += 8;
- dst += 8;
- }
-
- src = block + off;
- dst = block + off;
- for(i = 0; i < 4; i++){
- t1 = 12 * (src[ 0] + src[32]);
- t2 = 12 * (src[ 0] - src[32]);
- t3 = 16 * src[16] + 6 * src[48];
- t4 = 6 * src[16] - 16 * src[48];
-
- t5 = t1 + t3;
- t6 = t2 + t4;
- t7 = t2 - t4;
- t8 = t1 - t3;
-
- t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56];
- t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56];
- t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56];
- t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56];
-
- dst[ 0] = (t5 + t1 + 64) >> 7;
- dst[ 8] = (t6 + t2 + 64) >> 7;
- dst[16] = (t7 + t3 + 64) >> 7;
- dst[24] = (t8 + t4 + 64) >> 7;
- dst[32] = (t8 - t4 + 64 + 1) >> 7;
- dst[40] = (t7 - t3 + 64 + 1) >> 7;
- dst[48] = (t6 - t2 + 64 + 1) >> 7;
- dst[56] = (t5 - t1 + 64 + 1) >> 7;
-
- src++;
- dst++;
- }
-}
-
-/** Do inverse transform on 4x4 part of block
-*/
-static void vc1_inv_trans_4x4_c(DCTELEM block[64], int n)
-{
- int i;
- register int t1,t2,t3,t4,t5,t6;
- DCTELEM *src, *dst;
- int off;
-
- off = (n&1) * 4 + (n&2) * 16;
- src = block + off;
- dst = block + off;
- for(i = 0; i < 4; i++){
- t1 = 17 * (src[0] + src[2]);
- t2 = 17 * (src[0] - src[2]);
- t3 = 22 * src[1];
- t4 = 22 * src[3];
- t5 = 10 * src[1];
- t6 = 10 * src[3];
-
- dst[0] = (t1 + t3 + t6 + 4) >> 3;
- dst[1] = (t2 - t4 + t5 + 4) >> 3;
- dst[2] = (t2 + t4 - t5 + 4) >> 3;
- dst[3] = (t1 - t3 - t6 + 4) >> 3;
-
- src += 8;
- dst += 8;
- }
-
- src = block + off;
- dst = block + off;
- for(i = 0; i < 4; i++){
- t1 = 17 * (src[ 0] + src[16]);
- t2 = 17 * (src[ 0] - src[16]);
- t3 = 22 * src[ 8];
- t4 = 22 * src[24];
- t5 = 10 * src[ 8];
- t6 = 10 * src[24];
-
- dst[ 0] = (t1 + t3 + t6 + 64) >> 7;
- dst[ 8] = (t2 - t4 + t5 + 64) >> 7;
- dst[16] = (t2 + t4 - t5 + 64) >> 7;
- dst[24] = (t1 - t3 - t6 + 64) >> 7;
-
- src ++;
- dst ++;
- }
-}
-
-/* motion compensation functions */
-
-/** Filter used to interpolate fractional pel values
- */
-static av_always_inline int vc1_mspel_filter(const uint8_t *src, int stride, int mode, int r)
-{
- switch(mode){
- case 0: //no shift
- return src[0];
- case 1: // 1/4 shift
- return (-4*src[-stride] + 53*src[0] + 18*src[stride] - 3*src[stride*2] + 32 - r) >> 6;
- case 2: // 1/2 shift
- return (-src[-stride] + 9*src[0] + 9*src[stride] - src[stride*2] + 8 - r) >> 4;
- case 3: // 3/4 shift
- return (-3*src[-stride] + 18*src[0] + 53*src[stride] - 4*src[stride*2] + 32 - r) >> 6;
- }
- return 0; //should not occur
-}
-
-/** Function used to do motion compensation with bicubic interpolation
- */
-static void vc1_mspel_mc(uint8_t *dst, const uint8_t *src, int stride, int mode, int rnd)
-{
- int i, j;
- uint8_t tmp[8*11], *tptr;
- int m, r;
-
- m = (mode & 3);
- r = rnd;
- src -= stride;
- tptr = tmp;
- for(j = 0; j < 11; j++) {
- for(i = 0; i < 8; i++)
- tptr[i] = clip_uint8(vc1_mspel_filter(src + i, 1, m, r));
- src += stride;
- tptr += 8;
- }
- r = 1 - rnd;
- m = (mode >> 2) & 3;
-
- tptr = tmp + 8;
- for(j = 0; j < 8; j++) {
- for(i = 0; i < 8; i++)
- dst[i] = clip_uint8(vc1_mspel_filter(tptr + i, 8, m, r));
- dst += stride;
- tptr += 8;
- }
-}
-
-/* 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);
-
-static void ff_put_vc1_mspel_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
- vc1_mspel_mc(dst, src, stride, 0x1, rnd);
-}
-
-static void ff_put_vc1_mspel_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
- vc1_mspel_mc(dst, src, stride, 0x2, rnd);
-}
-
-static void ff_put_vc1_mspel_mc30_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
- vc1_mspel_mc(dst, src, stride, 0x3, rnd);
-}
-
-static void ff_put_vc1_mspel_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
- vc1_mspel_mc(dst, src, stride, 0x4, rnd);
-}
-
-static void ff_put_vc1_mspel_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
- vc1_mspel_mc(dst, src, stride, 0x5, rnd);
-}
-
-static void ff_put_vc1_mspel_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
- vc1_mspel_mc(dst, src, stride, 0x6, rnd);
-}
-
-static void ff_put_vc1_mspel_mc31_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
- vc1_mspel_mc(dst, src, stride, 0x7, rnd);
-}
-
-static void ff_put_vc1_mspel_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
- vc1_mspel_mc(dst, src, stride, 0x8, rnd);
-}
-
-static void ff_put_vc1_mspel_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
- vc1_mspel_mc(dst, src, stride, 0x9, rnd);
-}
-
-static void ff_put_vc1_mspel_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
- vc1_mspel_mc(dst, src, stride, 0xA, rnd);
-}
-
-static void ff_put_vc1_mspel_mc32_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
- vc1_mspel_mc(dst, src, stride, 0xB, rnd);
-}
-
-static void ff_put_vc1_mspel_mc03_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
- vc1_mspel_mc(dst, src, stride, 0xC, rnd);
-}
-
-static void ff_put_vc1_mspel_mc13_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
- vc1_mspel_mc(dst, src, stride, 0xD, rnd);
-}
-
-static void ff_put_vc1_mspel_mc23_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
- vc1_mspel_mc(dst, src, stride, 0xE, rnd);
-}
-
-static void ff_put_vc1_mspel_mc33_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
- vc1_mspel_mc(dst, src, stride, 0xF, rnd);
-}
-
-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;
- dsp->vc1_inv_trans_4x4 = vc1_inv_trans_4x4_c;
- dsp->vc1_h_overlap = vc1_h_overlap_c;
- dsp->vc1_v_overlap = vc1_v_overlap_c;
-
- dsp->put_vc1_mspel_pixels_tab[ 0] = ff_put_vc1_mspel_mc00_c;
- dsp->put_vc1_mspel_pixels_tab[ 1] = ff_put_vc1_mspel_mc10_c;
- dsp->put_vc1_mspel_pixels_tab[ 2] = ff_put_vc1_mspel_mc20_c;
- dsp->put_vc1_mspel_pixels_tab[ 3] = ff_put_vc1_mspel_mc30_c;
- dsp->put_vc1_mspel_pixels_tab[ 4] = ff_put_vc1_mspel_mc01_c;
- dsp->put_vc1_mspel_pixels_tab[ 5] = ff_put_vc1_mspel_mc11_c;
- dsp->put_vc1_mspel_pixels_tab[ 6] = ff_put_vc1_mspel_mc21_c;
- dsp->put_vc1_mspel_pixels_tab[ 7] = ff_put_vc1_mspel_mc31_c;
- dsp->put_vc1_mspel_pixels_tab[ 8] = ff_put_vc1_mspel_mc02_c;
- dsp->put_vc1_mspel_pixels_tab[ 9] = ff_put_vc1_mspel_mc12_c;
- dsp->put_vc1_mspel_pixels_tab[10] = ff_put_vc1_mspel_mc22_c;
- dsp->put_vc1_mspel_pixels_tab[11] = ff_put_vc1_mspel_mc32_c;
- dsp->put_vc1_mspel_pixels_tab[12] = ff_put_vc1_mspel_mc03_c;
- dsp->put_vc1_mspel_pixels_tab[13] = ff_put_vc1_mspel_mc13_c;
- dsp->put_vc1_mspel_pixels_tab[14] = ff_put_vc1_mspel_mc23_c;
- dsp->put_vc1_mspel_pixels_tab[15] = ff_put_vc1_mspel_mc33_c;
-}
diff --git a/src/libffmpeg/libavcodec/vmdav.c b/src/libffmpeg/libavcodec/vmdav.c
deleted file mode 100644
index e0f958cbe..000000000
--- a/src/libffmpeg/libavcodec/vmdav.c
+++ /dev/null
@@ -1,572 +0,0 @@
-/*
- * Sierra VMD Audio & Video Decoders
- * Copyright (C) 2004 the ffmpeg project
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-/**
- * @file vmdvideo.c
- * Sierra VMD audio & video decoders
- * by Vladimir "VAG" Gneushev (vagsoft at mail.ru)
- * for more information on the Sierra VMD format, visit:
- * http://www.pcisys.net/~melanson/codecs/
- *
- * The video decoder outputs PAL8 colorspace data. The decoder expects
- * a 0x330-byte VMD file header to be transmitted via extradata during
- * codec initialization. Each encoded frame that is sent to this decoder
- * is expected to be prepended with the appropriate 16-byte frame
- * information record from the VMD file.
- *
- * The audio decoder, like the video decoder, expects each encoded data
- * chunk to be prepended with the appropriate 16-byte frame information
- * record from the VMD file. It does not require the 0x330-byte VMD file
- * header, but it does need the audio setup parameters passed in through
- * normal libavcodec API means.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "common.h"
-#include "avcodec.h"
-#include "dsputil.h"
-
-#define VMD_HEADER_SIZE 0x330
-#define PALETTE_COUNT 256
-
-/*
- * Video Decoder
- */
-
-typedef struct VmdVideoContext {
-
- AVCodecContext *avctx;
- DSPContext dsp;
- AVFrame frame;
- AVFrame prev_frame;
-
- unsigned char *buf;
- int size;
-
- unsigned char palette[PALETTE_COUNT * 4];
- unsigned char *unpack_buffer;
- int unpack_buffer_size;
-
-} VmdVideoContext;
-
-#define QUEUE_SIZE 0x1000
-#define QUEUE_MASK 0x0FFF
-
-static void lz_unpack(unsigned char *src, unsigned char *dest, int dest_len)
-{
- unsigned char *s;
- unsigned char *d;
- unsigned char *d_end;
- unsigned char queue[QUEUE_SIZE];
- unsigned int qpos;
- unsigned int dataleft;
- unsigned int chainofs;
- unsigned int chainlen;
- unsigned int speclen;
- unsigned char tag;
- unsigned int i, j;
-
- s = src;
- d = dest;
- d_end = d + dest_len;
- dataleft = AV_RL32(s);
- s += 4;
- memset(queue, 0x20, QUEUE_SIZE);
- if (AV_RL32(s) == 0x56781234) {
- s += 4;
- qpos = 0x111;
- speclen = 0xF + 3;
- } else {
- qpos = 0xFEE;
- speclen = 100; /* no speclen */
- }
-
- while (dataleft > 0) {
- tag = *s++;
- if ((tag == 0xFF) && (dataleft > 8)) {
- if (d + 8 > d_end)
- return;
- for (i = 0; i < 8; i++) {
- queue[qpos++] = *d++ = *s++;
- qpos &= QUEUE_MASK;
- }
- dataleft -= 8;
- } else {
- for (i = 0; i < 8; i++) {
- if (dataleft == 0)
- break;
- if (tag & 0x01) {
- if (d + 1 > d_end)
- return;
- queue[qpos++] = *d++ = *s++;
- qpos &= QUEUE_MASK;
- dataleft--;
- } else {
- chainofs = *s++;
- chainofs |= ((*s & 0xF0) << 4);
- chainlen = (*s++ & 0x0F) + 3;
- if (chainlen == speclen)
- chainlen = *s++ + 0xF + 3;
- if (d + chainlen > d_end)
- return;
- for (j = 0; j < chainlen; j++) {
- *d = queue[chainofs++ & QUEUE_MASK];
- queue[qpos++] = *d++;
- qpos &= QUEUE_MASK;
- }
- dataleft -= chainlen;
- }
- tag >>= 1;
- }
- }
- }
-}
-
-static int rle_unpack(unsigned char *src, unsigned char *dest,
- int src_len, int dest_len)
-{
- unsigned char *ps;
- unsigned char *pd;
- int i, l;
- unsigned char *dest_end = dest + dest_len;
-
- ps = src;
- pd = dest;
- if (src_len & 1)
- *pd++ = *ps++;
-
- src_len >>= 1;
- i = 0;
- do {
- l = *ps++;
- if (l & 0x80) {
- l = (l & 0x7F) * 2;
- if (pd + l > dest_end)
- return (ps - src);
- memcpy(pd, ps, l);
- ps += l;
- pd += l;
- } else {
- if (pd + i > dest_end)
- return (ps - src);
- for (i = 0; i < l; i++) {
- *pd++ = ps[0];
- *pd++ = ps[1];
- }
- ps += 2;
- }
- i += l;
- } while (i < src_len);
-
- return (ps - src);
-}
-
-static void vmd_decode(VmdVideoContext *s)
-{
- int i;
- unsigned int *palette32;
- unsigned char r, g, b;
-
- /* point to the start of the encoded data */
- unsigned char *p = s->buf + 16;
-
- unsigned char *pb;
- unsigned char meth;
- unsigned char *dp; /* pointer to current frame */
- unsigned char *pp; /* pointer to previous frame */
- unsigned char len;
- int ofs;
-
- int frame_x, frame_y;
- int frame_width, frame_height;
- int dp_size;
-
- frame_x = AV_RL16(&s->buf[6]);
- frame_y = AV_RL16(&s->buf[8]);
- frame_width = AV_RL16(&s->buf[10]) - frame_x + 1;
- frame_height = AV_RL16(&s->buf[12]) - frame_y + 1;
-
- /* if only a certain region will be updated, copy the entire previous
- * frame before the decode */
- if (frame_x || frame_y || (frame_width != s->avctx->width) ||
- (frame_height != s->avctx->height)) {
-
- memcpy(s->frame.data[0], s->prev_frame.data[0],
- s->avctx->height * s->frame.linesize[0]);
- }
-
- /* check if there is a new palette */
- if (s->buf[15] & 0x02) {
- p += 2;
- palette32 = (unsigned int *)s->palette;
- for (i = 0; i < PALETTE_COUNT; i++) {
- r = *p++ * 4;
- g = *p++ * 4;
- b = *p++ * 4;
- palette32[i] = (r << 16) | (g << 8) | (b);
- }
- s->size -= (256 * 3 + 2);
- }
- if (s->size >= 0) {
- /* originally UnpackFrame in VAG's code */
- pb = p;
- meth = *pb++;
- if (meth & 0x80) {
- lz_unpack(pb, s->unpack_buffer, s->unpack_buffer_size);
- meth &= 0x7F;
- pb = s->unpack_buffer;
- }
-
- dp = &s->frame.data[0][frame_y * s->frame.linesize[0] + frame_x];
- dp_size = s->frame.linesize[0] * s->avctx->height;
- pp = &s->prev_frame.data[0][frame_y * s->prev_frame.linesize[0] + frame_x];
- switch (meth) {
- case 1:
- for (i = 0; i < frame_height; i++) {
- ofs = 0;
- do {
- len = *pb++;
- if (len & 0x80) {
- len = (len & 0x7F) + 1;
- if (ofs + len > frame_width)
- return;
- memcpy(&dp[ofs], pb, len);
- pb += len;
- ofs += len;
- } else {
- /* interframe pixel copy */
- if (ofs + len + 1 > frame_width)
- return;
- memcpy(&dp[ofs], &pp[ofs], len + 1);
- ofs += len + 1;
- }
- } while (ofs < frame_width);
- if (ofs > frame_width) {
- av_log(s->avctx, AV_LOG_ERROR, "VMD video: offset > width (%d > %d)\n",
- ofs, frame_width);
- break;
- }
- dp += s->frame.linesize[0];
- pp += s->prev_frame.linesize[0];
- }
- break;
-
- case 2:
- for (i = 0; i < frame_height; i++) {
- memcpy(dp, pb, frame_width);
- pb += frame_width;
- dp += s->frame.linesize[0];
- pp += s->prev_frame.linesize[0];
- }
- break;
-
- case 3:
- for (i = 0; i < frame_height; i++) {
- ofs = 0;
- do {
- len = *pb++;
- if (len & 0x80) {
- len = (len & 0x7F) + 1;
- if (*pb++ == 0xFF)
- len = rle_unpack(pb, &dp[ofs], len, frame_width - ofs);
- else
- memcpy(&dp[ofs], pb, len);
- pb += len;
- ofs += len;
- } else {
- /* interframe pixel copy */
- if (ofs + len + 1 > frame_width)
- return;
- memcpy(&dp[ofs], &pp[ofs], len + 1);
- ofs += len + 1;
- }
- } while (ofs < frame_width);
- if (ofs > frame_width) {
- av_log(s->avctx, AV_LOG_ERROR, "VMD video: offset > width (%d > %d)\n",
- ofs, frame_width);
- }
- dp += s->frame.linesize[0];
- pp += s->prev_frame.linesize[0];
- }
- break;
- }
- }
-}
-
-static int vmdvideo_decode_init(AVCodecContext *avctx)
-{
- VmdVideoContext *s = (VmdVideoContext *)avctx->priv_data;
- int i;
- unsigned int *palette32;
- int palette_index = 0;
- unsigned char r, g, b;
- unsigned char *vmd_header;
- unsigned char *raw_palette;
-
- s->avctx = avctx;
- avctx->pix_fmt = PIX_FMT_PAL8;
- avctx->has_b_frames = 0;
- dsputil_init(&s->dsp, avctx);
-
- /* make sure the VMD header made it */
- if (s->avctx->extradata_size != VMD_HEADER_SIZE) {
- av_log(s->avctx, AV_LOG_ERROR, "VMD video: expected extradata size of %d\n",
- VMD_HEADER_SIZE);
- return -1;
- }
- vmd_header = (unsigned char *)avctx->extradata;
-
- s->unpack_buffer_size = AV_RL32(&vmd_header[800]);
- s->unpack_buffer = av_malloc(s->unpack_buffer_size);
- if (!s->unpack_buffer)
- return -1;
-
- /* load up the initial palette */
- raw_palette = &vmd_header[28];
- palette32 = (unsigned int *)s->palette;
- for (i = 0; i < PALETTE_COUNT; i++) {
- r = raw_palette[palette_index++] * 4;
- g = raw_palette[palette_index++] * 4;
- b = raw_palette[palette_index++] * 4;
- palette32[i] = (r << 16) | (g << 8) | (b);
- }
-
- s->frame.data[0] = s->prev_frame.data[0] = NULL;
-
- return 0;
-}
-
-static int vmdvideo_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- VmdVideoContext *s = (VmdVideoContext *)avctx->priv_data;
-
- s->buf = buf;
- s->size = buf_size;
-
- if (buf_size < 16)
- return buf_size;
-
- s->frame.reference = 1;
- if (avctx->get_buffer(avctx, &s->frame)) {
- av_log(s->avctx, AV_LOG_ERROR, "VMD Video: get_buffer() failed\n");
- return -1;
- }
-
- vmd_decode(s);
-
- /* make the palette available on the way out */
- memcpy(s->frame.data[1], s->palette, PALETTE_COUNT * 4);
-
- if (s->prev_frame.data[0])
- avctx->release_buffer(avctx, &s->prev_frame);
-
- /* shuffle frames */
- s->prev_frame = s->frame;
-
- *data_size = sizeof(AVFrame);
- *(AVFrame*)data = s->frame;
-
- /* report that the buffer was completely consumed */
- return buf_size;
-}
-
-static int vmdvideo_decode_end(AVCodecContext *avctx)
-{
- VmdVideoContext *s = (VmdVideoContext *)avctx->priv_data;
-
- if (s->prev_frame.data[0])
- avctx->release_buffer(avctx, &s->prev_frame);
- av_free(s->unpack_buffer);
-
- return 0;
-}
-
-
-/*
- * Audio Decoder
- */
-
-typedef struct VmdAudioContext {
- AVCodecContext *avctx;
- int channels;
- int bits;
- int block_align;
- int predictors[2];
-} VmdAudioContext;
-
-static uint16_t vmdaudio_table[128] = {
- 0x000, 0x008, 0x010, 0x020, 0x030, 0x040, 0x050, 0x060, 0x070, 0x080,
- 0x090, 0x0A0, 0x0B0, 0x0C0, 0x0D0, 0x0E0, 0x0F0, 0x100, 0x110, 0x120,
- 0x130, 0x140, 0x150, 0x160, 0x170, 0x180, 0x190, 0x1A0, 0x1B0, 0x1C0,
- 0x1D0, 0x1E0, 0x1F0, 0x200, 0x208, 0x210, 0x218, 0x220, 0x228, 0x230,
- 0x238, 0x240, 0x248, 0x250, 0x258, 0x260, 0x268, 0x270, 0x278, 0x280,
- 0x288, 0x290, 0x298, 0x2A0, 0x2A8, 0x2B0, 0x2B8, 0x2C0, 0x2C8, 0x2D0,
- 0x2D8, 0x2E0, 0x2E8, 0x2F0, 0x2F8, 0x300, 0x308, 0x310, 0x318, 0x320,
- 0x328, 0x330, 0x338, 0x340, 0x348, 0x350, 0x358, 0x360, 0x368, 0x370,
- 0x378, 0x380, 0x388, 0x390, 0x398, 0x3A0, 0x3A8, 0x3B0, 0x3B8, 0x3C0,
- 0x3C8, 0x3D0, 0x3D8, 0x3E0, 0x3E8, 0x3F0, 0x3F8, 0x400, 0x440, 0x480,
- 0x4C0, 0x500, 0x540, 0x580, 0x5C0, 0x600, 0x640, 0x680, 0x6C0, 0x700,
- 0x740, 0x780, 0x7C0, 0x800, 0x900, 0xA00, 0xB00, 0xC00, 0xD00, 0xE00,
- 0xF00, 0x1000, 0x1400, 0x1800, 0x1C00, 0x2000, 0x3000, 0x4000
-};
-
-static int vmdaudio_decode_init(AVCodecContext *avctx)
-{
- VmdAudioContext *s = (VmdAudioContext *)avctx->priv_data;
-
- s->avctx = avctx;
- s->channels = avctx->channels;
- s->bits = avctx->bits_per_sample;
- s->block_align = avctx->block_align;
-
- av_log(s->avctx, AV_LOG_DEBUG, "%d channels, %d bits/sample, block align = %d, sample rate = %d\n",
- s->channels, s->bits, s->block_align, avctx->sample_rate);
-
- return 0;
-}
-
-static void vmdaudio_decode_audio(VmdAudioContext *s, unsigned char *data,
- uint8_t *buf, int stereo)
-{
- int i;
- int chan = 0;
- int16_t *out = (int16_t*)data;
-
- for(i = 0; i < s->block_align; i++) {
- if(buf[i] & 0x80)
- s->predictors[chan] -= vmdaudio_table[buf[i] & 0x7F];
- else
- s->predictors[chan] += vmdaudio_table[buf[i]];
- s->predictors[chan] = clip(s->predictors[chan], -32768, 32767);
- out[i] = s->predictors[chan];
- chan ^= stereo;
- }
-}
-
-static int vmdaudio_loadsound(VmdAudioContext *s, unsigned char *data,
- uint8_t *buf, int silence)
-{
- int bytes_decoded = 0;
- int i;
-
-// if (silence)
-// av_log(s->avctx, AV_LOG_INFO, "silent block!\n");
- if (s->channels == 2) {
-
- /* stereo handling */
- if (silence) {
- memset(data, 0, s->block_align * 2);
- } else {
- if (s->bits == 16)
- vmdaudio_decode_audio(s, data, buf, 1);
- else {
- /* copy the data but convert it to signed */
- for (i = 0; i < s->block_align; i++){
- *data++ = buf[i] + 0x80;
- *data++ = buf[i] + 0x80;
- }
- }
- }
- } else {
- bytes_decoded = s->block_align * 2;
-
- /* mono handling */
- if (silence) {
- memset(data, 0, s->block_align * 2);
- } else {
- if (s->bits == 16) {
- vmdaudio_decode_audio(s, data, buf, 0);
- } else {
- /* copy the data but convert it to signed */
- for (i = 0; i < s->block_align; i++){
- *data++ = buf[i] + 0x80;
- *data++ = buf[i] + 0x80;
- }
- }
- }
- }
-
- return s->block_align * 2;
-}
-
-static int vmdaudio_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- VmdAudioContext *s = (VmdAudioContext *)avctx->priv_data;
- unsigned char *output_samples = (unsigned char *)data;
-
- /* point to the start of the encoded data */
- unsigned char *p = buf + 16;
-
- if (buf_size < 16)
- return buf_size;
-
- if (buf[6] == 1) {
- /* the chunk contains audio */
- *data_size = vmdaudio_loadsound(s, output_samples, p, 0);
- } else if (buf[6] == 2) {
- /* the chunk may contain audio */
- p += 4;
- *data_size = vmdaudio_loadsound(s, output_samples, p, (buf_size == 16));
- output_samples += (s->block_align * s->bits / 8);
- } else if (buf[6] == 3) {
- /* silent chunk */
- *data_size = vmdaudio_loadsound(s, output_samples, p, 1);
- }
-
- return buf_size;
-}
-
-
-/*
- * Public Data Structures
- */
-
-AVCodec vmdvideo_decoder = {
- "vmdvideo",
- CODEC_TYPE_VIDEO,
- CODEC_ID_VMDVIDEO,
- sizeof(VmdVideoContext),
- vmdvideo_decode_init,
- NULL,
- vmdvideo_decode_end,
- vmdvideo_decode_frame,
- CODEC_CAP_DR1,
-};
-
-AVCodec vmdaudio_decoder = {
- "vmdaudio",
- CODEC_TYPE_AUDIO,
- CODEC_ID_VMDAUDIO,
- sizeof(VmdAudioContext),
- vmdaudio_decode_init,
- NULL,
- NULL,
- vmdaudio_decode_frame,
-};
diff --git a/src/libffmpeg/libavcodec/vorbis.c b/src/libffmpeg/libavcodec/vorbis.c
deleted file mode 100644
index ca8d0a956..000000000
--- a/src/libffmpeg/libavcodec/vorbis.c
+++ /dev/null
@@ -1,1814 +0,0 @@
-/**
- * @file vorbis.c
- * 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
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General 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 V_DEBUG
-//#define V_DEBUG
-//#define AV_DEBUG(...) av_log(NULL, AV_LOG_INFO, __VA_ARGS__)
-
-#include <math.h>
-
-#define ALT_BITSTREAM_READER_LE
-#include "avcodec.h"
-#include "bitstream.h"
-#include "dsputil.h"
-
-#include "vorbis.h"
-
-#define V_NB_BITS 8
-#define V_NB_BITS2 11
-#define V_MAX_VLCS (1<<16)
-
-#ifndef V_DEBUG
-#define AV_DEBUG(...)
-#endif
-
-#undef NDEBUG
-#include <assert.h>
-
-typedef struct {
- uint_fast8_t dimensions;
- uint_fast8_t lookup_type;
- uint_fast8_t maxdepth;
- VLC vlc;
- float *codevectors;
- unsigned int nb_bits;
-} vorbis_codebook;
-
-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;
-typedef
-uint_fast8_t (* vorbis_floor_decode_func)
- (struct vorbis_context_s *, vorbis_floor_data *, float *);
-typedef struct {
- uint_fast8_t floor_type;
- vorbis_floor_decode_func decode;
- 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];
- 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;
- } t0;
- struct vorbis_floor1_s
- {
- uint_fast8_t partitions;
- uint_fast8_t maximum_class;
- uint_fast8_t partition_class[32];
- uint_fast8_t class_dimensions[16];
- uint_fast8_t class_subclasses[16];
- uint_fast8_t class_masterbook[16];
- int_fast16_t subclass_books[16][8];
- uint_fast8_t multiplier;
- uint_fast16_t x_list_dim;
- floor1_entry_t * list;
- } t1;
- } data;
-} vorbis_floor;
-
-typedef struct {
- uint_fast16_t type;
- 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;
-} vorbis_residue;
-
-typedef struct {
- 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];
-} vorbis_mapping;
-
-typedef struct {
- uint_fast8_t blockflag;
- uint_fast16_t windowtype;
- uint_fast16_t transformtype;
- uint_fast8_t mapping;
-} vorbis_mode;
-
-typedef struct vorbis_context_s {
- AVCodecContext *avccontext;
- GetBitContext gb;
- DSPContext dsp;
-
- MDCTContext mdct[2];
- uint_fast8_t first_frame;
- uint_fast32_t version;
- 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];
- uint_fast16_t codebook_count;
- vorbis_codebook *codebooks;
- uint_fast8_t floor_count;
- vorbis_floor *floors;
- uint_fast8_t residue_count;
- vorbis_residue *residues;
- 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
- float *channel_residues;
- float *channel_floors;
- float *saved;
- uint_fast16_t saved_start;
- float *ret;
- float *buf;
- float *buf_tmp;
- uint_fast32_t add_bias; // for float->int conversion
- uint_fast32_t exp_bias;
-} vorbis_context;
-
-/* Helper functions */
-
-#define BARK(x) \
- (13.1f*atan(0.00074f*(x))+2.24f*atan(1.85e-8f*(x)*(x))+1e-4f*(x))
-
-unsigned int ff_vorbis_nth_root(unsigned int x, unsigned int n) { // x^(1/n)
- unsigned int ret=0, i, j;
-
- do {
- ++ret;
- for(i=0,j=ret;i<n-1;i++) j*=ret;
- } while (j<=x);
-
- return (ret-1);
-}
-
-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));
-}
-
-
-// Generate vlc codes from vorbis huffman code lengths
-
-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;
-
-#ifdef V_DEBUG
- GetBitContext gb;
-#endif
-
- for(p=0;(bits[p]==0) && (p<num);++p);
- if (p==num) {
-// av_log(vc->avccontext, AV_LOG_INFO, "An empty codebook. Heh?! \n");
- return 0;
- }
-
- codes[p]=0;
- 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<bits[p];++i) {
- av_log(NULL, AV_LOG_INFO, "%s", get_bits1(&gb) ? "1" : "0");
- }
- av_log(NULL, AV_LOG_INFO, "\n");
-#endif
-
- ++p;
-
- for(;p<num;++p) {
- 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;
- // 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;
-
-#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<bits[p];++i) {
- av_log(NULL, AV_LOG_INFO, "%s", get_bits1(&gb) ? "1" : "0");
- }
- av_log(NULL, AV_LOG_INFO, "\n");
-#endif
-
- }
-
- //no exits should be left (underspecified tree - ie. unused valid vlcs - not allowed by SPEC)
- for (p=1; p<33; p++)
- if (exit_at_level[p]) return 1;
-
- return 0;
-}
-
-void ff_vorbis_ready_floor1_list(floor1_entry_t * list, int values) {
- int i;
- list[0].sort = 0;
- list[1].sort = 1;
- for (i = 2; i < values; i++) {
- int j;
- list[i].low = 0;
- list[i].high = 1;
- list[i].sort = i;
- for (j = 2; j < i; j++) {
- int tmp = list[j].x;
- if (tmp < list[i].x) {
- if (tmp > list[list[i].low].x) list[i].low = j;
- } else {
- if (tmp < list[list[i].high].x) list[i].high = j;
- }
- }
- }
- for (i = 0; i < values - 1; i++) {
- int j;
- for (j = i + 1; j < values; j++) {
- if (list[list[i].sort].x > list[list[j].sort].x) {
- int tmp = list[i].sort;
- list[i].sort = list[j].sort;
- list[j].sort = tmp;
- }
- }
- }
-}
-
-// Free all allocated memory -----------------------------------------
-
-static void vorbis_free(vorbis_context *vc) {
- int_fast16_t i;
-
- av_freep(&vc->channel_residues);
- av_freep(&vc->channel_floors);
- av_freep(&vc->saved);
- av_freep(&vc->ret);
- av_freep(&vc->buf);
- av_freep(&vc->buf_tmp);
-
- av_freep(&vc->residues);
- av_freep(&vc->modes);
-
- ff_mdct_end(&vc->mdct[0]);
- ff_mdct_end(&vc->mdct[1]);
-
- 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;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 {
- av_free(vc->floors[i].data.t1.list);
- }
- }
- av_freep(&vc->floors);
-
- 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);
- }
- av_freep(&vc->mappings);
-
- if(vc->exp_bias){
- av_freep(&vc->win[0]);
- av_freep(&vc->win[1]);
- }
-}
-
-// Parse setup header -------------------------------------------------
-
-// Process codebooks part
-
-static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc) {
- uint_fast16_t cb;
- uint8_t *tmp_vlc_bits;
- uint32_t *tmp_vlc_codes;
- GetBitContext *gb=&vc->gb;
-
- vc->codebook_count=get_bits(gb,8)+1;
-
- AV_DEBUG(" Codebooks: %d \n", vc->codebook_count);
-
- vc->codebooks=(vorbis_codebook *)av_mallocz(vc->codebook_count * sizeof(vorbis_codebook));
- tmp_vlc_bits=(uint8_t *)av_mallocz(V_MAX_VLCS * sizeof(uint8_t));
- tmp_vlc_codes=(uint32_t *)av_mallocz(V_MAX_VLCS * sizeof(uint32_t));
-
- 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 entries;
-
- AV_DEBUG(" %d. Codebook \n", cb);
-
- 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);
- goto error;
- }
- 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);
-
- 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);
-
- AV_DEBUG(" not ordered \n");
-
- if (sparse) {
- AV_DEBUG(" sparse \n");
-
- used_entries=0;
- for(ce=0;ce<entries;++ce) {
- flag=get_bits1(gb);
- if (flag) {
- tmp_vlc_bits[ce]=get_bits(gb, 5)+1;
- ++used_entries;
- }
- else tmp_vlc_bits[ce]=0;
- }
- } else {
- AV_DEBUG(" not sparse \n");
-
- used_entries=entries;
- for(ce=0;ce<entries;++ce) {
- tmp_vlc_bits[ce]=get_bits(gb, 5)+1;
- }
- }
- } else {
- uint_fast16_t current_entry=0;
- uint_fast8_t current_length=get_bits(gb, 5)+1;
-
- AV_DEBUG(" ordered, current length: %d \n", current_length); //FIXME
-
- used_entries=entries;
- for(;current_entry<used_entries;++current_length) {
- uint_fast16_t i, number;
-
- AV_DEBUG(" number bits: %d ", ilog(entries - current_entry));
-
- number=get_bits(gb, ilog(entries - current_entry));
-
- AV_DEBUG(" number: %d \n", number);
-
- for(i=current_entry;i<number+current_entry;++i) {
- if (i<used_entries) tmp_vlc_bits[i]=current_length;
- }
-
- current_entry+=number;
- }
- if (current_entry>used_entries) {
- av_log(vc->avccontext, AV_LOG_ERROR, " More codelengths than codes in codebook. \n");
- goto error;
- }
- }
-
- 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" );
-
-// If the codebook is used for (inverse) VQ, calculate codevectors.
-
- 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_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);
-
- 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;i<codebook_lookup_values;++i) {
- codebook_multiplicands[i]=get_bits(gb, codebook_value_bits);
-
- AV_DEBUG(" multiplicands*delta+minmum : %e \n", (float)codebook_multiplicands[i]*codebook_delta_value+codebook_minimum_value);
- AV_DEBUG(" multiplicand %d \n", codebook_multiplicands[i]);
- }
-
-// Weed out unused vlcs and build codevector vector
- codebook_setup->codevectors=(float *)av_mallocz(used_entries*codebook_setup->dimensions * sizeof(float));
- 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;
-
-#ifdef V_DEBUG
- av_log(vc->avccontext, AV_LOG_INFO, "Lookup offset %d ,", i);
-#endif
-
- for(k=0;k<dim;++k) {
- uint_fast32_t multiplicand_offset = lookup_offset % codebook_lookup_values;
- 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];
-
-#ifdef V_DEBUG
- av_log(vc->avccontext, AV_LOG_INFO, "real lookup offset %d, vector: ", j);
- 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) {
- 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) {
- av_log(vc->avccontext, AV_LOG_ERROR, "Codebook lookup type not supported. \n");
- goto error;
- }
-
-// Initialize VLC table
- if (ff_vorbis_len2vlc(tmp_vlc_bits, tmp_vlc_codes, entries)) {
- av_log(vc->avccontext, AV_LOG_ERROR, " Invalid code lengths while generating vlcs. \n");
- goto error;
- }
- 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;
-
- 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");
- goto error;
- }
- }
-
- av_free(tmp_vlc_bits);
- av_free(tmp_vlc_codes);
- return 0;
-
-// Error:
-error:
- av_free(tmp_vlc_bits);
- av_free(tmp_vlc_codes);
- 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;
- uint_fast8_t i;
- uint_fast8_t vorbis_time_count=get_bits(gb, 6)+1;
-
- for(i=0;i<vorbis_time_count;++i) {
- uint_fast16_t vorbis_tdtransform=get_bits(gb, 16);
-
- AV_DEBUG(" Vorbis time domain transform %d: %d \n", vorbis_time_count, vorbis_tdtransform);
-
- if (vorbis_tdtransform) {
- av_log(vc->avccontext, AV_LOG_ERROR, "Vorbis time domain transform data nonzero. \n");
- return 1;
- }
- }
- return 0;
-}
-
-// Process floors part
-
-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 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;
- uint_fast16_t i,j,k;
-
- vc->floor_count=get_bits(gb, 6)+1;
-
- vc->floors=(vorbis_floor *)av_mallocz(vc->floor_count * sizeof(vorbis_floor));
-
- for (i=0;i<vc->floor_count;++i) {
- vorbis_floor *floor_setup=&vc->floors[i];
-
- 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;
-
- floor_setup->decode=vorbis_floor1_decode;
-
- 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;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]);
-
- }
-
- AV_DEBUG(" maximum class %d \n", 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);
-
- 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);
-
- AV_DEBUG(" masterbook: %d \n", floor_setup->data.t1.class_masterbook[j]);
- }
-
- for(k=0;k<(1<<floor_setup->data.t1.class_subclasses[j]);++k) {
- floor_setup->data.t1.subclass_books[j][k]=(int16_t)get_bits(gb, 8)-1;
-
- 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;
-
- 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=(floor1_entry_t *)av_mallocz(floor_setup->data.t1.x_list_dim * sizeof(floor1_entry_t));
-
-
- rangebits=get_bits(gb, 4);
- floor_setup->data.t1.list[0].x = 0;
- floor_setup->data.t1.list[1].x = (1<<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);
- }
- }
-
-// 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;
-
- 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);
- /* 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;
- }
- 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=
- av_malloc(floor_setup->data.t0.num_books);
- if(!floor_setup->data.t0.book_list) { return 1; }
- /* read book indexes */
- {
- int idx;
- uint_fast8_t book_idx;
- for (idx=0;idx<floor_setup->data.t0.num_books;++idx) {
- book_idx=get_bits(gb, 8);
- floor_setup->data.t0.book_list[idx]=book_idx;
- 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;
- }
- }
-
- 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=
- av_malloc((floor_setup->data.t0.order+1 + max_codebook_dim)
- * sizeof(float));
- if(!floor_setup->data.t0.lsp) { return 1; }
- }
-
-#ifdef V_DEBUG /* debug output parsed headers */
- AV_DEBUG("floor0 order: %u\n", floor_setup->data.t0.order);
- AV_DEBUG("floor0 rate: %u\n", floor_setup->data.t0.rate);
- AV_DEBUG("floor0 bark map size: %u\n",
- floor_setup->data.t0.bark_map_size);
- AV_DEBUG("floor0 amplitude bits: %u\n",
- floor_setup->data.t0.amplitude_bits);
- AV_DEBUG("floor0 amplitude offset: %u\n",
- floor_setup->data.t0.amplitude_offset);
- AV_DEBUG("floor0 number of books: %u\n",
- floor_setup->data.t0.num_books);
- AV_DEBUG("floor0 book list pointer: %p\n",
- floor_setup->data.t0.book_list);
- {
- int 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 {
- av_log(vc->avccontext, AV_LOG_ERROR, "Invalid floor type!\n");
- return 1;
- }
- }
- return 0;
-}
-
-// Process residues part
-
-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=(vorbis_residue *)av_mallocz(vc->residue_count * sizeof(vorbis_residue));
-
- AV_DEBUG(" There are %d residues. \n", vc->residue_count);
-
- 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);
-
- 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);
-
- 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;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;j<res_setup->classifications;++j) {
- for(k=0;k<8;++k) {
- if (cascade[j]&(1<<k)) {
- res_setup->books[j][k]=get_bits(gb, 8);
-
- 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;
- }
- } else {
- res_setup->books[j][k]=-1;
- }
- }
- }
- }
- return 0;
-}
-
-// Process mappings part
-
-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=(vorbis_mapping *)av_mallocz(vc->mapping_count * sizeof(vorbis_mapping));
-
- AV_DEBUG(" There are %d mappings. \n", vc->mapping_count);
-
- 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;
- }
- if (get_bits1(gb)) {
- mapping_setup->submaps=get_bits(gb, 4)+1;
- } else {
- mapping_setup->submaps=1;
- }
-
- if (get_bits1(gb)) {
- mapping_setup->coupling_steps=get_bits(gb, 8)+1;
- mapping_setup->magnitude=(uint_fast8_t *)av_mallocz(mapping_setup->coupling_steps * sizeof(uint_fast8_t));
- mapping_setup->angle=(uint_fast8_t *)av_mallocz(mapping_setup->coupling_steps * sizeof(uint_fast8_t));
- for(j=0;j<mapping_setup->coupling_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
- }
- } else {
- mapping_setup->coupling_steps=0;
- }
-
- AV_DEBUG(" %d mapping coupling steps: %d \n", i, mapping_setup->coupling_steps);
-
- if(get_bits(gb, 2)) {
- av_log(vc->avccontext, AV_LOG_ERROR, "%d. mapping setup data invalid. \n", i);
- return 1; // following spec.
- }
-
- if (mapping_setup->submaps>1) {
- mapping_setup->mux=(uint_fast8_t *)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;j<mapping_setup->submaps;++j) {
- get_bits(gb, 8); // FIXME check?
- mapping_setup->submap_floor[j]=get_bits(gb, 8);
- mapping_setup->submap_residue[j]=get_bits(gb, 8);
-
- AV_DEBUG(" %d mapping %d submap : floor %d, residue %d \n", i, j, mapping_setup->submap_floor[j], mapping_setup->submap_residue[j]);
- }
- }
- return 0;
-}
-
-// Process modes part
-
-static void create_map( vorbis_context * vc, uint_fast8_t floor_number )
-{
- vorbis_floor * floors=vc->floors;
- vorbis_floor0 * vf;
- int idx;
- int_fast8_t blockflag;
- 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
-
- map=floors[floor_number].data.t0.map[blockflag];
- vf=&floors[floor_number].data.t0;
-
- 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;
- }
-
-# ifdef V_DEBUG
- 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;
- uint_fast8_t i;
-
- vc->mode_count=get_bits(gb, 6)+1;
- vc->modes=(vorbis_mode *)av_mallocz(vc->mode_count * sizeof(vorbis_mode));
-
- AV_DEBUG(" There are %d modes.\n", vc->mode_count);
-
- for(i=0;i<vc->mode_count;++i) {
- vorbis_mode *mode_setup=&vc->modes[i];
-
- mode_setup->blockflag=get_bits(gb, 1);
- 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
-
- 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);
- }
- return 0;
-}
-
-// Process the whole setup header using the functions above
-
-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')) {
- av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (no vorbis signature). \n");
- 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;
- }
- 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;
- }
- if (vorbis_parse_setup_hdr_floors(vc)) {
- av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (floors). \n");
- 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;
- }
- if (vorbis_parse_setup_hdr_mappings(vc)) {
- av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (mappings). \n");
- 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;
- }
- 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 0;
-}
-
-// Process the identification header
-
-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')) {
- av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (no vorbis signature). \n");
- 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<<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;
- }
- // output format int16
- 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;
- }
- vc->win[0]=ff_vorbis_vwin[bl0-6];
- vc->win[1]=ff_vorbis_vwin[bl1-6];
-
- if(vc->exp_bias){
- int i, j;
- for(j=0; j<2; j++){
- float *win = av_malloc(vc->blocksize[j]/2 * sizeof(float));
- for(i=0; i<vc->blocksize[j]/2; i++)
- win[i] = vc->win[j][i] * (1<<15);
- vc->win[j] = win;
- }
- }
-
- if ((get_bits1(gb)) == 0) {
- av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (framing flag not set). \n");
- return 2;
- }
-
- vc->channel_residues=(float *)av_malloc((vc->blocksize[1]/2)*vc->audio_channels * sizeof(float));
- vc->channel_floors=(float *)av_malloc((vc->blocksize[1]/2)*vc->audio_channels * sizeof(float));
- vc->saved=(float *)av_malloc((vc->blocksize[1]/2)*vc->audio_channels * sizeof(float));
- vc->ret=(float *)av_malloc((vc->blocksize[1]/2)*vc->audio_channels * sizeof(float));
- vc->buf=(float *)av_malloc(vc->blocksize[1] * sizeof(float));
- vc->buf_tmp=(float *)av_malloc(vc->blocksize[1] * sizeof(float));
- vc->saved_start=0;
-
- ff_mdct_init(&vc->mdct[0], bl0, 1);
- ff_mdct_init(&vc->mdct[1], bl1, 1);
-
- 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;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)));
- }
-*/
-
- return 0;
-}
-
-// Process the extradata using the functions above (identification header, setup header)
-
-static 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 *header_start[3];
- int header_len[3];
- GetBitContext *gb = &(vc->gb);
- int i, j, hdr_type;
-
- vc->avccontext = avccontext;
- dsputil_init(&vc->dsp, avccontext);
-
- if(vc->dsp.float_to_int16 == ff_float_to_int16_c) {
- vc->add_bias = 385;
- vc->exp_bias = 0;
- } else {
- vc->add_bias = 0;
- vc->exp_bias = 15<<23;
- }
-
- if (!headers_len) {
- av_log(avccontext, AV_LOG_ERROR, "Extradata corrupt.\n");
- return -1;
- }
-
- if(headers[0] == 0 && headers[1] == 30) {
- for(i = 0; i < 3; i++){
- header_len[i] = *headers++ << 8;
- header_len[i] += *headers++;
- header_start[i] = headers;
- headers += header_len[i];
- }
- } else if(headers[0] == 2) {
- for(j=1,i=0;i<2;++i, ++j) {
- header_len[i]=0;
- while(j<headers_len && headers[j]==0xff) {
- header_len[i]+=0xff;
- ++j;
- }
- if (j>=headers_len) {
- av_log(avccontext, AV_LOG_ERROR, "Extradata corrupt.\n");
- return -1;
- }
- header_len[i]+=headers[j];
- }
- header_len[2]=headers_len-header_len[0]-header_len[1]-j;
- headers+=j;
- header_start[0] = headers;
- header_start[1] = header_start[0] + header_len[0];
- header_start[2] = header_start[1] + header_len[1];
- } else {
- av_log(avccontext, AV_LOG_ERROR, "Extradata corrupt.\n");
- return -1;
- }
-
- init_get_bits(gb, header_start[0], header_len[0]*8);
- 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;
- }
- if (vorbis_parse_id_hdr(vc)) {
- av_log(avccontext, AV_LOG_ERROR, "Id header corrupt.\n");
- vorbis_free(vc);
- return -1;
- }
-
- init_get_bits(gb, header_start[2], header_len[2]*8);
- hdr_type=get_bits(gb, 8);
- if (hdr_type!=5) {
- av_log(avccontext, AV_LOG_ERROR, "Third header is not the setup header.\n");
- return -1;
- }
- if (vorbis_parse_setup_hdr(vc)) {
- av_log(avccontext, AV_LOG_ERROR, "Setup header corrupt.\n");
- vorbis_free(vc);
- return -1;
- }
-
- avccontext->channels = vc->audio_channels;
- avccontext->sample_rate = vc->audio_samplerate;
-
- return 0 ;
-}
-
-// Decode audiopackets -------------------------------------------------
-
-// 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;
- uint_fast32_t amplitude;
- uint_fast32_t book_idx;
- uint_fast8_t blockflag=vc->modes[vc->mode_number].blockflag;
-
- 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" );
- //FIXME: look above
- }
- AV_DEBUG( "floor0 dec: booknumber: %u\n", book_idx );
- codebook=vc->codebooks[vf->book_list[book_idx]];
-
- while (lsp_len<vf->order) {
- int vec_off;
-
- 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 );
- /* copy each vector component and add last to it */
- for (idx=0; idx<codebook.dimensions; ++idx) {
- lsp[lsp_len+idx]=codebook.codevectors[vec_off+idx]+last;
- }
- last=lsp[lsp_len+idx-1]; /* set last to last vector component */
-
- lsp_len += codebook.dimensions;
- }
-#ifdef V_DEBUG
- /* DEBUG: output lsp coeffs */
- {
- int idx;
- for ( idx = 0; idx < lsp_len; ++idx )
- AV_DEBUG("floor0 dec: coeff at %d is %f\n", idx, lsp[idx] );
- }
-#endif
-
- /* synthesize floor output vector */
- {
- int i;
- int order=vf->order;
- float wstep=M_PI/vf->bark_map_size;
-
- for(i=0;i<order;i++) { lsp[i]=2.0f*cos(lsp[i]); }
-
- AV_DEBUG("floor0 synth: map_size=%d; m=%d; wstep=%f\n",
- vf->map_size, order, wstep);
-
- 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<order;j+=2) {
- q *= lsp[j] -two_cos_w;
- p *= lsp[j+1]-two_cos_w;
- }
- if(j==order) { // even order
- p *= p*(2.0f-two_cos_w);
- q *= q*(2.0f+two_cos_w);
- }
- else { // odd order
- q *= two_cos_w-lsp[j]; // one more time for q
-
- /* final step and square */
- p *= p*(4.f-two_cos_w*two_cos_w);
- q *= q;
- }
-
- /* calculate linear floor value */
- {
- 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);
- }
- }
- }
- else {
- /* this channel is unused */
- return 1;
- }
-
- AV_DEBUG(" Floor0 decoded\n");
-
- return 0;
-}
-
-static void render_line(int x0, int y0, int x1, int y1, float * buf, int n) {
- int dy = y1 - y0;
- int adx = x1 - x0;
- int ady = FFABS(dy);
- int base = dy / adx;
- int x = x0;
- int y = y0;
- int err = 0;
- int sy;
- if (dy < 0) sy = base - 1;
- else sy = base + 1;
- ady = ady - FFABS(base) * adx;
- if (x >= n) return;
- buf[x] = ff_vorbis_floor1_inverse_db_table[y];
- for (x = x0 + 1; x < x1; x++) {
- if (x >= n) return;
- err += ady;
- if (err >= adx) {
- err -= adx;
- y += sy;
- } else {
- y += base;
- }
- buf[x] = ff_vorbis_floor1_inverse_db_table[y];
- }
-}
-
-void ff_vorbis_floor1_render_list(floor1_entry_t * 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;
- for (i = 1; i < values; i++) {
- int pos = list[i].sort;
- if (flag[pos]) {
- render_line(lx, ly, list[pos].x, y_list[pos] * multiplier, out, samples);
- lx = list[pos].x;
- ly = y_list[pos] * multiplier;
- }
- if (lx >= samples) break;
- }
- if (lx < samples) render_line(lx, ly, samples, ly, out, samples);
-}
-
-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];
- uint_fast8_t class_;
- uint_fast8_t cdim;
- uint_fast8_t cbits;
- uint_fast8_t csub;
- uint_fast8_t cval;
- 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 ?
- int_fast16_t dy, err;
-
-
- if (!get_bits1(gb)) return 1; // silence
-
-// 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));
-
- AV_DEBUG("floor 0 Y %d floor 1 Y %d \n", floor1_Y[0], floor1_Y[1]);
-
- offset=2;
- for(i=0;i<vf->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);
- }
-
- 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,
- vc->codebooks[book].nb_bits, 3);
- } else {
- floor1_Y[offset+j]=0;
- }
-
- AV_DEBUG(" floor(%d) = %d \n", vf->list[offset+j].x, floor1_Y[offset+j]);
- }
- offset+=cdim;
- }
-
-// 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];
-
- 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;
- } else {
- predicted=floor1_Y_final[low_neigh_offs]+off;
- } // render_point end
-
- val=floor1_Y[i];
- highroom=range-predicted;
- lowroom=predicted;
- if (highroom < lowroom) {
- room=highroom*2;
- } else {
- 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) {
- if (highroom > lowroom) {
- floor1_Y_final[i]=val-lowroom+predicted;
- } else {
- floor1_Y_final[i]=predicted-val+highroom-1;
- }
- } else {
- if (val & 1) {
- floor1_Y_final[i]=predicted-(val+1)/2;
- } else {
- floor1_Y_final[i]=predicted+val/2;
- }
- }
- } else {
- 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);
- }
-
-// Curve synth - connect the calculated dots and convert from dB scale FIXME optimize ?
-
- ff_vorbis_floor1_render_list(vf->list, vf->x_list_dim, floor1_Y_final, floor1_flag, vf->multiplier, vec, vf->list[1].x);
-
- AV_DEBUG(" Floor decoded\n");
-
- return 0;
-}
-
-// Read and decode residue
-
-static 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) {
- 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;j<ch;++j) {
- do_not_decode[0]&=do_not_decode[j]; // FIXME - clobbering input
- }
- if (do_not_decode[0]) return 0;
- ch_used=1;
- } else {
- ch_used=ch;
- }
-
- AV_DEBUG(" residue type 0/1/2 decode begin, ch: %d cpc %d \n", ch, c_p_c);
-
- 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_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;j<ch_used;++j) {
- if (!do_not_decode[j]) {
- 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;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;
- }
- }
- j_times_ptns_to_read+=ptns_to_read;
- }
- }
- for(i=0;(i<c_p_c) && (partition_count<ptns_to_read);++i) {
- for(j_times_ptns_to_read=0, j=0;j<ch_used;++j) {
- uint_fast16_t voffs;
-
- if (!do_not_decode[j]) {
- uint_fast8_t vqclass=classifs[j_times_ptns_to_read+partition_count];
- int_fast16_t vqbook=vr->books[vqclass][pass];
-
- if (vqbook>=0) {
- 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];
-
- if (vr->type==0) {
-
- voffs=voffset+j*vlen;
- for(k=0;k<step;++k) {
- coffs=get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * dim;
- for(l=0;l<dim;++l) {
- vec[voffs+k+l*step]+=codebook.codevectors[coffs+l]; // FPMATH
- }
- }
- }
- else if (vr->type==1) {
- voffs=voffset+j*vlen;
- for(k=0;k<step;++k) {
- coffs=get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * dim;
- for(l=0;l<dim;++l, ++voffs) {
- vec[voffs]+=codebook.codevectors[coffs+l]; // FPMATH
-
- AV_DEBUG(" pass %d offs: %d curr: %f change: %f cv offs.: %d \n", pass, voffs, vec[voffs], codebook.codevectors[coffs+l], coffs);
- }
- }
- }
- 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;k<step;++k) {
- coffs=get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * 2;
- vec[voffs+k ]+=codebook.codevectors[coffs ]; // FPMATH
- vec[voffs+k+vlen]+=codebook.codevectors[coffs+1]; // FPMATH
- }
- } else
- for(k=0;k<step;++k) {
- coffs=get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * dim;
- for(l=0;l<dim;l+=2, voffs++) {
- vec[voffs ]+=codebook.codevectors[coffs+l ]; // FPMATH
- vec[voffs+vlen]+=codebook.codevectors[coffs+l+1]; // FPMATH
-
- AV_DEBUG(" pass %d offs: %d curr: %f change: %f cv offs.: %d+%d \n", pass, voffset/ch+(voffs%ch)*vlen, vec[voffset/ch+(voffs%ch)*vlen], codebook.codevectors[coffs+l], coffs, l);
- }
- }
-
- }
- else if (vr->type==2) {
- voffs=voffset;
-
- for(k=0;k<step;++k) {
- coffs=get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * dim;
- for(l=0;l<dim;++l, ++voffs) {
- vec[voffs/ch+(voffs%ch)*vlen]+=codebook.codevectors[coffs+l]; // FPMATH FIXME use if and counter instead of / and %
-
- AV_DEBUG(" pass %d offs: %d curr: %f change: %f cv offs.: %d+%d \n", pass, voffset/ch+(voffs%ch)*vlen, vec[voffset/ch+(voffs%ch)*vlen], codebook.codevectors[coffs+l], coffs, l);
- }
- }
- } else {
- av_log(vc->avccontext, AV_LOG_ERROR, " Invalid residue type while residue decode?! \n");
- return 1;
- }
- }
- }
- j_times_ptns_to_read+=ptns_to_read;
- }
- ++partition_count;
- voffset+=vr->partition_size;
- }
- }
- }
- return 0;
-}
-
-void vorbis_inverse_coupling(float *mag, float *ang, int blocksize)
-{
- int 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;
- }
- } else {
- if (ang[i]>0.0) {
- ang[i]+=mag[i];
- } else {
- float temp=ang[i];
- ang[i]=mag[i];
- mag[i]-=temp;
- }
- }
- }
-}
-
-// Decode the audio packet using the functions above
-
-static int vorbis_parse_audio_packet(vorbis_context *vc) {
- GetBitContext *gb=&vc->gb;
-
- uint_fast8_t previous_window=0,next_window=0;
- uint_fast8_t mode_number;
- uint_fast16_t blocksize;
- int_fast32_t i,j;
- 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;
- uint_fast8_t res_chan[vc->audio_channels];
- uint_fast8_t res_num=0;
- int_fast16_t retlen=0;
- uint_fast16_t saved_start=0;
- float fadd_bias = vc->add_bias;
-
- if (get_bits1(gb)) {
- av_log(vc->avccontext, AV_LOG_ERROR, "Not a Vorbis I audio packet.\n");
- return -1; // packet type not audio
- }
-
- if (vc->mode_count==1) {
- mode_number=0;
- } else {
- mode_number=get_bits(gb, ilog(vc->mode_count-1));
- }
- 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);
-
- if (vc->modes[mode_number].blockflag) {
- previous_window=get_bits1(gb);
- next_window=get_bits1(gb);
- }
-
- blocksize=vc->blocksize[vc->modes[mode_number].blockflag];
- 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;i<vc->audio_channels;++i) {
- vorbis_floor *floor;
- if (mapping->submaps>1) {
- floor=&vc->floors[mapping->submap_floor[mapping->mux[i]]];
- } else {
- floor=&vc->floors[mapping->submap_floor[0]];
- }
-
- 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) {
- if (!(no_residue[mapping->magnitude[i]] & no_residue[mapping->angle[i]])) {
- no_residue[mapping->magnitude[i]]=0;
- no_residue[mapping->angle[i]]=0;
- }
- }
-
-// Decode residue
-
- for(i=0;i<mapping->submaps;++i) {
- vorbis_residue *residue;
- uint_fast8_t ch=0;
-
- 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;
- } else {
- do_not_decode[ch]=0;
- }
- ++ch;
- ++res_num;
- }
- }
- 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;
- }
-
-// Inverse coupling
-
- 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);
- }
-
-// Dotproduct
-
- for(j=0, ch_floor_ptr=vc->channel_floors;j<vc->audio_channels;++j,ch_floor_ptr+=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);
- }
-
-// MDCT, overlap/add, save data for next overlapping FPMATH
-
- for(j=0;j<vc->audio_channels;++j) {
- uint_fast8_t step=vc->audio_channels;
- uint_fast16_t k;
- float *saved=vc->saved+j*vc->blocksize[1]/2;
- float *ret=vc->ret;
- const float *lwin=vc->win[1];
- const float *swin=vc->win[0];
- float *buf=vc->buf;
- float *buf_tmp=vc->buf_tmp;
-
- ch_floor_ptr=vc->channel_floors+j*blocksize/2;
-
- saved_start=vc->saved_start;
-
- vc->mdct[0].fft.imdct_calc(&vc->mdct[vc->modes[mode_number].blockflag], buf, ch_floor_ptr, buf_tmp);
-
- //FIXME process channels together, to allow faster simd vector_fmul_add_add?
- if (vc->modes[mode_number].blockflag) {
- // -- overlap/add
- if (previous_window) {
- vc->dsp.vector_fmul_add_add(ret+j, buf, lwin, saved, vc->add_bias, vc->blocksize[1]/2, step);
- retlen=vc->blocksize[1]/2;
- } else {
- int len = (vc->blocksize[1]-vc->blocksize[0])/4;
- buf += len;
- vc->dsp.vector_fmul_add_add(ret+j, buf, swin, saved, vc->add_bias, vc->blocksize[0]/2, step);
- k = vc->blocksize[0]/2*step + j;
- buf += vc->blocksize[0]/2;
- if(vc->exp_bias){
- for(i=0; i<len; i++, k+=step)
- ((uint32_t*)ret)[k] = ((uint32_t*)buf)[i] + vc->exp_bias; // ret[k]=buf[i]*(1<<bias)
- } else {
- for(i=0; i<len; i++, k+=step)
- ret[k] = buf[i] + fadd_bias;
- }
- buf=vc->buf;
- retlen=vc->blocksize[0]/2+len;
- }
- // -- save
- if (next_window) {
- buf += vc->blocksize[1]/2;
- vc->dsp.vector_fmul_reverse(saved, buf, lwin, vc->blocksize[1]/2);
- saved_start=0;
- } else {
- saved_start=(vc->blocksize[1]-vc->blocksize[0])/4;
- buf += vc->blocksize[1]/2;
- for(i=0; i<saved_start; i++)
- ((uint32_t*)saved)[i] = ((uint32_t*)buf)[i] + vc->exp_bias;
- vc->dsp.vector_fmul_reverse(saved+saved_start, buf+saved_start, swin, vc->blocksize[0]/2);
- }
- } else {
- // --overlap/add
- if(vc->add_bias) {
- for(k=j, i=0;i<saved_start;++i, k+=step)
- ret[k] = saved[i] + fadd_bias;
- } else {
- for(k=j, i=0;i<saved_start;++i, k+=step)
- ret[k] = saved[i];
- }
- vc->dsp.vector_fmul_add_add(ret+k, buf, swin, saved+saved_start, vc->add_bias, vc->blocksize[0]/2, step);
- retlen=saved_start+vc->blocksize[0]/2;
- // -- save
- buf += vc->blocksize[0]/2;
- vc->dsp.vector_fmul_reverse(saved, buf, swin, vc->blocksize[0]/2);
- saved_start=0;
- }
- }
- vc->saved_start=saved_start;
-
- return retlen*vc->audio_channels;
-}
-
-// Return the decoded audio packet through the standard api
-
-static int vorbis_decode_frame(AVCodecContext *avccontext,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- vorbis_context *vc = avccontext->priv_data ;
- GetBitContext *gb = &(vc->gb);
-
- int_fast16_t len;
-
- 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);
-
- if (len<=0) {
- *data_size=0;
- return buf_size;
- }
-
- if (!vc->first_frame) {
- 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);
-
- vc->dsp.float_to_int16(data, vc->ret, len);
- *data_size=len*2;
-
- return buf_size ;
-}
-
-// Close decoder
-
-static int vorbis_decode_close(AVCodecContext *avccontext) {
- vorbis_context *vc = avccontext->priv_data;
-
- vorbis_free(vc);
-
- return 0 ;
-}
-
-AVCodec vorbis_decoder = {
- "vorbis",
- CODEC_TYPE_AUDIO,
- CODEC_ID_VORBIS,
- sizeof(vorbis_context),
- vorbis_decode_init,
- NULL,
- vorbis_decode_close,
- vorbis_decode_frame,
-};
-
diff --git a/src/libffmpeg/libavcodec/vp3.c b/src/libffmpeg/libavcodec/vp3.c
deleted file mode 100644
index f02215407..000000000
--- a/src/libffmpeg/libavcodec/vp3.c
+++ /dev/null
@@ -1,2657 +0,0 @@
-/*
- * Copyright (C) 2003-2004 the ffmpeg project
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-/**
- * @file vp3.c
- * On2 VP3 Video Decoder
- *
- * VP3 Video Decoder by Mike Melanson (mike at multimedia.cx)
- * For more information about the VP3 coding process, visit:
- * http://multimedia.cx/
- *
- * Theora decoder by Alex Beregszaszi
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "common.h"
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-
-#include "vp3data.h"
-
-#define FRAGMENT_PIXELS 8
-
-/*
- * Debugging Variables
- *
- * Define one or more of the following compile-time variables to 1 to obtain
- * elaborate information about certain aspects of the decoding process.
- *
- * KEYFRAMES_ONLY: set this to 1 to only see keyframes (VP3 slideshow mode)
- * DEBUG_VP3: high-level decoding flow
- * DEBUG_INIT: initialization parameters
- * DEBUG_DEQUANTIZERS: display how the dequanization tables are built
- * DEBUG_BLOCK_CODING: unpacking the superblock/macroblock/fragment coding
- * DEBUG_MODES: unpacking the coding modes for individual fragments
- * DEBUG_VECTORS: display the motion vectors
- * DEBUG_TOKEN: display exhaustive information about each DCT token
- * DEBUG_VLC: display the VLCs as they are extracted from the stream
- * DEBUG_DC_PRED: display the process of reversing DC prediction
- * DEBUG_IDCT: show every detail of the IDCT process
- */
-
-#define KEYFRAMES_ONLY 0
-
-#define DEBUG_VP3 0
-#define DEBUG_INIT 0
-#define DEBUG_DEQUANTIZERS 0
-#define DEBUG_BLOCK_CODING 0
-#define DEBUG_MODES 0
-#define DEBUG_VECTORS 0
-#define DEBUG_TOKEN 0
-#define DEBUG_VLC 0
-#define DEBUG_DC_PRED 0
-#define DEBUG_IDCT 0
-
-#if DEBUG_VP3
-#define debug_vp3(args...) av_log(NULL, AV_LOG_DEBUG, ## args)
-#else
-static inline void debug_vp3(const char *format, ...) { }
-#endif
-
-#if DEBUG_INIT
-#define debug_init(args...) av_log(NULL, AV_LOG_DEBUG, ## args)
-#else
-static inline void debug_init(const char *format, ...) { }
-#endif
-
-#if DEBUG_DEQUANTIZERS
-#define debug_dequantizers(args...) av_log(NULL, AV_LOG_DEBUG, ## args)
-#else
-static inline void debug_dequantizers(const char *format, ...) { }
-#endif
-
-#if DEBUG_BLOCK_CODING
-#define debug_block_coding(args...) av_log(NULL, AV_LOG_DEBUG, ## args)
-#else
-static inline void debug_block_coding(const char *format, ...) { }
-#endif
-
-#if DEBUG_MODES
-#define debug_modes(args...) av_log(NULL, AV_LOG_DEBUG, ## args)
-#else
-static inline void debug_modes(const char *format, ...) { }
-#endif
-
-#if DEBUG_VECTORS
-#define debug_vectors(args...) av_log(NULL, AV_LOG_DEBUG, ## args)
-#else
-static inline void debug_vectors(const char *format, ...) { }
-#endif
-
-#if DEBUG_TOKEN
-#define debug_token(args...) av_log(NULL, AV_LOG_DEBUG, ## args)
-#else
-static inline void debug_token(const char *format, ...) { }
-#endif
-
-#if DEBUG_VLC
-#define debug_vlc(args...) av_log(NULL, AV_LOG_DEBUG, ## args)
-#else
-static inline void debug_vlc(const char *format, ...) { }
-#endif
-
-#if DEBUG_DC_PRED
-#define debug_dc_pred(args...) av_log(NULL, AV_LOG_DEBUG, ## args)
-#else
-static inline void debug_dc_pred(const char *format, ...) { }
-#endif
-
-#if DEBUG_IDCT
-#define debug_idct(args...) av_log(NULL, AV_LOG_DEBUG, ## args)
-#else
-static inline void debug_idct(const char *format, ...) { }
-#endif
-
-typedef struct Coeff {
- struct Coeff *next;
- DCTELEM coeff;
- uint8_t index;
-} Coeff;
-
-//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;
- uint8_t coding_method;
- uint8_t coeff_count;
- int8_t motion_x;
- int8_t motion_y;
-} Vp3Fragment;
-
-#define SB_NOT_CODED 0
-#define SB_PARTIALLY_CODED 1
-#define SB_FULLY_CODED 2
-
-#define MODE_INTER_NO_MV 0
-#define MODE_INTRA 1
-#define MODE_INTER_PLUS_MV 2
-#define MODE_INTER_LAST_MV 3
-#define MODE_INTER_PRIOR_LAST 4
-#define MODE_USING_GOLDEN 5
-#define MODE_GOLDEN_MV 6
-#define MODE_INTER_FOURMV 7
-#define CODING_MODE_COUNT 8
-
-/* special internal mode */
-#define MODE_COPY 8
-
-/* There are 6 preset schemes, plus a free-form scheme */
-static int ModeAlphabet[7][CODING_MODE_COUNT] =
-{
- /* this is the custom scheme */
- { 0, 0, 0, 0, 0, 0, 0, 0 },
-
- /* scheme 1: Last motion vector dominates */
- { MODE_INTER_LAST_MV, MODE_INTER_PRIOR_LAST,
- MODE_INTER_PLUS_MV, MODE_INTER_NO_MV,
- MODE_INTRA, MODE_USING_GOLDEN,
- MODE_GOLDEN_MV, MODE_INTER_FOURMV },
-
- /* scheme 2 */
- { MODE_INTER_LAST_MV, MODE_INTER_PRIOR_LAST,
- MODE_INTER_NO_MV, MODE_INTER_PLUS_MV,
- MODE_INTRA, MODE_USING_GOLDEN,
- MODE_GOLDEN_MV, MODE_INTER_FOURMV },
-
- /* scheme 3 */
- { MODE_INTER_LAST_MV, MODE_INTER_PLUS_MV,
- MODE_INTER_PRIOR_LAST, MODE_INTER_NO_MV,
- MODE_INTRA, MODE_USING_GOLDEN,
- MODE_GOLDEN_MV, MODE_INTER_FOURMV },
-
- /* scheme 4 */
- { MODE_INTER_LAST_MV, MODE_INTER_PLUS_MV,
- MODE_INTER_NO_MV, MODE_INTER_PRIOR_LAST,
- MODE_INTRA, MODE_USING_GOLDEN,
- MODE_GOLDEN_MV, MODE_INTER_FOURMV },
-
- /* scheme 5: No motion vector dominates */
- { MODE_INTER_NO_MV, MODE_INTER_LAST_MV,
- MODE_INTER_PRIOR_LAST, MODE_INTER_PLUS_MV,
- MODE_INTRA, MODE_USING_GOLDEN,
- MODE_GOLDEN_MV, MODE_INTER_FOURMV },
-
- /* scheme 6 */
- { MODE_INTER_NO_MV, MODE_USING_GOLDEN,
- MODE_INTER_LAST_MV, MODE_INTER_PRIOR_LAST,
- MODE_INTER_PLUS_MV, MODE_INTRA,
- MODE_GOLDEN_MV, MODE_INTER_FOURMV },
-
-};
-
-#define MIN_DEQUANT_VAL 2
-
-typedef struct Vp3DecodeContext {
- AVCodecContext *avctx;
- int theora, theora_tables;
- int version;
- int width, height;
- AVFrame golden_frame;
- AVFrame last_frame;
- AVFrame current_frame;
- int keyframe;
- DSPContext dsp;
- int flipped_image;
-
- int qis[3];
- int nqis;
- int quality_index;
- int last_quality_index;
-
- int superblock_count;
- int superblock_width;
- int superblock_height;
- int y_superblock_width;
- int y_superblock_height;
- int c_superblock_width;
- int c_superblock_height;
- int u_superblock_start;
- int v_superblock_start;
- unsigned char *superblock_coding;
-
- int macroblock_count;
- int macroblock_width;
- int macroblock_height;
-
- int fragment_count;
- int fragment_width;
- int fragment_height;
-
- Vp3Fragment *all_fragments;
- Coeff *coeffs;
- Coeff *next_coeff;
- int fragment_start[3];
-
- ScanTable scantable;
-
- /* tables */
- uint16_t coded_dc_scale_factor[64];
- uint32_t coded_ac_scale_factor[64];
- uint8_t base_matrix[384][64];
- uint8_t qr_count[2][3];
- uint8_t qr_size [2][3][64];
- uint16_t qr_base[2][3][64];
-
- /* this is a list of indices into the all_fragments array indicating
- * which of the fragments are coded */
- int *coded_fragment_list;
- int coded_fragment_list_index;
- int pixel_addresses_inited;
-
- VLC dc_vlc[16];
- VLC ac_vlc_1[16];
- VLC ac_vlc_2[16];
- VLC ac_vlc_3[16];
- VLC ac_vlc_4[16];
-
- VLC superblock_run_length_vlc;
- VLC fragment_run_length_vlc;
- VLC mode_code_vlc;
- VLC motion_vector_vlc;
-
- /* these arrays need to be on 16-byte boundaries since SSE2 operations
- * index into them */
- DECLARE_ALIGNED_16(int16_t, qmat[2][4][64]); //<qmat[is_inter][plane]
-
- /* This table contains superblock_count * 16 entries. Each set of 16
- * numbers corresponds to the fragment indices 0..15 of the superblock.
- * An entry will be -1 to indicate that no entry corresponds to that
- * index. */
- int *superblock_fragments;
-
- /* This table contains superblock_count * 4 entries. Each set of 4
- * numbers corresponds to the macroblock indices 0..3 of the superblock.
- * An entry will be -1 to indicate that no entry corresponds to that
- * index. */
- int *superblock_macroblocks;
-
- /* This table contains macroblock_count * 6 entries. Each set of 6
- * numbers corresponds to the fragment indices 0..5 which comprise
- * the macroblock (4 Y fragments and 2 C fragments). */
- int *macroblock_fragments;
- /* This is an array that indicates how a particular macroblock
- * is coded. */
- unsigned char *macroblock_coding;
-
- int first_coded_y_fragment;
- int first_coded_c_fragment;
- int last_coded_y_fragment;
- int last_coded_c_fragment;
-
- uint8_t edge_emu_buffer[9*2048]; //FIXME dynamic alloc
- int8_t qscale_table[2048]; //FIXME dynamic alloc (width+15)/16
-
- /* Huffman decode */
- int hti;
- unsigned int hbits;
- int entries;
- int huff_code_size;
- uint16_t huffman_table[80][32][2];
-
- uint32_t filter_limit_values[64];
- int bounding_values_array[256];
-} Vp3DecodeContext;
-
-static int theora_decode_tables(AVCodecContext *avctx, GetBitContext *gb);
-
-/************************************************************************
- * VP3 specific functions
- ************************************************************************/
-
-/*
- * This function sets up all of the various blocks mappings:
- * superblocks <-> fragments, macroblocks <-> fragments,
- * superblocks <-> macroblocks
- *
- * Returns 0 is successful; returns 1 if *anything* went wrong.
- */
-static int init_block_mapping(Vp3DecodeContext *s)
-{
- int i, j;
- signed int hilbert_walk_mb[4];
-
- int current_fragment = 0;
- int current_width = 0;
- int current_height = 0;
- int right_edge = 0;
- int bottom_edge = 0;
- int superblock_row_inc = 0;
- int *hilbert = NULL;
- int mapping_index = 0;
-
- int current_macroblock;
- int c_fragment;
-
- 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
- };
-
- debug_vp3(" vp3: initialize block mapping tables\n");
-
- 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++) {
- debug_init(" superblock %d (u starts @ %d, v starts @ %d)\n",
- i, s->u_superblock_start, s->v_superblock_start);
-
- /* 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;
- debug_init(" mapping fragment %d to superblock %d, position %d (%d/%d x %d/%d)\n",
- s->superblock_fragments[mapping_index], i, j,
- current_width, right_edge, current_height, bottom_edge);
- } else {
- s->superblock_fragments[mapping_index] = -1;
- debug_init(" superblock %d, position %d has no fragment (%d/%d x %d/%d)\n",
- i, j,
- current_width, right_edge, current_height, bottom_edge);
- }
-
- 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);;
- hilbert = hilbert_walk_mb;
- 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;
- debug_init(" mapping macroblock %d to superblock %d, position %d (%d/%d x %d/%d)\n",
- s->superblock_macroblocks[mapping_index], i, j,
- current_width, right_edge, current_height, bottom_edge);
- } else {
- s->superblock_macroblocks[mapping_index] = -1;
- debug_init(" superblock %d, position %d has no macroblock (%d/%d x %d/%d)\n",
- i, j,
- current_width, right_edge, current_height, bottom_edge);
- }
-
- 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) {
-
- debug_init(" macroblock %d contains fragments: ", current_macroblock);
- s->all_fragments[current_fragment].macroblock = current_macroblock;
- s->macroblock_fragments[mapping_index++] = current_fragment;
- debug_init("%d ", 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;
- debug_init("%d ", 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;
- debug_init("%d ", 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;
- debug_init("%d ", 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;
- debug_init("%d ", 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;
- debug_init("%d ", c_fragment);
-
- debug_init("\n");
-
- if (j + 2 <= s->fragment_width)
- current_fragment += 2;
- else
- current_fragment++;
- current_macroblock++;
- }
-
- current_fragment += s->fragment_width;
- }
-
- 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->all_fragments[i].coeff_count = 0;
- s->all_fragments[i].motion_x = 127;
- s->all_fragments[i].motion_y = 127;
- s->all_fragments[i].next_coeff= NULL;
- 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.
- */
-static void init_dequantizer(Vp3DecodeContext *s)
-{
- int ac_scale_factor = s->coded_ac_scale_factor[s->quality_index];
- int dc_scale_factor = s->coded_dc_scale_factor[s->quality_index];
- int i, plane, inter, qri, bmi, bmj, qistart;
-
- debug_vp3(" vp3: initializing dequantization tables\n");
-
- for(inter=0; inter<2; inter++){
- for(plane=0; plane<3; plane++){
- int sum=0;
- for(qri=0; qri<s->qr_count[inter][plane]; qri++){
- sum+= s->qr_size[inter][plane][qri];
- if(s->quality_index <= sum)
- break;
- }
- qistart= sum - s->qr_size[inter][plane][qri];
- bmi= s->qr_base[inter][plane][qri ];
- bmj= s->qr_base[inter][plane][qri+1];
- for(i=0; i<64; i++){
- int coeff= ( 2*(sum -s->quality_index)*s->base_matrix[bmi][i]
- - 2*(qistart-s->quality_index)*s->base_matrix[bmj][i]
- + s->qr_size[inter][plane][qri])
- / (2*s->qr_size[inter][plane][qri]);
-
- int qmin= 8<<(inter + !i);
- int qscale= i ? ac_scale_factor : dc_scale_factor;
-
- s->qmat[inter][plane][i]= clip((qscale * coeff)/100 * 4, qmin, 4096);
- }
- }
- }
-
- memset(s->qscale_table, (FFMAX(s->qmat[0][0][1], s->qmat[0][1][1])+8)/16, 512); //FIXME finetune
-}
-
-/*
- * This function initializes the loop filter boundary limits if the frame's
- * quality index is different from the previous frame's.
- */
-static void init_loop_filter(Vp3DecodeContext *s)
-{
- int *bounding_values= s->bounding_values_array+127;
- int filter_limit;
- int x;
-
- filter_limit = s->filter_limit_values[s->quality_index];
-
- /* set up the bounding values */
- memset(s->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;
- }
-}
-
-/*
- * This function unpacks all of the superblock/macroblock/fragment coding
- * information from the bitstream.
- */
-static int unpack_superblocks(Vp3DecodeContext *s, GetBitContext *gb)
-{
- 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 i, j;
- int current_fragment;
-
- debug_vp3(" vp3: unpacking superblock coding\n");
-
- if (s->keyframe) {
-
- debug_vp3(" keyframe-- all superblocks are fully coded\n");
- memset(s->superblock_coding, SB_FULLY_CODED, s->superblock_count);
-
- } else {
-
- /* unpack the list of partially-coded superblocks */
- bit = get_bits(gb, 1);
- /* 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;
- current_run = get_vlc2(gb,
- s->superblock_run_length_vlc.table, 6, 2);
- if (current_run == 33)
- current_run += get_bits(gb, 12);
- debug_block_coding(" setting superblocks %d..%d to %s\n",
- current_superblock,
- current_superblock + current_run - 1,
- (bit) ? "partially coded" : "not coded");
-
- /* 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;
- }
- }
- s->superblock_coding[current_superblock++] = bit;
- }
-
- /* 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) {
-
- current_superblock = 0;
- current_run = 0;
- bit = get_bits(gb, 1);
- /* 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) {
-
- /* 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);
- }
-
- debug_block_coding(" setting superblock %d to %s\n",
- current_superblock,
- (bit) ? "fully coded" : "not coded");
- s->superblock_coding[current_superblock] = 2*bit;
- }
- current_superblock++;
- }
- }
-
- /* if there were partial blocks, initialize bitstream for
- * unpacking fragment codings */
- if (decode_partial_blocks) {
-
- current_run = 0;
- bit = get_bits(gb, 1);
- /* toggle the bit because as soon as the first run length is
- * fetched the bit will be toggled again */
- bit ^= 1;
- }
- }
-
- /* 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;
- memset(s->macroblock_coding, MODE_COPY, s->macroblock_count);
- for (i = 0; i < s->superblock_count; 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) {
-
- /* 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) {
-
- /* fragment may or may not be coded; this is the case
- * that cares about the fragment coding runs */
- if (current_run-- == 0) {
- bit ^= 1;
- current_run = get_vlc2(gb,
- s->fragment_run_length_vlc.table, 5, 2);
- }
-
- if (bit) {
- /* 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] =
- 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;
- debug_block_coding(" superblock %d is partially coded, fragment %d is coded\n",
- i, current_fragment);
- } else {
- /* not coded; copy this fragment from the prior frame */
- s->all_fragments[current_fragment].coding_method =
- MODE_COPY;
- debug_block_coding(" superblock %d is partially coded, fragment %d is not coded\n",
- i, current_fragment);
- }
-
- } 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;
- debug_block_coding(" superblock %d is fully coded, fragment %d is coded\n",
- i, current_fragment);
- }
- }
- }
- }
-
- 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;
-
- debug_block_coding(" %d total coded fragments, y: %d -> %d, c: %d -> %d\n",
- s->coded_fragment_list_index,
- s->first_coded_y_fragment,
- s->last_coded_y_fragment,
- s->first_coded_c_fragment,
- s->last_coded_c_fragment);
-
- return 0;
-}
-
-/*
- * This function unpacks all the coding mode data for individual macroblocks
- * from the bitstream.
- */
-static int unpack_modes(Vp3DecodeContext *s, GetBitContext *gb)
-{
- int i, j, k;
- int scheme;
- int current_macroblock;
- int current_fragment;
- int coding_mode;
-
- debug_vp3(" vp3: unpacking encoding modes\n");
-
- if (s->keyframe) {
- debug_vp3(" keyframe-- all blocks are coded as INTRA\n");
-
- for (i = 0; i < s->fragment_count; i++)
- s->all_fragments[i].coding_method = MODE_INTRA;
-
- } else {
-
- /* fetch the mode coding scheme for this frame */
- scheme = get_bits(gb, 3);
- debug_modes(" using mode alphabet %d\n", scheme);
-
- /* is it a custom coding scheme? */
- if (scheme == 0) {
- debug_modes(" custom mode alphabet ahead:\n");
- for (i = 0; i < 8; i++)
- ModeAlphabet[scheme][get_bits(gb, 3)] = i;
- }
-
- for (i = 0; i < 8; i++)
- debug_modes(" mode[%d][%d] = %d\n", scheme, i,
- ModeAlphabet[scheme][i]);
-
- /* iterate through all of the macroblocks that contain 1 or more
- * coded fragments */
- for (i = 0; i < s->u_superblock_start; i++) {
-
- 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))
- 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
- coding_mode = ModeAlphabet[scheme]
- [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;
- }
-
- debug_modes(" coding method for macroblock starting @ fragment %d = %d\n",
- s->macroblock_fragments[current_macroblock * 6], coding_mode);
- }
- }
- }
-
- return 0;
-}
-
-/*
- * This function unpacks all the motion vectors for the individual
- * macroblocks from the bitstream.
- */
-static int unpack_vectors(Vp3DecodeContext *s, GetBitContext *gb)
-{
- int i, j, k;
- int coding_mode;
- int motion_x[6];
- int motion_y[6];
- 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;
-
- debug_vp3(" vp3: unpacking motion vectors\n");
- if (s->keyframe) {
-
- debug_vp3(" keyframe-- there are no motion vectors\n");
-
- } else {
-
- 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_bits(gb, 1);
- debug_vectors(" using %s scheme for unpacking motion vectors\n",
- (coding_mode == 0) ? "VLC" : "fixed-length");
-
- /* iterate through all of the macroblocks that contain 1 or more
- * coded fragments */
- for (i = 0; i < s->u_superblock_start; i++) {
-
- 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))
- 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:
- case MODE_GOLDEN_MV:
- /* all 6 fragments use the same motion vector */
- if (coding_mode == 0) {
- motion_x[0] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)];
- motion_y[0] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)];
- } else {
- motion_x[0] = fixed_motion_vector_table[get_bits(gb, 6)];
- 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) {
- prior_last_motion_x = last_motion_x;
- prior_last_motion_y = last_motion_y;
- last_motion_x = motion_x[0];
- last_motion_y = motion_y[0];
- }
- break;
-
- case MODE_INTER_FOURMV:
- /* 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++) {
- 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)];
- } else {
- motion_x[k] = fixed_motion_vector_table[get_bits(gb, 6)];
- motion_y[k] = fixed_motion_vector_table[get_bits(gb, 6)];
- }
- 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);
-
- /* vector maintenance; vector[3] is treated as the
- * last vector in this case */
- prior_last_motion_x = last_motion_x;
- prior_last_motion_y = last_motion_y;
- last_motion_x = motion_x[3];
- last_motion_y = motion_y[3];
- 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) */
- break;
-
- case MODE_INTER_PRIOR_LAST:
- /* all 6 fragments use the motion vector prior to the
- * 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;
- prior_last_motion_y = last_motion_y;
- last_motion_x = motion_x[0];
- last_motion_y = motion_y[0];
- break;
-
- default:
- /* covers intra, inter without MV, golden without MV */
- memset(motion_x, 0, 6 * sizeof(int));
- memset(motion_y, 0, 6 * sizeof(int));
-
- /* no vector maintenance */
- break;
- }
-
- /* assign the motion vectors to the correct fragments */
- debug_vectors(" vectors for macroblock starting @ fragment %d (coding method %d):\n",
- current_fragment,
- s->macroblock_coding[current_macroblock]);
- 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_vectors(): bad fragment number (%d >= %d)\n",
- current_fragment, s->fragment_count);
- return 1;
- }
- s->all_fragments[current_fragment].motion_x = motion_x[k];
- s->all_fragments[current_fragment].motion_y = motion_y[k];
- debug_vectors(" vector %d: fragment %d = (%d, %d)\n",
- k, current_fragment, motion_x[k], motion_y[k]);
- }
- }
- }
- }
-
- return 0;
-}
-
-/*
- * This function is called by unpack_dct_coeffs() to extract the VLCs from
- * the bitstream. The VLCs encode tokens which are used to unpack DCT
- * data. This function unpacks all the VLCs for either the Y plane or both
- * C planes, and is called for DC coefficients or different AC coefficient
- * levels (since different coefficient types require different VLC tables.
- *
- * This function returns a residual eob run. E.g, if a particular token gave
- * instructions to EOB the next 5 fragments and there were only 2 fragments
- * left in the current fragment range, 3 would be returned so that it could
- * be passed into the next call to this same function.
- */
-static int unpack_vlcs(Vp3DecodeContext *s, GetBitContext *gb,
- VLC *table, int coeff_index,
- int first_fragment, int last_fragment,
- int eob_run)
-{
- int i;
- int token;
- int zero_run = 0;
- DCTELEM coeff = 0;
- Vp3Fragment *fragment;
- uint8_t *perm= s->scantable.permutated;
- int bits_to_get;
-
- if ((first_fragment >= s->fragment_count) ||
- (last_fragment >= s->fragment_count)) {
-
- av_log(s->avctx, AV_LOG_ERROR, " vp3:unpack_vlcs(): bad fragment number (%d -> %d ?)\n",
- first_fragment, last_fragment);
- return 0;
- }
-
- for (i = first_fragment; i <= last_fragment; i++) {
-
- fragment = &s->all_fragments[s->coded_fragment_list[i]];
- if (fragment->coeff_count > coeff_index)
- continue;
-
- if (!eob_run) {
- /* decode a VLC into a token */
- token = get_vlc2(gb, table->table, 5, 3);
- debug_vlc(" token = %2d, ", token);
- /* 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;
- } 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)];
-
- 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) {
- fragment->coeff_count += zero_run;
- if (fragment->coeff_count < 64){
- fragment->next_coeff->coeff= coeff;
- fragment->next_coeff->index= perm[fragment->coeff_count++]; //FIXME perm here already?
- fragment->next_coeff->next= s->next_coeff;
- s->next_coeff->next=NULL;
- fragment->next_coeff= s->next_coeff++;
- }
- debug_vlc(" fragment %d coeff = %d\n",
- s->coded_fragment_list[i], fragment->next_coeff[coeff_index]);
- } else {
- fragment->coeff_count |= 128;
- debug_vlc(" fragment %d eob with %d coefficients\n",
- s->coded_fragment_list[i], fragment->coeff_count&127);
- eob_run--;
- }
- }
-
- return eob_run;
-}
-
-/*
- * This function unpacks all of the DCT coefficient data from the
- * bitstream.
- */
-static int unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb)
-{
- int i;
- int dc_y_table;
- int dc_c_table;
- int ac_y_table;
- int ac_c_table;
- int residual_eob_run = 0;
-
- /* fetch the DC table indices */
- dc_y_table = get_bits(gb, 4);
- dc_c_table = get_bits(gb, 4);
-
- /* unpack the Y plane DC coefficients */
- debug_vp3(" vp3: unpacking Y plane DC coefficients using table %d\n",
- dc_y_table);
- 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);
-
- /* unpack the C plane DC coefficients */
- debug_vp3(" vp3: unpacking C plane DC coefficients using table %d\n",
- dc_c_table);
- 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);
-
- /* fetch the AC table indices */
- ac_y_table = get_bits(gb, 4);
- ac_c_table = get_bits(gb, 4);
-
- /* unpack the group 1 AC coefficients (coeffs 1-5) */
- for (i = 1; i <= 5; i++) {
-
- debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n",
- i, ac_y_table);
- 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);
-
- debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n",
- i, ac_c_table);
- 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);
- }
-
- /* unpack the group 2 AC coefficients (coeffs 6-14) */
- for (i = 6; i <= 14; i++) {
-
- debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n",
- i, ac_y_table);
- 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);
-
- debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n",
- i, ac_c_table);
- 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);
- }
-
- /* unpack the group 3 AC coefficients (coeffs 15-27) */
- for (i = 15; i <= 27; i++) {
-
- debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n",
- i, ac_y_table);
- 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);
-
- debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n",
- i, ac_c_table);
- 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);
- }
-
- /* unpack the group 4 AC coefficients (coeffs 28-63) */
- for (i = 28; i <= 63; i++) {
-
- debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n",
- i, ac_y_table);
- 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);
-
- debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n",
- i, ac_c_table);
- 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);
- }
-
- return 0;
-}
-
-/*
- * This function reverses the DC prediction for each coded fragment in
- * the frame. Much of this function is adapted directly from the original
- * VP3 source code.
- */
-#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
-
-static void reverse_dc_prediction(Vp3DecodeContext *s,
- int first_fragment,
- int fragment_width,
- int fragment_height)
-{
-
-#define PUL 8
-#define PU 4
-#define PUR 2
-#define PL 1
-
- int x, y;
- int i = first_fragment;
-
- int predicted_dc;
-
- /* DC values for the left, up-left, up, and up-right fragments */
- int vl, vul, vu, vur;
-
- /* indices for the left, up-left, up, and up-right fragments */
- int l, ul, u, ur;
-
- /*
- * The 6 fields mean:
- * 0: up-left multiplier
- * 1: up multiplier
- * 2: up-right multiplier
- * 3: left multiplier
- */
- int predictor_transform[16][4] = {
- { 0, 0, 0, 0},
- { 0, 0, 0,128}, // PL
- { 0, 0,128, 0}, // PUR
- { 0, 0, 53, 75}, // PUR|PL
- { 0,128, 0, 0}, // PU
- { 0, 64, 0, 64}, // PU|PL
- { 0,128, 0, 0}, // PU|PUR
- { 0, 0, 53, 75}, // PU|PUR|PL
- {128, 0, 0, 0}, // PUL
- { 0, 0, 0,128}, // PUL|PL
- { 64, 0, 64, 0}, // PUL|PUR
- { 0, 0, 53, 75}, // PUL|PUR|PL
- { 0,128, 0, 0}, // PUL|PU
- {-104,116, 0,116}, // PUL|PU|PL
- { 24, 80, 24, 0}, // PUL|PU|PUR
- {-104,116, 0,116} // PUL|PU|PUR|PL
- };
-
- /* This table shows which types of blocks can use other blocks for
- * prediction. For example, INTRA is the only mode in this table to
- * have a frame number of 0. That means INTRA blocks can only predict
- * 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] = {
- 1, /* MODE_INTER_NO_MV */
- 0, /* MODE_INTRA */
- 1, /* MODE_INTER_PLUS_MV */
- 1, /* MODE_INTER_LAST_MV */
- 1, /* MODE_INTER_PRIOR_MV */
- 2, /* MODE_USING_GOLDEN */
- 2, /* MODE_GOLDEN_MV */
- 1 /* MODE_INTER_FOUR_MV */
- };
- int current_frame_type;
-
- /* there is a last DC predictor for each of the 3 frame types */
- short last_dc[3];
-
- int transform = 0;
-
- debug_vp3(" vp3: reversing DC prediction\n");
-
- vul = vu = vur = vl = 0;
- last_dc[0] = last_dc[1] = last_dc[2] = 0;
-
- /* for each fragment row... */
- for (y = 0; y < fragment_height; y++) {
-
- /* for each fragment in a row... */
- for (x = 0; x < fragment_width; x++, i++) {
-
- /* reverse prediction if this block was coded */
- if (s->all_fragments[i].coding_method != MODE_COPY) {
-
- current_frame_type =
- compatible_frame[s->all_fragments[i].coding_method];
- debug_dc_pred(" frag %d: orig DC = %d, ",
- i, DC_COEFF(i));
-
- transform= 0;
- if(x){
- l= i-1;
- vl = DC_COEFF(l);
- if(FRAME_CODED(l) && COMPATIBLE_FRAME(l))
- transform |= PL;
- }
- if(y){
- u= i-fragment_width;
- vu = DC_COEFF(u);
- if(FRAME_CODED(u) && COMPATIBLE_FRAME(u))
- transform |= PU;
- if(x){
- ul= i-fragment_width-1;
- vul = DC_COEFF(ul);
- if(FRAME_CODED(ul) && 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))
- transform |= PUR;
- }
- }
-
- debug_dc_pred("transform = %d, ", transform);
-
- if (transform == 0) {
-
- /* if there were no fragments to predict from, use last
- * DC saved */
- predicted_dc = last_dc[current_frame_type];
- debug_dc_pred("from last DC (%d) = %d\n",
- current_frame_type, DC_COEFF(i));
-
- } else {
-
- /* apply the appropriate predictor transform */
- predicted_dc =
- (predictor_transform[transform][0] * vul) +
- (predictor_transform[transform][1] * vu) +
- (predictor_transform[transform][2] * vur) +
- (predictor_transform[transform][3] * vl);
-
- predicted_dc /= 128;
-
- /* check for outranging on the [ul u l] and
- * [ul u ur l] predictors */
- if ((transform == 13) || (transform == 15)) {
- if (FFABS(predicted_dc - vu) > 128)
- predicted_dc = vu;
- else if (FFABS(predicted_dc - vl) > 128)
- predicted_dc = vl;
- else if (FFABS(predicted_dc - vul) > 128)
- predicted_dc = vul;
- }
-
- debug_dc_pred("from pred DC = %d\n",
- DC_COEFF(i));
- }
-
- /* 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;
- /* save the DC */
- last_dc[current_frame_type] = DC_COEFF(i);
- if(DC_COEFF(i) && !(s->all_fragments[i].coeff_count&127)){
- s->all_fragments[i].coeff_count= 129;
-// s->all_fragments[i].next_coeff= s->next_coeff;
- s->coeffs[i].next= s->next_coeff;
- (s->next_coeff++)->next=NULL;
- }
- }
- }
- }
-}
-
-
-static void horizontal_filter(unsigned char *first_pixel, int stride,
- int *bounding_values);
-static void vertical_filter(unsigned char *first_pixel, int stride,
- int *bounding_values);
-
-/*
- * Perform the final rendering for a particular slice of data.
- * The slice number ranges from 0..(macroblock_height - 1).
- */
-static void render_slice(Vp3DecodeContext *s, int slice)
-{
- int x;
- int m, n;
- int16_t *dequantizer;
- DECLARE_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;
-
- if (slice >= s->macroblock_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];
- 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];
-
- if (!s->flipped_image) stride = -stride;
-
-
- 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 fragment in a row... */
- for (x = 0; x < plane_width; x += 8, i++) {
-
- if ((i < 0) || (i >= s->fragment_count)) {
- av_log(s->avctx, AV_LOG_ERROR, " vp3:render_slice(): bad fragment number (%d)\n", i);
- return;
- }
-
- /* 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_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_halfpel_index = 0;
-
- /* sort out the motion vector if this fragment is coded
- * using a motion vector method */
- 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);
- }
-
- 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);
-
- motion_halfpel_index = motion_x & 0x01;
- motion_source += (motion_x >> 1);
-
- motion_halfpel_index |= (motion_y & 0x01) << 1;
- motion_source += ((motion_y >> 1) * stride);
-
- if(src_x<0 || src_y<0 || src_x + 9 >= plane_width || src_y + 9 >= plane_height){
- uint8_t *temp= s->edge_emu_buffer;
- if(stride<0) temp -= 9*stride;
- else temp += 9*stride;
-
- ff_emulated_edge_mc(temp, motion_source, stride, 9, 9, src_x, src_y, plane_width, plane_height);
- motion_source= temp;
- }
- }
-
-
- /* first, take care of copying a block from either the
- * previous or the golden frame */
- if (s->all_fragments[i].coding_method != MODE_INTRA) {
- /* Note, it is possible to implement all MC cases with
- put_no_rnd_pixels_l2 which would look more like the
- VP3 source but this would be slower as
- 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,
- 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,
- motion_source - d,
- motion_source + stride + 1 + d,
- stride, 8);
- }
- dequantizer = s->qmat[1][plane];
- }else{
- dequantizer = s->qmat[0][plane];
- }
-
- /* dequantize the DCT coefficients */
- debug_idct("fragment %d, coding mode %d, DC = %d, dequant = %d:\n",
- i, s->all_fragments[i].coding_method,
- DC_COEFF(i), dequantizer[0]);
-
- if(s->avctx->idct_algo==FF_IDCT_VP3){
- Coeff *coeff= s->coeffs + i;
- memset(block, 0, sizeof(block));
- while(coeff->next){
- block[coeff->index]= coeff->coeff * dequantizer[coeff->index];
- coeff= coeff->next;
- }
- }else{
- Coeff *coeff= s->coeffs + i;
- memset(block, 0, sizeof(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) {
- if(s->avctx->idct_algo!=FF_IDCT_VP3)
- block[0] += 128<<3;
- s->dsp.idct_put(
- output_plane + s->all_fragments[i].first_pixel,
- stride,
- block);
- } else {
- s->dsp.idct_add(
- output_plane + s->all_fragments[i].first_pixel,
- stride,
- block);
- }
-
- debug_idct("block after idct_%s():\n",
- (s->all_fragments[i].coding_method == MODE_INTRA)?
- "put" : "add");
- for (m = 0; m < 8; m++) {
- for (n = 0; n < 8; n++) {
- debug_idct(" %3d", *(output_plane +
- s->all_fragments[i].first_pixel + (m * stride + n)));
- }
- debug_idct("\n");
- }
- debug_idct("\n");
-
- } 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,
- 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
- }
- }
- }
-
- /* this looks like a good place for slice dispatch... */
- /* algorithm:
- * if (slice == s->macroblock_height - 1)
- * dispatch (both last slice & 2nd-to-last slice);
- * else if (slice > 0)
- * dispatch (slice - 1);
- */
-
- emms_c();
-}
-
-static void horizontal_filter(unsigned char *first_pixel, int stride,
- int *bounding_values)
-{
- unsigned char *end;
- int filter_value;
-
- for (end= first_pixel + 8*stride; first_pixel != end; first_pixel += stride) {
- filter_value =
- (first_pixel[-2] - first_pixel[ 1])
- +3*(first_pixel[ 0] - first_pixel[-1]);
- filter_value = bounding_values[(filter_value + 4) >> 3];
- first_pixel[-1] = clip_uint8(first_pixel[-1] + filter_value);
- first_pixel[ 0] = clip_uint8(first_pixel[ 0] - filter_value);
- }
-}
-
-static void vertical_filter(unsigned char *first_pixel, int stride,
- int *bounding_values)
-{
- unsigned char *end;
- int filter_value;
- const int nstride= -stride;
-
- for (end= first_pixel + 8; first_pixel < end; first_pixel++) {
- filter_value =
- (first_pixel[2 * nstride] - first_pixel[ stride])
- +3*(first_pixel[0 ] - first_pixel[nstride]);
- filter_value = bounding_values[(filter_value + 4) >> 3];
- first_pixel[nstride] = clip_uint8(first_pixel[nstride] + filter_value);
- first_pixel[0] = clip_uint8(first_pixel[0] - filter_value);
- }
-}
-
-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++) {
-START_TIMER
- /* do not perform left edge filter for left columns frags */
- if ((x > 0) &&
- (s->all_fragments[fragment].coding_method != MODE_COPY)) {
- horizontal_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)) {
- vertical_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)) {
- horizontal_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)) {
- vertical_filter(
- plane_data + s->all_fragments[fragment + width].first_pixel,
- stride, bounding_values);
- }
-
- fragment++;
-STOP_TIMER("loop filter")
- }
- }
- }
-}
-
-/*
- * 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)
-{
-
- int i, x, y;
-
- /* figure out the first pixel addresses for each of the fragments */
- /* Y plane */
- i = 0;
- for (y = s->fragment_height; y > 0; y--) {
- 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;
- debug_init(" fragment %d, first pixel @ %d\n",
- i-1, s->all_fragments[i-1].first_pixel);
- }
- }
-
- /* U plane */
- i = s->fragment_start[1];
- for (y = s->fragment_height / 2; y > 0; y--) {
- 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;
- debug_init(" fragment %d, first pixel @ %d\n",
- i-1, s->all_fragments[i-1].first_pixel);
- }
- }
-
- /* V plane */
- i = s->fragment_start[2];
- for (y = s->fragment_height / 2; y > 0; y--) {
- 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;
- debug_init(" fragment %d, first pixel @ %d\n",
- i-1, s->all_fragments[i-1].first_pixel);
- }
- }
-}
-
-/* FIXME: this should be merged with the above! */
-static void theora_calculate_pixel_addresses(Vp3DecodeContext *s)
-{
-
- int i, x, y;
-
- /* figure out the first pixel addresses for each of the fragments */
- /* Y plane */
- i = 0;
- for (y = 1; y <= s->fragment_height; y++) {
- 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;
- debug_init(" fragment %d, first pixel @ %d\n",
- i-1, s->all_fragments[i-1].first_pixel);
- }
- }
-
- /* U plane */
- i = s->fragment_start[1];
- for (y = 1; y <= s->fragment_height / 2; y++) {
- 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;
- debug_init(" fragment %d, first pixel @ %d\n",
- i-1, s->all_fragments[i-1].first_pixel);
- }
- }
-
- /* V plane */
- i = s->fragment_start[2];
- for (y = 1; y <= s->fragment_height / 2; y++) {
- 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;
- debug_init(" fragment %d, first pixel @ %d\n",
- i-1, s->all_fragments[i-1].first_pixel);
- }
- }
-}
-
-/*
- * This is the ffmpeg/libavcodec API init function.
- */
-static int vp3_decode_init(AVCodecContext *avctx)
-{
- Vp3DecodeContext *s = avctx->priv_data;
- int i, inter, plane;
- int c_width;
- int c_height;
- int y_superblock_count;
- int c_superblock_count;
-
- if (avctx->codec_tag == MKTAG('V','P','3','0'))
- s->version = 0;
- else
- s->version = 1;
-
- s->avctx = avctx;
- s->width = (avctx->width + 15) & 0xFFFFFFF0;
- s->height = (avctx->height + 15) & 0xFFFFFFF0;
- avctx->pix_fmt = PIX_FMT_YUV420P;
- avctx->has_b_frames = 0;
- if(avctx->idct_algo==FF_IDCT_AUTO)
- avctx->idct_algo=FF_IDCT_VP3;
- dsputil_init(&s->dsp, avctx);
-
- ff_init_scantable(s->dsp.idct_permutation, &s->scantable, ff_zigzag_direct);
-
- /* initialize to an impossible value which will force a recalculation
- * in the first frame decode */
- s->quality_index = -1;
-
- 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;
-
- /* work out the dimensions for the C planes */
- c_width = s->width / 2;
- c_height = s->height / 2;
- 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->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_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;
-
- /* 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;
-
- debug_init(" Y plane: %d x %d\n", s->width, s->height);
- debug_init(" C plane: %d x %d\n", c_width, c_height);
- debug_init(" Y superblocks: %d x %d, %d total\n",
- s->y_superblock_width, s->y_superblock_height, y_superblock_count);
- debug_init(" C superblocks: %d x %d, %d total\n",
- s->c_superblock_width, s->c_superblock_height, c_superblock_count);
- debug_init(" total superblocks = %d, U starts @ %d, V starts @ %d\n",
- s->superblock_count, s->u_superblock_start, s->v_superblock_start);
- debug_init(" macroblocks: %d x %d, %d total\n",
- s->macroblock_width, s->macroblock_height, s->macroblock_count);
- debug_init(" %d fragments, %d x %d, u starts @ %d, v starts @ %d\n",
- s->fragment_count,
- s->fragment_width,
- s->fragment_height,
- s->fragment_start[1],
- s->fragment_start[2]);
-
- s->all_fragments = av_malloc(s->fragment_count * sizeof(Vp3Fragment));
- s->coeffs = av_malloc(s->fragment_count * sizeof(Coeff) * 65);
- s->coded_fragment_list = av_malloc(s->fragment_count * sizeof(int));
- s->pixel_addresses_inited = 0;
-
- if (!s->theora_tables)
- {
- for (i = 0; i < 64; i++) {
- s->coded_dc_scale_factor[i] = vp31_dc_scale_factor[i];
- s->coded_ac_scale_factor[i] = vp31_ac_scale_factor[i];
- s->base_matrix[0][i] = vp31_intra_y_dequant[i];
- s->base_matrix[1][i] = vp31_intra_c_dequant[i];
- s->base_matrix[2][i] = vp31_inter_dequant[i];
- s->filter_limit_values[i] = vp31_filter_limit_values[i];
- }
-
- for(inter=0; inter<2; inter++){
- for(plane=0; plane<3; plane++){
- s->qr_count[inter][plane]= 1;
- s->qr_size [inter][plane][0]= 63;
- s->qr_base [inter][plane][0]=
- s->qr_base [inter][plane][1]= 2*inter + (!!plane)*!inter;
- }
- }
-
- /* init VLC tables */
- for (i = 0; i < 16; i++) {
-
- /* DC histograms */
- init_vlc(&s->dc_vlc[i], 5, 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,
- &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,
- &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,
- &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,
- &ac_bias_3[i][0][1], 4, 2,
- &ac_bias_3[i][0][0], 4, 2, 0);
- }
- } else {
- for (i = 0; i < 16; i++) {
-
- /* DC histograms */
- 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);
-
- /* group 1 AC histograms */
- 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);
-
- /* group 2 AC histograms */
- 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);
-
- /* group 3 AC histograms */
- 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);
-
- /* group 4 AC histograms */
- 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);
- }
- }
-
- init_vlc(&s->superblock_run_length_vlc, 6, 34,
- &superblock_run_length_vlc_table[0][1], 4, 2,
- &superblock_run_length_vlc_table[0][0], 4, 2, 0);
-
- init_vlc(&s->fragment_run_length_vlc, 5, 30,
- &fragment_run_length_vlc_table[0][1], 4, 2,
- &fragment_run_length_vlc_table[0][0], 4, 2, 0);
-
- init_vlc(&s->mode_code_vlc, 3, 8,
- &mode_code_vlc_table[0][1], 2, 1,
- &mode_code_vlc_table[0][0], 2, 1, 0);
-
- init_vlc(&s->motion_vector_vlc, 6, 63,
- &motion_vector_vlc_table[0][1], 2, 1,
- &motion_vector_vlc_table[0][0], 2, 1, 0);
-
- /* 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);
- init_block_mapping(s);
-
- for (i = 0; i < 3; i++) {
- s->current_frame.data[i] = NULL;
- s->last_frame.data[i] = NULL;
- s->golden_frame.data[i] = NULL;
- }
-
- return 0;
-}
-
-/*
- * This is the ffmpeg/libavcodec API frame decode function.
- */
-static int vp3_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- Vp3DecodeContext *s = avctx->priv_data;
- GetBitContext gb;
- static int counter = 0;
- int i;
-
- init_get_bits(&gb, buf, buf_size * 8);
-
- if (s->theora && get_bits1(&gb))
- {
-#if 1
- av_log(avctx, AV_LOG_ERROR, "Header packet passed to frame decoder, skipping\n");
- return -1;
-#else
- int ptype = get_bits(&gb, 7);
-
- skip_bits(&gb, 6*8); /* "theora" */
-
- switch(ptype)
- {
- case 1:
- theora_decode_comments(avctx, &gb);
- break;
- case 2:
- theora_decode_tables(avctx, &gb);
- init_dequantizer(s);
- break;
- default:
- av_log(avctx, AV_LOG_ERROR, "Unknown Theora config packet: %d\n", ptype);
- }
- return buf_size;
-#endif
- }
-
- s->keyframe = !get_bits1(&gb);
- if (!s->theora)
- skip_bits(&gb, 1);
- s->last_quality_index = s->quality_index;
-
- s->nqis=0;
- do{
- s->qis[s->nqis++]= get_bits(&gb, 6);
- } while(s->theora >= 0x030200 && s->nqis<3 && get_bits1(&gb));
-
- s->quality_index= s->qis[0];
-
- if (s->avctx->debug & FF_DEBUG_PICT_INFO)
- av_log(s->avctx, AV_LOG_INFO, " VP3 %sframe #%d: Q index = %d\n",
- s->keyframe?"key":"", counter, s->quality_index);
- counter++;
-
- if (s->quality_index != s->last_quality_index) {
- init_dequantizer(s);
- init_loop_filter(s);
- }
-
- if (s->keyframe) {
- if (!s->theora)
- {
- skip_bits(&gb, 4); /* width code */
- skip_bits(&gb, 4); /* height code */
- if (s->version)
- {
- s->version = get_bits(&gb, 5);
- if (counter == 1)
- av_log(s->avctx, AV_LOG_DEBUG, "VP version: %d\n", s->version);
- }
- }
- if (s->version || s->theora)
- {
- if (get_bits1(&gb))
- 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_inited)
- {
- if (!s->flipped_image)
- vp3_calculate_pixel_addresses(s);
- else
- theora_calculate_pixel_addresses(s);
- s->pixel_addresses_inited = 1;
- }
- } else {
- /* allocate a new current frame */
- s->current_frame.reference = 3;
- if (!s->pixel_addresses_inited) {
- 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;
- }
- }
-
- s->current_frame.qscale_table= s->qscale_table; //FIXME allocate individual tables per AVFrame
- s->current_frame.qstride= 0;
-
- {START_TIMER
- init_frame(s, &gb);
- STOP_TIMER("init_frame")}
-
-#if KEYFRAMES_ONLY
-if (!s->keyframe) {
-
- memcpy(s->current_frame.data[0], s->golden_frame.data[0],
- s->current_frame.linesize[0] * s->height);
- memcpy(s->current_frame.data[1], s->golden_frame.data[1],
- s->current_frame.linesize[1] * s->height / 2);
- memcpy(s->current_frame.data[2], s->golden_frame.data[2],
- s->current_frame.linesize[2] * s->height / 2);
-
-} else {
-#endif
-
- {START_TIMER
- if (unpack_superblocks(s, &gb)){
- av_log(s->avctx, AV_LOG_ERROR, "error in unpack_superblocks\n");
- return -1;
- }
- STOP_TIMER("unpack_superblocks")}
- {START_TIMER
- if (unpack_modes(s, &gb)){
- av_log(s->avctx, AV_LOG_ERROR, "error in unpack_modes\n");
- return -1;
- }
- STOP_TIMER("unpack_modes")}
- {START_TIMER
- if (unpack_vectors(s, &gb)){
- av_log(s->avctx, AV_LOG_ERROR, "error in unpack_vectors\n");
- return -1;
- }
- STOP_TIMER("unpack_vectors")}
- {START_TIMER
- if (unpack_dct_coeffs(s, &gb)){
- av_log(s->avctx, AV_LOG_ERROR, "error in unpack_dct_coeffs\n");
- return -1;
- }
- STOP_TIMER("unpack_dct_coeffs")}
- {START_TIMER
-
- 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);
- }
- STOP_TIMER("reverse_dc_prediction")}
- {START_TIMER
-
- for (i = 0; i < s->macroblock_height; i++)
- render_slice(s, i);
- STOP_TIMER("render_fragments")}
-
- {START_TIMER
- apply_loop_filter(s);
- STOP_TIMER("apply_loop_filter")}
-#if KEYFRAMES_ONLY
-}
-#endif
-
- *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]))
- avctx->release_buffer(avctx, &s->last_frame);
-
- /* shuffle frames (last = current) */
- s->last_frame= s->current_frame;
- s->current_frame.data[0]= NULL; /* ensure that we catch any access to this released frame */
-
- return buf_size;
-}
-
-/*
- * This is the ffmpeg/libavcodec API module cleanup function.
- */
-static int vp3_decode_end(AVCodecContext *avctx)
-{
- Vp3DecodeContext *s = avctx->priv_data;
-
- av_free(s->all_fragments);
- av_free(s->coeffs);
- av_free(s->coded_fragment_list);
- av_free(s->superblock_fragments);
- av_free(s->superblock_macroblocks);
- av_free(s->macroblock_fragments);
- av_free(s->macroblock_coding);
-
- /* release all frames */
- if (s->golden_frame.data[0] && s->golden_frame.data[0] != s->last_frame.data[0])
- avctx->release_buffer(avctx, &s->golden_frame);
- if (s->last_frame.data[0])
- 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 */
-
- return 0;
-}
-
-static int read_huffman_tree(AVCodecContext *avctx, GetBitContext *gb)
-{
- Vp3DecodeContext *s = avctx->priv_data;
-
- if (get_bits(gb, 1)) {
- int token;
- if (s->entries >= 32) { /* overflow */
- av_log(avctx, AV_LOG_ERROR, "huffman tree overflow\n");
- return -1;
- }
- token = get_bits(gb, 5);
- //av_log(avctx, AV_LOG_DEBUG, "hti %d hbits %x token %d entry : %d size %d\n", s->hti, s->hbits, token, s->entries, s->huff_code_size);
- s->huffman_table[s->hti][token][0] = s->hbits;
- s->huffman_table[s->hti][token][1] = s->huff_code_size;
- s->entries++;
- }
- else {
- if (s->huff_code_size >= 32) {/* overflow */
- av_log(avctx, AV_LOG_ERROR, "huffman tree overflow\n");
- return -1;
- }
- s->huff_code_size++;
- s->hbits <<= 1;
- read_huffman_tree(avctx, gb);
- s->hbits |= 1;
- read_huffman_tree(avctx, gb);
- s->hbits >>= 1;
- s->huff_code_size--;
- }
- return 0;
-}
-
-static int theora_decode_header(AVCodecContext *avctx, GetBitContext *gb)
-{
- Vp3DecodeContext *s = avctx->priv_data;
-
- s->theora = get_bits_long(gb, 24);
- av_log(avctx, AV_LOG_INFO, "Theora bitstream version %X\n", s->theora);
-
- /* 3.2.0 aka alpha3 has the same frame orientation as original vp3 */
- /* but previous versions have the image flipped relative to vp3 */
- if (s->theora < 0x030200)
- {
- s->flipped_image = 1;
- av_log(avctx, AV_LOG_DEBUG, "Old (<alpha3) Theora bitstream, flipped image\n");
- }
-
- s->width = get_bits(gb, 16) << 4;
- s->height = get_bits(gb, 16) << 4;
-
- if(avcodec_check_dimensions(avctx, s->width, s->height)){
- av_log(avctx, AV_LOG_ERROR, "Invalid dimensions (%dx%d)\n", s->width, s->height);
- s->width= s->height= 0;
- 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 */
-
- skip_bits(gb, 24); /* frame width */
- skip_bits(gb, 24); /* frame height */
- }
- else
- {
- skip_bits(gb, 24); /* frame width */
- skip_bits(gb, 24); /* frame height */
- }
-
- if (s->theora >= 0x030200) {
- skip_bits(gb, 8); /* offset x */
- skip_bits(gb, 8); /* offset y */
- }
-
- skip_bits(gb, 32); /* fps numerator */
- skip_bits(gb, 32); /* fps denumerator */
- skip_bits(gb, 24); /* aspect numerator */
- skip_bits(gb, 24); /* aspect denumerator */
-
- 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 */
- skip_bits(gb, 24); /* bitrate */
-
- skip_bits(gb, 6); /* quality hint */
-
- if (s->theora >= 0x030200)
- {
- skip_bits(gb, 5); /* keyframe frequency force */
-
- if (s->theora < 0x030400)
- skip_bits(gb, 5); /* spare bits */
- }
-
-// align_get_bits(gb);
-
- avctx->width = s->width;
- avctx->height = s->height;
-
- return 0;
-}
-
-static int theora_decode_tables(AVCodecContext *avctx, GetBitContext *gb)
-{
- Vp3DecodeContext *s = avctx->priv_data;
- int i, n, matrices, inter, plane;
-
- if (s->theora >= 0x030200) {
- n = get_bits(gb, 3);
- /* loop filter limit values table */
- for (i = 0; i < 64; i++)
- s->filter_limit_values[i] = get_bits(gb, n);
- }
-
- if (s->theora >= 0x030200)
- n = get_bits(gb, 4) + 1;
- else
- n = 16;
- /* quality threshold table */
- for (i = 0; i < 64; i++)
- s->coded_ac_scale_factor[i] = get_bits(gb, n);
-
- if (s->theora >= 0x030200)
- n = get_bits(gb, 4) + 1;
- else
- n = 16;
- /* dc scale factor table */
- for (i = 0; i < 64; i++)
- s->coded_dc_scale_factor[i] = get_bits(gb, n);
-
- if (s->theora >= 0x030200)
- matrices = get_bits(gb, 9) + 1;
- else
- matrices = 3;
-
- if(matrices > 384){
- av_log(avctx, AV_LOG_ERROR, "invalid number of base matrixes\n");
- return -1;
- }
-
- for(n=0; n<matrices; n++){
- for (i = 0; i < 64; i++)
- s->base_matrix[n][i]= get_bits(gb, 8);
- }
-
- for (inter = 0; inter <= 1; inter++) {
- for (plane = 0; plane <= 2; plane++) {
- int newqr= 1;
- if (inter || plane > 0)
- newqr = get_bits(gb, 1);
- if (!newqr) {
- int qtj, plj;
- if(inter && get_bits(gb, 1)){
- qtj = 0;
- plj = plane;
- }else{
- qtj= (3*inter + plane - 1) / 3;
- plj= (plane + 2) % 3;
- }
- s->qr_count[inter][plane]= s->qr_count[qtj][plj];
- memcpy(s->qr_size[inter][plane], s->qr_size[qtj][plj], sizeof(s->qr_size[0][0]));
- memcpy(s->qr_base[inter][plane], s->qr_base[qtj][plj], sizeof(s->qr_base[0][0]));
- } else {
- int qri= 0;
- int qi = 0;
-
- for(;;){
- i= get_bits(gb, av_log2(matrices-1)+1);
- if(i>= matrices){
- av_log(avctx, AV_LOG_ERROR, "invalid base matrix index\n");
- return -1;
- }
- s->qr_base[inter][plane][qri]= i;
- if(qi >= 63)
- break;
- i = get_bits(gb, av_log2(63-qi)+1) + 1;
- s->qr_size[inter][plane][qri++]= i;
- qi += i;
- }
-
- if (qi > 63) {
- av_log(avctx, AV_LOG_ERROR, "invalid qi %d > 63\n", qi);
- return -1;
- }
- s->qr_count[inter][plane]= qri;
- }
- }
- }
-
- /* Huffman tables */
- for (s->hti = 0; s->hti < 80; s->hti++) {
- s->entries = 0;
- s->huff_code_size = 1;
- if (!get_bits(gb, 1)) {
- s->hbits = 0;
- read_huffman_tree(avctx, gb);
- s->hbits = 1;
- read_huffman_tree(avctx, gb);
- }
- }
-
- s->theora_tables = 1;
-
- return 0;
-}
-
-static int theora_decode_init(AVCodecContext *avctx)
-{
- Vp3DecodeContext *s = avctx->priv_data;
- GetBitContext gb;
- int ptype;
- uint8_t *p= avctx->extradata;
- int op_bytes, i;
-
- s->theora = 1;
-
- if (!avctx->extradata_size)
- {
- av_log(avctx, AV_LOG_ERROR, "Missing extradata!\n");
- return -1;
- }
-
- for(i=0;i<3;i++) {
- op_bytes = *(p++)<<8;
- op_bytes += *(p++);
-
- init_get_bits(&gb, p, op_bytes);
- p += op_bytes;
-
- ptype = get_bits(&gb, 8);
- debug_vp3("Theora headerpacket type: %x\n", ptype);
-
- if (!(ptype & 0x80))
- {
- av_log(avctx, AV_LOG_ERROR, "Invalid extradata!\n");
-// return -1;
- }
-
- // FIXME: check for this aswell
- skip_bits(&gb, 6*8); /* "theora" */
-
- switch(ptype)
- {
- case 0x80:
- theora_decode_header(avctx, &gb);
- break;
- case 0x81:
-// FIXME: is this needed? it breaks sometimes
-// theora_decode_comments(avctx, gb);
- break;
- case 0x82:
- theora_decode_tables(avctx, &gb);
- break;
- default:
- av_log(avctx, AV_LOG_ERROR, "Unknown Theora config packet: %d\n", ptype&~0x80);
- break;
- }
- if(8*op_bytes != get_bits_count(&gb))
- av_log(avctx, AV_LOG_ERROR, "%d bits left in packet %X\n", 8*op_bytes - get_bits_count(&gb), ptype);
- if (s->theora < 0x030200)
- break;
- }
-
- vp3_decode_init(avctx);
- return 0;
-}
-
-AVCodec vp3_decoder = {
- "vp3",
- CODEC_TYPE_VIDEO,
- CODEC_ID_VP3,
- sizeof(Vp3DecodeContext),
- vp3_decode_init,
- NULL,
- vp3_decode_end,
- vp3_decode_frame,
- 0,
- NULL
-};
-
-AVCodec theora_decoder = {
- "theora",
- CODEC_TYPE_VIDEO,
- CODEC_ID_THEORA,
- sizeof(Vp3DecodeContext),
- theora_decode_init,
- NULL,
- vp3_decode_end,
- vp3_decode_frame,
- 0,
- NULL
-};
diff --git a/src/libffmpeg/libavcodec/vp5.c b/src/libffmpeg/libavcodec/vp5.c
deleted file mode 100644
index ac953c7aa..000000000
--- a/src/libffmpeg/libavcodec/vp5.c
+++ /dev/null
@@ -1,290 +0,0 @@
-/**
- * @file vp5.c
- * VP5 compatible video decoder
- *
- * Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "avcodec.h"
-#include "dsputil.h"
-#include "bitstream.h"
-#include "mpegvideo.h"
-
-#include "vp56.h"
-#include "vp56data.h"
-#include "vp5data.h"
-
-
-static int vp5_parse_header(vp56_context_t *s, uint8_t *buf, int buf_size,
- int *golden_frame)
-{
- vp56_range_coder_t *c = &s->c;
- int rows, cols;
-
- vp56_init_range_decoder(&s->c, buf, buf_size);
- s->frames[VP56_FRAME_CURRENT].key_frame = !vp56_rac_get(c);
- vp56_rac_get(c);
- vp56_init_dequant(s, vp56_rac_gets(c, 6));
- if (s->frames[VP56_FRAME_CURRENT].key_frame)
- {
- vp56_rac_gets(c, 8);
- if(vp56_rac_gets(c, 5) > 5)
- return 0;
- vp56_rac_gets(c, 2);
- if (vp56_rac_get(c)) {
- av_log(s->avctx, AV_LOG_ERROR, "interlacing not supported\n");
- return 0;
- }
- rows = vp56_rac_gets(c, 8); /* number of stored macroblock rows */
- cols = vp56_rac_gets(c, 8); /* number of stored macroblock cols */
- vp56_rac_gets(c, 8); /* number of displayed macroblock rows */
- vp56_rac_gets(c, 8); /* number of displayed macroblock cols */
- vp56_rac_gets(c, 2);
- if (16*cols != s->avctx->coded_width ||
- 16*rows != s->avctx->coded_height) {
- avcodec_set_dimensions(s->avctx, 16*cols, 16*rows);
- return 2;
- }
- }
- 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(vp56_context_t *s, vp56_mv_t *vect)
-{
- vp56_range_coder_t *c = &s->c;
- int comp, di;
-
- for (comp=0; comp<2; comp++) {
- int delta = 0;
- if (vp56_rac_get_prob(c, s->vector_model_dct[comp])) {
- int sign = vp56_rac_get_prob(c, s->vector_model_sig[comp]);
- di = vp56_rac_get_prob(c, s->vector_model_pdi[comp][0]);
- di |= vp56_rac_get_prob(c, s->vector_model_pdi[comp][1]) << 1;
- delta = vp56_rac_get_tree(c, vp56_pva_tree,
- s->vector_model_pdv[comp]);
- delta = di | (delta << 2);
- delta = (delta ^ -sign) + sign;
- }
- if (!comp)
- vect->x = delta;
- else
- vect->y = delta;
- }
-}
-
-static void vp5_parse_vector_models(vp56_context_t *s)
-{
- vp56_range_coder_t *c = &s->c;
- int comp, node;
-
- for (comp=0; comp<2; comp++) {
- if (vp56_rac_get_prob(c, vp5_vmc_pct[comp][0]))
- s->vector_model_dct[comp] = vp56_rac_gets_nn(c, 7);
- if (vp56_rac_get_prob(c, vp5_vmc_pct[comp][1]))
- s->vector_model_sig[comp] = vp56_rac_gets_nn(c, 7);
- if (vp56_rac_get_prob(c, vp5_vmc_pct[comp][2]))
- s->vector_model_pdi[comp][0] = vp56_rac_gets_nn(c, 7);
- if (vp56_rac_get_prob(c, vp5_vmc_pct[comp][3]))
- s->vector_model_pdi[comp][1] = vp56_rac_gets_nn(c, 7);
- }
-
- for (comp=0; comp<2; comp++)
- for (node=0; node<7; node++)
- if (vp56_rac_get_prob(c, vp5_vmc_pct[comp][4 + node]))
- s->vector_model_pdv[comp][node] = vp56_rac_gets_nn(c, 7);
-}
-
-static void vp5_parse_coeff_models(vp56_context_t *s)
-{
- vp56_range_coder_t *c = &s->c;
- uint8_t def_prob[11];
- int node, cg, ctx;
- int ct; /* code type */
- int pt; /* plane type (0 for Y, 1 for U or V) */
-
- memset(def_prob, 0x80, sizeof(def_prob));
-
- for (pt=0; pt<2; pt++)
- for (node=0; node<11; node++)
- if (vp56_rac_get_prob(c, vp5_dccv_pct[pt][node])) {
- def_prob[node] = vp56_rac_gets_nn(c, 7);
- s->coeff_model_dccv[pt][node] = def_prob[node];
- } else if (s->frames[VP56_FRAME_CURRENT].key_frame) {
- s->coeff_model_dccv[pt][node] = def_prob[node];
- }
-
- for (ct=0; ct<3; ct++)
- for (pt=0; pt<2; pt++)
- for (cg=0; cg<6; cg++)
- for (node=0; node<11; node++)
- if (vp56_rac_get_prob(c, vp5_ract_pct[ct][pt][cg][node])) {
- def_prob[node] = vp56_rac_gets_nn(c, 7);
- s->coeff_model_ract[pt][ct][cg][node] = def_prob[node];
- } else if (s->frames[VP56_FRAME_CURRENT].key_frame) {
- s->coeff_model_ract[pt][ct][cg][node] = def_prob[node];
- }
-
- /* coeff_model_dcct is a linear combination of coeff_model_dccv */
- for (pt=0; pt<2; pt++)
- for (ctx=0; ctx<36; ctx++)
- for (node=0; node<5; node++)
- s->coeff_model_dcct[pt][ctx][node] = clip(((s->coeff_model_dccv[pt][node] * vp5_dccv_lc[node][ctx][0] + 128) >> 8) + vp5_dccv_lc[node][ctx][1], 1, 254);
-
- /* coeff_model_acct is a linear combination of coeff_model_ract */
- for (ct=0; ct<3; ct++)
- for (pt=0; pt<2; pt++)
- for (cg=0; cg<3; cg++)
- for (ctx=0; ctx<6; ctx++)
- for (node=0; node<5; node++)
- s->coeff_model_acct[pt][ct][cg][ctx][node] = clip(((s->coeff_model_ract[pt][ct][cg][node] * vp5_ract_lc[ct][cg][node][ctx][0] + 128) >> 8) + vp5_ract_lc[ct][cg][node][ctx][1], 1, 254);
-}
-
-static void vp5_parse_coeff(vp56_context_t *s)
-{
- vp56_range_coder_t *c = &s->c;
- uint8_t *permute = s->scantable.permutated;
- uint8_t *model, *model2;
- int coeff, sign, coeff_idx;
- int b, i, cg, idx, ctx, ctx_last;
- int pt = 0; /* plane type (0 for Y, 1 for U or V) */
-
- for (b=0; b<6; b++) {
- int ct = 1; /* code type */
-
- if (b > 3) pt = 1;
-
- ctx = 6*s->coeff_ctx[vp56_b6to4[b]][0]
- + s->above_blocks[s->above_block_idx[b]].not_null_dc;
- model = s->coeff_model_dccv[pt];
- model2 = s->coeff_model_dcct[pt][ctx];
-
- for (coeff_idx=0; coeff_idx<64; ) {
- if (vp56_rac_get_prob(c, model2[0])) {
- if (vp56_rac_get_prob(c, model2[2])) {
- if (vp56_rac_get_prob(c, model2[3])) {
- s->coeff_ctx[vp56_b6to4[b]][coeff_idx] = 4;
- idx = vp56_rac_get_tree(c, vp56_pc_tree, model);
- sign = vp56_rac_get(c);
- coeff = vp56_coeff_bias[idx];
- for (i=vp56_coeff_bit_length[idx]; i>=0; i--)
- coeff += vp56_rac_get_prob(c, vp56_coeff_parse_table[idx][i]) << i;
- } else {
- if (vp56_rac_get_prob(c, model2[4])) {
- coeff = 3 + vp56_rac_get_prob(c, model[5]);
- s->coeff_ctx[vp56_b6to4[b]][coeff_idx] = 3;
- } else {
- coeff = 2;
- s->coeff_ctx[vp56_b6to4[b]][coeff_idx] = 2;
- }
- sign = vp56_rac_get(c);
- }
- ct = 2;
- } else {
- ct = 1;
- s->coeff_ctx[vp56_b6to4[b]][coeff_idx] = 1;
- sign = vp56_rac_get(c);
- coeff = 1;
- }
- coeff = (coeff ^ -sign) + sign;
- if (coeff_idx)
- coeff *= s->dequant_ac;
- s->block_coeff[b][permute[coeff_idx]] = coeff;
- } else {
- if (ct && !vp56_rac_get_prob(c, model2[1]))
- break;
- ct = 0;
- s->coeff_ctx[vp56_b6to4[b]][coeff_idx] = 0;
- }
-
- cg = vp5_coeff_groups[++coeff_idx];
- ctx = s->coeff_ctx[vp56_b6to4[b]][coeff_idx];
- model = s->coeff_model_ract[pt][ct][cg];
- model2 = cg > 2 ? model : s->coeff_model_acct[pt][ct][cg][ctx];
- }
-
- ctx_last = FFMIN(s->coeff_ctx_last[vp56_b6to4[b]], 24);
- s->coeff_ctx_last[vp56_b6to4[b]] = coeff_idx;
- if (coeff_idx < ctx_last)
- for (i=coeff_idx; i<=ctx_last; i++)
- s->coeff_ctx[vp56_b6to4[b]][i] = 5;
- s->above_blocks[s->above_block_idx[b]].not_null_dc = s->coeff_ctx[vp56_b6to4[b]][0];
- }
-}
-
-static void vp5_default_models_init(vp56_context_t *s)
-{
- int i;
-
- for (i=0; i<2; i++) {
- s->vector_model_sig[i] = 0x80;
- s->vector_model_dct[i] = 0x80;
- s->vector_model_pdi[i][0] = 0x55;
- s->vector_model_pdi[i][1] = 0x80;
- }
- memcpy(s->mb_types_stats, vp56_def_mb_types_stats, sizeof(s->mb_types_stats));
- memset(s->vector_model_pdv, 0x80, sizeof(s->vector_model_pdv));
-}
-
-static int vp5_decode_init(AVCodecContext *avctx)
-{
- vp56_context_t *s = avctx->priv_data;
-
- vp56_init(s, avctx, 1);
- 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;
- s->parse_coeff_models = vp5_parse_coeff_models;
- s->parse_header = vp5_parse_header;
-
- return 0;
-}
-
-AVCodec vp5_decoder = {
- "vp5",
- CODEC_TYPE_VIDEO,
- CODEC_ID_VP5,
- sizeof(vp56_context_t),
- vp5_decode_init,
- NULL,
- vp56_free,
- vp56_decode_frame,
-};
diff --git a/src/libffmpeg/libavcodec/vp56.c b/src/libffmpeg/libavcodec/vp56.c
deleted file mode 100644
index eb78d02e4..000000000
--- a/src/libffmpeg/libavcodec/vp56.c
+++ /dev/null
@@ -1,665 +0,0 @@
-/**
- * @file vp56.c
- * VP5 and VP6 compatible video decoder (common features)
- *
- * Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include "avcodec.h"
-
-#include "vp56.h"
-#include "vp56data.h"
-
-
-void vp56_init_dequant(vp56_context_t *s, int quantizer)
-{
- s->quantizer = quantizer;
- s->dequant_dc = vp56_dc_dequant[quantizer] << 2;
- s->dequant_ac = vp56_ac_dequant[quantizer] << 2;
-}
-
-static int vp56_get_vectors_predictors(vp56_context_t *s, int row, int col,
- vp56_frame_t ref_frame)
-{
- int nb_pred = 0;
- vp56_mv_t vect[2] = {{0,0}, {0,0}};
- int pos, offset;
- vp56_mv_t mvp;
-
- for (pos=0; pos<12; pos++) {
- mvp.x = col + vp56_candidate_predictor_pos[pos][0];
- mvp.y = row + vp56_candidate_predictor_pos[pos][1];
- if (mvp.x < 0 || mvp.x >= s->mb_width ||
- mvp.y < 0 || mvp.y >= s->mb_height)
- continue;
- offset = mvp.x + s->mb_width*mvp.y;
-
- if (vp56_reference_frame[s->macroblocks[offset].type] != ref_frame)
- continue;
- if ((s->macroblocks[offset].mv.x == vect[0].x &&
- s->macroblocks[offset].mv.y == vect[0].y) ||
- (s->macroblocks[offset].mv.x == 0 &&
- s->macroblocks[offset].mv.y == 0))
- continue;
-
- vect[nb_pred++] = s->macroblocks[offset].mv;
- if (nb_pred > 1) {
- nb_pred = -1;
- break;
- }
- s->vector_candidate_pos = pos;
- }
-
- s->vector_candidate[0] = vect[0];
- s->vector_candidate[1] = vect[1];
-
- return nb_pred+1;
-}
-
-static void vp56_parse_mb_type_models(vp56_context_t *s)
-{
- vp56_range_coder_t *c = &s->c;
- int i, ctx, type;
-
- for (ctx=0; ctx<3; ctx++) {
- if (vp56_rac_get_prob(c, 174)) {
- int idx = vp56_rac_gets(c, 4);
- memcpy(s->mb_types_stats[ctx],vp56_pre_def_mb_type_stats[idx][ctx],
- sizeof(s->mb_types_stats[ctx]));
- }
- if (vp56_rac_get_prob(c, 254)) {
- for (type=0; type<10; type++) {
- for(i=0; i<2; i++) {
- if (vp56_rac_get_prob(c, 205)) {
- int delta, sign = vp56_rac_get(c);
-
- delta = vp56_rac_get_tree(c, vp56_pmbtm_tree,
- vp56_mb_type_model_model);
- if (!delta)
- delta = 4 * vp56_rac_gets(c, 7);
- s->mb_types_stats[ctx][type][i] += (delta ^ -sign) + sign;
- }
- }
- }
- }
- }
-
- /* compute MB type probability tables based on previous MB type */
- for (ctx=0; ctx<3; ctx++) {
- int p[10];
-
- for (type=0; type<10; type++)
- p[type] = 100 * s->mb_types_stats[ctx][type][1];
-
- for (type=0; type<10; type++) {
- int p02, p34, p0234, p17, p56, p89, p5689, p156789;
-
- /* conservative MB type probability */
- s->mb_type_model[ctx][type][0] = 255 - (255 * s->mb_types_stats[ctx][type][0]) / (1 + s->mb_types_stats[ctx][type][0] + s->mb_types_stats[ctx][type][1]);
-
- p[type] = 0; /* same MB type => weight is null */
-
- /* binary tree parsing probabilities */
- p02 = p[0] + p[2];
- p34 = p[3] + p[4];
- p0234 = p02 + p34;
- p17 = p[1] + p[7];
- p56 = p[5] + p[6];
- p89 = p[8] + p[9];
- p5689 = p56 + p89;
- p156789 = p17 + p5689;
-
- s->mb_type_model[ctx][type][1] = 1 + 255 * p0234/(1+p0234+p156789);
- s->mb_type_model[ctx][type][2] = 1 + 255 * p02 / (1+p0234);
- s->mb_type_model[ctx][type][3] = 1 + 255 * p17 / (1+p156789);
- s->mb_type_model[ctx][type][4] = 1 + 255 * p[0] / (1+p02);
- s->mb_type_model[ctx][type][5] = 1 + 255 * p[3] / (1+p34);
- s->mb_type_model[ctx][type][6] = 1 + 255 * p[1] / (1+p17);
- s->mb_type_model[ctx][type][7] = 1 + 255 * p56 / (1+p5689);
- s->mb_type_model[ctx][type][8] = 1 + 255 * p[5] / (1+p56);
- s->mb_type_model[ctx][type][9] = 1 + 255 * p[8] / (1+p89);
-
- /* restore initial value */
- p[type] = 100 * s->mb_types_stats[ctx][type][1];
- }
- }
-}
-
-static vp56_mb_t vp56_parse_mb_type(vp56_context_t *s,
- vp56_mb_t prev_type, int ctx)
-{
- uint8_t *mb_type_model = s->mb_type_model[ctx][prev_type];
- vp56_range_coder_t *c = &s->c;
-
- if (vp56_rac_get_prob(c, mb_type_model[0]))
- return prev_type;
- else
- return vp56_rac_get_tree(c, vp56_pmbt_tree, mb_type_model);
-}
-
-static void vp56_decode_4mv(vp56_context_t *s, int row, int col)
-{
- vp56_mv_t mv = {0,0};
- int type[4];
- int b;
-
- /* parse each block type */
- for (b=0; b<4; b++) {
- type[b] = vp56_rac_gets(&s->c, 2);
- if (type[b])
- type[b]++; /* only returns 0, 2, 3 or 4 (all INTER_PF) */
- }
-
- /* get vectors */
- for (b=0; b<4; b++) {
- switch (type[b]) {
- case VP56_MB_INTER_NOVEC_PF:
- s->mv[b] = (vp56_mv_t) {0,0};
- break;
- case VP56_MB_INTER_DELTA_PF:
- s->parse_vector_adjustment(s, &s->mv[b]);
- break;
- case VP56_MB_INTER_V1_PF:
- s->mv[b] = s->vector_candidate[0];
- break;
- case VP56_MB_INTER_V2_PF:
- s->mv[b] = s->vector_candidate[1];
- break;
- }
- mv.x += s->mv[b].x;
- mv.y += s->mv[b].y;
- }
-
- /* this is the one selected for the whole MB for prediction */
- s->macroblocks[row * s->mb_width + col].mv = s->mv[3];
-
- /* chroma vectors are average luma vectors */
- if (s->avctx->codec->id == CODEC_ID_VP5) {
- s->mv[4].x = s->mv[5].x = RSHIFT(mv.x,2);
- s->mv[4].y = s->mv[5].y = RSHIFT(mv.y,2);
- } else {
- s->mv[4] = s->mv[5] = (vp56_mv_t) {mv.x/4, mv.y/4};
- }
-}
-
-static vp56_mb_t vp56_decode_mv(vp56_context_t *s, int row, int col)
-{
- vp56_mv_t *mv, vect = {0,0};
- int ctx, b;
-
- ctx = vp56_get_vectors_predictors(s, row, col, VP56_FRAME_PREVIOUS);
- s->mb_type = vp56_parse_mb_type(s, s->mb_type, ctx);
- s->macroblocks[row * s->mb_width + col].type = s->mb_type;
-
- switch (s->mb_type) {
- case VP56_MB_INTER_V1_PF:
- mv = &s->vector_candidate[0];
- break;
-
- case VP56_MB_INTER_V2_PF:
- mv = &s->vector_candidate[1];
- break;
-
- case VP56_MB_INTER_V1_GF:
- vp56_get_vectors_predictors(s, row, col, VP56_FRAME_GOLDEN);
- mv = &s->vector_candidate[0];
- break;
-
- case VP56_MB_INTER_V2_GF:
- vp56_get_vectors_predictors(s, row, col, VP56_FRAME_GOLDEN);
- mv = &s->vector_candidate[1];
- break;
-
- case VP56_MB_INTER_DELTA_PF:
- s->parse_vector_adjustment(s, &vect);
- mv = &vect;
- break;
-
- case VP56_MB_INTER_DELTA_GF:
- vp56_get_vectors_predictors(s, row, col, VP56_FRAME_GOLDEN);
- s->parse_vector_adjustment(s, &vect);
- mv = &vect;
- break;
-
- case VP56_MB_INTER_4V:
- vp56_decode_4mv(s, row, col);
- return s->mb_type;
-
- default:
- mv = &vect;
- break;
- }
-
- s->macroblocks[row*s->mb_width + col].mv = *mv;
-
- /* same vector for all blocks */
- for (b=0; b<6; b++)
- s->mv[b] = *mv;
-
- return s->mb_type;
-}
-
-static void vp56_add_predictors_dc(vp56_context_t *s, vp56_frame_t ref_frame)
-{
- int idx = s->scantable.permutated[0];
- int i;
-
- for (i=0; i<6; i++) {
- vp56_ref_dc_t *ab = &s->above_blocks[s->above_block_idx[i]];
- vp56_ref_dc_t *lb = &s->left_block[vp56_b6to4[i]];
- int count = 0;
- int dc = 0;
-
- if (ref_frame == lb->ref_frame) {
- dc += lb->dc_coeff;
- count++;
- }
- if (ref_frame == ab->ref_frame) {
- dc += ab->dc_coeff;
- count++;
- }
- if (s->avctx->codec->id == CODEC_ID_VP5) {
- if (count < 2 && ref_frame == ab[-1].ref_frame) {
- dc += ab[-1].dc_coeff;
- count++;
- }
- if (count < 2 && ref_frame == ab[1].ref_frame) {
- dc += ab[1].dc_coeff;
- count++;
- }
- }
- if (count == 0)
- dc = s->prev_dc[vp56_b6to3[i]][ref_frame];
- else if (count == 2)
- dc /= 2;
-
- s->block_coeff[i][idx] += dc;
- s->prev_dc[vp56_b6to3[i]][ref_frame] = s->block_coeff[i][idx];
- ab->dc_coeff = s->block_coeff[i][idx];
- ab->ref_frame = ref_frame;
- lb->dc_coeff = s->block_coeff[i][idx];
- lb->ref_frame = ref_frame;
- s->block_coeff[i][idx] *= s->dequant_dc;
- }
-}
-
-static void vp56_edge_filter(vp56_context_t *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] = clip_uint8(yuv[-pix_inc] + v);
- yuv[0] = clip_uint8(yuv[0] - v);
- yuv += line_inc;
- }
-}
-
-static void vp56_deblock_filter(vp56_context_t *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);
-}
-
-static void vp56_mc(vp56_context_t *s, int b, uint8_t *src,
- int stride, int x, int y)
-{
- int plane = vp56_b6to3[b];
- uint8_t *dst= s->frames[VP56_FRAME_CURRENT].data[plane]+s->block_offset[b];
- uint8_t *src_block;
- int src_offset;
- int overlap_offset = 0;
- int mask = s->vp56_coord_div[b] - 1;
- int deblock_filtering = s->deblock_filtering;
- int dx;
- int dy;
-
- if (s->avctx->skip_loop_filter >= AVDISCARD_ALL ||
- (s->avctx->skip_loop_filter >= AVDISCARD_NONKEY
- && !s->frames[VP56_FRAME_CURRENT].key_frame))
- deblock_filtering = 0;
-
- dx = s->mv[b].x / s->vp56_coord_div[b];
- dy = s->mv[b].y / s->vp56_coord_div[b];
-
- if (b >= 4) {
- x /= 2;
- y /= 2;
- }
- x += dx - 2;
- y += dy - 2;
-
- if (x<0 || x+12>=s->plane_width[plane] ||
- y<0 || y+12>=s->plane_height[plane]) {
- ff_emulated_edge_mc(s->edge_emu_buffer,
- src + s->block_offset[b] + (dy-2)*stride + (dx-2),
- stride, 12, 12, x, y,
- s->plane_width[plane],
- s->plane_height[plane]);
- src_block = s->edge_emu_buffer;
- src_offset = 2 + 2*stride;
- } else if (deblock_filtering) {
- /* only need a 12x12 block, but there is no such dsp function, */
- /* so copy a 16x12 block */
- s->dsp.put_pixels_tab[0][0](s->edge_emu_buffer,
- src + s->block_offset[b] + (dy-2)*stride + (dx-2),
- stride, 12);
- src_block = s->edge_emu_buffer;
- src_offset = 2 + 2*stride;
- } else {
- src_block = src;
- src_offset = s->block_offset[b] + dy*stride + dx;
- }
-
- if (deblock_filtering)
- vp56_deblock_filter(s, src_block, stride, dx&7, dy&7);
-
- if (s->mv[b].x & mask)
- overlap_offset += (s->mv[b].x > 0) ? 1 : -1;
- if (s->mv[b].y & mask)
- overlap_offset += (s->mv[b].y > 0) ? stride : -stride;
-
- if (overlap_offset) {
- if (s->filter)
- s->filter(s, dst, src_block, src_offset, src_offset+overlap_offset,
- stride, s->mv[b], mask, s->filter_selection, b<4);
- else
- s->dsp.put_no_rnd_pixels_l2[1](dst, src_block+src_offset,
- src_block+src_offset+overlap_offset,
- stride, 8);
- } else {
- s->dsp.put_pixels_tab[1][0](dst, src_block+src_offset, stride, 8);
- }
-}
-
-static void vp56_decode_mb(vp56_context_t *s, int row, int col)
-{
- AVFrame *frame_current, *frame_ref;
- vp56_mb_t mb_type;
- vp56_frame_t ref_frame;
- int b, plan, off;
-
- if (s->frames[VP56_FRAME_CURRENT].key_frame)
- mb_type = VP56_MB_INTRA;
- else
- mb_type = vp56_decode_mv(s, row, col);
- ref_frame = vp56_reference_frame[mb_type];
-
- memset(s->block_coeff, 0, sizeof(s->block_coeff));
-
- s->parse_coeff(s);
-
- vp56_add_predictors_dc(s, ref_frame);
-
- frame_current = &s->frames[VP56_FRAME_CURRENT];
- frame_ref = &s->frames[ref_frame];
-
- switch (mb_type) {
- case VP56_MB_INTRA:
- for (b=0; b<6; b++) {
- plan = vp56_b6to3[b];
- s->dsp.idct_put(frame_current->data[plan] + s->block_offset[b],
- s->stride[plan], s->block_coeff[b]);
- }
- break;
-
- case VP56_MB_INTER_NOVEC_PF:
- case VP56_MB_INTER_NOVEC_GF:
- for (b=0; b<6; b++) {
- plan = vp56_b6to3[b];
- off = s->block_offset[b];
- s->dsp.put_pixels_tab[1][0](frame_current->data[plan] + off,
- frame_ref->data[plan] + off,
- s->stride[plan], 8);
- s->dsp.idct_add(frame_current->data[plan] + off,
- s->stride[plan], s->block_coeff[b]);
- }
- break;
-
- case VP56_MB_INTER_DELTA_PF:
- case VP56_MB_INTER_V1_PF:
- case VP56_MB_INTER_V2_PF:
- case VP56_MB_INTER_DELTA_GF:
- case VP56_MB_INTER_4V:
- case VP56_MB_INTER_V1_GF:
- case VP56_MB_INTER_V2_GF:
- for (b=0; b<6; b++) {
- int x_off = b==1 || b==3 ? 8 : 0;
- int y_off = b==2 || b==3 ? 8 : 0;
- plan = vp56_b6to3[b];
- vp56_mc(s, b, frame_ref->data[plan], s->stride[plan],
- 16*col+x_off, 16*row+y_off);
- s->dsp.idct_add(frame_current->data[plan] + s->block_offset[b],
- s->stride[plan], s->block_coeff[b]);
- }
- break;
- }
-}
-
-static int vp56_size_changed(AVCodecContext *avctx, vp56_context_t *s)
-{
- int stride = s->frames[VP56_FRAME_CURRENT].linesize[0];
- int i;
-
- s->plane_width[0] = s->avctx->coded_width;
- s->plane_width[1] = s->plane_width[2] = s->avctx->coded_width/2;
- s->plane_height[0] = s->avctx->coded_height;
- s->plane_height[1] = s->plane_height[2] = s->avctx->coded_height/2;
-
- for (i=0; i<3; i++)
- s->stride[i] = s->flip * s->frames[VP56_FRAME_CURRENT].linesize[i];
-
- s->mb_width = (s->avctx->coded_width+15) / 16;
- s->mb_height = (s->avctx->coded_height+15) / 16;
-
- if (s->mb_width > 1000 || s->mb_height > 1000) {
- av_log(avctx, AV_LOG_ERROR, "picture too big\n");
- return -1;
- }
-
- s->above_blocks = av_realloc(s->above_blocks,
- (4*s->mb_width+6) * sizeof(*s->above_blocks));
- s->macroblocks = av_realloc(s->macroblocks,
- s->mb_width*s->mb_height*sizeof(*s->macroblocks));
- av_free(s->edge_emu_buffer_alloc);
- s->edge_emu_buffer_alloc = av_malloc(16*stride);
- s->edge_emu_buffer = s->edge_emu_buffer_alloc;
- if (s->flip < 0)
- s->edge_emu_buffer += 15 * stride;
-
- return 0;
-}
-
-int vp56_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- vp56_context_t *s = avctx->priv_data;
- AVFrame *const p = &s->frames[VP56_FRAME_CURRENT];
- AVFrame *picture = data;
- int mb_row, mb_col, mb_row_flip, mb_offset = 0;
- int block, y, uv, stride_y, stride_uv;
- int golden_frame = 0;
- int res;
-
- res = s->parse_header(s, buf, buf_size, &golden_frame);
- if (!res)
- return -1;
-
- p->reference = 1;
- if (avctx->get_buffer(avctx, p) < 0) {
- av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
- return -1;
- }
-
- if (res == 2)
- if (vp56_size_changed(avctx, s)) {
- avctx->release_buffer(avctx, p);
- return -1;
- }
-
- if (p->key_frame) {
- p->pict_type = FF_I_TYPE;
- s->default_models_init(s);
- for (block=0; block<s->mb_height*s->mb_width; block++)
- s->macroblocks[block].type = VP56_MB_INTRA;
- } else {
- p->pict_type = FF_P_TYPE;
- vp56_parse_mb_type_models(s);
- s->parse_vector_models(s);
- s->mb_type = VP56_MB_INTER_NOVEC_PF;
- }
-
- s->parse_coeff_models(s);
-
- memset(s->prev_dc, 0, sizeof(s->prev_dc));
- s->prev_dc[1][VP56_FRAME_CURRENT] = 128;
- s->prev_dc[2][VP56_FRAME_CURRENT] = 128;
-
- for (block=0; block < 4*s->mb_width+6; block++) {
- s->above_blocks[block].ref_frame = -1;
- s->above_blocks[block].dc_coeff = 0;
- s->above_blocks[block].not_null_dc = 0;
- }
- s->above_blocks[2*s->mb_width + 2].ref_frame = 0;
- s->above_blocks[3*s->mb_width + 4].ref_frame = 0;
-
- stride_y = p->linesize[0];
- stride_uv = p->linesize[1];
-
- if (s->flip < 0)
- mb_offset = 7;
-
- /* main macroblocks loop */
- for (mb_row=0; mb_row<s->mb_height; mb_row++) {
- if (s->flip < 0)
- mb_row_flip = s->mb_height - mb_row - 1;
- else
- mb_row_flip = mb_row;
-
- for (block=0; block<4; block++) {
- s->left_block[block].ref_frame = -1;
- s->left_block[block].dc_coeff = 0;
- s->left_block[block].not_null_dc = 0;
- memset(s->coeff_ctx[block], 0, 64*sizeof(s->coeff_ctx[block][0]));
- }
- memset(s->coeff_ctx_last, 24, sizeof(s->coeff_ctx_last));
-
- s->above_block_idx[0] = 1;
- s->above_block_idx[1] = 2;
- s->above_block_idx[2] = 1;
- s->above_block_idx[3] = 2;
- s->above_block_idx[4] = 2*s->mb_width + 2 + 1;
- s->above_block_idx[5] = 3*s->mb_width + 4 + 1;
-
- s->block_offset[s->frbi] = (mb_row_flip*16 + mb_offset) * stride_y;
- s->block_offset[s->srbi] = s->block_offset[s->frbi] + 8*stride_y;
- s->block_offset[1] = s->block_offset[0] + 8;
- s->block_offset[3] = s->block_offset[2] + 8;
- s->block_offset[4] = (mb_row_flip*8 + mb_offset) * stride_uv;
- s->block_offset[5] = s->block_offset[4];
-
- for (mb_col=0; mb_col<s->mb_width; mb_col++) {
- vp56_decode_mb(s, mb_row, mb_col);
-
- for (y=0; y<4; y++) {
- s->above_block_idx[y] += 2;
- s->block_offset[y] += 16;
- }
-
- for (uv=4; uv<6; uv++) {
- s->above_block_idx[uv] += 1;
- s->block_offset[uv] += 8;
- }
- }
- }
-
- if (s->frames[VP56_FRAME_PREVIOUS].data[0]
- && (s->frames[VP56_FRAME_PREVIOUS].data[0]
- != s->frames[VP56_FRAME_GOLDEN].data[0])) {
- avctx->release_buffer(avctx, &s->frames[VP56_FRAME_PREVIOUS]);
- }
- if (p->key_frame || golden_frame) {
- if (s->frames[VP56_FRAME_GOLDEN].data[0])
- avctx->release_buffer(avctx, &s->frames[VP56_FRAME_GOLDEN]);
- s->frames[VP56_FRAME_GOLDEN] = *p;
- }
- s->frames[VP56_FRAME_PREVIOUS] = *p;
-
- *picture = *p;
- *data_size = sizeof(AVPicture);
-
- return buf_size;
-}
-
-void vp56_init(vp56_context_t *s, AVCodecContext *avctx, int flip)
-{
- int i;
-
- s->avctx = avctx;
- avctx->pix_fmt = PIX_FMT_YUV420P;
-
- if (s->avctx->idct_algo == FF_IDCT_AUTO)
- s->avctx->idct_algo = FF_IDCT_VP3;
- dsputil_init(&s->dsp, s->avctx);
- ff_init_scantable(s->dsp.idct_permutation, &s->scantable,ff_zigzag_direct);
-
- avcodec_set_dimensions(s->avctx, 0, 0);
-
- for (i=0; i<3; i++)
- s->frames[i].data[0] = NULL;
- s->edge_emu_buffer_alloc = NULL;
-
- s->above_blocks = NULL;
- s->macroblocks = NULL;
- s->quantizer = -1;
- s->deblock_filtering = 1;
-
- s->filter = NULL;
-
- if (flip) {
- s->flip = -1;
- s->frbi = 2;
- s->srbi = 0;
- } else {
- s->flip = 1;
- s->frbi = 0;
- s->srbi = 2;
- }
-}
-
-int vp56_free(AVCodecContext *avctx)
-{
- vp56_context_t *s = avctx->priv_data;
-
- av_free(s->above_blocks);
- av_free(s->macroblocks);
- av_free(s->edge_emu_buffer_alloc);
- if (s->frames[VP56_FRAME_GOLDEN].data[0]
- && (s->frames[VP56_FRAME_PREVIOUS].data[0]
- != s->frames[VP56_FRAME_GOLDEN].data[0]))
- avctx->release_buffer(avctx, &s->frames[VP56_FRAME_GOLDEN]);
- if (s->frames[VP56_FRAME_PREVIOUS].data[0])
- avctx->release_buffer(avctx, &s->frames[VP56_FRAME_PREVIOUS]);
- return 0;
-}
diff --git a/src/libffmpeg/libavcodec/vp56.h b/src/libffmpeg/libavcodec/vp56.h
deleted file mode 100644
index 50e201550..000000000
--- a/src/libffmpeg/libavcodec/vp56.h
+++ /dev/null
@@ -1,252 +0,0 @@
-/**
- * @file vp56.h
- * VP5 and VP6 compatible video decoder (common features)
- *
- * Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef VP56_H
-#define VP56_H
-
-#include "vp56data.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-
-
-typedef struct vp56_context vp56_context_t;
-typedef struct vp56_mv vp56_mv_t;
-
-typedef void (*vp56_parse_vector_adjustment_t)(vp56_context_t *s,
- vp56_mv_t *vect);
-typedef int (*vp56_adjust_t)(int v, int t);
-typedef void (*vp56_filter_t)(vp56_context_t *s, uint8_t *dst, uint8_t *src,
- int offset1, int offset2, int stride,
- vp56_mv_t mv, int mask, int select, int luma);
-typedef void (*vp56_parse_coeff_t)(vp56_context_t *s);
-typedef void (*vp56_default_models_init_t)(vp56_context_t *s);
-typedef void (*vp56_parse_vector_models_t)(vp56_context_t *s);
-typedef void (*vp56_parse_coeff_models_t)(vp56_context_t *s);
-typedef int (*vp56_parse_header_t)(vp56_context_t *s, uint8_t *buf,
- int buf_size, int *golden_frame);
-
-typedef struct {
- int high;
- int bits;
- const uint8_t *buffer;
- unsigned long code_word;
-} vp56_range_coder_t;
-
-typedef struct {
- uint8_t not_null_dc;
- vp56_frame_t ref_frame;
- DCTELEM dc_coeff;
-} vp56_ref_dc_t;
-
-struct vp56_mv {
- int x;
- int y;
-};
-
-typedef struct {
- uint8_t type;
- vp56_mv_t mv;
-} vp56_macroblock_t;
-
-struct vp56_context {
- AVCodecContext *avctx;
- DSPContext dsp;
- ScanTable scantable;
- AVFrame frames[3];
- uint8_t *edge_emu_buffer_alloc;
- uint8_t *edge_emu_buffer;
- vp56_range_coder_t c;
- vp56_range_coder_t cc;
- vp56_range_coder_t *ccp;
- int sub_version;
-
- /* frame info */
- int plane_width[3];
- int plane_height[3];
- int mb_width; /* number of horizontal MB */
- int mb_height; /* number of vertical MB */
- int block_offset[6];
-
- int quantizer;
- uint16_t dequant_dc;
- uint16_t dequant_ac;
-
- /* DC predictors management */
- vp56_ref_dc_t *above_blocks;
- vp56_ref_dc_t left_block[4];
- int above_block_idx[6];
- DCTELEM prev_dc[3][3]; /* [plan][ref_frame] */
-
- /* blocks / macroblock */
- vp56_mb_t mb_type;
- vp56_macroblock_t *macroblocks;
- DECLARE_ALIGNED_16(DCTELEM, block_coeff[6][64]);
- uint8_t coeff_reorder[64]; /* used in vp6 only */
- uint8_t coeff_index_to_pos[64]; /* used in vp6 only */
-
- /* motion vectors */
- vp56_mv_t mv[6]; /* vectors for each block in MB */
- vp56_mv_t vector_candidate[2];
- int vector_candidate_pos;
-
- /* filtering hints */
- int filter_header; /* used in vp6 only */
- int deblock_filtering;
- int filter_selection;
- int filter_mode;
- int max_vector_length;
- int sample_variance_threshold;
-
- /* AC models */
- uint8_t vector_model_sig[2]; /* delta sign */
- uint8_t vector_model_dct[2]; /* delta coding types */
- uint8_t vector_model_pdi[2][2]; /* predefined delta init */
- uint8_t vector_model_pdv[2][7]; /* predefined delta values */
- uint8_t vector_model_fdv[2][8]; /* 8 bit delta value definition */
- uint8_t mb_type_model[3][10][10]; /* model for decoding MB type */
- uint8_t coeff_model_dccv[2][11]; /* DC coeff value */
- uint8_t coeff_model_ract[2][3][6][11]; /* Run/AC coding type and AC coeff value */
- uint8_t coeff_model_acct[2][3][3][6][5];/* vp5 only AC coding type for coding group < 3 */
- uint8_t coeff_model_dcct[2][36][5]; /* DC coeff coding type */
- uint8_t coeff_model_runv[2][14]; /* run value (vp6 only) */
- uint8_t mb_types_stats[3][10][2]; /* contextual, next MB type stats */
- uint8_t coeff_ctx[4][64]; /* used in vp5 only */
- uint8_t coeff_ctx_last[4]; /* used in vp5 only */
-
- /* upside-down flipping hints */
- int flip; /* are we flipping ? */
- int frbi; /* first row block index in MB */
- int srbi; /* second row block index in MB */
- int stride[3]; /* stride for each plan */
-
- const uint8_t *vp56_coord_div;
- vp56_parse_vector_adjustment_t parse_vector_adjustment;
- vp56_adjust_t adjust;
- vp56_filter_t filter;
- vp56_parse_coeff_t parse_coeff;
- vp56_default_models_init_t default_models_init;
- vp56_parse_vector_models_t parse_vector_models;
- vp56_parse_coeff_models_t parse_coeff_models;
- vp56_parse_header_t parse_header;
-};
-
-
-void vp56_init(vp56_context_t *s, AVCodecContext *avctx, int flip);
-int vp56_free(AVCodecContext *avctx);
-void vp56_init_dequant(vp56_context_t *s, int quantizer);
-int vp56_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
- uint8_t *buf, int buf_size);
-
-
-/**
- * vp56 specific range coder implementation
- */
-
-static inline void vp56_init_range_decoder(vp56_range_coder_t *c,
- const uint8_t *buf, int buf_size)
-{
- c->high = 255;
- c->bits = 8;
- c->buffer = buf;
- c->code_word = *c->buffer++ << 8;
- c->code_word |= *c->buffer++;
-}
-
-static inline int vp56_rac_get_prob(vp56_range_coder_t *c, uint8_t prob)
-{
- unsigned int low = 1 + (((c->high - 1) * prob) / 256);
- unsigned int low_shift = low << 8;
- int bit = c->code_word >= low_shift;
-
- if (bit) {
- c->high -= low;
- c->code_word -= low_shift;
- } else {
- c->high = low;
- }
-
- /* normalize */
- while (c->high < 128) {
- c->high <<= 1;
- c->code_word <<= 1;
- if (--c->bits == 0) {
- c->bits = 8;
- c->code_word |= *c->buffer++;
- }
- }
- return bit;
-}
-
-static inline int vp56_rac_get(vp56_range_coder_t *c)
-{
- /* equiprobable */
- int low = (c->high + 1) >> 1;
- unsigned int low_shift = low << 8;
- int bit = c->code_word >= low_shift;
- if (bit) {
- c->high = (c->high - low) << 1;
- c->code_word -= low_shift;
- } else {
- c->high = low << 1;
- }
-
- /* normalize */
- c->code_word <<= 1;
- if (--c->bits == 0) {
- c->bits = 8;
- c->code_word |= *c->buffer++;
- }
- return bit;
-}
-
-static inline int vp56_rac_gets(vp56_range_coder_t *c, int bits)
-{
- int value = 0;
-
- while (bits--) {
- value = (value << 1) | vp56_rac_get(c);
- }
-
- return value;
-}
-
-static inline int vp56_rac_gets_nn(vp56_range_coder_t *c, int bits)
-{
- int v = vp56_rac_gets(c, 7) << 1;
- return v + !v;
-}
-
-static inline int vp56_rac_get_tree(vp56_range_coder_t *c,
- const vp56_tree_t *tree,
- const uint8_t *probs)
-{
- while (tree->val > 0) {
- if (vp56_rac_get_prob(c, probs[tree->prob_idx]))
- tree += tree->val;
- else
- tree++;
- }
- return -tree->val;
-}
-
-#endif /* VP56_H */
diff --git a/src/libffmpeg/libavcodec/vp56data.h b/src/libffmpeg/libavcodec/vp56data.h
deleted file mode 100644
index dbf92dd68..000000000
--- a/src/libffmpeg/libavcodec/vp56data.h
+++ /dev/null
@@ -1,248 +0,0 @@
-/**
- * @file vp56data.h
- * VP5 and VP6 compatible video decoder (common data)
- *
- * Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef VP56DATA_H
-#define VP56DATA_H
-
-#include "common.h"
-
-typedef enum {
- VP56_FRAME_CURRENT = 0,
- VP56_FRAME_PREVIOUS = 1,
- VP56_FRAME_GOLDEN = 2,
-} vp56_frame_t;
-
-typedef enum {
- VP56_MB_INTER_NOVEC_PF = 0, /**< Inter MB, no vector, from previous frame */
- VP56_MB_INTRA = 1, /**< Intra MB */
- VP56_MB_INTER_DELTA_PF = 2, /**< Inter MB, above/left vector + delta, from previous frame */
- VP56_MB_INTER_V1_PF = 3, /**< Inter MB, first vector, from previous frame */
- VP56_MB_INTER_V2_PF = 4, /**< Inter MB, second vector, from previous frame */
- VP56_MB_INTER_NOVEC_GF = 5, /**< Inter MB, no vector, from golden frame */
- VP56_MB_INTER_DELTA_GF = 6, /**< Inter MB, above/left vector + delta, from golden frame */
- VP56_MB_INTER_4V = 7, /**< Inter MB, 4 vectors, from previous frame */
- VP56_MB_INTER_V1_GF = 8, /**< Inter MB, first vector, from golden frame */
- VP56_MB_INTER_V2_GF = 9, /**< Inter MB, second vector, from golden frame */
-} vp56_mb_t;
-
-typedef struct {
- int8_t val;
- int8_t prob_idx;
-} vp56_tree_t;
-
-extern const uint8_t vp56_b6to3[];
-extern const uint8_t vp56_b6to4[];
-extern const uint8_t vp56_coeff_parse_table[6][11];
-extern const uint8_t vp56_def_mb_types_stats[3][10][2];
-extern const vp56_tree_t vp56_pva_tree[];
-extern const vp56_tree_t vp56_pc_tree[];
-extern const uint8_t vp56_coeff_bias[];
-extern const uint8_t vp56_coeff_bit_length[];
-
-static const vp56_frame_t vp56_reference_frame[] = {
- VP56_FRAME_PREVIOUS, /* VP56_MB_INTER_NOVEC_PF */
- VP56_FRAME_CURRENT, /* VP56_MB_INTRA */
- VP56_FRAME_PREVIOUS, /* VP56_MB_INTER_DELTA_PF */
- VP56_FRAME_PREVIOUS, /* VP56_MB_INTER_V1_PF */
- VP56_FRAME_PREVIOUS, /* VP56_MB_INTER_V2_PF */
- VP56_FRAME_GOLDEN, /* VP56_MB_INTER_NOVEC_GF */
- VP56_FRAME_GOLDEN, /* VP56_MB_INTER_DELTA_GF */
- VP56_FRAME_PREVIOUS, /* VP56_MB_INTER_4V */
- VP56_FRAME_GOLDEN, /* VP56_MB_INTER_V1_GF */
- VP56_FRAME_GOLDEN, /* VP56_MB_INTER_V2_GF */
-};
-
-static const uint8_t vp56_ac_dequant[64] = {
- 94, 92, 90, 88, 86, 82, 78, 74,
- 70, 66, 62, 58, 54, 53, 52, 51,
- 50, 49, 48, 47, 46, 45, 44, 43,
- 42, 40, 39, 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,
-};
-
-static const uint8_t vp56_dc_dequant[64] = {
- 47, 47, 47, 47, 45, 43, 43, 43,
- 43, 43, 42, 41, 41, 40, 40, 40,
- 40, 35, 35, 35, 35, 33, 33, 33,
- 33, 32, 32, 32, 27, 27, 26, 26,
- 25, 25, 24, 24, 23, 23, 19, 19,
- 19, 19, 18, 18, 17, 16, 16, 16,
- 16, 16, 15, 11, 11, 11, 10, 10,
- 9, 8, 7, 5, 3, 3, 2, 2,
-};
-
-static const uint8_t vp56_pre_def_mb_type_stats[16][3][10][2] = {
- { { { 9, 15 }, { 32, 25 }, { 7, 19 }, { 9, 21 }, { 1, 12 },
- { 14, 12 }, { 3, 18 }, { 14, 23 }, { 3, 10 }, { 0, 4 }, },
- { { 41, 22 }, { 1, 0 }, { 1, 31 }, { 0, 0 }, { 0, 0 },
- { 0, 1 }, { 1, 7 }, { 0, 1 }, { 98, 25 }, { 4, 10 }, },
- { { 2, 3 }, { 2, 3 }, { 0, 2 }, { 0, 2 }, { 0, 0 },
- { 11, 4 }, { 1, 4 }, { 0, 2 }, { 3, 2 }, { 0, 4 }, }, },
- { { { 48, 39 }, { 1, 2 }, { 11, 27 }, { 29, 44 }, { 7, 27 },
- { 1, 4 }, { 0, 3 }, { 1, 6 }, { 1, 2 }, { 0, 0 }, },
- { { 123, 37 }, { 6, 4 }, { 1, 27 }, { 0, 0 }, { 0, 0 },
- { 5, 8 }, { 1, 7 }, { 0, 1 }, { 12, 10 }, { 0, 2 }, },
- { { 49, 46 }, { 3, 4 }, { 7, 31 }, { 42, 41 }, { 0, 0 },
- { 2, 6 }, { 1, 7 }, { 1, 4 }, { 2, 4 }, { 0, 1 }, }, },
- { { { 21, 32 }, { 1, 2 }, { 4, 10 }, { 32, 43 }, { 6, 23 },
- { 2, 3 }, { 1, 19 }, { 1, 6 }, { 12, 21 }, { 0, 7 }, },
- { { 26, 14 }, { 14, 12 }, { 0, 24 }, { 0, 0 }, { 0, 0 },
- { 55, 17 }, { 1, 9 }, { 0, 36 }, { 5, 7 }, { 1, 3 }, },
- { { 26, 25 }, { 1, 1 }, { 2, 10 }, { 67, 39 }, { 0, 0 },
- { 1, 1 }, { 0, 14 }, { 0, 2 }, { 31, 26 }, { 1, 6 }, }, },
- { { { 69, 83 }, { 0, 0 }, { 0, 2 }, { 10, 29 }, { 3, 12 },
- { 0, 1 }, { 0, 3 }, { 0, 3 }, { 2, 2 }, { 0, 0 }, },
- { { 209, 5 }, { 0, 0 }, { 0, 27 }, { 0, 0 }, { 0, 0 },
- { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 0 }, { 0, 0 }, },
- { { 103, 46 }, { 1, 2 }, { 2, 10 }, { 33, 42 }, { 0, 0 },
- { 1, 4 }, { 0, 3 }, { 0, 1 }, { 1, 3 }, { 0, 0 }, }, },
- { { { 11, 20 }, { 1, 4 }, { 18, 36 }, { 43, 48 }, { 13, 35 },
- { 0, 2 }, { 0, 5 }, { 3, 12 }, { 1, 2 }, { 0, 0 }, },
- { { 2, 5 }, { 4, 5 }, { 0, 121 }, { 0, 0 }, { 0, 0 },
- { 0, 3 }, { 2, 4 }, { 1, 4 }, { 2, 2 }, { 0, 1 }, },
- { { 14, 31 }, { 9, 13 }, { 14, 54 }, { 22, 29 }, { 0, 0 },
- { 2, 6 }, { 4, 18 }, { 6, 13 }, { 1, 5 }, { 0, 1 }, }, },
- { { { 70, 44 }, { 0, 1 }, { 2, 10 }, { 37, 46 }, { 8, 26 },
- { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 1 }, { 0, 0 }, },
- { { 175, 5 }, { 0, 1 }, { 0, 48 }, { 0, 0 }, { 0, 0 },
- { 0, 2 }, { 0, 1 }, { 0, 2 }, { 0, 1 }, { 0, 0 }, },
- { { 85, 39 }, { 0, 0 }, { 1, 9 }, { 69, 40 }, { 0, 0 },
- { 0, 1 }, { 0, 3 }, { 0, 1 }, { 2, 3 }, { 0, 0 }, }, },
- { { { 8, 15 }, { 0, 1 }, { 8, 21 }, { 74, 53 }, { 22, 42 },
- { 0, 1 }, { 0, 2 }, { 0, 3 }, { 1, 2 }, { 0, 0 }, },
- { { 83, 5 }, { 2, 3 }, { 0, 102 }, { 0, 0 }, { 0, 0 },
- { 1, 3 }, { 0, 2 }, { 0, 1 }, { 0, 0 }, { 0, 0 }, },
- { { 31, 28 }, { 0, 0 }, { 3, 14 }, { 130, 34 }, { 0, 0 },
- { 0, 1 }, { 0, 3 }, { 0, 1 }, { 3, 3 }, { 0, 1 }, }, },
- { { { 141, 42 }, { 0, 0 }, { 1, 4 }, { 11, 24 }, { 1, 11 },
- { 0, 1 }, { 0, 1 }, { 0, 2 }, { 0, 0 }, { 0, 0 }, },
- { { 233, 6 }, { 0, 0 }, { 0, 8 }, { 0, 0 }, { 0, 0 },
- { 0, 1 }, { 0, 1 }, { 0, 0 }, { 0, 1 }, { 0, 0 }, },
- { { 171, 25 }, { 0, 0 }, { 1, 5 }, { 25, 21 }, { 0, 0 },
- { 0, 1 }, { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, }, },
- { { { 8, 19 }, { 4, 10 }, { 24, 45 }, { 21, 37 }, { 9, 29 },
- { 0, 3 }, { 1, 7 }, { 11, 25 }, { 0, 2 }, { 0, 1 }, },
- { { 34, 16 }, { 112, 21 }, { 1, 28 }, { 0, 0 }, { 0, 0 },
- { 6, 8 }, { 1, 7 }, { 0, 3 }, { 2, 5 }, { 0, 2 }, },
- { { 17, 21 }, { 68, 29 }, { 6, 15 }, { 13, 22 }, { 0, 0 },
- { 6, 12 }, { 3, 14 }, { 4, 10 }, { 1, 7 }, { 0, 3 }, }, },
- { { { 46, 42 }, { 0, 1 }, { 2, 10 }, { 54, 51 }, { 10, 30 },
- { 0, 2 }, { 0, 2 }, { 0, 1 }, { 0, 1 }, { 0, 0 }, },
- { { 159, 35 }, { 2, 2 }, { 0, 25 }, { 0, 0 }, { 0, 0 },
- { 3, 6 }, { 0, 5 }, { 0, 1 }, { 4, 4 }, { 0, 1 }, },
- { { 51, 39 }, { 0, 1 }, { 2, 12 }, { 91, 44 }, { 0, 0 },
- { 0, 2 }, { 0, 3 }, { 0, 1 }, { 2, 3 }, { 0, 1 }, }, },
- { { { 28, 32 }, { 0, 0 }, { 3, 10 }, { 75, 51 }, { 14, 33 },
- { 0, 1 }, { 0, 2 }, { 0, 1 }, { 1, 2 }, { 0, 0 }, },
- { { 75, 39 }, { 5, 7 }, { 2, 48 }, { 0, 0 }, { 0, 0 },
- { 3, 11 }, { 2, 16 }, { 1, 4 }, { 7, 10 }, { 0, 2 }, },
- { { 81, 25 }, { 0, 0 }, { 2, 9 }, { 106, 26 }, { 0, 0 },
- { 0, 1 }, { 0, 1 }, { 0, 1 }, { 1, 1 }, { 0, 0 }, }, },
- { { { 100, 46 }, { 0, 1 }, { 3, 9 }, { 21, 37 }, { 5, 20 },
- { 0, 1 }, { 0, 2 }, { 1, 2 }, { 0, 1 }, { 0, 0 }, },
- { { 212, 21 }, { 0, 1 }, { 0, 9 }, { 0, 0 }, { 0, 0 },
- { 1, 2 }, { 0, 2 }, { 0, 0 }, { 2, 2 }, { 0, 0 }, },
- { { 140, 37 }, { 0, 1 }, { 1, 8 }, { 24, 33 }, { 0, 0 },
- { 1, 2 }, { 0, 2 }, { 0, 1 }, { 1, 2 }, { 0, 0 }, }, },
- { { { 27, 29 }, { 0, 1 }, { 9, 25 }, { 53, 51 }, { 12, 34 },
- { 0, 1 }, { 0, 3 }, { 1, 5 }, { 0, 2 }, { 0, 0 }, },
- { { 4, 2 }, { 0, 0 }, { 0, 172 }, { 0, 0 }, { 0, 0 },
- { 0, 1 }, { 0, 2 }, { 0, 0 }, { 2, 0 }, { 0, 0 }, },
- { { 14, 23 }, { 1, 3 }, { 11, 53 }, { 90, 31 }, { 0, 0 },
- { 0, 3 }, { 1, 5 }, { 2, 6 }, { 1, 2 }, { 0, 0 }, }, },
- { { { 80, 38 }, { 0, 0 }, { 1, 4 }, { 69, 33 }, { 5, 16 },
- { 0, 1 }, { 0, 1 }, { 0, 0 }, { 0, 1 }, { 0, 0 }, },
- { { 187, 22 }, { 1, 1 }, { 0, 17 }, { 0, 0 }, { 0, 0 },
- { 3, 6 }, { 0, 4 }, { 0, 1 }, { 4, 4 }, { 0, 1 }, },
- { { 123, 29 }, { 0, 0 }, { 1, 7 }, { 57, 30 }, { 0, 0 },
- { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 0 }, }, },
- { { { 16, 20 }, { 0, 0 }, { 2, 8 }, { 104, 49 }, { 15, 33 },
- { 0, 1 }, { 0, 1 }, { 0, 1 }, { 1, 1 }, { 0, 0 }, },
- { { 133, 6 }, { 1, 2 }, { 1, 70 }, { 0, 0 }, { 0, 0 },
- { 0, 2 }, { 0, 4 }, { 0, 3 }, { 1, 1 }, { 0, 0 }, },
- { { 13, 14 }, { 0, 0 }, { 4, 20 }, { 175, 20 }, { 0, 0 },
- { 0, 1 }, { 0, 1 }, { 0, 1 }, { 1, 1 }, { 0, 0 }, }, },
- { { { 194, 16 }, { 0, 0 }, { 1, 1 }, { 1, 9 }, { 1, 3 },
- { 0, 0 }, { 0, 1 }, { 0, 1 }, { 0, 0 }, { 0, 0 }, },
- { { 251, 1 }, { 0, 0 }, { 0, 2 }, { 0, 0 }, { 0, 0 },
- { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, },
- { { 202, 23 }, { 0, 0 }, { 1, 3 }, { 2, 9 }, { 0, 0 },
- { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 0 }, { 0, 0 }, }, },
-};
-
-static const uint8_t vp56_filter_threshold[] = {
- 14, 14, 13, 13, 12, 12, 10, 10,
- 10, 10, 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, 7, 7, 7, 7,
- 7, 7, 6, 6, 6, 6, 6, 6,
- 5, 5, 5, 5, 4, 4, 4, 4,
- 4, 4, 4, 3, 3, 3, 3, 2,
-};
-
-static const uint8_t vp56_mb_type_model_model[] = {
- 171, 83, 199, 140, 125, 104,
-};
-
-static const vp56_tree_t vp56_pmbtm_tree[] = {
- { 4, 0},
- { 2, 1}, {-8}, {-4},
- { 8, 2},
- { 6, 3},
- { 4, 4},
- { 2, 5}, {-24}, {-20}, {-16}, {-12}, {-0},
-};
-
-static const vp56_tree_t vp56_pmbt_tree[] = {
- { 8, 1},
- { 4, 2},
- { 2, 4}, {-VP56_MB_INTER_NOVEC_PF}, {-VP56_MB_INTER_DELTA_PF},
- { 2, 5}, {-VP56_MB_INTER_V1_PF}, {-VP56_MB_INTER_V2_PF},
- { 4, 3},
- { 2, 6}, {-VP56_MB_INTRA}, {-VP56_MB_INTER_4V},
- { 4, 7},
- { 2, 8}, {-VP56_MB_INTER_NOVEC_GF}, {-VP56_MB_INTER_DELTA_GF},
- { 2, 9}, {-VP56_MB_INTER_V1_GF}, {-VP56_MB_INTER_V2_GF},
-};
-
-/* relative pos of surrounding blocks, from closest to farthest */
-static const int8_t vp56_candidate_predictor_pos[12][2] = {
- { 0, -1 },
- { -1, 0 },
- { -1, -1 },
- { 1, -1 },
- { 0, -2 },
- { -2, 0 },
- { -2, -1 },
- { -1, -2 },
- { 1, -2 },
- { 2, -1 },
- { -2, -2 },
- { 2, -2 },
-};
-
-#endif /* VP56DATA */
diff --git a/src/libffmpeg/libavcodec/vp6.c b/src/libffmpeg/libavcodec/vp6.c
deleted file mode 100644
index df4ebf87d..000000000
--- a/src/libffmpeg/libavcodec/vp6.c
+++ /dev/null
@@ -1,556 +0,0 @@
-/**
- * @file vp6.c
- * VP6 compatible video decoder
- *
- * Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- *
- * The VP6F decoder accept an optional 1 byte extradata. It is composed of:
- * - upper 4bits: difference between encoded width and visible width
- * - lower 4bits: difference between encoded height and visible height
- */
-
-#include <stdlib.h>
-
-#include "avcodec.h"
-#include "dsputil.h"
-#include "bitstream.h"
-#include "mpegvideo.h"
-
-#include "vp56.h"
-#include "vp56data.h"
-#include "vp6data.h"
-
-
-static int vp6_parse_header(vp56_context_t *s, uint8_t *buf, int buf_size,
- int *golden_frame)
-{
- vp56_range_coder_t *c = &s->c;
- int parse_filter_info = 0;
- int coeff_offset = 0;
- int vrt_shift = 0;
- int sub_version;
- int rows, cols;
- int res = 1;
- int separated_coeff = buf[0] & 1;
-
- s->frames[VP56_FRAME_CURRENT].key_frame = !(buf[0] & 0x80);
- vp56_init_dequant(s, (buf[0] >> 1) & 0x3F);
-
- if (s->frames[VP56_FRAME_CURRENT].key_frame) {
- sub_version = buf[1] >> 3;
- if (sub_version > 8)
- return 0;
- s->filter_header = buf[1] & 0x06;
- if (buf[1] & 1) {
- av_log(s->avctx, AV_LOG_ERROR, "interlacing not supported\n");
- return 0;
- }
- if (separated_coeff || !s->filter_header) {
- coeff_offset = AV_RB16(buf+2) - 2;
- buf += 2;
- buf_size -= 2;
- }
-
- rows = buf[2]; /* number of stored macroblock rows */
- cols = buf[3]; /* number of stored macroblock cols */
- /* buf[4] is number of displayed macroblock rows */
- /* buf[5] is number of displayed macroblock cols */
-
- if (16*cols != s->avctx->coded_width ||
- 16*rows != s->avctx->coded_height) {
- avcodec_set_dimensions(s->avctx, 16*cols, 16*rows);
- if (s->avctx->extradata_size == 1) {
- s->avctx->width -= s->avctx->extradata[0] >> 4;
- s->avctx->height -= s->avctx->extradata[0] & 0x0F;
- }
- res = 2;
- }
-
- vp56_init_range_decoder(c, buf+6, buf_size-6);
- vp56_rac_gets(c, 2);
-
- parse_filter_info = s->filter_header;
- if (sub_version < 8)
- vrt_shift = 5;
- s->sub_version = sub_version;
- } else {
- if (!s->sub_version)
- return 0;
-
- if (separated_coeff || !s->filter_header) {
- coeff_offset = AV_RB16(buf+1) - 2;
- buf += 2;
- buf_size -= 2;
- }
- vp56_init_range_decoder(c, buf+1, buf_size-1);
-
- *golden_frame = vp56_rac_get(c);
- if (s->filter_header) {
- s->deblock_filtering = vp56_rac_get(c);
- if (s->deblock_filtering)
- vp56_rac_get(c);
- if (s->sub_version > 7)
- parse_filter_info = vp56_rac_get(c);
- }
- }
-
- if (parse_filter_info) {
- if (vp56_rac_get(c)) {
- s->filter_mode = 2;
- s->sample_variance_threshold = vp56_rac_gets(c, 5) << vrt_shift;
- s->max_vector_length = 2 << vp56_rac_gets(c, 3);
- } else if (vp56_rac_get(c)) {
- s->filter_mode = 1;
- } else {
- s->filter_mode = 0;
- }
- if (s->sub_version > 7)
- s->filter_selection = vp56_rac_gets(c, 4);
- else
- s->filter_selection = 16;
- }
-
- vp56_rac_get(c);
-
- if (coeff_offset) {
- vp56_init_range_decoder(&s->cc, buf+coeff_offset,
- buf_size-coeff_offset);
- s->ccp = &s->cc;
- } else {
- s->ccp = &s->c;
- }
-
- return res;
-}
-
-static void vp6_coeff_order_table_init(vp56_context_t *s)
-{
- int i, pos, idx = 1;
-
- s->coeff_index_to_pos[0] = 0;
- for (i=0; i<16; i++)
- for (pos=1; pos<64; pos++)
- if (s->coeff_reorder[pos] == i)
- s->coeff_index_to_pos[idx++] = pos;
-}
-
-static void vp6_default_models_init(vp56_context_t *s)
-{
- s->vector_model_dct[0] = 0xA2;
- s->vector_model_dct[1] = 0xA4;
- s->vector_model_sig[0] = 0x80;
- s->vector_model_sig[1] = 0x80;
-
- memcpy(s->mb_types_stats, vp56_def_mb_types_stats, sizeof(s->mb_types_stats));
- memcpy(s->vector_model_fdv, vp6_def_fdv_vector_model, sizeof(s->vector_model_fdv));
- memcpy(s->vector_model_pdv, vp6_def_pdv_vector_model, sizeof(s->vector_model_pdv));
- memcpy(s->coeff_model_runv, vp6_def_runv_coeff_model, sizeof(s->coeff_model_runv));
- memcpy(s->coeff_reorder, vp6_def_coeff_reorder, sizeof(s->coeff_reorder));
-
- vp6_coeff_order_table_init(s);
-}
-
-static void vp6_parse_vector_models(vp56_context_t *s)
-{
- vp56_range_coder_t *c = &s->c;
- int comp, node;
-
- for (comp=0; comp<2; comp++) {
- if (vp56_rac_get_prob(c, vp6_sig_dct_pct[comp][0]))
- s->vector_model_dct[comp] = vp56_rac_gets_nn(c, 7);
- if (vp56_rac_get_prob(c, vp6_sig_dct_pct[comp][1]))
- s->vector_model_sig[comp] = vp56_rac_gets_nn(c, 7);
- }
-
- for (comp=0; comp<2; comp++)
- for (node=0; node<7; node++)
- if (vp56_rac_get_prob(c, vp6_pdv_pct[comp][node]))
- s->vector_model_pdv[comp][node] = vp56_rac_gets_nn(c, 7);
-
- for (comp=0; comp<2; comp++)
- for (node=0; node<8; node++)
- if (vp56_rac_get_prob(c, vp6_fdv_pct[comp][node]))
- s->vector_model_fdv[comp][node] = vp56_rac_gets_nn(c, 7);
-}
-
-static void vp6_parse_coeff_models(vp56_context_t *s)
-{
- vp56_range_coder_t *c = &s->c;
- int def_prob[11];
- int node, cg, ctx, pos;
- int ct; /* code type */
- int pt; /* plane type (0 for Y, 1 for U or V) */
-
- memset(def_prob, 0x80, sizeof(def_prob));
-
- for (pt=0; pt<2; pt++)
- for (node=0; node<11; node++)
- if (vp56_rac_get_prob(c, vp6_dccv_pct[pt][node])) {
- def_prob[node] = vp56_rac_gets_nn(c, 7);
- s->coeff_model_dccv[pt][node] = def_prob[node];
- } else if (s->frames[VP56_FRAME_CURRENT].key_frame) {
- s->coeff_model_dccv[pt][node] = def_prob[node];
- }
-
- if (vp56_rac_get(c)) {
- for (pos=1; pos<64; pos++)
- if (vp56_rac_get_prob(c, vp6_coeff_reorder_pct[pos]))
- s->coeff_reorder[pos] = vp56_rac_gets(c, 4);
- vp6_coeff_order_table_init(s);
- }
-
- for (cg=0; cg<2; cg++)
- for (node=0; node<14; node++)
- if (vp56_rac_get_prob(c, vp6_runv_pct[cg][node]))
- s->coeff_model_runv[cg][node] = vp56_rac_gets_nn(c, 7);
-
- for (ct=0; ct<3; ct++)
- for (pt=0; pt<2; pt++)
- for (cg=0; cg<6; cg++)
- for (node=0; node<11; node++)
- if (vp56_rac_get_prob(c, vp6_ract_pct[ct][pt][cg][node])) {
- def_prob[node] = vp56_rac_gets_nn(c, 7);
- s->coeff_model_ract[pt][ct][cg][node] = def_prob[node];
- } else if (s->frames[VP56_FRAME_CURRENT].key_frame) {
- s->coeff_model_ract[pt][ct][cg][node] = def_prob[node];
- }
-
- /* coeff_model_dcct is a linear combination of coeff_model_dccv */
- for (pt=0; pt<2; pt++)
- for (ctx=0; ctx<3; ctx++)
- for (node=0; node<5; node++)
- s->coeff_model_dcct[pt][ctx][node] = clip(((s->coeff_model_dccv[pt][node] * vp6_dccv_lc[ctx][node][0] + 128) >> 8) + vp6_dccv_lc[ctx][node][1], 1, 255);
-}
-
-static void vp6_parse_vector_adjustment(vp56_context_t *s, vp56_mv_t *vect)
-{
- vp56_range_coder_t *c = &s->c;
- int comp;
-
- *vect = (vp56_mv_t) {0,0};
- if (s->vector_candidate_pos < 2)
- *vect = s->vector_candidate[0];
-
- for (comp=0; comp<2; comp++) {
- int i, delta = 0;
-
- if (vp56_rac_get_prob(c, s->vector_model_dct[comp])) {
- static const uint8_t prob_order[] = {0, 1, 2, 7, 6, 5, 4};
- for (i=0; i<sizeof(prob_order); i++) {
- int j = prob_order[i];
- delta |= vp56_rac_get_prob(c, s->vector_model_fdv[comp][j])<<j;
- }
- if (delta & 0xF0)
- delta |= vp56_rac_get_prob(c, s->vector_model_fdv[comp][3])<<3;
- else
- delta |= 8;
- } else {
- delta = vp56_rac_get_tree(c, vp56_pva_tree,
- s->vector_model_pdv[comp]);
- }
-
- if (delta && vp56_rac_get_prob(c, s->vector_model_sig[comp]))
- delta = -delta;
-
- if (!comp)
- vect->x += delta;
- else
- vect->y += delta;
- }
-}
-
-static void vp6_parse_coeff(vp56_context_t *s)
-{
- vp56_range_coder_t *c = s->ccp;
- uint8_t *permute = s->scantable.permutated;
- uint8_t *model, *model2, *model3;
- int coeff, sign, coeff_idx;
- int b, i, cg, idx, ctx;
- int pt = 0; /* plane type (0 for Y, 1 for U or V) */
-
- for (b=0; b<6; b++) {
- int ct = 1; /* code type */
- int run = 1;
-
- if (b > 3) pt = 1;
-
- ctx = s->left_block[vp56_b6to4[b]].not_null_dc
- + s->above_blocks[s->above_block_idx[b]].not_null_dc;
- model = s->coeff_model_dccv[pt];
- model2 = s->coeff_model_dcct[pt][ctx];
-
- for (coeff_idx=0; coeff_idx<64; ) {
- if ((coeff_idx>1 && ct==0) || vp56_rac_get_prob(c, model2[0])) {
- /* parse a coeff */
- if (coeff_idx == 0) {
- s->left_block[vp56_b6to4[b]].not_null_dc = 1;
- s->above_blocks[s->above_block_idx[b]].not_null_dc = 1;
- }
-
- if (vp56_rac_get_prob(c, model2[2])) {
- if (vp56_rac_get_prob(c, model2[3])) {
- idx = vp56_rac_get_tree(c, vp56_pc_tree, model);
- coeff = vp56_coeff_bias[idx];
- for (i=vp56_coeff_bit_length[idx]; i>=0; i--)
- coeff += vp56_rac_get_prob(c, vp56_coeff_parse_table[idx][i]) << i;
- } else {
- if (vp56_rac_get_prob(c, model2[4]))
- coeff = 3 + vp56_rac_get_prob(c, model[5]);
- else
- coeff = 2;
- }
- ct = 2;
- } else {
- ct = 1;
- coeff = 1;
- }
- sign = vp56_rac_get(c);
- coeff = (coeff ^ -sign) + sign;
- if (coeff_idx)
- coeff *= s->dequant_ac;
- idx = s->coeff_index_to_pos[coeff_idx];
- s->block_coeff[b][permute[idx]] = coeff;
- run = 1;
- } else {
- /* parse a run */
- ct = 0;
- if (coeff_idx == 0) {
- s->left_block[vp56_b6to4[b]].not_null_dc = 0;
- s->above_blocks[s->above_block_idx[b]].not_null_dc = 0;
- } else {
- if (!vp56_rac_get_prob(c, model2[1]))
- break;
-
- model3 = s->coeff_model_runv[coeff_idx >= 6];
- run = vp56_rac_get_tree(c, vp6_pcr_tree, model3);
- if (!run)
- for (run=9, i=0; i<6; i++)
- run += vp56_rac_get_prob(c, model3[i+8]) << i;
- }
- }
-
- cg = vp6_coeff_groups[coeff_idx+=run];
- model = model2 = s->coeff_model_ract[pt][ct][cg];
- }
- }
-}
-
-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;
- int y, x;
-
- for (y=0; y<8; y+=2) {
- for (x=0; x<8; x+=2) {
- sum += src[x];
- square_sum += src[x]*src[x];
- }
- src += 2*stride;
- }
- return (16*square_sum - sum*sum) >> 8;
-}
-
-static void vp6_filter_hv2(vp56_context_t *s, uint8_t *dst, uint8_t *src,
- int stride, int delta, int16_t weight)
-{
- s->dsp.put_pixels_tab[1][0](dst, src, stride, 8);
- s->dsp.biweight_h264_pixels_tab[3](dst, src+delta, stride, 2,
- 8-weight, weight, 0);
-}
-
-static void vp6_filter_hv4(uint8_t *dst, uint8_t *src, int stride,
- int delta, const int16_t *weights)
-{
- int x, y;
-
- for (y=0; y<8; y++) {
- for (x=0; x<8; x++) {
- dst[x] = clip_uint8(( src[x-delta ] * weights[0]
- + src[x ] * weights[1]
- + src[x+delta ] * weights[2]
- + src[x+2*delta] * weights[3] + 64) >> 7);
- }
- src += stride;
- dst += stride;
- }
-}
-
-static void vp6_filter_diag2(vp56_context_t *s, uint8_t *dst, uint8_t *src,
- int stride, int h_weight, int v_weight)
-{
- uint8_t *tmp = s->edge_emu_buffer+16;
- int x, xmax;
-
- s->dsp.put_pixels_tab[1][0](tmp, src, stride, 8);
- s->dsp.biweight_h264_pixels_tab[3](tmp, src+1, stride, 2,
- 8-h_weight, h_weight, 0);
- /* we need a 8x9 block to do vertical filter, so compute one more line */
- for (x=8*stride, xmax=x+8; x<xmax; x++)
- tmp[x] = (src[x]*(8-h_weight) + src[x+1]*h_weight + 4) >> 3;
-
- s->dsp.put_pixels_tab[1][0](dst, tmp, stride, 8);
- s->dsp.biweight_h264_pixels_tab[3](dst, tmp+stride, stride, 2,
- 8-v_weight, v_weight, 0);
-}
-
-static void vp6_filter_diag4(uint8_t *dst, uint8_t *src, int stride,
- const int16_t *h_weights,const int16_t *v_weights)
-{
- int x, y;
- int tmp[8*11];
- int *t = tmp;
-
- src -= stride;
-
- for (y=0; y<11; y++) {
- for (x=0; x<8; x++) {
- t[x] = clip_uint8(( src[x-1] * h_weights[0]
- + src[x ] * h_weights[1]
- + src[x+1] * h_weights[2]
- + src[x+2] * h_weights[3] + 64) >> 7);
- }
- src += stride;
- t += 8;
- }
-
- t = tmp + 8;
- for (y=0; y<8; y++) {
- for (x=0; x<8; x++) {
- dst[x] = clip_uint8(( t[x-8 ] * v_weights[0]
- + t[x ] * v_weights[1]
- + t[x+8 ] * v_weights[2]
- + t[x+16] * v_weights[3] + 64) >> 7);
- }
- dst += stride;
- t += 8;
- }
-}
-
-static void vp6_filter(vp56_context_t *s, uint8_t *dst, uint8_t *src,
- int offset1, int offset2, int stride,
- vp56_mv_t mv, int mask, int select, int luma)
-{
- int filter4 = 0;
- int x8 = mv.x & mask;
- int y8 = mv.y & mask;
-
- if (luma) {
- x8 *= 2;
- y8 *= 2;
- filter4 = s->filter_mode;
- if (filter4 == 2) {
- if (s->max_vector_length &&
- (FFABS(mv.x) > s->max_vector_length ||
- FFABS(mv.y) > s->max_vector_length)) {
- filter4 = 0;
- } else if (s->sample_variance_threshold
- && (vp6_block_variance(src+offset1, stride)
- < s->sample_variance_threshold)) {
- filter4 = 0;
- }
- }
- }
-
- if ((y8 && (offset2-offset1)*s->flip<0) || (!y8 && offset1 > offset2)) {
- offset1 = offset2;
- }
-
- if (filter4) {
- if (!y8) { /* left or right combine */
- vp6_filter_hv4(dst, src+offset1, stride, 1,
- vp6_block_copy_filter[select][x8]);
- } else if (!x8) { /* above or below combine */
- vp6_filter_hv4(dst, src+offset1, stride, stride,
- vp6_block_copy_filter[select][y8]);
- } else if ((mv.x^mv.y) >> 31) { /* lower-left or upper-right combine */
- vp6_filter_diag4(dst, src+offset1-1, stride,
- vp6_block_copy_filter[select][x8],
- vp6_block_copy_filter[select][y8]);
- } else { /* lower-right or upper-left combine */
- vp6_filter_diag4(dst, src+offset1, stride,
- vp6_block_copy_filter[select][x8],
- vp6_block_copy_filter[select][y8]);
- }
- } else {
- if (!y8) { /* left or right combine */
- vp6_filter_hv2(s, dst, src+offset1, stride, 1, x8);
- } else if (!x8) { /* above or below combine */
- vp6_filter_hv2(s, dst, src+offset1, stride, stride, y8);
- } else if ((mv.x^mv.y) >> 31) { /* lower-left or upper-right combine */
- vp6_filter_diag2(s, dst, src+offset1-1, stride, x8, y8);
- } else { /* lower-right or upper-left combine */
- vp6_filter_diag2(s, dst, src+offset1, stride, x8, y8);
- }
- }
-}
-
-static int vp6_decode_init(AVCodecContext *avctx)
-{
- vp56_context_t *s = avctx->priv_data;
-
- vp56_init(s, avctx, avctx->codec->id == CODEC_ID_VP6);
- s->vp56_coord_div = vp6_coord_div;
- s->parse_vector_adjustment = vp6_parse_vector_adjustment;
- s->adjust = vp6_adjust;
- s->filter = vp6_filter;
- s->parse_coeff = vp6_parse_coeff;
- s->default_models_init = vp6_default_models_init;
- s->parse_vector_models = vp6_parse_vector_models;
- s->parse_coeff_models = vp6_parse_coeff_models;
- s->parse_header = vp6_parse_header;
-
- return 0;
-}
-
-AVCodec vp6_decoder = {
- "vp6",
- CODEC_TYPE_VIDEO,
- CODEC_ID_VP6,
- sizeof(vp56_context_t),
- vp6_decode_init,
- NULL,
- vp56_free,
- vp56_decode_frame,
-};
-
-/* flash version, not flipped upside-down */
-AVCodec vp6f_decoder = {
- "vp6f",
- CODEC_TYPE_VIDEO,
- CODEC_ID_VP6F,
- sizeof(vp56_context_t),
- vp6_decode_init,
- NULL,
- vp56_free,
- vp56_decode_frame,
-};
diff --git a/src/libffmpeg/libavcodec/wavpack.c b/src/libffmpeg/libavcodec/wavpack.c
deleted file mode 100644
index b462174da..000000000
--- a/src/libffmpeg/libavcodec/wavpack.c
+++ /dev/null
@@ -1,556 +0,0 @@
-/*
- * WavPack lossless audio decoder
- * Copyright (c) 2006 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
- */
-#define ALT_BITSTREAM_READER_LE
-#include "avcodec.h"
-#include "bitstream.h"
-
-/**
- * @file wavpack.c
- * WavPack lossless audio decoder
- */
-
-#define WV_JOINT 0x0010
-
-enum WP_ID_Flags{
- WP_IDF_MASK = 0x1F,
- WP_IDF_IGNORE = 0x20,
- WP_IDF_ODD = 0x40,
- WP_IDF_LONG = 0x80
-};
-
-enum WP_ID{
- WP_ID_DUMMY = 0,
- WP_ID_ENCINFO,
- WP_ID_DECTERMS,
- WP_ID_DECWEIGHTS,
- WP_ID_DECSAMPLES,
- WP_ID_ENTROPY,
- WP_ID_HYBRID,
- WP_ID_SHAPING,
- WP_ID_FLOATINFO,
- WP_ID_INT32INFO,
- WP_ID_DATA,
- WP_ID_CORR,
- WP_ID_FLT,
- WP_ID_CHANINFO
-};
-
-#define MAX_TERMS 16
-
-typedef struct Decorr {
- int delta;
- int value;
- int weightA;
- int weightB;
- int samplesA[8];
- int samplesB[8];
-} Decorr;
-
-typedef struct WavpackContext {
- AVCodecContext *avctx;
- int stereo;
- int joint;
- uint32_t CRC;
- GetBitContext gb;
- int data_size; // in bits
- int samples;
- int median[6];
- int terms;
- Decorr decorr[MAX_TERMS];
- int zero, one, zeroes;
-} WavpackContext;
-
-// exponent table copied from WavPack source
-static const uint8_t wp_exp2_table [256] = {
- 0x00, 0x01, 0x01, 0x02, 0x03, 0x03, 0x04, 0x05, 0x06, 0x06, 0x07, 0x08, 0x08, 0x09, 0x0a, 0x0b,
- 0x0b, 0x0c, 0x0d, 0x0e, 0x0e, 0x0f, 0x10, 0x10, 0x11, 0x12, 0x13, 0x13, 0x14, 0x15, 0x16, 0x16,
- 0x17, 0x18, 0x19, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1d, 0x1e, 0x1f, 0x20, 0x20, 0x21, 0x22, 0x23,
- 0x24, 0x24, 0x25, 0x26, 0x27, 0x28, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,
- 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3a, 0x3b, 0x3c, 0x3d,
- 0x3e, 0x3f, 0x40, 0x41, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x48, 0x49, 0x4a, 0x4b,
- 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a,
- 0x5b, 0x5c, 0x5d, 0x5e, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
- 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
- 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x87, 0x88, 0x89, 0x8a,
- 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,
- 0x9c, 0x9d, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad,
- 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0,
- 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc8, 0xc9, 0xca, 0xcb, 0xcd, 0xce, 0xcf, 0xd0, 0xd2, 0xd3, 0xd4,
- 0xd6, 0xd7, 0xd8, 0xd9, 0xdb, 0xdc, 0xdd, 0xde, 0xe0, 0xe1, 0xe2, 0xe4, 0xe5, 0xe6, 0xe8, 0xe9,
- 0xea, 0xec, 0xed, 0xee, 0xf0, 0xf1, 0xf2, 0xf4, 0xf5, 0xf6, 0xf8, 0xf9, 0xfa, 0xfc, 0xfd, 0xff
-};
-
-static av_always_inline int wp_exp2(int16_t val)
-{
- int res, neg = 0;
-
- if(val < 0){
- val = -val;
- neg = 1;
- }
-
- res = wp_exp2_table[val & 0xFF] | 0x100;
- val >>= 8;
- res = (val > 9) ? (res << (val - 9)) : (res >> (9 - val));
- return neg ? -res : res;
-}
-
-static inline int get_unary(GetBitContext *gb){
- int r=0;
- while(get_bits1(gb) && r<33)r++;
- return r;
-}
-
-// macros for manipulating median values
-#define GET_MED(n) ((median[n] >> 4) + 1)
-#define DEC_MED(n) median[n] -= ((median[n] + (128>>n) - 2) / (128>>n)) * 2
-#define INC_MED(n) median[n] += ((median[n] + (128>>n)) / (128>>n)) * 5
-
-// macros for applying weight
-#define UPDATE_WEIGHT_CLIP(weight, delta, samples, in) \
- if(samples && in){ \
- if((samples ^ in) < 0){ \
- weight -= delta; \
- if(weight < -1024) weight = -1024; \
- }else{ \
- weight += delta; \
- if(weight > 1024) weight = 1024; \
- } \
- }
-
-
-static av_always_inline int get_tail(GetBitContext *gb, int k)
-{
- int p, e, res;
-
- if(k<1)return 0;
- p = av_log2(k);
- e = (1 << (p + 1)) - k - 1;
- res = p ? get_bits(gb, p) : 0;
- if(res >= e){
- res = (res<<1) - e + get_bits1(gb);
- }
- return res;
-}
-
-static int wv_get_value(WavpackContext *ctx, GetBitContext *gb, int *median, int *last)
-{
- int t, t2;
- int sign, base, add, ret;
-
- *last = 0;
-
- if((ctx->median[0] < 2U) && (ctx->median[3] < 2U) && !ctx->zero && !ctx->one){
- if(ctx->zeroes){
- ctx->zeroes--;
- if(ctx->zeroes)
- return 0;
- }else{
- t = get_unary(gb);
- if(t >= 2) t = get_bits(gb, t - 1) | (1 << (t-1));
- ctx->zeroes = t;
- if(ctx->zeroes){
- memset(ctx->median, 0, sizeof(ctx->median));
- return 0;
- }
- }
- }
-
- if(get_bits_count(gb) >= ctx->data_size){
- *last = 1;
- return 0;
- }
-
- if(ctx->zero){
- t = 0;
- ctx->zero = 0;
- }else{
- t = get_unary(gb);
- if(get_bits_count(gb) >= ctx->data_size){
- *last = 1;
- return 0;
- }
- if(t == 16) {
- t2 = get_unary(gb);
- if(t2 < 2) t += t2;
- else t += get_bits(gb, t2 - 1) | (1 << (t2 - 1));
- }
-
- if(ctx->one){
- ctx->one = t&1;
- t = (t>>1) + 1;
- }else{
- ctx->one = t&1;
- t >>= 1;
- }
- ctx->zero = !ctx->one;
- }
-
- if(!t){
- base = 0;
- add = GET_MED(0) - 1;
- DEC_MED(0);
- }else if(t == 1){
- base = GET_MED(0);
- add = GET_MED(1) - 1;
- INC_MED(0);
- DEC_MED(1);
- }else if(t == 2){
- base = GET_MED(0) + GET_MED(1);
- add = GET_MED(2) - 1;
- INC_MED(0);
- INC_MED(1);
- DEC_MED(2);
- }else{
- base = GET_MED(0) + GET_MED(1) + GET_MED(2) * (t - 2);
- add = GET_MED(2) - 1;
- INC_MED(0);
- INC_MED(1);
- INC_MED(2);
- }
- ret = base + get_tail(gb, add);
- sign = get_bits1(gb);
- return sign ? ~ret : ret;
-}
-
-static int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, int16_t *dst)
-{
- int i, j, count = 0;
- int last, t;
- int A, B, L, L2, R, R2;
- int pos = 0;
- uint32_t crc = 0xFFFFFFFF;
-
- s->one = s->zero = s->zeroes = 0;
- do{
- L = wv_get_value(s, gb, s->median, &last);
- if(last) break;
- R = wv_get_value(s, gb, s->median + 3, &last);
- if(last) break;
- for(i = 0; i < s->terms; i++){
- t = s->decorr[i].value;
- j = 0;
- if(t > 0){
- if(t > 8){
- if(t & 1){
- A = 2 * s->decorr[i].samplesA[0] - s->decorr[i].samplesA[1];
- B = 2 * s->decorr[i].samplesB[0] - s->decorr[i].samplesB[1];
- }else{
- A = (3 * s->decorr[i].samplesA[0] - s->decorr[i].samplesA[1]) >> 1;
- B = (3 * s->decorr[i].samplesB[0] - s->decorr[i].samplesB[1]) >> 1;
- }
- s->decorr[i].samplesA[1] = s->decorr[i].samplesA[0];
- s->decorr[i].samplesB[1] = s->decorr[i].samplesB[0];
- j = 0;
- }else{
- A = s->decorr[i].samplesA[pos];
- B = s->decorr[i].samplesB[pos];
- j = (pos + t) & 7;
- }
- L2 = L + ((s->decorr[i].weightA * A + 512) >> 10);
- R2 = R + ((s->decorr[i].weightB * B + 512) >> 10);
- if(A && L) s->decorr[i].weightA -= ((((L ^ A) >> 30) & 2) - 1) * s->decorr[i].delta;
- if(B && R) s->decorr[i].weightB -= ((((R ^ B) >> 30) & 2) - 1) * s->decorr[i].delta;
- s->decorr[i].samplesA[j] = L = L2;
- s->decorr[i].samplesB[j] = R = R2;
- }else if(t == -1){
- L2 = L + ((s->decorr[i].weightA * s->decorr[i].samplesA[0] + 512) >> 10);
- UPDATE_WEIGHT_CLIP(s->decorr[i].weightA, s->decorr[i].delta, s->decorr[i].samplesA[0], L);
- L = L2;
- R2 = R + ((s->decorr[i].weightB * L2 + 512) >> 10);
- UPDATE_WEIGHT_CLIP(s->decorr[i].weightB, s->decorr[i].delta, L2, R);
- R = R2;
- s->decorr[i].samplesA[0] = R;
- }else{
- R2 = R + ((s->decorr[i].weightB * s->decorr[i].samplesB[0] + 512) >> 10);
- UPDATE_WEIGHT_CLIP(s->decorr[i].weightB, s->decorr[i].delta, s->decorr[i].samplesB[0], R);
- R = R2;
-
- if(t == -3){
- R2 = s->decorr[i].samplesA[0];
- s->decorr[i].samplesA[0] = R;
- }
-
- L2 = L + ((s->decorr[i].weightA * R2 + 512) >> 10);
- UPDATE_WEIGHT_CLIP(s->decorr[i].weightA, s->decorr[i].delta, R2, L);
- L = L2;
- s->decorr[i].samplesB[0] = L;
- }
- }
- pos = (pos + 1) & 7;
- if(s->joint)
- L += (R -= (L >> 1));
- crc = (crc * 3 + L) * 3 + R;
- *dst++ = L;
- *dst++ = R;
-
- count++;
- }while(!last && count < s->samples);
-
- if(crc != s->CRC){
- av_log(s->avctx, AV_LOG_ERROR, "CRC error\n");
- return -1;
- }
- return count * 2;
-}
-
-static int wv_unpack_mono(WavpackContext *s, GetBitContext *gb, int16_t *dst)
-{
- int i, j, count = 0;
- int last, t;
- int A, S, T;
- int pos = 0;
- uint32_t crc = 0xFFFFFFFF;
-
- s->one = s->zero = s->zeroes = 0;
- do{
- T = wv_get_value(s, gb, s->median, &last);
- S = 0;
- if(last) break;
- for(i = 0; i < s->terms; i++){
- t = s->decorr[i].value;
- if(t > 8){
- if(t & 1)
- A = 2 * s->decorr[i].samplesA[0] - s->decorr[i].samplesA[1];
- else
- A = (3 * s->decorr[i].samplesA[0] - s->decorr[i].samplesA[1]) >> 1;
- s->decorr[i].samplesA[1] = s->decorr[i].samplesA[0];
- j = 0;
- }else{
- A = s->decorr[i].samplesA[pos];
- j = (pos + t) & 7;
- }
- S = T + ((s->decorr[i].weightA * A + 512) >> 10);
- if(A && T) s->decorr[i].weightA -= ((((T ^ A) >> 30) & 2) - 1) * s->decorr[i].delta;
- s->decorr[i].samplesA[j] = T = S;
- }
- pos = (pos + 1) & 7;
- crc = crc * 3 + S;
- *dst++ = S;
- count++;
- }while(!last && count < s->samples);
-
- if(crc != s->CRC){
- av_log(s->avctx, AV_LOG_ERROR, "CRC error\n");
- return -1;
- }
- return count;
-}
-
-static int wavpack_decode_init(AVCodecContext *avctx)
-{
- WavpackContext *s = avctx->priv_data;
-
- s->avctx = avctx;
- s->stereo = (avctx->channels == 2);
-
- return 0;
-}
-
-static int wavpack_decode_close(AVCodecContext *avctx)
-{
-// WavpackContext *s = avctx->priv_data;
-
- return 0;
-}
-
-static int wavpack_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- WavpackContext *s = avctx->priv_data;
- int16_t *samples = data;
- int samplecount;
- int got_terms = 0, got_weights = 0, got_samples = 0, got_entropy = 0, got_bs = 0;
- uint8_t* buf_end = buf + buf_size;
- int i, j, id, size, ssize, weights, t;
-
- if (buf_size == 0) return 0;
-
- memset(s->decorr, 0, MAX_TERMS * sizeof(Decorr));
-
- s->samples = AV_RL32(buf); buf += 4;
- if(!s->samples) return buf_size;
- /* should not happen but who knows */
- if(s->samples * 2 * avctx->channels > AVCODEC_MAX_AUDIO_FRAME_SIZE){
- av_log(avctx, AV_LOG_ERROR, "Packet size is too big to be handled in lavc!\n");
- return -1;
- }
- s->joint = AV_RL32(buf) & WV_JOINT; buf += 4;
- s->CRC = AV_RL32(buf); buf += 4;
- // parse metadata blocks
- while(buf < buf_end){
- id = *buf++;
- size = *buf++;
- if(id & WP_IDF_LONG) {
- size |= (*buf++) << 8;
- size |= (*buf++) << 16;
- }
- size <<= 1; // size is specified in words
- ssize = size;
- if(id & WP_IDF_ODD) size--;
- if(size < 0){
- av_log(avctx, AV_LOG_ERROR, "Got incorrect block %02X with size %i\n", id, size);
- break;
- }
- if(buf + ssize > buf_end){
- av_log(avctx, AV_LOG_ERROR, "Block size %i is out of bounds\n", size);
- break;
- }
- if(id & WP_IDF_IGNORE){
- buf += ssize;
- continue;
- }
- switch(id & WP_IDF_MASK){
- case WP_ID_DECTERMS:
- s->terms = size;
- if(s->terms > MAX_TERMS){
- av_log(avctx, AV_LOG_ERROR, "Too many decorrelation terms\n");
- buf += ssize;
- continue;
- }
- for(i = 0; i < s->terms; i++) {
- s->decorr[s->terms - i - 1].value = (*buf & 0x1F) - 5;
- s->decorr[s->terms - i - 1].delta = *buf >> 5;
- buf++;
- }
- got_terms = 1;
- break;
- case WP_ID_DECWEIGHTS:
- if(!got_terms){
- av_log(avctx, AV_LOG_ERROR, "No decorrelation terms met\n");
- continue;
- }
- weights = size >> s->stereo;
- if(weights > MAX_TERMS || weights > s->terms){
- av_log(avctx, AV_LOG_ERROR, "Too many decorrelation weights\n");
- buf += ssize;
- continue;
- }
- for(i = 0; i < weights; i++) {
- t = (int8_t)(*buf++);
- s->decorr[s->terms - i - 1].weightA = t << 3;
- if(s->decorr[s->terms - i - 1].weightA > 0)
- s->decorr[s->terms - i - 1].weightA += (s->decorr[s->terms - i - 1].weightA + 64) >> 7;
- if(s->stereo){
- t = (int8_t)(*buf++);
- s->decorr[s->terms - i - 1].weightB = t << 3;
- if(s->decorr[s->terms - i - 1].weightB > 0)
- s->decorr[s->terms - i - 1].weightB += (s->decorr[s->terms - i - 1].weightB + 64) >> 7;
- }
- }
- got_weights = 1;
- break;
- case WP_ID_DECSAMPLES:
- if(!got_terms){
- av_log(avctx, AV_LOG_ERROR, "No decorrelation terms met\n");
- continue;
- }
- t = 0;
- for(i = s->terms - 1; (i >= 0) && (t < size); i--) {
- if(s->decorr[i].value > 8){
- s->decorr[i].samplesA[0] = wp_exp2(AV_RL16(buf)); buf += 2;
- s->decorr[i].samplesA[1] = wp_exp2(AV_RL16(buf)); buf += 2;
- if(s->stereo){
- s->decorr[i].samplesB[0] = wp_exp2(AV_RL16(buf)); buf += 2;
- s->decorr[i].samplesB[1] = wp_exp2(AV_RL16(buf)); buf += 2;
- t += 4;
- }
- t += 4;
- }else if(s->decorr[i].value < 0){
- s->decorr[i].samplesA[0] = wp_exp2(AV_RL16(buf)); buf += 2;
- s->decorr[i].samplesB[0] = wp_exp2(AV_RL16(buf)); buf += 2;
- t += 4;
- }else{
- for(j = 0; j < s->decorr[i].value; j++){
- s->decorr[i].samplesA[j] = wp_exp2(AV_RL16(buf)); buf += 2;
- if(s->stereo){
- s->decorr[i].samplesB[j] = wp_exp2(AV_RL16(buf)); buf += 2;
- }
- }
- t += s->decorr[i].value * 2 * avctx->channels;
- }
- }
- got_samples = 1;
- break;
- case WP_ID_ENTROPY:
- if(size != 6 * avctx->channels){
- av_log(avctx, AV_LOG_ERROR, "Entropy vars size should be %i, got %i", 6 * avctx->channels, size);
- buf += ssize;
- continue;
- }
- for(i = 0; i < 3 * avctx->channels; i++){
- s->median[i] = wp_exp2(AV_RL16(buf));
- buf += 2;
- }
- got_entropy = 1;
- break;
- case WP_ID_DATA:
- init_get_bits(&s->gb, buf, size * 8);
- s->data_size = size * 8;
- buf += size;
- got_bs = 1;
- break;
- default:
- buf += size;
- }
- 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(!got_bs){
- av_log(avctx, AV_LOG_ERROR, "Packed samples not found\n");
- return -1;
- }
-
- if(s->stereo)
- samplecount = wv_unpack_stereo(s, &s->gb, samples);
- else
- samplecount = wv_unpack_mono(s, &s->gb, samples);
- *data_size = samplecount * 2;
-
- return buf_size;
-}
-
-AVCodec wavpack_decoder = {
- "wavpack",
- CODEC_TYPE_AUDIO,
- CODEC_ID_WAVPACK,
- sizeof(WavpackContext),
- wavpack_decode_init,
- NULL,
- wavpack_decode_close,
- wavpack_decode_frame,
-};
diff --git a/src/libffmpeg/libavcodec/wmadata.h b/src/libffmpeg/libavcodec/wmadata.h
deleted file mode 100644
index 35e545ce6..000000000
--- a/src/libffmpeg/libavcodec/wmadata.h
+++ /dev/null
@@ -1,1433 +0,0 @@
-/*
- * WMA compatible decoder
- * copyright (c) 2002 The FFmpeg Project
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/**
- * @file wmadata.h
- * Various WMA tables.
- */
-
-static const uint16_t 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,
- 24500,
-};
-
-/* first value is number of bands */
-static const uint8_t exponent_band_22050[3][25] = {
- { 10, 4, 8, 4, 8, 8, 12, 20, 24, 24, 16, },
- { 14, 4, 8, 8, 4, 12, 12, 16, 24, 16, 20, 24, 32, 40, 36, },
- { 23, 4, 4, 4, 8, 4, 4, 8, 8, 8, 8, 8, 12, 12, 16, 16, 24, 24, 32, 44, 48, 60, 84, 72, },
-};
-
-static const uint8_t exponent_band_32000[3][25] = {
- { 11, 4, 4, 8, 4, 4, 12, 16, 24, 20, 28, 4, },
- { 15, 4, 8, 4, 4, 8, 8, 16, 20, 12, 20, 20, 28, 40, 56, 8, },
- { 16, 8, 4, 8, 8, 12, 16, 20, 24, 40, 32, 32, 44, 56, 80, 112, 16, },
-};
-
-static const uint8_t exponent_band_44100[3][25] = {
- { 12, 4, 4, 4, 4, 4, 8, 8, 8, 12, 16, 20, 36, },
- { 15, 4, 8, 4, 8, 8, 4, 8, 8, 12, 12, 12, 24, 28, 40, 76, },
- { 17, 4, 8, 8, 4, 12, 12, 8, 8, 24, 16, 20, 24, 32, 40, 60, 80, 152, },
-};
-
-static const uint16_t hgain_huffcodes[37] = {
- 0x00003, 0x002e7, 0x00001, 0x005cd, 0x0005d, 0x005c9, 0x0005e, 0x00003,
- 0x00016, 0x0000b, 0x00001, 0x00006, 0x00001, 0x00006, 0x00004, 0x00005,
- 0x00004, 0x00007, 0x00003, 0x00007, 0x00004, 0x0000a, 0x0000a, 0x00002,
- 0x00003, 0x00000, 0x00005, 0x00002, 0x0005f, 0x00004, 0x00003, 0x00002,
- 0x005c8, 0x000b8, 0x005ca, 0x005cb, 0x005cc,
-};
-
-static const uint8_t hgain_huffbits[37] = {
- 10, 12, 10, 13, 9, 13, 9, 8,
- 7, 5, 5, 4, 4, 3, 3, 3,
- 4, 3, 4, 4, 5, 5, 6, 8,
- 7, 10, 8, 10, 9, 8, 9, 9,
- 13, 10, 13, 13, 13,
-};
-
-static const float lsp_codebook[NB_LSP_COEFS][16] = {
- { 1.98732877, 1.97944528, 1.97179088, 1.96260549, 1.95038374, 1.93336114, 1.90719232, 1.86191415, },
- { 1.97260000, 1.96083160, 1.94982586, 1.93806164, 1.92516608, 1.91010199, 1.89232331, 1.87149812,
- 1.84564818, 1.81358067, 1.77620070, 1.73265264, 1.67907855, 1.60959081, 1.50829650, 1.33120330, },
- { 1.90109110, 1.86482426, 1.83419671, 1.80168452, 1.76650116, 1.72816320, 1.68502700, 1.63738256,
- 1.58501580, 1.51795181, 1.43679906, 1.33950585, 1.24176208, 1.12260729, 0.96749668, 0.74048265, },
- { 1.76943864, 1.67822463, 1.59946365, 1.53560582, 1.47470796, 1.41210167, 1.34509536, 1.27339507,
- 1.19303814, 1.09765169, 0.98818722, 0.87239446, 0.74369172, 0.59768184, 0.43168630, 0.17977021, },
- { 1.43428349, 1.32038354, 1.21074086, 1.10577988, 1.00561746, 0.90335924, 0.80437489, 0.70709671,
- 0.60427395, 0.49814048, 0.38509539, 0.27106800, 0.14407416, 0.00219910, -0.16725141, -0.36936085, },
- { 0.99895687, 0.84188166, 0.70753739, 0.57906595, 0.47055563, 0.36966965, 0.26826648, 0.17163380,
- 0.07208392, -0.03062936, -1.40037388, -0.25128968, -0.37213937, -0.51075646, -0.64887512, -0.80308031, },
- { 0.26515280, 0.06313551, -0.08872080, -0.21103548, -0.31069678, -0.39680323, -0.47223474, -0.54167135,
- -0.61444740, -0.68943343, -0.76580211, -0.85170082, -0.95289061, -1.06514703, -1.20510707, -1.37617746, },
- { -0.53940301, -0.73770929, -0.88424876, -1.01117930, -1.13389091, -1.26830073, -1.42041987, -1.62033919,
- -1.10158808, -1.16512566, -1.23337128, -1.30414401, -1.37663312, -1.46853845, -1.57625798, -1.66893638, },
- { -0.38601997, -0.56009350, -0.66978483, -0.76028471, -0.83846064, -0.90868087, -0.97408881, -1.03694962, },
- { -1.56144989, -1.65944032, -1.72689685, -1.77857740, -1.82203011, -1.86220079, -1.90283983, -1.94820479, },
-};
-
-static const uint32_t 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,
-};
-
-static const uint8_t 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,
- 0x0004a, 0x0004d, 0x00061, 0x00070, 0x00073, 0x00048, 0x00052, 0x0005a,
- 0x0005d, 0x0006e, 0x00099, 0x0009e, 0x000c1, 0x000ce, 0x000e4, 0x000f0,
- 0x00093, 0x0009e, 0x000a2, 0x000a1, 0x000b8, 0x000d2, 0x000d3, 0x0012e,
- 0x00130, 0x000de, 0x0012d, 0x0019b, 0x001e4, 0x00139, 0x0013a, 0x0013f,
- 0x0014f, 0x0016d, 0x001a2, 0x0027c, 0x0027e, 0x00332, 0x0033c, 0x0033f,
- 0x0038b, 0x00396, 0x003c5, 0x00270, 0x0027c, 0x0025a, 0x00395, 0x00248,
- 0x004bd, 0x004fb, 0x00662, 0x00661, 0x0071b, 0x004e6, 0x004ff, 0x00666,
- 0x0071c, 0x0071a, 0x0071f, 0x00794, 0x00536, 0x004e2, 0x0078e, 0x004ee,
- 0x00518, 0x00535, 0x004fb, 0x0078d, 0x00530, 0x00680, 0x0068f, 0x005cb,
- 0x00965, 0x006a6, 0x00967, 0x0097f, 0x00682, 0x006ae, 0x00cd0, 0x00e28,
- 0x00f13, 0x00f1f, 0x009f5, 0x00cd3, 0x00f11, 0x00926, 0x00964, 0x00f32,
- 0x00f12, 0x00f30, 0x00966, 0x00d0b, 0x00a68, 0x00b91, 0x009c7, 0x00b73,
- 0x012fa, 0x0131d, 0x013f9, 0x01ca0, 0x0199c, 0x01c7a, 0x0198c, 0x01248,
- 0x01c74, 0x01c64, 0x0139e, 0x012fd, 0x00a77, 0x012fc, 0x01c7b, 0x012ca,
- 0x014cc, 0x014d2, 0x014e3, 0x014dc, 0x012dc, 0x03344, 0x02598, 0x0263c,
- 0x0333b, 0x025e6, 0x01a1c, 0x01e3c, 0x014e2, 0x033d4, 0x01a11, 0x03349,
- 0x03cce, 0x014e1, 0x01a34, 0x0273e, 0x02627, 0x0273f, 0x038ee, 0x03971,
- 0x03c67, 0x03c61, 0x0333d, 0x038c2, 0x0263f, 0x038cd, 0x02638, 0x02e41,
- 0x0351f, 0x03348, 0x03c66, 0x03562, 0x02989, 0x027d5, 0x0333c, 0x02e4f,
- 0x0343b, 0x02ddf, 0x04bc8, 0x029c0, 0x02e57, 0x04c72, 0x025b7, 0x03547,
- 0x03540, 0x029d3, 0x04c45, 0x025bb, 0x06600, 0x04c73, 0x04bce, 0x0357b,
- 0x029a6, 0x029d2, 0x0263e, 0x0298a, 0x07183, 0x06602, 0x07958, 0x04b66,
- 0x0537d, 0x05375, 0x04fe9, 0x04b67, 0x0799f, 0x04bc9, 0x051fe, 0x06a3b,
- 0x05bb6, 0x04fa8, 0x0728f, 0x05376, 0x0492c, 0x0537e, 0x0795a, 0x06a3c,
- 0x0e515, 0x07887, 0x0683a, 0x051f9, 0x051fd, 0x0cc6a, 0x06a8a, 0x0cc6d,
- 0x05bb3, 0x0683b, 0x051fc, 0x05378, 0x0728e, 0x07886, 0x05bb7, 0x0f2a4,
- 0x0795b, 0x0683c, 0x09fc1, 0x0683d, 0x0b752, 0x09678, 0x0a3e8, 0x06ac7,
- 0x051f0, 0x0b759, 0x06af3, 0x04b6b, 0x0f2a0, 0x0f2ad, 0x096c3, 0x0e518,
- 0x0b75c, 0x0d458, 0x0cc6b, 0x0537c, 0x067aa, 0x04fea, 0x0343a, 0x0cc71,
- 0x0967f, 0x09fc4, 0x096c2, 0x0e516, 0x0f2a1, 0x0d45c, 0x0d45d, 0x0d45e,
- 0x12fb9, 0x0967e, 0x1982f, 0x09883, 0x096c4, 0x0b753, 0x12fb8, 0x0f2a8,
- 0x1ca21, 0x096c5, 0x0e51a, 0x1ca27, 0x12f3c, 0x0d471, 0x0f2aa, 0x0b75b,
- 0x12fbb, 0x0f2a9, 0x0f2ac, 0x0d45a, 0x0b74f, 0x096c8, 0x16e91, 0x096ca,
- 0x12fbf, 0x0d0a7, 0x13103, 0x0d516, 0x16e99, 0x12cbd, 0x0a3ea, 0x19829,
- 0x0b755, 0x29ba7, 0x1ca28, 0x29ba5, 0x16e93, 0x1982c, 0x19828, 0x25994,
- 0x0a3eb, 0x1ca29, 0x16e90, 0x1ca25, 0x1982d, 0x1ca26, 0x16e9b, 0x0b756,
- 0x0967c, 0x25997, 0x0b75f, 0x198d3, 0x0b757, 0x19a2a, 0x0d45b, 0x0e517,
- 0x1ca24, 0x1ca23, 0x1ca22, 0x0b758, 0x16e97, 0x0cd14, 0x13100, 0x00007,
- 0x0003b, 0x0006b, 0x00097, 0x00138, 0x00125, 0x00173, 0x00258, 0x00335,
- 0x0028e, 0x004c6, 0x00715, 0x00729, 0x004ef, 0x00519, 0x004ed, 0x00532,
- 0x0068c, 0x00686, 0x00978, 0x00e5d, 0x00e31, 0x009f4, 0x00b92, 0x012f8,
- 0x00d06, 0x00a67, 0x00d44, 0x00a76, 0x00d59, 0x012cd, 0x01c78, 0x01c75,
- 0x0199f, 0x0198f, 0x01c67, 0x014c6, 0x01c79, 0x01c76, 0x00b94, 0x00d1b,
- 0x01e32, 0x01e31, 0x01ab0, 0x01a05, 0x01aa1, 0x0333a, 0x025e5, 0x02626,
- 0x03541, 0x03544, 0x03421, 0x03546, 0x02e55, 0x02e56, 0x0492d, 0x02dde,
- 0x0299b, 0x02ddc, 0x0357a, 0x0249c, 0x0668b, 0x1c77f, 0x1ca20, 0x0d45f,
- 0x09886, 0x16e9a, 0x0f2a7, 0x0b751, 0x0a3ee, 0x0cf59, 0x0cf57, 0x0b754,
- 0x0d0a6, 0x16e98, 0x0b760, 0x06ac6, 0x0a3f0, 0x12fbe, 0x13104, 0x0f2a5,
- 0x0a3ef, 0x0d472, 0x12cba, 0x1982e, 0x16e9c, 0x1c77e, 0x198d0, 0x13105,
- 0x16e92, 0x0b75d, 0x0d459, 0x0001a, 0x000c0, 0x0016c, 0x003cd, 0x00350,
- 0x0067b, 0x0051e, 0x006a9, 0x009f4, 0x00b72, 0x00d09, 0x01249, 0x01e3d,
- 0x01ca1, 0x01a1f, 0x01721, 0x01a8a, 0x016e8, 0x03347, 0x01a35, 0x0249d,
- 0x0299a, 0x02596, 0x02e4e, 0x0298b, 0x07182, 0x04c46, 0x025ba, 0x02e40,
- 0x027d6, 0x04fe8, 0x06607, 0x05310, 0x09884, 0x072e1, 0x06a3d, 0x04b6a,
- 0x04c7a, 0x06603, 0x04c7b, 0x03428, 0x06605, 0x09664, 0x09fc0, 0x071de,
- 0x06601, 0x05bb2, 0x09885, 0x0a3e2, 0x1c61f, 0x12cbb, 0x0b750, 0x0cf58,
- 0x0967d, 0x25995, 0x668ad, 0x0b75a, 0x09fc2, 0x0537f, 0x0b75e, 0x13fae,
- 0x12fbc, 0x00031, 0x001c4, 0x004c5, 0x005b8, 0x00cf4, 0x0096f, 0x00d46,
- 0x01e57, 0x01a04, 0x02625, 0x03346, 0x028f9, 0x04c47, 0x072e0, 0x04b69,
- 0x03420, 0x07957, 0x06639, 0x0799e, 0x07959, 0x07881, 0x04b68, 0x09fc3,
- 0x09fd6, 0x0cc70, 0x0a3f1, 0x12cbe, 0x0e30e, 0x0e51b, 0x06af2, 0x12cbc,
- 0x1c77d, 0x0f2ab, 0x12fbd, 0x1aa2f, 0x0a3ec, 0x0d473, 0x05377, 0x0a3e9,
- 0x1982b, 0x0e300, 0x12f3f, 0x0cf5f, 0x096c0, 0x38c3c, 0x16e94, 0x16e95,
- 0x12f3d, 0x29ba4, 0x29ba6, 0x1c77c, 0x6a8ba, 0x3545c, 0x33457, 0x668ac,
- 0x6a8bb, 0x16e9d, 0x0e519, 0x25996, 0x12f3e, 0x00036, 0x0033e, 0x006ad,
- 0x00d03, 0x012c8, 0x0124a, 0x03c42, 0x03ccd, 0x06606, 0x07880, 0x06852,
- 0x06a3a, 0x05bb4, 0x0f2a2, 0x09fc7, 0x12cb9, 0x0cc6c, 0x0a6e8, 0x096c1,
- 0x0004a, 0x00355, 0x012f9, 0x014e8, 0x01abe, 0x025b6, 0x0492e, 0x09fc6,
- 0x051ff, 0x0cc6f, 0x096cb, 0x0d071, 0x198d1, 0x12cb8, 0x38c3d, 0x13faf,
- 0x096c9, 0x0009d, 0x00539, 0x012ce, 0x0341f, 0x029c1, 0x04b33, 0x0a3e3,
- 0x0d070, 0x16e96, 0x0b763, 0x000a0, 0x009ce, 0x038cc, 0x0343d, 0x051fa,
- 0x09888, 0x12fba, 0x000df, 0x00a75, 0x029a7, 0x09fc5, 0x0e301, 0x0967b,
- 0x001e7, 0x012c9, 0x051fb, 0x09889, 0x0f2a6, 0x0016f, 0x01cb9, 0x0cf5a,
- 0x12cbf, 0x09679, 0x00272, 0x01a15, 0x0967a, 0x003cb, 0x025f6, 0x0b762,
- 0x0028d, 0x03c60, 0x0cf5e, 0x00352, 0x03ccc, 0x0072f, 0x07186, 0x004ec,
- 0x05379, 0x0068e, 0x09887, 0x006a7, 0x06af1, 0x00e29, 0x0cf5b, 0x00f31,
- 0x0d470, 0x009c6, 0x013fb, 0x13102, 0x019a5, 0x13101, 0x01983, 0x01c65,
- 0x0124f, 0x014c7, 0x01726, 0x01abf, 0x03304, 0x02624, 0x03c41, 0x027d7,
- 0x02ddd, 0x02e54, 0x0343c, 0x06604, 0x07181, 0x0663a, 0x04fa9, 0x0663b,
- 0x05311, 0x0537a, 0x06839, 0x05bb5, 0x0492f, 0x06af0, 0x096c7, 0x0cc6e,
- 0x0537b, 0x0cf5c, 0x0cf56, 0x198d2, 0x0cf5d, 0x0a3ed, 0x0f2a3, 0x1982a,
- 0x0b761, 0x096c6,
-};
-
-static const uint8_t coef0_huffbits[666] = {
- 11, 6, 2, 3, 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,
- 9, 9, 9, 9, 9, 9, 9, 9,
- 9, 9, 9, 9, 9, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 11, 11, 11, 10, 11,
- 11, 11, 11, 11, 11, 11, 11, 11,
- 11, 11, 11, 11, 12, 12, 11, 12,
- 12, 12, 12, 11, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 13, 13, 12,
- 12, 12, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 14,
- 13, 13, 13, 13, 13, 13, 13, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 13, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 15,
- 15, 14, 14, 15, 15, 15, 14, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 14, 15, 15, 15, 15, 16,
- 16, 16, 15, 16, 15, 15, 16, 16,
- 16, 16, 15, 16, 16, 16, 15, 16,
- 16, 15, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 15, 15, 16, 16,
- 15, 16, 16, 16, 17, 17, 17, 16,
- 16, 17, 16, 16, 16, 16, 17, 16,
- 17, 17, 16, 16, 15, 15, 15, 16,
- 17, 16, 17, 16, 16, 17, 17, 17,
- 17, 17, 17, 16, 17, 17, 17, 16,
- 17, 17, 16, 17, 17, 17, 16, 17,
- 17, 16, 16, 17, 17, 17, 18, 17,
- 17, 17, 17, 17, 18, 18, 17, 17,
- 17, 19, 17, 19, 18, 17, 17, 18,
- 17, 17, 18, 17, 17, 17, 18, 17,
- 17, 18, 17, 17, 17, 17, 17, 16,
- 17, 17, 17, 17, 18, 16, 17, 4,
- 6, 8, 9, 9, 10, 10, 10, 10,
- 11, 11, 11, 11, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 14, 13, 13, 13, 13,
- 13, 13, 14, 14, 14, 14, 14, 14,
- 15, 15, 15, 15, 15, 15, 16, 15,
- 15, 15, 15, 15, 15, 17, 17, 17,
- 16, 18, 16, 17, 17, 16, 16, 17,
- 17, 18, 17, 16, 17, 17, 17, 16,
- 17, 17, 18, 17, 18, 17, 17, 17,
- 18, 17, 17, 5, 8, 10, 10, 11,
- 11, 12, 12, 12, 13, 13, 14, 13,
- 13, 14, 14, 14, 14, 14, 14, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 16, 16, 15, 16, 16,
- 15, 15, 15, 15, 15, 16, 16, 15,
- 15, 16, 16, 17, 17, 18, 17, 16,
- 17, 18, 19, 17, 16, 16, 17, 17,
- 17, 6, 9, 11, 12, 12, 13, 13,
- 13, 14, 14, 14, 15, 15, 15, 16,
- 15, 15, 15, 15, 15, 15, 16, 16,
- 16, 16, 17, 18, 16, 16, 16, 18,
- 17, 16, 17, 18, 17, 17, 16, 17,
- 17, 16, 17, 16, 17, 18, 18, 18,
- 17, 19, 19, 17, 20, 19, 18, 19,
- 20, 18, 16, 18, 17, 7, 10, 12,
- 13, 13, 14, 14, 14, 15, 15, 16,
- 16, 16, 16, 16, 18, 16, 17, 17,
- 8, 11, 13, 14, 14, 15, 16, 16,
- 16, 16, 17, 17, 17, 18, 18, 17,
- 17, 8, 12, 14, 15, 15, 15, 17,
- 17, 18, 17, 9, 12, 14, 15, 16,
- 16, 17, 9, 13, 15, 16, 16, 17,
- 9, 13, 16, 16, 16, 10, 13, 16,
- 18, 17, 10, 14, 17, 10, 14, 17,
- 11, 14, 16, 11, 14, 11, 15, 12,
- 16, 12, 16, 12, 16, 12, 16, 12,
- 17, 13, 13, 17, 13, 17, 13, 13,
- 14, 14, 14, 14, 14, 14, 14, 15,
- 15, 15, 15, 15, 15, 15, 16, 15,
- 16, 16, 16, 16, 16, 16, 17, 16,
- 16, 16, 16, 17, 16, 17, 16, 17,
- 17, 17,
-};
-
-static const uint32_t coef1_huffcodes[555] = {
- 0x00115, 0x00002, 0x00001, 0x00000, 0x0000d, 0x00007, 0x00013, 0x0001d,
- 0x00008, 0x0000c, 0x00023, 0x0002b, 0x0003f, 0x00017, 0x0001b, 0x00043,
- 0x00049, 0x00050, 0x00055, 0x00054, 0x00067, 0x00064, 0x0007b, 0x0002d,
- 0x00028, 0x0002a, 0x00085, 0x00089, 0x0002b, 0x00035, 0x00090, 0x00091,
- 0x00094, 0x00088, 0x000c1, 0x000c6, 0x000f2, 0x000e3, 0x000c5, 0x000e2,
- 0x00036, 0x000f0, 0x000a7, 0x000cd, 0x000fb, 0x00059, 0x00116, 0x00103,
- 0x00108, 0x0012b, 0x0012d, 0x00188, 0x0012e, 0x0014c, 0x001c3, 0x00187,
- 0x001e7, 0x0006f, 0x00094, 0x00069, 0x001e6, 0x001ca, 0x00147, 0x00195,
- 0x000a7, 0x00213, 0x00209, 0x00303, 0x00295, 0x00289, 0x0028c, 0x0028d,
- 0x00312, 0x00330, 0x0029b, 0x00308, 0x00328, 0x0029a, 0x0025e, 0x003c5,
- 0x00384, 0x0039f, 0x00397, 0x00296, 0x0032e, 0x00332, 0x003c6, 0x003e6,
- 0x0012d, 0x000d1, 0x00402, 0x000dd, 0x00161, 0x0012b, 0x00127, 0x0045d,
- 0x00601, 0x004ab, 0x0045f, 0x00410, 0x004bf, 0x00528, 0x0045c, 0x00424,
- 0x00400, 0x00511, 0x00618, 0x0073d, 0x0063a, 0x00614, 0x0073c, 0x007c0,
- 0x007cf, 0x00802, 0x00966, 0x00964, 0x00951, 0x008a0, 0x00346, 0x00803,
- 0x00a52, 0x0024a, 0x007c1, 0x0063f, 0x00126, 0x00406, 0x00789, 0x008a2,
- 0x00960, 0x00967, 0x00c05, 0x00c70, 0x00c79, 0x00a5d, 0x00c26, 0x00c4d,
- 0x00372, 0x008a5, 0x00c08, 0x002c5, 0x00f11, 0x00cc4, 0x00f8e, 0x00e16,
- 0x00496, 0x00e77, 0x00f9c, 0x00c25, 0x00f1e, 0x00c27, 0x00f1f, 0x00e17,
- 0x00ccd, 0x00355, 0x00c09, 0x00c78, 0x00f90, 0x00521, 0x00357, 0x00356,
- 0x0068e, 0x00f9d, 0x00c04, 0x00e58, 0x00a20, 0x00a2c, 0x00c4c, 0x0052f,
- 0x00f8d, 0x01178, 0x01053, 0x01097, 0x0180f, 0x0180d, 0x012fb, 0x012aa,
- 0x0202a, 0x00a40, 0x018ed, 0x01ceb, 0x01455, 0x018e3, 0x012a1, 0x00354,
- 0x00353, 0x00f1c, 0x00c7b, 0x00c37, 0x0101d, 0x012cb, 0x01142, 0x0197d,
- 0x01095, 0x01e3b, 0x0186b, 0x00588, 0x01c2a, 0x014b8, 0x01e3a, 0x018ec,
- 0x01f46, 0x012fa, 0x00a53, 0x01ce8, 0x00a55, 0x01c29, 0x0117b, 0x01052,
- 0x012a0, 0x00589, 0x00950, 0x01c2b, 0x00a50, 0x0208b, 0x0180e, 0x02027,
- 0x02556, 0x01e20, 0x006e7, 0x01c28, 0x0197a, 0x00684, 0x020a2, 0x01f22,
- 0x03018, 0x039cf, 0x03e25, 0x02557, 0x0294c, 0x028a6, 0x00d11, 0x028a9,
- 0x02979, 0x00d46, 0x00a56, 0x039ce, 0x030cc, 0x0329a, 0x0149d, 0x0510f,
- 0x0451c, 0x02028, 0x03299, 0x01ced, 0x014b9, 0x00f85, 0x00c7a, 0x01800,
- 0x00341, 0x012ca, 0x039c8, 0x0329d, 0x00d0d, 0x03e20, 0x05144, 0x00d45,
- 0x030d0, 0x0186d, 0x030d5, 0x00d0f, 0x00d40, 0x04114, 0x020a1, 0x0297f,
- 0x03e24, 0x032f1, 0x04047, 0x030d4, 0x028a8, 0x00d0e, 0x0451d, 0x04044,
- 0x0297e, 0x04042, 0x030d2, 0x030cf, 0x03e21, 0x03e26, 0x028a5, 0x0451a,
- 0x00d48, 0x01a16, 0x00d44, 0x04518, 0x0149b, 0x039ca, 0x01498, 0x0403d,
- 0x0451b, 0x0149c, 0x032f3, 0x030cb, 0x08073, 0x03e22, 0x0529a, 0x020aa,
- 0x039cc, 0x0738a, 0x06530, 0x07389, 0x06193, 0x08071, 0x04043, 0x030ce,
- 0x05147, 0x07388, 0x05145, 0x08072, 0x04521, 0x00d47, 0x0297c, 0x030cd,
- 0x030ca, 0x0000b, 0x0000c, 0x00083, 0x000e4, 0x00048, 0x00102, 0x001cc,
- 0x001f5, 0x00097, 0x0020b, 0x00124, 0x00453, 0x00627, 0x00639, 0x00605,
- 0x00517, 0x001b8, 0x00663, 0x00667, 0x007c3, 0x00823, 0x00961, 0x00963,
- 0x00e5a, 0x00e59, 0x00a2b, 0x00cbf, 0x00292, 0x00a2d, 0x007d0, 0x00953,
- 0x00cc5, 0x00f84, 0x004ab, 0x014a7, 0x0068a, 0x0117a, 0x0052e, 0x01442,
- 0x0052c, 0x00c77, 0x00f8f, 0x004aa, 0x01094, 0x01801, 0x012c4, 0x0297b,
- 0x00952, 0x01f19, 0x006a5, 0x01149, 0x012c5, 0x01803, 0x022f2, 0x0329b,
- 0x04520, 0x0149e, 0x00d13, 0x01f16, 0x01ce9, 0x0101c, 0x006e6, 0x039c9,
- 0x06191, 0x07c8e, 0x06192, 0x0ca63, 0x039cd, 0x06190, 0x06884, 0x06885,
- 0x07382, 0x00d49, 0x00d41, 0x0450c, 0x0149a, 0x030d1, 0x08077, 0x03e23,
- 0x01a15, 0x0e701, 0x0e702, 0x08079, 0x0822a, 0x0a218, 0x07887, 0x0403f,
- 0x0520b, 0x0529b, 0x0e700, 0x04519, 0x00007, 0x000e0, 0x000d0, 0x0039b,
- 0x003e5, 0x00163, 0x0063e, 0x007c9, 0x00806, 0x00954, 0x01044, 0x01f44,
- 0x0197c, 0x01f45, 0x00a51, 0x01f47, 0x00951, 0x0052d, 0x02291, 0x0092f,
- 0x00a54, 0x00d12, 0x0297d, 0x00d0c, 0x01499, 0x0329e, 0x032f0, 0x02025,
- 0x039c6, 0x00a57, 0x03e46, 0x00d42, 0x0738b, 0x05146, 0x04046, 0x08078,
- 0x0510e, 0x07886, 0x02904, 0x04156, 0x04157, 0x06032, 0x030d3, 0x08bce,
- 0x04040, 0x0403e, 0x0a414, 0x10457, 0x08075, 0x06887, 0x07c8f, 0x039c7,
- 0x07387, 0x08070, 0x08bcf, 0x1482a, 0x10456, 0x1482b, 0x01a17, 0x06886,
- 0x0450d, 0x00013, 0x0006b, 0x00615, 0x0080b, 0x0082b, 0x00952, 0x00e5b,
- 0x018e2, 0x0186c, 0x01f18, 0x0329f, 0x00d43, 0x03e29, 0x05140, 0x05141,
- 0x0ca62, 0x06033, 0x03c42, 0x03e28, 0x0450f, 0x0a21a, 0x07384, 0x0a219,
- 0x0e703, 0x0a21b, 0x01a14, 0x07383, 0x045e6, 0x0007a, 0x0012c, 0x00ccc,
- 0x0068f, 0x01802, 0x00a52, 0x00953, 0x04045, 0x01a20, 0x0451f, 0x000a4,
- 0x00735, 0x01cec, 0x02029, 0x020a3, 0x0451e, 0x00069, 0x00c24, 0x02024,
- 0x032f2, 0x05142, 0x00196, 0x00523, 0x000a6, 0x0197b, 0x0030b, 0x0092e,
- 0x003e9, 0x03e27, 0x00160, 0x05143, 0x00652, 0x04041, 0x00734, 0x028a7,
- 0x0080f, 0x01483, 0x0097c, 0x00340, 0x0068b, 0x00522, 0x01054, 0x01096,
- 0x01f17, 0x0202b, 0x01cea, 0x020a0, 0x02978, 0x02026, 0x0297a, 0x039cb,
- 0x03e2b, 0x0149f, 0x0329c, 0x07385, 0x08074, 0x0450e, 0x03e2a, 0x05149,
- 0x08076, 0x07386, 0x05148,
-};
-
-static const uint8_t coef1_huffbits[555] = {
- 9, 5, 2, 4, 4, 5, 5, 5,
- 6, 6, 6, 6, 6, 7, 7, 7,
- 7, 7, 7, 7, 7, 7, 7, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 9, 8, 8, 8, 8, 9, 9, 9,
- 9, 9, 9, 9, 9, 9, 9, 9,
- 9, 10, 10, 10, 9, 9, 9, 9,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 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, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 11, 11, 11, 11, 11, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 13, 12, 12, 12, 12, 12, 12, 12,
- 13, 12, 12, 12, 12, 12, 12, 12,
- 12, 13, 12, 12, 12, 13, 13, 13,
- 13, 12, 12, 12, 12, 12, 12, 13,
- 12, 13, 13, 13, 13, 13, 13, 13,
- 14, 14, 13, 13, 13, 13, 13, 13,
- 13, 12, 12, 12, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 14, 13, 14, 13, 13, 13,
- 13, 13, 14, 13, 14, 14, 13, 14,
- 14, 13, 14, 13, 13, 14, 14, 13,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 15, 14, 14, 14, 14, 15, 15,
- 15, 14, 14, 13, 13, 12, 12, 13,
- 13, 13, 14, 14, 15, 14, 15, 15,
- 14, 13, 14, 15, 15, 15, 14, 14,
- 14, 14, 15, 14, 14, 15, 15, 15,
- 14, 15, 14, 14, 14, 14, 14, 15,
- 15, 16, 15, 15, 15, 14, 15, 15,
- 15, 15, 14, 14, 16, 14, 15, 14,
- 14, 15, 15, 15, 15, 16, 15, 14,
- 15, 15, 15, 16, 15, 15, 14, 14,
- 14, 4, 7, 8, 8, 9, 9, 9,
- 9, 10, 10, 11, 11, 11, 11, 11,
- 11, 12, 11, 11, 11, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 11, 12,
- 12, 12, 13, 13, 13, 13, 13, 13,
- 13, 12, 12, 13, 13, 13, 13, 14,
- 14, 13, 14, 13, 13, 13, 14, 14,
- 15, 15, 14, 13, 13, 13, 14, 14,
- 15, 15, 15, 16, 14, 15, 17, 17,
- 15, 15, 15, 15, 15, 14, 16, 14,
- 16, 16, 16, 16, 16, 16, 15, 15,
- 17, 15, 16, 15, 6, 8, 10, 10,
- 10, 11, 11, 11, 12, 12, 13, 13,
- 13, 13, 14, 13, 14, 13, 14, 14,
- 14, 14, 14, 15, 15, 14, 14, 14,
- 14, 14, 14, 15, 15, 15, 15, 16,
- 15, 15, 16, 15, 15, 15, 14, 16,
- 15, 15, 18, 17, 16, 17, 15, 14,
- 15, 16, 16, 19, 17, 19, 16, 17,
- 15, 7, 10, 11, 12, 12, 12, 12,
- 13, 13, 13, 14, 15, 14, 15, 15,
- 16, 15, 14, 14, 15, 16, 15, 16,
- 16, 16, 16, 15, 15, 7, 11, 12,
- 13, 13, 14, 14, 15, 15, 15, 8,
- 11, 13, 14, 14, 15, 9, 12, 14,
- 14, 15, 9, 13, 10, 13, 10, 14,
- 10, 14, 11, 15, 11, 15, 11, 14,
- 12, 15, 12, 13, 13, 13, 13, 13,
- 13, 14, 13, 14, 14, 14, 14, 14,
- 14, 15, 14, 15, 16, 15, 14, 15,
- 16, 15, 15,
-};
-
-static const uint32_t coef2_huffcodes[1336] = {
- 0x003e6, 0x000f6, 0x00000, 0x00002, 0x00006, 0x0000f, 0x0001b, 0x00028,
- 0x00039, 0x0003f, 0x0006b, 0x00076, 0x000b7, 0x000e8, 0x000ef, 0x00169,
- 0x001a7, 0x001d4, 0x001dc, 0x002c4, 0x00349, 0x00355, 0x00391, 0x003dc,
- 0x00581, 0x005b2, 0x00698, 0x0070c, 0x00755, 0x0073a, 0x00774, 0x007cf,
- 0x00b0a, 0x00b66, 0x00d2e, 0x00d5e, 0x00e1b, 0x00eac, 0x00e5a, 0x00f7e,
- 0x00fa1, 0x0163e, 0x01a37, 0x01a52, 0x01c39, 0x01ab3, 0x01d5f, 0x01cb6,
- 0x01f52, 0x01dd9, 0x02c04, 0x02c2e, 0x02c2d, 0x02c23, 0x03467, 0x034a3,
- 0x0351b, 0x03501, 0x03a5d, 0x0351c, 0x03875, 0x03dea, 0x0397b, 0x039db,
- 0x03df1, 0x039d8, 0x03bb4, 0x0580a, 0x0584d, 0x05842, 0x05b13, 0x058ea,
- 0x0697d, 0x06a06, 0x068cc, 0x06ac7, 0x06a96, 0x072f4, 0x07543, 0x072b4,
- 0x07d20, 0x0b003, 0x073b5, 0x07be6, 0x0d180, 0x07bd1, 0x07cb8, 0x07d06,
- 0x07d25, 0x0d2f2, 0x0d19a, 0x0d334, 0x0e1dc, 0x0d529, 0x0d584, 0x0e1d2,
- 0x0e5e3, 0x0eec4, 0x0e564, 0x0fa49, 0x16001, 0x0eedc, 0x0f7fa, 0x1a32c,
- 0x16131, 0x16003, 0x0f9c8, 0x1ef80, 0x1d2a0, 0x1aa4b, 0x0f7ce, 0x1abfe,
- 0x1aa50, 0x1a458, 0x1a816, 0x1cae4, 0x1d2fe, 0x1d52e, 0x1aa4c, 0x2c245,
- 0x1d2a1, 0x1a35d, 0x1ca1b, 0x1d5d8, 0x1f531, 0x1ca1c, 0x1f389, 0x1f4af,
- 0x3a5e7, 0x351fb, 0x2c24b, 0x34bce, 0x2c24d, 0x2c249, 0x2c24a, 0x72dfc,
- 0x357ef, 0x35002, 0x3a5e6, 0x39431, 0x5843b, 0x34a77, 0x58431, 0x3a5f3,
- 0x3a5dd, 0x3e5e5, 0x356bd, 0x3976e, 0x6a3d2, 0x3500d, 0x694c4, 0x580bd,
- 0x3e5e8, 0x74b95, 0x34a6e, 0x3977c, 0x39432, 0x5b0d2, 0x6a3d8, 0x580b8,
- 0x5b0cb, 0x5b0d7, 0x72dee, 0x72ded, 0x72dec, 0x74b9c, 0x3977f, 0x72dea,
- 0x74b9e, 0x7be7d, 0x580bf, 0x5b0d5, 0x7cba8, 0x74b91, 0x3e5dd, 0xb6171,
- 0xd46b3, 0xd46b9, 0x7cba1, 0x74b9f, 0x72de1, 0xe59f5, 0x3e5eb, 0x00004,
- 0x00015, 0x00038, 0x00075, 0x000e8, 0x001d3, 0x00347, 0x0039c, 0x00690,
- 0x0074a, 0x00b60, 0x00e93, 0x00f74, 0x0163d, 0x01a5a, 0x01d24, 0x01cbe,
- 0x01f4b, 0x03468, 0x03562, 0x03947, 0x03e82, 0x05804, 0x05b12, 0x05803,
- 0x0696d, 0x06a9e, 0x0697c, 0x06978, 0x06afb, 0x074b2, 0x072f5, 0x073c0,
- 0x07541, 0x06944, 0x074b7, 0x070d3, 0x07ba9, 0x0b0b1, 0x0d1af, 0x0e1dd,
- 0x0e5e2, 0x0e1a3, 0x0eec3, 0x1612f, 0x0e961, 0x0eeda, 0x0e78e, 0x0fa48,
- 0x1612c, 0x0e511, 0x0e565, 0x0e953, 0x1aa4a, 0x0e59d, 0x1d52c, 0x1a811,
- 0x1cae7, 0x1abfc, 0x1d52d, 0x1cacf, 0x1cf05, 0x2c254, 0x34a72, 0x1f4ac,
- 0x3976b, 0x34a71, 0x2c6d9, 0x2d873, 0x34a6a, 0x357e7, 0x3464c, 0x3e5f5,
- 0x58433, 0x1f53a, 0x3500a, 0x357ea, 0x34a73, 0x3942f, 0x357e5, 0x39775,
- 0x694cd, 0x39772, 0x7cba5, 0x6a3ef, 0x35483, 0x74b98, 0x5b0c1, 0x39770,
- 0x3a5d7, 0x39433, 0x39434, 0x694ce, 0x580be, 0x3e5ff, 0x6a3ec, 0xb616f,
- 0xd46b1, 0x6a3d1, 0x72de5, 0x74b6e, 0x72de9, 0x3e700, 0xd46b6, 0x6a3e9,
- 0x74b69, 0xe5675, 0xd46b8, 0x7cbaa, 0x3a5d1, 0x0000c, 0x0003c, 0x000eb,
- 0x001f1, 0x003a4, 0x006a8, 0x007d5, 0x00d43, 0x00e77, 0x016c5, 0x01cb1,
- 0x02c5d, 0x03a55, 0x03a56, 0x03e51, 0x03bb5, 0x05b0a, 0x06a9f, 0x074b8,
- 0x07d28, 0x0d187, 0x0d40e, 0x0d52e, 0x0d425, 0x0eae3, 0x0e1d3, 0x1612e,
- 0x0e59e, 0x0eec2, 0x0e578, 0x0e51a, 0x0e579, 0x0e515, 0x0e960, 0x0d183,
- 0x0d220, 0x0d2cb, 0x0e512, 0x16c3e, 0x16002, 0x16c42, 0x1cae9, 0x3461a,
- 0x1d2fa, 0x1a308, 0x1a849, 0x1cf07, 0x1f38f, 0x34b65, 0x2c253, 0x1ef9e,
- 0x1cbc3, 0x1cbc1, 0x2c255, 0x1f384, 0x58435, 0x2c5cd, 0x3a5f7, 0x2c252,
- 0x3959c, 0x2c6d8, 0x3a5d3, 0x6ad78, 0x6a3f2, 0x7cba9, 0xb6176, 0x72deb,
- 0x39764, 0x3e5f6, 0x3a5d8, 0x74a8c, 0x6a3e6, 0x694d1, 0x6ad79, 0x1a4592,
- 0xe59fb, 0x7cbb3, 0x5b0cd, 0x00017, 0x000b5, 0x002c3, 0x005b7, 0x00b1c,
- 0x00e5c, 0x0163f, 0x01ab2, 0x01efa, 0x0348a, 0x0396e, 0x058da, 0x06963,
- 0x06a30, 0x072cd, 0x073cf, 0x07ce7, 0x0d2ca, 0x0d2d8, 0x0e764, 0x0e794,
- 0x16008, 0x16167, 0x1617e, 0x1aa49, 0x1a30b, 0x1a813, 0x2c6da, 0x1a580,
- 0x1cbc2, 0x0f9ca, 0x1617f, 0x1d2fe, 0x0f7fc, 0x16c40, 0x0e513, 0x0eec5,
- 0x0f7c3, 0x1d508, 0x1a81e, 0x1d2fd, 0x39430, 0x35486, 0x3e5fd, 0x2c24c,
- 0x2c75a, 0x34a74, 0x3a5f4, 0x3464d, 0x694ca, 0x3a5f1, 0x1d509, 0x1d5c0,
- 0x34648, 0x3464e, 0x6a3d5, 0x6a3e8, 0x6a3e7, 0x5b0c3, 0x2c248, 0x1f38a,
- 0x3a5f2, 0x6a3e5, 0x00029, 0x00168, 0x0058c, 0x00b67, 0x00f9d, 0x01c3d,
- 0x01cbf, 0x02c20, 0x0351d, 0x03df6, 0x06af9, 0x072b5, 0x0b1d7, 0x0b0b2,
- 0x0d40a, 0x0d52b, 0x0e952, 0x0e797, 0x163c3, 0x1c3a0, 0x1f386, 0x1ca21,
- 0x34655, 0x2c247, 0x1f53b, 0x2c250, 0x2c24f, 0x1f385, 0x1ef5d, 0x1cf15,
- 0x1caea, 0x1ab0a, 0x1cf19, 0x1f53d, 0x1d5c2, 0x1d2fb, 0x1ef58, 0x34a78,
- 0x357ec, 0x1f533, 0x3a5e1, 0x694d2, 0x58482, 0x3a5ee, 0x2c6dc, 0x357eb,
- 0x5b0c4, 0x39778, 0x6a3e1, 0x7cbb4, 0x3a5e1, 0x74b68, 0x3a5ef, 0x3a5d2,
- 0x39424, 0x72de2, 0xe59f6, 0xe59f7, 0x3e702, 0x3e5ec, 0x1f38b, 0x0003b,
- 0x001f0, 0x00777, 0x00fa8, 0x01cb2, 0x02d84, 0x03a57, 0x03dd6, 0x06917,
- 0x06a11, 0x07d07, 0x0eae2, 0x0e796, 0x0f9c9, 0x0f7fb, 0x16166, 0x16160,
- 0x1ab1b, 0x1abfa, 0x2d87b, 0x1d2f7, 0x39768, 0x1f38c, 0x34653, 0x34651,
- 0x6a3d9, 0x35001, 0x3abbd, 0x38742, 0x39426, 0x34a76, 0x3a5ec, 0x34a75,
- 0x35000, 0x35488, 0x1cf10, 0x2c6db, 0x357ed, 0x357e8, 0x357e9, 0x3a5f0,
- 0x694c2, 0xb6178, 0x72df5, 0x39425, 0x3942b, 0x74b6d, 0x74b6f, 0xb6177,
- 0xb6179, 0x74b6a, 0xb6172, 0x58487, 0x3e5ee, 0x3e5ed, 0x72df2, 0x72df4,
- 0x7cbae, 0x6a3ca, 0x70e86, 0x34bcf, 0x6a3c8, 0x00059, 0x00384, 0x00d5b,
- 0x01c38, 0x03560, 0x0395b, 0x0584e, 0x06964, 0x073cd, 0x0b1e7, 0x0e798,
- 0x0e78d, 0x0fa43, 0x1a848, 0x1a32f, 0x1aa4e, 0x3464a, 0x1f4ab, 0x1f38d,
- 0x3a5eb, 0x3a5d4, 0x3548a, 0x6a3c7, 0x5b0d0, 0x6a3c5, 0x7cbb0, 0x694cb,
- 0x3a5e5, 0x3e5e2, 0x3942c, 0x2d872, 0x1f4ae, 0x3a5d5, 0x694d3, 0x58481,
- 0x35009, 0x39774, 0x58432, 0xb616c, 0x5b0db, 0x3548b, 0xb6174, 0x1d5d95,
- 0xb004c, 0x7cbb2, 0x3a5e5, 0x74a8f, 0xe59f9, 0x72df6, 0xe59fd, 0x7cbad,
- 0xd427d, 0x72cff, 0x3977a, 0x5b0d9, 0xb616d, 0xb616b, 0x1a4593, 0x7cbaf,
- 0x5b0da, 0x00071, 0x003eb, 0x01603, 0x02c6c, 0x03961, 0x068c8, 0x06a31,
- 0x072bd, 0x0d2c2, 0x0e51b, 0x0e5e6, 0x1abfb, 0x1d2ff, 0x1cae5, 0x1ef5c,
- 0x1ef5e, 0x1cf13, 0x34a6d, 0x3976d, 0xb616a, 0x3e5f2, 0x6a3c4, 0xb6169,
- 0x3e5dc, 0x580b9, 0x74b99, 0x75764, 0x58434, 0x3a5d9, 0x6945a, 0x69459,
- 0x3548c, 0x3a5e9, 0x69457, 0x72df1, 0x6945e, 0x6a35e, 0x3e701, 0xb6168,
- 0x5b0dd, 0x3a5de, 0x6a3c2, 0xd4278, 0x6a3cc, 0x72dfd, 0xb6165, 0x16009a,
- 0x7cbb1, 0xd427c, 0xb6162, 0xe765e, 0x1cecbe, 0x7cbb6, 0x69454, 0xb6160,
- 0xd427a, 0x1d5d96, 0xb1d6d, 0xe59f4, 0x72de8, 0x3a5db, 0x0007a, 0x006ae,
- 0x01c3c, 0x03aba, 0x058e9, 0x072cc, 0x0d2dd, 0x0d22d, 0x0eec1, 0x0eedb,
- 0x1d2a2, 0x1ef5b, 0x357e2, 0x3abbf, 0x1d2f9, 0x35004, 0x3a5dc, 0x351fc,
- 0x3976c, 0x6a3c6, 0x6a3cb, 0x3e5ea, 0xe59f3, 0x6a3ce, 0x69452, 0xe59f0,
- 0x74b90, 0xd4279, 0xd427b, 0x7cbb5, 0x5b0c5, 0x3a5e3, 0x3a5e2, 0x000d0,
- 0x00775, 0x01efe, 0x03dd5, 0x0728c, 0x07cb9, 0x0e1a2, 0x0ea85, 0x0eed8,
- 0x1a30a, 0x1aa4f, 0x3a5df, 0x35008, 0x3a5e0, 0x3e5f4, 0x3e5f7, 0xb1d6c,
- 0x5843e, 0x34a70, 0x72df8, 0x74b6b, 0xd427f, 0x72df0, 0x5b0bf, 0x5b0c0,
- 0xd46b0, 0x72def, 0xe59f8, 0x162e64, 0xb1d6f, 0x3a5e0, 0x39427, 0x69166,
- 0x6a3e2, 0x6a3e3, 0x74a8d, 0xd427e, 0x1d5d97, 0xd46b4, 0x5b0d8, 0x6a3d3,
- 0x000e0, 0x00b63, 0x034cc, 0x06a33, 0x073c9, 0x0e1a0, 0x0f7fd, 0x0f9cc,
- 0x1617d, 0x1caeb, 0x1f4a9, 0x3abb3, 0x69450, 0x39420, 0x39777, 0x3e5e0,
- 0x6a3d4, 0x6a3ed, 0xb6166, 0xe59f1, 0xb1d6e, 0xe5676, 0x6a3ea, 0xe5674,
- 0xb6163, 0xd46b7, 0x7cba6, 0xd46ba, 0x1d5d94, 0xb6164, 0x6a3f1, 0x7cba2,
- 0x69451, 0x72dfa, 0xd46bb, 0x72df7, 0x74b94, 0x1cecbf, 0xe59fa, 0x16009b,
- 0x6a3e4, 0x000e6, 0x00e94, 0x03876, 0x070ef, 0x0d52a, 0x16015, 0x16014,
- 0x1abf9, 0x1cf17, 0x34a79, 0x34650, 0x3e705, 0x6a3d0, 0x58430, 0x74b9d,
- 0x7be7e, 0x5b0be, 0x39773, 0x6a3de, 0x000fb, 0x00f7b, 0x03dd7, 0x07bd0,
- 0x0e59c, 0x0f9cd, 0x1cf18, 0x1d2ff, 0x34a7a, 0x39429, 0x3500c, 0x72de0,
- 0x69456, 0x7be7c, 0xd46b5, 0xd46b2, 0x6a3dd, 0x001a2, 0x0163b, 0x06913,
- 0x0b016, 0x0fa42, 0x1a32d, 0x1cf06, 0x34a7c, 0x34a7d, 0xb6161, 0x35481,
- 0x3e5fa, 0x7cba0, 0x7be7f, 0x7cba3, 0x7cba7, 0x5b0d3, 0x72de6, 0x6a3dc,
- 0x001a9, 0x01ab4, 0x06a34, 0x0d46a, 0x16130, 0x1ef5f, 0x1f532, 0x1f536,
- 0x3942e, 0x58436, 0x6a3db, 0x6945b, 0x001c9, 0x01ca0, 0x0728b, 0x0eed9,
- 0x1f539, 0x1ca1d, 0x39765, 0x39766, 0x58439, 0x6945d, 0x39767, 0x001d3,
- 0x01f2c, 0x07bfc, 0x16161, 0x34652, 0x3a5ed, 0x3548d, 0x58438, 0x6a3da,
- 0x002c1, 0x02c5e, 0x0d335, 0x1ab1a, 0x2d874, 0x35006, 0x35484, 0x5b0cc,
- 0x74b9a, 0x72df3, 0x6a3d6, 0x002da, 0x034b3, 0x0d5ae, 0x1caee, 0x2d871,
- 0x357e3, 0x74b97, 0x72df9, 0x580ba, 0x5b0d4, 0x0034d, 0x0354e, 0x0f750,
- 0x1cbc0, 0x3a5e7, 0x3a5e4, 0x00385, 0x03a58, 0x16c41, 0x2c5cf, 0x3e5e1,
- 0x74b6c, 0xe5677, 0x6a3df, 0x00390, 0x03e50, 0x163c2, 0x2d876, 0x35482,
- 0x5b0d6, 0x5843a, 0x0039f, 0x0585e, 0x1a583, 0x3500f, 0x74b93, 0x39771,
- 0x003e4, 0x06912, 0x16c43, 0x357e1, 0x0058a, 0x0696f, 0x1f538, 0x5b0c9,
- 0x6a3cf, 0x005b6, 0x06af8, 0x1f534, 0x58483, 0x6a3e0, 0x00695, 0x07d02,
- 0x1cae8, 0x58485, 0x006a2, 0x0754a, 0x357ee, 0x3977b, 0x00748, 0x074b2,
- 0x34a7b, 0x00729, 0x0b1e0, 0x34649, 0x3e5e3, 0x0073d, 0x0d2c4, 0x3e5e6,
- 0x007bb, 0x0b099, 0x39762, 0x5b0ce, 0x6945f, 0x007d1, 0x0d5ab, 0x39779,
- 0x007d3, 0x0d52f, 0x39763, 0x6945c, 0x00b1a, 0x0d2c5, 0x35489, 0x00d23,
- 0x0eaed, 0x3e5f8, 0x00d32, 0x16016, 0x3e5fb, 0x00d41, 0x0e768, 0x3a5ed,
- 0x00e1f, 0x16017, 0x58027, 0x00ead, 0x0fa07, 0x69455, 0x00e54, 0x1612b,
- 0x00e55, 0x1a581, 0x00f78, 0x1a32b, 0x580bc, 0x6a3ee, 0x00f79, 0x1abfd,
- 0x00f95, 0x1ab18, 0x6a3f0, 0x01637, 0x1aa4d, 0x0162d, 0x1f53c, 0x6a3f3,
- 0x01a31, 0x1a810, 0x39769, 0x01a50, 0x1caef, 0x01a36, 0x1a32e, 0x01a67,
- 0x1f38e, 0x01a85, 0x1ef59, 0x01aa6, 0x1ef83, 0x01d51, 0x2c012, 0x01d53,
- 0x2d879, 0x01d5e, 0x35005, 0x01cba, 0x1cf04, 0x69453, 0x01d2d, 0x351ff,
- 0x01f2d, 0x2d86f, 0x01f29, 0x35007, 0x02c22, 0x351fa, 0x02c03, 0x3a5ec,
- 0x02c5f, 0x3a5eb, 0x02c58, 0x34a6b, 0x03469, 0x356be, 0x02c59, 0x34a6c,
- 0x0346a, 0x3a5ea, 0x034bd, 0x034bf, 0x356bf, 0x0386a, 0x03ab9, 0x5843f,
- 0x0386b, 0x3a5f5, 0x03a4b, 0x39421, 0x03aa4, 0x3a5e9, 0x03a5a, 0x03960,
- 0x3977e, 0x03de9, 0x03958, 0x03df7, 0x039e1, 0x3e5e4, 0x0395f, 0x69458,
- 0x03e91, 0x03df2, 0x39428, 0x058f2, 0x03e80, 0x6a3c3, 0x03e93, 0x694c0,
- 0x058b8, 0x5b0ca, 0x0584f, 0x694c1, 0x058f1, 0x068d6, 0x06a10, 0x06ac3,
- 0x06a32, 0x070d2, 0x06911, 0x074b1, 0x07494, 0x06ad4, 0x06ad6, 0x072b8,
- 0x06afa, 0x074b3, 0x07540, 0x073ce, 0x0b005, 0x074b3, 0x07495, 0x074b9,
- 0x0d336, 0x07bff, 0x07763, 0x073c8, 0x07d29, 0x0b622, 0x0d221, 0x0d181,
- 0x0b1d1, 0x074b8, 0x0b1d0, 0x0d19b, 0x0d2c3, 0x0b172, 0x0d2dc, 0x0b623,
- 0x0d5aa, 0x0d426, 0x0d182, 0x0e795, 0x0e1d1, 0x0d337, 0x0e96c, 0x0e5e4,
- 0x0e514, 0x0eaee, 0x16000, 0x0e767, 0x0e1a1, 0x0e78f, 0x16004, 0x0f7c2,
- 0x0e799, 0x0e5e7, 0x0e566, 0x0e769, 0x0f751, 0x0eede, 0x0fa06, 0x16005,
- 0x0fa9f, 0x1a5e6, 0x0e766, 0x1636f, 0x0eedd, 0x0eec0, 0x1a309, 0x1ceca,
- 0x163cd, 0x0f9cb, 0x0eedf, 0x1a582, 0x1612d, 0x0e5e5, 0x1abf8, 0x1a30c,
- 0x1ca1f, 0x163cc, 0x1a35c, 0x1ca1e, 0x1aa51, 0x163ac, 0x1a84e, 0x1a53f,
- 0x1cf16, 0x1d2fc, 0x1a5b3, 0x1ab19, 0x1a81f, 0x1d5c3, 0x16c3f, 0x1d5c1,
- 0x1d2fc, 0x1f4aa, 0x1a812, 0x1f535, 0x1cf12, 0x1a817, 0x1617c, 0x1ab0b,
- 0x1d2f8, 0x1ef82, 0x2d87a, 0x1d52f, 0x1f530, 0x1aa48, 0x35487, 0x1d2fd,
- 0x1f4ad, 0x1cf11, 0x3461b, 0x35485, 0x1ca20, 0x1caed, 0x1cae6, 0x1abff,
- 0x3464f, 0x34a6f, 0x1ef81, 0x3464b, 0x39d96, 0x1f383, 0x1f537, 0x1cf14,
- 0x2c5ce, 0x3500e, 0x2c251, 0x1caec, 0x1f387, 0x34654, 0x357e4, 0x2d878,
- 0x3500b, 0x35480, 0x3a5e8, 0x3548e, 0x34b64, 0x1f4a8, 0x35003, 0x3e5df,
- 0x2d870, 0x357e6, 0x3e5f0, 0x1ef5a, 0x3a5ea, 0x1f388, 0x3e703, 0x2c24e,
- 0x3a5e2, 0x351fd, 0x2c6dd, 0x3e704, 0x351fe, 0x2d875, 0x5b0c7, 0x3976a,
- 0x3a5e6, 0x39423, 0x58480, 0x2c246, 0x3a5e3, 0x2d877, 0x3e5f1, 0x3abbe,
- 0x58489, 0x3e5f9, 0x357e0, 0x3abbc, 0x5b0c6, 0x69167, 0x69165, 0x3e5e9,
- 0x39422, 0x3976f, 0x3977d, 0x3e5de, 0x6a3c9, 0x58b98, 0x3a5f6, 0x3a5d0,
- 0x58486, 0x6a3c1, 0x3e5fc, 0x5b0dc, 0x3548f, 0x3942d, 0x694c9, 0x58484,
- 0x3a5e8, 0x74b9b, 0x74b96, 0x694d0, 0x58488, 0x3a5e4, 0x3942a, 0x72ec2,
- 0x39776, 0x5b0d1, 0x5b0cf, 0x3a5d6, 0xe59fc, 0x5b0c8, 0x3e5e7, 0x7cbb7,
- 0x70e87, 0x7cbab, 0x5b0c2, 0x694c3, 0x74a8e, 0x3e5f3, 0x6a3cd, 0x72dfe,
- 0x73b2e, 0x72ec0, 0x694c5, 0x58437, 0x694c8, 0x72dff, 0x39435, 0x5843d,
- 0x6a3d7, 0x72ec1, 0xd22c8, 0x694cf, 0xb6173, 0x3e5fe, 0x580bb, 0xe59f2,
- 0xb616e, 0xb6175, 0x3a5da, 0x5b0bd, 0x694cc, 0x5843c, 0x694c7, 0x74b92,
- 0x72ec3, 0x694c6, 0xb6170, 0x7cbac, 0xb1733, 0x7cba4, 0xb6167, 0x72de7,
- 0x72de4, 0x6a3c0, 0x3e5ef, 0x162e65, 0x72de3, 0x72dfb, 0x6a35f, 0x6a3eb,
-};
-
-static const uint8_t coef2_huffbits[1336] = {
- 11, 9, 2, 3, 4, 4, 5, 6,
- 6, 7, 7, 8, 8, 8, 9, 9,
- 9, 9, 10, 10, 10, 10, 11, 11,
- 11, 11, 11, 11, 11, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 16, 15, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 18, 17, 17, 17, 17,
- 17, 17, 17, 18, 18, 17, 17, 18,
- 17, 17, 18, 17, 18, 18, 18, 18,
- 19, 18, 18, 18, 18, 18, 18, 20,
- 18, 18, 18, 19, 19, 18, 19, 18,
- 19, 19, 18, 19, 19, 18, 19, 19,
- 19, 19, 18, 19, 19, 19, 19, 19,
- 19, 19, 20, 20, 20, 19, 19, 20,
- 19, 20, 19, 19, 20, 19, 19, 20,
- 20, 20, 20, 19, 20, 21, 19, 3,
- 5, 7, 8, 9, 9, 10, 11, 11,
- 12, 12, 12, 13, 13, 13, 13, 14,
- 14, 14, 14, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 16, 16,
- 15, 15, 15, 15, 16, 16, 16, 16,
- 17, 16, 17, 17, 16, 17, 17, 17,
- 17, 17, 17, 16, 17, 17, 17, 17,
- 18, 17, 17, 18, 18, 18, 18, 18,
- 19, 18, 18, 18, 18, 18, 18, 19,
- 19, 18, 18, 18, 18, 19, 18, 19,
- 19, 19, 20, 19, 18, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 20,
- 20, 19, 20, 19, 20, 19, 20, 19,
- 19, 21, 20, 20, 19, 4, 7, 8,
- 10, 11, 11, 12, 12, 13, 13, 14,
- 14, 14, 14, 15, 15, 15, 15, 15,
- 16, 16, 16, 16, 16, 16, 16, 17,
- 17, 17, 17, 17, 17, 17, 16, 16,
- 16, 16, 17, 17, 17, 17, 18, 18,
- 18, 17, 17, 18, 18, 18, 18, 18,
- 18, 18, 18, 18, 19, 18, 18, 18,
- 19, 18, 19, 19, 19, 20, 20, 20,
- 19, 19, 19, 19, 19, 19, 19, 21,
- 21, 20, 19, 5, 8, 10, 11, 12,
- 13, 13, 13, 14, 14, 15, 15, 15,
- 15, 16, 16, 16, 16, 16, 17, 17,
- 17, 17, 17, 17, 17, 17, 18, 17,
- 18, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 19, 18, 19, 18,
- 18, 18, 18, 18, 19, 18, 17, 17,
- 18, 18, 19, 19, 19, 19, 18, 18,
- 18, 19, 6, 9, 11, 12, 13, 13,
- 14, 14, 14, 15, 15, 16, 16, 16,
- 16, 16, 16, 17, 17, 17, 18, 18,
- 18, 18, 18, 18, 18, 18, 18, 18,
- 18, 17, 18, 18, 17, 18, 18, 18,
- 18, 18, 18, 19, 19, 18, 18, 18,
- 19, 19, 19, 20, 19, 19, 18, 19,
- 19, 20, 21, 21, 19, 19, 18, 6,
- 10, 12, 13, 14, 14, 14, 15, 15,
- 15, 16, 16, 17, 17, 17, 17, 17,
- 17, 17, 18, 18, 19, 18, 18, 18,
- 19, 18, 18, 18, 19, 18, 18, 18,
- 18, 18, 18, 18, 18, 18, 18, 18,
- 19, 20, 20, 19, 19, 19, 19, 20,
- 20, 19, 20, 19, 19, 19, 20, 20,
- 20, 19, 19, 18, 19, 7, 10, 12,
- 13, 14, 15, 15, 15, 16, 16, 17,
- 17, 17, 17, 17, 17, 18, 18, 18,
- 18, 19, 18, 19, 19, 19, 20, 19,
- 18, 19, 19, 18, 18, 19, 19, 19,
- 18, 19, 19, 20, 19, 18, 20, 21,
- 20, 20, 19, 19, 21, 20, 21, 20,
- 20, 20, 19, 19, 20, 20, 21, 20,
- 19, 7, 11, 13, 14, 15, 15, 15,
- 16, 16, 17, 17, 17, 17, 18, 18,
- 18, 18, 18, 19, 20, 19, 19, 20,
- 19, 19, 19, 19, 19, 19, 19, 19,
- 18, 18, 19, 20, 19, 19, 19, 20,
- 19, 19, 19, 20, 19, 20, 20, 21,
- 20, 20, 20, 21, 22, 20, 19, 20,
- 20, 21, 20, 21, 20, 19, 8, 11,
- 13, 14, 15, 16, 16, 16, 17, 17,
- 17, 18, 18, 18, 18, 18, 19, 18,
- 19, 19, 19, 19, 21, 19, 19, 21,
- 19, 20, 20, 20, 19, 18, 18, 8,
- 12, 14, 15, 16, 16, 16, 16, 17,
- 17, 17, 19, 18, 18, 19, 19, 20,
- 19, 18, 20, 19, 20, 20, 19, 19,
- 20, 20, 21, 21, 20, 19, 19, 19,
- 19, 19, 19, 20, 21, 20, 19, 19,
- 8, 12, 14, 15, 16, 16, 17, 17,
- 17, 18, 18, 18, 19, 19, 19, 19,
- 19, 19, 20, 21, 20, 21, 19, 21,
- 20, 20, 20, 20, 21, 20, 19, 20,
- 19, 20, 20, 20, 19, 22, 21, 21,
- 19, 9, 12, 14, 15, 16, 17, 17,
- 17, 18, 18, 18, 19, 19, 19, 19,
- 20, 19, 19, 19, 9, 13, 15, 16,
- 17, 17, 18, 18, 18, 19, 18, 20,
- 19, 20, 20, 20, 19, 9, 13, 15,
- 16, 17, 17, 18, 18, 18, 20, 18,
- 19, 20, 20, 20, 20, 19, 20, 19,
- 9, 13, 15, 16, 17, 18, 18, 18,
- 19, 19, 19, 19, 10, 14, 16, 17,
- 18, 18, 19, 19, 19, 19, 19, 10,
- 14, 16, 17, 18, 18, 18, 19, 19,
- 10, 14, 16, 17, 18, 18, 18, 19,
- 19, 20, 19, 10, 14, 16, 18, 18,
- 18, 19, 20, 19, 19, 10, 14, 17,
- 18, 18, 18, 10, 15, 17, 18, 19,
- 19, 21, 19, 11, 15, 17, 18, 18,
- 19, 19, 11, 15, 17, 18, 19, 19,
- 11, 15, 17, 18, 11, 15, 18, 19,
- 19, 11, 15, 18, 19, 19, 11, 16,
- 18, 19, 11, 15, 18, 19, 11, 16,
- 18, 12, 16, 18, 19, 12, 16, 19,
- 12, 16, 19, 19, 19, 12, 16, 19,
- 12, 16, 19, 19, 12, 16, 18, 12,
- 16, 19, 12, 17, 19, 12, 17, 19,
- 12, 17, 19, 12, 17, 19, 13, 17,
- 13, 17, 13, 17, 19, 19, 13, 17,
- 13, 17, 19, 13, 17, 13, 18, 19,
- 13, 17, 19, 13, 18, 13, 17, 13,
- 18, 13, 18, 13, 18, 13, 18, 13,
- 18, 13, 18, 14, 18, 19, 14, 18,
- 14, 18, 14, 18, 14, 18, 14, 19,
- 14, 19, 14, 18, 14, 18, 14, 18,
- 14, 19, 14, 14, 18, 14, 14, 19,
- 14, 18, 14, 19, 14, 19, 14, 15,
- 19, 15, 15, 15, 15, 19, 15, 19,
- 15, 15, 19, 15, 15, 19, 15, 19,
- 15, 19, 15, 19, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 16,
- 15, 15, 15, 16, 16, 16, 15, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 17, 16, 16, 16, 17,
- 17, 16, 17, 17, 16, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 18,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 18, 17, 17, 18, 17, 17, 17, 17,
- 18, 18, 17, 17, 17, 17, 17, 17,
- 17, 18, 17, 18, 18, 17, 17, 17,
- 18, 18, 18, 17, 18, 17, 18, 18,
- 18, 18, 18, 18, 18, 18, 18, 17,
- 18, 18, 18, 18, 19, 18, 18, 18,
- 18, 18, 18, 18, 18, 18, 18, 18,
- 18, 18, 18, 18, 18, 18, 18, 19,
- 18, 18, 19, 18, 18, 18, 19, 18,
- 19, 18, 18, 19, 18, 18, 19, 19,
- 19, 19, 19, 18, 19, 18, 19, 18,
- 19, 19, 18, 18, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 18, 19,
- 19, 19, 19, 19, 18, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 20,
- 19, 19, 19, 19, 21, 19, 19, 20,
- 19, 20, 19, 19, 19, 19, 19, 20,
- 20, 20, 19, 19, 19, 20, 19, 19,
- 19, 20, 20, 19, 20, 19, 19, 21,
- 20, 20, 19, 19, 19, 19, 19, 19,
- 20, 19, 20, 20, 20, 20, 20, 20,
- 20, 19, 19, 21, 20, 20, 19, 19,
-};
-
-static const uint32_t coef3_huffcodes[1072] = {
- 0x001b2, 0x00069, 0x00000, 0x00004, 0x00006, 0x0000e, 0x00014, 0x00019,
- 0x00016, 0x0002b, 0x00030, 0x0003d, 0x0003c, 0x0005a, 0x0005f, 0x0006d,
- 0x0007e, 0x0005f, 0x0007f, 0x000b6, 0x000bc, 0x000d8, 0x000f2, 0x000fe,
- 0x000bc, 0x000fc, 0x00161, 0x0016e, 0x00174, 0x00176, 0x001a2, 0x001e3,
- 0x001f3, 0x00174, 0x0017a, 0x001ea, 0x002a8, 0x002c4, 0x002e6, 0x00314,
- 0x00346, 0x00367, 0x003e9, 0x002e5, 0x002ee, 0x003d6, 0x00555, 0x00554,
- 0x00557, 0x005c3, 0x005d6, 0x006e0, 0x0062f, 0x006e2, 0x00799, 0x00789,
- 0x007fa, 0x005ce, 0x007fe, 0x005ec, 0x007cc, 0x007af, 0x00aa7, 0x00b19,
- 0x00b94, 0x00b85, 0x00b9f, 0x00c48, 0x00c45, 0x00dd8, 0x00c4c, 0x00c4b,
- 0x00d99, 0x00d1f, 0x00dc2, 0x00f95, 0x00fa2, 0x00bb5, 0x00b9f, 0x00f5d,
- 0x00bbf, 0x00f47, 0x0154a, 0x00fd5, 0x00f45, 0x00f7f, 0x0160d, 0x01889,
- 0x01757, 0x01722, 0x018b3, 0x0172d, 0x01a39, 0x01a18, 0x01bb3, 0x01b30,
- 0x01e63, 0x0173c, 0x01b35, 0x01723, 0x01e80, 0x01fee, 0x01761, 0x01ffc,
- 0x01f7f, 0x02c7c, 0x01fa1, 0x0177b, 0x01755, 0x0175a, 0x01fa6, 0x02eab,
- 0x0310a, 0x02c69, 0x03669, 0x03127, 0x03103, 0x02e43, 0x03662, 0x03165,
- 0x03124, 0x0313b, 0x03111, 0x03668, 0x0343b, 0x03c52, 0x03efc, 0x02e6c,
- 0x03fda, 0x03ef8, 0x02e7b, 0x03ee2, 0x03cc5, 0x03d72, 0x058c0, 0x03df8,
- 0x02ea9, 0x03e7e, 0x0556d, 0x05c82, 0x03d71, 0x03e7b, 0x03c42, 0x058d7,
- 0x03f4e, 0x06200, 0x03d70, 0x05cb2, 0x05c96, 0x05cb0, 0x03f45, 0x05cb1,
- 0x02e6d, 0x03110, 0x02f68, 0x05c90, 0x07ca6, 0x07c88, 0x06204, 0x062c8,
- 0x078a6, 0x07986, 0x079d5, 0x0b1ad, 0x07989, 0x0b079, 0x05cdd, 0x0aad4,
- 0x05de8, 0x07dcd, 0x07987, 0x05d67, 0x05d99, 0x0b91d, 0x07cf1, 0x05d9b,
- 0x079d7, 0x0b07b, 0x05c85, 0x05d9a, 0x07dcc, 0x07ebf, 0x07dce, 0x07dfb,
- 0x07ec0, 0x07d1a, 0x07a07, 0x05c84, 0x0c471, 0x07cf2, 0x0baef, 0x0b9d2,
- 0x05deb, 0x07bd6, 0x0b845, 0x05d98, 0x0b91a, 0x0bae8, 0x0c4e0, 0x0dc31,
- 0x0f93d, 0x0bbce, 0x0d1d2, 0x0f7a9, 0x0d9b9, 0x0bbcb, 0x0b900, 0x0aad7,
- 0x0babd, 0x0c4e1, 0x0f46f, 0x0c588, 0x0c58b, 0x160e6, 0x0bbcf, 0x0bac3,
- 0x0f945, 0x0f7a3, 0x0d1c1, 0x0fb8e, 0x0f7a4, 0x0fb8c, 0x0f40c, 0x0c473,
- 0x0fd72, 0x0bbcd, 0x0fffa, 0x0f940, 0x0bbc9, 0x0f7a8, 0x1a1ed, 0x0bbc5,
- 0x1f26f, 0x163fd, 0x160c7, 0x1a1f5, 0x0f947, 0x163fc, 0x154b3, 0x0fff6,
- 0x163f6, 0x160e9, 0x1a1f0, 0x0bab9, 0x0baba, 0x17086, 0x0b903, 0x0fd75,
- 0x0f308, 0x176f3, 0x163ff, 0x0fd7d, 0x1bb78, 0x163fb, 0x188db, 0x1a1f7,
- 0x154b2, 0x172fd, 0x163f4, 0x1bb73, 0x172ff, 0x0babc, 0x0f97d, 0x1a1f3,
- 0x1bb6d, 0x1ffd5, 0x1a1f4, 0x1f272, 0x17380, 0x17382, 0x1ffe7, 0x0bac8,
- 0x0bbc4, 0x188d3, 0x160e0, 0x0fd7b, 0x1725f, 0x172f5, 0x1bb79, 0x1fad9,
- 0x1f269, 0x188d0, 0x0bac4, 0x0bac5, 0x31185, 0x188d2, 0x188cc, 0x31187,
- 0x3e7fe, 0x188d1, 0x1bb6c, 0x1f268, 0x1fad2, 0x1ffd9, 0x1a1ea, 0x1bb68,
- 0x1facb, 0x3fdb2, 0x1e81a, 0x188ce, 0x172fb, 0x1a1ef, 0x1face, 0x1bb70,
- 0x0bac1, 0x1bb6b, 0x172f8, 0x1bb66, 0x1ffdf, 0x1bb6a, 0x1ffd7, 0x1f266,
- 0x176f8, 0x37653, 0x1fa7e, 0x31182, 0x1fac8, 0x2c7e3, 0x370ee, 0x176ec,
- 0x176e9, 0x2e4bc, 0x160c5, 0x3765a, 0x3ce9c, 0x17373, 0x176e8, 0x188d4,
- 0x176f1, 0x176ef, 0x37659, 0x1bb7c, 0x1ffde, 0x176f2, 0x3118b, 0x2c7d4,
- 0x37651, 0x5ce9f, 0x37650, 0x31191, 0x3f4f6, 0x3f4f5, 0x7a06c, 0x1fac1,
- 0x5c97b, 0x2c7e0, 0x79d3a, 0x3e7fd, 0x2c7df, 0x3f4f0, 0x7a06d, 0x376c1,
- 0x79d3b, 0x00004, 0x00014, 0x00059, 0x000ab, 0x000b8, 0x00177, 0x001f5,
- 0x001f2, 0x00315, 0x003fc, 0x005bd, 0x0062d, 0x006e8, 0x007dd, 0x00b04,
- 0x007cd, 0x00b1e, 0x00d1e, 0x00f15, 0x00f3b, 0x00f41, 0x01548, 0x018b0,
- 0x0173b, 0x01884, 0x01a1c, 0x01bb4, 0x01f25, 0x017b5, 0x0176d, 0x01ef8,
- 0x02e73, 0x03107, 0x03125, 0x03105, 0x02e49, 0x03ce8, 0x03ef9, 0x03e5e,
- 0x02e72, 0x03471, 0x03fd9, 0x0623f, 0x078a0, 0x06867, 0x05cb3, 0x06272,
- 0x068ec, 0x06e9a, 0x079d4, 0x06e98, 0x0b1aa, 0x06e1a, 0x07985, 0x068ee,
- 0x06e9b, 0x05c88, 0x0b1ac, 0x07dfa, 0x05d65, 0x07cf0, 0x07cbf, 0x0c475,
- 0x160eb, 0x1bb7e, 0x0f7a6, 0x1fedd, 0x160e3, 0x0fffb, 0x0fb8d, 0x0fff9,
- 0x0d1c0, 0x0c58c, 0x1a1e9, 0x0bab8, 0x0f5cf, 0x0fff5, 0x376c5, 0x1a1ec,
- 0x160ed, 0x1fede, 0x1fac9, 0x1a1eb, 0x1f224, 0x176ee, 0x0fd79, 0x17080,
- 0x17387, 0x1bb7a, 0x1ffe9, 0x176f7, 0x17385, 0x17781, 0x2c7d5, 0x17785,
- 0x1ffe3, 0x163f5, 0x1fac2, 0x3e7f9, 0x3118d, 0x3fdb1, 0x1ffe2, 0x1f226,
- 0x3118a, 0x2c7d9, 0x31190, 0x3118c, 0x3f4f3, 0x1bb7f, 0x1bb72, 0x31184,
- 0xb92f4, 0x3e7fb, 0x6e1d9, 0x1faca, 0x62300, 0x3fdb8, 0x3d037, 0x3e7fc,
- 0x62301, 0x3f4f2, 0x1f26a, 0x0000e, 0x00063, 0x000f8, 0x001ee, 0x00377,
- 0x003f7, 0x006e3, 0x005cc, 0x00b05, 0x00dd2, 0x00fd4, 0x0172e, 0x0172a,
- 0x01e23, 0x01f2d, 0x01763, 0x01769, 0x0176c, 0x02e75, 0x03104, 0x02ec1,
- 0x03e58, 0x0583f, 0x03f62, 0x03f44, 0x058c5, 0x0623c, 0x05cf4, 0x07bd7,
- 0x05d9d, 0x0aad2, 0x05d66, 0x0b1a9, 0x0b078, 0x07cfe, 0x0b918, 0x0c46f,
- 0x0b919, 0x0b847, 0x06e1b, 0x0b84b, 0x0aad8, 0x0fd74, 0x172f4, 0x17081,
- 0x0f97c, 0x1f273, 0x0f7a0, 0x0fd7c, 0x172f7, 0x0fd7a, 0x1bb77, 0x172fe,
- 0x1f270, 0x0fd73, 0x1bb7b, 0x1a1bc, 0x1bb7d, 0x0bbc3, 0x172f6, 0x0baeb,
- 0x0fb8f, 0x3f4f4, 0x3fdb4, 0x376c8, 0x3e7fa, 0x1ffd0, 0x62303, 0xb92f5,
- 0x1f261, 0x31189, 0x3fdb5, 0x2c7db, 0x376c9, 0x1fad6, 0x1fad1, 0x00015,
- 0x000f0, 0x002e0, 0x0058e, 0x005d7, 0x00c4d, 0x00fa1, 0x00bdb, 0x01756,
- 0x01f70, 0x02c19, 0x0313c, 0x0370f, 0x03cc0, 0x02ea8, 0x058c6, 0x058c7,
- 0x02eb7, 0x058d0, 0x07d18, 0x0aa58, 0x0b848, 0x05d9e, 0x05d6c, 0x0b84c,
- 0x0c589, 0x0b901, 0x163f8, 0x0bac9, 0x0b9c5, 0x0f93c, 0x188d8, 0x0bbc7,
- 0x160ec, 0x0fd6f, 0x188d9, 0x160ea, 0x0f7a7, 0x0f944, 0x0baab, 0x0dc3a,
- 0x188cf, 0x176fb, 0x2c7d8, 0x2c7d7, 0x1bb75, 0x5ce9e, 0x62302, 0x370ed,
- 0x176f4, 0x1ffd1, 0x370ef, 0x3f4f8, 0x376c7, 0x1ffe1, 0x376c6, 0x176ff,
- 0x6e1d8, 0x176f6, 0x17087, 0x0f5cd, 0x00035, 0x001a0, 0x0058b, 0x00aac,
- 0x00b9a, 0x0175f, 0x01e22, 0x01e8c, 0x01fb2, 0x0310b, 0x058d1, 0x0552e,
- 0x05c27, 0x0686e, 0x07ca7, 0x0c474, 0x0dc33, 0x07bf2, 0x05de9, 0x07a35,
- 0x0baaa, 0x0b9eb, 0x0fb95, 0x0b9b8, 0x17381, 0x1f262, 0x188cd, 0x17088,
- 0x172fa, 0x0f7a2, 0x1fad3, 0x0bac0, 0x3765c, 0x1fedf, 0x1f225, 0x1fad4,
- 0x2c7da, 0x5ce9d, 0x3e7f8, 0x1e203, 0x188d7, 0x00054, 0x002c0, 0x007a1,
- 0x00f78, 0x01b36, 0x01fa3, 0x0313a, 0x03436, 0x0343a, 0x07d1d, 0x07bd8,
- 0x05cdf, 0x0b846, 0x0b189, 0x0d9b8, 0x0fff8, 0x0d9be, 0x0c58a, 0x05dea,
- 0x0d1d3, 0x160e4, 0x1f26b, 0x188da, 0x1e202, 0x2c7d2, 0x163fe, 0x31193,
- 0x17782, 0x376c2, 0x2c7d1, 0x3fdb0, 0x3765d, 0x2c7d0, 0x1fad0, 0x1e201,
- 0x188dd, 0x2c7e2, 0x37657, 0x37655, 0x376c4, 0x376c0, 0x176ea, 0x0006f,
- 0x003cf, 0x00dd5, 0x01f23, 0x02c61, 0x02ed0, 0x05d54, 0x0552d, 0x07883,
- 0x0b1a8, 0x0b91c, 0x0babf, 0x0b902, 0x0f7aa, 0x0f7a5, 0x1a1e8, 0x1ffd6,
- 0x0babe, 0x1a1bf, 0x163f3, 0x1ffd8, 0x1fad7, 0x1f275, 0x1ffdc, 0x0007d,
- 0x005bc, 0x01549, 0x02a99, 0x03def, 0x06273, 0x079d6, 0x07d1b, 0x0aad3,
- 0x0d0fc, 0x2c7dd, 0x188d6, 0x0bac2, 0x2c7e1, 0x1bb76, 0x1a1bd, 0x31186,
- 0x0fd78, 0x1a1be, 0x31183, 0x3fdb6, 0x3f4f1, 0x37652, 0x1fad5, 0x3f4f9,
- 0x3e7ff, 0x5ce9c, 0x3765b, 0x31188, 0x17372, 0x000bd, 0x0078b, 0x01f21,
- 0x03c43, 0x03ded, 0x0aad6, 0x07ec1, 0x0f942, 0x05c86, 0x17089, 0x0babb,
- 0x1ffe8, 0x2c7de, 0x1f26e, 0x1fac4, 0x3f4f7, 0x37656, 0x1fa7d, 0x376c3,
- 0x3fdb3, 0x3118f, 0x1fac6, 0x000f8, 0x007ed, 0x01efd, 0x03e7a, 0x05c91,
- 0x0aad9, 0x0baec, 0x0dc32, 0x0f46e, 0x1e200, 0x176fa, 0x3765e, 0x3fdb7,
- 0x2c7d6, 0x3fdb9, 0x37654, 0x37658, 0x3118e, 0x1ffdb, 0x000f6, 0x00c43,
- 0x03106, 0x068ef, 0x0b84d, 0x0b188, 0x0bbcc, 0x1f264, 0x1bb69, 0x17386,
- 0x1fac0, 0x00171, 0x00f39, 0x03e41, 0x068ed, 0x0d9bc, 0x0f7a1, 0x1bb67,
- 0x1ffdd, 0x176f9, 0x001b9, 0x00f7d, 0x03f63, 0x0d0fd, 0x0b9ea, 0x188dc,
- 0x1fac3, 0x1a1f2, 0x31192, 0x1ffe4, 0x001f6, 0x01754, 0x06865, 0x0f309,
- 0x160e5, 0x176f5, 0x3765f, 0x1facc, 0x001e9, 0x01a1a, 0x06201, 0x0f105,
- 0x176f0, 0x002df, 0x01756, 0x05d6d, 0x163fa, 0x176ed, 0x00342, 0x02e40,
- 0x0d0ff, 0x17082, 0x003cd, 0x02a98, 0x0fffc, 0x2c7dc, 0x1fa7f, 0x003fe,
- 0x03764, 0x0fffd, 0x176fc, 0x1fac5, 0x002f7, 0x02ed1, 0x0fb97, 0x0058a,
- 0x02edc, 0x0bbc8, 0x005d4, 0x0623d, 0x160e8, 0x0062e, 0x05830, 0x163f9,
- 0x006eb, 0x06205, 0x1f274, 0x007de, 0x062c9, 0x1f265, 0x005c9, 0x05cde,
- 0x1ffd3, 0x005d4, 0x07988, 0x007ce, 0x0b849, 0x00b1b, 0x05c89, 0x1fac7,
- 0x00b93, 0x05c83, 0x00b9e, 0x0f14f, 0x00c4a, 0x0b9c7, 0x00dd4, 0x0c470,
- 0x1f271, 0x00f38, 0x0fb96, 0x176eb, 0x00fa0, 0x163f7, 0x00bb2, 0x0b91b,
- 0x00bbe, 0x0f102, 0x00f44, 0x0f946, 0x1facd, 0x00f79, 0x0d9bd, 0x0154d,
- 0x0bbc6, 0x00fd2, 0x160e7, 0x0172b, 0x188cb, 0x0175e, 0x0fd76, 0x0175c,
- 0x1bb71, 0x0189f, 0x1a1ee, 0x01f24, 0x1a1f6, 0x01ba7, 0x0bbca, 0x01f7d,
- 0x0ffff, 0x01f2e, 0x1bb65, 0x01bb5, 0x172f9, 0x01fef, 0x1f26c, 0x01f3e,
- 0x0fd77, 0x01762, 0x1bb6e, 0x01ef9, 0x172fc, 0x01fa0, 0x02ab7, 0x02e4a,
- 0x1f267, 0x01fb3, 0x1ffda, 0x02e42, 0x03101, 0x17780, 0x0313d, 0x03475,
- 0x17784, 0x03126, 0x1facf, 0x03c51, 0x17783, 0x03e40, 0x1ffe5, 0x03663,
- 0x1ffe0, 0x03e8f, 0x1f26d, 0x0343c, 0x03cc1, 0x176fd, 0x03e45, 0x02ec0,
- 0x03f61, 0x03dee, 0x03fd8, 0x0583e, 0x02e45, 0x03e59, 0x03d02, 0x05ce8,
- 0x05568, 0x176fe, 0x02f69, 0x1fad8, 0x058c1, 0x05c83, 0x1ffe6, 0x06271,
- 0x06e1c, 0x062c7, 0x068e1, 0x0552f, 0x06864, 0x06866, 0x06e99, 0x05cbc,
- 0x07ca5, 0x078a1, 0x05c82, 0x07dcf, 0x0623b, 0x0623e, 0x068e8, 0x07a36,
- 0x05d9c, 0x0b077, 0x07cf3, 0x07a34, 0x07ca4, 0x07d19, 0x079d2, 0x07d1c,
- 0x07bd9, 0x0b84a, 0x0fb94, 0x0aad5, 0x0dc30, 0x07bf3, 0x0baee, 0x0b07a,
- 0x0c472, 0x0b91e, 0x0d9ba, 0x05d9f, 0x0d0fe, 0x0b9c6, 0x05c87, 0x0f14e,
- 0x0baed, 0x0b92e, 0x0f103, 0x0b9c4, 0x0fb91, 0x0d9bb, 0x0b1ab, 0x0c58d,
- 0x0fffe, 0x0f93b, 0x0f941, 0x0baea, 0x0b91f, 0x0f5cc, 0x0d9bf, 0x0f943,
- 0x0f104, 0x1f260, 0x0fb92, 0x0f93f, 0x0f3a6, 0x0bac7, 0x0f7ab, 0x0bac6,
- 0x17383, 0x0fd6d, 0x0bae9, 0x0fd6e, 0x1e74f, 0x188ca, 0x1f227, 0x0fb93,
- 0x0fb90, 0x0fff7, 0x17085, 0x17083, 0x160e1, 0x17084, 0x0f93e, 0x160e2,
- 0x160c6, 0x1a1f1, 0x1bb6f, 0x17384, 0x0fd70, 0x1f263, 0x188d5, 0x173a6,
- 0x0f5ce, 0x163f2, 0x0fd71, 0x1ffd2, 0x160c4, 0x1ffd4, 0x2c7d3, 0x1bb74,
-};
-
-static const uint8_t coef3_huffbits[1072] = {
- 9, 7, 2, 3, 4, 4, 5, 5,
- 6, 6, 6, 6, 7, 7, 7, 7,
- 7, 8, 8, 8, 8, 8, 8, 8,
- 9, 9, 9, 9, 9, 9, 9, 9,
- 9, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 11, 11, 11, 11, 11,
- 11, 11, 11, 11, 11, 11, 11, 11,
- 11, 12, 11, 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, 14, 13, 14, 14, 13, 14, 13,
- 13, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 15,
- 14, 14, 15, 14, 14, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 14, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 14, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 16, 15, 16, 16, 16,
- 16, 15, 15, 16, 16, 16, 16, 16,
- 15, 16, 16, 16, 15, 16, 15, 15,
- 16, 15, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 17, 16, 17, 16, 17, 17, 16,
- 17, 16, 17, 16, 16, 17, 17, 17,
- 16, 17, 16, 16, 17, 16, 17, 16,
- 17, 17, 16, 16, 17, 17, 17, 17,
- 17, 17, 17, 17, 16, 17, 17, 16,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 16, 18, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 16, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 18,
- 17, 17, 17, 17, 18, 17, 17, 18,
- 19, 17, 17, 17, 18, 17, 17, 17,
- 18, 18, 18, 17, 17, 17, 18, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 18, 18, 18, 18, 18, 18, 18, 18,
- 18, 18, 17, 18, 18, 18, 18, 17,
- 18, 18, 18, 17, 17, 18, 18, 18,
- 18, 19, 18, 18, 19, 19, 20, 18,
- 19, 18, 19, 19, 18, 19, 20, 18,
- 19, 4, 6, 7, 8, 9, 9, 9,
- 10, 10, 10, 11, 11, 11, 11, 12,
- 12, 12, 12, 12, 12, 13, 13, 13,
- 13, 13, 13, 13, 13, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 16, 15, 15, 15,
- 15, 16, 16, 15, 16, 16, 15, 16,
- 17, 17, 17, 17, 17, 16, 16, 16,
- 16, 16, 17, 17, 17, 16, 18, 17,
- 17, 17, 18, 17, 17, 18, 17, 17,
- 17, 17, 17, 18, 17, 18, 18, 18,
- 17, 17, 18, 19, 18, 18, 17, 17,
- 18, 18, 18, 18, 19, 17, 17, 18,
- 20, 19, 19, 18, 19, 18, 19, 19,
- 19, 19, 17, 5, 7, 9, 10, 10,
- 11, 11, 12, 12, 12, 13, 13, 13,
- 13, 13, 14, 14, 14, 14, 14, 15,
- 14, 15, 15, 15, 15, 15, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 15, 16, 16, 17, 17, 17,
- 16, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 16,
- 16, 19, 18, 18, 19, 17, 19, 20,
- 17, 18, 18, 18, 18, 18, 18, 6,
- 8, 10, 11, 12, 12, 12, 13, 13,
- 13, 14, 14, 14, 14, 15, 15, 15,
- 15, 15, 15, 16, 16, 16, 16, 16,
- 16, 17, 17, 17, 16, 16, 17, 17,
- 17, 17, 17, 17, 17, 16, 16, 16,
- 17, 18, 18, 18, 17, 19, 19, 18,
- 18, 17, 18, 19, 18, 17, 18, 18,
- 19, 18, 17, 17, 6, 9, 11, 12,
- 13, 13, 13, 14, 14, 14, 15, 15,
- 15, 15, 15, 16, 16, 16, 16, 16,
- 16, 17, 16, 17, 17, 17, 17, 17,
- 17, 17, 18, 17, 18, 17, 17, 18,
- 18, 19, 19, 17, 17, 7, 10, 12,
- 13, 13, 14, 14, 14, 14, 15, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 17, 17, 17, 17, 18, 17, 18,
- 18, 18, 18, 18, 18, 18, 18, 17,
- 17, 18, 18, 18, 18, 18, 18, 7,
- 10, 12, 13, 14, 15, 15, 15, 15,
- 16, 16, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 18, 17, 17, 8,
- 11, 13, 14, 15, 15, 15, 15, 16,
- 16, 18, 17, 17, 18, 17, 17, 18,
- 17, 17, 18, 18, 19, 18, 18, 19,
- 19, 19, 18, 18, 18, 8, 11, 13,
- 14, 15, 16, 16, 16, 16, 17, 17,
- 17, 18, 17, 18, 19, 18, 18, 18,
- 18, 18, 18, 8, 12, 14, 15, 15,
- 16, 16, 16, 17, 17, 18, 18, 18,
- 18, 18, 18, 18, 18, 17, 9, 12,
- 14, 15, 16, 16, 17, 17, 17, 17,
- 18, 9, 12, 14, 15, 16, 17, 17,
- 17, 18, 9, 13, 15, 16, 17, 17,
- 18, 17, 18, 17, 9, 13, 15, 16,
- 17, 18, 18, 18, 10, 13, 15, 16,
- 18, 10, 14, 16, 17, 18, 10, 14,
- 16, 17, 10, 14, 16, 18, 18, 10,
- 14, 16, 18, 18, 11, 15, 16, 11,
- 15, 17, 11, 15, 17, 11, 15, 17,
- 11, 15, 17, 11, 15, 17, 12, 16,
- 17, 12, 15, 12, 16, 12, 16, 18,
- 12, 16, 12, 16, 12, 16, 12, 16,
- 17, 12, 16, 18, 12, 17, 13, 16,
- 13, 16, 13, 16, 18, 13, 16, 13,
- 17, 13, 17, 13, 17, 13, 17, 13,
- 17, 13, 17, 13, 17, 13, 17, 13,
- 16, 13, 17, 13, 17, 13, 17, 14,
- 17, 14, 17, 14, 17, 14, 14, 14,
- 17, 14, 17, 14, 14, 18, 14, 14,
- 18, 14, 18, 14, 18, 14, 17, 14,
- 17, 14, 17, 14, 14, 18, 14, 15,
- 15, 15, 14, 15, 15, 14, 15, 15,
- 15, 18, 15, 18, 15, 15, 17, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 16, 15, 15, 15, 15, 16,
- 16, 16, 16, 16, 15, 15, 15, 15,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 17, 16, 16,
- 16, 17, 16, 16, 16, 17, 17, 17,
- 17, 17, 16, 17, 17, 17, 17, 16,
- 16, 16, 17, 17, 17, 17, 16, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 18, 17,
-};
-
-static const uint32_t coef4_huffcodes[476] = {
- 0x00f01, 0x0001e, 0x00000, 0x00004, 0x00006, 0x0000d, 0x0000a, 0x00017,
- 0x0001d, 0x00017, 0x0002c, 0x00031, 0x00039, 0x0003e, 0x00039, 0x0005a,
- 0x00066, 0x00070, 0x0007b, 0x00070, 0x00077, 0x000af, 0x000c9, 0x000f2,
- 0x000f4, 0x000b2, 0x000e3, 0x0015b, 0x0015d, 0x00181, 0x0019d, 0x001e3,
- 0x001c5, 0x002b5, 0x002db, 0x00338, 0x003c3, 0x003cc, 0x003f0, 0x002cd,
- 0x003fa, 0x003a1, 0x005b4, 0x00657, 0x007ab, 0x0074d, 0x0074c, 0x00ac1,
- 0x00ac5, 0x0076b, 0x00ca8, 0x00f04, 0x00f00, 0x00fe3, 0x00f3c, 0x00f10,
- 0x00f39, 0x00fe6, 0x00e26, 0x00e90, 0x016c5, 0x01827, 0x01954, 0x015c5,
- 0x01958, 0x01f8a, 0x01c4a, 0x02b0f, 0x02b41, 0x02b0e, 0x033c6, 0x03050,
- 0x01c4f, 0x02d88, 0x0305c, 0x03c18, 0x02b4f, 0x02cc2, 0x03a47, 0x05680,
- 0x0569d, 0x06442, 0x06443, 0x06446, 0x0656e, 0x06444, 0x07120, 0x0748a,
- 0x0c1ba, 0x07e22, 0x07aa6, 0x07f25, 0x07aa7, 0x07e20, 0x0c11b, 0x0c118,
- 0x07aa5, 0x0ad0a, 0x0f389, 0x19ebb, 0x0caad, 0x0fe42, 0x0fe40, 0x16c34,
- 0x2b4e5, 0x33d65, 0x16c30, 0x1e7ae, 0x1e25c, 0x18370, 0x1e703, 0x19eba,
- 0x16c37, 0x0e234, 0x16c6e, 0x00004, 0x0002a, 0x00061, 0x00075, 0x000cb,
- 0x000ff, 0x00190, 0x001eb, 0x001d1, 0x002b9, 0x00307, 0x00339, 0x0033f,
- 0x003fb, 0x003b4, 0x0060c, 0x00679, 0x00645, 0x0067d, 0x0078a, 0x007e3,
- 0x00749, 0x00ac4, 0x00ad2, 0x00ae3, 0x00c10, 0x00c16, 0x00ad1, 0x00cf4,
- 0x00fe2, 0x01586, 0x00e9d, 0x019f1, 0x01664, 0x01e26, 0x01d38, 0x02b4d,
- 0x033c5, 0x01fc2, 0x01fc3, 0x01d28, 0x03c1d, 0x0598e, 0x0f094, 0x07aa4,
- 0x0ad38, 0x0ac0c, 0x0c11a, 0x079ea, 0x0c881, 0x0fe44, 0x0b635, 0x0ac0d,
- 0x0b61e, 0x05987, 0x07121, 0x0f382, 0x0f387, 0x0e237, 0x0fe47, 0x0f383,
- 0x0f091, 0x0f385, 0x0e233, 0x182ee, 0x19eb8, 0x1663e, 0x0f093, 0x00014,
- 0x00058, 0x00159, 0x00167, 0x00300, 0x003d4, 0x005b5, 0x0079d, 0x0076a,
- 0x00b67, 0x00b60, 0x00f05, 0x00cf0, 0x00f17, 0x00e95, 0x01822, 0x01913,
- 0x016c2, 0x0182f, 0x01959, 0x01fcb, 0x01e27, 0x01c40, 0x033c7, 0x01e7b,
- 0x01c49, 0x02d89, 0x01e23, 0x01660, 0x03f12, 0x02cc6, 0x033e1, 0x05b34,
- 0x0609a, 0x06569, 0x07488, 0x07e21, 0x0cf5f, 0x0712c, 0x0389d, 0x067cf,
- 0x07f28, 0x1663f, 0x33d67, 0x1663d, 0x1e25d, 0x3c1ab, 0x15c44, 0x16c36,
- 0x0001f, 0x000ec, 0x00323, 0x005b2, 0x0079f, 0x00ac2, 0x00f16, 0x00e9e,
- 0x01956, 0x01e0f, 0x019ea, 0x01666, 0x02b89, 0x02b02, 0x02d8c, 0x03c1b,
- 0x03c19, 0x032b5, 0x03f9c, 0x02ccf, 0x03897, 0x05b35, 0x0ad02, 0x07f29,
- 0x06441, 0x03884, 0x07888, 0x0784e, 0x06568, 0x0c1bb, 0x05986, 0x067cc,
- 0x0fe49, 0x0fe48, 0x0c1bc, 0x0fe41, 0x18371, 0x1663c, 0x0e231, 0x0711e,
- 0x0ad09, 0x0f092, 0x0002d, 0x001db, 0x00781, 0x00c1a, 0x00f55, 0x01580,
- 0x01ea8, 0x02d9b, 0x032af, 0x03f16, 0x03c1c, 0x07834, 0x03c45, 0x0389c,
- 0x067ce, 0x06445, 0x0c1b9, 0x07889, 0x07f3a, 0x0784f, 0x07f2b, 0x0ad0b,
- 0x0f090, 0x0c11d, 0x0e94e, 0x0711f, 0x0e9f1, 0x0f38e, 0x079e9, 0x0ad03,
- 0x0f09b, 0x0caae, 0x0fe46, 0x2b4e6, 0x0e9f0, 0x19eb6, 0x67ac1, 0x67ac0,
- 0x33d66, 0x0f388, 0x00071, 0x003a0, 0x00ca9, 0x01829, 0x01d39, 0x02b43,
- 0x02cc4, 0x06554, 0x0f09a, 0x0b61f, 0x067cd, 0x0711c, 0x0b636, 0x07f2a,
- 0x0b634, 0x0c11f, 0x0cf5e, 0x0b61d, 0x0f06b, 0x0caab, 0x0c1be, 0x0e94c,
- 0x0f099, 0x182ed, 0x0e94f, 0x0c119, 0x0e232, 0x2b4e4, 0x0f38a, 0x19eb4,
- 0x1e25f, 0x0e94d, 0x000b7, 0x00785, 0x016cc, 0x03051, 0x033c4, 0x0656f,
- 0x03891, 0x0711d, 0x0caaf, 0x0f097, 0x07489, 0x0f098, 0x0c880, 0x0caaa,
- 0x0f386, 0x19eb7, 0x16c6f, 0x0f384, 0x182e8, 0x182e9, 0x0e230, 0x1e700,
- 0x33d62, 0x33d63, 0x33d64, 0x16c33, 0x0e216, 0x000fd, 0x00c15, 0x01665,
- 0x03c4a, 0x07f3b, 0x07896, 0x0c11c, 0x0e215, 0x16c32, 0x0f38b, 0x0f38d,
- 0x182ea, 0x1e701, 0x712df, 0x15c46, 0x00194, 0x00fe0, 0x03f13, 0x0748b,
- 0x0f096, 0x0cf80, 0x1e25e, 0xe25bd, 0x33d61, 0x16c31, 0x001f9, 0x01912,
- 0x05710, 0x0f3d0, 0x0c1bf, 0x00301, 0x01e24, 0x0ad08, 0x003cd, 0x01c41,
- 0x0c1bd, 0x00563, 0x03a52, 0x0f3d1, 0x00570, 0x02cce, 0x0e217, 0x0067b,
- 0x0655d, 0x0074b, 0x06447, 0x00c12, 0x074fb, 0x00f08, 0x0b61c, 0x00e22,
- 0x0fe43, 0x016c7, 0x01836, 0x019f2, 0x01c43, 0x01d3f, 0x01fcf, 0x02b4c,
- 0x0304c, 0x032b6, 0x03a46, 0x05607, 0x03f17, 0x02cc5, 0x0609b, 0x0655c,
- 0x07e23, 0x067c1, 0x07f26, 0x07f27, 0x0f095, 0x0e9f3, 0x0cf81, 0x0c11e,
- 0x0caac, 0x0f38f, 0x0e9f2, 0x074fa, 0x0e236, 0x0fe45, 0x1c428, 0x0e235,
- 0x182ef, 0x19eb5, 0x0f3d6, 0x182ec, 0x16c35, 0x0f38c, 0x2b4e7, 0x15c47,
- 0xe25bc, 0x1e702, 0x1c4b6, 0x0e25a, 0x3c1aa, 0x15c45, 0x1c429, 0x19eb9,
- 0x1e7af, 0x182eb, 0x1e0d4, 0x3896e,
-};
-
-static const uint8_t coef4_huffbits[476] = {
- 12, 6, 2, 3, 4, 4, 5, 5,
- 5, 6, 6, 6, 6, 6, 7, 7,
- 7, 7, 7, 8, 8, 8, 8, 8,
- 8, 9, 9, 9, 9, 9, 9, 9,
- 10, 10, 10, 10, 10, 10, 10, 11,
- 10, 11, 11, 11, 11, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 13, 13, 13, 13, 13, 13,
- 13, 13, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 16, 16,
- 16, 15, 15, 15, 15, 15, 16, 16,
- 15, 16, 16, 17, 16, 16, 16, 17,
- 18, 18, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 4, 6, 7, 8, 8,
- 8, 9, 9, 10, 10, 10, 10, 10,
- 10, 11, 11, 11, 11, 11, 11, 11,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 13, 13, 13, 14, 13, 14, 14,
- 14, 13, 13, 14, 14, 16, 16, 15,
- 16, 16, 16, 15, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 17, 16, 16,
- 16, 16, 17, 17, 17, 18, 16, 5,
- 8, 9, 10, 10, 10, 11, 11, 12,
- 12, 12, 12, 12, 12, 13, 13, 13,
- 13, 13, 13, 13, 13, 14, 14, 13,
- 14, 14, 13, 14, 14, 15, 14, 15,
- 15, 15, 16, 15, 16, 16, 15, 15,
- 15, 18, 18, 18, 17, 18, 17, 17,
- 6, 9, 10, 11, 11, 12, 12, 13,
- 13, 13, 13, 14, 14, 14, 14, 14,
- 14, 14, 14, 15, 15, 15, 16, 15,
- 15, 15, 15, 15, 15, 16, 16, 15,
- 16, 16, 16, 16, 17, 18, 17, 16,
- 16, 16, 7, 10, 11, 12, 12, 13,
- 13, 14, 14, 14, 14, 15, 14, 15,
- 15, 15, 16, 15, 15, 15, 15, 16,
- 16, 16, 17, 16, 17, 16, 15, 16,
- 16, 16, 16, 18, 17, 17, 19, 19,
- 18, 16, 7, 11, 12, 13, 14, 14,
- 15, 15, 16, 16, 15, 16, 16, 15,
- 16, 16, 16, 16, 16, 16, 16, 17,
- 16, 17, 17, 16, 17, 18, 16, 17,
- 17, 17, 8, 11, 13, 14, 14, 15,
- 15, 16, 16, 16, 16, 16, 16, 16,
- 16, 17, 17, 16, 17, 17, 17, 17,
- 18, 18, 18, 17, 17, 8, 12, 14,
- 14, 15, 15, 16, 17, 17, 16, 16,
- 17, 17, 20, 17, 9, 12, 14, 16,
- 16, 16, 17, 21, 18, 17, 9, 13,
- 15, 16, 16, 10, 13, 16, 10, 14,
- 16, 11, 15, 16, 11, 15, 17, 11,
- 15, 12, 15, 12, 16, 12, 16, 13,
- 16, 13, 13, 13, 14, 14, 13, 14,
- 14, 14, 15, 15, 14, 15, 15, 15,
- 15, 15, 15, 15, 16, 17, 16, 16,
- 16, 16, 17, 16, 17, 16, 18, 17,
- 17, 17, 16, 17, 17, 16, 18, 17,
- 21, 17, 18, 17, 18, 17, 18, 17,
- 17, 17, 17, 19,
-};
-
-static const uint32_t coef5_huffcodes[435] = {
- 0x00347, 0x0000b, 0x00001, 0x00001, 0x0000c, 0x00004, 0x00010, 0x00015,
- 0x0001f, 0x0000b, 0x00023, 0x00026, 0x00029, 0x00035, 0x00037, 0x00001,
- 0x00015, 0x0001a, 0x0001d, 0x0001c, 0x0001e, 0x0004e, 0x00049, 0x00051,
- 0x00078, 0x00004, 0x00000, 0x00008, 0x0000d, 0x0007b, 0x00005, 0x00032,
- 0x00095, 0x00091, 0x00096, 0x000a1, 0x000d9, 0x00003, 0x00019, 0x00061,
- 0x00066, 0x00060, 0x00017, 0x0000e, 0x00063, 0x001a0, 0x001b7, 0x001e6,
- 0x001e7, 0x001b6, 0x00018, 0x001e8, 0x00038, 0x00031, 0x00005, 0x0003d,
- 0x00027, 0x001ea, 0x0001a, 0x000c5, 0x000f9, 0x000ff, 0x000db, 0x00250,
- 0x000fc, 0x0025c, 0x00008, 0x00075, 0x003d7, 0x003d3, 0x001b0, 0x0007c,
- 0x003ca, 0x00036, 0x00189, 0x004a6, 0x004a2, 0x004fb, 0x000c0, 0x0007f,
- 0x0009a, 0x00311, 0x0006e, 0x0009b, 0x0068c, 0x006c0, 0x00484, 0x00012,
- 0x000c3, 0x0094f, 0x00979, 0x009f9, 0x00d09, 0x00da6, 0x00da8, 0x00901,
- 0x000c1, 0x00373, 0x00d08, 0x009fa, 0x00d8b, 0x00d85, 0x00d86, 0x000df,
- 0x006e2, 0x000ce, 0x00f24, 0x009fe, 0x001f7, 0x007c1, 0x000cf, 0x009fc,
- 0x009ff, 0x00d89, 0x00da9, 0x009fd, 0x001f8, 0x01a36, 0x0128c, 0x0129d,
- 0x01a37, 0x00196, 0x003ea, 0x00f8b, 0x00d93, 0x01e45, 0x01e58, 0x01e4b,
- 0x01e59, 0x013f1, 0x00309, 0x00265, 0x00308, 0x0243a, 0x027e1, 0x00f89,
- 0x00324, 0x03cbc, 0x03c86, 0x03695, 0x0243c, 0x0243b, 0x0243e, 0x01e4a,
- 0x003a5, 0x03468, 0x03428, 0x03c84, 0x027e0, 0x025e2, 0x01880, 0x00197,
- 0x00325, 0x03cb7, 0x0791e, 0x007ec, 0x06c75, 0x004c8, 0x04bc7, 0x004c6,
- 0x00983, 0x0481e, 0x01b53, 0x0251b, 0x01b58, 0x00984, 0x04fa8, 0x03cbb,
- 0x00f8a, 0x00322, 0x0346a, 0x0243d, 0x00326, 0x03469, 0x0481f, 0x0481d,
- 0x00746, 0x09032, 0x01b50, 0x01d13, 0x0d8e4, 0x0481b, 0x06c74, 0x0796b,
- 0x07969, 0x00985, 0x0d8e3, 0x00986, 0x00fa2, 0x01301, 0x06c7c, 0x00987,
- 0x03cb8, 0x0f4af, 0x00e88, 0x1b1c0, 0x00fce, 0x033eb, 0x03f6a, 0x03f69,
- 0x00fcf, 0x0791f, 0x004c9, 0x04871, 0x00fcd, 0x00982, 0x00fcc, 0x00fa3,
- 0x01d12, 0x0796c, 0x01b47, 0x00321, 0x0796a, 0x0d8e2, 0x04872, 0x04873,
- 0x0000e, 0x00014, 0x0000a, 0x000a0, 0x00012, 0x0007d, 0x001a2, 0x0003b,
- 0x0025f, 0x000dd, 0x0027c, 0x00343, 0x00368, 0x0036b, 0x0003e, 0x001fa,
- 0x00485, 0x001b3, 0x0007f, 0x001b1, 0x0019e, 0x004ba, 0x007ad, 0x00339,
- 0x00066, 0x007a4, 0x00793, 0x006c6, 0x0007e, 0x000f1, 0x00372, 0x009fb,
- 0x00d83, 0x00d8a, 0x00947, 0x009f4, 0x001d0, 0x01b09, 0x01b4b, 0x007ec,
- 0x003e1, 0x000ca, 0x003ec, 0x02539, 0x04fa9, 0x01b57, 0x03429, 0x03d2a,
- 0x00d97, 0x003a7, 0x00dc0, 0x00d96, 0x00dc1, 0x007eb, 0x03cba, 0x00c43,
- 0x00c41, 0x01b52, 0x007ef, 0x00323, 0x03cb9, 0x03c83, 0x007d0, 0x007ed,
- 0x06c7f, 0x09033, 0x03f6c, 0x36383, 0x1e95d, 0x06c78, 0x00747, 0x01b51,
- 0x00022, 0x00016, 0x00039, 0x00252, 0x00079, 0x00486, 0x00338, 0x00369,
- 0x00d88, 0x00026, 0x00d87, 0x00f4b, 0x00d82, 0x00027, 0x001e1, 0x01a15,
- 0x007c7, 0x012f0, 0x001e0, 0x006d0, 0x01a16, 0x01e44, 0x01e5f, 0x03690,
- 0x00d90, 0x00c42, 0x00daf, 0x00d92, 0x00f80, 0x00cfb, 0x0342f, 0x0487f,
- 0x01b46, 0x07968, 0x00d95, 0x00d91, 0x01b55, 0x03f68, 0x04bc6, 0x03cbd,
- 0x00f81, 0x00320, 0x00069, 0x000fe, 0x006d5, 0x0033f, 0x000de, 0x007c6,
- 0x01e40, 0x00d94, 0x00f88, 0x03c8e, 0x03694, 0x00dae, 0x00dad, 0x00267,
- 0x003a6, 0x00327, 0x0487e, 0x007ee, 0x00749, 0x004c7, 0x03692, 0x01b56,
- 0x00fd1, 0x07a56, 0x06c77, 0x09031, 0x00748, 0x06c7a, 0x0796d, 0x033ea,
- 0x06c76, 0x00fd0, 0x36382, 0x1e417, 0x00745, 0x04faf, 0x0d8e1, 0x03f6b,
- 0x1e95c, 0x04fad, 0x0009e, 0x004bd, 0x0067c, 0x01b08, 0x003eb, 0x01b45,
- 0x03691, 0x0d8e5, 0x07904, 0x00981, 0x007ea, 0x019f4, 0x06c7d, 0x04fab,
- 0x04fac, 0x06c7e, 0x01300, 0x06c7b, 0x0006f, 0x003f7, 0x03c85, 0x004c4,
- 0x0001e, 0x006e1, 0x03693, 0x01b44, 0x00241, 0x01e46, 0x0019d, 0x00266,
- 0x004bb, 0x02538, 0x007ac, 0x01b54, 0x00902, 0x04870, 0x00da7, 0x00900,
- 0x00185, 0x06c79, 0x006e3, 0x003e9, 0x01e94, 0x003ed, 0x003f2, 0x0342e,
- 0x0346b, 0x0251a, 0x004c5, 0x01881, 0x0481c, 0x01b59, 0x03c87, 0x04fae,
- 0x007e9, 0x03f6d, 0x0f20a, 0x09030, 0x04faa, 0x0d8e6, 0x03f6f, 0x0481a,
- 0x03f6e, 0x1e416, 0x0d8e7,
-};
-
-static const uint8_t coef5_huffbits[435] = {
- 10, 4, 2, 4, 4, 5, 5, 5,
- 5, 6, 6, 6, 6, 6, 6, 7,
- 7, 7, 7, 7, 7, 7, 7, 7,
- 7, 8, 8, 8, 8, 7, 8, 8,
- 8, 8, 8, 8, 8, 9, 9, 9,
- 9, 9, 9, 9, 9, 9, 9, 9,
- 9, 9, 10, 9, 10, 10, 10, 10,
- 10, 9, 10, 10, 10, 10, 10, 10,
- 10, 10, 11, 11, 10, 10, 11, 11,
- 10, 11, 11, 11, 11, 11, 12, 12,
- 12, 12, 12, 12, 11, 11, 11, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 13,
- 13, 13, 12, 12, 13, 13, 13, 12,
- 12, 12, 12, 12, 13, 13, 13, 13,
- 13, 14, 14, 14, 14, 13, 13, 13,
- 13, 13, 14, 14, 14, 14, 14, 14,
- 15, 14, 14, 14, 14, 14, 14, 13,
- 14, 14, 14, 14, 14, 14, 15, 14,
- 15, 14, 15, 15, 15, 15, 15, 15,
- 16, 15, 15, 14, 15, 16, 15, 14,
- 14, 15, 14, 14, 15, 14, 15, 15,
- 15, 16, 15, 17, 16, 15, 15, 15,
- 15, 16, 16, 16, 16, 17, 15, 16,
- 14, 16, 16, 17, 16, 16, 16, 16,
- 16, 15, 15, 15, 16, 16, 16, 16,
- 17, 15, 15, 15, 15, 16, 15, 15,
- 4, 7, 8, 8, 9, 9, 9, 10,
- 10, 10, 10, 10, 10, 10, 11, 11,
- 11, 11, 11, 11, 11, 11, 11, 12,
- 12, 11, 11, 11, 12, 12, 12, 12,
- 12, 12, 12, 12, 13, 13, 13, 13,
- 12, 13, 14, 14, 15, 15, 14, 14,
- 14, 14, 14, 14, 14, 15, 14, 14,
- 14, 15, 15, 15, 14, 14, 15, 15,
- 15, 16, 16, 18, 17, 15, 15, 15,
- 6, 9, 10, 10, 11, 11, 12, 12,
- 12, 13, 12, 12, 12, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 14,
- 14, 14, 14, 14, 14, 14, 14, 15,
- 15, 15, 14, 14, 15, 16, 15, 14,
- 14, 15, 7, 10, 11, 12, 13, 13,
- 13, 14, 14, 14, 14, 14, 14, 14,
- 14, 15, 15, 15, 15, 15, 14, 15,
- 16, 15, 15, 16, 15, 15, 15, 16,
- 15, 16, 18, 17, 15, 15, 16, 16,
- 17, 15, 8, 11, 13, 13, 14, 15,
- 14, 16, 15, 16, 15, 15, 15, 15,
- 15, 15, 17, 15, 9, 12, 14, 15,
- 10, 13, 14, 15, 10, 13, 11, 14,
- 11, 14, 11, 15, 12, 15, 12, 12,
- 13, 15, 13, 14, 13, 14, 14, 14,
- 14, 14, 15, 15, 15, 15, 14, 15,
- 15, 16, 16, 16, 15, 16, 16, 15,
- 16, 17, 16,
-};
-
-static const uint16_t levels0[60] = {
-317, 92, 62, 60, 19, 17, 10, 7,
- 6, 5, 5, 3, 3, 3, 2, 2,
- 2, 2, 2, 2, 2, 1, 2, 2,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1,
-};
-
-static const uint16_t levels1[40] = {
-311, 91, 61, 28, 10, 6, 5, 2,
- 2, 2, 2, 2, 2, 2, 2, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
-};
-
-static const uint16_t levels2[340] = {
-181,110, 78, 63, 61, 62, 60, 61,
- 33, 41, 41, 19, 17, 19, 12, 11,
- 9, 11, 10, 6, 8, 7, 6, 4,
- 5, 5, 4, 4, 3, 4, 3, 5,
- 3, 4, 3, 3, 3, 3, 3, 3,
- 2, 2, 4, 2, 3, 2, 3, 3,
- 2, 2, 2, 2, 2, 2, 2, 2,
- 3, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 1, 2, 1, 2, 2,
- 2, 2, 1, 2, 1, 1, 1, 2,
- 2, 1, 2, 1, 2, 2, 2, 2,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1,
-};
-
-static const uint16_t levels3[180] = {
-351,122, 76, 61, 41, 42, 24, 30,
- 22, 19, 11, 9, 10, 8, 5, 5,
- 4, 5, 5, 3, 3, 3, 3, 3,
- 3, 3, 2, 2, 3, 2, 2, 2,
- 3, 3, 2, 2, 2, 3, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 1, 1,
- 2, 2, 1, 2, 1, 2, 2, 2,
- 2, 2, 2, 1, 2, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 2,
- 2, 1, 2, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1,
-};
-
-static const uint16_t levels4[70] = {
-113, 68, 49, 42, 40, 32, 27, 15,
- 10, 5, 3, 3, 3, 3, 2, 2,
- 2, 2, 2, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1,
-};
-
-static const uint16_t levels5[40] = {
-214, 72, 42, 40, 18, 4, 4, 2,
- 2, 2, 2, 2, 1, 1, 2, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
-};
-
-static const CoefVLCTable coef_vlcs[6] = {
- {
- sizeof(coef0_huffbits), coef0_huffcodes, coef0_huffbits, levels0,
- },
- {
- sizeof(coef1_huffbits), coef1_huffcodes, coef1_huffbits, levels1,
- },
- {
- sizeof(coef2_huffbits), coef2_huffcodes, coef2_huffbits, levels2,
- },
- {
- sizeof(coef3_huffbits), coef3_huffcodes, coef3_huffbits, levels3,
- },
- {
- sizeof(coef4_huffbits), coef4_huffcodes, coef4_huffbits, levels4,
- },
- {
- sizeof(coef5_huffbits), coef5_huffcodes, coef5_huffbits, levels5,
- },
-};
diff --git a/src/libffmpeg/libavcodec/wmadec.c b/src/libffmpeg/libavcodec/wmadec.c
deleted file mode 100644
index bbf4970ce..000000000
--- a/src/libffmpeg/libavcodec/wmadec.c
+++ /dev/null
@@ -1,1337 +0,0 @@
-/*
- * WMA compatible decoder
- * Copyright (c) 2002 The FFmpeg Project.
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/**
- * @file wmadec.c
- * 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
- * (ASF/AVI/WAV). WMA v2 is identified by audio format 0x161.
- *
- * To use this decoder, a calling application must supply the extra data
- * bytes provided with the WMA data. These are the extra, codec-specific
- * bytes at the end of a WAVEFORMATEX data structure. Transmit these bytes
- * to the decoder using the extradata[_size] fields in AVCodecContext. There
- * should be 4 extra bytes for v1 data and 6 extra bytes for v2 data.
- */
-
-#include "avcodec.h"
-#include "bitstream.h"
-#include "dsputil.h"
-
-/* size of blocks */
-#define BLOCK_MIN_BITS 7
-#define BLOCK_MAX_BITS 11
-#define BLOCK_MAX_SIZE (1 << BLOCK_MAX_BITS)
-
-#define BLOCK_NB_SIZES (BLOCK_MAX_BITS - BLOCK_MIN_BITS + 1)
-
-/* XXX: find exact max size */
-#define HIGH_BAND_MAX_SIZE 16
-
-#define NB_LSP_COEFS 10
-
-/* XXX: is it a suitable value ? */
-#define MAX_CODED_SUPERFRAME_SIZE 16384
-
-#define MAX_CHANNELS 2
-
-#define NOISE_TAB_SIZE 8192
-
-#define LSP_POW_BITS 7
-
-#define VLCBITS 9
-#define VLCMAX ((22+VLCBITS-1)/VLCBITS)
-
-#define EXPVLCBITS 8
-#define EXPMAX ((19+EXPVLCBITS-1)/EXPVLCBITS)
-
-#define HGAINVLCBITS 9
-#define HGAINMAX ((13+HGAINVLCBITS-1)/HGAINVLCBITS)
-
-typedef struct WMADecodeContext {
- GetBitContext gb;
- int sample_rate;
- int nb_channels;
- int bit_rate;
- int version; /* 1 = 0x160 (WMAV1), 2 = 0x161 (WMAV2) */
- int block_align;
- int use_bit_reservoir;
- int use_variable_block_len;
- int use_exp_vlc; /* exponent coding: 0 = lsp, 1 = vlc + delta */
- int use_noise_coding; /* true if perceptual noise is added */
- int byte_offset_bits;
- VLC exp_vlc;
- int exponent_sizes[BLOCK_NB_SIZES];
- uint16_t exponent_bands[BLOCK_NB_SIZES][25];
- int high_band_start[BLOCK_NB_SIZES]; /* index of first coef in high band */
- int coefs_start; /* first coded coef */
- int coefs_end[BLOCK_NB_SIZES]; /* max number of coded coefficients */
- int exponent_high_sizes[BLOCK_NB_SIZES];
- int exponent_high_bands[BLOCK_NB_SIZES][HIGH_BAND_MAX_SIZE];
- VLC hgain_vlc;
-
- /* coded values in high bands */
- int high_band_coded[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
- int high_band_values[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
-
- /* there are two possible tables for spectral coefficients */
- VLC coef_vlc[2];
- uint16_t *run_table[2];
- uint16_t *level_table[2];
- /* frame info */
- int frame_len; /* frame length in samples */
- int frame_len_bits; /* frame_len = 1 << frame_len_bits */
- int nb_block_sizes; /* number of block sizes */
- /* block info */
- int reset_block_lengths;
- int block_len_bits; /* log2 of current block length */
- int next_block_len_bits; /* log2 of next block length */
- int prev_block_len_bits; /* log2 of prev block length */
- int block_len; /* block length in samples */
- int block_num; /* block number in current frame */
- int block_pos; /* current position in frame */
- uint8_t ms_stereo; /* true if mid/side stereo mode */
- uint8_t channel_coded[MAX_CHANNELS]; /* true if channel is coded */
- DECLARE_ALIGNED_16(float, exponents[MAX_CHANNELS][BLOCK_MAX_SIZE]);
- float max_exponent[MAX_CHANNELS];
- int16_t 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]);
- DECLARE_ALIGNED_16(float, window[BLOCK_MAX_SIZE * 2]);
- MDCTContext mdct_ctx[BLOCK_NB_SIZES];
- float *windows[BLOCK_NB_SIZES];
- DECLARE_ALIGNED_16(FFTSample, mdct_tmp[BLOCK_MAX_SIZE]); /* temporary storage for imdct */
- /* output buffer for one frame and the last for IMDCT windowing */
- 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;
- int last_superframe_len;
- float noise_table[NOISE_TAB_SIZE];
- int noise_index;
- float noise_mult; /* XXX: suppress that and integrate it in the noise array */
- /* lsp_to_curve tables */
- float lsp_cos_table[BLOCK_MAX_SIZE];
- float lsp_pow_e_table[256];
- float lsp_pow_m_table1[(1 << LSP_POW_BITS)];
- float lsp_pow_m_table2[(1 << LSP_POW_BITS)];
- DSPContext dsp;
-
-#ifdef TRACE
- int frame_count;
-#endif
-} WMADecodeContext;
-
-typedef struct CoefVLCTable {
- int n; /* total number of codes */
- const uint32_t *huffcodes; /* VLC bit values */
- const uint8_t *huffbits; /* VLC bit size */
- const uint16_t *levels; /* table to build run/level tables */
-} CoefVLCTable;
-
-static void wma_lsp_to_curve_init(WMADecodeContext *s, int frame_len);
-
-#include "wmadata.h"
-
-#ifdef TRACE
-static void dump_shorts(const char *name, const short *tab, int n)
-{
- int i;
-
- tprintf("%s[%d]:\n", name, n);
- for(i=0;i<n;i++) {
- if ((i & 7) == 0)
- tprintf("%4d: ", i);
- tprintf(" %5d.0", tab[i]);
- if ((i & 7) == 7)
- tprintf("\n");
- }
-}
-
-static void dump_floats(const char *name, int prec, const float *tab, int n)
-{
- int i;
-
- tprintf("%s[%d]:\n", name, n);
- for(i=0;i<n;i++) {
- if ((i & 7) == 0)
- tprintf("%4d: ", i);
- tprintf(" %8.*f", prec, tab[i]);
- if ((i & 7) == 7)
- tprintf("\n");
- }
- if ((i & 7) != 0)
- tprintf("\n");
-}
-#endif
-
-/* XXX: use same run/length optimization as mpeg decoders */
-static void init_coef_vlc(VLC *vlc,
- uint16_t **prun_table, uint16_t **plevel_table,
- const CoefVLCTable *vlc_table)
-{
- int n = vlc_table->n;
- const uint8_t *table_bits = vlc_table->huffbits;
- const uint32_t *table_codes = vlc_table->huffcodes;
- const uint16_t *levels_table = vlc_table->levels;
- uint16_t *run_table, *level_table;
- const uint16_t *p;
- int i, l, j, 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));
- p = levels_table;
- i = 2;
- level = 1;
- while (i < n) {
- l = *p++;
- for(j=0;j<l;j++) {
- run_table[i] = j;
- level_table[i] = level;
- i++;
- }
- level++;
- }
- *prun_table = run_table;
- *plevel_table = level_table;
-}
-
-static int wma_decode_init(AVCodecContext * avctx)
-{
- WMADecodeContext *s = avctx->priv_data;
- int i, flags1, flags2;
- float *window;
- uint8_t *extradata;
- float bps1, high_freq;
- volatile float bps;
- int sample_rate1;
- int coef_vlc_table;
-
- s->sample_rate = avctx->sample_rate;
- s->nb_channels = avctx->channels;
- s->bit_rate = avctx->bit_rate;
- s->block_align = avctx->block_align;
-
- dsputil_init(&s->dsp, avctx);
-
- if (avctx->codec->id == CODEC_ID_WMAV1) {
- s->version = 1;
- } else {
- s->version = 2;
- }
-
- /* extract flag infos */
- flags1 = 0;
- flags2 = 0;
- extradata = avctx->extradata;
- if (s->version == 1 && avctx->extradata_size >= 4) {
- flags1 = extradata[0] | (extradata[1] << 8);
- flags2 = extradata[2] | (extradata[3] << 8);
- } else if (s->version == 2 && avctx->extradata_size >= 6) {
- flags1 = extradata[0] | (extradata[1] << 8) |
- (extradata[2] << 16) | (extradata[3] << 24);
- flags2 = extradata[4] | (extradata[5] << 8);
- }
- s->use_exp_vlc = flags2 & 0x0001;
- s->use_bit_reservoir = flags2 & 0x0002;
- s->use_variable_block_len = flags2 & 0x0004;
-
- /* compute MDCT block size */
- if (s->sample_rate <= 16000) {
- s->frame_len_bits = 9;
- } else if (s->sample_rate <= 22050 ||
- (s->sample_rate <= 32000 && s->version == 1)) {
- s->frame_len_bits = 10;
- } else {
- s->frame_len_bits = 11;
- }
- s->frame_len = 1 << s->frame_len_bits;
- if (s->use_variable_block_len) {
- int nb_max, nb;
- nb = ((flags2 >> 3) & 3) + 1;
- if ((s->bit_rate / s->nb_channels) >= 32000)
- nb += 2;
- nb_max = s->frame_len_bits - BLOCK_MIN_BITS;
- if (nb > nb_max)
- nb = nb_max;
- s->nb_block_sizes = nb + 1;
- } else {
- s->nb_block_sizes = 1;
- }
-
- /* init rate dependant parameters */
- s->use_noise_coding = 1;
- high_freq = s->sample_rate * 0.5;
-
- /* if version 2, then the rates are normalized */
- sample_rate1 = s->sample_rate;
- if (s->version == 2) {
- if (sample_rate1 >= 44100)
- sample_rate1 = 44100;
- else if (sample_rate1 >= 22050)
- sample_rate1 = 22050;
- else if (sample_rate1 >= 16000)
- sample_rate1 = 16000;
- else if (sample_rate1 >= 11025)
- sample_rate1 = 11025;
- else if (sample_rate1 >= 8000)
- sample_rate1 = 8000;
- }
-
- bps = (float)s->bit_rate / (float)(s->nb_channels * s->sample_rate);
- s->byte_offset_bits = av_log2((int)(bps * s->frame_len / 8.0 + 0.5)) + 2;
-
- /* compute high frequency value and choose if noise coding should
- be activated */
- bps1 = bps;
- if (s->nb_channels == 2)
- bps1 = bps * 1.6;
- if (sample_rate1 == 44100) {
- if (bps1 >= 0.61)
- s->use_noise_coding = 0;
- else
- high_freq = high_freq * 0.4;
- } else if (sample_rate1 == 22050) {
- if (bps1 >= 1.16)
- s->use_noise_coding = 0;
- else if (bps1 >= 0.72)
- high_freq = high_freq * 0.7;
- else
- high_freq = high_freq * 0.6;
- } else if (sample_rate1 == 16000) {
- if (bps > 0.5)
- high_freq = high_freq * 0.5;
- else
- high_freq = high_freq * 0.3;
- } else if (sample_rate1 == 11025) {
- high_freq = high_freq * 0.7;
- } else if (sample_rate1 == 8000) {
- if (bps <= 0.625) {
- high_freq = high_freq * 0.5;
- } else if (bps > 0.75) {
- s->use_noise_coding = 0;
- } else {
- high_freq = high_freq * 0.65;
- }
- } else {
- if (bps >= 0.8) {
- high_freq = high_freq * 0.75;
- } else if (bps >= 0.6) {
- high_freq = high_freq * 0.6;
- } else {
- high_freq = high_freq * 0.5;
- }
- }
- dprintf("flags1=0x%x flags2=0x%x\n", flags1, flags2);
- dprintf("version=%d channels=%d sample_rate=%d bitrate=%d block_align=%d\n",
- s->version, s->nb_channels, s->sample_rate, s->bit_rate,
- s->block_align);
- dprintf("bps=%f bps1=%f high_freq=%f bitoffset=%d\n",
- bps, bps1, high_freq, s->byte_offset_bits);
- dprintf("use_noise_coding=%d use_exp_vlc=%d nb_block_sizes=%d\n",
- s->use_noise_coding, s->use_exp_vlc, s->nb_block_sizes);
-
- /* compute the scale factor band sizes for each MDCT block size */
- {
- int a, b, pos, lpos, k, block_len, i, j, n;
- const uint8_t *table;
-
- if (s->version == 1) {
- s->coefs_start = 3;
- } else {
- s->coefs_start = 0;
- }
- for(k = 0; k < s->nb_block_sizes; k++) {
- block_len = s->frame_len >> k;
-
- if (s->version == 1) {
- lpos = 0;
- for(i=0;i<25;i++) {
- a = wma_critical_freqs[i];
- b = s->sample_rate;
- pos = ((block_len * 2 * a) + (b >> 1)) / b;
- if (pos > block_len)
- pos = block_len;
- s->exponent_bands[0][i] = pos - lpos;
- if (pos >= block_len) {
- i++;
- break;
- }
- lpos = pos;
- }
- s->exponent_sizes[0] = i;
- } else {
- /* hardcoded tables */
- table = NULL;
- a = s->frame_len_bits - BLOCK_MIN_BITS - k;
- if (a < 3) {
- if (s->sample_rate >= 44100)
- table = exponent_band_44100[a];
- else if (s->sample_rate >= 32000)
- table = exponent_band_32000[a];
- else if (s->sample_rate >= 22050)
- table = exponent_band_22050[a];
- }
- if (table) {
- n = *table++;
- for(i=0;i<n;i++)
- s->exponent_bands[k][i] = table[i];
- s->exponent_sizes[k] = n;
- } else {
- j = 0;
- lpos = 0;
- for(i=0;i<25;i++) {
- a = wma_critical_freqs[i];
- b = s->sample_rate;
- pos = ((block_len * 2 * a) + (b << 1)) / (4 * b);
- pos <<= 2;
- if (pos > block_len)
- pos = block_len;
- if (pos > lpos)
- s->exponent_bands[k][j++] = pos - lpos;
- if (pos >= block_len)
- break;
- lpos = pos;
- }
- s->exponent_sizes[k] = j;
- }
- }
-
- /* max number of coefs */
- s->coefs_end[k] = (s->frame_len - ((s->frame_len * 9) / 100)) >> k;
- /* high freq computation */
- s->high_band_start[k] = (int)((block_len * 2 * high_freq) /
- s->sample_rate + 0.5);
- n = s->exponent_sizes[k];
- j = 0;
- pos = 0;
- for(i=0;i<n;i++) {
- int start, end;
- start = pos;
- pos += s->exponent_bands[k][i];
- end = pos;
- if (start < s->high_band_start[k])
- start = s->high_band_start[k];
- if (end > s->coefs_end[k])
- end = s->coefs_end[k];
- if (end > start)
- s->exponent_high_bands[k][j++] = end - start;
- }
- s->exponent_high_sizes[k] = j;
-#if 0
- tprintf("%5d: coefs_end=%d high_band_start=%d nb_high_bands=%d: ",
- s->frame_len >> k,
- s->coefs_end[k],
- s->high_band_start[k],
- s->exponent_high_sizes[k]);
- for(j=0;j<s->exponent_high_sizes[k];j++)
- tprintf(" %d", s->exponent_high_bands[k][j]);
- tprintf("\n");
-#endif
- }
- }
-
-#ifdef TRACE
- {
- int i, j;
- for(i = 0; i < s->nb_block_sizes; i++) {
- tprintf("%5d: n=%2d:",
- s->frame_len >> i,
- s->exponent_sizes[i]);
- for(j=0;j<s->exponent_sizes[i];j++)
- tprintf(" %d", s->exponent_bands[i][j]);
- tprintf("\n");
- }
- }
-#endif
-
- /* init MDCT */
- for(i = 0; i < s->nb_block_sizes; i++)
- ff_mdct_init(&s->mdct_ctx[i], s->frame_len_bits - i + 1, 1);
-
- /* init MDCT windows : simple sinus window */
- for(i = 0; i < s->nb_block_sizes; i++) {
- int n, j;
- float alpha;
- n = 1 << (s->frame_len_bits - i);
- window = av_malloc(sizeof(float) * n);
- alpha = M_PI / (2.0 * n);
- for(j=0;j<n;j++) {
- window[n - j - 1] = sin((j + 0.5) * alpha);
- }
- s->windows[i] = window;
- }
-
- s->reset_block_lengths = 1;
-
- if (s->use_noise_coding) {
-
- /* init the noise generator */
- if (s->use_exp_vlc)
- s->noise_mult = 0.02;
- else
- s->noise_mult = 0.04;
-
-#ifdef TRACE
- for(i=0;i<NOISE_TAB_SIZE;i++)
- s->noise_table[i] = 1.0 * s->noise_mult;
-#else
- {
- unsigned int seed;
- float norm;
- seed = 1;
- norm = (1.0 / (float)(1LL << 31)) * sqrt(3) * s->noise_mult;
- for(i=0;i<NOISE_TAB_SIZE;i++) {
- seed = seed * 314159 + 1;
- s->noise_table[i] = (float)((int)seed) * norm;
- }
- }
-#endif
- init_vlc(&s->hgain_vlc, HGAINVLCBITS, sizeof(hgain_huffbits),
- hgain_huffbits, 1, 1,
- hgain_huffcodes, 2, 2, 0);
- }
-
- if (s->use_exp_vlc) {
- init_vlc(&s->exp_vlc, EXPVLCBITS, sizeof(scale_huffbits),
- scale_huffbits, 1, 1,
- scale_huffcodes, 4, 4, 0);
- } else {
- wma_lsp_to_curve_init(s, s->frame_len);
- }
-
- /* choose the VLC tables for the coefficients */
- coef_vlc_table = 2;
- if (s->sample_rate >= 32000) {
- if (bps1 < 0.72)
- coef_vlc_table = 0;
- else if (bps1 < 1.16)
- coef_vlc_table = 1;
- }
-
- init_coef_vlc(&s->coef_vlc[0], &s->run_table[0], &s->level_table[0],
- &coef_vlcs[coef_vlc_table * 2]);
- init_coef_vlc(&s->coef_vlc[1], &s->run_table[1], &s->level_table[1],
- &coef_vlcs[coef_vlc_table * 2 + 1]);
- return 0;
-}
-
-/* interpolate values for a bigger or smaller block. The block must
- have multiple sizes */
-static void interpolate_array(float *scale, int old_size, int new_size)
-{
- int i, j, jincr, k;
- float v;
-
- if (new_size > old_size) {
- jincr = new_size / old_size;
- j = new_size;
- for(i = old_size - 1; i >=0; i--) {
- v = scale[i];
- k = jincr;
- do {
- scale[--j] = v;
- } while (--k);
- }
- } else if (new_size < old_size) {
- j = 0;
- jincr = old_size / new_size;
- for(i = 0; i < new_size; i++) {
- scale[i] = scale[j];
- j += jincr;
- }
- }
-}
-
-/* compute x^-0.25 with an exponent and mantissa table. We use linear
- interpolation to reduce the mantissa table size at a small speed
- expense (linear interpolation approximately doubles the number of
- bits of precision). */
-static inline float pow_m1_4(WMADecodeContext *s, float x)
-{
- union {
- float f;
- unsigned int v;
- } u, t;
- unsigned int e, m;
- float a, b;
-
- u.f = x;
- e = u.v >> 23;
- m = (u.v >> (23 - LSP_POW_BITS)) & ((1 << LSP_POW_BITS) - 1);
- /* build interpolation scale: 1 <= t < 2. */
- t.v = ((u.v << LSP_POW_BITS) & ((1 << 23) - 1)) | (127 << 23);
- a = s->lsp_pow_m_table1[m];
- b = s->lsp_pow_m_table2[m];
- return s->lsp_pow_e_table[e] * (a + b * t.f);
-}
-
-static void wma_lsp_to_curve_init(WMADecodeContext *s, int frame_len)
-{
- float wdel, a, b;
- int i, e, m;
-
- wdel = M_PI / frame_len;
- for(i=0;i<frame_len;i++)
- s->lsp_cos_table[i] = 2.0f * cos(wdel * i);
-
- /* tables for x^-0.25 computation */
- for(i=0;i<256;i++) {
- e = i - 126;
- s->lsp_pow_e_table[i] = pow(2.0, e * -0.25);
- }
-
- /* NOTE: these two tables are needed to avoid two operations in
- pow_m1_4 */
- b = 1.0;
- for(i=(1 << LSP_POW_BITS) - 1;i>=0;i--) {
- m = (1 << LSP_POW_BITS) + i;
- a = (float)m * (0.5 / (1 << LSP_POW_BITS));
- a = pow(a, -0.25);
- s->lsp_pow_m_table1[i] = 2 * a - b;
- s->lsp_pow_m_table2[i] = b - a;
- b = a;
- }
-#if 0
- for(i=1;i<20;i++) {
- float v, r1, r2;
- v = 5.0 / i;
- r1 = pow_m1_4(s, v);
- r2 = pow(v,-0.25);
- printf("%f^-0.25=%f e=%f\n", v, r1, r2 - r1);
- }
-#endif
-}
-
-/* NOTE: We use the same code as Vorbis here */
-/* XXX: optimize it further with SSE/3Dnow */
-static void wma_lsp_to_curve(WMADecodeContext *s,
- float *out, float *val_max_ptr,
- int n, float *lsp)
-{
- int i, j;
- float p, q, w, v, val_max;
-
- val_max = 0;
- for(i=0;i<n;i++) {
- p = 0.5f;
- q = 0.5f;
- w = s->lsp_cos_table[i];
- for(j=1;j<NB_LSP_COEFS;j+=2){
- q *= w - lsp[j - 1];
- p *= w - lsp[j];
- }
- p *= p * (2.0f - w);
- q *= q * (2.0f + w);
- v = p + q;
- v = pow_m1_4(s, v);
- if (v > val_max)
- val_max = v;
- out[i] = v;
- }
- *val_max_ptr = val_max;
-}
-
-/* decode exponents coded with LSP coefficients (same idea as Vorbis) */
-static void decode_exp_lsp(WMADecodeContext *s, int ch)
-{
- float lsp_coefs[NB_LSP_COEFS];
- int val, i;
-
- for(i = 0; i < NB_LSP_COEFS; i++) {
- if (i == 0 || i >= 8)
- val = get_bits(&s->gb, 3);
- else
- val = get_bits(&s->gb, 4);
- lsp_coefs[i] = lsp_codebook[i][val];
- }
-
- wma_lsp_to_curve(s, s->exponents[ch], &s->max_exponent[ch],
- s->block_len, lsp_coefs);
-}
-
-/* decode exponents coded with VLC codes */
-static int decode_exp_vlc(WMADecodeContext *s, int ch)
-{
- int last_exp, n, code;
- const uint16_t *ptr, *band_ptr;
- float v, *q, max_scale, *q_end;
-
- band_ptr = s->exponent_bands[s->frame_len_bits - s->block_len_bits];
- ptr = band_ptr;
- q = 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));
- max_scale = v;
- n = *ptr++;
- do {
- *q++ = v;
- } while (--n);
- }
- last_exp = 36;
- while (q < q_end) {
- code = get_vlc2(&s->gb, s->exp_vlc.table, EXPVLCBITS, EXPMAX);
- if (code < 0)
- 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 (v > max_scale)
- max_scale = v;
- n = *ptr++;
- do {
- *q++ = v;
- } while (--n);
- }
- s->max_exponent[ch] = max_scale;
- return 0;
-}
-
-/* return 0 if OK. return 1 if last block of frame. return -1 if
- unrecorrable error. */
-static int wma_decode_block(WMADecodeContext *s)
-{
- int n, v, a, ch, code, bsize;
- int coef_nb_bits, total_gain, parse_exponents;
- int nb_coefs[MAX_CHANNELS];
- float mdct_norm;
-
-#ifdef TRACE
- tprintf("***decode_block: %d:%d\n", s->frame_count - 1, s->block_num);
-#endif
-
- /* compute current block length */
- if (s->use_variable_block_len) {
- n = av_log2(s->nb_block_sizes - 1) + 1;
-
- if (s->reset_block_lengths) {
- s->reset_block_lengths = 0;
- v = get_bits(&s->gb, n);
- if (v >= s->nb_block_sizes)
- return -1;
- s->prev_block_len_bits = s->frame_len_bits - v;
- v = get_bits(&s->gb, n);
- if (v >= s->nb_block_sizes)
- return -1;
- s->block_len_bits = s->frame_len_bits - v;
- } else {
- /* update block lengths */
- s->prev_block_len_bits = s->block_len_bits;
- s->block_len_bits = s->next_block_len_bits;
- }
- v = get_bits(&s->gb, n);
- if (v >= s->nb_block_sizes)
- return -1;
- s->next_block_len_bits = s->frame_len_bits - v;
- } else {
- /* fixed block len */
- s->next_block_len_bits = s->frame_len_bits;
- s->prev_block_len_bits = s->frame_len_bits;
- s->block_len_bits = s->frame_len_bits;
- }
-
- /* 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)
- return -1;
-
- if (s->nb_channels == 2) {
- s->ms_stereo = get_bits(&s->gb, 1);
- }
- v = 0;
- for(ch = 0; ch < s->nb_channels; ch++) {
- a = get_bits(&s->gb, 1);
- s->channel_coded[ch] = a;
- v |= a;
- }
- /* if no channel coded, no need to go further */
- /* XXX: fix potential framing problems */
- if (!v)
- goto next;
-
- bsize = s->frame_len_bits - s->block_len_bits;
-
- /* read total gain and extract corresponding number of bits for
- coef escape coding */
- total_gain = 1;
- for(;;) {
- a = get_bits(&s->gb, 7);
- total_gain += a;
- if (a != 127)
- break;
- }
-
- if (total_gain < 15)
- coef_nb_bits = 13;
- else if (total_gain < 32)
- coef_nb_bits = 12;
- else if (total_gain < 40)
- coef_nb_bits = 11;
- else if (total_gain < 45)
- coef_nb_bits = 10;
- else
- coef_nb_bits = 9;
-
- /* compute number of coefficients */
- n = s->coefs_end[bsize] - s->coefs_start;
- for(ch = 0; ch < s->nb_channels; ch++)
- nb_coefs[ch] = n;
-
- /* complex coding */
- if (s->use_noise_coding) {
-
- for(ch = 0; ch < s->nb_channels; ch++) {
- if (s->channel_coded[ch]) {
- int i, n, a;
- n = s->exponent_high_sizes[bsize];
- for(i=0;i<n;i++) {
- a = get_bits(&s->gb, 1);
- s->high_band_coded[ch][i] = a;
- /* if noise coding, the coefficients are not transmitted */
- if (a)
- nb_coefs[ch] -= s->exponent_high_bands[bsize][i];
- }
- }
- }
- for(ch = 0; ch < s->nb_channels; ch++) {
- if (s->channel_coded[ch]) {
- int i, n, val, code;
-
- n = s->exponent_high_sizes[bsize];
- val = (int)0x80000000;
- for(i=0;i<n;i++) {
- if (s->high_band_coded[ch][i]) {
- if (val == (int)0x80000000) {
- val = get_bits(&s->gb, 7) - 19;
- } else {
- code = get_vlc2(&s->gb, s->hgain_vlc.table, HGAINVLCBITS, HGAINMAX);
- if (code < 0)
- return -1;
- val += code - 18;
- }
- s->high_band_values[ch][i] = val;
- }
- }
- }
- }
- }
-
- /* exposant can be interpolated in short blocks. */
- parse_exponents = 1;
- if (s->block_len_bits != s->frame_len_bits) {
- parse_exponents = get_bits(&s->gb, 1);
- }
-
- if (parse_exponents) {
- for(ch = 0; ch < s->nb_channels; ch++) {
- if (s->channel_coded[ch]) {
- if (s->use_exp_vlc) {
- if (decode_exp_vlc(s, ch) < 0)
- return -1;
- } else {
- decode_exp_lsp(s, ch);
- }
- }
- }
- } else {
- for(ch = 0; ch < s->nb_channels; ch++) {
- if (s->channel_coded[ch]) {
- interpolate_array(s->exponents[ch], 1 << s->prev_block_len_bits,
- s->block_len);
- }
- }
- }
-
- /* parse spectral coefficients : just RLE encoding */
- for(ch = 0; ch < s->nb_channels; ch++) {
- if (s->channel_coded[ch]) {
- VLC *coef_vlc;
- int level, run, sign, tindex;
- int16_t *ptr, *eptr;
- const uint16_t *level_table, *run_table;
-
- /* special VLC tables are used for ms stereo because
- there is potentially less energy there */
- tindex = (ch == 1 && s->ms_stereo);
- coef_vlc = &s->coef_vlc[tindex];
- run_table = s->run_table[tindex];
- level_table = s->level_table[tindex];
- /* XXX: optimize */
- ptr = &s->coefs1[ch][0];
- eptr = ptr + nb_coefs[ch];
- memset(ptr, 0, s->block_len * sizeof(int16_t));
- for(;;) {
- code = get_vlc2(&s->gb, coef_vlc->table, VLCBITS, VLCMAX);
- if (code < 0)
- return -1;
- if (code == 1) {
- /* EOB */
- break;
- } else if (code == 0) {
- /* escape */
- level = get_bits(&s->gb, coef_nb_bits);
- /* NOTE: this is rather suboptimal. reading
- block_len_bits would be better */
- run = get_bits(&s->gb, s->frame_len_bits);
- } else {
- /* normal code */
- run = run_table[code];
- level = level_table[code];
- }
- sign = get_bits(&s->gb, 1);
- if (!sign)
- level = -level;
- ptr += run;
- if (ptr >= eptr)
- {
- av_log(NULL, AV_LOG_ERROR, "overflow in spectral RLE, ignoring\n");
- break;
- }
- *ptr++ = level;
- /* NOTE: EOB can be omitted */
- if (ptr >= eptr)
- break;
- }
- }
- if (s->version == 1 && s->nb_channels >= 2) {
- align_get_bits(&s->gb);
- }
- }
-
- /* normalize */
- {
- int n4 = s->block_len / 2;
- mdct_norm = 1.0 / (float)n4;
- if (s->version == 1) {
- mdct_norm *= sqrt(n4);
- }
- }
-
- /* finally compute the MDCT coefficients */
- for(ch = 0; ch < s->nb_channels; ch++) {
- if (s->channel_coded[ch]) {
- int16_t *coefs1;
- float *coefs, *exponents, mult, mult1, noise, *exp_ptr;
- int i, j, n, n1, last_high_band;
- float exp_power[HIGH_BAND_MAX_SIZE];
-
- coefs1 = s->coefs1[ch];
- exponents = s->exponents[ch];
- mult = pow(10, total_gain * 0.05) / s->max_exponent[ch];
- mult *= mdct_norm;
- coefs = s->coefs[ch];
- if (s->use_noise_coding) {
- mult1 = mult;
- /* very low freqs : noise */
- for(i = 0;i < s->coefs_start; i++) {
- *coefs++ = s->noise_table[s->noise_index] * (*exponents++) * mult1;
- s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
- }
-
- n1 = s->exponent_high_sizes[bsize];
-
- /* compute power of high bands */
- exp_ptr = exponents +
- s->high_band_start[bsize] -
- s->coefs_start;
- last_high_band = 0; /* avoid warning */
- for(j=0;j<n1;j++) {
- n = s->exponent_high_bands[s->frame_len_bits -
- s->block_len_bits][j];
- if (s->high_band_coded[ch][j]) {
- float e2, v;
- e2 = 0;
- for(i = 0;i < n; i++) {
- v = exp_ptr[i];
- e2 += v * v;
- }
- exp_power[j] = e2 / n;
- last_high_band = j;
- tprintf("%d: power=%f (%d)\n", j, exp_power[j], n);
- }
- exp_ptr += n;
- }
-
- /* main freqs and high freqs */
- for(j=-1;j<n1;j++) {
- if (j < 0) {
- n = s->high_band_start[bsize] -
- s->coefs_start;
- } else {
- n = s->exponent_high_bands[s->frame_len_bits -
- s->block_len_bits][j];
- }
- if (j >= 0 && s->high_band_coded[ch][j]) {
- /* use noise with specified power */
- mult1 = sqrt(exp_power[j] / exp_power[last_high_band]);
- /* XXX: use a table */
- mult1 = mult1 * pow(10, s->high_band_values[ch][j] * 0.05);
- mult1 = mult1 / (s->max_exponent[ch] * s->noise_mult);
- mult1 *= mdct_norm;
- for(i = 0;i < n; i++) {
- noise = s->noise_table[s->noise_index];
- s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
- *coefs++ = (*exponents++) * noise * mult1;
- }
- } else {
- /* coded values + small noise */
- for(i = 0;i < n; i++) {
- noise = s->noise_table[s->noise_index];
- s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
- *coefs++ = ((*coefs1++) + noise) * (*exponents++) * mult;
- }
- }
- }
-
- /* very high freqs : noise */
- n = s->block_len - s->coefs_end[bsize];
- mult1 = mult * exponents[-1];
- for(i = 0; i < n; i++) {
- *coefs++ = s->noise_table[s->noise_index] * mult1;
- s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
- }
- } else {
- /* XXX: optimize more */
- for(i = 0;i < s->coefs_start; i++)
- *coefs++ = 0.0;
- n = nb_coefs[ch];
- for(i = 0;i < n; i++) {
- *coefs++ = coefs1[i] * exponents[i] * mult;
- }
- n = s->block_len - s->coefs_end[bsize];
- for(i = 0;i < n; i++)
- *coefs++ = 0.0;
- }
- }
- }
-
-#ifdef TRACE
- for(ch = 0; ch < s->nb_channels; ch++) {
- if (s->channel_coded[ch]) {
- dump_floats("exponents", 3, s->exponents[ch], s->block_len);
- dump_floats("coefs", 1, s->coefs[ch], s->block_len);
- }
- }
-#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 */
- if (!s->channel_coded[0]) {
- tprintf("rare ms-stereo case happened\n");
- memset(s->coefs[0], 0, sizeof(float) * s->block_len);
- 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;
- }
- }
-
- /* build the window : we ensure that when the windows overlap
- their squared sum is always 1 (MDCT reconstruction rule) */
- /* XXX: merge with output */
- {
- int i, next_block_len, block_len, prev_block_len, n;
- float *wptr;
-
- block_len = s->block_len;
- prev_block_len = 1 << s->prev_block_len_bits;
- next_block_len = 1 << s->next_block_len_bits;
-
- /* right part */
- wptr = s->window + block_len;
- if (block_len <= next_block_len) {
- for(i=0;i<block_len;i++)
- *wptr++ = s->windows[bsize][i];
- } else {
- /* overlap */
- n = (block_len / 2) - (next_block_len / 2);
- for(i=0;i<n;i++)
- *wptr++ = 1.0;
- for(i=0;i<next_block_len;i++)
- *wptr++ = s->windows[s->frame_len_bits - s->next_block_len_bits][i];
- for(i=0;i<n;i++)
- *wptr++ = 0.0;
- }
-
- /* left part */
- wptr = s->window + block_len;
- if (block_len <= prev_block_len) {
- for(i=0;i<block_len;i++)
- *--wptr = s->windows[bsize][i];
- } else {
- /* overlap */
- n = (block_len / 2) - (prev_block_len / 2);
- for(i=0;i<n;i++)
- *--wptr = 1.0;
- for(i=0;i<prev_block_len;i++)
- *--wptr = s->windows[s->frame_len_bits - s->prev_block_len_bits][i];
- for(i=0;i<n;i++)
- *--wptr = 0.0;
- }
- }
-
-
- for(ch = 0; ch < s->nb_channels; ch++) {
- if (s->channel_coded[ch]) {
- float *ptr;
- int n4, index, n;
-
- n = s->block_len;
- n4 = s->block_len / 2;
- s->mdct_ctx[bsize].fft.imdct_calc(&s->mdct_ctx[bsize],
- s->output, s->coefs[ch], s->mdct_tmp);
-
- /* XXX: optimize all that by build the window and
- multipying/adding at the same time */
-
- /* multiply by the window and add in the frame */
- index = (s->frame_len / 2) + s->block_pos - n4;
- ptr = &s->frame_out[ch][index];
- s->dsp.vector_fmul_add_add(ptr,s->window,s->output,ptr,0,2*n,1);
-
- /* specific fast case for ms-stereo : add to second
- channel if it is not coded */
- if (s->ms_stereo && !s->channel_coded[1]) {
- ptr = &s->frame_out[1][index];
- s->dsp.vector_fmul_add_add(ptr,s->window,s->output,ptr,0,2*n,1);
- }
- }
- }
- next:
- /* update block number */
- s->block_num++;
- s->block_pos += s->block_len;
- if (s->block_pos >= s->frame_len)
- return 1;
- else
- return 0;
-}
-
-/* decode a frame of frame_len samples */
-static int wma_decode_frame(WMADecodeContext *s, int16_t *samples)
-{
- int ret, i, n, a, ch, incr;
- int16_t *ptr;
- float *iptr;
-
-#ifdef TRACE
- tprintf("***decode_frame: %d size=%d\n", s->frame_count++, s->frame_len);
-#endif
-
- /* read each block */
- s->block_num = 0;
- s->block_pos = 0;
- for(;;) {
- ret = wma_decode_block(s);
- if (ret < 0)
- return -1;
- if (ret)
- break;
- }
-
- /* 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];
-
- for(i=0;i<n;i++) {
- a = lrintf(*iptr++);
- if (a > 32767)
- a = 32767;
- else if (a < -32768)
- a = -32768;
- *ptr = a;
- ptr += incr;
- }
- /* prepare for next block */
- memmove(&s->frame_out[ch][0], &s->frame_out[ch][s->frame_len],
- s->frame_len * sizeof(float));
- /* XXX: suppress this */
- memset(&s->frame_out[ch][s->frame_len], 0,
- s->frame_len * sizeof(float));
- }
-
-#ifdef TRACE
- dump_shorts("samples", samples, n * s->nb_channels);
-#endif
- return 0;
-}
-
-static int wma_decode_superframe(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- WMADecodeContext *s = avctx->priv_data;
- int nb_frames, bit_offset, i, pos, len;
- uint8_t *q;
- int16_t *samples;
-
- tprintf("***decode_superframe:\n");
-
- if(buf_size==0){
- s->last_superframe_len = 0;
- return 0;
- }
-
- samples = data;
-
- init_get_bits(&s->gb, buf, buf_size*8);
-
- if (s->use_bit_reservoir) {
- /* read super frame header */
- get_bits(&s->gb, 4); /* super frame index */
- nb_frames = get_bits(&s->gb, 4) - 1;
-
- bit_offset = get_bits(&s->gb, s->byte_offset_bits + 3);
-
- if (s->last_superframe_len > 0) {
- // printf("skip=%d\n", s->last_bitoffset);
- /* add bit_offset bits to last frame */
- if ((s->last_superframe_len + ((bit_offset + 7) >> 3)) >
- MAX_CODED_SUPERFRAME_SIZE)
- goto fail;
- q = s->last_superframe + s->last_superframe_len;
- len = bit_offset;
- while (len > 7) {
- *q++ = (get_bits)(&s->gb, 8);
- len -= 8;
- }
- if (len > 0) {
- *q++ = (get_bits)(&s->gb, len) << (8 - len);
- }
-
- /* XXX: bit_offset bits into last frame */
- init_get_bits(&s->gb, s->last_superframe, MAX_CODED_SUPERFRAME_SIZE*8);
- /* skip unused bits */
- if (s->last_bitoffset > 0)
- skip_bits(&s->gb, s->last_bitoffset);
- /* this frame is stored in the last superframe and in the
- current one */
- if (wma_decode_frame(s, samples) < 0)
- goto fail;
- samples += s->nb_channels * s->frame_len;
- }
-
- /* read each frame starting from bit_offset */
- pos = bit_offset + 4 + 4 + s->byte_offset_bits + 3;
- init_get_bits(&s->gb, buf + (pos >> 3), (MAX_CODED_SUPERFRAME_SIZE - (pos >> 3))*8);
- len = pos & 7;
- if (len > 0)
- skip_bits(&s->gb, len);
-
- s->reset_block_lengths = 1;
- for(i=0;i<nb_frames;i++) {
- if (wma_decode_frame(s, samples) < 0)
- goto fail;
- samples += s->nb_channels * s->frame_len;
- }
-
- /* we copy the end of the frame in the last frame buffer */
- pos = get_bits_count(&s->gb) + ((bit_offset + 4 + 4 + s->byte_offset_bits + 3) & ~7);
- s->last_bitoffset = pos & 7;
- pos >>= 3;
- len = buf_size - pos;
- if (len > MAX_CODED_SUPERFRAME_SIZE || len < 0) {
- goto fail;
- }
- s->last_superframe_len = len;
- memcpy(s->last_superframe, buf + pos, len);
- } else {
- /* single frame decode */
- if (wma_decode_frame(s, samples) < 0)
- goto fail;
- samples += s->nb_channels * s->frame_len;
- }
- *data_size = (int8_t *)samples - (int8_t *)data;
- return s->block_align;
- fail:
- /* when error, we reset the bit reservoir */
- s->last_superframe_len = 0;
- return -1;
-}
-
-static int wma_decode_end(AVCodecContext *avctx)
-{
- WMADecodeContext *s = avctx->priv_data;
- int i;
-
- for(i = 0; i < s->nb_block_sizes; i++)
- ff_mdct_end(&s->mdct_ctx[i]);
- for(i = 0; i < s->nb_block_sizes; i++)
- av_free(s->windows[i]);
-
- if (s->use_exp_vlc) {
- free_vlc(&s->exp_vlc);
- }
- if (s->use_noise_coding) {
- free_vlc(&s->hgain_vlc);
- }
- for(i = 0;i < 2; i++) {
- free_vlc(&s->coef_vlc[i]);
- av_free(s->run_table[i]);
- av_free(s->level_table[i]);
- }
-
- return 0;
-}
-
-AVCodec wmav1_decoder =
-{
- "wmav1",
- CODEC_TYPE_AUDIO,
- CODEC_ID_WMAV1,
- sizeof(WMADecodeContext),
- wma_decode_init,
- NULL,
- wma_decode_end,
- wma_decode_superframe,
-};
-
-AVCodec wmav2_decoder =
-{
- "wmav2",
- CODEC_TYPE_AUDIO,
- CODEC_ID_WMAV2,
- sizeof(WMADecodeContext),
- wma_decode_init,
- NULL,
- wma_decode_end,
- wma_decode_superframe,
-};
diff --git a/src/libffmpeg/libavcodec/wmv2.c b/src/libffmpeg/libavcodec/wmv2.c
deleted file mode 100644
index f3d4f0f23..000000000
--- a/src/libffmpeg/libavcodec/wmv2.c
+++ /dev/null
@@ -1,861 +0,0 @@
-/*
- * Copyright (c) 2002 The FFmpeg Project.
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-/**
- * @file wmv2.c
- * wmv2 codec.
- */
-
-#include "simple_idct.h"
-
-#define SKIP_TYPE_NONE 0
-#define SKIP_TYPE_MPEG 1
-#define SKIP_TYPE_ROW 2
-#define SKIP_TYPE_COL 3
-
-
-typedef struct Wmv2Context{
- MpegEncContext s;
- int j_type_bit;
- int j_type;
- int flag3;
- int flag63;
- int abt_flag;
- int abt_type;
- int abt_type_table[6];
- int per_mb_abt;
- int per_block_abt;
- int mspel_bit;
- int cbp_table_index;
- int top_left_mv_flag;
- int per_mb_rl_bit;
- int skip_type;
- int hshift;
-
- ScanTable abt_scantable[2];
- DECLARE_ALIGNED_8(DCTELEM, abt_block2[6][64]);
-}Wmv2Context;
-
-static void wmv2_common_init(Wmv2Context * w){
- MpegEncContext * const s= &w->s;
-
- ff_init_scantable(s->dsp.idct_permutation, &w->abt_scantable[0], wmv2_scantableA);
- ff_init_scantable(s->dsp.idct_permutation, &w->abt_scantable[1], wmv2_scantableB);
-}
-
-#ifdef CONFIG_ENCODERS
-
-static int encode_ext_header(Wmv2Context *w){
- MpegEncContext * const s= &w->s;
- PutBitContext pb;
- int code;
-
- init_put_bits(&pb, s->avctx->extradata, s->avctx->extradata_size);
-
- put_bits(&pb, 5, s->avctx->time_base.den / s->avctx->time_base.num); //yes 29.97 -> 29
- put_bits(&pb, 11, FFMIN(s->bit_rate/1024, 2047));
-
- put_bits(&pb, 1, w->mspel_bit=1);
- put_bits(&pb, 1, w->flag3=1);
- put_bits(&pb, 1, w->abt_flag=1);
- put_bits(&pb, 1, w->j_type_bit=1);
- put_bits(&pb, 1, w->top_left_mv_flag=0);
- put_bits(&pb, 1, w->per_mb_rl_bit=1);
- put_bits(&pb, 3, code=1);
-
- flush_put_bits(&pb);
-
- s->slice_height = s->mb_height / code;
-
- return 0;
-}
-
-static int wmv2_encode_init(AVCodecContext *avctx){
- Wmv2Context * const w= avctx->priv_data;
-
- if(MPV_encode_init(avctx) < 0)
- return -1;
-
- wmv2_common_init(w);
-
- avctx->extradata_size= 4;
- avctx->extradata= av_mallocz(avctx->extradata_size + 10);
- encode_ext_header(w);
-
- return 0;
-}
-
-#if 0 /* unused, remove? */
-static int wmv2_encode_end(AVCodecContext *avctx){
-
- if(MPV_encode_end(avctx) < 0)
- return -1;
-
- avctx->extradata_size= 0;
- av_freep(&avctx->extradata);
-
- return 0;
-}
-#endif
-
-int ff_wmv2_encode_picture_header(MpegEncContext * s, int picture_number)
-{
- Wmv2Context * const w= (Wmv2Context*)s;
-
- put_bits(&s->pb, 1, s->pict_type - 1);
- if(s->pict_type == I_TYPE){
- put_bits(&s->pb, 7, 0);
- }
- put_bits(&s->pb, 5, s->qscale);
-
- s->dc_table_index = 1;
- s->mv_table_index = 1; /* only if P frame */
-// s->use_skip_mb_code = 1; /* only if P frame */
- s->per_mb_rl_table = 0;
- s->mspel= 0;
- w->per_mb_abt=0;
- w->abt_type=0;
- w->j_type=0;
-
- assert(s->flipflop_rounding);
-
- if (s->pict_type == I_TYPE) {
- assert(s->no_rounding==1);
- if(w->j_type_bit) put_bits(&s->pb, 1, w->j_type);
-
- if(w->per_mb_rl_bit) put_bits(&s->pb, 1, s->per_mb_rl_table);
-
- if(!s->per_mb_rl_table){
- code012(&s->pb, s->rl_chroma_table_index);
- code012(&s->pb, s->rl_table_index);
- }
-
- put_bits(&s->pb, 1, s->dc_table_index);
-
- s->inter_intra_pred= 0;
- }else{
- int cbp_index;
-
- put_bits(&s->pb, 2, SKIP_TYPE_NONE);
-
- code012(&s->pb, cbp_index=0);
- if(s->qscale <= 10){
- int map[3]= {0,2,1};
- w->cbp_table_index= map[cbp_index];
- }else if(s->qscale <= 20){
- int map[3]= {1,0,2};
- w->cbp_table_index= map[cbp_index];
- }else{
- int map[3]= {2,1,0};
- w->cbp_table_index= map[cbp_index];
- }
-
- if(w->mspel_bit) put_bits(&s->pb, 1, s->mspel);
-
- if(w->abt_flag){
- put_bits(&s->pb, 1, w->per_mb_abt^1);
- if(!w->per_mb_abt){
- code012(&s->pb, w->abt_type);
- }
- }
-
- if(w->per_mb_rl_bit) put_bits(&s->pb, 1, s->per_mb_rl_table);
-
- if(!s->per_mb_rl_table){
- code012(&s->pb, s->rl_table_index);
- s->rl_chroma_table_index = s->rl_table_index;
- }
- put_bits(&s->pb, 1, s->dc_table_index);
- put_bits(&s->pb, 1, s->mv_table_index);
-
- s->inter_intra_pred= 0;//(s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE);
- }
- s->esc3_level_length= 0;
- s->esc3_run_length= 0;
-
- return 0;
-}
-
-// nearly idential to wmv1 but thats just because we dont use the useless M$ crap features
-// its duplicated here in case someone wants to add support for these carp features
-void ff_wmv2_encode_mb(MpegEncContext * s,
- DCTELEM block[6][64],
- int motion_x, int motion_y)
-{
- Wmv2Context * const w= (Wmv2Context*)s;
- int cbp, coded_cbp, i;
- int pred_x, pred_y;
- uint8_t *coded_block;
-
- handle_slices(s);
-
- if (!s->mb_intra) {
- /* compute cbp */
- cbp = 0;
- for (i = 0; i < 6; i++) {
- if (s->block_last_index[i] >= 0)
- cbp |= 1 << (5 - i);
- }
-
- put_bits(&s->pb,
- wmv2_inter_table[w->cbp_table_index][cbp + 64][1],
- wmv2_inter_table[w->cbp_table_index][cbp + 64][0]);
-
- /* motion vector */
- h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
- msmpeg4_encode_motion(s, motion_x - pred_x,
- motion_y - pred_y);
- } else {
- /* compute cbp */
- cbp = 0;
- coded_cbp = 0;
- for (i = 0; i < 6; i++) {
- int val, pred;
- val = (s->block_last_index[i] >= 1);
- cbp |= val << (5 - i);
- if (i < 4) {
- /* predict value for close blocks only for luma */
- pred = coded_block_pred(s, i, &coded_block);
- *coded_block = val;
- val = val ^ pred;
- }
- coded_cbp |= val << (5 - i);
- }
-#if 0
- if (coded_cbp)
- printf("cbp=%x %x\n", cbp, coded_cbp);
-#endif
-
- if (s->pict_type == I_TYPE) {
- put_bits(&s->pb,
- ff_msmp4_mb_i_table[coded_cbp][1], ff_msmp4_mb_i_table[coded_cbp][0]);
- } else {
- put_bits(&s->pb,
- wmv2_inter_table[w->cbp_table_index][cbp][1],
- wmv2_inter_table[w->cbp_table_index][cbp][0]);
- }
- put_bits(&s->pb, 1, 0); /* no AC prediction yet */
- if(s->inter_intra_pred){
- s->h263_aic_dir=0;
- put_bits(&s->pb, table_inter_intra[s->h263_aic_dir][1], table_inter_intra[s->h263_aic_dir][0]);
- }
- }
-
- for (i = 0; i < 6; i++) {
- msmpeg4_encode_block(s, block[i], i);
- }
-}
-#endif //CONFIG_ENCODERS
-
-static void parse_mb_skip(Wmv2Context * w){
- int mb_x, mb_y;
- MpegEncContext * const s= &w->s;
- uint32_t * const mb_type= s->current_picture_ptr->mb_type;
-
- w->skip_type= get_bits(&s->gb, 2);
- switch(w->skip_type){
- case SKIP_TYPE_NONE:
- for(mb_y=0; mb_y<s->mb_height; mb_y++){
- for(mb_x=0; mb_x<s->mb_width; mb_x++){
- mb_type[mb_y*s->mb_stride + mb_x]= MB_TYPE_16x16 | MB_TYPE_L0;
- }
- }
- break;
- case SKIP_TYPE_MPEG:
- for(mb_y=0; mb_y<s->mb_height; mb_y++){
- for(mb_x=0; mb_x<s->mb_width; mb_x++){
- mb_type[mb_y*s->mb_stride + mb_x]= (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_L0;
- }
- }
- break;
- case SKIP_TYPE_ROW:
- for(mb_y=0; mb_y<s->mb_height; mb_y++){
- if(get_bits1(&s->gb)){
- for(mb_x=0; mb_x<s->mb_width; mb_x++){
- mb_type[mb_y*s->mb_stride + mb_x]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
- }
- }else{
- for(mb_x=0; mb_x<s->mb_width; mb_x++){
- mb_type[mb_y*s->mb_stride + mb_x]= (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_L0;
- }
- }
- }
- break;
- case SKIP_TYPE_COL:
- for(mb_x=0; mb_x<s->mb_width; mb_x++){
- if(get_bits1(&s->gb)){
- for(mb_y=0; mb_y<s->mb_height; mb_y++){
- mb_type[mb_y*s->mb_stride + mb_x]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
- }
- }else{
- for(mb_y=0; mb_y<s->mb_height; mb_y++){
- mb_type[mb_y*s->mb_stride + mb_x]= (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_L0;
- }
- }
- }
- break;
- }
-}
-
-static int decode_ext_header(Wmv2Context *w){
- MpegEncContext * const s= &w->s;
- GetBitContext gb;
- int fps;
- int code;
-
- if(s->avctx->extradata_size<4) return -1;
-
- init_get_bits(&gb, s->avctx->extradata, s->avctx->extradata_size*8);
-
- fps = get_bits(&gb, 5);
- s->bit_rate = get_bits(&gb, 11)*1024;
- w->mspel_bit = get_bits1(&gb);
- w->flag3 = get_bits1(&gb);
- w->abt_flag = get_bits1(&gb);
- w->j_type_bit = get_bits1(&gb);
- w->top_left_mv_flag= get_bits1(&gb);
- w->per_mb_rl_bit = get_bits1(&gb);
- code = get_bits(&gb, 3);
-
- if(code==0) return -1;
-
- s->slice_height = s->mb_height / code;
-
- if(s->avctx->debug&FF_DEBUG_PICT_INFO){
- av_log(s->avctx, AV_LOG_DEBUG, "fps:%d, br:%d, qpbit:%d, abt_flag:%d, j_type_bit:%d, tl_mv_flag:%d, mbrl_bit:%d, code:%d, flag3:%d, slices:%d\n",
- fps, s->bit_rate, w->mspel_bit, w->abt_flag, w->j_type_bit, w->top_left_mv_flag, w->per_mb_rl_bit, code, w->flag3,
- code);
- }
- return 0;
-}
-
-int ff_wmv2_decode_picture_header(MpegEncContext * s)
-{
- Wmv2Context * const w= (Wmv2Context*)s;
- int code;
-
-#if 0
-{
-int i;
-for(i=0; i<s->gb.size*8; i++)
- printf("%d", get_bits1(&s->gb));
-// get_bits1(&s->gb);
-printf("END\n");
-return -1;
-}
-#endif
- if(s->picture_number==0)
- decode_ext_header(w);
-
- s->pict_type = get_bits(&s->gb, 1) + 1;
- if(s->pict_type == I_TYPE){
- code = get_bits(&s->gb, 7);
- av_log(s->avctx, AV_LOG_DEBUG, "I7:%X/\n", code);
- }
- s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
- if(s->qscale < 0)
- return -1;
-
- return 0;
-}
-
-int ff_wmv2_decode_secondary_picture_header(MpegEncContext * s)
-{
- Wmv2Context * const w= (Wmv2Context*)s;
-
- if (s->pict_type == I_TYPE) {
- if(w->j_type_bit) w->j_type= get_bits1(&s->gb);
- else w->j_type= 0; //FIXME check
-
- if(!w->j_type){
- if(w->per_mb_rl_bit) s->per_mb_rl_table= get_bits1(&s->gb);
- else s->per_mb_rl_table= 0;
-
- if(!s->per_mb_rl_table){
- s->rl_chroma_table_index = decode012(&s->gb);
- s->rl_table_index = decode012(&s->gb);
- }
-
- s->dc_table_index = get_bits1(&s->gb);
- }
- s->inter_intra_pred= 0;
- s->no_rounding = 1;
- if(s->avctx->debug&FF_DEBUG_PICT_INFO){
- av_log(s->avctx, AV_LOG_DEBUG, "qscale:%d rlc:%d rl:%d dc:%d mbrl:%d j_type:%d \n",
- s->qscale,
- s->rl_chroma_table_index,
- s->rl_table_index,
- s->dc_table_index,
- s->per_mb_rl_table,
- w->j_type);
- }
- }else{
- int cbp_index;
- w->j_type=0;
-
- parse_mb_skip(w);
- cbp_index= decode012(&s->gb);
- if(s->qscale <= 10){
- int map[3]= {0,2,1};
- w->cbp_table_index= map[cbp_index];
- }else if(s->qscale <= 20){
- int map[3]= {1,0,2};
- w->cbp_table_index= map[cbp_index];
- }else{
- int map[3]= {2,1,0};
- w->cbp_table_index= map[cbp_index];
- }
-
- if(w->mspel_bit) s->mspel= get_bits1(&s->gb);
- else s->mspel= 0; //FIXME check
-
- if(w->abt_flag){
- w->per_mb_abt= get_bits1(&s->gb)^1;
- if(!w->per_mb_abt){
- w->abt_type= decode012(&s->gb);
- }
- }
-
- if(w->per_mb_rl_bit) s->per_mb_rl_table= get_bits1(&s->gb);
- else s->per_mb_rl_table= 0;
-
- if(!s->per_mb_rl_table){
- s->rl_table_index = decode012(&s->gb);
- s->rl_chroma_table_index = s->rl_table_index;
- }
-
- s->dc_table_index = get_bits1(&s->gb);
- s->mv_table_index = get_bits1(&s->gb);
-
- s->inter_intra_pred= 0;//(s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE);
- s->no_rounding ^= 1;
-
- if(s->avctx->debug&FF_DEBUG_PICT_INFO){
- av_log(s->avctx, AV_LOG_DEBUG, "rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d mspel:%d per_mb_abt:%d abt_type:%d cbp:%d ii:%d\n",
- s->rl_table_index,
- s->rl_chroma_table_index,
- s->dc_table_index,
- s->mv_table_index,
- s->per_mb_rl_table,
- s->qscale,
- s->mspel,
- w->per_mb_abt,
- w->abt_type,
- w->cbp_table_index,
- s->inter_intra_pred);
- }
- }
- s->esc3_level_length= 0;
- s->esc3_run_length= 0;
-
-s->picture_number++; //FIXME ?
-
-
-// if(w->j_type)
-// return wmv2_decode_j_picture(w); //FIXME
-
- if(w->j_type){
- av_log(s->avctx, AV_LOG_ERROR, "J-type picture is not supported\n");
- return -1;
- }
-
- return 0;
-}
-
-static inline int wmv2_decode_motion(Wmv2Context *w, int *mx_ptr, int *my_ptr){
- MpegEncContext * const s= &w->s;
- int ret;
-
- ret= msmpeg4_decode_motion(s, mx_ptr, my_ptr);
-
- if(ret<0) return -1;
-
- if((((*mx_ptr)|(*my_ptr)) & 1) && s->mspel)
- w->hshift= get_bits1(&s->gb);
- else
- w->hshift= 0;
-
-//printf("%d %d ", *mx_ptr, *my_ptr);
-
- return 0;
-}
-
-static int16_t *wmv2_pred_motion(Wmv2Context *w, int *px, int *py){
- MpegEncContext * const s= &w->s;
- int xy, wrap, diff, type;
- int16_t *A, *B, *C, *mot_val;
-
- wrap = s->b8_stride;
- xy = s->block_index[0];
-
- mot_val = s->current_picture.motion_val[0][xy];
-
- A = s->current_picture.motion_val[0][xy - 1];
- B = s->current_picture.motion_val[0][xy - wrap];
- C = s->current_picture.motion_val[0][xy + 2 - wrap];
-
- if(s->mb_x && !s->first_slice_line && !s->mspel && w->top_left_mv_flag)
- diff= FFMAX(FFABS(A[0] - B[0]), FFABS(A[1] - B[1]));
- else
- diff=0;
-
- if(diff >= 8)
- type= get_bits1(&s->gb);
- else
- type= 2;
-
- if(type == 0){
- *px= A[0];
- *py= A[1];
- }else if(type == 1){
- *px= B[0];
- *py= B[1];
- }else{
- /* special case for first (slice) line */
- if (s->first_slice_line) {
- *px = A[0];
- *py = A[1];
- } else {
- *px = mid_pred(A[0], B[0], C[0]);
- *py = mid_pred(A[1], B[1], C[1]);
- }
- }
-
- return mot_val;
-}
-
-static inline int wmv2_decode_inter_block(Wmv2Context *w, DCTELEM *block, int n, int cbp){
- MpegEncContext * const s= &w->s;
- static const int sub_cbp_table[3]= {2,3,1};
- int sub_cbp;
-
- if(!cbp){
- s->block_last_index[n] = -1;
-
- return 0;
- }
-
- if(w->per_block_abt)
- w->abt_type= decode012(&s->gb);
-#if 0
- if(w->per_block_abt)
- printf("B%d", w->abt_type);
-#endif
- w->abt_type_table[n]= w->abt_type;
-
- if(w->abt_type){
-// const uint8_t *scantable= w->abt_scantable[w->abt_type-1].permutated;
- const uint8_t *scantable= w->abt_scantable[w->abt_type-1].scantable;
-// const uint8_t *scantable= w->abt_type-1 ? w->abt_scantable[1].permutated : w->abt_scantable[0].scantable;
-
- sub_cbp= sub_cbp_table[ decode012(&s->gb) ];
-// printf("S%d", sub_cbp);
-
- if(sub_cbp&1){
- if (msmpeg4_decode_block(s, block, n, 1, scantable) < 0)
- return -1;
- }
-
- if(sub_cbp&2){
- if (msmpeg4_decode_block(s, w->abt_block2[n], n, 1, scantable) < 0)
- return -1;
- }
- s->block_last_index[n] = 63;
-
- return 0;
- }else{
- return msmpeg4_decode_block(s, block, n, 1, s->inter_scantable.permutated);
- }
-}
-
-static void wmv2_add_block(Wmv2Context *w, DCTELEM *block1, uint8_t *dst, int stride, int n){
- MpegEncContext * const s= &w->s;
-
- if (s->block_last_index[n] >= 0) {
- switch(w->abt_type_table[n]){
- case 0:
- s->dsp.idct_add (dst, stride, block1);
- break;
- case 1:
- simple_idct84_add(dst , stride, block1);
- simple_idct84_add(dst + 4*stride, stride, w->abt_block2[n]);
- memset(w->abt_block2[n], 0, 64*sizeof(DCTELEM));
- break;
- case 2:
- simple_idct48_add(dst , stride, block1);
- simple_idct48_add(dst + 4 , stride, w->abt_block2[n]);
- memset(w->abt_block2[n], 0, 64*sizeof(DCTELEM));
- break;
- default:
- av_log(s->avctx, AV_LOG_ERROR, "internal error in WMV2 abt\n");
- }
- }
-}
-
-void ff_wmv2_add_mb(MpegEncContext *s, DCTELEM block1[6][64], uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr){
- Wmv2Context * const w= (Wmv2Context*)s;
-
- wmv2_add_block(w, block1[0], dest_y , s->linesize, 0);
- wmv2_add_block(w, block1[1], dest_y + 8 , s->linesize, 1);
- wmv2_add_block(w, block1[2], dest_y + 8*s->linesize, s->linesize, 2);
- wmv2_add_block(w, block1[3], dest_y + 8 + 8*s->linesize, s->linesize, 3);
-
- if(s->flags&CODEC_FLAG_GRAY) return;
-
- wmv2_add_block(w, block1[4], dest_cb , s->uvlinesize, 4);
- wmv2_add_block(w, block1[5], dest_cr , s->uvlinesize, 5);
-}
-
-void ff_mspel_motion(MpegEncContext *s,
- uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
- uint8_t **ref_picture, op_pixels_func (*pix_op)[4],
- int motion_x, int motion_y, int h)
-{
- Wmv2Context * const w= (Wmv2Context*)s;
- uint8_t *ptr;
- int dxy, offset, mx, my, src_x, src_y, v_edge_pos, linesize, uvlinesize;
- int emu=0;
-
- dxy = ((motion_y & 1) << 1) | (motion_x & 1);
- dxy = 2*dxy + w->hshift;
- src_x = s->mb_x * 16 + (motion_x >> 1);
- src_y = s->mb_y * 16 + (motion_y >> 1);
-
- /* WARNING: do no forget half pels */
- v_edge_pos = s->v_edge_pos;
- src_x = clip(src_x, -16, s->width);
- src_y = clip(src_y, -16, s->height);
-
- if(src_x<=-16 || src_x >= s->width)
- dxy &= ~3;
- if(src_y<=-16 || src_y >= s->height)
- dxy &= ~4;
-
- linesize = s->linesize;
- uvlinesize = s->uvlinesize;
- ptr = ref_picture[0] + (src_y * linesize) + src_x;
-
- if(s->flags&CODEC_FLAG_EMU_EDGE){
- if(src_x<1 || src_y<1 || src_x + 17 >= s->h_edge_pos
- || src_y + h+1 >= v_edge_pos){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr - 1 - s->linesize, s->linesize, 19, 19,
- src_x-1, src_y-1, s->h_edge_pos, s->v_edge_pos);
- ptr= s->edge_emu_buffer + 1 + s->linesize;
- emu=1;
- }
- }
-
- s->dsp.put_mspel_pixels_tab[dxy](dest_y , ptr , linesize);
- s->dsp.put_mspel_pixels_tab[dxy](dest_y+8 , ptr+8 , linesize);
- s->dsp.put_mspel_pixels_tab[dxy](dest_y +8*linesize, ptr +8*linesize, linesize);
- s->dsp.put_mspel_pixels_tab[dxy](dest_y+8+8*linesize, ptr+8+8*linesize, linesize);
-
- if(s->flags&CODEC_FLAG_GRAY) return;
-
- if (s->out_format == FMT_H263) {
- dxy = 0;
- if ((motion_x & 3) != 0)
- dxy |= 1;
- if ((motion_y & 3) != 0)
- dxy |= 2;
- mx = motion_x >> 2;
- my = motion_y >> 2;
- } else {
- mx = motion_x / 2;
- my = motion_y / 2;
- dxy = ((my & 1) << 1) | (mx & 1);
- mx >>= 1;
- my >>= 1;
- }
-
- src_x = s->mb_x * 8 + mx;
- src_y = s->mb_y * 8 + my;
- src_x = clip(src_x, -8, s->width >> 1);
- if (src_x == (s->width >> 1))
- dxy &= ~1;
- src_y = clip(src_y, -8, s->height >> 1);
- if (src_y == (s->height >> 1))
- dxy &= ~2;
- offset = (src_y * uvlinesize) + src_x;
- ptr = ref_picture[1] + offset;
- if(emu){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9,
- src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
- ptr= s->edge_emu_buffer;
- }
- pix_op[1][dxy](dest_cb, ptr, uvlinesize, h >> 1);
-
- ptr = ref_picture[2] + offset;
- if(emu){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9,
- src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
- ptr= s->edge_emu_buffer;
- }
- pix_op[1][dxy](dest_cr, ptr, uvlinesize, h >> 1);
-}
-
-
-static int wmv2_decode_mb(MpegEncContext *s, DCTELEM block[6][64])
-{
- Wmv2Context * const w= (Wmv2Context*)s;
- int cbp, code, i;
- uint8_t *coded_val;
-
- if(w->j_type) return 0;
-
- if (s->pict_type == P_TYPE) {
- if(IS_SKIP(s->current_picture.mb_type[s->mb_y * s->mb_stride + s->mb_x])){
- /* 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;
- w->hshift=0;
- return 0;
- }
-
- code = get_vlc2(&s->gb, mb_non_intra_vlc[w->cbp_table_index].table, MB_NON_INTRA_VLC_BITS, 3);
- if (code < 0)
- return -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){
- av_log(s->avctx, AV_LOG_ERROR, "II-cbp illegal at %d %d\n", s->mb_x, s->mb_y);
- 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 = 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);
- wmv2_pred_motion(w, &mx, &my);
-
- if(cbp){
- s->dsp.clear_blocks(s->block[0]);
- if(s->per_mb_rl_table){
- s->rl_table_index = decode012(&s->gb);
- s->rl_chroma_table_index = s->rl_table_index;
- }
-
- if(w->abt_flag && w->per_mb_abt){
- w->per_block_abt= get_bits1(&s->gb);
- if(!w->per_block_abt)
- w->abt_type= decode012(&s->gb);
- }else
- w->per_block_abt=0;
- }
-
- if (wmv2_decode_motion(w, &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;
-
- for (i = 0; i < 6; i++) {
- if (wmv2_decode_inter_block(w, block[i], i, (cbp >> (5 - i)) & 1) < 0)
- {
- av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding inter block: %d x %d (%d)\n", s->mb_x, s->mb_y, i);
- return -1;
- }
- }
- } else {
-//if(s->pict_type==P_TYPE)
-// printf("%d%d ", s->inter_intra_pred, cbp);
-//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);
- if(s->inter_intra_pred){
- s->h263_aic_dir= get_vlc2(&s->gb, 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 (msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
- {
- av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding intra block: %d x %d (%d)\n", s->mb_x, s->mb_y, i);
- return -1;
- }
- }
- }
-
- return 0;
-}
-
-static int wmv2_decode_init(AVCodecContext *avctx){
- Wmv2Context * const w= avctx->priv_data;
-
- if(ff_h263_decode_init(avctx) < 0)
- return -1;
-
- wmv2_common_init(w);
-
- return 0;
-}
-
-AVCodec wmv2_decoder = {
- "wmv2",
- CODEC_TYPE_VIDEO,
- CODEC_ID_WMV2,
- sizeof(Wmv2Context),
- wmv2_decode_init,
- NULL,
- ff_h263_decode_end,
- ff_h263_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
-};
-
-#ifdef CONFIG_ENCODERS
-AVCodec wmv2_encoder = {
- "wmv2",
- CODEC_TYPE_VIDEO,
- CODEC_ID_WMV2,
- sizeof(Wmv2Context),
- wmv2_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
- .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1},
-};
-#endif
diff --git a/src/libffmpeg/libavcodec/zmbv.c b/src/libffmpeg/libavcodec/zmbv.c
deleted file mode 100644
index 3b87c7db1..000000000
--- a/src/libffmpeg/libavcodec/zmbv.c
+++ /dev/null
@@ -1,692 +0,0 @@
-/*
- * Zip Motion Blocks Video (ZMBV) decoder
- * Copyright (c) 2006 Konstantin Shishkov
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-/**
- * @file zmbv.c
- * Zip Motion Blocks Video decoder
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "common.h"
-#include "avcodec.h"
-
-#ifdef CONFIG_ZLIB
-#include <zlib.h>
-#endif
-
-#define ZMBV_KEYFRAME 1
-#define ZMBV_DELTAPAL 2
-
-enum ZmbvFormat {
- ZMBV_FMT_NONE = 0,
- ZMBV_FMT_1BPP = 1,
- ZMBV_FMT_2BPP = 2,
- ZMBV_FMT_4BPP = 3,
- ZMBV_FMT_8BPP = 4,
- ZMBV_FMT_15BPP = 5,
- ZMBV_FMT_16BPP = 6,
- ZMBV_FMT_24BPP = 7,
- ZMBV_FMT_32BPP = 8
-};
-
-/*
- * Decoder context
- */
-typedef struct ZmbvContext {
- AVCodecContext *avctx;
- AVFrame pic;
-
- int bpp;
- unsigned int decomp_size;
- uint8_t* decomp_buf;
- uint8_t pal[768];
- uint8_t *prev, *cur;
- int width, height;
- int fmt;
- int comp;
- int flags;
- int bw, bh, bx, by;
- int decomp_len;
-#ifdef CONFIG_ZLIB
- z_stream zstream;
-#endif
- int (*decode_intra)(struct ZmbvContext *c);
- int (*decode_xor)(struct ZmbvContext *c);
-} ZmbvContext;
-
-/**
- * Decode XOR'ed frame - 8bpp version
- */
-
-static int zmbv_decode_xor_8(ZmbvContext *c)
-{
- uint8_t *src = c->decomp_buf;
- uint8_t *output, *prev;
- int8_t *mvec;
- int x, y;
- int d, dx, dy, bw2, bh2;
- int block;
- int i, j;
- int mx, my;
-
- output = c->cur;
- prev = c->prev;
-
- if(c->flags & ZMBV_DELTAPAL){
- for(i = 0; i < 768; i++)
- c->pal[i] ^= *src++;
- }
-
- mvec = (int8_t*)src;
- src += ((c->bx * c->by * 2 + 3) & ~3);
-
- block = 0;
- for(y = 0; y < c->height; y += c->bh) {
- bh2 = ((c->height - y) > c->bh) ? c->bh : (c->height - y);
- for(x = 0; x < c->width; x += c->bw) {
- uint8_t *out, *tprev;
-
- d = mvec[block] & 1;
- dx = mvec[block] >> 1;
- dy = mvec[block + 1] >> 1;
- block += 2;
-
- bw2 = ((c->width - x) > c->bw) ? c->bw : (c->width - x);
-
- /* copy block - motion vectors out of bounds are used to zero blocks */
- out = output + x;
- tprev = prev + x + dx + dy * c->width;
- mx = x + dx;
- my = y + dy;
- for(j = 0; j < bh2; j++){
- if((my + j < 0) || (my + j >= c->height)) {
- memset(out, 0, bw2);
- } else {
- for(i = 0; i < bw2; i++){
- if((mx + i < 0) || (mx + i >= c->width))
- out[i] = 0;
- else
- out[i] = tprev[i];
- }
- }
- out += c->width;
- tprev += c->width;
- }
-
- if(d) { /* apply XOR'ed difference */
- out = output + x;
- for(j = 0; j < bh2; j++){
- for(i = 0; i < bw2; i++)
- out[i] ^= *src++;
- out += c->width;
- }
- }
- }
- output += c->width * c->bh;
- prev += c->width * c->bh;
- }
- if(src - c->decomp_buf != c->decomp_len)
- av_log(c->avctx, AV_LOG_ERROR, "Used %i of %i bytes\n", src-c->decomp_buf, c->decomp_len);
- return 0;
-}
-
-/**
- * Decode XOR'ed frame - 15bpp and 16bpp version
- */
-
-static int zmbv_decode_xor_16(ZmbvContext *c)
-{
- uint8_t *src = c->decomp_buf;
- uint16_t *output, *prev;
- int8_t *mvec;
- int x, y;
- int d, dx, dy, bw2, bh2;
- int block;
- int i, j;
- int mx, my;
-
- output = (uint16_t*)c->cur;
- prev = (uint16_t*)c->prev;
-
- mvec = (int8_t*)src;
- src += ((c->bx * c->by * 2 + 3) & ~3);
-
- block = 0;
- for(y = 0; y < c->height; y += c->bh) {
- bh2 = ((c->height - y) > c->bh) ? c->bh : (c->height - y);
- for(x = 0; x < c->width; x += c->bw) {
- uint16_t *out, *tprev;
-
- d = mvec[block] & 1;
- dx = mvec[block] >> 1;
- dy = mvec[block + 1] >> 1;
- block += 2;
-
- bw2 = ((c->width - x) > c->bw) ? c->bw : (c->width - x);
-
- /* copy block - motion vectors out of bounds are used to zero blocks */
- out = output + x;
- tprev = prev + x + dx + dy * c->width;
- mx = x + dx;
- my = y + dy;
- for(j = 0; j < bh2; j++){
- if((my + j < 0) || (my + j >= c->height)) {
- memset(out, 0, bw2 * 2);
- } else {
- for(i = 0; i < bw2; i++){
- if((mx + i < 0) || (mx + i >= c->width))
- out[i] = 0;
- else
- out[i] = tprev[i];
- }
- }
- out += c->width;
- tprev += c->width;
- }
-
- if(d) { /* apply XOR'ed difference */
- out = output + x;
- for(j = 0; j < bh2; j++){
- for(i = 0; i < bw2; i++) {
- out[i] ^= *((uint16_t*)src);
- src += 2;
- }
- out += c->width;
- }
- }
- }
- output += c->width * c->bh;
- prev += c->width * c->bh;
- }
- if(src - c->decomp_buf != c->decomp_len)
- av_log(c->avctx, AV_LOG_ERROR, "Used %i of %i bytes\n", src-c->decomp_buf, c->decomp_len);
- return 0;
-}
-
-#ifdef ZMBV_ENABLE_24BPP
-/**
- * Decode XOR'ed frame - 24bpp version
- */
-
-static int zmbv_decode_xor_24(ZmbvContext *c)
-{
- uint8_t *src = c->decomp_buf;
- uint8_t *output, *prev;
- int8_t *mvec;
- int x, y;
- int d, dx, dy, bw2, bh2;
- int block;
- int i, j;
- int mx, my;
- int stride;
-
- output = c->cur;
- prev = c->prev;
-
- stride = c->width * 3;
- mvec = (int8_t*)src;
- src += ((c->bx * c->by * 2 + 3) & ~3);
-
- block = 0;
- for(y = 0; y < c->height; y += c->bh) {
- bh2 = ((c->height - y) > c->bh) ? c->bh : (c->height - y);
- for(x = 0; x < c->width; x += c->bw) {
- uint8_t *out, *tprev;
-
- d = mvec[block] & 1;
- dx = mvec[block] >> 1;
- dy = mvec[block + 1] >> 1;
- block += 2;
-
- bw2 = ((c->width - x) > c->bw) ? c->bw : (c->width - x);
-
- /* copy block - motion vectors out of bounds are used to zero blocks */
- out = output + x * 3;
- tprev = prev + (x + dx) * 3 + dy * stride;
- mx = x + dx;
- my = y + dy;
- for(j = 0; j < bh2; j++){
- if((my + j < 0) || (my + j >= c->height)) {
- memset(out, 0, bw2 * 3);
- } else {
- for(i = 0; i < bw2; i++){
- if((mx + i < 0) || (mx + i >= c->width)) {
- out[i * 3 + 0] = 0;
- out[i * 3 + 1] = 0;
- out[i * 3 + 2] = 0;
- } else {
- out[i * 3 + 0] = tprev[i * 3 + 0];
- out[i * 3 + 1] = tprev[i * 3 + 1];
- out[i * 3 + 2] = tprev[i * 3 + 2];
- }
- }
- }
- out += stride;
- tprev += stride;
- }
-
- if(d) { /* apply XOR'ed difference */
- out = output + x * 3;
- for(j = 0; j < bh2; j++){
- for(i = 0; i < bw2; i++) {
- out[i * 3 + 0] ^= *src++;
- out[i * 3 + 1] ^= *src++;
- out[i * 3 + 2] ^= *src++;
- }
- out += stride;
- }
- }
- }
- output += stride * c->bh;
- prev += stride * c->bh;
- }
- if(src - c->decomp_buf != c->decomp_len)
- av_log(c->avctx, AV_LOG_ERROR, "Used %i of %i bytes\n", src-c->decomp_buf, c->decomp_len);
- return 0;
-}
-#endif //ZMBV_ENABLE_24BPP
-
-/**
- * Decode XOR'ed frame - 32bpp version
- */
-
-static int zmbv_decode_xor_32(ZmbvContext *c)
-{
- uint8_t *src = c->decomp_buf;
- uint32_t *output, *prev;
- int8_t *mvec;
- int x, y;
- int d, dx, dy, bw2, bh2;
- int block;
- int i, j;
- int mx, my;
-
- output = (uint32_t*)c->cur;
- prev = (uint32_t*)c->prev;
-
- mvec = (int8_t*)src;
- src += ((c->bx * c->by * 2 + 3) & ~3);
-
- block = 0;
- for(y = 0; y < c->height; y += c->bh) {
- bh2 = ((c->height - y) > c->bh) ? c->bh : (c->height - y);
- for(x = 0; x < c->width; x += c->bw) {
- uint32_t *out, *tprev;
-
- d = mvec[block] & 1;
- dx = mvec[block] >> 1;
- dy = mvec[block + 1] >> 1;
- block += 2;
-
- bw2 = ((c->width - x) > c->bw) ? c->bw : (c->width - x);
-
- /* copy block - motion vectors out of bounds are used to zero blocks */
- out = output + x;
- tprev = prev + x + dx + dy * c->width;
- mx = x + dx;
- my = y + dy;
- for(j = 0; j < bh2; j++){
- if((my + j < 0) || (my + j >= c->height)) {
- memset(out, 0, bw2 * 4);
- } else {
- for(i = 0; i < bw2; i++){
- if((mx + i < 0) || (mx + i >= c->width))
- out[i] = 0;
- else
- out[i] = tprev[i];
- }
- }
- out += c->width;
- tprev += c->width;
- }
-
- if(d) { /* apply XOR'ed difference */
- out = output + x;
- for(j = 0; j < bh2; j++){
- for(i = 0; i < bw2; i++) {
- out[i] ^= *((uint32_t*)src);
- src += 4;
- }
- out += c->width;
- }
- }
- }
- output += c->width * c->bh;
- prev += c->width * c->bh;
- }
- if(src - c->decomp_buf != c->decomp_len)
- av_log(c->avctx, AV_LOG_ERROR, "Used %i of %i bytes\n", src-c->decomp_buf, c->decomp_len);
- return 0;
-}
-
-/**
- * Decode intraframe
- */
-static int zmbv_decode_intra(ZmbvContext *c)
-{
- uint8_t *src = c->decomp_buf;
-
- /* make the palette available on the way out */
- if (c->fmt == ZMBV_FMT_8BPP) {
- memcpy(c->pal, src, 768);
- src += 768;
- }
-
- memcpy(c->cur, src, c->width * c->height * (c->bpp / 8));
- return 0;
-}
-
-static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size)
-{
- ZmbvContext * const c = (ZmbvContext *)avctx->priv_data;
- uint8_t *outptr;
-#ifdef CONFIG_ZLIB
- int zret = Z_OK; // Zlib return code
-#endif
- int len = buf_size;
- int hi_ver, lo_ver;
-
- if(c->pic.data[0])
- avctx->release_buffer(avctx, &c->pic);
-
- c->pic.reference = 1;
- c->pic.buffer_hints = FF_BUFFER_HINTS_VALID;
- if(avctx->get_buffer(avctx, &c->pic) < 0){
- av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
- return -1;
- }
-
- outptr = c->pic.data[0]; // Output image pointer
-
- /* parse header */
- c->flags = buf[0];
- buf++; len--;
- if(c->flags & ZMBV_KEYFRAME) {
- hi_ver = buf[0];
- lo_ver = buf[1];
- c->comp = buf[2];
- c->fmt = buf[3];
- c->bw = buf[4];
- c->bh = buf[5];
-
- buf += 6;
- len -= 6;
- av_log(avctx, AV_LOG_DEBUG, "Flags=%X ver=%i.%i comp=%i fmt=%i blk=%ix%i\n",c->flags,hi_ver,lo_ver,c->comp,c->fmt,c->bw,c->bh);
- if(hi_ver != 0 || lo_ver != 1) {
- av_log(avctx, AV_LOG_ERROR, "Unsupported version %i.%i\n", hi_ver, lo_ver);
- return -1;
- }
- if(c->bw == 0 || c->bh == 0) {
- av_log(avctx, AV_LOG_ERROR, "Unsupported block size %ix%i\n", c->bw, c->bh);
- }
- if(c->comp != 0 && c->comp != 1) {
- av_log(avctx, AV_LOG_ERROR, "Unsupported compression type %i\n", c->comp);
- return -1;
- }
-
- switch(c->fmt) {
- case ZMBV_FMT_8BPP:
- c->bpp = 8;
- c->decode_intra = zmbv_decode_intra;
- c->decode_xor = zmbv_decode_xor_8;
- break;
- case ZMBV_FMT_15BPP:
- case ZMBV_FMT_16BPP:
- c->bpp = 16;
- c->decode_intra = zmbv_decode_intra;
- c->decode_xor = zmbv_decode_xor_16;
- break;
-#ifdef ZMBV_ENABLE_24BPP
- case ZMBV_FMT_24BPP:
- c->bpp = 24;
- c->decode_intra = zmbv_decode_intra;
- c->decode_xor = zmbv_decode_xor_24;
- break;
-#endif //ZMBV_ENABLE_24BPP
- case ZMBV_FMT_32BPP:
- c->bpp = 32;
- c->decode_intra = zmbv_decode_intra;
- c->decode_xor = zmbv_decode_xor_32;
- break;
- default:
- c->decode_intra = NULL;
- c->decode_xor = NULL;
- av_log(avctx, AV_LOG_ERROR, "Unsupported (for now) format %i\n", c->fmt);
- return -1;
- }
-#ifdef CONFIG_ZLIB
- zret = inflateReset(&c->zstream);
- if (zret != Z_OK) {
- av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret);
- return -1;
- }
-#else
- av_log(avctx, AV_LOG_ERROR, "BUG! Zlib support not compiled in frame decoder.\n");
- return -1;
-#endif /* CONFIG_ZLIB */
- c->cur = av_realloc(c->cur, avctx->width * avctx->height * (c->bpp / 8));
- c->prev = av_realloc(c->prev, avctx->width * avctx->height * (c->bpp / 8));
- c->bx = (c->width + c->bw - 1) / c->bw;
- c->by = (c->height+ c->bh - 1) / c->bh;
- }
-
- if(c->decode_intra == NULL) {
- av_log(avctx, AV_LOG_ERROR, "Error! Got no format or no keyframe!\n");
- return -1;
- }
-
- if(c->comp == 0) { //Uncompressed data
- memcpy(c->decomp_buf, buf, len);
- c->decomp_size = 1;
- } else { // ZLIB-compressed data
-#ifdef CONFIG_ZLIB
- c->zstream.total_in = c->zstream.total_out = 0;
- c->zstream.next_in = buf;
- c->zstream.avail_in = len;
- c->zstream.next_out = c->decomp_buf;
- c->zstream.avail_out = c->decomp_size;
- inflate(&c->zstream, Z_FINISH);
- c->decomp_len = c->zstream.total_out;
-#else
- av_log(avctx, AV_LOG_ERROR, "BUG! Zlib support not compiled in frame decoder.\n");
- return -1;
-#endif
- }
- if(c->flags & ZMBV_KEYFRAME) {
- c->pic.key_frame = 1;
- c->pic.pict_type = FF_I_TYPE;
- c->decode_intra(c);
- } else {
- c->pic.key_frame = 0;
- c->pic.pict_type = FF_P_TYPE;
- c->decode_xor(c);
- }
-
- /* update frames */
- {
- uint8_t *out, *src;
- int i, j;
-
- out = c->pic.data[0];
- src = c->cur;
- switch(c->fmt) {
- case ZMBV_FMT_8BPP:
- for(j = 0; j < c->height; j++) {
- for(i = 0; i < c->width; i++) {
- out[i * 3 + 0] = c->pal[(*src) * 3 + 0];
- out[i * 3 + 1] = c->pal[(*src) * 3 + 1];
- out[i * 3 + 2] = c->pal[(*src) * 3 + 2];
- *src++;
- }
- out += c->pic.linesize[0];
- }
- break;
- case ZMBV_FMT_15BPP:
- for(j = 0; j < c->height; j++) {
- for(i = 0; i < c->width; i++) {
- uint16_t tmp = AV_RL16(src);
- src += 2;
- out[i * 3 + 0] = (tmp & 0x7C00) >> 7;
- out[i * 3 + 1] = (tmp & 0x03E0) >> 2;
- out[i * 3 + 2] = (tmp & 0x001F) << 3;
- }
- out += c->pic.linesize[0];
- }
- break;
- case ZMBV_FMT_16BPP:
- for(j = 0; j < c->height; j++) {
- for(i = 0; i < c->width; i++) {
- uint16_t tmp = AV_RL16(src);
- src += 2;
- out[i * 3 + 0] = (tmp & 0xF800) >> 8;
- out[i * 3 + 1] = (tmp & 0x07E0) >> 3;
- out[i * 3 + 2] = (tmp & 0x001F) << 3;
- }
- out += c->pic.linesize[0];
- }
- break;
-#ifdef ZMBV_ENABLE_24BPP
- case ZMBV_FMT_24BPP:
- for(j = 0; j < c->height; j++) {
- memcpy(out, src, c->width * 3);
- src += c->width * 3;
- out += c->pic.linesize[0];
- }
- break;
-#endif //ZMBV_ENABLE_24BPP
- case ZMBV_FMT_32BPP:
- for(j = 0; j < c->height; j++) {
- for(i = 0; i < c->width; i++) {
- uint32_t tmp = AV_RL32(src);
- src += 4;
- out[i * 3 + 0] = tmp >> 16;
- out[i * 3 + 1] = tmp >> 8;
- out[i * 3 + 2] = tmp >> 0;
- }
- out += c->pic.linesize[0];
- }
- break;
- default:
- av_log(avctx, AV_LOG_ERROR, "Cannot handle format %i\n", c->fmt);
- }
- memcpy(c->prev, c->cur, c->width * c->height * (c->bpp / 8));
- }
- *data_size = sizeof(AVFrame);
- *(AVFrame*)data = c->pic;
-
- /* always report that the buffer was completely consumed */
- return buf_size;
-}
-
-
-
-/*
- *
- * Init zmbv decoder
- *
- */
-static int decode_init(AVCodecContext *avctx)
-{
- ZmbvContext * const c = (ZmbvContext *)avctx->priv_data;
- int zret; // Zlib return code
-
- c->avctx = avctx;
- avctx->has_b_frames = 0;
-
- c->pic.data[0] = NULL;
- 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_sample;
-
-#ifdef CONFIG_ZLIB
- // Needed if zlib unused or init aborted before inflateInit
- memset(&(c->zstream), 0, sizeof(z_stream));
-#else
- av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled.\n");
- return 1;
-#endif
- avctx->pix_fmt = PIX_FMT_RGB24;
- c->decomp_size = (avctx->width + 255) * 4 * (avctx->height + 64);
-
- /* Allocate decompression buffer */
- if (c->decomp_size) {
- if ((c->decomp_buf = av_malloc(c->decomp_size)) == NULL) {
- av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
- return 1;
- }
- }
-
-#ifdef CONFIG_ZLIB
- c->zstream.zalloc = Z_NULL;
- c->zstream.zfree = Z_NULL;
- c->zstream.opaque = Z_NULL;
- zret = inflateInit(&(c->zstream));
- if (zret != Z_OK) {
- av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
- return 1;
- }
-#endif
-
- return 0;
-}
-
-
-
-/*
- *
- * Uninit zmbv decoder
- *
- */
-static int decode_end(AVCodecContext *avctx)
-{
- ZmbvContext * const c = (ZmbvContext *)avctx->priv_data;
-
- av_freep(&c->decomp_buf);
-
- if (c->pic.data[0])
- avctx->release_buffer(avctx, &c->pic);
-#ifdef CONFIG_ZLIB
- inflateEnd(&(c->zstream));
-#endif
- av_freep(&c->cur);
- av_freep(&c->prev);
-
- return 0;
-}
-
-AVCodec zmbv_decoder = {
- "zmbv",
- CODEC_TYPE_VIDEO,
- CODEC_ID_ZMBV,
- sizeof(ZmbvContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame
-};
-
diff --git a/src/libffmpeg/libavutil/Makefile.am b/src/libffmpeg/libavutil/Makefile.am
deleted file mode 100644
index 6010a8134..000000000
--- a/src/libffmpeg/libavutil/Makefile.am
+++ /dev/null
@@ -1,38 +0,0 @@
-include $(top_srcdir)/misc/Makefile.common
-
-AM_CPPFLAGS = $(LIBFFMPEG_CPPFLAGS) -I$(top_srcdir)/src/libffmpeg \
- -I$(top_builddir)/src/libffmpeg
-AM_CFLAGS = -fno-strict-aliasing
-ASFLAGS =
-
-noinst_LTLIBRARIES = libavutil.la
-
-libavutil_la_SOURCES = \
- adler32.c \
- crc.c \
- integer.c \
- lls.c \
- log.c \
- mathematics.c \
- md5.c \
- mem.c \
- rational.c
-
-libavutil_la_LDFLAGS = -avoid-version -module
-
-noinst_HEADERS = \
- adler32.h \
- avutil.h \
- bswap.h \
- common.h \
- crc.h \
- integer.h \
- internal.h \
- intfloat_readwrite.h \
- intreadwrite.h \
- lls.h \
- log.h \
- mathematics.h \
- md5.h \
- rational.h \
- x86_cpu.h
diff --git a/src/libffmpeg/libavutil/avutil.h b/src/libffmpeg/libavutil/avutil.h
deleted file mode 100644
index d5a4570dc..000000000
--- a/src/libffmpeg/libavutil/avutil.h
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef AVUTIL_H
-#define AVUTIL_H
-
-/**
- * @file avutil.h
- * external api header.
- */
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define AV_STRINGIFY(s) AV_TOSTRING(s)
-#define AV_TOSTRING(s) #s
-
-#define LIBAVUTIL_VERSION_INT ((49<<16)+(2<<8)+0)
-#define LIBAVUTIL_VERSION 49.2.0
-#define LIBAVUTIL_BUILD LIBAVUTIL_VERSION_INT
-
-#define LIBAVUTIL_IDENT "Lavu" AV_STRINGIFY(LIBAVUTIL_VERSION)
-
-
-#include "common.h"
-#include "mathematics.h"
-#include "rational.h"
-#include "integer.h"
-#include "intfloat_readwrite.h"
-#include "log.h"
-
-/**
- * Pixel format. Notes:
- *
- * PIX_FMT_RGB32 is handled in an endian-specific manner. A RGBA
- * color is put together as:
- * (A << 24) | (R << 16) | (G << 8) | B
- * This is stored as BGRA on little endian CPU architectures and ARGB on
- * big endian CPUs.
- *
- * When the pixel format is palettized RGB (PIX_FMT_PAL8), the palettized
- * image data is stored in AVFrame.data[0]. The palette is transported in
- * AVFrame.data[1] and, is 1024 bytes long (256 4-byte entries) and is
- * formatted the same as in PIX_FMT_RGB32 described above (i.e., it is
- * also endian-specific). Note also that the individual RGB palette
- * components stored in AVFrame.data[1] should be in the range 0..255.
- * This is important as many custom PAL8 video codecs that were designed
- * to run on the IBM VGA graphics adapter use 6-bit palette components.
- */
-enum PixelFormat {
- PIX_FMT_NONE= -1,
- PIX_FMT_YUV420P, ///< Planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
- PIX_FMT_YUYV422, ///< Packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
- PIX_FMT_RGB24, ///< Packed RGB 8:8:8, 24bpp, RGBRGB...
- PIX_FMT_BGR24, ///< Packed RGB 8:8:8, 24bpp, BGRBGR...
- PIX_FMT_YUV422P, ///< Planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
- PIX_FMT_YUV444P, ///< Planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
- PIX_FMT_RGB32, ///< Packed RGB 8:8:8, 32bpp, (msb)8A 8R 8G 8B(lsb), in cpu endianness
- PIX_FMT_YUV410P, ///< Planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
- PIX_FMT_YUV411P, ///< Planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
- PIX_FMT_RGB565, ///< Packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), in cpu endianness
- PIX_FMT_RGB555, ///< Packed RGB 5:5:5, 16bpp, (msb)1A 5R 5G 5B(lsb), in cpu endianness most significant bit to 0
- PIX_FMT_GRAY8, ///< Y , 8bpp
- PIX_FMT_MONOWHITE, ///< Y , 1bpp, 1 is white
- PIX_FMT_MONOBLACK, ///< Y , 1bpp, 0 is black
- PIX_FMT_PAL8, ///< 8 bit with PIX_FMT_RGB32 palette
- PIX_FMT_YUVJ420P, ///< Planar YUV 4:2:0, 12bpp, full scale (jpeg)
- PIX_FMT_YUVJ422P, ///< Planar YUV 4:2:2, 16bpp, full scale (jpeg)
- PIX_FMT_YUVJ444P, ///< Planar YUV 4:4:4, 24bpp, full scale (jpeg)
- PIX_FMT_XVMC_MPEG2_MC,///< XVideo Motion Acceleration via common packet passing(xvmc_render.h)
- PIX_FMT_XVMC_MPEG2_IDCT,
- PIX_FMT_UYVY422, ///< Packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
- PIX_FMT_UYYVYY411, ///< Packed YUV 4:1:1, 12bpp, Cb Y0 Y1 Cr Y2 Y3
- PIX_FMT_BGR32, ///< Packed RGB 8:8:8, 32bpp, (msb)8A 8B 8G 8R(lsb), in cpu endianness
- PIX_FMT_BGR565, ///< Packed RGB 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), in cpu endianness
- PIX_FMT_BGR555, ///< Packed RGB 5:5:5, 16bpp, (msb)1A 5B 5G 5R(lsb), in cpu endianness most significant bit to 1
- PIX_FMT_BGR8, ///< Packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
- PIX_FMT_BGR4, ///< Packed RGB 1:2:1, 4bpp, (msb)1B 2G 1R(lsb)
- PIX_FMT_BGR4_BYTE, ///< Packed RGB 1:2:1, 8bpp, (msb)1B 2G 1R(lsb)
- PIX_FMT_RGB8, ///< Packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb)
- PIX_FMT_RGB4, ///< Packed RGB 1:2:1, 4bpp, (msb)2R 3G 3B(lsb)
- PIX_FMT_RGB4_BYTE, ///< Packed RGB 1:2:1, 8bpp, (msb)2R 3G 3B(lsb)
- PIX_FMT_NV12, ///< Planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 for UV
- PIX_FMT_NV21, ///< as above, but U and V bytes are swapped
-
- PIX_FMT_RGB32_1, ///< Packed RGB 8:8:8, 32bpp, (msb)8R 8G 8B 8A(lsb), in cpu endianness
- PIX_FMT_BGR32_1, ///< Packed RGB 8:8:8, 32bpp, (msb)8B 8G 8R 8A(lsb), in cpu endianness
-
- PIX_FMT_GRAY16BE, ///< Y , 16bpp, big-endian
- PIX_FMT_GRAY16LE, ///< Y , 16bpp, little-endian
- PIX_FMT_NB, ///< number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of formats might differ between versions
-};
-
-#ifdef WORDS_BIGENDIAN
-#define PIX_FMT_RGBA PIX_FMT_RGB32_1
-#define PIX_FMT_BGRA PIX_FMT_BGR32_1
-#define PIX_FMT_ARGB PIX_FMT_RGB32
-#define PIX_FMT_ABGR PIX_FMT_BGR32
-#define PIX_FMT_GRAY16 PIX_FMT_GRAY16BE
-#else
-#define PIX_FMT_RGBA PIX_FMT_BGR32
-#define PIX_FMT_BGRA PIX_FMT_RGB32
-#define PIX_FMT_ARGB PIX_FMT_BGR32_1
-#define PIX_FMT_ABGR PIX_FMT_RGB32_1
-#define PIX_FMT_GRAY16 PIX_FMT_GRAY16LE
-#endif
-
-#if LIBAVUTIL_VERSION_INT < (50<<16)
-#define PIX_FMT_UYVY411 PIX_FMT_UYYVYY411
-#define PIX_FMT_RGBA32 PIX_FMT_RGB32
-#define PIX_FMT_YUV422 PIX_FMT_YUYV422
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* AVUTIL_H */
diff --git a/src/libffmpeg/libavutil/common.h b/src/libffmpeg/libavutil/common.h
deleted file mode 100644
index 0d4346048..000000000
--- a/src/libffmpeg/libavutil/common.h
+++ /dev/null
@@ -1,364 +0,0 @@
-/*
- * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/**
- * @file common.h
- * common internal and external api header.
- */
-
-#ifndef COMMON_H
-#define COMMON_H
-
-#include <inttypes.h>
-
-#ifdef HAVE_AV_CONFIG_H
-/* only include the following when compiling package */
-# include "config.h"
-
-# include <stdlib.h>
-# include <stdio.h>
-# include <string.h>
-# include <ctype.h>
-# include <limits.h>
-# ifndef __BEOS__
-# include <errno.h>
-# else
-# include "berrno.h"
-# endif
-# include <math.h>
-#endif /* HAVE_AV_CONFIG_H */
-
-#ifndef av_always_inline
-#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
-# define av_always_inline __attribute__((always_inline)) inline
-#else
-# define av_always_inline inline
-#endif
-#endif
-
-#ifdef HAVE_AV_CONFIG_H
-# include "internal.h"
-#endif /* HAVE_AV_CONFIG_H */
-
-#ifndef attribute_deprecated
-#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
-# define attribute_deprecated __attribute__((deprecated))
-#else
-# define attribute_deprecated
-#endif
-#endif
-
-#ifndef INT64_C
-#define INT64_C(c) (c ## LL)
-#define UINT64_C(c) (c ## ULL)
-#endif
-
-//rounded divison & shift
-#define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b))
-/* assume b>0 */
-#define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))
-#define FFABS(a) ((a) >= 0 ? (a) : (-(a)))
-#define FFSIGN(a) ((a) > 0 ? 1 : -1)
-
-#define FFMAX(a,b) ((a) > (b) ? (a) : (b))
-#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
-
-#define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0)
-
-/* misc math functions */
-extern const uint8_t ff_log2_tab[256];
-
-static inline int av_log2(unsigned int v)
-{
- int n;
-
- n = 0;
- if (v & 0xffff0000) {
- v >>= 16;
- n += 16;
- }
- if (v & 0xff00) {
- v >>= 8;
- n += 8;
- }
- n += ff_log2_tab[v];
-
- return n;
-}
-
-static inline int av_log2_16bit(unsigned int v)
-{
- int n;
-
- n = 0;
- if (v & 0xff00) {
- v >>= 8;
- n += 8;
- }
- n += ff_log2_tab[v];
-
- return n;
-}
-
-/* median of 3 */
-static inline int mid_pred(int a, int b, int c)
-{
-#ifdef HAVE_CMOV
- int i=b;
- asm volatile(
- "cmp %2, %1 \n\t"
- "cmovg %1, %0 \n\t"
- "cmovg %2, %1 \n\t"
- "cmp %3, %1 \n\t"
- "cmovl %3, %1 \n\t"
- "cmp %1, %0 \n\t"
- "cmovg %1, %0 \n\t"
- :"+&r"(i), "+&r"(a)
- :"r"(b), "r"(c)
- );
- return i;
-#elif 0
- int t= (a-b)&((a-b)>>31);
- a-=t;
- b+=t;
- b-= (b-c)&((b-c)>>31);
- b+= (a-b)&((a-b)>>31);
-
- return b;
-#else
- if(a>b){
- if(c>b){
- if(c>a) b=a;
- else b=c;
- }
- }else{
- if(b>c){
- if(c>a) b=c;
- else b=a;
- }
- }
- return b;
-#endif
-}
-
-/**
- * clip a signed integer value into the amin-amax range
- * @param a value to clip
- * @param amin minimum value of the clip range
- * @param amax maximum value of the clip range
- * @return clipped value
- */
-static inline int clip(int a, int amin, int amax)
-{
- if (a < amin) return amin;
- else if (a > amax) return amax;
- else return a;
-}
-
-/**
- * clip a signed integer value into the 0-255 range
- * @param a value to clip
- * @return clipped value
- */
-static inline uint8_t clip_uint8(int a)
-{
- if (a&(~255)) return (-a)>>31;
- else return a;
-}
-
-/* math */
-int64_t ff_gcd(int64_t a, int64_t b);
-
-/**
- * converts fourcc string to int
- */
-static inline int ff_get_fourcc(const char *s){
-#ifdef HAVE_AV_CONFIG_H
- assert( strlen(s)==4 );
-#endif
-
- return (s[0]) + (s[1]<<8) + (s[2]<<16) + (s[3]<<24);
-}
-
-#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))
-
-/*!
- * \def GET_UTF8(val, GET_BYTE, ERROR)
- * converts a utf-8 character (up to 4 bytes long) 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_BYTE gets utf-8 encoded bytes from any proper source. It can be
- * a function or a statement whose return value or evaluated value is of type
- * uint8_t. It will be executed up to 4 times for values in the valid utf-8 range,
- * and up to 7 times in the general case.
- * \param ERROR action that should be taken when an invalid utf-8 byte 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_UTF8(val, GET_BYTE, ERROR)\
- val= GET_BYTE;\
- {\
- int ones= 7 - av_log2(val ^ 255);\
- if(ones==1)\
- ERROR\
- val&= 127>>ones;\
- while(--ones > 0){\
- int tmp= GET_BYTE - 128;\
- if(tmp>>6)\
- ERROR\
- val= (val<<6) + tmp;\
- }\
- }
-
-/*!
- * \def PUT_UTF8(val, tmp, PUT_BYTE)
- * converts a 32-bit unicode character to its utf-8 encoded form (up to 4 bytes long).
- * \param val is an input only argument and should be of type uint32_t. It holds
- * a ucs4 encoded unicode character that is to be converted to utf-8. If
- * val is given as a function it's executed only once.
- * \param tmp is a temporary variable and should be of type uint8_t. It
- * represents an intermediate value during conversion that is to be
- * outputted by PUT_BYTE.
- * \param PUT_BYTE writes the converted utf-8 bytes to any proper destination.
- * 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 up to 4 times for values in the valid utf-8 range and up to
- * 7 times in the general case, depending on the length of the converted
- * unicode character.
- */
-#define PUT_UTF8(val, tmp, PUT_BYTE)\
- {\
- int bytes, shift;\
- uint32_t in = val;\
- if (in < 0x80) {\
- tmp = in;\
- PUT_BYTE\
- } else {\
- bytes = (av_log2(in) + 4) / 5;\
- shift = (bytes - 1) * 6;\
- tmp = (256 - (256 >> bytes)) | (in >> shift);\
- PUT_BYTE\
- while (shift >= 6) {\
- shift -= 6;\
- tmp = 0x80 | ((in >> shift) & 0x3f);\
- PUT_BYTE\
- }\
- }\
- }
-
-#if defined(ARCH_X86) || defined(ARCH_POWERPC)
-#if defined(ARCH_X86_64)
-static inline uint64_t read_time(void)
-{
- uint64_t a, d;
- asm volatile( "rdtsc\n\t"
- : "=a" (a), "=d" (d)
- );
- return (d << 32) | (a & 0xffffffff);
-}
-#elif defined(ARCH_X86_32)
-static inline long long read_time(void)
-{
- long long l;
- asm volatile( "rdtsc\n\t"
- : "=A" (l)
- );
- return l;
-}
-#else //FIXME check ppc64
-static inline uint64_t read_time(void)
-{
- uint32_t tbu, tbl, temp;
-
- /* from section 2.2.1 of the 32-bit PowerPC PEM */
- __asm__ __volatile__(
- "1:\n"
- "mftbu %2\n"
- "mftb %0\n"
- "mftbu %1\n"
- "cmpw %2,%1\n"
- "bne 1b\n"
- : "=r"(tbl), "=r"(tbu), "=r"(temp)
- :
- : "cc");
-
- return (((uint64_t)tbu)<<32) | (uint64_t)tbl;
-}
-#endif
-
-#define START_TIMER \
-uint64_t tend;\
-uint64_t tstart= read_time();\
-
-#define STOP_TIMER(id) \
-tend= read_time();\
-{\
- static uint64_t tsum=0;\
- static int tcount=0;\
- static int tskip_count=0;\
- if(tcount<2 || tend - tstart < 8*tsum/tcount){\
- tsum+= tend - tstart;\
- tcount++;\
- }else\
- tskip_count++;\
- if(((tcount+tskip_count)&(tcount+tskip_count-1))==0){\
- av_log(NULL, AV_LOG_DEBUG, "%"PRIu64" dezicycles in %s, %d runs, %d skips\n", tsum*10/tcount, id, tcount, tskip_count);\
- }\
-}
-#else
-#define START_TIMER
-#define STOP_TIMER(id) {}
-#endif
-
-/* memory */
-
-#ifdef __GNUC__
- #define DECLARE_ALIGNED(n,t,v) t v __attribute__ ((aligned (n)))
-#else
- #define DECLARE_ALIGNED(n,t,v) __declspec(align(n)) t v
-#endif
-
-/* memory */
-void *av_malloc(unsigned int size);
-void *av_realloc(void *ptr, unsigned int size);
-void av_free(void *ptr);
-
-void *av_mallocz(unsigned int size);
-char *av_strdup(const char *s);
-void av_freep(void *ptr);
-
-/* xine: inline causes trouble for debug compiling */
-#ifdef DISABLE_INLINE
-# ifdef inline
-# undef inline
-# endif
-# ifdef always_inline
-# undef always_inline
-# endif
-# define inline
-# define always_inline
-#endif
-
-/* xine: another config.h with codecs to use */
-#include "ffmpeg_config.h"
-
-#endif /* COMMON_H */
-
diff --git a/src/libffmpeg/libavutil/crc.c b/src/libffmpeg/libavutil/crc.c
deleted file mode 100644
index baa605d32..000000000
--- a/src/libffmpeg/libavutil/crc.c
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include "common.h"
-#include "crc.h"
-
-AVCRC *av_crcEDB88320;
-AVCRC *av_crc04C11DB7;
-AVCRC *av_crc8005 ;
-AVCRC *av_crc07 ;
-
-/**
- * Inits a crc table.
- * @param ctx must be an array of sizeof(AVCRC)*257 or sizeof(AVCRC)*1024
- * @param cts_size size of ctx in bytes
- * @return <0 on failure
- */
-int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size){
- int i, j;
- uint32_t c;
-
- if (bits < 8 || bits > 32 || poly >= (1LL<<bits))
- return -1;
- if (ctx_size != sizeof(AVCRC)*257 && ctx_size != sizeof(AVCRC)*1024)
- return -1;
-
- for (i = 0; i < 256; i++) {
- if (le) {
- for (c = i, j = 0; j < 8; j++)
- c = (c>>1)^(poly & (-(c&1)));
- ctx[i] = c;
- } else {
- for (c = i << 24, j = 0; j < 8; j++)
- c = (c<<1) ^ ((poly<<(32-bits)) & (((int32_t)c)>>31) );
- ctx[i] = bswap_32(c);
- }
- }
- ctx[256]=1;
-#ifndef CONFIG_SMALL
- if(ctx_size >= sizeof(AVCRC)*1024)
- for (i = 0; i < 256; i++)
- for(j=0; j<3; j++)
- ctx[256*(j+1) + i]= (ctx[256*j + i]>>8) ^ ctx[ ctx[256*j + i]&0xFF ];
-#endif
-
- return 0;
-}
-
-uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length){
- const uint8_t *end= buffer+length;
-
-#ifndef CONFIG_SMALL
- if(!ctx[256])
- while(buffer<end-3){
- crc ^= le2me_32(*(uint32_t*)buffer); buffer+=4;
- crc = ctx[3*256 + ( crc &0xFF)]
- ^ctx[2*256 + ((crc>>8 )&0xFF)]
- ^ctx[1*256 + ((crc>>16)&0xFF)]
- ^ctx[0*256 + ((crc>>24) )];
- }
-#endif
- while(buffer<end)
- crc = ctx[((uint8_t)crc) ^ *buffer++] ^ (crc >> 8);
-
- return crc;
-}
-
-#ifdef TEST
-#undef printf
-main(){
- uint8_t buf[1999];
- int i;
- int p[4][4]={{1, 32, 0xedb88320L, 0x3D5CDD04},
- {0, 32, 0x04c11db7L, 0xC0F5BAE0},
- {0, 16, 0x8005 , 0x1FBB },
- {0, 8, 0x07 , 0xE3 },};
- AVCRC ctx[1 ? 1024:257];
-
- for(i=0; i<sizeof(buf); i++)
- buf[i]= i+i*i;
-
- for(i=0; i<4; i++){
- av_crc_init(ctx, p[i][0], p[i][1], p[i][2], sizeof(ctx));
- printf("crc %08X =%X\n", p[i][2], av_crc(ctx, 0, buf, sizeof(buf)));
- }
-}
-#endif
diff --git a/src/libffmpeg/libavutil/crc.h b/src/libffmpeg/libavutil/crc.h
deleted file mode 100644
index e739c309b..000000000
--- a/src/libffmpeg/libavutil/crc.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef CRC_H
-#define CRC_H
-
-typedef uint32_t AVCRC;
-
-extern AVCRC *av_crcEDB88320;
-extern AVCRC *av_crc04C11DB7;
-extern AVCRC *av_crc8005 ;
-extern AVCRC *av_crc07 ;
-
-int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size);
-uint32_t av_crc(const AVCRC *ctx, uint32_t start_crc, const uint8_t *buffer, size_t length);
-
-#endif /* CRC_H */
-
diff --git a/src/libffmpeg/libavutil/integer.c b/src/libffmpeg/libavutil/integer.c
deleted file mode 100644
index 5c7b71530..000000000
--- a/src/libffmpeg/libavutil/integer.c
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- * arbitrary precision integers
- * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-/**
- * @file integer.c
- * arbitrary precision integers.
- * @author Michael Niedermayer <michaelni@gmx.at>
- */
-
-#include "common.h"
-#include "integer.h"
-
-AVInteger av_add_i(AVInteger a, AVInteger b){
- int i, carry=0;
-
- for(i=0; i<AV_INTEGER_SIZE; i++){
- carry= (carry>>16) + a.v[i] + b.v[i];
- a.v[i]= carry;
- }
- return a;
-}
-
-AVInteger av_sub_i(AVInteger a, AVInteger b){
- int i, carry=0;
-
- for(i=0; i<AV_INTEGER_SIZE; i++){
- carry= (carry>>16) + a.v[i] - b.v[i];
- a.v[i]= carry;
- }
- return a;
-}
-
-/**
- * returns the rounded down value of the logarithm of base 2 of the given AVInteger.
- * this is simply the index of the most significant bit which is 1. Or 0 of all bits are 0
- */
-int av_log2_i(AVInteger a){
- int i;
-
- for(i=AV_INTEGER_SIZE-1; i>=0; i--){
- if(a.v[i])
- return av_log2_16bit(a.v[i]) + 16*i;
- }
- return -1;
-}
-
-AVInteger av_mul_i(AVInteger a, AVInteger b){
- AVInteger out;
- int i, j;
- int na= (av_log2_i(a)+16) >> 4;
- int nb= (av_log2_i(b)+16) >> 4;
-
- memset(&out, 0, sizeof(out));
-
- for(i=0; i<na; i++){
- unsigned int carry=0;
-
- if(a.v[i])
- for(j=i; j<AV_INTEGER_SIZE && j-i<=nb; j++){
- carry= (carry>>16) + out.v[j] + a.v[i]*b.v[j-i];
- out.v[j]= carry;
- }
- }
-
- return out;
-}
-
-/**
- * returns 0 if a==b, 1 if a>b and -1 if a<b.
- */
-int av_cmp_i(AVInteger a, AVInteger b){
- int i;
- int v= (int16_t)a.v[AV_INTEGER_SIZE-1] - (int16_t)b.v[AV_INTEGER_SIZE-1];
- if(v) return (v>>16)|1;
-
- for(i=AV_INTEGER_SIZE-2; i>=0; i--){
- int v= a.v[i] - b.v[i];
- if(v) return (v>>16)|1;
- }
- return 0;
-}
-
-/**
- * bitwise shift.
- * @param s the number of bits by which the value should be shifted right, may be negative for shifting left
- */
-AVInteger av_shr_i(AVInteger a, int s){
- AVInteger out;
- int i;
-
- for(i=0; i<AV_INTEGER_SIZE; i++){
- int index= i + (s>>4);
- unsigned int v=0;
- if(index+1<AV_INTEGER_SIZE && index+1>=0) v = a.v[index+1]<<16;
- if(index <AV_INTEGER_SIZE && index >=0) v+= a.v[index ];
- out.v[i]= v >> (s&15);
- }
- return out;
-}
-
-/**
- * returns a % b.
- * @param quot a/b will be stored here
- */
-AVInteger av_mod_i(AVInteger *quot, AVInteger a, AVInteger b){
- int i= av_log2_i(a) - av_log2_i(b);
- AVInteger quot_temp;
- if(!quot) quot = &quot_temp;
-
- assert((int16_t)a.v[AV_INTEGER_SIZE-1] >= 0 && (int16_t)b.v[AV_INTEGER_SIZE-1] >= 0);
- assert(av_log2_i(b)>=0);
-
- if(i > 0)
- b= av_shr_i(b, -i);
-
- memset(quot, 0, sizeof(AVInteger));
-
- while(i-- >= 0){
- *quot= av_shr_i(*quot, -1);
- if(av_cmp_i(a, b) >= 0){
- a= av_sub_i(a, b);
- quot->v[0] += 1;
- }
- b= av_shr_i(b, 1);
- }
- return a;
-}
-
-/**
- * returns a/b.
- */
-AVInteger av_div_i(AVInteger a, AVInteger b){
- AVInteger quot;
- av_mod_i(&quot, a, b);
- return quot;
-}
-
-/**
- * converts the given int64_t to an AVInteger.
- */
-AVInteger av_int2i(int64_t a){
- AVInteger out;
- int i;
-
- for(i=0; i<AV_INTEGER_SIZE; i++){
- out.v[i]= a;
- a>>=16;
- }
- return out;
-}
-
-/**
- * converts the given AVInteger to an int64_t.
- * if the AVInteger is too large to fit into an int64_t,
- * then only the least significant 64bit will be used
- */
-int64_t av_i2int(AVInteger a){
- int i;
- int64_t out=(int8_t)a.v[AV_INTEGER_SIZE-1];
-
- for(i= AV_INTEGER_SIZE-2; i>=0; i--){
- out = (out<<16) + a.v[i];
- }
- return out;
-}
-
-#if 0
-#undef NDEBUG
-#include <assert.h>
-
-const uint8_t ff_log2_tab[256]={
- 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
- 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
-};
-
-main(){
- int64_t a,b;
-
- for(a=7; a<256*256*256; a+=13215){
- for(b=3; b<256*256*256; b+=27118){
- AVInteger ai= av_int2i(a);
- AVInteger bi= av_int2i(b);
-
- assert(av_i2int(ai) == a);
- assert(av_i2int(bi) == b);
- assert(av_i2int(av_add_i(ai,bi)) == a+b);
- assert(av_i2int(av_sub_i(ai,bi)) == a-b);
- assert(av_i2int(av_mul_i(ai,bi)) == a*b);
- assert(av_i2int(av_shr_i(ai, 9)) == a>>9);
- assert(av_i2int(av_shr_i(ai,-9)) == a<<9);
- assert(av_i2int(av_shr_i(ai, 17)) == a>>17);
- assert(av_i2int(av_shr_i(ai,-17)) == a<<17);
- assert(av_log2_i(ai) == av_log2(a));
- assert(av_i2int(av_div_i(ai,bi)) == a/b);
- }
- }
-}
-#endif
diff --git a/src/libffmpeg/libavutil/integer.h b/src/libffmpeg/libavutil/integer.h
deleted file mode 100644
index a50ad9bae..000000000
--- a/src/libffmpeg/libavutil/integer.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * arbitrary precision integers
- * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-/**
- * @file integer.h
- * arbitrary precision integers
- * @author Michael Niedermayer <michaelni@gmx.at>
- */
-
-#ifndef INTEGER_H
-#define INTEGER_H
-
-#define AV_INTEGER_SIZE 8
-
-typedef struct AVInteger{
- uint16_t v[AV_INTEGER_SIZE];
-} AVInteger;
-
-AVInteger av_add_i(AVInteger a, AVInteger b);
-AVInteger av_sub_i(AVInteger a, AVInteger b);
-int av_log2_i(AVInteger a);
-AVInteger av_mul_i(AVInteger a, AVInteger b);
-int av_cmp_i(AVInteger a, AVInteger b);
-AVInteger av_shr_i(AVInteger a, int s);
-AVInteger av_mod_i(AVInteger *quot, AVInteger a, AVInteger b);
-AVInteger av_div_i(AVInteger a, AVInteger b);
-AVInteger av_int2i(int64_t a);
-int64_t av_i2int(AVInteger a);
-
-#endif // INTEGER_H
diff --git a/src/libffmpeg/libavutil/internal.h b/src/libffmpeg/libavutil/internal.h
deleted file mode 100644
index 0c4b44170..000000000
--- a/src/libffmpeg/libavutil/internal.h
+++ /dev/null
@@ -1,328 +0,0 @@
-/*
- * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/**
- * @file internal.h
- * common internal api header.
- */
-
-#ifndef INTERNAL_H
-#define INTERNAL_H
-
-#ifndef attribute_used
-#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
-# define attribute_used __attribute__((used))
-#else
-# define attribute_used
-#endif
-#endif
-
-#ifndef attribute_unused
-#if defined(__GNUC__)
-# define attribute_unused __attribute__((unused))
-#else
-# define attribute_unused
-#endif
-#endif
-
-#ifndef M_PI
-#define M_PI 3.14159265358979323846
-#endif
-
-#ifndef PRId64
-#define PRId64 "lld"
-#endif
-
-#ifndef PRIu64
-#define PRIu64 "llu"
-#endif
-
-#ifndef PRIx64
-#define PRIx64 "llx"
-#endif
-
-#ifndef PRIX64
-#define PRIX64 "llX"
-#endif
-
-#ifndef PRId32
-#define PRId32 "d"
-#endif
-
-#ifndef PRIdFAST16
-#define PRIdFAST16 PRId32
-#endif
-
-#ifndef PRIdFAST32
-#define PRIdFAST32 PRId32
-#endif
-
-#ifndef INT16_MIN
-#define INT16_MIN (-0x7fff-1)
-#endif
-
-#ifndef INT16_MAX
-#define INT16_MAX 0x7fff
-#endif
-
-#ifndef INT32_MIN
-#define INT32_MIN (-0x7fffffff-1)
-#endif
-
-#ifndef INT32_MAX
-#define INT32_MAX 0x7fffffff
-#endif
-
-#ifndef UINT32_MAX
-#define UINT32_MAX 0xffffffff
-#endif
-
-#ifndef INT64_MIN
-#define INT64_MIN (-0x7fffffffffffffffLL-1)
-#endif
-
-#ifndef INT64_MAX
-#define INT64_MAX INT64_C(9223372036854775807)
-#endif
-
-#ifndef UINT64_MAX
-#define UINT64_MAX UINT64_C(0xFFFFFFFFFFFFFFFF)
-#endif
-
-#ifndef INT_BIT
-# if INT_MAX != 2147483647
-# define INT_BIT 64
-# else
-# define INT_BIT 32
-# endif
-#endif
-
-#if ( defined(__PIC__) || defined(__pic__) ) && ! defined(PIC)
-# define PIC
-#endif
-
-#ifndef ENODATA
-# define ENODATA 61
-#endif
-
-#include "intreadwrite.h"
-#include "bswap.h"
-
-#include <stddef.h>
-#ifndef offsetof
-# define offsetof(T,F) ((unsigned int)((char *)&((T *)0)->F))
-#endif
-
-#ifdef __MINGW32__
-# ifdef _DEBUG
-# define DEBUG
-# endif
-
-# define snprintf _snprintf
-# define vsnprintf _vsnprintf
-
-# ifdef CONFIG_WINCE
-# define perror(a)
-# define abort()
-# endif
-
-/* __MINGW32__ end */
-#elif defined (CONFIG_OS2)
-/* OS/2 EMX */
-
-# include <float.h>
-
-#endif /* !__MINGW32__ && CONFIG_OS2 */
-
-#ifdef USE_FASTMEMCPY
-# include "libvo/fastmemcpy.h"
-#endif
-
-// Use rip-relative addressing if compiling PIC code on x86-64.
-#if defined(__MINGW32__) || defined(__CYGWIN__) || \
- defined(__OS2__) || (defined (__OpenBSD__) && !defined(__ELF__))
-# if defined(ARCH_X86_64) && defined(PIC)
-# define MANGLE(a) "_" #a"(%%rip)"
-# else
-# define MANGLE(a) "_" #a
-# endif
-#else
-# if defined(ARCH_X86_64) && defined(PIC)
-# define MANGLE(a) #a"(%%rip)"
-# elif defined(CONFIG_DARWIN)
-# define MANGLE(a) "_" #a
-# else
-# define MANGLE(a) #a
-# endif
-#endif
-
-/* debug stuff */
-
-#if !defined(DEBUG) && !defined(NDEBUG)
-# define NDEBUG
-#endif
-#include <assert.h>
-
-/* dprintf macros */
-# ifdef DEBUG
-# ifdef __GNUC__
-# define dprintf(fmt,args...) av_log(NULL, AV_LOG_DEBUG, fmt, ##args)
-# else
-# define dprintf(fmt,...) av_log(NULL, AV_LOG_DEBUG, fmt, __VA_ARGS__)
-# endif
-# else
-# define dprintf(fmt,...)
-# endif
-
-#define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0)
-
-/* math */
-
-extern const uint32_t ff_inverse[256];
-
-#if defined(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 defined(ARCH_ARMV4L)
-# define FASTDIV(a,b) \
- ({\
- int ret,dmy;\
- asm volatile(\
- "umull %1, %0, %2, %3"\
- :"=&r"(ret),"=&r"(dmy)\
- :"r"(a),"r"(ff_inverse[b])\
- );\
- ret;\
- })
-#elif defined(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[128];
-
-static inline int ff_sqrt(int a)
-{
- int ret=0;
- int s;
- int ret_sq=0;
-
- if(a<128) return ff_sqrt_tab[a];
-
- for(s=15; s>=0; s--){
- int b= ret_sq + (1<<(s*2)) + (ret<<s)*2;
- if(b<=a){
- ret_sq=b;
- ret+= 1<<s;
- }
- }
- return ret;
-}
-
-#if defined(ARCH_X86)
-#define MASK_ABS(mask, level)\
- asm volatile(\
- "cdq \n\t"\
- "xorl %1, %0 \n\t"\
- "subl %1, %0 \n\t"\
- : "+a" (level), "=&d" (mask)\
- );
-#else
-#define MASK_ABS(mask, level)\
- mask= level>>31;\
- level= (level^mask)-mask;
-#endif
-
-#ifdef 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);\
-}
-#endif
-
-/* avoid usage of various functions */
-#define malloc please_use_av_malloc
-#define free please_use_av_free
-#define realloc please_use_av_realloc
-#define time time_is_forbidden_due_to_security_issues
-#define rand rand_is_forbidden_due_to_state_trashing
-#define srand srand_is_forbidden_due_to_state_trashing
-#define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf
-#define strcat strcat_is_forbidden_due_to_security_issues_use_pstrcat
-#if !(defined(LIBAVFORMAT_BUILD) || defined(_FRAMEHOOK_H))
-#define printf please_use_av_log
-#define fprintf please_use_av_log
-#endif
-
-#define CHECKED_ALLOCZ(p, size)\
-{\
- p= av_mallocz(size);\
- if(p==NULL && (size)!=0){\
- perror("malloc");\
- goto fail;\
- }\
-}
-
-#ifndef HAVE_LRINTF
-/* XXX: add ISOC specific test to avoid specific BSD testing. */
-/* better than nothing implementation. */
-/* btw, rintf() is existing on fbsd too -- alex */
-static av_always_inline long int lrintf(float x)
-{
-#ifdef __MINGW32__
-# ifdef ARCH_X86_32
- int32_t i;
- asm volatile(
- "fistpl %0\n\t"
- : "=m" (i) : "t" (x) : "st"
- );
- return i;
-# else
- /* XXX: incorrect, but make it compile */
- return (int)(x + (x < 0 ? -0.5 : 0.5));
-# endif /* ARCH_X86_32 */
-#else
- return (int)(rint(x));
-#endif /* __MINGW32__ */
-}
-#endif /* HAVE_LRINTF */
-
-#endif /* INTERNAL_H */
diff --git a/src/libffmpeg/libavutil/intreadwrite.h b/src/libffmpeg/libavutil/intreadwrite.h
deleted file mode 100644
index e6db5ce6f..000000000
--- a/src/libffmpeg/libavutil/intreadwrite.h
+++ /dev/null
@@ -1,65 +0,0 @@
-#ifndef INTREADWRITE_H
-#define INTREADWRITE_H
-
-#ifdef __GNUC__
-
-struct unaligned_64 { uint64_t l; } __attribute__((packed));
-struct unaligned_32 { uint32_t l; } __attribute__((packed));
-struct unaligned_16 { uint16_t l; } __attribute__((packed));
-
-#define LD16(a) (((const struct unaligned_16 *) (a))->l)
-#define LD32(a) (((const struct unaligned_32 *) (a))->l)
-#define LD64(a) (((const struct unaligned_64 *) (a))->l)
-
-#define ST16(a, b) (((struct unaligned_16 *) (a))->l) = (b)
-#define ST32(a, b) (((struct unaligned_32 *) (a))->l) = (b)
-
-#else /* __GNUC__ */
-
-#define LD16(a) (*((uint16_t*)(a)))
-#define LD32(a) (*((uint32_t*)(a)))
-#define LD64(a) (*((uint64_t*)(a)))
-
-#define ST16(a, b) *((uint16_t*)(a)) = (b)
-#define ST32(a, b) *((uint32_t*)(a)) = (b)
-
-#endif /* !__GNUC__ */
-
-/* endian macros */
-#define AV_RB8(x) (((uint8_t*)(x))[0])
-#define AV_WB8(p, i, d) { ((uint8_t*)(p))[(i)] = (d); }
-
-#define AV_RB16(x) ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1])
-#define AV_WB16(p, i, d) { \
- ((uint8_t*)(p))[(i)+1] = (d); \
- ((uint8_t*)(p))[(i)] = (d)>>8; }
-
-#define AV_RB32(x) ((((uint8_t*)(x))[0] << 24) | \
- (((uint8_t*)(x))[1] << 16) | \
- (((uint8_t*)(x))[2] << 8) | \
- ((uint8_t*)(x))[3])
-#define AV_WB32(p, i, d) { \
- ((uint8_t*)(p))[(i)+3] = (d); \
- ((uint8_t*)(p))[(i)+2] = (d)>>8; \
- ((uint8_t*)(p))[(i)+1] = (d)>>16; \
- ((uint8_t*)(p))[(i)] = (d)>>24; }
-
-#define AV_RL8(x) AV_RB8(x)
-#define AV_WL8(p, i, d) AV_WB8(p, i, d)
-
-#define AV_RL16(x) ((((uint8_t*)(x))[1] << 8) | ((uint8_t*)(x))[0])
-#define AV_WL16(p, i, d) { \
- ((uint8_t*)(p))[(i)] = (d); \
- ((uint8_t*)(p))[(i)+1] = (d)>>8; }
-
-#define AV_RL32(x) ((((uint8_t*)(x))[3] << 24) | \
- (((uint8_t*)(x))[2] << 16) | \
- (((uint8_t*)(x))[1] << 8) | \
- ((uint8_t*)(x))[0])
-#define AV_WL32(p, i, d) { \
- ((uint8_t*)(p))[(i)] = (d); \
- ((uint8_t*)(p))[(i)+1] = (d)>>8; \
- ((uint8_t*)(p))[(i)+2] = (d)>>16; \
- ((uint8_t*)(p))[(i)+3] = (d)>>24; }
-
-#endif /* INTREADWRITE_H */
diff --git a/src/libffmpeg/libavutil/log.h b/src/libffmpeg/libavutil/log.h
deleted file mode 100644
index 56ca01289..000000000
--- a/src/libffmpeg/libavutil/log.h
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef LOG_H
-#define LOG_H
-
-#include <stdarg.h>
-
-/**
- * Used by av_log
- */
-typedef struct AVCLASS AVClass;
-struct AVCLASS {
- const char* class_name;
- const char* (*item_name)(void*); /* actually passing a pointer to an AVCodecContext
- or AVFormatContext, which begin with an AVClass.
- Needed because av_log is in libavcodec and has no visibility
- of AVIn/OutputFormat */
- const struct AVOption *option;
-};
-
-/* av_log API */
-
-#if LIBAVUTIL_VERSION_INT < (50<<16)
-#define AV_LOG_QUIET -1
-#define AV_LOG_FATAL 0
-#define AV_LOG_ERROR 0
-#define AV_LOG_WARNING 1
-#define AV_LOG_INFO 1
-#define AV_LOG_VERBOSE 1
-#define AV_LOG_DEBUG 2
-#else
-#define AV_LOG_QUIET -8
-
-/**
- * something went really wrong and we will crash now
- */
-#define AV_LOG_PANIC 0
-
-/**
- * something went wrong and recovery is not possible
- * like no header in a format which depends on it or a combination
- * of parameters which are not allowed
- */
-#define AV_LOG_FATAL 8
-
-/**
- * something went wrong and cannot losslessly be recovered
- * but not all future data is affected
- */
-#define AV_LOG_ERROR 16
-
-/**
- * something somehow does not look correct / something which may or may not
- * lead to some problems like use of -vstrict -2
- */
-#define AV_LOG_WARNING 24
-
-#define AV_LOG_INFO 32
-#define AV_LOG_VERBOSE 40
-
-/**
- * stuff which is only useful for libav* developers
- */
-#define AV_LOG_DEBUG 48
-#endif
-extern int av_log_level;
-
-#ifdef __GNUC__
-extern void av_log(void*, int level, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 3, 4)));
-#else
-extern void av_log(void*, int level, const char *fmt, ...);
-#endif
-
-#if LIBAVUTIL_VERSION_INT < (50<<16)
-extern void av_vlog(void*, int level, const char *fmt, va_list);
-extern int av_log_get_level(void);
-extern void av_log_set_level(int);
-extern void av_log_set_callback(void (*)(void*, int, const char*, va_list));
-extern void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl);
-#else
-extern void (*av_vlog)(void*, int, const char*, va_list);
-#endif
-
-#endif /* LOG_H */
diff --git a/src/libffmpeg/libavutil/md5.c b/src/libffmpeg/libavutil/md5.c
deleted file mode 100644
index d33ad1483..000000000
--- a/src/libffmpeg/libavutil/md5.c
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * Copyright (C) 2006 Michael Niedermayer (michaelni@gmx.at)
- * Copyright (C) 2003-2005 by Christopher R. Hertel (crh@ubiqx.mn.org)
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * References:
- * IETF RFC 1321: The MD5 Message-Digest Algorithm
- * Ron Rivest. IETF, April, 1992
- *
- * based on http://ubiqx.org/libcifs/source/Auth/MD5.c
- * from Christopher R. Hertel (crh@ubiqx.mn.org)
- * simplified, cleaned and IMO redundant comments removed by michael
- *
- * if you use gcc, then version 4.1 or later and -fomit-frame-pointer is
- * strongly recommended
- */
-
-#include "common.h"
-#include <string.h>
-#include "md5.h"
-
-typedef struct AVMD5{
- uint8_t block[64];
- uint32_t ABCD[4];
- uint64_t len;
- int b_used;
-} AVMD5;
-
-const int av_md5_size= sizeof(AVMD5);
-
-static const uint8_t S[4][4] = {
- { 7, 12, 17, 22 }, /* Round 1 */
- { 5, 9, 14, 20 }, /* Round 2 */
- { 4, 11, 16, 23 }, /* Round 3 */
- { 6, 10, 15, 21 } /* Round 4 */
-};
-
-static const uint32_t T[64] = {
- 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, /* Round 1 */
- 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
- 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
- 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
-
- 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, /* Round 2 */
- 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,
- 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
- 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
-
- 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, /* Round 3 */
- 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
- 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05,
- 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
-
- 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, /* Round 4 */
- 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
- 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
- 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391,
-};
-
-#define CORE(i, a, b, c, d) \
- t = S[i>>4][i&3];\
- a += T[i];\
-\
- switch(i>>4){\
- case 0: a += (d ^ (b&(c^d))) + X[ i &15 ]; break;\
- case 1: a += (c ^ (d&(c^b))) + X[ (1+5*i)&15 ]; break;\
- case 2: a += (b^c^d) + X[ (5+3*i)&15 ]; break;\
- case 3: a += (c^(b|~d)) + X[ ( 7*i)&15 ]; break;\
- }\
- a = b + (( a << t ) | ( a >> (32 - t) ));
-
-static void body(uint32_t ABCD[4], uint32_t X[16]){
-
- int t;
- int i attribute_unused;
- unsigned int a= ABCD[3];
- unsigned int b= ABCD[2];
- unsigned int c= ABCD[1];
- unsigned int d= ABCD[0];
-
-#ifdef WORDS_BIGENDIAN
- for(i=0; i<16; i++)
- X[i]= bswap_32(X[i]);
-#endif
-
-#ifdef CONFIG_SMALL
- for( i = 0; i < 64; i++ ){
- CORE(i,a,b,c,d)
- t=d; d=c; c=b; b=a; a=t;
- }
-#else
-#define CORE2(i) CORE(i,a,b,c,d) CORE((i+1),d,a,b,c) CORE((i+2),c,d,a,b) CORE((i+3),b,c,d,a)
-#define CORE4(i) CORE2(i) CORE2((i+4)) CORE2((i+8)) CORE2((i+12))
-CORE4(0) CORE4(16) CORE4(32) CORE4(48)
-#endif
-
- ABCD[0] += d;
- ABCD[1] += c;
- ABCD[2] += b;
- ABCD[3] += a;
-}
-
-void av_md5_init(AVMD5 *ctx){
- ctx->len = 0;
- ctx->b_used = 0;
-
- ctx->ABCD[0] = 0x10325476;
- ctx->ABCD[1] = 0x98badcfe;
- ctx->ABCD[2] = 0xefcdab89;
- ctx->ABCD[3] = 0x67452301;
-}
-
-void av_md5_update(AVMD5 *ctx, const uint8_t *src, const int len){
- int i;
-
- ctx->len += len;
-
- for( i = 0; i < len; i++ ){
- ctx->block[ ctx->b_used++ ] = src[i];
- if( 64 == ctx->b_used ){
- body(ctx->ABCD, (uint32_t*) ctx->block);
- ctx->b_used = 0;
- }
- }
-}
-
-void av_md5_final(AVMD5 *ctx, uint8_t *dst){
- int i;
-
- ctx->block[ctx->b_used++] = 0x80;
-
- memset(&ctx->block[ctx->b_used], 0, 64 - ctx->b_used);
-
- if( 56 < ctx->b_used ){
- body( ctx->ABCD, (uint32_t*) ctx->block );
- memset(ctx->block, 0, 64);
- }
-
- for(i=0; i<8; i++)
- ctx->block[56+i] = (ctx->len << 3) >> (i<<3);
-
- body(ctx->ABCD, (uint32_t*) ctx->block);
-
- for(i=0; i<4; i++)
- ((uint32_t*)dst)[i]= le2me_32(ctx->ABCD[3-i]);
-}
-
-void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len){
- AVMD5 ctx[1];
-
- av_md5_init(ctx);
- av_md5_update(ctx, src, len);
- av_md5_final(ctx, dst);
-}
-
-#ifdef TEST
-#include <stdio.h>
-main(){
- uint64_t md5val;
- int i;
- uint8_t in[1000];
-
- for(i=0; i<1000; i++) in[i]= i*i;
- av_md5_sum( (uint8_t*)&md5val, in, 1000); printf("%"PRId64"\n", md5val);
- av_md5_sum( (uint8_t*)&md5val, in, 63); printf("%"PRId64"\n", md5val);
- av_md5_sum( (uint8_t*)&md5val, in, 64); printf("%"PRId64"\n", md5val);
- av_md5_sum( (uint8_t*)&md5val, in, 65); printf("%"PRId64"\n", md5val);
- for(i=0; i<1000; i++) in[i]= i % 127;
- av_md5_sum( (uint8_t*)&md5val, in, 999); printf("%"PRId64"\n", md5val);
-}
-#endif
diff --git a/src/libffmpeg/libavutil/mem.c b/src/libffmpeg/libavutil/mem.c
deleted file mode 100644
index f43fb5420..000000000
--- a/src/libffmpeg/libavutil/mem.c
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * default memory allocator for libavutil
- * 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 mem.c
- * default memory allocator for libavutil.
- */
-
-#include "common.h"
-
-/* here we can use OS dependant allocation functions */
-#undef malloc
-#undef free
-#undef realloc
-
-#ifdef HAVE_MALLOC_H
-#include <malloc.h>
-#endif
-
-/* 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 */
-
-/**
- * Memory allocation of size byte with alignment suitable for all
- * memory accesses (including vectors if available on the
- * CPU). av_malloc(0) must return a non NULL pointer.
- */
-void *av_malloc(unsigned int size)
-{
- void *ptr;
-#ifdef CONFIG_MEMALIGN_HACK
- long diff;
-#endif
-
- /* let's disallow possible ambiguous cases */
- if(size > (INT_MAX-16) )
- return NULL;
-
-#ifdef CONFIG_MEMALIGN_HACK
- ptr = malloc(size+16);
- if(!ptr)
- return ptr;
- diff= ((-(long)ptr - 1)&15) + 1;
- ptr += diff;
- ((char*)ptr)[-1]= diff;
-#elif defined (HAVE_MEMALIGN)
- ptr = memalign(16,size);
- /* Why 64?
- Indeed, we should align it:
- on 4 for 386
- on 16 for 486
- on 32 for 586, PPro - k6-III
- on 64 for K7 (maybe for P3 too).
- Because L1 and L2 caches are aligned on those values.
- But I don't want to code such logic here!
- */
- /* Why 16?
- because some cpus need alignment, for example SSE2 on P4, & most RISC cpus
- it will just trigger an exception and the unaligned load will be done in the
- exception handler or it will just segfault (SSE2 on P4)
- Why not larger? because i didnt see a difference in benchmarks ...
- */
- /* benchmarks with p3
- memalign(64)+1 3071,3051,3032
- memalign(64)+2 3051,3032,3041
- memalign(64)+4 2911,2896,2915
- memalign(64)+8 2545,2554,2550
- memalign(64)+16 2543,2572,2563
- memalign(64)+32 2546,2545,2571
- memalign(64)+64 2570,2533,2558
-
- btw, malloc seems to do 8 byte alignment by default here
- */
-#else
- ptr = malloc(size);
-#endif
- return ptr;
-}
-
-/**
- * av_realloc semantics (same as glibc): if ptr is NULL and size > 0,
- * identical to malloc(size). If size is zero, it is identical to
- * free(ptr) and NULL is returned.
- */
-void *av_realloc(void *ptr, unsigned int size)
-{
-#ifdef CONFIG_MEMALIGN_HACK
- int diff;
-#endif
-
- /* let's disallow possible ambiguous cases */
- if(size > (INT_MAX-16) )
- return NULL;
-
-#ifdef CONFIG_MEMALIGN_HACK
- //FIXME this isn't aligned correctly, though it probably isn't needed
- if(!ptr) return av_malloc(size);
- diff= ((char*)ptr)[-1];
- return realloc(ptr - diff, size + diff) + diff;
-#else
- return realloc(ptr, size);
-#endif
-}
-
-/**
- * Free memory which has been allocated with av_malloc(z)() or av_realloc().
- * NOTE: ptr = NULL is explicetly allowed
- * Note2: it is recommended that you use av_freep() instead
- */
-void av_free(void *ptr)
-{
- /* XXX: this test should not be needed on most libcs */
- if (ptr)
-#ifdef CONFIG_MEMALIGN_HACK
- free(ptr - ((char*)ptr)[-1]);
-#else
- free(ptr);
-#endif
-}
-
-/**
- * Frees memory and sets the pointer to NULL.
- * @param arg pointer to the pointer which should be freed
- */
-void av_freep(void *arg)
-{
- void **ptr= (void**)arg;
- av_free(*ptr);
- *ptr = NULL;
-}
-
-void *av_mallocz(unsigned int size)
-{
- void *ptr;
-
- ptr = av_malloc(size);
- if (ptr)
- memset(ptr, 0, size);
- return ptr;
-}
-
-char *av_strdup(const char *s)
-{
- char *ptr;
- int len;
- len = strlen(s) + 1;
- ptr = av_malloc(len);
- if (ptr)
- memcpy(ptr, s, len);
- return ptr;
-}
-
diff --git a/src/libffmpeg/libavutil/rational.c b/src/libffmpeg/libavutil/rational.c
deleted file mode 100644
index 0480aa882..000000000
--- a/src/libffmpeg/libavutil/rational.c
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Rational numbers
- * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-/**
- * @file rational.c
- * Rational numbers
- * @author Michael Niedermayer <michaelni@gmx.at>
- */
-
-//#include <math.h>
-#include <limits.h>
-
-#include "common.h"
-#include "mathematics.h"
-#include "rational.h"
-
-int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max){
- AVRational a0={0,1}, a1={1,0};
- int sign= (nom<0) ^ (den<0);
- int64_t gcd= ff_gcd(FFABS(nom), FFABS(den));
-
- if(gcd){
- nom = FFABS(nom)/gcd;
- den = FFABS(den)/gcd;
- }
- if(nom<=max && den<=max){
- a1= (AVRational){nom, den};
- den=0;
- }
-
- while(den){
- uint64_t x = nom / den;
- int64_t next_den= nom - den*x;
- int64_t a2n= x*a1.num + a0.num;
- int64_t a2d= x*a1.den + a0.den;
-
- if(a2n > max || a2d > max){
- if(a1.num) x= (max - a0.num) / a1.num;
- if(a1.den) x= FFMIN(x, (max - a0.den) / a1.den);
-
- if (den*(2*x*a1.den + a0.den) > nom*a1.den)
- a1 = (AVRational){x*a1.num + a0.num, x*a1.den + a0.den};
- break;
- }
-
- a0= a1;
- a1= (AVRational){a2n, a2d};
- nom= den;
- den= next_den;
- }
- assert(ff_gcd(a1.num, a1.den) <= 1U);
-
- *dst_nom = sign ? -a1.num : a1.num;
- *dst_den = a1.den;
-
- return den==0;
-}
-
-/**
- * returns b*c.
- */
-AVRational av_mul_q(AVRational b, AVRational c){
- av_reduce(&b.num, &b.den, b.num * (int64_t)c.num, b.den * (int64_t)c.den, INT_MAX);
- return b;
-}
-
-/**
- * returns b/c.
- */
-AVRational av_div_q(AVRational b, AVRational c){
- return av_mul_q(b, (AVRational){c.den, c.num});
-}
-
-/**
- * returns b+c.
- */
-AVRational av_add_q(AVRational b, AVRational c){
- av_reduce(&b.num, &b.den, b.num * (int64_t)c.den + c.num * (int64_t)b.den, b.den * (int64_t)c.den, INT_MAX);
- return b;
-}
-
-/**
- * returns b-c.
- */
-AVRational av_sub_q(AVRational b, AVRational c){
- return av_add_q(b, (AVRational){-c.num, c.den});
-}
-
-/**
- * Converts a double precission floating point number to a AVRational.
- * @param max the maximum allowed numerator and denominator
- */
-AVRational av_d2q(double d, int max){
- AVRational a;
-#define LOG2 0.69314718055994530941723212145817656807550013436025
- int exponent= FFMAX( (int)(log(fabs(d) + 1e-20)/LOG2), 0);
- int64_t den= 1LL << (61 - exponent);
- av_reduce(&a.num, &a.den, (int64_t)(d * den + 0.5), den, max);
-
- return a;
-}
diff --git a/src/libffmpeg/libavutil/rational.h b/src/libffmpeg/libavutil/rational.h
deleted file mode 100644
index 43fc22114..000000000
--- a/src/libffmpeg/libavutil/rational.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Rational numbers
- * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-/**
- * @file rational.h
- * Rational numbers.
- * @author Michael Niedermayer <michaelni@gmx.at>
- */
-
-#ifndef RATIONAL_H
-#define RATIONAL_H
-
-/**
- * Rational number num/den.
- */
-typedef struct AVRational{
- int num; ///< numerator
- int den; ///< denominator
-} AVRational;
-
-/**
- * returns 0 if a==b, 1 if a>b and -1 if a<b.
- */
-static inline int av_cmp_q(AVRational a, AVRational b){
- const int64_t tmp= a.num * (int64_t)b.den - b.num * (int64_t)a.den;
-
- if(tmp) return (tmp>>63)|1;
- else return 0;
-}
-
-/**
- * converts the given AVRational to a double.
- */
-static inline double av_q2d(AVRational a){
- return a.num / (double) a.den;
-}
-
-/**
- * reduce a fraction.
- * this is usefull for framerate calculations
- * @param max the maximum allowed for dst_nom & dst_den
- * @return 1 if exact, 0 otherwise
- */
-int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max);
-
-AVRational av_mul_q(AVRational b, AVRational c);
-AVRational av_div_q(AVRational b, AVRational c);
-AVRational av_add_q(AVRational b, AVRational c);
-AVRational av_sub_q(AVRational b, AVRational c);
-AVRational av_d2q(double d, int max);
-
-#endif // RATIONAL_H
diff --git a/src/libffmpeg/libavutil/x86_cpu.h b/src/libffmpeg/libavutil/x86_cpu.h
deleted file mode 100644
index 3d54b2a60..000000000
--- a/src/libffmpeg/libavutil/x86_cpu.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef AVUTIL_X86CPU_H
-#define AVUTIL_X86CPU_H
-
-#ifdef ARCH_X86_64
-# define REG_a "rax"
-# define REG_b "rbx"
-# define REG_c "rcx"
-# define REG_d "rdx"
-# define REG_D "rdi"
-# define REG_S "rsi"
-# define PTR_SIZE "8"
-
-# define REG_SP "rsp"
-# define REG_BP "rbp"
-# define REGBP rbp
-# define REGa rax
-# define REGb rbx
-# define REGc rcx
-# define REGSP rsp
-
-#else
-
-# define REG_a "eax"
-# define REG_b "ebx"
-# define REG_c "ecx"
-# define REG_d "edx"
-# define REG_D "edi"
-# define REG_S "esi"
-# define PTR_SIZE "4"
-
-# define REG_SP "esp"
-# define REG_BP "ebp"
-# define REGBP ebp
-# define REGa eax
-# define REGb ebx
-# define REGc ecx
-# define REGSP esp
-#endif
-
-#endif /* AVUTIL_X86CPU_H */
diff --git a/src/libmad/D.dat b/src/libmad/D.dat
deleted file mode 100644
index 31c6cd4fa..000000000
--- a/src/libmad/D.dat
+++ /dev/null
@@ -1,607 +0,0 @@
-/*
- * libmad - MPEG audio decoder library
- * Copyright (C) 2000-2004 Underbit Technologies, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: D.dat,v 1.3 2004/04/22 00:22:33 miguelfreitas Exp $
- */
-
-/*
- * These are the coefficients for the subband synthesis window. This is a
- * reordered version of Table B.3 from ISO/IEC 11172-3.
- *
- * Every value is parameterized so that shift optimizations can be made at
- * compile-time. For example, every value can be right-shifted 12 bits to
- * minimize multiply instruction times without any loss of accuracy.
- */
-
- { PRESHIFT(0x00000000) /* 0.000000000 */, /* 0 */
- -PRESHIFT(0x0001d000) /* -0.000442505 */,
- PRESHIFT(0x000d5000) /* 0.003250122 */,
- -PRESHIFT(0x001cb000) /* -0.007003784 */,
- PRESHIFT(0x007f5000) /* 0.031082153 */,
- -PRESHIFT(0x01421000) /* -0.078628540 */,
- PRESHIFT(0x019ae000) /* 0.100311279 */,
- -PRESHIFT(0x09271000) /* -0.572036743 */,
- PRESHIFT(0x1251e000) /* 1.144989014 */,
- PRESHIFT(0x09271000) /* 0.572036743 */,
- PRESHIFT(0x019ae000) /* 0.100311279 */,
- PRESHIFT(0x01421000) /* 0.078628540 */,
- PRESHIFT(0x007f5000) /* 0.031082153 */,
- PRESHIFT(0x001cb000) /* 0.007003784 */,
- PRESHIFT(0x000d5000) /* 0.003250122 */,
- PRESHIFT(0x0001d000) /* 0.000442505 */,
-
- PRESHIFT(0x00000000) /* 0.000000000 */,
- -PRESHIFT(0x0001d000) /* -0.000442505 */,
- PRESHIFT(0x000d5000) /* 0.003250122 */,
- -PRESHIFT(0x001cb000) /* -0.007003784 */,
- PRESHIFT(0x007f5000) /* 0.031082153 */,
- -PRESHIFT(0x01421000) /* -0.078628540 */,
- PRESHIFT(0x019ae000) /* 0.100311279 */,
- -PRESHIFT(0x09271000) /* -0.572036743 */,
- PRESHIFT(0x1251e000) /* 1.144989014 */,
- PRESHIFT(0x09271000) /* 0.572036743 */,
- PRESHIFT(0x019ae000) /* 0.100311279 */,
- PRESHIFT(0x01421000) /* 0.078628540 */,
- PRESHIFT(0x007f5000) /* 0.031082153 */,
- PRESHIFT(0x001cb000) /* 0.007003784 */,
- PRESHIFT(0x000d5000) /* 0.003250122 */,
- PRESHIFT(0x0001d000) /* 0.000442505 */ },
-
- { -PRESHIFT(0x00001000) /* -0.000015259 */, /* 1 */
- -PRESHIFT(0x0001f000) /* -0.000473022 */,
- PRESHIFT(0x000da000) /* 0.003326416 */,
- -PRESHIFT(0x00207000) /* -0.007919312 */,
- PRESHIFT(0x007d0000) /* 0.030517578 */,
- -PRESHIFT(0x0158d000) /* -0.084182739 */,
- PRESHIFT(0x01747000) /* 0.090927124 */,
- -PRESHIFT(0x099a8000) /* -0.600219727 */,
- PRESHIFT(0x124f0000) /* 1.144287109 */,
- PRESHIFT(0x08b38000) /* 0.543823242 */,
- PRESHIFT(0x01bde000) /* 0.108856201 */,
- PRESHIFT(0x012b4000) /* 0.073059082 */,
- PRESHIFT(0x0080f000) /* 0.031478882 */,
- PRESHIFT(0x00191000) /* 0.006118774 */,
- PRESHIFT(0x000d0000) /* 0.003173828 */,
- PRESHIFT(0x0001a000) /* 0.000396729 */,
-
- -PRESHIFT(0x00001000) /* -0.000015259 */,
- -PRESHIFT(0x0001f000) /* -0.000473022 */,
- PRESHIFT(0x000da000) /* 0.003326416 */,
- -PRESHIFT(0x00207000) /* -0.007919312 */,
- PRESHIFT(0x007d0000) /* 0.030517578 */,
- -PRESHIFT(0x0158d000) /* -0.084182739 */,
- PRESHIFT(0x01747000) /* 0.090927124 */,
- -PRESHIFT(0x099a8000) /* -0.600219727 */,
- PRESHIFT(0x124f0000) /* 1.144287109 */,
- PRESHIFT(0x08b38000) /* 0.543823242 */,
- PRESHIFT(0x01bde000) /* 0.108856201 */,
- PRESHIFT(0x012b4000) /* 0.073059082 */,
- PRESHIFT(0x0080f000) /* 0.031478882 */,
- PRESHIFT(0x00191000) /* 0.006118774 */,
- PRESHIFT(0x000d0000) /* 0.003173828 */,
- PRESHIFT(0x0001a000) /* 0.000396729 */ },
-
- { -PRESHIFT(0x00001000) /* -0.000015259 */, /* 2 */
- -PRESHIFT(0x00023000) /* -0.000534058 */,
- PRESHIFT(0x000de000) /* 0.003387451 */,
- -PRESHIFT(0x00245000) /* -0.008865356 */,
- PRESHIFT(0x007a0000) /* 0.029785156 */,
- -PRESHIFT(0x016f7000) /* -0.089706421 */,
- PRESHIFT(0x014a8000) /* 0.080688477 */,
- -PRESHIFT(0x0a0d8000) /* -0.628295898 */,
- PRESHIFT(0x12468000) /* 1.142211914 */,
- PRESHIFT(0x083ff000) /* 0.515609741 */,
- PRESHIFT(0x01dd8000) /* 0.116577148 */,
- PRESHIFT(0x01149000) /* 0.067520142 */,
- PRESHIFT(0x00820000) /* 0.031738281 */,
- PRESHIFT(0x0015b000) /* 0.005294800 */,
- PRESHIFT(0x000ca000) /* 0.003082275 */,
- PRESHIFT(0x00018000) /* 0.000366211 */,
-
- -PRESHIFT(0x00001000) /* -0.000015259 */,
- -PRESHIFT(0x00023000) /* -0.000534058 */,
- PRESHIFT(0x000de000) /* 0.003387451 */,
- -PRESHIFT(0x00245000) /* -0.008865356 */,
- PRESHIFT(0x007a0000) /* 0.029785156 */,
- -PRESHIFT(0x016f7000) /* -0.089706421 */,
- PRESHIFT(0x014a8000) /* 0.080688477 */,
- -PRESHIFT(0x0a0d8000) /* -0.628295898 */,
- PRESHIFT(0x12468000) /* 1.142211914 */,
- PRESHIFT(0x083ff000) /* 0.515609741 */,
- PRESHIFT(0x01dd8000) /* 0.116577148 */,
- PRESHIFT(0x01149000) /* 0.067520142 */,
- PRESHIFT(0x00820000) /* 0.031738281 */,
- PRESHIFT(0x0015b000) /* 0.005294800 */,
- PRESHIFT(0x000ca000) /* 0.003082275 */,
- PRESHIFT(0x00018000) /* 0.000366211 */ },
-
- { -PRESHIFT(0x00001000) /* -0.000015259 */, /* 3 */
- -PRESHIFT(0x00026000) /* -0.000579834 */,
- PRESHIFT(0x000e1000) /* 0.003433228 */,
- -PRESHIFT(0x00285000) /* -0.009841919 */,
- PRESHIFT(0x00765000) /* 0.028884888 */,
- -PRESHIFT(0x0185d000) /* -0.095169067 */,
- PRESHIFT(0x011d1000) /* 0.069595337 */,
- -PRESHIFT(0x0a7fe000) /* -0.656219482 */,
- PRESHIFT(0x12386000) /* 1.138763428 */,
- PRESHIFT(0x07ccb000) /* 0.487472534 */,
- PRESHIFT(0x01f9c000) /* 0.123474121 */,
- PRESHIFT(0x00fdf000) /* 0.061996460 */,
- PRESHIFT(0x00827000) /* 0.031845093 */,
- PRESHIFT(0x00126000) /* 0.004486084 */,
- PRESHIFT(0x000c4000) /* 0.002990723 */,
- PRESHIFT(0x00015000) /* 0.000320435 */,
-
- -PRESHIFT(0x00001000) /* -0.000015259 */,
- -PRESHIFT(0x00026000) /* -0.000579834 */,
- PRESHIFT(0x000e1000) /* 0.003433228 */,
- -PRESHIFT(0x00285000) /* -0.009841919 */,
- PRESHIFT(0x00765000) /* 0.028884888 */,
- -PRESHIFT(0x0185d000) /* -0.095169067 */,
- PRESHIFT(0x011d1000) /* 0.069595337 */,
- -PRESHIFT(0x0a7fe000) /* -0.656219482 */,
- PRESHIFT(0x12386000) /* 1.138763428 */,
- PRESHIFT(0x07ccb000) /* 0.487472534 */,
- PRESHIFT(0x01f9c000) /* 0.123474121 */,
- PRESHIFT(0x00fdf000) /* 0.061996460 */,
- PRESHIFT(0x00827000) /* 0.031845093 */,
- PRESHIFT(0x00126000) /* 0.004486084 */,
- PRESHIFT(0x000c4000) /* 0.002990723 */,
- PRESHIFT(0x00015000) /* 0.000320435 */ },
-
- { -PRESHIFT(0x00001000) /* -0.000015259 */, /* 4 */
- -PRESHIFT(0x00029000) /* -0.000625610 */,
- PRESHIFT(0x000e3000) /* 0.003463745 */,
- -PRESHIFT(0x002c7000) /* -0.010848999 */,
- PRESHIFT(0x0071e000) /* 0.027801514 */,
- -PRESHIFT(0x019bd000) /* -0.100540161 */,
- PRESHIFT(0x00ec0000) /* 0.057617187 */,
- -PRESHIFT(0x0af15000) /* -0.683914185 */,
- PRESHIFT(0x12249000) /* 1.133926392 */,
- PRESHIFT(0x075a0000) /* 0.459472656 */,
- PRESHIFT(0x0212c000) /* 0.129577637 */,
- PRESHIFT(0x00e79000) /* 0.056533813 */,
- PRESHIFT(0x00825000) /* 0.031814575 */,
- PRESHIFT(0x000f4000) /* 0.003723145 */,
- PRESHIFT(0x000be000) /* 0.002899170 */,
- PRESHIFT(0x00013000) /* 0.000289917 */,
-
- -PRESHIFT(0x00001000) /* -0.000015259 */,
- -PRESHIFT(0x00029000) /* -0.000625610 */,
- PRESHIFT(0x000e3000) /* 0.003463745 */,
- -PRESHIFT(0x002c7000) /* -0.010848999 */,
- PRESHIFT(0x0071e000) /* 0.027801514 */,
- -PRESHIFT(0x019bd000) /* -0.100540161 */,
- PRESHIFT(0x00ec0000) /* 0.057617187 */,
- -PRESHIFT(0x0af15000) /* -0.683914185 */,
- PRESHIFT(0x12249000) /* 1.133926392 */,
- PRESHIFT(0x075a0000) /* 0.459472656 */,
- PRESHIFT(0x0212c000) /* 0.129577637 */,
- PRESHIFT(0x00e79000) /* 0.056533813 */,
- PRESHIFT(0x00825000) /* 0.031814575 */,
- PRESHIFT(0x000f4000) /* 0.003723145 */,
- PRESHIFT(0x000be000) /* 0.002899170 */,
- PRESHIFT(0x00013000) /* 0.000289917 */ },
-
- { -PRESHIFT(0x00001000) /* -0.000015259 */, /* 5 */
- -PRESHIFT(0x0002d000) /* -0.000686646 */,
- PRESHIFT(0x000e4000) /* 0.003479004 */,
- -PRESHIFT(0x0030b000) /* -0.011886597 */,
- PRESHIFT(0x006cb000) /* 0.026535034 */,
- -PRESHIFT(0x01b17000) /* -0.105819702 */,
- PRESHIFT(0x00b77000) /* 0.044784546 */,
- -PRESHIFT(0x0b619000) /* -0.711318970 */,
- PRESHIFT(0x120b4000) /* 1.127746582 */,
- PRESHIFT(0x06e81000) /* 0.431655884 */,
- PRESHIFT(0x02288000) /* 0.134887695 */,
- PRESHIFT(0x00d17000) /* 0.051132202 */,
- PRESHIFT(0x0081b000) /* 0.031661987 */,
- PRESHIFT(0x000c5000) /* 0.003005981 */,
- PRESHIFT(0x000b7000) /* 0.002792358 */,
- PRESHIFT(0x00011000) /* 0.000259399 */,
-
- -PRESHIFT(0x00001000) /* -0.000015259 */,
- -PRESHIFT(0x0002d000) /* -0.000686646 */,
- PRESHIFT(0x000e4000) /* 0.003479004 */,
- -PRESHIFT(0x0030b000) /* -0.011886597 */,
- PRESHIFT(0x006cb000) /* 0.026535034 */,
- -PRESHIFT(0x01b17000) /* -0.105819702 */,
- PRESHIFT(0x00b77000) /* 0.044784546 */,
- -PRESHIFT(0x0b619000) /* -0.711318970 */,
- PRESHIFT(0x120b4000) /* 1.127746582 */,
- PRESHIFT(0x06e81000) /* 0.431655884 */,
- PRESHIFT(0x02288000) /* 0.134887695 */,
- PRESHIFT(0x00d17000) /* 0.051132202 */,
- PRESHIFT(0x0081b000) /* 0.031661987 */,
- PRESHIFT(0x000c5000) /* 0.003005981 */,
- PRESHIFT(0x000b7000) /* 0.002792358 */,
- PRESHIFT(0x00011000) /* 0.000259399 */ },
-
- { -PRESHIFT(0x00001000) /* -0.000015259 */, /* 6 */
- -PRESHIFT(0x00031000) /* -0.000747681 */,
- PRESHIFT(0x000e4000) /* 0.003479004 */,
- -PRESHIFT(0x00350000) /* -0.012939453 */,
- PRESHIFT(0x0066c000) /* 0.025085449 */,
- -PRESHIFT(0x01c67000) /* -0.110946655 */,
- PRESHIFT(0x007f5000) /* 0.031082153 */,
- -PRESHIFT(0x0bd06000) /* -0.738372803 */,
- PRESHIFT(0x11ec7000) /* 1.120223999 */,
- PRESHIFT(0x06772000) /* 0.404083252 */,
- PRESHIFT(0x023b3000) /* 0.139450073 */,
- PRESHIFT(0x00bbc000) /* 0.045837402 */,
- PRESHIFT(0x00809000) /* 0.031387329 */,
- PRESHIFT(0x00099000) /* 0.002334595 */,
- PRESHIFT(0x000b0000) /* 0.002685547 */,
- PRESHIFT(0x00010000) /* 0.000244141 */,
-
- -PRESHIFT(0x00001000) /* -0.000015259 */,
- -PRESHIFT(0x00031000) /* -0.000747681 */,
- PRESHIFT(0x000e4000) /* 0.003479004 */,
- -PRESHIFT(0x00350000) /* -0.012939453 */,
- PRESHIFT(0x0066c000) /* 0.025085449 */,
- -PRESHIFT(0x01c67000) /* -0.110946655 */,
- PRESHIFT(0x007f5000) /* 0.031082153 */,
- -PRESHIFT(0x0bd06000) /* -0.738372803 */,
- PRESHIFT(0x11ec7000) /* 1.120223999 */,
- PRESHIFT(0x06772000) /* 0.404083252 */,
- PRESHIFT(0x023b3000) /* 0.139450073 */,
- PRESHIFT(0x00bbc000) /* 0.045837402 */,
- PRESHIFT(0x00809000) /* 0.031387329 */,
- PRESHIFT(0x00099000) /* 0.002334595 */,
- PRESHIFT(0x000b0000) /* 0.002685547 */,
- PRESHIFT(0x00010000) /* 0.000244141 */ },
-
- { -PRESHIFT(0x00002000) /* -0.000030518 */, /* 7 */
- -PRESHIFT(0x00035000) /* -0.000808716 */,
- PRESHIFT(0x000e3000) /* 0.003463745 */,
- -PRESHIFT(0x00397000) /* -0.014022827 */,
- PRESHIFT(0x005ff000) /* 0.023422241 */,
- -PRESHIFT(0x01dad000) /* -0.115921021 */,
- PRESHIFT(0x0043a000) /* 0.016510010 */,
- -PRESHIFT(0x0c3d9000) /* -0.765029907 */,
- PRESHIFT(0x11c83000) /* 1.111373901 */,
- PRESHIFT(0x06076000) /* 0.376800537 */,
- PRESHIFT(0x024ad000) /* 0.143264771 */,
- PRESHIFT(0x00a67000) /* 0.040634155 */,
- PRESHIFT(0x007f0000) /* 0.031005859 */,
- PRESHIFT(0x0006f000) /* 0.001693726 */,
- PRESHIFT(0x000a9000) /* 0.002578735 */,
- PRESHIFT(0x0000e000) /* 0.000213623 */,
-
- -PRESHIFT(0x00002000) /* -0.000030518 */,
- -PRESHIFT(0x00035000) /* -0.000808716 */,
- PRESHIFT(0x000e3000) /* 0.003463745 */,
- -PRESHIFT(0x00397000) /* -0.014022827 */,
- PRESHIFT(0x005ff000) /* 0.023422241 */,
- -PRESHIFT(0x01dad000) /* -0.115921021 */,
- PRESHIFT(0x0043a000) /* 0.016510010 */,
- -PRESHIFT(0x0c3d9000) /* -0.765029907 */,
- PRESHIFT(0x11c83000) /* 1.111373901 */,
- PRESHIFT(0x06076000) /* 0.376800537 */,
- PRESHIFT(0x024ad000) /* 0.143264771 */,
- PRESHIFT(0x00a67000) /* 0.040634155 */,
- PRESHIFT(0x007f0000) /* 0.031005859 */,
- PRESHIFT(0x0006f000) /* 0.001693726 */,
- PRESHIFT(0x000a9000) /* 0.002578735 */,
- PRESHIFT(0x0000e000) /* 0.000213623 */ },
-
- { -PRESHIFT(0x00002000) /* -0.000030518 */, /* 8 */
- -PRESHIFT(0x0003a000) /* -0.000885010 */,
- PRESHIFT(0x000e0000) /* 0.003417969 */,
- -PRESHIFT(0x003df000) /* -0.015121460 */,
- PRESHIFT(0x00586000) /* 0.021575928 */,
- -PRESHIFT(0x01ee6000) /* -0.120697021 */,
- PRESHIFT(0x00046000) /* 0.001068115 */,
- -PRESHIFT(0x0ca8d000) /* -0.791213989 */,
- PRESHIFT(0x119e9000) /* 1.101211548 */,
- PRESHIFT(0x05991000) /* 0.349868774 */,
- PRESHIFT(0x02578000) /* 0.146362305 */,
- PRESHIFT(0x0091a000) /* 0.035552979 */,
- PRESHIFT(0x007d1000) /* 0.030532837 */,
- PRESHIFT(0x00048000) /* 0.001098633 */,
- PRESHIFT(0x000a1000) /* 0.002456665 */,
- PRESHIFT(0x0000d000) /* 0.000198364 */,
-
- -PRESHIFT(0x00002000) /* -0.000030518 */,
- -PRESHIFT(0x0003a000) /* -0.000885010 */,
- PRESHIFT(0x000e0000) /* 0.003417969 */,
- -PRESHIFT(0x003df000) /* -0.015121460 */,
- PRESHIFT(0x00586000) /* 0.021575928 */,
- -PRESHIFT(0x01ee6000) /* -0.120697021 */,
- PRESHIFT(0x00046000) /* 0.001068115 */,
- -PRESHIFT(0x0ca8d000) /* -0.791213989 */,
- PRESHIFT(0x119e9000) /* 1.101211548 */,
- PRESHIFT(0x05991000) /* 0.349868774 */,
- PRESHIFT(0x02578000) /* 0.146362305 */,
- PRESHIFT(0x0091a000) /* 0.035552979 */,
- PRESHIFT(0x007d1000) /* 0.030532837 */,
- PRESHIFT(0x00048000) /* 0.001098633 */,
- PRESHIFT(0x000a1000) /* 0.002456665 */,
- PRESHIFT(0x0000d000) /* 0.000198364 */ },
-
- { -PRESHIFT(0x00002000) /* -0.000030518 */, /* 9 */
- -PRESHIFT(0x0003f000) /* -0.000961304 */,
- PRESHIFT(0x000dd000) /* 0.003372192 */,
- -PRESHIFT(0x00428000) /* -0.016235352 */,
- PRESHIFT(0x00500000) /* 0.019531250 */,
- -PRESHIFT(0x02011000) /* -0.125259399 */,
- -PRESHIFT(0x003e6000) /* -0.015228271 */,
- -PRESHIFT(0x0d11e000) /* -0.816864014 */,
- PRESHIFT(0x116fc000) /* 1.089782715 */,
- PRESHIFT(0x052c5000) /* 0.323318481 */,
- PRESHIFT(0x02616000) /* 0.148773193 */,
- PRESHIFT(0x007d6000) /* 0.030609131 */,
- PRESHIFT(0x007aa000) /* 0.029937744 */,
- PRESHIFT(0x00024000) /* 0.000549316 */,
- PRESHIFT(0x0009a000) /* 0.002349854 */,
- PRESHIFT(0x0000b000) /* 0.000167847 */,
-
- -PRESHIFT(0x00002000) /* -0.000030518 */,
- -PRESHIFT(0x0003f000) /* -0.000961304 */,
- PRESHIFT(0x000dd000) /* 0.003372192 */,
- -PRESHIFT(0x00428000) /* -0.016235352 */,
- PRESHIFT(0x00500000) /* 0.019531250 */,
- -PRESHIFT(0x02011000) /* -0.125259399 */,
- -PRESHIFT(0x003e6000) /* -0.015228271 */,
- -PRESHIFT(0x0d11e000) /* -0.816864014 */,
- PRESHIFT(0x116fc000) /* 1.089782715 */,
- PRESHIFT(0x052c5000) /* 0.323318481 */,
- PRESHIFT(0x02616000) /* 0.148773193 */,
- PRESHIFT(0x007d6000) /* 0.030609131 */,
- PRESHIFT(0x007aa000) /* 0.029937744 */,
- PRESHIFT(0x00024000) /* 0.000549316 */,
- PRESHIFT(0x0009a000) /* 0.002349854 */,
- PRESHIFT(0x0000b000) /* 0.000167847 */ },
-
- { -PRESHIFT(0x00002000) /* -0.000030518 */, /* 10 */
- -PRESHIFT(0x00044000) /* -0.001037598 */,
- PRESHIFT(0x000d7000) /* 0.003280640 */,
- -PRESHIFT(0x00471000) /* -0.017349243 */,
- PRESHIFT(0x0046b000) /* 0.017257690 */,
- -PRESHIFT(0x0212b000) /* -0.129562378 */,
- -PRESHIFT(0x0084a000) /* -0.032379150 */,
- -PRESHIFT(0x0d78a000) /* -0.841949463 */,
- PRESHIFT(0x113be000) /* 1.077117920 */,
- PRESHIFT(0x04c16000) /* 0.297210693 */,
- PRESHIFT(0x02687000) /* 0.150497437 */,
- PRESHIFT(0x0069c000) /* 0.025817871 */,
- PRESHIFT(0x0077f000) /* 0.029281616 */,
- PRESHIFT(0x00002000) /* 0.000030518 */,
- PRESHIFT(0x00093000) /* 0.002243042 */,
- PRESHIFT(0x0000a000) /* 0.000152588 */,
-
- -PRESHIFT(0x00002000) /* -0.000030518 */,
- -PRESHIFT(0x00044000) /* -0.001037598 */,
- PRESHIFT(0x000d7000) /* 0.003280640 */,
- -PRESHIFT(0x00471000) /* -0.017349243 */,
- PRESHIFT(0x0046b000) /* 0.017257690 */,
- -PRESHIFT(0x0212b000) /* -0.129562378 */,
- -PRESHIFT(0x0084a000) /* -0.032379150 */,
- -PRESHIFT(0x0d78a000) /* -0.841949463 */,
- PRESHIFT(0x113be000) /* 1.077117920 */,
- PRESHIFT(0x04c16000) /* 0.297210693 */,
- PRESHIFT(0x02687000) /* 0.150497437 */,
- PRESHIFT(0x0069c000) /* 0.025817871 */,
- PRESHIFT(0x0077f000) /* 0.029281616 */,
- PRESHIFT(0x00002000) /* 0.000030518 */,
- PRESHIFT(0x00093000) /* 0.002243042 */,
- PRESHIFT(0x0000a000) /* 0.000152588 */ },
-
- { -PRESHIFT(0x00003000) /* -0.000045776 */, /* 11 */
- -PRESHIFT(0x00049000) /* -0.001113892 */,
- PRESHIFT(0x000d0000) /* 0.003173828 */,
- -PRESHIFT(0x004ba000) /* -0.018463135 */,
- PRESHIFT(0x003ca000) /* 0.014801025 */,
- -PRESHIFT(0x02233000) /* -0.133590698 */,
- -PRESHIFT(0x00ce4000) /* -0.050354004 */,
- -PRESHIFT(0x0ddca000) /* -0.866363525 */,
- PRESHIFT(0x1102f000) /* 1.063217163 */,
- PRESHIFT(0x04587000) /* 0.271591187 */,
- PRESHIFT(0x026cf000) /* 0.151596069 */,
- PRESHIFT(0x0056c000) /* 0.021179199 */,
- PRESHIFT(0x0074e000) /* 0.028533936 */,
- -PRESHIFT(0x0001d000) /* -0.000442505 */,
- PRESHIFT(0x0008b000) /* 0.002120972 */,
- PRESHIFT(0x00009000) /* 0.000137329 */,
-
- -PRESHIFT(0x00003000) /* -0.000045776 */,
- -PRESHIFT(0x00049000) /* -0.001113892 */,
- PRESHIFT(0x000d0000) /* 0.003173828 */,
- -PRESHIFT(0x004ba000) /* -0.018463135 */,
- PRESHIFT(0x003ca000) /* 0.014801025 */,
- -PRESHIFT(0x02233000) /* -0.133590698 */,
- -PRESHIFT(0x00ce4000) /* -0.050354004 */,
- -PRESHIFT(0x0ddca000) /* -0.866363525 */,
- PRESHIFT(0x1102f000) /* 1.063217163 */,
- PRESHIFT(0x04587000) /* 0.271591187 */,
- PRESHIFT(0x026cf000) /* 0.151596069 */,
- PRESHIFT(0x0056c000) /* 0.021179199 */,
- PRESHIFT(0x0074e000) /* 0.028533936 */,
- -PRESHIFT(0x0001d000) /* -0.000442505 */,
- PRESHIFT(0x0008b000) /* 0.002120972 */,
- PRESHIFT(0x00009000) /* 0.000137329 */ },
-
- { -PRESHIFT(0x00003000) /* -0.000045776 */, /* 12 */
- -PRESHIFT(0x0004f000) /* -0.001205444 */,
- PRESHIFT(0x000c8000) /* 0.003051758 */,
- -PRESHIFT(0x00503000) /* -0.019577026 */,
- PRESHIFT(0x0031a000) /* 0.012115479 */,
- -PRESHIFT(0x02326000) /* -0.137298584 */,
- -PRESHIFT(0x011b5000) /* -0.069168091 */,
- -PRESHIFT(0x0e3dd000) /* -0.890090942 */,
- PRESHIFT(0x10c54000) /* 1.048156738 */,
- PRESHIFT(0x03f1b000) /* 0.246505737 */,
- PRESHIFT(0x026ee000) /* 0.152069092 */,
- PRESHIFT(0x00447000) /* 0.016708374 */,
- PRESHIFT(0x00719000) /* 0.027725220 */,
- -PRESHIFT(0x00039000) /* -0.000869751 */,
- PRESHIFT(0x00084000) /* 0.002014160 */,
- PRESHIFT(0x00008000) /* 0.000122070 */,
-
- -PRESHIFT(0x00003000) /* -0.000045776 */,
- -PRESHIFT(0x0004f000) /* -0.001205444 */,
- PRESHIFT(0x000c8000) /* 0.003051758 */,
- -PRESHIFT(0x00503000) /* -0.019577026 */,
- PRESHIFT(0x0031a000) /* 0.012115479 */,
- -PRESHIFT(0x02326000) /* -0.137298584 */,
- -PRESHIFT(0x011b5000) /* -0.069168091 */,
- -PRESHIFT(0x0e3dd000) /* -0.890090942 */,
- PRESHIFT(0x10c54000) /* 1.048156738 */,
- PRESHIFT(0x03f1b000) /* 0.246505737 */,
- PRESHIFT(0x026ee000) /* 0.152069092 */,
- PRESHIFT(0x00447000) /* 0.016708374 */,
- PRESHIFT(0x00719000) /* 0.027725220 */,
- -PRESHIFT(0x00039000) /* -0.000869751 */,
- PRESHIFT(0x00084000) /* 0.002014160 */,
- PRESHIFT(0x00008000) /* 0.000122070 */ },
-
- { -PRESHIFT(0x00004000) /* -0.000061035 */, /* 13 */
- -PRESHIFT(0x00055000) /* -0.001296997 */,
- PRESHIFT(0x000bd000) /* 0.002883911 */,
- -PRESHIFT(0x0054c000) /* -0.020690918 */,
- PRESHIFT(0x0025d000) /* 0.009231567 */,
- -PRESHIFT(0x02403000) /* -0.140670776 */,
- -PRESHIFT(0x016ba000) /* -0.088775635 */,
- -PRESHIFT(0x0e9be000) /* -0.913055420 */,
- PRESHIFT(0x1082d000) /* 1.031936646 */,
- PRESHIFT(0x038d4000) /* 0.221984863 */,
- PRESHIFT(0x026e7000) /* 0.151962280 */,
- PRESHIFT(0x0032e000) /* 0.012420654 */,
- PRESHIFT(0x006df000) /* 0.026840210 */,
- -PRESHIFT(0x00053000) /* -0.001266479 */,
- PRESHIFT(0x0007d000) /* 0.001907349 */,
- PRESHIFT(0x00007000) /* 0.000106812 */,
-
- -PRESHIFT(0x00004000) /* -0.000061035 */,
- -PRESHIFT(0x00055000) /* -0.001296997 */,
- PRESHIFT(0x000bd000) /* 0.002883911 */,
- -PRESHIFT(0x0054c000) /* -0.020690918 */,
- PRESHIFT(0x0025d000) /* 0.009231567 */,
- -PRESHIFT(0x02403000) /* -0.140670776 */,
- -PRESHIFT(0x016ba000) /* -0.088775635 */,
- -PRESHIFT(0x0e9be000) /* -0.913055420 */,
- PRESHIFT(0x1082d000) /* 1.031936646 */,
- PRESHIFT(0x038d4000) /* 0.221984863 */,
- PRESHIFT(0x026e7000) /* 0.151962280 */,
- PRESHIFT(0x0032e000) /* 0.012420654 */,
- PRESHIFT(0x006df000) /* 0.026840210 */,
- -PRESHIFT(0x00053000) /* -0.001266479 */,
- PRESHIFT(0x0007d000) /* 0.001907349 */,
- PRESHIFT(0x00007000) /* 0.000106812 */ },
-
- { -PRESHIFT(0x00004000) /* -0.000061035 */, /* 14 */
- -PRESHIFT(0x0005b000) /* -0.001388550 */,
- PRESHIFT(0x000b1000) /* 0.002700806 */,
- -PRESHIFT(0x00594000) /* -0.021789551 */,
- PRESHIFT(0x00192000) /* 0.006134033 */,
- -PRESHIFT(0x024c8000) /* -0.143676758 */,
- -PRESHIFT(0x01bf2000) /* -0.109161377 */,
- -PRESHIFT(0x0ef69000) /* -0.935195923 */,
- PRESHIFT(0x103be000) /* 1.014617920 */,
- PRESHIFT(0x032b4000) /* 0.198059082 */,
- PRESHIFT(0x026bc000) /* 0.151306152 */,
- PRESHIFT(0x00221000) /* 0.008316040 */,
- PRESHIFT(0x006a2000) /* 0.025909424 */,
- -PRESHIFT(0x0006a000) /* -0.001617432 */,
- PRESHIFT(0x00075000) /* 0.001785278 */,
- PRESHIFT(0x00007000) /* 0.000106812 */,
-
- -PRESHIFT(0x00004000) /* -0.000061035 */,
- -PRESHIFT(0x0005b000) /* -0.001388550 */,
- PRESHIFT(0x000b1000) /* 0.002700806 */,
- -PRESHIFT(0x00594000) /* -0.021789551 */,
- PRESHIFT(0x00192000) /* 0.006134033 */,
- -PRESHIFT(0x024c8000) /* -0.143676758 */,
- -PRESHIFT(0x01bf2000) /* -0.109161377 */,
- -PRESHIFT(0x0ef69000) /* -0.935195923 */,
- PRESHIFT(0x103be000) /* 1.014617920 */,
- PRESHIFT(0x032b4000) /* 0.198059082 */,
- PRESHIFT(0x026bc000) /* 0.151306152 */,
- PRESHIFT(0x00221000) /* 0.008316040 */,
- PRESHIFT(0x006a2000) /* 0.025909424 */,
- -PRESHIFT(0x0006a000) /* -0.001617432 */,
- PRESHIFT(0x00075000) /* 0.001785278 */,
- PRESHIFT(0x00007000) /* 0.000106812 */ },
-
- { -PRESHIFT(0x00005000) /* -0.000076294 */, /* 15 */
- -PRESHIFT(0x00061000) /* -0.001480103 */,
- PRESHIFT(0x000a3000) /* 0.002487183 */,
- -PRESHIFT(0x005da000) /* -0.022857666 */,
- PRESHIFT(0x000b9000) /* 0.002822876 */,
- -PRESHIFT(0x02571000) /* -0.146255493 */,
- -PRESHIFT(0x0215c000) /* -0.130310059 */,
- -PRESHIFT(0x0f4dc000) /* -0.956481934 */,
- PRESHIFT(0x0ff0a000) /* 0.996246338 */,
- PRESHIFT(0x02cbf000) /* 0.174789429 */,
- PRESHIFT(0x0266e000) /* 0.150115967 */,
- PRESHIFT(0x00120000) /* 0.004394531 */,
- PRESHIFT(0x00662000) /* 0.024932861 */,
- -PRESHIFT(0x0007f000) /* -0.001937866 */,
- PRESHIFT(0x0006f000) /* 0.001693726 */,
- PRESHIFT(0x00006000) /* 0.000091553 */,
-
- -PRESHIFT(0x00005000) /* -0.000076294 */,
- -PRESHIFT(0x00061000) /* -0.001480103 */,
- PRESHIFT(0x000a3000) /* 0.002487183 */,
- -PRESHIFT(0x005da000) /* -0.022857666 */,
- PRESHIFT(0x000b9000) /* 0.002822876 */,
- -PRESHIFT(0x02571000) /* -0.146255493 */,
- -PRESHIFT(0x0215c000) /* -0.130310059 */,
- -PRESHIFT(0x0f4dc000) /* -0.956481934 */,
- PRESHIFT(0x0ff0a000) /* 0.996246338 */,
- PRESHIFT(0x02cbf000) /* 0.174789429 */,
- PRESHIFT(0x0266e000) /* 0.150115967 */,
- PRESHIFT(0x00120000) /* 0.004394531 */,
- PRESHIFT(0x00662000) /* 0.024932861 */,
- -PRESHIFT(0x0007f000) /* -0.001937866 */,
- PRESHIFT(0x0006f000) /* 0.001693726 */,
- PRESHIFT(0x00006000) /* 0.000091553 */ },
-
- { -PRESHIFT(0x00005000) /* -0.000076294 */, /* 16 */
- -PRESHIFT(0x00068000) /* -0.001586914 */,
- PRESHIFT(0x00092000) /* 0.002227783 */,
- -PRESHIFT(0x0061f000) /* -0.023910522 */,
- -PRESHIFT(0x0002d000) /* -0.000686646 */,
- -PRESHIFT(0x025ff000) /* -0.148422241 */,
- -PRESHIFT(0x026f7000) /* -0.152206421 */,
- -PRESHIFT(0x0fa13000) /* -0.976852417 */,
- PRESHIFT(0x0fa13000) /* 0.976852417 */,
- PRESHIFT(0x026f7000) /* 0.152206421 */,
- PRESHIFT(0x025ff000) /* 0.148422241 */,
- PRESHIFT(0x0002d000) /* 0.000686646 */,
- PRESHIFT(0x0061f000) /* 0.023910522 */,
- -PRESHIFT(0x00092000) /* -0.002227783 */,
- PRESHIFT(0x00068000) /* 0.001586914 */,
- PRESHIFT(0x00005000) /* 0.000076294 */,
-
- -PRESHIFT(0x00005000) /* -0.000076294 */,
- -PRESHIFT(0x00068000) /* -0.001586914 */,
- PRESHIFT(0x00092000) /* 0.002227783 */,
- -PRESHIFT(0x0061f000) /* -0.023910522 */,
- -PRESHIFT(0x0002d000) /* -0.000686646 */,
- -PRESHIFT(0x025ff000) /* -0.148422241 */,
- -PRESHIFT(0x026f7000) /* -0.152206421 */,
- -PRESHIFT(0x0fa13000) /* -0.976852417 */,
- PRESHIFT(0x0fa13000) /* 0.976852417 */,
- PRESHIFT(0x026f7000) /* 0.152206421 */,
- PRESHIFT(0x025ff000) /* 0.148422241 */,
- PRESHIFT(0x0002d000) /* 0.000686646 */,
- PRESHIFT(0x0061f000) /* 0.023910522 */,
- -PRESHIFT(0x00092000) /* -0.002227783 */,
- PRESHIFT(0x00068000) /* 0.001586914 */,
- PRESHIFT(0x00005000) /* 0.000076294 */ }
diff --git a/src/libmad/Makefile.am b/src/libmad/Makefile.am
deleted file mode 100644
index c879645c5..000000000
--- a/src/libmad/Makefile.am
+++ /dev/null
@@ -1,57 +0,0 @@
-include $(top_srcdir)/misc/Makefile.common
-
-AM_CFLAGS = -DOPT_SPEED
-
-EXTRA_DIST = imdct_l_arm.S
-
-if MAD
-mad_module = xineplug_decode_mad.la
-endif
-
-xineplug_LTLIBRARIES = $(mad_module)
-
-if EXTERNAL_LIBMAD
-internal_sources =
-else
-internal_sources = \
- bit.c \
- fixed.c \
- frame.c \
- huffman.c \
- layer12.c \
- layer3.c \
- stream.c \
- synth.c \
- timer.c \
- version.c
-endif
-
-xineplug_decode_mad_la_SOURCES = \
- xine_mad_decoder.c \
- $(internal_sources)
-
-if EXTERNAL_LIBMAD
-xineplug_decode_mad_la_LIBADD = $(XINE_LIB) $(LIBMAD_LIBS)
-else
-xineplug_decode_mad_la_LIBADD = $(XINE_LIB)
-endif
-xineplug_decode_mad_la_CFLAGS = $(LIBMAD_CFLAGS) $(VISIBILITY_FLAG)
-xineplug_decode_mad_la_LDFLAGS = $(xineplug_ldflags)
-
-noinst_HEADERS = \
- D.dat \
- imdct_s.dat \
- qc_table.dat \
- rq_table.dat \
- sf_table.dat \
- bit.h \
- fixed.h \
- frame.h \
- global.h \
- huffman.h \
- layer12.h \
- layer3.h \
- stream.h \
- synth.h \
- timer.h \
- version.h
diff --git a/src/libmad/bit.c b/src/libmad/bit.c
deleted file mode 100644
index 8d9571e8f..000000000
--- a/src/libmad/bit.c
+++ /dev/null
@@ -1,237 +0,0 @@
-/*
- * libmad - MPEG audio decoder library
- * Copyright (C) 2000-2004 Underbit Technologies, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: bit.c,v 1.3 2004/04/22 00:22:35 miguelfreitas Exp $
- */
-
-# ifdef HAVE_CONFIG_H
-# include "config.h"
-# endif
-
-# include "global.h"
-
-# ifdef HAVE_LIMITS_H
-# include <limits.h>
-# else
-# define CHAR_BIT 8
-# endif
-
-# include "bit.h"
-
-/*
- * This is the lookup table for computing the CRC-check word.
- * As described in section 2.4.3.1 and depicted in Figure A.9
- * of ISO/IEC 11172-3, the generator polynomial is:
- *
- * G(X) = X^16 + X^15 + X^2 + 1
- */
-static
-unsigned short const crc_table[256] = {
- 0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
- 0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022,
- 0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072,
- 0x0050, 0x8055, 0x805f, 0x005a, 0x804b, 0x004e, 0x0044, 0x8041,
- 0x80c3, 0x00c6, 0x00cc, 0x80c9, 0x00d8, 0x80dd, 0x80d7, 0x00d2,
- 0x00f0, 0x80f5, 0x80ff, 0x00fa, 0x80eb, 0x00ee, 0x00e4, 0x80e1,
- 0x00a0, 0x80a5, 0x80af, 0x00aa, 0x80bb, 0x00be, 0x00b4, 0x80b1,
- 0x8093, 0x0096, 0x009c, 0x8099, 0x0088, 0x808d, 0x8087, 0x0082,
-
- 0x8183, 0x0186, 0x018c, 0x8189, 0x0198, 0x819d, 0x8197, 0x0192,
- 0x01b0, 0x81b5, 0x81bf, 0x01ba, 0x81ab, 0x01ae, 0x01a4, 0x81a1,
- 0x01e0, 0x81e5, 0x81ef, 0x01ea, 0x81fb, 0x01fe, 0x01f4, 0x81f1,
- 0x81d3, 0x01d6, 0x01dc, 0x81d9, 0x01c8, 0x81cd, 0x81c7, 0x01c2,
- 0x0140, 0x8145, 0x814f, 0x014a, 0x815b, 0x015e, 0x0154, 0x8151,
- 0x8173, 0x0176, 0x017c, 0x8179, 0x0168, 0x816d, 0x8167, 0x0162,
- 0x8123, 0x0126, 0x012c, 0x8129, 0x0138, 0x813d, 0x8137, 0x0132,
- 0x0110, 0x8115, 0x811f, 0x011a, 0x810b, 0x010e, 0x0104, 0x8101,
-
- 0x8303, 0x0306, 0x030c, 0x8309, 0x0318, 0x831d, 0x8317, 0x0312,
- 0x0330, 0x8335, 0x833f, 0x033a, 0x832b, 0x032e, 0x0324, 0x8321,
- 0x0360, 0x8365, 0x836f, 0x036a, 0x837b, 0x037e, 0x0374, 0x8371,
- 0x8353, 0x0356, 0x035c, 0x8359, 0x0348, 0x834d, 0x8347, 0x0342,
- 0x03c0, 0x83c5, 0x83cf, 0x03ca, 0x83db, 0x03de, 0x03d4, 0x83d1,
- 0x83f3, 0x03f6, 0x03fc, 0x83f9, 0x03e8, 0x83ed, 0x83e7, 0x03e2,
- 0x83a3, 0x03a6, 0x03ac, 0x83a9, 0x03b8, 0x83bd, 0x83b7, 0x03b2,
- 0x0390, 0x8395, 0x839f, 0x039a, 0x838b, 0x038e, 0x0384, 0x8381,
-
- 0x0280, 0x8285, 0x828f, 0x028a, 0x829b, 0x029e, 0x0294, 0x8291,
- 0x82b3, 0x02b6, 0x02bc, 0x82b9, 0x02a8, 0x82ad, 0x82a7, 0x02a2,
- 0x82e3, 0x02e6, 0x02ec, 0x82e9, 0x02f8, 0x82fd, 0x82f7, 0x02f2,
- 0x02d0, 0x82d5, 0x82df, 0x02da, 0x82cb, 0x02ce, 0x02c4, 0x82c1,
- 0x8243, 0x0246, 0x024c, 0x8249, 0x0258, 0x825d, 0x8257, 0x0252,
- 0x0270, 0x8275, 0x827f, 0x027a, 0x826b, 0x026e, 0x0264, 0x8261,
- 0x0220, 0x8225, 0x822f, 0x022a, 0x823b, 0x023e, 0x0234, 0x8231,
- 0x8213, 0x0216, 0x021c, 0x8219, 0x0208, 0x820d, 0x8207, 0x0202
-};
-
-# define CRC_POLY 0x8005
-
-/*
- * NAME: bit->init()
- * DESCRIPTION: initialize bit pointer struct
- */
-void mad_bit_init(struct mad_bitptr *bitptr, unsigned char const *byte)
-{
- bitptr->byte = byte;
- bitptr->cache = 0;
- bitptr->left = CHAR_BIT;
-}
-
-/*
- * NAME: bit->length()
- * DESCRIPTION: return number of bits between start and end points
- */
-unsigned int mad_bit_length(struct mad_bitptr const *begin,
- struct mad_bitptr const *end)
-{
- return begin->left +
- CHAR_BIT * (end->byte - (begin->byte + 1)) + (CHAR_BIT - end->left);
-}
-
-/*
- * NAME: bit->nextbyte()
- * DESCRIPTION: return pointer to next unprocessed byte
- */
-unsigned char const *mad_bit_nextbyte(struct mad_bitptr const *bitptr)
-{
- return bitptr->left == CHAR_BIT ? bitptr->byte : bitptr->byte + 1;
-}
-
-/*
- * NAME: bit->skip()
- * DESCRIPTION: advance bit pointer
- */
-void mad_bit_skip(struct mad_bitptr *bitptr, unsigned int len)
-{
- bitptr->byte += len / CHAR_BIT;
- bitptr->left -= len % CHAR_BIT;
-
- if (bitptr->left > CHAR_BIT) {
- bitptr->byte++;
- bitptr->left += CHAR_BIT;
- }
-
- if (bitptr->left < CHAR_BIT)
- bitptr->cache = *bitptr->byte;
-}
-
-/*
- * NAME: bit->read()
- * DESCRIPTION: read an arbitrary number of bits and return their UIMSBF value
- */
-unsigned long mad_bit_read(struct mad_bitptr *bitptr, unsigned int len)
-{
- register unsigned long value;
-
- if (bitptr->left == CHAR_BIT)
- bitptr->cache = *bitptr->byte;
-
- if (len < bitptr->left) {
- value = (bitptr->cache & ((1 << bitptr->left) - 1)) >>
- (bitptr->left - len);
- bitptr->left -= len;
-
- return value;
- }
-
- /* remaining bits in current byte */
-
- value = bitptr->cache & ((1 << bitptr->left) - 1);
- len -= bitptr->left;
-
- bitptr->byte++;
- bitptr->left = CHAR_BIT;
-
- /* more bytes */
-
- while (len >= CHAR_BIT) {
- value = (value << CHAR_BIT) | *bitptr->byte++;
- len -= CHAR_BIT;
- }
-
- if (len > 0) {
- bitptr->cache = *bitptr->byte;
-
- value = (value << len) | (bitptr->cache >> (CHAR_BIT - len));
- bitptr->left -= len;
- }
-
- return value;
-}
-
-# if 0
-/*
- * NAME: bit->write()
- * DESCRIPTION: write an arbitrary number of bits
- */
-void mad_bit_write(struct mad_bitptr *bitptr, unsigned int len,
- unsigned long value)
-{
- unsigned char *ptr;
-
- ptr = (unsigned char *) bitptr->byte;
-
- /* ... */
-}
-# endif
-
-/*
- * NAME: bit->crc()
- * DESCRIPTION: compute CRC-check word
- */
-unsigned short mad_bit_crc(struct mad_bitptr bitptr, unsigned int len,
- unsigned short init)
-{
- register unsigned int crc;
-
- for (crc = init; len >= 32; len -= 32) {
- register unsigned long data;
-
- data = mad_bit_read(&bitptr, 32);
-
- crc = (crc << 8) ^ crc_table[((crc >> 8) ^ (data >> 24)) & 0xff];
- crc = (crc << 8) ^ crc_table[((crc >> 8) ^ (data >> 16)) & 0xff];
- crc = (crc << 8) ^ crc_table[((crc >> 8) ^ (data >> 8)) & 0xff];
- crc = (crc << 8) ^ crc_table[((crc >> 8) ^ (data >> 0)) & 0xff];
- }
-
- switch (len / 8) {
- case 3: crc = (crc << 8) ^
- crc_table[((crc >> 8) ^ mad_bit_read(&bitptr, 8)) & 0xff];
- case 2: crc = (crc << 8) ^
- crc_table[((crc >> 8) ^ mad_bit_read(&bitptr, 8)) & 0xff];
- case 1: crc = (crc << 8) ^
- crc_table[((crc >> 8) ^ mad_bit_read(&bitptr, 8)) & 0xff];
-
- len %= 8;
-
- case 0: break;
- }
-
- while (len--) {
- register unsigned int msb;
-
- msb = mad_bit_read(&bitptr, 1) ^ (crc >> 15);
-
- crc <<= 1;
- if (msb & 1)
- crc ^= CRC_POLY;
- }
-
- return crc & 0xffff;
-}
diff --git a/src/libmad/bit.h b/src/libmad/bit.h
deleted file mode 100644
index 6c09d5493..000000000
--- a/src/libmad/bit.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * libmad - MPEG audio decoder library
- * Copyright (C) 2000-2004 Underbit Technologies, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: bit.h,v 1.3 2004/04/22 00:22:36 miguelfreitas Exp $
- */
-
-# ifndef LIBMAD_BIT_H
-# define LIBMAD_BIT_H
-
-struct mad_bitptr {
- unsigned char const *byte;
- unsigned short cache;
- unsigned short left;
-};
-
-void mad_bit_init(struct mad_bitptr *, unsigned char const *);
-
-# define mad_bit_finish(bitptr) /* nothing */
-
-unsigned int mad_bit_length(struct mad_bitptr const *,
- struct mad_bitptr const *);
-
-# define mad_bit_bitsleft(bitptr) ((bitptr)->left)
-unsigned char const *mad_bit_nextbyte(struct mad_bitptr const *);
-
-void mad_bit_skip(struct mad_bitptr *, unsigned int);
-unsigned long mad_bit_read(struct mad_bitptr *, unsigned int);
-void mad_bit_write(struct mad_bitptr *, unsigned int, unsigned long);
-
-unsigned short mad_bit_crc(struct mad_bitptr, unsigned int, unsigned short);
-
-# endif
diff --git a/src/libmad/fixed.c b/src/libmad/fixed.c
deleted file mode 100644
index ae02360ca..000000000
--- a/src/libmad/fixed.c
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * libmad - MPEG audio decoder library
- * Copyright (C) 2000-2004 Underbit Technologies, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: fixed.c,v 1.3 2004/04/22 00:22:36 miguelfreitas Exp $
- */
-
-# ifdef HAVE_CONFIG_H
-# include "config.h"
-# endif
-
-# include "global.h"
-
-# include "fixed.h"
-
-/*
- * NAME: fixed->abs()
- * DESCRIPTION: return absolute value of a fixed-point number
- */
-mad_fixed_t mad_f_abs(mad_fixed_t x)
-{
- return x < 0 ? -x : x;
-}
-
-/*
- * NAME: fixed->div()
- * DESCRIPTION: perform division using fixed-point math
- */
-mad_fixed_t mad_f_div(mad_fixed_t x, mad_fixed_t y)
-{
- mad_fixed_t q, r;
- unsigned int bits;
-
- q = mad_f_abs(x / y);
-
- if (x < 0) {
- x = -x;
- y = -y;
- }
-
- r = x % y;
-
- if (y < 0) {
- x = -x;
- y = -y;
- }
-
- if (q > mad_f_intpart(MAD_F_MAX) &&
- !(q == -mad_f_intpart(MAD_F_MIN) && r == 0 && (x < 0) != (y < 0)))
- return 0;
-
- for (bits = MAD_F_FRACBITS; bits && r; --bits) {
- q <<= 1, r <<= 1;
- if (r >= y)
- r -= y, ++q;
- }
-
- /* round */
- if (2 * r >= y)
- ++q;
-
- /* fix sign */
- if ((x < 0) != (y < 0))
- q = -q;
-
- return q << bits;
-}
diff --git a/src/libmad/fixed.h b/src/libmad/fixed.h
deleted file mode 100644
index 658b3399e..000000000
--- a/src/libmad/fixed.h
+++ /dev/null
@@ -1,499 +0,0 @@
-/*
- * libmad - MPEG audio decoder library
- * Copyright (C) 2000-2004 Underbit Technologies, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: fixed.h,v 1.3 2004/04/28 19:57:40 mroi Exp $
- */
-
-# ifndef LIBMAD_FIXED_H
-# define LIBMAD_FIXED_H
-
-# if SIZEOF_INT >= 4
-typedef signed int mad_fixed_t;
-
-typedef signed int mad_fixed64hi_t;
-typedef unsigned int mad_fixed64lo_t;
-# else
-typedef signed long mad_fixed_t;
-
-typedef signed long mad_fixed64hi_t;
-typedef unsigned long mad_fixed64lo_t;
-# endif
-
-# if defined(_MSC_VER)
-# define mad_fixed64_t signed __int64
-# elif 1 || defined(__GNUC__)
-# define mad_fixed64_t signed long long
-# endif
-
-# if defined(FPM_FLOAT)
-typedef double mad_sample_t;
-# else
-typedef mad_fixed_t mad_sample_t;
-# endif
-
-/*
- * Fixed-point format: 0xABBBBBBB
- * A == whole part (sign + 3 bits)
- * B == fractional part (28 bits)
- *
- * Values are signed two's complement, so the effective range is:
- * 0x80000000 to 0x7fffffff
- * -8.0 to +7.9999999962747097015380859375
- *
- * The smallest representable value is:
- * 0x00000001 == 0.0000000037252902984619140625 (i.e. about 3.725e-9)
- *
- * 28 bits of fractional accuracy represent about
- * 8.6 digits of decimal accuracy.
- *
- * Fixed-point numbers can be added or subtracted as normal
- * integers, but multiplication requires shifting the 64-bit result
- * from 56 fractional bits back to 28 (and rounding.)
- *
- * Changing the definition of MAD_F_FRACBITS is only partially
- * supported, and must be done with care.
- */
-
-# define MAD_F_FRACBITS 28
-
-# if MAD_F_FRACBITS == 28
-# define MAD_F(x) ((mad_fixed_t) (x##L))
-# else
-# if MAD_F_FRACBITS < 28
-# warning "MAD_F_FRACBITS < 28"
-# define MAD_F(x) ((mad_fixed_t) \
- (((x##L) + \
- (1L << (28 - MAD_F_FRACBITS - 1))) >> \
- (28 - MAD_F_FRACBITS)))
-# elif MAD_F_FRACBITS > 28
-# error "MAD_F_FRACBITS > 28 not currently supported"
-# define MAD_F(x) ((mad_fixed_t) \
- ((x##L) << (MAD_F_FRACBITS - 28)))
-# endif
-# endif
-
-# define MAD_F_MIN ((mad_fixed_t) -0x80000000L)
-# define MAD_F_MAX ((mad_fixed_t) +0x7fffffffL)
-
-# define MAD_F_ONE MAD_F(0x10000000)
-
-# define mad_f_tofixed(x) ((mad_fixed_t) \
- ((x) * (double) (1L << MAD_F_FRACBITS) + 0.5))
-# define mad_f_todouble(x) ((double) \
- ((x) / (double) (1L << MAD_F_FRACBITS)))
-
-# define mad_f_intpart(x) ((x) >> MAD_F_FRACBITS)
-# define mad_f_fracpart(x) ((x) & ((1L << MAD_F_FRACBITS) - 1))
- /* (x should be positive) */
-
-# define mad_f_fromint(x) ((x) << MAD_F_FRACBITS)
-
-# define mad_f_add(x, y) ((x) + (y))
-# define mad_f_sub(x, y) ((x) - (y))
-
-# if defined(FPM_FLOAT)
-# error "FPM_FLOAT not yet supported"
-
-# undef MAD_F
-# define MAD_F(x) mad_f_todouble(x)
-
-# define mad_f_mul(x, y) ((x) * (y))
-# define mad_f_scale64
-
-# undef ASO_ZEROCHECK
-
-# elif defined(FPM_64BIT)
-
-/*
- * This version should be the most accurate if 64-bit types are supported by
- * the compiler, although it may not be the most efficient.
- */
-# if defined(OPT_ACCURACY)
-# define mad_f_mul(x, y) \
- ((mad_fixed_t) \
- ((((mad_fixed64_t) (x) * (y)) + \
- (1L << (MAD_F_SCALEBITS - 1))) >> MAD_F_SCALEBITS))
-# else
-# define mad_f_mul(x, y) \
- ((mad_fixed_t) (((mad_fixed64_t) (x) * (y)) >> MAD_F_SCALEBITS))
-# endif
-
-# define MAD_F_SCALEBITS MAD_F_FRACBITS
-
-/* --- Intel --------------------------------------------------------------- */
-
-# elif defined(FPM_INTEL)
-
-# if defined(_MSC_VER)
-# pragma warning(push)
-# pragma warning(disable: 4035) /* no return value */
-static __forceinline
-mad_fixed_t mad_f_mul_inline(mad_fixed_t x, mad_fixed_t y)
-{
- enum {
- fracbits = MAD_F_FRACBITS
- };
-
- __asm {
- mov eax, x
- imul y
- shrd eax, edx, fracbits
- }
-
- /* implicit return of eax */
-}
-# pragma warning(pop)
-
-# define mad_f_mul mad_f_mul_inline
-# define mad_f_scale64
-# else
-/*
- * This Intel version is fast and accurate; the disposition of the least
- * significant bit depends on OPT_ACCURACY via mad_f_scale64().
- */
-# define MAD_F_MLX(hi, lo, x, y) \
- asm ("imull %3" \
- : "=a" (lo), "=d" (hi) \
- : "%a" (x), "rm" (y) \
- : "cc")
-
-# if defined(OPT_ACCURACY)
-/*
- * This gives best accuracy but is not very fast.
- */
-# define MAD_F_MLA(hi, lo, x, y) \
- ({ mad_fixed64hi_t __hi; \
- mad_fixed64lo_t __lo; \
- MAD_F_MLX(__hi, __lo, (x), (y)); \
- asm ("addl %2,%0\n\t" \
- "adcl %3,%1" \
- : "=rm" (lo), "=rm" (hi) \
- : "r" (__lo), "r" (__hi), "0" (lo), "1" (hi) \
- : "cc"); \
- })
-# endif /* OPT_ACCURACY */
-
-# if defined(OPT_ACCURACY)
-/*
- * Surprisingly, this is faster than SHRD followed by ADC.
- */
-# define mad_f_scale64(hi, lo) \
- ({ mad_fixed64hi_t __hi_; \
- mad_fixed64lo_t __lo_; \
- mad_fixed_t __result; \
- asm ("addl %4,%2\n\t" \
- "adcl %5,%3" \
- : "=rm" (__lo_), "=rm" (__hi_) \
- : "0" (lo), "1" (hi), \
- "ir" (1L << (MAD_F_SCALEBITS - 1)), "ir" (0) \
- : "cc"); \
- asm ("shrdl %3,%2,%1" \
- : "=rm" (__result) \
- : "0" (__lo_), "r" (__hi_), "I" (MAD_F_SCALEBITS) \
- : "cc"); \
- __result; \
- })
-# elif defined(OPT_INTEL)
-/*
- * Alternate Intel scaling that may or may not perform better.
- */
-# define mad_f_scale64(hi, lo) \
- ({ mad_fixed_t __result; \
- asm ("shrl %3,%1\n\t" \
- "shll %4,%2\n\t" \
- "orl %2,%1" \
- : "=rm" (__result) \
- : "0" (lo), "r" (hi), \
- "I" (MAD_F_SCALEBITS), "I" (32 - MAD_F_SCALEBITS) \
- : "cc"); \
- __result; \
- })
-# else
-# define mad_f_scale64(hi, lo) \
- ({ mad_fixed_t __result; \
- asm ("shrdl %3,%2,%1" \
- : "=rm" (__result) \
- : "0" (lo), "r" (hi), "I" (MAD_F_SCALEBITS) \
- : "cc"); \
- __result; \
- })
-# endif /* OPT_ACCURACY */
-
-# define MAD_F_SCALEBITS MAD_F_FRACBITS
-# endif
-
-/* --- ARM ----------------------------------------------------------------- */
-
-# elif defined(FPM_ARM)
-
-/*
- * This ARM V4 version is as accurate as FPM_64BIT but much faster. The
- * least significant bit is properly rounded at no CPU cycle cost!
- */
-# if 1
-/*
- * This is faster than the default implementation via MAD_F_MLX() and
- * mad_f_scale64().
- */
-# define mad_f_mul(x, y) \
- ({ mad_fixed64hi_t __hi; \
- mad_fixed64lo_t __lo; \
- mad_fixed_t __result; \
- asm ("smull %0, %1, %3, %4\n\t" \
- "movs %0, %0, lsr %5\n\t" \
- "adc %2, %0, %1, lsl %6" \
- : "=&r" (__lo), "=&r" (__hi), "=r" (__result) \
- : "%r" (x), "r" (y), \
- "M" (MAD_F_SCALEBITS), "M" (32 - MAD_F_SCALEBITS) \
- : "cc"); \
- __result; \
- })
-# endif
-
-# define MAD_F_MLX(hi, lo, x, y) \
- asm ("smull %0, %1, %2, %3" \
- : "=&r" (lo), "=&r" (hi) \
- : "%r" (x), "r" (y))
-
-# define MAD_F_MLA(hi, lo, x, y) \
- asm ("smlal %0, %1, %2, %3" \
- : "+r" (lo), "+r" (hi) \
- : "%r" (x), "r" (y))
-
-# define MAD_F_MLN(hi, lo) \
- asm ("rsbs %0, %2, #0\n\t" \
- "rsc %1, %3, #0" \
- : "=r" (lo), "=r" (hi) \
- : "0" (lo), "1" (hi) \
- : "cc")
-
-# define mad_f_scale64(hi, lo) \
- ({ mad_fixed_t __result; \
- asm ("movs %0, %1, lsr %3\n\t" \
- "adc %0, %0, %2, lsl %4" \
- : "=&r" (__result) \
- : "r" (lo), "r" (hi), \
- "M" (MAD_F_SCALEBITS), "M" (32 - MAD_F_SCALEBITS) \
- : "cc"); \
- __result; \
- })
-
-# define MAD_F_SCALEBITS MAD_F_FRACBITS
-
-/* --- MIPS ---------------------------------------------------------------- */
-
-# elif defined(FPM_MIPS)
-
-/*
- * This MIPS version is fast and accurate; the disposition of the least
- * significant bit depends on OPT_ACCURACY via mad_f_scale64().
- */
-# define MAD_F_MLX(hi, lo, x, y) \
- asm ("mult %2,%3" \
- : "=l" (lo), "=h" (hi) \
- : "%r" (x), "r" (y))
-
-# if defined(HAVE_MADD_ASM)
-# define MAD_F_MLA(hi, lo, x, y) \
- asm ("madd %2,%3" \
- : "+l" (lo), "+h" (hi) \
- : "%r" (x), "r" (y))
-# elif defined(HAVE_MADD16_ASM)
-/*
- * This loses significant accuracy due to the 16-bit integer limit in the
- * multiply/accumulate instruction.
- */
-# define MAD_F_ML0(hi, lo, x, y) \
- asm ("mult %2,%3" \
- : "=l" (lo), "=h" (hi) \
- : "%r" ((x) >> 12), "r" ((y) >> 16))
-# define MAD_F_MLA(hi, lo, x, y) \
- asm ("madd16 %2,%3" \
- : "+l" (lo), "+h" (hi) \
- : "%r" ((x) >> 12), "r" ((y) >> 16))
-# define MAD_F_MLZ(hi, lo) ((mad_fixed_t) (lo))
-# endif
-
-# if defined(OPT_SPEED)
-# define mad_f_scale64(hi, lo) \
- ((mad_fixed_t) ((hi) << (32 - MAD_F_SCALEBITS)))
-# define MAD_F_SCALEBITS MAD_F_FRACBITS
-# endif
-
-/* --- SPARC --------------------------------------------------------------- */
-
-# elif defined(FPM_SPARC)
-
-/*
- * This SPARC V8 version is fast and accurate; the disposition of the least
- * significant bit depends on OPT_ACCURACY via mad_f_scale64().
- */
-# define MAD_F_MLX(hi, lo, x, y) \
- asm ("smul %2, %3, %0\n\t" \
- "rd %%y, %1" \
- : "=r" (lo), "=r" (hi) \
- : "%r" (x), "rI" (y))
-
-/* --- PowerPC ------------------------------------------------------------- */
-
-# elif defined(FPM_PPC)
-
-/*
- * This PowerPC version is fast and accurate; the disposition of the least
- * significant bit depends on OPT_ACCURACY via mad_f_scale64().
- */
-# define MAD_F_MLX(hi, lo, x, y) \
- do { \
- asm ("mullw %0,%1,%2" \
- : "=r" (lo) \
- : "%r" (x), "r" (y)); \
- asm ("mulhw %0,%1,%2" \
- : "=r" (hi) \
- : "%r" (x), "r" (y)); \
- } \
- while (0)
-
-# if defined(OPT_ACCURACY)
-/*
- * This gives best accuracy but is not very fast.
- */
-# define MAD_F_MLA(hi, lo, x, y) \
- ({ mad_fixed64hi_t __hi; \
- mad_fixed64lo_t __lo; \
- MAD_F_MLX(__hi, __lo, (x), (y)); \
- asm ("addc %0,%2,%3\n\t" \
- "adde %1,%4,%5" \
- : "=r" (lo), "=r" (hi) \
- : "%r" (lo), "r" (__lo), \
- "%r" (hi), "r" (__hi) \
- : "xer"); \
- })
-# endif
-
-# if defined(OPT_ACCURACY)
-/*
- * This is slower than the truncating version below it.
- */
-# define mad_f_scale64(hi, lo) \
- ({ mad_fixed_t __result, __round; \
- asm ("rotrwi %0,%1,%2" \
- : "=r" (__result) \
- : "r" (lo), "i" (MAD_F_SCALEBITS)); \
- asm ("extrwi %0,%1,1,0" \
- : "=r" (__round) \
- : "r" (__result)); \
- asm ("insrwi %0,%1,%2,0" \
- : "+r" (__result) \
- : "r" (hi), "i" (MAD_F_SCALEBITS)); \
- asm ("add %0,%1,%2" \
- : "=r" (__result) \
- : "%r" (__result), "r" (__round)); \
- __result; \
- })
-# else
-# define mad_f_scale64(hi, lo) \
- ({ mad_fixed_t __result; \
- asm ("rotrwi %0,%1,%2" \
- : "=r" (__result) \
- : "r" (lo), "i" (MAD_F_SCALEBITS)); \
- asm ("insrwi %0,%1,%2,0" \
- : "+r" (__result) \
- : "r" (hi), "i" (MAD_F_SCALEBITS)); \
- __result; \
- })
-# endif
-
-# define MAD_F_SCALEBITS MAD_F_FRACBITS
-
-/* --- Default ------------------------------------------------------------- */
-
-# elif defined(FPM_DEFAULT)
-
-/*
- * This version is the most portable but it loses significant accuracy.
- * Furthermore, accuracy is biased against the second argument, so care
- * should be taken when ordering operands.
- *
- * The scale factors are constant as this is not used with SSO.
- *
- * Pre-rounding is required to stay within the limits of compliance.
- */
-# if defined(OPT_SPEED)
-# define mad_f_mul(x, y) (((x) >> 12) * ((y) >> 16))
-# else
-# define mad_f_mul(x, y) ((((x) + (1L << 11)) >> 12) * \
- (((y) + (1L << 15)) >> 16))
-# endif
-
-/* ------------------------------------------------------------------------- */
-
-# else
-# error "no FPM selected"
-# endif
-
-/* default implementations */
-
-# if !defined(mad_f_mul)
-# define mad_f_mul(x, y) \
- ({ register mad_fixed64hi_t __hi; \
- register mad_fixed64lo_t __lo; \
- MAD_F_MLX(__hi, __lo, (x), (y)); \
- mad_f_scale64(__hi, __lo); \
- })
-# endif
-
-# if !defined(MAD_F_MLA)
-# define MAD_F_ML0(hi, lo, x, y) ((lo) = mad_f_mul((x), (y)))
-# define MAD_F_MLA(hi, lo, x, y) ((lo) += mad_f_mul((x), (y)))
-# define MAD_F_MLN(hi, lo) ((lo) = -(lo))
-# define MAD_F_MLZ(hi, lo) ((void) (hi), (mad_fixed_t) (lo))
-# endif
-
-# if !defined(MAD_F_ML0)
-# define MAD_F_ML0(hi, lo, x, y) MAD_F_MLX((hi), (lo), (x), (y))
-# endif
-
-# if !defined(MAD_F_MLN)
-# define MAD_F_MLN(hi, lo) ((hi) = ((lo) = -(lo)) ? ~(hi) : -(hi))
-# endif
-
-# if !defined(MAD_F_MLZ)
-# define MAD_F_MLZ(hi, lo) mad_f_scale64((hi), (lo))
-# endif
-
-# if !defined(mad_f_scale64)
-# if defined(OPT_ACCURACY)
-# define mad_f_scale64(hi, lo) \
- ((((mad_fixed_t) \
- (((hi) << (32 - (MAD_F_SCALEBITS - 1))) | \
- ((lo) >> (MAD_F_SCALEBITS - 1)))) + 1) >> 1)
-# else
-# define mad_f_scale64(hi, lo) \
- ((mad_fixed_t) \
- (((hi) << (32 - MAD_F_SCALEBITS)) | \
- ((lo) >> MAD_F_SCALEBITS)))
-# endif
-# define MAD_F_SCALEBITS MAD_F_FRACBITS
-# endif
-
-/* C routines */
-
-mad_fixed_t mad_f_abs(mad_fixed_t);
-mad_fixed_t mad_f_div(mad_fixed_t, mad_fixed_t);
-
-# endif
diff --git a/src/libmad/frame.c b/src/libmad/frame.c
deleted file mode 100644
index 6fe1970c0..000000000
--- a/src/libmad/frame.c
+++ /dev/null
@@ -1,503 +0,0 @@
-/*
- * libmad - MPEG audio decoder library
- * Copyright (C) 2000-2004 Underbit Technologies, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: frame.c,v 1.3 2004/04/22 00:22:36 miguelfreitas Exp $
- */
-
-# ifdef HAVE_CONFIG_H
-# include "config.h"
-# endif
-
-# include "global.h"
-
-# include <stdlib.h>
-
-# include "bit.h"
-# include "stream.h"
-# include "frame.h"
-# include "timer.h"
-# include "layer12.h"
-# include "layer3.h"
-
-static
-unsigned long const bitrate_table[5][15] = {
- /* MPEG-1 */
- { 0, 32000, 64000, 96000, 128000, 160000, 192000, 224000, /* Layer I */
- 256000, 288000, 320000, 352000, 384000, 416000, 448000 },
- { 0, 32000, 48000, 56000, 64000, 80000, 96000, 112000, /* Layer II */
- 128000, 160000, 192000, 224000, 256000, 320000, 384000 },
- { 0, 32000, 40000, 48000, 56000, 64000, 80000, 96000, /* Layer III */
- 112000, 128000, 160000, 192000, 224000, 256000, 320000 },
-
- /* MPEG-2 LSF */
- { 0, 32000, 48000, 56000, 64000, 80000, 96000, 112000, /* Layer I */
- 128000, 144000, 160000, 176000, 192000, 224000, 256000 },
- { 0, 8000, 16000, 24000, 32000, 40000, 48000, 56000, /* Layers */
- 64000, 80000, 96000, 112000, 128000, 144000, 160000 } /* II & III */
-};
-
-static
-unsigned int const samplerate_table[3] = { 44100, 48000, 32000 };
-
-static
-int (*const decoder_table[3])(struct mad_stream *, struct mad_frame *) = {
- mad_layer_I,
- mad_layer_II,
- mad_layer_III
-};
-
-/*
- * NAME: header->init()
- * DESCRIPTION: initialize header struct
- */
-void mad_header_init(struct mad_header *header)
-{
- header->layer = 0;
- header->mode = 0;
- header->mode_extension = 0;
- header->emphasis = 0;
-
- header->bitrate = 0;
- header->samplerate = 0;
-
- header->crc_check = 0;
- header->crc_target = 0;
-
- header->flags = 0;
- header->private_bits = 0;
-
- header->duration = mad_timer_zero;
-}
-
-/*
- * NAME: frame->init()
- * DESCRIPTION: initialize frame struct
- */
-void mad_frame_init(struct mad_frame *frame)
-{
- mad_header_init(&frame->header);
-
- frame->options = 0;
-
- frame->overlap = 0;
- mad_frame_mute(frame);
-}
-
-/*
- * NAME: frame->finish()
- * DESCRIPTION: deallocate any dynamic memory associated with frame
- */
-void mad_frame_finish(struct mad_frame *frame)
-{
- mad_header_finish(&frame->header);
-
- if (frame->overlap) {
- free(frame->overlap);
- frame->overlap = 0;
- }
-}
-
-/*
- * NAME: decode_header()
- * DESCRIPTION: read header data and following CRC word
- */
-static
-int decode_header(struct mad_header *header, struct mad_stream *stream)
-{
- unsigned int index;
-
- header->flags = 0;
- header->private_bits = 0;
-
- /* header() */
-
- /* syncword */
- mad_bit_skip(&stream->ptr, 11);
-
- /* MPEG 2.5 indicator (really part of syncword) */
- if (mad_bit_read(&stream->ptr, 1) == 0)
- header->flags |= MAD_FLAG_MPEG_2_5_EXT;
-
- /* ID */
- if (mad_bit_read(&stream->ptr, 1) == 0)
- header->flags |= MAD_FLAG_LSF_EXT;
- else if (header->flags & MAD_FLAG_MPEG_2_5_EXT) {
- stream->error = MAD_ERROR_LOSTSYNC;
- return -1;
- }
-
- /* layer */
- header->layer = 4 - mad_bit_read(&stream->ptr, 2);
-
- if (header->layer == 4) {
- stream->error = MAD_ERROR_BADLAYER;
- return -1;
- }
-
- /* protection_bit */
- if (mad_bit_read(&stream->ptr, 1) == 0) {
- header->flags |= MAD_FLAG_PROTECTION;
- header->crc_check = mad_bit_crc(stream->ptr, 16, 0xffff);
- }
-
- /* bitrate_index */
- index = mad_bit_read(&stream->ptr, 4);
-
- if (index == 15) {
- stream->error = MAD_ERROR_BADBITRATE;
- return -1;
- }
-
- if (header->flags & MAD_FLAG_LSF_EXT)
- header->bitrate = bitrate_table[3 + (header->layer >> 1)][index];
- else
- header->bitrate = bitrate_table[header->layer - 1][index];
-
- /* sampling_frequency */
- index = mad_bit_read(&stream->ptr, 2);
-
- if (index == 3) {
- stream->error = MAD_ERROR_BADSAMPLERATE;
- return -1;
- }
-
- header->samplerate = samplerate_table[index];
-
- if (header->flags & MAD_FLAG_LSF_EXT) {
- header->samplerate /= 2;
-
- if (header->flags & MAD_FLAG_MPEG_2_5_EXT)
- header->samplerate /= 2;
- }
-
- /* padding_bit */
- if (mad_bit_read(&stream->ptr, 1))
- header->flags |= MAD_FLAG_PADDING;
-
- /* private_bit */
- if (mad_bit_read(&stream->ptr, 1))
- header->private_bits |= MAD_PRIVATE_HEADER;
-
- /* mode */
- header->mode = 3 - mad_bit_read(&stream->ptr, 2);
-
- /* mode_extension */
- header->mode_extension = mad_bit_read(&stream->ptr, 2);
-
- /* copyright */
- if (mad_bit_read(&stream->ptr, 1))
- header->flags |= MAD_FLAG_COPYRIGHT;
-
- /* original/copy */
- if (mad_bit_read(&stream->ptr, 1))
- header->flags |= MAD_FLAG_ORIGINAL;
-
- /* emphasis */
- header->emphasis = mad_bit_read(&stream->ptr, 2);
-
-# if defined(OPT_STRICT)
- /*
- * ISO/IEC 11172-3 says this is a reserved emphasis value, but
- * streams exist which use it anyway. Since the value is not important
- * to the decoder proper, we allow it unless OPT_STRICT is defined.
- */
- if (header->emphasis == MAD_EMPHASIS_RESERVED) {
- stream->error = MAD_ERROR_BADEMPHASIS;
- return -1;
- }
-# endif
-
- /* error_check() */
-
- /* crc_check */
- if (header->flags & MAD_FLAG_PROTECTION)
- header->crc_target = mad_bit_read(&stream->ptr, 16);
-
- return 0;
-}
-
-/*
- * NAME: free_bitrate()
- * DESCRIPTION: attempt to discover the bitstream's free bitrate
- */
-static
-int free_bitrate(struct mad_stream *stream, struct mad_header const *header)
-{
- struct mad_bitptr keep_ptr;
- unsigned long rate = 0;
- unsigned int pad_slot, slots_per_frame;
- unsigned char const *ptr = 0;
-
- keep_ptr = stream->ptr;
-
- pad_slot = (header->flags & MAD_FLAG_PADDING) ? 1 : 0;
- slots_per_frame = (header->layer == MAD_LAYER_III &&
- (header->flags & MAD_FLAG_LSF_EXT)) ? 72 : 144;
-
- while (mad_stream_sync(stream) == 0) {
- struct mad_stream peek_stream;
- struct mad_header peek_header;
-
- peek_stream = *stream;
- peek_header = *header;
-
- if (decode_header(&peek_header, &peek_stream) == 0 &&
- peek_header.layer == header->layer &&
- peek_header.samplerate == header->samplerate) {
- unsigned int N;
-
- ptr = mad_bit_nextbyte(&stream->ptr);
-
- N = ptr - stream->this_frame;
-
- if (header->layer == MAD_LAYER_I) {
- rate = (unsigned long) header->samplerate *
- (N - 4 * pad_slot + 4) / 48 / 1000;
- }
- else {
- rate = (unsigned long) header->samplerate *
- (N - pad_slot + 1) / slots_per_frame / 1000;
- }
-
- if (rate >= 8)
- break;
- }
-
- mad_bit_skip(&stream->ptr, 8);
- }
-
- stream->ptr = keep_ptr;
-
- if (rate < 8 || (header->layer == MAD_LAYER_III && rate > 640)) {
- stream->error = MAD_ERROR_LOSTSYNC;
- return -1;
- }
-
- stream->freerate = rate * 1000;
-
- return 0;
-}
-
-/*
- * NAME: header->decode()
- * DESCRIPTION: read the next frame header from the stream
- */
-int mad_header_decode(struct mad_header *header, struct mad_stream *stream)
-{
- register unsigned char const *ptr, *end;
- unsigned int pad_slot, N;
-
- ptr = stream->next_frame;
- end = stream->bufend;
-
- if (ptr == 0) {
- stream->error = MAD_ERROR_BUFPTR;
- goto fail;
- }
-
- /* stream skip */
- if (stream->skiplen) {
- if (!stream->sync)
- ptr = stream->this_frame;
-
- if (end - ptr < stream->skiplen) {
- stream->skiplen -= end - ptr;
- stream->next_frame = end;
-
- stream->error = MAD_ERROR_BUFLEN;
- goto fail;
- }
-
- ptr += stream->skiplen;
- stream->skiplen = 0;
-
- stream->sync = 1;
- }
-
- sync:
- /* synchronize */
- if (stream->sync) {
- if (end - ptr < MAD_BUFFER_GUARD) {
- stream->next_frame = ptr;
-
- stream->error = MAD_ERROR_BUFLEN;
- goto fail;
- }
- else if (!(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0)) {
- /* mark point where frame sync word was expected */
- stream->this_frame = ptr;
- stream->next_frame = ptr + 1;
-
- stream->error = MAD_ERROR_LOSTSYNC;
- goto fail;
- }
- }
- else {
- mad_bit_init(&stream->ptr, ptr);
-
- if (mad_stream_sync(stream) == -1) {
- if (end - stream->next_frame >= MAD_BUFFER_GUARD)
- stream->next_frame = end - MAD_BUFFER_GUARD;
-
- stream->error = MAD_ERROR_BUFLEN;
- goto fail;
- }
-
- ptr = mad_bit_nextbyte(&stream->ptr);
- }
-
- /* begin processing */
- stream->this_frame = ptr;
- stream->next_frame = ptr + 1; /* possibly bogus sync word */
-
- mad_bit_init(&stream->ptr, stream->this_frame);
-
- if (decode_header(header, stream) == -1)
- goto fail;
-
- /* calculate frame duration */
- mad_timer_set(&header->duration, 0,
- 32 * MAD_NSBSAMPLES(header), header->samplerate);
-
- /* calculate free bit rate */
- if (header->bitrate == 0) {
- if ((stream->freerate == 0 || !stream->sync ||
- (header->layer == MAD_LAYER_III && stream->freerate > 640000)) &&
- free_bitrate(stream, header) == -1)
- goto fail;
-
- header->bitrate = stream->freerate;
- header->flags |= MAD_FLAG_FREEFORMAT;
- }
-
- /* calculate beginning of next frame */
- pad_slot = (header->flags & MAD_FLAG_PADDING) ? 1 : 0;
-
- if (header->layer == MAD_LAYER_I)
- N = ((12 * header->bitrate / header->samplerate) + pad_slot) * 4;
- else {
- unsigned int slots_per_frame;
-
- slots_per_frame = (header->layer == MAD_LAYER_III &&
- (header->flags & MAD_FLAG_LSF_EXT)) ? 72 : 144;
-
- N = (slots_per_frame * header->bitrate / header->samplerate) + pad_slot;
- }
-
- /* verify there is enough data left in buffer to decode this frame */
- if (N + MAD_BUFFER_GUARD > end - stream->this_frame) {
- stream->next_frame = stream->this_frame;
-
- stream->error = MAD_ERROR_BUFLEN;
- goto fail;
- }
-
- stream->next_frame = stream->this_frame + N;
-
- if (!stream->sync) {
- /* check that a valid frame header follows this frame */
-
- ptr = stream->next_frame;
- if (!(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0)) {
- ptr = stream->next_frame = stream->this_frame + 1;
- goto sync;
- }
-
- stream->sync = 1;
- }
-
- header->flags |= MAD_FLAG_INCOMPLETE;
-
- return 0;
-
- fail:
- stream->sync = 0;
-
- return -1;
-}
-
-/*
- * NAME: frame->decode()
- * DESCRIPTION: decode a single frame from a bitstream
- */
-int mad_frame_decode(struct mad_frame *frame, struct mad_stream *stream)
-{
- frame->options = stream->options;
-
- /* header() */
- /* error_check() */
-
- if (!(frame->header.flags & MAD_FLAG_INCOMPLETE) &&
- mad_header_decode(&frame->header, stream) == -1)
- goto fail;
-
- /* audio_data() */
-
- frame->header.flags &= ~MAD_FLAG_INCOMPLETE;
-
- if (decoder_table[frame->header.layer - 1](stream, frame) == -1) {
- if (!MAD_RECOVERABLE(stream->error))
- stream->next_frame = stream->this_frame;
-
- goto fail;
- }
-
- /* ancillary_data() */
-
- if (frame->header.layer != MAD_LAYER_III) {
- struct mad_bitptr next_frame;
-
- mad_bit_init(&next_frame, stream->next_frame);
-
- stream->anc_ptr = stream->ptr;
- stream->anc_bitlen = mad_bit_length(&stream->ptr, &next_frame);
-
- mad_bit_finish(&next_frame);
- }
-
- return 0;
-
- fail:
- stream->anc_bitlen = 0;
- return -1;
-}
-
-/*
- * NAME: frame->mute()
- * DESCRIPTION: zero all subband values so the frame becomes silent
- */
-void mad_frame_mute(struct mad_frame *frame)
-{
- unsigned int s, sb;
-
- for (s = 0; s < 36; ++s) {
- for (sb = 0; sb < 32; ++sb) {
- frame->sbsample[0][s][sb] =
- frame->sbsample[1][s][sb] = 0;
- }
- }
-
- if (frame->overlap) {
- for (s = 0; s < 18; ++s) {
- for (sb = 0; sb < 32; ++sb) {
- (*frame->overlap)[0][sb][s] =
- (*frame->overlap)[1][sb][s] = 0;
- }
- }
- }
-}
diff --git a/src/libmad/frame.h b/src/libmad/frame.h
deleted file mode 100644
index 270420ab8..000000000
--- a/src/libmad/frame.h
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * libmad - MPEG audio decoder library
- * Copyright (C) 2000-2004 Underbit Technologies, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: frame.h,v 1.3 2004/04/22 00:22:36 miguelfreitas Exp $
- */
-
-# ifndef LIBMAD_FRAME_H
-# define LIBMAD_FRAME_H
-
-# include "fixed.h"
-# include "timer.h"
-# include "stream.h"
-
-enum mad_layer {
- MAD_LAYER_I = 1, /* Layer I */
- MAD_LAYER_II = 2, /* Layer II */
- MAD_LAYER_III = 3 /* Layer III */
-};
-
-enum mad_mode {
- MAD_MODE_SINGLE_CHANNEL = 0, /* single channel */
- MAD_MODE_DUAL_CHANNEL = 1, /* dual channel */
- MAD_MODE_JOINT_STEREO = 2, /* joint (MS/intensity) stereo */
- MAD_MODE_STEREO = 3 /* normal LR stereo */
-};
-
-enum mad_emphasis {
- MAD_EMPHASIS_NONE = 0, /* no emphasis */
- MAD_EMPHASIS_50_15_US = 1, /* 50/15 microseconds emphasis */
- MAD_EMPHASIS_CCITT_J_17 = 3, /* CCITT J.17 emphasis */
- MAD_EMPHASIS_RESERVED = 2 /* unknown emphasis */
-};
-
-struct mad_header {
- enum mad_layer layer; /* audio layer (1, 2, or 3) */
- enum mad_mode mode; /* channel mode (see above) */
- int mode_extension; /* additional mode info */
- enum mad_emphasis emphasis; /* de-emphasis to use (see above) */
-
- unsigned long bitrate; /* stream bitrate (bps) */
- unsigned int samplerate; /* sampling frequency (Hz) */
-
- unsigned short crc_check; /* frame CRC accumulator */
- unsigned short crc_target; /* final target CRC checksum */
-
- int flags; /* flags (see below) */
- int private_bits; /* private bits (see below) */
-
- mad_timer_t duration; /* audio playing time of frame */
-};
-
-struct mad_frame {
- struct mad_header header; /* MPEG audio header */
-
- int options; /* decoding options (from stream) */
-
- mad_fixed_t sbsample[2][36][32]; /* synthesis subband filter samples */
- mad_fixed_t (*overlap)[2][32][18]; /* Layer III block overlap data */
-};
-
-# define MAD_NCHANNELS(header) ((header)->mode ? 2 : 1)
-# define MAD_NSBSAMPLES(header) \
- ((header)->layer == MAD_LAYER_I ? 12 : \
- (((header)->layer == MAD_LAYER_III && \
- ((header)->flags & MAD_FLAG_LSF_EXT)) ? 18 : 36))
-
-enum {
- MAD_FLAG_NPRIVATE_III = 0x0007, /* number of Layer III private bits */
- MAD_FLAG_INCOMPLETE = 0x0008, /* header but not data is decoded */
-
- MAD_FLAG_PROTECTION = 0x0010, /* frame has CRC protection */
- MAD_FLAG_COPYRIGHT = 0x0020, /* frame is copyright */
- MAD_FLAG_ORIGINAL = 0x0040, /* frame is original (else copy) */
- MAD_FLAG_PADDING = 0x0080, /* frame has additional slot */
-
- MAD_FLAG_I_STEREO = 0x0100, /* uses intensity joint stereo */
- MAD_FLAG_MS_STEREO = 0x0200, /* uses middle/side joint stereo */
- MAD_FLAG_FREEFORMAT = 0x0400, /* uses free format bitrate */
-
- MAD_FLAG_LSF_EXT = 0x1000, /* lower sampling freq. extension */
- MAD_FLAG_MC_EXT = 0x2000, /* multichannel audio extension */
- MAD_FLAG_MPEG_2_5_EXT = 0x4000 /* MPEG 2.5 (unofficial) extension */
-};
-
-enum {
- MAD_PRIVATE_HEADER = 0x0100, /* header private bit */
- MAD_PRIVATE_III = 0x001f /* Layer III private bits (up to 5) */
-};
-
-void mad_header_init(struct mad_header *);
-
-# define mad_header_finish(header) /* nothing */
-
-int mad_header_decode(struct mad_header *, struct mad_stream *);
-
-void mad_frame_init(struct mad_frame *);
-void mad_frame_finish(struct mad_frame *);
-
-int mad_frame_decode(struct mad_frame *, struct mad_stream *);
-
-void mad_frame_mute(struct mad_frame *);
-
-# endif
diff --git a/src/libmad/global.h b/src/libmad/global.h
deleted file mode 100644
index 2f4b41db5..000000000
--- a/src/libmad/global.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * libmad - MPEG audio decoder library
- * Copyright (C) 2000-2004 Underbit Technologies, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: global.h,v 1.4 2004/04/22 00:22:36 miguelfreitas Exp $
- */
-
-# ifndef LIBMAD_GLOBAL_H
-# define LIBMAD_GLOBAL_H
-
-/* conditional debugging */
-
-# if defined(DEBUG) && defined(NDEBUG)
-# error "cannot define both DEBUG and NDEBUG"
-# endif
-
-# if defined(DEBUG)
-# include <stdio.h>
-# endif
-
-/* conditional features */
-
-# if defined(OPT_SPEED) && defined(OPT_ACCURACY)
-# error "cannot optimize for both speed and accuracy"
-# endif
-
-# if defined(OPT_SPEED) && !defined(OPT_SSO)
-# define OPT_SSO
-# endif
-
-# if defined(HAVE_UNISTD_H) && defined(HAVE_WAITPID) && \
- defined(HAVE_FCNTL) && defined(HAVE_PIPE) && defined(HAVE_FORK)
-# define USE_ASYNC
-# endif
-
-# if !defined(HAVE_ASSERT_H)
-# if defined(NDEBUG)
-# define assert(x) /* nothing */
-# else
-# define assert(x) do { if (!(x)) abort(); } while (0)
-# endif
-# endif
-
-# endif
diff --git a/src/libmad/huffman.c b/src/libmad/huffman.c
deleted file mode 100644
index 5d34c0142..000000000
--- a/src/libmad/huffman.c
+++ /dev/null
@@ -1,3109 +0,0 @@
-/*
- * libmad - MPEG audio decoder library
- * Copyright (C) 2000-2004 Underbit Technologies, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: huffman.c,v 1.4 2004/04/22 00:22:36 miguelfreitas Exp $
- */
-
-# ifdef HAVE_CONFIG_H
-# include "config.h"
-# endif
-
-# include "global.h"
-
-# include "huffman.h"
-
-/*
- * These are the Huffman code words for Layer III.
- * The data for these tables are derived from Table B.7 of ISO/IEC 11172-3.
- *
- * These tables support decoding up to 4 Huffman code bits at a time.
- */
-
-# if defined(__GNUC__) || \
- (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901)
-# define PTR(offs, bits) { .ptr = { 0, bits, offs } }
-# define V(v, w, x, y, hlen) { .value = { 1, hlen, v, w, x, y } }
-# else
-# define PTR(offs, bits) { { 0, bits, offs } }
-# if defined(WORDS_BIGENDIAN)
-# define V(v, w, x, y, hlen) { { 1, hlen, (v << 11) | (w << 10) | \
- (x << 9) | (y << 8) } }
-# else
-# define V(v, w, x, y, hlen) { { 1, hlen, (v << 0) | (w << 1) | \
- (x << 2) | (y << 3) } }
-# endif
-# endif
-
-static
-union huffquad const hufftabA[] = {
- /* 0000 */ PTR(16, 2),
- /* 0001 */ PTR(20, 2),
- /* 0010 */ PTR(24, 1),
- /* 0011 */ PTR(26, 1),
- /* 0100 */ V(0, 0, 1, 0, 4),
- /* 0101 */ V(0, 0, 0, 1, 4),
- /* 0110 */ V(0, 1, 0, 0, 4),
- /* 0111 */ V(1, 0, 0, 0, 4),
- /* 1000 */ V(0, 0, 0, 0, 1),
- /* 1001 */ V(0, 0, 0, 0, 1),
- /* 1010 */ V(0, 0, 0, 0, 1),
- /* 1011 */ V(0, 0, 0, 0, 1),
- /* 1100 */ V(0, 0, 0, 0, 1),
- /* 1101 */ V(0, 0, 0, 0, 1),
- /* 1110 */ V(0, 0, 0, 0, 1),
- /* 1111 */ V(0, 0, 0, 0, 1),
-
- /* 0000 ... */
- /* 00 */ V(1, 0, 1, 1, 2), /* 16 */
- /* 01 */ V(1, 1, 1, 1, 2),
- /* 10 */ V(1, 1, 0, 1, 2),
- /* 11 */ V(1, 1, 1, 0, 2),
-
- /* 0001 ... */
- /* 00 */ V(0, 1, 1, 1, 2), /* 20 */
- /* 01 */ V(0, 1, 0, 1, 2),
- /* 10 */ V(1, 0, 0, 1, 1),
- /* 11 */ V(1, 0, 0, 1, 1),
-
- /* 0010 ... */
- /* 0 */ V(0, 1, 1, 0, 1), /* 24 */
- /* 1 */ V(0, 0, 1, 1, 1),
-
- /* 0011 ... */
- /* 0 */ V(1, 0, 1, 0, 1), /* 26 */
- /* 1 */ V(1, 1, 0, 0, 1)
-};
-
-static
-union huffquad const hufftabB[] = {
- /* 0000 */ V(1, 1, 1, 1, 4),
- /* 0001 */ V(1, 1, 1, 0, 4),
- /* 0010 */ V(1, 1, 0, 1, 4),
- /* 0011 */ V(1, 1, 0, 0, 4),
- /* 0100 */ V(1, 0, 1, 1, 4),
- /* 0101 */ V(1, 0, 1, 0, 4),
- /* 0110 */ V(1, 0, 0, 1, 4),
- /* 0111 */ V(1, 0, 0, 0, 4),
- /* 1000 */ V(0, 1, 1, 1, 4),
- /* 1001 */ V(0, 1, 1, 0, 4),
- /* 1010 */ V(0, 1, 0, 1, 4),
- /* 1011 */ V(0, 1, 0, 0, 4),
- /* 1100 */ V(0, 0, 1, 1, 4),
- /* 1101 */ V(0, 0, 1, 0, 4),
- /* 1110 */ V(0, 0, 0, 1, 4),
- /* 1111 */ V(0, 0, 0, 0, 4)
-};
-
-# undef V
-# undef PTR
-
-# if defined(__GNUC__) || \
- (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901)
-# define PTR(offs, bits) { .ptr = { 0, bits, offs } }
-# define V(x, y, hlen) { .value = { 1, hlen, x, y } }
-# else
-# define PTR(offs, bits) { { 0, bits, offs } }
-# if defined(WORDS_BIGENDIAN)
-# define V(x, y, hlen) { { 1, hlen, (x << 8) | (y << 4) } }
-# else
-# define V(x, y, hlen) { { 1, hlen, (x << 0) | (y << 4) } }
-# endif
-# endif
-
-static
-union huffpair const hufftab0[] = {
- /* */ V(0, 0, 0)
-};
-
-static
-union huffpair const hufftab1[] = {
- /* 000 */ V(1, 1, 3),
- /* 001 */ V(0, 1, 3),
- /* 010 */ V(1, 0, 2),
- /* 011 */ V(1, 0, 2),
- /* 100 */ V(0, 0, 1),
- /* 101 */ V(0, 0, 1),
- /* 110 */ V(0, 0, 1),
- /* 111 */ V(0, 0, 1)
-};
-
-static
-union huffpair const hufftab2[] = {
- /* 000 */ PTR(8, 3),
- /* 001 */ V(1, 1, 3),
- /* 010 */ V(0, 1, 3),
- /* 011 */ V(1, 0, 3),
- /* 100 */ V(0, 0, 1),
- /* 101 */ V(0, 0, 1),
- /* 110 */ V(0, 0, 1),
- /* 111 */ V(0, 0, 1),
-
- /* 000 ... */
- /* 000 */ V(2, 2, 3), /* 8 */
- /* 001 */ V(0, 2, 3),
- /* 010 */ V(1, 2, 2),
- /* 011 */ V(1, 2, 2),
- /* 100 */ V(2, 1, 2),
- /* 101 */ V(2, 1, 2),
- /* 110 */ V(2, 0, 2),
- /* 111 */ V(2, 0, 2)
-};
-
-static
-union huffpair const hufftab3[] = {
- /* 000 */ PTR(8, 3),
- /* 001 */ V(1, 0, 3),
- /* 010 */ V(1, 1, 2),
- /* 011 */ V(1, 1, 2),
- /* 100 */ V(0, 1, 2),
- /* 101 */ V(0, 1, 2),
- /* 110 */ V(0, 0, 2),
- /* 111 */ V(0, 0, 2),
-
- /* 000 ... */
- /* 000 */ V(2, 2, 3), /* 8 */
- /* 001 */ V(0, 2, 3),
- /* 010 */ V(1, 2, 2),
- /* 011 */ V(1, 2, 2),
- /* 100 */ V(2, 1, 2),
- /* 101 */ V(2, 1, 2),
- /* 110 */ V(2, 0, 2),
- /* 111 */ V(2, 0, 2)
-};
-
-static
-union huffpair const hufftab5[] = {
- /* 000 */ PTR(8, 4),
- /* 001 */ V(1, 1, 3),
- /* 010 */ V(0, 1, 3),
- /* 011 */ V(1, 0, 3),
- /* 100 */ V(0, 0, 1),
- /* 101 */ V(0, 0, 1),
- /* 110 */ V(0, 0, 1),
- /* 111 */ V(0, 0, 1),
-
- /* 000 ... */
- /* 0000 */ PTR(24, 1), /* 8 */
- /* 0001 */ V(3, 2, 4),
- /* 0010 */ V(3, 1, 3),
- /* 0011 */ V(3, 1, 3),
- /* 0100 */ V(1, 3, 4),
- /* 0101 */ V(0, 3, 4),
- /* 0110 */ V(3, 0, 4),
- /* 0111 */ V(2, 2, 4),
- /* 1000 */ V(1, 2, 3),
- /* 1001 */ V(1, 2, 3),
- /* 1010 */ V(2, 1, 3),
- /* 1011 */ V(2, 1, 3),
- /* 1100 */ V(0, 2, 3),
- /* 1101 */ V(0, 2, 3),
- /* 1110 */ V(2, 0, 3),
- /* 1111 */ V(2, 0, 3),
-
- /* 000 0000 ... */
- /* 0 */ V(3, 3, 1), /* 24 */
- /* 1 */ V(2, 3, 1)
-};
-
-static
-union huffpair const hufftab6[] = {
- /* 0000 */ PTR(16, 3),
- /* 0001 */ PTR(24, 1),
- /* 0010 */ PTR(26, 1),
- /* 0011 */ V(1, 2, 4),
- /* 0100 */ V(2, 1, 4),
- /* 0101 */ V(2, 0, 4),
- /* 0110 */ V(0, 1, 3),
- /* 0111 */ V(0, 1, 3),
- /* 1000 */ V(1, 1, 2),
- /* 1001 */ V(1, 1, 2),
- /* 1010 */ V(1, 1, 2),
- /* 1011 */ V(1, 1, 2),
- /* 1100 */ V(1, 0, 3),
- /* 1101 */ V(1, 0, 3),
- /* 1110 */ V(0, 0, 3),
- /* 1111 */ V(0, 0, 3),
-
- /* 0000 ... */
- /* 000 */ V(3, 3, 3), /* 16 */
- /* 001 */ V(0, 3, 3),
- /* 010 */ V(2, 3, 2),
- /* 011 */ V(2, 3, 2),
- /* 100 */ V(3, 2, 2),
- /* 101 */ V(3, 2, 2),
- /* 110 */ V(3, 0, 2),
- /* 111 */ V(3, 0, 2),
-
- /* 0001 ... */
- /* 0 */ V(1, 3, 1), /* 24 */
- /* 1 */ V(3, 1, 1),
-
- /* 0010 ... */
- /* 0 */ V(2, 2, 1), /* 26 */
- /* 1 */ V(0, 2, 1)
-};
-
-static
-union huffpair const hufftab7[] = {
- /* 0000 */ PTR(16, 4),
- /* 0001 */ PTR(32, 4),
- /* 0010 */ PTR(48, 2),
- /* 0011 */ V(1, 1, 4),
- /* 0100 */ V(0, 1, 3),
- /* 0101 */ V(0, 1, 3),
- /* 0110 */ V(1, 0, 3),
- /* 0111 */ V(1, 0, 3),
- /* 1000 */ V(0, 0, 1),
- /* 1001 */ V(0, 0, 1),
- /* 1010 */ V(0, 0, 1),
- /* 1011 */ V(0, 0, 1),
- /* 1100 */ V(0, 0, 1),
- /* 1101 */ V(0, 0, 1),
- /* 1110 */ V(0, 0, 1),
- /* 1111 */ V(0, 0, 1),
-
- /* 0000 ... */
- /* 0000 */ PTR(52, 2), /* 16 */
- /* 0001 */ PTR(56, 1),
- /* 0010 */ PTR(58, 1),
- /* 0011 */ V(1, 5, 4),
- /* 0100 */ V(5, 1, 4),
- /* 0101 */ PTR(60, 1),
- /* 0110 */ V(5, 0, 4),
- /* 0111 */ PTR(62, 1),
- /* 1000 */ V(2, 4, 4),
- /* 1001 */ V(4, 2, 4),
- /* 1010 */ V(1, 4, 3),
- /* 1011 */ V(1, 4, 3),
- /* 1100 */ V(4, 1, 3),
- /* 1101 */ V(4, 1, 3),
- /* 1110 */ V(4, 0, 3),
- /* 1111 */ V(4, 0, 3),
-
- /* 0001 ... */
- /* 0000 */ V(0, 4, 4), /* 32 */
- /* 0001 */ V(2, 3, 4),
- /* 0010 */ V(3, 2, 4),
- /* 0011 */ V(0, 3, 4),
- /* 0100 */ V(1, 3, 3),
- /* 0101 */ V(1, 3, 3),
- /* 0110 */ V(3, 1, 3),
- /* 0111 */ V(3, 1, 3),
- /* 1000 */ V(3, 0, 3),
- /* 1001 */ V(3, 0, 3),
- /* 1010 */ V(2, 2, 3),
- /* 1011 */ V(2, 2, 3),
- /* 1100 */ V(1, 2, 2),
- /* 1101 */ V(1, 2, 2),
- /* 1110 */ V(1, 2, 2),
- /* 1111 */ V(1, 2, 2),
-
- /* 0010 ... */
- /* 00 */ V(2, 1, 1), /* 48 */
- /* 01 */ V(2, 1, 1),
- /* 10 */ V(0, 2, 2),
- /* 11 */ V(2, 0, 2),
-
- /* 0000 0000 ... */
- /* 00 */ V(5, 5, 2), /* 52 */
- /* 01 */ V(4, 5, 2),
- /* 10 */ V(5, 4, 2),
- /* 11 */ V(5, 3, 2),
-
- /* 0000 0001 ... */
- /* 0 */ V(3, 5, 1), /* 56 */
- /* 1 */ V(4, 4, 1),
-
- /* 0000 0010 ... */
- /* 0 */ V(2, 5, 1), /* 58 */
- /* 1 */ V(5, 2, 1),
-
- /* 0000 0101 ... */
- /* 0 */ V(0, 5, 1), /* 60 */
- /* 1 */ V(3, 4, 1),
-
- /* 0000 0111 ... */
- /* 0 */ V(4, 3, 1), /* 62 */
- /* 1 */ V(3, 3, 1)
-};
-
-# if 0
-/* this version saves 8 entries (16 bytes) at the expense of
- an extra lookup in 4 out of 36 cases */
-static
-union huffpair const hufftab8[] = {
- /* 0000 */ PTR(16, 4),
- /* 0001 */ PTR(32, 2),
- /* 0010 */ V(1, 2, 4),
- /* 0011 */ V(2, 1, 4),
- /* 0100 */ V(1, 1, 2),
- /* 0101 */ V(1, 1, 2),
- /* 0110 */ V(1, 1, 2),
- /* 0111 */ V(1, 1, 2),
- /* 1000 */ V(0, 1, 3),
- /* 1001 */ V(0, 1, 3),
- /* 1010 */ V(1, 0, 3),
- /* 1011 */ V(1, 0, 3),
- /* 1100 */ V(0, 0, 2),
- /* 1101 */ V(0, 0, 2),
- /* 1110 */ V(0, 0, 2),
- /* 1111 */ V(0, 0, 2),
-
- /* 0000 ... */
- /* 0000 */ PTR(36, 3), /* 16 */
- /* 0001 */ PTR(44, 2),
- /* 0010 */ PTR(48, 1),
- /* 0011 */ V(1, 5, 4),
- /* 0100 */ V(5, 1, 4),
- /* 0101 */ PTR(50, 1),
- /* 0110 */ PTR(52, 1),
- /* 0111 */ V(2, 4, 4),
- /* 1000 */ V(4, 2, 4),
- /* 1001 */ V(1, 4, 4),
- /* 1010 */ V(4, 1, 3),
- /* 1011 */ V(4, 1, 3),
- /* 1100 */ V(0, 4, 4),
- /* 1101 */ V(4, 0, 4),
- /* 1110 */ V(2, 3, 4),
- /* 1111 */ V(3, 2, 4),
-
- /* 0001 ... */
- /* 00 */ PTR(54, 2), /* 32 */
- /* 01 */ V(2, 2, 2),
- /* 10 */ V(0, 2, 2),
- /* 11 */ V(2, 0, 2),
-
- /* 0000 0000 ... */
- /* 000 */ V(5, 5, 3), /* 36 */
- /* 001 */ V(5, 4, 3),
- /* 010 */ V(4, 5, 2),
- /* 011 */ V(4, 5, 2),
- /* 100 */ V(5, 3, 1),
- /* 101 */ V(5, 3, 1),
- /* 110 */ V(5, 3, 1),
- /* 111 */ V(5, 3, 1),
-
- /* 0000 0001 ... */
- /* 00 */ V(3, 5, 2), /* 44 */
- /* 01 */ V(4, 4, 2),
- /* 10 */ V(2, 5, 1),
- /* 11 */ V(2, 5, 1),
-
- /* 0000 0010 ... */
- /* 0 */ V(5, 2, 1), /* 48 */
- /* 1 */ V(0, 5, 1),
-
- /* 0000 0101 ... */
- /* 0 */ V(3, 4, 1), /* 50 */
- /* 1 */ V(4, 3, 1),
-
- /* 0000 0110 ... */
- /* 0 */ V(5, 0, 1), /* 52 */
- /* 1 */ V(3, 3, 1),
-
- /* 0001 00 ... */
- /* 00 */ V(1, 3, 2), /* 54 */
- /* 01 */ V(3, 1, 2),
- /* 10 */ V(0, 3, 2),
- /* 11 */ V(3, 0, 2),
-};
-# else
-static
-union huffpair const hufftab8[] = {
- /* 0000 */ PTR(16, 4),
- /* 0001 */ PTR(32, 4),
- /* 0010 */ V(1, 2, 4),
- /* 0011 */ V(2, 1, 4),
- /* 0100 */ V(1, 1, 2),
- /* 0101 */ V(1, 1, 2),
- /* 0110 */ V(1, 1, 2),
- /* 0111 */ V(1, 1, 2),
- /* 1000 */ V(0, 1, 3),
- /* 1001 */ V(0, 1, 3),
- /* 1010 */ V(1, 0, 3),
- /* 1011 */ V(1, 0, 3),
- /* 1100 */ V(0, 0, 2),
- /* 1101 */ V(0, 0, 2),
- /* 1110 */ V(0, 0, 2),
- /* 1111 */ V(0, 0, 2),
-
- /* 0000 ... */
- /* 0000 */ PTR(48, 3), /* 16 */
- /* 0001 */ PTR(56, 2),
- /* 0010 */ PTR(60, 1),
- /* 0011 */ V(1, 5, 4),
- /* 0100 */ V(5, 1, 4),
- /* 0101 */ PTR(62, 1),
- /* 0110 */ PTR(64, 1),
- /* 0111 */ V(2, 4, 4),
- /* 1000 */ V(4, 2, 4),
- /* 1001 */ V(1, 4, 4),
- /* 1010 */ V(4, 1, 3),
- /* 1011 */ V(4, 1, 3),
- /* 1100 */ V(0, 4, 4),
- /* 1101 */ V(4, 0, 4),
- /* 1110 */ V(2, 3, 4),
- /* 1111 */ V(3, 2, 4),
-
- /* 0001 ... */
- /* 0000 */ V(1, 3, 4), /* 32 */
- /* 0001 */ V(3, 1, 4),
- /* 0010 */ V(0, 3, 4),
- /* 0011 */ V(3, 0, 4),
- /* 0100 */ V(2, 2, 2),
- /* 0101 */ V(2, 2, 2),
- /* 0110 */ V(2, 2, 2),
- /* 0111 */ V(2, 2, 2),
- /* 1000 */ V(0, 2, 2),
- /* 1001 */ V(0, 2, 2),
- /* 1010 */ V(0, 2, 2),
- /* 1011 */ V(0, 2, 2),
- /* 1100 */ V(2, 0, 2),
- /* 1101 */ V(2, 0, 2),
- /* 1110 */ V(2, 0, 2),
- /* 1111 */ V(2, 0, 2),
-
- /* 0000 0000 ... */
- /* 000 */ V(5, 5, 3), /* 48 */
- /* 001 */ V(5, 4, 3),
- /* 010 */ V(4, 5, 2),
- /* 011 */ V(4, 5, 2),
- /* 100 */ V(5, 3, 1),
- /* 101 */ V(5, 3, 1),
- /* 110 */ V(5, 3, 1),
- /* 111 */ V(5, 3, 1),
-
- /* 0000 0001 ... */
- /* 00 */ V(3, 5, 2), /* 56 */
- /* 01 */ V(4, 4, 2),
- /* 10 */ V(2, 5, 1),
- /* 11 */ V(2, 5, 1),
-
- /* 0000 0010 ... */
- /* 0 */ V(5, 2, 1), /* 60 */
- /* 1 */ V(0, 5, 1),
-
- /* 0000 0101 ... */
- /* 0 */ V(3, 4, 1), /* 62 */
- /* 1 */ V(4, 3, 1),
-
- /* 0000 0110 ... */
- /* 0 */ V(5, 0, 1), /* 64 */
- /* 1 */ V(3, 3, 1)
-};
-# endif
-
-static
-union huffpair const hufftab9[] = {
- /* 0000 */ PTR(16, 4),
- /* 0001 */ PTR(32, 3),
- /* 0010 */ PTR(40, 2),
- /* 0011 */ PTR(44, 2),
- /* 0100 */ PTR(48, 1),
- /* 0101 */ V(1, 2, 4),
- /* 0110 */ V(2, 1, 4),
- /* 0111 */ V(2, 0, 4),
- /* 1000 */ V(1, 1, 3),
- /* 1001 */ V(1, 1, 3),
- /* 1010 */ V(0, 1, 3),
- /* 1011 */ V(0, 1, 3),
- /* 1100 */ V(1, 0, 3),
- /* 1101 */ V(1, 0, 3),
- /* 1110 */ V(0, 0, 3),
- /* 1111 */ V(0, 0, 3),
-
- /* 0000 ... */
- /* 0000 */ PTR(50, 1), /* 16 */
- /* 0001 */ V(3, 5, 4),
- /* 0010 */ V(5, 3, 4),
- /* 0011 */ PTR(52, 1),
- /* 0100 */ V(4, 4, 4),
- /* 0101 */ V(2, 5, 4),
- /* 0110 */ V(5, 2, 4),
- /* 0111 */ V(1, 5, 4),
- /* 1000 */ V(5, 1, 3),
- /* 1001 */ V(5, 1, 3),
- /* 1010 */ V(3, 4, 3),
- /* 1011 */ V(3, 4, 3),
- /* 1100 */ V(4, 3, 3),
- /* 1101 */ V(4, 3, 3),
- /* 1110 */ V(5, 0, 4),
- /* 1111 */ V(0, 4, 4),
-
- /* 0001 ... */
- /* 000 */ V(2, 4, 3), /* 32 */
- /* 001 */ V(4, 2, 3),
- /* 010 */ V(3, 3, 3),
- /* 011 */ V(4, 0, 3),
- /* 100 */ V(1, 4, 2),
- /* 101 */ V(1, 4, 2),
- /* 110 */ V(4, 1, 2),
- /* 111 */ V(4, 1, 2),
-
- /* 0010 ... */
- /* 00 */ V(2, 3, 2), /* 40 */
- /* 01 */ V(3, 2, 2),
- /* 10 */ V(1, 3, 1),
- /* 11 */ V(1, 3, 1),
-
- /* 0011 ... */
- /* 00 */ V(3, 1, 1), /* 44 */
- /* 01 */ V(3, 1, 1),
- /* 10 */ V(0, 3, 2),
- /* 11 */ V(3, 0, 2),
-
- /* 0100 ... */
- /* 0 */ V(2, 2, 1), /* 48 */
- /* 1 */ V(0, 2, 1),
-
- /* 0000 0000 ... */
- /* 0 */ V(5, 5, 1), /* 50 */
- /* 1 */ V(4, 5, 1),
-
- /* 0000 0011 ... */
- /* 0 */ V(5, 4, 1), /* 52 */
- /* 1 */ V(0, 5, 1)
-};
-
-static
-union huffpair const hufftab10[] = {
- /* 0000 */ PTR(16, 4),
- /* 0001 */ PTR(32, 4),
- /* 0010 */ PTR(48, 2),
- /* 0011 */ V(1, 1, 4),
- /* 0100 */ V(0, 1, 3),
- /* 0101 */ V(0, 1, 3),
- /* 0110 */ V(1, 0, 3),
- /* 0111 */ V(1, 0, 3),
- /* 1000 */ V(0, 0, 1),
- /* 1001 */ V(0, 0, 1),
- /* 1010 */ V(0, 0, 1),
- /* 1011 */ V(0, 0, 1),
- /* 1100 */ V(0, 0, 1),
- /* 1101 */ V(0, 0, 1),
- /* 1110 */ V(0, 0, 1),
- /* 1111 */ V(0, 0, 1),
-
- /* 0000 ... */
- /* 0000 */ PTR(52, 3), /* 16 */
- /* 0001 */ PTR(60, 2),
- /* 0010 */ PTR(64, 3),
- /* 0011 */ PTR(72, 1),
- /* 0100 */ PTR(74, 2),
- /* 0101 */ PTR(78, 2),
- /* 0110 */ PTR(82, 2),
- /* 0111 */ V(1, 7, 4),
- /* 1000 */ V(7, 1, 4),
- /* 1001 */ PTR(86, 1),
- /* 1010 */ PTR(88, 2),
- /* 1011 */ PTR(92, 2),
- /* 1100 */ V(1, 6, 4),
- /* 1101 */ V(6, 1, 4),
- /* 1110 */ V(6, 0, 4),
- /* 1111 */ PTR(96, 1),
-
- /* 0001 ... */
- /* 0000 */ PTR(98, 1), /* 32 */
- /* 0001 */ PTR(100, 1),
- /* 0010 */ V(1, 4, 4),
- /* 0011 */ V(4, 1, 4),
- /* 0100 */ V(4, 0, 4),
- /* 0101 */ V(2, 3, 4),
- /* 0110 */ V(3, 2, 4),
- /* 0111 */ V(0, 3, 4),
- /* 1000 */ V(1, 3, 3),
- /* 1001 */ V(1, 3, 3),
- /* 1010 */ V(3, 1, 3),
- /* 1011 */ V(3, 1, 3),
- /* 1100 */ V(3, 0, 3),
- /* 1101 */ V(3, 0, 3),
- /* 1110 */ V(2, 2, 3),
- /* 1111 */ V(2, 2, 3),
-
- /* 0010 ... */
- /* 00 */ V(1, 2, 2), /* 48 */
- /* 01 */ V(2, 1, 2),
- /* 10 */ V(0, 2, 2),
- /* 11 */ V(2, 0, 2),
-
- /* 0000 0000 ... */
- /* 000 */ V(7, 7, 3), /* 52 */
- /* 001 */ V(6, 7, 3),
- /* 010 */ V(7, 6, 3),
- /* 011 */ V(5, 7, 3),
- /* 100 */ V(7, 5, 3),
- /* 101 */ V(6, 6, 3),
- /* 110 */ V(4, 7, 2),
- /* 111 */ V(4, 7, 2),
-
- /* 0000 0001 ... */
- /* 00 */ V(7, 4, 2), /* 60 */
- /* 01 */ V(5, 6, 2),
- /* 10 */ V(6, 5, 2),
- /* 11 */ V(3, 7, 2),
-
- /* 0000 0010 ... */
- /* 000 */ V(7, 3, 2), /* 64 */
- /* 001 */ V(7, 3, 2),
- /* 010 */ V(4, 6, 2),
- /* 011 */ V(4, 6, 2),
- /* 100 */ V(5, 5, 3),
- /* 101 */ V(5, 4, 3),
- /* 110 */ V(6, 3, 2),
- /* 111 */ V(6, 3, 2),
-
- /* 0000 0011 ... */
- /* 0 */ V(2, 7, 1), /* 72 */
- /* 1 */ V(7, 2, 1),
-
- /* 0000 0100 ... */
- /* 00 */ V(6, 4, 2), /* 74 */
- /* 01 */ V(0, 7, 2),
- /* 10 */ V(7, 0, 1),
- /* 11 */ V(7, 0, 1),
-
- /* 0000 0101 ... */
- /* 00 */ V(6, 2, 1), /* 78 */
- /* 01 */ V(6, 2, 1),
- /* 10 */ V(4, 5, 2),
- /* 11 */ V(3, 5, 2),
-
- /* 0000 0110 ... */
- /* 00 */ V(0, 6, 1), /* 82 */
- /* 01 */ V(0, 6, 1),
- /* 10 */ V(5, 3, 2),
- /* 11 */ V(4, 4, 2),
-
- /* 0000 1001 ... */
- /* 0 */ V(3, 6, 1), /* 86 */
- /* 1 */ V(2, 6, 1),
-
- /* 0000 1010 ... */
- /* 00 */ V(2, 5, 2), /* 88 */
- /* 01 */ V(5, 2, 2),
- /* 10 */ V(1, 5, 1),
- /* 11 */ V(1, 5, 1),
-
- /* 0000 1011 ... */
- /* 00 */ V(5, 1, 1), /* 92 */
- /* 01 */ V(5, 1, 1),
- /* 10 */ V(3, 4, 2),
- /* 11 */ V(4, 3, 2),
-
- /* 0000 1111 ... */
- /* 0 */ V(0, 5, 1), /* 96 */
- /* 1 */ V(5, 0, 1),
-
- /* 0001 0000 ... */
- /* 0 */ V(2, 4, 1), /* 98 */
- /* 1 */ V(4, 2, 1),
-
- /* 0001 0001 ... */
- /* 0 */ V(3, 3, 1), /* 100 */
- /* 1 */ V(0, 4, 1)
-};
-
-static
-union huffpair const hufftab11[] = {
- /* 0000 */ PTR(16, 4),
- /* 0001 */ PTR(32, 4),
- /* 0010 */ PTR(48, 4),
- /* 0011 */ PTR(64, 3),
- /* 0100 */ V(1, 2, 4),
- /* 0101 */ PTR(72, 1),
- /* 0110 */ V(1, 1, 3),
- /* 0111 */ V(1, 1, 3),
- /* 1000 */ V(0, 1, 3),
- /* 1001 */ V(0, 1, 3),
- /* 1010 */ V(1, 0, 3),
- /* 1011 */ V(1, 0, 3),
- /* 1100 */ V(0, 0, 2),
- /* 1101 */ V(0, 0, 2),
- /* 1110 */ V(0, 0, 2),
- /* 1111 */ V(0, 0, 2),
-
- /* 0000 ... */
- /* 0000 */ PTR(74, 2), /* 16 */
- /* 0001 */ PTR(78, 3),
- /* 0010 */ PTR(86, 2),
- /* 0011 */ PTR(90, 1),
- /* 0100 */ PTR(92, 2),
- /* 0101 */ V(2, 7, 4),
- /* 0110 */ V(7, 2, 4),
- /* 0111 */ PTR(96, 1),
- /* 1000 */ V(7, 1, 3),
- /* 1001 */ V(7, 1, 3),
- /* 1010 */ V(1, 7, 4),
- /* 1011 */ V(7, 0, 4),
- /* 1100 */ V(3, 6, 4),
- /* 1101 */ V(6, 3, 4),
- /* 1110 */ V(6, 0, 4),
- /* 1111 */ PTR(98, 1),
-
- /* 0001 ... */
- /* 0000 */ PTR(100, 1), /* 32 */
- /* 0001 */ V(1, 5, 4),
- /* 0010 */ V(6, 2, 3),
- /* 0011 */ V(6, 2, 3),
- /* 0100 */ V(2, 6, 4),
- /* 0101 */ V(0, 6, 4),
- /* 0110 */ V(1, 6, 3),
- /* 0111 */ V(1, 6, 3),
- /* 1000 */ V(6, 1, 3),
- /* 1001 */ V(6, 1, 3),
- /* 1010 */ V(5, 1, 4),
- /* 1011 */ V(3, 4, 4),
- /* 1100 */ V(5, 0, 4),
- /* 1101 */ PTR(102, 1),
- /* 1110 */ V(2, 4, 4),
- /* 1111 */ V(4, 2, 4),
-
- /* 0010 ... */
- /* 0000 */ V(1, 4, 4), /* 48 */
- /* 0001 */ V(4, 1, 4),
- /* 0010 */ V(0, 4, 4),
- /* 0011 */ V(4, 0, 4),
- /* 0100 */ V(2, 3, 3),
- /* 0101 */ V(2, 3, 3),
- /* 0110 */ V(3, 2, 3),
- /* 0111 */ V(3, 2, 3),
- /* 1000 */ V(1, 3, 2),
- /* 1001 */ V(1, 3, 2),
- /* 1010 */ V(1, 3, 2),
- /* 1011 */ V(1, 3, 2),
- /* 1100 */ V(3, 1, 2),
- /* 1101 */ V(3, 1, 2),
- /* 1110 */ V(3, 1, 2),
- /* 1111 */ V(3, 1, 2),
-
- /* 0011 ... */
- /* 000 */ V(0, 3, 3), /* 64 */
- /* 001 */ V(3, 0, 3),
- /* 010 */ V(2, 2, 2),
- /* 011 */ V(2, 2, 2),
- /* 100 */ V(2, 1, 1),
- /* 101 */ V(2, 1, 1),
- /* 110 */ V(2, 1, 1),
- /* 111 */ V(2, 1, 1),
-
- /* 0101 ... */
- /* 0 */ V(0, 2, 1), /* 72 */
- /* 1 */ V(2, 0, 1),
-
- /* 0000 0000 ... */
- /* 00 */ V(7, 7, 2), /* 74 */
- /* 01 */ V(6, 7, 2),
- /* 10 */ V(7, 6, 2),
- /* 11 */ V(7, 5, 2),
-
- /* 0000 0001 ... */
- /* 000 */ V(6, 6, 2), /* 78 */
- /* 001 */ V(6, 6, 2),
- /* 010 */ V(4, 7, 2),
- /* 011 */ V(4, 7, 2),
- /* 100 */ V(7, 4, 2),
- /* 101 */ V(7, 4, 2),
- /* 110 */ V(5, 7, 3),
- /* 111 */ V(5, 5, 3),
-
- /* 0000 0010 ... */
- /* 00 */ V(5, 6, 2), /* 86 */
- /* 01 */ V(6, 5, 2),
- /* 10 */ V(3, 7, 1),
- /* 11 */ V(3, 7, 1),
-
- /* 0000 0011 ... */
- /* 0 */ V(7, 3, 1), /* 90 */
- /* 1 */ V(4, 6, 1),
-
- /* 0000 0100 ... */
- /* 00 */ V(4, 5, 2), /* 92 */
- /* 01 */ V(5, 4, 2),
- /* 10 */ V(3, 5, 2),
- /* 11 */ V(5, 3, 2),
-
- /* 0000 0111 ... */
- /* 0 */ V(6, 4, 1), /* 96 */
- /* 1 */ V(0, 7, 1),
-
- /* 0000 1111 ... */
- /* 0 */ V(4, 4, 1), /* 98 */
- /* 1 */ V(2, 5, 1),
-
- /* 0001 0000 ... */
- /* 0 */ V(5, 2, 1), /* 100 */
- /* 1 */ V(0, 5, 1),
-
- /* 0001 1101 ... */
- /* 0 */ V(4, 3, 1), /* 102 */
- /* 1 */ V(3, 3, 1)
-};
-
-static
-union huffpair const hufftab12[] = {
- /* 0000 */ PTR(16, 4),
- /* 0001 */ PTR(32, 4),
- /* 0010 */ PTR(48, 4),
- /* 0011 */ PTR(64, 2),
- /* 0100 */ PTR(68, 3),
- /* 0101 */ PTR(76, 1),
- /* 0110 */ V(1, 2, 4),
- /* 0111 */ V(2, 1, 4),
- /* 1000 */ PTR(78, 1),
- /* 1001 */ V(0, 0, 4),
- /* 1010 */ V(1, 1, 3),
- /* 1011 */ V(1, 1, 3),
- /* 1100 */ V(0, 1, 3),
- /* 1101 */ V(0, 1, 3),
- /* 1110 */ V(1, 0, 3),
- /* 1111 */ V(1, 0, 3),
-
- /* 0000 ... */
- /* 0000 */ PTR(80, 2), /* 16 */
- /* 0001 */ PTR(84, 1),
- /* 0010 */ PTR(86, 1),
- /* 0011 */ PTR(88, 1),
- /* 0100 */ V(5, 6, 4),
- /* 0101 */ V(3, 7, 4),
- /* 0110 */ PTR(90, 1),
- /* 0111 */ V(2, 7, 4),
- /* 1000 */ V(7, 2, 4),
- /* 1001 */ V(4, 6, 4),
- /* 1010 */ V(6, 4, 4),
- /* 1011 */ V(1, 7, 4),
- /* 1100 */ V(7, 1, 4),
- /* 1101 */ PTR(92, 1),
- /* 1110 */ V(3, 6, 4),
- /* 1111 */ V(6, 3, 4),
-
- /* 0001 ... */
- /* 0000 */ V(4, 5, 4), /* 32 */
- /* 0001 */ V(5, 4, 4),
- /* 0010 */ V(4, 4, 4),
- /* 0011 */ PTR(94, 1),
- /* 0100 */ V(2, 6, 3),
- /* 0101 */ V(2, 6, 3),
- /* 0110 */ V(6, 2, 3),
- /* 0111 */ V(6, 2, 3),
- /* 1000 */ V(6, 1, 3),
- /* 1001 */ V(6, 1, 3),
- /* 1010 */ V(1, 6, 4),
- /* 1011 */ V(6, 0, 4),
- /* 1100 */ V(3, 5, 4),
- /* 1101 */ V(5, 3, 4),
- /* 1110 */ V(2, 5, 4),
- /* 1111 */ V(5, 2, 4),
-
- /* 0010 ... */
- /* 0000 */ V(1, 5, 3), /* 48 */
- /* 0001 */ V(1, 5, 3),
- /* 0010 */ V(5, 1, 3),
- /* 0011 */ V(5, 1, 3),
- /* 0100 */ V(3, 4, 3),
- /* 0101 */ V(3, 4, 3),
- /* 0110 */ V(4, 3, 3),
- /* 0111 */ V(4, 3, 3),
- /* 1000 */ V(5, 0, 4),
- /* 1001 */ V(0, 4, 4),
- /* 1010 */ V(2, 4, 3),
- /* 1011 */ V(2, 4, 3),
- /* 1100 */ V(4, 2, 3),
- /* 1101 */ V(4, 2, 3),
- /* 1110 */ V(1, 4, 3),
- /* 1111 */ V(1, 4, 3),
-
- /* 0011 ... */
- /* 00 */ V(3, 3, 2), /* 64 */
- /* 01 */ V(4, 1, 2),
- /* 10 */ V(2, 3, 2),
- /* 11 */ V(3, 2, 2),
-
- /* 0100 ... */
- /* 000 */ V(4, 0, 3), /* 68 */
- /* 001 */ V(0, 3, 3),
- /* 010 */ V(3, 0, 2),
- /* 011 */ V(3, 0, 2),
- /* 100 */ V(1, 3, 1),
- /* 101 */ V(1, 3, 1),
- /* 110 */ V(1, 3, 1),
- /* 111 */ V(1, 3, 1),
-
- /* 0101 ... */
- /* 0 */ V(3, 1, 1), /* 76 */
- /* 1 */ V(2, 2, 1),
-
- /* 1000 ... */
- /* 0 */ V(0, 2, 1), /* 78 */
- /* 1 */ V(2, 0, 1),
-
- /* 0000 0000 ... */
- /* 00 */ V(7, 7, 2), /* 80 */
- /* 01 */ V(6, 7, 2),
- /* 10 */ V(7, 6, 1),
- /* 11 */ V(7, 6, 1),
-
- /* 0000 0001 ... */
- /* 0 */ V(5, 7, 1), /* 84 */
- /* 1 */ V(7, 5, 1),
-
- /* 0000 0010 ... */
- /* 0 */ V(6, 6, 1), /* 86 */
- /* 1 */ V(4, 7, 1),
-
- /* 0000 0011 ... */
- /* 0 */ V(7, 4, 1), /* 88 */
- /* 1 */ V(6, 5, 1),
-
- /* 0000 0110 ... */
- /* 0 */ V(7, 3, 1), /* 90 */
- /* 1 */ V(5, 5, 1),
-
- /* 0000 1101 ... */
- /* 0 */ V(0, 7, 1), /* 92 */
- /* 1 */ V(7, 0, 1),
-
- /* 0001 0011 ... */
- /* 0 */ V(0, 6, 1), /* 94 */
- /* 1 */ V(0, 5, 1)
-};
-
-static
-union huffpair const hufftab13[] = {
- /* 0000 */ PTR(16, 4),
- /* 0001 */ PTR(32, 4),
- /* 0010 */ PTR(48, 4),
- /* 0011 */ PTR(64, 2),
- /* 0100 */ V(1, 1, 4),
- /* 0101 */ V(0, 1, 4),
- /* 0110 */ V(1, 0, 3),
- /* 0111 */ V(1, 0, 3),
- /* 1000 */ V(0, 0, 1),
- /* 1001 */ V(0, 0, 1),
- /* 1010 */ V(0, 0, 1),
- /* 1011 */ V(0, 0, 1),
- /* 1100 */ V(0, 0, 1),
- /* 1101 */ V(0, 0, 1),
- /* 1110 */ V(0, 0, 1),
- /* 1111 */ V(0, 0, 1),
-
- /* 0000 ... */
- /* 0000 */ PTR(68, 4), /* 16 */
- /* 0001 */ PTR(84, 4),
- /* 0010 */ PTR(100, 4),
- /* 0011 */ PTR(116, 4),
- /* 0100 */ PTR(132, 4),
- /* 0101 */ PTR(148, 4),
- /* 0110 */ PTR(164, 3),
- /* 0111 */ PTR(172, 3),
- /* 1000 */ PTR(180, 3),
- /* 1001 */ PTR(188, 3),
- /* 1010 */ PTR(196, 3),
- /* 1011 */ PTR(204, 3),
- /* 1100 */ PTR(212, 1),
- /* 1101 */ PTR(214, 2),
- /* 1110 */ PTR(218, 3),
- /* 1111 */ PTR(226, 1),
-
- /* 0001 ... */
- /* 0000 */ PTR(228, 2), /* 32 */
- /* 0001 */ PTR(232, 2),
- /* 0010 */ PTR(236, 2),
- /* 0011 */ PTR(240, 2),
- /* 0100 */ V(8, 1, 4),
- /* 0101 */ PTR(244, 1),
- /* 0110 */ PTR(246, 1),
- /* 0111 */ PTR(248, 1),
- /* 1000 */ PTR(250, 2),
- /* 1001 */ PTR(254, 1),
- /* 1010 */ V(1, 5, 4),
- /* 1011 */ V(5, 1, 4),
- /* 1100 */ PTR(256, 1),
- /* 1101 */ PTR(258, 1),
- /* 1110 */ PTR(260, 1),
- /* 1111 */ V(1, 4, 4),
-
- /* 0010 ... */
- /* 0000 */ V(4, 1, 3), /* 48 */
- /* 0001 */ V(4, 1, 3),
- /* 0010 */ V(0, 4, 4),
- /* 0011 */ V(4, 0, 4),
- /* 0100 */ V(2, 3, 4),
- /* 0101 */ V(3, 2, 4),
- /* 0110 */ V(1, 3, 3),
- /* 0111 */ V(1, 3, 3),
- /* 1000 */ V(3, 1, 3),
- /* 1001 */ V(3, 1, 3),
- /* 1010 */ V(0, 3, 3),
- /* 1011 */ V(0, 3, 3),
- /* 1100 */ V(3, 0, 3),
- /* 1101 */ V(3, 0, 3),
- /* 1110 */ V(2, 2, 3),
- /* 1111 */ V(2, 2, 3),
-
- /* 0011 ... */
- /* 00 */ V(1, 2, 2), /* 64 */
- /* 01 */ V(2, 1, 2),
- /* 10 */ V(0, 2, 2),
- /* 11 */ V(2, 0, 2),
-
- /* 0000 0000 ... */
- /* 0000 */ PTR(262, 4), /* 68 */
- /* 0001 */ PTR(278, 4),
- /* 0010 */ PTR(294, 4),
- /* 0011 */ PTR(310, 3),
- /* 0100 */ PTR(318, 2),
- /* 0101 */ PTR(322, 2),
- /* 0110 */ PTR(326, 3),
- /* 0111 */ PTR(334, 2),
- /* 1000 */ PTR(338, 1),
- /* 1001 */ PTR(340, 2),
- /* 1010 */ PTR(344, 2),
- /* 1011 */ PTR(348, 2),
- /* 1100 */ PTR(352, 2),
- /* 1101 */ PTR(356, 2),
- /* 1110 */ V(1, 15, 4),
- /* 1111 */ V(15, 1, 4),
-
- /* 0000 0001 ... */
- /* 0000 */ V(15, 0, 4), /* 84 */
- /* 0001 */ PTR(360, 1),
- /* 0010 */ PTR(362, 1),
- /* 0011 */ PTR(364, 1),
- /* 0100 */ V(14, 2, 4),
- /* 0101 */ PTR(366, 1),
- /* 0110 */ V(1, 14, 4),
- /* 0111 */ V(14, 1, 4),
- /* 1000 */ PTR(368, 1),
- /* 1001 */ PTR(370, 1),
- /* 1010 */ PTR(372, 1),
- /* 1011 */ PTR(374, 1),
- /* 1100 */ PTR(376, 1),
- /* 1101 */ PTR(378, 1),
- /* 1110 */ V(12, 6, 4),
- /* 1111 */ V(3, 13, 4),
-
- /* 0000 0010 ... */
- /* 0000 */ PTR(380, 1), /* 100 */
- /* 0001 */ V(2, 13, 4),
- /* 0010 */ V(13, 2, 4),
- /* 0011 */ V(1, 13, 4),
- /* 0100 */ V(11, 7, 4),
- /* 0101 */ PTR(382, 1),
- /* 0110 */ PTR(384, 1),
- /* 0111 */ V(12, 3, 4),
- /* 1000 */ PTR(386, 1),
- /* 1001 */ V(4, 11, 4),
- /* 1010 */ V(13, 1, 3),
- /* 1011 */ V(13, 1, 3),
- /* 1100 */ V(0, 13, 4),
- /* 1101 */ V(13, 0, 4),
- /* 1110 */ V(8, 10, 4),
- /* 1111 */ V(10, 8, 4),
-
- /* 0000 0011 ... */
- /* 0000 */ V(4, 12, 4), /* 116 */
- /* 0001 */ V(12, 4, 4),
- /* 0010 */ V(6, 11, 4),
- /* 0011 */ V(11, 6, 4),
- /* 0100 */ V(3, 12, 3),
- /* 0101 */ V(3, 12, 3),
- /* 0110 */ V(2, 12, 3),
- /* 0111 */ V(2, 12, 3),
- /* 1000 */ V(12, 2, 3),
- /* 1001 */ V(12, 2, 3),
- /* 1010 */ V(5, 11, 3),
- /* 1011 */ V(5, 11, 3),
- /* 1100 */ V(11, 5, 4),
- /* 1101 */ V(8, 9, 4),
- /* 1110 */ V(1, 12, 3),
- /* 1111 */ V(1, 12, 3),
-
- /* 0000 0100 ... */
- /* 0000 */ V(12, 1, 3), /* 132 */
- /* 0001 */ V(12, 1, 3),
- /* 0010 */ V(9, 8, 4),
- /* 0011 */ V(0, 12, 4),
- /* 0100 */ V(12, 0, 3),
- /* 0101 */ V(12, 0, 3),
- /* 0110 */ V(11, 4, 4),
- /* 0111 */ V(6, 10, 4),
- /* 1000 */ V(10, 6, 4),
- /* 1001 */ V(7, 9, 4),
- /* 1010 */ V(3, 11, 3),
- /* 1011 */ V(3, 11, 3),
- /* 1100 */ V(11, 3, 3),
- /* 1101 */ V(11, 3, 3),
- /* 1110 */ V(8, 8, 4),
- /* 1111 */ V(5, 10, 4),
-
- /* 0000 0101 ... */
- /* 0000 */ V(2, 11, 3), /* 148 */
- /* 0001 */ V(2, 11, 3),
- /* 0010 */ V(10, 5, 4),
- /* 0011 */ V(6, 9, 4),
- /* 0100 */ V(10, 4, 3),
- /* 0101 */ V(10, 4, 3),
- /* 0110 */ V(7, 8, 4),
- /* 0111 */ V(8, 7, 4),
- /* 1000 */ V(9, 4, 3),
- /* 1001 */ V(9, 4, 3),
- /* 1010 */ V(7, 7, 4),
- /* 1011 */ V(7, 6, 4),
- /* 1100 */ V(11, 2, 2),
- /* 1101 */ V(11, 2, 2),
- /* 1110 */ V(11, 2, 2),
- /* 1111 */ V(11, 2, 2),
-
- /* 0000 0110 ... */
- /* 000 */ V(1, 11, 2), /* 164 */
- /* 001 */ V(1, 11, 2),
- /* 010 */ V(11, 1, 2),
- /* 011 */ V(11, 1, 2),
- /* 100 */ V(0, 11, 3),
- /* 101 */ V(11, 0, 3),
- /* 110 */ V(9, 6, 3),
- /* 111 */ V(4, 10, 3),
-
- /* 0000 0111 ... */
- /* 000 */ V(3, 10, 3), /* 172 */
- /* 001 */ V(10, 3, 3),
- /* 010 */ V(5, 9, 3),
- /* 011 */ V(9, 5, 3),
- /* 100 */ V(2, 10, 2),
- /* 101 */ V(2, 10, 2),
- /* 110 */ V(10, 2, 2),
- /* 111 */ V(10, 2, 2),
-
- /* 0000 1000 ... */
- /* 000 */ V(1, 10, 2), /* 180 */
- /* 001 */ V(1, 10, 2),
- /* 010 */ V(10, 1, 2),
- /* 011 */ V(10, 1, 2),
- /* 100 */ V(0, 10, 3),
- /* 101 */ V(6, 8, 3),
- /* 110 */ V(10, 0, 2),
- /* 111 */ V(10, 0, 2),
-
- /* 0000 1001 ... */
- /* 000 */ V(8, 6, 3), /* 188 */
- /* 001 */ V(4, 9, 3),
- /* 010 */ V(9, 3, 2),
- /* 011 */ V(9, 3, 2),
- /* 100 */ V(3, 9, 3),
- /* 101 */ V(5, 8, 3),
- /* 110 */ V(8, 5, 3),
- /* 111 */ V(6, 7, 3),
-
- /* 0000 1010 ... */
- /* 000 */ V(2, 9, 2), /* 196 */
- /* 001 */ V(2, 9, 2),
- /* 010 */ V(9, 2, 2),
- /* 011 */ V(9, 2, 2),
- /* 100 */ V(5, 7, 3),
- /* 101 */ V(7, 5, 3),
- /* 110 */ V(3, 8, 2),
- /* 111 */ V(3, 8, 2),
-
- /* 0000 1011 ... */
- /* 000 */ V(8, 3, 2), /* 204 */
- /* 001 */ V(8, 3, 2),
- /* 010 */ V(6, 6, 3),
- /* 011 */ V(4, 7, 3),
- /* 100 */ V(7, 4, 3),
- /* 101 */ V(5, 6, 3),
- /* 110 */ V(6, 5, 3),
- /* 111 */ V(7, 3, 3),
-
- /* 0000 1100 ... */
- /* 0 */ V(1, 9, 1), /* 212 */
- /* 1 */ V(9, 1, 1),
-
- /* 0000 1101 ... */
- /* 00 */ V(0, 9, 2), /* 214 */
- /* 01 */ V(9, 0, 2),
- /* 10 */ V(4, 8, 2),
- /* 11 */ V(8, 4, 2),
-
- /* 0000 1110 ... */
- /* 000 */ V(7, 2, 2), /* 218 */
- /* 001 */ V(7, 2, 2),
- /* 010 */ V(4, 6, 3),
- /* 011 */ V(6, 4, 3),
- /* 100 */ V(2, 8, 1),
- /* 101 */ V(2, 8, 1),
- /* 110 */ V(2, 8, 1),
- /* 111 */ V(2, 8, 1),
-
- /* 0000 1111 ... */
- /* 0 */ V(8, 2, 1), /* 226 */
- /* 1 */ V(1, 8, 1),
-
- /* 0001 0000 ... */
- /* 00 */ V(3, 7, 2), /* 228 */
- /* 01 */ V(2, 7, 2),
- /* 10 */ V(1, 7, 1),
- /* 11 */ V(1, 7, 1),
-
- /* 0001 0001 ... */
- /* 00 */ V(7, 1, 1), /* 232 */
- /* 01 */ V(7, 1, 1),
- /* 10 */ V(5, 5, 2),
- /* 11 */ V(0, 7, 2),
-
- /* 0001 0010 ... */
- /* 00 */ V(7, 0, 2), /* 236 */
- /* 01 */ V(3, 6, 2),
- /* 10 */ V(6, 3, 2),
- /* 11 */ V(4, 5, 2),
-
- /* 0001 0011 ... */
- /* 00 */ V(5, 4, 2), /* 240 */
- /* 01 */ V(2, 6, 2),
- /* 10 */ V(6, 2, 2),
- /* 11 */ V(3, 5, 2),
-
- /* 0001 0101 ... */
- /* 0 */ V(0, 8, 1), /* 244 */
- /* 1 */ V(8, 0, 1),
-
- /* 0001 0110 ... */
- /* 0 */ V(1, 6, 1), /* 246 */
- /* 1 */ V(6, 1, 1),
-
- /* 0001 0111 ... */
- /* 0 */ V(0, 6, 1), /* 248 */
- /* 1 */ V(6, 0, 1),
-
- /* 0001 1000 ... */
- /* 00 */ V(5, 3, 2), /* 250 */
- /* 01 */ V(4, 4, 2),
- /* 10 */ V(2, 5, 1),
- /* 11 */ V(2, 5, 1),
-
- /* 0001 1001 ... */
- /* 0 */ V(5, 2, 1), /* 254 */
- /* 1 */ V(0, 5, 1),
-
- /* 0001 1100 ... */
- /* 0 */ V(3, 4, 1), /* 256 */
- /* 1 */ V(4, 3, 1),
-
- /* 0001 1101 ... */
- /* 0 */ V(5, 0, 1), /* 258 */
- /* 1 */ V(2, 4, 1),
-
- /* 0001 1110 ... */
- /* 0 */ V(4, 2, 1), /* 260 */
- /* 1 */ V(3, 3, 1),
-
- /* 0000 0000 0000 ... */
- /* 0000 */ PTR(388, 3), /* 262 */
- /* 0001 */ V(15, 15, 4),
- /* 0010 */ V(14, 15, 4),
- /* 0011 */ V(13, 15, 4),
- /* 0100 */ V(14, 14, 4),
- /* 0101 */ V(12, 15, 4),
- /* 0110 */ V(13, 14, 4),
- /* 0111 */ V(11, 15, 4),
- /* 1000 */ V(15, 11, 4),
- /* 1001 */ V(12, 14, 4),
- /* 1010 */ V(13, 12, 4),
- /* 1011 */ PTR(396, 1),
- /* 1100 */ V(14, 12, 3),
- /* 1101 */ V(14, 12, 3),
- /* 1110 */ V(13, 13, 3),
- /* 1111 */ V(13, 13, 3),
-
- /* 0000 0000 0001 ... */
- /* 0000 */ V(15, 10, 4), /* 278 */
- /* 0001 */ V(12, 13, 4),
- /* 0010 */ V(11, 14, 3),
- /* 0011 */ V(11, 14, 3),
- /* 0100 */ V(14, 11, 3),
- /* 0101 */ V(14, 11, 3),
- /* 0110 */ V(9, 15, 3),
- /* 0111 */ V(9, 15, 3),
- /* 1000 */ V(15, 9, 3),
- /* 1001 */ V(15, 9, 3),
- /* 1010 */ V(14, 10, 3),
- /* 1011 */ V(14, 10, 3),
- /* 1100 */ V(11, 13, 3),
- /* 1101 */ V(11, 13, 3),
- /* 1110 */ V(13, 11, 3),
- /* 1111 */ V(13, 11, 3),
-
- /* 0000 0000 0010 ... */
- /* 0000 */ V(8, 15, 3), /* 294 */
- /* 0001 */ V(8, 15, 3),
- /* 0010 */ V(15, 8, 3),
- /* 0011 */ V(15, 8, 3),
- /* 0100 */ V(12, 12, 3),
- /* 0101 */ V(12, 12, 3),
- /* 0110 */ V(10, 14, 4),
- /* 0111 */ V(9, 14, 4),
- /* 1000 */ V(8, 14, 3),
- /* 1001 */ V(8, 14, 3),
- /* 1010 */ V(7, 15, 4),
- /* 1011 */ V(7, 14, 4),
- /* 1100 */ V(15, 7, 2),
- /* 1101 */ V(15, 7, 2),
- /* 1110 */ V(15, 7, 2),
- /* 1111 */ V(15, 7, 2),
-
- /* 0000 0000 0011 ... */
- /* 000 */ V(13, 10, 2), /* 310 */
- /* 001 */ V(13, 10, 2),
- /* 010 */ V(10, 13, 3),
- /* 011 */ V(11, 12, 3),
- /* 100 */ V(12, 11, 3),
- /* 101 */ V(15, 6, 3),
- /* 110 */ V(6, 15, 2),
- /* 111 */ V(6, 15, 2),
-
- /* 0000 0000 0100 ... */
- /* 00 */ V(14, 8, 2), /* 318 */
- /* 01 */ V(5, 15, 2),
- /* 10 */ V(9, 13, 2),
- /* 11 */ V(13, 9, 2),
-
- /* 0000 0000 0101 ... */
- /* 00 */ V(15, 5, 2), /* 322 */
- /* 01 */ V(14, 7, 2),
- /* 10 */ V(10, 12, 2),
- /* 11 */ V(11, 11, 2),
-
- /* 0000 0000 0110 ... */
- /* 000 */ V(4, 15, 2), /* 326 */
- /* 001 */ V(4, 15, 2),
- /* 010 */ V(15, 4, 2),
- /* 011 */ V(15, 4, 2),
- /* 100 */ V(12, 10, 3),
- /* 101 */ V(14, 6, 3),
- /* 110 */ V(15, 3, 2),
- /* 111 */ V(15, 3, 2),
-
- /* 0000 0000 0111 ... */
- /* 00 */ V(3, 15, 1), /* 334 */
- /* 01 */ V(3, 15, 1),
- /* 10 */ V(8, 13, 2),
- /* 11 */ V(13, 8, 2),
-
- /* 0000 0000 1000 ... */
- /* 0 */ V(2, 15, 1), /* 338 */
- /* 1 */ V(15, 2, 1),
-
- /* 0000 0000 1001 ... */
- /* 00 */ V(6, 14, 2), /* 340 */
- /* 01 */ V(9, 12, 2),
- /* 10 */ V(0, 15, 1),
- /* 11 */ V(0, 15, 1),
-
- /* 0000 0000 1010 ... */
- /* 00 */ V(12, 9, 2), /* 344 */
- /* 01 */ V(5, 14, 2),
- /* 10 */ V(10, 11, 1),
- /* 11 */ V(10, 11, 1),
-
- /* 0000 0000 1011 ... */
- /* 00 */ V(7, 13, 2), /* 348 */
- /* 01 */ V(13, 7, 2),
- /* 10 */ V(4, 14, 1),
- /* 11 */ V(4, 14, 1),
-
- /* 0000 0000 1100 ... */
- /* 00 */ V(12, 8, 2), /* 352 */
- /* 01 */ V(13, 6, 2),
- /* 10 */ V(3, 14, 1),
- /* 11 */ V(3, 14, 1),
-
- /* 0000 0000 1101 ... */
- /* 00 */ V(11, 9, 1), /* 356 */
- /* 01 */ V(11, 9, 1),
- /* 10 */ V(9, 11, 2),
- /* 11 */ V(10, 10, 2),
-
- /* 0000 0001 0001 ... */
- /* 0 */ V(11, 10, 1), /* 360 */
- /* 1 */ V(14, 5, 1),
-
- /* 0000 0001 0010 ... */
- /* 0 */ V(14, 4, 1), /* 362 */
- /* 1 */ V(8, 12, 1),
-
- /* 0000 0001 0011 ... */
- /* 0 */ V(6, 13, 1), /* 364 */
- /* 1 */ V(14, 3, 1),
-
- /* 0000 0001 0101 ... */
- /* 0 */ V(2, 14, 1), /* 366 */
- /* 1 */ V(0, 14, 1),
-
- /* 0000 0001 1000 ... */
- /* 0 */ V(14, 0, 1), /* 368 */
- /* 1 */ V(5, 13, 1),
-
- /* 0000 0001 1001 ... */
- /* 0 */ V(13, 5, 1), /* 370 */
- /* 1 */ V(7, 12, 1),
-
- /* 0000 0001 1010 ... */
- /* 0 */ V(12, 7, 1), /* 372 */
- /* 1 */ V(4, 13, 1),
-
- /* 0000 0001 1011 ... */
- /* 0 */ V(8, 11, 1), /* 374 */
- /* 1 */ V(11, 8, 1),
-
- /* 0000 0001 1100 ... */
- /* 0 */ V(13, 4, 1), /* 376 */
- /* 1 */ V(9, 10, 1),
-
- /* 0000 0001 1101 ... */
- /* 0 */ V(10, 9, 1), /* 378 */
- /* 1 */ V(6, 12, 1),
-
- /* 0000 0010 0000 ... */
- /* 0 */ V(13, 3, 1), /* 380 */
- /* 1 */ V(7, 11, 1),
-
- /* 0000 0010 0101 ... */
- /* 0 */ V(5, 12, 1), /* 382 */
- /* 1 */ V(12, 5, 1),
-
- /* 0000 0010 0110 ... */
- /* 0 */ V(9, 9, 1), /* 384 */
- /* 1 */ V(7, 10, 1),
-
- /* 0000 0010 1000 ... */
- /* 0 */ V(10, 7, 1), /* 386 */
- /* 1 */ V(9, 7, 1),
-
- /* 0000 0000 0000 0000 ... */
- /* 000 */ V(15, 14, 3), /* 388 */
- /* 001 */ V(15, 12, 3),
- /* 010 */ V(15, 13, 2),
- /* 011 */ V(15, 13, 2),
- /* 100 */ V(14, 13, 1),
- /* 101 */ V(14, 13, 1),
- /* 110 */ V(14, 13, 1),
- /* 111 */ V(14, 13, 1),
-
- /* 0000 0000 0000 1011 ... */
- /* 0 */ V(10, 15, 1), /* 396 */
- /* 1 */ V(14, 9, 1)
-};
-
-static
-union huffpair const hufftab15[] = {
- /* 0000 */ PTR(16, 4),
- /* 0001 */ PTR(32, 4),
- /* 0010 */ PTR(48, 4),
- /* 0011 */ PTR(64, 4),
- /* 0100 */ PTR(80, 4),
- /* 0101 */ PTR(96, 3),
- /* 0110 */ PTR(104, 3),
- /* 0111 */ PTR(112, 2),
- /* 1000 */ PTR(116, 1),
- /* 1001 */ PTR(118, 1),
- /* 1010 */ V(1, 1, 3),
- /* 1011 */ V(1, 1, 3),
- /* 1100 */ V(0, 1, 4),
- /* 1101 */ V(1, 0, 4),
- /* 1110 */ V(0, 0, 3),
- /* 1111 */ V(0, 0, 3),
-
- /* 0000 ... */
- /* 0000 */ PTR(120, 4), /* 16 */
- /* 0001 */ PTR(136, 4),
- /* 0010 */ PTR(152, 4),
- /* 0011 */ PTR(168, 4),
- /* 0100 */ PTR(184, 4),
- /* 0101 */ PTR(200, 3),
- /* 0110 */ PTR(208, 3),
- /* 0111 */ PTR(216, 4),
- /* 1000 */ PTR(232, 3),
- /* 1001 */ PTR(240, 3),
- /* 1010 */ PTR(248, 3),
- /* 1011 */ PTR(256, 3),
- /* 1100 */ PTR(264, 2),
- /* 1101 */ PTR(268, 3),
- /* 1110 */ PTR(276, 3),
- /* 1111 */ PTR(284, 2),
-
- /* 0001 ... */
- /* 0000 */ PTR(288, 2), /* 32 */
- /* 0001 */ PTR(292, 2),
- /* 0010 */ PTR(296, 2),
- /* 0011 */ PTR(300, 2),
- /* 0100 */ PTR(304, 2),
- /* 0101 */ PTR(308, 2),
- /* 0110 */ PTR(312, 2),
- /* 0111 */ PTR(316, 2),
- /* 1000 */ PTR(320, 1),
- /* 1001 */ PTR(322, 1),
- /* 1010 */ PTR(324, 1),
- /* 1011 */ PTR(326, 2),
- /* 1100 */ PTR(330, 1),
- /* 1101 */ PTR(332, 1),
- /* 1110 */ PTR(334, 2),
- /* 1111 */ PTR(338, 1),
-
- /* 0010 ... */
- /* 0000 */ PTR(340, 1), /* 48 */
- /* 0001 */ PTR(342, 1),
- /* 0010 */ V(9, 1, 4),
- /* 0011 */ PTR(344, 1),
- /* 0100 */ PTR(346, 1),
- /* 0101 */ PTR(348, 1),
- /* 0110 */ PTR(350, 1),
- /* 0111 */ PTR(352, 1),
- /* 1000 */ V(2, 8, 4),
- /* 1001 */ V(8, 2, 4),
- /* 1010 */ V(1, 8, 4),
- /* 1011 */ V(8, 1, 4),
- /* 1100 */ PTR(354, 1),
- /* 1101 */ PTR(356, 1),
- /* 1110 */ PTR(358, 1),
- /* 1111 */ PTR(360, 1),
-
- /* 0011 ... */
- /* 0000 */ V(2, 7, 4), /* 64 */
- /* 0001 */ V(7, 2, 4),
- /* 0010 */ V(6, 4, 4),
- /* 0011 */ V(1, 7, 4),
- /* 0100 */ V(5, 5, 4),
- /* 0101 */ V(7, 1, 4),
- /* 0110 */ PTR(362, 1),
- /* 0111 */ V(3, 6, 4),
- /* 1000 */ V(6, 3, 4),
- /* 1001 */ V(4, 5, 4),
- /* 1010 */ V(5, 4, 4),
- /* 1011 */ V(2, 6, 4),
- /* 1100 */ V(6, 2, 4),
- /* 1101 */ V(1, 6, 4),
- /* 1110 */ PTR(364, 1),
- /* 1111 */ V(3, 5, 4),
-
- /* 0100 ... */
- /* 0000 */ V(6, 1, 3), /* 80 */
- /* 0001 */ V(6, 1, 3),
- /* 0010 */ V(5, 3, 4),
- /* 0011 */ V(4, 4, 4),
- /* 0100 */ V(2, 5, 3),
- /* 0101 */ V(2, 5, 3),
- /* 0110 */ V(5, 2, 3),
- /* 0111 */ V(5, 2, 3),
- /* 1000 */ V(1, 5, 3),
- /* 1001 */ V(1, 5, 3),
- /* 1010 */ V(5, 1, 3),
- /* 1011 */ V(5, 1, 3),
- /* 1100 */ V(0, 5, 4),
- /* 1101 */ V(5, 0, 4),
- /* 1110 */ V(3, 4, 3),
- /* 1111 */ V(3, 4, 3),
-
- /* 0101 ... */
- /* 000 */ V(4, 3, 3), /* 96 */
- /* 001 */ V(2, 4, 3),
- /* 010 */ V(4, 2, 3),
- /* 011 */ V(3, 3, 3),
- /* 100 */ V(4, 1, 2),
- /* 101 */ V(4, 1, 2),
- /* 110 */ V(1, 4, 3),
- /* 111 */ V(0, 4, 3),
-
- /* 0110 ... */
- /* 000 */ V(2, 3, 2), /* 104 */
- /* 001 */ V(2, 3, 2),
- /* 010 */ V(3, 2, 2),
- /* 011 */ V(3, 2, 2),
- /* 100 */ V(4, 0, 3),
- /* 101 */ V(0, 3, 3),
- /* 110 */ V(1, 3, 2),
- /* 111 */ V(1, 3, 2),
-
- /* 0111 ... */
- /* 00 */ V(3, 1, 2), /* 112 */
- /* 01 */ V(3, 0, 2),
- /* 10 */ V(2, 2, 1),
- /* 11 */ V(2, 2, 1),
-
- /* 1000 ... */
- /* 0 */ V(1, 2, 1), /* 116 */
- /* 1 */ V(2, 1, 1),
-
- /* 1001 ... */
- /* 0 */ V(0, 2, 1), /* 118 */
- /* 1 */ V(2, 0, 1),
-
- /* 0000 0000 ... */
- /* 0000 */ PTR(366, 1), /* 120 */
- /* 0001 */ PTR(368, 1),
- /* 0010 */ V(14, 14, 4),
- /* 0011 */ PTR(370, 1),
- /* 0100 */ PTR(372, 1),
- /* 0101 */ PTR(374, 1),
- /* 0110 */ V(15, 11, 4),
- /* 0111 */ PTR(376, 1),
- /* 1000 */ V(13, 13, 4),
- /* 1001 */ V(10, 15, 4),
- /* 1010 */ V(15, 10, 4),
- /* 1011 */ V(11, 14, 4),
- /* 1100 */ V(14, 11, 4),
- /* 1101 */ V(12, 13, 4),
- /* 1110 */ V(13, 12, 4),
- /* 1111 */ V(9, 15, 4),
-
- /* 0000 0001 ... */
- /* 0000 */ V(15, 9, 4), /* 136 */
- /* 0001 */ V(14, 10, 4),
- /* 0010 */ V(11, 13, 4),
- /* 0011 */ V(13, 11, 4),
- /* 0100 */ V(8, 15, 4),
- /* 0101 */ V(15, 8, 4),
- /* 0110 */ V(12, 12, 4),
- /* 0111 */ V(9, 14, 4),
- /* 1000 */ V(14, 9, 4),
- /* 1001 */ V(7, 15, 4),
- /* 1010 */ V(15, 7, 4),
- /* 1011 */ V(10, 13, 4),
- /* 1100 */ V(13, 10, 4),
- /* 1101 */ V(11, 12, 4),
- /* 1110 */ V(6, 15, 4),
- /* 1111 */ PTR(378, 1),
-
- /* 0000 0010 ... */
- /* 0000 */ V(12, 11, 3), /* 152 */
- /* 0001 */ V(12, 11, 3),
- /* 0010 */ V(15, 6, 3),
- /* 0011 */ V(15, 6, 3),
- /* 0100 */ V(8, 14, 4),
- /* 0101 */ V(14, 8, 4),
- /* 0110 */ V(5, 15, 4),
- /* 0111 */ V(9, 13, 4),
- /* 1000 */ V(15, 5, 3),
- /* 1001 */ V(15, 5, 3),
- /* 1010 */ V(7, 14, 3),
- /* 1011 */ V(7, 14, 3),
- /* 1100 */ V(14, 7, 3),
- /* 1101 */ V(14, 7, 3),
- /* 1110 */ V(10, 12, 3),
- /* 1111 */ V(10, 12, 3),
-
- /* 0000 0011 ... */
- /* 0000 */ V(12, 10, 3), /* 168 */
- /* 0001 */ V(12, 10, 3),
- /* 0010 */ V(11, 11, 3),
- /* 0011 */ V(11, 11, 3),
- /* 0100 */ V(13, 9, 4),
- /* 0101 */ V(8, 13, 4),
- /* 0110 */ V(4, 15, 3),
- /* 0111 */ V(4, 15, 3),
- /* 1000 */ V(15, 4, 3),
- /* 1001 */ V(15, 4, 3),
- /* 1010 */ V(3, 15, 3),
- /* 1011 */ V(3, 15, 3),
- /* 1100 */ V(15, 3, 3),
- /* 1101 */ V(15, 3, 3),
- /* 1110 */ V(13, 8, 3),
- /* 1111 */ V(13, 8, 3),
-
- /* 0000 0100 ... */
- /* 0000 */ V(14, 6, 3), /* 184 */
- /* 0001 */ V(14, 6, 3),
- /* 0010 */ V(2, 15, 3),
- /* 0011 */ V(2, 15, 3),
- /* 0100 */ V(15, 2, 3),
- /* 0101 */ V(15, 2, 3),
- /* 0110 */ V(6, 14, 4),
- /* 0111 */ V(15, 0, 4),
- /* 1000 */ V(1, 15, 3),
- /* 1001 */ V(1, 15, 3),
- /* 1010 */ V(15, 1, 3),
- /* 1011 */ V(15, 1, 3),
- /* 1100 */ V(9, 12, 3),
- /* 1101 */ V(9, 12, 3),
- /* 1110 */ V(12, 9, 3),
- /* 1111 */ V(12, 9, 3),
-
- /* 0000 0101 ... */
- /* 000 */ V(5, 14, 3), /* 200 */
- /* 001 */ V(10, 11, 3),
- /* 010 */ V(11, 10, 3),
- /* 011 */ V(14, 5, 3),
- /* 100 */ V(7, 13, 3),
- /* 101 */ V(13, 7, 3),
- /* 110 */ V(4, 14, 3),
- /* 111 */ V(14, 4, 3),
-
- /* 0000 0110 ... */
- /* 000 */ V(8, 12, 3), /* 208 */
- /* 001 */ V(12, 8, 3),
- /* 010 */ V(3, 14, 3),
- /* 011 */ V(6, 13, 3),
- /* 100 */ V(13, 6, 3),
- /* 101 */ V(14, 3, 3),
- /* 110 */ V(9, 11, 3),
- /* 111 */ V(11, 9, 3),
-
- /* 0000 0111 ... */
- /* 0000 */ V(2, 14, 3), /* 216 */
- /* 0001 */ V(2, 14, 3),
- /* 0010 */ V(10, 10, 3),
- /* 0011 */ V(10, 10, 3),
- /* 0100 */ V(14, 2, 3),
- /* 0101 */ V(14, 2, 3),
- /* 0110 */ V(1, 14, 3),
- /* 0111 */ V(1, 14, 3),
- /* 1000 */ V(14, 1, 3),
- /* 1001 */ V(14, 1, 3),
- /* 1010 */ V(0, 14, 4),
- /* 1011 */ V(14, 0, 4),
- /* 1100 */ V(5, 13, 3),
- /* 1101 */ V(5, 13, 3),
- /* 1110 */ V(13, 5, 3),
- /* 1111 */ V(13, 5, 3),
-
- /* 0000 1000 ... */
- /* 000 */ V(7, 12, 3), /* 232 */
- /* 001 */ V(12, 7, 3),
- /* 010 */ V(4, 13, 3),
- /* 011 */ V(8, 11, 3),
- /* 100 */ V(13, 4, 2),
- /* 101 */ V(13, 4, 2),
- /* 110 */ V(11, 8, 3),
- /* 111 */ V(9, 10, 3),
-
- /* 0000 1001 ... */
- /* 000 */ V(10, 9, 3), /* 240 */
- /* 001 */ V(6, 12, 3),
- /* 010 */ V(12, 6, 3),
- /* 011 */ V(3, 13, 3),
- /* 100 */ V(13, 3, 2),
- /* 101 */ V(13, 3, 2),
- /* 110 */ V(13, 2, 2),
- /* 111 */ V(13, 2, 2),
-
- /* 0000 1010 ... */
- /* 000 */ V(2, 13, 3), /* 248 */
- /* 001 */ V(0, 13, 3),
- /* 010 */ V(1, 13, 2),
- /* 011 */ V(1, 13, 2),
- /* 100 */ V(7, 11, 2),
- /* 101 */ V(7, 11, 2),
- /* 110 */ V(11, 7, 2),
- /* 111 */ V(11, 7, 2),
-
- /* 0000 1011 ... */
- /* 000 */ V(13, 1, 2), /* 256 */
- /* 001 */ V(13, 1, 2),
- /* 010 */ V(5, 12, 3),
- /* 011 */ V(13, 0, 3),
- /* 100 */ V(12, 5, 2),
- /* 101 */ V(12, 5, 2),
- /* 110 */ V(8, 10, 2),
- /* 111 */ V(8, 10, 2),
-
- /* 0000 1100 ... */
- /* 00 */ V(10, 8, 2), /* 264 */
- /* 01 */ V(4, 12, 2),
- /* 10 */ V(12, 4, 2),
- /* 11 */ V(6, 11, 2),
-
- /* 0000 1101 ... */
- /* 000 */ V(11, 6, 2), /* 268 */
- /* 001 */ V(11, 6, 2),
- /* 010 */ V(9, 9, 3),
- /* 011 */ V(0, 12, 3),
- /* 100 */ V(3, 12, 2),
- /* 101 */ V(3, 12, 2),
- /* 110 */ V(12, 3, 2),
- /* 111 */ V(12, 3, 2),
-
- /* 0000 1110 ... */
- /* 000 */ V(7, 10, 2), /* 276 */
- /* 001 */ V(7, 10, 2),
- /* 010 */ V(10, 7, 2),
- /* 011 */ V(10, 7, 2),
- /* 100 */ V(10, 6, 2),
- /* 101 */ V(10, 6, 2),
- /* 110 */ V(12, 0, 3),
- /* 111 */ V(0, 11, 3),
-
- /* 0000 1111 ... */
- /* 00 */ V(12, 2, 1), /* 284 */
- /* 01 */ V(12, 2, 1),
- /* 10 */ V(2, 12, 2),
- /* 11 */ V(5, 11, 2),
-
- /* 0001 0000 ... */
- /* 00 */ V(11, 5, 2), /* 288 */
- /* 01 */ V(1, 12, 2),
- /* 10 */ V(8, 9, 2),
- /* 11 */ V(9, 8, 2),
-
- /* 0001 0001 ... */
- /* 00 */ V(12, 1, 2), /* 292 */
- /* 01 */ V(4, 11, 2),
- /* 10 */ V(11, 4, 2),
- /* 11 */ V(6, 10, 2),
-
- /* 0001 0010 ... */
- /* 00 */ V(3, 11, 2), /* 296 */
- /* 01 */ V(7, 9, 2),
- /* 10 */ V(11, 3, 1),
- /* 11 */ V(11, 3, 1),
-
- /* 0001 0011 ... */
- /* 00 */ V(9, 7, 2), /* 300 */
- /* 01 */ V(8, 8, 2),
- /* 10 */ V(2, 11, 2),
- /* 11 */ V(5, 10, 2),
-
- /* 0001 0100 ... */
- /* 00 */ V(11, 2, 1), /* 304 */
- /* 01 */ V(11, 2, 1),
- /* 10 */ V(10, 5, 2),
- /* 11 */ V(1, 11, 2),
-
- /* 0001 0101 ... */
- /* 00 */ V(11, 1, 1), /* 308 */
- /* 01 */ V(11, 1, 1),
- /* 10 */ V(11, 0, 2),
- /* 11 */ V(6, 9, 2),
-
- /* 0001 0110 ... */
- /* 00 */ V(9, 6, 2), /* 312 */
- /* 01 */ V(4, 10, 2),
- /* 10 */ V(10, 4, 2),
- /* 11 */ V(7, 8, 2),
-
- /* 0001 0111 ... */
- /* 00 */ V(8, 7, 2), /* 316 */
- /* 01 */ V(3, 10, 2),
- /* 10 */ V(10, 3, 1),
- /* 11 */ V(10, 3, 1),
-
- /* 0001 1000 ... */
- /* 0 */ V(5, 9, 1), /* 320 */
- /* 1 */ V(9, 5, 1),
-
- /* 0001 1001 ... */
- /* 0 */ V(2, 10, 1), /* 322 */
- /* 1 */ V(10, 2, 1),
-
- /* 0001 1010 ... */
- /* 0 */ V(1, 10, 1), /* 324 */
- /* 1 */ V(10, 1, 1),
-
- /* 0001 1011 ... */
- /* 00 */ V(0, 10, 2), /* 326 */
- /* 01 */ V(10, 0, 2),
- /* 10 */ V(6, 8, 1),
- /* 11 */ V(6, 8, 1),
-
- /* 0001 1100 ... */
- /* 0 */ V(8, 6, 1), /* 330 */
- /* 1 */ V(4, 9, 1),
-
- /* 0001 1101 ... */
- /* 0 */ V(9, 4, 1), /* 332 */
- /* 1 */ V(3, 9, 1),
-
- /* 0001 1110 ... */
- /* 00 */ V(9, 3, 1), /* 334 */
- /* 01 */ V(9, 3, 1),
- /* 10 */ V(7, 7, 2),
- /* 11 */ V(0, 9, 2),
-
- /* 0001 1111 ... */
- /* 0 */ V(5, 8, 1), /* 338 */
- /* 1 */ V(8, 5, 1),
-
- /* 0010 0000 ... */
- /* 0 */ V(2, 9, 1), /* 340 */
- /* 1 */ V(6, 7, 1),
-
- /* 0010 0001 ... */
- /* 0 */ V(7, 6, 1), /* 342 */
- /* 1 */ V(9, 2, 1),
-
- /* 0010 0011 ... */
- /* 0 */ V(1, 9, 1), /* 344 */
- /* 1 */ V(9, 0, 1),
-
- /* 0010 0100 ... */
- /* 0 */ V(4, 8, 1), /* 346 */
- /* 1 */ V(8, 4, 1),
-
- /* 0010 0101 ... */
- /* 0 */ V(5, 7, 1), /* 348 */
- /* 1 */ V(7, 5, 1),
-
- /* 0010 0110 ... */
- /* 0 */ V(3, 8, 1), /* 350 */
- /* 1 */ V(8, 3, 1),
-
- /* 0010 0111 ... */
- /* 0 */ V(6, 6, 1), /* 352 */
- /* 1 */ V(4, 7, 1),
-
- /* 0010 1100 ... */
- /* 0 */ V(7, 4, 1), /* 354 */
- /* 1 */ V(0, 8, 1),
-
- /* 0010 1101 ... */
- /* 0 */ V(8, 0, 1), /* 356 */
- /* 1 */ V(5, 6, 1),
-
- /* 0010 1110 ... */
- /* 0 */ V(6, 5, 1), /* 358 */
- /* 1 */ V(3, 7, 1),
-
- /* 0010 1111 ... */
- /* 0 */ V(7, 3, 1), /* 360 */
- /* 1 */ V(4, 6, 1),
-
- /* 0011 0110 ... */
- /* 0 */ V(0, 7, 1), /* 362 */
- /* 1 */ V(7, 0, 1),
-
- /* 0011 1110 ... */
- /* 0 */ V(0, 6, 1), /* 364 */
- /* 1 */ V(6, 0, 1),
-
- /* 0000 0000 0000 ... */
- /* 0 */ V(15, 15, 1), /* 366 */
- /* 1 */ V(14, 15, 1),
-
- /* 0000 0000 0001 ... */
- /* 0 */ V(15, 14, 1), /* 368 */
- /* 1 */ V(13, 15, 1),
-
- /* 0000 0000 0011 ... */
- /* 0 */ V(15, 13, 1), /* 370 */
- /* 1 */ V(12, 15, 1),
-
- /* 0000 0000 0100 ... */
- /* 0 */ V(15, 12, 1), /* 372 */
- /* 1 */ V(13, 14, 1),
-
- /* 0000 0000 0101 ... */
- /* 0 */ V(14, 13, 1), /* 374 */
- /* 1 */ V(11, 15, 1),
-
- /* 0000 0000 0111 ... */
- /* 0 */ V(12, 14, 1), /* 376 */
- /* 1 */ V(14, 12, 1),
-
- /* 0000 0001 1111 ... */
- /* 0 */ V(10, 14, 1), /* 378 */
- /* 1 */ V(0, 15, 1)
-};
-
-static
-union huffpair const hufftab16[] = {
- /* 0000 */ PTR(16, 4),
- /* 0001 */ PTR(32, 4),
- /* 0010 */ PTR(48, 4),
- /* 0011 */ PTR(64, 2),
- /* 0100 */ V(1, 1, 4),
- /* 0101 */ V(0, 1, 4),
- /* 0110 */ V(1, 0, 3),
- /* 0111 */ V(1, 0, 3),
- /* 1000 */ V(0, 0, 1),
- /* 1001 */ V(0, 0, 1),
- /* 1010 */ V(0, 0, 1),
- /* 1011 */ V(0, 0, 1),
- /* 1100 */ V(0, 0, 1),
- /* 1101 */ V(0, 0, 1),
- /* 1110 */ V(0, 0, 1),
- /* 1111 */ V(0, 0, 1),
-
- /* 0000 ... */
- /* 0000 */ PTR(68, 3), /* 16 */
- /* 0001 */ PTR(76, 3),
- /* 0010 */ PTR(84, 2),
- /* 0011 */ V(15, 15, 4),
- /* 0100 */ PTR(88, 2),
- /* 0101 */ PTR(92, 1),
- /* 0110 */ PTR(94, 4),
- /* 0111 */ V(15, 2, 4),
- /* 1000 */ PTR(110, 1),
- /* 1001 */ V(1, 15, 4),
- /* 1010 */ V(15, 1, 4),
- /* 1011 */ PTR(112, 4),
- /* 1100 */ PTR(128, 4),
- /* 1101 */ PTR(144, 4),
- /* 1110 */ PTR(160, 4),
- /* 1111 */ PTR(176, 4),
-
- /* 0001 ... */
- /* 0000 */ PTR(192, 4), /* 32 */
- /* 0001 */ PTR(208, 3),
- /* 0010 */ PTR(216, 3),
- /* 0011 */ PTR(224, 3),
- /* 0100 */ PTR(232, 3),
- /* 0101 */ PTR(240, 3),
- /* 0110 */ PTR(248, 3),
- /* 0111 */ PTR(256, 3),
- /* 1000 */ PTR(264, 2),
- /* 1001 */ PTR(268, 2),
- /* 1010 */ PTR(272, 1),
- /* 1011 */ PTR(274, 2),
- /* 1100 */ PTR(278, 2),
- /* 1101 */ PTR(282, 1),
- /* 1110 */ V(5, 1, 4),
- /* 1111 */ PTR(284, 1),
-
- /* 0010 ... */
- /* 0000 */ PTR(286, 1), /* 48 */
- /* 0001 */ PTR(288, 1),
- /* 0010 */ PTR(290, 1),
- /* 0011 */ V(1, 4, 4),
- /* 0100 */ V(4, 1, 4),
- /* 0101 */ PTR(292, 1),
- /* 0110 */ V(2, 3, 4),
- /* 0111 */ V(3, 2, 4),
- /* 1000 */ V(1, 3, 3),
- /* 1001 */ V(1, 3, 3),
- /* 1010 */ V(3, 1, 3),
- /* 1011 */ V(3, 1, 3),
- /* 1100 */ V(0, 3, 4),
- /* 1101 */ V(3, 0, 4),
- /* 1110 */ V(2, 2, 3),
- /* 1111 */ V(2, 2, 3),
-
- /* 0011 ... */
- /* 00 */ V(1, 2, 2), /* 64 */
- /* 01 */ V(2, 1, 2),
- /* 10 */ V(0, 2, 2),
- /* 11 */ V(2, 0, 2),
-
- /* 0000 0000 ... */
- /* 000 */ V(14, 15, 3), /* 68 */
- /* 001 */ V(15, 14, 3),
- /* 010 */ V(13, 15, 3),
- /* 011 */ V(15, 13, 3),
- /* 100 */ V(12, 15, 3),
- /* 101 */ V(15, 12, 3),
- /* 110 */ V(11, 15, 3),
- /* 111 */ V(15, 11, 3),
-
- /* 0000 0001 ... */
- /* 000 */ V(10, 15, 2), /* 76 */
- /* 001 */ V(10, 15, 2),
- /* 010 */ V(15, 10, 3),
- /* 011 */ V(9, 15, 3),
- /* 100 */ V(15, 9, 3),
- /* 101 */ V(15, 8, 3),
- /* 110 */ V(8, 15, 2),
- /* 111 */ V(8, 15, 2),
-
- /* 0000 0010 ... */
- /* 00 */ V(7, 15, 2), /* 84 */
- /* 01 */ V(15, 7, 2),
- /* 10 */ V(6, 15, 2),
- /* 11 */ V(15, 6, 2),
-
- /* 0000 0100 ... */
- /* 00 */ V(5, 15, 2), /* 88 */
- /* 01 */ V(15, 5, 2),
- /* 10 */ V(4, 15, 1),
- /* 11 */ V(4, 15, 1),
-
- /* 0000 0101 ... */
- /* 0 */ V(15, 4, 1), /* 92 */
- /* 1 */ V(15, 3, 1),
-
- /* 0000 0110 ... */
- /* 0000 */ V(15, 0, 1), /* 94 */
- /* 0001 */ V(15, 0, 1),
- /* 0010 */ V(15, 0, 1),
- /* 0011 */ V(15, 0, 1),
- /* 0100 */ V(15, 0, 1),
- /* 0101 */ V(15, 0, 1),
- /* 0110 */ V(15, 0, 1),
- /* 0111 */ V(15, 0, 1),
- /* 1000 */ V(3, 15, 2),
- /* 1001 */ V(3, 15, 2),
- /* 1010 */ V(3, 15, 2),
- /* 1011 */ V(3, 15, 2),
- /* 1100 */ PTR(294, 4),
- /* 1101 */ PTR(310, 3),
- /* 1110 */ PTR(318, 3),
- /* 1111 */ PTR(326, 3),
-
- /* 0000 1000 ... */
- /* 0 */ V(2, 15, 1), /* 110 */
- /* 1 */ V(0, 15, 1),
-
- /* 0000 1011 ... */
- /* 0000 */ PTR(334, 2), /* 112 */
- /* 0001 */ PTR(338, 2),
- /* 0010 */ PTR(342, 2),
- /* 0011 */ PTR(346, 1),
- /* 0100 */ PTR(348, 2),
- /* 0101 */ PTR(352, 2),
- /* 0110 */ PTR(356, 1),
- /* 0111 */ PTR(358, 2),
- /* 1000 */ PTR(362, 2),
- /* 1001 */ PTR(366, 2),
- /* 1010 */ PTR(370, 2),
- /* 1011 */ V(14, 3, 4),
- /* 1100 */ PTR(374, 1),
- /* 1101 */ PTR(376, 1),
- /* 1110 */ PTR(378, 1),
- /* 1111 */ PTR(380, 1),
-
- /* 0000 1100 ... */
- /* 0000 */ PTR(382, 1), /* 128 */
- /* 0001 */ PTR(384, 1),
- /* 0010 */ PTR(386, 1),
- /* 0011 */ V(0, 13, 4),
- /* 0100 */ PTR(388, 1),
- /* 0101 */ PTR(390, 1),
- /* 0110 */ PTR(392, 1),
- /* 0111 */ V(3, 12, 4),
- /* 1000 */ PTR(394, 1),
- /* 1001 */ V(1, 12, 4),
- /* 1010 */ V(12, 0, 4),
- /* 1011 */ PTR(396, 1),
- /* 1100 */ V(14, 2, 3),
- /* 1101 */ V(14, 2, 3),
- /* 1110 */ V(2, 14, 4),
- /* 1111 */ V(1, 14, 4),
-
- /* 0000 1101 ... */
- /* 0000 */ V(13, 3, 4), /* 144 */
- /* 0001 */ V(2, 13, 4),
- /* 0010 */ V(13, 2, 4),
- /* 0011 */ V(13, 1, 4),
- /* 0100 */ V(3, 11, 4),
- /* 0101 */ PTR(398, 1),
- /* 0110 */ V(1, 13, 3),
- /* 0111 */ V(1, 13, 3),
- /* 1000 */ V(12, 4, 4),
- /* 1001 */ V(6, 11, 4),
- /* 1010 */ V(12, 3, 4),
- /* 1011 */ V(10, 7, 4),
- /* 1100 */ V(2, 12, 3),
- /* 1101 */ V(2, 12, 3),
- /* 1110 */ V(12, 2, 4),
- /* 1111 */ V(11, 5, 4),
-
- /* 0000 1110 ... */
- /* 0000 */ V(12, 1, 4), /* 160 */
- /* 0001 */ V(0, 12, 4),
- /* 0010 */ V(4, 11, 4),
- /* 0011 */ V(11, 4, 4),
- /* 0100 */ V(6, 10, 4),
- /* 0101 */ V(10, 6, 4),
- /* 0110 */ V(11, 3, 3),
- /* 0111 */ V(11, 3, 3),
- /* 1000 */ V(5, 10, 4),
- /* 1001 */ V(10, 5, 4),
- /* 1010 */ V(2, 11, 3),
- /* 1011 */ V(2, 11, 3),
- /* 1100 */ V(11, 2, 3),
- /* 1101 */ V(11, 2, 3),
- /* 1110 */ V(1, 11, 3),
- /* 1111 */ V(1, 11, 3),
-
- /* 0000 1111 ... */
- /* 0000 */ V(11, 1, 3), /* 176 */
- /* 0001 */ V(11, 1, 3),
- /* 0010 */ V(0, 11, 4),
- /* 0011 */ V(11, 0, 4),
- /* 0100 */ V(6, 9, 4),
- /* 0101 */ V(9, 6, 4),
- /* 0110 */ V(4, 10, 4),
- /* 0111 */ V(10, 4, 4),
- /* 1000 */ V(7, 8, 4),
- /* 1001 */ V(8, 7, 4),
- /* 1010 */ V(10, 3, 3),
- /* 1011 */ V(10, 3, 3),
- /* 1100 */ V(3, 10, 4),
- /* 1101 */ V(5, 9, 4),
- /* 1110 */ V(2, 10, 3),
- /* 1111 */ V(2, 10, 3),
-
- /* 0001 0000 ... */
- /* 0000 */ V(9, 5, 4), /* 192 */
- /* 0001 */ V(6, 8, 4),
- /* 0010 */ V(10, 1, 3),
- /* 0011 */ V(10, 1, 3),
- /* 0100 */ V(8, 6, 4),
- /* 0101 */ V(7, 7, 4),
- /* 0110 */ V(9, 4, 3),
- /* 0111 */ V(9, 4, 3),
- /* 1000 */ V(4, 9, 4),
- /* 1001 */ V(5, 7, 4),
- /* 1010 */ V(6, 7, 3),
- /* 1011 */ V(6, 7, 3),
- /* 1100 */ V(10, 2, 2),
- /* 1101 */ V(10, 2, 2),
- /* 1110 */ V(10, 2, 2),
- /* 1111 */ V(10, 2, 2),
-
- /* 0001 0001 ... */
- /* 000 */ V(1, 10, 2), /* 208 */
- /* 001 */ V(1, 10, 2),
- /* 010 */ V(0, 10, 3),
- /* 011 */ V(10, 0, 3),
- /* 100 */ V(3, 9, 3),
- /* 101 */ V(9, 3, 3),
- /* 110 */ V(5, 8, 3),
- /* 111 */ V(8, 5, 3),
-
- /* 0001 0010 ... */
- /* 000 */ V(2, 9, 2), /* 216 */
- /* 001 */ V(2, 9, 2),
- /* 010 */ V(9, 2, 2),
- /* 011 */ V(9, 2, 2),
- /* 100 */ V(7, 6, 3),
- /* 101 */ V(0, 9, 3),
- /* 110 */ V(1, 9, 2),
- /* 111 */ V(1, 9, 2),
-
- /* 0001 0011 ... */
- /* 000 */ V(9, 1, 2), /* 224 */
- /* 001 */ V(9, 1, 2),
- /* 010 */ V(9, 0, 3),
- /* 011 */ V(4, 8, 3),
- /* 100 */ V(8, 4, 3),
- /* 101 */ V(7, 5, 3),
- /* 110 */ V(3, 8, 3),
- /* 111 */ V(8, 3, 3),
-
- /* 0001 0100 ... */
- /* 000 */ V(6, 6, 3), /* 232 */
- /* 001 */ V(2, 8, 3),
- /* 010 */ V(8, 2, 2),
- /* 011 */ V(8, 2, 2),
- /* 100 */ V(4, 7, 3),
- /* 101 */ V(7, 4, 3),
- /* 110 */ V(1, 8, 2),
- /* 111 */ V(1, 8, 2),
-
- /* 0001 0101 ... */
- /* 000 */ V(8, 1, 2), /* 240 */
- /* 001 */ V(8, 1, 2),
- /* 010 */ V(8, 0, 2),
- /* 011 */ V(8, 0, 2),
- /* 100 */ V(0, 8, 3),
- /* 101 */ V(5, 6, 3),
- /* 110 */ V(3, 7, 2),
- /* 111 */ V(3, 7, 2),
-
- /* 0001 0110 ... */
- /* 000 */ V(7, 3, 2), /* 248 */
- /* 001 */ V(7, 3, 2),
- /* 010 */ V(6, 5, 3),
- /* 011 */ V(4, 6, 3),
- /* 100 */ V(2, 7, 2),
- /* 101 */ V(2, 7, 2),
- /* 110 */ V(7, 2, 2),
- /* 111 */ V(7, 2, 2),
-
- /* 0001 0111 ... */
- /* 000 */ V(6, 4, 3), /* 256 */
- /* 001 */ V(5, 5, 3),
- /* 010 */ V(0, 7, 2),
- /* 011 */ V(0, 7, 2),
- /* 100 */ V(1, 7, 1),
- /* 101 */ V(1, 7, 1),
- /* 110 */ V(1, 7, 1),
- /* 111 */ V(1, 7, 1),
-
- /* 0001 1000 ... */
- /* 00 */ V(7, 1, 1), /* 264 */
- /* 01 */ V(7, 1, 1),
- /* 10 */ V(7, 0, 2),
- /* 11 */ V(3, 6, 2),
-
- /* 0001 1001 ... */
- /* 00 */ V(6, 3, 2), /* 268 */
- /* 01 */ V(4, 5, 2),
- /* 10 */ V(5, 4, 2),
- /* 11 */ V(2, 6, 2),
-
- /* 0001 1010 ... */
- /* 0 */ V(6, 2, 1), /* 272 */
- /* 1 */ V(1, 6, 1),
-
- /* 0001 1011 ... */
- /* 00 */ V(6, 1, 1), /* 274 */
- /* 01 */ V(6, 1, 1),
- /* 10 */ V(0, 6, 2),
- /* 11 */ V(6, 0, 2),
-
- /* 0001 1100 ... */
- /* 00 */ V(5, 3, 1), /* 278 */
- /* 01 */ V(5, 3, 1),
- /* 10 */ V(3, 5, 2),
- /* 11 */ V(4, 4, 2),
-
- /* 0001 1101 ... */
- /* 0 */ V(2, 5, 1), /* 282 */
- /* 1 */ V(5, 2, 1),
-
- /* 0001 1111 ... */
- /* 0 */ V(1, 5, 1), /* 284 */
- /* 1 */ V(0, 5, 1),
-
- /* 0010 0000 ... */
- /* 0 */ V(3, 4, 1), /* 286 */
- /* 1 */ V(4, 3, 1),
-
- /* 0010 0001 ... */
- /* 0 */ V(5, 0, 1), /* 288 */
- /* 1 */ V(2, 4, 1),
-
- /* 0010 0010 ... */
- /* 0 */ V(4, 2, 1), /* 290 */
- /* 1 */ V(3, 3, 1),
-
- /* 0010 0101 ... */
- /* 0 */ V(0, 4, 1), /* 292 */
- /* 1 */ V(4, 0, 1),
-
- /* 0000 0110 1100 ... */
- /* 0000 */ V(12, 14, 4), /* 294 */
- /* 0001 */ PTR(400, 1),
- /* 0010 */ V(13, 14, 3),
- /* 0011 */ V(13, 14, 3),
- /* 0100 */ V(14, 9, 3),
- /* 0101 */ V(14, 9, 3),
- /* 0110 */ V(14, 10, 4),
- /* 0111 */ V(13, 9, 4),
- /* 1000 */ V(14, 14, 2),
- /* 1001 */ V(14, 14, 2),
- /* 1010 */ V(14, 14, 2),
- /* 1011 */ V(14, 14, 2),
- /* 1100 */ V(14, 13, 3),
- /* 1101 */ V(14, 13, 3),
- /* 1110 */ V(14, 11, 3),
- /* 1111 */ V(14, 11, 3),
-
- /* 0000 0110 1101 ... */
- /* 000 */ V(11, 14, 2), /* 310 */
- /* 001 */ V(11, 14, 2),
- /* 010 */ V(12, 13, 2),
- /* 011 */ V(12, 13, 2),
- /* 100 */ V(13, 12, 3),
- /* 101 */ V(13, 11, 3),
- /* 110 */ V(10, 14, 2),
- /* 111 */ V(10, 14, 2),
-
- /* 0000 0110 1110 ... */
- /* 000 */ V(12, 12, 2), /* 318 */
- /* 001 */ V(12, 12, 2),
- /* 010 */ V(10, 13, 3),
- /* 011 */ V(13, 10, 3),
- /* 100 */ V(7, 14, 3),
- /* 101 */ V(10, 12, 3),
- /* 110 */ V(12, 10, 2),
- /* 111 */ V(12, 10, 2),
-
- /* 0000 0110 1111 ... */
- /* 000 */ V(12, 9, 3), /* 326 */
- /* 001 */ V(7, 13, 3),
- /* 010 */ V(5, 14, 2),
- /* 011 */ V(5, 14, 2),
- /* 100 */ V(11, 13, 1),
- /* 101 */ V(11, 13, 1),
- /* 110 */ V(11, 13, 1),
- /* 111 */ V(11, 13, 1),
-
- /* 0000 1011 0000 ... */
- /* 00 */ V(9, 14, 1), /* 334 */
- /* 01 */ V(9, 14, 1),
- /* 10 */ V(11, 12, 2),
- /* 11 */ V(12, 11, 2),
-
- /* 0000 1011 0001 ... */
- /* 00 */ V(8, 14, 2), /* 338 */
- /* 01 */ V(14, 8, 2),
- /* 10 */ V(9, 13, 2),
- /* 11 */ V(14, 7, 2),
-
- /* 0000 1011 0010 ... */
- /* 00 */ V(11, 11, 2), /* 342 */
- /* 01 */ V(8, 13, 2),
- /* 10 */ V(13, 8, 2),
- /* 11 */ V(6, 14, 2),
-
- /* 0000 1011 0011 ... */
- /* 0 */ V(14, 6, 1), /* 346 */
- /* 1 */ V(9, 12, 1),
-
- /* 0000 1011 0100 ... */
- /* 00 */ V(10, 11, 2), /* 348 */
- /* 01 */ V(11, 10, 2),
- /* 10 */ V(14, 5, 2),
- /* 11 */ V(13, 7, 2),
-
- /* 0000 1011 0101 ... */
- /* 00 */ V(4, 14, 1), /* 352 */
- /* 01 */ V(4, 14, 1),
- /* 10 */ V(14, 4, 2),
- /* 11 */ V(8, 12, 2),
-
- /* 0000 1011 0110 ... */
- /* 0 */ V(12, 8, 1), /* 356 */
- /* 1 */ V(3, 14, 1),
-
- /* 0000 1011 0111 ... */
- /* 00 */ V(6, 13, 1), /* 358 */
- /* 01 */ V(6, 13, 1),
- /* 10 */ V(13, 6, 2),
- /* 11 */ V(9, 11, 2),
-
- /* 0000 1011 1000 ... */
- /* 00 */ V(11, 9, 2), /* 362 */
- /* 01 */ V(10, 10, 2),
- /* 10 */ V(14, 1, 1),
- /* 11 */ V(14, 1, 1),
-
- /* 0000 1011 1001 ... */
- /* 00 */ V(13, 4, 1), /* 366 */
- /* 01 */ V(13, 4, 1),
- /* 10 */ V(11, 8, 2),
- /* 11 */ V(10, 9, 2),
-
- /* 0000 1011 1010 ... */
- /* 00 */ V(7, 11, 1), /* 370 */
- /* 01 */ V(7, 11, 1),
- /* 10 */ V(11, 7, 2),
- /* 11 */ V(13, 0, 2),
-
- /* 0000 1011 1100 ... */
- /* 0 */ V(0, 14, 1), /* 374 */
- /* 1 */ V(14, 0, 1),
-
- /* 0000 1011 1101 ... */
- /* 0 */ V(5, 13, 1), /* 376 */
- /* 1 */ V(13, 5, 1),
-
- /* 0000 1011 1110 ... */
- /* 0 */ V(7, 12, 1), /* 378 */
- /* 1 */ V(12, 7, 1),
-
- /* 0000 1011 1111 ... */
- /* 0 */ V(4, 13, 1), /* 380 */
- /* 1 */ V(8, 11, 1),
-
- /* 0000 1100 0000 ... */
- /* 0 */ V(9, 10, 1), /* 382 */
- /* 1 */ V(6, 12, 1),
-
- /* 0000 1100 0001 ... */
- /* 0 */ V(12, 6, 1), /* 384 */
- /* 1 */ V(3, 13, 1),
-
- /* 0000 1100 0010 ... */
- /* 0 */ V(5, 12, 1), /* 386 */
- /* 1 */ V(12, 5, 1),
-
- /* 0000 1100 0100 ... */
- /* 0 */ V(8, 10, 1), /* 388 */
- /* 1 */ V(10, 8, 1),
-
- /* 0000 1100 0101 ... */
- /* 0 */ V(9, 9, 1), /* 390 */
- /* 1 */ V(4, 12, 1),
-
- /* 0000 1100 0110 ... */
- /* 0 */ V(11, 6, 1), /* 392 */
- /* 1 */ V(7, 10, 1),
-
- /* 0000 1100 1000 ... */
- /* 0 */ V(5, 11, 1), /* 394 */
- /* 1 */ V(8, 9, 1),
-
- /* 0000 1100 1011 ... */
- /* 0 */ V(9, 8, 1), /* 396 */
- /* 1 */ V(7, 9, 1),
-
- /* 0000 1101 0101 ... */
- /* 0 */ V(9, 7, 1), /* 398 */
- /* 1 */ V(8, 8, 1),
-
- /* 0000 0110 1100 0001 ... */
- /* 0 */ V(14, 12, 1), /* 400 */
- /* 1 */ V(13, 13, 1)
-};
-
-static
-union huffpair const hufftab24[] = {
- /* 0000 */ PTR(16, 4),
- /* 0001 */ PTR(32, 4),
- /* 0010 */ PTR(48, 4),
- /* 0011 */ V(15, 15, 4),
- /* 0100 */ PTR(64, 4),
- /* 0101 */ PTR(80, 4),
- /* 0110 */ PTR(96, 4),
- /* 0111 */ PTR(112, 4),
- /* 1000 */ PTR(128, 4),
- /* 1001 */ PTR(144, 4),
- /* 1010 */ PTR(160, 3),
- /* 1011 */ PTR(168, 2),
- /* 1100 */ V(1, 1, 4),
- /* 1101 */ V(0, 1, 4),
- /* 1110 */ V(1, 0, 4),
- /* 1111 */ V(0, 0, 4),
-
- /* 0000 ... */
- /* 0000 */ V(14, 15, 4), /* 16 */
- /* 0001 */ V(15, 14, 4),
- /* 0010 */ V(13, 15, 4),
- /* 0011 */ V(15, 13, 4),
- /* 0100 */ V(12, 15, 4),
- /* 0101 */ V(15, 12, 4),
- /* 0110 */ V(11, 15, 4),
- /* 0111 */ V(15, 11, 4),
- /* 1000 */ V(15, 10, 3),
- /* 1001 */ V(15, 10, 3),
- /* 1010 */ V(10, 15, 4),
- /* 1011 */ V(9, 15, 4),
- /* 1100 */ V(15, 9, 3),
- /* 1101 */ V(15, 9, 3),
- /* 1110 */ V(15, 8, 3),
- /* 1111 */ V(15, 8, 3),
-
- /* 0001 ... */
- /* 0000 */ V(8, 15, 4), /* 32 */
- /* 0001 */ V(7, 15, 4),
- /* 0010 */ V(15, 7, 3),
- /* 0011 */ V(15, 7, 3),
- /* 0100 */ V(6, 15, 3),
- /* 0101 */ V(6, 15, 3),
- /* 0110 */ V(15, 6, 3),
- /* 0111 */ V(15, 6, 3),
- /* 1000 */ V(5, 15, 3),
- /* 1001 */ V(5, 15, 3),
- /* 1010 */ V(15, 5, 3),
- /* 1011 */ V(15, 5, 3),
- /* 1100 */ V(4, 15, 3),
- /* 1101 */ V(4, 15, 3),
- /* 1110 */ V(15, 4, 3),
- /* 1111 */ V(15, 4, 3),
-
- /* 0010 ... */
- /* 0000 */ V(3, 15, 3), /* 48 */
- /* 0001 */ V(3, 15, 3),
- /* 0010 */ V(15, 3, 3),
- /* 0011 */ V(15, 3, 3),
- /* 0100 */ V(2, 15, 3),
- /* 0101 */ V(2, 15, 3),
- /* 0110 */ V(15, 2, 3),
- /* 0111 */ V(15, 2, 3),
- /* 1000 */ V(15, 1, 3),
- /* 1001 */ V(15, 1, 3),
- /* 1010 */ V(1, 15, 4),
- /* 1011 */ V(15, 0, 4),
- /* 1100 */ PTR(172, 3),
- /* 1101 */ PTR(180, 3),
- /* 1110 */ PTR(188, 3),
- /* 1111 */ PTR(196, 3),
-
- /* 0100 ... */
- /* 0000 */ PTR(204, 4), /* 64 */
- /* 0001 */ PTR(220, 3),
- /* 0010 */ PTR(228, 3),
- /* 0011 */ PTR(236, 3),
- /* 0100 */ PTR(244, 2),
- /* 0101 */ PTR(248, 2),
- /* 0110 */ PTR(252, 2),
- /* 0111 */ PTR(256, 2),
- /* 1000 */ PTR(260, 2),
- /* 1001 */ PTR(264, 2),
- /* 1010 */ PTR(268, 2),
- /* 1011 */ PTR(272, 2),
- /* 1100 */ PTR(276, 2),
- /* 1101 */ PTR(280, 3),
- /* 1110 */ PTR(288, 2),
- /* 1111 */ PTR(292, 2),
-
- /* 0101 ... */
- /* 0000 */ PTR(296, 2), /* 80 */
- /* 0001 */ PTR(300, 3),
- /* 0010 */ PTR(308, 2),
- /* 0011 */ PTR(312, 3),
- /* 0100 */ PTR(320, 1),
- /* 0101 */ PTR(322, 2),
- /* 0110 */ PTR(326, 2),
- /* 0111 */ PTR(330, 1),
- /* 1000 */ PTR(332, 2),
- /* 1001 */ PTR(336, 1),
- /* 1010 */ PTR(338, 1),
- /* 1011 */ PTR(340, 1),
- /* 1100 */ PTR(342, 1),
- /* 1101 */ PTR(344, 1),
- /* 1110 */ PTR(346, 1),
- /* 1111 */ PTR(348, 1),
-
- /* 0110 ... */
- /* 0000 */ PTR(350, 1), /* 96 */
- /* 0001 */ PTR(352, 1),
- /* 0010 */ PTR(354, 1),
- /* 0011 */ PTR(356, 1),
- /* 0100 */ PTR(358, 1),
- /* 0101 */ PTR(360, 1),
- /* 0110 */ PTR(362, 1),
- /* 0111 */ PTR(364, 1),
- /* 1000 */ PTR(366, 1),
- /* 1001 */ PTR(368, 1),
- /* 1010 */ PTR(370, 2),
- /* 1011 */ PTR(374, 1),
- /* 1100 */ PTR(376, 2),
- /* 1101 */ V(7, 3, 4),
- /* 1110 */ PTR(380, 1),
- /* 1111 */ V(7, 2, 4),
-
- /* 0111 ... */
- /* 0000 */ V(4, 6, 4), /* 112 */
- /* 0001 */ V(6, 4, 4),
- /* 0010 */ V(5, 5, 4),
- /* 0011 */ V(7, 1, 4),
- /* 0100 */ V(3, 6, 4),
- /* 0101 */ V(6, 3, 4),
- /* 0110 */ V(4, 5, 4),
- /* 0111 */ V(5, 4, 4),
- /* 1000 */ V(2, 6, 4),
- /* 1001 */ V(6, 2, 4),
- /* 1010 */ V(1, 6, 4),
- /* 1011 */ V(6, 1, 4),
- /* 1100 */ PTR(382, 1),
- /* 1101 */ V(3, 5, 4),
- /* 1110 */ V(5, 3, 4),
- /* 1111 */ V(4, 4, 4),
-
- /* 1000 ... */
- /* 0000 */ V(2, 5, 4), /* 128 */
- /* 0001 */ V(5, 2, 4),
- /* 0010 */ V(1, 5, 4),
- /* 0011 */ PTR(384, 1),
- /* 0100 */ V(5, 1, 3),
- /* 0101 */ V(5, 1, 3),
- /* 0110 */ V(3, 4, 4),
- /* 0111 */ V(4, 3, 4),
- /* 1000 */ V(2, 4, 3),
- /* 1001 */ V(2, 4, 3),
- /* 1010 */ V(4, 2, 3),
- /* 1011 */ V(4, 2, 3),
- /* 1100 */ V(3, 3, 3),
- /* 1101 */ V(3, 3, 3),
- /* 1110 */ V(1, 4, 3),
- /* 1111 */ V(1, 4, 3),
-
- /* 1001 ... */
- /* 0000 */ V(4, 1, 3), /* 144 */
- /* 0001 */ V(4, 1, 3),
- /* 0010 */ V(0, 4, 4),
- /* 0011 */ V(4, 0, 4),
- /* 0100 */ V(2, 3, 3),
- /* 0101 */ V(2, 3, 3),
- /* 0110 */ V(3, 2, 3),
- /* 0111 */ V(3, 2, 3),
- /* 1000 */ V(1, 3, 2),
- /* 1001 */ V(1, 3, 2),
- /* 1010 */ V(1, 3, 2),
- /* 1011 */ V(1, 3, 2),
- /* 1100 */ V(3, 1, 2),
- /* 1101 */ V(3, 1, 2),
- /* 1110 */ V(3, 1, 2),
- /* 1111 */ V(3, 1, 2),
-
- /* 1010 ... */
- /* 000 */ V(0, 3, 3), /* 160 */
- /* 001 */ V(3, 0, 3),
- /* 010 */ V(2, 2, 2),
- /* 011 */ V(2, 2, 2),
- /* 100 */ V(1, 2, 1),
- /* 101 */ V(1, 2, 1),
- /* 110 */ V(1, 2, 1),
- /* 111 */ V(1, 2, 1),
-
- /* 1011 ... */
- /* 00 */ V(2, 1, 1), /* 168 */
- /* 01 */ V(2, 1, 1),
- /* 10 */ V(0, 2, 2),
- /* 11 */ V(2, 0, 2),
-
- /* 0010 1100 ... */
- /* 000 */ V(0, 15, 1), /* 172 */
- /* 001 */ V(0, 15, 1),
- /* 010 */ V(0, 15, 1),
- /* 011 */ V(0, 15, 1),
- /* 100 */ V(14, 14, 3),
- /* 101 */ V(13, 14, 3),
- /* 110 */ V(14, 13, 3),
- /* 111 */ V(12, 14, 3),
-
- /* 0010 1101 ... */
- /* 000 */ V(14, 12, 3), /* 180 */
- /* 001 */ V(13, 13, 3),
- /* 010 */ V(11, 14, 3),
- /* 011 */ V(14, 11, 3),
- /* 100 */ V(12, 13, 3),
- /* 101 */ V(13, 12, 3),
- /* 110 */ V(10, 14, 3),
- /* 111 */ V(14, 10, 3),
-
- /* 0010 1110 ... */
- /* 000 */ V(11, 13, 3), /* 188 */
- /* 001 */ V(13, 11, 3),
- /* 010 */ V(12, 12, 3),
- /* 011 */ V(9, 14, 3),
- /* 100 */ V(14, 9, 3),
- /* 101 */ V(10, 13, 3),
- /* 110 */ V(13, 10, 3),
- /* 111 */ V(11, 12, 3),
-
- /* 0010 1111 ... */
- /* 000 */ V(12, 11, 3), /* 196 */
- /* 001 */ V(8, 14, 3),
- /* 010 */ V(14, 8, 3),
- /* 011 */ V(9, 13, 3),
- /* 100 */ V(13, 9, 3),
- /* 101 */ V(7, 14, 3),
- /* 110 */ V(14, 7, 3),
- /* 111 */ V(10, 12, 3),
-
- /* 0100 0000 ... */
- /* 0000 */ V(12, 10, 3), /* 204 */
- /* 0001 */ V(12, 10, 3),
- /* 0010 */ V(11, 11, 3),
- /* 0011 */ V(11, 11, 3),
- /* 0100 */ V(8, 13, 3),
- /* 0101 */ V(8, 13, 3),
- /* 0110 */ V(13, 8, 3),
- /* 0111 */ V(13, 8, 3),
- /* 1000 */ V(0, 14, 4),
- /* 1001 */ V(14, 0, 4),
- /* 1010 */ V(0, 13, 3),
- /* 1011 */ V(0, 13, 3),
- /* 1100 */ V(14, 6, 2),
- /* 1101 */ V(14, 6, 2),
- /* 1110 */ V(14, 6, 2),
- /* 1111 */ V(14, 6, 2),
-
- /* 0100 0001 ... */
- /* 000 */ V(6, 14, 3), /* 220 */
- /* 001 */ V(9, 12, 3),
- /* 010 */ V(12, 9, 2),
- /* 011 */ V(12, 9, 2),
- /* 100 */ V(5, 14, 2),
- /* 101 */ V(5, 14, 2),
- /* 110 */ V(11, 10, 2),
- /* 111 */ V(11, 10, 2),
-
- /* 0100 0010 ... */
- /* 000 */ V(14, 5, 2), /* 228 */
- /* 001 */ V(14, 5, 2),
- /* 010 */ V(10, 11, 3),
- /* 011 */ V(7, 13, 3),
- /* 100 */ V(13, 7, 2),
- /* 101 */ V(13, 7, 2),
- /* 110 */ V(14, 4, 2),
- /* 111 */ V(14, 4, 2),
-
- /* 0100 0011 ... */
- /* 000 */ V(8, 12, 2), /* 236 */
- /* 001 */ V(8, 12, 2),
- /* 010 */ V(12, 8, 2),
- /* 011 */ V(12, 8, 2),
- /* 100 */ V(4, 14, 3),
- /* 101 */ V(2, 14, 3),
- /* 110 */ V(3, 14, 2),
- /* 111 */ V(3, 14, 2),
-
- /* 0100 0100 ... */
- /* 00 */ V(6, 13, 2), /* 244 */
- /* 01 */ V(13, 6, 2),
- /* 10 */ V(14, 3, 2),
- /* 11 */ V(9, 11, 2),
-
- /* 0100 0101 ... */
- /* 00 */ V(11, 9, 2), /* 248 */
- /* 01 */ V(10, 10, 2),
- /* 10 */ V(14, 2, 2),
- /* 11 */ V(1, 14, 2),
-
- /* 0100 0110 ... */
- /* 00 */ V(14, 1, 2), /* 252 */
- /* 01 */ V(5, 13, 2),
- /* 10 */ V(13, 5, 2),
- /* 11 */ V(7, 12, 2),
-
- /* 0100 0111 ... */
- /* 00 */ V(12, 7, 2), /* 256 */
- /* 01 */ V(4, 13, 2),
- /* 10 */ V(8, 11, 2),
- /* 11 */ V(11, 8, 2),
-
- /* 0100 1000 ... */
- /* 00 */ V(13, 4, 2), /* 260 */
- /* 01 */ V(9, 10, 2),
- /* 10 */ V(10, 9, 2),
- /* 11 */ V(6, 12, 2),
-
- /* 0100 1001 ... */
- /* 00 */ V(12, 6, 2), /* 264 */
- /* 01 */ V(3, 13, 2),
- /* 10 */ V(13, 3, 2),
- /* 11 */ V(2, 13, 2),
-
- /* 0100 1010 ... */
- /* 00 */ V(13, 2, 2), /* 268 */
- /* 01 */ V(1, 13, 2),
- /* 10 */ V(7, 11, 2),
- /* 11 */ V(11, 7, 2),
-
- /* 0100 1011 ... */
- /* 00 */ V(13, 1, 2), /* 272 */
- /* 01 */ V(5, 12, 2),
- /* 10 */ V(12, 5, 2),
- /* 11 */ V(8, 10, 2),
-
- /* 0100 1100 ... */
- /* 00 */ V(10, 8, 2), /* 276 */
- /* 01 */ V(9, 9, 2),
- /* 10 */ V(4, 12, 2),
- /* 11 */ V(12, 4, 2),
-
- /* 0100 1101 ... */
- /* 000 */ V(6, 11, 2), /* 280 */
- /* 001 */ V(6, 11, 2),
- /* 010 */ V(11, 6, 2),
- /* 011 */ V(11, 6, 2),
- /* 100 */ V(13, 0, 3),
- /* 101 */ V(0, 12, 3),
- /* 110 */ V(3, 12, 2),
- /* 111 */ V(3, 12, 2),
-
- /* 0100 1110 ... */
- /* 00 */ V(12, 3, 2), /* 288 */
- /* 01 */ V(7, 10, 2),
- /* 10 */ V(10, 7, 2),
- /* 11 */ V(2, 12, 2),
-
- /* 0100 1111 ... */
- /* 00 */ V(12, 2, 2), /* 292 */
- /* 01 */ V(5, 11, 2),
- /* 10 */ V(11, 5, 2),
- /* 11 */ V(1, 12, 2),
-
- /* 0101 0000 ... */
- /* 00 */ V(8, 9, 2), /* 296 */
- /* 01 */ V(9, 8, 2),
- /* 10 */ V(12, 1, 2),
- /* 11 */ V(4, 11, 2),
-
- /* 0101 0001 ... */
- /* 000 */ V(12, 0, 3), /* 300 */
- /* 001 */ V(0, 11, 3),
- /* 010 */ V(3, 11, 2),
- /* 011 */ V(3, 11, 2),
- /* 100 */ V(11, 0, 3),
- /* 101 */ V(0, 10, 3),
- /* 110 */ V(1, 10, 2),
- /* 111 */ V(1, 10, 2),
-
- /* 0101 0010 ... */
- /* 00 */ V(11, 4, 1), /* 308 */
- /* 01 */ V(11, 4, 1),
- /* 10 */ V(6, 10, 2),
- /* 11 */ V(10, 6, 2),
-
- /* 0101 0011 ... */
- /* 000 */ V(7, 9, 2), /* 312 */
- /* 001 */ V(7, 9, 2),
- /* 010 */ V(9, 7, 2),
- /* 011 */ V(9, 7, 2),
- /* 100 */ V(10, 0, 3),
- /* 101 */ V(0, 9, 3),
- /* 110 */ V(9, 0, 2),
- /* 111 */ V(9, 0, 2),
-
- /* 0101 0100 ... */
- /* 0 */ V(11, 3, 1), /* 320 */
- /* 1 */ V(8, 8, 1),
-
- /* 0101 0101 ... */
- /* 00 */ V(2, 11, 2), /* 322 */
- /* 01 */ V(5, 10, 2),
- /* 10 */ V(11, 2, 1),
- /* 11 */ V(11, 2, 1),
-
- /* 0101 0110 ... */
- /* 00 */ V(10, 5, 2), /* 326 */
- /* 01 */ V(1, 11, 2),
- /* 10 */ V(11, 1, 2),
- /* 11 */ V(6, 9, 2),
-
- /* 0101 0111 ... */
- /* 0 */ V(9, 6, 1), /* 330 */
- /* 1 */ V(10, 4, 1),
-
- /* 0101 1000 ... */
- /* 00 */ V(4, 10, 2), /* 332 */
- /* 01 */ V(7, 8, 2),
- /* 10 */ V(8, 7, 1),
- /* 11 */ V(8, 7, 1),
-
- /* 0101 1001 ... */
- /* 0 */ V(3, 10, 1), /* 336 */
- /* 1 */ V(10, 3, 1),
-
- /* 0101 1010 ... */
- /* 0 */ V(5, 9, 1), /* 338 */
- /* 1 */ V(9, 5, 1),
-
- /* 0101 1011 ... */
- /* 0 */ V(2, 10, 1), /* 340 */
- /* 1 */ V(10, 2, 1),
-
- /* 0101 1100 ... */
- /* 0 */ V(10, 1, 1), /* 342 */
- /* 1 */ V(6, 8, 1),
-
- /* 0101 1101 ... */
- /* 0 */ V(8, 6, 1), /* 344 */
- /* 1 */ V(7, 7, 1),
-
- /* 0101 1110 ... */
- /* 0 */ V(4, 9, 1), /* 346 */
- /* 1 */ V(9, 4, 1),
-
- /* 0101 1111 ... */
- /* 0 */ V(3, 9, 1), /* 348 */
- /* 1 */ V(9, 3, 1),
-
- /* 0110 0000 ... */
- /* 0 */ V(5, 8, 1), /* 350 */
- /* 1 */ V(8, 5, 1),
-
- /* 0110 0001 ... */
- /* 0 */ V(2, 9, 1), /* 352 */
- /* 1 */ V(6, 7, 1),
-
- /* 0110 0010 ... */
- /* 0 */ V(7, 6, 1), /* 354 */
- /* 1 */ V(9, 2, 1),
-
- /* 0110 0011 ... */
- /* 0 */ V(1, 9, 1), /* 356 */
- /* 1 */ V(9, 1, 1),
-
- /* 0110 0100 ... */
- /* 0 */ V(4, 8, 1), /* 358 */
- /* 1 */ V(8, 4, 1),
-
- /* 0110 0101 ... */
- /* 0 */ V(5, 7, 1), /* 360 */
- /* 1 */ V(7, 5, 1),
-
- /* 0110 0110 ... */
- /* 0 */ V(3, 8, 1), /* 362 */
- /* 1 */ V(8, 3, 1),
-
- /* 0110 0111 ... */
- /* 0 */ V(6, 6, 1), /* 364 */
- /* 1 */ V(2, 8, 1),
-
- /* 0110 1000 ... */
- /* 0 */ V(8, 2, 1), /* 366 */
- /* 1 */ V(1, 8, 1),
-
- /* 0110 1001 ... */
- /* 0 */ V(4, 7, 1), /* 368 */
- /* 1 */ V(7, 4, 1),
-
- /* 0110 1010 ... */
- /* 00 */ V(8, 1, 1), /* 370 */
- /* 01 */ V(8, 1, 1),
- /* 10 */ V(0, 8, 2),
- /* 11 */ V(8, 0, 2),
-
- /* 0110 1011 ... */
- /* 0 */ V(5, 6, 1), /* 374 */
- /* 1 */ V(6, 5, 1),
-
- /* 0110 1100 ... */
- /* 00 */ V(1, 7, 1), /* 376 */
- /* 01 */ V(1, 7, 1),
- /* 10 */ V(0, 7, 2),
- /* 11 */ V(7, 0, 2),
-
- /* 0110 1110 ... */
- /* 0 */ V(3, 7, 1), /* 380 */
- /* 1 */ V(2, 7, 1),
-
- /* 0111 1100 ... */
- /* 0 */ V(0, 6, 1), /* 382 */
- /* 1 */ V(6, 0, 1),
-
- /* 1000 0011 ... */
- /* 0 */ V(0, 5, 1), /* 384 */
- /* 1 */ V(5, 0, 1)
-};
-
-# undef V
-# undef PTR
-
-/* external tables */
-
-union huffquad const *const mad_huff_quad_table[2] = { hufftabA, hufftabB };
-
-struct hufftable const mad_huff_pair_table[32] = {
- /* 0 */ { hufftab0, 0, 0 },
- /* 1 */ { hufftab1, 0, 3 },
- /* 2 */ { hufftab2, 0, 3 },
- /* 3 */ { hufftab3, 0, 3 },
- /* 4 */ { 0 /* not used */ },
- /* 5 */ { hufftab5, 0, 3 },
- /* 6 */ { hufftab6, 0, 4 },
- /* 7 */ { hufftab7, 0, 4 },
- /* 8 */ { hufftab8, 0, 4 },
- /* 9 */ { hufftab9, 0, 4 },
- /* 10 */ { hufftab10, 0, 4 },
- /* 11 */ { hufftab11, 0, 4 },
- /* 12 */ { hufftab12, 0, 4 },
- /* 13 */ { hufftab13, 0, 4 },
- /* 14 */ { 0 /* not used */ },
- /* 15 */ { hufftab15, 0, 4 },
- /* 16 */ { hufftab16, 1, 4 },
- /* 17 */ { hufftab16, 2, 4 },
- /* 18 */ { hufftab16, 3, 4 },
- /* 19 */ { hufftab16, 4, 4 },
- /* 20 */ { hufftab16, 6, 4 },
- /* 21 */ { hufftab16, 8, 4 },
- /* 22 */ { hufftab16, 10, 4 },
- /* 23 */ { hufftab16, 13, 4 },
- /* 24 */ { hufftab24, 4, 4 },
- /* 25 */ { hufftab24, 5, 4 },
- /* 26 */ { hufftab24, 6, 4 },
- /* 27 */ { hufftab24, 7, 4 },
- /* 28 */ { hufftab24, 8, 4 },
- /* 29 */ { hufftab24, 9, 4 },
- /* 30 */ { hufftab24, 11, 4 },
- /* 31 */ { hufftab24, 13, 4 }
-};
diff --git a/src/libmad/huffman.h b/src/libmad/huffman.h
deleted file mode 100644
index 2f00c00a1..000000000
--- a/src/libmad/huffman.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * libmad - MPEG audio decoder library
- * Copyright (C) 2000-2004 Underbit Technologies, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: huffman.h,v 1.4 2004/04/22 00:22:41 miguelfreitas Exp $
- */
-
-# ifndef LIBMAD_HUFFMAN_H
-# define LIBMAD_HUFFMAN_H
-
-union huffquad {
- struct {
- unsigned short final : 1;
- unsigned short bits : 3;
- unsigned short offset : 12;
- } ptr;
- struct {
- unsigned short final : 1;
- unsigned short hlen : 3;
- unsigned short v : 1;
- unsigned short w : 1;
- unsigned short x : 1;
- unsigned short y : 1;
- } value;
- unsigned short final : 1;
-};
-
-union huffpair {
- struct {
- unsigned short final : 1;
- unsigned short bits : 3;
- unsigned short offset : 12;
- } ptr;
- struct {
- unsigned short final : 1;
- unsigned short hlen : 3;
- unsigned short x : 4;
- unsigned short y : 4;
- } value;
- unsigned short final : 1;
-};
-
-struct hufftable {
- union huffpair const *table;
- unsigned short linbits;
- unsigned short startbits;
-};
-
-extern union huffquad const *const mad_huff_quad_table[2];
-extern struct hufftable const mad_huff_pair_table[32];
-
-# endif
diff --git a/src/libmad/imdct_l_arm.S b/src/libmad/imdct_l_arm.S
deleted file mode 100644
index 35b2e2626..000000000
--- a/src/libmad/imdct_l_arm.S
+++ /dev/null
@@ -1,1000 +0,0 @@
-/*****************************************************************************
-* Copyright (C) 2000-2001 Andre McCurdy <armccurdy@yahoo.co.uk>
-*
-* This program is free software. you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation@ either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY, without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program@ if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*
-*****************************************************************************
-*
-* Notes:
-*
-*
-*****************************************************************************
-*
-* $Id: imdct_l_arm.S,v 1.1 2002/04/30 18:46:58 miguelfreitas Exp $
-*
-* 2001/03/24: Andre McCurdy <armccurdy@yahoo.co.uk>
-* - Corrected PIC unsafe loading of address of 'imdct36_long_karray'
-*
-* 2000/09/20: Robert Leslie <rob@mars.org>
-* - Added a global symbol with leading underscore per suggestion of
-* Simon Burge to support linking with the a.out format.
-*
-* 2000/09/15: Robert Leslie <rob@mars.org>
-* - Fixed a small bug where flags were changed before a conditional branch.
-*
-* 2000/09/15: Andre McCurdy <armccurdy@yahoo.co.uk>
-* - Applied Nicolas Pitre's rounding optimisation in all remaining places.
-*
-* 2000/09/09: Nicolas Pitre <nico@cam.org>
-* - Optimized rounding + scaling operations.
-*
-* 2000/08/09: Andre McCurdy <armccurdy@yahoo.co.uk>
-* - Original created.
-*
-****************************************************************************/
-
-
-/*
- On entry:
-
- r0 = pointer to 18 element input array
- r1 = pointer to 36 element output array
- r2 = windowing block type
-
-
- Stack frame created during execution of the function:
-
- Initial Holds:
- Stack
- pointer
- minus:
-
- 0
- 4 lr
- 8 r11
- 12 r10
- 16 r9
- 20 r8
- 24 r7
- 28 r6
- 32 r5
- 36 r4
-
- 40 r2 : windowing block type
-
- 44 ct00 high
- 48 ct00 low
- 52 ct01 high
- 56 ct01 low
- 60 ct04 high
- 64 ct04 low
- 68 ct06 high
- 72 ct06 low
- 76 ct05 high
- 80 ct05 low
- 84 ct03 high
- 88 ct03 low
- 92 -ct05 high
- 96 -ct05 low
- 100 -ct07 high
- 104 -ct07 low
- 108 ct07 high
- 112 ct07 low
- 116 ct02 high
- 120 ct02 low
-*/
-
-#define BLOCK_MODE_NORMAL 0
-#define BLOCK_MODE_START 1
-#define BLOCK_MODE_STOP 3
-
-
-#define X0 0x00
-#define X1 0x04
-#define X2 0x08
-#define X3 0x0C
-#define X4 0x10
-#define X5 0x14
-#define X6 0x18
-#define X7 0x1c
-#define X8 0x20
-#define X9 0x24
-#define X10 0x28
-#define X11 0x2c
-#define X12 0x30
-#define X13 0x34
-#define X14 0x38
-#define X15 0x3c
-#define X16 0x40
-#define X17 0x44
-
-#define x0 0x00
-#define x1 0x04
-#define x2 0x08
-#define x3 0x0C
-#define x4 0x10
-#define x5 0x14
-#define x6 0x18
-#define x7 0x1c
-#define x8 0x20
-#define x9 0x24
-#define x10 0x28
-#define x11 0x2c
-#define x12 0x30
-#define x13 0x34
-#define x14 0x38
-#define x15 0x3c
-#define x16 0x40
-#define x17 0x44
-#define x18 0x48
-#define x19 0x4c
-#define x20 0x50
-#define x21 0x54
-#define x22 0x58
-#define x23 0x5c
-#define x24 0x60
-#define x25 0x64
-#define x26 0x68
-#define x27 0x6c
-#define x28 0x70
-#define x29 0x74
-#define x30 0x78
-#define x31 0x7c
-#define x32 0x80
-#define x33 0x84
-#define x34 0x88
-#define x35 0x8c
-
-#define K00 0x0ffc19fd
-#define K01 0x00b2aa3e
-#define K02 0x0fdcf549
-#define K03 0x0216a2a2
-#define K04 0x0f9ee890
-#define K05 0x03768962
-#define K06 0x0f426cb5
-#define K07 0x04cfb0e2
-#define K08 0x0ec835e8
-#define K09 0x061f78aa
-#define K10 0x0e313245
-#define K11 0x07635284
-#define K12 0x0d7e8807
-#define K13 0x0898c779
-#define K14 0x0cb19346
-#define K15 0x09bd7ca0
-#define K16 0x0bcbe352
-#define K17 0x0acf37ad
-
-#define minus_K02 0xf0230ab7
-
-#define WL0 0x00b2aa3e
-#define WL1 0x0216a2a2
-#define WL2 0x03768962
-#define WL3 0x04cfb0e2
-#define WL4 0x061f78aa
-#define WL5 0x07635284
-#define WL6 0x0898c779
-#define WL7 0x09bd7ca0
-#define WL8 0x0acf37ad
-#define WL9 0x0bcbe352
-#define WL10 0x0cb19346
-#define WL11 0x0d7e8807
-#define WL12 0x0e313245
-#define WL13 0x0ec835e8
-#define WL14 0x0f426cb5
-#define WL15 0x0f9ee890
-#define WL16 0x0fdcf549
-#define WL17 0x0ffc19fd
-
-
-@*****************************************************************************
-
-
- .text
- .align
-
- .global III_imdct_l
- .global _III_imdct_l
-
-III_imdct_l:
-_III_imdct_l:
-
- stmdb sp!, { r2, r4 - r11, lr } @ all callee saved regs, plus arg3
-
- ldr r4, =K08 @ r4 = K08
- ldr r5, =K09 @ r5 = K09
- ldr r8, [r0, #X4] @ r8 = X4
- ldr r9, [r0, #X13] @ r9 = X13
- rsb r6, r4, #0 @ r6 = -K08
- rsb r7, r5, #0 @ r7 = -K09
-
- smull r2, r3, r4, r8 @ r2..r3 = (X4 * K08)
- smlal r2, r3, r5, r9 @ r2..r3 = (X4 * K08) + (X13 * K09) = ct01
-
- smull r10, lr, r8, r5 @ r10..lr = (X4 * K09)
- smlal r10, lr, r9, r6 @ r10..lr = (X4 * K09) + (X13 * -K08) = ct00
-
- ldr r8, [r0, #X7] @ r8 = X7
- ldr r9, [r0, #X16] @ r9 = X16
-
- stmdb sp!, { r2, r3, r10, lr } @ stack ct00_h, ct00_l, ct01_h, ct01_l
-
- add r8, r8, r9 @ r8 = (X7 + X16)
- ldr r9, [r0, #X1] @ r9 = X1
-
- smlal r2, r3, r6, r8 @ r2..r3 = ct01 + ((X7 + X16) * -K08)
- smlal r2, r3, r7, r9 @ r2..r3 += (X1 * -K09)
-
- ldr r7, [r0, #X10] @ r7 = X10
-
- rsbs r10, r10, #0
- rsc lr, lr, #0 @ r10..lr = -ct00
-
- smlal r2, r3, r5, r7 @ r2..r3 += (X10 * K09) = ct06
-
- smlal r10, lr, r9, r6 @ r10..lr = -ct00 + ( X1 * -K08)
- smlal r10, lr, r8, r5 @ r10..lr += ((X7 + X16) * K09)
- smlal r10, lr, r7, r4 @ r10..lr += ( X10 * K08) = ct04
-
- stmdb sp!, { r2, r3, r10, lr } @ stack ct04_h, ct04_l, ct06_h, ct06_l
-
- @----
-
- ldr r7, [r0, #X0]
- ldr r8, [r0, #X11]
- ldr r9, [r0, #X12]
- sub r7, r7, r8
- sub r7, r7, r9 @ r7 = (X0 - X11 -X12) = ct14
-
- ldr r9, [r0, #X3]
- ldr r8, [r0, #X8]
- ldr r11, [r0, #X15]
- sub r8, r8, r9
- add r8, r8, r11 @ r8 = (X8 - X3 + X15) = ct16
-
- add r11, r7, r8 @ r11 = ct14 + ct16 = ct18
-
- smlal r2, r3, r6, r11 @ r2..r3 = ct06 + ((X0 - X11 - X3 + X15 + X8 - X12) * -K08)
-
- ldr r6, [r0, #X2]
- ldr r9, [r0, #X9]
- ldr r12, [r0, #X14]
- sub r6, r6, r9
- sub r6, r6, r12 @ r6 = (X2 - X9 - X14) = ct15
-
- ldr r9, [r0, #X5]
- ldr r12, [r0, #X6]
- sub r9, r9, r12
- ldr r12, [r0, #X17]
- sub r9, r9, r12 @ r9 = (X5 - X6 - X17) = ct17
-
- add r12, r9, r6 @ r12 = ct15 + ct17 = ct19
-
- smlal r2, r3, r5, r12 @ r2..r3 += ((X2 - X9 + X5 - X6 - X17 - X14) * K09)
-
- smlal r10, lr, r11, r5 @ r10..lr = ct04 + (ct18 * K09)
- smlal r10, lr, r12, r4 @ r10..lr = ct04 + (ct18 * K09) + (ct19 * K08)
-
- movs r2, r2, lsr #28
- adc r2, r2, r3, lsl #4 @ r2 = bits[59..28] of r2..r3
- str r2, [r1, #x22] @ store result x22
-
- movs r10, r10, lsr #28
- adc r10, r10, lr, lsl #4 @ r10 = bits[59..28] of r10..lr
- str r10, [r1, #x4] @ store result x4
-
- @----
-
- ldmia sp, { r2, r3, r4, r5 } @ r2..r3 = ct06, r4..r5 = ct04 (dont update sp)
-
- @ r2..r3 = ct06
- @ r4..r5 = ct04
- @ r6 = ct15
- @ r7 = ct14
- @ r8 = ct16
- @ r9 = ct17
- @ r10 = .
- @ r11 = .
- @ r12 = .
- @ lr = .
-
- ldr r10, =K03 @ r10 = K03
- ldr lr, =K15 @ lr = K15
-
- smlal r2, r3, r10, r7 @ r2..r3 = ct06 + (ct14 * K03)
- smlal r4, r5, lr, r7 @ r4..r5 = ct04 + (ct14 * K15)
-
- ldr r12, =K14 @ r12 = K14
- rsb r10, r10, #0 @ r10 = -K03
-
- smlal r2, r3, lr, r6 @ r2..r3 += (ct15 * K15)
- smlal r4, r5, r10, r6 @ r4..r5 += (ct15 * -K03)
- smlal r2, r3, r12, r8 @ r2..r3 += (ct16 * K14)
-
- ldr r11, =minus_K02 @ r11 = -K02
- rsb r12, r12, #0 @ r12 = -K14
-
- smlal r4, r5, r12, r9 @ r4..r5 += (ct17 * -K14)
- smlal r2, r3, r11, r9 @ r2..r3 += (ct17 * -K02)
- smlal r4, r5, r11, r8 @ r4..r5 += (ct16 * -K02)
-
- movs r2, r2, lsr #28
- adc r2, r2, r3, lsl #4 @ r2 = bits[59..28] of r2..r3
- str r2, [r1, #x7] @ store result x7
-
- movs r4, r4, lsr #28
- adc r4, r4, r5, lsl #4 @ r4 = bits[59..28] of r4..r5
- str r4, [r1, #x1] @ store result x1
-
- @----
-
- ldmia sp, { r2, r3, r4, r5 } @ r2..r3 = ct06, r4..r5 = ct04 (dont update sp)
-
- @ r2..r3 = ct06
- @ r4..r5 = ct04
- @ r6 = ct15
- @ r7 = ct14
- @ r8 = ct16
- @ r9 = ct17
- @ r10 = -K03
- @ r11 = -K02
- @ r12 = -K14
- @ lr = K15
-
- rsbs r2, r2, #0
- rsc r3, r3, #0 @ r2..r3 = -ct06
-
- smlal r2, r3, r12, r7 @ r2..r3 = -ct06 + (ct14 * -K14)
- smlal r2, r3, r10, r8 @ r2..r3 += (ct16 * -K03)
-
- smlal r4, r5, r12, r6 @ r4..r5 = ct04 + (ct15 * -K14)
- smlal r4, r5, r10, r9 @ r4..r5 += (ct17 * -K03)
- smlal r4, r5, lr, r8 @ r4..r5 += (ct16 * K15)
- smlal r4, r5, r11, r7 @ r4..r5 += (ct14 * -K02)
-
- rsb lr, lr, #0 @ lr = -K15
- rsb r11, r11, #0 @ r11 = K02
-
- smlal r2, r3, lr, r9 @ r2..r3 += (ct17 * -K15)
- smlal r2, r3, r11, r6 @ r2..r3 += (ct15 * K02)
-
- movs r4, r4, lsr #28
- adc r4, r4, r5, lsl #4 @ r4 = bits[59..28] of r4..r5
- str r4, [r1, #x25] @ store result x25
-
- movs r2, r2, lsr #28
- adc r2, r2, r3, lsl #4 @ r2 = bits[59..28] of r2..r3
- str r2, [r1, #x19] @ store result x19
-
- @----
-
- ldr r2, [sp, #16] @ r2 = ct01_l
- ldr r3, [sp, #20] @ r3 = ct01_h
-
- ldr r6, [r0, #X1]
- ldr r8, [r0, #X7]
- ldr r9, [r0, #X10]
- ldr r7, [r0, #X16]
-
- rsbs r2, r2, #0
- rsc r3, r3, #0 @ r2..r3 = -ct01
-
- mov r4, r2
- mov r5, r3 @ r4..r5 = -ct01
-
- @ r2..r3 = -ct01
- @ r4..r5 = -ct01
- @ r6 = X1
- @ r7 = X16
- @ r8 = X7
- @ r9 = X10
- @ r10 = -K03
- @ r11 = K02
- @ r12 = -K14
- @ lr = -K15
-
- smlal r4, r5, r12, r7 @ r4..r5 = -ct01 + (X16 * -K14)
- smlal r2, r3, lr, r9 @ r2..r3 = -ct01 + (X10 * -K15)
-
- smlal r4, r5, r10, r8 @ r4..r5 += (X7 * -K03)
- smlal r2, r3, r10, r7 @ r2..r3 += (X16 * -K03)
-
- smlal r4, r5, r11, r9 @ r4..r5 += (X10 * K02)
- smlal r2, r3, r12, r8 @ r2..r3 += (X7 * -K14)
-
- rsb lr, lr, #0 @ lr = K15
- rsb r11, r11, #0 @ r11 = -K02
-
- smlal r4, r5, lr, r6 @ r4..r5 += (X1 * K15) = ct05
- smlal r2, r3, r11, r6 @ r2..r3 += (X1 * -K02) = ct03
-
- stmdb sp!, { r2, r3, r4, r5 } @ stack ct05_h, ct05_l, ct03_h, ct03_l
-
- rsbs r4, r4, #0
- rsc r5, r5, #0 @ r4..r5 = -ct05
-
- stmdb sp!, { r4, r5 } @ stack -ct05_h, -ct05_l
-
- ldr r2, [sp, #48] @ r2 = ct00_l
- ldr r3, [sp, #52] @ r3 = ct00_h
-
- rsb r10, r10, #0 @ r10 = K03
-
- rsbs r4, r2, #0
- rsc r5, r3, #0 @ r4..r5 = -ct00
-
- @ r2..r3 = ct00
- @ r4..r5 = -ct00
- @ r6 = X1
- @ r7 = X16
- @ r8 = X7
- @ r9 = X10
- @ r10 = K03
- @ r11 = -K02
- @ r12 = -K14
- @ lr = K15
-
- smlal r4, r5, r10, r6 @ r4..r5 = -ct00 + (X1 * K03)
- smlal r2, r3, r10, r9 @ r2..r3 = ct00 + (X10 * K03)
-
- smlal r4, r5, r12, r9 @ r4..r5 += (X10 * -K14)
- smlal r2, r3, r12, r6 @ r2..r3 += (X1 * -K14)
-
- smlal r4, r5, r11, r7 @ r4..r5 += (X16 * -K02)
- smlal r4, r5, lr, r8 @ r4..r5 += (X7 * K15) = ct07
-
- rsb lr, lr, #0 @ lr = -K15
- rsb r11, r11, #0 @ r11 = K02
-
- smlal r2, r3, r11, r8 @ r2..r3 += (X7 * K02)
- smlal r2, r3, lr, r7 @ r2..r3 += (X16 * -K15) = ct02
-
- rsbs r6, r4, #0
- rsc r7, r5, #0 @ r6..r7 = -ct07
-
- stmdb sp!, { r2 - r7 } @ stack -ct07_h, -ct07_l, ct07_h, ct07_l, ct02_h, ct02_l
-
-
- @----
-
- add r2, pc, #(imdct36_long_karray-.-8) @ r2 = base address of Knn array (PIC safe ?)
-
-
-loop:
- ldr r12, [r0, #X0]
-
- ldmia r2!, { r5 - r11 } @ first 7 words from Karray element
-
- smull r3, r4, r5, r12 @ sum = (Kxx * X0)
- ldr r12, [r0, #X2]
- ldr r5, [r0, #X3]
- smlal r3, r4, r6, r12 @ sum += (Kxx * X2)
- ldr r12, [r0, #X5]
- ldr r6, [r0, #X6]
- smlal r3, r4, r7, r5 @ sum += (Kxx * X3)
- smlal r3, r4, r8, r12 @ sum += (Kxx * X5)
- ldr r12, [r0, #X8]
- ldr r5, [r0, #X9]
- smlal r3, r4, r9, r6 @ sum += (Kxx * X6)
- smlal r3, r4, r10, r12 @ sum += (Kxx * X8)
- smlal r3, r4, r11, r5 @ sum += (Kxx * X9)
-
- ldmia r2!, { r5 - r10 } @ final 6 words from Karray element
-
- ldr r11, [r0, #X11]
- ldr r12, [r0, #X12]
- smlal r3, r4, r5, r11 @ sum += (Kxx * X11)
- ldr r11, [r0, #X14]
- ldr r5, [r0, #X15]
- smlal r3, r4, r6, r12 @ sum += (Kxx * X12)
- smlal r3, r4, r7, r11 @ sum += (Kxx * X14)
- ldr r11, [r0, #X17]
- smlal r3, r4, r8, r5 @ sum += (Kxx * X15)
- smlal r3, r4, r9, r11 @ sum += (Kxx * X17)
-
- add r5, sp, r10, lsr #16 @ create index back into stack for required ctxx
-
- ldmia r5, { r6, r7 } @ r6..r7 = ctxx
-
- mov r8, r10, lsl #16 @ push ctxx index off the top end
-
- adds r3, r3, r6 @ add low words
- adc r4, r4, r7 @ add high words, with carry
- movs r3, r3, lsr #28
- adc r3, r3, r4, lsl #4 @ r3 = bits[59..28] of r3..r4
-
- str r3, [r1, r8, lsr #24] @ push completion flag off the bottom end
-
- movs r8, r8, lsl #8 @ push result location index off the top end
- beq loop @ loop back if completion flag not set
- b imdct_l_windowing @ branch to windowing stage if looping finished
-
-imdct36_long_karray:
-
- .word K17, -K13, K10, -K06, -K05, K01, -K00, K04, -K07, K11, K12, -K16, 0x00000000
- .word K13, K07, K16, K01, K10, -K05, K04, -K11, K00, -K17, K06, -K12, 0x00200800
- .word K11, K17, K05, K12, -K01, K06, -K07, K00, -K13, K04, -K16, K10, 0x00200c00
- .word K07, K00, -K12, K05, -K16, -K10, K11, -K17, K04, K13, K01, K06, 0x00001400
- .word K05, K10, -K00, -K17, K07, -K13, K12, K06, -K16, K01, -K11, -K04, 0x00181800
- .word K01, K05, -K07, -K11, K13, K17, -K16, -K12, K10, K06, -K04, -K00, 0x00102000
- .word -K16, K12, -K11, K07, K04, -K00, -K01, K05, -K06, K10, K13, -K17, 0x00284800
- .word -K12, K06, K17, -K00, -K11, K04, K05, -K10, K01, K16, -K07, -K13, 0x00085000
- .word -K10, K16, K04, -K13, -K00, K07, K06, -K01, -K12, -K05, K17, K11, 0x00105400
- .word -K06, -K01, K13, K04, K17, -K11, -K10, -K16, -K05, K12, K00, K07, 0x00185c00
- .word -K04, -K11, -K01, K16, K06, K12, K13, -K07, -K17, -K00, -K10, -K05, 0x00006000
- .word -K00, -K04, -K06, -K10, -K12, -K16, -K17, -K13, -K11, -K07, -K05, -K01, 0x00206801
-
-
- @----
- @-------------------------------------------------------------------------
- @----
-
-imdct_l_windowing:
-
- ldr r11, [sp, #80] @ fetch function parameter 3 from out of the stack
- ldmia r1!, { r0, r2 - r9 } @ load 9 words from x0, update pointer
-
- @ r0 = x0
- @ r1 = &x[9]
- @ r2 = x1
- @ r3 = x2
- @ r4 = x3
- @ r5 = x4
- @ r6 = x5
- @ r7 = x6
- @ r8 = x7
- @ r9 = x8
- @ r10 = .
- @ r11 = window mode: (0 == normal), (1 == start block), (3 == stop block)
- @ r12 = .
- @ lr = .
-
- cmp r11, #BLOCK_MODE_STOP @ setup flags
- rsb r10, r0, #0 @ r10 = -x0 (DONT change flags !!)
- beq stop_block_x0_to_x17
-
-
- @ start and normal blocks are treated the same for x[0]..x[17]
-
-normal_block_x0_to_x17:
-
- ldr r12, =WL9 @ r12 = window_l[9]
-
- rsb r0, r9, #0 @ r0 = -x8
- rsb r9, r2, #0 @ r9 = -x1
- rsb r2, r8, #0 @ r2 = -x7
- rsb r8, r3, #0 @ r8 = -x2
- rsb r3, r7, #0 @ r3 = -x6
- rsb r7, r4, #0 @ r7 = -x3
- rsb r4, r6, #0 @ r4 = -x5
- rsb r6, r5, #0 @ r6 = -x4
-
- @ r0 = -x8
- @ r1 = &x[9]
- @ r2 = -x7
- @ r3 = -x6
- @ r4 = -x5
- @ r5 = .
- @ r6 = -x4
- @ r7 = -x3
- @ r8 = -x2
- @ r9 = -x1
- @ r10 = -x0
- @ r11 = window mode: (0 == normal), (1 == start block), (3 == stop block)
- @ r12 = window_l[9]
- @ lr = .
-
- smull r5, lr, r12, r0 @ r5..lr = (window_l[9] * (x[9] == -x[8]))
- ldr r12, =WL10 @ r12 = window_l[10]
- movs r5, r5, lsr #28
- adc r0, r5, lr, lsl #4 @ r0 = bits[59..28] of windowed x9
-
- smull r5, lr, r12, r2 @ r5..lr = (window_l[10] * (x[10] == -x[7]))
- ldr r12, =WL11 @ r12 = window_l[11]
- movs r5, r5, lsr #28
- adc r2, r5, lr, lsl #4 @ r2 = bits[59..28] of windowed x10
-
- smull r5, lr, r12, r3 @ r5..lr = (window_l[11] * (x[11] == -x[6]))
- ldr r12, =WL12 @ r12 = window_l[12]
- movs r5, r5, lsr #28
- adc r3, r5, lr, lsl #4 @ r3 = bits[59..28] of windowed x11
-
- smull r5, lr, r12, r4 @ r5..lr = (window_l[12] * (x[12] == -x[5]))
- ldr r12, =WL13 @ r12 = window_l[13]
- movs r5, r5, lsr #28
- adc r4, r5, lr, lsl #4 @ r4 = bits[59..28] of windowed x12
-
- smull r5, lr, r12, r6 @ r5..lr = (window_l[13] * (x[13] == -x[4]))
- ldr r12, =WL14 @ r12 = window_l[14]
- movs r5, r5, lsr #28
- adc r6, r5, lr, lsl #4 @ r6 = bits[59..28] of windowed x13
-
- smull r5, lr, r12, r7 @ r5..lr = (window_l[14] * (x[14] == -x[3]))
- ldr r12, =WL15 @ r12 = window_l[15]
- movs r5, r5, lsr #28
- adc r7, r5, lr, lsl #4 @ r7 = bits[59..28] of windowed x14
-
- smull r5, lr, r12, r8 @ r5..lr = (window_l[15] * (x[15] == -x[2]))
- ldr r12, =WL16 @ r12 = window_l[16]
- movs r5, r5, lsr #28
- adc r8, r5, lr, lsl #4 @ r8 = bits[59..28] of windowed x15
-
- smull r5, lr, r12, r9 @ r5..lr = (window_l[16] * (x[16] == -x[1]))
- ldr r12, =WL17 @ r12 = window_l[17]
- movs r5, r5, lsr #28
- adc r9, r5, lr, lsl #4 @ r9 = bits[59..28] of windowed x16
-
- smull r5, lr, r12, r10 @ r5..lr = (window_l[17] * (x[17] == -x[0]))
- ldr r12, =WL0 @ r12 = window_l[0]
- movs r5, r5, lsr #28
- adc r10, r5, lr, lsl #4 @ r10 = bits[59..28] of windowed x17
-
-
- stmia r1, { r0, r2 - r4, r6 - r10 } @ store windowed x[9] .. x[17]
- ldmdb r1!, { r0, r2 - r9 } @ load 9 words downto (and including) x0
-
-
- smull r10, lr, r12, r0 @ r10..lr = (window_l[0] * x[0])
- ldr r12, =WL1 @ r12 = window_l[1]
- movs r10, r10, lsr #28
- adc r0, r10, lr, lsl #4 @ r0 = bits[59..28] of windowed x0
-
- smull r10, lr, r12, r2 @ r10..lr = (window_l[1] * x[1])
- ldr r12, =WL2 @ r12 = window_l[2]
- movs r10, r10, lsr #28
- adc r2, r10, lr, lsl #4 @ r2 = bits[59..28] of windowed x1
-
- smull r10, lr, r12, r3 @ r10..lr = (window_l[2] * x[2])
- ldr r12, =WL3 @ r12 = window_l[3]
- movs r10, r10, lsr #28
- adc r3, r10, lr, lsl #4 @ r3 = bits[59..28] of windowed x2
-
- smull r10, lr, r12, r4 @ r10..lr = (window_l[3] * x[3])
- ldr r12, =WL4 @ r12 = window_l[4]
- movs r10, r10, lsr #28
- adc r4, r10, lr, lsl #4 @ r4 = bits[59..28] of windowed x3
-
- smull r10, lr, r12, r5 @ r10..lr = (window_l[4] * x[4])
- ldr r12, =WL5 @ r12 = window_l[5]
- movs r10, r10, lsr #28
- adc r5, r10, lr, lsl #4 @ r5 = bits[59..28] of windowed x4
-
- smull r10, lr, r12, r6 @ r10..lr = (window_l[5] * x[5])
- ldr r12, =WL6 @ r12 = window_l[6]
- movs r10, r10, lsr #28
- adc r6, r10, lr, lsl #4 @ r6 = bits[59..28] of windowed x5
-
- smull r10, lr, r12, r7 @ r10..lr = (window_l[6] * x[6])
- ldr r12, =WL7 @ r12 = window_l[7]
- movs r10, r10, lsr #28
- adc r7, r10, lr, lsl #4 @ r7 = bits[59..28] of windowed x6
-
- smull r10, lr, r12, r8 @ r10..lr = (window_l[7] * x[7])
- ldr r12, =WL8 @ r12 = window_l[8]
- movs r10, r10, lsr #28
- adc r8, r10, lr, lsl #4 @ r8 = bits[59..28] of windowed x7
-
- smull r10, lr, r12, r9 @ r10..lr = (window_l[8] * x[8])
- movs r10, r10, lsr #28
- adc r9, r10, lr, lsl #4 @ r9 = bits[59..28] of windowed x8
-
- stmia r1, { r0, r2 - r9 } @ store windowed x[0] .. x[8]
-
- cmp r11, #BLOCK_MODE_START
- beq start_block_x18_to_x35
-
-
- @----
-
-
-normal_block_x18_to_x35:
-
- ldr r11, =WL3 @ r11 = window_l[3]
- ldr r12, =WL4 @ r12 = window_l[4]
-
- add r1, r1, #(18*4) @ r1 = &x[18]
-
- ldmia r1!, { r0, r2 - r4, r6 - r10 } @ load 9 words from x18, update pointer
-
- @ r0 = x18
- @ r1 = &x[27]
- @ r2 = x19
- @ r3 = x20
- @ r4 = x21
- @ r5 = .
- @ r6 = x22
- @ r7 = x23
- @ r8 = x24
- @ r9 = x25
- @ r10 = x26
- @ r11 = window_l[3]
- @ r12 = window_l[4]
- @ lr = .
-
- smull r5, lr, r12, r6 @ r5..lr = (window_l[4] * (x[22] == x[31]))
- movs r5, r5, lsr #28
- adc r5, r5, lr, lsl #4 @ r5 = bits[59..28] of windowed x31
-
- smull r6, lr, r11, r4 @ r5..lr = (window_l[3] * (x[21] == x[32]))
- ldr r12, =WL5 @ r12 = window_l[5]
- movs r6, r6, lsr #28
- adc r6, r6, lr, lsl #4 @ r6 = bits[59..28] of windowed x32
-
- smull r4, lr, r12, r7 @ r4..lr = (window_l[5] * (x[23] == x[30]))
- ldr r11, =WL1 @ r11 = window_l[1]
- ldr r12, =WL2 @ r12 = window_l[2]
- movs r4, r4, lsr #28
- adc r4, r4, lr, lsl #4 @ r4 = bits[59..28] of windowed x30
-
- smull r7, lr, r12, r3 @ r7..lr = (window_l[2] * (x[20] == x[33]))
- ldr r12, =WL6 @ r12 = window_l[6]
- movs r7, r7, lsr #28
- adc r7, r7, lr, lsl #4 @ r7 = bits[59..28] of windowed x33
-
- smull r3, lr, r12, r8 @ r3..lr = (window_l[6] * (x[24] == x[29]))
- movs r3, r3, lsr #28
- adc r3, r3, lr, lsl #4 @ r3 = bits[59..28] of windowed x29
-
- smull r8, lr, r11, r2 @ r7..lr = (window_l[1] * (x[19] == x[34]))
- ldr r12, =WL7 @ r12 = window_l[7]
- ldr r11, =WL8 @ r11 = window_l[8]
- movs r8, r8, lsr #28
- adc r8, r8, lr, lsl #4 @ r8 = bits[59..28] of windowed x34
-
- smull r2, lr, r12, r9 @ r7..lr = (window_l[7] * (x[25] == x[28]))
- ldr r12, =WL0 @ r12 = window_l[0]
- movs r2, r2, lsr #28
- adc r2, r2, lr, lsl #4 @ r2 = bits[59..28] of windowed x28
-
- smull r9, lr, r12, r0 @ r3..lr = (window_l[0] * (x[18] == x[35]))
- movs r9, r9, lsr #28
- adc r9, r9, lr, lsl #4 @ r9 = bits[59..28] of windowed x35
-
- smull r0, lr, r11, r10 @ r7..lr = (window_l[8] * (x[26] == x[27]))
- ldr r11, =WL16 @ r11 = window_l[16]
- ldr r12, =WL17 @ r12 = window_l[17]
- movs r0, r0, lsr #28
- adc r0, r0, lr, lsl #4 @ r0 = bits[59..28] of windowed x27
-
-
- stmia r1, { r0, r2 - r9 } @ store windowed x[27] .. x[35]
- ldmdb r1!, { r0, r2 - r9 } @ load 9 words downto (and including) x18
-
-
- smull r10, lr, r12, r0 @ r10..lr = (window_l[17] * x[18])
- movs r10, r10, lsr #28
- adc r0, r10, lr, lsl #4 @ r0 = bits[59..28] of windowed x0
-
- smull r10, lr, r11, r2 @ r10..lr = (window_l[16] * x[19])
- ldr r11, =WL14 @ r11 = window_l[14]
- ldr r12, =WL15 @ r12 = window_l[15]
- movs r10, r10, lsr #28
- adc r2, r10, lr, lsl #4 @ r2 = bits[59..28] of windowed x1
-
- smull r10, lr, r12, r3 @ r10..lr = (window_l[15] * x[20])
- movs r10, r10, lsr #28
- adc r3, r10, lr, lsl #4 @ r3 = bits[59..28] of windowed x2
-
- smull r10, lr, r11, r4 @ r10..lr = (window_l[14] * x[21])
- ldr r11, =WL12 @ r11 = window_l[12]
- ldr r12, =WL13 @ r12 = window_l[13]
- movs r10, r10, lsr #28
- adc r4, r10, lr, lsl #4 @ r4 = bits[59..28] of windowed x3
-
- smull r10, lr, r12, r5 @ r10..lr = (window_l[13] * x[22])
- movs r10, r10, lsr #28
- adc r5, r10, lr, lsl #4 @ r5 = bits[59..28] of windowed x4
-
- smull r10, lr, r11, r6 @ r10..lr = (window_l[12] * x[23])
- ldr r11, =WL10 @ r12 = window_l[10]
- ldr r12, =WL11 @ r12 = window_l[11]
- movs r10, r10, lsr #28
- adc r6, r10, lr, lsl #4 @ r6 = bits[59..28] of windowed x5
-
- smull r10, lr, r12, r7 @ r10..lr = (window_l[11] * x[24])
- movs r10, r10, lsr #28
- adc r7, r10, lr, lsl #4 @ r7 = bits[59..28] of windowed x6
-
- smull r10, lr, r11, r8 @ r10..lr = (window_l[10] * x[25])
- ldr r12, =WL9 @ r12 = window_l[9]
- movs r10, r10, lsr #28
- adc r8, r10, lr, lsl #4 @ r8 = bits[59..28] of windowed x7
-
- smull r10, lr, r12, r9 @ r10..lr = (window_l[9] * x[26])
-
- movs r10, r10, lsr #28
- adc r9, r10, lr, lsl #4 @ r9 = bits[59..28] of windowed x8
-
- stmia r1, { r0, r2 - r9 } @ store windowed x[18] .. x[26]
-
- @----
- @ NB there are 2 possible exits from this function - this is only one of them
- @----
-
- add sp, sp, #(21*4) @ return stack frame
- ldmia sp!, { r4 - r11, pc } @ restore callee saved regs, and return
-
- @----
-
-
-stop_block_x0_to_x17:
-
- @ r0 = x0
- @ r1 = &x[9]
- @ r2 = x1
- @ r3 = x2
- @ r4 = x3
- @ r5 = x4
- @ r6 = x5
- @ r7 = x6
- @ r8 = x7
- @ r9 = x8
- @ r10 = -x0
- @ r11 = window mode: (0 == normal), (1 == start block), (3 == stop block)
- @ r12 = .
- @ lr = .
-
- rsb r0, r6, #0 @ r0 = -x5
- rsb r6, r2, #0 @ r6 = -x1
- rsb r2, r5, #0 @ r2 = -x4
- rsb r5, r3, #0 @ r5 = -x2
- rsb r3, r4, #0 @ r3 = -x3
-
- add r1, r1, #(3*4) @ r1 = &x[12]
- stmia r1, { r0, r2, r3, r5, r6, r10 } @ store unchanged x[12] .. x[17]
-
- ldr r0, =WL1 @ r0 = window_l[1] == window_s[0]
-
- rsb r10, r9, #0 @ r10 = -x8
- rsb r12, r8, #0 @ r12 = -x7
- rsb lr, r7, #0 @ lr = -x6
-
- @ r0 = WL1
- @ r1 = &x[12]
- @ r2 = .
- @ r3 = .
- @ r4 = .
- @ r5 = .
- @ r6 = .
- @ r7 = x6
- @ r8 = x7
- @ r9 = x8
- @ r10 = -x8
- @ r11 = window mode: (0 == normal), (1 == start block), (3 == stop block)
- @ r12 = -x7
- @ lr = -x6
-
- smull r5, r6, r0, r7 @ r5..r6 = (window_l[1] * x[6])
- ldr r2, =WL4 @ r2 = window_l[4] == window_s[1]
- movs r5, r5, lsr #28
- adc r7, r5, r6, lsl #4 @ r7 = bits[59..28] of windowed x6
-
- smull r5, r6, r2, r8 @ r5..r6 = (window_l[4] * x[7])
- ldr r3, =WL7 @ r3 = window_l[7] == window_s[2]
- movs r5, r5, lsr #28
- adc r8, r5, r6, lsl #4 @ r8 = bits[59..28] of windowed x7
-
- smull r5, r6, r3, r9 @ r5..r6 = (window_l[7] * x[8])
- ldr r4, =WL10 @ r4 = window_l[10] == window_s[3]
- movs r5, r5, lsr #28
- adc r9, r5, r6, lsl #4 @ r9 = bits[59..28] of windowed x8
-
- smull r5, r6, r4, r10 @ r5..r6 = (window_l[10] * (x[9] == -x[8]))
- ldr r0, =WL13 @ r0 = window_l[13] == window_s[4]
- movs r5, r5, lsr #28
- adc r10, r5, r6, lsl #4 @ r10 = bits[59..28] of windowed x9
-
- smull r5, r6, r0, r12 @ r5..r6 = (window_l[13] * (x[10] == -x[7]))
- ldr r2, =WL16 @ r2 = window_l[16] == window_s[5]
- movs r5, r5, lsr #28
- adc r12, r5, r6, lsl #4 @ r10 = bits[59..28] of windowed x9
-
- smull r5, r6, r2, lr @ r5..r6 = (window_l[16] * (x[11] == -x[6]))
-
- ldr r0, =0x00
-
- movs r5, r5, lsr #28
- adc lr, r5, r6, lsl #4 @ r10 = bits[59..28] of windowed x9
-
- stmdb r1!, { r7 - r10, r12, lr } @ store windowed x[6] .. x[11]
-
- ldr r5, =0x00
- ldr r6, =0x00
- ldr r2, =0x00
- ldr r3, =0x00
- ldr r4, =0x00
-
- stmdb r1!, { r0, r2 - r6 } @ store windowed x[0] .. x[5]
-
- b normal_block_x18_to_x35
-
-
- @----
-
-
-start_block_x18_to_x35:
-
- ldr r4, =WL1 @ r0 = window_l[1] == window_s[0]
-
- add r1, r1, #(24*4) @ r1 = &x[24]
-
- ldmia r1, { r0, r2, r3 } @ load 3 words from x24, dont update pointer
-
- @ r0 = x24
- @ r1 = &x[24]
- @ r2 = x25
- @ r3 = x26
- @ r4 = WL1
- @ r5 = WL4
- @ r6 = WL7
- @ r7 = WL10
- @ r8 = WL13
- @ r9 = WL16
- @ r10 = .
- @ r11 = .
- @ r12 = .
- @ lr = .
-
- ldr r5, =WL4 @ r5 = window_l[4] == window_s[1]
-
- smull r10, r11, r4, r0 @ r10..r11 = (window_l[1] * (x[24] == x[29]))
- ldr r6, =WL7 @ r6 = window_l[7] == window_s[2]
- movs r10, r10, lsr #28
- adc lr, r10, r11, lsl #4 @ lr = bits[59..28] of windowed x29
-
- smull r10, r11, r5, r2 @ r10..r11 = (window_l[4] * (x[25] == x[28]))
- ldr r7, =WL10 @ r7 = window_l[10] == window_s[3]
- movs r10, r10, lsr #28
- adc r12, r10, r11, lsl #4 @ r12 = bits[59..28] of windowed x28
-
- smull r10, r11, r6, r3 @ r10..r11 = (window_l[7] * (x[26] == x[27]))
- ldr r8, =WL13 @ r8 = window_l[13] == window_s[4]
- movs r10, r10, lsr #28
- adc r4, r10, r11, lsl #4 @ r4 = bits[59..28] of windowed x27
-
- smull r10, r11, r7, r3 @ r10..r11 = (window_l[10] * x[26])
- ldr r9, =WL16 @ r9 = window_l[16] == window_s[5]
- movs r10, r10, lsr #28
- adc r3, r10, r11, lsl #4 @ r3 = bits[59..28] of windowed x26
-
- smull r10, r11, r8, r2 @ r10..r11 = (window_l[13] * x[25])
- ldr r5, =0x00
- movs r10, r10, lsr #28
- adc r2, r10, r11, lsl #4 @ r2 = bits[59..28] of windowed x25
-
- smull r10, r11, r9, r0 @ r10..r11 = (window_l[16] * x[24])
- ldr r6, =0x00
- movs r10, r10, lsr #28
- adc r0, r10, r11, lsl #4 @ r0 = bits[59..28] of windowed x24
-
- stmia r1!, { r0, r2, r3, r4, r12, lr } @ store windowed x[24] .. x[29]
-
- ldr r7, =0x00
- ldr r8, =0x00
- ldr r9, =0x00
- ldr r10, =0x00
-
- stmia r1!, { r5 - r10 } @ store windowed x[30] .. x[35]
-
- @----
- @ NB there are 2 possible exits from this function - this is only one of them
- @----
-
- add sp, sp, #(21*4) @ return stack frame
- ldmia sp!, { r4 - r11, pc } @ restore callee saved regs, and return
-
- @----
- @END
- @----
-
diff --git a/src/libmad/imdct_s.dat b/src/libmad/imdct_s.dat
deleted file mode 100644
index c938859e0..000000000
--- a/src/libmad/imdct_s.dat
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * libmad - MPEG audio decoder library
- * Copyright (C) 2000-2004 Underbit Technologies, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: imdct_s.dat,v 1.3 2004/04/22 00:22:41 miguelfreitas Exp $
- */
-
- /* 0 */ { MAD_F(0x09bd7ca0) /* 0.608761429 */,
- -MAD_F(0x0ec835e8) /* -0.923879533 */,
- -MAD_F(0x0216a2a2) /* -0.130526192 */,
- MAD_F(0x0fdcf549) /* 0.991444861 */,
- -MAD_F(0x061f78aa) /* -0.382683432 */,
- -MAD_F(0x0cb19346) /* -0.793353340 */ },
-
- /* 6 */ { -MAD_F(0x0cb19346) /* -0.793353340 */,
- MAD_F(0x061f78aa) /* 0.382683432 */,
- MAD_F(0x0fdcf549) /* 0.991444861 */,
- MAD_F(0x0216a2a2) /* 0.130526192 */,
- -MAD_F(0x0ec835e8) /* -0.923879533 */,
- -MAD_F(0x09bd7ca0) /* -0.608761429 */ },
-
- /* 1 */ { MAD_F(0x061f78aa) /* 0.382683432 */,
- -MAD_F(0x0ec835e8) /* -0.923879533 */,
- MAD_F(0x0ec835e8) /* 0.923879533 */,
- -MAD_F(0x061f78aa) /* -0.382683432 */,
- -MAD_F(0x061f78aa) /* -0.382683432 */,
- MAD_F(0x0ec835e8) /* 0.923879533 */ },
-
- /* 7 */ { -MAD_F(0x0ec835e8) /* -0.923879533 */,
- -MAD_F(0x061f78aa) /* -0.382683432 */,
- MAD_F(0x061f78aa) /* 0.382683432 */,
- MAD_F(0x0ec835e8) /* 0.923879533 */,
- MAD_F(0x0ec835e8) /* 0.923879533 */,
- MAD_F(0x061f78aa) /* 0.382683432 */ },
-
- /* 2 */ { MAD_F(0x0216a2a2) /* 0.130526192 */,
- -MAD_F(0x061f78aa) /* -0.382683432 */,
- MAD_F(0x09bd7ca0) /* 0.608761429 */,
- -MAD_F(0x0cb19346) /* -0.793353340 */,
- MAD_F(0x0ec835e8) /* 0.923879533 */,
- -MAD_F(0x0fdcf549) /* -0.991444861 */ },
-
- /* 8 */ { -MAD_F(0x0fdcf549) /* -0.991444861 */,
- -MAD_F(0x0ec835e8) /* -0.923879533 */,
- -MAD_F(0x0cb19346) /* -0.793353340 */,
- -MAD_F(0x09bd7ca0) /* -0.608761429 */,
- -MAD_F(0x061f78aa) /* -0.382683432 */,
- -MAD_F(0x0216a2a2) /* -0.130526192 */ }
diff --git a/src/libmad/layer12.c b/src/libmad/layer12.c
deleted file mode 100644
index 25fd04d70..000000000
--- a/src/libmad/layer12.c
+++ /dev/null
@@ -1,534 +0,0 @@
-/*
- * libmad - MPEG audio decoder library
- * Copyright (C) 2000-2004 Underbit Technologies, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: layer12.c,v 1.3 2004/04/22 00:22:41 miguelfreitas Exp $
- */
-
-# ifdef HAVE_CONFIG_H
-# include "config.h"
-# endif
-
-# include "global.h"
-
-# ifdef HAVE_LIMITS_H
-# include <limits.h>
-# else
-# define CHAR_BIT 8
-# endif
-
-# include "fixed.h"
-# include "bit.h"
-# include "stream.h"
-# include "frame.h"
-# include "layer12.h"
-
-/*
- * scalefactor table
- * used in both Layer I and Layer II decoding
- */
-static
-mad_fixed_t const sf_table[64] = {
-# include "sf_table.dat"
-};
-
-/* --- Layer I ------------------------------------------------------------- */
-
-/* linear scaling table */
-static
-mad_fixed_t const linear_table[14] = {
- MAD_F(0x15555555), /* 2^2 / (2^2 - 1) == 1.33333333333333 */
- MAD_F(0x12492492), /* 2^3 / (2^3 - 1) == 1.14285714285714 */
- MAD_F(0x11111111), /* 2^4 / (2^4 - 1) == 1.06666666666667 */
- MAD_F(0x10842108), /* 2^5 / (2^5 - 1) == 1.03225806451613 */
- MAD_F(0x10410410), /* 2^6 / (2^6 - 1) == 1.01587301587302 */
- MAD_F(0x10204081), /* 2^7 / (2^7 - 1) == 1.00787401574803 */
- MAD_F(0x10101010), /* 2^8 / (2^8 - 1) == 1.00392156862745 */
- MAD_F(0x10080402), /* 2^9 / (2^9 - 1) == 1.00195694716243 */
- MAD_F(0x10040100), /* 2^10 / (2^10 - 1) == 1.00097751710655 */
- MAD_F(0x10020040), /* 2^11 / (2^11 - 1) == 1.00048851978505 */
- MAD_F(0x10010010), /* 2^12 / (2^12 - 1) == 1.00024420024420 */
- MAD_F(0x10008004), /* 2^13 / (2^13 - 1) == 1.00012208521548 */
- MAD_F(0x10004001), /* 2^14 / (2^14 - 1) == 1.00006103888177 */
- MAD_F(0x10002000) /* 2^15 / (2^15 - 1) == 1.00003051850948 */
-};
-
-/*
- * NAME: I_sample()
- * DESCRIPTION: decode one requantized Layer I sample from a bitstream
- */
-static
-mad_fixed_t I_sample(struct mad_bitptr *ptr, unsigned int nb)
-{
- mad_fixed_t sample;
-
- sample = mad_bit_read(ptr, nb);
-
- /* invert most significant bit, extend sign, then scale to fixed format */
-
- sample ^= 1 << (nb - 1);
- sample |= -(sample & (1 << (nb - 1)));
-
- sample <<= MAD_F_FRACBITS - (nb - 1);
-
- /* requantize the sample */
-
- /* s'' = (2^nb / (2^nb - 1)) * (s''' + 2^(-nb + 1)) */
-
- sample += MAD_F_ONE >> (nb - 1);
-
- return mad_f_mul(sample, linear_table[nb - 2]);
-
- /* s' = factor * s'' */
- /* (to be performed by caller) */
-}
-
-/*
- * NAME: layer->I()
- * DESCRIPTION: decode a single Layer I frame
- */
-int mad_layer_I(struct mad_stream *stream, struct mad_frame *frame)
-{
- struct mad_header *header = &frame->header;
- unsigned int nch, bound, ch, s, sb, nb;
- unsigned char allocation[2][32], scalefactor[2][32];
-
- nch = MAD_NCHANNELS(header);
-
- bound = 32;
- if (header->mode == MAD_MODE_JOINT_STEREO) {
- header->flags |= MAD_FLAG_I_STEREO;
- bound = 4 + header->mode_extension * 4;
- }
-
- /* check CRC word */
-
- if (header->flags & MAD_FLAG_PROTECTION) {
- header->crc_check =
- mad_bit_crc(stream->ptr, 4 * (bound * nch + (32 - bound)),
- header->crc_check);
-
- if (header->crc_check != header->crc_target &&
- !(frame->options & MAD_OPTION_IGNORECRC)) {
- stream->error = MAD_ERROR_BADCRC;
- return -1;
- }
- }
-
- /* decode bit allocations */
-
- for (sb = 0; sb < bound; ++sb) {
- for (ch = 0; ch < nch; ++ch) {
- nb = mad_bit_read(&stream->ptr, 4);
-
- if (nb == 15) {
- stream->error = MAD_ERROR_BADBITALLOC;
- return -1;
- }
-
- allocation[ch][sb] = nb ? nb + 1 : 0;
- }
- }
-
- for (sb = bound; sb < 32; ++sb) {
- nb = mad_bit_read(&stream->ptr, 4);
-
- if (nb == 15) {
- stream->error = MAD_ERROR_BADBITALLOC;
- return -1;
- }
-
- allocation[0][sb] =
- allocation[1][sb] = nb ? nb + 1 : 0;
- }
-
- /* decode scalefactors */
-
- for (sb = 0; sb < 32; ++sb) {
- for (ch = 0; ch < nch; ++ch) {
- if (allocation[ch][sb]) {
- scalefactor[ch][sb] = mad_bit_read(&stream->ptr, 6);
-
-# if defined(OPT_STRICT)
- /*
- * Scalefactor index 63 does not appear in Table B.1 of
- * ISO/IEC 11172-3. Nonetheless, other implementations accept it,
- * so we only reject it if OPT_STRICT is defined.
- */
- if (scalefactor[ch][sb] == 63) {
- stream->error = MAD_ERROR_BADSCALEFACTOR;
- return -1;
- }
-# endif
- }
- }
- }
-
- /* decode samples */
-
- for (s = 0; s < 12; ++s) {
- for (sb = 0; sb < bound; ++sb) {
- for (ch = 0; ch < nch; ++ch) {
- nb = allocation[ch][sb];
- frame->sbsample[ch][s][sb] = nb ?
- mad_f_mul(I_sample(&stream->ptr, nb),
- sf_table[scalefactor[ch][sb]]) : 0;
- }
- }
-
- for (sb = bound; sb < 32; ++sb) {
- if ((nb = allocation[0][sb])) {
- mad_fixed_t sample;
-
- sample = I_sample(&stream->ptr, nb);
-
- for (ch = 0; ch < nch; ++ch) {
- frame->sbsample[ch][s][sb] =
- mad_f_mul(sample, sf_table[scalefactor[ch][sb]]);
- }
- }
- else {
- for (ch = 0; ch < nch; ++ch)
- frame->sbsample[ch][s][sb] = 0;
- }
- }
- }
-
- return 0;
-}
-
-/* --- Layer II ------------------------------------------------------------ */
-
-/* possible quantization per subband table */
-static
-struct {
- unsigned int sblimit;
- unsigned char const offsets[30];
-} const sbquant_table[5] = {
- /* ISO/IEC 11172-3 Table B.2a */
- { 27, { 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 3, 3, 3, 3, 3, /* 0 */
- 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0 } },
- /* ISO/IEC 11172-3 Table B.2b */
- { 30, { 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 3, 3, 3, 3, 3, /* 1 */
- 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0 } },
- /* ISO/IEC 11172-3 Table B.2c */
- { 8, { 5, 5, 2, 2, 2, 2, 2, 2 } }, /* 2 */
- /* ISO/IEC 11172-3 Table B.2d */
- { 12, { 5, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 } }, /* 3 */
- /* ISO/IEC 13818-3 Table B.1 */
- { 30, { 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, /* 4 */
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } }
-};
-
-/* bit allocation table */
-static
-struct {
- unsigned short nbal;
- unsigned short offset;
-} const bitalloc_table[8] = {
- { 2, 0 }, /* 0 */
- { 2, 3 }, /* 1 */
- { 3, 3 }, /* 2 */
- { 3, 1 }, /* 3 */
- { 4, 2 }, /* 4 */
- { 4, 3 }, /* 5 */
- { 4, 4 }, /* 6 */
- { 4, 5 } /* 7 */
-};
-
-/* offsets into quantization class table */
-static
-unsigned char const offset_table[6][15] = {
- { 0, 1, 16 }, /* 0 */
- { 0, 1, 2, 3, 4, 5, 16 }, /* 1 */
- { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }, /* 2 */
- { 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, /* 3 */
- { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16 }, /* 4 */
- { 0, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 } /* 5 */
-};
-
-/* quantization class table */
-static
-struct quantclass {
- unsigned short nlevels;
- unsigned char group;
- unsigned char bits;
- mad_fixed_t C;
- mad_fixed_t D;
-} const qc_table[17] = {
-# include "qc_table.dat"
-};
-
-/*
- * NAME: II_samples()
- * DESCRIPTION: decode three requantized Layer II samples from a bitstream
- */
-static
-void II_samples(struct mad_bitptr *ptr,
- struct quantclass const *quantclass,
- mad_fixed_t output[3])
-{
- unsigned int nb, s, sample[3];
-
- if ((nb = quantclass->group)) {
- unsigned int c, nlevels;
-
- /* degrouping */
- c = mad_bit_read(ptr, quantclass->bits);
- nlevels = quantclass->nlevels;
-
- for (s = 0; s < 3; ++s) {
- sample[s] = c % nlevels;
- c /= nlevels;
- }
- }
- else {
- nb = quantclass->bits;
-
- for (s = 0; s < 3; ++s)
- sample[s] = mad_bit_read(ptr, nb);
- }
-
- for (s = 0; s < 3; ++s) {
- mad_fixed_t requantized;
-
- /* invert most significant bit, extend sign, then scale to fixed format */
-
- requantized = sample[s] ^ (1 << (nb - 1));
- requantized |= -(requantized & (1 << (nb - 1)));
-
- requantized <<= MAD_F_FRACBITS - (nb - 1);
-
- /* requantize the sample */
-
- /* s'' = C * (s''' + D) */
-
- output[s] = mad_f_mul(requantized + quantclass->D, quantclass->C);
-
- /* s' = factor * s'' */
- /* (to be performed by caller) */
- }
-}
-
-/*
- * NAME: layer->II()
- * DESCRIPTION: decode a single Layer II frame
- */
-int mad_layer_II(struct mad_stream *stream, struct mad_frame *frame)
-{
- struct mad_header *header = &frame->header;
- struct mad_bitptr start;
- unsigned int index, sblimit, nbal, nch, bound, gr, ch, s, sb;
- unsigned char const *offsets;
- unsigned char allocation[2][32], scfsi[2][32], scalefactor[2][32][3];
- mad_fixed_t samples[3];
-
- nch = MAD_NCHANNELS(header);
-
- if (header->flags & MAD_FLAG_LSF_EXT)
- index = 4;
- else if (header->flags & MAD_FLAG_FREEFORMAT)
- goto freeformat;
- else {
- unsigned long bitrate_per_channel;
-
- bitrate_per_channel = header->bitrate;
- if (nch == 2) {
- bitrate_per_channel /= 2;
-
-# if defined(OPT_STRICT)
- /*
- * ISO/IEC 11172-3 allows only single channel mode for 32, 48, 56, and
- * 80 kbps bitrates in Layer II, but some encoders ignore this
- * restriction. We enforce it if OPT_STRICT is defined.
- */
- if (bitrate_per_channel <= 28000 || bitrate_per_channel == 40000) {
- stream->error = MAD_ERROR_BADMODE;
- return -1;
- }
-# endif
- }
- else { /* nch == 1 */
- if (bitrate_per_channel > 192000) {
- /*
- * ISO/IEC 11172-3 does not allow single channel mode for 224, 256,
- * 320, or 384 kbps bitrates in Layer II.
- */
- stream->error = MAD_ERROR_BADMODE;
- return -1;
- }
- }
-
- if (bitrate_per_channel <= 48000)
- index = (header->samplerate == 32000) ? 3 : 2;
- else if (bitrate_per_channel <= 80000)
- index = 0;
- else {
- freeformat:
- index = (header->samplerate == 48000) ? 0 : 1;
- }
- }
-
- sblimit = sbquant_table[index].sblimit;
- offsets = sbquant_table[index].offsets;
-
- bound = 32;
- if (header->mode == MAD_MODE_JOINT_STEREO) {
- header->flags |= MAD_FLAG_I_STEREO;
- bound = 4 + header->mode_extension * 4;
- }
-
- if (bound > sblimit)
- bound = sblimit;
-
- start = stream->ptr;
-
- /* decode bit allocations */
-
- for (sb = 0; sb < bound; ++sb) {
- nbal = bitalloc_table[offsets[sb]].nbal;
-
- for (ch = 0; ch < nch; ++ch)
- allocation[ch][sb] = mad_bit_read(&stream->ptr, nbal);
- }
-
- for (sb = bound; sb < sblimit; ++sb) {
- nbal = bitalloc_table[offsets[sb]].nbal;
-
- allocation[0][sb] =
- allocation[1][sb] = mad_bit_read(&stream->ptr, nbal);
- }
-
- /* decode scalefactor selection info */
-
- for (sb = 0; sb < sblimit; ++sb) {
- for (ch = 0; ch < nch; ++ch) {
- if (allocation[ch][sb])
- scfsi[ch][sb] = mad_bit_read(&stream->ptr, 2);
- }
- }
-
- /* check CRC word */
-
- if (header->flags & MAD_FLAG_PROTECTION) {
- header->crc_check =
- mad_bit_crc(start, mad_bit_length(&start, &stream->ptr),
- header->crc_check);
-
- if (header->crc_check != header->crc_target &&
- !(frame->options & MAD_OPTION_IGNORECRC)) {
- stream->error = MAD_ERROR_BADCRC;
- return -1;
- }
- }
-
- /* decode scalefactors */
-
- for (sb = 0; sb < sblimit; ++sb) {
- for (ch = 0; ch < nch; ++ch) {
- if (allocation[ch][sb]) {
- scalefactor[ch][sb][0] = mad_bit_read(&stream->ptr, 6);
-
- switch (scfsi[ch][sb]) {
- case 2:
- scalefactor[ch][sb][2] =
- scalefactor[ch][sb][1] =
- scalefactor[ch][sb][0];
- break;
-
- case 0:
- scalefactor[ch][sb][1] = mad_bit_read(&stream->ptr, 6);
- /* fall through */
-
- case 1:
- case 3:
- scalefactor[ch][sb][2] = mad_bit_read(&stream->ptr, 6);
- }
-
- if (scfsi[ch][sb] & 1)
- scalefactor[ch][sb][1] = scalefactor[ch][sb][scfsi[ch][sb] - 1];
-
-# if defined(OPT_STRICT)
- /*
- * Scalefactor index 63 does not appear in Table B.1 of
- * ISO/IEC 11172-3. Nonetheless, other implementations accept it,
- * so we only reject it if OPT_STRICT is defined.
- */
- if (scalefactor[ch][sb][0] == 63 ||
- scalefactor[ch][sb][1] == 63 ||
- scalefactor[ch][sb][2] == 63) {
- stream->error = MAD_ERROR_BADSCALEFACTOR;
- return -1;
- }
-# endif
- }
- }
- }
-
- /* decode samples */
-
- for (gr = 0; gr < 12; ++gr) {
- for (sb = 0; sb < bound; ++sb) {
- for (ch = 0; ch < nch; ++ch) {
- if ((index = allocation[ch][sb])) {
- index = offset_table[bitalloc_table[offsets[sb]].offset][index - 1];
-
- II_samples(&stream->ptr, &qc_table[index], samples);
-
- for (s = 0; s < 3; ++s) {
- frame->sbsample[ch][3 * gr + s][sb] =
- mad_f_mul(samples[s], sf_table[scalefactor[ch][sb][gr / 4]]);
- }
- }
- else {
- for (s = 0; s < 3; ++s)
- frame->sbsample[ch][3 * gr + s][sb] = 0;
- }
- }
- }
-
- for (sb = bound; sb < sblimit; ++sb) {
- if ((index = allocation[0][sb])) {
- index = offset_table[bitalloc_table[offsets[sb]].offset][index - 1];
-
- II_samples(&stream->ptr, &qc_table[index], samples);
-
- for (ch = 0; ch < nch; ++ch) {
- for (s = 0; s < 3; ++s) {
- frame->sbsample[ch][3 * gr + s][sb] =
- mad_f_mul(samples[s], sf_table[scalefactor[ch][sb][gr / 4]]);
- }
- }
- }
- else {
- for (ch = 0; ch < nch; ++ch) {
- for (s = 0; s < 3; ++s)
- frame->sbsample[ch][3 * gr + s][sb] = 0;
- }
- }
- }
-
- for (ch = 0; ch < nch; ++ch) {
- for (s = 0; s < 3; ++s) {
- for (sb = sblimit; sb < 32; ++sb)
- frame->sbsample[ch][3 * gr + s][sb] = 0;
- }
- }
- }
-
- return 0;
-}
diff --git a/src/libmad/layer12.h b/src/libmad/layer12.h
deleted file mode 100644
index 645bb6405..000000000
--- a/src/libmad/layer12.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * libmad - MPEG audio decoder library
- * Copyright (C) 2000-2004 Underbit Technologies, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: layer12.h,v 1.3 2004/04/22 00:22:49 miguelfreitas Exp $
- */
-
-# ifndef LIBMAD_LAYER12_H
-# define LIBMAD_LAYER12_H
-
-# include "stream.h"
-# include "frame.h"
-
-int mad_layer_I(struct mad_stream *, struct mad_frame *);
-int mad_layer_II(struct mad_stream *, struct mad_frame *);
-
-# endif
diff --git a/src/libmad/layer3.c b/src/libmad/layer3.c
deleted file mode 100644
index c5d46e8d1..000000000
--- a/src/libmad/layer3.c
+++ /dev/null
@@ -1,2698 +0,0 @@
-/*
- * libmad - MPEG audio decoder library
- * Copyright (C) 2000-2004 Underbit Technologies, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: layer3.c,v 1.7 2006/09/26 00:12:20 dgp85 Exp $
- */
-
-# ifdef HAVE_CONFIG_H
-# include "config.h"
-# endif
-
-# include "global.h"
-
-# include <stdlib.h>
-# include <string.h>
-
-# ifdef HAVE_ASSERT_H
-# include <assert.h>
-# endif
-
-# ifdef HAVE_LIMITS_H
-# include <limits.h>
-# else
-# define CHAR_BIT 8
-# endif
-
-# include "fixed.h"
-# include "bit.h"
-# include "stream.h"
-# include "frame.h"
-# include "huffman.h"
-# include "layer3.h"
-
-/* --- Layer III ----------------------------------------------------------- */
-
-enum {
- count1table_select = 0x01,
- scalefac_scale = 0x02,
- preflag = 0x04,
- mixed_block_flag = 0x08
-};
-
-enum {
- I_STEREO = 0x1,
- MS_STEREO = 0x2
-};
-
-struct sideinfo {
- unsigned int main_data_begin;
- unsigned int private_bits;
-
- unsigned char scfsi[2];
-
- struct granule {
- struct channel {
- /* from side info */
- unsigned short part2_3_length;
- unsigned short big_values;
- unsigned short global_gain;
- unsigned short scalefac_compress;
-
- unsigned char flags;
- unsigned char block_type;
- unsigned char table_select[3];
- unsigned char subblock_gain[3];
- unsigned char region0_count;
- unsigned char region1_count;
-
- /* from main_data */
- unsigned char scalefac[39]; /* scalefac_l and/or scalefac_s */
- } ch[2];
- } gr[2];
-};
-
-/*
- * scalefactor bit lengths
- * derived from section 2.4.2.7 of ISO/IEC 11172-3
- */
-static
-struct {
- unsigned char slen1;
- unsigned char slen2;
-} const sflen_table[16] = {
- { 0, 0 }, { 0, 1 }, { 0, 2 }, { 0, 3 },
- { 3, 0 }, { 1, 1 }, { 1, 2 }, { 1, 3 },
- { 2, 1 }, { 2, 2 }, { 2, 3 }, { 3, 1 },
- { 3, 2 }, { 3, 3 }, { 4, 2 }, { 4, 3 }
-};
-
-/*
- * number of LSF scalefactor band values
- * derived from section 2.4.3.2 of ISO/IEC 13818-3
- */
-static
-unsigned char const nsfb_table[6][3][4] = {
- { { 6, 5, 5, 5 },
- { 9, 9, 9, 9 },
- { 6, 9, 9, 9 } },
-
- { { 6, 5, 7, 3 },
- { 9, 9, 12, 6 },
- { 6, 9, 12, 6 } },
-
- { { 11, 10, 0, 0 },
- { 18, 18, 0, 0 },
- { 15, 18, 0, 0 } },
-
- { { 7, 7, 7, 0 },
- { 12, 12, 12, 0 },
- { 6, 15, 12, 0 } },
-
- { { 6, 6, 6, 3 },
- { 12, 9, 9, 6 },
- { 6, 12, 9, 6 } },
-
- { { 8, 8, 5, 0 },
- { 15, 12, 9, 0 },
- { 6, 18, 9, 0 } }
-};
-
-/*
- * MPEG-1 scalefactor band widths
- * derived from Table B.8 of ISO/IEC 11172-3
- */
-static
-unsigned char const sfb_48000_long[] = {
- 4, 4, 4, 4, 4, 4, 6, 6, 6, 8, 10,
- 12, 16, 18, 22, 28, 34, 40, 46, 54, 54, 192
-};
-
-static
-unsigned char const sfb_44100_long[] = {
- 4, 4, 4, 4, 4, 4, 6, 6, 8, 8, 10,
- 12, 16, 20, 24, 28, 34, 42, 50, 54, 76, 158
-};
-
-static
-unsigned char const sfb_32000_long[] = {
- 4, 4, 4, 4, 4, 4, 6, 6, 8, 10, 12,
- 16, 20, 24, 30, 38, 46, 56, 68, 84, 102, 26
-};
-
-static
-unsigned char const sfb_48000_short[] = {
- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6,
- 6, 6, 6, 6, 6, 10, 10, 10, 12, 12, 12, 14, 14,
- 14, 16, 16, 16, 20, 20, 20, 26, 26, 26, 66, 66, 66
-};
-
-static
-unsigned char const sfb_44100_short[] = {
- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6,
- 6, 6, 8, 8, 8, 10, 10, 10, 12, 12, 12, 14, 14,
- 14, 18, 18, 18, 22, 22, 22, 30, 30, 30, 56, 56, 56
-};
-
-static
-unsigned char const sfb_32000_short[] = {
- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6,
- 6, 6, 8, 8, 8, 12, 12, 12, 16, 16, 16, 20, 20,
- 20, 26, 26, 26, 34, 34, 34, 42, 42, 42, 12, 12, 12
-};
-
-static
-unsigned char const sfb_48000_mixed[] = {
- /* long */ 4, 4, 4, 4, 4, 4, 6, 6,
- /* short */ 4, 4, 4, 6, 6, 6, 6, 6, 6, 10,
- 10, 10, 12, 12, 12, 14, 14, 14, 16, 16,
- 16, 20, 20, 20, 26, 26, 26, 66, 66, 66
-};
-
-static
-unsigned char const sfb_44100_mixed[] = {
- /* long */ 4, 4, 4, 4, 4, 4, 6, 6,
- /* short */ 4, 4, 4, 6, 6, 6, 8, 8, 8, 10,
- 10, 10, 12, 12, 12, 14, 14, 14, 18, 18,
- 18, 22, 22, 22, 30, 30, 30, 56, 56, 56
-};
-
-static
-unsigned char const sfb_32000_mixed[] = {
- /* long */ 4, 4, 4, 4, 4, 4, 6, 6,
- /* short */ 4, 4, 4, 6, 6, 6, 8, 8, 8, 12,
- 12, 12, 16, 16, 16, 20, 20, 20, 26, 26,
- 26, 34, 34, 34, 42, 42, 42, 12, 12, 12
-};
-
-/*
- * MPEG-2 scalefactor band widths
- * derived from Table B.2 of ISO/IEC 13818-3
- */
-static
-unsigned char const sfb_24000_long[] = {
- 6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16,
- 18, 22, 26, 32, 38, 46, 54, 62, 70, 76, 36
-};
-
-static
-unsigned char const sfb_22050_long[] = {
- 6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16,
- 20, 24, 28, 32, 38, 46, 52, 60, 68, 58, 54
-};
-
-# define sfb_16000_long sfb_22050_long
-
-static
-unsigned char const sfb_24000_short[] = {
- 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 8,
- 8, 8, 10, 10, 10, 12, 12, 12, 14, 14, 14, 18, 18,
- 18, 24, 24, 24, 32, 32, 32, 44, 44, 44, 12, 12, 12
-};
-
-static
-unsigned char const sfb_22050_short[] = {
- 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 6,
- 6, 6, 8, 8, 8, 10, 10, 10, 14, 14, 14, 18, 18,
- 18, 26, 26, 26, 32, 32, 32, 42, 42, 42, 18, 18, 18
-};
-
-static
-unsigned char const sfb_16000_short[] = {
- 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 8,
- 8, 8, 10, 10, 10, 12, 12, 12, 14, 14, 14, 18, 18,
- 18, 24, 24, 24, 30, 30, 30, 40, 40, 40, 18, 18, 18
-};
-
-static
-unsigned char const sfb_24000_mixed[] = {
- /* long */ 6, 6, 6, 6, 6, 6,
- /* short */ 6, 6, 6, 8, 8, 8, 10, 10, 10, 12,
- 12, 12, 14, 14, 14, 18, 18, 18, 24, 24,
- 24, 32, 32, 32, 44, 44, 44, 12, 12, 12
-};
-
-static
-unsigned char const sfb_22050_mixed[] = {
- /* long */ 6, 6, 6, 6, 6, 6,
- /* short */ 6, 6, 6, 6, 6, 6, 8, 8, 8, 10,
- 10, 10, 14, 14, 14, 18, 18, 18, 26, 26,
- 26, 32, 32, 32, 42, 42, 42, 18, 18, 18
-};
-
-static
-unsigned char const sfb_16000_mixed[] = {
- /* long */ 6, 6, 6, 6, 6, 6,
- /* short */ 6, 6, 6, 8, 8, 8, 10, 10, 10, 12,
- 12, 12, 14, 14, 14, 18, 18, 18, 24, 24,
- 24, 30, 30, 30, 40, 40, 40, 18, 18, 18
-};
-
-/*
- * MPEG 2.5 scalefactor band widths
- * derived from public sources
- */
-# define sfb_12000_long sfb_16000_long
-# define sfb_11025_long sfb_12000_long
-
-static
-unsigned char const sfb_8000_long[] = {
- 12, 12, 12, 12, 12, 12, 16, 20, 24, 28, 32,
- 40, 48, 56, 64, 76, 90, 2, 2, 2, 2, 2
-};
-
-# define sfb_12000_short sfb_16000_short
-# define sfb_11025_short sfb_12000_short
-
-static
-unsigned char const sfb_8000_short[] = {
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 12, 12, 12, 16,
- 16, 16, 20, 20, 20, 24, 24, 24, 28, 28, 28, 36, 36,
- 36, 2, 2, 2, 2, 2, 2, 2, 2, 2, 26, 26, 26
-};
-
-# define sfb_12000_mixed sfb_16000_mixed
-# define sfb_11025_mixed sfb_12000_mixed
-
-/* the 8000 Hz short block scalefactor bands do not break after
- the first 36 frequency lines, so this is probably wrong */
-static
-unsigned char const sfb_8000_mixed[] = {
- /* long */ 12, 12, 12,
- /* short */ 4, 4, 4, 8, 8, 8, 12, 12, 12, 16, 16, 16,
- 20, 20, 20, 24, 24, 24, 28, 28, 28, 36, 36, 36,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 26, 26, 26
-};
-
-static
-struct {
- unsigned char const *l;
- unsigned char const *s;
- unsigned char const *m;
-} const sfbwidth_table[9] = {
- { sfb_48000_long, sfb_48000_short, sfb_48000_mixed },
- { sfb_44100_long, sfb_44100_short, sfb_44100_mixed },
- { sfb_32000_long, sfb_32000_short, sfb_32000_mixed },
- { sfb_24000_long, sfb_24000_short, sfb_24000_mixed },
- { sfb_22050_long, sfb_22050_short, sfb_22050_mixed },
- { sfb_16000_long, sfb_16000_short, sfb_16000_mixed },
- { sfb_12000_long, sfb_12000_short, sfb_12000_mixed },
- { sfb_11025_long, sfb_11025_short, sfb_11025_mixed },
- { sfb_8000_long, sfb_8000_short, sfb_8000_mixed }
-};
-
-/*
- * scalefactor band preemphasis (used only when preflag is set)
- * derived from Table B.6 of ISO/IEC 11172-3
- */
-static
-unsigned char const pretab[22] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 2, 0
-};
-
-/*
- * table for requantization
- *
- * rq_table[x].mantissa * 2^(rq_table[x].exponent) = x^(4/3)
- */
-static
-struct fixedfloat {
- unsigned long mantissa : 27;
- unsigned short exponent : 5;
-} const rq_table[8207] = {
-# include "rq_table.dat"
-};
-
-/*
- * fractional powers of two
- * used for requantization and joint stereo decoding
- *
- * root_table[3 + x] = 2^(x/4)
- */
-static
-mad_fixed_t const root_table[7] = {
- MAD_F(0x09837f05) /* 2^(-3/4) == 0.59460355750136 */,
- MAD_F(0x0b504f33) /* 2^(-2/4) == 0.70710678118655 */,
- MAD_F(0x0d744fcd) /* 2^(-1/4) == 0.84089641525371 */,
- MAD_F(0x10000000) /* 2^( 0/4) == 1.00000000000000 */,
- MAD_F(0x1306fe0a) /* 2^(+1/4) == 1.18920711500272 */,
- MAD_F(0x16a09e66) /* 2^(+2/4) == 1.41421356237310 */,
- MAD_F(0x1ae89f99) /* 2^(+3/4) == 1.68179283050743 */
-};
-
-/*
- * coefficients for aliasing reduction
- * derived from Table B.9 of ISO/IEC 11172-3
- *
- * c[] = { -0.6, -0.535, -0.33, -0.185, -0.095, -0.041, -0.0142, -0.0037 }
- * cs[i] = 1 / sqrt(1 + c[i]^2)
- * ca[i] = c[i] / sqrt(1 + c[i]^2)
- */
-static
-mad_fixed_t const cs[8] = {
- +MAD_F(0x0db84a81) /* +0.857492926 */, +MAD_F(0x0e1b9d7f) /* +0.881741997 */,
- +MAD_F(0x0f31adcf) /* +0.949628649 */, +MAD_F(0x0fbba815) /* +0.983314592 */,
- +MAD_F(0x0feda417) /* +0.995517816 */, +MAD_F(0x0ffc8fc8) /* +0.999160558 */,
- +MAD_F(0x0fff964c) /* +0.999899195 */, +MAD_F(0x0ffff8d3) /* +0.999993155 */
-};
-
-static
-mad_fixed_t const ca[8] = {
- -MAD_F(0x083b5fe7) /* -0.514495755 */, -MAD_F(0x078c36d2) /* -0.471731969 */,
- -MAD_F(0x05039814) /* -0.313377454 */, -MAD_F(0x02e91dd1) /* -0.181913200 */,
- -MAD_F(0x0183603a) /* -0.094574193 */, -MAD_F(0x00a7cb87) /* -0.040965583 */,
- -MAD_F(0x003a2847) /* -0.014198569 */, -MAD_F(0x000f27b4) /* -0.003699975 */
-};
-
-/*
- * IMDCT coefficients for short blocks
- * derived from section 2.4.3.4.10.2 of ISO/IEC 11172-3
- *
- * imdct_s[i/even][k] = cos((PI / 24) * (2 * (i / 2) + 7) * (2 * k + 1))
- * imdct_s[i /odd][k] = cos((PI / 24) * (2 * (6 + (i-1)/2) + 7) * (2 * k + 1))
- */
-static
-mad_fixed_t const imdct_s[6][6] = {
-# include "imdct_s.dat"
-};
-
-# if !defined(ASO_IMDCT)
-/*
- * windowing coefficients for long blocks
- * derived from section 2.4.3.4.10.3 of ISO/IEC 11172-3
- *
- * window_l[i] = sin((PI / 36) * (i + 1/2))
- */
-static
-mad_fixed_t const window_l[36] = {
- MAD_F(0x00b2aa3e) /* 0.043619387 */, MAD_F(0x0216a2a2) /* 0.130526192 */,
- MAD_F(0x03768962) /* 0.216439614 */, MAD_F(0x04cfb0e2) /* 0.300705800 */,
- MAD_F(0x061f78aa) /* 0.382683432 */, MAD_F(0x07635284) /* 0.461748613 */,
- MAD_F(0x0898c779) /* 0.537299608 */, MAD_F(0x09bd7ca0) /* 0.608761429 */,
- MAD_F(0x0acf37ad) /* 0.675590208 */, MAD_F(0x0bcbe352) /* 0.737277337 */,
- MAD_F(0x0cb19346) /* 0.793353340 */, MAD_F(0x0d7e8807) /* 0.843391446 */,
-
- MAD_F(0x0e313245) /* 0.887010833 */, MAD_F(0x0ec835e8) /* 0.923879533 */,
- MAD_F(0x0f426cb5) /* 0.953716951 */, MAD_F(0x0f9ee890) /* 0.976296007 */,
- MAD_F(0x0fdcf549) /* 0.991444861 */, MAD_F(0x0ffc19fd) /* 0.999048222 */,
- MAD_F(0x0ffc19fd) /* 0.999048222 */, MAD_F(0x0fdcf549) /* 0.991444861 */,
- MAD_F(0x0f9ee890) /* 0.976296007 */, MAD_F(0x0f426cb5) /* 0.953716951 */,
- MAD_F(0x0ec835e8) /* 0.923879533 */, MAD_F(0x0e313245) /* 0.887010833 */,
-
- MAD_F(0x0d7e8807) /* 0.843391446 */, MAD_F(0x0cb19346) /* 0.793353340 */,
- MAD_F(0x0bcbe352) /* 0.737277337 */, MAD_F(0x0acf37ad) /* 0.675590208 */,
- MAD_F(0x09bd7ca0) /* 0.608761429 */, MAD_F(0x0898c779) /* 0.537299608 */,
- MAD_F(0x07635284) /* 0.461748613 */, MAD_F(0x061f78aa) /* 0.382683432 */,
- MAD_F(0x04cfb0e2) /* 0.300705800 */, MAD_F(0x03768962) /* 0.216439614 */,
- MAD_F(0x0216a2a2) /* 0.130526192 */, MAD_F(0x00b2aa3e) /* 0.043619387 */,
-};
-# endif /* ASO_IMDCT */
-
-/*
- * windowing coefficients for short blocks
- * derived from section 2.4.3.4.10.3 of ISO/IEC 11172-3
- *
- * window_s[i] = sin((PI / 12) * (i + 1/2))
- */
-static
-mad_fixed_t const window_s[12] = {
- MAD_F(0x0216a2a2) /* 0.130526192 */, MAD_F(0x061f78aa) /* 0.382683432 */,
- MAD_F(0x09bd7ca0) /* 0.608761429 */, MAD_F(0x0cb19346) /* 0.793353340 */,
- MAD_F(0x0ec835e8) /* 0.923879533 */, MAD_F(0x0fdcf549) /* 0.991444861 */,
- MAD_F(0x0fdcf549) /* 0.991444861 */, MAD_F(0x0ec835e8) /* 0.923879533 */,
- MAD_F(0x0cb19346) /* 0.793353340 */, MAD_F(0x09bd7ca0) /* 0.608761429 */,
- MAD_F(0x061f78aa) /* 0.382683432 */, MAD_F(0x0216a2a2) /* 0.130526192 */,
-};
-
-/*
- * coefficients for intensity stereo processing
- * derived from section 2.4.3.4.9.3 of ISO/IEC 11172-3
- *
- * is_ratio[i] = tan(i * (PI / 12))
- * is_table[i] = is_ratio[i] / (1 + is_ratio[i])
- */
-static
-mad_fixed_t const is_table[7] = {
- MAD_F(0x00000000) /* 0.000000000 */,
- MAD_F(0x0361962f) /* 0.211324865 */,
- MAD_F(0x05db3d74) /* 0.366025404 */,
- MAD_F(0x08000000) /* 0.500000000 */,
- MAD_F(0x0a24c28c) /* 0.633974596 */,
- MAD_F(0x0c9e69d1) /* 0.788675135 */,
- MAD_F(0x10000000) /* 1.000000000 */
-};
-
-/*
- * coefficients for LSF intensity stereo processing
- * derived from section 2.4.3.2 of ISO/IEC 13818-3
- *
- * is_lsf_table[0][i] = (1 / sqrt(sqrt(2)))^(i + 1)
- * is_lsf_table[1][i] = (1 / sqrt(2)) ^(i + 1)
- */
-static
-mad_fixed_t const is_lsf_table[2][15] = {
- {
- MAD_F(0x0d744fcd) /* 0.840896415 */,
- MAD_F(0x0b504f33) /* 0.707106781 */,
- MAD_F(0x09837f05) /* 0.594603558 */,
- MAD_F(0x08000000) /* 0.500000000 */,
- MAD_F(0x06ba27e6) /* 0.420448208 */,
- MAD_F(0x05a8279a) /* 0.353553391 */,
- MAD_F(0x04c1bf83) /* 0.297301779 */,
- MAD_F(0x04000000) /* 0.250000000 */,
- MAD_F(0x035d13f3) /* 0.210224104 */,
- MAD_F(0x02d413cd) /* 0.176776695 */,
- MAD_F(0x0260dfc1) /* 0.148650889 */,
- MAD_F(0x02000000) /* 0.125000000 */,
- MAD_F(0x01ae89fa) /* 0.105112052 */,
- MAD_F(0x016a09e6) /* 0.088388348 */,
- MAD_F(0x01306fe1) /* 0.074325445 */
- }, {
- MAD_F(0x0b504f33) /* 0.707106781 */,
- MAD_F(0x08000000) /* 0.500000000 */,
- MAD_F(0x05a8279a) /* 0.353553391 */,
- MAD_F(0x04000000) /* 0.250000000 */,
- MAD_F(0x02d413cd) /* 0.176776695 */,
- MAD_F(0x02000000) /* 0.125000000 */,
- MAD_F(0x016a09e6) /* 0.088388348 */,
- MAD_F(0x01000000) /* 0.062500000 */,
- MAD_F(0x00b504f3) /* 0.044194174 */,
- MAD_F(0x00800000) /* 0.031250000 */,
- MAD_F(0x005a827a) /* 0.022097087 */,
- MAD_F(0x00400000) /* 0.015625000 */,
- MAD_F(0x002d413d) /* 0.011048543 */,
- MAD_F(0x00200000) /* 0.007812500 */,
- MAD_F(0x0016a09e) /* 0.005524272 */
- }
-};
-
-/*
- * NAME: III_sideinfo()
- * DESCRIPTION: decode frame side information from a bitstream
- */
-static
-enum mad_error III_sideinfo(struct mad_bitptr *ptr, unsigned int nch,
- int lsf, struct sideinfo *si,
- unsigned int *data_bitlen,
- unsigned int *priv_bitlen)
-{
- unsigned int ngr, gr, ch, i;
- enum mad_error result = MAD_ERROR_NONE;
-
- *data_bitlen = 0;
- *priv_bitlen = lsf ? ((nch == 1) ? 1 : 2) : ((nch == 1) ? 5 : 3);
-
- si->main_data_begin = mad_bit_read(ptr, lsf ? 8 : 9);
- si->private_bits = mad_bit_read(ptr, *priv_bitlen);
-
- ngr = 1;
- if (!lsf) {
- ngr = 2;
-
- for (ch = 0; ch < nch; ++ch)
- si->scfsi[ch] = mad_bit_read(ptr, 4);
- }
-
- for (gr = 0; gr < ngr; ++gr) {
- struct granule *granule = &si->gr[gr];
-
- for (ch = 0; ch < nch; ++ch) {
- struct channel *channel = &granule->ch[ch];
-
- channel->part2_3_length = mad_bit_read(ptr, 12);
- channel->big_values = mad_bit_read(ptr, 9);
- channel->global_gain = mad_bit_read(ptr, 8);
- channel->scalefac_compress = mad_bit_read(ptr, lsf ? 9 : 4);
-
- *data_bitlen += channel->part2_3_length;
-
- if (channel->big_values > 288 && result == 0)
- result = MAD_ERROR_BADBIGVALUES;
-
- channel->flags = 0;
-
- /* window_switching_flag */
- if (mad_bit_read(ptr, 1)) {
- channel->block_type = mad_bit_read(ptr, 2);
-
- if (channel->block_type == 0 && result == 0)
- result = MAD_ERROR_BADBLOCKTYPE;
-
- if (!lsf && channel->block_type == 2 && si->scfsi[ch] && result == 0)
- result = MAD_ERROR_BADSCFSI;
-
- channel->region0_count = 7;
- channel->region1_count = 36;
-
- if (mad_bit_read(ptr, 1))
- channel->flags |= mixed_block_flag;
- else if (channel->block_type == 2)
- channel->region0_count = 8;
-
- for (i = 0; i < 2; ++i)
- channel->table_select[i] = mad_bit_read(ptr, 5);
-
-# if defined(DEBUG)
- channel->table_select[2] = 4; /* not used */
-# endif
-
- for (i = 0; i < 3; ++i)
- channel->subblock_gain[i] = mad_bit_read(ptr, 3);
- }
- else {
- channel->block_type = 0;
-
- for (i = 0; i < 3; ++i)
- channel->table_select[i] = mad_bit_read(ptr, 5);
-
- channel->region0_count = mad_bit_read(ptr, 4);
- channel->region1_count = mad_bit_read(ptr, 3);
- }
-
- /* [preflag,] scalefac_scale, count1table_select */
- channel->flags |= mad_bit_read(ptr, lsf ? 2 : 3);
- }
- }
-
- return result;
-}
-
-/*
- * NAME: III_scalefactors_lsf()
- * DESCRIPTION: decode channel scalefactors for LSF from a bitstream
- */
-static
-unsigned int III_scalefactors_lsf(struct mad_bitptr *ptr,
- struct channel *channel,
- struct channel *gr1ch, int mode_extension)
-{
- struct mad_bitptr start;
- unsigned int scalefac_compress, index, slen[4], part, n, i;
- unsigned char const *nsfb;
-
- start = *ptr;
-
- scalefac_compress = channel->scalefac_compress;
- index = (channel->block_type == 2) ?
- ((channel->flags & mixed_block_flag) ? 2 : 1) : 0;
-
- if (!((mode_extension & I_STEREO) && gr1ch)) {
- if (scalefac_compress < 400) {
- slen[0] = (scalefac_compress >> 4) / 5;
- slen[1] = (scalefac_compress >> 4) % 5;
- slen[2] = (scalefac_compress % 16) >> 2;
- slen[3] = scalefac_compress % 4;
-
- nsfb = nsfb_table[0][index];
- }
- else if (scalefac_compress < 500) {
- scalefac_compress -= 400;
-
- slen[0] = (scalefac_compress >> 2) / 5;
- slen[1] = (scalefac_compress >> 2) % 5;
- slen[2] = scalefac_compress % 4;
- slen[3] = 0;
-
- nsfb = nsfb_table[1][index];
- }
- else {
- scalefac_compress -= 500;
-
- slen[0] = scalefac_compress / 3;
- slen[1] = scalefac_compress % 3;
- slen[2] = 0;
- slen[3] = 0;
-
- channel->flags |= preflag;
-
- nsfb = nsfb_table[2][index];
- }
-
- n = 0;
- for (part = 0; part < 4; ++part) {
- for (i = 0; i < nsfb[part]; ++i)
- channel->scalefac[n++] = mad_bit_read(ptr, slen[part]);
- }
-
- while (n < 39)
- channel->scalefac[n++] = 0;
- }
- else { /* (mode_extension & I_STEREO) && gr1ch (i.e. ch == 1) */
- scalefac_compress >>= 1;
-
- if (scalefac_compress < 180) {
- slen[0] = scalefac_compress / 36;
- slen[1] = (scalefac_compress % 36) / 6;
- slen[2] = (scalefac_compress % 36) % 6;
- slen[3] = 0;
-
- nsfb = nsfb_table[3][index];
- }
- else if (scalefac_compress < 244) {
- scalefac_compress -= 180;
-
- slen[0] = (scalefac_compress % 64) >> 4;
- slen[1] = (scalefac_compress % 16) >> 2;
- slen[2] = scalefac_compress % 4;
- slen[3] = 0;
-
- nsfb = nsfb_table[4][index];
- }
- else {
- scalefac_compress -= 244;
-
- slen[0] = scalefac_compress / 3;
- slen[1] = scalefac_compress % 3;
- slen[2] = 0;
- slen[3] = 0;
-
- nsfb = nsfb_table[5][index];
- }
-
- n = 0;
- for (part = 0; part < 4; ++part) {
- unsigned int max, is_pos;
-
- max = (1 << slen[part]) - 1;
-
- for (i = 0; i < nsfb[part]; ++i) {
- is_pos = mad_bit_read(ptr, slen[part]);
-
- channel->scalefac[n] = is_pos;
- gr1ch->scalefac[n++] = (is_pos == max);
- }
- }
-
- while (n < 39) {
- channel->scalefac[n] = 0;
- gr1ch->scalefac[n++] = 0; /* apparently not illegal */
- }
- }
-
- return mad_bit_length(&start, ptr);
-}
-
-/*
- * NAME: III_scalefactors()
- * DESCRIPTION: decode channel scalefactors of one granule from a bitstream
- */
-static
-unsigned int III_scalefactors(struct mad_bitptr *ptr, struct channel *channel,
- struct channel const *gr0ch, unsigned int scfsi)
-{
- struct mad_bitptr start;
- unsigned int slen1, slen2, sfbi;
-
- start = *ptr;
-
- slen1 = sflen_table[channel->scalefac_compress].slen1;
- slen2 = sflen_table[channel->scalefac_compress].slen2;
-
- if (channel->block_type == 2) {
- unsigned int nsfb;
-
- sfbi = 0;
-
- nsfb = (channel->flags & mixed_block_flag) ? 8 + 3 * 3 : 6 * 3;
- while (nsfb--)
- channel->scalefac[sfbi++] = mad_bit_read(ptr, slen1);
-
- nsfb = 6 * 3;
- while (nsfb--)
- channel->scalefac[sfbi++] = mad_bit_read(ptr, slen2);
-
- nsfb = 1 * 3;
- while (nsfb--)
- channel->scalefac[sfbi++] = 0;
- }
- else { /* channel->block_type != 2 */
- if (scfsi & 0x8) {
- for (sfbi = 0; sfbi < 6; ++sfbi)
- channel->scalefac[sfbi] = gr0ch->scalefac[sfbi];
- }
- else {
- for (sfbi = 0; sfbi < 6; ++sfbi)
- channel->scalefac[sfbi] = mad_bit_read(ptr, slen1);
- }
-
- if (scfsi & 0x4) {
- for (sfbi = 6; sfbi < 11; ++sfbi)
- channel->scalefac[sfbi] = gr0ch->scalefac[sfbi];
- }
- else {
- for (sfbi = 6; sfbi < 11; ++sfbi)
- channel->scalefac[sfbi] = mad_bit_read(ptr, slen1);
- }
-
- if (scfsi & 0x2) {
- for (sfbi = 11; sfbi < 16; ++sfbi)
- channel->scalefac[sfbi] = gr0ch->scalefac[sfbi];
- }
- else {
- for (sfbi = 11; sfbi < 16; ++sfbi)
- channel->scalefac[sfbi] = mad_bit_read(ptr, slen2);
- }
-
- if (scfsi & 0x1) {
- for (sfbi = 16; sfbi < 21; ++sfbi)
- channel->scalefac[sfbi] = gr0ch->scalefac[sfbi];
- }
- else {
- for (sfbi = 16; sfbi < 21; ++sfbi)
- channel->scalefac[sfbi] = mad_bit_read(ptr, slen2);
- }
-
- channel->scalefac[21] = 0;
- }
-
- return mad_bit_length(&start, ptr);
-}
-
-/*
- * The Layer III formula for requantization and scaling is defined by
- * section 2.4.3.4.7.1 of ISO/IEC 11172-3, as follows:
- *
- * long blocks:
- * xr[i] = sign(is[i]) * abs(is[i])^(4/3) *
- * 2^((1/4) * (global_gain - 210)) *
- * 2^-(scalefac_multiplier *
- * (scalefac_l[sfb] + preflag * pretab[sfb]))
- *
- * short blocks:
- * xr[i] = sign(is[i]) * abs(is[i])^(4/3) *
- * 2^((1/4) * (global_gain - 210 - 8 * subblock_gain[w])) *
- * 2^-(scalefac_multiplier * scalefac_s[sfb][w])
- *
- * where:
- * scalefac_multiplier = (scalefac_scale + 1) / 2
- *
- * The routines III_exponents() and III_requantize() facilitate this
- * calculation.
- */
-
-/*
- * NAME: III_exponents()
- * DESCRIPTION: calculate scalefactor exponents
- */
-static
-void III_exponents(struct channel const *channel,
- unsigned char const *sfbwidth, signed int exponents[39])
-{
- signed int gain;
- unsigned int scalefac_multiplier, sfbi;
-
- gain = (signed int) channel->global_gain - 210;
- scalefac_multiplier = (channel->flags & scalefac_scale) ? 2 : 1;
-
- if (channel->block_type == 2) {
- unsigned int l;
- signed int gain0, gain1, gain2;
-
- sfbi = l = 0;
-
- if (channel->flags & mixed_block_flag) {
- unsigned int premask;
-
- premask = (channel->flags & preflag) ? ~0 : 0;
-
- /* long block subbands 0-1 */
-
- while (l < 36) {
- exponents[sfbi] = gain -
- (signed int) ((channel->scalefac[sfbi] + (pretab[sfbi] & premask)) <<
- scalefac_multiplier);
-
- l += sfbwidth[sfbi++];
- }
- }
-
- /* this is probably wrong for 8000 Hz short/mixed blocks */
-
- gain0 = gain - 8 * (signed int) channel->subblock_gain[0];
- gain1 = gain - 8 * (signed int) channel->subblock_gain[1];
- gain2 = gain - 8 * (signed int) channel->subblock_gain[2];
-
- while (l < 576) {
- exponents[sfbi + 0] = gain0 -
- (signed int) (channel->scalefac[sfbi + 0] << scalefac_multiplier);
- exponents[sfbi + 1] = gain1 -
- (signed int) (channel->scalefac[sfbi + 1] << scalefac_multiplier);
- exponents[sfbi + 2] = gain2 -
- (signed int) (channel->scalefac[sfbi + 2] << scalefac_multiplier);
-
- l += 3 * sfbwidth[sfbi];
- sfbi += 3;
- }
- }
- else { /* channel->block_type != 2 */
- if (channel->flags & preflag) {
- for (sfbi = 0; sfbi < 22; ++sfbi) {
- exponents[sfbi] = gain -
- (signed int) ((channel->scalefac[sfbi] + pretab[sfbi]) <<
- scalefac_multiplier);
- }
- }
- else {
- for (sfbi = 0; sfbi < 22; ++sfbi) {
- exponents[sfbi] = gain -
- (signed int) (channel->scalefac[sfbi] << scalefac_multiplier);
- }
- }
- }
-}
-
-/*
- * NAME: III_requantize()
- * DESCRIPTION: requantize one (positive) value
- */
-static
-mad_fixed_t III_requantize(unsigned int value, signed int exp)
-{
- mad_fixed_t requantized;
- signed int frac;
- struct fixedfloat const *power;
-
- frac = exp % 4; /* assumes sign(frac) == sign(exp) */
- exp /= 4;
-
- power = &rq_table[value];
- requantized = power->mantissa;
- exp += power->exponent;
-
- if (exp < 0) {
- if (-exp >= sizeof(mad_fixed_t) * CHAR_BIT) {
- /* underflow */
- requantized = 0;
- }
- else {
- requantized += 1L << (-exp - 1);
- requantized >>= -exp;
- }
- }
- else {
- if (exp >= 5) {
- /* overflow */
-# if defined(DEBUG)
- fprintf(stderr, "requantize overflow (%f * 2^%d)\n",
- mad_f_todouble(requantized), exp);
-# endif
- requantized = MAD_F_MAX;
- }
- else
- requantized <<= exp;
- }
-
- return frac ? mad_f_mul(requantized, root_table[3 + frac]) : requantized;
-}
-
-/* we must take care that sz >= bits and sz < sizeof(long) lest bits == 0 */
-# define MASK(cache, sz, bits) \
- (((cache) >> ((sz) - (bits))) & ((1 << (bits)) - 1))
-# define MASK1BIT(cache, sz) \
- ((cache) & (1 << ((sz) - 1)))
-
-/*
- * NAME: III_huffdecode()
- * DESCRIPTION: decode Huffman code words of one channel of one granule
- */
-static
-enum mad_error III_huffdecode(struct mad_bitptr *ptr, mad_fixed_t xr[576],
- struct channel *channel,
- unsigned char const *sfbwidth,
- unsigned int part2_length)
-{
- signed int exponents[39], exp;
- signed int const *expptr;
- struct mad_bitptr peek;
- signed int bits_left, cachesz;
- register mad_fixed_t *xrptr;
- mad_fixed_t const *sfbound;
- register unsigned long bitcache;
-
- bits_left = (signed) channel->part2_3_length - (signed) part2_length;
- if (bits_left < 0)
- return MAD_ERROR_BADPART3LEN;
-
- III_exponents(channel, sfbwidth, exponents);
-
- peek = *ptr;
- mad_bit_skip(ptr, bits_left);
-
- /* align bit reads to byte boundaries */
- cachesz = mad_bit_bitsleft(&peek);
- cachesz += ((32 - 1 - 24) + (24 - cachesz)) & ~7;
-
- bitcache = mad_bit_read(&peek, cachesz);
- bits_left -= cachesz;
-
- xrptr = &xr[0];
-
- /* big_values */
- {
- unsigned int region, rcount;
- struct hufftable const *entry;
- union huffpair const *table;
- unsigned int linbits, startbits, big_values, reqhits;
- mad_fixed_t reqcache[16];
-
- sfbound = xrptr + *sfbwidth++;
- rcount = channel->region0_count + 1;
-
- entry = &mad_huff_pair_table[channel->table_select[region = 0]];
- table = entry->table;
- linbits = entry->linbits;
- startbits = entry->startbits;
-
- if (table == 0)
- return MAD_ERROR_BADHUFFTABLE;
-
- expptr = &exponents[0];
- exp = *expptr++;
- reqhits = 0;
-
- big_values = channel->big_values;
-
- while (big_values-- && cachesz + bits_left > 0) {
- union huffpair const *pair;
- unsigned int clumpsz, value;
- register mad_fixed_t requantized;
-
- if (xrptr == sfbound) {
- sfbound += *sfbwidth++;
-
- /* change table if region boundary */
-
- if (--rcount == 0) {
- if (region == 0)
- rcount = channel->region1_count + 1;
- else
- rcount = 0; /* all remaining */
-
- entry = &mad_huff_pair_table[channel->table_select[++region]];
- table = entry->table;
- linbits = entry->linbits;
- startbits = entry->startbits;
-
- if (table == 0)
- return MAD_ERROR_BADHUFFTABLE;
- }
-
- if (exp != *expptr) {
- exp = *expptr;
- reqhits = 0;
- }
-
- ++expptr;
- }
-
- if (cachesz < 21) {
- unsigned int bits;
-
- bits = ((32 - 1 - 21) + (21 - cachesz)) & ~7;
- bitcache = (bitcache << bits) | mad_bit_read(&peek, bits);
- cachesz += bits;
- bits_left -= bits;
- }
-
- /* hcod (0..19) */
-
- clumpsz = startbits;
- pair = &table[MASK(bitcache, cachesz, clumpsz)];
-
- while (!pair->final) {
- cachesz -= clumpsz;
-
- clumpsz = pair->ptr.bits;
- pair = &table[pair->ptr.offset + MASK(bitcache, cachesz, clumpsz)];
- }
-
- cachesz -= pair->value.hlen;
-
- if (linbits) {
- /* x (0..14) */
-
- value = pair->value.x;
-
- switch (value) {
- case 0:
- xrptr[0] = 0;
- break;
-
- case 15:
- if (cachesz < linbits + 2) {
- bitcache = (bitcache << 16) | mad_bit_read(&peek, 16);
- cachesz += 16;
- bits_left -= 16;
- }
-
- value += MASK(bitcache, cachesz, linbits);
- cachesz -= linbits;
-
- requantized = III_requantize(value, exp);
- goto x_final;
-
- default:
- if (reqhits & (1 << value))
- requantized = reqcache[value];
- else {
- reqhits |= (1 << value);
- requantized = reqcache[value] = III_requantize(value, exp);
- }
-
- x_final:
- xrptr[0] = MASK1BIT(bitcache, cachesz--) ?
- -requantized : requantized;
- }
-
- /* y (0..14) */
-
- value = pair->value.y;
-
- switch (value) {
- case 0:
- xrptr[1] = 0;
- break;
-
- case 15:
- if (cachesz < linbits + 1) {
- bitcache = (bitcache << 16) | mad_bit_read(&peek, 16);
- cachesz += 16;
- bits_left -= 16;
- }
-
- value += MASK(bitcache, cachesz, linbits);
- cachesz -= linbits;
-
- requantized = III_requantize(value, exp);
- goto y_final;
-
- default:
- if (reqhits & (1 << value))
- requantized = reqcache[value];
- else {
- reqhits |= (1 << value);
- requantized = reqcache[value] = III_requantize(value, exp);
- }
-
- y_final:
- xrptr[1] = MASK1BIT(bitcache, cachesz--) ?
- -requantized : requantized;
- }
- }
- else {
- /* x (0..1) */
-
- value = pair->value.x;
-
- if (value == 0)
- xrptr[0] = 0;
- else {
- if (reqhits & (1 << value))
- requantized = reqcache[value];
- else {
- reqhits |= (1 << value);
- requantized = reqcache[value] = III_requantize(value, exp);
- }
-
- xrptr[0] = MASK1BIT(bitcache, cachesz--) ?
- -requantized : requantized;
- }
-
- /* y (0..1) */
-
- value = pair->value.y;
-
- if (value == 0)
- xrptr[1] = 0;
- else {
- if (reqhits & (1 << value))
- requantized = reqcache[value];
- else {
- reqhits |= (1 << value);
- requantized = reqcache[value] = III_requantize(value, exp);
- }
-
- xrptr[1] = MASK1BIT(bitcache, cachesz--) ?
- -requantized : requantized;
- }
- }
-
- xrptr += 2;
- }
- }
-
- if (cachesz + bits_left < 0)
- return MAD_ERROR_BADHUFFDATA; /* big_values overrun */
-
- /* count1 */
- {
- union huffquad const *table;
- register mad_fixed_t requantized;
-
- table = mad_huff_quad_table[channel->flags & count1table_select];
-
- requantized = III_requantize(1, exp);
-
- while (cachesz + bits_left > 0 && xrptr <= &xr[572]) {
- union huffquad const *quad;
-
- /* hcod (1..6) */
-
- if (cachesz < 10) {
- bitcache = (bitcache << 16) | mad_bit_read(&peek, 16);
- cachesz += 16;
- bits_left -= 16;
- }
-
- quad = &table[MASK(bitcache, cachesz, 4)];
-
- /* quad tables guaranteed to have at most one extra lookup */
- if (!quad->final) {
- cachesz -= 4;
-
- quad = &table[quad->ptr.offset +
- MASK(bitcache, cachesz, quad->ptr.bits)];
- }
-
- cachesz -= quad->value.hlen;
-
- if (xrptr == sfbound) {
- sfbound += *sfbwidth++;
-
- if (exp != *expptr) {
- exp = *expptr;
- requantized = III_requantize(1, exp);
- }
-
- ++expptr;
- }
-
- /* v (0..1) */
-
- xrptr[0] = quad->value.v ?
- (MASK1BIT(bitcache, cachesz--) ? -requantized : requantized) : 0;
-
- /* w (0..1) */
-
- xrptr[1] = quad->value.w ?
- (MASK1BIT(bitcache, cachesz--) ? -requantized : requantized) : 0;
-
- xrptr += 2;
-
- if (xrptr == sfbound) {
- sfbound += *sfbwidth++;
-
- if (exp != *expptr) {
- exp = *expptr;
- requantized = III_requantize(1, exp);
- }
-
- ++expptr;
- }
-
- /* x (0..1) */
-
- xrptr[0] = quad->value.x ?
- (MASK1BIT(bitcache, cachesz--) ? -requantized : requantized) : 0;
-
- /* y (0..1) */
-
- xrptr[1] = quad->value.y ?
- (MASK1BIT(bitcache, cachesz--) ? -requantized : requantized) : 0;
-
- xrptr += 2;
- }
-
- if (cachesz + bits_left < 0) {
-# if 0 && defined(DEBUG)
- fprintf(stderr, "huffman count1 overrun (%d bits)\n",
- -(cachesz + bits_left));
-# endif
-
- /* technically the bitstream is misformatted, but apparently
- some encoders are just a bit sloppy with stuffing bits */
-
- xrptr -= 4;
- }
- }
-
- assert(-bits_left <= MAD_BUFFER_GUARD * CHAR_BIT);
-
-# if 0 && defined(DEBUG)
- if (bits_left < 0)
- fprintf(stderr, "read %d bits too many\n", -bits_left);
- else if (cachesz + bits_left > 0)
- fprintf(stderr, "%d stuffing bits\n", cachesz + bits_left);
-# endif
-
- /* rzero */
- while (xrptr < &xr[576]) {
- xrptr[0] = 0;
- xrptr[1] = 0;
-
- xrptr += 2;
- }
-
- return MAD_ERROR_NONE;
-}
-
-# undef MASK
-# undef MASK1BIT
-
-/*
- * NAME: III_reorder()
- * DESCRIPTION: reorder frequency lines of a short block into subband order
- */
-static
-void III_reorder(mad_fixed_t xr[576], struct channel const *channel,
- unsigned char const sfbwidth[39])
-{
- mad_fixed_t tmp[32][3][6];
- unsigned int sb, l, f, w, sbw[3], sw[3];
-
- /* this is probably wrong for 8000 Hz mixed blocks */
-
- sb = 0;
- if (channel->flags & mixed_block_flag) {
- sb = 2;
-
- l = 0;
- while (l < 36)
- l += *sfbwidth++;
- }
-
- for (w = 0; w < 3; ++w) {
- sbw[w] = sb;
- sw[w] = 0;
- }
-
- f = *sfbwidth++;
- w = 0;
-
- for (l = 18 * sb; l < 576; ++l) {
- if (f-- == 0) {
- f = *sfbwidth++ - 1;
- w = (w + 1) % 3;
- }
-
- tmp[sbw[w]][w][sw[w]++] = xr[l];
-
- if (sw[w] == 6) {
- sw[w] = 0;
- ++sbw[w];
- }
- }
-
- memcpy(&xr[18 * sb], &tmp[sb], (576 - 18 * sb) * sizeof(mad_fixed_t));
-}
-
-/*
- * NAME: III_stereo()
- * DESCRIPTION: perform joint stereo processing on a granule
- */
-static
-enum mad_error III_stereo(mad_fixed_t xr[2][576],
- struct granule const *granule,
- struct mad_header *header,
- unsigned char const *sfbwidth)
-{
- short modes[39];
- unsigned int sfbi, l, n, i;
-
- if (granule->ch[0].block_type !=
- granule->ch[1].block_type ||
- (granule->ch[0].flags & mixed_block_flag) !=
- (granule->ch[1].flags & mixed_block_flag))
- return MAD_ERROR_BADSTEREO;
-
- for (i = 0; i < 39; ++i)
- modes[i] = header->mode_extension;
-
- /* intensity stereo */
-
- if (header->mode_extension & I_STEREO) {
- struct channel const *right_ch = &granule->ch[1];
- mad_fixed_t const *right_xr = xr[1];
- unsigned int is_pos;
-
- header->flags |= MAD_FLAG_I_STEREO;
-
- /* first determine which scalefactor bands are to be processed */
-
- if (right_ch->block_type == 2) {
- unsigned int lower, start, max, bound[3], w;
-
- lower = start = max = bound[0] = bound[1] = bound[2] = 0;
-
- sfbi = l = 0;
-
- if (right_ch->flags & mixed_block_flag) {
- while (l < 36) {
- n = sfbwidth[sfbi++];
-
- for (i = 0; i < n; ++i) {
- if (right_xr[i]) {
- lower = sfbi;
- break;
- }
- }
-
- right_xr += n;
- l += n;
- }
-
- start = sfbi;
- }
-
- w = 0;
- while (l < 576) {
- n = sfbwidth[sfbi++];
-
- for (i = 0; i < n; ++i) {
- if (right_xr[i]) {
- max = bound[w] = sfbi;
- break;
- }
- }
-
- right_xr += n;
- l += n;
- w = (w + 1) % 3;
- }
-
- if (max)
- lower = start;
-
- /* long blocks */
-
- for (i = 0; i < lower; ++i)
- modes[i] = header->mode_extension & ~I_STEREO;
-
- /* short blocks */
-
- w = 0;
- for (i = start; i < max; ++i) {
- if (i < bound[w])
- modes[i] = header->mode_extension & ~I_STEREO;
-
- w = (w + 1) % 3;
- }
- }
- else { /* right_ch->block_type != 2 */
- unsigned int bound;
-
- bound = 0;
- for (sfbi = l = 0; l < 576; l += n) {
- n = sfbwidth[sfbi++];
-
- for (i = 0; i < n; ++i) {
- if (right_xr[i]) {
- bound = sfbi;
- break;
- }
- }
-
- right_xr += n;
- }
-
- for (i = 0; i < bound; ++i)
- modes[i] = header->mode_extension & ~I_STEREO;
- }
-
- /* now do the actual processing */
-
- if (header->flags & MAD_FLAG_LSF_EXT) {
- unsigned char const *illegal_pos = granule[1].ch[1].scalefac;
- mad_fixed_t const *lsf_scale;
-
- /* intensity_scale */
- lsf_scale = is_lsf_table[right_ch->scalefac_compress & 0x1];
-
- for (sfbi = l = 0; l < 576; ++sfbi, l += n) {
- n = sfbwidth[sfbi];
-
- if (!(modes[sfbi] & I_STEREO))
- continue;
-
- if (illegal_pos[sfbi]) {
- modes[sfbi] &= ~I_STEREO;
- continue;
- }
-
- is_pos = right_ch->scalefac[sfbi];
-
- for (i = 0; i < n; ++i) {
- register mad_fixed_t left;
-
- left = xr[0][l + i];
-
- if (is_pos == 0)
- xr[1][l + i] = left;
- else {
- register mad_fixed_t opposite;
-
- opposite = mad_f_mul(left, lsf_scale[(is_pos - 1) / 2]);
-
- if (is_pos & 1) {
- xr[0][l + i] = opposite;
- xr[1][l + i] = left;
- }
- else
- xr[1][l + i] = opposite;
- }
- }
- }
- }
- else { /* !(header->flags & MAD_FLAG_LSF_EXT) */
- for (sfbi = l = 0; l < 576; ++sfbi, l += n) {
- n = sfbwidth[sfbi];
-
- if (!(modes[sfbi] & I_STEREO))
- continue;
-
- is_pos = right_ch->scalefac[sfbi];
-
- if (is_pos >= 7) { /* illegal intensity position */
- modes[sfbi] &= ~I_STEREO;
- continue;
- }
-
- for (i = 0; i < n; ++i) {
- register mad_fixed_t left;
-
- left = xr[0][l + i];
-
- xr[0][l + i] = mad_f_mul(left, is_table[ is_pos]);
- xr[1][l + i] = mad_f_mul(left, is_table[6 - is_pos]);
- }
- }
- }
- }
-
- /* middle/side stereo */
-
- if (header->mode_extension & MS_STEREO) {
- register mad_fixed_t invsqrt2;
-
- header->flags |= MAD_FLAG_MS_STEREO;
-
- invsqrt2 = root_table[3 + -2];
-
- for (sfbi = l = 0; l < 576; ++sfbi, l += n) {
- n = sfbwidth[sfbi];
-
- if (modes[sfbi] != MS_STEREO)
- continue;
-
- for (i = 0; i < n; ++i) {
- register mad_fixed_t m, s;
-
- m = xr[0][l + i];
- s = xr[1][l + i];
-
- xr[0][l + i] = mad_f_mul(m + s, invsqrt2); /* l = (m + s) / sqrt(2) */
- xr[1][l + i] = mad_f_mul(m - s, invsqrt2); /* r = (m - s) / sqrt(2) */
- }
- }
- }
-
- return MAD_ERROR_NONE;
-}
-
-/*
- * NAME: III_aliasreduce()
- * DESCRIPTION: perform frequency line alias reduction
- */
-static
-void III_aliasreduce(mad_fixed_t xr[576], int lines)
-{
- mad_fixed_t const *bound;
- int i;
-
- bound = &xr[lines];
- for (xr += 18; xr < bound; xr += 18) {
- for (i = 0; i < 8; ++i) {
- register mad_fixed_t a, b;
- register mad_fixed64hi_t hi = 0;
- register mad_fixed64lo_t lo = 0;
-
- a = xr[-1 - i];
- b = xr[ i];
-
-# if defined(ASO_ZEROCHECK)
- if (a | b) {
-# endif
- MAD_F_ML0(hi, lo, a, cs[i]);
- MAD_F_MLA(hi, lo, -b, ca[i]);
-
- xr[-1 - i] = MAD_F_MLZ(hi, lo);
-
- MAD_F_ML0(hi, lo, b, cs[i]);
- MAD_F_MLA(hi, lo, a, ca[i]);
-
- xr[ i] = MAD_F_MLZ(hi, lo);
-# if defined(ASO_ZEROCHECK)
- }
-# endif
- }
- }
-}
-
-# if defined(ASO_IMDCT)
-void III_imdct_l(mad_fixed_t const [18], mad_fixed_t [36], unsigned int);
-# else
-# if 1
-static
-void fastsdct(mad_fixed_t const x[9], mad_fixed_t y[18])
-{
- mad_fixed_t a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12;
- mad_fixed_t a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25;
- mad_fixed_t m0, m1, m2, m3, m4, m5, m6, m7;
-
- enum {
- c0 = MAD_F(0x1f838b8d), /* 2 * cos( 1 * PI / 18) */
- c1 = MAD_F(0x1bb67ae8), /* 2 * cos( 3 * PI / 18) */
- c2 = MAD_F(0x18836fa3), /* 2 * cos( 4 * PI / 18) */
- c3 = MAD_F(0x1491b752), /* 2 * cos( 5 * PI / 18) */
- c4 = MAD_F(0x0af1d43a), /* 2 * cos( 7 * PI / 18) */
- c5 = MAD_F(0x058e86a0), /* 2 * cos( 8 * PI / 18) */
- c6 = -MAD_F(0x1e11f642) /* 2 * cos(16 * PI / 18) */
- };
-
- a0 = x[3] + x[5];
- a1 = x[3] - x[5];
- a2 = x[6] + x[2];
- a3 = x[6] - x[2];
- a4 = x[1] + x[7];
- a5 = x[1] - x[7];
- a6 = x[8] + x[0];
- a7 = x[8] - x[0];
-
- a8 = a0 + a2;
- a9 = a0 - a2;
- a10 = a0 - a6;
- a11 = a2 - a6;
- a12 = a8 + a6;
- a13 = a1 - a3;
- a14 = a13 + a7;
- a15 = a3 + a7;
- a16 = a1 - a7;
- a17 = a1 + a3;
-
- m0 = mad_f_mul(a17, -c3);
- m1 = mad_f_mul(a16, -c0);
- m2 = mad_f_mul(a15, -c4);
- m3 = mad_f_mul(a14, -c1);
- m4 = mad_f_mul(a5, -c1);
- m5 = mad_f_mul(a11, -c6);
- m6 = mad_f_mul(a10, -c5);
- m7 = mad_f_mul(a9, -c2);
-
- a18 = x[4] + a4;
- a19 = 2 * x[4] - a4;
- a20 = a19 + m5;
- a21 = a19 - m5;
- a22 = a19 + m6;
- a23 = m4 + m2;
- a24 = m4 - m2;
- a25 = m4 + m1;
-
- /* output to every other slot for convenience */
-
- y[ 0] = a18 + a12;
- y[ 2] = m0 - a25;
- y[ 4] = m7 - a20;
- y[ 6] = m3;
- y[ 8] = a21 - m6;
- y[10] = a24 - m1;
- y[12] = a12 - 2 * a18;
- y[14] = a23 + m0;
- y[16] = a22 + m7;
-}
-
-static inline
-void sdctII(mad_fixed_t const x[18], mad_fixed_t X[18])
-{
- mad_fixed_t tmp[9];
- int i;
-
- /* scale[i] = 2 * cos(PI * (2 * i + 1) / (2 * 18)) */
- static mad_fixed_t const scale[9] = {
- MAD_F(0x1fe0d3b4), MAD_F(0x1ee8dd47), MAD_F(0x1d007930),
- MAD_F(0x1a367e59), MAD_F(0x16a09e66), MAD_F(0x125abcf8),
- MAD_F(0x0d8616bc), MAD_F(0x08483ee1), MAD_F(0x02c9fad7)
- };
-
- /* divide the 18-point SDCT-II into two 9-point SDCT-IIs */
-
- /* even input butterfly */
-
- for (i = 0; i < 9; i += 3) {
- tmp[i + 0] = x[i + 0] + x[18 - (i + 0) - 1];
- tmp[i + 1] = x[i + 1] + x[18 - (i + 1) - 1];
- tmp[i + 2] = x[i + 2] + x[18 - (i + 2) - 1];
- }
-
- fastsdct(tmp, &X[0]);
-
- /* odd input butterfly and scaling */
-
- for (i = 0; i < 9; i += 3) {
- tmp[i + 0] = mad_f_mul(x[i + 0] - x[18 - (i + 0) - 1], scale[i + 0]);
- tmp[i + 1] = mad_f_mul(x[i + 1] - x[18 - (i + 1) - 1], scale[i + 1]);
- tmp[i + 2] = mad_f_mul(x[i + 2] - x[18 - (i + 2) - 1], scale[i + 2]);
- }
-
- fastsdct(tmp, &X[1]);
-
- /* output accumulation */
-
- for (i = 3; i < 18; i += 8) {
- X[i + 0] -= X[(i + 0) - 2];
- X[i + 2] -= X[(i + 2) - 2];
- X[i + 4] -= X[(i + 4) - 2];
- X[i + 6] -= X[(i + 6) - 2];
- }
-}
-
-static inline
-void dctIV(mad_fixed_t const y[18], mad_fixed_t X[18])
-{
- mad_fixed_t tmp[18];
- int i;
-
- /* scale[i] = 2 * cos(PI * (2 * i + 1) / (4 * 18)) */
- static mad_fixed_t const scale[18] = {
- MAD_F(0x1ff833fa), MAD_F(0x1fb9ea93), MAD_F(0x1f3dd120),
- MAD_F(0x1e84d969), MAD_F(0x1d906bcf), MAD_F(0x1c62648b),
- MAD_F(0x1afd100f), MAD_F(0x1963268b), MAD_F(0x1797c6a4),
- MAD_F(0x159e6f5b), MAD_F(0x137af940), MAD_F(0x11318ef3),
- MAD_F(0x0ec6a507), MAD_F(0x0c3ef153), MAD_F(0x099f61c5),
- MAD_F(0x06ed12c5), MAD_F(0x042d4544), MAD_F(0x0165547c)
- };
-
- /* scaling */
-
- for (i = 0; i < 18; i += 3) {
- tmp[i + 0] = mad_f_mul(y[i + 0], scale[i + 0]);
- tmp[i + 1] = mad_f_mul(y[i + 1], scale[i + 1]);
- tmp[i + 2] = mad_f_mul(y[i + 2], scale[i + 2]);
- }
-
- /* SDCT-II */
-
- sdctII(tmp, X);
-
- /* scale reduction and output accumulation */
-
- X[0] /= 2;
- for (i = 1; i < 17; i += 4) {
- X[i + 0] = X[i + 0] / 2 - X[(i + 0) - 1];
- X[i + 1] = X[i + 1] / 2 - X[(i + 1) - 1];
- X[i + 2] = X[i + 2] / 2 - X[(i + 2) - 1];
- X[i + 3] = X[i + 3] / 2 - X[(i + 3) - 1];
- }
- X[17] = X[17] / 2 - X[16];
-}
-
-/*
- * NAME: imdct36
- * DESCRIPTION: perform X[18]->x[36] IMDCT using Szu-Wei Lee's fast algorithm
- */
-static inline
-void imdct36(mad_fixed_t const x[18], mad_fixed_t y[36])
-{
- mad_fixed_t tmp[18];
- int i;
-
- /* DCT-IV */
-
- dctIV(x, tmp);
-
- /* convert 18-point DCT-IV to 36-point IMDCT */
-
- for (i = 0; i < 9; i += 3) {
- y[i + 0] = tmp[9 + (i + 0)];
- y[i + 1] = tmp[9 + (i + 1)];
- y[i + 2] = tmp[9 + (i + 2)];
- }
- for (i = 9; i < 27; i += 3) {
- y[i + 0] = -tmp[36 - (9 + (i + 0)) - 1];
- y[i + 1] = -tmp[36 - (9 + (i + 1)) - 1];
- y[i + 2] = -tmp[36 - (9 + (i + 2)) - 1];
- }
- for (i = 27; i < 36; i += 3) {
- y[i + 0] = -tmp[(i + 0) - 27];
- y[i + 1] = -tmp[(i + 1) - 27];
- y[i + 2] = -tmp[(i + 2) - 27];
- }
-}
-# else
-/*
- * NAME: imdct36
- * DESCRIPTION: perform X[18]->x[36] IMDCT
- */
-static inline
-void imdct36(mad_fixed_t const X[18], mad_fixed_t x[36])
-{
- mad_fixed_t t0, t1, t2, t3, t4, t5, t6, t7;
- mad_fixed_t t8, t9, t10, t11, t12, t13, t14, t15;
- register mad_fixed64hi_t hi;
- register mad_fixed64lo_t lo;
-
- MAD_F_ML0(hi, lo, X[4], MAD_F(0x0ec835e8));
- MAD_F_MLA(hi, lo, X[13], MAD_F(0x061f78aa));
-
- t6 = MAD_F_MLZ(hi, lo);
-
- MAD_F_MLA(hi, lo, (t14 = X[1] - X[10]), -MAD_F(0x061f78aa));
- MAD_F_MLA(hi, lo, (t15 = X[7] + X[16]), -MAD_F(0x0ec835e8));
-
- t0 = MAD_F_MLZ(hi, lo);
-
- MAD_F_MLA(hi, lo, (t8 = X[0] - X[11] - X[12]), MAD_F(0x0216a2a2));
- MAD_F_MLA(hi, lo, (t9 = X[2] - X[9] - X[14]), MAD_F(0x09bd7ca0));
- MAD_F_MLA(hi, lo, (t10 = X[3] - X[8] - X[15]), -MAD_F(0x0cb19346));
- MAD_F_MLA(hi, lo, (t11 = X[5] - X[6] - X[17]), -MAD_F(0x0fdcf549));
-
- x[7] = MAD_F_MLZ(hi, lo);
- x[10] = -x[7];
-
- MAD_F_ML0(hi, lo, t8, -MAD_F(0x0cb19346));
- MAD_F_MLA(hi, lo, t9, MAD_F(0x0fdcf549));
- MAD_F_MLA(hi, lo, t10, MAD_F(0x0216a2a2));
- MAD_F_MLA(hi, lo, t11, -MAD_F(0x09bd7ca0));
-
- x[19] = x[34] = MAD_F_MLZ(hi, lo) - t0;
-
- t12 = X[0] - X[3] + X[8] - X[11] - X[12] + X[15];
- t13 = X[2] + X[5] - X[6] - X[9] - X[14] - X[17];
-
- MAD_F_ML0(hi, lo, t12, -MAD_F(0x0ec835e8));
- MAD_F_MLA(hi, lo, t13, MAD_F(0x061f78aa));
-
- x[22] = x[31] = MAD_F_MLZ(hi, lo) + t0;
-
- MAD_F_ML0(hi, lo, X[1], -MAD_F(0x09bd7ca0));
- MAD_F_MLA(hi, lo, X[7], MAD_F(0x0216a2a2));
- MAD_F_MLA(hi, lo, X[10], -MAD_F(0x0fdcf549));
- MAD_F_MLA(hi, lo, X[16], MAD_F(0x0cb19346));
-
- t1 = MAD_F_MLZ(hi, lo) + t6;
-
- MAD_F_ML0(hi, lo, X[0], MAD_F(0x03768962));
- MAD_F_MLA(hi, lo, X[2], MAD_F(0x0e313245));
- MAD_F_MLA(hi, lo, X[3], -MAD_F(0x0ffc19fd));
- MAD_F_MLA(hi, lo, X[5], -MAD_F(0x0acf37ad));
- MAD_F_MLA(hi, lo, X[6], MAD_F(0x04cfb0e2));
- MAD_F_MLA(hi, lo, X[8], -MAD_F(0x0898c779));
- MAD_F_MLA(hi, lo, X[9], MAD_F(0x0d7e8807));
- MAD_F_MLA(hi, lo, X[11], MAD_F(0x0f426cb5));
- MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0bcbe352));
- MAD_F_MLA(hi, lo, X[14], MAD_F(0x00b2aa3e));
- MAD_F_MLA(hi, lo, X[15], -MAD_F(0x07635284));
- MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0f9ee890));
-
- x[6] = MAD_F_MLZ(hi, lo) + t1;
- x[11] = -x[6];
-
- MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0f426cb5));
- MAD_F_MLA(hi, lo, X[2], -MAD_F(0x00b2aa3e));
- MAD_F_MLA(hi, lo, X[3], MAD_F(0x0898c779));
- MAD_F_MLA(hi, lo, X[5], MAD_F(0x0f9ee890));
- MAD_F_MLA(hi, lo, X[6], MAD_F(0x0acf37ad));
- MAD_F_MLA(hi, lo, X[8], -MAD_F(0x07635284));
- MAD_F_MLA(hi, lo, X[9], -MAD_F(0x0e313245));
- MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0bcbe352));
- MAD_F_MLA(hi, lo, X[12], -MAD_F(0x03768962));
- MAD_F_MLA(hi, lo, X[14], MAD_F(0x0d7e8807));
- MAD_F_MLA(hi, lo, X[15], MAD_F(0x0ffc19fd));
- MAD_F_MLA(hi, lo, X[17], MAD_F(0x04cfb0e2));
-
- x[23] = x[30] = MAD_F_MLZ(hi, lo) + t1;
-
- MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0bcbe352));
- MAD_F_MLA(hi, lo, X[2], MAD_F(0x0d7e8807));
- MAD_F_MLA(hi, lo, X[3], -MAD_F(0x07635284));
- MAD_F_MLA(hi, lo, X[5], MAD_F(0x04cfb0e2));
- MAD_F_MLA(hi, lo, X[6], MAD_F(0x0f9ee890));
- MAD_F_MLA(hi, lo, X[8], -MAD_F(0x0ffc19fd));
- MAD_F_MLA(hi, lo, X[9], -MAD_F(0x00b2aa3e));
- MAD_F_MLA(hi, lo, X[11], MAD_F(0x03768962));
- MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0f426cb5));
- MAD_F_MLA(hi, lo, X[14], MAD_F(0x0e313245));
- MAD_F_MLA(hi, lo, X[15], MAD_F(0x0898c779));
- MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0acf37ad));
-
- x[18] = x[35] = MAD_F_MLZ(hi, lo) - t1;
-
- MAD_F_ML0(hi, lo, X[4], MAD_F(0x061f78aa));
- MAD_F_MLA(hi, lo, X[13], -MAD_F(0x0ec835e8));
-
- t7 = MAD_F_MLZ(hi, lo);
-
- MAD_F_MLA(hi, lo, X[1], -MAD_F(0x0cb19346));
- MAD_F_MLA(hi, lo, X[7], MAD_F(0x0fdcf549));
- MAD_F_MLA(hi, lo, X[10], MAD_F(0x0216a2a2));
- MAD_F_MLA(hi, lo, X[16], -MAD_F(0x09bd7ca0));
-
- t2 = MAD_F_MLZ(hi, lo);
-
- MAD_F_MLA(hi, lo, X[0], MAD_F(0x04cfb0e2));
- MAD_F_MLA(hi, lo, X[2], MAD_F(0x0ffc19fd));
- MAD_F_MLA(hi, lo, X[3], -MAD_F(0x0d7e8807));
- MAD_F_MLA(hi, lo, X[5], MAD_F(0x03768962));
- MAD_F_MLA(hi, lo, X[6], -MAD_F(0x0bcbe352));
- MAD_F_MLA(hi, lo, X[8], -MAD_F(0x0e313245));
- MAD_F_MLA(hi, lo, X[9], MAD_F(0x07635284));
- MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0acf37ad));
- MAD_F_MLA(hi, lo, X[12], MAD_F(0x0f9ee890));
- MAD_F_MLA(hi, lo, X[14], MAD_F(0x0898c779));
- MAD_F_MLA(hi, lo, X[15], MAD_F(0x00b2aa3e));
- MAD_F_MLA(hi, lo, X[17], MAD_F(0x0f426cb5));
-
- x[5] = MAD_F_MLZ(hi, lo);
- x[12] = -x[5];
-
- MAD_F_ML0(hi, lo, X[0], MAD_F(0x0acf37ad));
- MAD_F_MLA(hi, lo, X[2], -MAD_F(0x0898c779));
- MAD_F_MLA(hi, lo, X[3], MAD_F(0x0e313245));
- MAD_F_MLA(hi, lo, X[5], -MAD_F(0x0f426cb5));
- MAD_F_MLA(hi, lo, X[6], -MAD_F(0x03768962));
- MAD_F_MLA(hi, lo, X[8], MAD_F(0x00b2aa3e));
- MAD_F_MLA(hi, lo, X[9], -MAD_F(0x0ffc19fd));
- MAD_F_MLA(hi, lo, X[11], MAD_F(0x0f9ee890));
- MAD_F_MLA(hi, lo, X[12], -MAD_F(0x04cfb0e2));
- MAD_F_MLA(hi, lo, X[14], MAD_F(0x07635284));
- MAD_F_MLA(hi, lo, X[15], MAD_F(0x0d7e8807));
- MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0bcbe352));
-
- x[0] = MAD_F_MLZ(hi, lo) + t2;
- x[17] = -x[0];
-
- MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0f9ee890));
- MAD_F_MLA(hi, lo, X[2], -MAD_F(0x07635284));
- MAD_F_MLA(hi, lo, X[3], -MAD_F(0x00b2aa3e));
- MAD_F_MLA(hi, lo, X[5], MAD_F(0x0bcbe352));
- MAD_F_MLA(hi, lo, X[6], MAD_F(0x0f426cb5));
- MAD_F_MLA(hi, lo, X[8], MAD_F(0x0d7e8807));
- MAD_F_MLA(hi, lo, X[9], MAD_F(0x0898c779));
- MAD_F_MLA(hi, lo, X[11], -MAD_F(0x04cfb0e2));
- MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0acf37ad));
- MAD_F_MLA(hi, lo, X[14], -MAD_F(0x0ffc19fd));
- MAD_F_MLA(hi, lo, X[15], -MAD_F(0x0e313245));
- MAD_F_MLA(hi, lo, X[17], -MAD_F(0x03768962));
-
- x[24] = x[29] = MAD_F_MLZ(hi, lo) + t2;
-
- MAD_F_ML0(hi, lo, X[1], -MAD_F(0x0216a2a2));
- MAD_F_MLA(hi, lo, X[7], -MAD_F(0x09bd7ca0));
- MAD_F_MLA(hi, lo, X[10], MAD_F(0x0cb19346));
- MAD_F_MLA(hi, lo, X[16], MAD_F(0x0fdcf549));
-
- t3 = MAD_F_MLZ(hi, lo) + t7;
-
- MAD_F_ML0(hi, lo, X[0], MAD_F(0x00b2aa3e));
- MAD_F_MLA(hi, lo, X[2], MAD_F(0x03768962));
- MAD_F_MLA(hi, lo, X[3], -MAD_F(0x04cfb0e2));
- MAD_F_MLA(hi, lo, X[5], -MAD_F(0x07635284));
- MAD_F_MLA(hi, lo, X[6], MAD_F(0x0898c779));
- MAD_F_MLA(hi, lo, X[8], MAD_F(0x0acf37ad));
- MAD_F_MLA(hi, lo, X[9], -MAD_F(0x0bcbe352));
- MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0d7e8807));
- MAD_F_MLA(hi, lo, X[12], MAD_F(0x0e313245));
- MAD_F_MLA(hi, lo, X[14], MAD_F(0x0f426cb5));
- MAD_F_MLA(hi, lo, X[15], -MAD_F(0x0f9ee890));
- MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0ffc19fd));
-
- x[8] = MAD_F_MLZ(hi, lo) + t3;
- x[9] = -x[8];
-
- MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0e313245));
- MAD_F_MLA(hi, lo, X[2], MAD_F(0x0bcbe352));
- MAD_F_MLA(hi, lo, X[3], MAD_F(0x0f9ee890));
- MAD_F_MLA(hi, lo, X[5], -MAD_F(0x0898c779));
- MAD_F_MLA(hi, lo, X[6], -MAD_F(0x0ffc19fd));
- MAD_F_MLA(hi, lo, X[8], MAD_F(0x04cfb0e2));
- MAD_F_MLA(hi, lo, X[9], MAD_F(0x0f426cb5));
- MAD_F_MLA(hi, lo, X[11], -MAD_F(0x00b2aa3e));
- MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0d7e8807));
- MAD_F_MLA(hi, lo, X[14], -MAD_F(0x03768962));
- MAD_F_MLA(hi, lo, X[15], MAD_F(0x0acf37ad));
- MAD_F_MLA(hi, lo, X[17], MAD_F(0x07635284));
-
- x[21] = x[32] = MAD_F_MLZ(hi, lo) + t3;
-
- MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0d7e8807));
- MAD_F_MLA(hi, lo, X[2], MAD_F(0x0f426cb5));
- MAD_F_MLA(hi, lo, X[3], MAD_F(0x0acf37ad));
- MAD_F_MLA(hi, lo, X[5], -MAD_F(0x0ffc19fd));
- MAD_F_MLA(hi, lo, X[6], -MAD_F(0x07635284));
- MAD_F_MLA(hi, lo, X[8], MAD_F(0x0f9ee890));
- MAD_F_MLA(hi, lo, X[9], MAD_F(0x03768962));
- MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0e313245));
- MAD_F_MLA(hi, lo, X[12], MAD_F(0x00b2aa3e));
- MAD_F_MLA(hi, lo, X[14], MAD_F(0x0bcbe352));
- MAD_F_MLA(hi, lo, X[15], -MAD_F(0x04cfb0e2));
- MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0898c779));
-
- x[20] = x[33] = MAD_F_MLZ(hi, lo) - t3;
-
- MAD_F_ML0(hi, lo, t14, -MAD_F(0x0ec835e8));
- MAD_F_MLA(hi, lo, t15, MAD_F(0x061f78aa));
-
- t4 = MAD_F_MLZ(hi, lo) - t7;
-
- MAD_F_ML0(hi, lo, t12, MAD_F(0x061f78aa));
- MAD_F_MLA(hi, lo, t13, MAD_F(0x0ec835e8));
-
- x[4] = MAD_F_MLZ(hi, lo) + t4;
- x[13] = -x[4];
-
- MAD_F_ML0(hi, lo, t8, MAD_F(0x09bd7ca0));
- MAD_F_MLA(hi, lo, t9, -MAD_F(0x0216a2a2));
- MAD_F_MLA(hi, lo, t10, MAD_F(0x0fdcf549));
- MAD_F_MLA(hi, lo, t11, -MAD_F(0x0cb19346));
-
- x[1] = MAD_F_MLZ(hi, lo) + t4;
- x[16] = -x[1];
-
- MAD_F_ML0(hi, lo, t8, -MAD_F(0x0fdcf549));
- MAD_F_MLA(hi, lo, t9, -MAD_F(0x0cb19346));
- MAD_F_MLA(hi, lo, t10, -MAD_F(0x09bd7ca0));
- MAD_F_MLA(hi, lo, t11, -MAD_F(0x0216a2a2));
-
- x[25] = x[28] = MAD_F_MLZ(hi, lo) + t4;
-
- MAD_F_ML0(hi, lo, X[1], -MAD_F(0x0fdcf549));
- MAD_F_MLA(hi, lo, X[7], -MAD_F(0x0cb19346));
- MAD_F_MLA(hi, lo, X[10], -MAD_F(0x09bd7ca0));
- MAD_F_MLA(hi, lo, X[16], -MAD_F(0x0216a2a2));
-
- t5 = MAD_F_MLZ(hi, lo) - t6;
-
- MAD_F_ML0(hi, lo, X[0], MAD_F(0x0898c779));
- MAD_F_MLA(hi, lo, X[2], MAD_F(0x04cfb0e2));
- MAD_F_MLA(hi, lo, X[3], MAD_F(0x0bcbe352));
- MAD_F_MLA(hi, lo, X[5], MAD_F(0x00b2aa3e));
- MAD_F_MLA(hi, lo, X[6], MAD_F(0x0e313245));
- MAD_F_MLA(hi, lo, X[8], -MAD_F(0x03768962));
- MAD_F_MLA(hi, lo, X[9], MAD_F(0x0f9ee890));
- MAD_F_MLA(hi, lo, X[11], -MAD_F(0x07635284));
- MAD_F_MLA(hi, lo, X[12], MAD_F(0x0ffc19fd));
- MAD_F_MLA(hi, lo, X[14], -MAD_F(0x0acf37ad));
- MAD_F_MLA(hi, lo, X[15], MAD_F(0x0f426cb5));
- MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0d7e8807));
-
- x[2] = MAD_F_MLZ(hi, lo) + t5;
- x[15] = -x[2];
-
- MAD_F_ML0(hi, lo, X[0], MAD_F(0x07635284));
- MAD_F_MLA(hi, lo, X[2], MAD_F(0x0acf37ad));
- MAD_F_MLA(hi, lo, X[3], MAD_F(0x03768962));
- MAD_F_MLA(hi, lo, X[5], MAD_F(0x0d7e8807));
- MAD_F_MLA(hi, lo, X[6], -MAD_F(0x00b2aa3e));
- MAD_F_MLA(hi, lo, X[8], MAD_F(0x0f426cb5));
- MAD_F_MLA(hi, lo, X[9], -MAD_F(0x04cfb0e2));
- MAD_F_MLA(hi, lo, X[11], MAD_F(0x0ffc19fd));
- MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0898c779));
- MAD_F_MLA(hi, lo, X[14], MAD_F(0x0f9ee890));
- MAD_F_MLA(hi, lo, X[15], -MAD_F(0x0bcbe352));
- MAD_F_MLA(hi, lo, X[17], MAD_F(0x0e313245));
-
- x[3] = MAD_F_MLZ(hi, lo) + t5;
- x[14] = -x[3];
-
- MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0ffc19fd));
- MAD_F_MLA(hi, lo, X[2], -MAD_F(0x0f9ee890));
- MAD_F_MLA(hi, lo, X[3], -MAD_F(0x0f426cb5));
- MAD_F_MLA(hi, lo, X[5], -MAD_F(0x0e313245));
- MAD_F_MLA(hi, lo, X[6], -MAD_F(0x0d7e8807));
- MAD_F_MLA(hi, lo, X[8], -MAD_F(0x0bcbe352));
- MAD_F_MLA(hi, lo, X[9], -MAD_F(0x0acf37ad));
- MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0898c779));
- MAD_F_MLA(hi, lo, X[12], -MAD_F(0x07635284));
- MAD_F_MLA(hi, lo, X[14], -MAD_F(0x04cfb0e2));
- MAD_F_MLA(hi, lo, X[15], -MAD_F(0x03768962));
- MAD_F_MLA(hi, lo, X[17], -MAD_F(0x00b2aa3e));
-
- x[26] = x[27] = MAD_F_MLZ(hi, lo) + t5;
-}
-# endif
-
-/*
- * NAME: III_imdct_l()
- * DESCRIPTION: perform IMDCT and windowing for long blocks
- */
-static
-void III_imdct_l(mad_fixed_t const X[18], mad_fixed_t z[36],
- unsigned int block_type)
-{
- unsigned int i;
-
- /* IMDCT */
-
- imdct36(X, z);
-
- /* windowing */
-
- switch (block_type) {
- case 0: /* normal window */
-# if defined(ASO_INTERLEAVE1)
- {
- register mad_fixed_t tmp1, tmp2;
-
- tmp1 = window_l[0];
- tmp2 = window_l[1];
-
- for (i = 0; i < 34; i += 2) {
- z[i + 0] = mad_f_mul(z[i + 0], tmp1);
- tmp1 = window_l[i + 2];
- z[i + 1] = mad_f_mul(z[i + 1], tmp2);
- tmp2 = window_l[i + 3];
- }
-
- z[34] = mad_f_mul(z[34], tmp1);
- z[35] = mad_f_mul(z[35], tmp2);
- }
-# elif defined(ASO_INTERLEAVE2)
- {
- register mad_fixed_t tmp1, tmp2;
-
- tmp1 = z[0];
- tmp2 = window_l[0];
-
- for (i = 0; i < 35; ++i) {
- z[i] = mad_f_mul(tmp1, tmp2);
- tmp1 = z[i + 1];
- tmp2 = window_l[i + 1];
- }
-
- z[35] = mad_f_mul(tmp1, tmp2);
- }
-# elif 1
- for (i = 0; i < 36; i += 4) {
- z[i + 0] = mad_f_mul(z[i + 0], window_l[i + 0]);
- z[i + 1] = mad_f_mul(z[i + 1], window_l[i + 1]);
- z[i + 2] = mad_f_mul(z[i + 2], window_l[i + 2]);
- z[i + 3] = mad_f_mul(z[i + 3], window_l[i + 3]);
- }
-# else
- for (i = 0; i < 36; ++i) z[i] = mad_f_mul(z[i], window_l[i]);
-# endif
- break;
-
- case 1: /* start block */
- for (i = 0; i < 18; i += 3) {
- z[i + 0] = mad_f_mul(z[i + 0], window_l[i + 0]);
- z[i + 1] = mad_f_mul(z[i + 1], window_l[i + 1]);
- z[i + 2] = mad_f_mul(z[i + 2], window_l[i + 2]);
- }
- /* (i = 18; i < 24; ++i) z[i] unchanged */
- for (i = 24; i < 30; ++i) z[i] = mad_f_mul(z[i], window_s[i - 18]);
- for (i = 30; i < 36; ++i) z[i] = 0;
- break;
-
- case 3: /* stop block */
- for (i = 0; i < 6; ++i) z[i] = 0;
- for (i = 6; i < 12; ++i) z[i] = mad_f_mul(z[i], window_s[i - 6]);
- /* (i = 12; i < 18; ++i) z[i] unchanged */
- for (i = 18; i < 36; i += 3) {
- z[i + 0] = mad_f_mul(z[i + 0], window_l[i + 0]);
- z[i + 1] = mad_f_mul(z[i + 1], window_l[i + 1]);
- z[i + 2] = mad_f_mul(z[i + 2], window_l[i + 2]);
- }
- break;
- }
-}
-# endif /* ASO_IMDCT */
-
-/*
- * NAME: III_imdct_s()
- * DESCRIPTION: perform IMDCT and windowing for short blocks
- */
-static
-void III_imdct_s(mad_fixed_t const X[18], mad_fixed_t z[36])
-{
- mad_fixed_t y[36], *yptr;
- mad_fixed_t const *wptr;
- int w, i;
- register mad_fixed64hi_t hi;
- register mad_fixed64lo_t lo;
-
- /* IMDCT */
-
- yptr = &y[0];
-
- for (w = 0; w < 3; ++w) {
- register mad_fixed_t const (*s)[6];
-
- s = imdct_s;
-
- for (i = 0; i < 3; ++i) {
- MAD_F_ML0(hi, lo, X[0], (*s)[0]);
- MAD_F_MLA(hi, lo, X[1], (*s)[1]);
- MAD_F_MLA(hi, lo, X[2], (*s)[2]);
- MAD_F_MLA(hi, lo, X[3], (*s)[3]);
- MAD_F_MLA(hi, lo, X[4], (*s)[4]);
- MAD_F_MLA(hi, lo, X[5], (*s)[5]);
-
- yptr[i + 0] = MAD_F_MLZ(hi, lo);
- yptr[5 - i] = -yptr[i + 0];
-
- ++s;
-
- MAD_F_ML0(hi, lo, X[0], (*s)[0]);
- MAD_F_MLA(hi, lo, X[1], (*s)[1]);
- MAD_F_MLA(hi, lo, X[2], (*s)[2]);
- MAD_F_MLA(hi, lo, X[3], (*s)[3]);
- MAD_F_MLA(hi, lo, X[4], (*s)[4]);
- MAD_F_MLA(hi, lo, X[5], (*s)[5]);
-
- yptr[ i + 6] = MAD_F_MLZ(hi, lo);
- yptr[11 - i] = yptr[i + 6];
-
- ++s;
- }
-
- yptr += 12;
- X += 6;
- }
-
- /* windowing, overlapping and concatenation */
-
- yptr = &y[0];
- wptr = &window_s[0];
-
- for (i = 0; i < 6; ++i) {
- z[i + 0] = 0;
- z[i + 6] = mad_f_mul(yptr[ 0 + 0], wptr[0]);
-
- MAD_F_ML0(hi, lo, yptr[ 0 + 6], wptr[6]);
- MAD_F_MLA(hi, lo, yptr[12 + 0], wptr[0]);
-
- z[i + 12] = MAD_F_MLZ(hi, lo);
-
- MAD_F_ML0(hi, lo, yptr[12 + 6], wptr[6]);
- MAD_F_MLA(hi, lo, yptr[24 + 0], wptr[0]);
-
- z[i + 18] = MAD_F_MLZ(hi, lo);
-
- z[i + 24] = mad_f_mul(yptr[24 + 6], wptr[6]);
- z[i + 30] = 0;
-
- ++yptr;
- ++wptr;
- }
-}
-
-/*
- * NAME: III_overlap()
- * DESCRIPTION: perform overlap-add of windowed IMDCT outputs
- */
-static
-void III_overlap(mad_fixed_t const output[36], mad_fixed_t overlap[18],
- mad_fixed_t sample[18][32], unsigned int sb)
-{
- unsigned int i;
-
-# if defined(ASO_INTERLEAVE2)
- {
- register mad_fixed_t tmp1, tmp2;
-
- tmp1 = overlap[0];
- tmp2 = overlap[1];
-
- for (i = 0; i < 16; i += 2) {
- sample[i + 0][sb] = output[i + 0 + 0] + tmp1;
- overlap[i + 0] = output[i + 0 + 18];
- tmp1 = overlap[i + 2];
-
- sample[i + 1][sb] = output[i + 1 + 0] + tmp2;
- overlap[i + 1] = output[i + 1 + 18];
- tmp2 = overlap[i + 3];
- }
-
- sample[16][sb] = output[16 + 0] + tmp1;
- overlap[16] = output[16 + 18];
- sample[17][sb] = output[17 + 0] + tmp2;
- overlap[17] = output[17 + 18];
- }
-# elif 0
- for (i = 0; i < 18; i += 2) {
- sample[i + 0][sb] = output[i + 0 + 0] + overlap[i + 0];
- overlap[i + 0] = output[i + 0 + 18];
-
- sample[i + 1][sb] = output[i + 1 + 0] + overlap[i + 1];
- overlap[i + 1] = output[i + 1 + 18];
- }
-# else
- for (i = 0; i < 18; ++i) {
- sample[i][sb] = output[i + 0] + overlap[i];
- overlap[i] = output[i + 18];
- }
-# endif
-}
-
-/*
- * NAME: III_overlap_z()
- * DESCRIPTION: perform "overlap-add" of zero IMDCT outputs
- */
-static inline
-void III_overlap_z(mad_fixed_t overlap[18],
- mad_fixed_t sample[18][32], unsigned int sb)
-{
- unsigned int i;
-
-# if defined(ASO_INTERLEAVE2)
- {
- register mad_fixed_t tmp1, tmp2;
-
- tmp1 = overlap[0];
- tmp2 = overlap[1];
-
- for (i = 0; i < 16; i += 2) {
- sample[i + 0][sb] = tmp1;
- overlap[i + 0] = 0;
- tmp1 = overlap[i + 2];
-
- sample[i + 1][sb] = tmp2;
- overlap[i + 1] = 0;
- tmp2 = overlap[i + 3];
- }
-
- sample[16][sb] = tmp1;
- overlap[16] = 0;
- sample[17][sb] = tmp2;
- overlap[17] = 0;
- }
-# else
- for (i = 0; i < 18; ++i) {
- sample[i][sb] = overlap[i];
- overlap[i] = 0;
- }
-# endif
-}
-
-/*
- * NAME: III_freqinver()
- * DESCRIPTION: perform subband frequency inversion for odd sample lines
- */
-static
-void III_freqinver(mad_fixed_t sample[18][32], unsigned int sb)
-{
- unsigned int i;
-
-# if 1 || defined(ASO_INTERLEAVE1) || defined(ASO_INTERLEAVE2)
- {
- register mad_fixed_t tmp1, tmp2;
-
- tmp1 = sample[1][sb];
- tmp2 = sample[3][sb];
-
- for (i = 1; i < 13; i += 4) {
- sample[i + 0][sb] = -tmp1;
- tmp1 = sample[i + 4][sb];
- sample[i + 2][sb] = -tmp2;
- tmp2 = sample[i + 6][sb];
- }
-
- sample[13][sb] = -tmp1;
- tmp1 = sample[17][sb];
- sample[15][sb] = -tmp2;
- sample[17][sb] = -tmp1;
- }
-# else
- for (i = 1; i < 18; i += 2)
- sample[i][sb] = -sample[i][sb];
-# endif
-}
-
-/*
- * NAME: III_decode()
- * DESCRIPTION: decode frame main_data
- */
-static
-enum mad_error III_decode(struct mad_bitptr *ptr, struct mad_frame *frame,
- struct sideinfo *si, unsigned int nch)
-{
- struct mad_header *header = &frame->header;
- unsigned int sfreqi, ngr, gr;
-
- {
- unsigned int sfreq;
-
- sfreq = header->samplerate;
- if (header->flags & MAD_FLAG_MPEG_2_5_EXT)
- sfreq *= 2;
-
- /* 48000 => 0, 44100 => 1, 32000 => 2,
- 24000 => 3, 22050 => 4, 16000 => 5 */
- sfreqi = ((sfreq >> 7) & 0x000f) +
- ((sfreq >> 15) & 0x0001) - 8;
-
- if (header->flags & MAD_FLAG_MPEG_2_5_EXT)
- sfreqi += 3;
- }
-
- /* scalefactors, Huffman decoding, requantization */
-
- ngr = (header->flags & MAD_FLAG_LSF_EXT) ? 1 : 2;
-
- for (gr = 0; gr < ngr; ++gr) {
- struct granule *granule = &si->gr[gr];
- unsigned char const *sfbwidth[2];
- mad_fixed_t xr[2][576];
- unsigned int ch;
- enum mad_error error;
-
- for (ch = 0; ch < nch; ++ch) {
- struct channel *channel = &granule->ch[ch];
- unsigned int part2_length;
-
- sfbwidth[ch] = sfbwidth_table[sfreqi].l;
- if (channel->block_type == 2) {
- sfbwidth[ch] = (channel->flags & mixed_block_flag) ?
- sfbwidth_table[sfreqi].m : sfbwidth_table[sfreqi].s;
- }
-
- if (header->flags & MAD_FLAG_LSF_EXT) {
- part2_length = III_scalefactors_lsf(ptr, channel,
- ch == 0 ? 0 : &si->gr[1].ch[1],
- header->mode_extension);
- }
- else {
- part2_length = III_scalefactors(ptr, channel, &si->gr[0].ch[ch],
- gr == 0 ? 0 : si->scfsi[ch]);
- }
-
- error = III_huffdecode(ptr, xr[ch], channel, sfbwidth[ch], part2_length);
- if (error)
- return error;
- }
-
- /* joint stereo processing */
-
- if (header->mode == MAD_MODE_JOINT_STEREO && header->mode_extension) {
- error = III_stereo(xr, granule, header, sfbwidth[0]);
- if (error)
- return error;
- }
-
- /* reordering, alias reduction, IMDCT, overlap-add, frequency inversion */
-
- for (ch = 0; ch < nch; ++ch) {
- struct channel const *channel = &granule->ch[ch];
- mad_fixed_t (*sample)[32] = &frame->sbsample[ch][18 * gr];
- unsigned int sb, l, i, sblimit;
- mad_fixed_t output[36];
-
- if (channel->block_type == 2) {
- III_reorder(xr[ch], channel, sfbwidth[ch]);
-
-# if !defined(OPT_STRICT)
- /*
- * According to ISO/IEC 11172-3, "Alias reduction is not applied for
- * granules with block_type == 2 (short block)." However, other
- * sources suggest alias reduction should indeed be performed on the
- * lower two subbands of mixed blocks. Most other implementations do
- * this, so by default we will too.
- */
- if (channel->flags & mixed_block_flag)
- III_aliasreduce(xr[ch], 36);
-# endif
- }
- else
- III_aliasreduce(xr[ch], 576);
-
- l = 0;
-
- /* subbands 0-1 */
-
- if (channel->block_type != 2 || (channel->flags & mixed_block_flag)) {
- unsigned int block_type;
-
- block_type = channel->block_type;
- if (channel->flags & mixed_block_flag)
- block_type = 0;
-
- /* long blocks */
- for (sb = 0; sb < 2; ++sb, l += 18) {
- III_imdct_l(&xr[ch][l], output, block_type);
- III_overlap(output, (*frame->overlap)[ch][sb], sample, sb);
- }
- }
- else {
- /* short blocks */
- for (sb = 0; sb < 2; ++sb, l += 18) {
- III_imdct_s(&xr[ch][l], output);
- III_overlap(output, (*frame->overlap)[ch][sb], sample, sb);
- }
- }
-
- III_freqinver(sample, 1);
-
- /* (nonzero) subbands 2-31 */
-
- i = 576;
- while (i > 36 && xr[ch][i - 1] == 0)
- --i;
-
- sblimit = 32 - (576 - i) / 18;
-
- if (channel->block_type != 2) {
- /* long blocks */
- for (sb = 2; sb < sblimit; ++sb, l += 18) {
- III_imdct_l(&xr[ch][l], output, channel->block_type);
- III_overlap(output, (*frame->overlap)[ch][sb], sample, sb);
-
- if (sb & 1)
- III_freqinver(sample, sb);
- }
- }
- else {
- /* short blocks */
- for (sb = 2; sb < sblimit; ++sb, l += 18) {
- III_imdct_s(&xr[ch][l], output);
- III_overlap(output, (*frame->overlap)[ch][sb], sample, sb);
-
- if (sb & 1)
- III_freqinver(sample, sb);
- }
- }
-
- /* remaining (zero) subbands */
-
- for (sb = sblimit; sb < 32; ++sb) {
- III_overlap_z((*frame->overlap)[ch][sb], sample, sb);
-
- if (sb & 1)
- III_freqinver(sample, sb);
- }
- }
- }
-
- return MAD_ERROR_NONE;
-}
-
-/*
- * NAME: layer->III()
- * DESCRIPTION: decode a single Layer III frame
- */
-int mad_layer_III(struct mad_stream *stream, struct mad_frame *frame)
-{
- struct mad_header *header = &frame->header;
- unsigned int nch, priv_bitlen, next_md_begin = 0;
- unsigned int si_len, data_bitlen, md_len;
- unsigned int frame_space, frame_used, frame_free;
- struct mad_bitptr ptr;
- struct sideinfo si;
- enum mad_error error;
- int result = 0;
-
- /* allocate Layer III dynamic structures */
-
- if (stream->main_data == 0) {
- stream->main_data = malloc(MAD_BUFFER_MDLEN);
- if (stream->main_data == 0) {
- stream->error = MAD_ERROR_NOMEM;
- return -1;
- }
- }
-
- if (frame->overlap == 0) {
- frame->overlap = calloc(2 * 32 * 18, sizeof(mad_fixed_t));
- if (frame->overlap == 0) {
- stream->error = MAD_ERROR_NOMEM;
- return -1;
- }
- }
-
- nch = MAD_NCHANNELS(header);
- si_len = (header->flags & MAD_FLAG_LSF_EXT) ?
- (nch == 1 ? 9 : 17) : (nch == 1 ? 17 : 32);
-
- /* check frame sanity */
-
- if (stream->next_frame - mad_bit_nextbyte(&stream->ptr) <
- (signed int) si_len) {
- stream->error = MAD_ERROR_BADFRAMELEN;
- stream->md_len = 0;
- return -1;
- }
-
- /* check CRC word */
-
- if (header->flags & MAD_FLAG_PROTECTION) {
- header->crc_check =
- mad_bit_crc(stream->ptr, si_len * CHAR_BIT, header->crc_check);
-
- if (header->crc_check != header->crc_target &&
- !(frame->options & MAD_OPTION_IGNORECRC)) {
- stream->error = MAD_ERROR_BADCRC;
- result = -1;
- }
- }
-
- /* decode frame side information */
-
- error = III_sideinfo(&stream->ptr, nch, header->flags & MAD_FLAG_LSF_EXT,
- &si, &data_bitlen, &priv_bitlen);
- if (error && result == 0) {
- stream->error = error;
- result = -1;
- }
-
- header->flags |= priv_bitlen;
- header->private_bits |= si.private_bits;
-
- /* find main_data of next frame */
-
- {
- struct mad_bitptr peek;
- unsigned long header;
-
- mad_bit_init(&peek, stream->next_frame);
-
- header = mad_bit_read(&peek, 32);
- if ((header & 0xffe60000L) /* syncword | layer */ == 0xffe20000L) {
- if (!(header & 0x00010000L)) /* protection_bit */
- mad_bit_skip(&peek, 16); /* crc_check */
-
- next_md_begin =
- mad_bit_read(&peek, (header & 0x00080000L) /* ID */ ? 9 : 8);
- }
-
- mad_bit_finish(&peek);
- }
-
- /* find main_data of this frame */
-
- frame_space = stream->next_frame - mad_bit_nextbyte(&stream->ptr);
-
- if (next_md_begin > si.main_data_begin + frame_space)
- next_md_begin = 0;
-
- md_len = si.main_data_begin + frame_space - next_md_begin;
-
- frame_used = 0;
-
- if (si.main_data_begin == 0) {
- ptr = stream->ptr;
- stream->md_len = 0;
-
- frame_used = md_len;
- }
- else {
- if (si.main_data_begin > stream->md_len) {
- if (result == 0) {
- stream->error = MAD_ERROR_BADDATAPTR;
- result = -1;
- }
- }
- else {
- mad_bit_init(&ptr,
- *stream->main_data + stream->md_len - si.main_data_begin);
-
- if (md_len > si.main_data_begin) {
- assert(stream->md_len + md_len -
- si.main_data_begin <= MAD_BUFFER_MDLEN);
-
- memcpy(*stream->main_data + stream->md_len,
- mad_bit_nextbyte(&stream->ptr),
- frame_used = md_len - si.main_data_begin);
- stream->md_len += frame_used;
- }
- }
- }
-
- frame_free = frame_space - frame_used;
-
- /* decode main_data */
-
- if (result == 0) {
- error = III_decode(&ptr, frame, &si, nch);
- if (error) {
- stream->error = error;
- result = -1;
- }
-
- /* designate ancillary bits */
-
- stream->anc_ptr = ptr;
- stream->anc_bitlen = md_len * CHAR_BIT - data_bitlen;
- }
-
-# if 0 && defined(DEBUG)
- fprintf(stderr,
- "main_data_begin:%u, md_len:%u, frame_free:%u, "
- "data_bitlen:%u, anc_bitlen: %u\n",
- si.main_data_begin, md_len, frame_free,
- data_bitlen, stream->anc_bitlen);
-# endif
-
- /* preload main_data buffer with up to 511 bytes for next frame(s) */
-
- if (frame_free >= next_md_begin) {
- memcpy(*stream->main_data,
- stream->next_frame - next_md_begin, next_md_begin);
- stream->md_len = next_md_begin;
- }
- else {
- if (md_len < si.main_data_begin) {
- unsigned int extra;
-
- extra = si.main_data_begin - md_len;
- if (extra + frame_free > next_md_begin)
- extra = next_md_begin - frame_free;
-
- if (extra < stream->md_len) {
- memmove(*stream->main_data,
- *stream->main_data + stream->md_len - extra, extra);
- stream->md_len = extra;
- }
- }
- else
- stream->md_len = 0;
-
- memcpy(*stream->main_data + stream->md_len,
- stream->next_frame - frame_free, frame_free);
- stream->md_len += frame_free;
- }
-
- return result;
-}
diff --git a/src/libmad/layer3.h b/src/libmad/layer3.h
deleted file mode 100644
index 3dca5b3b8..000000000
--- a/src/libmad/layer3.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * libmad - MPEG audio decoder library
- * Copyright (C) 2000-2004 Underbit Technologies, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: layer3.h,v 1.3 2004/04/22 00:23:06 miguelfreitas Exp $
- */
-
-# ifndef LIBMAD_LAYER3_H
-# define LIBMAD_LAYER3_H
-
-# include "stream.h"
-# include "frame.h"
-
-int mad_layer_III(struct mad_stream *, struct mad_frame *);
-
-# endif
diff --git a/src/libmad/qc_table.dat b/src/libmad/qc_table.dat
deleted file mode 100644
index 1848e0011..000000000
--- a/src/libmad/qc_table.dat
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * libmad - MPEG audio decoder library
- * Copyright (C) 2000-2001 Robert Leslie
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: qc_table.dat,v 1.2 2002/04/30 18:46:58 miguelfreitas Exp $
- */
-
-/*
- * These are the Layer II classes of quantization.
- * The table is derived from Table B.4 of ISO/IEC 11172-3.
- */
-
- { 3, 2, 5,
- MAD_F(0x15555555) /* 1.33333333333 => 1.33333333209, e 0.00000000124 */,
- MAD_F(0x08000000) /* 0.50000000000 => 0.50000000000, e 0.00000000000 */ },
- { 5, 3, 7,
- MAD_F(0x1999999a) /* 1.60000000000 => 1.60000000149, e -0.00000000149 */,
- MAD_F(0x08000000) /* 0.50000000000 => 0.50000000000, e 0.00000000000 */ },
- { 7, 0, 3,
- MAD_F(0x12492492) /* 1.14285714286 => 1.14285714179, e 0.00000000107 */,
- MAD_F(0x04000000) /* 0.25000000000 => 0.25000000000, e 0.00000000000 */ },
- { 9, 4, 10,
- MAD_F(0x1c71c71c) /* 1.77777777777 => 1.77777777612, e 0.00000000165 */,
- MAD_F(0x08000000) /* 0.50000000000 => 0.50000000000, e 0.00000000000 */ },
- { 15, 0, 4,
- MAD_F(0x11111111) /* 1.06666666666 => 1.06666666642, e 0.00000000024 */,
- MAD_F(0x02000000) /* 0.12500000000 => 0.12500000000, e 0.00000000000 */ },
- { 31, 0, 5,
- MAD_F(0x10842108) /* 1.03225806452 => 1.03225806355, e 0.00000000097 */,
- MAD_F(0x01000000) /* 0.06250000000 => 0.06250000000, e 0.00000000000 */ },
- { 63, 0, 6,
- MAD_F(0x10410410) /* 1.01587301587 => 1.01587301493, e 0.00000000094 */,
- MAD_F(0x00800000) /* 0.03125000000 => 0.03125000000, e 0.00000000000 */ },
- { 127, 0, 7,
- MAD_F(0x10204081) /* 1.00787401575 => 1.00787401572, e 0.00000000003 */,
- MAD_F(0x00400000) /* 0.01562500000 => 0.01562500000, e 0.00000000000 */ },
- { 255, 0, 8,
- MAD_F(0x10101010) /* 1.00392156863 => 1.00392156839, e 0.00000000024 */,
- MAD_F(0x00200000) /* 0.00781250000 => 0.00781250000, e 0.00000000000 */ },
- { 511, 0, 9,
- MAD_F(0x10080402) /* 1.00195694716 => 1.00195694715, e 0.00000000001 */,
- MAD_F(0x00100000) /* 0.00390625000 => 0.00390625000, e 0.00000000000 */ },
- { 1023, 0, 10,
- MAD_F(0x10040100) /* 1.00097751711 => 1.00097751617, e 0.00000000094 */,
- MAD_F(0x00080000) /* 0.00195312500 => 0.00195312500, e 0.00000000000 */ },
- { 2047, 0, 11,
- MAD_F(0x10020040) /* 1.00048851979 => 1.00048851967, e 0.00000000012 */,
- MAD_F(0x00040000) /* 0.00097656250 => 0.00097656250, e 0.00000000000 */ },
- { 4095, 0, 12,
- MAD_F(0x10010010) /* 1.00024420024 => 1.00024420023, e 0.00000000001 */,
- MAD_F(0x00020000) /* 0.00048828125 => 0.00048828125, e 0.00000000000 */ },
- { 8191, 0, 13,
- MAD_F(0x10008004) /* 1.00012208522 => 1.00012208521, e 0.00000000001 */,
- MAD_F(0x00010000) /* 0.00024414063 => 0.00024414062, e 0.00000000000 */ },
- { 16383, 0, 14,
- MAD_F(0x10004001) /* 1.00006103888 => 1.00006103888, e -0.00000000000 */,
- MAD_F(0x00008000) /* 0.00012207031 => 0.00012207031, e -0.00000000000 */ },
- { 32767, 0, 15,
- MAD_F(0x10002000) /* 1.00003051851 => 1.00003051758, e 0.00000000093 */,
- MAD_F(0x00004000) /* 0.00006103516 => 0.00006103516, e 0.00000000000 */ },
- { 65535, 0, 16,
- MAD_F(0x10001000) /* 1.00001525902 => 1.00001525879, e 0.00000000023 */,
- MAD_F(0x00002000) /* 0.00003051758 => 0.00003051758, e 0.00000000000 */ }
diff --git a/src/libmad/rq_table.dat b/src/libmad/rq_table.dat
deleted file mode 100644
index 7db10fd33..000000000
--- a/src/libmad/rq_table.dat
+++ /dev/null
@@ -1,8747 +0,0 @@
-/*
- * libmad - MPEG audio decoder library
- * Copyright (C) 2000-2001 Robert Leslie
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: rq_table.dat,v 1.2 2002/04/30 18:46:58 miguelfreitas Exp $
- */
-
-/*
- * This is the lookup table used to compute x^(4/3) for Layer III
- * requantization. To maintain the best possible accuracy, the value is
- * stored as a normalized mantissa with exponent. The requantization
- * algorithm recombines these parts with appropriate scaling.
- */
-
- /* 0 */ { MAD_F(0x00000000) /* 0.000000000 */, 0 },
- /* 1 */ { MAD_F(0x04000000) /* 0.250000000 */, 2 },
- /* 2 */ { MAD_F(0x050a28be) /* 0.314980262 */, 3 },
- /* 3 */ { MAD_F(0x0453a5cd) /* 0.270421794 */, 4 },
- /* 4 */ { MAD_F(0x06597fa9) /* 0.396850263 */, 4 },
- /* 5 */ { MAD_F(0x04466275) /* 0.267183742 */, 5 },
- /* 6 */ { MAD_F(0x05738c72) /* 0.340710111 */, 5 },
- /* 7 */ { MAD_F(0x06b1fc81) /* 0.418453696 */, 5 },
- /* 8 */ { MAD_F(0x04000000) /* 0.250000000 */, 6 },
- /* 9 */ { MAD_F(0x04ae20d7) /* 0.292511788 */, 6 },
- /* 10 */ { MAD_F(0x0562d694) /* 0.336630420 */, 6 },
- /* 11 */ { MAD_F(0x061dae96) /* 0.382246578 */, 6 },
- /* 12 */ { MAD_F(0x06de47f4) /* 0.429267841 */, 6 },
- /* 13 */ { MAD_F(0x07a44f7a) /* 0.477614858 */, 6 },
- /* 14 */ { MAD_F(0x0437be65) /* 0.263609310 */, 7 },
- /* 15 */ { MAD_F(0x049fc824) /* 0.289009227 */, 7 },
-
- /* 16 */ { MAD_F(0x050a28be) /* 0.314980262 */, 7 },
- /* 17 */ { MAD_F(0x0576c6f5) /* 0.341498336 */, 7 },
- /* 18 */ { MAD_F(0x05e58c0b) /* 0.368541759 */, 7 },
- /* 19 */ { MAD_F(0x06566361) /* 0.396090870 */, 7 },
- /* 20 */ { MAD_F(0x06c93a2e) /* 0.424127753 */, 7 },
- /* 21 */ { MAD_F(0x073dff3e) /* 0.452635998 */, 7 },
- /* 22 */ { MAD_F(0x07b4a2bc) /* 0.481600510 */, 7 },
- /* 23 */ { MAD_F(0x04168b05) /* 0.255503674 */, 8 },
- /* 24 */ { MAD_F(0x0453a5cd) /* 0.270421794 */, 8 },
- /* 25 */ { MAD_F(0x04919b6a) /* 0.285548607 */, 8 },
- /* 26 */ { MAD_F(0x04d065fb) /* 0.300878507 */, 8 },
- /* 27 */ { MAD_F(0x05100000) /* 0.316406250 */, 8 },
- /* 28 */ { MAD_F(0x05506451) /* 0.332126919 */, 8 },
- /* 29 */ { MAD_F(0x05918e15) /* 0.348035890 */, 8 },
- /* 30 */ { MAD_F(0x05d378bb) /* 0.364128809 */, 8 },
- /* 31 */ { MAD_F(0x06161ff3) /* 0.380401563 */, 8 },
-
- /* 32 */ { MAD_F(0x06597fa9) /* 0.396850263 */, 8 },
- /* 33 */ { MAD_F(0x069d9400) /* 0.413471222 */, 8 },
- /* 34 */ { MAD_F(0x06e2594c) /* 0.430260942 */, 8 },
- /* 35 */ { MAD_F(0x0727cc11) /* 0.447216097 */, 8 },
- /* 36 */ { MAD_F(0x076de8fc) /* 0.464333519 */, 8 },
- /* 37 */ { MAD_F(0x07b4ace3) /* 0.481610189 */, 8 },
- /* 38 */ { MAD_F(0x07fc14bf) /* 0.499043224 */, 8 },
- /* 39 */ { MAD_F(0x04220ed7) /* 0.258314934 */, 9 },
- /* 40 */ { MAD_F(0x04466275) /* 0.267183742 */, 9 },
- /* 41 */ { MAD_F(0x046b03e7) /* 0.276126771 */, 9 },
- /* 42 */ { MAD_F(0x048ff1e8) /* 0.285142811 */, 9 },
- /* 43 */ { MAD_F(0x04b52b3f) /* 0.294230696 */, 9 },
- /* 44 */ { MAD_F(0x04daaec0) /* 0.303389310 */, 9 },
- /* 45 */ { MAD_F(0x05007b49) /* 0.312617576 */, 9 },
- /* 46 */ { MAD_F(0x05268fc6) /* 0.321914457 */, 9 },
- /* 47 */ { MAD_F(0x054ceb2a) /* 0.331278957 */, 9 },
-
- /* 48 */ { MAD_F(0x05738c72) /* 0.340710111 */, 9 },
- /* 49 */ { MAD_F(0x059a72a5) /* 0.350206992 */, 9 },
- /* 50 */ { MAD_F(0x05c19cd3) /* 0.359768701 */, 9 },
- /* 51 */ { MAD_F(0x05e90a12) /* 0.369394372 */, 9 },
- /* 52 */ { MAD_F(0x0610b982) /* 0.379083164 */, 9 },
- /* 53 */ { MAD_F(0x0638aa48) /* 0.388834268 */, 9 },
- /* 54 */ { MAD_F(0x0660db91) /* 0.398646895 */, 9 },
- /* 55 */ { MAD_F(0x06894c90) /* 0.408520284 */, 9 },
- /* 56 */ { MAD_F(0x06b1fc81) /* 0.418453696 */, 9 },
- /* 57 */ { MAD_F(0x06daeaa1) /* 0.428446415 */, 9 },
- /* 58 */ { MAD_F(0x07041636) /* 0.438497744 */, 9 },
- /* 59 */ { MAD_F(0x072d7e8b) /* 0.448607009 */, 9 },
- /* 60 */ { MAD_F(0x075722ef) /* 0.458773552 */, 9 },
- /* 61 */ { MAD_F(0x078102b8) /* 0.468996735 */, 9 },
- /* 62 */ { MAD_F(0x07ab1d3e) /* 0.479275937 */, 9 },
- /* 63 */ { MAD_F(0x07d571e0) /* 0.489610555 */, 9 },
-
- /* 64 */ { MAD_F(0x04000000) /* 0.250000000 */, 10 },
- /* 65 */ { MAD_F(0x04156381) /* 0.255221850 */, 10 },
- /* 66 */ { MAD_F(0x042ae32a) /* 0.260470548 */, 10 },
- /* 67 */ { MAD_F(0x04407eb1) /* 0.265745823 */, 10 },
- /* 68 */ { MAD_F(0x045635cf) /* 0.271047409 */, 10 },
- /* 69 */ { MAD_F(0x046c083e) /* 0.276375048 */, 10 },
- /* 70 */ { MAD_F(0x0481f5bb) /* 0.281728487 */, 10 },
- /* 71 */ { MAD_F(0x0497fe03) /* 0.287107481 */, 10 },
- /* 72 */ { MAD_F(0x04ae20d7) /* 0.292511788 */, 10 },
- /* 73 */ { MAD_F(0x04c45df6) /* 0.297941173 */, 10 },
- /* 74 */ { MAD_F(0x04dab524) /* 0.303395408 */, 10 },
- /* 75 */ { MAD_F(0x04f12624) /* 0.308874267 */, 10 },
- /* 76 */ { MAD_F(0x0507b0bc) /* 0.314377532 */, 10 },
- /* 77 */ { MAD_F(0x051e54b1) /* 0.319904987 */, 10 },
- /* 78 */ { MAD_F(0x053511cb) /* 0.325456423 */, 10 },
- /* 79 */ { MAD_F(0x054be7d4) /* 0.331031635 */, 10 },
-
- /* 80 */ { MAD_F(0x0562d694) /* 0.336630420 */, 10 },
- /* 81 */ { MAD_F(0x0579ddd8) /* 0.342252584 */, 10 },
- /* 82 */ { MAD_F(0x0590fd6c) /* 0.347897931 */, 10 },
- /* 83 */ { MAD_F(0x05a8351c) /* 0.353566275 */, 10 },
- /* 84 */ { MAD_F(0x05bf84b8) /* 0.359257429 */, 10 },
- /* 85 */ { MAD_F(0x05d6ec0e) /* 0.364971213 */, 10 },
- /* 86 */ { MAD_F(0x05ee6aef) /* 0.370707448 */, 10 },
- /* 87 */ { MAD_F(0x0606012b) /* 0.376465960 */, 10 },
- /* 88 */ { MAD_F(0x061dae96) /* 0.382246578 */, 10 },
- /* 89 */ { MAD_F(0x06357302) /* 0.388049134 */, 10 },
- /* 90 */ { MAD_F(0x064d4e43) /* 0.393873464 */, 10 },
- /* 91 */ { MAD_F(0x0665402d) /* 0.399719406 */, 10 },
- /* 92 */ { MAD_F(0x067d4896) /* 0.405586801 */, 10 },
- /* 93 */ { MAD_F(0x06956753) /* 0.411475493 */, 10 },
- /* 94 */ { MAD_F(0x06ad9c3d) /* 0.417385331 */, 10 },
- /* 95 */ { MAD_F(0x06c5e72b) /* 0.423316162 */, 10 },
-
- /* 96 */ { MAD_F(0x06de47f4) /* 0.429267841 */, 10 },
- /* 97 */ { MAD_F(0x06f6be73) /* 0.435240221 */, 10 },
- /* 98 */ { MAD_F(0x070f4a80) /* 0.441233161 */, 10 },
- /* 99 */ { MAD_F(0x0727ebf7) /* 0.447246519 */, 10 },
- /* 100 */ { MAD_F(0x0740a2b2) /* 0.453280160 */, 10 },
- /* 101 */ { MAD_F(0x07596e8d) /* 0.459333946 */, 10 },
- /* 102 */ { MAD_F(0x07724f64) /* 0.465407744 */, 10 },
- /* 103 */ { MAD_F(0x078b4514) /* 0.471501425 */, 10 },
- /* 104 */ { MAD_F(0x07a44f7a) /* 0.477614858 */, 10 },
- /* 105 */ { MAD_F(0x07bd6e75) /* 0.483747918 */, 10 },
- /* 106 */ { MAD_F(0x07d6a1e2) /* 0.489900479 */, 10 },
- /* 107 */ { MAD_F(0x07efe9a1) /* 0.496072418 */, 10 },
- /* 108 */ { MAD_F(0x0404a2c9) /* 0.251131807 */, 11 },
- /* 109 */ { MAD_F(0x04115aca) /* 0.254236974 */, 11 },
- /* 110 */ { MAD_F(0x041e1cc4) /* 0.257351652 */, 11 },
- /* 111 */ { MAD_F(0x042ae8a7) /* 0.260475783 */, 11 },
-
- /* 112 */ { MAD_F(0x0437be65) /* 0.263609310 */, 11 },
- /* 113 */ { MAD_F(0x04449dee) /* 0.266752177 */, 11 },
- /* 114 */ { MAD_F(0x04518733) /* 0.269904329 */, 11 },
- /* 115 */ { MAD_F(0x045e7a26) /* 0.273065710 */, 11 },
- /* 116 */ { MAD_F(0x046b76b9) /* 0.276236269 */, 11 },
- /* 117 */ { MAD_F(0x04787cdc) /* 0.279415952 */, 11 },
- /* 118 */ { MAD_F(0x04858c83) /* 0.282604707 */, 11 },
- /* 119 */ { MAD_F(0x0492a59f) /* 0.285802482 */, 11 },
- /* 120 */ { MAD_F(0x049fc824) /* 0.289009227 */, 11 },
- /* 121 */ { MAD_F(0x04acf402) /* 0.292224893 */, 11 },
- /* 122 */ { MAD_F(0x04ba292e) /* 0.295449429 */, 11 },
- /* 123 */ { MAD_F(0x04c7679a) /* 0.298682788 */, 11 },
- /* 124 */ { MAD_F(0x04d4af3a) /* 0.301924921 */, 11 },
- /* 125 */ { MAD_F(0x04e20000) /* 0.305175781 */, 11 },
- /* 126 */ { MAD_F(0x04ef59e0) /* 0.308435322 */, 11 },
- /* 127 */ { MAD_F(0x04fcbcce) /* 0.311703498 */, 11 },
-
- /* 128 */ { MAD_F(0x050a28be) /* 0.314980262 */, 11 },
- /* 129 */ { MAD_F(0x05179da4) /* 0.318265572 */, 11 },
- /* 130 */ { MAD_F(0x05251b73) /* 0.321559381 */, 11 },
- /* 131 */ { MAD_F(0x0532a220) /* 0.324861647 */, 11 },
- /* 132 */ { MAD_F(0x054031a0) /* 0.328172327 */, 11 },
- /* 133 */ { MAD_F(0x054dc9e7) /* 0.331491377 */, 11 },
- /* 134 */ { MAD_F(0x055b6ae9) /* 0.334818756 */, 11 },
- /* 135 */ { MAD_F(0x0569149c) /* 0.338154423 */, 11 },
- /* 136 */ { MAD_F(0x0576c6f5) /* 0.341498336 */, 11 },
- /* 137 */ { MAD_F(0x058481e9) /* 0.344850455 */, 11 },
- /* 138 */ { MAD_F(0x0592456d) /* 0.348210741 */, 11 },
- /* 139 */ { MAD_F(0x05a01176) /* 0.351579152 */, 11 },
- /* 140 */ { MAD_F(0x05ade5fa) /* 0.354955651 */, 11 },
- /* 141 */ { MAD_F(0x05bbc2ef) /* 0.358340200 */, 11 },
- /* 142 */ { MAD_F(0x05c9a84a) /* 0.361732758 */, 11 },
- /* 143 */ { MAD_F(0x05d79601) /* 0.365133291 */, 11 },
-
- /* 144 */ { MAD_F(0x05e58c0b) /* 0.368541759 */, 11 },
- /* 145 */ { MAD_F(0x05f38a5d) /* 0.371958126 */, 11 },
- /* 146 */ { MAD_F(0x060190ee) /* 0.375382356 */, 11 },
- /* 147 */ { MAD_F(0x060f9fb3) /* 0.378814413 */, 11 },
- /* 148 */ { MAD_F(0x061db6a5) /* 0.382254261 */, 11 },
- /* 149 */ { MAD_F(0x062bd5b8) /* 0.385701865 */, 11 },
- /* 150 */ { MAD_F(0x0639fce4) /* 0.389157191 */, 11 },
- /* 151 */ { MAD_F(0x06482c1f) /* 0.392620204 */, 11 },
- /* 152 */ { MAD_F(0x06566361) /* 0.396090870 */, 11 },
- /* 153 */ { MAD_F(0x0664a2a0) /* 0.399569155 */, 11 },
- /* 154 */ { MAD_F(0x0672e9d4) /* 0.403055027 */, 11 },
- /* 155 */ { MAD_F(0x068138f3) /* 0.406548452 */, 11 },
- /* 156 */ { MAD_F(0x068f8ff5) /* 0.410049398 */, 11 },
- /* 157 */ { MAD_F(0x069deed1) /* 0.413557833 */, 11 },
- /* 158 */ { MAD_F(0x06ac557f) /* 0.417073724 */, 11 },
- /* 159 */ { MAD_F(0x06bac3f6) /* 0.420597041 */, 11 },
-
- /* 160 */ { MAD_F(0x06c93a2e) /* 0.424127753 */, 11 },
- /* 161 */ { MAD_F(0x06d7b81f) /* 0.427665827 */, 11 },
- /* 162 */ { MAD_F(0x06e63dc0) /* 0.431211234 */, 11 },
- /* 163 */ { MAD_F(0x06f4cb09) /* 0.434763944 */, 11 },
- /* 164 */ { MAD_F(0x07035ff3) /* 0.438323927 */, 11 },
- /* 165 */ { MAD_F(0x0711fc75) /* 0.441891153 */, 11 },
- /* 166 */ { MAD_F(0x0720a087) /* 0.445465593 */, 11 },
- /* 167 */ { MAD_F(0x072f4c22) /* 0.449047217 */, 11 },
- /* 168 */ { MAD_F(0x073dff3e) /* 0.452635998 */, 11 },
- /* 169 */ { MAD_F(0x074cb9d3) /* 0.456231906 */, 11 },
- /* 170 */ { MAD_F(0x075b7bdb) /* 0.459834914 */, 11 },
- /* 171 */ { MAD_F(0x076a454c) /* 0.463444993 */, 11 },
- /* 172 */ { MAD_F(0x07791620) /* 0.467062117 */, 11 },
- /* 173 */ { MAD_F(0x0787ee50) /* 0.470686258 */, 11 },
- /* 174 */ { MAD_F(0x0796cdd4) /* 0.474317388 */, 11 },
- /* 175 */ { MAD_F(0x07a5b4a5) /* 0.477955481 */, 11 },
-
- /* 176 */ { MAD_F(0x07b4a2bc) /* 0.481600510 */, 11 },
- /* 177 */ { MAD_F(0x07c39812) /* 0.485252449 */, 11 },
- /* 178 */ { MAD_F(0x07d294a0) /* 0.488911273 */, 11 },
- /* 179 */ { MAD_F(0x07e1985f) /* 0.492576954 */, 11 },
- /* 180 */ { MAD_F(0x07f0a348) /* 0.496249468 */, 11 },
- /* 181 */ { MAD_F(0x07ffb554) /* 0.499928790 */, 11 },
- /* 182 */ { MAD_F(0x0407673f) /* 0.251807447 */, 12 },
- /* 183 */ { MAD_F(0x040ef75e) /* 0.253653877 */, 12 },
- /* 184 */ { MAD_F(0x04168b05) /* 0.255503674 */, 12 },
- /* 185 */ { MAD_F(0x041e2230) /* 0.257356825 */, 12 },
- /* 186 */ { MAD_F(0x0425bcdd) /* 0.259213318 */, 12 },
- /* 187 */ { MAD_F(0x042d5b07) /* 0.261073141 */, 12 },
- /* 188 */ { MAD_F(0x0434fcad) /* 0.262936282 */, 12 },
- /* 189 */ { MAD_F(0x043ca1c9) /* 0.264802730 */, 12 },
- /* 190 */ { MAD_F(0x04444a5a) /* 0.266672472 */, 12 },
- /* 191 */ { MAD_F(0x044bf65d) /* 0.268545497 */, 12 },
-
- /* 192 */ { MAD_F(0x0453a5cd) /* 0.270421794 */, 12 },
- /* 193 */ { MAD_F(0x045b58a9) /* 0.272301352 */, 12 },
- /* 194 */ { MAD_F(0x04630eed) /* 0.274184158 */, 12 },
- /* 195 */ { MAD_F(0x046ac896) /* 0.276070203 */, 12 },
- /* 196 */ { MAD_F(0x047285a2) /* 0.277959474 */, 12 },
- /* 197 */ { MAD_F(0x047a460c) /* 0.279851960 */, 12 },
- /* 198 */ { MAD_F(0x048209d3) /* 0.281747652 */, 12 },
- /* 199 */ { MAD_F(0x0489d0f4) /* 0.283646538 */, 12 },
- /* 200 */ { MAD_F(0x04919b6a) /* 0.285548607 */, 12 },
- /* 201 */ { MAD_F(0x04996935) /* 0.287453849 */, 12 },
- /* 202 */ { MAD_F(0x04a13a50) /* 0.289362253 */, 12 },
- /* 203 */ { MAD_F(0x04a90eba) /* 0.291273810 */, 12 },
- /* 204 */ { MAD_F(0x04b0e66e) /* 0.293188507 */, 12 },
- /* 205 */ { MAD_F(0x04b8c16c) /* 0.295106336 */, 12 },
- /* 206 */ { MAD_F(0x04c09faf) /* 0.297027285 */, 12 },
- /* 207 */ { MAD_F(0x04c88135) /* 0.298951346 */, 12 },
-
- /* 208 */ { MAD_F(0x04d065fb) /* 0.300878507 */, 12 },
- /* 209 */ { MAD_F(0x04d84dff) /* 0.302808759 */, 12 },
- /* 210 */ { MAD_F(0x04e0393e) /* 0.304742092 */, 12 },
- /* 211 */ { MAD_F(0x04e827b6) /* 0.306678497 */, 12 },
- /* 212 */ { MAD_F(0x04f01963) /* 0.308617963 */, 12 },
- /* 213 */ { MAD_F(0x04f80e44) /* 0.310560480 */, 12 },
- /* 214 */ { MAD_F(0x05000655) /* 0.312506041 */, 12 },
- /* 215 */ { MAD_F(0x05080195) /* 0.314454634 */, 12 },
- /* 216 */ { MAD_F(0x05100000) /* 0.316406250 */, 12 },
- /* 217 */ { MAD_F(0x05180194) /* 0.318360880 */, 12 },
- /* 218 */ { MAD_F(0x0520064f) /* 0.320318516 */, 12 },
- /* 219 */ { MAD_F(0x05280e2d) /* 0.322279147 */, 12 },
- /* 220 */ { MAD_F(0x0530192e) /* 0.324242764 */, 12 },
- /* 221 */ { MAD_F(0x0538274e) /* 0.326209359 */, 12 },
- /* 222 */ { MAD_F(0x0540388a) /* 0.328178922 */, 12 },
- /* 223 */ { MAD_F(0x05484ce2) /* 0.330151445 */, 12 },
-
- /* 224 */ { MAD_F(0x05506451) /* 0.332126919 */, 12 },
- /* 225 */ { MAD_F(0x05587ed5) /* 0.334105334 */, 12 },
- /* 226 */ { MAD_F(0x05609c6e) /* 0.336086683 */, 12 },
- /* 227 */ { MAD_F(0x0568bd17) /* 0.338070956 */, 12 },
- /* 228 */ { MAD_F(0x0570e0cf) /* 0.340058145 */, 12 },
- /* 229 */ { MAD_F(0x05790793) /* 0.342048241 */, 12 },
- /* 230 */ { MAD_F(0x05813162) /* 0.344041237 */, 12 },
- /* 231 */ { MAD_F(0x05895e39) /* 0.346037122 */, 12 },
- /* 232 */ { MAD_F(0x05918e15) /* 0.348035890 */, 12 },
- /* 233 */ { MAD_F(0x0599c0f4) /* 0.350037532 */, 12 },
- /* 234 */ { MAD_F(0x05a1f6d5) /* 0.352042040 */, 12 },
- /* 235 */ { MAD_F(0x05aa2fb5) /* 0.354049405 */, 12 },
- /* 236 */ { MAD_F(0x05b26b92) /* 0.356059619 */, 12 },
- /* 237 */ { MAD_F(0x05baaa69) /* 0.358072674 */, 12 },
- /* 238 */ { MAD_F(0x05c2ec39) /* 0.360088563 */, 12 },
- /* 239 */ { MAD_F(0x05cb3100) /* 0.362107278 */, 12 },
-
- /* 240 */ { MAD_F(0x05d378bb) /* 0.364128809 */, 12 },
- /* 241 */ { MAD_F(0x05dbc368) /* 0.366153151 */, 12 },
- /* 242 */ { MAD_F(0x05e41105) /* 0.368180294 */, 12 },
- /* 243 */ { MAD_F(0x05ec6190) /* 0.370210231 */, 12 },
- /* 244 */ { MAD_F(0x05f4b507) /* 0.372242955 */, 12 },
- /* 245 */ { MAD_F(0x05fd0b68) /* 0.374278458 */, 12 },
- /* 246 */ { MAD_F(0x060564b1) /* 0.376316732 */, 12 },
- /* 247 */ { MAD_F(0x060dc0e0) /* 0.378357769 */, 12 },
- /* 248 */ { MAD_F(0x06161ff3) /* 0.380401563 */, 12 },
- /* 249 */ { MAD_F(0x061e81e8) /* 0.382448106 */, 12 },
- /* 250 */ { MAD_F(0x0626e6bc) /* 0.384497391 */, 12 },
- /* 251 */ { MAD_F(0x062f4e6f) /* 0.386549409 */, 12 },
- /* 252 */ { MAD_F(0x0637b8fd) /* 0.388604155 */, 12 },
- /* 253 */ { MAD_F(0x06402666) /* 0.390661620 */, 12 },
- /* 254 */ { MAD_F(0x064896a7) /* 0.392721798 */, 12 },
- /* 255 */ { MAD_F(0x065109be) /* 0.394784681 */, 12 },
-
- /* 256 */ { MAD_F(0x06597fa9) /* 0.396850263 */, 12 },
- /* 257 */ { MAD_F(0x0661f867) /* 0.398918536 */, 12 },
- /* 258 */ { MAD_F(0x066a73f5) /* 0.400989493 */, 12 },
- /* 259 */ { MAD_F(0x0672f252) /* 0.403063128 */, 12 },
- /* 260 */ { MAD_F(0x067b737c) /* 0.405139433 */, 12 },
- /* 261 */ { MAD_F(0x0683f771) /* 0.407218402 */, 12 },
- /* 262 */ { MAD_F(0x068c7e2f) /* 0.409300027 */, 12 },
- /* 263 */ { MAD_F(0x069507b5) /* 0.411384303 */, 12 },
- /* 264 */ { MAD_F(0x069d9400) /* 0.413471222 */, 12 },
- /* 265 */ { MAD_F(0x06a6230f) /* 0.415560778 */, 12 },
- /* 266 */ { MAD_F(0x06aeb4e0) /* 0.417652964 */, 12 },
- /* 267 */ { MAD_F(0x06b74971) /* 0.419747773 */, 12 },
- /* 268 */ { MAD_F(0x06bfe0c0) /* 0.421845199 */, 12 },
- /* 269 */ { MAD_F(0x06c87acc) /* 0.423945235 */, 12 },
- /* 270 */ { MAD_F(0x06d11794) /* 0.426047876 */, 12 },
- /* 271 */ { MAD_F(0x06d9b714) /* 0.428153114 */, 12 },
-
- /* 272 */ { MAD_F(0x06e2594c) /* 0.430260942 */, 12 },
- /* 273 */ { MAD_F(0x06eafe3a) /* 0.432371356 */, 12 },
- /* 274 */ { MAD_F(0x06f3a5dc) /* 0.434484348 */, 12 },
- /* 275 */ { MAD_F(0x06fc5030) /* 0.436599912 */, 12 },
- /* 276 */ { MAD_F(0x0704fd35) /* 0.438718042 */, 12 },
- /* 277 */ { MAD_F(0x070dacea) /* 0.440838732 */, 12 },
- /* 278 */ { MAD_F(0x07165f4b) /* 0.442961975 */, 12 },
- /* 279 */ { MAD_F(0x071f1459) /* 0.445087765 */, 12 },
- /* 280 */ { MAD_F(0x0727cc11) /* 0.447216097 */, 12 },
- /* 281 */ { MAD_F(0x07308671) /* 0.449346964 */, 12 },
- /* 282 */ { MAD_F(0x07394378) /* 0.451480360 */, 12 },
- /* 283 */ { MAD_F(0x07420325) /* 0.453616280 */, 12 },
- /* 284 */ { MAD_F(0x074ac575) /* 0.455754717 */, 12 },
- /* 285 */ { MAD_F(0x07538a67) /* 0.457895665 */, 12 },
- /* 286 */ { MAD_F(0x075c51fa) /* 0.460039119 */, 12 },
- /* 287 */ { MAD_F(0x07651c2c) /* 0.462185072 */, 12 },
-
- /* 288 */ { MAD_F(0x076de8fc) /* 0.464333519 */, 12 },
- /* 289 */ { MAD_F(0x0776b867) /* 0.466484455 */, 12 },
- /* 290 */ { MAD_F(0x077f8a6d) /* 0.468637872 */, 12 },
- /* 291 */ { MAD_F(0x07885f0b) /* 0.470793767 */, 12 },
- /* 292 */ { MAD_F(0x07913641) /* 0.472952132 */, 12 },
- /* 293 */ { MAD_F(0x079a100c) /* 0.475112962 */, 12 },
- /* 294 */ { MAD_F(0x07a2ec6c) /* 0.477276252 */, 12 },
- /* 295 */ { MAD_F(0x07abcb5f) /* 0.479441997 */, 12 },
- /* 296 */ { MAD_F(0x07b4ace3) /* 0.481610189 */, 12 },
- /* 297 */ { MAD_F(0x07bd90f6) /* 0.483780825 */, 12 },
- /* 298 */ { MAD_F(0x07c67798) /* 0.485953899 */, 12 },
- /* 299 */ { MAD_F(0x07cf60c7) /* 0.488129404 */, 12 },
- /* 300 */ { MAD_F(0x07d84c81) /* 0.490307336 */, 12 },
- /* 301 */ { MAD_F(0x07e13ac5) /* 0.492487690 */, 12 },
- /* 302 */ { MAD_F(0x07ea2b92) /* 0.494670459 */, 12 },
- /* 303 */ { MAD_F(0x07f31ee6) /* 0.496855639 */, 12 },
-
- /* 304 */ { MAD_F(0x07fc14bf) /* 0.499043224 */, 12 },
- /* 305 */ { MAD_F(0x0402868e) /* 0.250616605 */, 13 },
- /* 306 */ { MAD_F(0x040703ff) /* 0.251712795 */, 13 },
- /* 307 */ { MAD_F(0x040b82b0) /* 0.252810180 */, 13 },
- /* 308 */ { MAD_F(0x041002a1) /* 0.253908756 */, 13 },
- /* 309 */ { MAD_F(0x041483d1) /* 0.255008523 */, 13 },
- /* 310 */ { MAD_F(0x04190640) /* 0.256109476 */, 13 },
- /* 311 */ { MAD_F(0x041d89ed) /* 0.257211614 */, 13 },
- /* 312 */ { MAD_F(0x04220ed7) /* 0.258314934 */, 13 },
- /* 313 */ { MAD_F(0x042694fe) /* 0.259419433 */, 13 },
- /* 314 */ { MAD_F(0x042b1c60) /* 0.260525110 */, 13 },
- /* 315 */ { MAD_F(0x042fa4fe) /* 0.261631960 */, 13 },
- /* 316 */ { MAD_F(0x04342ed7) /* 0.262739982 */, 13 },
- /* 317 */ { MAD_F(0x0438b9e9) /* 0.263849174 */, 13 },
- /* 318 */ { MAD_F(0x043d4635) /* 0.264959533 */, 13 },
- /* 319 */ { MAD_F(0x0441d3b9) /* 0.266071056 */, 13 },
-
- /* 320 */ { MAD_F(0x04466275) /* 0.267183742 */, 13 },
- /* 321 */ { MAD_F(0x044af269) /* 0.268297587 */, 13 },
- /* 322 */ { MAD_F(0x044f8393) /* 0.269412589 */, 13 },
- /* 323 */ { MAD_F(0x045415f3) /* 0.270528746 */, 13 },
- /* 324 */ { MAD_F(0x0458a989) /* 0.271646056 */, 13 },
- /* 325 */ { MAD_F(0x045d3e53) /* 0.272764515 */, 13 },
- /* 326 */ { MAD_F(0x0461d451) /* 0.273884123 */, 13 },
- /* 327 */ { MAD_F(0x04666b83) /* 0.275004875 */, 13 },
- /* 328 */ { MAD_F(0x046b03e7) /* 0.276126771 */, 13 },
- /* 329 */ { MAD_F(0x046f9d7e) /* 0.277249808 */, 13 },
- /* 330 */ { MAD_F(0x04743847) /* 0.278373983 */, 13 },
- /* 331 */ { MAD_F(0x0478d440) /* 0.279499294 */, 13 },
- /* 332 */ { MAD_F(0x047d716a) /* 0.280625739 */, 13 },
- /* 333 */ { MAD_F(0x04820fc3) /* 0.281753315 */, 13 },
- /* 334 */ { MAD_F(0x0486af4c) /* 0.282882021 */, 13 },
- /* 335 */ { MAD_F(0x048b5003) /* 0.284011853 */, 13 },
-
- /* 336 */ { MAD_F(0x048ff1e8) /* 0.285142811 */, 13 },
- /* 337 */ { MAD_F(0x049494fb) /* 0.286274891 */, 13 },
- /* 338 */ { MAD_F(0x0499393a) /* 0.287408091 */, 13 },
- /* 339 */ { MAD_F(0x049ddea5) /* 0.288542409 */, 13 },
- /* 340 */ { MAD_F(0x04a2853c) /* 0.289677844 */, 13 },
- /* 341 */ { MAD_F(0x04a72cfe) /* 0.290814392 */, 13 },
- /* 342 */ { MAD_F(0x04abd5ea) /* 0.291952051 */, 13 },
- /* 343 */ { MAD_F(0x04b08000) /* 0.293090820 */, 13 },
- /* 344 */ { MAD_F(0x04b52b3f) /* 0.294230696 */, 13 },
- /* 345 */ { MAD_F(0x04b9d7a7) /* 0.295371678 */, 13 },
- /* 346 */ { MAD_F(0x04be8537) /* 0.296513762 */, 13 },
- /* 347 */ { MAD_F(0x04c333ee) /* 0.297656947 */, 13 },
- /* 348 */ { MAD_F(0x04c7e3cc) /* 0.298801231 */, 13 },
- /* 349 */ { MAD_F(0x04cc94d1) /* 0.299946611 */, 13 },
- /* 350 */ { MAD_F(0x04d146fb) /* 0.301093085 */, 13 },
- /* 351 */ { MAD_F(0x04d5fa4b) /* 0.302240653 */, 13 },
-
- /* 352 */ { MAD_F(0x04daaec0) /* 0.303389310 */, 13 },
- /* 353 */ { MAD_F(0x04df6458) /* 0.304539056 */, 13 },
- /* 354 */ { MAD_F(0x04e41b14) /* 0.305689888 */, 13 },
- /* 355 */ { MAD_F(0x04e8d2f3) /* 0.306841804 */, 13 },
- /* 356 */ { MAD_F(0x04ed8bf5) /* 0.307994802 */, 13 },
- /* 357 */ { MAD_F(0x04f24618) /* 0.309148880 */, 13 },
- /* 358 */ { MAD_F(0x04f7015d) /* 0.310304037 */, 13 },
- /* 359 */ { MAD_F(0x04fbbdc3) /* 0.311460269 */, 13 },
- /* 360 */ { MAD_F(0x05007b49) /* 0.312617576 */, 13 },
- /* 361 */ { MAD_F(0x050539ef) /* 0.313775954 */, 13 },
- /* 362 */ { MAD_F(0x0509f9b4) /* 0.314935403 */, 13 },
- /* 363 */ { MAD_F(0x050eba98) /* 0.316095920 */, 13 },
- /* 364 */ { MAD_F(0x05137c9a) /* 0.317257503 */, 13 },
- /* 365 */ { MAD_F(0x05183fba) /* 0.318420150 */, 13 },
- /* 366 */ { MAD_F(0x051d03f7) /* 0.319583859 */, 13 },
- /* 367 */ { MAD_F(0x0521c950) /* 0.320748629 */, 13 },
-
- /* 368 */ { MAD_F(0x05268fc6) /* 0.321914457 */, 13 },
- /* 369 */ { MAD_F(0x052b5757) /* 0.323081342 */, 13 },
- /* 370 */ { MAD_F(0x05302003) /* 0.324249281 */, 13 },
- /* 371 */ { MAD_F(0x0534e9ca) /* 0.325418273 */, 13 },
- /* 372 */ { MAD_F(0x0539b4ab) /* 0.326588316 */, 13 },
- /* 373 */ { MAD_F(0x053e80a6) /* 0.327759407 */, 13 },
- /* 374 */ { MAD_F(0x05434db9) /* 0.328931546 */, 13 },
- /* 375 */ { MAD_F(0x05481be5) /* 0.330104730 */, 13 },
- /* 376 */ { MAD_F(0x054ceb2a) /* 0.331278957 */, 13 },
- /* 377 */ { MAD_F(0x0551bb85) /* 0.332454225 */, 13 },
- /* 378 */ { MAD_F(0x05568cf8) /* 0.333630533 */, 13 },
- /* 379 */ { MAD_F(0x055b5f81) /* 0.334807879 */, 13 },
- /* 380 */ { MAD_F(0x05603321) /* 0.335986261 */, 13 },
- /* 381 */ { MAD_F(0x056507d6) /* 0.337165677 */, 13 },
- /* 382 */ { MAD_F(0x0569dda0) /* 0.338346125 */, 13 },
- /* 383 */ { MAD_F(0x056eb47f) /* 0.339527604 */, 13 },
-
- /* 384 */ { MAD_F(0x05738c72) /* 0.340710111 */, 13 },
- /* 385 */ { MAD_F(0x05786578) /* 0.341893646 */, 13 },
- /* 386 */ { MAD_F(0x057d3f92) /* 0.343078205 */, 13 },
- /* 387 */ { MAD_F(0x05821abf) /* 0.344263788 */, 13 },
- /* 388 */ { MAD_F(0x0586f6fd) /* 0.345450393 */, 13 },
- /* 389 */ { MAD_F(0x058bd44e) /* 0.346638017 */, 13 },
- /* 390 */ { MAD_F(0x0590b2b0) /* 0.347826659 */, 13 },
- /* 391 */ { MAD_F(0x05959222) /* 0.349016318 */, 13 },
- /* 392 */ { MAD_F(0x059a72a5) /* 0.350206992 */, 13 },
- /* 393 */ { MAD_F(0x059f5438) /* 0.351398678 */, 13 },
- /* 394 */ { MAD_F(0x05a436da) /* 0.352591376 */, 13 },
- /* 395 */ { MAD_F(0x05a91a8c) /* 0.353785083 */, 13 },
- /* 396 */ { MAD_F(0x05adff4c) /* 0.354979798 */, 13 },
- /* 397 */ { MAD_F(0x05b2e51a) /* 0.356175519 */, 13 },
- /* 398 */ { MAD_F(0x05b7cbf5) /* 0.357372244 */, 13 },
- /* 399 */ { MAD_F(0x05bcb3de) /* 0.358569972 */, 13 },
-
- /* 400 */ { MAD_F(0x05c19cd3) /* 0.359768701 */, 13 },
- /* 401 */ { MAD_F(0x05c686d5) /* 0.360968429 */, 13 },
- /* 402 */ { MAD_F(0x05cb71e2) /* 0.362169156 */, 13 },
- /* 403 */ { MAD_F(0x05d05dfb) /* 0.363370878 */, 13 },
- /* 404 */ { MAD_F(0x05d54b1f) /* 0.364573594 */, 13 },
- /* 405 */ { MAD_F(0x05da394d) /* 0.365777304 */, 13 },
- /* 406 */ { MAD_F(0x05df2885) /* 0.366982004 */, 13 },
- /* 407 */ { MAD_F(0x05e418c7) /* 0.368187694 */, 13 },
- /* 408 */ { MAD_F(0x05e90a12) /* 0.369394372 */, 13 },
- /* 409 */ { MAD_F(0x05edfc66) /* 0.370602036 */, 13 },
- /* 410 */ { MAD_F(0x05f2efc2) /* 0.371810684 */, 13 },
- /* 411 */ { MAD_F(0x05f7e426) /* 0.373020316 */, 13 },
- /* 412 */ { MAD_F(0x05fcd992) /* 0.374230929 */, 13 },
- /* 413 */ { MAD_F(0x0601d004) /* 0.375442522 */, 13 },
- /* 414 */ { MAD_F(0x0606c77d) /* 0.376655093 */, 13 },
- /* 415 */ { MAD_F(0x060bbffd) /* 0.377868641 */, 13 },
-
- /* 416 */ { MAD_F(0x0610b982) /* 0.379083164 */, 13 },
- /* 417 */ { MAD_F(0x0615b40c) /* 0.380298661 */, 13 },
- /* 418 */ { MAD_F(0x061aaf9c) /* 0.381515130 */, 13 },
- /* 419 */ { MAD_F(0x061fac2f) /* 0.382732569 */, 13 },
- /* 420 */ { MAD_F(0x0624a9c7) /* 0.383950977 */, 13 },
- /* 421 */ { MAD_F(0x0629a863) /* 0.385170352 */, 13 },
- /* 422 */ { MAD_F(0x062ea802) /* 0.386390694 */, 13 },
- /* 423 */ { MAD_F(0x0633a8a3) /* 0.387611999 */, 13 },
- /* 424 */ { MAD_F(0x0638aa48) /* 0.388834268 */, 13 },
- /* 425 */ { MAD_F(0x063dacee) /* 0.390057497 */, 13 },
- /* 426 */ { MAD_F(0x0642b096) /* 0.391281687 */, 13 },
- /* 427 */ { MAD_F(0x0647b53f) /* 0.392506834 */, 13 },
- /* 428 */ { MAD_F(0x064cbae9) /* 0.393732939 */, 13 },
- /* 429 */ { MAD_F(0x0651c193) /* 0.394959999 */, 13 },
- /* 430 */ { MAD_F(0x0656c93d) /* 0.396188012 */, 13 },
- /* 431 */ { MAD_F(0x065bd1e7) /* 0.397416978 */, 13 },
-
- /* 432 */ { MAD_F(0x0660db91) /* 0.398646895 */, 13 },
- /* 433 */ { MAD_F(0x0665e639) /* 0.399877761 */, 13 },
- /* 434 */ { MAD_F(0x066af1df) /* 0.401109575 */, 13 },
- /* 435 */ { MAD_F(0x066ffe84) /* 0.402342335 */, 13 },
- /* 436 */ { MAD_F(0x06750c26) /* 0.403576041 */, 13 },
- /* 437 */ { MAD_F(0x067a1ac6) /* 0.404810690 */, 13 },
- /* 438 */ { MAD_F(0x067f2a62) /* 0.406046281 */, 13 },
- /* 439 */ { MAD_F(0x06843afb) /* 0.407282813 */, 13 },
- /* 440 */ { MAD_F(0x06894c90) /* 0.408520284 */, 13 },
- /* 441 */ { MAD_F(0x068e5f21) /* 0.409758693 */, 13 },
- /* 442 */ { MAD_F(0x069372ae) /* 0.410998038 */, 13 },
- /* 443 */ { MAD_F(0x06988735) /* 0.412238319 */, 13 },
- /* 444 */ { MAD_F(0x069d9cb7) /* 0.413479532 */, 13 },
- /* 445 */ { MAD_F(0x06a2b333) /* 0.414721679 */, 13 },
- /* 446 */ { MAD_F(0x06a7caa9) /* 0.415964756 */, 13 },
- /* 447 */ { MAD_F(0x06ace318) /* 0.417208762 */, 13 },
-
- /* 448 */ { MAD_F(0x06b1fc81) /* 0.418453696 */, 13 },
- /* 449 */ { MAD_F(0x06b716e2) /* 0.419699557 */, 13 },
- /* 450 */ { MAD_F(0x06bc323b) /* 0.420946343 */, 13 },
- /* 451 */ { MAD_F(0x06c14e8d) /* 0.422194054 */, 13 },
- /* 452 */ { MAD_F(0x06c66bd6) /* 0.423442686 */, 13 },
- /* 453 */ { MAD_F(0x06cb8a17) /* 0.424692240 */, 13 },
- /* 454 */ { MAD_F(0x06d0a94e) /* 0.425942714 */, 13 },
- /* 455 */ { MAD_F(0x06d5c97c) /* 0.427194106 */, 13 },
- /* 456 */ { MAD_F(0x06daeaa1) /* 0.428446415 */, 13 },
- /* 457 */ { MAD_F(0x06e00cbb) /* 0.429699640 */, 13 },
- /* 458 */ { MAD_F(0x06e52fca) /* 0.430953779 */, 13 },
- /* 459 */ { MAD_F(0x06ea53cf) /* 0.432208832 */, 13 },
- /* 460 */ { MAD_F(0x06ef78c8) /* 0.433464796 */, 13 },
- /* 461 */ { MAD_F(0x06f49eb6) /* 0.434721671 */, 13 },
- /* 462 */ { MAD_F(0x06f9c597) /* 0.435979455 */, 13 },
- /* 463 */ { MAD_F(0x06feed6d) /* 0.437238146 */, 13 },
-
- /* 464 */ { MAD_F(0x07041636) /* 0.438497744 */, 13 },
- /* 465 */ { MAD_F(0x07093ff2) /* 0.439758248 */, 13 },
- /* 466 */ { MAD_F(0x070e6aa0) /* 0.441019655 */, 13 },
- /* 467 */ { MAD_F(0x07139641) /* 0.442281965 */, 13 },
- /* 468 */ { MAD_F(0x0718c2d3) /* 0.443545176 */, 13 },
- /* 469 */ { MAD_F(0x071df058) /* 0.444809288 */, 13 },
- /* 470 */ { MAD_F(0x07231ecd) /* 0.446074298 */, 13 },
- /* 471 */ { MAD_F(0x07284e34) /* 0.447340205 */, 13 },
- /* 472 */ { MAD_F(0x072d7e8b) /* 0.448607009 */, 13 },
- /* 473 */ { MAD_F(0x0732afd2) /* 0.449874708 */, 13 },
- /* 474 */ { MAD_F(0x0737e209) /* 0.451143300 */, 13 },
- /* 475 */ { MAD_F(0x073d1530) /* 0.452412785 */, 13 },
- /* 476 */ { MAD_F(0x07424946) /* 0.453683161 */, 13 },
- /* 477 */ { MAD_F(0x07477e4b) /* 0.454954427 */, 13 },
- /* 478 */ { MAD_F(0x074cb43e) /* 0.456226581 */, 13 },
- /* 479 */ { MAD_F(0x0751eb20) /* 0.457499623 */, 13 },
-
- /* 480 */ { MAD_F(0x075722ef) /* 0.458773552 */, 13 },
- /* 481 */ { MAD_F(0x075c5bac) /* 0.460048365 */, 13 },
- /* 482 */ { MAD_F(0x07619557) /* 0.461324062 */, 13 },
- /* 483 */ { MAD_F(0x0766cfee) /* 0.462600642 */, 13 },
- /* 484 */ { MAD_F(0x076c0b72) /* 0.463878102 */, 13 },
- /* 485 */ { MAD_F(0x077147e2) /* 0.465156443 */, 13 },
- /* 486 */ { MAD_F(0x0776853e) /* 0.466435663 */, 13 },
- /* 487 */ { MAD_F(0x077bc385) /* 0.467715761 */, 13 },
- /* 488 */ { MAD_F(0x078102b8) /* 0.468996735 */, 13 },
- /* 489 */ { MAD_F(0x078642d6) /* 0.470278584 */, 13 },
- /* 490 */ { MAD_F(0x078b83de) /* 0.471561307 */, 13 },
- /* 491 */ { MAD_F(0x0790c5d1) /* 0.472844904 */, 13 },
- /* 492 */ { MAD_F(0x079608ae) /* 0.474129372 */, 13 },
- /* 493 */ { MAD_F(0x079b4c74) /* 0.475414710 */, 13 },
- /* 494 */ { MAD_F(0x07a09124) /* 0.476700918 */, 13 },
- /* 495 */ { MAD_F(0x07a5d6bd) /* 0.477987994 */, 13 },
-
- /* 496 */ { MAD_F(0x07ab1d3e) /* 0.479275937 */, 13 },
- /* 497 */ { MAD_F(0x07b064a8) /* 0.480564746 */, 13 },
- /* 498 */ { MAD_F(0x07b5acfb) /* 0.481854420 */, 13 },
- /* 499 */ { MAD_F(0x07baf635) /* 0.483144957 */, 13 },
- /* 500 */ { MAD_F(0x07c04056) /* 0.484436356 */, 13 },
- /* 501 */ { MAD_F(0x07c58b5f) /* 0.485728617 */, 13 },
- /* 502 */ { MAD_F(0x07cad74e) /* 0.487021738 */, 13 },
- /* 503 */ { MAD_F(0x07d02424) /* 0.488315717 */, 13 },
- /* 504 */ { MAD_F(0x07d571e0) /* 0.489610555 */, 13 },
- /* 505 */ { MAD_F(0x07dac083) /* 0.490906249 */, 13 },
- /* 506 */ { MAD_F(0x07e0100a) /* 0.492202799 */, 13 },
- /* 507 */ { MAD_F(0x07e56078) /* 0.493500203 */, 13 },
- /* 508 */ { MAD_F(0x07eab1ca) /* 0.494798460 */, 13 },
- /* 509 */ { MAD_F(0x07f00401) /* 0.496097570 */, 13 },
- /* 510 */ { MAD_F(0x07f5571d) /* 0.497397530 */, 13 },
- /* 511 */ { MAD_F(0x07faab1c) /* 0.498698341 */, 13 },
-
- /* 512 */ { MAD_F(0x04000000) /* 0.250000000 */, 14 },
- /* 513 */ { MAD_F(0x0402aae3) /* 0.250651254 */, 14 },
- /* 514 */ { MAD_F(0x04055638) /* 0.251302930 */, 14 },
- /* 515 */ { MAD_F(0x040801ff) /* 0.251955030 */, 14 },
- /* 516 */ { MAD_F(0x040aae37) /* 0.252607552 */, 14 },
- /* 517 */ { MAD_F(0x040d5ae0) /* 0.253260495 */, 14 },
- /* 518 */ { MAD_F(0x041007fa) /* 0.253913860 */, 14 },
- /* 519 */ { MAD_F(0x0412b586) /* 0.254567645 */, 14 },
- /* 520 */ { MAD_F(0x04156381) /* 0.255221850 */, 14 },
- /* 521 */ { MAD_F(0x041811ee) /* 0.255876475 */, 14 },
- /* 522 */ { MAD_F(0x041ac0cb) /* 0.256531518 */, 14 },
- /* 523 */ { MAD_F(0x041d7018) /* 0.257186980 */, 14 },
- /* 524 */ { MAD_F(0x04201fd5) /* 0.257842860 */, 14 },
- /* 525 */ { MAD_F(0x0422d003) /* 0.258499157 */, 14 },
- /* 526 */ { MAD_F(0x042580a0) /* 0.259155872 */, 14 },
- /* 527 */ { MAD_F(0x042831ad) /* 0.259813002 */, 14 },
-
- /* 528 */ { MAD_F(0x042ae32a) /* 0.260470548 */, 14 },
- /* 529 */ { MAD_F(0x042d9516) /* 0.261128510 */, 14 },
- /* 530 */ { MAD_F(0x04304772) /* 0.261786886 */, 14 },
- /* 531 */ { MAD_F(0x0432fa3d) /* 0.262445676 */, 14 },
- /* 532 */ { MAD_F(0x0435ad76) /* 0.263104880 */, 14 },
- /* 533 */ { MAD_F(0x0438611f) /* 0.263764497 */, 14 },
- /* 534 */ { MAD_F(0x043b1536) /* 0.264424527 */, 14 },
- /* 535 */ { MAD_F(0x043dc9bc) /* 0.265084969 */, 14 },
- /* 536 */ { MAD_F(0x04407eb1) /* 0.265745823 */, 14 },
- /* 537 */ { MAD_F(0x04433414) /* 0.266407088 */, 14 },
- /* 538 */ { MAD_F(0x0445e9e5) /* 0.267068763 */, 14 },
- /* 539 */ { MAD_F(0x0448a024) /* 0.267730848 */, 14 },
- /* 540 */ { MAD_F(0x044b56d1) /* 0.268393343 */, 14 },
- /* 541 */ { MAD_F(0x044e0dec) /* 0.269056248 */, 14 },
- /* 542 */ { MAD_F(0x0450c575) /* 0.269719560 */, 14 },
- /* 543 */ { MAD_F(0x04537d6b) /* 0.270383281 */, 14 },
-
- /* 544 */ { MAD_F(0x045635cf) /* 0.271047409 */, 14 },
- /* 545 */ { MAD_F(0x0458ee9f) /* 0.271711944 */, 14 },
- /* 546 */ { MAD_F(0x045ba7dd) /* 0.272376886 */, 14 },
- /* 547 */ { MAD_F(0x045e6188) /* 0.273042234 */, 14 },
- /* 548 */ { MAD_F(0x04611ba0) /* 0.273707988 */, 14 },
- /* 549 */ { MAD_F(0x0463d625) /* 0.274374147 */, 14 },
- /* 550 */ { MAD_F(0x04669116) /* 0.275040710 */, 14 },
- /* 551 */ { MAD_F(0x04694c74) /* 0.275707677 */, 14 },
- /* 552 */ { MAD_F(0x046c083e) /* 0.276375048 */, 14 },
- /* 553 */ { MAD_F(0x046ec474) /* 0.277042822 */, 14 },
- /* 554 */ { MAD_F(0x04718116) /* 0.277710999 */, 14 },
- /* 555 */ { MAD_F(0x04743e25) /* 0.278379578 */, 14 },
- /* 556 */ { MAD_F(0x0476fb9f) /* 0.279048558 */, 14 },
- /* 557 */ { MAD_F(0x0479b984) /* 0.279717940 */, 14 },
- /* 558 */ { MAD_F(0x047c77d6) /* 0.280387722 */, 14 },
- /* 559 */ { MAD_F(0x047f3693) /* 0.281057905 */, 14 },
-
- /* 560 */ { MAD_F(0x0481f5bb) /* 0.281728487 */, 14 },
- /* 561 */ { MAD_F(0x0484b54e) /* 0.282399469 */, 14 },
- /* 562 */ { MAD_F(0x0487754c) /* 0.283070849 */, 14 },
- /* 563 */ { MAD_F(0x048a35b6) /* 0.283742628 */, 14 },
- /* 564 */ { MAD_F(0x048cf68a) /* 0.284414805 */, 14 },
- /* 565 */ { MAD_F(0x048fb7c8) /* 0.285087379 */, 14 },
- /* 566 */ { MAD_F(0x04927972) /* 0.285760350 */, 14 },
- /* 567 */ { MAD_F(0x04953b85) /* 0.286433717 */, 14 },
- /* 568 */ { MAD_F(0x0497fe03) /* 0.287107481 */, 14 },
- /* 569 */ { MAD_F(0x049ac0eb) /* 0.287781640 */, 14 },
- /* 570 */ { MAD_F(0x049d843e) /* 0.288456194 */, 14 },
- /* 571 */ { MAD_F(0x04a047fa) /* 0.289131142 */, 14 },
- /* 572 */ { MAD_F(0x04a30c20) /* 0.289806485 */, 14 },
- /* 573 */ { MAD_F(0x04a5d0af) /* 0.290482221 */, 14 },
- /* 574 */ { MAD_F(0x04a895a8) /* 0.291158351 */, 14 },
- /* 575 */ { MAD_F(0x04ab5b0b) /* 0.291834873 */, 14 },
-
- /* 576 */ { MAD_F(0x04ae20d7) /* 0.292511788 */, 14 },
- /* 577 */ { MAD_F(0x04b0e70c) /* 0.293189094 */, 14 },
- /* 578 */ { MAD_F(0x04b3adaa) /* 0.293866792 */, 14 },
- /* 579 */ { MAD_F(0x04b674b1) /* 0.294544881 */, 14 },
- /* 580 */ { MAD_F(0x04b93c21) /* 0.295223360 */, 14 },
- /* 581 */ { MAD_F(0x04bc03fa) /* 0.295902229 */, 14 },
- /* 582 */ { MAD_F(0x04becc3b) /* 0.296581488 */, 14 },
- /* 583 */ { MAD_F(0x04c194e4) /* 0.297261136 */, 14 },
- /* 584 */ { MAD_F(0x04c45df6) /* 0.297941173 */, 14 },
- /* 585 */ { MAD_F(0x04c72771) /* 0.298621598 */, 14 },
- /* 586 */ { MAD_F(0x04c9f153) /* 0.299302411 */, 14 },
- /* 587 */ { MAD_F(0x04ccbb9d) /* 0.299983611 */, 14 },
- /* 588 */ { MAD_F(0x04cf864f) /* 0.300665198 */, 14 },
- /* 589 */ { MAD_F(0x04d25169) /* 0.301347172 */, 14 },
- /* 590 */ { MAD_F(0x04d51ceb) /* 0.302029532 */, 14 },
- /* 591 */ { MAD_F(0x04d7e8d4) /* 0.302712277 */, 14 },
-
- /* 592 */ { MAD_F(0x04dab524) /* 0.303395408 */, 14 },
- /* 593 */ { MAD_F(0x04dd81dc) /* 0.304078923 */, 14 },
- /* 594 */ { MAD_F(0x04e04efb) /* 0.304762823 */, 14 },
- /* 595 */ { MAD_F(0x04e31c81) /* 0.305447106 */, 14 },
- /* 596 */ { MAD_F(0x04e5ea6e) /* 0.306131773 */, 14 },
- /* 597 */ { MAD_F(0x04e8b8c2) /* 0.306816823 */, 14 },
- /* 598 */ { MAD_F(0x04eb877c) /* 0.307502256 */, 14 },
- /* 599 */ { MAD_F(0x04ee569d) /* 0.308188071 */, 14 },
- /* 600 */ { MAD_F(0x04f12624) /* 0.308874267 */, 14 },
- /* 601 */ { MAD_F(0x04f3f612) /* 0.309560845 */, 14 },
- /* 602 */ { MAD_F(0x04f6c666) /* 0.310247804 */, 14 },
- /* 603 */ { MAD_F(0x04f99721) /* 0.310935143 */, 14 },
- /* 604 */ { MAD_F(0x04fc6841) /* 0.311622862 */, 14 },
- /* 605 */ { MAD_F(0x04ff39c7) /* 0.312310961 */, 14 },
- /* 606 */ { MAD_F(0x05020bb3) /* 0.312999439 */, 14 },
- /* 607 */ { MAD_F(0x0504de05) /* 0.313688296 */, 14 },
-
- /* 608 */ { MAD_F(0x0507b0bc) /* 0.314377532 */, 14 },
- /* 609 */ { MAD_F(0x050a83d8) /* 0.315067145 */, 14 },
- /* 610 */ { MAD_F(0x050d575b) /* 0.315757136 */, 14 },
- /* 611 */ { MAD_F(0x05102b42) /* 0.316447504 */, 14 },
- /* 612 */ { MAD_F(0x0512ff8e) /* 0.317138249 */, 14 },
- /* 613 */ { MAD_F(0x0515d440) /* 0.317829370 */, 14 },
- /* 614 */ { MAD_F(0x0518a956) /* 0.318520867 */, 14 },
- /* 615 */ { MAD_F(0x051b7ed1) /* 0.319212739 */, 14 },
- /* 616 */ { MAD_F(0x051e54b1) /* 0.319904987 */, 14 },
- /* 617 */ { MAD_F(0x05212af5) /* 0.320597609 */, 14 },
- /* 618 */ { MAD_F(0x0524019e) /* 0.321290606 */, 14 },
- /* 619 */ { MAD_F(0x0526d8ab) /* 0.321983976 */, 14 },
- /* 620 */ { MAD_F(0x0529b01d) /* 0.322677720 */, 14 },
- /* 621 */ { MAD_F(0x052c87f2) /* 0.323371837 */, 14 },
- /* 622 */ { MAD_F(0x052f602c) /* 0.324066327 */, 14 },
- /* 623 */ { MAD_F(0x053238ca) /* 0.324761189 */, 14 },
-
- /* 624 */ { MAD_F(0x053511cb) /* 0.325456423 */, 14 },
- /* 625 */ { MAD_F(0x0537eb30) /* 0.326152028 */, 14 },
- /* 626 */ { MAD_F(0x053ac4f9) /* 0.326848005 */, 14 },
- /* 627 */ { MAD_F(0x053d9f25) /* 0.327544352 */, 14 },
- /* 628 */ { MAD_F(0x054079b5) /* 0.328241070 */, 14 },
- /* 629 */ { MAD_F(0x054354a8) /* 0.328938157 */, 14 },
- /* 630 */ { MAD_F(0x05462ffe) /* 0.329635614 */, 14 },
- /* 631 */ { MAD_F(0x05490bb7) /* 0.330333440 */, 14 },
- /* 632 */ { MAD_F(0x054be7d4) /* 0.331031635 */, 14 },
- /* 633 */ { MAD_F(0x054ec453) /* 0.331730198 */, 14 },
- /* 634 */ { MAD_F(0x0551a134) /* 0.332429129 */, 14 },
- /* 635 */ { MAD_F(0x05547e79) /* 0.333128427 */, 14 },
- /* 636 */ { MAD_F(0x05575c20) /* 0.333828093 */, 14 },
- /* 637 */ { MAD_F(0x055a3a2a) /* 0.334528126 */, 14 },
- /* 638 */ { MAD_F(0x055d1896) /* 0.335228525 */, 14 },
- /* 639 */ { MAD_F(0x055ff764) /* 0.335929290 */, 14 },
-
- /* 640 */ { MAD_F(0x0562d694) /* 0.336630420 */, 14 },
- /* 641 */ { MAD_F(0x0565b627) /* 0.337331916 */, 14 },
- /* 642 */ { MAD_F(0x0568961b) /* 0.338033777 */, 14 },
- /* 643 */ { MAD_F(0x056b7671) /* 0.338736002 */, 14 },
- /* 644 */ { MAD_F(0x056e5729) /* 0.339438592 */, 14 },
- /* 645 */ { MAD_F(0x05713843) /* 0.340141545 */, 14 },
- /* 646 */ { MAD_F(0x057419be) /* 0.340844862 */, 14 },
- /* 647 */ { MAD_F(0x0576fb9a) /* 0.341548541 */, 14 },
- /* 648 */ { MAD_F(0x0579ddd8) /* 0.342252584 */, 14 },
- /* 649 */ { MAD_F(0x057cc077) /* 0.342956988 */, 14 },
- /* 650 */ { MAD_F(0x057fa378) /* 0.343661754 */, 14 },
- /* 651 */ { MAD_F(0x058286d9) /* 0.344366882 */, 14 },
- /* 652 */ { MAD_F(0x05856a9b) /* 0.345072371 */, 14 },
- /* 653 */ { MAD_F(0x05884ebe) /* 0.345778221 */, 14 },
- /* 654 */ { MAD_F(0x058b3342) /* 0.346484431 */, 14 },
- /* 655 */ { MAD_F(0x058e1827) /* 0.347191002 */, 14 },
-
- /* 656 */ { MAD_F(0x0590fd6c) /* 0.347897931 */, 14 },
- /* 657 */ { MAD_F(0x0593e311) /* 0.348605221 */, 14 },
- /* 658 */ { MAD_F(0x0596c917) /* 0.349312869 */, 14 },
- /* 659 */ { MAD_F(0x0599af7d) /* 0.350020876 */, 14 },
- /* 660 */ { MAD_F(0x059c9643) /* 0.350729240 */, 14 },
- /* 661 */ { MAD_F(0x059f7d6a) /* 0.351437963 */, 14 },
- /* 662 */ { MAD_F(0x05a264f0) /* 0.352147044 */, 14 },
- /* 663 */ { MAD_F(0x05a54cd6) /* 0.352856481 */, 14 },
- /* 664 */ { MAD_F(0x05a8351c) /* 0.353566275 */, 14 },
- /* 665 */ { MAD_F(0x05ab1dc2) /* 0.354276426 */, 14 },
- /* 666 */ { MAD_F(0x05ae06c7) /* 0.354986932 */, 14 },
- /* 667 */ { MAD_F(0x05b0f02b) /* 0.355697795 */, 14 },
- /* 668 */ { MAD_F(0x05b3d9f0) /* 0.356409012 */, 14 },
- /* 669 */ { MAD_F(0x05b6c413) /* 0.357120585 */, 14 },
- /* 670 */ { MAD_F(0x05b9ae95) /* 0.357832512 */, 14 },
- /* 671 */ { MAD_F(0x05bc9977) /* 0.358544794 */, 14 },
-
- /* 672 */ { MAD_F(0x05bf84b8) /* 0.359257429 */, 14 },
- /* 673 */ { MAD_F(0x05c27057) /* 0.359970419 */, 14 },
- /* 674 */ { MAD_F(0x05c55c56) /* 0.360683761 */, 14 },
- /* 675 */ { MAD_F(0x05c848b3) /* 0.361397456 */, 14 },
- /* 676 */ { MAD_F(0x05cb356e) /* 0.362111504 */, 14 },
- /* 677 */ { MAD_F(0x05ce2289) /* 0.362825904 */, 14 },
- /* 678 */ { MAD_F(0x05d11001) /* 0.363540655 */, 14 },
- /* 679 */ { MAD_F(0x05d3fdd8) /* 0.364255759 */, 14 },
- /* 680 */ { MAD_F(0x05d6ec0e) /* 0.364971213 */, 14 },
- /* 681 */ { MAD_F(0x05d9daa1) /* 0.365687018 */, 14 },
- /* 682 */ { MAD_F(0x05dcc993) /* 0.366403174 */, 14 },
- /* 683 */ { MAD_F(0x05dfb8e2) /* 0.367119680 */, 14 },
- /* 684 */ { MAD_F(0x05e2a890) /* 0.367836535 */, 14 },
- /* 685 */ { MAD_F(0x05e5989b) /* 0.368553740 */, 14 },
- /* 686 */ { MAD_F(0x05e88904) /* 0.369271294 */, 14 },
- /* 687 */ { MAD_F(0x05eb79cb) /* 0.369989197 */, 14 },
-
- /* 688 */ { MAD_F(0x05ee6aef) /* 0.370707448 */, 14 },
- /* 689 */ { MAD_F(0x05f15c70) /* 0.371426047 */, 14 },
- /* 690 */ { MAD_F(0x05f44e4f) /* 0.372144994 */, 14 },
- /* 691 */ { MAD_F(0x05f7408b) /* 0.372864289 */, 14 },
- /* 692 */ { MAD_F(0x05fa3324) /* 0.373583930 */, 14 },
- /* 693 */ { MAD_F(0x05fd261b) /* 0.374303918 */, 14 },
- /* 694 */ { MAD_F(0x0600196e) /* 0.375024253 */, 14 },
- /* 695 */ { MAD_F(0x06030d1e) /* 0.375744934 */, 14 },
- /* 696 */ { MAD_F(0x0606012b) /* 0.376465960 */, 14 },
- /* 697 */ { MAD_F(0x0608f595) /* 0.377187332 */, 14 },
- /* 698 */ { MAD_F(0x060bea5c) /* 0.377909049 */, 14 },
- /* 699 */ { MAD_F(0x060edf7f) /* 0.378631110 */, 14 },
- /* 700 */ { MAD_F(0x0611d4fe) /* 0.379353516 */, 14 },
- /* 701 */ { MAD_F(0x0614cada) /* 0.380076266 */, 14 },
- /* 702 */ { MAD_F(0x0617c112) /* 0.380799360 */, 14 },
- /* 703 */ { MAD_F(0x061ab7a6) /* 0.381522798 */, 14 },
-
- /* 704 */ { MAD_F(0x061dae96) /* 0.382246578 */, 14 },
- /* 705 */ { MAD_F(0x0620a5e3) /* 0.382970701 */, 14 },
- /* 706 */ { MAD_F(0x06239d8b) /* 0.383695167 */, 14 },
- /* 707 */ { MAD_F(0x0626958f) /* 0.384419975 */, 14 },
- /* 708 */ { MAD_F(0x06298def) /* 0.385145124 */, 14 },
- /* 709 */ { MAD_F(0x062c86aa) /* 0.385870615 */, 14 },
- /* 710 */ { MAD_F(0x062f7fc1) /* 0.386596448 */, 14 },
- /* 711 */ { MAD_F(0x06327934) /* 0.387322621 */, 14 },
- /* 712 */ { MAD_F(0x06357302) /* 0.388049134 */, 14 },
- /* 713 */ { MAD_F(0x06386d2b) /* 0.388775988 */, 14 },
- /* 714 */ { MAD_F(0x063b67b0) /* 0.389503182 */, 14 },
- /* 715 */ { MAD_F(0x063e6290) /* 0.390230715 */, 14 },
- /* 716 */ { MAD_F(0x06415dcb) /* 0.390958588 */, 14 },
- /* 717 */ { MAD_F(0x06445960) /* 0.391686799 */, 14 },
- /* 718 */ { MAD_F(0x06475551) /* 0.392415349 */, 14 },
- /* 719 */ { MAD_F(0x064a519c) /* 0.393144238 */, 14 },
-
- /* 720 */ { MAD_F(0x064d4e43) /* 0.393873464 */, 14 },
- /* 721 */ { MAD_F(0x06504b44) /* 0.394603028 */, 14 },
- /* 722 */ { MAD_F(0x0653489f) /* 0.395332930 */, 14 },
- /* 723 */ { MAD_F(0x06564655) /* 0.396063168 */, 14 },
- /* 724 */ { MAD_F(0x06594465) /* 0.396793743 */, 14 },
- /* 725 */ { MAD_F(0x065c42d0) /* 0.397524655 */, 14 },
- /* 726 */ { MAD_F(0x065f4195) /* 0.398255903 */, 14 },
- /* 727 */ { MAD_F(0x066240b4) /* 0.398987487 */, 14 },
- /* 728 */ { MAD_F(0x0665402d) /* 0.399719406 */, 14 },
- /* 729 */ { MAD_F(0x06684000) /* 0.400451660 */, 14 },
- /* 730 */ { MAD_F(0x066b402d) /* 0.401184249 */, 14 },
- /* 731 */ { MAD_F(0x066e40b3) /* 0.401917173 */, 14 },
- /* 732 */ { MAD_F(0x06714194) /* 0.402650431 */, 14 },
- /* 733 */ { MAD_F(0x067442ce) /* 0.403384024 */, 14 },
- /* 734 */ { MAD_F(0x06774462) /* 0.404117949 */, 14 },
- /* 735 */ { MAD_F(0x067a464f) /* 0.404852209 */, 14 },
-
- /* 736 */ { MAD_F(0x067d4896) /* 0.405586801 */, 14 },
- /* 737 */ { MAD_F(0x06804b36) /* 0.406321726 */, 14 },
- /* 738 */ { MAD_F(0x06834e2f) /* 0.407056983 */, 14 },
- /* 739 */ { MAD_F(0x06865181) /* 0.407792573 */, 14 },
- /* 740 */ { MAD_F(0x0689552c) /* 0.408528495 */, 14 },
- /* 741 */ { MAD_F(0x068c5931) /* 0.409264748 */, 14 },
- /* 742 */ { MAD_F(0x068f5d8e) /* 0.410001332 */, 14 },
- /* 743 */ { MAD_F(0x06926245) /* 0.410738247 */, 14 },
- /* 744 */ { MAD_F(0x06956753) /* 0.411475493 */, 14 },
- /* 745 */ { MAD_F(0x06986cbb) /* 0.412213070 */, 14 },
- /* 746 */ { MAD_F(0x069b727b) /* 0.412950976 */, 14 },
- /* 747 */ { MAD_F(0x069e7894) /* 0.413689213 */, 14 },
- /* 748 */ { MAD_F(0x06a17f05) /* 0.414427779 */, 14 },
- /* 749 */ { MAD_F(0x06a485cf) /* 0.415166674 */, 14 },
- /* 750 */ { MAD_F(0x06a78cf1) /* 0.415905897 */, 14 },
- /* 751 */ { MAD_F(0x06aa946b) /* 0.416645450 */, 14 },
-
- /* 752 */ { MAD_F(0x06ad9c3d) /* 0.417385331 */, 14 },
- /* 753 */ { MAD_F(0x06b0a468) /* 0.418125540 */, 14 },
- /* 754 */ { MAD_F(0x06b3acea) /* 0.418866076 */, 14 },
- /* 755 */ { MAD_F(0x06b6b5c4) /* 0.419606940 */, 14 },
- /* 756 */ { MAD_F(0x06b9bef6) /* 0.420348132 */, 14 },
- /* 757 */ { MAD_F(0x06bcc880) /* 0.421089650 */, 14 },
- /* 758 */ { MAD_F(0x06bfd261) /* 0.421831494 */, 14 },
- /* 759 */ { MAD_F(0x06c2dc9a) /* 0.422573665 */, 14 },
- /* 760 */ { MAD_F(0x06c5e72b) /* 0.423316162 */, 14 },
- /* 761 */ { MAD_F(0x06c8f213) /* 0.424058985 */, 14 },
- /* 762 */ { MAD_F(0x06cbfd52) /* 0.424802133 */, 14 },
- /* 763 */ { MAD_F(0x06cf08e9) /* 0.425545607 */, 14 },
- /* 764 */ { MAD_F(0x06d214d7) /* 0.426289405 */, 14 },
- /* 765 */ { MAD_F(0x06d5211c) /* 0.427033528 */, 14 },
- /* 766 */ { MAD_F(0x06d82db8) /* 0.427777975 */, 14 },
- /* 767 */ { MAD_F(0x06db3aaa) /* 0.428522746 */, 14 },
-
- /* 768 */ { MAD_F(0x06de47f4) /* 0.429267841 */, 14 },
- /* 769 */ { MAD_F(0x06e15595) /* 0.430013259 */, 14 },
- /* 770 */ { MAD_F(0x06e4638d) /* 0.430759001 */, 14 },
- /* 771 */ { MAD_F(0x06e771db) /* 0.431505065 */, 14 },
- /* 772 */ { MAD_F(0x06ea807f) /* 0.432251452 */, 14 },
- /* 773 */ { MAD_F(0x06ed8f7b) /* 0.432998162 */, 14 },
- /* 774 */ { MAD_F(0x06f09ecc) /* 0.433745193 */, 14 },
- /* 775 */ { MAD_F(0x06f3ae75) /* 0.434492546 */, 14 },
- /* 776 */ { MAD_F(0x06f6be73) /* 0.435240221 */, 14 },
- /* 777 */ { MAD_F(0x06f9cec8) /* 0.435988217 */, 14 },
- /* 778 */ { MAD_F(0x06fcdf72) /* 0.436736534 */, 14 },
- /* 779 */ { MAD_F(0x06fff073) /* 0.437485172 */, 14 },
- /* 780 */ { MAD_F(0x070301ca) /* 0.438234130 */, 14 },
- /* 781 */ { MAD_F(0x07061377) /* 0.438983408 */, 14 },
- /* 782 */ { MAD_F(0x0709257a) /* 0.439733006 */, 14 },
- /* 783 */ { MAD_F(0x070c37d2) /* 0.440482924 */, 14 },
-
- /* 784 */ { MAD_F(0x070f4a80) /* 0.441233161 */, 14 },
- /* 785 */ { MAD_F(0x07125d84) /* 0.441983717 */, 14 },
- /* 786 */ { MAD_F(0x071570de) /* 0.442734592 */, 14 },
- /* 787 */ { MAD_F(0x0718848d) /* 0.443485785 */, 14 },
- /* 788 */ { MAD_F(0x071b9891) /* 0.444237296 */, 14 },
- /* 789 */ { MAD_F(0x071eaceb) /* 0.444989126 */, 14 },
- /* 790 */ { MAD_F(0x0721c19a) /* 0.445741273 */, 14 },
- /* 791 */ { MAD_F(0x0724d69e) /* 0.446493738 */, 14 },
- /* 792 */ { MAD_F(0x0727ebf7) /* 0.447246519 */, 14 },
- /* 793 */ { MAD_F(0x072b01a6) /* 0.447999618 */, 14 },
- /* 794 */ { MAD_F(0x072e17a9) /* 0.448753033 */, 14 },
- /* 795 */ { MAD_F(0x07312e01) /* 0.449506765 */, 14 },
- /* 796 */ { MAD_F(0x073444ae) /* 0.450260813 */, 14 },
- /* 797 */ { MAD_F(0x07375bb0) /* 0.451015176 */, 14 },
- /* 798 */ { MAD_F(0x073a7307) /* 0.451769856 */, 14 },
- /* 799 */ { MAD_F(0x073d8ab2) /* 0.452524850 */, 14 },
-
- /* 800 */ { MAD_F(0x0740a2b2) /* 0.453280160 */, 14 },
- /* 801 */ { MAD_F(0x0743bb06) /* 0.454035784 */, 14 },
- /* 802 */ { MAD_F(0x0746d3af) /* 0.454791723 */, 14 },
- /* 803 */ { MAD_F(0x0749ecac) /* 0.455547976 */, 14 },
- /* 804 */ { MAD_F(0x074d05fe) /* 0.456304543 */, 14 },
- /* 805 */ { MAD_F(0x07501fa3) /* 0.457061423 */, 14 },
- /* 806 */ { MAD_F(0x0753399d) /* 0.457818618 */, 14 },
- /* 807 */ { MAD_F(0x075653eb) /* 0.458576125 */, 14 },
- /* 808 */ { MAD_F(0x07596e8d) /* 0.459333946 */, 14 },
- /* 809 */ { MAD_F(0x075c8983) /* 0.460092079 */, 14 },
- /* 810 */ { MAD_F(0x075fa4cc) /* 0.460850524 */, 14 },
- /* 811 */ { MAD_F(0x0762c06a) /* 0.461609282 */, 14 },
- /* 812 */ { MAD_F(0x0765dc5b) /* 0.462368352 */, 14 },
- /* 813 */ { MAD_F(0x0768f8a0) /* 0.463127733 */, 14 },
- /* 814 */ { MAD_F(0x076c1538) /* 0.463887426 */, 14 },
- /* 815 */ { MAD_F(0x076f3224) /* 0.464647430 */, 14 },
-
- /* 816 */ { MAD_F(0x07724f64) /* 0.465407744 */, 14 },
- /* 817 */ { MAD_F(0x07756cf7) /* 0.466168370 */, 14 },
- /* 818 */ { MAD_F(0x07788add) /* 0.466929306 */, 14 },
- /* 819 */ { MAD_F(0x077ba916) /* 0.467690552 */, 14 },
- /* 820 */ { MAD_F(0x077ec7a3) /* 0.468452108 */, 14 },
- /* 821 */ { MAD_F(0x0781e683) /* 0.469213973 */, 14 },
- /* 822 */ { MAD_F(0x078505b5) /* 0.469976148 */, 14 },
- /* 823 */ { MAD_F(0x0788253b) /* 0.470738632 */, 14 },
- /* 824 */ { MAD_F(0x078b4514) /* 0.471501425 */, 14 },
- /* 825 */ { MAD_F(0x078e653f) /* 0.472264527 */, 14 },
- /* 826 */ { MAD_F(0x079185be) /* 0.473027937 */, 14 },
- /* 827 */ { MAD_F(0x0794a68f) /* 0.473791655 */, 14 },
- /* 828 */ { MAD_F(0x0797c7b2) /* 0.474555681 */, 14 },
- /* 829 */ { MAD_F(0x079ae929) /* 0.475320014 */, 14 },
- /* 830 */ { MAD_F(0x079e0af1) /* 0.476084655 */, 14 },
- /* 831 */ { MAD_F(0x07a12d0c) /* 0.476849603 */, 14 },
-
- /* 832 */ { MAD_F(0x07a44f7a) /* 0.477614858 */, 14 },
- /* 833 */ { MAD_F(0x07a7723a) /* 0.478380420 */, 14 },
- /* 834 */ { MAD_F(0x07aa954c) /* 0.479146288 */, 14 },
- /* 835 */ { MAD_F(0x07adb8b0) /* 0.479912463 */, 14 },
- /* 836 */ { MAD_F(0x07b0dc67) /* 0.480678943 */, 14 },
- /* 837 */ { MAD_F(0x07b4006f) /* 0.481445729 */, 14 },
- /* 838 */ { MAD_F(0x07b724ca) /* 0.482212820 */, 14 },
- /* 839 */ { MAD_F(0x07ba4976) /* 0.482980216 */, 14 },
- /* 840 */ { MAD_F(0x07bd6e75) /* 0.483747918 */, 14 },
- /* 841 */ { MAD_F(0x07c093c5) /* 0.484515924 */, 14 },
- /* 842 */ { MAD_F(0x07c3b967) /* 0.485284235 */, 14 },
- /* 843 */ { MAD_F(0x07c6df5a) /* 0.486052849 */, 14 },
- /* 844 */ { MAD_F(0x07ca059f) /* 0.486821768 */, 14 },
- /* 845 */ { MAD_F(0x07cd2c36) /* 0.487590991 */, 14 },
- /* 846 */ { MAD_F(0x07d0531e) /* 0.488360517 */, 14 },
- /* 847 */ { MAD_F(0x07d37a57) /* 0.489130346 */, 14 },
-
- /* 848 */ { MAD_F(0x07d6a1e2) /* 0.489900479 */, 14 },
- /* 849 */ { MAD_F(0x07d9c9be) /* 0.490670914 */, 14 },
- /* 850 */ { MAD_F(0x07dcf1ec) /* 0.491441651 */, 14 },
- /* 851 */ { MAD_F(0x07e01a6a) /* 0.492212691 */, 14 },
- /* 852 */ { MAD_F(0x07e3433a) /* 0.492984033 */, 14 },
- /* 853 */ { MAD_F(0x07e66c5a) /* 0.493755677 */, 14 },
- /* 854 */ { MAD_F(0x07e995cc) /* 0.494527623 */, 14 },
- /* 855 */ { MAD_F(0x07ecbf8e) /* 0.495299870 */, 14 },
- /* 856 */ { MAD_F(0x07efe9a1) /* 0.496072418 */, 14 },
- /* 857 */ { MAD_F(0x07f31405) /* 0.496845266 */, 14 },
- /* 858 */ { MAD_F(0x07f63eba) /* 0.497618416 */, 14 },
- /* 859 */ { MAD_F(0x07f969c0) /* 0.498391866 */, 14 },
- /* 860 */ { MAD_F(0x07fc9516) /* 0.499165616 */, 14 },
- /* 861 */ { MAD_F(0x07ffc0bc) /* 0.499939666 */, 14 },
- /* 862 */ { MAD_F(0x04017659) /* 0.250357008 */, 15 },
- /* 863 */ { MAD_F(0x04030c7d) /* 0.250744333 */, 15 },
-
- /* 864 */ { MAD_F(0x0404a2c9) /* 0.251131807 */, 15 },
- /* 865 */ { MAD_F(0x0406393d) /* 0.251519431 */, 15 },
- /* 866 */ { MAD_F(0x0407cfd9) /* 0.251907204 */, 15 },
- /* 867 */ { MAD_F(0x0409669d) /* 0.252295127 */, 15 },
- /* 868 */ { MAD_F(0x040afd89) /* 0.252683198 */, 15 },
- /* 869 */ { MAD_F(0x040c949e) /* 0.253071419 */, 15 },
- /* 870 */ { MAD_F(0x040e2bda) /* 0.253459789 */, 15 },
- /* 871 */ { MAD_F(0x040fc33e) /* 0.253848307 */, 15 },
- /* 872 */ { MAD_F(0x04115aca) /* 0.254236974 */, 15 },
- /* 873 */ { MAD_F(0x0412f27e) /* 0.254625790 */, 15 },
- /* 874 */ { MAD_F(0x04148a5a) /* 0.255014755 */, 15 },
- /* 875 */ { MAD_F(0x0416225d) /* 0.255403867 */, 15 },
- /* 876 */ { MAD_F(0x0417ba89) /* 0.255793128 */, 15 },
- /* 877 */ { MAD_F(0x041952dc) /* 0.256182537 */, 15 },
- /* 878 */ { MAD_F(0x041aeb57) /* 0.256572095 */, 15 },
- /* 879 */ { MAD_F(0x041c83fa) /* 0.256961800 */, 15 },
-
- /* 880 */ { MAD_F(0x041e1cc4) /* 0.257351652 */, 15 },
- /* 881 */ { MAD_F(0x041fb5b6) /* 0.257741653 */, 15 },
- /* 882 */ { MAD_F(0x04214ed0) /* 0.258131801 */, 15 },
- /* 883 */ { MAD_F(0x0422e811) /* 0.258522097 */, 15 },
- /* 884 */ { MAD_F(0x04248179) /* 0.258912540 */, 15 },
- /* 885 */ { MAD_F(0x04261b0a) /* 0.259303130 */, 15 },
- /* 886 */ { MAD_F(0x0427b4c2) /* 0.259693868 */, 15 },
- /* 887 */ { MAD_F(0x04294ea1) /* 0.260084752 */, 15 },
- /* 888 */ { MAD_F(0x042ae8a7) /* 0.260475783 */, 15 },
- /* 889 */ { MAD_F(0x042c82d6) /* 0.260866961 */, 15 },
- /* 890 */ { MAD_F(0x042e1d2b) /* 0.261258286 */, 15 },
- /* 891 */ { MAD_F(0x042fb7a8) /* 0.261649758 */, 15 },
- /* 892 */ { MAD_F(0x0431524c) /* 0.262041376 */, 15 },
- /* 893 */ { MAD_F(0x0432ed17) /* 0.262433140 */, 15 },
- /* 894 */ { MAD_F(0x0434880a) /* 0.262825051 */, 15 },
- /* 895 */ { MAD_F(0x04362324) /* 0.263217107 */, 15 },
-
- /* 896 */ { MAD_F(0x0437be65) /* 0.263609310 */, 15 },
- /* 897 */ { MAD_F(0x043959cd) /* 0.264001659 */, 15 },
- /* 898 */ { MAD_F(0x043af55d) /* 0.264394153 */, 15 },
- /* 899 */ { MAD_F(0x043c9113) /* 0.264786794 */, 15 },
- /* 900 */ { MAD_F(0x043e2cf1) /* 0.265179580 */, 15 },
- /* 901 */ { MAD_F(0x043fc8f6) /* 0.265572511 */, 15 },
- /* 902 */ { MAD_F(0x04416522) /* 0.265965588 */, 15 },
- /* 903 */ { MAD_F(0x04430174) /* 0.266358810 */, 15 },
- /* 904 */ { MAD_F(0x04449dee) /* 0.266752177 */, 15 },
- /* 905 */ { MAD_F(0x04463a8f) /* 0.267145689 */, 15 },
- /* 906 */ { MAD_F(0x0447d756) /* 0.267539347 */, 15 },
- /* 907 */ { MAD_F(0x04497445) /* 0.267933149 */, 15 },
- /* 908 */ { MAD_F(0x044b115a) /* 0.268327096 */, 15 },
- /* 909 */ { MAD_F(0x044cae96) /* 0.268721187 */, 15 },
- /* 910 */ { MAD_F(0x044e4bf9) /* 0.269115423 */, 15 },
- /* 911 */ { MAD_F(0x044fe983) /* 0.269509804 */, 15 },
-
- /* 912 */ { MAD_F(0x04518733) /* 0.269904329 */, 15 },
- /* 913 */ { MAD_F(0x0453250a) /* 0.270298998 */, 15 },
- /* 914 */ { MAD_F(0x0454c308) /* 0.270693811 */, 15 },
- /* 915 */ { MAD_F(0x0456612d) /* 0.271088768 */, 15 },
- /* 916 */ { MAD_F(0x0457ff78) /* 0.271483869 */, 15 },
- /* 917 */ { MAD_F(0x04599dea) /* 0.271879114 */, 15 },
- /* 918 */ { MAD_F(0x045b3c82) /* 0.272274503 */, 15 },
- /* 919 */ { MAD_F(0x045cdb41) /* 0.272670035 */, 15 },
- /* 920 */ { MAD_F(0x045e7a26) /* 0.273065710 */, 15 },
- /* 921 */ { MAD_F(0x04601932) /* 0.273461530 */, 15 },
- /* 922 */ { MAD_F(0x0461b864) /* 0.273857492 */, 15 },
- /* 923 */ { MAD_F(0x046357bd) /* 0.274253597 */, 15 },
- /* 924 */ { MAD_F(0x0464f73c) /* 0.274649846 */, 15 },
- /* 925 */ { MAD_F(0x046696e2) /* 0.275046238 */, 15 },
- /* 926 */ { MAD_F(0x046836ae) /* 0.275442772 */, 15 },
- /* 927 */ { MAD_F(0x0469d6a0) /* 0.275839449 */, 15 },
-
- /* 928 */ { MAD_F(0x046b76b9) /* 0.276236269 */, 15 },
- /* 929 */ { MAD_F(0x046d16f7) /* 0.276633232 */, 15 },
- /* 930 */ { MAD_F(0x046eb75c) /* 0.277030337 */, 15 },
- /* 931 */ { MAD_F(0x047057e8) /* 0.277427584 */, 15 },
- /* 932 */ { MAD_F(0x0471f899) /* 0.277824973 */, 15 },
- /* 933 */ { MAD_F(0x04739971) /* 0.278222505 */, 15 },
- /* 934 */ { MAD_F(0x04753a6f) /* 0.278620179 */, 15 },
- /* 935 */ { MAD_F(0x0476db92) /* 0.279017995 */, 15 },
- /* 936 */ { MAD_F(0x04787cdc) /* 0.279415952 */, 15 },
- /* 937 */ { MAD_F(0x047a1e4c) /* 0.279814051 */, 15 },
- /* 938 */ { MAD_F(0x047bbfe2) /* 0.280212292 */, 15 },
- /* 939 */ { MAD_F(0x047d619e) /* 0.280610675 */, 15 },
- /* 940 */ { MAD_F(0x047f0380) /* 0.281009199 */, 15 },
- /* 941 */ { MAD_F(0x0480a588) /* 0.281407864 */, 15 },
- /* 942 */ { MAD_F(0x048247b6) /* 0.281806670 */, 15 },
- /* 943 */ { MAD_F(0x0483ea0a) /* 0.282205618 */, 15 },
-
- /* 944 */ { MAD_F(0x04858c83) /* 0.282604707 */, 15 },
- /* 945 */ { MAD_F(0x04872f22) /* 0.283003936 */, 15 },
- /* 946 */ { MAD_F(0x0488d1e8) /* 0.283403307 */, 15 },
- /* 947 */ { MAD_F(0x048a74d3) /* 0.283802818 */, 15 },
- /* 948 */ { MAD_F(0x048c17e3) /* 0.284202470 */, 15 },
- /* 949 */ { MAD_F(0x048dbb1a) /* 0.284602263 */, 15 },
- /* 950 */ { MAD_F(0x048f5e76) /* 0.285002195 */, 15 },
- /* 951 */ { MAD_F(0x049101f8) /* 0.285402269 */, 15 },
- /* 952 */ { MAD_F(0x0492a59f) /* 0.285802482 */, 15 },
- /* 953 */ { MAD_F(0x0494496c) /* 0.286202836 */, 15 },
- /* 954 */ { MAD_F(0x0495ed5f) /* 0.286603329 */, 15 },
- /* 955 */ { MAD_F(0x04979177) /* 0.287003963 */, 15 },
- /* 956 */ { MAD_F(0x049935b5) /* 0.287404737 */, 15 },
- /* 957 */ { MAD_F(0x049ada19) /* 0.287805650 */, 15 },
- /* 958 */ { MAD_F(0x049c7ea1) /* 0.288206703 */, 15 },
- /* 959 */ { MAD_F(0x049e2350) /* 0.288607895 */, 15 },
-
- /* 960 */ { MAD_F(0x049fc824) /* 0.289009227 */, 15 },
- /* 961 */ { MAD_F(0x04a16d1d) /* 0.289410699 */, 15 },
- /* 962 */ { MAD_F(0x04a3123b) /* 0.289812309 */, 15 },
- /* 963 */ { MAD_F(0x04a4b77f) /* 0.290214059 */, 15 },
- /* 964 */ { MAD_F(0x04a65ce8) /* 0.290615948 */, 15 },
- /* 965 */ { MAD_F(0x04a80277) /* 0.291017976 */, 15 },
- /* 966 */ { MAD_F(0x04a9a82b) /* 0.291420143 */, 15 },
- /* 967 */ { MAD_F(0x04ab4e04) /* 0.291822449 */, 15 },
- /* 968 */ { MAD_F(0x04acf402) /* 0.292224893 */, 15 },
- /* 969 */ { MAD_F(0x04ae9a26) /* 0.292627476 */, 15 },
- /* 970 */ { MAD_F(0x04b0406e) /* 0.293030197 */, 15 },
- /* 971 */ { MAD_F(0x04b1e6dc) /* 0.293433057 */, 15 },
- /* 972 */ { MAD_F(0x04b38d6f) /* 0.293836055 */, 15 },
- /* 973 */ { MAD_F(0x04b53427) /* 0.294239192 */, 15 },
- /* 974 */ { MAD_F(0x04b6db05) /* 0.294642466 */, 15 },
- /* 975 */ { MAD_F(0x04b88207) /* 0.295045879 */, 15 },
-
- /* 976 */ { MAD_F(0x04ba292e) /* 0.295449429 */, 15 },
- /* 977 */ { MAD_F(0x04bbd07a) /* 0.295853118 */, 15 },
- /* 978 */ { MAD_F(0x04bd77ec) /* 0.296256944 */, 15 },
- /* 979 */ { MAD_F(0x04bf1f82) /* 0.296660907 */, 15 },
- /* 980 */ { MAD_F(0x04c0c73d) /* 0.297065009 */, 15 },
- /* 981 */ { MAD_F(0x04c26f1d) /* 0.297469248 */, 15 },
- /* 982 */ { MAD_F(0x04c41722) /* 0.297873624 */, 15 },
- /* 983 */ { MAD_F(0x04c5bf4c) /* 0.298278137 */, 15 },
- /* 984 */ { MAD_F(0x04c7679a) /* 0.298682788 */, 15 },
- /* 985 */ { MAD_F(0x04c9100d) /* 0.299087576 */, 15 },
- /* 986 */ { MAD_F(0x04cab8a6) /* 0.299492500 */, 15 },
- /* 987 */ { MAD_F(0x04cc6163) /* 0.299897562 */, 15 },
- /* 988 */ { MAD_F(0x04ce0a44) /* 0.300302761 */, 15 },
- /* 989 */ { MAD_F(0x04cfb34b) /* 0.300708096 */, 15 },
- /* 990 */ { MAD_F(0x04d15c76) /* 0.301113568 */, 15 },
- /* 991 */ { MAD_F(0x04d305c5) /* 0.301519176 */, 15 },
-
- /* 992 */ { MAD_F(0x04d4af3a) /* 0.301924921 */, 15 },
- /* 993 */ { MAD_F(0x04d658d2) /* 0.302330802 */, 15 },
- /* 994 */ { MAD_F(0x04d80290) /* 0.302736820 */, 15 },
- /* 995 */ { MAD_F(0x04d9ac72) /* 0.303142973 */, 15 },
- /* 996 */ { MAD_F(0x04db5679) /* 0.303549263 */, 15 },
- /* 997 */ { MAD_F(0x04dd00a4) /* 0.303955689 */, 15 },
- /* 998 */ { MAD_F(0x04deaaf3) /* 0.304362251 */, 15 },
- /* 999 */ { MAD_F(0x04e05567) /* 0.304768948 */, 15 },
- /* 1000 */ { MAD_F(0x04e20000) /* 0.305175781 */, 15 },
- /* 1001 */ { MAD_F(0x04e3aabd) /* 0.305582750 */, 15 },
- /* 1002 */ { MAD_F(0x04e5559e) /* 0.305989854 */, 15 },
- /* 1003 */ { MAD_F(0x04e700a3) /* 0.306397094 */, 15 },
- /* 1004 */ { MAD_F(0x04e8abcd) /* 0.306804470 */, 15 },
- /* 1005 */ { MAD_F(0x04ea571c) /* 0.307211980 */, 15 },
- /* 1006 */ { MAD_F(0x04ec028e) /* 0.307619626 */, 15 },
- /* 1007 */ { MAD_F(0x04edae25) /* 0.308027406 */, 15 },
-
- /* 1008 */ { MAD_F(0x04ef59e0) /* 0.308435322 */, 15 },
- /* 1009 */ { MAD_F(0x04f105bf) /* 0.308843373 */, 15 },
- /* 1010 */ { MAD_F(0x04f2b1c3) /* 0.309251558 */, 15 },
- /* 1011 */ { MAD_F(0x04f45dea) /* 0.309659879 */, 15 },
- /* 1012 */ { MAD_F(0x04f60a36) /* 0.310068333 */, 15 },
- /* 1013 */ { MAD_F(0x04f7b6a6) /* 0.310476923 */, 15 },
- /* 1014 */ { MAD_F(0x04f9633a) /* 0.310885647 */, 15 },
- /* 1015 */ { MAD_F(0x04fb0ff2) /* 0.311294505 */, 15 },
- /* 1016 */ { MAD_F(0x04fcbcce) /* 0.311703498 */, 15 },
- /* 1017 */ { MAD_F(0x04fe69ce) /* 0.312112625 */, 15 },
- /* 1018 */ { MAD_F(0x050016f3) /* 0.312521885 */, 15 },
- /* 1019 */ { MAD_F(0x0501c43b) /* 0.312931280 */, 15 },
- /* 1020 */ { MAD_F(0x050371a7) /* 0.313340809 */, 15 },
- /* 1021 */ { MAD_F(0x05051f37) /* 0.313750472 */, 15 },
- /* 1022 */ { MAD_F(0x0506cceb) /* 0.314160269 */, 15 },
- /* 1023 */ { MAD_F(0x05087ac2) /* 0.314570199 */, 15 },
-
- /* 1024 */ { MAD_F(0x050a28be) /* 0.314980262 */, 15 },
- /* 1025 */ { MAD_F(0x050bd6de) /* 0.315390460 */, 15 },
- /* 1026 */ { MAD_F(0x050d8521) /* 0.315800790 */, 15 },
- /* 1027 */ { MAD_F(0x050f3388) /* 0.316211255 */, 15 },
- /* 1028 */ { MAD_F(0x0510e213) /* 0.316621852 */, 15 },
- /* 1029 */ { MAD_F(0x051290c2) /* 0.317032582 */, 15 },
- /* 1030 */ { MAD_F(0x05143f94) /* 0.317443446 */, 15 },
- /* 1031 */ { MAD_F(0x0515ee8a) /* 0.317854442 */, 15 },
- /* 1032 */ { MAD_F(0x05179da4) /* 0.318265572 */, 15 },
- /* 1033 */ { MAD_F(0x05194ce1) /* 0.318676834 */, 15 },
- /* 1034 */ { MAD_F(0x051afc42) /* 0.319088229 */, 15 },
- /* 1035 */ { MAD_F(0x051cabc7) /* 0.319499756 */, 15 },
- /* 1036 */ { MAD_F(0x051e5b6f) /* 0.319911417 */, 15 },
- /* 1037 */ { MAD_F(0x05200b3a) /* 0.320323209 */, 15 },
- /* 1038 */ { MAD_F(0x0521bb2a) /* 0.320735134 */, 15 },
- /* 1039 */ { MAD_F(0x05236b3d) /* 0.321147192 */, 15 },
-
- /* 1040 */ { MAD_F(0x05251b73) /* 0.321559381 */, 15 },
- /* 1041 */ { MAD_F(0x0526cbcd) /* 0.321971703 */, 15 },
- /* 1042 */ { MAD_F(0x05287c4a) /* 0.322384156 */, 15 },
- /* 1043 */ { MAD_F(0x052a2cea) /* 0.322796742 */, 15 },
- /* 1044 */ { MAD_F(0x052bddae) /* 0.323209460 */, 15 },
- /* 1045 */ { MAD_F(0x052d8e96) /* 0.323622309 */, 15 },
- /* 1046 */ { MAD_F(0x052f3fa1) /* 0.324035290 */, 15 },
- /* 1047 */ { MAD_F(0x0530f0cf) /* 0.324448403 */, 15 },
- /* 1048 */ { MAD_F(0x0532a220) /* 0.324861647 */, 15 },
- /* 1049 */ { MAD_F(0x05345395) /* 0.325275023 */, 15 },
- /* 1050 */ { MAD_F(0x0536052d) /* 0.325688530 */, 15 },
- /* 1051 */ { MAD_F(0x0537b6e8) /* 0.326102168 */, 15 },
- /* 1052 */ { MAD_F(0x053968c6) /* 0.326515938 */, 15 },
- /* 1053 */ { MAD_F(0x053b1ac8) /* 0.326929839 */, 15 },
- /* 1054 */ { MAD_F(0x053ccced) /* 0.327343870 */, 15 },
- /* 1055 */ { MAD_F(0x053e7f35) /* 0.327758033 */, 15 },
-
- /* 1056 */ { MAD_F(0x054031a0) /* 0.328172327 */, 15 },
- /* 1057 */ { MAD_F(0x0541e42e) /* 0.328586751 */, 15 },
- /* 1058 */ { MAD_F(0x054396df) /* 0.329001306 */, 15 },
- /* 1059 */ { MAD_F(0x054549b4) /* 0.329415992 */, 15 },
- /* 1060 */ { MAD_F(0x0546fcab) /* 0.329830808 */, 15 },
- /* 1061 */ { MAD_F(0x0548afc6) /* 0.330245755 */, 15 },
- /* 1062 */ { MAD_F(0x054a6303) /* 0.330660832 */, 15 },
- /* 1063 */ { MAD_F(0x054c1663) /* 0.331076039 */, 15 },
- /* 1064 */ { MAD_F(0x054dc9e7) /* 0.331491377 */, 15 },
- /* 1065 */ { MAD_F(0x054f7d8d) /* 0.331906845 */, 15 },
- /* 1066 */ { MAD_F(0x05513156) /* 0.332322443 */, 15 },
- /* 1067 */ { MAD_F(0x0552e542) /* 0.332738170 */, 15 },
- /* 1068 */ { MAD_F(0x05549951) /* 0.333154028 */, 15 },
- /* 1069 */ { MAD_F(0x05564d83) /* 0.333570016 */, 15 },
- /* 1070 */ { MAD_F(0x055801d8) /* 0.333986133 */, 15 },
- /* 1071 */ { MAD_F(0x0559b64f) /* 0.334402380 */, 15 },
-
- /* 1072 */ { MAD_F(0x055b6ae9) /* 0.334818756 */, 15 },
- /* 1073 */ { MAD_F(0x055d1fa6) /* 0.335235262 */, 15 },
- /* 1074 */ { MAD_F(0x055ed486) /* 0.335651898 */, 15 },
- /* 1075 */ { MAD_F(0x05608988) /* 0.336068662 */, 15 },
- /* 1076 */ { MAD_F(0x05623ead) /* 0.336485556 */, 15 },
- /* 1077 */ { MAD_F(0x0563f3f5) /* 0.336902579 */, 15 },
- /* 1078 */ { MAD_F(0x0565a960) /* 0.337319732 */, 15 },
- /* 1079 */ { MAD_F(0x05675eed) /* 0.337737013 */, 15 },
- /* 1080 */ { MAD_F(0x0569149c) /* 0.338154423 */, 15 },
- /* 1081 */ { MAD_F(0x056aca6f) /* 0.338571962 */, 15 },
- /* 1082 */ { MAD_F(0x056c8064) /* 0.338989630 */, 15 },
- /* 1083 */ { MAD_F(0x056e367b) /* 0.339407426 */, 15 },
- /* 1084 */ { MAD_F(0x056fecb5) /* 0.339825351 */, 15 },
- /* 1085 */ { MAD_F(0x0571a311) /* 0.340243405 */, 15 },
- /* 1086 */ { MAD_F(0x05735990) /* 0.340661587 */, 15 },
- /* 1087 */ { MAD_F(0x05751032) /* 0.341079898 */, 15 },
-
- /* 1088 */ { MAD_F(0x0576c6f5) /* 0.341498336 */, 15 },
- /* 1089 */ { MAD_F(0x05787ddc) /* 0.341916903 */, 15 },
- /* 1090 */ { MAD_F(0x057a34e4) /* 0.342335598 */, 15 },
- /* 1091 */ { MAD_F(0x057bec0f) /* 0.342754421 */, 15 },
- /* 1092 */ { MAD_F(0x057da35d) /* 0.343173373 */, 15 },
- /* 1093 */ { MAD_F(0x057f5acc) /* 0.343592452 */, 15 },
- /* 1094 */ { MAD_F(0x0581125e) /* 0.344011659 */, 15 },
- /* 1095 */ { MAD_F(0x0582ca12) /* 0.344430993 */, 15 },
- /* 1096 */ { MAD_F(0x058481e9) /* 0.344850455 */, 15 },
- /* 1097 */ { MAD_F(0x058639e2) /* 0.345270045 */, 15 },
- /* 1098 */ { MAD_F(0x0587f1fd) /* 0.345689763 */, 15 },
- /* 1099 */ { MAD_F(0x0589aa3a) /* 0.346109608 */, 15 },
- /* 1100 */ { MAD_F(0x058b629a) /* 0.346529580 */, 15 },
- /* 1101 */ { MAD_F(0x058d1b1b) /* 0.346949679 */, 15 },
- /* 1102 */ { MAD_F(0x058ed3bf) /* 0.347369906 */, 15 },
- /* 1103 */ { MAD_F(0x05908c85) /* 0.347790260 */, 15 },
-
- /* 1104 */ { MAD_F(0x0592456d) /* 0.348210741 */, 15 },
- /* 1105 */ { MAD_F(0x0593fe77) /* 0.348631348 */, 15 },
- /* 1106 */ { MAD_F(0x0595b7a3) /* 0.349052083 */, 15 },
- /* 1107 */ { MAD_F(0x059770f1) /* 0.349472945 */, 15 },
- /* 1108 */ { MAD_F(0x05992a61) /* 0.349893933 */, 15 },
- /* 1109 */ { MAD_F(0x059ae3f3) /* 0.350315048 */, 15 },
- /* 1110 */ { MAD_F(0x059c9da8) /* 0.350736290 */, 15 },
- /* 1111 */ { MAD_F(0x059e577e) /* 0.351157658 */, 15 },
- /* 1112 */ { MAD_F(0x05a01176) /* 0.351579152 */, 15 },
- /* 1113 */ { MAD_F(0x05a1cb90) /* 0.352000773 */, 15 },
- /* 1114 */ { MAD_F(0x05a385cc) /* 0.352422520 */, 15 },
- /* 1115 */ { MAD_F(0x05a5402a) /* 0.352844394 */, 15 },
- /* 1116 */ { MAD_F(0x05a6faa9) /* 0.353266393 */, 15 },
- /* 1117 */ { MAD_F(0x05a8b54b) /* 0.353688519 */, 15 },
- /* 1118 */ { MAD_F(0x05aa700e) /* 0.354110771 */, 15 },
- /* 1119 */ { MAD_F(0x05ac2af3) /* 0.354533148 */, 15 },
-
- /* 1120 */ { MAD_F(0x05ade5fa) /* 0.354955651 */, 15 },
- /* 1121 */ { MAD_F(0x05afa123) /* 0.355378281 */, 15 },
- /* 1122 */ { MAD_F(0x05b15c6d) /* 0.355801035 */, 15 },
- /* 1123 */ { MAD_F(0x05b317d9) /* 0.356223916 */, 15 },
- /* 1124 */ { MAD_F(0x05b4d367) /* 0.356646922 */, 15 },
- /* 1125 */ { MAD_F(0x05b68f16) /* 0.357070053 */, 15 },
- /* 1126 */ { MAD_F(0x05b84ae7) /* 0.357493310 */, 15 },
- /* 1127 */ { MAD_F(0x05ba06da) /* 0.357916692 */, 15 },
- /* 1128 */ { MAD_F(0x05bbc2ef) /* 0.358340200 */, 15 },
- /* 1129 */ { MAD_F(0x05bd7f25) /* 0.358763832 */, 15 },
- /* 1130 */ { MAD_F(0x05bf3b7c) /* 0.359187590 */, 15 },
- /* 1131 */ { MAD_F(0x05c0f7f5) /* 0.359611472 */, 15 },
- /* 1132 */ { MAD_F(0x05c2b490) /* 0.360035480 */, 15 },
- /* 1133 */ { MAD_F(0x05c4714c) /* 0.360459613 */, 15 },
- /* 1134 */ { MAD_F(0x05c62e2a) /* 0.360883870 */, 15 },
- /* 1135 */ { MAD_F(0x05c7eb29) /* 0.361308252 */, 15 },
-
- /* 1136 */ { MAD_F(0x05c9a84a) /* 0.361732758 */, 15 },
- /* 1137 */ { MAD_F(0x05cb658c) /* 0.362157390 */, 15 },
- /* 1138 */ { MAD_F(0x05cd22ef) /* 0.362582145 */, 15 },
- /* 1139 */ { MAD_F(0x05cee074) /* 0.363007026 */, 15 },
- /* 1140 */ { MAD_F(0x05d09e1b) /* 0.363432030 */, 15 },
- /* 1141 */ { MAD_F(0x05d25be2) /* 0.363857159 */, 15 },
- /* 1142 */ { MAD_F(0x05d419cb) /* 0.364282412 */, 15 },
- /* 1143 */ { MAD_F(0x05d5d7d5) /* 0.364707789 */, 15 },
- /* 1144 */ { MAD_F(0x05d79601) /* 0.365133291 */, 15 },
- /* 1145 */ { MAD_F(0x05d9544e) /* 0.365558916 */, 15 },
- /* 1146 */ { MAD_F(0x05db12bc) /* 0.365984665 */, 15 },
- /* 1147 */ { MAD_F(0x05dcd14c) /* 0.366410538 */, 15 },
- /* 1148 */ { MAD_F(0x05de8ffc) /* 0.366836535 */, 15 },
- /* 1149 */ { MAD_F(0x05e04ece) /* 0.367262655 */, 15 },
- /* 1150 */ { MAD_F(0x05e20dc1) /* 0.367688900 */, 15 },
- /* 1151 */ { MAD_F(0x05e3ccd5) /* 0.368115267 */, 15 },
-
- /* 1152 */ { MAD_F(0x05e58c0b) /* 0.368541759 */, 15 },
- /* 1153 */ { MAD_F(0x05e74b61) /* 0.368968373 */, 15 },
- /* 1154 */ { MAD_F(0x05e90ad9) /* 0.369395111 */, 15 },
- /* 1155 */ { MAD_F(0x05eaca72) /* 0.369821973 */, 15 },
- /* 1156 */ { MAD_F(0x05ec8a2b) /* 0.370248957 */, 15 },
- /* 1157 */ { MAD_F(0x05ee4a06) /* 0.370676065 */, 15 },
- /* 1158 */ { MAD_F(0x05f00a02) /* 0.371103295 */, 15 },
- /* 1159 */ { MAD_F(0x05f1ca1f) /* 0.371530649 */, 15 },
- /* 1160 */ { MAD_F(0x05f38a5d) /* 0.371958126 */, 15 },
- /* 1161 */ { MAD_F(0x05f54abc) /* 0.372385725 */, 15 },
- /* 1162 */ { MAD_F(0x05f70b3c) /* 0.372813448 */, 15 },
- /* 1163 */ { MAD_F(0x05f8cbdc) /* 0.373241292 */, 15 },
- /* 1164 */ { MAD_F(0x05fa8c9e) /* 0.373669260 */, 15 },
- /* 1165 */ { MAD_F(0x05fc4d81) /* 0.374097350 */, 15 },
- /* 1166 */ { MAD_F(0x05fe0e84) /* 0.374525563 */, 15 },
- /* 1167 */ { MAD_F(0x05ffcfa8) /* 0.374953898 */, 15 },
-
- /* 1168 */ { MAD_F(0x060190ee) /* 0.375382356 */, 15 },
- /* 1169 */ { MAD_F(0x06035254) /* 0.375810936 */, 15 },
- /* 1170 */ { MAD_F(0x060513da) /* 0.376239638 */, 15 },
- /* 1171 */ { MAD_F(0x0606d582) /* 0.376668462 */, 15 },
- /* 1172 */ { MAD_F(0x0608974a) /* 0.377097408 */, 15 },
- /* 1173 */ { MAD_F(0x060a5934) /* 0.377526476 */, 15 },
- /* 1174 */ { MAD_F(0x060c1b3d) /* 0.377955667 */, 15 },
- /* 1175 */ { MAD_F(0x060ddd68) /* 0.378384979 */, 15 },
- /* 1176 */ { MAD_F(0x060f9fb3) /* 0.378814413 */, 15 },
- /* 1177 */ { MAD_F(0x0611621f) /* 0.379243968 */, 15 },
- /* 1178 */ { MAD_F(0x061324ac) /* 0.379673646 */, 15 },
- /* 1179 */ { MAD_F(0x0614e759) /* 0.380103444 */, 15 },
- /* 1180 */ { MAD_F(0x0616aa27) /* 0.380533365 */, 15 },
- /* 1181 */ { MAD_F(0x06186d16) /* 0.380963407 */, 15 },
- /* 1182 */ { MAD_F(0x061a3025) /* 0.381393570 */, 15 },
- /* 1183 */ { MAD_F(0x061bf354) /* 0.381823855 */, 15 },
-
- /* 1184 */ { MAD_F(0x061db6a5) /* 0.382254261 */, 15 },
- /* 1185 */ { MAD_F(0x061f7a15) /* 0.382684788 */, 15 },
- /* 1186 */ { MAD_F(0x06213da7) /* 0.383115436 */, 15 },
- /* 1187 */ { MAD_F(0x06230158) /* 0.383546205 */, 15 },
- /* 1188 */ { MAD_F(0x0624c52a) /* 0.383977096 */, 15 },
- /* 1189 */ { MAD_F(0x0626891d) /* 0.384408107 */, 15 },
- /* 1190 */ { MAD_F(0x06284d30) /* 0.384839239 */, 15 },
- /* 1191 */ { MAD_F(0x062a1164) /* 0.385270492 */, 15 },
- /* 1192 */ { MAD_F(0x062bd5b8) /* 0.385701865 */, 15 },
- /* 1193 */ { MAD_F(0x062d9a2c) /* 0.386133359 */, 15 },
- /* 1194 */ { MAD_F(0x062f5ec1) /* 0.386564974 */, 15 },
- /* 1195 */ { MAD_F(0x06312376) /* 0.386996709 */, 15 },
- /* 1196 */ { MAD_F(0x0632e84b) /* 0.387428565 */, 15 },
- /* 1197 */ { MAD_F(0x0634ad41) /* 0.387860541 */, 15 },
- /* 1198 */ { MAD_F(0x06367257) /* 0.388292637 */, 15 },
- /* 1199 */ { MAD_F(0x0638378d) /* 0.388724854 */, 15 },
-
- /* 1200 */ { MAD_F(0x0639fce4) /* 0.389157191 */, 15 },
- /* 1201 */ { MAD_F(0x063bc25b) /* 0.389589648 */, 15 },
- /* 1202 */ { MAD_F(0x063d87f2) /* 0.390022225 */, 15 },
- /* 1203 */ { MAD_F(0x063f4da9) /* 0.390454922 */, 15 },
- /* 1204 */ { MAD_F(0x06411380) /* 0.390887739 */, 15 },
- /* 1205 */ { MAD_F(0x0642d978) /* 0.391320675 */, 15 },
- /* 1206 */ { MAD_F(0x06449f8f) /* 0.391753732 */, 15 },
- /* 1207 */ { MAD_F(0x064665c7) /* 0.392186908 */, 15 },
- /* 1208 */ { MAD_F(0x06482c1f) /* 0.392620204 */, 15 },
- /* 1209 */ { MAD_F(0x0649f297) /* 0.393053619 */, 15 },
- /* 1210 */ { MAD_F(0x064bb92f) /* 0.393487154 */, 15 },
- /* 1211 */ { MAD_F(0x064d7fe8) /* 0.393920808 */, 15 },
- /* 1212 */ { MAD_F(0x064f46c0) /* 0.394354582 */, 15 },
- /* 1213 */ { MAD_F(0x06510db8) /* 0.394788475 */, 15 },
- /* 1214 */ { MAD_F(0x0652d4d0) /* 0.395222488 */, 15 },
- /* 1215 */ { MAD_F(0x06549c09) /* 0.395656619 */, 15 },
-
- /* 1216 */ { MAD_F(0x06566361) /* 0.396090870 */, 15 },
- /* 1217 */ { MAD_F(0x06582ad9) /* 0.396525239 */, 15 },
- /* 1218 */ { MAD_F(0x0659f271) /* 0.396959728 */, 15 },
- /* 1219 */ { MAD_F(0x065bba29) /* 0.397394336 */, 15 },
- /* 1220 */ { MAD_F(0x065d8201) /* 0.397829062 */, 15 },
- /* 1221 */ { MAD_F(0x065f49f9) /* 0.398263907 */, 15 },
- /* 1222 */ { MAD_F(0x06611211) /* 0.398698871 */, 15 },
- /* 1223 */ { MAD_F(0x0662da49) /* 0.399133954 */, 15 },
- /* 1224 */ { MAD_F(0x0664a2a0) /* 0.399569155 */, 15 },
- /* 1225 */ { MAD_F(0x06666b17) /* 0.400004475 */, 15 },
- /* 1226 */ { MAD_F(0x066833ae) /* 0.400439913 */, 15 },
- /* 1227 */ { MAD_F(0x0669fc65) /* 0.400875470 */, 15 },
- /* 1228 */ { MAD_F(0x066bc53c) /* 0.401311145 */, 15 },
- /* 1229 */ { MAD_F(0x066d8e32) /* 0.401746938 */, 15 },
- /* 1230 */ { MAD_F(0x066f5748) /* 0.402182850 */, 15 },
- /* 1231 */ { MAD_F(0x0671207e) /* 0.402618879 */, 15 },
-
- /* 1232 */ { MAD_F(0x0672e9d4) /* 0.403055027 */, 15 },
- /* 1233 */ { MAD_F(0x0674b349) /* 0.403491293 */, 15 },
- /* 1234 */ { MAD_F(0x06767cde) /* 0.403927676 */, 15 },
- /* 1235 */ { MAD_F(0x06784692) /* 0.404364178 */, 15 },
- /* 1236 */ { MAD_F(0x067a1066) /* 0.404800797 */, 15 },
- /* 1237 */ { MAD_F(0x067bda5a) /* 0.405237535 */, 15 },
- /* 1238 */ { MAD_F(0x067da46d) /* 0.405674390 */, 15 },
- /* 1239 */ { MAD_F(0x067f6ea0) /* 0.406111362 */, 15 },
- /* 1240 */ { MAD_F(0x068138f3) /* 0.406548452 */, 15 },
- /* 1241 */ { MAD_F(0x06830365) /* 0.406985660 */, 15 },
- /* 1242 */ { MAD_F(0x0684cdf6) /* 0.407422985 */, 15 },
- /* 1243 */ { MAD_F(0x068698a8) /* 0.407860427 */, 15 },
- /* 1244 */ { MAD_F(0x06886378) /* 0.408297987 */, 15 },
- /* 1245 */ { MAD_F(0x068a2e68) /* 0.408735664 */, 15 },
- /* 1246 */ { MAD_F(0x068bf978) /* 0.409173458 */, 15 },
- /* 1247 */ { MAD_F(0x068dc4a7) /* 0.409611370 */, 15 },
-
- /* 1248 */ { MAD_F(0x068f8ff5) /* 0.410049398 */, 15 },
- /* 1249 */ { MAD_F(0x06915b63) /* 0.410487544 */, 15 },
- /* 1250 */ { MAD_F(0x069326f0) /* 0.410925806 */, 15 },
- /* 1251 */ { MAD_F(0x0694f29c) /* 0.411364185 */, 15 },
- /* 1252 */ { MAD_F(0x0696be68) /* 0.411802681 */, 15 },
- /* 1253 */ { MAD_F(0x06988a54) /* 0.412241294 */, 15 },
- /* 1254 */ { MAD_F(0x069a565e) /* 0.412680024 */, 15 },
- /* 1255 */ { MAD_F(0x069c2288) /* 0.413118870 */, 15 },
- /* 1256 */ { MAD_F(0x069deed1) /* 0.413557833 */, 15 },
- /* 1257 */ { MAD_F(0x069fbb3a) /* 0.413996912 */, 15 },
- /* 1258 */ { MAD_F(0x06a187c1) /* 0.414436108 */, 15 },
- /* 1259 */ { MAD_F(0x06a35468) /* 0.414875420 */, 15 },
- /* 1260 */ { MAD_F(0x06a5212f) /* 0.415314849 */, 15 },
- /* 1261 */ { MAD_F(0x06a6ee14) /* 0.415754393 */, 15 },
- /* 1262 */ { MAD_F(0x06a8bb18) /* 0.416194054 */, 15 },
- /* 1263 */ { MAD_F(0x06aa883c) /* 0.416633831 */, 15 },
-
- /* 1264 */ { MAD_F(0x06ac557f) /* 0.417073724 */, 15 },
- /* 1265 */ { MAD_F(0x06ae22e1) /* 0.417513734 */, 15 },
- /* 1266 */ { MAD_F(0x06aff062) /* 0.417953859 */, 15 },
- /* 1267 */ { MAD_F(0x06b1be03) /* 0.418394100 */, 15 },
- /* 1268 */ { MAD_F(0x06b38bc2) /* 0.418834457 */, 15 },
- /* 1269 */ { MAD_F(0x06b559a1) /* 0.419274929 */, 15 },
- /* 1270 */ { MAD_F(0x06b7279e) /* 0.419715518 */, 15 },
- /* 1271 */ { MAD_F(0x06b8f5bb) /* 0.420156222 */, 15 },
- /* 1272 */ { MAD_F(0x06bac3f6) /* 0.420597041 */, 15 },
- /* 1273 */ { MAD_F(0x06bc9251) /* 0.421037977 */, 15 },
- /* 1274 */ { MAD_F(0x06be60cb) /* 0.421479027 */, 15 },
- /* 1275 */ { MAD_F(0x06c02f63) /* 0.421920193 */, 15 },
- /* 1276 */ { MAD_F(0x06c1fe1b) /* 0.422361475 */, 15 },
- /* 1277 */ { MAD_F(0x06c3ccf1) /* 0.422802871 */, 15 },
- /* 1278 */ { MAD_F(0x06c59be7) /* 0.423244383 */, 15 },
- /* 1279 */ { MAD_F(0x06c76afb) /* 0.423686010 */, 15 },
-
- /* 1280 */ { MAD_F(0x06c93a2e) /* 0.424127753 */, 15 },
- /* 1281 */ { MAD_F(0x06cb0981) /* 0.424569610 */, 15 },
- /* 1282 */ { MAD_F(0x06ccd8f2) /* 0.425011582 */, 15 },
- /* 1283 */ { MAD_F(0x06cea881) /* 0.425453669 */, 15 },
- /* 1284 */ { MAD_F(0x06d07830) /* 0.425895871 */, 15 },
- /* 1285 */ { MAD_F(0x06d247fe) /* 0.426338188 */, 15 },
- /* 1286 */ { MAD_F(0x06d417ea) /* 0.426780620 */, 15 },
- /* 1287 */ { MAD_F(0x06d5e7f5) /* 0.427223166 */, 15 },
- /* 1288 */ { MAD_F(0x06d7b81f) /* 0.427665827 */, 15 },
- /* 1289 */ { MAD_F(0x06d98868) /* 0.428108603 */, 15 },
- /* 1290 */ { MAD_F(0x06db58cf) /* 0.428551493 */, 15 },
- /* 1291 */ { MAD_F(0x06dd2955) /* 0.428994497 */, 15 },
- /* 1292 */ { MAD_F(0x06def9fa) /* 0.429437616 */, 15 },
- /* 1293 */ { MAD_F(0x06e0cabe) /* 0.429880849 */, 15 },
- /* 1294 */ { MAD_F(0x06e29ba0) /* 0.430324197 */, 15 },
- /* 1295 */ { MAD_F(0x06e46ca1) /* 0.430767659 */, 15 },
-
- /* 1296 */ { MAD_F(0x06e63dc0) /* 0.431211234 */, 15 },
- /* 1297 */ { MAD_F(0x06e80efe) /* 0.431654924 */, 15 },
- /* 1298 */ { MAD_F(0x06e9e05b) /* 0.432098728 */, 15 },
- /* 1299 */ { MAD_F(0x06ebb1d6) /* 0.432542647 */, 15 },
- /* 1300 */ { MAD_F(0x06ed8370) /* 0.432986678 */, 15 },
- /* 1301 */ { MAD_F(0x06ef5529) /* 0.433430824 */, 15 },
- /* 1302 */ { MAD_F(0x06f12700) /* 0.433875084 */, 15 },
- /* 1303 */ { MAD_F(0x06f2f8f5) /* 0.434319457 */, 15 },
- /* 1304 */ { MAD_F(0x06f4cb09) /* 0.434763944 */, 15 },
- /* 1305 */ { MAD_F(0x06f69d3c) /* 0.435208545 */, 15 },
- /* 1306 */ { MAD_F(0x06f86f8d) /* 0.435653259 */, 15 },
- /* 1307 */ { MAD_F(0x06fa41fd) /* 0.436098087 */, 15 },
- /* 1308 */ { MAD_F(0x06fc148b) /* 0.436543029 */, 15 },
- /* 1309 */ { MAD_F(0x06fde737) /* 0.436988083 */, 15 },
- /* 1310 */ { MAD_F(0x06ffba02) /* 0.437433251 */, 15 },
- /* 1311 */ { MAD_F(0x07018ceb) /* 0.437878533 */, 15 },
-
- /* 1312 */ { MAD_F(0x07035ff3) /* 0.438323927 */, 15 },
- /* 1313 */ { MAD_F(0x07053319) /* 0.438769435 */, 15 },
- /* 1314 */ { MAD_F(0x0707065d) /* 0.439215056 */, 15 },
- /* 1315 */ { MAD_F(0x0708d9c0) /* 0.439660790 */, 15 },
- /* 1316 */ { MAD_F(0x070aad41) /* 0.440106636 */, 15 },
- /* 1317 */ { MAD_F(0x070c80e1) /* 0.440552596 */, 15 },
- /* 1318 */ { MAD_F(0x070e549f) /* 0.440998669 */, 15 },
- /* 1319 */ { MAD_F(0x0710287b) /* 0.441444855 */, 15 },
- /* 1320 */ { MAD_F(0x0711fc75) /* 0.441891153 */, 15 },
- /* 1321 */ { MAD_F(0x0713d08d) /* 0.442337564 */, 15 },
- /* 1322 */ { MAD_F(0x0715a4c4) /* 0.442784088 */, 15 },
- /* 1323 */ { MAD_F(0x07177919) /* 0.443230724 */, 15 },
- /* 1324 */ { MAD_F(0x07194d8c) /* 0.443677473 */, 15 },
- /* 1325 */ { MAD_F(0x071b221e) /* 0.444124334 */, 15 },
- /* 1326 */ { MAD_F(0x071cf6ce) /* 0.444571308 */, 15 },
- /* 1327 */ { MAD_F(0x071ecb9b) /* 0.445018394 */, 15 },
-
- /* 1328 */ { MAD_F(0x0720a087) /* 0.445465593 */, 15 },
- /* 1329 */ { MAD_F(0x07227591) /* 0.445912903 */, 15 },
- /* 1330 */ { MAD_F(0x07244ab9) /* 0.446360326 */, 15 },
- /* 1331 */ { MAD_F(0x07262000) /* 0.446807861 */, 15 },
- /* 1332 */ { MAD_F(0x0727f564) /* 0.447255509 */, 15 },
- /* 1333 */ { MAD_F(0x0729cae7) /* 0.447703268 */, 15 },
- /* 1334 */ { MAD_F(0x072ba087) /* 0.448151139 */, 15 },
- /* 1335 */ { MAD_F(0x072d7646) /* 0.448599122 */, 15 },
- /* 1336 */ { MAD_F(0x072f4c22) /* 0.449047217 */, 15 },
- /* 1337 */ { MAD_F(0x0731221d) /* 0.449495424 */, 15 },
- /* 1338 */ { MAD_F(0x0732f835) /* 0.449943742 */, 15 },
- /* 1339 */ { MAD_F(0x0734ce6c) /* 0.450392173 */, 15 },
- /* 1340 */ { MAD_F(0x0736a4c1) /* 0.450840715 */, 15 },
- /* 1341 */ { MAD_F(0x07387b33) /* 0.451289368 */, 15 },
- /* 1342 */ { MAD_F(0x073a51c4) /* 0.451738133 */, 15 },
- /* 1343 */ { MAD_F(0x073c2872) /* 0.452187010 */, 15 },
-
- /* 1344 */ { MAD_F(0x073dff3e) /* 0.452635998 */, 15 },
- /* 1345 */ { MAD_F(0x073fd628) /* 0.453085097 */, 15 },
- /* 1346 */ { MAD_F(0x0741ad30) /* 0.453534308 */, 15 },
- /* 1347 */ { MAD_F(0x07438456) /* 0.453983630 */, 15 },
- /* 1348 */ { MAD_F(0x07455b9a) /* 0.454433063 */, 15 },
- /* 1349 */ { MAD_F(0x074732fc) /* 0.454882607 */, 15 },
- /* 1350 */ { MAD_F(0x07490a7b) /* 0.455332262 */, 15 },
- /* 1351 */ { MAD_F(0x074ae218) /* 0.455782029 */, 15 },
- /* 1352 */ { MAD_F(0x074cb9d3) /* 0.456231906 */, 15 },
- /* 1353 */ { MAD_F(0x074e91ac) /* 0.456681894 */, 15 },
- /* 1354 */ { MAD_F(0x075069a3) /* 0.457131993 */, 15 },
- /* 1355 */ { MAD_F(0x075241b7) /* 0.457582203 */, 15 },
- /* 1356 */ { MAD_F(0x075419e9) /* 0.458032524 */, 15 },
- /* 1357 */ { MAD_F(0x0755f239) /* 0.458482956 */, 15 },
- /* 1358 */ { MAD_F(0x0757caa7) /* 0.458933498 */, 15 },
- /* 1359 */ { MAD_F(0x0759a332) /* 0.459384151 */, 15 },
-
- /* 1360 */ { MAD_F(0x075b7bdb) /* 0.459834914 */, 15 },
- /* 1361 */ { MAD_F(0x075d54a1) /* 0.460285788 */, 15 },
- /* 1362 */ { MAD_F(0x075f2d85) /* 0.460736772 */, 15 },
- /* 1363 */ { MAD_F(0x07610687) /* 0.461187867 */, 15 },
- /* 1364 */ { MAD_F(0x0762dfa6) /* 0.461639071 */, 15 },
- /* 1365 */ { MAD_F(0x0764b8e3) /* 0.462090387 */, 15 },
- /* 1366 */ { MAD_F(0x0766923e) /* 0.462541812 */, 15 },
- /* 1367 */ { MAD_F(0x07686bb6) /* 0.462993348 */, 15 },
- /* 1368 */ { MAD_F(0x076a454c) /* 0.463444993 */, 15 },
- /* 1369 */ { MAD_F(0x076c1eff) /* 0.463896749 */, 15 },
- /* 1370 */ { MAD_F(0x076df8d0) /* 0.464348615 */, 15 },
- /* 1371 */ { MAD_F(0x076fd2be) /* 0.464800591 */, 15 },
- /* 1372 */ { MAD_F(0x0771acca) /* 0.465252676 */, 15 },
- /* 1373 */ { MAD_F(0x077386f3) /* 0.465704872 */, 15 },
- /* 1374 */ { MAD_F(0x0775613a) /* 0.466157177 */, 15 },
- /* 1375 */ { MAD_F(0x07773b9e) /* 0.466609592 */, 15 },
-
- /* 1376 */ { MAD_F(0x07791620) /* 0.467062117 */, 15 },
- /* 1377 */ { MAD_F(0x077af0bf) /* 0.467514751 */, 15 },
- /* 1378 */ { MAD_F(0x077ccb7c) /* 0.467967495 */, 15 },
- /* 1379 */ { MAD_F(0x077ea656) /* 0.468420349 */, 15 },
- /* 1380 */ { MAD_F(0x0780814d) /* 0.468873312 */, 15 },
- /* 1381 */ { MAD_F(0x07825c62) /* 0.469326384 */, 15 },
- /* 1382 */ { MAD_F(0x07843794) /* 0.469779566 */, 15 },
- /* 1383 */ { MAD_F(0x078612e3) /* 0.470232857 */, 15 },
- /* 1384 */ { MAD_F(0x0787ee50) /* 0.470686258 */, 15 },
- /* 1385 */ { MAD_F(0x0789c9da) /* 0.471139767 */, 15 },
- /* 1386 */ { MAD_F(0x078ba581) /* 0.471593386 */, 15 },
- /* 1387 */ { MAD_F(0x078d8146) /* 0.472047114 */, 15 },
- /* 1388 */ { MAD_F(0x078f5d28) /* 0.472500951 */, 15 },
- /* 1389 */ { MAD_F(0x07913927) /* 0.472954896 */, 15 },
- /* 1390 */ { MAD_F(0x07931543) /* 0.473408951 */, 15 },
- /* 1391 */ { MAD_F(0x0794f17d) /* 0.473863115 */, 15 },
-
- /* 1392 */ { MAD_F(0x0796cdd4) /* 0.474317388 */, 15 },
- /* 1393 */ { MAD_F(0x0798aa48) /* 0.474771769 */, 15 },
- /* 1394 */ { MAD_F(0x079a86d9) /* 0.475226259 */, 15 },
- /* 1395 */ { MAD_F(0x079c6388) /* 0.475680858 */, 15 },
- /* 1396 */ { MAD_F(0x079e4053) /* 0.476135565 */, 15 },
- /* 1397 */ { MAD_F(0x07a01d3c) /* 0.476590381 */, 15 },
- /* 1398 */ { MAD_F(0x07a1fa42) /* 0.477045306 */, 15 },
- /* 1399 */ { MAD_F(0x07a3d765) /* 0.477500339 */, 15 },
- /* 1400 */ { MAD_F(0x07a5b4a5) /* 0.477955481 */, 15 },
- /* 1401 */ { MAD_F(0x07a79202) /* 0.478410731 */, 15 },
- /* 1402 */ { MAD_F(0x07a96f7d) /* 0.478866089 */, 15 },
- /* 1403 */ { MAD_F(0x07ab4d14) /* 0.479321555 */, 15 },
- /* 1404 */ { MAD_F(0x07ad2ac8) /* 0.479777130 */, 15 },
- /* 1405 */ { MAD_F(0x07af089a) /* 0.480232813 */, 15 },
- /* 1406 */ { MAD_F(0x07b0e688) /* 0.480688604 */, 15 },
- /* 1407 */ { MAD_F(0x07b2c494) /* 0.481144503 */, 15 },
-
- /* 1408 */ { MAD_F(0x07b4a2bc) /* 0.481600510 */, 15 },
- /* 1409 */ { MAD_F(0x07b68102) /* 0.482056625 */, 15 },
- /* 1410 */ { MAD_F(0x07b85f64) /* 0.482512848 */, 15 },
- /* 1411 */ { MAD_F(0x07ba3de4) /* 0.482969179 */, 15 },
- /* 1412 */ { MAD_F(0x07bc1c80) /* 0.483425618 */, 15 },
- /* 1413 */ { MAD_F(0x07bdfb39) /* 0.483882164 */, 15 },
- /* 1414 */ { MAD_F(0x07bfda0f) /* 0.484338818 */, 15 },
- /* 1415 */ { MAD_F(0x07c1b902) /* 0.484795580 */, 15 },
- /* 1416 */ { MAD_F(0x07c39812) /* 0.485252449 */, 15 },
- /* 1417 */ { MAD_F(0x07c5773f) /* 0.485709426 */, 15 },
- /* 1418 */ { MAD_F(0x07c75689) /* 0.486166511 */, 15 },
- /* 1419 */ { MAD_F(0x07c935ef) /* 0.486623703 */, 15 },
- /* 1420 */ { MAD_F(0x07cb1573) /* 0.487081002 */, 15 },
- /* 1421 */ { MAD_F(0x07ccf513) /* 0.487538409 */, 15 },
- /* 1422 */ { MAD_F(0x07ced4d0) /* 0.487995923 */, 15 },
- /* 1423 */ { MAD_F(0x07d0b4aa) /* 0.488453544 */, 15 },
-
- /* 1424 */ { MAD_F(0x07d294a0) /* 0.488911273 */, 15 },
- /* 1425 */ { MAD_F(0x07d474b3) /* 0.489369108 */, 15 },
- /* 1426 */ { MAD_F(0x07d654e4) /* 0.489827051 */, 15 },
- /* 1427 */ { MAD_F(0x07d83530) /* 0.490285101 */, 15 },
- /* 1428 */ { MAD_F(0x07da159a) /* 0.490743258 */, 15 },
- /* 1429 */ { MAD_F(0x07dbf620) /* 0.491201522 */, 15 },
- /* 1430 */ { MAD_F(0x07ddd6c3) /* 0.491659892 */, 15 },
- /* 1431 */ { MAD_F(0x07dfb783) /* 0.492118370 */, 15 },
- /* 1432 */ { MAD_F(0x07e1985f) /* 0.492576954 */, 15 },
- /* 1433 */ { MAD_F(0x07e37958) /* 0.493035645 */, 15 },
- /* 1434 */ { MAD_F(0x07e55a6e) /* 0.493494443 */, 15 },
- /* 1435 */ { MAD_F(0x07e73ba0) /* 0.493953348 */, 15 },
- /* 1436 */ { MAD_F(0x07e91cef) /* 0.494412359 */, 15 },
- /* 1437 */ { MAD_F(0x07eafe5a) /* 0.494871476 */, 15 },
- /* 1438 */ { MAD_F(0x07ecdfe2) /* 0.495330701 */, 15 },
- /* 1439 */ { MAD_F(0x07eec187) /* 0.495790031 */, 15 },
-
- /* 1440 */ { MAD_F(0x07f0a348) /* 0.496249468 */, 15 },
- /* 1441 */ { MAD_F(0x07f28526) /* 0.496709012 */, 15 },
- /* 1442 */ { MAD_F(0x07f46720) /* 0.497168662 */, 15 },
- /* 1443 */ { MAD_F(0x07f64937) /* 0.497628418 */, 15 },
- /* 1444 */ { MAD_F(0x07f82b6a) /* 0.498088280 */, 15 },
- /* 1445 */ { MAD_F(0x07fa0dba) /* 0.498548248 */, 15 },
- /* 1446 */ { MAD_F(0x07fbf026) /* 0.499008323 */, 15 },
- /* 1447 */ { MAD_F(0x07fdd2af) /* 0.499468503 */, 15 },
- /* 1448 */ { MAD_F(0x07ffb554) /* 0.499928790 */, 15 },
- /* 1449 */ { MAD_F(0x0400cc0b) /* 0.250194591 */, 16 },
- /* 1450 */ { MAD_F(0x0401bd7a) /* 0.250424840 */, 16 },
- /* 1451 */ { MAD_F(0x0402aef7) /* 0.250655143 */, 16 },
- /* 1452 */ { MAD_F(0x0403a083) /* 0.250885498 */, 16 },
- /* 1453 */ { MAD_F(0x0404921c) /* 0.251115906 */, 16 },
- /* 1454 */ { MAD_F(0x040583c4) /* 0.251346367 */, 16 },
- /* 1455 */ { MAD_F(0x0406757a) /* 0.251576880 */, 16 },
-
- /* 1456 */ { MAD_F(0x0407673f) /* 0.251807447 */, 16 },
- /* 1457 */ { MAD_F(0x04085911) /* 0.252038066 */, 16 },
- /* 1458 */ { MAD_F(0x04094af1) /* 0.252268738 */, 16 },
- /* 1459 */ { MAD_F(0x040a3ce0) /* 0.252499463 */, 16 },
- /* 1460 */ { MAD_F(0x040b2edd) /* 0.252730240 */, 16 },
- /* 1461 */ { MAD_F(0x040c20e8) /* 0.252961071 */, 16 },
- /* 1462 */ { MAD_F(0x040d1301) /* 0.253191953 */, 16 },
- /* 1463 */ { MAD_F(0x040e0529) /* 0.253422889 */, 16 },
- /* 1464 */ { MAD_F(0x040ef75e) /* 0.253653877 */, 16 },
- /* 1465 */ { MAD_F(0x040fe9a1) /* 0.253884918 */, 16 },
- /* 1466 */ { MAD_F(0x0410dbf3) /* 0.254116011 */, 16 },
- /* 1467 */ { MAD_F(0x0411ce53) /* 0.254347157 */, 16 },
- /* 1468 */ { MAD_F(0x0412c0c1) /* 0.254578356 */, 16 },
- /* 1469 */ { MAD_F(0x0413b33d) /* 0.254809606 */, 16 },
- /* 1470 */ { MAD_F(0x0414a5c7) /* 0.255040910 */, 16 },
- /* 1471 */ { MAD_F(0x0415985f) /* 0.255272266 */, 16 },
-
- /* 1472 */ { MAD_F(0x04168b05) /* 0.255503674 */, 16 },
- /* 1473 */ { MAD_F(0x04177db9) /* 0.255735135 */, 16 },
- /* 1474 */ { MAD_F(0x0418707c) /* 0.255966648 */, 16 },
- /* 1475 */ { MAD_F(0x0419634c) /* 0.256198213 */, 16 },
- /* 1476 */ { MAD_F(0x041a562a) /* 0.256429831 */, 16 },
- /* 1477 */ { MAD_F(0x041b4917) /* 0.256661501 */, 16 },
- /* 1478 */ { MAD_F(0x041c3c11) /* 0.256893223 */, 16 },
- /* 1479 */ { MAD_F(0x041d2f1a) /* 0.257124998 */, 16 },
- /* 1480 */ { MAD_F(0x041e2230) /* 0.257356825 */, 16 },
- /* 1481 */ { MAD_F(0x041f1555) /* 0.257588704 */, 16 },
- /* 1482 */ { MAD_F(0x04200888) /* 0.257820635 */, 16 },
- /* 1483 */ { MAD_F(0x0420fbc8) /* 0.258052619 */, 16 },
- /* 1484 */ { MAD_F(0x0421ef17) /* 0.258284654 */, 16 },
- /* 1485 */ { MAD_F(0x0422e273) /* 0.258516742 */, 16 },
- /* 1486 */ { MAD_F(0x0423d5de) /* 0.258748882 */, 16 },
- /* 1487 */ { MAD_F(0x0424c956) /* 0.258981074 */, 16 },
-
- /* 1488 */ { MAD_F(0x0425bcdd) /* 0.259213318 */, 16 },
- /* 1489 */ { MAD_F(0x0426b071) /* 0.259445614 */, 16 },
- /* 1490 */ { MAD_F(0x0427a414) /* 0.259677962 */, 16 },
- /* 1491 */ { MAD_F(0x042897c4) /* 0.259910362 */, 16 },
- /* 1492 */ { MAD_F(0x04298b83) /* 0.260142814 */, 16 },
- /* 1493 */ { MAD_F(0x042a7f4f) /* 0.260375318 */, 16 },
- /* 1494 */ { MAD_F(0x042b7329) /* 0.260607874 */, 16 },
- /* 1495 */ { MAD_F(0x042c6711) /* 0.260840481 */, 16 },
- /* 1496 */ { MAD_F(0x042d5b07) /* 0.261073141 */, 16 },
- /* 1497 */ { MAD_F(0x042e4f0b) /* 0.261305852 */, 16 },
- /* 1498 */ { MAD_F(0x042f431d) /* 0.261538616 */, 16 },
- /* 1499 */ { MAD_F(0x0430373d) /* 0.261771431 */, 16 },
- /* 1500 */ { MAD_F(0x04312b6b) /* 0.262004297 */, 16 },
- /* 1501 */ { MAD_F(0x04321fa6) /* 0.262237216 */, 16 },
- /* 1502 */ { MAD_F(0x043313f0) /* 0.262470186 */, 16 },
- /* 1503 */ { MAD_F(0x04340847) /* 0.262703208 */, 16 },
-
- /* 1504 */ { MAD_F(0x0434fcad) /* 0.262936282 */, 16 },
- /* 1505 */ { MAD_F(0x0435f120) /* 0.263169407 */, 16 },
- /* 1506 */ { MAD_F(0x0436e5a1) /* 0.263402584 */, 16 },
- /* 1507 */ { MAD_F(0x0437da2f) /* 0.263635813 */, 16 },
- /* 1508 */ { MAD_F(0x0438cecc) /* 0.263869093 */, 16 },
- /* 1509 */ { MAD_F(0x0439c377) /* 0.264102425 */, 16 },
- /* 1510 */ { MAD_F(0x043ab82f) /* 0.264335808 */, 16 },
- /* 1511 */ { MAD_F(0x043bacf5) /* 0.264569243 */, 16 },
- /* 1512 */ { MAD_F(0x043ca1c9) /* 0.264802730 */, 16 },
- /* 1513 */ { MAD_F(0x043d96ab) /* 0.265036267 */, 16 },
- /* 1514 */ { MAD_F(0x043e8b9b) /* 0.265269857 */, 16 },
- /* 1515 */ { MAD_F(0x043f8098) /* 0.265503498 */, 16 },
- /* 1516 */ { MAD_F(0x044075a3) /* 0.265737190 */, 16 },
- /* 1517 */ { MAD_F(0x04416abc) /* 0.265970933 */, 16 },
- /* 1518 */ { MAD_F(0x04425fe3) /* 0.266204728 */, 16 },
- /* 1519 */ { MAD_F(0x04435518) /* 0.266438574 */, 16 },
-
- /* 1520 */ { MAD_F(0x04444a5a) /* 0.266672472 */, 16 },
- /* 1521 */ { MAD_F(0x04453fab) /* 0.266906421 */, 16 },
- /* 1522 */ { MAD_F(0x04463508) /* 0.267140421 */, 16 },
- /* 1523 */ { MAD_F(0x04472a74) /* 0.267374472 */, 16 },
- /* 1524 */ { MAD_F(0x04481fee) /* 0.267608575 */, 16 },
- /* 1525 */ { MAD_F(0x04491575) /* 0.267842729 */, 16 },
- /* 1526 */ { MAD_F(0x044a0b0a) /* 0.268076934 */, 16 },
- /* 1527 */ { MAD_F(0x044b00ac) /* 0.268311190 */, 16 },
- /* 1528 */ { MAD_F(0x044bf65d) /* 0.268545497 */, 16 },
- /* 1529 */ { MAD_F(0x044cec1b) /* 0.268779856 */, 16 },
- /* 1530 */ { MAD_F(0x044de1e7) /* 0.269014265 */, 16 },
- /* 1531 */ { MAD_F(0x044ed7c0) /* 0.269248726 */, 16 },
- /* 1532 */ { MAD_F(0x044fcda8) /* 0.269483238 */, 16 },
- /* 1533 */ { MAD_F(0x0450c39c) /* 0.269717800 */, 16 },
- /* 1534 */ { MAD_F(0x0451b99f) /* 0.269952414 */, 16 },
- /* 1535 */ { MAD_F(0x0452afaf) /* 0.270187079 */, 16 },
-
- /* 1536 */ { MAD_F(0x0453a5cd) /* 0.270421794 */, 16 },
- /* 1537 */ { MAD_F(0x04549bf9) /* 0.270656561 */, 16 },
- /* 1538 */ { MAD_F(0x04559232) /* 0.270891379 */, 16 },
- /* 1539 */ { MAD_F(0x04568879) /* 0.271126247 */, 16 },
- /* 1540 */ { MAD_F(0x04577ece) /* 0.271361166 */, 16 },
- /* 1541 */ { MAD_F(0x04587530) /* 0.271596136 */, 16 },
- /* 1542 */ { MAD_F(0x04596ba0) /* 0.271831157 */, 16 },
- /* 1543 */ { MAD_F(0x045a621e) /* 0.272066229 */, 16 },
- /* 1544 */ { MAD_F(0x045b58a9) /* 0.272301352 */, 16 },
- /* 1545 */ { MAD_F(0x045c4f42) /* 0.272536525 */, 16 },
- /* 1546 */ { MAD_F(0x045d45e9) /* 0.272771749 */, 16 },
- /* 1547 */ { MAD_F(0x045e3c9d) /* 0.273007024 */, 16 },
- /* 1548 */ { MAD_F(0x045f335e) /* 0.273242350 */, 16 },
- /* 1549 */ { MAD_F(0x04602a2e) /* 0.273477726 */, 16 },
- /* 1550 */ { MAD_F(0x0461210b) /* 0.273713153 */, 16 },
- /* 1551 */ { MAD_F(0x046217f5) /* 0.273948630 */, 16 },
-
- /* 1552 */ { MAD_F(0x04630eed) /* 0.274184158 */, 16 },
- /* 1553 */ { MAD_F(0x046405f3) /* 0.274419737 */, 16 },
- /* 1554 */ { MAD_F(0x0464fd06) /* 0.274655366 */, 16 },
- /* 1555 */ { MAD_F(0x0465f427) /* 0.274891046 */, 16 },
- /* 1556 */ { MAD_F(0x0466eb55) /* 0.275126776 */, 16 },
- /* 1557 */ { MAD_F(0x0467e291) /* 0.275362557 */, 16 },
- /* 1558 */ { MAD_F(0x0468d9db) /* 0.275598389 */, 16 },
- /* 1559 */ { MAD_F(0x0469d132) /* 0.275834270 */, 16 },
- /* 1560 */ { MAD_F(0x046ac896) /* 0.276070203 */, 16 },
- /* 1561 */ { MAD_F(0x046bc009) /* 0.276306185 */, 16 },
- /* 1562 */ { MAD_F(0x046cb788) /* 0.276542218 */, 16 },
- /* 1563 */ { MAD_F(0x046daf15) /* 0.276778302 */, 16 },
- /* 1564 */ { MAD_F(0x046ea6b0) /* 0.277014435 */, 16 },
- /* 1565 */ { MAD_F(0x046f9e58) /* 0.277250619 */, 16 },
- /* 1566 */ { MAD_F(0x0470960e) /* 0.277486854 */, 16 },
- /* 1567 */ { MAD_F(0x04718dd1) /* 0.277723139 */, 16 },
-
- /* 1568 */ { MAD_F(0x047285a2) /* 0.277959474 */, 16 },
- /* 1569 */ { MAD_F(0x04737d80) /* 0.278195859 */, 16 },
- /* 1570 */ { MAD_F(0x0474756c) /* 0.278432294 */, 16 },
- /* 1571 */ { MAD_F(0x04756d65) /* 0.278668780 */, 16 },
- /* 1572 */ { MAD_F(0x0476656b) /* 0.278905316 */, 16 },
- /* 1573 */ { MAD_F(0x04775d7f) /* 0.279141902 */, 16 },
- /* 1574 */ { MAD_F(0x047855a1) /* 0.279378538 */, 16 },
- /* 1575 */ { MAD_F(0x04794dd0) /* 0.279615224 */, 16 },
- /* 1576 */ { MAD_F(0x047a460c) /* 0.279851960 */, 16 },
- /* 1577 */ { MAD_F(0x047b3e56) /* 0.280088747 */, 16 },
- /* 1578 */ { MAD_F(0x047c36ae) /* 0.280325583 */, 16 },
- /* 1579 */ { MAD_F(0x047d2f12) /* 0.280562470 */, 16 },
- /* 1580 */ { MAD_F(0x047e2784) /* 0.280799406 */, 16 },
- /* 1581 */ { MAD_F(0x047f2004) /* 0.281036393 */, 16 },
- /* 1582 */ { MAD_F(0x04801891) /* 0.281273429 */, 16 },
- /* 1583 */ { MAD_F(0x0481112b) /* 0.281510516 */, 16 },
-
- /* 1584 */ { MAD_F(0x048209d3) /* 0.281747652 */, 16 },
- /* 1585 */ { MAD_F(0x04830288) /* 0.281984838 */, 16 },
- /* 1586 */ { MAD_F(0x0483fb4b) /* 0.282222075 */, 16 },
- /* 1587 */ { MAD_F(0x0484f41b) /* 0.282459361 */, 16 },
- /* 1588 */ { MAD_F(0x0485ecf8) /* 0.282696697 */, 16 },
- /* 1589 */ { MAD_F(0x0486e5e3) /* 0.282934082 */, 16 },
- /* 1590 */ { MAD_F(0x0487dedb) /* 0.283171518 */, 16 },
- /* 1591 */ { MAD_F(0x0488d7e1) /* 0.283409003 */, 16 },
- /* 1592 */ { MAD_F(0x0489d0f4) /* 0.283646538 */, 16 },
- /* 1593 */ { MAD_F(0x048aca14) /* 0.283884123 */, 16 },
- /* 1594 */ { MAD_F(0x048bc341) /* 0.284121757 */, 16 },
- /* 1595 */ { MAD_F(0x048cbc7c) /* 0.284359441 */, 16 },
- /* 1596 */ { MAD_F(0x048db5c4) /* 0.284597175 */, 16 },
- /* 1597 */ { MAD_F(0x048eaf1a) /* 0.284834959 */, 16 },
- /* 1598 */ { MAD_F(0x048fa87d) /* 0.285072792 */, 16 },
- /* 1599 */ { MAD_F(0x0490a1ed) /* 0.285310675 */, 16 },
-
- /* 1600 */ { MAD_F(0x04919b6a) /* 0.285548607 */, 16 },
- /* 1601 */ { MAD_F(0x049294f5) /* 0.285786589 */, 16 },
- /* 1602 */ { MAD_F(0x04938e8d) /* 0.286024621 */, 16 },
- /* 1603 */ { MAD_F(0x04948833) /* 0.286262702 */, 16 },
- /* 1604 */ { MAD_F(0x049581e5) /* 0.286500832 */, 16 },
- /* 1605 */ { MAD_F(0x04967ba5) /* 0.286739012 */, 16 },
- /* 1606 */ { MAD_F(0x04977573) /* 0.286977242 */, 16 },
- /* 1607 */ { MAD_F(0x04986f4d) /* 0.287215521 */, 16 },
- /* 1608 */ { MAD_F(0x04996935) /* 0.287453849 */, 16 },
- /* 1609 */ { MAD_F(0x049a632a) /* 0.287692227 */, 16 },
- /* 1610 */ { MAD_F(0x049b5d2c) /* 0.287930654 */, 16 },
- /* 1611 */ { MAD_F(0x049c573c) /* 0.288169131 */, 16 },
- /* 1612 */ { MAD_F(0x049d5159) /* 0.288407657 */, 16 },
- /* 1613 */ { MAD_F(0x049e4b83) /* 0.288646232 */, 16 },
- /* 1614 */ { MAD_F(0x049f45ba) /* 0.288884857 */, 16 },
- /* 1615 */ { MAD_F(0x04a03ffe) /* 0.289123530 */, 16 },
-
- /* 1616 */ { MAD_F(0x04a13a50) /* 0.289362253 */, 16 },
- /* 1617 */ { MAD_F(0x04a234af) /* 0.289601026 */, 16 },
- /* 1618 */ { MAD_F(0x04a32f1b) /* 0.289839847 */, 16 },
- /* 1619 */ { MAD_F(0x04a42995) /* 0.290078718 */, 16 },
- /* 1620 */ { MAD_F(0x04a5241b) /* 0.290317638 */, 16 },
- /* 1621 */ { MAD_F(0x04a61eaf) /* 0.290556607 */, 16 },
- /* 1622 */ { MAD_F(0x04a71950) /* 0.290795626 */, 16 },
- /* 1623 */ { MAD_F(0x04a813fe) /* 0.291034693 */, 16 },
- /* 1624 */ { MAD_F(0x04a90eba) /* 0.291273810 */, 16 },
- /* 1625 */ { MAD_F(0x04aa0982) /* 0.291512975 */, 16 },
- /* 1626 */ { MAD_F(0x04ab0458) /* 0.291752190 */, 16 },
- /* 1627 */ { MAD_F(0x04abff3b) /* 0.291991453 */, 16 },
- /* 1628 */ { MAD_F(0x04acfa2b) /* 0.292230766 */, 16 },
- /* 1629 */ { MAD_F(0x04adf528) /* 0.292470128 */, 16 },
- /* 1630 */ { MAD_F(0x04aef032) /* 0.292709539 */, 16 },
- /* 1631 */ { MAD_F(0x04afeb4a) /* 0.292948998 */, 16 },
-
- /* 1632 */ { MAD_F(0x04b0e66e) /* 0.293188507 */, 16 },
- /* 1633 */ { MAD_F(0x04b1e1a0) /* 0.293428065 */, 16 },
- /* 1634 */ { MAD_F(0x04b2dcdf) /* 0.293667671 */, 16 },
- /* 1635 */ { MAD_F(0x04b3d82b) /* 0.293907326 */, 16 },
- /* 1636 */ { MAD_F(0x04b4d384) /* 0.294147031 */, 16 },
- /* 1637 */ { MAD_F(0x04b5ceea) /* 0.294386784 */, 16 },
- /* 1638 */ { MAD_F(0x04b6ca5e) /* 0.294626585 */, 16 },
- /* 1639 */ { MAD_F(0x04b7c5de) /* 0.294866436 */, 16 },
- /* 1640 */ { MAD_F(0x04b8c16c) /* 0.295106336 */, 16 },
- /* 1641 */ { MAD_F(0x04b9bd06) /* 0.295346284 */, 16 },
- /* 1642 */ { MAD_F(0x04bab8ae) /* 0.295586281 */, 16 },
- /* 1643 */ { MAD_F(0x04bbb463) /* 0.295826327 */, 16 },
- /* 1644 */ { MAD_F(0x04bcb024) /* 0.296066421 */, 16 },
- /* 1645 */ { MAD_F(0x04bdabf3) /* 0.296306564 */, 16 },
- /* 1646 */ { MAD_F(0x04bea7cf) /* 0.296546756 */, 16 },
- /* 1647 */ { MAD_F(0x04bfa3b8) /* 0.296786996 */, 16 },
-
- /* 1648 */ { MAD_F(0x04c09faf) /* 0.297027285 */, 16 },
- /* 1649 */ { MAD_F(0x04c19bb2) /* 0.297267623 */, 16 },
- /* 1650 */ { MAD_F(0x04c297c2) /* 0.297508009 */, 16 },
- /* 1651 */ { MAD_F(0x04c393df) /* 0.297748444 */, 16 },
- /* 1652 */ { MAD_F(0x04c49009) /* 0.297988927 */, 16 },
- /* 1653 */ { MAD_F(0x04c58c41) /* 0.298229459 */, 16 },
- /* 1654 */ { MAD_F(0x04c68885) /* 0.298470039 */, 16 },
- /* 1655 */ { MAD_F(0x04c784d6) /* 0.298710668 */, 16 },
- /* 1656 */ { MAD_F(0x04c88135) /* 0.298951346 */, 16 },
- /* 1657 */ { MAD_F(0x04c97da0) /* 0.299192071 */, 16 },
- /* 1658 */ { MAD_F(0x04ca7a18) /* 0.299432846 */, 16 },
- /* 1659 */ { MAD_F(0x04cb769e) /* 0.299673668 */, 16 },
- /* 1660 */ { MAD_F(0x04cc7330) /* 0.299914539 */, 16 },
- /* 1661 */ { MAD_F(0x04cd6fcf) /* 0.300155459 */, 16 },
- /* 1662 */ { MAD_F(0x04ce6c7b) /* 0.300396426 */, 16 },
- /* 1663 */ { MAD_F(0x04cf6935) /* 0.300637443 */, 16 },
-
- /* 1664 */ { MAD_F(0x04d065fb) /* 0.300878507 */, 16 },
- /* 1665 */ { MAD_F(0x04d162ce) /* 0.301119620 */, 16 },
- /* 1666 */ { MAD_F(0x04d25fae) /* 0.301360781 */, 16 },
- /* 1667 */ { MAD_F(0x04d35c9b) /* 0.301601990 */, 16 },
- /* 1668 */ { MAD_F(0x04d45995) /* 0.301843247 */, 16 },
- /* 1669 */ { MAD_F(0x04d5569c) /* 0.302084553 */, 16 },
- /* 1670 */ { MAD_F(0x04d653b0) /* 0.302325907 */, 16 },
- /* 1671 */ { MAD_F(0x04d750d1) /* 0.302567309 */, 16 },
- /* 1672 */ { MAD_F(0x04d84dff) /* 0.302808759 */, 16 },
- /* 1673 */ { MAD_F(0x04d94b3a) /* 0.303050257 */, 16 },
- /* 1674 */ { MAD_F(0x04da4881) /* 0.303291804 */, 16 },
- /* 1675 */ { MAD_F(0x04db45d6) /* 0.303533399 */, 16 },
- /* 1676 */ { MAD_F(0x04dc4337) /* 0.303775041 */, 16 },
- /* 1677 */ { MAD_F(0x04dd40a6) /* 0.304016732 */, 16 },
- /* 1678 */ { MAD_F(0x04de3e21) /* 0.304258471 */, 16 },
- /* 1679 */ { MAD_F(0x04df3ba9) /* 0.304500257 */, 16 },
-
- /* 1680 */ { MAD_F(0x04e0393e) /* 0.304742092 */, 16 },
- /* 1681 */ { MAD_F(0x04e136e0) /* 0.304983975 */, 16 },
- /* 1682 */ { MAD_F(0x04e2348f) /* 0.305225906 */, 16 },
- /* 1683 */ { MAD_F(0x04e3324b) /* 0.305467885 */, 16 },
- /* 1684 */ { MAD_F(0x04e43013) /* 0.305709911 */, 16 },
- /* 1685 */ { MAD_F(0x04e52de9) /* 0.305951986 */, 16 },
- /* 1686 */ { MAD_F(0x04e62bcb) /* 0.306194108 */, 16 },
- /* 1687 */ { MAD_F(0x04e729ba) /* 0.306436279 */, 16 },
- /* 1688 */ { MAD_F(0x04e827b6) /* 0.306678497 */, 16 },
- /* 1689 */ { MAD_F(0x04e925bf) /* 0.306920763 */, 16 },
- /* 1690 */ { MAD_F(0x04ea23d4) /* 0.307163077 */, 16 },
- /* 1691 */ { MAD_F(0x04eb21f7) /* 0.307405438 */, 16 },
- /* 1692 */ { MAD_F(0x04ec2026) /* 0.307647848 */, 16 },
- /* 1693 */ { MAD_F(0x04ed1e62) /* 0.307890305 */, 16 },
- /* 1694 */ { MAD_F(0x04ee1cab) /* 0.308132810 */, 16 },
- /* 1695 */ { MAD_F(0x04ef1b01) /* 0.308375362 */, 16 },
-
- /* 1696 */ { MAD_F(0x04f01963) /* 0.308617963 */, 16 },
- /* 1697 */ { MAD_F(0x04f117d3) /* 0.308860611 */, 16 },
- /* 1698 */ { MAD_F(0x04f2164f) /* 0.309103306 */, 16 },
- /* 1699 */ { MAD_F(0x04f314d8) /* 0.309346050 */, 16 },
- /* 1700 */ { MAD_F(0x04f4136d) /* 0.309588841 */, 16 },
- /* 1701 */ { MAD_F(0x04f51210) /* 0.309831679 */, 16 },
- /* 1702 */ { MAD_F(0x04f610bf) /* 0.310074565 */, 16 },
- /* 1703 */ { MAD_F(0x04f70f7b) /* 0.310317499 */, 16 },
- /* 1704 */ { MAD_F(0x04f80e44) /* 0.310560480 */, 16 },
- /* 1705 */ { MAD_F(0x04f90d19) /* 0.310803509 */, 16 },
- /* 1706 */ { MAD_F(0x04fa0bfc) /* 0.311046586 */, 16 },
- /* 1707 */ { MAD_F(0x04fb0aeb) /* 0.311289710 */, 16 },
- /* 1708 */ { MAD_F(0x04fc09e7) /* 0.311532881 */, 16 },
- /* 1709 */ { MAD_F(0x04fd08ef) /* 0.311776100 */, 16 },
- /* 1710 */ { MAD_F(0x04fe0805) /* 0.312019366 */, 16 },
- /* 1711 */ { MAD_F(0x04ff0727) /* 0.312262680 */, 16 },
-
- /* 1712 */ { MAD_F(0x05000655) /* 0.312506041 */, 16 },
- /* 1713 */ { MAD_F(0x05010591) /* 0.312749449 */, 16 },
- /* 1714 */ { MAD_F(0x050204d9) /* 0.312992905 */, 16 },
- /* 1715 */ { MAD_F(0x0503042e) /* 0.313236408 */, 16 },
- /* 1716 */ { MAD_F(0x0504038f) /* 0.313479959 */, 16 },
- /* 1717 */ { MAD_F(0x050502fe) /* 0.313723556 */, 16 },
- /* 1718 */ { MAD_F(0x05060279) /* 0.313967202 */, 16 },
- /* 1719 */ { MAD_F(0x05070200) /* 0.314210894 */, 16 },
- /* 1720 */ { MAD_F(0x05080195) /* 0.314454634 */, 16 },
- /* 1721 */ { MAD_F(0x05090136) /* 0.314698420 */, 16 },
- /* 1722 */ { MAD_F(0x050a00e3) /* 0.314942255 */, 16 },
- /* 1723 */ { MAD_F(0x050b009e) /* 0.315186136 */, 16 },
- /* 1724 */ { MAD_F(0x050c0065) /* 0.315430064 */, 16 },
- /* 1725 */ { MAD_F(0x050d0039) /* 0.315674040 */, 16 },
- /* 1726 */ { MAD_F(0x050e0019) /* 0.315918063 */, 16 },
- /* 1727 */ { MAD_F(0x050f0006) /* 0.316162133 */, 16 },
-
- /* 1728 */ { MAD_F(0x05100000) /* 0.316406250 */, 16 },
- /* 1729 */ { MAD_F(0x05110006) /* 0.316650414 */, 16 },
- /* 1730 */ { MAD_F(0x05120019) /* 0.316894625 */, 16 },
- /* 1731 */ { MAD_F(0x05130039) /* 0.317138884 */, 16 },
- /* 1732 */ { MAD_F(0x05140065) /* 0.317383189 */, 16 },
- /* 1733 */ { MAD_F(0x0515009e) /* 0.317627541 */, 16 },
- /* 1734 */ { MAD_F(0x051600e3) /* 0.317871941 */, 16 },
- /* 1735 */ { MAD_F(0x05170135) /* 0.318116387 */, 16 },
- /* 1736 */ { MAD_F(0x05180194) /* 0.318360880 */, 16 },
- /* 1737 */ { MAD_F(0x051901ff) /* 0.318605421 */, 16 },
- /* 1738 */ { MAD_F(0x051a0277) /* 0.318850008 */, 16 },
- /* 1739 */ { MAD_F(0x051b02fc) /* 0.319094642 */, 16 },
- /* 1740 */ { MAD_F(0x051c038d) /* 0.319339323 */, 16 },
- /* 1741 */ { MAD_F(0x051d042a) /* 0.319584051 */, 16 },
- /* 1742 */ { MAD_F(0x051e04d4) /* 0.319828826 */, 16 },
- /* 1743 */ { MAD_F(0x051f058b) /* 0.320073647 */, 16 },
-
- /* 1744 */ { MAD_F(0x0520064f) /* 0.320318516 */, 16 },
- /* 1745 */ { MAD_F(0x0521071f) /* 0.320563431 */, 16 },
- /* 1746 */ { MAD_F(0x052207fb) /* 0.320808393 */, 16 },
- /* 1747 */ { MAD_F(0x052308e4) /* 0.321053402 */, 16 },
- /* 1748 */ { MAD_F(0x052409da) /* 0.321298457 */, 16 },
- /* 1749 */ { MAD_F(0x05250adc) /* 0.321543560 */, 16 },
- /* 1750 */ { MAD_F(0x05260bea) /* 0.321788709 */, 16 },
- /* 1751 */ { MAD_F(0x05270d06) /* 0.322033904 */, 16 },
- /* 1752 */ { MAD_F(0x05280e2d) /* 0.322279147 */, 16 },
- /* 1753 */ { MAD_F(0x05290f62) /* 0.322524436 */, 16 },
- /* 1754 */ { MAD_F(0x052a10a3) /* 0.322769771 */, 16 },
- /* 1755 */ { MAD_F(0x052b11f0) /* 0.323015154 */, 16 },
- /* 1756 */ { MAD_F(0x052c134a) /* 0.323260583 */, 16 },
- /* 1757 */ { MAD_F(0x052d14b0) /* 0.323506058 */, 16 },
- /* 1758 */ { MAD_F(0x052e1623) /* 0.323751580 */, 16 },
- /* 1759 */ { MAD_F(0x052f17a2) /* 0.323997149 */, 16 },
-
- /* 1760 */ { MAD_F(0x0530192e) /* 0.324242764 */, 16 },
- /* 1761 */ { MAD_F(0x05311ac6) /* 0.324488426 */, 16 },
- /* 1762 */ { MAD_F(0x05321c6b) /* 0.324734134 */, 16 },
- /* 1763 */ { MAD_F(0x05331e1c) /* 0.324979889 */, 16 },
- /* 1764 */ { MAD_F(0x05341fda) /* 0.325225690 */, 16 },
- /* 1765 */ { MAD_F(0x053521a4) /* 0.325471538 */, 16 },
- /* 1766 */ { MAD_F(0x0536237b) /* 0.325717432 */, 16 },
- /* 1767 */ { MAD_F(0x0537255e) /* 0.325963372 */, 16 },
- /* 1768 */ { MAD_F(0x0538274e) /* 0.326209359 */, 16 },
- /* 1769 */ { MAD_F(0x0539294a) /* 0.326455392 */, 16 },
- /* 1770 */ { MAD_F(0x053a2b52) /* 0.326701472 */, 16 },
- /* 1771 */ { MAD_F(0x053b2d67) /* 0.326947598 */, 16 },
- /* 1772 */ { MAD_F(0x053c2f89) /* 0.327193770 */, 16 },
- /* 1773 */ { MAD_F(0x053d31b6) /* 0.327439989 */, 16 },
- /* 1774 */ { MAD_F(0x053e33f1) /* 0.327686254 */, 16 },
- /* 1775 */ { MAD_F(0x053f3637) /* 0.327932565 */, 16 },
-
- /* 1776 */ { MAD_F(0x0540388a) /* 0.328178922 */, 16 },
- /* 1777 */ { MAD_F(0x05413aea) /* 0.328425326 */, 16 },
- /* 1778 */ { MAD_F(0x05423d56) /* 0.328671776 */, 16 },
- /* 1779 */ { MAD_F(0x05433fce) /* 0.328918272 */, 16 },
- /* 1780 */ { MAD_F(0x05444253) /* 0.329164814 */, 16 },
- /* 1781 */ { MAD_F(0x054544e4) /* 0.329411403 */, 16 },
- /* 1782 */ { MAD_F(0x05464781) /* 0.329658038 */, 16 },
- /* 1783 */ { MAD_F(0x05474a2b) /* 0.329904718 */, 16 },
- /* 1784 */ { MAD_F(0x05484ce2) /* 0.330151445 */, 16 },
- /* 1785 */ { MAD_F(0x05494fa4) /* 0.330398218 */, 16 },
- /* 1786 */ { MAD_F(0x054a5273) /* 0.330645037 */, 16 },
- /* 1787 */ { MAD_F(0x054b554e) /* 0.330891903 */, 16 },
- /* 1788 */ { MAD_F(0x054c5836) /* 0.331138814 */, 16 },
- /* 1789 */ { MAD_F(0x054d5b2a) /* 0.331385771 */, 16 },
- /* 1790 */ { MAD_F(0x054e5e2b) /* 0.331632774 */, 16 },
- /* 1791 */ { MAD_F(0x054f6138) /* 0.331879824 */, 16 },
-
- /* 1792 */ { MAD_F(0x05506451) /* 0.332126919 */, 16 },
- /* 1793 */ { MAD_F(0x05516776) /* 0.332374060 */, 16 },
- /* 1794 */ { MAD_F(0x05526aa8) /* 0.332621247 */, 16 },
- /* 1795 */ { MAD_F(0x05536de6) /* 0.332868480 */, 16 },
- /* 1796 */ { MAD_F(0x05547131) /* 0.333115759 */, 16 },
- /* 1797 */ { MAD_F(0x05557487) /* 0.333363084 */, 16 },
- /* 1798 */ { MAD_F(0x055677ea) /* 0.333610455 */, 16 },
- /* 1799 */ { MAD_F(0x05577b5a) /* 0.333857872 */, 16 },
- /* 1800 */ { MAD_F(0x05587ed5) /* 0.334105334 */, 16 },
- /* 1801 */ { MAD_F(0x0559825e) /* 0.334352843 */, 16 },
- /* 1802 */ { MAD_F(0x055a85f2) /* 0.334600397 */, 16 },
- /* 1803 */ { MAD_F(0x055b8992) /* 0.334847997 */, 16 },
- /* 1804 */ { MAD_F(0x055c8d3f) /* 0.335095642 */, 16 },
- /* 1805 */ { MAD_F(0x055d90f9) /* 0.335343334 */, 16 },
- /* 1806 */ { MAD_F(0x055e94be) /* 0.335591071 */, 16 },
- /* 1807 */ { MAD_F(0x055f9890) /* 0.335838854 */, 16 },
-
- /* 1808 */ { MAD_F(0x05609c6e) /* 0.336086683 */, 16 },
- /* 1809 */ { MAD_F(0x0561a058) /* 0.336334557 */, 16 },
- /* 1810 */ { MAD_F(0x0562a44f) /* 0.336582477 */, 16 },
- /* 1811 */ { MAD_F(0x0563a851) /* 0.336830443 */, 16 },
- /* 1812 */ { MAD_F(0x0564ac60) /* 0.337078454 */, 16 },
- /* 1813 */ { MAD_F(0x0565b07c) /* 0.337326511 */, 16 },
- /* 1814 */ { MAD_F(0x0566b4a3) /* 0.337574614 */, 16 },
- /* 1815 */ { MAD_F(0x0567b8d7) /* 0.337822762 */, 16 },
- /* 1816 */ { MAD_F(0x0568bd17) /* 0.338070956 */, 16 },
- /* 1817 */ { MAD_F(0x0569c163) /* 0.338319195 */, 16 },
- /* 1818 */ { MAD_F(0x056ac5bc) /* 0.338567480 */, 16 },
- /* 1819 */ { MAD_F(0x056bca20) /* 0.338815811 */, 16 },
- /* 1820 */ { MAD_F(0x056cce91) /* 0.339064186 */, 16 },
- /* 1821 */ { MAD_F(0x056dd30e) /* 0.339312608 */, 16 },
- /* 1822 */ { MAD_F(0x056ed798) /* 0.339561075 */, 16 },
- /* 1823 */ { MAD_F(0x056fdc2d) /* 0.339809587 */, 16 },
-
- /* 1824 */ { MAD_F(0x0570e0cf) /* 0.340058145 */, 16 },
- /* 1825 */ { MAD_F(0x0571e57d) /* 0.340306748 */, 16 },
- /* 1826 */ { MAD_F(0x0572ea37) /* 0.340555397 */, 16 },
- /* 1827 */ { MAD_F(0x0573eefd) /* 0.340804091 */, 16 },
- /* 1828 */ { MAD_F(0x0574f3d0) /* 0.341052830 */, 16 },
- /* 1829 */ { MAD_F(0x0575f8ae) /* 0.341301615 */, 16 },
- /* 1830 */ { MAD_F(0x0576fd99) /* 0.341550445 */, 16 },
- /* 1831 */ { MAD_F(0x05780290) /* 0.341799321 */, 16 },
- /* 1832 */ { MAD_F(0x05790793) /* 0.342048241 */, 16 },
- /* 1833 */ { MAD_F(0x057a0ca3) /* 0.342297207 */, 16 },
- /* 1834 */ { MAD_F(0x057b11be) /* 0.342546219 */, 16 },
- /* 1835 */ { MAD_F(0x057c16e6) /* 0.342795275 */, 16 },
- /* 1836 */ { MAD_F(0x057d1c1a) /* 0.343044377 */, 16 },
- /* 1837 */ { MAD_F(0x057e2159) /* 0.343293524 */, 16 },
- /* 1838 */ { MAD_F(0x057f26a6) /* 0.343542717 */, 16 },
- /* 1839 */ { MAD_F(0x05802bfe) /* 0.343791954 */, 16 },
-
- /* 1840 */ { MAD_F(0x05813162) /* 0.344041237 */, 16 },
- /* 1841 */ { MAD_F(0x058236d2) /* 0.344290564 */, 16 },
- /* 1842 */ { MAD_F(0x05833c4f) /* 0.344539937 */, 16 },
- /* 1843 */ { MAD_F(0x058441d8) /* 0.344789356 */, 16 },
- /* 1844 */ { MAD_F(0x0585476c) /* 0.345038819 */, 16 },
- /* 1845 */ { MAD_F(0x05864d0d) /* 0.345288327 */, 16 },
- /* 1846 */ { MAD_F(0x058752ba) /* 0.345537880 */, 16 },
- /* 1847 */ { MAD_F(0x05885873) /* 0.345787479 */, 16 },
- /* 1848 */ { MAD_F(0x05895e39) /* 0.346037122 */, 16 },
- /* 1849 */ { MAD_F(0x058a640a) /* 0.346286811 */, 16 },
- /* 1850 */ { MAD_F(0x058b69e7) /* 0.346536545 */, 16 },
- /* 1851 */ { MAD_F(0x058c6fd1) /* 0.346786323 */, 16 },
- /* 1852 */ { MAD_F(0x058d75c6) /* 0.347036147 */, 16 },
- /* 1853 */ { MAD_F(0x058e7bc8) /* 0.347286015 */, 16 },
- /* 1854 */ { MAD_F(0x058f81d5) /* 0.347535929 */, 16 },
- /* 1855 */ { MAD_F(0x059087ef) /* 0.347785887 */, 16 },
-
- /* 1856 */ { MAD_F(0x05918e15) /* 0.348035890 */, 16 },
- /* 1857 */ { MAD_F(0x05929447) /* 0.348285939 */, 16 },
- /* 1858 */ { MAD_F(0x05939a84) /* 0.348536032 */, 16 },
- /* 1859 */ { MAD_F(0x0594a0ce) /* 0.348786170 */, 16 },
- /* 1860 */ { MAD_F(0x0595a724) /* 0.349036353 */, 16 },
- /* 1861 */ { MAD_F(0x0596ad86) /* 0.349286580 */, 16 },
- /* 1862 */ { MAD_F(0x0597b3f4) /* 0.349536853 */, 16 },
- /* 1863 */ { MAD_F(0x0598ba6e) /* 0.349787170 */, 16 },
- /* 1864 */ { MAD_F(0x0599c0f4) /* 0.350037532 */, 16 },
- /* 1865 */ { MAD_F(0x059ac786) /* 0.350287939 */, 16 },
- /* 1866 */ { MAD_F(0x059bce25) /* 0.350538391 */, 16 },
- /* 1867 */ { MAD_F(0x059cd4cf) /* 0.350788887 */, 16 },
- /* 1868 */ { MAD_F(0x059ddb85) /* 0.351039428 */, 16 },
- /* 1869 */ { MAD_F(0x059ee247) /* 0.351290014 */, 16 },
- /* 1870 */ { MAD_F(0x059fe915) /* 0.351540645 */, 16 },
- /* 1871 */ { MAD_F(0x05a0efef) /* 0.351791320 */, 16 },
-
- /* 1872 */ { MAD_F(0x05a1f6d5) /* 0.352042040 */, 16 },
- /* 1873 */ { MAD_F(0x05a2fdc7) /* 0.352292804 */, 16 },
- /* 1874 */ { MAD_F(0x05a404c5) /* 0.352543613 */, 16 },
- /* 1875 */ { MAD_F(0x05a50bcf) /* 0.352794467 */, 16 },
- /* 1876 */ { MAD_F(0x05a612e5) /* 0.353045365 */, 16 },
- /* 1877 */ { MAD_F(0x05a71a07) /* 0.353296308 */, 16 },
- /* 1878 */ { MAD_F(0x05a82135) /* 0.353547296 */, 16 },
- /* 1879 */ { MAD_F(0x05a9286f) /* 0.353798328 */, 16 },
- /* 1880 */ { MAD_F(0x05aa2fb5) /* 0.354049405 */, 16 },
- /* 1881 */ { MAD_F(0x05ab3707) /* 0.354300526 */, 16 },
- /* 1882 */ { MAD_F(0x05ac3e65) /* 0.354551691 */, 16 },
- /* 1883 */ { MAD_F(0x05ad45ce) /* 0.354802901 */, 16 },
- /* 1884 */ { MAD_F(0x05ae4d44) /* 0.355054156 */, 16 },
- /* 1885 */ { MAD_F(0x05af54c6) /* 0.355305455 */, 16 },
- /* 1886 */ { MAD_F(0x05b05c53) /* 0.355556799 */, 16 },
- /* 1887 */ { MAD_F(0x05b163ed) /* 0.355808187 */, 16 },
-
- /* 1888 */ { MAD_F(0x05b26b92) /* 0.356059619 */, 16 },
- /* 1889 */ { MAD_F(0x05b37343) /* 0.356311096 */, 16 },
- /* 1890 */ { MAD_F(0x05b47b00) /* 0.356562617 */, 16 },
- /* 1891 */ { MAD_F(0x05b582c9) /* 0.356814182 */, 16 },
- /* 1892 */ { MAD_F(0x05b68a9e) /* 0.357065792 */, 16 },
- /* 1893 */ { MAD_F(0x05b7927f) /* 0.357317446 */, 16 },
- /* 1894 */ { MAD_F(0x05b89a6c) /* 0.357569145 */, 16 },
- /* 1895 */ { MAD_F(0x05b9a265) /* 0.357820887 */, 16 },
- /* 1896 */ { MAD_F(0x05baaa69) /* 0.358072674 */, 16 },
- /* 1897 */ { MAD_F(0x05bbb27a) /* 0.358324506 */, 16 },
- /* 1898 */ { MAD_F(0x05bcba96) /* 0.358576381 */, 16 },
- /* 1899 */ { MAD_F(0x05bdc2be) /* 0.358828301 */, 16 },
- /* 1900 */ { MAD_F(0x05becaf2) /* 0.359080265 */, 16 },
- /* 1901 */ { MAD_F(0x05bfd332) /* 0.359332273 */, 16 },
- /* 1902 */ { MAD_F(0x05c0db7e) /* 0.359584326 */, 16 },
- /* 1903 */ { MAD_F(0x05c1e3d6) /* 0.359836423 */, 16 },
-
- /* 1904 */ { MAD_F(0x05c2ec39) /* 0.360088563 */, 16 },
- /* 1905 */ { MAD_F(0x05c3f4a9) /* 0.360340748 */, 16 },
- /* 1906 */ { MAD_F(0x05c4fd24) /* 0.360592977 */, 16 },
- /* 1907 */ { MAD_F(0x05c605ab) /* 0.360845251 */, 16 },
- /* 1908 */ { MAD_F(0x05c70e3e) /* 0.361097568 */, 16 },
- /* 1909 */ { MAD_F(0x05c816dd) /* 0.361349929 */, 16 },
- /* 1910 */ { MAD_F(0x05c91f87) /* 0.361602335 */, 16 },
- /* 1911 */ { MAD_F(0x05ca283e) /* 0.361854784 */, 16 },
- /* 1912 */ { MAD_F(0x05cb3100) /* 0.362107278 */, 16 },
- /* 1913 */ { MAD_F(0x05cc39ce) /* 0.362359815 */, 16 },
- /* 1914 */ { MAD_F(0x05cd42a8) /* 0.362612397 */, 16 },
- /* 1915 */ { MAD_F(0x05ce4b8d) /* 0.362865022 */, 16 },
- /* 1916 */ { MAD_F(0x05cf547f) /* 0.363117692 */, 16 },
- /* 1917 */ { MAD_F(0x05d05d7c) /* 0.363370405 */, 16 },
- /* 1918 */ { MAD_F(0x05d16685) /* 0.363623163 */, 16 },
- /* 1919 */ { MAD_F(0x05d26f9a) /* 0.363875964 */, 16 },
-
- /* 1920 */ { MAD_F(0x05d378bb) /* 0.364128809 */, 16 },
- /* 1921 */ { MAD_F(0x05d481e7) /* 0.364381698 */, 16 },
- /* 1922 */ { MAD_F(0x05d58b1f) /* 0.364634632 */, 16 },
- /* 1923 */ { MAD_F(0x05d69463) /* 0.364887608 */, 16 },
- /* 1924 */ { MAD_F(0x05d79db3) /* 0.365140629 */, 16 },
- /* 1925 */ { MAD_F(0x05d8a70f) /* 0.365393694 */, 16 },
- /* 1926 */ { MAD_F(0x05d9b076) /* 0.365646802 */, 16 },
- /* 1927 */ { MAD_F(0x05dab9e9) /* 0.365899955 */, 16 },
- /* 1928 */ { MAD_F(0x05dbc368) /* 0.366153151 */, 16 },
- /* 1929 */ { MAD_F(0x05dcccf2) /* 0.366406390 */, 16 },
- /* 1930 */ { MAD_F(0x05ddd689) /* 0.366659674 */, 16 },
- /* 1931 */ { MAD_F(0x05dee02b) /* 0.366913001 */, 16 },
- /* 1932 */ { MAD_F(0x05dfe9d8) /* 0.367166372 */, 16 },
- /* 1933 */ { MAD_F(0x05e0f392) /* 0.367419787 */, 16 },
- /* 1934 */ { MAD_F(0x05e1fd57) /* 0.367673246 */, 16 },
- /* 1935 */ { MAD_F(0x05e30728) /* 0.367926748 */, 16 },
-
- /* 1936 */ { MAD_F(0x05e41105) /* 0.368180294 */, 16 },
- /* 1937 */ { MAD_F(0x05e51aed) /* 0.368433883 */, 16 },
- /* 1938 */ { MAD_F(0x05e624e1) /* 0.368687517 */, 16 },
- /* 1939 */ { MAD_F(0x05e72ee1) /* 0.368941193 */, 16 },
- /* 1940 */ { MAD_F(0x05e838ed) /* 0.369194914 */, 16 },
- /* 1941 */ { MAD_F(0x05e94304) /* 0.369448678 */, 16 },
- /* 1942 */ { MAD_F(0x05ea4d27) /* 0.369702485 */, 16 },
- /* 1943 */ { MAD_F(0x05eb5756) /* 0.369956336 */, 16 },
- /* 1944 */ { MAD_F(0x05ec6190) /* 0.370210231 */, 16 },
- /* 1945 */ { MAD_F(0x05ed6bd6) /* 0.370464169 */, 16 },
- /* 1946 */ { MAD_F(0x05ee7628) /* 0.370718151 */, 16 },
- /* 1947 */ { MAD_F(0x05ef8085) /* 0.370972177 */, 16 },
- /* 1948 */ { MAD_F(0x05f08aee) /* 0.371226245 */, 16 },
- /* 1949 */ { MAD_F(0x05f19563) /* 0.371480358 */, 16 },
- /* 1950 */ { MAD_F(0x05f29fe3) /* 0.371734513 */, 16 },
- /* 1951 */ { MAD_F(0x05f3aa6f) /* 0.371988712 */, 16 },
-
- /* 1952 */ { MAD_F(0x05f4b507) /* 0.372242955 */, 16 },
- /* 1953 */ { MAD_F(0x05f5bfab) /* 0.372497241 */, 16 },
- /* 1954 */ { MAD_F(0x05f6ca5a) /* 0.372751570 */, 16 },
- /* 1955 */ { MAD_F(0x05f7d514) /* 0.373005943 */, 16 },
- /* 1956 */ { MAD_F(0x05f8dfdb) /* 0.373260359 */, 16 },
- /* 1957 */ { MAD_F(0x05f9eaad) /* 0.373514819 */, 16 },
- /* 1958 */ { MAD_F(0x05faf58a) /* 0.373769322 */, 16 },
- /* 1959 */ { MAD_F(0x05fc0073) /* 0.374023868 */, 16 },
- /* 1960 */ { MAD_F(0x05fd0b68) /* 0.374278458 */, 16 },
- /* 1961 */ { MAD_F(0x05fe1669) /* 0.374533091 */, 16 },
- /* 1962 */ { MAD_F(0x05ff2175) /* 0.374787767 */, 16 },
- /* 1963 */ { MAD_F(0x06002c8d) /* 0.375042486 */, 16 },
- /* 1964 */ { MAD_F(0x060137b0) /* 0.375297249 */, 16 },
- /* 1965 */ { MAD_F(0x060242df) /* 0.375552055 */, 16 },
- /* 1966 */ { MAD_F(0x06034e19) /* 0.375806904 */, 16 },
- /* 1967 */ { MAD_F(0x0604595f) /* 0.376061796 */, 16 },
-
- /* 1968 */ { MAD_F(0x060564b1) /* 0.376316732 */, 16 },
- /* 1969 */ { MAD_F(0x0606700f) /* 0.376571710 */, 16 },
- /* 1970 */ { MAD_F(0x06077b77) /* 0.376826732 */, 16 },
- /* 1971 */ { MAD_F(0x060886ec) /* 0.377081797 */, 16 },
- /* 1972 */ { MAD_F(0x0609926c) /* 0.377336905 */, 16 },
- /* 1973 */ { MAD_F(0x060a9df8) /* 0.377592057 */, 16 },
- /* 1974 */ { MAD_F(0x060ba98f) /* 0.377847251 */, 16 },
- /* 1975 */ { MAD_F(0x060cb532) /* 0.378102489 */, 16 },
- /* 1976 */ { MAD_F(0x060dc0e0) /* 0.378357769 */, 16 },
- /* 1977 */ { MAD_F(0x060ecc9a) /* 0.378613093 */, 16 },
- /* 1978 */ { MAD_F(0x060fd860) /* 0.378868460 */, 16 },
- /* 1979 */ { MAD_F(0x0610e431) /* 0.379123870 */, 16 },
- /* 1980 */ { MAD_F(0x0611f00d) /* 0.379379322 */, 16 },
- /* 1981 */ { MAD_F(0x0612fbf5) /* 0.379634818 */, 16 },
- /* 1982 */ { MAD_F(0x061407e9) /* 0.379890357 */, 16 },
- /* 1983 */ { MAD_F(0x061513e8) /* 0.380145939 */, 16 },
-
- /* 1984 */ { MAD_F(0x06161ff3) /* 0.380401563 */, 16 },
- /* 1985 */ { MAD_F(0x06172c09) /* 0.380657231 */, 16 },
- /* 1986 */ { MAD_F(0x0618382b) /* 0.380912942 */, 16 },
- /* 1987 */ { MAD_F(0x06194458) /* 0.381168695 */, 16 },
- /* 1988 */ { MAD_F(0x061a5091) /* 0.381424492 */, 16 },
- /* 1989 */ { MAD_F(0x061b5cd5) /* 0.381680331 */, 16 },
- /* 1990 */ { MAD_F(0x061c6925) /* 0.381936213 */, 16 },
- /* 1991 */ { MAD_F(0x061d7581) /* 0.382192138 */, 16 },
- /* 1992 */ { MAD_F(0x061e81e8) /* 0.382448106 */, 16 },
- /* 1993 */ { MAD_F(0x061f8e5a) /* 0.382704117 */, 16 },
- /* 1994 */ { MAD_F(0x06209ad8) /* 0.382960171 */, 16 },
- /* 1995 */ { MAD_F(0x0621a761) /* 0.383216267 */, 16 },
- /* 1996 */ { MAD_F(0x0622b3f6) /* 0.383472406 */, 16 },
- /* 1997 */ { MAD_F(0x0623c096) /* 0.383728588 */, 16 },
- /* 1998 */ { MAD_F(0x0624cd42) /* 0.383984813 */, 16 },
- /* 1999 */ { MAD_F(0x0625d9f9) /* 0.384241080 */, 16 },
-
- /* 2000 */ { MAD_F(0x0626e6bc) /* 0.384497391 */, 16 },
- /* 2001 */ { MAD_F(0x0627f38a) /* 0.384753744 */, 16 },
- /* 2002 */ { MAD_F(0x06290064) /* 0.385010139 */, 16 },
- /* 2003 */ { MAD_F(0x062a0d49) /* 0.385266578 */, 16 },
- /* 2004 */ { MAD_F(0x062b1a3a) /* 0.385523059 */, 16 },
- /* 2005 */ { MAD_F(0x062c2736) /* 0.385779582 */, 16 },
- /* 2006 */ { MAD_F(0x062d343d) /* 0.386036149 */, 16 },
- /* 2007 */ { MAD_F(0x062e4150) /* 0.386292758 */, 16 },
- /* 2008 */ { MAD_F(0x062f4e6f) /* 0.386549409 */, 16 },
- /* 2009 */ { MAD_F(0x06305b99) /* 0.386806104 */, 16 },
- /* 2010 */ { MAD_F(0x063168ce) /* 0.387062840 */, 16 },
- /* 2011 */ { MAD_F(0x0632760f) /* 0.387319620 */, 16 },
- /* 2012 */ { MAD_F(0x0633835b) /* 0.387576442 */, 16 },
- /* 2013 */ { MAD_F(0x063490b2) /* 0.387833306 */, 16 },
- /* 2014 */ { MAD_F(0x06359e15) /* 0.388090213 */, 16 },
- /* 2015 */ { MAD_F(0x0636ab83) /* 0.388347163 */, 16 },
-
- /* 2016 */ { MAD_F(0x0637b8fd) /* 0.388604155 */, 16 },
- /* 2017 */ { MAD_F(0x0638c682) /* 0.388861190 */, 16 },
- /* 2018 */ { MAD_F(0x0639d413) /* 0.389118267 */, 16 },
- /* 2019 */ { MAD_F(0x063ae1af) /* 0.389375386 */, 16 },
- /* 2020 */ { MAD_F(0x063bef56) /* 0.389632548 */, 16 },
- /* 2021 */ { MAD_F(0x063cfd09) /* 0.389889752 */, 16 },
- /* 2022 */ { MAD_F(0x063e0ac7) /* 0.390146999 */, 16 },
- /* 2023 */ { MAD_F(0x063f1891) /* 0.390404289 */, 16 },
- /* 2024 */ { MAD_F(0x06402666) /* 0.390661620 */, 16 },
- /* 2025 */ { MAD_F(0x06413446) /* 0.390918994 */, 16 },
- /* 2026 */ { MAD_F(0x06424232) /* 0.391176411 */, 16 },
- /* 2027 */ { MAD_F(0x06435029) /* 0.391433869 */, 16 },
- /* 2028 */ { MAD_F(0x06445e2b) /* 0.391691371 */, 16 },
- /* 2029 */ { MAD_F(0x06456c39) /* 0.391948914 */, 16 },
- /* 2030 */ { MAD_F(0x06467a52) /* 0.392206500 */, 16 },
- /* 2031 */ { MAD_F(0x06478877) /* 0.392464128 */, 16 },
-
- /* 2032 */ { MAD_F(0x064896a7) /* 0.392721798 */, 16 },
- /* 2033 */ { MAD_F(0x0649a4e2) /* 0.392979511 */, 16 },
- /* 2034 */ { MAD_F(0x064ab328) /* 0.393237266 */, 16 },
- /* 2035 */ { MAD_F(0x064bc17a) /* 0.393495063 */, 16 },
- /* 2036 */ { MAD_F(0x064ccfd8) /* 0.393752902 */, 16 },
- /* 2037 */ { MAD_F(0x064dde40) /* 0.394010784 */, 16 },
- /* 2038 */ { MAD_F(0x064eecb4) /* 0.394268707 */, 16 },
- /* 2039 */ { MAD_F(0x064ffb33) /* 0.394526673 */, 16 },
- /* 2040 */ { MAD_F(0x065109be) /* 0.394784681 */, 16 },
- /* 2041 */ { MAD_F(0x06521854) /* 0.395042732 */, 16 },
- /* 2042 */ { MAD_F(0x065326f5) /* 0.395300824 */, 16 },
- /* 2043 */ { MAD_F(0x065435a1) /* 0.395558959 */, 16 },
- /* 2044 */ { MAD_F(0x06554459) /* 0.395817135 */, 16 },
- /* 2045 */ { MAD_F(0x0656531c) /* 0.396075354 */, 16 },
- /* 2046 */ { MAD_F(0x065761ea) /* 0.396333615 */, 16 },
- /* 2047 */ { MAD_F(0x065870c4) /* 0.396591918 */, 16 },
-
- /* 2048 */ { MAD_F(0x06597fa9) /* 0.396850263 */, 16 },
- /* 2049 */ { MAD_F(0x065a8e99) /* 0.397108650 */, 16 },
- /* 2050 */ { MAD_F(0x065b9d95) /* 0.397367079 */, 16 },
- /* 2051 */ { MAD_F(0x065cac9c) /* 0.397625550 */, 16 },
- /* 2052 */ { MAD_F(0x065dbbae) /* 0.397884063 */, 16 },
- /* 2053 */ { MAD_F(0x065ecacb) /* 0.398142619 */, 16 },
- /* 2054 */ { MAD_F(0x065fd9f4) /* 0.398401216 */, 16 },
- /* 2055 */ { MAD_F(0x0660e928) /* 0.398659855 */, 16 },
- /* 2056 */ { MAD_F(0x0661f867) /* 0.398918536 */, 16 },
- /* 2057 */ { MAD_F(0x066307b1) /* 0.399177259 */, 16 },
- /* 2058 */ { MAD_F(0x06641707) /* 0.399436024 */, 16 },
- /* 2059 */ { MAD_F(0x06652668) /* 0.399694831 */, 16 },
- /* 2060 */ { MAD_F(0x066635d4) /* 0.399953679 */, 16 },
- /* 2061 */ { MAD_F(0x0667454c) /* 0.400212570 */, 16 },
- /* 2062 */ { MAD_F(0x066854ce) /* 0.400471503 */, 16 },
- /* 2063 */ { MAD_F(0x0669645c) /* 0.400730477 */, 16 },
-
- /* 2064 */ { MAD_F(0x066a73f5) /* 0.400989493 */, 16 },
- /* 2065 */ { MAD_F(0x066b839a) /* 0.401248551 */, 16 },
- /* 2066 */ { MAD_F(0x066c9349) /* 0.401507651 */, 16 },
- /* 2067 */ { MAD_F(0x066da304) /* 0.401766793 */, 16 },
- /* 2068 */ { MAD_F(0x066eb2ca) /* 0.402025976 */, 16 },
- /* 2069 */ { MAD_F(0x066fc29b) /* 0.402285202 */, 16 },
- /* 2070 */ { MAD_F(0x0670d278) /* 0.402544469 */, 16 },
- /* 2071 */ { MAD_F(0x0671e25f) /* 0.402803777 */, 16 },
- /* 2072 */ { MAD_F(0x0672f252) /* 0.403063128 */, 16 },
- /* 2073 */ { MAD_F(0x06740250) /* 0.403322520 */, 16 },
- /* 2074 */ { MAD_F(0x0675125a) /* 0.403581954 */, 16 },
- /* 2075 */ { MAD_F(0x0676226e) /* 0.403841430 */, 16 },
- /* 2076 */ { MAD_F(0x0677328e) /* 0.404100947 */, 16 },
- /* 2077 */ { MAD_F(0x067842b9) /* 0.404360506 */, 16 },
- /* 2078 */ { MAD_F(0x067952ef) /* 0.404620107 */, 16 },
- /* 2079 */ { MAD_F(0x067a6330) /* 0.404879749 */, 16 },
-
- /* 2080 */ { MAD_F(0x067b737c) /* 0.405139433 */, 16 },
- /* 2081 */ { MAD_F(0x067c83d4) /* 0.405399159 */, 16 },
- /* 2082 */ { MAD_F(0x067d9436) /* 0.405658926 */, 16 },
- /* 2083 */ { MAD_F(0x067ea4a4) /* 0.405918735 */, 16 },
- /* 2084 */ { MAD_F(0x067fb51d) /* 0.406178585 */, 16 },
- /* 2085 */ { MAD_F(0x0680c5a2) /* 0.406438477 */, 16 },
- /* 2086 */ { MAD_F(0x0681d631) /* 0.406698410 */, 16 },
- /* 2087 */ { MAD_F(0x0682e6cb) /* 0.406958385 */, 16 },
- /* 2088 */ { MAD_F(0x0683f771) /* 0.407218402 */, 16 },
- /* 2089 */ { MAD_F(0x06850822) /* 0.407478460 */, 16 },
- /* 2090 */ { MAD_F(0x068618de) /* 0.407738559 */, 16 },
- /* 2091 */ { MAD_F(0x068729a5) /* 0.407998700 */, 16 },
- /* 2092 */ { MAD_F(0x06883a77) /* 0.408258883 */, 16 },
- /* 2093 */ { MAD_F(0x06894b55) /* 0.408519107 */, 16 },
- /* 2094 */ { MAD_F(0x068a5c3d) /* 0.408779372 */, 16 },
- /* 2095 */ { MAD_F(0x068b6d31) /* 0.409039679 */, 16 },
-
- /* 2096 */ { MAD_F(0x068c7e2f) /* 0.409300027 */, 16 },
- /* 2097 */ { MAD_F(0x068d8f39) /* 0.409560417 */, 16 },
- /* 2098 */ { MAD_F(0x068ea04e) /* 0.409820848 */, 16 },
- /* 2099 */ { MAD_F(0x068fb16e) /* 0.410081321 */, 16 },
- /* 2100 */ { MAD_F(0x0690c299) /* 0.410341834 */, 16 },
- /* 2101 */ { MAD_F(0x0691d3cf) /* 0.410602390 */, 16 },
- /* 2102 */ { MAD_F(0x0692e511) /* 0.410862986 */, 16 },
- /* 2103 */ { MAD_F(0x0693f65d) /* 0.411123624 */, 16 },
- /* 2104 */ { MAD_F(0x069507b5) /* 0.411384303 */, 16 },
- /* 2105 */ { MAD_F(0x06961917) /* 0.411645024 */, 16 },
- /* 2106 */ { MAD_F(0x06972a85) /* 0.411905785 */, 16 },
- /* 2107 */ { MAD_F(0x06983bfe) /* 0.412166588 */, 16 },
- /* 2108 */ { MAD_F(0x06994d82) /* 0.412427433 */, 16 },
- /* 2109 */ { MAD_F(0x069a5f11) /* 0.412688318 */, 16 },
- /* 2110 */ { MAD_F(0x069b70ab) /* 0.412949245 */, 16 },
- /* 2111 */ { MAD_F(0x069c8250) /* 0.413210213 */, 16 },
-
- /* 2112 */ { MAD_F(0x069d9400) /* 0.413471222 */, 16 },
- /* 2113 */ { MAD_F(0x069ea5bb) /* 0.413732273 */, 16 },
- /* 2114 */ { MAD_F(0x069fb781) /* 0.413993364 */, 16 },
- /* 2115 */ { MAD_F(0x06a0c953) /* 0.414254497 */, 16 },
- /* 2116 */ { MAD_F(0x06a1db2f) /* 0.414515671 */, 16 },
- /* 2117 */ { MAD_F(0x06a2ed16) /* 0.414776886 */, 16 },
- /* 2118 */ { MAD_F(0x06a3ff09) /* 0.415038142 */, 16 },
- /* 2119 */ { MAD_F(0x06a51106) /* 0.415299440 */, 16 },
- /* 2120 */ { MAD_F(0x06a6230f) /* 0.415560778 */, 16 },
- /* 2121 */ { MAD_F(0x06a73522) /* 0.415822157 */, 16 },
- /* 2122 */ { MAD_F(0x06a84741) /* 0.416083578 */, 16 },
- /* 2123 */ { MAD_F(0x06a9596a) /* 0.416345040 */, 16 },
- /* 2124 */ { MAD_F(0x06aa6b9f) /* 0.416606542 */, 16 },
- /* 2125 */ { MAD_F(0x06ab7ddf) /* 0.416868086 */, 16 },
- /* 2126 */ { MAD_F(0x06ac9029) /* 0.417129671 */, 16 },
- /* 2127 */ { MAD_F(0x06ada27f) /* 0.417391297 */, 16 },
-
- /* 2128 */ { MAD_F(0x06aeb4e0) /* 0.417652964 */, 16 },
- /* 2129 */ { MAD_F(0x06afc74b) /* 0.417914672 */, 16 },
- /* 2130 */ { MAD_F(0x06b0d9c2) /* 0.418176420 */, 16 },
- /* 2131 */ { MAD_F(0x06b1ec43) /* 0.418438210 */, 16 },
- /* 2132 */ { MAD_F(0x06b2fed0) /* 0.418700041 */, 16 },
- /* 2133 */ { MAD_F(0x06b41168) /* 0.418961912 */, 16 },
- /* 2134 */ { MAD_F(0x06b5240a) /* 0.419223825 */, 16 },
- /* 2135 */ { MAD_F(0x06b636b8) /* 0.419485778 */, 16 },
- /* 2136 */ { MAD_F(0x06b74971) /* 0.419747773 */, 16 },
- /* 2137 */ { MAD_F(0x06b85c34) /* 0.420009808 */, 16 },
- /* 2138 */ { MAD_F(0x06b96f03) /* 0.420271884 */, 16 },
- /* 2139 */ { MAD_F(0x06ba81dc) /* 0.420534001 */, 16 },
- /* 2140 */ { MAD_F(0x06bb94c1) /* 0.420796159 */, 16 },
- /* 2141 */ { MAD_F(0x06bca7b0) /* 0.421058358 */, 16 },
- /* 2142 */ { MAD_F(0x06bdbaaa) /* 0.421320597 */, 16 },
- /* 2143 */ { MAD_F(0x06becdb0) /* 0.421582878 */, 16 },
-
- /* 2144 */ { MAD_F(0x06bfe0c0) /* 0.421845199 */, 16 },
- /* 2145 */ { MAD_F(0x06c0f3db) /* 0.422107561 */, 16 },
- /* 2146 */ { MAD_F(0x06c20702) /* 0.422369964 */, 16 },
- /* 2147 */ { MAD_F(0x06c31a33) /* 0.422632407 */, 16 },
- /* 2148 */ { MAD_F(0x06c42d6f) /* 0.422894891 */, 16 },
- /* 2149 */ { MAD_F(0x06c540b6) /* 0.423157416 */, 16 },
- /* 2150 */ { MAD_F(0x06c65408) /* 0.423419982 */, 16 },
- /* 2151 */ { MAD_F(0x06c76765) /* 0.423682588 */, 16 },
- /* 2152 */ { MAD_F(0x06c87acc) /* 0.423945235 */, 16 },
- /* 2153 */ { MAD_F(0x06c98e3f) /* 0.424207923 */, 16 },
- /* 2154 */ { MAD_F(0x06caa1bd) /* 0.424470652 */, 16 },
- /* 2155 */ { MAD_F(0x06cbb545) /* 0.424733421 */, 16 },
- /* 2156 */ { MAD_F(0x06ccc8d9) /* 0.424996230 */, 16 },
- /* 2157 */ { MAD_F(0x06cddc77) /* 0.425259081 */, 16 },
- /* 2158 */ { MAD_F(0x06cef020) /* 0.425521972 */, 16 },
- /* 2159 */ { MAD_F(0x06d003d4) /* 0.425784903 */, 16 },
-
- /* 2160 */ { MAD_F(0x06d11794) /* 0.426047876 */, 16 },
- /* 2161 */ { MAD_F(0x06d22b5e) /* 0.426310889 */, 16 },
- /* 2162 */ { MAD_F(0x06d33f32) /* 0.426573942 */, 16 },
- /* 2163 */ { MAD_F(0x06d45312) /* 0.426837036 */, 16 },
- /* 2164 */ { MAD_F(0x06d566fd) /* 0.427100170 */, 16 },
- /* 2165 */ { MAD_F(0x06d67af2) /* 0.427363345 */, 16 },
- /* 2166 */ { MAD_F(0x06d78ef3) /* 0.427626561 */, 16 },
- /* 2167 */ { MAD_F(0x06d8a2fe) /* 0.427889817 */, 16 },
- /* 2168 */ { MAD_F(0x06d9b714) /* 0.428153114 */, 16 },
- /* 2169 */ { MAD_F(0x06dacb35) /* 0.428416451 */, 16 },
- /* 2170 */ { MAD_F(0x06dbdf61) /* 0.428679828 */, 16 },
- /* 2171 */ { MAD_F(0x06dcf398) /* 0.428943246 */, 16 },
- /* 2172 */ { MAD_F(0x06de07d9) /* 0.429206704 */, 16 },
- /* 2173 */ { MAD_F(0x06df1c26) /* 0.429470203 */, 16 },
- /* 2174 */ { MAD_F(0x06e0307d) /* 0.429733743 */, 16 },
- /* 2175 */ { MAD_F(0x06e144df) /* 0.429997322 */, 16 },
-
- /* 2176 */ { MAD_F(0x06e2594c) /* 0.430260942 */, 16 },
- /* 2177 */ { MAD_F(0x06e36dc4) /* 0.430524603 */, 16 },
- /* 2178 */ { MAD_F(0x06e48246) /* 0.430788304 */, 16 },
- /* 2179 */ { MAD_F(0x06e596d4) /* 0.431052045 */, 16 },
- /* 2180 */ { MAD_F(0x06e6ab6c) /* 0.431315826 */, 16 },
- /* 2181 */ { MAD_F(0x06e7c00f) /* 0.431579648 */, 16 },
- /* 2182 */ { MAD_F(0x06e8d4bd) /* 0.431843511 */, 16 },
- /* 2183 */ { MAD_F(0x06e9e976) /* 0.432107413 */, 16 },
- /* 2184 */ { MAD_F(0x06eafe3a) /* 0.432371356 */, 16 },
- /* 2185 */ { MAD_F(0x06ec1308) /* 0.432635339 */, 16 },
- /* 2186 */ { MAD_F(0x06ed27e2) /* 0.432899362 */, 16 },
- /* 2187 */ { MAD_F(0x06ee3cc6) /* 0.433163426 */, 16 },
- /* 2188 */ { MAD_F(0x06ef51b4) /* 0.433427530 */, 16 },
- /* 2189 */ { MAD_F(0x06f066ae) /* 0.433691674 */, 16 },
- /* 2190 */ { MAD_F(0x06f17bb3) /* 0.433955859 */, 16 },
- /* 2191 */ { MAD_F(0x06f290c2) /* 0.434220083 */, 16 },
-
- /* 2192 */ { MAD_F(0x06f3a5dc) /* 0.434484348 */, 16 },
- /* 2193 */ { MAD_F(0x06f4bb01) /* 0.434748653 */, 16 },
- /* 2194 */ { MAD_F(0x06f5d030) /* 0.435012998 */, 16 },
- /* 2195 */ { MAD_F(0x06f6e56b) /* 0.435277383 */, 16 },
- /* 2196 */ { MAD_F(0x06f7fab0) /* 0.435541809 */, 16 },
- /* 2197 */ { MAD_F(0x06f91000) /* 0.435806274 */, 16 },
- /* 2198 */ { MAD_F(0x06fa255a) /* 0.436070780 */, 16 },
- /* 2199 */ { MAD_F(0x06fb3ac0) /* 0.436335326 */, 16 },
- /* 2200 */ { MAD_F(0x06fc5030) /* 0.436599912 */, 16 },
- /* 2201 */ { MAD_F(0x06fd65ab) /* 0.436864538 */, 16 },
- /* 2202 */ { MAD_F(0x06fe7b31) /* 0.437129204 */, 16 },
- /* 2203 */ { MAD_F(0x06ff90c2) /* 0.437393910 */, 16 },
- /* 2204 */ { MAD_F(0x0700a65d) /* 0.437658657 */, 16 },
- /* 2205 */ { MAD_F(0x0701bc03) /* 0.437923443 */, 16 },
- /* 2206 */ { MAD_F(0x0702d1b4) /* 0.438188269 */, 16 },
- /* 2207 */ { MAD_F(0x0703e76f) /* 0.438453136 */, 16 },
-
- /* 2208 */ { MAD_F(0x0704fd35) /* 0.438718042 */, 16 },
- /* 2209 */ { MAD_F(0x07061306) /* 0.438982988 */, 16 },
- /* 2210 */ { MAD_F(0x070728e2) /* 0.439247975 */, 16 },
- /* 2211 */ { MAD_F(0x07083ec9) /* 0.439513001 */, 16 },
- /* 2212 */ { MAD_F(0x070954ba) /* 0.439778067 */, 16 },
- /* 2213 */ { MAD_F(0x070a6ab6) /* 0.440043173 */, 16 },
- /* 2214 */ { MAD_F(0x070b80bc) /* 0.440308320 */, 16 },
- /* 2215 */ { MAD_F(0x070c96ce) /* 0.440573506 */, 16 },
- /* 2216 */ { MAD_F(0x070dacea) /* 0.440838732 */, 16 },
- /* 2217 */ { MAD_F(0x070ec310) /* 0.441103997 */, 16 },
- /* 2218 */ { MAD_F(0x070fd942) /* 0.441369303 */, 16 },
- /* 2219 */ { MAD_F(0x0710ef7e) /* 0.441634649 */, 16 },
- /* 2220 */ { MAD_F(0x071205c5) /* 0.441900034 */, 16 },
- /* 2221 */ { MAD_F(0x07131c17) /* 0.442165460 */, 16 },
- /* 2222 */ { MAD_F(0x07143273) /* 0.442430925 */, 16 },
- /* 2223 */ { MAD_F(0x071548da) /* 0.442696430 */, 16 },
-
- /* 2224 */ { MAD_F(0x07165f4b) /* 0.442961975 */, 16 },
- /* 2225 */ { MAD_F(0x071775c8) /* 0.443227559 */, 16 },
- /* 2226 */ { MAD_F(0x07188c4f) /* 0.443493184 */, 16 },
- /* 2227 */ { MAD_F(0x0719a2e0) /* 0.443758848 */, 16 },
- /* 2228 */ { MAD_F(0x071ab97d) /* 0.444024552 */, 16 },
- /* 2229 */ { MAD_F(0x071bd024) /* 0.444290296 */, 16 },
- /* 2230 */ { MAD_F(0x071ce6d6) /* 0.444556079 */, 16 },
- /* 2231 */ { MAD_F(0x071dfd92) /* 0.444821902 */, 16 },
- /* 2232 */ { MAD_F(0x071f1459) /* 0.445087765 */, 16 },
- /* 2233 */ { MAD_F(0x07202b2b) /* 0.445353668 */, 16 },
- /* 2234 */ { MAD_F(0x07214207) /* 0.445619610 */, 16 },
- /* 2235 */ { MAD_F(0x072258ee) /* 0.445885592 */, 16 },
- /* 2236 */ { MAD_F(0x07236fe0) /* 0.446151614 */, 16 },
- /* 2237 */ { MAD_F(0x072486dc) /* 0.446417675 */, 16 },
- /* 2238 */ { MAD_F(0x07259de3) /* 0.446683776 */, 16 },
- /* 2239 */ { MAD_F(0x0726b4f4) /* 0.446949917 */, 16 },
-
- /* 2240 */ { MAD_F(0x0727cc11) /* 0.447216097 */, 16 },
- /* 2241 */ { MAD_F(0x0728e338) /* 0.447482317 */, 16 },
- /* 2242 */ { MAD_F(0x0729fa69) /* 0.447748576 */, 16 },
- /* 2243 */ { MAD_F(0x072b11a5) /* 0.448014875 */, 16 },
- /* 2244 */ { MAD_F(0x072c28ec) /* 0.448281214 */, 16 },
- /* 2245 */ { MAD_F(0x072d403d) /* 0.448547592 */, 16 },
- /* 2246 */ { MAD_F(0x072e5799) /* 0.448814010 */, 16 },
- /* 2247 */ { MAD_F(0x072f6f00) /* 0.449080467 */, 16 },
- /* 2248 */ { MAD_F(0x07308671) /* 0.449346964 */, 16 },
- /* 2249 */ { MAD_F(0x07319ded) /* 0.449613501 */, 16 },
- /* 2250 */ { MAD_F(0x0732b573) /* 0.449880076 */, 16 },
- /* 2251 */ { MAD_F(0x0733cd04) /* 0.450146692 */, 16 },
- /* 2252 */ { MAD_F(0x0734e4a0) /* 0.450413347 */, 16 },
- /* 2253 */ { MAD_F(0x0735fc46) /* 0.450680041 */, 16 },
- /* 2254 */ { MAD_F(0x073713f7) /* 0.450946775 */, 16 },
- /* 2255 */ { MAD_F(0x07382bb2) /* 0.451213548 */, 16 },
-
- /* 2256 */ { MAD_F(0x07394378) /* 0.451480360 */, 16 },
- /* 2257 */ { MAD_F(0x073a5b49) /* 0.451747213 */, 16 },
- /* 2258 */ { MAD_F(0x073b7324) /* 0.452014104 */, 16 },
- /* 2259 */ { MAD_F(0x073c8b0a) /* 0.452281035 */, 16 },
- /* 2260 */ { MAD_F(0x073da2fa) /* 0.452548005 */, 16 },
- /* 2261 */ { MAD_F(0x073ebaf5) /* 0.452815015 */, 16 },
- /* 2262 */ { MAD_F(0x073fd2fa) /* 0.453082064 */, 16 },
- /* 2263 */ { MAD_F(0x0740eb0a) /* 0.453349152 */, 16 },
- /* 2264 */ { MAD_F(0x07420325) /* 0.453616280 */, 16 },
- /* 2265 */ { MAD_F(0x07431b4a) /* 0.453883447 */, 16 },
- /* 2266 */ { MAD_F(0x0744337a) /* 0.454150653 */, 16 },
- /* 2267 */ { MAD_F(0x07454bb4) /* 0.454417899 */, 16 },
- /* 2268 */ { MAD_F(0x074663f8) /* 0.454685184 */, 16 },
- /* 2269 */ { MAD_F(0x07477c48) /* 0.454952508 */, 16 },
- /* 2270 */ { MAD_F(0x074894a2) /* 0.455219872 */, 16 },
- /* 2271 */ { MAD_F(0x0749ad06) /* 0.455487275 */, 16 },
-
- /* 2272 */ { MAD_F(0x074ac575) /* 0.455754717 */, 16 },
- /* 2273 */ { MAD_F(0x074bddee) /* 0.456022198 */, 16 },
- /* 2274 */ { MAD_F(0x074cf672) /* 0.456289719 */, 16 },
- /* 2275 */ { MAD_F(0x074e0f01) /* 0.456557278 */, 16 },
- /* 2276 */ { MAD_F(0x074f279a) /* 0.456824877 */, 16 },
- /* 2277 */ { MAD_F(0x0750403e) /* 0.457092516 */, 16 },
- /* 2278 */ { MAD_F(0x075158ec) /* 0.457360193 */, 16 },
- /* 2279 */ { MAD_F(0x075271a4) /* 0.457627909 */, 16 },
- /* 2280 */ { MAD_F(0x07538a67) /* 0.457895665 */, 16 },
- /* 2281 */ { MAD_F(0x0754a335) /* 0.458163460 */, 16 },
- /* 2282 */ { MAD_F(0x0755bc0d) /* 0.458431294 */, 16 },
- /* 2283 */ { MAD_F(0x0756d4f0) /* 0.458699167 */, 16 },
- /* 2284 */ { MAD_F(0x0757eddd) /* 0.458967079 */, 16 },
- /* 2285 */ { MAD_F(0x075906d5) /* 0.459235030 */, 16 },
- /* 2286 */ { MAD_F(0x075a1fd7) /* 0.459503021 */, 16 },
- /* 2287 */ { MAD_F(0x075b38e3) /* 0.459771050 */, 16 },
-
- /* 2288 */ { MAD_F(0x075c51fa) /* 0.460039119 */, 16 },
- /* 2289 */ { MAD_F(0x075d6b1c) /* 0.460307226 */, 16 },
- /* 2290 */ { MAD_F(0x075e8448) /* 0.460575373 */, 16 },
- /* 2291 */ { MAD_F(0x075f9d7f) /* 0.460843559 */, 16 },
- /* 2292 */ { MAD_F(0x0760b6c0) /* 0.461111783 */, 16 },
- /* 2293 */ { MAD_F(0x0761d00b) /* 0.461380047 */, 16 },
- /* 2294 */ { MAD_F(0x0762e961) /* 0.461648350 */, 16 },
- /* 2295 */ { MAD_F(0x076402c1) /* 0.461916691 */, 16 },
- /* 2296 */ { MAD_F(0x07651c2c) /* 0.462185072 */, 16 },
- /* 2297 */ { MAD_F(0x076635a2) /* 0.462453492 */, 16 },
- /* 2298 */ { MAD_F(0x07674f22) /* 0.462721950 */, 16 },
- /* 2299 */ { MAD_F(0x076868ac) /* 0.462990448 */, 16 },
- /* 2300 */ { MAD_F(0x07698240) /* 0.463258984 */, 16 },
- /* 2301 */ { MAD_F(0x076a9be0) /* 0.463527560 */, 16 },
- /* 2302 */ { MAD_F(0x076bb589) /* 0.463796174 */, 16 },
- /* 2303 */ { MAD_F(0x076ccf3d) /* 0.464064827 */, 16 },
-
- /* 2304 */ { MAD_F(0x076de8fc) /* 0.464333519 */, 16 },
- /* 2305 */ { MAD_F(0x076f02c5) /* 0.464602250 */, 16 },
- /* 2306 */ { MAD_F(0x07701c98) /* 0.464871020 */, 16 },
- /* 2307 */ { MAD_F(0x07713676) /* 0.465139829 */, 16 },
- /* 2308 */ { MAD_F(0x0772505e) /* 0.465408676 */, 16 },
- /* 2309 */ { MAD_F(0x07736a51) /* 0.465677563 */, 16 },
- /* 2310 */ { MAD_F(0x0774844e) /* 0.465946488 */, 16 },
- /* 2311 */ { MAD_F(0x07759e55) /* 0.466215452 */, 16 },
- /* 2312 */ { MAD_F(0x0776b867) /* 0.466484455 */, 16 },
- /* 2313 */ { MAD_F(0x0777d283) /* 0.466753496 */, 16 },
- /* 2314 */ { MAD_F(0x0778ecaa) /* 0.467022577 */, 16 },
- /* 2315 */ { MAD_F(0x077a06db) /* 0.467291696 */, 16 },
- /* 2316 */ { MAD_F(0x077b2117) /* 0.467560854 */, 16 },
- /* 2317 */ { MAD_F(0x077c3b5d) /* 0.467830050 */, 16 },
- /* 2318 */ { MAD_F(0x077d55ad) /* 0.468099285 */, 16 },
- /* 2319 */ { MAD_F(0x077e7008) /* 0.468368560 */, 16 },
-
- /* 2320 */ { MAD_F(0x077f8a6d) /* 0.468637872 */, 16 },
- /* 2321 */ { MAD_F(0x0780a4dc) /* 0.468907224 */, 16 },
- /* 2322 */ { MAD_F(0x0781bf56) /* 0.469176614 */, 16 },
- /* 2323 */ { MAD_F(0x0782d9da) /* 0.469446043 */, 16 },
- /* 2324 */ { MAD_F(0x0783f469) /* 0.469715510 */, 16 },
- /* 2325 */ { MAD_F(0x07850f02) /* 0.469985016 */, 16 },
- /* 2326 */ { MAD_F(0x078629a5) /* 0.470254561 */, 16 },
- /* 2327 */ { MAD_F(0x07874453) /* 0.470524145 */, 16 },
- /* 2328 */ { MAD_F(0x07885f0b) /* 0.470793767 */, 16 },
- /* 2329 */ { MAD_F(0x078979ce) /* 0.471063427 */, 16 },
- /* 2330 */ { MAD_F(0x078a949a) /* 0.471333126 */, 16 },
- /* 2331 */ { MAD_F(0x078baf72) /* 0.471602864 */, 16 },
- /* 2332 */ { MAD_F(0x078cca53) /* 0.471872641 */, 16 },
- /* 2333 */ { MAD_F(0x078de53f) /* 0.472142456 */, 16 },
- /* 2334 */ { MAD_F(0x078f0035) /* 0.472412309 */, 16 },
- /* 2335 */ { MAD_F(0x07901b36) /* 0.472682201 */, 16 },
-
- /* 2336 */ { MAD_F(0x07913641) /* 0.472952132 */, 16 },
- /* 2337 */ { MAD_F(0x07925156) /* 0.473222101 */, 16 },
- /* 2338 */ { MAD_F(0x07936c76) /* 0.473492108 */, 16 },
- /* 2339 */ { MAD_F(0x079487a0) /* 0.473762155 */, 16 },
- /* 2340 */ { MAD_F(0x0795a2d4) /* 0.474032239 */, 16 },
- /* 2341 */ { MAD_F(0x0796be13) /* 0.474302362 */, 16 },
- /* 2342 */ { MAD_F(0x0797d95c) /* 0.474572524 */, 16 },
- /* 2343 */ { MAD_F(0x0798f4af) /* 0.474842724 */, 16 },
- /* 2344 */ { MAD_F(0x079a100c) /* 0.475112962 */, 16 },
- /* 2345 */ { MAD_F(0x079b2b74) /* 0.475383239 */, 16 },
- /* 2346 */ { MAD_F(0x079c46e7) /* 0.475653554 */, 16 },
- /* 2347 */ { MAD_F(0x079d6263) /* 0.475923908 */, 16 },
- /* 2348 */ { MAD_F(0x079e7dea) /* 0.476194300 */, 16 },
- /* 2349 */ { MAD_F(0x079f997b) /* 0.476464731 */, 16 },
- /* 2350 */ { MAD_F(0x07a0b516) /* 0.476735200 */, 16 },
- /* 2351 */ { MAD_F(0x07a1d0bc) /* 0.477005707 */, 16 },
-
- /* 2352 */ { MAD_F(0x07a2ec6c) /* 0.477276252 */, 16 },
- /* 2353 */ { MAD_F(0x07a40827) /* 0.477546836 */, 16 },
- /* 2354 */ { MAD_F(0x07a523eb) /* 0.477817459 */, 16 },
- /* 2355 */ { MAD_F(0x07a63fba) /* 0.478088119 */, 16 },
- /* 2356 */ { MAD_F(0x07a75b93) /* 0.478358818 */, 16 },
- /* 2357 */ { MAD_F(0x07a87777) /* 0.478629555 */, 16 },
- /* 2358 */ { MAD_F(0x07a99364) /* 0.478900331 */, 16 },
- /* 2359 */ { MAD_F(0x07aaaf5c) /* 0.479171145 */, 16 },
- /* 2360 */ { MAD_F(0x07abcb5f) /* 0.479441997 */, 16 },
- /* 2361 */ { MAD_F(0x07ace76b) /* 0.479712887 */, 16 },
- /* 2362 */ { MAD_F(0x07ae0382) /* 0.479983816 */, 16 },
- /* 2363 */ { MAD_F(0x07af1fa3) /* 0.480254782 */, 16 },
- /* 2364 */ { MAD_F(0x07b03bcf) /* 0.480525787 */, 16 },
- /* 2365 */ { MAD_F(0x07b15804) /* 0.480796831 */, 16 },
- /* 2366 */ { MAD_F(0x07b27444) /* 0.481067912 */, 16 },
- /* 2367 */ { MAD_F(0x07b3908e) /* 0.481339032 */, 16 },
-
- /* 2368 */ { MAD_F(0x07b4ace3) /* 0.481610189 */, 16 },
- /* 2369 */ { MAD_F(0x07b5c941) /* 0.481881385 */, 16 },
- /* 2370 */ { MAD_F(0x07b6e5aa) /* 0.482152620 */, 16 },
- /* 2371 */ { MAD_F(0x07b8021d) /* 0.482423892 */, 16 },
- /* 2372 */ { MAD_F(0x07b91e9b) /* 0.482695202 */, 16 },
- /* 2373 */ { MAD_F(0x07ba3b22) /* 0.482966551 */, 16 },
- /* 2374 */ { MAD_F(0x07bb57b4) /* 0.483237938 */, 16 },
- /* 2375 */ { MAD_F(0x07bc7450) /* 0.483509362 */, 16 },
- /* 2376 */ { MAD_F(0x07bd90f6) /* 0.483780825 */, 16 },
- /* 2377 */ { MAD_F(0x07beada7) /* 0.484052326 */, 16 },
- /* 2378 */ { MAD_F(0x07bfca61) /* 0.484323865 */, 16 },
- /* 2379 */ { MAD_F(0x07c0e726) /* 0.484595443 */, 16 },
- /* 2380 */ { MAD_F(0x07c203f5) /* 0.484867058 */, 16 },
- /* 2381 */ { MAD_F(0x07c320cf) /* 0.485138711 */, 16 },
- /* 2382 */ { MAD_F(0x07c43db2) /* 0.485410402 */, 16 },
- /* 2383 */ { MAD_F(0x07c55aa0) /* 0.485682131 */, 16 },
-
- /* 2384 */ { MAD_F(0x07c67798) /* 0.485953899 */, 16 },
- /* 2385 */ { MAD_F(0x07c7949a) /* 0.486225704 */, 16 },
- /* 2386 */ { MAD_F(0x07c8b1a7) /* 0.486497547 */, 16 },
- /* 2387 */ { MAD_F(0x07c9cebd) /* 0.486769429 */, 16 },
- /* 2388 */ { MAD_F(0x07caebde) /* 0.487041348 */, 16 },
- /* 2389 */ { MAD_F(0x07cc0909) /* 0.487313305 */, 16 },
- /* 2390 */ { MAD_F(0x07cd263e) /* 0.487585300 */, 16 },
- /* 2391 */ { MAD_F(0x07ce437d) /* 0.487857333 */, 16 },
- /* 2392 */ { MAD_F(0x07cf60c7) /* 0.488129404 */, 16 },
- /* 2393 */ { MAD_F(0x07d07e1b) /* 0.488401513 */, 16 },
- /* 2394 */ { MAD_F(0x07d19b79) /* 0.488673660 */, 16 },
- /* 2395 */ { MAD_F(0x07d2b8e1) /* 0.488945845 */, 16 },
- /* 2396 */ { MAD_F(0x07d3d653) /* 0.489218067 */, 16 },
- /* 2397 */ { MAD_F(0x07d4f3cf) /* 0.489490328 */, 16 },
- /* 2398 */ { MAD_F(0x07d61156) /* 0.489762626 */, 16 },
- /* 2399 */ { MAD_F(0x07d72ee6) /* 0.490034962 */, 16 },
-
- /* 2400 */ { MAD_F(0x07d84c81) /* 0.490307336 */, 16 },
- /* 2401 */ { MAD_F(0x07d96a26) /* 0.490579748 */, 16 },
- /* 2402 */ { MAD_F(0x07da87d5) /* 0.490852198 */, 16 },
- /* 2403 */ { MAD_F(0x07dba58f) /* 0.491124686 */, 16 },
- /* 2404 */ { MAD_F(0x07dcc352) /* 0.491397211 */, 16 },
- /* 2405 */ { MAD_F(0x07dde120) /* 0.491669774 */, 16 },
- /* 2406 */ { MAD_F(0x07defef7) /* 0.491942375 */, 16 },
- /* 2407 */ { MAD_F(0x07e01cd9) /* 0.492215014 */, 16 },
- /* 2408 */ { MAD_F(0x07e13ac5) /* 0.492487690 */, 16 },
- /* 2409 */ { MAD_F(0x07e258bc) /* 0.492760404 */, 16 },
- /* 2410 */ { MAD_F(0x07e376bc) /* 0.493033156 */, 16 },
- /* 2411 */ { MAD_F(0x07e494c6) /* 0.493305946 */, 16 },
- /* 2412 */ { MAD_F(0x07e5b2db) /* 0.493578773 */, 16 },
- /* 2413 */ { MAD_F(0x07e6d0f9) /* 0.493851638 */, 16 },
- /* 2414 */ { MAD_F(0x07e7ef22) /* 0.494124541 */, 16 },
- /* 2415 */ { MAD_F(0x07e90d55) /* 0.494397481 */, 16 },
-
- /* 2416 */ { MAD_F(0x07ea2b92) /* 0.494670459 */, 16 },
- /* 2417 */ { MAD_F(0x07eb49d9) /* 0.494943475 */, 16 },
- /* 2418 */ { MAD_F(0x07ec682a) /* 0.495216529 */, 16 },
- /* 2419 */ { MAD_F(0x07ed8686) /* 0.495489620 */, 16 },
- /* 2420 */ { MAD_F(0x07eea4eb) /* 0.495762748 */, 16 },
- /* 2421 */ { MAD_F(0x07efc35b) /* 0.496035915 */, 16 },
- /* 2422 */ { MAD_F(0x07f0e1d4) /* 0.496309119 */, 16 },
- /* 2423 */ { MAD_F(0x07f20058) /* 0.496582360 */, 16 },
- /* 2424 */ { MAD_F(0x07f31ee6) /* 0.496855639 */, 16 },
- /* 2425 */ { MAD_F(0x07f43d7e) /* 0.497128956 */, 16 },
- /* 2426 */ { MAD_F(0x07f55c20) /* 0.497402310 */, 16 },
- /* 2427 */ { MAD_F(0x07f67acc) /* 0.497675702 */, 16 },
- /* 2428 */ { MAD_F(0x07f79982) /* 0.497949132 */, 16 },
- /* 2429 */ { MAD_F(0x07f8b842) /* 0.498222598 */, 16 },
- /* 2430 */ { MAD_F(0x07f9d70c) /* 0.498496103 */, 16 },
- /* 2431 */ { MAD_F(0x07faf5e1) /* 0.498769645 */, 16 },
-
- /* 2432 */ { MAD_F(0x07fc14bf) /* 0.499043224 */, 16 },
- /* 2433 */ { MAD_F(0x07fd33a8) /* 0.499316841 */, 16 },
- /* 2434 */ { MAD_F(0x07fe529a) /* 0.499590496 */, 16 },
- /* 2435 */ { MAD_F(0x07ff7197) /* 0.499864188 */, 16 },
- /* 2436 */ { MAD_F(0x0400484f) /* 0.250068959 */, 17 },
- /* 2437 */ { MAD_F(0x0400d7d7) /* 0.250205842 */, 17 },
- /* 2438 */ { MAD_F(0x04016764) /* 0.250342744 */, 17 },
- /* 2439 */ { MAD_F(0x0401f6f7) /* 0.250479665 */, 17 },
- /* 2440 */ { MAD_F(0x0402868e) /* 0.250616605 */, 17 },
- /* 2441 */ { MAD_F(0x0403162b) /* 0.250753563 */, 17 },
- /* 2442 */ { MAD_F(0x0403a5cc) /* 0.250890540 */, 17 },
- /* 2443 */ { MAD_F(0x04043573) /* 0.251027536 */, 17 },
- /* 2444 */ { MAD_F(0x0404c51e) /* 0.251164550 */, 17 },
- /* 2445 */ { MAD_F(0x040554cf) /* 0.251301583 */, 17 },
- /* 2446 */ { MAD_F(0x0405e484) /* 0.251438635 */, 17 },
- /* 2447 */ { MAD_F(0x0406743f) /* 0.251575706 */, 17 },
-
- /* 2448 */ { MAD_F(0x040703ff) /* 0.251712795 */, 17 },
- /* 2449 */ { MAD_F(0x040793c3) /* 0.251849903 */, 17 },
- /* 2450 */ { MAD_F(0x0408238d) /* 0.251987029 */, 17 },
- /* 2451 */ { MAD_F(0x0408b35b) /* 0.252124174 */, 17 },
- /* 2452 */ { MAD_F(0x0409432f) /* 0.252261338 */, 17 },
- /* 2453 */ { MAD_F(0x0409d308) /* 0.252398520 */, 17 },
- /* 2454 */ { MAD_F(0x040a62e5) /* 0.252535721 */, 17 },
- /* 2455 */ { MAD_F(0x040af2c8) /* 0.252672941 */, 17 },
- /* 2456 */ { MAD_F(0x040b82b0) /* 0.252810180 */, 17 },
- /* 2457 */ { MAD_F(0x040c129c) /* 0.252947436 */, 17 },
- /* 2458 */ { MAD_F(0x040ca28e) /* 0.253084712 */, 17 },
- /* 2459 */ { MAD_F(0x040d3284) /* 0.253222006 */, 17 },
- /* 2460 */ { MAD_F(0x040dc280) /* 0.253359319 */, 17 },
- /* 2461 */ { MAD_F(0x040e5281) /* 0.253496651 */, 17 },
- /* 2462 */ { MAD_F(0x040ee286) /* 0.253634001 */, 17 },
- /* 2463 */ { MAD_F(0x040f7291) /* 0.253771369 */, 17 },
-
- /* 2464 */ { MAD_F(0x041002a1) /* 0.253908756 */, 17 },
- /* 2465 */ { MAD_F(0x041092b5) /* 0.254046162 */, 17 },
- /* 2466 */ { MAD_F(0x041122cf) /* 0.254183587 */, 17 },
- /* 2467 */ { MAD_F(0x0411b2ed) /* 0.254321030 */, 17 },
- /* 2468 */ { MAD_F(0x04124311) /* 0.254458491 */, 17 },
- /* 2469 */ { MAD_F(0x0412d339) /* 0.254595971 */, 17 },
- /* 2470 */ { MAD_F(0x04136367) /* 0.254733470 */, 17 },
- /* 2471 */ { MAD_F(0x0413f399) /* 0.254870987 */, 17 },
- /* 2472 */ { MAD_F(0x041483d1) /* 0.255008523 */, 17 },
- /* 2473 */ { MAD_F(0x0415140d) /* 0.255146077 */, 17 },
- /* 2474 */ { MAD_F(0x0415a44f) /* 0.255283650 */, 17 },
- /* 2475 */ { MAD_F(0x04163495) /* 0.255421241 */, 17 },
- /* 2476 */ { MAD_F(0x0416c4e1) /* 0.255558851 */, 17 },
- /* 2477 */ { MAD_F(0x04175531) /* 0.255696480 */, 17 },
- /* 2478 */ { MAD_F(0x0417e586) /* 0.255834127 */, 17 },
- /* 2479 */ { MAD_F(0x041875e1) /* 0.255971792 */, 17 },
-
- /* 2480 */ { MAD_F(0x04190640) /* 0.256109476 */, 17 },
- /* 2481 */ { MAD_F(0x041996a4) /* 0.256247179 */, 17 },
- /* 2482 */ { MAD_F(0x041a270d) /* 0.256384900 */, 17 },
- /* 2483 */ { MAD_F(0x041ab77b) /* 0.256522639 */, 17 },
- /* 2484 */ { MAD_F(0x041b47ef) /* 0.256660397 */, 17 },
- /* 2485 */ { MAD_F(0x041bd867) /* 0.256798174 */, 17 },
- /* 2486 */ { MAD_F(0x041c68e4) /* 0.256935969 */, 17 },
- /* 2487 */ { MAD_F(0x041cf966) /* 0.257073782 */, 17 },
- /* 2488 */ { MAD_F(0x041d89ed) /* 0.257211614 */, 17 },
- /* 2489 */ { MAD_F(0x041e1a79) /* 0.257349465 */, 17 },
- /* 2490 */ { MAD_F(0x041eab0a) /* 0.257487334 */, 17 },
- /* 2491 */ { MAD_F(0x041f3b9f) /* 0.257625221 */, 17 },
- /* 2492 */ { MAD_F(0x041fcc3a) /* 0.257763127 */, 17 },
- /* 2493 */ { MAD_F(0x04205cda) /* 0.257901051 */, 17 },
- /* 2494 */ { MAD_F(0x0420ed7f) /* 0.258038994 */, 17 },
- /* 2495 */ { MAD_F(0x04217e28) /* 0.258176955 */, 17 },
-
- /* 2496 */ { MAD_F(0x04220ed7) /* 0.258314934 */, 17 },
- /* 2497 */ { MAD_F(0x04229f8a) /* 0.258452932 */, 17 },
- /* 2498 */ { MAD_F(0x04233043) /* 0.258590948 */, 17 },
- /* 2499 */ { MAD_F(0x0423c100) /* 0.258728983 */, 17 },
- /* 2500 */ { MAD_F(0x042451c3) /* 0.258867036 */, 17 },
- /* 2501 */ { MAD_F(0x0424e28a) /* 0.259005108 */, 17 },
- /* 2502 */ { MAD_F(0x04257356) /* 0.259143198 */, 17 },
- /* 2503 */ { MAD_F(0x04260428) /* 0.259281307 */, 17 },
- /* 2504 */ { MAD_F(0x042694fe) /* 0.259419433 */, 17 },
- /* 2505 */ { MAD_F(0x042725d9) /* 0.259557579 */, 17 },
- /* 2506 */ { MAD_F(0x0427b6b9) /* 0.259695742 */, 17 },
- /* 2507 */ { MAD_F(0x0428479e) /* 0.259833924 */, 17 },
- /* 2508 */ { MAD_F(0x0428d888) /* 0.259972124 */, 17 },
- /* 2509 */ { MAD_F(0x04296976) /* 0.260110343 */, 17 },
- /* 2510 */ { MAD_F(0x0429fa6a) /* 0.260248580 */, 17 },
- /* 2511 */ { MAD_F(0x042a8b63) /* 0.260386836 */, 17 },
-
- /* 2512 */ { MAD_F(0x042b1c60) /* 0.260525110 */, 17 },
- /* 2513 */ { MAD_F(0x042bad63) /* 0.260663402 */, 17 },
- /* 2514 */ { MAD_F(0x042c3e6a) /* 0.260801712 */, 17 },
- /* 2515 */ { MAD_F(0x042ccf77) /* 0.260940041 */, 17 },
- /* 2516 */ { MAD_F(0x042d6088) /* 0.261078388 */, 17 },
- /* 2517 */ { MAD_F(0x042df19e) /* 0.261216754 */, 17 },
- /* 2518 */ { MAD_F(0x042e82b9) /* 0.261355137 */, 17 },
- /* 2519 */ { MAD_F(0x042f13d9) /* 0.261493540 */, 17 },
- /* 2520 */ { MAD_F(0x042fa4fe) /* 0.261631960 */, 17 },
- /* 2521 */ { MAD_F(0x04303628) /* 0.261770399 */, 17 },
- /* 2522 */ { MAD_F(0x0430c757) /* 0.261908856 */, 17 },
- /* 2523 */ { MAD_F(0x0431588b) /* 0.262047331 */, 17 },
- /* 2524 */ { MAD_F(0x0431e9c3) /* 0.262185825 */, 17 },
- /* 2525 */ { MAD_F(0x04327b01) /* 0.262324337 */, 17 },
- /* 2526 */ { MAD_F(0x04330c43) /* 0.262462867 */, 17 },
- /* 2527 */ { MAD_F(0x04339d8a) /* 0.262601416 */, 17 },
-
- /* 2528 */ { MAD_F(0x04342ed7) /* 0.262739982 */, 17 },
- /* 2529 */ { MAD_F(0x0434c028) /* 0.262878568 */, 17 },
- /* 2530 */ { MAD_F(0x0435517e) /* 0.263017171 */, 17 },
- /* 2531 */ { MAD_F(0x0435e2d9) /* 0.263155792 */, 17 },
- /* 2532 */ { MAD_F(0x04367439) /* 0.263294432 */, 17 },
- /* 2533 */ { MAD_F(0x0437059e) /* 0.263433090 */, 17 },
- /* 2534 */ { MAD_F(0x04379707) /* 0.263571767 */, 17 },
- /* 2535 */ { MAD_F(0x04382876) /* 0.263710461 */, 17 },
- /* 2536 */ { MAD_F(0x0438b9e9) /* 0.263849174 */, 17 },
- /* 2537 */ { MAD_F(0x04394b61) /* 0.263987905 */, 17 },
- /* 2538 */ { MAD_F(0x0439dcdf) /* 0.264126655 */, 17 },
- /* 2539 */ { MAD_F(0x043a6e61) /* 0.264265422 */, 17 },
- /* 2540 */ { MAD_F(0x043affe8) /* 0.264404208 */, 17 },
- /* 2541 */ { MAD_F(0x043b9174) /* 0.264543012 */, 17 },
- /* 2542 */ { MAD_F(0x043c2305) /* 0.264681834 */, 17 },
- /* 2543 */ { MAD_F(0x043cb49a) /* 0.264820674 */, 17 },
-
- /* 2544 */ { MAD_F(0x043d4635) /* 0.264959533 */, 17 },
- /* 2545 */ { MAD_F(0x043dd7d4) /* 0.265098410 */, 17 },
- /* 2546 */ { MAD_F(0x043e6979) /* 0.265237305 */, 17 },
- /* 2547 */ { MAD_F(0x043efb22) /* 0.265376218 */, 17 },
- /* 2548 */ { MAD_F(0x043f8cd0) /* 0.265515149 */, 17 },
- /* 2549 */ { MAD_F(0x04401e83) /* 0.265654099 */, 17 },
- /* 2550 */ { MAD_F(0x0440b03b) /* 0.265793066 */, 17 },
- /* 2551 */ { MAD_F(0x044141f7) /* 0.265932052 */, 17 },
- /* 2552 */ { MAD_F(0x0441d3b9) /* 0.266071056 */, 17 },
- /* 2553 */ { MAD_F(0x04426580) /* 0.266210078 */, 17 },
- /* 2554 */ { MAD_F(0x0442f74b) /* 0.266349119 */, 17 },
- /* 2555 */ { MAD_F(0x0443891b) /* 0.266488177 */, 17 },
- /* 2556 */ { MAD_F(0x04441af0) /* 0.266627254 */, 17 },
- /* 2557 */ { MAD_F(0x0444acca) /* 0.266766349 */, 17 },
- /* 2558 */ { MAD_F(0x04453ea9) /* 0.266905462 */, 17 },
- /* 2559 */ { MAD_F(0x0445d08d) /* 0.267044593 */, 17 },
-
- /* 2560 */ { MAD_F(0x04466275) /* 0.267183742 */, 17 },
- /* 2561 */ { MAD_F(0x0446f463) /* 0.267322909 */, 17 },
- /* 2562 */ { MAD_F(0x04478655) /* 0.267462094 */, 17 },
- /* 2563 */ { MAD_F(0x0448184c) /* 0.267601298 */, 17 },
- /* 2564 */ { MAD_F(0x0448aa48) /* 0.267740519 */, 17 },
- /* 2565 */ { MAD_F(0x04493c49) /* 0.267879759 */, 17 },
- /* 2566 */ { MAD_F(0x0449ce4f) /* 0.268019017 */, 17 },
- /* 2567 */ { MAD_F(0x044a6059) /* 0.268158293 */, 17 },
- /* 2568 */ { MAD_F(0x044af269) /* 0.268297587 */, 17 },
- /* 2569 */ { MAD_F(0x044b847d) /* 0.268436899 */, 17 },
- /* 2570 */ { MAD_F(0x044c1696) /* 0.268576229 */, 17 },
- /* 2571 */ { MAD_F(0x044ca8b4) /* 0.268715577 */, 17 },
- /* 2572 */ { MAD_F(0x044d3ad7) /* 0.268854943 */, 17 },
- /* 2573 */ { MAD_F(0x044dccff) /* 0.268994328 */, 17 },
- /* 2574 */ { MAD_F(0x044e5f2b) /* 0.269133730 */, 17 },
- /* 2575 */ { MAD_F(0x044ef15d) /* 0.269273150 */, 17 },
-
- /* 2576 */ { MAD_F(0x044f8393) /* 0.269412589 */, 17 },
- /* 2577 */ { MAD_F(0x045015ce) /* 0.269552045 */, 17 },
- /* 2578 */ { MAD_F(0x0450a80e) /* 0.269691520 */, 17 },
- /* 2579 */ { MAD_F(0x04513a53) /* 0.269831013 */, 17 },
- /* 2580 */ { MAD_F(0x0451cc9c) /* 0.269970523 */, 17 },
- /* 2581 */ { MAD_F(0x04525eeb) /* 0.270110052 */, 17 },
- /* 2582 */ { MAD_F(0x0452f13e) /* 0.270249599 */, 17 },
- /* 2583 */ { MAD_F(0x04538396) /* 0.270389163 */, 17 },
- /* 2584 */ { MAD_F(0x045415f3) /* 0.270528746 */, 17 },
- /* 2585 */ { MAD_F(0x0454a855) /* 0.270668347 */, 17 },
- /* 2586 */ { MAD_F(0x04553abb) /* 0.270807965 */, 17 },
- /* 2587 */ { MAD_F(0x0455cd27) /* 0.270947602 */, 17 },
- /* 2588 */ { MAD_F(0x04565f97) /* 0.271087257 */, 17 },
- /* 2589 */ { MAD_F(0x0456f20c) /* 0.271226930 */, 17 },
- /* 2590 */ { MAD_F(0x04578486) /* 0.271366620 */, 17 },
- /* 2591 */ { MAD_F(0x04581705) /* 0.271506329 */, 17 },
-
- /* 2592 */ { MAD_F(0x0458a989) /* 0.271646056 */, 17 },
- /* 2593 */ { MAD_F(0x04593c11) /* 0.271785800 */, 17 },
- /* 2594 */ { MAD_F(0x0459ce9e) /* 0.271925563 */, 17 },
- /* 2595 */ { MAD_F(0x045a6130) /* 0.272065343 */, 17 },
- /* 2596 */ { MAD_F(0x045af3c7) /* 0.272205142 */, 17 },
- /* 2597 */ { MAD_F(0x045b8663) /* 0.272344958 */, 17 },
- /* 2598 */ { MAD_F(0x045c1903) /* 0.272484793 */, 17 },
- /* 2599 */ { MAD_F(0x045caba9) /* 0.272624645 */, 17 },
- /* 2600 */ { MAD_F(0x045d3e53) /* 0.272764515 */, 17 },
- /* 2601 */ { MAD_F(0x045dd102) /* 0.272904403 */, 17 },
- /* 2602 */ { MAD_F(0x045e63b6) /* 0.273044310 */, 17 },
- /* 2603 */ { MAD_F(0x045ef66e) /* 0.273184234 */, 17 },
- /* 2604 */ { MAD_F(0x045f892b) /* 0.273324176 */, 17 },
- /* 2605 */ { MAD_F(0x04601bee) /* 0.273464136 */, 17 },
- /* 2606 */ { MAD_F(0x0460aeb5) /* 0.273604113 */, 17 },
- /* 2607 */ { MAD_F(0x04614180) /* 0.273744109 */, 17 },
-
- /* 2608 */ { MAD_F(0x0461d451) /* 0.273884123 */, 17 },
- /* 2609 */ { MAD_F(0x04626727) /* 0.274024154 */, 17 },
- /* 2610 */ { MAD_F(0x0462fa01) /* 0.274164204 */, 17 },
- /* 2611 */ { MAD_F(0x04638ce0) /* 0.274304271 */, 17 },
- /* 2612 */ { MAD_F(0x04641fc4) /* 0.274444356 */, 17 },
- /* 2613 */ { MAD_F(0x0464b2ac) /* 0.274584459 */, 17 },
- /* 2614 */ { MAD_F(0x0465459a) /* 0.274724580 */, 17 },
- /* 2615 */ { MAD_F(0x0465d88c) /* 0.274864719 */, 17 },
- /* 2616 */ { MAD_F(0x04666b83) /* 0.275004875 */, 17 },
- /* 2617 */ { MAD_F(0x0466fe7f) /* 0.275145050 */, 17 },
- /* 2618 */ { MAD_F(0x0467917f) /* 0.275285242 */, 17 },
- /* 2619 */ { MAD_F(0x04682485) /* 0.275425452 */, 17 },
- /* 2620 */ { MAD_F(0x0468b78f) /* 0.275565681 */, 17 },
- /* 2621 */ { MAD_F(0x04694a9e) /* 0.275705926 */, 17 },
- /* 2622 */ { MAD_F(0x0469ddb2) /* 0.275846190 */, 17 },
- /* 2623 */ { MAD_F(0x046a70ca) /* 0.275986472 */, 17 },
-
- /* 2624 */ { MAD_F(0x046b03e7) /* 0.276126771 */, 17 },
- /* 2625 */ { MAD_F(0x046b970a) /* 0.276267088 */, 17 },
- /* 2626 */ { MAD_F(0x046c2a31) /* 0.276407423 */, 17 },
- /* 2627 */ { MAD_F(0x046cbd5c) /* 0.276547776 */, 17 },
- /* 2628 */ { MAD_F(0x046d508d) /* 0.276688147 */, 17 },
- /* 2629 */ { MAD_F(0x046de3c2) /* 0.276828535 */, 17 },
- /* 2630 */ { MAD_F(0x046e76fc) /* 0.276968942 */, 17 },
- /* 2631 */ { MAD_F(0x046f0a3b) /* 0.277109366 */, 17 },
- /* 2632 */ { MAD_F(0x046f9d7e) /* 0.277249808 */, 17 },
- /* 2633 */ { MAD_F(0x047030c7) /* 0.277390267 */, 17 },
- /* 2634 */ { MAD_F(0x0470c414) /* 0.277530745 */, 17 },
- /* 2635 */ { MAD_F(0x04715766) /* 0.277671240 */, 17 },
- /* 2636 */ { MAD_F(0x0471eabc) /* 0.277811753 */, 17 },
- /* 2637 */ { MAD_F(0x04727e18) /* 0.277952284 */, 17 },
- /* 2638 */ { MAD_F(0x04731178) /* 0.278092832 */, 17 },
- /* 2639 */ { MAD_F(0x0473a4dd) /* 0.278233399 */, 17 },
-
- /* 2640 */ { MAD_F(0x04743847) /* 0.278373983 */, 17 },
- /* 2641 */ { MAD_F(0x0474cbb5) /* 0.278514584 */, 17 },
- /* 2642 */ { MAD_F(0x04755f29) /* 0.278655204 */, 17 },
- /* 2643 */ { MAD_F(0x0475f2a1) /* 0.278795841 */, 17 },
- /* 2644 */ { MAD_F(0x0476861d) /* 0.278936496 */, 17 },
- /* 2645 */ { MAD_F(0x0477199f) /* 0.279077169 */, 17 },
- /* 2646 */ { MAD_F(0x0477ad25) /* 0.279217860 */, 17 },
- /* 2647 */ { MAD_F(0x047840b0) /* 0.279358568 */, 17 },
- /* 2648 */ { MAD_F(0x0478d440) /* 0.279499294 */, 17 },
- /* 2649 */ { MAD_F(0x047967d5) /* 0.279640037 */, 17 },
- /* 2650 */ { MAD_F(0x0479fb6e) /* 0.279780799 */, 17 },
- /* 2651 */ { MAD_F(0x047a8f0c) /* 0.279921578 */, 17 },
- /* 2652 */ { MAD_F(0x047b22af) /* 0.280062375 */, 17 },
- /* 2653 */ { MAD_F(0x047bb657) /* 0.280203189 */, 17 },
- /* 2654 */ { MAD_F(0x047c4a03) /* 0.280344021 */, 17 },
- /* 2655 */ { MAD_F(0x047cddb4) /* 0.280484871 */, 17 },
-
- /* 2656 */ { MAD_F(0x047d716a) /* 0.280625739 */, 17 },
- /* 2657 */ { MAD_F(0x047e0524) /* 0.280766624 */, 17 },
- /* 2658 */ { MAD_F(0x047e98e4) /* 0.280907527 */, 17 },
- /* 2659 */ { MAD_F(0x047f2ca8) /* 0.281048447 */, 17 },
- /* 2660 */ { MAD_F(0x047fc071) /* 0.281189385 */, 17 },
- /* 2661 */ { MAD_F(0x0480543e) /* 0.281330341 */, 17 },
- /* 2662 */ { MAD_F(0x0480e811) /* 0.281471315 */, 17 },
- /* 2663 */ { MAD_F(0x04817be8) /* 0.281612306 */, 17 },
- /* 2664 */ { MAD_F(0x04820fc3) /* 0.281753315 */, 17 },
- /* 2665 */ { MAD_F(0x0482a3a4) /* 0.281894341 */, 17 },
- /* 2666 */ { MAD_F(0x04833789) /* 0.282035386 */, 17 },
- /* 2667 */ { MAD_F(0x0483cb73) /* 0.282176447 */, 17 },
- /* 2668 */ { MAD_F(0x04845f62) /* 0.282317527 */, 17 },
- /* 2669 */ { MAD_F(0x0484f355) /* 0.282458624 */, 17 },
- /* 2670 */ { MAD_F(0x0485874d) /* 0.282599738 */, 17 },
- /* 2671 */ { MAD_F(0x04861b4a) /* 0.282740871 */, 17 },
-
- /* 2672 */ { MAD_F(0x0486af4c) /* 0.282882021 */, 17 },
- /* 2673 */ { MAD_F(0x04874352) /* 0.283023188 */, 17 },
- /* 2674 */ { MAD_F(0x0487d75d) /* 0.283164373 */, 17 },
- /* 2675 */ { MAD_F(0x04886b6d) /* 0.283305576 */, 17 },
- /* 2676 */ { MAD_F(0x0488ff82) /* 0.283446796 */, 17 },
- /* 2677 */ { MAD_F(0x0489939b) /* 0.283588034 */, 17 },
- /* 2678 */ { MAD_F(0x048a27b9) /* 0.283729290 */, 17 },
- /* 2679 */ { MAD_F(0x048abbdc) /* 0.283870563 */, 17 },
- /* 2680 */ { MAD_F(0x048b5003) /* 0.284011853 */, 17 },
- /* 2681 */ { MAD_F(0x048be42f) /* 0.284153161 */, 17 },
- /* 2682 */ { MAD_F(0x048c7860) /* 0.284294487 */, 17 },
- /* 2683 */ { MAD_F(0x048d0c96) /* 0.284435831 */, 17 },
- /* 2684 */ { MAD_F(0x048da0d0) /* 0.284577192 */, 17 },
- /* 2685 */ { MAD_F(0x048e350f) /* 0.284718570 */, 17 },
- /* 2686 */ { MAD_F(0x048ec953) /* 0.284859966 */, 17 },
- /* 2687 */ { MAD_F(0x048f5d9b) /* 0.285001380 */, 17 },
-
- /* 2688 */ { MAD_F(0x048ff1e8) /* 0.285142811 */, 17 },
- /* 2689 */ { MAD_F(0x0490863a) /* 0.285284259 */, 17 },
- /* 2690 */ { MAD_F(0x04911a91) /* 0.285425726 */, 17 },
- /* 2691 */ { MAD_F(0x0491aeec) /* 0.285567209 */, 17 },
- /* 2692 */ { MAD_F(0x0492434c) /* 0.285708711 */, 17 },
- /* 2693 */ { MAD_F(0x0492d7b0) /* 0.285850229 */, 17 },
- /* 2694 */ { MAD_F(0x04936c1a) /* 0.285991766 */, 17 },
- /* 2695 */ { MAD_F(0x04940088) /* 0.286133319 */, 17 },
- /* 2696 */ { MAD_F(0x049494fb) /* 0.286274891 */, 17 },
- /* 2697 */ { MAD_F(0x04952972) /* 0.286416480 */, 17 },
- /* 2698 */ { MAD_F(0x0495bdee) /* 0.286558086 */, 17 },
- /* 2699 */ { MAD_F(0x0496526f) /* 0.286699710 */, 17 },
- /* 2700 */ { MAD_F(0x0496e6f5) /* 0.286841351 */, 17 },
- /* 2701 */ { MAD_F(0x04977b7f) /* 0.286983010 */, 17 },
- /* 2702 */ { MAD_F(0x0498100e) /* 0.287124686 */, 17 },
- /* 2703 */ { MAD_F(0x0498a4a1) /* 0.287266380 */, 17 },
-
- /* 2704 */ { MAD_F(0x0499393a) /* 0.287408091 */, 17 },
- /* 2705 */ { MAD_F(0x0499cdd7) /* 0.287549820 */, 17 },
- /* 2706 */ { MAD_F(0x049a6278) /* 0.287691566 */, 17 },
- /* 2707 */ { MAD_F(0x049af71f) /* 0.287833330 */, 17 },
- /* 2708 */ { MAD_F(0x049b8bca) /* 0.287975111 */, 17 },
- /* 2709 */ { MAD_F(0x049c207a) /* 0.288116909 */, 17 },
- /* 2710 */ { MAD_F(0x049cb52e) /* 0.288258725 */, 17 },
- /* 2711 */ { MAD_F(0x049d49e7) /* 0.288400559 */, 17 },
- /* 2712 */ { MAD_F(0x049ddea5) /* 0.288542409 */, 17 },
- /* 2713 */ { MAD_F(0x049e7367) /* 0.288684278 */, 17 },
- /* 2714 */ { MAD_F(0x049f082f) /* 0.288826163 */, 17 },
- /* 2715 */ { MAD_F(0x049f9cfa) /* 0.288968067 */, 17 },
- /* 2716 */ { MAD_F(0x04a031cb) /* 0.289109987 */, 17 },
- /* 2717 */ { MAD_F(0x04a0c6a0) /* 0.289251925 */, 17 },
- /* 2718 */ { MAD_F(0x04a15b7a) /* 0.289393881 */, 17 },
- /* 2719 */ { MAD_F(0x04a1f059) /* 0.289535854 */, 17 },
-
- /* 2720 */ { MAD_F(0x04a2853c) /* 0.289677844 */, 17 },
- /* 2721 */ { MAD_F(0x04a31a24) /* 0.289819851 */, 17 },
- /* 2722 */ { MAD_F(0x04a3af10) /* 0.289961876 */, 17 },
- /* 2723 */ { MAD_F(0x04a44401) /* 0.290103919 */, 17 },
- /* 2724 */ { MAD_F(0x04a4d8f7) /* 0.290245979 */, 17 },
- /* 2725 */ { MAD_F(0x04a56df2) /* 0.290388056 */, 17 },
- /* 2726 */ { MAD_F(0x04a602f1) /* 0.290530150 */, 17 },
- /* 2727 */ { MAD_F(0x04a697f5) /* 0.290672262 */, 17 },
- /* 2728 */ { MAD_F(0x04a72cfe) /* 0.290814392 */, 17 },
- /* 2729 */ { MAD_F(0x04a7c20b) /* 0.290956538 */, 17 },
- /* 2730 */ { MAD_F(0x04a8571d) /* 0.291098703 */, 17 },
- /* 2731 */ { MAD_F(0x04a8ec33) /* 0.291240884 */, 17 },
- /* 2732 */ { MAD_F(0x04a9814e) /* 0.291383083 */, 17 },
- /* 2733 */ { MAD_F(0x04aa166e) /* 0.291525299 */, 17 },
- /* 2734 */ { MAD_F(0x04aaab93) /* 0.291667532 */, 17 },
- /* 2735 */ { MAD_F(0x04ab40bc) /* 0.291809783 */, 17 },
-
- /* 2736 */ { MAD_F(0x04abd5ea) /* 0.291952051 */, 17 },
- /* 2737 */ { MAD_F(0x04ac6b1c) /* 0.292094337 */, 17 },
- /* 2738 */ { MAD_F(0x04ad0053) /* 0.292236640 */, 17 },
- /* 2739 */ { MAD_F(0x04ad958f) /* 0.292378960 */, 17 },
- /* 2740 */ { MAD_F(0x04ae2ad0) /* 0.292521297 */, 17 },
- /* 2741 */ { MAD_F(0x04aec015) /* 0.292663652 */, 17 },
- /* 2742 */ { MAD_F(0x04af555e) /* 0.292806024 */, 17 },
- /* 2743 */ { MAD_F(0x04afeaad) /* 0.292948414 */, 17 },
- /* 2744 */ { MAD_F(0x04b08000) /* 0.293090820 */, 17 },
- /* 2745 */ { MAD_F(0x04b11557) /* 0.293233244 */, 17 },
- /* 2746 */ { MAD_F(0x04b1aab4) /* 0.293375686 */, 17 },
- /* 2747 */ { MAD_F(0x04b24015) /* 0.293518144 */, 17 },
- /* 2748 */ { MAD_F(0x04b2d57a) /* 0.293660620 */, 17 },
- /* 2749 */ { MAD_F(0x04b36ae4) /* 0.293803113 */, 17 },
- /* 2750 */ { MAD_F(0x04b40053) /* 0.293945624 */, 17 },
- /* 2751 */ { MAD_F(0x04b495c7) /* 0.294088151 */, 17 },
-
- /* 2752 */ { MAD_F(0x04b52b3f) /* 0.294230696 */, 17 },
- /* 2753 */ { MAD_F(0x04b5c0bc) /* 0.294373259 */, 17 },
- /* 2754 */ { MAD_F(0x04b6563d) /* 0.294515838 */, 17 },
- /* 2755 */ { MAD_F(0x04b6ebc3) /* 0.294658435 */, 17 },
- /* 2756 */ { MAD_F(0x04b7814e) /* 0.294801049 */, 17 },
- /* 2757 */ { MAD_F(0x04b816dd) /* 0.294943680 */, 17 },
- /* 2758 */ { MAD_F(0x04b8ac71) /* 0.295086329 */, 17 },
- /* 2759 */ { MAD_F(0x04b9420a) /* 0.295228995 */, 17 },
- /* 2760 */ { MAD_F(0x04b9d7a7) /* 0.295371678 */, 17 },
- /* 2761 */ { MAD_F(0x04ba6d49) /* 0.295514378 */, 17 },
- /* 2762 */ { MAD_F(0x04bb02ef) /* 0.295657095 */, 17 },
- /* 2763 */ { MAD_F(0x04bb989a) /* 0.295799830 */, 17 },
- /* 2764 */ { MAD_F(0x04bc2e4a) /* 0.295942582 */, 17 },
- /* 2765 */ { MAD_F(0x04bcc3fe) /* 0.296085351 */, 17 },
- /* 2766 */ { MAD_F(0x04bd59b7) /* 0.296228138 */, 17 },
- /* 2767 */ { MAD_F(0x04bdef74) /* 0.296370941 */, 17 },
-
- /* 2768 */ { MAD_F(0x04be8537) /* 0.296513762 */, 17 },
- /* 2769 */ { MAD_F(0x04bf1afd) /* 0.296656600 */, 17 },
- /* 2770 */ { MAD_F(0x04bfb0c9) /* 0.296799455 */, 17 },
- /* 2771 */ { MAD_F(0x04c04699) /* 0.296942327 */, 17 },
- /* 2772 */ { MAD_F(0x04c0dc6d) /* 0.297085217 */, 17 },
- /* 2773 */ { MAD_F(0x04c17247) /* 0.297228124 */, 17 },
- /* 2774 */ { MAD_F(0x04c20824) /* 0.297371048 */, 17 },
- /* 2775 */ { MAD_F(0x04c29e07) /* 0.297513989 */, 17 },
- /* 2776 */ { MAD_F(0x04c333ee) /* 0.297656947 */, 17 },
- /* 2777 */ { MAD_F(0x04c3c9da) /* 0.297799922 */, 17 },
- /* 2778 */ { MAD_F(0x04c45fca) /* 0.297942915 */, 17 },
- /* 2779 */ { MAD_F(0x04c4f5bf) /* 0.298085925 */, 17 },
- /* 2780 */ { MAD_F(0x04c58bb8) /* 0.298228951 */, 17 },
- /* 2781 */ { MAD_F(0x04c621b6) /* 0.298371996 */, 17 },
- /* 2782 */ { MAD_F(0x04c6b7b9) /* 0.298515057 */, 17 },
- /* 2783 */ { MAD_F(0x04c74dc0) /* 0.298658135 */, 17 },
-
- /* 2784 */ { MAD_F(0x04c7e3cc) /* 0.298801231 */, 17 },
- /* 2785 */ { MAD_F(0x04c879dd) /* 0.298944343 */, 17 },
- /* 2786 */ { MAD_F(0x04c90ff2) /* 0.299087473 */, 17 },
- /* 2787 */ { MAD_F(0x04c9a60c) /* 0.299230620 */, 17 },
- /* 2788 */ { MAD_F(0x04ca3c2a) /* 0.299373784 */, 17 },
- /* 2789 */ { MAD_F(0x04cad24d) /* 0.299516965 */, 17 },
- /* 2790 */ { MAD_F(0x04cb6874) /* 0.299660163 */, 17 },
- /* 2791 */ { MAD_F(0x04cbfea0) /* 0.299803378 */, 17 },
- /* 2792 */ { MAD_F(0x04cc94d1) /* 0.299946611 */, 17 },
- /* 2793 */ { MAD_F(0x04cd2b06) /* 0.300089860 */, 17 },
- /* 2794 */ { MAD_F(0x04cdc140) /* 0.300233127 */, 17 },
- /* 2795 */ { MAD_F(0x04ce577f) /* 0.300376411 */, 17 },
- /* 2796 */ { MAD_F(0x04ceedc2) /* 0.300519711 */, 17 },
- /* 2797 */ { MAD_F(0x04cf8409) /* 0.300663029 */, 17 },
- /* 2798 */ { MAD_F(0x04d01a55) /* 0.300806364 */, 17 },
- /* 2799 */ { MAD_F(0x04d0b0a6) /* 0.300949716 */, 17 },
-
- /* 2800 */ { MAD_F(0x04d146fb) /* 0.301093085 */, 17 },
- /* 2801 */ { MAD_F(0x04d1dd55) /* 0.301236472 */, 17 },
- /* 2802 */ { MAD_F(0x04d273b4) /* 0.301379875 */, 17 },
- /* 2803 */ { MAD_F(0x04d30a17) /* 0.301523295 */, 17 },
- /* 2804 */ { MAD_F(0x04d3a07f) /* 0.301666733 */, 17 },
- /* 2805 */ { MAD_F(0x04d436eb) /* 0.301810187 */, 17 },
- /* 2806 */ { MAD_F(0x04d4cd5c) /* 0.301953659 */, 17 },
- /* 2807 */ { MAD_F(0x04d563d1) /* 0.302097147 */, 17 },
- /* 2808 */ { MAD_F(0x04d5fa4b) /* 0.302240653 */, 17 },
- /* 2809 */ { MAD_F(0x04d690ca) /* 0.302384175 */, 17 },
- /* 2810 */ { MAD_F(0x04d7274d) /* 0.302527715 */, 17 },
- /* 2811 */ { MAD_F(0x04d7bdd5) /* 0.302671271 */, 17 },
- /* 2812 */ { MAD_F(0x04d85461) /* 0.302814845 */, 17 },
- /* 2813 */ { MAD_F(0x04d8eaf2) /* 0.302958436 */, 17 },
- /* 2814 */ { MAD_F(0x04d98187) /* 0.303102044 */, 17 },
- /* 2815 */ { MAD_F(0x04da1821) /* 0.303245668 */, 17 },
-
- /* 2816 */ { MAD_F(0x04daaec0) /* 0.303389310 */, 17 },
- /* 2817 */ { MAD_F(0x04db4563) /* 0.303532969 */, 17 },
- /* 2818 */ { MAD_F(0x04dbdc0a) /* 0.303676645 */, 17 },
- /* 2819 */ { MAD_F(0x04dc72b7) /* 0.303820337 */, 17 },
- /* 2820 */ { MAD_F(0x04dd0967) /* 0.303964047 */, 17 },
- /* 2821 */ { MAD_F(0x04dda01d) /* 0.304107774 */, 17 },
- /* 2822 */ { MAD_F(0x04de36d7) /* 0.304251517 */, 17 },
- /* 2823 */ { MAD_F(0x04decd95) /* 0.304395278 */, 17 },
- /* 2824 */ { MAD_F(0x04df6458) /* 0.304539056 */, 17 },
- /* 2825 */ { MAD_F(0x04dffb20) /* 0.304682850 */, 17 },
- /* 2826 */ { MAD_F(0x04e091ec) /* 0.304826662 */, 17 },
- /* 2827 */ { MAD_F(0x04e128bc) /* 0.304970491 */, 17 },
- /* 2828 */ { MAD_F(0x04e1bf92) /* 0.305114336 */, 17 },
- /* 2829 */ { MAD_F(0x04e2566b) /* 0.305258199 */, 17 },
- /* 2830 */ { MAD_F(0x04e2ed4a) /* 0.305402078 */, 17 },
- /* 2831 */ { MAD_F(0x04e3842d) /* 0.305545974 */, 17 },
-
- /* 2832 */ { MAD_F(0x04e41b14) /* 0.305689888 */, 17 },
- /* 2833 */ { MAD_F(0x04e4b200) /* 0.305833818 */, 17 },
- /* 2834 */ { MAD_F(0x04e548f1) /* 0.305977765 */, 17 },
- /* 2835 */ { MAD_F(0x04e5dfe6) /* 0.306121729 */, 17 },
- /* 2836 */ { MAD_F(0x04e676df) /* 0.306265710 */, 17 },
- /* 2837 */ { MAD_F(0x04e70dde) /* 0.306409708 */, 17 },
- /* 2838 */ { MAD_F(0x04e7a4e0) /* 0.306553723 */, 17 },
- /* 2839 */ { MAD_F(0x04e83be7) /* 0.306697755 */, 17 },
- /* 2840 */ { MAD_F(0x04e8d2f3) /* 0.306841804 */, 17 },
- /* 2841 */ { MAD_F(0x04e96a04) /* 0.306985869 */, 17 },
- /* 2842 */ { MAD_F(0x04ea0118) /* 0.307129952 */, 17 },
- /* 2843 */ { MAD_F(0x04ea9832) /* 0.307274051 */, 17 },
- /* 2844 */ { MAD_F(0x04eb2f50) /* 0.307418168 */, 17 },
- /* 2845 */ { MAD_F(0x04ebc672) /* 0.307562301 */, 17 },
- /* 2846 */ { MAD_F(0x04ec5d99) /* 0.307706451 */, 17 },
- /* 2847 */ { MAD_F(0x04ecf4c5) /* 0.307850618 */, 17 },
-
- /* 2848 */ { MAD_F(0x04ed8bf5) /* 0.307994802 */, 17 },
- /* 2849 */ { MAD_F(0x04ee2329) /* 0.308139003 */, 17 },
- /* 2850 */ { MAD_F(0x04eeba63) /* 0.308283220 */, 17 },
- /* 2851 */ { MAD_F(0x04ef51a0) /* 0.308427455 */, 17 },
- /* 2852 */ { MAD_F(0x04efe8e2) /* 0.308571706 */, 17 },
- /* 2853 */ { MAD_F(0x04f08029) /* 0.308715974 */, 17 },
- /* 2854 */ { MAD_F(0x04f11774) /* 0.308860260 */, 17 },
- /* 2855 */ { MAD_F(0x04f1aec4) /* 0.309004561 */, 17 },
- /* 2856 */ { MAD_F(0x04f24618) /* 0.309148880 */, 17 },
- /* 2857 */ { MAD_F(0x04f2dd71) /* 0.309293216 */, 17 },
- /* 2858 */ { MAD_F(0x04f374cf) /* 0.309437568 */, 17 },
- /* 2859 */ { MAD_F(0x04f40c30) /* 0.309581938 */, 17 },
- /* 2860 */ { MAD_F(0x04f4a397) /* 0.309726324 */, 17 },
- /* 2861 */ { MAD_F(0x04f53b02) /* 0.309870727 */, 17 },
- /* 2862 */ { MAD_F(0x04f5d271) /* 0.310015147 */, 17 },
- /* 2863 */ { MAD_F(0x04f669e5) /* 0.310159583 */, 17 },
-
- /* 2864 */ { MAD_F(0x04f7015d) /* 0.310304037 */, 17 },
- /* 2865 */ { MAD_F(0x04f798da) /* 0.310448507 */, 17 },
- /* 2866 */ { MAD_F(0x04f8305c) /* 0.310592994 */, 17 },
- /* 2867 */ { MAD_F(0x04f8c7e2) /* 0.310737498 */, 17 },
- /* 2868 */ { MAD_F(0x04f95f6c) /* 0.310882018 */, 17 },
- /* 2869 */ { MAD_F(0x04f9f6fb) /* 0.311026556 */, 17 },
- /* 2870 */ { MAD_F(0x04fa8e8f) /* 0.311171110 */, 17 },
- /* 2871 */ { MAD_F(0x04fb2627) /* 0.311315681 */, 17 },
- /* 2872 */ { MAD_F(0x04fbbdc3) /* 0.311460269 */, 17 },
- /* 2873 */ { MAD_F(0x04fc5564) /* 0.311604874 */, 17 },
- /* 2874 */ { MAD_F(0x04fced0a) /* 0.311749495 */, 17 },
- /* 2875 */ { MAD_F(0x04fd84b4) /* 0.311894133 */, 17 },
- /* 2876 */ { MAD_F(0x04fe1c62) /* 0.312038788 */, 17 },
- /* 2877 */ { MAD_F(0x04feb415) /* 0.312183460 */, 17 },
- /* 2878 */ { MAD_F(0x04ff4bcd) /* 0.312328148 */, 17 },
- /* 2879 */ { MAD_F(0x04ffe389) /* 0.312472854 */, 17 },
-
- /* 2880 */ { MAD_F(0x05007b49) /* 0.312617576 */, 17 },
- /* 2881 */ { MAD_F(0x0501130e) /* 0.312762314 */, 17 },
- /* 2882 */ { MAD_F(0x0501aad8) /* 0.312907070 */, 17 },
- /* 2883 */ { MAD_F(0x050242a6) /* 0.313051842 */, 17 },
- /* 2884 */ { MAD_F(0x0502da78) /* 0.313196631 */, 17 },
- /* 2885 */ { MAD_F(0x0503724f) /* 0.313341437 */, 17 },
- /* 2886 */ { MAD_F(0x05040a2b) /* 0.313486259 */, 17 },
- /* 2887 */ { MAD_F(0x0504a20b) /* 0.313631098 */, 17 },
- /* 2888 */ { MAD_F(0x050539ef) /* 0.313775954 */, 17 },
- /* 2889 */ { MAD_F(0x0505d1d8) /* 0.313920827 */, 17 },
- /* 2890 */ { MAD_F(0x050669c5) /* 0.314065716 */, 17 },
- /* 2891 */ { MAD_F(0x050701b7) /* 0.314210622 */, 17 },
- /* 2892 */ { MAD_F(0x050799ae) /* 0.314355545 */, 17 },
- /* 2893 */ { MAD_F(0x050831a9) /* 0.314500484 */, 17 },
- /* 2894 */ { MAD_F(0x0508c9a8) /* 0.314645440 */, 17 },
- /* 2895 */ { MAD_F(0x050961ac) /* 0.314790413 */, 17 },
-
- /* 2896 */ { MAD_F(0x0509f9b4) /* 0.314935403 */, 17 },
- /* 2897 */ { MAD_F(0x050a91c1) /* 0.315080409 */, 17 },
- /* 2898 */ { MAD_F(0x050b29d2) /* 0.315225432 */, 17 },
- /* 2899 */ { MAD_F(0x050bc1e8) /* 0.315370472 */, 17 },
- /* 2900 */ { MAD_F(0x050c5a02) /* 0.315515528 */, 17 },
- /* 2901 */ { MAD_F(0x050cf221) /* 0.315660601 */, 17 },
- /* 2902 */ { MAD_F(0x050d8a44) /* 0.315805690 */, 17 },
- /* 2903 */ { MAD_F(0x050e226c) /* 0.315950797 */, 17 },
- /* 2904 */ { MAD_F(0x050eba98) /* 0.316095920 */, 17 },
- /* 2905 */ { MAD_F(0x050f52c9) /* 0.316241059 */, 17 },
- /* 2906 */ { MAD_F(0x050feafe) /* 0.316386216 */, 17 },
- /* 2907 */ { MAD_F(0x05108337) /* 0.316531388 */, 17 },
- /* 2908 */ { MAD_F(0x05111b75) /* 0.316676578 */, 17 },
- /* 2909 */ { MAD_F(0x0511b3b8) /* 0.316821784 */, 17 },
- /* 2910 */ { MAD_F(0x05124bff) /* 0.316967007 */, 17 },
- /* 2911 */ { MAD_F(0x0512e44a) /* 0.317112247 */, 17 },
-
- /* 2912 */ { MAD_F(0x05137c9a) /* 0.317257503 */, 17 },
- /* 2913 */ { MAD_F(0x051414ee) /* 0.317402775 */, 17 },
- /* 2914 */ { MAD_F(0x0514ad47) /* 0.317548065 */, 17 },
- /* 2915 */ { MAD_F(0x051545a5) /* 0.317693371 */, 17 },
- /* 2916 */ { MAD_F(0x0515de06) /* 0.317838693 */, 17 },
- /* 2917 */ { MAD_F(0x0516766d) /* 0.317984033 */, 17 },
- /* 2918 */ { MAD_F(0x05170ed7) /* 0.318129388 */, 17 },
- /* 2919 */ { MAD_F(0x0517a746) /* 0.318274761 */, 17 },
- /* 2920 */ { MAD_F(0x05183fba) /* 0.318420150 */, 17 },
- /* 2921 */ { MAD_F(0x0518d832) /* 0.318565555 */, 17 },
- /* 2922 */ { MAD_F(0x051970ae) /* 0.318710978 */, 17 },
- /* 2923 */ { MAD_F(0x051a092f) /* 0.318856416 */, 17 },
- /* 2924 */ { MAD_F(0x051aa1b5) /* 0.319001872 */, 17 },
- /* 2925 */ { MAD_F(0x051b3a3f) /* 0.319147344 */, 17 },
- /* 2926 */ { MAD_F(0x051bd2cd) /* 0.319292832 */, 17 },
- /* 2927 */ { MAD_F(0x051c6b60) /* 0.319438338 */, 17 },
-
- /* 2928 */ { MAD_F(0x051d03f7) /* 0.319583859 */, 17 },
- /* 2929 */ { MAD_F(0x051d9c92) /* 0.319729398 */, 17 },
- /* 2930 */ { MAD_F(0x051e3532) /* 0.319874952 */, 17 },
- /* 2931 */ { MAD_F(0x051ecdd7) /* 0.320020524 */, 17 },
- /* 2932 */ { MAD_F(0x051f6680) /* 0.320166112 */, 17 },
- /* 2933 */ { MAD_F(0x051fff2d) /* 0.320311716 */, 17 },
- /* 2934 */ { MAD_F(0x052097df) /* 0.320457337 */, 17 },
- /* 2935 */ { MAD_F(0x05213095) /* 0.320602975 */, 17 },
- /* 2936 */ { MAD_F(0x0521c950) /* 0.320748629 */, 17 },
- /* 2937 */ { MAD_F(0x0522620f) /* 0.320894300 */, 17 },
- /* 2938 */ { MAD_F(0x0522fad3) /* 0.321039987 */, 17 },
- /* 2939 */ { MAD_F(0x0523939b) /* 0.321185691 */, 17 },
- /* 2940 */ { MAD_F(0x05242c68) /* 0.321331411 */, 17 },
- /* 2941 */ { MAD_F(0x0524c538) /* 0.321477148 */, 17 },
- /* 2942 */ { MAD_F(0x05255e0e) /* 0.321622901 */, 17 },
- /* 2943 */ { MAD_F(0x0525f6e8) /* 0.321768671 */, 17 },
-
- /* 2944 */ { MAD_F(0x05268fc6) /* 0.321914457 */, 17 },
- /* 2945 */ { MAD_F(0x052728a9) /* 0.322060260 */, 17 },
- /* 2946 */ { MAD_F(0x0527c190) /* 0.322206079 */, 17 },
- /* 2947 */ { MAD_F(0x05285a7b) /* 0.322351915 */, 17 },
- /* 2948 */ { MAD_F(0x0528f36b) /* 0.322497768 */, 17 },
- /* 2949 */ { MAD_F(0x05298c5f) /* 0.322643636 */, 17 },
- /* 2950 */ { MAD_F(0x052a2558) /* 0.322789522 */, 17 },
- /* 2951 */ { MAD_F(0x052abe55) /* 0.322935424 */, 17 },
- /* 2952 */ { MAD_F(0x052b5757) /* 0.323081342 */, 17 },
- /* 2953 */ { MAD_F(0x052bf05d) /* 0.323227277 */, 17 },
- /* 2954 */ { MAD_F(0x052c8968) /* 0.323373228 */, 17 },
- /* 2955 */ { MAD_F(0x052d2277) /* 0.323519196 */, 17 },
- /* 2956 */ { MAD_F(0x052dbb8a) /* 0.323665180 */, 17 },
- /* 2957 */ { MAD_F(0x052e54a2) /* 0.323811180 */, 17 },
- /* 2958 */ { MAD_F(0x052eedbe) /* 0.323957197 */, 17 },
- /* 2959 */ { MAD_F(0x052f86de) /* 0.324103231 */, 17 },
-
- /* 2960 */ { MAD_F(0x05302003) /* 0.324249281 */, 17 },
- /* 2961 */ { MAD_F(0x0530b92d) /* 0.324395347 */, 17 },
- /* 2962 */ { MAD_F(0x0531525b) /* 0.324541430 */, 17 },
- /* 2963 */ { MAD_F(0x0531eb8d) /* 0.324687530 */, 17 },
- /* 2964 */ { MAD_F(0x053284c4) /* 0.324833646 */, 17 },
- /* 2965 */ { MAD_F(0x05331dff) /* 0.324979778 */, 17 },
- /* 2966 */ { MAD_F(0x0533b73e) /* 0.325125926 */, 17 },
- /* 2967 */ { MAD_F(0x05345082) /* 0.325272091 */, 17 },
- /* 2968 */ { MAD_F(0x0534e9ca) /* 0.325418273 */, 17 },
- /* 2969 */ { MAD_F(0x05358317) /* 0.325564471 */, 17 },
- /* 2970 */ { MAD_F(0x05361c68) /* 0.325710685 */, 17 },
- /* 2971 */ { MAD_F(0x0536b5be) /* 0.325856916 */, 17 },
- /* 2972 */ { MAD_F(0x05374f17) /* 0.326003163 */, 17 },
- /* 2973 */ { MAD_F(0x0537e876) /* 0.326149427 */, 17 },
- /* 2974 */ { MAD_F(0x053881d9) /* 0.326295707 */, 17 },
- /* 2975 */ { MAD_F(0x05391b40) /* 0.326442003 */, 17 },
-
- /* 2976 */ { MAD_F(0x0539b4ab) /* 0.326588316 */, 17 },
- /* 2977 */ { MAD_F(0x053a4e1b) /* 0.326734645 */, 17 },
- /* 2978 */ { MAD_F(0x053ae78f) /* 0.326880990 */, 17 },
- /* 2979 */ { MAD_F(0x053b8108) /* 0.327027352 */, 17 },
- /* 2980 */ { MAD_F(0x053c1a85) /* 0.327173730 */, 17 },
- /* 2981 */ { MAD_F(0x053cb407) /* 0.327320125 */, 17 },
- /* 2982 */ { MAD_F(0x053d4d8d) /* 0.327466536 */, 17 },
- /* 2983 */ { MAD_F(0x053de717) /* 0.327612963 */, 17 },
- /* 2984 */ { MAD_F(0x053e80a6) /* 0.327759407 */, 17 },
- /* 2985 */ { MAD_F(0x053f1a39) /* 0.327905867 */, 17 },
- /* 2986 */ { MAD_F(0x053fb3d0) /* 0.328052344 */, 17 },
- /* 2987 */ { MAD_F(0x05404d6c) /* 0.328198837 */, 17 },
- /* 2988 */ { MAD_F(0x0540e70c) /* 0.328345346 */, 17 },
- /* 2989 */ { MAD_F(0x054180b1) /* 0.328491871 */, 17 },
- /* 2990 */ { MAD_F(0x05421a5a) /* 0.328638413 */, 17 },
- /* 2991 */ { MAD_F(0x0542b407) /* 0.328784971 */, 17 },
-
- /* 2992 */ { MAD_F(0x05434db9) /* 0.328931546 */, 17 },
- /* 2993 */ { MAD_F(0x0543e76f) /* 0.329078137 */, 17 },
- /* 2994 */ { MAD_F(0x0544812a) /* 0.329224744 */, 17 },
- /* 2995 */ { MAD_F(0x05451ae9) /* 0.329371367 */, 17 },
- /* 2996 */ { MAD_F(0x0545b4ac) /* 0.329518007 */, 17 },
- /* 2997 */ { MAD_F(0x05464e74) /* 0.329664663 */, 17 },
- /* 2998 */ { MAD_F(0x0546e840) /* 0.329811336 */, 17 },
- /* 2999 */ { MAD_F(0x05478211) /* 0.329958024 */, 17 },
- /* 3000 */ { MAD_F(0x05481be5) /* 0.330104730 */, 17 },
- /* 3001 */ { MAD_F(0x0548b5bf) /* 0.330251451 */, 17 },
- /* 3002 */ { MAD_F(0x05494f9c) /* 0.330398189 */, 17 },
- /* 3003 */ { MAD_F(0x0549e97e) /* 0.330544943 */, 17 },
- /* 3004 */ { MAD_F(0x054a8364) /* 0.330691713 */, 17 },
- /* 3005 */ { MAD_F(0x054b1d4f) /* 0.330838499 */, 17 },
- /* 3006 */ { MAD_F(0x054bb73e) /* 0.330985302 */, 17 },
- /* 3007 */ { MAD_F(0x054c5132) /* 0.331132121 */, 17 },
-
- /* 3008 */ { MAD_F(0x054ceb2a) /* 0.331278957 */, 17 },
- /* 3009 */ { MAD_F(0x054d8526) /* 0.331425808 */, 17 },
- /* 3010 */ { MAD_F(0x054e1f26) /* 0.331572676 */, 17 },
- /* 3011 */ { MAD_F(0x054eb92b) /* 0.331719560 */, 17 },
- /* 3012 */ { MAD_F(0x054f5334) /* 0.331866461 */, 17 },
- /* 3013 */ { MAD_F(0x054fed42) /* 0.332013377 */, 17 },
- /* 3014 */ { MAD_F(0x05508754) /* 0.332160310 */, 17 },
- /* 3015 */ { MAD_F(0x0551216b) /* 0.332307260 */, 17 },
- /* 3016 */ { MAD_F(0x0551bb85) /* 0.332454225 */, 17 },
- /* 3017 */ { MAD_F(0x055255a4) /* 0.332601207 */, 17 },
- /* 3018 */ { MAD_F(0x0552efc8) /* 0.332748205 */, 17 },
- /* 3019 */ { MAD_F(0x055389f0) /* 0.332895219 */, 17 },
- /* 3020 */ { MAD_F(0x0554241c) /* 0.333042249 */, 17 },
- /* 3021 */ { MAD_F(0x0554be4c) /* 0.333189296 */, 17 },
- /* 3022 */ { MAD_F(0x05555881) /* 0.333336359 */, 17 },
- /* 3023 */ { MAD_F(0x0555f2ba) /* 0.333483438 */, 17 },
-
- /* 3024 */ { MAD_F(0x05568cf8) /* 0.333630533 */, 17 },
- /* 3025 */ { MAD_F(0x0557273a) /* 0.333777645 */, 17 },
- /* 3026 */ { MAD_F(0x0557c180) /* 0.333924772 */, 17 },
- /* 3027 */ { MAD_F(0x05585bcb) /* 0.334071916 */, 17 },
- /* 3028 */ { MAD_F(0x0558f61a) /* 0.334219076 */, 17 },
- /* 3029 */ { MAD_F(0x0559906d) /* 0.334366253 */, 17 },
- /* 3030 */ { MAD_F(0x055a2ac5) /* 0.334513445 */, 17 },
- /* 3031 */ { MAD_F(0x055ac521) /* 0.334660654 */, 17 },
- /* 3032 */ { MAD_F(0x055b5f81) /* 0.334807879 */, 17 },
- /* 3033 */ { MAD_F(0x055bf9e6) /* 0.334955120 */, 17 },
- /* 3034 */ { MAD_F(0x055c944f) /* 0.335102377 */, 17 },
- /* 3035 */ { MAD_F(0x055d2ebd) /* 0.335249651 */, 17 },
- /* 3036 */ { MAD_F(0x055dc92e) /* 0.335396941 */, 17 },
- /* 3037 */ { MAD_F(0x055e63a5) /* 0.335544246 */, 17 },
- /* 3038 */ { MAD_F(0x055efe1f) /* 0.335691568 */, 17 },
- /* 3039 */ { MAD_F(0x055f989e) /* 0.335838906 */, 17 },
-
- /* 3040 */ { MAD_F(0x05603321) /* 0.335986261 */, 17 },
- /* 3041 */ { MAD_F(0x0560cda8) /* 0.336133631 */, 17 },
- /* 3042 */ { MAD_F(0x05616834) /* 0.336281018 */, 17 },
- /* 3043 */ { MAD_F(0x056202c4) /* 0.336428421 */, 17 },
- /* 3044 */ { MAD_F(0x05629d59) /* 0.336575840 */, 17 },
- /* 3045 */ { MAD_F(0x056337f2) /* 0.336723275 */, 17 },
- /* 3046 */ { MAD_F(0x0563d28f) /* 0.336870726 */, 17 },
- /* 3047 */ { MAD_F(0x05646d30) /* 0.337018193 */, 17 },
- /* 3048 */ { MAD_F(0x056507d6) /* 0.337165677 */, 17 },
- /* 3049 */ { MAD_F(0x0565a280) /* 0.337313176 */, 17 },
- /* 3050 */ { MAD_F(0x05663d2f) /* 0.337460692 */, 17 },
- /* 3051 */ { MAD_F(0x0566d7e1) /* 0.337608224 */, 17 },
- /* 3052 */ { MAD_F(0x05677298) /* 0.337755772 */, 17 },
- /* 3053 */ { MAD_F(0x05680d54) /* 0.337903336 */, 17 },
- /* 3054 */ { MAD_F(0x0568a814) /* 0.338050916 */, 17 },
- /* 3055 */ { MAD_F(0x056942d8) /* 0.338198513 */, 17 },
-
- /* 3056 */ { MAD_F(0x0569dda0) /* 0.338346125 */, 17 },
- /* 3057 */ { MAD_F(0x056a786d) /* 0.338493753 */, 17 },
- /* 3058 */ { MAD_F(0x056b133e) /* 0.338641398 */, 17 },
- /* 3059 */ { MAD_F(0x056bae13) /* 0.338789059 */, 17 },
- /* 3060 */ { MAD_F(0x056c48ed) /* 0.338936736 */, 17 },
- /* 3061 */ { MAD_F(0x056ce3cb) /* 0.339084429 */, 17 },
- /* 3062 */ { MAD_F(0x056d7ead) /* 0.339232138 */, 17 },
- /* 3063 */ { MAD_F(0x056e1994) /* 0.339379863 */, 17 },
- /* 3064 */ { MAD_F(0x056eb47f) /* 0.339527604 */, 17 },
- /* 3065 */ { MAD_F(0x056f4f6e) /* 0.339675361 */, 17 },
- /* 3066 */ { MAD_F(0x056fea62) /* 0.339823134 */, 17 },
- /* 3067 */ { MAD_F(0x0570855a) /* 0.339970924 */, 17 },
- /* 3068 */ { MAD_F(0x05712056) /* 0.340118729 */, 17 },
- /* 3069 */ { MAD_F(0x0571bb56) /* 0.340266550 */, 17 },
- /* 3070 */ { MAD_F(0x0572565b) /* 0.340414388 */, 17 },
- /* 3071 */ { MAD_F(0x0572f164) /* 0.340562242 */, 17 },
-
- /* 3072 */ { MAD_F(0x05738c72) /* 0.340710111 */, 17 },
- /* 3073 */ { MAD_F(0x05742784) /* 0.340857997 */, 17 },
- /* 3074 */ { MAD_F(0x0574c29a) /* 0.341005899 */, 17 },
- /* 3075 */ { MAD_F(0x05755db4) /* 0.341153816 */, 17 },
- /* 3076 */ { MAD_F(0x0575f8d3) /* 0.341301750 */, 17 },
- /* 3077 */ { MAD_F(0x057693f6) /* 0.341449700 */, 17 },
- /* 3078 */ { MAD_F(0x05772f1d) /* 0.341597666 */, 17 },
- /* 3079 */ { MAD_F(0x0577ca49) /* 0.341745648 */, 17 },
- /* 3080 */ { MAD_F(0x05786578) /* 0.341893646 */, 17 },
- /* 3081 */ { MAD_F(0x057900ad) /* 0.342041659 */, 17 },
- /* 3082 */ { MAD_F(0x05799be5) /* 0.342189689 */, 17 },
- /* 3083 */ { MAD_F(0x057a3722) /* 0.342337735 */, 17 },
- /* 3084 */ { MAD_F(0x057ad263) /* 0.342485797 */, 17 },
- /* 3085 */ { MAD_F(0x057b6da8) /* 0.342633875 */, 17 },
- /* 3086 */ { MAD_F(0x057c08f2) /* 0.342781969 */, 17 },
- /* 3087 */ { MAD_F(0x057ca440) /* 0.342930079 */, 17 },
-
- /* 3088 */ { MAD_F(0x057d3f92) /* 0.343078205 */, 17 },
- /* 3089 */ { MAD_F(0x057ddae9) /* 0.343226347 */, 17 },
- /* 3090 */ { MAD_F(0x057e7644) /* 0.343374505 */, 17 },
- /* 3091 */ { MAD_F(0x057f11a3) /* 0.343522679 */, 17 },
- /* 3092 */ { MAD_F(0x057fad06) /* 0.343670869 */, 17 },
- /* 3093 */ { MAD_F(0x0580486e) /* 0.343819075 */, 17 },
- /* 3094 */ { MAD_F(0x0580e3da) /* 0.343967296 */, 17 },
- /* 3095 */ { MAD_F(0x05817f4a) /* 0.344115534 */, 17 },
- /* 3096 */ { MAD_F(0x05821abf) /* 0.344263788 */, 17 },
- /* 3097 */ { MAD_F(0x0582b638) /* 0.344412058 */, 17 },
- /* 3098 */ { MAD_F(0x058351b5) /* 0.344560343 */, 17 },
- /* 3099 */ { MAD_F(0x0583ed36) /* 0.344708645 */, 17 },
- /* 3100 */ { MAD_F(0x058488bc) /* 0.344856963 */, 17 },
- /* 3101 */ { MAD_F(0x05852446) /* 0.345005296 */, 17 },
- /* 3102 */ { MAD_F(0x0585bfd4) /* 0.345153646 */, 17 },
- /* 3103 */ { MAD_F(0x05865b67) /* 0.345302011 */, 17 },
-
- /* 3104 */ { MAD_F(0x0586f6fd) /* 0.345450393 */, 17 },
- /* 3105 */ { MAD_F(0x05879298) /* 0.345598790 */, 17 },
- /* 3106 */ { MAD_F(0x05882e38) /* 0.345747203 */, 17 },
- /* 3107 */ { MAD_F(0x0588c9dc) /* 0.345895632 */, 17 },
- /* 3108 */ { MAD_F(0x05896583) /* 0.346044077 */, 17 },
- /* 3109 */ { MAD_F(0x058a0130) /* 0.346192538 */, 17 },
- /* 3110 */ { MAD_F(0x058a9ce0) /* 0.346341015 */, 17 },
- /* 3111 */ { MAD_F(0x058b3895) /* 0.346489508 */, 17 },
- /* 3112 */ { MAD_F(0x058bd44e) /* 0.346638017 */, 17 },
- /* 3113 */ { MAD_F(0x058c700b) /* 0.346786542 */, 17 },
- /* 3114 */ { MAD_F(0x058d0bcd) /* 0.346935082 */, 17 },
- /* 3115 */ { MAD_F(0x058da793) /* 0.347083639 */, 17 },
- /* 3116 */ { MAD_F(0x058e435d) /* 0.347232211 */, 17 },
- /* 3117 */ { MAD_F(0x058edf2b) /* 0.347380799 */, 17 },
- /* 3118 */ { MAD_F(0x058f7afe) /* 0.347529403 */, 17 },
- /* 3119 */ { MAD_F(0x059016d5) /* 0.347678023 */, 17 },
-
- /* 3120 */ { MAD_F(0x0590b2b0) /* 0.347826659 */, 17 },
- /* 3121 */ { MAD_F(0x05914e8f) /* 0.347975311 */, 17 },
- /* 3122 */ { MAD_F(0x0591ea73) /* 0.348123979 */, 17 },
- /* 3123 */ { MAD_F(0x0592865b) /* 0.348272662 */, 17 },
- /* 3124 */ { MAD_F(0x05932247) /* 0.348421362 */, 17 },
- /* 3125 */ { MAD_F(0x0593be37) /* 0.348570077 */, 17 },
- /* 3126 */ { MAD_F(0x05945a2c) /* 0.348718808 */, 17 },
- /* 3127 */ { MAD_F(0x0594f625) /* 0.348867555 */, 17 },
- /* 3128 */ { MAD_F(0x05959222) /* 0.349016318 */, 17 },
- /* 3129 */ { MAD_F(0x05962e24) /* 0.349165097 */, 17 },
- /* 3130 */ { MAD_F(0x0596ca2a) /* 0.349313892 */, 17 },
- /* 3131 */ { MAD_F(0x05976634) /* 0.349462702 */, 17 },
- /* 3132 */ { MAD_F(0x05980242) /* 0.349611528 */, 17 },
- /* 3133 */ { MAD_F(0x05989e54) /* 0.349760370 */, 17 },
- /* 3134 */ { MAD_F(0x05993a6b) /* 0.349909228 */, 17 },
- /* 3135 */ { MAD_F(0x0599d686) /* 0.350058102 */, 17 },
-
- /* 3136 */ { MAD_F(0x059a72a5) /* 0.350206992 */, 17 },
- /* 3137 */ { MAD_F(0x059b0ec9) /* 0.350355897 */, 17 },
- /* 3138 */ { MAD_F(0x059baaf1) /* 0.350504818 */, 17 },
- /* 3139 */ { MAD_F(0x059c471d) /* 0.350653756 */, 17 },
- /* 3140 */ { MAD_F(0x059ce34d) /* 0.350802708 */, 17 },
- /* 3141 */ { MAD_F(0x059d7f81) /* 0.350951677 */, 17 },
- /* 3142 */ { MAD_F(0x059e1bba) /* 0.351100662 */, 17 },
- /* 3143 */ { MAD_F(0x059eb7f7) /* 0.351249662 */, 17 },
- /* 3144 */ { MAD_F(0x059f5438) /* 0.351398678 */, 17 },
- /* 3145 */ { MAD_F(0x059ff07e) /* 0.351547710 */, 17 },
- /* 3146 */ { MAD_F(0x05a08cc7) /* 0.351696758 */, 17 },
- /* 3147 */ { MAD_F(0x05a12915) /* 0.351845821 */, 17 },
- /* 3148 */ { MAD_F(0x05a1c567) /* 0.351994901 */, 17 },
- /* 3149 */ { MAD_F(0x05a261be) /* 0.352143996 */, 17 },
- /* 3150 */ { MAD_F(0x05a2fe18) /* 0.352293107 */, 17 },
- /* 3151 */ { MAD_F(0x05a39a77) /* 0.352442233 */, 17 },
-
- /* 3152 */ { MAD_F(0x05a436da) /* 0.352591376 */, 17 },
- /* 3153 */ { MAD_F(0x05a4d342) /* 0.352740534 */, 17 },
- /* 3154 */ { MAD_F(0x05a56fad) /* 0.352889708 */, 17 },
- /* 3155 */ { MAD_F(0x05a60c1d) /* 0.353038898 */, 17 },
- /* 3156 */ { MAD_F(0x05a6a891) /* 0.353188103 */, 17 },
- /* 3157 */ { MAD_F(0x05a7450a) /* 0.353337325 */, 17 },
- /* 3158 */ { MAD_F(0x05a7e186) /* 0.353486562 */, 17 },
- /* 3159 */ { MAD_F(0x05a87e07) /* 0.353635814 */, 17 },
- /* 3160 */ { MAD_F(0x05a91a8c) /* 0.353785083 */, 17 },
- /* 3161 */ { MAD_F(0x05a9b715) /* 0.353934367 */, 17 },
- /* 3162 */ { MAD_F(0x05aa53a2) /* 0.354083667 */, 17 },
- /* 3163 */ { MAD_F(0x05aaf034) /* 0.354232983 */, 17 },
- /* 3164 */ { MAD_F(0x05ab8cca) /* 0.354382314 */, 17 },
- /* 3165 */ { MAD_F(0x05ac2964) /* 0.354531662 */, 17 },
- /* 3166 */ { MAD_F(0x05acc602) /* 0.354681025 */, 17 },
- /* 3167 */ { MAD_F(0x05ad62a5) /* 0.354830403 */, 17 },
-
- /* 3168 */ { MAD_F(0x05adff4c) /* 0.354979798 */, 17 },
- /* 3169 */ { MAD_F(0x05ae9bf7) /* 0.355129208 */, 17 },
- /* 3170 */ { MAD_F(0x05af38a6) /* 0.355278634 */, 17 },
- /* 3171 */ { MAD_F(0x05afd559) /* 0.355428075 */, 17 },
- /* 3172 */ { MAD_F(0x05b07211) /* 0.355577533 */, 17 },
- /* 3173 */ { MAD_F(0x05b10ecd) /* 0.355727006 */, 17 },
- /* 3174 */ { MAD_F(0x05b1ab8d) /* 0.355876494 */, 17 },
- /* 3175 */ { MAD_F(0x05b24851) /* 0.356025999 */, 17 },
- /* 3176 */ { MAD_F(0x05b2e51a) /* 0.356175519 */, 17 },
- /* 3177 */ { MAD_F(0x05b381e6) /* 0.356325054 */, 17 },
- /* 3178 */ { MAD_F(0x05b41eb7) /* 0.356474606 */, 17 },
- /* 3179 */ { MAD_F(0x05b4bb8c) /* 0.356624173 */, 17 },
- /* 3180 */ { MAD_F(0x05b55866) /* 0.356773756 */, 17 },
- /* 3181 */ { MAD_F(0x05b5f543) /* 0.356923354 */, 17 },
- /* 3182 */ { MAD_F(0x05b69225) /* 0.357072969 */, 17 },
- /* 3183 */ { MAD_F(0x05b72f0b) /* 0.357222598 */, 17 },
-
- /* 3184 */ { MAD_F(0x05b7cbf5) /* 0.357372244 */, 17 },
- /* 3185 */ { MAD_F(0x05b868e3) /* 0.357521905 */, 17 },
- /* 3186 */ { MAD_F(0x05b905d6) /* 0.357671582 */, 17 },
- /* 3187 */ { MAD_F(0x05b9a2cd) /* 0.357821275 */, 17 },
- /* 3188 */ { MAD_F(0x05ba3fc8) /* 0.357970983 */, 17 },
- /* 3189 */ { MAD_F(0x05badcc7) /* 0.358120707 */, 17 },
- /* 3190 */ { MAD_F(0x05bb79ca) /* 0.358270446 */, 17 },
- /* 3191 */ { MAD_F(0x05bc16d2) /* 0.358420201 */, 17 },
- /* 3192 */ { MAD_F(0x05bcb3de) /* 0.358569972 */, 17 },
- /* 3193 */ { MAD_F(0x05bd50ee) /* 0.358719758 */, 17 },
- /* 3194 */ { MAD_F(0x05bdee02) /* 0.358869560 */, 17 },
- /* 3195 */ { MAD_F(0x05be8b1a) /* 0.359019378 */, 17 },
- /* 3196 */ { MAD_F(0x05bf2837) /* 0.359169211 */, 17 },
- /* 3197 */ { MAD_F(0x05bfc558) /* 0.359319060 */, 17 },
- /* 3198 */ { MAD_F(0x05c0627d) /* 0.359468925 */, 17 },
- /* 3199 */ { MAD_F(0x05c0ffa6) /* 0.359618805 */, 17 },
-
- /* 3200 */ { MAD_F(0x05c19cd3) /* 0.359768701 */, 17 },
- /* 3201 */ { MAD_F(0x05c23a05) /* 0.359918612 */, 17 },
- /* 3202 */ { MAD_F(0x05c2d73a) /* 0.360068540 */, 17 },
- /* 3203 */ { MAD_F(0x05c37474) /* 0.360218482 */, 17 },
- /* 3204 */ { MAD_F(0x05c411b2) /* 0.360368440 */, 17 },
- /* 3205 */ { MAD_F(0x05c4aef5) /* 0.360518414 */, 17 },
- /* 3206 */ { MAD_F(0x05c54c3b) /* 0.360668404 */, 17 },
- /* 3207 */ { MAD_F(0x05c5e986) /* 0.360818409 */, 17 },
- /* 3208 */ { MAD_F(0x05c686d5) /* 0.360968429 */, 17 },
- /* 3209 */ { MAD_F(0x05c72428) /* 0.361118466 */, 17 },
- /* 3210 */ { MAD_F(0x05c7c17f) /* 0.361268517 */, 17 },
- /* 3211 */ { MAD_F(0x05c85eda) /* 0.361418585 */, 17 },
- /* 3212 */ { MAD_F(0x05c8fc3a) /* 0.361568668 */, 17 },
- /* 3213 */ { MAD_F(0x05c9999e) /* 0.361718766 */, 17 },
- /* 3214 */ { MAD_F(0x05ca3706) /* 0.361868881 */, 17 },
- /* 3215 */ { MAD_F(0x05cad472) /* 0.362019010 */, 17 },
-
- /* 3216 */ { MAD_F(0x05cb71e2) /* 0.362169156 */, 17 },
- /* 3217 */ { MAD_F(0x05cc0f57) /* 0.362319316 */, 17 },
- /* 3218 */ { MAD_F(0x05ccaccf) /* 0.362469493 */, 17 },
- /* 3219 */ { MAD_F(0x05cd4a4c) /* 0.362619685 */, 17 },
- /* 3220 */ { MAD_F(0x05cde7cd) /* 0.362769892 */, 17 },
- /* 3221 */ { MAD_F(0x05ce8552) /* 0.362920115 */, 17 },
- /* 3222 */ { MAD_F(0x05cf22dc) /* 0.363070354 */, 17 },
- /* 3223 */ { MAD_F(0x05cfc069) /* 0.363220608 */, 17 },
- /* 3224 */ { MAD_F(0x05d05dfb) /* 0.363370878 */, 17 },
- /* 3225 */ { MAD_F(0x05d0fb91) /* 0.363521163 */, 17 },
- /* 3226 */ { MAD_F(0x05d1992b) /* 0.363671464 */, 17 },
- /* 3227 */ { MAD_F(0x05d236c9) /* 0.363821780 */, 17 },
- /* 3228 */ { MAD_F(0x05d2d46c) /* 0.363972112 */, 17 },
- /* 3229 */ { MAD_F(0x05d37212) /* 0.364122459 */, 17 },
- /* 3230 */ { MAD_F(0x05d40fbd) /* 0.364272822 */, 17 },
- /* 3231 */ { MAD_F(0x05d4ad6c) /* 0.364423200 */, 17 },
-
- /* 3232 */ { MAD_F(0x05d54b1f) /* 0.364573594 */, 17 },
- /* 3233 */ { MAD_F(0x05d5e8d6) /* 0.364724004 */, 17 },
- /* 3234 */ { MAD_F(0x05d68691) /* 0.364874429 */, 17 },
- /* 3235 */ { MAD_F(0x05d72451) /* 0.365024869 */, 17 },
- /* 3236 */ { MAD_F(0x05d7c215) /* 0.365175325 */, 17 },
- /* 3237 */ { MAD_F(0x05d85fdc) /* 0.365325796 */, 17 },
- /* 3238 */ { MAD_F(0x05d8fda8) /* 0.365476283 */, 17 },
- /* 3239 */ { MAD_F(0x05d99b79) /* 0.365626786 */, 17 },
- /* 3240 */ { MAD_F(0x05da394d) /* 0.365777304 */, 17 },
- /* 3241 */ { MAD_F(0x05dad726) /* 0.365927837 */, 17 },
- /* 3242 */ { MAD_F(0x05db7502) /* 0.366078386 */, 17 },
- /* 3243 */ { MAD_F(0x05dc12e3) /* 0.366228950 */, 17 },
- /* 3244 */ { MAD_F(0x05dcb0c8) /* 0.366379530 */, 17 },
- /* 3245 */ { MAD_F(0x05dd4eb1) /* 0.366530125 */, 17 },
- /* 3246 */ { MAD_F(0x05ddec9e) /* 0.366680736 */, 17 },
- /* 3247 */ { MAD_F(0x05de8a90) /* 0.366831362 */, 17 },
-
- /* 3248 */ { MAD_F(0x05df2885) /* 0.366982004 */, 17 },
- /* 3249 */ { MAD_F(0x05dfc67f) /* 0.367132661 */, 17 },
- /* 3250 */ { MAD_F(0x05e0647d) /* 0.367283334 */, 17 },
- /* 3251 */ { MAD_F(0x05e1027f) /* 0.367434022 */, 17 },
- /* 3252 */ { MAD_F(0x05e1a085) /* 0.367584725 */, 17 },
- /* 3253 */ { MAD_F(0x05e23e8f) /* 0.367735444 */, 17 },
- /* 3254 */ { MAD_F(0x05e2dc9e) /* 0.367886179 */, 17 },
- /* 3255 */ { MAD_F(0x05e37ab0) /* 0.368036929 */, 17 },
- /* 3256 */ { MAD_F(0x05e418c7) /* 0.368187694 */, 17 },
- /* 3257 */ { MAD_F(0x05e4b6e2) /* 0.368338475 */, 17 },
- /* 3258 */ { MAD_F(0x05e55501) /* 0.368489271 */, 17 },
- /* 3259 */ { MAD_F(0x05e5f324) /* 0.368640082 */, 17 },
- /* 3260 */ { MAD_F(0x05e6914c) /* 0.368790909 */, 17 },
- /* 3261 */ { MAD_F(0x05e72f77) /* 0.368941752 */, 17 },
- /* 3262 */ { MAD_F(0x05e7cda7) /* 0.369092610 */, 17 },
- /* 3263 */ { MAD_F(0x05e86bda) /* 0.369243483 */, 17 },
-
- /* 3264 */ { MAD_F(0x05e90a12) /* 0.369394372 */, 17 },
- /* 3265 */ { MAD_F(0x05e9a84e) /* 0.369545276 */, 17 },
- /* 3266 */ { MAD_F(0x05ea468e) /* 0.369696195 */, 17 },
- /* 3267 */ { MAD_F(0x05eae4d3) /* 0.369847130 */, 17 },
- /* 3268 */ { MAD_F(0x05eb831b) /* 0.369998080 */, 17 },
- /* 3269 */ { MAD_F(0x05ec2168) /* 0.370149046 */, 17 },
- /* 3270 */ { MAD_F(0x05ecbfb8) /* 0.370300027 */, 17 },
- /* 3271 */ { MAD_F(0x05ed5e0d) /* 0.370451024 */, 17 },
- /* 3272 */ { MAD_F(0x05edfc66) /* 0.370602036 */, 17 },
- /* 3273 */ { MAD_F(0x05ee9ac3) /* 0.370753063 */, 17 },
- /* 3274 */ { MAD_F(0x05ef3924) /* 0.370904105 */, 17 },
- /* 3275 */ { MAD_F(0x05efd78a) /* 0.371055163 */, 17 },
- /* 3276 */ { MAD_F(0x05f075f3) /* 0.371206237 */, 17 },
- /* 3277 */ { MAD_F(0x05f11461) /* 0.371357326 */, 17 },
- /* 3278 */ { MAD_F(0x05f1b2d3) /* 0.371508430 */, 17 },
- /* 3279 */ { MAD_F(0x05f25148) /* 0.371659549 */, 17 },
-
- /* 3280 */ { MAD_F(0x05f2efc2) /* 0.371810684 */, 17 },
- /* 3281 */ { MAD_F(0x05f38e40) /* 0.371961834 */, 17 },
- /* 3282 */ { MAD_F(0x05f42cc3) /* 0.372113000 */, 17 },
- /* 3283 */ { MAD_F(0x05f4cb49) /* 0.372264181 */, 17 },
- /* 3284 */ { MAD_F(0x05f569d3) /* 0.372415377 */, 17 },
- /* 3285 */ { MAD_F(0x05f60862) /* 0.372566589 */, 17 },
- /* 3286 */ { MAD_F(0x05f6a6f5) /* 0.372717816 */, 17 },
- /* 3287 */ { MAD_F(0x05f7458b) /* 0.372869058 */, 17 },
- /* 3288 */ { MAD_F(0x05f7e426) /* 0.373020316 */, 17 },
- /* 3289 */ { MAD_F(0x05f882c5) /* 0.373171589 */, 17 },
- /* 3290 */ { MAD_F(0x05f92169) /* 0.373322877 */, 17 },
- /* 3291 */ { MAD_F(0x05f9c010) /* 0.373474181 */, 17 },
- /* 3292 */ { MAD_F(0x05fa5ebb) /* 0.373625500 */, 17 },
- /* 3293 */ { MAD_F(0x05fafd6b) /* 0.373776834 */, 17 },
- /* 3294 */ { MAD_F(0x05fb9c1e) /* 0.373928184 */, 17 },
- /* 3295 */ { MAD_F(0x05fc3ad6) /* 0.374079549 */, 17 },
-
- /* 3296 */ { MAD_F(0x05fcd992) /* 0.374230929 */, 17 },
- /* 3297 */ { MAD_F(0x05fd7852) /* 0.374382325 */, 17 },
- /* 3298 */ { MAD_F(0x05fe1716) /* 0.374533735 */, 17 },
- /* 3299 */ { MAD_F(0x05feb5de) /* 0.374685162 */, 17 },
- /* 3300 */ { MAD_F(0x05ff54aa) /* 0.374836603 */, 17 },
- /* 3301 */ { MAD_F(0x05fff37b) /* 0.374988060 */, 17 },
- /* 3302 */ { MAD_F(0x0600924f) /* 0.375139532 */, 17 },
- /* 3303 */ { MAD_F(0x06013128) /* 0.375291019 */, 17 },
- /* 3304 */ { MAD_F(0x0601d004) /* 0.375442522 */, 17 },
- /* 3305 */ { MAD_F(0x06026ee5) /* 0.375594040 */, 17 },
- /* 3306 */ { MAD_F(0x06030dca) /* 0.375745573 */, 17 },
- /* 3307 */ { MAD_F(0x0603acb3) /* 0.375897122 */, 17 },
- /* 3308 */ { MAD_F(0x06044ba0) /* 0.376048685 */, 17 },
- /* 3309 */ { MAD_F(0x0604ea91) /* 0.376200265 */, 17 },
- /* 3310 */ { MAD_F(0x06058987) /* 0.376351859 */, 17 },
- /* 3311 */ { MAD_F(0x06062880) /* 0.376503468 */, 17 },
-
- /* 3312 */ { MAD_F(0x0606c77d) /* 0.376655093 */, 17 },
- /* 3313 */ { MAD_F(0x0607667f) /* 0.376806733 */, 17 },
- /* 3314 */ { MAD_F(0x06080585) /* 0.376958389 */, 17 },
- /* 3315 */ { MAD_F(0x0608a48f) /* 0.377110059 */, 17 },
- /* 3316 */ { MAD_F(0x0609439c) /* 0.377261745 */, 17 },
- /* 3317 */ { MAD_F(0x0609e2ae) /* 0.377413446 */, 17 },
- /* 3318 */ { MAD_F(0x060a81c4) /* 0.377565163 */, 17 },
- /* 3319 */ { MAD_F(0x060b20df) /* 0.377716894 */, 17 },
- /* 3320 */ { MAD_F(0x060bbffd) /* 0.377868641 */, 17 },
- /* 3321 */ { MAD_F(0x060c5f1f) /* 0.378020403 */, 17 },
- /* 3322 */ { MAD_F(0x060cfe46) /* 0.378172181 */, 17 },
- /* 3323 */ { MAD_F(0x060d9d70) /* 0.378323973 */, 17 },
- /* 3324 */ { MAD_F(0x060e3c9f) /* 0.378475781 */, 17 },
- /* 3325 */ { MAD_F(0x060edbd1) /* 0.378627604 */, 17 },
- /* 3326 */ { MAD_F(0x060f7b08) /* 0.378779442 */, 17 },
- /* 3327 */ { MAD_F(0x06101a43) /* 0.378931296 */, 17 },
-
- /* 3328 */ { MAD_F(0x0610b982) /* 0.379083164 */, 17 },
- /* 3329 */ { MAD_F(0x061158c5) /* 0.379235048 */, 17 },
- /* 3330 */ { MAD_F(0x0611f80c) /* 0.379386947 */, 17 },
- /* 3331 */ { MAD_F(0x06129757) /* 0.379538862 */, 17 },
- /* 3332 */ { MAD_F(0x061336a6) /* 0.379690791 */, 17 },
- /* 3333 */ { MAD_F(0x0613d5fa) /* 0.379842736 */, 17 },
- /* 3334 */ { MAD_F(0x06147551) /* 0.379994696 */, 17 },
- /* 3335 */ { MAD_F(0x061514ad) /* 0.380146671 */, 17 },
- /* 3336 */ { MAD_F(0x0615b40c) /* 0.380298661 */, 17 },
- /* 3337 */ { MAD_F(0x06165370) /* 0.380450666 */, 17 },
- /* 3338 */ { MAD_F(0x0616f2d8) /* 0.380602687 */, 17 },
- /* 3339 */ { MAD_F(0x06179243) /* 0.380754723 */, 17 },
- /* 3340 */ { MAD_F(0x061831b3) /* 0.380906774 */, 17 },
- /* 3341 */ { MAD_F(0x0618d127) /* 0.381058840 */, 17 },
- /* 3342 */ { MAD_F(0x0619709f) /* 0.381210921 */, 17 },
- /* 3343 */ { MAD_F(0x061a101b) /* 0.381363018 */, 17 },
-
- /* 3344 */ { MAD_F(0x061aaf9c) /* 0.381515130 */, 17 },
- /* 3345 */ { MAD_F(0x061b4f20) /* 0.381667257 */, 17 },
- /* 3346 */ { MAD_F(0x061beea8) /* 0.381819399 */, 17 },
- /* 3347 */ { MAD_F(0x061c8e34) /* 0.381971556 */, 17 },
- /* 3348 */ { MAD_F(0x061d2dc5) /* 0.382123728 */, 17 },
- /* 3349 */ { MAD_F(0x061dcd59) /* 0.382275916 */, 17 },
- /* 3350 */ { MAD_F(0x061e6cf2) /* 0.382428118 */, 17 },
- /* 3351 */ { MAD_F(0x061f0c8f) /* 0.382580336 */, 17 },
- /* 3352 */ { MAD_F(0x061fac2f) /* 0.382732569 */, 17 },
- /* 3353 */ { MAD_F(0x06204bd4) /* 0.382884817 */, 17 },
- /* 3354 */ { MAD_F(0x0620eb7d) /* 0.383037080 */, 17 },
- /* 3355 */ { MAD_F(0x06218b2a) /* 0.383189358 */, 17 },
- /* 3356 */ { MAD_F(0x06222adb) /* 0.383341652 */, 17 },
- /* 3357 */ { MAD_F(0x0622ca90) /* 0.383493960 */, 17 },
- /* 3358 */ { MAD_F(0x06236a49) /* 0.383646284 */, 17 },
- /* 3359 */ { MAD_F(0x06240a06) /* 0.383798623 */, 17 },
-
- /* 3360 */ { MAD_F(0x0624a9c7) /* 0.383950977 */, 17 },
- /* 3361 */ { MAD_F(0x0625498d) /* 0.384103346 */, 17 },
- /* 3362 */ { MAD_F(0x0625e956) /* 0.384255730 */, 17 },
- /* 3363 */ { MAD_F(0x06268923) /* 0.384408129 */, 17 },
- /* 3364 */ { MAD_F(0x062728f5) /* 0.384560544 */, 17 },
- /* 3365 */ { MAD_F(0x0627c8ca) /* 0.384712973 */, 17 },
- /* 3366 */ { MAD_F(0x062868a4) /* 0.384865418 */, 17 },
- /* 3367 */ { MAD_F(0x06290881) /* 0.385017878 */, 17 },
- /* 3368 */ { MAD_F(0x0629a863) /* 0.385170352 */, 17 },
- /* 3369 */ { MAD_F(0x062a4849) /* 0.385322842 */, 17 },
- /* 3370 */ { MAD_F(0x062ae832) /* 0.385475347 */, 17 },
- /* 3371 */ { MAD_F(0x062b8820) /* 0.385627867 */, 17 },
- /* 3372 */ { MAD_F(0x062c2812) /* 0.385780402 */, 17 },
- /* 3373 */ { MAD_F(0x062cc808) /* 0.385932953 */, 17 },
- /* 3374 */ { MAD_F(0x062d6802) /* 0.386085518 */, 17 },
- /* 3375 */ { MAD_F(0x062e0800) /* 0.386238098 */, 17 },
-
- /* 3376 */ { MAD_F(0x062ea802) /* 0.386390694 */, 17 },
- /* 3377 */ { MAD_F(0x062f4808) /* 0.386543304 */, 17 },
- /* 3378 */ { MAD_F(0x062fe812) /* 0.386695930 */, 17 },
- /* 3379 */ { MAD_F(0x06308820) /* 0.386848570 */, 17 },
- /* 3380 */ { MAD_F(0x06312832) /* 0.387001226 */, 17 },
- /* 3381 */ { MAD_F(0x0631c849) /* 0.387153897 */, 17 },
- /* 3382 */ { MAD_F(0x06326863) /* 0.387306582 */, 17 },
- /* 3383 */ { MAD_F(0x06330881) /* 0.387459283 */, 17 },
- /* 3384 */ { MAD_F(0x0633a8a3) /* 0.387611999 */, 17 },
- /* 3385 */ { MAD_F(0x063448ca) /* 0.387764730 */, 17 },
- /* 3386 */ { MAD_F(0x0634e8f4) /* 0.387917476 */, 17 },
- /* 3387 */ { MAD_F(0x06358923) /* 0.388070237 */, 17 },
- /* 3388 */ { MAD_F(0x06362955) /* 0.388223013 */, 17 },
- /* 3389 */ { MAD_F(0x0636c98c) /* 0.388375804 */, 17 },
- /* 3390 */ { MAD_F(0x063769c6) /* 0.388528610 */, 17 },
- /* 3391 */ { MAD_F(0x06380a05) /* 0.388681431 */, 17 },
-
- /* 3392 */ { MAD_F(0x0638aa48) /* 0.388834268 */, 17 },
- /* 3393 */ { MAD_F(0x06394a8e) /* 0.388987119 */, 17 },
- /* 3394 */ { MAD_F(0x0639ead9) /* 0.389139985 */, 17 },
- /* 3395 */ { MAD_F(0x063a8b28) /* 0.389292866 */, 17 },
- /* 3396 */ { MAD_F(0x063b2b7b) /* 0.389445762 */, 17 },
- /* 3397 */ { MAD_F(0x063bcbd1) /* 0.389598674 */, 17 },
- /* 3398 */ { MAD_F(0x063c6c2c) /* 0.389751600 */, 17 },
- /* 3399 */ { MAD_F(0x063d0c8b) /* 0.389904541 */, 17 },
- /* 3400 */ { MAD_F(0x063dacee) /* 0.390057497 */, 17 },
- /* 3401 */ { MAD_F(0x063e4d55) /* 0.390210468 */, 17 },
- /* 3402 */ { MAD_F(0x063eedc0) /* 0.390363455 */, 17 },
- /* 3403 */ { MAD_F(0x063f8e2f) /* 0.390516456 */, 17 },
- /* 3404 */ { MAD_F(0x06402ea2) /* 0.390669472 */, 17 },
- /* 3405 */ { MAD_F(0x0640cf19) /* 0.390822503 */, 17 },
- /* 3406 */ { MAD_F(0x06416f94) /* 0.390975549 */, 17 },
- /* 3407 */ { MAD_F(0x06421013) /* 0.391128611 */, 17 },
-
- /* 3408 */ { MAD_F(0x0642b096) /* 0.391281687 */, 17 },
- /* 3409 */ { MAD_F(0x0643511d) /* 0.391434778 */, 17 },
- /* 3410 */ { MAD_F(0x0643f1a8) /* 0.391587884 */, 17 },
- /* 3411 */ { MAD_F(0x06449237) /* 0.391741005 */, 17 },
- /* 3412 */ { MAD_F(0x064532ca) /* 0.391894141 */, 17 },
- /* 3413 */ { MAD_F(0x0645d361) /* 0.392047292 */, 17 },
- /* 3414 */ { MAD_F(0x064673fc) /* 0.392200458 */, 17 },
- /* 3415 */ { MAD_F(0x0647149c) /* 0.392353638 */, 17 },
- /* 3416 */ { MAD_F(0x0647b53f) /* 0.392506834 */, 17 },
- /* 3417 */ { MAD_F(0x064855e6) /* 0.392660045 */, 17 },
- /* 3418 */ { MAD_F(0x0648f691) /* 0.392813271 */, 17 },
- /* 3419 */ { MAD_F(0x06499740) /* 0.392966511 */, 17 },
- /* 3420 */ { MAD_F(0x064a37f4) /* 0.393119767 */, 17 },
- /* 3421 */ { MAD_F(0x064ad8ab) /* 0.393273038 */, 17 },
- /* 3422 */ { MAD_F(0x064b7966) /* 0.393426323 */, 17 },
- /* 3423 */ { MAD_F(0x064c1a25) /* 0.393579623 */, 17 },
-
- /* 3424 */ { MAD_F(0x064cbae9) /* 0.393732939 */, 17 },
- /* 3425 */ { MAD_F(0x064d5bb0) /* 0.393886269 */, 17 },
- /* 3426 */ { MAD_F(0x064dfc7b) /* 0.394039614 */, 17 },
- /* 3427 */ { MAD_F(0x064e9d4b) /* 0.394192974 */, 17 },
- /* 3428 */ { MAD_F(0x064f3e1e) /* 0.394346349 */, 17 },
- /* 3429 */ { MAD_F(0x064fdef5) /* 0.394499739 */, 17 },
- /* 3430 */ { MAD_F(0x06507fd0) /* 0.394653144 */, 17 },
- /* 3431 */ { MAD_F(0x065120b0) /* 0.394806564 */, 17 },
- /* 3432 */ { MAD_F(0x0651c193) /* 0.394959999 */, 17 },
- /* 3433 */ { MAD_F(0x0652627a) /* 0.395113448 */, 17 },
- /* 3434 */ { MAD_F(0x06530366) /* 0.395266913 */, 17 },
- /* 3435 */ { MAD_F(0x0653a455) /* 0.395420392 */, 17 },
- /* 3436 */ { MAD_F(0x06544548) /* 0.395573886 */, 17 },
- /* 3437 */ { MAD_F(0x0654e640) /* 0.395727395 */, 17 },
- /* 3438 */ { MAD_F(0x0655873b) /* 0.395880919 */, 17 },
- /* 3439 */ { MAD_F(0x0656283a) /* 0.396034458 */, 17 },
-
- /* 3440 */ { MAD_F(0x0656c93d) /* 0.396188012 */, 17 },
- /* 3441 */ { MAD_F(0x06576a45) /* 0.396341581 */, 17 },
- /* 3442 */ { MAD_F(0x06580b50) /* 0.396495164 */, 17 },
- /* 3443 */ { MAD_F(0x0658ac5f) /* 0.396648763 */, 17 },
- /* 3444 */ { MAD_F(0x06594d73) /* 0.396802376 */, 17 },
- /* 3445 */ { MAD_F(0x0659ee8a) /* 0.396956004 */, 17 },
- /* 3446 */ { MAD_F(0x065a8fa5) /* 0.397109647 */, 17 },
- /* 3447 */ { MAD_F(0x065b30c4) /* 0.397263305 */, 17 },
- /* 3448 */ { MAD_F(0x065bd1e7) /* 0.397416978 */, 17 },
- /* 3449 */ { MAD_F(0x065c730f) /* 0.397570666 */, 17 },
- /* 3450 */ { MAD_F(0x065d143a) /* 0.397724368 */, 17 },
- /* 3451 */ { MAD_F(0x065db569) /* 0.397878085 */, 17 },
- /* 3452 */ { MAD_F(0x065e569c) /* 0.398031818 */, 17 },
- /* 3453 */ { MAD_F(0x065ef7d3) /* 0.398185565 */, 17 },
- /* 3454 */ { MAD_F(0x065f990e) /* 0.398339326 */, 17 },
- /* 3455 */ { MAD_F(0x06603a4e) /* 0.398493103 */, 17 },
-
- /* 3456 */ { MAD_F(0x0660db91) /* 0.398646895 */, 17 },
- /* 3457 */ { MAD_F(0x06617cd8) /* 0.398800701 */, 17 },
- /* 3458 */ { MAD_F(0x06621e23) /* 0.398954522 */, 17 },
- /* 3459 */ { MAD_F(0x0662bf72) /* 0.399108358 */, 17 },
- /* 3460 */ { MAD_F(0x066360c5) /* 0.399262209 */, 17 },
- /* 3461 */ { MAD_F(0x0664021c) /* 0.399416075 */, 17 },
- /* 3462 */ { MAD_F(0x0664a377) /* 0.399569955 */, 17 },
- /* 3463 */ { MAD_F(0x066544d6) /* 0.399723851 */, 17 },
- /* 3464 */ { MAD_F(0x0665e639) /* 0.399877761 */, 17 },
- /* 3465 */ { MAD_F(0x066687a0) /* 0.400031686 */, 17 },
- /* 3466 */ { MAD_F(0x0667290b) /* 0.400185625 */, 17 },
- /* 3467 */ { MAD_F(0x0667ca79) /* 0.400339580 */, 17 },
- /* 3468 */ { MAD_F(0x06686bec) /* 0.400493549 */, 17 },
- /* 3469 */ { MAD_F(0x06690d63) /* 0.400647534 */, 17 },
- /* 3470 */ { MAD_F(0x0669aede) /* 0.400801533 */, 17 },
- /* 3471 */ { MAD_F(0x066a505d) /* 0.400955546 */, 17 },
-
- /* 3472 */ { MAD_F(0x066af1df) /* 0.401109575 */, 17 },
- /* 3473 */ { MAD_F(0x066b9366) /* 0.401263618 */, 17 },
- /* 3474 */ { MAD_F(0x066c34f1) /* 0.401417676 */, 17 },
- /* 3475 */ { MAD_F(0x066cd67f) /* 0.401571749 */, 17 },
- /* 3476 */ { MAD_F(0x066d7812) /* 0.401725837 */, 17 },
- /* 3477 */ { MAD_F(0x066e19a9) /* 0.401879939 */, 17 },
- /* 3478 */ { MAD_F(0x066ebb43) /* 0.402034056 */, 17 },
- /* 3479 */ { MAD_F(0x066f5ce2) /* 0.402188188 */, 17 },
- /* 3480 */ { MAD_F(0x066ffe84) /* 0.402342335 */, 17 },
- /* 3481 */ { MAD_F(0x0670a02a) /* 0.402496497 */, 17 },
- /* 3482 */ { MAD_F(0x067141d5) /* 0.402650673 */, 17 },
- /* 3483 */ { MAD_F(0x0671e383) /* 0.402804864 */, 17 },
- /* 3484 */ { MAD_F(0x06728535) /* 0.402959070 */, 17 },
- /* 3485 */ { MAD_F(0x067326ec) /* 0.403113291 */, 17 },
- /* 3486 */ { MAD_F(0x0673c8a6) /* 0.403267526 */, 17 },
- /* 3487 */ { MAD_F(0x06746a64) /* 0.403421776 */, 17 },
-
- /* 3488 */ { MAD_F(0x06750c26) /* 0.403576041 */, 17 },
- /* 3489 */ { MAD_F(0x0675adec) /* 0.403730320 */, 17 },
- /* 3490 */ { MAD_F(0x06764fb6) /* 0.403884615 */, 17 },
- /* 3491 */ { MAD_F(0x0676f184) /* 0.404038924 */, 17 },
- /* 3492 */ { MAD_F(0x06779356) /* 0.404193247 */, 17 },
- /* 3493 */ { MAD_F(0x0678352c) /* 0.404347586 */, 17 },
- /* 3494 */ { MAD_F(0x0678d706) /* 0.404501939 */, 17 },
- /* 3495 */ { MAD_F(0x067978e4) /* 0.404656307 */, 17 },
- /* 3496 */ { MAD_F(0x067a1ac6) /* 0.404810690 */, 17 },
- /* 3497 */ { MAD_F(0x067abcac) /* 0.404965087 */, 17 },
- /* 3498 */ { MAD_F(0x067b5e95) /* 0.405119499 */, 17 },
- /* 3499 */ { MAD_F(0x067c0083) /* 0.405273926 */, 17 },
- /* 3500 */ { MAD_F(0x067ca275) /* 0.405428368 */, 17 },
- /* 3501 */ { MAD_F(0x067d446a) /* 0.405582824 */, 17 },
- /* 3502 */ { MAD_F(0x067de664) /* 0.405737295 */, 17 },
- /* 3503 */ { MAD_F(0x067e8861) /* 0.405891781 */, 17 },
-
- /* 3504 */ { MAD_F(0x067f2a62) /* 0.406046281 */, 17 },
- /* 3505 */ { MAD_F(0x067fcc68) /* 0.406200796 */, 17 },
- /* 3506 */ { MAD_F(0x06806e71) /* 0.406355326 */, 17 },
- /* 3507 */ { MAD_F(0x0681107e) /* 0.406509870 */, 17 },
- /* 3508 */ { MAD_F(0x0681b28f) /* 0.406664429 */, 17 },
- /* 3509 */ { MAD_F(0x068254a4) /* 0.406819003 */, 17 },
- /* 3510 */ { MAD_F(0x0682f6bd) /* 0.406973592 */, 17 },
- /* 3511 */ { MAD_F(0x068398da) /* 0.407128195 */, 17 },
- /* 3512 */ { MAD_F(0x06843afb) /* 0.407282813 */, 17 },
- /* 3513 */ { MAD_F(0x0684dd20) /* 0.407437445 */, 17 },
- /* 3514 */ { MAD_F(0x06857f49) /* 0.407592093 */, 17 },
- /* 3515 */ { MAD_F(0x06862176) /* 0.407746754 */, 17 },
- /* 3516 */ { MAD_F(0x0686c3a6) /* 0.407901431 */, 17 },
- /* 3517 */ { MAD_F(0x068765db) /* 0.408056122 */, 17 },
- /* 3518 */ { MAD_F(0x06880814) /* 0.408210828 */, 17 },
- /* 3519 */ { MAD_F(0x0688aa50) /* 0.408365549 */, 17 },
-
- /* 3520 */ { MAD_F(0x06894c90) /* 0.408520284 */, 17 },
- /* 3521 */ { MAD_F(0x0689eed5) /* 0.408675034 */, 17 },
- /* 3522 */ { MAD_F(0x068a911d) /* 0.408829798 */, 17 },
- /* 3523 */ { MAD_F(0x068b3369) /* 0.408984577 */, 17 },
- /* 3524 */ { MAD_F(0x068bd5b9) /* 0.409139371 */, 17 },
- /* 3525 */ { MAD_F(0x068c780e) /* 0.409294180 */, 17 },
- /* 3526 */ { MAD_F(0x068d1a66) /* 0.409449003 */, 17 },
- /* 3527 */ { MAD_F(0x068dbcc1) /* 0.409603840 */, 17 },
- /* 3528 */ { MAD_F(0x068e5f21) /* 0.409758693 */, 17 },
- /* 3529 */ { MAD_F(0x068f0185) /* 0.409913560 */, 17 },
- /* 3530 */ { MAD_F(0x068fa3ed) /* 0.410068441 */, 17 },
- /* 3531 */ { MAD_F(0x06904658) /* 0.410223338 */, 17 },
- /* 3532 */ { MAD_F(0x0690e8c8) /* 0.410378249 */, 17 },
- /* 3533 */ { MAD_F(0x06918b3c) /* 0.410533174 */, 17 },
- /* 3534 */ { MAD_F(0x06922db3) /* 0.410688114 */, 17 },
- /* 3535 */ { MAD_F(0x0692d02e) /* 0.410843069 */, 17 },
-
- /* 3536 */ { MAD_F(0x069372ae) /* 0.410998038 */, 17 },
- /* 3537 */ { MAD_F(0x06941531) /* 0.411153022 */, 17 },
- /* 3538 */ { MAD_F(0x0694b7b8) /* 0.411308021 */, 17 },
- /* 3539 */ { MAD_F(0x06955a43) /* 0.411463034 */, 17 },
- /* 3540 */ { MAD_F(0x0695fcd2) /* 0.411618062 */, 17 },
- /* 3541 */ { MAD_F(0x06969f65) /* 0.411773104 */, 17 },
- /* 3542 */ { MAD_F(0x069741fb) /* 0.411928161 */, 17 },
- /* 3543 */ { MAD_F(0x0697e496) /* 0.412083232 */, 17 },
- /* 3544 */ { MAD_F(0x06988735) /* 0.412238319 */, 17 },
- /* 3545 */ { MAD_F(0x069929d7) /* 0.412393419 */, 17 },
- /* 3546 */ { MAD_F(0x0699cc7e) /* 0.412548535 */, 17 },
- /* 3547 */ { MAD_F(0x069a6f28) /* 0.412703664 */, 17 },
- /* 3548 */ { MAD_F(0x069b11d6) /* 0.412858809 */, 17 },
- /* 3549 */ { MAD_F(0x069bb489) /* 0.413013968 */, 17 },
- /* 3550 */ { MAD_F(0x069c573f) /* 0.413169142 */, 17 },
- /* 3551 */ { MAD_F(0x069cf9f9) /* 0.413324330 */, 17 },
-
- /* 3552 */ { MAD_F(0x069d9cb7) /* 0.413479532 */, 17 },
- /* 3553 */ { MAD_F(0x069e3f78) /* 0.413634750 */, 17 },
- /* 3554 */ { MAD_F(0x069ee23e) /* 0.413789982 */, 17 },
- /* 3555 */ { MAD_F(0x069f8508) /* 0.413945228 */, 17 },
- /* 3556 */ { MAD_F(0x06a027d5) /* 0.414100489 */, 17 },
- /* 3557 */ { MAD_F(0x06a0caa7) /* 0.414255765 */, 17 },
- /* 3558 */ { MAD_F(0x06a16d7c) /* 0.414411055 */, 17 },
- /* 3559 */ { MAD_F(0x06a21055) /* 0.414566359 */, 17 },
- /* 3560 */ { MAD_F(0x06a2b333) /* 0.414721679 */, 17 },
- /* 3561 */ { MAD_F(0x06a35614) /* 0.414877012 */, 17 },
- /* 3562 */ { MAD_F(0x06a3f8f9) /* 0.415032361 */, 17 },
- /* 3563 */ { MAD_F(0x06a49be2) /* 0.415187723 */, 17 },
- /* 3564 */ { MAD_F(0x06a53ece) /* 0.415343101 */, 17 },
- /* 3565 */ { MAD_F(0x06a5e1bf) /* 0.415498493 */, 17 },
- /* 3566 */ { MAD_F(0x06a684b4) /* 0.415653899 */, 17 },
- /* 3567 */ { MAD_F(0x06a727ac) /* 0.415809320 */, 17 },
-
- /* 3568 */ { MAD_F(0x06a7caa9) /* 0.415964756 */, 17 },
- /* 3569 */ { MAD_F(0x06a86da9) /* 0.416120206 */, 17 },
- /* 3570 */ { MAD_F(0x06a910ad) /* 0.416275670 */, 17 },
- /* 3571 */ { MAD_F(0x06a9b3b5) /* 0.416431149 */, 17 },
- /* 3572 */ { MAD_F(0x06aa56c1) /* 0.416586643 */, 17 },
- /* 3573 */ { MAD_F(0x06aaf9d1) /* 0.416742151 */, 17 },
- /* 3574 */ { MAD_F(0x06ab9ce5) /* 0.416897673 */, 17 },
- /* 3575 */ { MAD_F(0x06ac3ffc) /* 0.417053210 */, 17 },
- /* 3576 */ { MAD_F(0x06ace318) /* 0.417208762 */, 17 },
- /* 3577 */ { MAD_F(0x06ad8637) /* 0.417364328 */, 17 },
- /* 3578 */ { MAD_F(0x06ae295b) /* 0.417519909 */, 17 },
- /* 3579 */ { MAD_F(0x06aecc82) /* 0.417675504 */, 17 },
- /* 3580 */ { MAD_F(0x06af6fad) /* 0.417831113 */, 17 },
- /* 3581 */ { MAD_F(0x06b012dc) /* 0.417986737 */, 17 },
- /* 3582 */ { MAD_F(0x06b0b60f) /* 0.418142376 */, 17 },
- /* 3583 */ { MAD_F(0x06b15946) /* 0.418298029 */, 17 },
-
- /* 3584 */ { MAD_F(0x06b1fc81) /* 0.418453696 */, 17 },
- /* 3585 */ { MAD_F(0x06b29fbf) /* 0.418609378 */, 17 },
- /* 3586 */ { MAD_F(0x06b34302) /* 0.418765075 */, 17 },
- /* 3587 */ { MAD_F(0x06b3e648) /* 0.418920786 */, 17 },
- /* 3588 */ { MAD_F(0x06b48992) /* 0.419076511 */, 17 },
- /* 3589 */ { MAD_F(0x06b52ce0) /* 0.419232251 */, 17 },
- /* 3590 */ { MAD_F(0x06b5d032) /* 0.419388005 */, 17 },
- /* 3591 */ { MAD_F(0x06b67388) /* 0.419543774 */, 17 },
- /* 3592 */ { MAD_F(0x06b716e2) /* 0.419699557 */, 17 },
- /* 3593 */ { MAD_F(0x06b7ba3f) /* 0.419855355 */, 17 },
- /* 3594 */ { MAD_F(0x06b85da1) /* 0.420011167 */, 17 },
- /* 3595 */ { MAD_F(0x06b90106) /* 0.420166994 */, 17 },
- /* 3596 */ { MAD_F(0x06b9a470) /* 0.420322835 */, 17 },
- /* 3597 */ { MAD_F(0x06ba47dd) /* 0.420478690 */, 17 },
- /* 3598 */ { MAD_F(0x06baeb4e) /* 0.420634560 */, 17 },
- /* 3599 */ { MAD_F(0x06bb8ec3) /* 0.420790445 */, 17 },
-
- /* 3600 */ { MAD_F(0x06bc323b) /* 0.420946343 */, 17 },
- /* 3601 */ { MAD_F(0x06bcd5b8) /* 0.421102257 */, 17 },
- /* 3602 */ { MAD_F(0x06bd7939) /* 0.421258184 */, 17 },
- /* 3603 */ { MAD_F(0x06be1cbd) /* 0.421414127 */, 17 },
- /* 3604 */ { MAD_F(0x06bec045) /* 0.421570083 */, 17 },
- /* 3605 */ { MAD_F(0x06bf63d1) /* 0.421726054 */, 17 },
- /* 3606 */ { MAD_F(0x06c00761) /* 0.421882040 */, 17 },
- /* 3607 */ { MAD_F(0x06c0aaf5) /* 0.422038039 */, 17 },
- /* 3608 */ { MAD_F(0x06c14e8d) /* 0.422194054 */, 17 },
- /* 3609 */ { MAD_F(0x06c1f229) /* 0.422350082 */, 17 },
- /* 3610 */ { MAD_F(0x06c295c8) /* 0.422506125 */, 17 },
- /* 3611 */ { MAD_F(0x06c3396c) /* 0.422662183 */, 17 },
- /* 3612 */ { MAD_F(0x06c3dd13) /* 0.422818255 */, 17 },
- /* 3613 */ { MAD_F(0x06c480be) /* 0.422974341 */, 17 },
- /* 3614 */ { MAD_F(0x06c5246d) /* 0.423130442 */, 17 },
- /* 3615 */ { MAD_F(0x06c5c820) /* 0.423286557 */, 17 },
-
- /* 3616 */ { MAD_F(0x06c66bd6) /* 0.423442686 */, 17 },
- /* 3617 */ { MAD_F(0x06c70f91) /* 0.423598830 */, 17 },
- /* 3618 */ { MAD_F(0x06c7b34f) /* 0.423754988 */, 17 },
- /* 3619 */ { MAD_F(0x06c85712) /* 0.423911161 */, 17 },
- /* 3620 */ { MAD_F(0x06c8fad8) /* 0.424067348 */, 17 },
- /* 3621 */ { MAD_F(0x06c99ea2) /* 0.424223550 */, 17 },
- /* 3622 */ { MAD_F(0x06ca4270) /* 0.424379765 */, 17 },
- /* 3623 */ { MAD_F(0x06cae641) /* 0.424535996 */, 17 },
- /* 3624 */ { MAD_F(0x06cb8a17) /* 0.424692240 */, 17 },
- /* 3625 */ { MAD_F(0x06cc2df0) /* 0.424848499 */, 17 },
- /* 3626 */ { MAD_F(0x06ccd1ce) /* 0.425004772 */, 17 },
- /* 3627 */ { MAD_F(0x06cd75af) /* 0.425161060 */, 17 },
- /* 3628 */ { MAD_F(0x06ce1994) /* 0.425317362 */, 17 },
- /* 3629 */ { MAD_F(0x06cebd7d) /* 0.425473678 */, 17 },
- /* 3630 */ { MAD_F(0x06cf6169) /* 0.425630009 */, 17 },
- /* 3631 */ { MAD_F(0x06d0055a) /* 0.425786354 */, 17 },
-
- /* 3632 */ { MAD_F(0x06d0a94e) /* 0.425942714 */, 17 },
- /* 3633 */ { MAD_F(0x06d14d47) /* 0.426099088 */, 17 },
- /* 3634 */ { MAD_F(0x06d1f143) /* 0.426255476 */, 17 },
- /* 3635 */ { MAD_F(0x06d29543) /* 0.426411878 */, 17 },
- /* 3636 */ { MAD_F(0x06d33947) /* 0.426568295 */, 17 },
- /* 3637 */ { MAD_F(0x06d3dd4e) /* 0.426724726 */, 17 },
- /* 3638 */ { MAD_F(0x06d4815a) /* 0.426881172 */, 17 },
- /* 3639 */ { MAD_F(0x06d52569) /* 0.427037632 */, 17 },
- /* 3640 */ { MAD_F(0x06d5c97c) /* 0.427194106 */, 17 },
- /* 3641 */ { MAD_F(0x06d66d93) /* 0.427350594 */, 17 },
- /* 3642 */ { MAD_F(0x06d711ae) /* 0.427507097 */, 17 },
- /* 3643 */ { MAD_F(0x06d7b5cd) /* 0.427663614 */, 17 },
- /* 3644 */ { MAD_F(0x06d859f0) /* 0.427820146 */, 17 },
- /* 3645 */ { MAD_F(0x06d8fe16) /* 0.427976692 */, 17 },
- /* 3646 */ { MAD_F(0x06d9a240) /* 0.428133252 */, 17 },
- /* 3647 */ { MAD_F(0x06da466f) /* 0.428289826 */, 17 },
-
- /* 3648 */ { MAD_F(0x06daeaa1) /* 0.428446415 */, 17 },
- /* 3649 */ { MAD_F(0x06db8ed6) /* 0.428603018 */, 17 },
- /* 3650 */ { MAD_F(0x06dc3310) /* 0.428759635 */, 17 },
- /* 3651 */ { MAD_F(0x06dcd74d) /* 0.428916267 */, 17 },
- /* 3652 */ { MAD_F(0x06dd7b8f) /* 0.429072913 */, 17 },
- /* 3653 */ { MAD_F(0x06de1fd4) /* 0.429229573 */, 17 },
- /* 3654 */ { MAD_F(0x06dec41d) /* 0.429386248 */, 17 },
- /* 3655 */ { MAD_F(0x06df686a) /* 0.429542937 */, 17 },
- /* 3656 */ { MAD_F(0x06e00cbb) /* 0.429699640 */, 17 },
- /* 3657 */ { MAD_F(0x06e0b10f) /* 0.429856357 */, 17 },
- /* 3658 */ { MAD_F(0x06e15567) /* 0.430013089 */, 17 },
- /* 3659 */ { MAD_F(0x06e1f9c4) /* 0.430169835 */, 17 },
- /* 3660 */ { MAD_F(0x06e29e24) /* 0.430326595 */, 17 },
- /* 3661 */ { MAD_F(0x06e34287) /* 0.430483370 */, 17 },
- /* 3662 */ { MAD_F(0x06e3e6ef) /* 0.430640159 */, 17 },
- /* 3663 */ { MAD_F(0x06e48b5b) /* 0.430796962 */, 17 },
-
- /* 3664 */ { MAD_F(0x06e52fca) /* 0.430953779 */, 17 },
- /* 3665 */ { MAD_F(0x06e5d43d) /* 0.431110611 */, 17 },
- /* 3666 */ { MAD_F(0x06e678b4) /* 0.431267457 */, 17 },
- /* 3667 */ { MAD_F(0x06e71d2f) /* 0.431424317 */, 17 },
- /* 3668 */ { MAD_F(0x06e7c1ae) /* 0.431581192 */, 17 },
- /* 3669 */ { MAD_F(0x06e86630) /* 0.431738080 */, 17 },
- /* 3670 */ { MAD_F(0x06e90ab7) /* 0.431894983 */, 17 },
- /* 3671 */ { MAD_F(0x06e9af41) /* 0.432051900 */, 17 },
- /* 3672 */ { MAD_F(0x06ea53cf) /* 0.432208832 */, 17 },
- /* 3673 */ { MAD_F(0x06eaf860) /* 0.432365778 */, 17 },
- /* 3674 */ { MAD_F(0x06eb9cf6) /* 0.432522737 */, 17 },
- /* 3675 */ { MAD_F(0x06ec418f) /* 0.432679712 */, 17 },
- /* 3676 */ { MAD_F(0x06ece62d) /* 0.432836700 */, 17 },
- /* 3677 */ { MAD_F(0x06ed8ace) /* 0.432993703 */, 17 },
- /* 3678 */ { MAD_F(0x06ee2f73) /* 0.433150720 */, 17 },
- /* 3679 */ { MAD_F(0x06eed41b) /* 0.433307751 */, 17 },
-
- /* 3680 */ { MAD_F(0x06ef78c8) /* 0.433464796 */, 17 },
- /* 3681 */ { MAD_F(0x06f01d78) /* 0.433621856 */, 17 },
- /* 3682 */ { MAD_F(0x06f0c22c) /* 0.433778929 */, 17 },
- /* 3683 */ { MAD_F(0x06f166e4) /* 0.433936017 */, 17 },
- /* 3684 */ { MAD_F(0x06f20ba0) /* 0.434093120 */, 17 },
- /* 3685 */ { MAD_F(0x06f2b060) /* 0.434250236 */, 17 },
- /* 3686 */ { MAD_F(0x06f35523) /* 0.434407367 */, 17 },
- /* 3687 */ { MAD_F(0x06f3f9eb) /* 0.434564512 */, 17 },
- /* 3688 */ { MAD_F(0x06f49eb6) /* 0.434721671 */, 17 },
- /* 3689 */ { MAD_F(0x06f54385) /* 0.434878844 */, 17 },
- /* 3690 */ { MAD_F(0x06f5e857) /* 0.435036032 */, 17 },
- /* 3691 */ { MAD_F(0x06f68d2e) /* 0.435193233 */, 17 },
- /* 3692 */ { MAD_F(0x06f73208) /* 0.435350449 */, 17 },
- /* 3693 */ { MAD_F(0x06f7d6e6) /* 0.435507679 */, 17 },
- /* 3694 */ { MAD_F(0x06f87bc8) /* 0.435664924 */, 17 },
- /* 3695 */ { MAD_F(0x06f920ae) /* 0.435822182 */, 17 },
-
- /* 3696 */ { MAD_F(0x06f9c597) /* 0.435979455 */, 17 },
- /* 3697 */ { MAD_F(0x06fa6a85) /* 0.436136741 */, 17 },
- /* 3698 */ { MAD_F(0x06fb0f76) /* 0.436294042 */, 17 },
- /* 3699 */ { MAD_F(0x06fbb46b) /* 0.436451358 */, 17 },
- /* 3700 */ { MAD_F(0x06fc5964) /* 0.436608687 */, 17 },
- /* 3701 */ { MAD_F(0x06fcfe60) /* 0.436766031 */, 17 },
- /* 3702 */ { MAD_F(0x06fda361) /* 0.436923388 */, 17 },
- /* 3703 */ { MAD_F(0x06fe4865) /* 0.437080760 */, 17 },
- /* 3704 */ { MAD_F(0x06feed6d) /* 0.437238146 */, 17 },
- /* 3705 */ { MAD_F(0x06ff9279) /* 0.437395547 */, 17 },
- /* 3706 */ { MAD_F(0x07003788) /* 0.437552961 */, 17 },
- /* 3707 */ { MAD_F(0x0700dc9c) /* 0.437710389 */, 17 },
- /* 3708 */ { MAD_F(0x070181b3) /* 0.437867832 */, 17 },
- /* 3709 */ { MAD_F(0x070226ce) /* 0.438025289 */, 17 },
- /* 3710 */ { MAD_F(0x0702cbed) /* 0.438182760 */, 17 },
- /* 3711 */ { MAD_F(0x0703710f) /* 0.438340245 */, 17 },
-
- /* 3712 */ { MAD_F(0x07041636) /* 0.438497744 */, 17 },
- /* 3713 */ { MAD_F(0x0704bb60) /* 0.438655258 */, 17 },
- /* 3714 */ { MAD_F(0x0705608e) /* 0.438812785 */, 17 },
- /* 3715 */ { MAD_F(0x070605c0) /* 0.438970327 */, 17 },
- /* 3716 */ { MAD_F(0x0706aaf5) /* 0.439127883 */, 17 },
- /* 3717 */ { MAD_F(0x0707502f) /* 0.439285453 */, 17 },
- /* 3718 */ { MAD_F(0x0707f56c) /* 0.439443037 */, 17 },
- /* 3719 */ { MAD_F(0x07089aad) /* 0.439600635 */, 17 },
- /* 3720 */ { MAD_F(0x07093ff2) /* 0.439758248 */, 17 },
- /* 3721 */ { MAD_F(0x0709e53a) /* 0.439915874 */, 17 },
- /* 3722 */ { MAD_F(0x070a8a86) /* 0.440073515 */, 17 },
- /* 3723 */ { MAD_F(0x070b2fd7) /* 0.440231170 */, 17 },
- /* 3724 */ { MAD_F(0x070bd52a) /* 0.440388839 */, 17 },
- /* 3725 */ { MAD_F(0x070c7a82) /* 0.440546522 */, 17 },
- /* 3726 */ { MAD_F(0x070d1fde) /* 0.440704219 */, 17 },
- /* 3727 */ { MAD_F(0x070dc53d) /* 0.440861930 */, 17 },
-
- /* 3728 */ { MAD_F(0x070e6aa0) /* 0.441019655 */, 17 },
- /* 3729 */ { MAD_F(0x070f1007) /* 0.441177395 */, 17 },
- /* 3730 */ { MAD_F(0x070fb571) /* 0.441335148 */, 17 },
- /* 3731 */ { MAD_F(0x07105ae0) /* 0.441492916 */, 17 },
- /* 3732 */ { MAD_F(0x07110052) /* 0.441650697 */, 17 },
- /* 3733 */ { MAD_F(0x0711a5c8) /* 0.441808493 */, 17 },
- /* 3734 */ { MAD_F(0x07124b42) /* 0.441966303 */, 17 },
- /* 3735 */ { MAD_F(0x0712f0bf) /* 0.442124127 */, 17 },
- /* 3736 */ { MAD_F(0x07139641) /* 0.442281965 */, 17 },
- /* 3737 */ { MAD_F(0x07143bc6) /* 0.442439817 */, 17 },
- /* 3738 */ { MAD_F(0x0714e14f) /* 0.442597683 */, 17 },
- /* 3739 */ { MAD_F(0x071586db) /* 0.442755564 */, 17 },
- /* 3740 */ { MAD_F(0x07162c6c) /* 0.442913458 */, 17 },
- /* 3741 */ { MAD_F(0x0716d200) /* 0.443071366 */, 17 },
- /* 3742 */ { MAD_F(0x07177798) /* 0.443229289 */, 17 },
- /* 3743 */ { MAD_F(0x07181d34) /* 0.443387226 */, 17 },
-
- /* 3744 */ { MAD_F(0x0718c2d3) /* 0.443545176 */, 17 },
- /* 3745 */ { MAD_F(0x07196877) /* 0.443703141 */, 17 },
- /* 3746 */ { MAD_F(0x071a0e1e) /* 0.443861120 */, 17 },
- /* 3747 */ { MAD_F(0x071ab3c9) /* 0.444019113 */, 17 },
- /* 3748 */ { MAD_F(0x071b5977) /* 0.444177119 */, 17 },
- /* 3749 */ { MAD_F(0x071bff2a) /* 0.444335140 */, 17 },
- /* 3750 */ { MAD_F(0x071ca4e0) /* 0.444493175 */, 17 },
- /* 3751 */ { MAD_F(0x071d4a9a) /* 0.444651224 */, 17 },
- /* 3752 */ { MAD_F(0x071df058) /* 0.444809288 */, 17 },
- /* 3753 */ { MAD_F(0x071e9619) /* 0.444967365 */, 17 },
- /* 3754 */ { MAD_F(0x071f3bde) /* 0.445125456 */, 17 },
- /* 3755 */ { MAD_F(0x071fe1a8) /* 0.445283561 */, 17 },
- /* 3756 */ { MAD_F(0x07208774) /* 0.445441680 */, 17 },
- /* 3757 */ { MAD_F(0x07212d45) /* 0.445599814 */, 17 },
- /* 3758 */ { MAD_F(0x0721d319) /* 0.445757961 */, 17 },
- /* 3759 */ { MAD_F(0x072278f1) /* 0.445916122 */, 17 },
-
- /* 3760 */ { MAD_F(0x07231ecd) /* 0.446074298 */, 17 },
- /* 3761 */ { MAD_F(0x0723c4ad) /* 0.446232487 */, 17 },
- /* 3762 */ { MAD_F(0x07246a90) /* 0.446390690 */, 17 },
- /* 3763 */ { MAD_F(0x07251077) /* 0.446548908 */, 17 },
- /* 3764 */ { MAD_F(0x0725b662) /* 0.446707139 */, 17 },
- /* 3765 */ { MAD_F(0x07265c51) /* 0.446865385 */, 17 },
- /* 3766 */ { MAD_F(0x07270244) /* 0.447023644 */, 17 },
- /* 3767 */ { MAD_F(0x0727a83a) /* 0.447181918 */, 17 },
- /* 3768 */ { MAD_F(0x07284e34) /* 0.447340205 */, 17 },
- /* 3769 */ { MAD_F(0x0728f431) /* 0.447498507 */, 17 },
- /* 3770 */ { MAD_F(0x07299a33) /* 0.447656822 */, 17 },
- /* 3771 */ { MAD_F(0x072a4038) /* 0.447815152 */, 17 },
- /* 3772 */ { MAD_F(0x072ae641) /* 0.447973495 */, 17 },
- /* 3773 */ { MAD_F(0x072b8c4e) /* 0.448131853 */, 17 },
- /* 3774 */ { MAD_F(0x072c325e) /* 0.448290224 */, 17 },
- /* 3775 */ { MAD_F(0x072cd873) /* 0.448448609 */, 17 },
-
- /* 3776 */ { MAD_F(0x072d7e8b) /* 0.448607009 */, 17 },
- /* 3777 */ { MAD_F(0x072e24a7) /* 0.448765422 */, 17 },
- /* 3778 */ { MAD_F(0x072ecac6) /* 0.448923850 */, 17 },
- /* 3779 */ { MAD_F(0x072f70e9) /* 0.449082291 */, 17 },
- /* 3780 */ { MAD_F(0x07301710) /* 0.449240746 */, 17 },
- /* 3781 */ { MAD_F(0x0730bd3b) /* 0.449399216 */, 17 },
- /* 3782 */ { MAD_F(0x0731636a) /* 0.449557699 */, 17 },
- /* 3783 */ { MAD_F(0x0732099c) /* 0.449716196 */, 17 },
- /* 3784 */ { MAD_F(0x0732afd2) /* 0.449874708 */, 17 },
- /* 3785 */ { MAD_F(0x0733560c) /* 0.450033233 */, 17 },
- /* 3786 */ { MAD_F(0x0733fc49) /* 0.450191772 */, 17 },
- /* 3787 */ { MAD_F(0x0734a28b) /* 0.450350325 */, 17 },
- /* 3788 */ { MAD_F(0x073548d0) /* 0.450508892 */, 17 },
- /* 3789 */ { MAD_F(0x0735ef18) /* 0.450667473 */, 17 },
- /* 3790 */ { MAD_F(0x07369565) /* 0.450826068 */, 17 },
- /* 3791 */ { MAD_F(0x07373bb5) /* 0.450984677 */, 17 },
-
- /* 3792 */ { MAD_F(0x0737e209) /* 0.451143300 */, 17 },
- /* 3793 */ { MAD_F(0x07388861) /* 0.451301937 */, 17 },
- /* 3794 */ { MAD_F(0x07392ebc) /* 0.451460588 */, 17 },
- /* 3795 */ { MAD_F(0x0739d51c) /* 0.451619252 */, 17 },
- /* 3796 */ { MAD_F(0x073a7b7f) /* 0.451777931 */, 17 },
- /* 3797 */ { MAD_F(0x073b21e5) /* 0.451936623 */, 17 },
- /* 3798 */ { MAD_F(0x073bc850) /* 0.452095330 */, 17 },
- /* 3799 */ { MAD_F(0x073c6ebe) /* 0.452254050 */, 17 },
- /* 3800 */ { MAD_F(0x073d1530) /* 0.452412785 */, 17 },
- /* 3801 */ { MAD_F(0x073dbba6) /* 0.452571533 */, 17 },
- /* 3802 */ { MAD_F(0x073e621f) /* 0.452730295 */, 17 },
- /* 3803 */ { MAD_F(0x073f089c) /* 0.452889071 */, 17 },
- /* 3804 */ { MAD_F(0x073faf1d) /* 0.453047861 */, 17 },
- /* 3805 */ { MAD_F(0x074055a2) /* 0.453206665 */, 17 },
- /* 3806 */ { MAD_F(0x0740fc2a) /* 0.453365483 */, 17 },
- /* 3807 */ { MAD_F(0x0741a2b6) /* 0.453524315 */, 17 },
-
- /* 3808 */ { MAD_F(0x07424946) /* 0.453683161 */, 17 },
- /* 3809 */ { MAD_F(0x0742efd9) /* 0.453842020 */, 17 },
- /* 3810 */ { MAD_F(0x07439671) /* 0.454000894 */, 17 },
- /* 3811 */ { MAD_F(0x07443d0c) /* 0.454159781 */, 17 },
- /* 3812 */ { MAD_F(0x0744e3aa) /* 0.454318683 */, 17 },
- /* 3813 */ { MAD_F(0x07458a4d) /* 0.454477598 */, 17 },
- /* 3814 */ { MAD_F(0x074630f3) /* 0.454636527 */, 17 },
- /* 3815 */ { MAD_F(0x0746d79d) /* 0.454795470 */, 17 },
- /* 3816 */ { MAD_F(0x07477e4b) /* 0.454954427 */, 17 },
- /* 3817 */ { MAD_F(0x074824fc) /* 0.455113397 */, 17 },
- /* 3818 */ { MAD_F(0x0748cbb1) /* 0.455272382 */, 17 },
- /* 3819 */ { MAD_F(0x0749726a) /* 0.455431381 */, 17 },
- /* 3820 */ { MAD_F(0x074a1927) /* 0.455590393 */, 17 },
- /* 3821 */ { MAD_F(0x074abfe7) /* 0.455749419 */, 17 },
- /* 3822 */ { MAD_F(0x074b66ab) /* 0.455908459 */, 17 },
- /* 3823 */ { MAD_F(0x074c0d73) /* 0.456067513 */, 17 },
-
- /* 3824 */ { MAD_F(0x074cb43e) /* 0.456226581 */, 17 },
- /* 3825 */ { MAD_F(0x074d5b0d) /* 0.456385663 */, 17 },
- /* 3826 */ { MAD_F(0x074e01e0) /* 0.456544759 */, 17 },
- /* 3827 */ { MAD_F(0x074ea8b7) /* 0.456703868 */, 17 },
- /* 3828 */ { MAD_F(0x074f4f91) /* 0.456862992 */, 17 },
- /* 3829 */ { MAD_F(0x074ff66f) /* 0.457022129 */, 17 },
- /* 3830 */ { MAD_F(0x07509d51) /* 0.457181280 */, 17 },
- /* 3831 */ { MAD_F(0x07514437) /* 0.457340445 */, 17 },
- /* 3832 */ { MAD_F(0x0751eb20) /* 0.457499623 */, 17 },
- /* 3833 */ { MAD_F(0x0752920d) /* 0.457658816 */, 17 },
- /* 3834 */ { MAD_F(0x075338fd) /* 0.457818022 */, 17 },
- /* 3835 */ { MAD_F(0x0753dff2) /* 0.457977243 */, 17 },
- /* 3836 */ { MAD_F(0x075486ea) /* 0.458136477 */, 17 },
- /* 3837 */ { MAD_F(0x07552de6) /* 0.458295725 */, 17 },
- /* 3838 */ { MAD_F(0x0755d4e5) /* 0.458454987 */, 17 },
- /* 3839 */ { MAD_F(0x07567be8) /* 0.458614262 */, 17 },
-
- /* 3840 */ { MAD_F(0x075722ef) /* 0.458773552 */, 17 },
- /* 3841 */ { MAD_F(0x0757c9fa) /* 0.458932855 */, 17 },
- /* 3842 */ { MAD_F(0x07587108) /* 0.459092172 */, 17 },
- /* 3843 */ { MAD_F(0x0759181a) /* 0.459251503 */, 17 },
- /* 3844 */ { MAD_F(0x0759bf30) /* 0.459410848 */, 17 },
- /* 3845 */ { MAD_F(0x075a664a) /* 0.459570206 */, 17 },
- /* 3846 */ { MAD_F(0x075b0d67) /* 0.459729579 */, 17 },
- /* 3847 */ { MAD_F(0x075bb488) /* 0.459888965 */, 17 },
- /* 3848 */ { MAD_F(0x075c5bac) /* 0.460048365 */, 17 },
- /* 3849 */ { MAD_F(0x075d02d5) /* 0.460207779 */, 17 },
- /* 3850 */ { MAD_F(0x075daa01) /* 0.460367206 */, 17 },
- /* 3851 */ { MAD_F(0x075e5130) /* 0.460526648 */, 17 },
- /* 3852 */ { MAD_F(0x075ef864) /* 0.460686103 */, 17 },
- /* 3853 */ { MAD_F(0x075f9f9b) /* 0.460845572 */, 17 },
- /* 3854 */ { MAD_F(0x076046d6) /* 0.461005055 */, 17 },
- /* 3855 */ { MAD_F(0x0760ee14) /* 0.461164552 */, 17 },
-
- /* 3856 */ { MAD_F(0x07619557) /* 0.461324062 */, 17 },
- /* 3857 */ { MAD_F(0x07623c9d) /* 0.461483586 */, 17 },
- /* 3858 */ { MAD_F(0x0762e3e6) /* 0.461643124 */, 17 },
- /* 3859 */ { MAD_F(0x07638b34) /* 0.461802676 */, 17 },
- /* 3860 */ { MAD_F(0x07643285) /* 0.461962242 */, 17 },
- /* 3861 */ { MAD_F(0x0764d9d9) /* 0.462121821 */, 17 },
- /* 3862 */ { MAD_F(0x07658132) /* 0.462281414 */, 17 },
- /* 3863 */ { MAD_F(0x0766288e) /* 0.462441021 */, 17 },
- /* 3864 */ { MAD_F(0x0766cfee) /* 0.462600642 */, 17 },
- /* 3865 */ { MAD_F(0x07677751) /* 0.462760276 */, 17 },
- /* 3866 */ { MAD_F(0x07681eb9) /* 0.462919924 */, 17 },
- /* 3867 */ { MAD_F(0x0768c624) /* 0.463079586 */, 17 },
- /* 3868 */ { MAD_F(0x07696d92) /* 0.463239262 */, 17 },
- /* 3869 */ { MAD_F(0x076a1505) /* 0.463398951 */, 17 },
- /* 3870 */ { MAD_F(0x076abc7b) /* 0.463558655 */, 17 },
- /* 3871 */ { MAD_F(0x076b63f4) /* 0.463718372 */, 17 },
-
- /* 3872 */ { MAD_F(0x076c0b72) /* 0.463878102 */, 17 },
- /* 3873 */ { MAD_F(0x076cb2f3) /* 0.464037847 */, 17 },
- /* 3874 */ { MAD_F(0x076d5a78) /* 0.464197605 */, 17 },
- /* 3875 */ { MAD_F(0x076e0200) /* 0.464357377 */, 17 },
- /* 3876 */ { MAD_F(0x076ea98c) /* 0.464517163 */, 17 },
- /* 3877 */ { MAD_F(0x076f511c) /* 0.464676962 */, 17 },
- /* 3878 */ { MAD_F(0x076ff8b0) /* 0.464836776 */, 17 },
- /* 3879 */ { MAD_F(0x0770a047) /* 0.464996603 */, 17 },
- /* 3880 */ { MAD_F(0x077147e2) /* 0.465156443 */, 17 },
- /* 3881 */ { MAD_F(0x0771ef80) /* 0.465316298 */, 17 },
- /* 3882 */ { MAD_F(0x07729723) /* 0.465476166 */, 17 },
- /* 3883 */ { MAD_F(0x07733ec9) /* 0.465636048 */, 17 },
- /* 3884 */ { MAD_F(0x0773e672) /* 0.465795943 */, 17 },
- /* 3885 */ { MAD_F(0x07748e20) /* 0.465955853 */, 17 },
- /* 3886 */ { MAD_F(0x077535d1) /* 0.466115776 */, 17 },
- /* 3887 */ { MAD_F(0x0775dd85) /* 0.466275713 */, 17 },
-
- /* 3888 */ { MAD_F(0x0776853e) /* 0.466435663 */, 17 },
- /* 3889 */ { MAD_F(0x07772cfa) /* 0.466595627 */, 17 },
- /* 3890 */ { MAD_F(0x0777d4ba) /* 0.466755605 */, 17 },
- /* 3891 */ { MAD_F(0x07787c7d) /* 0.466915597 */, 17 },
- /* 3892 */ { MAD_F(0x07792444) /* 0.467075602 */, 17 },
- /* 3893 */ { MAD_F(0x0779cc0f) /* 0.467235621 */, 17 },
- /* 3894 */ { MAD_F(0x077a73dd) /* 0.467395654 */, 17 },
- /* 3895 */ { MAD_F(0x077b1baf) /* 0.467555701 */, 17 },
- /* 3896 */ { MAD_F(0x077bc385) /* 0.467715761 */, 17 },
- /* 3897 */ { MAD_F(0x077c6b5f) /* 0.467875835 */, 17 },
- /* 3898 */ { MAD_F(0x077d133c) /* 0.468035922 */, 17 },
- /* 3899 */ { MAD_F(0x077dbb1d) /* 0.468196023 */, 17 },
- /* 3900 */ { MAD_F(0x077e6301) /* 0.468356138 */, 17 },
- /* 3901 */ { MAD_F(0x077f0ae9) /* 0.468516267 */, 17 },
- /* 3902 */ { MAD_F(0x077fb2d5) /* 0.468676409 */, 17 },
- /* 3903 */ { MAD_F(0x07805ac5) /* 0.468836565 */, 17 },
-
- /* 3904 */ { MAD_F(0x078102b8) /* 0.468996735 */, 17 },
- /* 3905 */ { MAD_F(0x0781aaaf) /* 0.469156918 */, 17 },
- /* 3906 */ { MAD_F(0x078252aa) /* 0.469317115 */, 17 },
- /* 3907 */ { MAD_F(0x0782faa8) /* 0.469477326 */, 17 },
- /* 3908 */ { MAD_F(0x0783a2aa) /* 0.469637550 */, 17 },
- /* 3909 */ { MAD_F(0x07844aaf) /* 0.469797788 */, 17 },
- /* 3910 */ { MAD_F(0x0784f2b8) /* 0.469958040 */, 17 },
- /* 3911 */ { MAD_F(0x07859ac5) /* 0.470118305 */, 17 },
- /* 3912 */ { MAD_F(0x078642d6) /* 0.470278584 */, 17 },
- /* 3913 */ { MAD_F(0x0786eaea) /* 0.470438877 */, 17 },
- /* 3914 */ { MAD_F(0x07879302) /* 0.470599183 */, 17 },
- /* 3915 */ { MAD_F(0x07883b1e) /* 0.470759503 */, 17 },
- /* 3916 */ { MAD_F(0x0788e33d) /* 0.470919836 */, 17 },
- /* 3917 */ { MAD_F(0x07898b60) /* 0.471080184 */, 17 },
- /* 3918 */ { MAD_F(0x078a3386) /* 0.471240545 */, 17 },
- /* 3919 */ { MAD_F(0x078adbb0) /* 0.471400919 */, 17 },
-
- /* 3920 */ { MAD_F(0x078b83de) /* 0.471561307 */, 17 },
- /* 3921 */ { MAD_F(0x078c2c10) /* 0.471721709 */, 17 },
- /* 3922 */ { MAD_F(0x078cd445) /* 0.471882125 */, 17 },
- /* 3923 */ { MAD_F(0x078d7c7e) /* 0.472042554 */, 17 },
- /* 3924 */ { MAD_F(0x078e24ba) /* 0.472202996 */, 17 },
- /* 3925 */ { MAD_F(0x078eccfb) /* 0.472363453 */, 17 },
- /* 3926 */ { MAD_F(0x078f753e) /* 0.472523923 */, 17 },
- /* 3927 */ { MAD_F(0x07901d86) /* 0.472684406 */, 17 },
- /* 3928 */ { MAD_F(0x0790c5d1) /* 0.472844904 */, 17 },
- /* 3929 */ { MAD_F(0x07916e20) /* 0.473005414 */, 17 },
- /* 3930 */ { MAD_F(0x07921672) /* 0.473165939 */, 17 },
- /* 3931 */ { MAD_F(0x0792bec8) /* 0.473326477 */, 17 },
- /* 3932 */ { MAD_F(0x07936722) /* 0.473487029 */, 17 },
- /* 3933 */ { MAD_F(0x07940f80) /* 0.473647594 */, 17 },
- /* 3934 */ { MAD_F(0x0794b7e1) /* 0.473808173 */, 17 },
- /* 3935 */ { MAD_F(0x07956045) /* 0.473968765 */, 17 },
-
- /* 3936 */ { MAD_F(0x079608ae) /* 0.474129372 */, 17 },
- /* 3937 */ { MAD_F(0x0796b11a) /* 0.474289991 */, 17 },
- /* 3938 */ { MAD_F(0x0797598a) /* 0.474450625 */, 17 },
- /* 3939 */ { MAD_F(0x079801fd) /* 0.474611272 */, 17 },
- /* 3940 */ { MAD_F(0x0798aa74) /* 0.474771932 */, 17 },
- /* 3941 */ { MAD_F(0x079952ee) /* 0.474932606 */, 17 },
- /* 3942 */ { MAD_F(0x0799fb6d) /* 0.475093294 */, 17 },
- /* 3943 */ { MAD_F(0x079aa3ef) /* 0.475253995 */, 17 },
- /* 3944 */ { MAD_F(0x079b4c74) /* 0.475414710 */, 17 },
- /* 3945 */ { MAD_F(0x079bf4fd) /* 0.475575439 */, 17 },
- /* 3946 */ { MAD_F(0x079c9d8a) /* 0.475736181 */, 17 },
- /* 3947 */ { MAD_F(0x079d461b) /* 0.475896936 */, 17 },
- /* 3948 */ { MAD_F(0x079deeaf) /* 0.476057705 */, 17 },
- /* 3949 */ { MAD_F(0x079e9747) /* 0.476218488 */, 17 },
- /* 3950 */ { MAD_F(0x079f3fe2) /* 0.476379285 */, 17 },
- /* 3951 */ { MAD_F(0x079fe881) /* 0.476540095 */, 17 },
-
- /* 3952 */ { MAD_F(0x07a09124) /* 0.476700918 */, 17 },
- /* 3953 */ { MAD_F(0x07a139ca) /* 0.476861755 */, 17 },
- /* 3954 */ { MAD_F(0x07a1e274) /* 0.477022606 */, 17 },
- /* 3955 */ { MAD_F(0x07a28b22) /* 0.477183470 */, 17 },
- /* 3956 */ { MAD_F(0x07a333d3) /* 0.477344348 */, 17 },
- /* 3957 */ { MAD_F(0x07a3dc88) /* 0.477505239 */, 17 },
- /* 3958 */ { MAD_F(0x07a48541) /* 0.477666144 */, 17 },
- /* 3959 */ { MAD_F(0x07a52dfd) /* 0.477827062 */, 17 },
- /* 3960 */ { MAD_F(0x07a5d6bd) /* 0.477987994 */, 17 },
- /* 3961 */ { MAD_F(0x07a67f80) /* 0.478148940 */, 17 },
- /* 3962 */ { MAD_F(0x07a72847) /* 0.478309899 */, 17 },
- /* 3963 */ { MAD_F(0x07a7d112) /* 0.478470871 */, 17 },
- /* 3964 */ { MAD_F(0x07a879e1) /* 0.478631857 */, 17 },
- /* 3965 */ { MAD_F(0x07a922b3) /* 0.478792857 */, 17 },
- /* 3966 */ { MAD_F(0x07a9cb88) /* 0.478953870 */, 17 },
- /* 3967 */ { MAD_F(0x07aa7462) /* 0.479114897 */, 17 },
-
- /* 3968 */ { MAD_F(0x07ab1d3e) /* 0.479275937 */, 17 },
- /* 3969 */ { MAD_F(0x07abc61f) /* 0.479436991 */, 17 },
- /* 3970 */ { MAD_F(0x07ac6f03) /* 0.479598058 */, 17 },
- /* 3971 */ { MAD_F(0x07ad17eb) /* 0.479759139 */, 17 },
- /* 3972 */ { MAD_F(0x07adc0d6) /* 0.479920233 */, 17 },
- /* 3973 */ { MAD_F(0x07ae69c6) /* 0.480081341 */, 17 },
- /* 3974 */ { MAD_F(0x07af12b8) /* 0.480242463 */, 17 },
- /* 3975 */ { MAD_F(0x07afbbaf) /* 0.480403598 */, 17 },
- /* 3976 */ { MAD_F(0x07b064a8) /* 0.480564746 */, 17 },
- /* 3977 */ { MAD_F(0x07b10da6) /* 0.480725908 */, 17 },
- /* 3978 */ { MAD_F(0x07b1b6a7) /* 0.480887083 */, 17 },
- /* 3979 */ { MAD_F(0x07b25fac) /* 0.481048272 */, 17 },
- /* 3980 */ { MAD_F(0x07b308b5) /* 0.481209475 */, 17 },
- /* 3981 */ { MAD_F(0x07b3b1c1) /* 0.481370691 */, 17 },
- /* 3982 */ { MAD_F(0x07b45ad0) /* 0.481531920 */, 17 },
- /* 3983 */ { MAD_F(0x07b503e4) /* 0.481693163 */, 17 },
-
- /* 3984 */ { MAD_F(0x07b5acfb) /* 0.481854420 */, 17 },
- /* 3985 */ { MAD_F(0x07b65615) /* 0.482015690 */, 17 },
- /* 3986 */ { MAD_F(0x07b6ff33) /* 0.482176973 */, 17 },
- /* 3987 */ { MAD_F(0x07b7a855) /* 0.482338270 */, 17 },
- /* 3988 */ { MAD_F(0x07b8517b) /* 0.482499580 */, 17 },
- /* 3989 */ { MAD_F(0x07b8faa4) /* 0.482660904 */, 17 },
- /* 3990 */ { MAD_F(0x07b9a3d0) /* 0.482822242 */, 17 },
- /* 3991 */ { MAD_F(0x07ba4d01) /* 0.482983592 */, 17 },
- /* 3992 */ { MAD_F(0x07baf635) /* 0.483144957 */, 17 },
- /* 3993 */ { MAD_F(0x07bb9f6c) /* 0.483306335 */, 17 },
- /* 3994 */ { MAD_F(0x07bc48a7) /* 0.483467726 */, 17 },
- /* 3995 */ { MAD_F(0x07bcf1e6) /* 0.483629131 */, 17 },
- /* 3996 */ { MAD_F(0x07bd9b28) /* 0.483790549 */, 17 },
- /* 3997 */ { MAD_F(0x07be446e) /* 0.483951980 */, 17 },
- /* 3998 */ { MAD_F(0x07beedb8) /* 0.484113426 */, 17 },
- /* 3999 */ { MAD_F(0x07bf9705) /* 0.484274884 */, 17 },
-
- /* 4000 */ { MAD_F(0x07c04056) /* 0.484436356 */, 17 },
- /* 4001 */ { MAD_F(0x07c0e9aa) /* 0.484597842 */, 17 },
- /* 4002 */ { MAD_F(0x07c19302) /* 0.484759341 */, 17 },
- /* 4003 */ { MAD_F(0x07c23c5e) /* 0.484920853 */, 17 },
- /* 4004 */ { MAD_F(0x07c2e5bd) /* 0.485082379 */, 17 },
- /* 4005 */ { MAD_F(0x07c38f20) /* 0.485243918 */, 17 },
- /* 4006 */ { MAD_F(0x07c43887) /* 0.485405471 */, 17 },
- /* 4007 */ { MAD_F(0x07c4e1f1) /* 0.485567037 */, 17 },
- /* 4008 */ { MAD_F(0x07c58b5f) /* 0.485728617 */, 17 },
- /* 4009 */ { MAD_F(0x07c634d0) /* 0.485890210 */, 17 },
- /* 4010 */ { MAD_F(0x07c6de45) /* 0.486051817 */, 17 },
- /* 4011 */ { MAD_F(0x07c787bd) /* 0.486213436 */, 17 },
- /* 4012 */ { MAD_F(0x07c83139) /* 0.486375070 */, 17 },
- /* 4013 */ { MAD_F(0x07c8dab9) /* 0.486536717 */, 17 },
- /* 4014 */ { MAD_F(0x07c9843c) /* 0.486698377 */, 17 },
- /* 4015 */ { MAD_F(0x07ca2dc3) /* 0.486860051 */, 17 },
-
- /* 4016 */ { MAD_F(0x07cad74e) /* 0.487021738 */, 17 },
- /* 4017 */ { MAD_F(0x07cb80dc) /* 0.487183438 */, 17 },
- /* 4018 */ { MAD_F(0x07cc2a6e) /* 0.487345152 */, 17 },
- /* 4019 */ { MAD_F(0x07ccd403) /* 0.487506879 */, 17 },
- /* 4020 */ { MAD_F(0x07cd7d9c) /* 0.487668620 */, 17 },
- /* 4021 */ { MAD_F(0x07ce2739) /* 0.487830374 */, 17 },
- /* 4022 */ { MAD_F(0x07ced0d9) /* 0.487992142 */, 17 },
- /* 4023 */ { MAD_F(0x07cf7a7d) /* 0.488153923 */, 17 },
- /* 4024 */ { MAD_F(0x07d02424) /* 0.488315717 */, 17 },
- /* 4025 */ { MAD_F(0x07d0cdcf) /* 0.488477525 */, 17 },
- /* 4026 */ { MAD_F(0x07d1777e) /* 0.488639346 */, 17 },
- /* 4027 */ { MAD_F(0x07d22130) /* 0.488801181 */, 17 },
- /* 4028 */ { MAD_F(0x07d2cae5) /* 0.488963029 */, 17 },
- /* 4029 */ { MAD_F(0x07d3749f) /* 0.489124890 */, 17 },
- /* 4030 */ { MAD_F(0x07d41e5c) /* 0.489286765 */, 17 },
- /* 4031 */ { MAD_F(0x07d4c81c) /* 0.489448653 */, 17 },
-
- /* 4032 */ { MAD_F(0x07d571e0) /* 0.489610555 */, 17 },
- /* 4033 */ { MAD_F(0x07d61ba8) /* 0.489772470 */, 17 },
- /* 4034 */ { MAD_F(0x07d6c573) /* 0.489934398 */, 17 },
- /* 4035 */ { MAD_F(0x07d76f42) /* 0.490096340 */, 17 },
- /* 4036 */ { MAD_F(0x07d81915) /* 0.490258295 */, 17 },
- /* 4037 */ { MAD_F(0x07d8c2eb) /* 0.490420263 */, 17 },
- /* 4038 */ { MAD_F(0x07d96cc4) /* 0.490582245 */, 17 },
- /* 4039 */ { MAD_F(0x07da16a2) /* 0.490744240 */, 17 },
- /* 4040 */ { MAD_F(0x07dac083) /* 0.490906249 */, 17 },
- /* 4041 */ { MAD_F(0x07db6a67) /* 0.491068271 */, 17 },
- /* 4042 */ { MAD_F(0x07dc144f) /* 0.491230306 */, 17 },
- /* 4043 */ { MAD_F(0x07dcbe3b) /* 0.491392355 */, 17 },
- /* 4044 */ { MAD_F(0x07dd682a) /* 0.491554417 */, 17 },
- /* 4045 */ { MAD_F(0x07de121d) /* 0.491716492 */, 17 },
- /* 4046 */ { MAD_F(0x07debc13) /* 0.491878581 */, 17 },
- /* 4047 */ { MAD_F(0x07df660d) /* 0.492040683 */, 17 },
-
- /* 4048 */ { MAD_F(0x07e0100a) /* 0.492202799 */, 17 },
- /* 4049 */ { MAD_F(0x07e0ba0c) /* 0.492364928 */, 17 },
- /* 4050 */ { MAD_F(0x07e16410) /* 0.492527070 */, 17 },
- /* 4051 */ { MAD_F(0x07e20e19) /* 0.492689225 */, 17 },
- /* 4052 */ { MAD_F(0x07e2b824) /* 0.492851394 */, 17 },
- /* 4053 */ { MAD_F(0x07e36234) /* 0.493013576 */, 17 },
- /* 4054 */ { MAD_F(0x07e40c47) /* 0.493175772 */, 17 },
- /* 4055 */ { MAD_F(0x07e4b65e) /* 0.493337981 */, 17 },
- /* 4056 */ { MAD_F(0x07e56078) /* 0.493500203 */, 17 },
- /* 4057 */ { MAD_F(0x07e60a95) /* 0.493662438 */, 17 },
- /* 4058 */ { MAD_F(0x07e6b4b7) /* 0.493824687 */, 17 },
- /* 4059 */ { MAD_F(0x07e75edc) /* 0.493986949 */, 17 },
- /* 4060 */ { MAD_F(0x07e80904) /* 0.494149225 */, 17 },
- /* 4061 */ { MAD_F(0x07e8b330) /* 0.494311514 */, 17 },
- /* 4062 */ { MAD_F(0x07e95d60) /* 0.494473816 */, 17 },
- /* 4063 */ { MAD_F(0x07ea0793) /* 0.494636131 */, 17 },
-
- /* 4064 */ { MAD_F(0x07eab1ca) /* 0.494798460 */, 17 },
- /* 4065 */ { MAD_F(0x07eb5c04) /* 0.494960802 */, 17 },
- /* 4066 */ { MAD_F(0x07ec0642) /* 0.495123158 */, 17 },
- /* 4067 */ { MAD_F(0x07ecb084) /* 0.495285526 */, 17 },
- /* 4068 */ { MAD_F(0x07ed5ac9) /* 0.495447908 */, 17 },
- /* 4069 */ { MAD_F(0x07ee0512) /* 0.495610304 */, 17 },
- /* 4070 */ { MAD_F(0x07eeaf5e) /* 0.495772712 */, 17 },
- /* 4071 */ { MAD_F(0x07ef59ae) /* 0.495935134 */, 17 },
- /* 4072 */ { MAD_F(0x07f00401) /* 0.496097570 */, 17 },
- /* 4073 */ { MAD_F(0x07f0ae58) /* 0.496260018 */, 17 },
- /* 4074 */ { MAD_F(0x07f158b3) /* 0.496422480 */, 17 },
- /* 4075 */ { MAD_F(0x07f20311) /* 0.496584955 */, 17 },
- /* 4076 */ { MAD_F(0x07f2ad72) /* 0.496747444 */, 17 },
- /* 4077 */ { MAD_F(0x07f357d8) /* 0.496909945 */, 17 },
- /* 4078 */ { MAD_F(0x07f40240) /* 0.497072460 */, 17 },
- /* 4079 */ { MAD_F(0x07f4acad) /* 0.497234989 */, 17 },
-
- /* 4080 */ { MAD_F(0x07f5571d) /* 0.497397530 */, 17 },
- /* 4081 */ { MAD_F(0x07f60190) /* 0.497560085 */, 17 },
- /* 4082 */ { MAD_F(0x07f6ac07) /* 0.497722653 */, 17 },
- /* 4083 */ { MAD_F(0x07f75682) /* 0.497885235 */, 17 },
- /* 4084 */ { MAD_F(0x07f80100) /* 0.498047829 */, 17 },
- /* 4085 */ { MAD_F(0x07f8ab82) /* 0.498210437 */, 17 },
- /* 4086 */ { MAD_F(0x07f95607) /* 0.498373058 */, 17 },
- /* 4087 */ { MAD_F(0x07fa0090) /* 0.498535693 */, 17 },
- /* 4088 */ { MAD_F(0x07faab1c) /* 0.498698341 */, 17 },
- /* 4089 */ { MAD_F(0x07fb55ac) /* 0.498861002 */, 17 },
- /* 4090 */ { MAD_F(0x07fc0040) /* 0.499023676 */, 17 },
- /* 4091 */ { MAD_F(0x07fcaad7) /* 0.499186364 */, 17 },
- /* 4092 */ { MAD_F(0x07fd5572) /* 0.499349064 */, 17 },
- /* 4093 */ { MAD_F(0x07fe0010) /* 0.499511778 */, 17 },
- /* 4094 */ { MAD_F(0x07feaab2) /* 0.499674506 */, 17 },
- /* 4095 */ { MAD_F(0x07ff5557) /* 0.499837246 */, 17 },
-
- /* 4096 */ { MAD_F(0x04000000) /* 0.250000000 */, 18 },
- /* 4097 */ { MAD_F(0x04005556) /* 0.250081384 */, 18 },
- /* 4098 */ { MAD_F(0x0400aaae) /* 0.250162774 */, 18 },
- /* 4099 */ { MAD_F(0x04010008) /* 0.250244170 */, 18 },
- /* 4100 */ { MAD_F(0x04015563) /* 0.250325574 */, 18 },
- /* 4101 */ { MAD_F(0x0401aac1) /* 0.250406984 */, 18 },
- /* 4102 */ { MAD_F(0x04020020) /* 0.250488400 */, 18 },
- /* 4103 */ { MAD_F(0x04025581) /* 0.250569824 */, 18 },
- /* 4104 */ { MAD_F(0x0402aae3) /* 0.250651254 */, 18 },
- /* 4105 */ { MAD_F(0x04030048) /* 0.250732690 */, 18 },
- /* 4106 */ { MAD_F(0x040355ae) /* 0.250814133 */, 18 },
- /* 4107 */ { MAD_F(0x0403ab16) /* 0.250895583 */, 18 },
- /* 4108 */ { MAD_F(0x04040080) /* 0.250977039 */, 18 },
- /* 4109 */ { MAD_F(0x040455eb) /* 0.251058502 */, 18 },
- /* 4110 */ { MAD_F(0x0404ab59) /* 0.251139971 */, 18 },
- /* 4111 */ { MAD_F(0x040500c8) /* 0.251221448 */, 18 },
-
- /* 4112 */ { MAD_F(0x04055638) /* 0.251302930 */, 18 },
- /* 4113 */ { MAD_F(0x0405abab) /* 0.251384420 */, 18 },
- /* 4114 */ { MAD_F(0x0406011f) /* 0.251465916 */, 18 },
- /* 4115 */ { MAD_F(0x04065696) /* 0.251547418 */, 18 },
- /* 4116 */ { MAD_F(0x0406ac0e) /* 0.251628927 */, 18 },
- /* 4117 */ { MAD_F(0x04070187) /* 0.251710443 */, 18 },
- /* 4118 */ { MAD_F(0x04075703) /* 0.251791965 */, 18 },
- /* 4119 */ { MAD_F(0x0407ac80) /* 0.251873494 */, 18 },
- /* 4120 */ { MAD_F(0x040801ff) /* 0.251955030 */, 18 },
- /* 4121 */ { MAD_F(0x04085780) /* 0.252036572 */, 18 },
- /* 4122 */ { MAD_F(0x0408ad02) /* 0.252118121 */, 18 },
- /* 4123 */ { MAD_F(0x04090287) /* 0.252199676 */, 18 },
- /* 4124 */ { MAD_F(0x0409580d) /* 0.252281238 */, 18 },
- /* 4125 */ { MAD_F(0x0409ad95) /* 0.252362807 */, 18 },
- /* 4126 */ { MAD_F(0x040a031e) /* 0.252444382 */, 18 },
- /* 4127 */ { MAD_F(0x040a58aa) /* 0.252525963 */, 18 },
-
- /* 4128 */ { MAD_F(0x040aae37) /* 0.252607552 */, 18 },
- /* 4129 */ { MAD_F(0x040b03c6) /* 0.252689147 */, 18 },
- /* 4130 */ { MAD_F(0x040b5957) /* 0.252770748 */, 18 },
- /* 4131 */ { MAD_F(0x040baee9) /* 0.252852356 */, 18 },
- /* 4132 */ { MAD_F(0x040c047e) /* 0.252933971 */, 18 },
- /* 4133 */ { MAD_F(0x040c5a14) /* 0.253015592 */, 18 },
- /* 4134 */ { MAD_F(0x040cafab) /* 0.253097220 */, 18 },
- /* 4135 */ { MAD_F(0x040d0545) /* 0.253178854 */, 18 },
- /* 4136 */ { MAD_F(0x040d5ae0) /* 0.253260495 */, 18 },
- /* 4137 */ { MAD_F(0x040db07d) /* 0.253342143 */, 18 },
- /* 4138 */ { MAD_F(0x040e061c) /* 0.253423797 */, 18 },
- /* 4139 */ { MAD_F(0x040e5bbd) /* 0.253505457 */, 18 },
- /* 4140 */ { MAD_F(0x040eb15f) /* 0.253587125 */, 18 },
- /* 4141 */ { MAD_F(0x040f0703) /* 0.253668799 */, 18 },
- /* 4142 */ { MAD_F(0x040f5ca9) /* 0.253750479 */, 18 },
- /* 4143 */ { MAD_F(0x040fb251) /* 0.253832166 */, 18 },
-
- /* 4144 */ { MAD_F(0x041007fa) /* 0.253913860 */, 18 },
- /* 4145 */ { MAD_F(0x04105da6) /* 0.253995560 */, 18 },
- /* 4146 */ { MAD_F(0x0410b353) /* 0.254077266 */, 18 },
- /* 4147 */ { MAD_F(0x04110901) /* 0.254158980 */, 18 },
- /* 4148 */ { MAD_F(0x04115eb2) /* 0.254240700 */, 18 },
- /* 4149 */ { MAD_F(0x0411b464) /* 0.254322426 */, 18 },
- /* 4150 */ { MAD_F(0x04120a18) /* 0.254404159 */, 18 },
- /* 4151 */ { MAD_F(0x04125fce) /* 0.254485899 */, 18 },
- /* 4152 */ { MAD_F(0x0412b586) /* 0.254567645 */, 18 },
- /* 4153 */ { MAD_F(0x04130b3f) /* 0.254649397 */, 18 },
- /* 4154 */ { MAD_F(0x041360fa) /* 0.254731157 */, 18 },
- /* 4155 */ { MAD_F(0x0413b6b7) /* 0.254812922 */, 18 },
- /* 4156 */ { MAD_F(0x04140c75) /* 0.254894695 */, 18 },
- /* 4157 */ { MAD_F(0x04146236) /* 0.254976474 */, 18 },
- /* 4158 */ { MAD_F(0x0414b7f8) /* 0.255058259 */, 18 },
- /* 4159 */ { MAD_F(0x04150dbc) /* 0.255140051 */, 18 },
-
- /* 4160 */ { MAD_F(0x04156381) /* 0.255221850 */, 18 },
- /* 4161 */ { MAD_F(0x0415b949) /* 0.255303655 */, 18 },
- /* 4162 */ { MAD_F(0x04160f12) /* 0.255385467 */, 18 },
- /* 4163 */ { MAD_F(0x041664dd) /* 0.255467285 */, 18 },
- /* 4164 */ { MAD_F(0x0416baaa) /* 0.255549110 */, 18 },
- /* 4165 */ { MAD_F(0x04171078) /* 0.255630941 */, 18 },
- /* 4166 */ { MAD_F(0x04176648) /* 0.255712779 */, 18 },
- /* 4167 */ { MAD_F(0x0417bc1a) /* 0.255794624 */, 18 },
- /* 4168 */ { MAD_F(0x041811ee) /* 0.255876475 */, 18 },
- /* 4169 */ { MAD_F(0x041867c3) /* 0.255958332 */, 18 },
- /* 4170 */ { MAD_F(0x0418bd9b) /* 0.256040196 */, 18 },
- /* 4171 */ { MAD_F(0x04191374) /* 0.256122067 */, 18 },
- /* 4172 */ { MAD_F(0x0419694e) /* 0.256203944 */, 18 },
- /* 4173 */ { MAD_F(0x0419bf2b) /* 0.256285828 */, 18 },
- /* 4174 */ { MAD_F(0x041a1509) /* 0.256367718 */, 18 },
- /* 4175 */ { MAD_F(0x041a6ae9) /* 0.256449615 */, 18 },
-
- /* 4176 */ { MAD_F(0x041ac0cb) /* 0.256531518 */, 18 },
- /* 4177 */ { MAD_F(0x041b16ae) /* 0.256613428 */, 18 },
- /* 4178 */ { MAD_F(0x041b6c94) /* 0.256695344 */, 18 },
- /* 4179 */ { MAD_F(0x041bc27b) /* 0.256777267 */, 18 },
- /* 4180 */ { MAD_F(0x041c1863) /* 0.256859197 */, 18 },
- /* 4181 */ { MAD_F(0x041c6e4e) /* 0.256941133 */, 18 },
- /* 4182 */ { MAD_F(0x041cc43a) /* 0.257023076 */, 18 },
- /* 4183 */ { MAD_F(0x041d1a28) /* 0.257105025 */, 18 },
- /* 4184 */ { MAD_F(0x041d7018) /* 0.257186980 */, 18 },
- /* 4185 */ { MAD_F(0x041dc60a) /* 0.257268942 */, 18 },
- /* 4186 */ { MAD_F(0x041e1bfd) /* 0.257350911 */, 18 },
- /* 4187 */ { MAD_F(0x041e71f2) /* 0.257432886 */, 18 },
- /* 4188 */ { MAD_F(0x041ec7e9) /* 0.257514868 */, 18 },
- /* 4189 */ { MAD_F(0x041f1de1) /* 0.257596856 */, 18 },
- /* 4190 */ { MAD_F(0x041f73dc) /* 0.257678851 */, 18 },
- /* 4191 */ { MAD_F(0x041fc9d8) /* 0.257760852 */, 18 },
-
- /* 4192 */ { MAD_F(0x04201fd5) /* 0.257842860 */, 18 },
- /* 4193 */ { MAD_F(0x042075d5) /* 0.257924875 */, 18 },
- /* 4194 */ { MAD_F(0x0420cbd6) /* 0.258006895 */, 18 },
- /* 4195 */ { MAD_F(0x042121d9) /* 0.258088923 */, 18 },
- /* 4196 */ { MAD_F(0x042177de) /* 0.258170957 */, 18 },
- /* 4197 */ { MAD_F(0x0421cde5) /* 0.258252997 */, 18 },
- /* 4198 */ { MAD_F(0x042223ed) /* 0.258335044 */, 18 },
- /* 4199 */ { MAD_F(0x042279f7) /* 0.258417097 */, 18 },
- /* 4200 */ { MAD_F(0x0422d003) /* 0.258499157 */, 18 },
- /* 4201 */ { MAD_F(0x04232611) /* 0.258581224 */, 18 },
- /* 4202 */ { MAD_F(0x04237c20) /* 0.258663297 */, 18 },
- /* 4203 */ { MAD_F(0x0423d231) /* 0.258745376 */, 18 },
- /* 4204 */ { MAD_F(0x04242844) /* 0.258827462 */, 18 },
- /* 4205 */ { MAD_F(0x04247e58) /* 0.258909555 */, 18 },
- /* 4206 */ { MAD_F(0x0424d46e) /* 0.258991654 */, 18 },
- /* 4207 */ { MAD_F(0x04252a87) /* 0.259073760 */, 18 },
-
- /* 4208 */ { MAD_F(0x042580a0) /* 0.259155872 */, 18 },
- /* 4209 */ { MAD_F(0x0425d6bc) /* 0.259237990 */, 18 },
- /* 4210 */ { MAD_F(0x04262cd9) /* 0.259320115 */, 18 },
- /* 4211 */ { MAD_F(0x042682f8) /* 0.259402247 */, 18 },
- /* 4212 */ { MAD_F(0x0426d919) /* 0.259484385 */, 18 },
- /* 4213 */ { MAD_F(0x04272f3b) /* 0.259566529 */, 18 },
- /* 4214 */ { MAD_F(0x04278560) /* 0.259648680 */, 18 },
- /* 4215 */ { MAD_F(0x0427db86) /* 0.259730838 */, 18 },
- /* 4216 */ { MAD_F(0x042831ad) /* 0.259813002 */, 18 },
- /* 4217 */ { MAD_F(0x042887d7) /* 0.259895173 */, 18 },
- /* 4218 */ { MAD_F(0x0428de02) /* 0.259977350 */, 18 },
- /* 4219 */ { MAD_F(0x0429342f) /* 0.260059533 */, 18 },
- /* 4220 */ { MAD_F(0x04298a5e) /* 0.260141723 */, 18 },
- /* 4221 */ { MAD_F(0x0429e08e) /* 0.260223920 */, 18 },
- /* 4222 */ { MAD_F(0x042a36c0) /* 0.260306123 */, 18 },
- /* 4223 */ { MAD_F(0x042a8cf4) /* 0.260388332 */, 18 },
-
- /* 4224 */ { MAD_F(0x042ae32a) /* 0.260470548 */, 18 },
- /* 4225 */ { MAD_F(0x042b3962) /* 0.260552771 */, 18 },
- /* 4226 */ { MAD_F(0x042b8f9b) /* 0.260635000 */, 18 },
- /* 4227 */ { MAD_F(0x042be5d6) /* 0.260717235 */, 18 },
- /* 4228 */ { MAD_F(0x042c3c12) /* 0.260799477 */, 18 },
- /* 4229 */ { MAD_F(0x042c9251) /* 0.260881725 */, 18 },
- /* 4230 */ { MAD_F(0x042ce891) /* 0.260963980 */, 18 },
- /* 4231 */ { MAD_F(0x042d3ed3) /* 0.261046242 */, 18 },
- /* 4232 */ { MAD_F(0x042d9516) /* 0.261128510 */, 18 },
- /* 4233 */ { MAD_F(0x042deb5c) /* 0.261210784 */, 18 },
- /* 4234 */ { MAD_F(0x042e41a3) /* 0.261293065 */, 18 },
- /* 4235 */ { MAD_F(0x042e97ec) /* 0.261375352 */, 18 },
- /* 4236 */ { MAD_F(0x042eee36) /* 0.261457646 */, 18 },
- /* 4237 */ { MAD_F(0x042f4482) /* 0.261539946 */, 18 },
- /* 4238 */ { MAD_F(0x042f9ad1) /* 0.261622253 */, 18 },
- /* 4239 */ { MAD_F(0x042ff120) /* 0.261704566 */, 18 },
-
- /* 4240 */ { MAD_F(0x04304772) /* 0.261786886 */, 18 },
- /* 4241 */ { MAD_F(0x04309dc5) /* 0.261869212 */, 18 },
- /* 4242 */ { MAD_F(0x0430f41a) /* 0.261951545 */, 18 },
- /* 4243 */ { MAD_F(0x04314a71) /* 0.262033884 */, 18 },
- /* 4244 */ { MAD_F(0x0431a0c9) /* 0.262116229 */, 18 },
- /* 4245 */ { MAD_F(0x0431f723) /* 0.262198581 */, 18 },
- /* 4246 */ { MAD_F(0x04324d7f) /* 0.262280940 */, 18 },
- /* 4247 */ { MAD_F(0x0432a3dd) /* 0.262363305 */, 18 },
- /* 4248 */ { MAD_F(0x0432fa3d) /* 0.262445676 */, 18 },
- /* 4249 */ { MAD_F(0x0433509e) /* 0.262528054 */, 18 },
- /* 4250 */ { MAD_F(0x0433a701) /* 0.262610438 */, 18 },
- /* 4251 */ { MAD_F(0x0433fd65) /* 0.262692829 */, 18 },
- /* 4252 */ { MAD_F(0x043453cc) /* 0.262775227 */, 18 },
- /* 4253 */ { MAD_F(0x0434aa34) /* 0.262857630 */, 18 },
- /* 4254 */ { MAD_F(0x0435009d) /* 0.262940040 */, 18 },
- /* 4255 */ { MAD_F(0x04355709) /* 0.263022457 */, 18 },
-
- /* 4256 */ { MAD_F(0x0435ad76) /* 0.263104880 */, 18 },
- /* 4257 */ { MAD_F(0x043603e5) /* 0.263187310 */, 18 },
- /* 4258 */ { MAD_F(0x04365a56) /* 0.263269746 */, 18 },
- /* 4259 */ { MAD_F(0x0436b0c9) /* 0.263352188 */, 18 },
- /* 4260 */ { MAD_F(0x0437073d) /* 0.263434637 */, 18 },
- /* 4261 */ { MAD_F(0x04375db3) /* 0.263517093 */, 18 },
- /* 4262 */ { MAD_F(0x0437b42a) /* 0.263599554 */, 18 },
- /* 4263 */ { MAD_F(0x04380aa4) /* 0.263682023 */, 18 },
- /* 4264 */ { MAD_F(0x0438611f) /* 0.263764497 */, 18 },
- /* 4265 */ { MAD_F(0x0438b79c) /* 0.263846979 */, 18 },
- /* 4266 */ { MAD_F(0x04390e1a) /* 0.263929466 */, 18 },
- /* 4267 */ { MAD_F(0x0439649b) /* 0.264011960 */, 18 },
- /* 4268 */ { MAD_F(0x0439bb1d) /* 0.264094461 */, 18 },
- /* 4269 */ { MAD_F(0x043a11a1) /* 0.264176968 */, 18 },
- /* 4270 */ { MAD_F(0x043a6826) /* 0.264259481 */, 18 },
- /* 4271 */ { MAD_F(0x043abead) /* 0.264342001 */, 18 },
-
- /* 4272 */ { MAD_F(0x043b1536) /* 0.264424527 */, 18 },
- /* 4273 */ { MAD_F(0x043b6bc1) /* 0.264507060 */, 18 },
- /* 4274 */ { MAD_F(0x043bc24d) /* 0.264589599 */, 18 },
- /* 4275 */ { MAD_F(0x043c18dc) /* 0.264672145 */, 18 },
- /* 4276 */ { MAD_F(0x043c6f6c) /* 0.264754697 */, 18 },
- /* 4277 */ { MAD_F(0x043cc5fd) /* 0.264837255 */, 18 },
- /* 4278 */ { MAD_F(0x043d1c91) /* 0.264919820 */, 18 },
- /* 4279 */ { MAD_F(0x043d7326) /* 0.265002392 */, 18 },
- /* 4280 */ { MAD_F(0x043dc9bc) /* 0.265084969 */, 18 },
- /* 4281 */ { MAD_F(0x043e2055) /* 0.265167554 */, 18 },
- /* 4282 */ { MAD_F(0x043e76ef) /* 0.265250144 */, 18 },
- /* 4283 */ { MAD_F(0x043ecd8b) /* 0.265332741 */, 18 },
- /* 4284 */ { MAD_F(0x043f2429) /* 0.265415345 */, 18 },
- /* 4285 */ { MAD_F(0x043f7ac8) /* 0.265497955 */, 18 },
- /* 4286 */ { MAD_F(0x043fd169) /* 0.265580571 */, 18 },
- /* 4287 */ { MAD_F(0x0440280c) /* 0.265663194 */, 18 },
-
- /* 4288 */ { MAD_F(0x04407eb1) /* 0.265745823 */, 18 },
- /* 4289 */ { MAD_F(0x0440d557) /* 0.265828459 */, 18 },
- /* 4290 */ { MAD_F(0x04412bff) /* 0.265911101 */, 18 },
- /* 4291 */ { MAD_F(0x044182a9) /* 0.265993749 */, 18 },
- /* 4292 */ { MAD_F(0x0441d955) /* 0.266076404 */, 18 },
- /* 4293 */ { MAD_F(0x04423002) /* 0.266159065 */, 18 },
- /* 4294 */ { MAD_F(0x044286b1) /* 0.266241733 */, 18 },
- /* 4295 */ { MAD_F(0x0442dd61) /* 0.266324407 */, 18 },
- /* 4296 */ { MAD_F(0x04433414) /* 0.266407088 */, 18 },
- /* 4297 */ { MAD_F(0x04438ac8) /* 0.266489775 */, 18 },
- /* 4298 */ { MAD_F(0x0443e17e) /* 0.266572468 */, 18 },
- /* 4299 */ { MAD_F(0x04443835) /* 0.266655168 */, 18 },
- /* 4300 */ { MAD_F(0x04448eef) /* 0.266737874 */, 18 },
- /* 4301 */ { MAD_F(0x0444e5aa) /* 0.266820587 */, 18 },
- /* 4302 */ { MAD_F(0x04453c66) /* 0.266903306 */, 18 },
- /* 4303 */ { MAD_F(0x04459325) /* 0.266986031 */, 18 },
-
- /* 4304 */ { MAD_F(0x0445e9e5) /* 0.267068763 */, 18 },
- /* 4305 */ { MAD_F(0x044640a7) /* 0.267151501 */, 18 },
- /* 4306 */ { MAD_F(0x0446976a) /* 0.267234246 */, 18 },
- /* 4307 */ { MAD_F(0x0446ee30) /* 0.267316997 */, 18 },
- /* 4308 */ { MAD_F(0x044744f7) /* 0.267399755 */, 18 },
- /* 4309 */ { MAD_F(0x04479bc0) /* 0.267482518 */, 18 },
- /* 4310 */ { MAD_F(0x0447f28a) /* 0.267565289 */, 18 },
- /* 4311 */ { MAD_F(0x04484956) /* 0.267648065 */, 18 },
- /* 4312 */ { MAD_F(0x0448a024) /* 0.267730848 */, 18 },
- /* 4313 */ { MAD_F(0x0448f6f4) /* 0.267813638 */, 18 },
- /* 4314 */ { MAD_F(0x04494dc5) /* 0.267896434 */, 18 },
- /* 4315 */ { MAD_F(0x0449a498) /* 0.267979236 */, 18 },
- /* 4316 */ { MAD_F(0x0449fb6d) /* 0.268062045 */, 18 },
- /* 4317 */ { MAD_F(0x044a5243) /* 0.268144860 */, 18 },
- /* 4318 */ { MAD_F(0x044aa91c) /* 0.268227681 */, 18 },
- /* 4319 */ { MAD_F(0x044afff6) /* 0.268310509 */, 18 },
-
- /* 4320 */ { MAD_F(0x044b56d1) /* 0.268393343 */, 18 },
- /* 4321 */ { MAD_F(0x044badaf) /* 0.268476184 */, 18 },
- /* 4322 */ { MAD_F(0x044c048e) /* 0.268559031 */, 18 },
- /* 4323 */ { MAD_F(0x044c5b6f) /* 0.268641885 */, 18 },
- /* 4324 */ { MAD_F(0x044cb251) /* 0.268724744 */, 18 },
- /* 4325 */ { MAD_F(0x044d0935) /* 0.268807611 */, 18 },
- /* 4326 */ { MAD_F(0x044d601b) /* 0.268890483 */, 18 },
- /* 4327 */ { MAD_F(0x044db703) /* 0.268973362 */, 18 },
- /* 4328 */ { MAD_F(0x044e0dec) /* 0.269056248 */, 18 },
- /* 4329 */ { MAD_F(0x044e64d7) /* 0.269139139 */, 18 },
- /* 4330 */ { MAD_F(0x044ebbc4) /* 0.269222037 */, 18 },
- /* 4331 */ { MAD_F(0x044f12b3) /* 0.269304942 */, 18 },
- /* 4332 */ { MAD_F(0x044f69a3) /* 0.269387853 */, 18 },
- /* 4333 */ { MAD_F(0x044fc095) /* 0.269470770 */, 18 },
- /* 4334 */ { MAD_F(0x04501788) /* 0.269553694 */, 18 },
- /* 4335 */ { MAD_F(0x04506e7e) /* 0.269636624 */, 18 },
-
- /* 4336 */ { MAD_F(0x0450c575) /* 0.269719560 */, 18 },
- /* 4337 */ { MAD_F(0x04511c6e) /* 0.269802503 */, 18 },
- /* 4338 */ { MAD_F(0x04517368) /* 0.269885452 */, 18 },
- /* 4339 */ { MAD_F(0x0451ca64) /* 0.269968408 */, 18 },
- /* 4340 */ { MAD_F(0x04522162) /* 0.270051370 */, 18 },
- /* 4341 */ { MAD_F(0x04527862) /* 0.270134338 */, 18 },
- /* 4342 */ { MAD_F(0x0452cf63) /* 0.270217312 */, 18 },
- /* 4343 */ { MAD_F(0x04532666) /* 0.270300293 */, 18 },
- /* 4344 */ { MAD_F(0x04537d6b) /* 0.270383281 */, 18 },
- /* 4345 */ { MAD_F(0x0453d472) /* 0.270466275 */, 18 },
- /* 4346 */ { MAD_F(0x04542b7a) /* 0.270549275 */, 18 },
- /* 4347 */ { MAD_F(0x04548284) /* 0.270632281 */, 18 },
- /* 4348 */ { MAD_F(0x0454d98f) /* 0.270715294 */, 18 },
- /* 4349 */ { MAD_F(0x0455309c) /* 0.270798313 */, 18 },
- /* 4350 */ { MAD_F(0x045587ab) /* 0.270881339 */, 18 },
- /* 4351 */ { MAD_F(0x0455debc) /* 0.270964371 */, 18 },
-
- /* 4352 */ { MAD_F(0x045635cf) /* 0.271047409 */, 18 },
- /* 4353 */ { MAD_F(0x04568ce3) /* 0.271130454 */, 18 },
- /* 4354 */ { MAD_F(0x0456e3f9) /* 0.271213505 */, 18 },
- /* 4355 */ { MAD_F(0x04573b10) /* 0.271296562 */, 18 },
- /* 4356 */ { MAD_F(0x04579229) /* 0.271379626 */, 18 },
- /* 4357 */ { MAD_F(0x0457e944) /* 0.271462696 */, 18 },
- /* 4358 */ { MAD_F(0x04584061) /* 0.271545772 */, 18 },
- /* 4359 */ { MAD_F(0x0458977f) /* 0.271628855 */, 18 },
- /* 4360 */ { MAD_F(0x0458ee9f) /* 0.271711944 */, 18 },
- /* 4361 */ { MAD_F(0x045945c1) /* 0.271795040 */, 18 },
- /* 4362 */ { MAD_F(0x04599ce5) /* 0.271878142 */, 18 },
- /* 4363 */ { MAD_F(0x0459f40a) /* 0.271961250 */, 18 },
- /* 4364 */ { MAD_F(0x045a4b31) /* 0.272044365 */, 18 },
- /* 4365 */ { MAD_F(0x045aa259) /* 0.272127486 */, 18 },
- /* 4366 */ { MAD_F(0x045af984) /* 0.272210613 */, 18 },
- /* 4367 */ { MAD_F(0x045b50b0) /* 0.272293746 */, 18 },
-
- /* 4368 */ { MAD_F(0x045ba7dd) /* 0.272376886 */, 18 },
- /* 4369 */ { MAD_F(0x045bff0d) /* 0.272460033 */, 18 },
- /* 4370 */ { MAD_F(0x045c563e) /* 0.272543185 */, 18 },
- /* 4371 */ { MAD_F(0x045cad71) /* 0.272626344 */, 18 },
- /* 4372 */ { MAD_F(0x045d04a5) /* 0.272709510 */, 18 },
- /* 4373 */ { MAD_F(0x045d5bdc) /* 0.272792681 */, 18 },
- /* 4374 */ { MAD_F(0x045db313) /* 0.272875859 */, 18 },
- /* 4375 */ { MAD_F(0x045e0a4d) /* 0.272959044 */, 18 },
- /* 4376 */ { MAD_F(0x045e6188) /* 0.273042234 */, 18 },
- /* 4377 */ { MAD_F(0x045eb8c5) /* 0.273125431 */, 18 },
- /* 4378 */ { MAD_F(0x045f1004) /* 0.273208635 */, 18 },
- /* 4379 */ { MAD_F(0x045f6745) /* 0.273291844 */, 18 },
- /* 4380 */ { MAD_F(0x045fbe87) /* 0.273375060 */, 18 },
- /* 4381 */ { MAD_F(0x046015cb) /* 0.273458283 */, 18 },
- /* 4382 */ { MAD_F(0x04606d10) /* 0.273541511 */, 18 },
- /* 4383 */ { MAD_F(0x0460c457) /* 0.273624747 */, 18 },
-
- /* 4384 */ { MAD_F(0x04611ba0) /* 0.273707988 */, 18 },
- /* 4385 */ { MAD_F(0x046172eb) /* 0.273791236 */, 18 },
- /* 4386 */ { MAD_F(0x0461ca37) /* 0.273874490 */, 18 },
- /* 4387 */ { MAD_F(0x04622185) /* 0.273957750 */, 18 },
- /* 4388 */ { MAD_F(0x046278d5) /* 0.274041017 */, 18 },
- /* 4389 */ { MAD_F(0x0462d026) /* 0.274124290 */, 18 },
- /* 4390 */ { MAD_F(0x0463277a) /* 0.274207569 */, 18 },
- /* 4391 */ { MAD_F(0x04637ece) /* 0.274290855 */, 18 },
- /* 4392 */ { MAD_F(0x0463d625) /* 0.274374147 */, 18 },
- /* 4393 */ { MAD_F(0x04642d7d) /* 0.274457445 */, 18 },
- /* 4394 */ { MAD_F(0x046484d7) /* 0.274540749 */, 18 },
- /* 4395 */ { MAD_F(0x0464dc33) /* 0.274624060 */, 18 },
- /* 4396 */ { MAD_F(0x04653390) /* 0.274707378 */, 18 },
- /* 4397 */ { MAD_F(0x04658aef) /* 0.274790701 */, 18 },
- /* 4398 */ { MAD_F(0x0465e250) /* 0.274874031 */, 18 },
- /* 4399 */ { MAD_F(0x046639b2) /* 0.274957367 */, 18 },
-
- /* 4400 */ { MAD_F(0x04669116) /* 0.275040710 */, 18 },
- /* 4401 */ { MAD_F(0x0466e87c) /* 0.275124059 */, 18 },
- /* 4402 */ { MAD_F(0x04673fe3) /* 0.275207414 */, 18 },
- /* 4403 */ { MAD_F(0x0467974d) /* 0.275290775 */, 18 },
- /* 4404 */ { MAD_F(0x0467eeb7) /* 0.275374143 */, 18 },
- /* 4405 */ { MAD_F(0x04684624) /* 0.275457517 */, 18 },
- /* 4406 */ { MAD_F(0x04689d92) /* 0.275540897 */, 18 },
- /* 4407 */ { MAD_F(0x0468f502) /* 0.275624284 */, 18 },
- /* 4408 */ { MAD_F(0x04694c74) /* 0.275707677 */, 18 },
- /* 4409 */ { MAD_F(0x0469a3e7) /* 0.275791076 */, 18 },
- /* 4410 */ { MAD_F(0x0469fb5c) /* 0.275874482 */, 18 },
- /* 4411 */ { MAD_F(0x046a52d3) /* 0.275957894 */, 18 },
- /* 4412 */ { MAD_F(0x046aaa4b) /* 0.276041312 */, 18 },
- /* 4413 */ { MAD_F(0x046b01c5) /* 0.276124737 */, 18 },
- /* 4414 */ { MAD_F(0x046b5941) /* 0.276208167 */, 18 },
- /* 4415 */ { MAD_F(0x046bb0bf) /* 0.276291605 */, 18 },
-
- /* 4416 */ { MAD_F(0x046c083e) /* 0.276375048 */, 18 },
- /* 4417 */ { MAD_F(0x046c5fbf) /* 0.276458498 */, 18 },
- /* 4418 */ { MAD_F(0x046cb741) /* 0.276541954 */, 18 },
- /* 4419 */ { MAD_F(0x046d0ec5) /* 0.276625416 */, 18 },
- /* 4420 */ { MAD_F(0x046d664b) /* 0.276708885 */, 18 },
- /* 4421 */ { MAD_F(0x046dbdd3) /* 0.276792360 */, 18 },
- /* 4422 */ { MAD_F(0x046e155c) /* 0.276875841 */, 18 },
- /* 4423 */ { MAD_F(0x046e6ce7) /* 0.276959328 */, 18 },
- /* 4424 */ { MAD_F(0x046ec474) /* 0.277042822 */, 18 },
- /* 4425 */ { MAD_F(0x046f1c02) /* 0.277126322 */, 18 },
- /* 4426 */ { MAD_F(0x046f7392) /* 0.277209829 */, 18 },
- /* 4427 */ { MAD_F(0x046fcb24) /* 0.277293341 */, 18 },
- /* 4428 */ { MAD_F(0x047022b8) /* 0.277376860 */, 18 },
- /* 4429 */ { MAD_F(0x04707a4d) /* 0.277460385 */, 18 },
- /* 4430 */ { MAD_F(0x0470d1e4) /* 0.277543917 */, 18 },
- /* 4431 */ { MAD_F(0x0471297c) /* 0.277627455 */, 18 },
-
- /* 4432 */ { MAD_F(0x04718116) /* 0.277710999 */, 18 },
- /* 4433 */ { MAD_F(0x0471d8b2) /* 0.277794549 */, 18 },
- /* 4434 */ { MAD_F(0x04723050) /* 0.277878106 */, 18 },
- /* 4435 */ { MAD_F(0x047287ef) /* 0.277961669 */, 18 },
- /* 4436 */ { MAD_F(0x0472df90) /* 0.278045238 */, 18 },
- /* 4437 */ { MAD_F(0x04733733) /* 0.278128813 */, 18 },
- /* 4438 */ { MAD_F(0x04738ed7) /* 0.278212395 */, 18 },
- /* 4439 */ { MAD_F(0x0473e67d) /* 0.278295983 */, 18 },
- /* 4440 */ { MAD_F(0x04743e25) /* 0.278379578 */, 18 },
- /* 4441 */ { MAD_F(0x047495ce) /* 0.278463178 */, 18 },
- /* 4442 */ { MAD_F(0x0474ed79) /* 0.278546785 */, 18 },
- /* 4443 */ { MAD_F(0x04754526) /* 0.278630398 */, 18 },
- /* 4444 */ { MAD_F(0x04759cd4) /* 0.278714018 */, 18 },
- /* 4445 */ { MAD_F(0x0475f484) /* 0.278797643 */, 18 },
- /* 4446 */ { MAD_F(0x04764c36) /* 0.278881275 */, 18 },
- /* 4447 */ { MAD_F(0x0476a3ea) /* 0.278964914 */, 18 },
-
- /* 4448 */ { MAD_F(0x0476fb9f) /* 0.279048558 */, 18 },
- /* 4449 */ { MAD_F(0x04775356) /* 0.279132209 */, 18 },
- /* 4450 */ { MAD_F(0x0477ab0e) /* 0.279215866 */, 18 },
- /* 4451 */ { MAD_F(0x047802c8) /* 0.279299529 */, 18 },
- /* 4452 */ { MAD_F(0x04785a84) /* 0.279383199 */, 18 },
- /* 4453 */ { MAD_F(0x0478b242) /* 0.279466875 */, 18 },
- /* 4454 */ { MAD_F(0x04790a01) /* 0.279550557 */, 18 },
- /* 4455 */ { MAD_F(0x047961c2) /* 0.279634245 */, 18 },
- /* 4456 */ { MAD_F(0x0479b984) /* 0.279717940 */, 18 },
- /* 4457 */ { MAD_F(0x047a1149) /* 0.279801641 */, 18 },
- /* 4458 */ { MAD_F(0x047a690f) /* 0.279885348 */, 18 },
- /* 4459 */ { MAD_F(0x047ac0d6) /* 0.279969061 */, 18 },
- /* 4460 */ { MAD_F(0x047b18a0) /* 0.280052781 */, 18 },
- /* 4461 */ { MAD_F(0x047b706b) /* 0.280136507 */, 18 },
- /* 4462 */ { MAD_F(0x047bc837) /* 0.280220239 */, 18 },
- /* 4463 */ { MAD_F(0x047c2006) /* 0.280303978 */, 18 },
-
- /* 4464 */ { MAD_F(0x047c77d6) /* 0.280387722 */, 18 },
- /* 4465 */ { MAD_F(0x047ccfa8) /* 0.280471473 */, 18 },
- /* 4466 */ { MAD_F(0x047d277b) /* 0.280555230 */, 18 },
- /* 4467 */ { MAD_F(0x047d7f50) /* 0.280638994 */, 18 },
- /* 4468 */ { MAD_F(0x047dd727) /* 0.280722764 */, 18 },
- /* 4469 */ { MAD_F(0x047e2eff) /* 0.280806540 */, 18 },
- /* 4470 */ { MAD_F(0x047e86d9) /* 0.280890322 */, 18 },
- /* 4471 */ { MAD_F(0x047edeb5) /* 0.280974110 */, 18 },
- /* 4472 */ { MAD_F(0x047f3693) /* 0.281057905 */, 18 },
- /* 4473 */ { MAD_F(0x047f8e72) /* 0.281141706 */, 18 },
- /* 4474 */ { MAD_F(0x047fe653) /* 0.281225513 */, 18 },
- /* 4475 */ { MAD_F(0x04803e35) /* 0.281309326 */, 18 },
- /* 4476 */ { MAD_F(0x04809619) /* 0.281393146 */, 18 },
- /* 4477 */ { MAD_F(0x0480edff) /* 0.281476972 */, 18 },
- /* 4478 */ { MAD_F(0x048145e7) /* 0.281560804 */, 18 },
- /* 4479 */ { MAD_F(0x04819dd0) /* 0.281644643 */, 18 },
-
- /* 4480 */ { MAD_F(0x0481f5bb) /* 0.281728487 */, 18 },
- /* 4481 */ { MAD_F(0x04824da7) /* 0.281812338 */, 18 },
- /* 4482 */ { MAD_F(0x0482a595) /* 0.281896195 */, 18 },
- /* 4483 */ { MAD_F(0x0482fd85) /* 0.281980059 */, 18 },
- /* 4484 */ { MAD_F(0x04835577) /* 0.282063928 */, 18 },
- /* 4485 */ { MAD_F(0x0483ad6a) /* 0.282147804 */, 18 },
- /* 4486 */ { MAD_F(0x0484055f) /* 0.282231686 */, 18 },
- /* 4487 */ { MAD_F(0x04845d56) /* 0.282315574 */, 18 },
- /* 4488 */ { MAD_F(0x0484b54e) /* 0.282399469 */, 18 },
- /* 4489 */ { MAD_F(0x04850d48) /* 0.282483370 */, 18 },
- /* 4490 */ { MAD_F(0x04856544) /* 0.282567277 */, 18 },
- /* 4491 */ { MAD_F(0x0485bd41) /* 0.282651190 */, 18 },
- /* 4492 */ { MAD_F(0x04861540) /* 0.282735109 */, 18 },
- /* 4493 */ { MAD_F(0x04866d40) /* 0.282819035 */, 18 },
- /* 4494 */ { MAD_F(0x0486c543) /* 0.282902967 */, 18 },
- /* 4495 */ { MAD_F(0x04871d47) /* 0.282986905 */, 18 },
-
- /* 4496 */ { MAD_F(0x0487754c) /* 0.283070849 */, 18 },
- /* 4497 */ { MAD_F(0x0487cd54) /* 0.283154800 */, 18 },
- /* 4498 */ { MAD_F(0x0488255d) /* 0.283238757 */, 18 },
- /* 4499 */ { MAD_F(0x04887d67) /* 0.283322720 */, 18 },
- /* 4500 */ { MAD_F(0x0488d574) /* 0.283406689 */, 18 },
- /* 4501 */ { MAD_F(0x04892d82) /* 0.283490665 */, 18 },
- /* 4502 */ { MAD_F(0x04898591) /* 0.283574646 */, 18 },
- /* 4503 */ { MAD_F(0x0489dda3) /* 0.283658634 */, 18 },
- /* 4504 */ { MAD_F(0x048a35b6) /* 0.283742628 */, 18 },
- /* 4505 */ { MAD_F(0x048a8dca) /* 0.283826629 */, 18 },
- /* 4506 */ { MAD_F(0x048ae5e1) /* 0.283910635 */, 18 },
- /* 4507 */ { MAD_F(0x048b3df9) /* 0.283994648 */, 18 },
- /* 4508 */ { MAD_F(0x048b9612) /* 0.284078667 */, 18 },
- /* 4509 */ { MAD_F(0x048bee2e) /* 0.284162692 */, 18 },
- /* 4510 */ { MAD_F(0x048c464b) /* 0.284246723 */, 18 },
- /* 4511 */ { MAD_F(0x048c9e69) /* 0.284330761 */, 18 },
-
- /* 4512 */ { MAD_F(0x048cf68a) /* 0.284414805 */, 18 },
- /* 4513 */ { MAD_F(0x048d4eac) /* 0.284498855 */, 18 },
- /* 4514 */ { MAD_F(0x048da6cf) /* 0.284582911 */, 18 },
- /* 4515 */ { MAD_F(0x048dfef5) /* 0.284666974 */, 18 },
- /* 4516 */ { MAD_F(0x048e571c) /* 0.284751042 */, 18 },
- /* 4517 */ { MAD_F(0x048eaf44) /* 0.284835117 */, 18 },
- /* 4518 */ { MAD_F(0x048f076f) /* 0.284919198 */, 18 },
- /* 4519 */ { MAD_F(0x048f5f9b) /* 0.285003285 */, 18 },
- /* 4520 */ { MAD_F(0x048fb7c8) /* 0.285087379 */, 18 },
- /* 4521 */ { MAD_F(0x04900ff8) /* 0.285171479 */, 18 },
- /* 4522 */ { MAD_F(0x04906829) /* 0.285255584 */, 18 },
- /* 4523 */ { MAD_F(0x0490c05b) /* 0.285339697 */, 18 },
- /* 4524 */ { MAD_F(0x04911890) /* 0.285423815 */, 18 },
- /* 4525 */ { MAD_F(0x049170c6) /* 0.285507939 */, 18 },
- /* 4526 */ { MAD_F(0x0491c8fd) /* 0.285592070 */, 18 },
- /* 4527 */ { MAD_F(0x04922137) /* 0.285676207 */, 18 },
-
- /* 4528 */ { MAD_F(0x04927972) /* 0.285760350 */, 18 },
- /* 4529 */ { MAD_F(0x0492d1ae) /* 0.285844499 */, 18 },
- /* 4530 */ { MAD_F(0x049329ed) /* 0.285928655 */, 18 },
- /* 4531 */ { MAD_F(0x0493822c) /* 0.286012816 */, 18 },
- /* 4532 */ { MAD_F(0x0493da6e) /* 0.286096984 */, 18 },
- /* 4533 */ { MAD_F(0x049432b1) /* 0.286181158 */, 18 },
- /* 4534 */ { MAD_F(0x04948af6) /* 0.286265338 */, 18 },
- /* 4535 */ { MAD_F(0x0494e33d) /* 0.286349525 */, 18 },
- /* 4536 */ { MAD_F(0x04953b85) /* 0.286433717 */, 18 },
- /* 4537 */ { MAD_F(0x049593cf) /* 0.286517916 */, 18 },
- /* 4538 */ { MAD_F(0x0495ec1b) /* 0.286602121 */, 18 },
- /* 4539 */ { MAD_F(0x04964468) /* 0.286686332 */, 18 },
- /* 4540 */ { MAD_F(0x04969cb7) /* 0.286770550 */, 18 },
- /* 4541 */ { MAD_F(0x0496f508) /* 0.286854773 */, 18 },
- /* 4542 */ { MAD_F(0x04974d5a) /* 0.286939003 */, 18 },
- /* 4543 */ { MAD_F(0x0497a5ae) /* 0.287023239 */, 18 },
-
- /* 4544 */ { MAD_F(0x0497fe03) /* 0.287107481 */, 18 },
- /* 4545 */ { MAD_F(0x0498565a) /* 0.287191729 */, 18 },
- /* 4546 */ { MAD_F(0x0498aeb3) /* 0.287275983 */, 18 },
- /* 4547 */ { MAD_F(0x0499070e) /* 0.287360244 */, 18 },
- /* 4548 */ { MAD_F(0x04995f6a) /* 0.287444511 */, 18 },
- /* 4549 */ { MAD_F(0x0499b7c8) /* 0.287528784 */, 18 },
- /* 4550 */ { MAD_F(0x049a1027) /* 0.287613063 */, 18 },
- /* 4551 */ { MAD_F(0x049a6889) /* 0.287697348 */, 18 },
- /* 4552 */ { MAD_F(0x049ac0eb) /* 0.287781640 */, 18 },
- /* 4553 */ { MAD_F(0x049b1950) /* 0.287865937 */, 18 },
- /* 4554 */ { MAD_F(0x049b71b6) /* 0.287950241 */, 18 },
- /* 4555 */ { MAD_F(0x049bca1e) /* 0.288034551 */, 18 },
- /* 4556 */ { MAD_F(0x049c2287) /* 0.288118867 */, 18 },
- /* 4557 */ { MAD_F(0x049c7af2) /* 0.288203190 */, 18 },
- /* 4558 */ { MAD_F(0x049cd35f) /* 0.288287518 */, 18 },
- /* 4559 */ { MAD_F(0x049d2bce) /* 0.288371853 */, 18 },
-
- /* 4560 */ { MAD_F(0x049d843e) /* 0.288456194 */, 18 },
- /* 4561 */ { MAD_F(0x049ddcaf) /* 0.288540541 */, 18 },
- /* 4562 */ { MAD_F(0x049e3523) /* 0.288624894 */, 18 },
- /* 4563 */ { MAD_F(0x049e8d98) /* 0.288709253 */, 18 },
- /* 4564 */ { MAD_F(0x049ee60e) /* 0.288793619 */, 18 },
- /* 4565 */ { MAD_F(0x049f3e87) /* 0.288877990 */, 18 },
- /* 4566 */ { MAD_F(0x049f9701) /* 0.288962368 */, 18 },
- /* 4567 */ { MAD_F(0x049fef7c) /* 0.289046752 */, 18 },
- /* 4568 */ { MAD_F(0x04a047fa) /* 0.289131142 */, 18 },
- /* 4569 */ { MAD_F(0x04a0a079) /* 0.289215538 */, 18 },
- /* 4570 */ { MAD_F(0x04a0f8f9) /* 0.289299941 */, 18 },
- /* 4571 */ { MAD_F(0x04a1517c) /* 0.289384349 */, 18 },
- /* 4572 */ { MAD_F(0x04a1a9ff) /* 0.289468764 */, 18 },
- /* 4573 */ { MAD_F(0x04a20285) /* 0.289553185 */, 18 },
- /* 4574 */ { MAD_F(0x04a25b0c) /* 0.289637612 */, 18 },
- /* 4575 */ { MAD_F(0x04a2b395) /* 0.289722045 */, 18 },
-
- /* 4576 */ { MAD_F(0x04a30c20) /* 0.289806485 */, 18 },
- /* 4577 */ { MAD_F(0x04a364ac) /* 0.289890930 */, 18 },
- /* 4578 */ { MAD_F(0x04a3bd3a) /* 0.289975382 */, 18 },
- /* 4579 */ { MAD_F(0x04a415c9) /* 0.290059840 */, 18 },
- /* 4580 */ { MAD_F(0x04a46e5a) /* 0.290144304 */, 18 },
- /* 4581 */ { MAD_F(0x04a4c6ed) /* 0.290228774 */, 18 },
- /* 4582 */ { MAD_F(0x04a51f81) /* 0.290313250 */, 18 },
- /* 4583 */ { MAD_F(0x04a57818) /* 0.290397733 */, 18 },
- /* 4584 */ { MAD_F(0x04a5d0af) /* 0.290482221 */, 18 },
- /* 4585 */ { MAD_F(0x04a62949) /* 0.290566716 */, 18 },
- /* 4586 */ { MAD_F(0x04a681e4) /* 0.290651217 */, 18 },
- /* 4587 */ { MAD_F(0x04a6da80) /* 0.290735724 */, 18 },
- /* 4588 */ { MAD_F(0x04a7331f) /* 0.290820237 */, 18 },
- /* 4589 */ { MAD_F(0x04a78bbf) /* 0.290904756 */, 18 },
- /* 4590 */ { MAD_F(0x04a7e460) /* 0.290989281 */, 18 },
- /* 4591 */ { MAD_F(0x04a83d03) /* 0.291073813 */, 18 },
-
- /* 4592 */ { MAD_F(0x04a895a8) /* 0.291158351 */, 18 },
- /* 4593 */ { MAD_F(0x04a8ee4f) /* 0.291242894 */, 18 },
- /* 4594 */ { MAD_F(0x04a946f7) /* 0.291327444 */, 18 },
- /* 4595 */ { MAD_F(0x04a99fa1) /* 0.291412001 */, 18 },
- /* 4596 */ { MAD_F(0x04a9f84c) /* 0.291496563 */, 18 },
- /* 4597 */ { MAD_F(0x04aa50fa) /* 0.291581131 */, 18 },
- /* 4598 */ { MAD_F(0x04aaa9a8) /* 0.291665706 */, 18 },
- /* 4599 */ { MAD_F(0x04ab0259) /* 0.291750286 */, 18 },
- /* 4600 */ { MAD_F(0x04ab5b0b) /* 0.291834873 */, 18 },
- /* 4601 */ { MAD_F(0x04abb3bf) /* 0.291919466 */, 18 },
- /* 4602 */ { MAD_F(0x04ac0c74) /* 0.292004065 */, 18 },
- /* 4603 */ { MAD_F(0x04ac652b) /* 0.292088670 */, 18 },
- /* 4604 */ { MAD_F(0x04acbde4) /* 0.292173281 */, 18 },
- /* 4605 */ { MAD_F(0x04ad169e) /* 0.292257899 */, 18 },
- /* 4606 */ { MAD_F(0x04ad6f5a) /* 0.292342522 */, 18 },
- /* 4607 */ { MAD_F(0x04adc818) /* 0.292427152 */, 18 },
-
- /* 4608 */ { MAD_F(0x04ae20d7) /* 0.292511788 */, 18 },
- /* 4609 */ { MAD_F(0x04ae7998) /* 0.292596430 */, 18 },
- /* 4610 */ { MAD_F(0x04aed25a) /* 0.292681078 */, 18 },
- /* 4611 */ { MAD_F(0x04af2b1e) /* 0.292765732 */, 18 },
- /* 4612 */ { MAD_F(0x04af83e4) /* 0.292850392 */, 18 },
- /* 4613 */ { MAD_F(0x04afdcac) /* 0.292935058 */, 18 },
- /* 4614 */ { MAD_F(0x04b03575) /* 0.293019731 */, 18 },
- /* 4615 */ { MAD_F(0x04b08e40) /* 0.293104409 */, 18 },
- /* 4616 */ { MAD_F(0x04b0e70c) /* 0.293189094 */, 18 },
- /* 4617 */ { MAD_F(0x04b13fda) /* 0.293273785 */, 18 },
- /* 4618 */ { MAD_F(0x04b198aa) /* 0.293358482 */, 18 },
- /* 4619 */ { MAD_F(0x04b1f17b) /* 0.293443185 */, 18 },
- /* 4620 */ { MAD_F(0x04b24a4e) /* 0.293527894 */, 18 },
- /* 4621 */ { MAD_F(0x04b2a322) /* 0.293612609 */, 18 },
- /* 4622 */ { MAD_F(0x04b2fbf9) /* 0.293697331 */, 18 },
- /* 4623 */ { MAD_F(0x04b354d1) /* 0.293782058 */, 18 },
-
- /* 4624 */ { MAD_F(0x04b3adaa) /* 0.293866792 */, 18 },
- /* 4625 */ { MAD_F(0x04b40685) /* 0.293951532 */, 18 },
- /* 4626 */ { MAD_F(0x04b45f62) /* 0.294036278 */, 18 },
- /* 4627 */ { MAD_F(0x04b4b840) /* 0.294121029 */, 18 },
- /* 4628 */ { MAD_F(0x04b51120) /* 0.294205788 */, 18 },
- /* 4629 */ { MAD_F(0x04b56a02) /* 0.294290552 */, 18 },
- /* 4630 */ { MAD_F(0x04b5c2e6) /* 0.294375322 */, 18 },
- /* 4631 */ { MAD_F(0x04b61bcb) /* 0.294460098 */, 18 },
- /* 4632 */ { MAD_F(0x04b674b1) /* 0.294544881 */, 18 },
- /* 4633 */ { MAD_F(0x04b6cd99) /* 0.294629669 */, 18 },
- /* 4634 */ { MAD_F(0x04b72683) /* 0.294714464 */, 18 },
- /* 4635 */ { MAD_F(0x04b77f6f) /* 0.294799265 */, 18 },
- /* 4636 */ { MAD_F(0x04b7d85c) /* 0.294884072 */, 18 },
- /* 4637 */ { MAD_F(0x04b8314b) /* 0.294968885 */, 18 },
- /* 4638 */ { MAD_F(0x04b88a3b) /* 0.295053704 */, 18 },
- /* 4639 */ { MAD_F(0x04b8e32d) /* 0.295138529 */, 18 },
-
- /* 4640 */ { MAD_F(0x04b93c21) /* 0.295223360 */, 18 },
- /* 4641 */ { MAD_F(0x04b99516) /* 0.295308197 */, 18 },
- /* 4642 */ { MAD_F(0x04b9ee0d) /* 0.295393041 */, 18 },
- /* 4643 */ { MAD_F(0x04ba4706) /* 0.295477890 */, 18 },
- /* 4644 */ { MAD_F(0x04baa000) /* 0.295562746 */, 18 },
- /* 4645 */ { MAD_F(0x04baf8fc) /* 0.295647608 */, 18 },
- /* 4646 */ { MAD_F(0x04bb51fa) /* 0.295732476 */, 18 },
- /* 4647 */ { MAD_F(0x04bbaaf9) /* 0.295817349 */, 18 },
- /* 4648 */ { MAD_F(0x04bc03fa) /* 0.295902229 */, 18 },
- /* 4649 */ { MAD_F(0x04bc5cfc) /* 0.295987115 */, 18 },
- /* 4650 */ { MAD_F(0x04bcb600) /* 0.296072008 */, 18 },
- /* 4651 */ { MAD_F(0x04bd0f06) /* 0.296156906 */, 18 },
- /* 4652 */ { MAD_F(0x04bd680d) /* 0.296241810 */, 18 },
- /* 4653 */ { MAD_F(0x04bdc116) /* 0.296326721 */, 18 },
- /* 4654 */ { MAD_F(0x04be1a21) /* 0.296411637 */, 18 },
- /* 4655 */ { MAD_F(0x04be732d) /* 0.296496560 */, 18 },
-
- /* 4656 */ { MAD_F(0x04becc3b) /* 0.296581488 */, 18 },
- /* 4657 */ { MAD_F(0x04bf254a) /* 0.296666423 */, 18 },
- /* 4658 */ { MAD_F(0x04bf7e5b) /* 0.296751364 */, 18 },
- /* 4659 */ { MAD_F(0x04bfd76e) /* 0.296836311 */, 18 },
- /* 4660 */ { MAD_F(0x04c03083) /* 0.296921264 */, 18 },
- /* 4661 */ { MAD_F(0x04c08999) /* 0.297006223 */, 18 },
- /* 4662 */ { MAD_F(0x04c0e2b0) /* 0.297091188 */, 18 },
- /* 4663 */ { MAD_F(0x04c13bca) /* 0.297176159 */, 18 },
- /* 4664 */ { MAD_F(0x04c194e4) /* 0.297261136 */, 18 },
- /* 4665 */ { MAD_F(0x04c1ee01) /* 0.297346120 */, 18 },
- /* 4666 */ { MAD_F(0x04c2471f) /* 0.297431109 */, 18 },
- /* 4667 */ { MAD_F(0x04c2a03f) /* 0.297516105 */, 18 },
- /* 4668 */ { MAD_F(0x04c2f960) /* 0.297601106 */, 18 },
- /* 4669 */ { MAD_F(0x04c35283) /* 0.297686114 */, 18 },
- /* 4670 */ { MAD_F(0x04c3aba8) /* 0.297771128 */, 18 },
- /* 4671 */ { MAD_F(0x04c404ce) /* 0.297856147 */, 18 },
-
- /* 4672 */ { MAD_F(0x04c45df6) /* 0.297941173 */, 18 },
- /* 4673 */ { MAD_F(0x04c4b720) /* 0.298026205 */, 18 },
- /* 4674 */ { MAD_F(0x04c5104b) /* 0.298111243 */, 18 },
- /* 4675 */ { MAD_F(0x04c56978) /* 0.298196287 */, 18 },
- /* 4676 */ { MAD_F(0x04c5c2a7) /* 0.298281337 */, 18 },
- /* 4677 */ { MAD_F(0x04c61bd7) /* 0.298366393 */, 18 },
- /* 4678 */ { MAD_F(0x04c67508) /* 0.298451456 */, 18 },
- /* 4679 */ { MAD_F(0x04c6ce3c) /* 0.298536524 */, 18 },
- /* 4680 */ { MAD_F(0x04c72771) /* 0.298621598 */, 18 },
- /* 4681 */ { MAD_F(0x04c780a7) /* 0.298706679 */, 18 },
- /* 4682 */ { MAD_F(0x04c7d9df) /* 0.298791765 */, 18 },
- /* 4683 */ { MAD_F(0x04c83319) /* 0.298876858 */, 18 },
- /* 4684 */ { MAD_F(0x04c88c55) /* 0.298961956 */, 18 },
- /* 4685 */ { MAD_F(0x04c8e592) /* 0.299047061 */, 18 },
- /* 4686 */ { MAD_F(0x04c93ed1) /* 0.299132172 */, 18 },
- /* 4687 */ { MAD_F(0x04c99811) /* 0.299217288 */, 18 },
-
- /* 4688 */ { MAD_F(0x04c9f153) /* 0.299302411 */, 18 },
- /* 4689 */ { MAD_F(0x04ca4a97) /* 0.299387540 */, 18 },
- /* 4690 */ { MAD_F(0x04caa3dc) /* 0.299472675 */, 18 },
- /* 4691 */ { MAD_F(0x04cafd23) /* 0.299557816 */, 18 },
- /* 4692 */ { MAD_F(0x04cb566b) /* 0.299642963 */, 18 },
- /* 4693 */ { MAD_F(0x04cbafb5) /* 0.299728116 */, 18 },
- /* 4694 */ { MAD_F(0x04cc0901) /* 0.299813275 */, 18 },
- /* 4695 */ { MAD_F(0x04cc624e) /* 0.299898440 */, 18 },
- /* 4696 */ { MAD_F(0x04ccbb9d) /* 0.299983611 */, 18 },
- /* 4697 */ { MAD_F(0x04cd14ee) /* 0.300068789 */, 18 },
- /* 4698 */ { MAD_F(0x04cd6e40) /* 0.300153972 */, 18 },
- /* 4699 */ { MAD_F(0x04cdc794) /* 0.300239161 */, 18 },
- /* 4700 */ { MAD_F(0x04ce20e9) /* 0.300324357 */, 18 },
- /* 4701 */ { MAD_F(0x04ce7a40) /* 0.300409558 */, 18 },
- /* 4702 */ { MAD_F(0x04ced399) /* 0.300494765 */, 18 },
- /* 4703 */ { MAD_F(0x04cf2cf3) /* 0.300579979 */, 18 },
-
- /* 4704 */ { MAD_F(0x04cf864f) /* 0.300665198 */, 18 },
- /* 4705 */ { MAD_F(0x04cfdfad) /* 0.300750424 */, 18 },
- /* 4706 */ { MAD_F(0x04d0390c) /* 0.300835656 */, 18 },
- /* 4707 */ { MAD_F(0x04d0926d) /* 0.300920893 */, 18 },
- /* 4708 */ { MAD_F(0x04d0ebcf) /* 0.301006137 */, 18 },
- /* 4709 */ { MAD_F(0x04d14533) /* 0.301091387 */, 18 },
- /* 4710 */ { MAD_F(0x04d19e99) /* 0.301176643 */, 18 },
- /* 4711 */ { MAD_F(0x04d1f800) /* 0.301261904 */, 18 },
- /* 4712 */ { MAD_F(0x04d25169) /* 0.301347172 */, 18 },
- /* 4713 */ { MAD_F(0x04d2aad4) /* 0.301432446 */, 18 },
- /* 4714 */ { MAD_F(0x04d30440) /* 0.301517726 */, 18 },
- /* 4715 */ { MAD_F(0x04d35dae) /* 0.301603012 */, 18 },
- /* 4716 */ { MAD_F(0x04d3b71d) /* 0.301688304 */, 18 },
- /* 4717 */ { MAD_F(0x04d4108e) /* 0.301773602 */, 18 },
- /* 4718 */ { MAD_F(0x04d46a01) /* 0.301858906 */, 18 },
- /* 4719 */ { MAD_F(0x04d4c375) /* 0.301944216 */, 18 },
-
- /* 4720 */ { MAD_F(0x04d51ceb) /* 0.302029532 */, 18 },
- /* 4721 */ { MAD_F(0x04d57662) /* 0.302114854 */, 18 },
- /* 4722 */ { MAD_F(0x04d5cfdb) /* 0.302200182 */, 18 },
- /* 4723 */ { MAD_F(0x04d62956) /* 0.302285516 */, 18 },
- /* 4724 */ { MAD_F(0x04d682d2) /* 0.302370856 */, 18 },
- /* 4725 */ { MAD_F(0x04d6dc50) /* 0.302456203 */, 18 },
- /* 4726 */ { MAD_F(0x04d735d0) /* 0.302541555 */, 18 },
- /* 4727 */ { MAD_F(0x04d78f51) /* 0.302626913 */, 18 },
- /* 4728 */ { MAD_F(0x04d7e8d4) /* 0.302712277 */, 18 },
- /* 4729 */ { MAD_F(0x04d84258) /* 0.302797648 */, 18 },
- /* 4730 */ { MAD_F(0x04d89bde) /* 0.302883024 */, 18 },
- /* 4731 */ { MAD_F(0x04d8f566) /* 0.302968406 */, 18 },
- /* 4732 */ { MAD_F(0x04d94eef) /* 0.303053794 */, 18 },
- /* 4733 */ { MAD_F(0x04d9a87a) /* 0.303139189 */, 18 },
- /* 4734 */ { MAD_F(0x04da0207) /* 0.303224589 */, 18 },
- /* 4735 */ { MAD_F(0x04da5b95) /* 0.303309995 */, 18 },
-
- /* 4736 */ { MAD_F(0x04dab524) /* 0.303395408 */, 18 },
- /* 4737 */ { MAD_F(0x04db0eb6) /* 0.303480826 */, 18 },
- /* 4738 */ { MAD_F(0x04db6849) /* 0.303566251 */, 18 },
- /* 4739 */ { MAD_F(0x04dbc1dd) /* 0.303651681 */, 18 },
- /* 4740 */ { MAD_F(0x04dc1b73) /* 0.303737117 */, 18 },
- /* 4741 */ { MAD_F(0x04dc750b) /* 0.303822560 */, 18 },
- /* 4742 */ { MAD_F(0x04dccea5) /* 0.303908008 */, 18 },
- /* 4743 */ { MAD_F(0x04dd2840) /* 0.303993463 */, 18 },
- /* 4744 */ { MAD_F(0x04dd81dc) /* 0.304078923 */, 18 },
- /* 4745 */ { MAD_F(0x04dddb7a) /* 0.304164390 */, 18 },
- /* 4746 */ { MAD_F(0x04de351a) /* 0.304249862 */, 18 },
- /* 4747 */ { MAD_F(0x04de8ebc) /* 0.304335340 */, 18 },
- /* 4748 */ { MAD_F(0x04dee85f) /* 0.304420825 */, 18 },
- /* 4749 */ { MAD_F(0x04df4203) /* 0.304506315 */, 18 },
- /* 4750 */ { MAD_F(0x04df9baa) /* 0.304591812 */, 18 },
- /* 4751 */ { MAD_F(0x04dff552) /* 0.304677314 */, 18 },
-
- /* 4752 */ { MAD_F(0x04e04efb) /* 0.304762823 */, 18 },
- /* 4753 */ { MAD_F(0x04e0a8a6) /* 0.304848337 */, 18 },
- /* 4754 */ { MAD_F(0x04e10253) /* 0.304933858 */, 18 },
- /* 4755 */ { MAD_F(0x04e15c01) /* 0.305019384 */, 18 },
- /* 4756 */ { MAD_F(0x04e1b5b1) /* 0.305104917 */, 18 },
- /* 4757 */ { MAD_F(0x04e20f63) /* 0.305190455 */, 18 },
- /* 4758 */ { MAD_F(0x04e26916) /* 0.305275999 */, 18 },
- /* 4759 */ { MAD_F(0x04e2c2cb) /* 0.305361550 */, 18 },
- /* 4760 */ { MAD_F(0x04e31c81) /* 0.305447106 */, 18 },
- /* 4761 */ { MAD_F(0x04e37639) /* 0.305532669 */, 18 },
- /* 4762 */ { MAD_F(0x04e3cff3) /* 0.305618237 */, 18 },
- /* 4763 */ { MAD_F(0x04e429ae) /* 0.305703811 */, 18 },
- /* 4764 */ { MAD_F(0x04e4836b) /* 0.305789392 */, 18 },
- /* 4765 */ { MAD_F(0x04e4dd29) /* 0.305874978 */, 18 },
- /* 4766 */ { MAD_F(0x04e536e9) /* 0.305960571 */, 18 },
- /* 4767 */ { MAD_F(0x04e590ab) /* 0.306046169 */, 18 },
-
- /* 4768 */ { MAD_F(0x04e5ea6e) /* 0.306131773 */, 18 },
- /* 4769 */ { MAD_F(0x04e64433) /* 0.306217383 */, 18 },
- /* 4770 */ { MAD_F(0x04e69df9) /* 0.306303000 */, 18 },
- /* 4771 */ { MAD_F(0x04e6f7c1) /* 0.306388622 */, 18 },
- /* 4772 */ { MAD_F(0x04e7518b) /* 0.306474250 */, 18 },
- /* 4773 */ { MAD_F(0x04e7ab56) /* 0.306559885 */, 18 },
- /* 4774 */ { MAD_F(0x04e80523) /* 0.306645525 */, 18 },
- /* 4775 */ { MAD_F(0x04e85ef2) /* 0.306731171 */, 18 },
- /* 4776 */ { MAD_F(0x04e8b8c2) /* 0.306816823 */, 18 },
- /* 4777 */ { MAD_F(0x04e91293) /* 0.306902481 */, 18 },
- /* 4778 */ { MAD_F(0x04e96c67) /* 0.306988145 */, 18 },
- /* 4779 */ { MAD_F(0x04e9c63b) /* 0.307073816 */, 18 },
- /* 4780 */ { MAD_F(0x04ea2012) /* 0.307159492 */, 18 },
- /* 4781 */ { MAD_F(0x04ea79ea) /* 0.307245174 */, 18 },
- /* 4782 */ { MAD_F(0x04ead3c4) /* 0.307330862 */, 18 },
- /* 4783 */ { MAD_F(0x04eb2d9f) /* 0.307416556 */, 18 },
-
- /* 4784 */ { MAD_F(0x04eb877c) /* 0.307502256 */, 18 },
- /* 4785 */ { MAD_F(0x04ebe15b) /* 0.307587962 */, 18 },
- /* 4786 */ { MAD_F(0x04ec3b3b) /* 0.307673674 */, 18 },
- /* 4787 */ { MAD_F(0x04ec951c) /* 0.307759392 */, 18 },
- /* 4788 */ { MAD_F(0x04ecef00) /* 0.307845115 */, 18 },
- /* 4789 */ { MAD_F(0x04ed48e5) /* 0.307930845 */, 18 },
- /* 4790 */ { MAD_F(0x04eda2cb) /* 0.308016581 */, 18 },
- /* 4791 */ { MAD_F(0x04edfcb3) /* 0.308102323 */, 18 },
- /* 4792 */ { MAD_F(0x04ee569d) /* 0.308188071 */, 18 },
- /* 4793 */ { MAD_F(0x04eeb088) /* 0.308273824 */, 18 },
- /* 4794 */ { MAD_F(0x04ef0a75) /* 0.308359584 */, 18 },
- /* 4795 */ { MAD_F(0x04ef6464) /* 0.308445350 */, 18 },
- /* 4796 */ { MAD_F(0x04efbe54) /* 0.308531121 */, 18 },
- /* 4797 */ { MAD_F(0x04f01846) /* 0.308616899 */, 18 },
- /* 4798 */ { MAD_F(0x04f07239) /* 0.308702682 */, 18 },
- /* 4799 */ { MAD_F(0x04f0cc2e) /* 0.308788472 */, 18 },
-
- /* 4800 */ { MAD_F(0x04f12624) /* 0.308874267 */, 18 },
- /* 4801 */ { MAD_F(0x04f1801d) /* 0.308960068 */, 18 },
- /* 4802 */ { MAD_F(0x04f1da16) /* 0.309045876 */, 18 },
- /* 4803 */ { MAD_F(0x04f23412) /* 0.309131689 */, 18 },
- /* 4804 */ { MAD_F(0x04f28e0f) /* 0.309217508 */, 18 },
- /* 4805 */ { MAD_F(0x04f2e80d) /* 0.309303334 */, 18 },
- /* 4806 */ { MAD_F(0x04f3420d) /* 0.309389165 */, 18 },
- /* 4807 */ { MAD_F(0x04f39c0f) /* 0.309475002 */, 18 },
- /* 4808 */ { MAD_F(0x04f3f612) /* 0.309560845 */, 18 },
- /* 4809 */ { MAD_F(0x04f45017) /* 0.309646694 */, 18 },
- /* 4810 */ { MAD_F(0x04f4aa1e) /* 0.309732549 */, 18 },
- /* 4811 */ { MAD_F(0x04f50426) /* 0.309818410 */, 18 },
- /* 4812 */ { MAD_F(0x04f55e30) /* 0.309904277 */, 18 },
- /* 4813 */ { MAD_F(0x04f5b83b) /* 0.309990150 */, 18 },
- /* 4814 */ { MAD_F(0x04f61248) /* 0.310076028 */, 18 },
- /* 4815 */ { MAD_F(0x04f66c56) /* 0.310161913 */, 18 },
-
- /* 4816 */ { MAD_F(0x04f6c666) /* 0.310247804 */, 18 },
- /* 4817 */ { MAD_F(0x04f72078) /* 0.310333700 */, 18 },
- /* 4818 */ { MAD_F(0x04f77a8b) /* 0.310419603 */, 18 },
- /* 4819 */ { MAD_F(0x04f7d4a0) /* 0.310505511 */, 18 },
- /* 4820 */ { MAD_F(0x04f82eb7) /* 0.310591426 */, 18 },
- /* 4821 */ { MAD_F(0x04f888cf) /* 0.310677346 */, 18 },
- /* 4822 */ { MAD_F(0x04f8e2e9) /* 0.310763272 */, 18 },
- /* 4823 */ { MAD_F(0x04f93d04) /* 0.310849205 */, 18 },
- /* 4824 */ { MAD_F(0x04f99721) /* 0.310935143 */, 18 },
- /* 4825 */ { MAD_F(0x04f9f13f) /* 0.311021087 */, 18 },
- /* 4826 */ { MAD_F(0x04fa4b5f) /* 0.311107037 */, 18 },
- /* 4827 */ { MAD_F(0x04faa581) /* 0.311192993 */, 18 },
- /* 4828 */ { MAD_F(0x04faffa4) /* 0.311278955 */, 18 },
- /* 4829 */ { MAD_F(0x04fb59c9) /* 0.311364923 */, 18 },
- /* 4830 */ { MAD_F(0x04fbb3ef) /* 0.311450897 */, 18 },
- /* 4831 */ { MAD_F(0x04fc0e17) /* 0.311536877 */, 18 },
-
- /* 4832 */ { MAD_F(0x04fc6841) /* 0.311622862 */, 18 },
- /* 4833 */ { MAD_F(0x04fcc26c) /* 0.311708854 */, 18 },
- /* 4834 */ { MAD_F(0x04fd1c99) /* 0.311794851 */, 18 },
- /* 4835 */ { MAD_F(0x04fd76c7) /* 0.311880855 */, 18 },
- /* 4836 */ { MAD_F(0x04fdd0f7) /* 0.311966864 */, 18 },
- /* 4837 */ { MAD_F(0x04fe2b29) /* 0.312052880 */, 18 },
- /* 4838 */ { MAD_F(0x04fe855c) /* 0.312138901 */, 18 },
- /* 4839 */ { MAD_F(0x04fedf91) /* 0.312224928 */, 18 },
- /* 4840 */ { MAD_F(0x04ff39c7) /* 0.312310961 */, 18 },
- /* 4841 */ { MAD_F(0x04ff93ff) /* 0.312397000 */, 18 },
- /* 4842 */ { MAD_F(0x04ffee38) /* 0.312483045 */, 18 },
- /* 4843 */ { MAD_F(0x05004874) /* 0.312569096 */, 18 },
- /* 4844 */ { MAD_F(0x0500a2b0) /* 0.312655153 */, 18 },
- /* 4845 */ { MAD_F(0x0500fcef) /* 0.312741216 */, 18 },
- /* 4846 */ { MAD_F(0x0501572e) /* 0.312827284 */, 18 },
- /* 4847 */ { MAD_F(0x0501b170) /* 0.312913359 */, 18 },
-
- /* 4848 */ { MAD_F(0x05020bb3) /* 0.312999439 */, 18 },
- /* 4849 */ { MAD_F(0x050265f8) /* 0.313085526 */, 18 },
- /* 4850 */ { MAD_F(0x0502c03e) /* 0.313171618 */, 18 },
- /* 4851 */ { MAD_F(0x05031a86) /* 0.313257716 */, 18 },
- /* 4852 */ { MAD_F(0x050374cf) /* 0.313343820 */, 18 },
- /* 4853 */ { MAD_F(0x0503cf1a) /* 0.313429931 */, 18 },
- /* 4854 */ { MAD_F(0x05042967) /* 0.313516047 */, 18 },
- /* 4855 */ { MAD_F(0x050483b5) /* 0.313602168 */, 18 },
- /* 4856 */ { MAD_F(0x0504de05) /* 0.313688296 */, 18 },
- /* 4857 */ { MAD_F(0x05053856) /* 0.313774430 */, 18 },
- /* 4858 */ { MAD_F(0x050592a9) /* 0.313860570 */, 18 },
- /* 4859 */ { MAD_F(0x0505ecfd) /* 0.313946715 */, 18 },
- /* 4860 */ { MAD_F(0x05064754) /* 0.314032867 */, 18 },
- /* 4861 */ { MAD_F(0x0506a1ab) /* 0.314119024 */, 18 },
- /* 4862 */ { MAD_F(0x0506fc04) /* 0.314205187 */, 18 },
- /* 4863 */ { MAD_F(0x0507565f) /* 0.314291357 */, 18 },
-
- /* 4864 */ { MAD_F(0x0507b0bc) /* 0.314377532 */, 18 },
- /* 4865 */ { MAD_F(0x05080b1a) /* 0.314463713 */, 18 },
- /* 4866 */ { MAD_F(0x05086579) /* 0.314549900 */, 18 },
- /* 4867 */ { MAD_F(0x0508bfdb) /* 0.314636092 */, 18 },
- /* 4868 */ { MAD_F(0x05091a3d) /* 0.314722291 */, 18 },
- /* 4869 */ { MAD_F(0x050974a2) /* 0.314808496 */, 18 },
- /* 4870 */ { MAD_F(0x0509cf08) /* 0.314894706 */, 18 },
- /* 4871 */ { MAD_F(0x050a296f) /* 0.314980923 */, 18 },
- /* 4872 */ { MAD_F(0x050a83d8) /* 0.315067145 */, 18 },
- /* 4873 */ { MAD_F(0x050ade43) /* 0.315153373 */, 18 },
- /* 4874 */ { MAD_F(0x050b38af) /* 0.315239607 */, 18 },
- /* 4875 */ { MAD_F(0x050b931d) /* 0.315325847 */, 18 },
- /* 4876 */ { MAD_F(0x050bed8d) /* 0.315412093 */, 18 },
- /* 4877 */ { MAD_F(0x050c47fe) /* 0.315498345 */, 18 },
- /* 4878 */ { MAD_F(0x050ca271) /* 0.315584603 */, 18 },
- /* 4879 */ { MAD_F(0x050cfce5) /* 0.315670866 */, 18 },
-
- /* 4880 */ { MAD_F(0x050d575b) /* 0.315757136 */, 18 },
- /* 4881 */ { MAD_F(0x050db1d2) /* 0.315843411 */, 18 },
- /* 4882 */ { MAD_F(0x050e0c4b) /* 0.315929693 */, 18 },
- /* 4883 */ { MAD_F(0x050e66c5) /* 0.316015980 */, 18 },
- /* 4884 */ { MAD_F(0x050ec141) /* 0.316102273 */, 18 },
- /* 4885 */ { MAD_F(0x050f1bbf) /* 0.316188572 */, 18 },
- /* 4886 */ { MAD_F(0x050f763e) /* 0.316274877 */, 18 },
- /* 4887 */ { MAD_F(0x050fd0bf) /* 0.316361187 */, 18 },
- /* 4888 */ { MAD_F(0x05102b42) /* 0.316447504 */, 18 },
- /* 4889 */ { MAD_F(0x051085c6) /* 0.316533826 */, 18 },
- /* 4890 */ { MAD_F(0x0510e04b) /* 0.316620155 */, 18 },
- /* 4891 */ { MAD_F(0x05113ad3) /* 0.316706489 */, 18 },
- /* 4892 */ { MAD_F(0x0511955b) /* 0.316792829 */, 18 },
- /* 4893 */ { MAD_F(0x0511efe6) /* 0.316879175 */, 18 },
- /* 4894 */ { MAD_F(0x05124a72) /* 0.316965527 */, 18 },
- /* 4895 */ { MAD_F(0x0512a4ff) /* 0.317051885 */, 18 },
-
- /* 4896 */ { MAD_F(0x0512ff8e) /* 0.317138249 */, 18 },
- /* 4897 */ { MAD_F(0x05135a1f) /* 0.317224618 */, 18 },
- /* 4898 */ { MAD_F(0x0513b4b1) /* 0.317310994 */, 18 },
- /* 4899 */ { MAD_F(0x05140f45) /* 0.317397375 */, 18 },
- /* 4900 */ { MAD_F(0x051469da) /* 0.317483762 */, 18 },
- /* 4901 */ { MAD_F(0x0514c471) /* 0.317570155 */, 18 },
- /* 4902 */ { MAD_F(0x05151f0a) /* 0.317656554 */, 18 },
- /* 4903 */ { MAD_F(0x051579a4) /* 0.317742959 */, 18 },
- /* 4904 */ { MAD_F(0x0515d440) /* 0.317829370 */, 18 },
- /* 4905 */ { MAD_F(0x05162edd) /* 0.317915786 */, 18 },
- /* 4906 */ { MAD_F(0x0516897c) /* 0.318002209 */, 18 },
- /* 4907 */ { MAD_F(0x0516e41c) /* 0.318088637 */, 18 },
- /* 4908 */ { MAD_F(0x05173ebe) /* 0.318175071 */, 18 },
- /* 4909 */ { MAD_F(0x05179962) /* 0.318261511 */, 18 },
- /* 4910 */ { MAD_F(0x0517f407) /* 0.318347957 */, 18 },
- /* 4911 */ { MAD_F(0x05184eae) /* 0.318434409 */, 18 },
-
- /* 4912 */ { MAD_F(0x0518a956) /* 0.318520867 */, 18 },
- /* 4913 */ { MAD_F(0x05190400) /* 0.318607330 */, 18 },
- /* 4914 */ { MAD_F(0x05195eab) /* 0.318693800 */, 18 },
- /* 4915 */ { MAD_F(0x0519b958) /* 0.318780275 */, 18 },
- /* 4916 */ { MAD_F(0x051a1407) /* 0.318866756 */, 18 },
- /* 4917 */ { MAD_F(0x051a6eb7) /* 0.318953243 */, 18 },
- /* 4918 */ { MAD_F(0x051ac969) /* 0.319039736 */, 18 },
- /* 4919 */ { MAD_F(0x051b241c) /* 0.319126235 */, 18 },
- /* 4920 */ { MAD_F(0x051b7ed1) /* 0.319212739 */, 18 },
- /* 4921 */ { MAD_F(0x051bd987) /* 0.319299250 */, 18 },
- /* 4922 */ { MAD_F(0x051c3440) /* 0.319385766 */, 18 },
- /* 4923 */ { MAD_F(0x051c8ef9) /* 0.319472288 */, 18 },
- /* 4924 */ { MAD_F(0x051ce9b4) /* 0.319558816 */, 18 },
- /* 4925 */ { MAD_F(0x051d4471) /* 0.319645350 */, 18 },
- /* 4926 */ { MAD_F(0x051d9f2f) /* 0.319731890 */, 18 },
- /* 4927 */ { MAD_F(0x051df9ef) /* 0.319818435 */, 18 },
-
- /* 4928 */ { MAD_F(0x051e54b1) /* 0.319904987 */, 18 },
- /* 4929 */ { MAD_F(0x051eaf74) /* 0.319991544 */, 18 },
- /* 4930 */ { MAD_F(0x051f0a38) /* 0.320078107 */, 18 },
- /* 4931 */ { MAD_F(0x051f64ff) /* 0.320164676 */, 18 },
- /* 4932 */ { MAD_F(0x051fbfc6) /* 0.320251251 */, 18 },
- /* 4933 */ { MAD_F(0x05201a90) /* 0.320337832 */, 18 },
- /* 4934 */ { MAD_F(0x0520755b) /* 0.320424419 */, 18 },
- /* 4935 */ { MAD_F(0x0520d027) /* 0.320511011 */, 18 },
- /* 4936 */ { MAD_F(0x05212af5) /* 0.320597609 */, 18 },
- /* 4937 */ { MAD_F(0x052185c5) /* 0.320684213 */, 18 },
- /* 4938 */ { MAD_F(0x0521e096) /* 0.320770823 */, 18 },
- /* 4939 */ { MAD_F(0x05223b69) /* 0.320857439 */, 18 },
- /* 4940 */ { MAD_F(0x0522963d) /* 0.320944061 */, 18 },
- /* 4941 */ { MAD_F(0x0522f113) /* 0.321030688 */, 18 },
- /* 4942 */ { MAD_F(0x05234bea) /* 0.321117322 */, 18 },
- /* 4943 */ { MAD_F(0x0523a6c3) /* 0.321203961 */, 18 },
-
- /* 4944 */ { MAD_F(0x0524019e) /* 0.321290606 */, 18 },
- /* 4945 */ { MAD_F(0x05245c7a) /* 0.321377257 */, 18 },
- /* 4946 */ { MAD_F(0x0524b758) /* 0.321463913 */, 18 },
- /* 4947 */ { MAD_F(0x05251237) /* 0.321550576 */, 18 },
- /* 4948 */ { MAD_F(0x05256d18) /* 0.321637244 */, 18 },
- /* 4949 */ { MAD_F(0x0525c7fb) /* 0.321723919 */, 18 },
- /* 4950 */ { MAD_F(0x052622df) /* 0.321810599 */, 18 },
- /* 4951 */ { MAD_F(0x05267dc4) /* 0.321897285 */, 18 },
- /* 4952 */ { MAD_F(0x0526d8ab) /* 0.321983976 */, 18 },
- /* 4953 */ { MAD_F(0x05273394) /* 0.322070674 */, 18 },
- /* 4954 */ { MAD_F(0x05278e7e) /* 0.322157377 */, 18 },
- /* 4955 */ { MAD_F(0x0527e96a) /* 0.322244087 */, 18 },
- /* 4956 */ { MAD_F(0x05284457) /* 0.322330802 */, 18 },
- /* 4957 */ { MAD_F(0x05289f46) /* 0.322417523 */, 18 },
- /* 4958 */ { MAD_F(0x0528fa37) /* 0.322504249 */, 18 },
- /* 4959 */ { MAD_F(0x05295529) /* 0.322590982 */, 18 },
-
- /* 4960 */ { MAD_F(0x0529b01d) /* 0.322677720 */, 18 },
- /* 4961 */ { MAD_F(0x052a0b12) /* 0.322764465 */, 18 },
- /* 4962 */ { MAD_F(0x052a6609) /* 0.322851215 */, 18 },
- /* 4963 */ { MAD_F(0x052ac101) /* 0.322937971 */, 18 },
- /* 4964 */ { MAD_F(0x052b1bfb) /* 0.323024732 */, 18 },
- /* 4965 */ { MAD_F(0x052b76f7) /* 0.323111500 */, 18 },
- /* 4966 */ { MAD_F(0x052bd1f4) /* 0.323198273 */, 18 },
- /* 4967 */ { MAD_F(0x052c2cf2) /* 0.323285052 */, 18 },
- /* 4968 */ { MAD_F(0x052c87f2) /* 0.323371837 */, 18 },
- /* 4969 */ { MAD_F(0x052ce2f4) /* 0.323458628 */, 18 },
- /* 4970 */ { MAD_F(0x052d3df7) /* 0.323545425 */, 18 },
- /* 4971 */ { MAD_F(0x052d98fc) /* 0.323632227 */, 18 },
- /* 4972 */ { MAD_F(0x052df403) /* 0.323719036 */, 18 },
- /* 4973 */ { MAD_F(0x052e4f0b) /* 0.323805850 */, 18 },
- /* 4974 */ { MAD_F(0x052eaa14) /* 0.323892670 */, 18 },
- /* 4975 */ { MAD_F(0x052f051f) /* 0.323979496 */, 18 },
-
- /* 4976 */ { MAD_F(0x052f602c) /* 0.324066327 */, 18 },
- /* 4977 */ { MAD_F(0x052fbb3a) /* 0.324153165 */, 18 },
- /* 4978 */ { MAD_F(0x0530164a) /* 0.324240008 */, 18 },
- /* 4979 */ { MAD_F(0x0530715b) /* 0.324326857 */, 18 },
- /* 4980 */ { MAD_F(0x0530cc6e) /* 0.324413712 */, 18 },
- /* 4981 */ { MAD_F(0x05312783) /* 0.324500572 */, 18 },
- /* 4982 */ { MAD_F(0x05318299) /* 0.324587439 */, 18 },
- /* 4983 */ { MAD_F(0x0531ddb0) /* 0.324674311 */, 18 },
- /* 4984 */ { MAD_F(0x053238ca) /* 0.324761189 */, 18 },
- /* 4985 */ { MAD_F(0x053293e4) /* 0.324848073 */, 18 },
- /* 4986 */ { MAD_F(0x0532ef01) /* 0.324934963 */, 18 },
- /* 4987 */ { MAD_F(0x05334a1e) /* 0.325021858 */, 18 },
- /* 4988 */ { MAD_F(0x0533a53e) /* 0.325108760 */, 18 },
- /* 4989 */ { MAD_F(0x0534005f) /* 0.325195667 */, 18 },
- /* 4990 */ { MAD_F(0x05345b81) /* 0.325282580 */, 18 },
- /* 4991 */ { MAD_F(0x0534b6a5) /* 0.325369498 */, 18 },
-
- /* 4992 */ { MAD_F(0x053511cb) /* 0.325456423 */, 18 },
- /* 4993 */ { MAD_F(0x05356cf2) /* 0.325543353 */, 18 },
- /* 4994 */ { MAD_F(0x0535c81b) /* 0.325630290 */, 18 },
- /* 4995 */ { MAD_F(0x05362345) /* 0.325717232 */, 18 },
- /* 4996 */ { MAD_F(0x05367e71) /* 0.325804179 */, 18 },
- /* 4997 */ { MAD_F(0x0536d99f) /* 0.325891133 */, 18 },
- /* 4998 */ { MAD_F(0x053734ce) /* 0.325978092 */, 18 },
- /* 4999 */ { MAD_F(0x05378ffe) /* 0.326065057 */, 18 },
- /* 5000 */ { MAD_F(0x0537eb30) /* 0.326152028 */, 18 },
- /* 5001 */ { MAD_F(0x05384664) /* 0.326239005 */, 18 },
- /* 5002 */ { MAD_F(0x0538a199) /* 0.326325988 */, 18 },
- /* 5003 */ { MAD_F(0x0538fcd0) /* 0.326412976 */, 18 },
- /* 5004 */ { MAD_F(0x05395808) /* 0.326499970 */, 18 },
- /* 5005 */ { MAD_F(0x0539b342) /* 0.326586970 */, 18 },
- /* 5006 */ { MAD_F(0x053a0e7d) /* 0.326673976 */, 18 },
- /* 5007 */ { MAD_F(0x053a69ba) /* 0.326760988 */, 18 },
-
- /* 5008 */ { MAD_F(0x053ac4f9) /* 0.326848005 */, 18 },
- /* 5009 */ { MAD_F(0x053b2039) /* 0.326935028 */, 18 },
- /* 5010 */ { MAD_F(0x053b7b7b) /* 0.327022057 */, 18 },
- /* 5011 */ { MAD_F(0x053bd6be) /* 0.327109092 */, 18 },
- /* 5012 */ { MAD_F(0x053c3203) /* 0.327196132 */, 18 },
- /* 5013 */ { MAD_F(0x053c8d49) /* 0.327283178 */, 18 },
- /* 5014 */ { MAD_F(0x053ce891) /* 0.327370231 */, 18 },
- /* 5015 */ { MAD_F(0x053d43da) /* 0.327457288 */, 18 },
- /* 5016 */ { MAD_F(0x053d9f25) /* 0.327544352 */, 18 },
- /* 5017 */ { MAD_F(0x053dfa72) /* 0.327631421 */, 18 },
- /* 5018 */ { MAD_F(0x053e55c0) /* 0.327718497 */, 18 },
- /* 5019 */ { MAD_F(0x053eb10f) /* 0.327805578 */, 18 },
- /* 5020 */ { MAD_F(0x053f0c61) /* 0.327892665 */, 18 },
- /* 5021 */ { MAD_F(0x053f67b3) /* 0.327979757 */, 18 },
- /* 5022 */ { MAD_F(0x053fc308) /* 0.328066855 */, 18 },
- /* 5023 */ { MAD_F(0x05401e5e) /* 0.328153960 */, 18 },
-
- /* 5024 */ { MAD_F(0x054079b5) /* 0.328241070 */, 18 },
- /* 5025 */ { MAD_F(0x0540d50e) /* 0.328328185 */, 18 },
- /* 5026 */ { MAD_F(0x05413068) /* 0.328415307 */, 18 },
- /* 5027 */ { MAD_F(0x05418bc4) /* 0.328502434 */, 18 },
- /* 5028 */ { MAD_F(0x0541e722) /* 0.328589567 */, 18 },
- /* 5029 */ { MAD_F(0x05424281) /* 0.328676706 */, 18 },
- /* 5030 */ { MAD_F(0x05429de2) /* 0.328763850 */, 18 },
- /* 5031 */ { MAD_F(0x0542f944) /* 0.328851001 */, 18 },
- /* 5032 */ { MAD_F(0x054354a8) /* 0.328938157 */, 18 },
- /* 5033 */ { MAD_F(0x0543b00d) /* 0.329025319 */, 18 },
- /* 5034 */ { MAD_F(0x05440b74) /* 0.329112486 */, 18 },
- /* 5035 */ { MAD_F(0x054466dd) /* 0.329199660 */, 18 },
- /* 5036 */ { MAD_F(0x0544c247) /* 0.329286839 */, 18 },
- /* 5037 */ { MAD_F(0x05451db2) /* 0.329374024 */, 18 },
- /* 5038 */ { MAD_F(0x0545791f) /* 0.329461215 */, 18 },
- /* 5039 */ { MAD_F(0x0545d48e) /* 0.329548411 */, 18 },
-
- /* 5040 */ { MAD_F(0x05462ffe) /* 0.329635614 */, 18 },
- /* 5041 */ { MAD_F(0x05468b70) /* 0.329722822 */, 18 },
- /* 5042 */ { MAD_F(0x0546e6e3) /* 0.329810036 */, 18 },
- /* 5043 */ { MAD_F(0x05474258) /* 0.329897255 */, 18 },
- /* 5044 */ { MAD_F(0x05479dce) /* 0.329984481 */, 18 },
- /* 5045 */ { MAD_F(0x0547f946) /* 0.330071712 */, 18 },
- /* 5046 */ { MAD_F(0x054854c0) /* 0.330158949 */, 18 },
- /* 5047 */ { MAD_F(0x0548b03b) /* 0.330246191 */, 18 },
- /* 5048 */ { MAD_F(0x05490bb7) /* 0.330333440 */, 18 },
- /* 5049 */ { MAD_F(0x05496735) /* 0.330420694 */, 18 },
- /* 5050 */ { MAD_F(0x0549c2b5) /* 0.330507954 */, 18 },
- /* 5051 */ { MAD_F(0x054a1e36) /* 0.330595220 */, 18 },
- /* 5052 */ { MAD_F(0x054a79b9) /* 0.330682491 */, 18 },
- /* 5053 */ { MAD_F(0x054ad53d) /* 0.330769768 */, 18 },
- /* 5054 */ { MAD_F(0x054b30c3) /* 0.330857051 */, 18 },
- /* 5055 */ { MAD_F(0x054b8c4b) /* 0.330944340 */, 18 },
-
- /* 5056 */ { MAD_F(0x054be7d4) /* 0.331031635 */, 18 },
- /* 5057 */ { MAD_F(0x054c435e) /* 0.331118935 */, 18 },
- /* 5058 */ { MAD_F(0x054c9eea) /* 0.331206241 */, 18 },
- /* 5059 */ { MAD_F(0x054cfa78) /* 0.331293553 */, 18 },
- /* 5060 */ { MAD_F(0x054d5607) /* 0.331380870 */, 18 },
- /* 5061 */ { MAD_F(0x054db197) /* 0.331468193 */, 18 },
- /* 5062 */ { MAD_F(0x054e0d2a) /* 0.331555522 */, 18 },
- /* 5063 */ { MAD_F(0x054e68bd) /* 0.331642857 */, 18 },
- /* 5064 */ { MAD_F(0x054ec453) /* 0.331730198 */, 18 },
- /* 5065 */ { MAD_F(0x054f1fe9) /* 0.331817544 */, 18 },
- /* 5066 */ { MAD_F(0x054f7b82) /* 0.331904896 */, 18 },
- /* 5067 */ { MAD_F(0x054fd71c) /* 0.331992254 */, 18 },
- /* 5068 */ { MAD_F(0x055032b7) /* 0.332079617 */, 18 },
- /* 5069 */ { MAD_F(0x05508e54) /* 0.332166986 */, 18 },
- /* 5070 */ { MAD_F(0x0550e9f3) /* 0.332254361 */, 18 },
- /* 5071 */ { MAD_F(0x05514593) /* 0.332341742 */, 18 },
-
- /* 5072 */ { MAD_F(0x0551a134) /* 0.332429129 */, 18 },
- /* 5073 */ { MAD_F(0x0551fcd8) /* 0.332516521 */, 18 },
- /* 5074 */ { MAD_F(0x0552587c) /* 0.332603919 */, 18 },
- /* 5075 */ { MAD_F(0x0552b423) /* 0.332691323 */, 18 },
- /* 5076 */ { MAD_F(0x05530fca) /* 0.332778732 */, 18 },
- /* 5077 */ { MAD_F(0x05536b74) /* 0.332866147 */, 18 },
- /* 5078 */ { MAD_F(0x0553c71f) /* 0.332953568 */, 18 },
- /* 5079 */ { MAD_F(0x055422cb) /* 0.333040995 */, 18 },
- /* 5080 */ { MAD_F(0x05547e79) /* 0.333128427 */, 18 },
- /* 5081 */ { MAD_F(0x0554da29) /* 0.333215865 */, 18 },
- /* 5082 */ { MAD_F(0x055535da) /* 0.333303309 */, 18 },
- /* 5083 */ { MAD_F(0x0555918c) /* 0.333390759 */, 18 },
- /* 5084 */ { MAD_F(0x0555ed40) /* 0.333478214 */, 18 },
- /* 5085 */ { MAD_F(0x055648f6) /* 0.333565675 */, 18 },
- /* 5086 */ { MAD_F(0x0556a4ad) /* 0.333653142 */, 18 },
- /* 5087 */ { MAD_F(0x05570066) /* 0.333740615 */, 18 },
-
- /* 5088 */ { MAD_F(0x05575c20) /* 0.333828093 */, 18 },
- /* 5089 */ { MAD_F(0x0557b7dc) /* 0.333915577 */, 18 },
- /* 5090 */ { MAD_F(0x05581399) /* 0.334003067 */, 18 },
- /* 5091 */ { MAD_F(0x05586f58) /* 0.334090562 */, 18 },
- /* 5092 */ { MAD_F(0x0558cb19) /* 0.334178063 */, 18 },
- /* 5093 */ { MAD_F(0x055926db) /* 0.334265570 */, 18 },
- /* 5094 */ { MAD_F(0x0559829e) /* 0.334353083 */, 18 },
- /* 5095 */ { MAD_F(0x0559de63) /* 0.334440601 */, 18 },
- /* 5096 */ { MAD_F(0x055a3a2a) /* 0.334528126 */, 18 },
- /* 5097 */ { MAD_F(0x055a95f2) /* 0.334615655 */, 18 },
- /* 5098 */ { MAD_F(0x055af1bb) /* 0.334703191 */, 18 },
- /* 5099 */ { MAD_F(0x055b4d87) /* 0.334790732 */, 18 },
- /* 5100 */ { MAD_F(0x055ba953) /* 0.334878279 */, 18 },
- /* 5101 */ { MAD_F(0x055c0522) /* 0.334965832 */, 18 },
- /* 5102 */ { MAD_F(0x055c60f1) /* 0.335053391 */, 18 },
- /* 5103 */ { MAD_F(0x055cbcc3) /* 0.335140955 */, 18 },
-
- /* 5104 */ { MAD_F(0x055d1896) /* 0.335228525 */, 18 },
- /* 5105 */ { MAD_F(0x055d746a) /* 0.335316100 */, 18 },
- /* 5106 */ { MAD_F(0x055dd040) /* 0.335403682 */, 18 },
- /* 5107 */ { MAD_F(0x055e2c17) /* 0.335491269 */, 18 },
- /* 5108 */ { MAD_F(0x055e87f0) /* 0.335578861 */, 18 },
- /* 5109 */ { MAD_F(0x055ee3cb) /* 0.335666460 */, 18 },
- /* 5110 */ { MAD_F(0x055f3fa7) /* 0.335754064 */, 18 },
- /* 5111 */ { MAD_F(0x055f9b85) /* 0.335841674 */, 18 },
- /* 5112 */ { MAD_F(0x055ff764) /* 0.335929290 */, 18 },
- /* 5113 */ { MAD_F(0x05605344) /* 0.336016911 */, 18 },
- /* 5114 */ { MAD_F(0x0560af27) /* 0.336104538 */, 18 },
- /* 5115 */ { MAD_F(0x05610b0a) /* 0.336192171 */, 18 },
- /* 5116 */ { MAD_F(0x056166f0) /* 0.336279809 */, 18 },
- /* 5117 */ { MAD_F(0x0561c2d7) /* 0.336367453 */, 18 },
- /* 5118 */ { MAD_F(0x05621ebf) /* 0.336455103 */, 18 },
- /* 5119 */ { MAD_F(0x05627aa9) /* 0.336542759 */, 18 },
-
- /* 5120 */ { MAD_F(0x0562d694) /* 0.336630420 */, 18 },
- /* 5121 */ { MAD_F(0x05633281) /* 0.336718087 */, 18 },
- /* 5122 */ { MAD_F(0x05638e70) /* 0.336805760 */, 18 },
- /* 5123 */ { MAD_F(0x0563ea60) /* 0.336893439 */, 18 },
- /* 5124 */ { MAD_F(0x05644651) /* 0.336981123 */, 18 },
- /* 5125 */ { MAD_F(0x0564a244) /* 0.337068813 */, 18 },
- /* 5126 */ { MAD_F(0x0564fe39) /* 0.337156508 */, 18 },
- /* 5127 */ { MAD_F(0x05655a2f) /* 0.337244209 */, 18 },
- /* 5128 */ { MAD_F(0x0565b627) /* 0.337331916 */, 18 },
- /* 5129 */ { MAD_F(0x05661220) /* 0.337419629 */, 18 },
- /* 5130 */ { MAD_F(0x05666e1a) /* 0.337507347 */, 18 },
- /* 5131 */ { MAD_F(0x0566ca17) /* 0.337595071 */, 18 },
- /* 5132 */ { MAD_F(0x05672614) /* 0.337682801 */, 18 },
- /* 5133 */ { MAD_F(0x05678214) /* 0.337770537 */, 18 },
- /* 5134 */ { MAD_F(0x0567de15) /* 0.337858278 */, 18 },
- /* 5135 */ { MAD_F(0x05683a17) /* 0.337946025 */, 18 },
-
- /* 5136 */ { MAD_F(0x0568961b) /* 0.338033777 */, 18 },
- /* 5137 */ { MAD_F(0x0568f220) /* 0.338121535 */, 18 },
- /* 5138 */ { MAD_F(0x05694e27) /* 0.338209299 */, 18 },
- /* 5139 */ { MAD_F(0x0569aa30) /* 0.338297069 */, 18 },
- /* 5140 */ { MAD_F(0x056a063a) /* 0.338384844 */, 18 },
- /* 5141 */ { MAD_F(0x056a6245) /* 0.338472625 */, 18 },
- /* 5142 */ { MAD_F(0x056abe52) /* 0.338560412 */, 18 },
- /* 5143 */ { MAD_F(0x056b1a61) /* 0.338648204 */, 18 },
- /* 5144 */ { MAD_F(0x056b7671) /* 0.338736002 */, 18 },
- /* 5145 */ { MAD_F(0x056bd283) /* 0.338823806 */, 18 },
- /* 5146 */ { MAD_F(0x056c2e96) /* 0.338911616 */, 18 },
- /* 5147 */ { MAD_F(0x056c8aab) /* 0.338999431 */, 18 },
- /* 5148 */ { MAD_F(0x056ce6c1) /* 0.339087252 */, 18 },
- /* 5149 */ { MAD_F(0x056d42d9) /* 0.339175078 */, 18 },
- /* 5150 */ { MAD_F(0x056d9ef2) /* 0.339262910 */, 18 },
- /* 5151 */ { MAD_F(0x056dfb0d) /* 0.339350748 */, 18 },
-
- /* 5152 */ { MAD_F(0x056e5729) /* 0.339438592 */, 18 },
- /* 5153 */ { MAD_F(0x056eb347) /* 0.339526441 */, 18 },
- /* 5154 */ { MAD_F(0x056f0f66) /* 0.339614296 */, 18 },
- /* 5155 */ { MAD_F(0x056f6b87) /* 0.339702157 */, 18 },
- /* 5156 */ { MAD_F(0x056fc7aa) /* 0.339790023 */, 18 },
- /* 5157 */ { MAD_F(0x057023cd) /* 0.339877895 */, 18 },
- /* 5158 */ { MAD_F(0x05707ff3) /* 0.339965773 */, 18 },
- /* 5159 */ { MAD_F(0x0570dc1a) /* 0.340053656 */, 18 },
- /* 5160 */ { MAD_F(0x05713843) /* 0.340141545 */, 18 },
- /* 5161 */ { MAD_F(0x0571946d) /* 0.340229440 */, 18 },
- /* 5162 */ { MAD_F(0x0571f098) /* 0.340317340 */, 18 },
- /* 5163 */ { MAD_F(0x05724cc5) /* 0.340405246 */, 18 },
- /* 5164 */ { MAD_F(0x0572a8f4) /* 0.340493158 */, 18 },
- /* 5165 */ { MAD_F(0x05730524) /* 0.340581075 */, 18 },
- /* 5166 */ { MAD_F(0x05736156) /* 0.340668999 */, 18 },
- /* 5167 */ { MAD_F(0x0573bd89) /* 0.340756927 */, 18 },
-
- /* 5168 */ { MAD_F(0x057419be) /* 0.340844862 */, 18 },
- /* 5169 */ { MAD_F(0x057475f4) /* 0.340932802 */, 18 },
- /* 5170 */ { MAD_F(0x0574d22c) /* 0.341020748 */, 18 },
- /* 5171 */ { MAD_F(0x05752e65) /* 0.341108699 */, 18 },
- /* 5172 */ { MAD_F(0x05758aa0) /* 0.341196656 */, 18 },
- /* 5173 */ { MAD_F(0x0575e6dc) /* 0.341284619 */, 18 },
- /* 5174 */ { MAD_F(0x0576431a) /* 0.341372587 */, 18 },
- /* 5175 */ { MAD_F(0x05769f59) /* 0.341460562 */, 18 },
- /* 5176 */ { MAD_F(0x0576fb9a) /* 0.341548541 */, 18 },
- /* 5177 */ { MAD_F(0x057757dd) /* 0.341636527 */, 18 },
- /* 5178 */ { MAD_F(0x0577b421) /* 0.341724518 */, 18 },
- /* 5179 */ { MAD_F(0x05781066) /* 0.341812515 */, 18 },
- /* 5180 */ { MAD_F(0x05786cad) /* 0.341900517 */, 18 },
- /* 5181 */ { MAD_F(0x0578c8f5) /* 0.341988525 */, 18 },
- /* 5182 */ { MAD_F(0x0579253f) /* 0.342076539 */, 18 },
- /* 5183 */ { MAD_F(0x0579818b) /* 0.342164558 */, 18 },
-
- /* 5184 */ { MAD_F(0x0579ddd8) /* 0.342252584 */, 18 },
- /* 5185 */ { MAD_F(0x057a3a27) /* 0.342340614 */, 18 },
- /* 5186 */ { MAD_F(0x057a9677) /* 0.342428651 */, 18 },
- /* 5187 */ { MAD_F(0x057af2c8) /* 0.342516693 */, 18 },
- /* 5188 */ { MAD_F(0x057b4f1c) /* 0.342604741 */, 18 },
- /* 5189 */ { MAD_F(0x057bab70) /* 0.342692794 */, 18 },
- /* 5190 */ { MAD_F(0x057c07c6) /* 0.342780853 */, 18 },
- /* 5191 */ { MAD_F(0x057c641e) /* 0.342868918 */, 18 },
- /* 5192 */ { MAD_F(0x057cc077) /* 0.342956988 */, 18 },
- /* 5193 */ { MAD_F(0x057d1cd2) /* 0.343045064 */, 18 },
- /* 5194 */ { MAD_F(0x057d792e) /* 0.343133146 */, 18 },
- /* 5195 */ { MAD_F(0x057dd58c) /* 0.343221233 */, 18 },
- /* 5196 */ { MAD_F(0x057e31eb) /* 0.343309326 */, 18 },
- /* 5197 */ { MAD_F(0x057e8e4c) /* 0.343397425 */, 18 },
- /* 5198 */ { MAD_F(0x057eeaae) /* 0.343485529 */, 18 },
- /* 5199 */ { MAD_F(0x057f4712) /* 0.343573639 */, 18 },
-
- /* 5200 */ { MAD_F(0x057fa378) /* 0.343661754 */, 18 },
- /* 5201 */ { MAD_F(0x057fffde) /* 0.343749876 */, 18 },
- /* 5202 */ { MAD_F(0x05805c47) /* 0.343838003 */, 18 },
- /* 5203 */ { MAD_F(0x0580b8b1) /* 0.343926135 */, 18 },
- /* 5204 */ { MAD_F(0x0581151c) /* 0.344014273 */, 18 },
- /* 5205 */ { MAD_F(0x05817189) /* 0.344102417 */, 18 },
- /* 5206 */ { MAD_F(0x0581cdf7) /* 0.344190566 */, 18 },
- /* 5207 */ { MAD_F(0x05822a67) /* 0.344278722 */, 18 },
- /* 5208 */ { MAD_F(0x058286d9) /* 0.344366882 */, 18 },
- /* 5209 */ { MAD_F(0x0582e34c) /* 0.344455049 */, 18 },
- /* 5210 */ { MAD_F(0x05833fc0) /* 0.344543221 */, 18 },
- /* 5211 */ { MAD_F(0x05839c36) /* 0.344631398 */, 18 },
- /* 5212 */ { MAD_F(0x0583f8ae) /* 0.344719582 */, 18 },
- /* 5213 */ { MAD_F(0x05845527) /* 0.344807771 */, 18 },
- /* 5214 */ { MAD_F(0x0584b1a1) /* 0.344895965 */, 18 },
- /* 5215 */ { MAD_F(0x05850e1e) /* 0.344984165 */, 18 },
-
- /* 5216 */ { MAD_F(0x05856a9b) /* 0.345072371 */, 18 },
- /* 5217 */ { MAD_F(0x0585c71a) /* 0.345160583 */, 18 },
- /* 5218 */ { MAD_F(0x0586239b) /* 0.345248800 */, 18 },
- /* 5219 */ { MAD_F(0x0586801d) /* 0.345337023 */, 18 },
- /* 5220 */ { MAD_F(0x0586dca1) /* 0.345425251 */, 18 },
- /* 5221 */ { MAD_F(0x05873926) /* 0.345513485 */, 18 },
- /* 5222 */ { MAD_F(0x058795ac) /* 0.345601725 */, 18 },
- /* 5223 */ { MAD_F(0x0587f235) /* 0.345689970 */, 18 },
- /* 5224 */ { MAD_F(0x05884ebe) /* 0.345778221 */, 18 },
- /* 5225 */ { MAD_F(0x0588ab49) /* 0.345866478 */, 18 },
- /* 5226 */ { MAD_F(0x058907d6) /* 0.345954740 */, 18 },
- /* 5227 */ { MAD_F(0x05896464) /* 0.346043008 */, 18 },
- /* 5228 */ { MAD_F(0x0589c0f4) /* 0.346131281 */, 18 },
- /* 5229 */ { MAD_F(0x058a1d85) /* 0.346219560 */, 18 },
- /* 5230 */ { MAD_F(0x058a7a18) /* 0.346307845 */, 18 },
- /* 5231 */ { MAD_F(0x058ad6ac) /* 0.346396135 */, 18 },
-
- /* 5232 */ { MAD_F(0x058b3342) /* 0.346484431 */, 18 },
- /* 5233 */ { MAD_F(0x058b8fd9) /* 0.346572733 */, 18 },
- /* 5234 */ { MAD_F(0x058bec72) /* 0.346661040 */, 18 },
- /* 5235 */ { MAD_F(0x058c490c) /* 0.346749353 */, 18 },
- /* 5236 */ { MAD_F(0x058ca5a8) /* 0.346837671 */, 18 },
- /* 5237 */ { MAD_F(0x058d0246) /* 0.346925996 */, 18 },
- /* 5238 */ { MAD_F(0x058d5ee4) /* 0.347014325 */, 18 },
- /* 5239 */ { MAD_F(0x058dbb85) /* 0.347102661 */, 18 },
- /* 5240 */ { MAD_F(0x058e1827) /* 0.347191002 */, 18 },
- /* 5241 */ { MAD_F(0x058e74ca) /* 0.347279348 */, 18 },
- /* 5242 */ { MAD_F(0x058ed16f) /* 0.347367700 */, 18 },
- /* 5243 */ { MAD_F(0x058f2e15) /* 0.347456058 */, 18 },
- /* 5244 */ { MAD_F(0x058f8abd) /* 0.347544422 */, 18 },
- /* 5245 */ { MAD_F(0x058fe766) /* 0.347632791 */, 18 },
- /* 5246 */ { MAD_F(0x05904411) /* 0.347721165 */, 18 },
- /* 5247 */ { MAD_F(0x0590a0be) /* 0.347809546 */, 18 },
-
- /* 5248 */ { MAD_F(0x0590fd6c) /* 0.347897931 */, 18 },
- /* 5249 */ { MAD_F(0x05915a1b) /* 0.347986323 */, 18 },
- /* 5250 */ { MAD_F(0x0591b6cc) /* 0.348074720 */, 18 },
- /* 5251 */ { MAD_F(0x0592137e) /* 0.348163123 */, 18 },
- /* 5252 */ { MAD_F(0x05927032) /* 0.348251531 */, 18 },
- /* 5253 */ { MAD_F(0x0592cce8) /* 0.348339945 */, 18 },
- /* 5254 */ { MAD_F(0x0593299f) /* 0.348428365 */, 18 },
- /* 5255 */ { MAD_F(0x05938657) /* 0.348516790 */, 18 },
- /* 5256 */ { MAD_F(0x0593e311) /* 0.348605221 */, 18 },
- /* 5257 */ { MAD_F(0x05943fcd) /* 0.348693657 */, 18 },
- /* 5258 */ { MAD_F(0x05949c8a) /* 0.348782099 */, 18 },
- /* 5259 */ { MAD_F(0x0594f948) /* 0.348870547 */, 18 },
- /* 5260 */ { MAD_F(0x05955608) /* 0.348959000 */, 18 },
- /* 5261 */ { MAD_F(0x0595b2ca) /* 0.349047459 */, 18 },
- /* 5262 */ { MAD_F(0x05960f8c) /* 0.349135923 */, 18 },
- /* 5263 */ { MAD_F(0x05966c51) /* 0.349224393 */, 18 },
-
- /* 5264 */ { MAD_F(0x0596c917) /* 0.349312869 */, 18 },
- /* 5265 */ { MAD_F(0x059725de) /* 0.349401350 */, 18 },
- /* 5266 */ { MAD_F(0x059782a7) /* 0.349489837 */, 18 },
- /* 5267 */ { MAD_F(0x0597df72) /* 0.349578329 */, 18 },
- /* 5268 */ { MAD_F(0x05983c3e) /* 0.349666827 */, 18 },
- /* 5269 */ { MAD_F(0x0598990c) /* 0.349755331 */, 18 },
- /* 5270 */ { MAD_F(0x0598f5db) /* 0.349843840 */, 18 },
- /* 5271 */ { MAD_F(0x059952ab) /* 0.349932355 */, 18 },
- /* 5272 */ { MAD_F(0x0599af7d) /* 0.350020876 */, 18 },
- /* 5273 */ { MAD_F(0x059a0c51) /* 0.350109402 */, 18 },
- /* 5274 */ { MAD_F(0x059a6926) /* 0.350197933 */, 18 },
- /* 5275 */ { MAD_F(0x059ac5fc) /* 0.350286470 */, 18 },
- /* 5276 */ { MAD_F(0x059b22d4) /* 0.350375013 */, 18 },
- /* 5277 */ { MAD_F(0x059b7fae) /* 0.350463562 */, 18 },
- /* 5278 */ { MAD_F(0x059bdc89) /* 0.350552116 */, 18 },
- /* 5279 */ { MAD_F(0x059c3965) /* 0.350640675 */, 18 },
-
- /* 5280 */ { MAD_F(0x059c9643) /* 0.350729240 */, 18 },
- /* 5281 */ { MAD_F(0x059cf323) /* 0.350817811 */, 18 },
- /* 5282 */ { MAD_F(0x059d5004) /* 0.350906388 */, 18 },
- /* 5283 */ { MAD_F(0x059dace6) /* 0.350994970 */, 18 },
- /* 5284 */ { MAD_F(0x059e09cb) /* 0.351083557 */, 18 },
- /* 5285 */ { MAD_F(0x059e66b0) /* 0.351172150 */, 18 },
- /* 5286 */ { MAD_F(0x059ec397) /* 0.351260749 */, 18 },
- /* 5287 */ { MAD_F(0x059f2080) /* 0.351349353 */, 18 },
- /* 5288 */ { MAD_F(0x059f7d6a) /* 0.351437963 */, 18 },
- /* 5289 */ { MAD_F(0x059fda55) /* 0.351526579 */, 18 },
- /* 5290 */ { MAD_F(0x05a03742) /* 0.351615200 */, 18 },
- /* 5291 */ { MAD_F(0x05a09431) /* 0.351703827 */, 18 },
- /* 5292 */ { MAD_F(0x05a0f121) /* 0.351792459 */, 18 },
- /* 5293 */ { MAD_F(0x05a14e12) /* 0.351881097 */, 18 },
- /* 5294 */ { MAD_F(0x05a1ab05) /* 0.351969740 */, 18 },
- /* 5295 */ { MAD_F(0x05a207fa) /* 0.352058389 */, 18 },
-
- /* 5296 */ { MAD_F(0x05a264f0) /* 0.352147044 */, 18 },
- /* 5297 */ { MAD_F(0x05a2c1e7) /* 0.352235704 */, 18 },
- /* 5298 */ { MAD_F(0x05a31ee1) /* 0.352324369 */, 18 },
- /* 5299 */ { MAD_F(0x05a37bdb) /* 0.352413041 */, 18 },
- /* 5300 */ { MAD_F(0x05a3d8d7) /* 0.352501718 */, 18 },
- /* 5301 */ { MAD_F(0x05a435d5) /* 0.352590400 */, 18 },
- /* 5302 */ { MAD_F(0x05a492d4) /* 0.352679088 */, 18 },
- /* 5303 */ { MAD_F(0x05a4efd4) /* 0.352767782 */, 18 },
- /* 5304 */ { MAD_F(0x05a54cd6) /* 0.352856481 */, 18 },
- /* 5305 */ { MAD_F(0x05a5a9da) /* 0.352945186 */, 18 },
- /* 5306 */ { MAD_F(0x05a606df) /* 0.353033896 */, 18 },
- /* 5307 */ { MAD_F(0x05a663e5) /* 0.353122612 */, 18 },
- /* 5308 */ { MAD_F(0x05a6c0ed) /* 0.353211333 */, 18 },
- /* 5309 */ { MAD_F(0x05a71df7) /* 0.353300061 */, 18 },
- /* 5310 */ { MAD_F(0x05a77b02) /* 0.353388793 */, 18 },
- /* 5311 */ { MAD_F(0x05a7d80e) /* 0.353477531 */, 18 },
-
- /* 5312 */ { MAD_F(0x05a8351c) /* 0.353566275 */, 18 },
- /* 5313 */ { MAD_F(0x05a8922c) /* 0.353655024 */, 18 },
- /* 5314 */ { MAD_F(0x05a8ef3c) /* 0.353743779 */, 18 },
- /* 5315 */ { MAD_F(0x05a94c4f) /* 0.353832540 */, 18 },
- /* 5316 */ { MAD_F(0x05a9a963) /* 0.353921306 */, 18 },
- /* 5317 */ { MAD_F(0x05aa0678) /* 0.354010077 */, 18 },
- /* 5318 */ { MAD_F(0x05aa638f) /* 0.354098855 */, 18 },
- /* 5319 */ { MAD_F(0x05aac0a8) /* 0.354187637 */, 18 },
- /* 5320 */ { MAD_F(0x05ab1dc2) /* 0.354276426 */, 18 },
- /* 5321 */ { MAD_F(0x05ab7add) /* 0.354365220 */, 18 },
- /* 5322 */ { MAD_F(0x05abd7fa) /* 0.354454019 */, 18 },
- /* 5323 */ { MAD_F(0x05ac3518) /* 0.354542824 */, 18 },
- /* 5324 */ { MAD_F(0x05ac9238) /* 0.354631635 */, 18 },
- /* 5325 */ { MAD_F(0x05acef5a) /* 0.354720451 */, 18 },
- /* 5326 */ { MAD_F(0x05ad4c7d) /* 0.354809272 */, 18 },
- /* 5327 */ { MAD_F(0x05ada9a1) /* 0.354898100 */, 18 },
-
- /* 5328 */ { MAD_F(0x05ae06c7) /* 0.354986932 */, 18 },
- /* 5329 */ { MAD_F(0x05ae63ee) /* 0.355075771 */, 18 },
- /* 5330 */ { MAD_F(0x05aec117) /* 0.355164615 */, 18 },
- /* 5331 */ { MAD_F(0x05af1e41) /* 0.355253464 */, 18 },
- /* 5332 */ { MAD_F(0x05af7b6d) /* 0.355342319 */, 18 },
- /* 5333 */ { MAD_F(0x05afd89b) /* 0.355431180 */, 18 },
- /* 5334 */ { MAD_F(0x05b035c9) /* 0.355520046 */, 18 },
- /* 5335 */ { MAD_F(0x05b092fa) /* 0.355608917 */, 18 },
- /* 5336 */ { MAD_F(0x05b0f02b) /* 0.355697795 */, 18 },
- /* 5337 */ { MAD_F(0x05b14d5f) /* 0.355786677 */, 18 },
- /* 5338 */ { MAD_F(0x05b1aa94) /* 0.355875566 */, 18 },
- /* 5339 */ { MAD_F(0x05b207ca) /* 0.355964460 */, 18 },
- /* 5340 */ { MAD_F(0x05b26502) /* 0.356053359 */, 18 },
- /* 5341 */ { MAD_F(0x05b2c23b) /* 0.356142264 */, 18 },
- /* 5342 */ { MAD_F(0x05b31f76) /* 0.356231175 */, 18 },
- /* 5343 */ { MAD_F(0x05b37cb2) /* 0.356320091 */, 18 },
-
- /* 5344 */ { MAD_F(0x05b3d9f0) /* 0.356409012 */, 18 },
- /* 5345 */ { MAD_F(0x05b4372f) /* 0.356497940 */, 18 },
- /* 5346 */ { MAD_F(0x05b4946f) /* 0.356586872 */, 18 },
- /* 5347 */ { MAD_F(0x05b4f1b2) /* 0.356675811 */, 18 },
- /* 5348 */ { MAD_F(0x05b54ef5) /* 0.356764754 */, 18 },
- /* 5349 */ { MAD_F(0x05b5ac3a) /* 0.356853704 */, 18 },
- /* 5350 */ { MAD_F(0x05b60981) /* 0.356942659 */, 18 },
- /* 5351 */ { MAD_F(0x05b666c9) /* 0.357031619 */, 18 },
- /* 5352 */ { MAD_F(0x05b6c413) /* 0.357120585 */, 18 },
- /* 5353 */ { MAD_F(0x05b7215e) /* 0.357209557 */, 18 },
- /* 5354 */ { MAD_F(0x05b77eab) /* 0.357298534 */, 18 },
- /* 5355 */ { MAD_F(0x05b7dbf9) /* 0.357387516 */, 18 },
- /* 5356 */ { MAD_F(0x05b83948) /* 0.357476504 */, 18 },
- /* 5357 */ { MAD_F(0x05b89699) /* 0.357565498 */, 18 },
- /* 5358 */ { MAD_F(0x05b8f3ec) /* 0.357654497 */, 18 },
- /* 5359 */ { MAD_F(0x05b95140) /* 0.357743502 */, 18 },
-
- /* 5360 */ { MAD_F(0x05b9ae95) /* 0.357832512 */, 18 },
- /* 5361 */ { MAD_F(0x05ba0bec) /* 0.357921528 */, 18 },
- /* 5362 */ { MAD_F(0x05ba6945) /* 0.358010550 */, 18 },
- /* 5363 */ { MAD_F(0x05bac69f) /* 0.358099576 */, 18 },
- /* 5364 */ { MAD_F(0x05bb23fa) /* 0.358188609 */, 18 },
- /* 5365 */ { MAD_F(0x05bb8157) /* 0.358277647 */, 18 },
- /* 5366 */ { MAD_F(0x05bbdeb6) /* 0.358366690 */, 18 },
- /* 5367 */ { MAD_F(0x05bc3c16) /* 0.358455739 */, 18 },
- /* 5368 */ { MAD_F(0x05bc9977) /* 0.358544794 */, 18 },
- /* 5369 */ { MAD_F(0x05bcf6da) /* 0.358633854 */, 18 },
- /* 5370 */ { MAD_F(0x05bd543e) /* 0.358722920 */, 18 },
- /* 5371 */ { MAD_F(0x05bdb1a4) /* 0.358811991 */, 18 },
- /* 5372 */ { MAD_F(0x05be0f0b) /* 0.358901067 */, 18 },
- /* 5373 */ { MAD_F(0x05be6c74) /* 0.358990150 */, 18 },
- /* 5374 */ { MAD_F(0x05bec9df) /* 0.359079237 */, 18 },
- /* 5375 */ { MAD_F(0x05bf274a) /* 0.359168331 */, 18 },
-
- /* 5376 */ { MAD_F(0x05bf84b8) /* 0.359257429 */, 18 },
- /* 5377 */ { MAD_F(0x05bfe226) /* 0.359346534 */, 18 },
- /* 5378 */ { MAD_F(0x05c03f97) /* 0.359435644 */, 18 },
- /* 5379 */ { MAD_F(0x05c09d08) /* 0.359524759 */, 18 },
- /* 5380 */ { MAD_F(0x05c0fa7c) /* 0.359613880 */, 18 },
- /* 5381 */ { MAD_F(0x05c157f0) /* 0.359703006 */, 18 },
- /* 5382 */ { MAD_F(0x05c1b566) /* 0.359792138 */, 18 },
- /* 5383 */ { MAD_F(0x05c212de) /* 0.359881276 */, 18 },
- /* 5384 */ { MAD_F(0x05c27057) /* 0.359970419 */, 18 },
- /* 5385 */ { MAD_F(0x05c2cdd2) /* 0.360059567 */, 18 },
- /* 5386 */ { MAD_F(0x05c32b4e) /* 0.360148721 */, 18 },
- /* 5387 */ { MAD_F(0x05c388cb) /* 0.360237881 */, 18 },
- /* 5388 */ { MAD_F(0x05c3e64b) /* 0.360327046 */, 18 },
- /* 5389 */ { MAD_F(0x05c443cb) /* 0.360416216 */, 18 },
- /* 5390 */ { MAD_F(0x05c4a14d) /* 0.360505392 */, 18 },
- /* 5391 */ { MAD_F(0x05c4fed1) /* 0.360594574 */, 18 },
-
- /* 5392 */ { MAD_F(0x05c55c56) /* 0.360683761 */, 18 },
- /* 5393 */ { MAD_F(0x05c5b9dc) /* 0.360772953 */, 18 },
- /* 5394 */ { MAD_F(0x05c61764) /* 0.360862152 */, 18 },
- /* 5395 */ { MAD_F(0x05c674ed) /* 0.360951355 */, 18 },
- /* 5396 */ { MAD_F(0x05c6d278) /* 0.361040564 */, 18 },
- /* 5397 */ { MAD_F(0x05c73005) /* 0.361129779 */, 18 },
- /* 5398 */ { MAD_F(0x05c78d93) /* 0.361218999 */, 18 },
- /* 5399 */ { MAD_F(0x05c7eb22) /* 0.361308225 */, 18 },
- /* 5400 */ { MAD_F(0x05c848b3) /* 0.361397456 */, 18 },
- /* 5401 */ { MAD_F(0x05c8a645) /* 0.361486693 */, 18 },
- /* 5402 */ { MAD_F(0x05c903d9) /* 0.361575935 */, 18 },
- /* 5403 */ { MAD_F(0x05c9616e) /* 0.361665183 */, 18 },
- /* 5404 */ { MAD_F(0x05c9bf05) /* 0.361754436 */, 18 },
- /* 5405 */ { MAD_F(0x05ca1c9d) /* 0.361843695 */, 18 },
- /* 5406 */ { MAD_F(0x05ca7a37) /* 0.361932959 */, 18 },
- /* 5407 */ { MAD_F(0x05cad7d2) /* 0.362022229 */, 18 },
-
- /* 5408 */ { MAD_F(0x05cb356e) /* 0.362111504 */, 18 },
- /* 5409 */ { MAD_F(0x05cb930d) /* 0.362200785 */, 18 },
- /* 5410 */ { MAD_F(0x05cbf0ac) /* 0.362290071 */, 18 },
- /* 5411 */ { MAD_F(0x05cc4e4d) /* 0.362379362 */, 18 },
- /* 5412 */ { MAD_F(0x05ccabf0) /* 0.362468660 */, 18 },
- /* 5413 */ { MAD_F(0x05cd0994) /* 0.362557962 */, 18 },
- /* 5414 */ { MAD_F(0x05cd6739) /* 0.362647271 */, 18 },
- /* 5415 */ { MAD_F(0x05cdc4e0) /* 0.362736584 */, 18 },
- /* 5416 */ { MAD_F(0x05ce2289) /* 0.362825904 */, 18 },
- /* 5417 */ { MAD_F(0x05ce8033) /* 0.362915228 */, 18 },
- /* 5418 */ { MAD_F(0x05ceddde) /* 0.363004559 */, 18 },
- /* 5419 */ { MAD_F(0x05cf3b8b) /* 0.363093894 */, 18 },
- /* 5420 */ { MAD_F(0x05cf9939) /* 0.363183236 */, 18 },
- /* 5421 */ { MAD_F(0x05cff6e9) /* 0.363272582 */, 18 },
- /* 5422 */ { MAD_F(0x05d0549a) /* 0.363361935 */, 18 },
- /* 5423 */ { MAD_F(0x05d0b24d) /* 0.363451292 */, 18 },
-
- /* 5424 */ { MAD_F(0x05d11001) /* 0.363540655 */, 18 },
- /* 5425 */ { MAD_F(0x05d16db7) /* 0.363630024 */, 18 },
- /* 5426 */ { MAD_F(0x05d1cb6e) /* 0.363719398 */, 18 },
- /* 5427 */ { MAD_F(0x05d22927) /* 0.363808778 */, 18 },
- /* 5428 */ { MAD_F(0x05d286e1) /* 0.363898163 */, 18 },
- /* 5429 */ { MAD_F(0x05d2e49d) /* 0.363987554 */, 18 },
- /* 5430 */ { MAD_F(0x05d3425a) /* 0.364076950 */, 18 },
- /* 5431 */ { MAD_F(0x05d3a018) /* 0.364166352 */, 18 },
- /* 5432 */ { MAD_F(0x05d3fdd8) /* 0.364255759 */, 18 },
- /* 5433 */ { MAD_F(0x05d45b9a) /* 0.364345171 */, 18 },
- /* 5434 */ { MAD_F(0x05d4b95d) /* 0.364434589 */, 18 },
- /* 5435 */ { MAD_F(0x05d51721) /* 0.364524013 */, 18 },
- /* 5436 */ { MAD_F(0x05d574e7) /* 0.364613442 */, 18 },
- /* 5437 */ { MAD_F(0x05d5d2af) /* 0.364702877 */, 18 },
- /* 5438 */ { MAD_F(0x05d63078) /* 0.364792317 */, 18 },
- /* 5439 */ { MAD_F(0x05d68e42) /* 0.364881762 */, 18 },
-
- /* 5440 */ { MAD_F(0x05d6ec0e) /* 0.364971213 */, 18 },
- /* 5441 */ { MAD_F(0x05d749db) /* 0.365060669 */, 18 },
- /* 5442 */ { MAD_F(0x05d7a7aa) /* 0.365150131 */, 18 },
- /* 5443 */ { MAD_F(0x05d8057a) /* 0.365239599 */, 18 },
- /* 5444 */ { MAD_F(0x05d8634c) /* 0.365329072 */, 18 },
- /* 5445 */ { MAD_F(0x05d8c11f) /* 0.365418550 */, 18 },
- /* 5446 */ { MAD_F(0x05d91ef4) /* 0.365508034 */, 18 },
- /* 5447 */ { MAD_F(0x05d97cca) /* 0.365597523 */, 18 },
- /* 5448 */ { MAD_F(0x05d9daa1) /* 0.365687018 */, 18 },
- /* 5449 */ { MAD_F(0x05da387a) /* 0.365776518 */, 18 },
- /* 5450 */ { MAD_F(0x05da9655) /* 0.365866024 */, 18 },
- /* 5451 */ { MAD_F(0x05daf431) /* 0.365955536 */, 18 },
- /* 5452 */ { MAD_F(0x05db520e) /* 0.366045052 */, 18 },
- /* 5453 */ { MAD_F(0x05dbafed) /* 0.366134574 */, 18 },
- /* 5454 */ { MAD_F(0x05dc0dce) /* 0.366224102 */, 18 },
- /* 5455 */ { MAD_F(0x05dc6baf) /* 0.366313635 */, 18 },
-
- /* 5456 */ { MAD_F(0x05dcc993) /* 0.366403174 */, 18 },
- /* 5457 */ { MAD_F(0x05dd2778) /* 0.366492718 */, 18 },
- /* 5458 */ { MAD_F(0x05dd855e) /* 0.366582267 */, 18 },
- /* 5459 */ { MAD_F(0x05dde346) /* 0.366671822 */, 18 },
- /* 5460 */ { MAD_F(0x05de412f) /* 0.366761383 */, 18 },
- /* 5461 */ { MAD_F(0x05de9f1a) /* 0.366850949 */, 18 },
- /* 5462 */ { MAD_F(0x05defd06) /* 0.366940520 */, 18 },
- /* 5463 */ { MAD_F(0x05df5af3) /* 0.367030097 */, 18 },
- /* 5464 */ { MAD_F(0x05dfb8e2) /* 0.367119680 */, 18 },
- /* 5465 */ { MAD_F(0x05e016d3) /* 0.367209267 */, 18 },
- /* 5466 */ { MAD_F(0x05e074c5) /* 0.367298861 */, 18 },
- /* 5467 */ { MAD_F(0x05e0d2b8) /* 0.367388459 */, 18 },
- /* 5468 */ { MAD_F(0x05e130ad) /* 0.367478064 */, 18 },
- /* 5469 */ { MAD_F(0x05e18ea4) /* 0.367567673 */, 18 },
- /* 5470 */ { MAD_F(0x05e1ec9c) /* 0.367657288 */, 18 },
- /* 5471 */ { MAD_F(0x05e24a95) /* 0.367746909 */, 18 },
-
- /* 5472 */ { MAD_F(0x05e2a890) /* 0.367836535 */, 18 },
- /* 5473 */ { MAD_F(0x05e3068c) /* 0.367926167 */, 18 },
- /* 5474 */ { MAD_F(0x05e3648a) /* 0.368015804 */, 18 },
- /* 5475 */ { MAD_F(0x05e3c289) /* 0.368105446 */, 18 },
- /* 5476 */ { MAD_F(0x05e4208a) /* 0.368195094 */, 18 },
- /* 5477 */ { MAD_F(0x05e47e8c) /* 0.368284747 */, 18 },
- /* 5478 */ { MAD_F(0x05e4dc8f) /* 0.368374406 */, 18 },
- /* 5479 */ { MAD_F(0x05e53a94) /* 0.368464070 */, 18 },
- /* 5480 */ { MAD_F(0x05e5989b) /* 0.368553740 */, 18 },
- /* 5481 */ { MAD_F(0x05e5f6a3) /* 0.368643415 */, 18 },
- /* 5482 */ { MAD_F(0x05e654ac) /* 0.368733096 */, 18 },
- /* 5483 */ { MAD_F(0x05e6b2b7) /* 0.368822782 */, 18 },
- /* 5484 */ { MAD_F(0x05e710c4) /* 0.368912473 */, 18 },
- /* 5485 */ { MAD_F(0x05e76ed2) /* 0.369002170 */, 18 },
- /* 5486 */ { MAD_F(0x05e7cce1) /* 0.369091873 */, 18 },
- /* 5487 */ { MAD_F(0x05e82af2) /* 0.369181581 */, 18 },
-
- /* 5488 */ { MAD_F(0x05e88904) /* 0.369271294 */, 18 },
- /* 5489 */ { MAD_F(0x05e8e718) /* 0.369361013 */, 18 },
- /* 5490 */ { MAD_F(0x05e9452d) /* 0.369450737 */, 18 },
- /* 5491 */ { MAD_F(0x05e9a343) /* 0.369540467 */, 18 },
- /* 5492 */ { MAD_F(0x05ea015c) /* 0.369630202 */, 18 },
- /* 5493 */ { MAD_F(0x05ea5f75) /* 0.369719942 */, 18 },
- /* 5494 */ { MAD_F(0x05eabd90) /* 0.369809688 */, 18 },
- /* 5495 */ { MAD_F(0x05eb1bad) /* 0.369899440 */, 18 },
- /* 5496 */ { MAD_F(0x05eb79cb) /* 0.369989197 */, 18 },
- /* 5497 */ { MAD_F(0x05ebd7ea) /* 0.370078959 */, 18 },
- /* 5498 */ { MAD_F(0x05ec360b) /* 0.370168727 */, 18 },
- /* 5499 */ { MAD_F(0x05ec942d) /* 0.370258500 */, 18 },
- /* 5500 */ { MAD_F(0x05ecf251) /* 0.370348279 */, 18 },
- /* 5501 */ { MAD_F(0x05ed5076) /* 0.370438063 */, 18 },
- /* 5502 */ { MAD_F(0x05edae9d) /* 0.370527853 */, 18 },
- /* 5503 */ { MAD_F(0x05ee0cc5) /* 0.370617648 */, 18 },
-
- /* 5504 */ { MAD_F(0x05ee6aef) /* 0.370707448 */, 18 },
- /* 5505 */ { MAD_F(0x05eec91a) /* 0.370797254 */, 18 },
- /* 5506 */ { MAD_F(0x05ef2746) /* 0.370887065 */, 18 },
- /* 5507 */ { MAD_F(0x05ef8574) /* 0.370976882 */, 18 },
- /* 5508 */ { MAD_F(0x05efe3a4) /* 0.371066704 */, 18 },
- /* 5509 */ { MAD_F(0x05f041d5) /* 0.371156532 */, 18 },
- /* 5510 */ { MAD_F(0x05f0a007) /* 0.371246365 */, 18 },
- /* 5511 */ { MAD_F(0x05f0fe3b) /* 0.371336203 */, 18 },
- /* 5512 */ { MAD_F(0x05f15c70) /* 0.371426047 */, 18 },
- /* 5513 */ { MAD_F(0x05f1baa7) /* 0.371515897 */, 18 },
- /* 5514 */ { MAD_F(0x05f218df) /* 0.371605751 */, 18 },
- /* 5515 */ { MAD_F(0x05f27719) /* 0.371695612 */, 18 },
- /* 5516 */ { MAD_F(0x05f2d554) /* 0.371785477 */, 18 },
- /* 5517 */ { MAD_F(0x05f33390) /* 0.371875348 */, 18 },
- /* 5518 */ { MAD_F(0x05f391cf) /* 0.371965225 */, 18 },
- /* 5519 */ { MAD_F(0x05f3f00e) /* 0.372055107 */, 18 },
-
- /* 5520 */ { MAD_F(0x05f44e4f) /* 0.372144994 */, 18 },
- /* 5521 */ { MAD_F(0x05f4ac91) /* 0.372234887 */, 18 },
- /* 5522 */ { MAD_F(0x05f50ad5) /* 0.372324785 */, 18 },
- /* 5523 */ { MAD_F(0x05f5691b) /* 0.372414689 */, 18 },
- /* 5524 */ { MAD_F(0x05f5c761) /* 0.372504598 */, 18 },
- /* 5525 */ { MAD_F(0x05f625aa) /* 0.372594513 */, 18 },
- /* 5526 */ { MAD_F(0x05f683f3) /* 0.372684433 */, 18 },
- /* 5527 */ { MAD_F(0x05f6e23f) /* 0.372774358 */, 18 },
- /* 5528 */ { MAD_F(0x05f7408b) /* 0.372864289 */, 18 },
- /* 5529 */ { MAD_F(0x05f79ed9) /* 0.372954225 */, 18 },
- /* 5530 */ { MAD_F(0x05f7fd29) /* 0.373044167 */, 18 },
- /* 5531 */ { MAD_F(0x05f85b7a) /* 0.373134114 */, 18 },
- /* 5532 */ { MAD_F(0x05f8b9cc) /* 0.373224066 */, 18 },
- /* 5533 */ { MAD_F(0x05f91820) /* 0.373314024 */, 18 },
- /* 5534 */ { MAD_F(0x05f97675) /* 0.373403987 */, 18 },
- /* 5535 */ { MAD_F(0x05f9d4cc) /* 0.373493956 */, 18 },
-
- /* 5536 */ { MAD_F(0x05fa3324) /* 0.373583930 */, 18 },
- /* 5537 */ { MAD_F(0x05fa917e) /* 0.373673910 */, 18 },
- /* 5538 */ { MAD_F(0x05faefd9) /* 0.373763895 */, 18 },
- /* 5539 */ { MAD_F(0x05fb4e36) /* 0.373853885 */, 18 },
- /* 5540 */ { MAD_F(0x05fbac94) /* 0.373943881 */, 18 },
- /* 5541 */ { MAD_F(0x05fc0af3) /* 0.374033882 */, 18 },
- /* 5542 */ { MAD_F(0x05fc6954) /* 0.374123889 */, 18 },
- /* 5543 */ { MAD_F(0x05fcc7b7) /* 0.374213901 */, 18 },
- /* 5544 */ { MAD_F(0x05fd261b) /* 0.374303918 */, 18 },
- /* 5545 */ { MAD_F(0x05fd8480) /* 0.374393941 */, 18 },
- /* 5546 */ { MAD_F(0x05fde2e7) /* 0.374483970 */, 18 },
- /* 5547 */ { MAD_F(0x05fe414f) /* 0.374574003 */, 18 },
- /* 5548 */ { MAD_F(0x05fe9fb9) /* 0.374664042 */, 18 },
- /* 5549 */ { MAD_F(0x05fefe24) /* 0.374754087 */, 18 },
- /* 5550 */ { MAD_F(0x05ff5c91) /* 0.374844137 */, 18 },
- /* 5551 */ { MAD_F(0x05ffbaff) /* 0.374934192 */, 18 },
-
- /* 5552 */ { MAD_F(0x0600196e) /* 0.375024253 */, 18 },
- /* 5553 */ { MAD_F(0x060077df) /* 0.375114319 */, 18 },
- /* 5554 */ { MAD_F(0x0600d651) /* 0.375204391 */, 18 },
- /* 5555 */ { MAD_F(0x060134c5) /* 0.375294468 */, 18 },
- /* 5556 */ { MAD_F(0x0601933b) /* 0.375384550 */, 18 },
- /* 5557 */ { MAD_F(0x0601f1b1) /* 0.375474638 */, 18 },
- /* 5558 */ { MAD_F(0x0602502a) /* 0.375564731 */, 18 },
- /* 5559 */ { MAD_F(0x0602aea3) /* 0.375654830 */, 18 },
- /* 5560 */ { MAD_F(0x06030d1e) /* 0.375744934 */, 18 },
- /* 5561 */ { MAD_F(0x06036b9b) /* 0.375835043 */, 18 },
- /* 5562 */ { MAD_F(0x0603ca19) /* 0.375925158 */, 18 },
- /* 5563 */ { MAD_F(0x06042898) /* 0.376015278 */, 18 },
- /* 5564 */ { MAD_F(0x06048719) /* 0.376105404 */, 18 },
- /* 5565 */ { MAD_F(0x0604e59c) /* 0.376195535 */, 18 },
- /* 5566 */ { MAD_F(0x0605441f) /* 0.376285671 */, 18 },
- /* 5567 */ { MAD_F(0x0605a2a5) /* 0.376375813 */, 18 },
-
- /* 5568 */ { MAD_F(0x0606012b) /* 0.376465960 */, 18 },
- /* 5569 */ { MAD_F(0x06065fb4) /* 0.376556113 */, 18 },
- /* 5570 */ { MAD_F(0x0606be3d) /* 0.376646271 */, 18 },
- /* 5571 */ { MAD_F(0x06071cc8) /* 0.376736434 */, 18 },
- /* 5572 */ { MAD_F(0x06077b55) /* 0.376826603 */, 18 },
- /* 5573 */ { MAD_F(0x0607d9e3) /* 0.376916777 */, 18 },
- /* 5574 */ { MAD_F(0x06083872) /* 0.377006957 */, 18 },
- /* 5575 */ { MAD_F(0x06089703) /* 0.377097141 */, 18 },
- /* 5576 */ { MAD_F(0x0608f595) /* 0.377187332 */, 18 },
- /* 5577 */ { MAD_F(0x06095429) /* 0.377277528 */, 18 },
- /* 5578 */ { MAD_F(0x0609b2be) /* 0.377367729 */, 18 },
- /* 5579 */ { MAD_F(0x060a1155) /* 0.377457935 */, 18 },
- /* 5580 */ { MAD_F(0x060a6fed) /* 0.377548147 */, 18 },
- /* 5581 */ { MAD_F(0x060ace86) /* 0.377638364 */, 18 },
- /* 5582 */ { MAD_F(0x060b2d21) /* 0.377728587 */, 18 },
- /* 5583 */ { MAD_F(0x060b8bbe) /* 0.377818815 */, 18 },
-
- /* 5584 */ { MAD_F(0x060bea5c) /* 0.377909049 */, 18 },
- /* 5585 */ { MAD_F(0x060c48fb) /* 0.377999288 */, 18 },
- /* 5586 */ { MAD_F(0x060ca79c) /* 0.378089532 */, 18 },
- /* 5587 */ { MAD_F(0x060d063e) /* 0.378179781 */, 18 },
- /* 5588 */ { MAD_F(0x060d64e1) /* 0.378270036 */, 18 },
- /* 5589 */ { MAD_F(0x060dc387) /* 0.378360297 */, 18 },
- /* 5590 */ { MAD_F(0x060e222d) /* 0.378450563 */, 18 },
- /* 5591 */ { MAD_F(0x060e80d5) /* 0.378540834 */, 18 },
- /* 5592 */ { MAD_F(0x060edf7f) /* 0.378631110 */, 18 },
- /* 5593 */ { MAD_F(0x060f3e29) /* 0.378721392 */, 18 },
- /* 5594 */ { MAD_F(0x060f9cd6) /* 0.378811680 */, 18 },
- /* 5595 */ { MAD_F(0x060ffb83) /* 0.378901972 */, 18 },
- /* 5596 */ { MAD_F(0x06105a33) /* 0.378992270 */, 18 },
- /* 5597 */ { MAD_F(0x0610b8e3) /* 0.379082574 */, 18 },
- /* 5598 */ { MAD_F(0x06111795) /* 0.379172883 */, 18 },
- /* 5599 */ { MAD_F(0x06117649) /* 0.379263197 */, 18 },
-
- /* 5600 */ { MAD_F(0x0611d4fe) /* 0.379353516 */, 18 },
- /* 5601 */ { MAD_F(0x061233b4) /* 0.379443841 */, 18 },
- /* 5602 */ { MAD_F(0x0612926c) /* 0.379534172 */, 18 },
- /* 5603 */ { MAD_F(0x0612f125) /* 0.379624507 */, 18 },
- /* 5604 */ { MAD_F(0x06134fe0) /* 0.379714848 */, 18 },
- /* 5605 */ { MAD_F(0x0613ae9c) /* 0.379805195 */, 18 },
- /* 5606 */ { MAD_F(0x06140d5a) /* 0.379895547 */, 18 },
- /* 5607 */ { MAD_F(0x06146c19) /* 0.379985904 */, 18 },
- /* 5608 */ { MAD_F(0x0614cada) /* 0.380076266 */, 18 },
- /* 5609 */ { MAD_F(0x0615299c) /* 0.380166634 */, 18 },
- /* 5610 */ { MAD_F(0x0615885f) /* 0.380257008 */, 18 },
- /* 5611 */ { MAD_F(0x0615e724) /* 0.380347386 */, 18 },
- /* 5612 */ { MAD_F(0x061645ea) /* 0.380437770 */, 18 },
- /* 5613 */ { MAD_F(0x0616a4b2) /* 0.380528160 */, 18 },
- /* 5614 */ { MAD_F(0x0617037b) /* 0.380618555 */, 18 },
- /* 5615 */ { MAD_F(0x06176246) /* 0.380708955 */, 18 },
-
- /* 5616 */ { MAD_F(0x0617c112) /* 0.380799360 */, 18 },
- /* 5617 */ { MAD_F(0x06181fdf) /* 0.380889771 */, 18 },
- /* 5618 */ { MAD_F(0x06187eae) /* 0.380980187 */, 18 },
- /* 5619 */ { MAD_F(0x0618dd7e) /* 0.381070609 */, 18 },
- /* 5620 */ { MAD_F(0x06193c50) /* 0.381161036 */, 18 },
- /* 5621 */ { MAD_F(0x06199b24) /* 0.381251468 */, 18 },
- /* 5622 */ { MAD_F(0x0619f9f8) /* 0.381341906 */, 18 },
- /* 5623 */ { MAD_F(0x061a58ce) /* 0.381432349 */, 18 },
- /* 5624 */ { MAD_F(0x061ab7a6) /* 0.381522798 */, 18 },
- /* 5625 */ { MAD_F(0x061b167f) /* 0.381613251 */, 18 },
- /* 5626 */ { MAD_F(0x061b7559) /* 0.381703711 */, 18 },
- /* 5627 */ { MAD_F(0x061bd435) /* 0.381794175 */, 18 },
- /* 5628 */ { MAD_F(0x061c3313) /* 0.381884645 */, 18 },
- /* 5629 */ { MAD_F(0x061c91f1) /* 0.381975120 */, 18 },
- /* 5630 */ { MAD_F(0x061cf0d2) /* 0.382065601 */, 18 },
- /* 5631 */ { MAD_F(0x061d4fb3) /* 0.382156087 */, 18 },
-
- /* 5632 */ { MAD_F(0x061dae96) /* 0.382246578 */, 18 },
- /* 5633 */ { MAD_F(0x061e0d7b) /* 0.382337075 */, 18 },
- /* 5634 */ { MAD_F(0x061e6c61) /* 0.382427577 */, 18 },
- /* 5635 */ { MAD_F(0x061ecb48) /* 0.382518084 */, 18 },
- /* 5636 */ { MAD_F(0x061f2a31) /* 0.382608597 */, 18 },
- /* 5637 */ { MAD_F(0x061f891b) /* 0.382699115 */, 18 },
- /* 5638 */ { MAD_F(0x061fe807) /* 0.382789638 */, 18 },
- /* 5639 */ { MAD_F(0x062046f4) /* 0.382880167 */, 18 },
- /* 5640 */ { MAD_F(0x0620a5e3) /* 0.382970701 */, 18 },
- /* 5641 */ { MAD_F(0x062104d3) /* 0.383061241 */, 18 },
- /* 5642 */ { MAD_F(0x062163c4) /* 0.383151786 */, 18 },
- /* 5643 */ { MAD_F(0x0621c2b7) /* 0.383242336 */, 18 },
- /* 5644 */ { MAD_F(0x062221ab) /* 0.383332891 */, 18 },
- /* 5645 */ { MAD_F(0x062280a1) /* 0.383423452 */, 18 },
- /* 5646 */ { MAD_F(0x0622df98) /* 0.383514018 */, 18 },
- /* 5647 */ { MAD_F(0x06233e91) /* 0.383604590 */, 18 },
-
- /* 5648 */ { MAD_F(0x06239d8b) /* 0.383695167 */, 18 },
- /* 5649 */ { MAD_F(0x0623fc86) /* 0.383785749 */, 18 },
- /* 5650 */ { MAD_F(0x06245b83) /* 0.383876337 */, 18 },
- /* 5651 */ { MAD_F(0x0624ba82) /* 0.383966930 */, 18 },
- /* 5652 */ { MAD_F(0x06251981) /* 0.384057528 */, 18 },
- /* 5653 */ { MAD_F(0x06257883) /* 0.384148132 */, 18 },
- /* 5654 */ { MAD_F(0x0625d785) /* 0.384238741 */, 18 },
- /* 5655 */ { MAD_F(0x06263689) /* 0.384329355 */, 18 },
- /* 5656 */ { MAD_F(0x0626958f) /* 0.384419975 */, 18 },
- /* 5657 */ { MAD_F(0x0626f496) /* 0.384510600 */, 18 },
- /* 5658 */ { MAD_F(0x0627539e) /* 0.384601230 */, 18 },
- /* 5659 */ { MAD_F(0x0627b2a8) /* 0.384691866 */, 18 },
- /* 5660 */ { MAD_F(0x062811b3) /* 0.384782507 */, 18 },
- /* 5661 */ { MAD_F(0x062870c0) /* 0.384873153 */, 18 },
- /* 5662 */ { MAD_F(0x0628cfce) /* 0.384963805 */, 18 },
- /* 5663 */ { MAD_F(0x06292ede) /* 0.385054462 */, 18 },
-
- /* 5664 */ { MAD_F(0x06298def) /* 0.385145124 */, 18 },
- /* 5665 */ { MAD_F(0x0629ed01) /* 0.385235792 */, 18 },
- /* 5666 */ { MAD_F(0x062a4c15) /* 0.385326465 */, 18 },
- /* 5667 */ { MAD_F(0x062aab2a) /* 0.385417143 */, 18 },
- /* 5668 */ { MAD_F(0x062b0a41) /* 0.385507827 */, 18 },
- /* 5669 */ { MAD_F(0x062b6959) /* 0.385598516 */, 18 },
- /* 5670 */ { MAD_F(0x062bc873) /* 0.385689211 */, 18 },
- /* 5671 */ { MAD_F(0x062c278e) /* 0.385779910 */, 18 },
- /* 5672 */ { MAD_F(0x062c86aa) /* 0.385870615 */, 18 },
- /* 5673 */ { MAD_F(0x062ce5c8) /* 0.385961326 */, 18 },
- /* 5674 */ { MAD_F(0x062d44e8) /* 0.386052041 */, 18 },
- /* 5675 */ { MAD_F(0x062da408) /* 0.386142762 */, 18 },
- /* 5676 */ { MAD_F(0x062e032a) /* 0.386233489 */, 18 },
- /* 5677 */ { MAD_F(0x062e624e) /* 0.386324221 */, 18 },
- /* 5678 */ { MAD_F(0x062ec173) /* 0.386414958 */, 18 },
- /* 5679 */ { MAD_F(0x062f209a) /* 0.386505700 */, 18 },
-
- /* 5680 */ { MAD_F(0x062f7fc1) /* 0.386596448 */, 18 },
- /* 5681 */ { MAD_F(0x062fdeeb) /* 0.386687201 */, 18 },
- /* 5682 */ { MAD_F(0x06303e16) /* 0.386777959 */, 18 },
- /* 5683 */ { MAD_F(0x06309d42) /* 0.386868723 */, 18 },
- /* 5684 */ { MAD_F(0x0630fc6f) /* 0.386959492 */, 18 },
- /* 5685 */ { MAD_F(0x06315b9e) /* 0.387050266 */, 18 },
- /* 5686 */ { MAD_F(0x0631bacf) /* 0.387141045 */, 18 },
- /* 5687 */ { MAD_F(0x06321a01) /* 0.387231830 */, 18 },
- /* 5688 */ { MAD_F(0x06327934) /* 0.387322621 */, 18 },
- /* 5689 */ { MAD_F(0x0632d869) /* 0.387413416 */, 18 },
- /* 5690 */ { MAD_F(0x0633379f) /* 0.387504217 */, 18 },
- /* 5691 */ { MAD_F(0x063396d7) /* 0.387595023 */, 18 },
- /* 5692 */ { MAD_F(0x0633f610) /* 0.387685835 */, 18 },
- /* 5693 */ { MAD_F(0x0634554a) /* 0.387776652 */, 18 },
- /* 5694 */ { MAD_F(0x0634b486) /* 0.387867474 */, 18 },
- /* 5695 */ { MAD_F(0x063513c3) /* 0.387958301 */, 18 },
-
- /* 5696 */ { MAD_F(0x06357302) /* 0.388049134 */, 18 },
- /* 5697 */ { MAD_F(0x0635d242) /* 0.388139972 */, 18 },
- /* 5698 */ { MAD_F(0x06363184) /* 0.388230816 */, 18 },
- /* 5699 */ { MAD_F(0x063690c7) /* 0.388321665 */, 18 },
- /* 5700 */ { MAD_F(0x0636f00b) /* 0.388412519 */, 18 },
- /* 5701 */ { MAD_F(0x06374f51) /* 0.388503378 */, 18 },
- /* 5702 */ { MAD_F(0x0637ae99) /* 0.388594243 */, 18 },
- /* 5703 */ { MAD_F(0x06380de1) /* 0.388685113 */, 18 },
- /* 5704 */ { MAD_F(0x06386d2b) /* 0.388775988 */, 18 },
- /* 5705 */ { MAD_F(0x0638cc77) /* 0.388866869 */, 18 },
- /* 5706 */ { MAD_F(0x06392bc4) /* 0.388957755 */, 18 },
- /* 5707 */ { MAD_F(0x06398b12) /* 0.389048646 */, 18 },
- /* 5708 */ { MAD_F(0x0639ea62) /* 0.389139542 */, 18 },
- /* 5709 */ { MAD_F(0x063a49b4) /* 0.389230444 */, 18 },
- /* 5710 */ { MAD_F(0x063aa906) /* 0.389321352 */, 18 },
- /* 5711 */ { MAD_F(0x063b085a) /* 0.389412264 */, 18 },
-
- /* 5712 */ { MAD_F(0x063b67b0) /* 0.389503182 */, 18 },
- /* 5713 */ { MAD_F(0x063bc707) /* 0.389594105 */, 18 },
- /* 5714 */ { MAD_F(0x063c265f) /* 0.389685033 */, 18 },
- /* 5715 */ { MAD_F(0x063c85b9) /* 0.389775967 */, 18 },
- /* 5716 */ { MAD_F(0x063ce514) /* 0.389866906 */, 18 },
- /* 5717 */ { MAD_F(0x063d4471) /* 0.389957850 */, 18 },
- /* 5718 */ { MAD_F(0x063da3cf) /* 0.390048800 */, 18 },
- /* 5719 */ { MAD_F(0x063e032f) /* 0.390139755 */, 18 },
- /* 5720 */ { MAD_F(0x063e6290) /* 0.390230715 */, 18 },
- /* 5721 */ { MAD_F(0x063ec1f2) /* 0.390321681 */, 18 },
- /* 5722 */ { MAD_F(0x063f2156) /* 0.390412651 */, 18 },
- /* 5723 */ { MAD_F(0x063f80bb) /* 0.390503628 */, 18 },
- /* 5724 */ { MAD_F(0x063fe022) /* 0.390594609 */, 18 },
- /* 5725 */ { MAD_F(0x06403f8a) /* 0.390685596 */, 18 },
- /* 5726 */ { MAD_F(0x06409ef3) /* 0.390776588 */, 18 },
- /* 5727 */ { MAD_F(0x0640fe5e) /* 0.390867585 */, 18 },
-
- /* 5728 */ { MAD_F(0x06415dcb) /* 0.390958588 */, 18 },
- /* 5729 */ { MAD_F(0x0641bd38) /* 0.391049596 */, 18 },
- /* 5730 */ { MAD_F(0x06421ca7) /* 0.391140609 */, 18 },
- /* 5731 */ { MAD_F(0x06427c18) /* 0.391231627 */, 18 },
- /* 5732 */ { MAD_F(0x0642db8a) /* 0.391322651 */, 18 },
- /* 5733 */ { MAD_F(0x06433afd) /* 0.391413680 */, 18 },
- /* 5734 */ { MAD_F(0x06439a72) /* 0.391504714 */, 18 },
- /* 5735 */ { MAD_F(0x0643f9e9) /* 0.391595754 */, 18 },
- /* 5736 */ { MAD_F(0x06445960) /* 0.391686799 */, 18 },
- /* 5737 */ { MAD_F(0x0644b8d9) /* 0.391777849 */, 18 },
- /* 5738 */ { MAD_F(0x06451854) /* 0.391868905 */, 18 },
- /* 5739 */ { MAD_F(0x064577d0) /* 0.391959966 */, 18 },
- /* 5740 */ { MAD_F(0x0645d74d) /* 0.392051032 */, 18 },
- /* 5741 */ { MAD_F(0x064636cc) /* 0.392142103 */, 18 },
- /* 5742 */ { MAD_F(0x0646964c) /* 0.392233180 */, 18 },
- /* 5743 */ { MAD_F(0x0646f5ce) /* 0.392324262 */, 18 },
-
- /* 5744 */ { MAD_F(0x06475551) /* 0.392415349 */, 18 },
- /* 5745 */ { MAD_F(0x0647b4d5) /* 0.392506442 */, 18 },
- /* 5746 */ { MAD_F(0x0648145b) /* 0.392597540 */, 18 },
- /* 5747 */ { MAD_F(0x064873e3) /* 0.392688643 */, 18 },
- /* 5748 */ { MAD_F(0x0648d36b) /* 0.392779751 */, 18 },
- /* 5749 */ { MAD_F(0x064932f6) /* 0.392870865 */, 18 },
- /* 5750 */ { MAD_F(0x06499281) /* 0.392961984 */, 18 },
- /* 5751 */ { MAD_F(0x0649f20e) /* 0.393053108 */, 18 },
- /* 5752 */ { MAD_F(0x064a519c) /* 0.393144238 */, 18 },
- /* 5753 */ { MAD_F(0x064ab12c) /* 0.393235372 */, 18 },
- /* 5754 */ { MAD_F(0x064b10be) /* 0.393326513 */, 18 },
- /* 5755 */ { MAD_F(0x064b7050) /* 0.393417658 */, 18 },
- /* 5756 */ { MAD_F(0x064bcfe4) /* 0.393508809 */, 18 },
- /* 5757 */ { MAD_F(0x064c2f7a) /* 0.393599965 */, 18 },
- /* 5758 */ { MAD_F(0x064c8f11) /* 0.393691126 */, 18 },
- /* 5759 */ { MAD_F(0x064ceea9) /* 0.393782292 */, 18 },
-
- /* 5760 */ { MAD_F(0x064d4e43) /* 0.393873464 */, 18 },
- /* 5761 */ { MAD_F(0x064dadde) /* 0.393964641 */, 18 },
- /* 5762 */ { MAD_F(0x064e0d7a) /* 0.394055823 */, 18 },
- /* 5763 */ { MAD_F(0x064e6d18) /* 0.394147011 */, 18 },
- /* 5764 */ { MAD_F(0x064eccb8) /* 0.394238204 */, 18 },
- /* 5765 */ { MAD_F(0x064f2c59) /* 0.394329402 */, 18 },
- /* 5766 */ { MAD_F(0x064f8bfb) /* 0.394420605 */, 18 },
- /* 5767 */ { MAD_F(0x064feb9e) /* 0.394511814 */, 18 },
- /* 5768 */ { MAD_F(0x06504b44) /* 0.394603028 */, 18 },
- /* 5769 */ { MAD_F(0x0650aaea) /* 0.394694247 */, 18 },
- /* 5770 */ { MAD_F(0x06510a92) /* 0.394785472 */, 18 },
- /* 5771 */ { MAD_F(0x06516a3b) /* 0.394876702 */, 18 },
- /* 5772 */ { MAD_F(0x0651c9e6) /* 0.394967937 */, 18 },
- /* 5773 */ { MAD_F(0x06522992) /* 0.395059177 */, 18 },
- /* 5774 */ { MAD_F(0x06528940) /* 0.395150423 */, 18 },
- /* 5775 */ { MAD_F(0x0652e8ef) /* 0.395241673 */, 18 },
-
- /* 5776 */ { MAD_F(0x0653489f) /* 0.395332930 */, 18 },
- /* 5777 */ { MAD_F(0x0653a851) /* 0.395424191 */, 18 },
- /* 5778 */ { MAD_F(0x06540804) /* 0.395515458 */, 18 },
- /* 5779 */ { MAD_F(0x065467b9) /* 0.395606730 */, 18 },
- /* 5780 */ { MAD_F(0x0654c76f) /* 0.395698007 */, 18 },
- /* 5781 */ { MAD_F(0x06552726) /* 0.395789289 */, 18 },
- /* 5782 */ { MAD_F(0x065586df) /* 0.395880577 */, 18 },
- /* 5783 */ { MAD_F(0x0655e699) /* 0.395971870 */, 18 },
- /* 5784 */ { MAD_F(0x06564655) /* 0.396063168 */, 18 },
- /* 5785 */ { MAD_F(0x0656a612) /* 0.396154472 */, 18 },
- /* 5786 */ { MAD_F(0x065705d0) /* 0.396245780 */, 18 },
- /* 5787 */ { MAD_F(0x06576590) /* 0.396337094 */, 18 },
- /* 5788 */ { MAD_F(0x0657c552) /* 0.396428414 */, 18 },
- /* 5789 */ { MAD_F(0x06582514) /* 0.396519738 */, 18 },
- /* 5790 */ { MAD_F(0x065884d9) /* 0.396611068 */, 18 },
- /* 5791 */ { MAD_F(0x0658e49e) /* 0.396702403 */, 18 },
-
- /* 5792 */ { MAD_F(0x06594465) /* 0.396793743 */, 18 },
- /* 5793 */ { MAD_F(0x0659a42e) /* 0.396885089 */, 18 },
- /* 5794 */ { MAD_F(0x065a03f7) /* 0.396976440 */, 18 },
- /* 5795 */ { MAD_F(0x065a63c3) /* 0.397067796 */, 18 },
- /* 5796 */ { MAD_F(0x065ac38f) /* 0.397159157 */, 18 },
- /* 5797 */ { MAD_F(0x065b235d) /* 0.397250524 */, 18 },
- /* 5798 */ { MAD_F(0x065b832d) /* 0.397341896 */, 18 },
- /* 5799 */ { MAD_F(0x065be2fe) /* 0.397433273 */, 18 },
- /* 5800 */ { MAD_F(0x065c42d0) /* 0.397524655 */, 18 },
- /* 5801 */ { MAD_F(0x065ca2a3) /* 0.397616043 */, 18 },
- /* 5802 */ { MAD_F(0x065d0279) /* 0.397707436 */, 18 },
- /* 5803 */ { MAD_F(0x065d624f) /* 0.397798834 */, 18 },
- /* 5804 */ { MAD_F(0x065dc227) /* 0.397890237 */, 18 },
- /* 5805 */ { MAD_F(0x065e2200) /* 0.397981646 */, 18 },
- /* 5806 */ { MAD_F(0x065e81db) /* 0.398073059 */, 18 },
- /* 5807 */ { MAD_F(0x065ee1b7) /* 0.398164479 */, 18 },
-
- /* 5808 */ { MAD_F(0x065f4195) /* 0.398255903 */, 18 },
- /* 5809 */ { MAD_F(0x065fa174) /* 0.398347333 */, 18 },
- /* 5810 */ { MAD_F(0x06600154) /* 0.398438767 */, 18 },
- /* 5811 */ { MAD_F(0x06606136) /* 0.398530207 */, 18 },
- /* 5812 */ { MAD_F(0x0660c119) /* 0.398621653 */, 18 },
- /* 5813 */ { MAD_F(0x066120fd) /* 0.398713103 */, 18 },
- /* 5814 */ { MAD_F(0x066180e3) /* 0.398804559 */, 18 },
- /* 5815 */ { MAD_F(0x0661e0cb) /* 0.398896020 */, 18 },
- /* 5816 */ { MAD_F(0x066240b4) /* 0.398987487 */, 18 },
- /* 5817 */ { MAD_F(0x0662a09e) /* 0.399078958 */, 18 },
- /* 5818 */ { MAD_F(0x06630089) /* 0.399170435 */, 18 },
- /* 5819 */ { MAD_F(0x06636077) /* 0.399261917 */, 18 },
- /* 5820 */ { MAD_F(0x0663c065) /* 0.399353404 */, 18 },
- /* 5821 */ { MAD_F(0x06642055) /* 0.399444897 */, 18 },
- /* 5822 */ { MAD_F(0x06648046) /* 0.399536395 */, 18 },
- /* 5823 */ { MAD_F(0x0664e039) /* 0.399627898 */, 18 },
-
- /* 5824 */ { MAD_F(0x0665402d) /* 0.399719406 */, 18 },
- /* 5825 */ { MAD_F(0x0665a022) /* 0.399810919 */, 18 },
- /* 5826 */ { MAD_F(0x06660019) /* 0.399902438 */, 18 },
- /* 5827 */ { MAD_F(0x06666011) /* 0.399993962 */, 18 },
- /* 5828 */ { MAD_F(0x0666c00b) /* 0.400085491 */, 18 },
- /* 5829 */ { MAD_F(0x06672006) /* 0.400177026 */, 18 },
- /* 5830 */ { MAD_F(0x06678003) /* 0.400268565 */, 18 },
- /* 5831 */ { MAD_F(0x0667e000) /* 0.400360110 */, 18 },
- /* 5832 */ { MAD_F(0x06684000) /* 0.400451660 */, 18 },
- /* 5833 */ { MAD_F(0x0668a000) /* 0.400543216 */, 18 },
- /* 5834 */ { MAD_F(0x06690003) /* 0.400634776 */, 18 },
- /* 5835 */ { MAD_F(0x06696006) /* 0.400726342 */, 18 },
- /* 5836 */ { MAD_F(0x0669c00b) /* 0.400817913 */, 18 },
- /* 5837 */ { MAD_F(0x066a2011) /* 0.400909489 */, 18 },
- /* 5838 */ { MAD_F(0x066a8019) /* 0.401001071 */, 18 },
- /* 5839 */ { MAD_F(0x066ae022) /* 0.401092657 */, 18 },
-
- /* 5840 */ { MAD_F(0x066b402d) /* 0.401184249 */, 18 },
- /* 5841 */ { MAD_F(0x066ba039) /* 0.401275847 */, 18 },
- /* 5842 */ { MAD_F(0x066c0046) /* 0.401367449 */, 18 },
- /* 5843 */ { MAD_F(0x066c6055) /* 0.401459057 */, 18 },
- /* 5844 */ { MAD_F(0x066cc065) /* 0.401550670 */, 18 },
- /* 5845 */ { MAD_F(0x066d2076) /* 0.401642288 */, 18 },
- /* 5846 */ { MAD_F(0x066d8089) /* 0.401733911 */, 18 },
- /* 5847 */ { MAD_F(0x066de09e) /* 0.401825540 */, 18 },
- /* 5848 */ { MAD_F(0x066e40b3) /* 0.401917173 */, 18 },
- /* 5849 */ { MAD_F(0x066ea0cb) /* 0.402008812 */, 18 },
- /* 5850 */ { MAD_F(0x066f00e3) /* 0.402100457 */, 18 },
- /* 5851 */ { MAD_F(0x066f60fd) /* 0.402192106 */, 18 },
- /* 5852 */ { MAD_F(0x066fc118) /* 0.402283761 */, 18 },
- /* 5853 */ { MAD_F(0x06702135) /* 0.402375420 */, 18 },
- /* 5854 */ { MAD_F(0x06708153) /* 0.402467086 */, 18 },
- /* 5855 */ { MAD_F(0x0670e173) /* 0.402558756 */, 18 },
-
- /* 5856 */ { MAD_F(0x06714194) /* 0.402650431 */, 18 },
- /* 5857 */ { MAD_F(0x0671a1b6) /* 0.402742112 */, 18 },
- /* 5858 */ { MAD_F(0x067201da) /* 0.402833798 */, 18 },
- /* 5859 */ { MAD_F(0x067261ff) /* 0.402925489 */, 18 },
- /* 5860 */ { MAD_F(0x0672c226) /* 0.403017186 */, 18 },
- /* 5861 */ { MAD_F(0x0673224e) /* 0.403108887 */, 18 },
- /* 5862 */ { MAD_F(0x06738277) /* 0.403200594 */, 18 },
- /* 5863 */ { MAD_F(0x0673e2a2) /* 0.403292306 */, 18 },
- /* 5864 */ { MAD_F(0x067442ce) /* 0.403384024 */, 18 },
- /* 5865 */ { MAD_F(0x0674a2fc) /* 0.403475746 */, 18 },
- /* 5866 */ { MAD_F(0x0675032b) /* 0.403567474 */, 18 },
- /* 5867 */ { MAD_F(0x0675635b) /* 0.403659207 */, 18 },
- /* 5868 */ { MAD_F(0x0675c38d) /* 0.403750945 */, 18 },
- /* 5869 */ { MAD_F(0x067623c0) /* 0.403842688 */, 18 },
- /* 5870 */ { MAD_F(0x067683f4) /* 0.403934437 */, 18 },
- /* 5871 */ { MAD_F(0x0676e42a) /* 0.404026190 */, 18 },
-
- /* 5872 */ { MAD_F(0x06774462) /* 0.404117949 */, 18 },
- /* 5873 */ { MAD_F(0x0677a49b) /* 0.404209714 */, 18 },
- /* 5874 */ { MAD_F(0x067804d5) /* 0.404301483 */, 18 },
- /* 5875 */ { MAD_F(0x06786510) /* 0.404393258 */, 18 },
- /* 5876 */ { MAD_F(0x0678c54d) /* 0.404485037 */, 18 },
- /* 5877 */ { MAD_F(0x0679258c) /* 0.404576822 */, 18 },
- /* 5878 */ { MAD_F(0x067985cb) /* 0.404668613 */, 18 },
- /* 5879 */ { MAD_F(0x0679e60c) /* 0.404760408 */, 18 },
- /* 5880 */ { MAD_F(0x067a464f) /* 0.404852209 */, 18 },
- /* 5881 */ { MAD_F(0x067aa693) /* 0.404944014 */, 18 },
- /* 5882 */ { MAD_F(0x067b06d8) /* 0.405035825 */, 18 },
- /* 5883 */ { MAD_F(0x067b671f) /* 0.405127642 */, 18 },
- /* 5884 */ { MAD_F(0x067bc767) /* 0.405219463 */, 18 },
- /* 5885 */ { MAD_F(0x067c27b1) /* 0.405311290 */, 18 },
- /* 5886 */ { MAD_F(0x067c87fc) /* 0.405403122 */, 18 },
- /* 5887 */ { MAD_F(0x067ce848) /* 0.405494959 */, 18 },
-
- /* 5888 */ { MAD_F(0x067d4896) /* 0.405586801 */, 18 },
- /* 5889 */ { MAD_F(0x067da8e5) /* 0.405678648 */, 18 },
- /* 5890 */ { MAD_F(0x067e0935) /* 0.405770501 */, 18 },
- /* 5891 */ { MAD_F(0x067e6987) /* 0.405862359 */, 18 },
- /* 5892 */ { MAD_F(0x067ec9da) /* 0.405954222 */, 18 },
- /* 5893 */ { MAD_F(0x067f2a2f) /* 0.406046090 */, 18 },
- /* 5894 */ { MAD_F(0x067f8a85) /* 0.406137963 */, 18 },
- /* 5895 */ { MAD_F(0x067feadd) /* 0.406229842 */, 18 },
- /* 5896 */ { MAD_F(0x06804b36) /* 0.406321726 */, 18 },
- /* 5897 */ { MAD_F(0x0680ab90) /* 0.406413615 */, 18 },
- /* 5898 */ { MAD_F(0x06810beb) /* 0.406505509 */, 18 },
- /* 5899 */ { MAD_F(0x06816c49) /* 0.406597408 */, 18 },
- /* 5900 */ { MAD_F(0x0681cca7) /* 0.406689313 */, 18 },
- /* 5901 */ { MAD_F(0x06822d07) /* 0.406781223 */, 18 },
- /* 5902 */ { MAD_F(0x06828d68) /* 0.406873138 */, 18 },
- /* 5903 */ { MAD_F(0x0682edcb) /* 0.406965058 */, 18 },
-
- /* 5904 */ { MAD_F(0x06834e2f) /* 0.407056983 */, 18 },
- /* 5905 */ { MAD_F(0x0683ae94) /* 0.407148914 */, 18 },
- /* 5906 */ { MAD_F(0x06840efb) /* 0.407240850 */, 18 },
- /* 5907 */ { MAD_F(0x06846f63) /* 0.407332791 */, 18 },
- /* 5908 */ { MAD_F(0x0684cfcd) /* 0.407424737 */, 18 },
- /* 5909 */ { MAD_F(0x06853038) /* 0.407516688 */, 18 },
- /* 5910 */ { MAD_F(0x068590a4) /* 0.407608645 */, 18 },
- /* 5911 */ { MAD_F(0x0685f112) /* 0.407700606 */, 18 },
- /* 5912 */ { MAD_F(0x06865181) /* 0.407792573 */, 18 },
- /* 5913 */ { MAD_F(0x0686b1f2) /* 0.407884545 */, 18 },
- /* 5914 */ { MAD_F(0x06871264) /* 0.407976522 */, 18 },
- /* 5915 */ { MAD_F(0x068772d7) /* 0.408068505 */, 18 },
- /* 5916 */ { MAD_F(0x0687d34c) /* 0.408160492 */, 18 },
- /* 5917 */ { MAD_F(0x068833c2) /* 0.408252485 */, 18 },
- /* 5918 */ { MAD_F(0x06889439) /* 0.408344483 */, 18 },
- /* 5919 */ { MAD_F(0x0688f4b2) /* 0.408436486 */, 18 },
-
- /* 5920 */ { MAD_F(0x0689552c) /* 0.408528495 */, 18 },
- /* 5921 */ { MAD_F(0x0689b5a8) /* 0.408620508 */, 18 },
- /* 5922 */ { MAD_F(0x068a1625) /* 0.408712527 */, 18 },
- /* 5923 */ { MAD_F(0x068a76a4) /* 0.408804551 */, 18 },
- /* 5924 */ { MAD_F(0x068ad724) /* 0.408896580 */, 18 },
- /* 5925 */ { MAD_F(0x068b37a5) /* 0.408988614 */, 18 },
- /* 5926 */ { MAD_F(0x068b9827) /* 0.409080653 */, 18 },
- /* 5927 */ { MAD_F(0x068bf8ac) /* 0.409172698 */, 18 },
- /* 5928 */ { MAD_F(0x068c5931) /* 0.409264748 */, 18 },
- /* 5929 */ { MAD_F(0x068cb9b8) /* 0.409356803 */, 18 },
- /* 5930 */ { MAD_F(0x068d1a40) /* 0.409448863 */, 18 },
- /* 5931 */ { MAD_F(0x068d7aca) /* 0.409540928 */, 18 },
- /* 5932 */ { MAD_F(0x068ddb54) /* 0.409632999 */, 18 },
- /* 5933 */ { MAD_F(0x068e3be1) /* 0.409725074 */, 18 },
- /* 5934 */ { MAD_F(0x068e9c6f) /* 0.409817155 */, 18 },
- /* 5935 */ { MAD_F(0x068efcfe) /* 0.409909241 */, 18 },
-
- /* 5936 */ { MAD_F(0x068f5d8e) /* 0.410001332 */, 18 },
- /* 5937 */ { MAD_F(0x068fbe20) /* 0.410093428 */, 18 },
- /* 5938 */ { MAD_F(0x06901eb4) /* 0.410185530 */, 18 },
- /* 5939 */ { MAD_F(0x06907f48) /* 0.410277637 */, 18 },
- /* 5940 */ { MAD_F(0x0690dfde) /* 0.410369748 */, 18 },
- /* 5941 */ { MAD_F(0x06914076) /* 0.410461865 */, 18 },
- /* 5942 */ { MAD_F(0x0691a10f) /* 0.410553988 */, 18 },
- /* 5943 */ { MAD_F(0x069201a9) /* 0.410646115 */, 18 },
- /* 5944 */ { MAD_F(0x06926245) /* 0.410738247 */, 18 },
- /* 5945 */ { MAD_F(0x0692c2e2) /* 0.410830385 */, 18 },
- /* 5946 */ { MAD_F(0x06932380) /* 0.410922528 */, 18 },
- /* 5947 */ { MAD_F(0x06938420) /* 0.411014676 */, 18 },
- /* 5948 */ { MAD_F(0x0693e4c1) /* 0.411106829 */, 18 },
- /* 5949 */ { MAD_F(0x06944563) /* 0.411198987 */, 18 },
- /* 5950 */ { MAD_F(0x0694a607) /* 0.411291151 */, 18 },
- /* 5951 */ { MAD_F(0x069506ad) /* 0.411383320 */, 18 },
-
- /* 5952 */ { MAD_F(0x06956753) /* 0.411475493 */, 18 },
- /* 5953 */ { MAD_F(0x0695c7fc) /* 0.411567672 */, 18 },
- /* 5954 */ { MAD_F(0x069628a5) /* 0.411659857 */, 18 },
- /* 5955 */ { MAD_F(0x06968950) /* 0.411752046 */, 18 },
- /* 5956 */ { MAD_F(0x0696e9fc) /* 0.411844240 */, 18 },
- /* 5957 */ { MAD_F(0x06974aaa) /* 0.411936440 */, 18 },
- /* 5958 */ { MAD_F(0x0697ab59) /* 0.412028645 */, 18 },
- /* 5959 */ { MAD_F(0x06980c09) /* 0.412120855 */, 18 },
- /* 5960 */ { MAD_F(0x06986cbb) /* 0.412213070 */, 18 },
- /* 5961 */ { MAD_F(0x0698cd6e) /* 0.412305290 */, 18 },
- /* 5962 */ { MAD_F(0x06992e23) /* 0.412397516 */, 18 },
- /* 5963 */ { MAD_F(0x06998ed9) /* 0.412489746 */, 18 },
- /* 5964 */ { MAD_F(0x0699ef90) /* 0.412581982 */, 18 },
- /* 5965 */ { MAD_F(0x069a5049) /* 0.412674223 */, 18 },
- /* 5966 */ { MAD_F(0x069ab103) /* 0.412766469 */, 18 },
- /* 5967 */ { MAD_F(0x069b11bf) /* 0.412858720 */, 18 },
-
- /* 5968 */ { MAD_F(0x069b727b) /* 0.412950976 */, 18 },
- /* 5969 */ { MAD_F(0x069bd33a) /* 0.413043238 */, 18 },
- /* 5970 */ { MAD_F(0x069c33f9) /* 0.413135505 */, 18 },
- /* 5971 */ { MAD_F(0x069c94ba) /* 0.413227776 */, 18 },
- /* 5972 */ { MAD_F(0x069cf57d) /* 0.413320053 */, 18 },
- /* 5973 */ { MAD_F(0x069d5641) /* 0.413412335 */, 18 },
- /* 5974 */ { MAD_F(0x069db706) /* 0.413504623 */, 18 },
- /* 5975 */ { MAD_F(0x069e17cc) /* 0.413596915 */, 18 },
- /* 5976 */ { MAD_F(0x069e7894) /* 0.413689213 */, 18 },
- /* 5977 */ { MAD_F(0x069ed95e) /* 0.413781515 */, 18 },
- /* 5978 */ { MAD_F(0x069f3a28) /* 0.413873823 */, 18 },
- /* 5979 */ { MAD_F(0x069f9af4) /* 0.413966136 */, 18 },
- /* 5980 */ { MAD_F(0x069ffbc2) /* 0.414058454 */, 18 },
- /* 5981 */ { MAD_F(0x06a05c91) /* 0.414150778 */, 18 },
- /* 5982 */ { MAD_F(0x06a0bd61) /* 0.414243106 */, 18 },
- /* 5983 */ { MAD_F(0x06a11e32) /* 0.414335440 */, 18 },
-
- /* 5984 */ { MAD_F(0x06a17f05) /* 0.414427779 */, 18 },
- /* 5985 */ { MAD_F(0x06a1dfda) /* 0.414520122 */, 18 },
- /* 5986 */ { MAD_F(0x06a240b0) /* 0.414612471 */, 18 },
- /* 5987 */ { MAD_F(0x06a2a187) /* 0.414704826 */, 18 },
- /* 5988 */ { MAD_F(0x06a3025f) /* 0.414797185 */, 18 },
- /* 5989 */ { MAD_F(0x06a36339) /* 0.414889549 */, 18 },
- /* 5990 */ { MAD_F(0x06a3c414) /* 0.414981919 */, 18 },
- /* 5991 */ { MAD_F(0x06a424f1) /* 0.415074294 */, 18 },
- /* 5992 */ { MAD_F(0x06a485cf) /* 0.415166674 */, 18 },
- /* 5993 */ { MAD_F(0x06a4e6ae) /* 0.415259059 */, 18 },
- /* 5994 */ { MAD_F(0x06a5478f) /* 0.415351449 */, 18 },
- /* 5995 */ { MAD_F(0x06a5a871) /* 0.415443844 */, 18 },
- /* 5996 */ { MAD_F(0x06a60955) /* 0.415536244 */, 18 },
- /* 5997 */ { MAD_F(0x06a66a3a) /* 0.415628650 */, 18 },
- /* 5998 */ { MAD_F(0x06a6cb20) /* 0.415721061 */, 18 },
- /* 5999 */ { MAD_F(0x06a72c08) /* 0.415813476 */, 18 },
-
- /* 6000 */ { MAD_F(0x06a78cf1) /* 0.415905897 */, 18 },
- /* 6001 */ { MAD_F(0x06a7eddb) /* 0.415998324 */, 18 },
- /* 6002 */ { MAD_F(0x06a84ec7) /* 0.416090755 */, 18 },
- /* 6003 */ { MAD_F(0x06a8afb4) /* 0.416183191 */, 18 },
- /* 6004 */ { MAD_F(0x06a910a3) /* 0.416275633 */, 18 },
- /* 6005 */ { MAD_F(0x06a97193) /* 0.416368079 */, 18 },
- /* 6006 */ { MAD_F(0x06a9d284) /* 0.416460531 */, 18 },
- /* 6007 */ { MAD_F(0x06aa3377) /* 0.416552988 */, 18 },
- /* 6008 */ { MAD_F(0x06aa946b) /* 0.416645450 */, 18 },
- /* 6009 */ { MAD_F(0x06aaf561) /* 0.416737917 */, 18 },
- /* 6010 */ { MAD_F(0x06ab5657) /* 0.416830389 */, 18 },
- /* 6011 */ { MAD_F(0x06abb750) /* 0.416922867 */, 18 },
- /* 6012 */ { MAD_F(0x06ac1849) /* 0.417015349 */, 18 },
- /* 6013 */ { MAD_F(0x06ac7944) /* 0.417107837 */, 18 },
- /* 6014 */ { MAD_F(0x06acda41) /* 0.417200330 */, 18 },
- /* 6015 */ { MAD_F(0x06ad3b3e) /* 0.417292828 */, 18 },
-
- /* 6016 */ { MAD_F(0x06ad9c3d) /* 0.417385331 */, 18 },
- /* 6017 */ { MAD_F(0x06adfd3e) /* 0.417477839 */, 18 },
- /* 6018 */ { MAD_F(0x06ae5e40) /* 0.417570352 */, 18 },
- /* 6019 */ { MAD_F(0x06aebf43) /* 0.417662871 */, 18 },
- /* 6020 */ { MAD_F(0x06af2047) /* 0.417755394 */, 18 },
- /* 6021 */ { MAD_F(0x06af814d) /* 0.417847923 */, 18 },
- /* 6022 */ { MAD_F(0x06afe255) /* 0.417940457 */, 18 },
- /* 6023 */ { MAD_F(0x06b0435e) /* 0.418032996 */, 18 },
- /* 6024 */ { MAD_F(0x06b0a468) /* 0.418125540 */, 18 },
- /* 6025 */ { MAD_F(0x06b10573) /* 0.418218089 */, 18 },
- /* 6026 */ { MAD_F(0x06b16680) /* 0.418310643 */, 18 },
- /* 6027 */ { MAD_F(0x06b1c78e) /* 0.418403203 */, 18 },
- /* 6028 */ { MAD_F(0x06b2289e) /* 0.418495767 */, 18 },
- /* 6029 */ { MAD_F(0x06b289af) /* 0.418588337 */, 18 },
- /* 6030 */ { MAD_F(0x06b2eac1) /* 0.418680911 */, 18 },
- /* 6031 */ { MAD_F(0x06b34bd5) /* 0.418773491 */, 18 },
-
- /* 6032 */ { MAD_F(0x06b3acea) /* 0.418866076 */, 18 },
- /* 6033 */ { MAD_F(0x06b40e00) /* 0.418958666 */, 18 },
- /* 6034 */ { MAD_F(0x06b46f18) /* 0.419051262 */, 18 },
- /* 6035 */ { MAD_F(0x06b4d031) /* 0.419143862 */, 18 },
- /* 6036 */ { MAD_F(0x06b5314c) /* 0.419236467 */, 18 },
- /* 6037 */ { MAD_F(0x06b59268) /* 0.419329078 */, 18 },
- /* 6038 */ { MAD_F(0x06b5f385) /* 0.419421694 */, 18 },
- /* 6039 */ { MAD_F(0x06b654a4) /* 0.419514314 */, 18 },
- /* 6040 */ { MAD_F(0x06b6b5c4) /* 0.419606940 */, 18 },
- /* 6041 */ { MAD_F(0x06b716e6) /* 0.419699571 */, 18 },
- /* 6042 */ { MAD_F(0x06b77808) /* 0.419792208 */, 18 },
- /* 6043 */ { MAD_F(0x06b7d92d) /* 0.419884849 */, 18 },
- /* 6044 */ { MAD_F(0x06b83a52) /* 0.419977495 */, 18 },
- /* 6045 */ { MAD_F(0x06b89b79) /* 0.420070147 */, 18 },
- /* 6046 */ { MAD_F(0x06b8fca1) /* 0.420162803 */, 18 },
- /* 6047 */ { MAD_F(0x06b95dcb) /* 0.420255465 */, 18 },
-
- /* 6048 */ { MAD_F(0x06b9bef6) /* 0.420348132 */, 18 },
- /* 6049 */ { MAD_F(0x06ba2023) /* 0.420440803 */, 18 },
- /* 6050 */ { MAD_F(0x06ba8150) /* 0.420533481 */, 18 },
- /* 6051 */ { MAD_F(0x06bae280) /* 0.420626163 */, 18 },
- /* 6052 */ { MAD_F(0x06bb43b0) /* 0.420718850 */, 18 },
- /* 6053 */ { MAD_F(0x06bba4e2) /* 0.420811542 */, 18 },
- /* 6054 */ { MAD_F(0x06bc0615) /* 0.420904240 */, 18 },
- /* 6055 */ { MAD_F(0x06bc674a) /* 0.420996942 */, 18 },
- /* 6056 */ { MAD_F(0x06bcc880) /* 0.421089650 */, 18 },
- /* 6057 */ { MAD_F(0x06bd29b7) /* 0.421182362 */, 18 },
- /* 6058 */ { MAD_F(0x06bd8af0) /* 0.421275080 */, 18 },
- /* 6059 */ { MAD_F(0x06bdec2a) /* 0.421367803 */, 18 },
- /* 6060 */ { MAD_F(0x06be4d66) /* 0.421460531 */, 18 },
- /* 6061 */ { MAD_F(0x06beaea3) /* 0.421553264 */, 18 },
- /* 6062 */ { MAD_F(0x06bf0fe1) /* 0.421646003 */, 18 },
- /* 6063 */ { MAD_F(0x06bf7120) /* 0.421738746 */, 18 },
-
- /* 6064 */ { MAD_F(0x06bfd261) /* 0.421831494 */, 18 },
- /* 6065 */ { MAD_F(0x06c033a4) /* 0.421924248 */, 18 },
- /* 6066 */ { MAD_F(0x06c094e7) /* 0.422017007 */, 18 },
- /* 6067 */ { MAD_F(0x06c0f62c) /* 0.422109770 */, 18 },
- /* 6068 */ { MAD_F(0x06c15773) /* 0.422202539 */, 18 },
- /* 6069 */ { MAD_F(0x06c1b8bb) /* 0.422295313 */, 18 },
- /* 6070 */ { MAD_F(0x06c21a04) /* 0.422388092 */, 18 },
- /* 6071 */ { MAD_F(0x06c27b4e) /* 0.422480876 */, 18 },
- /* 6072 */ { MAD_F(0x06c2dc9a) /* 0.422573665 */, 18 },
- /* 6073 */ { MAD_F(0x06c33de8) /* 0.422666460 */, 18 },
- /* 6074 */ { MAD_F(0x06c39f36) /* 0.422759259 */, 18 },
- /* 6075 */ { MAD_F(0x06c40086) /* 0.422852064 */, 18 },
- /* 6076 */ { MAD_F(0x06c461d8) /* 0.422944873 */, 18 },
- /* 6077 */ { MAD_F(0x06c4c32a) /* 0.423037688 */, 18 },
- /* 6078 */ { MAD_F(0x06c5247f) /* 0.423130508 */, 18 },
- /* 6079 */ { MAD_F(0x06c585d4) /* 0.423223333 */, 18 },
-
- /* 6080 */ { MAD_F(0x06c5e72b) /* 0.423316162 */, 18 },
- /* 6081 */ { MAD_F(0x06c64883) /* 0.423408997 */, 18 },
- /* 6082 */ { MAD_F(0x06c6a9dd) /* 0.423501838 */, 18 },
- /* 6083 */ { MAD_F(0x06c70b38) /* 0.423594683 */, 18 },
- /* 6084 */ { MAD_F(0x06c76c94) /* 0.423687533 */, 18 },
- /* 6085 */ { MAD_F(0x06c7cdf2) /* 0.423780389 */, 18 },
- /* 6086 */ { MAD_F(0x06c82f51) /* 0.423873249 */, 18 },
- /* 6087 */ { MAD_F(0x06c890b1) /* 0.423966115 */, 18 },
- /* 6088 */ { MAD_F(0x06c8f213) /* 0.424058985 */, 18 },
- /* 6089 */ { MAD_F(0x06c95376) /* 0.424151861 */, 18 },
- /* 6090 */ { MAD_F(0x06c9b4da) /* 0.424244742 */, 18 },
- /* 6091 */ { MAD_F(0x06ca1640) /* 0.424337628 */, 18 },
- /* 6092 */ { MAD_F(0x06ca77a8) /* 0.424430519 */, 18 },
- /* 6093 */ { MAD_F(0x06cad910) /* 0.424523415 */, 18 },
- /* 6094 */ { MAD_F(0x06cb3a7a) /* 0.424616316 */, 18 },
- /* 6095 */ { MAD_F(0x06cb9be5) /* 0.424709222 */, 18 },
-
- /* 6096 */ { MAD_F(0x06cbfd52) /* 0.424802133 */, 18 },
- /* 6097 */ { MAD_F(0x06cc5ec0) /* 0.424895050 */, 18 },
- /* 6098 */ { MAD_F(0x06ccc030) /* 0.424987971 */, 18 },
- /* 6099 */ { MAD_F(0x06cd21a0) /* 0.425080898 */, 18 },
- /* 6100 */ { MAD_F(0x06cd8313) /* 0.425173829 */, 18 },
- /* 6101 */ { MAD_F(0x06cde486) /* 0.425266766 */, 18 },
- /* 6102 */ { MAD_F(0x06ce45fb) /* 0.425359708 */, 18 },
- /* 6103 */ { MAD_F(0x06cea771) /* 0.425452655 */, 18 },
- /* 6104 */ { MAD_F(0x06cf08e9) /* 0.425545607 */, 18 },
- /* 6105 */ { MAD_F(0x06cf6a62) /* 0.425638564 */, 18 },
- /* 6106 */ { MAD_F(0x06cfcbdc) /* 0.425731526 */, 18 },
- /* 6107 */ { MAD_F(0x06d02d58) /* 0.425824493 */, 18 },
- /* 6108 */ { MAD_F(0x06d08ed5) /* 0.425917465 */, 18 },
- /* 6109 */ { MAD_F(0x06d0f053) /* 0.426010443 */, 18 },
- /* 6110 */ { MAD_F(0x06d151d3) /* 0.426103425 */, 18 },
- /* 6111 */ { MAD_F(0x06d1b354) /* 0.426196412 */, 18 },
-
- /* 6112 */ { MAD_F(0x06d214d7) /* 0.426289405 */, 18 },
- /* 6113 */ { MAD_F(0x06d2765a) /* 0.426382403 */, 18 },
- /* 6114 */ { MAD_F(0x06d2d7e0) /* 0.426475405 */, 18 },
- /* 6115 */ { MAD_F(0x06d33966) /* 0.426568413 */, 18 },
- /* 6116 */ { MAD_F(0x06d39aee) /* 0.426661426 */, 18 },
- /* 6117 */ { MAD_F(0x06d3fc77) /* 0.426754444 */, 18 },
- /* 6118 */ { MAD_F(0x06d45e02) /* 0.426847467 */, 18 },
- /* 6119 */ { MAD_F(0x06d4bf8e) /* 0.426940495 */, 18 },
- /* 6120 */ { MAD_F(0x06d5211c) /* 0.427033528 */, 18 },
- /* 6121 */ { MAD_F(0x06d582aa) /* 0.427126566 */, 18 },
- /* 6122 */ { MAD_F(0x06d5e43a) /* 0.427219609 */, 18 },
- /* 6123 */ { MAD_F(0x06d645cc) /* 0.427312657 */, 18 },
- /* 6124 */ { MAD_F(0x06d6a75f) /* 0.427405711 */, 18 },
- /* 6125 */ { MAD_F(0x06d708f3) /* 0.427498769 */, 18 },
- /* 6126 */ { MAD_F(0x06d76a88) /* 0.427591833 */, 18 },
- /* 6127 */ { MAD_F(0x06d7cc1f) /* 0.427684901 */, 18 },
-
- /* 6128 */ { MAD_F(0x06d82db8) /* 0.427777975 */, 18 },
- /* 6129 */ { MAD_F(0x06d88f51) /* 0.427871054 */, 18 },
- /* 6130 */ { MAD_F(0x06d8f0ec) /* 0.427964137 */, 18 },
- /* 6131 */ { MAD_F(0x06d95288) /* 0.428057226 */, 18 },
- /* 6132 */ { MAD_F(0x06d9b426) /* 0.428150320 */, 18 },
- /* 6133 */ { MAD_F(0x06da15c5) /* 0.428243419 */, 18 },
- /* 6134 */ { MAD_F(0x06da7766) /* 0.428336523 */, 18 },
- /* 6135 */ { MAD_F(0x06dad907) /* 0.428429632 */, 18 },
- /* 6136 */ { MAD_F(0x06db3aaa) /* 0.428522746 */, 18 },
- /* 6137 */ { MAD_F(0x06db9c4f) /* 0.428615865 */, 18 },
- /* 6138 */ { MAD_F(0x06dbfdf5) /* 0.428708989 */, 18 },
- /* 6139 */ { MAD_F(0x06dc5f9c) /* 0.428802119 */, 18 },
- /* 6140 */ { MAD_F(0x06dcc145) /* 0.428895253 */, 18 },
- /* 6141 */ { MAD_F(0x06dd22ee) /* 0.428988392 */, 18 },
- /* 6142 */ { MAD_F(0x06dd849a) /* 0.429081537 */, 18 },
- /* 6143 */ { MAD_F(0x06dde646) /* 0.429174686 */, 18 },
-
- /* 6144 */ { MAD_F(0x06de47f4) /* 0.429267841 */, 18 },
- /* 6145 */ { MAD_F(0x06dea9a4) /* 0.429361001 */, 18 },
- /* 6146 */ { MAD_F(0x06df0b54) /* 0.429454165 */, 18 },
- /* 6147 */ { MAD_F(0x06df6d06) /* 0.429547335 */, 18 },
- /* 6148 */ { MAD_F(0x06dfceba) /* 0.429640510 */, 18 },
- /* 6149 */ { MAD_F(0x06e0306f) /* 0.429733690 */, 18 },
- /* 6150 */ { MAD_F(0x06e09225) /* 0.429826874 */, 18 },
- /* 6151 */ { MAD_F(0x06e0f3dc) /* 0.429920064 */, 18 },
- /* 6152 */ { MAD_F(0x06e15595) /* 0.430013259 */, 18 },
- /* 6153 */ { MAD_F(0x06e1b74f) /* 0.430106459 */, 18 },
- /* 6154 */ { MAD_F(0x06e2190b) /* 0.430199664 */, 18 },
- /* 6155 */ { MAD_F(0x06e27ac8) /* 0.430292875 */, 18 },
- /* 6156 */ { MAD_F(0x06e2dc86) /* 0.430386090 */, 18 },
- /* 6157 */ { MAD_F(0x06e33e46) /* 0.430479310 */, 18 },
- /* 6158 */ { MAD_F(0x06e3a007) /* 0.430572535 */, 18 },
- /* 6159 */ { MAD_F(0x06e401c9) /* 0.430665765 */, 18 },
-
- /* 6160 */ { MAD_F(0x06e4638d) /* 0.430759001 */, 18 },
- /* 6161 */ { MAD_F(0x06e4c552) /* 0.430852241 */, 18 },
- /* 6162 */ { MAD_F(0x06e52718) /* 0.430945487 */, 18 },
- /* 6163 */ { MAD_F(0x06e588e0) /* 0.431038737 */, 18 },
- /* 6164 */ { MAD_F(0x06e5eaa9) /* 0.431131993 */, 18 },
- /* 6165 */ { MAD_F(0x06e64c73) /* 0.431225253 */, 18 },
- /* 6166 */ { MAD_F(0x06e6ae3f) /* 0.431318519 */, 18 },
- /* 6167 */ { MAD_F(0x06e7100c) /* 0.431411790 */, 18 },
- /* 6168 */ { MAD_F(0x06e771db) /* 0.431505065 */, 18 },
- /* 6169 */ { MAD_F(0x06e7d3ab) /* 0.431598346 */, 18 },
- /* 6170 */ { MAD_F(0x06e8357c) /* 0.431691632 */, 18 },
- /* 6171 */ { MAD_F(0x06e8974e) /* 0.431784923 */, 18 },
- /* 6172 */ { MAD_F(0x06e8f922) /* 0.431878218 */, 18 },
- /* 6173 */ { MAD_F(0x06e95af8) /* 0.431971519 */, 18 },
- /* 6174 */ { MAD_F(0x06e9bcce) /* 0.432064825 */, 18 },
- /* 6175 */ { MAD_F(0x06ea1ea6) /* 0.432158136 */, 18 },
-
- /* 6176 */ { MAD_F(0x06ea807f) /* 0.432251452 */, 18 },
- /* 6177 */ { MAD_F(0x06eae25a) /* 0.432344773 */, 18 },
- /* 6178 */ { MAD_F(0x06eb4436) /* 0.432438099 */, 18 },
- /* 6179 */ { MAD_F(0x06eba614) /* 0.432531431 */, 18 },
- /* 6180 */ { MAD_F(0x06ec07f2) /* 0.432624767 */, 18 },
- /* 6181 */ { MAD_F(0x06ec69d2) /* 0.432718108 */, 18 },
- /* 6182 */ { MAD_F(0x06eccbb4) /* 0.432811454 */, 18 },
- /* 6183 */ { MAD_F(0x06ed2d97) /* 0.432904805 */, 18 },
- /* 6184 */ { MAD_F(0x06ed8f7b) /* 0.432998162 */, 18 },
- /* 6185 */ { MAD_F(0x06edf160) /* 0.433091523 */, 18 },
- /* 6186 */ { MAD_F(0x06ee5347) /* 0.433184889 */, 18 },
- /* 6187 */ { MAD_F(0x06eeb52f) /* 0.433278261 */, 18 },
- /* 6188 */ { MAD_F(0x06ef1719) /* 0.433371637 */, 18 },
- /* 6189 */ { MAD_F(0x06ef7904) /* 0.433465019 */, 18 },
- /* 6190 */ { MAD_F(0x06efdaf0) /* 0.433558405 */, 18 },
- /* 6191 */ { MAD_F(0x06f03cde) /* 0.433651797 */, 18 },
-
- /* 6192 */ { MAD_F(0x06f09ecc) /* 0.433745193 */, 18 },
- /* 6193 */ { MAD_F(0x06f100bd) /* 0.433838595 */, 18 },
- /* 6194 */ { MAD_F(0x06f162ae) /* 0.433932001 */, 18 },
- /* 6195 */ { MAD_F(0x06f1c4a1) /* 0.434025413 */, 18 },
- /* 6196 */ { MAD_F(0x06f22696) /* 0.434118830 */, 18 },
- /* 6197 */ { MAD_F(0x06f2888b) /* 0.434212251 */, 18 },
- /* 6198 */ { MAD_F(0x06f2ea82) /* 0.434305678 */, 18 },
- /* 6199 */ { MAD_F(0x06f34c7b) /* 0.434399110 */, 18 },
- /* 6200 */ { MAD_F(0x06f3ae75) /* 0.434492546 */, 18 },
- /* 6201 */ { MAD_F(0x06f41070) /* 0.434585988 */, 18 },
- /* 6202 */ { MAD_F(0x06f4726c) /* 0.434679435 */, 18 },
- /* 6203 */ { MAD_F(0x06f4d46a) /* 0.434772887 */, 18 },
- /* 6204 */ { MAD_F(0x06f53669) /* 0.434866344 */, 18 },
- /* 6205 */ { MAD_F(0x06f59869) /* 0.434959806 */, 18 },
- /* 6206 */ { MAD_F(0x06f5fa6b) /* 0.435053272 */, 18 },
- /* 6207 */ { MAD_F(0x06f65c6e) /* 0.435146744 */, 18 },
-
- /* 6208 */ { MAD_F(0x06f6be73) /* 0.435240221 */, 18 },
- /* 6209 */ { MAD_F(0x06f72079) /* 0.435333703 */, 18 },
- /* 6210 */ { MAD_F(0x06f78280) /* 0.435427190 */, 18 },
- /* 6211 */ { MAD_F(0x06f7e489) /* 0.435520682 */, 18 },
- /* 6212 */ { MAD_F(0x06f84693) /* 0.435614179 */, 18 },
- /* 6213 */ { MAD_F(0x06f8a89e) /* 0.435707681 */, 18 },
- /* 6214 */ { MAD_F(0x06f90aaa) /* 0.435801188 */, 18 },
- /* 6215 */ { MAD_F(0x06f96cb8) /* 0.435894700 */, 18 },
- /* 6216 */ { MAD_F(0x06f9cec8) /* 0.435988217 */, 18 },
- /* 6217 */ { MAD_F(0x06fa30d8) /* 0.436081739 */, 18 },
- /* 6218 */ { MAD_F(0x06fa92ea) /* 0.436175266 */, 18 },
- /* 6219 */ { MAD_F(0x06faf4fe) /* 0.436268799 */, 18 },
- /* 6220 */ { MAD_F(0x06fb5712) /* 0.436362336 */, 18 },
- /* 6221 */ { MAD_F(0x06fbb928) /* 0.436455878 */, 18 },
- /* 6222 */ { MAD_F(0x06fc1b40) /* 0.436549425 */, 18 },
- /* 6223 */ { MAD_F(0x06fc7d58) /* 0.436642977 */, 18 },
-
- /* 6224 */ { MAD_F(0x06fcdf72) /* 0.436736534 */, 18 },
- /* 6225 */ { MAD_F(0x06fd418e) /* 0.436830096 */, 18 },
- /* 6226 */ { MAD_F(0x06fda3ab) /* 0.436923664 */, 18 },
- /* 6227 */ { MAD_F(0x06fe05c9) /* 0.437017236 */, 18 },
- /* 6228 */ { MAD_F(0x06fe67e8) /* 0.437110813 */, 18 },
- /* 6229 */ { MAD_F(0x06feca09) /* 0.437204395 */, 18 },
- /* 6230 */ { MAD_F(0x06ff2c2b) /* 0.437297982 */, 18 },
- /* 6231 */ { MAD_F(0x06ff8e4f) /* 0.437391575 */, 18 },
- /* 6232 */ { MAD_F(0x06fff073) /* 0.437485172 */, 18 },
- /* 6233 */ { MAD_F(0x0700529a) /* 0.437578774 */, 18 },
- /* 6234 */ { MAD_F(0x0700b4c1) /* 0.437672381 */, 18 },
- /* 6235 */ { MAD_F(0x070116ea) /* 0.437765994 */, 18 },
- /* 6236 */ { MAD_F(0x07017914) /* 0.437859611 */, 18 },
- /* 6237 */ { MAD_F(0x0701db40) /* 0.437953233 */, 18 },
- /* 6238 */ { MAD_F(0x07023d6c) /* 0.438046860 */, 18 },
- /* 6239 */ { MAD_F(0x07029f9b) /* 0.438140493 */, 18 },
-
- /* 6240 */ { MAD_F(0x070301ca) /* 0.438234130 */, 18 },
- /* 6241 */ { MAD_F(0x070363fb) /* 0.438327772 */, 18 },
- /* 6242 */ { MAD_F(0x0703c62d) /* 0.438421419 */, 18 },
- /* 6243 */ { MAD_F(0x07042861) /* 0.438515072 */, 18 },
- /* 6244 */ { MAD_F(0x07048a96) /* 0.438608729 */, 18 },
- /* 6245 */ { MAD_F(0x0704eccc) /* 0.438702391 */, 18 },
- /* 6246 */ { MAD_F(0x07054f04) /* 0.438796059 */, 18 },
- /* 6247 */ { MAD_F(0x0705b13d) /* 0.438889731 */, 18 },
- /* 6248 */ { MAD_F(0x07061377) /* 0.438983408 */, 18 },
- /* 6249 */ { MAD_F(0x070675b3) /* 0.439077090 */, 18 },
- /* 6250 */ { MAD_F(0x0706d7f0) /* 0.439170778 */, 18 },
- /* 6251 */ { MAD_F(0x07073a2e) /* 0.439264470 */, 18 },
- /* 6252 */ { MAD_F(0x07079c6e) /* 0.439358167 */, 18 },
- /* 6253 */ { MAD_F(0x0707feaf) /* 0.439451869 */, 18 },
- /* 6254 */ { MAD_F(0x070860f1) /* 0.439545577 */, 18 },
- /* 6255 */ { MAD_F(0x0708c335) /* 0.439639289 */, 18 },
-
- /* 6256 */ { MAD_F(0x0709257a) /* 0.439733006 */, 18 },
- /* 6257 */ { MAD_F(0x070987c0) /* 0.439826728 */, 18 },
- /* 6258 */ { MAD_F(0x0709ea08) /* 0.439920456 */, 18 },
- /* 6259 */ { MAD_F(0x070a4c51) /* 0.440014188 */, 18 },
- /* 6260 */ { MAD_F(0x070aae9b) /* 0.440107925 */, 18 },
- /* 6261 */ { MAD_F(0x070b10e7) /* 0.440201667 */, 18 },
- /* 6262 */ { MAD_F(0x070b7334) /* 0.440295414 */, 18 },
- /* 6263 */ { MAD_F(0x070bd583) /* 0.440389167 */, 18 },
- /* 6264 */ { MAD_F(0x070c37d2) /* 0.440482924 */, 18 },
- /* 6265 */ { MAD_F(0x070c9a23) /* 0.440576686 */, 18 },
- /* 6266 */ { MAD_F(0x070cfc76) /* 0.440670453 */, 18 },
- /* 6267 */ { MAD_F(0x070d5eca) /* 0.440764225 */, 18 },
- /* 6268 */ { MAD_F(0x070dc11f) /* 0.440858002 */, 18 },
- /* 6269 */ { MAD_F(0x070e2375) /* 0.440951784 */, 18 },
- /* 6270 */ { MAD_F(0x070e85cd) /* 0.441045572 */, 18 },
- /* 6271 */ { MAD_F(0x070ee826) /* 0.441139364 */, 18 },
-
- /* 6272 */ { MAD_F(0x070f4a80) /* 0.441233161 */, 18 },
- /* 6273 */ { MAD_F(0x070facdc) /* 0.441326963 */, 18 },
- /* 6274 */ { MAD_F(0x07100f39) /* 0.441420770 */, 18 },
- /* 6275 */ { MAD_F(0x07107198) /* 0.441514582 */, 18 },
- /* 6276 */ { MAD_F(0x0710d3f8) /* 0.441608399 */, 18 },
- /* 6277 */ { MAD_F(0x07113659) /* 0.441702221 */, 18 },
- /* 6278 */ { MAD_F(0x071198bb) /* 0.441796048 */, 18 },
- /* 6279 */ { MAD_F(0x0711fb1f) /* 0.441889880 */, 18 },
- /* 6280 */ { MAD_F(0x07125d84) /* 0.441983717 */, 18 },
- /* 6281 */ { MAD_F(0x0712bfeb) /* 0.442077559 */, 18 },
- /* 6282 */ { MAD_F(0x07132253) /* 0.442171406 */, 18 },
- /* 6283 */ { MAD_F(0x071384bc) /* 0.442265257 */, 18 },
- /* 6284 */ { MAD_F(0x0713e726) /* 0.442359114 */, 18 },
- /* 6285 */ { MAD_F(0x07144992) /* 0.442452976 */, 18 },
- /* 6286 */ { MAD_F(0x0714abff) /* 0.442546843 */, 18 },
- /* 6287 */ { MAD_F(0x07150e6e) /* 0.442640715 */, 18 },
-
- /* 6288 */ { MAD_F(0x071570de) /* 0.442734592 */, 18 },
- /* 6289 */ { MAD_F(0x0715d34f) /* 0.442828473 */, 18 },
- /* 6290 */ { MAD_F(0x071635c1) /* 0.442922360 */, 18 },
- /* 6291 */ { MAD_F(0x07169835) /* 0.443016252 */, 18 },
- /* 6292 */ { MAD_F(0x0716faaa) /* 0.443110148 */, 18 },
- /* 6293 */ { MAD_F(0x07175d21) /* 0.443204050 */, 18 },
- /* 6294 */ { MAD_F(0x0717bf99) /* 0.443297957 */, 18 },
- /* 6295 */ { MAD_F(0x07182212) /* 0.443391868 */, 18 },
- /* 6296 */ { MAD_F(0x0718848d) /* 0.443485785 */, 18 },
- /* 6297 */ { MAD_F(0x0718e709) /* 0.443579706 */, 18 },
- /* 6298 */ { MAD_F(0x07194986) /* 0.443673633 */, 18 },
- /* 6299 */ { MAD_F(0x0719ac04) /* 0.443767564 */, 18 },
- /* 6300 */ { MAD_F(0x071a0e84) /* 0.443861501 */, 18 },
- /* 6301 */ { MAD_F(0x071a7105) /* 0.443955442 */, 18 },
- /* 6302 */ { MAD_F(0x071ad388) /* 0.444049389 */, 18 },
- /* 6303 */ { MAD_F(0x071b360c) /* 0.444143340 */, 18 },
-
- /* 6304 */ { MAD_F(0x071b9891) /* 0.444237296 */, 18 },
- /* 6305 */ { MAD_F(0x071bfb18) /* 0.444331258 */, 18 },
- /* 6306 */ { MAD_F(0x071c5d9f) /* 0.444425224 */, 18 },
- /* 6307 */ { MAD_F(0x071cc029) /* 0.444519195 */, 18 },
- /* 6308 */ { MAD_F(0x071d22b3) /* 0.444613171 */, 18 },
- /* 6309 */ { MAD_F(0x071d853f) /* 0.444707153 */, 18 },
- /* 6310 */ { MAD_F(0x071de7cc) /* 0.444801139 */, 18 },
- /* 6311 */ { MAD_F(0x071e4a5b) /* 0.444895130 */, 18 },
- /* 6312 */ { MAD_F(0x071eaceb) /* 0.444989126 */, 18 },
- /* 6313 */ { MAD_F(0x071f0f7c) /* 0.445083127 */, 18 },
- /* 6314 */ { MAD_F(0x071f720e) /* 0.445177133 */, 18 },
- /* 6315 */ { MAD_F(0x071fd4a2) /* 0.445271144 */, 18 },
- /* 6316 */ { MAD_F(0x07203737) /* 0.445365160 */, 18 },
- /* 6317 */ { MAD_F(0x072099ce) /* 0.445459181 */, 18 },
- /* 6318 */ { MAD_F(0x0720fc66) /* 0.445553206 */, 18 },
- /* 6319 */ { MAD_F(0x07215eff) /* 0.445647237 */, 18 },
-
- /* 6320 */ { MAD_F(0x0721c19a) /* 0.445741273 */, 18 },
- /* 6321 */ { MAD_F(0x07222436) /* 0.445835314 */, 18 },
- /* 6322 */ { MAD_F(0x072286d3) /* 0.445929359 */, 18 },
- /* 6323 */ { MAD_F(0x0722e971) /* 0.446023410 */, 18 },
- /* 6324 */ { MAD_F(0x07234c11) /* 0.446117466 */, 18 },
- /* 6325 */ { MAD_F(0x0723aeb2) /* 0.446211526 */, 18 },
- /* 6326 */ { MAD_F(0x07241155) /* 0.446305592 */, 18 },
- /* 6327 */ { MAD_F(0x072473f9) /* 0.446399662 */, 18 },
- /* 6328 */ { MAD_F(0x0724d69e) /* 0.446493738 */, 18 },
- /* 6329 */ { MAD_F(0x07253944) /* 0.446587818 */, 18 },
- /* 6330 */ { MAD_F(0x07259bec) /* 0.446681903 */, 18 },
- /* 6331 */ { MAD_F(0x0725fe95) /* 0.446775994 */, 18 },
- /* 6332 */ { MAD_F(0x07266140) /* 0.446870089 */, 18 },
- /* 6333 */ { MAD_F(0x0726c3ec) /* 0.446964189 */, 18 },
- /* 6334 */ { MAD_F(0x07272699) /* 0.447058294 */, 18 },
- /* 6335 */ { MAD_F(0x07278947) /* 0.447152404 */, 18 },
-
- /* 6336 */ { MAD_F(0x0727ebf7) /* 0.447246519 */, 18 },
- /* 6337 */ { MAD_F(0x07284ea8) /* 0.447340639 */, 18 },
- /* 6338 */ { MAD_F(0x0728b15b) /* 0.447434764 */, 18 },
- /* 6339 */ { MAD_F(0x0729140f) /* 0.447528894 */, 18 },
- /* 6340 */ { MAD_F(0x072976c4) /* 0.447623029 */, 18 },
- /* 6341 */ { MAD_F(0x0729d97a) /* 0.447717169 */, 18 },
- /* 6342 */ { MAD_F(0x072a3c32) /* 0.447811314 */, 18 },
- /* 6343 */ { MAD_F(0x072a9eeb) /* 0.447905463 */, 18 },
- /* 6344 */ { MAD_F(0x072b01a6) /* 0.447999618 */, 18 },
- /* 6345 */ { MAD_F(0x072b6461) /* 0.448093778 */, 18 },
- /* 6346 */ { MAD_F(0x072bc71e) /* 0.448187942 */, 18 },
- /* 6347 */ { MAD_F(0x072c29dd) /* 0.448282112 */, 18 },
- /* 6348 */ { MAD_F(0x072c8c9d) /* 0.448376286 */, 18 },
- /* 6349 */ { MAD_F(0x072cef5e) /* 0.448470466 */, 18 },
- /* 6350 */ { MAD_F(0x072d5220) /* 0.448564650 */, 18 },
- /* 6351 */ { MAD_F(0x072db4e4) /* 0.448658839 */, 18 },
-
- /* 6352 */ { MAD_F(0x072e17a9) /* 0.448753033 */, 18 },
- /* 6353 */ { MAD_F(0x072e7a6f) /* 0.448847233 */, 18 },
- /* 6354 */ { MAD_F(0x072edd37) /* 0.448941437 */, 18 },
- /* 6355 */ { MAD_F(0x072f4000) /* 0.449035646 */, 18 },
- /* 6356 */ { MAD_F(0x072fa2ca) /* 0.449129860 */, 18 },
- /* 6357 */ { MAD_F(0x07300596) /* 0.449224079 */, 18 },
- /* 6358 */ { MAD_F(0x07306863) /* 0.449318303 */, 18 },
- /* 6359 */ { MAD_F(0x0730cb32) /* 0.449412531 */, 18 },
- /* 6360 */ { MAD_F(0x07312e01) /* 0.449506765 */, 18 },
- /* 6361 */ { MAD_F(0x073190d2) /* 0.449601004 */, 18 },
- /* 6362 */ { MAD_F(0x0731f3a5) /* 0.449695247 */, 18 },
- /* 6363 */ { MAD_F(0x07325678) /* 0.449789496 */, 18 },
- /* 6364 */ { MAD_F(0x0732b94d) /* 0.449883749 */, 18 },
- /* 6365 */ { MAD_F(0x07331c23) /* 0.449978008 */, 18 },
- /* 6366 */ { MAD_F(0x07337efb) /* 0.450072271 */, 18 },
- /* 6367 */ { MAD_F(0x0733e1d4) /* 0.450166540 */, 18 },
-
- /* 6368 */ { MAD_F(0x073444ae) /* 0.450260813 */, 18 },
- /* 6369 */ { MAD_F(0x0734a78a) /* 0.450355091 */, 18 },
- /* 6370 */ { MAD_F(0x07350a67) /* 0.450449374 */, 18 },
- /* 6371 */ { MAD_F(0x07356d45) /* 0.450543662 */, 18 },
- /* 6372 */ { MAD_F(0x0735d025) /* 0.450637955 */, 18 },
- /* 6373 */ { MAD_F(0x07363306) /* 0.450732253 */, 18 },
- /* 6374 */ { MAD_F(0x073695e8) /* 0.450826556 */, 18 },
- /* 6375 */ { MAD_F(0x0736f8cb) /* 0.450920864 */, 18 },
- /* 6376 */ { MAD_F(0x07375bb0) /* 0.451015176 */, 18 },
- /* 6377 */ { MAD_F(0x0737be96) /* 0.451109494 */, 18 },
- /* 6378 */ { MAD_F(0x0738217e) /* 0.451203817 */, 18 },
- /* 6379 */ { MAD_F(0x07388467) /* 0.451298144 */, 18 },
- /* 6380 */ { MAD_F(0x0738e751) /* 0.451392477 */, 18 },
- /* 6381 */ { MAD_F(0x07394a3d) /* 0.451486814 */, 18 },
- /* 6382 */ { MAD_F(0x0739ad29) /* 0.451581156 */, 18 },
- /* 6383 */ { MAD_F(0x073a1017) /* 0.451675503 */, 18 },
-
- /* 6384 */ { MAD_F(0x073a7307) /* 0.451769856 */, 18 },
- /* 6385 */ { MAD_F(0x073ad5f8) /* 0.451864213 */, 18 },
- /* 6386 */ { MAD_F(0x073b38ea) /* 0.451958575 */, 18 },
- /* 6387 */ { MAD_F(0x073b9bdd) /* 0.452052942 */, 18 },
- /* 6388 */ { MAD_F(0x073bfed2) /* 0.452147313 */, 18 },
- /* 6389 */ { MAD_F(0x073c61c8) /* 0.452241690 */, 18 },
- /* 6390 */ { MAD_F(0x073cc4bf) /* 0.452336072 */, 18 },
- /* 6391 */ { MAD_F(0x073d27b8) /* 0.452430458 */, 18 },
- /* 6392 */ { MAD_F(0x073d8ab2) /* 0.452524850 */, 18 },
- /* 6393 */ { MAD_F(0x073dedae) /* 0.452619246 */, 18 },
- /* 6394 */ { MAD_F(0x073e50aa) /* 0.452713648 */, 18 },
- /* 6395 */ { MAD_F(0x073eb3a8) /* 0.452808054 */, 18 },
- /* 6396 */ { MAD_F(0x073f16a8) /* 0.452902465 */, 18 },
- /* 6397 */ { MAD_F(0x073f79a8) /* 0.452996882 */, 18 },
- /* 6398 */ { MAD_F(0x073fdcaa) /* 0.453091303 */, 18 },
- /* 6399 */ { MAD_F(0x07403fad) /* 0.453185729 */, 18 },
-
- /* 6400 */ { MAD_F(0x0740a2b2) /* 0.453280160 */, 18 },
- /* 6401 */ { MAD_F(0x074105b8) /* 0.453374595 */, 18 },
- /* 6402 */ { MAD_F(0x074168bf) /* 0.453469036 */, 18 },
- /* 6403 */ { MAD_F(0x0741cbc8) /* 0.453563482 */, 18 },
- /* 6404 */ { MAD_F(0x07422ed2) /* 0.453657932 */, 18 },
- /* 6405 */ { MAD_F(0x074291dd) /* 0.453752388 */, 18 },
- /* 6406 */ { MAD_F(0x0742f4e9) /* 0.453846848 */, 18 },
- /* 6407 */ { MAD_F(0x074357f7) /* 0.453941314 */, 18 },
- /* 6408 */ { MAD_F(0x0743bb06) /* 0.454035784 */, 18 },
- /* 6409 */ { MAD_F(0x07441e17) /* 0.454130259 */, 18 },
- /* 6410 */ { MAD_F(0x07448129) /* 0.454224739 */, 18 },
- /* 6411 */ { MAD_F(0x0744e43c) /* 0.454319224 */, 18 },
- /* 6412 */ { MAD_F(0x07454750) /* 0.454413714 */, 18 },
- /* 6413 */ { MAD_F(0x0745aa66) /* 0.454508209 */, 18 },
- /* 6414 */ { MAD_F(0x07460d7d) /* 0.454602708 */, 18 },
- /* 6415 */ { MAD_F(0x07467095) /* 0.454697213 */, 18 },
-
- /* 6416 */ { MAD_F(0x0746d3af) /* 0.454791723 */, 18 },
- /* 6417 */ { MAD_F(0x074736ca) /* 0.454886237 */, 18 },
- /* 6418 */ { MAD_F(0x074799e7) /* 0.454980756 */, 18 },
- /* 6419 */ { MAD_F(0x0747fd04) /* 0.455075281 */, 18 },
- /* 6420 */ { MAD_F(0x07486023) /* 0.455169810 */, 18 },
- /* 6421 */ { MAD_F(0x0748c344) /* 0.455264344 */, 18 },
- /* 6422 */ { MAD_F(0x07492665) /* 0.455358883 */, 18 },
- /* 6423 */ { MAD_F(0x07498988) /* 0.455453427 */, 18 },
- /* 6424 */ { MAD_F(0x0749ecac) /* 0.455547976 */, 18 },
- /* 6425 */ { MAD_F(0x074a4fd2) /* 0.455642529 */, 18 },
- /* 6426 */ { MAD_F(0x074ab2f9) /* 0.455737088 */, 18 },
- /* 6427 */ { MAD_F(0x074b1621) /* 0.455831652 */, 18 },
- /* 6428 */ { MAD_F(0x074b794b) /* 0.455926220 */, 18 },
- /* 6429 */ { MAD_F(0x074bdc75) /* 0.456020793 */, 18 },
- /* 6430 */ { MAD_F(0x074c3fa1) /* 0.456115372 */, 18 },
- /* 6431 */ { MAD_F(0x074ca2cf) /* 0.456209955 */, 18 },
-
- /* 6432 */ { MAD_F(0x074d05fe) /* 0.456304543 */, 18 },
- /* 6433 */ { MAD_F(0x074d692e) /* 0.456399136 */, 18 },
- /* 6434 */ { MAD_F(0x074dcc5f) /* 0.456493733 */, 18 },
- /* 6435 */ { MAD_F(0x074e2f92) /* 0.456588336 */, 18 },
- /* 6436 */ { MAD_F(0x074e92c6) /* 0.456682944 */, 18 },
- /* 6437 */ { MAD_F(0x074ef5fb) /* 0.456777556 */, 18 },
- /* 6438 */ { MAD_F(0x074f5932) /* 0.456872174 */, 18 },
- /* 6439 */ { MAD_F(0x074fbc6a) /* 0.456966796 */, 18 },
- /* 6440 */ { MAD_F(0x07501fa3) /* 0.457061423 */, 18 },
- /* 6441 */ { MAD_F(0x075082de) /* 0.457156056 */, 18 },
- /* 6442 */ { MAD_F(0x0750e61a) /* 0.457250693 */, 18 },
- /* 6443 */ { MAD_F(0x07514957) /* 0.457345335 */, 18 },
- /* 6444 */ { MAD_F(0x0751ac96) /* 0.457439981 */, 18 },
- /* 6445 */ { MAD_F(0x07520fd6) /* 0.457534633 */, 18 },
- /* 6446 */ { MAD_F(0x07527317) /* 0.457629290 */, 18 },
- /* 6447 */ { MAD_F(0x0752d659) /* 0.457723951 */, 18 },
-
- /* 6448 */ { MAD_F(0x0753399d) /* 0.457818618 */, 18 },
- /* 6449 */ { MAD_F(0x07539ce2) /* 0.457913289 */, 18 },
- /* 6450 */ { MAD_F(0x07540029) /* 0.458007965 */, 18 },
- /* 6451 */ { MAD_F(0x07546371) /* 0.458102646 */, 18 },
- /* 6452 */ { MAD_F(0x0754c6ba) /* 0.458197332 */, 18 },
- /* 6453 */ { MAD_F(0x07552a04) /* 0.458292023 */, 18 },
- /* 6454 */ { MAD_F(0x07558d50) /* 0.458386719 */, 18 },
- /* 6455 */ { MAD_F(0x0755f09d) /* 0.458481420 */, 18 },
- /* 6456 */ { MAD_F(0x075653eb) /* 0.458576125 */, 18 },
- /* 6457 */ { MAD_F(0x0756b73b) /* 0.458670836 */, 18 },
- /* 6458 */ { MAD_F(0x07571a8c) /* 0.458765551 */, 18 },
- /* 6459 */ { MAD_F(0x07577dde) /* 0.458860271 */, 18 },
- /* 6460 */ { MAD_F(0x0757e131) /* 0.458954996 */, 18 },
- /* 6461 */ { MAD_F(0x07584486) /* 0.459049726 */, 18 },
- /* 6462 */ { MAD_F(0x0758a7dd) /* 0.459144461 */, 18 },
- /* 6463 */ { MAD_F(0x07590b34) /* 0.459239201 */, 18 },
-
- /* 6464 */ { MAD_F(0x07596e8d) /* 0.459333946 */, 18 },
- /* 6465 */ { MAD_F(0x0759d1e7) /* 0.459428695 */, 18 },
- /* 6466 */ { MAD_F(0x075a3542) /* 0.459523450 */, 18 },
- /* 6467 */ { MAD_F(0x075a989f) /* 0.459618209 */, 18 },
- /* 6468 */ { MAD_F(0x075afbfd) /* 0.459712973 */, 18 },
- /* 6469 */ { MAD_F(0x075b5f5d) /* 0.459807742 */, 18 },
- /* 6470 */ { MAD_F(0x075bc2bd) /* 0.459902516 */, 18 },
- /* 6471 */ { MAD_F(0x075c261f) /* 0.459997295 */, 18 },
- /* 6472 */ { MAD_F(0x075c8983) /* 0.460092079 */, 18 },
- /* 6473 */ { MAD_F(0x075cece7) /* 0.460186867 */, 18 },
- /* 6474 */ { MAD_F(0x075d504d) /* 0.460281661 */, 18 },
- /* 6475 */ { MAD_F(0x075db3b5) /* 0.460376459 */, 18 },
- /* 6476 */ { MAD_F(0x075e171d) /* 0.460471262 */, 18 },
- /* 6477 */ { MAD_F(0x075e7a87) /* 0.460566071 */, 18 },
- /* 6478 */ { MAD_F(0x075eddf2) /* 0.460660884 */, 18 },
- /* 6479 */ { MAD_F(0x075f415f) /* 0.460755701 */, 18 },
-
- /* 6480 */ { MAD_F(0x075fa4cc) /* 0.460850524 */, 18 },
- /* 6481 */ { MAD_F(0x0760083b) /* 0.460945352 */, 18 },
- /* 6482 */ { MAD_F(0x07606bac) /* 0.461040184 */, 18 },
- /* 6483 */ { MAD_F(0x0760cf1e) /* 0.461135022 */, 18 },
- /* 6484 */ { MAD_F(0x07613291) /* 0.461229864 */, 18 },
- /* 6485 */ { MAD_F(0x07619605) /* 0.461324711 */, 18 },
- /* 6486 */ { MAD_F(0x0761f97b) /* 0.461419563 */, 18 },
- /* 6487 */ { MAD_F(0x07625cf2) /* 0.461514420 */, 18 },
- /* 6488 */ { MAD_F(0x0762c06a) /* 0.461609282 */, 18 },
- /* 6489 */ { MAD_F(0x076323e3) /* 0.461704149 */, 18 },
- /* 6490 */ { MAD_F(0x0763875e) /* 0.461799020 */, 18 },
- /* 6491 */ { MAD_F(0x0763eadb) /* 0.461893897 */, 18 },
- /* 6492 */ { MAD_F(0x07644e58) /* 0.461988778 */, 18 },
- /* 6493 */ { MAD_F(0x0764b1d7) /* 0.462083664 */, 18 },
- /* 6494 */ { MAD_F(0x07651557) /* 0.462178555 */, 18 },
- /* 6495 */ { MAD_F(0x076578d8) /* 0.462273451 */, 18 },
-
- /* 6496 */ { MAD_F(0x0765dc5b) /* 0.462368352 */, 18 },
- /* 6497 */ { MAD_F(0x07663fdf) /* 0.462463257 */, 18 },
- /* 6498 */ { MAD_F(0x0766a364) /* 0.462558168 */, 18 },
- /* 6499 */ { MAD_F(0x076706eb) /* 0.462653083 */, 18 },
- /* 6500 */ { MAD_F(0x07676a73) /* 0.462748003 */, 18 },
- /* 6501 */ { MAD_F(0x0767cdfc) /* 0.462842928 */, 18 },
- /* 6502 */ { MAD_F(0x07683187) /* 0.462937858 */, 18 },
- /* 6503 */ { MAD_F(0x07689513) /* 0.463032793 */, 18 },
- /* 6504 */ { MAD_F(0x0768f8a0) /* 0.463127733 */, 18 },
- /* 6505 */ { MAD_F(0x07695c2e) /* 0.463222678 */, 18 },
- /* 6506 */ { MAD_F(0x0769bfbe) /* 0.463317627 */, 18 },
- /* 6507 */ { MAD_F(0x076a234f) /* 0.463412581 */, 18 },
- /* 6508 */ { MAD_F(0x076a86e2) /* 0.463507540 */, 18 },
- /* 6509 */ { MAD_F(0x076aea75) /* 0.463602504 */, 18 },
- /* 6510 */ { MAD_F(0x076b4e0a) /* 0.463697473 */, 18 },
- /* 6511 */ { MAD_F(0x076bb1a1) /* 0.463792447 */, 18 },
-
- /* 6512 */ { MAD_F(0x076c1538) /* 0.463887426 */, 18 },
- /* 6513 */ { MAD_F(0x076c78d1) /* 0.463982409 */, 18 },
- /* 6514 */ { MAD_F(0x076cdc6c) /* 0.464077398 */, 18 },
- /* 6515 */ { MAD_F(0x076d4007) /* 0.464172391 */, 18 },
- /* 6516 */ { MAD_F(0x076da3a4) /* 0.464267389 */, 18 },
- /* 6517 */ { MAD_F(0x076e0742) /* 0.464362392 */, 18 },
- /* 6518 */ { MAD_F(0x076e6ae2) /* 0.464457399 */, 18 },
- /* 6519 */ { MAD_F(0x076ece82) /* 0.464552412 */, 18 },
- /* 6520 */ { MAD_F(0x076f3224) /* 0.464647430 */, 18 },
- /* 6521 */ { MAD_F(0x076f95c8) /* 0.464742452 */, 18 },
- /* 6522 */ { MAD_F(0x076ff96c) /* 0.464837479 */, 18 },
- /* 6523 */ { MAD_F(0x07705d12) /* 0.464932511 */, 18 },
- /* 6524 */ { MAD_F(0x0770c0ba) /* 0.465027548 */, 18 },
- /* 6525 */ { MAD_F(0x07712462) /* 0.465122590 */, 18 },
- /* 6526 */ { MAD_F(0x0771880c) /* 0.465217637 */, 18 },
- /* 6527 */ { MAD_F(0x0771ebb7) /* 0.465312688 */, 18 },
-
- /* 6528 */ { MAD_F(0x07724f64) /* 0.465407744 */, 18 },
- /* 6529 */ { MAD_F(0x0772b312) /* 0.465502806 */, 18 },
- /* 6530 */ { MAD_F(0x077316c1) /* 0.465597872 */, 18 },
- /* 6531 */ { MAD_F(0x07737a71) /* 0.465692943 */, 18 },
- /* 6532 */ { MAD_F(0x0773de23) /* 0.465788018 */, 18 },
- /* 6533 */ { MAD_F(0x077441d6) /* 0.465883099 */, 18 },
- /* 6534 */ { MAD_F(0x0774a58a) /* 0.465978184 */, 18 },
- /* 6535 */ { MAD_F(0x07750940) /* 0.466073275 */, 18 },
- /* 6536 */ { MAD_F(0x07756cf7) /* 0.466168370 */, 18 },
- /* 6537 */ { MAD_F(0x0775d0af) /* 0.466263470 */, 18 },
- /* 6538 */ { MAD_F(0x07763468) /* 0.466358575 */, 18 },
- /* 6539 */ { MAD_F(0x07769823) /* 0.466453684 */, 18 },
- /* 6540 */ { MAD_F(0x0776fbdf) /* 0.466548799 */, 18 },
- /* 6541 */ { MAD_F(0x07775f9d) /* 0.466643918 */, 18 },
- /* 6542 */ { MAD_F(0x0777c35c) /* 0.466739043 */, 18 },
- /* 6543 */ { MAD_F(0x0778271c) /* 0.466834172 */, 18 },
-
- /* 6544 */ { MAD_F(0x07788add) /* 0.466929306 */, 18 },
- /* 6545 */ { MAD_F(0x0778ee9f) /* 0.467024445 */, 18 },
- /* 6546 */ { MAD_F(0x07795263) /* 0.467119588 */, 18 },
- /* 6547 */ { MAD_F(0x0779b629) /* 0.467214737 */, 18 },
- /* 6548 */ { MAD_F(0x077a19ef) /* 0.467309890 */, 18 },
- /* 6549 */ { MAD_F(0x077a7db7) /* 0.467405048 */, 18 },
- /* 6550 */ { MAD_F(0x077ae180) /* 0.467500211 */, 18 },
- /* 6551 */ { MAD_F(0x077b454b) /* 0.467595379 */, 18 },
- /* 6552 */ { MAD_F(0x077ba916) /* 0.467690552 */, 18 },
- /* 6553 */ { MAD_F(0x077c0ce3) /* 0.467785729 */, 18 },
- /* 6554 */ { MAD_F(0x077c70b2) /* 0.467880912 */, 18 },
- /* 6555 */ { MAD_F(0x077cd481) /* 0.467976099 */, 18 },
- /* 6556 */ { MAD_F(0x077d3852) /* 0.468071291 */, 18 },
- /* 6557 */ { MAD_F(0x077d9c24) /* 0.468166488 */, 18 },
- /* 6558 */ { MAD_F(0x077dfff8) /* 0.468261690 */, 18 },
- /* 6559 */ { MAD_F(0x077e63cd) /* 0.468356896 */, 18 },
-
- /* 6560 */ { MAD_F(0x077ec7a3) /* 0.468452108 */, 18 },
- /* 6561 */ { MAD_F(0x077f2b7a) /* 0.468547324 */, 18 },
- /* 6562 */ { MAD_F(0x077f8f53) /* 0.468642545 */, 18 },
- /* 6563 */ { MAD_F(0x077ff32d) /* 0.468737771 */, 18 },
- /* 6564 */ { MAD_F(0x07805708) /* 0.468833002 */, 18 },
- /* 6565 */ { MAD_F(0x0780bae5) /* 0.468928237 */, 18 },
- /* 6566 */ { MAD_F(0x07811ec3) /* 0.469023478 */, 18 },
- /* 6567 */ { MAD_F(0x078182a2) /* 0.469118723 */, 18 },
- /* 6568 */ { MAD_F(0x0781e683) /* 0.469213973 */, 18 },
- /* 6569 */ { MAD_F(0x07824a64) /* 0.469309228 */, 18 },
- /* 6570 */ { MAD_F(0x0782ae47) /* 0.469404488 */, 18 },
- /* 6571 */ { MAD_F(0x0783122c) /* 0.469499752 */, 18 },
- /* 6572 */ { MAD_F(0x07837612) /* 0.469595022 */, 18 },
- /* 6573 */ { MAD_F(0x0783d9f9) /* 0.469690296 */, 18 },
- /* 6574 */ { MAD_F(0x07843de1) /* 0.469785575 */, 18 },
- /* 6575 */ { MAD_F(0x0784a1ca) /* 0.469880859 */, 18 },
-
- /* 6576 */ { MAD_F(0x078505b5) /* 0.469976148 */, 18 },
- /* 6577 */ { MAD_F(0x078569a2) /* 0.470071442 */, 18 },
- /* 6578 */ { MAD_F(0x0785cd8f) /* 0.470166740 */, 18 },
- /* 6579 */ { MAD_F(0x0786317e) /* 0.470262043 */, 18 },
- /* 6580 */ { MAD_F(0x0786956e) /* 0.470357351 */, 18 },
- /* 6581 */ { MAD_F(0x0786f95f) /* 0.470452664 */, 18 },
- /* 6582 */ { MAD_F(0x07875d52) /* 0.470547982 */, 18 },
- /* 6583 */ { MAD_F(0x0787c146) /* 0.470643305 */, 18 },
- /* 6584 */ { MAD_F(0x0788253b) /* 0.470738632 */, 18 },
- /* 6585 */ { MAD_F(0x07888932) /* 0.470833964 */, 18 },
- /* 6586 */ { MAD_F(0x0788ed2a) /* 0.470929301 */, 18 },
- /* 6587 */ { MAD_F(0x07895123) /* 0.471024643 */, 18 },
- /* 6588 */ { MAD_F(0x0789b51d) /* 0.471119990 */, 18 },
- /* 6589 */ { MAD_F(0x078a1919) /* 0.471215341 */, 18 },
- /* 6590 */ { MAD_F(0x078a7d16) /* 0.471310698 */, 18 },
- /* 6591 */ { MAD_F(0x078ae114) /* 0.471406059 */, 18 },
-
- /* 6592 */ { MAD_F(0x078b4514) /* 0.471501425 */, 18 },
- /* 6593 */ { MAD_F(0x078ba915) /* 0.471596796 */, 18 },
- /* 6594 */ { MAD_F(0x078c0d17) /* 0.471692171 */, 18 },
- /* 6595 */ { MAD_F(0x078c711a) /* 0.471787552 */, 18 },
- /* 6596 */ { MAD_F(0x078cd51f) /* 0.471882937 */, 18 },
- /* 6597 */ { MAD_F(0x078d3925) /* 0.471978327 */, 18 },
- /* 6598 */ { MAD_F(0x078d9d2d) /* 0.472073722 */, 18 },
- /* 6599 */ { MAD_F(0x078e0135) /* 0.472169122 */, 18 },
- /* 6600 */ { MAD_F(0x078e653f) /* 0.472264527 */, 18 },
- /* 6601 */ { MAD_F(0x078ec94b) /* 0.472359936 */, 18 },
- /* 6602 */ { MAD_F(0x078f2d57) /* 0.472455350 */, 18 },
- /* 6603 */ { MAD_F(0x078f9165) /* 0.472550769 */, 18 },
- /* 6604 */ { MAD_F(0x078ff574) /* 0.472646193 */, 18 },
- /* 6605 */ { MAD_F(0x07905985) /* 0.472741622 */, 18 },
- /* 6606 */ { MAD_F(0x0790bd96) /* 0.472837055 */, 18 },
- /* 6607 */ { MAD_F(0x079121a9) /* 0.472932493 */, 18 },
-
- /* 6608 */ { MAD_F(0x079185be) /* 0.473027937 */, 18 },
- /* 6609 */ { MAD_F(0x0791e9d3) /* 0.473123384 */, 18 },
- /* 6610 */ { MAD_F(0x07924dea) /* 0.473218837 */, 18 },
- /* 6611 */ { MAD_F(0x0792b202) /* 0.473314295 */, 18 },
- /* 6612 */ { MAD_F(0x0793161c) /* 0.473409757 */, 18 },
- /* 6613 */ { MAD_F(0x07937a37) /* 0.473505224 */, 18 },
- /* 6614 */ { MAD_F(0x0793de53) /* 0.473600696 */, 18 },
- /* 6615 */ { MAD_F(0x07944270) /* 0.473696173 */, 18 },
- /* 6616 */ { MAD_F(0x0794a68f) /* 0.473791655 */, 18 },
- /* 6617 */ { MAD_F(0x07950aaf) /* 0.473887141 */, 18 },
- /* 6618 */ { MAD_F(0x07956ed0) /* 0.473982632 */, 18 },
- /* 6619 */ { MAD_F(0x0795d2f2) /* 0.474078128 */, 18 },
- /* 6620 */ { MAD_F(0x07963716) /* 0.474173629 */, 18 },
- /* 6621 */ { MAD_F(0x07969b3b) /* 0.474269135 */, 18 },
- /* 6622 */ { MAD_F(0x0796ff62) /* 0.474364645 */, 18 },
- /* 6623 */ { MAD_F(0x07976389) /* 0.474460161 */, 18 },
-
- /* 6624 */ { MAD_F(0x0797c7b2) /* 0.474555681 */, 18 },
- /* 6625 */ { MAD_F(0x07982bdd) /* 0.474651205 */, 18 },
- /* 6626 */ { MAD_F(0x07989008) /* 0.474746735 */, 18 },
- /* 6627 */ { MAD_F(0x0798f435) /* 0.474842270 */, 18 },
- /* 6628 */ { MAD_F(0x07995863) /* 0.474937809 */, 18 },
- /* 6629 */ { MAD_F(0x0799bc92) /* 0.475033353 */, 18 },
- /* 6630 */ { MAD_F(0x079a20c3) /* 0.475128902 */, 18 },
- /* 6631 */ { MAD_F(0x079a84f5) /* 0.475224456 */, 18 },
- /* 6632 */ { MAD_F(0x079ae929) /* 0.475320014 */, 18 },
- /* 6633 */ { MAD_F(0x079b4d5d) /* 0.475415578 */, 18 },
- /* 6634 */ { MAD_F(0x079bb193) /* 0.475511146 */, 18 },
- /* 6635 */ { MAD_F(0x079c15ca) /* 0.475606719 */, 18 },
- /* 6636 */ { MAD_F(0x079c7a03) /* 0.475702296 */, 18 },
- /* 6637 */ { MAD_F(0x079cde3c) /* 0.475797879 */, 18 },
- /* 6638 */ { MAD_F(0x079d4277) /* 0.475893466 */, 18 },
- /* 6639 */ { MAD_F(0x079da6b4) /* 0.475989058 */, 18 },
-
- /* 6640 */ { MAD_F(0x079e0af1) /* 0.476084655 */, 18 },
- /* 6641 */ { MAD_F(0x079e6f30) /* 0.476180257 */, 18 },
- /* 6642 */ { MAD_F(0x079ed370) /* 0.476275863 */, 18 },
- /* 6643 */ { MAD_F(0x079f37b2) /* 0.476371475 */, 18 },
- /* 6644 */ { MAD_F(0x079f9bf5) /* 0.476467091 */, 18 },
- /* 6645 */ { MAD_F(0x07a00039) /* 0.476562712 */, 18 },
- /* 6646 */ { MAD_F(0x07a0647e) /* 0.476658338 */, 18 },
- /* 6647 */ { MAD_F(0x07a0c8c5) /* 0.476753968 */, 18 },
- /* 6648 */ { MAD_F(0x07a12d0c) /* 0.476849603 */, 18 },
- /* 6649 */ { MAD_F(0x07a19156) /* 0.476945243 */, 18 },
- /* 6650 */ { MAD_F(0x07a1f5a0) /* 0.477040888 */, 18 },
- /* 6651 */ { MAD_F(0x07a259ec) /* 0.477136538 */, 18 },
- /* 6652 */ { MAD_F(0x07a2be39) /* 0.477232193 */, 18 },
- /* 6653 */ { MAD_F(0x07a32287) /* 0.477327852 */, 18 },
- /* 6654 */ { MAD_F(0x07a386d7) /* 0.477423516 */, 18 },
- /* 6655 */ { MAD_F(0x07a3eb28) /* 0.477519185 */, 18 },
-
- /* 6656 */ { MAD_F(0x07a44f7a) /* 0.477614858 */, 18 },
- /* 6657 */ { MAD_F(0x07a4b3ce) /* 0.477710537 */, 18 },
- /* 6658 */ { MAD_F(0x07a51822) /* 0.477806220 */, 18 },
- /* 6659 */ { MAD_F(0x07a57c78) /* 0.477901908 */, 18 },
- /* 6660 */ { MAD_F(0x07a5e0d0) /* 0.477997601 */, 18 },
- /* 6661 */ { MAD_F(0x07a64528) /* 0.478093299 */, 18 },
- /* 6662 */ { MAD_F(0x07a6a982) /* 0.478189001 */, 18 },
- /* 6663 */ { MAD_F(0x07a70ddd) /* 0.478284708 */, 18 },
- /* 6664 */ { MAD_F(0x07a7723a) /* 0.478380420 */, 18 },
- /* 6665 */ { MAD_F(0x07a7d698) /* 0.478476137 */, 18 },
- /* 6666 */ { MAD_F(0x07a83af7) /* 0.478571858 */, 18 },
- /* 6667 */ { MAD_F(0x07a89f57) /* 0.478667585 */, 18 },
- /* 6668 */ { MAD_F(0x07a903b9) /* 0.478763316 */, 18 },
- /* 6669 */ { MAD_F(0x07a9681c) /* 0.478859052 */, 18 },
- /* 6670 */ { MAD_F(0x07a9cc80) /* 0.478954793 */, 18 },
- /* 6671 */ { MAD_F(0x07aa30e5) /* 0.479050538 */, 18 },
-
- /* 6672 */ { MAD_F(0x07aa954c) /* 0.479146288 */, 18 },
- /* 6673 */ { MAD_F(0x07aaf9b4) /* 0.479242043 */, 18 },
- /* 6674 */ { MAD_F(0x07ab5e1e) /* 0.479337803 */, 18 },
- /* 6675 */ { MAD_F(0x07abc288) /* 0.479433568 */, 18 },
- /* 6676 */ { MAD_F(0x07ac26f4) /* 0.479529337 */, 18 },
- /* 6677 */ { MAD_F(0x07ac8b61) /* 0.479625111 */, 18 },
- /* 6678 */ { MAD_F(0x07acefd0) /* 0.479720890 */, 18 },
- /* 6679 */ { MAD_F(0x07ad543f) /* 0.479816674 */, 18 },
- /* 6680 */ { MAD_F(0x07adb8b0) /* 0.479912463 */, 18 },
- /* 6681 */ { MAD_F(0x07ae1d23) /* 0.480008256 */, 18 },
- /* 6682 */ { MAD_F(0x07ae8196) /* 0.480104054 */, 18 },
- /* 6683 */ { MAD_F(0x07aee60b) /* 0.480199857 */, 18 },
- /* 6684 */ { MAD_F(0x07af4a81) /* 0.480295664 */, 18 },
- /* 6685 */ { MAD_F(0x07afaef9) /* 0.480391477 */, 18 },
- /* 6686 */ { MAD_F(0x07b01372) /* 0.480487294 */, 18 },
- /* 6687 */ { MAD_F(0x07b077ec) /* 0.480583116 */, 18 },
-
- /* 6688 */ { MAD_F(0x07b0dc67) /* 0.480678943 */, 18 },
- /* 6689 */ { MAD_F(0x07b140e4) /* 0.480774774 */, 18 },
- /* 6690 */ { MAD_F(0x07b1a561) /* 0.480870611 */, 18 },
- /* 6691 */ { MAD_F(0x07b209e1) /* 0.480966452 */, 18 },
- /* 6692 */ { MAD_F(0x07b26e61) /* 0.481062298 */, 18 },
- /* 6693 */ { MAD_F(0x07b2d2e3) /* 0.481158148 */, 18 },
- /* 6694 */ { MAD_F(0x07b33766) /* 0.481254004 */, 18 },
- /* 6695 */ { MAD_F(0x07b39bea) /* 0.481349864 */, 18 },
- /* 6696 */ { MAD_F(0x07b4006f) /* 0.481445729 */, 18 },
- /* 6697 */ { MAD_F(0x07b464f6) /* 0.481541598 */, 18 },
- /* 6698 */ { MAD_F(0x07b4c97e) /* 0.481637473 */, 18 },
- /* 6699 */ { MAD_F(0x07b52e08) /* 0.481733352 */, 18 },
- /* 6700 */ { MAD_F(0x07b59292) /* 0.481829236 */, 18 },
- /* 6701 */ { MAD_F(0x07b5f71e) /* 0.481925125 */, 18 },
- /* 6702 */ { MAD_F(0x07b65bac) /* 0.482021019 */, 18 },
- /* 6703 */ { MAD_F(0x07b6c03a) /* 0.482116917 */, 18 },
-
- /* 6704 */ { MAD_F(0x07b724ca) /* 0.482212820 */, 18 },
- /* 6705 */ { MAD_F(0x07b7895b) /* 0.482308728 */, 18 },
- /* 6706 */ { MAD_F(0x07b7eded) /* 0.482404640 */, 18 },
- /* 6707 */ { MAD_F(0x07b85281) /* 0.482500558 */, 18 },
- /* 6708 */ { MAD_F(0x07b8b716) /* 0.482596480 */, 18 },
- /* 6709 */ { MAD_F(0x07b91bac) /* 0.482692407 */, 18 },
- /* 6710 */ { MAD_F(0x07b98044) /* 0.482788339 */, 18 },
- /* 6711 */ { MAD_F(0x07b9e4dc) /* 0.482884275 */, 18 },
- /* 6712 */ { MAD_F(0x07ba4976) /* 0.482980216 */, 18 },
- /* 6713 */ { MAD_F(0x07baae12) /* 0.483076162 */, 18 },
- /* 6714 */ { MAD_F(0x07bb12ae) /* 0.483172113 */, 18 },
- /* 6715 */ { MAD_F(0x07bb774c) /* 0.483268069 */, 18 },
- /* 6716 */ { MAD_F(0x07bbdbeb) /* 0.483364029 */, 18 },
- /* 6717 */ { MAD_F(0x07bc408c) /* 0.483459994 */, 18 },
- /* 6718 */ { MAD_F(0x07bca52d) /* 0.483555964 */, 18 },
- /* 6719 */ { MAD_F(0x07bd09d0) /* 0.483651939 */, 18 },
-
- /* 6720 */ { MAD_F(0x07bd6e75) /* 0.483747918 */, 18 },
- /* 6721 */ { MAD_F(0x07bdd31a) /* 0.483843902 */, 18 },
- /* 6722 */ { MAD_F(0x07be37c1) /* 0.483939891 */, 18 },
- /* 6723 */ { MAD_F(0x07be9c69) /* 0.484035885 */, 18 },
- /* 6724 */ { MAD_F(0x07bf0113) /* 0.484131883 */, 18 },
- /* 6725 */ { MAD_F(0x07bf65bd) /* 0.484227886 */, 18 },
- /* 6726 */ { MAD_F(0x07bfca69) /* 0.484323894 */, 18 },
- /* 6727 */ { MAD_F(0x07c02f16) /* 0.484419907 */, 18 },
- /* 6728 */ { MAD_F(0x07c093c5) /* 0.484515924 */, 18 },
- /* 6729 */ { MAD_F(0x07c0f875) /* 0.484611946 */, 18 },
- /* 6730 */ { MAD_F(0x07c15d26) /* 0.484707973 */, 18 },
- /* 6731 */ { MAD_F(0x07c1c1d8) /* 0.484804005 */, 18 },
- /* 6732 */ { MAD_F(0x07c2268b) /* 0.484900041 */, 18 },
- /* 6733 */ { MAD_F(0x07c28b40) /* 0.484996083 */, 18 },
- /* 6734 */ { MAD_F(0x07c2eff6) /* 0.485092128 */, 18 },
- /* 6735 */ { MAD_F(0x07c354ae) /* 0.485188179 */, 18 },
-
- /* 6736 */ { MAD_F(0x07c3b967) /* 0.485284235 */, 18 },
- /* 6737 */ { MAD_F(0x07c41e21) /* 0.485380295 */, 18 },
- /* 6738 */ { MAD_F(0x07c482dc) /* 0.485476360 */, 18 },
- /* 6739 */ { MAD_F(0x07c4e798) /* 0.485572430 */, 18 },
- /* 6740 */ { MAD_F(0x07c54c56) /* 0.485668504 */, 18 },
- /* 6741 */ { MAD_F(0x07c5b115) /* 0.485764583 */, 18 },
- /* 6742 */ { MAD_F(0x07c615d6) /* 0.485860667 */, 18 },
- /* 6743 */ { MAD_F(0x07c67a97) /* 0.485956756 */, 18 },
- /* 6744 */ { MAD_F(0x07c6df5a) /* 0.486052849 */, 18 },
- /* 6745 */ { MAD_F(0x07c7441e) /* 0.486148948 */, 18 },
- /* 6746 */ { MAD_F(0x07c7a8e4) /* 0.486245051 */, 18 },
- /* 6747 */ { MAD_F(0x07c80daa) /* 0.486341158 */, 18 },
- /* 6748 */ { MAD_F(0x07c87272) /* 0.486437271 */, 18 },
- /* 6749 */ { MAD_F(0x07c8d73c) /* 0.486533388 */, 18 },
- /* 6750 */ { MAD_F(0x07c93c06) /* 0.486629510 */, 18 },
- /* 6751 */ { MAD_F(0x07c9a0d2) /* 0.486725637 */, 18 },
-
- /* 6752 */ { MAD_F(0x07ca059f) /* 0.486821768 */, 18 },
- /* 6753 */ { MAD_F(0x07ca6a6d) /* 0.486917905 */, 18 },
- /* 6754 */ { MAD_F(0x07cacf3d) /* 0.487014045 */, 18 },
- /* 6755 */ { MAD_F(0x07cb340e) /* 0.487110191 */, 18 },
- /* 6756 */ { MAD_F(0x07cb98e0) /* 0.487206342 */, 18 },
- /* 6757 */ { MAD_F(0x07cbfdb4) /* 0.487302497 */, 18 },
- /* 6758 */ { MAD_F(0x07cc6288) /* 0.487398657 */, 18 },
- /* 6759 */ { MAD_F(0x07ccc75e) /* 0.487494821 */, 18 },
- /* 6760 */ { MAD_F(0x07cd2c36) /* 0.487590991 */, 18 },
- /* 6761 */ { MAD_F(0x07cd910e) /* 0.487687165 */, 18 },
- /* 6762 */ { MAD_F(0x07cdf5e8) /* 0.487783344 */, 18 },
- /* 6763 */ { MAD_F(0x07ce5ac3) /* 0.487879528 */, 18 },
- /* 6764 */ { MAD_F(0x07cebfa0) /* 0.487975716 */, 18 },
- /* 6765 */ { MAD_F(0x07cf247d) /* 0.488071909 */, 18 },
- /* 6766 */ { MAD_F(0x07cf895c) /* 0.488168107 */, 18 },
- /* 6767 */ { MAD_F(0x07cfee3c) /* 0.488264310 */, 18 },
-
- /* 6768 */ { MAD_F(0x07d0531e) /* 0.488360517 */, 18 },
- /* 6769 */ { MAD_F(0x07d0b801) /* 0.488456729 */, 18 },
- /* 6770 */ { MAD_F(0x07d11ce5) /* 0.488552946 */, 18 },
- /* 6771 */ { MAD_F(0x07d181ca) /* 0.488649167 */, 18 },
- /* 6772 */ { MAD_F(0x07d1e6b0) /* 0.488745394 */, 18 },
- /* 6773 */ { MAD_F(0x07d24b98) /* 0.488841625 */, 18 },
- /* 6774 */ { MAD_F(0x07d2b081) /* 0.488937860 */, 18 },
- /* 6775 */ { MAD_F(0x07d3156c) /* 0.489034101 */, 18 },
- /* 6776 */ { MAD_F(0x07d37a57) /* 0.489130346 */, 18 },
- /* 6777 */ { MAD_F(0x07d3df44) /* 0.489226596 */, 18 },
- /* 6778 */ { MAD_F(0x07d44432) /* 0.489322851 */, 18 },
- /* 6779 */ { MAD_F(0x07d4a922) /* 0.489419110 */, 18 },
- /* 6780 */ { MAD_F(0x07d50e13) /* 0.489515375 */, 18 },
- /* 6781 */ { MAD_F(0x07d57305) /* 0.489611643 */, 18 },
- /* 6782 */ { MAD_F(0x07d5d7f8) /* 0.489707917 */, 18 },
- /* 6783 */ { MAD_F(0x07d63cec) /* 0.489804195 */, 18 },
-
- /* 6784 */ { MAD_F(0x07d6a1e2) /* 0.489900479 */, 18 },
- /* 6785 */ { MAD_F(0x07d706d9) /* 0.489996766 */, 18 },
- /* 6786 */ { MAD_F(0x07d76bd2) /* 0.490093059 */, 18 },
- /* 6787 */ { MAD_F(0x07d7d0cb) /* 0.490189356 */, 18 },
- /* 6788 */ { MAD_F(0x07d835c6) /* 0.490285658 */, 18 },
- /* 6789 */ { MAD_F(0x07d89ac2) /* 0.490381965 */, 18 },
- /* 6790 */ { MAD_F(0x07d8ffc0) /* 0.490478277 */, 18 },
- /* 6791 */ { MAD_F(0x07d964be) /* 0.490574593 */, 18 },
- /* 6792 */ { MAD_F(0x07d9c9be) /* 0.490670914 */, 18 },
- /* 6793 */ { MAD_F(0x07da2ebf) /* 0.490767239 */, 18 },
- /* 6794 */ { MAD_F(0x07da93c2) /* 0.490863570 */, 18 },
- /* 6795 */ { MAD_F(0x07daf8c6) /* 0.490959905 */, 18 },
- /* 6796 */ { MAD_F(0x07db5dcb) /* 0.491056245 */, 18 },
- /* 6797 */ { MAD_F(0x07dbc2d1) /* 0.491152589 */, 18 },
- /* 6798 */ { MAD_F(0x07dc27d9) /* 0.491248939 */, 18 },
- /* 6799 */ { MAD_F(0x07dc8ce1) /* 0.491345293 */, 18 },
-
- /* 6800 */ { MAD_F(0x07dcf1ec) /* 0.491441651 */, 18 },
- /* 6801 */ { MAD_F(0x07dd56f7) /* 0.491538015 */, 18 },
- /* 6802 */ { MAD_F(0x07ddbc04) /* 0.491634383 */, 18 },
- /* 6803 */ { MAD_F(0x07de2111) /* 0.491730756 */, 18 },
- /* 6804 */ { MAD_F(0x07de8621) /* 0.491827134 */, 18 },
- /* 6805 */ { MAD_F(0x07deeb31) /* 0.491923516 */, 18 },
- /* 6806 */ { MAD_F(0x07df5043) /* 0.492019903 */, 18 },
- /* 6807 */ { MAD_F(0x07dfb556) /* 0.492116295 */, 18 },
- /* 6808 */ { MAD_F(0x07e01a6a) /* 0.492212691 */, 18 },
- /* 6809 */ { MAD_F(0x07e07f80) /* 0.492309093 */, 18 },
- /* 6810 */ { MAD_F(0x07e0e496) /* 0.492405499 */, 18 },
- /* 6811 */ { MAD_F(0x07e149ae) /* 0.492501909 */, 18 },
- /* 6812 */ { MAD_F(0x07e1aec8) /* 0.492598325 */, 18 },
- /* 6813 */ { MAD_F(0x07e213e2) /* 0.492694745 */, 18 },
- /* 6814 */ { MAD_F(0x07e278fe) /* 0.492791170 */, 18 },
- /* 6815 */ { MAD_F(0x07e2de1b) /* 0.492887599 */, 18 },
-
- /* 6816 */ { MAD_F(0x07e3433a) /* 0.492984033 */, 18 },
- /* 6817 */ { MAD_F(0x07e3a859) /* 0.493080472 */, 18 },
- /* 6818 */ { MAD_F(0x07e40d7a) /* 0.493176916 */, 18 },
- /* 6819 */ { MAD_F(0x07e4729c) /* 0.493273365 */, 18 },
- /* 6820 */ { MAD_F(0x07e4d7c0) /* 0.493369818 */, 18 },
- /* 6821 */ { MAD_F(0x07e53ce4) /* 0.493466275 */, 18 },
- /* 6822 */ { MAD_F(0x07e5a20a) /* 0.493562738 */, 18 },
- /* 6823 */ { MAD_F(0x07e60732) /* 0.493659205 */, 18 },
- /* 6824 */ { MAD_F(0x07e66c5a) /* 0.493755677 */, 18 },
- /* 6825 */ { MAD_F(0x07e6d184) /* 0.493852154 */, 18 },
- /* 6826 */ { MAD_F(0x07e736af) /* 0.493948635 */, 18 },
- /* 6827 */ { MAD_F(0x07e79bdb) /* 0.494045122 */, 18 },
- /* 6828 */ { MAD_F(0x07e80109) /* 0.494141612 */, 18 },
- /* 6829 */ { MAD_F(0x07e86638) /* 0.494238108 */, 18 },
- /* 6830 */ { MAD_F(0x07e8cb68) /* 0.494334608 */, 18 },
- /* 6831 */ { MAD_F(0x07e93099) /* 0.494431113 */, 18 },
-
- /* 6832 */ { MAD_F(0x07e995cc) /* 0.494527623 */, 18 },
- /* 6833 */ { MAD_F(0x07e9fb00) /* 0.494624137 */, 18 },
- /* 6834 */ { MAD_F(0x07ea6035) /* 0.494720656 */, 18 },
- /* 6835 */ { MAD_F(0x07eac56b) /* 0.494817180 */, 18 },
- /* 6836 */ { MAD_F(0x07eb2aa3) /* 0.494913709 */, 18 },
- /* 6837 */ { MAD_F(0x07eb8fdc) /* 0.495010242 */, 18 },
- /* 6838 */ { MAD_F(0x07ebf516) /* 0.495106780 */, 18 },
- /* 6839 */ { MAD_F(0x07ec5a51) /* 0.495203322 */, 18 },
- /* 6840 */ { MAD_F(0x07ecbf8e) /* 0.495299870 */, 18 },
- /* 6841 */ { MAD_F(0x07ed24cc) /* 0.495396422 */, 18 },
- /* 6842 */ { MAD_F(0x07ed8a0b) /* 0.495492978 */, 18 },
- /* 6843 */ { MAD_F(0x07edef4c) /* 0.495589540 */, 18 },
- /* 6844 */ { MAD_F(0x07ee548e) /* 0.495686106 */, 18 },
- /* 6845 */ { MAD_F(0x07eeb9d1) /* 0.495782677 */, 18 },
- /* 6846 */ { MAD_F(0x07ef1f15) /* 0.495879252 */, 18 },
- /* 6847 */ { MAD_F(0x07ef845b) /* 0.495975833 */, 18 },
-
- /* 6848 */ { MAD_F(0x07efe9a1) /* 0.496072418 */, 18 },
- /* 6849 */ { MAD_F(0x07f04ee9) /* 0.496169007 */, 18 },
- /* 6850 */ { MAD_F(0x07f0b433) /* 0.496265602 */, 18 },
- /* 6851 */ { MAD_F(0x07f1197d) /* 0.496362201 */, 18 },
- /* 6852 */ { MAD_F(0x07f17ec9) /* 0.496458804 */, 18 },
- /* 6853 */ { MAD_F(0x07f1e416) /* 0.496555413 */, 18 },
- /* 6854 */ { MAD_F(0x07f24965) /* 0.496652026 */, 18 },
- /* 6855 */ { MAD_F(0x07f2aeb5) /* 0.496748644 */, 18 },
- /* 6856 */ { MAD_F(0x07f31405) /* 0.496845266 */, 18 },
- /* 6857 */ { MAD_F(0x07f37958) /* 0.496941894 */, 18 },
- /* 6858 */ { MAD_F(0x07f3deab) /* 0.497038526 */, 18 },
- /* 6859 */ { MAD_F(0x07f44400) /* 0.497135162 */, 18 },
- /* 6860 */ { MAD_F(0x07f4a956) /* 0.497231804 */, 18 },
- /* 6861 */ { MAD_F(0x07f50ead) /* 0.497328450 */, 18 },
- /* 6862 */ { MAD_F(0x07f57405) /* 0.497425100 */, 18 },
- /* 6863 */ { MAD_F(0x07f5d95f) /* 0.497521756 */, 18 },
-
- /* 6864 */ { MAD_F(0x07f63eba) /* 0.497618416 */, 18 },
- /* 6865 */ { MAD_F(0x07f6a416) /* 0.497715081 */, 18 },
- /* 6866 */ { MAD_F(0x07f70974) /* 0.497811750 */, 18 },
- /* 6867 */ { MAD_F(0x07f76ed3) /* 0.497908425 */, 18 },
- /* 6868 */ { MAD_F(0x07f7d433) /* 0.498005103 */, 18 },
- /* 6869 */ { MAD_F(0x07f83994) /* 0.498101787 */, 18 },
- /* 6870 */ { MAD_F(0x07f89ef7) /* 0.498198475 */, 18 },
- /* 6871 */ { MAD_F(0x07f9045a) /* 0.498295168 */, 18 },
- /* 6872 */ { MAD_F(0x07f969c0) /* 0.498391866 */, 18 },
- /* 6873 */ { MAD_F(0x07f9cf26) /* 0.498488568 */, 18 },
- /* 6874 */ { MAD_F(0x07fa348e) /* 0.498585275 */, 18 },
- /* 6875 */ { MAD_F(0x07fa99f6) /* 0.498681987 */, 18 },
- /* 6876 */ { MAD_F(0x07faff60) /* 0.498778704 */, 18 },
- /* 6877 */ { MAD_F(0x07fb64cc) /* 0.498875425 */, 18 },
- /* 6878 */ { MAD_F(0x07fbca38) /* 0.498972150 */, 18 },
- /* 6879 */ { MAD_F(0x07fc2fa6) /* 0.499068881 */, 18 },
-
- /* 6880 */ { MAD_F(0x07fc9516) /* 0.499165616 */, 18 },
- /* 6881 */ { MAD_F(0x07fcfa86) /* 0.499262356 */, 18 },
- /* 6882 */ { MAD_F(0x07fd5ff8) /* 0.499359101 */, 18 },
- /* 6883 */ { MAD_F(0x07fdc56b) /* 0.499455850 */, 18 },
- /* 6884 */ { MAD_F(0x07fe2adf) /* 0.499552604 */, 18 },
- /* 6885 */ { MAD_F(0x07fe9054) /* 0.499649362 */, 18 },
- /* 6886 */ { MAD_F(0x07fef5cb) /* 0.499746126 */, 18 },
- /* 6887 */ { MAD_F(0x07ff5b43) /* 0.499842894 */, 18 },
- /* 6888 */ { MAD_F(0x07ffc0bc) /* 0.499939666 */, 18 },
- /* 6889 */ { MAD_F(0x0400131b) /* 0.250018222 */, 19 },
- /* 6890 */ { MAD_F(0x040045d9) /* 0.250066613 */, 19 },
- /* 6891 */ { MAD_F(0x04007897) /* 0.250115006 */, 19 },
- /* 6892 */ { MAD_F(0x0400ab57) /* 0.250163402 */, 19 },
- /* 6893 */ { MAD_F(0x0400de16) /* 0.250211800 */, 19 },
- /* 6894 */ { MAD_F(0x040110d7) /* 0.250260200 */, 19 },
- /* 6895 */ { MAD_F(0x04014398) /* 0.250308603 */, 19 },
-
- /* 6896 */ { MAD_F(0x04017659) /* 0.250357008 */, 19 },
- /* 6897 */ { MAD_F(0x0401a91c) /* 0.250405415 */, 19 },
- /* 6898 */ { MAD_F(0x0401dbdf) /* 0.250453825 */, 19 },
- /* 6899 */ { MAD_F(0x04020ea2) /* 0.250502237 */, 19 },
- /* 6900 */ { MAD_F(0x04024166) /* 0.250550652 */, 19 },
- /* 6901 */ { MAD_F(0x0402742b) /* 0.250599068 */, 19 },
- /* 6902 */ { MAD_F(0x0402a6f0) /* 0.250647488 */, 19 },
- /* 6903 */ { MAD_F(0x0402d9b6) /* 0.250695909 */, 19 },
- /* 6904 */ { MAD_F(0x04030c7d) /* 0.250744333 */, 19 },
- /* 6905 */ { MAD_F(0x04033f44) /* 0.250792759 */, 19 },
- /* 6906 */ { MAD_F(0x0403720c) /* 0.250841187 */, 19 },
- /* 6907 */ { MAD_F(0x0403a4d5) /* 0.250889618 */, 19 },
- /* 6908 */ { MAD_F(0x0403d79e) /* 0.250938051 */, 19 },
- /* 6909 */ { MAD_F(0x04040a68) /* 0.250986487 */, 19 },
- /* 6910 */ { MAD_F(0x04043d32) /* 0.251034924 */, 19 },
- /* 6911 */ { MAD_F(0x04046ffd) /* 0.251083365 */, 19 },
-
- /* 6912 */ { MAD_F(0x0404a2c9) /* 0.251131807 */, 19 },
- /* 6913 */ { MAD_F(0x0404d595) /* 0.251180252 */, 19 },
- /* 6914 */ { MAD_F(0x04050862) /* 0.251228699 */, 19 },
- /* 6915 */ { MAD_F(0x04053b30) /* 0.251277148 */, 19 },
- /* 6916 */ { MAD_F(0x04056dfe) /* 0.251325600 */, 19 },
- /* 6917 */ { MAD_F(0x0405a0cd) /* 0.251374054 */, 19 },
- /* 6918 */ { MAD_F(0x0405d39c) /* 0.251422511 */, 19 },
- /* 6919 */ { MAD_F(0x0406066c) /* 0.251470970 */, 19 },
- /* 6920 */ { MAD_F(0x0406393d) /* 0.251519431 */, 19 },
- /* 6921 */ { MAD_F(0x04066c0e) /* 0.251567894 */, 19 },
- /* 6922 */ { MAD_F(0x04069ee0) /* 0.251616360 */, 19 },
- /* 6923 */ { MAD_F(0x0406d1b3) /* 0.251664828 */, 19 },
- /* 6924 */ { MAD_F(0x04070486) /* 0.251713299 */, 19 },
- /* 6925 */ { MAD_F(0x0407375a) /* 0.251761772 */, 19 },
- /* 6926 */ { MAD_F(0x04076a2e) /* 0.251810247 */, 19 },
- /* 6927 */ { MAD_F(0x04079d03) /* 0.251858724 */, 19 },
-
- /* 6928 */ { MAD_F(0x0407cfd9) /* 0.251907204 */, 19 },
- /* 6929 */ { MAD_F(0x040802af) /* 0.251955686 */, 19 },
- /* 6930 */ { MAD_F(0x04083586) /* 0.252004171 */, 19 },
- /* 6931 */ { MAD_F(0x0408685e) /* 0.252052658 */, 19 },
- /* 6932 */ { MAD_F(0x04089b36) /* 0.252101147 */, 19 },
- /* 6933 */ { MAD_F(0x0408ce0f) /* 0.252149638 */, 19 },
- /* 6934 */ { MAD_F(0x040900e8) /* 0.252198132 */, 19 },
- /* 6935 */ { MAD_F(0x040933c2) /* 0.252246628 */, 19 },
- /* 6936 */ { MAD_F(0x0409669d) /* 0.252295127 */, 19 },
- /* 6937 */ { MAD_F(0x04099978) /* 0.252343627 */, 19 },
- /* 6938 */ { MAD_F(0x0409cc54) /* 0.252392131 */, 19 },
- /* 6939 */ { MAD_F(0x0409ff31) /* 0.252440636 */, 19 },
- /* 6940 */ { MAD_F(0x040a320e) /* 0.252489144 */, 19 },
- /* 6941 */ { MAD_F(0x040a64ec) /* 0.252537654 */, 19 },
- /* 6942 */ { MAD_F(0x040a97cb) /* 0.252586166 */, 19 },
- /* 6943 */ { MAD_F(0x040acaaa) /* 0.252634681 */, 19 },
-
- /* 6944 */ { MAD_F(0x040afd89) /* 0.252683198 */, 19 },
- /* 6945 */ { MAD_F(0x040b306a) /* 0.252731718 */, 19 },
- /* 6946 */ { MAD_F(0x040b634b) /* 0.252780240 */, 19 },
- /* 6947 */ { MAD_F(0x040b962c) /* 0.252828764 */, 19 },
- /* 6948 */ { MAD_F(0x040bc90e) /* 0.252877290 */, 19 },
- /* 6949 */ { MAD_F(0x040bfbf1) /* 0.252925819 */, 19 },
- /* 6950 */ { MAD_F(0x040c2ed5) /* 0.252974350 */, 19 },
- /* 6951 */ { MAD_F(0x040c61b9) /* 0.253022883 */, 19 },
- /* 6952 */ { MAD_F(0x040c949e) /* 0.253071419 */, 19 },
- /* 6953 */ { MAD_F(0x040cc783) /* 0.253119957 */, 19 },
- /* 6954 */ { MAD_F(0x040cfa69) /* 0.253168498 */, 19 },
- /* 6955 */ { MAD_F(0x040d2d4f) /* 0.253217040 */, 19 },
- /* 6956 */ { MAD_F(0x040d6037) /* 0.253265585 */, 19 },
- /* 6957 */ { MAD_F(0x040d931e) /* 0.253314133 */, 19 },
- /* 6958 */ { MAD_F(0x040dc607) /* 0.253362682 */, 19 },
- /* 6959 */ { MAD_F(0x040df8f0) /* 0.253411234 */, 19 },
-
- /* 6960 */ { MAD_F(0x040e2bda) /* 0.253459789 */, 19 },
- /* 6961 */ { MAD_F(0x040e5ec4) /* 0.253508345 */, 19 },
- /* 6962 */ { MAD_F(0x040e91af) /* 0.253556904 */, 19 },
- /* 6963 */ { MAD_F(0x040ec49b) /* 0.253605466 */, 19 },
- /* 6964 */ { MAD_F(0x040ef787) /* 0.253654029 */, 19 },
- /* 6965 */ { MAD_F(0x040f2a74) /* 0.253702595 */, 19 },
- /* 6966 */ { MAD_F(0x040f5d61) /* 0.253751164 */, 19 },
- /* 6967 */ { MAD_F(0x040f904f) /* 0.253799734 */, 19 },
- /* 6968 */ { MAD_F(0x040fc33e) /* 0.253848307 */, 19 },
- /* 6969 */ { MAD_F(0x040ff62d) /* 0.253896883 */, 19 },
- /* 6970 */ { MAD_F(0x0410291d) /* 0.253945460 */, 19 },
- /* 6971 */ { MAD_F(0x04105c0e) /* 0.253994040 */, 19 },
- /* 6972 */ { MAD_F(0x04108eff) /* 0.254042622 */, 19 },
- /* 6973 */ { MAD_F(0x0410c1f1) /* 0.254091207 */, 19 },
- /* 6974 */ { MAD_F(0x0410f4e3) /* 0.254139794 */, 19 },
- /* 6975 */ { MAD_F(0x041127d6) /* 0.254188383 */, 19 },
-
- /* 6976 */ { MAD_F(0x04115aca) /* 0.254236974 */, 19 },
- /* 6977 */ { MAD_F(0x04118dbe) /* 0.254285568 */, 19 },
- /* 6978 */ { MAD_F(0x0411c0b3) /* 0.254334165 */, 19 },
- /* 6979 */ { MAD_F(0x0411f3a9) /* 0.254382763 */, 19 },
- /* 6980 */ { MAD_F(0x0412269f) /* 0.254431364 */, 19 },
- /* 6981 */ { MAD_F(0x04125996) /* 0.254479967 */, 19 },
- /* 6982 */ { MAD_F(0x04128c8d) /* 0.254528572 */, 19 },
- /* 6983 */ { MAD_F(0x0412bf85) /* 0.254577180 */, 19 },
- /* 6984 */ { MAD_F(0x0412f27e) /* 0.254625790 */, 19 },
- /* 6985 */ { MAD_F(0x04132577) /* 0.254674403 */, 19 },
- /* 6986 */ { MAD_F(0x04135871) /* 0.254723017 */, 19 },
- /* 6987 */ { MAD_F(0x04138b6c) /* 0.254771635 */, 19 },
- /* 6988 */ { MAD_F(0x0413be67) /* 0.254820254 */, 19 },
- /* 6989 */ { MAD_F(0x0413f163) /* 0.254868876 */, 19 },
- /* 6990 */ { MAD_F(0x0414245f) /* 0.254917500 */, 19 },
- /* 6991 */ { MAD_F(0x0414575c) /* 0.254966126 */, 19 },
-
- /* 6992 */ { MAD_F(0x04148a5a) /* 0.255014755 */, 19 },
- /* 6993 */ { MAD_F(0x0414bd58) /* 0.255063386 */, 19 },
- /* 6994 */ { MAD_F(0x0414f057) /* 0.255112019 */, 19 },
- /* 6995 */ { MAD_F(0x04152356) /* 0.255160655 */, 19 },
- /* 6996 */ { MAD_F(0x04155657) /* 0.255209292 */, 19 },
- /* 6997 */ { MAD_F(0x04158957) /* 0.255257933 */, 19 },
- /* 6998 */ { MAD_F(0x0415bc59) /* 0.255306575 */, 19 },
- /* 6999 */ { MAD_F(0x0415ef5b) /* 0.255355220 */, 19 },
- /* 7000 */ { MAD_F(0x0416225d) /* 0.255403867 */, 19 },
- /* 7001 */ { MAD_F(0x04165561) /* 0.255452517 */, 19 },
- /* 7002 */ { MAD_F(0x04168864) /* 0.255501169 */, 19 },
- /* 7003 */ { MAD_F(0x0416bb69) /* 0.255549823 */, 19 },
- /* 7004 */ { MAD_F(0x0416ee6e) /* 0.255598479 */, 19 },
- /* 7005 */ { MAD_F(0x04172174) /* 0.255647138 */, 19 },
- /* 7006 */ { MAD_F(0x0417547a) /* 0.255695799 */, 19 },
- /* 7007 */ { MAD_F(0x04178781) /* 0.255744463 */, 19 },
-
- /* 7008 */ { MAD_F(0x0417ba89) /* 0.255793128 */, 19 },
- /* 7009 */ { MAD_F(0x0417ed91) /* 0.255841796 */, 19 },
- /* 7010 */ { MAD_F(0x0418209a) /* 0.255890467 */, 19 },
- /* 7011 */ { MAD_F(0x041853a3) /* 0.255939139 */, 19 },
- /* 7012 */ { MAD_F(0x041886ad) /* 0.255987814 */, 19 },
- /* 7013 */ { MAD_F(0x0418b9b8) /* 0.256036492 */, 19 },
- /* 7014 */ { MAD_F(0x0418ecc3) /* 0.256085171 */, 19 },
- /* 7015 */ { MAD_F(0x04191fcf) /* 0.256133853 */, 19 },
- /* 7016 */ { MAD_F(0x041952dc) /* 0.256182537 */, 19 },
- /* 7017 */ { MAD_F(0x041985e9) /* 0.256231224 */, 19 },
- /* 7018 */ { MAD_F(0x0419b8f7) /* 0.256279913 */, 19 },
- /* 7019 */ { MAD_F(0x0419ec05) /* 0.256328604 */, 19 },
- /* 7020 */ { MAD_F(0x041a1f15) /* 0.256377297 */, 19 },
- /* 7021 */ { MAD_F(0x041a5224) /* 0.256425993 */, 19 },
- /* 7022 */ { MAD_F(0x041a8534) /* 0.256474691 */, 19 },
- /* 7023 */ { MAD_F(0x041ab845) /* 0.256523392 */, 19 },
-
- /* 7024 */ { MAD_F(0x041aeb57) /* 0.256572095 */, 19 },
- /* 7025 */ { MAD_F(0x041b1e69) /* 0.256620800 */, 19 },
- /* 7026 */ { MAD_F(0x041b517c) /* 0.256669507 */, 19 },
- /* 7027 */ { MAD_F(0x041b848f) /* 0.256718217 */, 19 },
- /* 7028 */ { MAD_F(0x041bb7a3) /* 0.256766929 */, 19 },
- /* 7029 */ { MAD_F(0x041beab8) /* 0.256815643 */, 19 },
- /* 7030 */ { MAD_F(0x041c1dcd) /* 0.256864359 */, 19 },
- /* 7031 */ { MAD_F(0x041c50e3) /* 0.256913078 */, 19 },
- /* 7032 */ { MAD_F(0x041c83fa) /* 0.256961800 */, 19 },
- /* 7033 */ { MAD_F(0x041cb711) /* 0.257010523 */, 19 },
- /* 7034 */ { MAD_F(0x041cea28) /* 0.257059249 */, 19 },
- /* 7035 */ { MAD_F(0x041d1d41) /* 0.257107977 */, 19 },
- /* 7036 */ { MAD_F(0x041d505a) /* 0.257156708 */, 19 },
- /* 7037 */ { MAD_F(0x041d8373) /* 0.257205440 */, 19 },
- /* 7038 */ { MAD_F(0x041db68e) /* 0.257254175 */, 19 },
- /* 7039 */ { MAD_F(0x041de9a8) /* 0.257302913 */, 19 },
-
- /* 7040 */ { MAD_F(0x041e1cc4) /* 0.257351652 */, 19 },
- /* 7041 */ { MAD_F(0x041e4fe0) /* 0.257400394 */, 19 },
- /* 7042 */ { MAD_F(0x041e82fd) /* 0.257449139 */, 19 },
- /* 7043 */ { MAD_F(0x041eb61a) /* 0.257497885 */, 19 },
- /* 7044 */ { MAD_F(0x041ee938) /* 0.257546634 */, 19 },
- /* 7045 */ { MAD_F(0x041f1c57) /* 0.257595386 */, 19 },
- /* 7046 */ { MAD_F(0x041f4f76) /* 0.257644139 */, 19 },
- /* 7047 */ { MAD_F(0x041f8296) /* 0.257692895 */, 19 },
- /* 7048 */ { MAD_F(0x041fb5b6) /* 0.257741653 */, 19 },
- /* 7049 */ { MAD_F(0x041fe8d7) /* 0.257790414 */, 19 },
- /* 7050 */ { MAD_F(0x04201bf9) /* 0.257839176 */, 19 },
- /* 7051 */ { MAD_F(0x04204f1b) /* 0.257887941 */, 19 },
- /* 7052 */ { MAD_F(0x0420823e) /* 0.257936709 */, 19 },
- /* 7053 */ { MAD_F(0x0420b561) /* 0.257985478 */, 19 },
- /* 7054 */ { MAD_F(0x0420e885) /* 0.258034250 */, 19 },
- /* 7055 */ { MAD_F(0x04211baa) /* 0.258083025 */, 19 },
-
- /* 7056 */ { MAD_F(0x04214ed0) /* 0.258131801 */, 19 },
- /* 7057 */ { MAD_F(0x042181f6) /* 0.258180580 */, 19 },
- /* 7058 */ { MAD_F(0x0421b51c) /* 0.258229361 */, 19 },
- /* 7059 */ { MAD_F(0x0421e843) /* 0.258278145 */, 19 },
- /* 7060 */ { MAD_F(0x04221b6b) /* 0.258326931 */, 19 },
- /* 7061 */ { MAD_F(0x04224e94) /* 0.258375719 */, 19 },
- /* 7062 */ { MAD_F(0x042281bd) /* 0.258424509 */, 19 },
- /* 7063 */ { MAD_F(0x0422b4e6) /* 0.258473302 */, 19 },
- /* 7064 */ { MAD_F(0x0422e811) /* 0.258522097 */, 19 },
- /* 7065 */ { MAD_F(0x04231b3c) /* 0.258570894 */, 19 },
- /* 7066 */ { MAD_F(0x04234e67) /* 0.258619694 */, 19 },
- /* 7067 */ { MAD_F(0x04238193) /* 0.258668496 */, 19 },
- /* 7068 */ { MAD_F(0x0423b4c0) /* 0.258717300 */, 19 },
- /* 7069 */ { MAD_F(0x0423e7ee) /* 0.258766106 */, 19 },
- /* 7070 */ { MAD_F(0x04241b1c) /* 0.258814915 */, 19 },
- /* 7071 */ { MAD_F(0x04244e4a) /* 0.258863726 */, 19 },
-
- /* 7072 */ { MAD_F(0x04248179) /* 0.258912540 */, 19 },
- /* 7073 */ { MAD_F(0x0424b4a9) /* 0.258961356 */, 19 },
- /* 7074 */ { MAD_F(0x0424e7da) /* 0.259010174 */, 19 },
- /* 7075 */ { MAD_F(0x04251b0b) /* 0.259058994 */, 19 },
- /* 7076 */ { MAD_F(0x04254e3d) /* 0.259107817 */, 19 },
- /* 7077 */ { MAD_F(0x0425816f) /* 0.259156642 */, 19 },
- /* 7078 */ { MAD_F(0x0425b4a2) /* 0.259205469 */, 19 },
- /* 7079 */ { MAD_F(0x0425e7d6) /* 0.259254298 */, 19 },
- /* 7080 */ { MAD_F(0x04261b0a) /* 0.259303130 */, 19 },
- /* 7081 */ { MAD_F(0x04264e3f) /* 0.259351964 */, 19 },
- /* 7082 */ { MAD_F(0x04268174) /* 0.259400801 */, 19 },
- /* 7083 */ { MAD_F(0x0426b4aa) /* 0.259449639 */, 19 },
- /* 7084 */ { MAD_F(0x0426e7e1) /* 0.259498480 */, 19 },
- /* 7085 */ { MAD_F(0x04271b18) /* 0.259547324 */, 19 },
- /* 7086 */ { MAD_F(0x04274e50) /* 0.259596169 */, 19 },
- /* 7087 */ { MAD_F(0x04278188) /* 0.259645017 */, 19 },
-
- /* 7088 */ { MAD_F(0x0427b4c2) /* 0.259693868 */, 19 },
- /* 7089 */ { MAD_F(0x0427e7fb) /* 0.259742720 */, 19 },
- /* 7090 */ { MAD_F(0x04281b36) /* 0.259791575 */, 19 },
- /* 7091 */ { MAD_F(0x04284e71) /* 0.259840432 */, 19 },
- /* 7092 */ { MAD_F(0x042881ac) /* 0.259889291 */, 19 },
- /* 7093 */ { MAD_F(0x0428b4e8) /* 0.259938153 */, 19 },
- /* 7094 */ { MAD_F(0x0428e825) /* 0.259987017 */, 19 },
- /* 7095 */ { MAD_F(0x04291b63) /* 0.260035883 */, 19 },
- /* 7096 */ { MAD_F(0x04294ea1) /* 0.260084752 */, 19 },
- /* 7097 */ { MAD_F(0x042981df) /* 0.260133623 */, 19 },
- /* 7098 */ { MAD_F(0x0429b51f) /* 0.260182496 */, 19 },
- /* 7099 */ { MAD_F(0x0429e85f) /* 0.260231372 */, 19 },
- /* 7100 */ { MAD_F(0x042a1b9f) /* 0.260280249 */, 19 },
- /* 7101 */ { MAD_F(0x042a4ee0) /* 0.260329129 */, 19 },
- /* 7102 */ { MAD_F(0x042a8222) /* 0.260378012 */, 19 },
- /* 7103 */ { MAD_F(0x042ab564) /* 0.260426896 */, 19 },
-
- /* 7104 */ { MAD_F(0x042ae8a7) /* 0.260475783 */, 19 },
- /* 7105 */ { MAD_F(0x042b1beb) /* 0.260524673 */, 19 },
- /* 7106 */ { MAD_F(0x042b4f2f) /* 0.260573564 */, 19 },
- /* 7107 */ { MAD_F(0x042b8274) /* 0.260622458 */, 19 },
- /* 7108 */ { MAD_F(0x042bb5ba) /* 0.260671354 */, 19 },
- /* 7109 */ { MAD_F(0x042be900) /* 0.260720252 */, 19 },
- /* 7110 */ { MAD_F(0x042c1c46) /* 0.260769153 */, 19 },
- /* 7111 */ { MAD_F(0x042c4f8e) /* 0.260818056 */, 19 },
- /* 7112 */ { MAD_F(0x042c82d6) /* 0.260866961 */, 19 },
- /* 7113 */ { MAD_F(0x042cb61e) /* 0.260915869 */, 19 },
- /* 7114 */ { MAD_F(0x042ce967) /* 0.260964779 */, 19 },
- /* 7115 */ { MAD_F(0x042d1cb1) /* 0.261013691 */, 19 },
- /* 7116 */ { MAD_F(0x042d4ffb) /* 0.261062606 */, 19 },
- /* 7117 */ { MAD_F(0x042d8346) /* 0.261111522 */, 19 },
- /* 7118 */ { MAD_F(0x042db692) /* 0.261160441 */, 19 },
- /* 7119 */ { MAD_F(0x042de9de) /* 0.261209363 */, 19 },
-
- /* 7120 */ { MAD_F(0x042e1d2b) /* 0.261258286 */, 19 },
- /* 7121 */ { MAD_F(0x042e5078) /* 0.261307212 */, 19 },
- /* 7122 */ { MAD_F(0x042e83c6) /* 0.261356140 */, 19 },
- /* 7123 */ { MAD_F(0x042eb715) /* 0.261405071 */, 19 },
- /* 7124 */ { MAD_F(0x042eea64) /* 0.261454004 */, 19 },
- /* 7125 */ { MAD_F(0x042f1db4) /* 0.261502939 */, 19 },
- /* 7126 */ { MAD_F(0x042f5105) /* 0.261551876 */, 19 },
- /* 7127 */ { MAD_F(0x042f8456) /* 0.261600816 */, 19 },
- /* 7128 */ { MAD_F(0x042fb7a8) /* 0.261649758 */, 19 },
- /* 7129 */ { MAD_F(0x042feafa) /* 0.261698702 */, 19 },
- /* 7130 */ { MAD_F(0x04301e4d) /* 0.261747649 */, 19 },
- /* 7131 */ { MAD_F(0x043051a1) /* 0.261796597 */, 19 },
- /* 7132 */ { MAD_F(0x043084f5) /* 0.261845548 */, 19 },
- /* 7133 */ { MAD_F(0x0430b84a) /* 0.261894502 */, 19 },
- /* 7134 */ { MAD_F(0x0430eb9f) /* 0.261943458 */, 19 },
- /* 7135 */ { MAD_F(0x04311ef5) /* 0.261992416 */, 19 },
-
- /* 7136 */ { MAD_F(0x0431524c) /* 0.262041376 */, 19 },
- /* 7137 */ { MAD_F(0x043185a3) /* 0.262090338 */, 19 },
- /* 7138 */ { MAD_F(0x0431b8fb) /* 0.262139303 */, 19 },
- /* 7139 */ { MAD_F(0x0431ec54) /* 0.262188270 */, 19 },
- /* 7140 */ { MAD_F(0x04321fad) /* 0.262237240 */, 19 },
- /* 7141 */ { MAD_F(0x04325306) /* 0.262286211 */, 19 },
- /* 7142 */ { MAD_F(0x04328661) /* 0.262335185 */, 19 },
- /* 7143 */ { MAD_F(0x0432b9bc) /* 0.262384162 */, 19 },
- /* 7144 */ { MAD_F(0x0432ed17) /* 0.262433140 */, 19 },
- /* 7145 */ { MAD_F(0x04332074) /* 0.262482121 */, 19 },
- /* 7146 */ { MAD_F(0x043353d0) /* 0.262531104 */, 19 },
- /* 7147 */ { MAD_F(0x0433872e) /* 0.262580089 */, 19 },
- /* 7148 */ { MAD_F(0x0433ba8c) /* 0.262629077 */, 19 },
- /* 7149 */ { MAD_F(0x0433edea) /* 0.262678067 */, 19 },
- /* 7150 */ { MAD_F(0x0434214a) /* 0.262727059 */, 19 },
- /* 7151 */ { MAD_F(0x043454aa) /* 0.262776054 */, 19 },
-
- /* 7152 */ { MAD_F(0x0434880a) /* 0.262825051 */, 19 },
- /* 7153 */ { MAD_F(0x0434bb6b) /* 0.262874050 */, 19 },
- /* 7154 */ { MAD_F(0x0434eecd) /* 0.262923051 */, 19 },
- /* 7155 */ { MAD_F(0x0435222f) /* 0.262972055 */, 19 },
- /* 7156 */ { MAD_F(0x04355592) /* 0.263021061 */, 19 },
- /* 7157 */ { MAD_F(0x043588f6) /* 0.263070069 */, 19 },
- /* 7158 */ { MAD_F(0x0435bc5a) /* 0.263119079 */, 19 },
- /* 7159 */ { MAD_F(0x0435efbf) /* 0.263168092 */, 19 },
- /* 7160 */ { MAD_F(0x04362324) /* 0.263217107 */, 19 },
- /* 7161 */ { MAD_F(0x0436568a) /* 0.263266125 */, 19 },
- /* 7162 */ { MAD_F(0x043689f1) /* 0.263315144 */, 19 },
- /* 7163 */ { MAD_F(0x0436bd58) /* 0.263364166 */, 19 },
- /* 7164 */ { MAD_F(0x0436f0c0) /* 0.263413191 */, 19 },
- /* 7165 */ { MAD_F(0x04372428) /* 0.263462217 */, 19 },
- /* 7166 */ { MAD_F(0x04375791) /* 0.263511246 */, 19 },
- /* 7167 */ { MAD_F(0x04378afb) /* 0.263560277 */, 19 },
-
- /* 7168 */ { MAD_F(0x0437be65) /* 0.263609310 */, 19 },
- /* 7169 */ { MAD_F(0x0437f1d0) /* 0.263658346 */, 19 },
- /* 7170 */ { MAD_F(0x0438253c) /* 0.263707384 */, 19 },
- /* 7171 */ { MAD_F(0x043858a8) /* 0.263756424 */, 19 },
- /* 7172 */ { MAD_F(0x04388c14) /* 0.263805466 */, 19 },
- /* 7173 */ { MAD_F(0x0438bf82) /* 0.263854511 */, 19 },
- /* 7174 */ { MAD_F(0x0438f2f0) /* 0.263903558 */, 19 },
- /* 7175 */ { MAD_F(0x0439265e) /* 0.263952607 */, 19 },
- /* 7176 */ { MAD_F(0x043959cd) /* 0.264001659 */, 19 },
- /* 7177 */ { MAD_F(0x04398d3d) /* 0.264050713 */, 19 },
- /* 7178 */ { MAD_F(0x0439c0ae) /* 0.264099769 */, 19 },
- /* 7179 */ { MAD_F(0x0439f41f) /* 0.264148827 */, 19 },
- /* 7180 */ { MAD_F(0x043a2790) /* 0.264197888 */, 19 },
- /* 7181 */ { MAD_F(0x043a5b02) /* 0.264246951 */, 19 },
- /* 7182 */ { MAD_F(0x043a8e75) /* 0.264296016 */, 19 },
- /* 7183 */ { MAD_F(0x043ac1e9) /* 0.264345084 */, 19 },
-
- /* 7184 */ { MAD_F(0x043af55d) /* 0.264394153 */, 19 },
- /* 7185 */ { MAD_F(0x043b28d2) /* 0.264443225 */, 19 },
- /* 7186 */ { MAD_F(0x043b5c47) /* 0.264492300 */, 19 },
- /* 7187 */ { MAD_F(0x043b8fbd) /* 0.264541376 */, 19 },
- /* 7188 */ { MAD_F(0x043bc333) /* 0.264590455 */, 19 },
- /* 7189 */ { MAD_F(0x043bf6aa) /* 0.264639536 */, 19 },
- /* 7190 */ { MAD_F(0x043c2a22) /* 0.264688620 */, 19 },
- /* 7191 */ { MAD_F(0x043c5d9a) /* 0.264737706 */, 19 },
- /* 7192 */ { MAD_F(0x043c9113) /* 0.264786794 */, 19 },
- /* 7193 */ { MAD_F(0x043cc48d) /* 0.264835884 */, 19 },
- /* 7194 */ { MAD_F(0x043cf807) /* 0.264884976 */, 19 },
- /* 7195 */ { MAD_F(0x043d2b82) /* 0.264934071 */, 19 },
- /* 7196 */ { MAD_F(0x043d5efd) /* 0.264983168 */, 19 },
- /* 7197 */ { MAD_F(0x043d9279) /* 0.265032268 */, 19 },
- /* 7198 */ { MAD_F(0x043dc5f6) /* 0.265081369 */, 19 },
- /* 7199 */ { MAD_F(0x043df973) /* 0.265130473 */, 19 },
-
- /* 7200 */ { MAD_F(0x043e2cf1) /* 0.265179580 */, 19 },
- /* 7201 */ { MAD_F(0x043e6070) /* 0.265228688 */, 19 },
- /* 7202 */ { MAD_F(0x043e93ef) /* 0.265277799 */, 19 },
- /* 7203 */ { MAD_F(0x043ec76e) /* 0.265326912 */, 19 },
- /* 7204 */ { MAD_F(0x043efaef) /* 0.265376027 */, 19 },
- /* 7205 */ { MAD_F(0x043f2e6f) /* 0.265425145 */, 19 },
- /* 7206 */ { MAD_F(0x043f61f1) /* 0.265474264 */, 19 },
- /* 7207 */ { MAD_F(0x043f9573) /* 0.265523387 */, 19 },
- /* 7208 */ { MAD_F(0x043fc8f6) /* 0.265572511 */, 19 },
- /* 7209 */ { MAD_F(0x043ffc79) /* 0.265621638 */, 19 },
- /* 7210 */ { MAD_F(0x04402ffd) /* 0.265670766 */, 19 },
- /* 7211 */ { MAD_F(0x04406382) /* 0.265719898 */, 19 },
- /* 7212 */ { MAD_F(0x04409707) /* 0.265769031 */, 19 },
- /* 7213 */ { MAD_F(0x0440ca8d) /* 0.265818167 */, 19 },
- /* 7214 */ { MAD_F(0x0440fe13) /* 0.265867305 */, 19 },
- /* 7215 */ { MAD_F(0x0441319a) /* 0.265916445 */, 19 },
-
- /* 7216 */ { MAD_F(0x04416522) /* 0.265965588 */, 19 },
- /* 7217 */ { MAD_F(0x044198aa) /* 0.266014732 */, 19 },
- /* 7218 */ { MAD_F(0x0441cc33) /* 0.266063880 */, 19 },
- /* 7219 */ { MAD_F(0x0441ffbc) /* 0.266113029 */, 19 },
- /* 7220 */ { MAD_F(0x04423346) /* 0.266162181 */, 19 },
- /* 7221 */ { MAD_F(0x044266d1) /* 0.266211334 */, 19 },
- /* 7222 */ { MAD_F(0x04429a5c) /* 0.266260491 */, 19 },
- /* 7223 */ { MAD_F(0x0442cde8) /* 0.266309649 */, 19 },
- /* 7224 */ { MAD_F(0x04430174) /* 0.266358810 */, 19 },
- /* 7225 */ { MAD_F(0x04433501) /* 0.266407973 */, 19 },
- /* 7226 */ { MAD_F(0x0443688f) /* 0.266457138 */, 19 },
- /* 7227 */ { MAD_F(0x04439c1d) /* 0.266506305 */, 19 },
- /* 7228 */ { MAD_F(0x0443cfac) /* 0.266555475 */, 19 },
- /* 7229 */ { MAD_F(0x0444033c) /* 0.266604647 */, 19 },
- /* 7230 */ { MAD_F(0x044436cc) /* 0.266653822 */, 19 },
- /* 7231 */ { MAD_F(0x04446a5d) /* 0.266702998 */, 19 },
-
- /* 7232 */ { MAD_F(0x04449dee) /* 0.266752177 */, 19 },
- /* 7233 */ { MAD_F(0x0444d180) /* 0.266801358 */, 19 },
- /* 7234 */ { MAD_F(0x04450513) /* 0.266850541 */, 19 },
- /* 7235 */ { MAD_F(0x044538a6) /* 0.266899727 */, 19 },
- /* 7236 */ { MAD_F(0x04456c39) /* 0.266948915 */, 19 },
- /* 7237 */ { MAD_F(0x04459fce) /* 0.266998105 */, 19 },
- /* 7238 */ { MAD_F(0x0445d363) /* 0.267047298 */, 19 },
- /* 7239 */ { MAD_F(0x044606f8) /* 0.267096492 */, 19 },
- /* 7240 */ { MAD_F(0x04463a8f) /* 0.267145689 */, 19 },
- /* 7241 */ { MAD_F(0x04466e25) /* 0.267194888 */, 19 },
- /* 7242 */ { MAD_F(0x0446a1bd) /* 0.267244090 */, 19 },
- /* 7243 */ { MAD_F(0x0446d555) /* 0.267293294 */, 19 },
- /* 7244 */ { MAD_F(0x044708ee) /* 0.267342500 */, 19 },
- /* 7245 */ { MAD_F(0x04473c87) /* 0.267391708 */, 19 },
- /* 7246 */ { MAD_F(0x04477021) /* 0.267440919 */, 19 },
- /* 7247 */ { MAD_F(0x0447a3bb) /* 0.267490131 */, 19 },
-
- /* 7248 */ { MAD_F(0x0447d756) /* 0.267539347 */, 19 },
- /* 7249 */ { MAD_F(0x04480af2) /* 0.267588564 */, 19 },
- /* 7250 */ { MAD_F(0x04483e8e) /* 0.267637783 */, 19 },
- /* 7251 */ { MAD_F(0x0448722b) /* 0.267687005 */, 19 },
- /* 7252 */ { MAD_F(0x0448a5c9) /* 0.267736229 */, 19 },
- /* 7253 */ { MAD_F(0x0448d967) /* 0.267785456 */, 19 },
- /* 7254 */ { MAD_F(0x04490d05) /* 0.267834685 */, 19 },
- /* 7255 */ { MAD_F(0x044940a5) /* 0.267883915 */, 19 },
- /* 7256 */ { MAD_F(0x04497445) /* 0.267933149 */, 19 },
- /* 7257 */ { MAD_F(0x0449a7e5) /* 0.267982384 */, 19 },
- /* 7258 */ { MAD_F(0x0449db86) /* 0.268031622 */, 19 },
- /* 7259 */ { MAD_F(0x044a0f28) /* 0.268080862 */, 19 },
- /* 7260 */ { MAD_F(0x044a42ca) /* 0.268130104 */, 19 },
- /* 7261 */ { MAD_F(0x044a766d) /* 0.268179349 */, 19 },
- /* 7262 */ { MAD_F(0x044aaa11) /* 0.268228595 */, 19 },
- /* 7263 */ { MAD_F(0x044addb5) /* 0.268277844 */, 19 },
-
- /* 7264 */ { MAD_F(0x044b115a) /* 0.268327096 */, 19 },
- /* 7265 */ { MAD_F(0x044b44ff) /* 0.268376349 */, 19 },
- /* 7266 */ { MAD_F(0x044b78a5) /* 0.268425605 */, 19 },
- /* 7267 */ { MAD_F(0x044bac4c) /* 0.268474863 */, 19 },
- /* 7268 */ { MAD_F(0x044bdff3) /* 0.268524123 */, 19 },
- /* 7269 */ { MAD_F(0x044c139b) /* 0.268573386 */, 19 },
- /* 7270 */ { MAD_F(0x044c4743) /* 0.268622651 */, 19 },
- /* 7271 */ { MAD_F(0x044c7aec) /* 0.268671918 */, 19 },
- /* 7272 */ { MAD_F(0x044cae96) /* 0.268721187 */, 19 },
- /* 7273 */ { MAD_F(0x044ce240) /* 0.268770459 */, 19 },
- /* 7274 */ { MAD_F(0x044d15eb) /* 0.268819733 */, 19 },
- /* 7275 */ { MAD_F(0x044d4997) /* 0.268869009 */, 19 },
- /* 7276 */ { MAD_F(0x044d7d43) /* 0.268918287 */, 19 },
- /* 7277 */ { MAD_F(0x044db0ef) /* 0.268967568 */, 19 },
- /* 7278 */ { MAD_F(0x044de49d) /* 0.269016851 */, 19 },
- /* 7279 */ { MAD_F(0x044e184b) /* 0.269066136 */, 19 },
-
- /* 7280 */ { MAD_F(0x044e4bf9) /* 0.269115423 */, 19 },
- /* 7281 */ { MAD_F(0x044e7fa8) /* 0.269164713 */, 19 },
- /* 7282 */ { MAD_F(0x044eb358) /* 0.269214005 */, 19 },
- /* 7283 */ { MAD_F(0x044ee708) /* 0.269263299 */, 19 },
- /* 7284 */ { MAD_F(0x044f1ab9) /* 0.269312595 */, 19 },
- /* 7285 */ { MAD_F(0x044f4e6b) /* 0.269361894 */, 19 },
- /* 7286 */ { MAD_F(0x044f821d) /* 0.269411195 */, 19 },
- /* 7287 */ { MAD_F(0x044fb5cf) /* 0.269460498 */, 19 },
- /* 7288 */ { MAD_F(0x044fe983) /* 0.269509804 */, 19 },
- /* 7289 */ { MAD_F(0x04501d37) /* 0.269559111 */, 19 },
- /* 7290 */ { MAD_F(0x045050eb) /* 0.269608421 */, 19 },
- /* 7291 */ { MAD_F(0x045084a0) /* 0.269657734 */, 19 },
- /* 7292 */ { MAD_F(0x0450b856) /* 0.269707048 */, 19 },
- /* 7293 */ { MAD_F(0x0450ec0d) /* 0.269756365 */, 19 },
- /* 7294 */ { MAD_F(0x04511fc4) /* 0.269805684 */, 19 },
- /* 7295 */ { MAD_F(0x0451537b) /* 0.269855005 */, 19 },
-
- /* 7296 */ { MAD_F(0x04518733) /* 0.269904329 */, 19 },
- /* 7297 */ { MAD_F(0x0451baec) /* 0.269953654 */, 19 },
- /* 7298 */ { MAD_F(0x0451eea5) /* 0.270002982 */, 19 },
- /* 7299 */ { MAD_F(0x0452225f) /* 0.270052313 */, 19 },
- /* 7300 */ { MAD_F(0x0452561a) /* 0.270101645 */, 19 },
- /* 7301 */ { MAD_F(0x045289d5) /* 0.270150980 */, 19 },
- /* 7302 */ { MAD_F(0x0452bd91) /* 0.270200317 */, 19 },
- /* 7303 */ { MAD_F(0x0452f14d) /* 0.270249656 */, 19 },
- /* 7304 */ { MAD_F(0x0453250a) /* 0.270298998 */, 19 },
- /* 7305 */ { MAD_F(0x045358c8) /* 0.270348341 */, 19 },
- /* 7306 */ { MAD_F(0x04538c86) /* 0.270397687 */, 19 },
- /* 7307 */ { MAD_F(0x0453c045) /* 0.270447036 */, 19 },
- /* 7308 */ { MAD_F(0x0453f405) /* 0.270496386 */, 19 },
- /* 7309 */ { MAD_F(0x045427c5) /* 0.270545739 */, 19 },
- /* 7310 */ { MAD_F(0x04545b85) /* 0.270595094 */, 19 },
- /* 7311 */ { MAD_F(0x04548f46) /* 0.270644451 */, 19 },
-
- /* 7312 */ { MAD_F(0x0454c308) /* 0.270693811 */, 19 },
- /* 7313 */ { MAD_F(0x0454f6cb) /* 0.270743173 */, 19 },
- /* 7314 */ { MAD_F(0x04552a8e) /* 0.270792537 */, 19 },
- /* 7315 */ { MAD_F(0x04555e51) /* 0.270841903 */, 19 },
- /* 7316 */ { MAD_F(0x04559216) /* 0.270891271 */, 19 },
- /* 7317 */ { MAD_F(0x0455c5db) /* 0.270940642 */, 19 },
- /* 7318 */ { MAD_F(0x0455f9a0) /* 0.270990015 */, 19 },
- /* 7319 */ { MAD_F(0x04562d66) /* 0.271039390 */, 19 },
- /* 7320 */ { MAD_F(0x0456612d) /* 0.271088768 */, 19 },
- /* 7321 */ { MAD_F(0x045694f4) /* 0.271138148 */, 19 },
- /* 7322 */ { MAD_F(0x0456c8bc) /* 0.271187530 */, 19 },
- /* 7323 */ { MAD_F(0x0456fc84) /* 0.271236914 */, 19 },
- /* 7324 */ { MAD_F(0x0457304e) /* 0.271286301 */, 19 },
- /* 7325 */ { MAD_F(0x04576417) /* 0.271335689 */, 19 },
- /* 7326 */ { MAD_F(0x045797e2) /* 0.271385080 */, 19 },
- /* 7327 */ { MAD_F(0x0457cbac) /* 0.271434474 */, 19 },
-
- /* 7328 */ { MAD_F(0x0457ff78) /* 0.271483869 */, 19 },
- /* 7329 */ { MAD_F(0x04583344) /* 0.271533267 */, 19 },
- /* 7330 */ { MAD_F(0x04586711) /* 0.271582667 */, 19 },
- /* 7331 */ { MAD_F(0x04589ade) /* 0.271632069 */, 19 },
- /* 7332 */ { MAD_F(0x0458ceac) /* 0.271681474 */, 19 },
- /* 7333 */ { MAD_F(0x0459027b) /* 0.271730880 */, 19 },
- /* 7334 */ { MAD_F(0x0459364a) /* 0.271780289 */, 19 },
- /* 7335 */ { MAD_F(0x04596a19) /* 0.271829701 */, 19 },
- /* 7336 */ { MAD_F(0x04599dea) /* 0.271879114 */, 19 },
- /* 7337 */ { MAD_F(0x0459d1bb) /* 0.271928530 */, 19 },
- /* 7338 */ { MAD_F(0x045a058c) /* 0.271977948 */, 19 },
- /* 7339 */ { MAD_F(0x045a395e) /* 0.272027368 */, 19 },
- /* 7340 */ { MAD_F(0x045a6d31) /* 0.272076790 */, 19 },
- /* 7341 */ { MAD_F(0x045aa104) /* 0.272126215 */, 19 },
- /* 7342 */ { MAD_F(0x045ad4d8) /* 0.272175642 */, 19 },
- /* 7343 */ { MAD_F(0x045b08ad) /* 0.272225071 */, 19 },
-
- /* 7344 */ { MAD_F(0x045b3c82) /* 0.272274503 */, 19 },
- /* 7345 */ { MAD_F(0x045b7058) /* 0.272323936 */, 19 },
- /* 7346 */ { MAD_F(0x045ba42e) /* 0.272373372 */, 19 },
- /* 7347 */ { MAD_F(0x045bd805) /* 0.272422810 */, 19 },
- /* 7348 */ { MAD_F(0x045c0bdd) /* 0.272472251 */, 19 },
- /* 7349 */ { MAD_F(0x045c3fb5) /* 0.272521693 */, 19 },
- /* 7350 */ { MAD_F(0x045c738e) /* 0.272571138 */, 19 },
- /* 7351 */ { MAD_F(0x045ca767) /* 0.272620585 */, 19 },
- /* 7352 */ { MAD_F(0x045cdb41) /* 0.272670035 */, 19 },
- /* 7353 */ { MAD_F(0x045d0f1b) /* 0.272719486 */, 19 },
- /* 7354 */ { MAD_F(0x045d42f7) /* 0.272768940 */, 19 },
- /* 7355 */ { MAD_F(0x045d76d2) /* 0.272818396 */, 19 },
- /* 7356 */ { MAD_F(0x045daaaf) /* 0.272867855 */, 19 },
- /* 7357 */ { MAD_F(0x045dde8c) /* 0.272917315 */, 19 },
- /* 7358 */ { MAD_F(0x045e1269) /* 0.272966778 */, 19 },
- /* 7359 */ { MAD_F(0x045e4647) /* 0.273016243 */, 19 },
-
- /* 7360 */ { MAD_F(0x045e7a26) /* 0.273065710 */, 19 },
- /* 7361 */ { MAD_F(0x045eae06) /* 0.273115180 */, 19 },
- /* 7362 */ { MAD_F(0x045ee1e6) /* 0.273164652 */, 19 },
- /* 7363 */ { MAD_F(0x045f15c6) /* 0.273214126 */, 19 },
- /* 7364 */ { MAD_F(0x045f49a7) /* 0.273263602 */, 19 },
- /* 7365 */ { MAD_F(0x045f7d89) /* 0.273313081 */, 19 },
- /* 7366 */ { MAD_F(0x045fb16c) /* 0.273362561 */, 19 },
- /* 7367 */ { MAD_F(0x045fe54f) /* 0.273412044 */, 19 },
- /* 7368 */ { MAD_F(0x04601932) /* 0.273461530 */, 19 },
- /* 7369 */ { MAD_F(0x04604d16) /* 0.273511017 */, 19 },
- /* 7370 */ { MAD_F(0x046080fb) /* 0.273560507 */, 19 },
- /* 7371 */ { MAD_F(0x0460b4e1) /* 0.273609999 */, 19 },
- /* 7372 */ { MAD_F(0x0460e8c7) /* 0.273659493 */, 19 },
- /* 7373 */ { MAD_F(0x04611cad) /* 0.273708989 */, 19 },
- /* 7374 */ { MAD_F(0x04615094) /* 0.273758488 */, 19 },
- /* 7375 */ { MAD_F(0x0461847c) /* 0.273807989 */, 19 },
-
- /* 7376 */ { MAD_F(0x0461b864) /* 0.273857492 */, 19 },
- /* 7377 */ { MAD_F(0x0461ec4d) /* 0.273906997 */, 19 },
- /* 7378 */ { MAD_F(0x04622037) /* 0.273956505 */, 19 },
- /* 7379 */ { MAD_F(0x04625421) /* 0.274006015 */, 19 },
- /* 7380 */ { MAD_F(0x0462880c) /* 0.274055527 */, 19 },
- /* 7381 */ { MAD_F(0x0462bbf7) /* 0.274105041 */, 19 },
- /* 7382 */ { MAD_F(0x0462efe3) /* 0.274154558 */, 19 },
- /* 7383 */ { MAD_F(0x046323d0) /* 0.274204076 */, 19 },
- /* 7384 */ { MAD_F(0x046357bd) /* 0.274253597 */, 19 },
- /* 7385 */ { MAD_F(0x04638bab) /* 0.274303121 */, 19 },
- /* 7386 */ { MAD_F(0x0463bf99) /* 0.274352646 */, 19 },
- /* 7387 */ { MAD_F(0x0463f388) /* 0.274402174 */, 19 },
- /* 7388 */ { MAD_F(0x04642778) /* 0.274451704 */, 19 },
- /* 7389 */ { MAD_F(0x04645b68) /* 0.274501236 */, 19 },
- /* 7390 */ { MAD_F(0x04648f59) /* 0.274550771 */, 19 },
- /* 7391 */ { MAD_F(0x0464c34a) /* 0.274600307 */, 19 },
-
- /* 7392 */ { MAD_F(0x0464f73c) /* 0.274649846 */, 19 },
- /* 7393 */ { MAD_F(0x04652b2f) /* 0.274699387 */, 19 },
- /* 7394 */ { MAD_F(0x04655f22) /* 0.274748931 */, 19 },
- /* 7395 */ { MAD_F(0x04659316) /* 0.274798476 */, 19 },
- /* 7396 */ { MAD_F(0x0465c70a) /* 0.274848024 */, 19 },
- /* 7397 */ { MAD_F(0x0465faff) /* 0.274897574 */, 19 },
- /* 7398 */ { MAD_F(0x04662ef5) /* 0.274947126 */, 19 },
- /* 7399 */ { MAD_F(0x046662eb) /* 0.274996681 */, 19 },
- /* 7400 */ { MAD_F(0x046696e2) /* 0.275046238 */, 19 },
- /* 7401 */ { MAD_F(0x0466cad9) /* 0.275095797 */, 19 },
- /* 7402 */ { MAD_F(0x0466fed1) /* 0.275145358 */, 19 },
- /* 7403 */ { MAD_F(0x046732ca) /* 0.275194921 */, 19 },
- /* 7404 */ { MAD_F(0x046766c3) /* 0.275244487 */, 19 },
- /* 7405 */ { MAD_F(0x04679abd) /* 0.275294055 */, 19 },
- /* 7406 */ { MAD_F(0x0467ceb7) /* 0.275343625 */, 19 },
- /* 7407 */ { MAD_F(0x046802b2) /* 0.275393198 */, 19 },
-
- /* 7408 */ { MAD_F(0x046836ae) /* 0.275442772 */, 19 },
- /* 7409 */ { MAD_F(0x04686aaa) /* 0.275492349 */, 19 },
- /* 7410 */ { MAD_F(0x04689ea7) /* 0.275541928 */, 19 },
- /* 7411 */ { MAD_F(0x0468d2a4) /* 0.275591509 */, 19 },
- /* 7412 */ { MAD_F(0x046906a2) /* 0.275641093 */, 19 },
- /* 7413 */ { MAD_F(0x04693aa1) /* 0.275690679 */, 19 },
- /* 7414 */ { MAD_F(0x04696ea0) /* 0.275740267 */, 19 },
- /* 7415 */ { MAD_F(0x0469a2a0) /* 0.275789857 */, 19 },
- /* 7416 */ { MAD_F(0x0469d6a0) /* 0.275839449 */, 19 },
- /* 7417 */ { MAD_F(0x046a0aa1) /* 0.275889044 */, 19 },
- /* 7418 */ { MAD_F(0x046a3ea3) /* 0.275938641 */, 19 },
- /* 7419 */ { MAD_F(0x046a72a5) /* 0.275988240 */, 19 },
- /* 7420 */ { MAD_F(0x046aa6a8) /* 0.276037842 */, 19 },
- /* 7421 */ { MAD_F(0x046adaab) /* 0.276087445 */, 19 },
- /* 7422 */ { MAD_F(0x046b0eaf) /* 0.276137051 */, 19 },
- /* 7423 */ { MAD_F(0x046b42b3) /* 0.276186659 */, 19 },
-
- /* 7424 */ { MAD_F(0x046b76b9) /* 0.276236269 */, 19 },
- /* 7425 */ { MAD_F(0x046baabe) /* 0.276285882 */, 19 },
- /* 7426 */ { MAD_F(0x046bdec5) /* 0.276335497 */, 19 },
- /* 7427 */ { MAD_F(0x046c12cc) /* 0.276385113 */, 19 },
- /* 7428 */ { MAD_F(0x046c46d3) /* 0.276434733 */, 19 },
- /* 7429 */ { MAD_F(0x046c7adb) /* 0.276484354 */, 19 },
- /* 7430 */ { MAD_F(0x046caee4) /* 0.276533978 */, 19 },
- /* 7431 */ { MAD_F(0x046ce2ee) /* 0.276583604 */, 19 },
- /* 7432 */ { MAD_F(0x046d16f7) /* 0.276633232 */, 19 },
- /* 7433 */ { MAD_F(0x046d4b02) /* 0.276682862 */, 19 },
- /* 7434 */ { MAD_F(0x046d7f0d) /* 0.276732495 */, 19 },
- /* 7435 */ { MAD_F(0x046db319) /* 0.276782129 */, 19 },
- /* 7436 */ { MAD_F(0x046de725) /* 0.276831766 */, 19 },
- /* 7437 */ { MAD_F(0x046e1b32) /* 0.276881406 */, 19 },
- /* 7438 */ { MAD_F(0x046e4f40) /* 0.276931047 */, 19 },
- /* 7439 */ { MAD_F(0x046e834e) /* 0.276980691 */, 19 },
-
- /* 7440 */ { MAD_F(0x046eb75c) /* 0.277030337 */, 19 },
- /* 7441 */ { MAD_F(0x046eeb6c) /* 0.277079985 */, 19 },
- /* 7442 */ { MAD_F(0x046f1f7c) /* 0.277129635 */, 19 },
- /* 7443 */ { MAD_F(0x046f538c) /* 0.277179288 */, 19 },
- /* 7444 */ { MAD_F(0x046f879d) /* 0.277228942 */, 19 },
- /* 7445 */ { MAD_F(0x046fbbaf) /* 0.277278600 */, 19 },
- /* 7446 */ { MAD_F(0x046fefc1) /* 0.277328259 */, 19 },
- /* 7447 */ { MAD_F(0x047023d4) /* 0.277377920 */, 19 },
- /* 7448 */ { MAD_F(0x047057e8) /* 0.277427584 */, 19 },
- /* 7449 */ { MAD_F(0x04708bfc) /* 0.277477250 */, 19 },
- /* 7450 */ { MAD_F(0x0470c011) /* 0.277526918 */, 19 },
- /* 7451 */ { MAD_F(0x0470f426) /* 0.277576588 */, 19 },
- /* 7452 */ { MAD_F(0x0471283c) /* 0.277626261 */, 19 },
- /* 7453 */ { MAD_F(0x04715c52) /* 0.277675936 */, 19 },
- /* 7454 */ { MAD_F(0x04719069) /* 0.277725613 */, 19 },
- /* 7455 */ { MAD_F(0x0471c481) /* 0.277775292 */, 19 },
-
- /* 7456 */ { MAD_F(0x0471f899) /* 0.277824973 */, 19 },
- /* 7457 */ { MAD_F(0x04722cb2) /* 0.277874657 */, 19 },
- /* 7458 */ { MAD_F(0x047260cc) /* 0.277924343 */, 19 },
- /* 7459 */ { MAD_F(0x047294e6) /* 0.277974031 */, 19 },
- /* 7460 */ { MAD_F(0x0472c900) /* 0.278023722 */, 19 },
- /* 7461 */ { MAD_F(0x0472fd1b) /* 0.278073414 */, 19 },
- /* 7462 */ { MAD_F(0x04733137) /* 0.278123109 */, 19 },
- /* 7463 */ { MAD_F(0x04736554) /* 0.278172806 */, 19 },
- /* 7464 */ { MAD_F(0x04739971) /* 0.278222505 */, 19 },
- /* 7465 */ { MAD_F(0x0473cd8e) /* 0.278272207 */, 19 },
- /* 7466 */ { MAD_F(0x047401ad) /* 0.278321910 */, 19 },
- /* 7467 */ { MAD_F(0x047435cb) /* 0.278371616 */, 19 },
- /* 7468 */ { MAD_F(0x047469eb) /* 0.278421324 */, 19 },
- /* 7469 */ { MAD_F(0x04749e0b) /* 0.278471035 */, 19 },
- /* 7470 */ { MAD_F(0x0474d22c) /* 0.278520747 */, 19 },
- /* 7471 */ { MAD_F(0x0475064d) /* 0.278570462 */, 19 },
-
- /* 7472 */ { MAD_F(0x04753a6f) /* 0.278620179 */, 19 },
- /* 7473 */ { MAD_F(0x04756e91) /* 0.278669898 */, 19 },
- /* 7474 */ { MAD_F(0x0475a2b4) /* 0.278719619 */, 19 },
- /* 7475 */ { MAD_F(0x0475d6d7) /* 0.278769343 */, 19 },
- /* 7476 */ { MAD_F(0x04760afc) /* 0.278819069 */, 19 },
- /* 7477 */ { MAD_F(0x04763f20) /* 0.278868797 */, 19 },
- /* 7478 */ { MAD_F(0x04767346) /* 0.278918527 */, 19 },
- /* 7479 */ { MAD_F(0x0476a76c) /* 0.278968260 */, 19 },
- /* 7480 */ { MAD_F(0x0476db92) /* 0.279017995 */, 19 },
- /* 7481 */ { MAD_F(0x04770fba) /* 0.279067731 */, 19 },
- /* 7482 */ { MAD_F(0x047743e1) /* 0.279117471 */, 19 },
- /* 7483 */ { MAD_F(0x0477780a) /* 0.279167212 */, 19 },
- /* 7484 */ { MAD_F(0x0477ac33) /* 0.279216956 */, 19 },
- /* 7485 */ { MAD_F(0x0477e05c) /* 0.279266701 */, 19 },
- /* 7486 */ { MAD_F(0x04781486) /* 0.279316449 */, 19 },
- /* 7487 */ { MAD_F(0x047848b1) /* 0.279366200 */, 19 },
-
- /* 7488 */ { MAD_F(0x04787cdc) /* 0.279415952 */, 19 },
- /* 7489 */ { MAD_F(0x0478b108) /* 0.279465707 */, 19 },
- /* 7490 */ { MAD_F(0x0478e535) /* 0.279515464 */, 19 },
- /* 7491 */ { MAD_F(0x04791962) /* 0.279565223 */, 19 },
- /* 7492 */ { MAD_F(0x04794d8f) /* 0.279614984 */, 19 },
- /* 7493 */ { MAD_F(0x047981be) /* 0.279664748 */, 19 },
- /* 7494 */ { MAD_F(0x0479b5ed) /* 0.279714513 */, 19 },
- /* 7495 */ { MAD_F(0x0479ea1c) /* 0.279764281 */, 19 },
- /* 7496 */ { MAD_F(0x047a1e4c) /* 0.279814051 */, 19 },
- /* 7497 */ { MAD_F(0x047a527d) /* 0.279863824 */, 19 },
- /* 7498 */ { MAD_F(0x047a86ae) /* 0.279913598 */, 19 },
- /* 7499 */ { MAD_F(0x047abae0) /* 0.279963375 */, 19 },
- /* 7500 */ { MAD_F(0x047aef12) /* 0.280013154 */, 19 },
- /* 7501 */ { MAD_F(0x047b2346) /* 0.280062935 */, 19 },
- /* 7502 */ { MAD_F(0x047b5779) /* 0.280112719 */, 19 },
- /* 7503 */ { MAD_F(0x047b8bad) /* 0.280162504 */, 19 },
-
- /* 7504 */ { MAD_F(0x047bbfe2) /* 0.280212292 */, 19 },
- /* 7505 */ { MAD_F(0x047bf418) /* 0.280262082 */, 19 },
- /* 7506 */ { MAD_F(0x047c284e) /* 0.280311875 */, 19 },
- /* 7507 */ { MAD_F(0x047c5c84) /* 0.280361669 */, 19 },
- /* 7508 */ { MAD_F(0x047c90bb) /* 0.280411466 */, 19 },
- /* 7509 */ { MAD_F(0x047cc4f3) /* 0.280461265 */, 19 },
- /* 7510 */ { MAD_F(0x047cf92c) /* 0.280511066 */, 19 },
- /* 7511 */ { MAD_F(0x047d2d65) /* 0.280560869 */, 19 },
- /* 7512 */ { MAD_F(0x047d619e) /* 0.280610675 */, 19 },
- /* 7513 */ { MAD_F(0x047d95d8) /* 0.280660483 */, 19 },
- /* 7514 */ { MAD_F(0x047dca13) /* 0.280710292 */, 19 },
- /* 7515 */ { MAD_F(0x047dfe4e) /* 0.280760105 */, 19 },
- /* 7516 */ { MAD_F(0x047e328a) /* 0.280809919 */, 19 },
- /* 7517 */ { MAD_F(0x047e66c7) /* 0.280859736 */, 19 },
- /* 7518 */ { MAD_F(0x047e9b04) /* 0.280909554 */, 19 },
- /* 7519 */ { MAD_F(0x047ecf42) /* 0.280959375 */, 19 },
-
- /* 7520 */ { MAD_F(0x047f0380) /* 0.281009199 */, 19 },
- /* 7521 */ { MAD_F(0x047f37bf) /* 0.281059024 */, 19 },
- /* 7522 */ { MAD_F(0x047f6bff) /* 0.281108852 */, 19 },
- /* 7523 */ { MAD_F(0x047fa03f) /* 0.281158682 */, 19 },
- /* 7524 */ { MAD_F(0x047fd47f) /* 0.281208514 */, 19 },
- /* 7525 */ { MAD_F(0x048008c1) /* 0.281258348 */, 19 },
- /* 7526 */ { MAD_F(0x04803d02) /* 0.281308184 */, 19 },
- /* 7527 */ { MAD_F(0x04807145) /* 0.281358023 */, 19 },
- /* 7528 */ { MAD_F(0x0480a588) /* 0.281407864 */, 19 },
- /* 7529 */ { MAD_F(0x0480d9cc) /* 0.281457707 */, 19 },
- /* 7530 */ { MAD_F(0x04810e10) /* 0.281507552 */, 19 },
- /* 7531 */ { MAD_F(0x04814255) /* 0.281557400 */, 19 },
- /* 7532 */ { MAD_F(0x0481769a) /* 0.281607250 */, 19 },
- /* 7533 */ { MAD_F(0x0481aae0) /* 0.281657101 */, 19 },
- /* 7534 */ { MAD_F(0x0481df27) /* 0.281706956 */, 19 },
- /* 7535 */ { MAD_F(0x0482136e) /* 0.281756812 */, 19 },
-
- /* 7536 */ { MAD_F(0x048247b6) /* 0.281806670 */, 19 },
- /* 7537 */ { MAD_F(0x04827bfe) /* 0.281856531 */, 19 },
- /* 7538 */ { MAD_F(0x0482b047) /* 0.281906394 */, 19 },
- /* 7539 */ { MAD_F(0x0482e491) /* 0.281956259 */, 19 },
- /* 7540 */ { MAD_F(0x048318db) /* 0.282006127 */, 19 },
- /* 7541 */ { MAD_F(0x04834d26) /* 0.282055996 */, 19 },
- /* 7542 */ { MAD_F(0x04838171) /* 0.282105868 */, 19 },
- /* 7543 */ { MAD_F(0x0483b5bd) /* 0.282155742 */, 19 },
- /* 7544 */ { MAD_F(0x0483ea0a) /* 0.282205618 */, 19 },
- /* 7545 */ { MAD_F(0x04841e57) /* 0.282255496 */, 19 },
- /* 7546 */ { MAD_F(0x048452a4) /* 0.282305377 */, 19 },
- /* 7547 */ { MAD_F(0x048486f3) /* 0.282355260 */, 19 },
- /* 7548 */ { MAD_F(0x0484bb42) /* 0.282405145 */, 19 },
- /* 7549 */ { MAD_F(0x0484ef91) /* 0.282455032 */, 19 },
- /* 7550 */ { MAD_F(0x048523e1) /* 0.282504921 */, 19 },
- /* 7551 */ { MAD_F(0x04855832) /* 0.282554813 */, 19 },
-
- /* 7552 */ { MAD_F(0x04858c83) /* 0.282604707 */, 19 },
- /* 7553 */ { MAD_F(0x0485c0d5) /* 0.282654603 */, 19 },
- /* 7554 */ { MAD_F(0x0485f527) /* 0.282704501 */, 19 },
- /* 7555 */ { MAD_F(0x0486297a) /* 0.282754401 */, 19 },
- /* 7556 */ { MAD_F(0x04865dce) /* 0.282804304 */, 19 },
- /* 7557 */ { MAD_F(0x04869222) /* 0.282854209 */, 19 },
- /* 7558 */ { MAD_F(0x0486c677) /* 0.282904116 */, 19 },
- /* 7559 */ { MAD_F(0x0486facc) /* 0.282954025 */, 19 },
- /* 7560 */ { MAD_F(0x04872f22) /* 0.283003936 */, 19 },
- /* 7561 */ { MAD_F(0x04876379) /* 0.283053850 */, 19 },
- /* 7562 */ { MAD_F(0x048797d0) /* 0.283103766 */, 19 },
- /* 7563 */ { MAD_F(0x0487cc28) /* 0.283153684 */, 19 },
- /* 7564 */ { MAD_F(0x04880080) /* 0.283203604 */, 19 },
- /* 7565 */ { MAD_F(0x048834d9) /* 0.283253527 */, 19 },
- /* 7566 */ { MAD_F(0x04886933) /* 0.283303451 */, 19 },
- /* 7567 */ { MAD_F(0x04889d8d) /* 0.283353378 */, 19 },
-
- /* 7568 */ { MAD_F(0x0488d1e8) /* 0.283403307 */, 19 },
- /* 7569 */ { MAD_F(0x04890643) /* 0.283453238 */, 19 },
- /* 7570 */ { MAD_F(0x04893a9f) /* 0.283503172 */, 19 },
- /* 7571 */ { MAD_F(0x04896efb) /* 0.283553107 */, 19 },
- /* 7572 */ { MAD_F(0x0489a358) /* 0.283603045 */, 19 },
- /* 7573 */ { MAD_F(0x0489d7b6) /* 0.283652985 */, 19 },
- /* 7574 */ { MAD_F(0x048a0c14) /* 0.283702927 */, 19 },
- /* 7575 */ { MAD_F(0x048a4073) /* 0.283752872 */, 19 },
- /* 7576 */ { MAD_F(0x048a74d3) /* 0.283802818 */, 19 },
- /* 7577 */ { MAD_F(0x048aa933) /* 0.283852767 */, 19 },
- /* 7578 */ { MAD_F(0x048add93) /* 0.283902718 */, 19 },
- /* 7579 */ { MAD_F(0x048b11f5) /* 0.283952671 */, 19 },
- /* 7580 */ { MAD_F(0x048b4656) /* 0.284002627 */, 19 },
- /* 7581 */ { MAD_F(0x048b7ab9) /* 0.284052584 */, 19 },
- /* 7582 */ { MAD_F(0x048baf1c) /* 0.284102544 */, 19 },
- /* 7583 */ { MAD_F(0x048be37f) /* 0.284152506 */, 19 },
-
- /* 7584 */ { MAD_F(0x048c17e3) /* 0.284202470 */, 19 },
- /* 7585 */ { MAD_F(0x048c4c48) /* 0.284252436 */, 19 },
- /* 7586 */ { MAD_F(0x048c80ad) /* 0.284302405 */, 19 },
- /* 7587 */ { MAD_F(0x048cb513) /* 0.284352376 */, 19 },
- /* 7588 */ { MAD_F(0x048ce97a) /* 0.284402349 */, 19 },
- /* 7589 */ { MAD_F(0x048d1de1) /* 0.284452324 */, 19 },
- /* 7590 */ { MAD_F(0x048d5249) /* 0.284502301 */, 19 },
- /* 7591 */ { MAD_F(0x048d86b1) /* 0.284552281 */, 19 },
- /* 7592 */ { MAD_F(0x048dbb1a) /* 0.284602263 */, 19 },
- /* 7593 */ { MAD_F(0x048def83) /* 0.284652246 */, 19 },
- /* 7594 */ { MAD_F(0x048e23ed) /* 0.284702233 */, 19 },
- /* 7595 */ { MAD_F(0x048e5858) /* 0.284752221 */, 19 },
- /* 7596 */ { MAD_F(0x048e8cc3) /* 0.284802211 */, 19 },
- /* 7597 */ { MAD_F(0x048ec12f) /* 0.284852204 */, 19 },
- /* 7598 */ { MAD_F(0x048ef59b) /* 0.284902199 */, 19 },
- /* 7599 */ { MAD_F(0x048f2a08) /* 0.284952196 */, 19 },
-
- /* 7600 */ { MAD_F(0x048f5e76) /* 0.285002195 */, 19 },
- /* 7601 */ { MAD_F(0x048f92e4) /* 0.285052197 */, 19 },
- /* 7602 */ { MAD_F(0x048fc753) /* 0.285102201 */, 19 },
- /* 7603 */ { MAD_F(0x048ffbc2) /* 0.285152206 */, 19 },
- /* 7604 */ { MAD_F(0x04903032) /* 0.285202214 */, 19 },
- /* 7605 */ { MAD_F(0x049064a3) /* 0.285252225 */, 19 },
- /* 7606 */ { MAD_F(0x04909914) /* 0.285302237 */, 19 },
- /* 7607 */ { MAD_F(0x0490cd86) /* 0.285352252 */, 19 },
- /* 7608 */ { MAD_F(0x049101f8) /* 0.285402269 */, 19 },
- /* 7609 */ { MAD_F(0x0491366b) /* 0.285452288 */, 19 },
- /* 7610 */ { MAD_F(0x04916ade) /* 0.285502309 */, 19 },
- /* 7611 */ { MAD_F(0x04919f52) /* 0.285552332 */, 19 },
- /* 7612 */ { MAD_F(0x0491d3c7) /* 0.285602358 */, 19 },
- /* 7613 */ { MAD_F(0x0492083c) /* 0.285652386 */, 19 },
- /* 7614 */ { MAD_F(0x04923cb2) /* 0.285702416 */, 19 },
- /* 7615 */ { MAD_F(0x04927128) /* 0.285752448 */, 19 },
-
- /* 7616 */ { MAD_F(0x0492a59f) /* 0.285802482 */, 19 },
- /* 7617 */ { MAD_F(0x0492da17) /* 0.285852519 */, 19 },
- /* 7618 */ { MAD_F(0x04930e8f) /* 0.285902557 */, 19 },
- /* 7619 */ { MAD_F(0x04934308) /* 0.285952598 */, 19 },
- /* 7620 */ { MAD_F(0x04937781) /* 0.286002641 */, 19 },
- /* 7621 */ { MAD_F(0x0493abfb) /* 0.286052687 */, 19 },
- /* 7622 */ { MAD_F(0x0493e076) /* 0.286102734 */, 19 },
- /* 7623 */ { MAD_F(0x049414f1) /* 0.286152784 */, 19 },
- /* 7624 */ { MAD_F(0x0494496c) /* 0.286202836 */, 19 },
- /* 7625 */ { MAD_F(0x04947de9) /* 0.286252890 */, 19 },
- /* 7626 */ { MAD_F(0x0494b266) /* 0.286302946 */, 19 },
- /* 7627 */ { MAD_F(0x0494e6e3) /* 0.286353005 */, 19 },
- /* 7628 */ { MAD_F(0x04951b61) /* 0.286403065 */, 19 },
- /* 7629 */ { MAD_F(0x04954fe0) /* 0.286453128 */, 19 },
- /* 7630 */ { MAD_F(0x0495845f) /* 0.286503193 */, 19 },
- /* 7631 */ { MAD_F(0x0495b8df) /* 0.286553260 */, 19 },
-
- /* 7632 */ { MAD_F(0x0495ed5f) /* 0.286603329 */, 19 },
- /* 7633 */ { MAD_F(0x049621e0) /* 0.286653401 */, 19 },
- /* 7634 */ { MAD_F(0x04965662) /* 0.286703475 */, 19 },
- /* 7635 */ { MAD_F(0x04968ae4) /* 0.286753551 */, 19 },
- /* 7636 */ { MAD_F(0x0496bf67) /* 0.286803629 */, 19 },
- /* 7637 */ { MAD_F(0x0496f3ea) /* 0.286853709 */, 19 },
- /* 7638 */ { MAD_F(0x0497286e) /* 0.286903792 */, 19 },
- /* 7639 */ { MAD_F(0x04975cf2) /* 0.286953876 */, 19 },
- /* 7640 */ { MAD_F(0x04979177) /* 0.287003963 */, 19 },
- /* 7641 */ { MAD_F(0x0497c5fd) /* 0.287054052 */, 19 },
- /* 7642 */ { MAD_F(0x0497fa83) /* 0.287104143 */, 19 },
- /* 7643 */ { MAD_F(0x04982f0a) /* 0.287154237 */, 19 },
- /* 7644 */ { MAD_F(0x04986392) /* 0.287204332 */, 19 },
- /* 7645 */ { MAD_F(0x0498981a) /* 0.287254430 */, 19 },
- /* 7646 */ { MAD_F(0x0498cca2) /* 0.287304530 */, 19 },
- /* 7647 */ { MAD_F(0x0499012c) /* 0.287354632 */, 19 },
-
- /* 7648 */ { MAD_F(0x049935b5) /* 0.287404737 */, 19 },
- /* 7649 */ { MAD_F(0x04996a40) /* 0.287454843 */, 19 },
- /* 7650 */ { MAD_F(0x04999ecb) /* 0.287504952 */, 19 },
- /* 7651 */ { MAD_F(0x0499d356) /* 0.287555063 */, 19 },
- /* 7652 */ { MAD_F(0x049a07e2) /* 0.287605176 */, 19 },
- /* 7653 */ { MAD_F(0x049a3c6f) /* 0.287655291 */, 19 },
- /* 7654 */ { MAD_F(0x049a70fc) /* 0.287705409 */, 19 },
- /* 7655 */ { MAD_F(0x049aa58a) /* 0.287755528 */, 19 },
- /* 7656 */ { MAD_F(0x049ada19) /* 0.287805650 */, 19 },
- /* 7657 */ { MAD_F(0x049b0ea8) /* 0.287855774 */, 19 },
- /* 7658 */ { MAD_F(0x049b4337) /* 0.287905900 */, 19 },
- /* 7659 */ { MAD_F(0x049b77c8) /* 0.287956028 */, 19 },
- /* 7660 */ { MAD_F(0x049bac58) /* 0.288006159 */, 19 },
- /* 7661 */ { MAD_F(0x049be0ea) /* 0.288056292 */, 19 },
- /* 7662 */ { MAD_F(0x049c157c) /* 0.288106427 */, 19 },
- /* 7663 */ { MAD_F(0x049c4a0e) /* 0.288156564 */, 19 },
-
- /* 7664 */ { MAD_F(0x049c7ea1) /* 0.288206703 */, 19 },
- /* 7665 */ { MAD_F(0x049cb335) /* 0.288256844 */, 19 },
- /* 7666 */ { MAD_F(0x049ce7ca) /* 0.288306988 */, 19 },
- /* 7667 */ { MAD_F(0x049d1c5e) /* 0.288357134 */, 19 },
- /* 7668 */ { MAD_F(0x049d50f4) /* 0.288407282 */, 19 },
- /* 7669 */ { MAD_F(0x049d858a) /* 0.288457432 */, 19 },
- /* 7670 */ { MAD_F(0x049dba21) /* 0.288507584 */, 19 },
- /* 7671 */ { MAD_F(0x049deeb8) /* 0.288557739 */, 19 },
- /* 7672 */ { MAD_F(0x049e2350) /* 0.288607895 */, 19 },
- /* 7673 */ { MAD_F(0x049e57e8) /* 0.288658054 */, 19 },
- /* 7674 */ { MAD_F(0x049e8c81) /* 0.288708215 */, 19 },
- /* 7675 */ { MAD_F(0x049ec11b) /* 0.288758379 */, 19 },
- /* 7676 */ { MAD_F(0x049ef5b5) /* 0.288808544 */, 19 },
- /* 7677 */ { MAD_F(0x049f2a50) /* 0.288858712 */, 19 },
- /* 7678 */ { MAD_F(0x049f5eeb) /* 0.288908881 */, 19 },
- /* 7679 */ { MAD_F(0x049f9387) /* 0.288959053 */, 19 },
-
- /* 7680 */ { MAD_F(0x049fc824) /* 0.289009227 */, 19 },
- /* 7681 */ { MAD_F(0x049ffcc1) /* 0.289059404 */, 19 },
- /* 7682 */ { MAD_F(0x04a0315e) /* 0.289109582 */, 19 },
- /* 7683 */ { MAD_F(0x04a065fd) /* 0.289159763 */, 19 },
- /* 7684 */ { MAD_F(0x04a09a9b) /* 0.289209946 */, 19 },
- /* 7685 */ { MAD_F(0x04a0cf3b) /* 0.289260131 */, 19 },
- /* 7686 */ { MAD_F(0x04a103db) /* 0.289310318 */, 19 },
- /* 7687 */ { MAD_F(0x04a1387b) /* 0.289360507 */, 19 },
- /* 7688 */ { MAD_F(0x04a16d1d) /* 0.289410699 */, 19 },
- /* 7689 */ { MAD_F(0x04a1a1be) /* 0.289460893 */, 19 },
- /* 7690 */ { MAD_F(0x04a1d661) /* 0.289511088 */, 19 },
- /* 7691 */ { MAD_F(0x04a20b04) /* 0.289561287 */, 19 },
- /* 7692 */ { MAD_F(0x04a23fa7) /* 0.289611487 */, 19 },
- /* 7693 */ { MAD_F(0x04a2744b) /* 0.289661689 */, 19 },
- /* 7694 */ { MAD_F(0x04a2a8f0) /* 0.289711894 */, 19 },
- /* 7695 */ { MAD_F(0x04a2dd95) /* 0.289762101 */, 19 },
-
- /* 7696 */ { MAD_F(0x04a3123b) /* 0.289812309 */, 19 },
- /* 7697 */ { MAD_F(0x04a346e2) /* 0.289862521 */, 19 },
- /* 7698 */ { MAD_F(0x04a37b89) /* 0.289912734 */, 19 },
- /* 7699 */ { MAD_F(0x04a3b030) /* 0.289962949 */, 19 },
- /* 7700 */ { MAD_F(0x04a3e4d8) /* 0.290013167 */, 19 },
- /* 7701 */ { MAD_F(0x04a41981) /* 0.290063387 */, 19 },
- /* 7702 */ { MAD_F(0x04a44e2b) /* 0.290113609 */, 19 },
- /* 7703 */ { MAD_F(0x04a482d5) /* 0.290163833 */, 19 },
- /* 7704 */ { MAD_F(0x04a4b77f) /* 0.290214059 */, 19 },
- /* 7705 */ { MAD_F(0x04a4ec2a) /* 0.290264288 */, 19 },
- /* 7706 */ { MAD_F(0x04a520d6) /* 0.290314519 */, 19 },
- /* 7707 */ { MAD_F(0x04a55582) /* 0.290364751 */, 19 },
- /* 7708 */ { MAD_F(0x04a58a2f) /* 0.290414986 */, 19 },
- /* 7709 */ { MAD_F(0x04a5bedd) /* 0.290465224 */, 19 },
- /* 7710 */ { MAD_F(0x04a5f38b) /* 0.290515463 */, 19 },
- /* 7711 */ { MAD_F(0x04a62839) /* 0.290565705 */, 19 },
-
- /* 7712 */ { MAD_F(0x04a65ce8) /* 0.290615948 */, 19 },
- /* 7713 */ { MAD_F(0x04a69198) /* 0.290666194 */, 19 },
- /* 7714 */ { MAD_F(0x04a6c648) /* 0.290716442 */, 19 },
- /* 7715 */ { MAD_F(0x04a6faf9) /* 0.290766692 */, 19 },
- /* 7716 */ { MAD_F(0x04a72fab) /* 0.290816945 */, 19 },
- /* 7717 */ { MAD_F(0x04a7645d) /* 0.290867199 */, 19 },
- /* 7718 */ { MAD_F(0x04a79910) /* 0.290917456 */, 19 },
- /* 7719 */ { MAD_F(0x04a7cdc3) /* 0.290967715 */, 19 },
- /* 7720 */ { MAD_F(0x04a80277) /* 0.291017976 */, 19 },
- /* 7721 */ { MAD_F(0x04a8372b) /* 0.291068239 */, 19 },
- /* 7722 */ { MAD_F(0x04a86be0) /* 0.291118505 */, 19 },
- /* 7723 */ { MAD_F(0x04a8a096) /* 0.291168772 */, 19 },
- /* 7724 */ { MAD_F(0x04a8d54c) /* 0.291219042 */, 19 },
- /* 7725 */ { MAD_F(0x04a90a03) /* 0.291269314 */, 19 },
- /* 7726 */ { MAD_F(0x04a93eba) /* 0.291319588 */, 19 },
- /* 7727 */ { MAD_F(0x04a97372) /* 0.291369865 */, 19 },
-
- /* 7728 */ { MAD_F(0x04a9a82b) /* 0.291420143 */, 19 },
- /* 7729 */ { MAD_F(0x04a9dce4) /* 0.291470424 */, 19 },
- /* 7730 */ { MAD_F(0x04aa119d) /* 0.291520706 */, 19 },
- /* 7731 */ { MAD_F(0x04aa4658) /* 0.291570991 */, 19 },
- /* 7732 */ { MAD_F(0x04aa7b13) /* 0.291621278 */, 19 },
- /* 7733 */ { MAD_F(0x04aaafce) /* 0.291671568 */, 19 },
- /* 7734 */ { MAD_F(0x04aae48a) /* 0.291721859 */, 19 },
- /* 7735 */ { MAD_F(0x04ab1947) /* 0.291772153 */, 19 },
- /* 7736 */ { MAD_F(0x04ab4e04) /* 0.291822449 */, 19 },
- /* 7737 */ { MAD_F(0x04ab82c2) /* 0.291872747 */, 19 },
- /* 7738 */ { MAD_F(0x04abb780) /* 0.291923047 */, 19 },
- /* 7739 */ { MAD_F(0x04abec3f) /* 0.291973349 */, 19 },
- /* 7740 */ { MAD_F(0x04ac20fe) /* 0.292023653 */, 19 },
- /* 7741 */ { MAD_F(0x04ac55be) /* 0.292073960 */, 19 },
- /* 7742 */ { MAD_F(0x04ac8a7f) /* 0.292124269 */, 19 },
- /* 7743 */ { MAD_F(0x04acbf40) /* 0.292174580 */, 19 },
-
- /* 7744 */ { MAD_F(0x04acf402) /* 0.292224893 */, 19 },
- /* 7745 */ { MAD_F(0x04ad28c5) /* 0.292275208 */, 19 },
- /* 7746 */ { MAD_F(0x04ad5d88) /* 0.292325526 */, 19 },
- /* 7747 */ { MAD_F(0x04ad924b) /* 0.292375845 */, 19 },
- /* 7748 */ { MAD_F(0x04adc70f) /* 0.292426167 */, 19 },
- /* 7749 */ { MAD_F(0x04adfbd4) /* 0.292476491 */, 19 },
- /* 7750 */ { MAD_F(0x04ae3099) /* 0.292526817 */, 19 },
- /* 7751 */ { MAD_F(0x04ae655f) /* 0.292577145 */, 19 },
- /* 7752 */ { MAD_F(0x04ae9a26) /* 0.292627476 */, 19 },
- /* 7753 */ { MAD_F(0x04aeceed) /* 0.292677808 */, 19 },
- /* 7754 */ { MAD_F(0x04af03b4) /* 0.292728143 */, 19 },
- /* 7755 */ { MAD_F(0x04af387d) /* 0.292778480 */, 19 },
- /* 7756 */ { MAD_F(0x04af6d45) /* 0.292828819 */, 19 },
- /* 7757 */ { MAD_F(0x04afa20f) /* 0.292879160 */, 19 },
- /* 7758 */ { MAD_F(0x04afd6d9) /* 0.292929504 */, 19 },
- /* 7759 */ { MAD_F(0x04b00ba3) /* 0.292979849 */, 19 },
-
- /* 7760 */ { MAD_F(0x04b0406e) /* 0.293030197 */, 19 },
- /* 7761 */ { MAD_F(0x04b0753a) /* 0.293080547 */, 19 },
- /* 7762 */ { MAD_F(0x04b0aa06) /* 0.293130899 */, 19 },
- /* 7763 */ { MAD_F(0x04b0ded3) /* 0.293181253 */, 19 },
- /* 7764 */ { MAD_F(0x04b113a1) /* 0.293231610 */, 19 },
- /* 7765 */ { MAD_F(0x04b1486f) /* 0.293281968 */, 19 },
- /* 7766 */ { MAD_F(0x04b17d3d) /* 0.293332329 */, 19 },
- /* 7767 */ { MAD_F(0x04b1b20c) /* 0.293382692 */, 19 },
- /* 7768 */ { MAD_F(0x04b1e6dc) /* 0.293433057 */, 19 },
- /* 7769 */ { MAD_F(0x04b21bad) /* 0.293483424 */, 19 },
- /* 7770 */ { MAD_F(0x04b2507d) /* 0.293533794 */, 19 },
- /* 7771 */ { MAD_F(0x04b2854f) /* 0.293584165 */, 19 },
- /* 7772 */ { MAD_F(0x04b2ba21) /* 0.293634539 */, 19 },
- /* 7773 */ { MAD_F(0x04b2eef4) /* 0.293684915 */, 19 },
- /* 7774 */ { MAD_F(0x04b323c7) /* 0.293735293 */, 19 },
- /* 7775 */ { MAD_F(0x04b3589b) /* 0.293785673 */, 19 },
-
- /* 7776 */ { MAD_F(0x04b38d6f) /* 0.293836055 */, 19 },
- /* 7777 */ { MAD_F(0x04b3c244) /* 0.293886440 */, 19 },
- /* 7778 */ { MAD_F(0x04b3f71a) /* 0.293936826 */, 19 },
- /* 7779 */ { MAD_F(0x04b42bf0) /* 0.293987215 */, 19 },
- /* 7780 */ { MAD_F(0x04b460c7) /* 0.294037606 */, 19 },
- /* 7781 */ { MAD_F(0x04b4959e) /* 0.294087999 */, 19 },
- /* 7782 */ { MAD_F(0x04b4ca76) /* 0.294138395 */, 19 },
- /* 7783 */ { MAD_F(0x04b4ff4e) /* 0.294188792 */, 19 },
- /* 7784 */ { MAD_F(0x04b53427) /* 0.294239192 */, 19 },
- /* 7785 */ { MAD_F(0x04b56901) /* 0.294289593 */, 19 },
- /* 7786 */ { MAD_F(0x04b59ddb) /* 0.294339997 */, 19 },
- /* 7787 */ { MAD_F(0x04b5d2b6) /* 0.294390403 */, 19 },
- /* 7788 */ { MAD_F(0x04b60791) /* 0.294440812 */, 19 },
- /* 7789 */ { MAD_F(0x04b63c6d) /* 0.294491222 */, 19 },
- /* 7790 */ { MAD_F(0x04b6714a) /* 0.294541635 */, 19 },
- /* 7791 */ { MAD_F(0x04b6a627) /* 0.294592049 */, 19 },
-
- /* 7792 */ { MAD_F(0x04b6db05) /* 0.294642466 */, 19 },
- /* 7793 */ { MAD_F(0x04b70fe3) /* 0.294692885 */, 19 },
- /* 7794 */ { MAD_F(0x04b744c2) /* 0.294743306 */, 19 },
- /* 7795 */ { MAD_F(0x04b779a1) /* 0.294793730 */, 19 },
- /* 7796 */ { MAD_F(0x04b7ae81) /* 0.294844155 */, 19 },
- /* 7797 */ { MAD_F(0x04b7e362) /* 0.294894583 */, 19 },
- /* 7798 */ { MAD_F(0x04b81843) /* 0.294945013 */, 19 },
- /* 7799 */ { MAD_F(0x04b84d24) /* 0.294995445 */, 19 },
- /* 7800 */ { MAD_F(0x04b88207) /* 0.295045879 */, 19 },
- /* 7801 */ { MAD_F(0x04b8b6ea) /* 0.295096315 */, 19 },
- /* 7802 */ { MAD_F(0x04b8ebcd) /* 0.295146753 */, 19 },
- /* 7803 */ { MAD_F(0x04b920b1) /* 0.295197194 */, 19 },
- /* 7804 */ { MAD_F(0x04b95596) /* 0.295247637 */, 19 },
- /* 7805 */ { MAD_F(0x04b98a7b) /* 0.295298082 */, 19 },
- /* 7806 */ { MAD_F(0x04b9bf61) /* 0.295348529 */, 19 },
- /* 7807 */ { MAD_F(0x04b9f447) /* 0.295398978 */, 19 },
-
- /* 7808 */ { MAD_F(0x04ba292e) /* 0.295449429 */, 19 },
- /* 7809 */ { MAD_F(0x04ba5e16) /* 0.295499883 */, 19 },
- /* 7810 */ { MAD_F(0x04ba92fe) /* 0.295550338 */, 19 },
- /* 7811 */ { MAD_F(0x04bac7e6) /* 0.295600796 */, 19 },
- /* 7812 */ { MAD_F(0x04bafcd0) /* 0.295651256 */, 19 },
- /* 7813 */ { MAD_F(0x04bb31b9) /* 0.295701718 */, 19 },
- /* 7814 */ { MAD_F(0x04bb66a4) /* 0.295752183 */, 19 },
- /* 7815 */ { MAD_F(0x04bb9b8f) /* 0.295802649 */, 19 },
- /* 7816 */ { MAD_F(0x04bbd07a) /* 0.295853118 */, 19 },
- /* 7817 */ { MAD_F(0x04bc0566) /* 0.295903588 */, 19 },
- /* 7818 */ { MAD_F(0x04bc3a53) /* 0.295954061 */, 19 },
- /* 7819 */ { MAD_F(0x04bc6f40) /* 0.296004536 */, 19 },
- /* 7820 */ { MAD_F(0x04bca42e) /* 0.296055013 */, 19 },
- /* 7821 */ { MAD_F(0x04bcd91d) /* 0.296105493 */, 19 },
- /* 7822 */ { MAD_F(0x04bd0e0c) /* 0.296155974 */, 19 },
- /* 7823 */ { MAD_F(0x04bd42fb) /* 0.296206458 */, 19 },
-
- /* 7824 */ { MAD_F(0x04bd77ec) /* 0.296256944 */, 19 },
- /* 7825 */ { MAD_F(0x04bdacdc) /* 0.296307432 */, 19 },
- /* 7826 */ { MAD_F(0x04bde1ce) /* 0.296357922 */, 19 },
- /* 7827 */ { MAD_F(0x04be16c0) /* 0.296408414 */, 19 },
- /* 7828 */ { MAD_F(0x04be4bb2) /* 0.296458908 */, 19 },
- /* 7829 */ { MAD_F(0x04be80a5) /* 0.296509405 */, 19 },
- /* 7830 */ { MAD_F(0x04beb599) /* 0.296559904 */, 19 },
- /* 7831 */ { MAD_F(0x04beea8d) /* 0.296610404 */, 19 },
- /* 7832 */ { MAD_F(0x04bf1f82) /* 0.296660907 */, 19 },
- /* 7833 */ { MAD_F(0x04bf5477) /* 0.296711413 */, 19 },
- /* 7834 */ { MAD_F(0x04bf896d) /* 0.296761920 */, 19 },
- /* 7835 */ { MAD_F(0x04bfbe64) /* 0.296812429 */, 19 },
- /* 7836 */ { MAD_F(0x04bff35b) /* 0.296862941 */, 19 },
- /* 7837 */ { MAD_F(0x04c02852) /* 0.296913455 */, 19 },
- /* 7838 */ { MAD_F(0x04c05d4b) /* 0.296963971 */, 19 },
- /* 7839 */ { MAD_F(0x04c09243) /* 0.297014489 */, 19 },
-
- /* 7840 */ { MAD_F(0x04c0c73d) /* 0.297065009 */, 19 },
- /* 7841 */ { MAD_F(0x04c0fc37) /* 0.297115531 */, 19 },
- /* 7842 */ { MAD_F(0x04c13131) /* 0.297166056 */, 19 },
- /* 7843 */ { MAD_F(0x04c1662d) /* 0.297216582 */, 19 },
- /* 7844 */ { MAD_F(0x04c19b28) /* 0.297267111 */, 19 },
- /* 7845 */ { MAD_F(0x04c1d025) /* 0.297317642 */, 19 },
- /* 7846 */ { MAD_F(0x04c20521) /* 0.297368175 */, 19 },
- /* 7847 */ { MAD_F(0x04c23a1f) /* 0.297418710 */, 19 },
- /* 7848 */ { MAD_F(0x04c26f1d) /* 0.297469248 */, 19 },
- /* 7849 */ { MAD_F(0x04c2a41b) /* 0.297519787 */, 19 },
- /* 7850 */ { MAD_F(0x04c2d91b) /* 0.297570329 */, 19 },
- /* 7851 */ { MAD_F(0x04c30e1a) /* 0.297620873 */, 19 },
- /* 7852 */ { MAD_F(0x04c3431b) /* 0.297671418 */, 19 },
- /* 7853 */ { MAD_F(0x04c3781c) /* 0.297721967 */, 19 },
- /* 7854 */ { MAD_F(0x04c3ad1d) /* 0.297772517 */, 19 },
- /* 7855 */ { MAD_F(0x04c3e21f) /* 0.297823069 */, 19 },
-
- /* 7856 */ { MAD_F(0x04c41722) /* 0.297873624 */, 19 },
- /* 7857 */ { MAD_F(0x04c44c25) /* 0.297924180 */, 19 },
- /* 7858 */ { MAD_F(0x04c48129) /* 0.297974739 */, 19 },
- /* 7859 */ { MAD_F(0x04c4b62d) /* 0.298025300 */, 19 },
- /* 7860 */ { MAD_F(0x04c4eb32) /* 0.298075863 */, 19 },
- /* 7861 */ { MAD_F(0x04c52038) /* 0.298126429 */, 19 },
- /* 7862 */ { MAD_F(0x04c5553e) /* 0.298176996 */, 19 },
- /* 7863 */ { MAD_F(0x04c58a44) /* 0.298227565 */, 19 },
- /* 7864 */ { MAD_F(0x04c5bf4c) /* 0.298278137 */, 19 },
- /* 7865 */ { MAD_F(0x04c5f453) /* 0.298328711 */, 19 },
- /* 7866 */ { MAD_F(0x04c6295c) /* 0.298379287 */, 19 },
- /* 7867 */ { MAD_F(0x04c65e65) /* 0.298429865 */, 19 },
- /* 7868 */ { MAD_F(0x04c6936e) /* 0.298480445 */, 19 },
- /* 7869 */ { MAD_F(0x04c6c878) /* 0.298531028 */, 19 },
- /* 7870 */ { MAD_F(0x04c6fd83) /* 0.298581612 */, 19 },
- /* 7871 */ { MAD_F(0x04c7328e) /* 0.298632199 */, 19 },
-
- /* 7872 */ { MAD_F(0x04c7679a) /* 0.298682788 */, 19 },
- /* 7873 */ { MAD_F(0x04c79ca7) /* 0.298733379 */, 19 },
- /* 7874 */ { MAD_F(0x04c7d1b4) /* 0.298783972 */, 19 },
- /* 7875 */ { MAD_F(0x04c806c1) /* 0.298834567 */, 19 },
- /* 7876 */ { MAD_F(0x04c83bcf) /* 0.298885165 */, 19 },
- /* 7877 */ { MAD_F(0x04c870de) /* 0.298935764 */, 19 },
- /* 7878 */ { MAD_F(0x04c8a5ed) /* 0.298986366 */, 19 },
- /* 7879 */ { MAD_F(0x04c8dafd) /* 0.299036970 */, 19 },
- /* 7880 */ { MAD_F(0x04c9100d) /* 0.299087576 */, 19 },
- /* 7881 */ { MAD_F(0x04c9451e) /* 0.299138184 */, 19 },
- /* 7882 */ { MAD_F(0x04c97a30) /* 0.299188794 */, 19 },
- /* 7883 */ { MAD_F(0x04c9af42) /* 0.299239406 */, 19 },
- /* 7884 */ { MAD_F(0x04c9e455) /* 0.299290021 */, 19 },
- /* 7885 */ { MAD_F(0x04ca1968) /* 0.299340638 */, 19 },
- /* 7886 */ { MAD_F(0x04ca4e7c) /* 0.299391256 */, 19 },
- /* 7887 */ { MAD_F(0x04ca8391) /* 0.299441877 */, 19 },
-
- /* 7888 */ { MAD_F(0x04cab8a6) /* 0.299492500 */, 19 },
- /* 7889 */ { MAD_F(0x04caedbb) /* 0.299543126 */, 19 },
- /* 7890 */ { MAD_F(0x04cb22d1) /* 0.299593753 */, 19 },
- /* 7891 */ { MAD_F(0x04cb57e8) /* 0.299644382 */, 19 },
- /* 7892 */ { MAD_F(0x04cb8d00) /* 0.299695014 */, 19 },
- /* 7893 */ { MAD_F(0x04cbc217) /* 0.299745648 */, 19 },
- /* 7894 */ { MAD_F(0x04cbf730) /* 0.299796284 */, 19 },
- /* 7895 */ { MAD_F(0x04cc2c49) /* 0.299846922 */, 19 },
- /* 7896 */ { MAD_F(0x04cc6163) /* 0.299897562 */, 19 },
- /* 7897 */ { MAD_F(0x04cc967d) /* 0.299948204 */, 19 },
- /* 7898 */ { MAD_F(0x04cccb98) /* 0.299998849 */, 19 },
- /* 7899 */ { MAD_F(0x04cd00b3) /* 0.300049495 */, 19 },
- /* 7900 */ { MAD_F(0x04cd35cf) /* 0.300100144 */, 19 },
- /* 7901 */ { MAD_F(0x04cd6aeb) /* 0.300150795 */, 19 },
- /* 7902 */ { MAD_F(0x04cda008) /* 0.300201448 */, 19 },
- /* 7903 */ { MAD_F(0x04cdd526) /* 0.300252103 */, 19 },
-
- /* 7904 */ { MAD_F(0x04ce0a44) /* 0.300302761 */, 19 },
- /* 7905 */ { MAD_F(0x04ce3f63) /* 0.300353420 */, 19 },
- /* 7906 */ { MAD_F(0x04ce7482) /* 0.300404082 */, 19 },
- /* 7907 */ { MAD_F(0x04cea9a2) /* 0.300454745 */, 19 },
- /* 7908 */ { MAD_F(0x04cedec3) /* 0.300505411 */, 19 },
- /* 7909 */ { MAD_F(0x04cf13e4) /* 0.300556079 */, 19 },
- /* 7910 */ { MAD_F(0x04cf4906) /* 0.300606749 */, 19 },
- /* 7911 */ { MAD_F(0x04cf7e28) /* 0.300657421 */, 19 },
- /* 7912 */ { MAD_F(0x04cfb34b) /* 0.300708096 */, 19 },
- /* 7913 */ { MAD_F(0x04cfe86e) /* 0.300758772 */, 19 },
- /* 7914 */ { MAD_F(0x04d01d92) /* 0.300809451 */, 19 },
- /* 7915 */ { MAD_F(0x04d052b6) /* 0.300860132 */, 19 },
- /* 7916 */ { MAD_F(0x04d087db) /* 0.300910815 */, 19 },
- /* 7917 */ { MAD_F(0x04d0bd01) /* 0.300961500 */, 19 },
- /* 7918 */ { MAD_F(0x04d0f227) /* 0.301012187 */, 19 },
- /* 7919 */ { MAD_F(0x04d1274e) /* 0.301062876 */, 19 },
-
- /* 7920 */ { MAD_F(0x04d15c76) /* 0.301113568 */, 19 },
- /* 7921 */ { MAD_F(0x04d1919e) /* 0.301164261 */, 19 },
- /* 7922 */ { MAD_F(0x04d1c6c6) /* 0.301214957 */, 19 },
- /* 7923 */ { MAD_F(0x04d1fbef) /* 0.301265655 */, 19 },
- /* 7924 */ { MAD_F(0x04d23119) /* 0.301316355 */, 19 },
- /* 7925 */ { MAD_F(0x04d26643) /* 0.301367057 */, 19 },
- /* 7926 */ { MAD_F(0x04d29b6e) /* 0.301417761 */, 19 },
- /* 7927 */ { MAD_F(0x04d2d099) /* 0.301468468 */, 19 },
- /* 7928 */ { MAD_F(0x04d305c5) /* 0.301519176 */, 19 },
- /* 7929 */ { MAD_F(0x04d33af2) /* 0.301569887 */, 19 },
- /* 7930 */ { MAD_F(0x04d3701f) /* 0.301620599 */, 19 },
- /* 7931 */ { MAD_F(0x04d3a54d) /* 0.301671314 */, 19 },
- /* 7932 */ { MAD_F(0x04d3da7b) /* 0.301722031 */, 19 },
- /* 7933 */ { MAD_F(0x04d40faa) /* 0.301772751 */, 19 },
- /* 7934 */ { MAD_F(0x04d444d9) /* 0.301823472 */, 19 },
- /* 7935 */ { MAD_F(0x04d47a09) /* 0.301874195 */, 19 },
-
- /* 7936 */ { MAD_F(0x04d4af3a) /* 0.301924921 */, 19 },
- /* 7937 */ { MAD_F(0x04d4e46b) /* 0.301975649 */, 19 },
- /* 7938 */ { MAD_F(0x04d5199c) /* 0.302026378 */, 19 },
- /* 7939 */ { MAD_F(0x04d54ecf) /* 0.302077110 */, 19 },
- /* 7940 */ { MAD_F(0x04d58401) /* 0.302127845 */, 19 },
- /* 7941 */ { MAD_F(0x04d5b935) /* 0.302178581 */, 19 },
- /* 7942 */ { MAD_F(0x04d5ee69) /* 0.302229319 */, 19 },
- /* 7943 */ { MAD_F(0x04d6239d) /* 0.302280060 */, 19 },
- /* 7944 */ { MAD_F(0x04d658d2) /* 0.302330802 */, 19 },
- /* 7945 */ { MAD_F(0x04d68e08) /* 0.302381547 */, 19 },
- /* 7946 */ { MAD_F(0x04d6c33e) /* 0.302432294 */, 19 },
- /* 7947 */ { MAD_F(0x04d6f875) /* 0.302483043 */, 19 },
- /* 7948 */ { MAD_F(0x04d72dad) /* 0.302533794 */, 19 },
- /* 7949 */ { MAD_F(0x04d762e5) /* 0.302584547 */, 19 },
- /* 7950 */ { MAD_F(0x04d7981d) /* 0.302635303 */, 19 },
- /* 7951 */ { MAD_F(0x04d7cd56) /* 0.302686060 */, 19 },
-
- /* 7952 */ { MAD_F(0x04d80290) /* 0.302736820 */, 19 },
- /* 7953 */ { MAD_F(0x04d837ca) /* 0.302787581 */, 19 },
- /* 7954 */ { MAD_F(0x04d86d05) /* 0.302838345 */, 19 },
- /* 7955 */ { MAD_F(0x04d8a240) /* 0.302889111 */, 19 },
- /* 7956 */ { MAD_F(0x04d8d77c) /* 0.302939879 */, 19 },
- /* 7957 */ { MAD_F(0x04d90cb9) /* 0.302990650 */, 19 },
- /* 7958 */ { MAD_F(0x04d941f6) /* 0.303041422 */, 19 },
- /* 7959 */ { MAD_F(0x04d97734) /* 0.303092197 */, 19 },
- /* 7960 */ { MAD_F(0x04d9ac72) /* 0.303142973 */, 19 },
- /* 7961 */ { MAD_F(0x04d9e1b1) /* 0.303193752 */, 19 },
- /* 7962 */ { MAD_F(0x04da16f0) /* 0.303244533 */, 19 },
- /* 7963 */ { MAD_F(0x04da4c30) /* 0.303295316 */, 19 },
- /* 7964 */ { MAD_F(0x04da8171) /* 0.303346101 */, 19 },
- /* 7965 */ { MAD_F(0x04dab6b2) /* 0.303396889 */, 19 },
- /* 7966 */ { MAD_F(0x04daebf4) /* 0.303447678 */, 19 },
- /* 7967 */ { MAD_F(0x04db2136) /* 0.303498469 */, 19 },
-
- /* 7968 */ { MAD_F(0x04db5679) /* 0.303549263 */, 19 },
- /* 7969 */ { MAD_F(0x04db8bbc) /* 0.303600059 */, 19 },
- /* 7970 */ { MAD_F(0x04dbc100) /* 0.303650857 */, 19 },
- /* 7971 */ { MAD_F(0x04dbf644) /* 0.303701657 */, 19 },
- /* 7972 */ { MAD_F(0x04dc2b8a) /* 0.303752459 */, 19 },
- /* 7973 */ { MAD_F(0x04dc60cf) /* 0.303803263 */, 19 },
- /* 7974 */ { MAD_F(0x04dc9616) /* 0.303854070 */, 19 },
- /* 7975 */ { MAD_F(0x04dccb5c) /* 0.303904878 */, 19 },
- /* 7976 */ { MAD_F(0x04dd00a4) /* 0.303955689 */, 19 },
- /* 7977 */ { MAD_F(0x04dd35ec) /* 0.304006502 */, 19 },
- /* 7978 */ { MAD_F(0x04dd6b34) /* 0.304057317 */, 19 },
- /* 7979 */ { MAD_F(0x04dda07d) /* 0.304108134 */, 19 },
- /* 7980 */ { MAD_F(0x04ddd5c7) /* 0.304158953 */, 19 },
- /* 7981 */ { MAD_F(0x04de0b11) /* 0.304209774 */, 19 },
- /* 7982 */ { MAD_F(0x04de405c) /* 0.304260597 */, 19 },
- /* 7983 */ { MAD_F(0x04de75a7) /* 0.304311423 */, 19 },
-
- /* 7984 */ { MAD_F(0x04deaaf3) /* 0.304362251 */, 19 },
- /* 7985 */ { MAD_F(0x04dee040) /* 0.304413080 */, 19 },
- /* 7986 */ { MAD_F(0x04df158d) /* 0.304463912 */, 19 },
- /* 7987 */ { MAD_F(0x04df4adb) /* 0.304514746 */, 19 },
- /* 7988 */ { MAD_F(0x04df8029) /* 0.304565582 */, 19 },
- /* 7989 */ { MAD_F(0x04dfb578) /* 0.304616421 */, 19 },
- /* 7990 */ { MAD_F(0x04dfeac7) /* 0.304667261 */, 19 },
- /* 7991 */ { MAD_F(0x04e02017) /* 0.304718103 */, 19 },
- /* 7992 */ { MAD_F(0x04e05567) /* 0.304768948 */, 19 },
- /* 7993 */ { MAD_F(0x04e08ab8) /* 0.304819795 */, 19 },
- /* 7994 */ { MAD_F(0x04e0c00a) /* 0.304870644 */, 19 },
- /* 7995 */ { MAD_F(0x04e0f55c) /* 0.304921495 */, 19 },
- /* 7996 */ { MAD_F(0x04e12aaf) /* 0.304972348 */, 19 },
- /* 7997 */ { MAD_F(0x04e16002) /* 0.305023203 */, 19 },
- /* 7998 */ { MAD_F(0x04e19556) /* 0.305074060 */, 19 },
- /* 7999 */ { MAD_F(0x04e1caab) /* 0.305124920 */, 19 },
-
- /* 8000 */ { MAD_F(0x04e20000) /* 0.305175781 */, 19 },
- /* 8001 */ { MAD_F(0x04e23555) /* 0.305226645 */, 19 },
- /* 8002 */ { MAD_F(0x04e26aac) /* 0.305277511 */, 19 },
- /* 8003 */ { MAD_F(0x04e2a002) /* 0.305328379 */, 19 },
- /* 8004 */ { MAD_F(0x04e2d55a) /* 0.305379249 */, 19 },
- /* 8005 */ { MAD_F(0x04e30ab2) /* 0.305430121 */, 19 },
- /* 8006 */ { MAD_F(0x04e3400a) /* 0.305480995 */, 19 },
- /* 8007 */ { MAD_F(0x04e37563) /* 0.305531872 */, 19 },
- /* 8008 */ { MAD_F(0x04e3aabd) /* 0.305582750 */, 19 },
- /* 8009 */ { MAD_F(0x04e3e017) /* 0.305633631 */, 19 },
- /* 8010 */ { MAD_F(0x04e41572) /* 0.305684513 */, 19 },
- /* 8011 */ { MAD_F(0x04e44acd) /* 0.305735398 */, 19 },
- /* 8012 */ { MAD_F(0x04e48029) /* 0.305786285 */, 19 },
- /* 8013 */ { MAD_F(0x04e4b585) /* 0.305837174 */, 19 },
- /* 8014 */ { MAD_F(0x04e4eae2) /* 0.305888066 */, 19 },
- /* 8015 */ { MAD_F(0x04e52040) /* 0.305938959 */, 19 },
-
- /* 8016 */ { MAD_F(0x04e5559e) /* 0.305989854 */, 19 },
- /* 8017 */ { MAD_F(0x04e58afd) /* 0.306040752 */, 19 },
- /* 8018 */ { MAD_F(0x04e5c05c) /* 0.306091652 */, 19 },
- /* 8019 */ { MAD_F(0x04e5f5bc) /* 0.306142554 */, 19 },
- /* 8020 */ { MAD_F(0x04e62b1c) /* 0.306193457 */, 19 },
- /* 8021 */ { MAD_F(0x04e6607d) /* 0.306244364 */, 19 },
- /* 8022 */ { MAD_F(0x04e695df) /* 0.306295272 */, 19 },
- /* 8023 */ { MAD_F(0x04e6cb41) /* 0.306346182 */, 19 },
- /* 8024 */ { MAD_F(0x04e700a3) /* 0.306397094 */, 19 },
- /* 8025 */ { MAD_F(0x04e73607) /* 0.306448009 */, 19 },
- /* 8026 */ { MAD_F(0x04e76b6b) /* 0.306498925 */, 19 },
- /* 8027 */ { MAD_F(0x04e7a0cf) /* 0.306549844 */, 19 },
- /* 8028 */ { MAD_F(0x04e7d634) /* 0.306600765 */, 19 },
- /* 8029 */ { MAD_F(0x04e80b99) /* 0.306651688 */, 19 },
- /* 8030 */ { MAD_F(0x04e84100) /* 0.306702613 */, 19 },
- /* 8031 */ { MAD_F(0x04e87666) /* 0.306753540 */, 19 },
-
- /* 8032 */ { MAD_F(0x04e8abcd) /* 0.306804470 */, 19 },
- /* 8033 */ { MAD_F(0x04e8e135) /* 0.306855401 */, 19 },
- /* 8034 */ { MAD_F(0x04e9169e) /* 0.306906334 */, 19 },
- /* 8035 */ { MAD_F(0x04e94c07) /* 0.306957270 */, 19 },
- /* 8036 */ { MAD_F(0x04e98170) /* 0.307008208 */, 19 },
- /* 8037 */ { MAD_F(0x04e9b6da) /* 0.307059148 */, 19 },
- /* 8038 */ { MAD_F(0x04e9ec45) /* 0.307110090 */, 19 },
- /* 8039 */ { MAD_F(0x04ea21b0) /* 0.307161034 */, 19 },
- /* 8040 */ { MAD_F(0x04ea571c) /* 0.307211980 */, 19 },
- /* 8041 */ { MAD_F(0x04ea8c88) /* 0.307262928 */, 19 },
- /* 8042 */ { MAD_F(0x04eac1f5) /* 0.307313879 */, 19 },
- /* 8043 */ { MAD_F(0x04eaf762) /* 0.307364831 */, 19 },
- /* 8044 */ { MAD_F(0x04eb2cd0) /* 0.307415786 */, 19 },
- /* 8045 */ { MAD_F(0x04eb623f) /* 0.307466743 */, 19 },
- /* 8046 */ { MAD_F(0x04eb97ae) /* 0.307517702 */, 19 },
- /* 8047 */ { MAD_F(0x04ebcd1e) /* 0.307568663 */, 19 },
-
- /* 8048 */ { MAD_F(0x04ec028e) /* 0.307619626 */, 19 },
- /* 8049 */ { MAD_F(0x04ec37ff) /* 0.307670591 */, 19 },
- /* 8050 */ { MAD_F(0x04ec6d71) /* 0.307721558 */, 19 },
- /* 8051 */ { MAD_F(0x04eca2e3) /* 0.307772528 */, 19 },
- /* 8052 */ { MAD_F(0x04ecd855) /* 0.307823499 */, 19 },
- /* 8053 */ { MAD_F(0x04ed0dc8) /* 0.307874473 */, 19 },
- /* 8054 */ { MAD_F(0x04ed433c) /* 0.307925449 */, 19 },
- /* 8055 */ { MAD_F(0x04ed78b0) /* 0.307976426 */, 19 },
- /* 8056 */ { MAD_F(0x04edae25) /* 0.308027406 */, 19 },
- /* 8057 */ { MAD_F(0x04ede39a) /* 0.308078389 */, 19 },
- /* 8058 */ { MAD_F(0x04ee1910) /* 0.308129373 */, 19 },
- /* 8059 */ { MAD_F(0x04ee4e87) /* 0.308180359 */, 19 },
- /* 8060 */ { MAD_F(0x04ee83fe) /* 0.308231347 */, 19 },
- /* 8061 */ { MAD_F(0x04eeb976) /* 0.308282338 */, 19 },
- /* 8062 */ { MAD_F(0x04eeeeee) /* 0.308333331 */, 19 },
- /* 8063 */ { MAD_F(0x04ef2467) /* 0.308384325 */, 19 },
-
- /* 8064 */ { MAD_F(0x04ef59e0) /* 0.308435322 */, 19 },
- /* 8065 */ { MAD_F(0x04ef8f5a) /* 0.308486321 */, 19 },
- /* 8066 */ { MAD_F(0x04efc4d5) /* 0.308537322 */, 19 },
- /* 8067 */ { MAD_F(0x04effa50) /* 0.308588325 */, 19 },
- /* 8068 */ { MAD_F(0x04f02fcb) /* 0.308639331 */, 19 },
- /* 8069 */ { MAD_F(0x04f06547) /* 0.308690338 */, 19 },
- /* 8070 */ { MAD_F(0x04f09ac4) /* 0.308741348 */, 19 },
- /* 8071 */ { MAD_F(0x04f0d041) /* 0.308792359 */, 19 },
- /* 8072 */ { MAD_F(0x04f105bf) /* 0.308843373 */, 19 },
- /* 8073 */ { MAD_F(0x04f13b3e) /* 0.308894389 */, 19 },
- /* 8074 */ { MAD_F(0x04f170bd) /* 0.308945407 */, 19 },
- /* 8075 */ { MAD_F(0x04f1a63c) /* 0.308996427 */, 19 },
- /* 8076 */ { MAD_F(0x04f1dbbd) /* 0.309047449 */, 19 },
- /* 8077 */ { MAD_F(0x04f2113d) /* 0.309098473 */, 19 },
- /* 8078 */ { MAD_F(0x04f246bf) /* 0.309149499 */, 19 },
- /* 8079 */ { MAD_F(0x04f27c40) /* 0.309200528 */, 19 },
-
- /* 8080 */ { MAD_F(0x04f2b1c3) /* 0.309251558 */, 19 },
- /* 8081 */ { MAD_F(0x04f2e746) /* 0.309302591 */, 19 },
- /* 8082 */ { MAD_F(0x04f31cc9) /* 0.309353626 */, 19 },
- /* 8083 */ { MAD_F(0x04f3524d) /* 0.309404663 */, 19 },
- /* 8084 */ { MAD_F(0x04f387d2) /* 0.309455702 */, 19 },
- /* 8085 */ { MAD_F(0x04f3bd57) /* 0.309506743 */, 19 },
- /* 8086 */ { MAD_F(0x04f3f2dd) /* 0.309557786 */, 19 },
- /* 8087 */ { MAD_F(0x04f42864) /* 0.309608831 */, 19 },
- /* 8088 */ { MAD_F(0x04f45dea) /* 0.309659879 */, 19 },
- /* 8089 */ { MAD_F(0x04f49372) /* 0.309710928 */, 19 },
- /* 8090 */ { MAD_F(0x04f4c8fa) /* 0.309761980 */, 19 },
- /* 8091 */ { MAD_F(0x04f4fe83) /* 0.309813033 */, 19 },
- /* 8092 */ { MAD_F(0x04f5340c) /* 0.309864089 */, 19 },
- /* 8093 */ { MAD_F(0x04f56996) /* 0.309915147 */, 19 },
- /* 8094 */ { MAD_F(0x04f59f20) /* 0.309966207 */, 19 },
- /* 8095 */ { MAD_F(0x04f5d4ab) /* 0.310017269 */, 19 },
-
- /* 8096 */ { MAD_F(0x04f60a36) /* 0.310068333 */, 19 },
- /* 8097 */ { MAD_F(0x04f63fc2) /* 0.310119400 */, 19 },
- /* 8098 */ { MAD_F(0x04f6754f) /* 0.310170468 */, 19 },
- /* 8099 */ { MAD_F(0x04f6aadc) /* 0.310221539 */, 19 },
- /* 8100 */ { MAD_F(0x04f6e06a) /* 0.310272611 */, 19 },
- /* 8101 */ { MAD_F(0x04f715f8) /* 0.310323686 */, 19 },
- /* 8102 */ { MAD_F(0x04f74b87) /* 0.310374763 */, 19 },
- /* 8103 */ { MAD_F(0x04f78116) /* 0.310425842 */, 19 },
- /* 8104 */ { MAD_F(0x04f7b6a6) /* 0.310476923 */, 19 },
- /* 8105 */ { MAD_F(0x04f7ec37) /* 0.310528006 */, 19 },
- /* 8106 */ { MAD_F(0x04f821c8) /* 0.310579091 */, 19 },
- /* 8107 */ { MAD_F(0x04f85759) /* 0.310630179 */, 19 },
- /* 8108 */ { MAD_F(0x04f88cec) /* 0.310681268 */, 19 },
- /* 8109 */ { MAD_F(0x04f8c27e) /* 0.310732360 */, 19 },
- /* 8110 */ { MAD_F(0x04f8f812) /* 0.310783453 */, 19 },
- /* 8111 */ { MAD_F(0x04f92da6) /* 0.310834549 */, 19 },
-
- /* 8112 */ { MAD_F(0x04f9633a) /* 0.310885647 */, 19 },
- /* 8113 */ { MAD_F(0x04f998cf) /* 0.310936747 */, 19 },
- /* 8114 */ { MAD_F(0x04f9ce65) /* 0.310987849 */, 19 },
- /* 8115 */ { MAD_F(0x04fa03fb) /* 0.311038953 */, 19 },
- /* 8116 */ { MAD_F(0x04fa3992) /* 0.311090059 */, 19 },
- /* 8117 */ { MAD_F(0x04fa6f29) /* 0.311141168 */, 19 },
- /* 8118 */ { MAD_F(0x04faa4c1) /* 0.311192278 */, 19 },
- /* 8119 */ { MAD_F(0x04fada59) /* 0.311243390 */, 19 },
- /* 8120 */ { MAD_F(0x04fb0ff2) /* 0.311294505 */, 19 },
- /* 8121 */ { MAD_F(0x04fb458c) /* 0.311345622 */, 19 },
- /* 8122 */ { MAD_F(0x04fb7b26) /* 0.311396741 */, 19 },
- /* 8123 */ { MAD_F(0x04fbb0c1) /* 0.311447862 */, 19 },
- /* 8124 */ { MAD_F(0x04fbe65c) /* 0.311498985 */, 19 },
- /* 8125 */ { MAD_F(0x04fc1bf8) /* 0.311550110 */, 19 },
- /* 8126 */ { MAD_F(0x04fc5194) /* 0.311601237 */, 19 },
- /* 8127 */ { MAD_F(0x04fc8731) /* 0.311652366 */, 19 },
-
- /* 8128 */ { MAD_F(0x04fcbcce) /* 0.311703498 */, 19 },
- /* 8129 */ { MAD_F(0x04fcf26c) /* 0.311754631 */, 19 },
- /* 8130 */ { MAD_F(0x04fd280b) /* 0.311805767 */, 19 },
- /* 8131 */ { MAD_F(0x04fd5daa) /* 0.311856905 */, 19 },
- /* 8132 */ { MAD_F(0x04fd934a) /* 0.311908044 */, 19 },
- /* 8133 */ { MAD_F(0x04fdc8ea) /* 0.311959186 */, 19 },
- /* 8134 */ { MAD_F(0x04fdfe8b) /* 0.312010330 */, 19 },
- /* 8135 */ { MAD_F(0x04fe342c) /* 0.312061476 */, 19 },
- /* 8136 */ { MAD_F(0x04fe69ce) /* 0.312112625 */, 19 },
- /* 8137 */ { MAD_F(0x04fe9f71) /* 0.312163775 */, 19 },
- /* 8138 */ { MAD_F(0x04fed514) /* 0.312214927 */, 19 },
- /* 8139 */ { MAD_F(0x04ff0ab8) /* 0.312266082 */, 19 },
- /* 8140 */ { MAD_F(0x04ff405c) /* 0.312317238 */, 19 },
- /* 8141 */ { MAD_F(0x04ff7601) /* 0.312368397 */, 19 },
- /* 8142 */ { MAD_F(0x04ffaba6) /* 0.312419558 */, 19 },
- /* 8143 */ { MAD_F(0x04ffe14c) /* 0.312470720 */, 19 },
-
- /* 8144 */ { MAD_F(0x050016f3) /* 0.312521885 */, 19 },
- /* 8145 */ { MAD_F(0x05004c9a) /* 0.312573052 */, 19 },
- /* 8146 */ { MAD_F(0x05008241) /* 0.312624222 */, 19 },
- /* 8147 */ { MAD_F(0x0500b7e9) /* 0.312675393 */, 19 },
- /* 8148 */ { MAD_F(0x0500ed92) /* 0.312726566 */, 19 },
- /* 8149 */ { MAD_F(0x0501233b) /* 0.312777742 */, 19 },
- /* 8150 */ { MAD_F(0x050158e5) /* 0.312828919 */, 19 },
- /* 8151 */ { MAD_F(0x05018e90) /* 0.312880099 */, 19 },
- /* 8152 */ { MAD_F(0x0501c43b) /* 0.312931280 */, 19 },
- /* 8153 */ { MAD_F(0x0501f9e6) /* 0.312982464 */, 19 },
- /* 8154 */ { MAD_F(0x05022f92) /* 0.313033650 */, 19 },
- /* 8155 */ { MAD_F(0x0502653f) /* 0.313084838 */, 19 },
- /* 8156 */ { MAD_F(0x05029aec) /* 0.313136028 */, 19 },
- /* 8157 */ { MAD_F(0x0502d09a) /* 0.313187220 */, 19 },
- /* 8158 */ { MAD_F(0x05030648) /* 0.313238414 */, 19 },
- /* 8159 */ { MAD_F(0x05033bf7) /* 0.313289611 */, 19 },
-
- /* 8160 */ { MAD_F(0x050371a7) /* 0.313340809 */, 19 },
- /* 8161 */ { MAD_F(0x0503a757) /* 0.313392010 */, 19 },
- /* 8162 */ { MAD_F(0x0503dd07) /* 0.313443212 */, 19 },
- /* 8163 */ { MAD_F(0x050412b9) /* 0.313494417 */, 19 },
- /* 8164 */ { MAD_F(0x0504486a) /* 0.313545624 */, 19 },
- /* 8165 */ { MAD_F(0x05047e1d) /* 0.313596833 */, 19 },
- /* 8166 */ { MAD_F(0x0504b3cf) /* 0.313648044 */, 19 },
- /* 8167 */ { MAD_F(0x0504e983) /* 0.313699257 */, 19 },
- /* 8168 */ { MAD_F(0x05051f37) /* 0.313750472 */, 19 },
- /* 8169 */ { MAD_F(0x050554eb) /* 0.313801689 */, 19 },
- /* 8170 */ { MAD_F(0x05058aa0) /* 0.313852909 */, 19 },
- /* 8171 */ { MAD_F(0x0505c056) /* 0.313904130 */, 19 },
- /* 8172 */ { MAD_F(0x0505f60c) /* 0.313955354 */, 19 },
- /* 8173 */ { MAD_F(0x05062bc3) /* 0.314006579 */, 19 },
- /* 8174 */ { MAD_F(0x0506617a) /* 0.314057807 */, 19 },
- /* 8175 */ { MAD_F(0x05069732) /* 0.314109037 */, 19 },
-
- /* 8176 */ { MAD_F(0x0506cceb) /* 0.314160269 */, 19 },
- /* 8177 */ { MAD_F(0x050702a4) /* 0.314211502 */, 19 },
- /* 8178 */ { MAD_F(0x0507385d) /* 0.314262739 */, 19 },
- /* 8179 */ { MAD_F(0x05076e17) /* 0.314313977 */, 19 },
- /* 8180 */ { MAD_F(0x0507a3d2) /* 0.314365217 */, 19 },
- /* 8181 */ { MAD_F(0x0507d98d) /* 0.314416459 */, 19 },
- /* 8182 */ { MAD_F(0x05080f49) /* 0.314467704 */, 19 },
- /* 8183 */ { MAD_F(0x05084506) /* 0.314518950 */, 19 },
- /* 8184 */ { MAD_F(0x05087ac2) /* 0.314570199 */, 19 },
- /* 8185 */ { MAD_F(0x0508b080) /* 0.314621449 */, 19 },
- /* 8186 */ { MAD_F(0x0508e63e) /* 0.314672702 */, 19 },
- /* 8187 */ { MAD_F(0x05091bfd) /* 0.314723957 */, 19 },
- /* 8188 */ { MAD_F(0x050951bc) /* 0.314775214 */, 19 },
- /* 8189 */ { MAD_F(0x0509877c) /* 0.314826473 */, 19 },
- /* 8190 */ { MAD_F(0x0509bd3c) /* 0.314877734 */, 19 },
- /* 8191 */ { MAD_F(0x0509f2fd) /* 0.314928997 */, 19 },
-
- /* 8192 */ { MAD_F(0x050a28be) /* 0.314980262 */, 19 },
- /* 8193 */ { MAD_F(0x050a5e80) /* 0.315031530 */, 19 },
- /* 8194 */ { MAD_F(0x050a9443) /* 0.315082799 */, 19 },
- /* 8195 */ { MAD_F(0x050aca06) /* 0.315134071 */, 19 },
- /* 8196 */ { MAD_F(0x050affc9) /* 0.315185344 */, 19 },
- /* 8197 */ { MAD_F(0x050b358e) /* 0.315236620 */, 19 },
- /* 8198 */ { MAD_F(0x050b6b52) /* 0.315287898 */, 19 },
- /* 8199 */ { MAD_F(0x050ba118) /* 0.315339178 */, 19 },
- /* 8200 */ { MAD_F(0x050bd6de) /* 0.315390460 */, 19 },
- /* 8201 */ { MAD_F(0x050c0ca4) /* 0.315441744 */, 19 },
- /* 8202 */ { MAD_F(0x050c426b) /* 0.315493030 */, 19 },
- /* 8203 */ { MAD_F(0x050c7833) /* 0.315544318 */, 19 },
- /* 8204 */ { MAD_F(0x050cadfb) /* 0.315595608 */, 19 },
- /* 8205 */ { MAD_F(0x050ce3c4) /* 0.315646901 */, 19 },
- /* 8206 */ { MAD_F(0x050d198d) /* 0.315698195 */, 19 }
diff --git a/src/libmad/sf_table.dat b/src/libmad/sf_table.dat
deleted file mode 100644
index ea7a1c191..000000000
--- a/src/libmad/sf_table.dat
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * libmad - MPEG audio decoder library
- * Copyright (C) 2000-2001 Robert Leslie
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: sf_table.dat,v 1.2 2002/04/30 18:46:58 miguelfreitas Exp $
- */
-
-/*
- * These are the scalefactor values for Layer I and Layer II.
- * The values are from Table B.1 of ISO/IEC 11172-3.
- *
- * There is some error introduced by the 32-bit fixed-point representation;
- * the amount of error is shown. For 16-bit PCM output, this shouldn't be
- * too much of a problem.
- */
-
- MAD_F(0x20000000), /* 2.000000000000 => 2.000000000000, e 0.000000000000 */
- MAD_F(0x1965fea5), /* 1.587401051968 => 1.587401051074, e 0.000000000894 */
- MAD_F(0x1428a2fa), /* 1.259921049895 => 1.259921051562, e -0.000000001667 */
- MAD_F(0x10000000), /* 1.000000000000 => 1.000000000000, e 0.000000000000 */
- MAD_F(0x0cb2ff53), /* 0.793700525984 => 0.793700527400, e -0.000000001416 */
- MAD_F(0x0a14517d), /* 0.629960524947 => 0.629960525781, e -0.000000000833 */
- MAD_F(0x08000000), /* 0.500000000000 => 0.500000000000, e 0.000000000000 */
- MAD_F(0x06597fa9), /* 0.396850262992 => 0.396850261837, e 0.000000001155 */
-
- MAD_F(0x050a28be), /* 0.314980262474 => 0.314980261028, e 0.000000001446 */
- MAD_F(0x04000000), /* 0.250000000000 => 0.250000000000, e 0.000000000000 */
- MAD_F(0x032cbfd5), /* 0.198425131496 => 0.198425132781, e -0.000000001285 */
- MAD_F(0x0285145f), /* 0.157490131237 => 0.157490130514, e 0.000000000723 */
- MAD_F(0x02000000), /* 0.125000000000 => 0.125000000000, e 0.000000000000 */
- MAD_F(0x01965fea), /* 0.099212565748 => 0.099212564528, e 0.000000001220 */
- MAD_F(0x01428a30), /* 0.078745065618 => 0.078745067120, e -0.000000001501 */
- MAD_F(0x01000000), /* 0.062500000000 => 0.062500000000, e 0.000000000000 */
-
- MAD_F(0x00cb2ff5), /* 0.049606282874 => 0.049606282264, e 0.000000000610 */
- MAD_F(0x00a14518), /* 0.039372532809 => 0.039372533560, e -0.000000000751 */
- MAD_F(0x00800000), /* 0.031250000000 => 0.031250000000, e 0.000000000000 */
- MAD_F(0x006597fb), /* 0.024803141437 => 0.024803142995, e -0.000000001558 */
- MAD_F(0x0050a28c), /* 0.019686266405 => 0.019686266780, e -0.000000000375 */
- MAD_F(0x00400000), /* 0.015625000000 => 0.015625000000, e 0.000000000000 */
- MAD_F(0x0032cbfd), /* 0.012401570719 => 0.012401569635, e 0.000000001084 */
- MAD_F(0x00285146), /* 0.009843133202 => 0.009843133390, e -0.000000000188 */
-
- MAD_F(0x00200000), /* 0.007812500000 => 0.007812500000, e 0.000000000000 */
- MAD_F(0x001965ff), /* 0.006200785359 => 0.006200786680, e -0.000000001321 */
- MAD_F(0x001428a3), /* 0.004921566601 => 0.004921566695, e -0.000000000094 */
- MAD_F(0x00100000), /* 0.003906250000 => 0.003906250000, e 0.000000000000 */
- MAD_F(0x000cb2ff), /* 0.003100392680 => 0.003100391477, e 0.000000001202 */
- MAD_F(0x000a1451), /* 0.002460783301 => 0.002460781485, e 0.000000001816 */
- MAD_F(0x00080000), /* 0.001953125000 => 0.001953125000, e 0.000000000000 */
- MAD_F(0x00065980), /* 0.001550196340 => 0.001550197601, e -0.000000001262 */
-
- MAD_F(0x00050a29), /* 0.001230391650 => 0.001230392605, e -0.000000000955 */
- MAD_F(0x00040000), /* 0.000976562500 => 0.000976562500, e 0.000000000000 */
- MAD_F(0x00032cc0), /* 0.000775098170 => 0.000775098801, e -0.000000000631 */
- MAD_F(0x00028514), /* 0.000615195825 => 0.000615194440, e 0.000000001385 */
- MAD_F(0x00020000), /* 0.000488281250 => 0.000488281250, e 0.000000000000 */
- MAD_F(0x00019660), /* 0.000387549085 => 0.000387549400, e -0.000000000315 */
- MAD_F(0x0001428a), /* 0.000307597913 => 0.000307597220, e 0.000000000693 */
- MAD_F(0x00010000), /* 0.000244140625 => 0.000244140625, e 0.000000000000 */
-
- MAD_F(0x0000cb30), /* 0.000193774542 => 0.000193774700, e -0.000000000158 */
- MAD_F(0x0000a145), /* 0.000153798956 => 0.000153798610, e 0.000000000346 */
- MAD_F(0x00008000), /* 0.000122070313 => 0.000122070313, e 0.000000000000 */
- MAD_F(0x00006598), /* 0.000096887271 => 0.000096887350, e -0.000000000079 */
- MAD_F(0x000050a3), /* 0.000076899478 => 0.000076901168, e -0.000000001689 */
- MAD_F(0x00004000), /* 0.000061035156 => 0.000061035156, e 0.000000000000 */
- MAD_F(0x000032cc), /* 0.000048443636 => 0.000048443675, e -0.000000000039 */
- MAD_F(0x00002851), /* 0.000038449739 => 0.000038448721, e 0.000000001018 */
-
- MAD_F(0x00002000), /* 0.000030517578 => 0.000030517578, e 0.000000000000 */
- MAD_F(0x00001966), /* 0.000024221818 => 0.000024221838, e -0.000000000020 */
- MAD_F(0x00001429), /* 0.000019224870 => 0.000019226223, e -0.000000001354 */
- MAD_F(0x00001000), /* 0.000015258789 => 0.000015258789, e -0.000000000000 */
- MAD_F(0x00000cb3), /* 0.000012110909 => 0.000012110919, e -0.000000000010 */
- MAD_F(0x00000a14), /* 0.000009612435 => 0.000009611249, e 0.000000001186 */
- MAD_F(0x00000800), /* 0.000007629395 => 0.000007629395, e -0.000000000000 */
- MAD_F(0x00000659), /* 0.000006055454 => 0.000006053597, e 0.000000001858 */
-
- MAD_F(0x0000050a), /* 0.000004806217 => 0.000004805624, e 0.000000000593 */
- MAD_F(0x00000400), /* 0.000003814697 => 0.000003814697, e 0.000000000000 */
- MAD_F(0x0000032d), /* 0.000003027727 => 0.000003028661, e -0.000000000934 */
- MAD_F(0x00000285), /* 0.000002403109 => 0.000002402812, e 0.000000000296 */
- MAD_F(0x00000200), /* 0.000001907349 => 0.000001907349, e -0.000000000000 */
- MAD_F(0x00000196), /* 0.000001513864 => 0.000001512468, e 0.000000001396 */
- MAD_F(0x00000143) /* 0.000001201554 => 0.000001203269, e -0.000000001714 */
diff --git a/src/libmad/stream.c b/src/libmad/stream.c
deleted file mode 100644
index fecc87434..000000000
--- a/src/libmad/stream.c
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * libmad - MPEG audio decoder library
- * Copyright (C) 2000-2004 Underbit Technologies, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: stream.c,v 1.3 2004/04/22 00:23:07 miguelfreitas Exp $
- */
-
-# ifdef HAVE_CONFIG_H
-# include "config.h"
-# endif
-
-# include "global.h"
-
-# include <stdlib.h>
-
-# include "bit.h"
-# include "stream.h"
-
-/*
- * NAME: stream->init()
- * DESCRIPTION: initialize stream struct
- */
-void mad_stream_init(struct mad_stream *stream)
-{
- stream->buffer = 0;
- stream->bufend = 0;
- stream->skiplen = 0;
-
- stream->sync = 0;
- stream->freerate = 0;
-
- stream->this_frame = 0;
- stream->next_frame = 0;
- mad_bit_init(&stream->ptr, 0);
-
- mad_bit_init(&stream->anc_ptr, 0);
- stream->anc_bitlen = 0;
-
- stream->main_data = 0;
- stream->md_len = 0;
-
- stream->options = 0;
- stream->error = MAD_ERROR_NONE;
-}
-
-/*
- * NAME: stream->finish()
- * DESCRIPTION: deallocate any dynamic memory associated with stream
- */
-void mad_stream_finish(struct mad_stream *stream)
-{
- if (stream->main_data) {
- free(stream->main_data);
- stream->main_data = 0;
- }
-
- mad_bit_finish(&stream->anc_ptr);
- mad_bit_finish(&stream->ptr);
-}
-
-/*
- * NAME: stream->buffer()
- * DESCRIPTION: set stream buffer pointers
- */
-void mad_stream_buffer(struct mad_stream *stream,
- unsigned char const *buffer, unsigned long length)
-{
- stream->buffer = buffer;
- stream->bufend = buffer + length;
-
- stream->this_frame = buffer;
- stream->next_frame = buffer;
-
- stream->sync = 1;
-
- mad_bit_init(&stream->ptr, buffer);
-}
-
-/*
- * NAME: stream->skip()
- * DESCRIPTION: arrange to skip bytes before the next frame
- */
-void mad_stream_skip(struct mad_stream *stream, unsigned long length)
-{
- stream->skiplen += length;
-}
-
-/*
- * NAME: stream->sync()
- * DESCRIPTION: locate the next stream sync word
- */
-int mad_stream_sync(struct mad_stream *stream)
-{
- register unsigned char const *ptr, *end;
-
- ptr = mad_bit_nextbyte(&stream->ptr);
- end = stream->bufend;
-
- while (ptr < end - 1 &&
- !(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0))
- ++ptr;
-
- if (end - ptr < MAD_BUFFER_GUARD)
- return -1;
-
- mad_bit_init(&stream->ptr, ptr);
-
- return 0;
-}
-
-/*
- * NAME: stream->errorstr()
- * DESCRIPTION: return a string description of the current error condition
- */
-char const *mad_stream_errorstr(struct mad_stream const *stream)
-{
- switch (stream->error) {
- case MAD_ERROR_NONE: return "no error";
-
- case MAD_ERROR_BUFLEN: return "input buffer too small (or EOF)";
- case MAD_ERROR_BUFPTR: return "invalid (null) buffer pointer";
-
- case MAD_ERROR_NOMEM: return "not enough memory";
-
- case MAD_ERROR_LOSTSYNC: return "lost synchronization";
- case MAD_ERROR_BADLAYER: return "reserved header layer value";
- case MAD_ERROR_BADBITRATE: return "forbidden bitrate value";
- case MAD_ERROR_BADSAMPLERATE: return "reserved sample frequency value";
- case MAD_ERROR_BADEMPHASIS: return "reserved emphasis value";
-
- case MAD_ERROR_BADCRC: return "CRC check failed";
- case MAD_ERROR_BADBITALLOC: return "forbidden bit allocation value";
- case MAD_ERROR_BADSCALEFACTOR: return "bad scalefactor index";
- case MAD_ERROR_BADMODE: return "bad bitrate/mode combination";
- case MAD_ERROR_BADFRAMELEN: return "bad frame length";
- case MAD_ERROR_BADBIGVALUES: return "bad big_values count";
- case MAD_ERROR_BADBLOCKTYPE: return "reserved block_type";
- case MAD_ERROR_BADSCFSI: return "bad scalefactor selection info";
- case MAD_ERROR_BADDATAPTR: return "bad main_data_begin pointer";
- case MAD_ERROR_BADPART3LEN: return "bad audio data length";
- case MAD_ERROR_BADHUFFTABLE: return "bad Huffman table select";
- case MAD_ERROR_BADHUFFDATA: return "Huffman data overrun";
- case MAD_ERROR_BADSTEREO: return "incompatible block_type for JS";
- }
-
- return 0;
-}
diff --git a/src/libmad/stream.h b/src/libmad/stream.h
deleted file mode 100644
index b99b87582..000000000
--- a/src/libmad/stream.h
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * libmad - MPEG audio decoder library
- * Copyright (C) 2000-2004 Underbit Technologies, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: stream.h,v 1.3 2004/04/22 00:23:12 miguelfreitas Exp $
- */
-
-# ifndef LIBMAD_STREAM_H
-# define LIBMAD_STREAM_H
-
-# include "bit.h"
-
-# define MAD_BUFFER_GUARD 8
-# define MAD_BUFFER_MDLEN (511 + 2048 + MAD_BUFFER_GUARD)
-
-enum mad_error {
- MAD_ERROR_NONE = 0x0000, /* no error */
-
- MAD_ERROR_BUFLEN = 0x0001, /* input buffer too small (or EOF) */
- MAD_ERROR_BUFPTR = 0x0002, /* invalid (null) buffer pointer */
-
- MAD_ERROR_NOMEM = 0x0031, /* not enough memory */
-
- MAD_ERROR_LOSTSYNC = 0x0101, /* lost synchronization */
- MAD_ERROR_BADLAYER = 0x0102, /* reserved header layer value */
- MAD_ERROR_BADBITRATE = 0x0103, /* forbidden bitrate value */
- MAD_ERROR_BADSAMPLERATE = 0x0104, /* reserved sample frequency value */
- MAD_ERROR_BADEMPHASIS = 0x0105, /* reserved emphasis value */
-
- MAD_ERROR_BADCRC = 0x0201, /* CRC check failed */
- MAD_ERROR_BADBITALLOC = 0x0211, /* forbidden bit allocation value */
- MAD_ERROR_BADSCALEFACTOR = 0x0221, /* bad scalefactor index */
- MAD_ERROR_BADMODE = 0x0222, /* bad bitrate/mode combination */
- MAD_ERROR_BADFRAMELEN = 0x0231, /* bad frame length */
- MAD_ERROR_BADBIGVALUES = 0x0232, /* bad big_values count */
- MAD_ERROR_BADBLOCKTYPE = 0x0233, /* reserved block_type */
- MAD_ERROR_BADSCFSI = 0x0234, /* bad scalefactor selection info */
- MAD_ERROR_BADDATAPTR = 0x0235, /* bad main_data_begin pointer */
- MAD_ERROR_BADPART3LEN = 0x0236, /* bad audio data length */
- MAD_ERROR_BADHUFFTABLE = 0x0237, /* bad Huffman table select */
- MAD_ERROR_BADHUFFDATA = 0x0238, /* Huffman data overrun */
- MAD_ERROR_BADSTEREO = 0x0239 /* incompatible block_type for JS */
-};
-
-# define MAD_RECOVERABLE(error) ((error) & 0xff00)
-
-struct mad_stream {
- unsigned char const *buffer; /* input bitstream buffer */
- unsigned char const *bufend; /* end of buffer */
- unsigned long skiplen; /* bytes to skip before next frame */
-
- int sync; /* stream sync found */
- unsigned long freerate; /* free bitrate (fixed) */
-
- unsigned char const *this_frame; /* start of current frame */
- unsigned char const *next_frame; /* start of next frame */
- struct mad_bitptr ptr; /* current processing bit pointer */
-
- struct mad_bitptr anc_ptr; /* ancillary bits pointer */
- unsigned int anc_bitlen; /* number of ancillary bits */
-
- unsigned char (*main_data)[MAD_BUFFER_MDLEN];
- /* Layer III main_data() */
- unsigned int md_len; /* bytes in main_data */
-
- int options; /* decoding options (see below) */
- enum mad_error error; /* error code (see above) */
-};
-
-enum {
- MAD_OPTION_IGNORECRC = 0x0001, /* ignore CRC errors */
- MAD_OPTION_HALFSAMPLERATE = 0x0002 /* generate PCM at 1/2 sample rate */
-# if 0 /* not yet implemented */
- MAD_OPTION_LEFTCHANNEL = 0x0010, /* decode left channel only */
- MAD_OPTION_RIGHTCHANNEL = 0x0020, /* decode right channel only */
- MAD_OPTION_SINGLECHANNEL = 0x0030 /* combine channels */
-# endif
-};
-
-void mad_stream_init(struct mad_stream *);
-void mad_stream_finish(struct mad_stream *);
-
-# define mad_stream_options(stream, opts) \
- ((void) ((stream)->options = (opts)))
-
-void mad_stream_buffer(struct mad_stream *,
- unsigned char const *, unsigned long);
-void mad_stream_skip(struct mad_stream *, unsigned long);
-
-int mad_stream_sync(struct mad_stream *);
-
-char const *mad_stream_errorstr(struct mad_stream const *);
-
-# endif
diff --git a/src/libmad/synth.c b/src/libmad/synth.c
deleted file mode 100644
index c05ad3efc..000000000
--- a/src/libmad/synth.c
+++ /dev/null
@@ -1,857 +0,0 @@
-/*
- * libmad - MPEG audio decoder library
- * Copyright (C) 2000-2004 Underbit Technologies, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: synth.c,v 1.4 2006/09/26 03:02:20 dgp85 Exp $
- */
-
-# ifdef HAVE_CONFIG_H
-# include "config.h"
-# endif
-
-# include "global.h"
-
-# include "fixed.h"
-# include "frame.h"
-# include "synth.h"
-
-/*
- * NAME: synth->init()
- * DESCRIPTION: initialize synth struct
- */
-void mad_synth_init(struct mad_synth *synth)
-{
- mad_synth_mute(synth);
-
- synth->phase = 0;
-
- synth->pcm.samplerate = 0;
- synth->pcm.channels = 0;
- synth->pcm.length = 0;
-}
-
-/*
- * NAME: synth->mute()
- * DESCRIPTION: zero all polyphase filterbank values, resetting synthesis
- */
-void mad_synth_mute(struct mad_synth *synth)
-{
- unsigned int ch, s, v;
-
- for (ch = 0; ch < 2; ++ch) {
- for (s = 0; s < 16; ++s) {
- for (v = 0; v < 8; ++v) {
- synth->filter[ch][0][0][s][v] = synth->filter[ch][0][1][s][v] =
- synth->filter[ch][1][0][s][v] = synth->filter[ch][1][1][s][v] = 0;
- }
- }
- }
-}
-
-/*
- * An optional optimization called here the Subband Synthesis Optimization
- * (SSO) improves the performance of subband synthesis at the expense of
- * accuracy.
- *
- * The idea is to simplify 32x32->64-bit multiplication to 32x32->32 such
- * that extra scaling and rounding are not necessary. This often allows the
- * compiler to use faster 32-bit multiply-accumulate instructions instead of
- * explicit 64-bit multiply, shift, and add instructions.
- *
- * SSO works like this: a full 32x32->64-bit multiply of two mad_fixed_t
- * values requires the result to be right-shifted 28 bits to be properly
- * scaled to the same fixed-point format. Right shifts can be applied at any
- * time to either operand or to the result, so the optimization involves
- * careful placement of these shifts to minimize the loss of accuracy.
- *
- * First, a 14-bit shift is applied with rounding at compile-time to the D[]
- * table of coefficients for the subband synthesis window. This only loses 2
- * bits of accuracy because the lower 12 bits are always zero. A second
- * 12-bit shift occurs after the DCT calculation. This loses 12 bits of
- * accuracy. Finally, a third 2-bit shift occurs just before the sample is
- * saved in the PCM buffer. 14 + 12 + 2 == 28 bits.
- */
-
-/* FPM_DEFAULT without OPT_SSO will actually lose accuracy and performance */
-
-# if defined(FPM_DEFAULT) && !defined(OPT_SSO)
-# define OPT_SSO
-# endif
-
-/* second SSO shift, with rounding */
-
-# if defined(OPT_SSO)
-# define SHIFT(x) (((x) + (1L << 11)) >> 12)
-# else
-# define SHIFT(x) (x)
-# endif
-
-/* possible DCT speed optimization */
-
-# if defined(OPT_SPEED) && defined(MAD_F_MLX)
-# define OPT_DCTO
-# define MUL(x, y) \
- ({ mad_fixed64hi_t hi; \
- mad_fixed64lo_t lo; \
- MAD_F_MLX(hi, lo, (x), (y)); \
- hi << (32 - MAD_F_SCALEBITS - 3); \
- })
-# else
-# undef OPT_DCTO
-# define MUL(x, y) mad_f_mul((x), (y))
-# endif
-
-/*
- * NAME: dct32()
- * DESCRIPTION: perform fast in[32]->out[32] DCT
- */
-static
-void dct32(mad_fixed_t const in[32], unsigned int slot,
- mad_fixed_t lo[16][8], mad_fixed_t hi[16][8])
-{
- mad_fixed_t t0, t1, t2, t3, t4, t5, t6, t7;
- mad_fixed_t t8, t9, t10, t11, t12, t13, t14, t15;
- mad_fixed_t t16, t17, t18, t19, t20, t21, t22, t23;
- mad_fixed_t t24, t25, t26, t27, t28, t29, t30, t31;
- mad_fixed_t t32, t33, t34, t35, t36, t37, t38, t39;
- mad_fixed_t t40, t41, t42, t43, t44, t45, t46, t47;
- mad_fixed_t t48, t49, t50, t51, t52, t53, t54, t55;
- mad_fixed_t t56, t57, t58, t59, t60, t61, t62, t63;
- mad_fixed_t t64, t65, t66, t67, t68, t69, t70, t71;
- mad_fixed_t t72, t73, t74, t75, t76, t77, t78, t79;
- mad_fixed_t t80, t81, t82, t83, t84, t85, t86, t87;
- mad_fixed_t t88, t89, t90, t91, t92, t93, t94, t95;
- mad_fixed_t t96, t97, t98, t99, t100, t101, t102, t103;
- mad_fixed_t t104, t105, t106, t107, t108, t109, t110, t111;
- mad_fixed_t t112, t113, t114, t115, t116, t117, t118, t119;
- mad_fixed_t t120, t121, t122, t123, t124, t125, t126, t127;
- mad_fixed_t t128, t129, t130, t131, t132, t133, t134, t135;
- mad_fixed_t t136, t137, t138, t139, t140, t141, t142, t143;
- mad_fixed_t t144, t145, t146, t147, t148, t149, t150, t151;
- mad_fixed_t t152, t153, t154, t155, t156, t157, t158, t159;
- mad_fixed_t t160, t161, t162, t163, t164, t165, t166, t167;
- mad_fixed_t t168, t169, t170, t171, t172, t173, t174, t175;
- mad_fixed_t t176;
-
- /* costab[i] = cos(PI / (2 * 32) * i) */
-
-# if defined(OPT_DCTO)
-# define costab1 MAD_F(0x7fd8878e)
-# define costab2 MAD_F(0x7f62368f)
-# define costab3 MAD_F(0x7e9d55fc)
-# define costab4 MAD_F(0x7d8a5f40)
-# define costab5 MAD_F(0x7c29fbee)
-# define costab6 MAD_F(0x7a7d055b)
-# define costab7 MAD_F(0x78848414)
-# define costab8 MAD_F(0x7641af3d)
-# define costab9 MAD_F(0x73b5ebd1)
-# define costab10 MAD_F(0x70e2cbc6)
-# define costab11 MAD_F(0x6dca0d14)
-# define costab12 MAD_F(0x6a6d98a4)
-# define costab13 MAD_F(0x66cf8120)
-# define costab14 MAD_F(0x62f201ac)
-# define costab15 MAD_F(0x5ed77c8a)
-# define costab16 MAD_F(0x5a82799a)
-# define costab17 MAD_F(0x55f5a4d2)
-# define costab18 MAD_F(0x5133cc94)
-# define costab19 MAD_F(0x4c3fdff4)
-# define costab20 MAD_F(0x471cece7)
-# define costab21 MAD_F(0x41ce1e65)
-# define costab22 MAD_F(0x3c56ba70)
-# define costab23 MAD_F(0x36ba2014)
-# define costab24 MAD_F(0x30fbc54d)
-# define costab25 MAD_F(0x2b1f34eb)
-# define costab26 MAD_F(0x25280c5e)
-# define costab27 MAD_F(0x1f19f97b)
-# define costab28 MAD_F(0x18f8b83c)
-# define costab29 MAD_F(0x12c8106f)
-# define costab30 MAD_F(0x0c8bd35e)
-# define costab31 MAD_F(0x0647d97c)
-# else
-# define costab1 MAD_F(0x0ffb10f2) /* 0.998795456 */
-# define costab2 MAD_F(0x0fec46d2) /* 0.995184727 */
-# define costab3 MAD_F(0x0fd3aac0) /* 0.989176510 */
-# define costab4 MAD_F(0x0fb14be8) /* 0.980785280 */
-# define costab5 MAD_F(0x0f853f7e) /* 0.970031253 */
-# define costab6 MAD_F(0x0f4fa0ab) /* 0.956940336 */
-# define costab7 MAD_F(0x0f109082) /* 0.941544065 */
-# define costab8 MAD_F(0x0ec835e8) /* 0.923879533 */
-# define costab9 MAD_F(0x0e76bd7a) /* 0.903989293 */
-# define costab10 MAD_F(0x0e1c5979) /* 0.881921264 */
-# define costab11 MAD_F(0x0db941a3) /* 0.857728610 */
-# define costab12 MAD_F(0x0d4db315) /* 0.831469612 */
-# define costab13 MAD_F(0x0cd9f024) /* 0.803207531 */
-# define costab14 MAD_F(0x0c5e4036) /* 0.773010453 */
-# define costab15 MAD_F(0x0bdaef91) /* 0.740951125 */
-# define costab16 MAD_F(0x0b504f33) /* 0.707106781 */
-# define costab17 MAD_F(0x0abeb49a) /* 0.671558955 */
-# define costab18 MAD_F(0x0a267993) /* 0.634393284 */
-# define costab19 MAD_F(0x0987fbfe) /* 0.595699304 */
-# define costab20 MAD_F(0x08e39d9d) /* 0.555570233 */
-# define costab21 MAD_F(0x0839c3cd) /* 0.514102744 */
-# define costab22 MAD_F(0x078ad74e) /* 0.471396737 */
-# define costab23 MAD_F(0x06d74402) /* 0.427555093 */
-# define costab24 MAD_F(0x061f78aa) /* 0.382683432 */
-# define costab25 MAD_F(0x0563e69d) /* 0.336889853 */
-# define costab26 MAD_F(0x04a5018c) /* 0.290284677 */
-# define costab27 MAD_F(0x03e33f2f) /* 0.242980180 */
-# define costab28 MAD_F(0x031f1708) /* 0.195090322 */
-# define costab29 MAD_F(0x0259020e) /* 0.146730474 */
-# define costab30 MAD_F(0x01917a6c) /* 0.098017140 */
-# define costab31 MAD_F(0x00c8fb30) /* 0.049067674 */
-# endif
-
- t0 = in[0] + in[31]; t16 = MUL(in[0] - in[31], costab1);
- t1 = in[15] + in[16]; t17 = MUL(in[15] - in[16], costab31);
-
- t41 = t16 + t17;
- t59 = MUL(t16 - t17, costab2);
- t33 = t0 + t1;
- t50 = MUL(t0 - t1, costab2);
-
- t2 = in[7] + in[24]; t18 = MUL(in[7] - in[24], costab15);
- t3 = in[8] + in[23]; t19 = MUL(in[8] - in[23], costab17);
-
- t42 = t18 + t19;
- t60 = MUL(t18 - t19, costab30);
- t34 = t2 + t3;
- t51 = MUL(t2 - t3, costab30);
-
- t4 = in[3] + in[28]; t20 = MUL(in[3] - in[28], costab7);
- t5 = in[12] + in[19]; t21 = MUL(in[12] - in[19], costab25);
-
- t43 = t20 + t21;
- t61 = MUL(t20 - t21, costab14);
- t35 = t4 + t5;
- t52 = MUL(t4 - t5, costab14);
-
- t6 = in[4] + in[27]; t22 = MUL(in[4] - in[27], costab9);
- t7 = in[11] + in[20]; t23 = MUL(in[11] - in[20], costab23);
-
- t44 = t22 + t23;
- t62 = MUL(t22 - t23, costab18);
- t36 = t6 + t7;
- t53 = MUL(t6 - t7, costab18);
-
- t8 = in[1] + in[30]; t24 = MUL(in[1] - in[30], costab3);
- t9 = in[14] + in[17]; t25 = MUL(in[14] - in[17], costab29);
-
- t45 = t24 + t25;
- t63 = MUL(t24 - t25, costab6);
- t37 = t8 + t9;
- t54 = MUL(t8 - t9, costab6);
-
- t10 = in[6] + in[25]; t26 = MUL(in[6] - in[25], costab13);
- t11 = in[9] + in[22]; t27 = MUL(in[9] - in[22], costab19);
-
- t46 = t26 + t27;
- t64 = MUL(t26 - t27, costab26);
- t38 = t10 + t11;
- t55 = MUL(t10 - t11, costab26);
-
- t12 = in[2] + in[29]; t28 = MUL(in[2] - in[29], costab5);
- t13 = in[13] + in[18]; t29 = MUL(in[13] - in[18], costab27);
-
- t47 = t28 + t29;
- t65 = MUL(t28 - t29, costab10);
- t39 = t12 + t13;
- t56 = MUL(t12 - t13, costab10);
-
- t14 = in[5] + in[26]; t30 = MUL(in[5] - in[26], costab11);
- t15 = in[10] + in[21]; t31 = MUL(in[10] - in[21], costab21);
-
- t48 = t30 + t31;
- t66 = MUL(t30 - t31, costab22);
- t40 = t14 + t15;
- t57 = MUL(t14 - t15, costab22);
-
- t69 = t33 + t34; t89 = MUL(t33 - t34, costab4);
- t70 = t35 + t36; t90 = MUL(t35 - t36, costab28);
- t71 = t37 + t38; t91 = MUL(t37 - t38, costab12);
- t72 = t39 + t40; t92 = MUL(t39 - t40, costab20);
- t73 = t41 + t42; t94 = MUL(t41 - t42, costab4);
- t74 = t43 + t44; t95 = MUL(t43 - t44, costab28);
- t75 = t45 + t46; t96 = MUL(t45 - t46, costab12);
- t76 = t47 + t48; t97 = MUL(t47 - t48, costab20);
-
- t78 = t50 + t51; t100 = MUL(t50 - t51, costab4);
- t79 = t52 + t53; t101 = MUL(t52 - t53, costab28);
- t80 = t54 + t55; t102 = MUL(t54 - t55, costab12);
- t81 = t56 + t57; t103 = MUL(t56 - t57, costab20);
-
- t83 = t59 + t60; t106 = MUL(t59 - t60, costab4);
- t84 = t61 + t62; t107 = MUL(t61 - t62, costab28);
- t85 = t63 + t64; t108 = MUL(t63 - t64, costab12);
- t86 = t65 + t66; t109 = MUL(t65 - t66, costab20);
-
- t113 = t69 + t70;
- t114 = t71 + t72;
-
- /* 0 */ hi[15][slot] = SHIFT(t113 + t114);
- /* 16 */ lo[ 0][slot] = SHIFT(MUL(t113 - t114, costab16));
-
- t115 = t73 + t74;
- t116 = t75 + t76;
-
- t32 = t115 + t116;
-
- /* 1 */ hi[14][slot] = SHIFT(t32);
-
- t118 = t78 + t79;
- t119 = t80 + t81;
-
- t58 = t118 + t119;
-
- /* 2 */ hi[13][slot] = SHIFT(t58);
-
- t121 = t83 + t84;
- t122 = t85 + t86;
-
- t67 = t121 + t122;
-
- t49 = (t67 * 2) - t32;
-
- /* 3 */ hi[12][slot] = SHIFT(t49);
-
- t125 = t89 + t90;
- t126 = t91 + t92;
-
- t93 = t125 + t126;
-
- /* 4 */ hi[11][slot] = SHIFT(t93);
-
- t128 = t94 + t95;
- t129 = t96 + t97;
-
- t98 = t128 + t129;
-
- t68 = (t98 * 2) - t49;
-
- /* 5 */ hi[10][slot] = SHIFT(t68);
-
- t132 = t100 + t101;
- t133 = t102 + t103;
-
- t104 = t132 + t133;
-
- t82 = (t104 * 2) - t58;
-
- /* 6 */ hi[ 9][slot] = SHIFT(t82);
-
- t136 = t106 + t107;
- t137 = t108 + t109;
-
- t110 = t136 + t137;
-
- t87 = (t110 * 2) - t67;
-
- t77 = (t87 * 2) - t68;
-
- /* 7 */ hi[ 8][slot] = SHIFT(t77);
-
- t141 = MUL(t69 - t70, costab8);
- t142 = MUL(t71 - t72, costab24);
- t143 = t141 + t142;
-
- /* 8 */ hi[ 7][slot] = SHIFT(t143);
- /* 24 */ lo[ 8][slot] =
- SHIFT((MUL(t141 - t142, costab16) * 2) - t143);
-
- t144 = MUL(t73 - t74, costab8);
- t145 = MUL(t75 - t76, costab24);
- t146 = t144 + t145;
-
- t88 = (t146 * 2) - t77;
-
- /* 9 */ hi[ 6][slot] = SHIFT(t88);
-
- t148 = MUL(t78 - t79, costab8);
- t149 = MUL(t80 - t81, costab24);
- t150 = t148 + t149;
-
- t105 = (t150 * 2) - t82;
-
- /* 10 */ hi[ 5][slot] = SHIFT(t105);
-
- t152 = MUL(t83 - t84, costab8);
- t153 = MUL(t85 - t86, costab24);
- t154 = t152 + t153;
-
- t111 = (t154 * 2) - t87;
-
- t99 = (t111 * 2) - t88;
-
- /* 11 */ hi[ 4][slot] = SHIFT(t99);
-
- t157 = MUL(t89 - t90, costab8);
- t158 = MUL(t91 - t92, costab24);
- t159 = t157 + t158;
-
- t127 = (t159 * 2) - t93;
-
- /* 12 */ hi[ 3][slot] = SHIFT(t127);
-
- t160 = (MUL(t125 - t126, costab16) * 2) - t127;
-
- /* 20 */ lo[ 4][slot] = SHIFT(t160);
- /* 28 */ lo[12][slot] =
- SHIFT((((MUL(t157 - t158, costab16) * 2) - t159) * 2) - t160);
-
- t161 = MUL(t94 - t95, costab8);
- t162 = MUL(t96 - t97, costab24);
- t163 = t161 + t162;
-
- t130 = (t163 * 2) - t98;
-
- t112 = (t130 * 2) - t99;
-
- /* 13 */ hi[ 2][slot] = SHIFT(t112);
-
- t164 = (MUL(t128 - t129, costab16) * 2) - t130;
-
- t166 = MUL(t100 - t101, costab8);
- t167 = MUL(t102 - t103, costab24);
- t168 = t166 + t167;
-
- t134 = (t168 * 2) - t104;
-
- t120 = (t134 * 2) - t105;
-
- /* 14 */ hi[ 1][slot] = SHIFT(t120);
-
- t135 = (MUL(t118 - t119, costab16) * 2) - t120;
-
- /* 18 */ lo[ 2][slot] = SHIFT(t135);
-
- t169 = (MUL(t132 - t133, costab16) * 2) - t134;
-
- t151 = (t169 * 2) - t135;
-
- /* 22 */ lo[ 6][slot] = SHIFT(t151);
-
- t170 = (((MUL(t148 - t149, costab16) * 2) - t150) * 2) - t151;
-
- /* 26 */ lo[10][slot] = SHIFT(t170);
- /* 30 */ lo[14][slot] =
- SHIFT((((((MUL(t166 - t167, costab16) * 2) -
- t168) * 2) - t169) * 2) - t170);
-
- t171 = MUL(t106 - t107, costab8);
- t172 = MUL(t108 - t109, costab24);
- t173 = t171 + t172;
-
- t138 = (t173 * 2) - t110;
-
- t123 = (t138 * 2) - t111;
-
- t139 = (MUL(t121 - t122, costab16) * 2) - t123;
-
- t117 = (t123 * 2) - t112;
-
- /* 15 */ hi[ 0][slot] = SHIFT(t117);
-
- t124 = (MUL(t115 - t116, costab16) * 2) - t117;
-
- /* 17 */ lo[ 1][slot] = SHIFT(t124);
-
- t131 = (t139 * 2) - t124;
-
- /* 19 */ lo[ 3][slot] = SHIFT(t131);
-
- t140 = (t164 * 2) - t131;
-
- /* 21 */ lo[ 5][slot] = SHIFT(t140);
-
- t174 = (MUL(t136 - t137, costab16) * 2) - t138;
-
- t155 = (t174 * 2) - t139;
-
- t147 = (t155 * 2) - t140;
-
- /* 23 */ lo[ 7][slot] = SHIFT(t147);
-
- t156 = (((MUL(t144 - t145, costab16) * 2) - t146) * 2) - t147;
-
- /* 25 */ lo[ 9][slot] = SHIFT(t156);
-
- t175 = (((MUL(t152 - t153, costab16) * 2) - t154) * 2) - t155;
-
- t165 = (t175 * 2) - t156;
-
- /* 27 */ lo[11][slot] = SHIFT(t165);
-
- t176 = (((((MUL(t161 - t162, costab16) * 2) -
- t163) * 2) - t164) * 2) - t165;
-
- /* 29 */ lo[13][slot] = SHIFT(t176);
- /* 31 */ lo[15][slot] =
- SHIFT((((((((MUL(t171 - t172, costab16) * 2) -
- t173) * 2) - t174) * 2) - t175) * 2) - t176);
-
- /*
- * Totals:
- * 80 multiplies
- * 80 additions
- * 119 subtractions
- * 49 shifts (not counting SSO)
- */
-}
-
-# undef MUL
-# undef SHIFT
-
-/* third SSO shift and/or D[] optimization preshift */
-
-# if defined(OPT_SSO)
-# if MAD_F_FRACBITS != 28
-# error "MAD_F_FRACBITS must be 28 to use OPT_SSO"
-# endif
-# define ML0(hi, lo, x, y) ((lo) = (x) * (y))
-# define MLA(hi, lo, x, y) ((lo) += (x) * (y))
-# define MLN(hi, lo) ((lo) = -(lo))
-# define MLZ(hi, lo) ((void) (hi), (mad_fixed_t) (lo))
-# define SHIFT(x) ((x) >> 2)
-# define PRESHIFT(x) ((MAD_F(x) + (1L << 13)) >> 14)
-# else
-# define ML0(hi, lo, x, y) MAD_F_ML0((hi), (lo), (x), (y))
-# define MLA(hi, lo, x, y) MAD_F_MLA((hi), (lo), (x), (y))
-# define MLN(hi, lo) MAD_F_MLN((hi), (lo))
-# define MLZ(hi, lo) MAD_F_MLZ((hi), (lo))
-# define SHIFT(x) (x)
-# if defined(MAD_F_SCALEBITS)
-# undef MAD_F_SCALEBITS
-# define MAD_F_SCALEBITS (MAD_F_FRACBITS - 12)
-# define PRESHIFT(x) (MAD_F(x) >> 12)
-# else
-# define PRESHIFT(x) MAD_F(x)
-# endif
-# endif
-
-static
-mad_fixed_t const D[17][32] = {
-# include "D.dat"
-};
-
-# if defined(ASO_SYNTH)
-void synth_full(struct mad_synth *, struct mad_frame const *,
- unsigned int, unsigned int);
-# else
-/*
- * NAME: synth->full()
- * DESCRIPTION: perform full frequency PCM synthesis
- */
-static
-void synth_full(struct mad_synth *synth, struct mad_frame const *frame,
- unsigned int nch, unsigned int ns)
-{
- unsigned int phase, ch, s, sb, pe, po;
- mad_fixed_t *pcm1, *pcm2, (*filter)[2][2][16][8];
- mad_fixed_t const (*sbsample)[36][32];
- register mad_fixed_t (*fe)[8], (*fx)[8], (*fo)[8];
- register mad_fixed_t const (*Dptr)[32], *ptr;
- register mad_fixed64hi_t hi = 0;
- register mad_fixed64lo_t lo = 0;
-
- for (ch = 0; ch < nch; ++ch) {
- sbsample = &frame->sbsample[ch];
- filter = &synth->filter[ch];
- phase = synth->phase;
- pcm1 = synth->pcm.samples[ch];
-
- for (s = 0; s < ns; ++s) {
- dct32((*sbsample)[s], phase >> 1,
- (*filter)[0][phase & 1], (*filter)[1][phase & 1]);
-
- pe = phase & ~1;
- po = ((phase - 1) & 0xf) | 1;
-
- /* calculate 32 samples */
-
- fe = &(*filter)[0][ phase & 1][0];
- fx = &(*filter)[0][~phase & 1][0];
- fo = &(*filter)[1][~phase & 1][0];
-
- Dptr = &D[0];
-
- ptr = *Dptr + po;
- ML0(hi, lo, (*fx)[0], ptr[ 0]);
- MLA(hi, lo, (*fx)[1], ptr[14]);
- MLA(hi, lo, (*fx)[2], ptr[12]);
- MLA(hi, lo, (*fx)[3], ptr[10]);
- MLA(hi, lo, (*fx)[4], ptr[ 8]);
- MLA(hi, lo, (*fx)[5], ptr[ 6]);
- MLA(hi, lo, (*fx)[6], ptr[ 4]);
- MLA(hi, lo, (*fx)[7], ptr[ 2]);
- MLN(hi, lo);
-
- ptr = *Dptr + pe;
- MLA(hi, lo, (*fe)[0], ptr[ 0]);
- MLA(hi, lo, (*fe)[1], ptr[14]);
- MLA(hi, lo, (*fe)[2], ptr[12]);
- MLA(hi, lo, (*fe)[3], ptr[10]);
- MLA(hi, lo, (*fe)[4], ptr[ 8]);
- MLA(hi, lo, (*fe)[5], ptr[ 6]);
- MLA(hi, lo, (*fe)[6], ptr[ 4]);
- MLA(hi, lo, (*fe)[7], ptr[ 2]);
-
- *pcm1++ = SHIFT(MLZ(hi, lo));
-
- pcm2 = pcm1 + 30;
-
- for (sb = 1; sb < 16; ++sb) {
- ++fe;
- ++Dptr;
-
- /* D[32 - sb][i] == -D[sb][31 - i] */
-
- ptr = *Dptr + po;
- ML0(hi, lo, (*fo)[0], ptr[ 0]);
- MLA(hi, lo, (*fo)[1], ptr[14]);
- MLA(hi, lo, (*fo)[2], ptr[12]);
- MLA(hi, lo, (*fo)[3], ptr[10]);
- MLA(hi, lo, (*fo)[4], ptr[ 8]);
- MLA(hi, lo, (*fo)[5], ptr[ 6]);
- MLA(hi, lo, (*fo)[6], ptr[ 4]);
- MLA(hi, lo, (*fo)[7], ptr[ 2]);
- MLN(hi, lo);
-
- ptr = *Dptr + pe;
- MLA(hi, lo, (*fe)[7], ptr[ 2]);
- MLA(hi, lo, (*fe)[6], ptr[ 4]);
- MLA(hi, lo, (*fe)[5], ptr[ 6]);
- MLA(hi, lo, (*fe)[4], ptr[ 8]);
- MLA(hi, lo, (*fe)[3], ptr[10]);
- MLA(hi, lo, (*fe)[2], ptr[12]);
- MLA(hi, lo, (*fe)[1], ptr[14]);
- MLA(hi, lo, (*fe)[0], ptr[ 0]);
-
- *pcm1++ = SHIFT(MLZ(hi, lo));
-
- ptr = *Dptr - pe;
- ML0(hi, lo, (*fe)[0], ptr[31 - 16]);
- MLA(hi, lo, (*fe)[1], ptr[31 - 14]);
- MLA(hi, lo, (*fe)[2], ptr[31 - 12]);
- MLA(hi, lo, (*fe)[3], ptr[31 - 10]);
- MLA(hi, lo, (*fe)[4], ptr[31 - 8]);
- MLA(hi, lo, (*fe)[5], ptr[31 - 6]);
- MLA(hi, lo, (*fe)[6], ptr[31 - 4]);
- MLA(hi, lo, (*fe)[7], ptr[31 - 2]);
-
- ptr = *Dptr - po;
- MLA(hi, lo, (*fo)[7], ptr[31 - 2]);
- MLA(hi, lo, (*fo)[6], ptr[31 - 4]);
- MLA(hi, lo, (*fo)[5], ptr[31 - 6]);
- MLA(hi, lo, (*fo)[4], ptr[31 - 8]);
- MLA(hi, lo, (*fo)[3], ptr[31 - 10]);
- MLA(hi, lo, (*fo)[2], ptr[31 - 12]);
- MLA(hi, lo, (*fo)[1], ptr[31 - 14]);
- MLA(hi, lo, (*fo)[0], ptr[31 - 16]);
-
- *pcm2-- = SHIFT(MLZ(hi, lo));
-
- ++fo;
- }
-
- ++Dptr;
-
- ptr = *Dptr + po;
- ML0(hi, lo, (*fo)[0], ptr[ 0]);
- MLA(hi, lo, (*fo)[1], ptr[14]);
- MLA(hi, lo, (*fo)[2], ptr[12]);
- MLA(hi, lo, (*fo)[3], ptr[10]);
- MLA(hi, lo, (*fo)[4], ptr[ 8]);
- MLA(hi, lo, (*fo)[5], ptr[ 6]);
- MLA(hi, lo, (*fo)[6], ptr[ 4]);
- MLA(hi, lo, (*fo)[7], ptr[ 2]);
-
- *pcm1 = SHIFT(-MLZ(hi, lo));
- pcm1 += 16;
-
- phase = (phase + 1) % 16;
- }
- }
-}
-# endif
-
-/*
- * NAME: synth->half()
- * DESCRIPTION: perform half frequency PCM synthesis
- */
-static
-void synth_half(struct mad_synth *synth, struct mad_frame const *frame,
- unsigned int nch, unsigned int ns)
-{
- unsigned int phase, ch, s, sb, pe, po;
- mad_fixed_t *pcm1, *pcm2, (*filter)[2][2][16][8];
- mad_fixed_t const (*sbsample)[36][32];
- register mad_fixed_t (*fe)[8], (*fx)[8], (*fo)[8];
- register mad_fixed_t const (*Dptr)[32], *ptr;
- register mad_fixed64hi_t hi = 0;
- register mad_fixed64lo_t lo = 0;
-
- for (ch = 0; ch < nch; ++ch) {
- sbsample = &frame->sbsample[ch];
- filter = &synth->filter[ch];
- phase = synth->phase;
- pcm1 = synth->pcm.samples[ch];
-
- for (s = 0; s < ns; ++s) {
- dct32((*sbsample)[s], phase >> 1,
- (*filter)[0][phase & 1], (*filter)[1][phase & 1]);
-
- pe = phase & ~1;
- po = ((phase - 1) & 0xf) | 1;
-
- /* calculate 16 samples */
-
- fe = &(*filter)[0][ phase & 1][0];
- fx = &(*filter)[0][~phase & 1][0];
- fo = &(*filter)[1][~phase & 1][0];
-
- Dptr = &D[0];
-
- ptr = *Dptr + po;
- ML0(hi, lo, (*fx)[0], ptr[ 0]);
- MLA(hi, lo, (*fx)[1], ptr[14]);
- MLA(hi, lo, (*fx)[2], ptr[12]);
- MLA(hi, lo, (*fx)[3], ptr[10]);
- MLA(hi, lo, (*fx)[4], ptr[ 8]);
- MLA(hi, lo, (*fx)[5], ptr[ 6]);
- MLA(hi, lo, (*fx)[6], ptr[ 4]);
- MLA(hi, lo, (*fx)[7], ptr[ 2]);
- MLN(hi, lo);
-
- ptr = *Dptr + pe;
- MLA(hi, lo, (*fe)[0], ptr[ 0]);
- MLA(hi, lo, (*fe)[1], ptr[14]);
- MLA(hi, lo, (*fe)[2], ptr[12]);
- MLA(hi, lo, (*fe)[3], ptr[10]);
- MLA(hi, lo, (*fe)[4], ptr[ 8]);
- MLA(hi, lo, (*fe)[5], ptr[ 6]);
- MLA(hi, lo, (*fe)[6], ptr[ 4]);
- MLA(hi, lo, (*fe)[7], ptr[ 2]);
-
- *pcm1++ = SHIFT(MLZ(hi, lo));
-
- pcm2 = pcm1 + 14;
-
- for (sb = 1; sb < 16; ++sb) {
- ++fe;
- ++Dptr;
-
- /* D[32 - sb][i] == -D[sb][31 - i] */
-
- if (!(sb & 1)) {
- ptr = *Dptr + po;
- ML0(hi, lo, (*fo)[0], ptr[ 0]);
- MLA(hi, lo, (*fo)[1], ptr[14]);
- MLA(hi, lo, (*fo)[2], ptr[12]);
- MLA(hi, lo, (*fo)[3], ptr[10]);
- MLA(hi, lo, (*fo)[4], ptr[ 8]);
- MLA(hi, lo, (*fo)[5], ptr[ 6]);
- MLA(hi, lo, (*fo)[6], ptr[ 4]);
- MLA(hi, lo, (*fo)[7], ptr[ 2]);
- MLN(hi, lo);
-
- ptr = *Dptr + pe;
- MLA(hi, lo, (*fe)[7], ptr[ 2]);
- MLA(hi, lo, (*fe)[6], ptr[ 4]);
- MLA(hi, lo, (*fe)[5], ptr[ 6]);
- MLA(hi, lo, (*fe)[4], ptr[ 8]);
- MLA(hi, lo, (*fe)[3], ptr[10]);
- MLA(hi, lo, (*fe)[2], ptr[12]);
- MLA(hi, lo, (*fe)[1], ptr[14]);
- MLA(hi, lo, (*fe)[0], ptr[ 0]);
-
- *pcm1++ = SHIFT(MLZ(hi, lo));
-
- ptr = *Dptr - po;
- ML0(hi, lo, (*fo)[7], ptr[31 - 2]);
- MLA(hi, lo, (*fo)[6], ptr[31 - 4]);
- MLA(hi, lo, (*fo)[5], ptr[31 - 6]);
- MLA(hi, lo, (*fo)[4], ptr[31 - 8]);
- MLA(hi, lo, (*fo)[3], ptr[31 - 10]);
- MLA(hi, lo, (*fo)[2], ptr[31 - 12]);
- MLA(hi, lo, (*fo)[1], ptr[31 - 14]);
- MLA(hi, lo, (*fo)[0], ptr[31 - 16]);
-
- ptr = *Dptr - pe;
- MLA(hi, lo, (*fe)[0], ptr[31 - 16]);
- MLA(hi, lo, (*fe)[1], ptr[31 - 14]);
- MLA(hi, lo, (*fe)[2], ptr[31 - 12]);
- MLA(hi, lo, (*fe)[3], ptr[31 - 10]);
- MLA(hi, lo, (*fe)[4], ptr[31 - 8]);
- MLA(hi, lo, (*fe)[5], ptr[31 - 6]);
- MLA(hi, lo, (*fe)[6], ptr[31 - 4]);
- MLA(hi, lo, (*fe)[7], ptr[31 - 2]);
-
- *pcm2-- = SHIFT(MLZ(hi, lo));
- }
-
- ++fo;
- }
-
- ++Dptr;
-
- ptr = *Dptr + po;
- ML0(hi, lo, (*fo)[0], ptr[ 0]);
- MLA(hi, lo, (*fo)[1], ptr[14]);
- MLA(hi, lo, (*fo)[2], ptr[12]);
- MLA(hi, lo, (*fo)[3], ptr[10]);
- MLA(hi, lo, (*fo)[4], ptr[ 8]);
- MLA(hi, lo, (*fo)[5], ptr[ 6]);
- MLA(hi, lo, (*fo)[6], ptr[ 4]);
- MLA(hi, lo, (*fo)[7], ptr[ 2]);
-
- *pcm1 = SHIFT(-MLZ(hi, lo));
- pcm1 += 8;
-
- phase = (phase + 1) % 16;
- }
- }
-}
-
-/*
- * NAME: synth->frame()
- * DESCRIPTION: perform PCM synthesis of frame subband samples
- */
-void mad_synth_frame(struct mad_synth *synth, struct mad_frame const *frame)
-{
- unsigned int nch, ns;
- void (*synth_frame)(struct mad_synth *, struct mad_frame const *,
- unsigned int, unsigned int);
-
- nch = MAD_NCHANNELS(&frame->header);
- ns = MAD_NSBSAMPLES(&frame->header);
-
- synth->pcm.samplerate = frame->header.samplerate;
- synth->pcm.channels = nch;
- synth->pcm.length = 32 * ns;
-
- synth_frame = synth_full;
-
- if (frame->options & MAD_OPTION_HALFSAMPLERATE) {
- synth->pcm.samplerate /= 2;
- synth->pcm.length /= 2;
-
- synth_frame = synth_half;
- }
-
- synth_frame(synth, frame, nch, ns);
-
- synth->phase = (synth->phase + ns) % 16;
-}
diff --git a/src/libmad/synth.h b/src/libmad/synth.h
deleted file mode 100644
index d5a63589e..000000000
--- a/src/libmad/synth.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * libmad - MPEG audio decoder library
- * Copyright (C) 2000-2004 Underbit Technologies, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: synth.h,v 1.3 2004/04/22 00:23:24 miguelfreitas Exp $
- */
-
-# ifndef LIBMAD_SYNTH_H
-# define LIBMAD_SYNTH_H
-
-# include "fixed.h"
-# include "frame.h"
-
-struct mad_pcm {
- unsigned int samplerate; /* sampling frequency (Hz) */
- unsigned short channels; /* number of channels */
- unsigned short length; /* number of samples per channel */
- mad_fixed_t samples[2][1152]; /* PCM output samples [ch][sample] */
-};
-
-struct mad_synth {
- mad_fixed_t filter[2][2][2][16][8]; /* polyphase filterbank outputs */
- /* [ch][eo][peo][s][v] */
-
- unsigned int phase; /* current processing phase */
-
- struct mad_pcm pcm; /* PCM output */
-};
-
-/* single channel PCM selector */
-enum {
- MAD_PCM_CHANNEL_SINGLE = 0
-};
-
-/* dual channel PCM selector */
-enum {
- MAD_PCM_CHANNEL_DUAL_1 = 0,
- MAD_PCM_CHANNEL_DUAL_2 = 1
-};
-
-/* stereo PCM selector */
-enum {
- MAD_PCM_CHANNEL_STEREO_LEFT = 0,
- MAD_PCM_CHANNEL_STEREO_RIGHT = 1
-};
-
-void mad_synth_init(struct mad_synth *);
-
-# define mad_synth_finish(synth) /* nothing */
-
-void mad_synth_mute(struct mad_synth *);
-
-void mad_synth_frame(struct mad_synth *, struct mad_frame const *);
-
-# endif
diff --git a/src/libmad/timer.c b/src/libmad/timer.c
deleted file mode 100644
index 9aa2e8924..000000000
--- a/src/libmad/timer.c
+++ /dev/null
@@ -1,485 +0,0 @@
-/*
- * libmad - MPEG audio decoder library
- * Copyright (C) 2000-2004 Underbit Technologies, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: timer.c,v 1.6 2004/04/22 00:23:26 miguelfreitas Exp $
- */
-
-# ifdef HAVE_CONFIG_H
-# include "config.h"
-# endif
-
-# include "global.h"
-
-# include <stdio.h>
-
-# ifdef HAVE_ASSERT_H
-# include <assert.h>
-# endif
-
-# include "timer.h"
-
-mad_timer_t const mad_timer_zero = { 0, 0 };
-
-/*
- * NAME: timer->compare()
- * DESCRIPTION: indicate relative order of two timers
- */
-int mad_timer_compare(mad_timer_t timer1, mad_timer_t timer2)
-{
- signed long diff;
-
- diff = timer1.seconds - timer2.seconds;
- if (diff < 0)
- return -1;
- else if (diff > 0)
- return +1;
-
- diff = timer1.fraction - timer2.fraction;
- if (diff < 0)
- return -1;
- else if (diff > 0)
- return +1;
-
- return 0;
-}
-
-/*
- * NAME: timer->negate()
- * DESCRIPTION: invert the sign of a timer
- */
-void mad_timer_negate(mad_timer_t *timer)
-{
- timer->seconds = -timer->seconds;
-
- if (timer->fraction) {
- timer->seconds -= 1;
- timer->fraction = MAD_TIMER_RESOLUTION - timer->fraction;
- }
-}
-
-/*
- * NAME: timer->abs()
- * DESCRIPTION: return the absolute value of a timer
- */
-mad_timer_t mad_timer_abs(mad_timer_t timer)
-{
- if (timer.seconds < 0)
- mad_timer_negate(&timer);
-
- return timer;
-}
-
-/*
- * NAME: reduce_timer()
- * DESCRIPTION: carry timer fraction into seconds
- */
-static
-void reduce_timer(mad_timer_t *timer)
-{
- timer->seconds += timer->fraction / MAD_TIMER_RESOLUTION;
- timer->fraction %= MAD_TIMER_RESOLUTION;
-}
-
-/*
- * NAME: gcd()
- * DESCRIPTION: compute greatest common denominator
- */
-static
-unsigned long gcd(unsigned long num1, unsigned long num2)
-{
- unsigned long tmp;
-
- while (num2) {
- tmp = num2;
- num2 = num1 % num2;
- num1 = tmp;
- }
-
- return num1;
-}
-
-/*
- * NAME: reduce_rational()
- * DESCRIPTION: convert rational expression to lowest terms
- */
-static
-void reduce_rational(unsigned long *numer, unsigned long *denom)
-{
- unsigned long factor;
-
- factor = gcd(*numer, *denom);
-
- assert(factor != 0);
-
- *numer /= factor;
- *denom /= factor;
-}
-
-/*
- * NAME: scale_rational()
- * DESCRIPTION: solve numer/denom == ?/scale avoiding overflowing
- */
-static
-unsigned long scale_rational(unsigned long numer, unsigned long denom,
- unsigned long scale)
-{
- reduce_rational(&numer, &denom);
- reduce_rational(&scale, &denom);
-
- assert(denom != 0);
-
- if (denom < scale)
- return numer * (scale / denom) + numer * (scale % denom) / denom;
- if (denom < numer)
- return scale * (numer / denom) + scale * (numer % denom) / denom;
-
- return numer * scale / denom;
-}
-
-/*
- * NAME: timer->set()
- * DESCRIPTION: set timer to specific (positive) value
- */
-void mad_timer_set(mad_timer_t *timer, unsigned long seconds,
- unsigned long numer, unsigned long denom)
-{
- timer->seconds = seconds;
- if (numer >= denom && denom > 0) {
- timer->seconds += numer / denom;
- numer %= denom;
- }
-
- switch (denom) {
- case 0:
- case 1:
- timer->fraction = 0;
- break;
-
- case MAD_TIMER_RESOLUTION:
- timer->fraction = numer;
- break;
-
- case 1000:
- timer->fraction = numer * (MAD_TIMER_RESOLUTION / 1000);
- break;
-
- case 8000:
- timer->fraction = numer * (MAD_TIMER_RESOLUTION / 8000);
- break;
-
- case 11025:
- timer->fraction = numer * (MAD_TIMER_RESOLUTION / 11025);
- break;
-
- case 12000:
- timer->fraction = numer * (MAD_TIMER_RESOLUTION / 12000);
- break;
-
- case 16000:
- timer->fraction = numer * (MAD_TIMER_RESOLUTION / 16000);
- break;
-
- case 22050:
- timer->fraction = numer * (MAD_TIMER_RESOLUTION / 22050);
- break;
-
- case 24000:
- timer->fraction = numer * (MAD_TIMER_RESOLUTION / 24000);
- break;
-
- case 32000:
- timer->fraction = numer * (MAD_TIMER_RESOLUTION / 32000);
- break;
-
- case 44100:
- timer->fraction = numer * (MAD_TIMER_RESOLUTION / 44100);
- break;
-
- case 48000:
- timer->fraction = numer * (MAD_TIMER_RESOLUTION / 48000);
- break;
-
- default:
- timer->fraction = scale_rational(numer, denom, MAD_TIMER_RESOLUTION);
- break;
- }
-
- if (timer->fraction >= MAD_TIMER_RESOLUTION)
- reduce_timer(timer);
-}
-
-/*
- * NAME: timer->add()
- * DESCRIPTION: add one timer to another
- */
-void mad_timer_add(mad_timer_t *timer, mad_timer_t incr)
-{
- timer->seconds += incr.seconds;
- timer->fraction += incr.fraction;
-
- if (timer->fraction >= MAD_TIMER_RESOLUTION)
- reduce_timer(timer);
-}
-
-/*
- * NAME: timer->multiply()
- * DESCRIPTION: multiply a timer by a scalar value
- */
-void mad_timer_multiply(mad_timer_t *timer, signed long scalar)
-{
- mad_timer_t addend;
- unsigned long factor;
-
- factor = scalar;
- if (scalar < 0) {
- factor = -scalar;
- mad_timer_negate(timer);
- }
-
- addend = *timer;
- *timer = mad_timer_zero;
-
- while (factor) {
- if (factor & 1)
- mad_timer_add(timer, addend);
-
- mad_timer_add(&addend, addend);
- factor >>= 1;
- }
-}
-
-/*
- * NAME: timer->count()
- * DESCRIPTION: return timer value in selected units
- */
-signed long mad_timer_count(mad_timer_t timer, enum mad_units units)
-{
- switch (units) {
- case MAD_UNITS_HOURS:
- return timer.seconds / 60 / 60;
-
- case MAD_UNITS_MINUTES:
- return timer.seconds / 60;
-
- case MAD_UNITS_SECONDS:
- return timer.seconds;
-
- case MAD_UNITS_DECISECONDS:
- case MAD_UNITS_CENTISECONDS:
- case MAD_UNITS_MILLISECONDS:
-
- case MAD_UNITS_8000_HZ:
- case MAD_UNITS_11025_HZ:
- case MAD_UNITS_12000_HZ:
- case MAD_UNITS_16000_HZ:
- case MAD_UNITS_22050_HZ:
- case MAD_UNITS_24000_HZ:
- case MAD_UNITS_32000_HZ:
- case MAD_UNITS_44100_HZ:
- case MAD_UNITS_48000_HZ:
-
- case MAD_UNITS_24_FPS:
- case MAD_UNITS_25_FPS:
- case MAD_UNITS_30_FPS:
- case MAD_UNITS_48_FPS:
- case MAD_UNITS_50_FPS:
- case MAD_UNITS_60_FPS:
- case MAD_UNITS_75_FPS:
- return timer.seconds * (signed long) units +
- (signed long) scale_rational(timer.fraction, MAD_TIMER_RESOLUTION,
- units);
-
- case MAD_UNITS_23_976_FPS:
- case MAD_UNITS_24_975_FPS:
- case MAD_UNITS_29_97_FPS:
- case MAD_UNITS_47_952_FPS:
- case MAD_UNITS_49_95_FPS:
- case MAD_UNITS_59_94_FPS:
- return (mad_timer_count(timer, -units) + 1) * 1000 / 1001;
- }
-
- /* unsupported units */
- return 0;
-}
-
-/*
- * NAME: timer->fraction()
- * DESCRIPTION: return fractional part of timer in arbitrary terms
- */
-unsigned long mad_timer_fraction(mad_timer_t timer, unsigned long denom)
-{
- timer = mad_timer_abs(timer);
-
- switch (denom) {
- case 0:
- return timer.fraction ?
- MAD_TIMER_RESOLUTION / timer.fraction : MAD_TIMER_RESOLUTION + 1;
-
- case MAD_TIMER_RESOLUTION:
- return timer.fraction;
-
- default:
- return scale_rational(timer.fraction, MAD_TIMER_RESOLUTION, denom);
- }
-}
-
-/*
- * NAME: timer->string()
- * DESCRIPTION: write a string representation of a timer using a template
- */
-void mad_timer_string(mad_timer_t timer,
- char *dest, char const *format, enum mad_units units,
- enum mad_units fracunits, unsigned long subparts)
-{
- unsigned long hours, minutes, seconds, sub;
- unsigned int frac;
-
- timer = mad_timer_abs(timer);
-
- seconds = timer.seconds;
- frac = sub = 0;
-
- switch (fracunits) {
- case MAD_UNITS_HOURS:
- case MAD_UNITS_MINUTES:
- case MAD_UNITS_SECONDS:
- break;
-
- case MAD_UNITS_DECISECONDS:
- case MAD_UNITS_CENTISECONDS:
- case MAD_UNITS_MILLISECONDS:
-
- case MAD_UNITS_8000_HZ:
- case MAD_UNITS_11025_HZ:
- case MAD_UNITS_12000_HZ:
- case MAD_UNITS_16000_HZ:
- case MAD_UNITS_22050_HZ:
- case MAD_UNITS_24000_HZ:
- case MAD_UNITS_32000_HZ:
- case MAD_UNITS_44100_HZ:
- case MAD_UNITS_48000_HZ:
-
- case MAD_UNITS_24_FPS:
- case MAD_UNITS_25_FPS:
- case MAD_UNITS_30_FPS:
- case MAD_UNITS_48_FPS:
- case MAD_UNITS_50_FPS:
- case MAD_UNITS_60_FPS:
- case MAD_UNITS_75_FPS:
- {
- unsigned long denom;
-
- denom = MAD_TIMER_RESOLUTION / fracunits;
-
- frac = timer.fraction / denom;
- sub = scale_rational(timer.fraction % denom, denom, subparts);
- }
- break;
-
- case MAD_UNITS_23_976_FPS:
- case MAD_UNITS_24_975_FPS:
- case MAD_UNITS_29_97_FPS:
- case MAD_UNITS_47_952_FPS:
- case MAD_UNITS_49_95_FPS:
- case MAD_UNITS_59_94_FPS:
- /* drop-frame encoding */
- /* N.B. this is only well-defined for MAD_UNITS_29_97_FPS */
- {
- unsigned long frame, cycle, d, m;
-
- frame = mad_timer_count(timer, fracunits);
-
- cycle = -fracunits * 60 * 10 - (10 - 1) * 2;
-
- d = frame / cycle;
- m = frame % cycle;
- frame += (10 - 1) * 2 * d;
- if (m > 2)
- frame += 2 * ((m - 2) / (cycle / 10));
-
- frac = frame % -fracunits;
- seconds = frame / -fracunits;
- }
- break;
- }
-
- switch (units) {
- case MAD_UNITS_HOURS:
- minutes = seconds / 60;
- hours = minutes / 60;
-
- sprintf(dest, format,
- hours,
- (unsigned int) (minutes % 60),
- (unsigned int) (seconds % 60),
- frac, sub);
- break;
-
- case MAD_UNITS_MINUTES:
- minutes = seconds / 60;
-
- sprintf(dest, format,
- minutes,
- (unsigned int) (seconds % 60),
- frac, sub);
- break;
-
- case MAD_UNITS_SECONDS:
- sprintf(dest, format,
- seconds,
- frac, sub);
- break;
-
- case MAD_UNITS_23_976_FPS:
- case MAD_UNITS_24_975_FPS:
- case MAD_UNITS_29_97_FPS:
- case MAD_UNITS_47_952_FPS:
- case MAD_UNITS_49_95_FPS:
- case MAD_UNITS_59_94_FPS:
- if (fracunits < 0) {
- /* not yet implemented */
- sub = 0;
- }
-
- /* fall through */
-
- case MAD_UNITS_DECISECONDS:
- case MAD_UNITS_CENTISECONDS:
- case MAD_UNITS_MILLISECONDS:
-
- case MAD_UNITS_8000_HZ:
- case MAD_UNITS_11025_HZ:
- case MAD_UNITS_12000_HZ:
- case MAD_UNITS_16000_HZ:
- case MAD_UNITS_22050_HZ:
- case MAD_UNITS_24000_HZ:
- case MAD_UNITS_32000_HZ:
- case MAD_UNITS_44100_HZ:
- case MAD_UNITS_48000_HZ:
-
- case MAD_UNITS_24_FPS:
- case MAD_UNITS_25_FPS:
- case MAD_UNITS_30_FPS:
- case MAD_UNITS_48_FPS:
- case MAD_UNITS_50_FPS:
- case MAD_UNITS_60_FPS:
- case MAD_UNITS_75_FPS:
- sprintf(dest, format, mad_timer_count(timer, units), sub);
- break;
- }
-}
diff --git a/src/libmad/timer.h b/src/libmad/timer.h
deleted file mode 100644
index 88e997d5e..000000000
--- a/src/libmad/timer.h
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * libmad - MPEG audio decoder library
- * Copyright (C) 2000-2004 Underbit Technologies, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: timer.h,v 1.3 2004/04/22 00:23:27 miguelfreitas Exp $
- */
-
-# ifndef LIBMAD_TIMER_H
-# define LIBMAD_TIMER_H
-
-typedef struct {
- signed long seconds; /* whole seconds */
- unsigned long fraction; /* 1/MAD_TIMER_RESOLUTION seconds */
-} mad_timer_t;
-
-extern mad_timer_t const mad_timer_zero;
-
-# define MAD_TIMER_RESOLUTION 352800000UL
-
-enum mad_units {
- MAD_UNITS_HOURS = -2,
- MAD_UNITS_MINUTES = -1,
- MAD_UNITS_SECONDS = 0,
-
- /* metric units */
-
- MAD_UNITS_DECISECONDS = 10,
- MAD_UNITS_CENTISECONDS = 100,
- MAD_UNITS_MILLISECONDS = 1000,
-
- /* audio sample units */
-
- MAD_UNITS_8000_HZ = 8000,
- MAD_UNITS_11025_HZ = 11025,
- MAD_UNITS_12000_HZ = 12000,
-
- MAD_UNITS_16000_HZ = 16000,
- MAD_UNITS_22050_HZ = 22050,
- MAD_UNITS_24000_HZ = 24000,
-
- MAD_UNITS_32000_HZ = 32000,
- MAD_UNITS_44100_HZ = 44100,
- MAD_UNITS_48000_HZ = 48000,
-
- /* video frame/field units */
-
- MAD_UNITS_24_FPS = 24,
- MAD_UNITS_25_FPS = 25,
- MAD_UNITS_30_FPS = 30,
- MAD_UNITS_48_FPS = 48,
- MAD_UNITS_50_FPS = 50,
- MAD_UNITS_60_FPS = 60,
-
- /* CD audio frames */
-
- MAD_UNITS_75_FPS = 75,
-
- /* video drop-frame units */
-
- MAD_UNITS_23_976_FPS = -24,
- MAD_UNITS_24_975_FPS = -25,
- MAD_UNITS_29_97_FPS = -30,
- MAD_UNITS_47_952_FPS = -48,
- MAD_UNITS_49_95_FPS = -50,
- MAD_UNITS_59_94_FPS = -60
-};
-
-# define mad_timer_reset(timer) ((void) (*(timer) = mad_timer_zero))
-
-int mad_timer_compare(mad_timer_t, mad_timer_t);
-
-# define mad_timer_sign(timer) mad_timer_compare((timer), mad_timer_zero)
-
-void mad_timer_negate(mad_timer_t *);
-mad_timer_t mad_timer_abs(mad_timer_t);
-
-void mad_timer_set(mad_timer_t *, unsigned long, unsigned long, unsigned long);
-void mad_timer_add(mad_timer_t *, mad_timer_t);
-void mad_timer_multiply(mad_timer_t *, signed long);
-
-signed long mad_timer_count(mad_timer_t, enum mad_units);
-unsigned long mad_timer_fraction(mad_timer_t, unsigned long);
-void mad_timer_string(mad_timer_t, char *, char const *,
- enum mad_units, enum mad_units, unsigned long);
-
-# endif
diff --git a/src/libmad/version.c b/src/libmad/version.c
deleted file mode 100644
index 8fc70f408..000000000
--- a/src/libmad/version.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * libmad - MPEG audio decoder library
- * Copyright (C) 2000-2004 Underbit Technologies, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: version.c,v 1.2 2004/04/22 00:23:27 miguelfreitas Exp $
- */
-
-# ifdef HAVE_CONFIG_H
-# include "config.h"
-# endif
-
-# include "global.h"
-
-# include "version.h"
-
-char const mad_version[] = "MPEG Audio Decoder " MAD_VERSION;
-char const mad_copyright[] = "Copyright (C) " MAD_PUBLISHYEAR " " MAD_AUTHOR;
-char const mad_author[] = MAD_AUTHOR " <" MAD_EMAIL ">";
-
-char const mad_build[] = ""
-# if defined(DEBUG)
- "DEBUG "
-# elif defined(NDEBUG)
- "NDEBUG "
-# endif
-
-# if defined(EXPERIMENTAL)
- "EXPERIMENTAL "
-# endif
-
-# if defined(FPM_64BIT)
- "FPM_64BIT "
-# elif defined(FPM_INTEL)
- "FPM_INTEL "
-# elif defined(FPM_ARM)
- "FPM_ARM "
-# elif defined(FPM_MIPS)
- "FPM_MIPS "
-# elif defined(FPM_SPARC)
- "FPM_SPARC "
-# elif defined(FPM_PPC)
- "FPM_PPC "
-# elif defined(FPM_DEFAULT)
- "FPM_DEFAULT "
-# endif
-
-# if defined(ASO_IMDCT)
- "ASO_IMDCT "
-# endif
-# if defined(ASO_INTERLEAVE1)
- "ASO_INTERLEAVE1 "
-# endif
-# if defined(ASO_INTERLEAVE2)
- "ASO_INTERLEAVE2 "
-# endif
-# if defined(ASO_ZEROCHECK)
- "ASO_ZEROCHECK "
-# endif
-
-# if defined(OPT_SPEED)
- "OPT_SPEED "
-# elif defined(OPT_ACCURACY)
- "OPT_ACCURACY "
-# endif
-
-# if defined(OPT_SSO)
- "OPT_SSO "
-# endif
-
-# if defined(OPT_DCTO) /* never defined here */
- "OPT_DCTO "
-# endif
-
-# if defined(OPT_STRICT)
- "OPT_STRICT "
-# endif
-;
diff --git a/src/libmad/version.h b/src/libmad/version.h
deleted file mode 100644
index c056e6fc9..000000000
--- a/src/libmad/version.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * libmad - MPEG audio decoder library
- * Copyright (C) 2000-2004 Underbit Technologies, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: version.h,v 1.2 2004/04/22 00:23:29 miguelfreitas Exp $
- */
-
-# ifndef LIBMAD_VERSION_H
-# define LIBMAD_VERSION_H
-
-# define MAD_VERSION_MAJOR 0
-# define MAD_VERSION_MINOR 15
-# define MAD_VERSION_PATCH 1
-# define MAD_VERSION_EXTRA " (beta)"
-
-# define MAD_VERSION_STRINGIZE(str) #str
-# define MAD_VERSION_STRING(num) MAD_VERSION_STRINGIZE(num)
-
-# define MAD_VERSION MAD_VERSION_STRING(MAD_VERSION_MAJOR) "." \
- MAD_VERSION_STRING(MAD_VERSION_MINOR) "." \
- MAD_VERSION_STRING(MAD_VERSION_PATCH) \
- MAD_VERSION_EXTRA
-
-# define MAD_PUBLISHYEAR "2000-2004"
-# define MAD_AUTHOR "Underbit Technologies, Inc."
-# define MAD_EMAIL "info@underbit.com"
-
-extern char const mad_version[];
-extern char const mad_copyright[];
-extern char const mad_author[];
-extern char const mad_build[];
-
-# endif
diff --git a/src/libmpeg2/Makefile.am b/src/libmpeg2/Makefile.am
index 66fb39f13..d772f0e09 100644
--- a/src/libmpeg2/Makefile.am
+++ b/src/libmpeg2/Makefile.am
@@ -1,5 +1,11 @@
include $(top_srcdir)/misc/Makefile.common
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+AM_LDFLAGS = $(xineplug_ldflags)
+
+noinst_HEADERS = vlc.h mpeg2.h xvmc.h xvmc_vld.h mpeg2_internal.h idct_mlib.h vis.h \
+ libmpeg2_accel.h
+
xineplug_LTLIBRARIES = xineplug_decode_mpeg2.la
xineplug_decode_mpeg2_la_SOURCES = \
@@ -23,8 +29,4 @@ xineplug_decode_mpeg2_la_SOURCES = \
libmpeg2_accel.c
xineplug_decode_mpeg2_la_LIBADD = $(MLIB_LIBS) $(XINE_LIB) -lm
-xineplug_decode_mpeg2_la_CFLAGS = $(VISIBILITY_FLAG) $(LIBMPEG2_CFLAGS)
-xineplug_decode_mpeg2_la_LDFLAGS = $(xineplug_ldflags)
-
-noinst_HEADERS = vlc.h mpeg2.h xvmc.h xvmc_vld.h mpeg2_internal.h idct_mlib.h vis.h \
- libmpeg2_accel.h
+xineplug_decode_mpeg2_la_CFLAGS = $(AM_CFLAGS) $(MLIB_CFLAGS)
diff --git a/src/libmpeg2new/Makefile.am b/src/libmpeg2new/Makefile.am
index 49959da86..8c248fdcb 100644
--- a/src/libmpeg2new/Makefile.am
+++ b/src/libmpeg2new/Makefile.am
@@ -1,13 +1,12 @@
include $(top_srcdir)/misc/Makefile.common
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+AM_LDFLAGS = $(xineplug_ldflags)
+
SUBDIRS = libmpeg2
xineplug_LTLIBRARIES = xineplug_decode_mpeg2.la
-xineplug_decode_mpeg2_la_SOURCES = \
- xine_mpeg2_decoder.c
-
-xineplug_decode_mpeg2_la_CFLAGS = $(VISIBILITY_FLAG) $(LIBMPEG2_CFLAGS)
+xineplug_decode_mpeg2_la_SOURCES = xine_mpeg2_decoder.c
xineplug_decode_mpeg2_la_LIBADD = $(XINE_LIB) ./libmpeg2/libmpeg2.la
-xineplug_decode_mpeg2_la_LDFLAGS = $(xineplug_ldflags)
-
+xineplug_decode_mpeg2_la_CFLAGS = $(AM_CFLAGS) $(MLIB_CFLAGS)
diff --git a/src/libmpeg2new/libmpeg2/Makefile.am b/src/libmpeg2new/libmpeg2/Makefile.am
index f99894f12..2caa3ddc2 100644
--- a/src/libmpeg2new/libmpeg2/Makefile.am
+++ b/src/libmpeg2new/libmpeg2/Makefile.am
@@ -1,5 +1,7 @@
include $(top_srcdir)/misc/Makefile.common
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+
noinst_LTLIBRARIES = libmpeg2.la libmpeg2arch.la
libmpeg2_la_SOURCES = alloc.c header.c decode.c slice.c motion_comp.c idct.c
@@ -10,4 +12,3 @@ libmpeg2arch_la_SOURCES = motion_comp_mmx.c idct_mmx.c \
motion_comp_alpha.c idct_alpha.c \
motion_comp_vis.c \
cpu_accel.c cpu_state.c
-
diff --git a/src/libmusepack/Makefile.am b/src/libmusepack/Makefile.am
deleted file mode 100644
index d39426597..000000000
--- a/src/libmusepack/Makefile.am
+++ /dev/null
@@ -1,26 +0,0 @@
-include $(top_srcdir)/misc/Makefile.common
-
-SUBDIRS = musepack
-
-EXTRA_DIST = diff_against_svn.patch
-
-if MUSEPACK
-xineplug_LTLIBRARIES = xineplug_decode_mpc.la
-endif
-
-if EXTERNAL_MPCDEC
-internal_sources =
-else
-internal_sources = huffsv46.c huffsv7.c idtag.c mpc_decoder.c \
- mpc_reader.c requant.c streaminfo.c synth_filter.c
-endif
-
-if EXTERNAL_MPCDEC
-xineplug_decode_mpc_la_LIBADD = $(XINE_LIB) -lmpcdec
-else
-xineplug_decode_mpc_la_LIBADD = $(XINE_LIB)
-endif
-
-xineplug_decode_mpc_la_SOURCES = $(internal_sources) xine_musepack_decoder.c
-xineplug_decode_mpc_la_CFLAGS = $(VISIBILITY_FLAG)
-xineplug_decode_mpc_la_LDFLAGS = $(xineplug_ldflags)
diff --git a/src/libmusepack/diff_against_svn.patch b/src/libmusepack/diff_against_svn.patch
deleted file mode 100644
index 1d44efb95..000000000
--- a/src/libmusepack/diff_against_svn.patch
+++ /dev/null
@@ -1,55 +0,0 @@
-Use xine's inttypes.
-The file config_types.h is generated from config_types.h.in in musepack SVN.
-Check for previous swap32 definition before writing a new swap32 function.
-
-Index: src/libmusepack/musepack/config_types.h
-===================================================================
-RCS file: /home/valtri/CVS/xine-lib/src/libmusepack/musepack/config_types.h,v
-retrieving revision 1.1.1.2
-diff -u -p -u -p -r1.1.1.2 config_types.h
---- src/libmusepack/musepack/config_types.h 3 Feb 2005 00:19:24 -0000 1.1.1.2
-+++ src/libmusepack/musepack/config_types.h 3 Feb 2005 00:21:06 -0000
-@@ -1,7 +1,7 @@
- #ifndef __CONFIG_TYPES_H__
- #define __CONFIG_TYPES_H__
-
--#include <stdint.h>
-+#include "os_types.h"
-
- #ifdef WORDS_BIGENDIAN
- #undef MPC_LITTLE_ENDIAN
-Index: src/libmusepack/synth_filter.c
-===================================================================
-RCS file: /cvsroot/xine/xine-lib/src/libmusepack/synth_filter.c,v
-retrieving revision 1.1
-diff -u -r1.1 synth_filter.c
---- src/libmusepack/synth_filter.c 14 Jan 2005 15:24:25 -0000 1.1
-+++ src/libmusepack/synth_filter.c 7 Jan 2006 10:54:27 -0000
-@@ -39,8 +39,6 @@
- #include "musepack/musepack.h"
- #include "musepack/internal.h"
-
--typedef mpc_int32_t ptrdiff_t;
--
- /* C O N S T A N T S */
- #undef _
-
-diff -r d25b274e6e6a src/libmusepack/musepack/internal.h
---- a/src/libmusepack/musepack/internal.h Wed Apr 04 13:41:11 2007 +0200
-+++ b/src/libmusepack/musepack/internal.h Wed Apr 04 13:42:45 2007 +0200
-@@ -8,6 +8,7 @@ enum {
- MPC_DECODER_SYNTH_DELAY = 481
- };
-
-+#ifndef swap32
- /// Big/little endian 32 bit byte swapping routine.
- static inline
- mpc_uint32_t swap32(mpc_uint32_t val) {
-@@ -16,6 +17,7 @@ mpc_uint32_t swap32(mpc_uint32_t val) {
- (mpc_uint32_t)src[0] |
- ((mpc_uint32_t)src[1] << 8) | ((mpc_uint32_t)src[2] << 16) | ((mpc_uint32_t)src[3] << 24);
- }
-+#endif
-
- /// Searches for a ID3v2-tag and reads the length (in bytes) of it.
- /// \param reader supplying raw stream data
diff --git a/src/libmusepack/huffsv46.c b/src/libmusepack/huffsv46.c
deleted file mode 100644
index 6ade01b9d..000000000
--- a/src/libmusepack/huffsv46.c
+++ /dev/null
@@ -1,268 +0,0 @@
-/*
- Copyright (c) 2004, The Musepack Development Team
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
- * Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials provided
- with the distribution.
-
- * Neither the name of the The Musepack Development Team nor the
- names of its contributors may be used to endorse or promote
- products derived from this software without specific prior
- written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-/// \file huffsv46.c
-/// Implementations of huffman decoding for streamversions < 7.
-
-#include "musepack/musepack.h"
-#include "musepack/requant.h"
-#include "musepack/huffman.h"
-
-void
-mpc_decoder_init_huffman_sv6(mpc_decoder *d)
-{
- mpc_decoder_init_huffman_sv6_tables(d);
- mpc_decoder_resort_huff_tables(16, d->Region_A , 0);
- mpc_decoder_resort_huff_tables( 8, d->Region_B , 0);
- mpc_decoder_resort_huff_tables( 4, d->Region_C , 0);
- mpc_decoder_resort_huff_tables( 8, d->SCFI_Bundle , 0);
- mpc_decoder_resort_huff_tables(13, d->DSCF_Entropie , 6);
- mpc_decoder_resort_huff_tables( 3, d->Entropie_1 , Dc[1]);
- mpc_decoder_resort_huff_tables( 5, d->Entropie_2 , Dc[2]);
- mpc_decoder_resort_huff_tables( 7, d->Entropie_3 , Dc[3]);
- mpc_decoder_resort_huff_tables( 9, d->Entropie_4 , Dc[4]);
- mpc_decoder_resort_huff_tables(15, d->Entropie_5 , Dc[5]);
- mpc_decoder_resort_huff_tables(31, d->Entropie_6 , Dc[6]);
- mpc_decoder_resort_huff_tables(63, d->Entropie_7 , Dc[7]);
-}
-
-void
-mpc_decoder_init_huffman_sv6_tables(mpc_decoder *d)
-{
- // SCFI-bundle
- d->SCFI_Bundle[7].Code= 1; d->SCFI_Bundle[7].Length= 1;
- d->SCFI_Bundle[3].Code= 1; d->SCFI_Bundle[3].Length= 2;
- d->SCFI_Bundle[5].Code= 0; d->SCFI_Bundle[5].Length= 3;
- d->SCFI_Bundle[1].Code= 7; d->SCFI_Bundle[1].Length= 5;
- d->SCFI_Bundle[2].Code= 6; d->SCFI_Bundle[2].Length= 5;
- d->SCFI_Bundle[4].Code= 4; d->SCFI_Bundle[4].Length= 5;
- d->SCFI_Bundle[0].Code= 11; d->SCFI_Bundle[0].Length= 6;
- d->SCFI_Bundle[6].Code= 10; d->SCFI_Bundle[6].Length= 6;
-
- // region A (subbands 0..10)
- d->Region_A[ 1].Code= 1; d->Region_A[ 1].Length= 1;
- d->Region_A[ 2].Code= 0; d->Region_A[ 2].Length= 2;
- d->Region_A[ 0].Code= 2; d->Region_A[ 0].Length= 3;
- d->Region_A[ 3].Code= 15; d->Region_A[ 3].Length= 5;
- d->Region_A[ 5].Code= 13; d->Region_A[ 5].Length= 5;
- d->Region_A[ 6].Code= 12; d->Region_A[ 6].Length= 5;
- d->Region_A[ 4].Code= 29; d->Region_A[ 4].Length= 6;
- d->Region_A[ 7].Code= 57; d->Region_A[ 7].Length= 7;
- d->Region_A[ 8].Code= 113; d->Region_A[ 8].Length= 8;
- d->Region_A[ 9].Code= 225; d->Region_A[ 9].Length= 9;
- d->Region_A[10].Code= 449; d->Region_A[10].Length= 10;
- d->Region_A[11].Code= 897; d->Region_A[11].Length= 11;
- d->Region_A[12].Code= 1793; d->Region_A[12].Length= 12;
- d->Region_A[13].Code= 3585; d->Region_A[13].Length= 13;
- d->Region_A[14].Code= 7169; d->Region_A[14].Length= 14;
- d->Region_A[15].Code= 7168; d->Region_A[15].Length= 14;
-
- // region B (subbands 11..22)
- d->Region_B[1].Code= 1; d->Region_B[1].Length= 1;
- d->Region_B[0].Code= 1; d->Region_B[0].Length= 2;
- d->Region_B[2].Code= 1; d->Region_B[2].Length= 3;
- d->Region_B[3].Code= 1; d->Region_B[3].Length= 4;
- d->Region_B[4].Code= 1; d->Region_B[4].Length= 5;
- d->Region_B[5].Code= 1; d->Region_B[5].Length= 6;
- d->Region_B[6].Code= 1; d->Region_B[6].Length= 7;
- d->Region_B[7].Code= 0; d->Region_B[7].Length= 7;
-
- // region C (subbands 23..31)
- d->Region_C[0].Code= 1; d->Region_C[0].Length= 1;
- d->Region_C[1].Code= 1; d->Region_C[1].Length= 2;
- d->Region_C[2].Code= 1; d->Region_C[2].Length= 3;
- d->Region_C[3].Code= 0; d->Region_C[3].Length= 3;
-
- // DSCF
- d->DSCF_Entropie[ 6].Code= 0; d->DSCF_Entropie[ 6].Length= 2;
- d->DSCF_Entropie[ 7].Code= 7; d->DSCF_Entropie[ 7].Length= 3;
- d->DSCF_Entropie[ 5].Code= 4; d->DSCF_Entropie[ 5].Length= 3;
- d->DSCF_Entropie[ 8].Code= 3; d->DSCF_Entropie[ 8].Length= 3;
- d->DSCF_Entropie[ 9].Code= 13; d->DSCF_Entropie[ 9].Length= 4;
- d->DSCF_Entropie[ 4].Code= 11; d->DSCF_Entropie[ 4].Length= 4;
- d->DSCF_Entropie[10].Code= 10; d->DSCF_Entropie[10].Length= 4;
- d->DSCF_Entropie[ 2].Code= 4; d->DSCF_Entropie[ 2].Length= 4;
- d->DSCF_Entropie[11].Code= 25; d->DSCF_Entropie[11].Length= 5;
- d->DSCF_Entropie[ 3].Code= 24; d->DSCF_Entropie[ 3].Length= 5;
- d->DSCF_Entropie[ 1].Code= 11; d->DSCF_Entropie[ 1].Length= 5;
- d->DSCF_Entropie[12].Code= 21; d->DSCF_Entropie[12].Length= 6;
- d->DSCF_Entropie[ 0].Code= 20; d->DSCF_Entropie[ 0].Length= 6;
-
- // first quantizer
- d->Entropie_1[1].Code= 1; d->Entropie_1[1].Length= 1;
- d->Entropie_1[0].Code= 1; d->Entropie_1[0].Length= 2;
- d->Entropie_1[2].Code= 0; d->Entropie_1[2].Length= 2;
-
- // second quantizer
- d->Entropie_2[2].Code= 3; d->Entropie_2[2].Length= 2;
- d->Entropie_2[3].Code= 1; d->Entropie_2[3].Length= 2;
- d->Entropie_2[1].Code= 0; d->Entropie_2[1].Length= 2;
- d->Entropie_2[4].Code= 5; d->Entropie_2[4].Length= 3;
- d->Entropie_2[0].Code= 4; d->Entropie_2[0].Length= 3;
-
- // third quantizer
- d->Entropie_3[3].Code= 3; d->Entropie_3[3].Length= 2;
- d->Entropie_3[2].Code= 1; d->Entropie_3[2].Length= 2;
- d->Entropie_3[4].Code= 0; d->Entropie_3[4].Length= 2;
- d->Entropie_3[1].Code= 5; d->Entropie_3[1].Length= 3;
- d->Entropie_3[5].Code= 9; d->Entropie_3[5].Length= 4;
- d->Entropie_3[0].Code= 17; d->Entropie_3[0].Length= 5;
- d->Entropie_3[6].Code= 16; d->Entropie_3[6].Length= 5;
-
- // forth quantizer
- d->Entropie_4[4].Code= 0; d->Entropie_4[4].Length= 2;
- d->Entropie_4[5].Code= 6; d->Entropie_4[5].Length= 3;
- d->Entropie_4[3].Code= 5; d->Entropie_4[3].Length= 3;
- d->Entropie_4[6].Code= 4; d->Entropie_4[6].Length= 3;
- d->Entropie_4[2].Code= 3; d->Entropie_4[2].Length= 3;
- d->Entropie_4[7].Code= 15; d->Entropie_4[7].Length= 4;
- d->Entropie_4[1].Code= 14; d->Entropie_4[1].Length= 4;
- d->Entropie_4[0].Code= 5; d->Entropie_4[0].Length= 4;
- d->Entropie_4[8].Code= 4; d->Entropie_4[8].Length= 4;
-
- // fifth quantizer
- d->Entropie_5[7 ].Code= 4; d->Entropie_5[7 ].Length= 3;
- d->Entropie_5[8 ].Code= 3; d->Entropie_5[8 ].Length= 3;
- d->Entropie_5[6 ].Code= 2; d->Entropie_5[6 ].Length= 3;
- d->Entropie_5[9 ].Code= 0; d->Entropie_5[9 ].Length= 3;
- d->Entropie_5[5 ].Code= 15; d->Entropie_5[5 ].Length= 4;
- d->Entropie_5[4 ].Code= 13; d->Entropie_5[4 ].Length= 4;
- d->Entropie_5[10].Code= 12; d->Entropie_5[10].Length= 4;
- d->Entropie_5[11].Code= 10; d->Entropie_5[11].Length= 4;
- d->Entropie_5[3 ].Code= 3; d->Entropie_5[3 ].Length= 4;
- d->Entropie_5[12].Code= 2; d->Entropie_5[12].Length= 4;
- d->Entropie_5[2 ].Code= 29; d->Entropie_5[2 ].Length= 5;
- d->Entropie_5[1 ].Code= 23; d->Entropie_5[1 ].Length= 5;
- d->Entropie_5[13].Code= 22; d->Entropie_5[13].Length= 5;
- d->Entropie_5[0 ].Code= 57; d->Entropie_5[0 ].Length= 6;
- d->Entropie_5[14].Code= 56; d->Entropie_5[14].Length= 6;
-
- // sixth quantizer
- d->Entropie_6[15].Code= 9; d->Entropie_6[15].Length= 4;
- d->Entropie_6[16].Code= 8; d->Entropie_6[16].Length= 4;
- d->Entropie_6[14].Code= 7; d->Entropie_6[14].Length= 4;
- d->Entropie_6[18].Code= 6; d->Entropie_6[18].Length= 4;
- d->Entropie_6[17].Code= 5; d->Entropie_6[17].Length= 4;
- d->Entropie_6[12].Code= 3; d->Entropie_6[12].Length= 4;
- d->Entropie_6[13].Code= 2; d->Entropie_6[13].Length= 4;
- d->Entropie_6[19].Code= 0; d->Entropie_6[19].Length= 4;
- d->Entropie_6[11].Code= 31; d->Entropie_6[11].Length= 5;
- d->Entropie_6[20].Code= 30; d->Entropie_6[20].Length= 5;
- d->Entropie_6[10].Code= 29; d->Entropie_6[10].Length= 5;
- d->Entropie_6[9 ].Code= 27; d->Entropie_6[9 ].Length= 5;
- d->Entropie_6[21].Code= 26; d->Entropie_6[21].Length= 5;
- d->Entropie_6[22].Code= 25; d->Entropie_6[22].Length= 5;
- d->Entropie_6[8 ].Code= 24; d->Entropie_6[8 ].Length= 5;
- d->Entropie_6[7 ].Code= 23; d->Entropie_6[7 ].Length= 5;
- d->Entropie_6[23].Code= 21; d->Entropie_6[23].Length= 5;
- d->Entropie_6[6 ].Code= 9; d->Entropie_6[6 ].Length= 5;
- d->Entropie_6[24].Code= 3; d->Entropie_6[24].Length= 5;
- d->Entropie_6[25].Code= 57; d->Entropie_6[25].Length= 6;
- d->Entropie_6[5 ].Code= 56; d->Entropie_6[5 ].Length= 6;
- d->Entropie_6[4 ].Code= 45; d->Entropie_6[4 ].Length= 6;
- d->Entropie_6[26].Code= 41; d->Entropie_6[26].Length= 6;
- d->Entropie_6[2 ].Code= 40; d->Entropie_6[2 ].Length= 6;
- d->Entropie_6[27].Code= 17; d->Entropie_6[27].Length= 6;
- d->Entropie_6[28].Code= 16; d->Entropie_6[28].Length= 6;
- d->Entropie_6[3 ].Code= 5; d->Entropie_6[3 ].Length= 6;
- d->Entropie_6[29].Code= 89; d->Entropie_6[29].Length= 7;
- d->Entropie_6[1 ].Code= 88; d->Entropie_6[1 ].Length= 7;
- d->Entropie_6[30].Code= 9; d->Entropie_6[30].Length= 7;
- d->Entropie_6[0 ].Code= 8; d->Entropie_6[0 ].Length= 7;
-
- // seventh quantizer
- d->Entropie_7[25].Code= 0; d->Entropie_7[25].Length= 5;
- d->Entropie_7[37].Code= 1; d->Entropie_7[37].Length= 5;
- d->Entropie_7[62].Code= 16; d->Entropie_7[62].Length= 8;
- d->Entropie_7[ 0].Code= 17; d->Entropie_7[ 0].Length= 8;
- d->Entropie_7[ 3].Code= 9; d->Entropie_7[ 3].Length= 7;
- d->Entropie_7[ 5].Code= 10; d->Entropie_7[ 5].Length= 7;
- d->Entropie_7[ 6].Code= 11; d->Entropie_7[ 6].Length= 7;
- d->Entropie_7[38].Code= 3; d->Entropie_7[38].Length= 5;
- d->Entropie_7[35].Code= 4; d->Entropie_7[35].Length= 5;
- d->Entropie_7[33].Code= 5; d->Entropie_7[33].Length= 5;
- d->Entropie_7[24].Code= 6; d->Entropie_7[24].Length= 5;
- d->Entropie_7[27].Code= 7; d->Entropie_7[27].Length= 5;
- d->Entropie_7[26].Code= 8; d->Entropie_7[26].Length= 5;
- d->Entropie_7[12].Code= 18; d->Entropie_7[12].Length= 6;
- d->Entropie_7[50].Code= 19; d->Entropie_7[50].Length= 6;
- d->Entropie_7[29].Code= 10; d->Entropie_7[29].Length= 5;
- d->Entropie_7[31].Code= 11; d->Entropie_7[31].Length= 5;
- d->Entropie_7[36].Code= 12; d->Entropie_7[36].Length= 5;
- d->Entropie_7[34].Code= 13; d->Entropie_7[34].Length= 5;
- d->Entropie_7[28].Code= 14; d->Entropie_7[28].Length= 5;
- d->Entropie_7[49].Code= 30; d->Entropie_7[49].Length= 6;
- d->Entropie_7[56].Code= 62; d->Entropie_7[56].Length= 7;
- d->Entropie_7[ 7].Code= 63; d->Entropie_7[ 7].Length= 7;
- d->Entropie_7[32].Code= 16; d->Entropie_7[32].Length= 5;
- d->Entropie_7[30].Code= 17; d->Entropie_7[30].Length= 5;
- d->Entropie_7[13].Code= 36; d->Entropie_7[13].Length= 6;
- d->Entropie_7[55].Code= 74; d->Entropie_7[55].Length= 7;
- d->Entropie_7[61].Code= 150; d->Entropie_7[61].Length= 8;
- d->Entropie_7[ 1].Code= 151; d->Entropie_7[ 1].Length= 8;
- d->Entropie_7[14].Code= 38; d->Entropie_7[14].Length= 6;
- d->Entropie_7[48].Code= 39; d->Entropie_7[48].Length= 6;
- d->Entropie_7[ 4].Code= 80; d->Entropie_7[ 4].Length= 7;
- d->Entropie_7[58].Code= 81; d->Entropie_7[58].Length= 7;
- d->Entropie_7[47].Code= 41; d->Entropie_7[47].Length= 6;
- d->Entropie_7[15].Code= 42; d->Entropie_7[15].Length= 6;
- d->Entropie_7[16].Code= 43; d->Entropie_7[16].Length= 6;
- d->Entropie_7[54].Code= 88; d->Entropie_7[54].Length= 7;
- d->Entropie_7[ 8].Code= 89; d->Entropie_7[ 8].Length= 7;
- d->Entropie_7[17].Code= 45; d->Entropie_7[17].Length= 6;
- d->Entropie_7[46].Code= 46; d->Entropie_7[46].Length= 6;
- d->Entropie_7[45].Code= 47; d->Entropie_7[45].Length= 6;
- d->Entropie_7[53].Code= 96; d->Entropie_7[53].Length= 7;
- d->Entropie_7[ 9].Code= 97; d->Entropie_7[ 9].Length= 7;
- d->Entropie_7[43].Code= 49; d->Entropie_7[43].Length= 6;
- d->Entropie_7[19].Code= 50; d->Entropie_7[19].Length= 6;
- d->Entropie_7[18].Code= 51; d->Entropie_7[18].Length= 6;
- d->Entropie_7[44].Code= 52; d->Entropie_7[44].Length= 6;
- d->Entropie_7[ 2].Code= 212; d->Entropie_7[ 2].Length= 8;
- d->Entropie_7[60].Code= 213; d->Entropie_7[60].Length= 8;
- d->Entropie_7[10].Code= 107; d->Entropie_7[10].Length= 7;
- d->Entropie_7[42].Code= 54; d->Entropie_7[42].Length= 6;
- d->Entropie_7[41].Code= 55; d->Entropie_7[41].Length= 6;
- d->Entropie_7[20].Code= 56; d->Entropie_7[20].Length= 6;
- d->Entropie_7[21].Code= 57; d->Entropie_7[21].Length= 6;
- d->Entropie_7[52].Code= 116; d->Entropie_7[52].Length= 7;
- d->Entropie_7[51].Code= 117; d->Entropie_7[51].Length= 7;
- d->Entropie_7[40].Code= 59; d->Entropie_7[40].Length= 6;
- d->Entropie_7[22].Code= 60; d->Entropie_7[22].Length= 6;
- d->Entropie_7[23].Code= 61; d->Entropie_7[23].Length= 6;
- d->Entropie_7[39].Code= 62; d->Entropie_7[39].Length= 6;
- d->Entropie_7[11].Code= 126; d->Entropie_7[11].Length= 7;
- d->Entropie_7[57].Code= 254; d->Entropie_7[57].Length= 8;
- d->Entropie_7[59].Code= 255; d->Entropie_7[59].Length= 8;
-}
diff --git a/src/libmusepack/huffsv7.c b/src/libmusepack/huffsv7.c
deleted file mode 100644
index 80a8f2bff..000000000
--- a/src/libmusepack/huffsv7.c
+++ /dev/null
@@ -1,500 +0,0 @@
-/*
- Copyright (c) 2004, The Musepack Development Team
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
- * Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials provided
- with the distribution.
-
- * Neither the name of the The Musepack Development Team nor the
- names of its contributors may be used to endorse or promote
- products derived from this software without specific prior
- written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-/// \file huffsv7.c
-/// Implementations of sv7 huffman decoding functions.
-
-#include "musepack/musepack.h"
-#include "musepack/huffman.h"
-#include "musepack/requant.h"
-
-void
-mpc_decoder_init_huffman_sv7(mpc_decoder *d)
-{
- mpc_decoder_init_huffman_sv7_tables(d);
- mpc_decoder_resort_huff_tables(10, &(d->HuffHdr[0]) , 5);
- mpc_decoder_resort_huff_tables( 4, &(d->HuffSCFI[0]) , 0);
- mpc_decoder_resort_huff_tables(16, &(d->HuffDSCF[0]) , 7);
- mpc_decoder_resort_huff_tables(27, &(d->HuffQ1[0][0]) , 0);
- mpc_decoder_resort_huff_tables(27, &(d->HuffQ1[1][0]) , 0);
- mpc_decoder_resort_huff_tables(25, &(d->HuffQ2[0][0]) , 0);
- mpc_decoder_resort_huff_tables(25, &(d->HuffQ2[1][0]) , 0);
- mpc_decoder_resort_huff_tables( 7, &(d->HuffQ3[0][0]) , Dc[3]);
- mpc_decoder_resort_huff_tables( 7, &(d->HuffQ3[1][0]) , Dc[3]);
- mpc_decoder_resort_huff_tables( 9, &(d->HuffQ4[0][0]) , Dc[4]);
- mpc_decoder_resort_huff_tables( 9, &(d->HuffQ4[1][0]) , Dc[4]);
- mpc_decoder_resort_huff_tables(15, &(d->HuffQ5[0][0]) , Dc[5]);
- mpc_decoder_resort_huff_tables(15, &(d->HuffQ5[1][0]) , Dc[5]);
- mpc_decoder_resort_huff_tables(31, &(d->HuffQ6[0][0]) , Dc[6]);
- mpc_decoder_resort_huff_tables(31, &(d->HuffQ6[1][0]) , Dc[6]);
- mpc_decoder_resort_huff_tables(63, &(d->HuffQ7[0][0]) , Dc[7]);
- mpc_decoder_resort_huff_tables(63, &(d->HuffQ7[1][0]) , Dc[7]);
-}
-
-void
-mpc_decoder_init_huffman_sv7_tables(mpc_decoder *d)
-{
- /***************************** SCFI *******************************/
- d->HuffSCFI[0].Code = 2; d->HuffSCFI[0].Length = 3;
- d->HuffSCFI[1].Code = 1; d->HuffSCFI[1].Length = 1;
- d->HuffSCFI[2].Code = 3; d->HuffSCFI[2].Length = 3;
- d->HuffSCFI[3].Code = 0; d->HuffSCFI[3].Length = 2;
-
- /***************************** DSCF *******************************/
- d->HuffDSCF[ 0].Code = 32; d->HuffDSCF[ 0].Length = 6;
- d->HuffDSCF[ 1].Code = 4; d->HuffDSCF[ 1].Length = 5;
- d->HuffDSCF[ 2].Code = 17; d->HuffDSCF[ 2].Length = 5;
- d->HuffDSCF[ 3].Code = 30; d->HuffDSCF[ 3].Length = 5;
- d->HuffDSCF[ 4].Code = 13; d->HuffDSCF[ 4].Length = 4;
- d->HuffDSCF[ 5].Code = 0; d->HuffDSCF[ 5].Length = 3;
- d->HuffDSCF[ 6].Code = 3; d->HuffDSCF[ 6].Length = 3;
- d->HuffDSCF[ 7].Code = 9; d->HuffDSCF[ 7].Length = 4;
- d->HuffDSCF[ 8].Code = 5; d->HuffDSCF[ 8].Length = 3;
- d->HuffDSCF[ 9].Code = 2; d->HuffDSCF[ 9].Length = 3;
- d->HuffDSCF[10].Code = 14; d->HuffDSCF[10].Length = 4;
- d->HuffDSCF[11].Code = 3; d->HuffDSCF[11].Length = 4;
- d->HuffDSCF[12].Code = 31; d->HuffDSCF[12].Length = 5;
- d->HuffDSCF[13].Code = 5; d->HuffDSCF[13].Length = 5;
- d->HuffDSCF[14].Code = 33; d->HuffDSCF[14].Length = 6;
- d->HuffDSCF[15].Code = 12; d->HuffDSCF[15].Length = 4;
-
- /************************* frame-header ***************************/
- /***************** differential quantizer indizes *****************/
- d->HuffHdr[0].Code = 92; d->HuffHdr[0].Length = 8;
- d->HuffHdr[1].Code = 47; d->HuffHdr[1].Length = 7;
- d->HuffHdr[2].Code = 10; d->HuffHdr[2].Length = 5;
- d->HuffHdr[3].Code = 4; d->HuffHdr[3].Length = 4;
- d->HuffHdr[4].Code = 0; d->HuffHdr[4].Length = 2;
- d->HuffHdr[5].Code = 1; d->HuffHdr[5].Length = 1;
- d->HuffHdr[6].Code = 3; d->HuffHdr[6].Length = 3;
- d->HuffHdr[7].Code = 22; d->HuffHdr[7].Length = 6;
- d->HuffHdr[8].Code = 187; d->HuffHdr[8].Length = 9;
- d->HuffHdr[9].Code = 186; d->HuffHdr[9].Length = 9;
-
- /********************** 3-step quantizer **************************/
- /********************* 3 bundled samples **************************/
- //less shaped, book 0
- d->HuffQ1[0][ 0].Code = 54; d->HuffQ1[0][ 0].Length = 6;
- d->HuffQ1[0][ 1].Code = 9; d->HuffQ1[0][ 1].Length = 5;
- d->HuffQ1[0][ 2].Code = 32; d->HuffQ1[0][ 2].Length = 6;
- d->HuffQ1[0][ 3].Code = 5; d->HuffQ1[0][ 3].Length = 5;
- d->HuffQ1[0][ 4].Code = 10; d->HuffQ1[0][ 4].Length = 4;
- d->HuffQ1[0][ 5].Code = 7; d->HuffQ1[0][ 5].Length = 5;
- d->HuffQ1[0][ 6].Code = 52; d->HuffQ1[0][ 6].Length = 6;
- d->HuffQ1[0][ 7].Code = 0; d->HuffQ1[0][ 7].Length = 5;
- d->HuffQ1[0][ 8].Code = 35; d->HuffQ1[0][ 8].Length = 6;
- d->HuffQ1[0][ 9].Code = 10; d->HuffQ1[0][ 9].Length = 5;
- d->HuffQ1[0][10].Code = 6; d->HuffQ1[0][10].Length = 4;
- d->HuffQ1[0][11].Code = 4; d->HuffQ1[0][11].Length = 5;
- d->HuffQ1[0][12].Code = 11; d->HuffQ1[0][12].Length = 4;
- d->HuffQ1[0][13].Code = 7; d->HuffQ1[0][13].Length = 3;
- d->HuffQ1[0][14].Code = 12; d->HuffQ1[0][14].Length = 4;
- d->HuffQ1[0][15].Code = 3; d->HuffQ1[0][15].Length = 5;
- d->HuffQ1[0][16].Code = 7; d->HuffQ1[0][16].Length = 4;
- d->HuffQ1[0][17].Code = 11; d->HuffQ1[0][17].Length = 5;
- d->HuffQ1[0][18].Code = 34; d->HuffQ1[0][18].Length = 6;
- d->HuffQ1[0][19].Code = 1; d->HuffQ1[0][19].Length = 5;
- d->HuffQ1[0][20].Code = 53; d->HuffQ1[0][20].Length = 6;
- d->HuffQ1[0][21].Code = 6; d->HuffQ1[0][21].Length = 5;
- d->HuffQ1[0][22].Code = 9; d->HuffQ1[0][22].Length = 4;
- d->HuffQ1[0][23].Code = 2; d->HuffQ1[0][23].Length = 5;
- d->HuffQ1[0][24].Code = 33; d->HuffQ1[0][24].Length = 6;
- d->HuffQ1[0][25].Code = 8; d->HuffQ1[0][25].Length = 5;
- d->HuffQ1[0][26].Code = 55; d->HuffQ1[0][26].Length = 6;
-
- //more shaped, book 1
- d->HuffQ1[1][ 0].Code = 103; d->HuffQ1[1][ 0].Length = 8;
- d->HuffQ1[1][ 1].Code = 62; d->HuffQ1[1][ 1].Length = 7;
- d->HuffQ1[1][ 2].Code = 225; d->HuffQ1[1][ 2].Length = 9;
- d->HuffQ1[1][ 3].Code = 55; d->HuffQ1[1][ 3].Length = 7;
- d->HuffQ1[1][ 4].Code = 3; d->HuffQ1[1][ 4].Length = 4;
- d->HuffQ1[1][ 5].Code = 52; d->HuffQ1[1][ 5].Length = 7;
- d->HuffQ1[1][ 6].Code = 101; d->HuffQ1[1][ 6].Length = 8;
- d->HuffQ1[1][ 7].Code = 60; d->HuffQ1[1][ 7].Length = 7;
- d->HuffQ1[1][ 8].Code = 227; d->HuffQ1[1][ 8].Length = 9;
- d->HuffQ1[1][ 9].Code = 24; d->HuffQ1[1][ 9].Length = 6;
- d->HuffQ1[1][10].Code = 0; d->HuffQ1[1][10].Length = 4;
- d->HuffQ1[1][11].Code = 61; d->HuffQ1[1][11].Length = 7;
- d->HuffQ1[1][12].Code = 4; d->HuffQ1[1][12].Length = 4;
- d->HuffQ1[1][13].Code = 1; d->HuffQ1[1][13].Length = 1;
- d->HuffQ1[1][14].Code = 5; d->HuffQ1[1][14].Length = 4;
- d->HuffQ1[1][15].Code = 63; d->HuffQ1[1][15].Length = 7;
- d->HuffQ1[1][16].Code = 1; d->HuffQ1[1][16].Length = 4;
- d->HuffQ1[1][17].Code = 59; d->HuffQ1[1][17].Length = 7;
- d->HuffQ1[1][18].Code = 226; d->HuffQ1[1][18].Length = 9;
- d->HuffQ1[1][19].Code = 57; d->HuffQ1[1][19].Length = 7;
- d->HuffQ1[1][20].Code = 100; d->HuffQ1[1][20].Length = 8;
- d->HuffQ1[1][21].Code = 53; d->HuffQ1[1][21].Length = 7;
- d->HuffQ1[1][22].Code = 2; d->HuffQ1[1][22].Length = 4;
- d->HuffQ1[1][23].Code = 54; d->HuffQ1[1][23].Length = 7;
- d->HuffQ1[1][24].Code = 224; d->HuffQ1[1][24].Length = 9;
- d->HuffQ1[1][25].Code = 58; d->HuffQ1[1][25].Length = 7;
- d->HuffQ1[1][26].Code = 102; d->HuffQ1[1][26].Length = 8;
-
- /********************** 5-step quantizer **************************/
- /********************* 2 bundled samples **************************/
- //less shaped, book 0
- d->HuffQ2[0][ 0].Code = 89; d->HuffQ2[0][ 0].Length = 7;
- d->HuffQ2[0][ 1].Code = 47; d->HuffQ2[0][ 1].Length = 6;
- d->HuffQ2[0][ 2].Code = 15; d->HuffQ2[0][ 2].Length = 5;
- d->HuffQ2[0][ 3].Code = 0; d->HuffQ2[0][ 3].Length = 5;
- d->HuffQ2[0][ 4].Code = 91; d->HuffQ2[0][ 4].Length = 7;
- d->HuffQ2[0][ 5].Code = 4; d->HuffQ2[0][ 5].Length = 5;
- d->HuffQ2[0][ 6].Code = 6; d->HuffQ2[0][ 6].Length = 4;
- d->HuffQ2[0][ 7].Code = 13; d->HuffQ2[0][ 7].Length = 4;
- d->HuffQ2[0][ 8].Code = 4; d->HuffQ2[0][ 8].Length = 4;
- d->HuffQ2[0][ 9].Code = 5; d->HuffQ2[0][ 9].Length = 5;
- d->HuffQ2[0][10].Code = 20; d->HuffQ2[0][10].Length = 5;
- d->HuffQ2[0][11].Code = 12; d->HuffQ2[0][11].Length = 4;
- d->HuffQ2[0][12].Code = 4; d->HuffQ2[0][12].Length = 3;
- d->HuffQ2[0][13].Code = 15; d->HuffQ2[0][13].Length = 4;
- d->HuffQ2[0][14].Code = 14; d->HuffQ2[0][14].Length = 5;
- d->HuffQ2[0][15].Code = 3; d->HuffQ2[0][15].Length = 5;
- d->HuffQ2[0][16].Code = 3; d->HuffQ2[0][16].Length = 4;
- d->HuffQ2[0][17].Code = 14; d->HuffQ2[0][17].Length = 4;
- d->HuffQ2[0][18].Code = 5; d->HuffQ2[0][18].Length = 4;
- d->HuffQ2[0][19].Code = 1; d->HuffQ2[0][19].Length = 5;
- d->HuffQ2[0][20].Code = 90; d->HuffQ2[0][20].Length = 7;
- d->HuffQ2[0][21].Code = 2; d->HuffQ2[0][21].Length = 5;
- d->HuffQ2[0][22].Code = 21; d->HuffQ2[0][22].Length = 5;
- d->HuffQ2[0][23].Code = 46; d->HuffQ2[0][23].Length = 6;
- d->HuffQ2[0][24].Code = 88; d->HuffQ2[0][24].Length = 7;
-
- //more shaped, book 1
- d->HuffQ2[1][ 0].Code = 921; d->HuffQ2[1][ 0].Length = 10;
- d->HuffQ2[1][ 1].Code = 113; d->HuffQ2[1][ 1].Length = 7;
- d->HuffQ2[1][ 2].Code = 51; d->HuffQ2[1][ 2].Length = 6;
- d->HuffQ2[1][ 3].Code = 231; d->HuffQ2[1][ 3].Length = 8;
- d->HuffQ2[1][ 4].Code = 922; d->HuffQ2[1][ 4].Length = 10;
- d->HuffQ2[1][ 5].Code = 104; d->HuffQ2[1][ 5].Length = 7;
- d->HuffQ2[1][ 6].Code = 30; d->HuffQ2[1][ 6].Length = 5;
- d->HuffQ2[1][ 7].Code = 0; d->HuffQ2[1][ 7].Length = 3;
- d->HuffQ2[1][ 8].Code = 29; d->HuffQ2[1][ 8].Length = 5;
- d->HuffQ2[1][ 9].Code = 105; d->HuffQ2[1][ 9].Length = 7;
- d->HuffQ2[1][10].Code = 50; d->HuffQ2[1][10].Length = 6;
- d->HuffQ2[1][11].Code = 1; d->HuffQ2[1][11].Length = 3;
- d->HuffQ2[1][12].Code = 2; d->HuffQ2[1][12].Length = 2;
- d->HuffQ2[1][13].Code = 3; d->HuffQ2[1][13].Length = 3;
- d->HuffQ2[1][14].Code = 49; d->HuffQ2[1][14].Length = 6;
- d->HuffQ2[1][15].Code = 107; d->HuffQ2[1][15].Length = 7;
- d->HuffQ2[1][16].Code = 27; d->HuffQ2[1][16].Length = 5;
- d->HuffQ2[1][17].Code = 2; d->HuffQ2[1][17].Length = 3;
- d->HuffQ2[1][18].Code = 31; d->HuffQ2[1][18].Length = 5;
- d->HuffQ2[1][19].Code = 112; d->HuffQ2[1][19].Length = 7;
- d->HuffQ2[1][20].Code = 920; d->HuffQ2[1][20].Length = 10;
- d->HuffQ2[1][21].Code = 106; d->HuffQ2[1][21].Length = 7;
- d->HuffQ2[1][22].Code = 48; d->HuffQ2[1][22].Length = 6;
- d->HuffQ2[1][23].Code = 114; d->HuffQ2[1][23].Length = 7;
- d->HuffQ2[1][24].Code = 923; d->HuffQ2[1][24].Length = 10;
-
- /********************** 7-step quantizer **************************/
- /*********************** single samples ***************************/
- //less shaped, book 0
- d->HuffQ3[0][0].Code = 12; d->HuffQ3[0][0].Length = 4;
- d->HuffQ3[0][1].Code = 4; d->HuffQ3[0][1].Length = 3;
- d->HuffQ3[0][2].Code = 0; d->HuffQ3[0][2].Length = 2;
- d->HuffQ3[0][3].Code = 1; d->HuffQ3[0][3].Length = 2;
- d->HuffQ3[0][4].Code = 7; d->HuffQ3[0][4].Length = 3;
- d->HuffQ3[0][5].Code = 5; d->HuffQ3[0][5].Length = 3;
- d->HuffQ3[0][6].Code = 13; d->HuffQ3[0][6].Length = 4;
-
- //more shaped, book 1
- d->HuffQ3[1][0].Code = 4; d->HuffQ3[1][0].Length = 5;
- d->HuffQ3[1][1].Code = 3; d->HuffQ3[1][1].Length = 4;
- d->HuffQ3[1][2].Code = 2; d->HuffQ3[1][2].Length = 2;
- d->HuffQ3[1][3].Code = 3; d->HuffQ3[1][3].Length = 2;
- d->HuffQ3[1][4].Code = 1; d->HuffQ3[1][4].Length = 2;
- d->HuffQ3[1][5].Code = 0; d->HuffQ3[1][5].Length = 3;
- d->HuffQ3[1][6].Code = 5; d->HuffQ3[1][6].Length = 5;
-
- /********************** 9-step quantizer **************************/
- /*********************** single samples ***************************/
- //less shaped, book 0
- d->HuffQ4[0][0].Code = 5; d->HuffQ4[0][0].Length = 4;
- d->HuffQ4[0][1].Code = 0; d->HuffQ4[0][1].Length = 3;
- d->HuffQ4[0][2].Code = 4; d->HuffQ4[0][2].Length = 3;
- d->HuffQ4[0][3].Code = 6; d->HuffQ4[0][3].Length = 3;
- d->HuffQ4[0][4].Code = 7; d->HuffQ4[0][4].Length = 3;
- d->HuffQ4[0][5].Code = 5; d->HuffQ4[0][5].Length = 3;
- d->HuffQ4[0][6].Code = 3; d->HuffQ4[0][6].Length = 3;
- d->HuffQ4[0][7].Code = 1; d->HuffQ4[0][7].Length = 3;
- d->HuffQ4[0][8].Code = 4; d->HuffQ4[0][8].Length = 4;
-
- //more shaped, book 1
- d->HuffQ4[1][0].Code = 9; d->HuffQ4[1][0].Length = 5;
- d->HuffQ4[1][1].Code = 12; d->HuffQ4[1][1].Length = 4;
- d->HuffQ4[1][2].Code = 3; d->HuffQ4[1][2].Length = 3;
- d->HuffQ4[1][3].Code = 0; d->HuffQ4[1][3].Length = 2;
- d->HuffQ4[1][4].Code = 2; d->HuffQ4[1][4].Length = 2;
- d->HuffQ4[1][5].Code = 7; d->HuffQ4[1][5].Length = 3;
- d->HuffQ4[1][6].Code = 13; d->HuffQ4[1][6].Length = 4;
- d->HuffQ4[1][7].Code = 5; d->HuffQ4[1][7].Length = 4;
- d->HuffQ4[1][8].Code = 8; d->HuffQ4[1][8].Length = 5;
-
- /********************* 15-step quantizer **************************/
- /*********************** single samples ***************************/
- //less shaped, book 0
- d->HuffQ5[0][ 0].Code = 57; d->HuffQ5[0][ 0].Length = 6;
- d->HuffQ5[0][ 1].Code = 23; d->HuffQ5[0][ 1].Length = 5;
- d->HuffQ5[0][ 2].Code = 8; d->HuffQ5[0][ 2].Length = 4;
- d->HuffQ5[0][ 3].Code = 10; d->HuffQ5[0][ 3].Length = 4;
- d->HuffQ5[0][ 4].Code = 13; d->HuffQ5[0][ 4].Length = 4;
- d->HuffQ5[0][ 5].Code = 0; d->HuffQ5[0][ 5].Length = 3;
- d->HuffQ5[0][ 6].Code = 2; d->HuffQ5[0][ 6].Length = 3;
- d->HuffQ5[0][ 7].Code = 3; d->HuffQ5[0][ 7].Length = 3;
- d->HuffQ5[0][ 8].Code = 1; d->HuffQ5[0][ 8].Length = 3;
- d->HuffQ5[0][ 9].Code = 15; d->HuffQ5[0][ 9].Length = 4;
- d->HuffQ5[0][10].Code = 12; d->HuffQ5[0][10].Length = 4;
- d->HuffQ5[0][11].Code = 9; d->HuffQ5[0][11].Length = 4;
- d->HuffQ5[0][12].Code = 29; d->HuffQ5[0][12].Length = 5;
- d->HuffQ5[0][13].Code = 22; d->HuffQ5[0][13].Length = 5;
- d->HuffQ5[0][14].Code = 56; d->HuffQ5[0][14].Length = 6;
-
- //more shaped, book 1
- d->HuffQ5[1][ 0].Code = 229; d->HuffQ5[1][ 0].Length = 8;
- d->HuffQ5[1][ 1].Code = 56; d->HuffQ5[1][ 1].Length = 6;
- d->HuffQ5[1][ 2].Code = 7; d->HuffQ5[1][ 2].Length = 5;
- d->HuffQ5[1][ 3].Code = 2; d->HuffQ5[1][ 3].Length = 4;
- d->HuffQ5[1][ 4].Code = 0; d->HuffQ5[1][ 4].Length = 3;
- d->HuffQ5[1][ 5].Code = 3; d->HuffQ5[1][ 5].Length = 3;
- d->HuffQ5[1][ 6].Code = 5; d->HuffQ5[1][ 6].Length = 3;
- d->HuffQ5[1][ 7].Code = 6; d->HuffQ5[1][ 7].Length = 3;
- d->HuffQ5[1][ 8].Code = 4; d->HuffQ5[1][ 8].Length = 3;
- d->HuffQ5[1][ 9].Code = 2; d->HuffQ5[1][ 9].Length = 3;
- d->HuffQ5[1][10].Code = 15; d->HuffQ5[1][10].Length = 4;
- d->HuffQ5[1][11].Code = 29; d->HuffQ5[1][11].Length = 5;
- d->HuffQ5[1][12].Code = 6; d->HuffQ5[1][12].Length = 5;
- d->HuffQ5[1][13].Code = 115; d->HuffQ5[1][13].Length = 7;
- d->HuffQ5[1][14].Code = 228; d->HuffQ5[1][14].Length = 8;
-
- /********************* 31-step quantizer **************************/
- /*********************** single samples ***************************/
- //less shaped, book 0
- d->HuffQ6[0][ 0].Code = 65; d->HuffQ6[0][ 0].Length = 7;
- d->HuffQ6[0][ 1].Code = 6; d->HuffQ6[0][ 1].Length = 6;
- d->HuffQ6[0][ 2].Code = 44; d->HuffQ6[0][ 2].Length = 6;
- d->HuffQ6[0][ 3].Code = 45; d->HuffQ6[0][ 3].Length = 6;
- d->HuffQ6[0][ 4].Code = 59; d->HuffQ6[0][ 4].Length = 6;
- d->HuffQ6[0][ 5].Code = 13; d->HuffQ6[0][ 5].Length = 5;
- d->HuffQ6[0][ 6].Code = 17; d->HuffQ6[0][ 6].Length = 5;
- d->HuffQ6[0][ 7].Code = 19; d->HuffQ6[0][ 7].Length = 5;
- d->HuffQ6[0][ 8].Code = 23; d->HuffQ6[0][ 8].Length = 5;
- d->HuffQ6[0][ 9].Code = 21; d->HuffQ6[0][ 9].Length = 5;
- d->HuffQ6[0][10].Code = 26; d->HuffQ6[0][10].Length = 5;
- d->HuffQ6[0][11].Code = 30; d->HuffQ6[0][11].Length = 5;
- d->HuffQ6[0][12].Code = 0; d->HuffQ6[0][12].Length = 4;
- d->HuffQ6[0][13].Code = 2; d->HuffQ6[0][13].Length = 4;
- d->HuffQ6[0][14].Code = 5; d->HuffQ6[0][14].Length = 4;
- d->HuffQ6[0][15].Code = 7; d->HuffQ6[0][15].Length = 4;
- d->HuffQ6[0][16].Code = 3; d->HuffQ6[0][16].Length = 4;
- d->HuffQ6[0][17].Code = 4; d->HuffQ6[0][17].Length = 4;
- d->HuffQ6[0][18].Code = 31; d->HuffQ6[0][18].Length = 5;
- d->HuffQ6[0][19].Code = 28; d->HuffQ6[0][19].Length = 5;
- d->HuffQ6[0][20].Code = 25; d->HuffQ6[0][20].Length = 5;
- d->HuffQ6[0][21].Code = 27; d->HuffQ6[0][21].Length = 5;
- d->HuffQ6[0][22].Code = 24; d->HuffQ6[0][22].Length = 5;
- d->HuffQ6[0][23].Code = 20; d->HuffQ6[0][23].Length = 5;
- d->HuffQ6[0][24].Code = 18; d->HuffQ6[0][24].Length = 5;
- d->HuffQ6[0][25].Code = 12; d->HuffQ6[0][25].Length = 5;
- d->HuffQ6[0][26].Code = 2; d->HuffQ6[0][26].Length = 5;
- d->HuffQ6[0][27].Code = 58; d->HuffQ6[0][27].Length = 6;
- d->HuffQ6[0][28].Code = 33; d->HuffQ6[0][28].Length = 6;
- d->HuffQ6[0][29].Code = 7; d->HuffQ6[0][29].Length = 6;
- d->HuffQ6[0][30].Code = 64; d->HuffQ6[0][30].Length = 7;
-
- //more shaped, book 1
- d->HuffQ6[1][ 0].Code = 6472; d->HuffQ6[1][ 0].Length = 13;
- d->HuffQ6[1][ 1].Code = 6474; d->HuffQ6[1][ 1].Length = 13;
- d->HuffQ6[1][ 2].Code = 808; d->HuffQ6[1][ 2].Length = 10;
- d->HuffQ6[1][ 3].Code = 405; d->HuffQ6[1][ 3].Length = 9;
- d->HuffQ6[1][ 4].Code = 203; d->HuffQ6[1][ 4].Length = 8;
- d->HuffQ6[1][ 5].Code = 102; d->HuffQ6[1][ 5].Length = 7;
- d->HuffQ6[1][ 6].Code = 49; d->HuffQ6[1][ 6].Length = 6;
- d->HuffQ6[1][ 7].Code = 9; d->HuffQ6[1][ 7].Length = 5;
- d->HuffQ6[1][ 8].Code = 15; d->HuffQ6[1][ 8].Length = 5;
- d->HuffQ6[1][ 9].Code = 31; d->HuffQ6[1][ 9].Length = 5;
- d->HuffQ6[1][10].Code = 2; d->HuffQ6[1][10].Length = 4;
- d->HuffQ6[1][11].Code = 6; d->HuffQ6[1][11].Length = 4;
- d->HuffQ6[1][12].Code = 8; d->HuffQ6[1][12].Length = 4;
- d->HuffQ6[1][13].Code = 11; d->HuffQ6[1][13].Length = 4;
- d->HuffQ6[1][14].Code = 13; d->HuffQ6[1][14].Length = 4;
- d->HuffQ6[1][15].Code = 0; d->HuffQ6[1][15].Length = 3;
- d->HuffQ6[1][16].Code = 14; d->HuffQ6[1][16].Length = 4;
- d->HuffQ6[1][17].Code = 10; d->HuffQ6[1][17].Length = 4;
- d->HuffQ6[1][18].Code = 9; d->HuffQ6[1][18].Length = 4;
- d->HuffQ6[1][19].Code = 5; d->HuffQ6[1][19].Length = 4;
- d->HuffQ6[1][20].Code = 3; d->HuffQ6[1][20].Length = 4;
- d->HuffQ6[1][21].Code = 30; d->HuffQ6[1][21].Length = 5;
- d->HuffQ6[1][22].Code = 14; d->HuffQ6[1][22].Length = 5;
- d->HuffQ6[1][23].Code = 8; d->HuffQ6[1][23].Length = 5;
- d->HuffQ6[1][24].Code = 48; d->HuffQ6[1][24].Length = 6;
- d->HuffQ6[1][25].Code = 103; d->HuffQ6[1][25].Length = 7;
- d->HuffQ6[1][26].Code = 201; d->HuffQ6[1][26].Length = 8;
- d->HuffQ6[1][27].Code = 200; d->HuffQ6[1][27].Length = 8;
- d->HuffQ6[1][28].Code = 1619; d->HuffQ6[1][28].Length = 11;
- d->HuffQ6[1][29].Code = 6473; d->HuffQ6[1][29].Length = 13;
- d->HuffQ6[1][30].Code = 6475; d->HuffQ6[1][30].Length = 13;
-
- /********************* 63-step quantizer **************************/
- /*********************** single samples ***************************/
- //less shaped, book 0
- d->HuffQ7[0][ 0].Code = 103; d->HuffQ7[0][ 0].Length = 8; /* 0.003338 - 01100111 */
- d->HuffQ7[0][ 1].Code = 153; d->HuffQ7[0][ 1].Length = 8; /* 0.003766 - 10011001 */
- d->HuffQ7[0][ 2].Code = 181; d->HuffQ7[0][ 2].Length = 8; /* 0.004715 - 10110101 */
- d->HuffQ7[0][ 3].Code = 233; d->HuffQ7[0][ 3].Length = 8; /* 0.005528 - 11101001 */
- d->HuffQ7[0][ 4].Code = 64; d->HuffQ7[0][ 4].Length = 7; /* 0.006677 - 1000000 */
- d->HuffQ7[0][ 5].Code = 65; d->HuffQ7[0][ 5].Length = 7; /* 0.007041 - 1000001 */
- d->HuffQ7[0][ 6].Code = 77; d->HuffQ7[0][ 6].Length = 7; /* 0.007733 - 1001101 */
- d->HuffQ7[0][ 7].Code = 81; d->HuffQ7[0][ 7].Length = 7; /* 0.008296 - 1010001 */
- d->HuffQ7[0][ 8].Code = 91; d->HuffQ7[0][ 8].Length = 7; /* 0.009295 - 1011011 */
- d->HuffQ7[0][ 9].Code = 113; d->HuffQ7[0][ 9].Length = 7; /* 0.010814 - 1110001 */
- d->HuffQ7[0][10].Code = 112; d->HuffQ7[0][10].Length = 7; /* 0.010807 - 1110000 */
- d->HuffQ7[0][11].Code = 24; d->HuffQ7[0][11].Length = 6; /* 0.012748 - 011000 */
- d->HuffQ7[0][12].Code = 29; d->HuffQ7[0][12].Length = 6; /* 0.013390 - 011101 */
- d->HuffQ7[0][13].Code = 35; d->HuffQ7[0][13].Length = 6; /* 0.014224 - 100011 */
- d->HuffQ7[0][14].Code = 37; d->HuffQ7[0][14].Length = 6; /* 0.015201 - 100101 */
- d->HuffQ7[0][15].Code = 41; d->HuffQ7[0][15].Length = 6; /* 0.016642 - 101001 */
- d->HuffQ7[0][16].Code = 44; d->HuffQ7[0][16].Length = 6; /* 0.017292 - 101100 */
- d->HuffQ7[0][17].Code = 46; d->HuffQ7[0][17].Length = 6; /* 0.018647 - 101110 */
- d->HuffQ7[0][18].Code = 51; d->HuffQ7[0][18].Length = 6; /* 0.020473 - 110011 */
- d->HuffQ7[0][19].Code = 49; d->HuffQ7[0][19].Length = 6; /* 0.020152 - 110001 */
- d->HuffQ7[0][20].Code = 54; d->HuffQ7[0][20].Length = 6; /* 0.021315 - 110110 */
- d->HuffQ7[0][21].Code = 55; d->HuffQ7[0][21].Length = 6; /* 0.021358 - 110111 */
- d->HuffQ7[0][22].Code = 57; d->HuffQ7[0][22].Length = 6; /* 0.021700 - 111001 */
- d->HuffQ7[0][23].Code = 60; d->HuffQ7[0][23].Length = 6; /* 0.022449 - 111100 */
- d->HuffQ7[0][24].Code = 0; d->HuffQ7[0][24].Length = 5; /* 0.023063 - 00000 */
- d->HuffQ7[0][25].Code = 2; d->HuffQ7[0][25].Length = 5; /* 0.023854 - 00010 */
- d->HuffQ7[0][26].Code = 10; d->HuffQ7[0][26].Length = 5; /* 0.025481 - 01010 */
- d->HuffQ7[0][27].Code = 5; d->HuffQ7[0][27].Length = 5; /* 0.024867 - 00101 */
- d->HuffQ7[0][28].Code = 9; d->HuffQ7[0][28].Length = 5; /* 0.025352 - 01001 */
- d->HuffQ7[0][29].Code = 6; d->HuffQ7[0][29].Length = 5; /* 0.025074 - 00110 */
- d->HuffQ7[0][30].Code = 13; d->HuffQ7[0][30].Length = 5; /* 0.025745 - 01101 */
- d->HuffQ7[0][31].Code = 7; d->HuffQ7[0][31].Length = 5; /* 0.025195 - 00111 */
- d->HuffQ7[0][32].Code = 11; d->HuffQ7[0][32].Length = 5; /* 0.025502 - 01011 */
- d->HuffQ7[0][33].Code = 15; d->HuffQ7[0][33].Length = 5; /* 0.026251 - 01111 */
- d->HuffQ7[0][34].Code = 8; d->HuffQ7[0][34].Length = 5; /* 0.025260 - 01000 */
- d->HuffQ7[0][35].Code = 4; d->HuffQ7[0][35].Length = 5; /* 0.024418 - 00100 */
- d->HuffQ7[0][36].Code = 3; d->HuffQ7[0][36].Length = 5; /* 0.023983 - 00011 */
- d->HuffQ7[0][37].Code = 1; d->HuffQ7[0][37].Length = 5; /* 0.023697 - 00001 */
- d->HuffQ7[0][38].Code = 63; d->HuffQ7[0][38].Length = 6; /* 0.023041 - 111111 */
- d->HuffQ7[0][39].Code = 62; d->HuffQ7[0][39].Length = 6; /* 0.022656 - 111110 */
- d->HuffQ7[0][40].Code = 61; d->HuffQ7[0][40].Length = 6; /* 0.022549 - 111101 */
- d->HuffQ7[0][41].Code = 53; d->HuffQ7[0][41].Length = 6; /* 0.021151 - 110101 */
- d->HuffQ7[0][42].Code = 59; d->HuffQ7[0][42].Length = 6; /* 0.022042 - 111011 */
- d->HuffQ7[0][43].Code = 52; d->HuffQ7[0][43].Length = 6; /* 0.020837 - 110100 */
- d->HuffQ7[0][44].Code = 48; d->HuffQ7[0][44].Length = 6; /* 0.019446 - 110000 */
- d->HuffQ7[0][45].Code = 47; d->HuffQ7[0][45].Length = 6; /* 0.019189 - 101111 */
- d->HuffQ7[0][46].Code = 43; d->HuffQ7[0][46].Length = 6; /* 0.017177 - 101011 */
- d->HuffQ7[0][47].Code = 42; d->HuffQ7[0][47].Length = 6; /* 0.017035 - 101010 */
- d->HuffQ7[0][48].Code = 39; d->HuffQ7[0][48].Length = 6; /* 0.015287 - 100111 */
- d->HuffQ7[0][49].Code = 36; d->HuffQ7[0][49].Length = 6; /* 0.014559 - 100100 */
- d->HuffQ7[0][50].Code = 33; d->HuffQ7[0][50].Length = 6; /* 0.014117 - 100001 */
- d->HuffQ7[0][51].Code = 28; d->HuffQ7[0][51].Length = 6; /* 0.012776 - 011100 */
- d->HuffQ7[0][52].Code = 117; d->HuffQ7[0][52].Length = 7; /* 0.011107 - 1110101 */
- d->HuffQ7[0][53].Code = 101; d->HuffQ7[0][53].Length = 7; /* 0.010636 - 1100101 */
- d->HuffQ7[0][54].Code = 100; d->HuffQ7[0][54].Length = 7; /* 0.009751 - 1100100 */
- d->HuffQ7[0][55].Code = 80; d->HuffQ7[0][55].Length = 7; /* 0.008132 - 1010000 */
- d->HuffQ7[0][56].Code = 69; d->HuffQ7[0][56].Length = 7; /* 0.007091 - 1000101 */
- d->HuffQ7[0][57].Code = 68; d->HuffQ7[0][57].Length = 7; /* 0.007084 - 1000100 */
- d->HuffQ7[0][58].Code = 50; d->HuffQ7[0][58].Length = 7; /* 0.006277 - 0110010 */
- d->HuffQ7[0][59].Code = 232; d->HuffQ7[0][59].Length = 8; /* 0.005386 - 11101000 */
- d->HuffQ7[0][60].Code = 180; d->HuffQ7[0][60].Length = 8; /* 0.004408 - 10110100 */
- d->HuffQ7[0][61].Code = 152; d->HuffQ7[0][61].Length = 8; /* 0.003759 - 10011000 */
- d->HuffQ7[0][62].Code = 102; d->HuffQ7[0][62].Length = 8; /* 0.003160 - 01100110 */
-
- //more shaped, book 1
- d->HuffQ7[1][ 0].Code = 14244; d->HuffQ7[1][ 0].Length = 14; /* 0.000059 - 11011110100100 */
- d->HuffQ7[1][ 1].Code = 14253; d->HuffQ7[1][ 1].Length = 14; /* 0.000098 - 11011110101101 */
- d->HuffQ7[1][ 2].Code = 14246; d->HuffQ7[1][ 2].Length = 14; /* 0.000078 - 11011110100110 */
- d->HuffQ7[1][ 3].Code = 14254; d->HuffQ7[1][ 3].Length = 14; /* 0.000111 - 11011110101110 */
- d->HuffQ7[1][ 4].Code = 3562; d->HuffQ7[1][ 4].Length = 12; /* 0.000320 - 110111101010 */
- d->HuffQ7[1][ 5].Code = 752; d->HuffQ7[1][ 5].Length = 10; /* 0.000920 - 1011110000 */
- d->HuffQ7[1][ 6].Code = 753; d->HuffQ7[1][ 6].Length = 10; /* 0.001057 - 1011110001 */
- d->HuffQ7[1][ 7].Code = 160; d->HuffQ7[1][ 7].Length = 9; /* 0.001403 - 010100000 */
- d->HuffQ7[1][ 8].Code = 162; d->HuffQ7[1][ 8].Length = 9; /* 0.001579 - 010100010 */
- d->HuffQ7[1][ 9].Code = 444; d->HuffQ7[1][ 9].Length = 9; /* 0.002486 - 110111100 */
- d->HuffQ7[1][10].Code = 122; d->HuffQ7[1][10].Length = 8; /* 0.003772 - 01111010 */
- d->HuffQ7[1][11].Code = 223; d->HuffQ7[1][11].Length = 8; /* 0.005710 - 11011111 */
- d->HuffQ7[1][12].Code = 60; d->HuffQ7[1][12].Length = 7; /* 0.006858 - 0111100 */
- d->HuffQ7[1][13].Code = 73; d->HuffQ7[1][13].Length = 7; /* 0.008033 - 1001001 */
- d->HuffQ7[1][14].Code = 110; d->HuffQ7[1][14].Length = 7; /* 0.009827 - 1101110 */
- d->HuffQ7[1][15].Code = 14; d->HuffQ7[1][15].Length = 6; /* 0.012601 - 001110 */
- d->HuffQ7[1][16].Code = 24; d->HuffQ7[1][16].Length = 6; /* 0.013194 - 011000 */
- d->HuffQ7[1][17].Code = 25; d->HuffQ7[1][17].Length = 6; /* 0.013938 - 011001 */
- d->HuffQ7[1][18].Code = 34; d->HuffQ7[1][18].Length = 6; /* 0.015693 - 100010 */
- d->HuffQ7[1][19].Code = 37; d->HuffQ7[1][19].Length = 6; /* 0.017846 - 100101 */
- d->HuffQ7[1][20].Code = 54; d->HuffQ7[1][20].Length = 6; /* 0.020078 - 110110 */
- d->HuffQ7[1][21].Code = 3; d->HuffQ7[1][21].Length = 5; /* 0.022975 - 00011 */
- d->HuffQ7[1][22].Code = 9; d->HuffQ7[1][22].Length = 5; /* 0.025631 - 01001 */
- d->HuffQ7[1][23].Code = 11; d->HuffQ7[1][23].Length = 5; /* 0.027021 - 01011 */
- d->HuffQ7[1][24].Code = 16; d->HuffQ7[1][24].Length = 5; /* 0.031465 - 10000 */
- d->HuffQ7[1][25].Code = 19; d->HuffQ7[1][25].Length = 5; /* 0.034244 - 10011 */
- d->HuffQ7[1][26].Code = 21; d->HuffQ7[1][26].Length = 5; /* 0.035921 - 10101 */
- d->HuffQ7[1][27].Code = 24; d->HuffQ7[1][27].Length = 5; /* 0.037938 - 11000 */
- d->HuffQ7[1][28].Code = 26; d->HuffQ7[1][28].Length = 5; /* 0.039595 - 11010 */
- d->HuffQ7[1][29].Code = 29; d->HuffQ7[1][29].Length = 5; /* 0.041546 - 11101 */
- d->HuffQ7[1][30].Code = 31; d->HuffQ7[1][30].Length = 5; /* 0.042623 - 11111 */
- d->HuffQ7[1][31].Code = 2; d->HuffQ7[1][31].Length = 4; /* 0.045180 - 0010 */
- d->HuffQ7[1][32].Code = 0; d->HuffQ7[1][32].Length = 4; /* 0.043151 - 0000 */
- d->HuffQ7[1][33].Code = 30; d->HuffQ7[1][33].Length = 5; /* 0.042538 - 11110 */
- d->HuffQ7[1][34].Code = 28; d->HuffQ7[1][34].Length = 5; /* 0.041422 - 11100 */
- d->HuffQ7[1][35].Code = 25; d->HuffQ7[1][35].Length = 5; /* 0.039145 - 11001 */
- d->HuffQ7[1][36].Code = 22; d->HuffQ7[1][36].Length = 5; /* 0.036691 - 10110 */
- d->HuffQ7[1][37].Code = 20; d->HuffQ7[1][37].Length = 5; /* 0.034955 - 10100 */
- d->HuffQ7[1][38].Code = 14; d->HuffQ7[1][38].Length = 5; /* 0.029155 - 01110 */
- d->HuffQ7[1][39].Code = 13; d->HuffQ7[1][39].Length = 5; /* 0.027921 - 01101 */
- d->HuffQ7[1][40].Code = 8; d->HuffQ7[1][40].Length = 5; /* 0.025553 - 01000 */
- d->HuffQ7[1][41].Code = 6; d->HuffQ7[1][41].Length = 5; /* 0.023093 - 00110 */
- d->HuffQ7[1][42].Code = 2; d->HuffQ7[1][42].Length = 5; /* 0.021200 - 00010 */
- d->HuffQ7[1][43].Code = 46; d->HuffQ7[1][43].Length = 6; /* 0.018134 - 101110 */
- d->HuffQ7[1][44].Code = 35; d->HuffQ7[1][44].Length = 6; /* 0.015824 - 100011 */
- d->HuffQ7[1][45].Code = 31; d->HuffQ7[1][45].Length = 6; /* 0.014701 - 011111 */
- d->HuffQ7[1][46].Code = 21; d->HuffQ7[1][46].Length = 6; /* 0.013187 - 010101 */
- d->HuffQ7[1][47].Code = 15; d->HuffQ7[1][47].Length = 6; /* 0.012776 - 001111 */
- d->HuffQ7[1][48].Code = 95; d->HuffQ7[1][48].Length = 7; /* 0.009664 - 1011111 */
- d->HuffQ7[1][49].Code = 72; d->HuffQ7[1][49].Length = 7; /* 0.007922 - 1001000 */
- d->HuffQ7[1][50].Code = 41; d->HuffQ7[1][50].Length = 7; /* 0.006838 - 0101001 */
- d->HuffQ7[1][51].Code = 189; d->HuffQ7[1][51].Length = 8; /* 0.005024 - 10111101 */
- d->HuffQ7[1][52].Code = 123; d->HuffQ7[1][52].Length = 8; /* 0.003830 - 01111011 */
- d->HuffQ7[1][53].Code = 377; d->HuffQ7[1][53].Length = 9; /* 0.002232 - 101111001 */
- d->HuffQ7[1][54].Code = 161; d->HuffQ7[1][54].Length = 9; /* 0.001566 - 010100001 */
- d->HuffQ7[1][55].Code = 891; d->HuffQ7[1][55].Length = 10; /* 0.001383 - 1101111011 */
- d->HuffQ7[1][56].Code = 327; d->HuffQ7[1][56].Length = 10; /* 0.000900 - 0101000111 */
- d->HuffQ7[1][57].Code = 326; d->HuffQ7[1][57].Length = 10; /* 0.000790 - 0101000110 */
- d->HuffQ7[1][58].Code = 3560; d->HuffQ7[1][58].Length = 12; /* 0.000254 - 110111101000 */
- d->HuffQ7[1][59].Code = 14255; d->HuffQ7[1][59].Length = 14; /* 0.000117 - 11011110101111 */
- d->HuffQ7[1][60].Code = 14247; d->HuffQ7[1][60].Length = 14; /* 0.000085 - 11011110100111 */
- d->HuffQ7[1][61].Code = 14252; d->HuffQ7[1][61].Length = 14; /* 0.000085 - 11011110101100 */
- d->HuffQ7[1][62].Code = 14245; d->HuffQ7[1][62].Length = 14; /* 0.000065 - 11011110100101 */
-}
diff --git a/src/libmusepack/idtag.c b/src/libmusepack/idtag.c
deleted file mode 100644
index 4b02b33f4..000000000
--- a/src/libmusepack/idtag.c
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- Copyright (c) 2004, The Musepack Development Team
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
- * Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials provided
- with the distribution.
-
- * Neither the name of the The Musepack Development Team nor the
- names of its contributors may be used to endorse or promote
- products derived from this software without specific prior
- written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-/// \file idtag.c
-/// Rudimentary id3tag handling routines, just enough to skip id3v2 tags,
-/// if present.
-
-#include "musepack/musepack.h"
-#include "musepack/internal.h"
-
-mpc_int32_t
-JumpID3v2 (mpc_reader* r) {
- unsigned char tmp [10];
- mpc_uint32_t Unsynchronisation; // ID3v2.4-flag
- mpc_uint32_t ExtHeaderPresent; // ID3v2.4-flag
- mpc_uint32_t ExperimentalFlag; // ID3v2.4-flag
- mpc_uint32_t FooterPresent; // ID3v2.4-flag
- mpc_int32_t ret;
-
- // seek to first byte of mpc data
- if (!r->seek (r->data, 0)) {
- return 0;
- }
-
- r->read(r->data, tmp, sizeof(tmp));
-
- // check id3-tag
- if ( 0 != memcmp ( tmp, "ID3", 3) )
- return 0;
-
- // read flags
- Unsynchronisation = tmp[5] & 0x80;
- ExtHeaderPresent = tmp[5] & 0x40;
- ExperimentalFlag = tmp[5] & 0x20;
- FooterPresent = tmp[5] & 0x10;
-
- if ( tmp[5] & 0x0F )
- return -1; // not (yet???) allowed
- if ( (tmp[6] | tmp[7] | tmp[8] | tmp[9]) & 0x80 )
- return -1; // not allowed
-
- // read HeaderSize (syncsave: 4 * $0xxxxxxx = 28 significant bits)
- ret = tmp[6] << 21;
- ret += tmp[7] << 14;
- ret += tmp[8] << 7;
- ret += tmp[9] ;
- ret += 10;
- if ( FooterPresent )
- ret += 10;
-
- return ret;
-}
diff --git a/src/libmusepack/mpc_decoder.c b/src/libmusepack/mpc_decoder.c
deleted file mode 100644
index d65708c52..000000000
--- a/src/libmusepack/mpc_decoder.c
+++ /dev/null
@@ -1,1349 +0,0 @@
-/*
- Copyright (c) 2004, The Musepack Development Team
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
- * Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials provided
- with the distribution.
-
- * Neither the name of the The Musepack Development Team nor the
- names of its contributors may be used to endorse or promote
- products derived from this software without specific prior
- written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-/// \file mpc_decoder.c
-/// Core decoding routines and logic.
-
-#include "musepack/musepack.h"
-#include "musepack/internal.h"
-#include "musepack/requant.h"
-#include "musepack/huffman.h"
-
-//------------------------------------------------------------------------------
-// types
-//------------------------------------------------------------------------------
-enum
- {
- EQ_TAP = 13, // length of FIR filter for EQ
- DELAY = ((EQ_TAP + 1) / 2), // delay of FIR
- FIR_BANDS = 4, // number of subbands to be FIR filtered
- MEMSIZE = MPC_DECODER_MEMSIZE, // overall buffer size
- MEMSIZE2 = (MEMSIZE/2), // size of one buffer
- MEMMASK = (MEMSIZE-1)
- };
-
-//------------------------------------------------------------------------------
-// forward declarations
-//------------------------------------------------------------------------------
-void mpc_decoder_init_huffman_sv6(mpc_decoder *d);
-void mpc_decoder_init_huffman_sv7(mpc_decoder *d);
-void mpc_decoder_read_bitstream_sv6(mpc_decoder *d);
-void mpc_decoder_read_bitstream_sv7(mpc_decoder *d);
-void mpc_decoder_update_buffer(mpc_decoder *d, mpc_uint32_t RING);
-mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample);
-void mpc_decoder_requantisierung(mpc_decoder *d, const mpc_int32_t Last_Band);
-
-//------------------------------------------------------------------------------
-// utility functions
-//------------------------------------------------------------------------------
-static mpc_int32_t f_read(mpc_decoder *d, void *ptr, size_t size)
-{
- return d->r->read(d->r->data, ptr, size);
-};
-
-static mpc_bool_t f_seek(mpc_decoder *d, mpc_int32_t offset)
-{
- return d->r->seek(d->r->data, offset);
-};
-
-static mpc_int32_t f_read_dword(mpc_decoder *d, mpc_uint32_t * ptr, mpc_uint32_t count)
-{
- count = f_read(d, ptr, count << 2) >> 2;
-#ifndef MPC_LITTLE_ENDIAN
- mpc_uint32_t n;
- for(n = 0; n< count; n++) {
- ptr[n] = swap32(ptr[n]);
- }
-#endif
- return count;
-}
-
-//------------------------------------------------------------------------------
-// huffman & bitstream functions
-//------------------------------------------------------------------------------
-static const mpc_uint32_t mask [33] = {
- 0x00000000, 0x00000001, 0x00000003, 0x00000007,
- 0x0000000F, 0x0000001F, 0x0000003F, 0x0000007F,
- 0x000000FF, 0x000001FF, 0x000003FF, 0x000007FF,
- 0x00000FFF, 0x00001FFF, 0x00003FFF, 0x00007FFF,
- 0x0000FFFF, 0x0001FFFF, 0x0003FFFF, 0x0007FFFF,
- 0x000FFFFF, 0x001FFFFF, 0x003FFFFF, 0x007FFFFF,
- 0x00FFFFFF, 0x01FFFFFF, 0x03FFFFFF, 0x07FFFFFF,
- 0x0FFFFFFF, 0x1FFFFFFF, 0x3FFFFFFF, 0x7FFFFFFF,
- 0xFFFFFFFF
-};
-
-/* F U N C T I O N S */
-
-// resets bitstream decoding
-static void
-mpc_decoder_reset_bitstream_decode(mpc_decoder *d)
-{
- d->dword = 0;
- d->pos = 0;
- d->Zaehler = 0;
- d->WordsRead = 0;
-}
-
-// reports the number of read bits
-static mpc_uint32_t
-mpc_decoder_bits_read(mpc_decoder *d)
-{
- return 32 * d->WordsRead + d->pos;
-}
-
-// read desired number of bits out of the bitstream
-static mpc_uint32_t
-mpc_decoder_bitstream_read(mpc_decoder *d, const mpc_uint32_t bits)
-{
- mpc_uint32_t out = d->dword;
-
- d->pos += bits;
-
- if (d->pos < 32) {
- out >>= (32 - d->pos);
- }
- else {
- d->dword = d->Speicher[d->Zaehler = (d->Zaehler + 1) & MEMMASK];
- d->pos -= 32;
- if (d->pos) {
- out <<= d->pos;
- out |= d->dword >> (32 - d->pos);
- }
- ++(d->WordsRead);
- }
-
- return out & mask[bits];
-}
-
-// decode SCFI-bundle (sv4,5,6)
-static void
-mpc_decoder_scfi_bundle_read(
- mpc_decoder *d,
- HuffmanTyp* Table, mpc_int32_t* SCFI, mpc_int32_t* DSCF)
-{
- // load preview and decode
- mpc_uint32_t code = d->dword << d->pos;
- if (d->pos > 26) {
- code |= d->Speicher[(d->Zaehler + 1) & MEMMASK] >> (32 - d->pos);
- }
- while (code < Table->Code) {
- Table++;
- }
-
- // set the new position within bitstream without performing a dummy-read
- if ((d->pos += Table->Length) >= 32) {
- d->pos -= 32;
- d->dword = d->Speicher[d->Zaehler = (d->Zaehler+1) & MEMMASK];
- ++(d->WordsRead);
- }
-
- *SCFI = Table->Value >> 1;
- *DSCF = Table->Value & 1;
-}
-
-static int
-mpc_decoder_huffman_typ_cmpfn(const void* p1, const void* p2)
-{
- if (((HuffmanTyp*) p1)->Code < ((HuffmanTyp*) p2)->Code ) return +1;
- if (((HuffmanTyp*) p1)->Code > ((HuffmanTyp*) p2)->Code ) return -1;
- return 0;
-}
-
-// sort huffman-tables by codeword
-// offset resulting value
-void
-mpc_decoder_resort_huff_tables(
- const mpc_uint32_t elements, HuffmanTyp* Table, const mpc_int32_t offset )
-{
- mpc_uint32_t i;
-
- for ( i = 0; i < elements; i++ ) {
- Table[i].Code <<= 32 - Table[i].Length;
- Table[i].Value = i - offset;
- }
- qsort(Table, elements, sizeof(*Table), mpc_decoder_huffman_typ_cmpfn);
-}
-
-// basic huffman decoding routine
-// works with maximum lengths up to 14
-static mpc_int32_t
-mpc_decoder_huffman_decode(mpc_decoder *d, const HuffmanTyp *Table)
-{
- // load preview and decode
- mpc_uint32_t code = d->dword << d->pos;
- if (d->pos > 18) {
- code |= d->Speicher[(d->Zaehler + 1) & MEMMASK] >> (32 - d->pos);
- }
- while (code < Table->Code) {
- Table++;
- }
-
- // set the new position within bitstream without performing a dummy-read
- if ((d->pos += Table->Length) >= 32) {
- d->pos -= 32;
- d->dword = d->Speicher[d->Zaehler = (d->Zaehler + 1) & MEMMASK];
- ++(d->WordsRead);
- }
-
- return Table->Value;
-}
-
-// faster huffman through previewing less bits
-// works with maximum lengths up to 10
-static mpc_int32_t
-mpc_decoder_huffman_decode_fast(mpc_decoder *d, const HuffmanTyp* Table)
-{
- // load preview and decode
- mpc_uint32_t code = d->dword << d->pos;
- if (d->pos > 22) {
- code |= d->Speicher[(d->Zaehler + 1) & MEMMASK] >> (32 - d->pos);
- }
- while (code < Table->Code) {
- Table++;
- }
-
- // set the new position within bitstream without performing a dummy-read
- if ((d->pos += Table->Length) >= 32) {
- d->pos -= 32;
- d->dword = d->Speicher[d->Zaehler = (d->Zaehler + 1) & MEMMASK];
- ++(d->WordsRead);
- }
-
- return Table->Value;
-}
-
-// even faster huffman through previewing even less bits
-// works with maximum lengths up to 5
-static mpc_int32_t
-mpc_decoder_huffman_decode_faster(mpc_decoder *d, const HuffmanTyp* Table)
-{
- // load preview and decode
- mpc_uint32_t code = d->dword << d->pos;
- if (d->pos > 27) {
- code |= d->Speicher[(d->Zaehler + 1) & MEMMASK] >> (32 - d->pos);
- }
- while (code < Table->Code) {
- Table++;
- }
-
- // set the new position within bitstream without performing a dummy-read
- if ((d->pos += Table->Length) >= 32) {
- d->pos -= 32;
- d->dword = d->Speicher[d->Zaehler = (d->Zaehler + 1) & MEMMASK];
- ++(d->WordsRead);
- }
-
- return Table->Value;
-}
-
-static void
-mpc_decoder_reset_v(mpc_decoder *d)
-{
- memset(d->V_L, 0, sizeof d->V_L);
- memset(d->V_R, 0, sizeof d->V_R);
-}
-
-static void
-mpc_decoder_reset_synthesis(mpc_decoder *d)
-{
- mpc_decoder_reset_v(d);
-}
-
-static void
-mpc_decoder_reset_y(mpc_decoder *d)
-{
- memset(d->Y_L, 0, sizeof d->Y_L);
- memset(d->Y_R, 0, sizeof d->Y_R);
-}
-
-static void
-mpc_decoder_reset_globals(mpc_decoder *d)
-{
- mpc_decoder_reset_bitstream_decode(d);
-
- d->DecodedFrames = 0;
- d->StreamVersion = 0;
- d->MS_used = 0;
-
- memset(d->Y_L , 0, sizeof d->Y_L );
- memset(d->Y_R , 0, sizeof d->Y_R );
- memset(d->SCF_Index_L , 0, sizeof d->SCF_Index_L );
- memset(d->SCF_Index_R , 0, sizeof d->SCF_Index_R );
- memset(d->Res_L , 0, sizeof d->Res_L );
- memset(d->Res_R , 0, sizeof d->Res_R );
- memset(d->SCFI_L , 0, sizeof d->SCFI_L );
- memset(d->SCFI_R , 0, sizeof d->SCFI_R );
- memset(d->DSCF_Flag_L , 0, sizeof d->DSCF_Flag_L );
- memset(d->DSCF_Flag_R , 0, sizeof d->DSCF_Flag_R );
- memset(d->DSCF_Reference_L, 0, sizeof d->DSCF_Reference_L );
- memset(d->DSCF_Reference_R, 0, sizeof d->DSCF_Reference_R );
- memset(d->Q , 0, sizeof d->Q );
- memset(d->MS_Flag , 0, sizeof d->MS_Flag );
-}
-
-static mpc_uint32_t
-mpc_decoder_decode_internal(mpc_decoder *d, MPC_SAMPLE_FORMAT *buffer)
-{
- mpc_uint32_t output_frame_length = MPC_FRAME_LENGTH;
-
- mpc_uint32_t FrameBitCnt = 0;
-
- if (d->DecodedFrames >= d->OverallFrames) {
- return (mpc_uint32_t)(-1); // end of file -> abort decoding
- }
-
- // read jump-info for validity check of frame
- d->FwdJumpInfo = mpc_decoder_bitstream_read(d, 20);
-
- d->ActDecodePos = (d->Zaehler << 5) + d->pos;
-
- // decode data and check for validity of frame
- FrameBitCnt = mpc_decoder_bits_read(d);
- switch (d->StreamVersion) {
- case 0x04:
- case 0x05:
- case 0x06:
- mpc_decoder_read_bitstream_sv6(d);
- break;
- case 0x07:
- case 0x17:
- mpc_decoder_read_bitstream_sv7(d);
- break;
- default:
- return (mpc_uint32_t)(-1);
- }
- d->FrameWasValid = mpc_decoder_bits_read(d) - FrameBitCnt == d->FwdJumpInfo;
-
- // synthesize signal
- mpc_decoder_requantisierung(d, d->Max_Band);
-
- //if ( d->EQ_activated && PluginSettings.EQbyMPC )
- // perform_EQ ();
-
- mpc_decoder_synthese_filter_float(d, buffer);
-
- d->DecodedFrames++;
-
- // cut off first MPC_DECODER_SYNTH_DELAY zero-samples
- if (d->DecodedFrames == d->OverallFrames && d->StreamVersion >= 6) {
- // reconstruct exact filelength
- mpc_int32_t mod_block = mpc_decoder_bitstream_read(d, 11);
- mpc_int32_t FilterDecay;
-
- if (mod_block == 0) {
- // Encoder bugfix
- mod_block = 1152;
- }
- FilterDecay = (mod_block + MPC_DECODER_SYNTH_DELAY) % MPC_FRAME_LENGTH;
-
- // additional FilterDecay samples are needed for decay of synthesis filter
- if (MPC_DECODER_SYNTH_DELAY + mod_block >= MPC_FRAME_LENGTH) {
-
- // **********************************************************************
- // Rhoades 4/16/2002
- // Commented out are blocks of code which cause gapless playback to fail.
- // Temporary fix...
- // **********************************************************************
-
- if (!d->TrueGaplessPresent) {
- mpc_decoder_reset_y(d);
- }
- else {
- //if ( MPC_FRAME_LENGTH != d->LastValidSamples ) {
- mpc_decoder_bitstream_read(d, 20);
- mpc_decoder_read_bitstream_sv7(d);
- mpc_decoder_requantisierung(d, d->Max_Band);
- //FilterDecay = d->LastValidSamples;
- //}
- //else {
- //FilterDecay = 0;
- //}
- }
-
- mpc_decoder_synthese_filter_float(d, buffer + 2304);
-
- output_frame_length = MPC_FRAME_LENGTH + FilterDecay;
- }
- else { // there are only FilterDecay samples needed for this frame
- output_frame_length = FilterDecay;
- }
- }
-
- if (d->samples_to_skip) {
- if (output_frame_length < d->samples_to_skip) {
- d->samples_to_skip -= output_frame_length;
- output_frame_length = 0;
- }
- else {
- output_frame_length -= d->samples_to_skip;
- memmove(
- buffer,
- buffer + d->samples_to_skip * 2,
- output_frame_length * 2 * sizeof (MPC_SAMPLE_FORMAT));
- d->samples_to_skip = 0;
- }
- }
-
- return output_frame_length;
-}
-
-mpc_uint32_t mpc_decoder_decode(
- mpc_decoder *d,
- MPC_SAMPLE_FORMAT *buffer,
- mpc_uint32_t *vbr_update_acc,
- mpc_uint32_t *vbr_update_bits)
-{
- for(;;)
- {
- //const mpc_int32_t MaxBrokenFrames = 0; // PluginSettings.MaxBrokenFrames
-
- mpc_uint32_t RING = d->Zaehler;
- mpc_int32_t vbr_ring = (RING << 5) + d->pos;
-
- mpc_uint32_t valid_samples = mpc_decoder_decode_internal(d, buffer);
-
- if (valid_samples == (mpc_uint32_t)(-1) ) {
- return 0;
- }
-
- /**************** ERROR CONCEALMENT *****************/
- if (d->FrameWasValid == 0 ) {
- // error occurred in bitstream
- return (mpc_uint32_t)(-1);
- }
- else {
- if (vbr_update_acc && vbr_update_bits) {
- (*vbr_update_acc) ++;
- vbr_ring = (d->Zaehler << 5) + d->pos - vbr_ring;
- if (vbr_ring < 0) {
- vbr_ring += 524288;
- }
- (*vbr_update_bits) += vbr_ring;
- }
-
- }
- mpc_decoder_update_buffer(d, RING);
-
- if (valid_samples > 0) {
- return valid_samples;
- }
- }
-}
-
-void
-mpc_decoder_requantisierung(mpc_decoder *d, const mpc_int32_t Last_Band)
-{
- mpc_int32_t Band;
- mpc_int32_t n;
- MPC_SAMPLE_FORMAT facL;
- MPC_SAMPLE_FORMAT facR;
- MPC_SAMPLE_FORMAT templ;
- MPC_SAMPLE_FORMAT tempr;
- MPC_SAMPLE_FORMAT* YL;
- MPC_SAMPLE_FORMAT* YR;
- mpc_int32_t* L;
- mpc_int32_t* R;
-
-#ifdef MPC_FIXED_POINT
-#if MPC_FIXED_POINT_FRACTPART == 14
-#define MPC_MULTIPLY_SCF(CcVal, SCF_idx) \
- MPC_MULTIPLY_EX(CcVal, d->SCF[SCF_idx], d->SCF_shift[SCF_idx])
-#else
-
-#error FIXME, Cc table is in 18.14 format
-
-#endif
-#else
-#define MPC_MULTIPLY_SCF(CcVal, SCF_idx) \
- MPC_MULTIPLY(CcVal, d->SCF[SCF_idx])
-#endif
- // requantization and scaling of subband-samples
- for ( Band = 0; Band <= Last_Band; Band++ ) { // setting pointers
- YL = d->Y_L[0] + Band;
- YR = d->Y_R[0] + Band;
- L = d->Q[Band].L;
- R = d->Q[Band].R;
- /************************** MS-coded **************************/
- if ( d->MS_Flag [Band] ) {
- if ( d->Res_L [Band] ) {
- if ( d->Res_R [Band] ) { // M!=0, S!=0
- facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][0]);
- facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][0]);
- for ( n = 0; n < 12; n++, YL += 32, YR += 32 ) {
- *YL = (templ = MPC_MULTIPLY_FLOAT_INT(facL,*L++))+(tempr = MPC_MULTIPLY_FLOAT_INT(facR,*R++));
- *YR = templ - tempr;
- }
- facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][1]);
- facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][1]);
- for ( ; n < 24; n++, YL += 32, YR += 32 ) {
- *YL = (templ = MPC_MULTIPLY_FLOAT_INT(facL,*L++))+(tempr = MPC_MULTIPLY_FLOAT_INT(facR,*R++));
- *YR = templ - tempr;
- }
- facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][2]);
- facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][2]);
- for ( ; n < 36; n++, YL += 32, YR += 32 ) {
- *YL = (templ = MPC_MULTIPLY_FLOAT_INT(facL,*L++))+(tempr = MPC_MULTIPLY_FLOAT_INT(facR,*R++));
- *YR = templ - tempr;
- }
- } else { // M!=0, S==0
- facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][0]);
- for ( n = 0; n < 12; n++, YL += 32, YR += 32 ) {
- *YR = *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++);
- }
- facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][1]);
- for ( ; n < 24; n++, YL += 32, YR += 32 ) {
- *YR = *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++);
- }
- facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][2]);
- for ( ; n < 36; n++, YL += 32, YR += 32 ) {
- *YR = *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++);
- }
- }
- } else {
- if (d->Res_R[Band]) // M==0, S!=0
- {
- facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][0]);
- for ( n = 0; n < 12; n++, YL += 32, YR += 32 ) {
- *YR = - (*YL = MPC_MULTIPLY_FLOAT_INT(facR,*(R++)));
- }
- facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][1]);
- for ( ; n < 24; n++, YL += 32, YR += 32 ) {
- *YR = - (*YL = MPC_MULTIPLY_FLOAT_INT(facR,*(R++)));
- }
- facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][2]);
- for ( ; n < 36; n++, YL += 32, YR += 32 ) {
- *YR = - (*YL = MPC_MULTIPLY_FLOAT_INT(facR,*(R++)));
- }
- } else { // M==0, S==0
- for ( n = 0; n < 36; n++, YL += 32, YR += 32 ) {
- *YR = *YL = 0;
- }
- }
- }
- }
- /************************** LR-coded **************************/
- else {
- if ( d->Res_L [Band] ) {
- if ( d->Res_R [Band] ) { // L!=0, R!=0
- facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][0]);
- facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][0]);
- for (n = 0; n < 12; n++, YL += 32, YR += 32 ) {
- *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++);
- *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++);
- }
- facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][1]);
- facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][1]);
- for (; n < 24; n++, YL += 32, YR += 32 ) {
- *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++);
- *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++);
- }
- facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][2]);
- facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][2]);
- for (; n < 36; n++, YL += 32, YR += 32 ) {
- *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++);
- *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++);
- }
- } else { // L!=0, R==0
- facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][0]);
- for ( n = 0; n < 12; n++, YL += 32, YR += 32 ) {
- *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++);
- *YR = 0;
- }
- facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][1]);
- for ( ; n < 24; n++, YL += 32, YR += 32 ) {
- *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++);
- *YR = 0;
- }
- facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][2]);
- for ( ; n < 36; n++, YL += 32, YR += 32 ) {
- *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++);
- *YR = 0;
- }
- }
- }
- else {
- if ( d->Res_R [Band] ) { // L==0, R!=0
- facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][0]);
- for ( n = 0; n < 12; n++, YL += 32, YR += 32 ) {
- *YL = 0;
- *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++);
- }
- facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][1]);
- for ( ; n < 24; n++, YL += 32, YR += 32 ) {
- *YL = 0;
- *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++);
- }
- facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][2]);
- for ( ; n < 36; n++, YL += 32, YR += 32 ) {
- *YL = 0;
- *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++);
- }
- } else { // L==0, R==0
- for ( n = 0; n < 36; n++, YL += 32, YR += 32 ) {
- *YR = *YL = 0;
- }
- }
- }
- }
- }
-}
-
-/****************************************** SV 6 ******************************************/
-void
-mpc_decoder_read_bitstream_sv6(mpc_decoder *d)
-{
- mpc_int32_t n,k;
- mpc_int32_t Max_used_Band=0;
- HuffmanTyp *Table;
- const HuffmanTyp *x1;
- const HuffmanTyp *x2;
- mpc_int32_t *L;
- mpc_int32_t *R;
- mpc_int32_t *ResL = d->Res_L;
- mpc_int32_t *ResR = d->Res_R;
-
- /************************ HEADER **************************/
- ResL = d->Res_L;
- ResR = d->Res_R;
- for (n=0; n <= d->Max_Band; ++n, ++ResL, ++ResR)
- {
- if (n<11) Table = d->Region_A;
- else if (n>=11 && n<=22) Table = d->Region_B;
- else /*if (n>=23)*/ Table = d->Region_C;
-
- *ResL = d->Q_res[n][mpc_decoder_huffman_decode(d, Table)];
- if (d->MS_used) {
- d->MS_Flag[n] = mpc_decoder_bitstream_read(d, 1);
- }
- *ResR = d->Q_res[n][mpc_decoder_huffman_decode(d, Table)];
-
- // only perform the following procedure up to the maximum non-zero subband
- if (*ResL || *ResR) Max_used_Band = n;
- }
-
- /************************* SCFI-Bundle *****************************/
- ResL = d->Res_L;
- ResR = d->Res_R;
- for (n=0; n<=Max_used_Band; ++n, ++ResL, ++ResR) {
- if (*ResL) mpc_decoder_scfi_bundle_read(d, d->SCFI_Bundle, &(d->SCFI_L[n]), &(d->DSCF_Flag_L[n]));
- if (*ResR) mpc_decoder_scfi_bundle_read(d, d->SCFI_Bundle, &(d->SCFI_R[n]), &(d->DSCF_Flag_R[n]));
- }
-
- /***************************** SCFI ********************************/
- ResL = d->Res_L;
- ResR = d->Res_R;
- L = d->SCF_Index_L[0];
- R = d->SCF_Index_R[0];
- for (n=0; n <= Max_used_Band; ++n, ++ResL, ++ResR, L+=3, R+=3)
- {
- if (*ResL)
- {
- /*********** DSCF ************/
- if (d->DSCF_Flag_L[n]==1)
- {
- L[2] = d->DSCF_Reference_L[n];
- switch (d->SCFI_L[n])
- {
- case 3:
- L[0] = L[2] + mpc_decoder_huffman_decode_fast(d, d->DSCF_Entropie);
- L[1] = L[0];
- L[2] = L[1];
- break;
- case 1:
- L[0] = L[2] + mpc_decoder_huffman_decode_fast(d, d->DSCF_Entropie);
- L[1] = L[0] + mpc_decoder_huffman_decode_fast(d, d->DSCF_Entropie);
- L[2] = L[1];
- break;
- case 2:
- L[0] = L[2] + mpc_decoder_huffman_decode_fast(d, d->DSCF_Entropie);
- L[1] = L[0];
- L[2] = L[1] + mpc_decoder_huffman_decode_fast(d, d->DSCF_Entropie);
- break;
- case 0:
- L[0] = L[2] + mpc_decoder_huffman_decode_fast(d, d->DSCF_Entropie);
- L[1] = L[0] + mpc_decoder_huffman_decode_fast(d, d->DSCF_Entropie);
- L[2] = L[1] + mpc_decoder_huffman_decode_fast(d, d->DSCF_Entropie);
- break;
- default:
- return;
- break;
- }
- }
- /************ SCF ************/
- else
- {
- switch (d->SCFI_L[n])
- {
- case 3:
- L[0] = mpc_decoder_bitstream_read(d, 6);
- L[1] = L[0];
- L[2] = L[1];
- break;
- case 1:
- L[0] = mpc_decoder_bitstream_read(d, 6);
- L[1] = mpc_decoder_bitstream_read(d, 6);
- L[2] = L[1];
- break;
- case 2:
- L[0] = mpc_decoder_bitstream_read(d, 6);
- L[1] = L[0];
- L[2] = mpc_decoder_bitstream_read(d, 6);
- break;
- case 0:
- L[0] = mpc_decoder_bitstream_read(d, 6);
- L[1] = mpc_decoder_bitstream_read(d, 6);
- L[2] = mpc_decoder_bitstream_read(d, 6);
- break;
- default:
- return;
- break;
- }
- }
- // update Reference for DSCF
- d->DSCF_Reference_L[n] = L[2];
- }
- if (*ResR)
- {
- R[2] = d->DSCF_Reference_R[n];
- /*********** DSCF ************/
- if (d->DSCF_Flag_R[n]==1)
- {
- switch (d->SCFI_R[n])
- {
- case 3:
- R[0] = R[2] + mpc_decoder_huffman_decode_fast(d, d->DSCF_Entropie);
- R[1] = R[0];
- R[2] = R[1];
- break;
- case 1:
- R[0] = R[2] + mpc_decoder_huffman_decode_fast(d, d->DSCF_Entropie);
- R[1] = R[0] + mpc_decoder_huffman_decode_fast(d, d->DSCF_Entropie);
- R[2] = R[1];
- break;
- case 2:
- R[0] = R[2] + mpc_decoder_huffman_decode_fast(d, d->DSCF_Entropie);
- R[1] = R[0];
- R[2] = R[1] + mpc_decoder_huffman_decode_fast(d, d->DSCF_Entropie);
- break;
- case 0:
- R[0] = R[2] + mpc_decoder_huffman_decode_fast(d, d->DSCF_Entropie);
- R[1] = R[0] + mpc_decoder_huffman_decode_fast(d, d->DSCF_Entropie);
- R[2] = R[1] + mpc_decoder_huffman_decode_fast(d, d->DSCF_Entropie);
- break;
- default:
- return;
- break;
- }
- }
- /************ SCF ************/
- else
- {
- switch (d->SCFI_R[n])
- {
- case 3:
- R[0] = mpc_decoder_bitstream_read(d, 6);
- R[1] = R[0];
- R[2] = R[1];
- break;
- case 1:
- R[0] = mpc_decoder_bitstream_read(d, 6);
- R[1] = mpc_decoder_bitstream_read(d, 6);
- R[2] = R[1];
- break;
- case 2:
- R[0] = mpc_decoder_bitstream_read(d, 6);
- R[1] = R[0];
- R[2] = mpc_decoder_bitstream_read(d, 6);
- break;
- case 0:
- R[0] = mpc_decoder_bitstream_read(d, 6);
- R[1] = mpc_decoder_bitstream_read(d, 6);
- R[2] = mpc_decoder_bitstream_read(d, 6);
- break;
- default:
- return;
- break;
- }
- }
- // update Reference for DSCF
- d->DSCF_Reference_R[n] = R[2];
- }
- }
-
- /**************************** Samples ****************************/
- ResL = d->Res_L;
- ResR = d->Res_R;
- for (n=0; n <= Max_used_Band; ++n, ++ResL, ++ResR)
- {
- // setting pointers
- x1 = d->SampleHuff[*ResL];
- x2 = d->SampleHuff[*ResR];
- L = d->Q[n].L;
- R = d->Q[n].R;
-
- if (x1!=NULL || x2!=NULL)
- for (k=0; k<36; ++k)
- {
- if (x1 != NULL) *L++ = mpc_decoder_huffman_decode_fast(d, x1);
- if (x2 != NULL) *R++ = mpc_decoder_huffman_decode_fast(d, x2);
- }
-
- if (*ResL>7 || *ResR>7)
- for (k=0; k<36; ++k)
- {
- if (*ResL>7) *L++ = (mpc_int32_t)mpc_decoder_bitstream_read(d, Res_bit[*ResL]) - Dc[*ResL];
- if (*ResR>7) *R++ = (mpc_int32_t)mpc_decoder_bitstream_read(d, Res_bit[*ResR]) - Dc[*ResR];
- }
- }
-}
-
-/****************************************** SV 7 ******************************************/
-void
-mpc_decoder_read_bitstream_sv7(mpc_decoder *d)
-{
- // these arrays hold decoding results for bundled quantizers (3- and 5-step)
- /*static*/ mpc_int32_t idx30[] = { -1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1};
- /*static*/ mpc_int32_t idx31[] = { -1,-1,-1, 0, 0, 0, 1, 1, 1,-1,-1,-1, 0, 0, 0, 1, 1, 1,-1,-1,-1, 0, 0, 0, 1, 1, 1};
- /*static*/ mpc_int32_t idx32[] = { -1,-1,-1,-1,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1};
- /*static*/ mpc_int32_t idx50[] = { -2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2};
- /*static*/ mpc_int32_t idx51[] = { -2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2};
-
- mpc_int32_t n,k;
- mpc_int32_t Max_used_Band=0;
- const HuffmanTyp *Table;
- mpc_int32_t idx;
- mpc_int32_t *L ,*R;
- mpc_int32_t *ResL,*ResR;
- mpc_uint32_t tmp;
-
- /***************************** Header *****************************/
- ResL = d->Res_L;
- ResR = d->Res_R;
-
- // first subband
- *ResL = mpc_decoder_bitstream_read(d, 4);
- *ResR = mpc_decoder_bitstream_read(d, 4);
- if (d->MS_used && !(*ResL==0 && *ResR==0)) {
- d->MS_Flag[0] = mpc_decoder_bitstream_read(d, 1);
- }
-
- // consecutive subbands
- ++ResL; ++ResR; // increase pointers
- for (n=1; n <= d->Max_Band; ++n, ++ResL, ++ResR)
- {
- idx = mpc_decoder_huffman_decode_fast(d, d->HuffHdr);
- *ResL = (idx!=4) ? *(ResL-1) + idx : mpc_decoder_bitstream_read(d, 4);
-
- idx = mpc_decoder_huffman_decode_fast(d, d->HuffHdr);
- *ResR = (idx!=4) ? *(ResR-1) + idx : mpc_decoder_bitstream_read(d, 4);
-
- if (d->MS_used && !(*ResL==0 && *ResR==0)) {
- d->MS_Flag[n] = mpc_decoder_bitstream_read(d, 1);
- }
-
- // only perform following procedures up to the maximum non-zero subband
- if (*ResL!=0 || *ResR!=0) {
- Max_used_Band = n;
- }
- }
- /****************************** SCFI ******************************/
- L = d->SCFI_L;
- R = d->SCFI_R;
- ResL = d->Res_L;
- ResR = d->Res_R;
- for (n=0; n <= Max_used_Band; ++n, ++L, ++R, ++ResL, ++ResR) {
- if (*ResL) *L = mpc_decoder_huffman_decode_faster(d, d->HuffSCFI);
- if (*ResR) *R = mpc_decoder_huffman_decode_faster(d, d->HuffSCFI);
- }
-
- /**************************** SCF/DSCF ****************************/
- ResL = d->Res_L;
- ResR = d->Res_R;
- L = d->SCF_Index_L[0];
- R = d->SCF_Index_R[0];
- for (n=0; n<=Max_used_Band; ++n, ++ResL, ++ResR, L+=3, R+=3) {
- if (*ResL)
- {
- L[2] = d->DSCF_Reference_L[n];
- switch (d->SCFI_L[n])
- {
- case 1:
- idx = mpc_decoder_huffman_decode_fast(d, d->HuffDSCF);
- L[0] = (idx!=8) ? L[2] + idx : mpc_decoder_bitstream_read(d, 6);
- idx = mpc_decoder_huffman_decode_fast(d, d->HuffDSCF);
- L[1] = (idx!=8) ? L[0] + idx : mpc_decoder_bitstream_read(d, 6);
- L[2] = L[1];
- break;
- case 3:
- idx = mpc_decoder_huffman_decode_fast(d, d->HuffDSCF);
- L[0] = (idx!=8) ? L[2] + idx : mpc_decoder_bitstream_read(d, 6);
- L[1] = L[0];
- L[2] = L[1];
- break;
- case 2:
- idx = mpc_decoder_huffman_decode_fast(d, d->HuffDSCF);
- L[0] = (idx!=8) ? L[2] + idx : mpc_decoder_bitstream_read(d, 6);
- L[1] = L[0];
- idx = mpc_decoder_huffman_decode_fast(d, d->HuffDSCF);
- L[2] = (idx!=8) ? L[1] + idx : mpc_decoder_bitstream_read(d, 6);
- break;
- case 0:
- idx = mpc_decoder_huffman_decode_fast(d, d->HuffDSCF);
- L[0] = (idx!=8) ? L[2] + idx : mpc_decoder_bitstream_read(d, 6);
- idx = mpc_decoder_huffman_decode_fast(d, d->HuffDSCF);
- L[1] = (idx!=8) ? L[0] + idx : mpc_decoder_bitstream_read(d, 6);
- idx = mpc_decoder_huffman_decode_fast(d, d->HuffDSCF);
- L[2] = (idx!=8) ? L[1] + idx : mpc_decoder_bitstream_read(d, 6);
- break;
- default:
- return;
- break;
- }
- // update Reference for DSCF
- d->DSCF_Reference_L[n] = L[2];
- }
- if (*ResR)
- {
- R[2] = d->DSCF_Reference_R[n];
- switch (d->SCFI_R[n])
- {
- case 1:
- idx = mpc_decoder_huffman_decode_fast(d, d->HuffDSCF);
- R[0] = (idx!=8) ? R[2] + idx : mpc_decoder_bitstream_read(d, 6);
- idx = mpc_decoder_huffman_decode_fast(d, d->HuffDSCF);
- R[1] = (idx!=8) ? R[0] + idx : mpc_decoder_bitstream_read(d, 6);
- R[2] = R[1];
- break;
- case 3:
- idx = mpc_decoder_huffman_decode_fast(d, d->HuffDSCF);
- R[0] = (idx!=8) ? R[2] + idx : mpc_decoder_bitstream_read(d, 6);
- R[1] = R[0];
- R[2] = R[1];
- break;
- case 2:
- idx = mpc_decoder_huffman_decode_fast(d, d->HuffDSCF);
- R[0] = (idx!=8) ? R[2] + idx : mpc_decoder_bitstream_read(d, 6);
- R[1] = R[0];
- idx = mpc_decoder_huffman_decode_fast(d, d->HuffDSCF);
- R[2] = (idx!=8) ? R[1] + idx : mpc_decoder_bitstream_read(d, 6);
- break;
- case 0:
- idx = mpc_decoder_huffman_decode_fast(d, d->HuffDSCF);
- R[0] = (idx!=8) ? R[2] + idx : mpc_decoder_bitstream_read(d, 6);
- idx = mpc_decoder_huffman_decode_fast(d, d->HuffDSCF);
- R[1] = (idx!=8) ? R[0] + idx : mpc_decoder_bitstream_read(d, 6);
- idx = mpc_decoder_huffman_decode_fast(d, d->HuffDSCF);
- R[2] = (idx!=8) ? R[1] + idx : mpc_decoder_bitstream_read(d, 6);
- break;
- default:
- return;
- break;
- }
- // update Reference for DSCF
- d->DSCF_Reference_R[n] = R[2];
- }
- }
- /***************************** Samples ****************************/
- ResL = d->Res_L;
- ResR = d->Res_R;
- L = d->Q[0].L;
- R = d->Q[0].R;
- for (n=0; n <= Max_used_Band; ++n, ++ResL, ++ResR, L+=36, R+=36)
- {
- /************** links **************/
- switch (*ResL)
- {
- case -2: case -3: case -4: case -5: case -6: case -7: case -8: case -9:
- case -10: case -11: case -12: case -13: case -14: case -15: case -16: case -17:
- L += 36;
- break;
- case -1:
- for (k=0; k<36; k++ ) {
- tmp = random_int(d);
- *L++ = ((tmp >> 24) & 0xFF) + ((tmp >> 16) & 0xFF) + ((tmp >> 8) & 0xFF) + ((tmp >> 0) & 0xFF) - 510;
- }
- break;
- case 0:
- L += 36;// increase pointer
- break;
- case 1:
- Table = d->HuffQ[mpc_decoder_bitstream_read(d, 1)][1];
- for (k=0; k<12; ++k)
- {
- idx = mpc_decoder_huffman_decode_fast(d, Table);
- *L++ = idx30[idx];
- *L++ = idx31[idx];
- *L++ = idx32[idx];
- }
- break;
- case 2:
- Table = d->HuffQ[mpc_decoder_bitstream_read(d, 1)][2];
- for (k=0; k<18; ++k)
- {
- idx = mpc_decoder_huffman_decode_fast(d, Table);
- *L++ = idx50[idx];
- *L++ = idx51[idx];
- }
- break;
- case 3:
- case 4:
- Table = d->HuffQ[mpc_decoder_bitstream_read(d, 1)][*ResL];
- for (k=0; k<36; ++k)
- *L++ = mpc_decoder_huffman_decode_faster(d, Table);
- break;
- case 5:
- Table = d->HuffQ[mpc_decoder_bitstream_read(d, 1)][*ResL];
- for (k=0; k<36; ++k)
- *L++ = mpc_decoder_huffman_decode_fast(d, Table);
- break;
- case 6:
- case 7:
- Table = d->HuffQ[mpc_decoder_bitstream_read(d, 1)][*ResL];
- for (k=0; k<36; ++k)
- *L++ = mpc_decoder_huffman_decode(d, Table);
- break;
- case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17:
- tmp = Dc[*ResL];
- for (k=0; k<36; ++k)
- *L++ = (mpc_int32_t)mpc_decoder_bitstream_read(d, Res_bit[*ResL]) - tmp;
- break;
- default:
- return;
- }
- /************** rechts **************/
- switch (*ResR)
- {
- case -2: case -3: case -4: case -5: case -6: case -7: case -8: case -9:
- case -10: case -11: case -12: case -13: case -14: case -15: case -16: case -17:
- R += 36;
- break;
- case -1:
- for (k=0; k<36; k++ ) {
- tmp = random_int(d);
- *R++ = ((tmp >> 24) & 0xFF) + ((tmp >> 16) & 0xFF) + ((tmp >> 8) & 0xFF) + ((tmp >> 0) & 0xFF) - 510;
- }
- break;
- case 0:
- R += 36;// increase pointer
- break;
- case 1:
- Table = d->HuffQ[mpc_decoder_bitstream_read(d, 1)][1];
- for (k=0; k<12; ++k)
- {
- idx = mpc_decoder_huffman_decode_fast(d, Table);
- *R++ = idx30[idx];
- *R++ = idx31[idx];
- *R++ = idx32[idx];
- }
- break;
- case 2:
- Table = d->HuffQ[mpc_decoder_bitstream_read(d, 1)][2];
- for (k=0; k<18; ++k)
- {
- idx = mpc_decoder_huffman_decode_fast(d, Table);
- *R++ = idx50[idx];
- *R++ = idx51[idx];
- }
- break;
- case 3:
- case 4:
- Table = d->HuffQ[mpc_decoder_bitstream_read(d, 1)][*ResR];
- for (k=0; k<36; ++k)
- *R++ = mpc_decoder_huffman_decode_faster(d, Table);
- break;
- case 5:
- Table = d->HuffQ[mpc_decoder_bitstream_read(d, 1)][*ResR];
- for (k=0; k<36; ++k)
- *R++ = mpc_decoder_huffman_decode_fast(d, Table);
- break;
- case 6:
- case 7:
- Table = d->HuffQ[mpc_decoder_bitstream_read(d, 1)][*ResR];
- for (k=0; k<36; ++k)
- *R++ = mpc_decoder_huffman_decode(d, Table);
- break;
- case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17:
- tmp = Dc[*ResR];
- for (k=0; k<36; ++k)
- *R++ = (mpc_int32_t)mpc_decoder_bitstream_read(d, Res_bit[*ResR]) - tmp;
- break;
- default:
- return;
- }
- }
-}
-
-void mpc_decoder_setup(mpc_decoder *d, mpc_reader *r)
-{
- d->r = r;
-
- d->HuffQ[0][0] = 0;
- d->HuffQ[1][0] = 0;
- d->HuffQ[0][1] = d->HuffQ1[0];
- d->HuffQ[1][1] = d->HuffQ1[1];
- d->HuffQ[0][2] = d->HuffQ2[0];
- d->HuffQ[1][2] = d->HuffQ2[1];
- d->HuffQ[0][3] = d->HuffQ3[0];
- d->HuffQ[1][3] = d->HuffQ3[1];
- d->HuffQ[0][4] = d->HuffQ4[0];
- d->HuffQ[1][4] = d->HuffQ4[1];
- d->HuffQ[0][5] = d->HuffQ5[0];
- d->HuffQ[1][5] = d->HuffQ5[1];
- d->HuffQ[0][6] = d->HuffQ6[0];
- d->HuffQ[1][6] = d->HuffQ6[1];
- d->HuffQ[0][7] = d->HuffQ7[0];
- d->HuffQ[1][7] = d->HuffQ7[1];
-
- d->SampleHuff[0] = NULL;
- d->SampleHuff[1] = d->Entropie_1;
- d->SampleHuff[2] = d->Entropie_2;
- d->SampleHuff[3] = d->Entropie_3;
- d->SampleHuff[4] = d->Entropie_4;
- d->SampleHuff[5] = d->Entropie_5;
- d->SampleHuff[6] = d->Entropie_6;
- d->SampleHuff[7] = d->Entropie_7;
- d->SampleHuff[8] = NULL;
- d->SampleHuff[9] = NULL;
- d->SampleHuff[10] = NULL;
- d->SampleHuff[11] = NULL;
- d->SampleHuff[12] = NULL;
- d->SampleHuff[13] = NULL;
- d->SampleHuff[14] = NULL;
- d->SampleHuff[15] = NULL;
- d->SampleHuff[16] = NULL;
- d->SampleHuff[17] = NULL;
-
- d->EQ_activated = 0;
- d->MPCHeaderPos = 0;
- d->StreamVersion = 0;
- d->MS_used = 0;
- d->FwdJumpInfo = 0;
- d->ActDecodePos = 0;
- d->FrameWasValid = 0;
- d->OverallFrames = 0;
- d->DecodedFrames = 0;
- d->LastValidSamples = 0;
- d->TrueGaplessPresent = 0;
- d->WordsRead = 0;
- d->Max_Band = 0;
- d->SampleRate = 0;
-// clips = 0;
- d->__r1 = 1;
- d->__r2 = 1;
-
- d->dword = 0;
- d->pos = 0;
- d->Zaehler = 0;
- d->WordsRead = 0;
- d->Max_Band = 0;
-
- mpc_decoder_initialisiere_quantisierungstabellen(d, 1.0f);
- mpc_decoder_init_huffman_sv6(d);
- mpc_decoder_init_huffman_sv7(d);
-}
-
-static void mpc_decoder_set_streaminfo(mpc_decoder *d, mpc_streaminfo *si)
-{
- mpc_decoder_reset_synthesis(d);
- mpc_decoder_reset_globals(d);
-
- d->StreamVersion = si->stream_version;
- d->MS_used = si->ms;
- d->Max_Band = si->max_band;
- d->OverallFrames = si->frames;
- d->MPCHeaderPos = si->header_position;
- d->LastValidSamples = si->last_frame_samples;
- d->TrueGaplessPresent = si->is_true_gapless;
- d->SampleRate = (mpc_int32_t)si->sample_freq;
-
- d->samples_to_skip = MPC_DECODER_SYNTH_DELAY;
-}
-
-mpc_bool_t mpc_decoder_initialize(mpc_decoder *d, mpc_streaminfo *si)
-{
- mpc_decoder_set_streaminfo(d, si);
-
- // AB: setting position to the beginning of the data-bitstream
- switch (d->StreamVersion) {
- case 0x04: f_seek(d, 4 + d->MPCHeaderPos); d->pos = 16; break; // Geht auch über eine der Helperfunktionen
- case 0x05:
- case 0x06: f_seek(d, 8 + d->MPCHeaderPos); d->pos = 0; break;
- case 0x07:
- case 0x17: /*f_seek ( 24 + d->MPCHeaderPos );*/ d->pos = 8; break;
- default: return FALSE;
- }
-
- // AB: fill buffer and initialize decoder
- f_read_dword(d, d->Speicher, MEMSIZE );
- d->dword = d->Speicher[d->Zaehler = 0];
-
- return TRUE;
-}
-
-//---------------------------------------------------------------
-// will seek from the beginning of the file to the desired
-// position in ms (given by seek_needed)
-//---------------------------------------------------------------
-#if 0
-static void
-helper1(mpc_decoder *d, mpc_uint32_t bitpos)
-{
- f_seek(d, (bitpos >> 5) * 4 + d->MPCHeaderPos);
- f_read_dword(d, d->Speicher, 2);
- d->dword = d->Speicher[d->Zaehler = 0];
- d->pos = bitpos & 31;
-}
-#endif
-
-static void
-helper2(mpc_decoder *d, mpc_uint32_t bitpos)
-{
- f_seek(d, (bitpos>>5) * 4 + d->MPCHeaderPos);
- f_read_dword(d, d->Speicher, MEMSIZE);
- d->dword = d->Speicher[d->Zaehler = 0];
- d->pos = bitpos & 31;
-}
-
-#if 0
-static void
-helper3(mpc_decoder *d, mpc_uint32_t bitpos, mpc_uint32_t* buffoffs)
-{
- d->pos = bitpos & 31;
- bitpos >>= 5;
- if ((mpc_uint32_t)(bitpos - *buffoffs) >= MEMSIZE - 2) {
- *buffoffs = bitpos;
- f_seek(d, bitpos * 4L + d->MPCHeaderPos);
- f_read_dword(d, d->Speicher, MEMSIZE );
- }
- d->dword = d->Speicher[d->Zaehler = bitpos - *buffoffs ];
-}
-#endif
-
-static mpc_uint32_t get_initial_fpos(mpc_decoder *d, mpc_uint32_t StreamVersion)
-{
- mpc_uint32_t fpos = 0;
- switch ( d->StreamVersion ) { // setting position to the beginning of the data-bitstream
- case 0x04: fpos = 48; break;
- case 0x05:
- case 0x06: fpos = 64; break;
- case 0x07:
- case 0x17: fpos = 200; break;
- }
- return fpos;
-}
-
-mpc_bool_t mpc_decoder_seek_seconds(mpc_decoder *d, double seconds)
-{
- return mpc_decoder_seek_sample(d, (mpc_int64_t)(seconds * (double)d->SampleRate + 0.5));
-}
-
-mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample)
-{
- mpc_uint32_t fpos;
- mpc_uint32_t fwd;
-
- fwd = (mpc_uint32_t) (destsample / MPC_FRAME_LENGTH);
- d->samples_to_skip = MPC_DECODER_SYNTH_DELAY + (mpc_uint32_t)(destsample % MPC_FRAME_LENGTH);
-
- memset(d->Y_L , 0, sizeof d->Y_L );
- memset(d->Y_R , 0, sizeof d->Y_R );
- memset(d->SCF_Index_L , 0, sizeof d->SCF_Index_L );
- memset(d->SCF_Index_R , 0, sizeof d->SCF_Index_R );
- memset(d->Res_L , 0, sizeof d->Res_L );
- memset(d->Res_R , 0, sizeof d->Res_R );
- memset(d->SCFI_L , 0, sizeof d->SCFI_L );
- memset(d->SCFI_R , 0, sizeof d->SCFI_R );
- memset(d->DSCF_Flag_L , 0, sizeof d->DSCF_Flag_L );
- memset(d->DSCF_Flag_R , 0, sizeof d->DSCF_Flag_R );
- memset(d->DSCF_Reference_L, 0, sizeof d->DSCF_Reference_L );
- memset(d->DSCF_Reference_R, 0, sizeof d->DSCF_Reference_R );
- memset(d->Q , 0, sizeof d->Q );
- memset(d->MS_Flag , 0, sizeof d->MS_Flag );
-
- // resetting synthesis filter to avoid "clicks"
- mpc_decoder_reset_synthesis(d);
-
- // prevent from desired position out of allowed range
- fwd = fwd < d->OverallFrames ? fwd : d->OverallFrames;
-
- // reset number of decoded frames
- d->DecodedFrames = 0;
-
- fpos = get_initial_fpos(d, d->StreamVersion);
- if (fpos == 0) {
- return FALSE;
- }
-
- helper2(d, fpos);
-
- // read the last 32 frames before the desired position to scan the scalefactors (artifactless jumping)
- for ( ; d->DecodedFrames < fwd; d->DecodedFrames++ ) {
- mpc_uint32_t FrameBitCnt;
- mpc_uint32_t RING;
- RING = d->Zaehler;
- d->FwdJumpInfo = mpc_decoder_bitstream_read(d, 20); // read jump-info
- d->ActDecodePos = (d->Zaehler << 5) + d->pos;
- FrameBitCnt = mpc_decoder_bits_read(d); // scanning the scalefactors and check for validity of frame
- if (d->StreamVersion >= 7) {
- mpc_decoder_read_bitstream_sv7(d);
- }
- else {
- mpc_decoder_read_bitstream_sv6(d);
- }
- if (mpc_decoder_bits_read(d) - FrameBitCnt != d->FwdJumpInfo ) {
- // Box ("Bug in perform_jump");
- return FALSE;
- }
- // update buffer
- if ((RING ^ d->Zaehler) & MEMSIZE2) {
- f_read_dword(d, d->Speicher + (RING & MEMSIZE2), MEMSIZE2);
- }
- }
-
- // LastBitsRead = BitsRead ();
- // LastFrame = d->DecodedFrames;
-
- return TRUE;
-}
-
-void mpc_decoder_update_buffer(mpc_decoder *d, mpc_uint32_t RING)
-{
- if ((RING ^ d->Zaehler) & MEMSIZE2 ) {
- // update buffer
- f_read_dword(d, d->Speicher + (RING & MEMSIZE2), MEMSIZE2);
- }
-}
-
-
diff --git a/src/libmusepack/mpc_reader.c b/src/libmusepack/mpc_reader.c
deleted file mode 100644
index 5ed913698..000000000
--- a/src/libmusepack/mpc_reader.c
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- Copyright (c) 2004, The Musepack Development Team
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
- * Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials provided
- with the distribution.
-
- * Neither the name of the The Musepack Development Team nor the
- names of its contributors may be used to endorse or promote
- products derived from this software without specific prior
- written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-/// \file mpc_reader.c
-/// Contains implementations for simple file-based mpc_reader
-
-#include "musepack/musepack.h"
-
-/// mpc_reader callback implementations
-static mpc_int32_t
-read_impl(void *data, void *ptr, mpc_int32_t size)
-{
- mpc_reader *d = (mpc_reader *) data;
-
- return fread(ptr, 1, size, d->file);
-}
-
-static mpc_bool_t
-seek_impl(void *data, int offset)
-{
- mpc_reader *d = (mpc_reader *) data;
-
- return d->is_seekable ? !fseek(d->file, offset, SEEK_SET) : FALSE;
-}
-
-static mpc_int32_t
-tell_impl(void *data)
-{
- mpc_reader *d = (mpc_reader *) data;
-
- return ftell(d->file);
-}
-
-static mpc_int32_t
-get_size_impl(void *data)
-{
- mpc_reader *d = (mpc_reader *) data;
-
- return d->file_size;
-}
-
-static mpc_bool_t
-canseek_impl(void *data)
-{
- mpc_reader *d = (mpc_reader *) data;
-
- return d->is_seekable;
-}
-
-void
-mpc_reader_setup_file_reader(mpc_reader *reader, FILE *input)
-{
- reader->seek = seek_impl;
- reader->read = read_impl;
- reader->tell = tell_impl;
- reader->get_size = get_size_impl;
- reader->canseek = canseek_impl;
- reader->data = reader; // point back to ourselves
-
- reader->file = input;
- reader->is_seekable = TRUE;
- fseek(reader->file, 0, SEEK_END);
- reader->file_size = ftell(reader->file);
- fseek(reader->file, 0, SEEK_SET);
-}
diff --git a/src/libmusepack/musepack/Makefile.am b/src/libmusepack/musepack/Makefile.am
deleted file mode 100644
index 1d37e1d79..000000000
--- a/src/libmusepack/musepack/Makefile.am
+++ /dev/null
@@ -1,5 +0,0 @@
-include $(top_srcdir)/misc/Makefile.common
-
-noinst_HEADERS = config_types.h decoder.h huffman.h internal.h math.h \
- musepack.h reader.h requant.h streaminfo.h
-
diff --git a/src/libmusepack/musepack/config_types.h b/src/libmusepack/musepack/config_types.h
deleted file mode 100644
index f501f5a38..000000000
--- a/src/libmusepack/musepack/config_types.h
+++ /dev/null
@@ -1,23 +0,0 @@
-#ifndef __CONFIG_TYPES_H__
-#define __CONFIG_TYPES_H__
-
-#include "os_types.h"
-
-#ifdef WORDS_BIGENDIAN
- #undef MPC_LITTLE_ENDIAN
-#else
- #define MPC_LITTLE_ENDIAN
-#endif
-
-typedef unsigned char mpc_bool_t;
-#define TRUE 1
-#define FALSE 0
-
-/* these are filled in by configure */
-typedef int16_t mpc_int16_t;
-typedef uint16_t mpc_uint16_t;
-typedef int32_t mpc_int32_t;
-typedef uint32_t mpc_uint32_t;
-typedef int64_t mpc_int64_t;
-
-#endif
diff --git a/src/libmusepack/musepack/decoder.h b/src/libmusepack/musepack/decoder.h
deleted file mode 100644
index 08c316390..000000000
--- a/src/libmusepack/musepack/decoder.h
+++ /dev/null
@@ -1,114 +0,0 @@
-/// \file decoder.h
-
-#ifndef _musepack_decoder_h_
-#define _musepack_decoder_h_
-
-#include "musepack/huffman.h"
-#include "musepack/math.h"
-#include "musepack/musepack.h"
-#include "musepack/reader.h"
-#include "musepack/streaminfo.h"
-
-enum {
- MPC_V_MEM = 2304,
- MPC_DECODER_MEMSIZE = 16384, // overall buffer size
-};
-
-typedef struct {
- mpc_int32_t L [36];
- mpc_int32_t R [36];
-} QuantTyp;
-
-typedef struct mpc_decoder_t {
- mpc_reader *r;
-
- /// @name internal state variables
- //@{
-
- mpc_uint32_t dword; /// actually decoded 32bit-word
- mpc_uint32_t pos; /// bit-position within dword
- mpc_uint32_t Speicher[MPC_DECODER_MEMSIZE]; /// read-buffer
- mpc_uint32_t Zaehler; /// actual index within read-buffer
-
- mpc_uint32_t samples_to_skip;
-
- mpc_uint32_t FwdJumpInfo;
- mpc_uint32_t ActDecodePos;
- mpc_uint32_t FrameWasValid;
-
- mpc_uint32_t DecodedFrames;
- mpc_uint32_t OverallFrames;
- mpc_int32_t SampleRate; // Sample frequency
-
- mpc_uint32_t StreamVersion; // version of bitstream
- mpc_uint32_t MS_used; // MS-coding used ?
- mpc_int32_t Max_Band;
- mpc_uint32_t MPCHeaderPos; // AB: needed to support ID3v2
- mpc_uint32_t LastValidSamples;
- mpc_uint32_t TrueGaplessPresent;
-
- mpc_uint32_t EQ_activated;
-
- mpc_uint32_t WordsRead; // counts amount of decoded dwords
-
- // randomizer state variables
- mpc_uint32_t __r1;
- mpc_uint32_t __r2;
-
- mpc_uint32_t Q_bit [32];
- mpc_uint32_t Q_res [32][16];
-
- // huffman table stuff
- HuffmanTyp HuffHdr [10];
- HuffmanTyp HuffSCFI [ 4];
- HuffmanTyp HuffDSCF [16];
- HuffmanTyp* HuffQ [2] [8];
-
- HuffmanTyp HuffQ1 [2] [3*3*3];
- HuffmanTyp HuffQ2 [2] [5*5];
- HuffmanTyp HuffQ3 [2] [ 7];
- HuffmanTyp HuffQ4 [2] [ 9];
- HuffmanTyp HuffQ5 [2] [15];
- HuffmanTyp HuffQ6 [2] [31];
- HuffmanTyp HuffQ7 [2] [63];
- const HuffmanTyp* SampleHuff [18];
- HuffmanTyp SCFI_Bundle [ 8];
- HuffmanTyp DSCF_Entropie [13];
- HuffmanTyp Region_A [16];
- HuffmanTyp Region_B [ 8];
- HuffmanTyp Region_C [ 4];
-
- HuffmanTyp Entropie_1 [ 3];
- HuffmanTyp Entropie_2 [ 5];
- HuffmanTyp Entropie_3 [ 7];
- HuffmanTyp Entropie_4 [ 9];
- HuffmanTyp Entropie_5 [15];
- HuffmanTyp Entropie_6 [31];
- HuffmanTyp Entropie_7 [63];
-
- mpc_int32_t SCF_Index_L [32] [3];
- mpc_int32_t SCF_Index_R [32] [3]; // holds scalefactor-indices
- QuantTyp Q [32]; // holds quantized samples
- mpc_int32_t Res_L [32];
- mpc_int32_t Res_R [32]; // holds the chosen quantizer for each subband
- mpc_int32_t DSCF_Flag_L [32];
- mpc_int32_t DSCF_Flag_R [32]; // differential SCF used?
- mpc_int32_t SCFI_L [32];
- mpc_int32_t SCFI_R [32]; // describes order of transmitted SCF
- mpc_int32_t DSCF_Reference_L [32];
- mpc_int32_t DSCF_Reference_R [32]; // holds last frames SCF
- mpc_int32_t MS_Flag[32]; // MS used?
-#ifdef MPC_FIXED_POINT
- unsigned char SCF_shift[256];
-#endif
-
- MPC_SAMPLE_FORMAT V_L[MPC_V_MEM + 960];
- MPC_SAMPLE_FORMAT V_R[MPC_V_MEM + 960];
- MPC_SAMPLE_FORMAT Y_L[36][32];
- MPC_SAMPLE_FORMAT Y_R[36][32];
- MPC_SAMPLE_FORMAT SCF[256]; ///< holds adapted scalefactors (for clipping prevention)
- //@}
-
-} mpc_decoder;
-
-#endif // _mpc_decoder_h
diff --git a/src/libmusepack/musepack/huffman.h b/src/libmusepack/musepack/huffman.h
deleted file mode 100644
index 7f587771f..000000000
--- a/src/libmusepack/musepack/huffman.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/// \file huffman.h
-/// Data structures and functions for huffman coding.
-
-#ifndef _musepack_huffman_h_
-#define _musepack_huffman_h_
-
-#include "musepack/config_types.h"
-#include "musepack/decoder.h"
-
-struct mpc_decoder_t; // forward declare to break circular dependencies
-
-/// Huffman table entry.
-typedef struct huffman_type_t {
- mpc_uint32_t Code;
- mpc_uint32_t Length;
- mpc_int32_t Value;
-} HuffmanTyp;
-
-//! \brief Sorts huffman-tables by codeword.
-//!
-//! offset resulting value.
-//! \param elements
-//! \param Table table to sort
-//! \param offset offset of resulting sort
-void
-mpc_decoder_resort_huff_tables(
- const mpc_uint32_t elements, HuffmanTyp *Table, const mpc_int32_t offset);
-
-/// Initializes sv6 huffman decoding structures.
-void mpc_decoder_init_huffman_sv6(struct mpc_decoder_t *d);
-
-/// Initializes sv6 huffman decoding tables.
-void mpc_decoder_init_huffman_sv6_tables(struct mpc_decoder_t *d);
-
-/// Initializes sv7 huffman decoding structures.
-void mpc_decoder_init_huffman_sv7(struct mpc_decoder_t *d);
-
-/// Initializes sv7 huffman decoding tables.
-void mpc_decoder_init_huffman_sv7_tables(struct mpc_decoder_t *d);
-
-#endif // _musepack_huffman_h_
diff --git a/src/libmusepack/musepack/internal.h b/src/libmusepack/musepack/internal.h
deleted file mode 100644
index f86b45bb3..000000000
--- a/src/libmusepack/musepack/internal.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/// \file musepack_internal.h
-/// Definitions and structures used only internally by the libmusepack.
-
-#ifndef _musepack_internal_h
-#define _musepack_internal_h
-
-enum {
- MPC_DECODER_SYNTH_DELAY = 481
-};
-
-#ifndef swap32
-/// Big/little endian 32 bit byte swapping routine.
-static inline
-mpc_uint32_t swap32(mpc_uint32_t val) {
- const unsigned char* src = (const unsigned char*)&val;
- return
- (mpc_uint32_t)src[0] |
- ((mpc_uint32_t)src[1] << 8) | ((mpc_uint32_t)src[2] << 16) | ((mpc_uint32_t)src[3] << 24);
-}
-#endif
-
-/// Searches for a ID3v2-tag and reads the length (in bytes) of it.
-/// \param reader supplying raw stream data
-/// \return size of tag, in bytes
-/// \return -1 on errors of any kind
-mpc_int32_t JumpID3v2(mpc_reader* fp);
-
-/// helper functions used by multiple files
-mpc_uint32_t random_int(mpc_decoder *d); // in synth_filter.c
-void mpc_decoder_initialisiere_quantisierungstabellen(mpc_decoder *d, double scale_factor);
-void mpc_decoder_synthese_filter_float(mpc_decoder *d, MPC_SAMPLE_FORMAT* OutData);
-
-#endif // _musepack_internal_h
-
diff --git a/src/libmusepack/musepack/math.h b/src/libmusepack/musepack/math.h
deleted file mode 100644
index f3d52c504..000000000
--- a/src/libmusepack/musepack/math.h
+++ /dev/null
@@ -1,110 +0,0 @@
-/// \file mpc_math.h
-/// Libmusepack internal math routines.
-
-#ifndef _musepack_math_h_
-#define _musepack_math_h_
-
-//#define MPC_FIXED_POINT
-
-#define MPC_FIXED_POINT_SHIFT 16
-
-#ifdef MPC_FIXED_POINT
-
-
-#ifdef _WIN32_WCE
-
-#include <cmnintrin.h>
-
-#define MPC_HAVE_MULHIGH
-
-#endif
-
-
-#define MPC_FIXED_POINT_SCALE_SHIFT (MPC_FIXED_POINT_SHIFT + MPC_FIXED_POINT_FRACTPART)
-#define MPC_FIXED_POINT_SCALE (1 << (MPC_FIXED_POINT_SCALE_SHIFT - 1))
-
-
-//in fixedpoint mode, results in decode output buffer are in -MPC_FIXED_POINT_SCALE ... MPC_FIXED_POINT_SCALE range
-
-#define MPC_FIXED_POINT_FRACTPART 14
-typedef mpc_int32_t MPC_SAMPLE_FORMAT;
-
-typedef mpc_int64_t MPC_SAMPLE_FORMAT_MULTIPLY;
-
-#define MAKE_MPC_SAMPLE(X) (MPC_SAMPLE_FORMAT)((double)(X) * (double)(((mpc_int64_t)1)<<MPC_FIXED_POINT_FRACTPART))
-#define MAKE_MPC_SAMPLE_EX(X,Y) (MPC_SAMPLE_FORMAT)((double)(X) * (double)(((mpc_int64_t)1)<<(Y)))
-
-#define MPC_MULTIPLY_NOTRUNCATE(X,Y) \
- (((MPC_SAMPLE_FORMAT_MULTIPLY)(X) * (MPC_SAMPLE_FORMAT_MULTIPLY)(Y)) >> MPC_FIXED_POINT_FRACTPART)
-
-#define MPC_MULTIPLY_EX_NOTRUNCATE(X,Y,Z) \
- (((MPC_SAMPLE_FORMAT_MULTIPLY)(X) * (MPC_SAMPLE_FORMAT_MULTIPLY)(Y)) >> (Z))
-
-#ifdef _DEBUG
-static inline MPC_SAMPLE_FORMAT MPC_MULTIPLY(MPC_SAMPLE_FORMAT item1,MPC_SAMPLE_FORMAT item2)
-{
- MPC_SAMPLE_FORMAT_MULTIPLY temp = MPC_MULTIPLY_NOTRUNCATE(item1,item2);
- assert(temp == (MPC_SAMPLE_FORMAT_MULTIPLY)(MPC_SAMPLE_FORMAT)temp);
- return (MPC_SAMPLE_FORMAT)temp;
-}
-
-static inline MPC_SAMPLE_FORMAT MPC_MULTIPLY_EX(MPC_SAMPLE_FORMAT item1,MPC_SAMPLE_FORMAT item2,unsigned shift)
-{
- MPC_SAMPLE_FORMAT_MULTIPLY temp = MPC_MULTIPLY_EX_NOTRUNCATE(item1,item2,shift);
- assert(temp == (MPC_SAMPLE_FORMAT_MULTIPLY)(MPC_SAMPLE_FORMAT)temp);
- return (MPC_SAMPLE_FORMAT)temp;
-}
-
-#else
-
-#define MPC_MULTIPLY(X,Y) ((MPC_SAMPLE_FORMAT)MPC_MULTIPLY_NOTRUNCATE(X,Y))
-#define MPC_MULTIPLY_EX(X,Y,Z) ((MPC_SAMPLE_FORMAT)MPC_MULTIPLY_EX_NOTRUNCATE(X,Y,Z))
-
-#endif
-
-#ifdef MPC_HAVE_MULHIGH
-#define MPC_MULTIPLY_FRACT(X,Y) _MulHigh(X,Y)
-#else
-#define MPC_MULTIPLY_FRACT(X,Y) MPC_MULTIPLY_EX(X,Y,32)
-#endif
-
-#define MPC_MAKE_FRACT_CONST(X) (MPC_SAMPLE_FORMAT)((X) * (double)(((mpc_int64_t)1)<<32) )
-#define MPC_MULTIPLY_FRACT_CONST(X,Y) MPC_MULTIPLY_FRACT(X,MPC_MAKE_FRACT_CONST(Y))
-#define MPC_MULTIPLY_FRACT_CONST_FIX(X,Y,Z) ( MPC_MULTIPLY_FRACT(X,MPC_MAKE_FRACT_CONST( Y / (1<<(Z)) )) << (Z) )
-#define MPC_MULTIPLY_FRACT_CONST_SHR(X,Y,Z) MPC_MULTIPLY_FRACT(X,MPC_MAKE_FRACT_CONST( Y / (1<<(Z)) ))
-
-#define MPC_MULTIPLY_FLOAT_INT(X,Y) ((X)*(Y))
-#define MPC_SCALE_CONST(X,Y,Z) MPC_MULTIPLY_EX(X,MAKE_MPC_SAMPLE_EX(Y,Z),(Z))
-#define MPC_SCALE_CONST_SHL(X,Y,Z,S) MPC_MULTIPLY_EX(X,MAKE_MPC_SAMPLE_EX(Y,Z),(Z)-(S))
-#define MPC_SCALE_CONST_SHR(X,Y,Z,S) MPC_MULTIPLY_EX(X,MAKE_MPC_SAMPLE_EX(Y,Z),(Z)+(S))
-#define MPC_SHR(X,Y) ((X)>>(Y))
-#define MPC_SHL(X,Y) ((X)<<(Y))
-
-#else
-
-//in floating-point mode, decoded samples are in -1...1 range
-
-typedef float MPC_SAMPLE_FORMAT;
-
-#define MAKE_MPC_SAMPLE(X) ((MPC_SAMPLE_FORMAT)(X))
-#define MAKE_MPC_SAMPLE_EX(X,Y) ((MPC_SAMPLE_FORMAT)(X))
-
-#define MPC_MULTIPLY_FRACT(X,Y) ((X)*(Y))
-#define MPC_MAKE_FRACT_CONST(X) (X)
-#define MPC_MULTIPLY_FRACT_CONST(X,Y) MPC_MULTPLY_FRACT(X,MPC_MAKE_FRACT_CONST(Y))
-#define MPC_MULTIPLY_FRACT_CONST_SHR(X,Y,Z) MPC_MULTIPLY_FRACT(X,MPC_MAKE_FRACT_CONST( Y ))
-#define MPC_MULTIPLY_FRACT_CONST_FIX(X,Y,Z) MPC_MULTIPLY_FRACT(X,MPC_MAKE_FRACT_CONST( Y ))
-
-#define MPC_MULTIPLY_FLOAT_INT(X,Y) ((X)*(Y))
-#define MPC_MULTIPLY(X,Y) ((X)*(Y))
-#define MPC_MULTIPLY_EX(X,Y,Z) ((X)*(Y))
-#define MPC_SCALE_CONST(X,Y,Z) ((X)*(Y))
-#define MPC_SCALE_CONST_SHL(X,Y,Z,S) ((X)*(Y))
-#define MPC_SCALE_CONST_SHR(X,Y,Z,S) ((X)*(Y))
-#define MPC_SHR(X,Y) (X)
-#define MPC_SHL(X,Y) (X)
-
-#endif
-
-#endif // _musepack_math_h_
-
diff --git a/src/libmusepack/musepack/musepack.h b/src/libmusepack/musepack/musepack.h
deleted file mode 100644
index dfbf0a36d..000000000
--- a/src/libmusepack/musepack/musepack.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/// \file musepack.h
-/// Top level include file for libmusepack.
-
-#ifndef _musepack_h_
-#define _musepack_h_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
-#include "musepack/config_types.h"
-#include "musepack/decoder.h"
-#include "musepack/math.h"
-#include "musepack/reader.h"
-#include "musepack/streaminfo.h"
-
-enum {
- MPC_FRAME_LENGTH = (36 * 32), /// samples per mpc frame
- MPC_DECODER_BUFFER_LENGTH = 4 * MPC_FRAME_LENGTH /// required buffer size for decoder
-};
-
-// error codes
-#define ERROR_CODE_OK 0
-#define ERROR_CODE_FILE -1
-#define ERROR_CODE_SV7BETA 1
-#define ERROR_CODE_CBR 2
-#define ERROR_CODE_IS 3
-#define ERROR_CODE_BLOCKSIZE 4
-#define ERROR_CODE_INVALIDSV 5
-
-/// Initializes a streaminfo structure.
-/// \param si streaminfo structure to initialize
-void mpc_streaminfo_init(mpc_streaminfo *si);
-
-/// Reads streaminfo header from the mpc stream supplied by r.
-/// \param si streaminfo pointer to which info will be written
-/// \param r stream reader to supply raw data
-/// \return error code
-mpc_int32_t mpc_streaminfo_read(mpc_streaminfo *si, mpc_reader *r);
-
-/// Gets length of stream si, in seconds.
-/// \return length of stream in seconds
-double mpc_streaminfo_get_length(mpc_streaminfo *si);
-
-/// Returns length of stream si, in samples.
-/// \return length of stream in samples
-mpc_int64_t mpc_streaminfo_get_length_samples(mpc_streaminfo *si);
-
-/// Sets up decoder library.
-/// Call this first when preparing to decode an mpc stream.
-/// \param r reader that will supply raw data to the decoder
-void mpc_decoder_setup(mpc_decoder *d, mpc_reader *r);
-
-/// Initializes mpc decoder with the supplied stream info parameters.
-/// Call this next after calling mpc_decoder_setup.
-/// \param si streaminfo structure indicating format of source stream
-/// \return TRUE if decoder was initalized successfully, FALSE otherwise
-mpc_bool_t mpc_decoder_initialize(mpc_decoder *d, mpc_streaminfo *si);
-
-/// Sets decoder sample scaling factor. All decoded samples will be multiplied
-/// by this factor.
-/// \param scale_factor multiplicative scaling factor
-void mpc_decoder_scale_output(mpc_decoder *d, double scale_factor);
-
-/// Actually reads data from previously initialized stream. Call
-/// this iteratively to decode the mpc stream.
-/// \param buffer destination buffer for decoded samples
-/// \param vbr_update_acc \todo document me
-/// \param vbr_update_bits \todo document me
-/// \return -1 if an error is encountered
-/// \return 0 if the stream has been completely decoded successfully and there are no more samples
-/// \return > 0 to indicate the number of bytes that were actually read from the stream.
-mpc_uint32_t mpc_decoder_decode(
- mpc_decoder *d,
- MPC_SAMPLE_FORMAT *buffer,
- mpc_uint32_t *vbr_update_acc,
- mpc_uint32_t *vbr_update_bits);
-
-/// Seeks to the specified sample in the source stream.
-mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample);
-
-/// Seeks to specified position in seconds in the source stream.
-mpc_bool_t mpc_decoder_seek_seconds(mpc_decoder *d, double seconds);
-
-#ifdef __cplusplus
-}
-#endif // __cplusplus
-
-#endif // _musepack_h_
diff --git a/src/libmusepack/musepack/reader.h b/src/libmusepack/musepack/reader.h
deleted file mode 100644
index 2f29f97e4..000000000
--- a/src/libmusepack/musepack/reader.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/// \file reader.h
-
-#ifndef _musepack_reader_h_
-#define _musepack_reader_h_
-
-/// \brief Stream reader interface structure.
-///
-/// This is the structure you must supply to the musepack decoding library
-/// to feed it with raw data. Implement the five member functions to provide
-/// a functional reader.
-typedef struct mpc_reader_t {
- /// Reads size bytes of data into buffer at ptr.
- mpc_int32_t (*read)(void *t, void *ptr, mpc_int32_t size);
-
- /// Seeks to byte position offset.
- mpc_bool_t (*seek)(void *t, mpc_int32_t offset);
-
- /// Returns the current byte offset in the stream.
- mpc_int32_t (*tell)(void *t);
-
- /// Returns the total length of the source stream, in bytes.
- mpc_int32_t (*get_size)(void *t);
-
- /// True if the stream is a seekable stream.
- mpc_bool_t (*canseek)(void *t);
-
- /// Optional field that can be used to identify a particular instance of
- /// reader or carry along data associated with that reader.
- void *data;
-
- // These are used by provided internal standard file-based reader implementation.
- // You shouldn't touch them. They're included in the main struct to avoid
- // malloc/free.
- FILE *file;
- long file_size;
- mpc_bool_t is_seekable;
-} mpc_reader;
-
-/// Initializes reader with default stdio file reader implementation. Use
-/// this if you're just reading from a plain file.
-///
-/// \param r reader struct to initalize
-/// \param input input stream to attach to the reader
-void mpc_reader_setup_file_reader(mpc_reader *r, FILE *input);
-
-#endif // _musepack_reader_h_
diff --git a/src/libmusepack/musepack/requant.h b/src/libmusepack/musepack/requant.h
deleted file mode 100644
index dc9a5c32f..000000000
--- a/src/libmusepack/musepack/requant.h
+++ /dev/null
@@ -1,17 +0,0 @@
-/// \file requant.h
-/// Requantization function definitions.
-
-#ifndef _musepack_requant_h
-#define _musepack_requant_h_
-
-#include "musepack/musepack.h"
-
-/* C O N S T A N T S */
-extern const mpc_uint32_t Res_bit [18]; // bits per sample for chosen quantizer
-extern const MPC_SAMPLE_FORMAT __Cc [1 + 18]; // coefficients for requantization
-extern const mpc_int32_t __Dc [1 + 18]; // offset for requantization
-
-#define Cc (__Cc + 1)
-#define Dc (__Dc + 1)
-
-#endif // _musepack_requant_h_
diff --git a/src/libmusepack/musepack/streaminfo.h b/src/libmusepack/musepack/streaminfo.h
deleted file mode 100644
index dc8e77c22..000000000
--- a/src/libmusepack/musepack/streaminfo.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/// \file streaminfo.h
-
-#ifndef _musepack_streaminfo_h_
-#define _musepack_streaminfo_h_
-
-typedef mpc_int32_t mpc_streaminfo_off_t;
-
-/// \brief mpc stream properties structure
-///
-/// Structure containing all the properties of an mpc stream. Populated
-/// by the streaminfo_read function.
-typedef struct mpc_streaminfo {
- /// @name core mpc stream properties
- //@{
- mpc_uint32_t sample_freq; ///< sample frequency of stream
- mpc_uint32_t channels; ///< number of channels in stream
- mpc_streaminfo_off_t header_position; ///< byte offset of position of header in stream
- mpc_uint32_t stream_version; ///< streamversion of stream
- mpc_uint32_t bitrate; ///< bitrate of stream file (in bps)
- double average_bitrate; ///< average bitrate of stream (in bits/sec)
- mpc_uint32_t frames; ///< number of frames in stream
- mpc_int64_t pcm_samples;
- mpc_uint32_t max_band; ///< maximum band-index used in stream (0...31)
- mpc_uint32_t is; ///< intensity stereo (0: off, 1: on)
- mpc_uint32_t ms; ///< mid/side stereo (0: off, 1: on)
- mpc_uint32_t block_size; ///< only needed for SV4...SV6 -> not supported
- mpc_uint32_t profile; ///< quality profile of stream
- const char* profile_name; ///< name of profile used by stream
- //@}
-
- /// @name replaygain related fields
- //@{
- mpc_int16_t gain_title; ///< replaygain title value
- mpc_int16_t gain_album; ///< replaygain album value
- mpc_uint16_t peak_album; ///< peak album loudness level
- mpc_uint16_t peak_title; ///< peak title loudness level
- //@}
-
- /// @name true gapless support data
- //@{
- mpc_uint32_t is_true_gapless; ///< true gapless? (0: no, 1: yes)
- mpc_uint32_t last_frame_samples; ///< number of valid samples within last frame
-
- mpc_uint32_t encoder_version; ///< version of encoder used
- char encoder[256]; ///< encoder name
-
- mpc_streaminfo_off_t tag_offset; ///< offset to file tags
- mpc_streaminfo_off_t total_file_length; ///< total length of underlying file
- //@}
-} mpc_streaminfo;
-
-#endif // _musepack_streaminfo_h_
diff --git a/src/libmusepack/requant.c b/src/libmusepack/requant.c
deleted file mode 100644
index d318d0bd0..000000000
--- a/src/libmusepack/requant.c
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- Copyright (c) 2004, The Musepack Development Team
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
- * Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials provided
- with the distribution.
-
- * Neither the name of the The Musepack Development Team nor the
- names of its contributors may be used to endorse or promote
- products derived from this software without specific prior
- written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-/// \file requant.c
-/// Requantization function implementations.
-/// \todo document me
-
-#include "musepack/musepack.h"
-#include "musepack/internal.h"
-
-/* C O N S T A N T S */
-// bits per sample for chosen quantizer
-const mpc_uint32_t Res_bit [18] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
-};
-
-// coefficients for requantization
-// 65536/step bzw. 65536/(2*D+1)
-
-#define _(X) MAKE_MPC_SAMPLE_EX(X,14)
-
-const MPC_SAMPLE_FORMAT __Cc [1 + 18] = {
- _(111.285962475327f), // 32768/2/255*sqrt(3)
- _(65536.000000000000f), _(21845.333333333332f), _(13107.200000000001f), _(9362.285714285713f),
- _(7281.777777777777f), _(4369.066666666666f), _(2114.064516129032f), _(1040.253968253968f),
- _(516.031496062992f), _(257.003921568627f), _(128.250489236790f), _(64.062561094819f),
- _(32.015632633121f), _(16.003907203907f), _(8.000976681723f), _(4.000244155527f),
- _(2.000061037018f), _(1.000015259021f)
-};
-
-#undef _
-
-// offset for requantization
-// 2*D+1 = steps of quantizer
-const mpc_int32_t __Dc [1 + 18] = {
- 2,
- 0, 1, 2, 3, 4, 7, 15, 31, 63,
- 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767
-};
-
-#ifdef MPC_FIXED_POINT
-static mpc_uint32_t find_shift(double fval)
-{
- mpc_int64_t val = (mpc_int64_t)fval;
- if (val<0) val = -val;
- mpc_uint32_t ptr = 0;
- while(val) {val>>=1;ptr++;}
-
- return ptr > 31 ? 0 : 31 - ptr;
-}
-#endif
-
-/* F U N C T I O N S */
-
-#define SET_SCF(N,X) d->SCF[N] = MAKE_MPC_SAMPLE_EX(X,SCF_shift[N] = (unsigned char)find_shift(X));
-
-void
-mpc_decoder_scale_output(mpc_decoder *d, double factor)
-{
- mpc_int32_t n;
- double f1;
- double f2;
-#ifndef MPC_FIXED_POINT
- factor *= 1.0 / (double)(1<<(MPC_FIXED_POINT_SHIFT-1));
-#else
- factor *= 1.0 / (double)(1<<(16 - MPC_FIXED_POINT_SHIFT));
-#endif
- f1 = f2 = factor;
-
- // handles +1.58...-98.41 dB, where's scf[n] / scf[n-1] = 1.20050805774840750476
-
- SET_SCF(1,factor);
-
- f1 *= 0.83298066476582673961;
- f2 *= 1/0.83298066476582673961;
-
- for ( n = 1; n <= 128; n++ ) {
- SET_SCF((unsigned char)(1+n),f1);
- SET_SCF((unsigned char)(1-n),f2);
- f1 *= 0.83298066476582673961;
- f2 *= 1/0.83298066476582673961;
- }
-}
-
-static void
-mpc_decoder_quantisierungsmodes(mpc_decoder *d) // conversion: index -> quantizer (bitstream reading)
-{ // conversion: quantizer -> index (bitstream writing)
- mpc_int32_t Band = 0;
- mpc_int32_t i;
-
- do {
- d->Q_bit [Band] = 4;
- for ( i = 0; i < 16-1; i++ )
- d->Q_res [Band] [i] = i;
- d->Q_res [Band][i] = 17;
- Band++;
- } while ( Band < 11 );
-
- do {
- d->Q_bit [Band] = 3;
- for ( i = 0; i < 8-1; i++ )
- d->Q_res [Band] [i] = i;
- d->Q_res [Band] [i] = 17;
- Band++;
- } while ( Band < 23 );
-
- do {
- d->Q_bit [Band] = 2;
- for ( i = 0; i < 4-1; i++ )
- d->Q_res [Band] [i] = i;
- d->Q_res [Band] [i] = 17;
- Band++;
- } while ( Band < 32 );
-}
-
-void
-mpc_decoder_initialisiere_quantisierungstabellen(mpc_decoder *d, double scale_factor)
-{
- mpc_decoder_quantisierungsmodes(d);
- mpc_decoder_scale_output(d, scale_factor);
-}
diff --git a/src/libmusepack/streaminfo.c b/src/libmusepack/streaminfo.c
deleted file mode 100644
index 2c6ff1c6f..000000000
--- a/src/libmusepack/streaminfo.c
+++ /dev/null
@@ -1,280 +0,0 @@
-/*
- Copyright (c) 2004, The Musepack Development Team
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
- * Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials provided
- with the distribution.
-
- * Neither the name of the The Musepack Development Team nor the
- names of its contributors may be used to endorse or promote
- products derived from this software without specific prior
- written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-/// \file streaminfo.c
-/// Implementation of streaminfo reading functions.
-
-#include "musepack/musepack.h"
-#include "musepack/internal.h"
-
-static const char *
-Stringify(mpc_uint32_t profile) // profile is 0...15, where 7...13 is used
-{
- static const char na[] = "n.a.";
- static const char *Names[] = {
- na, "'Unstable/Experimental'", na, na,
- na, "'quality 0'", "'quality 1'", "'Telephone'",
- "'Thumb'", "'Radio'", "'Standard'", "'Xtreme'",
- "'Insane'", "'BrainDead'", "'quality 9'", "'quality 10'"
- };
-
- return profile >= sizeof(Names) / sizeof(*Names) ? na : Names[profile];
-}
-
-void
-mpc_streaminfo_init(mpc_streaminfo * si)
-{
- memset(si, 0, sizeof(mpc_streaminfo));
-}
-
-// read information from SV8 header
-// not yet implemented
-static mpc_int32_t
-streaminfo_read_header_sv8(mpc_streaminfo * si, mpc_reader * fp)
-{
- return 0;
-}
-
-/// Reads streaminfo from SV7 header.
-static mpc_int32_t
-streaminfo_read_header_sv7(mpc_streaminfo * si, mpc_uint32_t HeaderData[8])
-{
- const mpc_int32_t samplefreqs[4] = { 44100, 48000, 37800, 32000 };
-
- //mpc_uint32_t HeaderData [8];
- mpc_uint16_t Estimatedpeak_title = 0;
-
- if (si->stream_version > 0x71) {
- // Update (si->stream_version);
- return 0;
- }
-
- /*
- if ( !fp->seek ( si->header_position ) ) // seek to header start
- return ERROR_CODE_FILE;
- if ( fp->read ( HeaderData, sizeof HeaderData) != sizeof HeaderData )
- return ERROR_CODE_FILE;
- */
-
- si->bitrate = 0;
- si->frames = HeaderData[1];
- si->is = 0;
- si->ms = (HeaderData[2] >> 30) & 0x0001;
- si->max_band = (HeaderData[2] >> 24) & 0x003F;
- si->block_size = 1;
- si->profile = (HeaderData[2] << 8) >> 28;
- si->profile_name = Stringify(si->profile);
- si->sample_freq = samplefreqs[(HeaderData[2] >> 16) & 0x0003];
- Estimatedpeak_title = (mpc_uint16_t) (HeaderData[2] & 0xFFFF); // read the ReplayGain data
- si->gain_title = (mpc_uint16_t) ((HeaderData[3] >> 16) & 0xFFFF);
- si->peak_title = (mpc_uint16_t) (HeaderData[3] & 0xFFFF);
- si->gain_album = (mpc_uint16_t) ((HeaderData[4] >> 16) & 0xFFFF);
- si->peak_album = (mpc_uint16_t) (HeaderData[4] & 0xFFFF);
- si->is_true_gapless = (HeaderData[5] >> 31) & 0x0001; // true gapless: used?
- si->last_frame_samples = (HeaderData[5] >> 20) & 0x07FF; // true gapless: valid samples for last frame
- si->encoder_version = (HeaderData[6] >> 24) & 0x00FF;
-
- if (si->encoder_version == 0) {
- sprintf(si->encoder, "Buschmann 1.7.0...9, Klemm 0.90...1.05");
- }
- else {
- switch (si->encoder_version % 10) {
- case 0:
- sprintf(si->encoder, "Release %u.%u", si->encoder_version / 100,
- si->encoder_version / 10 % 10);
- break;
- case 2:
- case 4:
- case 6:
- case 8:
- sprintf(si->encoder, "Beta %u.%02u", si->encoder_version / 100,
- si->encoder_version % 100);
- break;
- default:
- sprintf(si->encoder, "--Alpha-- %u.%02u",
- si->encoder_version / 100, si->encoder_version % 100);
- break;
- }
- }
-
- // if ( si->peak_title == 0 ) // there is no correct peak_title contained within header
- // si->peak_title = (mpc_uint16_t)(Estimatedpeak_title * 1.18);
- // if ( si->peak_album == 0 )
- // si->peak_album = si->peak_title; // no correct peak_album, use peak_title
-
- //si->sample_freq = 44100; // AB: used by all files up to SV7
- si->channels = 2;
-
- return ERROR_CODE_OK;
-}
-
-// read information from SV4-SV6 header
-static mpc_int32_t
-streaminfo_read_header_sv6(mpc_streaminfo * si, mpc_uint32_t HeaderData[8])
-{
- //mpc_uint32_t HeaderData [8];
-
- /*
- if ( !fp->seek ( si->header_position ) ) // seek to header start
- return ERROR_CODE_FILE;
- if ( fp->read ( HeaderData, sizeof HeaderData ) != sizeof HeaderData )
- return ERROR_CODE_FILE;
- */
-
- si->bitrate = (HeaderData[0] >> 23) & 0x01FF; // read the file-header (SV6 and below)
- si->is = (HeaderData[0] >> 22) & 0x0001;
- si->ms = (HeaderData[0] >> 21) & 0x0001;
- si->stream_version = (HeaderData[0] >> 11) & 0x03FF;
- si->max_band = (HeaderData[0] >> 6) & 0x001F;
- si->block_size = (HeaderData[0]) & 0x003F;
- si->profile = 0;
- si->profile_name = Stringify((mpc_uint32_t) (-1));
- if (si->stream_version >= 5)
- si->frames = HeaderData[1]; // 32 bit
- else
- si->frames = (HeaderData[1] >> 16); // 16 bit
-
- si->gain_title = 0; // not supported
- si->peak_title = 0;
- si->gain_album = 0;
- si->peak_album = 0;
-
- si->last_frame_samples = 0;
- si->is_true_gapless = 0;
-
- si->encoder_version = 0;
- si->encoder[0] = '\0';
-
- if (si->stream_version == 7)
- return ERROR_CODE_SV7BETA; // are there any unsupported parameters used?
- if (si->bitrate != 0)
- return ERROR_CODE_CBR;
- if (si->is != 0)
- return ERROR_CODE_IS;
- if (si->block_size != 1)
- return ERROR_CODE_BLOCKSIZE;
-
- if (si->stream_version < 6) // Bugfix: last frame was invalid for up to SV5
- si->frames -= 1;
-
- si->sample_freq = 44100; // AB: used by all files up to SV7
- si->channels = 2;
-
- if (si->stream_version < 4 || si->stream_version > 7)
- return ERROR_CODE_INVALIDSV;
-
- return ERROR_CODE_OK;
-}
-
-// reads file header and tags
-mpc_int32_t
-mpc_streaminfo_read(mpc_streaminfo * si, mpc_reader * r)
-{
- mpc_uint32_t HeaderData[8];
- mpc_int32_t Error = 0;
-
- // get header position
- if ((si->header_position = JumpID3v2(r)) < 0) {
- return ERROR_CODE_FILE;
- }
- // seek to first byte of mpc data
- if (!r->seek(r->data, si->header_position)) {
- return ERROR_CODE_FILE;
- }
- if (r->read(r->data, HeaderData, 8 * 4) != 8 * 4) {
- return ERROR_CODE_FILE;
- }
- if (!r->seek(r->data, si->header_position + 6 * 4)) {
- return ERROR_CODE_FILE;
- }
-
- si->total_file_length = r->get_size(r->data);
- si->tag_offset = si->total_file_length;
- if (memcmp(HeaderData, "MP+", 3) == 0) {
-#ifndef MPC_LITTLE_ENDIAN
- mpc_uint32_t ptr;
- for (ptr = 0; ptr < 8; ptr++) {
- HeaderData[ptr] = swap32(HeaderData[ptr]);
- }
-#endif
- si->stream_version = HeaderData[0] >> 24;
-
- // stream version 8
- if ((si->stream_version & 15) >= 8) {
- Error = streaminfo_read_header_sv8(si, r);
- }
- // stream version 7
- else if ((si->stream_version & 15) == 7) {
- Error = streaminfo_read_header_sv7(si, HeaderData);
- }
- }
- else {
- // stream version 4-6
- Error = streaminfo_read_header_sv6(si, HeaderData);
- }
-
- // estimation, exact value needs too much time
- si->pcm_samples = 1152 * si->frames - 576;
-
- if (si->pcm_samples > 0) {
- si->average_bitrate =
- (si->tag_offset -
- si->header_position) * 8.0 * si->sample_freq / si->pcm_samples;
- }
- else {
- si->average_bitrate = 0;
- }
-
- return Error;
-}
-
-double
-mpc_streaminfo_get_length(mpc_streaminfo * si)
-{
- return (double)mpc_streaminfo_get_length_samples(si) /
- (double)si->sample_freq;
-}
-
-mpc_int64_t
-mpc_streaminfo_get_length_samples(mpc_streaminfo * si)
-{
- mpc_int64_t samples = (mpc_int64_t) si->frames * MPC_FRAME_LENGTH;
- if (si->is_true_gapless) {
- samples -= (MPC_FRAME_LENGTH - si->last_frame_samples);
- }
- else {
- samples -= MPC_DECODER_SYNTH_DELAY;
- }
- return samples;
-}
diff --git a/src/libmusepack/synth_filter.c b/src/libmusepack/synth_filter.c
deleted file mode 100644
index dceb0a64d..000000000
--- a/src/libmusepack/synth_filter.c
+++ /dev/null
@@ -1,440 +0,0 @@
-/*
- Copyright (c) 2004, The Musepack Development Team
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
- * Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials provided
- with the distribution.
-
- * Neither the name of the The Musepack Development Team nor the
- names of its contributors may be used to endorse or promote
- products derived from this software without specific prior
- written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-/// \file synth_filter.c
-/// Synthesis functions.
-/// \todo document me
-
-#include "musepack/musepack.h"
-#include "musepack/internal.h"
-
-/* C O N S T A N T S */
-#undef _
-
-#define MPC_FIXED_POINT_SYNTH_FIX 2
-
-#ifdef MPC_FIXED_POINT
-#define _(value) MPC_MAKE_FRACT_CONST((double)value/(double)(0x40000))
-#else
-#define _(value) MAKE_MPC_SAMPLE((double)value/(double)(0x10000))
-#endif
-
-
-static const MPC_SAMPLE_FORMAT Di_opt [32] [16] = {
- { _( 0), _( -29), _( 213), _( -459), _( 2037), _(-5153), _( 6574), _(-37489), _(75038), _(37489), _(6574), _( 5153), _(2037), _( 459), _(213), _(29) },
- { _( -1), _( -31), _( 218), _( -519), _( 2000), _(-5517), _( 5959), _(-39336), _(74992), _(35640), _(7134), _( 4788), _(2063), _( 401), _(208), _(26) },
- { _( -1), _( -35), _( 222), _( -581), _( 1952), _(-5879), _( 5288), _(-41176), _(74856), _(33791), _(7640), _( 4425), _(2080), _( 347), _(202), _(24) },
- { _( -1), _( -38), _( 225), _( -645), _( 1893), _(-6237), _( 4561), _(-43006), _(74630), _(31947), _(8092), _( 4063), _(2087), _( 294), _(196), _(21) },
- { _( -1), _( -41), _( 227), _( -711), _( 1822), _(-6589), _( 3776), _(-44821), _(74313), _(30112), _(8492), _( 3705), _(2085), _( 244), _(190), _(19) },
- { _( -1), _( -45), _( 228), _( -779), _( 1739), _(-6935), _( 2935), _(-46617), _(73908), _(28289), _(8840), _( 3351), _(2075), _( 197), _(183), _(17) },
- { _( -1), _( -49), _( 228), _( -848), _( 1644), _(-7271), _( 2037), _(-48390), _(73415), _(26482), _(9139), _( 3004), _(2057), _( 153), _(176), _(16) },
- { _( -2), _( -53), _( 227), _( -919), _( 1535), _(-7597), _( 1082), _(-50137), _(72835), _(24694), _(9389), _( 2663), _(2032), _( 111), _(169), _(14) },
- { _( -2), _( -58), _( 224), _( -991), _( 1414), _(-7910), _( 70), _(-51853), _(72169), _(22929), _(9592), _( 2330), _(2001), _( 72), _(161), _(13) },
- { _( -2), _( -63), _( 221), _(-1064), _( 1280), _(-8209), _( -998), _(-53534), _(71420), _(21189), _(9750), _( 2006), _(1962), _( 36), _(154), _(11) },
- { _( -2), _( -68), _( 215), _(-1137), _( 1131), _(-8491), _( -2122), _(-55178), _(70590), _(19478), _(9863), _( 1692), _(1919), _( 2), _(147), _(10) },
- { _( -3), _( -73), _( 208), _(-1210), _( 970), _(-8755), _( -3300), _(-56778), _(69679), _(17799), _(9935), _( 1388), _(1870), _( -29), _(139), _( 9) },
- { _( -3), _( -79), _( 200), _(-1283), _( 794), _(-8998), _( -4533), _(-58333), _(68692), _(16155), _(9966), _( 1095), _(1817), _( -57), _(132), _( 8) },
- { _( -4), _( -85), _( 189), _(-1356), _( 605), _(-9219), _( -5818), _(-59838), _(67629), _(14548), _(9959), _( 814), _(1759), _( -83), _(125), _( 7) },
- { _( -4), _( -91), _( 177), _(-1428), _( 402), _(-9416), _( -7154), _(-61289), _(66494), _(12980), _(9916), _( 545), _(1698), _(-106), _(117), _( 7) },
- { _( -5), _( -97), _( 163), _(-1498), _( 185), _(-9585), _( -8540), _(-62684), _(65290), _(11455), _(9838), _( 288), _(1634), _(-127), _(111), _( 6) },
- { _( -5), _(-104), _( 146), _(-1567), _( -45), _(-9727), _( -9975), _(-64019), _(64019), _( 9975), _(9727), _( 45), _(1567), _(-146), _(104), _( 5) },
- { _( -6), _(-111), _( 127), _(-1634), _( -288), _(-9838), _(-11455), _(-65290), _(62684), _( 8540), _(9585), _( -185), _(1498), _(-163), _( 97), _( 5) },
- { _( -7), _(-117), _( 106), _(-1698), _( -545), _(-9916), _(-12980), _(-66494), _(61289), _( 7154), _(9416), _( -402), _(1428), _(-177), _( 91), _( 4) },
- { _( -7), _(-125), _( 83), _(-1759), _( -814), _(-9959), _(-14548), _(-67629), _(59838), _( 5818), _(9219), _( -605), _(1356), _(-189), _( 85), _( 4) },
- { _( -8), _(-132), _( 57), _(-1817), _(-1095), _(-9966), _(-16155), _(-68692), _(58333), _( 4533), _(8998), _( -794), _(1283), _(-200), _( 79), _( 3) },
- { _( -9), _(-139), _( 29), _(-1870), _(-1388), _(-9935), _(-17799), _(-69679), _(56778), _( 3300), _(8755), _( -970), _(1210), _(-208), _( 73), _( 3) },
- { _(-10), _(-147), _( -2), _(-1919), _(-1692), _(-9863), _(-19478), _(-70590), _(55178), _( 2122), _(8491), _(-1131), _(1137), _(-215), _( 68), _( 2) },
- { _(-11), _(-154), _( -36), _(-1962), _(-2006), _(-9750), _(-21189), _(-71420), _(53534), _( 998), _(8209), _(-1280), _(1064), _(-221), _( 63), _( 2) },
- { _(-13), _(-161), _( -72), _(-2001), _(-2330), _(-9592), _(-22929), _(-72169), _(51853), _( -70), _(7910), _(-1414), _( 991), _(-224), _( 58), _( 2) },
- { _(-14), _(-169), _(-111), _(-2032), _(-2663), _(-9389), _(-24694), _(-72835), _(50137), _(-1082), _(7597), _(-1535), _( 919), _(-227), _( 53), _( 2) },
- { _(-16), _(-176), _(-153), _(-2057), _(-3004), _(-9139), _(-26482), _(-73415), _(48390), _(-2037), _(7271), _(-1644), _( 848), _(-228), _( 49), _( 1) },
- { _(-17), _(-183), _(-197), _(-2075), _(-3351), _(-8840), _(-28289), _(-73908), _(46617), _(-2935), _(6935), _(-1739), _( 779), _(-228), _( 45), _( 1) },
- { _(-19), _(-190), _(-244), _(-2085), _(-3705), _(-8492), _(-30112), _(-74313), _(44821), _(-3776), _(6589), _(-1822), _( 711), _(-227), _( 41), _( 1) },
- { _(-21), _(-196), _(-294), _(-2087), _(-4063), _(-8092), _(-31947), _(-74630), _(43006), _(-4561), _(6237), _(-1893), _( 645), _(-225), _( 38), _( 1) },
- { _(-24), _(-202), _(-347), _(-2080), _(-4425), _(-7640), _(-33791), _(-74856), _(41176), _(-5288), _(5879), _(-1952), _( 581), _(-222), _( 35), _( 1) },
- { _(-26), _(-208), _(-401), _(-2063), _(-4788), _(-7134), _(-35640), _(-74992), _(39336), _(-5959), _(5517), _(-2000), _( 519), _(-218), _( 31), _( 1) }
-};
-
-#undef _
-
-static void Calculate_New_V ( const MPC_SAMPLE_FORMAT * Sample, MPC_SAMPLE_FORMAT * V )
-{
- // Calculating new V-buffer values for left channel
- // calculate new V-values (ISO-11172-3, p. 39)
- // based upon fast-MDCT algorithm by Byeong Gi Lee
- /*static*/ MPC_SAMPLE_FORMAT A00, A01, A02, A03, A04, A05, A06, A07, A08, A09, A10, A11, A12, A13, A14, A15;
- /*static*/ MPC_SAMPLE_FORMAT B00, B01, B02, B03, B04, B05, B06, B07, B08, B09, B10, B11, B12, B13, B14, B15;
- MPC_SAMPLE_FORMAT tmp;
-
- A00 = Sample[ 0] + Sample[31];
- A01 = Sample[ 1] + Sample[30];
- A02 = Sample[ 2] + Sample[29];
- A03 = Sample[ 3] + Sample[28];
- A04 = Sample[ 4] + Sample[27];
- A05 = Sample[ 5] + Sample[26];
- A06 = Sample[ 6] + Sample[25];
- A07 = Sample[ 7] + Sample[24];
- A08 = Sample[ 8] + Sample[23];
- A09 = Sample[ 9] + Sample[22];
- A10 = Sample[10] + Sample[21];
- A11 = Sample[11] + Sample[20];
- A12 = Sample[12] + Sample[19];
- A13 = Sample[13] + Sample[18];
- A14 = Sample[14] + Sample[17];
- A15 = Sample[15] + Sample[16];
-
- B00 = A00 + A15;
- B01 = A01 + A14;
- B02 = A02 + A13;
- B03 = A03 + A12;
- B04 = A04 + A11;
- B05 = A05 + A10;
- B06 = A06 + A09;
- B07 = A07 + A08;;
- B08 = MPC_SCALE_CONST((A00 - A15) , 0.5024192929f , 31);
- B09 = MPC_SCALE_CONST((A01 - A14) , 0.5224986076f , 31);
- B10 = MPC_SCALE_CONST((A02 - A13) , 0.5669440627f , 31);
- B11 = MPC_SCALE_CONST((A03 - A12) , 0.6468217969f , 31);
- B12 = MPC_SCALE_CONST((A04 - A11) , 0.7881546021f , 31);
- B13 = MPC_SCALE_CONST((A05 - A10) , 1.0606776476f , 30);
- B14 = MPC_SCALE_CONST((A06 - A09) , 1.7224471569f , 30);
- B15 = MPC_SCALE_CONST((A07 - A08) , 5.1011486053f , 28);
-
- A00 = B00 + B07;
- A01 = B01 + B06;
- A02 = B02 + B05;
- A03 = B03 + B04;
- A04 = MPC_SCALE_CONST((B00 - B07) , 0.5097956061f , 31);
- A05 = MPC_SCALE_CONST((B01 - B06) , 0.6013448834f , 31);
- A06 = MPC_SCALE_CONST((B02 - B05) , 0.8999761939f , 31);
- A07 = MPC_SCALE_CONST((B03 - B04) , 2.5629155636f , 29);
- A08 = B08 + B15;
- A09 = B09 + B14;
- A10 = B10 + B13;
- A11 = B11 + B12;
- A12 = MPC_SCALE_CONST((B08 - B15) , 0.5097956061f , 31);
- A13 = MPC_SCALE_CONST((B09 - B14) , 0.6013448834f , 31);
- A14 = MPC_SCALE_CONST((B10 - B13) , 0.8999761939f , 31);
- A15 = MPC_SCALE_CONST((B11 - B12) , 2.5629155636f , 29);
-
- B00 = A00 + A03;
- B01 = A01 + A02;
- B02 = MPC_MULTIPLY_FRACT_CONST_FIX((A00 - A03) , 0.5411961079f , 1);
- B03 = MPC_MULTIPLY_FRACT_CONST_FIX((A01 - A02) , 1.3065630198f , 2);
- B04 = A04 + A07;
- B05 = A05 + A06;
- B06 = MPC_MULTIPLY_FRACT_CONST_FIX((A04 - A07) , 0.5411961079f , 1);
- B07 = MPC_MULTIPLY_FRACT_CONST_FIX((A05 - A06) , 1.3065630198f , 2);
- B08 = A08 + A11;
- B09 = A09 + A10;
- B10 = MPC_MULTIPLY_FRACT_CONST_FIX((A08 - A11) , 0.5411961079f , 1);
- B11 = MPC_MULTIPLY_FRACT_CONST_FIX((A09 - A10) , 1.3065630198f , 2);
- B12 = A12 + A15;
- B13 = A13 + A14;
- B14 = MPC_MULTIPLY_FRACT_CONST_FIX((A12 - A15) , 0.5411961079f , 1);
- B15 = MPC_MULTIPLY_FRACT_CONST_FIX((A13 - A14) , 1.3065630198f , 2);
-
- A00 = B00 + B01;
- A01 = MPC_MULTIPLY_FRACT_CONST_FIX((B00 - B01) , 0.7071067691f , 1);
- A02 = B02 + B03;
- A03 = MPC_MULTIPLY_FRACT_CONST_FIX((B02 - B03) , 0.7071067691f , 1);
- A04 = B04 + B05;
- A05 = MPC_MULTIPLY_FRACT_CONST_FIX((B04 - B05) , 0.7071067691f , 1);
- A06 = B06 + B07;
- A07 = MPC_MULTIPLY_FRACT_CONST_FIX((B06 - B07) , 0.7071067691f , 1);
- A08 = B08 + B09;
- A09 = MPC_MULTIPLY_FRACT_CONST_FIX((B08 - B09) , 0.7071067691f , 1);
- A10 = B10 + B11;
- A11 = MPC_MULTIPLY_FRACT_CONST_FIX((B10 - B11) , 0.7071067691f , 1);
- A12 = B12 + B13;
- A13 = MPC_MULTIPLY_FRACT_CONST_FIX((B12 - B13) , 0.7071067691f , 1);
- A14 = B14 + B15;
- A15 = MPC_MULTIPLY_FRACT_CONST_FIX((B14 - B15) , 0.7071067691f , 1);
-
- V[48] = -A00;
- V[ 0] = A01;
- V[40] = -A02 - (V[ 8] = A03);
- V[36] = -((V[ 4] = A05 + (V[12] = A07)) + A06);
- V[44] = - A04 - A06 - A07;
- V[ 6] = (V[10] = A11 + (V[14] = A15)) + A13;
- V[38] = (V[34] = -(V[ 2] = A09 + A13 + A15) - A14) + A09 - A10 - A11;
- V[46] = (tmp = -(A12 + A14 + A15)) - A08;
- V[42] = tmp - A10 - A11;
-
- A00 = MPC_MULTIPLY_FRACT_CONST_SHR((Sample[ 0] - Sample[31]) , 0.5006030202f , MPC_FIXED_POINT_SYNTH_FIX);
- A01 = MPC_MULTIPLY_FRACT_CONST_SHR((Sample[ 1] - Sample[30]) , 0.5054709315f , MPC_FIXED_POINT_SYNTH_FIX);
- A02 = MPC_MULTIPLY_FRACT_CONST_SHR((Sample[ 2] - Sample[29]) , 0.5154473186f , MPC_FIXED_POINT_SYNTH_FIX);
- A03 = MPC_MULTIPLY_FRACT_CONST_SHR((Sample[ 3] - Sample[28]) , 0.5310425758f , MPC_FIXED_POINT_SYNTH_FIX);
- A04 = MPC_MULTIPLY_FRACT_CONST_SHR((Sample[ 4] - Sample[27]) , 0.5531039238f , MPC_FIXED_POINT_SYNTH_FIX);
- A05 = MPC_MULTIPLY_FRACT_CONST_SHR((Sample[ 5] - Sample[26]) , 0.5829349756f , MPC_FIXED_POINT_SYNTH_FIX);
- A06 = MPC_MULTIPLY_FRACT_CONST_SHR((Sample[ 6] - Sample[25]) , 0.6225041151f , MPC_FIXED_POINT_SYNTH_FIX);
- A07 = MPC_MULTIPLY_FRACT_CONST_SHR((Sample[ 7] - Sample[24]) , 0.6748083234f , MPC_FIXED_POINT_SYNTH_FIX);
- A08 = MPC_MULTIPLY_FRACT_CONST_SHR((Sample[ 8] - Sample[23]) , 0.7445362806f , MPC_FIXED_POINT_SYNTH_FIX);
- A09 = MPC_MULTIPLY_FRACT_CONST_SHR((Sample[ 9] - Sample[22]) , 0.8393496275f , MPC_FIXED_POINT_SYNTH_FIX);
- A10 = MPC_MULTIPLY_FRACT_CONST_SHR((Sample[10] - Sample[21]) , 0.9725682139f , MPC_FIXED_POINT_SYNTH_FIX);
-#if MPC_FIXED_POINT_SYNTH_FIX>=2
- A11 = MPC_MULTIPLY_FRACT_CONST_SHR((Sample[11] - Sample[20]) , 1.1694399118f , MPC_FIXED_POINT_SYNTH_FIX);
- A12 = MPC_MULTIPLY_FRACT_CONST_SHR((Sample[12] - Sample[19]) , 1.4841645956f , MPC_FIXED_POINT_SYNTH_FIX);
-#else
- A11 = MPC_SCALE_CONST_SHR ((Sample[11] - Sample[20]) , 1.1694399118f , 30, MPC_FIXED_POINT_SYNTH_FIX);
- A12 = MPC_SCALE_CONST_SHR ((Sample[12] - Sample[19]) , 1.4841645956f , 30, MPC_FIXED_POINT_SYNTH_FIX);
-#endif
- A13 = MPC_SCALE_CONST_SHR ((Sample[13] - Sample[18]) , 2.0577809811f , 29, MPC_FIXED_POINT_SYNTH_FIX);
- A14 = MPC_SCALE_CONST_SHR ((Sample[14] - Sample[17]) , 3.4076085091f , 29, MPC_FIXED_POINT_SYNTH_FIX);
- A15 = MPC_SCALE_CONST_SHR ((Sample[15] - Sample[16]) , 10.1900081635f, 27 ,MPC_FIXED_POINT_SYNTH_FIX);
-
- B00 = A00 + A15;
- B01 = A01 + A14;
- B02 = A02 + A13;
- B03 = A03 + A12;
- B04 = A04 + A11;
- B05 = A05 + A10;
- B06 = A06 + A09;
- B07 = A07 + A08;
- B08 = MPC_SCALE_CONST((A00 - A15) , 0.5024192929f , 31);
- B09 = MPC_SCALE_CONST((A01 - A14) , 0.5224986076f , 31);
- B10 = MPC_SCALE_CONST((A02 - A13) , 0.5669440627f , 31);
- B11 = MPC_SCALE_CONST((A03 - A12) , 0.6468217969f , 31);
- B12 = MPC_SCALE_CONST((A04 - A11) , 0.7881546021f , 31);
- B13 = MPC_SCALE_CONST((A05 - A10) , 1.0606776476f , 30);
- B14 = MPC_SCALE_CONST((A06 - A09) , 1.7224471569f , 30);
- B15 = MPC_SCALE_CONST((A07 - A08) , 5.1011486053f , 28);
-
- A00 = B00 + B07;
- A01 = B01 + B06;
- A02 = B02 + B05;
- A03 = B03 + B04;
- A04 = MPC_SCALE_CONST((B00 - B07) , 0.5097956061f , 31);
- A05 = MPC_SCALE_CONST((B01 - B06) , 0.6013448834f , 31);
- A06 = MPC_SCALE_CONST((B02 - B05) , 0.8999761939f , 31);
- A07 = MPC_SCALE_CONST((B03 - B04) , 2.5629155636f , 29);
- A08 = B08 + B15;
- A09 = B09 + B14;
- A10 = B10 + B13;
- A11 = B11 + B12;
- A12 = MPC_SCALE_CONST((B08 - B15) , 0.5097956061f , 31);
- A13 = MPC_SCALE_CONST((B09 - B14) , 0.6013448834f , 31);
- A14 = MPC_SCALE_CONST((B10 - B13) , 0.8999761939f , 31);
- A15 = MPC_SCALE_CONST((B11 - B12) , 2.5629155636f , 29);
-
- B00 = A00 + A03;
- B01 = A01 + A02;
- B02 = MPC_SCALE_CONST((A00 - A03) , 0.5411961079f , 31);
- B03 = MPC_SCALE_CONST((A01 - A02) , 1.3065630198f , 30);
- B04 = A04 + A07;
- B05 = A05 + A06;
- B06 = MPC_SCALE_CONST((A04 - A07) , 0.5411961079f , 31);
- B07 = MPC_SCALE_CONST((A05 - A06) , 1.3065630198f , 30);
- B08 = A08 + A11;
- B09 = A09 + A10;
- B10 = MPC_SCALE_CONST((A08 - A11) , 0.5411961079f , 31);
- B11 = MPC_SCALE_CONST((A09 - A10) , 1.3065630198f , 30);
- B12 = A12 + A15;
- B13 = A13 + A14;
- B14 = MPC_SCALE_CONST((A12 - A15) , 0.5411961079f , 31);
- B15 = MPC_SCALE_CONST((A13 - A14) , 1.3065630198f , 30);
-
- A00 = MPC_SHL(B00 + B01, MPC_FIXED_POINT_SYNTH_FIX);
- A01 = MPC_SCALE_CONST_SHL((B00 - B01) , 0.7071067691f , 31, MPC_FIXED_POINT_SYNTH_FIX);
- A02 = MPC_SHL(B02 + B03, MPC_FIXED_POINT_SYNTH_FIX);
- A03 = MPC_SCALE_CONST_SHL((B02 - B03) , 0.7071067691f , 31, MPC_FIXED_POINT_SYNTH_FIX);
- A04 = MPC_SHL(B04 + B05, MPC_FIXED_POINT_SYNTH_FIX);
- A05 = MPC_SCALE_CONST_SHL((B04 - B05) , 0.7071067691f , 31, MPC_FIXED_POINT_SYNTH_FIX);
- A06 = MPC_SHL(B06 + B07, MPC_FIXED_POINT_SYNTH_FIX);
- A07 = MPC_SCALE_CONST_SHL((B06 - B07) , 0.7071067691f , 31, MPC_FIXED_POINT_SYNTH_FIX);
- A08 = MPC_SHL(B08 + B09, MPC_FIXED_POINT_SYNTH_FIX);
- A09 = MPC_SCALE_CONST_SHL((B08 - B09) , 0.7071067691f , 31, MPC_FIXED_POINT_SYNTH_FIX);
- A10 = MPC_SHL(B10 + B11, MPC_FIXED_POINT_SYNTH_FIX);
- A11 = MPC_SCALE_CONST_SHL((B10 - B11) , 0.7071067691f , 31, MPC_FIXED_POINT_SYNTH_FIX);
- A12 = MPC_SHL(B12 + B13, MPC_FIXED_POINT_SYNTH_FIX);
- A13 = MPC_SCALE_CONST_SHL((B12 - B13) , 0.7071067691f , 31, MPC_FIXED_POINT_SYNTH_FIX);
- A14 = MPC_SHL(B14 + B15, MPC_FIXED_POINT_SYNTH_FIX);
- A15 = MPC_SCALE_CONST_SHL((B14 - B15) , 0.7071067691f , 31, MPC_FIXED_POINT_SYNTH_FIX);
-
- // mehrfach verwendete Ausdrücke: A04+A06+A07, A09+A13+A15
- V[ 5] = (V[11] = (V[13] = A07 + (V[15] = A15)) + A11) + A05 + A13;
- V[ 7] = (V[ 9] = A03 + A11 + A15) + A13;
- V[33] = -(V[ 1] = A01 + A09 + A13 + A15) - A14;
- V[35] = -(V[ 3] = A05 + A07 + A09 + A13 + A15) - A06 - A14;
- V[37] = (tmp = -(A10 + A11 + A13 + A14 + A15)) - A05 - A06 - A07;
- V[39] = tmp - A02 - A03; // abhängig vom Befehl drüber
- V[41] = (tmp += A13 - A12) - A02 - A03; // abhängig vom Befehl 2 drüber
- V[43] = tmp - A04 - A06 - A07; // abhängig von Befehlen 1 und 3 drüber
- V[47] = (tmp = -(A08 + A12 + A14 + A15)) - A00;
- V[45] = tmp - A04 - A06 - A07; // abhängig vom Befehl drüber
-
- V[32] = -V[ 0];
- V[31] = -V[ 1];
- V[30] = -V[ 2];
- V[29] = -V[ 3];
- V[28] = -V[ 4];
- V[27] = -V[ 5];
- V[26] = -V[ 6];
- V[25] = -V[ 7];
- V[24] = -V[ 8];
- V[23] = -V[ 9];
- V[22] = -V[10];
- V[21] = -V[11];
- V[20] = -V[12];
- V[19] = -V[13];
- V[18] = -V[14];
- V[17] = -V[15];
-
- V[63] = V[33];
- V[62] = V[34];
- V[61] = V[35];
- V[60] = V[36];
- V[59] = V[37];
- V[58] = V[38];
- V[57] = V[39];
- V[56] = V[40];
- V[55] = V[41];
- V[54] = V[42];
- V[53] = V[43];
- V[52] = V[44];
- V[51] = V[45];
- V[50] = V[46];
- V[49] = V[47];
-}
-
-static void Synthese_Filter_float_internal(MPC_SAMPLE_FORMAT * OutData,MPC_SAMPLE_FORMAT * V,const MPC_SAMPLE_FORMAT * Y)
-{
- mpc_uint32_t n;
- for ( n = 0; n < 36; n++, Y += 32 ) {
- V -= 64;
- Calculate_New_V ( Y, V );
- {
- MPC_SAMPLE_FORMAT * Data = OutData;
- const MPC_SAMPLE_FORMAT * D = (const MPC_SAMPLE_FORMAT *) &Di_opt;
- mpc_int32_t k;
- //mpc_int32_t tmp;
-
-
-
- for ( k = 0; k < 32; k++, D += 16, V++ ) {
- *Data = MPC_SHL(
- MPC_MULTIPLY_FRACT(V[ 0],D[ 0]) + MPC_MULTIPLY_FRACT(V[ 96],D[ 1]) + MPC_MULTIPLY_FRACT(V[128],D[ 2]) + MPC_MULTIPLY_FRACT(V[224],D[ 3])
- + MPC_MULTIPLY_FRACT(V[256],D[ 4]) + MPC_MULTIPLY_FRACT(V[352],D[ 5]) + MPC_MULTIPLY_FRACT(V[384],D[ 6]) + MPC_MULTIPLY_FRACT(V[480],D[ 7])
- + MPC_MULTIPLY_FRACT(V[512],D[ 8]) + MPC_MULTIPLY_FRACT(V[608],D[ 9]) + MPC_MULTIPLY_FRACT(V[640],D[10]) + MPC_MULTIPLY_FRACT(V[736],D[11])
- + MPC_MULTIPLY_FRACT(V[768],D[12]) + MPC_MULTIPLY_FRACT(V[864],D[13]) + MPC_MULTIPLY_FRACT(V[896],D[14]) + MPC_MULTIPLY_FRACT(V[992],D[15])
- , 2);
-
- Data += 2;
- }
- V -= 32;//bleh
- OutData+=64;
- }
- }
-}
-
-void
-mpc_decoder_synthese_filter_float(mpc_decoder *d, MPC_SAMPLE_FORMAT* OutData)
-{
- /********* left channel ********/
- memmove(d->V_L + MPC_V_MEM, d->V_L, 960 * sizeof(MPC_SAMPLE_FORMAT) );
-
- Synthese_Filter_float_internal(
- OutData,
- (MPC_SAMPLE_FORMAT *)(d->V_L + MPC_V_MEM),
- (MPC_SAMPLE_FORMAT *)(d->Y_L [0]));
-
- /******** right channel ********/
- memmove(d->V_R + MPC_V_MEM, d->V_R, 960 * sizeof(MPC_SAMPLE_FORMAT) );
-
- Synthese_Filter_float_internal(
- OutData + 1,
- (MPC_SAMPLE_FORMAT *)(d->V_R + MPC_V_MEM),
- (MPC_SAMPLE_FORMAT *)(d->Y_R [0]));
-}
-
-/*******************************************/
-/* */
-/* dithered synthesis */
-/* */
-/*******************************************/
-
-static const unsigned char Parity [256] = { // parity
- 0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
- 1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,
- 1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,
- 0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
- 1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,
- 0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
- 0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
- 1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0
-};
-
-/*
- * This is a simple random number generator with good quality for audio purposes.
- * It consists of two polycounters with opposite rotation direction and different
- * periods. The periods are coprime, so the total period is the product of both.
- *
- * -------------------------------------------------------------------------------------------------
- * +-> |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|
- * | -------------------------------------------------------------------------------------------------
- * | | | | | | |
- * | +--+--+--+-XOR-+--------+
- * | |
- * +--------------------------------------------------------------------------------------+
- *
- * -------------------------------------------------------------------------------------------------
- * |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| <-+
- * ------------------------------------------------------------------------------------------------- |
- * | | | | |
- * +--+----XOR----+--+ |
- * | |
- * +----------------------------------------------------------------------------------------+
- *
- *
- * The first has an period of 3*5*17*257*65537, the second of 7*47*73*178481,
- * which gives a period of 18.410.713.077.675.721.215. The result is the
- * XORed values of both generators.
- */
-mpc_uint32_t
-random_int(mpc_decoder *d)
-{
-#if 1
- mpc_uint32_t t1, t2, t3, t4;
-
- t3 = t1 = d->__r1; t4 = t2 = d->__r2; // Parity calculation is done via table lookup, this is also available
- t1 &= 0xF5; t2 >>= 25; // on CPUs without parity, can be implemented in C and avoid unpredictable
- t1 = Parity [t1]; t2 &= 0x63; // jumps and slow rotate through the carry flag operations.
- t1 <<= 31; t2 = Parity [t2];
-
- return (d->__r1 = (t3 >> 1) | t1 ) ^ (d->__r2 = (t4 + t4) | t2 );
-#else
- return (d->__r1 = (d->__r1 >> 1) | ((mpc_uint32_t)Parity [d->__r1 & 0xF5] << 31) ) ^
- (d->__r2 = (d->__r2 << 1) | (mpc_uint32_t)Parity [(d->__r2 >> 25) & 0x63] );
-#endif
-}
diff --git a/src/libmusepack/xine_musepack_decoder.c b/src/libmusepack/xine_musepack_decoder.c
deleted file mode 100644
index 26c2eddf5..000000000
--- a/src/libmusepack/xine_musepack_decoder.c
+++ /dev/null
@@ -1,471 +0,0 @@
-/*
- * Copyright (C) 2005 the xine project
- *
- * This file is part of xine, a free video player.
- *
- * xine 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.
- *
- * xine is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- *
- * xine interface to libmusepack by James Stembridge <jstembridge@gmail.com>
- *
- * TODO:
- * 32bit float output
- * Seeking??
- *
- * $Id: xine_decoder.c,v 1.10 2007/01/19 02:35:36 dgp85 Exp $
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#define LOG_MODULE "mpc_decoder"
-#define LOG_VERBOSE
-/*
-#define LOG
-*/
-
-#include "xine_internal.h"
-#include "audio_out.h"
-#include "buffer.h"
-#include "xineutils.h"
-
-#ifdef HAVE_MPCDEC_MPCDEC_H
-# include <mpcdec/mpcdec.h>
-#else
-# include "musepack/musepack.h"
-#endif
-
-#define MPC_DECODER_MEMSIZE 65536
-#define MPC_DECODER_MEMSIZE2 (MPC_DECODER_MEMSIZE/2)
-
-#define INIT_BUFSIZE (MPC_DECODER_MEMSIZE*2)
-
-typedef struct {
- audio_decoder_class_t decoder_class;
-} mpc_class_t;
-
-typedef struct mpc_decoder_s {
- audio_decoder_t audio_decoder;
-
- xine_stream_t *stream;
-
- int sample_rate; /* audio sample rate */
- int bits_per_sample; /* bits/sample, usually 8 or 16 */
- int channels; /* 1 or 2, usually */
-
- int output_open; /* flag to indicate audio is ready */
-
- unsigned char *buf; /* data accumulation buffer */
- unsigned int buf_max; /* maximum size of buf */
- unsigned int read; /* size of accum. data already read */
- unsigned int size; /* size of accumulated data in buf */
-
- mpc_reader reader;
- mpc_streaminfo streaminfo;
- mpc_decoder decoder;
-
- int decoder_ok;
- unsigned int current_frame;
-
- int32_t file_size;
-
-} mpc_decoder_t;
-
-
-/**************************************************************************
- * musepack specific functions
- *************************************************************************/
-
-/* Reads size bytes of data into buffer at ptr. */
-static int32_t mpc_reader_read(void *data, void *ptr, int size) {
- mpc_decoder_t *this = (mpc_decoder_t *) data;
-
- lprintf("mpc_reader_read: size=%d\n", size);
-
- /* Don't try to read more data than we have */
- if (size > (this->size - this->read))
- size = this->size - this->read;
-
- /* Copy the data */
- xine_fast_memcpy(ptr, &this->buf[this->read], size);
-
- /* Update our position in the data buffer */
- this->read += size;
-
- return size;
-}
-
-/* Seeks to byte position offset. */
-static mpc_bool_t mpc_reader_seek(void *data, int32_t offset) {
- mpc_decoder_t *this = (mpc_decoder_t *) data;
-
- lprintf("mpc_reader_seek: offset=%d\n", offset);
-
- /* seek is only called when reading the header so we can assume
- * that the buffer starts at the start of the file */
- this->read = offset;
-
- return TRUE;
-}
-
-/* Returns the current byte offset in the stream. */
-static int32_t mpc_reader_tell(void *data) {
- lprintf("mpc_reader_tell\n");
-
- /* Tell isn't used so just return 0 */
- return 0;
-}
-
-/* Returns the total length of the source stream, in bytes. */
-static int32_t mpc_reader_get_size(void *data) {
- mpc_decoder_t *this = (mpc_decoder_t *) data;
-
- lprintf("mpc_reader_get_size\n");
-
- return this->file_size;
-}
-
-/* True if the stream is a seekable stream. */
-static mpc_bool_t mpc_reader_canseek(void *data) {
- lprintf("mpc_reader_canseek\n");
-
- return TRUE;
-}
-
-/* Convert 32bit float samples into 16bit int samples */
-static inline void float_to_int(float *_f, int16_t *s16, int samples) {
- int i;
- float f;
- for (i = 0; i < samples; i++) {
- f = _f[i] * 32767;
- if (f > INT16_MAX) f = INT16_MAX;
- if (f < INT16_MIN) f = INT16_MIN;
- s16[i] = f;
- /* printf("samples[%d] = %f, %d\n", i, _f[i], s16[num_channels*i]); */
- }
-}
-
-/* Decode a musepack frame */
-static int mpc_decode_frame (mpc_decoder_t *this) {
- float buffer[MPC_DECODER_BUFFER_LENGTH];
- uint32_t frames;
-
- lprintf("mpd_decode_frame\n");
-
- frames = mpc_decoder_decode(&this->decoder, buffer, 0, 0);
-
- if (frames > 0) {
- audio_buffer_t *audio_buffer;
- int16_t *int_samples;
-
- lprintf("got %d samples\n", frames);
-
- /* Get audio buffer */
- audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out);
- audio_buffer->vpts = 0;
- audio_buffer->num_frames = frames;
-
- /* Convert samples */
- int_samples = (int16_t *) audio_buffer->mem;
- float_to_int(buffer, int_samples, frames*this->channels);
-
- /* Output converted samples */
- this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream);
- }
-
- return frames;
-}
-
-/**************************************************************************
- * xine audio plugin functions
- *************************************************************************/
-
-static void mpc_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) {
- mpc_decoder_t *this = (mpc_decoder_t *) this_gen;
- int err;
-
- lprintf("mpc_decode_data\n");
-
- if (!_x_stream_info_get(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED))
- return;
-
- /* We don't handle special buffers */
- if (buf->decoder_flags & BUF_FLAG_SPECIAL)
- return;
-
- /* Read header */
- if (buf->decoder_flags & BUF_FLAG_HEADER) {
-
- lprintf("header\n");
-
- /* File size is in decoder_info[0] */
- this->file_size = buf->decoder_info[0];
-
- /* Initialise the data accumulation buffer */
- this->buf = xine_xmalloc(INIT_BUFSIZE);
- this->buf_max = INIT_BUFSIZE;
- this->read = 0;
- this->size = 0;
-
- /* Initialise the reader */
- this->reader.read = mpc_reader_read;
- this->reader.seek = mpc_reader_seek;
- this->reader.tell = mpc_reader_tell;
- this->reader.get_size = mpc_reader_get_size;
- this->reader.canseek = mpc_reader_canseek;
- this->reader.data = this;
-
- /* Copy header to buffer */
- xine_fast_memcpy(this->buf, buf->content, buf->size);
- this->size = buf->size;
-
- /* Initialise and read stream info */
- mpc_streaminfo_init(&this->streaminfo);
-
- if ((err = mpc_streaminfo_read(&this->streaminfo, &this->reader))) {
- xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
- _("libmusepack: mpc_streaminfo_read failed: %d\n"), err);
-
- _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0);
- return;
- }
-
- this->sample_rate = this->streaminfo.sample_freq;
- this->channels = this->streaminfo.channels;
- this->bits_per_sample = 16;
-
- /* After the header the demuxer starts sending data from an offset
- * of 28 bytes */
- this->size = 28;
-
- /* We need to keep track of the current frame so we now when we've
- * reached the end of the stream */
- this->current_frame = 0;
-
- /* Setup the decoder */
- mpc_decoder_setup(&this->decoder, &this->reader);
- this->decoder_ok = 0;
-
- /* Take this opportunity to initialize stream/meta information */
- _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC,
- "Musepack (libmusepack)");
- _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITRATE,
- (int) this->streaminfo.average_bitrate);
-
- return;
- }
-
- lprintf("data: %u size=%u read=%u\n", buf->size, this->size, this->read);
-
- /* if the audio output is not open yet, open the audio output */
- if (!this->output_open) {
- this->output_open = this->stream->audio_out->open(
- this->stream->audio_out,
- this->stream,
- this->bits_per_sample,
- this->sample_rate,
- _x_ao_channels2mode(this->channels));
- }
-
- /* if the audio still isn't open, do not go any further with the decode */
- if (!this->output_open)
- return;
-
- /* If we run out of space in our internal buffer we discard what's
- * already been read */
- if (((this->size + buf->size) > this->buf_max) && this->read) {
- lprintf("discarding read data\n");
- this->size -= this->read;
- memmove(this->buf, &this->buf[this->read], this->size);
- this->read = 0;
- }
-
- /* If there still isn't space we have to increase the size of the
- * internal buffer */
- if ((this->size + buf->size) > this->buf_max) {
- xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG,
- "libmusepack: increasing internal buffer size\n");
- this->buf_max += 2*buf->size;
- this->buf = realloc(this->buf, this->buf_max);
- }
-
- /* Copy data */
- xine_fast_memcpy(&this->buf[this->size], buf->content, buf->size);
- this->size += buf->size;
-
- /* Time to decode */
- if (buf->decoder_flags & BUF_FLAG_FRAME_END) {
- /* Increment frame count */
- if (this->current_frame++ == this->streaminfo.frames) {
- xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
- _("libmusepack: data after last frame ignored\n"));
- return;
- }
-
- if (!this->decoder_ok) {
- /* We require MPC_DECODER_MEMSIZE bytes to initialise the decoder */
- if ((this->size - this->read) >= MPC_DECODER_MEMSIZE) {
- lprintf("initialise");
-
- if (!mpc_decoder_initialize(&this->decoder, &this->streaminfo)) {
- xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
- _("libmusepack: mpc_decoder_initialise failed\n"));
-
- _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0);
- return;
- }
-
- this->decoder_ok = 1;
- } else {
- /* Not enough data yet */
- return;
- }
- }
-
- /* mpc_decoder_decode may cause a read of MPC_DECODER_MEMSIZE/2 bytes so
- * make sure we have enough data available */
- if ((this->size - this->read) >= MPC_DECODER_MEMSIZE2) {
- lprintf("decoding\n");
-
- if ((err = mpc_decode_frame(this)) < 0) {
- xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
- _("libmusepack: mpc_decoder_decode failed: %d\n"), err);
-
- _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0);
- return;
- }
- }
-
- /* If we are at the end of the stream we decode the remaining frames as we
- * know we'll have enough data */
- if (this->current_frame == this->streaminfo.frames) {
- lprintf("flushing buffers\n");
-
- do {
- if ((err = mpc_decode_frame(this)) < 0) {
- xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
- _("libmusepack: mpc_decoder_decode failed: %d\n"), err);
- }
- } while (err > 0);
-
- lprintf("buffers flushed\n");
- }
- }
-}
-
-static void mpc_reset (audio_decoder_t *this_gen) {
- mpc_decoder_t *this = (mpc_decoder_t *) this_gen;
-
- this->size = 0;
- this->read = 0;
-}
-
-static void mpc_discontinuity (audio_decoder_t *this_gen) {
- /* mpc_decoder_t *this = (mpc_decoder_t *) this_gen; */
-}
-
-static void mpc_dispose (audio_decoder_t *this_gen) {
-
- mpc_decoder_t *this = (mpc_decoder_t *) this_gen;
-
- /* close the audio output */
- if (this->output_open)
- this->stream->audio_out->close (this->stream->audio_out, this->stream);
- this->output_open = 0;
-
- /* free anything that was allocated during operation */
- if (this->buf)
- free(this->buf);
-
- free(this);
-}
-
-static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) {
-
- mpc_decoder_t *this ;
-
- this = (mpc_decoder_t *) xine_xmalloc (sizeof (mpc_decoder_t));
-
- /* connect the member functions */
- this->audio_decoder.decode_data = mpc_decode_data;
- this->audio_decoder.reset = mpc_reset;
- this->audio_decoder.discontinuity = mpc_discontinuity;
- this->audio_decoder.dispose = mpc_dispose;
-
- /* connect the stream */
- this->stream = stream;
-
- /* audio output is not open at the start */
- this->output_open = 0;
-
- /* no buffer yet */
- this->buf = NULL;
-
- /* initialize the basic audio parameters */
- this->channels = 0;
- this->sample_rate = 0;
- this->bits_per_sample = 0;
-
- /* return the newly-initialized audio decoder */
- return &this->audio_decoder;
-}
-
-static char *get_identifier (audio_decoder_class_t *this) {
- return "mpc";
-}
-
-static char *get_description (audio_decoder_class_t *this) {
- return "mpc: musepack audio decoder plugin";
-}
-
-static void dispose_class (audio_decoder_class_t *this_gen) {
-
- mpc_class_t *this = (mpc_class_t *)this_gen;
-
- free (this);
-}
-
-static void *init_plugin (xine_t *xine, void *data) {
-
- mpc_class_t *this ;
-
- this = (mpc_class_t *) xine_xmalloc (sizeof (mpc_class_t));
-
- this->decoder_class.open_plugin = open_plugin;
- this->decoder_class.get_identifier = get_identifier;
- this->decoder_class.get_description = get_description;
- this->decoder_class.dispose = dispose_class;
-
- return this;
-}
-
-static uint32_t audio_types[] = {
- BUF_AUDIO_MPC,
- 0
-};
-
-static const decoder_info_t dec_info_audio = {
- audio_types, /* supported types */
- 5 /* priority */
-};
-
-const plugin_info_t xine_plugin_info[] EXPORTED = {
- /* { type, API version, "name", version, special_info, init_function }, */
- { PLUGIN_AUDIO_DECODER, 15, "mpc", XINE_VERSION_CODE, &dec_info_audio, &init_plugin },
- { PLUGIN_NONE, 0, "", 0, NULL, NULL }
-};
-
diff --git a/src/libreal/Makefile.am b/src/libreal/Makefile.am
index c9cf62984..0f765394e 100644
--- a/src/libreal/Makefile.am
+++ b/src/libreal/Makefile.am
@@ -1,12 +1,13 @@
include $(top_srcdir)/misc/Makefile.common
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+AM_LDFLAGS = $(xineplug_ldflags)
+
+noinst_HEADERS = real_common.h
+
if ENABLE_REAL
xineplug_LTLIBRARIES = xineplug_decode_real.la
endif
xineplug_decode_real_la_SOURCES = xine_real_video_decoder.c real_common.c xine_real_audio_decoder.c
xineplug_decode_real_la_LIBADD = $(XINE_LIB) $(DYNAMIC_LD_LIBS)
-xineplug_decode_real_la_CFLAGS = $(VISIBILITY_FLAG)
-xineplug_decode_real_la_LDFLAGS = $(xineplug_ldflags)
-
-noinst_HEADERS = real_common.h
diff --git a/src/libspucc/Makefile.am b/src/libspucc/Makefile.am
index aefe4d7c1..87266505c 100644
--- a/src/libspucc/Makefile.am
+++ b/src/libspucc/Makefile.am
@@ -1,10 +1,12 @@
include $(top_srcdir)/misc/Makefile.common
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+AM_LDFLAGS = $(xineplug_ldflags)
+
+noinst_HEADERS = cc_decoder.h
+
xineplug_LTLIBRARIES = xineplug_decode_spucc.la
xineplug_decode_spucc_la_SOURCES = cc_decoder.c xine_cc_decoder.c
-xineplug_decode_spucc_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS) -fno-strict-aliasing
xineplug_decode_spucc_la_LIBADD = $(XINE_LIB)
-xineplug_decode_spucc_la_LDFLAGS = -avoid-version -module
-
-noinst_HEADERS = cc_decoder.h
+xineplug_decode_spucc_la_CFLAGS = $(AM_CFLAGS) -fno-strict-aliasing
diff --git a/src/libspucmml/Makefile.am b/src/libspucmml/Makefile.am
index ac2970482..fb92ff589 100644
--- a/src/libspucmml/Makefile.am
+++ b/src/libspucmml/Makefile.am
@@ -1,8 +1,9 @@
include $(top_srcdir)/misc/Makefile.common
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+AM_LDFLAGS = $(xineplug_ldflags)
+
xineplug_LTLIBRARIES = xineplug_decode_spucmml.la
xineplug_decode_spucmml_la_SOURCES = xine_cmml_decoder.c
xineplug_decode_spucmml_la_LIBADD = $(XINE_LIB)
-xineplug_decode_spucmml_la_CFLAGS = $(VISIBILITY_FLAG)
-xineplug_decode_spucmml_la_LDFLAGS = $(xineplug_ldflags)
diff --git a/src/libspudec/Makefile.am b/src/libspudec/Makefile.am
index 208d994f5..62de3774d 100644
--- a/src/libspudec/Makefile.am
+++ b/src/libspudec/Makefile.am
@@ -1,26 +1,21 @@
include $(top_srcdir)/misc/Makefile.common
-xineplug_LTLIBRARIES = xineplug_decode_spu.la
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+AM_CPPFLAGS = -I$(top_srcdir)/src/input/libdvdnav
+AM_LDFLAGS = $(xineplug_ldflags)
-if HAVE_DVDNAV
+noinst_HEADERS = spu.h
-xineplug_decode_spu_la_SOURCES = \
- spu.c \
- xine_spu_decoder.c
-xineplug_decode_spu_la_LIBADD = $(XINE_LIB) $(DVDNAV_LIBS) $(PTHREAD_LIBS)
+xineplug_LTLIBRARIES = xineplug_decode_spu.la
+if WITH_EXTERNAL_DVDNAV
+external_dvdnav_libs = $(DVDNAV_LIBS)
+internal_dvdnav_sources =
else
-
-xineplug_decode_spu_la_SOURCES = \
- nav_read.c \
- spu.c \
- xine_spu_decoder.c
-AM_CPPFLAGS = -I$(top_srcdir)/src/input/libdvdnav
-xineplug_decode_spu_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS)
-
+external_dvdnav_libs =
+internal_dvdnav_sources = nav_read.c
endif
-xineplug_decode_spu_la_CFLAGS = $(DVDNAV_CFLAGS) $(VISIBILITY_FLAG)
-xineplug_decode_spu_la_LDFLAGS = $(xineplug_ldflags)
-
-noinst_HEADERS = spu.h
+xineplug_decode_spu_la_SOURCES = $(internal_dvdnav_sources) spu.c xine_spu_decoder.c
+xineplug_decode_spu_la_LIBADD = $(XINE_LIB) $(external_dvdnav_libs) $(PTHREAD_LIBS)
+xineplug_decode_spu_la_CFLAGS = $(AM_CFLAGS) $(DVDNAV_CFLAGS)
diff --git a/src/libspudvb/Makefile.am b/src/libspudvb/Makefile.am
index e385e5553..f822df0d9 100644
--- a/src/libspudvb/Makefile.am
+++ b/src/libspudvb/Makefile.am
@@ -1,8 +1,9 @@
include $(top_srcdir)/misc/Makefile.common
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+AM_LDFLAGS = $(xineplug_ldflags)
+
xineplug_LTLIBRARIES = xineplug_decode_spudvb.la
xineplug_decode_spudvb_la_SOURCES = xine_spudvb_decoder.c
xineplug_decode_spudvb_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS)
-xineplug_decode_spudvb_la_CFLAGS = $(VISIBILITY_FLAG)
-xineplug_decode_spudvb_la_LDFLAGS = $(xineplug_ldflags)
diff --git a/src/libsputext/Makefile.am b/src/libsputext/Makefile.am
index 5e4ce59d0..f09219043 100644
--- a/src/libsputext/Makefile.am
+++ b/src/libsputext/Makefile.am
@@ -1,13 +1,12 @@
include $(top_srcdir)/misc/Makefile.common
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
AM_LDFLAGS = $(xineplug_ldflags)
xineplug_LTLIBRARIES = xineplug_decode_sputext.la xineplug_dmx_sputext.la
xineplug_dmx_sputext_la_SOURCES = demux_sputext.c
xineplug_dmx_sputext_la_LIBADD = $(XINE_LIB)
-xineplug_dmx_sputext_la_CFLAGS = $(VISIBILITY_FLAG)
xineplug_decode_sputext_la_SOURCES = xine_sputext_decoder.c
xineplug_decode_sputext_la_LIBADD = $(XINE_LIB)
-xineplug_decode_sputext_la_CFLAGS = $(VISIBILITY_FLAG)
diff --git a/src/libsputext/xine_sputext_decoder.c b/src/libsputext/xine_sputext_decoder.c
index e8ef631ca..d4dd103ec 100644
--- a/src/libsputext/xine_sputext_decoder.c
+++ b/src/libsputext/xine_sputext_decoder.c
@@ -925,7 +925,7 @@ static void update_src_encoding(void *class_gen, xine_cfg_entry_t *entry)
static void *init_spu_decoder_plugin (xine_t *xine, void *data) {
- static const char *subtitle_size_strings[] = {
+ static const char *const subtitle_size_strings[] = {
"tiny", "small", "normal", "large", "very large", "huge", NULL
};
sputext_class_t *this ;
diff --git a/src/libw32dll/DirectShow/Makefile.am b/src/libw32dll/DirectShow/Makefile.am
index a74c65815..02eddc00a 100644
--- a/src/libw32dll/DirectShow/Makefile.am
+++ b/src/libw32dll/DirectShow/Makefile.am
@@ -1,26 +1,9 @@
include $(top_srcdir)/misc/Makefile.common
-AM_CFLAGS = $(X_CFLAGS) -fno-omit-frame-pointer \
- -Wmissing-prototypes -Wimplicit-function-declaration \
- -DWIN32_PATH=\"@w32_path@\" -DNOAVIFILE_HEADERS \
+AM_CFLAGS = $(X_CFLAGS) -fno-omit-frame-pointer
+AM_CPPFLAGS = -DWIN32_PATH=\"$(w32_path)\" -DNOAVIFILE_HEADERS \
-I$(srcdir)/.. -I$(srcdir)/../wine
-if HAVE_W32DLL
-ds_filter_lib = libds_filter.la
-endif
-
-noinst_LTLIBRARIES = $(ds_filter_lib)
-
-libds_filter_la_SOURCES = \
- allocator.c \
- cmediasample.c \
- guids.c \
- inputpin.c \
- outputpin.c \
- DS_Filter.c \
- DS_AudioDecoder.c \
- DS_VideoDecoder.c
-
noinst_HEADERS = \
allocator.h \
cmediasample.h \
@@ -32,3 +15,15 @@ noinst_HEADERS = \
DS_AudioDecoder.h \
DS_Filter.h \
DS_VideoDecoder.h
+
+noinst_LTLIBRARIES = libds_filter.la
+
+libds_filter_la_SOURCES = \
+ allocator.c \
+ cmediasample.c \
+ guids.c \
+ inputpin.c \
+ outputpin.c \
+ DS_Filter.c \
+ DS_AudioDecoder.c \
+ DS_VideoDecoder.c
diff --git a/src/libw32dll/Makefile.am b/src/libw32dll/Makefile.am
index 358eea40a..7d11bb2dc 100644
--- a/src/libw32dll/Makefile.am
+++ b/src/libw32dll/Makefile.am
@@ -1,36 +1,32 @@
include $(top_srcdir)/misc/Makefile.common
-AM_CFLAGS = -I$(srcdir)/wine -DWIN32_PATH=\"@w32_path@\" $(VISIBILITY_FLAG)
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+AM_CPPFLAGS = -I$(srcdir)/wine -DWIN32_PATH=\"$(w32_path)\"
+AM_LDFLAGS = $(xineplug_ldflags)
-SUBDIRS = wine DirectShow dmo qtx
-
-if HAVE_W32DLL
-w32dll_codec = xineplug_decode_w32dll.la
-qt_codec = xineplug_decode_qt.la
+SUBDIRS =
+if ENABLE_W32DLL
+SUBDIRS += wine DirectShow dmo qtx
endif
-xineplug_LTLIBRARIES = $(w32dll_codec) $(qt_codec)
-
EXTRA_DIST = common.c
+noinst_HEADERS = libwin32.h w32codec.h
+
+if ENABLE_W32DLL
+xineplug_LTLIBRARIES = xineplug_decode_w32dll.la xineplug_decode_qt.la
+endif
+
xineplug_decode_w32dll_la_SOURCES = w32codec.c
-xineplug_decode_w32dll_la_LDFLAGS = -avoid-version -module
+xineplug_decode_w32dll_la_DEPS = $(XDG_BASEDIR_DEPS)
xineplug_decode_w32dll_la_LIBADD = \
$(top_builddir)/src/libw32dll/wine/libwine.la \
- $(XINE_LIB) \
- $(PTHREAD_LIBS) \
- -lm \
$(top_builddir)/src/libw32dll/DirectShow/libds_filter.la \
$(top_builddir)/src/libw32dll/dmo/libdmo_filter.la \
- @KSTAT_LIBS@
+ $(XINE_LIB) $(PTHREAD_LIBS) -lm $(KSTAT_LIBS) $(XDG_BASEDIR_LIBS)
+xineplug_decode_w32dll_la_CPPFLAGS = $(AM_CPPFLAGS) $(XDG_BASEDIR_CPPFLAGS)
xineplug_decode_qt_la_SOURCES = qt_decoder.c
-xineplug_decode_qt_la_LDFLAGS = -avoid-version -module
xineplug_decode_qt_la_LIBADD = \
$(top_builddir)/src/libw32dll/wine/libwine.la \
- $(XINE_LIB) \
- $(PTHREAD_LIBS) \
- -lm \
- @KSTAT_LIBS@
-
-noinst_HEADERS = libwin32.h w32codec.h
+ $(XINE_LIB) $(PTHREAD_LIBS) -lm $(KSTAT_LIBS)
diff --git a/src/libw32dll/dmo/Makefile.am b/src/libw32dll/dmo/Makefile.am
index 2b7cd3e37..531a4559a 100644
--- a/src/libw32dll/dmo/Makefile.am
+++ b/src/libw32dll/dmo/Makefile.am
@@ -1,22 +1,7 @@
include $(top_srcdir)/misc/Makefile.common
-AM_CFLAGS = $(X_CFLAGS) -fno-omit-frame-pointer \
- -Wmissing-prototypes -Wimplicit-function-declaration \
- -DWIN32_PATH=\"@w32_path@\" -DNOAVIFILE_HEADERS \
- -I$(srcdir)/.. -I$(srcdir)/../wine
-
-if HAVE_W32DLL
-dmo_filter_lib = libdmo_filter.la
-endif
-
-noinst_LTLIBRARIES = $(dmo_filter_lib)
-
-libdmo_filter_la_SOURCES = \
- buffer.c \
- DMO_AudioDecoder.c \
- dmo.c \
- dmo_guids.c \
- DMO_VideoDecoder.c
+AM_CFLAGS = $(X_CFLAGS) -fno-omit-frame-pointer
+AM_CPPFLAGS = -DWIN32_PATH=\"$(w32_path)\" -DNOAVIFILE_HEADERS -I$(srcdir)/.. -I$(srcdir)/../wine
noinst_HEADERS = \
DMO_AudioDecoder.h \
@@ -25,3 +10,12 @@ noinst_HEADERS = \
DMO_Filter.h \
dmo.h \
DMO_VideoDecoder.h
+
+noinst_LTLIBRARIES = libdmo_filter.la
+
+libdmo_filter_la_SOURCES = \
+ buffer.c \
+ DMO_AudioDecoder.c \
+ dmo.c \
+ dmo_guids.c \
+ DMO_VideoDecoder.c
diff --git a/src/libw32dll/wine/Makefile.am b/src/libw32dll/wine/Makefile.am
index 63da4068e..1756e3262 100644
--- a/src/libw32dll/wine/Makefile.am
+++ b/src/libw32dll/wine/Makefile.am
@@ -1,40 +1,13 @@
include $(top_srcdir)/misc/Makefile.common
-LIBTOOL = $(SHELL) $(top_builddir)/libtool
-
-EXTRA_DIST = stubs.s wrapper.S
-
-noinst_LTLIBRARIES = $(wine_lib)
-
-AM_CFLAGS = $(X_CFLAGS) @W32_NO_OPTIMIZE@ \
- -Wmissing-prototypes -Wimplicit-function-declaration \
- -DWIN32_PATH=\"@w32_path@\" -I$(srcdir)/.. -D__WINE__ \
+# disable -fomit-frame-pointer, -finline-functions, and -frename-registers
+# because they cause bad behavior of wine
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(X_CFLAGS) @W32_NO_OPTIMIZE@ \
+ -fno-omit-frame-pointer -fno-inline-functions -fno-rename-registers
+AM_CPPFLAGS = -DWIN32_PATH=\"$(w32_path)\" -I$(srcdir)/.. -D__WINE__ \
-Ddbg_printf=__vprintf -DTRACE=__vprintf
-# CFLAGS is here to filter out -fomit-frame-pointer,
-# -finline-functions and -frename-registers because they cause bad
-# behavior of wine
-CFLAGS = `echo @CFLAGS@ | sed -e 's/-fomit-frame-pointer//g;s/-finline-functions//g;s/-frename-registers//g'`
-
-if HAVE_W32DLL
-wine_lib = libwine.la
-endif
-
-libwine_la_SOURCES = \
- afl.c \
- driver.c \
- elfdll.c \
- ext.c \
- ldt_keeper.c \
- module.c \
- pe_image.c \
- pe_resource.c \
- resource.c \
- registry.c \
- vfl.c \
- win32.c \
- stubs.s \
- wrapper.S
+EXTRA_DIST = stubs.s wrapper.S
noinst_HEADERS = \
avifmt.h \
@@ -74,3 +47,21 @@ noinst_HEADERS = \
winuser.h \
wrapper.h
+noinst_LTLIBRARIES = libwine.la
+
+libwine_la_SOURCES = \
+ afl.c \
+ driver.c \
+ elfdll.c \
+ ext.c \
+ ldt_keeper.c \
+ module.c \
+ pe_image.c \
+ pe_resource.c \
+ resource.c \
+ registry.c \
+ vfl.c \
+ win32.c \
+ stubs.s \
+ wrapper.S
+libwine_la_CPPFLAGS = $(AM_CPPFLAGS) $(XDG_BASEDIR_CPPFLAGS)
diff --git a/src/libw32dll/wine/registry.c b/src/libw32dll/wine/registry.c
index 0f91499b3..c8e3c4dd0 100644
--- a/src/libw32dll/wine/registry.c
+++ b/src/libw32dll/wine/registry.c
@@ -19,6 +19,7 @@
#ifdef XINE_MAJOR
#include "xineutils.h"
+#include <basedir.h>
#endif
//#undef TRACE
@@ -302,44 +303,22 @@ static struct reg_value* insert_reg_value(int handle, const char* name, int type
static void init_registry(void)
{
+ xdgHandle tmph = xdgAllocHandle();
+ const char *const xdg_cache_home = xdgCacheHome(tmph);
+
TRACE("Initializing registry\n");
// can't be free-ed - it's static and probably thread
// unsafe structure which is stored in glibc
-#ifdef MPLAYER
- regpathname = get_path("registry");
- localregpathname = regpathname;
-#else
-#ifdef XINE_MAJOR
- localregpathname = (char *)malloc(strlen(xine_get_homedir()) + 21);
- sprintf(localregpathname, "%s/.xine/win32registry", xine_get_homedir());
-#else
- // regpathname is an external pointer
- //
- // registry.c is holding it's own internal pointer
- // localregpathname - which is being allocate/deallocated
-
- if (localregpathname == 0)
- {
- const char* pthn = regpathname;
- if (!regpathname)
- {
- // avifile - for now reading data from user's home
- struct passwd* pwent;
- pwent = getpwuid(geteuid());
- pthn = pwent->pw_dir;
- }
-
- localregpathname = (char*)malloc(strlen(pthn)+20);
- strcpy(localregpathname, pthn);
- strcat(localregpathname, "/.registry");
- }
-#endif
-#endif
+ localregpathname = malloc(strlen(xdg_cache_home) + sizeof("/"PACKAGE"/win32registry"));
+ strcpy(localregpathname, xdg_cache_home);
+ strcat(localregpathname, "/"PACKAGE"/win32registry");
open_registry();
insert_handle(HKEY_LOCAL_MACHINE, "HKLM");
insert_handle(HKEY_CURRENT_USER, "HKCU");
+
+ xdgFreeHandle(tmph);
}
#if 0
diff --git a/src/libw32dll/wine/windef.h b/src/libw32dll/wine/windef.h
index e7f691a02..b86f2f740 100644
--- a/src/libw32dll/wine/windef.h
+++ b/src/libw32dll/wine/windef.h
@@ -7,8 +7,9 @@
#ifndef __WINE_WINDEF_H
#define __WINE_WINDEF_H
+#include "config.h"
+
#ifdef __WINE__
-# include "config.h"
# undef UNICODE
#endif
@@ -493,14 +494,14 @@ typedef LRESULT CALLBACK (*WNDPROC16)(HWND16,UINT16,WPARAM16,LPARAM);
/* Macro for structure packing. */
+#define WINE_PACKED XINE_PACKED
+
#if defined(__GNUC__) || defined(__ICC)
#ifndef _EGCS_
-#define WINE_PACKED __attribute__((packed))
#define WINE_UNUSED __attribute__((unused))
#define WINE_NORETURN __attribute__((noreturn))
#endif
#else
-#define WINE_PACKED /* nothing */
#define WINE_UNUSED /* nothing */
#define WINE_NORETURN /* nothing */
#endif
diff --git a/src/libxineadec/Makefile.am b/src/libxineadec/Makefile.am
index b2ffcf078..5545a44d0 100644
--- a/src/libxineadec/Makefile.am
+++ b/src/libxineadec/Makefile.am
@@ -1,42 +1,77 @@
include $(top_srcdir)/misc/Makefile.common
-EXTRA_DIST = fooaudio.c
-
-SUBDIRS = gsm610 nosefart
-
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
AM_LDFLAGS = $(xineplug_ldflags)
-if HAVE_VORBIS
+EXTRA_DIST = fooaudio.c
+
+if ENABLE_VORBIS
vorbis_module = xineplug_decode_vorbis.la
endif
-if HAVE_SPEEX
+if ENABLE_SPEEX
speex_module = xineplug_decode_speex.la
endif
+if ENABLE_MUSEPACK
+musepack_module = xineplug_decode_mpc.la
+endif
+
+if ENABLE_DTS
+dts_module = xineplug_decode_dts.la
+endif
+
+if ENABLE_MAD
+mad_module = xineplug_decode_mad.la
+endif
+
+$(top_builddir)/contrib/libmad/libmad.la:
+ $(MAKE) -C $(top_builddir)/contrib/libmad
+
+$(top_builddir)/contrib/libmpcdec/libmpcdec.la:
+ $(MAKE) -C $(top_builddir)/contrib/libmpcdec
+
+$(top_builddir)/contrib/libdca/libdca.la:
+ $(MAKE) -C $(top_builddir)/contrib/libdca
+
+$(top_builddir)/contrib/gsm610/libgsm610.la:
+ $(MAKE) -C $(top_builddir)/contrib/gsm610
+
xineplug_LTLIBRARIES = \
xineplug_decode_gsm610.la \
- xineplug_decode_nsf.la \
xineplug_decode_lpcm.la \
$(vorbis_module) \
- $(speex_module)
+ $(speex_module) \
+ $(musepack_module) \
+ $(dts_module) \
+ $(mad_module)
xineplug_decode_gsm610_la_SOURCES = gsm610.c
-xineplug_decode_gsm610_la_CFLAGS = $(VISIBILITY_FLAG)
-xineplug_decode_gsm610_la_LIBADD = $(XINE_LIB) gsm610/libgsm610.la
-
-xineplug_decode_nsf_la_SOURCES = nsf.c
-xineplug_decode_nsf_la_CFLAGS = $(VISIBILITY_FLAG) -DNSF_PLAYER -fno-strict-aliasing
-xineplug_decode_nsf_la_LIBADD = $(XINE_LIB) -lm nosefart/libnosefart.la
+xineplug_decode_gsm610_la_LIBADD = $(XINE_LIB) $(top_builddir)/contrib/gsm610/libgsm610.la
+xineplug_decode_gsm610_la_CPPFLAGS = -I$(top_srcdir)/contrib/gsm610
xineplug_decode_lpcm_la_SOURCES = xine_lpcm_decoder.c
-xineplug_decode_lpcm_la_CFLAGS = $(VISIBILITY_FLAG)
xineplug_decode_lpcm_la_LIBADD = $(XINE_LIB)
xineplug_decode_vorbis_la_SOURCES = xine_vorbis_decoder.c
xineplug_decode_vorbis_la_LIBADD = $(XINE_LIB) $(VORBIS_LIBS) $(OGG_LIBS)
-xineplug_decode_vorbis_la_CFLAGS = $(VISIBILITY_FLAG) $(VORBIS_CFLAGS)
+xineplug_decode_vorbis_la_CFLAGS = $(AM_CFLAGS) $(VORBIS_CFLAGS)
xineplug_decode_speex_la_SOURCES = xine_speex_decoder.c
xineplug_decode_speex_la_LIBADD = $(XINE_LIB) $(SPEEX_LIBS)
-xineplug_decode_speex_la_CFLAGS = $(VISIBILITY_FLAGS) $(SPEEX_CFLAGS)
+xineplug_decode_speex_la_CFLAGS = $(AM_CFLAGS) $(SPEEX_CFLAGS)
+
+xineplug_decode_mpc_la_SOURCES = xine_musepack_decoder.c
+xineplug_decode_mpc_la_DEPENDENCIES = $(MPCDEC_DEPS)
+xineplug_decode_mpc_la_LIBADD = $(XINE_LIB) $(MPCDEC_LIBS)
+xineplug_decode_mpc_la_CFLAGS = $(AM_CFLAGS) $(MPCDEC_CFLAGS)
+
+xineplug_decode_dts_la_SOURCES = xine_dts_decoder.c
+xineplug_decode_dts_la_DEPENDENCIES = $(LIBDTS_DEPS)
+xineplug_decode_dts_la_LIBADD = $(XINE_LIB) $(LIBDTS_LIBS)
+xineplug_decode_dts_la_CFLAGS = $(AM_CFLAGS) $(LIBDTS_CFLAGS)
+
+xineplug_decode_mad_la_SOURCES = xine_mad_decoder.c
+xineplug_decode_mad_la_DEPENDENCIES = $(LIBMAD_DEPS)
+xineplug_decode_mad_la_LIBADD = $(XINE_LIB) $(LIBMAD_LIBS)
+xineplug_decode_mad_la_CFLAGS = $(AM_CFLAGS) $(LIBMAD_CFLAGS)
diff --git a/src/libxineadec/gsm610.c b/src/libxineadec/gsm610.c
index 4f54714c9..e144c5bbf 100644
--- a/src/libxineadec/gsm610.c
+++ b/src/libxineadec/gsm610.c
@@ -61,8 +61,8 @@
#include "xineutils.h"
#include "bswap.h"
-#include "gsm610/private.h"
-#include "gsm610/gsm.h"
+#include "private.h"
+#include "gsm.h"
#define AUDIOBUFSIZE 128*1024
@@ -86,7 +86,6 @@ typedef struct gsm610_decoder_s {
int bufsize;
int size;
- unsigned short decode_buffer[GSM610_BLOCK_SIZE];
gsm gsm_state;
} gsm610_decoder_t;
@@ -138,6 +137,7 @@ static void gsm610_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) {
this->size += buf->size;
if (buf->decoder_flags & BUF_FLAG_FRAME_END) { /* time to decode a frame */
+ int16_t decode_buffer[GSM610_BLOCK_SIZE];
/* handle the Microsoft variant of GSM data */
if (this->buf_type == BUF_AUDIO_MSGSM) {
@@ -154,7 +154,7 @@ static void gsm610_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) {
in_ptr = 0;
while (this->size) {
- gsm_decode(this->gsm_state, &this->buf[in_ptr], this->decode_buffer);
+ gsm_decode(this->gsm_state, &this->buf[in_ptr], decode_buffer);
if ((in_ptr % 65) == 0) {
in_ptr += 33;
this->size -= 33;
@@ -167,7 +167,7 @@ static void gsm610_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) {
* always contain at least 160 samples */
audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out);
- xine_fast_memcpy(audio_buffer->mem, this->decode_buffer,
+ xine_fast_memcpy(audio_buffer->mem, decode_buffer,
GSM610_BLOCK_SIZE * 2);
audio_buffer->num_frames = GSM610_BLOCK_SIZE;
@@ -189,7 +189,7 @@ static void gsm610_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) {
in_ptr = 0;
while (this->size) {
- gsm_decode(this->gsm_state, &this->buf[in_ptr], this->decode_buffer);
+ gsm_decode(this->gsm_state, &this->buf[in_ptr], decode_buffer);
in_ptr += 33;
this->size -= 33;
@@ -197,7 +197,7 @@ static void gsm610_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) {
* always contain at least 160 samples */
audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out);
- xine_fast_memcpy(audio_buffer->mem, this->decode_buffer,
+ xine_fast_memcpy(audio_buffer->mem, decode_buffer,
GSM610_BLOCK_SIZE * 2);
audio_buffer->num_frames = GSM610_BLOCK_SIZE;
diff --git a/src/libxineadec/gsm610/Makefile.am b/src/libxineadec/gsm610/Makefile.am
deleted file mode 100644
index fe25ad9c3..000000000
--- a/src/libxineadec/gsm610/Makefile.am
+++ /dev/null
@@ -1,25 +0,0 @@
-include $(top_srcdir)/misc/Makefile.common
-
-noinst_LTLIBRARIES = libgsm610.la
-
-libgsm610_la_SOURCES = \
- add.c \
- decode.c \
- gsm_create.c \
- gsm_decode.c \
- gsm_destroy.c \
- long_term.c \
- lpc.c \
- rpe.c \
- short_term.c \
- table.c
-
-libgsm610_la_CFLAGS = $(VISIBILITY_FLAG)
-libgsm610_la_LDFLAGS = -avoid-version -module
-
-noinst_HEADERS = \
- gsm_config.h \
- gsm.h \
- private.h \
- proto.h \
- unproto.h
diff --git a/src/libxineadec/nosefart/Makefile.am b/src/libxineadec/nosefart/Makefile.am
deleted file mode 100644
index 51cc3f238..000000000
--- a/src/libxineadec/nosefart/Makefile.am
+++ /dev/null
@@ -1,34 +0,0 @@
-include $(top_srcdir)/misc/Makefile.common
-
-noinst_LTLIBRARIES = libnosefart.la
-
-libnosefart_la_SOURCES = \
- fds_snd.c \
- log.c \
- mmc5_snd.c \
- nes_apu.c \
- vrc7_snd.c \
- dis6502.c \
- fmopl.c \
- memguard.c \
- nes6502.c \
- nsf.c \
- vrcvisnd.c
-
-libnosefart_la_CFLAGS = $(VISIBILITY_FLAG) -DNSF_PLAYER -fno-strict-aliasing
-
-noinst_HEADERS = \
- dis6502.h \
- fmopl.h \
- memguard.h \
- nes6502.h \
- nsf.h \
- types.h \
- vrc7_snd.h \
- fds_snd.h \
- log.h \
- mmc5_snd.h \
- nes_apu.h \
- osd.h \
- version.h \
- vrcvisnd.h
diff --git a/src/libxineadec/nosefart/diff_to_nosefart_cvs.patch b/src/libxineadec/nosefart/diff_to_nosefart_cvs.patch
deleted file mode 100644
index 280cd89cb..000000000
--- a/src/libxineadec/nosefart/diff_to_nosefart_cvs.patch
+++ /dev/null
@@ -1,75 +0,0 @@
-diff -u -p -r1.1.1.1 types.h
---- types.h 26 Jul 2004 15:27:59 -0000 1.1.1.1
-+++ types.h 26 Aug 2004 16:00:07 -0000
-@@ -23,8 +23,8 @@
- ** $Id: diff_to_nosefart_cvs.patch,v 1.2 2005/05/07 09:11:39 valtri Exp $
- */
-
--#ifndef _TYPES_H_
--#define _TYPES_H_
-+#ifndef _NOSEFART_TYPES_H_
-+#define _NOSEFART_TYPES_H_
-
- #ifdef HAVE_CONFIG_H
- #include "config.h"
-@@ -88,7 +88,7 @@ typedef uint8 boolean;
- #define ASSERT_MSG(msg)
- #endif
-
--#endif /* _TYPES_H_ */
-+#endif /* _NOSEFART_TYPES_H_ */
-
- /*
- ** $Log: diff_to_nosefart_cvs.patch,v $
- ** Revision 1.2 2005/05/07 09:11:39 valtri
- ** *BUGFIX*
- ** gcc4 patches from Dams Nadé (livna.org) and Keenan Pepper.
- **
- ** Revision 1.1 2004/08/27 19:33:37 valtri
- ** MINGW32 port. Engine library and most of plugins compiles now.
- **
- ** List of some changes:
- ** - replaced some _MSC_VER by more common WIN32
- ** - define INTLDIR, remove -static flag for included intl
- ** - shared more common CFLAGS with DEBUG_CFLAGS
- ** - use WIN32_CFLAGS for all building
- ** - separate some flags into THREAD_CFLAGS_CONFIG,
- ** THREAD_CFLAGS_CONFIG and ZLIB_LIB_CONFIG for public xine-config,
- ** automatically use internal libs if necessary
- ** - don't warn about missing X for mingw and cygwin
- ** - libw32dll disabled for WIN32 (making native loader would be
- ** interesting, or porting wine code to Windows? :->)
- ** - DVB and RTP disabled for WIN32, not ported yet
- ** - fix build and fix a warning in cdda
- ** - fix build for nosefart and libfaad
- ** - implement configure option --disable-freetype
- ** - sync libxine.pc and xine-config.in
- ** - add -liberty to goom under WIN32
- ** - move original build files from included phread and zlib into archives
- ** and replace them by autotools
- **
-Index: nes_apu.c
-===================================================================
-RCS file: /home/valtri/CVS/xine-lib/src/libxineadec/nosefart/nes_apu.c,v
-retrieving revision 1.1.1.1
-diff -u -p -r1.1.1.1 nes_apu.c
---- nes_apu.c 12 Dec 2004 13:57:16 -0000 1.1.1.1
-+++ nes_apu.c 7 May 2005 08:23:36 -0000
-@@ -1011,10 +1011,13 @@ void apu_process(void *buffer, int num_s
- accum = -0x8000;
-
- /* signed 16-bit output, unsigned 8-bit */
-- if (16 == apu->sample_bits)
-- *((int16 *) buffer)++ = (int16) accum;
-- else
-- *((uint8 *) buffer)++ = (accum >> 8) ^ 0x80;
-+ if (16 == apu->sample_bits) {
-+ *((int16 *) buffer) = (int16) accum;
-+ buffer = (int16 *) buffer + 1;
-+ } else {
-+ *((uint8 *) buffer) = (accum >> 8) ^ 0x80;
-+ buffer = (int8 *) buffer + 1;
-+ }
- }
-
- /* resync cycle counter */
diff --git a/src/libxineadec/nosefart/nsf.h b/src/libxineadec/nosefart/nsf.h
deleted file mode 100644
index 163e2f62f..000000000
--- a/src/libxineadec/nosefart/nsf.h
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
-** Nofrendo (c) 1998-2000 Matthew Conte (matt@conte.com)
-**
-**
-** This program is free software; you can redistribute it and/or
-** modify it under the terms of version 2 of the GNU Library General
-** Public License as published by the Free Software Foundation.
-**
-** This program is distributed in the hope that it will be useful,
-** but WITHOUT ANY WARRANTY; without even the implied warranty of
-** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-** Library General Public License for more details. To obtain a
-** copy of the GNU Library General Public License, write to the Free
-** Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-**
-** Any permitted reproduction of these routines, in whole or in part,
-** must bear this legend.
-**
-**
-** nsf.h
-**
-** NSF loading/saving related defines / prototypes
-** $Id: nsf.h,v 1.3 2007/01/18 21:34:10 dgp85 Exp $
-*/
-
-#ifndef _NSF_H_
-#define _NSF_H_
-
-#include "osd.h"
-#include "nes6502.h"
-#include "nes_apu.h"
-
-#define NSF_MAGIC "NESM\x1A"
-
-#define NSF_DEDICATED_PAL 0x01
-#define NSF_DUAL_PAL_NTSC 0x02
-
-#define EXT_SOUND_NONE 0x00
-#define EXT_SOUND_VRCVI 0x01
-#define EXT_SOUND_VRCVII 0x02
-#define EXT_SOUND_FDS 0x04
-#define EXT_SOUND_MMC5 0x08
-#define EXT_SOUND_NAMCO106 0x10
-#define EXT_SOUND_SUNSOFT_FME07 0x20
-/* bits 6,7: future expansion */
-
-#define NSF_HEADER_SIZE 0x80
-
-/* 60 Hertz refresh (NTSC) */
-#define NES_MASTER_CLOCK 21477272.7272
-#define NTSC_REFRESH 60
-#define NTSC_SUBCARRIER_DIV 12
-#define NTSC_SCANLINES 262
-
-#define NES_FRAME_CYCLES ((NES_MASTER_CLOCK / NTSC_SUBCARRIER_DIV) / NTSC_REFRESH)
-#define NES_SCANLINE_CYCLES (NES_FRAME_CYCLES / NTSC_SCANLINES)
-
-/* filter levels */
-enum
-{
- NSF_FILTER_NONE,
- NSF_FILTER_LOWPASS,
- NSF_FILTER_WEIGHTED
-};
-
-typedef struct nsf_s
-{
- /* NESM header */
- uint8 id[5]; /* NESM\x1A */
- uint8 version; /* spec version */
- uint8 num_songs; /* total num songs */
- uint8 start_song; /* first song */
- uint16 load_addr; /* loc to load code */
- uint16 init_addr; /* init call address */
- uint16 play_addr; /* play call address */
- uint8 song_name[32]; /* name of song */
- uint8 artist_name[32]; /* artist name */
- uint8 copyright[32]; /* copyright info */
- uint16 ntsc_speed; /* playback speed (if NTSC) */
- uint8 bankswitch_info[8]; /* initial code banking */
- uint16 pal_speed; /* playback speed (if PAL) */
- uint8 pal_ntsc_bits; /* NTSC/PAL determination bits */
- uint8 ext_sound_type; /* type of external sound gen. */
- uint8 reserved[4]; /* reserved */
-
- /* things that the NSF player needs */
- uint8 *data; /* actual NSF data */
- uint32 length; /* length of data */
- uint32 playback_rate; /* current playback rate */
- uint8 current_song; /* current song */
- boolean bankswitched; /* is bankswitched? */
-
- /* CPU and APU contexts */
- nes6502_context *cpu;
- apu_t *apu;
-
- /* our main processing routine, calls all external mixing routines */
- void (*process)(void *buffer, int num_samples);
-} __PACKED__ nsf_t;
-
-/* Function prototypes */
-extern void nsf_init(void);
-
-extern nsf_t *nsf_load(char *filename, void *source, int length);
-extern void nsf_free(nsf_t **nsf_info);
-
-extern void nsf_playtrack(nsf_t *nsf, int track, int sample_rate, int sample_bits,
- boolean stereo);
-extern void nsf_frame(nsf_t *nsf);
-extern void nsf_setchan(nsf_t *nsf, int chan, boolean enabled);
-extern void nsf_setfilter(nsf_t *nsf, int filter_type);
-
-#endif /* _NSF_H_ */
-
-/*
-** $Log: nsf.h,v $
-** Revision 1.3 2007/01/18 21:34:10 dgp85
-** __attribute__(packed) is used on the struct, not on its members.
-**
-** Revision 1.2 2003/12/05 15:55:01 f1rmb
-** cleanup phase II. use xprintf when it's relevant, use xine_xmalloc when it's relevant too. Small other little fix (can't remember). Change few internal function prototype because it xine_t pointer need to be used if some xine's internal sections. NOTE: libdvd{nav,read} is still too noisy, i will take a look to made it quit, without invasive changes. To be continued...
-**
-** Revision 1.1 2003/01/08 07:04:35 tmmm
-** initial import of Nosefart sources
-**
-** Revision 1.11 2000/07/04 04:59:24 matt
-** removed DOS-specific stuff
-**
-** Revision 1.10 2000/07/03 02:19:36 matt
-** dynamic address range handlers, cleaner and faster
-**
-** Revision 1.9 2000/06/23 03:27:58 matt
-** cleaned up external sound inteface
-**
-** Revision 1.8 2000/06/20 04:04:37 matt
-** moved external soundchip struct to apu module
-**
-** Revision 1.7 2000/06/20 00:05:45 matt
-** changed to driver-based external sound generation
-**
-** Revision 1.6 2000/06/13 03:51:54 matt
-** update API to take freq/sample data on nsf_playtrack
-**
-** Revision 1.5 2000/06/12 01:13:00 matt
-** added CPU/APU as members of the nsf struct
-**
-** Revision 1.4 2000/06/09 15:12:26 matt
-** initial revision
-**
-*/
diff --git a/src/libxineadec/nosefart/osd.h b/src/libxineadec/nosefart/osd.h
deleted file mode 100644
index ee90aa972..000000000
--- a/src/libxineadec/nosefart/osd.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
-** Nofrendo (c) 1998-2000 Matthew Conte (matt@conte.com)
-**
-**
-** This program is free software; you can redistribute it and/or
-** modify it under the terms of version 2 of the GNU Library General
-** Public License as published by the Free Software Foundation.
-**
-** This program is distributed in the hope that it will be useful,
-** but WITHOUT ANY WARRANTY; without even the implied warranty of
-** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-** Library General Public License for more details. To obtain a
-** copy of the GNU Library General Public License, write to the Free
-** Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-**
-** Any permitted reproduction of these routines, in whole or in part,
-** must bear this legend.
-**
-**
-** osd.h
-**
-** O/S dependent routine defintions (must be customized)
-** $Id: osd.h,v 1.2 2003/07/12 12:31:14 mroi Exp $
-*/
-
-#ifndef _OSD_H_
-#define _OSD_H_
-
-
-#if defined(__GNUC__) || defined(__ICC)
-#define __PACKED__ __attribute__ ((packed))
-#define PATH_SEP '/'
-#ifdef __DJGPP__
-#include <dpmi.h>
-#include "dos_ints.h"
-#endif
-#elif defined(WIN32)
-#define __PACKED__
-#define PATH_SEP '\\'
-#else /* crapintosh? */
-#define __PACKED__
-#define PATH_SEP ':'
-#endif
-
-extern void osd_loginit(void);
-extern void osd_logshutdown(void);
-extern void osd_logprint(const char *string);
-
-extern int osd_startsound(void (*playfunc)(void *buffer, int size));
-extern int osd_getsoundbps(void);
-extern int osd_getsamplerate(void);
-
-
-#ifndef NSF_PLAYER
-#include "rgb.h"
-#include "bitmap.h"
-
-extern bitmap_t *osd_getvidbuf(void);
-typedef void (*blitproc_t)(bitmap_t *bmp, int x_pos, int y_pos, int width, int height);
-extern blitproc_t osd_blit;
-extern void osd_copytoscreen(void);
-
-extern void osd_showusage(char *filename);
-extern void osd_fullname(char *fullname, const char *shortname);
-extern char *osd_newextension(char *string, char *ext);
-
-extern void osd_setpalette(rgb_t *pal);
-extern void osd_restorepalette(void);
-
-extern void osd_getinput(void);
-extern int osd_gethostinput(void);
-extern void osd_getmouse(int *x, int *y, int *button);
-
-extern int osd_init(void);
-extern void osd_shutdown(void);
-#endif /* !NSF_PLAYER */
-
-#endif /* _OSD_H_ */
-
-/*
-** $Log: osd.h,v $
-** Revision 1.2 2003/07/12 12:31:14 mroi
-** - adding support for the Intel compiler icc
-** - general multipass compilation make targets
-**
-** Revision 1.1 2003/01/08 07:04:35 tmmm
-** initial import of Nosefart sources
-**
-** Revision 1.7 2000/07/04 04:45:33 matt
-** moved INLINE define into types.h
-**
-** Revision 1.6 2000/06/29 16:06:18 neil
-** Wrapped DOS-specific headers in an ifdef
-**
-** Revision 1.5 2000/06/09 15:12:25 matt
-** initial revision
-**
-*/
diff --git a/src/libxineadec/nsf.c b/src/libxineadec/nsf.c
deleted file mode 100644
index e646ca873..000000000
--- a/src/libxineadec/nsf.c
+++ /dev/null
@@ -1,295 +0,0 @@
-/*
- * Copyright (C) 2000-2001 the xine project
- *
- * This file is part of xine, a free video player.
- *
- * xine 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.
- *
- * xine is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- *
- * NSF Audio "Decoder" using the Nosefart NSF engine by Matt Conte
- * http://www.baisoku.org/
- *
- * $Id: nsf.c,v 1.13 2006/09/25 23:56:31 dgp85 Exp $
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include "xine_internal.h"
-#include "audio_out.h"
-#include "buffer.h"
-#include "xineutils.h"
-#include "bswap.h"
-
-/* Nosefart includes */
-#include "nosefart/types.h"
-#include "nosefart/nsf.h"
-
-typedef struct {
- audio_decoder_class_t decoder_class;
-} nsf_class_t;
-
-typedef struct nsf_decoder_s {
- audio_decoder_t audio_decoder;
-
- xine_stream_t *stream;
-
- int sample_rate; /* audio sample rate */
- int bits_per_sample; /* bits/sample, usually 8 or 16 */
- int channels; /* 1 or 2, usually */
-
- int output_open; /* flag to indicate audio is ready */
-
- int nsf_size;
- unsigned char *nsf_file;
- int nsf_index;
- int song_number;
-
- /* nsf-specific variables */
- int64_t last_pts;
- unsigned int iteration;
-
- nsf_t *nsf;
-} nsf_decoder_t;
-
-/**************************************************************************
- * xine audio plugin functions
- *************************************************************************/
-
-static void nsf_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) {
-
- nsf_decoder_t *this = (nsf_decoder_t *) this_gen;
- audio_buffer_t *audio_buffer;
-
- if (buf->decoder_flags & BUF_FLAG_HEADER) {
-
- /* When the engine sends a BUF_FLAG_HEADER flag, it is time to initialize
- * the decoder. The buffer element type has 4 decoder_info fields,
- * 0..3. Field 1 is the sample rate. Field 2 is the bits/sample. Field
- * 3 is the number of channels. */
- this->sample_rate = buf->decoder_info[1];
- this->bits_per_sample = buf->decoder_info[2];
- this->channels = buf->decoder_info[3];
-
- /* take this opportunity to initialize stream/meta information */
- _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC,
- "NES Music (Nosefart)");
-
- this->song_number = buf->content[4];
- /* allocate a buffer for the file */
- this->nsf_size = BE_32(&buf->content[0]);
- this->nsf_file = xine_xmalloc(this->nsf_size);
- this->nsf_index = 0;
-
- /* peform any other required initialization */
- this->last_pts = -1;
- this->iteration = 0;
-
- return;
- }
-
- /* accumulate chunks from the NSF file until whole file is received */
- if (this->nsf_index < this->nsf_size) {
- xine_fast_memcpy(&this->nsf_file[this->nsf_index], buf->content,
- buf->size);
- this->nsf_index += buf->size;
-
- if (this->nsf_index == this->nsf_size) {
- /* file has been received, proceed to initialize engine */
- nsf_init();
- this->nsf = nsf_load(NULL, this->nsf_file, this->nsf_size);
- if (!this->nsf) {
- xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "nsf: could not initialize NSF\n");
- /* make the decoder return on every subsequent buffer */
- this->nsf_index = 0;
- return;
- }
- this->nsf->current_song = this->song_number;
- nsf_playtrack(this->nsf, this->nsf->current_song, this->sample_rate,
- this->bits_per_sample, this->channels);
- }
- return;
- }
-
- /* if the audio output is not open yet, open the audio output */
- if (!this->output_open) {
- this->output_open = this->stream->audio_out->open(
- this->stream->audio_out,
- this->stream,
- this->bits_per_sample,
- this->sample_rate,
- _x_ao_channels2mode(this->channels));
- }
-
- /* if the audio still isn't open, do not go any further with the decode */
- if (!this->output_open)
- return;
-
- /* check if a song change was requested */
- if (buf->decoder_info[1]) {
- this->nsf->current_song = buf->decoder_info[1];
- nsf_playtrack(this->nsf, this->nsf->current_song, this->sample_rate,
- this->bits_per_sample, this->channels);
- }
-
- /* time to decode a frame */
- if (this->last_pts != -1) {
-
- /* process a frame */
- nsf_frame(this->nsf);
-
- /* get an audio buffer */
- audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out);
- if (audio_buffer->mem_size == 0) {
- xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "nsf: Help! Allocated audio buffer with nothing in it!\n");
- return;
- }
-
- apu_process(audio_buffer->mem, this->sample_rate / this->nsf->playback_rate);
- audio_buffer->vpts = buf->pts;
- audio_buffer->num_frames = this->sample_rate / this->nsf->playback_rate;
- this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream);
- }
- this->last_pts = buf->pts;
-}
-
-/* This function resets the state of the audio decoder. This usually
- * entails resetting the data accumulation buffer. */
-static void nsf_reset (audio_decoder_t *this_gen) {
-
- nsf_decoder_t *this = (nsf_decoder_t *) this_gen;
-
- this->last_pts = -1;
-}
-
-/* This function resets the last pts value of the audio decoder. */
-static void nsf_discontinuity (audio_decoder_t *this_gen) {
-
- nsf_decoder_t *this = (nsf_decoder_t *) this_gen;
-
- this->last_pts = -1;
-}
-
-/* This function closes the audio output and frees the private audio decoder
- * structure. */
-static void nsf_dispose (audio_decoder_t *this_gen) {
-
- nsf_decoder_t *this = (nsf_decoder_t *) this_gen;
-
- /* close the audio output */
- if (this->output_open)
- this->stream->audio_out->close (this->stream->audio_out, this->stream);
- this->output_open = 0;
-
- /* free anything that was allocated during operation */
- nsf_free(&this->nsf);
- free(this->nsf_file);
- free(this);
-}
-
-/* This function allocates, initializes, and returns a private audio
- * decoder structure. */
-static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) {
-
- nsf_decoder_t *this ;
-
- this = (nsf_decoder_t *) xine_xmalloc (sizeof (nsf_decoder_t));
-
- /* connect the member functions */
- this->audio_decoder.decode_data = nsf_decode_data;
- this->audio_decoder.reset = nsf_reset;
- this->audio_decoder.discontinuity = nsf_discontinuity;
- this->audio_decoder.dispose = nsf_dispose;
-
- /* connect the stream */
- this->stream = stream;
-
- /* audio output is not open at the start */
- this->output_open = 0;
-
- /* initialize the basic audio parameters */
- this->channels = 0;
- this->sample_rate = 0;
- this->bits_per_sample = 0;
-
- /* return the newly-initialized audio decoder */
- return &this->audio_decoder;
-}
-
-/* This function returns a brief string that describes (usually with the
- * decoder's most basic name) the audio decoder plugin. */
-static char *get_identifier (audio_decoder_class_t *this) {
- return "NSF";
-}
-
-/* This function returns a slightly longer string describing the audio
- * decoder plugin. */
-static char *get_description (audio_decoder_class_t *this) {
- return "NES Music audio decoder plugin";
-}
-
-/* This function frees the audio decoder class and any other memory that was
- * allocated. */
-static void dispose_class (audio_decoder_class_t *this_gen) {
-
- nsf_class_t *this = (nsf_class_t *)this_gen;
-
- free (this);
-}
-
-/* This function allocates a private audio decoder class and initializes
- * the class's member functions. */
-static void *init_plugin (xine_t *xine, void *data) {
-
- nsf_class_t *this ;
-
- this = (nsf_class_t *) xine_xmalloc (sizeof (nsf_class_t));
-
- this->decoder_class.open_plugin = open_plugin;
- this->decoder_class.get_identifier = get_identifier;
- this->decoder_class.get_description = get_description;
- this->decoder_class.dispose = dispose_class;
-
- return this;
-}
-
-/* This is a list of all of the internal xine audio buffer types that
- * this decoder is able to handle. Check src/xine-engine/buffer.h for a
- * list of valid buffer types (and add a new one if the one you need does
- * not exist). Terminate the list with a 0. */
-static uint32_t audio_types[] = {
- BUF_AUDIO_NSF,
- 0
-};
-
-/* This data structure combines the list of supported xine buffer types and
- * the priority that the plugin should be given with respect to other
- * plugins that handle the same buffer type. A plugin with priority (n+1)
- * will be used instead of a plugin with priority (n). */
-static const decoder_info_t dec_info_audio = {
- audio_types, /* supported types */
- 5 /* priority */
-};
-
-/* The plugin catalog entry. This is the only information that this plugin
- * will export to the public. */
-const plugin_info_t xine_plugin_info[] EXPORTED = {
- /* { type, API version, "name", version, special_info, init_function }, */
- { PLUGIN_AUDIO_DECODER, 15, "nsf", XINE_VERSION_CODE, &dec_info_audio, &init_plugin },
- { PLUGIN_NONE, 0, "", 0, NULL, NULL }
-};
-
diff --git a/src/libxineadec/xine_dts_decoder.c b/src/libxineadec/xine_dts_decoder.c
new file mode 100644
index 000000000..000adaa85
--- /dev/null
+++ b/src/libxineadec/xine_dts_decoder.c
@@ -0,0 +1,592 @@
+/*
+ * Copyright (C) 2000-2007 the xine project
+ *
+ * This file is part of xine, a unix video player.
+ *
+ * xine 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.
+ *
+ * xine is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+/**
+ * @file
+ * @brief DTS decoder for xine
+ *
+ * @author Joachim Koenig (2001-09-04)
+ * @author James Courtier-Dutton (2001-12-09)
+ */
+
+#ifndef __sun
+/* required for swab() */
+#define _XOPEN_SOURCE 500
+#endif
+/* avoid compiler warnings */
+#define _BSD_SOURCE 1
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <assert.h>
+
+#define LOG_MODULE "libdts"
+#define LOG_VERBOSE
+/*
+#define LOG
+*/
+
+#include "xine_internal.h"
+#include "xineutils.h"
+#include "audio_out.h"
+#include "buffer.h"
+
+#include "bswap.h"
+
+#include <dts.h>
+
+#define MAX_AC5_FRAME 4096
+
+typedef struct {
+ audio_decoder_class_t decoder_class;
+} dts_class_t;
+
+typedef struct {
+ audio_decoder_t audio_decoder;
+
+ xine_stream_t *stream;
+ audio_decoder_class_t *class;
+
+ dts_state_t *dts_state;
+ int64_t pts;
+
+ int audio_caps;
+ int sync_state;
+ int ac5_length, ac5_pcm_length, frame_todo;
+ uint32_t syncdword;
+ uint8_t frame_buffer[MAX_AC5_FRAME];
+ uint8_t *frame_ptr;
+
+ int output_open;
+
+ int bypass_mode;
+ int dts_flags;
+ int dts_sample_rate;
+ int dts_bit_rate;
+ int dts_flags_map[11]; /* Convert from stream dts_flags to the dts_flags we want from the dts downmixer */
+ int ao_flags_map[11]; /* Convert from the xine AO_CAP's to dts_flags. */
+ int have_lfe;
+
+
+} dts_decoder_t;
+
+static void dts_reset (audio_decoder_t *const this_gen) {
+}
+
+static void dts_discontinuity (audio_decoder_t *const this_gen) {
+}
+
+/**
+ * @brief Convert a array of floating point samples into 16-bit signed integer samples
+ * @param f Floating point samples array (origin)
+ * @param s16 16-bit signed integer samples array (destination)
+ * @param num_channels Number of channels present in the stream
+ *
+ * @todo This same work is being done in many decoders to adapt the output of
+ * the decoder to what the audio output can actually use, this should be
+ * done by the audio_output loop, not by the decoders.
+ * @note This is subtly different from the function with the same name in xine_musepack_decoder.c
+ */
+static inline void float_to_int (const float *const _f, int16_t *const s16, const int num_channels) {
+ const int endidx = 256 * num_channels;
+ int i, j;
+
+ for (i = 0, j = 0; j < endidx; i++, j += num_channels) {
+ const float f = _f[i] * 32767;
+ if (f > INT16_MAX)
+ s16[j] = INT16_MAX;
+ else if (f < INT16_MIN)
+ s16[j] = INT16_MIN;
+ else
+ s16[j] = f;
+ /* printf("samples[%d] = %f, %d\n", i, _f[i], s16[num_channels*i]); */
+ }
+}
+
+static inline void mute_channel (int16_t *const s16, const int num_channels) {
+ const int endidx = 256 * num_channels;
+ int i;
+
+ for (i = 0; i < endidx; i += num_channels)
+ s16[i] = 0;
+}
+
+static void dts_decode_frame (dts_decoder_t *this, const int64_t pts, const int preview_mode) {
+
+ audio_buffer_t *audio_buffer;
+ uint32_t ac5_spdif_type=0;
+ int output_mode = AO_CAP_MODE_STEREO;
+ uint8_t *data_out;
+ uint8_t *const data_in = this->frame_buffer;
+
+ lprintf("decode_frame\n");
+ audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out);
+ audio_buffer->vpts = pts;
+
+ if(this->bypass_mode) {
+ /* SPDIF digital output */
+ if (!this->output_open) {
+ this->output_open = (this->stream->audio_out->open (this->stream->audio_out, this->stream,
+ 16, this->dts_sample_rate,
+ AO_CAP_MODE_AC5));
+ }
+
+ if (!this->output_open)
+ return;
+
+ data_out=(uint8_t *) audio_buffer->mem;
+ if (this->ac5_length > 8191) {
+ xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "libdts: ac5_length too long\n");
+ this->ac5_pcm_length = 0;
+ }
+
+ switch (this->ac5_pcm_length) {
+ case 512:
+ ac5_spdif_type = 0x0b; /* DTS-1 (512-sample bursts) */
+ break;
+ case 1024:
+ ac5_spdif_type = 0x0c; /* DTS-1 (1024-sample bursts) */
+ break;
+ case 2048:
+ ac5_spdif_type = 0x0d; /* DTS-1 (2048-sample bursts) */
+ break;
+ default:
+ xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG,
+ "libdts: DTS %i-sample bursts not supported\n", this->ac5_pcm_length);
+ return;
+ }
+
+#ifdef LOG_DEBUG
+ {
+ int i;
+ printf("libdts: DTS frame type=%d\n",data_in[4] >> 7);
+ printf("libdts: DTS deficit frame count=%d\n",(data_in[4] & 0x7f) >> 2);
+ printf("libdts: DTS AC5 PCM samples=%d\n",ac5_pcm_samples);
+ printf("libdts: DTS AC5 length=%d\n",this->ac5_length);
+ printf("libdts: DTS AC5 bitrate=%d\n",((data_in[8] & 0x03) << 4) | (data_in[8] >> 4));
+ printf("libdts: DTS AC5 spdif type=%d\n", ac5_spdif_type);
+
+ printf("libdts: ");
+ for(i=2000;i<2048;i++) {
+ printf("%02x ",data_in[i]);
+ }
+ printf("\n");
+ }
+#endif
+
+ lprintf("length=%d pts=%"PRId64"\n",this->ac5_pcm_length,audio_buffer->vpts);
+
+ audio_buffer->num_frames = this->ac5_pcm_length;
+
+ data_out[0] = 0x72; data_out[1] = 0xf8; /* spdif syncword */
+ data_out[2] = 0x1f; data_out[3] = 0x4e; /* .............. */
+ data_out[4] = ac5_spdif_type; /* DTS data */
+ data_out[5] = 0; /* Unknown */
+ data_out[6] = (this->ac5_length << 3) & 0xff; /* ac5_length * 8 */
+ data_out[7] = ((this->ac5_length ) >> 5) & 0xff;
+
+ if( this->ac5_pcm_length ) {
+ if( this->ac5_pcm_length % 2) {
+ swab(data_in, &data_out[8], this->ac5_length );
+ } else {
+ swab(data_in, &data_out[8], this->ac5_length + 1);
+ }
+ }
+ } else {
+ /* Software decode */
+ int i, dts_output_flags;
+ int16_t *const int_samples = audio_buffer->mem;
+ int number_of_dts_blocks;
+
+ level_t level = 1.0;
+ sample_t *samples;
+
+ dts_output_flags = this->dts_flags_map[this->dts_flags & DTS_CHANNEL_MASK];
+
+ if(dts_frame(this->dts_state, data_in, &dts_output_flags, &level, 0)) {
+ xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libdts: dts_frame error\n");
+ return;
+ }
+
+ this->have_lfe = dts_output_flags & DTS_LFE;
+ if (this->have_lfe)
+ if (this->audio_caps & AO_CAP_MODE_5_1CHANNEL) {
+ output_mode = AO_CAP_MODE_5_1CHANNEL;
+ } else if (this->audio_caps & AO_CAP_MODE_4_1CHANNEL) {
+ output_mode = AO_CAP_MODE_4_1CHANNEL;
+ } else {
+ xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "libdts: WHAT DO I DO!!!\n");
+ output_mode = this->ao_flags_map[dts_output_flags & DTS_CHANNEL_MASK];
+ }
+ else
+ output_mode = this->ao_flags_map[dts_output_flags & DTS_CHANNEL_MASK];
+
+ if (!this->output_open) {
+ this->output_open = this->stream->audio_out->open (this->stream->audio_out, this->stream,
+ 16, this->dts_sample_rate,
+ output_mode);
+ }
+
+ if (!this->output_open)
+ return;
+ number_of_dts_blocks = dts_blocks_num (this->dts_state);
+ audio_buffer->num_frames = 256*number_of_dts_blocks;
+ for(i = 0; i < number_of_dts_blocks; i++) {
+ if(dts_block(this->dts_state)) {
+ xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG,
+ "libdts: dts_block error on audio channel %d\n", i);
+ audio_buffer->num_frames = 0;
+ break;
+ }
+
+ samples = dts_samples(this->dts_state);
+ switch (output_mode) {
+ case AO_CAP_MODE_MONO:
+ float_to_int (&samples[0], int_samples+(i*256), 1);
+ break;
+ case AO_CAP_MODE_STEREO:
+ /* Tested, working. */
+ float_to_int (&samples[0*256], int_samples+(i*256*2), 2); /* L */
+ float_to_int (&samples[1*256], int_samples+(i*256*2)+1, 2); /* R */
+ break;
+ case AO_CAP_MODE_4CHANNEL:
+ /* Tested, working */
+ float_to_int (&samples[0*256], int_samples+(i*256*4), 4); /* L */
+ float_to_int (&samples[1*256], int_samples+(i*256*4)+1, 4); /* R */
+ float_to_int (&samples[2*256], int_samples+(i*256*4)+2, 4); /* RL */
+ float_to_int (&samples[3*256], int_samples+(i*256*4)+3, 4); /* RR */
+ break;
+ case AO_CAP_MODE_4_1CHANNEL:
+ /* Tested, working */
+ float_to_int (&samples[0*256], int_samples+(i*256*6)+0, 6); /* L */
+ float_to_int (&samples[1*256], int_samples+(i*256*6)+1, 6); /* R */
+ float_to_int (&samples[2*256], int_samples+(i*256*6)+2, 6); /* RL */
+ float_to_int (&samples[3*256], int_samples+(i*256*6)+3, 6); /* RR */
+ float_to_int (&samples[4*256], int_samples+(i*256*6)+5, 6); /* LFE */
+ mute_channel ( int_samples+(i*256*6)+4, 6); /* C */
+ break;
+ case AO_CAP_MODE_5CHANNEL:
+ /* Tested, working */
+ float_to_int (&samples[0*256], int_samples+(i*256*6)+4, 6); /* C */
+ float_to_int (&samples[1*256], int_samples+(i*256*6)+0, 6); /* L */
+ float_to_int (&samples[2*256], int_samples+(i*256*6)+1, 6); /* R */
+ float_to_int (&samples[3*256], int_samples+(i*256*6)+2, 6); /* RL */
+ float_to_int (&samples[4*256], int_samples+(i*256*6)+3, 6); /* RR */
+ mute_channel ( int_samples+(i*256*6)+5, 6); /* LFE */
+ break;
+ case AO_CAP_MODE_5_1CHANNEL:
+ float_to_int (&samples[0*256], int_samples+(i*256*6)+4, 6); /* C */
+ float_to_int (&samples[1*256], int_samples+(i*256*6)+0, 6); /* L */
+ float_to_int (&samples[2*256], int_samples+(i*256*6)+1, 6); /* R */
+ float_to_int (&samples[3*256], int_samples+(i*256*6)+2, 6); /* RL */
+ float_to_int (&samples[4*256], int_samples+(i*256*6)+3, 6); /* RR */
+ float_to_int (&samples[5*256], int_samples+(i*256*6)+5, 6); /* LFE */ /* Not working yet */
+ break;
+ default:
+ xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libdts: help - unsupported mode %08x\n", output_mode);
+ }
+ }
+ }
+
+ this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream);
+
+
+}
+
+static void dts_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) {
+
+ dts_decoder_t *const this = (dts_decoder_t *) this_gen;
+ uint8_t *current = (uint8_t *)buf->content;
+ uint8_t *sync_start=current + 1;
+ uint8_t *const end = buf->content + buf->size;
+
+ lprintf("decode_data\n");
+
+ if (buf->decoder_flags & BUF_FLAG_PREVIEW)
+ return;
+ if (buf->decoder_flags & BUF_FLAG_STDHEADER)
+ return;
+
+ lprintf ("processing...state %d\n", this->sync_state);
+
+ while (current < end) {
+ switch (this->sync_state) {
+ case 0: /* Looking for sync header */
+ this->syncdword = (this->syncdword << 8) | *current++;
+/*
+ if ((this->syncdword == 0xff1f00e8) ||
+ (this->syncdword == 0x1fffe800) ||
+ (this->syncdword == 0xfe7f0180) ||
+ (this->syncdword == 0x7ffe8001) ) {
+*/
+
+ if ((this->syncdword == 0x7ffe8001) || (this->syncdword == 0xff1f00e8)) {
+ const uint32_t be_syncdword = be2me_32(this->syncdword);
+
+ lprintf ("sync found: syncdword=0x%x\n", this->syncdword);
+
+ memcpy(this->frame_buffer, &be_syncdword, sizeof(be_syncdword));
+
+ this->sync_state = 1;
+ this->frame_ptr = this->frame_buffer+4;
+ this->pts = buf->pts;
+ }
+ break;
+
+ case 1: /* Looking for enough bytes for sync_info. */
+ sync_start = current - 1;
+ *this->frame_ptr++ = *current++;
+ if ((this->frame_ptr - this->frame_buffer) > 19) {
+ const int old_dts_flags = this->dts_flags;
+ const int old_dts_sample_rate = this->dts_sample_rate;
+ const int old_dts_bit_rate = this->dts_bit_rate;
+
+ this->ac5_length = dts_syncinfo (this->dts_state, this->frame_buffer,
+ &this->dts_flags,
+ &this->dts_sample_rate,
+ &this->dts_bit_rate, &(this->ac5_pcm_length));
+ lprintf("ac5_length=%d\n",this->ac5_length);
+ lprintf("dts_sample_rate=%d\n",this->dts_sample_rate);
+
+ if ( (this->ac5_length < 80) || (this->ac5_length > MAX_AC5_FRAME) ) { /* Invalid dts ac5_pcm_length */
+ this->syncdword = 0;
+ current = sync_start;
+ this->sync_state = 0;
+ break;
+ }
+
+ lprintf("Frame length = %d\n",this->ac5_pcm_length);
+
+ this->frame_todo = this->ac5_length - 20;
+ this->sync_state = 2;
+ if (!_x_meta_info_get(this->stream, XINE_META_INFO_AUDIOCODEC) ||
+ old_dts_flags != this->dts_flags ||
+ old_dts_sample_rate != this->dts_sample_rate ||
+ old_dts_bit_rate != this->dts_bit_rate) {
+
+ switch (this->dts_flags & DTS_CHANNEL_MASK) {
+ case DTS_3F2R:
+ if (this->dts_flags & DTS_LFE)
+ _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 5.1");
+ else
+ _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 5.0");
+ break;
+ case DTS_3F1R:
+ case DTS_2F2R:
+ if (this->dts_flags & DTS_LFE)
+ _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 4.1");
+ else
+ _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 4.0");
+ break;
+ case DTS_2F1R:
+ case DTS_3F:
+ _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 3.0");
+ break;
+ case DTS_STEREO:
+ _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 2.0 (stereo)");
+ break;
+ case DTS_MONO:
+ _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 1.0");
+ break;
+ default:
+ _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS");
+ break;
+ }
+
+ _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITRATE, this->dts_bit_rate);
+ _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_SAMPLERATE, this->dts_sample_rate);
+ }
+ }
+ break;
+
+ case 2: /* Filling frame_buffer with sync_info bytes */
+ *this->frame_ptr++ = *current++;
+ this->frame_todo--;
+ if (this->frame_todo < 1) {
+ this->sync_state = 3;
+ } else break;
+
+ case 3: /* Ready for decode */
+#if 0
+ dtsdec_decode_frame (this, this->pts_list[0], buf->decoder_flags & BUF_FLAG_PREVIEW);
+#else
+ dts_decode_frame (this, this->pts, buf->decoder_flags & BUF_FLAG_PREVIEW);
+#endif
+ case 4: /* Clear up ready for next frame */
+ this->pts = 0;
+ this->syncdword = 0;
+ this->sync_state = 0;
+ break;
+ default: /* No come here */
+ break;
+ }
+ }
+}
+
+static void dts_dispose (audio_decoder_t *this_gen) {
+ dts_decoder_t *const this = (dts_decoder_t *) this_gen;
+
+ if (this->output_open)
+ this->stream->audio_out->close (this->stream->audio_out, this->stream);
+
+ free (this);
+}
+
+static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) {
+ dts_decoder_t *this ;
+
+ lprintf("open_plugin\n");
+
+ this = (dts_decoder_t *) xine_xmalloc (sizeof (dts_decoder_t));
+
+ this->audio_decoder.decode_data = dts_decode_data;
+ this->audio_decoder.reset = dts_reset;
+ this->audio_decoder.discontinuity = dts_discontinuity;
+ this->audio_decoder.dispose = dts_dispose;
+
+ this->dts_state = dts_init(0);
+ this->audio_caps = stream->audio_out->get_capabilities(stream->audio_out);
+ if(this->audio_caps & AO_CAP_MODE_AC5)
+ this->bypass_mode = 1;
+ else {
+ this->bypass_mode = 0;
+ /* FIXME: Leave "DOLBY pro logic" downmix out for now. */
+ this->dts_flags_map[DTS_MONO] = DTS_MONO;
+ this->dts_flags_map[DTS_STEREO] = DTS_STEREO;
+ this->dts_flags_map[DTS_3F] = DTS_STEREO;
+ this->dts_flags_map[DTS_2F1R] = DTS_STEREO;
+ this->dts_flags_map[DTS_3F1R] = DTS_STEREO;
+ this->dts_flags_map[DTS_2F2R] = DTS_STEREO;
+ this->dts_flags_map[DTS_3F2R] = DTS_STEREO;
+
+ this->ao_flags_map[DTS_MONO] = AO_CAP_MODE_MONO;
+ this->ao_flags_map[DTS_STEREO] = AO_CAP_MODE_STEREO;
+ this->ao_flags_map[DTS_3F] = AO_CAP_MODE_STEREO;
+ this->ao_flags_map[DTS_2F1R] = AO_CAP_MODE_STEREO;
+ this->ao_flags_map[DTS_3F1R] = AO_CAP_MODE_STEREO;
+ this->ao_flags_map[DTS_2F2R] = AO_CAP_MODE_STEREO;
+ this->ao_flags_map[DTS_3F2R] = AO_CAP_MODE_STEREO;
+
+ /* find best mode */
+ if (this->audio_caps & AO_CAP_MODE_5_1CHANNEL) {
+
+ this->dts_flags_map[DTS_2F2R] = DTS_2F2R;
+ this->dts_flags_map[DTS_3F2R] = DTS_3F2R | DTS_LFE;
+ this->ao_flags_map[DTS_2F2R] = AO_CAP_MODE_4CHANNEL;
+ this->ao_flags_map[DTS_3F2R] = AO_CAP_MODE_5CHANNEL;
+
+ } else if (this->audio_caps & AO_CAP_MODE_5CHANNEL) {
+
+ this->dts_flags_map[DTS_2F2R] = DTS_2F2R;
+ this->dts_flags_map[DTS_3F2R] = DTS_3F2R;
+ this->ao_flags_map[DTS_2F2R] = AO_CAP_MODE_4CHANNEL;
+ this->ao_flags_map[DTS_3F2R] = AO_CAP_MODE_5CHANNEL;
+
+ } else if (this->audio_caps & AO_CAP_MODE_4_1CHANNEL) {
+
+ this->dts_flags_map[DTS_2F2R] = DTS_2F2R;
+ this->dts_flags_map[DTS_3F2R] = DTS_2F2R | DTS_LFE;
+ this->ao_flags_map[DTS_2F2R] = AO_CAP_MODE_4CHANNEL;
+ this->ao_flags_map[DTS_3F2R] = AO_CAP_MODE_4CHANNEL;
+
+ } else if (this->audio_caps & AO_CAP_MODE_4CHANNEL) {
+
+ this->dts_flags_map[DTS_2F2R] = DTS_2F2R;
+ this->dts_flags_map[DTS_3F2R] = DTS_2F2R;
+
+ this->ao_flags_map[DTS_2F2R] = AO_CAP_MODE_4CHANNEL;
+ this->ao_flags_map[DTS_3F2R] = AO_CAP_MODE_4CHANNEL;
+
+ /* else if (this->audio_caps & AO_CAP_MODE_STEREO)
+ defaults are ok */
+ } else if (!(this->audio_caps & AO_CAP_MODE_STEREO)) {
+ xprintf (this->stream->xine, XINE_VERBOSITY_LOG, _("HELP! a mono-only audio driver?!\n"));
+
+ this->dts_flags_map[DTS_MONO] = DTS_MONO;
+ this->dts_flags_map[DTS_STEREO] = DTS_MONO;
+ this->dts_flags_map[DTS_3F] = DTS_MONO;
+ this->dts_flags_map[DTS_2F1R] = DTS_MONO;
+ this->dts_flags_map[DTS_3F1R] = DTS_MONO;
+ this->dts_flags_map[DTS_2F2R] = DTS_MONO;
+ this->dts_flags_map[DTS_3F2R] = DTS_MONO;
+
+ this->ao_flags_map[DTS_MONO] = AO_CAP_MODE_MONO;
+ this->ao_flags_map[DTS_STEREO] = AO_CAP_MODE_MONO;
+ this->ao_flags_map[DTS_3F] = AO_CAP_MODE_MONO;
+ this->ao_flags_map[DTS_2F1R] = AO_CAP_MODE_MONO;
+ this->ao_flags_map[DTS_3F1R] = AO_CAP_MODE_MONO;
+ this->ao_flags_map[DTS_2F2R] = AO_CAP_MODE_MONO;
+ this->ao_flags_map[DTS_3F2R] = AO_CAP_MODE_MONO;
+ }
+ }
+ this->stream = stream;
+ this->class = class_gen;
+ this->output_open = 0;
+
+ return &this->audio_decoder;
+}
+
+static char *get_identifier (audio_decoder_class_t *this) {
+ return "DTS";
+}
+
+static char *get_description (audio_decoder_class_t *this) {
+ return "DTS passthru audio format decoder plugin";
+}
+
+static void dispose_class (audio_decoder_class_t *this) {
+ lprintf("dispose_class\n");
+
+ free (this);
+}
+
+static void *init_plugin (xine_t *xine, void *data) {
+ dts_class_t *this ;
+
+ lprintf("init_plugin\n");
+
+ this = (dts_class_t *) xine_xmalloc (sizeof (dts_class_t));
+
+ this->decoder_class.open_plugin = open_plugin;
+ this->decoder_class.get_identifier = get_identifier;
+ this->decoder_class.get_description = get_description;
+ this->decoder_class.dispose = dispose_class;
+
+ return this;
+}
+
+static uint32_t audio_types[] = {
+ BUF_AUDIO_DTS, 0
+ };
+
+static const decoder_info_t dec_info_audio = {
+ audio_types, /* supported types */
+ 1 /* priority */
+};
+
+const plugin_info_t xine_plugin_info[] EXPORTED = {
+ /* type, API, "name", version, special_info, init_function */
+ { PLUGIN_AUDIO_DECODER, 15, "dts", XINE_VERSION_CODE, &dec_info_audio, init_plugin },
+ { PLUGIN_NONE, 0, "", 0, NULL, NULL }
+};
diff --git a/src/libxineadec/xine_lpcm_decoder.c b/src/libxineadec/xine_lpcm_decoder.c
index 43bea4cbf..88256eb74 100644
--- a/src/libxineadec/xine_lpcm_decoder.c
+++ b/src/libxineadec/xine_lpcm_decoder.c
@@ -16,13 +16,15 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+/**
+ * @file
+ * @author James Courtier-Dutton <james@superbug.demon.co.uk>
*
- * $Id: xine_decoder.c,v 1.62 2007/03/17 20:59:36 dgp85 Exp $
- *
- * 31-8-2001 Added LPCM rate sensing.
- * (c) 2001 James Courtier-Dutton James@superbug.demon.co.uk
- *
+ * @date 2001-08-31 Added LPCM rate sensing
*/
+
#ifndef __sun
#define _XOPEN_SOURCE 500
#endif
@@ -61,7 +63,7 @@ typedef struct lpcm_decoder_s {
uint32_t ao_cap_mode;
int output_open;
- int cpu_be; /* TRUE, if we're a Big endian CPU */
+ int cpu_be; /**< TRUE, if we're a Big endian CPU */
} lpcm_decoder_t;
static void lpcm_reset (audio_decoder_t *this_gen) {
diff --git a/src/libmad/xine_mad_decoder.c b/src/libxineadec/xine_mad_decoder.c
index 98695db68..98695db68 100644
--- a/src/libmad/xine_mad_decoder.c
+++ b/src/libxineadec/xine_mad_decoder.c
diff --git a/src/libxineadec/xine_musepack_decoder.c b/src/libxineadec/xine_musepack_decoder.c
new file mode 100644
index 000000000..51b2a9109
--- /dev/null
+++ b/src/libxineadec/xine_musepack_decoder.c
@@ -0,0 +1,477 @@
+/*
+ * Copyright (C) 2005 the xine project
+ *
+ * This file is part of xine, a free video player.
+ *
+ * xine 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.
+ *
+ * xine is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+/**
+ * @file
+ * @brief xine interface to libmusepack/libmpcdec
+ * @author James Stembridge <jstembridge@gmail.com>
+ *
+ * @todo Add support for 32-bit float samples.
+ * @todo Add support for seeking.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#define LOG_MODULE "mpc_decoder"
+#define LOG_VERBOSE
+/*
+#define LOG
+*/
+
+#include "xine_internal.h"
+#include "audio_out.h"
+#include "buffer.h"
+#include "xineutils.h"
+
+#include <mpcdec/mpcdec.h>
+
+#define MPC_DECODER_MEMSIZE 65536
+#define MPC_DECODER_MEMSIZE2 (MPC_DECODER_MEMSIZE/2)
+
+#define INIT_BUFSIZE (MPC_DECODER_MEMSIZE*2)
+
+typedef struct {
+ audio_decoder_class_t decoder_class;
+} mpc_class_t;
+
+typedef struct mpc_decoder_s {
+ audio_decoder_t audio_decoder;
+
+ xine_stream_t *stream;
+
+ int sample_rate; /* audio sample rate */
+ int bits_per_sample; /* bits/sample, usually 8 or 16 */
+ int channels; /* 1 or 2, usually */
+
+ int output_open; /* flag to indicate audio is ready */
+
+ unsigned char *buf; /* data accumulation buffer */
+ unsigned int buf_max; /* maximum size of buf */
+ unsigned int read; /* size of accum. data already read */
+ unsigned int size; /* size of accumulated data in buf */
+
+ mpc_reader reader;
+ mpc_streaminfo streaminfo;
+ mpc_decoder decoder;
+
+ int decoder_ok;
+ unsigned int current_frame;
+
+ int32_t file_size;
+
+} mpc_decoder_t;
+
+
+/**************************************************************************
+ * musepack specific functions
+ *************************************************************************/
+
+/* Reads size bytes of data into buffer at ptr. */
+static int32_t mpc_reader_read(void *const data, void *const ptr, int size) {
+ mpc_decoder_t *const this = (mpc_decoder_t *) data;
+
+ lprintf("mpc_reader_read: size=%d\n", size);
+
+ /* Don't try to read more data than we have */
+ if (size > (this->size - this->read))
+ size = this->size - this->read;
+
+ /* Copy the data */
+ xine_fast_memcpy(ptr, &this->buf[this->read], size);
+
+ /* Update our position in the data buffer */
+ this->read += size;
+
+ return size;
+}
+
+/* Seeks to byte position offset. */
+static mpc_bool_t mpc_reader_seek(void *const data, const int32_t offset) {
+ mpc_decoder_t *const this = (mpc_decoder_t *) data;
+
+ lprintf("mpc_reader_seek: offset=%d\n", offset);
+
+ /* seek is only called when reading the header so we can assume
+ * that the buffer starts at the start of the file */
+ this->read = offset;
+
+ return TRUE;
+}
+
+/* Returns the current byte offset in the stream. */
+static int32_t mpc_reader_tell(void *const data) {
+ lprintf("mpc_reader_tell\n");
+
+ /* Tell isn't used so just return 0 */
+ return 0;
+}
+
+/* Returns the total length of the source stream, in bytes. */
+static int32_t mpc_reader_get_size(void *const data) {
+ mpc_decoder_t *const this = (const mpc_decoder_t *) data;
+
+ lprintf("mpc_reader_get_size\n");
+
+ return this->file_size;
+}
+
+/* True if the stream is a seekable stream. */
+static mpc_bool_t mpc_reader_canseek(void *data) {
+ lprintf("mpc_reader_canseek\n");
+
+ return TRUE;
+}
+
+/**
+ * @brief Convert a array of floating point samples into 16-bit signed integer samples
+ * @param f Floating point samples array (origin)
+ * @param s16 16-bit signed integer samples array (destination)
+ * @param samples Number of samples to convert
+ *
+ * @todo This same work is being done in many decoders to adapt the output of
+ * the decoder to what the audio output can actually use, this should be
+ * done by the audio_output loop, not by the decoders.
+ */
+static inline void float_to_int(const float *const _f, int16_t *const s16, const int samples) {
+ int i;
+ for (i = 0; i < samples; i++) {
+ const float f = _f[i] * 32767;
+ if (f > INT16_MAX)
+ s16[i] = INT16_MAX;
+ else if (f < INT16_MIN)
+ s16[i] = INT16_MIN;
+ else
+ s16[i] = f;
+ /* printf("samples[%d] = %f, %d\n", i, _f[i], s16[num_channels*i]); */
+ }
+}
+
+/* Decode a musepack frame */
+static int mpc_decode_frame (mpc_decoder_t *this) {
+ float buffer[MPC_DECODER_BUFFER_LENGTH];
+ uint32_t frames;
+
+ lprintf("mpd_decode_frame\n");
+
+ frames = mpc_decoder_decode(&this->decoder, buffer, 0, 0);
+
+ if (frames > 0) {
+ audio_buffer_t *audio_buffer;
+ int16_t *int_samples;
+
+ lprintf("got %d samples\n", frames);
+
+ /* Get audio buffer */
+ audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out);
+ audio_buffer->vpts = 0;
+ audio_buffer->num_frames = frames;
+
+ /* Convert samples */
+ int_samples = (int16_t *) audio_buffer->mem;
+ float_to_int(buffer, int_samples, frames*this->channels);
+
+ /* Output converted samples */
+ this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream);
+ }
+
+ return frames;
+}
+
+/**************************************************************************
+ * xine audio plugin functions
+ *************************************************************************/
+
+static void mpc_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) {
+ mpc_decoder_t *this = (mpc_decoder_t *) this_gen;
+ int err;
+
+ lprintf("mpc_decode_data\n");
+
+ if (!_x_stream_info_get(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED))
+ return;
+
+ /* We don't handle special buffers */
+ if (buf->decoder_flags & BUF_FLAG_SPECIAL)
+ return;
+
+ /* Read header */
+ if (buf->decoder_flags & BUF_FLAG_HEADER) {
+
+ lprintf("header\n");
+
+ /* File size is in decoder_info[0] */
+ this->file_size = buf->decoder_info[0];
+
+ /* Initialise the data accumulation buffer */
+ this->buf = xine_xmalloc(INIT_BUFSIZE);
+ this->buf_max = INIT_BUFSIZE;
+ this->read = 0;
+ this->size = 0;
+
+ /* Initialise the reader */
+ this->reader.read = mpc_reader_read;
+ this->reader.seek = mpc_reader_seek;
+ this->reader.tell = mpc_reader_tell;
+ this->reader.get_size = mpc_reader_get_size;
+ this->reader.canseek = mpc_reader_canseek;
+ this->reader.data = this;
+
+ /* Copy header to buffer */
+ xine_fast_memcpy(this->buf, buf->content, buf->size);
+ this->size = buf->size;
+
+ /* Initialise and read stream info */
+ mpc_streaminfo_init(&this->streaminfo);
+
+ if ((err = mpc_streaminfo_read(&this->streaminfo, &this->reader))) {
+ xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
+ _("libmusepack: mpc_streaminfo_read failed: %d\n"), err);
+
+ _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0);
+ return;
+ }
+
+ this->sample_rate = this->streaminfo.sample_freq;
+ this->channels = this->streaminfo.channels;
+ this->bits_per_sample = 16;
+
+ /* After the header the demuxer starts sending data from an offset
+ * of 28 bytes */
+ this->size = 28;
+
+ /* We need to keep track of the current frame so we now when we've
+ * reached the end of the stream */
+ this->current_frame = 0;
+
+ /* Setup the decoder */
+ mpc_decoder_setup(&this->decoder, &this->reader);
+ this->decoder_ok = 0;
+
+ /* Take this opportunity to initialize stream/meta information */
+ _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC,
+ "Musepack (libmusepack)");
+ _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITRATE,
+ (int) this->streaminfo.average_bitrate);
+
+ return;
+ }
+
+ lprintf("data: %u size=%u read=%u\n", buf->size, this->size, this->read);
+
+ /* if the audio output is not open yet, open the audio output */
+ if (!this->output_open) {
+ this->output_open = this->stream->audio_out->open(
+ this->stream->audio_out,
+ this->stream,
+ this->bits_per_sample,
+ this->sample_rate,
+ _x_ao_channels2mode(this->channels));
+ }
+
+ /* if the audio still isn't open, do not go any further with the decode */
+ if (!this->output_open)
+ return;
+
+ /* If we run out of space in our internal buffer we discard what's
+ * already been read */
+ if (((this->size + buf->size) > this->buf_max) && this->read) {
+ lprintf("discarding read data\n");
+ this->size -= this->read;
+ memmove(this->buf, &this->buf[this->read], this->size);
+ this->read = 0;
+ }
+
+ /* If there still isn't space we have to increase the size of the
+ * internal buffer */
+ if ((this->size + buf->size) > this->buf_max) {
+ xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG,
+ "libmusepack: increasing internal buffer size\n");
+ this->buf_max += 2*buf->size;
+ this->buf = realloc(this->buf, this->buf_max);
+ }
+
+ /* Copy data */
+ xine_fast_memcpy(&this->buf[this->size], buf->content, buf->size);
+ this->size += buf->size;
+
+ /* Time to decode */
+ if (buf->decoder_flags & BUF_FLAG_FRAME_END) {
+ /* Increment frame count */
+ if (this->current_frame++ == this->streaminfo.frames) {
+ xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
+ _("libmusepack: data after last frame ignored\n"));
+ return;
+ }
+
+ if (!this->decoder_ok) {
+ /* We require MPC_DECODER_MEMSIZE bytes to initialise the decoder */
+ if ((this->size - this->read) >= MPC_DECODER_MEMSIZE) {
+ lprintf("initialise");
+
+ if (!mpc_decoder_initialize(&this->decoder, &this->streaminfo)) {
+ xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
+ _("libmusepack: mpc_decoder_initialise failed\n"));
+
+ _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0);
+ return;
+ }
+
+ this->decoder_ok = 1;
+ } else {
+ /* Not enough data yet */
+ return;
+ }
+ }
+
+ /* mpc_decoder_decode may cause a read of MPC_DECODER_MEMSIZE/2 bytes so
+ * make sure we have enough data available */
+ if ((this->size - this->read) >= MPC_DECODER_MEMSIZE2) {
+ lprintf("decoding\n");
+
+ if ((err = mpc_decode_frame(this)) < 0) {
+ xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
+ _("libmusepack: mpc_decoder_decode failed: %d\n"), err);
+
+ _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0);
+ return;
+ }
+ }
+
+ /* If we are at the end of the stream we decode the remaining frames as we
+ * know we'll have enough data */
+ if (this->current_frame == this->streaminfo.frames) {
+ lprintf("flushing buffers\n");
+
+ do {
+ if ((err = mpc_decode_frame(this)) < 0) {
+ xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
+ _("libmusepack: mpc_decoder_decode failed: %d\n"), err);
+ }
+ } while (err > 0);
+
+ lprintf("buffers flushed\n");
+ }
+ }
+}
+
+static void mpc_reset (audio_decoder_t *this_gen) {
+ mpc_decoder_t *this = (mpc_decoder_t *) this_gen;
+
+ this->size = 0;
+ this->read = 0;
+}
+
+static void mpc_discontinuity (audio_decoder_t *this_gen) {
+ /* mpc_decoder_t *this = (mpc_decoder_t *) this_gen; */
+}
+
+static void mpc_dispose (audio_decoder_t *this_gen) {
+
+ mpc_decoder_t *this = (mpc_decoder_t *) this_gen;
+
+ /* close the audio output */
+ if (this->output_open)
+ this->stream->audio_out->close (this->stream->audio_out, this->stream);
+
+ /* free anything that was allocated during operation */
+ free(this->buf);
+
+ free(this);
+}
+
+static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) {
+
+ mpc_decoder_t *this ;
+
+ this = (mpc_decoder_t *) xine_xmalloc (sizeof (mpc_decoder_t));
+
+ /* connect the member functions */
+ this->audio_decoder.decode_data = mpc_decode_data;
+ this->audio_decoder.reset = mpc_reset;
+ this->audio_decoder.discontinuity = mpc_discontinuity;
+ this->audio_decoder.dispose = mpc_dispose;
+
+ /* connect the stream */
+ this->stream = stream;
+
+ /* audio output is not open at the start */
+ this->output_open = 0;
+
+ /* no buffer yet */
+ this->buf = NULL;
+
+ /* initialize the basic audio parameters */
+ this->channels = 0;
+ this->sample_rate = 0;
+ this->bits_per_sample = 0;
+
+ /* return the newly-initialized audio decoder */
+ return &this->audio_decoder;
+}
+
+static char *get_identifier (audio_decoder_class_t *this) {
+ return "mpc";
+}
+
+static char *get_description (audio_decoder_class_t *this) {
+ return "mpc: musepack audio decoder plugin";
+}
+
+static void dispose_class (audio_decoder_class_t *this_gen) {
+
+ mpc_class_t *this = (mpc_class_t *)this_gen;
+
+ free (this);
+}
+
+static void *init_plugin (xine_t *xine, void *data) {
+
+ mpc_class_t *this ;
+
+ this = (mpc_class_t *) xine_xmalloc (sizeof (mpc_class_t));
+
+ this->decoder_class.open_plugin = open_plugin;
+ this->decoder_class.get_identifier = get_identifier;
+ this->decoder_class.get_description = get_description;
+ this->decoder_class.dispose = dispose_class;
+
+ return this;
+}
+
+static uint32_t audio_types[] = {
+ BUF_AUDIO_MPC,
+ 0
+};
+
+static const decoder_info_t dec_info_audio = {
+ audio_types, /* supported types */
+ 5 /* priority */
+};
+
+const plugin_info_t xine_plugin_info[] EXPORTED = {
+ /* { type, API version, "name", version, special_info, init_function }, */
+ { PLUGIN_AUDIO_DECODER, 15, "mpc", XINE_VERSION_CODE, &dec_info_audio, &init_plugin },
+ { PLUGIN_NONE, 0, "", 0, NULL, NULL }
+};
+
diff --git a/src/libxineadec/xine_vorbis_decoder.c b/src/libxineadec/xine_vorbis_decoder.c
index ef8575949..7fc1b9197 100644
--- a/src/libxineadec/xine_vorbis_decoder.c
+++ b/src/libxineadec/xine_vorbis_decoder.c
@@ -91,8 +91,8 @@ static void vorbis_discontinuity (audio_decoder_t *this_gen) {
}
/* Known vorbis comment keys from ogg123 sources*/
-static struct {
- char *key; /* includes the '=' for programming convenience */
+static const struct {
+ const char *key; /* includes the '=' for programming convenience */
int xine_metainfo_index;
} vorbis_comment_keys[] = {
{"ARTIST=", XINE_META_INFO_ARTIST},
diff --git a/src/libxinevdec/Makefile.am b/src/libxinevdec/Makefile.am
index 87ee050e6..28a926a79 100644
--- a/src/libxinevdec/Makefile.am
+++ b/src/libxinevdec/Makefile.am
@@ -1,19 +1,19 @@
include $(top_srcdir)/misc/Makefile.common
-AM_CFLAGS = $(VISIBILITY_FLAG)
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
AM_LDFLAGS = $(xineplug_ldflags)
EXTRA_DIST = foovideo.c
-if HAVE_WAND
+if ENABLE_IMAGEMAGICK
image_module = xineplug_decode_image.la
endif
-if HAVE_GDK_PIXBUF
+if ENABLE_GDK_PIXBUF
gdkpixbuf_module = xineplug_decode_gdk_pixbuf.la
endif
-if HAVE_THEORA
+if ENABLE_THEORA
theora_module = xineplug_decode_theora.la
endif
@@ -34,13 +34,13 @@ xineplug_decode_yuv_la_SOURCES = yuv.c
xineplug_decode_yuv_la_LIBADD = $(XINE_LIB)
xineplug_decode_image_la_SOURCES = image.c
-xineplug_decode_image_la_CFLAGS = $(AM_CFLAGS) $(WAND_CFLAGS)
xineplug_decode_image_la_LIBADD = $(XINE_LIB) $(DYNAMIC_LD_LIBS) $(WAND_LIBS)
+xineplug_decode_image_la_CFLAGS = $(AM_CFLAGS) $(WAND_CFLAGS)
xineplug_decode_gdk_pixbuf_la_SOURCES = gdkpixbuf.c
-xineplug_decode_gdk_pixbuf_la_CFLAGS = $(AM_CFLAGS) $(GDK_PIXBUF_CFLAGS)
xineplug_decode_gdk_pixbuf_la_LIBADD = $(XINE_LIB) $(DYNAMIC_LD_LIBS) $(GDK_PIXBUF_LIBS)
+xineplug_decode_gdk_pixbuf_la_CFLAGS = $(AM_CFLAGS) $(GDK_PIXBUF_CFLAGS)
xineplug_decode_theora_la_SOURCES = xine_theora_decoder.c
-xineplug_decode_theora_la_CFLAGS = $(AM_CFLAGS) $(OGG_CFLAGS) $(THEORA_CFLAGS)
xineplug_decode_theora_la_LIBADD = $(XINE_LIB) $(OGG_LIBS) $(THEORA_LIBS)
+xineplug_decode_theora_la_CFLAGS = $(AM_CFLAGS) $(OGG_CFLAGS) $(THEORA_CFLAGS)
diff --git a/src/libxinevdec/bitplane.c b/src/libxinevdec/bitplane.c
index 373d5d8b1..62f7a19db 100644
--- a/src/libxinevdec/bitplane.c
+++ b/src/libxinevdec/bitplane.c
@@ -1160,8 +1160,8 @@ static void bitplane_decode_data (video_decoder_t *this_gen,
this->bytes_per_pixel = 1;
/* New Buffer for indexes (palette based formats) */
- this->index_buf = xine_xmalloc( this->num_pixel * this->bytes_per_pixel );
- this->index_buf_hist = xine_xmalloc( this->num_pixel * this->bytes_per_pixel );
+ this->index_buf = xine_xcalloc( this->num_pixel, this->bytes_per_pixel );
+ this->index_buf_hist = xine_xcalloc( this->num_pixel, this->bytes_per_pixel );
this->num_bitplanes = bih->biPlanes;
this->camg_mode = bih->biCompression;
@@ -1316,8 +1316,8 @@ static void bitplane_decode_data (video_decoder_t *this_gen,
}
}
if( this->index_buf == NULL ) {
- this->index_buf = xine_xmalloc( (this->num_pixel * this->bytes_per_pixel) );
- this->index_buf_hist = xine_xmalloc( (this->num_pixel * this->bytes_per_pixel) );
+ this->index_buf = xine_xcalloc( this->num_pixel, this->bytes_per_pixel );
+ this->index_buf_hist = xine_xcalloc( this->num_pixel, this->bytes_per_pixel );
for (i = 0; i < (this->num_pixel * this->bytes_per_pixel); i++) {
this->index_buf[i] = 0;
this->index_buf_hist[i] = 0;
diff --git a/src/post/Makefile.am b/src/post/Makefile.am
index 8408c3f3a..6c28b41f7 100644
--- a/src/post/Makefile.am
+++ b/src/post/Makefile.am
@@ -1,4 +1,3 @@
include $(top_srcdir)/misc/Makefile.common
-SUBDIRS = \
- planar goom visualizations mosaico deinterlace audio
+SUBDIRS = planar goom visualizations mosaico deinterlace audio
diff --git a/src/post/audio/Makefile.am b/src/post/audio/Makefile.am
index f4018a780..7ede380da 100644
--- a/src/post/audio/Makefile.am
+++ b/src/post/audio/Makefile.am
@@ -1,5 +1,8 @@
include $(top_srcdir)/misc/Makefile.common
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+AM_LDFLAGS = $(xineplug_ldflags)
+
noinst_HEADERS = dsp.h filter.h window.h audio_filters.h
xinepost_LTLIBRARIES = xineplug_post_audio_filters.la
@@ -7,6 +10,4 @@ xinepost_LTLIBRARIES = xineplug_post_audio_filters.la
xineplug_post_audio_filters_la_SOURCES = \
upmix.c upmix_mono.c filter.c window.c stretch.c volnorm.c audio_filters.c
xineplug_post_audio_filters_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS) -lm
-xineplug_post_audio_filters_la_CFLAGS = $(VISIBILITY_FLAG)
-xineplug_post_audio_filters_la_LDFLAGS = -avoid-version -module
diff --git a/src/post/deinterlace/Makefile.am b/src/post/deinterlace/Makefile.am
index d2d1d5c10..ef030b22d 100644
--- a/src/post/deinterlace/Makefile.am
+++ b/src/post/deinterlace/Makefile.am
@@ -1,8 +1,9 @@
include $(top_srcdir)/misc/Makefile.common
-SUBDIRS = plugins
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+AM_LDFLAGS = $(xineplug_ldflags) $(IMPURE_TEXT_LDFLAGS)
-EXTRA_DIST =
+SUBDIRS = plugins
xinepost_LTLIBRARIES = xineplug_post_tvtime.la
@@ -11,8 +12,4 @@ xineplug_post_tvtime_la_SOURCES = xine_plugin.c \
xineplug_post_tvtime_la_LIBADD = $(XINE_LIB) \
$(top_builddir)/src/post/deinterlace/plugins/libdeinterlaceplugins.la
-xineplug_post_tvtime_la_CFLAGS = $(VISIBILITY_FLAG)
-xineplug_post_tvtime_la_LDFLAGS = -avoid-version -module \
- @IMPURE_TEXT_LDFLAGS@
-
noinst_HEADERS = deinterlace.h pulldown.h speedtools.h speedy.h tvtime.h
diff --git a/src/post/deinterlace/plugins/Makefile.am b/src/post/deinterlace/plugins/Makefile.am
index 17d170127..4185b5706 100644
--- a/src/post/deinterlace/plugins/Makefile.am
+++ b/src/post/deinterlace/plugins/Makefile.am
@@ -17,6 +17,11 @@ include $(top_srcdir)/misc/Makefile.common
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+# libpostproc is here so we can use their nice mangle.h
+AM_CFLAGS = $(VISIBILITY_FLAG)
+AM_CPPFLAGS = -I$(top_srcdir)/src/post/deinterlace \
+ -I$(top_srcdir)/contrib/ffmpeg/libpostproc
+
EXTRA_DIST = greedy2frame_template.c greedyh.asm \
tomsmocomp/SearchLoop0A.inc tomsmocomp/SearchLoopBottom.inc \
tomsmocomp/SearchLoopEdgeA.inc tomsmocomp/SearchLoopEdgeA8.inc \
@@ -28,25 +33,26 @@ EXTRA_DIST = greedy2frame_template.c greedyh.asm \
tomsmocomp/TomsMoCompAll2.inc tomsmocomp/WierdBob.inc \
tomsmocomp/tomsmocompmacros.h x86-64_macros.inc
-# libpostproc is here so we can use their nice mangle.h
-AM_CFLAGS = -I$(top_srcdir)/src/post/deinterlace \
- -I$(top_srcdir)/src/libffmpeg/libavcodec/libpostproc
-
-noinst_LTLIBRARIES = libdeinterlaceplugins.la
-
-libdeinterlaceplugins_la_SOURCES = \
- double.c \
- greedy.c \
- linear.c \
- linearblend.c \
- vfir.c \
- weave.c \
- greedy2frame.c \
- scalerbob.c \
- kdetv_greedyh.c \
- kdetv_tomsmocomp.c
-libdeinterlaceplugins_la_LIBADD = $(XINE_LIB)
-libdeinterlaceplugins_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS)
-libdeinterlaceplugins_la_LDFLAGS = -avoid-version -module
-
noinst_HEADERS = plugins.h greedyhmacros.h
+
+if DEBUG_BUILD
+debug_sources = greedy2frame.c
+nodebug_sources =
+else
+debug_sources =
+nodebug_sources = greedy2frame.c
+endif
+
+# per-object CFLAGS -- drop optimization on kdetv_greedyh.c so that gcc
+# doesn't run out of general registers trying to compile it.
+
+noinst_LTLIBRARIES = libdeinterlacepluginsO1.la libdeinterlaceplugins.la
+libdeinterlacepluginsO1_la_SOURCES = kdetv_greedyh.c $(debug_sources)
+libdeinterlacepluginsO1_la_CFLAGS = $(O1_CFLAGS) $(AM_CFLAGS)
+
+libdeinterlaceplugins_la_SOURCES = double.c greedy.c linear.c linearblend.c \
+ vfir.c weave.c scalerbob.c kdetv_tomsmocomp.c \
+ $(nodebug_sources)
+libdeinterlaceplugins_la_LIBADD = $(XINE_LIB) libdeinterlacepluginsO1.la
+libdeinterlaceplugins_la_CFLAGS = $(DEFAULT_OCFLAGS) $(AM_CFLAGS)
+libdeinterlaceplugins_la_LDFLAGS = $(AM_LDFLAGS) $(xineplug_ldflags)
diff --git a/src/post/goom/Makefile.am b/src/post/goom/Makefile.am
index 53a806a7a..40636736c 100644
--- a/src/post/goom/Makefile.am
+++ b/src/post/goom/Makefile.am
@@ -1,36 +1,15 @@
include $(top_srcdir)/misc/Makefile.common
-EXTRA_DIST = mmx.c xmmx.c ppc_drawings.s ppc_zoom_ultimate.s diff_against_release.patch \
- gfontrle.c mathtools.c
-
-## -fomit-frame-pointer segfaults here
-## Use -O2 if -Os is stripped or x86 does not build
-#CFLAGS = `echo @CFLAGS@ | sed -e 's/-fomit-frame-pointer//g;s/-Os/-O2/g'`
-CFLAGS = `echo @CFLAGS@ | sed -e 's/-Os/-O2/g'`
-
-# Avoid errors with -O0
-xineplug_post_goom_la-xmmx.o xineplug_post_goom_la-xmmx.lo: CFLAGS=`echo @CFLAGS@ | sed -e 's/-O0\?\s/-Os /g'`
-
-xinepost_LTLIBRARIES = xineplug_post_goom.la
+AM_CFLAGS = $(VISIBILITY_FLAG)
## doesn't work
-#if PPC_ARCH
+#if ARCH_PPC
#extra_files = ppc_drawings.s ppc_zoom_ultimate.s
#AM_CPPFLAGS = -DCPU_POWERPC
#endif
-if HAVE_MMX
-extra_files = mmx.c xmmx.c
-endif
-
-xineplug_post_goom_la_SOURCES = $(extra_files) xine_goom.c \
- config_param.c convolve_fx.c cpu_info.c drawmethods.c filters.c flying_stars_fx.c \
- gfontlib.c goom_core.c goom_tools.c goomsl.c goomsl_hash.c goomsl_heap.c \
- goomsl_lex.c goomsl_yacc.c graphic.c ifs.c lines.c \
- plugin_info.c sound_tester.c surf3d.c tentacle3d.c v3d.c
-xineplug_post_goom_la_LIBADD = $(XINE_LIB) $(GOOM_LIBS) $(PTHREAD_LIBS) -lm
-xineplug_post_goom_la_CFLAGS = $(VISIBILITY_FLAG)
-xineplug_post_goom_la_LDFLAGS = -avoid-version -module
+EXTRA_DIST = mmx.c xmmx.c ppc_drawings.s ppc_zoom_ultimate.s diff_against_release.patch \
+ gfontrle.c mathtools.c
noinst_HEADERS = cpu_info.h default_scripts.h drawmethods.h gfontlib.h goom.h \
goom_config.h goom_config_param.h goom_filters.h goom_fx.h goom_graphic.h \
@@ -38,3 +17,21 @@ noinst_HEADERS = cpu_info.h default_scripts.h drawmethods.h gfontlib.h goom.h \
goomsl_heap.h goomsl_private.h goomsl_yacc.h ifs.h lines.h mathtools.h mmx.h \
ppc_drawings.h ppc_zoom_ultimate.h sound_tester.h surf3d.h tentacle3d.h v3d.h \
motif_goom1.h motif_goom2.h
+
+noinst_LTLIBRARIES = libpost_goom_asm.la
+libpost_goom_asm_la_SOURCES = xmmx.c
+if DEBUG_BUILD
+libpost_goom_asm_la_CFLAGS = $(O1_CFLAGS) $(AM_CFLAGS)
+else
+libpost_goom_asm_la_CFLAGS = $(DEFAULT_OCFLAGS) $(AM_CFLAGS)
+endif
+
+xinepost_LTLIBRARIES = xineplug_post_goom.la
+xineplug_post_goom_la_SOURCES = mmx.c xine_goom.c \
+ config_param.c convolve_fx.c cpu_info.c drawmethods.c filters.c flying_stars_fx.c \
+ gfontlib.c goom_core.c goom_tools.c goomsl.c goomsl_hash.c goomsl_heap.c \
+ goomsl_lex.c goomsl_yacc.c graphic.c ifs.c lines.c \
+ plugin_info.c sound_tester.c surf3d.c tentacle3d.c v3d.c
+xineplug_post_goom_la_LIBADD = $(XINE_LIB) $(GOOM_LIBS) $(PTHREAD_LIBS) -lm $(noinst_LTLIBRARIES)
+xineplug_post_goom_la_CFLAGS = $(DEFAULT_OCFLAGS) $(AM_CFLAGS)
+xineplug_post_goom_la_LDFLAGS = $(AM_LDFLAGS) $(xineplug_ldflags)
diff --git a/src/post/goom/gfontlib.c b/src/post/goom/gfontlib.c
index 2bc366305..2bc366305 100644..100755
--- a/src/post/goom/gfontlib.c
+++ b/src/post/goom/gfontlib.c
diff --git a/src/post/goom/gfontlib.h b/src/post/goom/gfontlib.h
index 0520b7da9..0520b7da9 100644..100755
--- a/src/post/goom/gfontlib.h
+++ b/src/post/goom/gfontlib.h
diff --git a/src/post/goom/gfontrle.c b/src/post/goom/gfontrle.c
index a22545a1e..a22545a1e 100644..100755
--- a/src/post/goom/gfontrle.c
+++ b/src/post/goom/gfontrle.c
diff --git a/src/post/goom/mathtools.h b/src/post/goom/mathtools.h
index 165fc66b0..165fc66b0 100644..100755
--- a/src/post/goom/mathtools.h
+++ b/src/post/goom/mathtools.h
diff --git a/src/post/goom/mmx.h b/src/post/goom/mmx.h
index b650d8b12..88789e86f 100644
--- a/src/post/goom/mmx.h
+++ b/src/post/goom/mmx.h
@@ -31,6 +31,8 @@
# include "config.h"
#endif
+#include "attributes.h"
+
#include "goom_graphic.h"
/* Warning: at this writing, the version of GAS packaged
@@ -58,7 +60,7 @@ typedef union {
char b[8]; /* 8 Byte (8-bit) values */
unsigned char ub[8]; /* 8 Unsigned Byte */
float s[2]; /* Single-precision (32-bit) value */
-} __attribute__ ((aligned (8))) mmx_t; /* On an 8-byte (64-bit) boundary */
+} ATTR_ALIGN(8) mmx_t; /* On an 8-byte (64-bit) boundary */
diff --git a/src/post/goom/surf3d.c b/src/post/goom/surf3d.c
index ba8c69094..ba8c69094 100644..100755
--- a/src/post/goom/surf3d.c
+++ b/src/post/goom/surf3d.c
diff --git a/src/post/goom/surf3d.h b/src/post/goom/surf3d.h
index 482b6a090..482b6a090 100644..100755
--- a/src/post/goom/surf3d.h
+++ b/src/post/goom/surf3d.h
diff --git a/src/post/goom/tentacle3d.c b/src/post/goom/tentacle3d.c
index e1e2157e7..e1e2157e7 100644..100755
--- a/src/post/goom/tentacle3d.c
+++ b/src/post/goom/tentacle3d.c
diff --git a/src/post/goom/tentacle3d.h b/src/post/goom/tentacle3d.h
index ad0858fad..ad0858fad 100644..100755
--- a/src/post/goom/tentacle3d.h
+++ b/src/post/goom/tentacle3d.h
diff --git a/src/post/goom/v3d.h b/src/post/goom/v3d.h
index 7690847f2..7690847f2 100644..100755
--- a/src/post/goom/v3d.h
+++ b/src/post/goom/v3d.h
diff --git a/src/post/mosaico/Makefile.am b/src/post/mosaico/Makefile.am
index c18b4e19c..6f9cca937 100644
--- a/src/post/mosaico/Makefile.am
+++ b/src/post/mosaico/Makefile.am
@@ -1,13 +1,12 @@
include $(top_srcdir)/misc/Makefile.common
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+AM_LDFLAGS = $(xineplug_ldflags)
+
xinepost_LTLIBRARIES = xineplug_post_mosaico.la xineplug_post_switch.la
xineplug_post_mosaico_la_SOURCES = mosaico.c
xineplug_post_mosaico_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS)
-xineplug_post_mosaico_la_CFLAGS = $(VISIBILITY_FLAG)
-xineplug_post_mosaico_la_LDFLAGS = -avoid-version -module
xineplug_post_switch_la_SOURCES = switch.c
xineplug_post_switch_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS)
-xineplug_post_switch_la_CFLAGS = $(VISIBILITY_FLAG)
-xineplug_post_switch_la_LDFLAGS = -avoid-version -module
diff --git a/src/post/mosaico/mosaico.c b/src/post/mosaico/mosaico.c
index 40173bd5d..cc7fefe2c 100644
--- a/src/post/mosaico/mosaico.c
+++ b/src/post/mosaico/mosaico.c
@@ -160,7 +160,7 @@ static post_plugin_t *mosaico_open_plugin(post_class_t *class_gen, int inputs,
_x_post_init(&this->post, 0, inputs);
- this->pip = (mosaico_pip_t *)xine_xmalloc(sizeof(mosaico_pip_t) * (inputs - 1));
+ this->pip = (mosaico_pip_t *)xine_xcalloc((inputs - 1), sizeof(mosaico_pip_t));
this->pip_count = inputs - 1;
pthread_cond_init(&this->vpts_limit_changed, NULL);
diff --git a/src/post/planar/Makefile.am b/src/post/planar/Makefile.am
index 826f378a6..5d6da97cd 100644
--- a/src/post/planar/Makefile.am
+++ b/src/post/planar/Makefile.am
@@ -1,34 +1,30 @@
include $(top_srcdir)/misc/Makefile.common
-POSTPROC_INT_LIB = $(top_builddir)/src/libffmpeg/libavcodec/libpostproc/libpostprocess.la
+AM_CFLAGS = $(VISIBILITY_FLAG) $(ff_cflags)
+AM_CPPFLAGS =
+AM_LDFLAGS =
-if HAVE_FFMPEG
+if WITH_EXTERNAL_FFMPEG
postproc_lib = $(FFMPEG_POSTPROC_LIBS)
-ff_cflags = $(FFMPEG_POSTPROC_CFLAGS)
+ff_cflags = $(FFMPEG_POSTPROC_CFLAGS)
else
-ff_cflags = -I$(top_srcdir)/src/libffmpeg/libavcodec/libpostproc
-postproc_lib = $(POSTPROC_INT_LIB)
-postproc_dep = $(postproc_lib)
-endif
+AM_CPPFLAGS += -I$(top_srcdir)/contrib/ffmpeg/libpostproc
+postproc_lib = $(top_builddir)/contrib/ffmpeg/libpostproc/libpostproc.a \
+ $(top_builddir)/contrib/ffmpeg/libavutil/libavutil.a
-# -fomit-frame-pointer is always needed. it might cause debug to not
-# work, but at least it compiles.
-AM_CFLAGS = $(ff_cflags) -fomit-frame-pointer
+$(top_builddir)/contrib/ffmpeg/libpostproc/libpostproc.a:
+ $(MAKE) -C $(top_builddir)/contrib ffmpeg/libpostproc/libpostproc.a
+$(top_builddir)/contrib/ffmpeg/libavutil/libavutil.a:
+ $(MAKE) -C $(top_builddir)/contrib ffmpeg/libavutil/libavutil.a
+endif
-# Avoid errors with -O0
-xineplug_post_planar_la-eq.o xineplug_post_planar_la-eq.lo: CFLAGS=`echo @CFLAGS@ | sed -e 's/-O0\?\s/-Os /g'`
-xineplug_post_planar_la-eq2.o xineplug_post_planar_la-eq2.lo: CFLAGS=`echo @CFLAGS@ | sed -e 's/-O0\?\s/-Os /g'`
-xineplug_post_planar_la-noise.o xineplug_post_planar_la-noise.lo: CFLAGS=`echo @CFLAGS@ | sed -e 's/-O0\?\s/-Os /g'`
+noinst_LTLIBRARIES = libpost_planar_asm.la
+libpost_planar_asm_la_SOURCES = eq.c eq2.c noise.c
+libpost_planar_asm_la_CFLAGS = $(O1_CFLAGS) -fomit-frame-pointer $(AM_CFLAGS)
xinepost_LTLIBRARIES = xineplug_post_planar.la
-
xineplug_post_planar_la_SOURCES = planar.c invert.c expand.c fill.c boxblur.c \
- denoise3d.c eq.c eq2.c unsharp.c pp.c noise.c
-xineplug_post_planar_la_DEPENDENCIES = $(postproc_dep)
-xineplug_post_planar_la_LIBADD = $(XINE_LIB) $(postproc_lib) -lm $(PTHREAD_LIBS)
-xineplug_post_planar_la_LDFLAGS = -avoid-version -module \
- @IMPURE_TEXT_LDFLAGS@
-xineplug_post_planar_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS)
-
-$(POSTPROC_INT_LIB):
- cd $(top_builddir)/src/libffmpeg/libavcodec/libpostproc && $(MAKE) libpostprocess.la
+ denoise3d.c unsharp.c pp.c
+xineplug_post_planar_la_LIBADD = $(XINE_LIB) $(postproc_lib) -lm $(PTHREAD_LIBS) $(noinst_LTLIBRARIES)
+xineplug_post_planar_la_CFLAGS = $(DEFAULT_OCFLAGS) $(AM_CFLAGS)
+xineplug_post_planar_la_LDFLAGS = $(AM_LDFLAGS) $(xineplug_ldflags) $(IMPURE_TEXT_LDFLAGS)
diff --git a/src/post/planar/pp.c b/src/post/planar/pp.c
index c66e40459..c66e40459 100644..100755
--- a/src/post/planar/pp.c
+++ b/src/post/planar/pp.c
diff --git a/src/post/visualizations/Makefile.am b/src/post/visualizations/Makefile.am
index f42598d9c..bea89ac49 100644
--- a/src/post/visualizations/Makefile.am
+++ b/src/post/visualizations/Makefile.am
@@ -1,13 +1,14 @@
include $(top_srcdir)/misc/Makefile.common
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+AM_LDFLAGS = $(xineplug_ldflags)
+
EXTRA_DIST = fooviz.c
+noinst_HEADERS = fft.h visualizations.h
+
xinepost_LTLIBRARIES = xineplug_post_visualizations.la
xineplug_post_visualizations_la_SOURCES = \
visualizations.c fft.c fftscope.c oscope.c fftgraph.c
xineplug_post_visualizations_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS) -lm
-xineplug_post_visualizations_la_CFLAGS = $(VISIBILITY_FLAG)
-xineplug_post_visualizations_la_LDFLAGS = -avoid-version -module
-
-noinst_HEADERS = fft.h visualizations.h
diff --git a/src/vdr/Makefile.am b/src/vdr/Makefile.am
new file mode 100644
index 000000000..fcdf6cae4
--- /dev/null
+++ b/src/vdr/Makefile.am
@@ -0,0 +1,17 @@
+include $(top_srcdir)/misc/Makefile.common
+
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+AM_LDFLAGS = $(xineplug_ldflags)
+
+xineinclude_HEADERS = input_vdr.h
+
+if ENABLE_DVB
+xineplug_LTLIBRARIES = xineplug_inp_vdr.la
+xinepost_LTLIBRARIES = xineplug_post_vdr.la
+endif
+
+xineplug_inp_vdr_la_SOURCES = input_vdr.c
+xineplug_inp_vdr_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS)
+
+xineplug_post_vdr_la_SOURCES = post_vdr.c post_vdr_video.c post_vdr_audio.c post_vdr.h
+xineplug_post_vdr_la_LIBADD = $(XINE_LIB)
diff --git a/src/vdr/input_vdr.c b/src/vdr/input_vdr.c
new file mode 100644
index 000000000..1f82def28
--- /dev/null
+++ b/src/vdr/input_vdr.c
@@ -0,0 +1,2545 @@
+/*
+ * Copyright (C) 2003-2004 the xine project
+ *
+ * This file is part of xine, a free video player.
+ *
+ * xine 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.
+ *
+ * xine is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * $Id: input_vdr.c,v 1.51 2003/05/02 15:02:11 miguelfreitas Exp $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/poll.h>
+#include <errno.h>
+#include <pthread.h>
+
+#define LOG_MODULE "input_vdr"
+#define LOG_VERBOSE
+/*
+#define LOG
+*/
+#include "xine_internal.h"
+#include "xineutils.h"
+#include "input_plugin.h"
+
+#include "input_vdr.h"
+#include "post_vdr.h"
+
+
+
+#define VDR_MAX_NUM_WINDOWS 16
+#define VDR_ABS_FIFO_DIR "/tmp/vdr-xine"
+
+
+
+#define BUF_SIZE 1024
+
+#define LOG_OSD(x)
+/*
+#define LOG_OSD(x) x
+*/
+
+
+typedef struct
+{
+ input_plugin_t input_plugin;
+
+ xine_stream_t *stream;
+ xine_stream_t *stream_external;
+
+ int fh;
+ int fh_control;
+ int fh_result;
+ int fh_event;
+
+ char *mrl;
+
+ off_t curpos;
+ char seek_buf[ BUF_SIZE ];
+
+ char *preview;
+ off_t preview_size;
+
+ enum funcs cur_func;
+ off_t cur_size;
+ off_t cur_done;
+
+ xine_osd_t *osd_window[ VDR_MAX_NUM_WINDOWS ];
+ uint8_t *osd_buffer;
+ uint32_t osd_buffer_size;
+ uint8_t osd_unscaled_blending;
+
+ uint8_t audio_channels;
+ uint8_t trick_speed_mode;
+ uint8_t mute_mode;
+ uint8_t volume_mode;
+ int last_volume;
+ vdr_frame_size_changed_data_t frame_size;
+
+ pthread_t rpc_thread;
+ int rpc_thread_shutdown;
+ pthread_mutex_t rpc_thread_shutdown_lock;
+ pthread_cond_t rpc_thread_shutdown_cond;
+
+ xine_event_queue_t *event_queue;
+ xine_event_queue_t *event_queue_external;
+
+ pthread_mutex_t adjust_zoom_lock;
+ uint16_t image4_3_zoom_x;
+ uint16_t image4_3_zoom_y;
+ uint16_t image16_9_zoom_x;
+ uint16_t image16_9_zoom_y;
+
+}
+vdr_input_plugin_t;
+
+
+
+typedef struct
+{
+ input_class_t input_class;
+ xine_t *xine;
+ char *mrls[ 2 ];
+}
+vdr_input_class_t;
+
+
+
+static int vdr_write(int f, void *b, int n)
+{
+ int t = 0, r;
+
+ while (t < n)
+ {
+ /*
+ * System calls are not a thread cancellation point in Linux
+ * pthreads. However, the RT signal sent to cancel the thread
+ * will cause recv() to return with EINTR, and we can manually
+ * check cancellation.
+ */
+ pthread_testcancel();
+ r = write(f, ((char *)b) + t, n - t);
+ pthread_testcancel();
+
+ if (r < 0
+ && (errno == EINTR
+ || errno == EAGAIN))
+ {
+ continue;
+ }
+
+ if (r < 0)
+ return r;
+
+ t += r;
+ }
+
+ return t;
+}
+
+
+
+static int internal_write_event_play_external(vdr_input_plugin_t *this, uint32_t key);
+
+static void event_handler_external(void *user_data, const xine_event_t *event)
+{
+ vdr_input_plugin_t *this = (vdr_input_plugin_t *)user_data;
+ uint32_t key = key_none;
+/*
+ printf("event_handler_external(): event->type: %d\n", event->type);
+*/
+ switch (event->type)
+ {
+ case XINE_EVENT_UI_PLAYBACK_FINISHED:
+ break;
+
+ default:
+ return;
+ }
+
+ if (0 != internal_write_event_play_external(this, key))
+ xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
+ _(LOG_MODULE ": input event write: %s.\n"), strerror(errno));
+}
+
+static void external_stream_stop(vdr_input_plugin_t *this)
+{
+ if (this->stream_external)
+ {
+ xine_stop(this->stream_external);
+ xine_close(this->stream_external);
+
+ if (this->event_queue_external)
+ {
+ xine_event_dispose_queue(this->event_queue_external);
+ this->event_queue_external = 0;
+ }
+
+ _x_demux_flush_engine(this->stream_external);
+
+ xine_dispose(this->stream_external);
+ this->stream_external = 0;
+ }
+}
+
+static void external_stream_play(vdr_input_plugin_t *this, char *file_name)
+{
+ external_stream_stop(this);
+
+ this->stream_external = xine_stream_new(this->stream->xine, this->stream->audio_out, this->stream->video_out);
+
+ this->event_queue_external = xine_event_new_queue(this->stream_external);
+
+ xine_event_create_listener_thread(this->event_queue_external, event_handler_external, this);
+
+ if (!xine_open(this->stream_external, file_name)
+ || !xine_play(this->stream_external, 0, 0))
+ {
+ uint32_t key = key_none;
+
+ if ( 0 != internal_write_event_play_external(this, key))
+ xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
+ _(LOG_MODULE ": input event write: %s.\n"), strerror(errno));
+ }
+}
+
+static off_t vdr_read_abort(xine_stream_t *stream, int fd, char *buf, off_t todo)
+{
+ off_t ret;
+
+ while (1)
+ {
+ /*
+ * System calls are not a thread cancellation point in Linux
+ * pthreads. However, the RT signal sent to cancel the thread
+ * will cause recv() to return with EINTR, and we can manually
+ * check cancellation.
+ */
+ pthread_testcancel();
+ ret = _x_read_abort(stream, fd, buf, todo);
+ pthread_testcancel();
+
+ if (ret < 0
+ && (errno == EINTR
+ || errno == EAGAIN))
+ {
+ continue;
+ }
+
+ break;
+ }
+
+ return ret;
+}
+
+#define READ_DATA_OR_FAIL(kind, log) \
+ data_##kind##_t *data = &data_union.kind; \
+ { \
+ log; \
+ n = vdr_read_abort(this->stream, this->fh_control, (char *)data + sizeof (data->header), sizeof (*data) - sizeof (data->header)); \
+ if (n != sizeof (*data) - sizeof (data->header)) \
+ return -1; \
+ \
+ this->cur_size -= n; \
+ }
+
+static double _now()
+{
+ struct timeval tv;
+
+ gettimeofday(&tv, 0);
+
+ return (tv.tv_sec * 1000000.0 + tv.tv_usec) / 1000.0;
+}
+
+static void adjust_zoom(vdr_input_plugin_t *this)
+{
+ pthread_mutex_lock(&this->adjust_zoom_lock);
+
+ if (this->image4_3_zoom_x && this->image4_3_zoom_y
+ && this->image16_9_zoom_x && this->image16_9_zoom_y)
+ {
+ int ratio = (int)(10000 * this->frame_size.r + 0.5);
+fprintf(stderr, "ratio: %d\n", ratio);
+ if (13332 <= ratio && ratio <= 13334)
+ {
+ xine_set_param(this->stream, XINE_PARAM_VO_ZOOM_X, this->image4_3_zoom_x);
+ xine_set_param(this->stream, XINE_PARAM_VO_ZOOM_Y, this->image4_3_zoom_y);
+ }
+ else if (17777 <= ratio && ratio <= 17779)
+ {
+ xine_set_param(this->stream, XINE_PARAM_VO_ZOOM_X, this->image16_9_zoom_x);
+ xine_set_param(this->stream, XINE_PARAM_VO_ZOOM_Y, this->image16_9_zoom_y);
+ }
+ }
+
+ pthread_mutex_unlock(&this->adjust_zoom_lock);
+}
+
+static off_t vdr_execute_rpc_command(vdr_input_plugin_t *this)
+{
+ data_union_t data_union;
+ off_t n;
+
+ n = vdr_read_abort(this->stream, this->fh_control, (char *)&data_union, sizeof (data_union.header));
+ if (n != sizeof (data_union.header))
+ return -1;
+
+ this->cur_func = data_union.header.func;
+ this->cur_size = data_union.header.len - sizeof (data_union.header);
+ this->cur_done = 0;
+
+ switch (this->cur_func)
+ {
+ case func_nop:
+ {
+ READ_DATA_OR_FAIL(nop, lprintf("got NOP\n"));
+ }
+ break;
+
+ case func_osd_new:
+ {
+ READ_DATA_OR_FAIL(osd_new, LOG_OSD(lprintf("got OSDNEW\n")));
+/*
+ LOG_OSD(lprintf("... (%d,%d)-(%d,%d)\n", data->x, data->y, data->width, data->height));
+
+ fprintf(stderr, "vdr: osdnew %d\n", data->window);
+*/
+ if (data->window >= VDR_MAX_NUM_WINDOWS)
+ return -1;
+
+ if (0 != this->osd_window[ data->window ])
+ return -1;
+
+ this->osd_window[ data->window ] = xine_osd_new(this->stream
+ , data->x
+ , data->y
+ , data->width
+ , data->height);
+
+ if (0 == this->osd_window[ data->window ])
+ return -1;
+ }
+ break;
+
+ case func_osd_free:
+ {
+ READ_DATA_OR_FAIL(osd_free, LOG_OSD(lprintf("got OSDFREE\n")));
+/*
+ fprintf(stderr, "vdr: osdfree %d\n", data->window);
+*/
+ if (data->window >= VDR_MAX_NUM_WINDOWS)
+ return -1;
+
+ if (0 != this->osd_window[ data->window ])
+ xine_osd_free(this->osd_window[ data->window ]);
+
+ this->osd_window[ data->window ] = 0;
+ }
+ break;
+
+ case func_osd_show:
+ {
+ READ_DATA_OR_FAIL(osd_show, LOG_OSD(lprintf("got OSDSHOW\n")));
+/*
+ fprintf(stderr, "vdr: osdshow %d\n", data->window);
+*/
+ if (data->window >= VDR_MAX_NUM_WINDOWS)
+ return -1;
+
+ if (0 != this->osd_window[ data->window ])
+ {
+ if (this->osd_unscaled_blending)
+ xine_osd_show_unscaled(this->osd_window[ data->window ], 0);
+ else
+ xine_osd_show(this->osd_window[ data->window ], 0);
+ }
+ }
+ break;
+
+ case func_osd_hide:
+ {
+ READ_DATA_OR_FAIL(osd_hide, LOG_OSD(lprintf("got OSDHIDE\n")));
+/*
+ fprintf(stderr, "vdr: osdhide %d\n", data->window);
+*/
+ if (data->window >= VDR_MAX_NUM_WINDOWS)
+ return -1;
+
+ if (0 != this->osd_window[ data->window ])
+ {
+ if (this->osd_unscaled_blending)
+ xine_osd_show_unscaled(this->osd_window[ data->window ], 0);
+ else
+ xine_osd_show(this->osd_window[ data->window ], 0);
+ }
+ }
+ break;
+
+ case func_osd_flush:
+ {
+ double _t1, _t2;
+ int _n = 0;
+ int _to = 0;
+ int r = 0;
+
+ READ_DATA_OR_FAIL(osd_flush, LOG_OSD(lprintf("got OSDFLUSH\n")));
+/*
+ fprintf(stderr, "vdr: osdflush +\n");
+*/
+ _t1 = _now();
+
+ while ((r = _x_query_unprocessed_osd_events(this->stream)))
+ {
+ if ((_now() - _t1) > 200)
+ {
+ _to = 1;
+ break;
+ }
+/*
+ fprintf(stderr, "redraw_needed: 1\n");
+*/
+/* sched_yield(); */
+ xine_usec_sleep(5000);
+ _n++;
+ }
+
+ _t2 = _now();
+ fprintf(stderr, "vdr: osdflush: n: %d, %.1lf, timeout: %d, result: %d\n", _n, _t2 - _t1, _to, r);
+/*
+ fprintf(stderr, "redraw_needed: 0\n");
+
+ fprintf(stderr, "vdr: osdflush -\n");
+*/
+ }
+ break;
+
+ case func_osd_set_position:
+ {
+ READ_DATA_OR_FAIL(osd_set_position, LOG_OSD(lprintf("got OSDSETPOSITION\n")));
+/*
+ fprintf(stderr, "vdr: osdsetposition %d\n", data->window);
+*/
+ if (data->window >= VDR_MAX_NUM_WINDOWS)
+ return -1;
+
+ if (0 != this->osd_window[ data->window ])
+ xine_osd_set_position(this->osd_window[ data->window ], data->x, data->y);
+ }
+ break;
+
+ case func_osd_draw_bitmap:
+ {
+ READ_DATA_OR_FAIL(osd_draw_bitmap, LOG_OSD(lprintf("got OSDDRAWBITMAP\n")));
+/*
+ fprintf(stderr, "vdr: osddrawbitmap %d\n", data->window);
+*/
+ if (this->osd_buffer_size < this->cur_size)
+ {
+ if (this->osd_buffer)
+ free(this->osd_buffer);
+
+ this->osd_buffer_size = 0;
+
+ this->osd_buffer = xine_xmalloc(this->cur_size);
+ if (!this->osd_buffer)
+ return -1;
+
+ this->osd_buffer_size = this->cur_size;
+ }
+
+ n = vdr_read_abort (this->stream, this->fh_control, (char *)this->osd_buffer, this->cur_size);
+ if (n != this->cur_size)
+ return -1;
+
+ this->cur_size -= n;
+
+ if (data->window >= VDR_MAX_NUM_WINDOWS)
+ return -1;
+
+ if (0 != this->osd_window[ data->window ])
+ xine_osd_draw_bitmap(this->osd_window[ data->window ], this->osd_buffer, data->x, data->y, data->width, data->height, 0);
+ }
+ break;
+
+ case func_set_color:
+ {
+ uint32_t vdr_color[ 256 ];
+
+ READ_DATA_OR_FAIL(set_color, lprintf("got SETCOLOR\n"));
+
+ if (((data->num + 1) * sizeof (uint32_t)) != this->cur_size)
+ return -1;
+
+ n = vdr_read_abort (this->stream, this->fh_control, (char *)&vdr_color[ data->index ], this->cur_size);
+ if (n != this->cur_size)
+ return -1;
+
+ this->cur_size -= n;
+
+ if (data->window >= VDR_MAX_NUM_WINDOWS)
+ return -1;
+
+ if (0 != this->osd_window[ data->window ])
+ {
+ uint32_t color[ 256 ];
+ uint8_t trans[ 256 ];
+
+ xine_osd_get_palette(this->osd_window[ data->window ], color, trans);
+
+ {
+ int i;
+
+ for (i = data->index; i <= (data->index + data->num); i++)
+ {
+ int a = (vdr_color[ i ] & 0xff000000) >> 0x18;
+ int r = (vdr_color[ i ] & 0x00ff0000) >> 0x10;
+ int g = (vdr_color[ i ] & 0x0000ff00) >> 0x08;
+ int b = (vdr_color[ i ] & 0x000000ff) >> 0x00;
+
+ int y = (( 66 * r + 129 * g + 25 * b + 128) >> 8) + 16;
+ int cr = ((112 * r - 94 * g - 18 * b + 128) >> 8) + 128;
+ int cb = ((-38 * r - 74 * g + 112 * b + 128) >> 8) + 128;
+
+ uint8_t *dst = (uint8_t *)&color[ i ];
+ *dst++ = cb;
+ *dst++ = cr;
+ *dst++ = y;
+ *dst++ = 0;
+
+ trans[ i ] = a >> 4;
+ }
+ }
+
+ xine_osd_set_palette(this->osd_window[ data->window ], color, trans);
+ }
+ }
+ break;
+
+ case func_play_external:
+ {
+ char file_name[ 1024 ];
+ int file_name_len = 0;
+
+ READ_DATA_OR_FAIL(play_external, lprintf("got PLAYEXTERNAL\n"));
+
+ file_name_len = this->cur_size;
+
+ if (0 != file_name_len)
+ {
+ if (file_name_len <= 1
+ || file_name_len > sizeof (file_name))
+ {
+ return -1;
+ }
+
+ n = vdr_read_abort (this->stream, this->fh_control, file_name, file_name_len);
+ if (n != file_name_len)
+ return -1;
+
+ if (file_name[ file_name_len - 1 ] != '\0')
+ return -1;
+
+ this->cur_size -= n;
+ }
+
+ lprintf((file_name_len > 0) ? "----------- play external: %s\n" : "---------- stop external\n", file_name);
+
+ if (file_name_len > 0)
+ external_stream_play(this, file_name);
+ else
+ external_stream_stop(this);
+ }
+ break;
+
+ case func_clear:
+ {
+ READ_DATA_OR_FAIL(clear, lprintf("got CLEAR\n"));
+
+ {
+ int orig_speed = xine_get_param(this->stream, XINE_PARAM_FINE_SPEED);
+ if (orig_speed <= 0)
+ xine_set_param(this->stream, XINE_PARAM_FINE_SPEED, XINE_FINE_SPEED_NORMAL);
+fprintf(stderr, "+++ CLEAR(%d%c)\n", data->n, data->s ? 'b' : 'a');
+/*
+ if (!this->dont_change_xine_volume)
+ xine_set_param(this->stream, XINE_PARAM_AUDIO_VOLUME, 0);
+*/
+ _x_demux_flush_engine(this->stream);
+fprintf(stderr, "=== CLEAR(%d.1)\n", data->n);
+ _x_demux_control_start(this->stream);
+fprintf(stderr, "=== CLEAR(%d.2)\n", data->n);
+ _x_demux_seek(this->stream, 0, 0, 0);
+fprintf(stderr, "=== CLEAR(%d.3)\n", data->n);
+
+ _x_stream_info_reset(this->stream, XINE_STREAM_INFO_AUDIO_BITRATE);
+fprintf(stderr, "=== CLEAR(%d.4)\n", data->n);
+ _x_meta_info_reset(this->stream, XINE_META_INFO_AUDIOCODEC);
+fprintf(stderr, "=== CLEAR(%d.5)\n", data->n);
+
+ _x_trigger_relaxed_frame_drop_mode(this->stream);
+/* _x_reset_relaxed_frame_drop_mode(this->stream); */
+/*
+ if (!this->dont_change_xine_volume)
+ xine_set_param(this->stream, XINE_PARAM_AUDIO_VOLUME, this->last_volume);
+*/
+fprintf(stderr, "--- CLEAR(%d%c)\n", data->n, data->s ? 'b' : 'a');
+ if (orig_speed <= 0)
+ xine_set_param(this->stream, XINE_PARAM_FINE_SPEED, orig_speed);
+ }
+ }
+ break;
+
+ case func_first_frame:
+ {
+ READ_DATA_OR_FAIL(first_frame, lprintf("got FIRST FRAME\n"));
+
+ _x_trigger_relaxed_frame_drop_mode(this->stream);
+/* _x_reset_relaxed_frame_drop_mode(this->stream); */
+ }
+ break;
+
+ case func_still_frame:
+ {
+ READ_DATA_OR_FAIL(still_frame, lprintf("got STILL FRAME\n"));
+
+ _x_reset_relaxed_frame_drop_mode(this->stream);
+ }
+ break;
+
+ case func_set_video_window:
+ {
+ READ_DATA_OR_FAIL(set_video_window, lprintf("got SET VIDEO WINDOW\n"));
+/*
+ fprintf(stderr, "svw: (%d, %d)x(%d, %d), (%d, %d)\n", data->x, data->y, data->w, data->h, data->wRef, data->hRef);
+*/
+ {
+ xine_event_t event;
+ vdr_set_video_window_data_t event_data;
+
+ event_data.x = data->x;
+ event_data.y = data->y;
+ event_data.w = data->w;
+ event_data.h = data->h;
+ event_data.w_ref = data->w_ref;
+ event_data.h_ref = data->h_ref;
+
+ event.type = XINE_EVENT_VDR_SETVIDEOWINDOW;
+ event.data = &event_data;
+ event.data_length = sizeof (event_data);
+
+ xine_event_send(this->stream, &event);
+ }
+ }
+ break;
+
+ case func_select_audio:
+ {
+ READ_DATA_OR_FAIL(select_audio, lprintf("got SELECT AUDIO\n"));
+
+ this->audio_channels = data->channels;
+
+ {
+ xine_event_t event;
+ vdr_select_audio_data_t event_data;
+
+ event_data.channels = this->audio_channels;
+
+ event.type = XINE_EVENT_VDR_SELECTAUDIO;
+ event.data = &event_data;
+ event.data_length = sizeof (event_data);
+
+ xine_event_send(this->stream, &event);
+ }
+ }
+ break;
+
+ case func_trick_speed_mode:
+ {
+ READ_DATA_OR_FAIL(trick_speed_mode, lprintf("got TRICK SPEED MODE\n"));
+
+ if (this->trick_speed_mode != data->on)
+ {
+fprintf(stderr, "ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß\n");
+ this->trick_speed_mode = data->on;
+
+ _x_demux_seek(this->stream, 0, 0, 0);
+
+ {
+ xine_event_t event;
+
+ event.type = XINE_EVENT_VDR_TRICKSPEEDMODE;
+ event.data = 0;
+ event.data_length = this->trick_speed_mode;
+/* fprintf(stderr, "************************: %p, %d\n", event.data, event.data_length); */
+ xine_event_send(this->stream, &event);
+ }
+ }
+ }
+ break;
+
+ case func_flush:
+ {
+ READ_DATA_OR_FAIL(flush, lprintf("got FLUSH\n"));
+
+ if (!data->just_wait)
+ {
+ if (this->stream->video_fifo)
+ {
+ buf_element_t *buf = this->stream->video_fifo->buffer_pool_alloc(this->stream->video_fifo);
+ if (!buf)
+ {
+ xprintf(this->stream->xine, XINE_VERBOSITY_LOG, _(LOG_MODULE ": buffer_pool_alloc() failed!\n"));
+ return -1;
+ }
+
+ buf->type = BUF_CONTROL_FLUSH_DECODER;
+
+ this->stream->video_fifo->put(this->stream->video_fifo, buf);
+ }
+ }
+
+ {
+ double _t1, _t2;
+ int _n = 0;
+
+ int vb = -1, ab = -1, vf = -1, af = -1;
+
+ uint8_t timed_out = 0;
+
+ struct timeval now, then;
+
+ if (data->ms_timeout >= 0)
+ {
+ gettimeofday(&now, 0);
+
+ then = now;
+ then.tv_usec += (data->ms_timeout % 1000) * 1000;
+ then.tv_sec += (data->ms_timeout / 1000);
+
+ if (then.tv_usec >= 1000000)
+ {
+ then.tv_usec -= 1000000;
+ then.tv_sec += 1;
+ }
+ }
+ else
+ {
+ then.tv_usec = 0;
+ then.tv_sec = 0;
+ }
+
+ _t1 = _now();
+
+ while (1)
+ {
+ _x_query_buffer_usage(this->stream, &vb, &ab, &vf, &af);
+
+ if (vb <= 0 && ab <= 0 && vf <= 0 && af <= 0)
+ break;
+
+ if (data->ms_timeout >= 0
+ && timercmp(&now, &then, >=))
+ {
+ timed_out++;
+ break;
+ }
+
+/* sched_yield(); */
+ xine_usec_sleep(5000);
+ _n++;
+
+ if (data->ms_timeout >= 0)
+ gettimeofday(&now, 0);
+ }
+
+ _t2 = _now();
+ fprintf(stderr, "vdr: flush: n: %d, %.1lf\n", _n, _t2 - _t1);
+
+ xprintf(this->stream->xine
+ , XINE_VERBOSITY_LOG
+ , _(LOG_MODULE ": flush buffers (vb: %d, ab: %d, vf: %d, af: %d) %s.\n")
+ , vb, ab, vf, af
+ , (timed_out ? "timed out" : "done"));
+
+ {
+ result_flush_t result_flush;
+ result_flush.header.func = data->header.func;
+ result_flush.header.len = sizeof (result_flush);
+
+ result_flush.timed_out = timed_out;
+
+ if (sizeof (result_flush) != vdr_write(this->fh_result, &result_flush, sizeof (result_flush)))
+ return -1;
+ }
+ }
+ }
+ break;
+
+ case func_mute:
+ {
+ READ_DATA_OR_FAIL(mute, lprintf("got MUTE\n"));
+
+ {
+ int param_mute = (this->volume_mode == INPUT_VDR_VOLUME_CHANGE_SW) ? XINE_PARAM_AUDIO_AMP_MUTE : XINE_PARAM_AUDIO_MUTE;
+ xine_set_param(this->stream, param_mute, data->mute);
+ }
+ }
+ break;
+
+ case func_set_volume:
+ {
+ READ_DATA_OR_FAIL(set_volume, lprintf("got SETVOLUME\n"));
+
+ {
+ int change_volume = (this->volume_mode != INPUT_VDR_VOLUME_IGNORE);
+ int do_mute = (this->last_volume != 0 && 0 == data->volume);
+ int do_unmute = (this->last_volume <= 0 && 0 != data->volume);
+ int report_change = 0;
+
+ int param_mute = (this->volume_mode == INPUT_VDR_VOLUME_CHANGE_SW) ? XINE_PARAM_AUDIO_AMP_MUTE : XINE_PARAM_AUDIO_MUTE;
+ int param_volume = (this->volume_mode == INPUT_VDR_VOLUME_CHANGE_SW) ? XINE_PARAM_AUDIO_AMP_LEVEL : XINE_PARAM_AUDIO_VOLUME;
+
+ this->last_volume = data->volume;
+
+ if (do_mute || do_unmute)
+ {
+ switch (this->mute_mode)
+ {
+ case INPUT_VDR_MUTE_EXECUTE:
+ report_change = 1;
+ xine_set_param(this->stream, param_mute, do_mute);
+
+ case INPUT_VDR_MUTE_IGNORE:
+ if (do_mute)
+ change_volume = 0;
+ break;
+
+ case INPUT_VDR_MUTE_SIMULATE:
+ change_volume = 1;
+ break;
+
+ default:
+ return -1;
+ };
+ }
+
+ if (change_volume)
+ {
+ report_change = 1;
+ xine_set_param(this->stream, param_volume, this->last_volume);
+ }
+
+ if (report_change && this->volume_mode != INPUT_VDR_VOLUME_CHANGE_SW)
+ {
+ xine_event_t event;
+ xine_audio_level_data_t data;
+
+ data.left
+ = data.right
+ = xine_get_param(this->stream, param_volume);
+ data.mute
+ = xine_get_param(this->stream, param_mute);
+
+ event.type = XINE_EVENT_AUDIO_LEVEL;
+ event.data = &data;
+ event.data_length = sizeof (data);
+
+ xine_event_send(this->stream, &event);
+ }
+ }
+ }
+ break;
+
+ case func_set_speed:
+ {
+ READ_DATA_OR_FAIL(set_speed, lprintf("got SETSPEED\n"));
+
+ lprintf("... got SETSPEED %d\n", data->speed);
+
+ if (data->speed != xine_get_param(this->stream, XINE_PARAM_FINE_SPEED))
+ xine_set_param(this->stream, XINE_PARAM_FINE_SPEED, data->speed);
+ }
+ break;
+
+ case func_set_prebuffer:
+ {
+ READ_DATA_OR_FAIL(set_prebuffer, lprintf("got SETPREBUFFER\n"));
+
+ xine_set_param(this->stream, XINE_PARAM_METRONOM_PREBUFFER, data->prebuffer);
+ }
+ break;
+
+ case func_metronom:
+ {
+ READ_DATA_OR_FAIL(metronom, lprintf("got METRONOM\n"));
+
+ _x_demux_control_newpts(this->stream, data->pts, data->flags);
+ }
+ break;
+
+ case func_start:
+ {
+ READ_DATA_OR_FAIL(start, lprintf("got START\n"));
+
+ _x_demux_control_start(this->stream);
+ _x_demux_seek(this->stream, 0, 0, 0);
+ }
+ break;
+
+ case func_wait:
+ {
+ READ_DATA_OR_FAIL(wait, lprintf("got WAIT\n"));
+
+ {
+ result_wait_t result_wait;
+ result_wait.header.func = data->header.func;
+ result_wait.header.len = sizeof (result_wait);
+
+ if (sizeof (result_wait) != vdr_write(this->fh_result, &result_wait, sizeof (result_wait)))
+ return -1;
+ }
+ }
+ break;
+
+ case func_setup:
+ {
+ READ_DATA_OR_FAIL(setup, lprintf("got SETUP\n"));
+
+ this->osd_unscaled_blending = data->osd_unscaled_blending;
+ this->volume_mode = data->volume_mode;
+ this->mute_mode = data->mute_mode;
+ this->image4_3_zoom_x = data->image4_3_zoom_x;
+ this->image4_3_zoom_y = data->image4_3_zoom_y;
+ this->image16_9_zoom_x = data->image16_9_zoom_x;
+ this->image16_9_zoom_y = data->image16_9_zoom_y;
+
+ adjust_zoom(this);
+ }
+ break;
+
+ case func_grab_image:
+ {
+ READ_DATA_OR_FAIL(grab_image, lprintf("got GRABIMAGE\n"));
+
+ {
+ off_t ret_val = -1;
+
+ uint8_t *img = 0;
+ int frame_size = 0;
+ int width = 0;
+ int height = 0;
+ int ratio_code = 0;
+ int format = 0;
+
+ int orig_speed = xine_get_param(this->stream, XINE_PARAM_FINE_SPEED);
+ if (XINE_SPEED_PAUSE != orig_speed)
+ xine_set_param(this->stream, XINE_PARAM_FINE_SPEED, XINE_SPEED_PAUSE);
+
+ if (xine_get_current_frame(this->stream, &width, &height, &ratio_code, &format, 0))
+ {
+ switch (format)
+ {
+ case XINE_IMGFMT_YV12:
+ frame_size = width * height
+ + ((width + 1) / 2) * ((height + 1) / 2)
+ + ((width + 1) / 2) * ((height + 1) / 2);
+ break;
+
+ case XINE_IMGFMT_YUY2:
+ frame_size = width * height
+ + ((width + 1) / 2) * height
+ + ((width + 1) / 2) * height;
+ break;
+ }
+
+ img = xine_xmalloc(frame_size);
+
+ if (!xine_get_current_frame(this->stream, &width, &height, &ratio_code, &format, img))
+ frame_size = 0;
+
+ if (ratio_code == XINE_VO_ASPECT_SQUARE)
+ ratio_code = 10000;
+ else if (ratio_code == XINE_VO_ASPECT_4_3)
+ ratio_code = 13333;
+ else if (ratio_code == XINE_VO_ASPECT_ANAMORPHIC)
+ ratio_code = 17778;
+ else if (ratio_code == XINE_VO_ASPECT_DVB)
+ ratio_code = 21100;
+
+ if (0 == frame_size)
+ {
+ width = 0;
+ height = 0;
+ ratio_code = 0;
+ }
+ }
+
+ if (XINE_SPEED_PAUSE != orig_speed)
+ xine_set_param(this->stream, XINE_PARAM_FINE_SPEED, orig_speed);
+
+ {
+ result_grab_image_t result_grab_image;
+ result_grab_image.header.func = data->header.func;
+ result_grab_image.header.len = sizeof (result_grab_image) + frame_size;
+
+ result_grab_image.width = width;
+ result_grab_image.height = height;
+ result_grab_image.ratio = ratio_code;
+ result_grab_image.format = format;
+
+ if (sizeof (result_grab_image) == vdr_write(this->fh_result, &result_grab_image, sizeof (result_grab_image)))
+ {
+ if (frame_size == vdr_write(this->fh_result, img, frame_size))
+ ret_val = 0;
+ }
+ }
+
+ if (img)
+ free(img);
+
+ if (ret_val != 0)
+ return ret_val;
+ }
+ }
+ break;
+
+ case func_get_pts:
+ {
+ READ_DATA_OR_FAIL(get_pts, lprintf("got GETPTS\n"));
+
+ {
+ result_get_pts_t result_get_pts;
+ result_get_pts.header.func = data->header.func;
+ result_get_pts.header.len = sizeof (result_get_pts);
+
+ result_get_pts.pts = xine_get_current_vpts(this->stream) - this->stream->metronom->get_option(this->stream->metronom, METRONOM_VPTS_OFFSET);
+
+ if (sizeof (result_get_pts) != vdr_write(this->fh_result, &result_get_pts, sizeof (result_get_pts)))
+ return -1;
+ }
+ }
+ break;
+
+ case func_get_version:
+ {
+ READ_DATA_OR_FAIL(get_version, lprintf("got GETVERSION\n"));
+
+ {
+ result_get_version_t result_get_version;
+ result_get_version.header.func = data->header.func;
+ result_get_version.header.len = sizeof (result_get_version);
+
+ result_get_version.version = XINE_INPUT_VDR_VERSION;
+
+ if (sizeof (result_get_version) != vdr_write(this->fh_result, &result_get_version, sizeof (result_get_version)))
+ return -1;
+ }
+ }
+ break;
+
+ case func_video_size:
+ {
+ READ_DATA_OR_FAIL(video_size, lprintf("got VIDEO SIZE\n"));
+
+ {
+ int format;
+
+ result_video_size_t result_video_size;
+ result_video_size.header.func = data->header.func;
+ result_video_size.header.len = sizeof (result_video_size);
+
+ result_video_size.top = -1;
+ result_video_size.left = -1;
+ result_video_size.width = -1;
+ result_video_size.height = -1;
+ result_video_size.ratio = 0;
+
+ xine_get_current_frame(this->stream, &result_video_size.width, &result_video_size.height, &result_video_size.ratio, &format, 0);
+
+ if (result_video_size.ratio == XINE_VO_ASPECT_SQUARE)
+ result_video_size.ratio = 10000;
+ else if (result_video_size.ratio == XINE_VO_ASPECT_4_3)
+ result_video_size.ratio = 13333;
+ else if (result_video_size.ratio == XINE_VO_ASPECT_ANAMORPHIC)
+ result_video_size.ratio = 17778;
+ else if (result_video_size.ratio == XINE_VO_ASPECT_DVB)
+ result_video_size.ratio = 21100;
+
+ if (0 != this->frame_size.x
+ || 0 != this->frame_size.y
+ || 0 != this->frame_size.w
+ || 0 != this->frame_size.h)
+ {
+ result_video_size.left = this->frame_size.x;
+ result_video_size.top = this->frame_size.y;
+ result_video_size.width = this->frame_size.w;
+ result_video_size.height = this->frame_size.h;
+ }
+//fprintf(stderr, "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n");
+ result_video_size.zoom_x = xine_get_param(this->stream, XINE_PARAM_VO_ZOOM_X);
+ result_video_size.zoom_y = xine_get_param(this->stream, XINE_PARAM_VO_ZOOM_Y);
+//fprintf(stderr, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\n");
+ if (sizeof (result_video_size) != vdr_write(this->fh_result, &result_video_size, sizeof (result_video_size)))
+ return -1;
+//fprintf(stderr, "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG\n");
+ }
+ }
+ break;
+
+ case func_reset_audio:
+ {
+ double _t1, _t2;
+ int _n = 0;
+
+ READ_DATA_OR_FAIL(reset_audio, lprintf("got RESET AUDIO\n"));
+
+ if (this->stream->audio_fifo)
+ {
+ xine_set_param(this->stream, XINE_PARAM_IGNORE_AUDIO, 1);
+ xine_set_param(this->stream, XINE_PARAM_AUDIO_CHANNEL_LOGICAL, -2);
+
+ _t1 = _now();
+
+ while (1)
+ {
+ int n = xine_get_stream_info(this->stream, XINE_STREAM_INFO_MAX_AUDIO_CHANNEL);
+ if (n <= 0)
+ break;
+
+ /* keep the decoder running */
+ if (this->stream->audio_fifo)
+ {
+ buf_element_t *buf = this->stream->audio_fifo->buffer_pool_alloc(this->stream->audio_fifo);
+ if (!buf)
+ {
+ xprintf(this->stream->xine, XINE_VERBOSITY_LOG, _(LOG_MODULE ": buffer_pool_alloc() failed!\n"));
+ return -1;
+ }
+
+ buf->type = BUF_CONTROL_RESET_TRACK_MAP;
+
+ this->stream->audio_fifo->put(this->stream->audio_fifo, buf);
+ }
+
+/* sched_yield(); */
+ xine_usec_sleep(5000);
+ _n++;
+ }
+
+ _t2 = _now();
+ fprintf(stderr, "vdr: reset_audio: n: %d, %.1lf\n", _n, _t2 - _t1);
+
+ xine_set_param(this->stream, XINE_PARAM_AUDIO_CHANNEL_LOGICAL, -1);
+
+ _x_stream_info_reset(this->stream, XINE_STREAM_INFO_AUDIO_BITRATE);
+ _x_meta_info_reset(this->stream, XINE_META_INFO_AUDIOCODEC);
+
+ xine_set_param(this->stream, XINE_PARAM_IGNORE_AUDIO, 0);
+ }
+ }
+ break;
+
+ default:
+ lprintf("unknown function: %d\n", this->cur_func);
+ }
+
+ if (this->cur_size != this->cur_done)
+ {
+ off_t skip = this->cur_size - this->cur_done;
+
+ lprintf("func: %d, skipping: %lld\n", this->cur_func, skip);
+
+ while (skip > BUF_SIZE)
+ {
+ n = vdr_read_abort(this->stream, this->fh_control, this->seek_buf, BUF_SIZE);
+ if (n != BUF_SIZE)
+ return -1;
+
+ skip -= BUF_SIZE;
+ }
+
+ n = vdr_read_abort(this->stream, this->fh_control, this->seek_buf, skip);
+ if (n != skip)
+ return -1;
+
+ this->cur_done = this->cur_size;
+
+ return -1;
+ }
+
+ return 0;
+}
+
+static void *vdr_rpc_thread_loop(void *arg)
+{
+ vdr_input_plugin_t *this = (vdr_input_plugin_t *)arg;
+ int frontend_lock_failures = 0;
+ int failed = 0;
+
+ while (!failed
+ && !this->rpc_thread_shutdown)
+ {
+ struct timeval timeout;
+ fd_set rset;
+
+ FD_ZERO(&rset);
+ FD_SET(this->fh_control, &rset);
+
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 50000;
+
+ if (select(this->fh_control + 1, &rset, NULL, NULL, &timeout) > 0)
+ {
+ if (!_x_lock_frontend(this->stream, 100))
+ {
+ if (++frontend_lock_failures > 50)
+ {
+ failed = 1;
+ xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
+ LOG_MODULE ": locking frontend for rpc command execution failed, exiting ...\n");
+ }
+ }
+ else
+ {
+ frontend_lock_failures = 0;
+
+ if (_x_lock_port_rewiring(this->stream->xine, 100))
+ {
+ if (vdr_execute_rpc_command(this) < 0)
+ {
+ failed = 1;
+ xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
+ LOG_MODULE ": execution of rpc command %d (%s) failed, exiting ...\n", this->cur_func, "");
+ }
+
+ _x_unlock_port_rewiring(this->stream->xine);
+ }
+
+ _x_unlock_frontend(this->stream);
+ }
+ }
+ }
+
+ /* close control and result channel here to have vdr-xine initiate a disconnect for the above error case ... */
+ close(this->fh_control);
+ this->fh_control = -1;
+
+ close(this->fh_result);
+ this->fh_result = -1;
+
+ xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
+ LOG_MODULE ": rpc thread done.\n");
+
+ pthread_mutex_lock(&this->rpc_thread_shutdown_lock);
+ this->rpc_thread_shutdown = -1;
+ pthread_cond_broadcast(&this->rpc_thread_shutdown_cond);
+ pthread_mutex_unlock(&this->rpc_thread_shutdown_lock);
+
+ return 0;
+}
+
+static int internal_write_event_key(vdr_input_plugin_t *this, uint32_t key)
+{
+ event_key_t event;
+ event.header.func = func_key;
+ event.header.len = sizeof (event);
+
+ event.key = key;
+
+ if (sizeof (event) != vdr_write(this->fh_event, &event, sizeof (event)))
+ return -1;
+
+ return 0;
+}
+
+static int internal_write_event_frame_size(vdr_input_plugin_t *this)
+{
+ event_frame_size_t event;
+ event.header.func = func_frame_size;
+ event.header.len = sizeof (event);
+
+ event.left = this->frame_size.x;
+ event.top = this->frame_size.y;
+ event.width = this->frame_size.w,
+ event.height = this->frame_size.h;
+ event.zoom_x = xine_get_param(this->stream, XINE_PARAM_VO_ZOOM_X);
+ event.zoom_y = xine_get_param(this->stream, XINE_PARAM_VO_ZOOM_Y);
+
+ if (sizeof (event) != vdr_write(this->fh_event, &event, sizeof (event)))
+ return -1;
+
+ return 0;
+}
+
+static int internal_write_event_play_external(vdr_input_plugin_t *this, uint32_t key)
+{
+ event_play_external_t event;
+ event.header.func = func_play_external;
+ event.header.len = sizeof (event);
+
+ event.key = key;
+
+ if (sizeof (event) != vdr_write(this->fh_event, &event, sizeof (event)))
+ return -1;
+
+ return 0;
+}
+
+static off_t vdr_plugin_read(input_plugin_t *this_gen,
+ char *buf, off_t len)
+{
+ vdr_input_plugin_t *this = (vdr_input_plugin_t *) this_gen;
+ off_t n, total;
+#ifdef LOG_READ
+ lprintf ("reading %lld bytes...\n", len);
+#endif
+ total=0;
+ if (this->curpos < this->preview_size)
+ {
+ n = this->preview_size - this->curpos;
+ if (n > (len - total))
+ n = len - total;
+#ifdef LOG_READ
+ lprintf ("%lld bytes from preview (which has %lld bytes)\n",
+ n, this->preview_size);
+#endif
+ memcpy (&buf[total], &this->preview[this->curpos], n);
+ this->curpos += n;
+ total += n;
+ }
+
+ if( (len-total) > 0 )
+ {
+ int retries = 0;
+ do
+ {
+ n = vdr_read_abort (this->stream, this->fh, &buf[total], len-total);
+ if (0 == n)
+ lprintf("read 0, retries: %d\n", retries);
+ }
+ while (0 == n
+ && !this->stream_external
+ && _x_continue_stream_processing(this->stream)
+ && 200 > retries++); /* 200 * 50ms */
+#ifdef LOG_READ
+ lprintf ("got %lld bytes (%lld/%lld bytes read)\n",
+ n,total,len);
+#endif
+ if (n < 0)
+ {
+ _x_message(this->stream, XINE_MSG_READ_ERROR, NULL);
+ return 0;
+ }
+
+ this->curpos += n;
+ total += n;
+ }
+ return total;
+}
+
+static buf_element_t *vdr_plugin_read_block(input_plugin_t *this_gen, fifo_buffer_t *fifo,
+ off_t todo)
+{
+ off_t total_bytes;
+ buf_element_t *buf = fifo->buffer_pool_alloc(fifo);
+
+ buf->content = buf->mem;
+ buf->type = BUF_DEMUX_BLOCK;
+
+ total_bytes = vdr_plugin_read(this_gen, (char *)buf->content, todo);
+
+ if (total_bytes != todo)
+ {
+ buf->free_buffer(buf);
+ return NULL;
+ }
+
+ buf->size = total_bytes;
+
+ return buf;
+}
+
+/* forward reference */
+static off_t vdr_plugin_get_current_pos(input_plugin_t *this_gen);
+
+static off_t vdr_plugin_seek(input_plugin_t *this_gen, off_t offset, int origin)
+{
+ vdr_input_plugin_t *this = (vdr_input_plugin_t *)this_gen;
+
+ lprintf("seek %lld offset, %d origin...\n",
+ offset, origin);
+
+ if ((origin == SEEK_CUR) && (offset >= 0))
+ {
+ for ( ; ((int)offset) - BUF_SIZE > 0; offset -= BUF_SIZE)
+ {
+ if (!this_gen->read(this_gen, this->seek_buf, BUF_SIZE))
+ return this->curpos;
+ }
+
+ this_gen->read (this_gen, this->seek_buf, offset);
+ }
+
+ if (origin == SEEK_SET)
+ {
+ if (offset < this->curpos)
+ {
+ if (this->curpos <= this->preview_size)
+ this->curpos = offset;
+ else
+ lprintf("cannot seek back! (%lld > %lld)\n", this->curpos, offset);
+ }
+ else
+ {
+ offset -= this->curpos;
+
+ for ( ; ((int)offset) - BUF_SIZE > 0; offset -= BUF_SIZE)
+ {
+ if (!this_gen->read(this_gen, this->seek_buf, BUF_SIZE))
+ return this->curpos;
+ }
+
+ this_gen->read(this_gen, this->seek_buf, offset);
+ }
+ }
+
+ return this->curpos;
+}
+
+static off_t vdr_plugin_get_length(input_plugin_t *this_gen)
+{
+ return 0;
+}
+
+static uint32_t vdr_plugin_get_capabilities(input_plugin_t *this_gen)
+{
+ return INPUT_CAP_NOCAP; /* INPUT_CAP_PREVIEW; */
+}
+
+static uint32_t vdr_plugin_get_blocksize(input_plugin_t *this_gen)
+{
+ return 0;
+}
+
+static off_t vdr_plugin_get_current_pos(input_plugin_t *this_gen)
+{
+ vdr_input_plugin_t *this = (vdr_input_plugin_t *)this_gen;
+
+ return this->curpos;
+}
+
+static const char *vdr_plugin_get_mrl(input_plugin_t *this_gen)
+{
+ vdr_input_plugin_t *this = (vdr_input_plugin_t *)this_gen;
+
+ return this->mrl;
+}
+
+static void vdr_plugin_dispose(input_plugin_t *this_gen)
+{
+ vdr_input_plugin_t *this = (vdr_input_plugin_t *)this_gen;
+ int i;
+
+ external_stream_stop(this);
+
+ if (this->event_queue)
+ xine_event_dispose_queue(this->event_queue);
+
+ if (this->rpc_thread)
+ {
+ struct timespec abstime;
+ int ms_to_time_out = 10000;
+
+ xprintf(this->stream->xine, XINE_VERBOSITY_LOG, _(LOG_MODULE ": shutting down rpc thread (timeout: %d ms) ...\n"), ms_to_time_out);
+
+ pthread_mutex_lock(&this->rpc_thread_shutdown_lock);
+
+ if (this->rpc_thread_shutdown > -1)
+ {
+ this->rpc_thread_shutdown = 1;
+
+ {
+ struct timeval now;
+ gettimeofday(&now, 0);
+
+ abstime.tv_sec = now.tv_sec + ms_to_time_out / 1000;
+ abstime.tv_nsec = now.tv_usec * 1000 + (ms_to_time_out % 1000) * 1e6;
+
+ if (abstime.tv_nsec > 1e9)
+ {
+ abstime.tv_nsec -= 1e9;
+ abstime.tv_sec++;
+ }
+ }
+
+ if (0 != pthread_cond_timedwait(&this->rpc_thread_shutdown_cond, &this->rpc_thread_shutdown_lock, &abstime))
+ {
+ xprintf(this->stream->xine, XINE_VERBOSITY_LOG, _(LOG_MODULE ": cancelling rpc thread in function %d...\n"), this->cur_func);
+ pthread_cancel(this->rpc_thread);
+ }
+ }
+
+ pthread_mutex_unlock(&this->rpc_thread_shutdown_lock);
+
+ xprintf(this->stream->xine, XINE_VERBOSITY_LOG, _(LOG_MODULE ": joining rpc thread ...\n"));
+ pthread_join(this->rpc_thread, 0);
+ xprintf(this->stream->xine, XINE_VERBOSITY_LOG, _(LOG_MODULE ": rpc thread joined.\n"));
+ }
+
+ pthread_cond_destroy(&this->rpc_thread_shutdown_cond);
+ pthread_mutex_destroy(&this->rpc_thread_shutdown_lock);
+
+ pthread_mutex_destroy(&this->adjust_zoom_lock);
+
+ if (this->fh_result != -1)
+ close(this->fh_result);
+
+ if (this->fh_control != -1)
+ close(this->fh_control);
+
+ if (this->fh_event != -1)
+ close(this->fh_event);
+
+ for (i = 0; i < VDR_MAX_NUM_WINDOWS; i++)
+ {
+ if (0 == this->osd_window[ i ])
+ continue;
+
+ xine_osd_hide(this->osd_window[ i ], 0);
+ xine_osd_free(this->osd_window[ i ]);
+ }
+
+ if (this->osd_buffer)
+ free(this->osd_buffer);
+
+ if ((this->fh != STDIN_FILENO) && (this->fh != -1))
+ close(this->fh);
+
+ free(this->mrl);
+ free(this);
+}
+
+static int vdr_plugin_get_optional_data(input_plugin_t *this_gen,
+ void *data, int data_type)
+{
+ vdr_input_plugin_t *this = (vdr_input_plugin_t *)this_gen;
+ int preview_size = (this->preview_size > MAX_PREVIEW_SIZE) ? MAX_PREVIEW_SIZE : this->preview_size;
+/*
+ switch (data_type)
+ {
+ case INPUT_OPTIONAL_DATA_PREVIEW:
+ memcpy (data, this->preview, preview_size);
+ return preview_size;
+ }
+*/
+ return INPUT_OPTIONAL_UNSUPPORTED;
+}
+
+static uint8_t preview_mpg_data[] =
+{
+/* 0x0000 */ 0x00, 0x00, 0x01, 0xb3, 0x2d, 0x02, 0x40, 0x23, 0x12, 0x4f, 0xa3, 0x80, 0x00, 0x00, 0x01, 0xb5,
+/* 0x0010 */ 0x14, 0x82, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0xb5, 0x23, 0x05, 0x05, 0x05, 0x0b, 0x42,
+/* 0x0020 */ 0x12, 0x00, 0x00, 0x00, 0x01, 0xb8, 0x00, 0x08, 0x00, 0x40, 0x00, 0x00, 0x01, 0x00, 0x00, 0x0f,
+/* 0x0030 */ 0xff, 0xf8, 0x00, 0x00, 0x01, 0xb5, 0x8f, 0xff, 0xf7, 0xdd, 0x80, 0x00, 0x00, 0x01, 0x01, 0x0b,
+/* 0x0040 */ 0xfc, 0x3e, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61,
+/* 0x0050 */ 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86,
+/* 0x0060 */ 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18,
+/* 0x0070 */ 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61,
+/* 0x0080 */ 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86,
+/* 0x0090 */ 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b,
+/* 0x00a0 */ 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e,
+/* 0x00b0 */ 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8,
+/* 0x00c0 */ 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3,
+/* 0x00d0 */ 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d,
+/* 0x00e0 */ 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34,
+/* 0x00f0 */ 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1,
+/* 0x0100 */ 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46,
+/* 0x0110 */ 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a,
+/* 0x0120 */ 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x60, 0x00, 0x00,
+/* 0x0130 */ 0x01, 0x02, 0x0b, 0xfc, 0x3e, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d,
+/* 0x0140 */ 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34,
+/* 0x0150 */ 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1,
+/* 0x0160 */ 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46,
+/* 0x0170 */ 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a,
+/* 0x0180 */ 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68,
+/* 0x0190 */ 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3,
+/* 0x01a0 */ 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d,
+/* 0x01b0 */ 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34,
+/* 0x01c0 */ 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1,
+/* 0x01d0 */ 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46,
+/* 0x01e0 */ 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18,
+/* 0x01f0 */ 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61,
+/* 0x0200 */ 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86,
+/* 0x0210 */ 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18,
+/* 0x0220 */ 0x60, 0x00, 0x00, 0x01, 0x03, 0x0b, 0xfc, 0x3e, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1,
+/* 0x0230 */ 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46,
+/* 0x0240 */ 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18,
+/* 0x0250 */ 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61,
+/* 0x0260 */ 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86,
+/* 0x0270 */ 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18,
+/* 0x0280 */ 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61,
+/* 0x0290 */ 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86,
+/* 0x02a0 */ 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b,
+/* 0x02b0 */ 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e,
+/* 0x02c0 */ 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8,
+/* 0x02d0 */ 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3,
+/* 0x02e0 */ 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d,
+/* 0x02f0 */ 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34,
+/* 0x0300 */ 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1,
+/* 0x0310 */ 0xa3, 0x46, 0x18, 0x60, 0x00, 0x00, 0x01, 0x04, 0x0b, 0xfc, 0x3e, 0xd1, 0xa3, 0x46, 0x18, 0x6e,
+/* 0x0320 */ 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8,
+/* 0x0330 */ 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3,
+/* 0x0340 */ 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d,
+/* 0x0350 */ 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34,
+/* 0x0360 */ 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1,
+/* 0x0370 */ 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46,
+/* 0x0380 */ 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a,
+/* 0x0390 */ 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68,
+/* 0x03a0 */ 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3,
+/* 0x03b0 */ 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d,
+/* 0x03c0 */ 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34,
+/* 0x03d0 */ 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1,
+/* 0x03e0 */ 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46,
+/* 0x03f0 */ 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18,
+/* 0x0400 */ 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x60, 0x00, 0x00, 0x01, 0x05, 0x0b, 0xfc, 0x3e, 0xd1, 0xa3,
+/* 0x0410 */ 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d,
+/* 0x0420 */ 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34,
+/* 0x0430 */ 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1,
+/* 0x0440 */ 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46,
+/* 0x0450 */ 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18,
+/* 0x0460 */ 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61,
+/* 0x0470 */ 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86,
+/* 0x0480 */ 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18,
+/* 0x0490 */ 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61,
+/* 0x04a0 */ 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86,
+/* 0x04b0 */ 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b,
+/* 0x04c0 */ 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e,
+/* 0x04d0 */ 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8,
+/* 0x04e0 */ 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3,
+/* 0x04f0 */ 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x60, 0x00, 0x00, 0x01, 0x06, 0x0b, 0xfc,
+/* 0x0500 */ 0x3e, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86,
+/* 0x0510 */ 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b,
+/* 0x0520 */ 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e,
+/* 0x0530 */ 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8,
+/* 0x0540 */ 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3,
+/* 0x0550 */ 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d,
+/* 0x0560 */ 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34,
+/* 0x0570 */ 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1,
+/* 0x0580 */ 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46,
+/* 0x0590 */ 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a,
+/* 0x05a0 */ 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68,
+/* 0x05b0 */ 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3,
+/* 0x05c0 */ 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d,
+/* 0x05d0 */ 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34,
+/* 0x05e0 */ 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x60, 0x00, 0x00, 0x01,
+/* 0x05f0 */ 0x07, 0x0b, 0xfc, 0x3e, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a,
+/* 0x0600 */ 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68,
+/* 0x0610 */ 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3,
+/* 0x0620 */ 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d,
+/* 0x0630 */ 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34,
+/* 0x0640 */ 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1,
+/* 0x0650 */ 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46,
+/* 0x0660 */ 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18,
+/* 0x0670 */ 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61,
+/* 0x0680 */ 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86,
+/* 0x0690 */ 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18,
+/* 0x06a0 */ 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61,
+/* 0x06b0 */ 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86,
+/* 0x06c0 */ 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b,
+/* 0x06d0 */ 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x60,
+/* 0x06e0 */ 0x00, 0x00, 0x01, 0x08, 0x0b, 0xfc, 0x3e, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86,
+/* 0x06f0 */ 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18,
+/* 0x0700 */ 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61,
+/* 0x0710 */ 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86,
+/* 0x0720 */ 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b,
+/* 0x0730 */ 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e,
+/* 0x0740 */ 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8,
+/* 0x0750 */ 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3,
+/* 0x0760 */ 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d,
+/* 0x0770 */ 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34,
+/* 0x0780 */ 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1,
+/* 0x0790 */ 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46,
+/* 0x07a0 */ 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a,
+/* 0x07b0 */ 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68,
+/* 0x07c0 */ 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3,
+/* 0x07d0 */ 0x46, 0x18, 0x60, 0x00, 0x00, 0x01, 0x09, 0x0b, 0xfc, 0x3e, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34,
+/* 0x07e0 */ 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1,
+/* 0x07f0 */ 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46,
+/* 0x0800 */ 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a,
+/* 0x0810 */ 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68,
+/* 0x0820 */ 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3,
+/* 0x0830 */ 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d,
+/* 0x0840 */ 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34,
+/* 0x0850 */ 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1,
+/* 0x0860 */ 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46,
+/* 0x0870 */ 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18,
+/* 0x0880 */ 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61,
+/* 0x0890 */ 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86,
+/* 0x08a0 */ 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18,
+/* 0x08b0 */ 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61,
+/* 0x08c0 */ 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x60, 0x00, 0x00, 0x01, 0x0a, 0x0b, 0xfc, 0x3e, 0xd1, 0xa3, 0x46,
+/* 0x08d0 */ 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18,
+/* 0x08e0 */ 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61,
+/* 0x08f0 */ 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86,
+/* 0x0900 */ 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18,
+/* 0x0910 */ 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61,
+/* 0x0920 */ 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86,
+/* 0x0930 */ 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b,
+/* 0x0940 */ 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e,
+/* 0x0950 */ 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8,
+/* 0x0960 */ 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3,
+/* 0x0970 */ 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d,
+/* 0x0980 */ 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34,
+/* 0x0990 */ 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1,
+/* 0x09a0 */ 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46,
+/* 0x09b0 */ 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x60, 0x00, 0x00, 0x01, 0x0b, 0x0b, 0xfc, 0x3e,
+/* 0x09c0 */ 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3,
+/* 0x09d0 */ 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d,
+/* 0x09e0 */ 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34,
+/* 0x09f0 */ 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1,
+/* 0x0a00 */ 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46,
+/* 0x0a10 */ 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a,
+/* 0x0a20 */ 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68,
+/* 0x0a30 */ 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3,
+/* 0x0a40 */ 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d,
+/* 0x0a50 */ 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34,
+/* 0x0a60 */ 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1,
+/* 0x0a70 */ 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46,
+/* 0x0a80 */ 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18,
+/* 0x0a90 */ 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61,
+/* 0x0aa0 */ 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x60, 0x00, 0x00, 0x01, 0x0c,
+/* 0x0ab0 */ 0x0b, 0xfc, 0x3e, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34,
+/* 0x0ac0 */ 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1,
+/* 0x0ad0 */ 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46,
+/* 0x0ae0 */ 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18,
+/* 0x0af0 */ 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61,
+/* 0x0b00 */ 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86,
+/* 0x0b10 */ 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18,
+/* 0x0b20 */ 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61,
+/* 0x0b30 */ 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86,
+/* 0x0b40 */ 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b,
+/* 0x0b50 */ 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e,
+/* 0x0b60 */ 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8,
+/* 0x0b70 */ 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3,
+/* 0x0b80 */ 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d,
+/* 0x0b90 */ 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x60, 0x00,
+/* 0x0ba0 */ 0x00, 0x01, 0x0d, 0x0b, 0xfc, 0x3e, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b,
+/* 0x0bb0 */ 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e,
+/* 0x0bc0 */ 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8,
+/* 0x0bd0 */ 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3,
+/* 0x0be0 */ 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d,
+/* 0x0bf0 */ 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34,
+/* 0x0c00 */ 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1,
+/* 0x0c10 */ 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46,
+/* 0x0c20 */ 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a,
+/* 0x0c30 */ 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68,
+/* 0x0c40 */ 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3,
+/* 0x0c50 */ 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d,
+/* 0x0c60 */ 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34,
+/* 0x0c70 */ 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1,
+/* 0x0c80 */ 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46,
+/* 0x0c90 */ 0x18, 0x60, 0x00, 0x00, 0x01, 0x0e, 0x0b, 0xfc, 0x3e, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68,
+/* 0x0ca0 */ 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3,
+/* 0x0cb0 */ 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d,
+/* 0x0cc0 */ 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34,
+/* 0x0cd0 */ 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1,
+/* 0x0ce0 */ 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46,
+/* 0x0cf0 */ 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18,
+/* 0x0d00 */ 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61,
+/* 0x0d10 */ 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86,
+/* 0x0d20 */ 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18,
+/* 0x0d30 */ 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61,
+/* 0x0d40 */ 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86,
+/* 0x0d50 */ 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b,
+/* 0x0d60 */ 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e,
+/* 0x0d70 */ 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8,
+/* 0x0d80 */ 0xd1, 0xa3, 0x46, 0x18, 0x60, 0x00, 0x00, 0x01, 0x0f, 0x0b, 0xfc, 0x3e, 0xd1, 0xa3, 0x46, 0x18,
+/* 0x0d90 */ 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61,
+/* 0x0da0 */ 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86,
+/* 0x0db0 */ 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b,
+/* 0x0dc0 */ 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e,
+/* 0x0dd0 */ 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8,
+/* 0x0de0 */ 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3,
+/* 0x0df0 */ 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d,
+/* 0x0e00 */ 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34,
+/* 0x0e10 */ 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1,
+/* 0x0e20 */ 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46,
+/* 0x0e30 */ 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a,
+/* 0x0e40 */ 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68,
+/* 0x0e50 */ 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3,
+/* 0x0e60 */ 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d,
+/* 0x0e70 */ 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x60, 0x00, 0x00, 0x01, 0x10, 0x0b, 0xfc, 0x3e, 0xd1,
+/* 0x0e80 */ 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46,
+/* 0x0e90 */ 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a,
+/* 0x0ea0 */ 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68,
+/* 0x0eb0 */ 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3,
+/* 0x0ec0 */ 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d,
+/* 0x0ed0 */ 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34,
+/* 0x0ee0 */ 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1,
+/* 0x0ef0 */ 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46,
+/* 0x0f00 */ 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18,
+/* 0x0f10 */ 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61,
+/* 0x0f20 */ 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86,
+/* 0x0f30 */ 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18,
+/* 0x0f40 */ 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61,
+/* 0x0f50 */ 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86,
+/* 0x0f60 */ 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x60, 0x00, 0x00, 0x01, 0x11, 0x0b,
+/* 0x0f70 */ 0xfc, 0x3e, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61,
+/* 0x0f80 */ 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86,
+/* 0x0f90 */ 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18,
+/* 0x0fa0 */ 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61,
+/* 0x0fb0 */ 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86,
+/* 0x0fc0 */ 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b,
+/* 0x0fd0 */ 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e,
+/* 0x0fe0 */ 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8,
+/* 0x0ff0 */ 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3,
+/* 0x1000 */ 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d,
+/* 0x1010 */ 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34,
+/* 0x1020 */ 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1,
+/* 0x1030 */ 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46,
+/* 0x1040 */ 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a,
+/* 0x1050 */ 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x60, 0x00, 0x00,
+/* 0x1060 */ 0x01, 0x12, 0x0b, 0xfc, 0x3e, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d,
+/* 0x1070 */ 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34,
+/* 0x1080 */ 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1,
+/* 0x1090 */ 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46,
+/* 0x10a0 */ 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a,
+/* 0x10b0 */ 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68,
+/* 0x10c0 */ 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3,
+/* 0x10d0 */ 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d,
+/* 0x10e0 */ 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34,
+/* 0x10f0 */ 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1,
+/* 0x1100 */ 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46,
+/* 0x1110 */ 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18,
+/* 0x1120 */ 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61,
+/* 0x1130 */ 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86,
+/* 0x1140 */ 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18,
+/* 0x1150 */ 0x60, 0x00, 0x00, 0x01, 0x13, 0x0b, 0xfc, 0x3e, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1,
+/* 0x1160 */ 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46,
+/* 0x1170 */ 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18,
+/* 0x1180 */ 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61,
+/* 0x1190 */ 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86,
+/* 0x11a0 */ 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18,
+/* 0x11b0 */ 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61,
+/* 0x11c0 */ 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86,
+/* 0x11d0 */ 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b,
+/* 0x11e0 */ 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e,
+/* 0x11f0 */ 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8,
+/* 0x1200 */ 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3,
+/* 0x1210 */ 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d,
+/* 0x1220 */ 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34,
+/* 0x1230 */ 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1,
+/* 0x1240 */ 0xa3, 0x46, 0x18, 0x60, 0x00, 0x00, 0x01, 0x14, 0x0b, 0xfc, 0x3e, 0xd1, 0xa3, 0x46, 0x18, 0x6e,
+/* 0x1250 */ 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8,
+/* 0x1260 */ 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3,
+/* 0x1270 */ 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d,
+/* 0x1280 */ 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34,
+/* 0x1290 */ 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1,
+/* 0x12a0 */ 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46,
+/* 0x12b0 */ 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a,
+/* 0x12c0 */ 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68,
+/* 0x12d0 */ 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3,
+/* 0x12e0 */ 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d,
+/* 0x12f0 */ 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34,
+/* 0x1300 */ 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1,
+/* 0x1310 */ 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46,
+/* 0x1320 */ 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18,
+/* 0x1330 */ 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x60, 0x00, 0x00, 0x01, 0x15, 0x0b, 0xfc, 0x3e, 0xd1, 0xa3,
+/* 0x1340 */ 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d,
+/* 0x1350 */ 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34,
+/* 0x1360 */ 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1,
+/* 0x1370 */ 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46,
+/* 0x1380 */ 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18,
+/* 0x1390 */ 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61,
+/* 0x13a0 */ 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86,
+/* 0x13b0 */ 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18,
+/* 0x13c0 */ 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61,
+/* 0x13d0 */ 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86,
+/* 0x13e0 */ 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b,
+/* 0x13f0 */ 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e,
+/* 0x1400 */ 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8,
+/* 0x1410 */ 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3,
+/* 0x1420 */ 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x60, 0x00, 0x00, 0x01, 0x16, 0x0b, 0xfc,
+/* 0x1430 */ 0x3e, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86,
+/* 0x1440 */ 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b,
+/* 0x1450 */ 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e,
+/* 0x1460 */ 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8,
+/* 0x1470 */ 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3,
+/* 0x1480 */ 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d,
+/* 0x1490 */ 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34,
+/* 0x14a0 */ 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1,
+/* 0x14b0 */ 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46,
+/* 0x14c0 */ 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a,
+/* 0x14d0 */ 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68,
+/* 0x14e0 */ 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3,
+/* 0x14f0 */ 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d,
+/* 0x1500 */ 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34,
+/* 0x1510 */ 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x60, 0x00, 0x00, 0x01,
+/* 0x1520 */ 0x17, 0x0b, 0xfc, 0x3e, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a,
+/* 0x1530 */ 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68,
+/* 0x1540 */ 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3,
+/* 0x1550 */ 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d,
+/* 0x1560 */ 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34,
+/* 0x1570 */ 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1,
+/* 0x1580 */ 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46,
+/* 0x1590 */ 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18,
+/* 0x15a0 */ 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61,
+/* 0x15b0 */ 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86,
+/* 0x15c0 */ 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18,
+/* 0x15d0 */ 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61,
+/* 0x15e0 */ 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86,
+/* 0x15f0 */ 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b,
+/* 0x1600 */ 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x60,
+/* 0x1610 */ 0x00, 0x00, 0x01, 0x18, 0x0b, 0xfc, 0x3e, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86,
+/* 0x1620 */ 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18,
+/* 0x1630 */ 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61,
+/* 0x1640 */ 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86,
+/* 0x1650 */ 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b,
+/* 0x1660 */ 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e,
+/* 0x1670 */ 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8,
+/* 0x1680 */ 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3,
+/* 0x1690 */ 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d,
+/* 0x16a0 */ 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34,
+/* 0x16b0 */ 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1,
+/* 0x16c0 */ 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46,
+/* 0x16d0 */ 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a,
+/* 0x16e0 */ 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68,
+/* 0x16f0 */ 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3,
+/* 0x1700 */ 0x46, 0x18, 0x60, 0x00, 0x00, 0x01, 0x19, 0x0b, 0xfc, 0x3e, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34,
+/* 0x1710 */ 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1,
+/* 0x1720 */ 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46,
+/* 0x1730 */ 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a,
+/* 0x1740 */ 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68,
+/* 0x1750 */ 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3,
+/* 0x1760 */ 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d,
+/* 0x1770 */ 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34,
+/* 0x1780 */ 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1,
+/* 0x1790 */ 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46,
+/* 0x17a0 */ 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18,
+/* 0x17b0 */ 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61,
+/* 0x17c0 */ 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86,
+/* 0x17d0 */ 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18,
+/* 0x17e0 */ 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61,
+/* 0x17f0 */ 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x60, 0x00, 0x00, 0x01, 0x1a, 0x0b, 0xfc, 0x3e, 0xd1, 0xa3, 0x46,
+/* 0x1800 */ 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18,
+/* 0x1810 */ 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61,
+/* 0x1820 */ 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86,
+/* 0x1830 */ 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18,
+/* 0x1840 */ 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61,
+/* 0x1850 */ 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86,
+/* 0x1860 */ 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b,
+/* 0x1870 */ 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e,
+/* 0x1880 */ 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8,
+/* 0x1890 */ 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3,
+/* 0x18a0 */ 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d,
+/* 0x18b0 */ 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34,
+/* 0x18c0 */ 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1,
+/* 0x18d0 */ 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46,
+/* 0x18e0 */ 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x60, 0x00, 0x00, 0x01, 0x1b, 0x0b, 0xfc, 0x3e,
+/* 0x18f0 */ 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3,
+/* 0x1900 */ 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d,
+/* 0x1910 */ 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34,
+/* 0x1920 */ 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1,
+/* 0x1930 */ 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46,
+/* 0x1940 */ 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a,
+/* 0x1950 */ 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68,
+/* 0x1960 */ 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3,
+/* 0x1970 */ 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d,
+/* 0x1980 */ 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34,
+/* 0x1990 */ 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1,
+/* 0x19a0 */ 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46,
+/* 0x19b0 */ 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18,
+/* 0x19c0 */ 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61,
+/* 0x19d0 */ 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x60, 0x00, 0x00, 0x01, 0x1c,
+/* 0x19e0 */ 0x0b, 0xfc, 0x3e, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34,
+/* 0x19f0 */ 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1,
+/* 0x1a00 */ 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46,
+/* 0x1a10 */ 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18,
+/* 0x1a20 */ 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61,
+/* 0x1a30 */ 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86,
+/* 0x1a40 */ 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18,
+/* 0x1a50 */ 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61,
+/* 0x1a60 */ 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86,
+/* 0x1a70 */ 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b,
+/* 0x1a80 */ 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e,
+/* 0x1a90 */ 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8,
+/* 0x1aa0 */ 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3,
+/* 0x1ab0 */ 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d,
+/* 0x1ac0 */ 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x60, 0x00,
+/* 0x1ad0 */ 0x00, 0x01, 0x1d, 0x0b, 0xfc, 0x3e, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b,
+/* 0x1ae0 */ 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e,
+/* 0x1af0 */ 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8,
+/* 0x1b00 */ 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3,
+/* 0x1b10 */ 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d,
+/* 0x1b20 */ 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34,
+/* 0x1b30 */ 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1,
+/* 0x1b40 */ 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46,
+/* 0x1b50 */ 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a,
+/* 0x1b60 */ 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68,
+/* 0x1b70 */ 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3,
+/* 0x1b80 */ 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d,
+/* 0x1b90 */ 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34,
+/* 0x1ba0 */ 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1,
+/* 0x1bb0 */ 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46,
+/* 0x1bc0 */ 0x18, 0x60, 0x00, 0x00, 0x01, 0x1e, 0x0b, 0xfc, 0x3e, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68,
+/* 0x1bd0 */ 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3,
+/* 0x1be0 */ 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d,
+/* 0x1bf0 */ 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34,
+/* 0x1c00 */ 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1,
+/* 0x1c10 */ 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46,
+/* 0x1c20 */ 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18,
+/* 0x1c30 */ 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61,
+/* 0x1c40 */ 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86,
+/* 0x1c50 */ 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18,
+/* 0x1c60 */ 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61,
+/* 0x1c70 */ 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86,
+/* 0x1c80 */ 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b,
+/* 0x1c90 */ 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e,
+/* 0x1ca0 */ 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8,
+/* 0x1cb0 */ 0xd1, 0xa3, 0x46, 0x18, 0x60, 0x00, 0x00, 0x01, 0x1f, 0x0b, 0xfc, 0x3e, 0xd1, 0xa3, 0x46, 0x18,
+/* 0x1cc0 */ 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61,
+/* 0x1cd0 */ 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86,
+/* 0x1ce0 */ 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b,
+/* 0x1cf0 */ 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e,
+/* 0x1d00 */ 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8,
+/* 0x1d10 */ 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3,
+/* 0x1d20 */ 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d,
+/* 0x1d30 */ 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34,
+/* 0x1d40 */ 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1,
+/* 0x1d50 */ 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46,
+/* 0x1d60 */ 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a,
+/* 0x1d70 */ 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68,
+/* 0x1d80 */ 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3,
+/* 0x1d90 */ 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d,
+/* 0x1da0 */ 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x60, 0x00, 0x00, 0x01, 0x20, 0x0b, 0xfc, 0x3e, 0xd1,
+/* 0x1db0 */ 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46,
+/* 0x1dc0 */ 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a,
+/* 0x1dd0 */ 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68,
+/* 0x1de0 */ 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3,
+/* 0x1df0 */ 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d,
+/* 0x1e00 */ 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34,
+/* 0x1e10 */ 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1,
+/* 0x1e20 */ 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46,
+/* 0x1e30 */ 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18,
+/* 0x1e40 */ 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61,
+/* 0x1e50 */ 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86,
+/* 0x1e60 */ 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18,
+/* 0x1e70 */ 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61,
+/* 0x1e80 */ 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86,
+/* 0x1e90 */ 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x60, 0x00, 0x00, 0x01, 0x21, 0x0b,
+/* 0x1ea0 */ 0xfc, 0x3e, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61,
+/* 0x1eb0 */ 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86,
+/* 0x1ec0 */ 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18,
+/* 0x1ed0 */ 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61,
+/* 0x1ee0 */ 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86,
+/* 0x1ef0 */ 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b,
+/* 0x1f00 */ 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e,
+/* 0x1f10 */ 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8,
+/* 0x1f20 */ 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3,
+/* 0x1f30 */ 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d,
+/* 0x1f40 */ 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34,
+/* 0x1f50 */ 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1,
+/* 0x1f60 */ 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46,
+/* 0x1f70 */ 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a,
+/* 0x1f80 */ 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x60, 0x00, 0x00,
+/* 0x1f90 */ 0x01, 0x22, 0x0b, 0xfc, 0x3e, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d,
+/* 0x1fa0 */ 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34,
+/* 0x1fb0 */ 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1,
+/* 0x1fc0 */ 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46,
+/* 0x1fd0 */ 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a,
+/* 0x1fe0 */ 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68,
+/* 0x1ff0 */ 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3,
+/* 0x2000 */ 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d,
+/* 0x2010 */ 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34,
+/* 0x2020 */ 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1,
+/* 0x2030 */ 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46,
+/* 0x2040 */ 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18,
+/* 0x2050 */ 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61,
+/* 0x2060 */ 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86,
+/* 0x2070 */ 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18,
+/* 0x2080 */ 0x60, 0x00, 0x00, 0x01, 0x23, 0x0b, 0xfc, 0x3e, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1,
+/* 0x2090 */ 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46,
+/* 0x20a0 */ 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18,
+/* 0x20b0 */ 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61,
+/* 0x20c0 */ 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86,
+/* 0x20d0 */ 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18,
+/* 0x20e0 */ 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61,
+/* 0x20f0 */ 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86,
+/* 0x2100 */ 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b,
+/* 0x2110 */ 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e,
+/* 0x2120 */ 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8,
+/* 0x2130 */ 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3,
+/* 0x2140 */ 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d,
+/* 0x2150 */ 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34,
+/* 0x2160 */ 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1,
+/* 0x2170 */ 0xa3, 0x46, 0x18, 0x60, 0x00, 0x00, 0x01, 0x24, 0x0b, 0xfc, 0x3e, 0xd1, 0xa3, 0x46, 0x18, 0x6e,
+/* 0x2180 */ 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8,
+/* 0x2190 */ 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3,
+/* 0x21a0 */ 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d,
+/* 0x21b0 */ 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34,
+/* 0x21c0 */ 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1,
+/* 0x21d0 */ 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46,
+/* 0x21e0 */ 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a,
+/* 0x21f0 */ 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68,
+/* 0x2200 */ 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3,
+/* 0x2210 */ 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d,
+/* 0x2220 */ 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34,
+/* 0x2230 */ 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x6e, 0x34, 0x68, 0xd1,
+/* 0x2240 */ 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18, 0x61, 0xb8, 0xd1, 0xa3, 0x46,
+/* 0x2250 */ 0x18, 0x6e, 0x34, 0x68, 0xd1, 0x86, 0x1b, 0x8d, 0x1a, 0x34, 0x61, 0x86, 0xe3, 0x46, 0x8d, 0x18,
+/* 0x2260 */ 0x61, 0xb8, 0xd1, 0xa3, 0x46, 0x18, 0x60, 0x00, 0x00, 0x01, 0xb7
+/* 0x226b */
+};
+
+static uint8_t preview_data[ sizeof (preview_mpg_data) + ((sizeof (preview_mpg_data) - 1) / (2048 - 6 - 3) + 1) * (6 + 3) ];
+
+static int vdr_plugin_open(input_plugin_t *this_gen)
+{
+ vdr_input_plugin_t *this = (vdr_input_plugin_t *)this_gen;
+
+ lprintf("trying to open '%s'...\n", this->mrl);
+
+ if (this->fh == -1)
+ {
+ char *filename;
+ int err = 0;
+
+ filename = (char *)&this->mrl[ 4 ];
+ this->fh = open(filename, O_RDONLY | O_NONBLOCK);
+
+ lprintf("filename '%s'\n", filename);
+
+ if (this->fh == -1)
+ {
+ xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
+ _(LOG_MODULE ": failed to open '%s' (%s)\n"),
+ filename,
+ strerror(errno));
+
+ return 0;
+ }
+
+ {
+ struct pollfd poll_fh = { this->fh, POLLIN, 0 };
+
+ int r = poll(&poll_fh, 1, 300);
+ if (1 != r)
+ {
+ xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
+ _(LOG_MODULE ": failed to open '%s' (%s)\n"),
+ filename,
+ _("timeout expired during setup phase"));
+
+ return 0;
+ }
+ }
+
+ fcntl(this->fh, F_SETFL, ~O_NONBLOCK & fcntl(this->fh, F_GETFL, 0));
+
+ {
+ char *filename_control = 0;
+ asprintf(&filename_control, "%s.control", filename);
+
+ this->fh_control = open(filename_control, O_RDONLY);
+
+ if (this->fh_control == -1) {
+ xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
+ _(LOG_MODULE ": failed to open '%s' (%s)\n"),
+ filename_control,
+ strerror(errno));
+
+ free(filename_control);
+ return 0;
+ }
+
+ free(filename_control);
+ }
+
+ {
+ char *filename_result = 0;
+ asprintf(&filename_result, "%s.result", filename);
+
+ this->fh_result = open(filename_result, O_WRONLY);
+
+ if (this->fh_result == -1) {
+ perror("failed");
+
+ xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
+ _(LOG_MODULE ": failed to open '%s' (%s)\n"),
+ filename_result,
+ strerror(errno));
+
+ free(filename_result);
+ return 0;
+ }
+
+ free(filename_result);
+ }
+
+ {
+ char *filename_event = 0;
+ asprintf(&filename_event, "%s.event", filename);
+
+ this->fh_event = open(filename_event, O_WRONLY);
+
+ if (this->fh_event == -1) {
+ perror("failed");
+
+ xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
+ _(LOG_MODULE ": failed to open '%s' (%s)\n"),
+ filename_event,
+ strerror(errno));
+
+ free(filename_event);
+ return 0;
+ }
+
+ free(filename_event);
+ }
+
+ this->rpc_thread_shutdown = 0;
+ if ((err = pthread_create(&this->rpc_thread, NULL,
+ vdr_rpc_thread_loop, (void *)this)) != 0)
+ {
+ xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
+ _(LOG_MODULE ": can't create new thread (%s)\n"),
+ strerror(err));
+
+ return 0;
+ }
+ }
+
+
+ /*
+ * mrl accepted and opened successfully at this point
+ *
+ * => create plugin instance
+ */
+
+ /*
+ * fill preview buffer
+ */
+
+ if (!preview_data[ 2 ])
+ {
+ uint8_t *src = preview_mpg_data;
+ uint8_t *dst = preview_data;
+ int todo = sizeof (preview_mpg_data);
+ int bite = 2048 - 6 - 3;
+
+ while (todo > 0)
+ {
+ if (bite > todo)
+ bite = todo;
+
+ *dst++ = 0x00;
+ *dst++ = 0x00;
+ *dst++ = 0x01;
+ *dst++ = 0xe0;
+
+ *dst++ = (bite + 3) >> 8;
+ *dst++ = (bite + 3) & 0xff;
+
+ *dst++ = 0x80;
+ *dst++ = 0x00;
+ *dst++ = 0x00;
+
+ memcpy(dst, src, bite);
+ dst += bite;
+ src += bite;
+
+ todo -= bite;
+ }
+ }
+
+ this->preview = (char *)&preview_data;
+ this->preview_size = 0; /* sizeof (preview_data); */
+ this->curpos = 0;
+
+ return 1;
+}
+
+static void event_handler(void *user_data, const xine_event_t *event)
+{
+ vdr_input_plugin_t *this = (vdr_input_plugin_t *)user_data;
+ uint32_t key = key_none;
+
+ lprintf("eventHandler(): event->type: %d\n", event->type);
+
+ if (XINE_EVENT_VDR_FRAMESIZECHANGED == event->type)
+ {
+ memcpy(&this->frame_size, event->data, event->data_length);
+
+ if (0 != internal_write_event_frame_size(this))
+ xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
+ _(LOG_MODULE ": input event write: %s.\n"), strerror(errno));
+
+ adjust_zoom(this);
+ return;
+ }
+ else if (XINE_EVENT_VDR_PLUGINSTARTED == event->type)
+ {
+ if (0 == event->data_length) /* vdr_video */
+ {
+ xine_event_t event;
+
+ event.type = XINE_EVENT_VDR_TRICKSPEEDMODE;
+ event.data = 0;
+ event.data_length = this->trick_speed_mode;
+
+ xine_event_send(this->stream, &event);
+ }
+ else if (1 == event->data_length) /* vdr_audio */
+ {
+ xine_event_t event;
+ vdr_select_audio_data_t event_data;
+
+ event_data.channels = this->audio_channels;
+
+ event.type = XINE_EVENT_VDR_SELECTAUDIO;
+ event.data = &event_data;
+ event.data_length = sizeof (event_data);
+
+ xine_event_send(this->stream, &event);
+ }
+ else
+ {
+ fprintf(stderr, "input_vdr: illegal XINE_EVENT_VDR_PLUGINSTARTED: %d\n", event->data_length);
+ }
+ }
+
+ switch (event->type)
+ {
+ case XINE_EVENT_INPUT_UP: key = key_up; break;
+ case XINE_EVENT_INPUT_DOWN: key = key_down; break;
+ case XINE_EVENT_INPUT_LEFT: key = key_left; break;
+ case XINE_EVENT_INPUT_RIGHT: key = key_right; break;
+ case XINE_EVENT_INPUT_SELECT: key = key_ok; break;
+ case XINE_EVENT_VDR_BACK: key = key_back; break;
+ case XINE_EVENT_VDR_CHANNELPLUS: key = key_channel_plus; break;
+ case XINE_EVENT_VDR_CHANNELMINUS: key = key_channel_minus; break;
+ case XINE_EVENT_VDR_RED: key = key_red; break;
+ case XINE_EVENT_VDR_GREEN: key = key_green; break;
+ case XINE_EVENT_VDR_YELLOW: key = key_yellow; break;
+ case XINE_EVENT_VDR_BLUE: key = key_blue; break;
+ case XINE_EVENT_VDR_PLAY: key = key_play; break;
+ case XINE_EVENT_VDR_PAUSE: key = key_pause; break;
+ case XINE_EVENT_VDR_STOP: key = key_stop; break;
+ case XINE_EVENT_VDR_RECORD: key = key_record; break;
+ case XINE_EVENT_VDR_FASTFWD: key = key_fast_fwd; break;
+ case XINE_EVENT_VDR_FASTREW: key = key_fast_rew; break;
+ case XINE_EVENT_VDR_POWER: key = key_power; break;
+ case XINE_EVENT_VDR_SCHEDULE: key = key_schedule; break;
+ case XINE_EVENT_VDR_CHANNELS: key = key_channels; break;
+ case XINE_EVENT_VDR_TIMERS: key = key_timers; break;
+ case XINE_EVENT_VDR_RECORDINGS: key = key_recordings; break;
+ case XINE_EVENT_INPUT_MENU1: key = key_menu; break;
+ case XINE_EVENT_VDR_SETUP: key = key_setup; break;
+ case XINE_EVENT_VDR_COMMANDS: key = key_commands; break;
+ case XINE_EVENT_INPUT_NUMBER_0: key = key_0; break;
+ case XINE_EVENT_INPUT_NUMBER_1: key = key_1; break;
+ case XINE_EVENT_INPUT_NUMBER_2: key = key_2; break;
+ case XINE_EVENT_INPUT_NUMBER_3: key = key_3; break;
+ case XINE_EVENT_INPUT_NUMBER_4: key = key_4; break;
+ case XINE_EVENT_INPUT_NUMBER_5: key = key_5; break;
+ case XINE_EVENT_INPUT_NUMBER_6: key = key_6; break;
+ case XINE_EVENT_INPUT_NUMBER_7: key = key_7; break;
+ case XINE_EVENT_INPUT_NUMBER_8: key = key_8; break;
+ case XINE_EVENT_INPUT_NUMBER_9: key = key_9; break;
+ case XINE_EVENT_VDR_USER1: key = key_user1; break;
+ case XINE_EVENT_VDR_USER2: key = key_user2; break;
+ case XINE_EVENT_VDR_USER3: key = key_user3; break;
+ case XINE_EVENT_VDR_USER4: key = key_user4; break;
+ case XINE_EVENT_VDR_USER5: key = key_user5; break;
+ case XINE_EVENT_VDR_USER6: key = key_user6; break;
+ case XINE_EVENT_VDR_USER7: key = key_user7; break;
+ case XINE_EVENT_VDR_USER8: key = key_user8; break;
+ case XINE_EVENT_VDR_USER9: key = key_user9; break;
+ case XINE_EVENT_VDR_VOLPLUS: key = key_volume_plus; break;
+ case XINE_EVENT_VDR_VOLMINUS: key = key_volume_minus; break;
+ case XINE_EVENT_VDR_MUTE: key = key_mute; break;
+ case XINE_EVENT_VDR_AUDIO: key = key_audio; break;
+ case XINE_EVENT_VDR_INFO: key = key_info; break;
+ case XINE_EVENT_VDR_CHANNELPREVIOUS: key = key_channel_previous; break;
+ case XINE_EVENT_INPUT_NEXT: key = key_next; break;
+ case XINE_EVENT_INPUT_PREVIOUS: key = key_previous; break;
+ default:
+ return;
+ }
+
+ if (0 != internal_write_event_key(this, key))
+ xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
+ _(LOG_MODULE ": input event write: %s.\n"), strerror(errno));
+}
+
+static input_plugin_t *vdr_class_get_instance(input_class_t *cls_gen, xine_stream_t *stream,
+ const char *data)
+{
+ vdr_input_plugin_t *this;
+ char *mrl = strdup(data);
+
+ if (!strncasecmp(mrl, "vdr:/", 5))
+ {
+ lprintf("filename '%s'\n", (char *)&mrl[ 4 ]);
+ }
+ else
+ {
+ free(mrl);
+ return NULL;
+ }
+
+ /*
+ * mrl accepted and opened successfully at this point
+ *
+ * => create plugin instance
+ */
+
+ this = (vdr_input_plugin_t *)xine_xmalloc(sizeof (vdr_input_plugin_t));
+
+ this->stream = stream;
+ this->curpos = 0;
+ this->mrl = mrl;
+ this->fh = -1;
+ this->fh_control = -1;
+ this->fh_result = -1;
+ this->fh_event = -1;
+
+ this->input_plugin.open = vdr_plugin_open;
+ this->input_plugin.get_capabilities = vdr_plugin_get_capabilities;
+ this->input_plugin.read = vdr_plugin_read;
+ this->input_plugin.read_block = vdr_plugin_read_block;
+ this->input_plugin.seek = vdr_plugin_seek;
+ this->input_plugin.get_current_pos = vdr_plugin_get_current_pos;
+ this->input_plugin.get_length = vdr_plugin_get_length;
+ this->input_plugin.get_blocksize = vdr_plugin_get_blocksize;
+ this->input_plugin.get_mrl = vdr_plugin_get_mrl;
+ this->input_plugin.dispose = vdr_plugin_dispose;
+ this->input_plugin.get_optional_data = vdr_plugin_get_optional_data;
+ this->input_plugin.input_class = cls_gen;
+
+ this->cur_func = func_unknown;
+ this->cur_size = 0;
+ this->cur_done = 0;
+
+ memset(this->osd_window, 0, sizeof (this->osd_window));
+
+ this->osd_buffer = 0;
+ this->osd_buffer_size = 0;
+ this->osd_unscaled_blending = 0;
+ this->trick_speed_mode = 0;
+ this->audio_channels = 0;
+ this->mute_mode = INPUT_VDR_MUTE_SIMULATE;
+ this->volume_mode = INPUT_VDR_VOLUME_CHANGE_HW;
+ this->last_volume = -1;
+ this->frame_size.x = 0;
+ this->frame_size.y = 0;
+ this->frame_size.w = 0;
+ this->frame_size.h = 0;
+ this->frame_size.r = 0;
+
+ this->stream_external = 0;
+ this->event_queue_external = 0;
+
+ pthread_mutex_init(&this->rpc_thread_shutdown_lock, 0);
+ pthread_cond_init(&this->rpc_thread_shutdown_cond, 0);
+
+ pthread_mutex_init(&this->adjust_zoom_lock, 0);
+ this->image4_3_zoom_x = 0;
+ this->image4_3_zoom_y = 0;
+ this->image16_9_zoom_x = 0;
+ this->image16_9_zoom_y = 0;
+
+ this->event_queue = xine_event_new_queue(this->stream);
+ if (this->event_queue)
+ xine_event_create_listener_thread(this->event_queue, event_handler, this);
+
+ return &this->input_plugin;
+}
+
+/*
+ * vdr input plugin class stuff
+ */
+
+static const char *vdr_class_get_description(input_class_t *this_gen)
+{
+ return _("VDR display device plugin");
+}
+
+static const char *vdr_class_get_identifier (input_class_t *this_gen)
+{
+ return "VDR";
+}
+
+static void vdr_class_dispose (input_class_t *this_gen)
+{
+ vdr_input_class_t *this = (vdr_input_class_t *)this_gen;
+
+ free(this);
+}
+
+static char **vdr_class_get_autoplay_list(input_class_t *this_gen,
+ int *num_files)
+{
+ vdr_input_class_t *class = (vdr_input_class_t *)this_gen;
+
+ *num_files = 1;
+ return class->mrls;
+}
+
+static void *init_class(xine_t *xine, void *data)
+{
+ vdr_input_class_t *this;
+
+ lprintf("init_class\n");
+
+ this = (vdr_input_class_t *)xine_xmalloc(sizeof (vdr_input_class_t));
+
+ this->xine = xine;
+
+ this->mrls[ 0 ] = "vdr:" VDR_ABS_FIFO_DIR "/stream#demux:mpeg_pes";
+ this->mrls[ 1 ] = 0;
+
+ this->input_class.get_instance = vdr_class_get_instance;
+ this->input_class.get_identifier = vdr_class_get_identifier;
+ this->input_class.get_description = vdr_class_get_description;
+ this->input_class.get_dir = NULL;
+ this->input_class.get_autoplay_list = vdr_class_get_autoplay_list;
+ this->input_class.dispose = vdr_class_dispose;
+ this->input_class.eject_media = NULL;
+
+ return this;
+}
+
+/*
+ * exported plugin catalog entry
+ */
+
+plugin_info_t xine_plugin_info[] EXPORTED =
+{
+ /* type, API, "name", version, special_info, init_function */
+ { PLUGIN_INPUT, 17, "VDR", XINE_VERSION_CODE, NULL, init_class },
+ { PLUGIN_NONE, 0, "", 0, NULL, NULL }
+};
+
diff --git a/src/vdr/input_vdr.h b/src/vdr/input_vdr.h
new file mode 100644
index 000000000..74c805bd0
--- /dev/null
+++ b/src/vdr/input_vdr.h
@@ -0,0 +1,596 @@
+
+#ifndef __INPUT_VDR_H
+#define __INPUT_VDR_H
+
+
+#define XINE_INPUT_VDR_VERSION 711
+
+
+enum funcs
+{
+ func_unknown = -1
+ , func_nop
+ , func_osd_new
+ , func_osd_free
+ , func_osd_show
+ , func_osd_hide
+ , func_osd_set_position
+ , func_osd_draw_bitmap
+ , func_set_color
+ , func_clear
+ , func_mute
+ , func_set_volume
+ , func_set_speed
+ , func_set_prebuffer
+ , func_metronom
+ , func_start
+ , func_wait
+ , func_setup
+ , func_grab_image
+ , func_get_pts
+ , func_flush
+ , func_first_frame
+ , func_still_frame
+ , func_video_size
+ , func_set_video_window
+ , func_osd_flush
+ , func_play_external
+ , func_key
+ , func_frame_size
+ , func_reset_audio
+ , func_select_audio
+ , func_trick_speed_mode
+ , func_get_version
+};
+
+enum keys
+{
+ key_none,
+ key_up,
+ key_down,
+ key_menu,
+ key_ok,
+ key_back,
+ key_left,
+ key_right,
+ key_red,
+ key_green,
+ key_yellow,
+ key_blue,
+ key_0,
+ key_1,
+ key_2,
+ key_3,
+ key_4,
+ key_5,
+ key_6,
+ key_7,
+ key_8,
+ key_9,
+ key_play,
+ key_pause,
+ key_stop,
+ key_record,
+ key_fast_fwd,
+ key_fast_rew,
+ key_power,
+ key_channel_plus,
+ key_channel_minus,
+ key_volume_plus,
+ key_volume_minus,
+ key_mute,
+ key_schedule,
+ key_channels,
+ key_timers,
+ key_recordings,
+ key_setup,
+ key_commands,
+ key_user1,
+ key_user2,
+ key_user3,
+ key_user4,
+ key_user5,
+ key_user6,
+ key_user7,
+ key_user8,
+ key_user9,
+ key_audio,
+ key_info,
+ key_channel_previous,
+ key_next,
+ key_previous,
+};
+
+
+
+typedef struct __attribute__((packed)) data_header_s
+{
+ uint32_t func:8;
+ uint32_t len:24;
+}
+data_header_t;
+
+
+
+typedef data_header_t result_header_t;
+typedef data_header_t event_header_t;
+
+
+
+typedef struct __attribute__((packed)) data_nop_s
+{
+ data_header_t header;
+}
+data_nop_t;
+
+
+
+typedef struct __attribute__((packed)) data_osd_new_s
+{
+ data_header_t header;
+
+ uint8_t window;
+ int16_t x;
+ int16_t y;
+ uint16_t width;
+ uint16_t height;
+}
+data_osd_new_t;
+
+
+
+typedef struct __attribute__((packed)) data_osd_free_s
+{
+ data_header_t header;
+
+ uint8_t window;
+}
+data_osd_free_t;
+
+
+
+typedef struct __attribute__((packed)) data_osd_show_s
+{
+ data_header_t header;
+
+ uint8_t window;
+}
+data_osd_show_t;
+
+
+
+typedef struct __attribute__((packed)) data_osd_hide_s
+{
+ data_header_t header;
+
+ uint8_t window;
+}
+data_osd_hide_t;
+
+
+
+typedef struct __attribute__((packed)) data_osd_flush_s
+{
+ data_header_t header;
+}
+data_osd_flush_t;
+
+
+
+typedef struct __attribute__((packed)) data_play_external_s
+{
+ data_header_t header;
+}
+data_play_external_t;
+
+
+
+typedef struct __attribute__((packed)) data_osd_set_position_s
+{
+ data_header_t header;
+
+ uint8_t window;
+ int16_t x;
+ int16_t y;
+}
+data_osd_set_position_t;
+
+
+
+typedef struct __attribute__((packed)) data_osd_draw_bitmap_s
+{
+ data_header_t header;
+
+ uint8_t window;
+ int16_t x;
+ int16_t y;
+ uint16_t width;
+ uint16_t height;
+}
+data_osd_draw_bitmap_t;
+
+
+
+typedef struct __attribute__((packed)) data_set_color_s
+{
+ data_header_t header;
+
+ uint8_t window;
+ uint8_t index;
+ uint8_t num;
+}
+data_set_color_t;
+
+
+
+typedef struct __attribute__((packed)) data_flush_s
+{
+ data_header_t header;
+
+ int32_t ms_timeout;
+ uint8_t just_wait;
+}
+data_flush_t;
+
+
+
+typedef struct __attribute__((packed)) result_flush_s
+{
+ result_header_t header;
+
+ uint8_t timed_out;
+}
+result_flush_t;
+
+
+
+typedef struct __attribute__((packed)) data_clear_s
+{
+ data_header_t header;
+
+ int32_t n;
+ int8_t s;
+}
+data_clear_t;
+
+
+
+typedef struct __attribute__((packed)) data_mute_s
+{
+ data_header_t header;
+
+ uint8_t mute;
+}
+data_mute_t;
+
+
+
+typedef struct __attribute__((packed)) data_set_volume_s
+{
+ data_header_t header;
+
+ uint8_t volume;
+}
+data_set_volume_t;
+
+
+
+typedef struct __attribute__((packed)) data_set_speed_s
+{
+ data_header_t header;
+
+ int32_t speed;
+}
+data_set_speed_t;
+
+
+
+typedef struct __attribute__((packed)) data_set_prebuffer_s
+{
+ data_header_t header;
+
+ uint32_t prebuffer;
+}
+data_set_prebuffer_t;
+
+
+
+typedef struct __attribute__((packed)) data_metronom_s
+{
+ data_header_t header;
+
+ int64_t pts;
+ uint32_t flags;
+}
+data_metronom_t;
+
+
+
+typedef struct __attribute__((packed)) data_start_s
+{
+ data_header_t header;
+}
+data_start_t;
+
+
+
+typedef struct __attribute__((packed)) data_wait_s
+{
+ data_header_t header;
+}
+data_wait_t;
+
+
+
+typedef struct __attribute__((packed)) result_wait_s
+{
+ result_header_t header;
+}
+result_wait_t;
+
+
+
+#define INPUT_VDR_VOLUME_IGNORE 0
+#define INPUT_VDR_VOLUME_CHANGE_HW 1
+#define INPUT_VDR_VOLUME_CHANGE_SW 2
+
+#define INPUT_VDR_MUTE_IGNORE 0
+#define INPUT_VDR_MUTE_EXECUTE 1
+#define INPUT_VDR_MUTE_SIMULATE 2
+
+typedef struct __attribute__((packed)) data_setup_s
+{
+ data_header_t header;
+
+ uint8_t osd_unscaled_blending;
+ uint8_t volume_mode;
+ uint8_t mute_mode;
+ uint16_t image4_3_zoom_x;
+ uint16_t image4_3_zoom_y;
+ uint16_t image16_9_zoom_x;
+ uint16_t image16_9_zoom_y;
+}
+data_setup_t;
+
+
+
+typedef struct __attribute__((packed)) data_first_frame_s
+{
+ data_header_t header;
+}
+data_first_frame_t;
+
+
+
+typedef struct __attribute__((packed)) data_still_frame_s
+{
+ data_header_t header;
+}
+data_still_frame_t;
+
+
+
+typedef struct __attribute__((packed)) data_set_video_window_s
+{
+ data_header_t header;
+
+ uint32_t x;
+ uint32_t y;
+ uint32_t w;
+ uint32_t h;
+ uint32_t w_ref;
+ uint32_t h_ref;
+}
+data_set_video_window_t;
+
+
+
+typedef struct __attribute__((packed)) data_grab_image_s
+{
+ data_header_t header;
+}
+data_grab_image_t;
+
+
+
+typedef struct __attribute__((packed)) result_grab_image_s
+{
+ result_header_t header;
+
+ int32_t width;
+ int32_t height;
+ int32_t ratio;
+ int32_t format;
+}
+result_grab_image_t;
+
+
+
+typedef struct __attribute__((packed)) data_get_pts_s
+{
+ data_header_t header;
+}
+data_get_pts_t;
+
+
+
+typedef struct __attribute__((packed)) result_get_pts_s
+{
+ result_header_t header;
+
+ int64_t pts;
+}
+result_get_pts_t;
+
+
+
+typedef struct __attribute__((packed)) data_get_version_s
+{
+ data_header_t header;
+}
+data_get_version_t;
+
+
+
+typedef struct __attribute__((packed)) result_get_version_s
+{
+ result_header_t header;
+
+ int32_t version;
+}
+result_get_version_t;
+
+
+
+typedef struct __attribute__((packed)) data_video_size_s
+{
+ data_header_t header;
+}
+data_video_size_t;
+
+
+
+typedef struct __attribute__((packed)) result_video_size_s
+{
+ result_header_t header;
+
+ int32_t left;
+ int32_t top;
+ int32_t width;
+ int32_t height;
+ int32_t ratio;
+ int32_t zoom_x;
+ int32_t zoom_y;
+}
+result_video_size_t;
+
+
+
+typedef struct __attribute__((packed)) data_reset_audio_s
+{
+ data_header_t header;
+}
+data_reset_audio_t;
+
+
+
+typedef struct __attribute__((packed)) event_key_s
+{
+ event_header_t header;
+
+ uint32_t key;
+}
+event_key_t;
+
+
+
+typedef struct __attribute__((packed)) event_frame_size_s
+{
+ event_header_t header;
+
+ int32_t left;
+ int32_t top;
+ int32_t width;
+ int32_t height;
+ int32_t zoom_x;
+ int32_t zoom_y;
+}
+event_frame_size_t;
+
+
+
+typedef struct __attribute__((packed)) event_play_external_s
+{
+ event_header_t header;
+
+ uint32_t key;
+}
+event_play_external_t;
+
+
+
+typedef struct __attribute__((packed)) data_select_audio_s
+{
+ data_header_t header;
+
+ uint8_t channels;
+}
+data_select_audio_t;
+
+
+
+typedef struct __attribute__((packed)) data_trick_speed_mode_s
+{
+ data_header_t header;
+
+ uint8_t on;
+}
+data_trick_speed_mode_t;
+
+
+
+typedef union __attribute__((packed)) data_union_u
+{
+ data_header_t header;
+ data_nop_t nop;
+ data_osd_new_t osd_new;
+ data_osd_free_t osd_free;
+ data_osd_show_t osd_show;
+ data_osd_hide_t osd_hide;
+ data_osd_set_position_t osd_set_position;
+ data_osd_draw_bitmap_t osd_draw_bitmap;
+ data_set_color_t set_color;
+ data_flush_t flush;
+ data_clear_t clear;
+ data_mute_t mute;
+ data_set_volume_t set_volume;
+ data_set_speed_t set_speed;
+ data_set_prebuffer_t set_prebuffer;
+ data_metronom_t metronom;
+ data_start_t start;
+ data_wait_t wait;
+ data_setup_t setup;
+ data_grab_image_t grab_image;
+ data_get_pts_t get_pts;
+ data_first_frame_t first_frame;
+ data_still_frame_t still_frame;
+ data_video_size_t video_size;
+ data_set_video_window_t set_video_window;
+ data_osd_flush_t osd_flush;
+ data_play_external_t play_external;
+ data_reset_audio_t reset_audio;
+ data_select_audio_t select_audio;
+ data_trick_speed_mode_t trick_speed_mode;
+ data_get_version_t get_version;
+}
+data_union_t;
+
+
+
+typedef union __attribute__((packed)) result_union_u
+{
+ result_header_t header;
+ result_grab_image_t grab_image;
+ result_get_pts_t get_pts;
+ result_flush_t flush;
+ result_video_size_t video_size;
+ result_get_version_t get_version;
+ result_wait_t wait;
+}
+result_union_t;
+
+
+
+typedef union __attribute__((packed)) event_union_u
+{
+ event_header_t header;
+ event_key_t key;
+ event_frame_size_t frame_size;
+ event_play_external_t play_external;
+}
+event_union_t;
+
+
+
+#endif /* __INPUT_VDR_H */
+
diff --git a/src/vdr/post_vdr.c b/src/vdr/post_vdr.c
new file mode 100644
index 000000000..fd95b371f
--- /dev/null
+++ b/src/vdr/post_vdr.c
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2000-2004 the xine project
+ *
+ * This file is part of xine, a free video player.
+ *
+ * xine 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.
+ *
+ * xine is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * $Id: vdr.c,v 1.20 2004/04/17 19:54:32 mroi Exp $
+ */
+
+/*
+ * plugins for VDR
+ */
+
+#include "xine_internal.h"
+#include "post.h"
+#include "post_vdr.h"
+
+
+
+static post_info_t vdr_video_special_info = { XINE_POST_TYPE_VIDEO_FILTER };
+static post_info_t vdr_audio_special_info = { XINE_POST_TYPE_AUDIO_FILTER };
+
+plugin_info_t xine_plugin_info[] EXPORTED =
+{
+ /* type, API, "name", version, special_info, init_function */
+ { PLUGIN_POST, 9, "vdr" , XINE_VERSION_CODE, &vdr_video_special_info, &vdr_video_init_plugin },
+ { PLUGIN_POST, 9, "vdr_video", XINE_VERSION_CODE, &vdr_video_special_info, &vdr_video_init_plugin },
+ { PLUGIN_POST, 9, "vdr_audio", XINE_VERSION_CODE, &vdr_audio_special_info, &vdr_audio_init_plugin },
+ { PLUGIN_NONE, 0, "", 0, NULL, NULL }
+};
+
diff --git a/src/vdr/post_vdr.h b/src/vdr/post_vdr.h
new file mode 100644
index 000000000..7684727eb
--- /dev/null
+++ b/src/vdr/post_vdr.h
@@ -0,0 +1,72 @@
+
+#ifndef __POST_VDR_H
+#define __POST_VDR_H
+
+
+
+typedef struct vdr_set_video_window_data_s {
+ int32_t x;
+ int32_t y;
+ int32_t w;
+ int32_t h;
+ int32_t w_ref;
+ int32_t h_ref;
+
+} vdr_set_video_window_data_t;
+
+
+
+typedef struct vdr_frame_size_changed_data_s {
+ int32_t x;
+ int32_t y;
+ int32_t w;
+ int32_t h;
+ double r;
+
+} vdr_frame_size_changed_data_t;
+
+
+
+typedef struct vdr_select_audio_data_s {
+ uint8_t channels;
+
+} vdr_select_audio_data_t;
+
+
+
+inline static int vdr_is_vdr_stream(xine_stream_t *stream)
+{
+ if (!stream
+ || !stream->input_plugin
+ || !stream->input_plugin->input_class)
+ {
+ return 0;
+ }
+
+ {
+ input_class_t *input_class = stream->input_plugin->input_class;
+
+ if (input_class->get_identifier)
+ {
+ const char *identifier = input_class->get_identifier(input_class);
+ if (identifier
+ && 0 == strcmp(identifier, "VDR"))
+ {
+ return 1;
+ }
+ }
+ }
+
+ return 0;
+}
+
+
+
+/* plugin class initialization function */
+void *vdr_video_init_plugin(xine_t *xine, void *);
+void *vdr_audio_init_plugin(xine_t *xine, void *);
+
+
+
+#endif /* __POST_VDR_H */
+
diff --git a/src/vdr/post_vdr_audio.c b/src/vdr/post_vdr_audio.c
new file mode 100644
index 000000000..c432ff6bb
--- /dev/null
+++ b/src/vdr/post_vdr_audio.c
@@ -0,0 +1,287 @@
+/*
+ * Copyright (C) 2000-2004 the xine project
+ *
+ * This file is part of xine, a free video player.
+ *
+ * xine 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.
+ *
+ * xine is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * $Id: vdr.c,v 1.20 2004/04/17 19:54:32 mroi Exp $
+ */
+
+/*
+ * select audio channel plugin for VDR
+ */
+
+#define LOG_MODULE "vdr_audio"
+#define LOG_VERBOSE
+/*
+#define LOG
+*/
+
+#include "xine_internal.h"
+#include "post.h"
+#include "post_vdr.h"
+
+
+
+typedef struct vdr_audio_post_plugin_s
+{
+ post_plugin_t post_plugin;
+
+ xine_event_queue_t *event_queue;
+ xine_stream_t *vdr_stream;
+
+ uint8_t audio_channels;
+ int num_channels;
+
+}
+vdr_audio_post_plugin_t;
+
+
+static void vdr_audio_select_audio(vdr_audio_post_plugin_t *this, uint8_t channels)
+{
+ this->audio_channels = channels;
+}
+
+
+/* plugin class functions */
+static post_plugin_t *vdr_audio_open_plugin(post_class_t *class_gen, int inputs,
+ xine_audio_port_t **audio_target,
+ xine_video_port_t **video_target);
+static char *vdr_audio_get_identifier(post_class_t *class_gen);
+static char *vdr_audio_get_description(post_class_t *class_gen);
+static void vdr_audio_class_dispose(post_class_t *class_gen);
+
+/* plugin instance functions */
+static void vdr_audio_dispose(post_plugin_t *this_gen);
+
+/* replaced ao_port functions */
+static int vdr_audio_port_open(xine_audio_port_t *port_gen, xine_stream_t *stream,
+ uint32_t bits, uint32_t rate, int mode);
+static void vdr_audio_port_put_buffer(xine_audio_port_t *port_gen, audio_buffer_t *buf, xine_stream_t *stream);
+
+
+
+void *vdr_audio_init_plugin(xine_t *xine, void *data)
+{
+ post_class_t *class = (post_class_t *)malloc(sizeof (post_class_t));
+
+ if (!class)
+ return NULL;
+
+ class->open_plugin = vdr_audio_open_plugin;
+ class->get_identifier = vdr_audio_get_identifier;
+ class->get_description = vdr_audio_get_description;
+ class->dispose = vdr_audio_class_dispose;
+
+ return class;
+}
+
+static post_plugin_t *vdr_audio_open_plugin(post_class_t *class_gen, int inputs,
+ xine_audio_port_t **audio_target,
+ xine_video_port_t **video_target)
+{
+ vdr_audio_post_plugin_t *this = (vdr_audio_post_plugin_t *)xine_xmalloc(sizeof (vdr_audio_post_plugin_t));
+ post_in_t *input;
+ post_out_t *output;
+ post_audio_port_t *port;
+/*
+fprintf(stderr, "~~~~~~~~~~ vdr open plugin\n");
+*/
+ if (!this || !audio_target || !audio_target[ 0 ])
+ {
+ free(this);
+ return NULL;
+ }
+
+ _x_post_init(&this->post_plugin, 1, 0);
+ this->post_plugin.dispose = vdr_audio_dispose;
+
+ port = _x_post_intercept_audio_port(&this->post_plugin, audio_target[ 0 ], &input, &output);
+ port->new_port.open = vdr_audio_port_open;
+ port->new_port.put_buffer = vdr_audio_port_put_buffer;
+
+ this->post_plugin.xine_post.audio_input[ 0 ] = &port->new_port;
+
+
+
+ this->audio_channels = 0;
+
+ return &this->post_plugin;
+}
+
+static char *vdr_audio_get_identifier(post_class_t *class_gen)
+{
+ return "vdr_audio";
+}
+
+static char *vdr_audio_get_description(post_class_t *class_gen)
+{
+ return "modifies every audio frame as requested by VDR";
+}
+
+static void vdr_audio_class_dispose(post_class_t *class_gen)
+{
+ free(class_gen);
+}
+
+
+static void vdr_audio_dispose(post_plugin_t *this_gen)
+{
+/*
+fprintf(stderr, "~~~~~~~~~~ vdr dispose\n");
+*/
+ if (_x_post_dispose(this_gen))
+ {
+ vdr_audio_post_plugin_t *this = (vdr_audio_post_plugin_t *)this_gen;
+
+ if (this->vdr_stream)
+ xine_event_dispose_queue(this->event_queue);
+
+ free(this_gen);
+ }
+}
+
+static int vdr_audio_port_open(xine_audio_port_t *port_gen, xine_stream_t *stream,
+ uint32_t bits, uint32_t rate, int mode) {
+
+ post_audio_port_t *port = (post_audio_port_t *)port_gen;
+ vdr_audio_post_plugin_t *this = (vdr_audio_post_plugin_t *)port->post;
+
+ _x_post_rewire(&this->post_plugin);
+ _x_post_inc_usage(port);
+/*
+fprintf(stderr, "~~~~~~~~~~ vdr port open\n");
+*/
+ port->stream = stream;
+ port->bits = bits;
+ port->rate = rate;
+ port->mode = mode;
+
+ this->num_channels = _x_ao_mode2channels(mode);
+
+ return port->original_port->open(port->original_port, stream, bits, rate, mode );
+}
+
+
+static void vdr_audio_port_put_buffer(xine_audio_port_t *port_gen, audio_buffer_t *buf, xine_stream_t *stream)
+{
+ post_audio_port_t *port = (post_audio_port_t *)port_gen;
+ vdr_audio_post_plugin_t *this = (vdr_audio_post_plugin_t *)port->post;
+ xine_event_t *event;
+/*
+fprintf(stderr, "~~~~~~ vdr_audio\n");
+*/
+ if (this->vdr_stream
+ && !_x_continue_stream_processing(this->vdr_stream))
+ {
+ this->vdr_stream = 0;
+
+ xine_event_dispose_queue(this->event_queue);
+ this->event_queue = 0;
+
+ this->audio_channels = 0;
+ }
+
+ if (!this->vdr_stream
+ && vdr_is_vdr_stream(stream))
+ {
+ this->event_queue = xine_event_new_queue(stream);
+ if (this->event_queue)
+ {
+ this->vdr_stream = stream;
+
+ {
+ xine_event_t event;
+
+ event.type = XINE_EVENT_VDR_PLUGINSTARTED;
+ event.data = 0;
+ event.data_length = 1; /* vdr_audio */
+
+ xine_event_send(this->vdr_stream, &event);
+ }
+ }
+ }
+
+ if (this->event_queue)
+ {
+ while ((event = xine_event_get(this->event_queue)))
+ {
+ if (event->type == XINE_EVENT_VDR_SELECTAUDIO)
+ {
+ vdr_select_audio_data_t *data = (vdr_select_audio_data_t *)event->data;
+
+ vdr_audio_select_audio(this, data->channels);
+ }
+
+ xine_event_free(event);
+ }
+ }
+
+ if (this->num_channels == 2
+ && this->audio_channels != 0
+ && this->audio_channels != 3)
+ {
+ audio_buffer_t *vdr_buf = port->original_port->get_buffer(port->original_port);
+ vdr_buf->num_frames = buf->num_frames;
+ vdr_buf->vpts = buf->vpts;
+ vdr_buf->frame_header_count = buf->frame_header_count;
+ vdr_buf->first_access_unit = buf->first_access_unit;
+ /* FIXME: The audio buffer should contain this info.
+ * We should not have to get it from the open call.
+ */
+ vdr_buf->format.bits = buf->format.bits;
+ vdr_buf->format.rate = buf->format.rate;
+ vdr_buf->format.mode = buf->format.mode;
+ _x_extra_info_merge(vdr_buf->extra_info, buf->extra_info);
+
+ {
+ int step = buf->format.bits / 8;
+ uint8_t *src = (uint8_t *)buf->mem;
+ uint8_t *dst = (uint8_t *)vdr_buf->mem;
+
+ if (this->audio_channels == 2)
+ src += step;
+/*
+ fprintf(stderr, "~~~~~~~~~~ vdr port put buffer: channels: %d, %d\n"
+ , this->audio_channels
+ , buf->format.bits);
+*/
+ int i, k;
+ for (i = 0; i < buf->num_frames; i++)
+ {
+ for (k = 0; k < step; k++)
+ *dst++ = *src++;
+
+ src -= step;
+
+ for (k = 0; k < step; k++)
+ *dst++ = *src++;
+
+ src += step;
+ }
+ }
+
+ /* pass data to original port */
+ port->original_port->put_buffer(port->original_port, vdr_buf, stream);
+
+ /* free data from origial buffer */
+ buf->num_frames = 0; /* UNDOCUMENTED, but hey, it works! Force old audio_out buffer free. */
+ }
+
+ port->original_port->put_buffer(port->original_port, buf, stream);
+
+ return;
+}
diff --git a/src/vdr/post_vdr_video.c b/src/vdr/post_vdr_video.c
new file mode 100644
index 000000000..84e05f8b5
--- /dev/null
+++ b/src/vdr/post_vdr_video.c
@@ -0,0 +1,492 @@
+/*
+ * Copyright (C) 2000-2004 the xine project
+ *
+ * This file is part of xine, a free video player.
+ *
+ * xine 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.
+ *
+ * xine is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * $Id: vdr.c,v 1.20 2004/04/17 19:54:32 mroi Exp $
+ */
+
+/*
+ * frame scaler plugin for VDR
+ */
+
+#define LOG_MODULE "vdr_video"
+#define LOG_VERBOSE
+/*
+#define LOG
+*/
+
+#include "xine_internal.h"
+#include "post.h"
+#include "post_vdr.h"
+
+
+
+typedef struct vdr_video_post_plugin_s
+{
+ post_plugin_t post_plugin;
+
+ xine_event_queue_t *event_queue;
+ xine_stream_t *vdr_stream;
+
+ int8_t trick_speed_mode;
+ int8_t enabled;
+
+ int32_t x;
+ int32_t y;
+ int32_t w;
+ int32_t h;
+ int32_t w_ref;
+ int32_t h_ref;
+
+ int32_t old_frame_left;
+ int32_t old_frame_top;
+ int32_t old_frame_width;
+ int32_t old_frame_height;
+ double old_frame_ratio;
+
+}
+vdr_video_post_plugin_t;
+
+
+static void vdr_video_set_video_window(vdr_video_post_plugin_t *this, int32_t x, int32_t y, int32_t w, int32_t h, int32_t w_ref, int32_t h_ref)
+{
+ this->enabled = 0;
+
+ this->x = x;
+ this->y = y;
+ this->w = w;
+ this->h = h;
+ this->w_ref = w_ref;
+ this->h_ref = h_ref;
+
+ if (w != w_ref || h != h_ref)
+ this->enabled = 1;
+}
+
+
+/* plugin class functions */
+static post_plugin_t *vdr_video_open_plugin(post_class_t *class_gen, int inputs,
+ xine_audio_port_t **audio_target,
+ xine_video_port_t **video_target);
+static char *vdr_video_get_identifier(post_class_t *class_gen);
+static char *vdr_video_get_description(post_class_t *class_gen);
+static void vdr_video_class_dispose(post_class_t *class_gen);
+
+/* plugin instance functions */
+static void vdr_video_dispose(post_plugin_t *this_gen);
+
+/* frame intercept check */
+static int vdr_video_intercept_frame(post_video_port_t *port, vo_frame_t *frame);
+
+/* replaced vo_frame functions */
+static int vdr_video_draw(vo_frame_t *frame, xine_stream_t *stream);
+
+
+void *vdr_video_init_plugin(xine_t *xine, void *data)
+{
+ post_class_t *class = (post_class_t *)malloc(sizeof (post_class_t));
+
+ if (!class)
+ return NULL;
+
+ class->open_plugin = vdr_video_open_plugin;
+ class->get_identifier = vdr_video_get_identifier;
+ class->get_description = vdr_video_get_description;
+ class->dispose = vdr_video_class_dispose;
+
+ return class;
+}
+
+static post_plugin_t *vdr_video_open_plugin(post_class_t *class_gen, int inputs,
+ xine_audio_port_t **audio_target,
+ xine_video_port_t **video_target)
+{
+ vdr_video_post_plugin_t *this = (vdr_video_post_plugin_t *)xine_xmalloc(sizeof (vdr_video_post_plugin_t));
+ post_in_t *input;
+ post_out_t *output;
+ post_video_port_t *port;
+
+ if (!this || !video_target || !video_target[ 0 ])
+ {
+ free(this);
+ return NULL;
+ }
+
+ _x_post_init(&this->post_plugin, 0, 1);
+ this->post_plugin.dispose = vdr_video_dispose;
+
+ port = _x_post_intercept_video_port(&this->post_plugin, video_target[ 0 ], &input, &output);
+ port->intercept_frame = vdr_video_intercept_frame;
+ port->new_frame->draw = vdr_video_draw;
+ this->post_plugin.xine_post.video_input[ 0 ] = &port->new_port;
+
+
+
+ this->enabled = 0;
+ this->vdr_stream = 0;
+ this->event_queue = 0;
+ this->old_frame_left = 0;
+ this->old_frame_top = 0;
+ this->old_frame_width = 0;
+ this->old_frame_height = 0;
+ this->old_frame_ratio = 0;
+ this->trick_speed_mode = 0;
+
+ return &this->post_plugin;
+}
+
+static char *vdr_video_get_identifier(post_class_t *class_gen)
+{
+ return "vdr";
+}
+
+static char *vdr_video_get_description(post_class_t *class_gen)
+{
+ return "modifies every video frame as requested by VDR";
+}
+
+static void vdr_video_class_dispose(post_class_t *class_gen)
+{
+ free(class_gen);
+}
+
+
+static void vdr_video_dispose(post_plugin_t *this_gen)
+{
+ if (_x_post_dispose(this_gen))
+ {
+ vdr_video_post_plugin_t *this = (vdr_video_post_plugin_t *)this_gen;
+
+ if (this->vdr_stream)
+ {
+ xine_event_t event;
+ vdr_frame_size_changed_data_t event_data;
+
+ event_data.x = 0;
+ event_data.y = 0;
+ event_data.w = 0;
+ event_data.h = 0;
+
+ event.type = XINE_EVENT_VDR_FRAMESIZECHANGED;
+ event.data = &event_data;
+ event.data_length = sizeof (event_data);
+
+ xine_event_send(this->vdr_stream, &event);
+
+ xine_event_dispose_queue(this->event_queue);
+ }
+
+ free(this_gen);
+ }
+}
+
+
+static int vdr_video_intercept_frame(post_video_port_t *port, vo_frame_t *frame)
+{
+ return (frame->format == XINE_IMGFMT_YUY2
+ || frame->format == XINE_IMGFMT_YV12);
+}
+
+
+static inline void vdr_video_scale(uint8_t *src, uint8_t *dst, int y_inc, int x_inc, int w_dst, int h_dst, int x, int y, int w, int h, int w_ref, int h_ref, int init)
+{
+ int x0 = x * w_dst / w_ref;
+ int y0 = y * h_dst / h_ref;
+
+ int x1 = ((x + w) * w_dst - 1 + w_ref) / w_ref;
+ int y1 = ((y + h) * h_dst - 1 + h_ref) / h_ref;
+
+ int dx = x1 - x0;
+ int dy = y1 - y0;
+
+ int yy, xx;
+
+ int dy2 = dy + dy;
+ int h_dst2 = h_dst + h_dst;
+ int y_eps = h_dst - dy2;
+
+ int dx2 = dx + dx;
+ int w_dst2 = w_dst + w_dst;
+ int x_eps0 = w_dst - dx2;
+
+ for (yy = 0; yy < y0; yy++)
+ {
+ uint8_t *dst0 = dst;
+
+ for (xx = 0; xx < w_dst; xx++)
+ {
+ *dst0 = init;
+ dst0 += x_inc;
+ }
+
+ dst += y_inc;
+ }
+
+ for (yy = y0; yy < y1; yy++)
+ {
+ uint8_t *dst0 = dst;
+ uint8_t *src0 = src;
+
+ int x_eps = x_eps0;
+
+ for (xx = 0; xx < x0; xx++)
+ {
+ *dst0 = init;
+ dst0 += x_inc;
+ }
+
+ for (xx = x0; xx < x1; xx++)
+ {
+ *dst0 = *src0;
+ dst0 += x_inc;
+
+ x_eps += w_dst2;
+ while (x_eps >= 0)
+ {
+ src0 += x_inc;
+ x_eps -= dx2;
+ }
+ }
+
+ for (xx = x1; xx < w_dst; xx++)
+ {
+ *dst0 = init;
+ dst0 += x_inc;
+ }
+
+ dst += y_inc;
+
+ y_eps += h_dst2;
+ while (y_eps >= 0)
+ {
+ src += y_inc;
+ y_eps -= dy2;
+ }
+ }
+
+ for (yy = y1; yy < h_dst; yy++)
+ {
+ uint8_t *dst0 = dst;
+
+ for (xx = 0; xx < w_dst; xx++)
+ {
+ *dst0 = init;
+ dst0 += x_inc;
+ }
+
+ dst += y_inc;
+ }
+}
+
+static void vdr_video_scale_YUY2(vdr_video_post_plugin_t *this, vo_frame_t *src, vo_frame_t *dst)
+{
+ int w = dst->width - dst->crop_left - dst->crop_right;
+ int h = dst->height - dst->crop_top - dst->crop_bottom;
+ int offset;
+
+ if (w < 0)
+ w = 0;
+
+ if (h < 0)
+ h = 0;
+
+ offset = dst->pitches[ 0 ] * dst->crop_top + 2 * dst->crop_left;
+ vdr_video_scale(&src->base[ 0 ][ 0 ] + offset, &dst->base[ 0 ][ 0 ] + offset, dst->pitches[ 0 ], 2, w , h, this->x, this->y, this->w, this->h, this->w_ref, this->h_ref, 0x00);
+ offset = dst->pitches[ 0 ] * dst->crop_top + 4 * ((dst->crop_left + 1) / 2);
+ vdr_video_scale(&src->base[ 0 ][ 1 ] + offset, &dst->base[ 0 ][ 1 ] + offset, dst->pitches[ 0 ], 4, (w + 1) / 2, h, this->x, this->y, this->w, this->h, this->w_ref, this->h_ref, 0x80);
+ offset = dst->pitches[ 0 ] * dst->crop_top + 4 * ((dst->crop_left + 1) / 2);
+ vdr_video_scale(&src->base[ 0 ][ 3 ] + offset, &dst->base[ 0 ][ 3 ] + offset, dst->pitches[ 0 ], 4, (w + 1) / 2, h, this->x, this->y, this->w, this->h, this->w_ref, this->h_ref, 0x80);
+}
+
+static void vdr_video_scale_YV12(vdr_video_post_plugin_t *this, vo_frame_t *src, vo_frame_t *dst)
+{
+ int w = dst->width - dst->crop_left - dst->crop_right;
+ int h = dst->height - dst->crop_top - dst->crop_bottom;
+ int offset;
+
+ if (w < 0)
+ w = 0;
+
+ if (h < 0)
+ h = 0;
+
+ offset = dst->pitches[ 0 ] * dst->crop_top + 1 * dst->crop_left;
+ vdr_video_scale(&src->base[ 0 ][ 0 ] + offset, &dst->base[ 0 ][ 0 ] + offset, dst->pitches[ 0 ], 1, w , h , this->x, this->y, this->w, this->h, this->w_ref, this->h_ref, 0x00);
+ offset = dst->pitches[ 1 ] * ((dst->crop_top + 1) / 2) + 1 * ((dst->crop_left + 1) / 2);
+ vdr_video_scale(&src->base[ 1 ][ 0 ] + offset, &dst->base[ 1 ][ 0 ] + offset, dst->pitches[ 1 ], 1, (w + 1) / 2, (h + 1) / 2, this->x, this->y, this->w, this->h, this->w_ref, this->h_ref, 0x80);
+ offset = dst->pitches[ 2 ] * ((dst->crop_top + 1) / 2) + 1 * ((dst->crop_left + 1) / 2);
+ vdr_video_scale(&src->base[ 2 ][ 0 ] + offset, &dst->base[ 2 ][ 0 ] + offset, dst->pitches[ 2 ], 1, (w + 1) / 2, (h + 1) / 2, this->x, this->y, this->w, this->h, this->w_ref, this->h_ref, 0x80);
+}
+
+
+static int vdr_video_draw(vo_frame_t *frame, xine_stream_t *stream)
+{
+ post_video_port_t *port = (post_video_port_t *)frame->port;
+ vdr_video_post_plugin_t *this = (vdr_video_post_plugin_t *)port->post;
+ vo_frame_t *vdr_frame;
+ xine_event_t *event;
+ int skip;
+
+ if (this->vdr_stream
+ && !_x_continue_stream_processing(this->vdr_stream))
+ {
+ this->vdr_stream = 0;
+
+ xine_event_dispose_queue(this->event_queue);
+ this->event_queue = 0;
+
+ this->old_frame_left = 0;
+ this->old_frame_top = 0;
+ this->old_frame_width = 0;
+ this->old_frame_height = 0;
+ this->old_frame_ratio = 0;
+ }
+
+ if (!this->vdr_stream
+ && vdr_is_vdr_stream(stream))
+ {
+ this->event_queue = xine_event_new_queue(stream);
+ if (this->event_queue)
+ {
+ this->vdr_stream = stream;
+
+ {
+ xine_event_t event;
+
+ event.type = XINE_EVENT_VDR_PLUGINSTARTED;
+ event.data = 0;
+ event.data_length = 0; /* vdr_video */
+
+ xine_event_send(this->vdr_stream, &event);
+ }
+ }
+ }
+
+ if (this->event_queue)
+ {
+ while ((event = xine_event_get(this->event_queue)))
+ {
+ if (event->type == XINE_EVENT_VDR_SETVIDEOWINDOW)
+ {
+ vdr_set_video_window_data_t *data = (vdr_set_video_window_data_t *)event->data;
+
+ vdr_video_set_video_window(this, data->x, data->y, data->w, data->h, data->w_ref, data->h_ref);
+ }
+ else if (event->type == XINE_EVENT_VDR_TRICKSPEEDMODE)
+ {
+/*
+ fprintf(stderr, "###############################: %p, %d\n", event->data, event->data_length);
+ this->trick_speed_mode = (0 != event->data_length);
+*/
+ }
+
+ xine_event_free(event);
+ }
+ }
+
+ {
+ int32_t frame_left = frame->crop_left;
+ int32_t frame_width = frame->width - frame->crop_left - frame->crop_right;
+ int32_t frame_top = frame->crop_top;
+ int32_t frame_height = frame->height - frame->crop_top - frame->crop_bottom;
+ double frame_ratio = frame->ratio;
+
+ if (frame_left < 0)
+ frame_left = 0;
+ if (frame_width > frame->width)
+ frame_width = frame->width;
+ if (frame_top < 0)
+ frame_top = 0;
+ if (frame_height > frame->height)
+ frame_height = frame->height;
+
+ if (this->vdr_stream
+ && (this->old_frame_left != frame_left
+ || this->old_frame_top != frame_top
+ || this->old_frame_width != frame_width
+ || this->old_frame_height != frame_height
+ || this->old_frame_ratio != frame_ratio))
+ {
+ xine_event_t event;
+ vdr_frame_size_changed_data_t event_data;
+
+ event_data.x = frame_left;
+ event_data.y = frame_top;
+ event_data.w = frame_width;
+ event_data.h = frame_height;
+ event_data.r = frame_ratio;
+
+ xprintf(this->vdr_stream->xine, XINE_VERBOSITY_LOG,
+ _(LOG_MODULE ": osd: (%d, %d)-(%d, %d)@%lg\n"), frame_left, frame_top, frame_width, frame_height, frame_ratio);
+
+ event.type = XINE_EVENT_VDR_FRAMESIZECHANGED;
+ event.data = &event_data;
+ event.data_length = sizeof (event_data);
+
+ xine_event_send(this->vdr_stream, &event);
+
+ this->old_frame_left = frame_left;
+ this->old_frame_top = frame_top;
+ this->old_frame_width = frame_width;
+ this->old_frame_height = frame_height;
+ this->old_frame_ratio = frame_ratio;
+ }
+ }
+/*
+ fprintf(stderr, "~~~~~~~~~~~~ trickspeedmode: %d\n", this->trick_speed_mode);
+
+ if (this->vdr_stream
+ && this->trick_speed_mode)
+ {
+ frame->pts = 0;
+ frame->next->pts = 0;
+ }
+*/
+ if (!this->enabled
+ || frame->bad_frame
+ || (frame->format != XINE_IMGFMT_YUY2
+ && frame->format != XINE_IMGFMT_YV12))
+ {
+ _x_post_frame_copy_down(frame, frame->next);
+ skip = frame->next->draw(frame->next, stream);
+ _x_post_frame_copy_up(frame, frame->next);
+ return skip;
+ }
+
+ vdr_frame = port->original_port->get_frame(port->original_port,
+ frame->width, frame->height, frame->ratio, frame->format, frame->flags | VO_BOTH_FIELDS);
+
+ _x_post_frame_copy_down(frame, vdr_frame);
+
+ switch (vdr_frame->format)
+ {
+ case XINE_IMGFMT_YUY2:
+ vdr_video_scale_YUY2(this, frame, vdr_frame);
+ break;
+
+ case XINE_IMGFMT_YV12:
+ vdr_video_scale_YV12(this, frame, vdr_frame);
+ break;
+ }
+
+ skip = vdr_frame->draw(vdr_frame, stream);
+ _x_post_frame_copy_up(frame, vdr_frame);
+ vdr_frame->free(vdr_frame);
+
+ return skip;
+}
diff --git a/src/video_out/Makefile.am b/src/video_out/Makefile.am
index 148eda84c..a4f219b9c 100644
--- a/src/video_out/Makefile.am
+++ b/src/video_out/Makefile.am
@@ -1,14 +1,30 @@
include $(top_srcdir)/misc/Makefile.common
-AM_CPPFLAGS = -DXINE_COMPILE
-AM_LDFLAGS = $(xineplug_ldflags)
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+AM_LDFLAGS = $(xineplug_ldflags)
+AM_OBJCFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
-SUBDIRS = libdha vidix macosx
+SUBDIRS =
+
+if BUILD_DHA_KMOD
+SUBDIRS += libdha
+endif
+
+# vidix depends on portions of dha
+if ENABLE_VIDIX
+if !BUILD_DHA_KMOD
+SUBDIRS += libdha
+endif
+SUBDIRS += vidix
+endif
+
+if ENABLE_MACOSX_VIDEO
+SUBDIRS += macosx
+endif
EXTRA_DIST = video_out_directfb.c video_out_directfb_fb.c video_out_directfb_x.c video_out_directx.c video_out_macosx.m
-VIDIX_CFLAGS = -I$(top_builddir)/src/video_out/vidix \
- -I$(top_srcdir)/src/video_out/vidix
+noinst_HEADERS = deinterlace.h video_out_syncfb.h yuv2rgb.h x11osd.h xcbosd.h
if HAVE_X11
X11OSD = x11osd.c
@@ -16,72 +32,72 @@ xshm_module = xineplug_vo_out_xshm.la
if HAVE_XV
xv_module = xineplug_vo_out_xv.la
endif
-if HAVE_XVMC
+if ENABLE_XVMC
xvmc_module = xineplug_vo_out_xvmc.la
endif
-if HAVE_XXMC
+if ENABLE_XXMC
xxmc_module = xineplug_vo_out_xxmc.la
endif
-if HAVE_OPENGL
+if ENABLE_OPENGL
opengl_module = xineplug_vo_out_opengl.la
endif
-if HAVE_SYNCFB
+if ENABLE_SYNCFB
syncfb_module = xineplug_vo_out_syncfb.la
endif
-if HAVE_SUNFB
-if HAVE_SUNDGA
+if ENABLE_SUNFB
+if ENABLE_SUNDGA
pgx64_module = xineplug_vo_out_pgx64.la
pgx32_module = xineplug_vo_out_pgx32.la
endif
endif
endif
-if HAVE_XCB
+if ENABLE_XCB
XCBOSD = xcbosd.c
-if HAVE_XCBSHM
+if ENABLE_XCBSHM
xcbshm_module = xineplug_vo_out_xcbshm.la
endif
-if HAVE_XCBXV
+if ENABLE_XCBXV
xcbxv_module = xineplug_vo_out_xcbxv.la
endif
endif
-if HAVE_VIDIX
+if ENABLE_VIDIX
vidix_module = xineplug_vo_out_vidix.la
endif
-if HAVE_AA
+if ENABLE_AA
aa_module = xineplug_vo_out_aa.la
endif
-if HAVE_CACA
+if ENABLE_CACA
caca_module = xineplug_vo_out_caca.la
endif
-if HAVE_FB
+if ENABLE_FB
fb_module = xineplug_vo_out_fb.la
endif
-if HAVE_DIRECTFB
+if ENABLE_DIRECTFB
directfb_module = xineplug_vo_out_directfb.la
if HAVE_X11
directfb_module += xineplug_vo_out_xdirectfb.la
endif
endif
-if HAVE_SDL
+if ENABLE_SDL
sdl_module = xineplug_vo_out_sdl.la
endif
-if HAVE_STK
+if ENABLE_STK
stk_module = xineplug_vo_out_stk.la
endif
-if HAVE_DIRECTX
+if ENABLE_DIRECTX
directx_module = xineplug_vo_out_directx.la
endif
-if HAVE_MACOSX_VIDEO
+if ENABLE_MACOSX_VIDEO
macosx_module = xineplug_vo_out_macosx.la
endif
@@ -104,101 +120,94 @@ xineplug_LTLIBRARIES = $(xshm_module) $(xv_module) $(xvmc_module) \
xineplug_vo_out_xcbshm_la_SOURCES = yuv2rgb.c yuv2rgb_mmx.c yuv2rgb_mlib.c video_out_xcbshm.c $(XCBOSD)
xineplug_vo_out_xcbshm_la_LIBADD = $(MLIB_LIBS) $(XINE_LIB) $(PTHREAD_LIBS) $(XCB_LIBS) $(XCBSHM_LIBS)
-xineplug_vo_out_xcbshm_la_CFLAGS = $(VISIBILITY_FLAG) $(MLIB_CFLAGS) $(XCB_CFLAGS) $(XCBSHM_CFLAGS)
+xineplug_vo_out_xcbshm_la_CFLAGS = $(AM_CFLAGS) $(MLIB_CFLAGS) $(XCB_CFLAGS) $(XCBSHM_CFLAGS)
xineplug_vo_out_xcbxv_la_SOURCES = deinterlace.c video_out_xcbxv.c $(XCBOSD)
xineplug_vo_out_xcbxv_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS) $(XCBXV_LIBS) $(XCB_LIBS)
-xineplug_vo_out_xcbxv_la_CFLAGS = $(VISIBILITY_FLAG) $(XCB_CFLAGS) $(XCBXV_CFLAGS)
+xineplug_vo_out_xcbxv_la_CFLAGS = $(AM_CFLAGS) $(XCB_CFLAGS) $(XCBXV_CFLAGS)
xineplug_vo_out_xshm_la_SOURCES = yuv2rgb.c yuv2rgb_mmx.c yuv2rgb_mlib.c \
video_out_xshm.c $(X11OSD)
xineplug_vo_out_xshm_la_LIBADD = $(MLIB_LIBS) $(X_LIBS) $(XINE_LIB) $(PTHREAD_LIBS)
-xineplug_vo_out_xshm_la_CFLAGS = $(VISIBILITY_FLAG) $(X_CFLAGS) $(MLIB_CFLAGS) -fno-strict-aliasing
+xineplug_vo_out_xshm_la_CFLAGS = $(AM_CFLAGS) $(X_CFLAGS) $(MLIB_CFLAGS) -fno-strict-aliasing
xineplug_vo_out_xv_la_SOURCES = $(X11OSD) deinterlace.c video_out_xv.c
xineplug_vo_out_xv_la_LIBADD = $(XV_LIBS) $(X_LIBS) $(XINE_LIB) $(PTHREAD_LIBS)
-xineplug_vo_out_xv_la_CFLAGS = $(VISIBILITY_FLAG) $(X_CFLAGS) $(XV_CFLAGS) -fno-strict-aliasing
+xineplug_vo_out_xv_la_CFLAGS = $(AM_CFLAGS) $(X_CFLAGS) $(XV_CFLAGS) -fno-strict-aliasing
xineplug_vo_out_xvmc_la_SOURCES = deinterlace.c video_out_xvmc.c
xineplug_vo_out_xvmc_la_LIBADD = $(XVMC_LIBS) $(XV_LIBS) $(X_LIBS) $(XINE_LIB) $(PTHREAD_LIBS)
-xineplug_vo_out_xvmc_la_CFLAGS = $(VISIBILITY_FLAG) $(X_CFLAGS) $(XV_CFLAGS)
+xineplug_vo_out_xvmc_la_CFLAGS = $(AM_CFLAGS) $(X_CFLAGS) $(XV_CFLAGS)
xineplug_vo_out_xxmc_la_SOURCES = $(X11OSD) deinterlace.c video_out_xxmc.c\
xvmc_mocomp.c xvmc_vld.c xxmc.h
xineplug_vo_out_xxmc_la_LIBADD = $(XXMC_LIBS) $(XV_LIBS) $(X_LIBS) $(XINE_LIB) $(PTHREAD_LIBS)
-xineplug_vo_out_xxmc_la_CFLAGS = $(VISIBILITY_FLAG) $(X_CFLAGS) $(XV_CFLAGS) -fno-strict-aliasing
+xineplug_vo_out_xxmc_la_CFLAGS = $(AM_CFLAGS) $(X_CFLAGS) $(XV_CFLAGS) -fno-strict-aliasing
xineplug_vo_out_opengl_la_SOURCES = yuv2rgb.c yuv2rgb_mmx.c yuv2rgb_mlib.c \
video_out_opengl.c myglext.h $(X11OSD)
xineplug_vo_out_opengl_la_LIBADD = $(MLIB_LIBS) $(OPENGL_LIBS) $(GLUT_LIBS) \
$(GLU_LIBS) $(X_LIBS) $(XINE_LIB) $(PTHREAD_LIBS) $(DYNAMIC_LD_LIBS)
-xineplug_vo_out_opengl_la_CFLAGS = $(VISIBILITY_FLAG) $(X_CFLAGS) $(MLIB_CFLAGS) -fno-strict-aliasing
+xineplug_vo_out_opengl_la_CFLAGS = $(AM_CFLAGS) $(X_CFLAGS) $(MLIB_CFLAGS) -fno-strict-aliasing
xineplug_vo_out_syncfb_la_SOURCES = video_out_syncfb.c
xineplug_vo_out_syncfb_la_LIBADD = $(X_LIBS) $(XINE_LIB) $(PTHREAD_LIBS)
-xineplug_vo_out_syncfb_la_CFLAGS = $(VISIBILITY_FLAG)
xineplug_vo_out_pgx64_la_SOURCES = video_out_pgx64.c
xineplug_vo_out_pgx64_la_LIBADD = $(XINE_LIB) $(X_LIBS) $(SUNDGA_LIBS) $(PTHREAD_LIBS)
-xineplug_vo_out_pgx64_la_CFLAGS = $(VISIBILITY_FLAG) $(X_CFLAGS)
+xineplug_vo_out_pgx64_la_CFLAGS = $(AM_CFLAGS) $(X_CFLAGS)
+xineplug_vo_out_pgx64_la_CPPFLAGS = $(AM_CPPFLAGS) $(SUNDGA_CPPFLAGS)
xineplug_vo_out_pgx32_la_SOURCES = video_out_pgx32.c
xineplug_vo_out_pgx32_la_LIBADD = $(XINE_LIB) $(X_LIBS) $(SUNDGA_LIBS) $(PTHREAD_LIBS)
-xineplug_vo_out_pgx32_la_CFLAGS = $(VISIBILITY_FLAG) $(X_CFLAGS)
+xineplug_vo_out_pgx32_la_CFLAGS = $(AM_CFLAGS) $(X_CFLAGS)
+xineplug_vo_out_pgx32_la_CPPFLAGS = $(AM_CPPFLAGS) $(SUNDGA_CPPFLAGS)
xineplug_vo_out_vidix_la_SOURCES = video_out_vidix.c $(X11OSD)
xineplug_vo_out_vidix_la_LIBADD = $(XINE_LIB) $(X_LIBS) \
$(top_builddir)/src/video_out/vidix/libvidix.la $(PTHREAD_LIBS)
-xineplug_vo_out_vidix_la_CFLAGS = $(VISIBILITY_FLAG) $(VIDIX_CFLAGS) $(X_CFLAGS) -fno-strict-aliasing
+xineplug_vo_out_vidix_la_CFLAGS = $(AM_CFLAGS) $(X_CFLAGS) -fno-strict-aliasing
+xineplug_vo_out_vidix_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_builddir)/src/video_out/vidix \
+ -I$(top_srcdir)/src/video_out/vidix
+
xineplug_vo_out_aa_la_SOURCES = video_out_aa.c
xineplug_vo_out_aa_la_LIBADD = $(AALIB_LIBS) $(XINE_LIB) $(PTHREAD_LIBS)
-xineplug_vo_out_aa_la_CFLAGS = $(VISIBILITY_FLAG) $(AALIB_CFLAGS)
+xineplug_vo_out_aa_la_CFLAGS = $(AM_CFLAGS) $(AALIB_CFLAGS)
xineplug_vo_out_caca_la_SOURCES = yuv2rgb.c yuv2rgb_mmx.c yuv2rgb_mlib.c \
video_out_caca.c
xineplug_vo_out_caca_la_LIBADD = $(CACA_LIBS) $(XINE_LIB) $(PTHREAD_LIBS)
-xineplug_vo_out_caca_la_CFLAGS = $(VISIBILITY_FLAG) $(CACA_CFLAGS)
+xineplug_vo_out_caca_la_CFLAGS = $(AM_CFLAGS) $(CACA_CFLAGS)
xineplug_vo_out_fb_la_SOURCES = yuv2rgb.c yuv2rgb_mmx.c yuv2rgb_mlib.c \
video_out_fb.c
xineplug_vo_out_fb_la_LIBADD = $(MLIB_LIBS) $(XINE_LIB) $(PTHREAD_LIBS)
-xineplug_vo_out_fb_la_CFLAGS = $(VISIBILITY_FLAG) $(MLIB_CFLAGS)
+xineplug_vo_out_fb_la_CFLAGS = $(AM_CFLAGS) $(MLIB_CFLAGS)
xineplug_vo_out_directfb_la_SOURCES = video_out_directfb_fb.c
xineplug_vo_out_directfb_la_LIBADD = $(XINE_LIB) $(DIRECTFB_LIBS) $(PTHREAD_LIBS)
-xineplug_vo_out_directfb_la_CFLAGS = $(VISIBILITY_FLAG) $(DIRECTFB_CFLAGS) -fno-strict-aliasing
+xineplug_vo_out_directfb_la_CFLAGS = $(AM_CFLAGS) $(DIRECTFB_CFLAGS) -fno-strict-aliasing
xineplug_vo_out_xdirectfb_la_SOURCES = video_out_directfb_x.c $(X11OSD)
xineplug_vo_out_xdirectfb_la_LIBADD = $(XINE_LIB) $(DIRECTFB_LIBS) $(X_LIBS) $(PTHREAD_LIBS)
-xineplug_vo_out_xdirectfb_la_CFLAGS = $(VISIBILITY_FLAG) $(DIRECTFB_CFLAGS) -fno-strict-aliasing
+xineplug_vo_out_xdirectfb_la_CFLAGS = $(AM_CFLAGS) $(DIRECTFB_CFLAGS) -fno-strict-aliasing
xineplug_vo_out_sdl_la_SOURCES = video_out_sdl.c
xineplug_vo_out_sdl_la_LIBADD = $(SDL_LIBS) $(X_LIBS) $(XINE_LIB) $(PTHREAD_LIBS)
-xineplug_vo_out_sdl_la_CFLAGS = $(VISIBILITY_FLAG) $(X_CFLAGS) $(SDL_CFLAGS)
+xineplug_vo_out_sdl_la_CFLAGS = $(AM_CFLAGS) $(X_CFLAGS) $(SDL_CFLAGS)
xineplug_vo_out_stk_la_SOURCES = video_out_stk.c
xineplug_vo_out_stk_la_LIBADD = $(XINE_LIB) $(LIBSTK_LIBS) $(PTHREAD_LIBS)
-xineplug_vo_out_stk_la_CFLAGS = $(VISIBILITY_FLAG) $(LIBSTK_CFLAGS)
+xineplug_vo_out_stk_la_CFLAGS = $(AM_CFLAGS) $(LIBSTK_CFLAGS)
xineplug_vo_out_directx_la_SOURCES = yuv2rgb.c yuv2rgb_mmx.c video_out_directx.c
-xineplug_vo_out_directx_la_CPPFLAGS = $(AM_CPPFLAGS) $(DIRECTX_CPPFLAGS)
xineplug_vo_out_directx_la_LIBADD = $(DIRECTX_VIDEO_LIBS) $(XINE_LIB) $(PTHREAD_LIBS)
-xineplug_vo_out_directx_la_CFLAGS = $(VISIBILITY_FLAG)
+xineplug_vo_out_directx_la_CPPFLAGS = $(AM_CPPFLAGS) $(DIRECTX_CPPFLAGS)
xineplug_vo_out_none_la_SOURCES = video_out_none.c
xineplug_vo_out_none_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS)
-xineplug_vo_out_none_la_CFLAGS = $(VISIBILITY_FLAG)
xineplug_vo_out_macosx_la_SOURCES = video_out_macosx.m
-xineplug_vo_out_macosx_la_CPPFLAGS = $(AM_CPPFLAGS) $(X_CFLAGS) $(MLIB_CFLAGS)
-xineplug_vo_out_macosx_la_OBJCFLAGS = $(VISIBILITY_FLAG)
-xineplug_vo_out_macosx_la_LIBADD = $(MLIB_LIBS) $(OPENGL_LIBS) $(GLUT_LIBS) \
- $(GLU_LIBS) $(X_LIBS) $(XINE_LIB) $(PTHREAD_LIBS)
-# The "-Wl,-framework -Wl,Cocoa" is needed for libtool versions before
-# 1.5.x (1.257): the default version that ships with Mac OS X is 1.5 (1.1220)
-xineplug_vo_out_macosx_la_LDFLAGS = $(AM_LDFLAGS) \
- -Wl,-framework -Wl,Cocoa -framework Cocoa -framework OpenGL
-
-noinst_HEADERS = deinterlace.h video_out_syncfb.h \
- yuv2rgb.h x11osd.h xcbosd.h
+xineplug_vo_out_macosx_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS)
+xineplug_vo_out_macosx_la_LDFLAGS = $(AM_LDFLAGS) -framework Cocoa -framework OpenGL
diff --git a/src/video_out/deinterlace.h b/src/video_out/deinterlace.h
index a9904b42a..6f398fcbd 100644
--- a/src/video_out/deinterlace.h
+++ b/src/video_out/deinterlace.h
@@ -41,7 +41,7 @@ void deinterlace_yuv( uint8_t *pdst, uint8_t *psrc[],
#define DEINTERLACE_ONEFIELDXV 5
#define DEINTERLACE_LINEARBLEND 6
-static const char *deinterlace_methods[] = {
+static const char *const deinterlace_methods[] = {
"none",
"bob",
"weave",
diff --git a/src/video_out/libdha/Makefile.am b/src/video_out/libdha/Makefile.am
index 8d94347d1..05aebb704 100644
--- a/src/video_out/libdha/Makefile.am
+++ b/src/video_out/libdha/Makefile.am
@@ -1,19 +1,23 @@
include $(top_srcdir)/misc/Makefile.common
-EXTRA_DIST = README pci_db2c.awk
+SUBDIRS = bin oth sysdep
-SUBDIRS = bin kernelhelper oth sysdep
+if BUILD_DHA_KMOD
+SUBDIRS += kernelhelper
+endif
-AM_CFLAGS = @STATIC@
+AM_CFLAGS = $(DEFAULT_OCFLAGS)
-if HAVE_VIDIX
-dha_lib = libdha.la
-endif
+EXTRA_DIST = README pci_db2c.awk
awk_generated = pci_dev_ids.c pci_ids.h pci_names.c pci_names.h pci_vendors.h
CLEANFILES = $(awk_generated)
-noinst_LTLIBRARIES = $(dha_lib)
+noinst_HEADERS = AsmMacros.h libdha.h pci_ids.h pci_names.h pci_vendors.h
+
+if ENABLE_VIDIX
+noinst_LTLIBRARIES = libdha.la
+endif
libdha_la_SOURCES = libdha.c mtrr.c pci.c mmi.c ports.c irq.c cpu_flush.c
nodist_libdha_la_SOURCES = pci_names.c
@@ -23,8 +27,6 @@ EXTRA_PROGRAMS = test
test_SOURCES = test.c
test_LDADD = $(top_builddir)/src/video_out/libdha/libdha.la
-noinst_HEADERS = AsmMacros.h libdha.h pci_ids.h pci_names.h pci_vendors.h
-
## for OpenBSD LIBS += -li386
## We have to create some files, on the fly, this is why this rule is needed.
@@ -33,7 +35,7 @@ oth/pci.db:
$(awk_generated): pci_db2c.awk oth/pci.db
LC_ALL=C $(AWK) -f $(top_srcdir)/src/video_out/libdha/pci_db2c.awk \
- $(top_srcdir)/src/video_out/libdha/oth/pci.db
+ $(top_srcdir)/src/video_out/libdha/oth/pci.db
pci_names.lo: $(awk_generated)
source='$*.c' object='$@' libtool=yes \
diff --git a/src/video_out/libdha/kernelhelper/Makefile.am b/src/video_out/libdha/kernelhelper/Makefile.am
index 82a37eae3..fffaab433 100644
--- a/src/video_out/libdha/kernelhelper/Makefile.am
+++ b/src/video_out/libdha/kernelhelper/Makefile.am
@@ -2,7 +2,7 @@ include $(top_srcdir)/misc/Makefile.common
EXTRA_DIST = README dhahelper.c
-KCFLAGS = -O2 -Wall -D__KERNEL__ -DMODULE -include `echo @LINUX_INCLUDE@ | sed -e 's/\-I//g'`/linux/modversions.h
+KCFLAGS = -O2 -Wall -D__KERNEL__ -DMODULE -include `echo $(LINUX_INCLUDE) | sed -e 's/\-I//g'`/linux/modversions.h
KVERSION = $(shell $(SHELL) -c 'uname -r')
moddir = /lib/modules/$(KVERSION)/misc
@@ -10,10 +10,8 @@ moddir = /lib/modules/$(KVERSION)/misc
KCOMPILE = $(CC) $(CFLAGS) $(KCFLAGS) $(INCLUDES) $(LINUX_INCLUDE)
if HAVE_LINUX
-if BUILD_DHA_KMOD
KERNEL_MODULE = dhahelper.o
endif
-endif
noinst_HEADERS = dhahelper.h
@@ -29,25 +27,24 @@ nodes:
all: $(KERNEL_MODULE)
install-exec-local: $(KERNEL_MODULE)
-@BUILD_DHA_KMOD_TRUE@ @$(NORMAL_INSTALL)
-@BUILD_DHA_KMOD_TRUE@ $(mkinstalldirs) $(DESTDIR)$(moddir)
-@BUILD_DHA_KMOD_TRUE@ @list='$(KERNEL_MODULE)'; \
-@BUILD_DHA_KMOD_TRUE@ for p in $$list; do \
-@BUILD_DHA_KMOD_TRUE@ if test -f $$p; then \
-@BUILD_DHA_KMOD_TRUE@ echo "$(INSTALL) -o root -g root -m 644 $$p $(DESTDIR)$(moddir)/$$p"; \
-@BUILD_DHA_KMOD_TRUE@ $(INSTALL) -o root -g root -m 644 $$p $(DESTDIR)$(moddir)/$$p; \
-@BUILD_DHA_KMOD_TRUE@ else :; fi; \
-@BUILD_DHA_KMOD_TRUE@ done; \
-@BUILD_DHA_KMOD_TRUE@ $(DEPMOD) -a
-@BUILD_DHA_KMOD_TRUE@ if test ! -c /dev/dhahelper; then \
-@BUILD_DHA_KMOD_TRUE@ $(MAKE) nodes; \
-@BUILD_DHA_KMOD_TRUE@ fi
-
+ @$(NORMAL_INSTALL)
+ $(mkinstalldirs) $(DESTDIR)$(moddir)
+ @list='$(KERNEL_MODULE)'; \
+ for p in $$list; do \
+ if test -f $$p; then \
+ echo "$(INSTALL) -o root -g root -m 644 $$p $(DESTDIR)$(moddir)/$$p"; \
+ $(INSTALL) -o root -g root -m 644 $$p $(DESTDIR)$(moddir)/$$p; \
+ else :; fi; \
+ done; \
+ $(DEPMOD) -a
+ if test ! -c /dev/dhahelper; then \
+ $(MAKE) nodes; \
+ fi
uninstall-local:
-@BUILD_DHA_KMOD_TRUE@ @$(NORMAL_UNINSTALL)
-@BUILD_DHA_KMOD_TRUE@ @list='$(KERNEL_MODULE)'; \
-@BUILD_DHA_KMOD_TRUE@ for p in $$list; do \
-@BUILD_DHA_KMOD_TRUE@ echo "rm -f $(DESTDIR)$(moddir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`"; \
-@BUILD_DHA_KMOD_TRUE@ rm -f $(DESTDIR)$(moddir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \
-@BUILD_DHA_KMOD_TRUE@ done
+ @$(NORMAL_UNINSTALL)
+ @list='$(KERNEL_MODULE)'; \
+ for p in $$list; do \
+ echo "rm -f $(DESTDIR)$(moddir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`"; \
+ rm -f $(DESTDIR)$(moddir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \
+ done
diff --git a/src/video_out/macosx/Makefile.am b/src/video_out/macosx/Makefile.am
index a69f30dc5..ae6a5acc8 100644
--- a/src/video_out/macosx/Makefile.am
+++ b/src/video_out/macosx/Makefile.am
@@ -1,27 +1,12 @@
include $(top_srcdir)/misc/Makefile.common
-AM_CPPFLAGS = -DXINE_COMPILE
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
+AM_OBJCFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG)
-EXTRA_DIST = \
- video_window.h \
- XineOpenGLView.m \
- XineOpenGLView.h \
- XineVideoWindow.m \
- XineVideoWindow.h
-
-if HAVE_MACOSX_VIDEO
+xineinclude_HEADERS = video_window.h XineOpenGLView.h XineVideoWindow.h
lib_LTLIBRARIES = libxineMacOSXVideo.la
libxineMacOSXVideo_la_SOURCES = XineOpenGLView.m XineVideoWindow.m
-# The "-Wl,-framework -Wl,..." is needed for libtool versions before
-# 1.5.x (1.257): the default version that ships with Mac OS X is 1.5 (1.1220)
-libxineMacOSXVideo_la_LDFLAGS = -version-info \
- $(XINE_LT_CURRENT):$(XINE_LT_REVISION):$(XINE_LT_AGE) \
- -Wl,-framework -Wl,Cocoa -framework Cocoa \
- -Wl,-framework -Wl,OpenGL -framework OpenGL
-
-xineinclude_HEADERS = video_window.h XineOpenGLView.h XineVideoWindow.h
-
-endif
-
+libxineMacOSXVideo_la_LDFLAGS = $(AM_LDFLAGS) -framework Cocoa -framework OpenGL \
+ -version-info $(XINE_LT_CURRENT):$(XINE_LT_REVISION):$(XINE_LT_AGE)
diff --git a/src/video_out/video_out_directfb.c b/src/video_out/video_out_directfb.c
index efbb30f2d..a374c56de 100644
--- a/src/video_out/video_out_directfb.c
+++ b/src/video_out/video_out_directfb.c
@@ -1333,8 +1333,8 @@ static void update_config_cb (void *data, xine_cfg_entry_t *entry) {
static void init_config (directfb_driver_t *this) {
config_values_t *config = this->xine->config;
- static const char *buffermode_enum[] = {"single", "double", "triple", 0};
- static const char *fieldparity_enum[] = {"none", "top", "bottom", 0};
+ static const char *const buffermode_enum[] = {"single", "double", "triple", 0};
+ static const char *const fieldparity_enum[] = {"none", "top", "bottom", 0};
this->buffermode = config->register_enum (config,
"video.device.directfb_buffermode", this->buffermode, (char**)buffermode_enum,
diff --git a/src/video_out/video_out_directx.c b/src/video_out/video_out_directx.c
index 7c3e5a78c..7c3e5a78c 100644..100755
--- a/src/video_out/video_out_directx.c
+++ b/src/video_out/video_out_directx.c
diff --git a/src/video_out/video_out_fb.c b/src/video_out/video_out_fb.c
index e88def112..e2672e2a1 100644
--- a/src/video_out/video_out_fb.c
+++ b/src/video_out/video_out_fb.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2000-2003 the xine project and Fredrik Noring
+ * Copyright (C) 2000-2007 the xine project and Fredrik Noring
*
* This file is part of xine, a free video player.
*
@@ -18,28 +18,28 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
* $Id: video_out_fb.c,v 1.49 2006/12/19 19:10:51 dsalt Exp $
- *
- * video_out_fb.c, frame buffer xine driver by Miguel Freitas
+ */
+
+/**
+ * @file
+ * @brief Frame buffer xine driver
*
- * Contributors:
+ * @author Miguel Freitas
*
- * Fredrik Noring <noring@nocrew.org>: Zero copy buffers and clean up.
+ * @author Fredrik Noring <noring@nocrew.org>:
+ * Zero copy buffers and clean up.
*
- * based on xine's video_out_xshm.c...
- * ...based on mpeg2dec code from
- * Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ * @author Aaron Holtzman <aholtzma@ess.engr.uvic.ca>:
+ * Based on xine's video_out_xshm.c, based on mpeg2dec code from
*
- * ideas from ppmtofb - Display P?M graphics on framebuffer devices
- * by Geert Uytterhoeven and Chris Lawrence
+ * @author Geert Uytterhoeven and Chris Lawrence:
+ * Ideas from ppmtofb - Display P?M graphics on framebuffer devices.
*
- * Note: Use this with fbxine. It may work with the regular xine too,
- * provided the visual type is changed (see below).
+ * @note Use this with fbxine.
*
- * TODO: VT switching (configurable)
+ * @todo VT Switching (configurable)
*/
-/* #define USE_X11_VISUAL */
-
#define RECOMMENDED_NUM_BUFFERS 5
#define MAXIMUM_NUM_BUFFERS 25
@@ -356,21 +356,10 @@ static void reset_dest_pointers(fb_frame_t *frame, int flags)
static void frame_reallocate(fb_driver_t *this, fb_frame_t *frame,
uint32_t width, uint32_t height, int format)
{
- if(frame->chunk[0])
- {
- free(frame->chunk[0]);
- frame->chunk[0] = NULL;
- }
- if(frame->chunk[1])
- {
- free(frame->chunk[1]);
- frame->chunk[1] = NULL;
- }
- if(frame->chunk[2])
- {
- free(frame->chunk[2]);
- frame->chunk[2] = NULL;
- }
+ free(frame->chunk[0]);
+ free(frame->chunk[1]);
+ free(frame->chunk[2]);
+ memset(frame->chunk, 0, sizeof(frame->chunk[0])*3);
if(this->use_zero_copy)
{
@@ -380,10 +369,9 @@ static void frame_reallocate(fb_driver_t *this, fb_frame_t *frame,
}
else
{
- if(frame->data)
- free(frame->data);
- frame->data = xine_xmalloc(frame->sc.output_width *
- frame->sc.output_height *
+ free(frame->data);
+ frame->data = xine_xcalloc(frame->sc.output_width *
+ frame->sc.output_height,
this->bytes_per_pixel);
}
@@ -842,7 +830,7 @@ static void register_callbacks(fb_driver_t *this)
static int open_fb_device(config_values_t *config, xine_t *xine)
{
- static char devkey[] = "video.device.fb_device"; /* Why static? */
+ static const char devkey[] = "video.device.fb_device";
char *device_name;
int fd;
@@ -924,7 +912,7 @@ static int mode_visual(fb_driver_t *this, config_values_t *config,
}
}
- xprintf(this->xine, XINE_VERBOSITY_LOG, _("video_out_fb: Your video mode was not recognized, sorry.\n"));
+ xprintf(this->xine, XINE_VERBOSITY_LOG, _("%s: Your video mode was not recognized, sorry.\n"), LOG_MODULE);
return 0;
}
@@ -981,16 +969,16 @@ static void setup_buffers(fb_driver_t *this,
this->cur_frame = this->old_frame = 0;
xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("video_out_fb: %d video RAM buffers are available.\n"), this->total_num_native_buffers);
+ _("%s: %d video RAM buffers are available.\n"), LOG_MODULE, this->total_num_native_buffers);
if(this->total_num_native_buffers < RECOMMENDED_NUM_BUFFERS)
{
this->use_zero_copy = 0;
xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("WARNING: video_out_fb: Zero copy buffers are DISABLED because only %d buffers\n"
+ _("WARNING: %s: Zero copy buffers are DISABLED because only %d buffers\n"
" are available which is less than the recommended %d buffers. Lowering\n"
" the frame buffer resolution might help.\n"),
- this->total_num_native_buffers, RECOMMENDED_NUM_BUFFERS);
+ LOG_MODULE, this->total_num_native_buffers, RECOMMENDED_NUM_BUFFERS);
}
else
{
@@ -998,8 +986,8 @@ static void setup_buffers(fb_driver_t *this,
this->fb_var.yoffset = this->fb_var.yres;
if(ioctl(this->fd, FBIOPAN_DISPLAY, &this->fb_var) == -1) {
xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("WARNING: video_out_fb: Zero copy buffers are DISABLED because kernel driver\n"
- " do not support screen panning (used for frame flips).\n"));
+ _("WARNING: %s: Zero copy buffers are DISABLED because kernel driver\n"
+ " do not support screen panning (used for frame flips).\n"), LOG_MODULE);
} else {
this->fb_var.yoffset = 0;
ioctl(this->fd, FBIOPAN_DISPLAY, &this->fb_var);
@@ -1067,12 +1055,13 @@ static vo_driver_t *fb_open_plugin(video_driver_class_t *class_gen,
if(this->depth > 16)
xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("WARNING: video_out_fb: current display depth is %d. For better performance\n"
- " a depth of 16 bpp is recommended!\n\n"), this->depth);
+ _("WARNING: %s: current display depth is %d. For better performance\n"
+ " a depth of 16 bpp is recommended!\n\n"), LOG_MODULE, this->depth);
xprintf(class->xine, XINE_VERBOSITY_DEBUG,
- "video_out_fb: video mode depth is %d (%d bpp),\n"
+ "%s: video mode depth is %d (%d bpp),\n"
" red: %d/%d, green: %d/%d, blue: %d/%d\n",
+ LOG_MODULE,
this->depth, this->bpp,
this->fb_var.red.length, this->fb_var.red.offset,
this->fb_var.green.length, this->fb_var.green.offset,
@@ -1125,11 +1114,7 @@ static void *fb_init_class(xine_t *xine, void *visual_gen)
static const vo_info_t vo_info_fb =
{
1, /* priority */
-#ifdef USE_X11_VISUAL
- XINE_VISUAL_TYPE_X11 /* visual type */
-#else
XINE_VISUAL_TYPE_FB /* visual type */
-#endif
};
/* exported plugin catalog entry */
diff --git a/src/video_out/video_out_xcbshm.c b/src/video_out/video_out_xcbshm.c
index 5b4eb1fa3..a7c3b3028 100644
--- a/src/video_out/video_out_xcbshm.c
+++ b/src/video_out/video_out_xcbshm.c
@@ -154,8 +154,9 @@ static void create_ximage(xshm_driver_t *this, xshm_frame_t *frame, int width, i
if (shmid < 0) {
xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xcbshm: %s: allocating image\n"
- "video_out_xcbshm: => not using MIT Shared Memory extension.\n"), strerror(errno));
+ _("%s: %s: allocating image\n"), LOG_MODULE, strerror(errno));
+ xprintf(this->xine, XINE_VERBOSITY_LOG,
+ _("%s: => not using MIT Shared Memory extension.\n"), LOG_MODULE);
goto shm_fail1;
}
@@ -163,8 +164,9 @@ static void create_ximage(xshm_driver_t *this, xshm_frame_t *frame, int width, i
if (frame->image == ((void *) -1)) {
xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xcbshm: shared memory error (address error) when allocating image \n"
- "video_out_xcbshm: => not using MIT Shared Memory extension.\n"));
+ _("%s: shared memory error (address error) when allocating image \n"), LOG_MODULE);
+ xprintf(this->xine, XINE_VERBOSITY_LOG,
+ _("%s: => not using MIT Shared Memory extension.\n"), LOG_MODULE);
goto shm_fail2;
}
@@ -174,8 +176,9 @@ static void create_ximage(xshm_driver_t *this, xshm_frame_t *frame, int width, i
if (generic_error != NULL) {
xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xcbshm: x11 error during shared memory XImage creation\n"
- "video_out_xcbshm: => not using MIT Shared Memory extension.\n"));
+ _("%s: x11 error during shared memory XImage creation\n"), LOG_MODULE);
+ xprintf(this->xine, XINE_VERBOSITY_LOG,
+ _("%s: => not using MIT Shared Memory extension.\n"), LOG_MODULE);
free(generic_error);
goto shm_fail3;
}
@@ -736,7 +739,7 @@ static int xshm_get_property (vo_driver_t *this_gen, int property) {
return this->sc.gui_height;
default:
xprintf(this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xcbshm: tried to get unsupported property %d\n", property);
+ LOG_MODULE ": tried to get unsupported property %d\n", property);
}
return 0;
@@ -752,7 +755,7 @@ static int xshm_set_property (vo_driver_t *this_gen,
value = XINE_VO_ASPECT_AUTO;
this->sc.user_ratio = value;
xprintf(this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xcbshm: aspect ratio changed to %s\n", _x_vo_scale_aspect_ratio_name(value));
+ LOG_MODULE ": aspect ratio changed to %s\n", _x_vo_scale_aspect_ratio_name(value));
} else if (property == VO_PROP_BRIGHTNESS) {
@@ -786,7 +789,7 @@ static int xshm_set_property (vo_driver_t *this_gen,
} else {
xprintf (this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xcbshm: tried to set unsupported property %d\n", property);
+ LOG_MODULE ": tried to set unsupported property %d\n", property);
}
return value;
@@ -1110,7 +1113,7 @@ static vo_driver_t *xshm_open_plugin(video_driver_class_t *class_gen, const void
}
else {
xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xcbshm: MIT shared memory extension not present on display.\n"));
+ _("%s: MIT shared memory extension not present on display.\n"), LOG_MODULE);
this->use_shm = 0;
}
@@ -1148,8 +1151,8 @@ static vo_driver_t *xshm_open_plugin(video_driver_class_t *class_gen, const void
swapped = cpu_byte_order != image_byte_order;
xprintf(this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xcbshm: video mode depth is %d (%d bpp), %s, %sswapped,\n"
- "\tred: %08x, green: %08x, blue: %08x\n",
+ LOG_MODULE ": video mode depth is %d (%d bpp), %s, %sswapped,\n"
+ LOG_MODULE ": red: %08x, green: %08x, blue: %08x\n",
this->depth, this->bpp,
visual_class_name(visualtype),
swapped ? "" : "not ",
@@ -1209,7 +1212,7 @@ static vo_driver_t *xshm_open_plugin(video_driver_class_t *class_gen, const void
if (!mode) {
xprintf (this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xcbshm: your video mode was not recognized, sorry :-(\n"));
+ _("%s: your video mode was not recognized, sorry :-(\n"), LOG_MODULE);
return NULL;
}
diff --git a/src/video_out/video_out_xcbxv.c b/src/video_out/video_out_xcbxv.c
index 432d93416..36d6de7a7 100644
--- a/src/video_out/video_out_xcbxv.c
+++ b/src/video_out/video_out_xcbxv.c
@@ -267,8 +267,9 @@ static void create_ximage(xv_driver_t *this, xv_frame_t *frame, int width, int h
if (frame->xv_data_size == 0) {
xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xcbxv: XvShmCreateImage returned a zero size\n"
- "video_out_xcbxv: => not using MIT Shared Memory extension.\n"));
+ _("%s: XvShmCreateImage returned a zero size\n"), LOG_MODULE);
+ xprintf(this->xine, XINE_VERBOSITY_LOG,
+ _("%s: => not using MIT Shared Memory extension.\n"), LOG_MODULE);
goto shm_fail1;
}
@@ -276,8 +277,9 @@ static void create_ximage(xv_driver_t *this, xv_frame_t *frame, int width, int h
if (shmid < 0 ) {
xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xcbxv: shared memory error in shmget: %s\n"
- "video_out_xcbxv: => not using MIT Shared Memory extension.\n"), strerror(errno));
+ _("%s: shared memory error in shmget: %s\n"), LOG_MODULE, strerror(errno));
+ xprintf(this->xine, XINE_VERBOSITY_LOG,
+ _("%s: => not using MIT Shared Memory extension.\n"), LOG_MODULE);
goto shm_fail1;
}
@@ -285,7 +287,9 @@ static void create_ximage(xv_driver_t *this, xv_frame_t *frame, int width, int h
if (frame->image == ((void *) -1)) {
xprintf(this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xcbxv: shared memory error (address error)\n");
+ _("%s: shared memory error (address error)\n"), LOG_MODULE);
+ xprintf(this->xine, XINE_VERBOSITY_LOG,
+ _("%s: => not using MIT Shared Memory extension.\n"), LOG_MODULE);
goto shm_fail2;
}
@@ -295,8 +299,9 @@ static void create_ximage(xv_driver_t *this, xv_frame_t *frame, int width, int h
if (generic_error != NULL) {
xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xcbxv: x11 error during shared memory XImage creation\n"
- "video_out_xcbxv: => not using MIT Shared Memory extension.\n"));
+ _("%s: x11 error during shared memory XImage creation\n"), LOG_MODULE);
+ xprintf(this->xine, XINE_VERBOSITY_LOG,
+ _("%s: => not using MIT Shared Memory extension.\n"), LOG_MODULE);
free(generic_error);
goto shm_fail3;
}
@@ -364,7 +369,7 @@ static void xv_update_frame_format (vo_driver_t *this_gen,
|| (frame->height != height)
|| (frame->format != format)) {
- /* printf ("video_out_xcbxv: updating frame to %d x %d (ratio=%d, format=%08x)\n",width,height,ratio_code,format); */
+ /* printf (LOG_MODULE ": updating frame to %d x %d (ratio=%d, format=%08x)\n",width,height,ratio_code,format); */
pthread_mutex_lock(&this->main_mutex);
@@ -692,7 +697,7 @@ static void xv_display_frame (vo_driver_t *this_gen, vo_frame_t *frame_gen) {
xv_driver_t *this = (xv_driver_t *) this_gen;
xv_frame_t *frame = (xv_frame_t *) frame_gen;
/*
- printf ("video_out_xcbxv: xv_display_frame...\n");
+ printf (LOG_MODULE ": xv_display_frame...\n");
*/
/*
@@ -759,7 +764,7 @@ static void xv_display_frame (vo_driver_t *this_gen, vo_frame_t *frame_gen) {
pthread_mutex_unlock(&this->main_mutex);
/*
- printf ("video_out_xcbxv: xv_display_frame... done\n");
+ printf (LOG_MODULE ": xv_display_frame... done\n");
*/
}
@@ -775,7 +780,7 @@ static int xv_get_property (vo_driver_t *this_gen, int property) {
break;
}
- lprintf("video_out_xcbxv: property #%d = %d\n", property, this->props[property].value);
+ lprintf(LOG_MODULE ": property #%d = %d\n", property, this->props[property].value);
return this->props[property].value;
}
@@ -824,7 +829,7 @@ static int xv_set_property (vo_driver_t *this_gen,
case VO_PROP_INTERLACED:
this->props[property].value = value;
xprintf(this->xine, XINE_VERBOSITY_LOG,
- "video_out_xcbxv: VO_PROP_INTERLACED(%d)\n", this->props[property].value);
+ LOG_MODULE ": VO_PROP_INTERLACED(%d)\n", this->props[property].value);
this->deinterlace_enabled = value;
if (this->deinterlace_method == DEINTERLACE_ONEFIELDXV) {
xv_compute_ideal_size (this);
@@ -838,7 +843,7 @@ static int xv_set_property (vo_driver_t *this_gen,
this->props[property].value = value;
xprintf(this->xine, XINE_VERBOSITY_LOG,
- "video_out_xcbxv: VO_PROP_ASPECT_RATIO(%d)\n", this->props[property].value);
+ LOG_MODULE ": VO_PROP_ASPECT_RATIO(%d)\n", this->props[property].value);
this->sc.user_ratio = value;
xv_compute_ideal_size (this);
@@ -850,7 +855,7 @@ static int xv_set_property (vo_driver_t *this_gen,
if ((value >= XINE_VO_ZOOM_MIN) && (value <= XINE_VO_ZOOM_MAX)) {
this->props[property].value = value;
xprintf(this->xine, XINE_VERBOSITY_LOG,
- "video_out_xcbxv: VO_PROP_ZOOM_X = %d\n", this->props[property].value);
+ LOG_MODULE ": VO_PROP_ZOOM_X = %d\n", this->props[property].value);
this->sc.zoom_factor_x = (double)value / (double)XINE_VO_ZOOM_STEP;
@@ -864,7 +869,7 @@ static int xv_set_property (vo_driver_t *this_gen,
if ((value >= XINE_VO_ZOOM_MIN) && (value <= XINE_VO_ZOOM_MAX)) {
this->props[property].value = value;
xprintf(this->xine, XINE_VERBOSITY_LOG,
- "video_out_xcbxv: VO_PROP_ZOOM_Y = %d\n", this->props[property].value);
+ LOG_MODULE ": VO_PROP_ZOOM_Y = %d\n", this->props[property].value);
this->sc.zoom_factor_y = (double)value / (double)XINE_VO_ZOOM_STEP;
@@ -1146,7 +1151,7 @@ static void xv_check_capability (xv_driver_t *this,
free(get_attribute_reply);
xprintf(this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xcbxv: port attribute %s (%d) value is %d\n", str_prop, property, int_default);
+ LOG_MODULE ": port attribute %s (%d) value is %d\n", str_prop, property, int_default);
/* disable autopaint colorkey by default */
/* might be overridden using config entry */
@@ -1217,7 +1222,7 @@ static void xv_update_XV_FILTER(void *this_gen, xine_cfg_entry_t *entry) {
pthread_mutex_unlock(&this->main_mutex);
xprintf(this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xcbxv: bilinear scaling mode (XV_FILTER) = %d\n",xv_filter);
+ LOG_MODULE ": bilinear scaling mode (XV_FILTER) = %d\n",xv_filter);
}
static void xv_update_XV_DOUBLE_BUFFER(void *this_gen, xine_cfg_entry_t *entry) {
@@ -1237,7 +1242,7 @@ static void xv_update_XV_DOUBLE_BUFFER(void *this_gen, xine_cfg_entry_t *entry)
pthread_mutex_unlock(&this->main_mutex);
xprintf(this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xcbxv: double buffering mode = %d\n", xv_double_buffer);
+ LOG_MODULE ": double buffering mode = %d\n", xv_double_buffer);
}
static void xv_update_xv_pitch_alignment(void *this_gen, xine_cfg_entry_t *entry) {
@@ -1286,7 +1291,7 @@ static vo_driver_t *open_plugin(video_driver_class_t *class_gen, const void *vis
query_extension_reply = xcb_get_extension_data(this->connection, &xcb_xv_id);
if (!query_extension_reply || !query_extension_reply->present) {
- xprintf (class->xine, XINE_VERBOSITY_LOG, _("video_out_xcbxv: Xv extension not present.\n"));
+ xprintf (class->xine, XINE_VERBOSITY_LOG, _("%s: Xv extension not present.\n"), LOG_MODULE);
return NULL;
}
@@ -1298,7 +1303,7 @@ static vo_driver_t *open_plugin(video_driver_class_t *class_gen, const void *vis
query_adaptors_reply = xcb_xv_query_adaptors_reply(this->connection, query_adaptors_cookie, NULL);
if (!query_adaptors_reply) {
- xprintf(class->xine, XINE_VERBOSITY_DEBUG, "video_out_xcbxv: XvQueryAdaptors failed.\n");
+ xprintf(class->xine, XINE_VERBOSITY_DEBUG, LOG_MODULE ": XvQueryAdaptors failed.\n");
return NULL;
}
@@ -1328,16 +1333,17 @@ static vo_driver_t *open_plugin(video_driver_class_t *class_gen, const void *vis
if (!xv_port) {
xprintf(class->xine, XINE_VERBOSITY_LOG,
- _("video_out_xcbxv: Xv extension is present but I couldn't find a usable yuv12 port.\n"
- " Looks like your graphics hardware driver doesn't support Xv?!\n"));
+ _("%s: Xv extension is present but I couldn't find a usable yuv12 port.\n"
+ "\tLooks like your graphics hardware driver doesn't support Xv?!\n"),
+ LOG_MODULE);
/* XvFreeAdaptorInfo (adaptor_info); this crashed on me (gb)*/
return NULL;
}
else
xprintf(class->xine, XINE_VERBOSITY_LOG,
- _("video_out_xcbxv: using Xv port %d from adaptor %s for hardware "
- "colorspace conversion and scaling.\n"), xv_port,
+ _("%s: using Xv port %d from adaptor %s for hardware "
+ "colorspace conversion and scaling.\n"), LOG_MODULE, xv_port,
xcb_xv_adaptor_info_name(adaptor_it.data));
this->xv_port = xv_port;
@@ -1409,7 +1415,7 @@ static vo_driver_t *open_plugin(video_driver_class_t *class_gen, const void *vis
if(!strcmp(xcb_xv_attribute_info_name(attribute_it.data), "XV_HUE")) {
if (!strncmp(xcb_xv_adaptor_info_name(adaptor_it.data), "NV", 2)) {
- xprintf (this->xine, XINE_VERBOSITY_NONE, "video_out_xcbxv: ignoring broken XV_HUE settings on NVidia cards");
+ xprintf (this->xine, XINE_VERBOSITY_NONE, LOG_MODULE ": ignoring broken XV_HUE settings on NVidia cards");
} else {
xv_check_capability (this, VO_PROP_HUE, attribute_it.data,
adaptor_it.data->base_id,
@@ -1479,7 +1485,7 @@ static vo_driver_t *open_plugin(video_driver_class_t *class_gen, const void *vis
free(query_attributes_reply);
}
else
- xprintf(this->xine, XINE_VERBOSITY_DEBUG, "video_out_xcbxv: no port attributes defined.\n");
+ xprintf(this->xine, XINE_VERBOSITY_DEBUG, LOG_MODULE ": no port attributes defined.\n");
free(query_adaptors_reply);
/*
@@ -1504,12 +1510,12 @@ static vo_driver_t *open_plugin(video_driver_class_t *class_gen, const void *vis
this->xv_format_yv12 = format_it.data->id;
this->capabilities |= VO_CAP_YV12;
xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xcbxv: this adaptor supports the yv12 format.\n"));
+ _("%s: this adaptor supports the yv12 format.\n"), LOG_MODULE);
} else if (format_it.data->id == XINE_IMGFMT_YUY2) {
this->xv_format_yuy2 = format_it.data->id;
this->capabilities |= VO_CAP_YUY2;
xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xcbxv: this adaptor supports the yuy2 format.\n"));
+ _("%s: this adaptor supports the yuy2 format.\n"), LOG_MODULE);
}
}
diff --git a/src/video_out/video_out_xshm.c b/src/video_out/video_out_xshm.c
index 00d3bee1c..79ab41e00 100644
--- a/src/video_out/video_out_xshm.c
+++ b/src/video_out/video_out_xshm.c
@@ -148,7 +148,7 @@ static int HandleXError (Display *display, XErrorEvent *xevent) {
char str [1024];
XGetErrorText (display, xevent->error_code, str, 1024);
- printf ("video_out_xshm: received X error event: %s\n", str);
+ printf (LOG_MODULE ": received X error event: %s\n", str);
gX11Fail = 1;
return 0;
@@ -199,8 +199,9 @@ static XImage *create_ximage (xshm_driver_t *this, XShmSegmentInfo *shminfo,
if (myimage == NULL ) {
xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xshm: shared memory error when allocating image\n"
- "video_out_xshm: => not using MIT Shared Memory extension.\n"));
+ _("%s: shared memory error when allocating image\n"), LOG_MODULE);
+ xprintf(this->xine, XINE_VERBOSITY_LOG,
+ _("%s: => not using MIT Shared Memory extension.\n"), LOG_MODULE);
this->use_shm = 0;
goto finishShmTesting;
}
@@ -215,8 +216,9 @@ static XImage *create_ximage (xshm_driver_t *this, XShmSegmentInfo *shminfo,
if (shminfo->shmid < 0 ) {
xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xshm: %s: allocating image\n"
- "video_out_xshm: => not using MIT Shared Memory extension.\n"), strerror(errno));
+ _("%s: %s: allocating image\n"), LOG_MODULE, strerror(errno));
+ xprintf(this->xine, XINE_VERBOSITY_LOG,
+ _("%s: => not using MIT Shared Memory extension.\n"), LOG_MODULE);
this->use_shm = 0;
goto finishShmTesting;
}
@@ -225,8 +227,9 @@ static XImage *create_ximage (xshm_driver_t *this, XShmSegmentInfo *shminfo,
if (shminfo->shmaddr == ((char *) -1)) {
xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xshm: shared memory error (address error) when allocating image \n"
- "video_out_xshm: => not using MIT Shared Memory extension.\n"));
+ _("%s: shared memory error (address error) when allocating image \n"), LOG_MODULE);
+ xprintf(this->xine, XINE_VERBOSITY_LOG,
+ _("%s: => not using MIT Shared Memory extension.\n"), LOG_MODULE);
shmctl (shminfo->shmid, IPC_RMID, 0);
shminfo->shmid = -1;
this->use_shm = 0;
@@ -241,10 +244,11 @@ static XImage *create_ximage (xshm_driver_t *this, XShmSegmentInfo *shminfo,
XSync(this->display, False);
if (gX11Fail) {
- xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xshm: x11 error during shared memory XImage creation\n"
- "video_out_xshm: => not using MIT Shared Memory extension.\n"));
shmdt (shminfo->shmaddr);
+ xprintf(this->xine, XINE_VERBOSITY_LOG,
+ _("%s: x11 error during shared memory XImage creation\n"), LOG_MODULE);
+ xprintf(this->xine, XINE_VERBOSITY_LOG,
+ _("%s: => not using MIT Shared Memory extension.\n"), LOG_MODULE);
shmctl (shminfo->shmid, IPC_RMID, 0);
shminfo->shmid = -1;
this->use_shm = 0;
@@ -284,7 +288,7 @@ static XImage *create_ximage (xshm_driver_t *this, XShmSegmentInfo *shminfo,
this->bytes_per_pixel = this->bpp / 8;
this->image_byte_order = myimage->byte_order;
- myimage->data = xine_xmalloc (width * this->bytes_per_pixel * height);
+ myimage->data = xine_xcalloc (width * height, this->bytes_per_pixel);
}
return myimage;
@@ -825,7 +829,7 @@ static int xshm_get_property (vo_driver_t *this_gen, int property) {
return this->sc.gui_height;
default:
xprintf(this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xshm: tried to get unsupported property %d\n", property);
+ LOG_MODULE ": tried to get unsupported property %d\n", property);
}
return 0;
@@ -841,7 +845,7 @@ static int xshm_set_property (vo_driver_t *this_gen,
value = XINE_VO_ASPECT_AUTO;
this->sc.user_ratio = value;
xprintf(this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xshm: aspect ratio changed to %s\n", _x_vo_scale_aspect_ratio_name(value));
+ LOG_MODULE ": aspect ratio changed to %s\n", _x_vo_scale_aspect_ratio_name(value));
} else if (property == VO_PROP_BRIGHTNESS) {
@@ -875,7 +879,7 @@ static int xshm_set_property (vo_driver_t *this_gen,
} else {
xprintf (this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xshm: tried to set unsupported property %d\n", property);
+ LOG_MODULE ": tried to set unsupported property %d\n", property);
}
return value;
@@ -1167,7 +1171,7 @@ static vo_driver_t *xshm_open_plugin_2 (video_driver_class_t *class_gen, const v
}
else {
xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xshm: MIT shared memory extension not present on display.\n"));
+ _("%s: MIT shared memory extension not present on display.\n"), LOG_MODULE);
this->use_shm = 0;
}
@@ -1188,8 +1192,8 @@ static vo_driver_t *xshm_open_plugin_2 (video_driver_class_t *class_gen, const v
swapped = cpu_byte_order != this->image_byte_order;
xprintf(this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xshm: video mode depth is %d (%d bpp), %s, %sswapped,\n"
- "\tred: %08lx, green: %08lx, blue: %08lx\n",
+ LOG_MODULE ": video mode depth is %d (%d bpp), %s, %sswapped,\n"
+ LOG_MODULE ": red: %08lx, green: %08lx, blue: %08lx\n",
this->depth, this->bpp,
visual_class_name(this->visual),
swapped ? "" : "not ",
@@ -1251,7 +1255,7 @@ static vo_driver_t *xshm_open_plugin_2 (video_driver_class_t *class_gen, const v
if (!mode) {
xprintf (this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xshm: your video mode was not recognized, sorry :-(\n"));
+ _("%s: your video mode was not recognized, sorry :-(\n"), LOG_MODULE);
return NULL;
}
diff --git a/src/video_out/video_out_xv.c b/src/video_out/video_out_xv.c
index 95a847c2c..4338246ae 100644
--- a/src/video_out/video_out_xv.c
+++ b/src/video_out/video_out_xv.c
@@ -295,8 +295,9 @@ static XvImage *create_ximage (xv_driver_t *this, XShmSegmentInfo *shminfo,
if (image == NULL ) {
xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xv: XvShmCreateImage failed\n"
- "video_out_xv: => not using MIT Shared Memory extension.\n"));
+ _("%s: XvShmCreateImage failed\n"), LOG_MODULE);
+ xprintf(this->xine, XINE_VERBOSITY_LOG,
+ _("%s: => not using MIT Shared Memory extension.\n"), LOG_MODULE);
this->use_shm = 0;
goto finishShmTesting;
}
@@ -321,16 +322,18 @@ static XvImage *create_ximage (xv_driver_t *this, XShmSegmentInfo *shminfo,
if (image->data_size==0) {
xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xv: XvShmCreateImage returned a zero size\n"
- "video_out_xv: => not using MIT Shared Memory extension.\n"));
+ _("%s: XvShmCreateImage returned a zero size\n"), LOG_MODULE);
+ xprintf(this->xine, XINE_VERBOSITY_LOG,
+ _("%s: => not using MIT Shared Memory extension.\n"), LOG_MODULE);
this->use_shm = 0;
goto finishShmTesting;
}
if (shminfo->shmid < 0 ) {
xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xv: shared memory error in shmget: %s\n"
- "video_out_xv: => not using MIT Shared Memory extension.\n"), strerror(errno));
+ _("%s: shared memory error in shmget: %s\n"), LOG_MODULE, strerror(errno));
+ xprintf(this->xine, XINE_VERBOSITY_LOG,
+ _("%s: => not using MIT Shared Memory extension.\n"), LOG_MODULE);
this->use_shm = 0;
goto finishShmTesting;
}
@@ -339,14 +342,14 @@ static XvImage *create_ximage (xv_driver_t *this, XShmSegmentInfo *shminfo,
if (shminfo->shmaddr == NULL) {
xprintf(this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xv: shared memory error (address error NULL)\n");
+ LOG_MODULE ": shared memory error (address error NULL)\n");
this->use_shm = 0;
goto finishShmTesting;
}
if (shminfo->shmaddr == ((char *) -1)) {
xprintf(this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xv: shared memory error (address error)\n");
+ LOG_MODULE ": shared memory error (address error)\n");
this->use_shm = 0;
goto finishShmTesting;
}
@@ -360,12 +363,13 @@ static XvImage *create_ximage (xv_driver_t *this, XShmSegmentInfo *shminfo,
shmctl(shminfo->shmid, IPC_RMID, 0);
if (gX11Fail) {
- xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xv: x11 error during shared memory XImage creation\n"
- "video_out_xv: => not using MIT Shared Memory extension.\n"));
shmdt (shminfo->shmaddr);
shmctl (shminfo->shmid, IPC_RMID, 0);
shminfo->shmid = -1;
+ xprintf(this->xine, XINE_VERBOSITY_LOG,
+ _("%s: x11 error during shared memory XImage creation\n"), LOG_MODULE);
+ xprintf(this->xine, XINE_VERBOSITY_LOG,
+ _("%s: => not using MIT Shared Memory extension.\n"), LOG_MODULE);
this->use_shm = 0;
goto finishShmTesting;
}
@@ -448,7 +452,7 @@ static void xv_update_frame_format (vo_driver_t *this_gen,
|| (frame->height != height)
|| (frame->format != format)) {
- /* printf ("video_out_xv: updating frame to %d x %d (ratio=%d, format=%08x)\n",width,height,ratio_code,format); */
+ /* printf (LOG_MODULE ": updating frame to %d x %d (ratio=%d, format=%08x)\n",width,height,ratio_code,format); */
LOCK_DISPLAY(this);
@@ -784,7 +788,7 @@ static void xv_display_frame (vo_driver_t *this_gen, vo_frame_t *frame_gen) {
xv_driver_t *this = (xv_driver_t *) this_gen;
xv_frame_t *frame = (xv_frame_t *) frame_gen;
/*
- printf ("video_out_xv: xv_display_frame...\n");
+ printf (LOG_MODULE ": xv_display_frame...\n");
*/
/*
@@ -864,7 +868,7 @@ static void xv_display_frame (vo_driver_t *this_gen, vo_frame_t *frame_gen) {
}
/*
- printf ("video_out_xv: xv_display_frame... done\n");
+ printf (LOG_MODULE ": xv_display_frame... done\n");
*/
}
@@ -880,7 +884,7 @@ static int xv_get_property (vo_driver_t *this_gen, int property) {
break;
}
- lprintf("video_out_xv: property #%d = %d\n", property, this->props[property].value);
+ lprintf(LOG_MODULE ": property #%d = %d\n", property, this->props[property].value);
return this->props[property].value;
}
@@ -925,7 +929,7 @@ static int xv_set_property (vo_driver_t *this_gen,
case VO_PROP_INTERLACED:
this->props[property].value = value;
xprintf(this->xine, XINE_VERBOSITY_LOG,
- "video_out_xv: VO_PROP_INTERLACED(%d)\n", this->props[property].value);
+ LOG_MODULE ": VO_PROP_INTERLACED(%d)\n", this->props[property].value);
this->deinterlace_enabled = value;
if (this->deinterlace_method == DEINTERLACE_ONEFIELDXV) {
xv_compute_ideal_size (this);
@@ -939,7 +943,7 @@ static int xv_set_property (vo_driver_t *this_gen,
this->props[property].value = value;
xprintf(this->xine, XINE_VERBOSITY_LOG,
- "video_out_xv: VO_PROP_ASPECT_RATIO(%d)\n", this->props[property].value);
+ LOG_MODULE ": VO_PROP_ASPECT_RATIO(%d)\n", this->props[property].value);
this->sc.user_ratio = value;
xv_compute_ideal_size (this);
@@ -951,7 +955,7 @@ static int xv_set_property (vo_driver_t *this_gen,
if ((value >= XINE_VO_ZOOM_MIN) && (value <= XINE_VO_ZOOM_MAX)) {
this->props[property].value = value;
xprintf(this->xine, XINE_VERBOSITY_LOG,
- "video_out_xv: VO_PROP_ZOOM_X = %d\n", this->props[property].value);
+ LOG_MODULE ": VO_PROP_ZOOM_X = %d\n", this->props[property].value);
this->sc.zoom_factor_x = (double)value / (double)XINE_VO_ZOOM_STEP;
@@ -965,7 +969,7 @@ static int xv_set_property (vo_driver_t *this_gen,
if ((value >= XINE_VO_ZOOM_MIN) && (value <= XINE_VO_ZOOM_MAX)) {
this->props[property].value = value;
xprintf(this->xine, XINE_VERBOSITY_LOG,
- "video_out_xv: VO_PROP_ZOOM_Y = %d\n", this->props[property].value);
+ LOG_MODULE ": VO_PROP_ZOOM_Y = %d\n", this->props[property].value);
this->sc.zoom_factor_y = (double)value / (double)XINE_VO_ZOOM_STEP;
@@ -1141,7 +1145,7 @@ static void xv_dispose (vo_driver_t *this_gen) {
LOCK_DISPLAY(this);
if(XvUngrabPort (this->display, this->xv_port, CurrentTime) != Success) {
- xprintf (this->xine, XINE_VERBOSITY_DEBUG, "video_out_xv: xv_exit: XvUngrabPort() failed.\n");
+ xprintf (this->xine, XINE_VERBOSITY_DEBUG, LOG_MODULE ": xv_exit: XvUngrabPort() failed.\n");
}
XFreeGC(this->display, this->gc);
UNLOCK_DISPLAY(this);
@@ -1208,7 +1212,7 @@ static void xv_check_capability (xv_driver_t *this,
this->props[property].atom, &int_default);
xprintf(this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xv: port attribute %s (%d) value is %d\n", str_prop, property, int_default);
+ LOG_MODULE ": port attribute %s (%d) value is %d\n", str_prop, property, int_default);
/* disable autopaint colorkey by default */
/* might be overridden using config entry */
@@ -1275,7 +1279,7 @@ static void xv_update_XV_FILTER(void *this_gen, xine_cfg_entry_t *entry) {
UNLOCK_DISPLAY(this);
xprintf(this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xv: bilinear scaling mode (XV_FILTER) = %d\n",xv_filter);
+ LOG_MODULE ": bilinear scaling mode (XV_FILTER) = %d\n",xv_filter);
}
static void xv_update_XV_DOUBLE_BUFFER(void *this_gen, xine_cfg_entry_t *entry) {
@@ -1291,7 +1295,7 @@ static void xv_update_XV_DOUBLE_BUFFER(void *this_gen, xine_cfg_entry_t *entry)
UNLOCK_DISPLAY(this);
xprintf(this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xv: double buffering mode = %d\n", xv_double_buffer);
+ LOG_MODULE ": double buffering mode = %d\n", xv_double_buffer);
}
static void xv_update_xv_pitch_alignment(void *this_gen, xine_cfg_entry_t *entry) {
@@ -1340,7 +1344,7 @@ static vo_driver_t *open_plugin_2 (video_driver_class_t *class_gen, const void *
LOCK_DISPLAY(this);
if (Success != XvQueryExtension(this->display, &ver,&rel, &req, &ev,&err)) {
- xprintf (class->xine, XINE_VERBOSITY_LOG, _("video_out_xv: Xv extension not present.\n"));
+ xprintf (class->xine, XINE_VERBOSITY_LOG, _("%s: Xv extension not present.\n"), LOG_MODULE);
UNLOCK_DISPLAY(this);
return NULL;
}
@@ -1350,7 +1354,7 @@ static vo_driver_t *open_plugin_2 (video_driver_class_t *class_gen, const void *
*/
if (Success != XvQueryAdaptors(this->display,DefaultRootWindow(this->display), &adaptors, &adaptor_info)) {
- xprintf(class->xine, XINE_VERBOSITY_DEBUG, "video_out_xv: XvQueryAdaptors failed.\n");
+ xprintf(class->xine, XINE_VERBOSITY_DEBUG, LOG_MODULE ": XvQueryAdaptors failed.\n");
UNLOCK_DISPLAY(this);
return NULL;
}
@@ -1377,8 +1381,9 @@ static vo_driver_t *open_plugin_2 (video_driver_class_t *class_gen, const void *
if (!xv_port) {
xprintf(class->xine, XINE_VERBOSITY_LOG,
- _("video_out_xv: Xv extension is present but I couldn't find a usable yuv12 port.\n"
- " Looks like your graphics hardware driver doesn't support Xv?!\n"));
+ _("%s: Xv extension is present but I couldn't find a usable yuv12 port.\n"
+ "\tLooks like your graphics hardware driver doesn't support Xv?!\n"),
+ LOG_MODULE);
/* XvFreeAdaptorInfo (adaptor_info); this crashed on me (gb)*/
UNLOCK_DISPLAY(this);
@@ -1386,8 +1391,8 @@ static vo_driver_t *open_plugin_2 (video_driver_class_t *class_gen, const void *
}
else
xprintf(class->xine, XINE_VERBOSITY_LOG,
- _("video_out_xv: using Xv port %ld from adaptor %s for hardware "
- "colorspace conversion and scaling.\n"), xv_port,
+ _("%s: using Xv port %ld from adaptor %s for hardware "
+ "colorspace conversion and scaling.\n"), LOG_MODULE, xv_port,
adaptor_info[adaptor_num].name);
UNLOCK_DISPLAY(this);
@@ -1469,7 +1474,7 @@ static vo_driver_t *open_plugin_2 (video_driver_class_t *class_gen, const void *
if(!strcmp(attr[k].name, "XV_HUE")) {
if (!strncmp(adaptor_info[adaptor_num].name, "NV", 2)) {
- xprintf (this->xine, XINE_VERBOSITY_NONE, "video_out_xv: ignoring broken XV_HUE settings on NVidia cards");
+ xprintf (this->xine, XINE_VERBOSITY_NONE, LOG_MODULE ": ignoring broken XV_HUE settings on NVidia cards");
} else {
xv_check_capability (this, VO_PROP_HUE, attr[k],
adaptor_info[adaptor_num].base_id,
@@ -1539,7 +1544,7 @@ static vo_driver_t *open_plugin_2 (video_driver_class_t *class_gen, const void *
XFree(attr);
}
else
- xprintf(this->xine, XINE_VERBOSITY_DEBUG, "video_out_xv: no port attributes defined.\n");
+ xprintf(this->xine, XINE_VERBOSITY_DEBUG, LOG_MODULE ": no port attributes defined.\n");
XvFreeAdaptorInfo(adaptor_info);
/*
@@ -1561,12 +1566,12 @@ static vo_driver_t *open_plugin_2 (video_driver_class_t *class_gen, const void *
this->xv_format_yv12 = fo[i].id;
this->capabilities |= VO_CAP_YV12;
xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xv: this adaptor supports the yv12 format.\n"));
+ _("%s: this adaptor supports the yv12 format.\n"), LOG_MODULE);
} else if (fo[i].id == XINE_IMGFMT_YUY2) {
this->xv_format_yuy2 = fo[i].id;
this->capabilities |= VO_CAP_YUY2;
xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xv: this adaptor supports the yuy2 format.\n"));
+ _("%s: this adaptor supports the yuy2 format.\n"), LOG_MODULE);
}
}
diff --git a/src/video_out/video_out_xxmc.c b/src/video_out/video_out_xxmc.c
index 1c71bb534..9d4f89103 100644
--- a/src/video_out/video_out_xxmc.c
+++ b/src/video_out/video_out_xxmc.c
@@ -165,14 +165,10 @@ static void xxmc_xvmc_surface_handler_construct(xxmc_driver_t *this)
xvmc_surface_handler_t *handler = &this->xvmc_surf_handler;
pthread_mutex_init(&handler->mutex,NULL);
- for (i=0; i<XVMC_MAX_SURFACES; ++i) {
- handler->surfInUse[i] = 0;
- handler->surfValid[i] = 0;
- }
- for (i=0; i<XVMC_MAX_SUBPICTURES; ++i) {
- handler->subInUse[i] = 0;
- handler->subValid[i] = 0;
- }
+ memset(handler->surfInUse, 0, sizeof(*handler->surfInUse)*XVMC_MAX_SURFACES);
+ memset(handler->surfValid, 0, sizeof(*handler->surfValid)*XVMC_MAX_SURFACES);
+ memset(handler->subInUse, 0, sizeof(*handler->subInUse)*XVMC_MAX_SUBPICTURES);
+ memset(handler->subValid, 0, sizeof(*handler->subValid)*XVMC_MAX_SUBPICTURES);
}
static void xxmc_xvmc_destroy_surfaces(xxmc_driver_t *this)
@@ -242,7 +238,7 @@ static XvMCSurface *xxmc_xvmc_alloc_surface(xxmc_driver_t *this,
}
XVMCUNLOCKDISPLAY( this->display );
xprintf (this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xxmc: Created surface %d\n",i);
+ LOG_MODULE ": Created surface %d\n",i);
handler->surfInUse[i] = 1;
handler->surfValid[i] = 1;
pthread_mutex_unlock(&handler->mutex);
@@ -262,7 +258,7 @@ static void xxmc_xvmc_free_surface(xxmc_driver_t *this, XvMCSurface *surf)
if (index >= XVMC_MAX_SURFACES) return;
pthread_mutex_lock(&handler->mutex);
xprintf (this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xxmc: Disposing of surface %d\n",index);
+ LOG_MODULE ": Disposing of surface %d\n",index);
handler->surfInUse[index]--;
xxmc_xvmc_dump_surfaces(this);
pthread_mutex_unlock(&handler->mutex);
@@ -322,7 +318,7 @@ static XvMCSubpicture *xxmc_xvmc_alloc_subpicture
}
XVMCUNLOCKDISPLAY( this->display );
xprintf (this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xxmc: Created subpicture %d\n",i);
+ LOG_MODULE ": Created subpicture %d\n",i);
handler->subInUse[i] = 1;
handler->subValid[i] = 1;
pthread_mutex_unlock(&handler->mutex);
@@ -343,7 +339,7 @@ static void xxmc_xvmc_free_subpicture(xxmc_driver_t *this, XvMCSubpicture *sub)
if (index >= XVMC_MAX_SUBPICTURES) return;
pthread_mutex_lock(&handler->mutex);
xprintf (this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xxmc: Disposing of subpicture %d\n",index);
+ LOG_MODULE ": Disposing of subpicture %d\n",index);
handler->subInUse[index] = 0;
xxmc_xvmc_dump_subpictures(this);
pthread_mutex_unlock(&handler->mutex);
@@ -647,8 +643,9 @@ static XvImage *create_ximage (xxmc_driver_t *this, XShmSegmentInfo *shminfo,
if (image == NULL ) {
xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xxmc: XvShmCreateImage failed\n"
- "video_out_xxmc: => not using MIT Shared Memory extension.\n"));
+ _("%s: XvShmCreateImage failed\n"), LOG_MODULE);
+ xprintf(this->xine, XINE_VERBOSITY_LOG,
+ _("%s: => not using MIT Shared Memory extension.\n"), LOG_MODULE);
this->use_shm = 0;
goto finishShmTesting;
}
@@ -657,16 +654,18 @@ static XvImage *create_ximage (xxmc_driver_t *this, XShmSegmentInfo *shminfo,
if (image->data_size==0) {
xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xxmc: XvShmCreateImage returned a zero size\n"
- "video_out_xxmc: => not using MIT Shared Memory extension.\n"));
+ _("%s: XvShmCreateImage returned a zero size\n"), LOG_MODULE);
+ xprintf(this->xine, XINE_VERBOSITY_LOG,
+ _("%s: => not using MIT Shared Memory extension.\n"), LOG_MODULE);
this->use_shm = 0;
goto finishShmTesting;
}
if (shminfo->shmid < 0 ) {
xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xxmc: shared memory error in shmget: %s\n"
- "video_out_xxmc: => not using MIT Shared Memory extension.\n"), strerror(errno));
+ _("%s: shared memory error in shmget: %s\n"), LOG_MODULE, strerror(errno));
+ xprintf(this->xine, XINE_VERBOSITY_LOG,
+ _("%s: => not using MIT Shared Memory extension.\n"), LOG_MODULE);
this->use_shm = 0;
goto finishShmTesting;
}
@@ -675,14 +674,14 @@ static XvImage *create_ximage (xxmc_driver_t *this, XShmSegmentInfo *shminfo,
if (shminfo->shmaddr == NULL) {
xprintf(this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xxmc: shared memory error (address error NULL)\n");
+ LOG_MODULE ": shared memory error (address error NULL)\n");
this->use_shm = 0;
goto finishShmTesting;
}
if (shminfo->shmaddr == ((char *) -1)) {
xprintf(this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xxmc: shared memory error (address error)\n");
+ LOG_MODULE ": shared memory error (address error)\n");
this->use_shm = 0;
goto finishShmTesting;
}
@@ -696,12 +695,13 @@ static XvImage *create_ximage (xxmc_driver_t *this, XShmSegmentInfo *shminfo,
shmctl(shminfo->shmid, IPC_RMID, 0);
if (gX11Fail) {
- xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xxmc: x11 error during shared memory XImage creation\n"
- "video_out_xxmc: => not using MIT Shared Memory extension.\n"));
shmdt (shminfo->shmaddr);
shmctl (shminfo->shmid, IPC_RMID, 0);
shminfo->shmid = -1;
+ xprintf(this->xine, XINE_VERBOSITY_LOG,
+ _("%s: x11 error during shared memory XImage creation\n"), LOG_MODULE);
+ xprintf(this->xine, XINE_VERBOSITY_LOG,
+ _("%s: => not using MIT Shared Memory extension.\n"), LOG_MODULE);
this->use_shm = 0;
goto finishShmTesting;
}
@@ -766,13 +766,13 @@ static void xxmc_dispose_context(xxmc_driver_t *driver)
}
xprintf(driver->xine, XINE_VERBOSITY_LOG,
- "video_out_xxmc: Freeing up XvMC Surfaces and subpictures.\n");
+ LOG_MODULE ": Freeing up XvMC Surfaces and subpictures.\n");
if (driver->xvmc_palette) free(driver->xvmc_palette);
_x_dispose_xx44_palette( &driver->palette );
xxmc_xvmc_destroy_subpictures( driver );
xxmc_xvmc_destroy_surfaces( driver );
xprintf(driver->xine, XINE_VERBOSITY_LOG,
- "video_out_xxmc: Freeing up XvMC Context.\n");
+ LOG_MODULE ": Freeing up XvMC Context.\n");
XLockDisplay (driver->display);
if (driver->subImage)
dispose_ximage(driver, &driver->subShmInfo, driver->subImage);
@@ -812,10 +812,10 @@ static int xxmc_find_context(xxmc_driver_t *driver, xine_xxmc_t *xxmc,
curCap = driver->xvmc_cap;
for (i =0; i < driver->xvmc_num_cap; ++i) {
xprintf(driver->xine, XINE_VERBOSITY_LOG,
- "video_out_xxmc: Surface type %d. Capabilities 0x%8x 0x%8x\n",i,
+ LOG_MODULE ": Surface type %d. Capabilities 0x%8x 0x%8x\n",i,
curCap->mpeg_flags,curCap->accel_flags);
xprintf(driver->xine, XINE_VERBOSITY_LOG,
- "video_out_xxmc: Requests: 0x%8x 0x%8x\n",
+ LOG_MODULE ": Requests: 0x%8x 0x%8x\n",
request_mpeg_flags,request_accel_flags);
if (((curCap->mpeg_flags & request_mpeg_flags) == request_mpeg_flags) &&
((curCap->accel_flags & request_accel_flags)) &&
@@ -846,7 +846,7 @@ static int xxmc_create_context(xxmc_driver_t *driver, unsigned width, unsigned h
curCap = driver->xvmc_cap + driver->xvmc_cur_cap;
xprintf(driver->xine, XINE_VERBOSITY_LOG,
- "video_out_xxmc: Creating new XvMC Context %d\n",curCap->type_id);
+ LOG_MODULE ": Creating new XvMC Context %d\n",curCap->type_id);
XVMCLOCKDISPLAY( driver->display );
if (Success == XvMCCreateContext( driver->display, driver->xv_port,
curCap->type_id, width,
@@ -879,7 +879,7 @@ static void xxmc_setup_subpictures(xxmc_driver_t *driver, unsigned width, unsign
if ((driver->xvmc_backend_subpic = (curCap->flags & XVMC_BACKEND_SUBPICTURE)))
xprintf(driver->xine, XINE_VERBOSITY_LOG,
- "video_out_xxmc: Using Backend subpictures.\n");
+ LOG_MODULE ": Using Backend subpictures.\n");
if (!driver->subImage) {
/*
@@ -895,7 +895,7 @@ static void xxmc_setup_subpictures(xxmc_driver_t *driver, unsigned width, unsign
XUnlockDisplay (driver->display);
if (NULL == driver->subImage) {
xprintf(driver->xine, XINE_VERBOSITY_LOG,
- "video_out_xxmc: Failed allocating XvImage for supbictures.\n");
+ LOG_MODULE ": Failed allocating XvImage for supbictures.\n");
return;
}
}
@@ -990,8 +990,8 @@ static int xxmc_xvmc_update_context(xxmc_driver_t *driver, xxmc_frame_t *frame,
return 0;
xprintf(driver->xine, XINE_VERBOSITY_LOG,
- "video_out_xxmc: New format. Need to change XvMC Context.\n"
- "width: %d height: %d", width, height);
+ LOG_MODULE ": New format. Need to change XvMC Context.\n"
+ LOG_MODULE ": width: %d height: %d", width, height);
if (frame_format_xxmc) {
xprintf(driver->xine, XINE_VERBOSITY_LOG,
" mpeg: %d acceleration: %d", xxmc->mpeg, xxmc->acceleration);
@@ -1011,17 +1011,17 @@ static int xxmc_xvmc_update_context(xxmc_driver_t *driver, xxmc_frame_t *frame,
if ((driver->xvmc_accel &
(XINE_XVMC_ACCEL_MOCOMP | XINE_XVMC_ACCEL_IDCT))) {
if (!xxmc_mocomp_create_macroblocks(driver, frame, 1)) {
- lprintf("video_out_xxmc: ERROR: Macroblock allocation failed\n");
+ printf(LOG_MODULE ": ERROR: Macroblock allocation failed\n");
xxmc_dispose_context( driver );
}
}
}
if (!driver->contextActive) {
- printf("video_out_xxmc: Using software decoding for this stream.\n");
+ printf(LOG_MODULE ": Using software decoding for this stream.\n");
driver->xvmc_accel = 0;
} else {
- printf("video_out_xxmc: Using hardware decoding for this stream.\n");
+ printf(LOG_MODULE ": Using hardware decoding for this stream.\n");
}
driver->xvmc_mpeg = xxmc->mpeg;
@@ -1057,9 +1057,9 @@ static void xxmc_frame_updates(xxmc_driver_t *driver,
if (frame->xvmc_surf == NULL) {
if (NULL == (frame->xvmc_surf =
xxmc_xvmc_alloc_surface( driver, &driver->context))) {
- fprintf(stderr, "video_out_xxmc: ERROR: Accelerated surface allocation failed.\n"
- "video_out_xxmc: You are probably out of framebuffer memory.\n"
- "video_out_xxmc: Falling back to software decoding.\n");
+ fprintf(stderr, LOG_MODULE ": ERROR: Accelerated surface allocation failed.\n"
+ LOG_MODULE ": You are probably out of framebuffer memory.\n"
+ LOG_MODULE ": Falling back to software decoding.\n");
driver->xvmc_accel = 0;
xxmc_dispose_context( driver );
return;
@@ -1747,7 +1747,7 @@ static int xxmc_get_property (vo_driver_t *this_gen, int property) {
break;
}
- lprintf("video_out_xxmc: property #%d = %d\n", property, this->props[property].value);
+ lprintf("%s: property #%d = %d\n", LOG_MODULE, property, this->props[property].value);
return this->props[property].value;
}
@@ -1810,7 +1810,7 @@ static int xxmc_set_property (vo_driver_t *this_gen,
case VO_PROP_INTERLACED:
this->props[property].value = value;
xprintf(this->xine, XINE_VERBOSITY_LOG,
- "video_out_xxmc: VO_PROP_INTERLACED(%d)\n", this->props[property].value);
+ LOG_MODULE ": VO_PROP_INTERLACED(%d)\n", this->props[property].value);
this->deinterlace_enabled = value;
break;
@@ -1820,7 +1820,7 @@ static int xxmc_set_property (vo_driver_t *this_gen,
this->props[property].value = value;
xprintf(this->xine, XINE_VERBOSITY_LOG,
- "video_out_xxmc: VO_PROP_ASPECT_RATIO(%d)\n", this->props[property].value);
+ LOG_MODULE ": VO_PROP_ASPECT_RATIO(%d)\n", this->props[property].value);
this->sc.user_ratio = value;
xxmc_compute_ideal_size (this);
@@ -1832,7 +1832,7 @@ static int xxmc_set_property (vo_driver_t *this_gen,
if ((value >= XINE_VO_ZOOM_MIN) && (value <= XINE_VO_ZOOM_MAX)) {
this->props[property].value = value;
xprintf(this->xine, XINE_VERBOSITY_LOG,
- "video_out_xxmc: VO_PROP_ZOOM_X = %d\n", this->props[property].value);
+ LOG_MODULE ": VO_PROP_ZOOM_X = %d\n", this->props[property].value);
this->sc.zoom_factor_x = (double)value / (double)XINE_VO_ZOOM_STEP;
@@ -1846,7 +1846,7 @@ static int xxmc_set_property (vo_driver_t *this_gen,
if ((value >= XINE_VO_ZOOM_MIN) && (value <= XINE_VO_ZOOM_MAX)) {
this->props[property].value = value;
xprintf(this->xine, XINE_VERBOSITY_LOG,
- "video_out_xxmc: VO_PROP_ZOOM_Y = %d\n", this->props[property].value);
+ LOG_MODULE ": VO_PROP_ZOOM_Y = %d\n", this->props[property].value);
this->sc.zoom_factor_y = (double)value / (double)XINE_VO_ZOOM_STEP;
@@ -1993,7 +1993,7 @@ static void xxmc_dispose (vo_driver_t *this_gen) {
XLockDisplay (this->display);
if(XvUngrabPort (this->display, this->xv_port, CurrentTime) != Success) {
- xprintf (this->xine, XINE_VERBOSITY_DEBUG, "video_out_xxmc: xxmc_exit: XvUngrabPort() failed.\n");
+ xprintf (this->xine, XINE_VERBOSITY_DEBUG, LOG_MODULE ": xxmc_exit: XvUngrabPort() failed.\n");
}
XFreeGC(this->display, this->gc);
XUnlockDisplay (this->display);
@@ -2057,7 +2057,7 @@ static void xxmc_check_capability (xxmc_driver_t *this,
this->props[property].atom, &int_default);
xprintf(this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xxmc: port attribute %s (%d) value is %d\n", str_prop, property, int_default);
+ LOG_MODULE ": port attribute %s (%d) value is %d\n", str_prop, property, int_default);
/*
* We enable autopaint by default.
@@ -2119,7 +2119,7 @@ static void xxmc_update_XV_FILTER(void *this_gen, xine_cfg_entry_t *entry) {
XUnlockDisplay(this->display);
xprintf(this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xxmc: bilinear scaling mode (XV_FILTER) = %d\n",xv_filter);
+ LOG_MODULE ": bilinear scaling mode (XV_FILTER) = %d\n",xv_filter);
}
static void xxmc_update_XV_DOUBLE_BUFFER(void *this_gen, xine_cfg_entry_t *entry) {
@@ -2135,7 +2135,7 @@ static void xxmc_update_XV_DOUBLE_BUFFER(void *this_gen, xine_cfg_entry_t *entry
XUnlockDisplay(this->display);
xprintf(this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xxmc: double buffering mode = %d\n", xv_double_buffer);
+ LOG_MODULE ": double buffering mode = %d\n", xv_double_buffer);
}
static void xxmc_update_xv_pitch_alignment(void *this_gen, xine_cfg_entry_t *entry) {
@@ -2195,7 +2195,7 @@ static void checkXvMCCap( xxmc_driver_t *this, XvPortID xv_port)
return;
}
xprintf (this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xxmc: XvMC extension present.\n");
+ LOG_MODULE ": XvMC extension present.\n");
surfaceInfo = XvMCListSurfaceTypes(this->display, xv_port, &numSurf);
if (0 == surfaceInfo) {
@@ -2211,7 +2211,7 @@ static void checkXvMCCap( xxmc_driver_t *this, XvPortID xv_port)
curCap = this->xvmc_cap;
xprintf (this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xxmc: Found %d XvMC surface types\n",numSurf);
+ LOG_MODULE ": Found %d XvMC surface types\n", numSurf);
for (i=0; i< numSurf; ++i) {
curCap->mpeg_flags = 0;
@@ -2235,10 +2235,10 @@ static void checkXvMCCap( xxmc_driver_t *this, XvPortID xv_port)
curCap->sub_max_height = curInfo->subpicture_max_height;
curCap->flags = curInfo->flags;
xprintf (this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xxmc: Surface type %d: Max size: %d %d.\n",
+ LOG_MODULE ": Surface type %d: Max size: %d %d.\n",
i,curCap->max_width,curCap->max_height);
xprintf (this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xxmc: Surface type %d: Max subpic size: %d %d.\n",
+ LOG_MODULE ": Surface type %d: Max subpic size: %d %d.\n",
i,curCap->sub_max_width,curCap->sub_max_height);
curCap->type_id = curInfo->surface_type_id;
@@ -2247,21 +2247,18 @@ static void checkXvMCCap( xxmc_driver_t *this, XvPortID xv_port)
curCap->subPicType.id = 0;
if (formatValues) {
xprintf (this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xxmc: Surface type %d: Found %d XvMC subpicture "
- "types\n",i,numSub);
+ LOG_MODULE ": Surface type %d: Found %d XvMC subpicture types\n",i,numSub);
for (j = 0; j<numSub; ++j) {
if (formatValues[j].id == FOURCC_IA44) {
curCap->subPicType = formatValues[j];
xprintf (this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xxmc: Surface type %d: Detected and using "
- "IA44 subpicture type.\n",i);
+ LOG_MODULE ": Surface type %d: Detected and using IA44 subpicture type.\n",i);
/* Prefer IA44 */
break;
} else if (formatValues[j].id == FOURCC_AI44) {
curCap->subPicType = formatValues[j];
xprintf (this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xxmc: Surface type %d: Detected AI44 "
- "subpicture type.\n",i);
+ LOG_MODULE ": Surface type %d: Detected AI44 subpicture type.\n",i);
}
}
}
@@ -2292,9 +2289,8 @@ static void checkXvMCCap( xxmc_driver_t *this, XvPortID xv_port)
free(this->xvmc_cap);
this->xvmc_cap = 0;
xprintf (this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xxmc: Apparent attempt to use a direct XvMC "
- "context\nvideo_out_xxmc: on a remote display. "
- "Falling back to XV.\n");
+ LOG_MODULE ": Apparent attempt to use a direct XvMC context on a remote display.\n"
+ LOG_MODULE ": Falling back to Xv.\n");
XVMCUNLOCKDISPLAY( this->display );
xvmc_context_writer_unlock( &this->xvmc_lock );
return;
@@ -2350,7 +2346,7 @@ static vo_driver_t *open_plugin (video_driver_class_t *class_gen, const void *vi
XLockDisplay(this->display);
if (Success != XvQueryExtension(this->display, &ver,&rel, &req, &ev,&err)) {
- xprintf (class->xine, XINE_VERBOSITY_LOG, _("video_out_xxmc: Xv extension not present.\n"));
+ xprintf (class->xine, XINE_VERBOSITY_LOG, _("%s: Xv extension not present.\n"), LOG_MODULE);
XUnlockDisplay(this->display);
return NULL;
}
@@ -2360,7 +2356,7 @@ static vo_driver_t *open_plugin (video_driver_class_t *class_gen, const void *vi
*/
if (Success != XvQueryAdaptors(this->display,DefaultRootWindow(this->display), &adaptors, &adaptor_info)) {
- xprintf(class->xine, XINE_VERBOSITY_DEBUG, "video_out_xxmc: XvQueryAdaptors failed.\n");
+ xprintf(class->xine, XINE_VERBOSITY_DEBUG, LOG_MODULE ": XvQueryAdaptors failed.\n");
XUnlockDisplay(this->display);
return NULL;
}
@@ -2387,8 +2383,9 @@ static vo_driver_t *open_plugin (video_driver_class_t *class_gen, const void *vi
if (!xv_port) {
xprintf(class->xine, XINE_VERBOSITY_LOG,
- _("video_out_xxmc: Xv extension is present but I couldn't find a usable yuv12 port.\n"
- " Looks like your graphics hardware driver doesn't support Xv?!\n"));
+ _("%s: Xv extension is present but I couldn't find a usable yuv12 port.\n"
+ "\tLooks like your graphics hardware driver doesn't support Xv?!\n"),
+ LOG_MODULE);
/* XvFreeAdaptorInfo (adaptor_info); this crashed on me (gb)*/
XUnlockDisplay(this->display);
@@ -2396,8 +2393,8 @@ static vo_driver_t *open_plugin (video_driver_class_t *class_gen, const void *vi
}
else
xprintf(class->xine, XINE_VERBOSITY_LOG,
- _("video_out_xxmc: using Xv port %ld from adaptor %s for hardware "
- "colorspace conversion and scaling.\n"), xv_port,
+ _("%s: using Xv port %ld from adaptor %s for hardware "
+ "colorspace conversion and scaling.\n"), LOG_MODULE, xv_port,
adaptor_info[adaptor_num].name);
XUnlockDisplay(this->display);
@@ -2473,7 +2470,7 @@ static vo_driver_t *open_plugin (video_driver_class_t *class_gen, const void *vi
if((attr[k].flags & XvSettable) && (attr[k].flags & XvGettable)) {
if(!strcmp(attr[k].name, "XV_HUE")) {
if (!strncmp(adaptor_info[adaptor_num].name, "NV", 2)) {
- xprintf (this->xine, XINE_VERBOSITY_NONE, "video_out_xxmc: ignoring broken XV_HUE settings on NVidia cards\n");
+ xprintf (this->xine, XINE_VERBOSITY_NONE, LOG_MODULE ": ignoring broken XV_HUE settings on NVidia cards\n");
} else {
xxmc_check_capability (this, VO_PROP_HUE, attr[k],
adaptor_info[adaptor_num].base_id, "XV_HUE",
@@ -2543,7 +2540,7 @@ static vo_driver_t *open_plugin (video_driver_class_t *class_gen, const void *vi
XFree(attr);
}
else
- xprintf(this->xine, XINE_VERBOSITY_DEBUG, "video_out_xxmc: no port attributes defined.\n");
+ xprintf(this->xine, XINE_VERBOSITY_DEBUG, LOG_MODULE ": no port attributes defined.\n");
XvFreeAdaptorInfo(adaptor_info);
/*
@@ -2572,12 +2569,12 @@ static vo_driver_t *open_plugin (video_driver_class_t *class_gen, const void *vi
this->xv_format_yv12 = fo[i].id;
this->capabilities |= VO_CAP_YV12;
xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xxmc: this adaptor supports the yv12 format.\n"));
+ _("%s: this adaptor supports the yv12 format.\n"), LOG_MODULE);
} else if (fo[i].id == XINE_IMGFMT_YUY2) {
this->xv_format_yuy2 = fo[i].id;
this->capabilities |= VO_CAP_YUY2;
xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xxmc: this adaptor supports the yuy2 format.\n"));
+ _("%s: this adaptor supports the yuy2 format.\n"), LOG_MODULE);
}
}
@@ -2635,10 +2632,10 @@ static vo_driver_t *open_plugin (video_driver_class_t *class_gen, const void *vi
this->cur_field = XVMC_FRAME_PICTURE;
#ifdef HAVE_VLDXVMC
- printf("video_out_xxmc: Unichrome CPU saving is %s.\n",
+ printf("%s: Unichrome CPU saving is %s.\n", LOG_MODULE,
(this->cpu_save_enabled) ? "on":"off");
#else
- printf("video_out_xxmc: warning - compiled with no vld extensions.\n");
+ printf("%s: warning - compiled with no vld extensions.\n", LOG_MODULE);
#endif
this->props[VO_PROP_MAX_NUM_FRAMES].value = (use_more_frames) ? 15:8;
this->cpu_saver = 0.;
diff --git a/src/video_out/vidix/Makefile.am b/src/video_out/vidix/Makefile.am
index 2ca8f168a..7f19e7ce8 100644
--- a/src/video_out/vidix/Makefile.am
+++ b/src/video_out/vidix/Makefile.am
@@ -1,21 +1,16 @@
include $(top_srcdir)/misc/Makefile.common
-EXTRA_DIST = README vidix.txt
-
SUBDIRS = drivers
-AM_CFLAGS = @STATIC@
+AM_CFLAGS = $(DEFAULT_OCFLAGS)
+AM_CPPFLAGS = -I$(top_srcdir)/src/video_out/vidix -I$(top_builddir)/src/video_out/libdha
-if HAVE_VIDIX
-vidix_lib = libvidix.la
-endif
+EXTRA_DIST = README vidix.txt
-noinst_LTLIBRARIES = $(vidix_lib)
+noinst_HEADERS = fourcc.h vidix.h vidixlib.h
+
+noinst_LTLIBRARIES = libvidix.la
libvidix_la_SOURCES = vidixlib.c
libvidix_la_LIBADD = $(DYNAMIC_LD_LIBS) $(top_builddir)/src/video_out/libdha/libdha.la
-noinst_HEADERS = fourcc.h vidix.h vidixlib.h
-
-AM_CPPFLAGS = -I$(top_srcdir)/src/video_out/vidix \
- -I$(top_builddir)/src/video_out/libdha
diff --git a/src/video_out/vidix/drivers/Makefile.am b/src/video_out/vidix/drivers/Makefile.am
index f438dde36..db3adc078 100644
--- a/src/video_out/vidix/drivers/Makefile.am
+++ b/src/video_out/vidix/drivers/Makefile.am
@@ -1,9 +1,16 @@
include $(top_srcdir)/misc/Makefile.common
+AM_CFLAGS = $(DEFAULT_OCFLAGS)
+AM_CPPFLAGS = -I$(top_srcdir)/src/video_out/vidix \
+ -I$(top_srcdir)/src/video_out/libdha -I$(top_builddir)/src/video_out/libdha
+AM_LDFLAGS = $(xineplug_ldflags)
+
EXTRA_DIST = genfb_vid.c
-if HAVE_VIDIX
-vidix_drivers = \
+noinst_HEADERS = mach64.h glint_regs.h pm3_regs.h radeon.h savage_regs.h \
+ cyberblade_regs.h unichrome_regs.h sis_defs.h sis_regs.h
+
+vidix_LTLIBRARIES = \
mach64_vid.la \
mga_crtc2_vid.la \
mga_vid.la \
@@ -16,51 +23,34 @@ vidix_drivers = \
nvidia_vid.la \
sis_vid.la \
savage_vid.la
-endif
-vidix_LTLIBRARIES = $(vidix_drivers)
-
-radeon_vid_la_SOURCES = radeon_vid.c
-radeon_vid_la_LDFLAGS = -avoid-version -module -lm
-
-rage128_vid_la_SOURCES = radeon_vid.c
-rage128_vid_la_LDFLAGS = -avoid-version -module -lm
-rage128_vid_la_CFLAGS = -DRAGE128 $(AM_CFLAGS)
-
-pm2_vid_la_SOURCES = pm2_vid.c
-pm2_vid_la_LDFLAGS = -avoid-version -module
-
-pm3_vid_la_SOURCES = pm3_vid.c
-pm3_vid_la_LDFLAGS = -avoid-version -module
+cyberblade_vid_la_SOURCES = cyberblade_vid.c
mach64_vid_la_SOURCES = mach64_vid.c
-mach64_vid_la_LDFLAGS = -avoid-version -module
+
+mga_crtc2_vid_la_SOURCES = mga_vid.c
+mga_crtc2_vid_la_LIBADD = -lm
+mga_crtc2_vid_la_CPPFLAGS = $(AM_CPPFLAGS) -DCRTC2
mga_vid_la_SOURCES = mga_vid.c
-mga_vid_la_LDFLAGS = -avoid-version -module -lm
+mga_vid_la_LIBADD = -lm
-mga_crtc2_vid_la_SOURCES = mga_vid.c
-mga_crtc2_vid_la_LDFLAGS = -avoid-version -module -lm
-mga_crtc2_vid_la_CFLAGS = -DCRTC2 $(AM_CFLAGS)
+nvidia_vid_la_SOURCES = nvidia_vid.c
-cyberblade_vid_la_SOURCES = cyberblade_vid.c
-cyberblade_vid_la_LDFLAGS = -avoid-version -module
+pm2_vid_la_SOURCES = pm2_vid.c
-unichrome_vid_la_SOURCES = unichrome_vid.c
-unichrome_vid_la_LDFLAGS = -avoid-version -module
+pm3_vid_la_SOURCES = pm3_vid.c
-nvidia_vid_la_SOURCES = nvidia_vid.c
-nvidia_vid_la_LDFLAGS = -avoid-version -module
+radeon_vid_la_SOURCES = radeon_vid.c
+radeon_vid_la_LIBADD = -lm
-sis_vid_la_SOURCES = sis_vid.c sis_bridge.c
-sis_vid_la_LDFLAGS = -avoid-version -module
+rage128_vid_la_SOURCES = radeon_vid.c
+rage128_vid_la_LIBADD = -lm
+rage128_vid_la_CPPFLAGS = $(AM_CPPFLAGS) -DRAGE128
savage_vid_la_SOURCES = savage_vid.c
-savage_vid_la_LDFLAGS = -avoid-version -module -lm
+savage_vid_la_LIBADD = -lm
-noinst_HEADERS = mach64.h glint_regs.h pm3_regs.h radeon.h savage_regs.h \
- cyberblade_regs.h unichrome_regs.h sis_defs.h sis_regs.h
+sis_vid_la_SOURCES = sis_vid.c sis_bridge.c
-AM_CPPFLAGS = -I$(top_srcdir)/src/video_out/vidix \
- -I$(top_srcdir)/src/video_out/libdha \
- -I$(top_builddir)/src/video_out/libdha
+unichrome_vid_la_SOURCES = unichrome_vid.c
diff --git a/src/xine-engine/Makefile.am b/src/xine-engine/Makefile.am
index ecd1968f2..8e4a9777a 100644
--- a/src/xine-engine/Makefile.am
+++ b/src/xine-engine/Makefile.am
@@ -1,18 +1,29 @@
include $(top_srcdir)/misc/Makefile.common
include $(top_srcdir)/lib/Makefile.common
-AM_CFLAGS = $(X_CFLAGS) $(FT2_CFLAGS) $(FONTCONFIG_CFLAGS) $(VISIBILITY_FLAG)
-AM_CPPFLAGS = $(ZLIB_CPPFLAGS) -DXINE_LIBRARY_COMPILE
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(X_CFLAGS) $(FT2_CFLAGS) $(FONTCONFIG_CFLAGS) $(VISIBILITY_FLAG)
+AM_CPPFLAGS = $(XDG_BASEDIR_CPPFLAGS) $(ZLIB_CPPFLAGS) -DXINE_LIBRARY_COMPILE
-LIBTOOL = $(SHELL) $(top_builddir)/libtool
-lib_LTLIBRARIES = libxine.la
+XINEUTILS_LIB = $(top_builddir)/src/xine-utils/libxineutils.la
+
+# FIXME: these are currently unused:
+EXTRA_DIST = lrb.c lrb.h accel_xvmc.h
-XINEUTILS_LIB = $(top_builddir)/src/xine-utils/libxineutils.la
-DEF_FILE = libxine-$(XINE_MAJOR).def
if WIN32
+DEF_FILE = libxine-$(XINE_MAJOR).def
def_ldflags="-Wl,--output-def,$(DEF_FILE)"
endif
+noinst_HEADERS = bswap.h ffmpeg_bswap.h
+
+xineinclude_HEADERS = buffer.h metronom.h configfile.h vo_scale.h \
+ audio_out.h resample.h video_out.h xine_internal.h spu_decoder.h \
+ video_overlay.h osd.h scratch.h xine_plugin.h xineintl.h \
+ plugin_catalog.h audio_decoder.h video_decoder.h post.h \
+ io_helper.h broadcaster.h info_helper.h refcounter.h alphablend.h
+
+lib_LTLIBRARIES = libxine.la
+
libxine_la_SOURCES = xine.c metronom.c configfile.c buffer.c \
load_plugins.c video_decoder.c buffer_types.c \
audio_decoder.c video_out.c audio_out.c resample.c events.c \
@@ -21,27 +32,17 @@ libxine_la_SOURCES = xine.c metronom.c configfile.c buffer.c \
input_rip.c input_cache.c info_helper.c refcounter.c \
alphablend.c
-# FIXME: these are currently unused:
-EXTRA_DIST = lrb.c lrb.h accel_xvmc.h
-
-libxine_la_DEPENDENCIES = $(XINEUTILS_LIB) \
+libxine_la_DEPENDENCIES = $(XINEUTILS_LIB) $(XDG_BASEDIR_DEPS) \
$(pthread_dep) $(LIBXINEPOSIX)
libxine_la_LIBADD = $(PTHREAD_LIBS) $(DYNAMIC_LD_LIBS) $(LTLIBINTL) $(ZLIB_LIBS) \
-lm $(XINEUTILS_LIB) $(LIBICONV) $(FT2_LIBS) $(FONTCONFIG_LIBS) \
- $(LIBXINEPOSIX) $(RT_LIBS) $(NET_LIBS)
-
-libxine_la_LDFLAGS = \
- -version-info $(XINE_LT_CURRENT):$(XINE_LT_REVISION):$(XINE_LT_AGE) \
- $(def_ldflags)
+ $(LIBXINEPOSIX) $(RT_LIBS) $(NET_LIBS) $(XDG_BASEDIR_LIBS)
+libxine_la_LDFLAGS = $(AM_LDFLAGS) $(def_ldflags) \
+ -version-info $(XINE_LT_CURRENT):$(XINE_LT_REVISION):$(XINE_LT_AGE)
-xineinclude_HEADERS = buffer.h metronom.h configfile.h vo_scale.h \
- audio_out.h resample.h video_out.h xine_internal.h spu_decoder.h \
- video_overlay.h osd.h scratch.h xine_plugin.h xineintl.h \
- plugin_catalog.h audio_decoder.h video_decoder.h post.h \
- io_helper.h broadcaster.h info_helper.h refcounter.h alphablend.h
-
-noinst_HEADERS = bswap.h ffmpeg_bswap.h
+$(XINEUTILS_LIB):
+ $(MAKE) -C $(top_builddir)/src/xine-utils libxineutils.la
if WIN32
install-exec-local:
@@ -50,6 +51,3 @@ install-exec-local:
uninstall-local:
rm -f $(DEF_FILE)
endif
-
-$(XINEUTILS_LIB):
- $(MAKE) -C $(top_builddir)/src/xine-utils libxineutils.la
diff --git a/src/xine-engine/alphablend.c b/src/xine-engine/alphablend.c
index 25c223272..57f8213cb 100644
--- a/src/xine-engine/alphablend.c
+++ b/src/xine-engine/alphablend.c
@@ -1104,7 +1104,7 @@ static void blend_yuv_exact(uint8_t *dst_cr, uint8_t *dst_cb, int src_width,
static uint8_t *(*blend_yuv_grow_extra_data(alphablend_t *extra_data, int osd_width))[ 3 ][ 2 ]
{
- struct __attribute__((packed)) header_s {
+ struct XINE_PACKED header_s {
int id;
int max_width;
uint8_t *data[ 3 ][ 2 ];
@@ -1546,7 +1546,7 @@ static void blend_yuy2_exact(uint8_t *dst_cr, uint8_t *dst_cb, int src_width,
static uint8_t *(*blend_yuy2_grow_extra_data(alphablend_t *extra_data, int osd_width))[ 3 ]
{
- struct __attribute__((packed)) header_s {
+ struct XINE_PACKED header_s {
int id;
int max_width;
uint8_t *data[ 3 ];
diff --git a/src/xine-engine/alphablend.h b/src/xine-engine/alphablend.h
index 513ac116f..4fc879b2c 100644
--- a/src/xine-engine/alphablend.h
+++ b/src/xine-engine/alphablend.h
@@ -39,37 +39,14 @@ typedef struct {
void _x_alphablend_init(alphablend_t *extra_data, xine_t *xine) XINE_PROTECTED;
void _x_alphablend_free(alphablend_t *extra_data) XINE_PROTECTED;
-/* _MSC_VER port changes */
-#undef ATTRIBUTE_PACKED
-#undef PRAGMA_PACK_BEGIN
-#undef PRAGMA_PACK_END
-
-#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) || defined(__ICC)
-#define ATTRIBUTE_PACKED __attribute__ ((packed))
-#define PRAGMA_PACK 0
-#endif
-
-#if !defined(ATTRIBUTE_PACKED)
-#define ATTRIBUTE_PACKED
-#define PRAGMA_PACK 1
-#endif
-
-#if PRAGMA_PACK
-#pragma pack(8)
-#endif
-
typedef struct { /* CLUT == Color LookUp Table */
uint8_t cb;
uint8_t cr;
uint8_t y;
uint8_t foo;
-} ATTRIBUTE_PACKED clut_t;
+} XINE_PACKED clut_t;
-#if PRAGMA_PACK
-#pragma pack()
-#endif
-
#define XX44_PALETTE_SIZE 32
typedef struct {
diff --git a/src/xine-engine/audio_out.c b/src/xine-engine/audio_out.c
index d39c99aba..66e28d80d 100644
--- a/src/xine-engine/audio_out.c
+++ b/src/xine-engine/audio_out.c
@@ -16,16 +16,18 @@
* You should have received a copy of the GNU General Public License
* along with self program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+/**
+ * @file
+ * @brief xine-lib audio output implementation
+ *
+ * @date 2001-08-20 First implementation of Audio sync and Audio driver separation.
+ * (c) 2001 James Courtier-Dutton <james@superbug.demon.co.uk>
+ * @date 2001-08-22 James imported some useful AC3 sections from the previous
+ * ALSA driver. (c) 2001 Andy Lo A Foe <andy@alsaplayer.org>
*
- * $Id: audio_out.c,v 1.210 2007/04/01 00:52:36 dgp85 Exp $
*
- * 22-8-2001 James imported some useful AC3 sections from the previous alsa driver.
- * (c) 2001 Andy Lo A Foe <andy@alsaplayer.org>
- * 20-8-2001 First implementation of Audio sync and Audio driver separation.
- * (c) 2001 James Courtier-Dutton James@superbug.demon.co.uk
- */
-
-/*
* General Programming Guidelines: -
* New concept of an "audio_frame".
* An audio_frame consists of all the samples required to fill every
@@ -576,18 +578,16 @@ static void audio_filter_compress (aos_t *this, int16_t *mem, int num_frames) {
}
static void audio_filter_amp (aos_t *this, void *buf, int num_frames) {
-
- int i;
- int num_channels;
double amp_factor;
-
- num_channels = _x_ao_mode2channels (this->input.mode);
- if (!num_channels)
+ int i;
+ const int total_frames = num_frames * _x_ao_mode2channels (this->input.mode);
+
+ if (!total_frames)
return;
amp_factor=this->amp_factor;
if (this->amp_mute || amp_factor == 0) {
- memset (buf, 0, num_frames * num_channels * (this->input.bits / 8));
+ memset (buf, 0, total_frames * (this->input.bits / 8));
return;
}
@@ -595,7 +595,7 @@ static void audio_filter_amp (aos_t *this, void *buf, int num_frames) {
int16_t test;
int8_t *mem = (int8_t *) buf;
- for (i=0; i<num_frames*num_channels; i++) {
+ for (i=0; i<total_frames; i++) {
test = mem[i] * amp_factor;
/* Force limit on amp_factor to prevent clipping */
if (test < INT8_MIN) {
@@ -612,7 +612,7 @@ static void audio_filter_amp (aos_t *this, void *buf, int num_frames) {
int32_t test;
int16_t *mem = (int16_t *) buf;
- for (i=0; i<num_frames*num_channels; i++) {
+ for (i=0; i<total_frames; i++) {
test = mem[i] * amp_factor;
/* Force limit on amp_factor to prevent clipping */
if (test < INT16_MIN) {
diff --git a/src/xine-engine/audio_out.h b/src/xine-engine/audio_out.h
index c5f335dbb..f4e01ad25 100644
--- a/src/xine-engine/audio_out.h
+++ b/src/xine-engine/audio_out.h
@@ -257,11 +257,12 @@ struct audio_driver_class_s {
void (*dispose) (audio_driver_class_t *);
};
-/*
- * this initiates the audio_out sync routines
- * found in ./src/xine-engine/audio_out.c
+/**
+ * @brief Initialise the audio_out sync routines
+ *
+ * @internal
*/
-xine_audio_port_t *_x_ao_new_port (xine_t *xine, ao_driver_t *driver, int grab_only) XINE_PROTECTED;
+xine_audio_port_t *_x_ao_new_port (xine_t *xine, ao_driver_t *driver, int grab_only);
/*
* audio output modes + capabilities
diff --git a/src/xine-engine/buffer.h b/src/xine-engine/buffer.h
index 64fe52a20..ca25dc531 100644
--- a/src/xine-engine/buffer.h
+++ b/src/xine-engine/buffer.h
@@ -56,8 +56,8 @@ extern "C" {
#define BUF_MAX_CALLBACKS 5
-/*
- * buffer types
+/**
+ * @defgroup buffer_types Buffer Types
*
* a buffer type ID describes the contents of a buffer
* it consists of three fields:
@@ -68,17 +68,20 @@ extern "C" {
* DD : decoder selection (e.g. MPEG, OPENDIVX ... for VIDEO)
* CCCC : channel number or other subtype information for the decoder
*/
+/*@{*/
#define BUF_MAJOR_MASK 0xFF000000
#define BUF_DECODER_MASK 0x00FF0000
-/* control buffer types */
-
+/**
+ * @defgroup buffer_ctrl Control buffer types
+ */
+/*@{*/
#define BUF_CONTROL_BASE 0x01000000
#define BUF_CONTROL_START 0x01000000
#define BUF_CONTROL_END 0x01010000
#define BUF_CONTROL_QUIT 0x01020000
-#define BUF_CONTROL_DISCONTINUITY 0x01030000 /* former AVSYNC_RESET */
+#define BUF_CONTROL_DISCONTINUITY 0x01030000 /**< former AVSYNC_RESET */
#define BUF_CONTROL_NOP 0x01040000
#define BUF_CONTROL_AUDIO_CHANNEL 0x01050000
#define BUF_CONTROL_SPU_CHANNEL 0x01060000
@@ -87,11 +90,15 @@ extern "C" {
#define BUF_CONTROL_HEADERS_DONE 0x01090000
#define BUF_CONTROL_FLUSH_DECODER 0x010a0000
#define BUF_CONTROL_RESET_TRACK_MAP 0x010b0000
+/*@}*/
-/* video buffer types: (please keep in sync with buffer_types.c) */
-
+/**
+ * @defgroup buffer_video Video buffer types
+ * @note (please keep in sync with buffer_types.c)
+ */
+/*@{*/
#define BUF_VIDEO_BASE 0x02000000
-#define BUF_VIDEO_UNKNOWN 0x02ff0000 /* no decoder should handle this one */
+#define BUF_VIDEO_UNKNOWN 0x02ff0000 /**< no decoder should handle this one */
#define BUF_VIDEO_MPEG 0x02000000
#define BUF_VIDEO_MPEG4 0x02010000
#define BUF_VIDEO_CINEPAK 0x02020000
@@ -150,7 +157,7 @@ extern "C" {
#define BUF_VIDEO_INTERPLAY 0x02380000
#define BUF_VIDEO_RV40 0x02390000
#define BUF_VIDEO_PSX_MDEC 0x023A0000
-#define BUF_VIDEO_YUV_FRAMES 0x023B0000 /* uncompressed YUV, delivered by v4l input plugin */
+#define BUF_VIDEO_YUV_FRAMES 0x023B0000 /**< uncompressed YUV, delivered by v4l input plugin */
#define BUF_VIDEO_HUFFYUV 0x023C0000
#define BUF_VIDEO_IMAGE 0x023D0000
#define BUF_VIDEO_THEORA 0x023E0000
@@ -165,8 +172,8 @@ extern "C" {
#define BUF_VIDEO_8BPS 0x02470000
#define BUF_VIDEO_ASV1 0x02480000
#define BUF_VIDEO_ASV2 0x02490000
-#define BUF_VIDEO_BITPLANE 0x024A0000 /* Amiga typical picture and animation format */
-#define BUF_VIDEO_BITPLANE_BR1 0x024B0000 /* the same with Bytrun compression 1 */
+#define BUF_VIDEO_BITPLANE 0x024A0000 /**< Amiga typical picture and animation format */
+#define BUF_VIDEO_BITPLANE_BR1 0x024B0000 /**< the same with Bytrun compression 1 */
#define BUF_VIDEO_FLV1 0x024C0000
#define BUF_VIDEO_H264 0x024D0000
#define BUF_VIDEO_MJPEG_B 0x024E0000
@@ -191,11 +198,15 @@ extern "C" {
#define BUF_VIDEO_FLASHSV 0x02610000
#define BUF_VIDEO_CAVS 0x02620000
#define BUF_VIDEO_VP6F 0x02630000
+/*@}*/
-/* audio buffer types: (please keep in sync with buffer_types.c) */
-
+/**
+ * @defgroup buffer_audio Audio buffer types
+ * @note (please keep in sync with buffer_types.c)
+ */
+/*@{*/
#define BUF_AUDIO_BASE 0x03000000
-#define BUF_AUDIO_UNKNOWN 0x03ff0000 /* no decoder should handle this one */
+#define BUF_AUDIO_UNKNOWN 0x03ff0000 /**< no decoder should handle this one */
#define BUF_AUDIO_A52 0x03000000
#define BUF_AUDIO_MPEG 0x03010000
#define BUF_AUDIO_LPCM_BE 0x03020000
@@ -258,9 +269,12 @@ extern "C" {
#define BUF_AUDIO_SMACKER 0x033B0000
#define BUF_AUDIO_FLVADPCM 0x033C0000
#define BUF_AUDIO_WAVPACK 0x033D0000
+/*@}*/
-/* spu buffer types: */
-
+/**
+ * @defgroup buffer_spu SPU buffer types
+ */
+/*@{*/
#define BUF_SPU_BASE 0x04000000
#define BUF_SPU_DVD 0x04000000
#define BUF_SPU_TEXT 0x04010000
@@ -270,33 +284,41 @@ extern "C" {
#define BUF_SPU_CVD 0x04050000
#define BUF_SPU_OGM 0x04060000
#define BUF_SPU_CMML 0x04070000
+/*@}*/
-/* demuxer block types: */
-
+/**
+ * @defgroup buffer_demux Demuxer block types
+ */
+/*@{*/
#define BUF_DEMUX_BLOCK 0x05000000
+/*@}*/
+
+/*@}*/
typedef struct extra_info_s extra_info_t;
-/*
- * extra_info_t is used to pass information from input or demuxer plugins
- * to output frames (past decoder). new data must be added after the existing
- * fields for backward compatibility.
+/**
+ * @brief Structure to pass information from input or demuxer plugins
+ * to output frames (past decoder).
+ *
+ * New data must be added after the existing fields to not break ABI
+ * (backward compatibility).
*/
struct extra_info_s {
- int input_normpos; /* remember where this buf came from in
- * the input source (0..65535). can be
- * either time or offset based. */
- int input_time; /* time offset in miliseconds from
- * beginning of stream */
- uint32_t frame_number; /* number of current frame if known */
+ int input_normpos; /**< remember where this buf came from in
+ * the input source (0..65535). can be
+ * either time or offset based. */
+ int input_time; /**< time offset in miliseconds from
+ * beginning of stream */
+ uint32_t frame_number; /**< number of current frame if known */
- int seek_count; /* internal engine use */
- int64_t vpts; /* set on output layers only */
+ int seek_count; /**< internal engine use */
+ int64_t vpts; /**< set on output layers only */
- int invalid; /* do not use this extra info to update anything */
- int total_time; /* duration in miliseconds of the stream */
+ int invalid; /**< do not use this extra info to update anything */
+ int total_time; /**< duration in miliseconds of the stream */
};
@@ -307,74 +329,75 @@ struct buf_element_s {
buf_element_t *next;
unsigned char *mem;
- unsigned char *content; /* start of raw content in mem (without header etc) */
+ unsigned char *content; /**< start of raw content in mem (without header etc) */
- int32_t size ; /* size of _content_ */
- int32_t max_size; /* size of pre-allocated memory pointed to by "mem" */
- uint32_t type;
- int64_t pts; /* presentation time stamp, used for a/v sync */
- int64_t disc_off; /* discontinuity offset */
+ int32_t size ; /**< size of _content_ */
+ int32_t max_size; /**< size of pre-allocated memory pointed to by "mem" */
+ int64_t pts; /**< presentation time stamp, used for a/v sync */
+ int64_t disc_off; /**< discontinuity offset */
- extra_info_t *extra_info; /* extra info will be passed to frames */
+ extra_info_t *extra_info; /**< extra info will be passed to frames */
- uint32_t decoder_flags; /* stuff like keyframe, is_header ... see below */
+ uint32_t decoder_flags; /**< stuff like keyframe, is_header ... see below */
- /* additional decoder flags and other dec-spec. stuff */
+ /** additional decoder flags and other dec-spec. stuff */
uint32_t decoder_info[BUF_NUM_DEC_INFO];
- /* pointers to dec-spec. stuff */
+ /** pointers to dec-spec. stuff */
void *decoder_info_ptr[BUF_NUM_DEC_INFO];
void (*free_buffer) (buf_element_t *buf);
- void *source; /* pointer to source of this buffer for */
- /* free_buffer */
+ void *source; /**< pointer to source of this buffer for
+ * free_buffer */
+ uint32_t type;
} ;
-/* keyframe should be set whenever possible (that is, when demuxer
+/** keyframe should be set whenever possible (that is, when demuxer
* knows about frames and keyframes). */
#define BUF_FLAG_KEYFRAME 0x0001
-/* frame start/end. BUF_FLAG_FRAME_END is sent on last buf of a frame */
+/** frame start/end. BUF_FLAG_FRAME_END is sent on last buf of a frame */
#define BUF_FLAG_FRAME_START 0x0002
#define BUF_FLAG_FRAME_END 0x0004
-/* any out-of-band data needed to initialize decoder must have
+/** any out-of-band data needed to initialize decoder must have
* this flag set. */
#define BUF_FLAG_HEADER 0x0008
-/* preview buffers are normal data buffers that must not produce any
+/** preview buffers are normal data buffers that must not produce any
* output in decoders (may be used to sneak details about the stream
* to come). */
#define BUF_FLAG_PREVIEW 0x0010
-/* set when user stop the playback */
+/** set when user stop the playback */
#define BUF_FLAG_END_USER 0x0020
-/* set when stream finished naturaly */
+/** set when stream finished naturaly */
#define BUF_FLAG_END_STREAM 0x0040
-/* decoder_info[0] carries the frame step (1/90000). */
+/** decoder_info[0] carries the frame step (1/90000). */
#define BUF_FLAG_FRAMERATE 0x0080
-/* hint to metronom that seeking has occurred */
+/** hint to metronom that seeking has occurred */
#define BUF_FLAG_SEEK 0x0100
-/* special information inside, see below. */
+/** special information inside, see below. */
#define BUF_FLAG_SPECIAL 0x0200
-/* header use standard xine_bmiheader or xine_waveformatex structs.
+/** header use standard xine_bmiheader or xine_waveformatex structs.
* xine_waveformatex is actually optional since the most important
* information for audio init is available from decoder_info[].
* note: BUF_FLAG_HEADER must also be set. */
#define BUF_FLAG_STDHEADER 0x0400
-/* decoder_info[1] carries numerator for display aspect ratio
+/** decoder_info[1] carries numerator for display aspect ratio
* decoder_info[2] carries denominator for display aspect ratio */
#define BUF_FLAG_ASPECT 0x0800
-/* Special buffer types:
+/**
+ * \defgroup buffer_special Special buffer types:
* Sometimes there is a need to relay special information from a demuxer
* to a video decoder. For example, some file types store palette data in
* the file header independant of the video data. The special buffer type
@@ -393,10 +416,9 @@ struct buf_element_s {
* buffer will fall through to the case where the buffer's data content
* is accumulated and no harm will be done.
*/
+/*@{*/
-/* these are the types of special buffers */
-
-/*
+/**
* In a BUF_SPECIAL_PALETTE buffer:
* decoder_info[1] = BUF_SPECIAL_PALETTE
* decoder_info[2] = number of entries in palette table
@@ -414,7 +436,7 @@ struct buf_element_s {
/* special buffer type 2 used to be defined but is now available for use */
-/*
+/**
* In a BUF_SPECIAL_ASPECT buffer:
* decoder_info[1] = BUF_SPECIAL_ASPECT
* decoder_info[2] = MPEG2 aspect ratio code
@@ -427,7 +449,7 @@ struct buf_element_s {
*/
#define BUF_SPECIAL_ASPECT 3
-/*
+/**
* In a BUF_SPECIAL_DECODER_CONFIG buffer:
* decoder_info[1] = BUF_SPECIAL_DECODER_CONFIG
* decoder_info[2] = data size
@@ -437,7 +459,7 @@ struct buf_element_s {
*/
#define BUF_SPECIAL_DECODER_CONFIG 4
-/*
+/**
* In a BUF_SPECIAL_STSD_ATOM buffer:
* decoder_info[1] = BUF_SPECIAL_STSD_ATOM
* decoder_info[2] = size of the ImageDescription atom, minus the
@@ -451,7 +473,7 @@ struct buf_element_s {
*/
#define BUF_SPECIAL_STSD_ATOM 5
-/*
+/**
* In a BUF_SPECIAL_LPCM_CONFIG buffer:
* decoder_info[1] = BUF_SPECIAL_LPCM_CONFIG
* decoder_info[2] = config data
@@ -461,7 +483,7 @@ struct buf_element_s {
*/
#define BUF_SPECIAL_LPCM_CONFIG 6
-/*
+/**
* In a BUF_SPECIAL_CHARSET_ENCODING buffer:
* decoder_info[1] = BUF_SPECIAL_CHARSET_ENCODING
* decoder_info[2] = size of charset encoding string
@@ -473,7 +495,7 @@ struct buf_element_s {
#define BUF_SPECIAL_CHARSET_ENCODING 7
-/*
+/**
* In a BUF_SPECIAL_SPU_DVD_SUBTYPE:
* decoder_info[1] = BUF_SPECIAL_SPU_DVD_SUBTYPE
* decoder_info[2] = subtype
@@ -488,7 +510,8 @@ struct buf_element_s {
#define SPU_DVD_SUBTYPE_VOBSUB_PACKAGE 3
#define SPU_DVD_SUBTYPE_NAV 4
-/* In a BUF_SPECIAL_SPU_DVB_DESCRIPTOR
+/**
+ * In a BUF_SPECIAL_SPU_DVB_DESCRIPTOR
* decoder_info[1] = BUF_SPECIAL_SPU_DVB_DESCRIPTOR
* decoder_info[2] = size of spu_dvb_descriptor_t
* decoder_info_ptr[2] = pointer to spu_dvb_descriptor_t, or NULL
@@ -500,7 +523,7 @@ struct buf_element_s {
**/
#define BUF_SPECIAL_SPU_DVB_DESCRIPTOR 9
-/*
+/**
* In a BUF_SPECIAL_RV_CHUNK_TABLE:
* decoder_info[1] = BUF_SPECIAL_RV_CHUNK_TABLE
* decoder_info[2] = number of entries in chunk table
@@ -509,6 +532,7 @@ struct buf_element_s {
* This buffer transports the chunk table associated to each RealVideo frame.
*/
#define BUF_SPECIAL_RV_CHUNK_TABLE 10
+/*@}*/
typedef struct spu_dvb_descriptor_s spu_dvb_descriptor_t;
struct spu_dvb_descriptor_s
@@ -600,42 +624,61 @@ struct fifo_buffer_s
void *get_cb_data[BUF_MAX_CALLBACKS];
} ;
-/*
- * allocate and initialize new (empty) fifo buffer,
- * init buffer pool for it:
- * allocate num_buffers of buf_size bytes each
+/**
+ * @brief Allocate and initialise new (empty) FIFO buffers.
+ * @param num_buffer Number of buffers to allocate.
+ * @param buf_size Size of each buffer.
+ * @internal Only used by video and audio decoder loops.
*/
+fifo_buffer_t *_x_fifo_buffer_new (int num_buffers, uint32_t buf_size);
-fifo_buffer_t *_x_fifo_buffer_new (int num_buffers, uint32_t buf_size) XINE_PROTECTED;
-fifo_buffer_t *_x_dummy_fifo_buffer_new (int num_buffers, uint32_t buf_size) XINE_PROTECTED;
+/**
+ * @brief Allocate and initialise new dummy FIFO buffers.
+ * @param num_buffer Number of dummy buffers to allocate.
+ * @param buf_size Size of each buffer.
+ * @internal Only used by video and audio decoder loops.
+ */
+fifo_buffer_t *_x_dummy_fifo_buffer_new (int num_buffers, uint32_t buf_size);
-/* return BUF_VIDEO_xxx given the fourcc
- * fourcc_int must be read in machine endianness
+/**
+ * @brief Returns the \ref buffer_video "BUF_VIDEO_xxx" for the given fourcc.
+ * @param fourcc_int 32-bit FOURCC value in machine endianness
+ * @sa _x_formattag_to_buf_audio
+ *
* example: fourcc_int = *(uint32_t *)fourcc_char;
*/
uint32_t _x_fourcc_to_buf_video( uint32_t fourcc_int ) XINE_PROTECTED;
-/* return codec name given BUF_VIDEO_xxx */
-char * _x_buf_video_name( uint32_t buf_type ) XINE_PROTECTED;
+/**
+ * @brief Returns video codec name given the buffer type.
+ * @param buf_type One of the \ref buffer_video "BUF_VIDEO_xxx" values.
+ * @sa _x_buf_audio_name
+ */
+const char *_x_buf_video_name( uint32_t buf_type ) XINE_PROTECTED;
-/* return BUF_AUDIO_xxx given the formattag */
+/**
+ * @brief Returns the \ref buffer_audio "BUF_AUDIO_xxx" for the given formattag.
+ * @param formattagg 32-bit format tag value in machine endianness
+ * @sa _x_fourcc_to_buf_video
+ */
uint32_t _x_formattag_to_buf_audio( uint32_t formattag ) XINE_PROTECTED;
-/* return codec name given BUF_AUDIO_xxx */
-char * _x_buf_audio_name( uint32_t buf_type ) XINE_PROTECTED;
+/**
+ * @brief Returns audio codec name given the buffer type.
+ * @param buf_type One of the \ref buffer_audio "BUF_AUDIO_xxx" values.
+ * @sa _x_buf_video_name
+ */
+const char *_x_buf_audio_name( uint32_t buf_type ) XINE_PROTECTED;
-#ifndef ATTRIBUTE_PACKED
-/* no attribute packed? let's try with pragma pack as a last resort */
-#pragma pack(2)
-#endif
-/* this is xine version of BITMAPINFOHEADER
- * - should be safe to compile on 64bits machines
- * - will always use machine endian format, so demuxers reading
- * stuff from win32 formats must use the function below.
+/**
+ * @brief xine version of BITMAPINFOHEADER.
+ * @note Should be safe to compile on 64bits machines.
+ * @note Will always use machine endian format, so demuxers reading
+ * stuff from win32 formats must use the function below.
*/
-typedef struct __attribute__((__packed__)) {
+typedef struct XINE_PACKED {
int32_t biSize;
int32_t biWidth;
int32_t biHeight;
@@ -649,10 +692,11 @@ typedef struct __attribute__((__packed__)) {
int32_t biClrImportant;
} xine_bmiheader;
-/* this is xine version of WAVEFORMATEX
- * (the same comments from xine_bmiheader)
+/**
+ * @brief xine version of WAVEFORMATEX.
+ * @note The same comments from xine_bmiheader applies.
*/
-typedef struct __attribute__((__packed__)) {
+typedef struct XINE_PACKED {
int16_t wFormatTag;
int16_t nChannels;
int32_t nSamplesPerSec;
@@ -661,14 +705,11 @@ typedef struct __attribute__((__packed__)) {
int16_t wBitsPerSample;
int16_t cbSize;
} xine_waveformatex;
-#ifndef ATTRIBUTE_PACKED
-#pragma pack()
-#endif
-/* convert xine_bmiheader struct from little endian */
+/** Convert xine_bmiheader struct from little endian */
void _x_bmiheader_le2me( xine_bmiheader *bih ) XINE_PROTECTED;
-/* convert xine_waveformatex struct from little endian */
+/** Convert xine_waveformatex struct from little endian */
void _x_waveformatex_le2me( xine_waveformatex *wavex ) XINE_PROTECTED;
#ifdef __cplusplus
diff --git a/src/xine-engine/buffer_types.c b/src/xine-engine/buffer_types.c
index 619a34c4c..f686f61a1 100644
--- a/src/xine-engine/buffer_types.c
+++ b/src/xine-engine/buffer_types.c
@@ -38,14 +38,6 @@
#include "buffer.h"
#include "bswap.h"
-/* FOURCC will be manipulated using machine endian */
-#ifdef WORDS_BIGENDIAN
-#define meFOURCC BE_FOURCC
-#else
-#define meFOURCC LE_FOURCC
-#endif
-
-
typedef struct video_db_s {
uint32_t fourcc[20];
uint32_t buf_type;
@@ -62,11 +54,11 @@ typedef struct audio_db_s {
static const video_db_t video_db[] = {
{
{
- meFOURCC('m', 'p', 'e', 'g'),
- meFOURCC('M', 'P', 'E', 'G'),
- meFOURCC('P', 'I', 'M', '1'),
- meFOURCC('m', 'p', 'g', '2'),
- meFOURCC('m', 'p', 'g', '1'),
+ ME_FOURCC('m', 'p', 'e', 'g'),
+ ME_FOURCC('M', 'P', 'E', 'G'),
+ ME_FOURCC('P', 'I', 'M', '1'),
+ ME_FOURCC('m', 'p', 'g', '2'),
+ ME_FOURCC('m', 'p', 'g', '1'),
0
},
BUF_VIDEO_MPEG,
@@ -74,15 +66,15 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('D', 'I', 'V', 'X'),
- meFOURCC('d', 'i', 'v', 'x'),
- meFOURCC('D', 'i', 'v', 'x'),
- meFOURCC('D', 'i', 'v', 'X'),
- meFOURCC('M', 'P', '4', 'S'),
- meFOURCC('m', 'p', '4', 'v'),
- meFOURCC('M', '4', 'S', '2'),
- meFOURCC('m', '4', 's', '2'),
- meFOURCC('F', 'M', 'P', '4'),
+ ME_FOURCC('D', 'I', 'V', 'X'),
+ ME_FOURCC('d', 'i', 'v', 'x'),
+ ME_FOURCC('D', 'i', 'v', 'x'),
+ ME_FOURCC('D', 'i', 'v', 'X'),
+ ME_FOURCC('M', 'P', '4', 'S'),
+ ME_FOURCC('m', 'p', '4', 'v'),
+ ME_FOURCC('M', '4', 'S', '2'),
+ ME_FOURCC('m', '4', 's', '2'),
+ ME_FOURCC('F', 'M', 'P', '4'),
0
},
BUF_VIDEO_MPEG4,
@@ -90,8 +82,8 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('X', 'V', 'I', 'D'),
- meFOURCC('x', 'v', 'i', 'd'),
+ ME_FOURCC('X', 'V', 'I', 'D'),
+ ME_FOURCC('x', 'v', 'i', 'd'),
0
},
BUF_VIDEO_XVID,
@@ -99,7 +91,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('D', 'X', '5', '0'),
+ ME_FOURCC('D', 'X', '5', '0'),
0
},
BUF_VIDEO_DIVX5,
@@ -107,7 +99,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('c', 'v', 'i', 'd'),
+ ME_FOURCC('c', 'v', 'i', 'd'),
0
},
BUF_VIDEO_CINEPAK,
@@ -115,9 +107,9 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('S', 'V', 'Q', '1'),
- meFOURCC('s', 'v', 'q', '1'),
- meFOURCC('s', 'v', 'q', 'i'),
+ ME_FOURCC('S', 'V', 'Q', '1'),
+ ME_FOURCC('s', 'v', 'q', '1'),
+ ME_FOURCC('s', 'v', 'q', 'i'),
0
},
BUF_VIDEO_SORENSON_V1,
@@ -125,8 +117,8 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('S', 'V', 'Q', '3'),
- meFOURCC('s', 'v', 'q', '3'),
+ ME_FOURCC('S', 'V', 'Q', '3'),
+ ME_FOURCC('s', 'v', 'q', '3'),
0
},
BUF_VIDEO_SORENSON_V3,
@@ -134,10 +126,10 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('M', 'P', '4', '1'),
- meFOURCC('m', 'p', '4', '1'),
- meFOURCC('M', 'P', 'G', '4'),
- meFOURCC('m', 'p', 'g', '4'),
+ ME_FOURCC('M', 'P', '4', '1'),
+ ME_FOURCC('m', 'p', '4', '1'),
+ ME_FOURCC('M', 'P', 'G', '4'),
+ ME_FOURCC('m', 'p', 'g', '4'),
0
},
BUF_VIDEO_MSMPEG4_V1,
@@ -145,12 +137,12 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('M', 'P', '4', '1'),
- meFOURCC('m', 'p', '4', '1'),
- meFOURCC('M', 'P', '4', '2'),
- meFOURCC('m', 'p', '4', '2'),
- meFOURCC('D', 'I', 'V', '2'),
- meFOURCC('d', 'i', 'v', '2'),
+ ME_FOURCC('M', 'P', '4', '1'),
+ ME_FOURCC('m', 'p', '4', '1'),
+ ME_FOURCC('M', 'P', '4', '2'),
+ ME_FOURCC('m', 'p', '4', '2'),
+ ME_FOURCC('D', 'I', 'V', '2'),
+ ME_FOURCC('d', 'i', 'v', '2'),
0
},
BUF_VIDEO_MSMPEG4_V2,
@@ -158,20 +150,20 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('M', 'P', '4', '3'),
- meFOURCC('m', 'p', '4', '3'),
- meFOURCC('D', 'I', 'V', '3'),
- meFOURCC('d', 'i', 'v', '3'),
- meFOURCC('D', 'I', 'V', '4'),
- meFOURCC('d', 'i', 'v', '4'),
- meFOURCC('D', 'I', 'V', '5'),
- meFOURCC('d', 'i', 'v', '5'),
- meFOURCC('D', 'I', 'V', '6'),
- meFOURCC('d', 'i', 'v', '6'),
- meFOURCC('A', 'P', '4', '1'),
- meFOURCC('M', 'P', 'G', '3'),
- meFOURCC('C', 'O', 'L', '1'),
- meFOURCC('3', 'I', 'V', 'D'),
+ ME_FOURCC('M', 'P', '4', '3'),
+ ME_FOURCC('m', 'p', '4', '3'),
+ ME_FOURCC('D', 'I', 'V', '3'),
+ ME_FOURCC('d', 'i', 'v', '3'),
+ ME_FOURCC('D', 'I', 'V', '4'),
+ ME_FOURCC('d', 'i', 'v', '4'),
+ ME_FOURCC('D', 'I', 'V', '5'),
+ ME_FOURCC('d', 'i', 'v', '5'),
+ ME_FOURCC('D', 'I', 'V', '6'),
+ ME_FOURCC('d', 'i', 'v', '6'),
+ ME_FOURCC('A', 'P', '4', '1'),
+ ME_FOURCC('M', 'P', 'G', '3'),
+ ME_FOURCC('C', 'O', 'L', '1'),
+ ME_FOURCC('3', 'I', 'V', 'D'),
0
},
BUF_VIDEO_MSMPEG4_V3,
@@ -179,8 +171,8 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('3', 'I', 'V', '1'),
- meFOURCC('3', 'I', 'V', '2'),
+ ME_FOURCC('3', 'I', 'V', '1'),
+ ME_FOURCC('3', 'I', 'V', '2'),
0
},
BUF_VIDEO_3IVX,
@@ -188,11 +180,11 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('d', 'm', 'b', '1'),
- meFOURCC('M', 'J', 'P', 'G'),
- meFOURCC('m', 'j', 'p', 'a'),
- meFOURCC('A', 'V', 'R', 'n'),
- meFOURCC('A', 'V', 'D', 'J'),
+ ME_FOURCC('d', 'm', 'b', '1'),
+ ME_FOURCC('M', 'J', 'P', 'G'),
+ ME_FOURCC('m', 'j', 'p', 'a'),
+ ME_FOURCC('A', 'V', 'R', 'n'),
+ ME_FOURCC('A', 'V', 'D', 'J'),
0
},
BUF_VIDEO_MJPEG,
@@ -200,7 +192,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('m', 'j', 'p', 'b'),
+ ME_FOURCC('m', 'j', 'p', 'b'),
0
},
BUF_VIDEO_MJPEG_B,
@@ -208,8 +200,8 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('I', 'V', '5', '0'),
- meFOURCC('i', 'v', '5', '0'),
+ ME_FOURCC('I', 'V', '5', '0'),
+ ME_FOURCC('i', 'v', '5', '0'),
0
},
BUF_VIDEO_IV50,
@@ -217,8 +209,8 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('I', 'V', '4', '1'),
- meFOURCC('i', 'v', '4', '1'),
+ ME_FOURCC('I', 'V', '4', '1'),
+ ME_FOURCC('i', 'v', '4', '1'),
0
},
BUF_VIDEO_IV41,
@@ -226,8 +218,8 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('I', 'V', '3', '2'),
- meFOURCC('i', 'v', '3', '2'),
+ ME_FOURCC('I', 'V', '3', '2'),
+ ME_FOURCC('i', 'v', '3', '2'),
0
},
BUF_VIDEO_IV32,
@@ -235,8 +227,8 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('I', 'V', '3', '1'),
- meFOURCC('i', 'v', '3', '1'),
+ ME_FOURCC('I', 'V', '3', '1'),
+ ME_FOURCC('i', 'v', '3', '1'),
0
},
BUF_VIDEO_IV31,
@@ -244,7 +236,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('V', 'C', 'R', '1'),
+ ME_FOURCC('V', 'C', 'R', '1'),
0
},
BUF_VIDEO_ATIVCR1,
@@ -252,7 +244,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('V', 'C', 'R', '2'),
+ ME_FOURCC('V', 'C', 'R', '2'),
0
},
BUF_VIDEO_ATIVCR2,
@@ -260,11 +252,11 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('I', '2', '6', '3'),
- meFOURCC('i', '2', '6', '3'),
- meFOURCC('V', 'I', 'V', 'O'),
- meFOURCC('v', 'i', 'v', 'o'),
- meFOURCC('v', 'i', 'v', '1'),
+ ME_FOURCC('I', '2', '6', '3'),
+ ME_FOURCC('i', '2', '6', '3'),
+ ME_FOURCC('V', 'I', 'V', 'O'),
+ ME_FOURCC('v', 'i', 'v', 'o'),
+ ME_FOURCC('v', 'i', 'v', '1'),
0
},
BUF_VIDEO_I263,
@@ -272,8 +264,8 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('D','I','B',' '), /* device-independent bitmap */
- meFOURCC('r','a','w',' '),
+ ME_FOURCC('D','I','B',' '), /* device-independent bitmap */
+ ME_FOURCC('r','a','w',' '),
0
},
BUF_VIDEO_RGB,
@@ -285,8 +277,8 @@ static const video_db_t video_db[] = {
else if (!strncasecmp (video, "yuv2", 4))
this->video_type = BUF_VIDEO_YUY2;
*/
- meFOURCC('y', 'u', 'v', '2'),
- meFOURCC('Y', 'U', 'Y', '2'),
+ ME_FOURCC('y', 'u', 'v', '2'),
+ ME_FOURCC('Y', 'U', 'Y', '2'),
0
},
BUF_VIDEO_YUY2,
@@ -294,8 +286,8 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('j','p','e','g'),
- meFOURCC('J','F','I','F'),
+ ME_FOURCC('j','p','e','g'),
+ ME_FOURCC('J','F','I','F'),
0
},
BUF_VIDEO_JPEG,
@@ -303,7 +295,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('W','M','V','1'),
+ ME_FOURCC('W','M','V','1'),
0
},
BUF_VIDEO_WMV7,
@@ -311,7 +303,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('W','M','V','2'),
+ ME_FOURCC('W','M','V','2'),
0
},
BUF_VIDEO_WMV8,
@@ -319,8 +311,8 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('W','M','V','3'),
- meFOURCC('W','M','V','P'),
+ ME_FOURCC('W','M','V','3'),
+ ME_FOURCC('W','M','V','P'),
0
},
BUF_VIDEO_WMV9,
@@ -328,12 +320,12 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('c','r','a','m'),
- meFOURCC('C','R','A','M'),
- meFOURCC('M','S','V','C'),
- meFOURCC('m','s','v','c'),
- meFOURCC('W','H','A','M'),
- meFOURCC('w','h','a','m'),
+ ME_FOURCC('c','r','a','m'),
+ ME_FOURCC('C','R','A','M'),
+ ME_FOURCC('M','S','V','C'),
+ ME_FOURCC('m','s','v','c'),
+ ME_FOURCC('W','H','A','M'),
+ ME_FOURCC('w','h','a','m'),
0
},
BUF_VIDEO_MSVC,
@@ -341,9 +333,9 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('D','V','S','D'),
- meFOURCC('d','v','s','d'),
- meFOURCC('d','v','c','p'),
+ ME_FOURCC('D','V','S','D'),
+ ME_FOURCC('d','v','s','d'),
+ ME_FOURCC('d','v','c','p'),
0
},
BUF_VIDEO_DV,
@@ -351,11 +343,11 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('V','P','3',' '),
- meFOURCC('V','P','3','0'),
- meFOURCC('v','p','3','0'),
- meFOURCC('V','P','3','1'),
- meFOURCC('v','p','3','1'),
+ ME_FOURCC('V','P','3',' '),
+ ME_FOURCC('V','P','3','0'),
+ ME_FOURCC('v','p','3','0'),
+ ME_FOURCC('V','P','3','1'),
+ ME_FOURCC('v','p','3','1'),
0
},
BUF_VIDEO_VP31,
@@ -363,7 +355,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('V','P','4','0'),
+ ME_FOURCC('V','P','4','0'),
0,
},
BUF_VIDEO_VP4,
@@ -371,10 +363,10 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('H', '2', '6', '3'),
- meFOURCC('h', '2', '6', '3'),
- meFOURCC('U', '2', '6', '3'),
- meFOURCC('s', '2', '6', '3'),
+ ME_FOURCC('H', '2', '6', '3'),
+ ME_FOURCC('h', '2', '6', '3'),
+ ME_FOURCC('U', '2', '6', '3'),
+ ME_FOURCC('s', '2', '6', '3'),
0
},
BUF_VIDEO_H263,
@@ -382,8 +374,8 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('c', 'y', 'u', 'v'),
- meFOURCC('C', 'Y', 'U', 'V'),
+ ME_FOURCC('c', 'y', 'u', 'v'),
+ ME_FOURCC('C', 'Y', 'U', 'V'),
0
},
BUF_VIDEO_CYUV,
@@ -391,7 +383,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('s', 'm', 'c', ' '),
+ ME_FOURCC('s', 'm', 'c', ' '),
0
},
BUF_VIDEO_SMC,
@@ -399,8 +391,8 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('r', 'p', 'z', 'a'),
- meFOURCC('a', 'z', 'p', 'r'),
+ ME_FOURCC('r', 'p', 'z', 'a'),
+ ME_FOURCC('a', 'z', 'p', 'r'),
0
},
BUF_VIDEO_RPZA,
@@ -408,7 +400,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('r', 'l', 'e', ' '),
+ ME_FOURCC('r', 'l', 'e', ' '),
0
},
BUF_VIDEO_QTRLE,
@@ -423,7 +415,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('D', 'U', 'C', 'K'),
+ ME_FOURCC('D', 'U', 'C', 'K'),
0
},
BUF_VIDEO_DUCKTM1,
@@ -431,7 +423,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('M', 'S', 'S', '1'),
+ ME_FOURCC('M', 'S', 'S', '1'),
0
},
BUF_VIDEO_MSS1,
@@ -439,7 +431,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('P', 'G', 'V', 'V'),
+ ME_FOURCC('P', 'G', 'V', 'V'),
0
},
BUF_VIDEO_PGVV,
@@ -447,7 +439,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('Z', 'y', 'G', 'o'),
+ ME_FOURCC('Z', 'y', 'G', 'o'),
0
},
BUF_VIDEO_ZYGO,
@@ -455,7 +447,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('t', 's', 'c', 'c'),
+ ME_FOURCC('t', 's', 'c', 'c'),
0
},
BUF_VIDEO_TSCC,
@@ -463,7 +455,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('Y', 'V', 'U', '9'),
+ ME_FOURCC('Y', 'V', 'U', '9'),
0
},
BUF_VIDEO_YVU9,
@@ -471,7 +463,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('G', 'R', 'E', 'Y'),
+ ME_FOURCC('G', 'R', 'E', 'Y'),
0
},
BUF_VIDEO_GREY,
@@ -479,9 +471,9 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('X', 'x', 'a', 'n'),
- meFOURCC('X', 'X', 'A', 'N'),
- meFOURCC('x', 'x', 'a', 'n'),
+ ME_FOURCC('X', 'x', 'a', 'n'),
+ ME_FOURCC('X', 'X', 'A', 'N'),
+ ME_FOURCC('x', 'x', 'a', 'n'),
0
},
BUF_VIDEO_XXAN,
@@ -489,8 +481,8 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('Y', 'V', '1', '2'),
- meFOURCC('y', 'v', '1', '2'),
+ ME_FOURCC('Y', 'V', '1', '2'),
+ ME_FOURCC('y', 'v', '1', '2'),
0
},
BUF_VIDEO_YV12,
@@ -498,8 +490,8 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('I', '4', '2', '0'),
- meFOURCC('I', 'Y', 'U', 'V'),
+ ME_FOURCC('I', '4', '2', '0'),
+ ME_FOURCC('I', 'Y', 'U', 'V'),
0
},
BUF_VIDEO_I420,
@@ -507,8 +499,8 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('S', 'E', 'G', 'A'),
- meFOURCC('s', 'e', 'g', 'a'),
+ ME_FOURCC('S', 'E', 'G', 'A'),
+ ME_FOURCC('s', 'e', 'g', 'a'),
0
},
BUF_VIDEO_SEGA,
@@ -516,8 +508,8 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('m', 'v', 'i', '2'),
- meFOURCC('M', 'V', 'I', '2'),
+ ME_FOURCC('m', 'v', 'i', '2'),
+ ME_FOURCC('M', 'V', 'I', '2'),
0
},
BUF_VIDEO_MVI2,
@@ -525,8 +517,8 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('u', 'c', 'o', 'd'),
- meFOURCC('U', 'C', 'O', 'D'),
+ ME_FOURCC('u', 'c', 'o', 'd'),
+ ME_FOURCC('U', 'C', 'O', 'D'),
0
},
BUF_VIDEO_UCOD,
@@ -534,7 +526,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('R', 'V', '1', '0'),
+ ME_FOURCC('R', 'V', '1', '0'),
0
},
BUF_VIDEO_RV10,
@@ -542,7 +534,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('R', 'V', '2', '0'),
+ ME_FOURCC('R', 'V', '2', '0'),
0
},
BUF_VIDEO_RV20,
@@ -550,7 +542,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('R', 'V', '3', '0'),
+ ME_FOURCC('R', 'V', '3', '0'),
0
},
BUF_VIDEO_RV30,
@@ -558,7 +550,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('R', 'V', '4', '0'),
+ ME_FOURCC('R', 'V', '4', '0'),
0
},
BUF_VIDEO_RV40,
@@ -566,7 +558,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('H', 'F', 'Y', 'U'),
+ ME_FOURCC('H', 'F', 'Y', 'U'),
0,
},
BUF_VIDEO_HUFFYUV,
@@ -574,8 +566,8 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('I', 'M', 'G', ' '),
- meFOURCC('g', 'i', 'f', ' '),
+ ME_FOURCC('I', 'M', 'G', ' '),
+ ME_FOURCC('g', 'i', 'f', ' '),
0,
},
BUF_VIDEO_IMAGE,
@@ -590,7 +582,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('V','P','5','0'),
+ ME_FOURCC('V','P','5','0'),
0
},
BUF_VIDEO_VP5,
@@ -598,9 +590,9 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('V','P','6','0'),
- meFOURCC('V','P','6','1'),
- meFOURCC('V','P','6','2'),
+ ME_FOURCC('V','P','6','0'),
+ ME_FOURCC('V','P','6','1'),
+ ME_FOURCC('V','P','6','2'),
0
},
BUF_VIDEO_VP6,
@@ -608,7 +600,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('8','B', 'P','S'),
+ ME_FOURCC('8','B', 'P','S'),
0
},
BUF_VIDEO_8BPS,
@@ -616,7 +608,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('Z','L','I','B'),
+ ME_FOURCC('Z','L','I','B'),
0
},
BUF_VIDEO_ZLIB,
@@ -624,7 +616,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('M','S','Z','H'),
+ ME_FOURCC('M','S','Z','H'),
0
},
BUF_VIDEO_MSZH,
@@ -632,7 +624,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('A','S','V','1'),
+ ME_FOURCC('A','S','V','1'),
0
},
BUF_VIDEO_ASV1,
@@ -640,7 +632,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('A','S','V','2'),
+ ME_FOURCC('A','S','V','2'),
0
},
BUF_VIDEO_ASV2,
@@ -648,9 +640,9 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('a','v','c','1'),
- meFOURCC('h','2','6','4'),
- meFOURCC('H','2','6','4'),
+ ME_FOURCC('a','v','c','1'),
+ ME_FOURCC('h','2','6','4'),
+ ME_FOURCC('H','2','6','4'),
0
},
BUF_VIDEO_H264,
@@ -658,7 +650,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('A','A','S','C'),
+ ME_FOURCC('A','A','S','C'),
0
},
BUF_VIDEO_AASC,
@@ -666,7 +658,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('q','d','r','w'),
+ ME_FOURCC('q','d','r','w'),
0
},
BUF_VIDEO_QDRW,
@@ -674,7 +666,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('L','O','C','O'),
+ ME_FOURCC('L','O','C','O'),
0
},
BUF_VIDEO_LOCO,
@@ -682,7 +674,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('U','L','T','I'),
+ ME_FOURCC('U','L','T','I'),
0
},
BUF_VIDEO_ULTI,
@@ -690,7 +682,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('W','N','V','1'),
+ ME_FOURCC('W','N','V','1'),
0
},
BUF_VIDEO_WNV1,
@@ -698,8 +690,8 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('P','I','X','L'),
- meFOURCC('X','I','X','L'),
+ ME_FOURCC('P','I','X','L'),
+ ME_FOURCC('X','I','X','L'),
0
},
BUF_VIDEO_XL,
@@ -707,9 +699,9 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('Q','P','E','G'),
- meFOURCC('Q','1','.','0'),
- meFOURCC('Q','1','.','1'),
+ ME_FOURCC('Q','P','E','G'),
+ ME_FOURCC('Q','1','.','0'),
+ ME_FOURCC('Q','1','.','1'),
0
},
BUF_VIDEO_QPEG,
@@ -717,7 +709,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('R','T','2','1'),
+ ME_FOURCC('R','T','2','1'),
0
},
BUF_VIDEO_RT21,
@@ -725,7 +717,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('F','P','S','1'),
+ ME_FOURCC('F','P','S','1'),
0
},
BUF_VIDEO_FPS1,
@@ -733,7 +725,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('T','M','2','0'),
+ ME_FOURCC('T','M','2','0'),
0
},
BUF_VIDEO_DUCKTM2,
@@ -741,7 +733,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('C','S','C','D'),
+ ME_FOURCC('C','S','C','D'),
0
},
BUF_VIDEO_CSCD,
@@ -749,7 +741,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('Z','M','B','V'),
+ ME_FOURCC('Z','M','B','V'),
0
},
BUF_VIDEO_ZMBV,
@@ -757,7 +749,7 @@ static const video_db_t video_db[] = {
},
{
{
- meFOURCC('K','M','V','C'),
+ ME_FOURCC('K','M','V','C'),
0
},
BUF_VIDEO_KMVC,
@@ -771,7 +763,7 @@ static const audio_db_t audio_db[] = {
{
{
0x2000,
- meFOURCC('m', 's', 0x20, 0x00),
+ ME_FOURCC('m', 's', 0x20, 0x00),
0
},
BUF_AUDIO_A52,
@@ -780,9 +772,9 @@ static const audio_db_t audio_db[] = {
{
{
0x50, 0x55,
- meFOURCC('.','m','p','3'),
- meFOURCC('m', 's', 0, 0x55),
- meFOURCC('M','P','3',' '),
+ ME_FOURCC('.','m','p','3'),
+ ME_FOURCC('m', 's', 0, 0x55),
+ ME_FOURCC('M','P','3',' '),
0
},
BUF_AUDIO_MPEG,
@@ -790,8 +782,8 @@ static const audio_db_t audio_db[] = {
},
{
{
- meFOURCC('t','w','o','s'),
- meFOURCC('i','n','2','4'),
+ ME_FOURCC('t','w','o','s'),
+ ME_FOURCC('i','n','2','4'),
0
},
BUF_AUDIO_LPCM_BE,
@@ -800,8 +792,8 @@ static const audio_db_t audio_db[] = {
{
{
0x01,
- meFOURCC('r','a','w',' '),
- meFOURCC('s','o','w','t'),
+ ME_FOURCC('r','a','w',' '),
+ ME_FOURCC('s','o','w','t'),
0
},
BUF_AUDIO_LPCM_LE,
@@ -852,7 +844,7 @@ static const audio_db_t audio_db[] = {
{
{
0x02,
- meFOURCC('m', 's', 0, 0x02),
+ ME_FOURCC('m', 's', 0, 0x02),
0
},
BUF_AUDIO_MSADPCM,
@@ -861,7 +853,7 @@ static const audio_db_t audio_db[] = {
{
{
0x11,
- meFOURCC('m', 's', 0, 0x11),
+ ME_FOURCC('m', 's', 0, 0x11),
0
},
BUF_AUDIO_MSIMAADPCM,
@@ -879,8 +871,8 @@ static const audio_db_t audio_db[] = {
/* these formattags are used by Vorbis ACM encoder and
supported by NanDub, a variant of VirtualDub. */
0x674f, 0x676f, 0x6750, 0x6770, 0x6751, 0x6771,
- meFOURCC('O','g','g','S'),
- meFOURCC('O','g','g','V'),
+ ME_FOURCC('O','g','g','S'),
+ ME_FOURCC('O','g','g','V'),
0
},
BUF_AUDIO_VORBIS,
@@ -937,7 +929,7 @@ static const audio_db_t audio_db[] = {
},
{
{
- meFOURCC('i', 'm', 'a', '4'),
+ ME_FOURCC('i', 'm', 'a', '4'),
0
},
BUF_AUDIO_QTIMAADPCM,
@@ -945,8 +937,8 @@ static const audio_db_t audio_db[] = {
},
{
{
- meFOURCC('m', 'a', 'c', '3'),
- meFOURCC('M', 'A', 'C', '3'),
+ ME_FOURCC('m', 'a', 'c', '3'),
+ ME_FOURCC('M', 'A', 'C', '3'),
0
},
BUF_AUDIO_MAC3,
@@ -954,8 +946,8 @@ static const audio_db_t audio_db[] = {
},
{
{
- meFOURCC('m', 'a', 'c', '6'),
- meFOURCC('M', 'A', 'C', '6'),
+ ME_FOURCC('m', 'a', 'c', '6'),
+ ME_FOURCC('M', 'A', 'C', '6'),
0
},
BUF_AUDIO_MAC6,
@@ -963,7 +955,7 @@ static const audio_db_t audio_db[] = {
},
{
{
- meFOURCC('Q', 'D', 'M', 'C'),
+ ME_FOURCC('Q', 'D', 'M', 'C'),
0
},
BUF_AUDIO_QDESIGN1,
@@ -971,7 +963,7 @@ static const audio_db_t audio_db[] = {
},
{
{
- meFOURCC('Q', 'D', 'M', '2'),
+ ME_FOURCC('Q', 'D', 'M', '2'),
0
},
BUF_AUDIO_QDESIGN2,
@@ -980,11 +972,11 @@ static const audio_db_t audio_db[] = {
{
{
0xFF,
- meFOURCC('m', 'p', '4', 'a'),
- meFOURCC('M', 'P', '4', 'A'),
- meFOURCC('r', 'a', 'a', 'c'),
- meFOURCC('r', 'a', 'c', 'p'),
- meFOURCC('A', 'A', 'C', ' '),
+ ME_FOURCC('m', 'p', '4', 'a'),
+ ME_FOURCC('M', 'P', '4', 'A'),
+ ME_FOURCC('r', 'a', 'a', 'c'),
+ ME_FOURCC('r', 'a', 'c', 'p'),
+ ME_FOURCC('A', 'A', 'C', ' '),
0
},
BUF_AUDIO_AAC,
@@ -992,7 +984,7 @@ static const audio_db_t audio_db[] = {
},
{
{
- meFOURCC('d', 'n', 'e', 't'),
+ ME_FOURCC('d', 'n', 'e', 't'),
0
},
BUF_AUDIO_DNET,
@@ -1000,7 +992,7 @@ static const audio_db_t audio_db[] = {
},
{
{
- meFOURCC('s', 'i', 'p', 'r'),
+ ME_FOURCC('s', 'i', 'p', 'r'),
0
},
BUF_AUDIO_SIPRO,
@@ -1008,7 +1000,7 @@ static const audio_db_t audio_db[] = {
},
{
{
- meFOURCC('c', 'o', 'o', 'k'),
+ ME_FOURCC('c', 'o', 'o', 'k'),
0
},
BUF_AUDIO_COOK,
@@ -1016,7 +1008,7 @@ static const audio_db_t audio_db[] = {
},
{
{
- meFOURCC('a', 't', 'r', 'c'),
+ ME_FOURCC('a', 't', 'r', 'c'),
0
},
BUF_AUDIO_ATRK,
@@ -1024,7 +1016,7 @@ static const audio_db_t audio_db[] = {
},
{
{
- meFOURCC('Q', 'c', 'l', 'p'),
+ ME_FOURCC('Q', 'c', 'l', 'p'),
0
},
BUF_AUDIO_QCLP,
@@ -1033,7 +1025,7 @@ static const audio_db_t audio_db[] = {
{
{
0x7,
- meFOURCC('u', 'l', 'a', 'w'),
+ ME_FOURCC('u', 'l', 'a', 'w'),
0
},
BUF_AUDIO_MULAW,
@@ -1042,7 +1034,7 @@ static const audio_db_t audio_db[] = {
{
{
0x6,
- meFOURCC('a', 'l', 'a', 'w'),
+ ME_FOURCC('a', 'l', 'a', 'w'),
0
},
BUF_AUDIO_ALAW,
@@ -1050,7 +1042,7 @@ static const audio_db_t audio_db[] = {
},
{
{
- meFOURCC('a', 'g', 's', 'm'),
+ ME_FOURCC('a', 'g', 's', 'm'),
0
},
BUF_AUDIO_GSM610,
@@ -1072,7 +1064,7 @@ static const audio_db_t audio_db[] = {
},
{
{
- meFOURCC('l', 'p', 'c', 'J'),
+ ME_FOURCC('l', 'p', 'c', 'J'),
0
},
BUF_AUDIO_14_4,
@@ -1080,7 +1072,7 @@ static const audio_db_t audio_db[] = {
},
{
{
- meFOURCC('2', '8', '_', '8'),
+ ME_FOURCC('2', '8', '_', '8'),
0
},
BUF_AUDIO_28_8,
@@ -1095,7 +1087,7 @@ static const audio_db_t audio_db[] = {
},
{
{
- meFOURCC('a', 'l', 'a', 'c'),
+ ME_FOURCC('a', 'l', 'a', 'c'),
},
BUF_AUDIO_ALAC,
"Apple Lossless Audio Codec"
@@ -1145,7 +1137,7 @@ static uint32_t cached_buf_type=0;
return 0;
}
-char * _x_buf_video_name( uint32_t buf_type ) {
+const char *_x_buf_video_name( uint32_t buf_type ) {
int i;
buf_type &= 0xffff0000;
@@ -1179,7 +1171,7 @@ static uint32_t cached_buf_type=0;
return 0;
}
-char * _x_buf_audio_name( uint32_t buf_type ) {
+const char *_x_buf_audio_name( uint32_t buf_type ) {
int i;
buf_type &= 0xffff0000;
diff --git a/src/xine-engine/configfile.h b/src/xine-engine/configfile.h
index 859214d1c..cf4a9703f 100644
--- a/src/xine-engine/configfile.h
+++ b/src/xine-engine/configfile.h
@@ -40,7 +40,7 @@ extern "C" {
#define CONFIG_FILE_VERSION 2
-/*
+/**
* config entries above this experience
* level must never be changed from MRL
*/
@@ -57,33 +57,32 @@ struct cfg_entry_s {
char *key;
int type;
- /* type unknown */
+ /** user experience level */
+ int exp_level;
+
+ /** type unknown */
char *unknown_value;
- /* type string */
+ /** type string */
char *str_value;
char *str_default;
- /* common to range, enum, num, bool: */
-
+ /** common to range, enum, num, bool: */
int num_value;
int num_default;
- /* type range specific: */
+ /** type range specific: */
int range_min;
int range_max;
- /* type enum specific: */
+ /** type enum specific: */
char **enum_values;
- /* help info for the user */
+ /** help info for the user */
char *description;
char *help;
- /* user experience level */
- int exp_level;
-
- /* callback function and data for live changeable values */
+ /** callback function and data for live changeable values */
xine_config_cb_t callback;
void *callback_data;
};
@@ -156,17 +155,17 @@ struct config_values_s {
xine_config_cb_t changed_cb,
void *cb_data);
- /* convenience function to update range, enum, num and bool values */
+ /** convenience function to update range, enum, num and bool values */
void (*update_num) (config_values_t *self, const char *key, int value);
- /* convenience function to update string values */
+ /** convenience function to update string values */
void (*update_string) (config_values_t *self, const char *key, const char *value);
- /* small utility function for enum handling */
+ /** small utility function for enum handling */
int (*parse_enum) (const char *str, const char **values);
- /*
- * lookup config entries
+ /**
+ * @brief lookup config entries
*
* remember to call the changed_cb if it exists
* and you changed the value of this item
@@ -174,12 +173,12 @@ struct config_values_s {
cfg_entry_t* (*lookup_entry) (config_values_t *self, const char *key);
- /*
+ /**
* unregister callback function
*/
void (*unregister_callback) (config_values_t *self, const char *key);
- /*
+ /**
* dispose of all config entries in memory
*/
void (*dispose) (config_values_t *self);
@@ -189,27 +188,29 @@ struct config_values_s {
*/
cfg_entry_t *first, *last, *cur;
- /*
+ /**
* mutex for modification to the config
*/
pthread_mutex_t config_lock;
- /*
+ /**
* current config file's version number
*/
int current_version;
};
-/*
- * allocate and init a new xine config object
+/**
+ * @brief allocate and init a new xine config object
+ * @internal
*/
-config_values_t *_x_config_init (void) XINE_PROTECTED;
+config_values_t *_x_config_init (void);
-/*
- * interpret stream_setup part of mrls for config value changes
+/**
+ * @brief interpret stream_setup part of mrls for config value changes
+ * @internal
*/
-int _x_config_change_opt(config_values_t *config, const char *opt) XINE_PROTECTED;
+int _x_config_change_opt(config_values_t *config, const char *opt);
#ifdef __cplusplus
diff --git a/src/xine-engine/load_plugins.c b/src/xine-engine/load_plugins.c
index c72241487..ca1f87c7a 100644
--- a/src/xine-engine/load_plugins.c
+++ b/src/xine-engine/load_plugins.c
@@ -43,6 +43,8 @@
#include <ctype.h>
#include <signal.h>
+#include <basedir.h>
+
#define LOG_MODULE "load_plugins"
#define LOG_VERBOSE
@@ -95,6 +97,7 @@ static void remove_segv_handler(void){
#endif
#endif /* 0 */
+#define CACHE_CATALOG_VERSION 2
static const int plugin_iface_versions[] = {
INPUT_PLUGIN_IFACE_VERSION,
@@ -949,7 +952,7 @@ static void load_plugin_list(FILE *fp, xine_sarray_t *plugins) {
file = xine_xmalloc(sizeof(plugin_file_t));
node->file = file;
file->filename = strdup(line+1);
- node->info = xine_xmalloc(2*sizeof(plugin_info_t));
+ node->info = xine_xcalloc(2, sizeof(plugin_info_t));
node->info[1].type = PLUGIN_NONE;
decoder_info = NULL;
vo_info = NULL;
@@ -1033,7 +1036,7 @@ static void load_plugin_list(FILE *fp, xine_sarray_t *plugins) {
for( s = value, i = 0; s && sscanf(s," %lu",&lu) > 0; i++ ) {
s = strchr(s+1, ' ');
}
- decoder_info->supported_types = xine_xmalloc((i+1)*sizeof(uint32_t));
+ decoder_info->supported_types = xine_xcalloc((i+1), sizeof(uint32_t));
for( s = value, i = 0; s && sscanf(s," %lu",&lu) > 0; i++ ) {
decoder_info->supported_types[i] = lu;
s = strchr(s+1, ' ');
@@ -1066,27 +1069,68 @@ static void load_plugin_list(FILE *fp, xine_sarray_t *plugins) {
}
}
+/**
+ * @brief Returns the complete filename for the plugins' cache file
+ * @param this Instance pointer, used for logging and libxdg-basedir.
+ * @param createdir If not zero, create the directory structure in which
+ * the file has to reside.
+ * @return If createdir was not zero, returns NULL if the directory hasn't
+ * been created; otherwise always returns a new string with the
+ * name of the cachefile.
+ * @internal
+ *
+ * @see XDG Base Directory specification:
+ * http://standards.freedesktop.org/basedir-spec/latest/index.html
+ */
+static char *catalog_filename(xine_t *this, int createdir) {
+ const char *const xdg_cache_home = xdgCacheHome(this->basedir_handle);
+ char *cachefile = NULL;
+
+ cachefile = xine_xmalloc( strlen(xdg_cache_home) + sizeof("/"PACKAGE"/plugins.cache") );
+ strcpy(cachefile, xdg_cache_home);
+
+ /* If we're going to create the directory structure, we concatenate
+ * piece by piece the path, so that we can try to create all the
+ * directories.
+ * If we don't need to create anything, we just concatenate the
+ * whole path at once.
+ */
+ if ( createdir ) {
+ int result = 0;
+
+ result = mkdir( cachefile, 0700 );
+ if ( result != 0 && errno != EEXIST ) {
+ /** @todo Convert this to use xine's log facility */
+ fprintf(stderr, _("Unable to create %s directory: %s\n"), cachefile, strerror(errno));
+ free(cachefile);
+ return NULL;
+ }
+
+ strcat(cachefile, "/"PACKAGE);
+ result = mkdir( cachefile, 0700 );
+ if ( result != 0 && errno != EEXIST ) {
+ /** @todo Convert this to use xine's log facility */
+ fprintf(stderr, _("Unable to create %s directory: %s\n"), cachefile, strerror(errno));
+ free(cachefile);
+ return NULL;
+ }
+
+ strcat(cachefile, "/plugins.cache");
+
+ } else
+ strcat(cachefile, "/"PACKAGE"/plugins.cache");
+
+ return cachefile;
+}
/*
* save catalog to cache file
*/
static void save_catalog (xine_t *this) {
-
FILE *fp;
- char *cachefile, *dirfile;
- const char *relname = CACHE_CATALOG_FILE;
- const char *dirname = CACHE_CATALOG_DIR;
-
- cachefile = (char *) xine_xmalloc(strlen(xine_get_homedir()) +
- strlen(relname) + 2);
- sprintf(cachefile, "%s/%s", xine_get_homedir(), relname);
-
- /* make sure homedir (~/.xine) exists */
- dirfile = (char *) xine_xmalloc(strlen(xine_get_homedir()) +
- strlen(dirname) + 2);
- sprintf(dirfile, "%s/%s", xine_get_homedir(), dirname);
- mkdir (dirfile, 0755);
- free (dirfile);
+ char *const cachefile = catalog_filename(this, 1);
+
+ if ( ! cachefile ) return;
if( (fp = fopen(cachefile,"w")) != NULL ) {
int i;
@@ -1108,13 +1152,9 @@ static void save_catalog (xine_t *this) {
static void load_cached_catalog (xine_t *this) {
FILE *fp;
- char *cachefile;
- const char *relname = CACHE_CATALOG_FILE;
-
- cachefile = (char *) xine_xmalloc(strlen(xine_get_homedir()) +
- strlen(relname) + 2);
- sprintf(cachefile, "%s/%s", xine_get_homedir(), relname);
-
+ char *const cachefile = catalog_filename(this, 0);
+ /* It can't return NULL without creating directories */
+
if( (fp = fopen(cachefile,"r")) != NULL ) {
load_plugin_list (fp, this->plugin_catalog->cache_list);
fclose(fp);
diff --git a/src/xine-engine/metronom.h b/src/xine-engine/metronom.h
index 1628ba9fd..e4115b6ad 100644
--- a/src/xine-engine/metronom.h
+++ b/src/xine-engine/metronom.h
@@ -336,8 +336,6 @@ metronom_clock_t *_x_metronom_clock_init(xine_t *xine) XINE_PROTECTED;
struct scr_plugin_s
{
- int interface_version;
-
int (*get_priority) (scr_plugin_t *self);
/*
@@ -358,6 +356,8 @@ struct scr_plugin_s
void (*exit) (scr_plugin_t *self);
metronom_clock_t *clock;
+
+ int interface_version;
};
#ifdef __cplusplus
diff --git a/src/xine-engine/osd.c b/src/xine-engine/osd.c
index b68b3b5c2..b8c3a1fd2 100644
--- a/src/xine-engine/osd.c
+++ b/src/xine-engine/osd.c
@@ -40,6 +40,8 @@
# include <iconv.h>
#endif
+#include <basedir.h>
+
#define LOG_MODULE "osd"
#define LOG_VERBOSE
/*
@@ -826,6 +828,93 @@ static int osd_renderer_unload_font(osd_renderer_t *this, char *fontname ) {
}
#ifdef HAVE_FT2
+
+# ifdef HAVE_FONTCONFIG
+/**
+ * @brief Look up a font name using FontConfig library
+ * @param osd The OSD object to load the font for.
+ * @param fontname Name of the font to look up.
+ * @param size Size of the font to look for.
+ *
+ * @return If the lookup was done correctly, a non-zero value is returned.
+ */
+static int osd_lookup_fontconfig( osd_object_t *osd, const char *const fontname, const int size ) {
+ FcPattern *pat = NULL, *match = NULL;
+ FcFontSet *fs = FcFontSetCreate();
+ FcResult result;
+
+ pat = FcPatternBuild(NULL, FC_FAMILY, FcTypeString, fontname, FC_SIZE, FcTypeDouble, (double)size, NULL);
+ FcConfigSubstitute(NULL, pat, FcMatchPattern);
+ FcDefaultSubstitute(pat);
+
+ match = FcFontMatch(NULL, pat, &result);
+ FcPatternDestroy(pat);
+
+ if ( ! match ) {
+ FcFontSetDestroy(fs);
+ xprintf(osd->renderer->stream->xine, XINE_VERBOSITY_LOG,
+ _("osd: error matching font %s with FontConfig"), fontname);
+ return 0;
+ }
+ FcFontSetAdd(fs, match);
+
+ if ( fs->nfont != 0 ) {
+ FcChar8 *filename = NULL;
+ FcPatternGetString(fs->fonts[0], FC_FILE, 0, &filename);
+ if ( ! FT_New_Face(osd->ft2->library, (const char*)filename, 0, &osd->ft2->face) ) {
+ FcFontSetDestroy(fs);
+ return 1;
+ }
+
+ xprintf(osd->renderer->stream->xine, XINE_VERBOSITY_LOG,
+ _("osd: error loading font %s with FontConfig"), fontname);
+ return 0;
+ } else {
+ xprintf(osd->renderer->stream->xine, XINE_VERBOSITY_LOG,
+ _("osd: error looking up font %s with FontConfig"), fontname);
+ return 0;
+ }
+}
+# endif /* HAVE_FONTCONFIG */
+
+/**
+ * @brief Look up a font file using XDG data directories.
+ * @param osd The OSD object to load the font for.
+ * @param fontname Name (absolute or relative) of the font to look up.
+ *
+ * @return If the lookup was done correctly, a non-zero value is returned.
+ *
+ * @see XDG Base Directory specification:
+ * http://standards.freedesktop.org/basedir-spec/latest/index.html
+ */
+static int osd_lookup_xdg( osd_object_t *osd, const char *const fontname ) {
+ const char *const *data_dirs = xdgSearchableDataDirectories(osd->renderer->stream->xine->basedir_handle);
+
+ /* try load font from current directory or from an absolute path */
+ if ( FT_New_Face(osd->ft2->library, fontname, 0, &osd->ft2->face) == FT_Err_Ok )
+ return 1;
+
+ if ( data_dirs )
+ while( (*data_dirs) && *(*data_dirs) ) {
+ FT_Error fte = FT_Err_Ok;
+ char *fontpath = NULL;
+ asprintf(&fontpath, "%s/"PACKAGE"/fonts/%s", *data_dirs, fontname);
+
+ fte = FT_New_Face(osd->ft2->library, fontpath, 0, &osd->ft2->face);
+
+ free(fontpath);
+
+ if ( fte == FT_Err_Ok )
+ return 1;
+
+ data_dirs++;
+ }
+
+ xprintf(osd->renderer->stream->xine, XINE_VERBOSITY_LOG,
+ _("osd: error loading font %s with in XDG data directories.\n"), fontname);
+ return 0;
+}
+
static int osd_set_font_freetype2( osd_object_t *osd, const char *fontname, int size ) {
if (!osd->ft2) {
osd->ft2 = xine_xmalloc(sizeof(osd_ft2context_t));
@@ -838,68 +927,19 @@ static int osd_set_font_freetype2( osd_object_t *osd, const char *fontname, int
}
}
+ do { /* while 0 */
#ifdef HAVE_FONTCONFIG
- do {
- FcPattern *pat = NULL, *match = NULL;
- FcFontSet *fs = FcFontSetCreate();
- FcResult result;
-
- pat = FcPatternBuild(NULL, FC_FAMILY, FcTypeString, fontname, FC_SIZE, FcTypeDouble, (double)size, NULL);
- FcConfigSubstitute(NULL, pat, FcMatchPattern);
- FcDefaultSubstitute(pat);
-
- match = FcFontMatch(NULL, pat, &result);
- FcPatternDestroy(pat);
-
- if ( ! match ) {
- FcFontSetDestroy(fs);
- xprintf(osd->renderer->stream->xine, XINE_VERBOSITY_LOG,
- _("osd: error matching font %s with FontConfig"), fontname);
+ if ( osd_lookup_fontconfig(osd, fontname, size) )
break;
- }
- FcFontSetAdd(fs, match);
-
- if ( fs->nfont != 0 ) {
- FcChar8 *filename = NULL;
- FcPatternGetString(fs->fonts[0], FC_FILE, 0, &filename);
- if ( ! FT_New_Face(osd->ft2->library, (const char*)filename, 0, &osd->ft2->face) ) {
- FcFontSetDestroy(fs);
- goto end;
- }
-
- xprintf(osd->renderer->stream->xine, XINE_VERBOSITY_LOG,
- _("osd: error loading font %s with FontConfig"), fontname);
- } else {
- xprintf(osd->renderer->stream->xine, XINE_VERBOSITY_LOG,
- _("osd: error looking up font %s with FontConfig"), fontname);
- }
- } while(0);
#endif
- {
- char pathname[1024];
- /* try load font from current directory */
- if ( !FT_New_Face(osd->ft2->library, fontname, 0, &osd->ft2->face) )
- goto end;
-
- /* try load font from home directory */
- snprintf(pathname, 1024, "%s/.xine/fonts/%s", xine_get_homedir(), fontname);
- if ( !FT_New_Face(osd->ft2->library, pathname, 0, &osd->ft2->face) )
- goto end;
-
- /* try load font from xine font directory */
- snprintf(pathname, 1024, "%s/%s", XINE_FONTDIR, fontname);
- if ( !FT_New_Face(osd->ft2->library, pathname, 0, &osd->ft2->face) )
- goto end;
-
- xprintf(osd->renderer->stream->xine, XINE_VERBOSITY_LOG,
- _("osd: error loading font %s with ft2\n"), fontname);
- }
+ if ( osd_lookup_xdg(osd, fontname) )
+ break;
- free(osd->ft2);
- osd->ft2 = NULL;
- return 0;
+ free(osd->ft2);
+ osd->ft2 = NULL;
+ return 0;
+ } while(0);
- end:
if (FT_Set_Pixel_Sizes(osd->ft2->face, 0, size)) {
xprintf(osd->renderer->stream->xine, XINE_VERBOSITY_LOG,
_("osd: error setting font size (no scalable font?)\n"));
@@ -1587,7 +1627,6 @@ static uint32_t osd_get_capabilities (osd_object_t *osd) {
osd_renderer_t *_x_osd_renderer_init( xine_stream_t *stream ) {
osd_renderer_t *this;
- char str[1024];
this = xine_xmalloc(sizeof(osd_renderer_t));
this->stream = stream;
@@ -1598,12 +1637,22 @@ osd_renderer_t *_x_osd_renderer_init( xine_stream_t *stream ) {
/*
* load available fonts
*/
+ {
+ const char *const *data_dirs = xdgSearchableDataDirectories(stream->xine->basedir_handle);
+ if ( data_dirs )
+ while( (*data_dirs) && *(*data_dirs) ) {
+ /* sizeof("") takes care of the final NUL byte */
+ char *fontpath = xine_xmalloc( strlen(*data_dirs) + sizeof("/"PACKAGE"/fonts/") );
+ strcpy(fontpath, *data_dirs);
+ strcat(fontpath, "/"PACKAGE"/fonts/");
- osd_preload_fonts (this, XINE_FONTDIR);
-
- snprintf (str, 1024, "%s/.xine/fonts", xine_get_homedir ());
+ osd_preload_fonts(this, fontpath);
- osd_preload_fonts (this, str);
+ free(fontpath);
+
+ data_dirs++;
+ }
+ }
this->textpalette = this->stream->xine->config->register_enum (this->stream->xine->config,
"ui.osd.text_palette", 0,
diff --git a/src/xine-engine/osd.h b/src/xine-engine/osd.h
index 6c7be8f0b..e8212acff 100644
--- a/src/xine-engine/osd.h
+++ b/src/xine-engine/osd.h
@@ -57,8 +57,6 @@ struct osd_object_s {
uint32_t color[OVL_PALETTE_SIZE]; /* color lookup table */
uint8_t trans[OVL_PALETTE_SIZE]; /* mixer key table */
- int32_t handle;
-
#ifdef HAVE_ICONV
iconv_t cd; /* iconv handle of encoding */
char *encoding; /* name of encoding */
@@ -66,6 +64,8 @@ struct osd_object_s {
osd_font_t *font;
osd_ft2context_t *ft2;
+
+ int32_t handle;
};
/* this one is public */
@@ -74,6 +74,8 @@ struct xine_osd_s {
};
struct osd_renderer_s {
+
+ xine_stream_t *stream;
/*
* open a new osd object. this will allocated an empty (all zero) drawing
@@ -219,8 +221,6 @@ struct osd_renderer_s {
osd_object_t *osds; /* instances of osd */
osd_font_t *fonts; /* loaded fonts */
int textpalette; /* default textpalette */
-
- xine_stream_t *stream;
};
diff --git a/src/xine-engine/plugin_catalog.h b/src/xine-engine/plugin_catalog.h
index 5bd1c4701..5533ab374 100644
--- a/src/xine-engine/plugin_catalog.h
+++ b/src/xine-engine/plugin_catalog.h
@@ -40,16 +40,12 @@
/* the engine takes this many plugins for one stream type */
#define PLUGINS_PER_TYPE 10
-#define CACHE_CATALOG_VERSION 2
-#define CACHE_CATALOG_FILE ".xine/catalog.cache"
-#define CACHE_CATALOG_DIR ".xine"
-
typedef struct {
char *filename;
off_t filesize;
time_t filemtime;
- int ref; /* count number of classes */
void *lib_handle;
+ int ref; /* count number of classes */
int no_unload; /* set if the file can't be unloaded */
} plugin_file_t ;
diff --git a/src/xine-engine/post.c b/src/xine-engine/post.c
index 6ae96e982..0dba50c82 100644
--- a/src/xine-engine/post.c
+++ b/src/xine-engine/post.c
@@ -149,6 +149,14 @@ static void post_video_flush(xine_video_port_t *port_gen) {
if (port->port_lock) pthread_mutex_unlock(port->port_lock);
}
+static void post_video_trigger_drawing(xine_video_port_t *port_gen) {
+ post_video_port_t *port = (post_video_port_t *)port_gen;
+
+ if (port->port_lock) pthread_mutex_lock(port->port_lock);
+ port->original_port->trigger_drawing(port->original_port);
+ if (port->port_lock) pthread_mutex_unlock(port->port_lock);
+}
+
static int post_video_status(xine_video_port_t *port_gen, xine_stream_t *stream,
int *width, int *height, int64_t *img_duration) {
post_video_port_t *port = (post_video_port_t *)port_gen;
@@ -192,6 +200,7 @@ static int post_video_rewire(xine_post_out_t *output_gen, void *data) {
if (!new_port)
return 0;
+ this->running_ticket->lock_port_rewiring(this->running_ticket, -1);
this->running_ticket->revoke(this->running_ticket, 1);
if (input_port->original_port->status(input_port->original_port, input_port->stream,
@@ -202,6 +211,7 @@ static int post_video_rewire(xine_post_out_t *output_gen, void *data) {
input_port->original_port = new_port;
this->running_ticket->issue(this->running_ticket, 1);
+ this->running_ticket->unlock_port_rewiring(this->running_ticket);
return 1;
}
@@ -223,6 +233,7 @@ post_video_port_t *_x_post_intercept_video_port(post_plugin_t *post, xine_video_
port->new_port.exit = post_video_exit;
port->new_port.get_overlay_manager = post_video_get_overlay_manager;
port->new_port.flush = post_video_flush;
+ port->new_port.trigger_drawing = post_video_trigger_drawing;
port->new_port.status = post_video_status;
port->new_port.get_property = post_video_get_property;
port->new_port.set_property = post_video_set_property;
@@ -680,6 +691,7 @@ static int post_audio_rewire(xine_post_out_t *output_gen, void *data) {
if (!new_port)
return 0;
+ this->running_ticket->lock_port_rewiring(this->running_ticket, -1);
this->running_ticket->revoke(this->running_ticket, 1);
if (input_port->original_port->status(input_port->original_port, input_port->stream,
@@ -690,6 +702,7 @@ static int post_audio_rewire(xine_post_out_t *output_gen, void *data) {
input_port->original_port = new_port;
this->running_ticket->issue(this->running_ticket, 1);
+ this->running_ticket->unlock_port_rewiring(this->running_ticket);
return 1;
}
diff --git a/src/xine-engine/post.h b/src/xine-engine/post.h
index bcdc3c54b..a3b9786ca 100644
--- a/src/xine-engine/post.h
+++ b/src/xine-engine/post.h
@@ -92,9 +92,6 @@ struct post_plugin_s {
*/
void (*dispose) (post_plugin_t *this);
- /* has dispose been called */
- int dispose_pending;
-
/* plugins don't have to init the stuff below */
/*
@@ -119,6 +116,9 @@ struct post_plugin_s {
/* used by plugin loader */
void *node;
+
+ /* has dispose been called */
+ int dispose_pending;
};
/* helper function to initialize a post_plugin_t */
@@ -290,15 +290,15 @@ struct post_audio_port_s {
/* the original port to call its functions from inside yours */
xine_audio_port_t *original_port;
- /* usage counter: how many objects are floating around that need
- * these pointers to exist */
- int usage_count;
- pthread_mutex_t usage_lock;
-
/* the stream we are being fed by; NULL means no stream is connected;
* this may be an anonymous stream */
xine_stream_t *stream;
+ pthread_mutex_t usage_lock;
+ /* usage counter: how many objects are floating around that need
+ * these pointers to exist */
+ int usage_count;
+
/* some values remembered by port->open() */
uint32_t bits;
uint32_t rate;
diff --git a/src/xine-engine/refcounter.h b/src/xine-engine/refcounter.h
index 640366b1f..739a6ad62 100644
--- a/src/xine-engine/refcounter.h
+++ b/src/xine-engine/refcounter.h
@@ -31,9 +31,9 @@
typedef struct {
pthread_mutex_t lock;
- int count;
void* object; /* referenced object */
void (*destructor)(void *); /* object destructor */
+ int count;
} refcounter_t;
typedef void (*refcounter_destructor)(void*);
diff --git a/src/xine-engine/scratch.c b/src/xine-engine/scratch.c
index 67281b041..4b694699f 100644
--- a/src/xine-engine/scratch.c
+++ b/src/xine-engine/scratch.c
@@ -112,11 +112,8 @@ scratch_buffer_t *_x_new_scratch_buffer (int num_lines) {
this = xine_xmalloc (sizeof (scratch_buffer_t));
- this->lines = xine_xmalloc (sizeof (char *) * (num_lines + 1));
- this->ordered = xine_xmalloc (sizeof (char *) * (num_lines + 1));
-
- for (i = 0; i <= num_lines; i++)
- this->lines[i] = this->ordered[i] = NULL;
+ this->lines = xine_xcalloc ((num_lines + 1), sizeof(char*));
+ this->ordered = xine_xcalloc ((num_lines + 1), sizeof(char*));
this->scratch_printf = scratch_printf;
this->get_content = scratch_get_content;
diff --git a/src/xine-engine/video_decoder.c b/src/xine-engine/video_decoder.c
index fee75ec76..3d39b4550 100644
--- a/src/xine-engine/video_decoder.c
+++ b/src/xine-engine/video_decoder.c
@@ -28,6 +28,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#define XINE_ENGINE_INTERNAL
@@ -110,6 +111,15 @@ static void *video_decoder_loop (void *stream_gen) {
int prof_video_decode = -1;
int prof_spu_decode = -1;
uint32_t buftype_unknown = 0;
+
+#ifndef WIN32
+ /* nice(-value) will fail silently for normal users.
+ * however when running as root this may provide smoother
+ * playback. follow the link for more information:
+ * http://cambuca.ldhs.cetuc.puc-rio.br/~miguel/multimedia_sim/
+ */
+ nice(-1);
+#endif /* WIN32 */
if (prof_video_decode == -1)
prof_video_decode = xine_profiler_allocate_slot ("video decoder");
diff --git a/src/xine-engine/video_out.c b/src/xine-engine/video_out.c
index 2a3ee1980..eeade3f48 100644
--- a/src/xine-engine/video_out.c
+++ b/src/xine-engine/video_out.c
@@ -71,6 +71,7 @@ typedef struct {
vo_frame_t *first;
vo_frame_t *last;
int num_buffers;
+ int num_buffers_max;
int locked_for_read;
pthread_mutex_t mutex;
@@ -128,9 +129,14 @@ typedef struct {
int current_width, current_height;
int64_t current_duration;
+ int frame_drop_limit_max;
int frame_drop_limit;
int frame_drop_cpt;
+ int frame_drop_suggested;
int crop_left, crop_right, crop_top, crop_bottom;
+ pthread_mutex_t trigger_drawing_mutex;
+ pthread_cond_t trigger_drawing_cond;
+ int trigger_drawing;
} vos_t;
@@ -144,9 +150,11 @@ static img_buf_fifo_t *vo_new_img_buf_queue () {
queue = (img_buf_fifo_t *) xine_xmalloc (sizeof (img_buf_fifo_t));
if( queue ) {
- queue->first = NULL;
- queue->last = NULL;
- queue->num_buffers = 0;
+ queue->first = NULL;
+ queue->last = NULL;
+ queue->num_buffers = 0;
+ queue->num_buffers_max = 0;
+
queue->locked_for_read = 0;
pthread_mutex_init (&queue->mutex, NULL);
pthread_cond_init (&queue->not_empty, NULL);
@@ -173,6 +181,8 @@ static void vo_append_to_img_buf_queue_int (img_buf_fifo_t *queue,
}
queue->num_buffers++;
+ if (queue->num_buffers_max < queue->num_buffers)
+ queue->num_buffers_max = queue->num_buffers;
pthread_cond_signal (&queue->not_empty);
}
@@ -213,14 +223,15 @@ static vo_frame_t *vo_remove_from_img_buf_queue_int (img_buf_fifo_t *queue, int
if( width && height ) {
if( !img ) {
- if( queue->num_buffers == 1 && !blocking) {
+ if( queue->num_buffers == 1 && !blocking && queue->num_buffers_max > 8) {
/* non-blocking and only a single frame on fifo with different
* format -> ignore it (give another chance of a frame format hit)
+ * only if we have a lot of buffers at all.
*/
lprintf("frame format mismatch - will wait another frame\n");
} else {
- /* we have at least 2 frames on fifo but they don't match ->
- * give up. return whatever we got.
+ /* we have just a limited number of buffers or at least 2 frames
+ * on fifo but they don't match -> give up. return whatever we got.
*/
img = queue->first;
lprintf("frame format miss (%d/%d)\n", i, queue->num_buffers);
@@ -467,28 +478,46 @@ static int vo_frame_draw (vo_frame_t *img, xine_stream_t *stream) {
duration = img->duration;
/* Frame dropping slow start:
- * The engine starts to drop frames if there is less than frame_drop_limit
+ * The engine starts to drop frames if there are less than frame_drop_limit
* frames in advance. There might be a problem just after a seek because
* there is no frame in advance yet.
* The following code increases progressively the frame_drop_limit (-2 -> 3)
* after a seek to give a chance to the engine to display the first frames
- * smootly before starting to drop frames if the decoder is really too
+ * smoothly before starting to drop frames if the decoder is really too
* slow.
+ * The above numbers are the result of frame_drop_limit_max beeing 3. They
+ * will be (-4 -> 1) when frame_drop_limit_max is only 1. This maximum value
+ * depends on the number of video buffers which the output device provides.
*/
if (stream && stream->first_frame_flag == 2)
this->frame_drop_cpt = 10;
if (this->frame_drop_cpt) {
- this->frame_drop_limit = 3 - (this->frame_drop_cpt / 2);
+ this->frame_drop_limit = this->frame_drop_limit_max - (this->frame_drop_cpt / 2);
this->frame_drop_cpt--;
}
frames_to_skip = ((-1 * diff) / duration + this->frame_drop_limit) * 2;
/* do not skip decoding until output fifo frames are consumed */
- if (this->display_img_buf_queue->num_buffers > this->frame_drop_limit ||
+ if (this->display_img_buf_queue->num_buffers >= this->frame_drop_limit ||
frames_to_skip < 0)
frames_to_skip = 0;
+ /* Do not drop frames immediately, but remember this as suggestion and give
+ * decoder a further chance to supply frames.
+ * This avoids unnecessary frame drops in situations where there is only
+ * a very little number of image buffers, e. g. when using xxmc.
+ */
+ if (this->frame_drop_suggested && frames_to_skip == 0)
+ this->frame_drop_suggested = 0;
+
+ if (frames_to_skip > 0) {
+ if (!this->frame_drop_suggested) {
+ this->frame_drop_suggested = 1;
+ frames_to_skip = 0;
+ }
+ }
+
lprintf ("delivery diff : %" PRId64 ", current vpts is %" PRId64 ", %d frames to skip\n",
diff, cur_vpts, frames_to_skip);
@@ -1043,6 +1072,32 @@ static void check_redraw_needed (vos_t *this, int64_t vpts) {
this->redraw_needed = 1;
}
+static int interruptable_sleep(vos_t *this, int usec_to_sleep)
+{
+ int timedout = 0;
+
+ struct timeval now;
+ gettimeofday(&now, 0);
+
+ pthread_mutex_lock (&this->trigger_drawing_mutex);
+ if (!this->trigger_drawing) {
+ struct timespec abstime;
+ abstime.tv_sec = now.tv_sec + usec_to_sleep / 1000000;
+ abstime.tv_nsec = now.tv_usec * 1000 + (usec_to_sleep % 1000000) * 1000;
+
+ if (abstime.tv_nsec > 1000000000) {
+ abstime.tv_nsec -= 1000000000;
+ abstime.tv_sec++;
+ }
+
+ timedout = pthread_cond_timedwait(&this->trigger_drawing_cond, &this->trigger_drawing_mutex, &abstime);
+ }
+ this->trigger_drawing = 0;
+ pthread_mutex_unlock (&this->trigger_drawing_mutex);
+
+ return timedout;
+}
+
/* special loop for paused mode
* needed to update screen due overlay changes, resize, window
* movement, brightness adjusting etc.
@@ -1088,7 +1143,7 @@ static void paused_loop( vos_t *this, int64_t vpts )
}
pthread_mutex_unlock( &this->free_img_buf_queue->mutex );
- xine_usec_sleep (20000);
+ interruptable_sleep(this, 20000);
pthread_mutex_lock( &this->free_img_buf_queue->mutex );
}
@@ -1218,7 +1273,10 @@ static void *video_out_loop (void *this_gen) {
"video_out: vpts/clock error, next_vpts=%" PRId64 " cur_vpts=%" PRId64 "\n", next_frame_vpts,vpts);
if (usec_to_sleep > 0)
- xine_usec_sleep (usec_to_sleep);
+ {
+ if (0 == interruptable_sleep(this, usec_to_sleep))
+ break;
+ }
if (this->discard_frames)
break;
@@ -1601,6 +1659,9 @@ static void vo_exit (xine_video_port_t *this_gen) {
free (this->free_img_buf_queue);
free (this->display_img_buf_queue);
+ pthread_cond_destroy(&this->trigger_drawing_cond);
+ pthread_mutex_destroy(&this->trigger_drawing_mutex);
+
free (this);
}
@@ -1670,6 +1731,15 @@ static void vo_flush (xine_video_port_t *this_gen) {
}
}
+static void vo_trigger_drawing (xine_video_port_t *this_gen) {
+ vos_t *this = (vos_t *) this_gen;
+
+ pthread_mutex_lock (&this->trigger_drawing_mutex);
+ this->trigger_drawing = 1;
+ pthread_cond_signal (&this->trigger_drawing_cond);
+ pthread_mutex_unlock (&this->trigger_drawing_mutex);
+}
+
/* crop_frame() will allocate a new frame to copy in the given image
* while cropping. maybe someday this will be an automatic post plugin.
*/
@@ -1765,6 +1835,7 @@ xine_video_port_t *_x_vo_new_port (xine_t *xine, vo_driver_t *driver, int grabon
this->vo.enable_ovl = vo_enable_overlay;
this->vo.get_overlay_manager = vo_get_overlay_manager;
this->vo.flush = vo_flush;
+ this->vo.trigger_drawing = vo_trigger_drawing;
this->vo.get_property = vo_get_property;
this->vo.set_property = vo_set_property;
this->vo.status = vo_status;
@@ -1784,8 +1855,6 @@ xine_video_port_t *_x_vo_new_port (xine_t *xine, vo_driver_t *driver, int grabon
this->overlay_source->init (this->overlay_source);
this->overlay_enabled = 1;
- this->frame_drop_limit = 3;
- this->frame_drop_cpt = 0;
/* default number of video frames from config */
num_frame_buffers = xine->config->register_num (xine->config,
@@ -1806,6 +1875,24 @@ xine_video_port_t *_x_vo_new_port (xine_t *xine, vo_driver_t *driver, int grabon
if (num_frame_buffers<5)
num_frame_buffers = 5;
+ /* Choose a frame_drop_limit which matches num_frame_buffers.
+ * xxmc for example supplies only 8 buffers. 2 are occupied by
+ * MPEG2 decoding, further 2 for displaying and the remaining 4 can
+ * hardly be filled all the time.
+ * The below constants reserve buffers for decoding, displaying and
+ * buffer fluctuation.
+ * A frame_drop_limit_max below 1 will disable frame drops at all.
+ */
+ this->frame_drop_limit_max = num_frame_buffers - 2 - 2 - 1;
+ if (this->frame_drop_limit_max < 1)
+ this->frame_drop_limit_max = 1;
+ else if (this->frame_drop_limit_max > 3)
+ this->frame_drop_limit_max = 3;
+
+ this->frame_drop_limit = this->frame_drop_limit_max;
+ this->frame_drop_cpt = 0;
+ this->frame_drop_suggested = 0;
+
this->extra_info_base = calloc (num_frame_buffers,
sizeof(extra_info_t));
@@ -1842,6 +1929,9 @@ xine_video_port_t *_x_vo_new_port (xine_t *xine, vo_driver_t *driver, int grabon
"were not scheduled for display in time, xine sends a notification."),
20, NULL, NULL);
+ pthread_mutex_init(&this->trigger_drawing_mutex, NULL);
+ pthread_cond_init(&this->trigger_drawing_cond, NULL);
+ this->trigger_drawing = 0;
if (grabonly) {
diff --git a/src/xine-engine/video_out.h b/src/xine-engine/video_out.h
index 085752dd8..bd169acfe 100644
--- a/src/xine-engine/video_out.h
+++ b/src/xine-engine/video_out.h
@@ -130,6 +130,9 @@ struct vo_frame_s {
/* cropping to be done */
int crop_left, crop_right, crop_top, crop_bottom;
+ int lock_counter;
+ pthread_mutex_t mutex; /* protect access to lock_count */
+
/* extra info coming from input or demuxers */
extra_info_t *extra_info;
@@ -158,8 +161,6 @@ struct vo_frame_s {
* obs: changing anything here will require recompiling vo drivers
*/
struct vo_frame_s *next;
- int lock_counter;
- pthread_mutex_t mutex; /* protect access to lock_count */
int id; /* debugging - track this frame */
int is_first;
@@ -205,6 +206,9 @@ struct xine_video_port_s {
/* flush video_out fifo */
void (*flush) (xine_video_port_t *self);
+ /* trigger immediate drawing */
+ void (*trigger_drawing) (xine_video_port_t *self);
+
/* Get/Set video property
*
* See VO_PROP_* bellow
@@ -443,11 +447,12 @@ struct video_overlay_manager_s {
vo_driver_t *output, vo_frame_t *vo_img, int enabled);
};
-/*
- * build a video_out_port from
- * a given video driver
+/**
+ * @brief Build a video output port from a given video driver.
+ *
+ * @internal
*/
-xine_video_port_t *_x_vo_new_port (xine_t *xine, vo_driver_t *driver, int grabonly) XINE_PROTECTED;
+xine_video_port_t *_x_vo_new_port (xine_t *xine, vo_driver_t *driver, int grabonly);
#ifdef __cplusplus
}
diff --git a/src/xine-engine/video_overlay.h b/src/xine-engine/video_overlay.h
index 1e7a2bcca..5e3455461 100644
--- a/src/xine-engine/video_overlay.h
+++ b/src/xine-engine/video_overlay.h
@@ -38,7 +38,7 @@
#define MAX_OBJECTS 50
#define MAX_EVENTS 50
-#define MAX_SHOWING 16
+#define MAX_SHOWING (5 + 16)
#define OVERLAY_EVENT_NULL 0
#define OVERLAY_EVENT_SHOW 1
@@ -46,58 +46,23 @@
#define OVERLAY_EVENT_MENU_BUTTON 3
#define OVERLAY_EVENT_FREE_HANDLE 8 /* Frees a handle, previous allocated via get_handle */
-/* number of colors in the overlay palette. Currently limited to 256
- at most, because some alphablend functions use an 8-bit index into
- the palette. This should probably be classified as a bug. */
-/* FIXME: Also defines in video_out.h */
-#define OVL_PALETTE_SIZE 256
-
-typedef struct vo_buttons_s {
- int32_t type; /* 0:Button not valid,
- 1:Button Valid, no auto_action,
- 2:Button Valid, auto_action.
- */
-
- /* The following clipping coordinates are relative to the left upper corner
- * of the OVERLAY, not of the target FRAME. Please do not mix them up! */
- int32_t hili_top;
- int32_t hili_bottom;
- int32_t hili_left;
- int32_t hili_right;
- int32_t up;
- int32_t down;
- int32_t left;
- int32_t right;
- uint32_t select_color[OVL_PALETTE_SIZE];
- uint8_t select_trans[OVL_PALETTE_SIZE];
- xine_event_t select_event;
- uint32_t active_color[OVL_PALETTE_SIZE];
- uint8_t active_trans[OVL_PALETTE_SIZE];
- xine_event_t active_event;
- int32_t hili_rgb_clut; /* true if clut was converted to rgb*/
- /* FIXME: Probably not needed ^^^ */
-} vo_buttons_t;
-
typedef struct video_overlay_object_s {
int32_t handle; /* Used to match Show and Hide events. */
uint32_t object_type; /* 0=Subtitle, 1=Menu */
int64_t pts; /* Needed for Menu button compares */
vo_overlay_t *overlay; /* The image data. */
- uint32_t palette_type; /* 1 Y'CrCB, 2 R'G'B' */
uint32_t *palette; /* If NULL, no palette contained in this event. */
- int32_t buttonN; /* Current highlighed button. 0 means no info on which button to higlight */
- /* -1 means don't use this button info. */
- vo_buttons_t button[32]; /* Info regarding each button on the overlay */
+ uint32_t palette_type; /* 1 Y'CrCB, 2 R'G'B' */
} video_overlay_object_t;
/* This will hold all details of an event item, needed for event queue to function */
typedef struct video_overlay_event_s {
- uint32_t event_type; /* Show SPU, Show OSD, Hide etc. */
int64_t vpts; /* Time when event will action. 0 means action now */
/* Once video_out blend_yuv etc. can take rle_elem_t with Colour, blend and length information.
* we can remove clut and blend from this structure.
* This will allow for many more colours for OSD.
*/
+ uint32_t event_type; /* Show SPU, Show OSD, Hide etc. */
video_overlay_object_t object; /* The image data. */
} video_overlay_event_t;
diff --git a/src/xine-engine/vo_scale.h b/src/xine-engine/vo_scale.h
index 917b6c99e..793ab1eb7 100644
--- a/src/xine-engine/vo_scale.h
+++ b/src/xine-engine/vo_scale.h
@@ -100,6 +100,9 @@ struct vo_scale_s {
int gui_width, gui_height;
int gui_win_x, gui_win_y;
+ /* */
+ int force_redraw;
+
/*
* video + display pixel aspect
* One pixel of height 1 has this width
@@ -121,10 +124,6 @@ struct vo_scale_s {
int output_yoffset;
- /* */
- int force_redraw;
-
-
/* gui callbacks */
void *user_data;
diff --git a/src/xine-engine/xine.c b/src/xine-engine/xine.c
index 9623668dc..ce2af52fa 100644
--- a/src/xine-engine/xine.c
+++ b/src/xine-engine/xine.c
@@ -47,6 +47,8 @@
#include <locale.h>
#endif
+#include <basedir.h>
+
#define LOG_MODULE "xine"
#define LOG_VERBOSE
/*
@@ -239,8 +241,37 @@ static void ticket_revoke(xine_ticket_t *this, int atomic) {
pthread_mutex_unlock(&this->revoke_lock);
}
+static int ticket_lock_port_rewiring(xine_ticket_t *this, int ms_timeout) {
+
+ if (ms_timeout >= 0) {
+ struct timespec abstime;
+
+ struct timeval now;
+ gettimeofday(&now, 0);
+
+ abstime.tv_sec = now.tv_sec + ms_timeout / 1000;
+ abstime.tv_nsec = now.tv_usec * 1000 + (ms_timeout % 1000) * 1e6;
+
+ if (abstime.tv_nsec > 1e9) {
+ abstime.tv_nsec -= 1e9;
+ abstime.tv_sec++;
+ }
+
+ return (0 == pthread_mutex_timedlock(&this->port_rewiring_lock, &abstime));
+ }
+
+ pthread_mutex_lock(&this->port_rewiring_lock);
+ return 1;
+}
+
+static void ticket_unlock_port_rewiring(xine_ticket_t *this) {
+
+ pthread_mutex_unlock(&this->port_rewiring_lock);
+}
+
static void ticket_dispose(xine_ticket_t *this) {
+ pthread_mutex_destroy(&this->port_rewiring_lock);
pthread_mutex_destroy(&this->lock);
pthread_mutex_destroy(&this->revoke_lock);
pthread_cond_destroy(&this->issued);
@@ -261,10 +292,13 @@ static xine_ticket_t *ticket_init(void) {
port_ticket->renew = ticket_renew;
port_ticket->issue = ticket_issue;
port_ticket->revoke = ticket_revoke;
+ port_ticket->lock_port_rewiring = ticket_lock_port_rewiring;
+ port_ticket->unlock_port_rewiring = ticket_unlock_port_rewiring;
port_ticket->dispose = ticket_dispose;
pthread_mutex_init(&port_ticket->lock, NULL);
pthread_mutex_init(&port_ticket->revoke_lock, NULL);
+ pthread_mutex_init(&port_ticket->port_rewiring_lock, NULL);
pthread_cond_init(&port_ticket->issued, NULL);
pthread_cond_init(&port_ticket->revoked, NULL);
@@ -458,6 +492,7 @@ static int stream_rewire_audio(xine_post_out_t *output, void *data)
if (!data)
return 0;
+ stream->xine->port_ticket->lock_port_rewiring(stream->xine->port_ticket, -1);
stream->xine->port_ticket->revoke(stream->xine->port_ticket, 1);
if (stream->audio_out->status(stream->audio_out, stream, &bits, &rate, &mode)) {
@@ -468,6 +503,7 @@ static int stream_rewire_audio(xine_post_out_t *output, void *data)
stream->audio_out = new_port;
stream->xine->port_ticket->issue(stream->xine->port_ticket, 1);
+ stream->xine->port_ticket->unlock_port_rewiring(stream->xine->port_ticket);
return 1;
}
@@ -482,6 +518,7 @@ static int stream_rewire_video(xine_post_out_t *output, void *data)
if (!data)
return 0;
+ stream->xine->port_ticket->lock_port_rewiring(stream->xine->port_ticket, -1);
stream->xine->port_ticket->revoke(stream->xine->port_ticket, 1);
if (stream->video_out->status(stream->video_out, stream, &width, &height, &img_duration)) {
@@ -492,6 +529,7 @@ static int stream_rewire_video(xine_post_out_t *output, void *data)
stream->video_out = new_port;
stream->xine->port_ticket->issue(stream->xine->port_ticket, 1);
+ stream->xine->port_ticket->unlock_port_rewiring(stream->xine->port_ticket);
return 1;
}
@@ -1439,6 +1477,8 @@ void xine_exit (xine_t *this) {
WSACleanup();
#endif
+ xdgFreeHandle(this->basedir_handle);
+
free (this);
}
@@ -1564,8 +1604,11 @@ static void config_save_cb (void *this_gen, xine_cfg_entry_t *entry) {
}
void xine_init (xine_t *this) {
- static const char *demux_strategies[] = {"default", "reverse", "content",
- "extension", NULL};
+ static const char *const demux_strategies[] = {"default", "reverse", "content",
+ "extension", NULL};
+
+ /* First of all, initialise libxdg-basedir as it's used by plugins. */
+ this->basedir_handle = xdgAllocHandle();
/* initialize color conversion tables and functions */
init_yuv_conversion();
@@ -1998,6 +2041,9 @@ const char *const *xine_get_log_names (xine_t *this) {
static inline void check_log_alloc (xine_t *this, int buf)
{
+ if ( this->log_buffers[buf] )
+ return;
+
pthread_mutex_lock (&this->log_lock);
if ( ! this->log_buffers[buf] )
@@ -2097,3 +2143,83 @@ int _x_query_buffer_usage(xine_stream_t *stream, int *num_video_buffers, int *nu
return ticket_acquired != 0;
}
+
+int _x_lock_port_rewiring(xine_t *xine, int ms_timeout)
+{
+ return xine->port_ticket->lock_port_rewiring(xine->port_ticket, ms_timeout);
+}
+
+void _x_unlock_port_rewiring(xine_t *xine)
+{
+ xine->port_ticket->unlock_port_rewiring(xine->port_ticket);
+}
+
+int _x_lock_frontend(xine_stream_t *stream, int ms_to_time_out)
+{
+ if (ms_to_time_out >= 0) {
+ struct timespec abstime;
+
+ struct timeval now;
+ gettimeofday(&now, 0);
+
+ abstime.tv_sec = now.tv_sec + ms_to_time_out / 1000;
+ abstime.tv_nsec = now.tv_usec * 1000 + (ms_to_time_out % 1000) * 1e6;
+
+ if (abstime.tv_nsec > 1e9) {
+ abstime.tv_nsec -= 1e9;
+ abstime.tv_sec++;
+ }
+
+ return (0 == pthread_mutex_timedlock(&stream->frontend_lock, &abstime));
+ }
+
+ pthread_mutex_lock(&stream->frontend_lock);
+ return 1;
+}
+
+void _x_unlock_frontend(xine_stream_t *stream)
+{
+ pthread_mutex_unlock(&stream->frontend_lock);
+}
+
+int _x_query_unprocessed_osd_events(xine_stream_t *stream)
+{
+ video_overlay_manager_t *ovl;
+ int redraw_needed;
+
+ if (!stream->xine->port_ticket->acquire_nonblocking(stream->xine->port_ticket, 1))
+ return -1;
+
+ ovl = stream->video_out->get_overlay_manager(stream->video_out);
+ redraw_needed = ovl->redraw_needed(ovl, 0);
+
+ if (redraw_needed)
+ stream->video_out->trigger_drawing(stream->video_out);
+
+ stream->xine->port_ticket->release_nonblocking(stream->xine->port_ticket, 1);
+
+ return redraw_needed;
+}
+
+int _x_demux_seek(xine_stream_t *stream, off_t start_pos, int start_time, int playing)
+{
+ if (!stream->demux_plugin)
+ return -1;
+ return stream->demux_plugin->seek(stream->demux_plugin, start_pos, start_time, playing);
+}
+
+int _x_continue_stream_processing(xine_stream_t *stream)
+{
+ return stream->status != XINE_STATUS_STOP
+ && stream->status != XINE_STATUS_QUIT;
+}
+
+void _x_trigger_relaxed_frame_drop_mode(xine_stream_t *stream)
+{
+ stream->first_frame_flag = 2;
+}
+
+void _x_reset_relaxed_frame_drop_mode(xine_stream_t *stream)
+{
+ stream->first_frame_flag = 1;
+}
diff --git a/src/xine-engine/xine_internal.h b/src/xine-engine/xine_internal.h
index c88bcc904..208ef7647 100644
--- a/src/xine-engine/xine_internal.h
+++ b/src/xine-engine/xine_internal.h
@@ -72,7 +72,6 @@ extern "C" {
# include <xine/alphablend.h>
#endif
-
#define XINE_MAX_EVENT_LISTENERS 50
#define XINE_MAX_EVENT_TYPES 100
@@ -103,19 +102,22 @@ struct xine_s {
plugin_catalog_t *plugin_catalog;
+ int verbosity;
+
int demux_strategy;
char *save_path;
/* log output that may be presented to the user */
scratch_buffer_t *log_buffers[XINE_LOG_NUM];
- int verbosity;
-
xine_list_t *streams;
pthread_mutex_t streams_lock;
metronom_clock_t *clock;
+ /** Handle for libxdg-basedir functions. It's actually an xdgHandle. */
+ void * basedir_handle;
+
#ifdef XINE_ENGINE_INTERNAL
xine_ticket_t *port_ticket;
pthread_mutex_t log_lock;
@@ -168,6 +170,9 @@ struct xine_ticket_s {
* be used in combination with acquire_nonblocking() */
void (*release_nonblocking)(xine_ticket_t *self, int irrevocable);
+ int (*lock_port_rewiring)(xine_ticket_t *self, int ms_timeout);
+ void (*unlock_port_rewiring)(xine_ticket_t *self);
+
void (*dispose)(xine_ticket_t *self);
pthread_mutex_t lock;
@@ -179,6 +184,7 @@ struct xine_ticket_s {
int pending_revocations;
int atomic_revoke;
pthread_t atomic_revoker_thread;
+ pthread_mutex_t port_rewiring_lock;
#endif
};
@@ -193,9 +199,9 @@ struct xine_event_queue_s {
pthread_cond_t events_processed;
xine_stream_t *stream;
pthread_t *listener_thread;
+ void *user_data;
xine_event_listener_cb_t callback;
int callback_running;
- void *user_data;
};
/*
@@ -213,9 +219,6 @@ struct xine_stream_s {
/* demuxers use input_plugin to read data */
input_plugin_t *input_plugin;
- /* current content detection method, see METHOD_BY_xxx */
- int content_detection_method;
-
/* used by video decoders */
xine_video_port_t *video_out;
@@ -249,6 +252,9 @@ struct xine_stream_s {
int spu_channel_letterbox;
int spu_channel;
+ /* current content detection method, see METHOD_BY_xxx */
+ int content_detection_method;
+
#ifdef XINE_ENGINE_INTERNAL
/* these are private variables, plugins must not access them */
@@ -256,27 +262,38 @@ struct xine_stream_s {
/* lock controlling speed change access */
pthread_mutex_t speed_change_lock;
- int ignore_speed_change; /* speed changes during stop can be disastrous */
+ uint32_t ignore_speed_change:1; /*< speed changes during stop can be disastrous */
+ uint32_t video_thread_created:1;
+ uint32_t audio_thread_created:1;
+ uint32_t first_frame_flag:2;
+ uint32_t demux_action_pending:1;
+ uint32_t demux_thread_created:1;
+ uint32_t demux_thread_running:1;
+ uint32_t slave_is_subtitle:1; /*< ... and will be automaticaly disposed */
+ uint32_t emergency_brake:1; /*< something went really wrong and this stream must be
+ * stopped. usually due some fatal error on output
+ * layers as they cannot call xine_stop. */
+ uint32_t early_finish_event:1; /*< do not wait fifos get empty before sending event */
+ uint32_t gapless_switch:1; /*< next stream switch will be gapless */
input_class_t *eject_class;
demux_plugin_t *demux_plugin;
/* vo_driver_t *video_driver;*/
pthread_t video_thread;
- int video_thread_created;
video_decoder_t *video_decoder_plugin;
- int video_decoder_streamtype;
extra_info_t *video_decoder_extra_info;
+ int video_decoder_streamtype;
int video_channel;
+ uint32_t audio_track_map[50];
+ int audio_track_map_entries;
+
+ int audio_decoder_streamtype;
pthread_t audio_thread;
- int audio_thread_created;
audio_decoder_t *audio_decoder_plugin;
- int audio_decoder_streamtype;
extra_info_t *audio_decoder_extra_info;
- uint32_t audio_track_map[50];
- int audio_track_map_entries;
uint32_t audio_type;
/* *_user: -2 => off
-1 => auto (use *_auto value)
@@ -308,7 +325,6 @@ struct xine_stream_s {
char *meta_info[XINE_STREAM_INFO_MAX];
/* seeking slowdown */
- int first_frame_flag;
pthread_mutex_t first_frame_lock;
pthread_cond_t first_frame_reached;
@@ -326,34 +342,25 @@ struct xine_stream_s {
/* demux thread stuff */
pthread_t demux_thread;
- int demux_thread_created;
- int demux_thread_running;
pthread_mutex_t demux_lock;
- int demux_action_pending;
pthread_mutex_t demux_mutex; /* used in _x_demux_... functions to synchronize order of pairwise A/V buffer operations */
extra_info_t *current_extra_info;
pthread_mutex_t current_extra_info_lock;
int video_seek_count;
- xine_post_out_t video_source;
- xine_post_out_t audio_source;
-
- int slave_is_subtitle; /* ... and will be automaticaly disposed */
+ int delay_finish_event; /* delay event in 1/10 sec units. 0=>no delay, -1=>forever */
+
int slave_affection; /* what operations need to be propagated down to the slave? */
int err;
+ xine_post_out_t video_source;
+ xine_post_out_t audio_source;
+
broadcaster_t *broadcaster;
refcounter_t *refcounter;
-
- int emergency_brake; /* something went really wrong and this stream must be
- * stopped. usually due some fatal error on output
- * layers as they cannot call xine_stop. */
- int early_finish_event; /* do not wait fifos get empty before sending event */
- int gapless_switch; /* next stream switch will be gapless */
- int delay_finish_event; /* delay event in 1/10 sec units. 0=>no delay, -1=>forever */
#endif
};
@@ -367,6 +374,15 @@ struct xine_stream_s {
*/
int _x_query_buffer_usage(xine_stream_t *stream, int *num_video_buffers, int *num_audio_buffers, int *num_video_frames, int *num_audio_frames) XINE_PROTECTED;
+int _x_lock_port_rewiring(xine_t *xine, int ms_to_time_out) XINE_PROTECTED;
+void _x_unlock_port_rewiring(xine_t *xine) XINE_PROTECTED;
+int _x_lock_frontend(xine_stream_t *stream, int ms_to_time_out) XINE_PROTECTED;
+void _x_unlock_frontend(xine_stream_t *stream) XINE_PROTECTED;
+int _x_query_unprocessed_osd_events(xine_stream_t *stream) XINE_PROTECTED;
+int _x_demux_seek(xine_stream_t *stream, off_t start_pos, int start_time, int playing) XINE_PROTECTED;
+int _x_continue_stream_processing(xine_stream_t *stream) XINE_PROTECTED;
+void _x_trigger_relaxed_frame_drop_mode(xine_stream_t *stream) XINE_PROTECTED;
+void _x_reset_relaxed_frame_drop_mode(xine_stream_t *stream) XINE_PROTECTED;
void _x_handle_stream_end (xine_stream_t *stream, int non_user) XINE_PROTECTED;
diff --git a/src/xine-utils/Makefile.am b/src/xine-utils/Makefile.am
index 95de06b9e..a9c37465a 100644
--- a/src/xine-utils/Makefile.am
+++ b/src/xine-utils/Makefile.am
@@ -1,19 +1,33 @@
include $(top_srcdir)/misc/Makefile.common
-LIBTOOL = $(SHELL) $(top_builddir)/libtool
-noinst_LTLIBRARIES = libxineutils.la
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(X_CFLAGS) $(VISIBILITY_FLAG)
+AM_CPPFLAGS = -DXINE_LIBRARY_COMPILE
EXTRA_DIST = ppcasm_string.S ppc_asm.tmpl
-if PPC_ARCH
+noinst_HEADERS = ppcasm_string.h xine_check.h
+
+xineinclude_HEADERS = \
+ attributes.h \
+ compat.h \
+ xine_buffer.h \
+ xineutils.h \
+ xmllexer.h \
+ xmlparser.h \
+ list.h \
+ array.h \
+ sorted_array.h \
+ pool.h \
+ ring_buffer.h
+
+noinst_LTLIBRARIES = libxineutils.la
+
+if ARCH_PPC
if !HOST_OS_DARWIN
pppc_files = ppcasm_string.S
endif
endif
-AM_CFLAGS = $(X_CFLAGS) $(VISIBILITY_FLAG)
-AM_CPPFLAGS=-DXINE_LIBRARY_COMPILE
-
libxineutils_la_SOURCES = $(pppc_files) \
cpu_accel.c \
color.c \
@@ -32,19 +46,3 @@ libxineutils_la_SOURCES = $(pppc_files) \
pool.c \
ring_buffer.c
-xineinclude_HEADERS = \
- attributes.h \
- compat.h \
- xine_buffer.h \
- xineutils.h \
- xmllexer.h \
- xmlparser.h \
- list.h \
- array.h \
- sorted_array.h \
- pool.h \
- ring_buffer.h
-
-
-noinst_HEADERS = ppcasm_string.h xine_check.h
-
diff --git a/src/xine-utils/attributes.h b/src/xine-utils/attributes.h
index 13c787925..280fd3685 100644
--- a/src/xine-utils/attributes.h
+++ b/src/xine-utils/attributes.h
@@ -32,18 +32,6 @@
#define ATTR_ALIGN(align)
#endif
-/* disable GNU __attribute__ extension, when not compiling with GNU C */
-#if defined(__GNUC__) || defined (__ICC)
-#ifndef ATTRIBUTE_PACKED
-#define ATTRIBUTE_PACKED 1
-#endif
-#else
-#undef ATTRIBUTE_PACKED
-#ifndef __attribute__
-#define __attribute__(x) /**/
-#endif /* __attribute __*/
-#endif
-
#ifdef XINE_COMPILE
# include "config.h"
#endif
@@ -83,4 +71,16 @@
# define XINE_FORMAT_PRINTF_ARG(fmt)
#endif
+#ifdef SUPPORT_ATTRIBUTE_PACKED
+# define XINE_PACKED __attribute__((packed))
+#else
+# define XINE_PACKED
+#endif
+
+#ifdef SUPPORT_ATTRIBUTE_MALLOC
+# define XINE_MALLOC __attribute__((__malloc__))
+#else
+# define XINE_MALLOC
+#endif
+
#endif /* ATTRIBUTE_H_ */
diff --git a/src/xine-utils/memcpy.c b/src/xine-utils/memcpy.c
index 539f4c8dd..67645081e 100644
--- a/src/xine-utils/memcpy.c
+++ b/src/xine-utils/memcpy.c
@@ -383,8 +383,8 @@ static void *linux_kernel_memcpy(void *to, const void *from, size_t len) {
#endif /* ARCH_X86 */
static struct {
- char *name;
- void *(* function)(void *to, const void *from, size_t len);
+ char *const name;
+ void *(*const function)(void *to, const void *from, size_t len);
uint64_t time; /* This type could be used for non-MSC build too! */
@@ -461,7 +461,7 @@ void xine_probe_fast_memcpy(xine_t *xine)
char *buf1, *buf2;
int i, j, best;
int config_flags = -1;
- static const char *memcpy_methods[] = {
+ static const char *const memcpy_methods[] = {
"probe", "libc",
#if (defined(ARCH_X86) || defined(ARCH_X86_64)) && !defined(_MSC_VER)
"kernel", "mmx", "mmxext", "sse",
diff --git a/src/xine-utils/monitor.c b/src/xine-utils/monitor.c
index c0cfd6179..b19195065 100644
--- a/src/xine-utils/monitor.c
+++ b/src/xine-utils/monitor.c
@@ -41,13 +41,10 @@ static long profiler_calls[MAX_ID] ;
static const char *profiler_label[MAX_ID] ;
void xine_profiler_init () {
- int i;
- for (i=0; i<MAX_ID; i++) {
- profiler_times[i] = 0;
- profiler_start[i] = 0;
- profiler_calls[i] = 0;
- profiler_label[i] = NULL;
- }
+ memset(profiler_times, 0, sizeof(profiler_times));
+ memset(profiler_start, 0, sizeof(profiler_start));
+ memset(profiler_calls, 0, sizeof(profiler_calls));
+ memset(profiler_label, 0, sizeof(profiler_label));
}
int xine_profiler_allocate_slot (const char *label) {
diff --git a/src/xine-utils/utils.c b/src/xine-utils/utils.c
index fa0c11dbe..63c2e2f09 100644
--- a/src/xine-utils/utils.c
+++ b/src/xine-utils/utils.c
@@ -256,6 +256,27 @@ void *xine_xmalloc(size_t size) {
return ptr;
}
+/**
+ * @brief Wrapper around calloc() function.
+ * @param nmemb Number of elements to allocate
+ * @param size Size of each element to allocate
+ *
+ * This is a simple wrapper around calloc(), the only thing
+ * it does more than calloc() is outputting an error if
+ * the calloc fails (returning NULL).
+ */
+void *xine_xcalloc(size_t nmemb, size_t size) {
+ void *ptr;
+
+ if((ptr = calloc(nmemb, size)) == NULL) {
+ fprintf(stderr, "%s: calloc() failed: %s.\n",
+ __XINE_FUNCTION__, strerror(errno));
+ return NULL;
+ }
+
+ return ptr;
+}
+
void *xine_xmalloc_aligned(size_t alignment, size_t size, void **base) {
char *ptr;
diff --git a/src/xine-utils/xineutils.h b/src/xine-utils/xineutils.h
index 03c5f689a..0be29ff63 100644
--- a/src/xine-utils/xineutils.h
+++ b/src/xine-utils/xineutils.h
@@ -624,11 +624,9 @@ void xine_profiler_print_results (void) XINE_PROTECTED;
* Allocate and clean memory size_t 'size', then return the pointer
* to the allocated memory.
*/
-#if !defined(__GNUC__) || __GNUC__ < 3
-void *xine_xmalloc(size_t size) XINE_PROTECTED;
-#else
-void *xine_xmalloc(size_t size) __attribute__ ((__malloc__)) XINE_PROTECTED;
-#endif
+void *xine_xmalloc(size_t size) XINE_MALLOC XINE_PROTECTED;
+
+void *xine_xcalloc(size_t nmemb, size_t size) XINE_MALLOC XINE_PROTECTED;
/*
* Same as above, but memory is aligned to 'alignement'.
diff --git a/version.sh b/version.sh
new file mode 100755
index 000000000..2d9438379
--- /dev/null
+++ b/version.sh
@@ -0,0 +1,50 @@
+#!/bin/sh
+
+# Making releases:
+# 1. Increment XINE_VERSION_SUB
+# 2. Remove .cvsversion before running make dist
+# 3. Adjust the values of XINE_LT_CURRENT, XINE_LT_REVISION, and XINE_LT_AGE
+# according to the following rules:
+#
+# If the interface is totally unchanged from the previous release,
+# increment XINE_LT_REVISION by one. Otherwise:
+# 1. XINE_LT_REVISION=0
+# 2. Increment XINE_LT_CURRENT by one.
+# 3. If any interfaces have been ADDED since the last release,
+# increment XINE_LT_AGE by one. If any interfaces have been
+# REMOVED or incompatibly changed, XINE_LT_AGE=0
+#
+# Regarding libtool versioning, here are some details, but see the info page for
+# libtool for the whole story. The most important thing to keep in mind is that
+# the libtool version numbers DO NOT MATCH the xine-lib version numbers, and you
+# should NEVER try to make them match.
+#
+# XINE_LT_CURRENT the current API version
+# XINE_LT_REVISION an internal revision number that is increased when the
+# API does not change in any way
+# XINE_LT_AGE the number of previous API versions still supported by
+# this version
+
+XINE_VERSION_MAJOR=1
+XINE_VERSION_MINOR=1
+XINE_VERSION_SUB=90
+
+XINE_LT_CURRENT=19
+XINE_LT_REVISION=0
+XINE_LT_AGE=17
+
+test -f "`dirname $0`/.cvsversion" && XINE_VERSION_SUFFIX="hg"
+XINE_VERSION_SPEC="${XINE_VERSION_MAJOR}.${XINE_VERSION_MINOR}.${XINE_VERSION_SUB}${XINE_VERSION_SUFFIX}"
+
+####
+#### You should not need to touch anything beyond this point
+####
+
+echo "m4_define([XINE_VERSION_MAJOR], [${XINE_VERSION_MAJOR}])dnl"
+echo "m4_define([XINE_VERSION_MINOR], [${XINE_VERSION_MINOR}])dnl"
+echo "m4_define([XINE_VERSION_SUB], [${XINE_VERSION_SUB}])dnl"
+echo "m4_define([XINE_VERSION_SUFFIX], [${XINE_VERSION_SUFFIX}])dnl"
+echo "m4_define([XINE_VERSION_SPEC], [${XINE_VERSION_SPEC}])dnl"
+echo "m4_define([__XINE_LT_CURRENT], [${XINE_LT_CURRENT}])dnl"
+echo "m4_define([__XINE_LT_REVISION], [${XINE_LT_REVISION}])dnl"
+echo "m4_define([__XINE_LT_AGE], [${XINE_LT_AGE}])dnl"
diff --git a/win32/README b/win32/README
index 926e2708d..926e2708d 100644..100755
--- a/win32/README
+++ b/win32/README
diff --git a/win32/config.h b/win32/config.h
index f62c641ec..f62c641ec 100644..100755
--- a/win32/config.h
+++ b/win32/config.h
diff --git a/win32/include/sys/socket.h b/win32/include/sys/socket.h
index 7786114a8..7786114a8 100644..100755
--- a/win32/include/sys/socket.h
+++ b/win32/include/sys/socket.h
diff --git a/win32/xineplug_dmx_audio.dsp b/win32/xineplug_dmx_audio.dsp
index 6d634a25f..6d634a25f 100644..100755
--- a/win32/xineplug_dmx_audio.dsp
+++ b/win32/xineplug_dmx_audio.dsp
diff --git a/win32/xineplug_dmx_lpcm.dsp b/win32/xineplug_dmx_lpcm.dsp
index f77a2336c..f77a2336c 100644..100755
--- a/win32/xineplug_dmx_lpcm.dsp
+++ b/win32/xineplug_dmx_lpcm.dsp
diff --git a/win32/xineplug_dmx_nsv.dsp b/win32/xineplug_dmx_nsv.dsp
index 95929b5cf..95929b5cf 100644..100755
--- a/win32/xineplug_dmx_nsv.dsp
+++ b/win32/xineplug_dmx_nsv.dsp
diff --git a/win32/xineplug_dmx_pva.dsp b/win32/xineplug_dmx_pva.dsp
index 276d77fd6..276d77fd6 100644..100755
--- a/win32/xineplug_dmx_pva.dsp
+++ b/win32/xineplug_dmx_pva.dsp
diff --git a/win32/xineplug_dmx_real.dsp b/win32/xineplug_dmx_real.dsp
index cdbdad67a..cdbdad67a 100644..100755
--- a/win32/xineplug_dmx_real.dsp
+++ b/win32/xineplug_dmx_real.dsp
diff --git a/win32/xineplug_dmx_slave.dsp b/win32/xineplug_dmx_slave.dsp
index 93315b293..93315b293 100644..100755
--- a/win32/xineplug_dmx_slave.dsp
+++ b/win32/xineplug_dmx_slave.dsp
diff --git a/win32/xineplug_dmx_yuv4mpeg2.dsp b/win32/xineplug_dmx_yuv4mpeg2.dsp
index 6f7db927f..6f7db927f 100644..100755
--- a/win32/xineplug_dmx_yuv4mpeg2.dsp
+++ b/win32/xineplug_dmx_yuv4mpeg2.dsp
diff --git a/win32/xineplug_dmx_yuv_frames.dsp b/win32/xineplug_dmx_yuv_frames.dsp
index e02f4d228..e02f4d228 100644..100755
--- a/win32/xineplug_dmx_yuv_frames.dsp
+++ b/win32/xineplug_dmx_yuv_frames.dsp
diff --git a/win32/xineplug_inp_cdda.dsp b/win32/xineplug_inp_cdda.dsp
index dddde9eb2..dddde9eb2 100644..100755
--- a/win32/xineplug_inp_cdda.dsp
+++ b/win32/xineplug_inp_cdda.dsp
diff --git a/win32/xineplug_inp_http.dsp b/win32/xineplug_inp_http.dsp
index da251d59e..da251d59e 100644..100755
--- a/win32/xineplug_inp_http.dsp
+++ b/win32/xineplug_inp_http.dsp
diff --git a/win32/xineplug_inp_net.dsp b/win32/xineplug_inp_net.dsp
index b8d9bd347..b8d9bd347 100644..100755
--- a/win32/xineplug_inp_net.dsp
+++ b/win32/xineplug_inp_net.dsp
diff --git a/win32/xineplug_vo_out_sdl.dsp b/win32/xineplug_vo_out_sdl.dsp
index 607cd74dc..607cd74dc 100644..100755
--- a/win32/xineplug_vo_out_sdl.dsp
+++ b/win32/xineplug_vo_out_sdl.dsp